From cbf9e004976062690decc76dc595aa487799d743 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 8 Sep 2025 19:30:42 +0200 Subject: [PATCH 01/15] CLDFB memory harmonization --- lib_com/cldfb_evs_fx.c | 176 +++++----- lib_com/cldfb_fx.c | 426 +++-------------------- lib_com/prot_fx.h | 91 +++-- lib_com/rom_com.c | 11 - lib_com/rom_com.h | 2 +- lib_com/stat_com.h | 17 +- lib_dec/acelp_core_dec_fx.c | 5 +- lib_dec/amr_wb_dec_fx.c | 6 +- lib_dec/dec_acelp_tcx_main_fx.c | 7 +- lib_dec/evs_dec_fx.c | 6 +- lib_dec/init_dec_fx.c | 106 +++--- lib_dec/ivas_corecoder_dec_reconfig_fx.c | 6 +- lib_dec/ivas_init_dec_fx.c | 13 +- lib_dec/ivas_stereo_switching_dec_fx.c | 4 +- lib_dec/lib_dec_fx.c | 4 +- lib_enc/amr_wb_enc_fx.c | 2 +- lib_enc/evs_enc_fx.c | 2 +- lib_enc/init_enc_fx.c | 34 +- lib_enc/ivas_init_enc_fx.c | 3 +- lib_enc/ivas_masa_enc_fx.c | 2 +- lib_enc/ivas_omasa_enc_fx.c | 2 +- lib_enc/ivas_sce_enc_fx.c | 4 - lib_enc/ivas_stereo_switching_enc_fx.c | 8 +- lib_enc/ivas_stereo_td_enc_fx.c | 4 +- lib_enc/lib_enc_fx.c | 2 - lib_enc/prot_fx_enc.h | 4 - lib_enc/stat_enc.h | 1 - lib_isar/isar_splitRendererPost.c | 6 +- lib_isar/isar_splitRendererPre.c | 2 +- lib_isar/lib_isar_pre_rend.c | 4 +- lib_rend/ivas_dirac_ana_fx.c | 2 +- lib_rend/ivas_masa_merge_fx.c | 2 +- lib_rend/ivas_mcmasa_ana_fx.c | 2 +- lib_rend/ivas_omasa_ana_fx.c | 2 +- lib_rend/lib_rend_fx.c | 10 +- 35 files changed, 293 insertions(+), 685 deletions(-) diff --git a/lib_com/cldfb_evs_fx.c b/lib_com/cldfb_evs_fx.c index 153f95cf9..609caf5ac 100644 --- a/lib_com/cldfb_evs_fx.c +++ b/lib_com/cldfb_evs_fx.c @@ -48,8 +48,9 @@ #define N40 ( 20 ) #define N60 ( 30 ) -static void -cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ); +static Word16 CLDFB_getNumChannels( const Word32 sampleRate ); + +static void cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ); #define cplxMpyS( yr, yi, xr, xi, cr, ci, syr, syi, sxr, sxi, CL_x, CL_z, C_c ) \ CL_x = CL_form( *xr, *xi ); \ @@ -722,7 +723,7 @@ void cldfbSynthesis_fx( scaleLB = limitScale32( sub( scale, scaleFactor->lb_scale ) ); scaleHB = limitScale32( sub( scale, scaleFactor->hb_scale ) ); - outScale = cldfbBank->synFilterHeadroom; + outScale = SYN_FILTER_HEADROOM_2_5MS; move16(); scaleMod = sub( add( scale, cldfbBank->outScalefactor ), outScale ); @@ -811,7 +812,6 @@ void cldfbSynthesis_fx( &iBuffer[0], &iBuffer[1], &iAnalysisS[0], &iAnalysisS[m - 1], 2, 2, 2, -2, rRotVctr, iRotVctr, m ); - /* FFT of DST IV */ scale = 0; move16(); @@ -909,25 +909,29 @@ void cldfbSynthesis_fx( /* move filter states */ Copy( &cldfbBank->FilterStates[nTimeSlots * L2], cldfbBank->FilterStates, statesSizeM2 ); set16_fx( &cldfbBank->FilterStates[statesSizeM2], 0, L2 ); + + return; } /*-------------------------------------------------------------------* - * configureClfdb() + * configureCldfb() * * configures a CLDFB handle *--------------------------------------------------------------------*/ -void configureCldfb( HANDLE_CLDFB_FILTER_BANK h_cldfb, /*!< Returns handle */ - const Word16 no_channels, /*!< Number of channels (bands) */ - const Word16 frameSize /*!< FrameSize */ +void configureCldfb( + HANDLE_CLDFB_FILTER_BANK h_cldfb, /*!< Returns handle */ + const Word32 sampling_rate /* i : sampling rate */ ) { + Word16 no_channels; + no_channels = CLDFB_getNumChannels( sampling_rate ); - h_cldfb->no_channels = no_channels; + h_cldfb->no_channels = extract_l( Mpy_32_32_r( sampling_rate, INV_CLDFB_BANDWIDTH_Q31 ) ); move16(); assert( h_cldfb->no_channels >= 10 ); - h_cldfb->no_col = div_l( frameSize, shr( h_cldfb->no_channels, 1 ) ); + h_cldfb->no_col = CLDFB_NO_COL_MAX; move16(); /* was cldfbInitFilterBank()*/ @@ -937,8 +941,6 @@ void configureCldfb( HANDLE_CLDFB_FILTER_BANK h_cldfb, /*!< Returns handle */ move16(); h_cldfb->bandsToZero = 0; move16(); - h_cldfb->filtermode = 0; - move16(); h_cldfb->memory = 0; move16(); h_cldfb->memory_length = 0; @@ -954,14 +956,13 @@ void configureCldfb( HANDLE_CLDFB_FILTER_BANK h_cldfb, /*!< Returns handle */ h_cldfb->zeros = 0; move16(); - h_cldfb->synFilterHeadroom = SYN_FILTER_HEADROOM_2_5MS; - move16(); cldfb_init_proto_and_twiddles( h_cldfb ); + /* the following is related to the EVS implentation only */ h_cldfb->lsb = no_channels; move16(); - h_cldfb->usb = s_min( no_channels, h_cldfb->no_channels ); /* Does this make any sense? in the previous implemenatation lsb, usb and no_channels are all maxCldfbBands */ + h_cldfb->usb = s_min( no_channels, h_cldfb->no_channels ); move16(); h_cldfb->FilterStates = (void *) h_cldfb->FilterStates; @@ -971,19 +972,23 @@ void configureCldfb( HANDLE_CLDFB_FILTER_BANK h_cldfb, /*!< Returns handle */ return; } + /*-------------------------------------------------------------------* * openClfdb() * * open and configures a CLDFB handle *--------------------------------------------------------------------*/ + ivas_error openCldfb( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /*!< Returns handle */ const Word16 type, /*!< analysis or synthesis */ - const Word16 maxCldfbBands, /*!< number of cldfb bands */ - const Word16 frameSize /*!< FrameSize */ + const Word32 sampling_rate /* i : sampling rate */ ) { HANDLE_CLDFB_FILTER_BANK hs; + Word16 buf_len, maxCldfbBands; + + maxCldfbBands = CLDFB_getNumChannels( sampling_rate ); hs = (HANDLE_CLDFB_FILTER_BANK) malloc( sizeof( CLDFB_FILTER_BANK ) ); IF( hs == NULL ) @@ -994,23 +999,31 @@ ivas_error openCldfb( hs->type = type; move16(); + configureCldfb( hs, sampling_rate ); + IF( type == CLDFB_ANALYSIS ) { - hs->FilterStates = (Word16 *) malloc( STATE_BUFFER_SIZE * maxCldfbBands * sizeof( Word16 ) ); + //buf_len = sub( hs->p_filter_length, hs->no_channels ); + buf_len = STATE_BUFFER_SIZE * maxCldfbBands; } ELSE { - hs->FilterStates = (Word16 *) malloc( 2 * STATE_BUFFER_SIZE * maxCldfbBands * sizeof( Word16 ) ); + //buf_len = hs->p_filter_length; + buf_len = 2 * STATE_BUFFER_SIZE * maxCldfbBands; + move16(); } - if ( hs->FilterStates == NULL ) + + IF( ( hs->FilterStates = (Word16 *) malloc( buf_len * sizeof( Word16 ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); } + hs->flags = s_and( hs->flags, ~CLDFB_FLAG_KEEP_STATES ); move16(); - configureCldfb( hs, maxCldfbBands, frameSize ); hs->memory = NULL; + hs->memory32 = NULL; + hs->cldfb_state_fx = NULL; hs->memory_length = 0; move16(); @@ -1019,7 +1032,7 @@ ivas_error openCldfb( test(); IF( ( s_and( hs->flags, CLDFB_FLAG_KEEP_STATES ) == 0 ) && ( hs->FilterStates != 0 ) ) { - set16_fx( hs->FilterStates, 0, i_mult( STATE_BUFFER_SIZE, hs->no_channels ) ); + set16_fx( hs->FilterStates, 0, buf_len ); set16_fx( hs->FilterStates_e, 0, sizeof( hs->FilterStates_e ) / sizeof( hs->FilterStates_e[0] ) ); hs->FilterStates_eg = 0; @@ -1032,7 +1045,7 @@ ivas_error openCldfb( { IF( s_and( hs->flags, CLDFB_FLAG_KEEP_STATES ) == 0 ) { - set16_fx( hs->FilterStates, 0, i_mult( shl( STATE_BUFFER_SIZE, 1 ), hs->no_channels ) ); + set16_fx( hs->FilterStates, 0, buf_len ); } } hs->FilterStates_eg = 0; @@ -1053,10 +1066,12 @@ ivas_error openCldfb( * * Change sample rate of filter bank *--------------------------------------------------------------------*/ -void resampleCldfb( HANDLE_CLDFB_FILTER_BANK hs, - const Word16 newCldfbBands, - const Word16 frameSize, - const Word8 firstFrame ) + +void resampleCldfb( + HANDLE_CLDFB_FILTER_BANK hs, + const Word32 sampling_rate, /* i : sampling rate */ + const Word16 frameSize, + const Word8 firstFrame ) { Word16 timeOffset; @@ -1072,7 +1087,7 @@ void resampleCldfb( HANDLE_CLDFB_FILTER_BANK hs, move16(); /* new settings */ - configureCldfb( hs, newCldfbBands, frameSize ); + configureCldfb( hs, sampling_rate ); /* resample cldfb state buffer */ timeOffset = sub( sub( hs->p_filter_length, hs->no_channels ), hs->zeros ); @@ -1104,20 +1119,20 @@ void resampleCldfb( HANDLE_CLDFB_FILTER_BANK hs, Returns: headroom */ -Word16 -AnalysisPostSpectrumScaling_Fx( HANDLE_CLDFB_FILTER_BANK cldfbBank, /*!< Handle of cldfbBank */ - Word32 **rSubband32, /*!< Real bands Q(cldfbSacle)*/ - Word32 **iSubband32, /*!< Imaginary bands Q(cldfbSacle)*/ - Word16 **rSubband16, /*!< Real bands Q(cldfbSacle)*/ - Word16 **iSubband16, /*!< Imaginary bands Q(cldfbScale)*/ - Word16 *cldfbScale /*!< CLDFB lowband scalefactor */ + +Word16 AnalysisPostSpectrumScaling_Fx( + HANDLE_CLDFB_FILTER_BANK cldfbBank, /*!< Handle of cldfbBank */ + Word32 **rSubband32, /*!< Real bands Q(cldfbSacle)*/ + Word32 **iSubband32, /*!< Imaginary bands Q(cldfbSacle)*/ + Word16 **rSubband16, /*!< Real bands Q(cldfbSacle)*/ + Word16 **iSubband16, /*!< Imaginary bands Q(cldfbScale)*/ + Word16 *cldfbScale /*!< CLDFB lowband scalefactor */ ) { Word16 i; Word16 j; Word16 headRoom; - headRoom = BASOP_util_norm_l_dim2_cplx( (const Word32 *const *) rSubband32, (const Word32 *const *) iSubband32, @@ -1215,19 +1230,21 @@ void analysisCldfbEncoder_fx( return; } -void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) | pointer to the result in the core look-ahead slot */ - Word16 *sf_energyLookahead, /*!< o: pointer to the scalefactor of the result in the core look-ahead slot */ - const Word16 numLookahead, /*!< i: Q0 the number of look-ahead time-slots */ - Word16 **realValues, /*!< i: Q(sf_Values) | the real part of the CLDFB subsamples */ - Word16 **imagValues, /*!< i: Q(sf_Values) | the imaginary part of the CLDFB subsamples */ - Word16 sf_Values, /*!< i: scalefactor of the CLDFB subcamples - apply as a negated Exponent */ - Word16 numberBands, /*!< i: Q0 | number of CLDFB bands */ - Word16 numberCols, /*!< i: Q0 | number of CLDFB subsamples */ - Word32 *energyHF, /*!< o: Q31 | pointer to HF energy */ - Word16 *energyHF_Exp, /*!< o: pointer to exponent of HF energy */ - Word32 *energyValuesSum, /*!< o: Q(2*sf_Values-4) | pointer to sum array of energy values, not initialized*/ - Word16 *energyValuesSum_Exp, /*!< o: pointer to exponents of energyValuesSum, not initialized */ - TEC_ENC_HANDLE hTecEnc ) + +void GetEnergyCldfb( + Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) | pointer to the result in the core look-ahead slot */ + Word16 *sf_energyLookahead, /*!< o: pointer to the scalefactor of the result in the core look-ahead slot */ + const Word16 numLookahead, /*!< i: Q0 the number of look-ahead time-slots */ + Word16 **realValues, /*!< i: Q(sf_Values) | the real part of the CLDFB subsamples */ + Word16 **imagValues, /*!< i: Q(sf_Values) | the imaginary part of the CLDFB subsamples */ + Word16 sf_Values, /*!< i: scalefactor of the CLDFB subcamples - apply as a negated Exponent */ + Word16 numberBands, /*!< i: Q0 | number of CLDFB bands */ + Word16 numberCols, /*!< i: Q0 | number of CLDFB subsamples */ + Word32 *energyHF, /*!< o: Q31 | pointer to HF energy */ + Word16 *energyHF_Exp, /*!< o: pointer to exponent of HF energy */ + Word32 *energyValuesSum, /*!< o: Q(2*sf_Values-4) | pointer to sum array of energy values, not initialized*/ + Word16 *energyValuesSum_Exp, /*!< o: pointer to exponents of energyValuesSum, not initialized */ + TEC_ENC_HANDLE hTecEnc ) { Word16 j; Word16 k; @@ -1388,14 +1405,12 @@ void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) } -Word16 -CLDFB_getNumChannels( Word32 sampleRate ) +static Word16 CLDFB_getNumChannels( + const Word32 sampleRate ) { - Word16 nChannels = 0; move16(); - SWITCH( sampleRate ) { case 48000: @@ -1427,13 +1442,15 @@ CLDFB_getNumChannels( Word32 sampleRate ) return ( nChannels ); } + /*-------------------------------------------------------------------* * cldfb_get_memory_length() * * Return length of filter state for recovery *--------------------------------------------------------------------*/ -static Word16 -cldfb_get_memory_length( HANDLE_CLDFB_FILTER_BANK hs ) + +static Word16 cldfb_get_memory_length( + HANDLE_CLDFB_FILTER_BANK hs ) { IF( EQ_16( hs->type, CLDFB_ANALYSIS ) ) { @@ -1445,39 +1462,21 @@ cldfb_get_memory_length( HANDLE_CLDFB_FILTER_BANK hs ) } } -/*-------------------------------------------------------------------* - * GetEnergyCldfb() - * - * Remove handle - *--------------------------------------------------------------------*/ -void deleteCldfb( HANDLE_CLDFB_FILTER_BANK *h_cldfb ) /* i: cldfb handle */ -{ - IF( *h_cldfb != NULL ) - { - IF( ( *h_cldfb )->FilterStates != NULL ) - { - free( ( *h_cldfb )->FilterStates ); - } - free( *h_cldfb ); - } - *h_cldfb = NULL; -} - /*-------------------------------------------------------------------* * cldfb_init_proto_and_twiddles() * * Initializes rom pointer *--------------------------------------------------------------------*/ -static void -cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle */ -{ +static void cldfb_init_proto_and_twiddles( + HANDLE_CLDFB_FILTER_BANK hs /* i: cldfb handle */ +) +{ /*find appropriate set of rotVecs*/ SWITCH( hs->no_channels ) { case 10: - hs->rRotVctr = rRotVectr_10; hs->iRotVctr = iRotVectr_10; hs->synGain = cldfb_synGain[0]; @@ -1585,6 +1584,8 @@ cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle } BREAK; } + + return; } @@ -1595,8 +1596,10 @@ cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle * * Save the memory of filter; to be restored with cldfb_restore_memory() *--------------------------------------------------------------------*/ -ivas_error -cldfb_save_memory( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle */ + +ivas_error cldfb_save_memory( + HANDLE_CLDFB_FILTER_BANK hs /* i: cldfb handle */ +) { test(); IF( hs->memory != NULL || hs->memory_length != 0 ) @@ -1617,6 +1620,7 @@ cldfb_save_memory( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle */ { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CLDFB\n" ); } + return IVAS_ERR_OK; } @@ -1626,12 +1630,14 @@ cldfb_save_memory( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle */ * * Restores the memory of filter; memory to be save by cldfb_save_memory() *--------------------------------------------------------------------*/ -void cldfb_restore_memory( HANDLE_CLDFB_FILTER_BANK hs ) /* i/o: cldfb handle */ + +void cldfb_restore_memory( + HANDLE_CLDFB_FILTER_BANK hs /* i/o: cldfb handle */ +) { Word16 size; - size = cldfb_get_memory_length( hs ); /* read the memory */ @@ -1640,7 +1646,6 @@ void cldfb_restore_memory( HANDLE_CLDFB_FILTER_BANK hs ) /* i/o: cldfb handle */ hs->FilterStates_eg = hs->memory[hs->memory_length + CLDFB_MEM_EXPONENTS]; move16(); - /* adjust sample rate if it was changed in the meanwhile */ IF( NE_16( hs->memory_length, size ) ) { @@ -1654,12 +1659,16 @@ void cldfb_restore_memory( HANDLE_CLDFB_FILTER_BANK hs ) /* i/o: cldfb handle */ return; } + /*-------------------------------------------------------------------* * cldfb_reset_memory() * * Resets the memory of filter. *--------------------------------------------------------------------*/ -void cldfb_reset_memory( HANDLE_CLDFB_FILTER_BANK hs ) /* i/o: cldfb handle */ + +void cldfb_reset_memory( + HANDLE_CLDFB_FILTER_BANK hs /* i/o: cldfb handle */ +) { Word16 length; @@ -1669,5 +1678,6 @@ void cldfb_reset_memory( HANDLE_CLDFB_FILTER_BANK hs ) /* i/o: cldfb handle */ set16_fx( hs->FilterStates_e, 0, sizeof( hs->FilterStates_e ) / sizeof( hs->FilterStates_e[0] ) ); hs->FilterStates_eg = 0; move16(); + return; } diff --git a/lib_com/cldfb_fx.c b/lib_com/cldfb_fx.c index f0a4e61cf..a30ab3ae6 100644 --- a/lib_com/cldfb_fx.c +++ b/lib_com/cldfb_fx.c @@ -57,8 +57,6 @@ static void cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ); -static void cldfb_init_proto_and_twiddles_enc_fx( HANDLE_CLDFB_FILTER_BANK hs ); - static void GetEnergyCldfb_ivas_fx( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) | pointer to the result in the core look-ahead slot */ Word16 *sf_energyLookahead, /*!< o: pointer to the scalefactor of the result in the core look-ahead slot */ const Word16 numLookahead, /*!< i: Q0 the number of look-ahead time-slots */ @@ -73,17 +71,13 @@ static void GetEnergyCldfb_ivas_fx( Word32 *energyLookahead, /*!< o: Q(*sf_e Word16 *energyValuesSum_Exp, /*!< o: pointer to exponents of energyValuesSum, not initialized */ TEC_ENC_HANDLE hTecEnc ); -/*-------------------------------------------------------------------* - * cplxMult() - * - * Conduct complex multiplication - *--------------------------------------------------------------------*/ /*-------------------------------------------------------------------* * cldfbAnalysis_ivas() * * Conduct multiple overlap complex low delay MDCT *--------------------------------------------------------------------*/ + void cldfbAnalysis_ivas_fx( const Word32 *timeIn_fx, /* i : time buffer Qx */ Word32 **realBuffer_fx, /* o : real value buffer Qx - 5*/ @@ -1334,38 +1328,22 @@ void cldfbSynthesis_ivas_fx( return; } -void configureCldfb_ivas_enc_fx( - HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i/o: filter bank handle */ - const Word32 sampling_rate /* i : sampling rate */ -) -{ - h_cldfb->no_col = CLDFB_NO_COL_MAX; - h_cldfb->bandsToZero = 0; - h_cldfb->nab = 0; - - h_cldfb->no_channels = extract_l( Mpy_32_32_r( sampling_rate, INV_CLDFB_BANDWIDTH_Q31 ) ); - h_cldfb->p_filter_length = i_mult( 10, h_cldfb->no_channels ); - h_cldfb->zeros = 0; - h_cldfb->anaScalefactor = 0; - h_cldfb->synScalefactor = 0; - h_cldfb->filterScale = 1; - cldfb_init_proto_and_twiddles_enc_fx( h_cldfb ); +/*-------------------------------------------------------------------* + * configureCldfb() + * + * configures a CLDFB handle + *--------------------------------------------------------------------*/ - return; -} void configureCldfb_ivas_fx( HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i/o: filter bank handle */ const Word32 sampling_rate /* i : sampling rate */ ) { - h_cldfb->no_col = CLDFB_NO_COL_MAX; move16(); h_cldfb->bandsToZero = 0; move16(); - h_cldfb->nab = 0; - move16(); // h_cldfb->no_channels = (int16_t) ( sampling_rate * INV_CLDFB_BANDWIDTH + 0.5f ); h_cldfb->no_channels = extract_l( Mpy_32_32_r( sampling_rate, INV_CLDFB_BANDWIDTH_Q31 ) ); @@ -1376,6 +1354,8 @@ void configureCldfb_ivas_fx( move16(); h_cldfb->synScalefactor = 0; move16(); + h_cldfb->filterScale = 1; + move16(); h_cldfb->p_filter_length = i_mult( 10, h_cldfb->no_channels ); move16(); @@ -1383,17 +1363,20 @@ void configureCldfb_ivas_fx( return; } + + /*-------------------------------------------------------------------* * openClfdb() * * open and configures a CLDFB handle *--------------------------------------------------------------------*/ + ivas_error openCldfb_ivas_fx( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */ CLDFB_TYPE type, /* i : analysis or synthesis */ const Word32 sampling_rate, /* i : sampling rate */ CLDFB_PROTOTYPE prototype, /* i : CLDFB version (1.25ms/5ms delay) */ - const Word16 enc_dec ) /* i : encoder/decoder flag */ + const Word16 enc_dec ) /* i : encoder/decoder flag */ { HANDLE_CLDFB_FILTER_BANK hs; Word16 buf_len; @@ -1407,17 +1390,19 @@ ivas_error openCldfb_ivas_fx( move32(); hs->prototype = prototype; move32(); + + configureCldfb_ivas_fx( hs, sampling_rate ); + IF( enc_dec == ENC ) { - configureCldfb_ivas_enc_fx( hs, sampling_rate ); hs->Q_cldfb_state = 0; } ELSE { - configureCldfb_ivas_fx( hs, sampling_rate ); hs->Q_cldfb_state = Q11; } move16(); + hs->memory32 = NULL; hs->FilterStates = NULL; hs->memory_length = 0; @@ -1450,11 +1435,13 @@ ivas_error openCldfb_ivas_fx( return IVAS_ERR_OK; } + /*-------------------------------------------------------------------* * resampleCldfb_ivas() * * Change sample rate of filter bank *--------------------------------------------------------------------*/ + void resampleCldfb_ivas_fx( HANDLE_CLDFB_FILTER_BANK hs, /* i/o: filter bank handle */ const Word32 newSamplerate ) @@ -1475,19 +1462,21 @@ void resampleCldfb_ivas_fx( return; } -static void GetEnergyCldfb_ivas_fx( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) | pointer to the result in the core look-ahead slot */ - Word16 *sf_energyLookahead, /*!< o: pointer to the scalefactor of the result in the core look-ahead slot */ - const Word16 numLookahead, /*!< i: Q0 the number of look-ahead time-slots */ - Word16 **realValues, /*!< i: Q(sf_Values) | the real part of the CLDFB subsamples */ - Word16 **imagValues, /*!< i: Q(sf_Values) | the imaginary part of the CLDFB subsamples */ - Word16 sf_Values, /*!< i: scalefactor of the CLDFB subcamples - apply as a negated Exponent */ - Word16 numberBands, /*!< i: Q0 | number of CLDFB bands */ - Word16 numberCols, /*!< i: Q0 | number of CLDFB subsamples */ - Word32 *energyHF, /*!< o: Q31 | pointer to HF energy */ - Word16 *energyHF_Exp, /*!< o: pointer to exponent of HF energy */ - Word32 *energyValuesSum, /*!< o: Q(2*sf_Values-4) | pointer to sum array of energy values, not initialized*/ - Word16 *energyValuesSum_Exp, /*!< o: pointer to exponents of energyValuesSum, not initialized */ - TEC_ENC_HANDLE hTecEnc ) + +static void GetEnergyCldfb_ivas_fx( + Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) | pointer to the result in the core look-ahead slot */ + Word16 *sf_energyLookahead, /*!< o: pointer to the scalefactor of the result in the core look-ahead slot */ + const Word16 numLookahead, /*!< i: Q0 the number of look-ahead time-slots */ + Word16 **realValues, /*!< i: Q(sf_Values) | the real part of the CLDFB subsamples */ + Word16 **imagValues, /*!< i: Q(sf_Values) | the imaginary part of the CLDFB subsamples */ + Word16 sf_Values, /*!< i: scalefactor of the CLDFB subcamples - apply as a negated Exponent */ + Word16 numberBands, /*!< i: Q0 | number of CLDFB bands */ + Word16 numberCols, /*!< i: Q0 | number of CLDFB subsamples */ + Word32 *energyHF, /*!< o: Q31 | pointer to HF energy */ + Word16 *energyHF_Exp, /*!< o: pointer to exponent of HF energy */ + Word32 *energyValuesSum, /*!< o: Q(2*sf_Values-4) | pointer to sum array of energy values, not initialized*/ + Word16 *energyValuesSum_Exp, /*!< o: pointer to exponents of energyValuesSum, not initialized */ + TEC_ENC_HANDLE hTecEnc ) { Word16 j; Word16 k; @@ -1713,7 +1702,14 @@ void analysisCldfbEncoder_ivas_fx( return; } -void deleteCldfb_ivas_fx( + +/*-------------------------------------------------------------------* + * deleteCldfb() + * + * Remove and deallcoate handle + *--------------------------------------------------------------------*/ + +void deleteCldfb_fx( HANDLE_CLDFB_FILTER_BANK *h_cldfb /* i/o: filter bank handle */ ) { @@ -1966,351 +1962,13 @@ static void cldfb_init_proto_and_twiddles( return; } -static void cldfb_init_proto_and_twiddles_enc_fx( - HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ -) -{ - /*find appropriate set of rotVecs*/ - SWITCH( hs->no_channels ) - { - case 10: - hs->rot_vec_ana_re_fx = rot_vec_ana_re_L10_fx; - hs->rot_vec_ana_im_fx = rot_vec_ana_im_L10_fx; - hs->rot_vec_syn_re_fx = rot_vec_syn_re_L10_fx; - hs->rot_vec_syn_im_fx = rot_vec_syn_im_L10_fx; - hs->rRotVctr = rRotVectr_10; - hs->iRotVctr = iRotVectr_10; - IF( EQ_16( hs->type, CLDFB_SYNTHESIS ) ) - { - hs->synScalefactor = add( cldfb_synScale[0], hs->filterScale ); - move16(); - } - ELSE - { - hs->anaScalefactor = add( cldfb_anaScale[0], hs->filterScale ); - move16(); - } - IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_1_25MS ) ) - { - hs->ds = 10; - hs->da = 10; - move16(); - move16(); - hs->rot_vec_ana_delay_re_fx = NULL; - hs->rot_vec_ana_delay_im_fx = NULL; - hs->rot_vec_syn_delay_re_fx = NULL; - hs->rot_vec_syn_delay_im_fx = NULL; - hs->scale = cldfb_scale_2_5ms[0]; - move16(); - move16(); - hs->p_filter_32 = CLDFB80_10_fx; - } - ELSE IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_5_00MS ) ) - { - hs->ds = 40; - hs->da = -20; - move16(); - move16(); - hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; - hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; - hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->p_filter_32 = LDQMF_10_fx; - hs->scale = cldfb_scale_5_0ms[0]; - move16(); - move16(); - } - BREAK; - - case 16: - hs->rot_vec_ana_re_fx = rot_vec_ana_re_L16_fx; - hs->rot_vec_ana_im_fx = rot_vec_ana_im_L16_fx; - hs->rot_vec_syn_re_fx = rot_vec_syn_re_L16_fx; - hs->rot_vec_syn_im_fx = rot_vec_syn_im_L16_fx; - hs->rRotVctr = rRotVectr_16; - hs->iRotVctr = iRotVectr_16; - { - hs->anaScalefactor = add( cldfb_anaScale[1], hs->filterScale ); - move16(); - } - IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_1_25MS ) ) - { - hs->ds = 20; - hs->da = 20; - move16(); - move16(); - hs->rot_vec_ana_delay_re_fx = NULL; - hs->rot_vec_ana_delay_im_fx = NULL; - hs->rot_vec_syn_delay_re_fx = NULL; - hs->rot_vec_syn_delay_im_fx = NULL; - hs->p_filter_32 = CLDFB80_16_fx; - hs->scale = cldfb_scale_2_5ms[1]; - move16(); - move16(); - } - ELSE IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_5_00MS ) ) - { - hs->ds = 80; - hs->da = -40; - move16(); - move16(); - hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; - hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; - hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->p_filter_32 = LDQMF_16_fx; - hs->scale = cldfb_scale_5_0ms[1]; - move16(); - move16(); - } - BREAK; - - case 20: - hs->rRotVctr = rRotVectr_20; - hs->iRotVctr = iRotVectr_20; - hs->rot_vec_ana_re_fx = rot_vec_ana_re_L20_fx; - hs->rot_vec_ana_im_fx = rot_vec_ana_im_L20_fx; - hs->rot_vec_syn_re_fx = rot_vec_syn_re_L20_fx; - hs->rot_vec_syn_im_fx = rot_vec_syn_im_L20_fx; - IF( EQ_16( hs->type, CLDFB_SYNTHESIS ) ) - { - hs->synScalefactor = add( cldfb_synScale[2], hs->filterScale ); - move16(); - } - ELSE - { - hs->anaScalefactor = add( cldfb_anaScale[2], hs->filterScale ); - move16(); - } - IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_1_25MS ) ) - { - hs->ds = 20; - hs->da = 20; - move16(); - move16(); - hs->rot_vec_ana_delay_re_fx = NULL; - hs->rot_vec_ana_delay_im_fx = NULL; - hs->rot_vec_syn_delay_re_fx = NULL; - hs->rot_vec_syn_delay_im_fx = NULL; - hs->p_filter_32 = CLDFB80_20_fx; - hs->scale = cldfb_scale_2_5ms[2]; - move16(); - move16(); - } - ELSE IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_5_00MS ) ) - { - hs->ds = 80; - hs->da = -40; - move16(); - move16(); - hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; - hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; - hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->p_filter_32 = LDQMF_20_fx; - hs->scale = cldfb_scale_5_0ms[2]; - move16(); - move16(); - } - BREAK; - - case 30: - hs->rot_vec_ana_re_fx = rot_vec_ana_re_L30_fx; - hs->rot_vec_ana_im_fx = rot_vec_ana_im_L30_fx; - hs->rot_vec_syn_re_fx = rot_vec_syn_re_L30_fx; - hs->rot_vec_syn_im_fx = rot_vec_syn_im_L30_fx; - hs->rRotVctr = rRotVectr_30; - hs->iRotVctr = iRotVectr_30; - IF( EQ_16( hs->type, CLDFB_SYNTHESIS ) ) - { - hs->synScalefactor = add( cldfb_synScale[6], hs->filterScale ); - move16(); - } - ELSE - { - hs->anaScalefactor = add( cldfb_anaScale[6], hs->filterScale ); - move16(); - } - IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_1_25MS ) ) - { - hs->ds = 30; - hs->da = 30; - move16(); - move16(); - hs->rot_vec_ana_delay_re_fx = NULL; - hs->rot_vec_ana_delay_im_fx = NULL; - hs->rot_vec_syn_delay_re_fx = NULL; - hs->rot_vec_syn_delay_im_fx = NULL; - hs->scale = cldfb_scale_2_5ms[6]; - hs->p_filter_32 = CLDFB80_30_fx; - } - ELSE IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_5_00MS ) ) - { - hs->ds = 120; - hs->da = -60; - move16(); - move16(); - hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; - hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; - hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->scale = cldfb_scale_5_0ms[6]; - hs->p_filter_32 = LDQMF_30_fx; - move16(); - move16(); - } - BREAK; - - case 32: - hs->rot_vec_ana_re_fx = rot_vec_ana_re_L32_fx; - hs->rot_vec_ana_im_fx = rot_vec_ana_im_L32_fx; - hs->rot_vec_syn_re_fx = rot_vec_syn_re_L32_fx; - hs->rot_vec_syn_im_fx = rot_vec_syn_im_L32_fx; - hs->rRotVctr = rRotVectr_32; - hs->iRotVctr = iRotVectr_32; - { - hs->anaScalefactor = add( cldfb_anaScale[3], hs->filterScale ); - move16(); - } - IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_1_25MS ) ) - { - hs->ds = 32; - hs->da = 32; - move16(); - move16(); - hs->rot_vec_ana_delay_re_fx = NULL; - hs->rot_vec_ana_delay_im_fx = NULL; - hs->rot_vec_syn_delay_re_fx = NULL; - hs->rot_vec_syn_delay_im_fx = NULL; - hs->p_filter_32 = CLDFB80_32_fx; - hs->scale = cldfb_scale_2_5ms[3]; - move16(); - move16(); - } - ELSE IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_5_00MS ) ) - { - hs->ds = 160; - hs->da = -80; - move16(); - move16(); - hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; - hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; - hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->scale = cldfb_scale_5_0ms[3]; - hs->p_filter_32 = LDQMF_32_fx; - move16(); - move16(); - } - BREAK; - - case 40: - hs->rot_vec_ana_re_fx = rot_vec_ana_re_L40_fx; - hs->rot_vec_ana_im_fx = rot_vec_ana_im_L40_fx; - hs->rot_vec_syn_re_fx = rot_vec_syn_re_L40_fx; - hs->rot_vec_syn_im_fx = rot_vec_syn_im_L40_fx; - hs->rRotVctr = rRotVectr_40; - hs->iRotVctr = iRotVectr_40; - IF( EQ_16( hs->type, CLDFB_SYNTHESIS ) ) - { - hs->synScalefactor = add( cldfb_synScale[4], hs->filterScale ); - move16(); - } - ELSE - { - hs->anaScalefactor = add( cldfb_anaScale[4], hs->filterScale ); - move16(); - } - IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_1_25MS ) ) - { - hs->ds = 40; - hs->da = 40; - move16(); - move16(); - hs->rot_vec_ana_delay_re_fx = NULL; - hs->rot_vec_ana_delay_im_fx = NULL; - hs->rot_vec_syn_delay_re_fx = NULL; - hs->rot_vec_syn_delay_im_fx = NULL; - hs->scale = cldfb_scale_2_5ms[4]; - hs->p_filter_32 = CLDFB80_40_fx; - move16(); - move16(); - } - ELSE IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_5_00MS ) ) - { - hs->ds = 160; - hs->da = -80; - move16(); - move16(); - hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; - hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; - hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->p_filter_32 = LDQMF_40_fx; - hs->scale = cldfb_scale_5_0ms[4]; - move16(); - move16(); - } - BREAK; - - case 60: - hs->rot_vec_ana_re_fx = rot_vec_ana_re_L60_fx; - hs->rot_vec_ana_im_fx = rot_vec_ana_im_L60_fx; - hs->rot_vec_syn_re_fx = rot_vec_syn_re_L60_fx; - hs->rot_vec_syn_im_fx = rot_vec_syn_im_L60_fx; - hs->rRotVctr = rRotVectr_60; - hs->iRotVctr = iRotVectr_60; - IF( EQ_16( hs->type, CLDFB_SYNTHESIS ) ) - { - hs->synScalefactor = add( cldfb_synScale[5], hs->filterScale ); - move16(); - } - ELSE - { - hs->anaScalefactor = add( cldfb_anaScale[5], hs->filterScale ); - move16(); - } - IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_1_25MS ) ) - { - hs->ds = 60; - hs->da = 60; - move16(); - move16(); - hs->rot_vec_ana_delay_re_fx = NULL; - hs->rot_vec_ana_delay_im_fx = NULL; - hs->rot_vec_syn_delay_re_fx = NULL; - hs->rot_vec_syn_delay_im_fx = NULL; - hs->p_filter_32 = CLDFB80_60_fx; - hs->scale = cldfb_scale_2_5ms[5]; - move16(); - move16(); - } - ELSE IF( EQ_16( hs->prototype, CLDFB_PROTOTYPE_5_00MS ) ) - { - hs->ds = 240; - hs->da = -120; - move16(); - move16(); - hs->rot_vec_ana_delay_re_fx = rot_vec_delay_re_LDQMF_fx; - hs->rot_vec_ana_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->rot_vec_syn_delay_re_fx = rot_vec_delay_re_LDQMF_fx; - hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; - hs->p_filter_32 = LDQMF_60_fx; - hs->scale = cldfb_scale_5_0ms[5]; - move16(); - move16(); - } - break; - } - - return; -} /*-------------------------------------------------------------------* * cldfb_save_memory_ivas() * * Save the memory of filter; to be restored with cldfb_restore_memory_ivas() *--------------------------------------------------------------------*/ + ivas_error cldfb_save_memory_ivas_fx( HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ ) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index ddd0bfdcc..5eb847ad1 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -4639,28 +4639,30 @@ void cldfbSynthesis_fx( Word32 *pWorkBuffer /*!< pointer to temporal working buffer */ ); -void configureCldfb( HANDLE_CLDFB_FILTER_BANK h_cldfb, /*!< CLDFB Handle */ - const Word16 no_channels, /*!< Number of critically sampled bands */ - const Word16 frameSize /*!< FrameSize */ +void configureCldfb( + HANDLE_CLDFB_FILTER_BANK h_cldfb, /*!< CLDFB Handle */ + const Word32 sampling_rate /* i : sampling rate */ ); -ivas_error openCldfb( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /*!< CLDFB Handle */ - const Word16 type, /*!< analysis or synthesis */ - const Word16 maxCldfbBands, /*!< number of cldfb bands */ - const Word16 frameSize /*!< FrameSize */ +ivas_error openCldfb( + HANDLE_CLDFB_FILTER_BANK *h_cldfb, /*!< CLDFB Handle */ + const Word16 type, /*!< analysis or synthesis */ + const Word32 sampling_rate /* i : sampling rate */ ); + void resampleCldfb( HANDLE_CLDFB_FILTER_BANK hs, /*!< CLDFB Handle */ - const Word16 newCldfbBands, /*!< number of cldfb bands */ + const Word32 sampling_rate, /* i : sampling rate */ const Word16 frameSize, /*!< FrameSize */ const Word8 firstFrame ); -Word16 -AnalysisPostSpectrumScaling_Fx( HANDLE_CLDFB_FILTER_BANK cldfbBank, - Word32 **rSubband32, - Word32 **iSubband32, - Word16 **rSubband16, - Word16 **iSubband16, - Word16 *cldfbScale ); + +Word16 AnalysisPostSpectrumScaling_Fx( + HANDLE_CLDFB_FILTER_BANK cldfbBank, + Word32 **rSubband32, + Word32 **iSubband32, + Word16 **rSubband16, + Word16 **iSubband16, + Word16 *cldfbScale ); void analysisCldfbEncoder_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ @@ -4673,28 +4675,32 @@ void analysisCldfbEncoder_fx( Word16 *enerBuffSum_exp, CLDFB_SCALE_FACTOR *scale ); -void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q31 | pointer to the result in the core look-ahead slot */ - Word16 *sf_energyLookahead, /*!< o: pointer to the scalefactor of the result in the core look-ahead slot - apply as negative exponent*/ - const Word16 numLookahead, /*!< i: Q0 the number of look-ahead time-slots */ - Word16 **realValues, /*!< i: Q15 | the real part of the CLDFB subsamples */ - Word16 **imagValues, /*!< i: Q15 | the imaginary part of the CLDFB subsamples */ - Word16 sf_Values, /*!< i: scalefactor of the CLDFB subcamples - apply as a negated Exponent */ - Word16 numberBands, /*!< i: Q0 | number of CLDFB bands */ - Word16 numberCols, /*!< i: Q0 | number of CLDFB subsamples */ - Word32 *energyHF, /*!< o: Q31 | pointer to HF energy */ - Word16 *energyHF_Exp, /*!< o: pointer to exponent of HF energy */ - Word32 *energyValuesSum, /*!< o: Q31 | pointer to sum array of energy values, not initialized*/ - Word16 *energyValuesSum_Exp, /*!< o: pointer to exponents of energyValuesSum, not initialized */ - TEC_ENC_HANDLE hTECEnc ); +void GetEnergyCldfb( + Word32 *energyLookahead, /*!< o: Q31 | pointer to the result in the core look-ahead slot */ + Word16 *sf_energyLookahead, /*!< o: pointer to the scalefactor of the result in the core look-ahead slot - apply as negative exponent*/ + const Word16 numLookahead, /*!< i: Q0 the number of look-ahead time-slots */ + Word16 **realValues, /*!< i: Q15 | the real part of the CLDFB subsamples */ + Word16 **imagValues, /*!< i: Q15 | the imaginary part of the CLDFB subsamples */ + Word16 sf_Values, /*!< i: scalefactor of the CLDFB subcamples - apply as a negated Exponent */ + Word16 numberBands, /*!< i: Q0 | number of CLDFB bands */ + Word16 numberCols, /*!< i: Q0 | number of CLDFB subsamples */ + Word32 *energyHF, /*!< o: Q31 | pointer to HF energy */ + Word16 *energyHF_Exp, /*!< o: pointer to exponent of HF energy */ + Word32 *energyValuesSum, /*!< o: Q31 | pointer to sum array of energy values, not initialized*/ + Word16 *energyValuesSum_Exp, /*!< o: pointer to exponents of energyValuesSum, not initialized */ + TEC_ENC_HANDLE hTECEnc ); -Word16 -CLDFB_getNumChannels( Word32 sampleRate ); +ivas_error cldfb_save_memory( + HANDLE_CLDFB_FILTER_BANK hs /* i/o: cldfb handle */ +); -void deleteCldfb( HANDLE_CLDFB_FILTER_BANK *h_cldfb ); /*!< CLDFB Handle */ +void cldfb_restore_memory( + HANDLE_CLDFB_FILTER_BANK hs /* i/o: cldfb handle */ +); -ivas_error cldfb_save_memory( HANDLE_CLDFB_FILTER_BANK hs ); /* i/o: cldfb handle */ -void cldfb_restore_memory( HANDLE_CLDFB_FILTER_BANK hs ); /* i/o: cldfb handle */ -void cldfb_reset_memory( HANDLE_CLDFB_FILTER_BANK hs ); /* i/o: cldfb handle */ +void cldfb_reset_memory( + HANDLE_CLDFB_FILTER_BANK hs /* i/o: cldfb handle */ +); // bits_alloc.c from IVAS void BITS_ALLOC_init_config_acelp( @@ -7385,13 +7391,7 @@ void generate_masking_noise_mdct_ivas_fx( Word32 *mdctBuffer, /* i/o: time-dom Word16 *mdctBuffer_e, /* i/o: exponent time-domain signal */ HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing all buffers and variables */ ); -// init_dec_fx.c ivas_error init_decoder_fx( - Decoder_State *st_fx, /* o: Decoder static variables structure */ - const Word16 idchan /* i : channel ID */ -); - -ivas_error init_decoder_ivas_fx( Decoder_State *st_fx, /* o: Decoder static variables structure */ const Word16 idchan, /* i : channel ID */ const MC_MODE mc_mode /* i : MC mode */ @@ -9459,7 +9459,7 @@ Word16 deindex_lvq_ivas_fx( ); -void deleteCldfb_ivas_fx( +void deleteCldfb_fx( HANDLE_CLDFB_FILTER_BANK *h_cldfb /* i/o: filter bank handle */ ); @@ -10246,10 +10246,6 @@ ivas_error acelp_core_dec_fx( const Word16 read_sid_info /* i : read SID info flag */ ); -void destroy_cldfb_decoder_ivas_fx( - Decoder_State *st /* o : Decoder static variables structure */ -); - void wtda_fx32( const Word32 *new_audio, /* i : input audio Q11 */ Word32 *wtda_audio, /* o : windowed audio Q11 */ @@ -10764,11 +10760,6 @@ ivas_error IGF_Reconfig_fx( const Word16 rf_mode /* i : flag to signal the RF mode */ ); -void configureCldfb_ivas_enc_fx( - HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i/o: filter bank handle */ - const Word32 sampling_rate /* i : sampling rate */ -); - void core_switching_post_enc_ivas_fx( Encoder_State *st, /* i/o: encoder state structure */ Word16 *old_inp_12k8_fx, /* i : old input signal @12.8kHz */ diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c index d9cb1919e..4d100280f 100644 --- a/lib_com/rom_com.c +++ b/lib_com/rom_com.c @@ -6776,17 +6776,6 @@ const Word16 cldfb_scale_2_5ms[7] = 22588/*88.234489 Q8*/ /* 30 bands */ }; -const Word16 cldfb_scale_5_0ms[7] = -{ - 21649/*88.293854 Q8*/, /* 10 bands */ - 21649/*88.299622 Q8*/, /* 16 bands */ - 21649/*88.300926 Q8*/, /* 20 bands */ - 21649/*88.303848 Q8*/, /* 32 bands */ - 21649/*88.304718 Q8*/, /* 40 bands */ - 22535/*88.028412 Q8*/, /* 60 bands */ - 21581/*88.028412 Q8*/ /* 30 bands */ -}; - /*Q31*/ const Word32 rot_vec_syn_re_L10_fx[5] = diff --git a/lib_com/rom_com.h b/lib_com/rom_com.h index d91abed59..b99ddbb97 100644 --- a/lib_com/rom_com.h +++ b/lib_com/rom_com.h @@ -1155,7 +1155,7 @@ extern const Word16 cldfb_synGain[]; // Q0 extern const Word16 *cldfb_protoFilter_2_5ms[]; // extern const Word16 *cldfb_protoFilter_5_0ms[]; extern const Word16 cldfb_scale_2_5ms[7]; // Q8 -extern const Word16 cldfb_scale_5_0ms[7]; // Q8 + extern const Word32 rot_vec_syn_re_L10_fx[5]; // Q31 extern const Word32 rot_vec_syn_im_L10_fx[5]; // Q31 diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index c50e99711..992adfb7d 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -627,12 +627,14 @@ typedef struct cldfb_filter_bank_struct const Word32 *rot_vec_syn_delay_re_fx; // Q31 const Word32 *rot_vec_syn_delay_im_fx; // Q31 + /* rotation vectors for delay */ const Word32 *rot_vec_ana_re_fx; // Q29 const Word32 *rot_vec_ana_im_fx; // Q29 const Word32 *rot_vec_ana_delay_re_fx; // Q31 const Word32 *rot_vec_ana_delay_im_fx; // Q31 + // Fix variables Word16 *FilterStates; /*!< Pointer to buffer of filter states Q15-FilterStates_eg*/ Word16 FilterStates_e[CLDFB_NO_COL_MAX + 9]; /*!< Filter states time slot exponents */ @@ -642,17 +644,14 @@ typedef struct cldfb_filter_bank_struct const Word16 *iRotVctr; /*Q(sqrt(1.0/16.00))*/ Word16 filterScale; /*!< filter scale Q0*/ - Word16 synGain; /*!< gain for synthesis filterbank Q0*/ - Word16 anaScalefactor; /*!< Scale factor of analysis cldfb Q0*/ - Word16 synScalefactor; /*!< Scale factor of synthesis cldfb Q0*/ - Word16 outScalefactor; /*!< Scale factor of output data (syn only) Q0*/ - Word16 synFilterHeadroom; /*!< Headroom for states in synthesis cldfb filterbank Q0*/ - + Word16 synGain; /*!< gain for synthesis filterbank Q0*/ + Word16 anaScalefactor; /*!< Scale factor of analysis cldfb Q0*/ + Word16 synScalefactor; /*!< Scale factor of synthesis cldfb Q0*/ + Word16 outScalefactor; /*!< Scale factor of output data (syn only) Q0*/ /* memory helper states */ Word16 *memory; // Qx Word32 *memory32; // Q_cldfb_state /*because cldfb_state_fx is word32 which is used to assign values*/ - UWord16 memory_length; /* main filter state */ @@ -663,9 +662,7 @@ typedef struct cldfb_filter_bank_struct /* other parameters */ Word16 bandsToZero; /* bands not synthesized */ - Word16 nab; /* number of active bands */ - Word16 filtermode; - Word16 scale; /* scaling of frequency domain */ /* Q8 */ + Word16 scale; /* scaling of frequency domain Q8 */ } CLDFB_FILTER_BANK, *HANDLE_CLDFB_FILTER_BANK; diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index 144762f74..31883fa0b 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -1757,9 +1757,8 @@ ivas_error acelp_core_dec_fx( IF( ( st->cldfbAna->usb * st->cldfbAna->no_col ) != st->L_frame ) { /* resample to ACELP internal sampling rate */ - Word16 newCldfbBands = CLDFB_getNumChannels( L_mult0( st->L_frame, FRAMES_PER_SEC ) ); - resampleCldfb( st->cldfbAna, newCldfbBands, st->L_frame, 0 ); - resampleCldfb( st->cldfbBPF, newCldfbBands, st->L_frame, 0 ); + resampleCldfb( st->cldfbAna, L_mult0( st->L_frame, FRAMES_PER_SEC ), st->L_frame, 0 ); + resampleCldfb( st->cldfbBPF, L_mult0( st->L_frame, FRAMES_PER_SEC ), st->L_frame, 0 ); IF( st->ini_frame > 0 ) { diff --git a/lib_dec/amr_wb_dec_fx.c b/lib_dec/amr_wb_dec_fx.c index d5a3cf71a..82619a87d 100644 --- a/lib_dec/amr_wb_dec_fx.c +++ b/lib_dec/amr_wb_dec_fx.c @@ -854,10 +854,8 @@ ivas_error amr_wb_dec_fx( IF( NE_16( i_mult( st_fx->cldfbAna->usb, st_fx->cldfbAna->no_col ), L_FRAME ) ) { /* resample to ACELP internal sampling rate */ - Word16 newCldfbBands = CLDFB_getNumChannels( INT_FS_FX ); - - resampleCldfb( st_fx->cldfbAna, newCldfbBands, L_FRAME, 0 ); - resampleCldfb( st_fx->cldfbBPF, newCldfbBands, L_FRAME, 0 ); + resampleCldfb( st_fx->cldfbAna, INT_FS_FX, L_FRAME, 0 ); + resampleCldfb( st_fx->cldfbBPF, INT_FS_FX, L_FRAME, 0 ); IF( st_fx->ini_frame > 0 ) { diff --git a/lib_dec/dec_acelp_tcx_main_fx.c b/lib_dec/dec_acelp_tcx_main_fx.c index 3ff221588..a4f4ef77c 100644 --- a/lib_dec/dec_acelp_tcx_main_fx.c +++ b/lib_dec/dec_acelp_tcx_main_fx.c @@ -209,15 +209,14 @@ static void decode_frame_type_fx( Decoder_State *st ) /* Reconf Core */ mode_switch_decoder_LPD_fx( st, st->bwidth, st->total_brate, frame_size_index ); + /* Reconf CLDFB */ IF( NE_16( i_mult( st->cldfbAna->no_channels, st->cldfbAna->no_col ), st->L_frame ) ) { - Word16 newCldfbBands = CLDFB_getNumChannels( L_mult0( st->L_frame, 50 ) ); - - resampleCldfb( st->cldfbAna, newCldfbBands, st->L_frame, 0 ); + resampleCldfb( st->cldfbAna, L_mult0( st->L_frame, FRAMES_PER_SEC ), st->L_frame, 0 ); IF( LE_16( st->L_frame, L_FRAME16k ) ) { - resampleCldfb( st->cldfbBPF, newCldfbBands, st->L_frame, 0 ); + resampleCldfb( st->cldfbBPF, L_mult0( st->L_frame, FRAMES_PER_SEC ), st->L_frame, 0 ); } } IF( EQ_16( st->bwidth, NB ) ) diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index d0231395b..498b20acc 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -1020,10 +1020,8 @@ ivas_error evs_dec_fx( /* check if the CLDFB works on the right sample rate */ IF( NE_16( i_mult( st_fx->cldfbAna->no_channels, st_fx->cldfbAna->no_col ), st_fx->L_frame ) ) { - Word16 newCldfbBands = CLDFB_getNumChannels( L_mult0( st_fx->L_frame, 50 ) ); - - resampleCldfb( st_fx->cldfbAna, newCldfbBands, st_fx->L_frame, 0 ); - resampleCldfb( st_fx->cldfbBPF, newCldfbBands, st_fx->L_frame, 0 ); + resampleCldfb( st_fx->cldfbAna, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ), st_fx->L_frame, 0 ); + resampleCldfb( st_fx->cldfbBPF, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ), st_fx->L_frame, 0 ); } st_fx->cldfbSyn->bandsToZero = 0; diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index 7a89118c3..4f4191ee3 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -1,3 +1,35 @@ +/****************************************************************************************************** + + (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ + /*==================================================================================== EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ @@ -10,13 +42,8 @@ #include "basop_util.h" #include "ivas_prot_fx.h" -/*----------------------------------------------------------------------* - * init_decoder() - * - * Initialization of static variables for the decoder - *----------------------------------------------------------------------*/ - -ivas_error init_decoder_fx( +#if 1 +ivas_error init_decoder_evs( Decoder_State *st_fx, /* o: Decoder static variables structure */ const Word16 idchan /* i : channel ID */ ) @@ -26,9 +53,6 @@ ivas_error init_decoder_fx( error = IVAS_ERR_OK; move16(); - Word16 newCldfbBands; - st_fx->total_num_bits = -1; - move16(); /*-----------------------------------------------------------------* * ACELP core parameters @@ -59,7 +83,6 @@ ivas_error init_decoder_fx( st_fx->extl_brate = 0; move16(); - st_fx->last_coder_type = GENERIC; move16(); st_fx->last_L_frame = st_fx->L_frame; @@ -72,7 +95,6 @@ ivas_error init_decoder_fx( st_fx->last_extl = st_fx->extl; move16(); - /* LSF initilaizations */ Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); @@ -114,6 +136,7 @@ ivas_error init_decoder_fx( st_fx->mem_deemph_fx = 0; // Q_syn move16(); + /*-----------------------------------------------------------------* * SWB BWE parameters *-----------------------------------------------------------------*/ @@ -213,6 +236,7 @@ ivas_error init_decoder_fx( /*-----------------------------------------------------------------* * parameters for fast recovery (WI) *-----------------------------------------------------------------*/ + test(); IF( EQ_32( st_fx->output_Fs, 16000 ) && ( st_fx->element_mode == EVS_MONO ) ) { @@ -317,9 +341,11 @@ ivas_error init_decoder_fx( move16(); st_fx->Q_stat_noise = 31; move16(); + /*-----------------------------------------------------------------* * LD music post-filter *-----------------------------------------------------------------*/ + test(); test(); IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) @@ -644,22 +670,25 @@ ivas_error init_decoder_fx( { st_fx->hBPF = NULL; } + /*-----------------------------------------------------------------* * FD BPF & resampling tools parameters *-----------------------------------------------------------------*/ + /* open analysis for max. SR 48kHz */ - IF( NE_32( ( error = openCldfb( &st_fx->cldfbAna, CLDFB_ANALYSIS, CLDFB_getNumChannels( 48000 ), 320 ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = openCldfb( &st_fx->cldfbAna, CLDFB_ANALYSIS, 48000 ) ), IVAS_ERR_OK ) ) { return error; } /* open analysis BPF for max. SR 16kHz */ - IF( NE_32( ( error = openCldfb( &st_fx->cldfbBPF, CLDFB_ANALYSIS, CLDFB_getNumChannels( 16000 ), 320 ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = openCldfb( &st_fx->cldfbBPF, CLDFB_ANALYSIS, 16000 ) ), IVAS_ERR_OK ) ) { return error; } + /* open synthesis for output SR */ - IF( NE_32( ( error = openCldfb( &st_fx->cldfbSyn, CLDFB_SYNTHESIS, CLDFB_getNumChannels( st_fx->output_Fs ), st_fx->output_frame_fx ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = openCldfb( &st_fx->cldfbSyn, CLDFB_SYNTHESIS, st_fx->output_Fs ) ), IVAS_ERR_OK ) ) { return error; } @@ -745,11 +774,8 @@ ivas_error init_decoder_fx( st_fx->m_old_frame_type = ACTIVE_FRAME; move16(); - - newCldfbBands = CLDFB_getNumChannels( L_mult0( st_fx->L_frame, 50 ) ); - - resampleCldfb( st_fx->cldfbAna, newCldfbBands, st_fx->L_frame, 1 ); - resampleCldfb( st_fx->cldfbBPF, newCldfbBands, st_fx->L_frame, 1 ); + resampleCldfb( st_fx->cldfbAna, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ), st_fx->L_frame, 1 ); + resampleCldfb( st_fx->cldfbBPF, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ), st_fx->L_frame, 1 ); test(); IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || idchan == 0 ) /*&& mc_mode != MC_MODE_MCT && mc_mode != MC_MODE_PARAMUPMIX*/ ) @@ -828,14 +854,14 @@ ivas_error init_decoder_fx( return error; } - +#endif /*----------------------------------------------------------------------* - * init_decoder_ivas_fx() + * init_decoder() * - * Initialization of static variables for the IVAS decoder + * Initialization of static variables for the decoder *----------------------------------------------------------------------*/ -ivas_error init_decoder_ivas_fx( +ivas_error init_decoder_fx( Decoder_State *st_fx, /* o: Decoder static variables structure */ const Word16 idchan, /* i : channel ID */ const MC_MODE mc_mode /* i : MC mode */ @@ -1098,10 +1124,10 @@ ivas_error init_decoder_ivas_fx( st_fx->hWIDec = NULL; } - /* NB post-filter */ /*-----------------------------------------------------------------* * NB/formant post-filter *-----------------------------------------------------------------*/ + test(); test(); IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) @@ -1740,6 +1766,7 @@ ivas_error init_decoder_ivas_fx( * * Initialization of static variables for pre-echo *----------------------------------------------------------------------*/ + void reset_preecho_dec_fx( HQ_DEC_HANDLE hHQ_core /* i/o: HQ core data handle */ ) @@ -1771,34 +1798,13 @@ void destroy_cldfb_decoder_fx( Decoder_State *st_fx /* o: Decoder static variables structure */ ) { - /* CLDFB BPF & resampling tools */ - - /* delete analysis for max. SR 16kHz */ - deleteCldfb( &st_fx->cldfbAna ); - - /* delete analysis BPF for max. SR 16kHz */ - deleteCldfb( &st_fx->cldfbBPF ); - - /* delete synthesis for output SR */ - deleteCldfb( &st_fx->cldfbSyn ); + deleteCldfb_fx( &st_fx->cldfbAna ); /* delete analysis for max. SR 16kHz */ + deleteCldfb_fx( &st_fx->cldfbBPF ); /* delete analysis BPF for max. SR 16kHz */ + deleteCldfb_fx( &st_fx->cldfbSyn ); /* delete synthesis for output SR */ + deleteCldfb_fx( &st_fx->cldfbSynHB ); deleteFdCngDec_fx( &st_fx->hFdCngDec ); return; } - -void destroy_cldfb_decoder_ivas_fx( - Decoder_State *st /* o : Decoder static variables structure */ -) -{ - /* CLDFB BPF & resampling tools */ - deleteCldfb_ivas_fx( &st->cldfbAna ); /* delete analysis at max. sampling rate 48kHz */ - deleteCldfb_ivas_fx( &st->cldfbBPF ); /* delete analysis BPF at max. internal sampling rate 16kHz */ - deleteCldfb_ivas_fx( &st->cldfbSyn ); /* delete synthesis at output sampling rate */ - deleteCldfb_ivas_fx( &st->cldfbSynHB ); - - deleteFdCngDec_fx( &st->hFdCngDec ); - - return; -} diff --git a/lib_dec/ivas_corecoder_dec_reconfig_fx.c b/lib_dec/ivas_corecoder_dec_reconfig_fx.c index e91b7f8b0..288cd9a03 100644 --- a/lib_dec/ivas_corecoder_dec_reconfig_fx.c +++ b/lib_dec/ivas_corecoder_dec_reconfig_fx.c @@ -578,7 +578,7 @@ ivas_error ivas_cldfb_dec_reconfig_fx( test(); IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) && EQ_16( nchan_transport_old, 1 ) && EQ_16( numCldfbAnalyses_old, 2 ) && GT_16( st_ivas->nchan_transport, 1 ) ) { - deleteCldfb_ivas_fx( &( st_ivas->cldfbAnaDec[1] ) ); + deleteCldfb_fx( &( st_ivas->cldfbAnaDec[1] ) ); numCldfbAnalyses_old = sub( numCldfbAnalyses_old, 1 ); } /* resample CLDFB analysis instances */ @@ -596,7 +596,7 @@ ivas_error ivas_cldfb_dec_reconfig_fx( /* delete superfluous CLDFB synthesis instances */ FOR( i = numCldfbAnalyses; i < numCldfbAnalyses_old; i++ ) { - deleteCldfb_ivas_fx( &( st_ivas->cldfbAnaDec[i] ) ); + deleteCldfb_fx( &( st_ivas->cldfbAnaDec[i] ) ); } } ELSE IF( LT_16( numCldfbAnalyses_old, numCldfbAnalyses ) ) @@ -616,7 +616,7 @@ ivas_error ivas_cldfb_dec_reconfig_fx( /* delete superfluous CLDFB synthesis instances */ FOR( i = numCldfbSyntheses; i < numCldfbSyntheses_old; i++ ) { - deleteCldfb_ivas_fx( &( st_ivas->cldfbSynDec[i] ) ); + deleteCldfb_fx( &( st_ivas->cldfbSynDec[i] ) ); } } ELSE IF( LT_16( numCldfbSyntheses_old, numCldfbSyntheses ) ) diff --git a/lib_dec/ivas_init_dec_fx.c b/lib_dec/ivas_init_dec_fx.c index 5a87800f7..7fc03ad13 100644 --- a/lib_dec/ivas_init_dec_fx.c +++ b/lib_dec/ivas_init_dec_fx.c @@ -2981,14 +2981,7 @@ void destroy_core_dec_fx( DEC_CORE_HANDLE hCoreCoder /* i/o: core decoder structure */ ) { - IF( EQ_16( hCoreCoder->element_mode, EVS_MONO ) ) - { - destroy_cldfb_decoder_fx( hCoreCoder ); - } - ELSE - { - destroy_cldfb_decoder_ivas_fx( hCoreCoder ); - } + destroy_cldfb_decoder_fx( hCoreCoder ); IF( hCoreCoder->hGSCDec != NULL ) { @@ -3241,7 +3234,7 @@ void ivas_destroy_dec_fx( { IF( st_ivas->cldfbAnaDec[i] != NULL ) { - deleteCldfb_ivas_fx( &( st_ivas->cldfbAnaDec[i] ) ); + deleteCldfb_fx( &( st_ivas->cldfbAnaDec[i] ) ); } } @@ -3249,7 +3242,7 @@ void ivas_destroy_dec_fx( { IF( st_ivas->cldfbSynDec[i] != NULL ) { - deleteCldfb_ivas_fx( &( st_ivas->cldfbSynDec[i] ) ); + deleteCldfb_fx( &( st_ivas->cldfbSynDec[i] ) ); } } diff --git a/lib_dec/ivas_stereo_switching_dec_fx.c b/lib_dec/ivas_stereo_switching_dec_fx.c index ef4cd013a..2d6ea5292 100644 --- a/lib_dec/ivas_stereo_switching_dec_fx.c +++ b/lib_dec/ivas_stereo_switching_dec_fx.c @@ -308,8 +308,8 @@ static void deallocate_CoreCoder_fx( /* CLDFB BPF & resampling tools */ IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { - deleteCldfb_ivas_fx( &st->cldfbAna ); /* delete analysis at max. sampling rate 48kHz */ - deleteCldfb_ivas_fx( &st->cldfbBPF ); /* delete analysis BPF at max. internal sampling rate 16kHz */ + deleteCldfb_fx( &st->cldfbAna ); /* delete analysis at max. sampling rate 48kHz */ + deleteCldfb_fx( &st->cldfbBPF ); /* delete analysis BPF at max. internal sampling rate 16kHz */ } IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index c1cc0bd04..6093a447c 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -4534,7 +4534,7 @@ static ivas_error ivas_dec_reconfig_split_rend( { IF( hSplitRendWrapper->hCldfbHandles->cldfbAna[ch] != NULL ) { - deleteCldfb_ivas_fx( &hSplitRendWrapper->hCldfbHandles->cldfbAna[ch] ); + deleteCldfb_fx( &hSplitRendWrapper->hCldfbHandles->cldfbAna[ch] ); hSplitRendWrapper->hCldfbHandles->cldfbAna[ch] = NULL; move32(); } @@ -4544,7 +4544,7 @@ static ivas_error ivas_dec_reconfig_split_rend( { IF( hSplitRendWrapper->hCldfbHandles->cldfbSyn[ch] != NULL ) { - deleteCldfb_ivas_fx( &hSplitRendWrapper->hCldfbHandles->cldfbSyn[ch] ); + deleteCldfb_fx( &hSplitRendWrapper->hCldfbHandles->cldfbSyn[ch] ); hSplitRendWrapper->hCldfbHandles->cldfbSyn[ch] = NULL; move32(); } diff --git a/lib_enc/amr_wb_enc_fx.c b/lib_enc/amr_wb_enc_fx.c index 1580a7818..13e518bc3 100644 --- a/lib_enc/amr_wb_enc_fx.c +++ b/lib_enc/amr_wb_enc_fx.c @@ -109,7 +109,7 @@ void amr_wb_enc_fx( move16(); st->coder_type = GENERIC; move16(); - input_frame = st->input_frame_fx; + input_frame = extract_l( Mult_32_16( st->input_Fs, 0x0290 ) ); move16(); /* frame length of the input signal */ st->extl = -1; move16(); diff --git a/lib_enc/evs_enc_fx.c b/lib_enc/evs_enc_fx.c index 8e9a82378..90d5a7b4b 100644 --- a/lib_enc/evs_enc_fx.c +++ b/lib_enc/evs_enc_fx.c @@ -100,7 +100,7 @@ ivas_error evs_enc_fx( * Initializiation *-----------------------------------------------------------------*/ - input_frame = st->input_frame_fx; + input_frame = extract_l( Mult_32_16( st->input_Fs, 0x0290 ) ); move16(); st->core = -1; move16(); diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index 0ee479a7c..a0dea46be 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -576,12 +576,12 @@ ivas_error init_encoder_fx( *-----------------------------------------------------------------*/ /* open analysis for input SR */ - if ( ( error = openCldfb( &st_fx->cldfbAnaEnc, CLDFB_ANALYSIS, CLDFB_getNumChannels( st_fx->input_Fs ), st_fx->input_frame_fx ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb( &st_fx->cldfbAnaEnc, CLDFB_ANALYSIS, st_fx->input_Fs ) ) != IVAS_ERR_OK ) { return error; } - if ( ( error = openCldfb( &st_fx->cldfbSynTd, CLDFB_SYNTHESIS, CLDFB_getNumChannels( 16000 ), L_FRAME16k ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb( &st_fx->cldfbSynTd, CLDFB_SYNTHESIS, 16000 ) ) != IVAS_ERR_OK ) { return error; } @@ -720,7 +720,7 @@ ivas_error init_encoder_fx( st_fx->input_fx = st_fx->input_buff_fx + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ); set16_fx( st_fx->input_buff_fx + L_FRAME48k, 0, L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); - st_fx->old_input_signal_fx = st_fx->input_fx - add( NS2SA_FX2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ), st_fx->input_frame_fx ); + st_fx->old_input_signal_fx = st_fx->input_fx - add( NS2SA_FX2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ), extract_l( Mult_32_16( st_fx->input_Fs, 0x0290 ) ) ); st_fx->Energy_Old_fx = 0; @@ -1014,23 +1014,6 @@ void LPDmem_enc_init_ivas_fx( return; } -/*-----------------------------------------------------------------------* - * destroy_encoder_fx() - * - * Free memory which was allocated in init_encoder_fx() - *-----------------------------------------------------------------------*/ - -void destroy_encoder_fx( - Encoder_State *st_fx /* i/o: Encoder static variables structure */ -) -{ - deleteCldfb( &st_fx->cldfbAnaEnc ); - deleteCldfb( &st_fx->cldfbSynTd ); - - deleteFdCngEnc_fx( &st_fx->hFdCngEnc ); - - return; -} ivas_error init_encoder_ivas_fx( Encoder_State *st, /* i/o: state structure */ @@ -1666,16 +1649,13 @@ ivas_error init_encoder_ivas_fx( IF( EQ_16( st->element_mode, EVS_MONO ) ) { /* open analysis for input SR */ - st->input_frame_fx = extract_l( Mult_32_16( st->input_Fs, 0x0290 ) ); - - if ( ( error = openCldfb( &st->cldfbAnaEnc, CLDFB_ANALYSIS, CLDFB_getNumChannels( st->input_Fs ), st->input_frame_fx ) ) != IVAS_ERR_OK ) + IF( ( error = openCldfb( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs ) ) != IVAS_ERR_OK ) { return error; } } ELSE { - IF( ( error = openCldfb_ivas_fx( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS, ENC ) ) != IVAS_ERR_OK ) { return error; @@ -1793,7 +1773,7 @@ ivas_error init_encoder_ivas_fx( IF( st->element_mode == EVS_MONO ) { - if ( ( error = openCldfb( &st->cldfbSynTd, CLDFB_SYNTHESIS, CLDFB_getNumChannels( 16000 ), L_FRAME16k ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000 ) ) != IVAS_ERR_OK ) { return error; } @@ -2200,8 +2180,8 @@ void destroy_cldfb_encoder_fx( Encoder_State *st /* i/o: Encoder static variables structure */ ) { - deleteCldfb_ivas_fx( &st->cldfbSynTd ); - deleteCldfb_ivas_fx( &st->cldfbAnaEnc ); + deleteCldfb_fx( &st->cldfbSynTd ); + deleteCldfb_fx( &st->cldfbAnaEnc ); deleteFdCngEnc_fx( &st->hFdCngEnc ); diff --git a/lib_enc/ivas_init_enc_fx.c b/lib_enc/ivas_init_enc_fx.c index 5a3592ad2..3c491edca 100644 --- a/lib_enc/ivas_init_enc_fx.c +++ b/lib_enc/ivas_init_enc_fx.c @@ -1198,7 +1198,7 @@ void destroy_evs_core_enc_fx( { Word16 i; - destroy_encoder_fx( hCoreCoder ); + destroy_cldfb_encoder_fx( hCoreCoder ); IF( hCoreCoder->hSignalBuf != NULL ) { @@ -1350,6 +1350,7 @@ void destroy_evs_core_enc_fx( * * Close IVAS encoder handles *-------------------------------------------------------------------------*/ + void ivas_destroy_enc_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) diff --git a/lib_enc/ivas_masa_enc_fx.c b/lib_enc/ivas_masa_enc_fx.c index 2f765fe05..4c644f250 100644 --- a/lib_enc/ivas_masa_enc_fx.c +++ b/lib_enc/ivas_masa_enc_fx.c @@ -275,7 +275,7 @@ void ivas_masa_enc_close_fx( FOR( i = 0; i < ( *hMasa )->data.num_Cldfb_instances; i++ ) { - deleteCldfb_ivas_fx( &( ( *hMasa )->data.cldfbAnaEnc[i] ) ); + deleteCldfb_fx( &( ( *hMasa )->data.cldfbAnaEnc[i] ) ); } IF( ( *hMasa )->data.hOmasaData != NULL ) diff --git a/lib_enc/ivas_omasa_enc_fx.c b/lib_enc/ivas_omasa_enc_fx.c index cbbbacf09..a8978c1fe 100644 --- a/lib_enc/ivas_omasa_enc_fx.c +++ b/lib_enc/ivas_omasa_enc_fx.c @@ -242,7 +242,7 @@ void ivas_omasa_enc_close_fx( FOR( i = 0; i < ( *hOMasa )->num_Cldfb_instances; i++ ) { - deleteCldfb_ivas_fx( &( ( *hOMasa )->cldfbAnaEnc[i] ) ); + deleteCldfb_fx( &( ( *hOMasa )->cldfbAnaEnc[i] ) ); } FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) diff --git a/lib_enc/ivas_sce_enc_fx.c b/lib_enc/ivas_sce_enc_fx.c index 180e175ec..a36fe44de 100644 --- a/lib_enc/ivas_sce_enc_fx.c +++ b/lib_enc/ivas_sce_enc_fx.c @@ -472,7 +472,6 @@ ivas_error create_sce_enc_fx( move32(); st->max_bwidth = st_ivas->hEncoderConfig->max_bwidth; st->input_Fs = st_ivas->hEncoderConfig->input_Fs; - st->input_frame_fx = extract_l( Mult_32_16( st->input_Fs, 0x0290 ) ); 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 ) ) { @@ -556,9 +555,6 @@ ivas_error create_evs_sce_enc_fx( st_fx->total_brate = st_ivas->hEncoderConfig->ivas_total_brate; move32(); - st_fx->input_frame_fx = extract_l( Mult_32_16( st_fx->input_Fs, 0x0290 ) ); - move16(); - IF( NE_32( ( error = init_encoder_fx( st_fx, st_ivas->hEncoderConfig->var_SID_rate_flag, st_ivas->hEncoderConfig->interval_SID ) ), IVAS_ERR_OK ) ) { return error; diff --git a/lib_enc/ivas_stereo_switching_enc_fx.c b/lib_enc/ivas_stereo_switching_enc_fx.c index 469bf211a..60215658f 100644 --- a/lib_enc/ivas_stereo_switching_enc_fx.c +++ b/lib_enc/ivas_stereo_switching_enc_fx.c @@ -183,7 +183,7 @@ static void deallocate_CoreCoder_enc_fx( IF( st->cldfbAnaEnc != NULL ) { - deleteCldfb_ivas_fx( &st->cldfbAnaEnc ); + deleteCldfb_fx( &st->cldfbAnaEnc ); } IF( st->hBWE_TD != NULL ) @@ -194,7 +194,7 @@ static void deallocate_CoreCoder_enc_fx( IF( st->cldfbSynTd != NULL ) { - deleteCldfb_ivas_fx( &st->cldfbSynTd ); + deleteCldfb_fx( &st->cldfbSynTd ); } IF( st->hBWE_FD != NULL ) @@ -362,8 +362,8 @@ ivas_error stereo_memory_enc_fx( IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) && ( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) || EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) ) { /* Deallocate MDCT CNG structures */ - deleteCldfb_ivas_fx( &hCPE->hCoreCoder[0]->cldfbAnaEnc ); - deleteCldfb_ivas_fx( &hCPE->hCoreCoder[1]->cldfbAnaEnc ); + deleteCldfb_fx( &hCPE->hCoreCoder[0]->cldfbAnaEnc ); + deleteCldfb_fx( &hCPE->hCoreCoder[1]->cldfbAnaEnc ); IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { diff --git a/lib_enc/ivas_stereo_td_enc_fx.c b/lib_enc/ivas_stereo_td_enc_fx.c index 8f1d2d9c9..5b381ee5b 100644 --- a/lib_enc/ivas_stereo_td_enc_fx.c +++ b/lib_enc/ivas_stereo_td_enc_fx.c @@ -263,7 +263,7 @@ ivas_error stereo_set_tdm_fx( /* deallocate CLDFB ana for secondary channel */ IF( st->cldfbAnaEnc != NULL ) { - deleteCldfb_ivas_fx( &st->cldfbAnaEnc ); + deleteCldfb_fx( &st->cldfbAnaEnc ); } /* deallocate BWEs for secondary channel */ @@ -275,7 +275,7 @@ ivas_error stereo_set_tdm_fx( st->hBWE_TD = NULL; } - deleteCldfb_ivas_fx( &st->cldfbSynTd ); + deleteCldfb_fx( &st->cldfbSynTd ); IF( st->hBWE_FD != NULL ) { diff --git a/lib_enc/lib_enc_fx.c b/lib_enc/lib_enc_fx.c index 295608d6f..3faf5a4bf 100644 --- a/lib_enc/lib_enc_fx.c +++ b/lib_enc/lib_enc_fx.c @@ -1496,8 +1496,6 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( #ifdef DEBUG_MODE_INFO dbgwrite( inputBuffer, sizeof( int16_t ), inputBufferSize, 1, strcat( fname( debug_dir, "ivas_input_dmx", 0, 1, ENC ), ".pcm" ) ); #endif - hCoreCoder->input_frame_fx = inputBufferSize; - move32(); IF( NE_32( ( error = evs_enc_fx( hCoreCoder, inputBuffer, hCoreCoder->mem_hp20_in_fx, inputBufferSize ) ), IVAS_ERR_OK ) ) { return error; diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 28389e9e0..3ca99fed2 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -4583,10 +4583,6 @@ void copy_encoder_config_fx( const Word16 flag_all /* i : flag 1==update all, 0=partial update Q0*/ ); -void destroy_encoder_fx( - Encoder_State *st_fx /* i/o: Encoder static variables structure */ -); - void amr_wb_enc_fx( Encoder_State *st, /* i/o: encoder state structure */ const Word16 input_sp[], /* i : i signal Q0*/ diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index fdcff722c..e82605860 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -1310,7 +1310,6 @@ typedef struct enc_core_structure // Word16 core_fx; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */ // Word32 core_brate_fx; /* core bitrate */ // Word32 last_core_brate_fx; /* previous frame core bitrate */ - Word16 input_frame_fx; /* Frame lenght (function of input_Fs) */ // Word16 extl_fx; /* extension layer */ // Word16 last_extl_fx; /* previous extension layer */ // Word32 extl_brate_fx; /* extension layer bitrate */ diff --git a/lib_isar/isar_splitRendererPost.c b/lib_isar/isar_splitRendererPost.c index f03afbeb8..1d734bed0 100644 --- a/lib_isar/isar_splitRendererPost.c +++ b/lib_isar/isar_splitRendererPost.c @@ -133,12 +133,12 @@ void isar_splitBinPostRendClose( { IF( ( *hBinHrSplitPostRend )->cldfbSyn[ch] != NULL ) { - deleteCldfb_ivas_fx( &( ( *hBinHrSplitPostRend )->cldfbSyn[ch] ) ); + deleteCldfb_fx( &( ( *hBinHrSplitPostRend )->cldfbSyn[ch] ) ); ( *hBinHrSplitPostRend )->cldfbSyn[ch] = NULL; } IF( ( *hBinHrSplitPostRend )->cldfbAna[ch] != NULL ) { - deleteCldfb_ivas_fx( &( ( *hBinHrSplitPostRend )->cldfbAna[ch] ) ); + deleteCldfb_fx( &( ( *hBinHrSplitPostRend )->cldfbAna[ch] ) ); ( *hBinHrSplitPostRend )->cldfbAna[ch] = NULL; } } @@ -149,7 +149,7 @@ void isar_splitBinPostRendClose( { if ( ( *hBinHrSplitPostRend )->cldfbSynReconsBinDec[i][ch] != NULL ) { - deleteCldfb_ivas_fx( &( ( *hBinHrSplitPostRend )->cldfbSynReconsBinDec[i][ch] ) ); + deleteCldfb_fx( &( ( *hBinHrSplitPostRend )->cldfbSynReconsBinDec[i][ch] ) ); ( *hBinHrSplitPostRend )->cldfbSynReconsBinDec[i][ch] = NULL; } } diff --git a/lib_isar/isar_splitRendererPre.c b/lib_isar/isar_splitRendererPre.c index 71e285a9c..3287d668c 100644 --- a/lib_isar/isar_splitRendererPre.c +++ b/lib_isar/isar_splitRendererPre.c @@ -2601,7 +2601,7 @@ void isar_splitBinPreRendClose( { IF( ( *hBinHrSplitPreRend )->cldfbSynRotBinDec[i][n] != NULL ) { - deleteCldfb_ivas_fx( &( ( *hBinHrSplitPreRend )->cldfbSynRotBinDec[i][n] ) ); + deleteCldfb_fx( &( ( *hBinHrSplitPreRend )->cldfbSynRotBinDec[i][n] ) ); ( *hBinHrSplitPreRend )->cldfbSynRotBinDec[i][n] = NULL; } } diff --git a/lib_isar/lib_isar_pre_rend.c b/lib_isar/lib_isar_pre_rend.c index da4f6542f..1ebb0cca1 100644 --- a/lib_isar/lib_isar_pre_rend.c +++ b/lib_isar/lib_isar_pre_rend.c @@ -204,7 +204,7 @@ void ISAR_PRE_REND_close( { IF( hSplitBinRend->hCldfbHandles->cldfbAna[ch] != NULL ) { - deleteCldfb_ivas_fx( &hSplitBinRend->hCldfbHandles->cldfbAna[ch] ); + deleteCldfb_fx( &hSplitBinRend->hCldfbHandles->cldfbAna[ch] ); hSplitBinRend->hCldfbHandles->cldfbAna[ch] = NULL; } } @@ -213,7 +213,7 @@ void ISAR_PRE_REND_close( { IF( hSplitBinRend->hCldfbHandles->cldfbSyn[ch] != NULL ) { - deleteCldfb_ivas_fx( &hSplitBinRend->hCldfbHandles->cldfbSyn[ch] ); + deleteCldfb_fx( &hSplitBinRend->hCldfbHandles->cldfbSyn[ch] ); hSplitBinRend->hCldfbHandles->cldfbSyn[ch] = NULL; } } diff --git a/lib_rend/ivas_dirac_ana_fx.c b/lib_rend/ivas_dirac_ana_fx.c index 4e00b9623..011f7bda3 100644 --- a/lib_rend/ivas_dirac_ana_fx.c +++ b/lib_rend/ivas_dirac_ana_fx.c @@ -196,7 +196,7 @@ void ivas_dirac_ana_close_fx( FOR( i = 0; i < ( *hDirAC )->num_Cldfb_instances; i++ ) { - deleteCldfb_ivas_fx( &( ( *hDirAC )->cldfbAnaEnc[i] ) ); + deleteCldfb_fx( &( ( *hDirAC )->cldfbAnaEnc[i] ) ); } FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) diff --git a/lib_rend/ivas_masa_merge_fx.c b/lib_rend/ivas_masa_merge_fx.c index 432ed8253..dfb45ad6d 100644 --- a/lib_rend/ivas_masa_merge_fx.c +++ b/lib_rend/ivas_masa_merge_fx.c @@ -551,7 +551,7 @@ void masaPrerendClose_fx( FOR( i = 0; i < ( *hMasaPrerendPtr )->num_Cldfb_instances; i++ ) { - deleteCldfb_ivas_fx( &( ( *hMasaPrerendPtr )->cldfbAnaEnc[i] ) ); + deleteCldfb_fx( &( ( *hMasaPrerendPtr )->cldfbAnaEnc[i] ) ); } free( ( *hMasaPrerendPtr )->hMasaOut ); diff --git a/lib_rend/ivas_mcmasa_ana_fx.c b/lib_rend/ivas_mcmasa_ana_fx.c index 1ce8dc77f..2e065e83b 100644 --- a/lib_rend/ivas_mcmasa_ana_fx.c +++ b/lib_rend/ivas_mcmasa_ana_fx.c @@ -414,7 +414,7 @@ void ivas_mcmasa_ana_close( FOR( i = 0; i < ( *hMcMasa )->num_Cldfb_instances; i++ ) { - deleteCldfb_ivas_fx( &( ( *hMcMasa )->cldfbAnaEnc[i] ) ); + deleteCldfb_fx( &( ( *hMcMasa )->cldfbAnaEnc[i] ) ); } /* intensity 3-dim */ diff --git a/lib_rend/ivas_omasa_ana_fx.c b/lib_rend/ivas_omasa_ana_fx.c index 67e72e84c..2b2e53b97 100644 --- a/lib_rend/ivas_omasa_ana_fx.c +++ b/lib_rend/ivas_omasa_ana_fx.c @@ -251,7 +251,7 @@ void ivas_omasa_ana_close( FOR( i = 0; i < ( *hOMasa )->num_Cldfb_instances; i++ ) { - deleteCldfb_ivas_fx( &( ( *hOMasa )->cldfbAnaEnc[i] ) ); + deleteCldfb_fx( &( ( *hOMasa )->cldfbAnaEnc[i] ) ); } FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) diff --git a/lib_rend/lib_rend_fx.c b/lib_rend/lib_rend_fx.c index c74d77bf9..3721cb4ff 100644 --- a/lib_rend/lib_rend_fx.c +++ b/lib_rend/lib_rend_fx.c @@ -8940,7 +8940,7 @@ static ivas_error getSamplesInternal( if ( ( error = ISAR_PRE_REND_MultiBinToSplitBinaural( hIvasRend->splitRendWrapper, hIvasRend->headRotData.headPositions[0], hIvasRend->hRendererConfig->split_rend_config.splitRendBitRate, hIvasRend->hRendererConfig->split_rend_config.codec, hIvasRend->hRendererConfig->split_rend_config.isar_frame_size_ms, hIvasRend->hRendererConfig->split_rend_config.codec_frame_size_ms, - &bits, Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, ( const Word16 )( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), tmpBinaural, 1, cldfb_in_flag, ( hIvasRend->outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ? 1 : 0, ro_md_flag, Q_buff, &Q_out[0] ) ) != IVAS_ERR_OK ) + &bits, Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, (const Word16) ( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), tmpBinaural, 1, cldfb_in_flag, ( hIvasRend->outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ? 1 : 0, ro_md_flag, Q_buff, &Q_out[0] ) ) != IVAS_ERR_OK ) { return error; } @@ -9197,7 +9197,7 @@ void IVAS_REND_closeCldfb( { IF( cldfbAna[n] != NULL ) { - deleteCldfb_ivas_fx( &( cldfbAna[n] ) ); + deleteCldfb_fx( &( cldfbAna[n] ) ); cldfbAna[n] = NULL; } } @@ -9206,7 +9206,7 @@ void IVAS_REND_closeCldfb( { IF( cldfbSyn[n] != NULL ) { - deleteCldfb_ivas_fx( &( cldfbSyn[n] ) ); + deleteCldfb_fx( &( cldfbSyn[n] ) ); cldfbSyn[n] = NULL; } } @@ -10241,7 +10241,7 @@ static void freeMasaExtRenderer( { IF( hMasaExtRend->cldfbAnaRend[i] != NULL ) { - deleteCldfb_ivas_fx( &hMasaExtRend->cldfbAnaRend[i] ); + deleteCldfb_fx( &hMasaExtRend->cldfbAnaRend[i] ); } } @@ -10249,7 +10249,7 @@ static void freeMasaExtRenderer( { IF( hMasaExtRend->cldfbSynRend[i] != NULL ) { - deleteCldfb_ivas_fx( &hMasaExtRend->cldfbSynRend[i] ); + deleteCldfb_fx( &hMasaExtRend->cldfbSynRend[i] ); } } -- GitLab From 6e90c39b7cefa49ae36eee1cc6e44cb85470b230 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 8 Sep 2025 21:09:06 +0200 Subject: [PATCH 02/15] harmonize init_decoder() --- lib_com/prot_fx.h | 8 +- lib_dec/dec4t64_fx.c | 2 - lib_dec/gs_dec_fx.c | 35 +- lib_dec/init_dec_fx.c | 914 ++----------------------- lib_dec/ivas_cpe_dec_fx.c | 2 +- lib_dec/ivas_sce_dec_fx.c | 17 +- lib_dec/ivas_stereo_switching_dec_fx.c | 2 +- lib_dec/stat_dec.h | 1 - 8 files changed, 80 insertions(+), 901 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 5eb847ad1..20c00a39f 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -6683,11 +6683,7 @@ void gsc_dec_fx( Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ Word16 *Q_exc ); -void GSC_dec_init( - GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ -); - -void GSC_dec_init_ivas_fx( +void GSC_dec_init_fx( GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ ); @@ -7392,7 +7388,7 @@ void generate_masking_noise_mdct_ivas_fx( Word32 *mdctBuffer, /* i/o: time-dom HANDLE_FD_CNG_COM st /* i/o: FD_CNG structure containing all buffers and variables */ ); ivas_error init_decoder_fx( - Decoder_State *st_fx, /* o: Decoder static variables structure */ + Decoder_State *st_fx, /* o : Decoder static variables structure */ const Word16 idchan, /* i : channel ID */ const MC_MODE mc_mode /* i : MC mode */ ); diff --git a/lib_dec/dec4t64_fx.c b/lib_dec/dec4t64_fx.c index ee6ef65a6..1b56c69cf 100644 --- a/lib_dec/dec4t64_fx.c +++ b/lib_dec/dec4t64_fx.c @@ -871,8 +871,6 @@ void dec_acelp_fast_fx( move16(); set16_fx( code, 0, L_subfr ); - st->total_num_bits = extract_l( st->total_brate / FRAMES_PER_SEC ); - IF( EQ_16( L_subfr, L_SUBFR ) ) { config = PulseConfTable[cdk_index]; diff --git a/lib_dec/gs_dec_fx.c b/lib_dec/gs_dec_fx.c index a17ca6feb..d174cd87b 100644 --- a/lib_dec/gs_dec_fx.c +++ b/lib_dec/gs_dec_fx.c @@ -867,7 +867,7 @@ void gsc_dec_fx( * Initialize GSC decoder state structure *-------------------------------------------------------------------*/ -void GSC_dec_init( +void GSC_dec_init_fx( GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ ) { @@ -881,43 +881,16 @@ void GSC_dec_init( move16(); move16(); - set16_fx( hGSCDec->Last_GSC_spectrum_fx, 0, L_FRAME ); - set16_fx( hGSCDec->last_exc_dct_in_fx, 0, L_FRAME ); - set16_fx( hGSCDec->old_y_gain_fx, 0, MBANDS_GN ); - set16_fx( hGSCDec->lt_ener_per_band_fx, 4096, MBANDS_GN ); /*Q12*/ - - hGSCDec->last_ener_fx = 0; - move16(); - set16_fx( hGSCDec->last_bitallocation_band, 0, 6 ); - - hGSCDec->Last_frame_ener_fx = MAX_32; - move32(); - return; -} - -void GSC_dec_init_ivas_fx( - GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ -) -{ - hGSCDec->seed_tcx = 15687; /* Q0 */ - move16(); - hGSCDec->cor_strong_limit = 1; - move16(); - set16_fx( hGSCDec->old_y_gain_fx, 0, MBANDS_GN ); - hGSCDec->noise_lev = NOISE_LEVEL_SP0; - move16(); set16_fx( hGSCDec->Last_GSC_spectrum_fx, 0, L_FRAME16k ); - hGSCDec->Last_GSC_pit_band_idx = 0; - move16(); - - set16_fx( hGSCDec->lt_ener_per_band_fx, 4096, MBANDS_GN16k ); /*Q12*/ set16_fx( hGSCDec->last_exc_dct_in_fx, 0, L_FRAME16k ); + set16_fx( hGSCDec->old_y_gain_fx, 0, MBANDS_GN16k ); + set16_fx( hGSCDec->lt_ener_per_band_fx, 4096, MBANDS_GN16k ); /*Q12*/ + hGSCDec->last_ener_fx = 0; move16(); set16_fx( hGSCDec->last_bitallocation_band, 0, 6 ); hGSCDec->Last_frame_ener_fx = MAX_32; move32(); - return; } diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index 4f4191ee3..c05e5fb71 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -42,819 +42,7 @@ #include "basop_util.h" #include "ivas_prot_fx.h" -#if 1 -ivas_error init_decoder_evs( - Decoder_State *st_fx, /* o: Decoder static variables structure */ - const Word16 idchan /* i : channel ID */ -) -{ - Word16 i; - ivas_error error; - - error = IVAS_ERR_OK; - move16(); - - /*-----------------------------------------------------------------* - * ACELP core parameters - *-----------------------------------------------------------------*/ - - st_fx->codec_mode = MODE1; - move16(); - st_fx->last_codec_mode = MODE1; - move16(); - st_fx->core = ACELP_CORE; - move16(); - st_fx->L_frame = L_FRAME; - move16(); - st_fx->extl = -1; - move16(); - st_fx->total_brate = 8000; - move16(); - st_fx->last_total_brate = -1; - move16(); - st_fx->last_total_brate_ber = -1; - move32(); - st_fx->core_brate = 8000; - move16(); - st_fx->ini_frame = 0; - move16(); - st_fx->bwidth = NB; - move16(); - st_fx->extl_brate = 0; - move16(); - - st_fx->last_coder_type = GENERIC; - move16(); - st_fx->last_L_frame = st_fx->L_frame; - move16(); - st_fx->last_core_brate = st_fx->core_brate; - move16(); - - st_fx->last_core = -1; - move16(); - st_fx->last_extl = st_fx->extl; - move16(); - - /* LSF initilaizations */ - Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); - - init_lvq_fx( st_fx->offset_scale1_fx, st_fx->offset_scale2_fx, st_fx->offset_scale1_p_fx, st_fx->offset_scale2_p_fx, st_fx->no_scales_fx, st_fx->no_scales_p_fx ); - - set16_fx( st_fx->mem_MA_fx, 0, M ); - - st_fx->dm_fx.prev_state = 0; // Q0 - move16(); /* This corresponds to st_fx->dispMem in FLP */ - st_fx->dm_fx.prev_gain_code = L_deposit_l( 0 ); // Q16 - FOR( i = 2; i < 8; i++ ) - { - st_fx->dm_fx.prev_gain_pit[i - 2] = 0; // Q14 - move16(); - } - - st_fx->tilt_code_fx = 0; // Q15 - move16(); - st_fx->gc_threshold_fx = L_deposit_l( 0 ); // Q16 - st_fx->last_good = UNVOICED_CLAS; - move16(); - st_fx->clas_dec = UNVOICED_CLAS; - move16(); - - st_fx->lp_gainp_fx = 0; // Q14 - move16(); - st_fx->lp_gainc_fx = 0; // Q3 - move16(); - - set16_fx( st_fx->old_exc_fx, 0, L_EXC_MEM_DEC ); // Q_exc - - /* AVQ pre-quantizer memory */ - st_fx->mem_preemp_preQ_fx = 0; - move16(); - st_fx->last_nq_preQ = 0; - move16(); - st_fx->use_acelp_preq = 0; - move16(); - - st_fx->mem_deemph_fx = 0; // Q_syn - move16(); - - /*-----------------------------------------------------------------* - * SWB BWE parameters - *-----------------------------------------------------------------*/ - - test(); - IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - IF( ( st_fx->hBWE_FD = (FD_BWE_DEC_HANDLE) malloc( sizeof( FD_BWE_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n" ) ); - } - - fd_bwe_dec_init_fx( st_fx->hBWE_FD ); - } - ELSE - { - st_fx->hBWE_FD = NULL; - } - - /*-----------------------------------------------------------------* - * IGF - *-----------------------------------------------------------------*/ - - test(); - IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - IF( ( st_fx->hIGFDec = (IGF_DEC_INSTANCE_HANDLE) malloc( sizeof( IGFDEC_INSTANCE ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for IGF\n" ) ); - } - - st_fx->igf = 0; - move16(); - init_igf_dec( st_fx->hIGFDec ); - } - ELSE - { - st_fx->hIGFDec = NULL; - } - - /*-----------------------------------------------------------------* - * HR SWB BWE parameters - *-----------------------------------------------------------------*/ - - IF( st_fx->element_mode == EVS_MONO ) - { - IF( ( st_fx->hBWE_FD_HR = (HR_BWE_DEC_HANDLE) malloc( sizeof( HR_BWE_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HR BWE\n" ) ); - } - - hr_bwe_dec_init( st_fx->hBWE_FD_HR ); - } - ELSE - { - st_fx->hBWE_FD_HR = NULL; - } - set16_fx( st_fx->mem_syn1_fx, 0, M ); - set16_fx( st_fx->mem_syn2_fx, 0, M ); - st_fx->stab_fac_fx = 0; // Q15 - move16(); - st_fx->stab_fac_smooth_fx = 0; // Q15 - move16(); - set16_fx( st_fx->agc_mem_fx, 0, 2 ); // Q0 - set32_fx( st_fx->L_mem_hp_out_fx, 0, 5 ); - set16_fx( st_fx->mem_syn3_fx, 0, M ); - - - Copy( GEWB_Ave_fx, st_fx->lsf_old_fx, M ); - lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, INT_FS_FX ); - st_fx->mid_lsf_int = 0; - move16(); - st_fx->safety_net = 0; - move16(); - st_fx->GSC_noisy_speech = 0; - move16(); - st_fx->last_voice_factor_fx = 0; // Q6 - move16(); - - - test(); - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - IF( ( st_fx->hGSCDec = (GSC_DEC_HANDLE) malloc( sizeof( GSC_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n" ) ); - } - - GSC_dec_init( st_fx->hGSCDec ); - } - ELSE - { - st_fx->hGSCDec = NULL; - } - - /*-----------------------------------------------------------------* - * parameters for fast recovery (WI) - *-----------------------------------------------------------------*/ - - test(); - IF( EQ_32( st_fx->output_Fs, 16000 ) && ( st_fx->element_mode == EVS_MONO ) ) - { - IF( ( st_fx->hWIDec = (WI_DEC_HANDLE) malloc( sizeof( WI_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FEC WI\n" ) ); - } - - set16_fx( st_fx->hWIDec->old_exc2_fx, 0, L_EXC_MEM ); - set16_fx( st_fx->hWIDec->old_syn2_fx, 0, L_EXC_MEM ); - } - ELSE - { - st_fx->hWIDec = NULL; - } - - /* NB post-filter */ - /*-----------------------------------------------------------------* - * NB/formant post-filter - *-----------------------------------------------------------------*/ - test(); - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - IF( ( st_fx->hPFstat = (PFSTAT_HANDLE) malloc( sizeof( PFSTAT ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for NB/formant postflter\n" ) ); - } - - Init_post_filter_fx( st_fx->hPFstat ); - st_fx->psf_lp_noise_fx = 0; // Q8 - move16(); - } - ELSE - { - st_fx->hPFstat = NULL; - } - st_fx->psf_lp_noise_fx = 0; // Q8 - move16(); - - /* FEC */ - st_fx->scaling_flag = 0; - move16(); - st_fx->lp_ener_FEC_av = 500000; // Q0 - move32(); - st_fx->lp_ener_FEC_max = 500000; // Q0 - move32(); - st_fx->prev_bfi = 0; - move16(); - st_fx->lp_ener_FER_fx = 15360; // Q8 - move16(); /*60 in Q8*/ - st_fx->old_enr_LP = 0; // Q5 - move16(); - st_fx->lp_ener_fx = L_deposit_l( 0 ); // Q6 - st_fx->enr_old_fx = L_deposit_l( 0 ); // Q0 - st_fx->bfi_pitch_fx = L_SUBFR_Q6; - move16(); - st_fx->bfi_pitch_frame = L_SUBFR; - move16(); - set16_fx( st_fx->mem_syn_clas_estim_fx, 0, L_SYN_MEM_CLAS_ESTIM ); - st_fx->classifier_Q_mem_syn = 0; - move16(); - st_fx->last_con_tcx = 0; - move16(); - - FOR( i = 0; i < 2 * NB_SUBFR16k; i++ ) - { - st_fx->old_pitch_buf_fx[i] = L_SUBFR << 16; // Q16 - move32(); /*15Q16*/ - } - - st_fx->upd_cnt = MAX_UPD_CNT; - move16(); - Copy( GEWB_Ave_fx, st_fx->lsfoldbfi0_fx, M ); - Copy( GEWB_Ave_fx, st_fx->lsfoldbfi1_fx, M ); - Copy( GEWB_Ave_fx, st_fx->lsf_adaptive_mean_fx, M ); - - st_fx->seed_acelp = RANDOM_INITSEED; - move16(); - st_fx->seed = RANDOM_INITSEED; - move16(); - st_fx->nbLostCmpt = 0; - move16(); - st_fx->decision_hyst = 0; - move16(); - - - /* Stationary noise UV modification */ - st_fx->unv_cnt = 0; - move16(); - st_fx->ge_sm_fx = L_deposit_l( 640 ); /*Q(GE_SHIFT)*/ - st_fx->uv_count = 0; - move16(); - st_fx->act_count = 3; - move16(); - Copy( st_fx->lsp_old_fx, st_fx->lspold_s_fx, M ); // Q15 - st_fx->noimix_seed = RANDOM_INITSEED; - move16(); - st_fx->min_alpha_fx = 32767; // Q15 - move16(); /*1; Q15*/ - st_fx->exc_pe_fx = 0; // Q_stat_noise - move16(); - st_fx->Q_stat_noise = 31; - move16(); - - /*-----------------------------------------------------------------* - * LD music post-filter - *-----------------------------------------------------------------*/ - - test(); - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - IF( ( st_fx->hMusicPF = (MUSIC_POSTFILT_HANDLE) malloc( sizeof( MUSIC_POSTFILT_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LD music postflter\n" ) ); - } - - music_postfilt_init( st_fx->hMusicPF ); - } - ELSE - { - st_fx->hMusicPF = NULL; - } - - /* CNG and DTX */ - test(); - test(); - test(); - IF( idchan == 0 && ( ( st_fx->element_mode == EVS_MONO ) || EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) ) - { - IF( ( st_fx->hTdCngDec = (TD_CNG_DEC_HANDLE) malloc( sizeof( TD_CNG_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); - } - - td_cng_dec_init_fx( st_fx ); - } - ELSE - { - st_fx->hTdCngDec = NULL; - } - st_fx->cng_type = -1; - move16(); - st_fx->first_CNG = 0; - move16(); - Copy( st_fx->lsp_old_fx, st_fx->lspCNG_fx, M ); // Q15 - - st_fx->CNG_mode = -1; - move16(); - st_fx->last_active_brate = ACELP_7k20; - move32(); - st_fx->last_CNG_L_frame = L_FRAME; - move16(); - - - st_fx->last_vad_fx = 0; - move16(); - - /* HF (6-7kHz) BWE */ - move16(); - st_fx->Q_stat_noise_ge = GE_SHIFT; // Q of ge_sm_fx - move16(); - st_fx->cngTDLevel = 0; - move16(); - st_fx->cngTDLevel_e = 0; - move16(); - - - /*-----------------------------------------------------------------* - * HQ core parameters - *-----------------------------------------------------------------*/ - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || EQ_16( st_fx->element_mode, IVAS_SCE ) || ( st_fx->element_mode == EVS_MONO ) ) ) - { - IF( ( st_fx->hHQ_core = (HQ_DEC_HANDLE) malloc( sizeof( HQ_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n" ) ); - } - - /* HQ core initialization */ - HQ_core_dec_init_fx( st_fx->hHQ_core ); - - IF( st_fx->element_mode == EVS_MONO ) - { - /* HQ NB FEC initialization */ - IF( ( st_fx->hHQ_nbfec = (HQ_NBFEC_HANDLE) malloc( sizeof( HQ_NBFEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ NB FEC\n" ) ); - } - HQ_nbfec_init_fx( st_fx->hHQ_nbfec ); - } - ELSE - { - st_fx->hHQ_nbfec = NULL; - } - } - ELSE - { - st_fx->hHQ_core = NULL; - st_fx->hHQ_nbfec = NULL; - } - st_fx->Qprev_synth_buffer_fx = 15; - move16(); - st_fx->old_bfi_cnt = 0; - move16(); - st_fx->prev_old_bfi = 0; - move16(); - set16_fx( st_fx->delay_buf_out_fx, 0, HQ_DELTA_MAX * HQ_DELAY_COMP ); - set16_fx( st_fx->previoussynth_fx, 0, L_FRAME48k ); - IF( st_fx->element_mode == EVS_MONO ) - { - set16_fx( st_fx->old_synth_sw_fx, 0, NS2SA( 48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ) ); - } - /*-----------------------------------------------------------------* - * TCX core - *-----------------------------------------------------------------*/ - - /* TCX-LTP */ - IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) - { - IF( ( st_fx->hTcxLtpDec = (TCX_LTP_DEC_HANDLE) malloc( sizeof( TCX_LTP_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TCX-LTP handle\n" ) ); - } - } - ELSE - { - st_fx->hTcxLtpDec = NULL; - } - - /* TCX core */ - IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - IF( ( st_fx->hTcxDec = (TCX_DEC_HANDLE) malloc( sizeof( TCX_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxDec\n" ) ); - } - - set16_fx( st_fx->hTcxDec->FBTCXdelayBuf, 0, 111 ); - - st_fx->hTcxDec->old_synthFB_fx = st_fx->hTcxDec->synth_history_fx + NS2SA_FX2( st_fx->output_Fs, PH_ECU_MEM_NS ); - st_fx->hTcxDec->prev_good_synth_fx = st_fx->hTcxDec->old_synthFB_fx + NS2SA_FX2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ); - } - ELSE - { - st_fx->hTcxDec = NULL; - } - /* TCX config. data structure */ - IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - IF( ( st_fx->hTcxCfg = (TCX_CONFIG_HANDLE) malloc( sizeof( TCX_config ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n" ) ); - } - } - ELSE - { - st_fx->hTcxCfg = NULL; - } - - /* Tonal MDCT concealment data structure */ - - if ( ( st_fx->hTonalMDCTConc = (TonalMDCTConcealPtr) malloc( sizeof( TonalMDCTConceal_INSTANCE ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TonalMDCTConcealment\n" ) ); - } - - st_fx->prev_coder_type = GENERIC; - move16(); - - move16(); - st_fx->tilt_wb_fx = 0; // Q11 - move16(); - - set16_fx( st_fx->prev_synth_buffer_fx, 0, NS2SA_FX2( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); - set16_fx( st_fx->hb_prev_synth_buffer_fx, 0, NS2SA_FX2( 48000, DELAY_BWE_TOTAL_NS ) ); - st_fx->old_bwe_delay = -1; /*Q0*/ - move16(); - - /*-----------------------------------------------------------------* - * TBE parameters - *-----------------------------------------------------------------*/ - - test(); - IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - IF( ( st_fx->hBWE_TD = (TD_BWE_DEC_HANDLE) malloc( sizeof( TD_BWE_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); - } - - td_bwe_dec_init_fx( st_fx->hBWE_TD, st_fx->extl, st_fx->output_Fs ); - - st_fx->prev_Q_bwe_exc = 31; - move16(); - } - ELSE - { - st_fx->hBWE_TD = NULL; - } - - st_fx->tilt_swb_fx = 0; // Q24 - move16(); - st_fx->tilt_wb_fx = 0; // Q11 - move16(); - - st_fx->prev_ener_shb_fx = 0; // Q1 - move16(); - st_fx->prev_enerLH_fx = 0; // Q1 - move16(); - st_fx->enerLH_fx = L_deposit_l( 0 ); - st_fx->enerLL_fx = L_deposit_l( 0 ); - st_fx->prev_enerLL_fx = 0; - move16(); - st_fx->prev_fractive = 0; - move16(); - st_fx->prev_bws_cnt = 0; - move16(); - st_fx->bws_cnt = N_WS2N_FRAMES; - move16(); - st_fx->bws_cnt1 = N_NS2W_FRAMES; - move16(); - st_fx->attenu_fx = 3277; // Q15 - move16(); - st_fx->last_inner_frame = L_FRAME8k; - move16(); - st_fx->last_bwidth = 0; - move16(); - - /*-----------------------------------------------------------------* - * channel-aware mode parameters - *-----------------------------------------------------------------*/ - - set16_fx( st_fx->tilt_code_dec_fx, 0, NB_SUBFR16k ); - - st_fx->use_partial_copy = 0; - move16(); - st_fx->prev_use_partial_copy = 0; - move16(); - st_fx->rf_flag = 0; - move16(); - st_fx->rf_flag_last = 0; - st_fx->prev_rf_frame_type = 0; - move16(); - st_fx->next_coder_type = 0; - move16(); - - st_fx->rf_target_bits = 0; - move16(); - - st_fx->rf_indx_nelp_fid = 0; - move16(); - st_fx->rf_indx_nelp_iG1 = 0; - move16(); - st_fx->rf_indx_nelp_iG2[0] = 0; - move16(); - st_fx->rf_indx_nelp_iG2[1] = 0; - move16(); - st_fx->rf_indx_tbeGainFr = 0; - move16(); - - /*----------------------------------------------------------------------------------* - * AMR-WB IO mode parameters - *----------------------------------------------------------------------------------*/ - test(); - IF( st_fx->Opt_AMR_WB || ( st_fx->element_mode == EVS_MONO ) ) - { - IF( ( st_fx->hAmrwb_IO = (AMRWB_IO_DEC_HANDLE) malloc( sizeof( AMRWB_IO_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AMR-WB IO\n" ) ); - } - - /* AMR-WB IO init */ - amr_wb_dec_init_fx( st_fx->hAmrwb_IO ); - - /* AMR-WB IO HF synth init */ - hf_synth_amr_wb_init_fx( st_fx->hAmrwb_IO ); - } - ELSE - { - st_fx->hAmrwb_IO = NULL; - } - /*-----------------------------------------------------------------* - * HF (6-7kHz) (zero) BWE parameters - *-----------------------------------------------------------------*/ - test(); - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - IF( ( st_fx->hBWE_zero = (ZERO_BWE_DEC_HANDLE) malloc( sizeof( ZERO_BWE_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for zero BWE\n" ) ); - } - - hf_synth_init_fx( st_fx->hBWE_zero ); - /* TBV Hack for bit exactness with 26.452, Issue should be corrected there as the the reset is not perform on all values of mem_hp400_fx*/ - set16_fx( st_fx->hBWE_zero->mem_hp400_fx, 0, 6 ); - } - ELSE - { - st_fx->hBWE_zero = NULL; - } - - /* HF synth init */ - hf_synth_amr_wb_init_fx( st_fx->hAmrwb_IO ); - - - st_fx->bpf_off = 0; - move16(); - /*-----------------------------------------------------------------* - * Bass post-filter parameters - *-----------------------------------------------------------------*/ - test(); - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - IF( ( st_fx->hBPF = (BPF_DEC_HANDLE) malloc( sizeof( BPF_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for BPF\n" ) ); - } - - bass_psfilter_init_fx( st_fx->hBPF ); - } - ELSE - { - st_fx->hBPF = NULL; - } - - /*-----------------------------------------------------------------* - * FD BPF & resampling tools parameters - *-----------------------------------------------------------------*/ - - /* open analysis for max. SR 48kHz */ - IF( NE_32( ( error = openCldfb( &st_fx->cldfbAna, CLDFB_ANALYSIS, 48000 ) ), IVAS_ERR_OK ) ) - { - return error; - } - - /* open analysis BPF for max. SR 16kHz */ - IF( NE_32( ( error = openCldfb( &st_fx->cldfbBPF, CLDFB_ANALYSIS, 16000 ) ), IVAS_ERR_OK ) ) - { - return error; - } - - /* open synthesis for output SR */ - IF( NE_32( ( error = openCldfb( &st_fx->cldfbSyn, CLDFB_SYNTHESIS, st_fx->output_Fs ) ), IVAS_ERR_OK ) ) - { - return error; - } - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move32(); - st_fx->last_active_bandsToZero_bwdec = 0; - st_fx->perc_bwddec = 0; - st_fx->last_flag_filter_NB = 0; - st_fx->active_frame_cnt_bwddec = 0; - st_fx->total_frame_cnt_bwddec = 0; - set16_fx( st_fx->flag_buffer, 0, 20 ); - st_fx->avg_nrg_LT = 0; - - st_fx->Ng_ener_ST_fx = -13056; - move16(); /*-51 IN Q8*/ - st_fx->old_Es_pred_fx = 0; - move16(); - set16_fx( st_fx->old_Aq_12_8_fx + 1, 0, M ); - st_fx->old_Aq_12_8_fx[0] = 4096; - move16(); /*1 in Q12*/ - - /*-----------------------------------------------------------------* - * SC-VBR parameters - *-----------------------------------------------------------------*/ - - IF( st_fx->element_mode == EVS_MONO ) - { - IF( ( st_fx->hSC_VBR = (SC_VBR_DEC_HANDLE) malloc( sizeof( SC_VBR_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SC-VBR\n" ) ); - } - - sc_vbr_dec_init( st_fx->hSC_VBR ); - } - ELSE - { - st_fx->hSC_VBR = NULL; - } - - st_fx->last_ppp_mode_dec = 0; - move16(); - st_fx->old_ppp_mode = 0; - move16(); - st_fx->ppp_mode_dec = 0; - move16(); - st_fx->last_nelp_mode_dec = 0; - move16(); - st_fx->nelp_mode_dec = 0; - move16(); - st_fx->prev_gain_pit_dec_fx = 0; - move16(); - st_fx->prev_tilt_code_dec_fx = 0; - move16(); - st_fx->vbr_hw_BWE_disable_dec = 0; - move16(); - st_fx->last_vbr_hw_BWE_disable_dec = 0; - move16(); - - /*-----------------------------------------------------------------* - * Mode 2 initialization - *-----------------------------------------------------------------*/ - - IF( ( st_fx->hPlcInfo = (T_PLCInfo_HANDLE) malloc( sizeof( T_PLCInfo ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PLC handle\n" ) ); - } - - st_fx->enablePlcWaveadjust = 0; - move16(); - - /* Init Decoder */ - open_decoder_LPD_fx( st_fx, st_fx->total_brate, st_fx->bwidth ); - - st_fx->m_decodeMode = DEC_NO_FRAM_LOSS; - move16(); - st_fx->m_frame_type = ACTIVE_FRAME; - move16(); - st_fx->m_old_frame_type = ACTIVE_FRAME; - move16(); - - resampleCldfb( st_fx->cldfbAna, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ), st_fx->L_frame, 1 ); - resampleCldfb( st_fx->cldfbBPF, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ), st_fx->L_frame, 1 ); - - test(); - IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || idchan == 0 ) /*&& mc_mode != MC_MODE_MCT && mc_mode != MC_MODE_PARAMUPMIX*/ ) - { - /* Create FD_CNG instance */ - - IF( NE_32( ( error = createFdCngDec_fx( &st_fx->hFdCngDec ) ), IVAS_ERR_OK ) ) - { - return error; - } - - /* Init FD-CNG */ - initFdCngDec_fx( st_fx, st_fx->cldfbSyn->scale ); - } - ELSE - { - st_fx->hFdCngDec = NULL; - } - - st_fx->lp_noise = -167772160l /*-20.f Q23*/; - move32(); - st_fx->force_lpd_reset = 0; - move16(); - - /*-----------------------------------------------------------------* - * initialzie Q values - *-----------------------------------------------------------------*/ - - st_fx->Q_syn2 = 0; - move16(); - st_fx->Q_exc = 8; - st_fx->prev_Q_exc = 0; - move16(); - st_fx->Q_syn = 0; - move16(); - st_fx->prev_Q_syn = 0; - move16(); - - FOR( i = 0; i < L_Q_MEM; i++ ) - { - st_fx->Q_subfr[i] = 8; - move16(); - } - - st_fx->prev_Q_exc_fr = 0; - move16(); - st_fx->prev_Q_syn_fr = 0; - move16(); - - /*----------------------------------------------------------------------------------* - * Stereo/IVAS parameters - *----------------------------------------------------------------------------------*/ - st_fx->tdm_LRTD_flag = 0; /* LRTD stereo mode flag */ - move16(); - st_fx->cna_dirac_flag = 0; /* CNA in DirAC flag */ - move16(); - st_fx->cng_sba_flag = 0; /* CNG in SBA flag */ - move16(); - st_fx->element_mode = EVS_MONO; /* element mode */ - move16(); - st_fx->element_brate = -1; /* element bitrate */ - move16(); - st_fx->low_rate_mode = 0; /* low-rate mode flag */ - move16(); - st_fx->last_low_rate_mode = 0; /* low-rate mode flag */ - move16(); -#ifdef DEBUGGING - st_fx->id_element = -1; /* element ID */ -#endif - st_fx->extl_orig = -1; /* extension layer */ - move16(); - st_fx->extl_brate_orig = 0; /* extension layer bitrate */ - move16(); - - return error; -} - -#endif /*----------------------------------------------------------------------* * init_decoder() * @@ -862,9 +50,9 @@ ivas_error init_decoder_evs( *----------------------------------------------------------------------*/ ivas_error init_decoder_fx( - Decoder_State *st_fx, /* o: Decoder static variables structure */ - const Word16 idchan, /* i : channel ID */ - const MC_MODE mc_mode /* i : MC mode */ + Decoder_State *st_fx, /* o : Decoder static variables structure */ + const Word16 idchan, /* i : channel ID */ + const MC_MODE mc_mode /* i : MC mode */ ) { Word16 i; @@ -1098,7 +286,7 @@ ivas_error init_decoder_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n" ) ); } - GSC_dec_init_ivas_fx( st_fx->hGSCDec ); + GSC_dec_init_fx( st_fx->hGSCDec ); } ELSE { @@ -1444,32 +632,56 @@ ivas_error init_decoder_fx( /*-----------------------------------------------------------------* * FD BPF & resampling tools parameters *-----------------------------------------------------------------*/ - test(); - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + + IF( st_fx->element_mode == EVS_MONO ) { /* open analysis for max. SR 48kHz */ - IF( NE_32( ( error = openCldfb_ivas_fx( &st_fx->cldfbAna, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS, DEC ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = openCldfb( &st_fx->cldfbAna, CLDFB_ANALYSIS, 48000 ) ), IVAS_ERR_OK ) ) { return error; } /* open analysis BPF for max. SR 16kHz */ - IF( NE_32( ( error = openCldfb_ivas_fx( &st_fx->cldfbBPF, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS, DEC ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = openCldfb( &st_fx->cldfbBPF, CLDFB_ANALYSIS, 16000 ) ), IVAS_ERR_OK ) ) + { + return error; + } + + /* open synthesis for output SR */ + IF( NE_32( ( error = openCldfb( &st_fx->cldfbSyn, CLDFB_SYNTHESIS, st_fx->output_Fs ) ), IVAS_ERR_OK ) ) { return error; } } ELSE { - st_fx->cldfbAna = NULL; - st_fx->cldfbBPF = NULL; - } + test(); + test(); + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + { + /* open analysis for max. SR 48kHz */ + IF( NE_32( ( error = openCldfb_ivas_fx( &st_fx->cldfbAna, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS, DEC ) ), IVAS_ERR_OK ) ) + { + return error; + } - /* open synthesis for output SR */ - IF( NE_32( ( error = openCldfb_ivas_fx( &st_fx->cldfbSyn, CLDFB_SYNTHESIS, st_fx->output_Fs, CLDFB_PROTOTYPE_1_25MS, DEC ) ), IVAS_ERR_OK ) ) - { - return error; + /* open analysis BPF for max. SR 16kHz */ + IF( NE_32( ( error = openCldfb_ivas_fx( &st_fx->cldfbBPF, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS, DEC ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + ELSE + { + st_fx->cldfbAna = NULL; + st_fx->cldfbBPF = NULL; + } + + /* open synthesis for output SR */ + IF( NE_32( ( error = openCldfb_ivas_fx( &st_fx->cldfbSyn, CLDFB_SYNTHESIS, st_fx->output_Fs, CLDFB_PROTOTYPE_1_25MS, DEC ) ), IVAS_ERR_OK ) ) + { + return error; + } } st_fx->cldfbSynHB = NULL; @@ -1630,6 +842,7 @@ ivas_error init_decoder_fx( /*-----------------------------------------------------------------* * Mode 2 initialization *-----------------------------------------------------------------*/ + IF( ( st_fx->element_mode == EVS_MONO ) ) { IF( ( st_fx->hPlcInfo = (T_PLCInfo_HANDLE) malloc( sizeof( T_PLCInfo ) ) ) == NULL ) @@ -1654,18 +867,24 @@ ivas_error init_decoder_fx( st_fx->hTECDec = NULL; } - /* Init Decoder */ - Word16 Q_syn_Overl_TDAC = 0, Q_fer_samples = 0, Q_syn_Overl = 0, Q_syn_Overl_TDACFB = 0, Q_syn_OverlFB = 0, Q_old_out = 0, Q_old_outLB = 0, Q_old_Aq_12_8 = 0; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - open_decoder_LPD_ivas_fx( st_fx, st_fx->total_brate, st_fx->last_total_brate, st_fx->bwidth, 0, st_fx->element_mode, 1, &Q_syn_Overl_TDAC, &Q_fer_samples, &Q_syn_Overl, &Q_syn_Overl_TDACFB, &Q_syn_OverlFB, &Q_old_out, &Q_old_outLB, &Q_old_Aq_12_8 ); + IF( st_fx->element_mode == EVS_MONO ) + { + open_decoder_LPD_fx( st_fx, st_fx->total_brate, st_fx->bwidth ); + } + ELSE + { + Word16 Q_syn_Overl_TDAC = 0, Q_fer_samples = 0, Q_syn_Overl = 0, Q_syn_Overl_TDACFB = 0, Q_syn_OverlFB = 0, Q_old_out = 0, Q_old_outLB = 0, Q_old_Aq_12_8 = 0; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + open_decoder_LPD_ivas_fx( st_fx, st_fx->total_brate, st_fx->last_total_brate, st_fx->bwidth, 0, st_fx->element_mode, 1, &Q_syn_Overl_TDAC, &Q_fer_samples, &Q_syn_Overl, &Q_syn_Overl_TDACFB, &Q_syn_OverlFB, &Q_old_out, &Q_old_outLB, &Q_old_Aq_12_8 ); + } /* PLC mode initialization */ st_fx->m_decodeMode = DEC_NO_FRAM_LOSS; @@ -1677,11 +896,19 @@ ivas_error init_decoder_fx( st_fx->m_old_frame_type = ACTIVE_FRAME; move16(); - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) + IF( st_fx->element_mode == EVS_MONO ) + { + resampleCldfb( st_fx->cldfbAna, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ), st_fx->L_frame, 1 ); + resampleCldfb( st_fx->cldfbBPF, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ), st_fx->L_frame, 1 ); + } + ELSE { - resampleCldfb_ivas_fx( st_fx->cldfbAna, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ) ); - resampleCldfb_ivas_fx( st_fx->cldfbBPF, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ) ); + test(); + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) + { + resampleCldfb_ivas_fx( st_fx->cldfbAna, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ) ); + resampleCldfb_ivas_fx( st_fx->cldfbBPF, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ) ); + } } /*-----------------------------------------------------------------* @@ -1694,7 +921,6 @@ ivas_error init_decoder_fx( IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || idchan == 0 ) && NE_16( mc_mode, MC_MODE_MCT ) && NE_16( mc_mode, MC_MODE_PARAMUPMIX ) ) { /* Create FD_CNG instance */ - IF( NE_32( ( error = createFdCngDec_fx( &st_fx->hFdCngDec ) ), IVAS_ERR_OK ) ) { return error; diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index a149f78b3..720d9905f 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -1320,7 +1320,7 @@ ivas_error create_cpe_dec( st->is_ism_format = 0; move16(); - IF( NE_32( ( error = init_decoder_ivas_fx( st, n, st_ivas->mc_mode ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = init_decoder_fx( st, n, st_ivas->mc_mode ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_dec/ivas_sce_dec_fx.c b/lib_dec/ivas_sce_dec_fx.c index 6e1893015..77c53c5ef 100644 --- a/lib_dec/ivas_sce_dec_fx.c +++ b/lib_dec/ivas_sce_dec_fx.c @@ -416,22 +416,9 @@ ivas_error create_sce_dec( move16(); } - // if (st_ivas->mode == IVAS_DEC_MODE_EVS) - IF( EQ_16( st->element_mode, EVS_MONO ) ) + IF( ( error = init_decoder_fx( st, 0, st_ivas->mc_mode ) ) != IVAS_ERR_OK ) { - error = init_decoder_fx( st, EVS_MONO ); - IF( error ) - { - return error; - } - } - ELSE - { - error = init_decoder_ivas_fx( st, 0, st_ivas->mc_mode ); - IF( error ) - { - return error; - } + return error; } IF( EQ_16( (Word16) st_ivas->ivas_format, SBA_FORMAT ) && ( EQ_16( (Word16) st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) || ( EQ_16( (Word16) st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) && EQ_16( st_ivas->nchan_transport, 1 ) ) ) ) diff --git a/lib_dec/ivas_stereo_switching_dec_fx.c b/lib_dec/ivas_stereo_switching_dec_fx.c index 2d6ea5292..a4b8f2353 100644 --- a/lib_dec/ivas_stereo_switching_dec_fx.c +++ b/lib_dec/ivas_stereo_switching_dec_fx.c @@ -159,7 +159,7 @@ static ivas_error allocate_CoreCoder_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n" ) ); } - GSC_dec_init_ivas_fx( st->hGSCDec ); + GSC_dec_init_fx( st->hGSCDec ); } IF( st->hPFstat == NULL ) diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index 0c5f7db85..5e99ad185 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -1032,7 +1032,6 @@ typedef struct Decoder_State Word16 bitstreamformat; /* Bitstream format flag (G.192/MIME/VOIP_G192_RTP/VOIP_RTPDUMP) */ Word16 sdp_hf_only; /* RTP payload format parameter: only Header-Full format without zero padding for size collision avoidance */ Word16 amrwb_rfc4867_flag; /* MIME from rfc4867 is used */ - Word16 total_num_bits; /* == st->total_brate / 50 */ Word16 BER_detect; /* flag to signal detected bit error in the bitstream */ Word32 output_Fs; /* output sampling rate */ Word16 output_frame_fx; /* Output frame length Q0*/ -- GitLab From 1859de271f138e1ba8117af8952e044a94149ee1 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 8 Sep 2025 21:47:34 +0200 Subject: [PATCH 03/15] remove create_evs_sce_enc_fx() --- lib_com/ivas_prot_fx.h | 13 +-- lib_dec/init_dec_fx.c | 1 + lib_enc/init_enc_fx.c | 8 +- lib_enc/ivas_corecoder_enc_reconfig_fx.c | 2 +- lib_enc/ivas_init_enc_fx.c | 28 ++--- lib_enc/ivas_sce_enc_fx.c | 134 +++++------------------ 6 files changed, 40 insertions(+), 146 deletions(-) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 12ad07e5c..5ab2b2509 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -60,15 +60,8 @@ void ivas_masa_dec_close_fx( MASA_DECODER_HANDLE *hMasa /* i/o: MASA metadata structure */ ); -ivas_error create_evs_sce_enc_fx( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const Word16 sce_id, /* i : SCE # identifier */ - const Word32 element_brate /* i : element bitrate */ -); - void destroy_sce_enc_fx( - SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ - Flag is_evs /* i : Flag to indicate EVS encoder */ + SCE_ENC_HANDLE hSCE /* i/o: SCE encoder structure */ ); void generate_gridEq_fx( @@ -807,10 +800,6 @@ void destroy_core_enc_fx( ENC_CORE_HANDLE hCoreCoder /* i/o: core encoder structure */ ); -void destroy_evs_core_enc_fx( - ENC_CORE_HANDLE hCoreCoder /* i/o: core encoder structure */ -); - ivas_error ivas_sce_dec_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const Word16 sce_id, /* i : SCE # identifier */ diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index c05e5fb71..39cc5d065 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -358,6 +358,7 @@ ivas_error init_decoder_fx( /*-----------------------------------------------------------------* * LD music post-filter *-----------------------------------------------------------------*/ + test(); test(); IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index a0dea46be..00c482f6c 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -886,6 +886,7 @@ ivas_error init_encoder_fx( InitTransientDetection_fx( extract_l( Mult_32_16( st_fx->input_Fs, 0x0290 ) ), NS2SA_FX2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ), &st_fx->transientDetection ); + st_fx->hTranDet = NULL; st_fx->Q_syn2 = 0; move16(); @@ -2124,9 +2125,8 @@ ivas_error init_encoder_ivas_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Transient Detection\n" ) ); } - Word16 temp; - Word16 frame_length = BASOP_Util_Divide3232_Scale( st->input_Fs, FRAMES_PER_SEC, &temp ); - frame_length = shr( frame_length, sub( 15, temp ) ); + + Word16 frame_length = extract_l( Mult_32_16( st->input_Fs, 0x0290 ) ); IF( GT_16( st->element_mode, EVS_MONO ) ) { @@ -2134,7 +2134,7 @@ ivas_error init_encoder_ivas_fx( } ELSE { - InitTransientDetection_fx( extract_l( Mult_32_16( st->input_Fs, 0x0290 ) ), + InitTransientDetection_fx( frame_length, NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), &st->transientDetection ); } diff --git a/lib_enc/ivas_corecoder_enc_reconfig_fx.c b/lib_enc/ivas_corecoder_enc_reconfig_fx.c index 019361561..ce2fa0d93 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig_fx.c +++ b/lib_enc/ivas_corecoder_enc_reconfig_fx.c @@ -372,7 +372,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( q_input_buff[sce_id] = st_ivas->hSCE[sce_id]->hCoreCoder[0]->q_old_inp32; move16(); } - destroy_sce_enc_fx( st_ivas->hSCE[sce_id], ( EQ_16( st_ivas->hEncoderConfig->element_mode_init, EVS_MONO ) && !st_ivas->hEncoderConfig->stereo_dmx_evs ) ); + destroy_sce_enc_fx( st_ivas->hSCE[sce_id] ); st_ivas->hSCE[sce_id] = NULL; } diff --git a/lib_enc/ivas_init_enc_fx.c b/lib_enc/ivas_init_enc_fx.c index 3c491edca..1b35b7022 100644 --- a/lib_enc/ivas_init_enc_fx.c +++ b/lib_enc/ivas_init_enc_fx.c @@ -421,6 +421,7 @@ void ivas_initialize_handles_enc_fx( * * Initialize IVAS encoder state structure *-------------------------------------------------------------------*/ + ivas_error ivas_init_encoder_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) @@ -565,11 +566,13 @@ ivas_error ivas_init_encoder_fx( move16(); sce_id = 0; move16(); + test(); - IF( NE_32( ( error = create_evs_sce_enc_fx( st_ivas, sce_id, ivas_total_brate ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = create_sce_enc_fx( st_ivas, sce_id, ivas_total_brate ) ), IVAS_ERR_OK ) ) { return error; } + /* prepare stereo downmix for EVS */ IF( EQ_16( hEncoderConfig->stereo_dmx_evs, 1 ) ) { @@ -1034,6 +1037,8 @@ ivas_error ivas_init_encoder_fx( return error; } + + /*------------------------------------------------------------------------- * destroy_core_enc() * @@ -1044,8 +1049,6 @@ void destroy_core_enc_fx( ENC_CORE_HANDLE hCoreCoder /* i/o: core encoder structure */ ) { - Word16 i; - destroy_cldfb_encoder_fx( hCoreCoder ); IF( hCoreCoder->hSignalBuf != NULL ) @@ -1056,12 +1059,6 @@ void destroy_core_enc_fx( IF( hCoreCoder->hBstr != NULL ) { - /* reset buffer of indices */ - FOR( i = 0; i < hCoreCoder->hBstr->nb_ind_tot; i++ ) - { - hCoreCoder->hBstr->ind_list[i].nb_bits = -1; - move16(); - } free( hCoreCoder->hBstr ); hCoreCoder->hBstr = NULL; } @@ -1092,8 +1089,7 @@ void destroy_core_enc_fx( IF( hCoreCoder->hVAD_CLDFB != NULL ) { - /* This is not required as we are not allocating memory dynamically */ - // free( hCoreCoder->hVAD_CLDFB ); + free( hCoreCoder->hVAD_CLDFB ); hCoreCoder->hVAD_CLDFB = NULL; } @@ -1198,14 +1194,6 @@ void destroy_evs_core_enc_fx( { Word16 i; - destroy_cldfb_encoder_fx( hCoreCoder ); - - IF( hCoreCoder->hSignalBuf != NULL ) - { - free( hCoreCoder->hSignalBuf ); - hCoreCoder->hSignalBuf = NULL; - } - IF( hCoreCoder->hBstr != NULL ) { /* reset buffer of indices */ @@ -1364,7 +1352,7 @@ void ivas_destroy_enc_fx( { if ( st_ivas->hSCE[i] != NULL ) { - destroy_sce_enc_fx( st_ivas->hSCE[i], EQ_16( st_ivas->hEncoderConfig->element_mode_init, EVS_MONO ) ); + destroy_sce_enc_fx( st_ivas->hSCE[i] ); st_ivas->hSCE[i] = NULL; } } diff --git a/lib_enc/ivas_sce_enc_fx.c b/lib_enc/ivas_sce_enc_fx.c index a36fe44de..aeb4f9c60 100644 --- a/lib_enc/ivas_sce_enc_fx.c +++ b/lib_enc/ivas_sce_enc_fx.c @@ -385,17 +385,18 @@ ivas_error ivas_sce_enc_fx( } #endif - pop_wmops(); return error; } + /*------------------------------------------------------------------------- * create_sce_enc() * * Create, allocate and initialize IVAS encoder SCE handle *-------------------------------------------------------------------------*/ + ivas_error create_sce_enc_fx( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const Word16 sce_id, /* i : SCE # identifier */ @@ -404,7 +405,6 @@ ivas_error create_sce_enc_fx( { SCE_ENC_HANDLE hSCE; Encoder_State *st; - ivas_error error; error = IVAS_ERR_OK; @@ -433,6 +433,7 @@ ivas_error create_sce_enc_fx( /*-----------------------------------------------------------------* * Metadata: allocate and initialize *-----------------------------------------------------------------*/ + test(); IF( NE_16( st_ivas->hEncoderConfig->ivas_format, MONO_FORMAT ) && EQ_16( sce_id, sub( st_ivas->nSCE, 1 ) ) ) { @@ -473,123 +474,47 @@ ivas_error create_sce_enc_fx( st->max_bwidth = st_ivas->hEncoderConfig->max_bwidth; st->input_Fs = st_ivas->hEncoderConfig->input_Fs; - 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 ) ) - { - return error; - } - hSCE->hCoreCoder[0] = st; - - st_ivas->hSCE[sce_id] = hSCE; - - return error; -} - -/*------------------------------------------------------------------------- - * create_evs_sce_enc_fx() - * - * Create, allocate and initialize EVS encoder SCE handle - *-------------------------------------------------------------------------*/ -ivas_error create_evs_sce_enc_fx( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const Word16 sce_id, /* i : SCE # identifier */ - const Word32 element_brate /* i : element bitrate */ -) -{ - SCE_ENC_HANDLE hSCE = st_ivas->hSCE[sce_id]; - Encoder_State *st_fx; - - ivas_error error; - - error = IVAS_ERR_OK; - move32(); - - /*-----------------------------------------------------------------* - * Allocate SCE handle - *-----------------------------------------------------------------*/ - - IF( ( hSCE = (SCE_ENC_HANDLE) malloc( sizeof( SCE_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SCE\n" ) ); - } - - /*-----------------------------------------------------------------* - * Initialization - general parameters - *-----------------------------------------------------------------*/ - - hSCE->sce_id = sce_id; - move16(); - hSCE->element_brate = element_brate; - move32(); - hSCE->last_element_brate = hSCE->element_brate; - move32(); - /*-----------------------------------------------------------------* - * Metadata: allocate and initialize - *-----------------------------------------------------------------*/ - test(); - IF( NE_32( st_ivas->hEncoderConfig->ivas_format, MONO_FORMAT ) && EQ_16( sce_id, sub( st_ivas->nSCE, 1 ) ) ) + IF( st->element_mode == EVS_MONO ) { - IF( NE_32( ( error = ivas_initialize_MD_bstr_enc_fx( &( hSCE->hMetaData ), st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = init_encoder_fx( st, st_ivas->hEncoderConfig->var_SID_rate_flag, st_ivas->hEncoderConfig->interval_SID ) ), IVAS_ERR_OK ) ) { return error; } - } - ELSE - { - hSCE->hMetaData = NULL; - } - /*-----------------------------------------------------------------* - * Core Coder, 1 instance: allocate and initialize - *-----------------------------------------------------------------*/ - IF( ( st_fx = (ENC_CORE_HANDLE) malloc( sizeof( Encoder_State ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n" ) ); + /* set pointer to the buffer of indices */ + st->hBstr->ind_list = st_ivas->ind_list; + st->hBstr->ivas_ind_list_zero = &st_ivas->ind_list; + st->hBstr->ivas_max_num_indices = &st_ivas->ivas_max_num_indices; + st->hBstr->nb_ind_tot = 0; + move16(); + st->hBstr->nb_bits_tot = 0; + move16(); + st->hBstr->st_ivas = st_ivas; } - memset( st_fx, 0, sizeof( Encoder_State ) ); - - copy_encoder_config_fx( st_ivas, st_fx, 1 ); - - st_fx->bitstreamformat = G192; - move16(); - - st_fx->total_brate = st_ivas->hEncoderConfig->ivas_total_brate; - move32(); - - IF( NE_32( ( error = init_encoder_fx( st_fx, st_ivas->hEncoderConfig->var_SID_rate_flag, st_ivas->hEncoderConfig->interval_SID ) ), IVAS_ERR_OK ) ) + ELSE { - return error; + 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 ) ) + { + return error; + } } - /*-----------------------------------------------------------------* - * Bitstream - *-----------------------------------------------------------------*/ - - /* set pointer to the buffer of indices */ - st_fx->hBstr->ind_list = st_ivas->ind_list; - st_fx->hBstr->ivas_ind_list_zero = &st_ivas->ind_list; - st_fx->hBstr->ivas_max_num_indices = &st_ivas->ivas_max_num_indices; - st_fx->hBstr->nb_ind_tot = 0; - move16(); - st_fx->hBstr->nb_bits_tot = 0; - move16(); - st_fx->hBstr->st_ivas = st_ivas; - - hSCE->hCoreCoder[0] = st_fx; + hSCE->hCoreCoder[0] = st; st_ivas->hSCE[sce_id] = hSCE; return error; } + /*------------------------------------------------------------------------- - * destroy_sce_enc_fx() + * destroy_sce_enc() * * Destroy and deallocate IVAS encoder SCE handle *-------------------------------------------------------------------------*/ void destroy_sce_enc_fx( - SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ - Flag is_evs /* i : Flag to indicate EVS encoder*/ + SCE_ENC_HANDLE hSCE /* i/o: SCE encoder structure */ ) { Encoder_State *st; @@ -598,17 +523,8 @@ void destroy_sce_enc_fx( IF( st != NULL ) { - test(); - IF( ( st->element_mode == EVS_MONO ) && is_evs ) - { - destroy_evs_core_enc_fx( st ); - st = NULL; - } - ELSE - { - destroy_core_enc_fx( st ); - st = NULL; - } + destroy_core_enc_fx( st ); + st = NULL; } ivas_destroy_MD_bstr_enc_fx( &( hSCE->hMetaData ) ); -- GitLab From 2a0141aeecb6bb26d6648fdf75e9d5da7c9d63e5 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 9 Sep 2025 13:35:23 +0200 Subject: [PATCH 04/15] - updates to init_encoder_ivas_fx() - remove duplication of st->last_vad_spa_fx - remove duplication of st->last_ener_fx --- lib_com/prot_fx.h | 24 +- lib_dec/fd_cng_dec_fx.c | 2 +- lib_enc/fd_cng_enc_fx.c | 39 +- lib_enc/gs_enc_fx.c | 2 +- lib_enc/init_enc_fx.c | 621 +++++++++++++++++++----------- lib_enc/ivas_cpe_enc_fx.c | 2 +- lib_enc/ivas_sce_enc_fx.c | 2 +- lib_enc/ivas_spar_encoder_fx.c | 2 +- lib_enc/prot_fx_enc.h | 26 +- lib_enc/speech_music_classif_fx.c | 4 +- lib_enc/stat_enc.h | 3 - lib_enc/transient_detection_fx.c | 18 +- 12 files changed, 451 insertions(+), 294 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 20c00a39f..7cf0148eb 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -7270,15 +7270,15 @@ void FEC_lsf2lsp_interp( ); -// fd_cng_dec_fx.c -ivas_error createFdCngDec_fx( HANDLE_FD_CNG_DEC *hFdCngDec ); +ivas_error createFdCngDec_fx( + HANDLE_FD_CNG_DEC *hFdCngDec ); void initFdCngDec_fx( DEC_CORE_HANDLE st, /* i/o: decoder state structure */ - Word16 scale ); + const Word16 scale ); -/* Delete the instance of type FD_CNG */ -void deleteFdCngDec_fx( HANDLE_FD_CNG_DEC *hFdCngDec ); +void deleteFdCngDec_fx( + HANDLE_FD_CNG_DEC *hFdCngDec ); /* Configure CLDFB-CNG */ void configureFdCngDec_fx( @@ -11053,14 +11053,12 @@ void read_next_force( #endif ivas_error init_encoder_ivas_fx( - Encoder_State *st, /* i/o: state structure */ - Encoder_Struct *st_ivas, /* i/o: encoder state structure */ - const Word16 idchan, /* i : channel ID */ - const Word16 var_SID_rate_flag, /* i : flag for variable SID update rate */ - const Word16 interval_SID, /* i : interval for SID update */ - const Word16 vad_only_flag, /* i : flag to indicate front-VAD structure */ - const ISM_MODE ism_mode, /* i : ISM mode */ - const Word32 element_brate /* i : element bitrate */ + Encoder_State *st, /* i/o: state structure */ + Encoder_Struct *st_ivas, /* i/o: encoder state structure */ + const Word16 idchan, /* i : channel ID */ + const Word16 vad_only_flag, /* i : flag to indicate front-VAD structure */ + const ISM_MODE ism_mode, /* i : ISM mode */ + const Word32 element_brate /* i : element bitrate */ ); ivas_error acelp_core_enc_ivas_fx( diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 47724c6e6..087351c7e 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -193,7 +193,7 @@ void initFdCngDec_ivas_fx( void initFdCngDec_fx( DEC_CORE_HANDLE st, /* i/o: decoder state structure */ - Word16 scale /*Q15*/ ) + const Word16 scale /*Q15*/ ) { /* Initialize common */ HANDLE_FD_CNG_DEC hFdCngDec; diff --git a/lib_enc/fd_cng_enc_fx.c b/lib_enc/fd_cng_enc_fx.c index 587016e5f..fefc18855 100644 --- a/lib_enc/fd_cng_enc_fx.c +++ b/lib_enc/fd_cng_enc_fx.c @@ -35,26 +35,33 @@ extern void BASOP_getTables( const PWord16 **ptwiddle, const PWord16 **sin_twidd /************************************* * Create an instance of type FD_CNG * *************************************/ -void createFdCngEnc_fx( HANDLE_FD_CNG_ENC *hFdCngEnc ) +ivas_error createFdCngEnc_fx( + HANDLE_FD_CNG_ENC *hFdCngEnc ) { HANDLE_FD_CNG_ENC hs; + ivas_error error; /* Allocate memory */ - hs = (HANDLE_FD_CNG_ENC) calloc( 1, sizeof( FD_CNG_ENC ) ); - move16(); + IF( ( hs = (HANDLE_FD_CNG_ENC) malloc( sizeof( FD_CNG_ENC ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for FD CNG ENC structure" ); + } + IF( ( error = createFdCngCom_fx( &( hs->hFdCngCom ) ) ) != IVAS_ERR_OK ) + { + return error; + } - createFdCngCom_fx( &( hs->hFdCngCom ) ); *hFdCngEnc = hs; move16(); - return; + return IVAS_ERR_OK; } void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, - Word32 input_Fs, /* Q0 */ - Word16 scale ) + const Word32 input_Fs, /* Q0 */ + const Word16 scale ) { Word16 j; HANDLE_FD_CNG_COM hsCom = hsEnc->hFdCngCom; @@ -155,9 +162,11 @@ void initFdCngEnc_fx( /************************************ * Configure FD_CNG * ************************************/ -void configureFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, /* i/o: Contains the variables related to the FD-based CNG process */ - Word16 bandwidth, /* i: bandwidth Q0*/ - Word32 bitrate /* Q0 */ + +void configureFdCngEnc_fx( + HANDLE_FD_CNG_ENC hsEnc, /* i/o: Contains the variables related to the FD-based CNG process */ + const Word16 bandwidth, /* i: bandwidth Q0*/ + const Word32 bitrate /* Q0 */ ) { HANDLE_FD_CNG_COM hsCom = hsEnc->hFdCngCom; @@ -279,6 +288,8 @@ void configureFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, /* i/o: Contains the variabl BASOP_getTables( &hsCom->olapWinSyn, NULL, NULL, shr( hsCom->fftlen, 2 ) ); hsCom->frameSize = shr( hsCom->fftlen, 1 ); move16(); + + return; } void configureFdCngEnc_ivas_fx( @@ -416,12 +427,14 @@ void configureFdCngEnc_ivas_fx( return; } + /************************************** * Delete the instance of type FD_CNG * **************************************/ -void deleteFdCngEnc_fx( HANDLE_FD_CNG_ENC *hFdCngEnc ) -{ +void deleteFdCngEnc_fx( + HANDLE_FD_CNG_ENC *hFdCngEnc ) +{ HANDLE_FD_CNG_ENC hsEnc; hsEnc = *hFdCngEnc; move16(); @@ -432,6 +445,8 @@ void deleteFdCngEnc_fx( HANDLE_FD_CNG_ENC *hFdCngEnc ) *hFdCngEnc = NULL; move16(); } + + return; } diff --git a/lib_enc/gs_enc_fx.c b/lib_enc/gs_enc_fx.c index 7bf52970d..58f9a8d51 100644 --- a/lib_enc/gs_enc_fx.c +++ b/lib_enc/gs_enc_fx.c @@ -1000,7 +1000,7 @@ void gsc_enc_fx( highband_exc_dct_in_fx( st_fx->core_brate, mfreq_bindiv_loc, last_bin, Diff_len, hGSCEnc->noise_lev, tmp_band, exc_diffQ, &hGSCEnc->seed_tcx, Ener_per_bd_iQ, nb_subfr, exc_dct_in, st_fx->last_coder_type, bitallocation_band, lsf_new, - hGSCEnc->last_exc_dct_in_fx, &st_fx->last_ener_fx, hGSCEnc->last_bitallocation_band, bitallocation_exc, 0, st_fx->coder_type, + hGSCEnc->last_exc_dct_in_fx, &hGSCEnc->last_ener_fx, hGSCEnc->last_bitallocation_band, bitallocation_exc, 0, st_fx->coder_type, st_fx->bwidth, exc_wo_nf, Q_PVQ_OUT, Q_exc, st_fx->GSC_noisy_speech, NULL, st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); exc_dct_in[0] = 0; diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index b8013326f..793c5f9b8 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -6,7 +6,6 @@ #include "cnst.h" /* Common constants */ #include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Static table prototypes */ -// #include "prot_fx.h" /* Function prototypes */ #include "stl.h" #include "ivas_cnst.h" #include "ivas_error.h" @@ -37,112 +36,180 @@ ivas_error init_encoder_fx( move16(); ISM_MODE ism_mode = ISM_MODE_NONE; ivas_error error; + Encoder_State *st = st_fx; error = IVAS_ERR_OK; + Word16 frame_length = extract_l( Mpy_32_32( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + /*-----------------------------------------------------------------* * General signal buffers *-----------------------------------------------------------------*/ IF( !vad_only_flag ) { - IF( ( st_fx->hSignalBuf = (SIGNAL_BUFFERS_ENC_HANDLE) malloc( sizeof( SIGNAL_BUFFERS_ENC_DATA ) ) ) == NULL ) + IF( ( st->hSignalBuf = (SIGNAL_BUFFERS_ENC_HANDLE) malloc( sizeof( SIGNAL_BUFFERS_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Signal buffers\n" ) ); } - st_fx->Bin_E_old_fx = st_fx->hSignalBuf->Bin_E_old_fx; - st_fx->mem_decim_fx = st_fx->hSignalBuf->mem_decim_fx; - st_fx->mem_decim16k_fx = st_fx->hSignalBuf->mem_decim16k_fx; - st_fx->old_inp_12k8_fx = st_fx->hSignalBuf->old_inp_12k8_fx; - st_fx->old_inp_16k_fx = st_fx->hSignalBuf->old_inp_16k_fx; - st_fx->buf_speech_enc_pe = st_fx->hSignalBuf->buf_speech_enc_pe; - st_fx->buf_synth = st_fx->hSignalBuf->buf_synth; - st_fx->buf_speech_enc = st_fx->hSignalBuf->buf_speech_enc; - st_fx->buf_wspeech_enc = st_fx->hSignalBuf->buf_wspeech_enc; + st->Bin_E_old_fx = st->hSignalBuf->Bin_E_old_fx; + st->mem_decim_fx = st->hSignalBuf->mem_decim_fx; + st->mem_decim16k_fx = st->hSignalBuf->mem_decim16k_fx; + st->old_inp_12k8_fx = st->hSignalBuf->old_inp_12k8_fx; + st->old_inp_16k_fx = st->hSignalBuf->old_inp_16k_fx; + st->buf_speech_enc_pe = st->hSignalBuf->buf_speech_enc_pe; + st->buf_synth = st->hSignalBuf->buf_synth; + st->buf_speech_enc = st->hSignalBuf->buf_speech_enc; + st->buf_wspeech_enc = st->hSignalBuf->buf_wspeech_enc; + set32_fx( st->Bin_E_old_fx, 0, L_FFT / 2 ); + st->q_Bin_E_old = Q31; + move16(); + set16_fx( st->hSignalBuf->buf_speech_enc, 0, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); + st->exp_buf_speech_enc = 0; + move16(); + set16_fx( st->hSignalBuf->buf_wspeech_enc, 0, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); + st->exp_buf_wspeech_enc = 0; + move16(); /* initializations */ - set16_fx( st_fx->old_inp_12k8_fx, 0, L_INP_MEM ); /* memory of input signal at 12.8kHz */ - set16_fx( st_fx->old_inp_16k_fx, 0, L_INP_MEM ); - set16_fx( st_fx->mem_decim16k_fx, 0, 2 * L_FILT_MAX ); - set16_fx( st_fx->mem_decim_fx, 0, 2 * L_FILT_MAX ); - set32_fx( st_fx->Bin_E_old_fx, 0, L_FFT / 2 ); - st_fx->q_Bin_E_old = Q31; + set32_fx( st->Bin_E_old_fx, 0, L_FFT / 2 ); + st->q_Bin_E_old = Q31; + move16(); + set16_fx( st->mem_decim_fx, 0, shl( L_FILT_MAX, 1 ) ); + set16_fx( st->mem_decim_fx_q_inp, 0, shl( L_FILT_MAX, 1 ) ); + set16_fx( st->mem_decim16k_fx, 0, shl( L_FILT_MAX, 1 ) ); + set16_fx( st->old_inp_12k8_fx, 0, L_INP_MEM ); + set16_fx( st->old_inp_16k_fx, 0, L_INP_MEM ); + st->exp_old_inp_16k = 0; + st->exp_old_inp_12k8 = 0; + move16(); + move16(); + + st->input_buff_fx = st->hSignalBuf->input_buff; + st->input_buff32_fx = st->hSignalBuf->input_buff32; + set16_fx( st->input_buff_fx, 0, add( L_FRAME48k, add( L_FRAME48k, NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ) ) ); + st->q_inp = Q15; + move16(); + st->mem_preemph_q = Q15; move16(); + st->mem_q = Q15; + move16(); + st->q_old_inp = Q15; + move16(); + set32_fx( st->input_buff32_fx, 0, add( L_FRAME48k, add( L_FRAME48k, NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ) ) ); + st->q_inp32 = Q31; + move16(); + st->q_old_inp32 = Q31; + move16(); + st->old_input_signal_fx = st->input_buff_fx; + st->old_input_signal32_fx = st->input_buff32_fx; - st_fx->input_buff_fx = st_fx->hSignalBuf->input_buff; - set16_fx( st_fx->input_buff_fx, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); - st_fx->old_input_signal_fx = st_fx->input_buff_fx; - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) + IF( st->element_mode == EVS_MONO ) { - st_fx->input_fx = st_fx->input_buff_fx + st_fx->input_Fs / FRAMES_PER_SEC + NS2SA_FX2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ); + st->input32_fx = st->input_buff32_fx + add( frame_length, NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ) ); + st->input_fx = st->input_buff_fx + add( frame_length, NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ) ); } ELSE { - st_fx->input_fx = st_fx->input_buff_fx + st_fx->input_Fs / FRAMES_PER_SEC; + st->input32_fx = st->input_buff32_fx + frame_length; + st->input_fx = st->input_buff_fx + frame_length; } } ELSE { - st_fx->hSignalBuf = NULL; - st_fx->Bin_E_old_fx = NULL; - st_fx->mem_decim_fx = NULL; - st_fx->mem_decim16k_fx = NULL; - st_fx->old_inp_12k8_fx = NULL; - st_fx->old_inp_16k_fx = NULL; - st_fx->buf_speech_enc_pe = NULL; - st_fx->buf_synth = NULL; - st_fx->buf_speech_enc = NULL; - st_fx->buf_wspeech_enc = NULL; - st_fx->input_buff_fx = NULL; + st->hSignalBuf = NULL; + st->Bin_E_old_fx = NULL; + st->mem_decim_fx = NULL; + st->mem_decim16k_fx = NULL; + st->old_inp_12k8_fx = NULL; + st->old_inp_16k_fx = NULL; + st->buf_speech_enc_pe = NULL; + st->buf_synth = NULL; + st->buf_speech_enc = NULL; + st->buf_wspeech_enc = NULL; + st->input_buff_fx = NULL; } /*-----------------------------------------------------------------* * ACELP core parameters *-----------------------------------------------------------------*/ - st_fx->last_core = -1; - move16(); - if ( st_fx->Opt_AMR_WB ) + IF( st->Opt_AMR_WB ) { - st_fx->last_core = AMR_WB_CORE; - move16(); + st->last_core = AMR_WB_CORE; + } + ELSE + { + st->last_core = -1; } + move16(); - st_fx->L_frame = L_FRAME; + st->L_frame = L_FRAME; + move16(); + st->last_coder_type = GENERIC; move16(); - st_fx->last_coder_type = GENERIC; + st->coder_type = GENERIC; move16(); - st_fx->last_total_brate = st_fx->total_brate; - move32(); - st_fx->last_total_brate_cng = -1; + st->last_total_brate = st->total_brate; move32(); - st_fx->last_core_brate = st_fx->total_brate; + st->last_bits_frame_nominal = -1; + move16(); + st->last_total_brate_cng = -1; + move16(); + st->last_core_brate = st->total_brate; move32(); - st_fx->extl = -1; + st->dtx_sce_sba = 0; move16(); - st_fx->last_extl = -1; + st->extl = -1; + move16(); + st->last_extl = -1; move16(); - st_fx->last_L_frame = L_FRAME; + st->last_L_frame = L_FRAME; move16(); - st_fx->rate_switching_reset = 0; + st->rate_switching_reset = 0; move16(); - st_fx->rate_switching_reset_16kHz = 0; + st->rate_switching_reset_16kHz = 0; + move16(); + st->clas = UNVOICED_CLAS; + move16(); + st->low_rate_mode = 0; + move16(); + st->ini_frame = 0; + move16(); + st->inactive_coder_type_flag = 0; + move16(); + st->sba_br_sw_while_no_data = 0; move16(); + st->coder_type_raw = VOICED; + move16(); + st->last_coder_type_raw = st->coder_type_raw; + move16(); + + st->flag_ACELP16k = set_ACELP_flag_IVAS( st->element_mode, st->total_brate, st->total_brate, idchan, 0, -1, -1 ); + move16(); + + st->is_ism_format = 0; + move16(); + if ( NE_16( ism_mode, ISM_MODE_NONE ) ) + { + st->is_ism_format = 1; + move16(); + } /*-----------------------------------------------------------------* * Bitstream *-----------------------------------------------------------------*/ IF( !vad_only_flag ) { - IF( ( st_fx->hBstr = (BSTR_ENC_HANDLE) malloc( sizeof( BSTR_ENC_DATA ) ) ) == NULL ) + IF( ( st->hBstr = (BSTR_ENC_HANDLE) malloc( sizeof( BSTR_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Bitstream structure\n" ) ); } } ELSE { - st_fx->hBstr = NULL; + st->hBstr = NULL; } @@ -162,135 +229,231 @@ ivas_error init_encoder_fx( init_gp_clip_fx( st_fx->clip_var_fx ); pitch_ol_init_fx( &st_fx->old_thres_fx, &st_fx->old_pitch, &st_fx->delta_pit, &st_fx->old_corr_fx ); - /*-----------------------------------------------------------------* - * AMR-WB IO initialization - *-----------------------------------------------------------------*/ - test(); - IF( st_fx->Opt_AMR_WB || EQ_16( st_fx->element_mode, EVS_MONO ) ) - { - IF( ( st_fx->hAmrwb_IO = (AMRWB_IO_ENC_HANDLE) malloc( sizeof( AMRWB_IO_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AMR-WB IO\n" ) ); - } + Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); + Copy( GEWB_Ave_fx, st->lsfoldbfi0_fx, M ); + Copy( GEWB_Ave_fx, st->lsfoldbfi1_fx, M ); + Copy( GEWB_Ave_fx, st->lsf_adaptive_mean_fx, M ); - amr_wb_enc_init_fx( st_fx->hAmrwb_IO ); - } - ELSE - { - st_fx->hAmrwb_IO = NULL; - } - st_fx->clas = UNVOICED_CLAS; + st->next_force_safety_net = 0; move16(); - set16_fx( st_fx->old_wsp2_fx, 0, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); - set16_fx( st_fx->old_wsp_fx, 0, L_WSP_MEM ); - st_fx->mem_deemph_fx = 0; + + st->pstreaklen = 0; move16(); - st_fx->mem_preemph_fx = 0; + st->streaklimit_fx = MAX_WORD16; move16(); - st_fx->mem_preemph16k_fx = 0; + set16_fx( st->mem_MA_fx, 0, M ); + + init_gp_clip_fx( st->clip_var_fx ); + pitch_ol_init_fx( &st->old_thres_fx, &st->old_pitch, &st->delta_pit, &st->old_corr_fx ); + set16_fx( st->old_wsp_fx, 0, L_WSP_MEM ); + st->exp_old_wsp = 0; move16(); - st_fx->mem_preemph_enc = 0; + set16_fx( st->old_wsp2_fx, 0, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); + st->Q_old_wsp2 = 0; move16(); - /* AVQ pre-quantizer memory */ - st_fx->mem_preemp_preQ_fx = 0; + st->mem_preemph_fx = 0; move16(); - st_fx->mem_deemp_preQ_fx = 0; + st->mem_preemph_fx_q_inp = 0; + move16(); + st->mem_preemph16k_fx = 0; move16(); - st_fx->last_nq_preQ = 0; + st->mem_preemph_enc = 0; move16(); - st_fx->use_acelp_preq = 0; + st->exp_mem_preemph_enc = 0; move16(); - /* (Decimated) Weighted Speech Memory */ - st_fx->mem_wsp_enc = 0; + /* AVQ pre-quantizer memory */ + st->mem_preemp_preQ_fx = 0; move16(); - - st_fx->mem_wsp_fx = 0; + st->mem_deemp_preQ_fx = 0; move16(); - st_fx->mem_wsp_q = 0; + st->last_nq_preQ = 0; move16(); - set32_fx( st_fx->Bin_E_fx, 0, L_FFT ); - st_fx->q_Bin_E = Q31; + st->last_code_preq = 0; move16(); - set16_fx( st_fx->mem_decim2_fx, 0, 3 ); - set16_fx( st_fx->lgBin_E_fx, 0, L_FFT / 2 ); - - st_fx->ini_frame = 0; + st->use_acelp_preq = 0; move16(); - st_fx->ee_old_fx = 640; - move32(); /*chk //10 in Q6 */ - st_fx->Nb_ACELP_frames = 0; + st->last_harm_flag_acelp = 0; move16(); - st_fx->audio_frame_cnt = AUDIO_COUNTER_INI; - move16(); /* Initializatin of the audio frame counter mildly into the audio mode */ - /* adaptive lag window memory */ - st_fx->old_pitch_la = 0; + /* (Decimated) Weighted Speech Memory */ + st->mem_wsp_enc = 0; move16(); - st_fx->old_voicing_la = 0; + st->mem_wsp_fx = 0; + move16(); + st->mem_wsp_q = 0; move16(); - set32_fx( st_fx->mem_hp20_in_fx, 0, 5 ); - st_fx->old_hpfilt_in_fx = 0; + set16_fx( st->mem_decim2_fx, 0, 3 ); + set32_fx( st->Bin_E_fx, 0, L_FFT ); + st->q_Bin_E = Q31; move16(); - st_fx->old_hpfilt_out_fx = 0; + + st->ee_old_fx = 640; /* 10.0f in Q6 */ move16(); - st_fx->EnergyLT_fx = 0; - move32(); - st_fx->prev_Q_new = 0; + st->Nb_ACELP_frames = 0; + move16(); + st->audio_frame_cnt = AUDIO_COUNTER_INI; /* Initialization of the audio frame counter mildly into the audio mode */ move16(); + /* adaptive lag window memory */ + st->old_pitch_la = 0; + move16(); + + st->prev_Q_new = 0; + move16(); - IF( EQ_32( st_fx->input_Fs, 8000 ) ) + IF( EQ_32( st->input_Fs, 8000 ) ) { - st_fx->min_band = 1; + st->min_band = 1; move16(); - st_fx->max_band = 16; + st->max_band = 16; move16(); } ELSE { - st_fx->min_band = 0; + st->min_band = 0; move16(); - st_fx->max_band = 19; + st->max_band = 19; move16(); } - IF( st_fx->Opt_AMR_WB ) + + IF( st->Opt_AMR_WB ) { - Copy( mean_isf_amr_wb_fx, st_fx->lsf_old_fx, M ); - E_LPC_isf_isp_conversion( st_fx->lsf_old_fx, st_fx->lsp_old1_fx, M ); + Copy( mean_isf_amr_wb_fx, st->lsf_old_fx, M ); + E_LPC_isf_isp_conversion( st->lsf_old_fx, st->lsp_old1_fx, M ); } ELSE { - Copy( GEWB_Ave_fx, st_fx->lsf_old_fx, M ); - lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old1_fx, M, INT_FS_FX ); + Copy( GEWB_Ave_fx, st->lsf_old_fx, M ); + lsf2lsp_fx( st->lsf_old_fx, st->lsp_old1_fx, M, INT_FS_12k8 ); } - Copy( st_fx->lsf_old_fx, st_fx->lsf_old1_fx, M ); - Copy( st_fx->lsp_old1_fx, st_fx->lsp_old_fx, M ); - Copy( st_fx->lsp_old_fx, st_fx->lsp_old16k_fx, M ); - Copy( st_fx->lsp_old_fx, st_fx->lspold_enc_fx, M ); + Copy( st->lsf_old_fx, st->lsf_old1_fx, M ); + Copy( st->lsp_old1_fx, st->lsp_old_fx, M ); + Copy( st->lsp_old_fx, st->lsp_old16k_fx, M ); + Copy( st->lsp_old_fx, st->lspold_enc_fx, M ); - st_fx->stab_fac_fx = 0; + st->stab_fac_fx = 0; move16(); + /* Bass post-filter memories - encoder side of MODE2 */ - st_fx->bpf_off = 0; + st->bpf_off = 0; + move16(); + st->pst_mem_deemp_err_fx = 0; + move16(); + st->pst_lp_ener_fx = 0; + move16(); + + /* TC coder type */ + st->tc_cnt = 0; + move16(); + + /* find_uv() parameters */ + st->old_dE1_fx = 0; + move16(); + st->old_ind_deltaMax = 0; + move16(); + set32_fx( st->old_enr_ssf_fx, 0, shl( NB_SSF, 1 ) ); + st->spike_hyst = -1; + move16(); + + /* stereo switching memories */ + st->mem_preemph_DFT_fx = 0; + move16(); + st->mem_preemph_DFT_fx_q_inp = 0; + move16(); + set16_fx( st->inp_12k8_mem_stereo_sw_fx, 0, sub( sub( STEREO_DFT_OVL_12k8, L_MEM_RECALC_12K8 ), L_FILT ) ); + st->mem_preemph16k_DFT_fx = 0; + move16(); + set16_fx( st->inp_16k_mem_stereo_sw_fx, 0, sub( sub( STEREO_DFT_OVL_16k, L_MEM_RECALC_16K ), L_FILT16k ) ); + + st->sharpFlag = 0; + move16(); + + /* Stationary noise UV modification */ + st->ge_sm_fx = L_deposit_l( 640 ); /*Q(GE_SHIFT)*/ + move16(); + st->uv_count = 0; + move16(); + st->act_count = 3; + move16(); + Copy( st->lsp_old_fx, st->lspold_s_fx, M ); + st->noimix_seed = RANDOM_INITSEED; + move16(); + st->min_alpha_fx = 32767; + move16(); + st->exc_pe_fx = 0; + move16(); + st->Q_stat_noise = 15; + move16(); + + /* FEC */ + st->last_clas = UNVOICED_CLAS; + move16(); + st->prev_fmerit = 0; + move16(); + st->fmerit_dt = 0; + move16(); + st->Last_pulse_pos = 0; + move16(); + + FOR( i = 0; i < shl( NB_SUBFR16k, 1 ); i++ ) + { + st->old_pitch_buf_fx[i] = L_SUBFR_Q6; + move16(); + } + + /* mode1 core switching */ + st->old_Es_pred_fx = 0; + move16(); + set16_fx( st->old_Aq_12_8_fx + 1, 0, M ); + st->old_Aq_12_8_fx[0] = ONE_IN_Q12; move16(); - /* TC mode */ - st_fx->tc_cnt = 0; + /* stable short pitch detection */ + st->voicing0_sm_fx = 0; + move16(); + st->voicing_sm_fx = 0; move16(); - st_fx->mCb1_fx = 0; + st->LF_EnergyRatio_sm_fx = 1; + move16(); + st->predecision_flag = 0; move16(); + st->diff_sm_fx = 0; + move32(); + st->energy_sm_fx = 0; + move32(); + + set16_fx( st->pitch, L_SUBFR, 3 ); + set16_fx( st->voicing_fx, 0, 3 ); + + + /*-----------------------------------------------------------------* + * AMR-WB IO initialization + *-----------------------------------------------------------------*/ + test(); + IF( st_fx->Opt_AMR_WB || EQ_16( st_fx->element_mode, EVS_MONO ) ) + { + IF( ( st_fx->hAmrwb_IO = (AMRWB_IO_ENC_HANDLE) malloc( sizeof( AMRWB_IO_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AMR-WB IO\n" ) ); + } + + amr_wb_enc_init_fx( st_fx->hAmrwb_IO ); + } + ELSE + { + st_fx->hAmrwb_IO = NULL; + } - /* AC mode */ /*-----------------------------------------------------------------* * parameters for AC coder type (GSC) *-----------------------------------------------------------------*/ - // st_fx->GSC_noisy_speech = 0; + st_fx->GSC_noisy_speech = 0; st_fx->GSC_IVAS_mode = 0; move16(); test(); @@ -309,9 +472,6 @@ ivas_error init_encoder_fx( st_fx->hGSCEnc = NULL; } - st_fx->last_ener_fx = 0; - move16(); - st_fx->old_dE1_fx = 0; move16(); st_fx->old_ind_deltaMax = 0; @@ -326,13 +486,6 @@ ivas_error init_encoder_fx( st_fx->GSC_noisy_speech = 0; move16(); - /* speech/music classifier */ - st_fx->Last_pulse_pos = 0; - move16(); - - st_fx->last_vad_spa_fx = 0; - move16(); - /*-----------------------------------------------------------------* * VAD *-----------------------------------------------------------------*/ @@ -450,32 +603,6 @@ ivas_error init_encoder_fx( move16(); - move16(); - st_fx->coder_type_raw = VOICED; - st_fx->last_coder_type_raw = st_fx->coder_type_raw; - move16(); - st_fx->is_ism_format = 0; - move16(); - if ( NE_16( ism_mode, ISM_MODE_NONE ) ) - { - st_fx->is_ism_format = 1; - move16(); - } - /* Stationary noise UV modification */ - st_fx->ge_sm_fx = 640; - move32(); /*Q(GE_SHIFT) */ - st_fx->uv_count = 0; - move16(); - st_fx->act_count = 3; - move16(); - Copy( st_fx->lsp_old_fx, st_fx->lspold_s_fx, M ); - st_fx->noimix_seed = RANDOM_INITSEED; - move16(); - st_fx->min_alpha_fx = 1; - move16(); - st_fx->exc_pe_fx = 0; - move16(); - /*-----------------------------------------------------------------* * DTX *-----------------------------------------------------------------*/ @@ -718,11 +845,6 @@ ivas_error init_encoder_fx( * HQ core parameters *-----------------------------------------------------------------*/ - st_fx->input_fx = st_fx->input_buff_fx + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ); - set16_fx( st_fx->input_buff_fx + L_FRAME48k, 0, L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); - st_fx->old_input_signal_fx = st_fx->input_fx - add( NS2SA_FX2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ), extract_l( Mult_32_16( st_fx->input_Fs, 0x0290 ) ) ); - - st_fx->Energy_Old_fx = 0; move16(); st_fx->Q_old_wtda = 15; @@ -881,6 +1003,7 @@ ivas_error init_encoder_fx( set16_fx( st_fx->totalNoise_increase_hist_fx, 0, TOTALNOISE_HIST_SIZE ); st_fx->totalNoise_increase_len = 0; move16(); + init_coder_ace_plus_fx( st_fx, st_fx->last_total_brate, 0, -10 /*hack*/ ); IF( ( st_fx->hTranDet = (TRAN_DET_HANDLE) malloc( sizeof( TRAN_DET_DATA ) ) ) == NULL ) @@ -888,9 +1011,7 @@ ivas_error init_encoder_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Transient Detection\n" ) ); } - InitTransientDetection_fx( extract_l( Mult_32_16( st_fx->input_Fs, 0x0290 ) ), - NS2SA_FX2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ), - st_fx->hTranDet, 0 ); + InitTransientDetection_fx( extract_l( Mult_32_16( st_fx->input_Fs, 0x0290 ) ), NS2SA_FX2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ), st_fx->hTranDet ); st_fx->Q_syn2 = 0; move16(); @@ -1021,23 +1142,24 @@ void LPDmem_enc_init_ivas_fx( ivas_error init_encoder_ivas_fx( - Encoder_State *st, /* i/o: state structure */ - Encoder_Struct *st_ivas, /* i/o: encoder state structure */ - const Word16 idchan, /* i : channel ID */ - const Word16 var_SID_rate_flag, /* i : flag for variable SID update rate */ - const Word16 interval_SID, /* i : interval for SID update */ - const Word16 vad_only_flag, /* i : flag to indicate front-VAD structure */ - const ISM_MODE ism_mode, /* i : ISM mode */ - const Word32 element_brate /* i : element bitrate */ + Encoder_State *st, /* i/o: state structure */ + Encoder_Struct *st_ivas, /* i/o: encoder state structure */ + const Word16 idchan, /* i : channel ID */ + const Word16 vad_only_flag, /* i : flag to indicate front-VAD structure */ + const ISM_MODE ism_mode, /* i : ISM mode */ + const Word32 element_brate /* i : element bitrate */ ) { - Word16 i; + Word16 i, frame_length; ivas_error error; Word32 igf_brate; error = IVAS_ERR_OK; move32(); + /* frame_length = st->input_Fs / FRAMES_PER_SEC */ + frame_length = extract_l( Mpy_32_32( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + /*-----------------------------------------------------------------* * General parameters *-----------------------------------------------------------------*/ @@ -1099,8 +1221,7 @@ ivas_error init_encoder_ivas_fx( st->is_ism_format = 0; move16(); - - IF( NE_16( ism_mode, ISM_MODE_NONE ) ) + if ( NE_16( ism_mode, ISM_MODE_NONE ) ) { st->is_ism_format = 1; move16(); @@ -1155,7 +1276,7 @@ ivas_error init_encoder_ivas_fx( set16_fx( st->old_wsp_fx, 0, L_WSP_MEM ); st->exp_old_wsp = 0; move16(); - set16_fx( st->old_wsp2_fx, 0, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); // Needs to change depending on usage. + set16_fx( st->old_wsp2_fx, 0, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); st->Q_old_wsp2 = 0; move16(); @@ -1170,14 +1291,6 @@ ivas_error init_encoder_ivas_fx( st->exp_mem_preemph_enc = 0; move16(); - st->active_cnt = 0; - move16(); - - st->pst_mem_deemp_err_fx = 0; - move16(); - st->pst_lp_ener_fx = 0; - move16(); - /* AVQ pre-quantizer memory */ st->mem_preemp_preQ_fx = 0; move16(); @@ -1199,10 +1312,12 @@ ivas_error init_encoder_ivas_fx( move16(); st->mem_wsp_q = 0; move16(); + set16_fx( st->mem_decim2_fx, 0, 3 ); set32_fx( st->Bin_E_fx, 0, L_FFT ); st->q_Bin_E = Q31; move16(); + st->ee_old_fx = 640; /* 10.0f in Q6 */ move16(); st->Nb_ACELP_frames = 0; @@ -1301,6 +1416,7 @@ ivas_error init_encoder_ivas_fx( move16(); st->Q_stat_noise = 15; move16(); + /* FEC */ st->last_clas = UNVOICED_CLAS; move16(); @@ -1403,17 +1519,14 @@ ivas_error init_encoder_ivas_fx( move16(); st->old_input_signal_fx = st->input_buff_fx; st->old_input_signal32_fx = st->input_buff32_fx; - /* st->input_Fs / FRAMES_PER_SEC */ - Word16 frame_length = extract_l( Mpy_32_32( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); IF( st->element_mode == EVS_MONO ) { - st->input32_fx = st->input_buff32_fx + st->input_Fs / FRAMES_PER_SEC + NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ); - st->input_fx = st->input_buff_fx + add( frame_length, (Word16) NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ) ); + st->input32_fx = st->input_buff32_fx + add( frame_length, NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ) ); + st->input_fx = st->input_buff_fx + add( frame_length, NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ) ); } ELSE { - // st->input32_fx = st->input_buff32_fx + Mpy_32_32( st->input_Fs, 42949673 ) /* 1/50 in Q31*/; // st->input_Fs / FRAMES_PER_SEC st->input32_fx = st->input_buff32_fx + frame_length; st->input_fx = st->input_buff_fx + frame_length; } @@ -1447,7 +1560,14 @@ ivas_error init_encoder_ivas_fx( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Noise estimation\n" ); } - noise_est_init_ivas_fx( st->hNoiseEst ); + IF( st->element_mode == EVS_MONO ) + { + noise_est_init_fx( st->hNoiseEst ); + } + ELSE + { + noise_est_init_ivas_fx( st->hNoiseEst ); + } } ELSE { @@ -1505,7 +1625,14 @@ ivas_error init_encoder_ivas_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Speech/music classifier\n" ) ); } - speech_music_clas_init_ivas_fx( st->hSpMusClas ); + IF( st->element_mode == EVS_MONO ) + { + speech_music_clas_init_fx( st->hSpMusClas ); + } + ELSE + { + speech_music_clas_init_ivas_fx( st->hSpMusClas ); + } st->sp_aud_decision0 = 0; move16(); st->sp_aud_decision1 = 0; @@ -1518,7 +1645,6 @@ ivas_error init_encoder_ivas_fx( st->hSpMusClas = NULL; } - /*-----------------------------------------------------------------* * WB, SWB and FB bandwidth detector *-----------------------------------------------------------------*/ @@ -1546,13 +1672,16 @@ ivas_error init_encoder_ivas_fx( st->bwidth_sw_cnt = 0; move16(); - /*-----------------------------------------------------------------* * DTX *-----------------------------------------------------------------*/ + st->lp_speech_fx = 11520; /*Q8 (45.0) */ /* Initialize the long-term active speech level in dB */ + move16(); st->lp_speech_32fx = 754974720; /*Q24 (45.0) */ /* Initialize the long-term active speech level in dB */ move32(); + st->lp_noise_fx = 0; + move16(); st->lp_noise_32fx = 0; move16(); st->flag_noisy_speech_snr = 0; @@ -1576,7 +1705,7 @@ ivas_error init_encoder_ivas_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX variables\n" ) ); } - dtx_enc_init_fx( st, var_SID_rate_flag, interval_SID ); + dtx_enc_init_fx( st, st_ivas->hEncoderConfig->var_SID_rate_flag, st_ivas->hEncoderConfig->interval_SID ); } ELSE { @@ -1636,7 +1765,14 @@ ivas_error init_encoder_ivas_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); } - td_cng_enc_init_ivas_fx( st->hTdCngEnc, st->Opt_DTX_ON, st->max_bwidth ); + IF( st->element_mode == EVS_MONO ) + { + td_cng_enc_init_fx( st->hTdCngEnc, st->Opt_DTX_ON, st->max_bwidth ); + } + ELSE + { + td_cng_enc_init_ivas_fx( st->hTdCngEnc, st->Opt_DTX_ON, st->max_bwidth ); + } } ELSE { @@ -1651,7 +1787,7 @@ ivas_error init_encoder_ivas_fx( test(); IF( ( NE_16( st->element_mode, IVAS_CPE_MDCT ) && idchan == 0 ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->Opt_DTX_ON ) ) { - IF( EQ_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode == EVS_MONO ) { /* open analysis for input SR */ IF( ( error = openCldfb( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs ) ) != IVAS_ERR_OK ) @@ -1672,10 +1808,20 @@ ivas_error init_encoder_ivas_fx( st->cldfbAnaEnc = NULL; } - st->energyCoreLookahead_Fx = 2; /* 6.1e-5f in Q15 */ - move32(); - st->sf_energyCoreLookahead_Fx = 2; /* 6.1e-5f in Q15 */ - move16(); + IF( st->element_mode == EVS_MONO ) + { + st->energyCoreLookahead_Fx = 0; + move32(); + st->sf_energyCoreLookahead_Fx = 0; + move16(); + } + ELSE + { + st->energyCoreLookahead_Fx = 2; /* 6.1e-5f in Q15 */ + move32(); + st->sf_energyCoreLookahead_Fx = 2; /* 6.1e-5f in Q15 */ + move16(); + } /*-----------------------------------------------------------------* * SC-VBR parameters @@ -1732,7 +1878,14 @@ ivas_error init_encoder_ivas_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LPDmem\n" ) ); } - LPDmem_enc_init_ivas_fx( st->hLPDmem ); + IF( st->element_mode == EVS_MONO ) + { + LPDmem_enc_init_fx( st->hLPDmem ); + } + ELSE + { + LPDmem_enc_init_ivas_fx( st->hLPDmem ); + } } ELSE { @@ -1782,6 +1935,8 @@ ivas_error init_encoder_ivas_fx( { return error; } + + InitSWBencBuffer_fx( st /*st_fx->hBWE_TD*/ ); } ELSE { @@ -1789,8 +1944,10 @@ ivas_error init_encoder_ivas_fx( { return error; } + + InitSWBencBuffer_ivas_fx( st ); } - InitSWBencBuffer_ivas_fx( st ); + ResetSHBbuffer_Enc_fx( st ); } ELSE @@ -1923,6 +2080,7 @@ ivas_error init_encoder_ivas_fx( set32_fx( st->hTcxEnc->spectrum_long_fx, 0, N_MAX ); st->hTcxEnc->spectrum_long_e = 0; move16(); + /* Share the memories for 2xTCX10/4xTCX5 and for TCX20 */ st->hTcxEnc->spectrum_fx[0] = st->hTcxEnc->spectrum_long_fx; st->hTcxEnc->spectrum_fx[1] = st->hTcxEnc->spectrum_long_fx + N_TCX10_MAX; @@ -2032,7 +2190,6 @@ ivas_error init_encoder_ivas_fx( st->last_sr_core = L_mult0( st->last_L_frame, FRAMES_PER_SEC ); move32(); - /* PLC encoder */ IF( st->element_mode == EVS_MONO ) { @@ -2055,35 +2212,37 @@ ivas_error init_encoder_ivas_fx( TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; IF( hTcxEnc != NULL ) { - hTcxEnc->L_frameTCX = extract_l( Mult_32_16( st->input_Fs, 0x0290 ) ); /* 0x0290 is 1/FRAMES_PER_SEC in Q15*/ + hTcxEnc->L_frameTCX = frame_length; move16(); } - st->currEnergyHF_fx = 0; - move32(); - st->currEnergyHF_e_fx = 0; - move16(); st->prevEnergyHF_fx = 0; move32(); - /* Initialize TCX */ + IF( st->element_mode == EVS_MONO ) + { + init_coder_ace_plus_fx( st, st->last_total_brate, 0, -10 /*hack*/ ); + } + ELSE + { + /* Initialize Signal Buffers */ + Word16 shift = getScaleFactor16( st->old_inp_16k_fx, L_INP_MEM ); + Scale_sig( st->old_inp_16k_fx, L_INP_MEM, shift ); + st->exp_old_inp_16k = sub( st->exp_old_inp_16k, shift ); + move16(); + shift = getScaleFactor16( st->old_inp_12k8_fx, L_INP_MEM ); + Scale_sig( st->old_inp_12k8_fx, L_INP_MEM, shift ); + st->exp_old_inp_12k8 = sub( st->exp_old_inp_12k8, shift ); + move16(); - /* Initialize Signal Buffers */ - Word16 shift = getScaleFactor16( st->old_inp_16k_fx, L_INP_MEM ); - Scale_sig( st->old_inp_16k_fx, L_INP_MEM, shift ); - st->exp_old_inp_16k = sub( st->exp_old_inp_16k, shift ); - move16(); - shift = getScaleFactor16( st->old_inp_12k8_fx, L_INP_MEM ); - Scale_sig( st->old_inp_12k8_fx, L_INP_MEM, shift ); - st->exp_old_inp_12k8 = sub( st->exp_old_inp_12k8, shift ); - move16(); - /* Initialize ACELP */ - init_coder_ace_plus_ivas_fx( st, st->last_total_brate, igf_brate, 0 ); + init_coder_ace_plus_ivas_fx( st, st->last_total_brate, igf_brate, 0 ); + } IF( st->hLPDmem != NULL ) { st->hLPDmem->q_lpd_old_exc = st->prev_Q_new; move16(); } + /*-----------------------------------------------------------------* * FD-CNG encoder *-----------------------------------------------------------------*/ @@ -2095,7 +2254,9 @@ ivas_error init_encoder_ivas_fx( IF( ( idchan == 0 && st->Opt_DTX_ON ) || st->element_mode == EVS_MONO || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->Opt_DTX_ON ) ) { createFdCngEnc_fx( &st->hFdCngEnc ); + initFdCngEnc_fx( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale ); + /* initialization for IVAS modes happens in first frame pre-processing */ IF( st->element_mode == EVS_MONO ) { @@ -2113,7 +2274,7 @@ ivas_error init_encoder_ivas_fx( move32(); } - configureFdCngEnc_ivas_fx( st->hFdCngEnc, st->bwidth, total_brate ); + configureFdCngEnc_fx( st->hFdCngEnc, st->bwidth, total_brate ); } } ELSE @@ -2130,17 +2291,13 @@ ivas_error init_encoder_ivas_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Transient Detection\n" ) ); } - Word16 frame_length = extract_l( Mult_32_16( st->input_Fs, 0x0290 ) ); - IF( GT_16( st->element_mode, EVS_MONO ) ) { InitTransientDetection_ivas_fx( frame_length, 0, st->hTranDet, 1 ); } ELSE { - InitTransientDetection_fx( frame_length, - NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), - st->hTranDet, 0 ); + InitTransientDetection_fx( frame_length, NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet ); } /*-----------------------------------------------------------------* diff --git a/lib_enc/ivas_cpe_enc_fx.c b/lib_enc/ivas_cpe_enc_fx.c index b73702d21..0d063f5af 100644 --- a/lib_enc/ivas_cpe_enc_fx.c +++ b/lib_enc/ivas_cpe_enc_fx.c @@ -1447,7 +1447,7 @@ ivas_error create_cpe_enc_fx( } st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; move16(); - IF( NE_32( ( error = init_encoder_ivas_fx( st, st_ivas, n, hEncoderConfig->var_SID_rate_flag, hEncoderConfig->interval_SID, 0, ISM_MODE_NONE, hCPE->element_brate ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = init_encoder_ivas_fx( st, st_ivas, n, 0, ISM_MODE_NONE, hCPE->element_brate ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_enc/ivas_sce_enc_fx.c b/lib_enc/ivas_sce_enc_fx.c index a48e4807b..170406b20 100644 --- a/lib_enc/ivas_sce_enc_fx.c +++ b/lib_enc/ivas_sce_enc_fx.c @@ -493,7 +493,7 @@ ivas_error create_sce_enc_fx( } ELSE { - 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 ) ) + IF( NE_32( ( error = init_encoder_ivas_fx( st, st_ivas, 0, 0, st_ivas->ism_mode, hSCE->element_brate ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_enc/ivas_spar_encoder_fx.c b/lib_enc/ivas_spar_encoder_fx.c index 04b4049a7..15643b702 100644 --- a/lib_enc/ivas_spar_encoder_fx.c +++ b/lib_enc/ivas_spar_encoder_fx.c @@ -228,7 +228,7 @@ ivas_error ivas_spar_enc_open_fx( hSpar->hCoreCoderVAD->mct_chan_mode = MCT_CHAN_MODE_IGNORE; move32(); move32(); - IF( NE_32( ( error = init_encoder_ivas_fx( hSpar->hCoreCoderVAD, st_ivas, 0, hEncoderConfig->var_SID_rate_flag, hEncoderConfig->interval_SID, 1, st_ivas->ism_mode, hSpar->hCoreCoderVAD->total_brate ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = init_encoder_ivas_fx( hSpar->hCoreCoderVAD, st_ivas, 0, 1, st_ivas->ism_mode, hSpar->hCoreCoderVAD->total_brate ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 0fca6ab8c..1842c3252 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -1047,8 +1047,7 @@ void calculate_hangover_attenuation_gain_fx( void InitTransientDetection_fx( const Word16 nFrameLength, const Word16 nTCXDelay, - TRAN_DET_HANDLE hTranDet, - const Word16 ext_mem_flag ); + TRAN_DET_HANDLE hTranDet ); void InitTransientDetection_ivas_fx( const Word16 nFrameLength, @@ -1898,9 +1897,6 @@ Word16 encod_tran_ivas_fx( const Word16 Q_new /* i : Input scaling */ ); -/* Delete the instance of type FD_CNG */ -void deleteFdCngEnc_fx( HANDLE_FD_CNG_ENC *hFdCngEnc ); - void coder_acelp_rf_fx( ACELP_config *acelp_cfg_rf, /*i /o : configuration of the ACELP coding*/ const Word16 coder_type, /* input: coding type Q0*/ @@ -1917,18 +1913,22 @@ void coder_acelp_rf_fx( Word16 *syn_rf, /* i/o: pointer to RF synthesis Q_new-1*/ Word16 Q_new, Word16 shift ); -/* Create an instance of type FD_CNG */ -void createFdCngEnc_fx( HANDLE_FD_CNG_ENC *hFdCngEnc ); + +ivas_error createFdCngEnc_fx( + HANDLE_FD_CNG_ENC *hFdCngEnc ); + +void deleteFdCngEnc_fx( + HANDLE_FD_CNG_ENC *hFdCngEnc ); void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, - Word32 input_Fs, /* Q0 */ - Word16 scale ); + const Word32 input_Fs, /* Q0 */ + const Word16 scale ); -/* Configure CLDFB-CNG */ -void configureFdCngEnc_fx( HANDLE_FD_CNG_ENC hs, /* i/o: Contains the variables related to the CLDFB-based CNG process */ - Word16 bandwidth, /* i: bandwidth Q0*/ - Word32 bitrate /* Q0 */ +void configureFdCngEnc_fx( + HANDLE_FD_CNG_ENC hs, /* i/o: Contains the variables related to the CLDFB-based CNG process */ + const Word16 bandwidth, /* i: bandwidth Q0*/ + const Word32 bitrate /* Q0 */ ); /* Perform noise estimation */ diff --git a/lib_enc/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index e2c8f59ff..846b794fe 100644 --- a/lib_enc/speech_music_classif_fx.c +++ b/lib_enc/speech_music_classif_fx.c @@ -4616,7 +4616,7 @@ static void detect_sparseness_fx( Msp = shl( Msp, 5 ); /* Q8 */ /* find long-term smoothed sparseness */ - IF( st_fx->last_vad_spa_fx == 0 ) + IF( hSpMusClas->last_vad_spa == 0 ) { set16_fx( &hSpMusClas->sparse_buf_fx[0], sparse, HANG_LEN_INIT - 1 ); hSpMusClas->LT_sparse_fx = sparse; @@ -4871,7 +4871,7 @@ static void detect_sparseness_fx( move16(); } - st_fx->last_vad_spa_fx = localVAD_HE_SAD; + hSpMusClas->last_vad_spa = localVAD_HE_SAD; move16(); return; diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 33a139403..899f12a15 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -1410,7 +1410,6 @@ typedef struct enc_core_structure Word16 old_Aq_12_8_fx[M + 1]; /* Q12 old Aq[] for core switching */ Word16 old_Es_pred_fx; /* old Es_pred for core switching Q8 */ Word16 music_hysteresis_fx; /* Counter of frames after AUDIO coding mode to prevent UC */ - Word16 last_vad_spa_fx; Word16 last_L_frame; /* ACELP@16kHz - last L_frame value */ Word16 mem_preemph16k_fx; /* ACELP@16kHz - preemphasis filter memory @16kHz Q-1 */ @@ -1782,8 +1781,6 @@ typedef struct enc_core_structure * Fixed point only variables *----------------------------------------------------------------------------------*/ - Word16 last_ener_fx; /* AC mode (GSC) - previous energy */ - Word16 Q_exc; Word16 prev_Q_bwe_exc; diff --git a/lib_enc/transient_detection_fx.c b/lib_enc/transient_detection_fx.c index 89b5464dd..bb8239f90 100644 --- a/lib_enc/transient_detection_fx.c +++ b/lib_enc/transient_detection_fx.c @@ -364,8 +364,7 @@ static void InitTCXTransientDetector( void InitTransientDetection_fx( const Word16 nFrameLength, const Word16 nTCXDelay, - TRAN_DET_HANDLE hTranDet, - const Word16 ext_mem_flag ) + TRAN_DET_HANDLE hTranDet ) { /* Init the delay buffer. */ InitDelayBuffer( nFrameLength, nTCXDelay, &hTranDet->delayBuffer ); @@ -377,18 +376,9 @@ void InitTransientDetection_fx( InitTCXTransientDetector( nTCXDelay, &hTranDet->subblockEnergies, &hTranDet->transientDetector ); /* We need two past subblocks for the TCX TD and NSUBBLOCKS+1 for the temporal flatness measure FOR the TCX LTP. */ - IF( ext_mem_flag ) - { - hTranDet->transientDetector.pSubblockEnergies->nDelay = - add( hTranDet->transientDetector.pSubblockEnergies->nDelay, add( ( NSUBBLOCKS + 1 ), ( NSUBBLOCKS_SHIFT + 1 ) ) ); - move16(); - } - ELSE - { - hTranDet->transientDetector.pSubblockEnergies->nDelay = - add( hTranDet->transientDetector.pSubblockEnergies->nDelay, NSUBBLOCKS + 1 ); - move16(); - } + hTranDet->transientDetector.pSubblockEnergies->nDelay = + add( hTranDet->transientDetector.pSubblockEnergies->nDelay, NSUBBLOCKS + 1 ); + move16(); return; } -- GitLab From 4d511c5a079a61f4eb594dab8312036fb02cec42 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 9 Sep 2025 14:16:11 +0200 Subject: [PATCH 05/15] - remove obsolete encoder parameters st->last_element_mode, st->extl_orig, and st->extl_brate_orig --- lib_enc/init_enc_fx.c | 345 ++++++++++++++++++++++++++---------------- lib_enc/stat_enc.h | 9 +- 2 files changed, 217 insertions(+), 137 deletions(-) diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index 793c5f9b8..a53b1f9b7 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -27,8 +27,6 @@ ivas_error init_encoder_fx( ) { Word16 i; - Word32 L_tmp; - Word16 idchan = 0; /* i : channel ID */ Word16 vad_only_flag = 0; /* i : channel ID */ @@ -607,20 +605,24 @@ ivas_error init_encoder_fx( * DTX *-----------------------------------------------------------------*/ - st_fx->lp_speech_fx = 11520; - move16(); /*Q8 (45.0) */ /* Initialize the long-term active speech level in dB */ - st_fx->lp_noise_fx = 0; + st->lp_speech_fx = 11520; /*Q8 (45.0) */ /* Initialize the long-term active speech level in dB */ + move16(); + st->lp_speech_32fx = 754974720; /*Q24 (45.0) */ /* Initialize the long-term active speech level in dB */ + move32(); + st->lp_noise_fx = 0; + move16(); + st->lp_noise_32fx = 0; move16(); test(); test(); - IF( ( ( idchan == 0 && st_fx->Opt_DTX_ON ) || EQ_16( st_fx->element_mode, EVS_MONO ) ) || ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && st_fx->Opt_DTX_ON ) ) + IF( ( ( idchan == 0 && st->Opt_DTX_ON ) || st->element_mode == EVS_MONO ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->Opt_DTX_ON ) ) { - if ( ( st_fx->hDtxEnc = (DTX_ENC_HANDLE) malloc( sizeof( DTX_ENC_DATA ) ) ) == NULL ) + IF( ( st->hDtxEnc = (DTX_ENC_HANDLE) malloc( sizeof( DTX_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX variables\n" ) ); } - dtx_enc_init_fx( st_fx, var_SID_rate_flag, interval_SID ); + dtx_enc_init_fx( st, var_SID_rate_flag, interval_SID ); } ELSE { @@ -643,23 +645,25 @@ ivas_error init_encoder_fx( * LP-CNG *-----------------------------------------------------------------*/ - test(); - test(); - test(); - test(); - test(); - IF( ( ( idchan == 0 && st_fx->Opt_DTX_ON && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, EVS_MONO ) ) && !( EQ_16( ism_mode, ISM_MODE_PARAM ) || EQ_16( ism_mode, ISM_MODE_DISC ) ) ) + IF( ( ( idchan == 0 && st->Opt_DTX_ON && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) || st->element_mode == EVS_MONO ) && !( EQ_16( ism_mode, ISM_MODE_PARAM ) || EQ_16( ism_mode, ISM_MODE_DISC ) ) ) { - IF( ( st_fx->hTdCngEnc = (TD_CNG_ENC_HANDLE) malloc( sizeof( TD_CNG_ENC_DATA ) ) ) == NULL ) + IF( ( st->hTdCngEnc = (TD_CNG_ENC_HANDLE) malloc( sizeof( TD_CNG_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); } - td_cng_enc_init_fx( st_fx->hTdCngEnc, st_fx->Opt_DTX_ON, st_fx->max_bwidth ); + IF( st->element_mode == EVS_MONO ) + { + td_cng_enc_init_fx( st->hTdCngEnc, st->Opt_DTX_ON, st->max_bwidth ); + } + ELSE + { + td_cng_enc_init_ivas_fx( st->hTdCngEnc, st->Opt_DTX_ON, st->max_bwidth ); + } } ELSE { - st_fx->hTdCngEnc = NULL; + st->hTdCngEnc = NULL; } @@ -669,68 +673,73 @@ ivas_error init_encoder_fx( test(); test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + IF( ( idchan == 0 && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) { - IF( ( st_fx->hLPDmem = (LPD_state_HANDLE) malloc( sizeof( LPD_state ) ) ) == NULL ) + IF( ( st->hLPDmem = (LPD_state_HANDLE) malloc( sizeof( LPD_state ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LPDmem\n" ) ); } - LPDmem_enc_init_fx( st_fx->hLPDmem ); + IF( st->element_mode == EVS_MONO ) + { + LPDmem_enc_init_fx( st->hLPDmem ); + } + ELSE + { + LPDmem_enc_init_ivas_fx( st->hLPDmem ); + } } ELSE { - st_fx->hLPDmem = NULL; + st->hLPDmem = NULL; } - /* FEC */ - st_fx->last_clas = UNVOICED_CLAS; - move16(); - - FOR( i = 0; i < 2 * NB_SUBFR16k; i++ ) - { - st_fx->old_pitch_buf_fx[i] = L_SUBFR_Q6; - move16(); - } - st_fx->old_Es_pred_fx = 0; - move16(); - set16_fx( st_fx->old_Aq_12_8_fx + 1, 0, M ); - st_fx->old_Aq_12_8_fx[0] = 4096; - move16(); /*-----------------------------------------------------------------* * CLDFB Analysis *-----------------------------------------------------------------*/ - /* open analysis for input SR */ - if ( ( error = openCldfb( &st_fx->cldfbAnaEnc, CLDFB_ANALYSIS, st_fx->input_Fs ) ) != IVAS_ERR_OK ) + test(); + test(); + test(); + IF( ( NE_16( st->element_mode, IVAS_CPE_MDCT ) && idchan == 0 ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->Opt_DTX_ON ) ) { - return error; + IF( st->element_mode == EVS_MONO ) + { + /* open analysis for input SR */ + IF( ( error = openCldfb( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + } + ELSE + { + IF( ( error = openCldfb_ivas_fx( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS, ENC ) ) != IVAS_ERR_OK ) + { + return error; + } + } } - - if ( ( error = openCldfb( &st_fx->cldfbSynTd, CLDFB_SYNTHESIS, 16000 ) ) != IVAS_ERR_OK ) + ELSE { - return error; + st->cldfbAnaEnc = NULL; } - st_fx->energyCoreLookahead_Fx = 0; - move32(); - st_fx->sf_energyCoreLookahead_Fx = 0; - move16(); + IF( st->element_mode == EVS_MONO ) + { + st->energyCoreLookahead_Fx = 0; + move32(); + st->sf_energyCoreLookahead_Fx = 0; + move16(); + } + ELSE + { + st->energyCoreLookahead_Fx = 2; /* 6.1e-5f in Q15 */ + move32(); + st->sf_energyCoreLookahead_Fx = 2; /* 6.1e-5f in Q15 */ + move16(); + } - /* stable short pitch detection */ - st_fx->voicing0_sm_fx = 0; - move16(); - st_fx->voicing_sm_fx = 0; - move16(); - st_fx->LF_EnergyRatio_sm_fx = 128; - move16(); - st_fx->predecision_flag = 0; - move16(); - st_fx->diff_sm_fx = 0; - move32(); - st_fx->energy_sm_fx = 0; - move32(); /*-----------------------------------------------------------------* * SC-VBR parameters @@ -780,18 +789,21 @@ ivas_error init_encoder_fx( /*-----------------------------------------------------------------* * SWB BWE parameters *-----------------------------------------------------------------*/ - IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) + test(); + IF( idchan == 0 && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { - IF( ( st_fx->hBWE_FD = (FD_BWE_ENC_HANDLE) malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) + IF( ( st->hBWE_FD = (FD_BWE_ENC_HANDLE) malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n" ) ); } - fd_bwe_enc_init_fx( st_fx->hBWE_FD ); + fd_bwe_enc_init_fx( st->hBWE_FD ); + st->Q_old_wtda = 0; + move16(); } ELSE { - st_fx->hBWE_FD = NULL; + st->hBWE_FD = NULL; } st_fx->prev_Q_shb = 0; @@ -803,27 +815,42 @@ ivas_error init_encoder_fx( * TBE parameters *-----------------------------------------------------------------*/ - IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) + test(); + IF( idchan == 0 && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { - IF( ( st_fx->hBWE_TD = (TD_BWE_ENC_HANDLE) malloc( sizeof( TD_BWE_ENC_DATA ) ) ) == NULL ) + IF( ( st->hBWE_TD = (TD_BWE_ENC_HANDLE) malloc( sizeof( TD_BWE_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); } - // IF ((error = openCldfb(&st_fx->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS)) != IVAS_ERR_OK) - //{ - // return error; - // } + IF( st->element_mode == EVS_MONO ) + { + if ( ( error = openCldfb( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000 ) ) != IVAS_ERR_OK ) + { + return error; + } - InitSWBencBuffer_fx( st_fx /*st_fx->hBWE_TD*/ ); - ResetSHBbuffer_Enc_fx( st_fx /*st_fx->hBWE_TD*/ ); + InitSWBencBuffer_fx( st /*st_fx->hBWE_TD*/ ); + } + ELSE + { + IF( ( error = openCldfb_ivas_fx( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS, ENC ) ) != IVAS_ERR_OK ) + { + return error; + } + + InitSWBencBuffer_ivas_fx( st ); + } + + ResetSHBbuffer_Enc_fx( st ); } ELSE { - st_fx->hBWE_TD = NULL; - // st_fx->cldfbSynTd = NULL; + st->hBWE_TD = NULL; + st->cldfbSynTd = NULL; } + test(); IF( st_fx->Opt_RF_ON || st_fx->element_mode == EVS_MONO ) { @@ -860,41 +887,46 @@ ivas_error init_encoder_fx( * TCX core *-----------------------------------------------------------------*/ + // ToDo: reduction possible for MCT_CHAN_MODE_LFE channel test(); - IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) + IF( idchan == 0 || EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { - IF( ( st_fx->hTcxEnc = (TCX_ENC_HANDLE) malloc( sizeof( TCX_ENC_DATA ) ) ) == NULL ) + IF( ( st->hTcxEnc = (TCX_ENC_HANDLE) malloc( sizeof( TCX_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxEnc\n" ) ); } + set32_fx( st->hTcxEnc->spectrum_long_fx, 0, N_MAX ); + st->hTcxEnc->spectrum_long_e = 0; + move16(); /* Share the memories for 2xTCX10/4xTCX5 and for TCX20 */ - /*st_fx->hTcxEnc->spectrum[0] = st_fx->hTcxEnc->spectrum_long; - st_fx->hTcxEnc->spectrum[1] = st_fx->hTcxEnc->spectrum_long + N_TCX10_MAX;*/ - - st_fx->hTcxEnc->spectrum_fx[0] = st_fx->hTcxEnc->spectrum_long_fx; - st_fx->hTcxEnc->spectrum_fx[1] = st_fx->hTcxEnc->spectrum_long_fx + N_TCX10_MAX; + st->hTcxEnc->spectrum_fx[0] = st->hTcxEnc->spectrum_long_fx; + st->hTcxEnc->spectrum_fx[1] = st->hTcxEnc->spectrum_long_fx + N_TCX10_MAX; + move32(); + move32(); + st->hTcxEnc->spectrum_e[0] = st->hTcxEnc->spectrum_e[1] = 0; + move16(); + move16(); - set16_fx( st_fx->hTcxEnc->old_out_fx, 0, L_FRAME32k ); - st_fx->hTcxEnc->Q_old_out = 0; + set16_fx( st->hTcxEnc->old_out_fx, 0, L_FRAME32k ); + st->hTcxEnc->Q_old_out = 0; move16(); + /* MDCT selector */ - MDCT_selector_reset_fx( st_fx->hTcxEnc ); - st_fx->hTcxEnc->Q_old_out = 0; - move16(); + MDCT_selector_reset_fx( st->hTcxEnc ); /* MDCT classifier */ - MDCT_classifier_reset_fx( st_fx->hTcxEnc ); + MDCT_classifier_reset_fx( st->hTcxEnc ); - IF( ( st_fx->hTcxCfg = (TCX_CONFIG_HANDLE) malloc( sizeof( TCX_config ) ) ) == NULL ) + IF( ( st->hTcxCfg = (TCX_CONFIG_HANDLE) malloc( sizeof( TCX_config ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n" ) ); } } ELSE { - st_fx->hTcxEnc = NULL; - // st_fx->hTcxCfg = NULL; + st->hTcxEnc = NULL; + st->hTcxCfg = NULL; } /*-----------------------------------------------------------------* * HQ core parameters @@ -961,57 +993,104 @@ ivas_error init_encoder_fx( * IGF *-----------------------------------------------------------------*/ + move16(); + + test(); test(); - IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) + test(); + IF( ( idchan == 0 || EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) && ( st->igf || st->element_mode == EVS_MONO ) ) { - IF( ( st_fx->hIGFEnc = (IGF_ENC_INSTANCE_HANDLE) malloc( sizeof( IGF_ENC_INSTANCE ) ) ) == NULL ) + IF( ( st->hIGFEnc = (IGF_ENC_INSTANCE_HANDLE) malloc( sizeof( IGF_ENC_INSTANCE ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hIGFEnc\n" ) ); } } ELSE { - st_fx->hIGFEnc = NULL; - move16(); + st->hIGFEnc = NULL; } - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + + /*-----------------------------------------------------------------* + * FD-CNG encoder + *-----------------------------------------------------------------*/ + + test(); + test(); + test(); + test(); + IF( ( idchan == 0 && st->Opt_DTX_ON ) || st->element_mode == EVS_MONO || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->Opt_DTX_ON ) ) { - st_fx->igf = getIgfPresent_fx( st_fx->element_mode, st_fx->total_brate, st_fx->bwidth, st_fx->rf_mode ); + createFdCngEnc_fx( &st->hFdCngEnc ); + + initFdCngEnc_fx( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale ); + + /* initialization for IVAS modes happens in first frame pre-processing */ + IF( st->element_mode == EVS_MONO ) + { + Word32 total_brate; + + test(); + IF( st->rf_mode && EQ_32( st->total_brate, ACELP_13k20 ) ) + { + total_brate = ACELP_9k60; + move32(); + } + ELSE + { + total_brate = st->total_brate; + move32(); + } + + configureFdCngEnc_fx( st->hFdCngEnc, st->bwidth, total_brate ); + } } ELSE { - st_fx->igf = 0; - move16(); + st->hFdCngEnc = NULL; } - /* FD-CNG encoder */ - createFdCngEnc_fx( &st_fx->hFdCngEnc ); - initFdCngEnc_fx( st_fx->hFdCngEnc, st_fx->input_Fs, st_fx->cldfbAnaEnc->scale ); - L_tmp = st_fx->total_brate; - move32(); - test(); - if ( st_fx->rf_mode && EQ_32( st_fx->total_brate, ACELP_13k20 ) ) - { - L_tmp = ACELP_9k60; - move32(); - } - configureFdCngEnc_fx( st_fx->hFdCngEnc, st_fx->bwidth, L_tmp ); st_fx->last_totalNoise_fx = 0; move16(); set16_fx( st_fx->totalNoise_increase_hist_fx, 0, TOTALNOISE_HIST_SIZE ); st_fx->totalNoise_increase_len = 0; move16(); + st->prevEnergyHF_fx = 0; + move32(); + + IF( st->element_mode == EVS_MONO ) + { + init_coder_ace_plus_fx( st, st->last_total_brate, 0, -10 /*hack*/ ); + } + ELSE + { + /* Initialize Signal Buffers */ + Word16 shift = getScaleFactor16( st->old_inp_16k_fx, L_INP_MEM ); + Scale_sig( st->old_inp_16k_fx, L_INP_MEM, shift ); + st->exp_old_inp_16k = sub( st->exp_old_inp_16k, shift ); + move16(); + shift = getScaleFactor16( st->old_inp_12k8_fx, L_INP_MEM ); + Scale_sig( st->old_inp_12k8_fx, L_INP_MEM, shift ); + st->exp_old_inp_12k8 = sub( st->exp_old_inp_12k8, shift ); + move16(); + + init_coder_ace_plus_ivas_fx( st, st->last_total_brate, -1, 0 ); + } + + IF( st->hLPDmem != NULL ) + { + st->hLPDmem->q_lpd_old_exc = st->prev_Q_new; + move16(); + } - init_coder_ace_plus_fx( st_fx, st_fx->last_total_brate, 0, -10 /*hack*/ ); IF( ( st_fx->hTranDet = (TRAN_DET_HANDLE) malloc( sizeof( TRAN_DET_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Transient Detection\n" ) ); } - InitTransientDetection_fx( extract_l( Mult_32_16( st_fx->input_Fs, 0x0290 ) ), NS2SA_FX2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ), st_fx->hTranDet ); + InitTransientDetection_fx( frame_length, NS2SA_FX2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ), st_fx->hTranDet ); st_fx->Q_syn2 = 0; move16(); @@ -1034,31 +1113,30 @@ ivas_error init_encoder_fx( move16(); st_fx->cng_sba_flag = 0; /* CNG in SBA flag */ move16(); - st_fx->GSC_IVAS_mode = 0; /* CNG in SBA flag */ + st->bits_frame_channel = 0; move16(); - st_fx->element_mode = EVS_MONO; /* element mode */ + st->side_bits_frame_channel = 0; move16(); - st_fx->last_element_mode = st_fx->element_mode; /* element mode */ + + st->Q_syn2 = 0; move16(); - st_fx->element_brate = -1; /* element bitrate */ - move32(); - // PMT("element_mode and element_brate should be initialized at a proper place in ivas_dec_init eventually") - st_fx->low_rate_mode = 0; /* low-rate mode flag */ + st->Q_syn = 0; move16(); - // st_fx->coder_type = GENERIC; /* low-rate mode flag */ - - set16_fx( st_fx->pitch, L_SUBFR, 3 ); - set16_fx( st_fx->voicing_fx, 0, 3 ); - + set16_fx( st->Q_max, Q_MAX, L_Q_MEM ); + set16_fx( st->Q_max_16k, Q_MAX, L_Q_MEM ); + st->Q_old = 15; + move16(); + st->old_wsp_max = 0; + move16(); + st->old_wsp_shift = 0; + move16(); + st->sharpFlag = 0; #ifdef DEBUGGING st_fx->id_element = -1; /* element ID */ move16(); #endif - st_fx->extl_orig = -1; /* extension layer */ - move16(); - st_fx->extl_brate_orig = 0; /* extension layer bitrate */ - move32(); + return error; } @@ -1684,6 +1762,7 @@ ivas_error init_encoder_ivas_fx( move16(); st->lp_noise_32fx = 0; move16(); + st->flag_noisy_speech_snr = 0; move16(); st->fd_cng_reset_flag = 0; @@ -1782,6 +1861,7 @@ ivas_error init_encoder_ivas_fx( /*-----------------------------------------------------------------* * CLDFB & resampling tools parameters *-----------------------------------------------------------------*/ + test(); test(); test(); @@ -1977,6 +2057,9 @@ ivas_error init_encoder_ivas_fx( st->hBWE_FD = NULL; } + st->prev_Q_shb = 0; + move16(); + /*-----------------------------------------------------------------* * HQ core parameters *-----------------------------------------------------------------*/ @@ -2209,12 +2292,6 @@ ivas_error init_encoder_ivas_fx( set16_fx( st->totalNoise_increase_hist_fx, 0, TOTALNOISE_HIST_SIZE ); st->totalNoise_increase_len = 0; move16(); - TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; - IF( hTcxEnc != NULL ) - { - hTcxEnc->L_frameTCX = frame_length; - move16(); - } st->prevEnergyHF_fx = 0; move32(); @@ -2326,6 +2403,10 @@ ivas_error init_encoder_ivas_fx( move16(); st->sharpFlag = 0; move16(); +#ifdef DEBUGGING + st_fx->id_element = -1; /* element ID */ + move16(); +#endif return error; } diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 899f12a15..8b3d56e8e 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -1234,13 +1234,12 @@ typedef struct enc_core_structure * Common parameters *----------------------------------------------------------------------------------*/ - Word16 idchan; /* channel ID (audio channel number) */ - Word16 id_element; /* element ID */ + Word16 idchan; /* channel ID (audio channel number) */ +#ifdef DEBUGGING + Word16 id_element; /* element ID */ +#endif Word16 element_mode; /* element mode */ - Word16 last_element_mode; /* element mode */ Word32 element_brate; /* element bitrate */ - Word16 extl_orig; /* extension layer */ - Word32 extl_brate_orig; /* extension layer bitrate */ Word16 codec_mode; /* Mode1 or Mode2 */ Word16 last_codec_mode; /* previous frame Mode 1 or 2 */ Word16 last_codec_mode_cng; /* previous inactive frame Mode 1 or 2 */ -- GitLab From 735c8188cf3b8a683a6b0efeb4be4d754fb5e9f2 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 9 Sep 2025 18:52:30 +0200 Subject: [PATCH 06/15] update init_encoder_fx() --- lib_enc/init_enc_fx.c | 336 ++++++++++++++++++++----------------- lib_enc/ivas_init_enc_fx.c | 144 ---------------- lib_enc/ivas_sce_enc_fx.c | 12 +- lib_enc/prot_fx_enc.h | 5 +- 4 files changed, 188 insertions(+), 309 deletions(-) diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index a53b1f9b7..bc9a72ee7 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -21,15 +21,14 @@ *-----------------------------------------------------------------------*/ ivas_error init_encoder_fx( - Encoder_State *st_fx, /* i/o: Encoder static variables structure */ - const int16_t var_SID_rate_flag, /* i : flag for variable SID update rate */ - const int16_t interval_SID /* i : interval for SID update */ + Encoder_State *st_fx, /* i/o: Encoder static variables structure */ + Encoder_Struct *st_ivas /* i/o: encoder state structure */ ) { Word16 i; - - Word16 idchan = 0; /* i : channel ID */ - Word16 vad_only_flag = 0; /* i : channel ID */ + Word32 L_tmp; + Word16 idchan = 0; + Word16 vad_only_flag = 0; move16(); move16(); ISM_MODE ism_mode = ISM_MODE_NONE; @@ -40,9 +39,77 @@ ivas_error init_encoder_fx( Word16 frame_length = extract_l( Mpy_32_32( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + /*-----------------------------------------------------------------* + * General parameters + *-----------------------------------------------------------------*/ + + IF( st->Opt_AMR_WB ) + { + st->last_core = AMR_WB_CORE; + } + ELSE + { + st->last_core = -1; + } + move16(); + + st->L_frame = L_FRAME; + move16(); + st->last_coder_type = GENERIC; + move16(); + st->coder_type = GENERIC; + move16(); + st->last_total_brate = st->total_brate; + move32(); + st->last_bits_frame_nominal = -1; + move16(); + st->last_total_brate_cng = -1; + move16(); + st->last_core_brate = st->total_brate; + move32(); + st->dtx_sce_sba = 0; + move16(); + st->extl = -1; + move16(); + st->last_extl = -1; + move16(); + st->last_L_frame = L_FRAME; + move16(); + st->rate_switching_reset = 0; + move16(); + st->rate_switching_reset_16kHz = 0; + move16(); + st->clas = UNVOICED_CLAS; + move16(); + st->low_rate_mode = 0; + move16(); + st->ini_frame = 0; + move16(); + st->inactive_coder_type_flag = 0; + move16(); + st->sba_br_sw_while_no_data = 0; + move16(); + + st->coder_type_raw = VOICED; + move16(); + st->last_coder_type_raw = st->coder_type_raw; + move16(); + + st->flag_ACELP16k = set_ACELP_flag_IVAS( st->element_mode, st->total_brate, st->total_brate, idchan, 0, -1, -1 ); + move16(); + + st->is_ism_format = 0; + move16(); + if ( NE_16( ism_mode, ISM_MODE_NONE ) ) + { + st->is_ism_format = 1; + move16(); + } + /*-----------------------------------------------------------------* * General signal buffers *-----------------------------------------------------------------*/ + IF( !vad_only_flag ) { IF( ( st->hSignalBuf = (SIGNAL_BUFFERS_ENC_HANDLE) malloc( sizeof( SIGNAL_BUFFERS_ENC_DATA ) ) ) == NULL ) @@ -99,18 +166,20 @@ ivas_error init_encoder_fx( move16(); st->q_old_inp32 = Q31; move16(); - st->old_input_signal_fx = st->input_buff_fx; - st->old_input_signal32_fx = st->input_buff32_fx; IF( st->element_mode == EVS_MONO ) { st->input32_fx = st->input_buff32_fx + add( frame_length, NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ) ); - st->input_fx = st->input_buff_fx + add( frame_length, NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ) ); + st->input_fx = st->input_buff_fx + add( L_FRAME48k, NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); ///////////////////// input_Fs + st->old_input_signal_fx = st_fx->input_fx - add( NS2SA_FX2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ), frame_length ); + st->old_input_signal32_fx = st->input_buff32_fx; } ELSE { st->input32_fx = st->input_buff32_fx + frame_length; st->input_fx = st->input_buff_fx + frame_length; + st->old_input_signal_fx = st->input_buff_fx; + st->old_input_signal32_fx = st->input_buff32_fx; } } ELSE @@ -128,72 +197,6 @@ ivas_error init_encoder_fx( st->input_buff_fx = NULL; } - /*-----------------------------------------------------------------* - * ACELP core parameters - *-----------------------------------------------------------------*/ - - IF( st->Opt_AMR_WB ) - { - st->last_core = AMR_WB_CORE; - } - ELSE - { - st->last_core = -1; - } - move16(); - - st->L_frame = L_FRAME; - move16(); - st->last_coder_type = GENERIC; - move16(); - st->coder_type = GENERIC; - move16(); - st->last_total_brate = st->total_brate; - move32(); - st->last_bits_frame_nominal = -1; - move16(); - st->last_total_brate_cng = -1; - move16(); - st->last_core_brate = st->total_brate; - move32(); - st->dtx_sce_sba = 0; - move16(); - st->extl = -1; - move16(); - st->last_extl = -1; - move16(); - st->last_L_frame = L_FRAME; - move16(); - st->rate_switching_reset = 0; - move16(); - st->rate_switching_reset_16kHz = 0; - move16(); - st->clas = UNVOICED_CLAS; - move16(); - st->low_rate_mode = 0; - move16(); - st->ini_frame = 0; - move16(); - st->inactive_coder_type_flag = 0; - move16(); - st->sba_br_sw_while_no_data = 0; - move16(); - - st->coder_type_raw = VOICED; - move16(); - st->last_coder_type_raw = st->coder_type_raw; - move16(); - - st->flag_ACELP16k = set_ACELP_flag_IVAS( st->element_mode, st->total_brate, st->total_brate, idchan, 0, -1, -1 ); - move16(); - - st->is_ism_format = 0; - move16(); - if ( NE_16( ism_mode, ISM_MODE_NONE ) ) - { - st->is_ism_format = 1; - move16(); - } /*-----------------------------------------------------------------* * Bitstream *-----------------------------------------------------------------*/ @@ -204,33 +207,31 @@ ivas_error init_encoder_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Bitstream structure\n" ) ); } + + /* set pointer to the buffer of indices */ + st->hBstr->ind_list = st_ivas->ind_list; + st->hBstr->ivas_ind_list_zero = &st_ivas->ind_list; + st->hBstr->ivas_max_num_indices = &st_ivas->ivas_max_num_indices; + st->hBstr->nb_ind_tot = 0; + move16(); + st->hBstr->nb_bits_tot = 0; + move16(); + st->hBstr->st_ivas = st_ivas; } ELSE { st->hBstr = NULL; } - - Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); - Copy( GEWB_Ave_fx, st_fx->lsfoldbfi0_fx, M ); - Copy( GEWB_Ave_fx, st_fx->lsfoldbfi1_fx, M ); - Copy( GEWB_Ave_fx, st_fx->lsf_adaptive_mean_fx, M ); - init_lvq_fx( st_fx->offset_scale1_fx, st_fx->offset_scale2_fx, st_fx->offset_scale1_p_fx, st_fx->offset_scale2_p_fx, st_fx->no_scales_fx, st_fx->no_scales_p_fx ); - st_fx->next_force_safety_net = 0; - move16(); - st_fx->pstreaklen = 0; - move16(); - st_fx->streaklimit_fx = 32767; - move16(); /*1;//Q15 */ - set16_fx( st_fx->mem_MA_fx, 0, M ); - - init_gp_clip_fx( st_fx->clip_var_fx ); - pitch_ol_init_fx( &st_fx->old_thres_fx, &st_fx->old_pitch, &st_fx->delta_pit, &st_fx->old_corr_fx ); + /*-----------------------------------------------------------------* + * Pre-processing and ACELP core parameters + *-----------------------------------------------------------------*/ Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); Copy( GEWB_Ave_fx, st->lsfoldbfi0_fx, M ); Copy( GEWB_Ave_fx, st->lsfoldbfi1_fx, M ); Copy( GEWB_Ave_fx, st->lsf_adaptive_mean_fx, M ); + init_lvq_fx( st_fx->offset_scale1_fx, st_fx->offset_scale2_fx, st_fx->offset_scale1_p_fx, st_fx->offset_scale2_p_fx, st_fx->no_scales_fx, st_fx->no_scales_p_fx ); st->next_force_safety_net = 0; move16(); @@ -243,6 +244,8 @@ ivas_error init_encoder_fx( init_gp_clip_fx( st->clip_var_fx ); pitch_ol_init_fx( &st->old_thres_fx, &st->old_pitch, &st->delta_pit, &st->old_corr_fx ); + + set16_fx( st->old_wsp_fx, 0, L_WSP_MEM ); st->exp_old_wsp = 0; move16(); @@ -287,6 +290,7 @@ ivas_error init_encoder_fx( set32_fx( st->Bin_E_fx, 0, L_FFT ); st->q_Bin_E = Q31; move16(); + set16_fx( st_fx->lgBin_E_fx, 0, L_FFT / 2 ); //////////////////////////////////////// st->ee_old_fx = 640; /* 10.0f in Q6 */ move16(); @@ -298,6 +302,8 @@ ivas_error init_encoder_fx( /* adaptive lag window memory */ st->old_pitch_la = 0; move16(); + st_fx->old_voicing_la = 0; //////////////////////////////////////////////////// + move16(); st->prev_Q_new = 0; move16(); @@ -347,6 +353,8 @@ ivas_error init_encoder_fx( /* TC coder type */ st->tc_cnt = 0; move16(); + st_fx->mCb1_fx = 0; /////////////////////////////////////// + move16(); /* find_uv() parameters */ st->old_dE1_fx = 0; @@ -427,7 +435,6 @@ ivas_error init_encoder_fx( set16_fx( st->pitch, L_SUBFR, 3 ); set16_fx( st->voicing_fx, 0, 3 ); - /*-----------------------------------------------------------------* * AMR-WB IO initialization *-----------------------------------------------------------------*/ @@ -446,7 +453,6 @@ ivas_error init_encoder_fx( st_fx->hAmrwb_IO = NULL; } - /*-----------------------------------------------------------------* * parameters for AC coder type (GSC) *-----------------------------------------------------------------*/ @@ -528,7 +534,6 @@ ivas_error init_encoder_fx( st_fx->hVAD_CLDFB = NULL; } - /*-----------------------------------------------------------------* * Noise estimator *-----------------------------------------------------------------*/ @@ -600,7 +605,6 @@ ivas_error init_encoder_fx( st_fx->last_bwidth_cng = st_fx->bwidth; move16(); - /*-----------------------------------------------------------------* * DTX *-----------------------------------------------------------------*/ @@ -622,7 +626,7 @@ ivas_error init_encoder_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX variables\n" ) ); } - dtx_enc_init_fx( st, var_SID_rate_flag, interval_SID ); + dtx_enc_init_fx( st, st_ivas->hEncoderConfig->var_SID_rate_flag, st_ivas->hEncoderConfig->interval_SID ); } ELSE { @@ -666,7 +670,6 @@ ivas_error init_encoder_fx( st->hTdCngEnc = NULL; } - /*-----------------------------------------------------------------* * ACELP LPDmem *-----------------------------------------------------------------*/ @@ -694,7 +697,6 @@ ivas_error init_encoder_fx( st->hLPDmem = NULL; } - /*-----------------------------------------------------------------* * CLDFB Analysis *-----------------------------------------------------------------*/ @@ -740,7 +742,6 @@ ivas_error init_encoder_fx( move16(); } - /*-----------------------------------------------------------------* * SC-VBR parameters *-----------------------------------------------------------------*/ @@ -770,6 +771,7 @@ ivas_error init_encoder_fx( { st_fx->hPlcExt = NULL; } + /*-----------------------------------------------------------------* * Temporal Envelope Coding *-----------------------------------------------------------------*/ @@ -825,7 +827,7 @@ ivas_error init_encoder_fx( IF( st->element_mode == EVS_MONO ) { - if ( ( error = openCldfb( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000 ) ) != IVAS_ERR_OK ) + IF( ( error = openCldfb( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000 ) ) != IVAS_ERR_OK ) { return error; } @@ -867,22 +869,6 @@ ivas_error init_encoder_fx( st_fx->hRF = NULL; } - - /*-----------------------------------------------------------------* - * HQ core parameters - *-----------------------------------------------------------------*/ - - st_fx->Energy_Old_fx = 0; - move16(); - st_fx->Q_old_wtda = 15; - move16(); - st_fx->EnergyLT_fx = 1; - move32(); - st_fx->EnergyLT_fx_exp = 30; - move16(); /* Set to a High Exponent so it is 1^-30 */ - st_fx->TransientHangOver = 0; - move16(); - /*-----------------------------------------------------------------* * TCX core *-----------------------------------------------------------------*/ @@ -928,6 +914,7 @@ ivas_error init_encoder_fx( st->hTcxEnc = NULL; st->hTcxCfg = NULL; } + /*-----------------------------------------------------------------* * HQ core parameters *-----------------------------------------------------------------*/ @@ -951,11 +938,26 @@ ivas_error init_encoder_fx( st_fx->last_enerBuffer_exp = 0; move16(); + /* init memory for detect_transient(), used by HQ core and swb_bwe_enc */ + st->old_hpfilt_in_fx = 0; + move16(); + st->old_hpfilt_out_fx = 0; + move16(); + st->EnergyLT_fx = 0; + move32(); + st->Energy_Old_fx = 0; + move32(); + st->TransientHangOver = 0; + move16(); + st->EnergyLT_fx_exp = 30; + move16(); + st->last_enerBuffer_exp = 0; + move16(); + /*-----------------------------------------------------------------* * Channel-aware mode *-----------------------------------------------------------------*/ - test(); test(); test(); @@ -983,17 +985,71 @@ ivas_error init_encoder_fx( /* initialize RF indice buffers */ reset_rf_indices_fx( st_fx ); + /*-----------------------------------------------------------------* * MODE2 initialization *-----------------------------------------------------------------*/ st_fx->last_sr_core = i_mult2( st_fx->last_L_frame, 50 ); move16(); + /*-----------------------------------------------------------------* * IGF *-----------------------------------------------------------------*/ - move16(); + Word32 igf_brate = st->total_brate; + move32(); + + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( st->element_mode, IVAS_SCE ) && ( EQ_16( st_ivas->hEncoderConfig->ivas_format, ISM_FORMAT ) || EQ_16( st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) ) + { + igf_brate = L_sub( st->total_brate, i_mult( ISM_NB_BITS_METADATA_NOMINAL, FRAMES_PER_SEC ) ); + } + ELSE IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || ( EQ_16( st->element_mode, IVAS_SCE ) && ( EQ_16( st_ivas->hEncoderConfig->ivas_format, SBA_FORMAT ) || + EQ_16( st_ivas->hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) || + EQ_16( st_ivas->hEncoderConfig->ivas_format, MC_FORMAT ) || + EQ_16( st_ivas->hEncoderConfig->ivas_format, MASA_FORMAT ) ) ) ) + { +#if 0 + /* use nominal bitrates for DFT Stereo and (O)SBA, same as in stereo_dft_config()/ivas_spar_config() */ + IF( EQ_32( element_brate, IVAS_13k2 ) ) + { + igf_brate = ACELP_9k60; + } + ELSE IF( EQ_32( element_brate, IVAS_16k4 ) ) + { + igf_brate = ACELP_13k20; + } + ELSE IF( EQ_32( element_brate, IVAS_24k4 ) ) + { + igf_brate = ACELP_16k40; + } + ELSE IF( EQ_32( element_brate, IVAS_32k ) ) + { + igf_brate = ACELP_24k40; + } +#endif + } + ELSE IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + // igf_brate = element_brate; + } + + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + { + st_fx->igf = getIgfPresent_fx( st_fx->element_mode, igf_brate, st_fx->bwidth, st_fx->rf_mode ); + } + ELSE + { + st_fx->igf = 0; + move16(); + } test(); test(); @@ -1010,7 +1066,6 @@ ivas_error init_encoder_fx( st->hIGFEnc = NULL; } - /*-----------------------------------------------------------------* * FD-CNG encoder *-----------------------------------------------------------------*/ @@ -1050,7 +1105,6 @@ ivas_error init_encoder_fx( st->hFdCngEnc = NULL; } - st_fx->last_totalNoise_fx = 0; move16(); set16_fx( st_fx->totalNoise_increase_hist_fx, 0, TOTALNOISE_HIST_SIZE ); @@ -1078,13 +1132,6 @@ ivas_error init_encoder_fx( init_coder_ace_plus_ivas_fx( st, st->last_total_brate, -1, 0 ); } - IF( st->hLPDmem != NULL ) - { - st->hLPDmem->q_lpd_old_exc = st->prev_Q_new; - move16(); - } - - IF( ( st_fx->hTranDet = (TRAN_DET_HANDLE) malloc( sizeof( TRAN_DET_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Transient Detection\n" ) ); @@ -1092,6 +1139,12 @@ ivas_error init_encoder_fx( InitTransientDetection_fx( frame_length, NS2SA_FX2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ), st_fx->hTranDet ); +#if 1 ////////////////////////////////////////////////////////////////////////////////////////////// + + + set32_fx( st_fx->mem_hp20_in_fx, 0, 5 ); + + st_fx->Q_syn2 = 0; move16(); st_fx->Q_syn = 0; @@ -1104,8 +1157,7 @@ ivas_error init_encoder_fx( move16(); st_fx->old_wsp_shift = 0; move16(); - st_fx->sharpFlag = 0; - move16(); + st_fx->tdm_LRTD_flag = 0; /* LRTD stereo mode flag */ move16(); @@ -1113,29 +1165,8 @@ ivas_error init_encoder_fx( move16(); st_fx->cng_sba_flag = 0; /* CNG in SBA flag */ move16(); - st->bits_frame_channel = 0; - move16(); - st->side_bits_frame_channel = 0; - move16(); - st->Q_syn2 = 0; - move16(); - st->Q_syn = 0; - move16(); - set16_fx( st->Q_max, Q_MAX, L_Q_MEM ); - set16_fx( st->Q_max_16k, Q_MAX, L_Q_MEM ); - st->Q_old = 15; - move16(); - st->old_wsp_max = 0; - move16(); - st->old_wsp_shift = 0; - move16(); - st->sharpFlag = 0; - -#ifdef DEBUGGING - st_fx->id_element = -1; /* element ID */ - move16(); -#endif +#endif ////////////////////////////////////////////////////////////////////////////////////////////// return error; } @@ -1192,12 +1223,14 @@ void LPDmem_enc_init_ivas_fx( set16_fx( hLPDmem->mem_syn2, 0, M ); set16_fx( hLPDmem->mem_syn_r, 0, L_SYN_MEM ); set16_fx( hLPDmem->mem_syn3, 0, M ); + hLPDmem->q_lpd_old_exc = Q15; move16(); hLPDmem->q_lpd_syn = Q15; move16(); hLPDmem->q_mem_syn = Q15; move16(); + hLPDmem->mem_w0 = 0; move16(); hLPDmem->tilt_code = 0; @@ -1339,6 +1372,7 @@ ivas_error init_encoder_ivas_fx( Copy( GEWB_Ave_fx, st->lsfoldbfi0_fx, M ); Copy( GEWB_Ave_fx, st->lsfoldbfi1_fx, M ); Copy( GEWB_Ave_fx, st->lsf_adaptive_mean_fx, M ); + init_lvq_fx( st->offset_scale1_fx, st->offset_scale2_fx, st->offset_scale1_p_fx, st->offset_scale2_p_fx, st->no_scales_fx, st->no_scales_p_fx ); st->next_force_safety_net = 0; move16(); diff --git a/lib_enc/ivas_init_enc_fx.c b/lib_enc/ivas_init_enc_fx.c index 1b35b7022..333d010df 100644 --- a/lib_enc/ivas_init_enc_fx.c +++ b/lib_enc/ivas_init_enc_fx.c @@ -1188,150 +1188,6 @@ void destroy_core_enc_fx( return; } -void destroy_evs_core_enc_fx( - ENC_CORE_HANDLE hCoreCoder /* i/o: core encoder structure */ -) -{ - Word16 i; - - IF( hCoreCoder->hBstr != NULL ) - { - /* reset buffer of indices */ - FOR( i = 0; i < hCoreCoder->hBstr->nb_ind_tot; i++ ) - { - hCoreCoder->hBstr->ind_list[i].nb_bits = -1; - move16(); - } - free( hCoreCoder->hBstr ); - hCoreCoder->hBstr = NULL; - } - - IF( hCoreCoder->hLPDmem != NULL ) - { - free( hCoreCoder->hLPDmem ); - hCoreCoder->hLPDmem = NULL; - } - - IF( hCoreCoder->hTranDet != NULL ) - { - free( hCoreCoder->hTranDet ); - hCoreCoder->hTranDet = NULL; - } - - IF( hCoreCoder->hNoiseEst != NULL ) - { - free( hCoreCoder->hNoiseEst ); - hCoreCoder->hNoiseEst = NULL; - } - - IF( hCoreCoder->hVAD != NULL ) - { - free( hCoreCoder->hVAD ); - hCoreCoder->hVAD = NULL; - } - - IF( hCoreCoder->hVAD_CLDFB != NULL ) - { - /* This is not required as we are not allocating memory dynamically */ - // free( hCoreCoder->hVAD_CLDFB ); - hCoreCoder->hVAD_CLDFB = NULL; - } - - IF( hCoreCoder->hTdCngEnc != NULL ) - { - free( hCoreCoder->hTdCngEnc ); - hCoreCoder->hTdCngEnc = NULL; - } - - IF( hCoreCoder->hDtxEnc != NULL ) - { - free( hCoreCoder->hDtxEnc ); - hCoreCoder->hDtxEnc = NULL; - } - - IF( hCoreCoder->hSpMusClas != NULL ) - { - free( hCoreCoder->hSpMusClas ); - hCoreCoder->hSpMusClas = NULL; - } - - IF( hCoreCoder->hGSCEnc != NULL ) - { - free( hCoreCoder->hGSCEnc ); - hCoreCoder->hGSCEnc = NULL; - } - - IF( hCoreCoder->hSC_VBR != NULL ) - { - free( hCoreCoder->hSC_VBR ); - hCoreCoder->hSC_VBR = NULL; - } - - IF( hCoreCoder->hAmrwb_IO != NULL ) - { - free( hCoreCoder->hAmrwb_IO ); - hCoreCoder->hAmrwb_IO = NULL; - } - - IF( hCoreCoder->hBWE_TD != NULL ) - { - free( hCoreCoder->hBWE_TD ); - hCoreCoder->hBWE_TD = NULL; - } - - IF( hCoreCoder->hBWE_FD != NULL ) - { - free( hCoreCoder->hBWE_FD ); - hCoreCoder->hBWE_FD = NULL; - } - - IF( hCoreCoder->hRF != NULL ) - { - free( hCoreCoder->hRF ); - hCoreCoder->hRF = NULL; - } - - IF( hCoreCoder->hTECEnc != NULL ) - { - free( hCoreCoder->hTECEnc ); - hCoreCoder->hTECEnc = NULL; - } - - IF( hCoreCoder->hTcxEnc != NULL ) - { - free( hCoreCoder->hTcxEnc ); - hCoreCoder->hTcxEnc = NULL; - } - - IF( hCoreCoder->hTcxCfg != NULL ) - { - free( hCoreCoder->hTcxCfg ); - hCoreCoder->hTcxCfg = NULL; - } - - IF( hCoreCoder->hIGFEnc != NULL ) - { - free( hCoreCoder->hIGFEnc ); - hCoreCoder->hIGFEnc = NULL; - } - - IF( hCoreCoder->hPlcExt != NULL ) - { - free( hCoreCoder->hPlcExt ); - hCoreCoder->hPlcExt = NULL; - } - - IF( hCoreCoder->hHQ_core != NULL ) - { - free( hCoreCoder->hHQ_core ); - hCoreCoder->hHQ_core = NULL; - } - - free( hCoreCoder ); - - return; -} - /*------------------------------------------------------------------------- * ivas_destroy_enc_fx() diff --git a/lib_enc/ivas_sce_enc_fx.c b/lib_enc/ivas_sce_enc_fx.c index 170406b20..9424f7e9b 100644 --- a/lib_enc/ivas_sce_enc_fx.c +++ b/lib_enc/ivas_sce_enc_fx.c @@ -476,20 +476,10 @@ ivas_error create_sce_enc_fx( IF( st->element_mode == EVS_MONO ) { - IF( NE_32( ( error = init_encoder_fx( st, st_ivas->hEncoderConfig->var_SID_rate_flag, st_ivas->hEncoderConfig->interval_SID ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = init_encoder_fx( st, st_ivas ) ), IVAS_ERR_OK ) ) { return error; } - - /* set pointer to the buffer of indices */ - st->hBstr->ind_list = st_ivas->ind_list; - st->hBstr->ivas_ind_list_zero = &st_ivas->ind_list; - st->hBstr->ivas_max_num_indices = &st_ivas->ivas_max_num_indices; - st->hBstr->nb_ind_tot = 0; - move16(); - st->hBstr->nb_bits_tot = 0; - move16(); - st->hBstr->st_ivas = st_ivas; } ELSE { diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 1842c3252..2399e9d20 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -4588,9 +4588,8 @@ void index_lvq_ivas_fx( const Word16 prediction_flag ); ivas_error init_encoder_fx( - Encoder_State *st_fx, /* i/o: Encoder static variables structure */ - const int16_t var_SID_rate_flag, /* i : flag for variable SID update rate */ - const int16_t interval_SID /* i : interval for SID update */ + Encoder_State *st_fx, /* i/o: Encoder static variables structure */ + Encoder_Struct *st_ivas /* i/o: encoder state structure */ ); void copy_encoder_config_fx( -- GitLab From a3b9d78244d6fe1e2d0fe2c16f9db2016e7fa9d1 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 9 Sep 2025 21:57:06 +0200 Subject: [PATCH 07/15] harmonize LPDmem_enc_init_fx() --- lib_enc/init_enc_fx.c | 73 +++++++------------------- lib_enc/ivas_stereo_switching_enc_fx.c | 2 +- lib_enc/prot_fx_enc.h | 4 -- 3 files changed, 21 insertions(+), 58 deletions(-) diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index bc9a72ee7..d8e6f967e 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -26,7 +26,6 @@ ivas_error init_encoder_fx( ) { Word16 i; - Word32 L_tmp; Word16 idchan = 0; Word16 vad_only_flag = 0; move16(); @@ -683,14 +682,7 @@ ivas_error init_encoder_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LPDmem\n" ) ); } - IF( st->element_mode == EVS_MONO ) - { - LPDmem_enc_init_fx( st->hLPDmem ); - } - ELSE - { - LPDmem_enc_init_ivas_fx( st->hLPDmem ); - } + LPDmem_enc_init_fx( st->hLPDmem ); } ELSE { @@ -1144,6 +1136,9 @@ ivas_error init_encoder_fx( set32_fx( st_fx->mem_hp20_in_fx, 0, 5 ); + /*-----------------------------------------------------------------* + * IVAS parameters + *-----------------------------------------------------------------*/ st_fx->Q_syn2 = 0; move16(); @@ -1191,39 +1186,6 @@ void LPDmem_enc_init_fx( set16_fx( hLPDmem->mem_syn_r, 0, L_SYN_MEM ); set16_fx( hLPDmem->mem_syn3, 0, M ); - hLPDmem->mem_w0 = 0; - move16(); - hLPDmem->tilt_code = 0; - move16(); - hLPDmem->gc_threshold = 0; - move32(); - hLPDmem->dm_fx.prev_state = 0; - move16(); /* This corresponds to st_fx->dispMem in FLP */ - hLPDmem->dm_fx.prev_gain_code = 0; - move32(); - - FOR( i = 2; i < 8; i++ ) - { - hLPDmem->dm_fx.prev_gain_pit[i - 2] = 0; - move16(); - } - return; -} - -void LPDmem_enc_init_ivas_fx( - LPD_state_HANDLE hLPDmem /* i/o: LP memories */ -) -{ - Word16 i; - - set16_fx( hLPDmem->syn, 0, 1 + M ); - set16_fx( hLPDmem->old_exc, 0, L_EXC_MEM ); - set16_fx( hLPDmem->mem_syn, 0, M ); - set16_fx( hLPDmem->mem_syn1_fx, 0, M ); - set16_fx( hLPDmem->mem_syn2, 0, M ); - set16_fx( hLPDmem->mem_syn_r, 0, L_SYN_MEM ); - set16_fx( hLPDmem->mem_syn3, 0, M ); - hLPDmem->q_lpd_old_exc = Q15; move16(); hLPDmem->q_lpd_syn = Q15; @@ -1383,8 +1345,13 @@ ivas_error init_encoder_ivas_fx( move16(); set16_fx( st->mem_MA_fx, 0, M ); + st->mCb1_fx = 0; + move16(); + init_gp_clip_fx( st->clip_var_fx ); + pitch_ol_init_fx( &st->old_thres_fx, &st->old_pitch, &st->delta_pit, &st->old_corr_fx ); + set16_fx( st->old_wsp_fx, 0, L_WSP_MEM ); st->exp_old_wsp = 0; move16(); @@ -1429,6 +1396,7 @@ ivas_error init_encoder_ivas_fx( set32_fx( st->Bin_E_fx, 0, L_FFT ); st->q_Bin_E = Q31; move16(); + set16_fx( st->lgBin_E_fx, 0, L_FFT / 2 ); st->ee_old_fx = 640; /* 10.0f in Q6 */ move16(); @@ -1440,6 +1408,8 @@ ivas_error init_encoder_ivas_fx( /* adaptive lag window memory */ st->old_pitch_la = 0; move16(); + st->old_voicing_la = 0; + move16(); st->prev_Q_new = 0; move16(); @@ -1569,6 +1539,8 @@ ivas_error init_encoder_ivas_fx( set16_fx( st->pitch, L_SUBFR, 3 ); set16_fx( st->voicing_fx, 0, 3 ); + set32_fx( st->mem_hp20_in_fx, 0, 5 ); //////////////////////////// + /*-----------------------------------------------------------------* * General signal buffers *-----------------------------------------------------------------*/ @@ -1629,18 +1601,20 @@ ivas_error init_encoder_ivas_fx( move16(); st->q_old_inp32 = Q31; move16(); - st->old_input_signal_fx = st->input_buff_fx; - st->old_input_signal32_fx = st->input_buff32_fx; IF( st->element_mode == EVS_MONO ) { st->input32_fx = st->input_buff32_fx + add( frame_length, NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ) ); - st->input_fx = st->input_buff_fx + add( frame_length, NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ) ); + st->input_fx = st->input_buff_fx + add( L_FRAME48k, NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); ///////////////////// input_Fs + st->old_input_signal_fx = st->input_fx - add( NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), frame_length ); + st->old_input_signal32_fx = st->input_buff32_fx; } ELSE { st->input32_fx = st->input_buff32_fx + frame_length; st->input_fx = st->input_buff_fx + frame_length; + st->old_input_signal_fx = st->input_buff_fx; + st->old_input_signal32_fx = st->input_buff32_fx; } } ELSE @@ -1992,14 +1966,7 @@ ivas_error init_encoder_ivas_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LPDmem\n" ) ); } - IF( st->element_mode == EVS_MONO ) - { - LPDmem_enc_init_fx( st->hLPDmem ); - } - ELSE - { - LPDmem_enc_init_ivas_fx( st->hLPDmem ); - } + LPDmem_enc_init_fx( st->hLPDmem ); } ELSE { diff --git a/lib_enc/ivas_stereo_switching_enc_fx.c b/lib_enc/ivas_stereo_switching_enc_fx.c index 60215658f..b6690d8c7 100644 --- a/lib_enc/ivas_stereo_switching_enc_fx.c +++ b/lib_enc/ivas_stereo_switching_enc_fx.c @@ -58,7 +58,7 @@ static ivas_error allocate_CoreCoder_enc_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LPDmem\n" ) ); } - LPDmem_enc_init_ivas_fx( st->hLPDmem ); + LPDmem_enc_init_fx( st->hLPDmem ); } IF( st->hGSCEnc == NULL && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 2399e9d20..27e508c1a 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -863,10 +863,6 @@ void LPDmem_enc_init_fx( LPD_state_HANDLE hLPDmem /* i/o: LP memories */ ); -void LPDmem_enc_init_ivas_fx( - LPD_state_HANDLE hLPDmem /* i/o: LP memories */ -); - void lsf_end_enc_fx( Encoder_State *st, /* i/o: encoder state structure */ const Word16 *lsf, /* i : LSF in the frequency domain (0..6400) */ -- GitLab From 1e5c3936e9f058900131921c239bfc99b83b78ce Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 10 Sep 2025 14:22:40 +0200 Subject: [PATCH 08/15] harmonize init_encoder_fx() --- lib_com/prot_fx.h | 2 +- lib_enc/init_enc_fx.c | 1242 ++---------------------- lib_enc/ivas_cpe_enc_fx.c | 2 +- lib_enc/ivas_sce_enc_fx.c | 14 +- lib_enc/ivas_spar_encoder_fx.c | 2 +- lib_enc/ivas_stereo_switching_enc_fx.c | 5 +- lib_enc/prot_fx_enc.h | 5 - lib_enc/stat_enc.h | 73 +- 8 files changed, 91 insertions(+), 1254 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 7cf0148eb..7ba036dd4 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -11052,7 +11052,7 @@ void read_next_force( ); #endif -ivas_error init_encoder_ivas_fx( +ivas_error init_encoder_fx( Encoder_State *st, /* i/o: state structure */ Encoder_Struct *st_ivas, /* i/o: encoder state structure */ const Word16 idchan, /* i : channel ID */ diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index d8e6f967e..f55edfc08 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -1,1170 +1,56 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "rom_com.h" /* Static table prototypes */ -#include "stl.h" -#include "ivas_cnst.h" -#include "ivas_error.h" -#include "prot_fx.h" /* Function prototypes */ -#include "prot_fx_enc.h" /* Function prototypes */ -#include "ivas_prot_fx.h" - - -/*-----------------------------------------------------------------------* - * init_encoder_fx() - * - * Initialization of state variables - *-----------------------------------------------------------------------*/ - -ivas_error init_encoder_fx( - Encoder_State *st_fx, /* i/o: Encoder static variables structure */ - Encoder_Struct *st_ivas /* i/o: encoder state structure */ -) -{ - Word16 i; - Word16 idchan = 0; - Word16 vad_only_flag = 0; - move16(); - move16(); - ISM_MODE ism_mode = ISM_MODE_NONE; - ivas_error error; - Encoder_State *st = st_fx; - - error = IVAS_ERR_OK; - - Word16 frame_length = extract_l( Mpy_32_32( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - - /*-----------------------------------------------------------------* - * General parameters - *-----------------------------------------------------------------*/ - - IF( st->Opt_AMR_WB ) - { - st->last_core = AMR_WB_CORE; - } - ELSE - { - st->last_core = -1; - } - move16(); - - st->L_frame = L_FRAME; - move16(); - st->last_coder_type = GENERIC; - move16(); - st->coder_type = GENERIC; - move16(); - st->last_total_brate = st->total_brate; - move32(); - st->last_bits_frame_nominal = -1; - move16(); - st->last_total_brate_cng = -1; - move16(); - st->last_core_brate = st->total_brate; - move32(); - st->dtx_sce_sba = 0; - move16(); - st->extl = -1; - move16(); - st->last_extl = -1; - move16(); - st->last_L_frame = L_FRAME; - move16(); - st->rate_switching_reset = 0; - move16(); - st->rate_switching_reset_16kHz = 0; - move16(); - st->clas = UNVOICED_CLAS; - move16(); - st->low_rate_mode = 0; - move16(); - st->ini_frame = 0; - move16(); - st->inactive_coder_type_flag = 0; - move16(); - st->sba_br_sw_while_no_data = 0; - move16(); - - st->coder_type_raw = VOICED; - move16(); - st->last_coder_type_raw = st->coder_type_raw; - move16(); - - st->flag_ACELP16k = set_ACELP_flag_IVAS( st->element_mode, st->total_brate, st->total_brate, idchan, 0, -1, -1 ); - move16(); - - st->is_ism_format = 0; - move16(); - if ( NE_16( ism_mode, ISM_MODE_NONE ) ) - { - st->is_ism_format = 1; - move16(); - } - - /*-----------------------------------------------------------------* - * General signal buffers - *-----------------------------------------------------------------*/ - - IF( !vad_only_flag ) - { - IF( ( st->hSignalBuf = (SIGNAL_BUFFERS_ENC_HANDLE) malloc( sizeof( SIGNAL_BUFFERS_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Signal buffers\n" ) ); - } - - st->Bin_E_old_fx = st->hSignalBuf->Bin_E_old_fx; - st->mem_decim_fx = st->hSignalBuf->mem_decim_fx; - st->mem_decim16k_fx = st->hSignalBuf->mem_decim16k_fx; - st->old_inp_12k8_fx = st->hSignalBuf->old_inp_12k8_fx; - st->old_inp_16k_fx = st->hSignalBuf->old_inp_16k_fx; - st->buf_speech_enc_pe = st->hSignalBuf->buf_speech_enc_pe; - st->buf_synth = st->hSignalBuf->buf_synth; - st->buf_speech_enc = st->hSignalBuf->buf_speech_enc; - st->buf_wspeech_enc = st->hSignalBuf->buf_wspeech_enc; - - set32_fx( st->Bin_E_old_fx, 0, L_FFT / 2 ); - st->q_Bin_E_old = Q31; - move16(); - set16_fx( st->hSignalBuf->buf_speech_enc, 0, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - st->exp_buf_speech_enc = 0; - move16(); - set16_fx( st->hSignalBuf->buf_wspeech_enc, 0, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); - st->exp_buf_wspeech_enc = 0; - move16(); - /* initializations */ - set32_fx( st->Bin_E_old_fx, 0, L_FFT / 2 ); - st->q_Bin_E_old = Q31; - move16(); - set16_fx( st->mem_decim_fx, 0, shl( L_FILT_MAX, 1 ) ); - set16_fx( st->mem_decim_fx_q_inp, 0, shl( L_FILT_MAX, 1 ) ); - set16_fx( st->mem_decim16k_fx, 0, shl( L_FILT_MAX, 1 ) ); - set16_fx( st->old_inp_12k8_fx, 0, L_INP_MEM ); - set16_fx( st->old_inp_16k_fx, 0, L_INP_MEM ); - st->exp_old_inp_16k = 0; - st->exp_old_inp_12k8 = 0; - move16(); - move16(); - - st->input_buff_fx = st->hSignalBuf->input_buff; - st->input_buff32_fx = st->hSignalBuf->input_buff32; - set16_fx( st->input_buff_fx, 0, add( L_FRAME48k, add( L_FRAME48k, NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ) ) ); - st->q_inp = Q15; - move16(); - st->mem_preemph_q = Q15; - move16(); - st->mem_q = Q15; - move16(); - st->q_old_inp = Q15; - move16(); - set32_fx( st->input_buff32_fx, 0, add( L_FRAME48k, add( L_FRAME48k, NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ) ) ); - st->q_inp32 = Q31; - move16(); - st->q_old_inp32 = Q31; - move16(); - - IF( st->element_mode == EVS_MONO ) - { - st->input32_fx = st->input_buff32_fx + add( frame_length, NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ) ); - st->input_fx = st->input_buff_fx + add( L_FRAME48k, NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); ///////////////////// input_Fs - st->old_input_signal_fx = st_fx->input_fx - add( NS2SA_FX2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ), frame_length ); - st->old_input_signal32_fx = st->input_buff32_fx; - } - ELSE - { - st->input32_fx = st->input_buff32_fx + frame_length; - st->input_fx = st->input_buff_fx + frame_length; - st->old_input_signal_fx = st->input_buff_fx; - st->old_input_signal32_fx = st->input_buff32_fx; - } - } - ELSE - { - st->hSignalBuf = NULL; - st->Bin_E_old_fx = NULL; - st->mem_decim_fx = NULL; - st->mem_decim16k_fx = NULL; - st->old_inp_12k8_fx = NULL; - st->old_inp_16k_fx = NULL; - st->buf_speech_enc_pe = NULL; - st->buf_synth = NULL; - st->buf_speech_enc = NULL; - st->buf_wspeech_enc = NULL; - st->input_buff_fx = NULL; - } - - /*-----------------------------------------------------------------* - * Bitstream - *-----------------------------------------------------------------*/ - - IF( !vad_only_flag ) - { - IF( ( st->hBstr = (BSTR_ENC_HANDLE) malloc( sizeof( BSTR_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Bitstream structure\n" ) ); - } - - /* set pointer to the buffer of indices */ - st->hBstr->ind_list = st_ivas->ind_list; - st->hBstr->ivas_ind_list_zero = &st_ivas->ind_list; - st->hBstr->ivas_max_num_indices = &st_ivas->ivas_max_num_indices; - st->hBstr->nb_ind_tot = 0; - move16(); - st->hBstr->nb_bits_tot = 0; - move16(); - st->hBstr->st_ivas = st_ivas; - } - ELSE - { - st->hBstr = NULL; - } - - /*-----------------------------------------------------------------* - * Pre-processing and ACELP core parameters - *-----------------------------------------------------------------*/ - - Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); - Copy( GEWB_Ave_fx, st->lsfoldbfi0_fx, M ); - Copy( GEWB_Ave_fx, st->lsfoldbfi1_fx, M ); - Copy( GEWB_Ave_fx, st->lsf_adaptive_mean_fx, M ); - init_lvq_fx( st_fx->offset_scale1_fx, st_fx->offset_scale2_fx, st_fx->offset_scale1_p_fx, st_fx->offset_scale2_p_fx, st_fx->no_scales_fx, st_fx->no_scales_p_fx ); - - st->next_force_safety_net = 0; - move16(); - - st->pstreaklen = 0; - move16(); - st->streaklimit_fx = MAX_WORD16; - move16(); - set16_fx( st->mem_MA_fx, 0, M ); - - init_gp_clip_fx( st->clip_var_fx ); - pitch_ol_init_fx( &st->old_thres_fx, &st->old_pitch, &st->delta_pit, &st->old_corr_fx ); - - - set16_fx( st->old_wsp_fx, 0, L_WSP_MEM ); - st->exp_old_wsp = 0; - move16(); - set16_fx( st->old_wsp2_fx, 0, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); - st->Q_old_wsp2 = 0; - move16(); - - st->mem_preemph_fx = 0; - move16(); - st->mem_preemph_fx_q_inp = 0; - move16(); - st->mem_preemph16k_fx = 0; - move16(); - st->mem_preemph_enc = 0; - move16(); - st->exp_mem_preemph_enc = 0; - move16(); - - /* AVQ pre-quantizer memory */ - st->mem_preemp_preQ_fx = 0; - move16(); - st->mem_deemp_preQ_fx = 0; - move16(); - st->last_nq_preQ = 0; - move16(); - st->last_code_preq = 0; - move16(); - st->use_acelp_preq = 0; - move16(); - st->last_harm_flag_acelp = 0; - move16(); - - /* (Decimated) Weighted Speech Memory */ - st->mem_wsp_enc = 0; - move16(); - st->mem_wsp_fx = 0; - move16(); - st->mem_wsp_q = 0; - move16(); - - set16_fx( st->mem_decim2_fx, 0, 3 ); - set32_fx( st->Bin_E_fx, 0, L_FFT ); - st->q_Bin_E = Q31; - move16(); - set16_fx( st_fx->lgBin_E_fx, 0, L_FFT / 2 ); //////////////////////////////////////// - - st->ee_old_fx = 640; /* 10.0f in Q6 */ - move16(); - st->Nb_ACELP_frames = 0; - move16(); - st->audio_frame_cnt = AUDIO_COUNTER_INI; /* Initialization of the audio frame counter mildly into the audio mode */ - move16(); - - /* adaptive lag window memory */ - st->old_pitch_la = 0; - move16(); - st_fx->old_voicing_la = 0; //////////////////////////////////////////////////// - move16(); - - st->prev_Q_new = 0; - move16(); - - IF( EQ_32( st->input_Fs, 8000 ) ) - { - st->min_band = 1; - move16(); - st->max_band = 16; - move16(); - } - ELSE - { - st->min_band = 0; - move16(); - st->max_band = 19; - move16(); - } - - IF( st->Opt_AMR_WB ) - { - Copy( mean_isf_amr_wb_fx, st->lsf_old_fx, M ); - E_LPC_isf_isp_conversion( st->lsf_old_fx, st->lsp_old1_fx, M ); - } - ELSE - { - Copy( GEWB_Ave_fx, st->lsf_old_fx, M ); - lsf2lsp_fx( st->lsf_old_fx, st->lsp_old1_fx, M, INT_FS_12k8 ); - } - - Copy( st->lsf_old_fx, st->lsf_old1_fx, M ); - Copy( st->lsp_old1_fx, st->lsp_old_fx, M ); - Copy( st->lsp_old_fx, st->lsp_old16k_fx, M ); - Copy( st->lsp_old_fx, st->lspold_enc_fx, M ); - - st->stab_fac_fx = 0; - move16(); - - /* Bass post-filter memories - encoder side of MODE2 */ - st->bpf_off = 0; - move16(); - st->pst_mem_deemp_err_fx = 0; - move16(); - st->pst_lp_ener_fx = 0; - move16(); - - /* TC coder type */ - st->tc_cnt = 0; - move16(); - st_fx->mCb1_fx = 0; /////////////////////////////////////// - move16(); - - /* find_uv() parameters */ - st->old_dE1_fx = 0; - move16(); - st->old_ind_deltaMax = 0; - move16(); - set32_fx( st->old_enr_ssf_fx, 0, shl( NB_SSF, 1 ) ); - st->spike_hyst = -1; - move16(); - - /* stereo switching memories */ - st->mem_preemph_DFT_fx = 0; - move16(); - st->mem_preemph_DFT_fx_q_inp = 0; - move16(); - set16_fx( st->inp_12k8_mem_stereo_sw_fx, 0, sub( sub( STEREO_DFT_OVL_12k8, L_MEM_RECALC_12K8 ), L_FILT ) ); - st->mem_preemph16k_DFT_fx = 0; - move16(); - set16_fx( st->inp_16k_mem_stereo_sw_fx, 0, sub( sub( STEREO_DFT_OVL_16k, L_MEM_RECALC_16K ), L_FILT16k ) ); - - st->sharpFlag = 0; - move16(); - - /* Stationary noise UV modification */ - st->ge_sm_fx = L_deposit_l( 640 ); /*Q(GE_SHIFT)*/ - move16(); - st->uv_count = 0; - move16(); - st->act_count = 3; - move16(); - Copy( st->lsp_old_fx, st->lspold_s_fx, M ); - st->noimix_seed = RANDOM_INITSEED; - move16(); - st->min_alpha_fx = 32767; - move16(); - st->exc_pe_fx = 0; - move16(); - st->Q_stat_noise = 15; - move16(); - - /* FEC */ - st->last_clas = UNVOICED_CLAS; - move16(); - st->prev_fmerit = 0; - move16(); - st->fmerit_dt = 0; - move16(); - st->Last_pulse_pos = 0; - move16(); - - FOR( i = 0; i < shl( NB_SUBFR16k, 1 ); i++ ) - { - st->old_pitch_buf_fx[i] = L_SUBFR_Q6; - move16(); - } - - /* mode1 core switching */ - st->old_Es_pred_fx = 0; - move16(); - set16_fx( st->old_Aq_12_8_fx + 1, 0, M ); - st->old_Aq_12_8_fx[0] = ONE_IN_Q12; - move16(); - - /* stable short pitch detection */ - st->voicing0_sm_fx = 0; - move16(); - st->voicing_sm_fx = 0; - move16(); - st->LF_EnergyRatio_sm_fx = 1; - move16(); - st->predecision_flag = 0; - move16(); - st->diff_sm_fx = 0; - move32(); - st->energy_sm_fx = 0; - move32(); - - set16_fx( st->pitch, L_SUBFR, 3 ); - set16_fx( st->voicing_fx, 0, 3 ); - - /*-----------------------------------------------------------------* - * AMR-WB IO initialization - *-----------------------------------------------------------------*/ - test(); - IF( st_fx->Opt_AMR_WB || EQ_16( st_fx->element_mode, EVS_MONO ) ) - { - IF( ( st_fx->hAmrwb_IO = (AMRWB_IO_ENC_HANDLE) malloc( sizeof( AMRWB_IO_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AMR-WB IO\n" ) ); - } - - amr_wb_enc_init_fx( st_fx->hAmrwb_IO ); - } - ELSE - { - st_fx->hAmrwb_IO = NULL; - } - - /*-----------------------------------------------------------------* - * parameters for AC coder type (GSC) - *-----------------------------------------------------------------*/ - - st_fx->GSC_noisy_speech = 0; - st_fx->GSC_IVAS_mode = 0; - move16(); - test(); - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - IF( ( st_fx->hGSCEnc = (GSC_ENC_HANDLE) malloc( sizeof( GSC_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n" ) ); - } - - GSC_enc_init_fx( st_fx->hGSCEnc ); - } - ELSE - { - st_fx->hGSCEnc = NULL; - } - - st_fx->old_dE1_fx = 0; - move16(); - st_fx->old_ind_deltaMax = 0; - move32(); - set32_fx( st_fx->old_enr_ssf_fx, 0, 2 * NB_SSF ); - st_fx->spike_hyst = -1; - move16(); - st_fx->music_hysteresis_fx = 0; - move16(); /* Counter of frames after AUDIO frame to prevent UC */ - st_fx->last_harm_flag_acelp = 0; - move16(); - st_fx->GSC_noisy_speech = 0; - move16(); - - /*-----------------------------------------------------------------* - * VAD - *-----------------------------------------------------------------*/ - - st_fx->vad_flag = 1; - st_fx->localVAD = 0; - move16(); - move16(); - test(); - test(); - test(); - test(); - IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || st_fx->element_mode == EVS_MONO ) && ( !vad_only_flag ) ) - { - if ( ( st_fx->hVAD = (VAD_HANDLE) malloc( sizeof( VAD_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VAD\n" ) ); - } - - wb_vad_init_fx( st_fx->hVAD ); - } - ELSE - { - st_fx->hVAD = NULL; - } - - st_fx->Pos_relE_cnt = 5120; - move16(); /*20.0f*/ - - /* CLDFB-based VAD */ - IF( st_fx->element_mode == EVS_MONO ) - { - if ( ( st_fx->hVAD_CLDFB = (VAD_CLDFB_HANDLE) malloc( sizeof( T_CldfbVadState ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CLDFB VAD\n" ) ); - } - - vad_init_fx( st_fx->hVAD_CLDFB ); - } - ELSE - { - st_fx->hVAD_CLDFB = NULL; - } - - /*-----------------------------------------------------------------* - * Noise estimator - *-----------------------------------------------------------------*/ - - test(); - test(); - IF( /*idchan == 0 ||*/ EQ_16( st_fx->element_mode, IVAS_CPE_TD ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || st_fx->element_mode == EVS_MONO ) - { - if ( ( st_fx->hNoiseEst = (NOISE_EST_HANDLE) malloc( sizeof( NOISE_EST_DATA ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Noise estimation\n" ); - } - noise_est_init_fx( st_fx->hNoiseEst ); - } - ELSE - { - st_fx->hNoiseEst = NULL; - } - - /*-----------------------------------------------------------------* - * Speech/music classifier - *-----------------------------------------------------------------*/ - test(); - test(); - test(); - IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || st_fx->element_mode == EVS_MONO ) - { - IF( ( st_fx->hSpMusClas = (SP_MUS_CLAS_HANDLE) malloc( sizeof( SP_MUS_CLAS_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Speech/music classifier\n" ) ); - } - - speech_music_clas_init_fx( st_fx->hSpMusClas ); - - st_fx->sp_aud_decision0 = 0; - st_fx->sp_aud_decision1 = 0; - st_fx->sp_aud_decision2 = 0; - move16(); - move16(); - move16(); - } - ELSE - { - st_fx->hSpMusClas = NULL; - } - - st_fx->bckr_tilt_lt = 0; - move32(); - - /* WB, SWB and FB bandwidth detector */ - st_fx->lt_mean_NB_fx = 0; - move16(); - st_fx->lt_mean_WB_fx = 0; - move16(); - st_fx->lt_mean_SWB_fx = 0; - move16(); - st_fx->count_WB = BWD_COUNT_MAX; - move16(); - st_fx->count_SWB = BWD_COUNT_MAX; - move16(); - st_fx->count_FB = BWD_COUNT_MAX; - move16(); - st_fx->bwidth = st_fx->max_bwidth; - move16(); - st_fx->last_input_bwidth = st_fx->bwidth; - move16(); - st_fx->last_bwidth = st_fx->bwidth; - move16(); - st_fx->last_bwidth_cng = st_fx->bwidth; - move16(); - - /*-----------------------------------------------------------------* - * DTX - *-----------------------------------------------------------------*/ - - st->lp_speech_fx = 11520; /*Q8 (45.0) */ /* Initialize the long-term active speech level in dB */ - move16(); - st->lp_speech_32fx = 754974720; /*Q24 (45.0) */ /* Initialize the long-term active speech level in dB */ - move32(); - st->lp_noise_fx = 0; - move16(); - st->lp_noise_32fx = 0; - move16(); - - test(); - test(); - IF( ( ( idchan == 0 && st->Opt_DTX_ON ) || st->element_mode == EVS_MONO ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->Opt_DTX_ON ) ) - { - IF( ( st->hDtxEnc = (DTX_ENC_HANDLE) malloc( sizeof( DTX_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX variables\n" ) ); - } - dtx_enc_init_fx( st, st_ivas->hEncoderConfig->var_SID_rate_flag, st_ivas->hEncoderConfig->interval_SID ); - } - ELSE - { - st_fx->hDtxEnc = NULL; - } - - st_fx->fd_cng_reset_flag = 0; - move16(); - - IF( st_fx->Opt_DTX_ON ) - { - move16(); - } - - st_fx->cng_type = -1; - move16(); - - - /*-----------------------------------------------------------------* - * LP-CNG - *-----------------------------------------------------------------*/ - - IF( ( ( idchan == 0 && st->Opt_DTX_ON && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) || st->element_mode == EVS_MONO ) && !( EQ_16( ism_mode, ISM_MODE_PARAM ) || EQ_16( ism_mode, ISM_MODE_DISC ) ) ) - { - IF( ( st->hTdCngEnc = (TD_CNG_ENC_HANDLE) malloc( sizeof( TD_CNG_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); - } - - IF( st->element_mode == EVS_MONO ) - { - td_cng_enc_init_fx( st->hTdCngEnc, st->Opt_DTX_ON, st->max_bwidth ); - } - ELSE - { - td_cng_enc_init_ivas_fx( st->hTdCngEnc, st->Opt_DTX_ON, st->max_bwidth ); - } - } - ELSE - { - st->hTdCngEnc = NULL; - } - - /*-----------------------------------------------------------------* - * ACELP LPDmem - *-----------------------------------------------------------------*/ - - test(); - test(); - IF( ( idchan == 0 && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) - { - IF( ( st->hLPDmem = (LPD_state_HANDLE) malloc( sizeof( LPD_state ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LPDmem\n" ) ); - } - - LPDmem_enc_init_fx( st->hLPDmem ); - } - ELSE - { - st->hLPDmem = NULL; - } - - /*-----------------------------------------------------------------* - * CLDFB Analysis - *-----------------------------------------------------------------*/ - - test(); - test(); - test(); - IF( ( NE_16( st->element_mode, IVAS_CPE_MDCT ) && idchan == 0 ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->Opt_DTX_ON ) ) - { - IF( st->element_mode == EVS_MONO ) - { - /* open analysis for input SR */ - IF( ( error = openCldfb( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs ) ) != IVAS_ERR_OK ) - { - return error; - } - } - ELSE - { - IF( ( error = openCldfb_ivas_fx( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS, ENC ) ) != IVAS_ERR_OK ) - { - return error; - } - } - } - ELSE - { - st->cldfbAnaEnc = NULL; - } - - IF( st->element_mode == EVS_MONO ) - { - st->energyCoreLookahead_Fx = 0; - move32(); - st->sf_energyCoreLookahead_Fx = 0; - move16(); - } - ELSE - { - st->energyCoreLookahead_Fx = 2; /* 6.1e-5f in Q15 */ - move32(); - st->sf_energyCoreLookahead_Fx = 2; /* 6.1e-5f in Q15 */ - move16(); - } - - /*-----------------------------------------------------------------* - * SC-VBR parameters - *-----------------------------------------------------------------*/ - test(); - IF( st_fx->Opt_SC_VBR || st_fx->element_mode == EVS_MONO ) - { - IF( ( st_fx->hSC_VBR = (SC_VBR_ENC_HANDLE) malloc( sizeof( SC_VBR_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SC-VBR\n" ) ); - } - - sc_vbr_enc_init_fx( st_fx->hSC_VBR ); - } - ELSE - { - st_fx->hSC_VBR = NULL; - } - /* PLC encoder */ - IF( st_fx->element_mode == EVS_MONO ) - { - IF( ( st_fx->hPlcExt = (PLC_ENC_EVS_HANDLE) malloc( sizeof( PLC_ENC_EVS ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hPlcExt\n" ) ); - } - } - ELSE - { - st_fx->hPlcExt = NULL; - } - - /*-----------------------------------------------------------------* - * Temporal Envelope Coding - *-----------------------------------------------------------------*/ - - IF( st_fx->element_mode == EVS_MONO ) - { - IF( ( st_fx->hTECEnc = (TEC_ENC_HANDLE) malloc( sizeof( TEC_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TEC\n" ) ); - } - } - ELSE - { - st_fx->hTECEnc = NULL; - } - - /*-----------------------------------------------------------------* - * SWB BWE parameters - *-----------------------------------------------------------------*/ - test(); - IF( idchan == 0 && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) - { - IF( ( st->hBWE_FD = (FD_BWE_ENC_HANDLE) malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n" ) ); - } - - fd_bwe_enc_init_fx( st->hBWE_FD ); - st->Q_old_wtda = 0; - move16(); - } - ELSE - { - st->hBWE_FD = NULL; - } - - st_fx->prev_Q_shb = 0; - move16(); - st_fx->last_Opt_SC_VBR = 0; - move16(); - - /*-----------------------------------------------------------------* - * TBE parameters - *-----------------------------------------------------------------*/ - - test(); - IF( idchan == 0 && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) - { - IF( ( st->hBWE_TD = (TD_BWE_ENC_HANDLE) malloc( sizeof( TD_BWE_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); - } - - IF( st->element_mode == EVS_MONO ) - { - IF( ( error = openCldfb( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000 ) ) != IVAS_ERR_OK ) - { - return error; - } - - InitSWBencBuffer_fx( st /*st_fx->hBWE_TD*/ ); - } - ELSE - { - IF( ( error = openCldfb_ivas_fx( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS, ENC ) ) != IVAS_ERR_OK ) - { - return error; - } - - InitSWBencBuffer_ivas_fx( st ); - } - - ResetSHBbuffer_Enc_fx( st ); - } - ELSE - { - st->hBWE_TD = NULL; - st->cldfbSynTd = NULL; - } - - - test(); - IF( st_fx->Opt_RF_ON || st_fx->element_mode == EVS_MONO ) - { - IF( ( st_fx->hRF = (RF_ENC_HANDLE) malloc( sizeof( RF_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for RF\n" ) ); - } - - /* initialize RF indice buffers */ - reset_rf_indices_fx( st_fx /*->hRF, st_fx->L_frame, &st->rf_target_bits_write*/ ); - } - ELSE - { - st_fx->hRF = NULL; - } - - /*-----------------------------------------------------------------* - * TCX core - *-----------------------------------------------------------------*/ - - // ToDo: reduction possible for MCT_CHAN_MODE_LFE channel - test(); - IF( idchan == 0 || EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) - { - IF( ( st->hTcxEnc = (TCX_ENC_HANDLE) malloc( sizeof( TCX_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxEnc\n" ) ); - } - set32_fx( st->hTcxEnc->spectrum_long_fx, 0, N_MAX ); - st->hTcxEnc->spectrum_long_e = 0; - move16(); - - /* Share the memories for 2xTCX10/4xTCX5 and for TCX20 */ - st->hTcxEnc->spectrum_fx[0] = st->hTcxEnc->spectrum_long_fx; - st->hTcxEnc->spectrum_fx[1] = st->hTcxEnc->spectrum_long_fx + N_TCX10_MAX; - move32(); - move32(); - st->hTcxEnc->spectrum_e[0] = st->hTcxEnc->spectrum_e[1] = 0; - move16(); - move16(); - - set16_fx( st->hTcxEnc->old_out_fx, 0, L_FRAME32k ); - st->hTcxEnc->Q_old_out = 0; - move16(); - - /* MDCT selector */ - MDCT_selector_reset_fx( st->hTcxEnc ); - - /* MDCT classifier */ - MDCT_classifier_reset_fx( st->hTcxEnc ); - - IF( ( st->hTcxCfg = (TCX_CONFIG_HANDLE) malloc( sizeof( TCX_config ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n" ) ); - } - } - ELSE - { - st->hTcxEnc = NULL; - st->hTcxCfg = NULL; - } - - /*-----------------------------------------------------------------* - * HQ core parameters - *-----------------------------------------------------------------*/ - - test(); - test(); - IF( NE_16( st_fx->element_mode, IVAS_CPE_TD ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) && idchan == 0 ) - { - IF( ( st_fx->hHQ_core = (HQ_ENC_HANDLE) malloc( sizeof( HQ_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n" ) ); - } - - HQ_core_enc_init_fx( st_fx->hHQ_core ); - } - ELSE - { - st_fx->hHQ_core = NULL; - } - - st_fx->last_enerBuffer_exp = 0; - move16(); - - /* init memory for detect_transient(), used by HQ core and swb_bwe_enc */ - st->old_hpfilt_in_fx = 0; - move16(); - st->old_hpfilt_out_fx = 0; - move16(); - st->EnergyLT_fx = 0; - move32(); - st->Energy_Old_fx = 0; - move32(); - st->TransientHangOver = 0; - move16(); - st->EnergyLT_fx_exp = 30; - move16(); - st->last_enerBuffer_exp = 0; - move16(); - - /*-----------------------------------------------------------------* - * Channel-aware mode - *-----------------------------------------------------------------*/ - - test(); - test(); - test(); - IF( st_fx->Opt_RF_ON == 0 || ( NE_16( st_fx->bwidth, WB ) && NE_16( st_fx->bwidth, SWB ) ) || NE_32( st_fx->total_brate, ACELP_13k20 ) ) - { - IF( EQ_16( st_fx->Opt_RF_ON, 1 ) ) - { - printf( "\nWarning: Channel-aware mode only available for 13.2 kbps WB/SWB\n" ); - printf( " Switched to normal mode!\n" ); - st_fx->Opt_RF_ON = 0; - move16(); - st_fx->rf_fec_offset = 0; - move16(); - } - st_fx->rf_mode = 0; - move16(); - } - ELSE - { - st_fx->rf_mode = st_fx->Opt_RF_ON; - move16(); - } - st_fx->rf_mode_last = st_fx->rf_mode; - move16(); - /* initialize RF indice buffers */ - reset_rf_indices_fx( st_fx ); - - - /*-----------------------------------------------------------------* - * MODE2 initialization - *-----------------------------------------------------------------*/ - - st_fx->last_sr_core = i_mult2( st_fx->last_L_frame, 50 ); - move16(); - - /*-----------------------------------------------------------------* - * IGF - *-----------------------------------------------------------------*/ - - Word32 igf_brate = st->total_brate; - move32(); - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( EQ_16( st->element_mode, IVAS_SCE ) && ( EQ_16( st_ivas->hEncoderConfig->ivas_format, ISM_FORMAT ) || EQ_16( st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) ) - { - igf_brate = L_sub( st->total_brate, i_mult( ISM_NB_BITS_METADATA_NOMINAL, FRAMES_PER_SEC ) ); - } - ELSE IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || ( EQ_16( st->element_mode, IVAS_SCE ) && ( EQ_16( st_ivas->hEncoderConfig->ivas_format, SBA_FORMAT ) || - EQ_16( st_ivas->hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) || - EQ_16( st_ivas->hEncoderConfig->ivas_format, MC_FORMAT ) || - EQ_16( st_ivas->hEncoderConfig->ivas_format, MASA_FORMAT ) ) ) ) - { -#if 0 - /* use nominal bitrates for DFT Stereo and (O)SBA, same as in stereo_dft_config()/ivas_spar_config() */ - IF( EQ_32( element_brate, IVAS_13k2 ) ) - { - igf_brate = ACELP_9k60; - } - ELSE IF( EQ_32( element_brate, IVAS_16k4 ) ) - { - igf_brate = ACELP_13k20; - } - ELSE IF( EQ_32( element_brate, IVAS_24k4 ) ) - { - igf_brate = ACELP_16k40; - } - ELSE IF( EQ_32( element_brate, IVAS_32k ) ) - { - igf_brate = ACELP_24k40; - } -#endif - } - ELSE IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) - { - // igf_brate = element_brate; - } - - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) - { - st_fx->igf = getIgfPresent_fx( st_fx->element_mode, igf_brate, st_fx->bwidth, st_fx->rf_mode ); - } - ELSE - { - st_fx->igf = 0; - move16(); - } - - test(); - test(); - test(); - IF( ( idchan == 0 || EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) && ( st->igf || st->element_mode == EVS_MONO ) ) - { - IF( ( st->hIGFEnc = (IGF_ENC_INSTANCE_HANDLE) malloc( sizeof( IGF_ENC_INSTANCE ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hIGFEnc\n" ) ); - } - } - ELSE - { - st->hIGFEnc = NULL; - } - - /*-----------------------------------------------------------------* - * FD-CNG encoder - *-----------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - IF( ( idchan == 0 && st->Opt_DTX_ON ) || st->element_mode == EVS_MONO || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->Opt_DTX_ON ) ) - { - createFdCngEnc_fx( &st->hFdCngEnc ); - - initFdCngEnc_fx( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale ); - - /* initialization for IVAS modes happens in first frame pre-processing */ - IF( st->element_mode == EVS_MONO ) - { - Word32 total_brate; - - test(); - IF( st->rf_mode && EQ_32( st->total_brate, ACELP_13k20 ) ) - { - total_brate = ACELP_9k60; - move32(); - } - ELSE - { - total_brate = st->total_brate; - move32(); - } - - configureFdCngEnc_fx( st->hFdCngEnc, st->bwidth, total_brate ); - } - } - ELSE - { - st->hFdCngEnc = NULL; - } - - st_fx->last_totalNoise_fx = 0; - move16(); - set16_fx( st_fx->totalNoise_increase_hist_fx, 0, TOTALNOISE_HIST_SIZE ); - st_fx->totalNoise_increase_len = 0; - move16(); - st->prevEnergyHF_fx = 0; - move32(); - - IF( st->element_mode == EVS_MONO ) - { - init_coder_ace_plus_fx( st, st->last_total_brate, 0, -10 /*hack*/ ); - } - ELSE - { - /* Initialize Signal Buffers */ - Word16 shift = getScaleFactor16( st->old_inp_16k_fx, L_INP_MEM ); - Scale_sig( st->old_inp_16k_fx, L_INP_MEM, shift ); - st->exp_old_inp_16k = sub( st->exp_old_inp_16k, shift ); - move16(); - shift = getScaleFactor16( st->old_inp_12k8_fx, L_INP_MEM ); - Scale_sig( st->old_inp_12k8_fx, L_INP_MEM, shift ); - st->exp_old_inp_12k8 = sub( st->exp_old_inp_12k8, shift ); - move16(); - - init_coder_ace_plus_ivas_fx( st, st->last_total_brate, -1, 0 ); - } - - IF( ( st_fx->hTranDet = (TRAN_DET_HANDLE) malloc( sizeof( TRAN_DET_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Transient Detection\n" ) ); - } - - InitTransientDetection_fx( frame_length, NS2SA_FX2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ), st_fx->hTranDet ); - -#if 1 ////////////////////////////////////////////////////////////////////////////////////////////// - - - set32_fx( st_fx->mem_hp20_in_fx, 0, 5 ); - - /*-----------------------------------------------------------------* - * IVAS parameters - *-----------------------------------------------------------------*/ - - st_fx->Q_syn2 = 0; - move16(); - st_fx->Q_syn = 0; - move16(); - set16_fx( st_fx->Q_max, Q_MAX, L_Q_MEM ); - set16_fx( st_fx->Q_max_16k, Q_MAX, L_Q_MEM ); - st_fx->Q_old = 15; - move16(); - st_fx->old_wsp_max = 0; - move16(); - st_fx->old_wsp_shift = 0; - move16(); +/****************************************************************************************************** + + (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ +/*==================================================================================== + EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + ====================================================================================*/ - st_fx->tdm_LRTD_flag = 0; /* LRTD stereo mode flag */ - move16(); - st_fx->cna_dirac_flag = 0; /* CNA in DirAC flag */ - move16(); - st_fx->cng_sba_flag = 0; /* CNG in SBA flag */ - move16(); +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com.h" /* Static table prototypes */ +#include "stl.h" +#include "ivas_cnst.h" +#include "ivas_error.h" +#include "prot_fx.h" /* Function prototypes */ +#include "prot_fx_enc.h" /* Function prototypes */ +#include "ivas_prot_fx.h" -#endif ////////////////////////////////////////////////////////////////////////////////////////////// - return error; -} +/*-----------------------------------------------------------------------* + * init_encoder() + * + * Initialization of state variables + *-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------* * LPDmem_enc_init_fx() @@ -1214,7 +100,7 @@ void LPDmem_enc_init_fx( } -ivas_error init_encoder_ivas_fx( +ivas_error init_encoder_fx( Encoder_State *st, /* i/o: state structure */ Encoder_Struct *st_ivas, /* i/o: encoder state structure */ const Word16 idchan, /* i : channel ID */ @@ -1223,15 +109,12 @@ ivas_error init_encoder_ivas_fx( const Word32 element_brate /* i : element bitrate */ ) { - Word16 i, frame_length; + Word16 i, input_frame; ivas_error error; Word32 igf_brate; - error = IVAS_ERR_OK; - move32(); - - /* frame_length = st->input_Fs / FRAMES_PER_SEC */ - frame_length = extract_l( Mpy_32_32( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + /* input_frame = st->input_Fs / FRAMES_PER_SEC */ + input_frame = extract_l( Mpy_32_32( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); /*-----------------------------------------------------------------* * General parameters @@ -1604,15 +487,15 @@ ivas_error init_encoder_ivas_fx( IF( st->element_mode == EVS_MONO ) { - st->input32_fx = st->input_buff32_fx + add( frame_length, NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ) ); + st->input32_fx = st->input_buff32_fx + add( input_frame, NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ) ); st->input_fx = st->input_buff_fx + add( L_FRAME48k, NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); ///////////////////// input_Fs - st->old_input_signal_fx = st->input_fx - add( NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), frame_length ); + st->old_input_signal_fx = st->input_fx - add( NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), input_frame ); st->old_input_signal32_fx = st->input_buff32_fx; } ELSE { - st->input32_fx = st->input_buff32_fx + frame_length; - st->input_fx = st->input_buff_fx + frame_length; + st->input32_fx = st->input_buff32_fx + input_frame; + st->input_fx = st->input_buff_fx + input_frame; st->old_input_signal_fx = st->input_buff_fx; st->old_input_signal32_fx = st->input_buff32_fx; } @@ -2331,7 +1214,10 @@ ivas_error init_encoder_ivas_fx( test(); IF( ( idchan == 0 && st->Opt_DTX_ON ) || st->element_mode == EVS_MONO || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->Opt_DTX_ON ) ) { - createFdCngEnc_fx( &st->hFdCngEnc ); + IF( ( error = createFdCngEnc_fx( &st->hFdCngEnc ) ) != IVAS_ERR_OK ) + { + return error; + } initFdCngEnc_fx( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale ); @@ -2371,11 +1257,11 @@ ivas_error init_encoder_ivas_fx( IF( GT_16( st->element_mode, EVS_MONO ) ) { - InitTransientDetection_ivas_fx( frame_length, 0, st->hTranDet, 1 ); + InitTransientDetection_ivas_fx( input_frame, 0, st->hTranDet, 1 ); } ELSE { - InitTransientDetection_fx( frame_length, NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet ); + InitTransientDetection_fx( input_frame, NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet ); } /*-----------------------------------------------------------------* @@ -2409,7 +1295,7 @@ ivas_error init_encoder_ivas_fx( move16(); #endif - return error; + return IVAS_ERR_OK; } diff --git a/lib_enc/ivas_cpe_enc_fx.c b/lib_enc/ivas_cpe_enc_fx.c index 0d063f5af..239ec7823 100644 --- a/lib_enc/ivas_cpe_enc_fx.c +++ b/lib_enc/ivas_cpe_enc_fx.c @@ -1447,7 +1447,7 @@ ivas_error create_cpe_enc_fx( } st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; move16(); - IF( NE_32( ( error = init_encoder_ivas_fx( st, st_ivas, n, 0, ISM_MODE_NONE, hCPE->element_brate ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = init_encoder_fx( st, st_ivas, n, 0, ISM_MODE_NONE, hCPE->element_brate ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_enc/ivas_sce_enc_fx.c b/lib_enc/ivas_sce_enc_fx.c index 9424f7e9b..fa58f2674 100644 --- a/lib_enc/ivas_sce_enc_fx.c +++ b/lib_enc/ivas_sce_enc_fx.c @@ -474,19 +474,9 @@ ivas_error create_sce_enc_fx( st->max_bwidth = st_ivas->hEncoderConfig->max_bwidth; st->input_Fs = st_ivas->hEncoderConfig->input_Fs; - IF( st->element_mode == EVS_MONO ) + IF( NE_32( ( error = init_encoder_fx( st, st_ivas, 0, 0, st_ivas->ism_mode, hSCE->element_brate ) ), IVAS_ERR_OK ) ) { - IF( NE_32( ( error = init_encoder_fx( st, st_ivas ) ), IVAS_ERR_OK ) ) - { - return error; - } - } - ELSE - { - IF( NE_32( ( error = init_encoder_ivas_fx( st, st_ivas, 0, 0, st_ivas->ism_mode, hSCE->element_brate ) ), IVAS_ERR_OK ) ) - { - return error; - } + return error; } hSCE->hCoreCoder[0] = st; diff --git a/lib_enc/ivas_spar_encoder_fx.c b/lib_enc/ivas_spar_encoder_fx.c index 15643b702..89d152677 100644 --- a/lib_enc/ivas_spar_encoder_fx.c +++ b/lib_enc/ivas_spar_encoder_fx.c @@ -228,7 +228,7 @@ ivas_error ivas_spar_enc_open_fx( hSpar->hCoreCoderVAD->mct_chan_mode = MCT_CHAN_MODE_IGNORE; move32(); move32(); - IF( NE_32( ( error = init_encoder_ivas_fx( hSpar->hCoreCoderVAD, st_ivas, 0, 1, st_ivas->ism_mode, hSpar->hCoreCoderVAD->total_brate ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = init_encoder_fx( hSpar->hCoreCoderVAD, st_ivas, 0, 1, st_ivas->ism_mode, hSpar->hCoreCoderVAD->total_brate ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_enc/ivas_stereo_switching_enc_fx.c b/lib_enc/ivas_stereo_switching_enc_fx.c index b6690d8c7..abc0d056b 100644 --- a/lib_enc/ivas_stereo_switching_enc_fx.c +++ b/lib_enc/ivas_stereo_switching_enc_fx.c @@ -603,7 +603,10 @@ ivas_error stereo_memory_enc_fx( IF( st->hFdCngEnc == NULL ) { - createFdCngEnc_fx( &st->hFdCngEnc ); + IF( ( error = createFdCngEnc_fx( &st->hFdCngEnc ) ) != IVAS_ERR_OK ) + { + return error; + } initFdCngEnc_fx( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale ); configureFdCngEnc_ivas_fx( st->hFdCngEnc, st->bwidth, st->rf_mode && st->total_brate == ACELP_13k20 ? ACELP_9k60 : st->total_brate ); diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 27e508c1a..cc55961b1 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -4583,11 +4583,6 @@ void index_lvq_ivas_fx( Word16 *index, /* o : encoded index (represented on 3 short each with 15 bits ) */ const Word16 prediction_flag ); -ivas_error init_encoder_fx( - Encoder_State *st_fx, /* i/o: Encoder static variables structure */ - Encoder_Struct *st_ivas /* i/o: encoder state structure */ -); - void copy_encoder_config_fx( Encoder_Struct *st_ivas, /* i : IVAS encoder structure */ Encoder_State *st, /* o : encoder state structure */ diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 8b3d56e8e..d3cb56d79 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -1152,20 +1152,16 @@ typedef struct tcx_enc_structure Word16 transform_type[2]; /* TCX20/10/5 mode in each subframe */ /* Core Signal Analysis Outputs */ - Word16 noiseTiltFactor; /* compensation for LPC tilt in noise filling Q15 */ Word16 noiseLevelMemory_cnt; /* counter of consecutive low TCX noise levels */ Word16 ltpGainMemory_fx[N_LTP_GAIN_MEMS]; /* for smoothing noiseTransWidth Q15 */ STnsData tnsData[2]; - // Word16 fUseTns[2]; Word8 fUseTns[2]; Word16 bTnsOnWhithenedSpectra[2]; - // Word16 memQuantZeros[L_FRAME_PLUS]; /* Quantization deadzone flags */ Word8 memQuantZeros[L_FRAME_PLUS]; /* Quantization deadzone flags */ Word16 *speech_TCX; Word16 *new_speech_TCX; - // Word16 q_speech_TCX; Word16 tcxltp; Word16 tcxltp_pitch_int; @@ -1219,6 +1215,7 @@ typedef struct tcx_enc_structure Word16 spectrum_long_e; /* MDCT output for a long block. Points to spectrum */ Word16 q_spectrum_long_fx; Word16 spectrum_length; /* corresponds to L_frameTCX, used for scaling of MDCT/MDST buffers */ + } TCX_ENC_DATA, *TCX_ENC_HANDLE; @@ -1289,33 +1286,8 @@ typedef struct enc_core_structure char *force_dir; /* directory containing external binary files for modes/parameters enforcement (empty string indicates no enforcement) */ #endif #endif - Word16 nTimeSlots; /* for CLDFB */ - Word16 ini_frame; /* initialization frames counter */ - // Word32 input_Fs_fx; /* input signal sampling frequency in Hz */ - // Word32 total_brate_fx; /* total bitrate in kbps of the codec */ - // Word32 last_total_brate_fx; /* total bitrate in kbps of the codec */ - // Word32 last_total_brate_cng_fx; /* total bitrate in kbps of the last inactive frame */ - // Word16 core_fx; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */ - // Word32 core_brate_fx; /* core bitrate */ - // Word32 last_core_brate_fx; /* previous frame core bitrate */ - // Word16 extl_fx; /* extension layer */ - // Word16 last_extl_fx; /* previous extension layer */ - // Word32 extl_brate_fx; /* extension layer bitrate */ - // Word16 input_bwidth_fx; /* input signal bandwidth */ - // Word16 last_input_bwidth_fx; /* input signal bandwidth in the previous frame */ - // Word16 bwidth_fx; /* encoded bandwidth NB, WB, SWB or FB */ - // Word16 max_bwidth_fx; /* maximum encoded bandwidth */ - // Word16 last_bwidth_fx; /* input signal bandwidth in the previous frame */ - // Word16 last_bwidth_cng_fx; /* input signal bandwidth in the previous inactive frame */ - // Word16 L_frame_fx; /* ACELP core internal frame length */ - // Word16 Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ - // Word16 Opt_DTX_ON_fx; /* flag indicating DTX operation */ - // Word16 cng_type; /* flag indicating LP or CLDFB based SID/CNG */ - // Word16 Opt_SC_VBR_fx; /* flag indicating SC-VBR mode */ - // Word16 last_Opt_SC_VBR_fx; /* flag indicating SC-VBR mode in the last frame */ - /*----------------------------------------------------------------------------------* * ACELP core parameters *----------------------------------------------------------------------------------*/ @@ -1326,27 +1298,25 @@ typedef struct enc_core_structure Word16 fmerit_dt; /* signal classification score difference Q15 */ Word16 Nb_ACELP_frames; - Word16 pitch[3]; /* open-loop pitch values @12.8 kHz for three half-frames */ - // Word16 pitch_fx[3]; + Word16 pitch[3]; /* open-loop pitch values @12.8 kHz for three half-frames */ Word16 voicing_fx[3]; /* open-loop normalized correlation values for three half-frames Q15 */ LPD_state_HANDLE hLPDmem; /* ACELP LPDmem memories */ - Word32 Bin_E_fx[L_FFT]; /* Q_new + Q_SCALE -2 per bin energy of two frames */ - Word16 q_Bin_E; /* Q_new + Q_SCALE -2 per bin energy of two frames */ - Word16 lsp_old1_fx[M]; /* old unquantized LSP vector at the end of the frame Q15 */ - Word16 lsf_old1_fx[M]; /* old LSF vector at the end of the frame Qlog2(2.56) */ - Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame Q15 */ - Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame Qlog2(2.56) */ - Word16 lsp_old16k_fx[M]; /* old LSP vector at the end of the frame @16kHz Q15 */ - Word16 lspold_enc_fx[M]; /* old LSP vector at the end of the frame @16kHz Q15 */ - Word16 pstreaklen; /* LSF quantizer */ - Word16 streaklimit_fx; /* LSF quantizer Q15 */ - Word16 stab_fac_fx; /* LSF stability factor Q15 */ - Word16 clip_var_fx[6]; /* pitch gain clipping memory [2.56x,Q14,Q8,Q0,Q14,Q14] */ - Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) Qlog2(2.56) */ - Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) Qlog2(2.56) */ - // Word16 pstreaklen_fx; /* LSF quantizer */ + Word32 Bin_E_fx[L_FFT]; /* Q_new + Q_SCALE -2 per bin energy of two frames */ + Word16 q_Bin_E; /* Q_new + Q_SCALE -2 per bin energy of two frames */ + Word16 lsp_old1_fx[M]; /* old unquantized LSP vector at the end of the frame Q15 */ + Word16 lsf_old1_fx[M]; /* old LSF vector at the end of the frame Qlog2(2.56) */ + Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame Q15 */ + Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame Qlog2(2.56) */ + Word16 lsp_old16k_fx[M]; /* old LSP vector at the end of the frame @16kHz Q15 */ + Word16 lspold_enc_fx[M]; /* old LSP vector at the end of the frame @16kHz Q15 */ + Word16 pstreaklen; /* LSF quantizer */ + Word16 streaklimit_fx; /* LSF quantizer Q15 */ + Word16 stab_fac_fx; /* LSF stability factor Q15 */ + Word16 clip_var_fx[6]; /* pitch gain clipping memory [2.56x,Q14,Q8,Q0,Q14,Q14] */ + Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) Qlog2(2.56) */ + Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) Qlog2(2.56) */ Word32 offset_scale1_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 1st 8-dim subvector*/ Word32 offset_scale2_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 2nd 8-dim subvector*/ Word32 offset_scale1_p_fx[MAX_NO_MODES_p + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure, pred. case, 1st 8-dim subvector*/ @@ -1362,7 +1332,6 @@ typedef struct enc_core_structure Word16 old_wsp_fx[L_WSP_MEM]; /* old weighted signal vector */ Word16 exp_old_wsp; Word16 Q_old_wsp2; - /*Word16 old_exc_fx[L_EXC_MEM];*/ /* old excitation vector */ Word16 old_wsp2_fx[( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM]; /* old decimated weighted signal vector qwsp */ Word16 mem_wsp_fx; /* weighted signal vector memory */ Word16 mem_wsp_q; @@ -1379,7 +1348,6 @@ typedef struct enc_core_structure Word16 lsfoldbfi1_fx[M]; /* FEC - LSF vector of the past previous frame Qlog2(2.56) */ Word16 lsf_adaptive_mean_fx[M]; /* FEC - adaptive mean LSF vector for FEC Qlog2(2.56) */ Word16 next_force_safety_net; /* FEC - flag to force safety net in next frame */ - // Word16 next_force_safety_net_fx; /* FEC - flag to force safety net in next frame */ Word16 uv_count; /* Stationary noise UV modification - unvoiced counter */ Word16 act_count; /* Stationary noise UV modification - activation counter */ @@ -1475,6 +1443,8 @@ typedef struct enc_core_structure Word16 exp_buf_wspeech_enc; Word16 exp_buf_synth; + Word16 lgBin_E_fx[L_FFT / 2]; /* Q8 per bin energy of two frames */ + /*----------------------------------------------------------------------------------* * Noise estimation *----------------------------------------------------------------------------------*/ @@ -1487,8 +1457,6 @@ typedef struct enc_core_structure SP_MUS_CLAS_HANDLE hSpMusClas; - Word16 lgBin_E_fx[L_FFT / 2]; /* Q8 per bin energy of two frames */ - Word16 sp_aud_decision0; /* 1st stage speech/music decision flag */ Word16 sp_aud_decision1; /* 1st stage speech/music classification flag */ Word16 sp_aud_decision2; /* 2nd stage speech/music classification flag */ @@ -1527,9 +1495,6 @@ typedef struct enc_core_structure HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc; /* main analysis filter bank handle */ HANDLE_CLDFB_FILTER_BANK cldfbSynTd; /* synthesis filterbank - used for HB signal generation */ - // HANDLE_CLDFB_FILTER_BANK cldfbAna_Fx; - - // HANDLE_CLDFB_FILTER_BANK cldfbSyn_Fx; /*----------------------------------------------------------------------------------* * FD CNG handle @@ -1560,7 +1525,6 @@ typedef struct enc_core_structure HQ_ENC_HANDLE hHQ_core; /* HQ core encoder handle */ - PVQ_ENC_HANDLE hPVQ; /*----------------------------------------------------------------------------------* * TD BWE parameters *----------------------------------------------------------------------------------*/ @@ -1682,7 +1646,6 @@ typedef struct enc_core_structure Word16 encoderLookahead_FB; /* pitch_ol for adaptive lag window */ - Word16 old_pitch_la; /* past open loop pitch lag from look-ahead before very short stable pitch detection */ Word16 old_voicing_la; /* past open loop pitch gain from look-ahead */ -- GitLab From d3015a847ccca5f3e24b324998812431d51d2fd0 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 10 Sep 2025 17:37:46 +0200 Subject: [PATCH 09/15] revision of core-coder struct members: remove obsolete ones, merge duplicates (hTranDet, hp20 memory), move TD BWE ones under the related sub-struct --- lib_enc/acelp_core_enc_fx.c | 4 +- lib_enc/amr_wb_enc_fx.c | 11 +- lib_enc/core_enc_ol_fx.c | 6 +- lib_enc/core_enc_switch_fx.c | 4 +- lib_enc/core_switching_enc_fx.c | 11 +- lib_enc/evs_enc_fx.c | 2 +- lib_enc/ext_sig_ana_fx.c | 4 +- lib_enc/gs_enc_fx.c | 2 +- lib_enc/igf_enc_fx.c | 2 +- lib_enc/init_enc_fx.c | 99 ++++---------- lib_enc/ivas_cpe_enc_fx.c | 2 +- lib_enc/ivas_init_enc_fx.c | 3 +- lib_enc/ivas_ism_enc_fx.c | 2 +- lib_enc/ivas_sce_enc_fx.c | 6 +- lib_enc/ivas_stereo_switching_enc_fx.c | 6 +- lib_enc/ivas_stereo_td_enc_fx.c | 4 +- lib_enc/lib_enc_fx.c | 6 +- lib_enc/mdct_selector_fx.c | 4 +- lib_enc/pre_proc_fx.c | 8 +- lib_enc/prot_fx_enc.h | 133 ++++++++++-------- lib_enc/stat_enc.h | 132 +++++------------- lib_enc/swb_tbe_enc_fx.c | 178 +++++++++++-------------- lib_enc/tcx_ltp_enc_fx.c | 73 +++++----- lib_enc/transient_detection_fx.c | 128 +++++++++++------- 24 files changed, 364 insertions(+), 466 deletions(-) diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c index eec55c1c7..0b3d95a7c 100644 --- a/lib_enc/acelp_core_enc_fx.c +++ b/lib_enc/acelp_core_enc_fx.c @@ -1509,9 +1509,9 @@ ivas_error acelp_core_enc_ivas_fx( IF( !st->Opt_SC_VBR && ( st->idchan == 0 || NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) ) { /* Apply a non linearity to the SHB excitation */ - Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( sub( shl( Q_new, 1 ), sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc + Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( sub( shl( Q_new, 1 ), sub( st->hBWE_TD->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc non_linearity_ivas_fx( bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, Q_new, st->coder_type, voice_factors_fx, st->L_frame ); - Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, negate( sub( shl( Q_new, 1 ), sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc + Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, negate( sub( shl( Q_new, 1 ), sub( st->hBWE_TD->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc } test(); diff --git a/lib_enc/amr_wb_enc_fx.c b/lib_enc/amr_wb_enc_fx.c index 1580a7818..25364e865 100644 --- a/lib_enc/amr_wb_enc_fx.c +++ b/lib_enc/amr_wb_enc_fx.c @@ -24,9 +24,10 @@ *--------------------------------------------------------------------*/ void amr_wb_enc_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 input_sp[], /* i : input signal Q0*/ - const Word16 n_samples /* i : number of input samples Q0*/ + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 input_sp[], /* i : input signal Q0*/ + Word32 *mem_hp20_in_fx, /* i/o: hp20 filter memory Qx*/ + const Word16 n_samples /* i : number of input samples Q0*/ ) { Word16 i, delay; @@ -109,7 +110,7 @@ void amr_wb_enc_fx( move16(); st->coder_type = GENERIC; move16(); - input_frame = st->input_frame_fx; + input_frame = extract_l( Mult_32_16( st->input_Fs, 0x0290 ) ); move16(); /* frame length of the input signal */ st->extl = -1; move16(); @@ -183,7 +184,7 @@ void amr_wb_enc_fx( st->input_fx[i] = 0; move16(); } - hp20( st->input_fx, 1, input_frame, st->mem_hp20_in_fx, st->input_Fs ); + hp20( st->input_fx, 1, input_frame, mem_hp20_in_fx, st->input_Fs ); /*-----------------------------------------------------------------* * switching from ACELP@16k core to AMR-WB IO mode diff --git a/lib_enc/core_enc_ol_fx.c b/lib_enc/core_enc_ol_fx.c index 020af121c..7313a9db7 100644 --- a/lib_enc/core_enc_ol_fx.c +++ b/lib_enc/core_enc_ol_fx.c @@ -256,7 +256,7 @@ void core_encode_openloop_fx( /* reset TBE buffers previous frame frame wasn't ACELP*/ IF( st->last_core != ACELP_CORE ) { - TBEreset_enc_fx( st, st->bwidth ); + TBEreset_enc_fx( st->hBWE_TD, st->last_core, st->bwidth ); } @@ -700,7 +700,7 @@ void core_encode_openloop_fx( test(); test(); IF( rf_PLC_Mode == 0 && hRF->rf_gain_tcx[1] != 0 && - ( ( st->transientDetection.transientDetector.bIsAttackPresent != 0 && LT_16( hRF->rf_gain_tcx[0], mult_r( hRF->rf_gain_tcx[1], 31785 /*0.97f Q15*/ ) ) ) || + ( ( st->hTranDet->transientDetector.bIsAttackPresent != 0 && LT_16( hRF->rf_gain_tcx[0], mult_r( hRF->rf_gain_tcx[1], 31785 /*0.97f Q15*/ ) ) ) || LT_16( hRF->rf_gain_tcx[0], mult_r( hRF->rf_gain_tcx[1], 29491 /*0.90f Q15*/ ) ) ) ) { TD_mode = 0; @@ -900,7 +900,7 @@ void core_acelp_tcx20_switching_fx( st->pit_fr2, st->pit_max, st->pit_res_max, - &st->transientDetection, + st->hTranDet, 0, A_q_tcx, M ); diff --git a/lib_enc/core_enc_switch_fx.c b/lib_enc/core_enc_switch_fx.c index fb5fd037a..8dafd3b04 100644 --- a/lib_enc/core_enc_switch_fx.c +++ b/lib_enc/core_enc_switch_fx.c @@ -173,7 +173,7 @@ void core_coder_mode_switch_fx( ( EQ_16( st->bwidth, FB ) && NE_16( st->last_extl, FB_TBE ) ) ) { /* reset TBE buffers as previous frame wasn't using TBE */ - TBEreset_enc_fx( st, st->bwidth ); + TBEreset_enc_fx( st->hBWE_TD, st->last_core, st->bwidth ); } ELSE { @@ -418,7 +418,7 @@ void core_coder_mode_switch_ivas_fx( ( EQ_16( st->bwidth, SWB ) && NE_16( st->last_extl, SWB_TBE ) ) || ( EQ_16( st->bwidth, FB ) && NE_16( st->last_extl, FB_TBE ) ) ) { - TBEreset_enc_fx( st, st->bwidth ); + TBEreset_enc_fx( st->hBWE_TD, st->last_core, st->bwidth ); } ELSE { diff --git a/lib_enc/core_switching_enc_fx.c b/lib_enc/core_switching_enc_fx.c index 5b657e9c5..e0878969c 100644 --- a/lib_enc/core_switching_enc_fx.c +++ b/lib_enc/core_switching_enc_fx.c @@ -45,8 +45,6 @@ void core_switching_pre_enc_fx( { IF( hLPDmem != NULL ) { - st_fx->mem_deemph_fx = hLPDmem->syn[M]; - move16(); Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn1_fx, M ); /*hLPDmem->q_mem_syn*/ } @@ -200,7 +198,6 @@ void core_switching_pre_enc_fx( lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, INT_FS_FX ); } - st_fx->mem_deemph_fx = 0; /* Reset ACELP parameters */ IF( hLPDmem != NULL ) { @@ -485,7 +482,7 @@ void core_switching_post_enc_fx( } ELSE IF( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) { - TBEreset_enc_fx( st_fx, st_fx->bwidth ); + TBEreset_enc_fx( st_fx->hBWE_TD, st_fx->last_core, st_fx->bwidth ); } test(); test(); @@ -660,8 +657,6 @@ void core_switching_pre_enc_ivas_fx( { IF( hLPDmem != NULL ) { - st_fx->mem_deemph_fx = hLPDmem->syn[M]; - move16(); Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn1_fx, M ); } @@ -818,8 +813,6 @@ void core_switching_pre_enc_ivas_fx( lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, INT_FS_FX ); } - st_fx->mem_deemph_fx = 0; - move16(); /* Reset ACELP parameters */ IF( hLPDmem != NULL ) { @@ -1159,7 +1152,7 @@ void core_switching_post_enc_ivas_fx( } ELSE IF( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) { - TBEreset_enc_fx( st, st->bwidth ); + TBEreset_enc_fx( st->hBWE_TD, st->last_core, st->bwidth ); } test(); diff --git a/lib_enc/evs_enc_fx.c b/lib_enc/evs_enc_fx.c index 8e9a82378..90d5a7b4b 100644 --- a/lib_enc/evs_enc_fx.c +++ b/lib_enc/evs_enc_fx.c @@ -100,7 +100,7 @@ ivas_error evs_enc_fx( * Initializiation *-----------------------------------------------------------------*/ - input_frame = st->input_frame_fx; + input_frame = extract_l( Mult_32_16( st->input_Fs, 0x0290 ) ); move16(); st->core = -1; move16(); diff --git a/lib_enc/ext_sig_ana_fx.c b/lib_enc/ext_sig_ana_fx.c index 87fa6a451..42f6dc487 100644 --- a/lib_enc/ext_sig_ana_fx.c +++ b/lib_enc/ext_sig_ana_fx.c @@ -118,7 +118,7 @@ void core_signal_analysis_high_bitrate_fx( &hTcxEnc->tcxltp_pitch_int, &hTcxEnc->tcxltp_pitch_fr, &hTcxEnc->tcxltp_gain, &hTcxEnc->tcxltp_pitch_int_past, &hTcxEnc->tcxltp_pitch_fr_past, &hTcxEnc->tcxltp_gain_past, &hTcxEnc->tcxltp_norm_corr_past, st->last_core, st->pit_min, st->pit_fr1, - st->pit_fr2, st->pit_max, st->pit_res_max, &st->transientDetection, + st->pit_fr2, st->pit_max, st->pit_res_max, st->hTranDet, tmp8, NULL, M ); } ELSE @@ -130,7 +130,7 @@ void core_signal_analysis_high_bitrate_fx( &hTcxEnc->tcxltp_pitch_int, &hTcxEnc->tcxltp_pitch_fr, &hTcxEnc->tcxltp_gain, &hTcxEnc->tcxltp_pitch_int_past, &hTcxEnc->tcxltp_pitch_fr_past, &hTcxEnc->tcxltp_gain_past, &hTcxEnc->tcxltp_norm_corr_past, st->last_core, st->pit_min, st->pit_fr1, - st->pit_fr2, st->pit_max, st->pit_res_max, &st->transientDetection, + st->pit_fr2, st->pit_max, st->pit_res_max, st->hTranDet, tmp8, NULL, M ); } diff --git a/lib_enc/gs_enc_fx.c b/lib_enc/gs_enc_fx.c index c666840df..30e4385bf 100644 --- a/lib_enc/gs_enc_fx.c +++ b/lib_enc/gs_enc_fx.c @@ -1000,7 +1000,7 @@ void gsc_enc_fx( highband_exc_dct_in_fx( st_fx->core_brate, mfreq_bindiv_loc, last_bin, Diff_len, hGSCEnc->noise_lev, tmp_band, exc_diffQ, &hGSCEnc->seed_tcx, Ener_per_bd_iQ, nb_subfr, exc_dct_in, st_fx->last_coder_type, bitallocation_band, lsf_new, - hGSCEnc->last_exc_dct_in_fx, &st_fx->last_ener_fx, hGSCEnc->last_bitallocation_band, bitallocation_exc, 0, st_fx->coder_type, + hGSCEnc->last_exc_dct_in_fx, &hGSCEnc->last_ener_fx, hGSCEnc->last_bitallocation_band, bitallocation_exc, 0, st_fx->coder_type, st_fx->bwidth, exc_wo_nf, Q_PVQ_OUT, Q_exc, st_fx->GSC_noisy_speech, NULL, st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); exc_dct_in[0] = 0; diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index b6a1c66c2..7481c4c86 100755 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -1802,7 +1802,7 @@ void IGFEncApplyMono_fx( const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in pPowerSpectrumParameterWhitening, /* i: MDCT^2 + MDST^2 spectrum, or estimate */ PowerSpectrum_e, /* i: exponent of powerSpectrum */ igfGridIdx, /* i: IGF grid index */ - ( st->transientDetection.transientDetector.bIsAttackPresent == 1 ), + ( st->hTranDet->transientDetector.bIsAttackPresent == 1 ), last_core_acelp ); /* i: last frame was acelp indicator */ pPowerSpectrumParameter = NULL; diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index 0ee479a7c..6d11af682 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -27,7 +27,7 @@ ivas_error init_encoder_fx( const int16_t interval_SID /* i : interval for SID update */ ) { - Word16 i; + Word16 i, input_frame; Word32 L_tmp; @@ -40,6 +40,8 @@ ivas_error init_encoder_fx( error = IVAS_ERR_OK; + input_frame = extract_l( Mult_32_16( st_fx->input_Fs, 0x0290 ) ); + /*-----------------------------------------------------------------* * General signal buffers *-----------------------------------------------------------------*/ @@ -183,8 +185,6 @@ ivas_error init_encoder_fx( move16(); set16_fx( st_fx->old_wsp2_fx, 0, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); set16_fx( st_fx->old_wsp_fx, 0, L_WSP_MEM ); - st_fx->mem_deemph_fx = 0; - move16(); st_fx->mem_preemph_fx = 0; move16(); st_fx->mem_preemph16k_fx = 0; @@ -230,7 +230,6 @@ ivas_error init_encoder_fx( move16(); st_fx->old_voicing_la = 0; move16(); - set32_fx( st_fx->mem_hp20_in_fx, 0, 5 ); st_fx->old_hpfilt_in_fx = 0; move16(); @@ -309,9 +308,6 @@ ivas_error init_encoder_fx( st_fx->hGSCEnc = NULL; } - st_fx->last_ener_fx = 0; - move16(); - st_fx->old_dE1_fx = 0; move16(); st_fx->old_ind_deltaMax = 0; @@ -576,7 +572,7 @@ ivas_error init_encoder_fx( *-----------------------------------------------------------------*/ /* open analysis for input SR */ - if ( ( error = openCldfb( &st_fx->cldfbAnaEnc, CLDFB_ANALYSIS, CLDFB_getNumChannels( st_fx->input_Fs ), st_fx->input_frame_fx ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb( &st_fx->cldfbAnaEnc, CLDFB_ANALYSIS, CLDFB_getNumChannels( st_fx->input_Fs ), input_frame ) ) != IVAS_ERR_OK ) { return error; } @@ -688,8 +684,8 @@ ivas_error init_encoder_fx( // return error; // } - InitSWBencBuffer_fx( st_fx /*st_fx->hBWE_TD*/ ); - ResetSHBbuffer_Enc_fx( st_fx /*st_fx->hBWE_TD*/ ); + InitSWBencBuffer_fx( st_fx->hBWE_TD ); + ResetSHBbuffer_Enc_fx( st_fx->hBWE_TD ); } ELSE { @@ -720,7 +716,7 @@ ivas_error init_encoder_fx( st_fx->input_fx = st_fx->input_buff_fx + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ); set16_fx( st_fx->input_buff_fx + L_FRAME48k, 0, L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); - st_fx->old_input_signal_fx = st_fx->input_fx - add( NS2SA_FX2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ), st_fx->input_frame_fx ); + st_fx->old_input_signal_fx = st_fx->input_fx - add( NS2SA_FX2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ), input_frame ); st_fx->Energy_Old_fx = 0; @@ -882,10 +878,15 @@ ivas_error init_encoder_fx( st_fx->totalNoise_increase_len = 0; move16(); init_coder_ace_plus_fx( st_fx, st_fx->last_total_brate, 0, -10 /*hack*/ ); - // PMT("Transient detector init needs review, handle hTranDet is missing") + + IF( ( st_fx->hTranDet = (TRAN_DET_HANDLE) malloc( sizeof( TRAN_DET_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Transient Detection\n" ) ); + } + InitTransientDetection_fx( extract_l( Mult_32_16( st_fx->input_Fs, 0x0290 ) ), NS2SA_FX2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ), - &st_fx->transientDetection ); + st_fx->hTranDet ); st_fx->Q_syn2 = 0; move16(); @@ -904,40 +905,30 @@ ivas_error init_encoder_fx( st_fx->tdm_LRTD_flag = 0; /* LRTD stereo mode flag */ move16(); - st_fx->cna_dirac_flag = 0; /* CNA in DirAC flag */ - move16(); st_fx->cng_sba_flag = 0; /* CNG in SBA flag */ move16(); st_fx->GSC_IVAS_mode = 0; /* CNG in SBA flag */ move16(); st_fx->element_mode = EVS_MONO; /* element mode */ move16(); - st_fx->last_element_mode = st_fx->element_mode; /* element mode */ - move16(); st_fx->element_brate = -1; /* element bitrate */ move32(); - // PMT("element_mode and element_brate should be initialized at a proper place in ivas_dec_init eventually") st_fx->low_rate_mode = 0; /* low-rate mode flag */ move16(); // st_fx->coder_type = GENERIC; /* low-rate mode flag */ set16_fx( st_fx->pitch, L_SUBFR, 3 ); set16_fx( st_fx->voicing_fx, 0, 3 ); - - #ifdef DEBUGGING st_fx->id_element = -1; /* element ID */ move16(); #endif - st_fx->extl_orig = -1; /* extension layer */ - move16(); - st_fx->extl_brate_orig = 0; /* extension layer bitrate */ - move32(); + return error; } /*-----------------------------------------------------------------------* - * LPDmem_enc_init_fx() + * LPDmem_enc_init() * * Initialization of ACELP LPDmem state variables *-----------------------------------------------------------------------*/ @@ -956,44 +947,13 @@ void LPDmem_enc_init_fx( set16_fx( hLPDmem->mem_syn_r, 0, L_SYN_MEM ); set16_fx( hLPDmem->mem_syn3, 0, M ); - hLPDmem->mem_w0 = 0; - move16(); - hLPDmem->tilt_code = 0; - move16(); - hLPDmem->gc_threshold = 0; - move32(); - hLPDmem->dm_fx.prev_state = 0; - move16(); /* This corresponds to st_fx->dispMem in FLP */ - hLPDmem->dm_fx.prev_gain_code = 0; - move32(); - - FOR( i = 2; i < 8; i++ ) - { - hLPDmem->dm_fx.prev_gain_pit[i - 2] = 0; - move16(); - } - return; -} - -void LPDmem_enc_init_ivas_fx( - LPD_state_HANDLE hLPDmem /* i/o: LP memories */ -) -{ - Word16 i; - - set16_fx( hLPDmem->syn, 0, 1 + M ); - set16_fx( hLPDmem->old_exc, 0, L_EXC_MEM ); - set16_fx( hLPDmem->mem_syn, 0, M ); - set16_fx( hLPDmem->mem_syn1_fx, 0, M ); - set16_fx( hLPDmem->mem_syn2, 0, M ); - set16_fx( hLPDmem->mem_syn_r, 0, L_SYN_MEM ); - set16_fx( hLPDmem->mem_syn3, 0, M ); hLPDmem->q_lpd_old_exc = Q15; move16(); hLPDmem->q_lpd_syn = Q15; move16(); hLPDmem->q_mem_syn = Q15; move16(); + hLPDmem->mem_w0 = 0; move16(); hLPDmem->tilt_code = 0; @@ -1043,13 +1003,15 @@ ivas_error init_encoder_ivas_fx( const Word32 element_brate /* i : element bitrate */ ) { - Word16 i; + Word16 i, input_frame; ivas_error error; Word32 igf_brate; error = IVAS_ERR_OK; move32(); + input_frame = extract_l( Mult_32_16( st->input_Fs, 0x0290 ) ); + /*-----------------------------------------------------------------* * General parameters *-----------------------------------------------------------------*/ @@ -1666,9 +1628,7 @@ ivas_error init_encoder_ivas_fx( IF( EQ_16( st->element_mode, EVS_MONO ) ) { /* open analysis for input SR */ - st->input_frame_fx = extract_l( Mult_32_16( st->input_Fs, 0x0290 ) ); - - if ( ( error = openCldfb( &st->cldfbAnaEnc, CLDFB_ANALYSIS, CLDFB_getNumChannels( st->input_Fs ), st->input_frame_fx ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb( &st->cldfbAnaEnc, CLDFB_ANALYSIS, CLDFB_getNumChannels( st->input_Fs ), input_frame ) ) != IVAS_ERR_OK ) { return error; } @@ -1747,7 +1707,7 @@ ivas_error init_encoder_ivas_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LPDmem\n" ) ); } - LPDmem_enc_init_ivas_fx( st->hLPDmem ); + LPDmem_enc_init_fx( st->hLPDmem ); } ELSE { @@ -1805,8 +1765,8 @@ ivas_error init_encoder_ivas_fx( return error; } } - InitSWBencBuffer_ivas_fx( st ); - ResetSHBbuffer_Enc_fx( st ); + InitSWBencBuffer_ivas_fx( st->hBWE_TD ); + ResetSHBbuffer_Enc_fx( st->hBWE_TD ); } ELSE { @@ -2144,19 +2104,14 @@ ivas_error init_encoder_ivas_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Transient Detection\n" ) ); } - Word16 temp; - Word16 frame_length = BASOP_Util_Divide3232_Scale( st->input_Fs, FRAMES_PER_SEC, &temp ); - frame_length = shr( frame_length, sub( 15, temp ) ); IF( GT_16( st->element_mode, EVS_MONO ) ) { - InitTransientDetection_ivas_fx( frame_length, 0, st->hTranDet, 1 ); + InitTransientDetection_ivas_fx( input_frame, 0, st->hTranDet, 1 ); } ELSE { - InitTransientDetection_fx( extract_l( Mult_32_16( st->input_Fs, 0x0290 ) ), - NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), - &st->transientDetection ); + InitTransientDetection_fx( input_frame, NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet ); } /*-----------------------------------------------------------------* @@ -2183,8 +2138,6 @@ ivas_error init_encoder_ivas_fx( move16(); st->old_wsp_shift = 0; move16(); - st->sharpFlag = 0; - move16(); return error; } diff --git a/lib_enc/ivas_cpe_enc_fx.c b/lib_enc/ivas_cpe_enc_fx.c index c9c54c2c6..b73702d21 100644 --- a/lib_enc/ivas_cpe_enc_fx.c +++ b/lib_enc/ivas_cpe_enc_fx.c @@ -493,7 +493,7 @@ ivas_error ivas_cpe_enc_fx( RunTransientDetection_ivas_fx( sts[n]->input_fx, input_frame, sts[n]->hTranDet, sts[n]->q_inp ); // Note q of sts[n]->input_fx changes inside function } - currFlatness_fx[n] = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( (const TransientDetection *) sts[n]->hTranDet, NSUBBLOCKS, 0 ); // Q21 + currFlatness_fx[n] = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( sts[n]->hTranDet, NSUBBLOCKS, 0 ); // Q21 move32(); } diff --git a/lib_enc/ivas_init_enc_fx.c b/lib_enc/ivas_init_enc_fx.c index 5a3592ad2..f4e88f41c 100644 --- a/lib_enc/ivas_init_enc_fx.c +++ b/lib_enc/ivas_init_enc_fx.c @@ -1244,8 +1244,7 @@ void destroy_evs_core_enc_fx( IF( hCoreCoder->hVAD_CLDFB != NULL ) { - /* This is not required as we are not allocating memory dynamically */ - // free( hCoreCoder->hVAD_CLDFB ); + free( hCoreCoder->hVAD_CLDFB ); hCoreCoder->hVAD_CLDFB = NULL; } diff --git a/lib_enc/ivas_ism_enc_fx.c b/lib_enc/ivas_ism_enc_fx.c index dc41c784d..6b75a6be7 100644 --- a/lib_enc/ivas_ism_enc_fx.c +++ b/lib_enc/ivas_ism_enc_fx.c @@ -217,7 +217,7 @@ ivas_error ivas_ism_enc_fx( RunTransientDetection_ivas_fx( st->input_fx, input_frame, st->hTranDet, st->q_inp ); - currFlatness_fx[0] = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS, 0 ); // Q21 + currFlatness_fx[0] = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( st->hTranDet, NSUBBLOCKS, 0 ); // Q21 move16(); /*----------------------------------------------------------------* diff --git a/lib_enc/ivas_sce_enc_fx.c b/lib_enc/ivas_sce_enc_fx.c index 180e175ec..841f4bea2 100644 --- a/lib_enc/ivas_sce_enc_fx.c +++ b/lib_enc/ivas_sce_enc_fx.c @@ -184,7 +184,7 @@ ivas_error ivas_sce_enc_fx( RunTransientDetection_ivas_fx( st->input_fx, input_frame, st->hTranDet, q_input ); } - currFlatness_fx[0] = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS, 0 ); // Q21 + currFlatness_fx[0] = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( st->hTranDet, NSUBBLOCKS, 0 ); // Q21 move32(); /*----------------------------------------------------------------* @@ -472,7 +472,6 @@ ivas_error create_sce_enc_fx( move32(); st->max_bwidth = st_ivas->hEncoderConfig->max_bwidth; st->input_Fs = st_ivas->hEncoderConfig->input_Fs; - st->input_frame_fx = extract_l( Mult_32_16( st->input_Fs, 0x0290 ) ); 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 ) ) { @@ -556,9 +555,6 @@ ivas_error create_evs_sce_enc_fx( st_fx->total_brate = st_ivas->hEncoderConfig->ivas_total_brate; move32(); - st_fx->input_frame_fx = extract_l( Mult_32_16( st_fx->input_Fs, 0x0290 ) ); - move16(); - IF( NE_32( ( error = init_encoder_fx( st_fx, st_ivas->hEncoderConfig->var_SID_rate_flag, st_ivas->hEncoderConfig->interval_SID ) ), IVAS_ERR_OK ) ) { return error; diff --git a/lib_enc/ivas_stereo_switching_enc_fx.c b/lib_enc/ivas_stereo_switching_enc_fx.c index 469bf211a..9e1649eb2 100644 --- a/lib_enc/ivas_stereo_switching_enc_fx.c +++ b/lib_enc/ivas_stereo_switching_enc_fx.c @@ -58,7 +58,7 @@ static ivas_error allocate_CoreCoder_enc_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LPDmem\n" ) ); } - LPDmem_enc_init_ivas_fx( st->hLPDmem ); + LPDmem_enc_init_fx( st->hLPDmem ); } IF( st->hGSCEnc == NULL && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) @@ -435,8 +435,8 @@ ivas_error stereo_memory_enc_fx( } } - InitSWBencBuffer_ivas_fx( st ); - ResetSHBbuffer_Enc_fx( st ); + InitSWBencBuffer_ivas_fx( st->hBWE_TD ); + ResetSHBbuffer_Enc_fx( st->hBWE_TD ); IF( ( st->hBWE_FD = (FD_BWE_ENC_HANDLE) malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) { diff --git a/lib_enc/ivas_stereo_td_enc_fx.c b/lib_enc/ivas_stereo_td_enc_fx.c index 8f1d2d9c9..1c9a5511e 100644 --- a/lib_enc/ivas_stereo_td_enc_fx.c +++ b/lib_enc/ivas_stereo_td_enc_fx.c @@ -327,8 +327,8 @@ ivas_error stereo_set_tdm_fx( return error; } - InitSWBencBuffer_ivas_fx( st ); - ResetSHBbuffer_Enc_fx( st ); + InitSWBencBuffer_ivas_fx( st->hBWE_TD ); + ResetSHBbuffer_Enc_fx( st->hBWE_TD ); IF( ( st->hBWE_FD = (FD_BWE_ENC_HANDLE) malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) { diff --git a/lib_enc/lib_enc_fx.c b/lib_enc/lib_enc_fx.c index 295608d6f..f64bdfd1e 100644 --- a/lib_enc/lib_enc_fx.c +++ b/lib_enc/lib_enc_fx.c @@ -1489,16 +1489,14 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( IF( hEncoderConfig->Opt_AMR_WB ) { - amr_wb_enc_fx( hCoreCoder, inputBuffer, inputBufferSize ); + amr_wb_enc_fx( hCoreCoder, inputBuffer, st_ivas->mem_hp20_in_fx[0], inputBufferSize ); } ELSE { #ifdef DEBUG_MODE_INFO dbgwrite( inputBuffer, sizeof( int16_t ), inputBufferSize, 1, strcat( fname( debug_dir, "ivas_input_dmx", 0, 1, ENC ), ".pcm" ) ); #endif - hCoreCoder->input_frame_fx = inputBufferSize; - move32(); - IF( NE_32( ( error = evs_enc_fx( hCoreCoder, inputBuffer, hCoreCoder->mem_hp20_in_fx, inputBufferSize ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = evs_enc_fx( hCoreCoder, inputBuffer, st_ivas->mem_hp20_in_fx[0], inputBufferSize ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_enc/mdct_selector_fx.c b/lib_enc/mdct_selector_fx.c index c4cc7d0db..8799806e4 100644 --- a/lib_enc/mdct_selector_fx.c +++ b/lib_enc/mdct_selector_fx.c @@ -315,11 +315,11 @@ void MDCT_selector_fx( test(); prefer_hq_core = ( LT_16( sub( Etot, sp_floor ), sig_lo_level_thr ) ) || /* noise floor is very high */ ( LT_16( cor_map_sum, cor_thr2 ) && LT_16( frame_voicing, voicing_thr2 ) && LT_16( sparseness, sparseness_thr2 ) ) || /* too weak tonal components */ - ( EQ_16( st->mdct_sw_enable, MODE1 ) && prefer_tcx == 0 && EQ_16( st->transientDetection.transientDetector.bIsAttackPresent, 1 ) ); + ( EQ_16( st->mdct_sw_enable, MODE1 ) && prefer_tcx == 0 && EQ_16( st->hTranDet->transientDetector.bIsAttackPresent, 1 ) ); /* Prefer HQ_CORE on transients */ test(); - IF( EQ_16( st->mdct_sw_enable, MODE2 ) && EQ_16( st->transientDetection.transientDetector.bIsAttackPresent, 1 ) ) + IF( EQ_16( st->mdct_sw_enable, MODE2 ) && EQ_16( st->hTranDet->transientDetector.bIsAttackPresent, 1 ) ) { prefer_tcx = 0; move16(); diff --git a/lib_enc/pre_proc_fx.c b/lib_enc/pre_proc_fx.c index 55e7437ee..ea94e6236 100644 --- a/lib_enc/pre_proc_fx.c +++ b/lib_enc/pre_proc_fx.c @@ -209,7 +209,7 @@ void pre_proc_fx( /*----------------------------------------------------------------* * Change the sampling frequency to 12.8 kHz *----------------------------------------------------------------*/ - modify_Fs_fx( signal_in, input_frame, st->input_Fs, new_inp_12k8, INT_FS_12k8, st->mem_decim_fx, ( const Word16 )( EQ_16( st->max_bwidth, NB ) ) ); + modify_Fs_fx( signal_in, input_frame, st->input_Fs, new_inp_12k8, INT_FS_12k8, st->mem_decim_fx, (const Word16) ( EQ_16( st->max_bwidth, NB ) ) ); Copy( new_inp_12k8, st->buf_speech_enc + L_FRAME32k, L_FRAME ); Scale_sig( st->buf_speech_enc + L_FRAME32k, L_FRAME, 1 ); /*------------------------------------------------------------------* @@ -393,8 +393,8 @@ void pre_proc_fx( test(); IF( st->tcx10Enabled || st->tcx20Enabled ) { - RunTransientDetection_fx( signal_in, input_frame, &st->transientDetection ); - currFlatness = GetTCXAvgTemporalFlatnessMeasure_fx( &st->transientDetection, NSUBBLOCKS, 0 ); + RunTransientDetection_fx( signal_in, input_frame, st->hTranDet ); + currFlatness = GetTCXAvgTemporalFlatnessMeasure_fx( st->hTranDet, NSUBBLOCKS, 0 ); } /*----------------------------------------------------------------* @@ -1261,7 +1261,7 @@ void pre_proc_fx( * TCX mode decision *---------------------------------------------------------------*/ - SetTCXModeInfo_fx( st, &st->transientDetection, &st->hTcxCfg->tcx_curr_overlap_mode ); + SetTCXModeInfo_fx( st, st->hTranDet, &st->hTcxCfg->tcx_curr_overlap_mode ); } /*-----------------------------------------------------------------* diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 28389e9e0..9d916f13a 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -863,10 +863,6 @@ void LPDmem_enc_init_fx( LPD_state_HANDLE hLPDmem /* i/o: LP memories */ ); -void LPDmem_enc_init_ivas_fx( - LPD_state_HANDLE hLPDmem /* i/o: LP memories */ -); - void lsf_end_enc_fx( Encoder_State *st, /* i/o: encoder state structure */ const Word16 *lsf, /* i : LSF in the frequency domain (0..6400) */ @@ -1044,14 +1040,16 @@ void calculate_hangover_attenuation_gain_fx( * Don't include the delay of the MDCT overlap. * @param pTransientDetection Structure to be initialized. It contains all transient detectors to be used. */ -void InitTransientDetection_fx( Word16 nFrameLength, - Word16 nTCXDelay, - struct TransientDetection *pTransientDetection ); +void InitTransientDetection_fx( + const Word16 nFrameLength, + const Word16 nTCXDelay, + TRAN_DET_HANDLE hTranDet ); -void InitTransientDetection_ivas_fx( Word16 nFrameLength, - Word16 nTCXDelay, - TRAN_DET_HANDLE pTransientDetection, - const Word16 ext_mem_flag ); +void InitTransientDetection_ivas_fx( + const Word16 nFrameLength, + const Word16 nTCXDelay, + TRAN_DET_HANDLE hTranDet, + const Word16 ext_mem_flag ); /** Runs transient detection. * Runs all transient detectors defined in pTransientDetection @@ -1060,7 +1058,10 @@ void InitTransientDetection_ivas_fx( Word16 nFrameLength, * @param nSamplesAvailable Number of new i samples available. * @param pTransientDetection Structure that contains transient detectors to be run. */ -void RunTransientDetection_fx( Word16 const *i, Word16 nSamplesAvailable, struct TransientDetection *pTransientDetection ); +void RunTransientDetection_fx( + Word16 const *i, + const Word16 nSamplesAvailable, + TRAN_DET_HANDLE hTranDet ); void RunTransientDetection_ivas_fx( @@ -1077,8 +1078,15 @@ void RunTransientDetection_ivas_fx( * @param nPrevSubblocks Number of subblocks from the previous frames to use for the calculation. * @return average temporal flatness measure with exponent AVG_FLAT_E */ -Word16 GetTCXAvgTemporalFlatnessMeasure_fx( struct TransientDetection const *pTransientDetection, Word16 nCurrentSubblocks, Word16 nPrevSubblocks ); -Word32 GetTCXAvgTemporalFlatnessMeasure_ivas_fx( struct TransientDetection const *pTransientDetection, Word16 nCurrentSubblocks, Word16 nPrevSubblocks ); +Word16 GetTCXAvgTemporalFlatnessMeasure_fx( + TRAN_DET_HANDLE hTranDet, + const Word16 nCurrentSubblocks, + const Word16 nPrevSubblocks ); + +Word32 GetTCXAvgTemporalFlatnessMeasure_ivas_fx( + TRAN_DET_HANDLE hTranDet, + const Word16 nCurrentSubblocks, + const Word16 nPrevSubblocks ); /** Get the maximum energy change using subblock energies aligned with the TCX. * @param pTransientDetection Structure that contains transient detectors to be run. @@ -1087,16 +1095,18 @@ Word32 GetTCXAvgTemporalFlatnessMeasure_ivas_fx( struct TransientDetection const * @param nPrevSubblocks Number of subblocks from the previous frames to use for the calculation. * @param maximum energy change with exponent NRG_CHANGE_E */ -Word16 GetTCXMaxenergyChange_fx( struct TransientDetection const *pTransientDetection, - const Word8 isTCX10, - const Word16 nCurrentSubblocks, - const Word16 nPrevSubblocks ); +Word16 GetTCXMaxenergyChange_fx( + TRAN_DET_HANDLE hTranDet, + const Word8 isTCX10, + const Word16 nCurrentSubblocks, + const Word16 nPrevSubblocks ); -Word16 GetTCXMaxenergyChange_ivas_fx( TRAN_DET_HANDLE hTranDet, - const Word8 isTCX10, - const Word16 nCurrentSubblocks, - const Word16 nPrevSubblocks ); +Word16 GetTCXMaxenergyChange_ivas_fx( + TRAN_DET_HANDLE hTranDet, + const Word8 isTCX10, + const Word16 nCurrentSubblocks, + const Word16 nPrevSubblocks ); /** Set TCX window length and overlap configuration * @param prevEnergyHF previous HF energy. Exponent must be the same as for currEnergyHF. @@ -1112,9 +1122,10 @@ void SetTCXModeInfo_ivas_fx( * @param prevEnergyHF previous HF energy. Exponent must be the same as for currEnergyHF. * @param currEnergyHF current HF energy. Exponent must be the same as for prevEnergyHF. */ -void SetTCXModeInfo_fx( Encoder_State *st, - struct TransientDetection const *pTransientDetection, - Word16 *tcxModeOverlap ); +void SetTCXModeInfo_fx( + Encoder_State *st, + TRAN_DET_HANDLE hTranDet, + Word16 *tcxModeOverlap ); void GSC_enc_init_fx( GSC_ENC_HANDLE hGSCEnc /* i/o: GSC data handle */ @@ -2645,34 +2656,35 @@ Word16 vlpc_1st_cod_fx( const Word16 *lsf, /* i : vector to quantize , Word16 rf_mode ); -void tcx_ltp_encode_fx( Word16 tcxltp_on, - Word8 tcxOnly, - Word16 tcxMode, - Word16 L_frame, - Word16 L_subfr, - Word16 *speech, - Word16 *speech_ltp, - Word16 *wsp, - Word16 Top, - Word16 *ltp_param, - Word16 *ltp_bits, - Word16 *pitch_int, - Word16 *pitch_fr, - Word16 *gain, - Word16 *pitch_int_past, - Word16 *pitch_fr_past, - Word16 *gain_past, - Word16 *norm_corr_past, - Word16 last_core, - Word16 pitmin, - Word16 pitfr1, - Word16 pitfr2, - Word16 pitmax, - Word16 pitres, - struct TransientDetection const *pTransientDetection, - Word8 SideInfoOnly, - Word16 *A, - Word16 lpcorder ); +void tcx_ltp_encode_fx( + Word16 tcxltp_on, + Word8 tcxOnly, + Word16 tcxMode, + Word16 L_frame, + Word16 L_subfr, + Word16 *speech, + Word16 *speech_ltp, + Word16 *wsp, + Word16 Top, + Word16 *ltp_param, + Word16 *ltp_bits, + Word16 *pitch_int, + Word16 *pitch_fr, + Word16 *gain, + Word16 *pitch_int_past, + Word16 *pitch_fr_past, + Word16 *gain_past, + Word16 *norm_corr_past, + Word16 last_core, + Word16 pitmin, + Word16 pitfr1, + Word16 pitfr2, + Word16 pitmax, + Word16 pitres, + TRAN_DET_HANDLE hTranDet, + Word8 SideInfoOnly, + Word16 *A, + Word16 lpcorder ); void tcx_ltp_encode_ivas_fx( Encoder_State *st, @@ -3513,8 +3525,9 @@ void re8_cod_fx( ); void TBEreset_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word16 bandwidth /* i : bandwidth mode */ + TD_BWE_ENC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + const int16_t last_core, /* i : last core */ + Word16 bandwidth /* i : bandwidth mode */ ); void acelp_core_switch_enc_fx( @@ -4228,16 +4241,17 @@ void noise_est_init_ivas_fx( ); void InitSWBencBuffer_fx( - Encoder_State *st_fx /* i/o: SHB encoder structure */ + TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ); void InitSWBencBuffer_ivas_fx( - Encoder_State *st_fx /* i/o: SHB encoder structure */ + TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ); void ResetSHBbuffer_Enc_fx( - Encoder_State *st_fx /* i/o: SHB encoder structure */ + TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ); + Word16 E_ACELP_hh_corr( Word16 *x /*Q11*/, Word16 *y /*Qy*/, Word16 L_subfr /*Q0*/, Word16 bits /*Q0*/ ); void acelp_1t64_fx( @@ -4588,8 +4602,9 @@ void destroy_encoder_fx( ); void amr_wb_enc_fx( - Encoder_State *st, /* i/o: encoder state structure */ + Encoder_State *st, /* i/o: encoder state structure */ const Word16 input_sp[], /* i : i signal Q0*/ + Word32 *mem_hp20_in_fx, /* i/o: hp20 filter memory Qx*/ const Word16 n_samples /* i : number of i samples Q0*/ ); diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index fdcff722c..760bbcb87 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -708,8 +708,6 @@ typedef struct sp_mus_clas_structure typedef struct lpd_state_structure { - - /* signal memory */ Word16 syn[1 + M]; /* Synthesis memory (non-pe) */ Word16 q_lpd_syn; @@ -803,7 +801,6 @@ typedef struct hq_enc_structure Word16 last_env_fx[BANDS_MAX]; /* Q1 */ Word16 last_max_pos_pulse; - } HQ_ENC_DATA, *HQ_ENC_HANDLE; /* PVQ range coder state */ @@ -1007,6 +1004,13 @@ typedef struct td_bwe_enc_structure Word16 gain_prec_swb_fx; /* Q14 */ Word16 mem_zero_swb_fx[LPC_SHB_ORDER]; + Word16 prev_lsp_wb_fx[LPC_SHB_ORDER_WB]; + Word16 prev_lpc_wb_fx[LPC_SHB_ORDER_WB]; + Word16 prev_lsp_wb_temp_fx[LPC_SHB_ORDER_WB]; + + Word16 prev_Q_bwe_exc; + Word16 prev_Q_bwe_syn; + } TD_BWE_ENC_DATA, *TD_BWE_ENC_HANDLE; @@ -1152,20 +1156,17 @@ typedef struct tcx_enc_structure Word16 transform_type[2]; /* TCX20/10/5 mode in each subframe */ /* Core Signal Analysis Outputs */ - Word16 noiseTiltFactor; /* compensation for LPC tilt in noise filling Q15 */ Word16 noiseLevelMemory_cnt; /* counter of consecutive low TCX noise levels */ Word16 ltpGainMemory_fx[N_LTP_GAIN_MEMS]; /* for smoothing noiseTransWidth Q15 */ STnsData tnsData[2]; - // Word16 fUseTns[2]; + Word8 fUseTns[2]; Word16 bTnsOnWhithenedSpectra[2]; - // Word16 memQuantZeros[L_FRAME_PLUS]; /* Quantization deadzone flags */ Word8 memQuantZeros[L_FRAME_PLUS]; /* Quantization deadzone flags */ Word16 *speech_TCX; Word16 *new_speech_TCX; - // Word16 q_speech_TCX; Word16 tcxltp; Word16 tcxltp_pitch_int; @@ -1219,17 +1220,9 @@ typedef struct tcx_enc_structure Word16 spectrum_long_e; /* MDCT output for a long block. Points to spectrum */ Word16 q_spectrum_long_fx; Word16 spectrum_length; /* corresponds to L_frameTCX, used for scaling of MDCT/MDST buffers */ + } TCX_ENC_DATA, *TCX_ENC_HANDLE; -typedef struct TransientDetection -{ - /** Transient detector. */ - TransientDetector transientDetector; - /** Delay buffer used by the transient detectors. */ - DelayBuffer delayBuffer; - /** Subblock energies used by the transient detector. */ - SubblockEnergies subblockEnergies; -} TransientDetection; /*----------------------------------------------------------------------------------* * @@ -1246,10 +1239,7 @@ typedef struct enc_core_structure Word16 idchan; /* channel ID (audio channel number) */ Word16 id_element; /* element ID */ Word16 element_mode; /* element mode */ - Word16 last_element_mode; /* element mode */ Word32 element_brate; /* element bitrate */ - Word16 extl_orig; /* extension layer */ - Word32 extl_brate_orig; /* extension layer bitrate */ Word16 codec_mode; /* Mode1 or Mode2 */ Word16 last_codec_mode; /* previous frame Mode 1 or 2 */ Word16 last_codec_mode_cng; /* previous inactive frame Mode 1 or 2 */ @@ -1258,9 +1248,7 @@ typedef struct enc_core_structure Word16 mdct_sw_enable; /* MDCT switching enable flag */ Word16 mdct_sw; /* MDCT switching indicator */ - BSTR_ENC_HANDLE hBstr; /* encoder bitstream handle */ - Word16 last_enerBuffer_exp; - + BSTR_ENC_HANDLE hBstr; /* encoder bitstream handle */ Word16 bitstreamformat; /* Bitstream format flag (G.192/MIME) */ Word16 next_bit_pos_fx; /* position of the next bit to be written in the bitstream */ @@ -1299,34 +1287,8 @@ typedef struct enc_core_structure char *force_dir; /* directory containing external binary files for modes/parameters enforcement (empty string indicates no enforcement) */ #endif #endif - Word16 nTimeSlots; /* for CLDFB */ - Word16 ini_frame; /* initialization frames counter */ - // Word32 input_Fs_fx; /* input signal sampling frequency in Hz */ - // Word32 total_brate_fx; /* total bitrate in kbps of the codec */ - // Word32 last_total_brate_fx; /* total bitrate in kbps of the codec */ - // Word32 last_total_brate_cng_fx; /* total bitrate in kbps of the last inactive frame */ - // Word16 core_fx; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */ - // Word32 core_brate_fx; /* core bitrate */ - // Word32 last_core_brate_fx; /* previous frame core bitrate */ - Word16 input_frame_fx; /* Frame lenght (function of input_Fs) */ - // Word16 extl_fx; /* extension layer */ - // Word16 last_extl_fx; /* previous extension layer */ - // Word32 extl_brate_fx; /* extension layer bitrate */ - // Word16 input_bwidth_fx; /* input signal bandwidth */ - // Word16 last_input_bwidth_fx; /* input signal bandwidth in the previous frame */ - // Word16 bwidth_fx; /* encoded bandwidth NB, WB, SWB or FB */ - // Word16 max_bwidth_fx; /* maximum encoded bandwidth */ - // Word16 last_bwidth_fx; /* input signal bandwidth in the previous frame */ - // Word16 last_bwidth_cng_fx; /* input signal bandwidth in the previous inactive frame */ - // Word16 L_frame_fx; /* ACELP core internal frame length */ - // Word16 Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ - // Word16 Opt_DTX_ON_fx; /* flag indicating DTX operation */ - // Word16 cng_type; /* flag indicating LP or CLDFB based SID/CNG */ - // Word16 Opt_SC_VBR_fx; /* flag indicating SC-VBR mode */ - // Word16 last_Opt_SC_VBR_fx; /* flag indicating SC-VBR mode in the last frame */ - /*----------------------------------------------------------------------------------* * ACELP core parameters *----------------------------------------------------------------------------------*/ @@ -1337,27 +1299,25 @@ typedef struct enc_core_structure Word16 fmerit_dt; /* signal classification score difference Q15 */ Word16 Nb_ACELP_frames; - Word16 pitch[3]; /* open-loop pitch values @12.8 kHz for three half-frames */ - // Word16 pitch_fx[3]; + Word16 pitch[3]; /* open-loop pitch values @12.8 kHz for three half-frames */ Word16 voicing_fx[3]; /* open-loop normalized correlation values for three half-frames Q15 */ LPD_state_HANDLE hLPDmem; /* ACELP LPDmem memories */ - Word32 Bin_E_fx[L_FFT]; /* Q_new + Q_SCALE -2 per bin energy of two frames */ - Word16 q_Bin_E; /* Q_new + Q_SCALE -2 per bin energy of two frames */ - Word16 lsp_old1_fx[M]; /* old unquantized LSP vector at the end of the frame Q15 */ - Word16 lsf_old1_fx[M]; /* old LSF vector at the end of the frame Qlog2(2.56) */ - Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame Q15 */ - Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame Qlog2(2.56) */ - Word16 lsp_old16k_fx[M]; /* old LSP vector at the end of the frame @16kHz Q15 */ - Word16 lspold_enc_fx[M]; /* old LSP vector at the end of the frame @16kHz Q15 */ - Word16 pstreaklen; /* LSF quantizer */ - Word16 streaklimit_fx; /* LSF quantizer Q15 */ - Word16 stab_fac_fx; /* LSF stability factor Q15 */ - Word16 clip_var_fx[6]; /* pitch gain clipping memory [2.56x,Q14,Q8,Q0,Q14,Q14] */ - Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) Qlog2(2.56) */ - Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) Qlog2(2.56) */ - // Word16 pstreaklen_fx; /* LSF quantizer */ + Word32 Bin_E_fx[L_FFT]; /* Q_new + Q_SCALE -2 per bin energy of two frames */ + Word16 q_Bin_E; /* Q_new + Q_SCALE -2 per bin energy of two frames */ + Word16 lsp_old1_fx[M]; /* old unquantized LSP vector at the end of the frame Q15 */ + Word16 lsf_old1_fx[M]; /* old LSF vector at the end of the frame Qlog2(2.56) */ + Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame Q15 */ + Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame Qlog2(2.56) */ + Word16 lsp_old16k_fx[M]; /* old LSP vector at the end of the frame @16kHz Q15 */ + Word16 lspold_enc_fx[M]; /* old LSP vector at the end of the frame @16kHz Q15 */ + Word16 pstreaklen; /* LSF quantizer */ + Word16 streaklimit_fx; /* LSF quantizer Q15 */ + Word16 stab_fac_fx; /* LSF stability factor Q15 */ + Word16 clip_var_fx[6]; /* pitch gain clipping memory [2.56x,Q14,Q8,Q0,Q14,Q14] */ + Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) Qlog2(2.56) */ + Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) Qlog2(2.56) */ Word32 offset_scale1_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 1st 8-dim subvector*/ Word32 offset_scale2_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 2nd 8-dim subvector*/ Word32 offset_scale1_p_fx[MAX_NO_MODES_p + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure, pred. case, 1st 8-dim subvector*/ @@ -1373,15 +1333,12 @@ typedef struct enc_core_structure Word16 old_wsp_fx[L_WSP_MEM]; /* old weighted signal vector */ Word16 exp_old_wsp; Word16 Q_old_wsp2; - /*Word16 old_exc_fx[L_EXC_MEM];*/ /* old excitation vector */ Word16 old_wsp2_fx[( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM]; /* old decimated weighted signal vector qwsp */ Word16 mem_wsp_fx; /* weighted signal vector memory */ Word16 mem_wsp_q; - Word16 mem_decim2_fx[3]; /* weighted signal decimation filter memory qwsp */ - Word16 mem_deemph_fx; /* deemphasis filter memory */ - Word32 mem_hp20_in_fx[5]; /* HP filter memory for AMR-WB IO */ - Word16 mCb1_fx; /* LSF quantizer - counter of stationary frames after a transition frame */ - Word16 GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ + Word16 mem_decim2_fx[3]; /* weighted signal decimation filter memory qwsp */ + Word16 mCb1_fx; /* LSF quantizer - counter of stationary frames after a transition frame */ + Word16 GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ Word16 GSC_IVAS_mode; GSC_ENC_HANDLE hGSCEnc; @@ -1390,7 +1347,6 @@ typedef struct enc_core_structure Word16 lsfoldbfi1_fx[M]; /* FEC - LSF vector of the past previous frame Qlog2(2.56) */ Word16 lsf_adaptive_mean_fx[M]; /* FEC - adaptive mean LSF vector for FEC Qlog2(2.56) */ Word16 next_force_safety_net; /* FEC - flag to force safety net in next frame */ - // Word16 next_force_safety_net_fx; /* FEC - flag to force safety net in next frame */ Word16 uv_count; /* Stationary noise UV modification - unvoiced counter */ Word16 act_count; /* Stationary noise UV modification - activation counter */ @@ -1476,7 +1432,7 @@ typedef struct enc_core_structure Word16 *old_inp_16k_fx; /* ACELP@16kHz - memory of input signal @16 kHz */ Word16 *buf_speech_enc_pe; // exp_buf_speech_enc_pe - Word16 *buf_synth; /*can be reduced to PIT_MAX_MAX+L_FRAME_MAX if no rate switching*/ + Word16 *buf_synth; /* can be reduced to PIT_MAX_MAX+L_FRAME_MAX if no rate switching*/ Word16 *buf_speech_enc; // exp_buf_speech_enc Word16 *buf_wspeech_enc; // exp_buf_wspeech_enc @@ -1487,6 +1443,8 @@ typedef struct enc_core_structure Word16 exp_buf_wspeech_enc; Word16 exp_buf_synth; + Word16 lgBin_E_fx[L_FFT / 2]; /* Q8 per bin energy of two frames */ + /*----------------------------------------------------------------------------------* * Noise estimation *----------------------------------------------------------------------------------*/ @@ -1499,8 +1457,6 @@ typedef struct enc_core_structure SP_MUS_CLAS_HANDLE hSpMusClas; - Word16 lgBin_E_fx[L_FFT / 2]; /* Q8 per bin energy of two frames */ - Word16 sp_aud_decision0; /* 1st stage speech/music decision flag */ Word16 sp_aud_decision1; /* 1st stage speech/music classification flag */ Word16 sp_aud_decision2; /* 2nd stage speech/music classification flag */ @@ -1539,9 +1495,6 @@ typedef struct enc_core_structure HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc; /* main analysis filter bank handle */ HANDLE_CLDFB_FILTER_BANK cldfbSynTd; /* synthesis filterbank - used for HB signal generation */ - // HANDLE_CLDFB_FILTER_BANK cldfbAna_Fx; - - // HANDLE_CLDFB_FILTER_BANK cldfbSyn_Fx; /*----------------------------------------------------------------------------------* * FD CNG handle @@ -1572,7 +1525,6 @@ typedef struct enc_core_structure HQ_ENC_HANDLE hHQ_core; /* HQ core encoder handle */ - PVQ_ENC_HANDLE hPVQ; /*----------------------------------------------------------------------------------* * TD BWE parameters *----------------------------------------------------------------------------------*/ @@ -1671,13 +1623,11 @@ typedef struct enc_core_structure Word16 inv_gamma; /* Q14 */ TRAN_DET_HANDLE hTranDet; - TransientDetection transientDetection; - Word16 transient_info[3]; + Word16 acelpFramesCount; Word16 prevTempFlatness_fx; /* exponent is AVG_FLAT_E Q7 in EVS */ /* Q4 in IVAS */ Word32 prevTempFlatness_32fx; /* Q21 in IVAS */ - // float currEnergyLookAhead; Word32 currEnergyLookAhead_fx; // Q31 Word32 prevEnergyHF_fx; Word32 currEnergyHF_fx; @@ -1696,7 +1646,6 @@ typedef struct enc_core_structure Word16 encoderLookahead_FB; /* pitch_ol for adaptive lag window */ - Word16 old_pitch_la; /* past open loop pitch lag from look-ahead before very short stable pitch detection */ Word16 old_voicing_la; /* past open loop pitch gain from look-ahead */ @@ -1773,8 +1722,7 @@ typedef struct enc_core_structure * IVAS parameters *---------------------------------------------------------------*/ - Word16 tdm_LRTD_flag; /* LRTD stereo mode flag */ - Word16 cna_dirac_flag; /* CNA in DirAC flag */ + Word16 tdm_LRTD_flag; /* LRTD stereo mode flag */ /* stereo switching memories */ Word16 mem_preemph_DFT_fx; /* Q(-1) */ @@ -1790,16 +1738,13 @@ typedef struct enc_core_structure Word16 dtx_sce_sba; /* enable use of FD CNG with transform domain cores in SCE SBA */ + Word16 sba_br_sw_while_no_data; /* Indicator for SBA bitrate switch while in FRAME_NO_DATA mode */ + /*----------------------------------------------------------------------------------* * Fixed point only variables *----------------------------------------------------------------------------------*/ - Word16 last_ener_fx; /* AC mode (GSC) - previous energy */ - Word16 Q_exc; - - Word16 prev_Q_bwe_exc; - Word16 prev_Q_bwe_syn; Word16 Q_stat_noise_ge; Word16 Q_stat_noise; Word16 Q_syn2; @@ -1813,13 +1758,8 @@ typedef struct enc_core_structure Word16 prev_Q_new; Word16 prev_Q_shb; Word16 Q_max_enc[2]; - Word16 EnergyLT_fx_exp; - Word16 prev_lsp_wb_fx[LPC_SHB_ORDER_WB]; - Word16 prev_lpc_wb_fx[LPC_SHB_ORDER_WB]; - Word16 prev_lsp_wb_temp_fx[LPC_SHB_ORDER_WB]; - - Word16 sba_br_sw_while_no_data; /* Indicator for SBA bitrate switch while in FRAME_NO_DATA mode */ + Word16 last_enerBuffer_exp; } Encoder_State, *ENC_CORE_HANDLE; diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 490d80aae..cd38203e9 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -417,12 +417,12 @@ void rescale_genWB_mem_enc( Encoder_State *st_fx, Word16 sf ) * * Initialize SWB buffers *-------------------------------------------------------------------*/ + void InitSWBencBuffer_fx( - Encoder_State *st_fx /* i/o: SHB encoder structure */ + TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ) { Word16 i; - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; set16_fx( hBWE_TD->old_bwe_exc_fx, 0, ( PIT16k_MAX * 2 ) ); hBWE_TD->bwe_seed[0] = 23; @@ -446,15 +446,8 @@ void InitSWBencBuffer_fx( set16_fx( hBWE_TD->old_input_fhb_fx, 0, NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2 ); // IVAS_CODE - // set_f(hBWE_TD->mem_shb_res, 0.0f, MAX_LEN_MA_FILTER); - // set_f(hBWE_TD->old_EnvSHBres, 0.0f, L_FRAME4k); - // hBWE_TD->old_mean_EnvSHBres = 0.0f; - // hBWE_TD->prev_enr_EnvSHBres = 1.0f; - // hBWE_TD->prev_shb_env_tilt = 0.0f; - // hBWE_TD->prev_pow_exc16kWhtnd = 1.0f; - // hBWE_TD->prev_mix_factor = 1.0f; - // hBWE_TD->prev_Env_error = 0.0f; - set16_fx( hBWE_TD->prev_lsp_shb_fx, 0, 10 ); + // InitSWBencBufferStates_fx(hBWE_TD, NULL ); + set16_fx( hBWE_TD->prev_lsp_shb_fx, 0, LPC_SHB_ORDER ); hBWE_TD->cldfbHBLT = 8192 /*1.0f Q13*/; move16(); @@ -504,25 +497,29 @@ void InitSWBencBuffer_fx( hBWE_TD->prev_fb_energy_fx_Q = 0; move16(); - - // TV2TV IVAS_CODE -> To be verify if it has to be moved to hBWE_TD - st_fx->prev_Q_bwe_exc = 31; + hBWE_TD->prev_Q_bwe_exc = 31; move16(); - st_fx->prev_Q_bwe_syn = 31; + hBWE_TD->prev_Q_bwe_syn = 31; move16(); - set16_fx( st_fx->prev_lsp_wb_fx, 0, 6 ); - set16_fx( st_fx->prev_lsp_wb_temp_fx, 0, 6 ); - set16_fx( st_fx->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB ); + set16_fx( hBWE_TD->prev_lsp_wb_fx, 0, 6 ); + set16_fx( hBWE_TD->prev_lsp_wb_temp_fx, 0, 6 ); + set16_fx( hBWE_TD->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB ); return; } + +/*-------------------------------------------------------------------* + * InitSWBencBufferStates() + * + * Initialize SWB buffer states + *-------------------------------------------------------------------*/ + void InitSWBencBuffer_ivas_fx( - Encoder_State *st_fx /* i/o: SHB encoder structure */ + TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ) { Word16 i; - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; set16_fx( hBWE_TD->old_bwe_exc_fx, 0, ( PIT16k_MAX * 2 ) ); hBWE_TD->bwe_seed[0] = 23; @@ -599,33 +596,30 @@ void InitSWBencBuffer_ivas_fx( set16_fx( hBWE_TD->dec_2_over_3_mem_fx, 0, 12 ); set16_fx( hBWE_TD->dec_2_over_3_mem_lp_fx, 0, 6 ); - hBWE_TD->prev_fb_energy_fx_Q = 0; move16(); - - // TV2TV IVAS_CODE -> To be verify if it has to be moved to hBWE_TD - st_fx->prev_Q_bwe_exc = 15; + hBWE_TD->prev_Q_bwe_exc = 15; move16(); - st_fx->prev_Q_bwe_syn = 15; + hBWE_TD->prev_Q_bwe_syn = 15; move16(); - set16_fx( st_fx->prev_lsp_wb_fx, 0, 6 ); - set16_fx( st_fx->prev_lsp_wb_temp_fx, 0, 6 ); - set16_fx( st_fx->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB ); + set16_fx( hBWE_TD->prev_lsp_wb_fx, 0, 6 ); + set16_fx( hBWE_TD->prev_lsp_wb_temp_fx, 0, 6 ); + set16_fx( hBWE_TD->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB ); return; } + /*-------------------------------------------------------------------* * ResetSHBbuffer_Enc() * *-------------------------------------------------------------------*/ + void ResetSHBbuffer_Enc_fx( - Encoder_State *st_fx /* i/o: SHB encoder structure */ + TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ) { - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - /* states for the filters used in generating SHB excitation from WB excitation*/ set16_fx( hBWE_TD->mem_genSHBexc_filt_down_shb_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); set32_fx( hBWE_TD->mem_csfilt_fx, 0, 2 ); @@ -656,7 +650,6 @@ void ResetSHBbuffer_Enc_fx( hBWE_TD->tbe_premph_fx = 0; move16(); - return; } @@ -804,11 +797,11 @@ void wb_tbe_enc_fx( move32(); } - lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb_temp_fx, st_fx->prev_lsp_wb_temp_fx, LPC_SHB_ORDER_WB ); + lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb_temp_fx, hBWE_TD->prev_lsp_wb_temp_fx, LPC_SHB_ORDER_WB ); FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { - st_fx->prev_lsp_wb_temp_fx[i] = lsp_wb_temp_fx[i]; + hBWE_TD->prev_lsp_wb_temp_fx[i] = lsp_wb_temp_fx[i]; move16(); } @@ -857,11 +850,11 @@ void wb_tbe_enc_fx( lpc_wb_32_fx[i] = L_negate( L_shr( L_deposit_h( lpc_wb[i] ), 1 ) ); move32(); /*Q27 */ } - lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, st_fx->prev_lsp_wb_fx, LPC_SHB_ORDER_LBR_WB ); + lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, hBWE_TD->prev_lsp_wb_fx, LPC_SHB_ORDER_LBR_WB ); FOR( i = 0; i < LPC_SHB_ORDER_LBR_WB; i++ ) { - st_fx->prev_lsp_wb_fx[i] = lsp_wb[i]; + hBWE_TD->prev_lsp_wb_fx[i] = lsp_wb[i]; move16(); } @@ -881,12 +874,12 @@ void wb_tbe_enc_fx( Copy( lbr_wb_bwe_lsfvq_cbook_2bit_fx + i * LPC_SHB_ORDER_LBR_WB, lsp_wb, LPC_SHB_ORDER_LBR_WB ); - lsp2lpc_fx( &lpc_wb[1], lsp_wb, st_fx->prev_lpc_wb_fx, LPC_SHB_ORDER_LBR_WB ); + lsp2lpc_fx( &lpc_wb[1], lsp_wb, hBWE_TD->prev_lpc_wb_fx, LPC_SHB_ORDER_LBR_WB ); set16_fx( lpc_wb + LPC_SHB_ORDER_LBR_WB + 1, 0, ( LPC_SHB_ORDER_WB - LPC_SHB_ORDER_LBR_WB ) ); FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { - st_fx->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; + hBWE_TD->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; move16(); } @@ -917,12 +910,11 @@ void wb_tbe_enc_fx( move32(); /*Q27 */ } - lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, st_fx->prev_lsp_wb_fx, LPC_SHB_ORDER_WB ); - + lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, hBWE_TD->prev_lsp_wb_fx, LPC_SHB_ORDER_WB ); FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { - st_fx->prev_lsp_wb_fx[i] = lsp_wb[i]; + hBWE_TD->prev_lsp_wb_fx[i] = lsp_wb[i]; move16(); } @@ -942,12 +934,11 @@ void wb_tbe_enc_fx( } Copy( wb_bwe_lsfvq_cbook_8bit_fx + i * LPC_SHB_ORDER_WB, lsp_wb, LPC_SHB_ORDER_WB ); - lsp2lpc_fx( &lpc_wb[1], lsp_wb, st_fx->prev_lpc_wb_fx, LPC_SHB_ORDER_WB ); - + lsp2lpc_fx( &lpc_wb[1], lsp_wb, hBWE_TD->prev_lpc_wb_fx, LPC_SHB_ORDER_WB ); FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { - st_fx->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; + hBWE_TD->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; move16(); } FOR( i = 1; i < LPC_SHB_ORDER_WB + 1; i++ ) @@ -1000,9 +991,9 @@ void wb_tbe_enc_fx( find_max_mem_wb_enc( st_fx, &n_mem ); - IF( GT_16( sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ), n_mem ) ) + IF( GT_16( sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_exc ), n_mem ) ) { - Q_bwe_exc = add( st_fx->prev_Q_bwe_exc, n_mem ); + Q_bwe_exc = add( hBWE_TD->prev_Q_bwe_exc, n_mem ); } IF( uv_flag ) @@ -1018,7 +1009,7 @@ void wb_tbe_enc_fx( move32(); IF( st_fx->element_mode > EVS_MONO ) { - tmp = sub( shl( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), 31 + 16 ); + tmp = sub( shl( sub( hBWE_TD->prev_Q_bwe_exc, 16 ), 1 ), 31 + 16 ); prev_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ } FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) @@ -1026,7 +1017,7 @@ void wb_tbe_enc_fx( prev_pow = L_mac0( prev_pow, hBWE_TD->state_syn_shbexc_fx[i], hBWE_TD->state_syn_shbexc_fx[i] ); /* Q(2*st_fx->prev_Q_bwe_exc) */ } - rescale_genWB_mem_enc( st_fx, sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ) ); + rescale_genWB_mem_enc( st_fx, sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_exc ) ); Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); sc = sub( Q_bwe_exc, add( Q_new, Q_new ) ); @@ -1037,11 +1028,9 @@ void wb_tbe_enc_fx( } Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); - Copy( hBWE_TD->state_syn_shbexc_fx, shaped_wb_excitation, L_SHB_LAHEAD / 4 ); Q_bwe_exc_ext = sub( Q_bwe_exc, 16 ); - GenShapedWBExcitation_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, hBWE_TD->state_lpc_syn_fx, coder_type, bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, @@ -1064,8 +1053,7 @@ void wb_tbe_enc_fx( curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc_ext) */ } - Lscale = root_a_over_b_fx( curr_pow, shl_r( Q_bwe_exc_ext, 1 ), prev_pow, shl_r( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), &exp ); - + Lscale = root_a_over_b_fx( curr_pow, shl_r( Q_bwe_exc_ext, 1 ), prev_pow, shl_r( sub( hBWE_TD->prev_Q_bwe_exc, 16 ), 1 ), &exp ); FOR( i = 0; i < L_SHB_LAHEAD / 4 - 1; i++ ) { @@ -1146,7 +1134,6 @@ void wb_tbe_enc_fx( move16(); /* Q15 */ } - temp_wb_fac_fx = hBWE_TD->prev_wb_GainShape; move16(); FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) @@ -1185,7 +1172,6 @@ void wb_tbe_enc_fx( EstimateSHBFrameGain_fx( SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, shaped_wb_excitation, Q_bwe_exc_ext, GainShape, &GainFrame, window_wb_fx, subwin_wb_fx, 0 ); - /* If there's a big difference in the power of gains away from the peak gain */ /* due to poor quantization then suppress energy of the high band. */ @@ -1239,7 +1225,6 @@ void wb_tbe_enc_fx( /*wbbwe_em_factor = add( mult_r( 29491, st_fx->prev_wbbwe_em_factor_fx ), mult_r( 3277, wbbwe_em_factor ) ); */ /* Q15 */ } - /*0.25f*sum_f(voice_factors, NB_SUBFR)*/ L_tmp = L_mult( voice_factors[0], 8192 ); FOR( i = 1; i < NB_SUBFR; i++ ) @@ -1271,7 +1256,7 @@ void wb_tbe_enc_fx( ScaleShapedSHB_fx( SHB_OVERLAP_LEN / 2, shaped_wb_excitation, hBWE_TD->syn_overlap_fx, GainShape, GainFrame, window_wb_fx, subwin_wb_fx, &Q_bwe_exc_ext, &dummy, dummy, dummy ); - st_fx->prev_Q_bwe_exc = Q_bwe_exc; + hBWE_TD->prev_Q_bwe_exc = Q_bwe_exc; move16(); return; @@ -1416,11 +1401,11 @@ void wb_tbe_enc_ivas_fx( move32(); } - lpc2lsp_ivas_fx( &lpc_wb_32_fx[1], lsp_wb_temp_fx, st_fx->prev_lsp_wb_temp_fx, LPC_SHB_ORDER_WB ); + lpc2lsp_ivas_fx( &lpc_wb_32_fx[1], lsp_wb_temp_fx, hBWE_TD->prev_lsp_wb_temp_fx, LPC_SHB_ORDER_WB ); FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { - st_fx->prev_lsp_wb_temp_fx[i] = lsp_wb_temp_fx[i]; + hBWE_TD->prev_lsp_wb_temp_fx[i] = lsp_wb_temp_fx[i]; move16(); } @@ -1469,11 +1454,11 @@ void wb_tbe_enc_ivas_fx( lpc_wb_32_fx[i] = L_negate( L_shr( L_deposit_h( lpc_wb[i] ), 1 ) ); move32(); /*Q27 */ } - lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, st_fx->prev_lsp_wb_fx, LPC_SHB_ORDER_LBR_WB ); + lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, hBWE_TD->prev_lsp_wb_fx, LPC_SHB_ORDER_LBR_WB ); FOR( i = 0; i < LPC_SHB_ORDER_LBR_WB; i++ ) { - st_fx->prev_lsp_wb_fx[i] = lsp_wb[i]; + hBWE_TD->prev_lsp_wb_fx[i] = lsp_wb[i]; move16(); } @@ -1493,12 +1478,12 @@ void wb_tbe_enc_ivas_fx( Copy( lbr_wb_bwe_lsfvq_cbook_2bit_fx + i * LPC_SHB_ORDER_LBR_WB, lsp_wb, LPC_SHB_ORDER_LBR_WB ); - lsp2lpc_fx( &lpc_wb[1], lsp_wb, st_fx->prev_lpc_wb_fx, LPC_SHB_ORDER_LBR_WB ); + lsp2lpc_fx( &lpc_wb[1], lsp_wb, hBWE_TD->prev_lpc_wb_fx, LPC_SHB_ORDER_LBR_WB ); set16_fx( lpc_wb + LPC_SHB_ORDER_LBR_WB + 1, 0, ( LPC_SHB_ORDER_WB - LPC_SHB_ORDER_LBR_WB ) ); FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { - st_fx->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; + hBWE_TD->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; move16(); } @@ -1529,12 +1514,11 @@ void wb_tbe_enc_ivas_fx( move32(); /*Q27 */ } - lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, st_fx->prev_lsp_wb_fx, LPC_SHB_ORDER_WB ); - + lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb, hBWE_TD->prev_lsp_wb_fx, LPC_SHB_ORDER_WB ); FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { - st_fx->prev_lsp_wb_fx[i] = lsp_wb[i]; + hBWE_TD->prev_lsp_wb_fx[i] = lsp_wb[i]; move16(); } @@ -1546,11 +1530,11 @@ void wb_tbe_enc_ivas_fx( push_indice( st_fx->hBstr, IND_SHB_LSF, i, NUM_BITS_WB_LSF ); Copy( wb_bwe_lsfvq_cbook_8bit_fx + i * LPC_SHB_ORDER_WB, lsp_wb, LPC_SHB_ORDER_WB ); - lsp2lpc_fx( &lpc_wb[1], lsp_wb, st_fx->prev_lpc_wb_fx, LPC_SHB_ORDER_WB ); + lsp2lpc_fx( &lpc_wb[1], lsp_wb, hBWE_TD->prev_lpc_wb_fx, LPC_SHB_ORDER_WB ); FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { - st_fx->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; + hBWE_TD->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; move16(); } FOR( i = 1; i < LPC_SHB_ORDER_WB + 1; i++ ) @@ -1605,9 +1589,9 @@ void wb_tbe_enc_ivas_fx( find_max_mem_wb_enc( st_fx, &n_mem ); - IF( GT_16( sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ), n_mem ) ) + IF( GT_16( sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_exc ), n_mem ) ) { - Q_bwe_exc = add( st_fx->prev_Q_bwe_exc, n_mem ); + Q_bwe_exc = add( hBWE_TD->prev_Q_bwe_exc, n_mem ); } IF( uv_flag ) @@ -1632,7 +1616,7 @@ void wb_tbe_enc_ivas_fx( shaped_wb_exc_scale[i] = shr( hBWE_TD->state_syn_shbexc_fx[i], 3 ); move16(); } - Q_prev_pow = shl_r( sub( sub( st_fx->prev_Q_bwe_exc, 16 ), 3 ), 1 ); + Q_prev_pow = shl_r( sub( sub( hBWE_TD->prev_Q_bwe_exc, 16 ), 3 ), 1 ); move16(); } ELSE @@ -1642,7 +1626,7 @@ void wb_tbe_enc_ivas_fx( shaped_wb_exc_scale[i] = hBWE_TD->state_syn_shbexc_fx[i]; move16(); } - Q_prev_pow = shl_r( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ); + Q_prev_pow = shl_r( sub( hBWE_TD->prev_Q_bwe_exc, 16 ), 1 ); move16(); } @@ -1656,7 +1640,7 @@ void wb_tbe_enc_ivas_fx( prev_pow = L_mac0( prev_pow, shaped_wb_exc_scale[i], shaped_wb_exc_scale[i] ); /* Q_prev_pow */ } - rescale_genWB_mem_enc( st_fx, sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ) ); + rescale_genWB_mem_enc( st_fx, sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_exc ) ); sc = sub( Q_bwe_exc, add( Q_new, Q_new ) ); FOR( i = 0; i < L_FRAME32k; i++ ) @@ -1795,7 +1779,6 @@ void wb_tbe_enc_ivas_fx( move16(); /* Q15 */ } - temp_wb_fac_fx = hBWE_TD->prev_wb_GainShape; move16(); FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) @@ -1930,7 +1913,6 @@ void wb_tbe_enc_ivas_fx( /* Adjust the subframe and frame gain of the synthesized SHB signal */ /* Scale the shaped excitation*/ - scale_sig( shaped_wb_excitation, ( L_FRAME16k + L_SHB_LAHEAD ) / 4, -1 ); scale_sig( hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, -1 ); Q_bwe_exc_ext = sub( Q_bwe_exc_ext, 1 ); @@ -1938,7 +1920,7 @@ void wb_tbe_enc_ivas_fx( &Q_bwe_exc_ext, &dummy, dummy, dummy ); Scale_sig( hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, 1 ); - st_fx->prev_Q_bwe_exc = Q_bwe_exc; + hBWE_TD->prev_Q_bwe_exc = Q_bwe_exc; move16(); return; @@ -2437,7 +2419,7 @@ void swb_tbe_enc_fx( /* Account for any outliers in the memories from previous frame for rescaling to avoid saturation */ find_max_mem_enc( st_fx, &n_mem, &n_mem2 ); - tmp2 = add( st_fx->prev_Q_bwe_exc, n_mem ); + tmp2 = add( hBWE_TD->prev_Q_bwe_exc, n_mem ); if ( GT_16( Q_bwe_exc, tmp2 ) ) { Q_bwe_exc = tmp2; @@ -2445,7 +2427,7 @@ void swb_tbe_enc_fx( } /* rescale the memories if Q_bwe_exc is different from previous frame */ - sc = sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ); + sc = sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_exc ); IF( sc != 0 ) { rescale_genSHB_mem_enc( st_fx, sc ); @@ -2466,7 +2448,7 @@ void swb_tbe_enc_fx( Copy( hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation_fx, L_SHB_LAHEAD ); /* save the previous Q factor of the buffer */ - st_fx->prev_Q_bwe_exc = Q_bwe_exc; + hBWE_TD->prev_Q_bwe_exc = Q_bwe_exc; move16(); Q_bwe_exc = sub( Q_bwe_exc, 16 ); /* Q_bwe_exc reflecting the single precision dynamic norm-ed buffers from here */ @@ -2487,7 +2469,7 @@ void swb_tbe_enc_fx( coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st_fx->extl, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_Q31, shb_res_gshape_fx, shb_res_fx, &vf_ind_fx, formant_fac_fx, hBWE_TD->fb_state_lpc_syn_fx, - &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, st_fx->prev_Q_bwe_syn, st_fx->total_brate, 0 ); + &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, hBWE_TD->prev_Q_bwe_syn, st_fx->total_brate, 0 ); *Q_white_exc = Q_bwe_exc_fb; move16(); @@ -2520,7 +2502,7 @@ void swb_tbe_enc_fx( FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->mem_stp_swb_fx[i] = shl( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, st_fx->prev_Q_bwe_syn ) ); + hBWE_TD->mem_stp_swb_fx[i] = shl( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_syn ) ); move16(); } @@ -2528,12 +2510,9 @@ void swb_tbe_enc_fx( { PostShortTerm_fx( &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); - /* i: shaped_shb_excitation_fx in Q_bwe_exc */ - /* i: lpc_shb_fx in Q12 */ } Copy( shaped_shb_excitationTemp_fx, &shaped_shb_excitation_fx[L_SHB_LAHEAD], L_FRAME16k ); - tmp = sub( shl( Q_bwe_exc, 1 ), 31 ); prev_pow_fx = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ curr_pow_fx = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ @@ -2909,7 +2888,7 @@ void swb_tbe_enc_fx( } /* *Q_white_exc = Q_bwe_exc_mod; move16(); output Qwhiteexc_FB from the GenShapedSHB function*/ - st_fx->prev_Q_bwe_syn = Q_bwe_exc; + hBWE_TD->prev_Q_bwe_syn = Q_bwe_exc; move16(); return; @@ -3744,7 +3723,7 @@ void swb_tbe_enc_ivas_fx( /* Account for any outliers in the memories from previous frame for rescaling to avoid saturation */ find_max_mem_enc( st_fx, &n_mem, &n_mem2 ); - tmp2 = add( st_fx->prev_Q_bwe_exc, n_mem ); + tmp2 = add( hBWE_TD->prev_Q_bwe_exc, n_mem ); if ( GT_16( Q_bwe_exc, tmp2 ) ) { Q_bwe_exc = tmp2; @@ -3752,7 +3731,7 @@ void swb_tbe_enc_ivas_fx( } /* rescale the memories if Q_bwe_exc is different from previous frame */ - sc = sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ); + sc = sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_exc ); IF( sc != 0 ) { rescale_genSHB_mem_enc( st_fx, sc ); @@ -3770,7 +3749,7 @@ void swb_tbe_enc_ivas_fx( Copy( hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation_fx, L_SHB_LAHEAD ); /* save the previous Q factor of the buffer */ - st_fx->prev_Q_bwe_exc = Q_bwe_exc; + hBWE_TD->prev_Q_bwe_exc = Q_bwe_exc; move16(); Q_bwe_exc = sub( Q_bwe_exc, 16 ); /* Q_bwe_exc reflecting the single precision dynamic norm-ed buffers from here */ @@ -3783,7 +3762,7 @@ void swb_tbe_enc_ivas_fx( hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, st_fx->coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st_fx->extl, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_Q31, shb_res_gshape_fx, shb_res_fx, &vf_ind_fx, formant_fac_fx, hBWE_TD->fb_state_lpc_syn_fx, &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, - &Q_bwe_exc_fb, Q_shb, n_mem2, st_fx->prev_Q_bwe_syn, st_fx->total_brate, 0, st_fx->element_mode, st_fx->flag_ACELP16k, nlExc16k_fx, + &Q_bwe_exc_fb, Q_shb, n_mem2, hBWE_TD->prev_Q_bwe_syn, st_fx->total_brate, 0, st_fx->element_mode, st_fx->flag_ACELP16k, nlExc16k_fx, nlExc16k_e, mixExc16k_fx, mixExc16k_e, st_fx->extl_brate, MSFlag, EnvSHBres_4k_norm_fx, Q_EnvSHBres_4k_norm, &( hBWE_TD->prev_pow_exc16kWhtnd_fx32 ), &( hBWE_TD->prev_mix_factor_fx ), &Env_error_fx, Env_error_part_fx ); @@ -3835,7 +3814,7 @@ void swb_tbe_enc_ivas_fx( FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->mem_stp_swb_fx[i] = shl_sat( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, st_fx->prev_Q_bwe_syn ) ); + hBWE_TD->mem_stp_swb_fx[i] = shl_sat( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_syn ) ); move16(); } @@ -4184,7 +4163,6 @@ void swb_tbe_enc_ivas_fx( } } - hBWE_TD->prev_swb_GainShape_fx = GainShape_fx[3]; move16(); @@ -4200,7 +4178,6 @@ void swb_tbe_enc_ivas_fx( /* Quantization of the gain shape parameter */ QuantizeSHBsubgains_ivas_fx( st_fx, GainShape_fx, st_fx->extl ); - /* o: GainShape_fx in Q15 */ /* Compute the power of gains away from the peak gain after quantization */ IF( st_fx->element_mode > EVS_MONO ) @@ -4568,7 +4545,7 @@ void swb_tbe_enc_ivas_fx( move16(); /* *Q_white_exc = Q_bwe_exc_mod; move16(); output Qwhiteexc_FB from the GenShapedSHB function*/ - st_fx->prev_Q_bwe_syn = Q_bwe_exc; + hBWE_TD->prev_Q_bwe_syn = Q_bwe_exc; move16(); return; @@ -7051,7 +7028,7 @@ static void first_VQstages_fx( dist[1] = dist_buf + maxC; move16(); - set16_fx( idx_buf, 0, ( const Word16 )( 2 * stagesVQ * maxC ) ); + set16_fx( idx_buf, 0, (const Word16) ( 2 * stagesVQ * maxC ) ); set16_fx( parents, 0, maxC ); /* Set up inital distance vector */ @@ -7902,22 +7879,23 @@ void tbe_write_bitstream_fx( { push_next_indice( hBstr, hBWE_TD->idxGain, 4 ); } + + return; } void TBEreset_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word16 bandwidth /* i : bandwidth mode */ + TD_BWE_ENC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + const int16_t last_core, /* i : last core */ + Word16 bandwidth /* i : bandwidth mode */ ) { - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - - IF( NE_16( st_fx->last_core, ACELP_CORE ) ) + IF( NE_16( last_core, ACELP_CORE ) ) { set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); move32(); - st_fx->prev_Q_bwe_exc = 31; + hBWE_TD->prev_Q_bwe_exc = 31; move16(); } @@ -7947,6 +7925,8 @@ void TBEreset_enc_fx( fb_tbe_reset_enc_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx, &hBWE_TD->prev_fb_energy_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, &hBWE_TD->prev_fb_energy_fx_Q ); } } + + return; } /*-------------------------------------------------------------------* diff --git a/lib_enc/tcx_ltp_enc_fx.c b/lib_enc/tcx_ltp_enc_fx.c index a3d8620a4..48067948b 100644 --- a/lib_enc/tcx_ltp_enc_fx.c +++ b/lib_enc/tcx_ltp_enc_fx.c @@ -606,34 +606,35 @@ static void tcx_ltp_find_gain_ivas_fx( Word16 *speech /*Qx*/, Word16 *pred_speec move16(); } -void tcx_ltp_encode_fx( Word16 tcxltp_on, - Word8 tcxOnly, - Word16 tcxMode, - Word16 L_frame, - Word16 L_subfr, - Word16 *speech, - Word16 *speech_ltp, - Word16 *wsp, - Word16 Top, - Word16 *ltp_param, - Word16 *ltp_bits, - Word16 *pitch_int, - Word16 *pitch_fr, - Word16 *gain, - Word16 *pitch_int_past, - Word16 *pitch_fr_past, - Word16 *gain_past, - Word16 *norm_corr_past, - Word16 last_core, - Word16 pitmin, - Word16 pitfr1, - Word16 pitfr2, - Word16 pitmax, - Word16 pitres, - struct TransientDetection const *pTransientDetection, - Word8 SideInfoOnly, - Word16 *A, - Word16 lpcorder ) +void tcx_ltp_encode_fx( + Word16 tcxltp_on, + Word8 tcxOnly, + Word16 tcxMode, + Word16 L_frame, + Word16 L_subfr, + Word16 *speech, + Word16 *speech_ltp, + Word16 *wsp, + Word16 Top, + Word16 *ltp_param, + Word16 *ltp_bits, + Word16 *pitch_int, + Word16 *pitch_fr, + Word16 *gain, + Word16 *pitch_int_past, + Word16 *pitch_fr_past, + Word16 *gain_past, + Word16 *norm_corr_past, + Word16 last_core, + Word16 pitmin, + Word16 pitfr1, + Word16 pitfr2, + Word16 pitmax, + Word16 pitres, + TRAN_DET_HANDLE hTranDet, + Word8 SideInfoOnly, + Word16 *A, + Word16 lpcorder ) { Word16 n; Word16 norm_corr; @@ -687,11 +688,9 @@ void tcx_ltp_encode_fx( Word16 tcxltp_on, nPrevSubblocks = extract_h( L_mac( 0x17fff, NSUBBLOCKS, div_s( *pitch_int, L_frame ) ) ); nPrevSubblocks = add( s_min( nPrevSubblocks, NSUBBLOCKS ), 1 ); - tempFlatness = GetTCXAvgTemporalFlatnessMeasure_fx( pTransientDetection, NSUBBLOCKS, nPrevSubblocks ); + tempFlatness = GetTCXAvgTemporalFlatnessMeasure_fx( hTranDet, NSUBBLOCKS, nPrevSubblocks ); - maxEnergyChange = GetTCXMaxenergyChange_fx( pTransientDetection, - (const Word8) isTCX10, - NSUBBLOCKS, nPrevSubblocks ); + maxEnergyChange = GetTCXMaxenergyChange_fx( hTranDet, (const Word8) isTCX10, NSUBBLOCKS, nPrevSubblocks ); /* Switch LTP on */ test(); @@ -1059,15 +1058,13 @@ void tcx_ltp_encode_ivas_fx( IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { - tempFlatness_fx = extract_l( L_shr( GetTCXAvgTemporalFlatnessMeasure_ivas_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS - NSUBBLOCKS_SHIFT, add( nPrevSubblocks, NSUBBLOCKS_SHIFT ) ), 14 ) ); // Q7 - maxEnergyChange_fx = GetTCXMaxenergyChange_ivas_fx( st->hTranDet, (const Word8) isTCX10, - NSUBBLOCKS - NSUBBLOCKS_SHIFT, add( nPrevSubblocks, NSUBBLOCKS_SHIFT ) ); // Q3 + tempFlatness_fx = extract_l( L_shr( GetTCXAvgTemporalFlatnessMeasure_ivas_fx( st->hTranDet, NSUBBLOCKS - NSUBBLOCKS_SHIFT, add( nPrevSubblocks, NSUBBLOCKS_SHIFT ) ), 14 ) ); // Q7 + maxEnergyChange_fx = GetTCXMaxenergyChange_ivas_fx( st->hTranDet, (const Word8) isTCX10, NSUBBLOCKS - NSUBBLOCKS_SHIFT, add( nPrevSubblocks, NSUBBLOCKS_SHIFT ) ); // Q3 } ELSE { - tempFlatness_fx = extract_l( L_shr( ( GetTCXAvgTemporalFlatnessMeasure_ivas_fx( (const TransientDetection *) st->hTranDet, NSUBBLOCKS, nPrevSubblocks ) ), 14 ) ); // Q7 - maxEnergyChange_fx = GetTCXMaxenergyChange_ivas_fx( st->hTranDet, (const Word8) isTCX10, - NSUBBLOCKS, nPrevSubblocks ); // Q3 + tempFlatness_fx = extract_l( L_shr( ( GetTCXAvgTemporalFlatnessMeasure_ivas_fx( st->hTranDet, NSUBBLOCKS, nPrevSubblocks ) ), 14 ) ); // Q7 + maxEnergyChange_fx = GetTCXMaxenergyChange_ivas_fx( st->hTranDet, (const Word8) isTCX10, NSUBBLOCKS, nPrevSubblocks ); // Q3 } /* Switch LTP on */ diff --git a/lib_enc/transient_detection_fx.c b/lib_enc/transient_detection_fx.c index 1ad69a330..e0fff2da5 100644 --- a/lib_enc/transient_detection_fx.c +++ b/lib_enc/transient_detection_fx.c @@ -333,52 +333,68 @@ static void InitTCXTransientDetector( Word16 nDelay, SubblockEnergies *pSubblock /* */ /************************************************/ -void InitTransientDetection_fx( Word16 nFrameLength, - Word16 nTCXDelay, - TransientDetection *pTransientDetection ) +void InitTransientDetection_fx( + const Word16 nFrameLength, + const Word16 nTCXDelay, + TRAN_DET_HANDLE hTranDet ) { /* Init the delay buffer. */ - InitDelayBuffer( nFrameLength, nTCXDelay, &pTransientDetection->delayBuffer ); + InitDelayBuffer( nFrameLength, nTCXDelay, &hTranDet->delayBuffer ); + /* Init a subblock energies buffer used for the TCX Short/Long decision. */ - InitSubblockEnergies( nFrameLength, nTCXDelay, &pTransientDetection->delayBuffer, &pTransientDetection->subblockEnergies ); + InitSubblockEnergies( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies ); + /* Init the TCX Short/Long transient detector. */ - InitTCXTransientDetector( nTCXDelay, &pTransientDetection->subblockEnergies, &pTransientDetection->transientDetector ); + InitTCXTransientDetector( nTCXDelay, &hTranDet->subblockEnergies, &hTranDet->transientDetector ); + /* We need two past subblocks for the TCX TD and NSUBBLOCKS+1 for the temporal flatness measure FOR the TCX LTP. */ - pTransientDetection->transientDetector.pSubblockEnergies->nDelay = - add( pTransientDetection->transientDetector.pSubblockEnergies->nDelay, NSUBBLOCKS + 1 ); + hTranDet->transientDetector.pSubblockEnergies->nDelay = + add( hTranDet->transientDetector.pSubblockEnergies->nDelay, NSUBBLOCKS + 1 ); + + return; } -void InitTransientDetection_ivas_fx( Word16 nFrameLength, - Word16 nTCXDelay, - TRAN_DET_HANDLE pTransientDetection, - const Word16 ext_mem_flag ) + +void InitTransientDetection_ivas_fx( + const Word16 nFrameLength, + const Word16 nTCXDelay, + TRAN_DET_HANDLE hTranDet, + const Word16 ext_mem_flag ) { /* Init the delay buffer. */ - InitDelayBuffer( nFrameLength, nTCXDelay, &pTransientDetection->delayBuffer ); + InitDelayBuffer( nFrameLength, nTCXDelay, &hTranDet->delayBuffer ); + /* Init a subblock energies buffer used for the TCX Short/Long decision. */ - InitSubblockEnergies_ivas_fx( nFrameLength, nTCXDelay, &pTransientDetection->delayBuffer, &pTransientDetection->subblockEnergies ); + InitSubblockEnergies_ivas_fx( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies ); + /* Init the TCX Short/Long transient detector. */ - InitTransientDetector_ivas_fx( &pTransientDetection->subblockEnergies, nTCXDelay, NSUBBLOCKS, GetAttackForTCXDecision_ivas_fx, 17408 /*8.5f/(1<transientDetector ); + InitTransientDetector_ivas_fx( &hTranDet->subblockEnergies, nTCXDelay, NSUBBLOCKS, GetAttackForTCXDecision_ivas_fx, 17408 /*8.5f/(1<transientDetector ); + /* We need two past subblocks for the TCX TD and NSUBBLOCKS+1 for the temporal flatness measure FOR the TCX LTP. */ IF( ext_mem_flag ) { - pTransientDetection->transientDetector.pSubblockEnergies->nDelay = - add( pTransientDetection->transientDetector.pSubblockEnergies->nDelay, add( ( NSUBBLOCKS + 1 ), ( NSUBBLOCKS_SHIFT + 1 ) ) ); + hTranDet->transientDetector.pSubblockEnergies->nDelay = + add( hTranDet->transientDetector.pSubblockEnergies->nDelay, add( ( NSUBBLOCKS + 1 ), ( NSUBBLOCKS_SHIFT + 1 ) ) ); move16(); } ELSE { - pTransientDetection->transientDetector.pSubblockEnergies->nDelay = - add( pTransientDetection->transientDetector.pSubblockEnergies->nDelay, NSUBBLOCKS + 1 ); + hTranDet->transientDetector.pSubblockEnergies->nDelay = + add( hTranDet->transientDetector.pSubblockEnergies->nDelay, NSUBBLOCKS + 1 ); move16(); } + + return; } /** * \brief Calculate average of temporal energy change. * \return average temporal energy change with exponent = 8 */ -Word16 GetTCXAvgTemporalFlatnessMeasure_fx( struct TransientDetection const *pTransientDetection, Word16 nCurrentSubblocks, Word16 nPrevSubblocks ) +Word16 GetTCXAvgTemporalFlatnessMeasure_fx( + TRAN_DET_HANDLE hTranDet, + const Word16 nCurrentSubblocks, + const Word16 nPrevSubblocks ) { Word16 i; TransientDetector const *pTransientDetector; @@ -389,9 +405,8 @@ Word16 GetTCXAvgTemporalFlatnessMeasure_fx( struct TransientDetection const *pTr Word32 sumTempFlatness; Word16 nTotBlocks; - /* Initialization */ - pTransientDetector = &pTransientDetection->transientDetector; + pTransientDetector = &hTranDet->transientDetector; pSubblockEnergies = pTransientDetector->pSubblockEnergies; move16(); nDelay = pTransientDetector->nDelay; @@ -419,7 +434,11 @@ Word16 GetTCXAvgTemporalFlatnessMeasure_fx( struct TransientDetection const *pTr return i; } -Word32 GetTCXAvgTemporalFlatnessMeasure_ivas_fx( struct TransientDetection const *pTransientDetection, Word16 nCurrentSubblocks, Word16 nPrevSubblocks ) + +Word32 GetTCXAvgTemporalFlatnessMeasure_ivas_fx( + TRAN_DET_HANDLE hTranDet, + const Word16 nCurrentSubblocks, + const Word16 nPrevSubblocks ) { Word32 i; TransientDetector const *pTransientDetector; @@ -432,7 +451,7 @@ Word32 GetTCXAvgTemporalFlatnessMeasure_ivas_fx( struct TransientDetection const Word16 nTotBlocks, sumTempFlatness_exp, exp; /* Initialization */ - pTransientDetector = &pTransientDetection->transientDetector; + pTransientDetector = &hTranDet->transientDetector; pSubblockEnergies = pTransientDetector->pSubblockEnergies; nDelay = pTransientDetector->nDelay; move16(); @@ -464,10 +483,11 @@ Word32 GetTCXAvgTemporalFlatnessMeasure_ivas_fx( struct TransientDetection const return i; } -Word16 GetTCXMaxenergyChange_fx( struct TransientDetection const *pTransientDetection, - const Word8 isTCX10, - const Word16 nCurrentSubblocks, - const Word16 nPrevSubblocks ) +Word16 GetTCXMaxenergyChange_fx( + TRAN_DET_HANDLE hTranDet, + const Word8 isTCX10, + const Word16 nCurrentSubblocks, + const Word16 nPrevSubblocks ) { Word16 i; TransientDetector const *pTransientDetector; @@ -478,8 +498,7 @@ Word16 GetTCXMaxenergyChange_fx( struct TransientDetection const *pTransientDete Word16 maxEnergyChange; Word16 nTotBlocks; - - pTransientDetector = &pTransientDetection->transientDetector; + pTransientDetector = &hTranDet->transientDetector; pSubblockEnergies = pTransientDetector->pSubblockEnergies; move16(); nDelay = pTransientDetector->nDelay; @@ -543,10 +562,11 @@ Word16 GetTCXMaxenergyChange_fx( struct TransientDetection const *pTransientDete } -Word16 GetTCXMaxenergyChange_ivas_fx( TRAN_DET_HANDLE hTranDet, - const Word8 isTCX10, - const Word16 nCurrentSubblocks, - const Word16 nPrevSubblocks ) +Word16 GetTCXMaxenergyChange_ivas_fx( + TRAN_DET_HANDLE hTranDet, + const Word8 isTCX10, + const Word16 nCurrentSubblocks, + const Word16 nPrevSubblocks ) { Word16 i; TransientDetector const *pTransientDetector; @@ -558,7 +578,6 @@ Word16 GetTCXMaxenergyChange_ivas_fx( TRAN_DET_HANDLE hTranDet, Word16 maxEnergyChange; Word16 nTotBlocks; - pTransientDetector = &hTranDet->transientDetector; pSubblockEnergies = pTransientDetector->pSubblockEnergies; move16(); @@ -620,13 +639,17 @@ Word16 GetTCXMaxenergyChange_ivas_fx( TRAN_DET_HANDLE hTranDet, return i; } -void RunTransientDetection_fx( Word16 const *input, Word16 nSamplesAvailable, TransientDetection *pTransientDetection ) + +void RunTransientDetection_fx( + Word16 const *input, + const Word16 nSamplesAvailable, + TRAN_DET_HANDLE hTranDet ) { Word16 filteredInput[L_FRAME48k]; - SubblockEnergies *pSubblockEnergies = &pTransientDetection->subblockEnergies; - TransientDetector *pTransientDetector = &pTransientDetection->transientDetector; + SubblockEnergies *pSubblockEnergies = &hTranDet->subblockEnergies; + TransientDetector *pTransientDetector = &hTranDet->transientDetector; - assert( ( input != NULL ) && ( pTransientDetection != NULL ) && ( pSubblockEnergies != NULL ) && ( pTransientDetector != NULL ) ); + assert( ( input != NULL ) && ( hTranDet != NULL ) && ( pSubblockEnergies != NULL ) && ( pTransientDetector != NULL ) ); HighPassFilter_fx( input, nSamplesAvailable, &pSubblockEnergies->firState1, &pSubblockEnergies->firState2, filteredInput ); @@ -637,7 +660,9 @@ void RunTransientDetection_fx( Word16 const *input, Word16 nSamplesAvailable, Tr RunTransientDetector_fx( pTransientDetector ); /* Update the delay buffer. */ - UpdateDelayBuffer( filteredInput, nSamplesAvailable, &pTransientDetection->delayBuffer ); + UpdateDelayBuffer( filteredInput, nSamplesAvailable, &hTranDet->delayBuffer ); + + return; } @@ -865,7 +890,7 @@ void SetTCXModeInfo_ivas_fx( move16(); } } - tmp = BASOP_Util_Divide3232_Scale( ONE_IN_Q21, GetTCXAvgTemporalFlatnessMeasure_ivas_fx( (const TransientDetection *) hTranDet, NSUBBLOCKS, 0 ), &exp_diff ); + tmp = BASOP_Util_Divide3232_Scale( ONE_IN_Q21, GetTCXAvgTemporalFlatnessMeasure_ivas_fx( hTranDet, NSUBBLOCKS, 0 ), &exp_diff ); tmp = shl_sat( tmp, exp_diff ); // Q15 test(); IF( isLongTermTransient_fx( L_deposit_h( tmp ), &hTcxEnc->tfm_mem_fx ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) @@ -895,7 +920,7 @@ void SetTCXModeInfo_ivas_fx( *tcxModeOverlap = ALDO_WINDOW; move16(); } - tmp = BASOP_Util_Divide3232_Scale( ONE_IN_Q21, GetTCXAvgTemporalFlatnessMeasure_ivas_fx( (const TransientDetection *) hTranDet, NSUBBLOCKS, 0 ), &exp_diff ); + tmp = BASOP_Util_Divide3232_Scale( ONE_IN_Q21, GetTCXAvgTemporalFlatnessMeasure_ivas_fx( hTranDet, NSUBBLOCKS, 0 ), &exp_diff ); tmp = shl_sat( tmp, exp_diff ); // Q15 test(); IF( isLongTermTransient_fx( L_deposit_h( tmp ), &hTcxEnc->tfm_mem_fx ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) @@ -933,13 +958,14 @@ void SetTCXModeInfo_ivas_fx( } -void SetTCXModeInfo_fx( Encoder_State *st, - TransientDetection const *pTransientDetection, - Word16 *tcxModeOverlap ) +void SetTCXModeInfo_fx( + Encoder_State *st, + TRAN_DET_HANDLE hTranDet, + Word16 *tcxModeOverlap ) { TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; - assert( pTransientDetection != NULL ); + assert( hTranDet != NULL ); IF( EQ_16( st->codec_mode, MODE2 ) ) { @@ -953,7 +979,7 @@ void SetTCXModeInfo_fx( Encoder_State *st, test(); test(); test(); - IF( ( ( pTransientDetection->transientDetector.bIsAttackPresent != 0 ) || ( GT_32( Mpy_32_16_1( st->currEnergyHF_fx, 840 /*1.0f/39.0f Q15*/ ), st->prevEnergyHF_fx ) ) ) && ( ( NE_16( st->last_core, ACELP_CORE ) ) && ( NE_16( st->last_core, AMR_WB_CORE ) ) ) ) + IF( ( ( hTranDet->transientDetector.bIsAttackPresent != 0 ) || ( GT_32( Mpy_32_16_1( st->currEnergyHF_fx, 840 /*1.0f/39.0f Q15*/ ), st->prevEnergyHF_fx ) ) ) && ( ( NE_16( st->last_core, ACELP_CORE ) ) && ( NE_16( st->last_core, AMR_WB_CORE ) ) ) ) { move16(); hTcxEnc->tcxMode = TCX_10; @@ -1005,7 +1031,7 @@ void SetTCXModeInfo_fx( Encoder_State *st, IF( EQ_16( hTcxEnc->tcxMode, TCX_10 ) ) { - IF( pTransientDetection->transientDetector.attackIndex < 0 ) + IF( hTranDet->transientDetector.attackIndex < 0 ) { move16(); *tcxModeOverlap = HALF_OVERLAP; @@ -1013,7 +1039,7 @@ void SetTCXModeInfo_fx( Encoder_State *st, ELSE { move16(); - *tcxModeOverlap = s_and( pTransientDetection->transientDetector.attackIndex, 3 ); + *tcxModeOverlap = s_and( hTranDet->transientDetector.attackIndex, 3 ); if ( EQ_16( *tcxModeOverlap, 1 ) ) { move16(); @@ -1023,12 +1049,12 @@ void SetTCXModeInfo_fx( Encoder_State *st, } ELSE IF( EQ_16( hTcxEnc->tcxMode, TCX_20 ) ) { - IF( EQ_16( pTransientDetection->transientDetector.attackIndex, 7 ) ) + IF( EQ_16( hTranDet->transientDetector.attackIndex, 7 ) ) { move16(); *tcxModeOverlap = HALF_OVERLAP; } - ELSE IF( EQ_16( pTransientDetection->transientDetector.attackIndex, 6 ) ) + ELSE IF( EQ_16( hTranDet->transientDetector.attackIndex, 6 ) ) { move16(); *tcxModeOverlap = MIN_OVERLAP; -- GitLab From 683b9958baf962a5d718d9d463da2d7bb11552f3 Mon Sep 17 00:00:00 2001 From: vaclav Date: Sun, 21 Sep 2025 22:26:11 +0200 Subject: [PATCH 10/15] clang-format --- lib_enc/pre_proc_fx.c | 2 +- lib_enc/swb_tbe_enc_fx.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_enc/pre_proc_fx.c b/lib_enc/pre_proc_fx.c index 08d225f98..29a0aa229 100644 --- a/lib_enc/pre_proc_fx.c +++ b/lib_enc/pre_proc_fx.c @@ -209,7 +209,7 @@ void pre_proc_fx( /*----------------------------------------------------------------* * Change the sampling frequency to 12.8 kHz *----------------------------------------------------------------*/ - modify_Fs_fx( signal_in, input_frame, st->input_Fs, new_inp_12k8, INT_FS_12k8, st->mem_decim_fx, (const Word16) ( EQ_16( st->max_bwidth, NB ) ) ); + modify_Fs_fx( signal_in, input_frame, st->input_Fs, new_inp_12k8, INT_FS_12k8, st->mem_decim_fx, ( const Word16 )( EQ_16( st->max_bwidth, NB ) ) ); Copy( new_inp_12k8, st->buf_speech_enc + L_FRAME32k, L_FRAME ); Scale_sig( st->buf_speech_enc + L_FRAME32k, L_FRAME, 1 ); /*------------------------------------------------------------------* diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 734f09e41..927120771 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -6998,7 +6998,7 @@ static void first_VQstages_fx( dist[1] = dist_buf + maxC; move16(); - set16_fx( idx_buf, 0, (const Word16) ( 2 * stagesVQ * maxC ) ); + set16_fx( idx_buf, 0, ( const Word16 )( 2 * stagesVQ * maxC ) ); set16_fx( parents, 0, maxC ); /* Set up inital distance vector */ -- GitLab From dc58f48f0005838b3b6e5ce8403852634d0b59d5 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 1 Oct 2025 23:33:58 +0200 Subject: [PATCH 11/15] number -> macro --- lib_enc/amr_wb_enc_fx.c | 2 +- lib_enc/evs_enc_fx.c | 2 +- lib_enc/init_enc_fx.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_enc/amr_wb_enc_fx.c b/lib_enc/amr_wb_enc_fx.c index 7159b507d..787e5f701 100644 --- a/lib_enc/amr_wb_enc_fx.c +++ b/lib_enc/amr_wb_enc_fx.c @@ -108,7 +108,7 @@ void amr_wb_enc_fx( move16(); st->coder_type = GENERIC; move16(); - input_frame = extract_l( Mult_32_16( st->input_Fs, 0x0290 ) ); + input_frame = extract_l( Mpy_32_32_r( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); move16(); /* frame length of the input signal */ st->extl = -1; move16(); diff --git a/lib_enc/evs_enc_fx.c b/lib_enc/evs_enc_fx.c index 90d5a7b4b..3380583c0 100644 --- a/lib_enc/evs_enc_fx.c +++ b/lib_enc/evs_enc_fx.c @@ -100,7 +100,7 @@ ivas_error evs_enc_fx( * Initializiation *-----------------------------------------------------------------*/ - input_frame = extract_l( Mult_32_16( st->input_Fs, 0x0290 ) ); + input_frame = extract_l( Mpy_32_32_r( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); move16(); st->core = -1; move16(); diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index 0439a4720..487b42bf7 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -36,7 +36,7 @@ ivas_error init_encoder_fx( error = IVAS_ERR_OK; - input_frame = extract_l( Mult_32_16( st_fx->input_Fs, 0x0290 ) ); + input_frame = extract_l( Mpy_32_32_r( st_fx->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); /*-----------------------------------------------------------------* * General signal buffers @@ -1004,7 +1004,7 @@ ivas_error init_encoder_ivas_fx( error = IVAS_ERR_OK; move32(); - input_frame = extract_l( Mult_32_16( st->input_Fs, 0x0290 ) ); + input_frame = extract_l( Mpy_32_32_r( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); /*-----------------------------------------------------------------* * General parameters -- GitLab From 3b69eb8c5f160d97a095fef3c660d3eb77f8e1b9 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 2 Oct 2025 11:01:27 +0200 Subject: [PATCH 12/15] clang-format --- lib_com/cldfb_evs_fx.c | 4 ++-- lib_rend/lib_rend_fx.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_com/cldfb_evs_fx.c b/lib_com/cldfb_evs_fx.c index 880300896..53f9846ff 100644 --- a/lib_com/cldfb_evs_fx.c +++ b/lib_com/cldfb_evs_fx.c @@ -1003,12 +1003,12 @@ ivas_error openCldfb( IF( type == CLDFB_ANALYSIS ) { - //buf_len = sub( hs->p_filter_length, hs->no_channels ); + // buf_len = sub( hs->p_filter_length, hs->no_channels ); buf_len = STATE_BUFFER_SIZE * maxCldfbBands; } ELSE { - //buf_len = hs->p_filter_length; + // buf_len = hs->p_filter_length; buf_len = 2 * STATE_BUFFER_SIZE * maxCldfbBands; move16(); } diff --git a/lib_rend/lib_rend_fx.c b/lib_rend/lib_rend_fx.c index a6dd11fa5..57532acd2 100644 --- a/lib_rend/lib_rend_fx.c +++ b/lib_rend/lib_rend_fx.c @@ -9150,7 +9150,7 @@ static ivas_error getSamplesInternal( if ( ( error = ISAR_PRE_REND_MultiBinToSplitBinaural( hIvasRend->splitRendWrapper, hIvasRend->headRotData.headPositions[0], hIvasRend->hRendererConfig->split_rend_config.splitRendBitRate, hIvasRend->hRendererConfig->split_rend_config.codec, hIvasRend->hRendererConfig->split_rend_config.isar_frame_size_ms, hIvasRend->hRendererConfig->split_rend_config.codec_frame_size_ms, - &bits, Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, (const Word16) ( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), tmpBinaural, 1, cldfb_in_flag, ( hIvasRend->outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ? 1 : 0, ro_md_flag, Q_buff, &Q_out[0] ) ) != IVAS_ERR_OK ) + &bits, Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, ( const Word16 )( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), tmpBinaural, 1, cldfb_in_flag, ( hIvasRend->outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ? 1 : 0, ro_md_flag, Q_buff, &Q_out[0] ) ) != IVAS_ERR_OK ) { return error; } -- GitLab From 90515804617f081675cfa1e51224b9ec4ac120a1 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 2 Oct 2025 14:35:21 +0200 Subject: [PATCH 13/15] fixes --- lib_enc/core_enc_init_fx.c | 2 ++ lib_enc/init_enc_fx.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib_enc/core_enc_init_fx.c b/lib_enc/core_enc_init_fx.c index a7ffcc229..2f669f09b 100644 --- a/lib_enc/core_enc_init_fx.c +++ b/lib_enc/core_enc_init_fx.c @@ -234,6 +234,8 @@ void init_coder_ace_plus_fx( set16_fx( st->bpf_T, PIT_MIN_12k8, NB_SUBFR16k ); + st->mem_bpf_fx.lp_error = 0; + move16(); st->mem_bpf_fx.noise_shift_old = 0; move16(); diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index 81ce03c66..ea5827bf6 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -1238,7 +1238,7 @@ ivas_error init_encoder_fx( st->old_wsp_shift = 0; move16(); #ifdef DEBUGGING - st_fx->id_element = -1; /* element ID */ + st->id_element = -1; /* element ID */ move16(); #endif -- GitLab From 804b662081935f7ffb0469651ff02ed25d9a7a26 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 7 Oct 2025 11:02:30 +0200 Subject: [PATCH 14/15] fix EVS SWB-BWE encoder --- lib_enc/init_enc_fx.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index ea5827bf6..8e469a68e 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -882,8 +882,6 @@ ivas_error init_encoder_fx( } fd_bwe_enc_init_fx( st->hBWE_FD ); - st->Q_old_wtda = 0; - move16(); } ELSE { @@ -918,6 +916,15 @@ ivas_error init_encoder_fx( move16(); st->EnergyLT_fx = 0; move32(); + st->Q_old_wtda = 0; + move16(); + IF( st->element_mode == EVS_MONO ) + { + st->EnergyLT_fx = 1; + move32(); + st->Q_old_wtda = 15; + move16(); + } st->Energy_Old_fx = 0; move32(); st->TransientHangOver = 0; -- GitLab From e8f008ad07ca027a87fbe017203d5f6ff940e9c9 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 6 Nov 2025 17:53:06 +0100 Subject: [PATCH 15/15] formatting --- lib_enc/ivas_init_enc_fx.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib_enc/ivas_init_enc_fx.c b/lib_enc/ivas_init_enc_fx.c index ec0fd03db..741a78dbc 100644 --- a/lib_enc/ivas_init_enc_fx.c +++ b/lib_enc/ivas_init_enc_fx.c @@ -144,6 +144,7 @@ void ivas_write_format_fx( return; } + /*-------------------------------------------------------------------* * ivas_write_format_sid() * @@ -230,6 +231,7 @@ void ivas_write_format_sid_fx( return; } + /*-------------------------------------------------------------------* * getNumChanAnalysis() * @@ -333,13 +335,13 @@ void copy_encoder_config_fx( st_fx->force_dir = st_ivas->hEncoderConfig->force_dir; #endif #endif - st_fx->element_mode = st_ivas->hEncoderConfig->element_mode_init; /* Q0 */ move16(); return; } + /*------------------------------------------------------------------------- * ivas_initialize_handles_enc_fx() * @@ -674,6 +676,7 @@ ivas_error ivas_init_encoder_fx( { return error; } + test(); IF( EQ_16( ivas_format, SBA_FORMAT ) && st_ivas->hEncoderConfig->Opt_DTX_ON ) { @@ -747,6 +750,7 @@ ivas_error ivas_init_encoder_fx( { return error; } + IF( ( error = ivas_masa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; @@ -853,6 +857,7 @@ ivas_error ivas_init_encoder_fx( return error; } } + IF( ( error = ivas_osba_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; -- GitLab