LCOV - code coverage report
Current view: top level - lib_enc - amr_wb_enc.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 6 154 3.9 %
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             : /*====================================================================================
      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_enc.h"
      44             : #include "rom_com.h"
      45             : #include "prot.h"
      46             : #include "wmc_auto.h"
      47             : 
      48             : #ifdef DEBUG_MODE_INFO
      49             : extern float snr_[2][320];
      50             : #endif
      51             : 
      52             : /*-------------------------------------------------------------------*
      53             :  * amr_wb_enc()
      54             :  *
      55             :  * AMR-WB encoder
      56             :  *-------------------------------------------------------------------*/
      57             : 
      58           0 : void amr_wb_enc(
      59             :     Encoder_State *st,       /* i/o: encoder state structure */
      60             :     const int16_t *input_sp, /* i  : input signal            */
      61             :     float *mem_hp20_in,      /* i/o: hp20 filter memory      */
      62             :     const int16_t n_samples  /* i  : number of input samples */
      63             : )
      64             : {
      65             :     int16_t i, delay, harm_flag;
      66             :     float old_inp[L_INP_12k8], *new_inp, *inp;                       /* buffer of old input signal           */
      67             :     float old_inp_16k[L_INP_12k8 + L_SUBFR], *inp_16k, *new_inp_16k; /* buffer of old input signal @16kHz*/
      68             :     float old_exc[L_EXC], *exc;                                      /* excitation signal buffer             */
      69             :     float old_wsp[L_WSP], *wsp;                                      /* weighted input signal buffer         */
      70             :     int16_t input_frame;                                             /* frame length at input sampling freq. */
      71             :     float fr_bands[2 * NB_BANDS];                                    /* energy in frequency bands            */
      72             :     float lf_E[2 * VOIC_BINS];                                       /* per bin spectrum energy in lf        */
      73             :     float tmpN[NB_BANDS];                                            /* temporary noise update               */
      74             :     float tmpE[NB_BANDS], PS[L_FFT / 2];                             /* temporary averaged energy of 2 sf.   */
      75             :     float corr_shift;                                                /* correlation shift                    */
      76             :     float relE;                                                      /* frame relative energy                */
      77             :     float non_staX, cor_map_sum, sp_div;
      78             :     float Etot;                     /* total energy                         */
      79             :     float ener;                     /* residual energy from Levinson-Durbin */
      80             :     float A[NB_SUBFR * ( M + 1 )];  /* A(z) unquantized for the 4 subframes */
      81             :     float Aw[NB_SUBFR * ( M + 1 )]; /* weigted A(z) unquant. for 4 subframes*/
      82             :     float epsP[M + 1];              /* LP prediction errors                 */
      83             :     float isp_new[M];               /* ISPs at the end of the frame         */
      84             :     float isf_new[M];               /* ISFs at the end of the frame         */
      85             :     float isp_tmp[M];
      86             :     float Aq[NB_SUBFR * ( M + 1 )]; /* A(z) quantized for the 4 subframes   */
      87             :     float syn[L_FRAME];             /* synthesis vector                     */
      88             :     float res[L_FRAME];             /* residual signal for FER protection   */
      89             :     float exc2[L_FRAME];            /* enhanced excitation                  */
      90             :     float pitch_buf[NB_SUBFR];      /* floating pitch for each subframe     */
      91             :     float dummy_buf[L_FRAME32k];    /* dummy buffer - no usage              */
      92             :     float snr_sum_he;
      93             :     int16_t allow_cn_step;
      94             :     int16_t localVAD_HE_SAD;
      95             :     int16_t tmps;
      96             :     int16_t vad_flag_dtx;
      97             :     int16_t vad_hover_flag;
      98             :     int16_t hf_gain[NB_SUBFR];
      99             :     int16_t high_lpn_flag;
     100             :     float lp_bckr, hp_bckr;
     101             :     float q_env[NUM_ENV_CNG];
     102           0 :     int16_t sid_bw = 0;
     103             :     float exc3[L_FRAME];
     104             :     float fft_buff[2 * L_FFT];
     105             :     float sp_floor;
     106             :     float tmp;
     107             :     int16_t old_pitch1;
     108             : 
     109           0 :     LPD_state_HANDLE hLPDmem = st->hLPDmem;
     110             : 
     111             :     /*------------------------------------------------------------------*
     112             :      * Initialization
     113             :      *------------------------------------------------------------------*/
     114             : 
     115           0 :     st->L_frame = L_FRAME;
     116           0 :     st->gamma = GAMMA1;
     117           0 :     st->core = AMR_WB_CORE;
     118           0 :     st->core_brate = st->total_brate;
     119           0 :     st->input_bwidth = st->last_input_bwidth;
     120           0 :     st->bwidth = st->last_bwidth;
     121           0 :     st->extl = -1;
     122           0 :     st->mdct_sw = 0;
     123           0 :     st->coder_type = GENERIC;
     124           0 :     input_frame = (int16_t) ( st->input_Fs / FRAMES_PER_SEC ); /* frame length of the input signal */
     125           0 :     st->encoderPastSamples_enc = ( L_FRAME * 9 ) / 16;
     126           0 :     st->encoderLookahead_enc = L_LOOK_12k8;
     127             : 
     128             : #ifdef DEBUG_MODE_INFO
     129             :     set_f( snr_[0], 0.0f, 320 );
     130             : #endif
     131             : 
     132           0 :     st->bpf_off = 0;
     133           0 :     if ( st->last_core == HQ_CORE || st->last_codec_mode == MODE2 )
     134             :     {
     135           0 :         st->bpf_off = 1;
     136             :     }
     137             : 
     138           0 :     st->igf = 0;
     139             : 
     140             :     /* Updates in case of EVS primary mode -> AMR-WB IO mode switching */
     141           0 :     if ( st->last_core != AMR_WB_CORE )
     142             :     {
     143           0 :         updt_IO_switch_enc( st, input_frame );
     144             :     }
     145             : 
     146             :     /* Updates in case of HQ -> AMR-WB IO switching */
     147           0 :     core_switching_pre_enc( st, NULL, NULL, 0, 0 );
     148             : 
     149           0 :     set_s( hf_gain, 0, NB_SUBFR );
     150             : 
     151           0 :     set_f( old_inp, 0.0f, L_INP_12k8 );
     152           0 :     exc = old_exc + L_EXC_MEM; /* pointer to excitation signal in the current frame */
     153           0 :     mvr2r( hLPDmem->old_exc, old_exc, L_EXC_MEM );
     154             : 
     155           0 :     new_inp = old_inp + L_INP_MEM; /* pointer to new samples of the input signal */
     156           0 :     inp = new_inp - L_LOOK_12k8;   /* pointer to current frame of input signal */
     157           0 :     wsp = old_wsp + L_WSP_MEM;     /* pointer to current frame of weighted signal */
     158             : 
     159           0 :     mvr2r( st->old_inp_12k8, old_inp, L_INP_MEM );
     160           0 :     mvr2r( st->old_wsp, old_wsp, L_WSP_MEM );
     161             : 
     162           0 :     new_inp_16k = old_inp_16k + L_INP_MEM; /* pointer to new samples of the input signal in 16kHz core */
     163           0 :     inp_16k = new_inp_16k - L_LOOK_16k;    /* pointer to the current frame of input signal in 16kHz core */
     164           0 :     mvr2r( st->old_inp_16k, old_inp_16k, L_INP_MEM );
     165             : 
     166             :     /* in case of switching, reset AMR-WB BWE memories */
     167           0 :     if ( st->total_brate == ACELP_23k85 && st->last_core_brate != ACELP_23k85 )
     168             :     {
     169           0 :         hf_cod_init( st->hAmrwb_IO->mem_hp400_enc, st->hAmrwb_IO->mem_hf_enc, st->hAmrwb_IO->mem_syn_hf_enc, st->hAmrwb_IO->mem_hf2_enc, &st->hAmrwb_IO->gain_alpha );
     170             :     }
     171             : 
     172             :     /*----------------------------------------------------------------*
     173             :      * set input samples buffer
     174             :      *----------------------------------------------------------------*/
     175             : 
     176             :     /* get delay to synchronize ACELP and MDCT frame */
     177           0 :     delay = NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS );
     178             : 
     179           0 :     mvr2r( st->input - delay, st->old_input_signal, input_frame + delay );
     180             : 
     181             :     /*----------------------------------------------------------------*
     182             :      * Buffering of input signal
     183             :      * (convert 'short' input data to 'float')
     184             :      * HP filtering
     185             :      *----------------------------------------------------------------*/
     186             : 
     187           0 :     mvs2r( input_sp, st->input, n_samples );
     188             : 
     189           0 :     for ( i = n_samples; i < input_frame; i++ )
     190             :     {
     191           0 :         st->input[i] = 0;
     192             :     }
     193             : 
     194           0 :     hp20( st->input, input_frame, mem_hp20_in, st->input_Fs );
     195             : 
     196             :     /*-----------------------------------------------------------------*
     197             :      * switching from ACELP@16k core to AMR-WB IO mode
     198             :      *-----------------------------------------------------------------*/
     199             : 
     200           0 :     st->rate_switching_reset = 0;
     201             : 
     202           0 :     if ( st->last_core != AMR_WB_CORE && st->last_L_frame == L_FRAME16k && st->last_core != HQ_CORE )
     203             :     {
     204             :         /* in case of switching, do not apply BPF */
     205           0 :         st->bpf_off = 1;
     206             :         /* convert old quantized LSP vector */
     207           0 :         st->rate_switching_reset = lsp_convert_poly( st->lsp_old, L_FRAME, 1 );
     208             : 
     209             :         /* convert old quantized LSF vector */
     210           0 :         lsp2lsf( st->lsp_old, st->lsf_old, M, INT_FS_12k8 );
     211             : 
     212             :         /* Reset LPC mem */
     213           0 :         mvr2r( GEWB_Ave, st->mem_AR, M );
     214           0 :         set_zero( st->mem_MA, M );
     215             : 
     216             :         /* update synthesis filter memories */
     217           0 :         synth_mem_updt2( L_FRAME, st->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn1, hLPDmem->mem_syn, ENC );
     218           0 :         mvr2r( hLPDmem->old_exc, old_exc, L_EXC_MEM );
     219           0 :         mvr2r( hLPDmem->mem_syn1, hLPDmem->mem_syn2, M );
     220           0 :         mvr2r( hLPDmem->mem_syn2, hLPDmem->mem_syn3, M );
     221             : 
     222             :         /* lsp -> isp */
     223           0 :         mvr2r( stable_ISP, isp_tmp, M );
     224           0 :         lsp2isp( st->lsp_old, st->lsp_old, isp_tmp, M );
     225             :     }
     226             : 
     227             :     /* update buffer of old subframe pitch values */
     228           0 :     if ( st->last_L_frame != L_FRAME )
     229             :     {
     230           0 :         if ( st->last_L_frame == L_FRAME32k )
     231             :         {
     232           0 :             tmp = (float) 12800 / (float) 32000;
     233             :         }
     234           0 :         else if ( st->last_L_frame == 512 )
     235             :         {
     236           0 :             tmp = (float) 12800 / (float) 25600;
     237             :         }
     238             :         else /* st->last_L_frame == L_FRAME16k */
     239             :         {
     240           0 :             tmp = (float) 12800 / (float) 16000;
     241             :         }
     242             : 
     243           0 :         for ( i = NB_SUBFR16k - NB_SUBFR; i < NB_SUBFR16k; i++ )
     244             :         {
     245           0 :             st->old_pitch_buf[i - 1] = tmp * st->old_pitch_buf[i];
     246             :         }
     247             : 
     248           0 :         for ( i = 2 * NB_SUBFR16k - NB_SUBFR; i < 2 * NB_SUBFR16k; i++ )
     249             :         {
     250           0 :             st->old_pitch_buf[i - 2] = tmp * st->old_pitch_buf[i];
     251             :         }
     252             :     }
     253           0 :     if ( st->last_bwidth == NB && st->ini_frame != 0 )
     254             :     {
     255           0 :         st->rate_switching_reset = 1;
     256             :     }
     257             : 
     258             :     /*----------------------------------------------------------------*
     259             :      * Change the sampling frequency to 12.8 kHz
     260             :      *----------------------------------------------------------------*/
     261             : 
     262           0 :     modify_Fs( st->input, input_frame, st->input_Fs, new_inp, 12800, st->mem_decim, 0 );
     263             : 
     264             :     /* update signal buffer */
     265           0 :     mvr2r( new_inp, st->buf_speech_enc + L_FRAME, L_FRAME );
     266             : 
     267             :     /*------------------------------------------------------------------*
     268             :      * Perform fixed preemphasis through 1 - g*z^-1
     269             :      *-----------------------------------------------------------------*/
     270             : 
     271           0 :     preemph( new_inp, PREEMPH_FAC, L_FRAME, &st->mem_preemph );
     272             : 
     273             :     /*----------------------------------------------------------------*
     274             :      * Compute spectrum, find energy per critical frequency band
     275             :      * Track energy and signal dynamics
     276             :      * Detect NB spectrum in a 16kHz-sampled input
     277             :      *----------------------------------------------------------------*/
     278             : 
     279           0 :     analy_sp( -1, NULL, st->input_Fs, inp, st->Bin_E, st->Bin_E_old, fr_bands, lf_E, &Etot, st->min_band, st->max_band, dummy_buf, PS, fft_buff );
     280             : 
     281           0 :     noise_est_pre( Etot, st->ini_frame, st->hNoiseEst, 0, EVS_MONO, EVS_MONO );
     282             : 
     283             :     /*----------------------------------------------------------------*
     284             :      * VAD
     285             :      *----------------------------------------------------------------*/
     286             : 
     287           0 :     st->vad_flag = wb_vad( st, fr_bands, &tmps, &tmps, &tmps, &snr_sum_he, &localVAD_HE_SAD, &( st->flag_noisy_speech_snr ), NULL, NULL, -1000.0f, -1000.0f );
     288             : 
     289           0 :     if ( st->vad_flag == 0 )
     290             :     {
     291           0 :         st->coder_type = INACTIVE;
     292             :     }
     293             : 
     294             :     /* apply DTX hangover for CNG analysis */
     295           0 :     vad_flag_dtx = dtx_hangover_addition( st, st->vad_flag, st->lp_speech - st->lp_noise, 0, &vad_hover_flag, NULL, NULL, NULL );
     296             : 
     297             :     /*-----------------------------------------------------------------*
     298             :      * Select SID or FRAME_NO_DATA frame if DTX enabled
     299             :      *-----------------------------------------------------------------*/
     300             : 
     301           0 :     if ( st->last_core != AMR_WB_CORE )
     302             :     {
     303           0 :         st->fd_cng_reset_flag = 1;
     304             :     }
     305           0 :     else if ( st->fd_cng_reset_flag > 0 && st->fd_cng_reset_flag < 10 )
     306             :     {
     307           0 :         st->fd_cng_reset_flag++;
     308             :     }
     309             :     else
     310             :     {
     311           0 :         st->fd_cng_reset_flag = 0;
     312             :     }
     313             : 
     314           0 :     dtx( st, -1, -1, vad_flag_dtx, inp );
     315             : 
     316             :     /*----------------------------------------------------------------*
     317             :      * Noise energy down-ward update and total noise energy estimation
     318             :      * Long-term energies and relative frame energy updates
     319             :      * Correlation correction as a function of total noise level
     320             :      *----------------------------------------------------------------*/
     321             : 
     322           0 :     noise_est_down( fr_bands, st->hNoiseEst->bckr, tmpN, tmpE, st->min_band, st->max_band, &st->hNoiseEst->totalNoise, Etot, &st->hNoiseEst->Etot_last, &st->hNoiseEst->Etot_v_h2 );
     323             : 
     324           0 :     high_lpn_flag = 0;
     325             : 
     326           0 :     long_enr( st, Etot, localVAD_HE_SAD, high_lpn_flag, NULL, 1, NULL, NULL );
     327             : 
     328           0 :     relE = Etot - st->lp_speech;
     329             : 
     330           0 :     if ( st->bwidth != NB )
     331             :     {
     332           0 :         lp_bckr = mean( st->hNoiseEst->bckr, 10 );
     333             :     }
     334             :     else
     335             :     {
     336           0 :         lp_bckr = mean( st->hNoiseEst->bckr + 1, 9 );
     337             :     }
     338           0 :     hp_bckr = 0.5f * ( st->hNoiseEst->bckr[st->max_band - 1] + st->hNoiseEst->bckr[st->max_band] );
     339           0 :     st->bckr_tilt_lt = 0.9f * st->bckr_tilt_lt + 0.1f * lp_bckr / hp_bckr;
     340             : 
     341           0 :     corr_shift = correlation_shift( st->hNoiseEst->totalNoise );
     342             : 
     343             :     /*----------------------------------------------------------------*
     344             :      * WB, SWB and FB bandwidth detector
     345             :      *----------------------------------------------------------------*/
     346             : 
     347           0 :     bw_detect( st, st->input, NULL, NULL, MONO_FORMAT, 0 );
     348             : 
     349             :     /* in AMR_WB IO, limit the maximum band-width to WB */
     350           0 :     if ( st->bwidth > WB )
     351             :     {
     352           0 :         st->bwidth = WB;
     353             :     }
     354             : 
     355             :     /*----------------------------------------------------------------*
     356             :      * Perform LP analysis
     357             :      * Compute weighted inp
     358             :      * Perform open-loop pitch analysis
     359             :      * Perform 1/4 pitch precision improvement
     360             :      *----------------------------------------------------------------*/
     361             : 
     362           0 :     if ( st->vad_flag == 0 )
     363             :     {
     364             :         /* reset the OL pitch tracker memories during inactive frames */
     365           0 :         pitch_ol_init( &st->old_thres, &st->old_pitch, &st->delta_pit, &st->old_corr );
     366             :     }
     367             : 
     368           0 :     old_pitch1 = st->pitch[1];
     369             : 
     370             :     /* LP analysis */
     371           0 :     analy_lp_AMR_WB( inp, &ener, A, epsP, isp_new, st->lsp_old1, isf_new, st->old_pitch_la, st->voicing[2] );
     372             : 
     373             :     /* compute weighted input */
     374           0 :     find_wsp( L_FRAME, L_SUBFR, NB_SUBFR, A, Aw, inp, TILT_FAC, wsp, &st->mem_wsp, GAMMA1, L_LOOK_12k8 );
     375             : 
     376             :     /* open-loop pitch analysis */
     377           0 :     pitch_ol( st->pitch, st->voicing, &st->old_pitch, &st->old_corr, corr_shift, &st->old_thres, &st->delta_pit, st->old_wsp2, wsp, st->mem_decim2, relE, L_LOOK_12k8, 0, st->bwidth, 0 );
     378             : 
     379           0 :     st->old_pitch_la = st->pitch[2];
     380           0 :     vad_param_updt( st, corr_shift, corr_shift, A, old_pitch1, NULL, 1 );
     381             : 
     382             :     /*------------------------------------------------------------------*
     383             :      * Update estimated noise energy and voicing cut-off frequency
     384             :      *-----------------------------------------------------------------*/
     385             : 
     386           0 :     noise_est( st, old_pitch1, tmpN, epsP, Etot, relE, corr_shift, tmpE, fr_bands, &cor_map_sum, NULL, &sp_div, &non_staX, &harm_flag, lf_E, &st->hNoiseEst->harm_cor_cnt, st->hNoiseEst->Etot_l_lp, &sp_floor, 0, NULL, NULL, st->ini_frame );
     387             : 
     388             :     /*----------------------------------------------------------------*
     389             :      * Change the sampling frequency to 16 kHz,
     390             :      *   input@16kHz needed for AMR-WB IO BWE @23.85kbps
     391             :      *----------------------------------------------------------------*/
     392             : 
     393           0 :     if ( st->input_Fs == 16000 )
     394             :     {
     395             :         /* no resampling needed, only delay adjustement to account for the FIR resampling delay */
     396           0 :         tmps = NS2SA( 16000, DELAY_FIR_RESAMPL_NS );
     397           0 :         mvr2r( st->mem_decim16k + tmps, new_inp_16k, tmps );
     398           0 :         mvr2r( st->input, new_inp_16k + tmps, input_frame - tmps );
     399           0 :         mvr2r( st->input + input_frame - 2 * tmps, st->mem_decim16k, 2 * tmps );
     400             :     }
     401           0 :     else if ( st->input_Fs == 32000 || st->input_Fs == 48000 )
     402             :     {
     403           0 :         modify_Fs( st->input, input_frame, st->input_Fs, new_inp_16k, 16000, st->mem_decim16k, 0 );
     404             :     }
     405             : 
     406             :     /*----------------------------------------------------------------*
     407             :      * Encoding of SID frames
     408             :      *----------------------------------------------------------------*/
     409             : 
     410           0 :     if ( st->core_brate == SID_1k75 || st->core_brate == FRAME_NO_DATA )
     411             :     {
     412             :         /* encode CNG parameters */
     413           0 :         CNG_enc( st, Aq, inp, ener, isp_new, isp_new, isf_new, &allow_cn_step, q_env, &sid_bw );
     414             : 
     415             :         /* comfort noise generation */
     416           0 :         CNG_exc( st->core_brate, L_FRAME, &st->hTdCngEnc->Enew, &st->hTdCngEnc->cng_seed, exc, exc2, &st->hTdCngEnc->lp_ener, st->last_core_brate, &st->hDtxEnc->first_CNG, &st->hTdCngEnc->cng_ener_seed, dummy_buf, allow_cn_step, &st->hTdCngEnc->last_allow_cn_step, st->hTdCngEnc->num_ho, q_env, st->hTdCngEnc->lp_env, st->hTdCngEnc->old_env, st->hTdCngEnc->exc_mem, st->hTdCngEnc->exc_mem1, &sid_bw, &st->hTdCngEnc->cng_ener_seed1, exc3, st->Opt_AMR_WB, EVS_MONO );
     417             : 
     418           0 :         if ( st->hDtxEnc->first_CNG == 0 )
     419             :         {
     420           0 :             st->hDtxEnc->first_CNG = 1;
     421             :         }
     422             : 
     423             :         /* synthesis */
     424           0 :         syn_12k8( L_FRAME, Aq, exc2, dummy_buf, hLPDmem->mem_syn3, 1 ); /* dummy_buf = temporary buffer to handle syn1[] */
     425             : 
     426             :         /* reset the encoder */
     427           0 :         CNG_reset_enc( st, pitch_buf, dummy_buf + L_FRAME, 0 );
     428             : 
     429             :         /* update mem_syn1 for ACELP core switching */
     430           0 :         mvr2r( hLPDmem->mem_syn3, hLPDmem->mem_syn1, M );
     431             : 
     432             :         /* update ACELP core synthesis filter memory */
     433           0 :         mvr2r( hLPDmem->mem_syn3, hLPDmem->mem_syn, M );
     434             : 
     435             :         /* update old synthesis buffer - needed for ACELP internal sampling rate switching */
     436           0 :         mvr2r( dummy_buf + L_FRAME - L_SYN_MEM, hLPDmem->mem_syn_r, L_SYN_MEM );
     437             : 
     438             :         /* Update MODE2 core switching memory */
     439           0 :         deemph( dummy_buf, PREEMPH_FAC, L_FRAME, &( hLPDmem->syn[M] ) );
     440           0 :         mvr2r( dummy_buf + L_FRAME - M - 1, hLPDmem->syn, M + 1 );
     441             :     }
     442             : 
     443             :     /*----------------------------------------------------------------*
     444             :      * Encoding of all other frames
     445             :      *----------------------------------------------------------------*/
     446             : 
     447             :     else
     448             :     {
     449             :         /*-----------------------------------------------------------------*
     450             :          * After inactive period, use the most up-to-date ISPs
     451             :          *-----------------------------------------------------------------*/
     452             : 
     453           0 :         if ( st->last_core_brate == FRAME_NO_DATA || st->last_core_brate == SID_1k75 )
     454             :         {
     455           0 :             mvr2r( st->hDtxEnc->lspCNG, st->lsp_old, M );
     456           0 :             isp2isf( st->hDtxEnc->lspCNG, st->lsf_old, M, INT_FS_12k8 );
     457           0 :             set_f( old_exc, 0, L_EXC_MEM );
     458             :         }
     459             : 
     460             :         /*-----------------------------------------------------------------*
     461             :          * ISF Quantization and interpolation
     462             :          *-----------------------------------------------------------------*/
     463             : 
     464           0 :         isf_enc_amr_wb( st, isf_new, isp_new, Aq );
     465             : 
     466             :         /*---------------------------------------------------------------*
     467             :          * Calculation of LP residual (filtering through A[z] filter)
     468             :          *---------------------------------------------------------------*/
     469             : 
     470           0 :         calc_residu( inp, res, Aq, L_FRAME );
     471             : 
     472           0 :         if ( st->hTdCngEnc != NULL )
     473             :         {
     474           0 :             st->hTdCngEnc->burst_ho_cnt = 0;
     475             :         }
     476             : 
     477             :         /*------------------------------------------------------------*
     478             :          * Encode excitation
     479             :          *------------------------------------------------------------*/
     480             : 
     481           0 :         encod_amr_wb( st, inp, Aw, Aq, res, syn, exc, exc2, pitch_buf, hf_gain, inp_16k );
     482             : 
     483             : #ifdef DEBUGGING
     484             :         /* SNR measuremenet of CELP coded output */
     485             :         snr_celp( L_FRAME, L_SUBFR, GAMMA1, TILT_FAC, ( st->vad_flag | vad_flag_dtx ), st->coder_type, inp, syn, A, 0, "CELP_output" );
     486             : #endif
     487             : 
     488             :         /* update mem_syn1 for ACELP core switching */
     489           0 :         mvr2r( hLPDmem->mem_syn, hLPDmem->mem_syn1, M );
     490             : 
     491             :         /* update old synthesis buffer - needed for ACELP internal sampling rate switching */
     492           0 :         mvr2r( syn + L_FRAME - L_SYN_MEM, hLPDmem->mem_syn_r, L_SYN_MEM );
     493             : 
     494             :         /* Update MODE2 core switching memory */
     495           0 :         mvr2r( syn, dummy_buf, L_FRAME );
     496           0 :         deemph( dummy_buf, PREEMPH_FAC, L_FRAME, &( hLPDmem->syn[M] ) );
     497           0 :         mvr2r( dummy_buf + L_FRAME - M - 1, hLPDmem->syn, M + 1 );
     498             : 
     499             :         /*--------------------------------------------------------------------------------------*
     500             :          * Write VAD information into the bitstream in AMR-WB IO mode
     501             :          *--------------------------------------------------------------------------------------*/
     502             : 
     503           0 :         push_indice( st->hBstr, IND_VAD_FLAG, st->vad_flag, 1 );
     504             :     }
     505             : 
     506             : 
     507             :     /*-----------------------------------------------------------------*
     508             :      * Updates
     509             :      *-----------------------------------------------------------------*/
     510             : 
     511             :     /* update old weighted speech buffer - for OL pitch analysis */
     512           0 :     mvr2r( &old_wsp[L_FRAME], st->old_wsp, L_WSP_MEM );
     513             : 
     514             :     /* update old input signal buffer */
     515           0 :     mvr2r( &old_inp[L_FRAME], st->old_inp_12k8, L_INP_MEM );
     516             : 
     517             :     /* update old input signal @16kHz buffer */
     518           0 :     if ( st->input_Fs > 8000 )
     519             :     {
     520           0 :         mvr2r( &old_inp_16k[L_FRAME16k], st->old_inp_16k, L_INP_MEM );
     521             :     }
     522             : 
     523             :     /* update of old per-band energy spectrum */
     524           0 :     mvr2r( fr_bands + NB_BANDS, st->hNoiseEst->enrO, NB_BANDS );
     525             : 
     526             :     /* update signal buffers */
     527           0 :     mvr2r( new_inp, st->buf_speech_enc_pe + L_FRAME, L_FRAME );
     528           0 :     mvr2r( wsp, st->buf_wspeech_enc + L_FRAME + L_SUBFR, L_FRAME + L_LOOK_12k8 );
     529             : 
     530             :     /* update ACELP core parameters */
     531           0 :     updt_enc( st, old_exc, pitch_buf, 0, Aq, isf_new, isp_new, dummy_buf );
     532             : 
     533             :     /* update main codec paramaters */
     534           0 :     updt_enc_common( st );
     535             : 
     536             : 
     537             : #ifdef DEBUG_MODE_INFO
     538             :     dbgwrite( &st->codec_mode, sizeof( int16_t ), 1, input_frame, "res/codec" );
     539             :     dbgwrite( &st->core, sizeof( int16_t ), 1, input_frame, "res/core" );
     540             :     dbgwrite( &st->extl, sizeof( int16_t ), 1, input_frame, "res/extl" );
     541             :     dbgwrite( &st->bwidth, sizeof( int16_t ), 1, input_frame, "res/bwidth" );
     542             :     ener = st->total_brate / 1000.0f;
     543             :     dbgwrite( &ener, sizeof( float ), 1, input_frame, "res/total_brate" );
     544             :     ener = st->core_brate / 1000.0f;
     545             :     dbgwrite( &ener, sizeof( float ), 1, input_frame, "res/core_brate" );
     546             :     dbgwrite( &st->coder_type, sizeof( int16_t ), 1, input_frame, "res/coder_type" );
     547             :     dbgwrite( &st->cng_type, sizeof( int16_t ), 1, input_frame, "res/cng_type" );
     548             :     dbgwrite( &st->L_frame, sizeof( int16_t ), 1, input_frame, "res/L_frame" );
     549             :     dbgwrite( &st->vad_flag, sizeof( int16_t ), 1, input_frame, "res/vad_flag" );
     550             :     dbgwrite( snr_[0], sizeof( float ), 320, 1, "res/snr" );
     551             : #endif
     552             : 
     553           0 :     return;
     554             : }
     555             : 
     556             : /*---------------------------------------------------------------------*
     557             :  * amr_wb_enc_init()
     558             :  *
     559             :  * Initialize AMR-WB encoder
     560             :  *---------------------------------------------------------------------*/
     561             : 
     562           3 : void amr_wb_enc_init(
     563             :     AMRWB_IO_ENC_HANDLE hAmrwb_IO /* i/o: AMR-WB IO encoder handle    */
     564             : )
     565             : {
     566             :     int16_t i;
     567             : 
     568             :     /* HF (6-7kHz) BWE */
     569           3 :     hAmrwb_IO->seed2_enc = RANDOM_INITSEED;
     570             : 
     571          15 :     for ( i = 0; i < GAIN_PRED_ORDER; i++ )
     572             :     {
     573          12 :         hAmrwb_IO->past_qua_en[i] = -14.0f; /* gain quantization memory (used in AMR-WB IO mode) */
     574             :     }
     575             : 
     576           3 :     hf_cod_init( hAmrwb_IO->mem_hp400_enc, hAmrwb_IO->mem_hf_enc, hAmrwb_IO->mem_syn_hf_enc, hAmrwb_IO->mem_hf2_enc, &hAmrwb_IO->gain_alpha );
     577             : 
     578           3 :     return;
     579             : }

Generated by: LCOV version 1.14