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 @ 8834b716eb6d7dfb881d5c69dd21cb18e1692722 Lines: 110 116 94.8 %
Date: 2025-07-09 08:36:12 Functions: 1 1 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             : #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      768638 : 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      768638 :     push_wmops( "ivas_core_enc" );
     108             : 
     109      768638 :     error = IVAS_ERR_OK;
     110             : 
     111             :     /*------------------------------------------------------------------*
     112             :      * General initialization
     113             :      *-----------------------------------------------------------------*/
     114             : 
     115      768638 :     if ( hSCE != NULL )
     116             :     {
     117      347783 :         cpe_id = -1;
     118      347783 :         MCT_flag = 0;
     119      347783 :         sts = hSCE->hCoreCoder;
     120      347783 :         hStereoTD = NULL;
     121      347783 :         hStereoICBWE = NULL;
     122      347783 :         element_brate = hSCE->element_brate;
     123      347783 :         last_element_brate = hSCE->last_element_brate;
     124      347783 :         last_element_mode = IVAS_SCE;
     125      347783 :         tdm_Pitch_reuse_flag = -1;
     126             :     }
     127             :     else
     128             :     {
     129      420855 :         cpe_id = hCPE->cpe_id;
     130      420855 :         MCT_flag = 0;
     131      420855 :         if ( hMCT != NULL )
     132             :         {
     133      270308 :             MCT_flag = 1;
     134             :         }
     135      420855 :         sts = hCPE->hCoreCoder;
     136      420855 :         hStereoICBWE = hCPE->hStereoICBWE;
     137      420855 :         element_brate = hCPE->element_brate;
     138      420855 :         last_element_brate = hCPE->last_element_brate;
     139      420855 :         last_element_mode = hCPE->last_element_mode;
     140             : 
     141      420855 :         if ( hCPE->hStereoTD != NULL )
     142             :         {
     143        3791 :             hStereoTD = hCPE->hStereoTD;
     144        3791 :             tdm_Pitch_reuse_flag = hCPE->hStereoTD->tdm_Pitch_reuse_flag;
     145             :         }
     146             :         else
     147             :         {
     148      417064 :             hStereoTD = NULL;
     149      417064 :             tdm_Pitch_reuse_flag = -1;
     150             :         }
     151             :     }
     152             : 
     153      768638 :     input_Fs = sts[0]->input_Fs;
     154      768638 :     input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC );
     155             : 
     156     1898452 :     for ( n = 0; n < n_CoreChannels; n++ )
     157             :     {
     158     1129814 :         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     1129814 :         st->extl = -1;
     169     1129814 :         unbits[n] = 0;
     170             : 
     171     1129814 :         st->element_brate = element_brate;
     172             : 
     173             :         /*---------------------------------------------------------------------*
     174             :          * Pre-processing, incl. Decision matrix
     175             :          *---------------------------------------------------------------------*/
     176             : 
     177     1129814 :         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 )
     178             :         {
     179           0 :             return error;
     180             :         }
     181             : 
     182     1129814 :         if ( st->element_mode == IVAS_CPE_MDCT || st->element_mode == IVAS_SCE )
     183             :         {
     184     1062553 :             st->enablePlcWaveadjust = 0;
     185             :         }
     186             :     }
     187             : 
     188             :     /*------------------------------------------------------------------*
     189             :      * Sanity check in combined format coding
     190             :      *-----------------------------------------------------------------*/
     191             : 
     192      768638 :     diff_nBits = 0;
     193      768638 :     if ( hCPE != NULL && hCPE->element_mode == IVAS_CPE_DFT && hCPE->brate_surplus > 0 )
     194             :     {
     195         101 :         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 );
     196             :     }
     197             : 
     198             :     /*---------------------------------------------------------------------*
     199             :      * Core Encoding
     200             :      *---------------------------------------------------------------------*/
     201             : 
     202     1898452 :     for ( n = 0; n < n_CoreChannels; n++ )
     203             :     {
     204     1129814 :         st = sts[n];
     205             : 
     206             :         /* update pointer to the buffer of indices of the second channel */
     207     1129814 :         if ( n == 1 && st->element_mode == IVAS_CPE_TD )
     208             :         {
     209             :             /* adjust the pointer to the buffer of indices of the secondary channel (make space for BWE indices) */
     210        3791 :             max_num_indices_BWE = get_BWE_max_num_indices( sts[0]->extl_brate );
     211        3791 :             st->hBstr->ind_list = sts[0]->hBstr->ind_list + sts[0]->hBstr->nb_ind_tot + max_num_indices_BWE;
     212             : 
     213             :             /* write TD stereo spatial parameters */
     214        3791 :             move_indices( hStereoTD->tdm_hBstr_tmp.ind_list, st->hBstr->ind_list, hStereoTD->tdm_hBstr_tmp.nb_ind_tot );
     215        3791 :             st->hBstr->nb_ind_tot += hStereoTD->tdm_hBstr_tmp.nb_ind_tot;
     216        3791 :             st->hBstr->nb_bits_tot += hStereoTD->tdm_hBstr_tmp.nb_bits_tot;
     217             : 
     218        3791 :             reset_indices_enc( &hStereoTD->tdm_hBstr_tmp, MAX_IND_TDM_TMP );
     219             :         }
     220             : 
     221             :         /*---------------------------------------------------------------------*
     222             :          * Write signaling info into the bitstream
     223             :          *---------------------------------------------------------------------*/
     224             : 
     225     1129814 :         if ( !MCT_flag || ( MCT_flag && cpe_id == 0 ) )
     226             :         {
     227      791076 :             ivas_signaling_enc( st, MCT_flag, element_brate, tdm_SM_or_LRTD_Pri, tdm_Pitch_reuse_flag );
     228             :         }
     229             : 
     230             :         /*---------------------------------------------------------------------*
     231             :          * Preprocessing (preparing) for ACELP/HQ core switching
     232             :          *---------------------------------------------------------------------*/
     233             : 
     234     1129814 :         core_switching_pre_enc( st, old_inp_12k8[n], old_inp_16k[n], sts[0]->active_cnt, last_element_mode );
     235             : 
     236             :         /*---------------------------------------------------------------------*
     237             :          * ACELP core encoding
     238             :          * TCX core encoding
     239             :          * HQ core encoding
     240             :          *---------------------------------------------------------------------*/
     241             : 
     242     1129814 :         if ( st->core == ACELP_CORE )
     243             :         {
     244             :             /* ACELP core encoder */
     245      180687 :             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 )
     246             :             {
     247           0 :                 return error;
     248             :             }
     249             :         }
     250             : 
     251     1129814 :         if ( ( st->core == TCX_20_CORE || st->core == TCX_10_CORE ) && st->element_mode != IVAS_CPE_MDCT )
     252             :         {
     253             :             /* TCX core encoder */
     254      235212 :             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] );
     255             :         }
     256             : 
     257     1129814 :         if ( st->core == HQ_CORE )
     258             :         {
     259             :             /* HQ core encoder */
     260        8017 :             hq_core_enc( st, st->input, input_frame, NORMAL_HQ_CORE, Voicing_flag[n], vad_hover_flag[0] );
     261             :         }
     262             : 
     263             :         /*---------------------------------------------------------------------*
     264             :          * TD stereo updates
     265             :          *---------------------------------------------------------------------*/
     266             : 
     267     1129814 :         if ( st->element_mode == IVAS_CPE_TD && n == 0 )
     268             :         {
     269        3791 :             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 );
     270             :         }
     271             :     }
     272             : 
     273             :     /*---------------------------------------------------------------------*
     274             :      * MDCT stereo: joint TCX Core Encoding
     275             :      *---------------------------------------------------------------------*/
     276             : 
     277      768638 :     if ( sts[0]->element_mode == IVAS_CPE_MDCT )
     278             :     {
     279      357385 :         if ( sts[0]->core_brate > SID_2k40 && sts[1]->core_brate > SID_2k40 )
     280             :         {
     281      352949 :             if ( MCT_flag )
     282             :             {
     283      270308 :                 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],
     284      270308 :                                               hMCT->tnsSize[cpe_id], hMCT->p_param[cpe_id], hMCT->hBstr, 1, hMCT->nchan_out_woLFE );
     285             :             }
     286             :             else
     287             :             {
     288       82641 :                 stereo_mdct_core_enc( hCPE, old_inp_16k, old_wsp, pitch_buf );
     289             :             }
     290             :         }
     291        4436 :         else if ( sts[0]->core_brate == SID_2k40 && sts[1]->core_brate == SID_2k40 )
     292             :         {
     293             :             /* synch CNG configs between channels */
     294        1869 :             for ( n = 0; n < CPE_CHANNELS; n++ )
     295             :             {
     296        1246 :                 st = sts[n];
     297        1246 :                 if ( ( st->hFdCngEnc->hFdCngCom->frameSize != st->L_frame ) || ( st->hFdCngEnc->hFdCngCom->CngBandwidth != st->bwidth ) )
     298             :                 {
     299         266 :                     configureFdCngEnc( st->hFdCngEnc, max( st->bwidth, WB ), st->L_frame == L_FRAME16k ? ACELP_16k40 : ACELP_9k60 );
     300             :                 }
     301             :             }
     302             : 
     303         623 :             if ( sts[0]->cng_sba_flag )
     304             :             {
     305         207 :                 FdCngEncodeDiracMDCTStereoSID( hCPE );
     306             :             }
     307             :             else
     308             :             {
     309         416 :                 FdCngEncodeMDCTStereoSID( hCPE );
     310             :             }
     311             :         }
     312             :     }
     313             : 
     314             :     /*---------------------------------------------------------------------*
     315             :      * Postprocessing, BWEs and Updates
     316             :      *---------------------------------------------------------------------*/
     317             : 
     318     1898452 :     for ( n = 0; n < n_CoreChannels; n++ )
     319             :     {
     320     1129814 :         st = sts[n];
     321             : 
     322             :         /*---------------------------------------------------------------------*
     323             :          * Postprocessing for ACELP/HQ core switching
     324             :          *---------------------------------------------------------------------*/
     325             : 
     326     1129814 :         core_switching_post_enc( st, old_inp_12k8[n], old_inp_16k[n], A[n] );
     327             : 
     328             :         /*---------------------------------------------------------------------*
     329             :          * WB TBE encoding
     330             :          * WB BWE encoding
     331             :          *---------------------------------------------------------------------*/
     332             : 
     333     1129814 :         hb_speech = new_swb_speech_buffer; /* reuse existing buffer: hb_speech[L_FRAME16k/4]; */
     334             : 
     335     1129814 :         if ( input_Fs >= 16000 && st->bwidth < SWB && st->hBWE_TD != NULL )
     336             :         {
     337             :             /* Common pre-processing for WB TBE and WB BWE */
     338       43722 :             wb_pre_proc( st, last_element_mode, new_inp_resamp16k[n], hb_speech );
     339             :         }
     340             : 
     341     1129814 :         if ( st->extl == WB_TBE )
     342             :         {
     343             :             /* WB TBE encoder */
     344        7241 :             wb_tbe_enc( st, hb_speech, bwe_exc_extended[n], voice_factors[n], pitch_buf[n] );
     345             :         }
     346     1122573 :         else if ( st->extl == WB_BWE && n == 0 && st->element_mode != IVAS_CPE_MDCT )
     347             :         {
     348             :             /* WB BWE encoder */
     349       11573 :             wb_bwe_enc( st, new_inp_resamp16k[n] );
     350             :         }
     351             : 
     352             :         /*---------------------------------------------------------------------*
     353             :          * SWB(FB) TBE encoding
     354             :          * SWB(FB) BWE encoding
     355             :          *---------------------------------------------------------------------*/
     356             : 
     357     1129814 :         new_swb_speech = new_swb_speech_buffer + STEREO_DFT_OVL_MAX;
     358     1129814 :         set_f( new_swb_speech_buffer, 0, L_FRAME48k + STEREO_DFT_OVL_MAX );
     359     1129814 :         shb_speech = new_inp_resamp16k[n]; /* reuse existing buffer: shb_speech[L_FRAME16k] */
     360             : 
     361     1129814 :         if ( !st->Opt_SC_VBR && input_Fs >= 32000 && st->hBWE_TD != NULL )
     362             :         {
     363             :             /* Common pre-processing for SWB(FB) TBE and SWB(FB) BWE */
     364      395991 :             swb_pre_proc( st, new_swb_speech, shb_speech, realBuffer[n], imagBuffer[n], hCPE );
     365             :         }
     366      733823 :         else if ( input_Fs >= 32000 )
     367             :         {
     368      669278 :             if ( st->hBWE_TD != NULL )
     369             :             {
     370           0 :                 InitSWBencBufferStates( st->hBWE_TD, shb_speech );
     371             :             }
     372             :         }
     373             : 
     374             :         /* SWB TBE encoder */
     375     1129814 :         if ( st->extl == SWB_TBE || st->extl == FB_TBE )
     376             :         {
     377      115658 :             if ( st->core_brate != FRAME_NO_DATA && st->core_brate != SID_2k40 )
     378             :             {
     379             :                 float fb_exc[L_FRAME16k];
     380             : 
     381      115658 :                 swb_tbe_enc( st, hStereoICBWE, shb_speech, bwe_exc_extended[n], voice_factors[n], fb_exc, pitch_buf[n] );
     382             : 
     383      115658 :                 if ( st->extl == FB_TBE )
     384             :                 {
     385             :                     /* FB TBE encoder */
     386       43877 :                     fb_tbe_enc( st, st->input, fb_exc );
     387             :                 }
     388             :             }
     389             :         }
     390     1014156 :         else if ( st->extl == SWB_BWE || st->extl == FB_BWE )
     391             :         {
     392             :             /* SWB(FB) BWE encoder */
     393       11916 :             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 );
     394             :         }
     395             : 
     396             :         /*---------------------------------------------------------------------*
     397             :          * SWB DTX/CNG encoding
     398             :          *---------------------------------------------------------------------*/
     399             : 
     400     1129814 :         if ( st->hTdCngEnc != NULL && st->Opt_DTX_ON && ( input_frame >= L_FRAME32k || st->element_mode == IVAS_CPE_DFT ) )
     401             :         {
     402             :             /* SHB DTX/CNG encoder */
     403       44242 :             swb_CNG_enc( st, shb_speech, old_syn_12k8_16k[n] );
     404             :         }
     405             : 
     406             :         /*-------------------------------------------------------------------*
     407             :          *  Inter-channel BWE encoding
     408             :          *-------------------------------------------------------------------*/
     409             : 
     410     1129814 :         if ( n == 0 && input_Fs >= 32000 && hStereoICBWE != NULL )
     411             :         {
     412       48232 :             stereo_icBWE_preproc( hCPE, input_frame, new_swb_speech_buffer /*tmp buffer*/ );
     413             : 
     414       48232 :             stereo_icBWE_enc( hCPE, shb_speech, new_swb_speech_buffer, voice_factors[0] );
     415             :         }
     416             : 
     417             :         /*---------------------------------------------------------------------*
     418             :          * Channel-aware mode - write signaling information into the bitstream
     419             :          *---------------------------------------------------------------------*/
     420             : 
     421     1129814 :         signaling_enc_rf( st );
     422             : 
     423             :         /*---------------------------------------------------------------------*
     424             :          * Common updates
     425             :          *---------------------------------------------------------------------*/
     426             : 
     427     1129814 :         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 */
     428             :         {
     429      589198 :             updt_enc_common( st );
     430             :         }
     431             :     }
     432             : 
     433             :     /*------------------------------------------------------------------*
     434             :      * Write potentially unused bits in combined format coding
     435             :      *-----------------------------------------------------------------*/
     436             : 
     437      768638 :     if ( hCPE != NULL && hCPE->element_mode == IVAS_CPE_DFT && hCPE->brate_surplus > 0 )
     438             :     {
     439         101 :         while ( diff_nBits > 0 )
     440             :         {
     441           0 :             n = min( diff_nBits, 16 );
     442           0 :             push_indice( sts[0]->hBstr, IND_UNUSED, 0, n );
     443           0 :             diff_nBits -= n;
     444             :         }
     445             :     }
     446             : 
     447             : #ifdef DEBUG_MODE_INFO
     448             :     for ( n = 0; n < n_CoreChannels; n++ )
     449             :     {
     450             :         float tmpF;
     451             :         int16_t tmpS, id;
     452             : #if defined DEBUG_MODE_ACELP || defined DEBUG_MODE_TCX
     453             :         int16_t k, _pitch[3], _pitch_buf[5];
     454             : #endif
     455             : 
     456             :         st = sts[n];
     457             :         id = st->id_element;
     458             : 
     459             :         dbgwrite( &st->core, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "core", n, id, ENC ) );
     460             :         dbgwrite( &st->extl, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "extl", n, id, ENC ) );
     461             :         dbgwrite( &st->bwidth, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "bwidth", n, id, ENC ) );
     462             :         tmpF = st->total_brate / 1000.0f;
     463             :         dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "total_brate", n, id, ENC ) );
     464             :         tmpS = st->bits_frame_nominal;
     465             :         dbgwrite( &tmpS, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "bits_nominal", n, id, ENC ) );
     466             :         tmpF = st->core_brate / 1000.0f;
     467             :         dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "core_brate", n, id, ENC ) );
     468             :         tmpF = st->extl_brate / 1000.0f;
     469             :         dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "extl_brate", n, id, ENC ) );
     470             : 
     471             :         dbgwrite( &st->coder_type, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "coder_type", n, id, ENC ) );
     472             :         dbgwrite( &st->coder_type_raw, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "coder_type_raw", n, id, ENC ) );
     473             :         dbgwrite( &st->clas, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "clas", n, id, ENC ) );
     474             :         dbgwrite( &st->cng_type, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "cng_type", n, id, ENC ) );
     475             :         dbgwrite( &st->L_frame, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "L_frame", n, id, ENC ) );
     476             :         dbgwrite( &st->vad_flag, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "vad_flag", n, id, ENC ) );
     477             :         dbgwrite( &st->localVAD, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "localVAD", n, id, ENC ) );
     478             : 
     479             :         dbgwrite( &st->count_WB, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "count_WB", n, id, ENC ) );
     480             :         dbgwrite( &st->count_SWB, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "count_SWB", n, id, ENC ) );
     481             : 
     482             : #ifdef DEBUG_MODE_ACELP
     483             :         dbgwrite( snr_[n], sizeof( float ), 320, 1, fname( debug_dir, "snr", n, id, ENC ) );
     484             : #endif
     485             :         dbgwrite( &st->sp_aud_decision0, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "sp_aud_decision0", n, id, ENC ) );
     486             :         dbgwrite( &st->sp_aud_decision1, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "sp_aud_decision1", n, id, ENC ) );
     487             :         dbgwrite( &st->sp_aud_decision2, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "sp_aud_decision2", n, id, ENC ) );
     488             : 
     489             :         dbgwrite( &st->lp_noise, sizeof( float ), 1, input_frame, fname( debug_dir, "lp_noise", n, id, ENC ) );
     490             : 
     491             : #if ( defined DEBUG_MODE_ACELP ) || ( defined DEBUG_MODE_TCX )
     492             :         if ( st->coder_type == INACTIVE || st->coder_type == UNVOICED )
     493             :         {
     494             :             _pitch[0] = 0;
     495             :             _pitch[1] = 0;
     496             :             _pitch[2] = 0;
     497             :         }
     498             :         else
     499             :         {
     500             :             _pitch[0] = st->pitch[0];
     501             :             _pitch[1] = st->pitch[1];
     502             :             _pitch[2] = st->pitch[2];
     503             :         }
     504             :         dbgwrite( &_pitch[0], sizeof( int16_t ), 1, ( input_frame / 8 * 3 ), fname( debug_dir, "pitch", n, id, ENC ) );
     505             :         dbgwrite( &_pitch[1], sizeof( int16_t ), 1, ( input_frame / 8 * 3 ), fname( debug_dir, "pitch", n, id, ENC ) );
     506             :         dbgwrite( &_pitch[2], sizeof( int16_t ), 1, ( input_frame / 8 * 2 ), fname( debug_dir, "pitch", n, id, ENC ) );
     507             : 
     508             :         if ( ( st->coder_type == INACTIVE ) || ( st->coder_type == UNVOICED ) )
     509             :         {
     510             :             set_s( _pitch_buf, 0, NB_SUBFR16k );
     511             :         }
     512             :         else if ( st->L_frame != L_FRAME )
     513             :         {
     514             :             for ( k = 0; k < NB_SUBFR16k; k++ )
     515             :                 _pitch_buf[k] = (int16_t) ( pitch_buf[n][k] + 0.5f );
     516             :         }
     517             :         else
     518             :         {
     519             :             for ( k = 0; k < NB_SUBFR; k++ )
     520             :                 _pitch_buf[k] = (int16_t) ( pitch_buf[n][k] * 5.0f / 4.0f + 0.5f );
     521             :         }
     522             :         if ( st->L_frame != L_FRAME )
     523             :         {
     524             :             for ( k = 0; k < NB_SUBFR16k; k++ )
     525             :                 dbgwrite( &_pitch_buf[k], sizeof( int16_t ), 1, L_SUBFR, fname( debug_dir, "pitchCL", n, id, ENC ) );
     526             :         }
     527             :         else
     528             :         {
     529             :             for ( k = 0; k < NB_SUBFR; k++ )
     530             :                 dbgwrite( &_pitch_buf[k], sizeof( int16_t ), 1, L_SUBFR16k, fname( debug_dir, "pitchCL", n, id, ENC ) );
     531             :         }
     532             : #endif
     533             : 
     534             : #ifdef DEBUG_MODE_ACELP
     535             :         if ( st->core != ACELP_CORE )
     536             :         {
     537             :             tmpF = 0.0f;
     538             :             dbgwrite( &tmpF, sizeof( float ), 1, st->L_frame, fname( debug_dir, "exc.enc", n, id, ENC ) );
     539             :             dbgwrite( &tmpF, sizeof( float ), 1, st->L_frame, fname( debug_dir, "resid", n, id, ENC ) );
     540             :         }
     541             :         if ( n_CoreChannels == 1 )
     542             :         {
     543             :             tmpS = -1;
     544             :             dbgwrite( &tmpS, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "coder_type", 2, id, ENC ) );
     545             :             tmpF = 0.0f;
     546             :             dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "total_brate", 2, id, ENC ) );
     547             :             tmpF = 0.0f;
     548             :             dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "core_brate", 2, id, ENC ) );
     549             :             tmpF = 0.0f;
     550             :             dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "extl_brate", 2, id, ENC ) );
     551             :             dbgwrite( &tmpS, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "vad_flag", 2, id, ENC ) );
     552             :             dbgwrite( &tmpS, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "localVAD", 2, id, ENC ) );
     553             :         }
     554             : 
     555             : #endif
     556             :     }
     557             : #endif
     558             : 
     559      768638 :     pop_wmops();
     560             : 
     561      768638 :     return error;
     562             : }

Generated by: LCOV version 1.14