LCOV - code coverage report
Current view: top level - lib_dec - ivas_td_low_rate_dec_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main -- dec/rend @ 4c82f1d24d39d0296b18d775f18a006f4c7d024b Lines: 62 123 50.4 %
Date: 2025-05-17 01:59:02 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             : #include "cnst.h"
      36             : #include "stat_enc.h"
      37             : #include "rom_com.h"
      38             : #include "ivas_rom_com.h"
      39             : #include "ivas_cnst.h"
      40             : #include "prot_fx.h"
      41             : #include "wmc_auto.h"
      42             : #include "ivas_prot_fx.h"
      43             : 
      44             : /*-------------------------------------------------------------------*
      45             :  * tdm_low_rate_dec_fx()
      46             :  *
      47             :  * Low-bitrate decoder
      48             :  *-------------------------------------------------------------------*/
      49             : 
      50        6763 : void tdm_low_rate_dec_fx(
      51             :     Decoder_State *st,     /* i/o: decoder static memory                                                         */
      52             :     Word16 dct_epit[],     /* o  : GSC excitation in DCT domain                                 Q_exc*/
      53             :     Word16 *pitch_buf,     /* o  : Word16 pitch values for each subframe                   Q6*/
      54             :     Word16 *voice_factors, /* o  : voicing factors                                                                Q15*/
      55             :     Word16 *exc,           /* i/o: adapt. excitation exc                                                Q_exc*/
      56             :     Word16 *exc2,          /* i/o: adapt. excitation/total exc                                  Q_exc*/
      57             :     Word16 *bwe_exc,       /* o  : excitation for SWB TBE                                               Q_exc*/
      58             :     const Word16 *lsf_new  /* i  : ISFs at the end of the frame            Q8/100 (2.56x)*/
      59             : )
      60             : {
      61             :     Word16 tmp_nb_bits_tot, pit_band_idx;
      62             :     GSC_DEC_HANDLE hGSCDec;
      63             :     Word16 Diff_len, nb_subfr;
      64             :     Word16 attack_flag;
      65             :     Word16 last_bin;
      66             :     Word16 exc_wo_nf_fx[L_FRAME];
      67             : 
      68        6763 :     hGSCDec = st->hGSCDec;
      69             : 
      70             :     /*---------------------------------------------------------------*
      71             :      * Initialization
      72             :      *---------------------------------------------------------------*/
      73             : 
      74        6763 :     nb_subfr = 2;
      75        6763 :     move16();
      76             : 
      77        6763 :     st->GSC_IVAS_mode = 0;
      78        6763 :     move16();
      79        6763 :     st->GSC_noisy_speech = 1;
      80        6763 :     move16();
      81        6763 :     hGSCDec->noise_lev = 14; /* Q0 */
      82        6763 :     move16();
      83             : 
      84        6763 :     pit_band_idx = 10 + BAND1k2;                   /* Q0 */
      85        6763 :     hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; /* Q0 */
      86        6763 :     move16();
      87        6763 :     move16();
      88             : 
      89        6763 :     st->tilt_code_fx = 0;
      90        6763 :     move16();
      91        6763 :     set16_fx( exc, 0, L_FRAME );
      92        6763 :     set16_fx( dct_epit, 0, L_FRAME );
      93        6763 :     set16_fx( pitch_buf, shl( L_SUBFR, Q6 ), NB_SUBFR );
      94        6763 :     st->bpf_off = 1;
      95        6763 :     move16();
      96             : 
      97        6763 :     st->bfi_pitch_fx = mean_fx( pitch_buf, 4 ); /* Q6 */
      98        6763 :     move16();
      99        6763 :     st->bfi_pitch_frame = L_FRAME; /* Q0 */
     100        6763 :     move16();
     101        6763 :     Diff_len = L_FRAME / 2;
     102        6763 :     move16();
     103        6763 :     st->bpf_off = 0;
     104        6763 :     move16();
     105        6763 :     attack_flag = 0;
     106        6763 :     move16();
     107             : 
     108        6763 :     move16();
     109        6763 :     move16();
     110        6763 :     move16();
     111        6763 :     move16();
     112             :     /*--------------------------------------------------------------------------------------*
     113             :      * GSC decoder
     114             :      *--------------------------------------------------------------------------------------*/
     115             : 
     116             :     /* find the current total number of bits used */
     117        6763 :     tmp_nb_bits_tot = st->next_bit_pos; /* Q0 */
     118        6763 :     move16();
     119             : 
     120        6763 :     move16();
     121        6763 :     if ( EQ_16( st->element_mode, IVAS_CPE_TD ) )
     122             :     {
     123          27 :         tmp_nb_bits_tot = add( tmp_nb_bits_tot, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ); /* Q0 */
     124             :     }
     125             : 
     126        6763 :     if ( EQ_16( st->tdm_LRTD_flag, 1 ) )
     127             :     {
     128          11 :         tmp_nb_bits_tot = sub( tmp_nb_bits_tot, STEREO_BITS_TCA ); /* Q0 */
     129             :     }
     130             : 
     131        6763 :     if ( st->extl_brate_orig > 0 )
     132             :     {
     133             :         /* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */
     134          70 :         tmp_nb_bits_tot = sub( tmp_nb_bits_tot, 1 ); /* Q0 */
     135             :     }
     136             : 
     137        6763 :     gsc_dec_fx( st, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st->coder_type, &last_bin, lsf_new, exc_wo_nf_fx, &st->Q_exc );
     138             : 
     139             :     /*--------------------------------------------------------------------------------------*
     140             :      * iDCT transform
     141             :      *--------------------------------------------------------------------------------------*/
     142             : 
     143        6763 :     edct_16fx( dct_epit, exc, L_FRAME, find_guarded_bits_fx( L_FRAME ), IVAS_CPE_TD );
     144             : 
     145        6763 :     edct_16fx( exc_wo_nf_fx, exc_wo_nf_fx, L_FRAME, find_guarded_bits_fx( L_FRAME ), IVAS_CPE_TD );
     146             : 
     147        6763 :     IF( bwe_exc != NULL )
     148             :     {
     149        6747 :         Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, &exc[0], &bwe_exc[0], st->hGSCDec->last_exc_dct_in_fx,
     150        6747 :                      L_FRAME, L_FRAME * HIBND_ACB_L_FAC, L_shl( st->lp_gainc_fx, 13 /* Q3 -> Q16*/ ), &( st->Q_exc ), st->Q_subfr, NULL, 0, st->coder_type );
     151             :     }
     152             :     ELSE
     153             :     {
     154          16 :         Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, &exc[0], NULL, st->hGSCDec->last_exc_dct_in_fx,
     155          16 :                      L_FRAME, L_FRAME * HIBND_ACB_L_FAC, L_shl( st->lp_gainc_fx, 13 /* Q3 -> Q16*/ ), &( st->Q_exc ), st->Q_subfr, NULL, 0, st->coder_type );
     156             :     }
     157             :     /*----------------------------------------------------------------------*
     158             :      * Remove potential pre-echo in case an onset has been detected
     159             :      *----------------------------------------------------------------------*/
     160             : 
     161        6763 :     pre_echo_att_fx( &hGSCDec->Last_frame_ener_fx, exc, attack_flag, st->Q_exc, st->last_coder_type, st->L_frame );
     162             : 
     163             : 
     164             :     /*--------------------------------------------------------------------------------------*
     165             :      * Update BWE excitation
     166             :      *--------------------------------------------------------------------------------------*/
     167             : 
     168        6763 :     set16_fx( voice_factors, 0, NB_SUBFR16k );
     169             : 
     170        6763 :     IF( st->hBWE_TD != NULL )
     171             :     {
     172        6747 :         IF( st->tdm_LRTD_flag )
     173             :         {
     174          11 :             interp_code_5over2_fx( exc, bwe_exc, L_FRAME );
     175             :         }
     176             :         ELSE
     177             :         {
     178        6736 :             set16_fx( bwe_exc, 0, L_FRAME32k );
     179             :         }
     180             :     }
     181             : 
     182             :     /*--------------------------------------------------------------------------------------*
     183             :      * Updates
     184             :      *--------------------------------------------------------------------------------------*/
     185             : 
     186        6763 :     Copy( exc, exc2, L_FRAME );         /* Q_exc */
     187        6763 :     Copy( exc_wo_nf_fx, exc, L_FRAME ); /* Q_exc */
     188             : 
     189             :     /*--------------------------------------------------------------------------------------*
     190             :      * Channel aware mode parameters
     191             :      *--------------------------------------------------------------------------------------*/
     192             : 
     193        6763 :     set16_fx( st->tilt_code_dec_fx, 0, NB_SUBFR16k );
     194             : 
     195        6763 :     return;
     196             : }
     197             : 
     198             : 
     199             : /*---------------------------------------------------------------------*
     200             :  * decod_gen_2sbfr()
     201             :  *
     202             :  * Decode generic (GC), 2 subframes mode
     203             :  *---------------------------------------------------------------------*/
     204             : 
     205           0 : void decod_gen_2sbfr_fx(
     206             :     Decoder_State *st,                 /* i/o: decoder static memory                        */
     207             :     const Word16 sharpFlag,            /* i  : formant sharpening flag                   `Q0*/
     208             :     const Word16 *Aq,                  /* i  : LP filter coefficient                                     Q12*/
     209             :     Word16 *pitch_buf,                 /* o  : Word16 pitch values for each subframe      Q6*/
     210             :     Word16 *voice_factors,             /* o  : voicing factors                                                   Q15*/
     211             :     Word16 *exc,                       /* i/o: adapt. excitation exc                               Q_exc*/
     212             :     Word16 *exc2,                      /* i/o: adapt. excitation/total exc                         Q_exc*/
     213             :     Word16 *bwe_exc,                   /* o  : excitation for SWB TBE                              Q_exc*/
     214             :     Word16 *gain_buf,                  /* o  : Word16 pitch gain for each subframe               Q14*/
     215             :     const Word16 tdm_Pitch_reuse_flag, /* i  : primary channel pitch reuse flag           Q0*/
     216             :     const Word16 tdm_Pri_pitch_buf[]   /* i  : pitch values for primary channel                   Q6*/
     217             : )
     218             : {
     219             :     Word16 T0, T0_frac, T0_min, T0_max; /* integer pitch variables                          */
     220           0 :     Word16 gain_pit = 0;                /* pitch gain                                       */
     221           0 :     move16();
     222           0 :     Word32 gain_code = 0; /* gain/normalized gain of the algebraic excitation */
     223           0 :     move32();
     224           0 :     Word32 norm_gain_code = 0; /* normalized gain of the algebraic excitation      */
     225           0 :     move32();
     226           0 :     Word16 gain_inov = 0; /* Innovation gain                                  */
     227           0 :     move16();
     228             :     Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes                */
     229             :     Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes               */
     230             :     Word16 voice_fac;            /* voicing factor                                   */
     231             :     Word16 code[2 * L_SUBFR];    /* algebraic codevector                             */
     232             :     const Word16 *p_Aq;          /* Pointer to frame LP coefficient                  */
     233             :     Word16 *pt_pitch;            /* pointer to Word16 pitch                          */
     234             :     Word16 i_subfr;              /* tmp variables                                    */
     235             :     Word16 L_frame;
     236             :     Word16 pitch_limit_flag;
     237             :     Word16 error;
     238             : 
     239             :     /*------------------------------------------------------------------*
     240             :      * Initialization
     241             :      *------------------------------------------------------------------*/
     242             : 
     243           0 :     L_frame = L_FRAME;
     244           0 :     move16();
     245             : 
     246           0 :     T0 = PIT_MIN;
     247           0 :     move16();
     248           0 :     T0_frac = 0;
     249           0 :     move16();
     250           0 :     error = 0;
     251           0 :     move16();
     252             : 
     253           0 :     move16();
     254           0 :     move16();
     255           0 :     move16();
     256             :     /*------------------------------------------------------------------*
     257             :      * ACELP subframe loop
     258             :      *------------------------------------------------------------------*/
     259             : 
     260           0 :     p_Aq = Aq;            /* pointer to interpolated LPC parameters             Q12*/
     261           0 :     pt_pitch = pitch_buf; /* pointer to the pitch buffer                                Q6*/
     262             : 
     263           0 :     FOR( i_subfr = 0; i_subfr < L_frame; i_subfr += 2 * L_SUBFR )
     264             :     {
     265             :         /*----------------------------------------------------------------------*
     266             :          * Decode pitch lag
     267             :          *----------------------------------------------------------------------*/
     268             : 
     269           0 :         *pt_pitch = pit_decode_fx( 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 ); /* Q6 */
     270             : 
     271           0 :         test();
     272           0 :         test();
     273           0 :         IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) && !( st->tdm_LRTD_flag ) ) )
     274             :         {
     275           0 :             tbe_celp_exc( L_frame, i_subfr, T0, T0_frac, &error, bwe_exc );
     276             :         }
     277             : 
     278             :         /*--------------------------------------------------------------*
     279             :          * Find the adaptive codebook vector
     280             :          *--------------------------------------------------------------*/
     281             : 
     282           0 :         pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac, 2 * L_SUBFR + 1, inter4_2_fx_Q15, L_INTERPOL2, PIT_UP_SAMP );
     283             : 
     284             :         /*--------------------------------------------------------------*
     285             :          * LP filtering of the adaptive excitation
     286             :          *--------------------------------------------------------------*/
     287             : 
     288           0 :         lp_filt_exc_dec_fx( st, MODE1, i_subfr, 2 * L_SUBFR, L_frame, st->acelp_cfg.ltf_mode, exc );
     289             : 
     290             :         /*--------------------------------------------------------------*
     291             :          * Innovation decoding
     292             :          *--------------------------------------------------------------*/
     293             : 
     294           0 :         inov_decode_ivas_fx( st, st->core_brate, 0, L_frame, sharpFlag, i_subfr, p_Aq, st->tilt_code_fx, *pt_pitch, code, 2 * L_SUBFR );
     295             : 
     296             :         /*--------------------------------------------------------------*
     297             :          * Gain decoding
     298             :          * Estimate spectrum tilt and voicing
     299             :          *--------------------------------------------------------------*/
     300             : 
     301           0 :         gain_dec_lbr_fx( st, GENERIC, i_subfr, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, gc_mem, gp_mem, 2 * L_SUBFR );
     302           0 :         st->tilt_code_fx = est_tilt_ivas_fx( exc + i_subfr, gain_pit, code, gain_code, &voice_fac, st->Q_exc, 2 * L_SUBFR, 0 ); /* Q15 */
     303           0 :         move16();
     304             : 
     305             :         /* update LP filtered gains for the case of frame erasures */
     306           0 :         lp_gain_updt_ivas_fx( i_subfr, gain_pit, norm_gain_code, &st->lp_gainp_fx, &st->lp_gainc_fx, L_frame );
     307           0 :         lp_gain_updt_ivas_fx( add( i_subfr, L_SUBFR ), gain_pit, norm_gain_code, &st->lp_gainp_fx, &st->lp_gainc_fx, L_frame );
     308             : 
     309             :         /*----------------------------------------------------------------------*
     310             :          * Find the total excitation
     311             :          *----------------------------------------------------------------------*/
     312             : 
     313           0 :         Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, &exc[i_subfr], ( bwe_exc != NULL ) ? &bwe_exc[i_subfr * HIBND_ACB_L_FAC] : NULL, st->hGSCDec->last_exc_dct_in_fx,
     314           0 :                      2 * L_SUBFR, 2 * L_SUBFR * HIBND_ACB_L_FAC, gain_code, &( st->Q_exc ), st->Q_subfr, exc2, i_subfr, st->coder_type );
     315             : 
     316           0 :         Word16 gain_code16 = round_fx( L_shl( gain_code, st->Q_exc ) ); /*Q_exc*/
     317           0 :         Acelp_dec_total_exc( exc, exc2, gain_code16, gain_pit, i_subfr, code, 2 * L_SUBFR );
     318             : 
     319             :         /*-----------------------------------------------------------------*
     320             :          * Prepare TBE excitation
     321             :          *-----------------------------------------------------------------*/
     322             : 
     323           0 :         prep_tbe_exc_fx( L_frame, 2 * L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/], bwe_exc, 0, NULL, st->Q_exc, T0, T0_frac, GENERIC, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag );
     324           0 :         voice_factors[i_subfr / L_SUBFR + 1] = voice_factors[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/]; /* Q15 */
     325           0 :         move16();
     326             : 
     327             :         /*----------------------------------------------------------------*
     328             :          * Excitation enhancements (update of total excitation signal)
     329             :          * called twice because adapting it to double the subfr length would need lot of modifications
     330             :          *----------------------------------------------------------------*/
     331             : 
     332           0 :         enhancer_ivas_fx2( st->core_brate, 0, GENERIC, i_subfr, L_frame, voice_fac, st->stab_fac_fx, norm_gain_code, gain_inov, &st->gc_threshold_fx, code, exc2, gain_pit, &st->dm_fx, st->Q_exc );
     333             : 
     334           0 :         enhancer_ivas_fx2( st->core_brate, 0, GENERIC, i_subfr, L_frame, voice_fac, st->stab_fac_fx, norm_gain_code, gain_inov, &st->gc_threshold_fx, code + L_SUBFR, exc2 + L_SUBFR, gain_pit, &st->dm_fx, st->Q_exc );
     335             : 
     336           0 :         p_Aq += 2 * ( M + 1 ); /* Q12 */
     337             : 
     338           0 :         pt_pitch++;
     339           0 :         *pt_pitch = *( pt_pitch - 1 ); /* Q6 */
     340           0 :         move16();
     341           0 :         pt_pitch++;
     342             : 
     343           0 :         gain_buf[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/] = gain_pit; /* Q14 */
     344           0 :         move16();
     345           0 :         gain_buf[( i_subfr + L_SUBFR ) / L_SUBFR /*(i_subfr+L_SUBFR) / L_SUBFR*/] = gain_pit; /* Q14 */
     346           0 :         move16();
     347           0 :         st->tilt_code_dec_fx[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/] = st->tilt_code_fx; /* Q15 */
     348           0 :         move16();
     349           0 :         st->tilt_code_dec_fx[( i_subfr + L_SUBFR ) / L_SUBFR /*( i_subfr + L_SUBFR ) / L_SUBFR*/] = st->tilt_code_fx; /* Q15 */
     350           0 :         move16();
     351             :     }
     352             : 
     353             :     /* SC-VBR */
     354           0 :     st->prev_gain_pit_dec_fx = gain_pit; /* Q14 */
     355           0 :     move16();
     356             : 
     357           0 :     return;
     358             : }

Generated by: LCOV version 1.14