LCOV - code coverage report
Current view: top level - lib_enc - ivas_ism_enc_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 574a190e3c6896c6c4ed10d7f23649709a0c4347 Lines: 216 226 95.6 %
Date: 2025-06-27 02:59:36 Functions: 2 2 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             : #include "ivas_cnst.h"
      36             : #include "prot_fx.h"
      37             : #include "ivas_stat_enc.h"
      38             : #include "wmc_auto.h"
      39             : #include "ivas_prot_fx.h"
      40             : #include "prot_fx_enc.h"
      41             : #ifdef DEBUGGING
      42             : #include "debug.h"
      43             : #endif
      44             : 
      45             : 
      46             : /*-------------------------------------------------------------------*
      47             :  * ivas_ism_enc()
      48             :  *
      49             :  * ISM CoreCoders encoding routine
      50             :  *-------------------------------------------------------------------*/
      51      109022 : ivas_error ivas_ism_enc_fx(
      52             :     Encoder_Struct *st_ivas,           /* i/o: IVAS encoder structure                                           */
      53             :     Word32 *data[],                    /* i  : input signal [channels][samples]                         Q(q_data)*/
      54             :     Word16 q_data,                     /* i  : Q-factor of input signal                                         */
      55             :     const Word16 input_frame,          /* i  : input frame length per channel                           Q0*/
      56             :     Word16 *nb_bits_metadata,          /* i  : number of metadata bits                                          Q0*/
      57             :     const Word16 flag_omasa_ener_brate /* i  : less bitrate for objects in OMASA flag           Q0*/
      58             : )
      59             : {
      60             :     SCE_ENC_HANDLE hSCE;
      61             :     Encoder_State *st;
      62             :     Word16 sce_id;
      63             :     Word16 old_inp_12k8_fx[MAX_NUM_OBJECTS][1][L_INP_12k8]; /* buffer of input signal @ 12k8    Q_new-1 */
      64             :     Word16 old_inp_16k_fx[MAX_NUM_OBJECTS][1][L_INP];       /* buffer of input signal @ 12k8    Q_new-1 */
      65      109022 :     Word16 Q_new[MAX_NUM_OBJECTS][1] = { 0 };
      66             :     Word16 vad_flag[MAX_NUM_OBJECTS];   /* VAD flag                                 */
      67             :     Word32 ener_fx[MAX_NUM_OBJECTS][1]; /* residual energy from Levinson-Durbin  Q6 */
      68             :     Word16 relE_fx[MAX_NUM_OBJECTS][1];
      69             :     /* frame relative energy, Q8                */
      70      109022 :     Word16 A_fx[MAX_NUM_OBJECTS][1][NB_SUBFR16k * ( M + 1 )] = { 0 };  /* A(z) unquantized for subframes           */
      71      109022 :     Word16 Aw_fx[MAX_NUM_OBJECTS][1][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* weighted A(z) unquantized for subframes  */
      72             :     Word32 epsP_fx[MAX_NUM_OBJECTS][1][M + 1];                         /* LP prediction errors                     */
      73             :     Word16 epsP_fx_q[MAX_NUM_OBJECTS][1];
      74             :     Word16 lsp_new_fx[MAX_NUM_OBJECTS][1][M];                                          /* LSPs at the end of the frame           Q15 */
      75             :     Word16 lsp_mid_fx[MAX_NUM_OBJECTS][1][M];                                          /* ISPs in the middle of the frame        Q15 */
      76             :     Word16 vad_hover_flag[MAX_NUM_OBJECTS][1];                                         /* VAD hangover flag                        */
      77             :     Word16 attack_flag[MAX_NUM_OBJECTS][1];                                            /* attack flag (GSC or TC)                  */
      78             :     Word32 realBuffer_fx[MAX_NUM_OBJECTS][1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer                              */
      79             :     Word32 imagBuffer_fx[MAX_NUM_OBJECTS][1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer                              */
      80             :     Word16 q_re_im_buf[MAX_NUM_OBJECTS];
      81             :     Word16 old_wsp_fx[MAX_NUM_OBJECTS][1][L_WSP]; /* old weighted input signal                */
      82             :     Word16 q_old_wsp;
      83             :     Word16 e_old_wsp[MAX_NUM_OBJECTS][CPE_CHANNELS];
      84             :     Word16 pitch_fr_fx[MAX_NUM_OBJECTS][1][NB_SUBFR];                /* fractional pitch values               Q6   */
      85             :     Word16 voicing_fr_fx[MAX_NUM_OBJECTS][1][NB_SUBFR];              /* fractional pitch gains                Q15  */
      86             :     Word16 loc_harm[MAX_NUM_OBJECTS][1];                             /* harmonicity flag                         */
      87             :     Word16 cor_map_sum_fx[MAX_NUM_OBJECTS][1];                       /* speech/music clasif. parameter         Q8 */
      88             :     Word16 vad_flag_dtx[MAX_NUM_OBJECTS][1];                         /* HE-SAD flag with additional DTX HO       */
      89             :     Word32 enerBuffer_fx[MAX_NUM_OBJECTS][1][CLDFB_NO_CHANNELS_MAX]; /* energy buffer                            */
      90             :     Word16 enerBuffer_fx_exp[MAX_NUM_OBJECTS][1];                    /* energy buffer                            */
      91             :     Word32 currFlatness_fx[1];                                       /* flatness parameter                       */
      92             :     Word16 fft_buff_fx[MAX_NUM_OBJECTS][1][2 * L_FFT];               /* FFT buffer                               */
      93             :     Word16 fft_buff_fx_q[MAX_NUM_OBJECTS][1];                        /* FFT buffer                               */
      94             :     Word32 fr_bands_fx[1][2 * NB_BANDS];                             /* energy in frequency bands                    */
      95             :     Word16 Etot_LR_fx[1];                                            /* total energy; correlation shift            Q8  */
      96             :     Word32 lf_E_fx[1][2 * VOIC_BINS];                                /* per bin spectrum energy in lf                */
      97             :     Word16 localVAD_HE_SAD[1];                                       /* local HE VAD */
      98             :     Word16 nchan_ism, dtx_flag, sid_flag, flag_noisy_speech;
      99             :     Word16 md_diff_flag[MAX_NUM_OBJECTS];
     100      109022 :     Encoder_State *prev_st = NULL;
     101             :     Word32 ism_total_brate_ref, ism_total_brate;
     102             :     Word16 i, nchan_transport_ism;
     103             :     Word16 q_st_inp_16;
     104             :     ivas_error error;
     105      109022 :     move16(); // Q_new
     106      109022 :     move16(); // Q_new
     107      109022 :     move16(); // Q_new
     108      109022 :     move16(); // Q_new
     109             : 
     110      109022 :     push_wmops( "ivas_ism_enc" );
     111             : 
     112             :     /*------------------------------------------------------------------*
     113             :      * Initialization
     114             :      *-----------------------------------------------------------------*/
     115             : 
     116      109022 :     error = IVAS_ERR_OK;
     117      109022 :     move32();
     118             : 
     119      545110 :     FOR( i = 0; i < MAX_NUM_OBJECTS; i++ )
     120             :     {
     121      436088 :         set16_zero_fx( old_inp_12k8_fx[i][0], L_INP_12k8 );
     122             :     }
     123             : 
     124      109022 :     set16_fx( q_re_im_buf, 0, MAX_NUM_OBJECTS );
     125             : 
     126      109022 :     dtx_flag = 0;
     127      109022 :     sid_flag = 0;
     128      109022 :     flag_noisy_speech = 0;
     129      109022 :     move16();
     130      109022 :     move16();
     131      109022 :     move16();
     132             : 
     133      109022 :     nchan_ism = st_ivas->hEncoderConfig->nchan_ism;
     134      109022 :     move16();
     135      109022 :     set16_fx( md_diff_flag, 1, nchan_ism );
     136             : 
     137      109022 :     nchan_transport_ism = st_ivas->nchan_transport; /* Q0 */
     138      109022 :     move16();
     139      109022 :     IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) )
     140             :     {
     141        2054 :         nchan_transport_ism = 1;
     142        2054 :         nchan_ism = 1;
     143        2054 :         move16();
     144        2054 :         move16();
     145             :     }
     146      106968 :     ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
     147             :     {
     148        3142 :         nchan_transport_ism = st_ivas->hEncoderConfig->nchan_ism; /* Q0 */
     149        3142 :         move16();
     150             :     }
     151      388472 :     FOR( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ )
     152             :     {
     153      279450 :         set16_fx( old_inp_16k_fx[sce_id][0], 0, L_INP );
     154             :     }
     155             : 
     156             :     /*------------------------------------------------------------------*
     157             :      * Preprocesing
     158             :      *-----------------------------------------------------------------*/
     159             : 
     160      388472 :     FOR( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ )
     161             :     {
     162      279450 :         hSCE = st_ivas->hSCE[sce_id];
     163      279450 :         st = hSCE->hCoreCoder[0];
     164             : 
     165             :         /*------------------------------------------------------------------*
     166             :          * Initialization - general
     167             :          *-----------------------------------------------------------------*/
     168      279450 :         Word16 Q_min = s_min( q_data, add( st->q_inp32, L_norm_arr( st->input32_fx - input_frame, input_frame ) ) );
     169      279450 :         scale_sig32( st->input32_fx - input_frame, input_frame, sub( Q_min, st->q_inp32 ) );
     170      279450 :         st->q_old_inp32 = Q_min;
     171      279450 :         move16();
     172      279450 :         Copy_Scale_sig32( data[sce_id], st->input32_fx, input_frame, sub( Q_min, q_data ) ); // Q(Q_min)
     173      279450 :         st->q_inp32 = Q_min;
     174      279450 :         move16();
     175      279450 :         q_st_inp_16 = sub( getScaleFactor32( st->input32_fx, input_frame ), 16 );
     176      279450 :         Copy_Scale_sig_32_16( st->input32_fx, st->input_fx, input_frame, q_st_inp_16 ); // Q_min -> Q(q_inp + Q_min)
     177      279450 :         st->q_inp = add( q_st_inp_16, Q_min );
     178      279450 :         move16();
     179             : 
     180      279450 :         st->element_mode = IVAS_SCE;
     181      279450 :         move16();
     182             : 
     183     4750650 :         FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
     184             :         {
     185     4471200 :             set_zero_fx( realBuffer_fx[sce_id][0][i], CLDFB_NO_CHANNELS_MAX );
     186     4471200 :             set_zero_fx( imagBuffer_fx[sce_id][0][i], CLDFB_NO_CHANNELS_MAX );
     187             :         }
     188             :         /*------------------------------------------------------------------*
     189             :          * SCE initialization - core coder
     190             :          *-----------------------------------------------------------------*/
     191             : 
     192      279450 :         st->idchan = 0;
     193      279450 :         st->core = -1;
     194      279450 :         st->core_brate = -1; /* updated in dtx() */
     195      279450 :         st->max_bwidth = st_ivas->hEncoderConfig->max_bwidth;
     196      279450 :         st->input_bwidth = st->last_input_bwidth; /* updated in BWD */
     197      279450 :         st->bwidth = st->last_bwidth;             /* updated in BWD */
     198      279450 :         st->rate_switching_reset = 0;
     199             : #ifdef DEBUGGING
     200             :         st->force = st_ivas->hEncoderConfig->force;
     201             :         st->id_element = sce_id;
     202             : #ifdef DEBUG_FORCE_DIR
     203             :         st->force_dir = st_ivas->hEncoderConfig->force_dir;
     204             : #endif
     205             : #endif
     206      279450 :         move16();
     207      279450 :         move16();
     208      279450 :         move16();
     209      279450 :         move16();
     210      279450 :         move16();
     211      279450 :         move16();
     212      279450 :         move16();
     213             : 
     214             :         /*---------------------------------------------------------------*
     215             :          * Time Domain Transient Detector
     216             :          *---------------------------------------------------------------*/
     217             : 
     218      279450 :         RunTransientDetection_ivas_fx( st->input_fx, input_frame, st->hTranDet, st->q_inp );
     219             : 
     220      279450 :         currFlatness_fx[0] = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS, 0 ); // Q21
     221      279450 :         move16();
     222             : 
     223             :         /*----------------------------------------------------------------*
     224             :          * Configuration of core encoder
     225             :          *----------------------------------------------------------------*/
     226             : 
     227             :         /* Force to MODE1 in IVAS */
     228      279450 :         st->codec_mode = MODE1;
     229      279450 :         move16();
     230             : 
     231      279450 :         st->bits_frame_nominal = sub( extract_l( Mpy_32_32( hSCE->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ), ISM_NB_BITS_METADATA_NOMINAL );
     232      279450 :         move16();
     233             : 
     234             : #ifdef DEBUG_MODE_INFO
     235             :         dbgwrite( &st->element_mode, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "element_mode", 0, st->id_element, ENC ) );
     236             : #endif
     237             : 
     238             :         /*----------------------------------------------------------------*
     239             :          * Front Pre-processing
     240             :          *----------------------------------------------------------------*/
     241     1485423 :         FOR( i = 0; i < hSCE->hCoreCoder[0]->nb_subfr; i++ )
     242             :         {
     243     1205973 :             Scale_sig( &A_fx[sce_id][0][i * ( M + 1 )], M + 1, sub( norm_s( A_fx[sce_id][0][i * ( M + 1 )] ), 2 ) ); // scaling to Q12
     244             :         }
     245             : 
     246      279450 :         set16_fx( old_wsp_fx[sce_id][0], 0, L_WSP );
     247      279450 :         q_old_wsp = Q15;
     248      279450 :         move16();
     249             : 
     250             :         Word16 q_fr_bands[2];
     251      279450 :         error = pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata[sce_id], input_frame, 0, old_inp_12k8_fx[sce_id][0], old_inp_16k_fx[sce_id][0],
     252      279450 :                                         &ener_fx[sce_id][0], &relE_fx[sce_id][0], A_fx[sce_id][0], Aw_fx[sce_id][0], epsP_fx[sce_id][0], &epsP_fx_q[sce_id][0], lsp_new_fx[sce_id][0], lsp_mid_fx[sce_id][0], &vad_hover_flag[sce_id][0], &attack_flag[sce_id][0],
     253      279450 :                                         realBuffer_fx[sce_id][0], imagBuffer_fx[sce_id][0], &q_re_im_buf[sce_id], old_wsp_fx[sce_id][0], &q_old_wsp, pitch_fr_fx[sce_id][0], voicing_fr_fx[sce_id][0], &loc_harm[sce_id][0], &cor_map_sum_fx[sce_id][0], &vad_flag_dtx[sce_id][0], enerBuffer_fx[sce_id][0], &enerBuffer_fx_exp[sce_id][0],
     254      279450 :                                         fft_buff_fx[sce_id][0], &fft_buff_fx_q[sce_id][0], A_fx[sce_id][0], lsp_new_fx[sce_id][0], currFlatness_fx[0], 0, fr_bands_fx, q_fr_bands, Etot_LR_fx, lf_E_fx, 31, localVAD_HE_SAD, NULL, 31, 0, 0, 0, 0, ISM_FORMAT, 0, st_ivas->hEncoderConfig->last_ivas_total_brate, st_ivas->hEncoderConfig->ivas_total_brate, &Q_new[sce_id][0]
     255             : #ifdef DEBUG_MODE_INFO
     256             :                                         ,
     257             :                                         st->id_element
     258             : #endif
     259             :         );
     260      279450 :         e_old_wsp[sce_id][0] = sub( Q15, q_old_wsp );
     261      279450 :         move16();
     262      279450 :         IF( error != IVAS_ERR_OK )
     263             :         {
     264           0 :             return error;
     265             :         }
     266             : 
     267      279450 :         IF( st_ivas->hEncoderConfig->Opt_DTX_ON )
     268             :         {
     269       38116 :             vad_flag[sce_id] = vad_flag_dtx[sce_id][0];
     270       38116 :             move16();
     271             :         }
     272             :         ELSE
     273             :         {
     274      241334 :             vad_flag[sce_id] = st->vad_flag; /* Q0 */
     275      241334 :             move16();
     276             :         }
     277             :     }
     278             : 
     279             :     /*------------------------------------------------------------------*
     280             :      * DTX analysis
     281             :      *-----------------------------------------------------------------*/
     282             : 
     283             :     /* compute the dominant sce_id using long term energy */
     284             : 
     285      109022 :     IF( st_ivas->hEncoderConfig->Opt_DTX_ON )
     286             :     {
     287       14826 :         ivas_ism_get_sce_id_dtx_fx( st_ivas->hISMDTX, st_ivas->hSCE, st_ivas->nchan_transport, input_frame );
     288             : 
     289       14826 :         dtx_flag = ivas_ism_dtx_enc_fx( 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 ); /* Q0 */
     290             : 
     291       14826 :         IF( sid_flag )
     292             :         {
     293             :             /* estimate coherence between objects */
     294         536 :             ivas_ism_coh_estim_dtx_enc_fx( st_ivas->hISMDTX, st_ivas->hSCE, st_ivas->nchan_transport, input_frame );
     295             :         }
     296             :     }
     297             : 
     298             :     /*------------------------------------------------------------------*
     299             :      * Analysis of objects, configuration and decision about bitrates per channel
     300             :      * Metadata quantization and encoding
     301             :      *-----------------------------------------------------------------*/
     302             : 
     303      109022 :     IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) )
     304             :     {
     305       20720 :         ivas_param_ism_compute_noisy_speech_flag_fx( st_ivas );
     306       20720 :         flag_noisy_speech = st_ivas->hParamIsm->flag_noisy_speech; // Q0
     307       20720 :         move16();
     308             :     }
     309             : 
     310      109022 :     IF( dtx_flag )
     311             :     {
     312        2115 :         ivas_ism_metadata_sid_enc_fx( 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 );
     313             :     }
     314      106907 :     ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) )
     315             :     {
     316       20413 :         IF( ( error = ivas_ism_metadata_enc_fx( &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, nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -256 /* -1.0f in Q8 */, 0, NULL, st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK )
     317             :         {
     318           0 :             return error;
     319             :         }
     320             :     }
     321             :     ELSE /* ISM_MODE_DISC */
     322             :     {
     323       86494 :         test();
     324       86494 :         IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) )
     325             :         {
     326        5196 :             ism_total_brate = 0;
     327        5196 :             move16();
     328       15710 :             FOR( i = 0; i < st_ivas->nSCE; i++ )
     329             :             {
     330       10514 :                 ism_total_brate = L_add( ism_total_brate, st_ivas->hSCE[i]->element_brate ); /* Q0 */
     331             :             }
     332             :         }
     333             :         ELSE
     334             :         {
     335       81298 :             ism_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; /* Q0 */
     336       81298 :             move32();
     337             :         }
     338             : 
     339       86494 :         ism_total_brate_ref = ism_total_brate; /* Q0 */
     340       86494 :         move32();
     341             : 
     342             :         Word16 lp_noise_CPE_fx;
     343       86494 :         if ( st_ivas->hMasa != NULL )
     344             :         {
     345        5196 :             lp_noise_CPE_fx = st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx;
     346        5196 :             move16();
     347             :         }
     348             :         else
     349             :         {
     350       81298 :             lp_noise_CPE_fx = 0;
     351       81298 :             move16();
     352             :         }
     353             : 
     354             :         Word16 *omasa_stereo_sw_cnt;
     355       86494 :         if ( st_ivas->hMasa != NULL )
     356             :         {
     357        5196 :             omasa_stereo_sw_cnt = &( st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt );
     358             :         }
     359             :         else
     360             :         {
     361       81298 :             omasa_stereo_sw_cnt = NULL;
     362             :         }
     363       86494 :         IF( ( error = ivas_ism_metadata_enc_fx( &ism_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData,
     364             :                                                 nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, lp_noise_CPE_fx, flag_omasa_ener_brate, omasa_stereo_sw_cnt, st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame ) ) !=
     365             :             IVAS_ERR_OK )
     366             :         {
     367           0 :             return error;
     368             :         }
     369             : 
     370       86494 :         IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) )
     371             :         {
     372        5196 :             st_ivas->hCPE[0]->brate_surplus = L_sub( ism_total_brate_ref, ism_total_brate ); /* Q0 */
     373        5196 :             move32();
     374             :         }
     375             :     }
     376      109022 :     update_last_metadata_fx( nchan_ism, st_ivas->hIsmMetaData, md_diff_flag );
     377             : 
     378             :     /*----------------------------------------------------------------*
     379             :      * Write IVAS format signaling in SID frames
     380             :      *----------------------------------------------------------------*/
     381             : 
     382      109022 :     st = st_ivas->hSCE[0]->hCoreCoder[0];
     383             : 
     384      109022 :     IF( sid_flag )
     385             :     {
     386         536 :         ivas_write_format_sid_fx( st_ivas->hEncoderConfig->ivas_format, IVAS_SCE, st->hBstr );
     387             :     }
     388             : 
     389             :     /*only metadata encoding is needed for this case*/
     390      109022 :     IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) )
     391             :     {
     392           0 :         assert( st_ivas->ism_mode != ISM_MODE_NONE );
     393           0 :         return error;
     394             :     }
     395             : 
     396             :     /*------------------------------------------------------------------*
     397             :      * CoreCoders encoding
     398             :      *-----------------------------------------------------------------*/
     399             : 
     400      388472 :     FOR( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ )
     401             :     {
     402      279450 :         hSCE = st_ivas->hSCE[sce_id];
     403      279450 :         st = hSCE->hCoreCoder[0];
     404             : 
     405             :         /* update pointer to the buffer of indices of the next channel */
     406      279450 :         IF( sce_id > 0 )
     407             :         {
     408      170428 :             st->hBstr->ind_list = prev_st->hBstr->ind_list + prev_st->hBstr->nb_ind_tot;
     409             :         }
     410             : 
     411      279450 :         if ( st->low_rate_mode )
     412             :         {
     413        7551 :             st->bwidth = WB;
     414        7551 :             move16();
     415             :         }
     416             : 
     417             :         /*----------------------------------------------------------------*
     418             :          * Core codec configuration
     419             :          *----------------------------------------------------------------*/
     420             : 
     421             :         /* IGF reconfiguration */
     422      279450 :         test();
     423      279450 :         IF( NE_32( hSCE->last_element_brate, hSCE->element_brate ) || NE_32( st->last_bwidth, st->bwidth ) )
     424             :         {
     425             :             Word16 igf;
     426        3941 :             igf = getIgfPresent_fx( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->max_bwidth, st->rf_mode );
     427        3941 :             IF( ( error = IGF_Reconfig_fx( &st->hIGFEnc, igf, 0, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->max_bwidth, st->element_mode, st->rf_mode ) ) != IVAS_ERR_OK )
     428             :             {
     429           0 :                 return error;
     430             :             }
     431             :         }
     432             : 
     433             :         /* set ACELP@12k8 / ACELP@16k flag for flexible ACELP core */
     434      279450 :         test();
     435      279450 :         IF( EQ_32( st->core_brate, SID_2k40 ) || st->core_brate == FRAME_NO_DATA )
     436             :         {
     437        5207 :             st->flag_ACELP16k = set_ACELP_flag_IVAS( IVAS_SCE, hSCE->element_brate, st->core_brate, 0, 0, -1, -1 );
     438        5207 :             move16();
     439             :         }
     440      274243 :         ELSE IF( st->low_rate_mode )
     441             :         {
     442        7551 :             st->flag_ACELP16k = 0;
     443        7551 :             move16();
     444             :         }
     445             :         ELSE
     446             :         {
     447      266692 :             st->flag_ACELP16k = set_ACELP_flag_IVAS( IVAS_SCE, hSCE->element_brate, st->total_brate, 0, 0, -1, -1 ); /* Q0 */
     448      266692 :             move16();
     449             :         }
     450             : 
     451             :         /* modify the coder_type depending on the total_brate per channel */
     452      279450 :         coder_type_modif_ivas_fx( st, relE_fx[sce_id][0] );
     453             : 
     454             :         /*----------------------------------------------------------------*
     455             :          * Encoder
     456             :          *----------------------------------------------------------------*/
     457      279450 :         test();
     458      279450 :         test();
     459      279450 :         IF( !dtx_flag || ( dtx_flag && EQ_16( sce_id, st_ivas->hISMDTX->sce_id_dtx ) ) )
     460             :         {
     461      276358 :             Scale_sig( old_wsp_fx[sce_id][0], L_WSP, sub( e_old_wsp[sce_id][0], Q16 ) ); /* exp(16) */
     462      276358 :             e_old_wsp[sce_id][0] = 16;
     463      276358 :             move16();
     464      276358 :             IF( NE_32( ( error = ivas_core_enc_fx( hSCE, NULL, NULL, 1, old_inp_12k8_fx[sce_id], old_inp_16k_fx[sce_id], Q_new[sce_id], ener_fx[sce_id], A_fx[sce_id], Aw_fx[sce_id], epsP_fx[sce_id], epsP_fx_q[sce_id], lsp_new_fx[sce_id], lsp_mid_fx[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer_fx[sce_id], imagBuffer_fx[sce_id], &q_re_im_buf[sce_id], old_wsp_fx[sce_id], e_old_wsp[sce_id], loc_harm[sce_id], cor_map_sum_fx[sce_id], vad_flag_dtx[sce_id], enerBuffer_fx[sce_id], enerBuffer_fx_exp[sce_id], fft_buff_fx[sce_id], 0, ISM_FORMAT, 0 ) ), IVAS_ERR_OK ) )
     465             :             {
     466           0 :                 return error;
     467             :             }
     468             :         }
     469             : 
     470             :         /*----------------------------------------------------------------*
     471             :          * Common updates
     472             :          *----------------------------------------------------------------*/
     473             : 
     474             :         /* update input samples buffer */
     475             : 
     476      279450 :         Copy( st->input_fx, st->old_input_signal_fx, input_frame ); /* st->q_inp */
     477      279450 :         st->q_old_inp = st->q_inp;
     478      279450 :         move16();
     479      279450 :         Copy32( st->input32_fx, st->old_input_signal32_fx, input_frame ); /* st->q_inp32 */
     480      279450 :         st->q_old_inp32 = st->q_inp32;
     481      279450 :         move16();
     482             : 
     483      279450 :         hSCE->last_element_brate = hSCE->element_brate; /* Q0 */
     484      279450 :         move32();
     485             : 
     486             :         /* Store previous attack detection flag */
     487      279450 :         st->hTranDet->transientDetector.prev_bIsAttackPresent = st->hTranDet->transientDetector.bIsAttackPresent; /* Q0 */
     488      279450 :         move16();
     489             : 
     490      279450 :         prev_st = st;
     491             :     }
     492             : 
     493      109022 :     IF( dtx_flag )
     494             :     {
     495        7322 :         FOR( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ )
     496             :         {
     497        5207 :             IF( NE_16( sce_id, st_ivas->hISMDTX->sce_id_dtx ) )
     498             :             {
     499        3092 :                 st_ivas->hSCE[sce_id]->hCoreCoder[0]->last_core = st_ivas->hSCE[st_ivas->hISMDTX->sce_id_dtx]->hCoreCoder[0]->last_core;        /* Q0 */
     500        3092 :                 st_ivas->hSCE[sce_id]->hCoreCoder[0]->last_core_brate = st_ivas->hSCE[st_ivas->hISMDTX->sce_id_dtx]->hCoreCoder[0]->core_brate; /* Q0 */
     501        3092 :                 st_ivas->hSCE[sce_id]->hCoreCoder[0]->last_L_frame = st_ivas->hSCE[st_ivas->hISMDTX->sce_id_dtx]->hCoreCoder[0]->last_L_frame;  /* Q0 */
     502        3092 :                 move16();
     503        3092 :                 move32();
     504        3092 :                 move16();
     505             :             }
     506             :         }
     507             :     }
     508             : 
     509             : #ifdef DEBUG_MODE_INFO
     510             :     for ( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ )
     511             :     {
     512             :         float tmpF;
     513             :         int16_t id;
     514             : 
     515             :         st = st_ivas->hSCE[sce_id]->hCoreCoder[0];
     516             :         id = st->id_element;
     517             : 
     518             :         tmpF = st->element_brate / 1000.0f;
     519             :         dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "element_brate", 0, id, ENC ) );
     520             :     }
     521             : #endif
     522             : 
     523      109022 :     pop_wmops();
     524             : 
     525      109022 :     return error;
     526             : }
     527             : 
     528             : /*-------------------------------------------------------------------------
     529             :  * ivas_ism_enc_config()
     530             :  *
     531             :  * - select ISM format mode
     532             :  * - reconfigure the ISM format encoder
     533             :  *-------------------------------------------------------------------------*/
     534             : 
     535      103826 : ivas_error ivas_ism_enc_config(
     536             :     Encoder_Struct *st_ivas /* i/o: IVAS encoder structure      */
     537             : )
     538             : {
     539             :     ivas_error error;
     540             :     ISM_MODE last_ism_mode;
     541             :     Word16 nchan_transport_old;
     542             :     Word16 nSCE_old, nCPE_old;
     543             : 
     544      103826 :     error = IVAS_ERR_OK;
     545      103826 :     move32();
     546      103826 :     last_ism_mode = st_ivas->ism_mode;
     547      103826 :     move16();
     548             : 
     549             :     /* select ISM format mode */
     550      103826 :     st_ivas->ism_mode = ivas_ism_mode_select( st_ivas->hEncoderConfig->nchan_inp, st_ivas->hEncoderConfig->ivas_total_brate ); /* Q0 */
     551      103826 :     move16();
     552             : 
     553             :     /* ISM bit-rate switching */
     554      103826 :     test();
     555      103826 :     IF( NE_16( st_ivas->ism_mode, last_ism_mode ) || NE_32( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->hEncoderConfig->last_ivas_total_brate ) )
     556             :     {
     557             :         Word32 element_brate_tmp[MAX_NUM_OBJECTS];
     558             : 
     559         947 :         nchan_transport_old = st_ivas->nchan_transport; /* Q0 */
     560         947 :         move16();
     561             : 
     562             :         /* Reset and Initialize */
     563         947 :         IF( EQ_16( st_ivas->ism_mode, ISM_MODE_PARAM ) )
     564             :         {
     565         312 :             st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE;
     566             :         }
     567             :         ELSE
     568             :         {
     569         635 :             st_ivas->nchan_transport = st_ivas->hEncoderConfig->nchan_inp; /* Q0 */
     570             :         }
     571         947 :         move16();
     572             : 
     573         947 :         nCPE_old = st_ivas->nCPE; /* Q0 */
     574         947 :         move16();
     575         947 :         nSCE_old = st_ivas->nSCE; /* Q0 */
     576         947 :         move16();
     577         947 :         st_ivas->nSCE = st_ivas->nchan_transport; /* Q0 */
     578         947 :         move16();
     579         947 :         st_ivas->nCPE = 0;
     580         947 :         move16();
     581             : 
     582         947 :         IF( ( error = ivas_ism_config_fx( 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 )
     583             :         {
     584           0 :             return error;
     585             :         }
     586             : 
     587         947 :         IF( ( error = ivas_corecoder_enc_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport, imult3216( ( st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport ), CPE_CHANNELS ), MC_MODE_NONE ) ) != IVAS_ERR_OK )
     588             :         {
     589           0 :             return error;
     590             :         }
     591             : 
     592         947 :         test();
     593         947 :         IF( EQ_16( st_ivas->ism_mode, ISM_MODE_PARAM ) && EQ_16( last_ism_mode, ISM_MODE_DISC ) )
     594             :         {
     595             :             /* Allocate and Initialize the memory used by ParamISM when switch from Discrete ISM */
     596         303 :             IF( ( error = ivas_param_ism_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK )
     597             :             {
     598           0 :                 return error;
     599             :             }
     600             :         }
     601             : 
     602         947 :         test();
     603         947 :         IF( EQ_16( st_ivas->ism_mode, ISM_MODE_DISC ) && EQ_16( last_ism_mode, ISM_MODE_PARAM ) )
     604             :         {
     605             :             /* Deallocate the memory used by ParamISM when switch to Discrete ISM */
     606         306 :             ivas_param_ism_enc_close_fx( &( st_ivas->hParamIsm ), st_ivas->hEncoderConfig->input_Fs );
     607             :         }
     608             :     }
     609             : 
     610      103826 :     return error;
     611             : }

Generated by: LCOV version 1.14