LCOV - code coverage report
Current view: top level - lib_enc - ivas_sce_enc_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 574a190e3c6896c6c4ed10d7f23649709a0c4347 Lines: 253 272 93.0 %
Date: 2025-06-27 02:59:36 Functions: 4 4 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 <string.h>
      35             : #include "options.h"
      36             : #include "cnst.h"
      37             : #include "ivas_cnst.h"
      38             : #include "rom_com.h"
      39             : #include "prot_fx.h"
      40             : #include "prot_fx_enc.h"
      41             : #include "ivas_rom_com.h"
      42             : #ifdef DEBUGGING
      43             : #include "debug.h"
      44             : #endif
      45             : #include "wmc_auto.h"
      46             : #include "ivas_prot_fx.h"
      47             : #include "prot_fx_enc.h"
      48             : 
      49             : 
      50             : /*-------------------------------------------------------------------*
      51             :  * ivas_sce_enc()
      52             :  *
      53             :  * Single Channel Element (SCE) encoding routine
      54             :  *-------------------------------------------------------------------*/
      55             : Indice ind_list[MAX_NUM_INDICES];
      56             : 
      57       70893 : ivas_error ivas_sce_enc_fx(
      58             :     Encoder_Struct *st_ivas,      /* i/o: IVAS encoder structure                       */
      59             :     const Word16 sce_id,          /* i  : SCE # identifier                             */
      60             :     const Word32 data_fx[],       /* i  : input signal for single channel Q(q_data_fx) */
      61             :     const Word16 q_data_fx,       /* i  : Q-factor of input signal for single channel  */
      62             :     const Word16 input_frame,     /* i  : input frame length per channel               */
      63             :     const Word16 nb_bits_metadata /* i  : number of metadata bits                      */
      64             : )
      65             : {
      66             :     Word16 old_wsp_fx[1][L_WSP];
      67             :     Word16 e_old_wsp[1];
      68             :     Word16 q_old_wsp;
      69             :     Word32 ener_fx[1];                              /* residual energy from Levinson-Durbin  Q6 */
      70             :     Word32 enerBuffer_fx[1][CLDFB_NO_CHANNELS_MAX]; /* energy buffer                            */
      71             :     Word16 enerBuffer_fx_exp[1];                    /* energy buffer                            */
      72             :     Word32 epsP_fx[1][M + 1];                       /* LP prediction errors                     */
      73             :     Word16 epsP_fx_q[1];
      74             :     Word16 A_fx[1][NB_SUBFR16k * ( M + 1 )];                          /* A(z) unquantized for subframes           */
      75             :     Word16 Aw_fx[1][NB_SUBFR16k * ( M + 1 )];                         /* weighted A(z) unquantized for subframes  */
      76             :     Word16 lsp_new_fx[1][M];                                          /* LSPs at the end of the frame            Q15 */
      77             :     Word16 lsp_mid_fx[1][M];                                          /* ISPs in the middle of the frame         Q15 */
      78             :     Word16 pitch_fr_fx[1][NB_SUBFR];                                  /* fractional pitch values                  */
      79             :     Word16 voicing_fr_fx[1][NB_SUBFR];                                /* fractional pitch gains                   */
      80             :     Word16 relE_fx[1];                                                /* frame relative energy               Q8   */
      81             :     Word32 currFlatness_fx[1];                                        /* flatness parameter                  Q7   */
      82             :     Word16 Etot_LR_fx[1];                                             /* total energy                            Q8   */
      83             :     Word32 realBuffer_fx[1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer                              */
      84             :     Word32 imagBuffer_fx[1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer                              */
      85       70893 :     Word16 q_re_im_buf = Q31;
      86       70893 :     move16();
      87             :     Word16 cor_map_sum_fx[1];            /* speech/music clasif. parameter          Q8 */
      88             :     Word32 fr_bands_fx[1][2 * NB_BANDS]; /* energy in frequency bands                */
      89             :     Word32 lf_E_fx[1][2 * VOIC_BINS];    /* per bin spectrum energy in lf            */
      90             : 
      91             :     Word16 old_inp_12k8_fx[1][L_INP_12k8]; /* buffer of input signal @ 12k8    Q_new-1 */
      92             :     Word16 old_inp_16k_fx[1][L_INP];       /* buffer of input signal @ 12k8    Q_new-1 */
      93       70893 :     Word16 Q_new[1] = { 0 };
      94             :     Word16 vad_hover_flag[1];         /* VAD hangover flag                        */
      95             :     Word16 attack_flag[1];            /* attack flag (GSC or TC)                  */
      96             :     Word16 loc_harm[1];               /* harmonicity flag                         */
      97             :     Word16 vad_flag_dtx[1];           /* HE-SAD flag with additional DTX HO       */
      98             :     Word16 fft_buff_fx[1][2 * L_FFT]; /* FFT buffer                               */
      99             :     Word16 fft_buff_fx_q[1];          /* FFT buffer                               */
     100             :     Word16 localVAD_HE_SAD[1];        /* local HE SAD */
     101             :     SCE_ENC_HANDLE hSCE;
     102             :     Encoder_State *st;
     103             :     IVAS_FORMAT ivas_format;
     104             :     ivas_error error;
     105             :     Word16 flag_16k_smc;
     106             :     Word16 q_input; /*stores q for input_fx*/
     107       70893 :     move16();       // Q_new
     108             : 
     109       70893 :     push_wmops( "ivas_sce_enc" );
     110             : 
     111       70893 :     error = IVAS_ERR_OK;
     112       70893 :     move32();
     113             : 
     114       70893 :     hSCE = st_ivas->hSCE[sce_id];
     115       70893 :     st = hSCE->hCoreCoder[0];
     116       70893 :     ivas_format = st_ivas->hEncoderConfig->ivas_format;
     117       70893 :     move32();
     118             : 
     119             :     /*------------------------------------------------------------------*
     120             :      * Initialization - general
     121             :      *-----------------------------------------------------------------*/
     122             : 
     123       70893 :     set16_zero_fx( old_inp_12k8_fx[0], L_INP_12k8 );
     124             : 
     125       70893 :     Word16 Q_min = s_min( q_data_fx, add( st->q_inp32, L_norm_arr( st->input32_fx - input_frame, input_frame ) ) );
     126       70893 :     scale_sig32( st->input32_fx - input_frame, input_frame, sub( Q_min, st->q_inp32 ) );
     127       70893 :     st->q_old_inp32 = Q_min;
     128       70893 :     move16();
     129       70893 :     Copy_Scale_sig32( data_fx, st->input32_fx, input_frame, sub( Q_min, q_data_fx ) ); // Q(Q_min)
     130       70893 :     st->q_inp32 = Q_min;
     131       70893 :     move16();
     132       70893 :     q_input = sub( add( L_norm_arr( st->input32_fx, input_frame ), Q_min ), 16 );
     133             : 
     134       70893 :     Copy_Scale_sig32_16( st->input32_fx, st->input_fx, input_frame, sub( add( Q16, q_input ), Q_min ) ); // Q(Q_min) -> Q(q_input)
     135       70893 :     st->q_inp = q_input;
     136       70893 :     move16();
     137             : 
     138       70893 :     st->element_mode = IVAS_SCE;
     139       70893 :     move16();
     140             : 
     141       70893 :     set16_fx( A_fx[0], 0, NB_SUBFR16k * ( M + 1 ) );
     142       70893 :     set16_fx( Aw_fx[0], 0, NB_SUBFR16k * ( M + 1 ) );
     143             : 
     144     1205181 :     FOR( Word16 i = 0; i < CLDFB_NO_COL_MAX; i++ )
     145             :     {
     146     1134288 :         set_zero_fx( realBuffer_fx[0][i], CLDFB_NO_CHANNELS_MAX );
     147     1134288 :         set_zero_fx( imagBuffer_fx[0][i], CLDFB_NO_CHANNELS_MAX );
     148             :     }
     149             : 
     150       70893 :     set16_zero_fx( old_inp_16k_fx[0], L_INP );
     151             : 
     152             :     /*------------------------------------------------------------------*
     153             :      * SCE initialization - core coder
     154             :      *-----------------------------------------------------------------*/
     155             : 
     156       70893 :     st->idchan = 0;
     157       70893 :     st->core = -1;
     158       70893 :     st->core_brate = -1; /* updated in dtx() */
     159       70893 :     st->max_bwidth = st_ivas->hEncoderConfig->max_bwidth;
     160       70893 :     st->input_bwidth = st->last_input_bwidth; /* updated in BWD */
     161       70893 :     st->bwidth = st->last_bwidth;             /* updated in BWD */
     162       70893 :     st->rate_switching_reset = 0;
     163             : #ifdef DEBUGGING
     164             :     st->force = st_ivas->hEncoderConfig->force;
     165             :     st->id_element = sce_id;
     166             : #ifdef DEBUG_FORCE_DIR
     167             :     st->force_dir = st_ivas->hEncoderConfig->force_dir;
     168             : #endif
     169             : #endif
     170       70893 :     move16();
     171       70893 :     move16();
     172       70893 :     move32();
     173       70893 :     move16();
     174       70893 :     move16();
     175       70893 :     move16();
     176       70893 :     move16();
     177             : 
     178             :     /*---------------------------------------------------------------*
     179             :      * Time Domain Transient Detector
     180             :      *---------------------------------------------------------------*/
     181       70893 :     test();
     182       70893 :     IF( NE_32( ivas_format, MC_FORMAT ) || NE_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) )
     183             :     {
     184       70893 :         RunTransientDetection_ivas_fx( st->input_fx, input_frame, st->hTranDet, q_input );
     185             :     }
     186             : 
     187       70893 :     currFlatness_fx[0] = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS, 0 ); // Q21
     188       70893 :     move32();
     189             : 
     190             :     /*----------------------------------------------------------------*
     191             :      * Configuration of core encoder
     192             :      *----------------------------------------------------------------*/
     193             : 
     194             :     /* Force to MODE1 in IVAS */
     195       70893 :     st->codec_mode = MODE1;
     196       70893 :     move16();
     197             : 
     198             :     /* set "bits_frame_nominal" */
     199       70893 :     test();
     200       70893 :     IF( st_ivas->hQMetaData != NULL && st_ivas->hSpar == NULL )
     201             :     {
     202       27002 :         test();
     203       27002 :         test();
     204       27002 :         IF( ( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) && GE_32( st_ivas->hEncoderConfig->ivas_total_brate, MCMASA_SEPARATE_BRATE ) ) || GE_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) )
     205             :         {
     206        2487 :             st->bits_frame_nominal = extract_l( Mpy_32_32( hSCE->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) );
     207        2487 :             move16();
     208             :         }
     209             :         ELSE
     210             :         {
     211       24515 :             st->bits_frame_nominal = st_ivas->hQMetaData->bits_frame_nominal;
     212       24515 :             move16();
     213             :         }
     214             :     }
     215       43891 :     ELSE IF( st_ivas->hSpar != NULL )
     216             :     {
     217       43891 :         st->bits_frame_nominal = extract_l( Mpy_32_32( st_ivas->hSpar->core_nominal_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) );
     218       43891 :         move16();
     219             :     }
     220             :     ELSE
     221             :     {
     222           0 :         st->bits_frame_nominal = sub( extract_l( Mpy_32_32( hSCE->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ), ISM_NB_BITS_METADATA_NOMINAL );
     223           0 :         move16();
     224             :     }
     225             : 
     226             :     /* set "total_brate" */
     227       70893 :     st->total_brate = L_sub( hSCE->element_brate, L_mult0( nb_bits_metadata, FRAMES_PER_SEC ) );
     228       70893 :     move32();
     229             : 
     230             :     /* set flag for sampling rate of OL S/M classifier */
     231       70893 :     flag_16k_smc = 0;
     232       70893 :     move16();
     233       70893 :     test();
     234       70893 :     test();
     235       70893 :     test();
     236       70893 :     if ( EQ_32( st_ivas->hEncoderConfig->ivas_format, SBA_FORMAT ) && ( EQ_32( st_ivas->hEncoderConfig->ivas_total_brate, IVAS_24k4 ) || EQ_32( st_ivas->hEncoderConfig->ivas_total_brate, IVAS_32k ) ) && EQ_32( hSCE->element_brate, hSCE->last_element_brate ) )
     237             :     {
     238       26562 :         flag_16k_smc = 1;
     239       26562 :         move16();
     240             :     }
     241             : 
     242             : #ifdef DEBUG_MODE_INFO
     243             :     dbgwrite( st->input_fx - NS2SA( st->input_Fs, ACELP_LOOK_NS ), sizeof( Word16 ), input_frame, 1, "res/input_DMX" );
     244             :     dbgwrite( &st->element_mode, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "element_mode", 0, st->id_element, ENC ) );
     245             : #endif
     246             : 
     247             : 
     248             :     /*----------------------------------------------------------------*
     249             :      * Front Pre-processing
     250             :      *----------------------------------------------------------------*/
     251       70893 :     set16_fx( old_wsp_fx[0], 0, L_WSP );
     252       70893 :     q_old_wsp = Q15;
     253       70893 :     move16();
     254             : 
     255             :     Word16 q_fr_bands[2];
     256      124897 :     error = pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata, input_frame, 0, old_inp_12k8_fx[0], old_inp_16k_fx[0],
     257             :                                     &ener_fx[0], &relE_fx[0], A_fx[0], Aw_fx[0], epsP_fx[0], &epsP_fx_q[0], lsp_new_fx[0], lsp_mid_fx[0], &vad_hover_flag[0], &attack_flag[0],
     258             :                                     realBuffer_fx[0], imagBuffer_fx[0], &q_re_im_buf, old_wsp_fx[0], &q_old_wsp, pitch_fr_fx[0], voicing_fr_fx[0], &loc_harm[0], &cor_map_sum_fx[0], &vad_flag_dtx[0], enerBuffer_fx[0], &enerBuffer_fx_exp[0],
     259             :                                     fft_buff_fx[0], &fft_buff_fx_q[0], A_fx[0], lsp_new_fx[0], currFlatness_fx[0], 0, fr_bands_fx, q_fr_bands, Etot_LR_fx, lf_E_fx, 31, localVAD_HE_SAD, NULL, 31, flag_16k_smc,
     260      124897 :                                     st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->force_front_vad : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_dtx_flag : 0, ivas_format, 0, st_ivas->hEncoderConfig->last_ivas_total_brate, st_ivas->hEncoderConfig->ivas_total_brate, &Q_new[0]
     261             : #ifdef DEBUG_MODE_INFO
     262             :                                     ,
     263             :                                     st->id_element
     264             : #endif
     265             :     );
     266       70893 :     e_old_wsp[0] = sub( Q15, q_old_wsp );
     267       70893 :     move16();
     268       70893 :     IF( NE_32( error, IVAS_ERR_OK ) )
     269             :     {
     270           0 :         return error;
     271             :     }
     272             : 
     273             :     /* sanity check -> DTX not supported for more than one SCEs/CPEs */
     274       70893 :     IF( sub( add( st_ivas->nSCE, st_ivas->nCPE ), 1 ) > 0 )
     275             :     {
     276        2487 :         test();
     277        2487 :         IF( EQ_32( st->core_brate, SID_2k40 ) || st->core_brate == FRAME_NO_DATA )
     278             :         {
     279           0 :             st->core_brate = -1;
     280           0 :             st->total_brate = L_sub( hSCE->element_brate, L_mult0( nb_bits_metadata, FRAMES_PER_SEC ) );
     281           0 :             move32();
     282           0 :             move32();
     283             :         }
     284             :     }
     285             : 
     286             :     /*----------------------------------------------------------------*
     287             :      * Reset metadata
     288             :      *----------------------------------------------------------------*/
     289             : 
     290       70893 :     reset_metadata_spatial_fx( ivas_format, hSCE->hMetaData, hSCE->element_brate, &st->total_brate, st->core_brate, nb_bits_metadata );
     291             : 
     292             :     /*----------------------------------------------------------------*
     293             :      * Combined format coding: get the ISM importance and the bit-rate
     294             :      *----------------------------------------------------------------*/
     295       70893 :     test();
     296       70893 :     IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) )
     297             :     {
     298        1862 :         st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx = 0;
     299        1862 :         move16();
     300        1862 :         ivas_set_ism_importance_interformat_fx( hSCE->element_brate, 1, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx, &st_ivas->hIsmMetaData[0]->ism_imp );
     301             : 
     302        1862 :         st->total_brate = L_sub( ivas_interformat_brate_fx( ISM_MASA_MODE_PARAM_ONE_OBJ, 1, hSCE->element_brate, st_ivas->hIsmMetaData[0]->ism_imp, 0 ), L_mult0( nb_bits_metadata, FRAMES_PER_SEC ) );
     303        1862 :         move32();
     304             :     }
     305             : 
     306             :     /*----------------------------------------------------------------*
     307             :      * Write IVAS format signaling in SID frames
     308             :      *----------------------------------------------------------------*/
     309             : 
     310       70893 :     IF( EQ_32( st->core_brate, SID_2k40 ) )
     311             :     {
     312         227 :         ivas_write_format_sid_fx( ivas_format, IVAS_SCE, st->hBstr );
     313             :     }
     314             : 
     315             :     /*----------------------------------------------------------------*
     316             :      * Core codec configuration
     317             :      *----------------------------------------------------------------*/
     318             : 
     319             :     /* IGF reconfiguration */
     320       70893 :     test();
     321       70893 :     IF( NE_32( hSCE->last_element_brate, hSCE->element_brate ) || NE_16( st->last_bwidth, st->bwidth ) )
     322             :     {
     323             :         Word16 igf;
     324        1210 :         igf = getIgfPresent_fx( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->max_bwidth, st->rf_mode );
     325        1210 :         IF( NE_32( ( 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 ) )
     326             :         {
     327           0 :             return error;
     328             :         }
     329             :     }
     330             : 
     331             :     /* set ACELP@12k8 / ACELP@16k flag for flexible ACELP core */
     332       70893 :     test();
     333       70893 :     test();
     334       70893 :     IF( EQ_32( st->core_brate, SID_2k40 ) || st->core_brate == FRAME_NO_DATA )
     335             :     {
     336        1633 :         st->flag_ACELP16k = set_ACELP_flag_IVAS( IVAS_SCE, hSCE->element_brate, st->core_brate, 0, 0, -1, -1 );
     337             :     }
     338       69260 :     ELSE IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) && st->low_rate_mode )
     339             :     {
     340           0 :         st->flag_ACELP16k = 0;
     341             :     }
     342             :     ELSE
     343             :     {
     344       69260 :         st->flag_ACELP16k = set_ACELP_flag_IVAS( IVAS_SCE, hSCE->element_brate, st->total_brate, 0, 0, -1, -1 );
     345             :     }
     346       70893 :     move16();
     347             : 
     348             :     /* modify the coder_type depending on the total_brate per channel */
     349       70893 :     coder_type_modif_ivas_fx( st, relE_fx[0] );
     350             : 
     351             :     /*----------------------------------------------------------------*
     352             :      * Encoder
     353             :      *----------------------------------------------------------------*/
     354             : 
     355       70893 :     Scale_sig( old_wsp_fx[0], L_WSP, sub( e_old_wsp[0], Q16 ) ); // Q(15-16)
     356       70893 :     e_old_wsp[0] = 16;
     357       70893 :     move16();
     358       70893 :     IF( NE_32( ( error = ivas_core_enc_fx( hSCE, NULL, NULL, 1, old_inp_12k8_fx, old_inp_16k_fx, Q_new, ener_fx, A_fx, Aw_fx, epsP_fx, epsP_fx_q, lsp_new_fx, lsp_mid_fx, vad_hover_flag, attack_flag, realBuffer_fx, imagBuffer_fx, &q_re_im_buf, old_wsp_fx, e_old_wsp, loc_harm, cor_map_sum_fx, vad_flag_dtx, enerBuffer_fx, enerBuffer_fx_exp, fft_buff_fx, 0, ivas_format, flag_16k_smc ) ), IVAS_ERR_OK ) )
     359             :     {
     360           0 :         return error;
     361             :     }
     362             : 
     363             :     /*----------------------------------------------------------------*
     364             :      * Common updates
     365             :      *----------------------------------------------------------------*/
     366             : 
     367             :     /* update input samples buffer */
     368       70893 :     Copy( st->input_fx, st->old_input_signal_fx, input_frame );
     369       70893 :     st->q_old_inp = st->q_inp;
     370       70893 :     move16();
     371       70893 :     Copy32( st->input32_fx, st->old_input_signal32_fx, input_frame ); /* st->q_inp32 */
     372       70893 :     st->q_old_inp32 = st->q_inp32;
     373       70893 :     move16();
     374       70893 :     hSCE->last_element_brate = hSCE->element_brate;
     375       70893 :     move32();
     376             : 
     377             :     /* Store previous attack detection flag */
     378       70893 :     st->hTranDet->transientDetector.prev_bIsAttackPresent = st->hTranDet->transientDetector.bIsAttackPresent;
     379       70893 :     move16();
     380             : 
     381             : #ifdef DEBUG_MODE_INFO
     382             :     {
     383             :         float tmpF = hSCE->element_brate / 1000.0f;
     384             :         dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "element_brate", 0, sce_id, ENC ) );
     385             :     }
     386             : #endif
     387             : 
     388             : 
     389       70893 :     pop_wmops();
     390             : 
     391       70893 :     return error;
     392             : }
     393             : 
     394             : /*-------------------------------------------------------------------------
     395             :  * create_sce_enc()
     396             :  *
     397             :  * Create, allocate and initialize IVAS encoder SCE handle
     398             :  *-------------------------------------------------------------------------*/
     399        2959 : ivas_error create_sce_enc_fx(
     400             :     Encoder_Struct *st_ivas,   /* i/o: IVAS encoder structure      */
     401             :     const Word16 sce_id,       /* i  : SCE # identifier            */
     402             :     const Word32 element_brate /* i  : element bitrate             */
     403             : )
     404             : {
     405             :     SCE_ENC_HANDLE hSCE;
     406             :     Encoder_State *st;
     407             : 
     408             :     ivas_error error;
     409             : 
     410        2959 :     error = IVAS_ERR_OK;
     411        2959 :     move32();
     412             : 
     413             :     /*-----------------------------------------------------------------*
     414             :      * Allocate SCE handle
     415             :      *-----------------------------------------------------------------*/
     416             : 
     417        2959 :     IF( ( hSCE = (SCE_ENC_HANDLE) malloc( sizeof( SCE_ENC_DATA ) ) ) == NULL )
     418             :     {
     419           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SCE\n" ) );
     420             :     }
     421             : 
     422             :     /*-----------------------------------------------------------------*
     423             :      * Initialization - general parameters
     424             :      *-----------------------------------------------------------------*/
     425             : 
     426        2959 :     hSCE->sce_id = sce_id;
     427        2959 :     hSCE->element_brate = element_brate;
     428        2959 :     hSCE->last_element_brate = hSCE->element_brate;
     429        2959 :     move16();
     430        2959 :     move32();
     431        2959 :     move32();
     432             : 
     433             :     /*-----------------------------------------------------------------*
     434             :      * Metadata: allocate and initialize
     435             :      *-----------------------------------------------------------------*/
     436        2959 :     test();
     437        2959 :     IF( NE_16( st_ivas->hEncoderConfig->ivas_format, MONO_FORMAT ) && EQ_16( sce_id, sub( st_ivas->nSCE, 1 ) ) )
     438             :     {
     439        1918 :         IF( NE_32( ( error = ivas_initialize_MD_bstr_enc_fx( &( hSCE->hMetaData ), st_ivas ) ), IVAS_ERR_OK ) )
     440             :         {
     441           0 :             return error;
     442             :         }
     443             :     }
     444             :     ELSE
     445             :     {
     446        1041 :         hSCE->hMetaData = NULL;
     447             :     }
     448             : 
     449             :     /*-----------------------------------------------------------------*
     450             :      * Core Coder, 1 instance: allocate and initialize
     451             :      *-----------------------------------------------------------------*/
     452             : 
     453        2959 :     IF( ( st = (ENC_CORE_HANDLE) malloc( sizeof( Encoder_State ) ) ) == NULL )
     454             :     {
     455           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n" ) );
     456             :     }
     457             : 
     458        2959 :     copy_encoder_config_fx( st_ivas, st, 1 );
     459             : 
     460        2959 :     test();
     461        2959 :     test();
     462        2959 :     test();
     463        2959 :     IF( EQ_16( st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) && ( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) )
     464             :     {
     465        1435 :         st->element_mode = IVAS_SCE;
     466        1435 :         move16();
     467             :     }
     468             : 
     469        2959 :     st->total_brate = hSCE->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
     470        2959 :     st->mct_chan_mode = MCT_CHAN_MODE_REGULAR;
     471        2959 :     move32();
     472        2959 :     move32();
     473        2959 :     st->max_bwidth = st_ivas->hEncoderConfig->max_bwidth;
     474        2959 :     st->input_Fs = st_ivas->hEncoderConfig->input_Fs;
     475        2959 :     st->input_frame_fx = extract_l( Mult_32_16( st->input_Fs, 0x0290 ) );
     476             : 
     477        2959 :     IF( NE_32( ( error = init_encoder_ivas_fx( st, st_ivas, 0, st_ivas->hEncoderConfig->var_SID_rate_flag, st_ivas->hEncoderConfig->interval_SID, 0, st_ivas->ism_mode, hSCE->element_brate ) ), IVAS_ERR_OK ) )
     478             :     {
     479           0 :         return error;
     480             :     }
     481        2959 :     hSCE->hCoreCoder[0] = st;
     482             : 
     483        2959 :     st_ivas->hSCE[sce_id] = hSCE;
     484             : 
     485        2959 :     return error;
     486             : }
     487             : 
     488             : /*-------------------------------------------------------------------------
     489             :  * create_evs_sce_enc_fx()
     490             :  *
     491             :  * Create, allocate and initialize EVS encoder SCE handle
     492             :  *-------------------------------------------------------------------------*/
     493             : #ifndef HARM_SCE_INIT
     494           3 : ivas_error create_evs_sce_enc_fx(
     495             :     Encoder_Struct *st_ivas,   /* i/o: IVAS encoder structure      */
     496             :     const Word16 sce_id,       /* i  : SCE # identifier            */
     497             :     const Word32 element_brate /* i  : element bitrate             */
     498             : )
     499             : {
     500           3 :     SCE_ENC_HANDLE hSCE = st_ivas->hSCE[sce_id];
     501             :     Encoder_State *st_fx;
     502             : 
     503             :     ivas_error error;
     504             : 
     505           3 :     error = IVAS_ERR_OK;
     506           3 :     move32();
     507             : 
     508             :     /*-----------------------------------------------------------------*
     509             :      * Allocate SCE handle
     510             :      *-----------------------------------------------------------------*/
     511             : 
     512           3 :     IF( ( hSCE = (SCE_ENC_HANDLE) malloc( sizeof( SCE_ENC_DATA ) ) ) == NULL )
     513             :     {
     514           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SCE\n" ) );
     515             :     }
     516             : 
     517             :     /*-----------------------------------------------------------------*
     518             :      * Initialization - general parameters
     519             :      *-----------------------------------------------------------------*/
     520             : 
     521           3 :     hSCE->sce_id = sce_id;
     522           3 :     move16();
     523           3 :     hSCE->element_brate = element_brate;
     524           3 :     move32();
     525           3 :     hSCE->last_element_brate = hSCE->element_brate;
     526           3 :     move32();
     527             :     /*-----------------------------------------------------------------*
     528             :      * Metadata: allocate and initialize
     529             :      *-----------------------------------------------------------------*/
     530           3 :     test();
     531           3 :     IF( NE_32( st_ivas->hEncoderConfig->ivas_format, MONO_FORMAT ) && EQ_16( sce_id, sub( st_ivas->nSCE, 1 ) ) )
     532             :     {
     533           0 :         IF( NE_32( ( error = ivas_initialize_MD_bstr_enc_fx( &( hSCE->hMetaData ), st_ivas ) ), IVAS_ERR_OK ) )
     534             :         {
     535           0 :             return error;
     536             :         }
     537             :     }
     538             :     ELSE
     539             :     {
     540           3 :         hSCE->hMetaData = NULL;
     541             :     }
     542             : 
     543             :     /*-----------------------------------------------------------------*
     544             :      * Core Coder, 1 instance: allocate and initialize
     545             :      *-----------------------------------------------------------------*/
     546           3 :     IF( ( st_fx = (ENC_CORE_HANDLE) malloc( sizeof( Encoder_State ) ) ) == NULL )
     547             :     {
     548           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n" ) );
     549             :     }
     550           3 :     memset( st_fx, 0, sizeof( Encoder_State ) );
     551           3 :     st_fx->input_Fs = 16000;
     552           3 :     move32();
     553           3 :     st_fx->total_brate = ACELP_12k65;
     554           3 :     move32();
     555           3 :     st_fx->Opt_AMR_WB = 0;
     556           3 :     move16();
     557           3 :     st_fx->Opt_RF_ON = 0;
     558           3 :     move16();
     559           3 :     st_fx->rf_fec_offset = 0;
     560           3 :     move16();
     561           3 :     st_fx->rf_fec_indicator = 1;
     562           3 :     move16();
     563             : 
     564           3 :     st_fx->max_bwidth = SWB;
     565           3 :     move16();
     566           3 :     st_fx->interval_SID_fx = FIXED_SID_RATE;
     567           3 :     move16();
     568           3 :     st_fx->var_SID_rate_flag_fx = 1;
     569           3 :     move16();
     570           3 :     st_fx->Opt_HE_SAD_ON_fx = 0;
     571           3 :     move16();
     572           3 :     st_fx->Opt_SC_VBR = 0;
     573           3 :     move16();
     574           3 :     st_fx->last_Opt_SC_VBR = 0;
     575           3 :     move16();
     576           3 :     st_fx->bitstreamformat = G192;
     577           3 :     move16();
     578             : 
     579             :     // copy_encoder_config_fx( st_ivas, st_fx, 1 );
     580           3 :     st_fx->max_bwidth = st_ivas->hEncoderConfig->max_bwidth;
     581           3 :     move16();
     582           3 :     st_fx->Opt_DTX_ON = st_ivas->hEncoderConfig->Opt_DTX_ON;
     583           3 :     move16();
     584           3 :     st_fx->var_SID_rate_flag_fx = st_ivas->hEncoderConfig->var_SID_rate_flag;
     585           3 :     move16();
     586           3 :     st_fx->interval_SID_fx = st_ivas->hEncoderConfig->interval_SID;
     587           3 :     move16();
     588           3 :     st_fx->Opt_RF_ON = st_ivas->hEncoderConfig->Opt_RF_ON;
     589           3 :     move16();
     590           3 :     st_fx->rf_fec_indicator = st_ivas->hEncoderConfig->rf_fec_indicator;
     591           3 :     move16();
     592           3 :     st_fx->rf_fec_offset = st_ivas->hEncoderConfig->rf_fec_offset;
     593           3 :     move16();
     594             :     // st_fx->bitstreamformat = st->bitstreamformat;
     595           3 :     st_fx->total_brate = st_ivas->hEncoderConfig->ivas_total_brate;
     596           3 :     move32();
     597           3 :     st_fx->Opt_SC_VBR = st_ivas->hEncoderConfig->Opt_SC_VBR;
     598           3 :     move16();
     599           3 :     st_fx->last_Opt_SC_VBR = st_ivas->hEncoderConfig->last_Opt_SC_VBR;
     600           3 :     move16();
     601           3 :     st_fx->Opt_AMR_WB = st_ivas->hEncoderConfig->Opt_AMR_WB;
     602           3 :     move16();
     603           3 :     st_fx->input_Fs = st_ivas->hEncoderConfig->input_Fs;
     604           3 :     move32();
     605           3 :     st_fx->codec_mode = st_ivas->codec_mode;
     606           3 :     move16();
     607           3 :     st_fx->last_codec_mode = st_ivas->last_codec_mode;
     608           3 :     move16();
     609           3 :     st_fx->input_frame_fx = extract_l( Mult_32_16( st_fx->input_Fs, 0x0290 ) );
     610           3 :     move16();
     611           3 :     IF( NE_32( ( error = init_encoder_fx( st_fx ) ), IVAS_ERR_OK ) )
     612             :     {
     613           0 :         return error;
     614             :     }
     615             :     /*-----------------------------------------------------------------*
     616             :      * Bitstream
     617             :      *-----------------------------------------------------------------*/
     618             : 
     619             :     /* set pointer to the buffer of indices */
     620           3 :     st_fx->hBstr->ind_list = st_ivas->ind_list;
     621           3 :     st_fx->hBstr->ivas_ind_list_zero = &st_ivas->ind_list;
     622           3 :     st_fx->hBstr->ivas_max_num_indices = &st_ivas->ivas_max_num_indices;
     623           3 :     st_fx->hBstr->nb_ind_tot = 0;
     624           3 :     move16();
     625           3 :     st_fx->hBstr->nb_bits_tot = 0;
     626           3 :     move16();
     627           3 :     st_fx->hBstr->st_ivas = st_ivas;
     628             : 
     629           3 :     hSCE->hCoreCoder[0] = st_fx;
     630             : 
     631           3 :     st_ivas->hSCE[sce_id] = hSCE;
     632             : 
     633           3 :     return error;
     634             : }
     635             : #endif
     636             : /*-------------------------------------------------------------------------
     637             :  * destroy_sce_enc_fx()
     638             :  *
     639             :  * Destroy and deallocate IVAS encoder SCE handle
     640             :  *-------------------------------------------------------------------------*/
     641             : 
     642        2962 : void destroy_sce_enc_fx(
     643             :     SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure       */
     644             :     Flag is_evs          /* i  : Flag to indicate EVS encoder*/
     645             : )
     646             : {
     647             :     Encoder_State *st;
     648             : 
     649        2962 :     st = hSCE->hCoreCoder[0];
     650             : 
     651        2962 :     IF( st != NULL )
     652             :     {
     653        2962 :         test();
     654        2962 :         IF( ( st->element_mode == EVS_MONO ) && is_evs )
     655             :         {
     656           3 :             destroy_evs_core_enc_fx( st );
     657           3 :             st = NULL;
     658             :         }
     659             :         ELSE
     660             :         {
     661        2959 :             destroy_core_enc_fx( st );
     662        2959 :             st = NULL;
     663             :         }
     664             :     }
     665             : 
     666        2962 :     ivas_destroy_MD_bstr_enc_fx( &( hSCE->hMetaData ) );
     667             : 
     668        2962 :     free( hSCE );
     669             : 
     670        2962 :     return;
     671             : }

Generated by: LCOV version 1.14