LCOV - code coverage report
Current view: top level - lib_dec - ivas_td_low_rate_dec.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 38 76 50.0 %
Date: 2025-05-23 08:37:30 Functions: 1 2 50.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             : #ifdef DEBUGGING
      36             : #include "debug.h"
      37             : #endif
      38             : #include "cnst.h"
      39             : #include "stat_enc.h"
      40             : #include "rom_com.h"
      41             : #include "ivas_rom_com.h"
      42             : #include "ivas_cnst.h"
      43             : #include "prot.h"
      44             : #include "ivas_prot.h"
      45             : #include "wmc_auto.h"
      46             : 
      47             : /*-------------------------------------------------------------------*
      48             :  * tdm_low_rate_dec()
      49             :  *
      50             :  * Decode secondary channel of TD Stereo with a low-bitrate decoder
      51             :  *-------------------------------------------------------------------*/
      52             : 
      53       22509 : void tdm_low_rate_dec(
      54             :     Decoder_State *st,    /* i/o: decoder static memory                   */
      55             :     float dct_epit[],     /* o  : GSC excitation in DCT domain            */
      56             :     float *tmp_noise,     /* o  : long term temporary noise energy        */
      57             :     float *pitch_buf,     /* o  : floating pitch values for each subframe */
      58             :     float *voice_factors, /* o  : voicing factors                         */
      59             :     float *exc,           /* i/o: adapt. excitation exc                   */
      60             :     float *exc2,          /* i/o: adapt. excitation/total exc             */
      61             :     float *bwe_exc,       /* o  : excitation for SWB TBE                  */
      62             :     const float *lsf_new  /* i  : ISFs at the end of the frame            */
      63             : )
      64             : {
      65             :     int16_t tmp_nb_bits_tot, pit_band_idx;
      66             :     GSC_DEC_HANDLE hGSCDec;
      67             :     int16_t Diff_len, nb_subfr;
      68             :     int16_t attack_flag;
      69             :     int16_t last_bin;
      70             :     float exc_wo_nf[L_FRAME];
      71             : 
      72       22509 :     hGSCDec = st->hGSCDec;
      73             : 
      74             :     /*---------------------------------------------------------------*
      75             :      * Initialization
      76             :      *---------------------------------------------------------------*/
      77             : 
      78       22509 :     nb_subfr = 2;
      79             : 
      80       22509 :     st->GSC_IVAS_mode = 0;
      81       22509 :     st->GSC_noisy_speech = 1;
      82       22509 :     hGSCDec->noise_lev = 14;
      83             : 
      84       22509 :     pit_band_idx = 10 + BAND1k2;
      85       22509 :     hGSCDec->Last_GSC_pit_band_idx = pit_band_idx;
      86             : 
      87       22509 :     st->tilt_code = 0.0f;
      88       22509 :     set_f( exc, 0, L_FRAME );
      89       22509 :     set_f( dct_epit, 0, L_FRAME );
      90       22509 :     set_f( pitch_buf, L_SUBFR, NB_SUBFR );
      91       22509 :     st->bpf_off = 1;
      92             : 
      93       22509 :     st->bfi_pitch = (int16_t) ( mean( pitch_buf, 4 ) + 0.5f );
      94       22509 :     st->bfi_pitch_frame = L_FRAME;
      95       22509 :     Diff_len = L_FRAME / 2;
      96       22509 :     st->bpf_off = 0;
      97       22509 :     attack_flag = 0;
      98             : 
      99             :     /*--------------------------------------------------------------------------------------*
     100             :      * GSC decoder
     101             :      *--------------------------------------------------------------------------------------*/
     102             : 
     103             :     /* find the current total number of bits used */
     104       22509 :     tmp_nb_bits_tot = st->next_bit_pos;
     105             : 
     106       22509 :     if ( st->element_mode == IVAS_CPE_TD )
     107             :     {
     108          81 :         tmp_nb_bits_tot += TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS;
     109             :     }
     110             : 
     111       22509 :     if ( st->tdm_LRTD_flag == 1 )
     112             :     {
     113          33 :         tmp_nb_bits_tot -= STEREO_BITS_TCA;
     114             :     }
     115             : 
     116       22509 :     if ( st->extl_brate_orig > 0 )
     117             :     {
     118             :         /* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */
     119         210 :         tmp_nb_bits_tot--;
     120             :     }
     121             : 
     122       22509 :     gsc_dec( st, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st->coder_type, &last_bin, lsf_new, exc_wo_nf, tmp_noise );
     123             : 
     124             :     /*--------------------------------------------------------------------------------------*
     125             :      * iDCT transform
     126             :      *--------------------------------------------------------------------------------------*/
     127             : 
     128       22509 :     edct( dct_epit, exc, L_FRAME, IVAS_CPE_TD );
     129             : 
     130       22509 :     edct( exc_wo_nf, exc_wo_nf, L_FRAME, IVAS_CPE_TD );
     131             : 
     132             :     /*----------------------------------------------------------------------*
     133             :      * Remove potential pre-echo in case an onset has been detected
     134             :      *----------------------------------------------------------------------*/
     135             : 
     136       22509 :     pre_echo_att( &hGSCDec->Last_frame_ener, exc, attack_flag, st->last_coder_type, st->L_frame );
     137             : 
     138             : 
     139             :     /*--------------------------------------------------------------------------------------*
     140             :      * Update BWE excitation
     141             :      *--------------------------------------------------------------------------------------*/
     142             : 
     143       22509 :     set_f( voice_factors, 0.0f, NB_SUBFR16k );
     144             : 
     145       22509 :     if ( st->hBWE_TD != NULL )
     146             :     {
     147       22461 :         if ( st->tdm_LRTD_flag )
     148             :         {
     149          33 :             interp_code_5over2( exc, bwe_exc, L_FRAME );
     150             :         }
     151             :         else
     152             :         {
     153       22428 :             set_f( bwe_exc, 0, L_FRAME32k );
     154             :         }
     155             :     }
     156             : 
     157             :     /*--------------------------------------------------------------------------------------*
     158             :      * Updates
     159             :      *--------------------------------------------------------------------------------------*/
     160             : 
     161       22509 :     mvr2r( exc, exc2, L_FRAME );
     162       22509 :     mvr2r( exc_wo_nf, exc, L_FRAME );
     163             : 
     164             :     /*--------------------------------------------------------------------------------------*
     165             :      * Channel aware mode parameters
     166             :      *--------------------------------------------------------------------------------------*/
     167             : 
     168       22509 :     set_f( st->tilt_code_dec, 0, NB_SUBFR16k );
     169             : 
     170       22509 :     return;
     171             : }
     172             : 
     173             : 
     174             : /*---------------------------------------------------------------------*
     175             :  * decod_gen_2sbfr()
     176             :  *
     177             :  * Decode generic (GC), 2 subframes mode
     178             :  *---------------------------------------------------------------------*/
     179             : 
     180           0 : void decod_gen_2sbfr(
     181             :     Decoder_State *st,                  /* i/o: decoder static memory                     */
     182             :     const int16_t sharpFlag,            /* i  : formant sharpening flag                   */
     183             :     const float *Aq,                    /* i  : LP filter coefficient                     */
     184             :     float *pitch_buf,                   /* o  : floating pitch values for each subframe   */
     185             :     float *voice_factors,               /* o  : voicing factors                           */
     186             :     float *exc,                         /* i/o: adapt. excitation exc                     */
     187             :     float *exc2,                        /* i/o: adapt. excitation/total exc               */
     188             :     float *bwe_exc,                     /* o  : excitation for SWB TBE                    */
     189             :     float *gain_buf,                    /* o  : floating pitch gain for each subframe     */
     190             :     const int16_t tdm_Pitch_reuse_flag, /* i  : primary channel pitch reuse flag          */
     191             :     const float tdm_Pri_pitch_buf[]     /* i  : pitch values for primary channel          */
     192             : )
     193             : {
     194             :     int16_t T0, T0_frac, T0_min, T0_max;   /* integer pitch variables                          */
     195           0 :     float gain_pit = 0.0f;                 /* pitch gain                                       */
     196           0 :     float gain_code = 0.0f;                /* gain/normalized gain of the algebraic excitation */
     197           0 :     float norm_gain_code = 0.0f;           /* normalized gain of the algebraic excitation      */
     198           0 :     float gain_inov = 0;                   /* Innovation gain                                  */
     199             :     float gains_mem[2 * ( NB_SUBFR - 1 )]; /* pitch gain and code gain from previous subframes */
     200             :     float voice_fac;                       /* voicing factor                                   */
     201             :     float code[2 * L_SUBFR];               /* algebraic codevector                             */
     202             :     const float *p_Aq;                     /* Pointer to frame LP coefficient                  */
     203             :     float *pt_pitch;                       /* pointer to floating pitch                        */
     204             :     int16_t i_subfr, i;                    /* tmp variables                                    */
     205             :     int16_t L_frame;
     206             :     int16_t pitch_limit_flag;
     207             :     float error;
     208             : 
     209             :     /*------------------------------------------------------------------*
     210             :      * Initialization
     211             :      *------------------------------------------------------------------*/
     212             : 
     213           0 :     L_frame = L_FRAME;
     214             : 
     215           0 :     T0 = PIT_MIN;
     216           0 :     T0_frac = 0;
     217           0 :     error = 0.0f;
     218             : 
     219             :     /*------------------------------------------------------------------*
     220             :      * ACELP subframe loop
     221             :      *------------------------------------------------------------------*/
     222             : 
     223           0 :     p_Aq = Aq;            /* pointer to interpolated LPC parameters */
     224           0 :     pt_pitch = pitch_buf; /* pointer to the pitch buffer */
     225             : 
     226           0 :     for ( i_subfr = 0; i_subfr < L_frame; i_subfr += 2 * L_SUBFR )
     227             :     {
     228             :         /*----------------------------------------------------------------------*
     229             :          * Decode pitch lag
     230             :          *----------------------------------------------------------------------*/
     231             : 
     232           0 :         *pt_pitch = pit_decode( st, st->core_brate, 0, L_frame, i_subfr, GENERIC, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, 2 * L_SUBFR, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf );
     233             : 
     234           0 :         tbe_celp_exc( st->element_mode, st->idchan, bwe_exc, L_frame, 2 * L_SUBFR, i_subfr, T0, T0_frac, &error, st->tdm_LRTD_flag );
     235             : 
     236             :         /*--------------------------------------------------------------*
     237             :          * Find the adaptive codebook vector
     238             :          *--------------------------------------------------------------*/
     239             : 
     240           0 :         pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac, 2 * L_SUBFR + 1, inter4_2, L_INTERPOL2, PIT_UP_SAMP );
     241             : 
     242             :         /*--------------------------------------------------------------*
     243             :          * LP filtering of the adaptive excitation
     244             :          *--------------------------------------------------------------*/
     245             : 
     246           0 :         lp_filt_exc_dec( st, MODE1, i_subfr, 2 * L_SUBFR, L_frame, st->acelp_cfg.ltf_mode, exc );
     247             : 
     248             :         /*--------------------------------------------------------------*
     249             :          * Innovation decoding
     250             :          *--------------------------------------------------------------*/
     251             : 
     252           0 :         inov_decode( st, st->core_brate, 0, L_frame, sharpFlag, i_subfr, p_Aq, st->tilt_code, *pt_pitch, code, 2 * L_SUBFR );
     253             : 
     254             :         /*--------------------------------------------------------------*
     255             :          * Gain decoding
     256             :          * Estimate spectrum tilt and voicing
     257             :          *--------------------------------------------------------------*/
     258             : 
     259           0 :         gain_dec_lbr( st, GENERIC, i_subfr, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, gains_mem, 2 * L_SUBFR );
     260           0 :         st->tilt_code = est_tilt( exc + i_subfr, gain_pit, code, gain_code, &voice_fac, 2 * L_SUBFR, 0 );
     261             : 
     262             :         /* update LP filtered gains for the case of frame erasures */
     263           0 :         lp_gain_updt( i_subfr, gain_pit, norm_gain_code, &st->lp_gainp, &st->lp_gainc, L_frame );
     264           0 :         lp_gain_updt( i_subfr + L_SUBFR, gain_pit, norm_gain_code, &st->lp_gainp, &st->lp_gainc, L_frame );
     265             : 
     266             :         /*----------------------------------------------------------------------*
     267             :          * Find the total excitation
     268             :          *----------------------------------------------------------------------*/
     269             : 
     270           0 :         for ( i = 0; i < 2 * L_SUBFR; i++ )
     271             :         {
     272           0 :             exc2[i + i_subfr] = gain_pit * exc[i + i_subfr];
     273           0 :             exc[i + i_subfr] = exc2[i + i_subfr] + gain_code * code[i];
     274             :         }
     275             : 
     276             :         /*-----------------------------------------------------------------*
     277             :          * Prepare TBE excitation
     278             :          *-----------------------------------------------------------------*/
     279             : 
     280           0 :         prep_tbe_exc( L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], bwe_exc, 0, NULL, T0, GENERIC, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag );
     281             : 
     282           0 :         voice_factors[i_subfr / L_SUBFR + 1] = voice_factors[i_subfr / L_SUBFR];
     283             : 
     284             :         /*----------------------------------------------------------------*
     285             :          * Excitation enhancements (update of total excitation signal)
     286             :          * called twice because adapting it to double the subfr length would need lot of modifications
     287             :          *----------------------------------------------------------------*/
     288             : 
     289           0 :         enhancer( MODE1, st->core_brate, -1, 0, GENERIC, L_frame, voice_fac, st->stab_fac, norm_gain_code, gain_inov, &st->gc_threshold, code, exc2 + i_subfr, gain_pit, st->dispMem );
     290             : 
     291           0 :         enhancer( MODE1, st->core_brate, -1, 0, GENERIC, L_frame, voice_fac, st->stab_fac, norm_gain_code, gain_inov, &st->gc_threshold, code + L_SUBFR, exc2 + i_subfr + L_SUBFR, gain_pit, st->dispMem );
     292             : 
     293           0 :         p_Aq += 2 * ( M + 1 );
     294             : 
     295           0 :         pt_pitch++;
     296           0 :         *pt_pitch = *( pt_pitch - 1 );
     297           0 :         pt_pitch++;
     298             : 
     299           0 :         gain_buf[i_subfr / L_SUBFR] = gain_pit;
     300           0 :         gain_buf[( i_subfr + L_SUBFR ) / L_SUBFR] = gain_pit;
     301           0 :         st->tilt_code_dec[i_subfr / L_SUBFR] = st->tilt_code;
     302           0 :         st->tilt_code_dec[( i_subfr + L_SUBFR ) / L_SUBFR] = st->tilt_code;
     303             :     }
     304             : 
     305             :     /* SC-VBR */
     306           0 :     st->prev_gain_pit_dec = gain_pit;
     307             : 
     308           0 :     return;
     309             : }

Generated by: LCOV version 1.14