diff --git a/lib_com/cldfb_evs_fx.c b/lib_com/cldfb_evs_fx.c index 368ce7923e560606c84f1fb665c82d573abab039..74f53f5e6aa670c3570e0d97fd591dc442da8c36 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, /* i/o: 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 */ + HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: Returns handle */ + const Word16 type, /* i : analysis or synthesis */ + 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; @@ -1374,14 +1391,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: @@ -1413,13 +1428,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 ) ) { @@ -1431,39 +1448,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]; @@ -1571,6 +1570,8 @@ cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle } BREAK; } + + return; } @@ -1581,8 +1582,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 ) @@ -1603,6 +1606,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; } @@ -1612,12 +1616,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 */ @@ -1626,7 +1632,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 ) ) { @@ -1640,12 +1645,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; @@ -1655,5 +1664,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 2ef540fe398c4983a22694bd310117c13c5b4319..e6f77e731754822ecff4b06e136afe95cf410df8 100644 --- a/lib_com/cldfb_fx.c +++ b/lib_com/cldfb_fx.c @@ -56,8 +56,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 */ @@ -72,17 +70,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*/ @@ -1327,38 +1321,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 ) ); @@ -1369,6 +1347,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(); @@ -1376,17 +1356,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; @@ -1400,17 +1383,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; @@ -1443,11 +1428,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 ) @@ -1468,19 +1455,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; @@ -1692,7 +1681,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 */ ) { @@ -1945,351 +1941,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/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index ca39a3138bba37476a01f35d7fad695b1bcf9b62..0e607039f7cb35642d8181270e953354be7d227c 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( @@ -800,10 +793,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_com/prot_fx.h b/lib_com/prot_fx.h index 2f0e059ec47a8ab08e886c3e103f9031a6261beb..7a26b7a21ef364e5920ed49085b455a78ae3dfc4 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -4800,21 +4800,19 @@ void cldfbSynthesis_fx( ); void configureCldfb( - HANDLE_CLDFB_FILTER_BANK h_cldfb, /*!< CLDFB Handle */ - const Word16 no_channels, /*!< Number of critically sampled bands */ - const Word16 frameSize /*!< FrameSize */ + HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i/o: Returns 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 */ + HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: Returns handle */ + const Word16 type, /* i : 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 ); @@ -4852,9 +4850,6 @@ void GetEnergyCldfb( Word16 *energyValuesSum_Exp, /*!< o: pointer to exponents of energyValuesSum, not initialized */ TEC_ENC_HANDLE hTECEnc ); -Word16 CLDFB_getNumChannels( - Word32 sampleRate ); - void deleteCldfb( HANDLE_CLDFB_FILTER_BANK *h_cldfb ); /*!< CLDFB Handle */ @@ -6828,11 +6823,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 */ ); @@ -7413,7 +7404,7 @@ ivas_error createFdCngDec_fx( 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( @@ -7530,12 +7521,7 @@ void generate_masking_noise_mdct_ivas_fx( 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 */ - const Word16 idchan /* i : channel ID */ -); - -ivas_error init_decoder_ivas_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 */ ); @@ -9570,7 +9556,7 @@ Word16 deindex_lvq_ivas_fx( Word16 no_bits /* i : number of bits for lattice */ ); -void deleteCldfb_ivas_fx( +void deleteCldfb_fx( HANDLE_CLDFB_FILTER_BANK *h_cldfb /* i/o: filter bank handle */ ); @@ -10438,10 +10424,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 */ @@ -10955,11 +10937,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 */ @@ -11250,15 +11227,13 @@ 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 */ +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 */ + 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_com/rom_com.h b/lib_com/rom_com.h index fd1a9221d375a241c1f1973df8e9af1f3d327240..829cf266a81106523b3f1adb4f984f0308aaded6 100644 --- a/lib_com/rom_com.h +++ b/lib_com/rom_com.h @@ -1133,7 +1133,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 5309e7ad777915352c43affb12246db259cdf68a..eab0aa77bfc2fa6e55d71c0291ea26dcd6c12e17 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -630,12 +630,14 @@ typedef struct ivas_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 */ @@ -645,16 +647,14 @@ typedef struct ivas_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 */ @@ -665,9 +665,7 @@ typedef struct ivas_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 00d6ce926a97d88692e32fce0752f5ab116279f7..513a9c692cb858f32938dfc7d77a605bfc8184b7 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 d5a3cf71a2f35b0b650407150d408758869ea412..82619a87d40cbea1a5fe59aa96f72dfbb9019bac 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/dec4t64_fx.c b/lib_dec/dec4t64_fx.c index ee6ef65a6ce3aa2b91e1020f51ad5f12405baa84..1b56c69cfdf1bf3120b326480439aa32aea65af6 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/dec_acelp_tcx_main_fx.c b/lib_dec/dec_acelp_tcx_main_fx.c index 3ff22158846d47df64e98b4e00fcaf84eb034bd9..a4f4ef77c1e8f30f46935132c55b252765a1239e 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 d0231395bfe12568540c4073b5ab68db4475bd5a..498b20acccc783dcc8702b247d6e4c3b8379ed5c 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/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 756a39e9b1d8b54f76c911ecaafeab3d8efaa845..b1e051b61660ece6b8f62090ef054510bb8b9a20 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -201,7 +201,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_dec/gs_dec_fx.c b/lib_dec/gs_dec_fx.c index a17ca6febc6d7d9d75e208bbad1b35fe0d75aa29..d174cd87bc8ee1a239450780a0411cfb8e454c4c 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 7a89118c3b041bd77316c322d945cd0f125aead9..39cc5d0658fb9e4b13387683eda6236f955ca9a7 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -1,844 +1,58 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 - ====================================================================================*/ - -#include "options.h" /* Compilation switches */ -#include "prot_fx.h" -#include "cnst.h" /* Common constants */ -#include "rom_com.h" /* Static table prototypes */ -#include "stl.h" /* required for wmc_tool */ -#include "basop_util.h" -#include "ivas_prot_fx.h" - -/*----------------------------------------------------------------------* - * init_decoder() - * - * Initialization of static variables for the decoder - *----------------------------------------------------------------------*/ - -ivas_error init_decoder_fx( - 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(); - Word16 newCldfbBands; - st_fx->total_num_bits = -1; - 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, CLDFB_getNumChannels( 48000 ), 320 ) ), 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 ) ) - { - 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 ) ) - { - 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(); - - - 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 ); - - 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(); +/****************************************************************************************************** + + (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. + +*******************************************************************************************************/ -#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(); +/*==================================================================================== + EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + ====================================================================================*/ - return error; -} +#include "options.h" /* Compilation switches */ +#include "prot_fx.h" +#include "cnst.h" /* Common constants */ +#include "rom_com.h" /* Static table prototypes */ +#include "stl.h" /* required for wmc_tool */ +#include "basop_util.h" +#include "ivas_prot_fx.h" /*----------------------------------------------------------------------* - * 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( - Decoder_State *st_fx, /* o: Decoder static variables structure */ - const Word16 idchan, /* i : channel ID */ - const MC_MODE mc_mode /* i : MC mode */ +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 */ ) { Word16 i; @@ -1072,7 +286,7 @@ ivas_error init_decoder_ivas_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 { @@ -1098,10 +312,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 ) ) @@ -1144,6 +358,7 @@ ivas_error init_decoder_ivas_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 ) ) @@ -1418,32 +633,56 @@ ivas_error init_decoder_ivas_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; @@ -1604,6 +843,7 @@ ivas_error init_decoder_ivas_fx( /*-----------------------------------------------------------------* * Mode 2 initialization *-----------------------------------------------------------------*/ + IF( ( st_fx->element_mode == EVS_MONO ) ) { IF( ( st_fx->hPlcInfo = (T_PLCInfo_HANDLE) malloc( sizeof( T_PLCInfo ) ) ) == NULL ) @@ -1628,18 +868,24 @@ ivas_error init_decoder_ivas_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; @@ -1651,11 +897,19 @@ ivas_error init_decoder_ivas_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 ) ); + } } /*-----------------------------------------------------------------* @@ -1668,7 +922,6 @@ ivas_error init_decoder_ivas_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; @@ -1740,6 +993,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 +1025,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 e91b7f8b019ea3870f92f3a80e9822050b2b6581..288cd9a0373fe7247a3cb4c3f8dbc5ea3c6df7ef 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_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index cfb6c615b1b4941cb117e88e585208d78491e3c0..3b6f9d91f42f076040467a30c11adcf5c16765ea 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -1312,7 +1312,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_init_dec_fx.c b/lib_dec/ivas_init_dec_fx.c index dff92f4e4b92fbaa66580d5f1a546857e70a8303..7359f329c43a7e9d6a5ce7aa48652fb99b3033d2 100644 --- a/lib_dec/ivas_init_dec_fx.c +++ b/lib_dec/ivas_init_dec_fx.c @@ -2963,14 +2963,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 ) { @@ -3224,7 +3217,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] ) ); } } @@ -3232,7 +3225,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_sce_dec_fx.c b/lib_dec/ivas_sce_dec_fx.c index 6e1893015fec3992e084426df2874572579b5d15..77c53c5ef63d18306328a6c065a495908be58b4f 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 76041da3972c25556d65eb30efb00b2fc0fc9bb1..8fcbf10cc138b3e04c4f4545fcc15ffa9bdb369c 100644 --- a/lib_dec/ivas_stereo_switching_dec_fx.c +++ b/lib_dec/ivas_stereo_switching_dec_fx.c @@ -158,7 +158,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 ) @@ -307,8 +307,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 ae2027e1093cc08edf740f5cce3a4bae4e0150c2..92f6cfdbd1eb838942e630f75fa47c94ce389abd 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -6112,7 +6112,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(); } @@ -6122,7 +6122,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_dec/stat_dec.h b/lib_dec/stat_dec.h index 8a8d6b09398d2b46219b6a3f740db980b33a879b..fd8f2943401014632f10409c37e9c3a4f828b02d 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*/ diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c index cdb0d4d34dcbb29a22b41875c877ba088134d278..ceaa4551467185d675b2550637d9d1ad688f7f62 100644 --- a/lib_enc/acelp_core_enc_fx.c +++ b/lib_enc/acelp_core_enc_fx.c @@ -1508,9 +1508,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 76c9930b68d67bb4fe9b5130ed14fee450a07a22..787e5f701eea596acda5b8070587c54387bf0116 100644 --- a/lib_enc/amr_wb_enc_fx.c +++ b/lib_enc/amr_wb_enc_fx.c @@ -22,9 +22,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; @@ -107,7 +108,7 @@ void amr_wb_enc_fx( move16(); st->coder_type = GENERIC; move16(); - input_frame = st->input_frame_fx; + 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(); @@ -181,7 +182,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_init_fx.c b/lib_enc/core_enc_init_fx.c index a7ffcc229c5024799f61277b983e7cb7a9046c0f..2f669f09bb13af6f7f9ef45b34e23104c62de801 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/core_enc_ol_fx.c b/lib_enc/core_enc_ol_fx.c index c26905199f00fb3652f400721a64767fe3d2fb77..716eecb15a2e29e0f932d00256fbe75cacdd34a2 100644 --- a/lib_enc/core_enc_ol_fx.c +++ b/lib_enc/core_enc_ol_fx.c @@ -247,7 +247,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 ); } diff --git a/lib_enc/core_enc_switch_fx.c b/lib_enc/core_enc_switch_fx.c index 440c02d049d133739642b664faa1f4021c7eb079..19bfd425cb8f16203de2d78eab457e6ff0936702 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 { @@ -415,7 +415,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 337e1200bc2e89648068ff2c00f556bfd7378c2a..b7cdbc99472340e7ebac0a1cdf2b67eed6018c02 100644 --- a/lib_enc/core_switching_enc_fx.c +++ b/lib_enc/core_switching_enc_fx.c @@ -44,8 +44,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*/ } @@ -199,7 +197,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 ) { @@ -484,7 +481,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(); @@ -659,8 +656,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 ); } @@ -817,8 +812,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 ) { @@ -1158,7 +1151,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 8e9a82378ad94cb3d5046e9e4943f57a63ef1be7..3380583c09d687238d218c91cd635a18e6fe4227 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( Mpy_32_32_r( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); move16(); st->core = -1; move16(); diff --git a/lib_enc/fd_cng_enc_fx.c b/lib_enc/fd_cng_enc_fx.c index 0bbbdcbd7ea7b30f7e379e0bb65d68f48999bec5..5bfb9f9acda99ee8cef452f4c0ef90af2980ff92 100644 --- a/lib_enc/fd_cng_enc_fx.c +++ b/lib_enc/fd_cng_enc_fx.c @@ -38,26 +38,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; @@ -166,9 +173,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; @@ -290,6 +299,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( @@ -427,12 +438,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(); @@ -443,6 +456,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 7a0d1a279b608c29f1064fb423549fd401e45548..76e92121bac29a2e3bbd9f1ed5c5ec0bf17beb92 100644 --- a/lib_enc/gs_enc_fx.c +++ b/lib_enc/gs_enc_fx.c @@ -1003,7 +1003,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 6d5618ee1aea0b6ec74127325ecc50d71680ec80..8e469a68eaffd436bbc9d9e92b048ed9889019c2 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -1,1055 +1,73 @@ -/*==================================================================================== - 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.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 */ - const Word16 var_SID_rate_flag, /* i : flag for variable SID update rate */ - const Word16 interval_SID /* i : interval for SID update */ -) -{ - Word16 i; - Word32 L_tmp; - Word16 idchan = 0; /* i : channel ID */ - Word16 vad_only_flag = 0; /* i : channel ID */ - move16(); - move16(); - ISM_MODE ism_mode = ISM_MODE_NONE; - ivas_error error; - - error = IVAS_ERR_OK; - - /*-----------------------------------------------------------------* - * General signal buffers - *-----------------------------------------------------------------*/ - IF( !vad_only_flag ) - { - IF( ( st_fx->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; - - /* 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; - move16(); - - 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 ) ) - { - 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 ); - } - ELSE - { - st_fx->input_fx = st_fx->input_buff_fx + st_fx->input_Fs / FRAMES_PER_SEC; - } - } - 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; - } - - /*-----------------------------------------------------------------* - * ACELP core parameters - *-----------------------------------------------------------------*/ - st_fx->last_core = -1; - move16(); - - if ( st_fx->Opt_AMR_WB ) - { - st_fx->last_core = AMR_WB_CORE; - move16(); - } - - st_fx->L_frame = L_FRAME; - move16(); - st_fx->last_coder_type = GENERIC; - move16(); - st_fx->last_total_brate = st_fx->total_brate; - move32(); - st_fx->last_total_brate_cng = -1; - move32(); - st_fx->last_core_brate = st_fx->total_brate; - move32(); - st_fx->extl = -1; - move16(); - st_fx->last_extl = -1; - move16(); - st_fx->last_L_frame = L_FRAME; - move16(); - st_fx->rate_switching_reset = 0; - move16(); - st_fx->rate_switching_reset_16kHz = 0; - move16(); - - /*-----------------------------------------------------------------* - * Bitstream - *-----------------------------------------------------------------*/ - - IF( !vad_only_flag ) - { - IF( ( st_fx->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; - } - - - 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 ); - - /*-----------------------------------------------------------------* - * 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; - } - st_fx->clas = UNVOICED_CLAS; - 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; - move16(); - st_fx->mem_preemph_enc = 0; - move16(); - - /* AVQ pre-quantizer memory */ - st_fx->mem_preemp_preQ_fx = 0; - move16(); - st_fx->mem_deemp_preQ_fx = 0; - move16(); - st_fx->last_nq_preQ = 0; - move16(); - st_fx->use_acelp_preq = 0; - move16(); - - /* (Decimated) Weighted Speech Memory */ - st_fx->mem_wsp_enc = 0; - move16(); - - st_fx->mem_wsp_fx = 0; - move16(); - st_fx->mem_wsp_q = 0; - move16(); - set32_fx( st_fx->Bin_E_fx, 0, L_FFT ); - st_fx->q_Bin_E = Q31; - 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; - move16(); - st_fx->ee_old_fx = 640; - move32(); /*chk //10 in Q6 */ - st_fx->Nb_ACELP_frames = 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; - 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(); - st_fx->old_hpfilt_out_fx = 0; - move16(); - st_fx->EnergyLT_fx = 0; - move32(); - st_fx->prev_Q_new = 0; - move16(); - - - IF( EQ_32( st_fx->input_Fs, 8000 ) ) - { - st_fx->min_band = 1; - move16(); - st_fx->max_band = 16; - move16(); - } - ELSE - { - st_fx->min_band = 0; - move16(); - st_fx->max_band = 19; - move16(); - } - IF( st_fx->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 ); - } - 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( 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 ); - - st_fx->stab_fac_fx = 0; - move16(); - /* Bass post-filter memories - encoder side of MODE2 */ - st_fx->bpf_off = 0; - move16(); - - /* TC mode */ - st_fx->tc_cnt = 0; - move16(); - st_fx->mCb1_fx = 0; - move16(); - - /* AC mode */ - - /*-----------------------------------------------------------------* - * 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->last_ener_fx = 0; - move16(); - - 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(); - - /* speech/music classifier */ - st_fx->Last_pulse_pos = 0; - move16(); - - st_fx->last_vad_spa_fx = 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(); - - - 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 - *-----------------------------------------------------------------*/ - - 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; - 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 ( ( st_fx->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 ); - } - 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 - *-----------------------------------------------------------------*/ - - 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( ( st_fx->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 ); - } - ELSE - { - st_fx->hTdCngEnc = NULL; - } - - - /*-----------------------------------------------------------------* - * ACELP LPDmem - *-----------------------------------------------------------------*/ - - 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->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 ); - } - ELSE - { - st_fx->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, CLDFB_getNumChannels( st_fx->input_Fs ), st_fx->input_frame_fx ) ) != IVAS_ERR_OK ) - { - return error; - } - - if ( ( error = openCldfb( &st_fx->cldfbSynTd, CLDFB_SYNTHESIS, CLDFB_getNumChannels( 16000 ), L_FRAME16k ) ) != IVAS_ERR_OK ) - { - return error; - } - - st_fx->energyCoreLookahead_Fx = 0; - move32(); - st_fx->sf_energyCoreLookahead_Fx = 0; - 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 - *-----------------------------------------------------------------*/ - 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 - *-----------------------------------------------------------------*/ - IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - IF( ( st_fx->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 ); - } - ELSE - { - st_fx->hBWE_FD = NULL; - } - - st_fx->prev_Q_shb = 0; - move16(); - st_fx->last_Opt_SC_VBR = 0; - move16(); - - /*-----------------------------------------------------------------* - * TBE parameters - *-----------------------------------------------------------------*/ - - IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - IF( ( st_fx->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; - // } - - InitSWBencBuffer_fx( st_fx /*st_fx->hBWE_TD*/ ); - ResetSHBbuffer_Enc_fx( st_fx /*st_fx->hBWE_TD*/ ); - } - ELSE - { - st_fx->hBWE_TD = NULL; - // st_fx->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; - } - - - /*-----------------------------------------------------------------* - * 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 ), st_fx->input_frame_fx ); - - - 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 - *-----------------------------------------------------------------*/ - - test(); - IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - IF( ( st_fx->hTcxEnc = (TCX_ENC_HANDLE) malloc( sizeof( TCX_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxEnc\n" ) ); - } - - /* 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; - - set16_fx( st_fx->hTcxEnc->old_out_fx, 0, L_FRAME32k ); - st_fx->hTcxEnc->Q_old_out = 0; - move16(); - /* MDCT selector */ - MDCT_selector_reset_fx( st_fx->hTcxEnc ); - st_fx->hTcxEnc->Q_old_out = 0; - move16(); - - /* MDCT classifier */ - MDCT_classifier_reset_fx( st_fx->hTcxEnc ); - - 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->hTcxEnc = NULL; - // st_fx->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(); - - /*-----------------------------------------------------------------* - * 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 - *-----------------------------------------------------------------*/ - - test(); - IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - IF( ( st_fx->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(); - } - - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) - { - st_fx->igf = getIgfPresent_fx( st_fx->element_mode, st_fx->total_brate, st_fx->bwidth, st_fx->rf_mode ); - } - ELSE - { - st_fx->igf = 0; - move16(); - } - - /* 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(); - 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, INV_FRAME_PER_SEC_Q15 ) ), - NS2SA_FX2( st_fx->input_Fs, DELAY_FIR_RESAMPL_NS ), - st_fx->hTranDet ); - - 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(); - st_fx->sharpFlag = 0; - move16(); - - 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() - * - * Initialization of ACELP LPDmem state variables - *-----------------------------------------------------------------------*/ - -void LPDmem_enc_init_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->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; +/****************************************************************************************************** + + (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. + +*******************************************************************************************************/ - 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; - 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(); +/*==================================================================================== + EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + ====================================================================================*/ - FOR( i = 2; i < 8; i++ ) - { - hLPDmem->dm_fx.prev_gain_pit[i - 2] = 0; - move16(); - } +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#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" - return; -} /*-----------------------------------------------------------------------* - * destroy_encoder_fx() + * init_encoder() * - * Free memory which was allocated in init_encoder_fx() + * Initialization of state variables *-----------------------------------------------------------------------*/ -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 */ - 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 */ +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 */ + 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, input_frame; ivas_error error; Word32 igf_brate; - error = IVAS_ERR_OK; - move32(); + /* input_frame = st->input_Fs / FRAMES_PER_SEC */ + input_frame = extract_l( Mpy_32_32( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + + input_frame = extract_l( Mpy_32_32_r( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); /*-----------------------------------------------------------------* * General parameters @@ -1112,8 +130,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(); @@ -1153,6 +170,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(); @@ -1163,12 +181,17 @@ 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(); - 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(); @@ -1183,14 +206,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(); @@ -1212,10 +227,13 @@ 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(); + set16_fx( st->lgBin_E_fx, 0, L_FFT / 2 ); + st->ee_old_fx = 640; /* 10.0f in Q6 */ move16(); st->Nb_ACELP_frames = 0; @@ -1226,6 +244,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(); @@ -1314,6 +334,7 @@ ivas_error init_encoder_ivas_fx( move16(); st->Q_stat_noise = 15; move16(); + /* FEC */ st->last_clas = UNVOICED_CLAS; move16(); @@ -1414,21 +435,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; - /* 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( 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 ), input_frame ); + st->old_input_signal32_fx = st->input_buff32_fx; } 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; + 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; } } ELSE @@ -1460,7 +480,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 { @@ -1518,7 +545,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; @@ -1531,7 +565,6 @@ ivas_error init_encoder_ivas_fx( st->hSpMusClas = NULL; } - /*-----------------------------------------------------------------* * WB, SWB and FB bandwidth detector *-----------------------------------------------------------------*/ @@ -1559,15 +592,19 @@ 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; move16(); st->fd_cng_reset_flag = 0; @@ -1589,7 +626,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 { @@ -1630,7 +667,7 @@ ivas_error init_encoder_ivas_fx( st->rf_mode = 0; move16(); - return error; + return IVAS_ERR_OK; } /*-----------------------------------------------------------------* @@ -1649,7 +686,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 { @@ -1659,24 +703,22 @@ ivas_error init_encoder_ivas_fx( /*-----------------------------------------------------------------* * CLDFB & resampling tools parameters *-----------------------------------------------------------------*/ + 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( EQ_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode == EVS_MONO ) { /* open analysis for input SR */ - st->input_frame_fx = extract_l( Mult_32_16( st->input_Fs, INV_FRAME_PER_SEC_Q15 ) ); - - 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; @@ -1688,10 +730,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 @@ -1715,7 +767,6 @@ ivas_error init_encoder_ivas_fx( st->last_Opt_SC_VBR = 0; move16(); - /*-----------------------------------------------------------------* * AMR-WB IO initialization *-----------------------------------------------------------------*/ @@ -1748,7 +799,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 { @@ -1794,10 +845,12 @@ 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; } + + InitSWBencBuffer_fx( st->hBWE_TD ); } ELSE { @@ -1805,9 +858,10 @@ ivas_error init_encoder_ivas_fx( { return error; } + + InitSWBencBuffer_ivas_fx( st->hBWE_TD ); } - InitSWBencBuffer_ivas_fx( st ); - ResetSHBbuffer_Enc_fx( st ); + ResetSHBbuffer_Enc_fx( st->hBWE_TD ); } ELSE { @@ -1828,14 +882,15 @@ ivas_error init_encoder_ivas_fx( } fd_bwe_enc_init_fx( st->hBWE_FD ); - st->Q_old_wtda = 0; - move16(); } ELSE { st->hBWE_FD = NULL; } + st->prev_Q_shb = 0; + move16(); + /*-----------------------------------------------------------------* * HQ core parameters *-----------------------------------------------------------------*/ @@ -1861,6 +916,15 @@ ivas_error init_encoder_ivas_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; @@ -1939,6 +1003,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; @@ -2048,7 +1113,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 ) { @@ -2068,38 +1132,34 @@ 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 = extract_l( Mult_32_16( st->input_Fs, INV_FRAME_PER_SEC_Q15 ) ); - 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 *-----------------------------------------------------------------*/ @@ -2110,8 +1170,13 @@ 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 ); + /* initialization for IVAS modes happens in first frame pre-processing */ IF( st->element_mode == EVS_MONO ) { @@ -2129,7 +1194,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 @@ -2146,15 +1211,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( Mpy_32_32_r( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - 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 ); } /*-----------------------------------------------------------------* @@ -2181,10 +1244,60 @@ ivas_error init_encoder_ivas_fx( move16(); st->old_wsp_shift = 0; move16(); - st->sharpFlag = 0; +#ifdef DEBUGGING + st->id_element = -1; /* element ID */ + move16(); +#endif + + return IVAS_ERR_OK; +} + + +/*-----------------------------------------------------------------------* + * LPDmem_enc_init() + * + * Initialization of ACELP LPDmem state variables + *-----------------------------------------------------------------------*/ + +void LPDmem_enc_init_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; 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 error; + return; } @@ -2198,8 +1311,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_corecoder_enc_reconfig_fx.c b/lib_enc/ivas_corecoder_enc_reconfig_fx.c index 019361561b527f2a72eb22c1044df820d56e0067..ce2fa0d93f35e1189ce13a0ab9f3ec2e969e49c1 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_cpe_enc_fx.c b/lib_enc/ivas_cpe_enc_fx.c index 28c2992ffb8e86842e51ed30e2ee9e73895b0963..da4bec541f247f3b787491f725af4fe4c3f760c8 100644 --- a/lib_enc/ivas_cpe_enc_fx.c +++ b/lib_enc/ivas_cpe_enc_fx.c @@ -1471,7 +1471,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_fx( st, st_ivas, n, 0, ISM_MODE_NONE, hCPE->element_brate ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_enc/ivas_init_enc_fx.c b/lib_enc/ivas_init_enc_fx.c index 6b1185b1e40dba82ffc0307eb949293da2c3f9e5..741a78dbc44bbf2dcc816c9f128e4a96edb04fa1 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() * @@ -569,11 +571,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 ) ) { @@ -672,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 ) { @@ -745,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; @@ -851,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; @@ -1041,8 +1048,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 ) @@ -1053,165 +1058,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; - } - - 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 this is only allocated in EVS mode */ - // 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; -} - - -void destroy_evs_core_enc_fx( - ENC_CORE_HANDLE hCoreCoder /* i/o: core encoder structure */ -) -{ - Word16 i; - - destroy_encoder_fx( hCoreCoder ); - - IF( hCoreCoder->hSignalBuf != NULL ) - { - free( hCoreCoder->hSignalBuf ); - hCoreCoder->hSignalBuf = NULL; - } - - 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; } @@ -1358,19 +1204,19 @@ void ivas_destroy_enc_fx( move16(); /* SCE handles */ - for ( i = 0; i < MAX_SCE; i++ ) + FOR( i = 0; i < MAX_SCE; i++ ) { - if ( st_ivas->hSCE[i] != NULL ) + 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; } } /* CPE handles */ - for ( i = 0; i < MAX_CPE; i++ ) + FOR( i = 0; i < MAX_CPE; i++ ) { - if ( st_ivas->hCPE[i] != NULL ) + IF( st_ivas->hCPE[i] != NULL ) { destroy_cpe_enc( st_ivas->hCPE[i] ); st_ivas->hCPE[i] = NULL; @@ -1378,11 +1224,11 @@ void ivas_destroy_enc_fx( } /* HP20 filter handles */ - if ( st_ivas->mem_hp20_in_fx != NULL ) + IF( st_ivas->mem_hp20_in_fx != NULL ) { n = getNumChanAnalysis_fx( st_ivas ); /* Q0 */ - for ( i = 0; i < n; i++ ) + FOR( i = 0; i < n; i++ ) { free( st_ivas->mem_hp20_in_fx[i] ); st_ivas->mem_hp20_in_fx[i] = NULL; @@ -1395,7 +1241,7 @@ void ivas_destroy_enc_fx( ivas_ism_metadata_close( st_ivas->hIsmMetaData, 0 ); /* ISM DTX Handle */ - if ( st_ivas->hISMDTX != NULL ) + IF( st_ivas->hISMDTX != NULL ) { free( st_ivas->hISMDTX ); st_ivas->hISMDTX = NULL; diff --git a/lib_enc/ivas_masa_enc_fx.c b/lib_enc/ivas_masa_enc_fx.c index 7d8a0f8354eaed50eefa768990027c5a38fe4e49..5613866ccc57e63116e7c224fcdfba71db62d480 100644 --- a/lib_enc/ivas_masa_enc_fx.c +++ b/lib_enc/ivas_masa_enc_fx.c @@ -274,7 +274,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 166bd67318dff995663cc884565ce74a3dc2bf0f..1311181dd78594bc9cfdcd78ed66741994668fd5 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 8ad20a539678a179572b2d572f72e6da7ad6a578..fa58f267479a7a380618fd19f7063b0541fa3d30 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 ) ) ) { @@ -472,12 +473,12 @@ 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, INV_FRAME_PER_SEC_Q15 ) ); - 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_fx( st, st_ivas, 0, 0, st_ivas->ism_mode, hSCE->element_brate ) ), IVAS_ERR_OK ) ) { return error; } + hSCE->hCoreCoder[0] = st; st_ivas->hSCE[sce_id] = hSCE; @@ -485,115 +486,15 @@ ivas_error create_sce_enc_fx( 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( NE_32( ( error = ivas_initialize_MD_bstr_enc_fx( &( hSCE->hMetaData ), st_ivas ) ), 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" ) ); - } - 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(); - - st_fx->input_frame_fx = extract_l( Mult_32_16( st_fx->input_Fs, INV_FRAME_PER_SEC_Q15 ) ); - 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; - } - - /*-----------------------------------------------------------------* - * 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; - - 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; @@ -602,17 +503,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 ) ); diff --git a/lib_enc/ivas_spar_encoder_fx.c b/lib_enc/ivas_spar_encoder_fx.c index 0b1f77245a19521319ec8798eb0f65bde6e2162b..1f48616d58ad6d00dca842601eb5e3c9ddf4b7bf 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_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 4375046237747b0b603012af082f673e133b9bf4..b9fc815a773208c1960749472b64519aaf6ef3a9 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 ) ) @@ -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 ) ) { @@ -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 ) { @@ -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/ivas_stereo_td_enc_fx.c b/lib_enc/ivas_stereo_td_enc_fx.c index e617e1a9ab707d744a1a3d6a97498694ba3d0812..bad9370b4c7ec575732abc5572af095b14e87bd3 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 ) { @@ -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 a242ad6792288918e0eafa5c736b8a3a863b1f55..e66342ad9b6eeca63fa65bddd8b60eee159114a3 100644 --- a/lib_enc/lib_enc_fx.c +++ b/lib_enc/lib_enc_fx.c @@ -1493,16 +1493,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/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 448a93b9ff07d372b829a09e6da8983bc9c7c4d7..5e995061569a99f74793eab34d724391f119862e 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -880,10 +880,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) */ @@ -1078,7 +1074,7 @@ void InitTransientDetection_fx( void InitTransientDetection_ivas_fx( const Word16 nFrameLength, const Word16 nTCXDelay, - TRAN_DET_HANDLE pTransientDetection, + TRAN_DET_HANDLE hTranDet, const Word16 ext_mem_flag ); /** Runs transient detection. @@ -1108,7 +1104,7 @@ void RunTransientDetection_ivas_fx( * @return average temporal flatness measure with exponent AVG_FLAT_E */ Word16 GetTCXAvgTemporalFlatnessMeasure_fx( - TRAN_DET_HANDLE hTranDetn, + TRAN_DET_HANDLE hTranDet, const Word16 nCurrentSubblocks, const Word16 nPrevSubblocks ); @@ -1913,10 +1909,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*/ @@ -1934,19 +1926,21 @@ void coder_acelp_rf_fx( 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 */ + 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 */ @@ -3630,8 +3624,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( @@ -4360,17 +4355,19 @@ 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*/ ); + Word16 E_ACELP_hh_corr( Word16 *x /*Q11*/, Word16 *y /*Qy*/, @@ -4728,26 +4725,17 @@ 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 */ - const Word16 var_SID_rate_flag, /* i : flag for variable SID update rate */ - const Word16 interval_SID /* i : interval for SID update */ -); - void copy_encoder_config_fx( Encoder_Struct *st_ivas, /* i : IVAS encoder structure */ Encoder_State *st, /* o : encoder state structure */ 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*/ - const Word16 n_samples /* i : number of i samples Q0*/ + 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*/ ); void writeLPCparam_fx( diff --git a/lib_enc/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index 38fd1726005ea31439079f1bdebb53e8d36bb85a..4f384b5750a60dff0692e05cfda3895cd02d403c 100644 --- a/lib_enc/speech_music_classif_fx.c +++ b/lib_enc/speech_music_classif_fx.c @@ -4598,7 +4598,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; @@ -4853,7 +4853,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 44125a717ff581be9d35dd2ce4b17b263ef06afb..e32333a57ce7def8e6ebf26f6acd970e9c641234 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -713,8 +713,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; @@ -808,7 +806,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 */ @@ -1012,6 +1009,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; @@ -1157,20 +1161,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; @@ -1224,6 +1225,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; @@ -1239,13 +1241,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 */ @@ -1254,9 +1255,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 */ @@ -1295,34 +1294,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 *----------------------------------------------------------------------------------*/ @@ -1333,27 +1306,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*/ @@ -1369,15 +1340,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; @@ -1386,7 +1354,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 */ @@ -1416,7 +1383,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 */ @@ -1472,7 +1438,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 @@ -1483,6 +1449,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 *----------------------------------------------------------------------------------*/ @@ -1495,8 +1463,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 */ @@ -1535,9 +1501,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 @@ -1568,7 +1531,6 @@ typedef struct enc_core_structure HQ_ENC_HANDLE hHQ_core; /* HQ core encoder handle */ - PVQ_ENC_HANDLE hPVQ; /*----------------------------------------------------------------------------------* * TD BWE parameters *----------------------------------------------------------------------------------*/ @@ -1667,7 +1629,7 @@ typedef struct enc_core_structure Word16 inv_gamma; /* Q14 */ TRAN_DET_HANDLE hTranDet; - 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 */ @@ -1766,8 +1728,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) */ @@ -1783,16 +1744,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; @@ -1806,13 +1764,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 0dc1ad698662af60efa13bf37c3ddf24066b0ef1..e89c881d2758604d2f8b42645add8f2beefda826 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -379,12 +379,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; @@ -408,15 +408,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(); @@ -466,25 +459,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; @@ -561,33 +558,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 ); @@ -618,7 +612,6 @@ void ResetSHBbuffer_Enc_fx( hBWE_TD->tbe_premph_fx = 0; move16(); - return; } @@ -760,11 +753,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(); } @@ -813,11 +806,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(); } @@ -837,12 +830,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(); } @@ -873,12 +866,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(); } @@ -898,12 +890,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++ ) @@ -956,9 +947,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 ) @@ -974,7 +965,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++ ) @@ -982,7 +973,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 ) ); @@ -993,11 +984,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, @@ -1020,8 +1009,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++ ) { @@ -1102,7 +1090,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++ ) @@ -1141,7 +1128,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. */ @@ -1190,7 +1176,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++ ) @@ -1222,7 +1207,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; @@ -1357,11 +1342,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(); } @@ -1410,11 +1395,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(); } @@ -1434,12 +1419,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(); } @@ -1470,12 +1455,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(); } @@ -1487,11 +1471,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++ ) @@ -1546,9 +1530,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 ) @@ -1573,7 +1557,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 @@ -1583,7 +1567,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(); } @@ -1597,7 +1581,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++ ) @@ -1736,7 +1720,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++ ) @@ -1866,7 +1849,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 ); @@ -1874,7 +1856,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; @@ -2367,7 +2349,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; @@ -2375,7 +2357,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 ); @@ -2396,7 +2378,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 */ @@ -2417,7 +2399,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(); @@ -2450,7 +2432,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(); } @@ -2458,12 +2440,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) */ @@ -2814,7 +2793,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; @@ -3657,7 +3636,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; @@ -3665,7 +3644,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 ); @@ -3683,7 +3662,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 */ @@ -3696,7 +3675,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 ); @@ -3748,7 +3727,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(); } @@ -4077,7 +4056,6 @@ void swb_tbe_enc_ivas_fx( } } - hBWE_TD->prev_swb_GainShape_fx = GainShape_fx[3]; move16(); @@ -4093,7 +4071,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 ) @@ -4457,7 +4434,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; @@ -7656,22 +7633,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(); } @@ -7701,6 +7679,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/transient_detection_fx.c b/lib_enc/transient_detection_fx.c index b0593456d05d7aeada3e57c854eb50b4a398e020..92ffe6863f21b8e17b388bd59de6cabebeff5751 100644 --- a/lib_enc/transient_detection_fx.c +++ b/lib_enc/transient_detection_fx.c @@ -296,7 +296,6 @@ void InitTransientDetection_fx( /* We need two past subblocks for the TCX TD and NSUBBLOCKS+1 for the temporal flatness measure FOR the TCX LTP. */ hTranDet->transientDetector.pSubblockEnergies->nDelay = add( hTranDet->transientDetector.pSubblockEnergies->nDelay, NSUBBLOCKS + 1 ); - move16(); return; } @@ -305,29 +304,32 @@ void InitTransientDetection_fx( void InitTransientDetection_ivas_fx( const Word16 nFrameLength, const Word16 nTCXDelay, - TRAN_DET_HANDLE pTransientDetection, + 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(); } @@ -432,7 +434,6 @@ Word32 GetTCXAvgTemporalFlatnessMeasure_ivas_fx( return i; } - Word16 GetTCXMaxenergyChange_fx( TRAN_DET_HANDLE hTranDet, const Word8 isTCX10, diff --git a/lib_isar/isar_splitRendererPost.c b/lib_isar/isar_splitRendererPost.c index f03afbeb8b79a4df9097257ed1f67b889301fd75..1d734bed010d765c43967abca192a3fb4144053b 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 8632b0aecf637cf4e513d38f02a98fd32d503299..c5902b3b5298eed4f62fd15cb25f4c4a4eef75c1 100644 --- a/lib_isar/isar_splitRendererPre.c +++ b/lib_isar/isar_splitRendererPre.c @@ -2655,7 +2655,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 ae32791dd8fba0c9b1fd5e492ef564bfd5e66a74..1447658a1601e839be0a7be6521f97d7bddc391c 100644 --- a/lib_isar/lib_isar_pre_rend.c +++ b/lib_isar/lib_isar_pre_rend.c @@ -203,7 +203,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; } } @@ -212,7 +212,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 37150a6da69944f8f5e14d50816bcb9ca0bf8ffc..81eb72e1dfe40274ec8ef916033f1748c771d9ae 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 144953e2672c93f199b87325e32c35ab7e9f3065..efffccf84bc6cc7195e7e2482aa38cd8e640219d 100644 --- a/lib_rend/ivas_masa_merge_fx.c +++ b/lib_rend/ivas_masa_merge_fx.c @@ -577,7 +577,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 2f607a7b33a956353a3d89d8ef82ede82edd84c7..e31241a53344115418de97f16b66cd871e70736d 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 7e73a0f605b4759938ed3c7ff8b892239a3d4497..ea4dadb73f183cb19f1089190ba8561d0d9f8928 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 b8e282d914658b815285586bea091ffa972bfe0d..299fe9b2ec5ffa6ad84d3e15ee15db337197d864 100644 --- a/lib_rend/lib_rend_fx.c +++ b/lib_rend/lib_rend_fx.c @@ -9777,7 +9777,7 @@ void IVAS_REND_closeCldfb( { IF( cldfbAna[n] != NULL ) { - deleteCldfb_ivas_fx( &( cldfbAna[n] ) ); + deleteCldfb_fx( &( cldfbAna[n] ) ); cldfbAna[n] = NULL; } } @@ -9786,7 +9786,7 @@ void IVAS_REND_closeCldfb( { IF( cldfbSyn[n] != NULL ) { - deleteCldfb_ivas_fx( &( cldfbSyn[n] ) ); + deleteCldfb_fx( &( cldfbSyn[n] ) ); cldfbSyn[n] = NULL; } } @@ -10827,7 +10827,7 @@ static void freeMasaExtRenderer( { IF( hMasaExtRend->cldfbAnaRend[i] != NULL ) { - deleteCldfb_ivas_fx( &hMasaExtRend->cldfbAnaRend[i] ); + deleteCldfb_fx( &hMasaExtRend->cldfbAnaRend[i] ); } } @@ -10835,7 +10835,7 @@ static void freeMasaExtRenderer( { IF( hMasaExtRend->cldfbSynRend[i] != NULL ) { - deleteCldfb_ivas_fx( &hMasaExtRend->cldfbSynRend[i] ); + deleteCldfb_fx( &hMasaExtRend->cldfbSynRend[i] ); } }