LCOV - code coverage report
Current view: top level - lib_enc - ivas_sce_enc_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ e95243e9e67ddeb69dddf129509de1b3d95b402e Lines: 204 223 91.5 %
Date: 2025-09-14 03:13:15 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       71463 : 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       71463 :     Word16 q_re_im_buf = Q31;
      86       71463 :     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       71463 :     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       71463 :     move16();       // Q_new
     108             : 
     109       71463 :     push_wmops( "ivas_sce_enc" );
     110             : 
     111       71463 :     error = IVAS_ERR_OK;
     112       71463 :     move32();
     113             : 
     114       71463 :     hSCE = st_ivas->hSCE[sce_id];
     115       71463 :     st = hSCE->hCoreCoder[0];
     116       71463 :     ivas_format = st_ivas->hEncoderConfig->ivas_format;
     117       71463 :     move32();
     118             : 
     119             :     /*------------------------------------------------------------------*
     120             :      * Initialization - general
     121             :      *-----------------------------------------------------------------*/
     122             : 
     123       71463 :     set16_zero_fx( old_inp_12k8_fx[0], L_INP_12k8 );
     124             : 
     125       71463 :     Word16 Q_min = s_min( q_data_fx, add( st->q_inp32, L_norm_arr( st->input32_fx - input_frame, input_frame ) ) );
     126       71463 :     scale_sig32( st->input32_fx - input_frame, input_frame, sub( Q_min, st->q_inp32 ) );
     127       71463 :     st->q_old_inp32 = Q_min;
     128       71463 :     move16();
     129       71463 :     Copy_Scale_sig32( data_fx, st->input32_fx, input_frame, sub( Q_min, q_data_fx ) ); // Q(Q_min)
     130       71463 :     st->q_inp32 = Q_min;
     131       71463 :     move16();
     132       71463 :     q_input = sub( add( L_norm_arr( st->input32_fx, input_frame ), Q_min ), 16 );
     133             : 
     134       71463 :     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       71463 :     st->q_inp = q_input;
     136       71463 :     move16();
     137             : 
     138       71463 :     st->element_mode = IVAS_SCE;
     139       71463 :     move16();
     140             : 
     141       71463 :     set16_fx( A_fx[0], 0, NB_SUBFR16k * ( M + 1 ) );
     142       71463 :     set16_fx( Aw_fx[0], 0, NB_SUBFR16k * ( M + 1 ) );
     143             : 
     144     1214871 :     FOR( Word16 i = 0; i < CLDFB_NO_COL_MAX; i++ )
     145             :     {
     146     1143408 :         set_zero_fx( realBuffer_fx[0][i], CLDFB_NO_CHANNELS_MAX );
     147     1143408 :         set_zero_fx( imagBuffer_fx[0][i], CLDFB_NO_CHANNELS_MAX );
     148             :     }
     149             : 
     150       71463 :     set16_zero_fx( old_inp_16k_fx[0], L_INP );
     151             : 
     152             :     /*------------------------------------------------------------------*
     153             :      * SCE initialization - core coder
     154             :      *-----------------------------------------------------------------*/
     155             : 
     156       71463 :     st->idchan = 0;
     157       71463 :     st->core = -1;
     158       71463 :     st->core_brate = -1; /* updated in dtx() */
     159       71463 :     st->max_bwidth = st_ivas->hEncoderConfig->max_bwidth;
     160       71463 :     st->input_bwidth = st->last_input_bwidth; /* updated in BWD */
     161       71463 :     st->bwidth = st->last_bwidth;             /* updated in BWD */
     162       71463 :     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       71463 :     move16();
     171       71463 :     move16();
     172       71463 :     move32();
     173       71463 :     move16();
     174       71463 :     move16();
     175       71463 :     move16();
     176       71463 :     move16();
     177             : 
     178             :     /*---------------------------------------------------------------*
     179             :      * Time Domain Transient Detector
     180             :      *---------------------------------------------------------------*/
     181       71463 :     test();
     182       71463 :     IF( NE_32( ivas_format, MC_FORMAT ) || NE_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) )
     183             :     {
     184       71463 :         RunTransientDetection_ivas_fx( st->input_fx, input_frame, st->hTranDet, q_input );
     185             :     }
     186             : 
     187       71463 :     currFlatness_fx[0] = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS, 0 ); // Q21
     188       71463 :     move32();
     189             : 
     190             :     /*----------------------------------------------------------------*
     191             :      * Configuration of core encoder
     192             :      *----------------------------------------------------------------*/
     193             : 
     194             :     /* Force to MODE1 in IVAS */
     195       71463 :     st->codec_mode = MODE1;
     196       71463 :     move16();
     197             : 
     198             :     /* set "bits_frame_nominal" */
     199       71463 :     test();
     200       71463 :     IF( st_ivas->hQMetaData != NULL && st_ivas->hSpar == NULL )
     201             :     {
     202       27212 :         test();
     203       27212 :         test();
     204       27212 :         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       24725 :             st->bits_frame_nominal = st_ivas->hQMetaData->bits_frame_nominal;
     212       24725 :             move16();
     213             :         }
     214             :     }
     215       44251 :     ELSE IF( st_ivas->hSpar != NULL )
     216             :     {
     217       44251 :         st->bits_frame_nominal = extract_l( Mpy_32_32( st_ivas->hSpar->core_nominal_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) );
     218       44251 :         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       71463 :     st->total_brate = L_sub( hSCE->element_brate, L_mult0( nb_bits_metadata, FRAMES_PER_SEC ) );
     228       71463 :     move32();
     229             : 
     230             :     /* set flag for sampling rate of OL S/M classifier */
     231       71463 :     flag_16k_smc = 0;
     232       71463 :     move16();
     233       71463 :     test();
     234       71463 :     test();
     235       71463 :     test();
     236       71463 :     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       71463 :     set16_fx( old_wsp_fx[0], 0, L_WSP );
     252       71463 :     q_old_wsp = Q15;
     253       71463 :     move16();
     254             : 
     255             :     Word16 q_fr_bands[2];
     256      125887 :     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      125887 :                                     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       71463 :     e_old_wsp[0] = sub( Q15, q_old_wsp );
     267       71463 :     move16();
     268       71463 :     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       71463 :     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       71463 :     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       71463 :     test();
     296       71463 :     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       71463 :     IF( EQ_32( st->core_brate, SID_2k40 ) )
     311             :     {
     312         227 :         ivas_write_format_sid_fx( ivas_format, IVAS_SCE, st->hBstr, st_ivas->hEncoderConfig->sba_order, st_ivas->hEncoderConfig->sba_planar );
     313             :     }
     314             : 
     315             :     /*----------------------------------------------------------------*
     316             :      * Core codec configuration
     317             :      *----------------------------------------------------------------*/
     318             : 
     319             :     /* IGF reconfiguration */
     320       71463 :     test();
     321       71463 :     IF( NE_32( hSCE->last_element_brate, hSCE->element_brate ) || NE_16( st->last_bwidth, st->bwidth ) )
     322             :     {
     323             :         Word16 igf;
     324        1221 :         igf = getIgfPresent_fx( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->max_bwidth, st->rf_mode );
     325        1221 :         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       71463 :     test();
     333       71463 :     test();
     334       71463 :     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       69830 :     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       69830 :         st->flag_ACELP16k = set_ACELP_flag_IVAS( IVAS_SCE, hSCE->element_brate, st->total_brate, 0, 0, -1, -1 );
     345             :     }
     346       71463 :     move16();
     347             : 
     348             :     /* modify the coder_type depending on the total_brate per channel */
     349       71463 :     coder_type_modif_ivas_fx( st, relE_fx[0] );
     350             : 
     351             :     /*----------------------------------------------------------------*
     352             :      * Encoder
     353             :      *----------------------------------------------------------------*/
     354             : 
     355       71463 :     Scale_sig( old_wsp_fx[0], L_WSP, sub( e_old_wsp[0], Q16 ) ); // Q(15-16)
     356       71463 :     e_old_wsp[0] = 16;
     357       71463 :     move16();
     358       71463 :     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       71463 :     Copy( st->input_fx, st->old_input_signal_fx, input_frame );
     369       71463 :     st->q_old_inp = st->q_inp;
     370       71463 :     move16();
     371       71463 :     Copy32( st->input32_fx, st->old_input_signal32_fx, input_frame ); /* st->q_inp32 */
     372       71463 :     st->q_old_inp32 = st->q_inp32;
     373       71463 :     move16();
     374       71463 :     hSCE->last_element_brate = hSCE->element_brate;
     375       71463 :     move32();
     376             : 
     377             :     /* Store previous attack detection flag */
     378       71463 :     st->hTranDet->transientDetector.prev_bIsAttackPresent = st->hTranDet->transientDetector.bIsAttackPresent;
     379       71463 :     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       71463 :     pop_wmops();
     390             : 
     391       71463 :     return error;
     392             : }
     393             : 
     394             : /*-------------------------------------------------------------------------
     395             :  * create_sce_enc()
     396             :  *
     397             :  * Create, allocate and initialize IVAS encoder SCE handle
     398             :  *-------------------------------------------------------------------------*/
     399        3004 : 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        3004 :     error = IVAS_ERR_OK;
     411        3004 :     move32();
     412             : 
     413             :     /*-----------------------------------------------------------------*
     414             :      * Allocate SCE handle
     415             :      *-----------------------------------------------------------------*/
     416             : 
     417        3004 :     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        3004 :     hSCE->sce_id = sce_id;
     427        3004 :     hSCE->element_brate = element_brate;
     428        3004 :     hSCE->last_element_brate = hSCE->element_brate;
     429        3004 :     move16();
     430        3004 :     move32();
     431        3004 :     move32();
     432             : 
     433             :     /*-----------------------------------------------------------------*
     434             :      * Metadata: allocate and initialize
     435             :      *-----------------------------------------------------------------*/
     436        3004 :     test();
     437        3004 :     IF( NE_16( st_ivas->hEncoderConfig->ivas_format, MONO_FORMAT ) && EQ_16( sce_id, sub( st_ivas->nSCE, 1 ) ) )
     438             :     {
     439        1963 :         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        3004 :     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        3004 :     copy_encoder_config_fx( st_ivas, st, 1 );
     459             : 
     460        3004 :     test();
     461        3004 :     test();
     462        3004 :     test();
     463        3004 :     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        3004 :     st->total_brate = hSCE->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
     470        3004 :     st->mct_chan_mode = MCT_CHAN_MODE_REGULAR;
     471        3004 :     move32();
     472        3004 :     move32();
     473        3004 :     st->max_bwidth = st_ivas->hEncoderConfig->max_bwidth;
     474        3004 :     st->input_Fs = st_ivas->hEncoderConfig->input_Fs;
     475        3004 :     st->input_frame_fx = extract_l( Mult_32_16( st->input_Fs, 0x0290 ) );
     476             : 
     477        3004 :     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        3004 :     hSCE->hCoreCoder[0] = st;
     482             : 
     483        3004 :     st_ivas->hSCE[sce_id] = hSCE;
     484             : 
     485        3004 :     return error;
     486             : }
     487             : 
     488             : /*-------------------------------------------------------------------------
     489             :  * create_evs_sce_enc_fx()
     490             :  *
     491             :  * Create, allocate and initialize EVS encoder SCE handle
     492             :  *-------------------------------------------------------------------------*/
     493           3 : ivas_error create_evs_sce_enc_fx(
     494             :     Encoder_Struct *st_ivas,   /* i/o: IVAS encoder structure      */
     495             :     const Word16 sce_id,       /* i  : SCE # identifier            */
     496             :     const Word32 element_brate /* i  : element bitrate             */
     497             : )
     498             : {
     499           3 :     SCE_ENC_HANDLE hSCE = st_ivas->hSCE[sce_id];
     500             :     Encoder_State *st_fx;
     501             : 
     502             :     ivas_error error;
     503             : 
     504           3 :     error = IVAS_ERR_OK;
     505           3 :     move32();
     506             : 
     507             :     /*-----------------------------------------------------------------*
     508             :      * Allocate SCE handle
     509             :      *-----------------------------------------------------------------*/
     510             : 
     511           3 :     IF( ( hSCE = (SCE_ENC_HANDLE) malloc( sizeof( SCE_ENC_DATA ) ) ) == NULL )
     512             :     {
     513           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SCE\n" ) );
     514             :     }
     515             : 
     516             :     /*-----------------------------------------------------------------*
     517             :      * Initialization - general parameters
     518             :      *-----------------------------------------------------------------*/
     519             : 
     520           3 :     hSCE->sce_id = sce_id;
     521           3 :     move16();
     522           3 :     hSCE->element_brate = element_brate;
     523           3 :     move32();
     524           3 :     hSCE->last_element_brate = hSCE->element_brate;
     525           3 :     move32();
     526             :     /*-----------------------------------------------------------------*
     527             :      * Metadata: allocate and initialize
     528             :      *-----------------------------------------------------------------*/
     529           3 :     test();
     530           3 :     IF( NE_32( st_ivas->hEncoderConfig->ivas_format, MONO_FORMAT ) && EQ_16( sce_id, sub( st_ivas->nSCE, 1 ) ) )
     531             :     {
     532           0 :         IF( NE_32( ( error = ivas_initialize_MD_bstr_enc_fx( &( hSCE->hMetaData ), st_ivas ) ), IVAS_ERR_OK ) )
     533             :         {
     534           0 :             return error;
     535             :         }
     536             :     }
     537             :     ELSE
     538             :     {
     539           3 :         hSCE->hMetaData = NULL;
     540             :     }
     541             : 
     542             :     /*-----------------------------------------------------------------*
     543             :      * Core Coder, 1 instance: allocate and initialize
     544             :      *-----------------------------------------------------------------*/
     545           3 :     IF( ( st_fx = (ENC_CORE_HANDLE) malloc( sizeof( Encoder_State ) ) ) == NULL )
     546             :     {
     547           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n" ) );
     548             :     }
     549           3 :     memset( st_fx, 0, sizeof( Encoder_State ) );
     550             : 
     551           3 :     copy_encoder_config_fx( st_ivas, st_fx, 1 );
     552             : 
     553           3 :     st_fx->bitstreamformat = G192;
     554           3 :     move16();
     555             : 
     556           3 :     st_fx->total_brate = st_ivas->hEncoderConfig->ivas_total_brate;
     557           3 :     move32();
     558             : 
     559           3 :     st_fx->input_frame_fx = extract_l( Mult_32_16( st_fx->input_Fs, 0x0290 ) );
     560           3 :     move16();
     561             : 
     562           3 :     IF( NE_32( ( error = init_encoder_fx( st_fx, st_ivas->hEncoderConfig->var_SID_rate_flag, st_ivas->hEncoderConfig->interval_SID ) ), IVAS_ERR_OK ) )
     563             :     {
     564           0 :         return error;
     565             :     }
     566             : 
     567             :     /*-----------------------------------------------------------------*
     568             :      * Bitstream
     569             :      *-----------------------------------------------------------------*/
     570             : 
     571             :     /* set pointer to the buffer of indices */
     572           3 :     st_fx->hBstr->ind_list = st_ivas->ind_list;
     573           3 :     st_fx->hBstr->ivas_ind_list_zero = &st_ivas->ind_list;
     574           3 :     st_fx->hBstr->ivas_max_num_indices = &st_ivas->ivas_max_num_indices;
     575           3 :     st_fx->hBstr->nb_ind_tot = 0;
     576           3 :     move16();
     577           3 :     st_fx->hBstr->nb_bits_tot = 0;
     578           3 :     move16();
     579           3 :     st_fx->hBstr->st_ivas = st_ivas;
     580             : 
     581           3 :     hSCE->hCoreCoder[0] = st_fx;
     582             : 
     583           3 :     st_ivas->hSCE[sce_id] = hSCE;
     584             : 
     585           3 :     return error;
     586             : }
     587             : 
     588             : /*-------------------------------------------------------------------------
     589             :  * destroy_sce_enc_fx()
     590             :  *
     591             :  * Destroy and deallocate IVAS encoder SCE handle
     592             :  *-------------------------------------------------------------------------*/
     593             : 
     594        3007 : void destroy_sce_enc_fx(
     595             :     SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure       */
     596             :     Flag is_evs          /* i  : Flag to indicate EVS encoder*/
     597             : )
     598             : {
     599             :     Encoder_State *st;
     600             : 
     601        3007 :     st = hSCE->hCoreCoder[0];
     602             : 
     603        3007 :     IF( st != NULL )
     604             :     {
     605        3007 :         test();
     606        3007 :         IF( ( st->element_mode == EVS_MONO ) && is_evs )
     607             :         {
     608           3 :             destroy_evs_core_enc_fx( st );
     609           3 :             st = NULL;
     610             :         }
     611             :         ELSE
     612             :         {
     613        3004 :             destroy_core_enc_fx( st );
     614        3004 :             st = NULL;
     615             :         }
     616             :     }
     617             : 
     618        3007 :     ivas_destroy_MD_bstr_enc_fx( &( hSCE->hMetaData ) );
     619             : 
     620        3007 :     free( hSCE );
     621             : 
     622        3007 :     return;
     623             : }

Generated by: LCOV version 1.14