LCOV - code coverage report
Current view: top level - lib_dec - ivas_mct_dec_mct.c (source / functions) Hit Total Coverage
Test: Coverage on main @ fec202a8f89be4a2f278a9fc377bfb58b58fab11 Lines: 93 96 96.9 %
Date: 2025-09-14 08:49:17 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             :    (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
       4             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
       5             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
       6             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
       7             :    contributors to this repository. All Rights Reserved.
       8             : 
       9             :    This software is protected by copyright law and by international treaties.
      10             :    The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
      11             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
      12             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
      13             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
      14             :    contributors to this repository retain full ownership rights in their respective contributions in
      15             :    the software. This notice grants no license of any kind, including but not limited to patent
      16             :    license, nor is any license granted by implication, estoppel or otherwise.
      17             : 
      18             :    Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
      19             :    contributions.
      20             : 
      21             :    This software is provided "AS IS", without any express or implied warranties. The software is in the
      22             :    development stage. It is intended exclusively for experts who have experience with such software and
      23             :    solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
      24             :    and fitness for a particular purpose are hereby disclaimed and excluded.
      25             : 
      26             :    Any dispute, controversy or claim arising under or in relation to providing this software shall be
      27             :    submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
      28             :    accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
      29             :    the United Nations Convention on Contracts on the International Sales of Goods.
      30             : 
      31             : *******************************************************************************************************/
      32             : 
      33             : #include <stdint.h>
      34             : #include "options.h"
      35             : #include "ivas_cnst.h"
      36             : #include "ivas_prot.h"
      37             : #include "prot.h"
      38             : #include "wmc_auto.h"
      39             : #include <assert.h>
      40             : #include "stat_enc.h"
      41             : 
      42             : 
      43             : /*----------------------------------------------------------*
      44             :  * indexToChannelPair()
      45             :  *
      46             :  * get the index of each channel pair
      47             :  *----------------------------------------------------------*/
      48             : 
      49     2783935 : static void indexToChannelPair(
      50             :     MCT_DEC_BLOCK_DATA_HANDLE hBlock,
      51             :     const int16_t nChannels,
      52             :     const int16_t pairIdx )
      53             : {
      54             :     int16_t ch1, ch2;
      55     2783935 :     int16_t tmpIdx = 0;
      56             : 
      57    11808435 :     for ( ch2 = 1; ch2 < nChannels; ch2++ )
      58             :     {
      59    43296599 :         for ( ch1 = 0; ch1 < ch2; ch1++ )
      60             :         {
      61             : 
      62    34272099 :             if ( tmpIdx == pairIdx )
      63             :             {
      64     2783935 :                 hBlock->ch1 = ch1;
      65     2783935 :                 hBlock->ch2 = ch2;
      66             : 
      67     2783935 :                 return;
      68             :             }
      69             :             else
      70             :             {
      71    31488164 :                 tmpIdx++;
      72             :             }
      73             :         }
      74             :     }
      75             : 
      76           0 :     return;
      77             : }
      78             : 
      79             : 
      80             : /*-------------------------------------------------------------------*
      81             :  * ivas_mct_dec_mct()
      82             :  *
      83             :  * decode core and mct information
      84             :  *-------------------------------------------------------------------*/
      85             : 
      86     3408294 : void ivas_mct_dec_mct(
      87             :     MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure       */
      88             :     Decoder_State **sts, /* i/o: decoder state structure     */
      89             :     const int16_t nchan  /* i  : number of channels          */
      90             : )
      91             : {
      92             :     int16_t pair, ch, channelPairIndex;
      93             :     MCT_DEC_BLOCK_DATA_HANDLE hBlock;
      94             :     Decoder_State *p_st[CPE_CHANNELS];
      95     3408294 :     int16_t nchan_active = 0;
      96             : 
      97     3408294 :     hMCT->currBlockDataCnt = get_next_indice( sts[0], MCT_NUM_BLOCK_DATA_BITS );
      98             : 
      99             :     /*first get core and overlap info for all channels*/
     100    19768222 :     for ( ch = 0; ch < nchan; ch++ )
     101             :     {
     102    16359928 :         if ( hMCT->currBlockDataCnt && sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE )
     103             :         {
     104     8807992 :             hMCT->mc_global_ild[ch] = get_next_indice( sts[0], SMDCT_GLOBAL_ILD_BITS );
     105             :         }
     106             :         else
     107             :         {
     108     7551936 :             hMCT->mc_global_ild[ch] = 0;
     109             :         }
     110             :     }
     111             : 
     112     3408294 :     if ( hMCT->currBlockDataCnt )
     113             :     {
     114    10631646 :         for ( ch = 0; ch < nchan; ch++ )
     115             :         {
     116     9016554 :             if (
     117     9016554 :                 sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE )
     118             :             {
     119     8807992 :                 hMCT->lowE_ch[ch] = get_next_indice( sts[0], 1 );
     120             :             }
     121             :         }
     122             :     }
     123             : 
     124    19768222 :     for ( ch = 0; ch < nchan; ch++ )
     125             :     {
     126    16359928 :         if ( sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE )
     127             :         {
     128    15891644 :             nchan_active++;
     129             :         }
     130             :     }
     131             : 
     132     6192229 :     for ( pair = hMCT->currBlockDataCnt - 1; pair >= 0; pair-- )
     133             :     {
     134     2783935 :         assert( nchan_active >= 2 );
     135     2783935 :         hBlock = hMCT->hBlockData[pair];
     136             : 
     137             :         /*get channel pair index from BS*/
     138     2783935 :         channelPairIndex = get_next_indice( sts[0], hMCT->bitsChannelPairIndex );
     139     2783935 :         indexToChannelPair( hBlock, nchan, channelPairIndex );
     140             : 
     141             :         /*point to decoder states of actual channels to read block pair bits*/
     142     2783935 :         p_st[0] = sts[hBlock->ch1];
     143     2783935 :         p_st[1] = sts[hBlock->ch2];
     144             : 
     145     2783935 :         parse_stereo_from_bitstream( hBlock->hStereoMdct, p_st, 1, 0, sts[0], hBlock->mask );
     146             :     }
     147             : 
     148     3408294 :     return;
     149             : }
     150             : 
     151             : 
     152             : /*----------------------------------------------------------*
     153             :  * applyGlobalILD()
     154             :  *
     155             :  * revert to initial channel energy levels using the ratios
     156             :  * sent from the encoder
     157             :  *----------------------------------------------------------*/
     158             : 
     159     3408294 : static void applyGlobalILD(
     160             :     Decoder_State **sts,
     161             :     MCT_DEC_HANDLE hMCT,
     162             :     float *x[MCT_MAX_CHANNELS][NB_DIV] )
     163             : {
     164             :     int16_t ch, k;
     165             :     int16_t nSubframes, L_subframeTCX;
     166             :     float qratio;
     167             : 
     168    19768222 :     for ( ch = 0; ch < ( hMCT->nchan_out_woLFE );
     169    16359928 :           ch++ )
     170             :     {
     171    16359928 :         nSubframes = ( sts[ch]->core == TCX_20_CORE ) ? 1 : NB_DIV;
     172    16359928 :         L_subframeTCX = sts[ch]->hTcxDec->L_frameTCX / nSubframes;
     173             : 
     174    16359928 :         if ( hMCT->mc_global_ild[ch] )
     175             :         {
     176     5567870 :             if ( hMCT->lowE_ch[ch] )
     177             :             {
     178     3262736 :                 qratio = (float) hMCT->mc_global_ild[ch] / SMDCT_ILD_RANGE;
     179             :             }
     180             :             else
     181             :             {
     182     2305134 :                 qratio = SMDCT_ILD_RANGE / (float) hMCT->mc_global_ild[ch];
     183             :             }
     184             : 
     185    11276090 :             for ( k = 0; k < nSubframes; k++ )
     186             :             {
     187     5708220 :                 v_multc( x[ch][k], qratio, x[ch][k], L_subframeTCX );
     188             :             }
     189             :         }
     190             :         else
     191             :         {
     192    10792058 :             continue;
     193             :         }
     194             :     }
     195             : 
     196     3408294 :     return;
     197             : }
     198             : 
     199             : 
     200             : /*----------------------------------------------------------*
     201             :  * apply_MCT_dec()
     202             :  *
     203             :  * main MCT decoding function
     204             :  *----------------------------------------------------------*/
     205             : 
     206     3408294 : void apply_MCT_dec(
     207             :     MCT_DEC_HANDLE hMCT,               /* i/o: MCT decoder structure                   */
     208             :     Decoder_State **sts,               /* i/o: decoder state structure                 */
     209             :     float *x[MCT_MAX_CHANNELS][NB_DIV] /* i/o: decoded and dequan. spect. input to MCT */
     210             : )
     211             : {
     212             :     int16_t pair;
     213             :     MCT_DEC_BLOCK_DATA_HANDLE hBlock;
     214             : 
     215     6192229 :     for ( pair = hMCT->currBlockDataCnt - 1; pair >= 0; pair-- )
     216             :     {
     217     2783935 :         hBlock = hMCT->hBlockData[pair];
     218             : 
     219     2783935 :         stereo_decoder_tcx( hBlock->hStereoMdct, hBlock->mask, &x[hBlock->ch2][0], &x[hBlock->ch1][0], &x[hBlock->ch2][0], hBlock->hStereoMdct->mdct_stereo_mode, sts[hBlock->ch1]->core, sts[hBlock->ch2]->core, sts[0]->igf, sts[0]->hTcxDec->L_frameTCX, sts[1]->hTcxDec->L_frameTCX, 1, TCX_20_CORE, TCX_20_CORE, 0 );
     220             :     }
     221             : 
     222     3408294 :     applyGlobalILD( sts, hMCT, x );
     223             : 
     224     3408294 :     return;
     225             : }
     226             : 
     227             : /*----------------------------------------------------------*
     228             :  * mctStereoIGF_dec()
     229             :  *
     230             :  * apply IGF to MCT stereo block pairs
     231             :  *----------------------------------------------------------*/
     232             : 
     233      849072 : void mctStereoIGF_dec(
     234             :     MCT_DEC_HANDLE hMCT,                /* i/o: MCT decoder structure           */
     235             :     Decoder_State **stm,                /* i/o: decoder state structure         */
     236             :     float *x[MCT_MAX_CHANNELS][NB_DIV], /* i/o: decoded and dequantized spectrum*/
     237             :     const int16_t bfi                   /* i  : bad frame flag                  */
     238             : )
     239             : {
     240             :     int16_t b, core, nSubframes, k, ch, p_ch[CPE_CHANNELS], ch1, ch2;
     241      849072 :     Decoder_State *sts[CPE_CHANNELS], *st = NULL;
     242             :     int16_t tcx_offset[CPE_CHANNELS];
     243             :     int16_t tcx_offsetFB[CPE_CHANNELS];
     244             :     int16_t left_rect[CPE_CHANNELS];
     245             :     int16_t L_spec[CPE_CHANNELS];
     246             :     int16_t L_frame[CPE_CHANNELS];
     247             :     int16_t L_frameTCX[CPE_CHANNELS];
     248             :     float *p_x[CPE_CHANNELS][NB_DIV];
     249             :     int16_t singleChEle[MCT_MAX_CHANNELS];
     250             : 
     251      849072 :     set_s( singleChEle, 1, ( hMCT->nchan_out_woLFE ) );
     252             : 
     253     2558533 :     for ( b = 0; b < hMCT->currBlockDataCnt; b++ )
     254             :     {
     255     1709461 :         ch1 = hMCT->hBlockData[b]->ch1;
     256     1709461 :         ch2 = hMCT->hBlockData[b]->ch2;
     257             : 
     258     1709461 :         sts[0] = stm[ch1];
     259     1709461 :         sts[1] = stm[ch2];
     260     1709461 :         core = sts[0]->core;
     261     1709461 :         nSubframes = core;
     262     1709461 :         p_ch[0] = ch1;
     263     1709461 :         p_ch[1] = ch2;
     264     1709461 :         singleChEle[hMCT->hBlockData[b]->ch1] = 0;
     265     1709461 :         singleChEle[hMCT->hBlockData[b]->ch2] = 0;
     266             : 
     267     3465396 :         for ( k = 0; k < nSubframes; k++ )
     268             :         {
     269     1755935 :             p_x[0][k] = x[ch1][k];
     270     1755935 :             p_x[1][k] = x[ch2][k];
     271             : 
     272     1755935 :             if ( hMCT->hBlockData[b]->hStereoMdct->IGFStereoMode[k] != SMDCT_DUAL_MONO || hMCT->hBlockData[b]->hStereoMdct->mdct_stereo_mode[k] != SMDCT_DUAL_MONO )
     273             :             {
     274     1755075 :                 L_spec[0] = sts[0]->hTcxCfg->tcx_coded_lines / nSubframes;
     275             : 
     276     1755075 :                 init_tcx_info( sts[0], sts[0]->L_frame / nSubframes, sts[0]->hTcxDec->L_frameTCX / nSubframes, k, bfi, &tcx_offset[0], &tcx_offsetFB[0], &L_frame[0], &L_frameTCX[0], &left_rect[0], &L_spec[0] );
     277             : 
     278             :                 /* stereo IGF decoding */
     279     1755075 :                 assert( ( sts[0]->core == sts[1]->core ) || ( hMCT->hBlockData[b]->hStereoMdct->mdct_stereo_mode[0] == SMDCT_DUAL_MONO ) );
     280             : 
     281     1755075 :                 decoder_tcx_IGF_stereo( sts, hMCT->hBlockData[b]->hStereoMdct, hMCT->hBlockData[b]->mask, p_x, L_frame[0], left_rect[0], k, bfi, 1 /* MCT_flag */ );
     282             :             }
     283             :             else
     284             :             {
     285        2580 :                 for ( ch = 0; ch < CPE_CHANNELS; ch++ )
     286             :                 {
     287        1720 :                     st = sts[ch];
     288        1720 :                     if ( bfi && st->core == ACELP_CORE ) /*no igf processing needed*/
     289             :                     {
     290           0 :                         continue;
     291             :                     }
     292        1720 :                     L_spec[ch] = st->hTcxCfg->tcx_coded_lines / nSubframes;
     293             : 
     294        1720 :                     init_tcx_info( st, st->L_frame / nSubframes, st->hTcxDec->L_frameTCX / nSubframes, k, bfi, &tcx_offset[ch], &tcx_offsetFB[ch], &L_frame[ch], &L_frameTCX[ch], &left_rect[ch], &L_spec[ch] );
     295             : 
     296             :                     /* mono or dual mono IGF decoding */
     297        1720 :                     decoder_tcx_IGF_mono( st, x[p_ch[ch]][k], L_frame[ch], left_rect[ch], bfi, k );
     298             :                 }
     299             :             }
     300             :         }
     301             :     }
     302             : 
     303             : 
     304      849072 :     if ( sum_s( singleChEle, ( hMCT->nchan_out_woLFE ) ) != 0 )
     305             :     {
     306     5608665 :         for ( ch = 0; ch < ( hMCT->nchan_out_woLFE ); ch++ )
     307             :         {
     308     4760729 :             if ( singleChEle[ch] )
     309             :             {
     310     1346355 :                 st = stm[ch];
     311     1346355 :                 if ( bfi && st->core == ACELP_CORE ) /*no igf processing needed*/
     312             :                 {
     313           0 :                     continue;
     314             :                 }
     315     1346355 :                 if ( st->mct_chan_mode == MCT_CHAN_MODE_IGNORE )
     316             :                 {
     317       38218 :                     continue;
     318             :                 }
     319     1308137 :                 nSubframes = ( st->core == TCX_10_CORE ) ? NB_DIV : 1;
     320             : 
     321     2649347 :                 for ( k = 0; k < nSubframes; k++ )
     322             :                 {
     323     1341210 :                     L_spec[0] = st->hTcxCfg->tcx_coded_lines / nSubframes;
     324             : 
     325     1341210 :                     init_tcx_info( st, st->L_frame / nSubframes, st->hTcxDec->L_frameTCX / nSubframes, k, bfi, &tcx_offset[0], &tcx_offsetFB[0], &L_frame[0], &L_frameTCX[0], &left_rect[0], &L_spec[0] );
     326             : 
     327             :                     /* mono or dual mono IGF decoding */
     328     1341210 :                     decoder_tcx_IGF_mono( st, x[ch][k], L_frame[0], left_rect[0], bfi, k );
     329             :                 }
     330             :             }
     331             :         }
     332             :     }
     333             : 
     334      849072 :     return;
     335             : }

Generated by: LCOV version 1.14