LCOV - code coverage report
Current view: top level - lib_enc - ivas_core_enc.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ e4dd50d43e5522084cbfc5cb7dcda17ea6ff534d Lines: 112 114 98.2 %
Date: 2026-01-27 05:59:54 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             :    (C) 2022-2026 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
       4             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
       5             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
       6             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
       7             :    contributors to this repository. All Rights Reserved.
       8             : 
       9             :    This software is protected by copyright law and by international treaties.
      10             :    The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
      11             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
      12             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
      13             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
      14             :    contributors to this repository retain full ownership rights in their respective contributions in
      15             :    the software. This notice grants no license of any kind, including but not limited to patent
      16             :    license, nor is any license granted by implication, estoppel or otherwise.
      17             : 
      18             :    Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
      19             :    contributions.
      20             : 
      21             :    This software is provided "AS IS", without any express or implied warranties. The software is in the
      22             :    development stage. It is intended exclusively for experts who have experience with such software and
      23             :    solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
      24             :    and fitness for a particular purpose are hereby disclaimed and excluded.
      25             : 
      26             :    Any dispute, controversy or claim arising under or in relation to providing this software shall be
      27             :    submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
      28             :    accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
      29             :    the United Nations Convention on Contracts on the International Sales of Goods.
      30             : 
      31             : *******************************************************************************************************/
      32             : 
      33             : #include <stdint.h>
      34             : #include "options.h"
      35             : #ifdef DEBUGGING
      36             : #include "debug.h"
      37             : #endif
      38             : #include "cnst.h"
      39             : #include "rom_com.h"
      40             : #include "prot.h"
      41             : #include "ivas_cnst.h"
      42             : #include "ivas_prot.h"
      43             : #include "wmc_auto.h"
      44             : #include <math.h>
      45             : 
      46             : #ifdef DEBUG_MODE_ACELP
      47             : extern float snr_[2][320];
      48             : #endif
      49             : 
      50             : 
      51             : /*-------------------------------------------------------------------*
      52             :  * ivas_core_enc()
      53             :  *
      54             :  * Principal IVAS core coder routine, where number of core channels is 1 or 2
      55             :  *-------------------------------------------------------------------*/
      56             : 
      57     1981024 : ivas_error ivas_core_enc(
      58             :     SCE_ENC_HANDLE hSCE,                                         /* i/o: SCE encoder structure                   */
      59             :     CPE_ENC_HANDLE hCPE,                                         /* i/o: CPE encoder structure                   */
      60             :     MCT_ENC_HANDLE hMCT,                                         /* i/o: MCT encoder structure                   */
      61             :     const int16_t n_CoreChannels,                                /* i  : number of core channels to be coded     */
      62             :     float old_inp_12k8[][L_INP_12k8],                            /* i  : buffer of old input signal              */
      63             :     float old_inp_16k[][L_INP],                                  /* i  : buffer of old input signal              */
      64             :     float ener[],                                                /* i  : residual energy from Levinson-Durbin    */
      65             :     float A[][NB_SUBFR16k * ( M + 1 )],                          /* i  : A(z) unquantized for the 4 subframes    */
      66             :     float Aw[][NB_SUBFR16k * ( M + 1 )],                         /* i  : weighted A(z) unquantized for subframes */
      67             :     float epsP[][M + 1],                                         /* i  : LP prediction errors                    */
      68             :     float lsp_new[][M],                                          /* i  : LSPs at the end of the frame            */
      69             :     float lsp_mid[][M],                                          /* i  : LSPs in the middle of the frame         */
      70             :     const int16_t vad_hover_flag[],                              /* i  : VAD hanglover flag                      */
      71             :     int16_t attack_flag[],                                       /* i  : attack flag (GSC or TC)                 */
      72             :     float realBuffer[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer                             */
      73             :     float imagBuffer[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer                             */
      74             :     float old_wsp[][L_WSP],                                      /* i  : weighted input signal buffer            */
      75             :     const int16_t loc_harm[],                                    /* i  : harmonicity flag                        */
      76             :     const float cor_map_sum[],                                   /* i  : speech/music clasif. parameter          */
      77             :     const int16_t vad_flag_dtx[],                                /* i  : HE-SAD flag with additional DTX HO      */
      78             :     float enerBuffer[][CLDFB_NO_CHANNELS_MAX],                   /* i  : energy buffer                           */
      79             :     float fft_buff[][2 * L_FFT],                                 /* i  : FFT buffer                              */
      80             :     const int16_t tdm_SM_or_LRTD_Pri,                            /* i  : channel combination scheme flag         */
      81             :     const int16_t ivas_format,                                   /* i  : IVAS format                             */
      82             :     const int16_t flag_16k_smc                                   /* i  : flag to indicate if the OL SMC is run at 16 kHz */
      83             : )
      84             : {
      85             :     int16_t n, input_frame;
      86             :     int16_t cpe_id, MCT_flag;
      87             :     Encoder_State **sts, *st;
      88             :     STEREO_ICBWE_ENC_HANDLE hStereoICBWE;
      89             :     STEREO_TD_ENC_DATA_HANDLE hStereoTD;
      90             :     float *inp[CPE_CHANNELS];
      91             :     float new_inp_resamp16k[CPE_CHANNELS][L_FRAME16k]; /* new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */
      92             :     float old_syn_12k8_16k[CPE_CHANNELS][L_FRAME16k];  /* ACELP core synthesis at 12.8kHz or 16kHz to be used by the SWB BWE */
      93             :     float *shb_speech, *hb_speech, *new_swb_speech;
      94             :     float new_swb_speech_buffer[L_FRAME48k + STEREO_DFT_OVL_MAX];
      95             :     float bwe_exc_extended[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET];
      96             :     float voice_factors[CPE_CHANNELS][NB_SUBFR16k];
      97             :     int16_t Voicing_flag[CPE_CHANNELS];
      98             :     float pitch_buf[CPE_CHANNELS][NB_SUBFR16k];
      99             :     int16_t unbits[CPE_CHANNELS];
     100             :     float tdm_lsfQ_PCh[M];
     101             :     int16_t last_element_mode, tdm_Pitch_reuse_flag;
     102             :     int32_t element_brate, last_element_brate, input_Fs;
     103             :     int16_t diff_nBits;
     104             :     ivas_error error;
     105             :     int16_t max_num_indices_BWE;
     106             : 
     107     1981024 :     push_wmops( "ivas_core_enc" );
     108             : 
     109     1981024 :     error = IVAS_ERR_OK;
     110             : 
     111             :     /*------------------------------------------------------------------*
     112             :      * General initialization
     113             :      *-----------------------------------------------------------------*/
     114             : 
     115     1981024 :     if ( hSCE != NULL )
     116             :     {
     117      728489 :         cpe_id = -1;
     118      728489 :         MCT_flag = 0;
     119      728489 :         sts = hSCE->hCoreCoder;
     120      728489 :         hStereoTD = NULL;
     121      728489 :         hStereoICBWE = NULL;
     122      728489 :         element_brate = hSCE->element_brate;
     123      728489 :         last_element_brate = hSCE->last_element_brate;
     124      728489 :         last_element_mode = IVAS_SCE;
     125      728489 :         tdm_Pitch_reuse_flag = -1;
     126             :     }
     127             :     else
     128             :     {
     129     1252535 :         cpe_id = hCPE->cpe_id;
     130     1252535 :         MCT_flag = 0;
     131     1252535 :         if ( hMCT != NULL )
     132             :         {
     133      888368 :             MCT_flag = 1;
     134             :         }
     135     1252535 :         sts = hCPE->hCoreCoder;
     136     1252535 :         hStereoICBWE = hCPE->hStereoICBWE;
     137     1252535 :         element_brate = hCPE->element_brate;
     138     1252535 :         last_element_brate = hCPE->last_element_brate;
     139     1252535 :         last_element_mode = hCPE->last_element_mode;
     140             : 
     141     1252535 :         if ( hCPE->hStereoTD != NULL )
     142             :         {
     143        4591 :             hStereoTD = hCPE->hStereoTD;
     144        4591 :             tdm_Pitch_reuse_flag = hCPE->hStereoTD->tdm_Pitch_reuse_flag;
     145             :         }
     146             :         else
     147             :         {
     148     1247944 :             hStereoTD = NULL;
     149     1247944 :             tdm_Pitch_reuse_flag = -1;
     150             :         }
     151             :     }
     152             : 
     153     1981024 :     input_Fs = sts[0]->input_Fs;
     154     1981024 :     input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC );
     155             : 
     156     5079958 :     for ( n = 0; n < n_CoreChannels; n++ )
     157             :     {
     158     3098934 :         st = sts[n];
     159             : 
     160             :         /*------------------------------------------------------------------*
     161             :          * Initializiation per core-coder channel
     162             :          *-----------------------------------------------------------------*/
     163             : 
     164             : #ifdef DEBUG_MODE_ACELP
     165             :         set_f( snr_[n], 0.0f, 320 );
     166             : #endif
     167             : 
     168     3098934 :         st->extl = -1;
     169     3098934 :         unbits[n] = 0;
     170             : 
     171     3098934 :         st->element_brate = element_brate;
     172             : 
     173             :         /*---------------------------------------------------------------------*
     174             :          * Pre-processing, incl. Decision matrix
     175             :          *---------------------------------------------------------------------*/
     176             : 
     177             : #ifdef FIX_2344_ALIGN_PREPROC
     178     3098934 :         pre_proc_ivas( st, last_element_mode, element_brate, ivas_format == SBA_FORMAT ? last_element_brate : element_brate, input_frame, old_inp_12k8[n], old_inp_16k[n], &inp[n], &ener[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], new_inp_resamp16k[n], &Voicing_flag[n], old_wsp[n], loc_harm[n], cor_map_sum[n], vad_flag_dtx[n], enerBuffer[n], fft_buff[n], MCT_flag, vad_hover_flag[n], flag_16k_smc );
     179             : #else
     180             :         if ( ( error = pre_proc_ivas( st, last_element_mode, element_brate, ivas_format == SBA_FORMAT ? last_element_brate : element_brate, input_frame, old_inp_12k8[n], old_inp_16k[n], &inp[n], &ener[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], new_inp_resamp16k[n], &Voicing_flag[n], old_wsp[n], loc_harm[n], cor_map_sum[n], vad_flag_dtx[n], enerBuffer[n], fft_buff[n], MCT_flag, vad_hover_flag[n], flag_16k_smc ) ) != IVAS_ERR_OK )
     181             :         {
     182             :             return error;
     183             :         }
     184             : #endif
     185             : 
     186     3098934 :         if ( st->element_mode == IVAS_CPE_MDCT || st->element_mode == IVAS_SCE )
     187             :         {
     188     2955127 :             st->enablePlcWaveadjust = 0;
     189             :         }
     190             :     }
     191             : 
     192             :     /*------------------------------------------------------------------*
     193             :      * Sanity check in combined format coding
     194             :      *-----------------------------------------------------------------*/
     195             : 
     196     1981024 :     diff_nBits = 0;
     197     1981024 :     if ( hCPE != NULL && hCPE->element_mode == IVAS_CPE_DFT && hCPE->brate_surplus > 0 )
     198             :     {
     199        2830 :         ivas_combined_format_brate_sanity( element_brate, sts[0]->core, sts[0]->total_brate, &( sts[0]->core_brate ), &( sts[0]->inactive_coder_type_flag ), &diff_nBits );
     200             :     }
     201             : 
     202             :     /*---------------------------------------------------------------------*
     203             :      * Core Encoding
     204             :      *---------------------------------------------------------------------*/
     205             : 
     206     5079958 :     for ( n = 0; n < n_CoreChannels; n++ )
     207             :     {
     208     3098934 :         st = sts[n];
     209             : 
     210             :         /* update pointer to the buffer of indices of the second channel */
     211     3098934 :         if ( n == 1 && st->element_mode == IVAS_CPE_TD )
     212             :         {
     213             :             /* adjust the pointer to the buffer of indices of the secondary channel (make space for BWE indices) */
     214        4591 :             max_num_indices_BWE = get_BWE_max_num_indices( sts[0]->extl_brate );
     215        4591 :             st->hBstr->ind_list = sts[0]->hBstr->ind_list + sts[0]->hBstr->nb_ind_tot + max_num_indices_BWE;
     216             : 
     217             :             /* write TD stereo spatial parameters */
     218        4591 :             move_indices( hStereoTD->tdm_hBstr_tmp.ind_list, st->hBstr->ind_list, hStereoTD->tdm_hBstr_tmp.nb_ind_tot );
     219        4591 :             st->hBstr->nb_ind_tot += hStereoTD->tdm_hBstr_tmp.nb_ind_tot;
     220        4591 :             st->hBstr->nb_bits_tot += hStereoTD->tdm_hBstr_tmp.nb_bits_tot;
     221             : 
     222        4591 :             reset_indices_enc( &hStereoTD->tdm_hBstr_tmp, MAX_IND_TDM_TMP );
     223             :         }
     224             : 
     225             :         /*---------------------------------------------------------------------*
     226             :          * Write signaling info into the bitstream
     227             :          *---------------------------------------------------------------------*/
     228             : 
     229     3098934 :         if ( !MCT_flag || ( MCT_flag && cpe_id == 0 ) )
     230             :         {
     231     1934756 :             ivas_signaling_enc( st, MCT_flag, element_brate, tdm_SM_or_LRTD_Pri, tdm_Pitch_reuse_flag );
     232             :         }
     233             : 
     234             :         /*---------------------------------------------------------------------*
     235             :          * Preprocessing (preparing) for ACELP/HQ core switching
     236             :          *---------------------------------------------------------------------*/
     237             : 
     238     3098934 :         core_switching_pre_enc( st, old_inp_12k8[n], old_inp_16k[n], sts[0]->active_cnt, last_element_mode );
     239             : 
     240             :         /*---------------------------------------------------------------------*
     241             :          * ACELP core encoding
     242             :          * TCX core encoding
     243             :          * HQ core encoding
     244             :          *---------------------------------------------------------------------*/
     245             : 
     246     3098934 :         if ( st->core == ACELP_CORE )
     247             :         {
     248             :             /* ACELP core encoder */
     249      343920 :             if ( ( error = acelp_core_enc( st, inp[n], ener[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], vad_hover_flag[0], attack_flag[n], bwe_exc_extended[n], voice_factors[n], old_syn_12k8_16k[n], pitch_buf[n], &unbits[n], hStereoTD, tdm_lsfQ_PCh ) ) != IVAS_ERR_OK )
     250             :             {
     251           0 :                 return error;
     252             :             }
     253             :         }
     254             : 
     255     3098934 :         if ( ( st->core == TCX_20_CORE || st->core == TCX_10_CORE ) && st->element_mode != IVAS_CPE_MDCT )
     256             :         {
     257             :             /* TCX core encoder */
     258      523512 :             stereo_tcx_core_enc( st, old_inp_12k8[n] + L_INP_MEM, old_inp_16k[n] + L_INP_MEM, Aw[n], lsp_new[n], lsp_mid[n], pitch_buf[n], last_element_mode, vad_hover_flag[0] );
     259             :         }
     260             : 
     261     3098934 :         if ( st->core == HQ_CORE )
     262             :         {
     263             :             /* HQ core encoder */
     264       13734 :             hq_core_enc( st, st->input, input_frame, NORMAL_HQ_CORE, Voicing_flag[n], vad_hover_flag[0] );
     265             :         }
     266             : 
     267             :         /*---------------------------------------------------------------------*
     268             :          * TD stereo updates
     269             :          *---------------------------------------------------------------------*/
     270             : 
     271     3098934 :         if ( st->element_mode == IVAS_CPE_TD && n == 0 )
     272             :         {
     273        4591 :             td_stereo_param_updt( st->lsp_old, st->lsf_old, pitch_buf[0], tdm_lsfQ_PCh, hStereoTD->tdm_Pri_pitch_buf, st->flag_ACELP16k, hStereoTD->tdm_use_IAWB_Ave_lpc );
     274             :         }
     275             :     }
     276             : 
     277             :     /*---------------------------------------------------------------------*
     278             :      * MDCT stereo: joint TCX Core Encoding
     279             :      *---------------------------------------------------------------------*/
     280             : 
     281     1981024 :     if ( sts[0]->element_mode == IVAS_CPE_MDCT )
     282             :     {
     283     1113319 :         if ( sts[0]->core_brate > SID_2k40 && sts[1]->core_brate > SID_2k40 )
     284             :         {
     285     1108884 :             if ( MCT_flag )
     286             :             {
     287      888368 :                 ivas_mdct_core_whitening_enc( hCPE, old_inp_16k, old_wsp, pitch_buf, hMCT->p_mdst_spectrum_long[cpe_id], hMCT->tnsBits[cpe_id], hMCT->p_orig_spectrum_long[cpe_id],
     288      888368 :                                               hMCT->tnsSize[cpe_id], hMCT->p_param[cpe_id], hMCT->hBstr, 1, hMCT->nchan_out_woLFE );
     289             :             }
     290             :             else
     291             :             {
     292      220516 :                 stereo_mdct_core_enc( hCPE, old_inp_16k, old_wsp, pitch_buf );
     293             :             }
     294             :         }
     295        4435 :         else if ( sts[0]->core_brate == SID_2k40 && sts[1]->core_brate == SID_2k40 )
     296             :         {
     297             :             /* synch CNG configs between channels */
     298        1908 :             for ( n = 0; n < CPE_CHANNELS; n++ )
     299             :             {
     300        1272 :                 st = sts[n];
     301        1272 :                 if ( ( st->hFdCngEnc->hFdCngCom->frameSize != st->L_frame ) || ( st->hFdCngEnc->hFdCngCom->CngBandwidth != st->bwidth ) )
     302             :                 {
     303         364 :                     configureFdCngEnc( st->hFdCngEnc, max( st->bwidth, WB ), st->L_frame == L_FRAME16k ? ACELP_16k40 : ACELP_9k60 );
     304             :                 }
     305             :             }
     306             : 
     307         636 :             if ( sts[0]->cng_sba_flag )
     308             :             {
     309         165 :                 FdCngEncodeDiracMDCTStereoSID( hCPE );
     310             :             }
     311             :             else
     312             :             {
     313         471 :                 FdCngEncodeMDCTStereoSID( hCPE );
     314             :             }
     315             :         }
     316             :     }
     317             : 
     318             :     /*---------------------------------------------------------------------*
     319             :      * Postprocessing, BWEs and Updates
     320             :      *---------------------------------------------------------------------*/
     321             : 
     322     5079958 :     for ( n = 0; n < n_CoreChannels; n++ )
     323             :     {
     324     3098934 :         st = sts[n];
     325             : 
     326             :         /*---------------------------------------------------------------------*
     327             :          * Postprocessing for ACELP/HQ core switching
     328             :          *---------------------------------------------------------------------*/
     329             : 
     330     3098934 :         core_switching_post_enc( st, old_inp_12k8[n], old_inp_16k[n], A[n] );
     331             : 
     332             :         /*---------------------------------------------------------------------*
     333             :          * WB TBE encoding
     334             :          * WB BWE encoding
     335             :          *---------------------------------------------------------------------*/
     336             : 
     337     3098934 :         hb_speech = new_swb_speech_buffer; /* reuse existing buffer: hb_speech[L_FRAME16k/4]; */
     338             : 
     339     3098934 :         if ( input_Fs >= 16000 && st->bwidth < SWB && st->hBWE_TD != NULL )
     340             :         {
     341             :             /* Common pre-processing for WB TBE and WB BWE */
     342       91129 :             wb_pre_proc( st, last_element_mode, new_inp_resamp16k[n], hb_speech );
     343             :         }
     344             : 
     345     3098934 :         if ( st->extl == WB_TBE )
     346             :         {
     347             :             /* WB TBE encoder */
     348       15698 :             wb_tbe_enc( st, hb_speech, bwe_exc_extended[n], voice_factors[n], pitch_buf[n] );
     349             :         }
     350     3083236 :         else if ( st->extl == WB_BWE && n == 0 && st->element_mode != IVAS_CPE_MDCT )
     351             :         {
     352             :             /* WB BWE encoder */
     353       15564 :             wb_bwe_enc( st, new_inp_resamp16k[n] );
     354             :         }
     355             : 
     356             :         /*---------------------------------------------------------------------*
     357             :          * SWB(FB) TBE encoding
     358             :          * SWB(FB) BWE encoding
     359             :          *---------------------------------------------------------------------*/
     360             : 
     361     3098934 :         new_swb_speech = new_swb_speech_buffer + STEREO_DFT_OVL_MAX;
     362     3098934 :         set_f( new_swb_speech_buffer, 0, L_FRAME48k + STEREO_DFT_OVL_MAX );
     363     3098934 :         shb_speech = new_inp_resamp16k[n]; /* reuse existing buffer: shb_speech[L_FRAME16k] */
     364             : 
     365     3098934 :         if ( !st->Opt_SC_VBR && input_Fs >= 32000 && st->hBWE_TD != NULL )
     366             :         {
     367             :             /* Common pre-processing for SWB(FB) TBE and SWB(FB) BWE */
     368      808937 :             swb_pre_proc( st, new_swb_speech, shb_speech, realBuffer[n], imagBuffer[n], hCPE );
     369             :         }
     370     2289997 :         else if ( input_Fs >= 32000 )
     371             :         {
     372     2085900 :             if ( st->hBWE_TD != NULL )
     373             :             {
     374           0 :                 InitSWBencBufferStates( st->hBWE_TD, shb_speech );
     375             :             }
     376             :         }
     377             : 
     378             :         /* SWB TBE encoder */
     379     3098934 :         if ( st->extl == SWB_TBE || st->extl == FB_TBE )
     380             :         {
     381      240690 :             if ( st->core_brate != FRAME_NO_DATA && st->core_brate != SID_2k40 )
     382             :             {
     383             :                 float fb_exc[L_FRAME16k];
     384             : 
     385      240690 :                 swb_tbe_enc( st, hStereoICBWE, shb_speech, bwe_exc_extended[n], voice_factors[n], fb_exc, pitch_buf[n] );
     386             : 
     387      240690 :                 if ( st->extl == FB_TBE )
     388             :                 {
     389             :                     /* FB TBE encoder */
     390       92422 :                     fb_tbe_enc( st, st->input, fb_exc );
     391             :                 }
     392             :             }
     393             :         }
     394     2858244 :         else if ( st->extl == SWB_BWE || st->extl == FB_BWE )
     395             :         {
     396             :             /* SWB(FB) BWE encoder */
     397       30444 :             swb_bwe_enc( st, last_element_mode, old_inp_12k8[n], old_inp_16k[n], old_syn_12k8_16k[n], new_swb_speech, shb_speech );
     398             :         }
     399             : 
     400             :         /*---------------------------------------------------------------------*
     401             :          * SWB DTX/CNG encoding
     402             :          *---------------------------------------------------------------------*/
     403             : 
     404     3098934 :         if ( st->hTdCngEnc != NULL && st->Opt_DTX_ON && ( input_frame >= L_FRAME32k || st->element_mode == IVAS_CPE_DFT ) )
     405             :         {
     406             :             /* SHB DTX/CNG encoder */
     407       52617 :             swb_CNG_enc( st, shb_speech, old_syn_12k8_16k[n] );
     408             :         }
     409             : 
     410             :         /*-------------------------------------------------------------------*
     411             :          *  Inter-channel BWE encoding
     412             :          *-------------------------------------------------------------------*/
     413             : 
     414     3098934 :         if ( n == 0 && input_Fs >= 32000 && hStereoICBWE != NULL )
     415             :         {
     416      119924 :             stereo_icBWE_preproc( hCPE, input_frame, new_swb_speech_buffer /*tmp buffer*/ );
     417             : 
     418      119924 :             stereo_icBWE_enc( hCPE, shb_speech, new_swb_speech_buffer, voice_factors[0] );
     419             :         }
     420             : 
     421             :         /*---------------------------------------------------------------------*
     422             :          * Common updates
     423             :          *---------------------------------------------------------------------*/
     424             : 
     425     3098934 :         if ( !MCT_flag ) /* for MCT do this later, otherwise there can be a problem because TCX quant happens later and might get the wrong last_core on a bit rate switch */
     426             :         {
     427     1322198 :             updt_enc_common( st );
     428             :         }
     429             :     }
     430             : 
     431             :     /*------------------------------------------------------------------*
     432             :      * Write potentially unused bits in combined format coding
     433             :      *-----------------------------------------------------------------*/
     434             : 
     435     1981024 :     if ( hCPE != NULL && hCPE->element_mode == IVAS_CPE_DFT && hCPE->brate_surplus > 0 )
     436             :     {
     437        2852 :         while ( diff_nBits > 0 )
     438             :         {
     439          22 :             n = min( diff_nBits, 16 );
     440          22 :             push_indice( sts[0]->hBstr, IND_UNUSED, 0, n );
     441          22 :             diff_nBits -= n;
     442             :         }
     443             :     }
     444             : 
     445             : #ifdef DEBUG_MODE_INFO
     446             :     for ( n = 0; n < n_CoreChannels; n++ )
     447             :     {
     448             :         float tmpF;
     449             :         int16_t tmpS, id;
     450             : #if defined DEBUG_MODE_ACELP || defined DEBUG_MODE_TCX
     451             :         int16_t k, _pitch[3], _pitch_buf[5];
     452             : #endif
     453             : 
     454             :         st = sts[n];
     455             :         id = st->id_element;
     456             : 
     457             :         dbgwrite( &st->core, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "core", n, id, ENC ) );
     458             :         dbgwrite( &st->extl, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "extl", n, id, ENC ) );
     459             :         dbgwrite( &st->bwidth, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "bwidth", n, id, ENC ) );
     460             :         tmpF = st->total_brate / 1000.0f;
     461             :         dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "total_brate", n, id, ENC ) );
     462             :         tmpS = st->bits_frame_nominal;
     463             :         dbgwrite( &tmpS, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "bits_nominal", n, id, ENC ) );
     464             :         tmpF = st->core_brate / 1000.0f;
     465             :         dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "core_brate", n, id, ENC ) );
     466             :         tmpF = st->extl_brate / 1000.0f;
     467             :         dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "extl_brate", n, id, ENC ) );
     468             : 
     469             :         dbgwrite( &st->coder_type, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "coder_type", n, id, ENC ) );
     470             :         dbgwrite( &st->coder_type_raw, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "coder_type_raw", n, id, ENC ) );
     471             :         dbgwrite( &st->clas, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "clas", n, id, ENC ) );
     472             :         dbgwrite( &st->cng_type, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "cng_type", n, id, ENC ) );
     473             :         dbgwrite( &st->L_frame, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "L_frame", n, id, ENC ) );
     474             :         dbgwrite( &st->vad_flag, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "vad_flag", n, id, ENC ) );
     475             :         dbgwrite( &st->localVAD, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "localVAD", n, id, ENC ) );
     476             : 
     477             :         dbgwrite( &st->count_WB, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "count_WB", n, id, ENC ) );
     478             :         dbgwrite( &st->count_SWB, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "count_SWB", n, id, ENC ) );
     479             : 
     480             : #ifdef DEBUG_MODE_ACELP
     481             :         dbgwrite( snr_[n], sizeof( float ), 320, 1, fname( debug_dir, "snr", n, id, ENC ) );
     482             : #endif
     483             :         dbgwrite( &st->sp_aud_decision0, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "sp_aud_decision0", n, id, ENC ) );
     484             :         dbgwrite( &st->sp_aud_decision1, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "sp_aud_decision1", n, id, ENC ) );
     485             :         dbgwrite( &st->sp_aud_decision2, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "sp_aud_decision2", n, id, ENC ) );
     486             : 
     487             :         dbgwrite( &st->lp_noise, sizeof( float ), 1, input_frame, fname( debug_dir, "lp_noise", n, id, ENC ) );
     488             : 
     489             : #if ( defined DEBUG_MODE_ACELP ) || ( defined DEBUG_MODE_TCX )
     490             :         if ( st->coder_type == INACTIVE || st->coder_type == UNVOICED )
     491             :         {
     492             :             _pitch[0] = 0;
     493             :             _pitch[1] = 0;
     494             :             _pitch[2] = 0;
     495             :         }
     496             :         else
     497             :         {
     498             :             _pitch[0] = st->pitch[0];
     499             :             _pitch[1] = st->pitch[1];
     500             :             _pitch[2] = st->pitch[2];
     501             :         }
     502             :         dbgwrite( &_pitch[0], sizeof( int16_t ), 1, ( input_frame / 8 * 3 ), fname( debug_dir, "pitch", n, id, ENC ) );
     503             :         dbgwrite( &_pitch[1], sizeof( int16_t ), 1, ( input_frame / 8 * 3 ), fname( debug_dir, "pitch", n, id, ENC ) );
     504             :         dbgwrite( &_pitch[2], sizeof( int16_t ), 1, ( input_frame / 8 * 2 ), fname( debug_dir, "pitch", n, id, ENC ) );
     505             : 
     506             :         if ( ( st->coder_type == INACTIVE ) || ( st->coder_type == UNVOICED ) )
     507             :         {
     508             :             set_s( _pitch_buf, 0, NB_SUBFR16k );
     509             :         }
     510             :         else if ( st->L_frame != L_FRAME )
     511             :         {
     512             :             for ( k = 0; k < NB_SUBFR16k; k++ )
     513             :                 _pitch_buf[k] = (int16_t) ( pitch_buf[n][k] + 0.5f );
     514             :         }
     515             :         else
     516             :         {
     517             :             for ( k = 0; k < NB_SUBFR; k++ )
     518             :                 _pitch_buf[k] = (int16_t) ( pitch_buf[n][k] * 5.0f / 4.0f + 0.5f );
     519             :         }
     520             :         if ( st->L_frame != L_FRAME )
     521             :         {
     522             :             for ( k = 0; k < NB_SUBFR16k; k++ )
     523             :                 dbgwrite( &_pitch_buf[k], sizeof( int16_t ), 1, L_SUBFR, fname( debug_dir, "pitchCL", n, id, ENC ) );
     524             :         }
     525             :         else
     526             :         {
     527             :             for ( k = 0; k < NB_SUBFR; k++ )
     528             :                 dbgwrite( &_pitch_buf[k], sizeof( int16_t ), 1, L_SUBFR16k, fname( debug_dir, "pitchCL", n, id, ENC ) );
     529             :         }
     530             : #endif
     531             : 
     532             : #ifdef DEBUG_MODE_ACELP
     533             :         if ( st->core != ACELP_CORE )
     534             :         {
     535             :             tmpF = 0.0f;
     536             :             dbgwrite( &tmpF, sizeof( float ), 1, st->L_frame, fname( debug_dir, "exc.enc", n, id, ENC ) );
     537             :             dbgwrite( &tmpF, sizeof( float ), 1, st->L_frame, fname( debug_dir, "resid", n, id, ENC ) );
     538             :         }
     539             :         if ( n_CoreChannels == 1 )
     540             :         {
     541             :             tmpS = -1;
     542             :             dbgwrite( &tmpS, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "coder_type", 2, id, ENC ) );
     543             :             tmpF = 0.0f;
     544             :             dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "total_brate", 2, id, ENC ) );
     545             :             tmpF = 0.0f;
     546             :             dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "core_brate", 2, id, ENC ) );
     547             :             tmpF = 0.0f;
     548             :             dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "extl_brate", 2, id, ENC ) );
     549             :             dbgwrite( &tmpS, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "vad_flag", 2, id, ENC ) );
     550             :             dbgwrite( &tmpS, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "localVAD", 2, id, ENC ) );
     551             :         }
     552             : 
     553             : #endif
     554             :     }
     555             : #endif
     556             : 
     557     1981024 :     pop_wmops();
     558             : 
     559     1981024 :     return error;
     560             : }

Generated by: LCOV version 1.14