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 @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 249 268 92.9 %
Date: 2025-05-03 01:55:50 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 :     Copy_Scale_sig32( data_fx, st->input32_fx, input_frame, sub( Q_min, q_data_fx ) ); // Q(Q_min)
     128       70893 :     st->q_inp32 = Q_min;
     129       70893 :     move16();
     130       70893 :     q_input = sub( add( L_norm_arr( st->input32_fx, input_frame ), Q_min ), 16 );
     131             : 
     132       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)
     133       70893 :     st->q_inp = q_input;
     134       70893 :     move16();
     135             : 
     136       70893 :     st->element_mode = IVAS_SCE;
     137       70893 :     move16();
     138             : 
     139       70893 :     set16_fx( A_fx[0], 0, NB_SUBFR16k * ( M + 1 ) );
     140       70893 :     set16_fx( Aw_fx[0], 0, NB_SUBFR16k * ( M + 1 ) );
     141             : 
     142     1205181 :     FOR( Word16 i = 0; i < CLDFB_NO_COL_MAX; i++ )
     143             :     {
     144     1134288 :         set_zero_fx( realBuffer_fx[0][i], CLDFB_NO_CHANNELS_MAX );
     145     1134288 :         set_zero_fx( imagBuffer_fx[0][i], CLDFB_NO_CHANNELS_MAX );
     146             :     }
     147             : 
     148       70893 :     set16_zero_fx( old_inp_16k_fx[0], L_INP );
     149             : 
     150             :     /*------------------------------------------------------------------*
     151             :      * SCE initialization - core coder
     152             :      *-----------------------------------------------------------------*/
     153             : 
     154       70893 :     st->idchan = 0;
     155       70893 :     st->core = -1;
     156       70893 :     st->core_brate = -1; /* updated in dtx() */
     157       70893 :     st->max_bwidth = st_ivas->hEncoderConfig->max_bwidth;
     158       70893 :     st->input_bwidth = st->last_input_bwidth; /* updated in BWD */
     159       70893 :     st->bwidth = st->last_bwidth;             /* updated in BWD */
     160       70893 :     st->rate_switching_reset = 0;
     161             : #ifdef DEBUGGING
     162             :     st->force = st_ivas->hEncoderConfig->force;
     163             :     st->id_element = sce_id;
     164             : #ifdef DEBUG_FORCE_DIR
     165             :     st->force_dir = st_ivas->hEncoderConfig->force_dir;
     166             : #endif
     167             : #endif
     168       70893 :     move16();
     169       70893 :     move16();
     170       70893 :     move32();
     171       70893 :     move16();
     172       70893 :     move16();
     173       70893 :     move16();
     174       70893 :     move16();
     175             : 
     176             :     /*---------------------------------------------------------------*
     177             :      * Time Domain Transient Detector
     178             :      *---------------------------------------------------------------*/
     179       70893 :     test();
     180       70893 :     IF( NE_32( ivas_format, MC_FORMAT ) || NE_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) )
     181             :     {
     182       70893 :         RunTransientDetection_ivas_fx( st->input_fx, input_frame, st->hTranDet, q_input );
     183             :     }
     184             : 
     185       70893 :     currFlatness_fx[0] = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS, 0 ); // Q21
     186       70893 :     move32();
     187             : 
     188             :     /*----------------------------------------------------------------*
     189             :      * Configuration of core encoder
     190             :      *----------------------------------------------------------------*/
     191             : 
     192             :     /* Force to MODE1 in IVAS */
     193       70893 :     st->codec_mode = MODE1;
     194       70893 :     move16();
     195             : 
     196             :     /* set "bits_frame_nominal" */
     197       70893 :     test();
     198       70893 :     IF( st_ivas->hQMetaData != NULL && st_ivas->hSpar == NULL )
     199             :     {
     200       27002 :         test();
     201       27002 :         test();
     202       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 ) )
     203             :         {
     204        2487 :             st->bits_frame_nominal = extract_l( Mpy_32_32( hSCE->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) );
     205        2487 :             move16();
     206             :         }
     207             :         ELSE
     208             :         {
     209       24515 :             st->bits_frame_nominal = st_ivas->hQMetaData->bits_frame_nominal;
     210       24515 :             move16();
     211             :         }
     212             :     }
     213       43891 :     ELSE IF( st_ivas->hSpar != NULL )
     214             :     {
     215       43891 :         st->bits_frame_nominal = extract_l( Mpy_32_32( st_ivas->hSpar->core_nominal_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) );
     216       43891 :         move16();
     217             :     }
     218             :     ELSE
     219             :     {
     220           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 );
     221           0 :         move16();
     222             :     }
     223             : 
     224             :     /* set "total_brate" */
     225       70893 :     st->total_brate = L_sub( hSCE->element_brate, L_mult0( nb_bits_metadata, FRAMES_PER_SEC ) );
     226       70893 :     move32();
     227             : 
     228             :     /* set flag for sampling rate of OL S/M classifier */
     229       70893 :     flag_16k_smc = 0;
     230       70893 :     move16();
     231       70893 :     test();
     232       70893 :     test();
     233       70893 :     test();
     234       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 ) )
     235             :     {
     236       26562 :         flag_16k_smc = 1;
     237       26562 :         move16();
     238             :     }
     239             : 
     240             : #ifdef DEBUG_MODE_INFO
     241             :     dbgwrite( st->input_fx - NS2SA( st->input_Fs, ACELP_LOOK_NS ), sizeof( Word16 ), input_frame, 1, "res/input_DMX" );
     242             :     dbgwrite( &st->element_mode, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "element_mode", 0, st->id_element, ENC ) );
     243             : #endif
     244             : 
     245             : 
     246             :     /*----------------------------------------------------------------*
     247             :      * Front Pre-processing
     248             :      *----------------------------------------------------------------*/
     249       70893 :     set16_fx( old_wsp_fx[0], 0, L_WSP );
     250       70893 :     q_old_wsp = Q15;
     251       70893 :     move16();
     252             : 
     253             :     Word16 q_fr_bands[2];
     254      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],
     255             :                                     &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],
     256             :                                     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],
     257             :                                     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,
     258      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]
     259             : #ifdef DEBUG_MODE_INFO
     260             :                                     ,
     261             :                                     st->id_element
     262             : #endif
     263             :     );
     264       70893 :     e_old_wsp[0] = sub( Q15, q_old_wsp );
     265       70893 :     move16();
     266       70893 :     IF( NE_32( error, IVAS_ERR_OK ) )
     267             :     {
     268           0 :         return error;
     269             :     }
     270             : 
     271             :     /* sanity check -> DTX not supported for more than one SCEs/CPEs */
     272       70893 :     IF( sub( add( st_ivas->nSCE, st_ivas->nCPE ), 1 ) > 0 )
     273             :     {
     274        2487 :         test();
     275        2487 :         IF( EQ_32( st->core_brate, SID_2k40 ) || st->core_brate == FRAME_NO_DATA )
     276             :         {
     277           0 :             st->core_brate = -1;
     278           0 :             st->total_brate = L_sub( hSCE->element_brate, L_mult0( nb_bits_metadata, FRAMES_PER_SEC ) );
     279           0 :             move32();
     280           0 :             move32();
     281             :         }
     282             :     }
     283             : 
     284             :     /*----------------------------------------------------------------*
     285             :      * Reset metadata
     286             :      *----------------------------------------------------------------*/
     287             : 
     288       70893 :     reset_metadata_spatial_fx( ivas_format, hSCE->hMetaData, hSCE->element_brate, &st->total_brate, st->core_brate, nb_bits_metadata );
     289             : 
     290             :     /*----------------------------------------------------------------*
     291             :      * Combined format coding: get the ISM importance and the bit-rate
     292             :      *----------------------------------------------------------------*/
     293       70893 :     test();
     294       70893 :     IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) )
     295             :     {
     296        1862 :         st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx = 0;
     297        1862 :         move16();
     298        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 );
     299             : 
     300        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 ) );
     301        1862 :         move32();
     302             :     }
     303             : 
     304             :     /*----------------------------------------------------------------*
     305             :      * Write IVAS format signaling in SID frames
     306             :      *----------------------------------------------------------------*/
     307             : 
     308       70893 :     IF( EQ_32( st->core_brate, SID_2k40 ) )
     309             :     {
     310         344 :         ivas_write_format_sid_fx( ivas_format, IVAS_SCE, st->hBstr );
     311             :     }
     312             : 
     313             :     /*----------------------------------------------------------------*
     314             :      * Core codec configuration
     315             :      *----------------------------------------------------------------*/
     316             : 
     317             :     /* IGF reconfiguration */
     318       70893 :     test();
     319       70893 :     IF( NE_32( hSCE->last_element_brate, hSCE->element_brate ) || NE_16( st->last_bwidth, st->bwidth ) )
     320             :     {
     321             :         Word16 igf;
     322        1210 :         igf = getIgfPresent_fx( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->max_bwidth, st->rf_mode );
     323        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 ) )
     324             :         {
     325           0 :             return error;
     326             :         }
     327             :     }
     328             : 
     329             :     /* set ACELP@12k8 / ACELP@16k flag for flexible ACELP core */
     330       70893 :     test();
     331       70893 :     test();
     332       70893 :     IF( EQ_32( st->core_brate, SID_2k40 ) || st->core_brate == FRAME_NO_DATA )
     333             :     {
     334        2617 :         st->flag_ACELP16k = set_ACELP_flag_IVAS( IVAS_SCE, hSCE->element_brate, st->core_brate, 0, 0, -1, -1 );
     335             :     }
     336       68276 :     ELSE IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) && st->low_rate_mode )
     337             :     {
     338           0 :         st->flag_ACELP16k = 0;
     339             :     }
     340             :     ELSE
     341             :     {
     342       68276 :         st->flag_ACELP16k = set_ACELP_flag_IVAS( IVAS_SCE, hSCE->element_brate, st->total_brate, 0, 0, -1, -1 );
     343             :     }
     344       70893 :     move16();
     345             : 
     346             :     /* modify the coder_type depending on the total_brate per channel */
     347       70893 :     coder_type_modif_ivas_fx( st, relE_fx[0] );
     348             : 
     349             :     /*----------------------------------------------------------------*
     350             :      * Encoder
     351             :      *----------------------------------------------------------------*/
     352             : 
     353       70893 :     Scale_sig( old_wsp_fx[0], L_WSP, sub( e_old_wsp[0], Q16 ) ); // Q(15-16)
     354       70893 :     e_old_wsp[0] = 16;
     355       70893 :     move16();
     356       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 ) )
     357             :     {
     358           0 :         return error;
     359             :     }
     360             : 
     361             :     /*----------------------------------------------------------------*
     362             :      * Common updates
     363             :      *----------------------------------------------------------------*/
     364             : 
     365             :     /* update input samples buffer */
     366       70893 :     Copy( st->input_fx, st->old_input_signal_fx, input_frame );
     367       70893 :     st->q_old_inp = st->q_inp;
     368       70893 :     move16();
     369       70893 :     Copy32( st->input32_fx, st->input32_fx - input_frame, input_frame ); /* st->q_inp32 */
     370       70893 :     hSCE->last_element_brate = hSCE->element_brate;
     371       70893 :     move32();
     372             : 
     373             :     /* Store previous attack detection flag */
     374       70893 :     st->hTranDet->transientDetector.prev_bIsAttackPresent = st->hTranDet->transientDetector.bIsAttackPresent;
     375       70893 :     move16();
     376             : 
     377             : #ifdef DEBUG_MODE_INFO
     378             :     {
     379             :         float tmpF = hSCE->element_brate / 1000.0f;
     380             :         dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "element_brate", 0, sce_id, ENC ) );
     381             :     }
     382             : #endif
     383             : 
     384             : 
     385       70893 :     pop_wmops();
     386             : 
     387       70893 :     return error;
     388             : }
     389             : 
     390             : /*-------------------------------------------------------------------------
     391             :  * create_sce_enc()
     392             :  *
     393             :  * Create, allocate and initialize IVAS encoder SCE handle
     394             :  *-------------------------------------------------------------------------*/
     395        2959 : ivas_error create_sce_enc_fx(
     396             :     Encoder_Struct *st_ivas,   /* i/o: IVAS encoder structure      */
     397             :     const Word16 sce_id,       /* i  : SCE # identifier            */
     398             :     const Word32 element_brate /* i  : element bitrate             */
     399             : )
     400             : {
     401             :     SCE_ENC_HANDLE hSCE;
     402             :     Encoder_State *st;
     403             : 
     404             :     ivas_error error;
     405             : 
     406        2959 :     error = IVAS_ERR_OK;
     407        2959 :     move32();
     408             : 
     409             :     /*-----------------------------------------------------------------*
     410             :      * Allocate SCE handle
     411             :      *-----------------------------------------------------------------*/
     412             : 
     413        2959 :     IF( ( hSCE = (SCE_ENC_HANDLE) malloc( sizeof( SCE_ENC_DATA ) ) ) == NULL )
     414             :     {
     415           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SCE\n" ) );
     416             :     }
     417             : 
     418             :     /*-----------------------------------------------------------------*
     419             :      * Initialization - general parameters
     420             :      *-----------------------------------------------------------------*/
     421             : 
     422        2959 :     hSCE->sce_id = sce_id;
     423        2959 :     hSCE->element_brate = element_brate;
     424        2959 :     hSCE->last_element_brate = hSCE->element_brate;
     425        2959 :     move16();
     426        2959 :     move32();
     427        2959 :     move32();
     428             : 
     429             :     /*-----------------------------------------------------------------*
     430             :      * Metadata: allocate and initialize
     431             :      *-----------------------------------------------------------------*/
     432        2959 :     test();
     433        2959 :     IF( NE_16( st_ivas->hEncoderConfig->ivas_format, MONO_FORMAT ) && EQ_16( sce_id, sub( st_ivas->nSCE, 1 ) ) )
     434             :     {
     435        1918 :         IF( NE_32( ( error = ivas_initialize_MD_bstr_enc_fx( &( hSCE->hMetaData ), st_ivas ) ), IVAS_ERR_OK ) )
     436             :         {
     437           0 :             return error;
     438             :         }
     439             :     }
     440             :     ELSE
     441             :     {
     442        1041 :         hSCE->hMetaData = NULL;
     443             :     }
     444             : 
     445             :     /*-----------------------------------------------------------------*
     446             :      * Core Coder, 1 instance: allocate and initialize
     447             :      *-----------------------------------------------------------------*/
     448             : 
     449        2959 :     IF( ( st = (ENC_CORE_HANDLE) malloc( sizeof( Encoder_State ) ) ) == NULL )
     450             :     {
     451           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n" ) );
     452             :     }
     453             : 
     454        2959 :     copy_encoder_config_fx( st_ivas, st, 1 );
     455             : 
     456        2959 :     test();
     457        2959 :     test();
     458        2959 :     test();
     459        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 ) ) )
     460             :     {
     461        1435 :         st->element_mode = IVAS_SCE;
     462        1435 :         move16();
     463             :     }
     464             : 
     465        2959 :     st->total_brate = hSCE->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
     466        2959 :     st->mct_chan_mode = MCT_CHAN_MODE_REGULAR;
     467        2959 :     move32();
     468        2959 :     move32();
     469        2959 :     st->max_bwidth = st_ivas->hEncoderConfig->max_bwidth;
     470        2959 :     st->input_Fs = st_ivas->hEncoderConfig->input_Fs;
     471        2959 :     st->input_frame_fx = extract_l( Mult_32_16( st->input_Fs, 0x0290 ) );
     472             : 
     473        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 ) )
     474             :     {
     475           0 :         return error;
     476             :     }
     477        2959 :     hSCE->hCoreCoder[0] = st;
     478             : 
     479        2959 :     st_ivas->hSCE[sce_id] = hSCE;
     480             : 
     481        2959 :     return error;
     482             : }
     483             : 
     484             : /*-------------------------------------------------------------------------
     485             :  * create_evs_sce_enc_fx()
     486             :  *
     487             :  * Create, allocate and initialize EVS encoder SCE handle
     488             :  *-------------------------------------------------------------------------*/
     489             : #ifndef HARM_SCE_INIT
     490           3 : ivas_error create_evs_sce_enc_fx(
     491             :     Encoder_Struct *st_ivas,   /* i/o: IVAS encoder structure      */
     492             :     const Word16 sce_id,       /* i  : SCE # identifier            */
     493             :     const Word32 element_brate /* i  : element bitrate             */
     494             : )
     495             : {
     496           3 :     SCE_ENC_HANDLE hSCE = st_ivas->hSCE[sce_id];
     497             :     Encoder_State *st_fx;
     498             : 
     499             :     ivas_error error;
     500             : 
     501           3 :     error = IVAS_ERR_OK;
     502           3 :     move32();
     503             : 
     504             :     /*-----------------------------------------------------------------*
     505             :      * Allocate SCE handle
     506             :      *-----------------------------------------------------------------*/
     507             : 
     508           3 :     IF( ( hSCE = (SCE_ENC_HANDLE) malloc( sizeof( SCE_ENC_DATA ) ) ) == NULL )
     509             :     {
     510           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SCE\n" ) );
     511             :     }
     512             : 
     513             :     /*-----------------------------------------------------------------*
     514             :      * Initialization - general parameters
     515             :      *-----------------------------------------------------------------*/
     516             : 
     517           3 :     hSCE->sce_id = sce_id;
     518           3 :     move16();
     519           3 :     hSCE->element_brate = element_brate;
     520           3 :     move32();
     521           3 :     hSCE->last_element_brate = hSCE->element_brate;
     522           3 :     move32();
     523             :     /*-----------------------------------------------------------------*
     524             :      * Metadata: allocate and initialize
     525             :      *-----------------------------------------------------------------*/
     526           3 :     test();
     527           3 :     IF( NE_32( st_ivas->hEncoderConfig->ivas_format, MONO_FORMAT ) && EQ_16( sce_id, sub( st_ivas->nSCE, 1 ) ) )
     528             :     {
     529           0 :         IF( NE_32( ( error = ivas_initialize_MD_bstr_enc_fx( &( hSCE->hMetaData ), st_ivas ) ), IVAS_ERR_OK ) )
     530             :         {
     531           0 :             return error;
     532             :         }
     533             :     }
     534             :     ELSE
     535             :     {
     536           3 :         hSCE->hMetaData = NULL;
     537             :     }
     538             : 
     539             :     /*-----------------------------------------------------------------*
     540             :      * Core Coder, 1 instance: allocate and initialize
     541             :      *-----------------------------------------------------------------*/
     542           3 :     IF( ( st_fx = (ENC_CORE_HANDLE) malloc( sizeof( Encoder_State ) ) ) == NULL )
     543             :     {
     544           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n" ) );
     545             :     }
     546           3 :     memset( st_fx, 0, sizeof( Encoder_State ) );
     547           3 :     st_fx->input_Fs = 16000;
     548           3 :     move32();
     549           3 :     st_fx->total_brate = ACELP_12k65;
     550           3 :     move32();
     551           3 :     st_fx->Opt_AMR_WB = 0;
     552           3 :     move16();
     553           3 :     st_fx->Opt_RF_ON = 0;
     554           3 :     move16();
     555           3 :     st_fx->rf_fec_offset = 0;
     556           3 :     move16();
     557           3 :     st_fx->rf_fec_indicator = 1;
     558           3 :     move16();
     559             : 
     560           3 :     st_fx->max_bwidth = SWB;
     561           3 :     move16();
     562           3 :     st_fx->interval_SID_fx = FIXED_SID_RATE;
     563           3 :     move16();
     564           3 :     st_fx->var_SID_rate_flag_fx = 1;
     565           3 :     move16();
     566           3 :     st_fx->Opt_HE_SAD_ON_fx = 0;
     567           3 :     move16();
     568           3 :     st_fx->Opt_SC_VBR = 0;
     569           3 :     move16();
     570           3 :     st_fx->last_Opt_SC_VBR = 0;
     571           3 :     move16();
     572           3 :     st_fx->bitstreamformat = G192;
     573           3 :     move16();
     574             : 
     575             :     // copy_encoder_config_fx( st_ivas, st_fx, 1 );
     576           3 :     st_fx->max_bwidth = st_ivas->hEncoderConfig->max_bwidth;
     577           3 :     move16();
     578           3 :     st_fx->Opt_DTX_ON = st_ivas->hEncoderConfig->Opt_DTX_ON;
     579           3 :     move16();
     580           3 :     st_fx->var_SID_rate_flag_fx = st_ivas->hEncoderConfig->var_SID_rate_flag;
     581           3 :     move16();
     582           3 :     st_fx->interval_SID_fx = st_ivas->hEncoderConfig->interval_SID;
     583           3 :     move16();
     584           3 :     st_fx->Opt_RF_ON = st_ivas->hEncoderConfig->Opt_RF_ON;
     585           3 :     move16();
     586           3 :     st_fx->rf_fec_indicator = st_ivas->hEncoderConfig->rf_fec_indicator;
     587           3 :     move16();
     588           3 :     st_fx->rf_fec_offset = st_ivas->hEncoderConfig->rf_fec_offset;
     589           3 :     move16();
     590             :     // st_fx->bitstreamformat = st->bitstreamformat;
     591           3 :     st_fx->total_brate = st_ivas->hEncoderConfig->ivas_total_brate;
     592           3 :     move32();
     593           3 :     st_fx->Opt_SC_VBR = st_ivas->hEncoderConfig->Opt_SC_VBR;
     594           3 :     move16();
     595           3 :     st_fx->last_Opt_SC_VBR = st_ivas->hEncoderConfig->last_Opt_SC_VBR;
     596           3 :     move16();
     597           3 :     st_fx->Opt_AMR_WB = st_ivas->hEncoderConfig->Opt_AMR_WB;
     598           3 :     move16();
     599           3 :     st_fx->input_Fs = st_ivas->hEncoderConfig->input_Fs;
     600           3 :     move32();
     601           3 :     st_fx->codec_mode = st_ivas->codec_mode;
     602           3 :     move16();
     603           3 :     st_fx->last_codec_mode = st_ivas->last_codec_mode;
     604           3 :     move16();
     605           3 :     st_fx->input_frame_fx = extract_l( Mult_32_16( st_fx->input_Fs, 0x0290 ) );
     606           3 :     move16();
     607           3 :     IF( NE_32( ( error = init_encoder_fx( st_fx ) ), IVAS_ERR_OK ) )
     608             :     {
     609           0 :         return error;
     610             :     }
     611             : #ifdef HARM_PUSH_BIT
     612             :     /*-----------------------------------------------------------------*
     613             :      * Bitstream
     614             :      *-----------------------------------------------------------------*/
     615             : 
     616             :     /* set pointer to the buffer of indices */
     617           3 :     st_fx->hBstr->ind_list = st_ivas->ind_list;
     618           3 :     st_fx->hBstr->ivas_ind_list_zero = &st_ivas->ind_list;
     619           3 :     st_fx->hBstr->ivas_max_num_indices = &st_ivas->ivas_max_num_indices;
     620           3 :     st_fx->hBstr->nb_ind_tot = 0;
     621           3 :     move16();
     622           3 :     st_fx->hBstr->nb_bits_tot = 0;
     623           3 :     move16();
     624           3 :     st_fx->hBstr->st_ivas = st_ivas;
     625             : #else
     626             :     st_fx->hBstr->ind_list = ind_list;
     627             :     // st_fx->hBstr->ind_list_fx = st->hBstr->ind_list;
     628             :     reset_indices_enc_fx( st_fx->hBstr, MAX_NUM_INDICES );
     629             : #endif
     630             : 
     631           3 :     hSCE->hCoreCoder[0] = st_fx;
     632             : 
     633           3 :     st_ivas->hSCE[sce_id] = hSCE;
     634             : 
     635           3 :     return error;
     636             : }
     637             : #endif
     638             : /*-------------------------------------------------------------------------
     639             :  * destroy_sce_enc_fx()
     640             :  *
     641             :  * Destroy and deallocate IVAS encoder SCE handle
     642             :  *-------------------------------------------------------------------------*/
     643             : 
     644        2962 : void destroy_sce_enc_fx(
     645             :     SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure       */
     646             :     Flag is_evs          /* i  : Flag to indicate EVS encoder*/
     647             : )
     648             : {
     649             :     Encoder_State *st;
     650             : 
     651        2962 :     st = hSCE->hCoreCoder[0];
     652             : 
     653        2962 :     IF( st != NULL )
     654             :     {
     655        2962 :         test();
     656        2962 :         IF( ( st->element_mode == EVS_MONO ) && is_evs )
     657             :         {
     658           3 :             destroy_evs_core_enc_fx( st );
     659           3 :             st = NULL;
     660             :         }
     661             :         ELSE
     662             :         {
     663        2959 :             destroy_core_enc_fx( st );
     664        2959 :             st = NULL;
     665             :         }
     666             :     }
     667             : 
     668        2962 :     ivas_destroy_MD_bstr_enc_fx( &( hSCE->hMetaData ) );
     669             : 
     670        2962 :     free( hSCE );
     671             : 
     672        2962 :     return;
     673             : }

Generated by: LCOV version 1.14