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 @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 212 222 95.5 %
Date: 2025-05-03 01:55:50 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 :         Copy_Scale_sig32( data[sce_id], st->input32_fx, input_frame, sub( Q_min, q_data ) ); // Q(Q_min)
     171      279450 :         st->q_inp32 = Q_min;
     172      279450 :         move16();
     173      279450 :         q_st_inp_16 = sub( getScaleFactor32( st->input32_fx, input_frame ), 16 );
     174      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)
     175      279450 :         st->q_inp = add( q_st_inp_16, Q_min );
     176      279450 :         move16();
     177             : 
     178      279450 :         st->element_mode = IVAS_SCE;
     179      279450 :         move16();
     180             : 
     181     4750650 :         FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
     182             :         {
     183     4471200 :             set_zero_fx( realBuffer_fx[sce_id][0][i], CLDFB_NO_CHANNELS_MAX );
     184     4471200 :             set_zero_fx( imagBuffer_fx[sce_id][0][i], CLDFB_NO_CHANNELS_MAX );
     185             :         }
     186             :         /*------------------------------------------------------------------*
     187             :          * SCE initialization - core coder
     188             :          *-----------------------------------------------------------------*/
     189             : 
     190      279450 :         st->idchan = 0;
     191      279450 :         st->core = -1;
     192      279450 :         st->core_brate = -1; /* updated in dtx() */
     193      279450 :         st->max_bwidth = st_ivas->hEncoderConfig->max_bwidth;
     194      279450 :         st->input_bwidth = st->last_input_bwidth; /* updated in BWD */
     195      279450 :         st->bwidth = st->last_bwidth;             /* updated in BWD */
     196      279450 :         st->rate_switching_reset = 0;
     197             : #ifdef DEBUGGING
     198             :         st->force = st_ivas->hEncoderConfig->force;
     199             :         st->id_element = sce_id;
     200             : #ifdef DEBUG_FORCE_DIR
     201             :         st->force_dir = st_ivas->hEncoderConfig->force_dir;
     202             : #endif
     203             : #endif
     204      279450 :         move16();
     205      279450 :         move16();
     206      279450 :         move16();
     207      279450 :         move16();
     208      279450 :         move16();
     209      279450 :         move16();
     210      279450 :         move16();
     211             : 
     212             :         /*---------------------------------------------------------------*
     213             :          * Time Domain Transient Detector
     214             :          *---------------------------------------------------------------*/
     215             : 
     216      279450 :         RunTransientDetection_ivas_fx( st->input_fx, input_frame, st->hTranDet, st->q_inp );
     217             : 
     218      279450 :         currFlatness_fx[0] = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS, 0 ); // Q21
     219      279450 :         move16();
     220             : 
     221             :         /*----------------------------------------------------------------*
     222             :          * Configuration of core encoder
     223             :          *----------------------------------------------------------------*/
     224             : 
     225             :         /* Force to MODE1 in IVAS */
     226      279450 :         st->codec_mode = MODE1;
     227      279450 :         move16();
     228             : 
     229      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 );
     230      279450 :         move16();
     231             : 
     232             : #ifdef DEBUG_MODE_INFO
     233             :         dbgwrite( &st->element_mode, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "element_mode", 0, st->id_element, ENC ) );
     234             : #endif
     235             : 
     236             :         /*----------------------------------------------------------------*
     237             :          * Front Pre-processing
     238             :          *----------------------------------------------------------------*/
     239     1485396 :         FOR( i = 0; i < hSCE->hCoreCoder[0]->nb_subfr; i++ )
     240             :         {
     241     1205946 :             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
     242             :         }
     243             : 
     244      279450 :         set16_fx( old_wsp_fx[sce_id][0], 0, L_WSP );
     245      279450 :         q_old_wsp = Q15;
     246      279450 :         move16();
     247             : 
     248             :         Word16 q_fr_bands[2];
     249      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],
     250      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],
     251      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],
     252      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]
     253             : #ifdef DEBUG_MODE_INFO
     254             :                                         ,
     255             :                                         st->id_element
     256             : #endif
     257             :         );
     258      279450 :         e_old_wsp[sce_id][0] = sub( Q15, q_old_wsp );
     259      279450 :         move16();
     260      279450 :         IF( error != IVAS_ERR_OK )
     261             :         {
     262           0 :             return error;
     263             :         }
     264             : 
     265      279450 :         IF( st_ivas->hEncoderConfig->Opt_DTX_ON )
     266             :         {
     267       38116 :             vad_flag[sce_id] = vad_flag_dtx[sce_id][0];
     268       38116 :             move16();
     269             :         }
     270             :         ELSE
     271             :         {
     272      241334 :             vad_flag[sce_id] = st->vad_flag; /* Q0 */
     273      241334 :             move16();
     274             :         }
     275             :     }
     276             : 
     277             :     /*------------------------------------------------------------------*
     278             :      * DTX analysis
     279             :      *-----------------------------------------------------------------*/
     280             : 
     281             :     /* compute the dominant sce_id using long term energy */
     282             : 
     283      109022 :     IF( st_ivas->hEncoderConfig->Opt_DTX_ON )
     284             :     {
     285       14826 :         ivas_ism_get_sce_id_dtx_fx( st_ivas->hISMDTX, st_ivas->hSCE, st_ivas->nchan_transport, input_frame );
     286             : 
     287       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 */
     288             : 
     289       14826 :         IF( sid_flag )
     290             :         {
     291             :             /* estimate coherence between objects */
     292         535 :             ivas_ism_coh_estim_dtx_enc_fx( st_ivas->hISMDTX, st_ivas->hSCE, st_ivas->nchan_transport, input_frame );
     293             :         }
     294             :     }
     295             : 
     296             :     /*------------------------------------------------------------------*
     297             :      * Analysis of objects, configuration and decision about bitrates per channel
     298             :      * Metadata quantization and encoding
     299             :      *-----------------------------------------------------------------*/
     300             : 
     301      109022 :     IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) )
     302             :     {
     303       20720 :         ivas_param_ism_compute_noisy_speech_flag_fx( st_ivas );
     304       20720 :         flag_noisy_speech = st_ivas->hParamIsm->flag_noisy_speech; // Q0
     305       20720 :         move16();
     306             :     }
     307             : 
     308      109022 :     IF( dtx_flag )
     309             :     {
     310        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 );
     311             :     }
     312      106907 :     ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) )
     313             :     {
     314       20414 :         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 )
     315             :         {
     316           0 :             return error;
     317             :         }
     318             :     }
     319             :     ELSE /* ISM_MODE_DISC */
     320             :     {
     321       86493 :         test();
     322       86493 :         IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) )
     323             :         {
     324        5196 :             ism_total_brate = 0;
     325        5196 :             move16();
     326       15710 :             FOR( i = 0; i < st_ivas->nSCE; i++ )
     327             :             {
     328       10514 :                 ism_total_brate = L_add( ism_total_brate, st_ivas->hSCE[i]->element_brate ); /* Q0 */
     329             :             }
     330             :         }
     331             :         ELSE
     332             :         {
     333       81297 :             ism_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; /* Q0 */
     334       81297 :             move32();
     335             :         }
     336             : 
     337       86493 :         ism_total_brate_ref = ism_total_brate; /* Q0 */
     338       86493 :         move32();
     339             : 
     340             :         Word16 lp_noise_CPE_fx;
     341       86493 :         if ( st_ivas->hMasa != NULL )
     342             :         {
     343        5196 :             lp_noise_CPE_fx = st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx;
     344        5196 :             move16();
     345             :         }
     346             :         else
     347             :         {
     348       81297 :             lp_noise_CPE_fx = 0;
     349       81297 :             move16();
     350             :         }
     351             : 
     352             :         Word16 *omasa_stereo_sw_cnt;
     353       86493 :         if ( st_ivas->hMasa != NULL )
     354             :         {
     355        5196 :             omasa_stereo_sw_cnt = &( st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt );
     356             :         }
     357             :         else
     358             :         {
     359       81297 :             omasa_stereo_sw_cnt = NULL;
     360             :         }
     361       86493 :         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,
     362             :                                                 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 ) ) !=
     363             :             IVAS_ERR_OK )
     364             :         {
     365           0 :             return error;
     366             :         }
     367             : 
     368       86493 :         IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) )
     369             :         {
     370        5196 :             st_ivas->hCPE[0]->brate_surplus = L_sub( ism_total_brate_ref, ism_total_brate ); /* Q0 */
     371        5196 :             move32();
     372             :         }
     373             :     }
     374      109022 :     update_last_metadata_fx( nchan_ism, st_ivas->hIsmMetaData, md_diff_flag );
     375             : 
     376             :     /*----------------------------------------------------------------*
     377             :      * Write IVAS format signaling in SID frames
     378             :      *----------------------------------------------------------------*/
     379             : 
     380      109022 :     st = st_ivas->hSCE[0]->hCoreCoder[0];
     381             : 
     382      109022 :     IF( sid_flag )
     383             :     {
     384         535 :         ivas_write_format_sid_fx( st_ivas->hEncoderConfig->ivas_format, IVAS_SCE, st->hBstr );
     385             :     }
     386             : 
     387             :     /*only metadata encoding is needed for this case*/
     388      109022 :     IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) )
     389             :     {
     390           0 :         assert( st_ivas->ism_mode != ISM_MODE_NONE );
     391           0 :         return error;
     392             :     }
     393             : 
     394             :     /*------------------------------------------------------------------*
     395             :      * CoreCoders encoding
     396             :      *-----------------------------------------------------------------*/
     397             : 
     398      388472 :     FOR( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ )
     399             :     {
     400      279450 :         hSCE = st_ivas->hSCE[sce_id];
     401      279450 :         st = hSCE->hCoreCoder[0];
     402             : 
     403             :         /* update pointer to the buffer of indices of the next channel */
     404      279450 :         IF( sce_id > 0 )
     405             :         {
     406      170428 :             st->hBstr->ind_list = prev_st->hBstr->ind_list + prev_st->hBstr->nb_ind_tot;
     407             :         }
     408             : 
     409      279450 :         if ( st->low_rate_mode )
     410             :         {
     411        7518 :             st->bwidth = WB;
     412        7518 :             move16();
     413             :         }
     414             : 
     415             :         /*----------------------------------------------------------------*
     416             :          * Core codec configuration
     417             :          *----------------------------------------------------------------*/
     418             : 
     419             :         /* IGF reconfiguration */
     420      279450 :         test();
     421      279450 :         IF( NE_32( hSCE->last_element_brate, hSCE->element_brate ) || NE_32( st->last_bwidth, st->bwidth ) )
     422             :         {
     423             :             Word16 igf;
     424        3913 :             igf = getIgfPresent_fx( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->max_bwidth, st->rf_mode );
     425        3913 :             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 )
     426             :             {
     427           0 :                 return error;
     428             :             }
     429             :         }
     430             : 
     431             :         /* set ACELP@12k8 / ACELP@16k flag for flexible ACELP core */
     432      279450 :         test();
     433      279450 :         IF( EQ_32( st->core_brate, SID_2k40 ) || st->core_brate == FRAME_NO_DATA )
     434             :         {
     435        5206 :             st->flag_ACELP16k = set_ACELP_flag_IVAS( IVAS_SCE, hSCE->element_brate, st->core_brate, 0, 0, -1, -1 );
     436        5206 :             move16();
     437             :         }
     438      274244 :         ELSE IF( st->low_rate_mode )
     439             :         {
     440        7518 :             st->flag_ACELP16k = 0;
     441        7518 :             move16();
     442             :         }
     443             :         ELSE
     444             :         {
     445      266726 :             st->flag_ACELP16k = set_ACELP_flag_IVAS( IVAS_SCE, hSCE->element_brate, st->total_brate, 0, 0, -1, -1 ); /* Q0 */
     446      266726 :             move16();
     447             :         }
     448             : 
     449             :         /* modify the coder_type depending on the total_brate per channel */
     450      279450 :         coder_type_modif_ivas_fx( st, relE_fx[sce_id][0] );
     451             : 
     452             :         /*----------------------------------------------------------------*
     453             :          * Encoder
     454             :          *----------------------------------------------------------------*/
     455      279450 :         test();
     456      279450 :         test();
     457      279450 :         IF( !dtx_flag || ( dtx_flag && EQ_16( sce_id, st_ivas->hISMDTX->sce_id_dtx ) ) )
     458             :         {
     459      276359 :             Scale_sig( old_wsp_fx[sce_id][0], L_WSP, sub( e_old_wsp[sce_id][0], Q16 ) ); /* exp(16) */
     460      276359 :             e_old_wsp[sce_id][0] = 16;
     461      276359 :             move16();
     462      276359 :             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 ) )
     463             :             {
     464           0 :                 return error;
     465             :             }
     466             :         }
     467             : 
     468             :         /*----------------------------------------------------------------*
     469             :          * Common updates
     470             :          *----------------------------------------------------------------*/
     471             : 
     472             :         /* update input samples buffer */
     473             : 
     474      279450 :         Copy( st->input_fx, st->old_input_signal_fx, input_frame ); /* st->q_inp */
     475      279450 :         st->q_old_inp = st->q_inp;
     476      279450 :         move16();
     477      279450 :         Copy32( st->input32_fx, st->input32_fx - input_frame, input_frame ); /* st->q_inp32 */
     478             : 
     479      279450 :         hSCE->last_element_brate = hSCE->element_brate; /* Q0 */
     480      279450 :         move32();
     481             : 
     482             :         /* Store previous attack detection flag */
     483      279450 :         st->hTranDet->transientDetector.prev_bIsAttackPresent = st->hTranDet->transientDetector.bIsAttackPresent; /* Q0 */
     484      279450 :         move16();
     485             : 
     486      279450 :         prev_st = st;
     487             :     }
     488             : 
     489      109022 :     IF( dtx_flag )
     490             :     {
     491        7321 :         FOR( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ )
     492             :         {
     493        5206 :             IF( NE_16( sce_id, st_ivas->hISMDTX->sce_id_dtx ) )
     494             :             {
     495        3091 :                 st_ivas->hSCE[sce_id]->hCoreCoder[0]->last_core = st_ivas->hSCE[st_ivas->hISMDTX->sce_id_dtx]->hCoreCoder[0]->last_core;        /* Q0 */
     496        3091 :                 st_ivas->hSCE[sce_id]->hCoreCoder[0]->last_core_brate = st_ivas->hSCE[st_ivas->hISMDTX->sce_id_dtx]->hCoreCoder[0]->core_brate; /* Q0 */
     497        3091 :                 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 */
     498        3091 :                 move16();
     499        3091 :                 move32();
     500        3091 :                 move16();
     501             :             }
     502             :         }
     503             :     }
     504             : 
     505             : #ifdef DEBUG_MODE_INFO
     506             :     for ( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ )
     507             :     {
     508             :         float tmpF;
     509             :         int16_t id;
     510             : 
     511             :         st = st_ivas->hSCE[sce_id]->hCoreCoder[0];
     512             :         id = st->id_element;
     513             : 
     514             :         tmpF = st->element_brate / 1000.0f;
     515             :         dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "element_brate", 0, id, ENC ) );
     516             :     }
     517             : #endif
     518             : 
     519      109022 :     pop_wmops();
     520             : 
     521      109022 :     return error;
     522             : }
     523             : 
     524             : /*-------------------------------------------------------------------------
     525             :  * ivas_ism_enc_config()
     526             :  *
     527             :  * - select ISM format mode
     528             :  * - reconfigure the ISM format encoder
     529             :  *-------------------------------------------------------------------------*/
     530             : 
     531      103826 : ivas_error ivas_ism_enc_config(
     532             :     Encoder_Struct *st_ivas /* i/o: IVAS encoder structure      */
     533             : )
     534             : {
     535             :     ivas_error error;
     536             :     ISM_MODE last_ism_mode;
     537             :     Word16 nchan_transport_old;
     538             :     Word16 nSCE_old, nCPE_old;
     539             : 
     540      103826 :     error = IVAS_ERR_OK;
     541      103826 :     move32();
     542      103826 :     last_ism_mode = st_ivas->ism_mode;
     543      103826 :     move16();
     544             : 
     545             :     /* select ISM format mode */
     546      103826 :     st_ivas->ism_mode = ivas_ism_mode_select( st_ivas->hEncoderConfig->nchan_inp, st_ivas->hEncoderConfig->ivas_total_brate ); /* Q0 */
     547      103826 :     move16();
     548             : 
     549             :     /* ISM bit-rate switching */
     550      103826 :     test();
     551      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 ) )
     552             :     {
     553             :         Word32 element_brate_tmp[MAX_NUM_OBJECTS];
     554             : 
     555         947 :         nchan_transport_old = st_ivas->nchan_transport; /* Q0 */
     556         947 :         move16();
     557             : 
     558             :         /* Reset and Initialize */
     559         947 :         IF( EQ_16( st_ivas->ism_mode, ISM_MODE_PARAM ) )
     560             :         {
     561         312 :             st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE;
     562             :         }
     563             :         ELSE
     564             :         {
     565         635 :             st_ivas->nchan_transport = st_ivas->hEncoderConfig->nchan_inp; /* Q0 */
     566             :         }
     567         947 :         move16();
     568             : 
     569         947 :         nCPE_old = st_ivas->nCPE; /* Q0 */
     570         947 :         move16();
     571         947 :         nSCE_old = st_ivas->nSCE; /* Q0 */
     572         947 :         move16();
     573         947 :         st_ivas->nSCE = st_ivas->nchan_transport; /* Q0 */
     574         947 :         move16();
     575         947 :         st_ivas->nCPE = 0;
     576         947 :         move16();
     577             : 
     578         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 )
     579             :         {
     580           0 :             return error;
     581             :         }
     582             : 
     583         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 )
     584             :         {
     585           0 :             return error;
     586             :         }
     587             : 
     588         947 :         test();
     589         947 :         IF( EQ_16( st_ivas->ism_mode, ISM_MODE_PARAM ) && EQ_16( last_ism_mode, ISM_MODE_DISC ) )
     590             :         {
     591             :             /* Allocate and Initialize the memory used by ParamISM when switch from Discrete ISM */
     592         303 :             IF( ( error = ivas_param_ism_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK )
     593             :             {
     594           0 :                 return error;
     595             :             }
     596             :         }
     597             : 
     598         947 :         test();
     599         947 :         IF( EQ_16( st_ivas->ism_mode, ISM_MODE_DISC ) && EQ_16( last_ism_mode, ISM_MODE_PARAM ) )
     600             :         {
     601             :             /* Deallocate the memory used by ParamISM when switch to Discrete ISM */
     602         306 :             ivas_param_ism_enc_close_fx( &( st_ivas->hParamIsm ), st_ivas->hEncoderConfig->input_Fs );
     603             :         }
     604             :     }
     605             : 
     606      103826 :     return error;
     607             : }

Generated by: LCOV version 1.14