LCOV - code coverage report
Current view: top level - lib_enc - ivas_ism_enc.c (source / functions) Hit Total Coverage
Test: Coverage on main -- conformance test test_26252.py @ efe53129c9ed87a5067dd0a8fb9dca41db9c4add Lines: 116 125 92.8 %
Date: 2026-02-12 06:30:15 Functions: 2 2 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             : #include "ivas_cnst.h"
      36             : #include "prot.h"
      37             : #include "ivas_prot.h"
      38             : #include "ivas_stat_enc.h"
      39             : #ifdef DEBUGGING
      40             : #include "debug.h"
      41             : #endif
      42             : #include "wmc_auto.h"
      43             : 
      44             : 
      45             : /*-------------------------------------------------------------------*
      46             :  * ivas_ism_enc()
      47             :  *
      48             :  * ISM CoreCoders encoding routine
      49             :  *-------------------------------------------------------------------*/
      50             : 
      51       87144 : ivas_error ivas_ism_enc(
      52             :     Encoder_Struct *st_ivas,            /* i/o: IVAS encoder structure          */
      53             :     float *data[],                      /* i  : input signal [channels][samples] */
      54             :     const int16_t input_frame,          /* i  : input frame length per channel  */
      55             :     int16_t *nb_bits_metadata,          /* i  : number of metadata bits         */
      56             :     const int16_t flag_omasa_ener_brate /* i  : less bitrate for objects in OMASA flag */
      57             : )
      58             : {
      59             :     SCE_ENC_HANDLE hSCE;
      60             :     Encoder_State *st;
      61             :     int16_t sce_id;
      62             :     float old_inp_12k8[MAX_NUM_OBJECTS][1][L_INP_12k8];                            /* buffer of input signal @ 12k8            */
      63             :     float old_inp_16k[MAX_NUM_OBJECTS][1][L_INP];                                  /* buffer of input signal @ 16kHz           */
      64             :     int16_t vad_flag[MAX_NUM_OBJECTS];                                             /* VAD flag                                 */
      65             :     float ener[MAX_NUM_OBJECTS][1];                                                /* residual energy from Levinson-Durbin     */
      66             :     float relE[MAX_NUM_OBJECTS][1];                                                /* frame relative energy                    */
      67             :     float A[MAX_NUM_OBJECTS][1][NB_SUBFR16k * ( M + 1 )];                          /* A(z) unquantized for subframes           */
      68             :     float Aw[MAX_NUM_OBJECTS][1][NB_SUBFR16k * ( M + 1 )];                         /* weighted A(z) unquantized for subframes  */
      69             :     float epsP[MAX_NUM_OBJECTS][1][M + 1];                                         /* LP prediction errors                     */
      70             :     float lsp_new[MAX_NUM_OBJECTS][1][M];                                          /* LSPs at the end of the frame             */
      71             :     float lsp_mid[MAX_NUM_OBJECTS][1][M];                                          /* ISPs in the middle of the frame          */
      72             :     int16_t vad_hover_flag[MAX_NUM_OBJECTS][1];                                    /* VAD hangover flag                        */
      73             :     int16_t attack_flag[MAX_NUM_OBJECTS][1];                                       /* attack flag (GSC or TC)                  */
      74             :     float realBuffer[MAX_NUM_OBJECTS][1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer                              */
      75             :     float imagBuffer[MAX_NUM_OBJECTS][1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer                              */
      76             :     float old_wsp[MAX_NUM_OBJECTS][1][L_WSP];                                      /* old weighted input signal                */
      77             :     float pitch_fr[MAX_NUM_OBJECTS][1][NB_SUBFR];                                  /* fractional pitch values                  */
      78             :     float voicing_fr[MAX_NUM_OBJECTS][1][NB_SUBFR];                                /* fractional pitch gains                   */
      79             :     int16_t loc_harm[MAX_NUM_OBJECTS][1];                                          /* harmonicity flag                         */
      80             :     float cor_map_sum[MAX_NUM_OBJECTS][1];                                         /* speech/music clasif. parameter           */
      81             :     int16_t vad_flag_dtx[MAX_NUM_OBJECTS][1];                                      /* HE-SAD flag with additional DTX HO       */
      82             :     float enerBuffer[MAX_NUM_OBJECTS][1][CLDFB_NO_CHANNELS_MAX];                   /* energy buffer                            */
      83             :     float currFlatness[1];                                                         /* flatness parameter                       */
      84             :     float fft_buff[MAX_NUM_OBJECTS][1][2 * L_FFT];                                 /* FFT buffer                               */
      85             :     float fr_bands[1][2 * NB_BANDS];                                               /* energy in frequency bands                    */
      86             :     float Etot_LR[1];                                                              /* total energy; correlation shift              */
      87             :     float lf_E[1][2 * VOIC_BINS];                                                  /* per bin spectrum energy in lf                */
      88             :     int16_t localVAD_HE_SAD[1];                                                    /* local HE VAD */
      89             :     int16_t nchan_ism, dtx_flag, sid_flag, flag_noisy_speech;
      90             :     int16_t md_diff_flag[MAX_NUM_OBJECTS];
      91       87144 :     Encoder_State *prev_st = NULL;
      92             :     int32_t ism_total_brate_ref, ism_total_brate;
      93             :     int16_t i, nchan_transport_ism;
      94             :     ivas_error error;
      95             : 
      96       87144 :     push_wmops( "ivas_ism_enc" );
      97             : 
      98             :     /*------------------------------------------------------------------*
      99             :      * Initialization
     100             :      *-----------------------------------------------------------------*/
     101             : 
     102       87144 :     error = IVAS_ERR_OK;
     103             : 
     104       87144 :     dtx_flag = 0;
     105       87144 :     sid_flag = 0;
     106       87144 :     flag_noisy_speech = 0;
     107             : 
     108       87144 :     nchan_ism = st_ivas->hEncoderConfig->nchan_ism;
     109       87144 :     set_s( md_diff_flag, 1, nchan_ism );
     110             : 
     111       87144 :     nchan_transport_ism = st_ivas->nchan_transport;
     112       87144 :     if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ )
     113             :     {
     114        7826 :         nchan_transport_ism = 1;
     115        7826 :         nchan_ism = 1;
     116             :     }
     117       79318 :     else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC )
     118             :     {
     119       11592 :         nchan_transport_ism = st_ivas->hEncoderConfig->nchan_ism;
     120             :     }
     121             : 
     122             :     /*------------------------------------------------------------------*
     123             :      * Preprocesing
     124             :      *-----------------------------------------------------------------*/
     125             : 
     126      307528 :     for ( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ )
     127             :     {
     128      220384 :         hSCE = st_ivas->hSCE[sce_id];
     129      220384 :         st = hSCE->hCoreCoder[0];
     130             : 
     131             :         /*------------------------------------------------------------------*
     132             :          * Initialization - general
     133             :          *-----------------------------------------------------------------*/
     134             : 
     135      220384 :         mvr2r( data[sce_id], st->input, input_frame );
     136             : 
     137      220384 :         st->element_mode = IVAS_SCE;
     138             : 
     139             :         /*------------------------------------------------------------------*
     140             :          * SCE initialization - core coder
     141             :          *-----------------------------------------------------------------*/
     142             : 
     143      220384 :         st->idchan = 0;
     144      220384 :         st->core = -1;
     145      220384 :         st->core_brate = -1; /* updated in dtx() */
     146      220384 :         st->max_bwidth = st_ivas->hEncoderConfig->max_bwidth;
     147      220384 :         st->input_bwidth = st->last_input_bwidth; /* updated in BWD */
     148      220384 :         st->bwidth = st->last_bwidth;             /* updated in BWD */
     149      220384 :         st->rate_switching_reset = 0;
     150             : #ifdef DEBUGGING
     151             :         st->force = st_ivas->hEncoderConfig->force;
     152             :         st->id_element = sce_id;
     153             : #endif
     154             : 
     155             :         /*---------------------------------------------------------------*
     156             :          * Time Domain Transient Detector
     157             :          *---------------------------------------------------------------*/
     158             : 
     159      220384 :         RunTransientDetection( st->input, input_frame, st->hTranDet );
     160      220384 :         currFlatness[0] = GetTCXAvgTemporalFlatnessMeasure( st->hTranDet, NSUBBLOCKS, 0 );
     161             : 
     162             :         /*----------------------------------------------------------------*
     163             :          * Configuration of core encoder
     164             :          *----------------------------------------------------------------*/
     165             : 
     166             :         /* Force to MODE1 in IVAS */
     167      220384 :         st->codec_mode = MODE1;
     168             : 
     169      220384 :         st->bits_frame_nominal = (int16_t) ( ( hSCE->element_brate / FRAMES_PER_SEC ) - ISM_NB_BITS_METADATA_NOMINAL );
     170             : 
     171             :         /*----------------------------------------------------------------*
     172             :          * Front Pre-processing
     173             :          *----------------------------------------------------------------*/
     174             : 
     175             : #ifdef DEBUGGING
     176             :         st_ivas->noClipping += check_clipping( hSCE->hCoreCoder[0]->input, input_frame, &st_ivas->maxOverload, &st_ivas->minOverload );
     177             : 
     178             : #endif
     179      220384 :         pre_proc_front_ivas( hSCE, NULL, hSCE->element_brate, nb_bits_metadata[sce_id], input_frame, 0, old_inp_12k8[sce_id][0], old_inp_16k[sce_id][0],
     180      220384 :                              &ener[sce_id][0], &relE[sce_id][0], A[sce_id][0], Aw[sce_id][0], epsP[sce_id][0], lsp_new[sce_id][0], lsp_mid[sce_id][0], &vad_hover_flag[sce_id][0], &attack_flag[sce_id][0],
     181      220384 :                              realBuffer[sce_id][0], imagBuffer[sce_id][0], old_wsp[sce_id][0], pitch_fr[sce_id][0], voicing_fr[sce_id][0], &loc_harm[sce_id][0], &cor_map_sum[sce_id][0], &vad_flag_dtx[sce_id][0], enerBuffer[sce_id][0],
     182      220384 :                              fft_buff[sce_id][0], A[sce_id][0], lsp_new[sce_id][0], currFlatness[0], 0, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, NULL, 0, 0, 0, 0, ISM_FORMAT, 0, st_ivas->hEncoderConfig->last_ivas_total_brate, st_ivas->hEncoderConfig->ivas_total_brate );
     183             : 
     184      220384 :         if ( st_ivas->hEncoderConfig->Opt_DTX_ON )
     185             :         {
     186       37736 :             vad_flag[sce_id] = vad_flag_dtx[sce_id][0];
     187             :         }
     188             :         else
     189             :         {
     190      182648 :             vad_flag[sce_id] = st->vad_flag;
     191             :         }
     192             :     }
     193             : 
     194             :     /*------------------------------------------------------------------*
     195             :      * DTX analysis
     196             :      *-----------------------------------------------------------------*/
     197             : 
     198       87144 :     if ( st_ivas->hEncoderConfig->Opt_DTX_ON )
     199             :     {
     200             :         /* compute the dominant sce_id using long term energy */
     201       14226 :         ivas_ism_get_sce_id_dtx( st_ivas->hISMDTX, st_ivas->hSCE, st_ivas->nchan_transport, input_frame );
     202             : 
     203             :         /* analysis and decision about DTX */
     204       14226 :         dtx_flag = ivas_ism_dtx_enc( st_ivas->hISMDTX, st_ivas->hSCE, st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, st_ivas->nchan_transport, vad_flag, st_ivas->hIsmMetaData, md_diff_flag, &sid_flag );
     205             : 
     206       14226 :         if ( sid_flag )
     207             :         {
     208             :             /* estimate coherence between objects */
     209         484 :             ivas_ism_coh_estim_dtx_enc( st_ivas->hISMDTX, st_ivas->hSCE, st_ivas->nchan_transport, input_frame );
     210             :         }
     211             : 
     212             : #ifdef DEBUG_MODE_PARAM_ISM
     213             :         if ( st_ivas->hParamIsmDec != NULL )
     214             :             dbgwrite( &( st_ivas->hParamIsmDec->hParamIsm->flag_noisy_speech ), sizeof( int16_t ), 1, 1, "./res/ParamISM_noisy_speech_flag_enc.dat" );
     215             :         dbgwrite( &( st_ivas->hISMDTX->dtx_flag ), sizeof( int16_t ), 1, 1, "./res/ParamISM_DTX_CNG_flag_enc.dat" );
     216             :         dbgwrite( &( st_ivas->hISMDTX->sce_id_dtx ), sizeof( int16_t ), 1, input_frame, "./res/sce_id_dtx" );
     217             :         dbgwrite( &( dtx_flag ), sizeof( int16_t ), 1, input_frame, "./res/dtx_flag" );
     218             : #endif
     219             :     }
     220             : 
     221             :     /*------------------------------------------------------------------*
     222             :      * Analysis of objects, configuration and decision about bitrates per channel
     223             :      * Metadata quantization and encoding
     224             :      *-----------------------------------------------------------------*/
     225             : 
     226       87144 :     if ( st_ivas->ism_mode == ISM_MODE_PARAM )
     227             :     {
     228        8810 :         ivas_param_ism_compute_noisy_speech_flag( st_ivas );
     229        8810 :         flag_noisy_speech = st_ivas->hParamIsm->flag_noisy_speech;
     230             :     }
     231             : 
     232       87144 :     if ( dtx_flag )
     233             :     {
     234        1685 :         ivas_ism_metadata_sid_enc( st_ivas->hISMDTX, flag_noisy_speech, nchan_ism, st_ivas->nchan_transport, st_ivas->ism_mode, st_ivas->hIsmMetaData, sid_flag, md_diff_flag, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata );
     235             :     }
     236       85459 :     else if ( st_ivas->ism_mode == ISM_MODE_PARAM )
     237             :     {
     238        8503 :         if ( ( error = ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData,
     239        8503 :                                               nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -1, 0, NULL, st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK )
     240             :         {
     241           0 :             return error;
     242             :         }
     243             :     }
     244             :     else /* ISM_MODE_DISC */
     245             :     {
     246       76956 :         if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ )
     247             :         {
     248       19418 :             ism_total_brate = 0;
     249       60746 :             for ( i = 0; i < st_ivas->nSCE; i++ )
     250             :             {
     251       41328 :                 ism_total_brate += st_ivas->hSCE[i]->element_brate;
     252             :             }
     253             :         }
     254             :         else
     255             :         {
     256       57538 :             ism_total_brate = st_ivas->hEncoderConfig->ivas_total_brate;
     257             :         }
     258             : 
     259       76956 :         ism_total_brate_ref = ism_total_brate;
     260             : 
     261      192032 :         if ( ( error = ivas_ism_metadata_enc( &ism_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData,
     262      192032 :                                               nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, st_ivas->hMasa != NULL ? st_ivas->hMasa->data.hOmasaData->lp_noise_CPE : 0, flag_omasa_ener_brate, st_ivas->hMasa != NULL ? &( st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt ) : NULL, st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK )
     263             :         {
     264           0 :             return error;
     265             :         }
     266             : 
     267       76956 :         if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT )
     268             :         {
     269       19418 :             st_ivas->hCPE[0]->brate_surplus = ism_total_brate_ref - ism_total_brate;
     270             :         }
     271             :     }
     272             : 
     273       87144 :     update_last_metadata( nchan_ism, st_ivas->hIsmMetaData, md_diff_flag );
     274             : 
     275             :     /*----------------------------------------------------------------*
     276             :      * Write IVAS format signaling in SID frames
     277             :      *----------------------------------------------------------------*/
     278             : 
     279       87144 :     st = st_ivas->hSCE[0]->hCoreCoder[0];
     280             : 
     281       87144 :     if ( sid_flag )
     282             :     {
     283         484 :         ivas_write_format_sid( st_ivas->hEncoderConfig->ivas_format, IVAS_SCE, st->hBstr, -1, -1 );
     284             :     }
     285             : 
     286             :     /*only metadata encoding is needed for this case*/
     287       87144 :     if ( st_ivas->hEncoderConfig->ivas_format == SBA_ISM_FORMAT )
     288             :     {
     289           0 :         assert( st_ivas->ism_mode != ISM_MODE_NONE );
     290           0 :         return error;
     291             :     }
     292             : 
     293             :     /*------------------------------------------------------------------*
     294             :      * CoreCoders encoding
     295             :      *-----------------------------------------------------------------*/
     296             : 
     297      307528 :     for ( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ )
     298             :     {
     299      220384 :         hSCE = st_ivas->hSCE[sce_id];
     300      220384 :         st = hSCE->hCoreCoder[0];
     301             : 
     302             :         /* update pointer to the buffer of indices of the next channel */
     303      220384 :         if ( sce_id > 0 )
     304             :         {
     305      133240 :             st->hBstr->ind_list = prev_st->hBstr->ind_list + prev_st->hBstr->nb_ind_tot;
     306             :         }
     307             : 
     308      220384 :         if ( st->low_rate_mode )
     309             :         {
     310        7153 :             st->bwidth = WB;
     311             :         }
     312             : 
     313             :         /*----------------------------------------------------------------*
     314             :          * Core codec configuration
     315             :          *----------------------------------------------------------------*/
     316             : 
     317             :         /* IGF reconfiguration */
     318      220384 :         if ( hSCE->last_element_brate != hSCE->element_brate || st->last_bwidth != st->bwidth )
     319             :         {
     320             :             int16_t igf;
     321        5115 :             igf = getIgfPresent( st->element_mode, st->bits_frame_nominal * FRAMES_PER_SEC, st->max_bwidth, st->rf_mode );
     322        5115 :             if ( ( error = IGF_Reconfig( &st->hIGFEnc, igf, 0, st->bits_frame_nominal * FRAMES_PER_SEC, st->max_bwidth, st->element_mode, st->rf_mode ) ) != IVAS_ERR_OK )
     323             :             {
     324           0 :                 return error;
     325             :             }
     326             :         }
     327             : 
     328             :         /* set ACELP@12k8 / ACELP@16k flag for flexible ACELP core */
     329      220384 :         if ( st->core_brate == SID_2k40 || st->core_brate == FRAME_NO_DATA )
     330             :         {
     331        4239 :             st->flag_ACELP16k = set_ACELP_flag( IVAS_SCE, hSCE->element_brate, st->core_brate, 0, 0, -1, -1 );
     332             :         }
     333      216145 :         else if ( st->low_rate_mode )
     334             :         {
     335        7153 :             st->flag_ACELP16k = 0;
     336             :         }
     337             :         else
     338             :         {
     339      208992 :             st->flag_ACELP16k = set_ACELP_flag( IVAS_SCE, hSCE->element_brate, st->total_brate, 0, 0, -1, -1 );
     340             :         }
     341             : 
     342             :         /* modify the coder_type depending on the total_brate per channel */
     343      220384 :         coder_type_modif( st, relE[sce_id][0] );
     344             : 
     345             :         /*----------------------------------------------------------------*
     346             :          * Encoder
     347             :          *----------------------------------------------------------------*/
     348             : 
     349      220384 :         if ( !dtx_flag || ( dtx_flag && sce_id == st_ivas->hISMDTX->sce_id_dtx ) )
     350             :         {
     351      217830 :             if ( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8[sce_id], old_inp_16k[sce_id], ener[sce_id], A[sce_id], Aw[sce_id], epsP[sce_id], lsp_new[sce_id], lsp_mid[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer[sce_id], imagBuffer[sce_id], old_wsp[sce_id], loc_harm[sce_id], cor_map_sum[sce_id], vad_flag_dtx[sce_id], enerBuffer[sce_id], fft_buff[sce_id], 0, ISM_FORMAT, 0 ) ) != IVAS_ERR_OK )
     352             :             {
     353           0 :                 return error;
     354             :             }
     355             :         }
     356             : 
     357             :         /*----------------------------------------------------------------*
     358             :          * Common updates
     359             :          *----------------------------------------------------------------*/
     360             : 
     361             :         /* update input samples buffer */
     362      220384 :         mvr2r( st->input, st->old_input_signal, input_frame );
     363             : 
     364      220384 :         hSCE->last_element_brate = hSCE->element_brate;
     365             : 
     366             :         /* Store previous attack detection flag */
     367      220384 :         st->hTranDet->transientDetector.prev_bIsAttackPresent = st->hTranDet->transientDetector.bIsAttackPresent;
     368             : 
     369      220384 :         prev_st = st;
     370             :     }
     371             : 
     372       87144 :     if ( dtx_flag )
     373             :     {
     374        5924 :         for ( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ )
     375             :         {
     376        4239 :             if ( sce_id != st_ivas->hISMDTX->sce_id_dtx )
     377             :             {
     378        2554 :                 st_ivas->hSCE[sce_id]->hCoreCoder[0]->last_core = st_ivas->hSCE[st_ivas->hISMDTX->sce_id_dtx]->hCoreCoder[0]->last_core;
     379        2554 :                 st_ivas->hSCE[sce_id]->hCoreCoder[0]->last_core_brate = st_ivas->hSCE[st_ivas->hISMDTX->sce_id_dtx]->hCoreCoder[0]->core_brate;
     380        2554 :                 st_ivas->hSCE[sce_id]->hCoreCoder[0]->last_L_frame = st_ivas->hSCE[st_ivas->hISMDTX->sce_id_dtx]->hCoreCoder[0]->last_L_frame;
     381             :             }
     382             :         }
     383             :     }
     384             : 
     385             : #ifdef DEBUG_MODE_INFO
     386             :     if ( dtx_flag )
     387             :     {
     388             :         float tmpF;
     389             :         int16_t id, n;
     390             : 
     391             :         n = 0;
     392             :         for ( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ )
     393             :         {
     394             :             if ( sce_id != st_ivas->hISMDTX->sce_id_dtx )
     395             :             {
     396             :                 st = st_ivas->hSCE[sce_id]->hCoreCoder[0];
     397             :                 id = st->id_element;
     398             : 
     399             :                 dbgwrite( &st->core, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "core", n, id, ENC ) );
     400             :                 dbgwrite( &st->extl, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "extl", n, id, ENC ) );
     401             :                 dbgwrite( &st->bwidth, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "bwidth", n, id, ENC ) );
     402             :                 tmpF = st->total_brate / 1000.0f;
     403             :                 dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "total_brate", n, id, ENC ) );
     404             :                 tmpF = st->core_brate / 1000.0f;
     405             :                 dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "core_brate", n, id, ENC ) );
     406             :                 tmpF = st->extl_brate / 1000.0f;
     407             :                 dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "extl_brate", n, id, ENC ) );
     408             : 
     409             :                 dbgwrite( &st->coder_type, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "coder_type", n, id, ENC ) );
     410             :                 dbgwrite( &st->coder_type_raw, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "coder_type_raw", n, id, ENC ) );
     411             :                 dbgwrite( &st->vad_flag, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "vad_flag", n, id, ENC ) );
     412             :                 dbgwrite( &st->localVAD, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "localVAD", n, id, ENC ) );
     413             : 
     414             :                 dbgwrite( &st->lp_noise, sizeof( float ), 1, input_frame, fname( debug_dir, "lp_noise", n, id, ENC ) );
     415             :             }
     416             :         }
     417             :     }
     418             : #endif
     419       87144 :     pop_wmops();
     420             : 
     421       87144 :     return error;
     422             : }
     423             : 
     424             : 
     425             : /*-------------------------------------------------------------------------
     426             :  * ivas_ism_enc_config()
     427             :  *
     428             :  * - select ISM format mode
     429             :  * - reconfigure the ISM format encoder
     430             :  *-------------------------------------------------------------------------*/
     431             : 
     432       67726 : ivas_error ivas_ism_enc_config(
     433             :     Encoder_Struct *st_ivas /* i/o: IVAS encoder structure      */
     434             : )
     435             : {
     436             :     ivas_error error;
     437             :     ISM_MODE last_ism_mode;
     438             :     int16_t nchan_transport_old;
     439             :     int16_t nSCE_old, nCPE_old;
     440             : 
     441       67726 :     error = IVAS_ERR_OK;
     442       67726 :     last_ism_mode = st_ivas->ism_mode;
     443             : 
     444             :     /* select ISM format mode */
     445       67726 :     st_ivas->ism_mode = ivas_ism_mode_select( st_ivas->hEncoderConfig->nchan_inp, st_ivas->hEncoderConfig->ivas_total_brate );
     446             : 
     447             :     /* ISM bit-rate switching */
     448       67726 :     if ( ( st_ivas->ism_mode != last_ism_mode ) || ( st_ivas->hEncoderConfig->ivas_total_brate != st_ivas->hEncoderConfig->last_ivas_total_brate ) )
     449             :     {
     450             :         int32_t element_brate_tmp[MAX_NUM_OBJECTS];
     451             : 
     452         999 :         nchan_transport_old = st_ivas->nchan_transport;
     453             : 
     454             :         /* Reset and Initialize */
     455         999 :         if ( st_ivas->ism_mode == ISM_MODE_PARAM )
     456             :         {
     457         322 :             st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE;
     458             :         }
     459             :         else
     460             :         {
     461         677 :             st_ivas->nchan_transport = st_ivas->hEncoderConfig->nchan_inp;
     462             :         }
     463             : 
     464         999 :         nCPE_old = st_ivas->nCPE;
     465         999 :         nSCE_old = st_ivas->nSCE;
     466         999 :         st_ivas->nSCE = st_ivas->nchan_transport;
     467         999 :         st_ivas->nCPE = 0;
     468             : 
     469         999 :         if ( ( error = ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hEncoderConfig->nchan_inp, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ) != IVAS_ERR_OK )
     470             :         {
     471           0 :             return error;
     472             :         }
     473             : 
     474         999 :         if ( ( error = ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS, MC_MODE_NONE ) ) != IVAS_ERR_OK )
     475             :         {
     476           0 :             return error;
     477             :         }
     478             : 
     479         999 :         if ( st_ivas->ism_mode == ISM_MODE_PARAM && last_ism_mode == ISM_MODE_DISC )
     480             :         {
     481             :             /* Allocate and Initialize the memory used by ParamISM when switch from Discrete ISM */
     482         313 :             if ( ( error = ivas_param_ism_enc_open( st_ivas ) ) != IVAS_ERR_OK )
     483             :             {
     484           0 :                 return error;
     485             :             }
     486             :         }
     487             : 
     488         999 :         if ( st_ivas->ism_mode == ISM_MODE_DISC && last_ism_mode == ISM_MODE_PARAM )
     489             :         {
     490             :             /* Deallocate the memory used by ParamISM when switch to Discrete ISM */
     491         315 :             ivas_param_ism_enc_close( &( st_ivas->hParamIsm ), st_ivas->hEncoderConfig->input_Fs );
     492             :         }
     493             :     }
     494             : 
     495       67726 :     return error;
     496             : }

Generated by: LCOV version 1.14