LCOV - code coverage report
Current view: top level - lib_dec - ivas_mct_dec_mct.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 93 96 96.9 %
Date: 2025-05-23 08:37:30 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      272955 : 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      272955 :     int16_t tmpIdx = 0;
      56             : 
      57     1044429 :     for ( ch2 = 1; ch2 < nChannels; ch2++ )
      58             :     {
      59     3401223 :         for ( ch1 = 0; ch1 < ch2; ch1++ )
      60             :         {
      61             : 
      62     2629749 :             if ( tmpIdx == pairIdx )
      63             :             {
      64      272955 :                 hBlock->ch1 = ch1;
      65      272955 :                 hBlock->ch2 = ch2;
      66             : 
      67      272955 :                 return;
      68             :             }
      69             :             else
      70             :             {
      71     2356794 :                 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      296901 : 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      296901 :     int16_t nchan_active = 0;
      96             : 
      97      296901 :     hMCT->currBlockDataCnt = get_next_indice( sts[0], MCT_NUM_BLOCK_DATA_BITS );
      98             : 
      99             :     /*first get core and overlap info for all channels*/
     100     1719531 :     for ( ch = 0; ch < nchan; ch++ )
     101             :     {
     102     1422630 :         if ( hMCT->currBlockDataCnt && sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE )
     103             :         {
     104      865158 :             hMCT->mc_global_ild[ch] = get_next_indice( sts[0], SMDCT_GLOBAL_ILD_BITS );
     105             :         }
     106             :         else
     107             :         {
     108      557472 :             hMCT->mc_global_ild[ch] = 0;
     109             :         }
     110             :     }
     111             : 
     112      296901 :     if ( hMCT->currBlockDataCnt )
     113             :     {
     114     1042011 :         for ( ch = 0; ch < nchan; ch++ )
     115             :         {
     116      875001 :             if (
     117      875001 :                 sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE )
     118             :             {
     119      865158 :                 hMCT->lowE_ch[ch] = get_next_indice( sts[0], 1 );
     120             :             }
     121             :         }
     122             :     }
     123             : 
     124     1719531 :     for ( ch = 0; ch < nchan; ch++ )
     125             :     {
     126     1422630 :         if ( sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE )
     127             :         {
     128     1397052 :             nchan_active++;
     129             :         }
     130             :     }
     131             : 
     132      569856 :     for ( pair = hMCT->currBlockDataCnt - 1; pair >= 0; pair-- )
     133             :     {
     134      272955 :         assert( nchan_active >= 2 );
     135      272955 :         hBlock = hMCT->hBlockData[pair];
     136             : 
     137             :         /*get channel pair index from BS*/
     138      272955 :         channelPairIndex = get_next_indice( sts[0], hMCT->bitsChannelPairIndex );
     139      272955 :         indexToChannelPair( hBlock, nchan, channelPairIndex );
     140             : 
     141             :         /*point to decoder states of actual channels to read block pair bits*/
     142      272955 :         p_st[0] = sts[hBlock->ch1];
     143      272955 :         p_st[1] = sts[hBlock->ch2];
     144             : 
     145      272955 :         parse_stereo_from_bitstream( hBlock->hStereoMdct, p_st, 1, 0, sts[0], hBlock->mask );
     146             :     }
     147             : 
     148      296901 :     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      296901 : 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     1719531 :     for ( ch = 0; ch < ( hMCT->nchan_out_woLFE );
     169     1422630 :           ch++ )
     170             :     {
     171     1422630 :         nSubframes = ( sts[ch]->core == TCX_20_CORE ) ? 1 : NB_DIV;
     172     1422630 :         L_subframeTCX = sts[ch]->hTcxDec->L_frameTCX / nSubframes;
     173             : 
     174     1422630 :         if ( hMCT->mc_global_ild[ch] )
     175             :         {
     176      545910 :             if ( hMCT->lowE_ch[ch] )
     177             :             {
     178      340728 :                 qratio = (float) hMCT->mc_global_ild[ch] / SMDCT_ILD_RANGE;
     179             :             }
     180             :             else
     181             :             {
     182      205182 :                 qratio = SMDCT_ILD_RANGE / (float) hMCT->mc_global_ild[ch];
     183             :             }
     184             : 
     185     1103688 :             for ( k = 0; k < nSubframes; k++ )
     186             :             {
     187      557778 :                 v_multc( x[ch][k], qratio, x[ch][k], L_subframeTCX );
     188             :             }
     189             :         }
     190             :         else
     191             :         {
     192      876720 :             continue;
     193             :         }
     194             :     }
     195             : 
     196      296901 :     return;
     197             : }
     198             : 
     199             : 
     200             : /*----------------------------------------------------------*
     201             :  * apply_MCT_dec()
     202             :  *
     203             :  * main MCT decoding function
     204             :  *----------------------------------------------------------*/
     205             : 
     206      296901 : 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      569856 :     for ( pair = hMCT->currBlockDataCnt - 1; pair >= 0; pair-- )
     216             :     {
     217      272955 :         hBlock = hMCT->hBlockData[pair];
     218             : 
     219      272955 :         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      296901 :     applyGlobalILD( sts, hMCT, x );
     223             : 
     224      296901 :     return;
     225             : }
     226             : 
     227             : /*----------------------------------------------------------*
     228             :  * mctStereoIGF_dec()
     229             :  *
     230             :  * apply IGF to MCT stereo block pairs
     231             :  *----------------------------------------------------------*/
     232             : 
     233      105513 : 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      105513 :     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      105513 :     set_s( singleChEle, 1, ( hMCT->nchan_out_woLFE ) );
     252             : 
     253      285030 :     for ( b = 0; b < hMCT->currBlockDataCnt; b++ )
     254             :     {
     255      179517 :         ch1 = hMCT->hBlockData[b]->ch1;
     256      179517 :         ch2 = hMCT->hBlockData[b]->ch2;
     257             : 
     258      179517 :         sts[0] = stm[ch1];
     259      179517 :         sts[1] = stm[ch2];
     260      179517 :         core = sts[0]->core;
     261      179517 :         nSubframes = core;
     262      179517 :         p_ch[0] = ch1;
     263      179517 :         p_ch[1] = ch2;
     264      179517 :         singleChEle[hMCT->hBlockData[b]->ch1] = 0;
     265      179517 :         singleChEle[hMCT->hBlockData[b]->ch2] = 0;
     266             : 
     267      363459 :         for ( k = 0; k < nSubframes; k++ )
     268             :         {
     269      183942 :             p_x[0][k] = x[ch1][k];
     270      183942 :             p_x[1][k] = x[ch2][k];
     271             : 
     272      183942 :             if ( hMCT->hBlockData[b]->hStereoMdct->IGFStereoMode[k] != SMDCT_DUAL_MONO || hMCT->hBlockData[b]->hStereoMdct->mdct_stereo_mode[k] != SMDCT_DUAL_MONO )
     273             :             {
     274      183882 :                 L_spec[0] = sts[0]->hTcxCfg->tcx_coded_lines / nSubframes;
     275             : 
     276      183882 :                 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      183882 :                 assert( ( sts[0]->core == sts[1]->core ) || ( hMCT->hBlockData[b]->hStereoMdct->mdct_stereo_mode[0] == SMDCT_DUAL_MONO ) );
     280             : 
     281      183882 :                 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         180 :                 for ( ch = 0; ch < CPE_CHANNELS; ch++ )
     286             :                 {
     287         120 :                     st = sts[ch];
     288         120 :                     if ( bfi && st->core == ACELP_CORE ) /*no igf processing needed*/
     289             :                     {
     290           0 :                         continue;
     291             :                     }
     292         120 :                     L_spec[ch] = st->hTcxCfg->tcx_coded_lines / nSubframes;
     293             : 
     294         120 :                     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         120 :                     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      105513 :     if ( sum_s( singleChEle, ( hMCT->nchan_out_woLFE ) ) != 0 )
     305             :     {
     306      623292 :         for ( ch = 0; ch < ( hMCT->nchan_out_woLFE ); ch++ )
     307             :         {
     308      517791 :             if ( singleChEle[ch] )
     309             :             {
     310      158805 :                 st = stm[ch];
     311      158805 :                 if ( bfi && st->core == ACELP_CORE ) /*no igf processing needed*/
     312             :                 {
     313           0 :                     continue;
     314             :                 }
     315      158805 :                 if ( st->mct_chan_mode == MCT_CHAN_MODE_IGNORE )
     316             :                 {
     317        3753 :                     continue;
     318             :                 }
     319      155052 :                 nSubframes = ( st->core == TCX_10_CORE ) ? NB_DIV : 1;
     320             : 
     321      314613 :                 for ( k = 0; k < nSubframes; k++ )
     322             :                 {
     323      159561 :                     L_spec[0] = st->hTcxCfg->tcx_coded_lines / nSubframes;
     324             : 
     325      159561 :                     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      159561 :                     decoder_tcx_IGF_mono( st, x[ch][k], L_frame[0], left_rect[0], bfi, k );
     329             :                 }
     330             :             }
     331             :         }
     332             :     }
     333             : 
     334      105513 :     return;
     335             : }

Generated by: LCOV version 1.14