LCOV - code coverage report
Current view: top level - lib_dec - acelp_core_switch_dec.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 178 207 86.0 %
Date: 2025-05-23 08:37:30 Functions: 3 3 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             : /*====================================================================================
      34             :     EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
      35             :   ====================================================================================*/
      36             : 
      37             : #include <stdint.h>
      38             : #include "options.h"
      39             : #ifdef DEBUGGING
      40             : #include "debug.h"
      41             : #endif
      42             : #include "cnst.h"
      43             : #include "rom_com.h"
      44             : #include "prot.h"
      45             : #include "wmc_auto.h"
      46             : 
      47             : /*---------------------------------------------------------------------*
      48             :  * Local function prototypes
      49             :  *---------------------------------------------------------------------*/
      50             : 
      51             : static void decod_gen_voic_core_switch( Decoder_State *st, const int16_t L_frame, const int16_t sharpFlag, const float *Aq, float *exc, const int32_t core_brate );
      52             : 
      53             : 
      54             : /*-------------------------------------------------------------------*
      55             :  * acelp_core_switch_dec()
      56             :  *
      57             :  * ACELP core decoder in the first ACELP->HQ switching frame
      58             :  *-------------------------------------------------------------------*/
      59             : 
      60          75 : ivas_error acelp_core_switch_dec(
      61             :     Decoder_State *st,                 /* i/o: decoder state structure         */
      62             :     float *synth_subfr_out,            /* o  : synthesized ACELP subframe      */
      63             :     float *tmp_synth_bwe,              /* o  : synthesized ACELP subframe BWE  */
      64             :     const int16_t output_frame,        /* i  : input frame legth               */
      65             :     const int16_t core_switching_flag, /* i  : core switching flag             */
      66             :     float *mem_synth,                  /* o  : synthesis to overlap            */
      67             :     const int16_t nchan_out            /* i  : number of output channels       */
      68             : )
      69             : {
      70             :     int16_t i, delta, L_frame_for_cs, decode_bwe;
      71             :     int16_t d1m, ind1, fdelay, gapsize;
      72             :     int32_t cbrate;
      73             :     float synth_intFreq[2 * L_SUBFR];
      74             :     float old_exc[L_EXC_DEC], *exc;
      75             :     float tmp_mem2[2 * L_FILT48k], gain;
      76             :     float hb_synth_tmp[NS2SA( 48000, 10000000L )];
      77             :     const float *hp_filter;
      78             :     float Aq[2 * ( M + 1 )];
      79             :     float bpf_error_signal[2 * L_SUBFR];
      80             :     float *realBuffer[CLDFB_NO_COL_MAX_SWITCH], *imagBuffer[CLDFB_NO_COL_MAX_SWITCH];
      81             :     float realBufferTmp[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX];
      82             :     ivas_error error;
      83             : 
      84          75 :     error = IVAS_ERR_OK;
      85             : 
      86             :     /*----------------------------------------------------------------*
      87             :      * Initializations
      88             :      *----------------------------------------------------------------*/
      89             : 
      90             :     /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
      91         525 :     for ( i = 0; i < CLDFB_NO_COL_MAX_SWITCH; i++ )
      92             :     {
      93         450 :         set_f( realBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX );
      94         450 :         set_f( imagBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX );
      95         450 :         realBuffer[i] = realBufferTmp[i];
      96         450 :         imagBuffer[i] = imagBufferTmp[i];
      97             :     }
      98             : 
      99          75 :     d1m = 0;
     100          75 :     gain = 0;
     101             : 
     102          75 :     mvr2r( st->old_Aq_12_8, Aq, M + 1 );
     103          75 :     mvr2r( st->old_Aq_12_8, Aq + ( M + 1 ), M + 1 );
     104             : 
     105          75 :     set_f( mem_synth, 0, NS2SA( 16000, DELAY_CLDFB_NS ) + 2 );
     106             : 
     107             :     /* set multiplication factor according to the sampling rate */
     108          75 :     delta = 1;
     109          75 :     if ( output_frame == L_FRAME32k )
     110             :     {
     111          15 :         delta = 2;
     112             :     }
     113          60 :     else if ( output_frame == L_FRAME48k )
     114             :     {
     115          60 :         delta = 3;
     116             :     }
     117             : 
     118             :     /*----------------------------------------------------------------*
     119             :      * set switching frame bitrate
     120             :      *----------------------------------------------------------------*/
     121             : 
     122          75 :     if ( core_switching_flag && st->last_L_frame == st->last_L_frame_ori && ( st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE ) )
     123             :     {
     124          75 :         exc = old_exc + L_EXC_MEM_DEC;
     125          75 :         mvr2r( st->old_exc, old_exc, L_EXC_MEM_DEC );
     126             : 
     127          75 :         if ( st->last_L_frame == L_FRAME )
     128             :         {
     129          15 :             if ( st->core_brate > ACELP_24k40 )
     130             :             {
     131           0 :                 cbrate = ACELP_24k40;
     132             :             }
     133             :             else
     134             :             {
     135          15 :                 cbrate = st->core_brate;
     136             :             }
     137          15 :             L_frame_for_cs = L_FRAME;
     138             :         }
     139             :         else
     140             :         {
     141          60 :             if ( st->core_brate <= ACELP_8k00 )
     142             :             {
     143           0 :                 cbrate = ACELP_8k00;
     144             :             }
     145          60 :             else if ( st->core_brate <= ACELP_14k80 )
     146             :             {
     147           0 :                 cbrate = ACELP_14k80;
     148             :             }
     149             :             else
     150             :             {
     151          60 :                 cbrate = min( st->core_brate, ACELP_22k60 );
     152             :             }
     153             : 
     154          60 :             L_frame_for_cs = L_FRAME16k;
     155             :         }
     156             : 
     157             :         /*----------------------------------------------------------------*
     158             :          * Excitation decoding
     159             :          *----------------------------------------------------------------*/
     160             : 
     161          75 :         config_acelp1( DEC, st->total_brate, cbrate, st->core, -1, -1, st->last_L_frame, -1, &( st->acelp_cfg ), st->next_bit_pos, GENERIC, st->inactive_coder_type_flag, -1, -1, &decode_bwe /* dummy */, &i, st->element_mode, &i /*dummy*/, 0, 0, st->idchan, st->active_cnt, 0, 0, 0 /*st->GSC_IVAS_mode*/ );
     162             : 
     163          75 :         decod_gen_voic_core_switch( st, L_frame_for_cs, 0, Aq, exc, cbrate );
     164             : 
     165             :         /*----------------------------------------------------------------*
     166             :          * synthesis, deemphasis, postprocessing and resampling
     167             :          *----------------------------------------------------------------*/
     168             : 
     169             :         /* synthesis and deemphasis */
     170          75 :         syn_12k8( 2 * L_SUBFR, Aq, exc, synth_intFreq, st->mem_syn2, 1 );
     171             : 
     172          75 :         if ( st->hPFstat->on && st->last_bwidth == NB )
     173             :         {
     174             :             float tmp_noise, pitch_buf_tmp[2];
     175           0 :             tmp_noise = 0;
     176             : 
     177           0 :             for ( i = 0; i < 2; i++ )
     178             :             {
     179           0 :                 pitch_buf_tmp[i] = L_SUBFR;
     180             :             }
     181             : 
     182           0 :             nb_post_filt( 2 * L_SUBFR, L_SUBFR, st->hPFstat, &tmp_noise, 0, synth_intFreq, Aq, pitch_buf_tmp, AUDIO, st->BER_detect, 0 );
     183             :         }
     184             : 
     185          75 :         if ( L_frame_for_cs == L_FRAME )
     186             :         {
     187          15 :             deemph( synth_intFreq, PREEMPH_FAC, 2 * L_SUBFR, &st->mem_deemph );
     188             :         }
     189             :         else
     190             :         {
     191          60 :             deemph( synth_intFreq, PREEMPH_FAC_16k, 2 * L_SUBFR, &st->mem_deemph );
     192             :         }
     193             : 
     194          75 :         AGC_dec( synth_intFreq, st->agc_mem2, 2 * L_SUBFR );
     195             : 
     196          75 :         if ( st->hPFstat->on && st->last_bwidth != NB )
     197             :         {
     198          24 :             mvr2r( st->hPFstat->mem_pf_in + L_SYN_MEM - M, bpf_error_signal, M ); /*bpf_error_signal used as temporary buffer*/
     199          24 :             mvr2r( synth_intFreq, bpf_error_signal + M, L_SUBFR );
     200          24 :             residu( Aq, M, bpf_error_signal + M, old_exc, L_SUBFR );
     201          24 :             syn_filt( Aq, M, old_exc, bpf_error_signal, L_SUBFR, st->hPFstat->mem_stp + L_SYN_MEM - M, 0 );
     202          24 :             scale_st( synth_intFreq, bpf_error_signal, &st->hPFstat->gain_prec, L_SUBFR, -1 );
     203          24 :             mvr2r( bpf_error_signal, synth_intFreq, L_SUBFR / 2 );
     204          24 :             blend_subfr2( bpf_error_signal + L_SUBFR / 2, synth_intFreq + L_SUBFR / 2, synth_intFreq + L_SUBFR / 2 );
     205             :         }
     206          75 :         st->hPFstat->on = 0;
     207             : 
     208          75 :         if ( st->flag_cna )
     209             :         {
     210          15 :             generate_masking_noise( synth_intFreq, st->hFdCngDec->hFdCngCom, 2 * L_SUBFR, 0, 0, 0, st->element_mode, NULL, nchan_out );
     211             :         }
     212             : 
     213             :         /*----------------------------------------------------------------*
     214             :          * Resample to the output sampling rate (8/16/32/48 kHz)
     215             :          * Bass post-filter
     216             :          *----------------------------------------------------------------*/
     217             : 
     218             :         /* bass post-filter */
     219          75 :         bass_psfilter( st->hBPF, st->Opt_AMR_WB, synth_intFreq, 2 * L_SUBFR, NULL, st->bpf_off, st->stab_fac, &st->stab_fac_smooth, GENERIC, bpf_error_signal );
     220             : 
     221             :         /* CLDFB analysis of the synthesis at internal sampling rate */
     222          75 :         if ( ( error = cldfb_save_memory( st->cldfbAna ) ) != IVAS_ERR_OK )
     223             :         {
     224           0 :             return error;
     225             :         }
     226             : 
     227          75 :         cldfbAnalysis( synth_intFreq, realBuffer, imagBuffer, NS2SA( L_frame_for_cs * FRAMES_PER_SEC, SWITCH_GAP_LENGTH_NS + DELAY_CLDFB_NS ), st->cldfbAna );
     228          75 :         cldfb_restore_memory( st->cldfbAna );
     229             : 
     230             :         /* CLDFB analysis and add the BPF error signal */
     231          75 :         if ( ( error = cldfb_save_memory( st->cldfbBPF ) ) != IVAS_ERR_OK )
     232             :         {
     233           0 :             return error;
     234             :         }
     235             : 
     236          75 :         addBassPostFilter( bpf_error_signal, st->bpf_off ? 0 : NS2SA( L_frame_for_cs * FRAMES_PER_SEC, SWITCH_GAP_LENGTH_NS + DELAY_CLDFB_NS ), realBuffer, imagBuffer, st->cldfbBPF );
     237          75 :         cldfb_restore_memory( st->cldfbBPF );
     238             : 
     239             :         /* CLDFB synthesis of the combined signal */
     240          75 :         if ( ( error = cldfb_save_memory( st->cldfbSyn ) ) != IVAS_ERR_OK )
     241             :         {
     242           0 :             return error;
     243             :         }
     244             : 
     245          75 :         cldfbSynthesis( realBuffer, imagBuffer, synth_subfr_out, NS2SA( st->output_Fs, SWITCH_GAP_LENGTH_NS + DELAY_CLDFB_NS ), st->cldfbSyn );
     246          75 :         cldfb_restore_memory( st->cldfbSyn );
     247             : 
     248          75 :         mvr2r( synth_intFreq + NS2SA( L_frame_for_cs * FRAMES_PER_SEC, SWITCH_GAP_LENGTH_NS - DELAY_CLDFB_NS ) - 2, mem_synth, NS2SA( L_frame_for_cs * FRAMES_PER_SEC, DELAY_CLDFB_NS ) + 2 ); /* need for switching (-2 is due to 0 delay filtering) */
     249             : 
     250             :         /*----------------------------------------------------------------*
     251             :          * BWE decoding
     252             :          *----------------------------------------------------------------*/
     253             : 
     254          75 :         decode_bwe = 0;
     255          75 :         if ( !( ( inner_frame_tbl[st->bwidth] == L_FRAME16k && st->last_L_frame == L_FRAME16k ) || inner_frame_tbl[st->bwidth] == L_FRAME8k ) )
     256             :         {
     257             :             /* Decoding of BWE */
     258          75 :             d1m = get_next_indice( st, AUDIODELAYBITS );
     259          75 :             ind1 = get_next_indice( st, NOOFGAINBITS1 );
     260          75 :             gain = usdequant( ind1, MINVALUEOFFIRSTGAIN, DELTAOFFIRSTGAIN );
     261          75 :             decode_bwe = 1;
     262             :         }
     263             : 
     264             : 
     265          75 :         if ( decode_bwe && !( ( output_frame == L_FRAME16k && st->last_L_frame == L_FRAME16k ) || output_frame == L_FRAME8k ) )
     266             :         {
     267          75 :             set_f( tmp_mem2, 0, 2 * L_FILT48k );
     268             : 
     269          75 :             hp_filter = hp16000_48000;
     270          75 :             fdelay = 48;
     271          75 :             if ( st->output_Fs == 16000 )
     272             :             {
     273           0 :                 if ( st->last_L_frame == L_FRAME )
     274             :                 {
     275           0 :                     hp_filter = hp12800_16000;
     276           0 :                     fdelay = 20;
     277             :                 }
     278             :             }
     279          75 :             else if ( st->output_Fs == 32000 )
     280             :             {
     281             : 
     282          15 :                 if ( st->last_L_frame == L_FRAME )
     283             :                 {
     284          15 :                     hp_filter = hp12800_32000;
     285          15 :                     fdelay = 40;
     286             :                 }
     287             :                 else
     288             :                 {
     289           0 :                     hp_filter = hp16000_32000;
     290           0 :                     fdelay = 32;
     291             :                 }
     292             :             }
     293          60 :             else if ( st->last_L_frame == L_FRAME )
     294             :             {
     295           0 :                 hp_filter = hp12800_48000;
     296           0 :                 fdelay = 60;
     297             :             }
     298             : 
     299             :             /* safety check in case of bit errors */
     300          75 :             i = MAX_D1M_16k;
     301          75 :             if ( st->last_L_frame == L_FRAME )
     302             :             {
     303          15 :                 i = MAX_D1M_12k8;
     304             :             }
     305             : 
     306          75 :             if ( d1m >= i )
     307             :             {
     308           0 :                 d1m = i - 1;
     309           0 :                 gain = 0; /* force muting */
     310           0 :                 st->BER_detect = 1;
     311             :             }
     312             : 
     313          75 :             i = NS2SA( st->output_Fs, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS );
     314          75 :             mvr2r( st->old_synth_sw, hb_synth_tmp, i );
     315          75 :             set_f( hb_synth_tmp + i, 0, NS2SA( st->output_Fs, 10000000L ) - i );
     316          75 :             fir( hb_synth_tmp, hp_filter, hb_synth_tmp, tmp_mem2, output_frame >> 1, fdelay, 0 ); /* put the 40 past samples into the memory */
     317          75 :             set_f( tmp_synth_bwe, 0, SWITCH_MAX_GAP );
     318             : 
     319          75 :             gapsize = delta * ( NS2SA( 16000, SWITCH_GAP_LENGTH_NS ) );
     320       21075 :             for ( i = 0; i < gapsize; i++ )
     321             :             {
     322       21000 :                 tmp_synth_bwe[i] = hb_synth_tmp[i + d1m * delta + fdelay] * gain;
     323             :             }
     324             :         }
     325             :         else
     326             :         {
     327           0 :             set_f( tmp_synth_bwe, 0, SWITCH_MAX_GAP );
     328             :         }
     329             :     }
     330             : 
     331          75 :     return error;
     332             : }
     333             : 
     334             : 
     335             : /*-------------------------------------------------------------------*
     336             :  * acelp_core_switch_dec_bfi()
     337             :  *
     338             :  * ACELP core decoder in the first ACELP->HQ switching frame in case of BAD frame
     339             :  *-------------------------------------------------------------------*/
     340             : 
     341       11706 : ivas_error acelp_core_switch_dec_bfi(
     342             :     Decoder_State *st /* i/o: decoder state structure  */
     343             : )
     344             : {
     345             :     int16_t i;
     346             :     float old_exc[L_EXC_DEC], *exc;                                              /* excitation signal buffer              */
     347             :     float syn[L_FRAME16k];                                                       /* synthesis signal buffer               */
     348             :     float lsf_new[M];                                                            /* LSFs at the end of the frame          */
     349             :     float lsp_new[M];                                                            /* LSPs at the end of the frame          */
     350             :     float Aq[NB_SUBFR16k * ( M + 1 )];                                           /* A(q)   quantized for the 4 subframes  */
     351             :     float old_exc2[L_FRAME16k + L_EXC_MEM], *exc2;                               /* total excitation buffer               */
     352             :     float tmp_noise;                                                             /* Long term temporary noise energy      */
     353             :     float FEC_pitch;                                                             /* FEC pitch                             */
     354             :     float old_bwe_exc[( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 )]; /* excitation buffer    */
     355             :     float *bwe_exc;                                                              /* Excitation for SWB TBE                */
     356             :     float tmp_float[NBPSF_PIT_MAX];
     357             :     float tmp_float2[M];
     358             :     float tmp_float3;
     359             :     float tmp_float4[L_TRACK_HIST];
     360             :     int16_t tmp_float5[L_TRACK_HIST];
     361             :     int16_t tmp_float6[L_TRACK_HIST];
     362             :     float tmp_float7;
     363             : 
     364             :     float voice_factors[NB_SUBFR16k];
     365             :     float pitch_buf[NB_SUBFR16k];
     366             :     float *realBuffer[CLDFB_NO_COL_MAX_SWITCH_BFI], *imagBuffer[CLDFB_NO_COL_MAX_SWITCH_BFI];
     367             :     float realBufferTmp[CLDFB_NO_COL_MAX_SWITCH_BFI][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX_SWITCH_BFI][CLDFB_NO_CHANNELS_MAX];
     368             :     ivas_error error;
     369             : 
     370       11706 :     error = IVAS_ERR_OK;
     371             : 
     372             :     /*----------------------------------------------------------------*
     373             :      * Initialization
     374             :      *----------------------------------------------------------------*/
     375             : 
     376             :     /* initialize CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
     377      128766 :     for ( i = 0; i < CLDFB_NO_COL_MAX_SWITCH_BFI; i++ )
     378             :     {
     379      117060 :         set_f( realBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX );
     380      117060 :         set_f( imagBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX );
     381      117060 :         realBuffer[i] = realBufferTmp[i];
     382      117060 :         imagBuffer[i] = imagBufferTmp[i];
     383             :     }
     384             : 
     385       11706 :     st->bpf_off = 1;
     386       11706 :     st->clas_dec = st->last_good;
     387       11706 :     tmp_noise = 0.0f;
     388             : 
     389       11706 :     mvr2r( st->old_exc, old_exc, L_EXC_MEM_DEC );
     390       11706 :     exc = old_exc + L_EXC_MEM_DEC;
     391             : 
     392       11706 :     if ( st->hWIDec != NULL )
     393             :     {
     394           0 :         mvr2r( st->hWIDec->old_exc2, old_exc2, L_EXC_MEM );
     395             :     }
     396             :     else
     397             :     {
     398       11706 :         set_f( old_exc2, 0, L_EXC_MEM );
     399             :     }
     400       11706 :     exc2 = old_exc2 + L_EXC_MEM;
     401             : 
     402       11706 :     if ( st->hBWE_TD != NULL )
     403             :     {
     404       11706 :         mvr2r( st->hBWE_TD->old_bwe_exc, old_bwe_exc, PIT16k_MAX * 2 );
     405       11706 :         bwe_exc = old_bwe_exc + PIT16k_MAX * 2;
     406             :     }
     407             :     else
     408             :     {
     409           0 :         bwe_exc = NULL;
     410             :     }
     411             : 
     412       11706 :     st->GSC_noisy_speech = 0;
     413       11706 :     st->relax_prev_lsf_interp = 0;
     414             : 
     415             :     /* SC-VBR */
     416       11706 :     if ( st->last_nelp_mode_dec == 1 )
     417             :     {
     418           0 :         st->nelp_mode_dec = 1;
     419             :     }
     420             : 
     421       11706 :     mvr2r( st->mem_AR, tmp_float, M );
     422       11706 :     mvr2r( st->mem_MA, tmp_float2, M );
     423             : 
     424             :     /* LSF estimation and A(z) calculation */
     425       11706 :     lsf_dec_bfi( MODE1, lsf_new, st->lsf_old, st->lsf_adaptive_mean, NULL, st->mem_MA, st->mem_AR, st->stab_fac, st->last_coder_type, st->L_frame, st->last_good, st->nbLostCmpt, 0, NULL, NULL, NULL, st->hGSCDec->Last_GSC_pit_band_idx, st->Opt_AMR_WB, st->bwidth );
     426             : 
     427       11706 :     FEC_lsf2lsp_interp( st, st->L_frame, Aq, lsf_new, lsp_new );
     428             : 
     429       11706 :     mvr2r( tmp_float, st->mem_AR, M );
     430       11706 :     mvr2r( tmp_float2, st->mem_MA, M );
     431             : 
     432             :     /*----------------------------------------------------------------*
     433             :      * Excitation decoding
     434             :      *----------------------------------------------------------------*/
     435             : 
     436       11706 :     if ( st->nelp_mode_dec == 1 )
     437             :     {
     438             :         /* SC-VBR */
     439           0 :         decod_nelp( st, &tmp_noise, pitch_buf, exc, exc2, voice_factors, bwe_exc, st->bfi, tmp_float2 );
     440           0 :         FEC_pitch = pitch_buf[3];
     441             :     }
     442             :     else
     443             :     {
     444       11706 :         tmp_float[0] = st->bfi_pitch;
     445       11706 :         tmp_float[1] = (float) st->bfi_pitch_frame;
     446       11706 :         tmp_float[2] = st->lp_gainp;
     447       11706 :         tmp_float[3] = st->lp_gainc;
     448       11706 :         tmp_float[4] = st->upd_cnt;
     449       11706 :         tmp_float[5] = st->seed;
     450             : 
     451             :         /* calculation of excitation signal */
     452       11706 :         FEC_exc_estim( st, st->L_frame, exc, exc2, syn /* dummy buffer */, pitch_buf, voice_factors, &FEC_pitch, bwe_exc, lsf_new, &tmp_noise );
     453             : 
     454       11706 :         st->seed = (int16_t) tmp_float[5];
     455       11706 :         st->bfi_pitch = tmp_float[0];
     456       11706 :         st->bfi_pitch_frame = (int16_t) tmp_float[1];
     457       11706 :         st->lp_gainp = tmp_float[2];
     458       11706 :         st->lp_gainc = tmp_float[3];
     459       11706 :         st->upd_cnt = (int16_t) tmp_float[4];
     460             :     }
     461             : 
     462             :     /*------------------------------------------------------------------*
     463             :      * Synthesis
     464             :      *-----------------------------------------------------------------*/
     465             : 
     466       11706 :     mvr2r( st->mem_syn2, tmp_float, M );
     467       11706 :     syn_12k8( st->L_frame, Aq, exc2, syn, tmp_float, 1 );
     468             : 
     469       11706 :     tmp_float[0] = st->enr_old;
     470       11706 :     fer_energy( st->L_frame, st->last_good, syn, FEC_pitch, tmp_float, st->L_frame );
     471             : 
     472             :     /*------------------------------------------------------------------*
     473             :      * Perform fixed deemphasis through 1/(1 - g*z^-1)
     474             :      *-----------------------------------------------------------------*/
     475             : 
     476       11706 :     mvr2r( &( st->mem_deemph ), tmp_float, 1 );
     477       11706 :     if ( st->L_frame == L_FRAME )
     478             :     {
     479        3699 :         deemph( syn, PREEMPH_FAC, L_FRAME, tmp_float );
     480             :     }
     481             :     else
     482             :     {
     483        8007 :         deemph( syn, PREEMPH_FAC_16k, L_FRAME16k, tmp_float );
     484             :     }
     485             : 
     486             :     /*----------------------------------------------------------------*
     487             :      * Bass post-filter
     488             :      *----------------------------------------------------------------*/
     489             : 
     490       11706 :     st->bpf_off = 1;
     491       11706 :     mvr2r( st->hBPF->pst_old_syn, tmp_float, NBPSF_PIT_MAX );
     492       11706 :     tmp_float3 = st->stab_fac_smooth;
     493       11706 :     mvr2r( st->hBPF->mem_mean_pit, tmp_float4, L_TRACK_HIST );
     494       11706 :     mvs2s( st->hBPF->Track_on_hist, tmp_float5, L_TRACK_HIST );
     495       11706 :     mvs2s( st->hBPF->vibrato_hist, tmp_float6, L_TRACK_HIST );
     496       11706 :     tmp_float7 = st->hBPF->psf_att;
     497             : 
     498             :     /* apply bass post-filter */
     499       11706 :     bass_psfilter( st->hBPF, st->Opt_AMR_WB, syn, st->L_frame, pitch_buf, st->bpf_off, st->stab_fac, &tmp_float3, st->coder_type, old_exc /* tmp buffer */ );
     500             : 
     501       11706 :     mvr2r( tmp_float, st->hBPF->pst_old_syn, NBPSF_PIT_MAX );
     502       11706 :     mvr2r( tmp_float4, st->hBPF->mem_mean_pit, L_TRACK_HIST );
     503       11706 :     mvs2s( tmp_float5, st->hBPF->Track_on_hist, L_TRACK_HIST );
     504       11706 :     mvs2s( tmp_float6, st->hBPF->vibrato_hist, L_TRACK_HIST );
     505       11706 :     st->hBPF->psf_att = tmp_float7;
     506             : 
     507             :     /*----------------------------------------------------------------*
     508             :      * Resampling to the output sampling frequency
     509             :      *----------------------------------------------------------------*/
     510             : 
     511             :     /* CLDFB analysis of the synthesis at internal sampling rate */
     512       11706 :     if ( ( error = cldfb_save_memory( st->cldfbAna ) ) != IVAS_ERR_OK )
     513             :     {
     514           0 :         return error;
     515             :     }
     516             : 
     517       11706 :     cldfbAnalysis( syn, realBuffer, imagBuffer, st->L_frame / 2, st->cldfbAna );
     518       11706 :     cldfb_restore_memory( st->cldfbAna );
     519             : 
     520             :     /* CLDFB synthesis of the combined signal */
     521       11706 :     if ( ( error = cldfb_save_memory( st->cldfbSyn ) ) != IVAS_ERR_OK )
     522             :     {
     523           0 :         return error;
     524             :     }
     525             : 
     526       11706 :     cldfbSynthesis( realBuffer, imagBuffer, st->hHQ_core->fer_samples, (int16_t) ( st->output_Fs * 0.01f ), st->cldfbSyn );
     527       11706 :     cldfb_restore_memory( st->cldfbSyn );
     528             : 
     529       11706 :     return error;
     530             : }
     531             : 
     532             : 
     533             : /*-------------------------------------------------------------------*
     534             :  * decod_gen_voic_core_switch()
     535             :  *
     536             :  * Decode excitation signal in the first ACELP->HQ switching frame
     537             :  *-------------------------------------------------------------------*/
     538             : 
     539          75 : static void decod_gen_voic_core_switch(
     540             :     Decoder_State *st,       /* i/o: decoder static memory       */
     541             :     const int16_t L_frame,   /* i  : length of the frame         */
     542             :     const int16_t sharpFlag, /* i  : flag for formant sharpening */
     543             :     const float *Aq,         /* i  : LP filter coefficient       */
     544             :     float *exc,              /* i/o: adapt. excitation exc       */
     545             :     const int32_t core_brate /* i  : switching frame bitrate     */
     546             : )
     547             : {
     548             :     int16_t T0, T0_frac, T0_min, T0_max; /* integer pitch variables                              */
     549             :     float gain_pit;                      /* pitch gain                                           */
     550             :     float gain_code;                     /* gain/normalized gain of the algebraic excitation     */
     551             :     float norm_gain_code;                /* normalized gain of the algebraic excitation          */
     552             :     float gain_inov;                     /* Innovation gain                                      */
     553             :     float voice_fac;                     /* voicing factor                                       */
     554             :     float code[L_SUBFR];                 /* algebraic codevector                                 */
     555             :     float pitch;                         /* pointer to floating pitch                            */
     556             :     int16_t i;                           /* tmp variables                                        */
     557             :     int16_t pitch_limit_flag;
     558             :     float tmpF;
     559             : 
     560             :     /* initializations */
     561          75 :     if ( L_frame == L_FRAME )
     562             :     {
     563          15 :         T0_max = PIT_MAX;
     564          15 :         T0_min = PIT_MIN;
     565             :     }
     566             :     else /* L_frame == L_FRAME16k */
     567             :     {
     568          60 :         T0_max = PIT16k_MAX;
     569          60 :         T0_min = PIT16k_MIN;
     570             :     }
     571             : 
     572             :     /*----------------------------------------------------------------------*
     573             :      * Decode pitch lag
     574             :      *----------------------------------------------------------------------*/
     575             : 
     576          75 :     pitch = pit_decode( st, core_brate, 0, L_frame, 0, GENERIC, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_SUBFR, 0, NULL );
     577             : 
     578             :     /*--------------------------------------------------------------*
     579             :      * Find the adaptive codebook vector.
     580             :      *--------------------------------------------------------------*/
     581             : 
     582          75 :     pred_lt4( &exc[0], &exc[0], T0, T0_frac, L_SUBFR + 1, inter4_2, L_INTERPOL2, PIT_UP_SAMP );
     583             : 
     584             :     /*--------------------------------------------------------------*
     585             :      * LP filtering of the adaptive excitation
     586             :      *--------------------------------------------------------------*/
     587             : 
     588          75 :     lp_filt_exc_dec( st, MODE1, 0, L_SUBFR, L_frame, st->acelp_cfg.ltf_mode, exc );
     589             : 
     590             :     /*--------------------------------------------------------------*
     591             :      * Innovation decoding
     592             :      *--------------------------------------------------------------*/
     593             : 
     594          75 :     inov_decode( st, core_brate, 0, L_frame, sharpFlag, 0, Aq, st->tilt_code, pitch, code, L_SUBFR );
     595             : 
     596             :     /*--------------------------------------------------------------*
     597             :      * Gain decoding
     598             :      * Estimate spectrum tilt and voicing
     599             :      *--------------------------------------------------------------*/
     600             : 
     601          75 :     if ( L_frame == L_FRAME )
     602             :     {
     603          15 :         gain_dec_mless( st, L_frame, TRANSITION, 0, -1, code, st->old_Es_pred, &gain_pit, &gain_code, &gain_inov, &norm_gain_code );
     604             :     }
     605             :     else
     606             :     {
     607          60 :         gain_dec_mless( st, L_frame, GENERIC, 0, -1, code, st->old_Es_pred, &gain_pit, &gain_code, &gain_inov, &norm_gain_code );
     608             :     }
     609             : 
     610          75 :     st->tilt_code = est_tilt( exc, gain_pit, code, gain_code, &voice_fac, L_SUBFR, 0 );
     611             : 
     612             :     /*----------------------------------------------------------------------*
     613             :      * Find the total excitation
     614             :      *----------------------------------------------------------------------*/
     615             : 
     616          75 :     if ( st->prev_bfi )
     617             :     {
     618           0 :         gain_code = min( gain_code, 0.5f * gain_code + 0.5f * st->lp_gainc );
     619             :     }
     620             : 
     621        4875 :     for ( i = 0; i < L_SUBFR; i++ )
     622             :     {
     623        4800 :         tmpF = gain_pit * exc[i];
     624        4800 :         exc[i] = tmpF + gain_code * code[i];
     625             :     }
     626             : 
     627             :     /*-----------------------------------------------------------------*
     628             :      * long term prediction on the 2nd sub frame
     629             :      *-----------------------------------------------------------------*/
     630             : 
     631          75 :     pred_lt4( &exc[L_SUBFR], &exc[L_SUBFR], T0, T0_frac, L_SUBFR + 1, inter4_2, L_INTERPOL2, PIT_UP_SAMP );
     632             : 
     633        4875 :     for ( i = 0; i < L_SUBFR; i++ )
     634             :     {
     635        4800 :         exc[i + L_SUBFR] *= gain_pit;
     636             :     }
     637             : 
     638          75 :     return;
     639             : }

Generated by: LCOV version 1.14