From 2afc0761a28c8f8ef01c0b0b9b30628a51d3975d Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 17 Apr 2025 15:49:28 +0200 Subject: [PATCH 1/3] accept REMOVE_EVS_DUPLICATES --- Workspace_msvc/lib_dec.vcxproj | 3 - Workspace_msvc/lib_dec.vcxproj.filters | 3 - lib_com/bits_alloc_fx.c | 1313 +------------------- lib_com/gs_inact_switching_fx.c | 134 +- lib_com/gs_noisefill_fx.c | 10 +- lib_com/ivas_prot_fx.h | 2 +- lib_com/lsf_tools_fx.c | 220 ++-- lib_com/options.h | 2 - lib_com/prot_fx.h | 602 +++------ lib_com/swb_tbe_com_fx.c | 235 +--- lib_dec/FEC_fx.c | 15 +- lib_dec/FEC_scale_syn_fx.c | 574 +-------- lib_dec/acelp_core_dec_fx.c | 1544 ------------------------ lib_dec/acelp_core_dec_ivas_fx.c | 107 +- lib_dec/acelp_core_switch_dec_fx.c | 12 +- lib_dec/amr_wb_dec_fx.c | 38 +- lib_dec/cng_dec_fx.c | 683 +---------- lib_dec/dec_LPD_fx.c | 4 - lib_dec/dec_ace_fx.c | 30 +- lib_dec/dec_amr_wb_fx.c | 6 +- lib_dec/dec_gen_voic_fx.c | 534 +------- lib_dec/dec_pit_exc_fx.c | 432 +------ lib_dec/dec_post_fx.c | 241 +--- lib_dec/dec_ppp_fx.c | 17 +- lib_dec/dec_tran_fx.c | 12 +- lib_dec/dec_uv_fx.c | 100 +- lib_dec/evs_dec_fx.c | 16 +- lib_dec/fd_cng_dec_fx.c | 593 +-------- lib_dec/gain_dec_fx.c | 390 +----- lib_dec/gs_dec_fx.c | 693 +---------- lib_dec/ivas_core_dec_fx.c | 2 +- lib_dec/ivas_dirac_dec_fx.c | 4 +- lib_dec/ivas_stereo_mdct_core_dec_fx.c | 4 +- lib_dec/ivas_tcx_core_dec_fx.c | 7 +- lib_dec/ivas_td_low_rate_dec_fx.c | 20 +- lib_dec/lsf_dec_fx.c | 276 +---- lib_dec/pit_dec_fx.c | 256 +--- lib_dec/post_dec_fx.c | 18 +- lib_enc/acelp_core_enc_fx.c | 40 +- lib_enc/acelp_core_switch_enc_fx.c | 37 +- lib_enc/analy_lp_fx.c | 150 +-- lib_enc/cod_ace_fx.c | 11 +- lib_enc/enc_gen_voic_fx.c | 23 +- lib_enc/enc_tran_fx.c | 15 +- lib_enc/ivas_core_pre_proc_front_fx.c | 7 +- lib_enc/ivas_core_pre_proc_fx.c | 13 +- lib_enc/ivas_front_vad_fx.c | 6 +- lib_enc/ivas_td_low_rate_enc_fx.c | 4 +- lib_enc/lsf_enc_fx.c | 7 +- lib_enc/pre_proc_fx.c | 14 +- lib_enc/prot_fx_enc.h | 104 +- lib_enc/transition_enc_fx.c | 41 +- 52 files changed, 659 insertions(+), 8965 deletions(-) delete mode 100644 lib_dec/acelp_core_dec_fx.c diff --git a/Workspace_msvc/lib_dec.vcxproj b/Workspace_msvc/lib_dec.vcxproj index 2d06d29aa..2839a5812 100644 --- a/Workspace_msvc/lib_dec.vcxproj +++ b/Workspace_msvc/lib_dec.vcxproj @@ -139,9 +139,6 @@ false - - false - diff --git a/Workspace_msvc/lib_dec.vcxproj.filters b/Workspace_msvc/lib_dec.vcxproj.filters index 8a4fc4605..ebf15bd4c 100644 --- a/Workspace_msvc/lib_dec.vcxproj.filters +++ b/Workspace_msvc/lib_dec.vcxproj.filters @@ -119,9 +119,6 @@ decoder_all_c - - decoder_all_c - decoder_all_c diff --git a/lib_com/bits_alloc_fx.c b/lib_com/bits_alloc_fx.c index e9abb7651..3bfcd0c20 100644 --- a/lib_com/bits_alloc_fx.c +++ b/lib_com/bits_alloc_fx.c @@ -434,174 +434,12 @@ static Word16 fcb_table( } /*-------------------------------------------------------------------* - * acelp_FCB_allocator() + * acelp_FCB_allocator_fx() * * Routine to allocate fixed innovation codebook bit-budget *--------------------------------------------------------------------*/ -#ifndef REMOVE_EVS_DUPLICATES -static ivas_error acelp_FCB_allocator( - Word16 *nBits, /* i/o: available bit-budget */ - Word16 fixed_cdk_index[], /* o : codebook index Q0 */ - Word16 nb_subfr, /* i : number of subframes */ - const Word16 L_subfr, /* i : subframe length */ - const Word16 coder_type, /* i : coder type */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 fix_first /* i : flag to indicate whether the first subframe bit-budget was fixed */ -) -{ - Word16 cdbk, sfr, step; - Word16 nBits_tmp; - Word16 *p_fixed_cdk_index; - Word16 max_n; - ivas_error error; - // PMT("Not floating point computation, but fixed point operator are still missing ") - - error = IVAS_ERR_OK; - move32(); - - cdbk = coder_type; /* just to avoid warning when DEBUGGING is deactivated */ - move16(); - - p_fixed_cdk_index = fixed_cdk_index; - - /* TRANSITION coding: first subframe bit-budget was already fixed, glottal pulse not in the first subframe */ - test(); - IF( GE_16( tc_subfr, L_SUBFR ) && fix_first ) - { - Word16 i; - - FOR( i = 0; i < nb_subfr; i++ ) - { - *nBits = sub( *nBits, ACELP_FIXED_CDK_BITS( fixed_cdk_index[i] ) ); - move16(); - } - return error; - } - - /* TRANSITION coding: first subframe bit-budget was already fixed, glottal pulse in the first subframe */ - sfr = 0; - move16(); - IF( fix_first ) - { - *nBits = sub( *nBits, ACELP_FIXED_CDK_BITS( fixed_cdk_index[0] ) ); - move16(); - sfr = 1; - move16(); - p_fixed_cdk_index++; - nb_subfr = 3; - move16(); - } - - /* distribute the bit-budget equally between subframes */ - IF( GT_16( L_subfr, L_SUBFR ) ) /* access fast_FCB_bits_2sfr */ - { - max_n = 6; - move16(); - } - ELSE - { - max_n = ACELP_FIXED_CDK_NB; - move16(); - } - FOR( cdbk = 0; cdbk < max_n; cdbk++ ) - { - IF( GT_32( L_mult0( fcb_table( cdbk, L_subfr ), nb_subfr ), L_deposit_l( *nBits ) ) ) - { - BREAK; - } - } - cdbk = sub( cdbk, 1 ); - -#ifdef DEBUGGING - if ( cdbk < 0 && coder_type != TRANSITION ) - { - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: Too low bit-budget for fixed innovation codebook (frame = %d). Exiting! \n" ); - } - if ( ( L_subfr == L_SUBFR && cdbk >= ACELP_FIXED_CDK_NB ) || ( L_subfr == 2 * L_SUBFR && fcb_table( cdbk, L_subfr ) == 128 /*stop value*/ ) ) - { - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: Too high bit-budget for fixed innovation codebook (frame = %d). Exiting! \n" ); - } -#endif - - set16_fx( p_fixed_cdk_index, cdbk, nb_subfr ); - nBits_tmp = 0; - move16(); - IF( cdbk >= 0 ) - { - nBits_tmp = fcb_table( cdbk, L_subfr ); - } - ELSE - { - nBits_tmp = 0; - move16(); - } - *nBits = sub( *nBits, i_mult( nBits_tmp, nb_subfr ) ); - move16(); - - /* try to increase the FCB bit-budget of the first subframe(s) */ - IF( LT_16( cdbk, ACELP_FIXED_CDK_NB - 1 ) ) - { - step = sub( fcb_table( add( cdbk, 1 ), L_subfr ), nBits_tmp ); - WHILE( *nBits >= step ) - { - ( *p_fixed_cdk_index )++; - *nBits = sub( *nBits, step ); - move16(); - p_fixed_cdk_index++; - } - - /* try to increase the FCB of the first subframe in cases when the next step is lower than the current step */ - step = sub( fcb_table( add( fixed_cdk_index[sfr], 1 ), L_subfr ), fcb_table( fixed_cdk_index[sfr], L_subfr ) ); - test(); - IF( GE_16( *nBits, step ) && cdbk >= 0 ) - { - fixed_cdk_index[sfr] = add( fixed_cdk_index[sfr], 1 ); - move16(); - *nBits = sub( *nBits, step ); - move16(); - test(); - IF( GE_16( *nBits, step ) && EQ_16( fixed_cdk_index[sfr + 1], sub( fixed_cdk_index[sfr], 1 ) ) ) - { - sfr = add( sfr, 1 ); - fixed_cdk_index[sfr] = add( fixed_cdk_index[sfr], 1 ); - move16(); - *nBits = sub( *nBits, step ); - move16(); - } - } - } - /* TRANSITION coding: allocate highest FCBQ bit-budget to the subframe with the glottal-shape codebook */ - IF( GE_16( tc_subfr, L_SUBFR ) ) - { - Word16 tempr; - - SWAP( fixed_cdk_index[0], fixed_cdk_index[tc_subfr / L_SUBFR] ); - - /* TRANSITION coding: allocate second highest FCBQ bit-budget to the last subframe */ - IF( idiv1616( tc_subfr, L_SUBFR ) < sub( nb_subfr, 1 ) ) - { - SWAP( fixed_cdk_index[( tc_subfr - L_SUBFR ) / L_SUBFR], fixed_cdk_index[nb_subfr - 1] ); - } - } - - /* when subframe length > L_SUBFR, number of bits instead of codebook index is signalled */ - IF( GT_16( L_subfr, L_SUBFR ) ) - { - Word16 i, j; - FOR( i = 0; i < nb_subfr; i++ ) - { - j = fixed_cdk_index[i]; - move16(); - fixed_cdk_index[i] = fast_FCB_bits_2sfr[j]; - move16(); - } - } - - return error; -} -#endif -static ivas_error acelp_FCB_allocator_ivas( +static ivas_error acelp_FCB_allocator_fx( Word16 *nBits, /* i/o: available bit-budget */ Word16 fixed_cdk_index[], /* o : codebook index Q0 */ Word16 nb_subfr, /* i : number of subframes */ @@ -754,1141 +592,16 @@ static ivas_error acelp_FCB_allocator_ivas( return error; } + /*-------------------------------------------------------------------* - * config_acelp1() + * config_acelp1_fx() * * Configure ACELP bit allocation * - should be in range of <6700; 24350> for ACELP@12.8kHz * - per channel bitrate minimum is 13250 kbps for ACELP@16kHz *--------------------------------------------------------------------*/ -#ifndef REMOVE_EVS_DUPLICATES -ivas_error config_acelp1( - const Word16 enc_dec, /* i : encoder/decoder flag */ - const Word32 total_brate, /* i : total bitrate */ - const Word32 core_brate_inp, /* i : core bitrate */ - const Word16 core, /* i : core */ - const Word16 extl, /* i : extension layer */ - const Word32 extl_brate, /* i : extension layer bitrate */ - const Word16 L_frame, /* i : frame length at internal Fs */ - const Word16 GSC_noisy_speech, /* i : GSC on SWB noisy speech flag */ - ACELP_config *acelp_cfg, /* i : ACELP bit-allocation */ - const Word16 signalling_bits, /* i : number of signalling bits */ - const Word16 coder_type, /* i : coder type */ - const Word16 inactive_coder_type_flag, /* i : AVQ (0) or GSC (1) IC flag */ - const Word16 tc_subfr, /* i : TC subfr ID */ - const Word16 tc_call, /* i : TC call number (0,1,2,3,5(DEC)) */ - Word16 *nBits_es_Pred, /* o : number of bits for Es_pred Q */ - Word16 *unbits, /* o : number of unused bits */ - const Word16 element_mode, /* i : element mode */ - Word16 *uc_two_stage_flag, /* o : flag undicating two-stage UC */ - const Word16 tdm_lp_reuse_flag, /* i : LPC reuse flag (can be 1 only with secondary channel */ - const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ - const Word16 idchan, /* i : stereo channel ID */ - const Word16 active_cnt, /* i : Active frame counter */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag*/ - const Word16 tdm_LRTD_flag, /* i : LRTD stereo mode flag */ - const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ -) -{ - Word16 i, bits, nb_subfr; - Word16 flag_hardcoded, coder_type_sw, fix_first; - Word32 core_brate; -#ifdef DEBUGGING - (void) active_cnt; -#endif - ivas_error error; - - error = IVAS_ERR_OK; - move32(); - // PMT("Not floating point computation, but fixed point operator are still missing ") - /*-----------------------------------------------------------------* - * Set the flag indicating two-stage Unvoiced (UC) frame - *-----------------------------------------------------------------*/ - - *uc_two_stage_flag = 0; - move16(); - IF( EQ_16( coder_type, UNVOICED ) ) - { - test(); - test(); - test(); - test(); - test(); - if ( GE_32( total_brate, MIN_UNVOICED_TWO_STAGE_BRATE ) && element_mode > EVS_MONO && ( idchan == 0 || ( ( GE_32( total_brate, 8500 ) || extl_brate == 0 ) && EQ_16( tdm_LRTD_flag, 1 ) ) ) ) - { - *uc_two_stage_flag = 1; - move16(); - } - } - - /*-----------------------------------------------------------------* - * Set the number of subframes - *-----------------------------------------------------------------*/ - - IF( EQ_16( L_frame, L_FRAME ) ) - { - nb_subfr = NB_SUBFR; - move16(); - -#ifdef DEBUGGING - if ( ( ( core_brate_inp < 5900 && coder_type > UNVOICED ) && !( core_brate_inp < MIN_TC_BRATE && coder_type == TRANSITION ) ) && !( idchan > 0 && element_mode == IVAS_CPE_TD ) && !( element_mode == IVAS_SCE && tdm_low_rate_mode ) ) - { - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: Too low bitrate (%d bps) for ACELP@12k8 in frame %d. Exiting!\n", core_brate_inp ); - } - - if ( core_brate_inp > ACELP_12k8_HIGH_LIMIT && core == ACELP_CORE ) - { - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: Too high bitrate (%d bps) for ACELP@12k8 in frame %d. Exiting!\n", core_brate_inp ); - } -#endif - } - ELSE /* L_frame == L_FRAME16k */ - { - nb_subfr = NB_SUBFR16k; - move16(); - -#ifdef DEBUGGING - if ( core_brate_inp < ACELP_16k_LOW_LIMIT && core == ACELP_CORE ) - { - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: Too low bitrate (%d bps) for ACELP@16k in frame %d. Exiting!\n", core_brate_inp ); - } -#endif - } - - coder_type_sw = coder_type; - move16(); - IF( core != ACELP_CORE ) - { - /* used in acelp_core_switch_enc() */ - nb_subfr = 1; - move16(); - if ( EQ_16( L_frame, L_FRAME ) ) - { - coder_type_sw = TRANSITION; - move16(); - } - } - - /*-----------------------------------------------------------------* - * Check if the core_brate is hard coded (to keep BE for mono core) or not - *-----------------------------------------------------------------*/ - - flag_hardcoded = 0; - move16(); - i = 0; - move16(); - - WHILE( i < SIZE_BRATE_INTERMED_TBL ) - { - IF( EQ_32( core_brate_inp, brate_intermed_tbl[i] ) ) - { - flag_hardcoded = 1; - move16(); - BREAK; - } - - IF( LT_32( core_brate_inp, brate_intermed_tbl[i] ) ) - { - flag_hardcoded = 0; - move16(); - BREAK; - } - - i = add( i, 1 ); - } - - test(); - test(); - test(); - IF( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( coder_type, AUDIO ) && - LE_32( core_brate_inp, STEREO_GSC_BIT_RATE_ALLOC ) && EQ_32( brate_intermed_tbl[i], ACELP_9k60 ) ) /* Bit allocation should be mapped to 8 kb/s instead of 9.6 kb/s in this case */ - { - i = sub( i, 1 ); - } - - core_brate = brate_intermed_tbl[i]; - move32(); - - if ( element_mode > EVS_MONO ) - { - flag_hardcoded = 0; /* use automatic and flexible ACELP bit-budget allocation */ - move16(); - } - - test(); - if ( ( core != ACELP_CORE ) && ( element_mode == EVS_MONO ) ) /* needed for mode1 core switching in EVS mono */ - { - flag_hardcoded = 1; - move16(); - } - - /*-----------------------------------------------------------------* - * ACELP bit allocation - *-----------------------------------------------------------------*/ - test(); - test(); - IF( !( EQ_16( coder_type, TRANSITION ) && NE_16( tc_subfr, -1 ) ) || EQ_16( enc_dec, DEC ) ) - { - /* Set the bit-budget */ - bits = extract_l( Mpy_32_32( core_brate_inp, ONE_BY_FRAMES_PER_SEC_Q31 ) ); // Q0 - - test(); - test(); - IF( EQ_16( coder_type, TRANSITION ) && EQ_16( enc_dec, DEC ) && EQ_16( tc_call, 1 ) ) - { - bits = add( bits, *nBits_es_Pred ); /* equalize for 4th signaling bit estimated at the encoder in TC_0_192 */ - } - - /* Subtract signalling bits */ - test(); - test(); - IF( EQ_16( enc_dec, DEC ) && EQ_16( idchan, 1 ) && element_mode > EVS_MONO ) - { - bits = sub( bits, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ); - - IF( EQ_16( tdm_LRTD_flag, 1 ) ) - { - bits = add( bits, STEREO_BITS_TCA ); - } - - /* subtract TBE/BWE flag */ - test(); - test(); - test(); - test(); - test(); - test(); - IF( extl_brate > 0 && ( EQ_16( extl, WB_TBE ) || EQ_16( extl, SWB_TBE ) || EQ_16( extl, FB_TBE ) || EQ_16( extl, WB_BWE ) || EQ_16( extl, SWB_BWE ) || EQ_16( extl, FB_BWE ) ) ) - { - bits = sub( bits, 1 ); - } - } - ELSE - { - /* Subtract signalling bits */ - bits = sub( bits, signalling_bits ); - } - - test(); - test(); - test(); - test(); - test(); - test(); - IF( extl_brate > 0 && ( EQ_16( extl, WB_TBE ) || EQ_16( extl, SWB_TBE ) || EQ_16( extl, FB_TBE ) || EQ_16( extl, WB_BWE ) || EQ_16( extl, SWB_BWE ) || EQ_16( extl, FB_BWE ) ) ) - { - /* extension layer signalling bit is counted in the extension layer bitbudget */ - bits = add( bits, 1 ); - } - - /*-----------------------------------------------------------------* - * LSF Q bit-budget - *-----------------------------------------------------------------*/ - test(); - test(); - test(); - IF( !tdm_lp_reuse_flag || idchan == 0 ) - { - /* LSF Q bit-budget */ - acelp_cfg->lsf_bits = LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx( core_brate, coder_type )]; - move16(); - - IF( !flag_hardcoded ) - { - IF( EQ_16( L_frame, L_FRAME ) ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( EQ_16( element_mode, IVAS_SCE ) && tdm_low_rate_mode ) - { - acelp_cfg->lsf_bits = LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx( core_brate, coder_type )]; - move16(); - } - ELSE IF( ( LT_32( total_brate, 7200 ) || coder_type == INACTIVE || EQ_16( coder_type, AUDIO ) ) && EQ_16( idchan, 1 ) ) - { - /* TD stereo, secondary channel: do nothing */ - acelp_cfg->lsf_bits = LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx( core_brate, coder_type )]; - move16(); - } - ELSE IF( element_mode > EVS_MONO && EQ_16( coder_type, AUDIO ) && LT_32( brate_intermed_tbl[i], ACELP_9k60 ) ) - { - /* primary channel: do nothing */ - } - ELSE IF( element_mode > EVS_MONO && EQ_16( coder_type, AUDIO ) /*&& brate_intermed_tbl[i] >= ACELP_9k60*/ ) - { - acelp_cfg->lsf_bits = 42; - move16(); - } - ELSE IF( LE_32( total_brate, 9600 ) || EQ_16( coder_type, UNVOICED ) ) - { - acelp_cfg->lsf_bits = 31; - move16(); - } - ELSE IF( LE_32( total_brate, 20000 ) ) - { - acelp_cfg->lsf_bits = 36; - move16(); - } - ELSE - { - acelp_cfg->lsf_bits = 41; - move16(); - } - } - ELSE /* L_frame == L_FRAME16k */ - { - acelp_cfg->lsf_bits = 41; - move16(); - } - } - - bits = sub( bits, acelp_cfg->lsf_bits ); - - /* mid-LSF Q bit-budget */ - acelp_cfg->mid_lsf_bits = mid_LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx( core_brate, coder_type )]; - move16(); - - test(); - if ( element_mode > EVS_MONO && EQ_16( coder_type, AUDIO ) /*&& brate_intermed_tbl[i] < ACELP_9k60*/ ) - { - acelp_cfg->mid_lsf_bits = 5; - move16(); - /* primary channel: do nothing */ - } - - bits = sub( bits, acelp_cfg->mid_lsf_bits ); - } - ELSE IF( EQ_16( tdm_lp_reuse_flag, 1 ) && EQ_16( idchan, 1 ) && NE_16( active_cnt, 1 ) ) - { - bits = sub( bits, TDM_IC_LSF_PRED_BITS ); - } - /* gain Q bit-budget - part 1: 'Es_pred' of memory-less gain Q */ - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( NE_16( coder_type, UNVOICED ) && NE_16( coder_type, AUDIO ) && coder_type != INACTIVE && !( LE_32( core_brate, ACELP_8k00 ) && NE_16( coder_type, TRANSITION ) ) ) /* mid bitrates in GC and VC, low+mid bitrates in TC */ || - ( coder_type == INACTIVE && !inactive_coder_type_flag ) /* AVQ inactive */ - ) - { - *nBits_es_Pred = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx( core_brate, coder_type, -1, -1 )]; - move16(); - bits = sub( bits, *nBits_es_Pred ); - } - ELSE IF( *uc_two_stage_flag ) - { - *nBits_es_Pred = 4; - move16(); - bits = sub( bits, *nBits_es_Pred ); - } - } - ELSE - { - bits = *unbits; - move16(); - } - - test(); - IF( EQ_16( coder_type, TRANSITION ) && tc_call == 0 ) - { - *unbits = bits; - return error; - } - - /*-----------------------------------------------------------------* - * Low-rate mode - bits are allocated in tdm_low_rate_enc() - *-----------------------------------------------------------------*/ - test(); - IF( EQ_16( element_mode, IVAS_SCE ) && tdm_low_rate_mode ) - { - acelp_cfg->FEC_mode = 0; - acelp_cfg->ltf_mode = FULL_BAND; - *nBits_es_Pred = 0; - *unbits = 0; - acelp_cfg->ubits = 0; - move16(); - move16(); - move16(); - move16(); - move16(); - - return error; - } - - /*-----------------------------------------------------------------* - * Supplementary information for FEC - *-----------------------------------------------------------------*/ - - acelp_cfg->FEC_mode = 0; - move16(); - test(); - test(); - IF( GE_32( core_brate, ACELP_11k60 ) && ( idchan == 0 || element_mode == EVS_MONO ) ) - { - acelp_cfg->FEC_mode = 1; - move16(); - - test(); - test(); - IF( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) && NE_16( coder_type, VOICED ) ) - { - bits = sub( bits, FEC_BITS_CLS ); - } - - IF( NE_16( coder_type, TRANSITION ) ) - { - IF( GE_32( total_brate, ACELP_16k40 ) ) - { - acelp_cfg->FEC_mode = 2; - move16(); - test(); - IF( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) ) - { - bits = sub( bits, FEC_BITS_ENR ); - } - } - - IF( GE_32( total_brate, ACELP_32k ) ) - { - acelp_cfg->FEC_mode = 3; - move16(); - - test(); - IF( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) ) - { - bits = sub( bits, FEC_BITS_POS ); - } - } - } - } - - /*-----------------------------------------------------------------* - * LP filtering of the adaptive excitation - *-----------------------------------------------------------------*/ - test(); - test(); - test(); - test(); - test(); - test(); - IF( idchan > 0 && element_mode > EVS_MONO ) - { - acelp_cfg->ltf_mode = FULL_BAND; - move16(); - } - ELSE IF( EQ_16( coder_type, UNVOICED ) ) - { - acelp_cfg->ltf_mode = FULL_BAND; - move16(); - } - ELSE IF( ( EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) ) && LT_32( core_brate, ACELP_11k60 ) ) - { - acelp_cfg->ltf_mode = LOW_PASS; - move16(); - } - ELSE IF( GE_32( core_brate, ACELP_11k60 ) && ( NE_16( coder_type, AUDIO ) && !( coder_type == INACTIVE && EQ_16( L_frame, L_FRAME ) ) ) ) - { - test(); - test(); - IF( coder_type == INACTIVE && EQ_16( L_frame, L_FRAME16k ) && inactive_coder_type_flag ) /* GSC Inactive @16kHz */ - { - acelp_cfg->ltf_mode = FULL_BAND; - move16(); - } - ELSE - { - acelp_cfg->ltf_mode = NORMAL_OPERATION; - move16(); - IF( coder_type != TRANSITION ) - { - bits = sub( bits, nb_subfr ); - } - } - } - ELSE - { - acelp_cfg->ltf_mode = FULL_BAND; - move16(); - } - - /*-----------------------------------------------------------------* - * UC bit-budget - *-----------------------------------------------------------------*/ - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( ( EQ_16( coder_type, UNVOICED ) && !( *uc_two_stage_flag ) ) || ( coder_type == INACTIVE && LE_32( core_brate, ACELP_9k60 ) ) ) && ( idchan == 0 || element_mode == EVS_MONO ) ) - { - bits = sub( bits, NBITS_NOISENESS ); /* noiseness */ - } - IF( EQ_16( coder_type, UNVOICED ) && !( *uc_two_stage_flag ) ) - { - bits = sub( bits, 3 * NB_SUBFR ); /* tilt factor */ - } - - /*-----------------------------------------------------------------* - * TC bit-budget - *-----------------------------------------------------------------*/ - - fix_first = 0; - move16(); - IF( EQ_16( coder_type, TRANSITION ) ) - { - if ( EQ_16( tc_call, 2 ) ) - { - fix_first = 1; - move16(); - } - - /* TC signalling */ - IF( EQ_16( L_frame, L_FRAME ) ) - { - IF( EQ_16( tc_subfr, TC_0_0 ) ) - { - IF( enc_dec == ENC ) - { - bits = sub( bits, 1 ); /* TC signalling */ - } - - IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) - { - bits = sub( bits, 3 ); /* LP filtering flag */ - } - } - ELSE IF( EQ_16( tc_subfr, TC_0_64 ) ) - { - IF( enc_dec == ENC ) - { - bits = sub( bits, 4 ); /* TC signalling */ - } - - IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) - { - bits = sub( bits, 3 ); /* LP filtering flag */ - } - } - ELSE IF( EQ_16( tc_subfr, TC_0_128 ) ) - { - IF( enc_dec == ENC ) - { - bits = sub( bits, 4 ); /* TC signalling */ - } - - IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) - { - bits = sub( bits, 2 ); /* LP filtering flag */ - } - } - ELSE IF( EQ_16( tc_subfr, TC_0_192 ) ) - { - IF( enc_dec == ENC ) - { - bits = sub( bits, 3 ); /* TC signalling */ - } - - IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) - { - bits = sub( bits, 1 ); /* LP filtering flag */ - } - } - ELSE IF( EQ_16( tc_subfr, L_SUBFR ) ) - { - IF( enc_dec == ENC ) - { - bits = sub( bits, 3 ); /* TC signalling */ - } - - IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) - { - bits = sub( bits, idiv1616( sub( L_FRAME - L_SUBFR, tc_subfr ), L_SUBFR ) ); /* LP filtering flag */ - } - } - ELSE - { - IF( enc_dec == ENC ) - { - bits = sub( bits, 4 ); /* TC signalling */ - } - - IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) - { - bits = sub( bits, idiv1616_1( sub( L_FRAME - L_SUBFR, tc_subfr ), L_SUBFR ) ); /* LP filtering flag */ - } - } - } - ELSE /* L_frame == L_FRAME16k */ - { - IF( enc_dec == ENC ) - { - IF( LE_16( tc_subfr, 2 * L_SUBFR ) ) - { - bits = sub( bits, 2 ); /* TC signalling */ - } - ELSE - { - bits = sub( bits, 3 ); /* TC signalling */ - } - } - - // bits -= ( L_FRAME16k - tc_subfr - L_SUBFR ) / L_SUBFR; /* LP filtering flag */ - bits = sub( bits, idiv1616_1( sub( L_FRAME16k - L_SUBFR, tc_subfr ), L_SUBFR ) ); /* LP filtering flag */ - } - - /* glottal-shape codebook bits */ - bits = sub( bits, 3 + 6 + 1 + 3 ); - } - - /*-----------------------------------------------------------------* - * pitch, innovation, gains bit-budget - *-----------------------------------------------------------------*/ - - acelp_cfg->fcb_mode = 0; - move16(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( tdm_low_rate_mode, 1 ) && ( coder_type != INACTIVE ) && NE_16( coder_type, UNVOICED ) ) /* GENERIC low rate mode for secondary channel */ - { - set16_fx( acelp_cfg->pitch_bits, 0, NB_SUBFR16k ); - set16_fx( acelp_cfg->gains_mode, 0, NB_SUBFR16k ); - - FOR( i = 0; i < 2; i++ ) - { - acelp_cfg->pitch_bits[i] = 0; - move16(); - IF( tdm_Pitch_reuse_flag == 0 ) - { - acelp_cfg->pitch_bits[i] = ACB_bits_tbl[BIT_ALLOC_IDX_fx( ACELP_7k20, GENERIC, i_mult( 2 * L_SUBFR, i ), TC_SUBFR2IDX_fx( tc_subfr ) )]; - move16(); - bits = sub( bits, acelp_cfg->pitch_bits[i] ); - } - acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX_fx( ACELP_7k20, GENERIC, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_fx( tc_subfr ) )]; - move16(); - bits = sub( bits, acelp_cfg->gains_mode[i] ); - } - acelp_cfg->fcb_mode = 1; - move16(); - -#ifdef DEBUGGING - if ( bits >= 55 ) - { - printf( "too much bits -> %d, LPC = %d and pitch = %d\n", bits, tdm_lp_reuse_flag, tdm_Pitch_reuse_flag ); - acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 ); - } - else -#endif - IF( GE_16( bits, 16 ) ) - { - acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 ); - } - ELSE - { - acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 ); - acelp_cfg->fixed_cdk_index[1] = -1; - move16(); - } - acelp_cfg->fixed_cdk_index[2] = -1; - move16(); - acelp_cfg->fixed_cdk_index[3] = -1; - move16(); - } - ELSE IF( ( coder_type != INACTIVE && EQ_16( nb_subfr, NB_SUBFR ) && NE_16( coder_type, AUDIO ) ) || /* @12.8kHz core except of GSC */ - ( EQ_16( nb_subfr, NB_SUBFR16k ) && ( !inactive_coder_type_flag || coder_type != INACTIVE ) ) /* @16kHz core GC, TC, AVQ inactive */ || - EQ_16( core, HQ_CORE ) /* ACELP -> HQ switching in EVS */ - ) - { - /* pitch Q & gain Q bit-budget - part 2*/ - FOR( i = 0; i < nb_subfr; i++ ) - { - IF( EQ_16( L_frame, L_FRAME ) ) - { - test(); - IF( EQ_16( tdm_Pitch_reuse_flag, 1 ) && EQ_16( idchan, 1 ) ) - { - acelp_cfg->pitch_bits[i] = 0; - move16(); - } - ELSE - { - acelp_cfg->pitch_bits[i] = ACB_bits_tbl[BIT_ALLOC_IDX_fx( core_brate, coder_type, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_fx( tc_subfr ) )]; - move16(); - } - acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX_fx( core_brate, coder_type_sw, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_fx( tc_subfr ) )]; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - test(); - IF( EQ_16( tdm_Pitch_reuse_flag, 1 ) && EQ_16( idchan, 1 ) ) - { - acelp_cfg->pitch_bits[i] = 0; - move16(); - } - ELSE - { - acelp_cfg->pitch_bits[i] = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( core_brate, coder_type, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_16KHZ_fx( tc_subfr ) )]; - move16(); - } - acelp_cfg->gains_mode[i] = gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( core_brate, coder_type_sw, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_16KHZ_fx( tc_subfr ) )]; - move16(); - } - - bits = sub( bits, acelp_cfg->pitch_bits[i] ); - - test(); - IF( coder_type == INACTIVE && EQ_16( acelp_cfg->gains_mode[i], 6 ) /* VQ vs. SQ threshold @32 kbps */ ) - { - bits = sub( bits, 5 ); - } - ELSE - { - if ( EQ_16( *uc_two_stage_flag, 1 ) ) - { - acelp_cfg->gains_mode[i] = 7; - move16(); - } - - bits = sub( bits, acelp_cfg->gains_mode[i] ); - } - } - - /* algebraic codebook bit-budget */ - test(); - test(); - test(); - test(); - test(); - test(); - IF( flag_hardcoded /* EVS */ || - ( GE_32( core_brate_inp, MIN_BRATE_AVQ_EXC ) && coder_type != INACTIVE ) /* high-birate ACELP except IC */ || - ( !inactive_coder_type_flag && coder_type == INACTIVE ) /* AVQ inactive */ ) - { - FOR( i = 0; i < nb_subfr; i++ ) - { - IF( EQ_16( L_frame, L_FRAME ) ) - { - acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX_fx( core_brate, coder_type, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_fx( tc_subfr ) )]; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - acelp_cfg->fixed_cdk_index[i] = FCB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( core_brate, coder_type, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_16KHZ_fx( tc_subfr ) )]; - move16(); - } - bits = sub( bits, acelp_cfg->fixed_cdk_index[i] ); - } - } - ELSE IF( !( EQ_16( coder_type, UNVOICED ) && EQ_16( tdm_low_rate_mode, 1 ) && EQ_16( element_mode, IVAS_CPE_TD ) ) ) - { - test(); - IF( EQ_16( coder_type, UNVOICED ) && !( *uc_two_stage_flag ) ) - { - i = idiv1616( bits, NB_SUBFR ); - IF( s_and( i, 1 ) == 0 ) - { - i = sub( i, 1 ); /* must be odd */ - } - i = s_min( i, 13 ); -#ifdef DEBUG_MODE_TD - if ( i < 0 ) - IVAS_ERROR( IVAS_ERR_INTERNAL, "ERROR::: UC negative index should not happen at frame %d\n" ); -#endif - i = s_max( i, 0 ); /* If i == 0-> random noise generator will be used as FCB */ - set16_fx( acelp_cfg->fixed_cdk_index, i, NB_SUBFR ); - bits = sub( bits, i_mult( i, NB_SUBFR ) ); - } - ELSE - { - - acelp_cfg->fcb_mode = 1; - move16(); - test(); - test(); - IF( EQ_16( element_mode, IVAS_CPE_TD ) ) - { - IF( GE_16( bits, i_mult( ACELP_FIXED_CDK_BITS( 0 ), ( nb_subfr ) ) ) ) /* enough bits for all fcb */ - { - acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); - } - ELSE IF( GE_16( bits, i_mult( ACELP_FIXED_CDK_BITS( 0 ), sub( nb_subfr, 1 ) ) ) ) - { - acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr - 1, L_SUBFR, coder_type, tc_subfr, fix_first ); - acelp_cfg->fixed_cdk_index[3] = -1; - move16(); - } - ELSE IF( GE_16( bits, i_mult( ACELP_FIXED_CDK_BITS( 0 ), sub( nb_subfr, 2 ) ) ) ) - { - acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, sub( nb_subfr, 2 ), L_SUBFR, coder_type, tc_subfr, fix_first ); - acelp_cfg->fixed_cdk_index[2] = acelp_cfg->fixed_cdk_index[1]; - move16(); - acelp_cfg->fixed_cdk_index[1] = -1; - move16(); - acelp_cfg->fixed_cdk_index[3] = -1; - move16(); - } - ELSE IF( GE_16( bits, ACELP_FIXED_CDK_BITS( 0 ) ) ) - { - acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, 1, L_SUBFR, coder_type, tc_subfr, fix_first ); - acelp_cfg->fixed_cdk_index[1] = acelp_cfg->fixed_cdk_index[0]; - move16(); - acelp_cfg->fixed_cdk_index[0] = -1; - move16(); - acelp_cfg->fixed_cdk_index[2] = -1; - move16(); - acelp_cfg->fixed_cdk_index[3] = -1; - move16(); - } - ELSE /* No FCB */ - { -#ifdef DEBUGGING - IVAS_ERROR( IVAS_ERR_INTERNAL, "WARNING!!!, No bit allocated to FCB, check frame %d\n" ); -#endif - acelp_cfg->fixed_cdk_index[0] = -1; - move16(); - acelp_cfg->fixed_cdk_index[1] = -1; - move16(); - acelp_cfg->fixed_cdk_index[2] = -1; - move16(); - acelp_cfg->fixed_cdk_index[3] = -1; - move16(); - } - } - ELSE IF( NE_16( element_mode, IVAS_CPE_TD ) && GSC_IVAS_mode > 0 && EQ_16( L_frame, L_FRAME16k ) ) - { - bits = 100; /* 9 kbps for fcb */ - move16(); - acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); - } - ELSE - { - acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); - } - } - } - - /* AVQ codebook */ - test(); - test(); - test(); - IF( ( GE_32( core_brate_inp, MIN_BRATE_AVQ_EXC ) && coder_type != INACTIVE ) /* high-birate ACELP except IC */ || - ( !inactive_coder_type_flag && coder_type == INACTIVE ) /* AVQ inactive */ ) - { - FOR( i = 0; i < nb_subfr; i++ ) - { - IF( flag_hardcoded ) - { - acelp_cfg->AVQ_cdk_bits[i] = AVQ_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( core_brate, coder_type, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_16KHZ_fx( tc_subfr ) )]; - move16(); - { - bits = sub( bits, acelp_cfg->AVQ_cdk_bits[i] ); - } - } - - bits = sub( bits, G_AVQ_BITS ); - } - - test(); - test(); - IF( GE_32( core_brate_inp, MIN_BRATE_AVQ_EXC ) && LE_32( core_brate_inp, MAX_BRATE_AVQ_EXC_TD ) && EQ_16( coder_type, GENERIC ) ) - { - /* harm. flag ACELP AVQ */ - bits = sub( bits, 1 ); - } - - IF( !flag_hardcoded ) - { - Word16 bit_tmp; - - bit_tmp = idiv1616( bits, nb_subfr ); - set16_fx( acelp_cfg->AVQ_cdk_bits, bit_tmp, nb_subfr ); - bits = sub( bits, i_mult( bit_tmp, nb_subfr ) ); - - bit_tmp = bits % nb_subfr; - move16(); - acelp_cfg->AVQ_cdk_bits[0] = add( acelp_cfg->AVQ_cdk_bits[0], bit_tmp ); - move16(); - bits = sub( bits, bit_tmp ); - } - } - } - ELSE IF( ( EQ_16( coder_type, UNVOICED ) && EQ_16( tdm_low_rate_mode, 1 ) && EQ_16( element_mode, IVAS_CPE_TD ) ) /* LBR secondary channel in TD stereo */ || - ( ( coder_type == INACTIVE || EQ_16( coder_type, AUDIO ) ) && EQ_16( nb_subfr, NB_SUBFR ) ) /* GSC @12.8kHz */ || - ( coder_type == INACTIVE && inactive_coder_type_flag ) /* AVQ inactive */ ) - { - Word32 Local_BR, Pitch_BR; - Word16 Pitch_CT; - - /* as defined at the beginning of [enc,dec]_pit_exc() */ - test(); - test(); - IF( GSC_IVAS_mode > 0 && ( GSC_noisy_speech || GT_32( core_brate, GSC_H_RATE_STG ) ) ) - { - Local_BR = ACELP_8k00; - move32(); - Pitch_CT = GENERIC; - move16(); - Pitch_BR = ACELP_8k00; - move32(); - IF( EQ_16( L_frame, L_FRAME16k ) ) - { - Local_BR = ACELP_14k80; - move32(); - test(); - if ( GSC_IVAS_mode > 0 && LT_32( core_brate, IVAS_24k4 ) ) - { - Local_BR = ACELP_9k60; - move32(); - } - Pitch_BR = core_brate; - move32(); - } - } - ELSE IF( GSC_noisy_speech ) - { - Local_BR = ACELP_7k20; - move32(); - Pitch_CT = GENERIC; - move16(); - Pitch_BR = ACELP_7k20; - move32(); - if ( EQ_16( L_frame, L_FRAME16k ) ) - { - Pitch_BR = core_brate; - move32(); - } - } - ELSE - { - Local_BR = ACELP_7k20; - move32(); - Pitch_CT = AUDIO; - move16(); - Pitch_BR = core_brate; - move32(); - - IF( EQ_16( L_frame, L_FRAME16k ) ) - { - Local_BR = ACELP_13k20; - move32(); - Pitch_CT = GENERIC; - move16(); - } - } - - FOR( i = 0; i < nb_subfr; i++ ) - { - IF( EQ_16( L_frame, L_FRAME16k ) ) - { - acelp_cfg->pitch_bits[i] = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( Pitch_BR, Pitch_CT, i_mult( i, L_SUBFR ), 0 )]; - move16(); - acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX_fx( Local_BR, LOCAL_CT, i_mult( i, L_SUBFR ), 0 )]; - move16(); - } - ELSE - { - acelp_cfg->pitch_bits[i] = ACB_bits_tbl[BIT_ALLOC_IDX_fx( Pitch_BR, Pitch_CT, i_mult( i, L_SUBFR ), 0 )]; - move16(); - acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX_fx( Local_BR, LOCAL_CT, i_mult( i, L_SUBFR ), 0 )]; - move16(); - acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX_fx( ACELP_7k20, LOCAL_CT, i_mult( i, L_SUBFR ), 0 )]; - move16(); - } - } - } - - test(); - test(); - test(); - IF( EQ_16( coder_type, TRANSITION ) && ( EQ_16( tc_call, 1 ) && tc_subfr == 0 && EQ_16( L_frame, L_FRAME ) ) ) - { - return error; - } - - /*-----------------------------------------------------------------* - * unused bits handling - *-----------------------------------------------------------------*/ - - acelp_cfg->ubits = 0; /* these bits could be reused for something else */ - move16(); - - test(); - IF( flag_hardcoded && NE_32( core_brate, PPP_NELP_2k80 ) ) - { - test(); - test(); - /* unused bits */ - IF( EQ_16( coder_type, AUDIO ) || ( coder_type == INACTIVE && LE_32( core_brate, ACELP_24k40 ) ) ) - { - acelp_cfg->ubits = 0; - move16(); - } - ELSE IF( EQ_16( L_frame, L_FRAME ) ) - { - acelp_cfg->ubits = reserved_bits_tbl[BIT_ALLOC_IDX_fx( core_brate, coder_type, -1, TC_SUBFR2IDX_fx( tc_subfr ) )]; - move16(); - } - ELSE - { - acelp_cfg->ubits = 0; - move16(); - } - - bits = sub( bits, acelp_cfg->ubits ); - } - - /* sanity check */ - test(); - test(); - test(); - IF( ( coder_type != INACTIVE && EQ_16( nb_subfr, NB_SUBFR ) && NE_16( coder_type, AUDIO ) ) || EQ_16( nb_subfr, NB_SUBFR16k ) ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( EQ_16( L_frame, L_FRAME16k ) && coder_type == INACTIVE && inactive_coder_type_flag ) /* GSC Inactive @16kHz */ || - ( GSC_IVAS_mode > 0 && EQ_16( L_frame, L_FRAME16k ) ) ) /* IVAS GSC @16kHz */ - { - acelp_cfg->ubits = 0; - move16(); - } - ELSE IF( flag_hardcoded && core == ACELP_CORE && bits != 0 ) - { -#ifdef DEBUGGING - IVAS_ERROR( IVAS_ERR_INTERNAL, "ERROR: bit-budget incorrect (%d bits) in frame %d.\n", (Word32) bits ); -#endif - } - ELSE IF( bits > 0 && !( EQ_16( coder_type, UNVOICED ) && EQ_16( tdm_low_rate_mode, 1 ) && EQ_16( element_mode, IVAS_CPE_TD ) ) ) - { - test(); - test(); - test(); - test(); - IF( idchan > 0 && EQ_16( element_mode, IVAS_CPE_TD ) ) - { - IF( !tdm_lp_reuse_flag ) - { - acelp_cfg->lsf_bits = add( acelp_cfg->lsf_bits, bits ); /* increase LSF Q bits */ - move16(); - bits = 0; - move16(); - } - ELSE - { - Word16 nb_prm = 4; - move16(); - if ( EQ_16( tdm_low_rate_mode, 1 ) ) - { - nb_prm = 2; - move16(); - } - /* First add remaining bits on gains */ - bits = sub( bits, allocate_unused( core_brate, coder_type, bits, nb_prm, 0, GAINSPRM, acelp_cfg->gains_mode ) ); - - /* Then, Increase pitch bit budget */ - test(); - IF( tdm_Pitch_reuse_flag == 0 && bits > 0 ) - { - bits = sub( bits, allocate_unused( core_brate, coder_type, bits, nb_prm, 0, PITCHPRM, acelp_cfg->pitch_bits ) ); - } - - /* Increase mid-lsf bit budget */ - test(); - IF( tdm_lp_reuse_flag == 0 && bits > 0 ) - { - bits = sub( bits, allocate_unused( core_brate, coder_type, bits, 1, 0, MID_LSFSPRM, &acelp_cfg->mid_lsf_bits ) ); - bits = sub( bits, allocate_unused( core_brate, coder_type, bits, 1, 0, LSFPRM, &acelp_cfg->lsf_bits ) ); - } - } - -#ifdef DEBUGGING - if ( idchan > 0 && bits > 0 && ( coder_type > UNVOICED || tdm_low_rate_mode == 0 ) ) - { - IVAS_ERROR( IVAS_ERR_INTERNAL, "WARNING !! Unused bits in secondary channel at frame %d\n" ); - } -#endif - } - - ELSE IF( core == ACELP_CORE && GE_16( coder_type, UNVOICED ) && LE_16( coder_type, GENERIC ) && EQ_16( L_frame, L_FRAME ) ) - { - acelp_cfg->lsf_bits = add( acelp_cfg->lsf_bits, bits ); /* increase LSF Q bits */ - move16(); - - test(); - IF( GT_16( acelp_cfg->lsf_bits, 46 ) ) - { - acelp_cfg->ubits = sub( acelp_cfg->lsf_bits, 46 ); - move16(); - acelp_cfg->lsf_bits = 46; - move16(); - } - ELSE IF( GT_16( acelp_cfg->lsf_bits, 42 ) && EQ_16( L_frame, L_FRAME ) ) - { - acelp_cfg->ubits = sub( acelp_cfg->lsf_bits, 42 ); - move16(); - acelp_cfg->lsf_bits = 42; - move16(); - } - } - ELSE - { - acelp_cfg->ubits = bits; - move16(); - } - } - ELSE IF( bits < 0 && !( EQ_16( coder_type, UNVOICED ) && EQ_16( tdm_low_rate_mode, 1 ) && EQ_16( element_mode, IVAS_CPE_TD ) ) ) - { -#ifdef DEBUGGING - IVAS_ERROR( IVAS_ERR_INTERNAL, "ERROR: bit-budget incorrect (%d bits) in frame %d.\n", (Word32) bits ); -#endif - } - } - - return error; -} - -/*-------------------------------------------------------------------* - * config_acelp1_IVAS() - * - * Configure ACELP bit allocation - * - should be in range of <6700; 24350> for ACELP@12.8kHz - * - per channel bitrate minimum is 13250 kbps for ACELP@16kHz - *--------------------------------------------------------------------*/ -#endif -ivas_error config_acelp1_IVAS( +ivas_error config_acelp1_fx( const Word16 enc_dec, /* i : encoder/decoder flag */ const Word32 total_brate, /* i : total bitrate */ const Word32 core_brate_inp, /* i : core bitrate */ @@ -2511,11 +1224,11 @@ ivas_error config_acelp1_IVAS( IF( GE_16( bits, 16 ) ) { - acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 ); + acelp_FCB_allocator_fx( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 ); } ELSE { - acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 ); + acelp_FCB_allocator_fx( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 ); acelp_cfg->fixed_cdk_index[1] = -1; move16(); } @@ -2634,17 +1347,17 @@ ivas_error config_acelp1_IVAS( { IF( GE_16( bits, imult1616( ACELP_FIXED_CDK_BITS( 0 ), nb_subfr ) ) ) /* enough bits for all fcb */ { - acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); + acelp_FCB_allocator_fx( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); } ELSE IF( GE_16( bits, imult1616( ACELP_FIXED_CDK_BITS( 0 ), sub( nb_subfr, 1 ) ) ) ) { - acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, sub( nb_subfr, 1 ), L_SUBFR, coder_type, tc_subfr, fix_first ); + acelp_FCB_allocator_fx( &bits, acelp_cfg->fixed_cdk_index, sub( nb_subfr, 1 ), L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_cfg->fixed_cdk_index[3] = -1; move16(); } ELSE IF( GE_32( bits, imult1616( ACELP_FIXED_CDK_BITS( 0 ), sub( nb_subfr, 2 ) ) ) ) { - acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, sub( nb_subfr, 2 ), L_SUBFR, coder_type, tc_subfr, fix_first ); + acelp_FCB_allocator_fx( &bits, acelp_cfg->fixed_cdk_index, sub( nb_subfr, 2 ), L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_cfg->fixed_cdk_index[2] = acelp_cfg->fixed_cdk_index[1]; move16(); acelp_cfg->fixed_cdk_index[1] = -1; @@ -2654,7 +1367,7 @@ ivas_error config_acelp1_IVAS( } ELSE IF( GE_32( bits, ACELP_FIXED_CDK_BITS( 0 ) ) ) { - acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, 1, L_SUBFR, coder_type, tc_subfr, fix_first ); + acelp_FCB_allocator_fx( &bits, acelp_cfg->fixed_cdk_index, 1, L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_cfg->fixed_cdk_index[1] = acelp_cfg->fixed_cdk_index[0]; move16(); acelp_cfg->fixed_cdk_index[0] = -1; @@ -2680,11 +1393,11 @@ ivas_error config_acelp1_IVAS( { bits = 100; /* 9 kbps for fcb */ move16(); - acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); + acelp_FCB_allocator_fx( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); } ELSE { - acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); + acelp_FCB_allocator_fx( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); } } } diff --git a/lib_com/gs_inact_switching_fx.c b/lib_com/gs_inact_switching_fx.c index 582fd3c8a..119811275 100644 --- a/lib_com/gs_inact_switching_fx.c +++ b/lib_com/gs_inact_switching_fx.c @@ -33,144 +33,24 @@ /*------------------------------------------------------------------------*/ /* OUTPUT ARGUMENTS : */ /*------------------------------------------------------------------------*/ - /*------------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ /* _ None */ /*========================================================================*/ -#ifndef REMOVE_EVS_DUPLICATES -void Inac_swtch_ematch_fx( - Word16 exc2[], /* i/o: CELP/GSC excitation buffer Q_exc*/ - Word16 dct_exc_tmp[], /* i : GSC excitation in DCT domain */ - Word16 lt_ener_per_band[], /* i/o: Long term energy per band Q12 */ - const Word16 coder_type, /* i : Coding mode */ - const Word16 L_frame, /* i : Frame lenght */ - const Word32 core_brate, /* i : Core bit rate */ - const Word16 Q_exc /* i : input and output format of exc2 */ - , - const Word16 bfi /* i : frame lost indicator */ - , - const Word16 last_core, /* i : Last core used */ - const Word16 last_codec_mode /* i : Last codec mode */ -) -{ - Word16 Ener_per_bd[MBANDS_GN]; - Word16 ftmp; - Word16 *pt_exc; - Word16 j, i; - - Word16 exp, frac; - Word32 L_tmp; - - /*-------------------------------------------------------------------------- - * average energy per band - *--------------------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - test(); - test(); - IF( EQ_16( coder_type, AUDIO ) && bfi == 0 ) - { - Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1 ); - - /* reset long-term energy per band */ - FOR( i = 0; i < MBANDS_GN; i++ ) - { - lt_ener_per_band[i] = Ener_per_bd[i]; - move16(); - } - } - ELSE IF( EQ_16( coder_type, VOICED ) || EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) || ( last_core != ACELP_CORE ) || NE_16( last_codec_mode, MODE1 ) ) - { - /* Find spectrum and energy per band for GC and VC frames */ - edct_16fx( exc2, dct_exc_tmp, L_frame, 5, EVS_MONO ); - - Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1 ); - - /* reset long-term energy per band */ - FOR( i = 0; i < MBANDS_GN; i++ ) - { - lt_ener_per_band[i] = Ener_per_bd[i]; - move16(); - } - } - ELSE IF( ( coder_type == INACTIVE ) && LE_32( core_brate, ACELP_24k40 ) ) - { - /* Find spectrum and energy per band for inactive frames */ - edct_16fx( exc2, dct_exc_tmp, L_frame, 5, EVS_MONO ); - Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1 ); - - /* More agressive smoothing in the first 50 frames */ - pt_exc = dct_exc_tmp; - move16(); - FOR( i = 0; i < MBANDS_GN; i++ ) - { - /* Compute smoothing gain to apply with gain limitation */ - L_tmp = L_mult( ALPHA0_FX, lt_ener_per_band[i] ); /*Q(15+12+1)=Q(28) */ - L_tmp = L_mac( L_tmp, BETA0_FX, Ener_per_bd[i] ); /*Q28 */ - lt_ener_per_band[i] = round_fx( L_tmp ); /*Q12 */ - move16(); - - ftmp = sub( lt_ener_per_band[i], Ener_per_bd[i] ); /*Q12 */ - - /* ftmp = (float)pow(10, ftmp);= pow(2,3.321928*ftmp);*/ - - L_tmp = L_mult( 27213, ftmp ); /*Q(13+12+1)=Q26 ; 27213=3.321928 in Q13 */ - L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of ftmp */ - ftmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - - exp = sub( exp, 14 ); - IF( LT_16( i, 2 ) ) - { - FOR( j = 0; j < 8; j++ ) - { - L_tmp = L_mult( *pt_exc, ftmp ); /* Q_exc*Q0 -> Q(Q_exc+1) */ - L_tmp = L_shl_sat( L_tmp, add( exp, 15 ) ); /* Q(Q_exc+1) -> Q(16+Q_exc)*/ - *pt_exc = round_fx_sat( L_tmp ); - move16(); - pt_exc++; - } - } - ELSE - { - FOR( j = 0; j < 16; j++ ) - { - L_tmp = L_mult( *pt_exc, ftmp ); /* Q_exc*Q0 -> Q(Q_exc+1) */ - L_tmp = L_shl_sat( L_tmp, add( exp, 15 ) ); /* Q(Q_exc+1) -> Q(16+Q_exc)*/ - *pt_exc = round_fx_sat( L_tmp ); /*Q_exc*/ - move16(); - pt_exc++; - } - } - } - - /* Going back to time */ - edct_16fx( dct_exc_tmp, exc2, L_frame, 5, EVS_MONO ); - } - - return; -} -#endif -void Inac_switch_ematch_ivas_fx( +void Inac_switch_ematch_fx( Word16 exc2[], /* i/o: CELP/GSC excitation buffer Q_exc*/ Word16 dct_exc_tmp[], /* i : GSC excitation in DCT domain */ Word16 lt_ener_per_band[], /* i/o: Long term energy per band Q12 */ const Word16 coder_type, /* i : Coding mode */ - const Word16 inactive_coder_type_flag, /* i : AVQ (0) or GSC (1) IC flag */ + const Word16 inactive_coder_type_flag, /* i : AVQ (0) or GSC (1) IC flag */ const Word16 L_frame, /* i : Frame lenght */ const Word16 Q_exc, /* i : input and output format of exc2 */ const Word16 bfi, /* i : frame lost indicator */ const Word16 last_core, /* i : Last core used */ const Word16 last_codec_mode, /* i : Last codec mode */ - const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag*/ - const Word16 element_mode /* i : element mode */ + const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ + const Word16 element_mode /* i : element mode */ ) { Word16 Ener_per_bd[MBANDS_GN16k]; @@ -251,7 +131,6 @@ void Inac_switch_ematch_ivas_fx( exp = sub( exp, 14 ); IF( LT_16( i, 2 ) ) { -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( element_mode, EVS_MONO ) ) { FOR( j = 0; j < 8; j++ ) @@ -264,7 +143,6 @@ void Inac_switch_ematch_ivas_fx( } } ELSE -#endif { FOR( j = 0; j < 8; j++ ) { @@ -278,7 +156,6 @@ void Inac_switch_ematch_ivas_fx( } ELSE { -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( element_mode, EVS_MONO ) ) { FOR( j = 0; j < 16; j++ ) @@ -291,7 +168,6 @@ void Inac_switch_ematch_ivas_fx( } } ELSE -#endif { FOR( j = 0; j < 16; j++ ) { @@ -306,9 +182,7 @@ void Inac_switch_ematch_ivas_fx( } /* Going back to time */ -#ifdef REMOVE_EVS_DUPLICATES IF( GT_16( element_mode, EVS_MONO ) ) -#endif { Scale_sig( dct_exc_tmp, 240, 1 ); // Q_exc Scale_sig( exc2, 240, 1 ); // Q_exc diff --git a/lib_com/gs_noisefill_fx.c b/lib_com/gs_noisefill_fx.c index 61aa1333c..8488851ac 100644 --- a/lib_com/gs_noisefill_fx.c +++ b/lib_com/gs_noisefill_fx.c @@ -1332,8 +1332,6 @@ void highband_exc_dct_in_ivas_fx( } } - -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( element_mode, EVS_MONO ) ) { Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Qexc_diffQ, *Q_exc ); @@ -1346,7 +1344,6 @@ void highband_exc_dct_in_ivas_fx( } ELSE { -#endif Word16 Q_tmp = *Q_exc; move16(); Word16 Q_old = *Q_exc; @@ -1373,9 +1370,7 @@ void highband_exc_dct_in_ivas_fx( { Scale_sig( exc_dct_in, L_frame, sub( *Q_exc, Q_old ) ); } -#ifdef REMOVE_EVS_DUPLICATES } -#endif /*--------------------------------------------------------------------------------------* * add the correction layer to the LF bins, @@ -1416,12 +1411,9 @@ void highband_exc_dct_in_ivas_fx( Q_hb_exc = 0; move16(); envelop_modify_fx( exc_diffQ, seed_tcx, last_bin, Ener_per_bd_iQ, *Q_exc, &Q_hb_exc ); -#ifdef REMOVE_EVS_DUPLICATES + test(); IF( GT_16( *Q_exc, Q_hb_exc ) && GT_16( element_mode, EVS_MONO ) ) -#else - IF( GT_16( *Q_exc, Q_hb_exc ) ) -#endif { Scale_sig( exc_wo_nf, L_frame, sub( Q_hb_exc, *Q_exc ) ); *Q_exc = Q_hb_exc; diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 8da9cd9ac..34c5df3af 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -3967,7 +3967,7 @@ ivas_error ivas_core_dec_fx( const Word16 sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ ); -void decod_gen_2sbfr_ivas_fx( +void decod_gen_2sbfr_fx( Decoder_State *st, /* i/o: decoder static memory */ const Word16 sharpFlag, /* i : formant sharpening flag `Q0*/ const Word16 *Aq, /* i : LP filter coefficient Q12*/ diff --git a/lib_com/lsf_tools_fx.c b/lib_com/lsf_tools_fx.c index 5f0b3b57b..a7713b48c 100644 --- a/lib_com/lsf_tools_fx.c +++ b/lib_com/lsf_tools_fx.c @@ -2863,40 +2863,39 @@ Word16 qlsf_ARSN_tcvq_Dec_16k_fx( } /*======================================================================*/ -/* FUNCTION : lsf_syn_mem_backup_fx */ +/* FUNCTION : lsf_syn_mem_backup_fx */ /*----------------------------------------------------------------------*/ /* PURPOSE : back-up synthesis filter memory and LSF qunatizer memories */ /*----------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16*) lsp_new : LSP vector to quantize */ -/* _ (Word16*) lsf_new : quantized LSF vector */ -/* _ (Word16*) lsp_mid : mid-frame LSP vector */ -/* _ (Encoder_State) st_fx : Encoder state Structure */ -/*-----------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _None */ -/*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16) clip_var : pitch clipping state var */ -/* _ (Word16*) mem_AR : quantizer memory for AR model */ -/* _ (Word16*) mem_MA : quantizer memory for MA model */ -/* _ (Word16*) lsp_new_bck : LSP vector to quantize- backup */ -/* _ (Word16*) lsf_new_bck : quantized LSF vector - backup */ -/* _ (Word16*) lsp_mid_bck : mid-frame LSP vector - backup */ +/* INPUT ARGUMENTS : */ +/* _ (Word16*) lsp_new : LSP vector to quantize */ +/* _ (Word16*) lsf_new : quantized LSF vector */ +/* _ (Word16*) lsp_mid : mid-frame LSP vector */ +/* _ (Encoder_State) st_fx : Encoder state Structure */ +/*----------------------------------------------------------------------*/ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _None */ +/*----------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16) clip_var : pitch clipping state var */ +/* _ (Word16*) mem_AR : quantizer memory for AR model */ +/* _ (Word16*) mem_MA : quantizer memory for MA model */ +/* _ (Word16*) lsp_new_bck : LSP vector to quantize- backup */ +/* _ (Word16*) lsf_new_bck : quantized LSF vector - backup */ +/* _ (Word16*) lsp_mid_bck : mid-frame LSP vector - backup */ /* _ (Word16) mCb1 :counter for stationary frame after a transition frame */ -/* _ (Word32*) Bin_E : FFT Bin energy 128 *2 sets */ -/* _ (Word32*) Bin_E_old : FFT Bin energy 128 *2 sets */ -/* _ (Word16*) mem_syn_bck : synthesis filter memory */ -/* _ (Word16) mem_w0_bck : memory of the weighting filter */ -/* _ (Word16) streaklimit : LSF quantizer */ -/* _ (Word16) pstreaklen : LSF quantizer */ -/*-----------------------------------------------------------------------*/ - -/* _ None */ -/*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*=======================================================================*/ +/* _ (Word32*) Bin_E : FFT Bin energy 128 *2 sets */ +/* _ (Word32*) Bin_E_old : FFT Bin energy 128 *2 sets */ +/* _ (Word16*) mem_syn_bck : synthesis filter memory */ +/* _ (Word16) mem_w0_bck : memory of the weighting filter */ +/* _ (Word16) streaklimit : LSF quantizer */ +/* _ (Word16) pstreaklen : LSF quantizer */ +/*----------------------------------------------------------------------*/ +/* _ None */ +/*----------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ None */ +/*======================================================================*/ void lsf_syn_mem_backup_fx( Encoder_State *st_fx, /* o: state structure */ @@ -2904,23 +2903,22 @@ void lsf_syn_mem_backup_fx( Word32 *gc_threshold_fx, /* i: Q16 */ Word16 *clip_var_bck_fx, /* i: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ Word16 *next_force_sf_bck_fx, /* i: */ - - Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ - Word16 *lsf_new, /* i: quantized LSF vector Q15 */ - Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ - Word16 *clip_var, /* i: pitch clipping state var Q(2.56) */ - Word16 *mem_AR, /* i: quantizer memory for AR model 2.56 */ - Word16 *mem_MA, /* i: quantizer memory for MA model 2.56 */ - Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ - Word16 *lsf_new_bck, /* o: quantized LSF vector - backup Q15 */ - Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ - Word16 *mCb1, /* o: counter for stationary frame after a transition frame */ - Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets q_bin */ - Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets q_bin */ - Word16 *mem_syn_bck, /* i: synthesis filter memory q */ - Word16 *mem_w0_bck, /* i: memory of the weighting filter q */ - Word16 *streaklimit, /* i:LSF quantizer Q15 */ - Word16 *pstreaklen /* i:LSF quantizer */ + Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ + Word16 *lsf_new, /* i: quantized LSF vector Q15 */ + Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ + Word16 *clip_var, /* i: pitch clipping state var Q(2.56) */ + Word16 *mem_AR, /* i: quantizer memory for AR model 2.56 */ + Word16 *mem_MA, /* i: quantizer memory for MA model 2.56 */ + Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ + Word16 *lsf_new_bck, /* o: quantized LSF vector - backup Q15 */ + Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ + Word16 *mCb1, /* o: counter for stationary frame after a transition frame */ + Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets q_bin */ + Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets q_bin */ + Word16 *mem_syn_bck, /* i: synthesis filter memory q */ + Word16 *mem_w0_bck, /* i: memory of the weighting filter q */ + Word16 *streaklimit, /* i:LSF quantizer Q15 */ + Word16 *pstreaklen /* i:LSF quantizer */ ) { Word16 i; @@ -2985,25 +2983,31 @@ void lsf_syn_mem_backup_fx( return; } + +/*-------------------------------------------------------------------* + * lsf_syn_mem_backup_fx() + * + * + *--------------------------------------------------------------------*/ + void lsf_syn_mem_backup_ivas_fx( Encoder_State *st_fx, /* i: state structure */ Word16 *btilt_code_fx, /* i: tilt code Q15 */ Word32 *gc_threshold_fx, /* i: Q16 */ Word16 *clip_var_bck_fx, /* o: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ Word16 *next_force_sf_bck_fx, /* o: */ - - Word16 *lsp_new, /* i: LSP vector to quantize Q15 */ - Word16 *lsp_mid, /* i: mid-frame LSP vector Q15 */ - Word16 *clip_var, /* o: pitch clipping state var Q(2.56) */ - Word16 *mem_AR, /* o: quantizer memory for AR model Q(2.56) */ - Word16 *mem_MA, /* o: quantizer memory for AR model Q(2.56) */ - Word16 *lsp_new_bck, /* o: LSP vector to quantize- backup Q15 */ - Word16 *lsp_mid_bck, /* o: mid-frame LSP vector - backup Q15 */ - Word32 *Bin_E, /* o: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ - Word32 *Bin_E_old, /* o: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ - Word16 *mem_syn_bck, /* o: synthesis filter memory ( 15 - st_fx->hLPDmem->e_mem_syn ) */ - Word16 *mem_w0_bck, /* o: memory of the weighting filter ( 15 - st_fx->hLPDmem->e_mem_syn ) */ - Word16 *streaklimit, /* Q15 */ + Word16 *lsp_new, /* i: LSP vector to quantize Q15 */ + Word16 *lsp_mid, /* i: mid-frame LSP vector Q15 */ + Word16 *clip_var, /* o: pitch clipping state var Q(2.56) */ + Word16 *mem_AR, /* o: quantizer memory for AR model Q(2.56) */ + Word16 *mem_MA, /* o: quantizer memory for AR model Q(2.56) */ + Word16 *lsp_new_bck, /* o: LSP vector to quantize- backup Q15 */ + Word16 *lsp_mid_bck, /* o: mid-frame LSP vector - backup Q15 */ + Word32 *Bin_E, /* o: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ + Word32 *Bin_E_old, /* o: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ + Word16 *mem_syn_bck, /* o: synthesis filter memory ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 *mem_w0_bck, /* o: memory of the weighting filter ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 *streaklimit, /* Q15 */ Word16 *pstreaklen ) { Word16 i; @@ -3079,66 +3083,68 @@ void lsf_update_memory( move16(); mem_MA[i] = sub( sub( qlsf[i], lsf_means[narrowband][i] ), mult_r( MU_MA_FX, old_mem_MA[i] ) ); } + + return; } + /*======================================================================*/ -/* FUNCTION : lsf_syn_mem_restore_fx */ +/* FUNCTION : lsf_syn_mem_restore_fx */ /*----------------------------------------------------------------------*/ /* PURPOSE : restore synthesis filter memory and LSF quantizer memories*/ /*----------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) clip_var : pitch clipping state var */ -/* _ (Word16*) mem_AR : quantizer memory for AR model */ -/* _ (Word16*) mem_MA : quantizer memory for MA model */ -/* _ (Word16*) lsp_new_bck : LSP vector to quantize- backup */ -/* _ (Word16*) lsf_new_bck : quantized LSF vector - backup */ -/* _ (Word16*) lsp_mid_bck : mid-frame LSP vector - backup */ +/* INPUT ARGUMENTS : */ +/* _ (Word16) clip_var : pitch clipping state var */ +/* _ (Word16*) mem_AR : quantizer memory for AR model */ +/* _ (Word16*) mem_MA : quantizer memory for MA model */ +/* _ (Word16*) lsp_new_bck : LSP vector to quantize- backup */ +/* _ (Word16*) lsf_new_bck : quantized LSF vector - backup */ +/* _ (Word16*) lsp_mid_bck : mid-frame LSP vector - backup */ /* _ (Word16) mCb1 :counter for stationary frame after a transition frame */ -/* _ (Word32*) Bin_E : FFT Bin energy 128 *2 sets */ -/* _ (Word32*) Bin_E_old : FFT Bin energy 128 *2 sets */ -/* _ (Word16*) mem_syn_bck : synthesis filter memory */ -/* _ (Word16) mem_w0_bck : memory of the weighting filter */ -/* _ (Word16) streaklimit : LSF quantizer */ -/* _ (Word16) pstreaklen : LSF quantizer */ -/*-----------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _None */ -/*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) lsp_new : LSP vector to quantize */ -/* _ (Word16*) lsf_new : quantized LSF vector */ -/* _ (Word16*) lsp_mid : mid-frame LSP vector */ -/* _ (Encoder_State) st_fx : Encoder state Structure */ -/*-----------------------------------------------------------------------*/ - -/* _ None */ -/*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*=======================================================================*/ +/* _ (Word32*) Bin_E : FFT Bin energy 128 *2 sets */ +/* _ (Word32*) Bin_E_old : FFT Bin energy 128 *2 sets */ +/* _ (Word16*) mem_syn_bck : synthesis filter memory */ +/* _ (Word16) mem_w0_bck : memory of the weighting filter */ +/* _ (Word16) streaklimit : LSF quantizer */ +/* _ (Word16) pstreaklen : LSF quantizer */ +/*----------------------------------------------------------------------*/ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _None */ +/*----------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16*) lsp_new : LSP vector to quantize */ +/* _ (Word16*) lsf_new : quantized LSF vector */ +/* _ (Word16*) lsp_mid : mid-frame LSP vector */ +/* _ (Encoder_State) st_fx : Encoder state Structure */ +/*----------------------------------------------------------------------*/ +/* _ None */ +/*----------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ None */ +/*======================================================================*/ + void lsf_syn_mem_restore_fx( Encoder_State *st_fx, /* o: state structure */ Word16 btilt_code_fx, /* i: Q15 */ Word32 gc_threshold_fx, /* i: Q16 */ Word16 *clip_var_bck_fx, /* i: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ Word16 next_force_sf_bck_fx, /* i: */ - - Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ - Word16 *lsf_new, /* o: quantized LSF vector Q15 */ - Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ - Word16 clip_var, /* i: pitch clipping state var Q(2.56) */ - Word16 *mem_AR, /* i: quantizer memory for AR model Q15 */ - Word16 *mem_MA, /* i: quantizer memory for MA model Q15 */ - Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ - Word16 *lsf_new_bck, /* i: quantized LSF vector - backup Q15 */ - Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ - Word16 mCb1, /* i: counter for stationary frame after a transition frame */ - Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ - Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ - Word16 *mem_syn_bck, /* i: synthesis filter memory ( 15 - st_fx->hLPDmem->e_mem_syn ) */ - Word16 mem_w0_bck, /* i: memory of the weighting filter ( 15 - st_fx->hLPDmem->e_mem_syn ) */ - Word16 streaklimit, /* i:LSF quantizer Q15 */ - Word16 pstreaklen /* i:LSF quantizer */ + Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ + Word16 *lsf_new, /* o: quantized LSF vector Q15 */ + Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ + Word16 clip_var, /* i: pitch clipping state var Q(2.56) */ + Word16 *mem_AR, /* i: quantizer memory for AR model Q15 */ + Word16 *mem_MA, /* i: quantizer memory for MA model Q15 */ + Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ + Word16 *lsf_new_bck, /* i: quantized LSF vector - backup Q15 */ + Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ + Word16 mCb1, /* i: counter for stationary frame after a transition frame */ + Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ + Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ + Word16 *mem_syn_bck, /* i: synthesis filter memory ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 mem_w0_bck, /* i: memory of the weighting filter ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 streaklimit, /* i:LSF quantizer Q15 */ + Word16 pstreaklen /* i:LSF quantizer */ ) { Word16 i; diff --git a/lib_com/options.h b/lib_com/options.h index daa609ed4..86b786588 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -95,6 +95,4 @@ #define TEST_HR -#define REMOVE_EVS_DUPLICATES /* remove core-coder duplicated functions, ACELP low-band decoder */ - #endif diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index e4d9b3dab..07e9dbdb1 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -3286,67 +3286,33 @@ void synthesise_fb_high_band_fx( Word16 bpf_memory_Q[], Word16 Qout ); -#ifndef REMOVE_EVS_DUPLICATES void prep_tbe_exc_fx( - const Word16 L_frame_fx, /* i : length of the frame */ -#ifdef ADD_IVAS_TBE_CODE - const Word16 L_subfr, -#endif - const Word16 i_subfr_fx, /* i : subframe index */ - const Word16 gain_pit_fx, /* i : Pitch gain Q14*/ - const Word32 gain_code_fx, /* i : algebraic codebook gain 16+Q_exc*/ - const Word16 code_fx[], /* i : algebraic excitation Q9*/ - const Word16 voice_fac_fx, /* i : voicing factor Q15*/ - Word16 *voice_factors_fx, /* o : TBE voicing factor Q15*/ - Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/ - const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */ - const Word16 code_preQ_fx[], /* i : prequantizer excitation */ - const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ - Word16 T0, /* i : integer pitch variables Q0 */ - Word16 T0_frac, /* i : Fractional pitch variables Q0*/ - const Word16 coder_type, /* i : coding type */ - Word32 core_brate /* i :core bitrate */ -#ifdef ADD_IVAS_TBE_CODE - , - const Word16 element_mode, /* i : element mode */ - const Word16 idchan, /* i : channel ID */ - const Word16 flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */ - const Word16 tdm_LRTD_flag /* i : LRTD stereo mode flag */ -#endif -); -#endif - -void prep_tbe_exc_ivas_fx( - const Word16 L_frame_fx, /* i : length of the frame */ -#if 1 // def ADD_IVAS_TBE_CODE - const Word16 L_subfr, -#endif - const Word16 i_subfr_fx, /* i : subframe index */ - const Word16 gain_pit_fx, /* i : Pitch gain Q14*/ - const Word32 gain_code_fx, /* i : algebraic codebook gain 16+Q_exc*/ - const Word16 code_fx[], /* i : algebraic excitation Q9*/ - const Word16 voice_fac_fx, /* i : voicing factor Q15*/ - Word16 *voice_factors_fx, /* o : TBE voicing factor Q15*/ - Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/ - const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */ - const Word16 code_preQ_fx[], /* i : prequantizer excitation */ - const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ - Word16 T0, /* i : integer pitch variables Q0 */ - Word16 T0_frac, /* i : Fractional pitch variables Q0*/ - const Word16 coder_type, /* i : coding type */ - Word32 core_brate -#if 1 // def ADD_IVAS_TBE_CODE - , /* i : core bitrate */ - const Word16 element_mode, /* i : element mode */ - const Word16 idchan, /* i : channel ID */ - const Word16 flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */ - const Word16 tdm_LRTD_flag /* i : LRTD stereo mode flag */ -#endif -); - -Word16 swb_formant_fac_fx( /* o : Formant filter strength [0,1] */ - const Word16 lpc_shb2, /* Q12 i : 2nd HB LPC coefficient */ - Word16 *tilt_mem /* i/o: Tilt smoothing memory */ + const Word16 L_frame_fx, /* i : length of the frame */ + const Word16 L_subfr, /* i : subframe length */ + const Word16 i_subfr_fx, /* i : subframe index */ + const Word16 gain_pit_fx, /* i : Pitch gain Q14*/ + const Word32 gain_code_fx, /* i : algebraic codebook gain 16+Q_exc*/ + const Word16 code_fx[], /* i : algebraic excitation Q9*/ + const Word16 voice_fac_fx, /* i : voicing factor Q15*/ + Word16 *voice_factors_fx, /* o : TBE voicing factor Q15*/ + Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/ + const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */ + const Word16 code_preQ_fx[], /* i : prequantizer excitation */ + const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ + Word16 T0, /* i : integer pitch variables Q0 */ + Word16 T0_frac, /* i : Fractional pitch variables Q0*/ + const Word16 coder_type, /* i : coding type */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 element_mode, /* i : element mode */ + const Word16 idchan, /* i : channel ID */ + const Word16 flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */ + const Word16 tdm_LRTD_flag /* i : LRTD stereo mode flag */ +); + +/*! r: Formant filter strength [0,1] */ +Word16 swb_formant_fac_fx( + const Word16 lpc_shb2, /* Q12 i : 2nd HB LPC coefficient */ + Word16 *tilt_mem /* i/o: Tilt smoothing memory */ ); void wb_tbe_extras_reset_fx( @@ -4858,35 +4824,6 @@ Word16 BITS_ALLOC_config_acelp( const Word16 narrowband, const Word16 nb_subfr ); -#ifndef REMOVE_EVS_DUPLICATES -ivas_error config_acelp1( - const Word16 enc_dec, /* i : encoder/decoder flag */ - const Word32 total_brate, /* i : total bitrate */ - const Word32 core_brate_inp, /* i : core bitrate */ - const Word16 core, /* i : core */ - const Word16 extl, /* i : extension layer */ - const Word32 extl_brate, /* i : extension layer bitrate */ - const Word16 L_frame, /* i : frame length at internal Fs */ - const Word16 GSC_noisy_speech, /* i : GSC on SWB noisy speech flag */ - ACELP_config *acelp_cfg, /* i : ACELP bit-allocation */ - const Word16 signalling_bits, /* i : number of signalling bits */ - const Word16 coder_type, /* i : coder type */ - const Word16 inactive_coder_type_flag, /* i : AVQ (0) or GSC (1) IC flag */ - const Word16 tc_subfr, /* i : TC subfr ID */ - const Word16 tc_call, /* i : TC call number (0,1,2,3,5(DEC)) */ - Word16 *nBits_es_Pred, /* o : number of bits for Es_pred Q */ - Word16 *unbits, /* o : number of unused bits */ - const Word16 element_mode, /* i : element mode */ - Word16 *uc_two_stage_flag, /* o : flag undicating two-stage UC */ - const Word16 tdm_lp_reuse_flag, /* i : LPC reuse flag (can be 1 only with secondary channel */ - const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ - const Word16 idchan, /* i : stereo channel ID */ - const Word16 active_cnt, /* i : Active frame counter */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag*/ - const Word16 tdm_LRTD_flag, /* i : LRTD stereo mode flag */ - const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ -); -#endif Word16 set_ACELP_flag( const Word16 element_mode, /* i : element mode */ const Word32 element_brate, /* i : element bitrate */ @@ -5833,35 +5770,19 @@ void tcx_ltp_post_fx32( Word32 *tcx_buf, /* sig_q */ Word16 sig_q ); -#ifndef REMOVE_EVS_DUPLICATES -// gs_inact_switching_fx.c -void Inac_swtch_ematch_fx( - Word16 exc2[], /* i/o: CELP/GSC excitation buffer Q_exc*/ - Word16 dct_exc_tmp[], /* i : GSC excitation in DCT domain */ - Word16 lt_ener_per_band[], /* i/o: Long term energy per band Q12 */ - const Word16 coder_type, /* i : Coding mode */ - const Word16 L_frame, /* i : Frame lenght */ - const Word32 core_brate, /* i : Core bit rate */ - const Word16 Q_exc, /* i : i and output format of exc2 */ - const Word16 bfi, /* i : frame lost indicator */ - const short last_core, /* i : Last core used */ - const short last_codec_mode /* i : Last codec mode */ -); -#endif - -void Inac_switch_ematch_ivas_fx( +void Inac_switch_ematch_fx( Word16 exc2[], /* i/o: CELP/GSC excitation buffer Q_exc*/ Word16 dct_exc_tmp[], /* i : GSC excitation in DCT domain */ Word16 lt_ener_per_band[], /* i/o: Long term energy per band Q12 */ const Word16 coder_type, /* i : Coding mode */ - const Word16 inactive_coder_type_flag, /* i : AVQ (0) or GSC (1) IC flag */ + const Word16 inactive_coder_type_flag, /* i : AVQ (0) or GSC (1) IC flag */ const Word16 L_frame, /* i : Frame lenght */ const Word16 Q_exc, /* i : input and output format of exc2 */ const Word16 bfi, /* i : frame lost indicator */ const Word16 last_core, /* i : Last core used */ const Word16 last_codec_mode, /* i : Last codec mode */ - const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag*/ - const Word16 element_mode /* i : element mode */ + const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ + const Word16 element_mode /* i : element mode */ ); // igf_base_fx.c @@ -6094,32 +6015,16 @@ void td_bwe_dec_init_fx( const Word32 output_Fs /* i : output sampling rate */ ); -#ifndef REMOVE_EVS_DUPLICATES -// lsf_dec_fx.c void lsf_dec_fx( - Decoder_State *st_fx, /* i/o: State structure */ - const Word16 tc_subfr, /* i : TC subframe index Q0*/ - Word16 *Aq, /* o : quantized A(z) for 4 subframes Q12*/ - Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ - Word16 *lsf_new, /* o : de-quantized LSF vector Q(x2.56)*/ - Word16 *lsp_new, /* o : de-quantized LSP vector Q15*/ - Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector Q15*/ - const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag Q0*/ - , - const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ -); -#endif -void lsf_dec_ivas_fx( - Decoder_State *st_fx, /* i/o: State structure */ - const Word16 tc_subfr, /* i : TC subframe index Q0*/ - Word16 *Aq, /* o : quantized A(z) for 4 subframes Q12*/ - Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ - Word16 *lsf_new, /* o : de-quantized LSF vector Q(x2.56)*/ - Word16 *lsp_new, /* o : de-quantized LSP vector Q15*/ - Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector Q15*/ - const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag Q0*/ - , - const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ + Decoder_State *st_fx, /* i/o: State structure */ + const Word16 tc_subfr, /* i : TC subframe index Q0*/ + Word16 *Aq, /* o : quantized A(z) for 4 subframes Q12*/ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ + Word16 *lsf_new, /* o : de-quantized LSF vector Q(x2.56)*/ + Word16 *lsp_new, /* o : de-quantized LSP vector Q15*/ + Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector Q15*/ + const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag Q0*/ + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ ); /*! r: index of the maximum value in the input vector */ @@ -6264,21 +6169,9 @@ void lsf_mid_dec_fx( Word16 lsp_mid[] /* o : quantized LSPs Q15*/ ); -#ifndef REMOVE_EVS_DUPLICATES -// cng_dec_fx.c void CNG_dec_fx( Decoder_State *st_fx, /* i/o: State structure */ - const Word16 last_element_mode, /* i : last element mode Q0 */ - Word16 Aq[], /* o : LP coefficients Q12 */ - Word16 *lsp_new, /* i/o: current frame LSPs Q15 */ - Word16 *lsf_new, /* i/o: current frame LSFs Qlog2(2.56) */ - Word16 *allow_cn_step, /* o : allow CN step Q0 */ - Word16 *sid_bw, /* i : 0-NB/WB, 1-SWB SID Q0 */ - Word32 *q_env ); -#endif -void CNG_dec_ivas_fx( - Decoder_State *st_fx, /* i/o: State structure */ - const Word16 last_element_mode, /* i : last element mode Q0 */ + const Word16 last_element_mode, /* i : last element mode Q0 */ Word16 Aq[], /* o : LP coefficients Q12 */ Word16 *lsp_new, /* i/o: current frame LSPs Q15 */ Word16 *lsf_new, /* i/o: current frame LSFs Qlog2(2.56) */ @@ -6688,12 +6581,12 @@ void hf_synth_amr_wb_fx( // dec_post_fx void Init_post_filter_fx( PFSTAT_HANDLE hPFstat /* i : core decoder parameters */ -); /* (i) : core decoder parameters */ +); /* i : core decoder parameters */ void nb_post_filt_fx( const Word16 L_frame, /* i : frame length */ - PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ + PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ Word16 *psf_lp_noise, /* i : Long term noise Q8 */ const Word16 tmp_noise, /* i : noise energy Q0 */ Word16 *Synth, /* i : 12k8 synthesis Qsyn */ @@ -6704,27 +6597,15 @@ void nb_post_filt_fx( const Word16 disable_hpf /* i : flag to diabled HPF */ ); -#ifndef REMOVE_EVS_DUPLICATES void formant_post_filt_fx( - PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ - Word16 *synth_in, /* i : 12k8 synthesis */ - Word16 *Aq, /* i : LP filter coefficient */ - Word16 *synth_out, /* i/o: i signal */ - Word16 L_frame, - Word32 lp_noise, /* (i) : background noise energy (15Q16) */ - Word32 rate, /* (i) : bit-rate */ - const Word16 off_flag /* i : off flag */ -); -#endif -void formant_post_filt_ivas_fx( - PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ + PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ Word16 *synth_in, /* i : 12k8 synthesis */ - Word16 *Aq, /* i : LP filter coefficient */ - Word16 *synth_out, /* i/o: i signal */ - Word16 L_frame, - Word32 lp_noise, /* (i) : background noise energy (15Q16) */ - Word32 rate, /* (i) : bit-rate */ - const Word16 off_flag /* i : off flag */ + Word16 *Aq, /* i : LP filter coefficient Q12 */ + Word16 *synth_out, /* i/o: input signal */ + const Word16 L_frame, /* i : frame length */ + const Word32 lp_noise, /* (i) : background noise energy (15Q16) */ + const Word32 brate, /* (i) : bit-rate */ + const Word16 off_flag /* i : off flag */ ); void Filt_mu_fx( Word16 *sig_in, /* i : signal (beginning at sample -1) */ @@ -6890,65 +6771,34 @@ void PulseResynchronization_fx( Word32 /*float*/ const pitchEnd /*i Q16*/ ); -#ifndef REMOVE_EVS_DUPLICATES -// gs_dec_fx.c void decod_audio_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - Word16 dct_epit[], /* o : GSC excitation in DCT domain Qx*/ - const Word16 *Aq, /* i : LP filter coefficient Q12*/ - Word16 *pitch_buf, /* o : floating pitch values for each subframe Q6*/ - Word16 *voice_factors, /* o : voicing factors Q15*/ - Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ - Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ - Word16 *lsf_new /* i : ISFs at the end of the frame Qx*/ - , - Word16 *gain_buf /*Q14*/ -); -#endif -void decod_audio_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - Word16 dct_epit[], /* o : GSC excitation in DCT domain Qx*/ - const Word16 *Aq, /* i : LP filter coefficient Q12*/ - Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ - Word16 *voice_factors, /* o : voicing factors Q15*/ - Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ - Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ - Word16 *lsf_new /* i : ISFs at the end of the frame Qx*/ - , - Word16 *gain_buf, /*Q14*/ + Decoder_State *st_fx, /* i/o: decoder static memory */ + Word16 dct_epit[], /* o : GSC excitation in DCT domain Qx*/ + const Word16 *Aq, /* i : LP filter coefficient Q12*/ + Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ + Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ const Word16 tdm_lp_reuse_flag, /* i : LPC reuse flag Q0*/ const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag Q0*/ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6*/ ); -#ifndef REMOVE_EVS_DUPLICATES void gsc_dec_fx( - Decoder_State *st_fx, /* i/o: State structure */ - Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation Q_exc*/ - const Word16 pit_band_idx, /* i : bin position of the cut-off frequency Q0*/ - const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral) Q0*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q Q0*/ - const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ - const Word16 coder_type, /* i : coding type Q0*/ - Word16 *last_bin, /* i : last bin of bit allocation Q0*/ - const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ - Word16 Q_exc ); -#endif -void gsc_dec_ivas_fx( - Decoder_State *st_fx, /* i/o: State structure */ - Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation Q_exc*/ + Decoder_State *st_fx, /* i/o: State structure */ + Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation Q_exc*/ const Word16 pit_band_idx, /* i : bin position of the cut-off frequency ` Q0*/ const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral) Q0*/ const Word16 bits_used, /* i : Number of bit used before frequency Q Q0*/ const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ const Word16 coder_type, /* i : coding type Q0*/ Word16 *last_bin, /* i : last bin of bit allocation Q0*/ - const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ + const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ + Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ Word16 *Q_exc ); void GSC_dec_init( @@ -6959,18 +6809,15 @@ void GSC_dec_init_ivas_fx( GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ ); - -// gain_dec_fx.c - void Es_pred_dec_fx( - Word16 *Es_pred, /* o : predicited scaled innovation energy Q8*/ - const Word16 enr_idx, /* i : indice */ - const Word16 nb_bits, /* i : number of bits */ - const Word16 no_ltp /* i : no LTP flag */ + Word16 *Es_pred, /* o : predicited scaled innovation energy Q8*/ + const Word16 enr_idx, /* i : indice */ + const Word16 nb_bits, /* i : number of bits */ + const Word16 no_ltp /* i : no LTP flag */ ); void gain_dec_tc_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ + Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 *code_fx, /* i : algebraic code excitation */ const Word16 i_subfr_fx, /* i : subframe number */ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ @@ -7005,7 +6852,6 @@ void gain_dec_mless_fx( Word32 *norm_gain_code_fx /* o : norm. gain of the codebook excitation Q16*/ ); -#ifndef REMOVE_EVS_DUPLICATES void gain_dec_lbr_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 coder_type, /* i : coding type */ @@ -7016,25 +6862,8 @@ void gain_dec_lbr_fx( Word16 *gain_inov_fx, /* o : gain of the innovation (used for normalization) Q12*/ Word32 *norm_gain_code_fx, /* o : norm. gain of the codebook excitation Q16*/ Word32 gc_mem[], /* i/o: gain_code from previous subframes */ - Word16 gp_mem[] /* i/o: gain_pitch from previous subframes */ - , - const Word16 L_subfr /* i : subfr lenght */ -); -#endif - -void gain_dec_lbr_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 *code_fx, /* i : algebraic excitation Q9 */ - Word16 *gain_pit_fx, /* o : quantized pitch gain Q14*/ - Word32 *gain_code_fx, /* o : quantized codebook gain Q16*/ - Word16 *gain_inov_fx, /* o : gain of the innovation (used for normalization) Q12*/ - Word32 *norm_gain_code_fx, /* o : norm. gain of the codebook excitation Q16*/ - Word32 gc_mem[], /* i/o: gain_code from previous subframes */ - Word16 gp_mem[] /* i/o: gain_pitch from previous subframes */ - , - const Word16 L_subfr /* i : subfr lenght */ + Word16 gp_mem[], /* i/o: gain_pitch from previous subframes */ + const Word16 L_subfr /* i : subfr lenght */ ); void lp_gain_updt_fx( @@ -7055,13 +6884,14 @@ void lp_gain_updt_ivas_fx( const Word16 L_frame /* i : length of the frame */ ); -Word32 gain_dec_gaus_fx( /* o : quantized codebook gain Q16 */ - Word16 index, /* i : quantization index */ - const Word16 bits, /* i : number of bits to quantize */ - const Word16 lowBound, /* i : lower bound of quantizer (dB) */ - const Word16 topBound, /* i : upper bound of quantizer (dB) */ - const Word16 inv_gain_inov, /* o : unscaled innovation gain Q12 */ - Word32 *L_norm_gain_code /* o : gain of normalized gaussian excitation Q16 */ +/*! r: quantized codebook gain Q16 */ +Word32 gain_dec_gaus_fx( + Word16 index, /* i : quantization index */ + const Word16 bits, /* i : number of bits to quantize */ + const Word16 lowBound, /* i : lower bound of quantizer (dB) */ + const Word16 topBound, /* i : upper bound of quantizer (dB) */ + const Word16 inv_gain_inov, /* o : unscaled innovation gain Q12 */ + Word32 *L_norm_gain_code /* o : gain of normalized gaussian excitation Q16 */ ); void gain_dec_SQ_fx( @@ -7155,23 +6985,7 @@ void re8_PPV_fx( Word16 y[] /* o : point in RE8 (8-dimensional integer vector) Q0 */ ); -#ifndef REMOVE_EVS_DUPLICATES -// dec_pit_exc_fx.c void dec_pit_exc_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 coder_type, /* i : coding type */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *code_fx, /* o : innovation */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - const Word16 nb_subfr_fx /* i : Number of subframe considered */ - , - Word16 *gain_buf /*Q14*/ -); -#endif -void dec_pit_exc_ivas_fx( Decoder_State *st_fx, /* i/o: decoder static memory */ const Word16 *Aq_fx, /* i : LP filter coefficient */ const Word16 coder_type, /* i : coding type */ @@ -7181,7 +6995,7 @@ void dec_pit_exc_ivas_fx( Word16 *exc_fx, /* i/o: adapt. excitation exc */ Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ const Word16 nb_subfr_fx, /* i : Number of subframe considered */ - Word16 *gain_buf, /*Q14*/ + Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ ); @@ -7225,24 +7039,8 @@ void Mode2_delta_pit_dec( Word16 **pt_indice /* i/o: pointer to Vector of Q indexes */ ); -#ifndef REMOVE_EVS_DUPLICATES -Word16 pit_decode_fx( /* o : floating pitch value */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : coding type */ - Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ - Word16 *T0, /* o : close loop integer pitch */ - Word16 *T0_frac, /* o : close loop fractional part of the pitch */ - Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ - Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ - const Word16 L_subfr /* i : subframe length */ -); -#endif /* o : floating pitch value */ -Word16 pit_decode_ivas_fx( +Word16 pit_decode_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ const Word32 core_brate, /* i : core bitrate */ const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ @@ -7603,22 +7401,7 @@ void configureFdCngDec_fx( const Word16 Last_L_frame, const Word16 element_mode ); -#ifndef REMOVE_EVS_DUPLICATES -/* Apply the CLDFB-based CNG */ Word16 ApplyFdCng_fx( - Word16 *timeDomainInput, /* i : pointer to time domain i */ - Word16 Q, -#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - Word16 *powerSpectrum, -#endif - Word32 **cldfbBufferReal, /* i/o: real part of the CLDFB buffer */ - Word32 **cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer */ - Word16 *cldfbBufferScale, /* o : pointer to the scalefactor for real and imaginary part of the CLDFB buffer */ - Decoder_State *st, - const Word16 concealWholeFrame, /* i : binary flag indicating frame loss */ - Word16 is_music ); -#endif -Word16 ApplyFdCng_ivas_fx( Word16 *timeDomainInput, /* i : pointer to time domain input */ Word16 Q, Word32 *powerSpectrum, @@ -8210,14 +7993,11 @@ void FEC_pitch_estim_fx( const Word32 old_pitch_buf[], /* i : buffer of old subframe pitch values 15Q16 */ Word16 *bfi_pitch, /* i/o: update of the estimated pitch for FEC */ Word16 *bfi_pitch_frame, /* o : frame length when pitch was updated */ - Word16 *upd_cnt /* i/o: update counter */ - , - const Word16 coder_type, /* i : coder_type */ - Word16 element_mode /* i : element mode */ + Word16 *upd_cnt, /* i/o: update counter */ + const Word16 coder_type, /* i : coder_type */ + Word16 element_mode /* i : element mode */ ); -#ifndef REMOVE_EVS_DUPLICATES -// FEC_scale_sync_fx.c void FEC_scale_syn_fx( const Word16 L_frame, /* i : length of the frame */ Word16 *update_flg, /* o: flag indicating re-synthesis after scaling*/ @@ -8244,69 +8024,37 @@ void FEC_scale_syn_fx( Word16 *mem_syn, /* o: initial synthesis filter states */ Word16 Q_exc, Word16 Q_syn, + const Word16 element_mode, /* i : element mode */ const Word16 avoid_lpc_burst_on_recovery, /* i : if true the excitation energy is limited if LP has big gain */ - const Word16 force_scaling /* i: force scaling */ -); -#endif -void FEC_scale_syn_ivas_fx( - const Word16 L_frame, /* i : length of the frame */ - Word16 *update_flg, /* o: flag indicating re-synthesis after scaling*/ - Word16 clas, /* i/o: frame classification */ - const Word16 last_good, /* i: last good frame classification */ - Word16 *synth, /* i/o: synthesized speech at Fs = 12k8 Hz */ - const Word16 *pitch, /* i: pitch values for each subframe */ - Word32 L_enr_old, /* i: energy at the end of previous frame */ - Word32 L_enr_q, /* i: transmitted energy for current frame */ - const Word16 coder_type, /* i: coder type */ - const Word16 LSF_Q_prediction, /* i : LSF prediction mode */ - Word16 *scaling_flag, /* i/o: flag to indicate energy control of syn */ - Word32 *lp_ener_FEC_av, /* i/o: averaged voiced signal energy */ - Word32 *lp_ener_FEC_max, /* i/o: averaged voiced signal energy */ - const Word16 bfi, /* i: current frame BFI */ - const Word32 total_brate, /* i: total bitrate */ - const Word16 prev_bfi, /* i: previous frame BFI */ - const Word32 last_core_brate, /* i: previous frame core bitrate */ - Word16 *exc, /* i/o: excitation signal without enhancement */ - Word16 *exc2, /* i/o: excitation signal with enhancement */ - Word16 Aq[], /* i/o: LP filter coefs (can be modified if BR) */ - Word16 *old_enr_LP, /* i/o: LP filter E of last good voiced frame */ - const Word16 *mem_tmp, /* i: temp. initial synthesis filter states */ - Word16 *mem_syn, /* o: initial synthesis filter states */ - Word16 Q_exc, - Word16 Q_syn, -#ifdef REMOVE_EVS_DUPLICATES - const Word16 element_mode, /* i : element mode */ -#endif - const Word16 avoid_lpc_burst_on_recovery, /* i : if true the excitation energy is limited if LP has big gain */ - const Word16 force_scaling /* i: force scaling */ + const Word16 force_scaling /* i : force scaling */ ); // LD_music_post_filter_fx.c void LD_music_post_filter_fx( - MUSIC_POSTFILT_HANDLE hMusicPF, /* i/o: LD music postfilter handle */ - const Word16 dtc_in[], /* i : i synthesis Qdct */ - Word16 dtc_out[], /* o : output synthesis Qdct */ - const Word32 core_brate, /* i : core bitrate Q0 */ - Word16 *Old_ener_Q, /* i/o : Old energy scaling factor */ - const Word16 coder_type, /* i : Coder type : -1 in case of IO Q0 */ - const Word16 Last_coder_type, /* i : i scaling Q0 */ - const Word16 Qdct /* i : i scaling Q0 */ + MUSIC_POSTFILT_HANDLE hMusicPF, /* i/o: LD music postfilter handle */ + const Word16 dtc_in[], /* i : i synthesis Qdct */ + Word16 dtc_out[], /* o : output synthesis Qdct */ + const Word32 core_brate, /* i : core bitrate Q0 */ + Word16 *Old_ener_Q, /* i/o: Old energy scaling factor */ + const Word16 coder_type, /* i : Coder type : -1 in case of IO Q0 */ + const Word16 Last_coder_type, /* i : i scaling Q0 */ + const Word16 Qdct /* i : i scaling Q0 */ ); void Prep_music_postP_fx( - Word16 exc_buffer_in[], /* i/o: excitation buffer Q_exc*/ - Word16 dct_buffer_out[], /* o : DCT output buffer (qdct)*/ - Word16 filt_lfE[], /* i/o: long term spectrum energy Q15 */ - const Word16 last_core, /* i : last core */ - const Word16 element_mode, /* i : element mode */ - const Word16 *pitch_buf, /* i : current frame pitch information Q6*/ - Word16 *LDm_enh_lp_gbin, /* o : smoothed suppression gain, per bin FFT Q15*/ - const Word16 Q_exc, /* i : excitation scaling */ - Word16 *qdct /* o : Scaling factor of dct coefficient */ + Word16 exc_buffer_in[], /* i/o: excitation buffer Q_exc*/ + Word16 dct_buffer_out[], /* o : DCT output buffer (qdct)*/ + Word16 filt_lfE[], /* i/o: long term spectrum energy Q15 */ + const Word16 last_core, /* i : last core */ + const Word16 element_mode, /* i : element mode */ + const Word16 *pitch_buf, /* i : current frame pitch information Q6*/ + Word16 *LDm_enh_lp_gbin, /* o : smoothed suppression gain, per bin FFT Q15*/ + const Word16 Q_exc, /* i : excitation scaling */ + Word16 *qdct /* o : Scaling factor of dct coefficient */ ); void Post_music_postP_fx( - Word16 dct_buffer_in[], /* i/o: excitation buffer */ + Word16 dct_buffer_in[], /* i/o: excitation buffer */ Word16 *exc2, /* i/o: Current excitation to be overwriten */ const Word16 *mem_tmp, /* i : previous frame synthesis memory */ Word16 *st_mem_syn2, /* i/o: current frame synthesis memory */ @@ -8316,15 +8064,14 @@ void Post_music_postP_fx( Word16 *prev_Q_syn, /* i : previsous frame synthesis scaling */ Word16 *Q_syn, /* i : Current frame synthesis scaling */ Word16 *mem_syn_clas_estim_fx, /* i : old 12k8 synthesis used for frame classification*/ - const Word16 IsIO, /* i: Flag to indicate IO mode */ - Word16 *mem_deemph, /* i/o: speech deemph filter memory */ - Word16 *st_pst_old_syn_fx, /* i/o: psfiler */ - Word16 *st_pst_mem_deemp_err_fx, /* i/o: psfiler */ + const Word16 IsIO, /* i : Flag to indicate IO mode */ + Word16 *mem_deemph, /* i/o: speech deemph filter memory */ + Word16 *st_pst_old_syn_fx, /* i/o: psfiler */ + Word16 *st_pst_mem_deemp_err_fx, /* i/o: psfiler */ Word16 *mem_agc, - PFSTAT *pf_stat, /* i/o: All memories related to NB post filter */ - const Word16 *tmp_buffer /* tmp_buffer in Q-1 */ - , - Word16 *mem_tmp2 /* Temporary memory used with scale_syn */ + PFSTAT *pf_stat, /* i/o: All memories related to NB post filter */ + const Word16 *tmp_buffer, /* tmp_buffer in Q-1 */ + Word16 *mem_tmp2 /* Temporary memory used with scale_syn */ ); void music_postfilt_init( @@ -8556,29 +8303,17 @@ Word16 FEC_enhACB_fx( const Word16 puls_pos, /* i : decoder position of the last glottal pulses decoded in the previous frame */ const Word16 bfi_pitch /* i : Q6 pitch used for concealment */ ); -Word16 FEC_synchro_exc_fx( /* o : do_WI flag */ - const Word16 L_frame, /* i : length of the frame */ - Word16 *exc, /* i/o: exc vector to modify */ - const Word16 desire_puls_pos, /* i : Pulse position send by the encoder */ - const Word16 true_puls_pos, /* i : Present pulse location */ - const Word16 Old_pitch /* i : Pitch use to create temporary adaptive codebook */ + +/*! r: do_WI flag */ +Word16 FEC_synchro_exc_fx( + const Word16 L_frame, /* i : length of the frame */ + Word16 *exc, /* i/o: exc vector to modify */ + const Word16 desire_puls_pos, /* i : Pulse position send by the encoder */ + const Word16 true_puls_pos, /* i : Present pulse location */ + const Word16 Old_pitch /* i : Pitch use to create temporary adaptive codebook */ ); -#ifndef REMOVE_EVS_DUPLICATES -// dec_uv_fx.c void decod_unvoiced_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* Q12 i : LP filter coefficient */ - const Word16 coder_type, /* Q0 i : coding type */ - Word16 *tmp_noise_fx, /* Q5 o : long term temporary noise energy */ - Word16 *pitch_buf_fx, /* Q6 o : floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* Q15 o : voicing factors */ - Word16 *exc_fx, /* Q_X o : adapt. excitation exc */ - Word16 *exc2_fx, /* Q_X o : adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* Q_X i/o: excitation for SWB TBE */ - Word16 *gain_buf ); -#endif -void decod_unvoiced_ivas_fx( Decoder_State *st_fx, /* i/o: decoder static memory */ const Word16 *Aq_fx, /* Q12 i : LP filter coefficient */ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ @@ -8621,38 +8356,20 @@ void gaus_L2_dec( Word16 *seed_acelp /*i/o : random seed Q0 */ ); -#ifndef REMOVE_EVS_DUPLICATES -// dec_gen_voic_fx.c ivas_error decod_gen_voic_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 sharpFlag_fx, /* i : formant sharpening flag */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - const Word16 do_WI_fx, /* i : do interpolation after a FER */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - Word16 *unbits, /* number of unused bits */ - Word16 *gain_buf /*Q14*/ -); -#endif -ivas_error decod_gen_voic_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 sharpFlag_fx, /* i : formant sharpening flag */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - const Word16 do_WI_fx, /* i : do interpolation after a FER */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - Word16 *unbits, /* number of unused bits */ - Word16 *gain_buf, + Decoder_State *st_fx, /* i/o: decoder static memory */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 sharpFlag_fx, /* i : formant sharpening flag */ + const Word16 *Aq_fx, /* i : LP filter coefficient */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + const Word16 do_WI_fx, /* i : do interpolation after a FER */ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ + Word16 *voice_factors_fx, /* o : voicing factors */ + Word16 *exc_fx, /* i/o: adapt. excitation exc */ + Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ + Word16 *unbits, /* number of unused bits */ + Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ ); @@ -9582,33 +9299,6 @@ void d_gain_pred_fx( Word16 **pt_indice /* i/o: pointer to the buffer of indices */ ); -#ifndef REMOVE_EVS_DUPLICATES -// acelp_core_dec_fx.c -ivas_error acelp_core_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 output[], /* o : synthesis @internal Fs */ - Word16 synth_out[], /* o : synthesis */ - Word16 save_hb_synth[], /* o : HB synthesis */ - Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis for SWB BWE */ - Word16 sharpFlag, - Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe */ - Word16 *unbits, /* o : number of unused bits */ - Word16 *sid_bw /* o : 0-NB/WB, 1-SWB SID */ - , - STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ - const Word16 tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */ - const Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - const Word16 last_element_mode, /* i : last element mode */ - const Word32 last_element_brate, /* i : last element bitrate */ - const Word16 flag_sec_CNA, /* i : CNA flag for secondary channel */ - const Word16 nchan_out, /* i : number of output channels */ - STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */ - const Word16 read_sid_info /* i : read SID info flag */ -); -#endif // evs_dec_fx.c ivas_error evs_dec_fx( Decoder_State *st_fx, /* i/o : Decoder state structure */ @@ -10678,7 +10368,7 @@ Word16 swb_bwe_dec_fx32( Word16 output_frame /* i : frame length */ ); -ivas_error acelp_core_dec_ivas_fx( +ivas_error acelp_core_dec_fx( Decoder_State *st, /* i/o: decoder state structure */ Word16 output_fx[], /* o : synthesis @internal Fs */ Word16 synth_fx16[], /* o : synthesis */ @@ -10975,6 +10665,7 @@ Word16 ari_decode_14bits_pow_ivas( Word16 *res, Tastat *s, UWord16 base ); + Word16 ari_decode_14bits_sign_ivas( Word16 *ptr, Word16 bp, @@ -10988,22 +10679,21 @@ void lsf_syn_mem_backup_ivas_fx( Word32 *gc_threshold_fx, /* i: Q16 */ Word16 *clip_var_bck_fx, /* o: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ Word16 *next_force_sf_bck_fx, /* o: */ - - Word16 *lsp_new, /* i: LSP vector to quantize Q15 */ - Word16 *lsp_mid, /* i: mid-frame LSP vector Q15 */ - Word16 *clip_var, /* o: pitch clipping state var Q(2.56) */ - Word16 *mem_AR, /* o: quantizer memory for AR model Q(2.56) */ - Word16 *mem_MA, /* o: quantizer memory for AR model Q(2.56) */ - Word16 *lsp_new_bck, /* o: LSP vector to quantize- backup Q15 */ - Word16 *lsp_mid_bck, /* o: mid-frame LSP vector - backup Q15 */ - Word32 *Bin_E, /* o: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ - Word32 *Bin_E_old, /* o: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ - Word16 *mem_syn_bck, /* o: synthesis filter memory ( 15 - st_fx->hLPDmem->e_mem_syn ) */ - Word16 *mem_w0_bck, /* o: memory of the weighting filter ( 15 - st_fx->hLPDmem->e_mem_syn ) */ - Word16 *streaklimit, /* Q15 */ + Word16 *lsp_new, /* i: LSP vector to quantize Q15 */ + Word16 *lsp_mid, /* i: mid-frame LSP vector Q15 */ + Word16 *clip_var, /* o: pitch clipping state var Q(2.56) */ + Word16 *mem_AR, /* o: quantizer memory for AR model Q(2.56) */ + Word16 *mem_MA, /* o: quantizer memory for AR model Q(2.56) */ + Word16 *lsp_new_bck, /* o: LSP vector to quantize- backup Q15 */ + Word16 *lsp_mid_bck, /* o: mid-frame LSP vector - backup Q15 */ + Word32 *Bin_E, /* o: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ + Word32 *Bin_E_old, /* o: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ + Word16 *mem_syn_bck, /* o: synthesis filter memory ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 *mem_w0_bck, /* o: memory of the weighting filter ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 *streaklimit, /* Q15 */ Word16 *pstreaklen ); -ivas_error config_acelp1_IVAS( +ivas_error config_acelp1_fx( const Word16 enc_dec, /* i : encoder/decoder flag */ const Word32 total_brate, /* i : total bitrate */ const Word32 core_brate_inp, /* i : core bitrate */ diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 2c0da33f5..fd841b67b 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -7359,33 +7359,27 @@ void tbe_celp_exc( /* _ None */ /*======================================================================================*/ -#ifndef REMOVE_EVS_DUPLICATES void prep_tbe_exc_fx( - const Word16 L_frame_fx, /* i : length of the frame */ -#ifdef ADD_IVAS_TBE_CODE - const Word16 L_subfr, -#endif - const Word16 i_subfr_fx, /* i : subframe index */ - const Word16 gain_pit_fx, /* i : Pitch gain Q14*/ - const Word32 gain_code_fx, /* i : algebraic codebook gain 16+Q_exc*/ - const Word16 code_fx[], /* i : algebraic excitation Q9*/ - const Word16 voice_fac_fx, /* i : voicing factor Q15*/ - Word16 *voice_factors_fx, /* o : TBE voicing factor Q15*/ - Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/ - const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */ - const Word16 code_preQ_fx[], /* i : prequantizer excitation */ - const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ - Word16 T0, /* i : integer pitch variables Q0 */ - Word16 T0_frac, /* i : Fractional pitch variables Q0*/ - const Word16 coder_type, /* i : coding type */ - Word32 core_brate -#ifdef ADD_IVAS_TBE_CODE - , /* i : core bitrate */ - const int16_t element_mode, /* i : element mode */ - const int16_t idchan, /* i : channel ID */ - const int16_t flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */ - const int16_t tdm_LRTD_flag /* i : LRTD stereo mode flag */ -#endif + const Word16 L_frame_fx, /* i : length of the frame */ + const Word16 L_subfr, /* i : subframe length */ + const Word16 i_subfr_fx, /* i : subframe index */ + const Word16 gain_pit_fx, /* i : Pitch gain Q14*/ + const Word32 gain_code_fx, /* i : algebraic codebook gain 16+Q_exc*/ + const Word16 code_fx[], /* i : algebraic excitation Q9*/ + const Word16 voice_fac_fx, /* i : voicing factor Q15*/ + Word16 *voice_factors_fx, /* o : TBE voicing factor Q15*/ + Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/ + const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */ + const Word16 code_preQ_fx[], /* i : prequantizer excitation */ + const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ + Word16 T0, /* i : integer pitch variables Q0 */ + Word16 T0_frac, /* i : Fractional pitch variables Q0*/ + const Word16 coder_type, /* i : coding type */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 element_mode, /* i : element mode */ + const Word16 idchan, /* i : channel ID */ + const Word16 flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */ + const Word16 tdm_LRTD_flag /* i : LRTD stereo mode flag */ ) { Word16 i; @@ -7396,176 +7390,6 @@ void prep_tbe_exc_fx( Word16 tmp /*, tmp1, tmp2*/; /*Word16 random_code[L_SUBFR * HIBND_ACB_L_FAC];*/ Word16 pitch; - - Word32 L_tmp, Ltemp1, Ltemp2; - Word32 tempQ31; - Word16 tempQ15; -#ifndef ADD_IVAS_TBE_CODE - Word16 L_subfr = L_SUBFR; - move16(); -#endif -#ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; - move32(); -#endif - - /**voice_factors = VF_0th_PARAM + VF_1st_PARAM * voice_fac + VF_2nd_PARAM * voice_fac * voice_fac; - = VF_0th_PARAM + voice_fac * (VF_1st_PARAM + VF_2nd_PARAM * voice_fac ) - *voice_factors = min( max_val(0.0f, *voice_factors), 1.0f); */ - tempQ31 = L_deposit_h( VF_1st_PARAM_FX ); - tempQ15 = mac_r( tempQ31, VF_2nd_PARAM_FX, voice_fac_fx ); - tempQ31 = L_deposit_h( VF_0th_PARAM_FX ); - *voice_factors_fx = mac_r( tempQ31, voice_fac_fx, tempQ15 ); - move16(); - tmp = MAX_16; - move16(); - - pitch = shl_o( add( shl_o( T0, 2, &Overflow ), T0_frac ), 5, &Overflow ); /* Q7 */ - - test(); - test(); - IF( ( ( EQ_16( coder_type, VOICED ) ) || ( GT_16( pitch, 14784 /* 115.5 in Q7 */ ) ) ) && ( GT_32( core_brate, ACELP_8k00 ) ) ) - { - tmp = MAX_16; - move16(); - *voice_factors_fx = mult_r( *voice_factors_fx, tmp ); - move16(); - } - - *voice_factors_fx = s_min( s_max( *voice_factors_fx, 0 ), MAX_16 ); - move16(); -#ifdef ADD_IVAS_TBE_CODE - IF( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( idchan, 1 ) && !tdm_LRTD_flag ) - { - IF( flag_TD_BWE && i_subfr == 0 ) - { - set16_fx( bwe_exc, 0, L_FRAME32k ); - } - return; - } - -#endif - IF( EQ_16( L_frame_fx, L_FRAME ) ) - { - interp_code_5over2_fx( code_fx, tmp_code_fx, L_subfr ); /* code: Q9, tmp_code: Q9 */ - gain_code16 = round_fx_o( L_shl_o( gain_code_fx, Q_exc, &Overflow ), &Overflow ); /*Q_exc */ - FOR( i = 0; i < L_subfr * HIBND_ACB_L_FAC; i++ ) - { - L_tmp = L_mult( gain_code16, tmp_code_fx[i] ); /* Q9 + Q_exc + 1*/ - L_tmp = L_shl_sat( L_tmp, 5 ); /* Q9 + Q_exc + Q6*/ - L_tmp = L_mac_sat( L_tmp, gain_pit_fx, bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] ); /*Q15+Q_exc */ - L_tmp = L_shl_o( L_tmp, 1, &Overflow ); /*16+Q_exc */ /* saturation can occur here */ - bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] = round_fx_o( L_tmp, &Overflow ); /*Q_exc */ - move16(); - } - } - ELSE - { - IF( gain_preQ_fx != 0 ) - { - FOR( i = 0; i < L_subfr; i++ ) - { - /*code in the encoder is Q9 and there is no <<1 with Mult_32_16 Q16 * Q9 -> Q9 */ - Ltemp1 = Mult_32_16( gain_code_fx, code_fx[i] ); /* Q16 + Q9 + 1 - 16 = Q10 */ - Ltemp2 = L_mult( gain_preQ_fx, code_preQ_fx[i] ); /*Q2 * Q10 -> Q12 */ - - Ltemp1 = L_shl_o( Ltemp1, add( Q_exc, 6 ) /*Q_exc+16-19*/, &Overflow ); /*Q_exc+16 */ - Ltemp2 = L_shl_o( Ltemp2, add( Q_exc, 4 ) /*Q_exc+16-13*/, &Overflow ); /*Q_exc+16 */ - - tmp_code_preInt_fx[i] = round_fx_o( L_add_o( Ltemp1, Ltemp2, &Overflow ), &Overflow ); /* Q_exc */ - move16(); - } - } - ELSE - { - FOR( i = 0; i < L_subfr; i++ ) - { - /*code in the encoder is Q9 and there is no <<1 with Mult_32_16 Q16 * Q9 -> Q9 */ - Ltemp1 = Mult_32_16( gain_code_fx, code_fx[i] ); /* Q16 + Q9 + 1 - 16 = Q10 */ - Ltemp1 = L_shl_o( Ltemp1, add( Q_exc, 6 ) /*Q_exc+16-19*/, &Overflow ); /*Q_exc+16 */ - tmp_code_preInt_fx[i] = round_fx_o( Ltemp1, &Overflow ); /* Q_exc */ - move16(); - } - } - - interp_code_4over2_fx( tmp_code_preInt_fx, tmp_code_fx, L_subfr ); /* o: tmp_code in Q_exc */ - FOR( i = 0; i < L_subfr * 2; i++ ) - { - L_tmp = L_mult( gain_pit_fx, bwe_exc_fx[i + i_subfr_fx * 2] ); /*Q14+Q_exc+1 */ - tmp = round_fx_o( L_shl_o( L_tmp, 1 /* (Q_exc+16)-(14+Q_exc+1)*/, &Overflow ), &Overflow ); /* tmp in Q_exc */ - bwe_exc_fx[i + i_subfr_fx * 2] = add_o( tmp, tmp_code_fx[i], &Overflow ); /*Q_exc */ - move16(); - } - } - - return; -} - -/*======================================================================================*/ -/* FUNCTION : prep_tbe_exc_ivas_fx() */ -/*--------------------------------------------------------------------------------------*/ -/* PURPOSE : Prepare TBE excitation */ -/*--------------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) L_frame_fx : length of the frame */ -/* _ (Word16) i_subfr_fx : subframe index */ -/* _ (Word16) gain_pit_fx : Pitch gain (14) */ -/* _ (Word32) gain_code_fx : algebraic codebook gain (Q(16+Q_exc)) */ -/* _ (Word16*[]) code_fx : algebraic excitation (Q9) */ -/* _ (Word16) voice_fac_fx : voicing factor (Q15) */ -/* _ (Word16) gain_preQ_fx : prequantizer excitation gain */ -/* _ (Word16[]) code_preQ_fx : prequantizer excitation */ -/*--------------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*[]) voice_factors_fx : TBE voicing factor (Q15) */ -/*--------------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16[]) bwe_exc_fx : excitation for TBE (Q_exc) */ -/*--------------------------------------------------------------------------------------*/ - -/* _ None */ -/*--------------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*======================================================================================*/ -#endif -void prep_tbe_exc_ivas_fx( - const Word16 L_frame_fx, /* i : length of the frame */ -#if 1 // def ADD_IVAS_TBE_CODE - const Word16 L_subfr, -#endif - const Word16 i_subfr_fx, /* i : subframe index */ - const Word16 gain_pit_fx, /* i : Pitch gain Q14*/ - const Word32 gain_code_fx, /* i : algebraic codebook gain 16+Q_exc*/ - const Word16 code_fx[], /* i : algebraic excitation Q9*/ - const Word16 voice_fac_fx, /* i : voicing factor Q15*/ - Word16 *voice_factors_fx, /* o : TBE voicing factor Q15*/ - Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/ - const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */ - const Word16 code_preQ_fx[], /* i : prequantizer excitation */ - const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ - Word16 T0, /* i : integer pitch variables Q0 */ - Word16 T0_frac, /* i : Fractional pitch variables Q0*/ - const Word16 coder_type, /* i : coding type */ - Word32 core_brate -#if 1 // def ADD_IVAS_TBE_CODE - , /* i : core bitrate */ - const Word16 element_mode, /* i : element mode */ - const Word16 idchan, /* i : channel ID */ - const Word16 flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */ - const Word16 tdm_LRTD_flag /* i : LRTD stereo mode flag */ -#endif -) -{ - Word16 i; - Word16 tmp_code_fx[2 * L_SUBFR * HIBND_ACB_L_FAC]; - Word16 tmp_code_preInt_fx[L_SUBFR]; - Word16 gain_code16 = 0; - move16(); - Word16 tmp /*, tmp1, tmp2*/; - /*Word16 random_code[L_SUBFR * HIBND_ACB_L_FAC];*/ - Word16 pitch; - Word32 L_tmp, Ltemp1, Ltemp2; Word32 tempQ31; Word16 tempQ15; @@ -7600,7 +7424,7 @@ void prep_tbe_exc_ivas_fx( *voice_factors_fx = s_min( s_max( *voice_factors_fx, 0 ), MAX_16 ); move16(); -#if 1 // def ADD_IVAS_TBE_CODE + test(); test(); IF( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( idchan, 1 ) && !tdm_LRTD_flag ) @@ -7613,7 +7437,6 @@ void prep_tbe_exc_ivas_fx( return; } -#endif IF( EQ_16( L_frame_fx, L_FRAME ) ) { interp_code_5over2_fx( code_fx, tmp_code_fx, L_subfr ); /* code: Q9, tmp_code: Q9 */ @@ -7672,6 +7495,7 @@ void prep_tbe_exc_ivas_fx( return; } + /*=============================================================================*/ /* FUNCTION : void swb_formant_fac_fx ( ) */ /*------------------------------------------------------------------------------*/ @@ -7691,9 +7515,10 @@ void prep_tbe_exc_ivas_fx( /* CALLED FROM : */ /*==============================================================================*/ -Word16 swb_formant_fac_fx( /* o : Formant filter strength [0,1] */ - const Word16 lpc_shb2, /* Q12 i : 2nd HB LPC coefficient */ - Word16 *tilt_mem /* i/o: Tilt smoothing memory (Q12) */ +/*! r: Formant filter strength [0,1] */ +Word16 swb_formant_fac_fx( + const Word16 lpc_shb2, /* Q12 i : 2nd HB LPC coefficient */ + Word16 *tilt_mem /* i/o: Tilt smoothing memory (Q12) */ ) { Word16 formant_fac; @@ -7713,7 +7538,6 @@ Word16 swb_formant_fac_fx( /* o : Formant filter strength tmp = sub( tmp, SWB_TILT_LOW_FX ); /* Q12 */ formant_fac = mult_r( tmp, SWB_TILT_DELTA_FX ); /* Q12 */ - IF( GT_16( formant_fac, 4096 /* 1 in Q12 */ ) ) { formant_fac = 4096; /* 1 in Q12 */ @@ -7733,6 +7557,12 @@ Word16 swb_formant_fac_fx( /* o : Formant filter strength } +/*-------------------------------------------------------------------* + * wb_tbe_extras_reset_fx() + * + * + *-------------------------------------------------------------------*/ + void wb_tbe_extras_reset_fx( Word16 mem_genSHBexc_filt_down_wb2[], Word16 mem_genSHBexc_filt_down_wb3[] ) @@ -7749,7 +7579,6 @@ void wb_tbe_extras_reset_fx( * Determine TBE bit consumption per frame from bitrate * *-------------------------------------------------------------------*/ - Word16 get_tbe_bits_fx( const Word32 total_brate, /* o : TBE bit consumption per frame */ const Word16 bwidth, /* i : overall bitrate */ diff --git a/lib_dec/FEC_fx.c b/lib_dec/FEC_fx.c index a23c9aa90..48d91a87a 100644 --- a/lib_dec/FEC_fx.c +++ b/lib_dec/FEC_fx.c @@ -510,19 +510,10 @@ void FEC_exc_estim_fx( move16(); /* st_fx->L_frame / L_SUBFR */ tmp = shr( st_fx->L_frame, 6 ); + /* Replication of the last spectrum, with a slight downscaling of its dynamic */ -#ifdef REMOVE_EVS_DUPLICATES - gsc_dec_ivas_fx( st_fx, exc_dct_in, hGSCDec->Last_GSC_pit_band_idx, Diff_len, 0, tmp, st_fx->last_coder_type, &last_bin_fx, lsf_new, NULL, &st_fx->Q_exc ); -#else - IF( st_fx->element_mode == EVS_MONO ) - { - gsc_dec_fx( st_fx, exc_dct_in, hGSCDec->Last_GSC_pit_band_idx, Diff_len, 0, tmp, st_fx->last_coder_type, &last_bin_fx, lsf_new, NULL, st_fx->Q_exc ); - } - ELSE - { - gsc_dec_ivas_fx( st_fx, exc_dct_in, hGSCDec->Last_GSC_pit_band_idx, Diff_len, 0, tmp, st_fx->last_coder_type, &last_bin_fx, lsf_new, NULL, &st_fx->Q_exc ); - } -#endif + gsc_dec_fx( st_fx, exc_dct_in, hGSCDec->Last_GSC_pit_band_idx, Diff_len, 0, tmp, st_fx->last_coder_type, &last_bin_fx, lsf_new, NULL, &st_fx->Q_exc ); + *tmp_noise = shr_r( st_fx->lp_gainc_fx, 3 ); /*Q0*/ move16(); /* Transform back to time domain */ diff --git a/lib_dec/FEC_scale_syn_fx.c b/lib_dec/FEC_scale_syn_fx.c index 714a60166..7f4586083 100644 --- a/lib_dec/FEC_scale_syn_fx.c +++ b/lib_dec/FEC_scale_syn_fx.c @@ -50,7 +50,6 @@ /* _ None */ /*========================================================================*/ -#ifndef REMOVE_EVS_DUPLICATES void FEC_scale_syn_fx( const Word16 L_frame, /* i : length of the frame */ Word16 *update_flg, /* o: flag indicating re-synthesis after scaling*/ @@ -77,574 +76,7 @@ void FEC_scale_syn_fx( Word16 *mem_syn, /* o: initial synthesis filter states Q_syn*/ Word16 Q_exc, Word16 Q_syn, - const Word16 avoid_lpc_burst_on_recovery, /* i : if true the excitation energy is limited if LP has big gain */ - const Word16 force_scaling /* i: force scaling */ -) -{ - Word16 i; - Word32 L_enr1, L_enr2; - Word16 gain1, gain2, enr_LP; - Word16 tmp, tmp2, exp, exp2; - Word16 tmp3; - Word32 L_tmp; - Word16 scaling; - Word32 ener_max, L_enr2_av, L_ener2_max; - Word16 h1[L_FRAME / 2], tilt, pitch_dist, mean_pitch; - Word16 k; - Word32 L_mean_pitch; - - enr_LP = 0; - move16(); - gain2 = 0; - move16(); - gain1 = 0; - move16(); - *update_flg = 0; - move16(); - L_enr_old = L_max( 1, L_enr_old ); /* to avoid division by zero (*L_enr_old is always >= 0) */ - scaling = 16384; - move16(); /* Q14*/ - - /*-----------------------------------------------------------------* - * Find the synthesis filter impulse response on voiced - *-----------------------------------------------------------------*/ - test(); - IF( GE_16( clas, VOICED_TRANSITION ) && LT_16( clas, INACTIVE_CLAS ) ) - { - IF( EQ_16( L_frame, L_FRAME ) ) - { - enr_LP = Enr_1_Az_fx( Aq + ( NB_SUBFR - 1 ) * ( M + 1 ), L_SUBFR ); - } - ELSE /* L_frame == L_FRAME16k */ - { - enr_LP = Enr_1_Az_fx( Aq + ( NB_SUBFR16k - 1 ) * ( M + 1 ), L_SUBFR ); /*Q3*/ - } - } - - /*-----------------------------------------------------------------* - * Define when to scale the synthesis - *-----------------------------------------------------------------*/ - - IF( bfi ) - { - *scaling_flag = 1; - move16(); /* Always check synthesis on bad frames */ - } - ELSE IF( prev_bfi ) - { - test(); - IF( ( EQ_16( LSF_Q_prediction, AUTO_REGRESSIVE ) ) || ( EQ_16( LSF_Q_prediction, MOVING_AVERAGE ) ) ) - { - *scaling_flag = 2; - move16(); /* Decoded LSFs affected */ - } - ELSE IF( NE_16( coder_type, TRANSITION ) ) - { - *scaling_flag = 1; - move16(); /* SN, but not TC mode - LSF still affected by the interpolation */ - } - ELSE - { - *scaling_flag = 0; - move16(); /* LSF still possibly affected due to interpolation */ - } - scaling = 24576; /*1.5 Q14*/ - move16(); - } - ELSE - { - test(); - IF( ( EQ_16( LSF_Q_prediction, AUTO_REGRESSIVE ) ) && ( EQ_16( *scaling_flag, 2 ) ) ) - { - *scaling_flag = 2; - move16(); /* Continue with energy control till the end of AR prediction */ - } - ELSE IF( *scaling_flag > 0 ) - { - ( *scaling_flag ) = sub( *scaling_flag, 1 ); /* If scaling flag was equal to 2, add one control frame to account for the LSF interpolation */ - move16(); - } - scaling = 32767; /*2.0 Q14*/ - move16(); - } - - /*-----------------------------------------------------------------* - * Find the energy/gain at the end of the frame - *-----------------------------------------------------------------*/ - - frame_ener_fx( L_frame, clas, synth, pitch[( L_frame >> 6 ) - 1], &L_enr2 /*Q0*/, 1, Q_syn, 3, 0 ); - - - test(); - test(); - IF( bfi || ( EQ_32( total_brate, ACELP_7k20 ) ) || ( EQ_32( total_brate, ACELP_8k00 ) ) ) - { - /* previous frame erased and no TC frame */ - IF( *scaling_flag > 0 ) - { - /*enr2 += 0.01f;*/ - L_enr2 = L_max( L_enr2, 1 ); /* L_enr2 is in Q0 */ - - IF( bfi ) /* In all bad frames, limit the gain to 1 */ - { - /* gain2 = (float)sqrt( enr_old / enr2 );*/ - L_tmp = Sqrt_Ratio32( L_enr_old, 0, L_enr2, 0, &exp2 ); - gain2 = round_fx_sat( L_shl_sat( L_tmp, sub( exp2, 1 ) ) ); /* in Q14 */ - - /*if( gain2 > 1.0f )gain2 = 1.0f;*/ - gain2 = s_min( gain2, 16384 ); - - /* find the energy/gain at the beginning of the frame */ - frame_ener_fx( L_frame, clas, synth, pitch[0], &L_enr1 /*Q0*/, 1, Q_syn, 3, 0 ); - - /*enr1 += 0.1f;*/ - L_enr1 = L_max( L_enr1, 1 ); /* L_enr2 is in Q0 */ - - /*gain1 = (float)sqrt( enr_old / enr1 );*/ - L_tmp = Sqrt_Ratio32( L_enr_old, 0, L_enr1, 0, &exp2 ); - gain1 = round_fx_sat( L_shl_sat( L_tmp, sub( exp2, 1 ) ) ); /* in Q14 */ - - /*if( gain1 > 1.0f )gain1 = 1.0f;*/ - gain1 = s_min( gain1, 16384 ); /*Q14*/ - } - ELSE /* good frame */ - { - IF( L_enr_q == 0 ) /* If E info (FEC protection bits) is not available in the bitstream */ - { - L_enr_q = L_enr2; /*Q0*/ - set16_fx( h1, 0, L_FRAME / 2 ); - h1[0] = 1024; /*1.0f in Q10*/ - move16(); - /*syn_filt( Aq+(3*(M+1)), M, h1, h1, L_FRAME/2, h1+(M+1), 0 );*/ - E_UTIL_synthesis( 1, Aq + ( 3 * ( M + 1 ) ), h1, h1, L_FRAME / 2, h1 + ( M + 1 ), 0, M ); - - /*Compute tilt */ - /*rr0 = dotp( h1, h1, L_FRAME/2-1 ) + 0.1f;*/ - /*rr1 = dotp( h1, h1+1, L_FRAME/2-1 );*/ - /*tilt = rr1 / rr0;*/ - tilt = extract_h( L_shl_sat( get_gain( h1 + 1, h1, L_FRAME / 2 - 1 ), 15 ) ); /*Q15*/ - pitch_dist = 0; - move16(); - L_mean_pitch = L_mult( pitch[0], 8192 /*1.0f in Q13*/ ); /*Q14*/ - FOR( k = 0; k < ( NB_SUBFR - 1 ); k++ ) - { - pitch_dist = add( pitch_dist, abs_s( sub( pitch[k + 1], pitch[k] ) ) ); /*Q0*/ - L_mean_pitch = L_mac( L_mean_pitch, pitch[k + 1], 8192 ); /*Q14*/ - } - /*pitch_dist /= (float)(NB_SUBFR-1); */ - pitch_dist = mult_r( shl( pitch_dist, 4 ), 10923 /*1/(float)(NB_SUBFR-1) in Q15*/ ); /*Q4*/ - /*mean_pitch /= (float)(NB_SUBFR);*/ - mean_pitch = extract_h( L_shl( L_mean_pitch, 4 ) ); /*Q4*/ - - - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( GT_16( tilt, 22938 ) ) && /* HF resonnant filter */ - ( ( GT_16( pitch_dist, 8 << 4 ) ) || ( LT_16( mean_pitch, PIT_MIN << 4 ) ) ) && /* pitch unstable or very short */ - ( ( prev_bfi ) || ( ( EQ_16( coder_type, GENERIC ) ) && ( EQ_16( LSF_Q_prediction, AUTO_REGRESSIVE ) ) ) ) ) - { - /*if( enr_q > scaling * enr_old ){enr_q = scaling * enr_old;}*/ - L_enr_q = L_min( L_enr_q, L_shl_sat( Mult_32_16( L_enr_old, scaling ), 1 ) ); /* scaling in Q14*/ - } - ELSE - { - ener_max = *lp_ener_FEC_max; /*Q0*/ - move32(); - test(); - if ( EQ_16( clas, VOICED_TRANSITION ) || ( GE_16( clas, INACTIVE_CLAS ) ) ) - { - ener_max = *lp_ener_FEC_av; /*Q0*/ - move32(); - } - /*if( enr_old > ener_max )ener_max = enr_old;*/ - ener_max = L_max( ener_max, L_enr_old ); - - /*if( enr_q > scaling * ener_max ){enr_q = scaling * ener_max;}*/ - L_enr_q = L_min( L_enr_q, L_shl_sat( Mult_32_16( ener_max, scaling ), 1 ) ); /* scaling in Q14*/ - } - } - /*gain2 = (float)sqrt( enr_q / enr2 );*/ - L_enr_q = L_max( L_enr_q, 1 ); /* L_enr2 is in Q0 */ - L_tmp = Sqrt_Ratio32( L_enr_q, 0, L_enr2, 0, &exp2 ); - gain2 = round_fx( L_shl( L_tmp, sub( exp2, 1 ) ) ); /* in Q14 */ - - /*-----------------------------------------------------------------* - * Find the energy/gain at the beginning of the frame to ensure smooth transition after erasure(s) - *-----------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( ( GE_16( last_good, VOICED_TRANSITION ) && LT_16( last_good, INACTIVE_CLAS ) && ( clas == UNVOICED_CLAS || EQ_16( clas, INACTIVE_CLAS ) ) ) || - EQ_32( last_core_brate, SID_1k75 ) || EQ_32( last_core_brate, SID_2k40 ) || last_core_brate == FRAME_NO_DATA ) && - prev_bfi ) - { - /* voiced -> unvoiced signal transition */ - /* CNG -> active signal transition */ - gain1 = gain2; /*Q14*/ - move16(); - } - ELSE - { - /* find the energy at the beginning of the frame */ - frame_ener_fx( L_frame, clas, synth, pitch[0], &L_enr1 /*Q0*/, 1, Q_syn, 3, 0 ); - - /*enr1 += 0.1f;*/ - L_enr1 = L_max( L_enr1, 1 ); /* L_enr1 is in Q0 */ - - /*gain1 = (float)sqrt( enr_old / enr1 );*/ - L_tmp = Sqrt_Ratio32( L_enr_old, 0, L_enr1, 0, &exp2 ); - gain1 = round_fx_sat( L_shl_sat( L_tmp, sub( exp2, 1 ) ) ); /* in Q14 */ - - /*if( gain1 > 1.2f )gain1 = 1.2f;*/ - /* prevent clipping */ - gain1 = s_min( gain1, 19661 /*1.2f in Q14*/ ); - - /* prevent amplifying the unvoiced or inactive part of the frame in case an offset is followed by an onset */ - test(); - test(); - if ( EQ_16( clas, ONSET ) && GT_16( gain1, gain2 ) && prev_bfi ) - { - gain1 = gain2; /*Q14*/ - move16(); - } - } - - L_enr2 = L_enr_q; /*Q0*/ - move32(); /* Set the end frame energy to the scaled energy, to be used in the lp_ener_FEC */ - } - - /*------------------------------------------------------------------------------* - * Smooth the energy evolution by exponentially evolving from gain1 to gain2 - *------------------------------------------------------------------------------*/ - - /*gain2 *= ( 1.0f - AGC );*/ - L_tmp = L_mult( gain2, (Word16) ( 32768 /*Q15*/ - AGC_FX ) ); /*Q30*/ - FOR( i = 0; i < L_frame; i++ ) - { - /*gain1 = gain1 * AGC + gain2;*/ - gain1 = mac_r( L_tmp, gain1, AGC_FX ); /* in Q14 */ - /*exc[i] *= gain1;*/ - exc[i] = mac_r( L_mult( exc[i], gain1 ), exc[i], gain1 ); - move16(); - /*exc2[i] *= gain1;*/ - exc2[i] = mac_r_sat( L_mult( exc2[i], gain1 ), exc2[i], gain1 ); - move16(); - } - /* smoothing is done in excitation domain, so redo synthesis */ - Copy( mem_tmp, mem_syn, M ); /* Q_syn */ - syn_12k8_fx( L_frame, Aq, exc2, synth, mem_syn, 1, Q_exc, Q_syn ); - *update_flg = 1; - move16(); - } - } - ELSE - { - /* previous frame erased and no TC frame */ - test(); - IF( prev_bfi && NE_16( coder_type, TRANSITION ) ) - { - IF( L_enr_q == 0 ) - { - L_enr_q = L_max( 1, L_enr2 ); /* sets to 'L_enr2' in 1 clock */ - set16_fx( h1, 0, L_FRAME / 2 ); - h1[0] = 1024; /*1.0f in Q10*/ - move16(); - /*syn_filt( Aq+(3*(M+1)), M, h1, h1, L_FRAME/2, h1+(M+1), 0 );*/ - E_UTIL_synthesis( 1, Aq + ( 3 * ( M + 1 ) ), h1, h1, L_FRAME / 2, h1 + ( M + 1 ), 0, M ); - /*Compute tilt */ - /*rr0 = dotp( h1, h1, L_FRAME/2-1 ) + 0.1f;*/ - /*rr1 = dotp( h1, h1+1, L_FRAME/2-1 );*/ - /*tilt = rr1 / rr0;*/ - tilt = extract_h( L_shl_sat( get_gain( h1 + 1, h1, L_FRAME / 2 - 1 ), 15 ) ); /*Q15*/ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( ( ( EQ_32( total_brate, ACELP_13k20 ) ) || ( EQ_32( total_brate, ACELP_12k85 ) ) || ( EQ_32( total_brate, ACELP_12k15 ) ) || ( EQ_32( total_brate, ACELP_11k60 ) ) || - ( EQ_32( total_brate, ACELP_9k60 ) ) ) && - ( GT_16( tilt, 22938 ) ) && /* HF resonnant filter */ - ( ( ( clas == UNVOICED_CLAS ) ) || ( EQ_16( clas, INACTIVE_CLAS ) ) ) ) ) /* unvoiced classification */ - { - /*if( enr_q > scaling * enr_old )enr_q = scaling * enr_old;*/ - L_enr_q = L_min( L_enr_q, L_shl_sat( Mult_32_16( L_enr_old, scaling ), 1 ) ); /* scaling in Q14*/ - } - ELSE IF( GE_16( last_good, VOICED_TRANSITION ) && LT_16( last_good, INACTIVE_CLAS ) && GE_16( clas, VOICED_TRANSITION ) && LT_16( clas, INACTIVE_CLAS ) ) - { - /* Voiced-voiced recovery */ - test(); - IF( *old_enr_LP != 0 && GT_16( enr_LP, shl_sat( *old_enr_LP, 1 ) ) ) - { - /* enr_q /= enr_LP */ - exp = norm_l( L_enr_q ); - tmp = extract_h( L_shl( L_enr_q, exp ) ); - - exp2 = norm_s( enr_LP ); - tmp2 = shl( enr_LP, exp2 ); - - exp = sub( exp2, exp ); - - tmp3 = sub( tmp, tmp2 ); - IF( tmp3 > 0 ) - { - tmp = shr( tmp, 1 ); - exp = add( exp, 1 ); - } - tmp = div_s( tmp, tmp2 ); - - /* L_enr_q *= 2 * *old_enr_LP */ - L_enr_q = L_shl( L_mult( tmp, shl( *old_enr_LP, 1 ) ), exp ); - } - - ELSE - { - test(); - IF( avoid_lpc_burst_on_recovery && GT_16( enr_LP, 160 /*20.0f in Q3*/ ) ) - { - exp = norm_s( enr_LP ); - tmp = shl( enr_LP, exp ); - - exp2 = 7; - move16(); - tmp2 = 160 << 7; /* 160 = 20.0f in Q3 */ - move16(); - exp = sub( exp2, exp ); - - IF( GT_16( tmp, tmp2 ) ) - { - tmp = shr( tmp, 1 ); - exp = add( exp, 1 ); - } - tmp = div_s( tmp, tmp2 ); /* tmp*2^exp = enr_LP/20.0 */ - L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* L_tmp*2^exp = sqrt(20.0/enr_LP) */ - L_enr_q = L_shl( Mpy_32_32( L_enr_q, L_tmp ), exp ); - } - } - } - - test(); - test(); - test(); - test(); - IF( ( GE_16( last_good, VOICED_TRANSITION ) && LT_16( last_good, INACTIVE_CLAS ) && GE_16( clas, VOICED_TRANSITION ) && LT_16( clas, INACTIVE_CLAS ) ) || force_scaling ) - { - - IF( GT_32( L_enr_q, L_enr_old ) ) /* Prevent energy to increase on voiced */ - { - L_enr_q = L_add( Mpy_32_16_1( L_enr_old, 32767 - SCLSYN_LAMBDA ), Mpy_32_16_1( L_enr_q, SCLSYN_LAMBDA ) ); /*Q0*/ - } - } - } - - L_enr_q = L_max( 1, L_enr_q ); - - /* gain2 = (float)sqrt( enr_q / enr2 );*/ - exp = norm_l( L_enr_q ); - tmp = extract_h( L_shl( L_enr_q, exp ) ); - - exp2 = norm_l( L_enr2 ); - tmp2 = extract_h( L_shl( L_enr2, exp2 ) ); - - exp2 = sub( exp, exp2 ); /* Denormalize and substract */ - - tmp3 = sub( tmp2, tmp ); - IF( tmp3 > 0 ) - { - tmp2 = shr( tmp2, 1 ); - exp2 = add( exp2, 1 ); - } - - tmp = div_s( tmp2, tmp ); - - L_tmp = L_deposit_h( tmp ); - L_tmp = Isqrt_lc( L_tmp, &exp2 ); - gain2 = round_fx_sat( L_shl_sat( L_tmp, sub( exp2, 1 ) ) ); /* in Q14 */ - /*-----------------------------------------------------------------* - * Clipping of the smoothing gain at the frame end - *-----------------------------------------------------------------*/ - - gain2 = s_min( gain2, 19661 /*1.2f in Q14*/ ); /* Gain modification clipping */ - if ( LT_32( L_enr_q, 2 ) ) - { - gain2 = s_min( gain2, 16384 /*1.0f in Q14*/ ); /* Gain modification clipping */ - } - - /*-----------------------------------------------------------------* - * Find the energy/gain at the beginning of the frame to ensure smooth transition after erasure(s) - *-----------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - test(); - test(); - IF( EQ_16( clas, SIN_ONSET ) ) /* slow increase */ - { - gain1 = shr( gain2, 1 ); /*0.5f * gain2*/ - } - /*------------------------------------------------------------* - * voiced->unvoiced transition recovery - *------------------------------------------------------------*/ - ELSE IF( ( GE_16( last_good, VOICED_TRANSITION ) && LT_16( last_good, INACTIVE_CLAS ) && ( clas == UNVOICED_CLAS || EQ_16( clas, INACTIVE_CLAS ) ) ) || /* voiced->unvoiced transition recovery */ - EQ_32( last_core_brate, SID_1k75 ) || EQ_32( last_core_brate, SID_2k40 ) || last_core_brate == FRAME_NO_DATA ) /* CNG -> active signal transition */ - { - gain1 = gain2; /*Q14*/ - move16(); - } - ELSE - { - /*--------------------------------------------------------* - * Find the energy at the beginning of the frame - *--------------------------------------------------------*/ - tmp = frame_ener_fx( L_frame, clas, synth, pitch[0], &L_enr1, 0, Q_syn, 3, 0 ); - - /*gain1 = (float)sqrt( enr_old / enr1 );*/ - exp = norm_l( L_enr_old ); - tmp = extract_h( L_shl( L_enr_old, exp ) ); - exp2 = norm_l( L_enr1 ); - tmp2 = extract_h( L_shl( L_enr1, exp2 ) ); - - exp2 = sub( exp, exp2 ); /* Denormalize and substract */ - - tmp3 = sub( tmp2, tmp ); - - IF( tmp3 > 0 ) - { - tmp2 = shr( tmp2, 1 ); - exp2 = add( exp2, 1 ); - } - - tmp = div_s( tmp2, tmp ); - - L_tmp = L_deposit_h( tmp ); - L_tmp = Isqrt_lc( L_tmp, &exp2 ); - gain1 = round_fx_sat( L_shl_sat( L_tmp, sub( exp2, 1 ) ) ); /* in Q14 */ - /* exp2 is always <= 1 */ - - gain1 = s_min( gain1, 19661 /*1.2F in Q14*/ ); - - test(); - test(); - if ( avoid_lpc_burst_on_recovery && ( GT_16( enr_LP, 160 ) ) && ( LE_16( enr_LP, shl_sat( *old_enr_LP, 1 ) ) ) ) - { - gain1 = s_min( gain1, 16384 /*1.0f in Q14*/ ); - } - - /*--------------------------------------------------------* - * Prevent a catastrophy in case of offset followed by onset - *--------------------------------------------------------*/ - test(); - if ( ( EQ_16( clas, ONSET ) ) && ( GT_16( gain1, gain2 ) ) ) - { - gain1 = gain2; /*Q14*/ - move16(); - } - } - /*-----------------------------------------------------------------* - * Smooth the energy evolution by exponentially evolving from - * gain1 to gain2 - *-----------------------------------------------------------------*/ - - L_tmp = L_mult( gain2, (Word16) ( 32768 /*Q15*/ - AGC_FX ) ); - - FOR( i = 0; i < L_frame; i++ ) - { - gain1 = mac_r( L_tmp, gain1, AGC_FX ); /* in Q14 */ - exc[i] = mac_r_sat( L_mult_sat( exc[i], gain1 ), exc[i], gain1 ); - move16(); - exc2[i] = mac_r_sat( L_mult_sat( exc2[i], gain1 ), exc2[i], gain1 ); - move16(); - } - - Copy( mem_tmp, mem_syn, M ); /* Q_syn */ - syn_12k8_fx( L_frame, Aq, exc2, synth, mem_syn, 1, Q_exc, Q_syn ); - *update_flg = 1; - move16(); - } - } - /*-----------------------------------------------------------------* - * Update low-pass filtered energy for voiced frames - *-----------------------------------------------------------------*/ - - test(); - test(); - IF( !bfi && ( GE_16( clas, VOICED_TRANSITION ) && LT_16( clas, INACTIVE_CLAS ) ) ) - { - IF( EQ_16( clas, VOICED_TRANSITION ) ) - { - L_enr2_av = L_enr2; /*Q0*/ - move32(); - frame_ener_fx( L_frame, VOICED_CLAS, synth, pitch[sub( shr( L_frame, 6 ), 1 )], &L_ener2_max /*Q0*/, 1, Q_syn, 3, 0 ); - } - ELSE - { - L_ener2_max = L_enr2; /*Q0*/ - move32(); - frame_ener_fx( L_frame, UNVOICED_CLAS, synth, pitch[sub( shr( L_frame, 6 ), 1 )], &L_enr2_av /*Q0*/, 1, Q_syn, 3, 0 ); - } - - /**lp_ener_FEC_av = 0.2f * enr2_av + 0.8f * *lp_ener_FEC_av; move32();*/ - *lp_ener_FEC_av = Madd_32_16( Mult_32_16( *lp_ener_FEC_av, 31130 /*0.95f in Q15*/ ), L_enr2_av, 1638 /*0.05F Q15*/ ); /*Q0*/ - move32(); - /**lp_ener_FEC_max = 0.2f * enr2_max + 0.8f * *lp_ener_FEC_max; move32();*/ - *lp_ener_FEC_max = Madd_32_16( Mult_32_16( *lp_ener_FEC_max, 31130 /*0.95f in Q15*/ ), L_ener2_max, 1638 /*0.05F Q15*/ ); /*Q0*/ - move32(); - } - - /*-----------------------------------------------------------------* - * Update the LP filter energy for voiced frames - *-----------------------------------------------------------------*/ - test(); - if ( GE_16( clas, VOICED_TRANSITION ) && LT_16( clas, INACTIVE_CLAS ) ) - { - *old_enr_LP = enr_LP; /*Q3*/ - move16(); - } - - return; -} -#endif -void FEC_scale_syn_ivas_fx( - const Word16 L_frame, /* i : length of the frame */ - Word16 *update_flg, /* o: flag indicating re-synthesis after scaling*/ - Word16 clas, /* i/o: frame classification */ - const Word16 last_good, /* i: last good frame classification */ - Word16 *synth, /* i/o: synthesized speech at Fs = 12k8 Hz Q_syn*/ - const Word16 *pitch, /* i: pitch values for each subframe Q0*/ - Word32 L_enr_old, /* i: energy at the end of previous frame */ - Word32 L_enr_q, /* i: transmitted energy for current frame */ - const Word16 coder_type, /* i: coder type */ - const Word16 LSF_Q_prediction, /* i : LSF prediction mode */ - Word16 *scaling_flag, /* i/o: flag to indicate energy control of syn */ - Word32 *lp_ener_FEC_av, /* i/o: averaged voiced signal energy Q0*/ - Word32 *lp_ener_FEC_max, /* i/o: averaged voiced signal energy Q0*/ - const Word16 bfi, /* i: current frame BFI */ - const Word32 total_brate, /* i: total bitrate */ - const Word16 prev_bfi, /* i: previous frame BFI */ - const Word32 last_core_brate, /* i: previous frame core bitrate */ - Word16 *exc, /* i/o: excitation signal without enhancement */ - Word16 *exc2, /* i/o: excitation signal with enhancement */ - Word16 Aq[], /* i/o: LP filter coefs (can be modified if BR) Q12*/ - Word16 *old_enr_LP, /* i/o: LP filter E of last good voiced frame Q3*/ - const Word16 *mem_tmp, /* i: temp. initial synthesis filter states Q_syn*/ - Word16 *mem_syn, /* o: initial synthesis filter states Q_syn*/ - Word16 Q_exc, - Word16 Q_syn, -#ifdef REMOVE_EVS_DUPLICATES - const Word16 element_mode, /* i : element mode */ -#endif + const Word16 element_mode, /* i : element mode */ const Word16 avoid_lpc_burst_on_recovery, /* i : if true the excitation energy is limited if LP has big gain */ const Word16 force_scaling /* i: force scaling */ ) @@ -742,12 +174,8 @@ void FEC_scale_syn_ivas_fx( tmp = sub( 3, getScaleFactor16( synth, L_frame ) ); -#ifdef REMOVE_EVS_DUPLICATES test(); IF( tmp > 0 && GT_16( element_mode, EVS_MONO ) ) -#else - IF( tmp > 0 ) -#endif { Word16 synth_tmp[L_FRAME16k]; Copy_Scale_sig( synth, synth_tmp, L_frame, -tmp ); // Q_synth - tmp diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c deleted file mode 100644 index 0fbedff60..000000000 --- a/lib_dec/acelp_core_dec_fx.c +++ /dev/null @@ -1,1544 +0,0 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 - ====================================================================================*/ - -#include -#include -#include "options.h" /* Compilation switches */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ -#include "ivas_prot_fx.h" -#include "ivas_cnst.h" /* Common constants */ -#include "cnst.h" /* Common constants */ - -#ifndef REMOVE_EVS_DUPLICATES -/*==========================================================================*/ -/* FUNCTION : void acelp_core_dec_fx () */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : ACELP core decoder */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ Word16 coder_type i : coder type */ - -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ Word16 *voice_factors o : voicing factors Q15 */ -/* _ Word16 old_syn_12k8_16k[] o : intermediate ACELP Q_syn2-1 */ -/* synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ -/* _ Word16 synth_out[] o : synthesis Q_syn2-1 */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ Decoder_State_fx *st_fx: */ -/* _ Word16 bwe_exc_extended[] i/o: bandwidth extended excitation Q0*/ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -/* CALLED FROM : RX */ -/*==========================================================================*/ - -ivas_error acelp_core_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 output[], /* o : synthesis @internal Fs */ - Word16 synth_out[], /* o : synthesis Q_syn2-1*/ - Word16 save_hb_synth[], /* o : HB synthesis */ - Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation Q0*/ - Word16 *voice_factors, /* o : voicing factors Q15 */ - Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis for SWB BWE Q_syn2-1*/ - Word16 sharpFlag, - Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe Q6*/ - Word16 *unbits, /* o : number of unused bits */ - Word16 *sid_bw, /* o : 0-NB/WB, 1-SWB SID */ - STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ - const Word16 tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */ - const Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - const Word16 last_element_mode, /* i : last element mode */ - const Word32 last_element_brate, /* i : last element bitrate */ - const Word16 flag_sec_CNA, /* i : CNA flag for secondary channel */ - const Word16 nchan_out, /* i : number of output channels */ - STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */ - const Word16 read_sid_info /* i : read SID info flag */ -) -{ - Word16 old_exc_fx[L_EXC_DEC] = { 0 }, *exc_fx; /* excitation signal buffer (Q0) */ - Word16 syn_fx_tmp[L_FRAME_16k + L_SUBFR], *syn_fx; /* synthesis signal buffer */ - Word16 temp_buf[L_FRAME16k + L_SYN_MEM]; - Word16 output_frame; /* frame length at output sampling freq. */ - Word16 mem_tmp_fx[M]; /* temporary synthesis filter memory */ - Word32 enr_q_fx; /* E information for FER protection */ - Word16 tmp_noise_fx; /* Long term temporary noise energy */ - Word16 i, int_fs; - Word16 tc_subfr_fx; - Word16 allow_cn_step_fx; - Word16 temp_buf_fx[L_FRAME16k + L_SYN_MEM]; - - Word16 Aq_fx[NB_SUBFR16k * ( M + 1 )] = { 0 }; /*Q12*/ - Word16 Es_pred_fx; /*Q8*/ - Word16 old_bwe_exc_fx[( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 )] = { 0 }; /* excitation buffer Q_exc*/ - Word16 old_exc2_fx[L_FRAME16k + L_EXC_MEM], *exc2_fx; /* total excitation buffer */ - Word16 *bwe_exc_fx; - Word16 lsf_new_fx[M]; /* LSFs at the end of the frame */ - Word16 lsp_new_fx[M]; /* LSPs at the end of the frame */ - Word16 lsp_mid_fx[M]; /* LSPs in the middle of the frame */ - Word16 FEC_pitch_fx; /*Q6*/ - Word16 last_pulse_pos; - Word16 T0_tmp; - Word16 do_WI_fx; - Word16 dct_buffer_fx[DCT_L_POST]; - Word16 exc_buffer_fx[DCT_L_POST]; - Word16 dct_exc_tmp[L_FRAME16k]; - Word16 qdct; - Word16 delta_mem_scale; - Word16 bpf_error_signal[L_FRAME16k]; - CLDFB_SCALE_FACTOR scaleFactor; - Word32 workBuffer[128 * 3]; - Word32 q_env[20]; - Word16 exc3_fx[L_FRAME16k]; - Word16 syn1_fx_tmp[L_FRAME16k + 2], *syn1_fx; - Word32 *realBuffer[CLDFB_NO_COL_MAX], *imagBuffer[CLDFB_NO_COL_MAX]; - Word16 gain_buf[NB_SUBFR16k]; /*Q14*/ - Word16 syn_fx_tmp2[L_FRAME_16k]; - Word16 pitch_buf_tmp[NB_SUBFR16k]; - Word16 k; - Word16 update_flg; - Word32 realBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word32 imagBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word16 LSF_Q_prediction; /* o : LSF prediction mode */ - Word16 avoid_lpc_burst_on_recovery; - Word16 uc_two_stage_flag, dec; - Word16 nb_bits, indice; - Word16 tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag; - MUSIC_POSTFILT_HANDLE hMusicPF; - BPF_DEC_HANDLE hBPF; - TD_BWE_DEC_HANDLE hBWE_TD; - FD_BWE_DEC_HANDLE hBWE_FD; - TCX_DEC_HANDLE hTcxDec; - ivas_error error; - (void) ( tdm_lspQ_PCh ); - (void) ( tdm_lsfQ_PCh ); - (void) ( use_cldfb_for_dft ); - (void) ( last_element_mode ); - (void) ( last_element_brate ); - (void) ( flag_sec_CNA ); - (void) ( nchan_out ); - (void) ( save_hb_synth ); - (void) ( output ); - (void) ( read_sid_info ); - (void) hStereoCng; - hMusicPF = st_fx->hMusicPF; - hBPF = st_fx->hBPF; - hBWE_TD = st_fx->hBWE_TD; - hBWE_FD = st_fx->hBWE_FD; - hTcxDec = st_fx->hTcxDec; - error = IVAS_ERR_OK; - move32(); - // IF ( EQ_16(st_fx->element_mode, IVAS_CPE_MDCT) && EQ_16(nchan_out, 1) && EQ_16(st_fx->idchan, 1) && LE_32(last_element_brate, IVAS_SID_4k4) ) - test(); - test(); - test(); - IF( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && EQ_16( nchan_out, 1 ) && EQ_16( st_fx->idchan, 1 ) && LE_32( last_element_brate, IVAS_SID_5k2 ) ) - { - /* In MDCT-Stereo DTX with mono output, we can skip CNG for the second channel, except for the first inactive frame following an active period */ - return error; - } - - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - set32_fx( realBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX ); - set32_fx( imagBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX ); - realBuffer[i] = realBufferTmp[i]; - move32(); - imagBuffer[i] = imagBufferTmp[i]; - move32(); - } - - /*----------------------------------------------------------------* - * Initialization - *----------------------------------------------------------------*/ - - LSF_Q_prediction = -1; - move16(); - set16_fx( syn_fx_tmp, 0, L_SUBFR ); - syn_fx = syn_fx_tmp + L_SUBFR; - syn1_fx_tmp[0] = 0; - move16(); - syn1_fx_tmp[1] = 0; - move16(); - syn1_fx = syn1_fx_tmp + 2; - /*output_frame = (Word16)(st_fx->output_Fs_fx / 50); move16();*/ - output_frame = st_fx->output_frame_fx; - move16(); - st_fx->bpf_off = 0; - move16(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( EQ_16( st_fx->last_core, HQ_CORE ) || EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) || ( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && LE_32( st_fx->last_core_brate, SID_2k40 ) ) || ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && LE_32( st_fx->last_core_brate, SID_2k40 ) ) ) - { - /* in case of HQ->ACELP switching, do not apply BPF */ - st_fx->bpf_off = 1; - move16(); - /* in case of core switching, reset post-filter memories */ - if ( st_fx->hPFstat != NULL ) - { - st_fx->hPFstat->on = 0; - move16(); - } - - /* reset the GSC pre echo energy threshold in case of switching */ - if ( st_fx->hGSCDec != NULL ) - { - st_fx->hGSCDec->Last_frame_ener_fx = MAX_32; - move32(); - } - } - IF( st_fx->prev_bfi > 0 ) - { - /* reset the GSC pre echo energy threshold in case of FEC */ - if ( st_fx->hGSCDec != NULL ) - { - st_fx->hGSCDec->Last_frame_ener_fx = MAX_32; - move32(); - } - } - - st_fx->clas_dec = st_fx->last_good; - move16(); - enr_q_fx = 0; - move32(); - Es_pred_fx = 0; - move16(); - tmp_noise_fx = 0; - move16(); - Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); // Q_exc - exc_fx = old_exc_fx + L_EXC_MEM_DEC; - - IF( st_fx->hWIDec != NULL ) - { - Copy( st_fx->hWIDec->old_exc2_fx, old_exc2_fx, L_EXC_MEM ); - } - ELSE - { - set16_fx( old_exc2_fx, 0, L_EXC_MEM ); - } - exc2_fx = old_exc2_fx + L_EXC_MEM; - IF( st_fx->hBWE_TD != NULL ) - { - Copy( hBWE_TD->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2 ); // Q_exc - bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2; - } - ELSE - { - bwe_exc_fx = NULL; - } - - last_pulse_pos = 0; - move16(); - do_WI_fx = 0; - move16(); - st_fx->GSC_noisy_speech = 0; - move16(); - st_fx->relax_prev_lsf_interp = 0; - move16(); - - set16_fx( gain_buf, 0, NB_SUBFR16k ); - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - st_fx->gamma = GAMMA1; - move16(); - st_fx->preemph_fac = PREEMPH_FAC; - move16(); - int_fs = INT_FS_FX; - move16(); - } - ELSE - { - st_fx->gamma = GAMMA16k; - move16(); - st_fx->preemph_fac = PREEMPH_FAC_16k; - move16(); - int_fs = INT_FS_16k; - move16(); - } - - /* reset post-filter in case post-filtering was off in previous frame */ - IF( st_fx->hPFstat != NULL ) - { - if ( st_fx->hPFstat->on == 0 ) - { - st_fx->hPFstat->reset = 1; - move16(); - } - } - avoid_lpc_burst_on_recovery = 0; - move16(); - test(); - test(); - if ( st_fx->last_con_tcx && NE_16( st_fx->L_frameTCX_past, st_fx->L_frame ) && st_fx->last_core != 0 ) - { - avoid_lpc_burst_on_recovery = 1; - move16(); - } - /* TD stereo parameters */ - test(); - IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && st_fx->idchan == 1 ) - { - tdm_lp_reuse_flag = hStereoTD->tdm_lp_reuse_flag; - tdm_low_rate_mode = hStereoTD->tdm_low_rate_mode; - tdm_Pitch_reuse_flag = hStereoTD->tdm_Pitch_reuse_flag; - move16(); - move16(); - move16(); - move16(); - } - ELSE - { - tdm_lp_reuse_flag = 0; - tdm_low_rate_mode = 0; - move16(); - move16(); - test(); - if ( EQ_16( st_fx->element_mode, IVAS_SCE ) && st_fx->low_rate_mode ) - { - tdm_low_rate_mode = 1; - move16(); - } - tdm_Pitch_reuse_flag = 0; - move16(); - } - /*----------------------------------------------------------------* - * Updates in case of internal sampling rate switching - *----------------------------------------------------------------*/ - test(); - test(); - IF( NE_16( st_fx->last_L_frame, st_fx->L_frame ) && ( st_fx->last_core == ACELP_CORE || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) - { - IF( st_fx->hPFstat->on != 0 ) - { - Word16 mem_syn_r_size_old, mem_syn_r_size_new; - - mem_syn_r_size_old = shr( st_fx->last_L_frame, 4 ); - mem_syn_r_size_new = shr( st_fx->L_frame, 4 ); - lerp( st_fx->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_old, st_fx->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - lerp( st_fx->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_old, st_fx->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - } - /* convert quantized LSP vector */ - st_fx->rate_switching_reset = lsp_convert_poly_fx( st_fx->lsp_old_fx, st_fx->L_frame, 0 ); - move16(); - /* convert old quantized LSF vector */ - lsp2lsf_fx( st_fx->lsp_old_fx, st_fx->lsf_old_fx, M, int_fs ); - - /* FEC - update adaptive LSF mean vector */ - Copy( st_fx->lsf_old_fx, st_fx->lsfoldbfi1_fx, M ); // Qlog2(2.56) - Copy( st_fx->lsf_old_fx, st_fx->lsfoldbfi0_fx, M ); // Qlog2(2.56) - Copy( st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, M ); // Qlog2(2.56) - - /* Reset LPC mem */ - IF( EQ_32( st_fx->sr_core, INT_FS_16k ) ) - { - Copy( GEWB2_Ave_fx, st_fx->mem_AR_fx, M ); // Qlog2(2.56) - } - ELSE - { - Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); // Qlog2(2.56) - } - set16_fx( st_fx->mem_MA_fx, 0, M ); - - dec = DEC; - move16(); - IF( NE_16( st_fx->element_mode, EVS_MONO ) ) - { - dec = DEC_IVAS; - move16(); - } - - /* update synthesis filter memories */ - synth_mem_updt2( st_fx->L_frame, st_fx->last_L_frame, st_fx->old_exc_fx, st_fx->mem_syn_r, st_fx->mem_syn2_fx, NULL, dec ); - - Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); // Q_exc - Copy_Scale_sig( st_fx->mem_syn2_fx, st_fx->mem_syn1_fx, M, sub( -1, st_fx->Q_syn ) ); /*Q-1*/ - - Copy( st_fx->mem_syn2_fx, st_fx->mem_syn3_fx, M ); - } - - IF( NE_16( st_fx->last_L_frame, st_fx->L_frame ) ) - { - /* update buffer of old subframe pitch values */ - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - - IF( EQ_16( st_fx->last_L_frame, L_FRAME32k ) ) - { - /* (float)12800/(float)32000; */ - k = 13107; // Q15 - move16(); - } - ELSE IF( EQ_16( st_fx->last_L_frame, 512 ) ) - { - /* (float)12800/(float)25600; */ - k = 16384; // Q15 - move16(); - } - ELSE /* st->last_L_frame == L_FRAME16k */ - { - /* (float)12800/(float)16000; */ - k = 26214; // Q15 - move16(); - } - - FOR( i = NB_SUBFR16k - NB_SUBFR; i < NB_SUBFR16k; i++ ) - { - st_fx->old_pitch_buf_fx[i - 1] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], k ); // Q(15+15+1-16) - move32(); - } - - FOR( i = 2 * NB_SUBFR16k - NB_SUBFR; i < 2 * NB_SUBFR16k; i++ ) - { - st_fx->old_pitch_buf_fx[i - 2] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], k ); // Q15 - move32(); - } - } - ELSE - { - - IF( EQ_16( st_fx->last_L_frame, L_FRAME32k ) ) - { - /* (float)16000/(float)32000; */ - k = -16384; // -0.5 in Q15 - move16(); - } - ELSE IF( EQ_16( st_fx->last_L_frame, 512 ) ) - { - /* tmpF = (float)16000/(float)25600; */ - k = -12288; //-0.375 in Q15 - move16(); - } - ELSE /* st->last_L_frame == L_FRAME12k8 */ - { - /* tmpF = (float)16000/(float)12800; */ - k = 8192; //.25 in Q15 - move16(); - } - - FOR( i = 2 * NB_SUBFR - 1; i >= NB_SUBFR; i-- ) - { - st_fx->old_pitch_buf_fx[i + 2] = L_add( st_fx->old_pitch_buf_fx[i], Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], k ) ); // Q15 - move32(); - } - st_fx->old_pitch_buf_fx[NB_SUBFR + 1] = st_fx->old_pitch_buf_fx[NB_SUBFR + 2]; - move32(); - - FOR( i = NB_SUBFR - 1; i >= 0; i-- ) - { - st_fx->old_pitch_buf_fx[i + 1] = L_add( st_fx->old_pitch_buf_fx[i], Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], k ) ); // Q15 - move32(); - } - st_fx->old_pitch_buf_fx[0] = st_fx->old_pitch_buf_fx[1]; - move32(); - } - } - - IF( NE_16( st_fx->bfi_pitch_frame, st_fx->L_frame ) ) - { - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - - IF( EQ_16( st_fx->bfi_pitch_frame, L_FRAME32k ) ) - { - /* (float)12800/(float)32000; */ - k = 13107; // Q15 - move16(); - } - ELSE IF( EQ_16( st_fx->bfi_pitch_frame, 512 ) ) - { - /* (float)12800/(float)25600; */ - k = 16384; // Q15 - move16(); - } - ELSE /* st->bfi_pitch_frame == L_FRAME16k */ - { - /* (float)12800/(float)16000; */ - k = 26214; // Q15 - move16(); - } - st_fx->bfi_pitch_fx = mult_r( k, st_fx->bfi_pitch_fx ); - move16(); - st_fx->bfi_pitch_frame = L_FRAME; - move16(); - } - ELSE - { - - IF( EQ_16( st_fx->bfi_pitch_frame, L_FRAME32k ) ) - { - /* (float)16000/(float)32000; */ - k = -16384; //-0.5 in Q15 - move16(); - } - ELSE IF( EQ_16( st_fx->bfi_pitch_frame, 512 ) ) - { - /* tmpF = (float)16000/(float)25600; */ - k = -12288; // -0.375 in Q15 - move16(); - } - ELSE /* st->bfi_pitch_frame == L_FRAME12k8 */ - { - /* tmpF = (float)16000/(float)12800; */ - k = 8192; // .25 in Q15 - move16(); - } - st_fx->bfi_pitch_fx = add( st_fx->bfi_pitch_fx, mult_r( st_fx->bfi_pitch_fx, k ) ); - move16(); - st_fx->bfi_pitch_frame = L_FRAME16k; - move16(); - } - } - - test(); - test(); - if ( EQ_16( st_fx->last_bwidth, NB ) && NE_16( st_fx->bwidth, NB ) && st_fx->ini_frame != 0 ) - { - st_fx->rate_switching_reset = 1; - move16(); - } - - /*----------------------------------------------------------------------* - * GOOD frame - *----------------------------------------------------------------------*/ - - IF( !st_fx->bfi ) - { - - /*----------------------------------------------------------------* - * Decoding of TC subframe classification - *----------------------------------------------------------------*/ - - tc_subfr_fx = -1; - move16(); - IF( EQ_16( st_fx->coder_type, TRANSITION ) ) - { - tc_subfr_fx = tc_classif_fx( st_fx, st_fx->L_frame ); - } - - /*----------------------------------------------------------------* - * Decoding of GSC IVAS mode - *----------------------------------------------------------------*/ - st_fx->GSC_IVAS_mode = 0; - move16(); - test(); - test(); - test(); - test(); - IF( ( st_fx->element_mode > EVS_MONO ) && st_fx->idchan == 0 && !( ( st_fx->core_brate == FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) && !tdm_low_rate_mode ) - { - test(); - test(); - IF( EQ_16( st_fx->coder_type, AUDIO ) || ( ( st_fx->coder_type == INACTIVE ) && LE_32( st_fx->total_brate, MAX_GSC_INACTIVE_BRATE ) ) ) - { - st_fx->GSC_IVAS_mode = get_next_indice( st_fx, 2 ); - move16(); - } - } - - /*----------------------------------------------------------------* - * Decoding of inactive CNG frames - *----------------------------------------------------------------*/ - test(); - IF( st_fx->core_brate == FRAME_NO_DATA || EQ_32( st_fx->core_brate, SID_2k40 ) ) - { - /* decode CNG parameters */ - IF( st_fx->cng_type == LP_CNG ) - { - - CNG_dec_fx( st_fx, EVS_MONO, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step_fx, sid_bw, q_env ); - - /* comfort noise generation */ - CNG_exc_fx( st_fx->core_brate, st_fx->L_frame, &st_fx->hTdCngDec->Enew_fx, &st_fx->hTdCngDec->cng_seed, exc_fx, exc2_fx, &st_fx->lp_ener_fx, st_fx->last_core_brate, - &st_fx->first_CNG, &( st_fx->hTdCngDec->cng_ener_seed ), bwe_exc_fx, allow_cn_step_fx, &st_fx->hTdCngDec->last_allow_cn_step, st_fx->prev_Q_exc, st_fx->Q_exc, st_fx->hTdCngDec->num_ho, - q_env, st_fx->hTdCngDec->lp_env_fx, st_fx->hTdCngDec->old_env_fx, st_fx->hTdCngDec->exc_mem_fx, st_fx->hTdCngDec->exc_mem1_fx, sid_bw, &st_fx->hTdCngDec->cng_ener_seed1, exc3_fx, st_fx->Opt_AMR_WB, st_fx->element_mode ); - - Copy( Aq_fx, st_fx->Aq_cng, M + 1 ); // Q12 - } - ELSE - { - test(); - IF( EQ_32( st_fx->core_brate, SID_2k40 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - FdCng_decodeSID_fx( st_fx->hFdCngDec->hFdCngCom, st_fx ); - *sid_bw = 0; - move16(); - } - - generate_comfort_noise_dec_fx( NULL, NULL, NULL, st_fx, &( st_fx->Q_exc ), 2, -1 ); - - FdCng_exc( st_fx->hFdCngDec->hFdCngCom, &st_fx->CNG_mode, st_fx->L_frame, st_fx->lsp_old_fx, st_fx->first_CNG, st_fx->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx ); - - Copy( exc2_fx, exc3_fx, st_fx->L_frame ); - } - - delta_mem_scale = 3; - move16(); - test(); - if ( LT_32( st_fx->lp_ener_fx, 40 ) && ( st_fx->cng_type == LP_CNG ) ) /* very low energy frames, less than 0.3125 */ - { - delta_mem_scale = 0; - move16(); - } - i = st_fx->Q_exc; - move16(); - Rescale_exc( hMusicPF->dct_post_old_exc_fx, exc_fx, bwe_exc_fx, st_fx->hGSCDec->last_exc_dct_in_fx, st_fx->L_frame, - st_fx->L_frame * HIBND_ACB_L_FAC, 0, &( st_fx->Q_exc ), st_fx->Q_subfr, NULL, 0, INACTIVE ); - Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, delta_mem_scale, - &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, 0, 0, NULL ); - Copy_Scale_sig( exc2_fx, exc2_fx, st_fx->L_frame, sub( st_fx->Q_exc, i ) ); // Q_exc - - /* update past excitation signals for LD music post-filter */ - IF( hMusicPF != NULL ) - { - Copy( hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); - Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); - /* Update music post processing values */ - /* Filter energies update */ - FOR( i = 0; i < DCT_L_POST; i++ ) - { - /*st_fx->filt_lfE_fx[i] = 0.3f + 0.7f * st_fx->filt_lfE_fx[i];*/ - hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, hMusicPF->filt_lfE_fx[i] ) ); - move16(); - } - } - /* synthesis at 12.8kHz sampling rate */ - syn_12k8_fx( st_fx->L_frame, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); - syn_12k8_fx( st_fx->L_frame, Aq_fx, exc3_fx, syn1_fx, st_fx->mem_syn3_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); - - /* reset the decoder */ - CNG_reset_dec_fx( st_fx, pitch_buf_fx, voice_factors ); - - /* update st_fx->mem_syn1 for ACELP core switching */ - Copy( st_fx->mem_syn3_fx, st_fx->mem_syn1_fx, M ); - - /* update old synthesis for classification */ - Copy( syn1_fx + st_fx->L_frame - L_SYN_MEM_CLAS_ESTIM, st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); - - - /* save and delay synthesis to be used by SWB BWE */ - Copy_Scale_sig( syn1_fx, temp_buf_fx, st_fx->L_frame, sub( -1, st_fx->Q_syn ) ); // Q_syn -> Q(-1) - IF( hBWE_FD != NULL ) - { - save_old_syn_fx( st_fx->L_frame, temp_buf_fx, old_syn_12k8_16k, hBWE_FD->old_syn_12k8_16k_fx, st_fx->preemph_fac, &hBWE_FD->mem_deemph_old_syn_fx ); - } - } - - /*----------------------------------------------------------------* - * Decoding of all other frames - *----------------------------------------------------------------*/ - - ELSE - { - /*-----------------------------------------------------------------* - * Configure ACELP bit allocation - *-----------------------------------------------------------------*/ - nb_bits = 0; - st_fx->acelp_cfg.FEC_mode = 0; - uc_two_stage_flag = 0; - move16(); - move16(); - move16(); - test(); - IF( !st_fx->nelp_mode_dec && !st_fx->ppp_mode_dec ) - { - Word16 tc_subfr_tmp; - - tc_subfr_tmp = tc_subfr_fx; - move16(); - if ( LT_16( tc_subfr_tmp, L_SUBFR ) ) - { - tc_subfr_tmp = 0; - move16(); - } - - if ( EQ_16( tc_subfr_fx, TC_0_192 ) ) - { - nb_bits = -1; - move16(); - } - - config_acelp1( DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, st_fx->coder_type, st_fx->inactive_coder_type_flag, tc_subfr_tmp, 1, &nb_bits, unbits, st_fx->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_cnt, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); - - test(); - test(); - IF( EQ_16( st_fx->coder_type, TRANSITION ) && LT_16( tc_subfr_fx, L_SUBFR ) && EQ_16( st_fx->L_frame, L_FRAME ) ) - { - config_acelp1( DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, -1, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, TRANSITION, -1, tc_subfr_fx, 2, &nb_bits, unbits, st_fx->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_cnt, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); - } - } - - /*-----------------------------------------------------------------* - * After CNG period, use the most up-to-date LSPs - *-----------------------------------------------------------------*/ - - test(); - test(); - IF( st_fx->hTdCngDec != NULL && ( st_fx->last_core_brate == FRAME_NO_DATA || EQ_32( st_fx->last_core_brate, SID_2k40 ) ) ) - { - Copy( st_fx->lspCNG_fx, st_fx->lsp_old_fx, M ); // Q15 - - lsp2lsf_fx( st_fx->lspCNG_fx, st_fx->lsf_old_fx, M, int_fs ); - } - - /*-----------------------------------------------------------------* - * Reset higher ACELP pre-quantizer in case of switching - *-----------------------------------------------------------------*/ - - IF( !st_fx->use_acelp_preq ) - { - st_fx->mem_preemp_preQ_fx = 0; - move16(); - st_fx->last_nq_preQ = 0; - move16(); - } - - st_fx->use_acelp_preq = 0; - move16(); - - /*-----------------------------------------------------------------* - * LSF de-quantization and interpolation - *-----------------------------------------------------------------*/ - - lsf_dec_fx( st_fx, tc_subfr_fx, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode, - tdm_lsfQ_PCh ); - - /*-----------------------------------------------------------------* - * FEC - first good frame after lost frame(s) (possibility to correct the ACB) - *-----------------------------------------------------------------*/ - - IF( st_fx->acelp_cfg.FEC_mode > 0 ) - { - last_pulse_pos = 0; - move16(); - - /* decode the last glottal pulse position */ - T0_tmp = FEC_pos_dec_fx( st_fx, &last_pulse_pos, &enr_q_fx, nb_bits ); - - - test(); - test(); - IF( NE_16( st_fx->last_core, HQ_CORE ) || ( EQ_16( st_fx->last_core, HQ_CORE ) && st_fx->last_con_tcx ) ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( EQ_16( st_fx->clas_dec, SIN_ONSET ) && last_pulse_pos != 0 && EQ_16( st_fx->prev_bfi, 1 ) ) - { - st_fx->Q_exc = - FEC_SinOnset_fx( old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, last_pulse_pos, T0_tmp, enr_q_fx, Aq_fx, st_fx->L_frame, st_fx->Q_exc ); - move16(); - } - ELSE IF( ( EQ_16( st_fx->coder_type, GENERIC ) || EQ_16( st_fx->coder_type, VOICED ) ) && last_pulse_pos != 0 && EQ_16( st_fx->old_bfi_cnt, 1 ) && EQ_16( output_frame, L_FRAME16k ) && st_fx->hWIDec != NULL ) - { - do_WI_fx = FEC_enhACB_fx( st_fx->L_frame, st_fx->last_L_frame, old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, T0_tmp, last_pulse_pos, st_fx->bfi_pitch_fx ); - } - } - } - - /*------------------------------------------------------------* - * In case of first frame after an erasure and transition from voiced to unvoiced or inactive - * redo the LPC interpolation - *------------------------------------------------------------*/ - test(); - test(); - test(); - test(); - test(); - test(); - IF( st_fx->stab_fac_fx == 0 && st_fx->old_bfi_cnt > 0 && NE_16( st_fx->clas_dec, VOICED_CLAS ) && NE_16( st_fx->clas_dec, ONSET ) && - st_fx->relax_prev_lsf_interp == 0 && !( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && EQ_16( st_fx->idchan, 1 ) ) ) - { - int_lsp4_fx( st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid_fx, lsp_new_fx, Aq_fx, M, 2 ); - } - - /*---------------------------------------------------------------* - * Decoding of the scaled predicted innovation energy - *---------------------------------------------------------------*/ - - IF( nb_bits > 0 ) - { - indice = get_next_indice( st_fx, nb_bits ); - Es_pred_dec_fx( &Es_pred_fx, indice, nb_bits, uc_two_stage_flag ); - } - - /*------------------------------------------------------------* - * Decode excitation according to coding type - *------------------------------------------------------------*/ - - test(); - test(); - IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) - { - /* SC-VBR - NELP frames */ - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st_fx->Q_exc ) ); // Q0 - st_fx->Q_exc = 0; - move16(); - - decod_nelp_fx( st_fx, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, voice_factors, bwe_exc_fx, &st_fx->Q_exc, st_fx->bfi, gain_buf ); - Rescale_exc( hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, L_FRAME, st_fx->coder_type ); - } - ELSE IF( EQ_16( st_fx->coder_type, UNVOICED ) ) - { - /* UNVOICED frames */ - decod_unvoiced_fx( st_fx, Aq_fx, st_fx->coder_type, &tmp_noise_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, gain_buf ); - } - ELSE IF( EQ_16( st_fx->ppp_mode_dec, 1 ) ) - { - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st_fx->Q_exc ) ); // Q0 - st_fx->Q_exc = 0; - move16(); - /* SC-VBR - PPP frames */ - IF( NE_32( ( error = decod_ppp_fx( st_fx, Aq_fx, pitch_buf_fx, exc_fx, exc2_fx, st_fx->bfi, gain_buf, voice_factors, bwe_exc_fx ) ), IVAS_ERR_OK ) ) - { - return error; - } - - Rescale_exc( hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, L_FRAME, st_fx->coder_type ); - } - ELSE IF( EQ_16( st_fx->coder_type, TRANSITION ) ) - { - decod_tran_fx( st_fx, st_fx->L_frame, tc_subfr_fx, Aq_fx, Es_pred_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, unbits, sharpFlag, gain_buf ); - } - ELSE IF( EQ_16( st_fx->coder_type, AUDIO ) || ( ( st_fx->coder_type == INACTIVE ) && LE_32( st_fx->core_brate, MAX_GSC_INACTIVE_BRATE ) ) ) - { - decod_audio_fx( st_fx, dct_exc_tmp, Aq_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf ); - tmp_noise_fx = shr_r( st_fx->lp_gainc_fx, 3 ); /*Q0*/ - } - ELSE - { - IF( NE_32( ( error = decod_gen_voic_fx( st_fx, st_fx->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf /*, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf*/ ) ), IVAS_ERR_OK ) ) - { - return error; - } - - IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - tmp_noise_fx = shr_r( st_fx->lp_gainc_fx, 3 ); /*Q0*/ - } - } - - /* synthesis for ACELP core switching and SWB BWE */ - syn_12k8_fx( st_fx->L_frame, Aq_fx, exc_fx, temp_buf_fx, st_fx->mem_syn1_fx, 1, st_fx->Q_exc, -1 ); - /* save and delay synthesis to be used by SWB BWE */ - IF( hBWE_FD != NULL ) - { - save_old_syn_fx( st_fx->L_frame, temp_buf_fx, old_syn_12k8_16k, hBWE_FD->old_syn_12k8_16k_fx, st_fx->preemph_fac, &hBWE_FD->mem_deemph_old_syn_fx ); - } - - /*-----------------------------------------------------------------* - * Apply energy matching when switching to inactive frames - *-----------------------------------------------------------------*/ - - Inac_swtch_ematch_fx( exc2_fx, dct_exc_tmp, st_fx->hGSCDec->lt_ener_per_band_fx, st_fx->coder_type, st_fx->L_frame, st_fx->core_brate, st_fx->Q_exc, st_fx->bfi, st_fx->last_core, st_fx->last_codec_mode ); - /*------------------------------------------------------------* - * Decode information and modify the excitation signal of stationary unvoiced frames - *------------------------------------------------------------*/ - test(); - test(); - test(); - test(); - IF( !( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) && NE_16( st_fx->nelp_mode_dec, 1 ) && !( EQ_16( st_fx->element_mode, IVAS_SCE ) && tdm_low_rate_mode ) ) - { - stat_noise_uv_dec_fx( st_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx, uc_two_stage_flag ); - } - - /*------------------------------------------------------------* - * Save filter memory in case the synthesis is redone after scaling - * Synthesis at 12k8 Hz sampling rate - *------------------------------------------------------------*/ - - /* update past excitation signals for LD music post-filter */ - IF( hMusicPF != NULL ) - { - Copy( hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); - Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); - Copy( hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, DCT_L_POST - OFFSET2 ); - } - test(); - test(); - test(); - test(); - IF( hMusicPF != NULL && ( ( EQ_16( st_fx->coder_type, AUDIO ) && st_fx->GSC_noisy_speech == 0 ) || ( GE_16( st_fx->GSC_IVAS_mode, 1 ) && EQ_16( st_fx->L_frame, L_FRAME ) ) ) ) - { - - Word16 last_coder_type = st_fx->last_coder_type; - move16(); - test(); - test(); - test(); - if ( ( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) || ( GE_16( st_fx->GSC_IVAS_mode, 1 ) && st_fx->GSC_noisy_speech == 0 ) ) - { - last_coder_type = AUDIO; - move16(); - } - /* Extrapolation of the last future part, windowing and high resolution DCT transform */ - qdct = 0; - move16(); -#ifdef _DIFF_FLOAT_FIX_ /* FLoat point using last_core which fits with the inner part of the function */ - Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, hMusicPF->filt_lfE_fx, st_fx->last_core, st_fx->element_mode, pitch_buf_fx, - hMusicPF->LDm_enh_lp_gbin_fx, st_fx->Q_exc, &qdct ); -#else - Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, hMusicPF->filt_lfE_fx, st_fx->last_coder_type, st_fx->element_mode, pitch_buf_fx, - hMusicPF->LDm_enh_lp_gbin_fx, st_fx->Q_exc, &qdct ); -#endif - /* LD music post-filter */ - LD_music_post_filter_fx( hMusicPF, dct_buffer_fx, dct_buffer_fx, st_fx->core_brate, - &hMusicPF->Old_ener_Q, AUDIO, last_coder_type, qdct ); - - /* Inverse DCT transform, retrieval of the aligned excitation, re-synthesis */ - Post_music_postP_fx( dct_buffer_fx, exc2_fx, st_fx->mem_syn2_fx, st_fx->mem_syn2_fx, Aq_fx, syn_fx, &st_fx->Q_exc, &st_fx->prev_Q_syn, - &st_fx->Q_syn, st_fx->mem_syn_clas_estim_fx, 0, &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx, - &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, temp_buf_fx, mem_tmp_fx ); - } - ELSE - { - /* Core synthesis at 12.8kHz or 16kHz */ - i = 1; - move16(); - if ( st_fx->coder_type == INACTIVE ) - { - i = 0; - move16(); - } - /* add extra headroom in case a CNA addition is likely (i.e. st_fx->psf_lp_noise_fx is close to the threshold) */ - k = 0; - move16(); - test(); - test(); - if ( ( st_fx->coder_type == INACTIVE ) && st_fx->flag_cna && GE_16( round_fx( L_shl( st_fx->lp_noise, 1 ) ), 15 << 7 ) ) - { - k = 1; - move16(); - } - - Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 4, &st_fx->mem_deemph_fx, - hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, i, k, temp_buf_fx ); - Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); // Q_syn - - syn_12k8_fx( st_fx->L_frame, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); - IF( hMusicPF != NULL ) - { - FOR( i = 0; i < DCT_L_POST; i++ ) - { - /*st_fx->filt_lfE_fx[i] = 0.3f + 0.7f * st_fx->filt_lfE_fx[i];*/ - hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, hMusicPF->filt_lfE_fx[i] ) ); - move16(); - } - } - } - - /*------------------------------------------------------------* - * FEC - Estimate the classification information - *------------------------------------------------------------*/ - - FEC_clas_estim_fx( st_fx, st_fx->Opt_AMR_WB, st_fx->L_frame, &st_fx->clas_dec, st_fx->coder_type, pitch_buf_fx, - syn_fx, &st_fx->lp_ener_FER_fx, &st_fx->decision_hyst, - NULL, NULL, NULL, NULL, 0, NULL, st_fx->Q_syn, temp_buf_fx, - st_fx->mem_syn_clas_estim_fx, &st_fx->classifier_Q_mem_syn, - 0, 0, 0, st_fx->last_core_brate, st_fx->acelp_cfg.FEC_mode ); - /*------------------------------------------------------------* - * FEC - Estimate pitch - *------------------------------------------------------------*/ - - FEC_pitch_estim_fx( st_fx->Opt_AMR_WB, st_fx->last_core, st_fx->L_frame, st_fx->clas_dec, st_fx->last_good, pitch_buf_fx, st_fx->old_pitch_buf_fx, - &st_fx->bfi_pitch_fx, &st_fx->bfi_pitch_frame, &st_fx->upd_cnt, st_fx->coder_type, st_fx->element_mode ); - - /*------------------------------------------------------------* - * FEC - Smooth the speech energy evolution when recovering after a BAD frame - * (smoothing is performed in the excitation domain and signal is resynthesized after) - *------------------------------------------------------------*/ - - k = 0; - move16(); - FOR( i = 0; i < st_fx->L_frame; i += L_SUBFR ) - { - pitch_buf_tmp[k] = mult_r( pitch_buf_fx[k], 512 ); // Q0(6+9-15) , (512 = 1.0f in Q9) - move16(); - k = add( k, 1 ); - } - - FEC_scale_syn_fx( st_fx->L_frame, &update_flg, st_fx->clas_dec, st_fx->last_good, syn_fx, pitch_buf_tmp, st_fx->enr_old_fx, enr_q_fx, st_fx->coder_type, LSF_Q_prediction, - &st_fx->scaling_flag, &st_fx->lp_ener_FEC_av, &st_fx->lp_ener_FEC_max, st_fx->bfi, st_fx->total_brate, st_fx->prev_bfi, st_fx->last_core_brate, - exc_fx, exc2_fx, Aq_fx, &st_fx->old_enr_LP, mem_tmp_fx, st_fx->mem_syn2_fx, st_fx->Q_exc, st_fx->Q_syn, avoid_lpc_burst_on_recovery, 0 ); - - test(); - test(); - test(); - test(); - IF( ( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && LE_32( st_fx->total_brate, ACELP_7k20 ) ) || ( EQ_32( st_fx->total_brate, ACELP_7k20 ) ) || ( EQ_32( st_fx->total_brate, ACELP_8k00 ) ) ) - { - frame_ener_fx( st_fx->L_frame, st_fx->clas_dec, syn_fx, pitch_buf_tmp[sub( shr( st_fx->L_frame, 6 ), 1 )], &st_fx->enr_old_fx, st_fx->L_frame, st_fx->Q_syn, 3, 0 ); - } - } - - } /* End of GOOD FRAME */ - - /*----------------------------------------------------------------* - * BAD frame - *----------------------------------------------------------------*/ - ELSE - { - /* SC-VBR */ - if ( EQ_16( st_fx->last_nelp_mode_dec, 1 ) ) - { - st_fx->nelp_mode_dec = 1; - move16(); - } - - /* long burst frame erasures */ - test(); - test(); - if ( GT_16( st_fx->nbLostCmpt, 5 ) && GE_16( st_fx->clas_dec, VOICED_CLAS ) && LT_16( st_fx->clas_dec, INACTIVE_CLAS ) ) - { - st_fx->last_good = VOICED_TRANSITION; - move16(); - } - - /* LSF estimation and A(z) calculation */ - lsf_dec_bfi( MODE1, lsf_new_fx, st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, NULL, st_fx->mem_MA_fx, st_fx->mem_AR_fx, - st_fx->stab_fac_fx, st_fx->last_coder_type, st_fx->L_frame, st_fx->last_good, - st_fx->nbLostCmpt, 0, NULL, NULL, NULL, st_fx->hGSCDec->Last_GSC_pit_band_idx, st_fx->Opt_AMR_WB, 0, st_fx->bwidth ); - - FEC_lsf2lsp_interp( st_fx, st_fx->L_frame, Aq_fx, lsf_new_fx, lsp_new_fx ); - - IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) - { - /* SC-VBR */ - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st_fx->Q_exc ) ); // Q0 - st_fx->Q_exc = 0; - move16(); - - decod_nelp_fx( st_fx, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, voice_factors, bwe_exc_fx, &st_fx->Q_exc, st_fx->bfi, gain_buf ); - FEC_pitch_fx = pitch_buf_fx[3]; - move16(); - - Rescale_exc( hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, L_FRAME, st_fx->coder_type ); - } - ELSE - { - /* calculation of excitation signal */ - - FEC_exc_estim_fx( st_fx, st_fx->L_frame, exc_fx, exc2_fx, dct_exc_tmp, pitch_buf_fx, voice_factors, &FEC_pitch_fx, bwe_exc_fx, lsf_new_fx, &st_fx->Q_exc, &tmp_noise_fx ); - - Rescale_exc( NULL, exc_fx, bwe_exc_fx, st_fx->hGSCDec->last_exc_dct_in_fx, st_fx->L_frame, L_FRAME32k, (Word32) 0, - &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, st_fx->L_frame, st_fx->last_coder_type ); - - tmp_noise_fx = shr_r( st_fx->lp_gainc_fx, 3 ); /*Q0*/ - - /* SC-VBR */ - st_fx->prev_gain_pit_dec_fx = st_fx->lp_gainp_fx; - move16(); /*Q14*/ - } - - /* synthesis for ACELP core switching and SWB BWE */ - syn_12k8_fx( st_fx->L_frame, Aq_fx, exc_fx, temp_buf_fx, st_fx->mem_syn1_fx, 1, st_fx->Q_exc, -1 ); /*old_syn_12k8_16k directly in q-1*/ - - /* save and delay synthesis to be used by SWB BWE */ - IF( hBWE_FD != NULL ) - { - save_old_syn_fx( st_fx->L_frame, temp_buf_fx, old_syn_12k8_16k, hBWE_FD->old_syn_12k8_16k_fx, st_fx->preemph_fac, &hBWE_FD->mem_deemph_old_syn_fx ); - } - /* Apply energy matching when switching to inactive frames */ - Inac_swtch_ematch_fx( exc2_fx, dct_exc_tmp, st_fx->hGSCDec->lt_ener_per_band_fx, st_fx->coder_type, st_fx->L_frame, st_fx->core_brate, st_fx->Q_exc, st_fx->bfi, st_fx->last_core, st_fx->last_codec_mode ); - - /* udate past excitation signals for LD music post-filter */ - IF( hMusicPF != NULL ) - { - Copy( hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); - Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); - /* Update music post processing values */ - /* Filter energies update */ - FOR( i = 0; i < DCT_L_POST; i++ ) - { - /*st_fx->filt_lfE_fx[i] = 0.3f + 0.7f * st_fx->filt_lfE_fx[i];*/ - hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, hMusicPF->filt_lfE_fx[i] ) ); - move16(); - } - /* Update circular buffer, keep last energy difference unchanged */ - FOR( i = 1; i < MAX_LT; i++ ) - { - hMusicPF->LDm_lt_diff_etot_fx[i - 1] = hMusicPF->LDm_lt_diff_etot_fx[i]; - move16(); - } - } - /* synthesis at 12k8 Hz sampling rate */ - /* add extra headroom in case a CNA addition is likely (i.e. st_fx->psf_lp_noise_fx is close to the threshold) */ - k = 0; - move16(); - test(); - test(); - if ( ( st_fx->coder_type == INACTIVE ) && st_fx->flag_cna && GE_16( round_fx( L_shl( st_fx->lp_noise, 1 ) ), 15 << 7 ) ) - { - k = 1; - move16(); - } - - Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 4, &st_fx->mem_deemph_fx, - hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, 1, k, temp_buf_fx ); - - test(); - IF( ( EQ_32( st_fx->total_brate, ACELP_7k20 ) ) || ( EQ_32( st_fx->total_brate, ACELP_8k00 ) ) ) - { - Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); // Q_syn - } - syn_12k8_fx( st_fx->L_frame, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); - - /* update buffer for classifier */ - IF( st_fx->hWIDec != NULL ) - { - Copy( exc2_fx + st_fx->L_frame - L_EXC_MEM, st_fx->hWIDec->old_exc2_fx, L_EXC_MEM ); - Copy( syn_fx + st_fx->L_frame - L_EXC_MEM, st_fx->hWIDec->old_syn2_fx, L_EXC_MEM ); - } - st_fx->prev_Q_exc_fr = st_fx->Q_exc; - move16(); - st_fx->prev_Q_syn_fr = st_fx->Q_syn; - move16(); - - Copy( syn_fx + st_fx->L_frame - L_SYN_MEM_CLAS_ESTIM, st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); - - test(); - IF( ( EQ_32( st_fx->total_brate, ACELP_7k20 ) ) || ( EQ_32( st_fx->total_brate, ACELP_8k00 ) ) ) - { - k = 0; - move16(); - FOR( i = 0; i < st_fx->L_frame; i += L_SUBFR ) - { - pitch_buf_tmp[k] = mult_r( pitch_buf_fx[k], 512 ); // Q0(6+9-15) , (512 = 1.0f in Q9) - move16(); - k = add( k, 1 ); - } - - /*------------------------------------------------------------* - * FEC - Smooth the speech energy evolution when recovering after a BAD frame - * (smoothing is performed in the excitation domain and signal is resynthesized after) - *------------------------------------------------------------*/ - - FEC_scale_syn_fx( st_fx->L_frame, &update_flg, st_fx->clas_dec, st_fx->last_good, syn_fx, pitch_buf_tmp, st_fx->enr_old_fx, enr_q_fx, st_fx->coder_type, LSF_Q_prediction, - &st_fx->scaling_flag, &st_fx->lp_ener_FEC_av, &st_fx->lp_ener_FEC_max, st_fx->bfi, st_fx->total_brate, st_fx->prev_bfi, st_fx->last_core_brate, - exc_fx, exc2_fx, Aq_fx, &st_fx->old_enr_LP, mem_tmp_fx, st_fx->mem_syn2_fx, st_fx->Q_exc, st_fx->Q_syn, avoid_lpc_burst_on_recovery, 0 ); - } - - /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ - /* fer_energy( st_fx->L_frame, st_fx->last_good, syn_fx, FEC_pitch_fx, &st_fx->enr_old_fx, st_fx->L_frame ); */ - frame_ener_fx( st_fx->L_frame, st_fx->last_good, syn_fx, shr( add( FEC_pitch_fx, 32 ), 6 ), &st_fx->enr_old_fx, st_fx->L_frame, st_fx->Q_syn, 3, 0 ); - - IF( st_fx->nelp_mode_dec != 1 ) - { - /* modify the excitation signal of stationary unvoiced frames */ - stat_noise_uv_mod_fx( st_fx->coder_type, 0, st_fx->lsp_old_fx, lsp_new_fx, lsp_new_fx, Aq_fx, exc2_fx, st_fx->Q_exc, 1, &st_fx->ge_sm_fx, - &st_fx->uv_count, &st_fx->act_count, st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, - &st_fx->exc_pe_fx, st_fx->core_brate, st_fx->bwidth, &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); - } - - /* SC-VBR */ - st_fx->hSC_VBR->FadeScale_fx = mult( st_fx->hSC_VBR->FadeScale_fx, 24576 ); /*24576 in Q15*/ - move16(); - } - IF( hBWE_TD != NULL ) - { - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - Copy( Aq_fx + 2 * ( M + 1 ), hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); // Q12 - } - ELSE - { - Copy( Aq_fx + 3 * ( M + 1 ), hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); // Q12 - } - } - /*--------------------------------------------------------* - * Apply NB postfilter in case of 8kHz output - *--------------------------------------------------------*/ - test(); - IF( EQ_16( st_fx->last_bwidth, NB ) && st_fx->hPFstat != NULL ) - { - k = 0; - move16(); - FOR( i = 0; i < st_fx->L_frame; i += L_SUBFR ) - { - pitch_buf_tmp[k] = mult_r( pitch_buf_fx[k], 512 ); // Q0(6+9-15) , (512 = 1.0f in Q9) - move16(); - k = add( k, 1 ); - } - - IF( EQ_16( st_fx->bwidth, NB ) ) - { - st_fx->hPFstat->on = 1; - move16(); - nb_post_filt_fx( st_fx->L_frame, st_fx->hPFstat, &st_fx->psf_lp_noise_fx, tmp_noise_fx, syn_fx, Aq_fx, pitch_buf_tmp, st_fx->coder_type, st_fx->BER_detect, 0 ); - } - ELSE - { - st_fx->hPFstat->on = 0; - move16(); - nb_post_filt_fx( st_fx->L_frame, st_fx->hPFstat, &st_fx->psf_lp_noise_fx, tmp_noise_fx, syn_fx, Aq_fx, pitch_buf_tmp, AUDIO, st_fx->BER_detect, 0 ); - } - } - ELSE - { - st_fx->psf_lp_noise_fx = round_fx( L_shl( st_fx->lp_noise, 1 ) ); - move16(); - } - - /*------------------------------------------------------------------* - * Perform fixed deemphasis through 1/(1 - g*z^-1) - *-----------------------------------------------------------------*/ - - /* Update old synthesis buffer - needed for ACELP internal sampling rate switching */ - Copy( syn_fx + st_fx->L_frame - L_SYN_MEM, st_fx->mem_syn_r, L_SYN_MEM ); - deemph_fx( syn_fx, st_fx->preemph_fac, st_fx->L_frame, &( st_fx->mem_deemph_fx ) ); - unscale_AGC( syn_fx, st_fx->Q_syn, syn_fx_tmp2, st_fx->agc_mem_fx, st_fx->L_frame ); - Copy( syn_fx_tmp2, syn_fx, st_fx->L_frame ); - - /* Update MODE2 memories*/ - IF( hTcxDec != NULL ) - { - Copy_Scale_sig( syn_fx + shr( st_fx->L_frame, 1 ), hTcxDec->old_syn_Overl, shr( st_fx->L_frame, 1 ), sub( -1, st_fx->Q_syn ) ); /*Q-1*/ - } - Copy_Scale_sig( syn_fx + st_fx->L_frame - M - 1, st_fx->syn, M + 1, sub( 0, st_fx->Q_syn ) ); /*Q0*/ - - /*------------------------------------------------------------------* - * Formant post-filter - *-----------------------------------------------------------------*/ - - IF( st_fx->hPFstat != NULL ) - { - test(); - test(); - test(); - IF( GE_16( st_fx->last_bwidth, WB ) && ( GT_32( st_fx->core_brate, ACELP_24k40 ) || ( st_fx->element_mode > EVS_MONO ) ) && LE_32( st_fx->core_brate, ACELP_32k ) ) - { - Copy( syn_fx, temp_buf + L_SYN_MEM, L_FRAME16k ); - st_fx->hPFstat->on = 1; - move16(); - formant_post_filt_fx( st_fx->hPFstat, temp_buf + L_SYN_MEM, Aq_fx, syn_fx, L_FRAME16k, st_fx->lp_noise, st_fx->total_brate, 0 ); - } - ELSE IF( GE_16( st_fx->last_bwidth, WB ) ) - { - IF( st_fx->hPFstat->on ) - { - Copy( st_fx->hPFstat->mem_pf_in + L_SYN_MEM - M, temp_buf, M ); - Copy( syn_fx, temp_buf + M, L_SUBFR ); - Residu3_fx( Aq_fx, temp_buf + M, temp_buf + M + L_SUBFR, L_SUBFR, 1 ); - E_UTIL_synthesis( 1, Aq_fx, temp_buf + M + L_SUBFR, temp_buf, L_SUBFR, st_fx->hPFstat->mem_stp + L_SYN_MEM - M, 0, M ); - scale_st_fx( syn_fx, temp_buf, &st_fx->hPFstat->gain_prec, L_SUBFR ); - Copy( temp_buf, syn_fx, L_SUBFR / 2 ); - blend_subfr2_fx( temp_buf + L_SUBFR / 2, syn_fx + L_SUBFR / 2, syn_fx + L_SUBFR / 2 ); - } - st_fx->hPFstat->on = 0; - move16(); - } - } - /*----------------------------------------------------------------* - * Comfort noise addition - *----------------------------------------------------------------*/ - - test(); - test(); - IF( ( st_fx->hFdCngDec != NULL || EQ_16( st_fx->idchan, 1 ) ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - test(); - test(); - test(); - test(); - test(); - IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) || st_fx->flag_cna || ( EQ_16( st_fx->cng_type, FD_CNG ) && LE_32( st_fx->total_brate, ACELP_32k ) ) || ( ( st_fx->cng_type == LP_CNG ) && LE_32( st_fx->total_brate, SID_2k40 ) ) ) - { - /*VAD only for non inactive frame*/ - test(); - st_fx->VAD = st_fx->VAD && ( st_fx->coder_type != INACTIVE ); - move16(); - test(); - test(); - test(); - test(); - test(); - IF( st_fx->idchan == 0 && ( st_fx->flag_cna || ( EQ_16( st_fx->cng_type, FD_CNG ) && LE_32( st_fx->total_brate, ACELP_32k ) ) || - ( EQ_16( st_fx->cng_type, LP_CNG ) && LE_32( st_fx->total_brate, SID_2k40 ) ) ) ) - { - /*Noisy speech detector*/ - noisy_speech_detection_fx( st_fx->hFdCngDec, st_fx->VAD, syn_fx, st_fx->Q_syn ); - - st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r( st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440 /*0.99 Q15*/ ); - move16(); - IF( st_fx->hFdCngDec->hFdCngCom->flag_noisy_speech != 0 ) - { - st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ ); - move16(); - } - } - if ( st_fx->idchan == 0 ) - { - st_fx->lp_noise = st_fx->hFdCngDec->lp_noise; - move32(); - } - /*Noise estimate*/ - IF( NE_16( st_fx->element_mode, IVAS_CPE_TD ) /* && !st->cng_ism_flag IVAS_CODE */ ) - { -#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - PMT( "Code for IVAS_CODE_CNG_FIX185_PLC_FADEOUT not done" ) - ApplyFdCng_fx( syn, st_fx->Q_syn, NULL, realBuffer, imagBuffer, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); -#else - ApplyFdCng_fx( syn_fx, st_fx->Q_syn, realBuffer, imagBuffer, NULL, st_fx, 0, ( EQ_16( st_fx->coder_type, AUDIO ) && st_fx->GSC_noisy_speech == 0 ) ); -#endif - } - /* CNA: Generate additional comfort noise to mask potential coding artefacts */ - } - - test(); - test(); - test(); - test(); - IF( st_fx->flag_cna && NE_16( st_fx->coder_type, AUDIO ) ) - { - generate_masking_noise_fx( syn_fx, st_fx->Q_syn, st_fx->hFdCngDec->hFdCngCom, st_fx->hFdCngDec->hFdCngCom->frameSize, 0 ); - } - ELSE IF( st_fx->flag_cna && EQ_16( st_fx->coder_type, AUDIO ) && st_fx->last_core == ACELP_CORE && NE_16( st_fx->last_coder_type, AUDIO ) ) - { - FOR( i = 0; i < st_fx->hFdCngDec->hFdCngCom->frameSize / 2; i++ ) - { - syn_fx[i] = add( syn_fx[i], shr_r( mult_r( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->hFdCngDec->hFdCngCom->frameSize / 4], st_fx->hFdCngDec->hFdCngCom->fftlenFac ), -st_fx->Q_syn ) ); - move16(); - } - } - - test(); - test(); - test(); - test(); - test(); - IF( st_fx->flag_cna == 0 && EQ_16( st_fx->L_frame, L_FRAME16k ) && EQ_16( st_fx->last_flag_cna, 1 ) && ( ( st_fx->last_core == ACELP_CORE && NE_16( st_fx->last_coder_type, AUDIO ) ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) - { - FOR( i = 0; i < st_fx->L_frame / 2; i++ ) - { - syn_fx[i] = add( syn_fx[i], shr_r( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->L_frame / 4], negate( st_fx->Q_syn ) ) ); - move16(); - } - } - - test(); - IF( st_fx->flag_cna == 0 || EQ_16( st_fx->coder_type, AUDIO ) ) - { - set16_fx( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st_fx->hFdCngDec->hFdCngCom->fftlen ); - } - } - - /*----------------------------------------------------------------* - * Resample to the output sampling rate (8/16/32/48 kHz) - * Bass post-filter - *----------------------------------------------------------------*/ - - /* check if the CLDFB works on the right sample rate */ - IF( ( st_fx->cldfbAna->usb * st_fx->cldfbAna->no_col ) != st_fx->L_frame ) - { - /* resample to ACELP internal sampling rate */ - Word16 newCldfbBands = CLDFB_getNumChannels( L_mult0( st_fx->L_frame, FRAMES_PER_SEC ) ); - resampleCldfb( st_fx->cldfbAna, newCldfbBands, st_fx->L_frame, 0 ); - resampleCldfb( st_fx->cldfbBPF, newCldfbBands, st_fx->L_frame, 0 ); - - IF( st_fx->ini_frame > 0 ) - { - st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ); - move16(); - } - } - - test(); - IF( !( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && st_fx->bpf_off ) ) - { - test(); - IF( NE_16( st_fx->L_frame, st_fx->last_L_frame ) && NE_16( st_fx->last_codec_mode, MODE2 ) ) - { - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - retro_interp5_4_fx( hBPF->pst_old_syn_fx ); - } - ELSE IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - retro_interp4_5_fx( syn_fx, hBPF->pst_old_syn_fx ); - } - } - - bass_psfilter_fx( st_fx->hBPF, st_fx->Opt_AMR_WB, syn_fx, st_fx->L_frame, pitch_buf_fx, st_fx->bpf_off, - st_fx->stab_fac_fx, &st_fx->stab_fac_smooth_fx, st_fx->coder_type, st_fx->Q_syn, bpf_error_signal ); - } - test(); - IF( NE_16( st_fx->element_mode, IVAS_CPE_DFT ) || use_cldfb_for_dft ) - { - /* analysis of the synthesis at internal sampling rate */ - cldfbAnalysis_fx( st_fx->cldfbAna, realBuffer, imagBuffer, &scaleFactor, syn_fx, negate( st_fx->Q_syn ), CLDFB_NO_COL_MAX, workBuffer ); - - scaleFactor.hb_scale = scaleFactor.lb_scale; - move16(); - - /* analysis and add the BPF error signal */ - i = 0; - move16(); - if ( st_fx->bpf_off == 0 ) - { - i = CLDFB_NO_COL_MAX; - move16(); - } - addBassPostFilter_fx( bpf_error_signal, realBuffer, imagBuffer, st_fx->cldfbBPF, workBuffer, negate( st_fx->Q_syn ), - i, st_fx->cldfbAna->no_col, st_fx->cldfbAna->no_channels, &scaleFactor ); - - /* set output mask for upsampling */ - IF( EQ_16( st_fx->bwidth, NB ) ) - { - /* set NB mask for upsampling */ - st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, 10 ); - move16(); - } - ELSE IF( NE_16( st_fx->cldfbSyn->bandsToZero, sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ) ) ) - { - /* in case of BW switching, re-init to default */ - st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ); - move16(); - } - - /*WB/SWB-FD_CNG*/ - scaleFactor.hb_scale = scaleFactor.lb_scale; - move16(); - - - test(); - IF( !st_fx->cng_sba_flag || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - test(); - test(); - test(); - IF( ( ( st_fx->core_brate == FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) && ( EQ_16( st_fx->cng_type, FD_CNG ) ) && ( LT_16( st_fx->hFdCngDec->hFdCngCom->numCoreBands, st_fx->cldfbSyn->no_channels ) ) ) - { - generate_comfort_noise_dec_hf_fx( realBuffer, imagBuffer, &scaleFactor.hb_scale, st_fx ); - - st_fx->cldfbSyn->bandsToZero = 0; - move16(); - IF( LT_16( st_fx->hFdCngDec->hFdCngCom->regularStopBand, st_fx->cldfbSyn->no_channels ) ) - { - st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, st_fx->hFdCngDec->hFdCngCom->regularStopBand ); - move16(); - } - st_fx->cldfbSyn->lsb = st_fx->cldfbAna->no_channels; - move16(); - } - } - /* synthesis of the combined signal */ - st_fx->Q_syn2 = st_fx->Q_syn; - move16(); - { - cldfbSynthesis_fx( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, synth_out, negate( st_fx->Q_syn2 ), CLDFB_NO_COL_MAX, workBuffer ); - } - /* Bring CLDFB output to Q0 */ - Scale_sig( synth_out, output_frame, negate( st_fx->Q_syn2 ) ); - st_fx->Q_syn2 = 0; - move16(); - - /* save synthesis - needed in case of core switching */ - Copy( synth_out, st_fx->previoussynth_fx, output_frame ); - } - - /*-----------------------------------------------------------------* - * Bandwidth extension 6kHz-7kHz - *-----------------------------------------------------------------*/ - IF( st_fx->hBWE_zero != NULL ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( EQ_16( st_fx->L_frame, L_FRAME ) && NE_16( st_fx->bwidth, NB ) && GE_16( output_frame, L_FRAME16k ) && - ( EQ_16( st_fx->extl, -1 ) || EQ_16( st_fx->extl, SWB_CNG ) || ( EQ_16( st_fx->extl, WB_BWE ) && st_fx->extl_brate == 0 && NE_16( st_fx->coder_type, AUDIO ) ) ) ) ) - { - hf_synth_fx( st_fx->hBWE_zero, st_fx->core_brate, output_frame, Aq_fx, exc2_fx, syn_fx, synth_out, st_fx->Q_exc, st_fx->Q_syn2 ); - } - ELSE - { - hf_synth_reset_fx( st_fx->hBWE_zero ); - } - } - - /*-----------------------------------------------------------------* - * Populate parameters for SWB TBE - *-----------------------------------------------------------------*/ - - /* Apply a non linearity to the SHB excitation */ - IF( hBWE_TD != NULL ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( !st_fx->bfi && ( st_fx->prev_bfi ) ) || ( ( EQ_16( st_fx->last_vbr_hw_BWE_disable_dec, 1 ) ) && ( st_fx->vbr_hw_BWE_disable_dec == 0 ) ) || ( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, WB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) ) && NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, WB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) || ( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && !st_fx->tdm_LRTD_flag ) ) - { - hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); - move32(); - set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - } - - test(); - test(); - test(); - test(); - test(); - IF( !st_fx->ppp_mode_dec && ( st_fx->idchan == 0 || NE_16( st_fx->element_mode, IVAS_CPE_TD ) || ( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && st_fx->tdm_LRTD_flag ) ) ) - { - non_linearity_fx( bwe_exc_fx, bwe_exc_extended, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, st_fx->Q_exc, - st_fx->coder_type, voice_factors, st_fx->L_frame ); - } - - test(); - IF( ( st_fx->core_brate == FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) - { - hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); - move32(); - } - } - /*----------------------------------------------------------------------* - * Updates - *----------------------------------------------------------------------*/ - - updt_dec_fx( st_fx, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, voice_factors, old_bwe_exc_fx, gain_buf ); - - test(); - test(); - IF( GT_32( st_fx->core_brate, SID_2k40 ) && st_fx->hTdCngDec != NULL && st_fx->hFdCngDec != NULL ) - { - /* update CNG parameters in active frames */ - cng_params_upd_fx( lsp_new_fx, exc_fx, st_fx->L_frame, &st_fx->hTdCngDec->ho_circ_ptr, st_fx->hTdCngDec->ho_ener_circ_fx, &st_fx->hTdCngDec->ho_circ_size, st_fx->hTdCngDec->ho_lsp_circ_fx, - st_fx->Q_exc, DEC, st_fx->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st_fx->last_active_brate ); - /* Set 16k LSP flag for CNG buffer */ - st_fx->hTdCngDec->ho_16k_lsp[st_fx->hTdCngDec->ho_circ_ptr] = 0; - move16(); - if ( NE_16( st_fx->L_frame, L_FRAME ) ) - { - st_fx->hTdCngDec->ho_16k_lsp[st_fx->hTdCngDec->ho_circ_ptr] = 1; - move16(); - } - } - - return IVAS_ERR_OK; -} -#endif diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index ad8ca9b50..2c72bba78 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -47,12 +47,12 @@ /*-------------------------------------------------------------------* - * acelp_core_dec_ivas_fx() + * acelp_core_dec_fx() * * ACELP core decoder *-------------------------------------------------------------------*/ -ivas_error acelp_core_dec_ivas_fx( +ivas_error acelp_core_dec_fx( Decoder_State *st, /* i/o: decoder state structure */ Word16 output_fx[], /* o : synthesis @internal Fs Q_syn*/ Word16 synth_fx16[], /* o : synthesis Q_syn2*/ @@ -81,14 +81,14 @@ ivas_error acelp_core_dec_ivas_fx( Word16 syn_tmp_fx[L_FRAME16k + L_SUBFR], *psyn_fx; /* synthesis signal buffer */ Word16 output_frame; /* frame length at output sampling freq. */ Word16 lsf_new_fx[M]; /* LSFs at the end of the frame Qlog2(2.56) */ - Word16 lsp_new_fx[M]; /* LSPs at the end of the frame Q15 */ + Word16 lsp_new_fx[M]; /* LSPs at the end of the frame Q15 */ Word16 lsp_mid_fx[M]; /* LSPs in the middle of the frame */ Word16 Aq_fx[NB_SUBFR16k * ( M + 1 )]; /* A(q) quantized for the 4 subframes */ Word16 old_exc2_fx[L_FRAME16k + L_EXC_MEM], *exc2_fx; /* total excitation buffer */ Word16 mem_tmp_fx[M]; /* temporary synthesis filter memory */ Word32 enr_q_fx; /* E information for FER protection */ Word16 tmp_noise_fx; /* Long term temporary noise energy */ - Word16 Es_pred_fx; /* predicted scaled innov. energy Q8 */ + Word16 Es_pred_fx; /* predicted scaled innov. energy Q8 */ Word16 FEC_pitch_fx; /* FEC pitch */ Word16 old_bwe_exc_fx[( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 )]; /* excitation buffer */ Word16 *bwe_exc_fx; /* Excitation for SWB TBE */ @@ -181,6 +181,7 @@ ivas_error acelp_core_dec_ivas_fx( st->hFdCngDec->hFdCngCom->sidNoiseEstExp = common_e; move16(); } + FOR( i = 0; i < NPART; i++ ) { st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] = Madd_32_32( Mpy_32_32( STEREO_DFT_FD_FILT_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] ), @@ -188,14 +189,14 @@ ivas_error acelp_core_dec_ivas_fx( move32(); } - ApplyFdCng_ivas_fx( NULL, 0, NULL, 0, NULL, NULL, NULL, st, 0, 0 ); + ApplyFdCng_fx( NULL, 0, NULL, 0, NULL, NULL, NULL, st, 0, 0 ); } ELSE { configureFdCngDec_fx( st->hFdCngDec, st->bwidth, ACELP_14k25, st->L_frame, st->last_L_frame, st->element_mode ); /* decode CNG parameters */ - CNG_dec_ivas_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx ); + CNG_dec_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx ); /* comfort noise generation */ CNG_exc_fx( st->core_brate, st->L_frame, &st->hTdCngDec->Enew_fx, &st->hTdCngDec->cng_seed, NULL, NULL, &st->lp_ener_fx, st->last_core_brate, &st->first_CNG, &( st->hTdCngDec->cng_ener_seed ), NULL, allow_cn_step, &st->hTdCngDec->last_allow_cn_step, st->prev_Q_exc, st->Q_exc, st->hTdCngDec->num_ho, q_env_fx, st->hTdCngDec->lp_env_fx, st->hTdCngDec->old_env_fx, st->hTdCngDec->exc_mem_fx, st->hTdCngDec->exc_mem1_fx, sid_bw, &st->hTdCngDec->cng_ener_seed1, NULL, st->Opt_AMR_WB, st->element_mode ); @@ -636,7 +637,7 @@ ivas_error acelp_core_dec_ivas_fx( /* decode CNG parameters */ IF( st->cng_type == LP_CNG ) { - CNG_dec_ivas_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx ); + CNG_dec_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx ); Copy( Aq_fx, st->Aq_cng, add( M, 1 ) ); /* comfort noise generation */ @@ -657,13 +658,11 @@ ivas_error acelp_core_dec_ivas_fx( test(); IF( EQ_32( st->core_brate, SID_2k40 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { FdCng_decodeSID_fx( st->hFdCngDec->hFdCngCom, st ); } ELSE -#endif { Word16 old_NoiseEstExp = st->hFdCngDec->hFdCngCom->sidNoiseEstExp; move16(); @@ -689,7 +688,7 @@ ivas_error acelp_core_dec_ivas_fx( move32(); } - ApplyFdCng_ivas_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); + ApplyFdCng_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); Word16 new_sidNoiseEstExp = 31 - Q4; move16(); @@ -704,7 +703,7 @@ ivas_error acelp_core_dec_ivas_fx( move16(); test(); - ApplyFdCng_ivas_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( EQ_16( st->coder_type, AUDIO ) && !st->GSC_noisy_speech ) ); + ApplyFdCng_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( EQ_16( st->coder_type, AUDIO ) && !st->GSC_noisy_speech ) ); IF( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 ) { @@ -728,13 +727,11 @@ ivas_error acelp_core_dec_ivas_fx( } } -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { generate_comfort_noise_dec_fx( NULL, NULL, NULL, st, &( st->Q_exc ), 2, -1 ); } ELSE -#endif { generate_comfort_noise_dec_ivas_fx( NULL, NULL, NULL, st, &( st->Q_exc ), 1, nchan_out ); } @@ -758,7 +755,6 @@ ivas_error acelp_core_dec_ivas_fx( test(); IF( st->hMusicPF && st->hGSCDec ) { -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { // VE: TBV: should 'st_fx->L_frame * HIBND_ACB_L_FAC' be corrected in EVS? @@ -766,7 +762,6 @@ ivas_error acelp_core_dec_ivas_fx( st->L_frame * HIBND_ACB_L_FAC, 0, &( st->Q_exc ), st->Q_subfr, NULL, 0, INACTIVE ); } ELSE -#endif { Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, bwe_exc_fx, st->hGSCDec->last_exc_dct_in_fx, st->L_frame, L_FRAME32k, 0, &( st->Q_exc ), st->Q_subfr, NULL, 0, INACTIVE ); @@ -794,7 +789,6 @@ ivas_error acelp_core_dec_ivas_fx( /* Update music post processing values */ /* Filter energies update */ -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { FOR( i = 0; i < DCT_L_POST; i++ ) @@ -804,7 +798,6 @@ ivas_error acelp_core_dec_ivas_fx( } } ELSE -#endif { FOR( i = 0; i < DCT_L_POST; i++ ) { @@ -822,15 +815,12 @@ ivas_error acelp_core_dec_ivas_fx( /* reset the decoder */ CNG_reset_dec_fx( st, pitch_buf_fx, voice_factors_fx ); - -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { /* update st_fx->mem_syn1 for ACELP core switching */ Copy( st->mem_syn3_fx, st->mem_syn1_fx, M ); } ELSE -#endif { st->Q_syn_cng = st->Q_syn; move16(); @@ -889,13 +879,13 @@ ivas_error acelp_core_dec_ivas_fx( move16(); } - config_acelp1_IVAS( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, st->inactive_coder_type_flag, tc_subfr_tmp, 1, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); + config_acelp1_fx( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, st->inactive_coder_type_flag, tc_subfr_tmp, 1, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); test(); test(); IF( EQ_16( st->coder_type, TRANSITION ) && LT_16( tc_subfr, L_SUBFR ) && EQ_16( st->L_frame, L_FRAME ) ) { - config_acelp1_IVAS( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, -1, &( st->acelp_cfg ), st->next_bit_pos, TRANSITION, -1, tc_subfr, 2, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); + config_acelp1_fx( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, -1, &( st->acelp_cfg ), st->next_bit_pos, TRANSITION, -1, tc_subfr, 2, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); } } @@ -934,7 +924,7 @@ ivas_error acelp_core_dec_ivas_fx( IF( !tdm_lp_reuse_flag ) { - lsf_dec_ivas_fx( st, tc_subfr, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode, tdm_lsfQ_PCh_fx ); + lsf_dec_fx( st, tc_subfr, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode, tdm_lsfQ_PCh_fx ); } ELSE { @@ -1084,7 +1074,7 @@ ivas_error acelp_core_dec_ivas_fx( } ELSE /* GENERIC */ { - decod_gen_2sbfr_ivas_fx( st, sharpFlag, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ); + decod_gen_2sbfr_fx( st, sharpFlag, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ); IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) { @@ -1106,7 +1096,7 @@ ivas_error acelp_core_dec_ivas_fx( ELSE IF( EQ_16( st->coder_type, UNVOICED ) ) { /* UNVOICED frames */ - decod_unvoiced_ivas_fx( st, Aq_fx, Es_pred_fx, uc_two_stage_flag, st->coder_type, &tmp_noise_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx ); + decod_unvoiced_fx( st, Aq_fx, Es_pred_fx, uc_two_stage_flag, st->coder_type, &tmp_noise_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx ); tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ } @@ -1131,15 +1121,15 @@ ivas_error acelp_core_dec_ivas_fx( ELSE IF( EQ_16( st->coder_type, AUDIO ) || ( ( st->coder_type == INACTIVE ) && st->inactive_coder_type_flag ) ) { /* AUDIO and INACTIVE frames (coded by GSC technology) */ - decod_audio_ivas_fx( st, dct_exc_tmp_fx, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf_fx, - tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ); + decod_audio_fx( st, dct_exc_tmp_fx, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf_fx, + tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ); tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ } ELSE { /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ - IF( NE_32( ( error = decod_gen_voic_ivas_fx( st, st->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = decod_gen_voic_fx( st, st->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ) ), IVAS_ERR_OK ) ) { return error; } @@ -1163,7 +1153,7 @@ ivas_error acelp_core_dec_ivas_fx( * Apply energy matching when switching to inactive frames *-----------------------------------------------------------------*/ - Inac_switch_ematch_ivas_fx( exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->inactive_coder_type_flag, st->L_frame, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); + Inac_switch_ematch_fx( exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->inactive_coder_type_flag, st->L_frame, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); /*------------------------------------------------------------* * Decode information and modify the excitation signal of stationary unvoiced frames @@ -1212,7 +1202,6 @@ ivas_error acelp_core_dec_ivas_fx( move16(); /* Extrapolation of the last future part, windowing and high resolution DCT transform */ -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { // VE: TBV: this is likely a bug in EVS - 'st->last_coder_type' should be replaced by 'st->core_brate' @@ -1220,7 +1209,6 @@ ivas_error acelp_core_dec_ivas_fx( st->hMusicPF->LDm_enh_lp_gbin_fx, st->Q_exc, &qdct ); } ELSE -#endif { Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, st->hMusicPF->filt_lfE_fx, st->last_core, st->element_mode, pitch_buf_fx, st->hMusicPF->LDm_enh_lp_gbin_fx, st->Q_exc, &qdct ); } @@ -1229,9 +1217,7 @@ ivas_error acelp_core_dec_ivas_fx( LD_music_post_filter_fx( st->hMusicPF, dct_buffer_fx, dct_buffer_fx, st->core_brate, &st->hMusicPF->Old_ener_Q, AUDIO, last_coder_type, qdct ); /* Inverse DCT transform, retrieval of the aligned excitation, re-synthesis */ -#ifdef REMOVE_EVS_DUPLICATES IF( NE_16( st->element_mode, EVS_MONO ) ) // VE: TBC whether needed in IVAS -#endif { Copy( st->mem_syn2_fx, mem_tmp_fx, M ); /*Q_syn*/ } @@ -1300,13 +1286,9 @@ ivas_error acelp_core_dec_ivas_fx( Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, st->nb_subfr, -Q6 ); // Q0 - FEC_scale_syn_ivas_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction, - &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, -#ifdef REMOVE_EVS_DUPLICATES - exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, st->element_mode, avoid_lpc_burst_on_recovery, 0 ); -#else - exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, avoid_lpc_burst_on_recovery, 0 ); -#endif + FEC_scale_syn_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction, + &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, + exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, st->element_mode, avoid_lpc_burst_on_recovery, 0 ); test(); test(); @@ -1384,7 +1366,7 @@ ivas_error acelp_core_dec_ivas_fx( } /* Apply energy matching when switching to inactive frames */ - Inac_switch_ematch_ivas_fx( exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->inactive_coder_type_flag, st->L_frame, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); + Inac_switch_ematch_fx( exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->inactive_coder_type_flag, st->L_frame, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); /* update past excitation signals for LD music post-filter */ IF( st->hMusicPF != NULL ) @@ -1452,13 +1434,9 @@ ivas_error acelp_core_dec_ivas_fx( { Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, st->nb_subfr, -Q6 ); // Q0 - FEC_scale_syn_ivas_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction, - &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, -#ifdef REMOVE_EVS_DUPLICATES - exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, st->element_mode, avoid_lpc_burst_on_recovery, 0 ); -#else - exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, avoid_lpc_burst_on_recovery, 0 ); -#endif + FEC_scale_syn_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction, + &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, + exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, st->element_mode, avoid_lpc_burst_on_recovery, 0 ); } /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ @@ -1544,7 +1522,7 @@ ivas_error acelp_core_dec_ivas_fx( Copy( psyn_fx, temp_buf_fx + L_SYN_MEM, L_FRAME16k ); set16_fx( st->hPFstat->mem_zero, 0, M ); - formant_post_filt_ivas_fx( st->hPFstat, temp_buf_fx + L_SYN_MEM, Aq_fx, psyn_fx, st->L_frame, st->lp_noise, st->total_brate, 0 ); + formant_post_filt_fx( st->hPFstat, temp_buf_fx + L_SYN_MEM, Aq_fx, psyn_fx, st->L_frame, st->lp_noise, st->total_brate, 0 ); } ELSE IF( st->hPFstat != NULL && GE_16( st->last_bwidth, WB ) ) { @@ -1612,7 +1590,7 @@ ivas_error acelp_core_dec_ivas_fx( IF( NE_16( st->element_mode, IVAS_CPE_TD ) && !st->cng_ism_flag ) { /* Noise estimate */ - ApplyFdCng_ivas_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); + ApplyFdCng_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); } IF( !st->cna_dirac_flag ) @@ -1652,13 +1630,11 @@ ivas_error acelp_core_dec_ivas_fx( } ELSE IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) { -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { generate_masking_noise_fx( psyn_fx, st->Q_syn, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0 ); } ELSE -#endif { IF( st->idchan == 0 ) { @@ -1666,10 +1642,13 @@ ivas_error acelp_core_dec_ivas_fx( { set16_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen ); } + Word32 psyn_32_fx[L_FRAME16k]; Copy_Scale_sig_16_32_no_sat( psyn_fx, psyn_32_fx, st->hFdCngDec->hFdCngCom->frameSize, sub( Q6, st->Q_syn ) ); // Q6 Copy_Scale_sig_16_32_no_sat( st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, shl( st->hFdCngDec->hFdCngCom->frameSize, 1 ), Q15 ); // Q15 + generate_masking_noise_ivas_fx( psyn_32_fx, &exp, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0, 0, 0, st->element_mode, hStereoCng, nchan_out ); + Copy_Scale_sig_32_16( psyn_32_fx, psyn_fx, st->hFdCngDec->hFdCngCom->frameSize, sub( st->Q_syn, exp ) ); // Q = st->Q_syn Copy_Scale_sig_32_16( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2, shl( st->hFdCngDec->hFdCngCom->frameSize, 1 ), -Q15 ); // Q0 } @@ -1713,7 +1692,7 @@ ivas_error acelp_core_dec_ivas_fx( /*Noise estimate*/ IF( ( st->idchan == 0 ) && ( EQ_16( nchan_out, 2 ) || ( st->core_brate != FRAME_NO_DATA && NE_32( st->core_brate, SID_2k40 ) ) ) ) { - ApplyFdCng_ivas_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); + ApplyFdCng_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); } } } @@ -1730,7 +1709,6 @@ ivas_error acelp_core_dec_ivas_fx( test(); IF( ( st->flag_cna == 0 ) && EQ_16( st->L_frame, L_FRAME16k ) && EQ_16( st->last_flag_cna, 1 ) && ( ( st->last_core == ACELP_CORE && !( EQ_16( st->last_coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag ) ) ) || EQ_16( st->last_core, AMR_WB_CORE ) ) ) { -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { // VE: TBV - is it correct in EVS? in FLP, it is: @@ -1743,7 +1721,6 @@ ivas_error acelp_core_dec_ivas_fx( } } ELSE -#endif { FOR( i = 0; i < ( st->hFdCngDec->hFdCngCom->frameSize ) / 2; i++ ) { @@ -1775,7 +1752,6 @@ ivas_error acelp_core_dec_ivas_fx( * Bass post-filter *----------------------------------------------------------------*/ -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { CLDFB_SCALE_FACTOR scaleFactor; @@ -1880,7 +1856,6 @@ ivas_error acelp_core_dec_ivas_fx( Copy( synth_fx16, st->previoussynth_fx, output_frame ); } ELSE -#endif { /* check if the CLDFB works on the right sample rate */ IF( NE_16( imult1616( st->cldfbAna->no_channels, st->cldfbAna->no_col ), st->L_frame ) ) @@ -1896,9 +1871,7 @@ ivas_error acelp_core_dec_ivas_fx( } /* analyze pitch coherence for bass post-filter */ - Word32 pitch_buf_fx_q20[12]; - Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, Q4 ); // Q(x+4) Word16 lim = shr( st->L_frame, 6 ); FOR( Word16 lp = 0; lp < lim; lp++ ) @@ -1961,7 +1934,9 @@ ivas_error acelp_core_dec_ivas_fx( Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, 1 ); // Q12 st->cldfbAna->Q_cldfb_state = Q12; move16(); + cldfbAnalysis_ivas_fx( syn_32_fx, realBuffer_fx, imagBuffer_fx, -1, st->cldfbAna ); + Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, -1 ); // Q11 st->cldfbAna->Q_cldfb_state = Q11; move16(); @@ -1990,6 +1965,7 @@ ivas_error acelp_core_dec_ivas_fx( } addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx, tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF ); + Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, negate( ( sub( q_bpf_error_signal, Q10 ) ) ) ); // Q10 st->cldfbBPF->Q_cldfb_state = Q10; move16(); @@ -2186,6 +2162,7 @@ ivas_error acelp_core_dec_ivas_fx( Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, 1 ); // Q12 st->cldfbAna->Q_cldfb_state = Q12; move16(); + cldfbAnalysis_ivas_fx( syn_32_fx + sub( st->L_frame, nSamples ), realBuffer_fx, imagBuffer_fx, nSamples, st->cldfbAna ); Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, -1 ); // Q11 @@ -2215,8 +2192,8 @@ ivas_error acelp_core_dec_ivas_fx( tmp = nSamples; move16(); } - addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx + sub( st->L_frame, nSamples ), tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF ); + addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx + sub( st->L_frame, nSamples ), tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF ); Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, negate( sub( q_bpf_error_signal, Q10 ) ) ); // Q10 st->cldfbBPF->Q_cldfb_state = Q10; @@ -2299,13 +2276,11 @@ ivas_error acelp_core_dec_ivas_fx( IF( ( EQ_16( st->L_frame, L_FRAME ) && ( st->bwidth != NB ) && GE_16( output_frame, L_FRAME16k ) && ( EQ_16( st->extl, -1 ) || EQ_16( st->extl, SWB_CNG ) || ( EQ_16( st->extl, WB_BWE ) && st->extl_brate == 0 && NE_16( st->coder_type, AUDIO ) ) ) ) ) { -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { hf_synth_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc2_fx, psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2 ); } ELSE -#endif { Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); // Q0 hf_synth_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc2_fx, psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2 ); @@ -2315,9 +2290,7 @@ ivas_error acelp_core_dec_ivas_fx( ELSE { hf_synth_reset_fx( st->hBWE_zero ); -#ifdef REMOVE_EVS_DUPLICATES IF( NE_16( st->element_mode, EVS_MONO ) ) // VE: TBV: tmp hack - it is a bug in EVS but condition is here to keep EVS bit-exact for the moment -#endif { set16_fx( st->hBWE_zero->mem_hp400_fx, 0, 6 ); } @@ -2356,13 +2329,11 @@ ivas_error acelp_core_dec_ivas_fx( test(); IF( !st->ppp_mode_dec && ( 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 ) ) ) { -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { non_linearity_fx( bwe_exc_fx, bwe_exc_extended_fx, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame ); } ELSE -#endif { Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( sub( shl( st->Q_exc, 1 ), sub( st->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, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame ); @@ -2389,14 +2360,12 @@ ivas_error acelp_core_dec_ivas_fx( IF( GT_32( st->core_brate, SID_2k40 ) && st->hTdCngDec != NULL && st->hFdCngDec != NULL ) { /* update CNG parameters in active frames */ -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { cng_params_upd_fx( lsp_new_fx, exc_fx, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate ); } ELSE -#endif { cng_params_upd_ivas_fx( lsp_new_fx, exc_fx, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode, @@ -2413,9 +2382,7 @@ ivas_error acelp_core_dec_ivas_fx( } } -#ifdef REMOVE_EVS_DUPLICATES IF( NE_16( st->element_mode, EVS_MONO ) ) -#endif { IF( save_hb_synth_fx16 ) { diff --git a/lib_dec/acelp_core_switch_dec_fx.c b/lib_dec/acelp_core_switch_dec_fx.c index 6d3d0b381..363db8202 100644 --- a/lib_dec/acelp_core_switch_dec_fx.c +++ b/lib_dec/acelp_core_switch_dec_fx.c @@ -128,11 +128,7 @@ ivas_error acelp_core_switch_dec_fx( * Excitation decoding *----------------------------------------------------------------*/ -#ifdef REMOVE_EVS_DUPLICATES - config_acelp1_IVAS( DEC, st_fx->total_brate, cbrate, st_fx->core, -1, -1, st_fx->last_L_frame, -1, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, GENERIC, st_fx->inactive_coder_type_flag, -1, -1, &decode_bwe /* dummy */, &i, st_fx->element_mode, &i /*dummy*/, 0, 0, st_fx->idchan, st_fx->active_cnt, 0, 0, 0 ); -#else - config_acelp1( DEC, st_fx->total_brate, cbrate, st_fx->core, -1, -1, st_fx->last_L_frame, -1, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, GENERIC, st_fx->inactive_coder_type_flag, -1, -1, &decode_bwe /* dummy */, &i, st_fx->element_mode, &i /*dummy*/, 0, 0, st_fx->idchan, st_fx->active_cnt, 0, 0, 0 ); -#endif + config_acelp1_fx( DEC, st_fx->total_brate, cbrate, st_fx->core, -1, -1, st_fx->last_L_frame, -1, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, GENERIC, st_fx->inactive_coder_type_flag, -1, -1, &decode_bwe /* dummy */, &i, st_fx->element_mode, &i /*dummy*/, 0, 0, st_fx->idchan, st_fx->active_cnt, 0, 0, 0 ); decod_gen_voic_core_switch_fx( st_fx, L_frame_for_cs, 0, Aq, exc, cbrate, &st_fx->Q_exc ); @@ -920,11 +916,7 @@ static void decod_gen_voic_core_switch_fx( * Decode pitch lag *----------------------------------------------------------------------*/ -#ifdef REMOVE_EVS_DUPLICATES - pitch = pit_decode_ivas_fx( st_fx, core_brate, 0, L_frame, 0, GENERIC, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_SUBFR, 0, NULL ); /*Q6*/ -#else - pitch = pit_decode_fx( st_fx, core_brate, 0, L_frame, 0, GENERIC, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_SUBFR ); /*Q6*/ -#endif + pitch = pit_decode_fx( st_fx, core_brate, 0, L_frame, 0, GENERIC, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_SUBFR, 0, NULL ); /*Q6*/ /*--------------------------------------------------------------* * Find the adaptive codebook vector. diff --git a/lib_dec/amr_wb_dec_fx.c b/lib_dec/amr_wb_dec_fx.c index c1c1e6143..96ae82dde 100644 --- a/lib_dec/amr_wb_dec_fx.c +++ b/lib_dec/amr_wb_dec_fx.c @@ -373,11 +373,7 @@ ivas_error amr_wb_dec_fx( IF( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_1k75 ) ) { /* decode CNG parameters */ -#ifdef REMOVE_EVS_DUPLICATES - CNG_dec_ivas_fx( st_fx, EVS_MONO, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, &sid_bw, q_env ); -#else CNG_dec_fx( st_fx, EVS_MONO, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, &sid_bw, q_env ); -#endif /* comfort noise generation */ CNG_exc_fx( st_fx->core_brate, L_FRAME, &st_fx->hTdCngDec->Enew_fx, &st_fx->hTdCngDec->cng_seed, exc_fx, exc2_fx, &st_fx->lp_ener_fx, st_fx->last_core_brate, @@ -630,15 +626,9 @@ ivas_error amr_wb_dec_fx( move16(); } -#ifdef REMOVE_EVS_DUPLICATES - FEC_scale_syn_ivas_fx( L_FRAME, &update_flg, st_fx->clas_dec, st_fx->last_good, syn_fx, pitch_buf_tmp, st_fx->enr_old_fx, L_enr_q_fx, -1, MOVING_AVERAGE, - &st_fx->scaling_flag, &st_fx->lp_ener_FEC_av, &st_fx->lp_ener_FEC_max, st_fx->bfi, st_fx->total_brate, st_fx->prev_bfi, st_fx->last_core_brate, - exc_fx, exc2_fx, Aq_fx, &st_fx->old_enr_LP, mem_tmp_fx, st_fx->mem_syn2_fx, st_fx->Q_exc, st_fx->Q_syn, EVS_MONO, avoid_lpc_burst_on_recovery, 0 ); -#else FEC_scale_syn_fx( L_FRAME, &update_flg, st_fx->clas_dec, st_fx->last_good, syn_fx, pitch_buf_tmp, st_fx->enr_old_fx, L_enr_q_fx, -1, MOVING_AVERAGE, &st_fx->scaling_flag, &st_fx->lp_ener_FEC_av, &st_fx->lp_ener_FEC_max, st_fx->bfi, st_fx->total_brate, st_fx->prev_bfi, st_fx->last_core_brate, - exc_fx, exc2_fx, Aq_fx, &st_fx->old_enr_LP, mem_tmp_fx, st_fx->mem_syn2_fx, st_fx->Q_exc, st_fx->Q_syn, avoid_lpc_burst_on_recovery, 0 ); -#endif + exc_fx, exc2_fx, Aq_fx, &st_fx->old_enr_LP, mem_tmp_fx, st_fx->mem_syn2_fx, st_fx->Q_exc, st_fx->Q_syn, EVS_MONO, avoid_lpc_burst_on_recovery, 0 ); frame_ener_fx( L_FRAME, st_fx->clas_dec, syn_fx, pitch_buf_tmp[3], &st_fx->enr_old_fx, L_FRAME, st_fx->Q_syn, 3, 0 ); } @@ -717,17 +707,10 @@ ivas_error amr_wb_dec_fx( * (smoothing is performed in the excitation domain and signal is resynthesized after) *------------------------------------------------------------*/ -#ifdef REMOVE_EVS_DUPLICATES - FEC_scale_syn_ivas_fx( L_FRAME, &update_flg, st_fx->clas_dec, st_fx->last_good, syn_fx, pitch_buf_tmp, st_fx->enr_old_fx, L_enr_q_fx, -1, - MOVING_AVERAGE, &st_fx->scaling_flag, &st_fx->lp_ener_FEC_av, &st_fx->lp_ener_FEC_max, st_fx->bfi, st_fx->total_brate, - st_fx->prev_bfi, st_fx->last_core_brate, exc_fx, exc2_fx, Aq_fx, &st_fx->old_enr_LP, mem_tmp_fx, st_fx->mem_syn2_fx, - st_fx->Q_exc, st_fx->Q_syn, EVS_MONO, 0, 0 ); -#else FEC_scale_syn_fx( L_FRAME, &update_flg, st_fx->clas_dec, st_fx->last_good, syn_fx, pitch_buf_tmp, st_fx->enr_old_fx, L_enr_q_fx, -1, MOVING_AVERAGE, &st_fx->scaling_flag, &st_fx->lp_ener_FEC_av, &st_fx->lp_ener_FEC_max, st_fx->bfi, st_fx->total_brate, st_fx->prev_bfi, st_fx->last_core_brate, exc_fx, exc2_fx, Aq_fx, &st_fx->old_enr_LP, mem_tmp_fx, st_fx->mem_syn2_fx, - st_fx->Q_exc, st_fx->Q_syn, 0, 0 ); -#endif + st_fx->Q_exc, st_fx->Q_syn, EVS_MONO, 0, 0 ); /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ frame_ener_fx( L_FRAME, st_fx->last_good, syn_fx, shr( FEC_pitch_fx, 6 ), &st_fx->enr_old_fx, L_FRAME, st_fx->Q_syn, 3, 0 ); @@ -785,11 +768,7 @@ ivas_error amr_wb_dec_fx( st_fx->hPFstat->on = 1; move16(); test(); -#ifdef REMOVE_EVS_DUPLICATES - formant_post_filt_ivas_fx( st_fx->hPFstat, tmp_buffer_fx + L_SYN_MEM, Aq_fx, syn_fx, L_FRAME, L_shl( st_fx->psf_lp_noise_fx, 15 ), st_fx->total_brate, sub( amr_io_class, AUDIO_CLAS ) == 0 ); -#else formant_post_filt_fx( st_fx->hPFstat, tmp_buffer_fx + L_SYN_MEM, Aq_fx, syn_fx, L_FRAME, L_shl( st_fx->psf_lp_noise_fx, 15 ), st_fx->total_brate, sub( amr_io_class, AUDIO_CLAS ) == 0 ); -#endif } /*----------------------------------------------------------------* @@ -813,16 +792,9 @@ ivas_error amr_wb_dec_fx( st_fx->VAD = 0; move16(); } -#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - PMT( "Fixed point not done here " ) - ApplyFdCng_fx( syn, NULL, NULL, NULL, st, 0, 0 ); -#else -#ifdef REMOVE_EVS_DUPLICATES - ApplyFdCng_ivas_fx( syn_fx, st_fx->Q_syn, NULL, 0, NULL, NULL, NULL, st_fx, 0, 0 ); -#else - ApplyFdCng_fx( syn_fx, st_fx->Q_syn, NULL, NULL, NULL, st_fx, 0, 0 ); -#endif -#endif + + ApplyFdCng_fx( syn_fx, st_fx->Q_syn, NULL, 0, NULL, NULL, NULL, st_fx, 0, 0 ); + st_fx->hFdCngDec->hFdCngCom->frame_type_previous = st_fx->m_frame_type; move16(); diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c index ce6ad6568..fdb6488db 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -22,19 +22,19 @@ static void shb_CNG_decod_fx( Decoder_State *st_fx, const Word16 *synth_fx, Word static void shb_CNG_decod_ivas_fx( Decoder_State *st_fx, const Word16 *synth_fx, Word16 *shb_synth_fx, const Word16 sid_bw, const Word16 Qsyn ); /*-----------------------------------------------------------------* + * CNG_dec_fx() + * * Decode residual signal energy *-----------------------------------------------------------------*/ -#ifndef REMOVE_EVS_DUPLICATES void CNG_dec_fx( Decoder_State *st_fx, /* i/o: State structure */ - const Word16 last_element_mode, /* i : last element mode Q0 */ + const Word16 last_element_mode, /* i : last element mode Q0 */ Word16 Aq[], /* o : LP coefficients Q12 */ Word16 *lsp_new, /* i/o: current frame LSPs Q15 */ Word16 *lsf_new, /* i/o: current frame LSFs Qlog2(2.56) */ Word16 *allow_cn_step, /* o : allow CN step Q0 */ - Word16 *sid_bw /* i : 0-NB/WB, 1-SWB SID Q0 */ - , + Word16 *sid_bw, /* i : 0-NB/WB, 1-SWB SID Q0 */ Word32 *q_env ) { Word16 istep; @@ -72,7 +72,6 @@ void CNG_dec_fx( Word16 exp_pow; Word16 tmp_loop; Word16 enr_new, Aq_tmp[M + 1]; - Word16 LSF_Q_prediction; /* o : LSF prediction mode - just temporary variable in CNG */ TD_CNG_DEC_HANDLE hTdCngDec; #ifdef BASOP_NOGLOB_DECLARE_LOCAL @@ -108,681 +107,9 @@ void CNG_dec_fx( } ELSE { - lsf_dec_fx( st_fx, 0, Aq, &LSF_Q_prediction, lsf_new, lsp_new, 0, 0, - NULL ); - /* check IF LSPs may trigger too much synthesis energy */ - - E_LPC_f_lsp_a_conversion( lsp_new, Aq_tmp, M ); - enr_new = Enr_1_Az_fx( Aq_tmp, 2 * L_SUBFR ); - - IF( shr( enr_new, 14 ) > 0 ) - { - /* Use old LSP vector */ - Copy( st_fx->lsp_old_fx, lsp_new, M ); /* Q15 */ - Copy( st_fx->lsf_old_fx, lsf_new, M ); /* Q2.56 */ - } - } - } - ELSE - { - /* Use old LSP vector */ - Copy( st_fx->lsp_old_fx, lsp_new, M ); /* Q15 */ - Copy( st_fx->lsf_old_fx, lsf_new, M ); /* Q2.56 */ - } - - /* Initialize the CNG spectral envelope in case of the very first CNG frame */ - IF( st_fx->first_CNG == 0 ) - { - Copy( st_fx->lsp_old_fx, st_fx->lspCNG_fx, M ); /* Q15 */ - } - - /*-----------------------------------------------------------------* - * Decode residual signal energy - *-----------------------------------------------------------------*/ - - *allow_cn_step = 0; - move16(); - test(); - IF( EQ_32( st_fx->core_brate, SID_1k75 ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) - { - istep = ISTEP_AMR_WB_SID_FX; /* Q15 */ - move16(); - if ( EQ_32( st_fx->core_brate, SID_2k40 ) ) - { - istep = ISTEP_SID_FX; /* Q15 */ - move16(); - } - - /* initialize the energy quantization parameters */ - num_bits = 6; - move16(); - if ( st_fx->Opt_AMR_WB == 0 ) - { - num_bits = 7; - move16(); - } - - /* decode the energy index */ - L_enr_index = get_next_indice_fx( st_fx, num_bits ); - - IF( LE_32( st_fx->last_core_brate, SID_2k40 ) || EQ_16( st_fx->prev_bfi, 1 ) ) - { - tmp1 = add( hTdCngDec->old_enr_index, 20 ); - } - ELSE - { - tmp1 = add( hTdCngDec->old_enr_index, 40 ); - } - IF( GT_16( L_enr_index, tmp1 ) && hTdCngDec->old_enr_index >= 0 ) /* Likely bit error and not startup */ - { - L_enr_index = tmp1; - move16(); - L_enr_index = s_min( L_enr_index, 127 ); /* Q0 */ - IF( st_fx->Opt_AMR_WB ) - { - L_enr_index = s_min( L_enr_index, 63 ); /* Q0 */ - } - } - - test(); - test(); - test(); - IF( GT_32( st_fx->last_core_brate, SID_1k75 ) && - NE_16( st_fx->first_CNG, 0 ) && - GE_16( hTdCngDec->old_enr_index, 0 ) && - GT_16( L_enr_index, add( hTdCngDec->old_enr_index, 1 ) ) ) - { - *allow_cn_step = 1; - move16(); - } - - hTdCngDec->old_enr_index = L_enr_index; - move16(); - if ( !L_enr_index ) - { - L_enr_index = -5; - move16(); - } - /* st_fx->Enew = L_enr_index / step - 2.0f;*/ - L_ener = L_mult( L_enr_index, istep ); /* Q16 (0+15) */ - /* subtract by 2 not done to leave Energy in Q2 */ - - /* extract integral and fractional parts */ - ener_fra = L_Extract_lc( L_ener, &ener_int ); - ener_int = add( ener_int, 4 ); /* Q2 to Q6 */ - - /* find the new energy value */ - hTdCngDec->Enew_fx = Pow2( ener_int, ener_fra ); - move32(); - - IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) - { - burst_ho_cnt = get_next_indice_fx( st_fx, 3 ); /* 3bit */ - - *sid_bw = get_next_indice_fx( st_fx, 1 ); - move16(); - IF( *sid_bw == 0 ) - { - env_idx[0] = get_next_indice_fx( st_fx, 6 ); - move16(); - - /* get quantized res_env_details */ - FOR( i = 0; i < NUM_ENV_CNG; i++ ) - { - q_env[i] = L_deposit_l( CNG_details_codebook_fx[env_idx[0]][i] ); - move32(); - } - } - } - /* Reset CNG history IF CNG frame length is changed */ - test(); - test(); - IF( EQ_16( st_fx->bwidth, WB ) && NE_16( st_fx->first_CNG, 0 ) && NE_16( st_fx->L_frame, st_fx->last_CNG_L_frame ) ) - { - hTdCngDec->ho_hist_size = 0; - move16(); - } - } - - /*---------------------------------------------------------------------* - * CNG spectral envelope update - * Find A(z) coefficients - *---------------------------------------------------------------------*/ - test(); - test(); - test(); - IF( LE_32( st_fx->last_core_brate, SID_2k40 ) ) - { - /* Reset hangover counter if not first SID period */ - if ( GT_32( st_fx->core_brate, FRAME_NO_DATA ) ) - { - hTdCngDec->num_ho = 0; - move16(); - } - /* Update LSPs IF last SID energy not outliers or insufficient number of hangover frames */ - test(); - IF( LT_16( hTdCngDec->num_ho, 3 ) || LT_32( Mult_32_16( hTdCngDec->Enew_fx, 21845 /*1/1.5f, Q15*/ ), st_fx->lp_ener_fx ) ) - { - FOR( i = 0; i < M; i++ ) - { - /* AR low-pass filter */ - st_fx->lspCNG_fx[i] = mac_r( L_mult( CNG_ISF_FACT_FX, st_fx->lspCNG_fx[i] ), 32768 - CNG_ISF_FACT_FX, lsp_new[i] ); - move16(); /* Q15 (15+15+1-16) */ - } - } - } - ELSE - { - /* Update CNG_mode IF allowed */ - test(); - test(); - test(); - IF( ( st_fx->Opt_AMR_WB || EQ_16( st_fx->bwidth, WB ) ) && ( !st_fx->first_CNG || GE_16( hTdCngDec->act_cnt2, MIN_ACT_CNG_UPD ) ) ) - { - IF( GT_32( st_fx->last_active_brate, ACELP_16k40 ) ) - { - st_fx->CNG_mode = -1; - move16(); - } - ELSE - { - st_fx->CNG_mode = get_cng_mode( st_fx->last_active_brate ); - move16(); - } - } - - /* If first sid after active burst update LSF history from circ buffer */ - burst_ho_cnt = s_min( burst_ho_cnt, hTdCngDec->ho_circ_size ); /* MODE1_DTX_IN_CODEC_B_FIX Q0*/ - hTdCngDec->act_cnt = 0; - move16(); - s_ptr = add( sub( hTdCngDec->ho_circ_ptr, burst_ho_cnt ), 1 ); - IF( s_ptr < 0 ) - { - s_ptr = add( s_ptr, hTdCngDec->ho_circ_size ); - } - - FOR( ll = burst_ho_cnt; ll > 0; ll-- ) - { - hTdCngDec->ho_hist_ptr = add( hTdCngDec->ho_hist_ptr, 1 ); /* Q0 */ - move16(); - if ( EQ_16( hTdCngDec->ho_hist_ptr, HO_HIST_SIZE ) ) - { - hTdCngDec->ho_hist_ptr = 0; - move16(); - } - - /* Conversion between 12.8k and 16k LSPs */ - test(); - test(); - test(); - IF( ( EQ_16( st_fx->L_frame, L_FRAME16k ) && hTdCngDec->ho_16k_lsp[s_ptr] == 0 ) || ( EQ_16( st_fx->L_frame, L_FRAME ) && EQ_16( hTdCngDec->ho_16k_lsp[s_ptr], 1 ) ) ) - { - /* Conversion from 16k LPSs to 12k8 */ - lsp_convert_poly_fx( &( hTdCngDec->ho_lsp_circ_fx[s_ptr * M] ), st_fx->L_frame, 0 ); - } - /* update the circular buffers */ - Copy( &( hTdCngDec->ho_lsp_circ_fx[s_ptr * M] ), &( hTdCngDec->ho_lsp_hist_fx[hTdCngDec->ho_hist_ptr * M] ), M ); /* Qx */ - Copy32( &( hTdCngDec->ho_ener_circ_fx[s_ptr] ), &( hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr] ), 1 ); /* Q6 */ - hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); - move32(); - Copy32( &( hTdCngDec->ho_env_circ_fx[s_ptr * NUM_ENV_CNG] ), &( hTdCngDec->ho_env_hist_fx[hTdCngDec->ho_hist_ptr * NUM_ENV_CNG] ), NUM_ENV_CNG ); /* Qx */ - - hTdCngDec->ho_hist_size = add( hTdCngDec->ho_hist_size, 1 ); - move16(); - - if ( GT_16( hTdCngDec->ho_hist_size, HO_HIST_SIZE ) ) - { - hTdCngDec->ho_hist_size = HO_HIST_SIZE; - move16(); - } - - s_ptr = add( s_ptr, 1 ); - if ( EQ_16( s_ptr, hTdCngDec->ho_circ_size ) ) - { - s_ptr = 0; - move16(); - } - } - - IF( hTdCngDec->ho_hist_size > 0 ) /* can be -1 at init MODE1_DTX_IN_CODEC_B_FIX */ - { - /* *allow_cn_step |= ( st_fx->ho_ener_hist[st_fx->ho_hist_ptr] > 4.0f * st_fx->lp_ener );*/ - L_tmp1 = L_shr( hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr], 2 ); - L_tmp1 = L_sub( L_tmp1, st_fx->lp_ener_fx ); + lsf_dec_fx( st_fx, 0, Aq, &LSF_Q_prediction, lsf_new, lsp_new, 0, 0, NULL ); - test(); - test(); - IF( ( L_tmp1 > 0 && ( st_fx->first_CNG || st_fx->element_mode == EVS_MONO ) ) ) - { - *allow_cn_step = s_or( *allow_cn_step, 1 ); - move16(); - } - } - IF( EQ_16( last_element_mode, IVAS_CPE_TD ) ) - { - *allow_cn_step = 1; - move16(); - } - test(); - IF( EQ_16( *allow_cn_step, 0 ) && GT_16( hTdCngDec->ho_hist_size, 0 ) ) - { - /* Use average of energies below last energy */ - ptr = hTdCngDec->ho_hist_ptr; - move16(); - Copy( &( hTdCngDec->ho_lsp_hist_fx[ptr * M] ), tmp, M ); /* Qx */ - m1 = 0; - move16(); - IF( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x1 ) == 0 ) - { - Copy32( &hTdCngDec->ho_env_hist_fx[ptr * NUM_ENV_CNG], tmp_env, NUM_ENV_CNG ); - m1 = 1; - move16(); - } - L_enr = Mult_32_16( hTdCngDec->ho_ener_hist_fx[ptr], W_DTX_HO_FX[0] ); /* Q6+15-15->Q6 */ - - weights = W_DTX_HO_FX[0]; /* Q15 */ - move16(); - - m = 1; - move16(); - FOR( k = 1; k < hTdCngDec->ho_hist_size; k++ ) - { - ptr--; - if ( ptr < 0 ) - { - ptr = HO_HIST_SIZE - 1; - move16(); - } - - test(); - IF( LT_32( Mult_32_16( hTdCngDec->ho_ener_hist_fx[ptr], ONE_OVER_BUF_H_NRG_FX ), hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr] ) && - GT_32( hTdCngDec->ho_ener_hist_fx[ptr], Mult_32_16( hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr], BUF_L_NRG_FX ) ) ) - { - /*enr += W_DTX_HO[k] * st_fx->ho_ener_hist[ptr];*/ - L_tmp1 = Mult_32_16( hTdCngDec->ho_ener_hist_fx[ptr], W_DTX_HO_FX[k] ); /* Q6+15-15->Q6 */ - L_enr = L_add( L_enr, L_tmp1 ); /* Q6 */ - - /*weights += W_DTX_HO[k];*/ - weights = add( weights, W_DTX_HO_FX[k] ); /* Q15 */ - - Copy( &hTdCngDec->ho_lsp_hist_fx[ptr * M], &tmp[m * M], M ); /* Qx */ - IF( EQ_32( L_and( hTdCngDec->ho_sid_bw, L_shl( (Word32) 0x1, k ) ), 0 ) ) - { - Copy32( &hTdCngDec->ho_env_hist_fx[ptr * NUM_ENV_CNG], &tmp_env[m1 * NUM_ENV_CNG], NUM_ENV_CNG ); /* Qx */ - m1++; - } - m++; - } - } - - /*enr /= weights;*/ - exp = norm_s( weights ); - tmp1 = div_s( shl( 1, sub( 14, exp ) ), weights ); /* Q(15+14-exp-15) */ - L_tmp1 = Mult_32_16( L_enr, tmp1 ); /* Q(14-exp+6-15)->Q(5-exp) */ - L_enr = L_shl( L_tmp1, add( exp, 1 ) ); /* Q6 */ - - st_fx->lp_ener_fx = L_enr; /* Q6 */ - move32(); - set32_fx( max_val, 0, 2 ); - set16_fx( max_idx, 0, 2 ); - - FOR( i = 0; i < m; i++ ) - { - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_FX ); - ftmp_fx = 964; - move16(); /*X2.56 */ - tmpv = sub( 16384, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56*/ - L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536*/ - } - ELSE - { - lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_16k_FX ); - ftmp_fx = 1205; - move16(); /*QX2.56*/ - tmpv = sub( 20480, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56*/ - L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536*/ - } - - tmpv = sub( lsf_tmp[0], ftmp_fx ); /*QX2.56*/ - L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /*QX6.5536*/ - FOR( j = 0; j < M - 1; j++ ) - { - tmpv = sub( sub( lsf_tmp[j + 1], lsf_tmp[j] ), ftmp_fx ); /*QX2.56*/ - L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /*QX6.5536*/ - } - - C[i] = Mpy_32_16_1( L_tmp, 1928 ); /*QX6.5536*/ - move32(); - - IF( GT_32( C[i], max_val[0] ) ) - { - max_val[1] = max_val[0]; - move32(); - max_idx[1] = max_idx[0]; - move16(); - max_val[0] = C[i]; - move32(); - max_idx[0] = i; - move16(); - } - ELSE IF( GT_32( C[i], max_val[1] ) ) - { - max_val[1] = C[i]; - move32(); - max_idx[1] = i; - move16(); - } - } - - IF( EQ_16( m, 1 ) ) - { - Copy( tmp, lsp_tmp, M ); /* Qx */ - } - ELSE IF( LT_16( m, 4 ) ) - { - FOR( i = 0; i < M; i++ ) - { - L_tmp1 = 0; - move32(); - FOR( j = 0; j < m; j++ ) - { - L_tmp1 = L_add( L_tmp1, L_deposit_l( tmp[j * M + i] ) ); - } - - L_tmp1 = L_sub( L_tmp1, L_deposit_l( tmp[max_idx[0] * M + i] ) ); - tmpv = div_s( 1, sub( m, 1 ) ); /*Q15*/ - L_tmp1 = Mpy_32_16_1( L_tmp1, tmpv ); /*Q15*/ - lsp_tmp[i] = extract_l( L_tmp1 ); /*Q15*/ - move16(); - } - } - ELSE - { - FOR( i = 0; i < M; i++ ) - { - L_tmp1 = 0; - move32(); - FOR( j = 0; j < m; j++ ) - { - L_tmp1 = L_add( L_tmp1, L_deposit_l( tmp[j * M + i] ) ); - } - - L_tmp1 = L_sub( L_tmp1, L_add( L_deposit_l( tmp[max_idx[0] * M + i] ), L_deposit_l( tmp[max_idx[1] * M + i] ) ) ); /*Q15*/ - tmpv = div_s( 1, sub( m, 2 ) ); /*Q15*/ - L_tmp1 = Mpy_32_16_1( L_tmp1, tmpv ); /*Q15*/ - lsp_tmp[i] = extract_l( L_tmp1 ); /*Q15*/ - move16(); - } - } - - dist = 0; - move16(); /*Q15*/ - max_dev = 0; - move16(); /*Q15*/ - FOR( i = 0; i < M; i++ ) - { - dev = abs_s( sub( lsp_tmp[i], lsp_new[i] ) ); /*Q15*/ - dist = add_o( dist, dev, &Overflow ); /*Q15*/ - if ( GT_16( dev, max_dev ) ) - { - max_dev = dev; - move16(); - } - } - - test(); - IF( GT_16( dist, 13107 ) || GT_16( max_dev, 3277 ) ) /* 0.4 and 0.1 in Q15 */ - { - FOR( i = 0; i < M; i++ ) - { - st_fx->lspCNG_fx[i] = lsp_tmp[i]; - move16(); /*Q15*/ - } - } - ELSE - { - FOR( i = 0; i < M; i++ ) - { - /* AR low-pass filter */ - st_fx->lspCNG_fx[i] = add( mult_r( 26214, lsp_tmp[i] ), mult_r( 6554, lsp_new[i] ) ); /* Q15 */ - move16(); - } - } - IF( m1 > 0 ) - { - FOR( i = 0; i < NUM_ENV_CNG; i++ ) - { - L_tmp = L_deposit_l( 0 ); - FOR( j = 0; j < m1; j++ ) - { - /* env[i] += tmp_env[j*NUM_ENV_CNG+i];*/ - L_tmp = L_add_sat( L_tmp, tmp_env[j * NUM_ENV_CNG + i] ); - } - /* env[i] /= (float)m1; */ - /* env[i] = env[i] - 2*st_fx->lp_ener_fx; */ - IF( EQ_16( m1, 1 ) ) - { - L_tmp = L_sub_sat( L_tmp, L_add_sat( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); /* Q6 */ - } - ELSE - { - tmp1 = div_s( 1, m1 ); - L_tmp = Mult_32_16( L_tmp, tmp1 ); /* Q6 */ - L_tmp = L_sub_sat( L_tmp, L_add_sat( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); /* Q6 */ - } - env[i] = L_tmp; /* Q6 */ - move32(); - } - - Copy32( env, hTdCngDec->lp_env_fx, NUM_ENV_CNG ); /* Q6 */ - } - } - ELSE - { - Copy( lsp_new, st_fx->lspCNG_fx, M ); /* use newly analyzed ISFs */ /* Q15 */ - } - } - - test(); - IF( EQ_32( st_fx->core_brate, SID_1k75 ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) - { - /* Update hangover memory during CNG */ - test(); - IF( ( *allow_cn_step == 0 ) && LT_32( hTdCngDec->Enew_fx, L_add_sat( st_fx->lp_ener_fx, L_shr( st_fx->lp_ener_fx, 1 ) ) ) ) - { - /* update the pointer to circular buffer of old LSP vectors */ - hTdCngDec->ho_hist_ptr++; - move16(); - if ( EQ_16( hTdCngDec->ho_hist_ptr, HO_HIST_SIZE ) ) - { - hTdCngDec->ho_hist_ptr = 0; - move16(); - } - - /* update the circular buffer of old LSP vectors with the new LSP vector */ - Copy( lsp_new, &( hTdCngDec->ho_lsp_hist_fx[( hTdCngDec->ho_hist_ptr ) * M] ), M ); /* Q15 */ - - /* update the hangover energy buffer */ - hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr] = hTdCngDec->Enew_fx; /* Q6 */ - move32(); - test(); - IF( EQ_32( st_fx->core_brate, SID_2k40 ) && ( *sid_bw == 0 ) ) - { - /* enr1 = (float)log10( st->Enew*L_frame + 0.1f ) / (float)log10( 2.0f );*/ - exp = norm_l( hTdCngDec->Enew_fx ); - L_tmp = L_shl( hTdCngDec->Enew_fx, exp ); /*Q(exp+6)*/ - L_tmp = Mult_32_16( L_tmp, shl( st_fx->L_frame, 5 ) ); /*Q(exp+6+5-15=exp-4)*/ - L_tmp = L_shr_sat( L_tmp, sub( exp, 10 ) ); /*Q6*/ - exp = norm_l( L_tmp ); - fra = Log2_norm_lc( L_shl( L_tmp, exp ) ); - exp = sub( sub( 30, exp ), 6 ); - L_tmp = L_Comp( exp, fra ); - enr1 = L_shr( L_tmp, 10 ); /* Q6 */ - - FOR( i = 0; i < NUM_ENV_CNG; i++ ) - { - /* get quantized envelope */ - /* env[i] = pow(2.0f,(enr1 - q_env[i])) + 2*st->Enew;*/ - L_tmp = L_sub( enr1, q_env[i] ); /* Q6 */ - L_tmp = L_shl( L_tmp, 10 ); /* 16 */ - temp_lo_fx = L_Extract_lc( L_tmp, &temp_hi_fx ); - - exp_pow = sub( 14, temp_hi_fx ); - L_tmp = Pow2( 14, temp_lo_fx ); /* Qexp_pow */ - env[i] = L_shl( L_tmp, sub( 6, exp_pow ) ); /* Q6 */ - move32(); - L_tmp = L_add( hTdCngDec->Enew_fx, hTdCngDec->Enew_fx ); - env[i] = L_add( env[i], L_tmp ); /* Q6 */ - move32(); - } - hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); /* Q0 */ - move32(); - Copy32( env, &( hTdCngDec->ho_env_hist_fx[hTdCngDec->ho_hist_ptr * NUM_ENV_CNG] ), NUM_ENV_CNG ); /* Q6 */ - } - ELSE IF( ( *sid_bw != 0 ) ) - { - hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); /* Q0 */ - move32(); - hTdCngDec->ho_sid_bw = L_or( hTdCngDec->ho_sid_bw, 0x1L ); /* Q0 */ - move32(); - } - - hTdCngDec->ho_hist_size = add( hTdCngDec->ho_hist_size, 1 ); - move16(); - if ( GT_16( hTdCngDec->ho_hist_size, HO_HIST_SIZE ) ) - { - hTdCngDec->ho_hist_size = HO_HIST_SIZE; - move16(); - } - } - /* Update the frame length memory */ - st_fx->last_CNG_L_frame = st_fx->L_frame; - move16(); - - if ( NE_32( st_fx->core_brate, SID_1k75 ) ) - { - hTdCngDec->num_ho = m; - move16(); - } - } - - IF( st_fx->element_mode == EVS_MONO ) - { - st_fx->last_CNG_L_frame = st_fx->L_frame; - move16(); - - IF( NE_32( st_fx->core_brate, SID_1k75 ) ) - { - hTdCngDec->num_ho = m; - move16(); - } - } - IF( st_fx->Opt_AMR_WB ) - { - E_LPC_f_isp_a_conversion( st_fx->lspCNG_fx, Aq, M ); - } - ELSE - { - E_LPC_f_lsp_a_conversion( st_fx->lspCNG_fx, Aq, M ); - } - - tmp_loop = shr( st_fx->L_frame, 6 ); - FOR( i = 1; i < tmp_loop; i++ ) /* L_frame/L_SUBFR */ - { - Copy( Aq, &Aq[i * ( M + 1 )], add( M, 1 ) ); /* Q12 */ - } - - return; -} -#endif -void CNG_dec_ivas_fx( - Decoder_State *st_fx, /* i/o: State structure */ - const Word16 last_element_mode, /* i : last element mode Q0 */ - Word16 Aq[], /* o : LP coefficients Q12 */ - Word16 *lsp_new, /* i/o: current frame LSPs Q15 */ - Word16 *lsf_new, /* i/o: current frame LSFs Qlog2(2.56) */ - Word16 *allow_cn_step, /* o : allow CN step Q0 */ - Word16 *sid_bw /* i : 0-NB/WB, 1-SWB SID Q0 */ - , - Word32 *q_env ) -{ - Word16 istep; - Word16 i, L_enr_index; - Word32 L_ener; - Word16 ener_fra, ener_int; - Word16 num_bits; - Word16 weights, ptr, j, k; - Word16 m1; - Word16 m = 0; - move16(); - Word16 tmp[HO_HIST_SIZE * M]; - Word16 burst_ho_cnt = 0; - move16(); - Word16 ll, s_ptr; - Word32 L_enr, L_tmp1; - Word16 tmp1, exp; - Word16 lsf_tmp[M]; - Word32 C[M]; - Word32 max_val[2]; - Word16 max_idx[2]; - Word16 ftmp_fx; - Word16 lsp_tmp[M]; - Word16 dev; - Word16 max_dev; - Word16 dist; - Word16 tmpv; - Word16 env_idx[2]; - Word32 enr1; - Word32 env[NUM_ENV_CNG]; - Word32 tmp_env[HO_HIST_SIZE * NUM_ENV_CNG]; - Word32 L_tmp; - Word16 fra; - Word16 temp_lo_fx, temp_hi_fx; - Word16 exp_pow; - Word16 tmp_loop; - Word16 enr_new, Aq_tmp[M + 1]; - - Word16 LSF_Q_prediction; /* o : LSF prediction mode - just temporary variable in CNG */ - TD_CNG_DEC_HANDLE hTdCngDec; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; - move32(); -#endif - hTdCngDec = st_fx->hTdCngDec; - - m = 0; - move16(); - /*-----------------------------------------------------------------* - * Decode CNG spectral envelope (only in SID frame) - *-----------------------------------------------------------------*/ - test(); - IF( EQ_32( st_fx->core_brate, SID_1k75 ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) - { - /* de-quantize the LSF vector */ - IF( st_fx->Opt_AMR_WB != 0 ) - { - /* Flt function */ - isf_dec_amr_wb_fx( st_fx, Aq, lsf_new, lsp_new ); - /* check IF ISPs may trigger too much synthesis energy */ - - E_LPC_f_isp_a_conversion( lsp_new, Aq_tmp, M ); - enr_new = Enr_1_Az_fx( Aq_tmp, 2 * L_SUBFR ); - - IF( ( shr( enr_new, 14 ) > 0 ) ) - { - /* Use old LSP vector */ - Copy( st_fx->lsp_old_fx, lsp_new, M ); /* Q15 */ - Copy( st_fx->lsf_old_fx, lsf_new, M ); /* Q2.56 */ - } - } - ELSE - { - lsf_dec_ivas_fx( st_fx, 0, Aq, &LSF_Q_prediction, lsf_new, lsp_new, 0, 0, - NULL ); /* check IF LSPs may trigger too much synthesis energy */ - E_LPC_f_lsp_a_conversion( lsp_new, Aq_tmp, M ); enr_new = Enr_1_Az_fx( Aq_tmp, 2 * L_SUBFR ); diff --git a/lib_dec/dec_LPD_fx.c b/lib_dec/dec_LPD_fx.c index f53234ded..d95359665 100644 --- a/lib_dec/dec_LPD_fx.c +++ b/lib_dec/dec_LPD_fx.c @@ -556,11 +556,7 @@ void decoder_LPD_fx( move16(); } -#ifdef REMOVE_EVS_DUPLICATES int_lsp4_ivas_fx( L_frame, &lsp[0], lspmid, &lsp[M], Aq, M, st->relax_prev_lsf_interp ); -#else - int_lsp4_fx( L_frame, &lsp[0], lspmid, &lsp[M], Aq, M, st->relax_prev_lsf_interp ); -#endif } ELSE { diff --git a/lib_dec/dec_ace_fx.c b/lib_dec/dec_ace_fx.c index 16f749156..9c366e3f3 100644 --- a/lib_dec/dec_ace_fx.c +++ b/lib_dec/dec_ace_fx.c @@ -532,35 +532,24 @@ void decoder_acelp_fx( move16(); IF( st->igf != 0 ) { -#ifdef REMOVE_EVS_DUPLICATES - prep_tbe_exc_ivas_fx( st->L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, st->voice_fac, &voice_factors[idx], bwe_exc, - gain_preQ, code_preQ, st->Q_exc, T0, T0_frac, st->coder_type, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, 0 ); -#else - prep_tbe_exc_fx( st->L_frame, -#ifdef ADD_IVAS_TBE_CODE - L_SUBFR, -#endif - i_subfr, gain_pit, gain_code, code, st->voice_fac, &voice_factors[idx], bwe_exc, - gain_preQ, code_preQ, st->Q_exc, T0, T0_frac, st->coder_type, st->core_brate -#ifdef ADD_IVAS_TBE_CODE - , - st->element_mode, st->idchan, st->hBWE_TD != NULL, 0 -#endif - ); -#endif + prep_tbe_exc_fx( st->L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, st->voice_fac, &voice_factors[idx], bwe_exc, + gain_preQ, code_preQ, st->Q_exc, T0, T0_frac, st->coder_type, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, 0 ); } /*---------------------------------------------------------* * Enhance the excitation * *---------------------------------------------------------*/ + E_UTIL_enhancer( st->voice_fac, stab_fac, st->past_gcode, gain_inov, &( st->gc_threshold_fx ), code, &exc2[i_subfr], gain_pit, &st->dm_fx.prev_gain_code, st->dm_fx.prev_gain_pit, &st->dm_fx.prev_state, st->coder_type, acelp_cfg.fixed_cdk_index[idx], L_SUBFR, st->L_frame, st->Q_exc ); } /* !RF_NELP frame partial copy */ + /*----------------------------------------------------------* * - compute the synthesis speech * *----------------------------------------------------------*/ + rescale_mem( &st->Q_exc, &prev_Q_syn, &st->Q_syn, mem_syn, syn, M, i_subfr ); E_UTIL_synthesis( sub( st->Q_exc, st->Q_syn ), p_A, &exc2[i_subfr], &syn[i_subfr], L_SUBFR, mem_syn, 1, M ); @@ -686,16 +675,11 @@ void decoder_acelp_fx( move16(); } -#ifdef REMOVE_EVS_DUPLICATES - FEC_scale_syn_ivas_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, syn, pBuf_scaleSyn, st->enr_old_fx, 0, - st->coder_type, LSF_Q_prediction, &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, - exc, exc2, A, &( st->old_enr_LP ), mem_back, mem_syn, st->Q_exc, st->Q_syn, EVS_MONO, avoid_lpc_burst_on_recovery, force_scale_syn ); -#else FEC_scale_syn_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, syn, pBuf_scaleSyn, st->enr_old_fx, 0, st->coder_type, LSF_Q_prediction, &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, - exc, exc2, A, &( st->old_enr_LP ), mem_back, mem_syn, st->Q_exc, st->Q_syn, avoid_lpc_burst_on_recovery, force_scale_syn ); -#endif + exc, exc2, A, &( st->old_enr_LP ), mem_back, mem_syn, st->Q_exc, st->Q_syn, EVS_MONO, avoid_lpc_burst_on_recovery, force_scale_syn ); } + /* update ACELP synthesis memory */ Copy( mem_syn, st->mem_syn2_fx, M ); Copy( syn + st->L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM ); diff --git a/lib_dec/dec_amr_wb_fx.c b/lib_dec/dec_amr_wb_fx.c index b03b6d69c..500fe34ba 100644 --- a/lib_dec/dec_amr_wb_fx.c +++ b/lib_dec/dec_amr_wb_fx.c @@ -71,11 +71,7 @@ void decod_amr_wb_fx( * Decode pitch lag *----------------------------------------------------------------------*/ -#ifdef REMOVE_EVS_DUPLICATES - *pt_pitch_fx = pit_decode_ivas_fx( st_fx, st_fx->core_brate, 1, L_FRAME, i_subfr, -1, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_SUBFR, 0, NULL ); -#else - *pt_pitch_fx = pit_decode_fx( st_fx, st_fx->core_brate, 1, L_FRAME, i_subfr, -1, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_SUBFR ); -#endif + *pt_pitch_fx = pit_decode_fx( st_fx, st_fx->core_brate, 1, L_FRAME, i_subfr, -1, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_SUBFR, 0, NULL ); /*--------------------------------------------------------------* * Find the adaptive codebook vector diff --git a/lib_dec/dec_gen_voic_fx.c b/lib_dec/dec_gen_voic_fx.c index 7411d59f2..3e42d9535 100644 --- a/lib_dec/dec_gen_voic_fx.c +++ b/lib_dec/dec_gen_voic_fx.c @@ -18,8 +18,7 @@ /*----------------------------------------------------------------------*/ /* GLOBAL INPUT ARGUMENTS : */ /* _ (Struct) st_fx : decoder static memory */ -/* _ (Word16) L_frame : length of the frame */ - +/* _ (Word16) L_frame : length of the frame */ /* _ (Word16[]) Aq_fx : LP filter coefficient Q12 */ /* _ (Word16) Es_pred_fx : predicted scaled innov. energy Q8 */ /* _ (Word16[]) pitch_buf_fx : floating pitch values for each subframe Q6*/ @@ -29,503 +28,30 @@ /* _ (Word16[]) exc_fx : adapt. excitation exc (Q_exc) */ /* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q_exc) */ /*----------------------------------------------------------------------*/ - - /*----------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ /* _ None */ /*======================================================================*/ -#ifndef REMOVE_EVS_DUPLICATES ivas_error decod_gen_voic_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 sharpFlag_fx, /* i : formant sharpening flag */ - const Word16 *Aq_fx, /* i : LP filter coefficient Q12 */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy Q8 */ - const Word16 do_WI_fx, /* i : do interpolation after a FER */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6 */ - Word16 *voice_factors_fx, /* o : voicing factors Q15 */ - Word16 *exc_fx, /* i/o: adapt. excitation exc Q_exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc Q_exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_exc */ - Word16 *unbits, /* number of unused bits */ - Word16 *gain_buf /*Q14*/ -) -{ - - - Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx; /* integer pitch variables */ - Word16 gain_pit_fx = 0; /* pitch gain Q14 */ - move16(); - Word32 gain_code_fx = 0; /* gain/normalized gain of the algebraic excitation Q16 */ - move32(); - Word32 norm_gain_code_fx = 0; /* normalized gain of the algebraic excitation Q16 */ - move32(); - Word16 gain_inov_fx = 0; /* Innovation gain Q12 */ - move16(); - Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ - Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */ - Word16 voice_fac_fx; /* voicing factor Q15 */ - Word16 code_fx[L_SUBFR]; /* algebraic codevector Q12 */ - - const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12 */ - Word16 *pt_pitch_fx; /* pointer to floating pitch Q6 */ - Word16 i_subfr_fx, i; /* tmp variables */ - Word16 error_fx = 0; - move16(); - Word16 gain_preQ_fx = 0; /* Gain of prequantizer excitation */ - move16(); - Word16 code_preQ_fx[L_SUBFR]; /* Prequantizer excitation */ - Word32 norm_gain_preQ_fx; - Word16 pitch_limit_flag_fx; - - Word16 tmp1_fx, gain_code16; - Word32 L_tmp_GC; - Word32 L_tmp; - - Word16 harm_flag_acelp; - - Word16 shft_prev, ph_offset_fx; - Word32 prev_res_nrg; - Word32 prev_spch_nrg; - Word32 curr_res_nrg; - Word32 curr_spch_nrg; - Word16 rint_bfi_pitch, rint_pitch; - Word16 fraca, fracb, expa, expb, scale, exp1; - Word16 *p_exc; - Word16 mem_tmp_fx[M]; - Word16 syn_tmp_fx[L_FRAME16k]; - Word16 shft_curr; - Word16 *p_syn; - Word16 sp_enratio, Qsp_enratio; - Word16 enratio, Qenratio; - DTFS_STRUCTURE *PREVP, *CURRP; - Word16 S_fx[PIT_MAX * 4 + 1], C_fx[PIT_MAX * 4 + 1]; - Word16 dummy2[2]; - Word16 out_fx[L_FRAME16k]; - - Word16 pf_temp1[MAXLAG_WI]; /*may not need more than MAXLAG_WI/2+1 */ - Word16 pf_temp2[MAXLAG_WI]; - Word16 pf_temp[MAXLAG_WI]; - Word16 pf_n2[MAXLAG_WI]; - MUSIC_POSTFILT_HANDLE hMusicPF; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; - move32(); -#endif - - hMusicPF = st_fx->hMusicPF; - - GSC_DEC_HANDLE hGSCDec; - hGSCDec = st_fx->hGSCDec; - ivas_error error; - - error = IVAS_ERR_OK; - move32(); - - T0_fx = PIT_MIN; - move16(); - T0_frac_fx = 0; - move16(); - - /* read harmonicity flag */ - harm_flag_acelp = 0; - move16(); - test(); - test(); - IF( ( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) ) && EQ_16( st_fx->coder_type, GENERIC ) ) - { - harm_flag_acelp = (Word16) get_next_indice( st_fx, 1 ); - } - - /*------------------------------------------------------------------* - * ACELP subframe loop - *------------------------------------------------------------------*/ - - p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */ - pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */ - norm_gain_preQ_fx = 0; - move32(); - gain_preQ_fx = 0; - move16(); - set16_fx( code_preQ_fx, 0, L_SUBFR ); - - FOR( i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR ) - { - /*----------------------------------------------------------------------* - * Decode pitch lag - *----------------------------------------------------------------------*/ - - *pt_pitch_fx = pit_decode_fx( st_fx, st_fx->core_brate, 0, L_frame, i_subfr_fx, st_fx->coder_type, &pitch_limit_flag_fx, - &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_SUBFR ); - move16(); /*Q6*/ - - /*--------------------------------------------------------------* - * Find the adaptive codebook vector - *--------------------------------------------------------------*/ - - pred_lt4( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); - - tbe_celp_exc( L_frame, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx ); - - /*--------------------------------------------------------------* - * LP filtering of the adaptive excitation - *--------------------------------------------------------------*/ - lp_filt_exc_dec_fx( st_fx, MODE1, i_subfr_fx, L_SUBFR, L_frame, st_fx->acelp_cfg.ltf_mode, exc_fx ); - /*-----------------------------------------------------------------* - * Transform-domain contribution decoding (active frames) - *-----------------------------------------------------------------*/ - - test(); - IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && ( st_fx->coder_type != INACTIVE ) ) - { - gain_code_fx = 0; - move16(); - transf_cdbk_dec_fx( st_fx, harm_flag_acelp, i_subfr_fx, Es_pred_fx, gain_code_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits ); - } - - /*--------------------------------------------------------------* - * Innovation decoding - *--------------------------------------------------------------*/ - - inov_decode_fx( st_fx, st_fx->core_brate, 0, L_frame, sharpFlag_fx, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_SUBFR ); - - /*--------------------------------------------------------------* - * Gain decoding - * Estimate spectrum tilt and voicing - *--------------------------------------------------------------*/ - - IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) - { - gain_dec_lbr_fx( st_fx, st_fx->coder_type, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_SUBFR ); - } - ELSE IF( GT_32( st_fx->core_brate, ACELP_32k ) ) - { - gain_dec_SQ_fx( st_fx, i_subfr_fx, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); - } - ELSE - { - gain_dec_mless_fx( st_fx, L_frame, st_fx->coder_type, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); - } - st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc ); // Q15 - move16(); - - /*-----------------------------------------------------------------* - * Transform domain contribution decoding - *-----------------------------------------------------------------*/ - test(); - IF( GE_32( st_fx->core_brate, MAX_GSC_INACTIVE_BRATE ) && ( st_fx->coder_type == INACTIVE ) ) - { - transf_cdbk_dec_fx( st_fx, harm_flag_acelp, i_subfr_fx, Es_pred_fx, gain_code_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits ); - } - - /* update LP filtered gains for the case of frame erasures */ - lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame ); - - /*----------------------------------------------------------------------* - * Find the total excitation - *----------------------------------------------------------------------*/ - - IF( EQ_16( L_frame, L_FRAME ) ) /* Rescaling for 12.8k core */ - { - Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC], hGSCDec->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type ); - } - ELSE /* Rescaling for 16k core */ - { - - L_tmp_GC = L_max( gain_code_fx, L_shl( gain_preQ_fx, 16 ) ); /* Chose the maximum of gain_code or the prequantizer excitation x4 to keep some room*/ - Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * 2], hGSCDec->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR * 2, L_tmp_GC, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type ); - } - - gain_code16 = round_fx( L_shl( gain_code_fx, st_fx->Q_exc ) ); /*Q_exc*/ - - /*-----------------------------------------------------------------* - * Add the ACELP pre-quantizer contribution - *-----------------------------------------------------------------*/ - - IF( gain_preQ_fx != 0 ) - { - IF( st_fx->element_mode == EVS_MONO ) - { - tmp1_fx = add( 15 - Q_AVQ_OUT_DEC - 2, st_fx->Q_exc ); - } - ELSE - { - tmp1_fx = add( 15 - Q_AVQ_OUT - 2, st_fx->Q_exc ); - } - FOR( i = 0; i < L_SUBFR; i++ ) - { - Word32 Ltmp1; - /* Contribution from AVQ layer */ - Ltmp1 = L_mult( gain_preQ_fx, code_preQ_fx[i] ); /* Q2 + Q6 -> Q9*/ - Ltmp1 = L_shl_sat( Ltmp1, tmp1_fx ); /* Q16 + Q_exc */ - - /* Compute exc2 */ - L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); // Q_exc+Q14+1+1 - exc2_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); // Q_exc - move16(); - /* gain_pit in Q14 */ - L_tmp = L_mult( gain_code16, code_fx[i] ); // Q_exc+Q9+1 - L_tmp = L_shl_sat( L_tmp, 5 ); // Q_exc+Q9+1+5 - L_tmp = L_mac_sat( L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); // Q_exc+Q15 +1 - L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here */ - - exc_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); // Q_exc - move16(); - } - } - ELSE - { - Acelp_dec_total_exc( exc_fx, exc2_fx, gain_code16, gain_pit_fx, i_subfr_fx, code_fx, L_SUBFR ); - } - - /*-----------------------------------------------------------------* - * Prepare TBE excitation - *-----------------------------------------------------------------*/ - - Word16 idx = 0; - move16(); - IF( i_subfr_fx != 0 ) - { - idx = idiv1616( i_subfr_fx, L_SUBFR ); - } - - prep_tbe_exc_fx( L_frame, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, - &voice_factors_fx[idx], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, - st_fx->Q_exc, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate ); - - - /*----------------------------------------------------------------* - * Excitation enhancements (update of total excitation signal) - *----------------------------------------------------------------*/ - - test(); - IF( GT_32( st_fx->core_brate, ACELP_32k ) || ( st_fx->coder_type == INACTIVE ) ) - { - Copy( exc_fx + i_subfr_fx, exc2_fx + i_subfr_fx, L_SUBFR ); - } - ELSE - { - enhancer_fx( st_fx->core_brate, 0, st_fx->coder_type, i_subfr_fx, L_frame, voice_fac_fx, st_fx->stab_fac_fx, - norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &( st_fx->dm_fx ), st_fx->Q_exc ); - } - - p_Aq_fx += ( M + 1 ); - pt_pitch_fx++; - gain_buf[idx] = gain_pit_fx; // Q14 - move16(); - } - - /* FEC fast recovery */ - - IF( do_WI_fx ) - { - /* shft_prev = L_EXC_MEM - rint_new_fx(st_fx->bfi_pitch_fx);*/ - L_tmp = L_shl( L_deposit_l( st_fx->bfi_pitch_fx ), 10 ); /*Q16*/ - rint_bfi_pitch = rint_new_fx( L_tmp ); /*Q0*/ - shft_prev = sub( L_EXC_MEM, rint_bfi_pitch ); /*Q0*/ - - p_exc = st_fx->hWIDec->old_exc2_fx + shft_prev; - p_syn = st_fx->hWIDec->old_syn2_fx + shft_prev; - move16(); - move16(); - - prev_res_nrg = L_deposit_l( 1 ); - prev_spch_nrg = L_deposit_l( 1 ); - FOR( i = 0; i < rint_bfi_pitch; i++ ) - { - prev_res_nrg = L_mac0_sat( prev_res_nrg, *p_exc, *p_exc ); /* 2*st_fx->prev_Q_exc_fr */ - prev_spch_nrg = L_mac0_sat( prev_spch_nrg, *p_syn, *p_syn ); /* 2*st_fx->prev_Q_syn_fr */ - p_exc++; - p_syn++; - } - - Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); - - syn_12k8_fx( st_fx->L_frame, Aq_fx, exc2_fx, syn_tmp_fx, mem_tmp_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); - - L_tmp = L_shl( L_deposit_l( pitch_buf_fx[NB_SUBFR16k - 1] ), 10 ); /*Q16*/ - rint_pitch = rint_new_fx( L_tmp ); /*Q0*/ - shft_curr = sub( st_fx->L_frame, rint_pitch ); /*Q0*/ - - p_exc = exc2_fx + shft_curr; - p_syn = syn_tmp_fx + shft_curr; - - curr_res_nrg = L_deposit_l( 1 ); - curr_spch_nrg = L_deposit_l( 1 ); - FOR( i = 0; i < rint_pitch; i++ ) - { - curr_res_nrg = L_mac0_sat( curr_res_nrg, *p_exc, *p_exc ); /* 2*st_fx->Q_exc */ - curr_spch_nrg = L_mac0_sat( curr_spch_nrg, *p_syn, *p_syn ); /* 2*st_fx->Q_syn */ - p_exc++; - p_syn++; - } - - /* enratio = (curr_res_nrg / prev_res_nrg); */ - IF( prev_res_nrg > 0 ) - { - expa = norm_l( prev_res_nrg ); - fraca = extract_h( L_shl( prev_res_nrg, expa ) ); /* 2*st_fx->prev_Q_exc_fr -16+expa +1*/ - expa = sub( 30, add( expa, ( shl( st_fx->prev_Q_exc_fr, 1 ) ) ) ); - - expb = norm_l( curr_res_nrg ); - fracb = round_fx_sat( L_shl_sat( curr_res_nrg, expb ) ); /* 2*st_fx->Q_exc +expb+1 -16*/ - expb = sub( 30, add( expb, shl( st_fx->Q_exc, 1 ) ) ); - - scale = shr( sub( fraca, fracb ), 15 ); - fracb = shl( fracb, scale ); // Q(15-expb)+scale - expb = sub( expb, scale ); - - enratio = div_s( fracb, fraca ); // Q(15-(expb-expa)) - exp1 = sub( expb, expa ); - Qenratio = sub( 15, exp1 ); - } - ELSE - { - enratio = 0; - move16(); - Qenratio = 0; - move16(); - } - - /* sp_enratio = curr_spch_nrg/prev_spch_nrg */ - IF( prev_spch_nrg > 0 ) - { - expa = norm_l( prev_spch_nrg ); - fraca = extract_h( L_shl( prev_spch_nrg, expa ) ); /* 2*st_fx->prev_Q_syn_fr +expa+1-16*/ - expa = sub( 30, add( expa, shl( st_fx->prev_Q_syn_fr, 1 ) ) ); - - expb = norm_l( curr_spch_nrg ); - fracb = round_fx_sat( L_shl_sat( curr_spch_nrg, expb ) ); /* 2*st_fx->Q_syn +expb-16 */ - expb = sub( 30, add( expb, shl( st_fx->Q_syn, 1 ) ) ); - - scale = shr( sub( fraca, fracb ), 15 ); - fracb = shl( fracb, scale ); // Q(15-expb) +scale - expb = sub( expb, scale ); - - sp_enratio = div_s( fracb, fraca ); // Q(15-(expb-expa)) - exp1 = sub( expb, expa ); - Qsp_enratio = sub( 15, exp1 ); - } - ELSE - { - sp_enratio = 0; - move16(); - Qsp_enratio = 0; - move16(); - } - - test(); - test(); - test(); - test(); - IF( GT_16( shl_ro( enratio, sub( 15, Qenratio ), &Overflow ), 8192 ) && /*compare with 0.25 in Q15*/ - LT_16( shl_ro( enratio, sub( 10, Qenratio ), &Overflow ), 15360 ) && /*compare with 15.0 in Q10*/ - GT_16( shl_ro( sp_enratio, sub( 15, Qsp_enratio ), &Overflow ), 4915 ) && /*compare with 0.15 in Q15*/ - LT_16( st_fx->bfi_pitch_fx, 9600 ) && /*Q6*/ - LT_16( pitch_buf_fx[NB_SUBFR16k - 1], 9600 ) ) /*Q6*/ - { - IF( NE_32( ( error = DTFS_new_fx( &PREVP ) ), IVAS_ERR_OK ) ) - { - return error; - } - - IF( NE_32( ( error = DTFS_new_fx( &CURRP ) ), IVAS_ERR_OK ) ) - { - return error; - } - - GetSinCosTab_fx( rint_bfi_pitch, S_fx, C_fx ); - DTFS_to_fs_fx( st_fx->hWIDec->old_exc2_fx + shft_prev, rint_bfi_pitch, PREVP, (Word16) st_fx->output_Fs, do_WI_fx, S_fx, C_fx ); - PREVP->Q = add( PREVP->Q, st_fx->prev_Q_exc_fr ); - move16(); - - GetSinCosTab_fx( rint_pitch, S_fx, C_fx ); - DTFS_to_fs_fx( exc2_fx + shft_curr, rint_pitch, CURRP, (Word16) st_fx->output_Fs, do_WI_fx, S_fx, C_fx ); - CURRP->Q = add( CURRP->Q, st_fx->Q_exc ); - move16(); - - ph_offset_fx = 0; - move16(); - IF( NE_32( ( error = WIsyn_fx( *PREVP, CURRP, dummy2, &( ph_offset_fx ), out_fx, (Word16) st_fx->L_frame, 1, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2 ) ), IVAS_ERR_OK ) ) - { - return error; - } - - - Copy_Scale_sig( out_fx, exc2_fx, st_fx->L_frame, st_fx->Q_exc ); // Q_exc - Copy_Scale_sig( out_fx, exc_fx, st_fx->L_frame, st_fx->Q_exc ); // Q_exc - - /* update bwe_exc for SWB-TBE */ - FOR( i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR ) - { - interp_code_4over2_fx( exc_fx + i_subfr_fx, bwe_exc_fx + shl( i_subfr_fx, 1 ), L_SUBFR ); - } - - free( PREVP ); - free( CURRP ); - } - } - - /* SC-VBR */ - st_fx->prev_gain_pit_dec_fx = gain_pit_fx; - move16(); /*Q14*/ - st_fx->prev_tilt_code_dec_fx = st_fx->tilt_code_fx; - move16(); /*Q15*/ - - return error; -} - -/*======================================================================*/ -/* FUNCTION : decod_gen_voic_ivas_fx() */ -/*----------------------------------------------------------------------*/ -/* PURPOSE : Decode generic (GC), voiced (VC) and AMR-WB IO frames */ -/* */ -/*----------------------------------------------------------------------*/ -/* GLOBAL INPUT ARGUMENTS : */ -/* _ (Struct) st_fx : decoder static memory */ -/* _ (Word16) L_frame : length of the frame */ - -/* _ (Word16[]) Aq_fx : LP filter coefficient Q12 */ -/* _ (Word16) Es_pred_fx : predicted scaled innov. energy Q8 */ -/* _ (Word16[]) pitch_buf_fx : floating pitch values for each subframe Q6*/ -/* _ (Word16[]) voice_factors_fx: frame error rate Q15 */ -/*----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) exc_fx : adapt. excitation exc (Q_exc) */ -/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q_exc) */ -/*----------------------------------------------------------------------*/ - - -/*----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*======================================================================*/ -#endif -ivas_error decod_gen_voic_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 sharpFlag_fx, /* i : formant sharpening flag */ - const Word16 *Aq_fx, /* i : LP filter coefficient Q12*/ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy Q8 */ - const Word16 do_WI_fx, /* i : do interpolation after a FER */ - Word16 *pitch_buf_fx, /* o : Word16 pitch values for each subframe Q6*/ - Word16 *voice_factors_fx, /* o : voicing factors Q15 */ - Word16 *exc_fx, /* i/o: adapt. excitation exc Q_exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc Q_exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_exc */ - Word16 *unbits, /* number of unused bits */ - Word16 *gain_buf, - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6 */ + Decoder_State *st_fx, /* i/o: decoder static memory */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 sharpFlag_fx, /* i : formant sharpening flag */ + const Word16 *Aq_fx, /* i : LP filter coefficient Q12 */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy Q8 */ + const Word16 do_WI_fx, /* i : do interpolation after a FER */ + Word16 *pitch_buf_fx, /* o : Word16 pitch values for each subframe Q6 */ + Word16 *voice_factors_fx, /* o : voicing factors Q15 */ + Word16 *exc_fx, /* i/o: adapt. excitation exc Q_exc */ + Word16 *exc2_fx, /* i/o: adapt. excitation/total exc Q_exc */ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_exc */ + Word16 *unbits, /* number of unused bits */ + Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14 */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6 */ ) { - - - Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx; /* integer pitch variables */ + Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx; /* integer pitch variables */ Word16 gain_pit_fx; /* pitch gain Q14 */ Word32 gain_code_fx; /* gain/normalized gain of the algebraic excitation Q16 */ Word32 norm_gain_code_fx; /* normalized gain of the algebraic excitation Q16 */ @@ -536,7 +62,7 @@ ivas_error decod_gen_voic_ivas_fx( Word16 code_fx[L_SUBFR]; /* algebraic codevector Q12 */ const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12 */ - Word16 *pt_pitch_fx; /* pointer to Word16 pitch Q6 */ + Word16 *pt_pitch_fx; /* pointer to Word16 pitch Q6 */ Word16 i_subfr_fx, i; /* tmp variables */ Word16 error_fx; Word16 gain_preQ_fx; /* Gain of prequantizer excitation */ @@ -633,10 +159,8 @@ ivas_error decod_gen_voic_ivas_fx( * Decode pitch lag *----------------------------------------------------------------------*/ - /**pt_pitch_fx = pit_decode_fx(st_fx, st_fx->core_brate, 0, L_frame, i_subfr_fx, st_fx->coder_type, &pitch_limit_flag_fx, - &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_SUBFR);*/ - *pt_pitch_fx = pit_decode_ivas_fx( st_fx, st_fx->core_brate, 0, L_frame, i_subfr_fx, st_fx->coder_type, &pitch_limit_flag_fx, - &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_SUBFR, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + *pt_pitch_fx = pit_decode_fx( st_fx, st_fx->core_brate, 0, L_frame, i_subfr_fx, st_fx->coder_type, &pitch_limit_flag_fx, + &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_SUBFR, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); move16(); /*Q6*/ /*--------------------------------------------------------------* @@ -677,7 +201,7 @@ ivas_error decod_gen_voic_ivas_fx( IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) { - gain_dec_lbr_ivas_fx( st_fx, st_fx->coder_type, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_SUBFR ); + gain_dec_lbr_fx( st_fx, st_fx->coder_type, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_SUBFR ); } ELSE IF( GT_32( st_fx->core_brate, ACELP_32k ) ) { @@ -700,13 +224,11 @@ ivas_error decod_gen_voic_ivas_fx( } /* update LP filtered gains for the case of frame erasures */ -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame ); } ELSE -#endif { lp_gain_updt_ivas_fx( i_subfr_fx, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame ); } @@ -790,10 +312,6 @@ ivas_error decod_gen_voic_ivas_fx( * Prepare TBE excitation *-----------------------------------------------------------------*/ - /*prep_tbe_exc_fx(L_frame, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, - &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, - st_fx->Q_exc, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate);*/ - Word16 idx; idx = 0; move16(); @@ -802,10 +320,10 @@ ivas_error decod_gen_voic_ivas_fx( idx = idiv1616( i_subfr_fx, L_SUBFR ); } - prep_tbe_exc_ivas_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, - &voice_factors_fx[idx], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, - st_fx->Q_exc, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate, - st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); + prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, + &voice_factors_fx[idx], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, + st_fx->Q_exc, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate, + st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); /*----------------------------------------------------------------* @@ -819,14 +337,12 @@ ivas_error decod_gen_voic_ivas_fx( } ELSE { -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { enhancer_fx( st_fx->core_brate, 0, st_fx->coder_type, i_subfr_fx, L_frame, voice_fac_fx, st_fx->stab_fac_fx, norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &( st_fx->dm_fx ), st_fx->Q_exc ); } ELSE -#endif { enhancer_ivas_fx2( st_fx->core_brate, 0, st_fx->coder_type, i_subfr_fx, L_frame, voice_fac_fx, st_fx->stab_fac_fx, norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &( st_fx->dm_fx ), st_fx->Q_exc ); diff --git a/lib_dec/dec_pit_exc_fx.c b/lib_dec/dec_pit_exc_fx.c index fe7d2daaf..a18029cdc 100644 --- a/lib_dec/dec_pit_exc_fx.c +++ b/lib_dec/dec_pit_exc_fx.c @@ -14,13 +14,13 @@ /*--------------------------------------------------------------------------*/ /* INPUT ARGUMENTS : */ /* _ (Word16*) Aq_fx : LP filter coefficient Q12 */ -/* _ (Word16) coder_type : coding type Q0 */ +/* _ (Word16) coder_type : coding type Q0 */ /* _ (Word16) nb_subfr_fx :Number of subframe considered */ /* _ (Word16) Es_pred_fx :predicted scaled innov. energy */ /*--------------------------------------------------------------------------*/ /* OUTPUT ARGUMENTS : */ /* _ (Word16*) pitch_buf_fx : floating pitch values for each subframe Q6 */ -/* _ (Word16*) code_fx : innovation Q12 */ +/* _ (Word16*) code_fx : innovation Q12 */ /*--------------------------------------------------------------------------*/ /* INPUT/OUTPUT ARGUMENTS : */ /* Decoder_State_fx *st_fx : decoder state structure */ @@ -30,438 +30,29 @@ /* _ None */ /*==========================================================================*/ -#ifndef REMOVE_EVS_DUPLICATES void dec_pit_exc_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 coder_type, /* i : coding type */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *code_fx, /* o : innovation */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - const Word16 nb_subfr_fx /* i : Number of subframe considered */ - , - Word16 *gain_buf /*Q14*/ -) -{ - Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx; /* integer pitch variables */ - Word16 gain_pit_fx; /* pitch gain Q14 */ - Word32 gain_code_fx; /* gain/normalized gain of the algebraic excitation Q16 */ - Word32 norm_gain_code_fx; /* normalized gain of the algebraic excitation Q16 */ - Word16 gain_inov_fx; /* Innovation gain Q12 */ - Word16 voice_fac_fx; /* voicing factor Q15 */ - Word16 L_subfr_fx, pit_idx_fx; - const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12 */ - Word16 *pt_pitch_fx; /* pointer to floating pitch Q6 */ - Word16 i_subfr_fx, i; /* tmp variables */ - Word32 Local_BR_fx, Pitch_BR_fx; - Word16 pitch_limit_flag, Pitch_CT_fx; - Word16 exc2_bidon[L_SUBFR]; - Word16 *pt_gain; /* Pointer to floating gain values for each subframe */ - - Word16 gain_code16, gain_pitx2; - Word32 L_tmp; - Word16 nbits; - GSC_DEC_HANDLE hGSCDec; - gain_pit_fx = 0; - move16(); - hGSCDec = st_fx->hGSCDec; - - MUSIC_POSTFILT_HANDLE hMusicPF; - hMusicPF = st_fx->hMusicPF; - - Word16 use_fcb; - Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ - Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */ -#ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; - move16(); -#endif - - use_fcb = 0; - move16(); - test(); - test(); - IF( ( st_fx->GSC_IVAS_mode > 0 ) && ( EQ_16( st_fx->GSC_noisy_speech, 1 ) || GT_32( st_fx->core_brate, GSC_H_RATE_STG ) ) ) - { - Local_BR_fx = ACELP_8k00; - Pitch_CT_fx = GENERIC; - Pitch_BR_fx = ACELP_8k00; - move32(); - move32(); - move16(); - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - Local_BR_fx = ACELP_14k80; - move32(); - if ( st_fx->GSC_IVAS_mode > 0 ) - { - Local_BR_fx = ACELP_9k60; - move32(); - } - Pitch_BR_fx = st_fx->core_brate; - move32(); - } - } - ELSE IF( EQ_16( st_fx->GSC_noisy_speech, 1 ) ) - { - Local_BR_fx = ACELP_7k20; - move32(); - Pitch_CT_fx = GENERIC; - move16(); - Pitch_BR_fx = ACELP_7k20; - move32(); - if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - Pitch_BR_fx = st_fx->core_brate; - move32(); - } - } - ELSE - { - Local_BR_fx = ACELP_7k20; - move32(); - Pitch_CT_fx = AUDIO; - move16(); - Pitch_BR_fx = st_fx->core_brate; - move32(); - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - Pitch_BR_fx = ACELP_13k20; - move32(); - Pitch_CT_fx = GENERIC; - move16(); - } - } - L_subfr_fx = mult_r( st_fx->L_frame, div_s( 1, nb_subfr_fx ) ); /* TV2Opt : this could be less complex with 2 ifs*/ - - - gain_code_fx = 0; - move16(); - pitch_limit_flag = 1; - move16(); /* always extended pitch Q range */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || ( EQ_16( st_fx->GSC_noisy_speech, 1 ) && ( ( EQ_16( st_fx->L_frame, L_FRAME ) && GE_32( st_fx->core_brate, ACELP_13k20 ) ) || ( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, GSC_H_RATE_STG ) ) || st_fx->GSC_IVAS_mode == 0 ) ) ) && EQ_16( L_subfr_fx, L_SUBFR ) ) ) - { - use_fcb = 1; - move16(); - } - ELSE IF( ( st_fx->GSC_IVAS_mode > 0 ) && EQ_16( L_subfr_fx, 2 * L_SUBFR ) && LT_16( st_fx->GSC_IVAS_mode, 3 ) ) - { - use_fcb = 2; - st_fx->acelp_cfg.fcb_mode = 1; - move16(); - move16(); - set16_fx( st_fx->acelp_cfg.gains_mode, 6, 4 ); - set16_fx( st_fx->acelp_cfg.pitch_bits, 9, 4 ); - set16_fx( st_fx->acelp_cfg.fixed_cdk_index, 14, 5 ); - } - /*------------------------------------------------------------------* - * ACELP subframe loop - *------------------------------------------------------------------*/ - p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */ - pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */ - pt_gain = gain_buf; /* pointer to the gain buffer */ - FOR( i_subfr_fx = 0; i_subfr_fx < st_fx->L_frame; i_subfr_fx += L_subfr_fx ) - { - /*----------------------------------------------------------------------* - * Decode pitch lag - *----------------------------------------------------------------------*/ - *pt_pitch_fx = pit_decode_fx( st_fx, Pitch_BR_fx, 0, st_fx->L_frame, i_subfr_fx, Pitch_CT_fx, &pitch_limit_flag, &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_subfr_fx ); - move16(); - - /*--------------------------------------------------------------* - * Find the adaptive codebook vector. - *--------------------------------------------------------------*/ - - pred_lt4( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_subfr_fx + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); - - /*--------------------------------------------------------------* - * Innovation decoding - *--------------------------------------------------------------*/ - - IF( EQ_16( use_fcb, 1 ) ) - { - inov_decode_fx( st_fx, Local_BR_fx, 0, st_fx->L_frame, 1, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx ); - /*--------------------------------------------------------------* - * Gain decoding - * Estimate spectrum tilt and voicing - *--------------------------------------------------------------*/ - - gain_dec_mless_fx( st_fx, st_fx->L_frame, LOCAL_CT, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); - - st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0 ); - move16(); - } - ELSE IF( EQ_16( use_fcb, 2 ) ) /* IVAS only */ - { - inov_decode_fx( st_fx, Local_BR_fx, 0, st_fx->L_frame, 1, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx ); - /*--------------------------------------------------------------* - * Gain decoding - * Estimate spectrum tilt and voicing - *--------------------------------------------------------------*/ - - gain_dec_lbr_fx( st_fx, GENERIC, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_subfr_fx ); - - st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0 ); - move16(); - } - ELSE - { - nbits = 5; - move16(); - if ( LT_32( st_fx->core_brate, MIN_RATE_FCB ) ) - { - nbits = 4; - move16(); - } - - set16_fx( code_fx, 0, L_SUBFR ); - gain_code_fx = L_deposit_l( 0 ); - st_fx->tilt_code_fx = 0; - move16(); - pit_idx_fx = (Word16) get_next_indice( st_fx, nbits ); - move16(); - - gain_pit_fx = add( 9590, dic_gp_fx[pit_idx_fx] ); - move16(); /*Q14 0.5853 in Q14 9590*/ - - if ( st_fx->BER_detect ) /* Bitstream is corrupted, use the past pitch gain */ - { - gain_pit_fx = st_fx->lp_gainp_fx; - move16(); - } - gain_code_fx = L_mult0( s_max( sub( 32767, shl_o( gain_pit_fx, 1, &Overflow ) ), 16384 ), st_fx->lp_gainc_fx ); /* Use gain pitch and past gain code as an indicator to help finding the best scaling value. gain_code_fx used a temp var*/ - } - - /*----------------------------------------------------------------------* - * Find the total excitation - *----------------------------------------------------------------------*/ - - Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[( i_subfr_fx * ( 2 * HIBND_ACB_L_FAC ) ) / 2], hGSCDec->last_exc_dct_in_fx, - L_subfr_fx, shr( imult1616( L_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 ), gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, NULL, i_subfr_fx, coder_type ); - - gain_code16 = round_fx( L_shl( gain_code_fx, st_fx->Q_exc ) ); /*Q_exc*/ - - IF( use_fcb != 0 ) - { - Acelp_dec_total_exc( exc_fx, exc2_bidon - i_subfr_fx, gain_code16, gain_pit_fx, i_subfr_fx, code_fx, L_subfr_fx ); - } - ELSE - { - IF( norm_s( s_or( gain_pit_fx, 1 ) ) == 0 ) - { - FOR( i = 0; i < L_subfr_fx; i++ ) - { - L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); /*Q16+Q_exc*/ - exc_fx[i + i_subfr_fx] = round_fx_sat( L_tmp ); /*Q_exc*/ - move16(); - } - } - ELSE - { - gain_pitx2 = shl( gain_pit_fx, 1 ); /*Q15*/ - - FOR( i = 0; i < L_subfr_fx; i++ ) - { - L_tmp = L_mult( gain_pitx2, exc_fx[i + i_subfr_fx] ); /*Q16+Q_exc*/ - exc_fx[i + i_subfr_fx] = round_fx_sat( L_tmp ); /*Q_exc*/ - move16(); - } - } - } - - IF( EQ_16( L_subfr_fx, L_FRAME16k ) ) - { - /* update gains for FEC - equivalent to lp_gain_updt() */ - st_fx->lp_gainp_fx = gain_pit_fx; - move16(); - st_fx->lp_gainc_fx = 0; - move32(); - - pt_pitch_fx++; - *pt_pitch_fx = *( pt_pitch_fx - 1 ); - pt_pitch_fx++; - *pt_pitch_fx = *( pt_pitch_fx - 1 ); - pt_pitch_fx++; - *pt_pitch_fx = *( pt_pitch_fx - 1 ); - pt_pitch_fx++; - *pt_pitch_fx = *( pt_pitch_fx - 1 ); - pt_pitch_fx++; - move16(); - move16(); - move16(); - move16(); - p_Aq_fx += 5 * ( M + 1 ); - } - ELSE IF( EQ_16( L_subfr_fx, L_FRAME16k / 2 ) ) - { - IF( i_subfr_fx == 0 ) - { - pt_pitch_fx++; - *pt_pitch_fx = *( pt_pitch_fx - 1 ); - pt_pitch_fx++; - p_Aq_fx += 2 * ( M + 1 ); - move16(); - - /* update gains for FEC - equivalent to lp_gain_updt() */ - st_fx->lp_gainp_fx = extract_h( L_mult( 6554, gain_pit_fx ) ); /*Q14 (3/15 in Q15 9830)*/ - st_fx->lp_gainc_fx = 0; - move16(); - move16(); - } - ELSE - { - pt_pitch_fx++; - *pt_pitch_fx = *( pt_pitch_fx - 1 ); - pt_pitch_fx++; - *pt_pitch_fx = *( pt_pitch_fx - 1 ); - pt_pitch_fx++; - p_Aq_fx += 3 * ( M + 1 ); - move16(); - move16(); - - /* update gains for FEC - equivalent to lp_gain_updt() */ - st_fx->lp_gainp_fx = extract_h( L_mult( 26214, gain_pit_fx ) ); /*Q14 (12/15 in Q15 9830)*/ - st_fx->lp_gainc_fx = 0; - move16(); - move16(); - } - } - ELSE IF( EQ_16( L_subfr_fx, 128 ) ) /*2*L_SUBFR*/ - { - p_Aq_fx += 2 * ( M + 1 ); - pt_pitch_fx++; - *pt_pitch_fx = *( pt_pitch_fx - 1 ); - move16(); - pt_pitch_fx++; - *pt_gain = gain_pit_fx; - move16(); - pt_gain++; - *pt_gain = *( pt_gain - 1 ); - move16(); - pt_gain++; - IF( i_subfr_fx == 0 ) - { - /* update gains for FEC - equivalent to lp_gain_updt() */ - st_fx->lp_gainp_fx = extract_h( L_mult( 9830, gain_pit_fx ) ); /*Q14 (3/10 in Q15 9830)*/ - st_fx->lp_gainc_fx = 0; - move16(); - move16(); - } - ELSE - { - /* update gains for FEC - equivalent to lp_gain_updt() */ - st_fx->lp_gainp_fx = extract_h( L_mult( 22938, gain_pit_fx ) ); /*Q14 (7/10 in Q15 22938)*/ - st_fx->lp_gainc_fx = 0; - move16(); - move16(); - } - } - ELSE IF( EQ_16( L_subfr_fx, 256 ) ) /*4*L_SUBFR*/ - { - pt_pitch_fx++; - *pt_pitch_fx = *( pt_pitch_fx - 1 ); - move16(); - pt_pitch_fx++; - *pt_pitch_fx = *( pt_pitch_fx - 1 ); - move16(); - pt_pitch_fx++; - *pt_pitch_fx = *( pt_pitch_fx - 1 ); - move16(); - pt_pitch_fx++; - *pt_gain = gain_pit_fx; - move16(); - pt_gain++; - *pt_gain = *( pt_gain - 1 ); - move16(); - pt_gain++; - *pt_gain = *( pt_gain - 1 ); - move16(); - pt_gain++; - *pt_gain = *( pt_gain - 1 ); - move16(); - pt_gain++; - p_Aq_fx += 4 * ( M + 1 ); - - /* update gains for FEC - equivalent to lp_gain_updt() */ - st_fx->lp_gainp_fx = gain_pit_fx; - move16(); - st_fx->lp_gainc_fx = 0; - move16(); - } - ELSE - { - p_Aq_fx += ( M + 1 ); - move16(); - pt_pitch_fx++; - move16(); - *pt_gain = gain_pit_fx; - move16(); - pt_gain++; - - lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, 0, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, st_fx->L_frame ); - } - } - - return; -} - -/*==========================================================================*/ -/* FUNCTION : void dec_pit_exc_ivas_fx() */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : Decode pitch only contribution */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16*) Aq_fx : LP filter coefficient Q12 */ -/* _ (Word16) coder_type : coding type Q0 */ -/* _ (Word16) nb_subfr_fx :Number of subframe considered */ -/* _ (Word16) Es_pred_fx :predicted scaled innov. energy */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) pitch_buf_fx : Word16 pitch values for each subframe Q6 */ -/* _ (Word16*) code_fx : innovation */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* Decoder_State_fx *st_fx : decoder state structure */ -/* _ (Word16*) exc_fx : adapt. excitation exc */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*==========================================================================*/ -#endif -void dec_pit_exc_ivas_fx( Decoder_State *st_fx, /* i/o: decoder static memory */ const Word16 *Aq_fx, /* i : LP filter coefficient */ const Word16 coder_type, /* i : coding type */ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - Word16 *pitch_buf_fx, /* o : Word16 pitch values for each subframe */ + Word16 *pitch_buf_fx, /* o : Word16 pitch values for each subframe */ Word16 *code_fx, /* o : innovation */ Word16 *exc_fx, /* i/o: adapt. excitation exc */ Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ const Word16 nb_subfr_fx, /* i : Number of subframe considered */ - Word16 *gain_buf, /*Q14*/ + Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ ) { - Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx; /* integer pitch variables */ - Word16 gain_pit_fx; /* pitch gain Q14 */ - Word32 gain_code_fx; /* gain/normalized gain of the algebraic excitation Q16 */ + Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx; /* integer pitch variables */ + Word16 gain_pit_fx; /* pitch gain Q14 */ + Word32 gain_code_fx; /* gain/normalized gain of the algebraic excitation Q16 */ Word32 norm_gain_code_fx; /* normalized gain of the algebraic excitation Q16 */ - Word16 gain_inov_fx; /* Innovation gain Q12 */ + Word16 gain_inov_fx; /* Innovation gain Q12 */ Word16 voice_fac_fx; /* voicing factor Q15 */ Word16 L_subfr_fx, pit_idx_fx; - const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12 */ + const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12 */ Word16 *pt_pitch_fx; /* pointer to Word16 pitch Q6 */ Word16 i_subfr_fx, i; /* tmp variables */ Word32 Local_BR_fx, Pitch_BR_fx; @@ -578,13 +169,14 @@ void dec_pit_exc_ivas_fx( p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */ pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */ pt_gain = gain_buf; /* pointer to the gain buffer */ + FOR( i_subfr_fx = 0; i_subfr_fx < st_fx->L_frame; i_subfr_fx += L_subfr_fx ) { /*----------------------------------------------------------------------* * Decode pitch lag *----------------------------------------------------------------------*/ - *pt_pitch_fx = pit_decode_ivas_fx( st_fx, Pitch_BR_fx, 0, st_fx->L_frame, i_subfr_fx, Pitch_CT_fx, &pitch_limit_flag, &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_subfr_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + *pt_pitch_fx = pit_decode_fx( st_fx, Pitch_BR_fx, 0, st_fx->L_frame, i_subfr_fx, Pitch_CT_fx, &pitch_limit_flag, &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_subfr_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); move16(); /*--------------------------------------------------------------* @@ -621,7 +213,7 @@ void dec_pit_exc_ivas_fx( * Estimate spectrum tilt and voicing *--------------------------------------------------------------*/ - gain_dec_lbr_ivas_fx( st_fx, GENERIC, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_subfr_fx ); + gain_dec_lbr_fx( st_fx, GENERIC, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_subfr_fx ); st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0, L_subfr_fx, 0 ); move16(); diff --git a/lib_dec/dec_post_fx.c b/lib_dec/dec_post_fx.c index 281281ed6..37d088a8f 100644 --- a/lib_dec/dec_post_fx.c +++ b/lib_dec/dec_post_fx.c @@ -33,10 +33,7 @@ static void calc_st_filt_local_fx( Word16 *apond2, Word16 *apond1, Word16 *parco static void modify_pst_param_fx( const Word16 lp_noise, Word16 *g1, Word16 *g2, const Word16 coder_type, Word16 *gain_factor ); -#ifndef REMOVE_EVS_DUPLICATES static void Dec_formant_postfilt_fx( PFSTAT_HANDLE hPFstat, Word16 *signal_ptr, Word16 *coeff, Word16 *sig_out, Word16 gamma1, Word16 gamma2 ); -#endif -static void Dec_formant_postfilt_ivas_fx( PFSTAT_HANDLE hPFstat, Word16 *signal_ptr, Word16 *coeff, Word16 *sig_out, Word16 gamma1, Word16 gamma2 ); static void calc_st_filt_ivas_fx( Word16 *apond2, Word16 *apond1, Word16 *parcor0, Word16 *sig_ltp_ptr, Word16 *mem_zero, const Word16 extl ); @@ -82,7 +79,7 @@ void Init_post_filter_fx( *--------------------------------------------------------------------------*/ void nb_post_filt_fx( const Word16 L_frame, /* i : frame length */ - PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ + PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ Word16 *psf_lp_noise, /* i : Long term noise Q8 */ const Word16 tmp_noise, /* i : noise energy Q0 */ Word16 *Synth, /* i : 12k8 synthesis Qsyn */ @@ -257,22 +254,20 @@ static void Dec_postfilt_fx( * Main routine to perform formant post filtering *--------------------------------------------------------------------------*/ -#ifndef REMOVE_EVS_DUPLICATES void formant_post_filt_fx( - PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ + PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ Word16 *synth_in, /* i : 12k8 synthesis */ - Word16 *Aq, /* i : LP filter coefficient Q12 */ + Word16 *Aq, /* i : LP filter coefficient Q12 */ Word16 *synth_out, /* i/o: input signal */ - Word16 L_frame, - Word32 lp_noise, /* (i) : background noise energy (15Q16) */ - Word32 brate, /* (i) : bit-rate */ - const Word16 off_flag /* i : off flag */ + const Word16 L_frame, /* i : frame length */ + const Word32 lp_noise, /* (i) : background noise energy (15Q16) */ + const Word32 brate, /* (i) : bit-rate */ + const Word16 off_flag /* i : off flag */ ) { Word16 i_subfr; Word16 *p_Aq; - Word16 post_G1, post_G2; // Q15 - + Word16 post_G1, post_G2; /*default parameter for noisy speech and high bit-rates*/ IF( EQ_16( L_frame, L_FRAME ) ) @@ -381,134 +376,13 @@ void formant_post_filt_fx( Dec_formant_postfilt_fx( hPFstat, &synth_in[i_subfr], p_Aq, &synth_out[i_subfr], post_G1, post_G2 ); p_Aq += ( M + 1 ); } -} -#endif -void formant_post_filt_ivas_fx( - PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ - Word16 *synth_in, /* i : 12k8 synthesis */ - Word16 *Aq, /* i : LP filter coefficient Q12 */ - Word16 *synth_out, /* i/o: input signal */ - Word16 L_frame, - Word32 lp_noise, /* (i) : background noise energy (15Q16) */ - Word32 brate, /* (i) : bit-rate */ - const Word16 off_flag /* i : off flag */ -) -{ - Word16 i_subfr; - Word16 *p_Aq; - Word16 post_G1, post_G2; - - - /*default parameter for noisy speech and high bit-rates*/ - IF( EQ_16( L_frame, L_FRAME ) ) - { - post_G2 = 22938 /*0.7f Q15*/; - move16(); - IF( LT_32( lp_noise, LP_NOISE_THRESH ) ) - { - /*Clean speech*/ - IF( LT_32( brate, ACELP_13k20 ) ) - { - /*Low rates*/ - - post_G1 = 26214 /*0.8f Q15*/; - move16(); - } - ELSE IF( LT_32( brate, ACELP_24k40 ) ) - { - /*Low rates*/ - - post_G1 = 24576 /*0.75f Q15*/; - move16(); - } - ELSE - { - post_G1 = 23593 /*0.72f Q15*/; - move16(); - } - } - ELSE /*Noisy speech*/ - { - post_G1 = 22938 /*0.7f Q15*/; - move16(); - if ( LT_32( brate, ACELP_15k85 ) ) - { - /*Low rates*/ - post_G1 = 24576 /*0.75f Q15*/; - move16(); - } - } - } - ELSE - { - post_G2 = 24904 /*0.76f Q15*/; - move16(); - test(); - IF( GE_32( lp_noise, LP_NOISE_THRESH ) ) - { - post_G1 = 24904 /*0.76f Q15*/; - } - ELSE IF( EQ_32( brate, ACELP_13k20 ) ) - { - post_G1 = 26870 /*0.82f Q15*/; - move16(); - } - ELSE IF( EQ_32( brate, ACELP_16k40 ) ) - { - post_G1 = 26214 /*0.80f Q15*/; - move16(); - } - ELSE IF( EQ_32( brate, ACELP_24k40 ) || EQ_32( brate, ACELP_32k ) ) - { - post_G1 = 25559 /*0.78f Q15*/; - move16(); - } - ELSE - { - post_G1 = 24904 /*0.76f Q15*/; - move16(); - } - } - /* Switch off post-filter */ - if ( off_flag != 0 ) - { - post_G1 = post_G2; - move16(); - } - - /* Reset post filter */ - IF( hPFstat->reset != 0 ) - { - post_G1 = MAX16B; - move16(); - post_G2 = MAX16B; - move16(); - hPFstat->reset = 0; - move16(); - Copy( &synth_in[L_frame - L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM ); - Copy( &synth_in[L_frame - L_SYN_MEM], hPFstat->mem_stp, L_SYN_MEM ); - hPFstat->gain_prec = 16384; // 1.Q14 - move16(); - Copy( synth_in, synth_out, L_frame ); - - return; - } + return; +} - /* input memory*/ - Copy( hPFstat->mem_pf_in, synth_in - L_SYN_MEM, L_SYN_MEM ); - Copy( &synth_in[L_frame - L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM ); - move16(); - p_Aq = Aq; // Q12 - FOR( i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR ) - { - Dec_formant_postfilt_ivas_fx( hPFstat, &synth_in[i_subfr], p_Aq, &synth_out[i_subfr], post_G1, post_G2 ); - p_Aq += ( M + 1 ); - } -} /*---------------------------------------------------------------------------- - * Dec_formant_postfilt_fx + * Dec_formant_postfilt_fx() * * Post - adaptive postfilter main function * Short term postfilter : @@ -522,93 +396,14 @@ void formant_post_filt_ivas_fx( * k1 = 1st parcor calculated on {hi} * gamma3 = gamma3_minus if k1<0, gamma3_plus if k1>0 *----------------------------------------------------------------------------*/ -#ifndef REMOVE_EVS_DUPLICATES -static void Dec_formant_postfilt_fx( - PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ - Word16 *signal_ptr, /* i : input signal (pointer to current subframe Q14*/ - Word16 *coeff, /* i : LPC coefficients for current subframe Q12 */ - Word16 *sig_out, /* o : postfiltered output */ - Word16 gamma1, /* i : short term postfilt. den. weighting factor Q15*/ - Word16 gamma2 /* i : short term postfilt. num. weighting factor Q15*/ -) -{ - /* Local variables and arrays */ - Word16 apond1[M + 1]; /* s.t. denominator coeff. Q12*/ - Word16 apond2[LONG_H_ST]; // Q12 - Word16 res2[L_SUBFR]; // Q14 - Word16 resynth[L_SUBFR + 1]; // Qy - Word16 parcor0; // Q15 - Word16 i, max; - Word16 scale_down; - - /* Compute weighted LPC coefficients */ - weight_a_fx( coeff, apond1, gamma1, M ); - weight_a_fx( coeff, apond2, gamma2, M ); - set16_fx( &apond2[M + 1], 0, LONG_H_ST - ( M + 1 ) ); - max = abs_s( signal_ptr[0] ); // Q14 - FOR( i = 1; i < L_SUBFR; i++ ) - { - max = s_max( max, abs_s( signal_ptr[i] ) ); - } - scale_down = 0; - move16(); - if ( GT_16( max, 16384 /*1.Q14*/ ) ) - { - scale_down = 1; - move16(); - } - - /* Compute A(gamma2) residual */ - IF( !scale_down ) - { - Residu3_fx( apond2, signal_ptr, res2, L_SUBFR, 1 ); - } - ELSE - { - Residu3_fx( apond2, signal_ptr, res2, L_SUBFR, 0 ); - Scale_sig( hPFstat->mem_stp, L_SYN_MEM, -1 ); - } - - /* Controls short term pst filter gain and compute parcor0 */ - calc_st_filt_local_fx( apond2, apond1, &parcor0, res2, hPFstat->mem_zero ); - - /* 1/A(gamma1) filtering, mem_stp is updated */ - resynth[0] = *( hPFstat->mem_stp + sub( L_SYN_MEM, 1 ) ); - move16(); - - E_UTIL_synthesis( 1, apond1, res2, &( resynth[1] ), L_SUBFR, hPFstat->mem_stp + L_SYN_MEM - M, 0, M ); - - IF( !scale_down ) - { - Copy( &( resynth[1] ) + L_SUBFR - L_SYN_MEM, hPFstat->mem_stp, L_SYN_MEM ); - } - ELSE - { - Copy_Scale_sig( &( resynth[1] ) + L_SUBFR - L_SYN_MEM, hPFstat->mem_stp, L_SYN_MEM, 1 ); - } - - /* Tilt filtering */ - Filt_mu_fx( resynth, sig_out, parcor0, L_SUBFR ); - IF( scale_down ) - { - Scale_sig( sig_out, L_SUBFR, 1 ); - } - - /* Gain control */ - scale_st_fx( signal_ptr, sig_out, &hPFstat->gain_prec, L_SUBFR ); - - - return; -} -#endif -static void Dec_formant_postfilt_ivas_fx( - PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ - Word16 *signal_ptr, /* i : input signal (pointer to current subframe Q14*/ - Word16 *coeff, /* i : LPC coefficients for current subframe Q12 */ - Word16 *sig_out, /* o : postfiltered output */ - Word16 gamma1, /* i : short term postfilt. den. weighting factor Q15*/ - Word16 gamma2 /* i : short term postfilt. num. weighting factor Q15*/ +static void Dec_formant_postfilt_fx( + PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ + Word16 *signal_ptr, /* i : input signal (pointer to current subframe Q14*/ + Word16 *coeff, /* i : LPC coefficients for current subframe Q12 */ + Word16 *sig_out, /* o : postfiltered output */ + Word16 gamma1, /* i : short term postfilt. den. weighting factor Q15*/ + Word16 gamma2 /* i : short term postfilt. num. weighting factor Q15*/ ) { /* Local variables and arrays */ diff --git a/lib_dec/dec_ppp_fx.c b/lib_dec/dec_ppp_fx.c index 4849e147a..4b3f4f554 100644 --- a/lib_dec/dec_ppp_fx.c +++ b/lib_dec/dec_ppp_fx.c @@ -6,6 +6,7 @@ #include #include "options.h" /* Compilation switches */ #include "prot_fx.h" /* Function prototypes */ + /*===================================================================*/ /* FUNCTION : void decod_ppp_fx () */ /*-------------------------------------------------------------------*/ @@ -45,20 +46,20 @@ /*-------------------------------------------------------------------*/ /* CALLED FROM : RX */ /*===================================================================*/ + ivas_error decod_ppp_fx( - Decoder_State *st_fx, /* i/o: state structure */ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - Word16 *pitch_buf_fx, /* i/o: fixed pitch values for each subframe */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ - Word16 *exc2_fx, /* i/o: current enhanced excitation */ - Word16 bfi, /* i : bad frame indicator */ - Word16 *gain_buf, + Decoder_State *st_fx, /* i/o: state structure */ + const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ + Word16 *pitch_buf_fx, /* i/o: fixed pitch values for each subframe */ + Word16 *exc_fx, /* i/o: current non-enhanced excitation */ + Word16 *exc2_fx, /* i/o: current enhanced excitation */ + Word16 bfi, /* i : bad frame indicator */ + Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ Word16 *voice_factors, /* o : voicing factors */ Word16 *bwe_exc_fx /* o : excitation for SWB TBE */ ) { Word16 k; - Word16 LPC_de_curr_fx[M + 1], p_Aq_curr_fx[M], p_Aq_old_fx[M + 1]; Word16 excQ_ppp_fx[L_FRAME], pitch_fx[NB_SUBFR], LPC_de_old_fx[M + 1]; ivas_error error; diff --git a/lib_dec/dec_tran_fx.c b/lib_dec/dec_tran_fx.c index c5b06724a..de3a1ff3f 100644 --- a/lib_dec/dec_tran_fx.c +++ b/lib_dec/dec_tran_fx.c @@ -254,16 +254,10 @@ void decod_tran_fx( tmp_idx_2 = idiv1616( i_subfr, L_SUBFR ); } -#ifdef REMOVE_EVS_DUPLICATES - prep_tbe_exc_ivas_fx( L_frame_fx, L_SUBFR, i_subfr, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, - &voice_factors_fx[tmp_idx_2], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, - st_fx->Q_exc, T0, T0_frac, st_fx->coder_type, st_fx->core_brate, - st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); -#else - prep_tbe_exc_fx( L_frame_fx, i_subfr, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, + prep_tbe_exc_fx( L_frame_fx, L_SUBFR, i_subfr, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, &voice_factors_fx[tmp_idx_2], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, - st_fx->Q_exc, T0, T0_frac, st_fx->coder_type, st_fx->core_brate ); -#endif + st_fx->Q_exc, T0, T0_frac, st_fx->coder_type, st_fx->core_brate, + st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); /*----------------------------------------------------------------* * Excitation enhancements (update of total excitation signal) diff --git a/lib_dec/dec_uv_fx.c b/lib_dec/dec_uv_fx.c index fcc2600a3..f1ba21979 100644 --- a/lib_dec/dec_uv_fx.c +++ b/lib_dec/dec_uv_fx.c @@ -25,96 +25,7 @@ static void gain_dec_gacelp_uv_fx( * Decode unvoiced (UC) frames *-------------------------------------------------------------------*/ -#ifndef REMOVE_EVS_DUPLICATES void decod_unvoiced_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* Q12 i : LP filter coefficient */ - const Word16 coder_type, /* Q0 i : coding type */ - Word16 *tmp_noise_fx, /* Q0 o : long term temporary noise energy */ - Word16 *pitch_buf_fx, /* Q6 o : floating pitch values for each subframe*/ - Word16 *voice_factors_fx, /* Q15 o : voicing factors */ - Word16 *exc_fx, /* Q_X o : adapt. excitation exc */ - Word16 *exc2_fx, /* Q_X o : adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* Q_X i/o: excitation for SWB TBE */ - Word16 *gain_buf ) -{ - Word16 gain_pit_fx; /* Quantized pitch gain */ - Word32 gain_code_fx; /* Quantized algebraic codeebook gain */ - Word16 gain_inov_fx; /* inovation gain */ - Word32 norm_gain_code_fx; /* normalized algebraic codeebook gain */ - Word16 voice_fac_fx; /* Voicing factor */ - Word16 code_fx[L_SUBFR]; /* algebraic codevector */ - Word16 i_subfr_fx; - const Word16 *p_Aq_fx; - Word16 *pt_pitch_fx; - - gain_pit_fx = 0; - move16(); - - test(); - IF( EQ_16( st_fx->last_ppp_mode_dec, 1 ) || EQ_16( st_fx->last_nelp_mode_dec, 1 ) ) - { - /* SC_VBR - reset the decoder, to avoid memory not updated issue for this unrealistic case */ - CNG_reset_dec_fx( st_fx, pitch_buf_fx, voice_factors_fx ); - } - - p_Aq_fx = Aq_fx; - move16(); /*Q12*/ /* pointer to interpolated LPC parameters */ - pt_pitch_fx = pitch_buf_fx; - move16(); /* pointer to the pitch buffer */ - - FOR( i_subfr_fx = 0; i_subfr_fx < L_FRAME; i_subfr_fx += L_SUBFR ) - { - /*----------------------------------------------------------------* - * Unvoiced subframe processing - *----------------------------------------------------------------*/ - - gaus_dec_fx( st_fx, i_subfr_fx, code_fx, &norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, &gain_inov_fx, &st_fx->tilt_code_fx, - &voice_fac_fx, &gain_pit_fx, pt_pitch_fx, exc_fx, &gain_code_fx, exc2_fx, bwe_exc_fx, &( st_fx->Q_exc ), st_fx->Q_subfr ); - - *tmp_noise_fx = extract_h( norm_gain_code_fx ); /*Q16*/ - move16(); - - /*----------------------------------------------------------------* - * Excitation enhancements (update of total excitation signal) - *----------------------------------------------------------------*/ - - enhancer_fx( st_fx->core_brate, 0, coder_type, i_subfr_fx, L_FRAME, voice_fac_fx, st_fx->stab_fac_fx, - norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &( st_fx->dm_fx ), st_fx->Q_exc ); - - Word16 tmp_idx = 0; - move16(); - IF( i_subfr_fx != 0 ) - { - tmp_idx = idiv1616( i_subfr_fx, L_SUBFR ); - } - voice_factors_fx[tmp_idx] = 0; - move16(); - - interp_code_5over2_fx( &exc_fx[i_subfr_fx], &bwe_exc_fx[( ( i_subfr_fx * 2 * HIBND_ACB_L_FAC ) >> 1 )], L_SUBFR ); - - p_Aq_fx += ( M + 1 ); - pt_pitch_fx++; - st_fx->tilt_code_dec_fx[tmp_idx] = st_fx->tilt_code_fx; - move16(); - } - - /* SC-VBR */ - st_fx->prev_gain_pit_dec_fx = gain_pit_fx; - move16(); - - set16_fx( gain_buf, 0, NB_SUBFR ); - - return; -} - -/*-------------------------------------------------------------------* - * decod_unvoiced() - * - * Decode unvoiced (UC) frames - *-------------------------------------------------------------------*/ -#endif -void decod_unvoiced_ivas_fx( Decoder_State *st_fx, /* i/o: decoder static memory */ const Word16 *Aq_fx, /* Q12 i : LP filter coefficient */ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ @@ -208,13 +119,11 @@ void decod_unvoiced_ivas_fx( move16(); /* update LP filtered gains for the case of frame erasures */ -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_FRAME ); } ELSE -#endif { lp_gain_updt_ivas_fx( i_subfr_fx, gain_pit_fx, norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_FRAME ); } @@ -250,6 +159,7 @@ void decod_unvoiced_ivas_fx( } // Scale_sig(code_fx, L_SUBFR, 3); //Q12 } + *tmp_noise_fx = extract_h( norm_gain_code_fx ); /*Q16*/ move16(); @@ -257,14 +167,12 @@ void decod_unvoiced_ivas_fx( * Excitation enhancements (update of total excitation signal) *----------------------------------------------------------------*/ -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { enhancer_fx( st_fx->core_brate, 0, coder_type, i_subfr_fx, L_FRAME, voice_fac_fx, st_fx->stab_fac_fx, norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &( st_fx->dm_fx ), st_fx->Q_exc ); } ELSE -#endif { enhancer_ivas_fx( MODE1, st_fx->core_brate, uc_two_stage_flag, 0, coder_type, i_subfr_fx, L_FRAME, voice_fac_fx, st_fx->stab_fac_fx, norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx /*Q9/Q12?*/, exc2_fx, gain_pit_fx, &( st_fx->dm_fx ), st_fx->Q_exc ); @@ -276,12 +184,6 @@ void decod_unvoiced_ivas_fx( IF( i_subfr_fx != 0 ) { tmp_idx = idiv1616( i_subfr_fx, L_SUBFR ); -#ifdef REMOVE_EVS_DUPLICATES - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) - { - tmp_idx = idiv1616( i_subfr_fx, L_SUBFR ); - } -#endif } voice_factors_fx[tmp_idx] = 0; move16(); diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index 090409b4c..fdd442bf6 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -332,11 +332,7 @@ ivas_error evs_dec_fx( IF( EQ_16( st_fx->core, ACELP_CORE ) ) { /* ACELP core decoder */ -#ifdef REMOVE_EVS_DUPLICATES - IF( ( error = acelp_core_dec_ivas_fx( st_fx, NULL, synth_fx, NULL, bwe_exc_extended_fx, voice_factors_fx, old_syn_12k8_16k_fx, sharpFlag, pitch_buf_fx, &unbits, &sid_bw, NULL, NULL, NULL, 0, EVS_MONO, 0, 0, 1, NULL, 1 ) ) != IVAS_ERR_OK ) -#else IF( ( error = acelp_core_dec_fx( st_fx, NULL, synth_fx, NULL, bwe_exc_extended_fx, voice_factors_fx, old_syn_12k8_16k_fx, sharpFlag, pitch_buf_fx, &unbits, &sid_bw, NULL, NULL, NULL, 0, EVS_MONO, 0, 0, 1, NULL, 1 ) ) != IVAS_ERR_OK ) -#endif { return error; } @@ -957,15 +953,9 @@ ivas_error evs_dec_fx( } st_fx->lp_noise = hFdCngDec->lp_noise; /*Q9.23*/ move32(); -#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - ApplyFdCng_fx( output, NULL, realBuffer, imagBuffer, st, concealWholeFrame, 0 ); -#else -#ifdef REMOVE_EVS_DUPLICATES - ApplyFdCng_ivas_fx( output_sp, 0, NULL, 0, realBuffer, imagBuffer, &st_fx->scaleFactor.hb_scale, st_fx, concealWholeFrame, 0 ); -#else - ApplyFdCng_fx( output_sp, 0, realBuffer, imagBuffer, &st_fx->scaleFactor.hb_scale, st_fx, concealWholeFrame, 0 ); -#endif -#endif + + ApplyFdCng_fx( output_sp, 0, NULL, 0, realBuffer, imagBuffer, &st_fx->scaleFactor.hb_scale, st_fx, concealWholeFrame, 0 ); + /* Generate additional comfort noise to mask potential coding artefacts */ test(); IF( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) && st_fx->flag_cna ) diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index d0fd178f2..7aaaeb161 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -555,573 +555,9 @@ void deleteFdCngDec_fx( HANDLE_FD_CNG_DEC *hFdCngDec ) error */ -#ifndef REMOVE_EVS_DUPLICATES Word16 ApplyFdCng_fx( Word16 *timeDomainInput, /* i : pointer to time domain input Q*/ Word16 Q, -#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - Word16 *powerSpectrum, -#endif - Word32 **cldfbBufferReal, /* i/o: real part of the CLDFB buffer cldfbBufferScale*/ - Word32 **cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer cldfbBufferScale*/ - Word16 *cldfbBufferScale, /* o : pointer to the scalefactor for real and imaginary part of the CLDFB buffer */ - Decoder_State *st, - const Word16 concealWholeFrame, /* i : binary flag indicating frame loss Q0*/ - Word16 is_music /*Q0*/ ) -{ - Word16 j, k, nBins; - Word16 s, s1, s2, num, denom; - Word32 *cngNoiseLevel; - Word16 *cngNoiseLevel_exp; - Word32 L_tmp; - Word16 L_tmp_exp; - Word16 facTab[NPART]; - Word16 facTabExp[NPART]; - Word16 tmp_loop; - Word32 L_c; - Word16 lsp_cng[M]; - HANDLE_FD_CNG_DEC hFdCngDec; - HANDLE_FD_CNG_COM hFdCngCom; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; - Flag Carry = 0; - move16(); - move16(); -#endif -#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - int16_t L_frame, last_L_frame; - int32_t sr_core; - - PMT( "Fix point code missing for IVAS_CODE_CNG_FIX185_PLC_FADEOUT" ) - /* limit L_frame and core fs values for MDCT-Stereo modes which can have higher core sampling than 16kHz, but use a downsampled buffer */ - L_frame = min( st->L_frame, L_FRAME16k ); - last_L_frame = min( st->last_L_frame, L_FRAME16k ); - sr_core = min( st->sr_core, INT_FS_16k ); -#endif - - hFdCngDec = st->hFdCngDec; - hFdCngCom = hFdCngDec->hFdCngCom; - - - if ( EQ_16( hFdCngCom->frame_type_previous, ACTIVE_FRAME ) ) - { - hFdCngCom->inactive_frame_counter = 0; - move16(); - } - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) - { - hFdCngDec->flag_dtx_mode = hFdCngDec->flag_dtx_mode || st->first_CNG; - test(); - move16(); - } - cngNoiseLevel = hFdCngCom->cngNoiseLevel; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ - move32(); - cngNoiseLevel_exp = &hFdCngCom->cngNoiseLevelExp; - move16(); - nBins = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); - - SWITCH( st->m_frame_type ) - { - case ACTIVE_FRAME: - - /************************** - * ACTIVE_FRAME at DECODER * - **************************/ - - hFdCngCom->inactive_frame_counter = 0; - move16(); - hFdCngCom->sid_frame_counter = 0; - move16(); - - /* set noise estimation inactive during concealment, as no update with noise generated by concealment should be performed. */ - /* set noise estimation inactive during concealment, no update with noise generated by concealment should be performed. */ - -#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - if ( concealWholeFrame == 0 && - ( timeDomainInput == NULL || - ( *timeDomainInput( -FLT_MAX ) && - *( timeDomainInput + hFdCngCom->frameSize - 1 ) < FLT_MAX && - *( timeDomainInput + hFdCngCom->frameSize - 1 ) > ( -FLT_MAX ) ) ) && - ( ( ( ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT && hFdCngDec->flag_dtx_mode ) || !st->VAD ) && - !( st->cng_type == LP_CNG && hFdCngDec->flag_dtx_mode ) && ( is_music == 0 ) ) || - ( st->element_mode == IVAS_CPE_TD ) ) && - ( !st->BER_detect ) ) -#else - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( - ( concealWholeFrame == 0 ) && - ( LT_16( *timeDomainInput, MAXVAL_WORD16 ) ) && GT_16( *timeDomainInput, MINVAL_WORD16 ) && ( LT_16( *( timeDomainInput + sub( hFdCngCom->frameSize, 1 ) ), MAXVAL_WORD16 ) ) && GT_16( *( timeDomainInput + sub( hFdCngCom->frameSize, 1 ) ), MINVAL_WORD16 ) && ( ( ( hFdCngDec->flag_dtx_mode == 0 ) && ( st->VAD != 0 ) ) == 0 ) && ( ( ( st->cng_type == LP_CNG ) && ( hFdCngDec->flag_dtx_mode != 0 ) ) == 0 ) && ( is_music == 0 ) && ( st->BER_detect == 0 ) ) -#endif - { - /* Perform noise estimation at the decoder */ -#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - perform_noise_estimation_dec_fx( timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); -#else - perform_noise_estimation_dec_fx( timeDomainInput, Q, hFdCngDec ); -#endif - - /* Update the shaping parameters */ - test(); - IF( NE_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->element_mode, IVAS_CPE_DFT ) ) - { - scalebands( hFdCngDec->msNoiseEst, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, nBins, hFdCngDec->bandNoiseShape, 1 ); - } - hFdCngDec->bandNoiseShape_exp = hFdCngDec->msNoiseEst_exp; - move16(); - - - /* Update CNG levels */ - test(); - IF( hFdCngDec->flag_dtx_mode != 0 && EQ_16( st->cng_type, FD_CNG ) ) - { - /* This needs to be done only once per inactive phase */ - bandcombinepow( - hFdCngDec->bandNoiseShape, - hFdCngDec->bandNoiseShape_exp, - nBins, - hFdCngCom->part, - hFdCngCom->nFFTpart, - hFdCngCom->psize_inv, - hFdCngDec->partNoiseShape, - &hFdCngDec->partNoiseShape_exp ); - - - j = 0; - move16(); - s2 = -( WORD32_BITS - 1 ); - move16(); - FOR( k = 0; k < hFdCngCom->nFFTpart; k++ ) - { - assert( hFdCngDec->partNoiseShape[k] >= 0 ); - assert( hFdCngCom->sidNoiseEst[k] >= 0 ); - - /* add DELTA as it is done in FLC version, in order to avoid num > denom */ - facTab[k] = 0; - move16(); - IF( hFdCngDec->partNoiseShape[k] != 0 ) - { - s1 = norm_l( hFdCngCom->sidNoiseEst[k] ); - L_tmp = L_shl( hFdCngCom->sidNoiseEst[k], s1 ); /*Q31 - hFdCngCom->sidNoiseEstExp + s1*/ - L_tmp_exp = sub( hFdCngCom->sidNoiseEstExp, s1 ); - L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); - L_tmp = L_shr( L_tmp, 1 ); - s = add( L_tmp_exp, 1 ); - num = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ - - s1 = norm_l( hFdCngDec->partNoiseShape[k] ); - L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); /*Q31 - hFdCngDec->partNoiseShape_exp + s1*/ - L_tmp_exp = sub( hFdCngDec->partNoiseShape_exp, s1 ); - L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); - s = sub( s, L_tmp_exp ); - denom = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ - - facTab[k] = div_s( num, denom ); /*Q15 - s*/ - move16(); - facTabExp[k] = s; - move16(); - } - /* Set unique exponent, if mantissa is equal to zero */ - if ( facTab[k] == 0 ) - { - facTabExp[k] = -( WORD32_BITS - 1 ); - move16(); - } - s2 = s_max( s2, facTabExp[k] ); - } - - FOR( k = 0; k < hFdCngCom->nFFTpart; k++ ) - { - s = sub( facTabExp[k], s2 ); - s = s_max( s_min( s, WORD32_BITS - 1 ), -( WORD32_BITS - 1 ) ); - FOR( ; j <= hFdCngCom->part[k]; j++ ) - { - cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ - move32(); - } - } - - /* adapt scaling for rest of the buffer */ - IF( NE_16( s2, -( WORD32_BITS - 1 ) ) ) - { - s = sub( *cngNoiseLevel_exp, add( hFdCngDec->bandNoiseShape_exp, s2 ) ); - FOR( ; k < hFdCngCom->npart; k++ ) - { - FOR( ; j <= hFdCngCom->part[k]; j++ ) - { - cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); /*Q31 - hFdCngDec->bandNoiseShape_exp + s*/ - move32(); - } - } - - *cngNoiseLevel_exp = add( hFdCngDec->bandNoiseShape_exp, s2 ); - move16(); - } - } - ELSE - { - /* This sets the new CNG levels until a SID update overwrites it */ - test(); - test(); - test(); - IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) ) || ( EQ_16( st->element_mode, IVAS_CPE_TD ) && !hFdCngDec->flag_dtx_mode && !st->VAD ) ) - { - Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, nBins ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ - *cngNoiseLevel_exp = hFdCngDec->bandNoiseShape_exp; - move16(); - } - } -#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - if ( st->element_mode == IVAS_CPE_MDCT && timeDomainInput == NULL ) - { - st->hTcxDec->CngLevelBackgroundTrace_bfi = sqrtf( sum_f( cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / NORM_MDCT_FACTOR ); - } - else - { - st->hTcxDec->CngLevelBackgroundTrace_bfi = (float) sqrt( ( sum_f( cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / L_frame ); - } -#endif - /*st->cngTDLevel = (float)sqrt( (sumFLOAT(cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand) / 2 * hFdCngCom->fftlen) / st->Mode2_L_frame);*/ - tmp_loop = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); - L_tmp = L_deposit_h( 0 ); - L_c = L_deposit_h( 0 ); - FOR( j = 0; j < tmp_loop; j++ ) - { - - Carry = 0; - move16(); - L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); /*Q31*/ - Overflow = 0; - move16(); - - IF( *( cngNoiseLevel + j ) < 0 ) - { - L_c = L_msuNs( L_c, 0, 0 ); /*Q-1*/ - } - IF( *( cngNoiseLevel + j ) >= 0 ) - { - L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ - } - } - L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ - L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); - - L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ - - L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )] ); /*Q16,exp -7*/ - L_tmp_exp = add( L_tmp_exp, -7 ); /*->Q16, L_tmp_exp */ - L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ - - st->cngTDLevel = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ - st->cngTDLevel_e = L_tmp_exp; - move16(); - } - ELSE IF( EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) ) - { - IF( hFdCngCom->active_frame_counter > 0 ) - { - /* Perform noise estimation in active frames in the decoder for downward updates */ -#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - perform_noise_estimation_dec_fx( timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); -#else - perform_noise_estimation_dec_fx( timeDomainInput, Q, hFdCngDec ); -#endif - } - } - test(); - test(); - L_tmp = 0; - FOR( j = hFdCngCom->startBand; j < hFdCngCom->stopFFTbin; j++ ) - { - L_tmp = L_add( L_tmp, L_shr( cngNoiseLevel[j], 16 ) ); - } - L_tmp_exp = add( *cngNoiseLevel_exp, 16 ); - test(); - test(); - IF( EQ_16( concealWholeFrame, 1 ) && EQ_16( st->nbLostCmpt, 1 ) && ( GT_32( L_shl_o( L_tmp, L_tmp_exp, &Overflow ), 21474836 ) /*0.01f Q31*/ ) ) - { - /* update isf cng estimate for concealment. Do that during concealment, in order to avoid addition clean channel complexity*/ -#ifndef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, 0 ); - E_LPC_a_lsp_conversion( hFdCngCom->A_cng, lsp_cng, st->lspold_cng, M ); - Copy( lsp_cng, st->lspold_cng, M ); /*Q15*/ - - lsp2lsf_fx( lsp_cng, st->lsf_cng, M, st->sr_core ); -#else - if ( st->element_mode == IVAS_CPE_MDCT && st->core != ACELP_CORE ) - { - float scf[SNS_NPTS]; - float scf_int[FDNS_NPTS]; - float whitenend_noise_shape[L_FRAME16k]; - int16_t inc, start_idx, stop_idx; - float *noiseLevelPtr; - - - inc = ( st->core > TCX_20 ) ? 2 : 1; - start_idx = hFdCngCom->startBand / inc; - stop_idx = L_frame / inc; - noiseLevelPtr = cngNoiseLevel; - - set_zero( whitenend_noise_shape, start_idx ); - for ( j = start_idx; j < stop_idx; j++, noiseLevelPtr += inc ) - { - whitenend_noise_shape[j] = *noiseLevelPtr; - } - if ( st->core == TCX_20_CORE ) - { - st->hTonalMDCTConc->psychParams = &st->hTonalMDCTConc->psychParamsTCX20; - } - else - { - st->hTonalMDCTConc->psychParams = &st->hTonalMDCTConc->psychParamsTCX10; - } - - sns_compute_scf( whitenend_noise_shape, st->hTonalMDCTConc->psychParams, L_frame, scf ); - sns_interpolate_scalefactors( scf_int, scf, ENC ); - sns_interpolate_scalefactors( st->hTonalMDCTConc->scaleFactorsBackground_flt, scf, DEC ); - sns_shape_spectrum( whitenend_noise_shape, st->hTonalMDCTConc->psychParams, scf_int, L_frame ); - - mvr2r( whitenend_noise_shape + start_idx, cngNoiseLevel, stop_idx - start_idx ); - wmops_sub_end(); - } - else if ( st->element_mode != IVAS_CPE_MDCT ) - { - lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, 0.f ); - a2lsp_stab( hFdCngCom->A_cng, lsp_cng, st->lspold_cng ); - mvr2r( lsp_cng, st->lspold_cng, M ); - lsp2lsf( lsp_cng, st->lsf_cng, M, sr_core ); - } - -#endif - st->plcBackgroundNoiseUpdated = 1; - move16(); - } - BREAK; - - case SID_FRAME: - - hFdCngDec->flag_dtx_mode = 1; - move16(); - /* no break */ - - case ZERO_FRAME: - - test(); - IF( st != NULL && st->cng_type == LP_CNG ) - { - /* Perform noise estimation on inactive phase at the decoder */ -#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - perform_noise_estimation_dec_fx( timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); -#else - perform_noise_estimation_dec_fx( timeDomainInput, Q, hFdCngDec ); -#endif - /* Update the shaping parameters */ - - test(); - IF( NE_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->element_mode, IVAS_CPE_DFT ) ) - { - scalebands( hFdCngDec->msNoiseEst, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), hFdCngDec->bandNoiseShape, 1 ); - } - hFdCngDec->bandNoiseShape_exp = hFdCngDec->msNoiseEst_exp; - move16(); - /* This sets the new CNG levels until a SID update overwrites it */ - Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ); /* This sets the new CNG levels until a SID update overwrites it Q31 - hFdCngDec->bandNoiseShape_exp*/ - *cngNoiseLevel_exp = hFdCngDec->bandNoiseShape_exp; - move16(); -#ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - st->cngTDLevel = (float) sqrt( ( sum_f( cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / L_frame ); -#else - /*st->cngTDLevel = (float)sqrt( (sumFLOAT(cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand) / 2 * hFdCngCom->fftlen) / st->Mode2_L_frame);*/ - tmp_loop = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); - L_tmp = L_deposit_h( 0 ); - L_c = L_deposit_h( 0 ); - FOR( j = 0; j < tmp_loop; j++ ) - { - - Carry = 0; - move16(); - L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); /*Q31*/ - Overflow = 0; - move16(); - - IF( *( cngNoiseLevel + j ) < 0 ) - { - L_c = L_msuNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ - } - IF( *( cngNoiseLevel + j ) >= 0 ) - { - L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ - } - } - L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ - L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); - - L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ - - L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )] ); /*Q16,exp -7*/ - L_tmp_exp = add( L_tmp_exp, -7 ); /*->Q16, L_tmp_exp */ - L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ - - st->cngTDLevel = round_fx_o( Sqrt32( L_tmp, &L_tmp_exp ), &Overflow ); /*Q15 - L_tmp_exp*/ - move16(); - st->cngTDLevel_e = L_tmp_exp; - move16(); -#endif - BREAK; - } - hFdCngCom->inactive_frame_counter = add( hFdCngCom->inactive_frame_counter, 1 ); - move16(); - - /************************************* - * SID_FRAME or ZERO_FRAME at DECODER * - *************************************/ - - /* Detect first non-active frame */ - IF( EQ_16( hFdCngCom->inactive_frame_counter, 1 ) ) - { - /* Compute the fine spectral structure of the comfort noise shape using the decoder-side noise estimates */ - bandcombinepow( - hFdCngDec->bandNoiseShape, - hFdCngDec->bandNoiseShape_exp, - nBins, - hFdCngCom->part, - hFdCngCom->nFFTpart, - hFdCngCom->psize_inv, - hFdCngDec->partNoiseShape, - &hFdCngDec->partNoiseShape_exp ); - } - - IF( EQ_16( st->m_frame_type, SID_FRAME ) ) - { - IF( LT_32( hFdCngCom->msFrCnt_init_counter, L_deposit_l( hFdCngCom->msFrCnt_init_thresh ) ) ) - { - /* At initialization, interpolate the bin/band-wise levels from the partition levels */ - scalebands( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, - hFdCngCom->nFFTpart, sub( hFdCngCom->stopBand, hFdCngCom->startBand ), cngNoiseLevel, 1 ); - *cngNoiseLevel_exp = hFdCngCom->sidNoiseEstExp; - move16(); - } - ELSE - { - if ( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) - { - } - - /* Interpolate the CLDFB band levels from the SID (partition) levels */ - IF( GT_16( hFdCngCom->regularStopBand, hFdCngCom->numCoreBands ) ) - { - scalebands( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, - hFdCngCom->nFFTpart, sub( hFdCngCom->stopBand, hFdCngCom->startBand ), cngNoiseLevel, 0 ); - *cngNoiseLevel_exp = hFdCngCom->sidNoiseEstExp; - move16(); - } - - s2 = -( WORD32_BITS - 1 ); - move16(); - /* Shape the SID noise levels in each FFT bin */ - j = 0; - move16(); - FOR( k = 0; k < hFdCngCom->nFFTpart; k++ ) - { - assert( hFdCngDec->partNoiseShape[k] >= 0 ); - - /* add DELTA as it is done in FLC version, in order to avoid num > denom */ - facTab[k] = 0; - move16(); - IF( hFdCngDec->partNoiseShape[k] != 0 ) - { - s1 = norm_l( hFdCngCom->sidNoiseEst[k] ); - L_tmp = L_shl( hFdCngCom->sidNoiseEst[k], s1 ); /*Q31 - hFdCngCom->sidNoiseEstExp + s1*/ - L_tmp_exp = sub( hFdCngCom->sidNoiseEstExp, s1 ); - L_tmp = BASOP_Util_Add_Mant32Exp( hFdCngCom->sidNoiseEst[k], hFdCngCom->sidNoiseEstExp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); - L_tmp = L_shr( L_tmp, 1 ); - s = add( L_tmp_exp, 1 ); - num = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ - - s1 = norm_l( hFdCngDec->partNoiseShape[k] ); - L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); /*Q31 - hFdCngDec->partNoiseShape_exp + s1*/ - L_tmp_exp = sub( hFdCngDec->partNoiseShape_exp, s1 ); - L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); - s = sub( s, L_tmp_exp ); - denom = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ - - facTab[k] = div_s( num, denom ); /*Q15 - s*/ - move16(); - facTabExp[k] = s; - move16(); - } - /* Set unique exponent, if mantissa is equal to zero */ - if ( facTab[k] == 0 ) - { - facTabExp[k] = -( WORD32_BITS - 1 ); - move16(); - } - s2 = s_max( s2, facTabExp[k] ); - } - - FOR( k = 0; k < hFdCngCom->nFFTpart; k++ ) - { - s = sub( facTabExp[k], s2 ); - s = s_max( s_min( s, WORD32_BITS - 1 ), -( WORD32_BITS - 1 ) ); - FOR( ; j <= hFdCngCom->part[k]; j++ ) - { - cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ - move32(); - } - } - /* adapt scaling for rest of the buffer */ - s = sub( *cngNoiseLevel_exp, add( hFdCngDec->bandNoiseShape_exp, s2 ) ); - FOR( ; k < hFdCngCom->npart; k++ ) - { - FOR( ; j <= hFdCngCom->part[k]; j++ ) - { - cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); /*Q31 - hFdCngDec->bandNoiseShape_exp + s*/ - move32(); - } - } - *cngNoiseLevel_exp = add( hFdCngDec->bandNoiseShape_exp, s2 ); - move16(); - } - } - - IF( EQ_16( st->codec_mode, MODE2 ) ) - { - /* Generate comfort noise during SID or zero frames */ - generate_comfort_noise_dec_fx( cldfbBufferReal, cldfbBufferImag, cldfbBufferScale, st, &( st->Q_exc ), 2, -1 ); - } - - BREAK; - - default: - return -1; - } - - - return 0; -} -#endif -Word16 ApplyFdCng_ivas_fx( - Word16 *timeDomainInput, /* i : pointer to time domain input Q*/ - Word16 Q, Word32 *powerSpectrum, /*Q_power_spectrum*/ Word16 Q_power_spectrum, Word32 **cldfbBufferReal, /* i/o: real part of the CLDFB buffer cldfbBufferScale*/ @@ -1221,27 +657,22 @@ Word16 ApplyFdCng_ivas_fx( ( !st->BER_detect ) ) { /* Perform noise estimation at the decoder */ -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { perform_noise_estimation_dec_fx( timeDomainInput, Q, hFdCngDec ); } ELSE -#endif { perform_noise_estimation_dec_ivas_fx( timeDomainInput, Q, powerSpectrum, Q_power_spectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); } /* Update the shaping parameters */ test(); -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { scalebands( hFdCngDec->msNoiseEst, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, nBins, hFdCngDec->bandNoiseShape, 1 ); } - ELSE -#endif - IF( NE_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->element_mode, IVAS_CPE_DFT ) ) + ELSE IF( NE_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->element_mode, IVAS_CPE_DFT ) ) { scalebands_fx( hFdCngDec->msNoiseEst, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, nBins, hFdCngDec->bandNoiseShape, 1 ); } @@ -1477,13 +908,11 @@ Word16 ApplyFdCng_ivas_fx( IF( hFdCngCom->active_frame_counter > 0 ) { /* Perform noise estimation in active frames in the decoder for downward updates */ -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { perform_noise_estimation_dec_fx( timeDomainInput, Q, hFdCngDec ); } ELSE -#endif { perform_noise_estimation_dec_ivas_fx( timeDomainInput, Q, powerSpectrum, Q_power_spectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); } @@ -1544,44 +973,37 @@ Word16 ApplyFdCng_ivas_fx( IF( st != NULL && EQ_16( st->cng_type, LP_CNG ) ) { /* Perform noise estimation on inactive phase at the decoder */ -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { perform_noise_estimation_dec_fx( timeDomainInput, Q, hFdCngDec ); } ELSE -#endif { perform_noise_estimation_dec_ivas_fx( timeDomainInput, Q, powerSpectrum, Q_power_spectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); } /* Update the shaping parameters */ - test(); -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { scalebands( hFdCngDec->msNoiseEst, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), hFdCngDec->bandNoiseShape, 1 ); } - ELSE -#endif - IF( NE_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->element_mode, IVAS_CPE_DFT ) ) + ELSE IF( NE_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->element_mode, IVAS_CPE_DFT ) ) { scalebands_fx( hFdCngDec->msNoiseEst, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), hFdCngDec->bandNoiseShape, 1 ); } hFdCngDec->bandNoiseShape_exp = hFdCngDec->msNoiseEst_exp; move16(); + /* This sets the new CNG levels until a SID update overwrites it */ Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ); /* This sets the new CNG levels until a SID update overwrites it */ /*Q31 - hFdCngDec->bandNoiseShape_exp*/ -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { *cngNoiseLevel_exp = hFdCngDec->bandNoiseShape_exp; move16(); } ELSE -#endif { Word16 shift1 = L_norm_arr( cngNoiseLevel, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ); Word16 shift2 = L_norm_arr( cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), sub( FFTCLDFBLEN, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ) ); @@ -1662,16 +1084,15 @@ Word16 ApplyFdCng_ivas_fx( IF( LT_32( hFdCngCom->msFrCnt_init_counter, L_deposit_l( hFdCngCom->msFrCnt_init_thresh ) ) ) { /* At initialization, interpolate the bin/band-wise levels from the partition levels */ -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { scalebands( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, sub( hFdCngCom->stopBand, hFdCngCom->startBand ), cngNoiseLevel, 1 ); } ELSE -#endif { scalebands_fx( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, sub( hFdCngCom->stopBand, hFdCngCom->startBand ), cngNoiseLevel, 1 ); } + *cngNoiseLevel_exp = hFdCngCom->sidNoiseEstExp; move16(); } @@ -1684,13 +1105,11 @@ Word16 ApplyFdCng_ivas_fx( /* Interpolate the CLDFB band levels from the SID (partition) levels */ IF( GT_16( hFdCngCom->regularStopBand, hFdCngCom->numCoreBands ) ) { -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { scalebands( sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, sub( hFdCngCom->stopBand, hFdCngCom->startBand ), cngNoiseLevel, 0 ); } ELSE -#endif { scalebands_fx( sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, sub( hFdCngCom->stopBand, hFdCngCom->startBand ), cngNoiseLevel, 0 ); } @@ -1757,7 +1176,6 @@ Word16 ApplyFdCng_ivas_fx( } } -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { /* adapt scaling for rest of the buffer */ @@ -1774,7 +1192,6 @@ Word16 ApplyFdCng_ivas_fx( move16(); } ELSE -#endif { Word16 shift1 = L_norm_arr( cngNoiseLevel, j ); Word16 shift2 = L_norm_arr( &cngNoiseLevel[j], sub( FFTCLDFBLEN, j ) ); @@ -1863,13 +1280,11 @@ Word16 ApplyFdCng_ivas_fx( IF( EQ_16( st->codec_mode, MODE2 ) ) { /* Generate comfort noise during SID or zero frames */ -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { generate_comfort_noise_dec_fx( cldfbBufferReal, cldfbBufferImag, cldfbBufferScale, st, &( st->Q_exc ), 2, -1 ); } ELSE -#endif { generate_comfort_noise_dec_ivas_fx( cldfbBufferReal, cldfbBufferImag, cldfbBufferScale, st, &( st->Q_exc ), 2, -1 ); } diff --git a/lib_dec/gain_dec_fx.c b/lib_dec/gain_dec_fx.c index 00eca187d..db325cd80 100644 --- a/lib_dec/gain_dec_fx.c +++ b/lib_dec/gain_dec_fx.c @@ -602,7 +602,6 @@ void gain_dec_mless_fx( /* _ None */ /*==================================================================================*/ -#ifndef REMOVE_EVS_DUPLICATES void gain_dec_lbr_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 coder_type, /* i : coding type */ @@ -653,375 +652,6 @@ void gain_dec_lbr_fx( ctype = shl( sub( coder_type, 1 ), 1 ); - /*-----------------------------------------------------------------* - * calculate prediction of gcode - * search for the best codeword - *-----------------------------------------------------------------*/ - IF( i_subfr == 0 ) - { - b_fx = b_1sfr_fx; - move16(); - n_pred = 2; - move16(); - cdbk_fx = gp_gamma_1sfr_6b_fx; - SWITCH( nBits ) - { - case 8: - { - cdbk_fx = gp_gamma_1sfr_8b_fx; /* Q14/Q9*/ - BREAK; - } - case 7: - { - cdbk_fx = gp_gamma_1sfr_7b_fx; /* Q14/Q9*/ - BREAK; - } - case 6: - { - cdbk_fx = gp_gamma_1sfr_6b_fx; /* Q14/Q9*/ - BREAK; - } - } - - /* calculate predicted gain */ - aux_fx[0] = 4096; /*Q12*/ - move16(); - aux_fx[1] = shl( ctype, 12 ); /*Q12*/ - move16(); - - /* gcode0 = (float)pow(10, dotp(b, aux, n_pred) - 0.5f * (float)log10(Ecode)); - gcode0 = (float)pow(10, dotp(b, aux, n_pred) - 0.05f * 10 * (float)log10(Ecode)); - gcode0 = (float)pow(10, 0.05(20 * dotp(b, aux, n_pred) - 10 * (float)log10(Ecode))); */ - - e_tmp = norm_l( L_tmp2 ); - f_tmp = Log2_norm_lc( L_shl( L_tmp2, e_tmp ) ); /*Q15*/ - e_tmp = sub( expg2, add( 1, e_tmp ) ); - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 12330 ); /* Q13 */ /* 10*log10(2) in Q12*/ - - L_tmp = Dot_product( b_fx, aux_fx, n_pred ); /*Q25*/ - L_tmp = Mult_32_16( L_tmp, 160 ); /*Q13, 20 in Q3*/ - L_tmp = L_sub( L_tmp, L_tmp1 ); /*Q13*/ - - gcode0_fx = round_fx( L_shl( L_tmp, 11 ) ); /* Q8 */ - - - /*-----------------------------------------------------------------* - * gcode0 = pow(10.0, gcode0/20) - * = pow(2, 3.321928*gcode0/20) - * = pow(2, 0.166096*gcode0) - *-----------------------------------------------------------------*/ - - L_tmp = L_mult( gcode0_fx, 21771 ); /* *0.166096 in Q17 -> Q26 */ - L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ - - gcode0_fx = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub( exp_gcode0, 14 ); - - /* retrieve the codebook index and calculate both gains */ - /*index = (Word16)get_indice( st_fx,"gain", i_subfr, ACELP_CORE);move16();*/ - index = (Word16) get_next_indice_fx( st_fx, nBits ); /*Q0*/ - move16(); - - *gain_pit_fx = cdbk_fx[index * 2]; /*Q14*/ - move16(); - - L_tmp = L_mult( cdbk_fx[( ( index * 2 ) + 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ - *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); /* Q10 -> Q16*/ - move16(); - - gc_mem[0] = *gain_code_fx; /*Q16*/ - move32(); - gp_mem[0] = *gain_pit_fx; /*Q14*/ - move16(); - } - ELSE IF( EQ_16( i_subfr, L_SUBFR ) || EQ_16( L_subfr, 2 * L_SUBFR ) ) - { - b_fx = b_2sfr_fx; /*Q12*/ - move16(); - n_pred = 4; - move16(); - - cdbk_fx = gp_gamma_1sfr_6b_fx; /*Q14/Q9 */ - SWITCH( nBits ) - { - case 7: - { - cdbk_fx = gp_gamma_2sfr_7b_fx; /* Q14/Q9*/ - BREAK; - } - case 6: - { - cdbk_fx = gp_gamma_2sfr_6b_fx; /* Q14/Q9*/ - BREAK; - } - } - - /* calculate predicted gain */ - aux_fx[0] = 4096; /*Q12*/ - move16(); - aux_fx[1] = shl( ctype, 12 ); /*Q12*/ - move16(); - - /*aux_fx[2] = (float)log10(gc_mem[0]); - = log2(gc_mem[0])*log10(2);*/ - e_tmp = norm_l( gc_mem[0] ); - f_tmp = Log2_norm_lc( L_shl( gc_mem[0], e_tmp ) ); /*Q15*/ - e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[0])=16*/ - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ - aux_fx[2] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ - move16(); - - aux_fx[3] = shr( gp_mem[0], 2 ); /*Q12*/ - move16(); - - /*-----------------------------------------------------------------* - * gcode0 = pow(10.0, dotp(b, aux, n_pred) - * = pow(2, 3.321928*dotp(b, aux, n_pred) - *-----------------------------------------------------------------*/ - L_tmp = Dot_product( b_fx, aux_fx, n_pred ); /*Q25*/ - L_tmp = Mult_32_16( L_tmp, 27213 ); /* *3.321928 in Q13 -> Q23 */ - L_tmp = L_shr( L_tmp, 7 ); /* From Q23 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ - - gcode0_fx = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub( exp_gcode0, 14 ); - - /* retrieve the codebook index and calculate both gains */ - index = (Word16) get_next_indice_fx( st_fx, nBits ); /*Q0*/ - move16(); - - *gain_pit_fx = cdbk_fx[index * 2]; /*Q14*/ - move16(); - - L_tmp = L_mult( cdbk_fx[( ( index * 2 ) + 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ - *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); /*Q16*/ - move16(); - - gc_mem[1] = *gain_code_fx; /*Q16*/ - move32(); - gp_mem[1] = *gain_pit_fx; /*Q14*/ - move16(); - } - ELSE IF( EQ_16( i_subfr, 2 * L_SUBFR ) ) - { - b_fx = b_3sfr_fx; - move16(); - n_pred = 6; - move16(); - - cdbk_fx = gp_gamma_3sfr_6b_fx; /*Q14/Q9 */ - - if ( EQ_16( nBits, 7 ) ) - { - cdbk_fx = gp_gamma_3sfr_7b_fx; /*Q14*/ - // PMT("verify if gp_gamma_3sfr_7b_fx is correct") - } - - /* calculate predicted gain */ - aux_fx[0] = 4096; /*Q12*/ - move16(); - aux_fx[1] = shl( ctype, 12 ); /*Q12*/ - move16(); - - /*aux_fx[2] = (float)log10(gc_mem[0]); - = log2(gc_mem[0])*log10(2);*/ - e_tmp = norm_l( gc_mem[0] ); - f_tmp = Log2_norm_lc( L_shl( gc_mem[0], e_tmp ) ); /*Q15*/ - e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[0])=16*/ - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ - aux_fx[2] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ - move16(); - - /*aux[3] = (float)log10(gc_mem[1]); - = log2(gc_mem[1])*log10(2);*/ - e_tmp = norm_l( gc_mem[1] ); - f_tmp = Log2_norm_lc( L_shl( gc_mem[1], e_tmp ) ); /*Q15*/ - e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[1])=16*/ - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ - aux_fx[3] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ - move16(); - - aux_fx[4] = shr( gp_mem[0], 2 ); /*Q12*/ - move16(); - aux_fx[5] = shr( gp_mem[1], 2 ); /*Q12*/ - move16(); - - /*-----------------------------------------------------------------* - * gcode0 = pow(10.0, dotp(b, aux, n_pred) - * = pow(2, 3.321928*dotp(b, aux, n_pred) - *-----------------------------------------------------------------*/ - L_tmp = Dot_product( b_fx, aux_fx, n_pred ); /*Q25*/ - L_tmp = Mult_32_16( L_tmp, 27213 ); /* *3.321928 in Q13 -> Q23 */ - L_tmp = L_shr( L_tmp, 7 ); /* From Q23 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ - - gcode0_fx = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub( exp_gcode0, 14 ); - - /* retrieve the codebook index and calculate both gains */ - index = (Word16) get_next_indice_fx( st_fx, nBits ); - move16(); - - *gain_pit_fx = cdbk_fx[( index * 2 )]; /*Q14*/ - move16(); - - L_tmp = L_mult( cdbk_fx[( ( index * 2 ) + 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ - *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); /* Q10 -> Q16*/ - move32(); - gc_mem[2] = *gain_code_fx; /*Q16*/ - move32(); - gp_mem[2] = *gain_pit_fx; /*Q14*/ - move16(); - } - ELSE IF( EQ_16( i_subfr, 3 * L_SUBFR ) ) - { - b_fx = b_4sfr_fx; /*Q12*/ - n_pred = 8; - move16(); - - - cdbk_fx = gp_gamma_4sfr_6b_fx; /*Q14*/ -#ifdef IVAS_GAIN_MOD - IF( EQ_16( nBits, 7 ) ) - { - cdbk_fx = gp_gamma_4sfr_7b_fx; - PMT( "verify if gp_gamma_4sfr_7b_fx is correct" ) - } -#endif - - /* calculate predicted gain */ - aux_fx[0] = 4096; /*Q12*/ - move16(); - aux_fx[1] = shl( ctype, 12 ); /*Q12*/ - move16(); - - /*aux[2] = (float)log10(gc_mem[0]); - = log2(gc_mem[0])*log10(2);*/ - e_tmp = norm_l( gc_mem[0] ); - f_tmp = Log2_norm_lc( L_shl( gc_mem[0], e_tmp ) ); /*Q15*/ - e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[0])=16*/ - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ - aux_fx[2] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ - move16(); - - /*aux[3] = (float)log10(gc_mem[1]); - = log2(gc_mem[1])*log10(2);*/ - e_tmp = norm_l( gc_mem[1] ); - f_tmp = Log2_norm_lc( L_shl( gc_mem[1], e_tmp ) ); /*Q15*/ - e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[1])=16*/ - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ - aux_fx[3] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ - move16(); - - /*aux[4] = (float)log10(gc_mem[2]); - = log2(gc_mem[2])*log10(2);*/ - e_tmp = norm_l( gc_mem[2] ); - f_tmp = Log2_norm_lc( L_shl( gc_mem[2], e_tmp ) ); /*Q15*/ - e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[2])=16*/ - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ - aux_fx[4] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ - move16(); - - aux_fx[5] = shr( gp_mem[0], 2 ); /*Q12*/ - move16(); - aux_fx[6] = shr( gp_mem[1], 2 ); /*Q12*/ - move16(); - aux_fx[7] = shr( gp_mem[2], 2 ); /*Q12*/ - move16(); - - /*-----------------------------------------------------------------* - * gcode0 = pow(10.0, dotp(b, aux, n_pred) - * = pow(2, 3.321928*dotp(b, aux, n_pred) - *-----------------------------------------------------------------*/ - L_tmp = Dot_product( b_fx, aux_fx, n_pred ); /*Q25*/ - L_tmp = Mult_32_16( L_tmp, 27213 ); /* *3.321928 in Q13 -> Q23 */ - L_tmp = L_shr( L_tmp, 7 ); /* From Q23 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ - - gcode0_fx = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub( exp_gcode0, 14 ); - - /* retrieve the codebook index and calculate both gains */ - index = (Word16) get_next_indice_fx( st_fx, nBits ); /*Q0*/ - move16(); - *gain_pit_fx = cdbk_fx[( index * 2 )]; /*Q14*/ - move16(); - - L_tmp = L_mult( cdbk_fx[( ( index * 2 ) + 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ - *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); /*Q16*/ - move32(); - } - - /* *norm_gain_code = *gain_code / *gain_inov; */ - expg = sub( norm_s( *gain_inov_fx ), 1 ); - expg = s_max( expg, 0 ); - - tmp_fx = div_s( shr( 8192, expg ), *gain_inov_fx ); /*Q15*/ - *norm_gain_code_fx = L_shr( Mult_32_16( *gain_code_fx, tmp_fx ), sub( 1, expg ) ); /*Q16*/ - move32(); - - return; -} -#endif -void gain_dec_lbr_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 *code_fx, /* i : algebraic excitation Q9 */ - Word16 *gain_pit_fx, /* o : quantized pitch gain Q14*/ - Word32 *gain_code_fx, /* o : quantized codebook gain Q16*/ - Word16 *gain_inov_fx, /* o : gain of the innovation (used for normalization) Q12*/ - Word32 *norm_gain_code_fx, /* o : norm. gain of the codebook excitation Q16*/ - Word32 gc_mem[], /* i/o: gain_code from previous subframes Q16*/ - Word16 gp_mem[], /* i/o: gain_pitch from previous subframes Q14*/ - const Word16 L_subfr /* i : subfr lenght */ -) -{ - Word16 index, nBits, n_pred, ctype; - Word16 gcode0_fx, aux_fx[10]; - Word32 L_tmp, L_tmp1, L_tmp2; - Word16 expg, expg2, e_tmp, exp_gcode0, f_tmp, frac, tmp_fx; - const Word16 *b_fx, *cdbk_fx = 0; - /* Ecode = ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR; - *gain_inov = 1.0f / (float)sqrt(Ecode); */ - Word16 shift_L_subfr; - shift_L_subfr = 6; - move16(); // for *cdbk_fx - move16(); - if ( GT_16( L_subfr, L_SUBFR ) ) - { - shift_L_subfr = add( shift_L_subfr, 1 ); - } - L_tmp = Dot_product12( code_fx, code_fx, L_subfr, &expg ); /*Q31 - expg*/ - expg = sub( expg, add( 18, shift_L_subfr ) ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ - - expg2 = expg; - move16(); - L_tmp2 = L_tmp; /* sets to 'L_tmp' in 1 clock */ - move32(); - L_tmp = Isqrt_lc( L_tmp, &expg ); /*Q31 - expg*/ - - *gain_inov_fx = extract_h( L_shl_sat( L_tmp, sub( expg, 3 ) ) ); /* gain_inov in Q12 */ - move16(); - - /*-----------------------------------------------------------------* - * select the codebook, size and number of bits - * set the gains searching range - *-----------------------------------------------------------------*/ - nBits = st_fx->acelp_cfg.gains_mode[shr( i_subfr, shift_L_subfr )]; - move16(); - - ctype = shl( sub( coder_type, 1 ), 1 ); - /*-----------------------------------------------------------------* * calculate prediction of gcode * search for the best codeword @@ -1583,24 +1213,28 @@ void lp_gain_updt_ivas_fx( } /*-------------------------------------------------* - * Gain_dec_gaus_vbr + * gain_dec_gaus_fx() * * Decode gains of purely unvoiced sounds *-------------------------------------------------*/ -Word32 gain_dec_gaus_fx( /* o : quantized codebook gain Q16 */ - Word16 index, /* i : quantization index */ - const Word16 bits, /* i : number of bits to quantize */ - const Word16 lowBound, /* i : lower bound of quantizer (dB) */ - const Word16 topBound, /* i : upper bound of quantizer (dB) */ - const Word16 inv_gain_inov, /* o : unscaled innovation gain Q12 */ - Word32 *L_norm_gain_code /* o : gain of normalized gaussian excitation Q16 */ + +/*! r: quantized codebook gain Q16 */ +Word32 gain_dec_gaus_fx( + Word16 index, /* i : quantization index */ + const Word16 bits, /* i : number of bits to quantize */ + const Word16 lowBound, /* i : lower bound of quantizer (dB) */ + const Word16 topBound, /* i : upper bound of quantizer (dB) */ + const Word16 inv_gain_inov, /* o : unscaled innovation gain Q12 */ + Word32 *L_norm_gain_code /* o : gain of normalized gaussian excitation Q16 */ ) { Word16 stepSize, gain, expg, frac, expi, tmp_igi; Word32 L_tmp, L_enr_q, L_gain; Word16 stepSize_Exp; + stepSize_Exp = 14; move16(); + /*------------------------------------------------------------------------------------------* * Quantize linearly the log E *------------------------------------------------------------------------------------------*/ diff --git a/lib_dec/gs_dec_fx.c b/lib_dec/gs_dec_fx.c index cf0fabc76..70639810c 100644 --- a/lib_dec/gs_dec_fx.c +++ b/lib_dec/gs_dec_fx.c @@ -23,7 +23,7 @@ /* _ (Word16[]) voice_factors_fx: frame error rate Q15 */ /*--------------------------------------------------------------------------*/ /* INPUT/OUTPUT ARGUMENTS : */ -/* Decoder_State *st_fx : decoder memory structure */ +/* Decoder_State *st_fx : decoder memory structure */ /* _ (Word16[]) exc_fx : adapt. excitation exc (Q_exc) */ /* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q_exc) */ /*--------------------------------------------------------------------------*/ @@ -31,439 +31,17 @@ /* _ None */ /*==========================================================================*/ -#ifndef REMOVE_EVS_DUPLICATES void decod_audio_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - Word16 dct_epit[], /* o : GSC excitation in DCT domain Qx*/ - const Word16 *Aq, /* i : LP filter coefficient Q12*/ - Word16 *pitch_buf, /* o : floating pitch values for each subframe Q6*/ - Word16 *voice_factors, /* o : voicing factors Q15*/ - Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ - Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ - Word16 *lsf_new /* i : ISFs at the end of the frame Qx*/ - , - Word16 *gain_buf /*Q14*/ -) -{ - Word16 tmp_nb_bits_tot, pit_band_idx; - Word16 code[4 * L_SUBFR]; - Word16 Diff_len, nb_subfr, i; - Word16 nb_frame_flg; - Word16 Es_pred = 0; - Word16 Len, max_len; - Word16 gsc_attack_flag; - - Word16 low_pit; - Word16 last_bin; - Word16 nbits; - - Word16 exc_wo_nf[L_FRAME16k]; - GSC_DEC_HANDLE hGSCDec; - hGSCDec = st_fx->hGSCDec; - - - /*---------------------------------------------------------------* - * Initialization - *---------------------------------------------------------------*/ - move16(); // corresponding to initialization of Es_pred - Diff_len = 0; - move16(); - - /* decode GSC attack flag (used to reduce possible pre-echo) */ - gsc_attack_flag = (Word16) get_next_indice_fx( st_fx, 1 ); /* Q0 */ - move16(); - - /* decode GSC SWB speech flag */ - test(); - IF( st_fx->coder_type != INACTIVE && GE_32( st_fx->total_brate, ACELP_13k20 ) ) - { - st_fx->GSC_noisy_speech = (Word16) get_next_indice_fx( st_fx, 1 ); /* Q0 */ - move16(); - } - - /* safety check in case of bit errors */ - test(); - test(); - IF( st_fx->GSC_noisy_speech && LT_16( st_fx->bwidth, SWB ) && st_fx->GSC_IVAS_mode == 0 ) - { - st_fx->BER_detect = 1; /* Q0 */ - move16(); - st_fx->GSC_noisy_speech = 0; /* Q0 */ - move16(); - } - - /* set bit-allocation */ -#ifdef REMOVE_EVS_DUPLICATES - config_acelp1_IVAS( DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, st_fx->coder_type, st_fx->inactive_coder_type_flag, -1, 1, &nbits, NULL, st_fx->element_mode, &nbits /*dummy*/, 0, 0, st_fx->idchan, st_fx->active_cnt, 0, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); -#else - config_acelp1( DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, st_fx->coder_type, st_fx->inactive_coder_type_flag, -1, 1, &nbits, NULL, st_fx->element_mode, &nbits /*dummy*/, 0, 0, st_fx->idchan, st_fx->active_cnt, 0, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); -#endif - - /*---------------------------------------------------------------* - * Decode energy dynamics - *---------------------------------------------------------------*/ - - IF( EQ_16( st_fx->GSC_noisy_speech, 1 ) ) - { - nb_subfr = NB_SUBFR; /* Q0 */ - move16(); - hGSCDec->cor_strong_limit = 0; - move16(); - hGSCDec->noise_lev = NOISE_LEVEL_SP3; /* Q0 */ - move16(); - } - ELSE - { - IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) - { - hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 2 ), NOISE_LEVEL_SP2 ); /* Q0 */ - move16(); - } - ELSE - { - hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 3 ), NOISE_LEVEL_SP0 ); /* Q0 */ - move16(); - } - - /*---------------------------------------------------------------* - * Decode number of subframes - *---------------------------------------------------------------*/ - - - hGSCDec->cor_strong_limit = 1; /* Q0 */ - move16(); - nb_subfr = SWNB_SUBFR; - move16(); - - IF( GE_32( st_fx->core_brate, ACELP_9k60 ) ) - { - nbits = 1; - move16(); - nb_frame_flg = (Word16) get_next_indice_fx( st_fx, nbits ); /* Q0 */ - move16(); - - IF( s_and( nb_frame_flg, 0x1 ) == 0 ) - { - nb_subfr = 2 * SWNB_SUBFR; /* Q0 */ - move16(); - hGSCDec->cor_strong_limit = 0; - move16(); - } - } - } - - /*---------------------------------------------------------------* - * Decode the last band where the adaptive (pitch) contribution is significant - *---------------------------------------------------------------*/ - - IF( LT_32( st_fx->core_brate, CFREQ_BITRATE ) ) - { - nbits = 3; /* Q0 */ - move16(); - test(); - if ( LT_32( st_fx->core_brate, ACELP_9k60 ) && st_fx->coder_type == INACTIVE ) - { - nbits = 1; /* Q0 */ - move16(); - } - } - ELSE - { - nbits = 4; /* Q0 */ - move16(); - } - test(); - IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && st_fx->coder_type != INACTIVE ) - { - pit_band_idx = 1; /* Q0 */ - move16(); - } - ELSE - { - pit_band_idx = (Word16) get_next_indice_fx( st_fx, nbits ); /* Q0 */ - move16(); - } - - IF( pit_band_idx != 0 ) - { - IF( LT_32( st_fx->core_brate, ACELP_9k60 ) ) - { - pit_band_idx = 7 + BAND1k2; /* Q0 */ - move16(); /* At low rate, if pitch model is chosen, then for to be use on extented and constant frequency range */ - } - ELSE - { - pit_band_idx = add( pit_band_idx, BAND1k2 ); /* Q0 */ - } - - /* detect bit errors in the bitstream */ - IF( GT_16( pit_band_idx, 13 ) ) /* The maximum decodable index is 10 + BAND1k2 (3) = 13 */ - { - pit_band_idx = 13; /* Q0 */ - move16(); - st_fx->BER_detect = 1; /* Q0 */ - move16(); - } - Diff_len = mfreq_loc_div_25[pit_band_idx]; /* Q0 */ - move16(); - } - hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; /* Q0 */ - move16(); - - - /*--------------------------------------------------------------------------------------* - * Decode adaptive (pitch) excitation contribution - * Reset unvaluable part of the adaptive (pitch) excitation contribution - *--------------------------------------------------------------------------------------*/ - IF( GT_16( pit_band_idx, BAND1k2 ) ) - { - /*---------------------------------------------------------------* - * Decode adaptive (pitch) excitation contribution - *---------------------------------------------------------------*/ - test(); - IF( EQ_16( st_fx->GSC_noisy_speech, 1 ) && EQ_16( nb_subfr, NB_SUBFR ) ) - { - Word16 indice; - nbits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx( st_fx->core_brate, GENERIC, -1, -1 )]; /* Q0 */ - move16(); - if ( st_fx->element_mode > EVS_MONO ) - { - nbits = 5; - move16(); - } - - indice = get_next_indice_fx( st_fx, nbits ); /* Q0 */ - - Es_pred_dec_fx( &Es_pred, indice, nbits, 0 ); - } - - dec_pit_exc_fx( st_fx, Aq, st_fx->coder_type, Es_pred, pitch_buf, code, exc, bwe_exc, nb_subfr, gain_buf ); - - IF( LT_32( st_fx->core_brate, ACELP_9k60 ) ) - { - minimum_fx( pitch_buf, shr( st_fx->L_frame, 6 ), &low_pit ); - low_pit = shr( low_pit, 6 ); /*Q6 -> Q0 */ - - IF( LT_16( low_pit, 64 ) ) - { - pit_band_idx = 9 + BAND1k2; /* Q0 */ - move16(); - if ( st_fx->bwidth == NB ) - { - pit_band_idx = 7 + BAND1k2; /* Q0 */ - move16(); - } - } - ELSE IF( LT_16( low_pit, 128 ) ) - { - pit_band_idx = 5 + BAND1k2; /* Q0 */ - move16(); - } - ELSE - { - pit_band_idx = 3 + BAND1k2; /* Q0 */ - move16(); - } - - Diff_len = mfreq_loc_div_25[pit_band_idx]; /* Q0 */ - move16(); - hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; /* Q0 */ - move16(); - } - - /*---------------------------------------------------------------* - * DCT transform - *---------------------------------------------------------------*/ - edct_16fx( exc, dct_epit, st_fx->L_frame, 7, st_fx->element_mode ); - - /*---------------------------------------------------------------* - * Reset unvaluable part of the adaptive (pitch) excitation contribution - *---------------------------------------------------------------*/ - - max_len = sub( st_fx->L_frame, Diff_len ); /* Q0 */ - - if ( st_fx->bwidth == NB ) - { - max_len = sub( 160, Diff_len ); /* Q0 */ - } - - Len = 80; - move16(); - if ( LT_16( max_len, 80 ) ) - { - Len = max_len; /* Q0 */ - move16(); - } - - test(); - IF( EQ_32( st_fx->core_brate, ACELP_8k00 ) && NE_16( st_fx->bwidth, NB ) ) - { - FOR( i = 0; i < max_len; i++ ) - { - dct_epit[i + Diff_len] = 0; - move16(); - } - } - ELSE - { - FOR( i = 0; i < Len; i++ ) - { - dct_epit[i + Diff_len] = mult_r( dct_epit[i + Diff_len], sm_table_fx[i] ); /* Qx */ - move16(); - } - - FOR( ; i < max_len; i++ ) - { - dct_epit[i + Diff_len] = 0; - move16(); - } - } - // PMT("in the rare case of 4 subfr, bfi_pitch_fx might be wrong") - st_fx->bfi_pitch_fx = mean_fx( pitch_buf, nb_subfr ); /* Q6 */ - move16(); - st_fx->bfi_pitch_frame = st_fx->L_frame; /* Q0 */ - move16(); - - Diff_len = add( Diff_len, 1 ); /* Q0 */ - st_fx->bpf_off = 0; - move16(); - } - ELSE - { - /* No adaptive (pitch) excitation contribution */ - st_fx->bpf_off = 1; /* Q0 */ - move16(); - set16_fx( dct_epit, 0, st_fx->L_frame ); - - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - set16_fx( pitch_buf, L_SUBFR16k * 64, NB_SUBFR16k ); - } - ELSE - { - set16_fx( pitch_buf, L_SUBFR * 64, NB_SUBFR ); - } - - set16_fx( gain_buf, 0, NB_SUBFR16k ); - - st_fx->bfi_pitch_fx = L_SUBFR * 64; - move16(); - st_fx->bfi_pitch_frame = st_fx->L_frame; /* Q0 */ - move16(); - st_fx->lp_gainp_fx = 0; - move16(); - st_fx->lp_gainc_fx = 0; - move16(); - st_fx->tilt_code_fx = 0; - move16(); - pit_band_idx = 0; - move16(); - Diff_len = 0; - move16(); - } - - /*--------------------------------------------------------------------------------------* - * GSC decoder - *--------------------------------------------------------------------------------------*/ - - /* find the current total number of bits used */ - - tmp_nb_bits_tot = st_fx->next_bit_pos; /* Q0 */ - move16(); - - if ( st_fx->extl_brate > 0 ) - { - /* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */ - tmp_nb_bits_tot = sub( tmp_nb_bits_tot, 1 ); /* Q0 */ - } - - test(); - if ( st_fx->coder_type == INACTIVE && LE_32( st_fx->core_brate, ACELP_9k60 ) ) - { - tmp_nb_bits_tot = add( tmp_nb_bits_tot, 5 ); /* Q0 */ - } - - gsc_dec_fx( st_fx, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st_fx->coder_type, &last_bin, lsf_new, exc_wo_nf, st_fx->Q_exc ); - /*--------------------------------------------------------------------------------------* - * iDCT transform - *--------------------------------------------------------------------------------------*/ - - edct_16fx( dct_epit, exc, st_fx->L_frame, 7, st_fx->element_mode ); - edct_16fx( exc_wo_nf, exc_wo_nf, st_fx->L_frame, 7, st_fx->element_mode ); - /*----------------------------------------------------------------------* - * Remove potential pre-echo in case an onset has been detected - *----------------------------------------------------------------------*/ - - pre_echo_att_fx( &hGSCDec->Last_frame_ener_fx, exc, gsc_attack_flag, st_fx->Q_exc, st_fx->last_coder_type, st_fx->L_frame ); - - /*--------------------------------------------------------------------------------------* - * Update BWE excitation - *--------------------------------------------------------------------------------------*/ - - IF( st_fx->hBWE_TD != NULL ) - { - set16_fx( voice_factors, 0, NB_SUBFR16k ); - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - interp_code_4over2_fx( exc, bwe_exc, st_fx->L_frame ); - } - ELSE - { - interp_code_5over2_fx( exc, bwe_exc, L_FRAME ); - } - } - /*--------------------------------------------------------------------------------------* - * Updates - *--------------------------------------------------------------------------------------*/ - - Copy( exc, exc2, st_fx->L_frame ); /* Q_exc */ - Copy( exc_wo_nf, exc, st_fx->L_frame ); /* Q_exc */ - - /*--------------------------------------------------------------------------------------* - * Channel aware mode parameters - *--------------------------------------------------------------------------------------*/ - - set16_fx( st_fx->tilt_code_dec_fx, 0, NB_SUBFR16k ); - - return; -} - -/*=========================================================================*/ -/* FUNCTION : void decod_audio_ivas_fx(); */ -/*-------------------------------------------------------------------------*/ -/* PURPOSE : Decode audio (AC) frames */ -/*-------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16[]) Aq : LP filter coefficient Q12 */ -/* _ (Word16) coder_type : coding type Q0 */ -/* _(Word16) Q_exc :Q format of excitation */ -/*-------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) pitch_buf_fx : Word16 pitch values for each subframe Q6*/ -/* _ (Word16[]) voice_factors_fx: frame error rate Q15 */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* Decoder_State *st_fx : decoder memory structure */ -/* _ (Word16[]) exc_fx : adapt. excitation exc (Q_exc) */ -/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q_exc) */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*==========================================================================*/ -#endif -void decod_audio_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - Word16 dct_epit[], /* o : GSC excitation in DCT domain Qx*/ - const Word16 *Aq, /* i : LP filter coefficient Q12*/ - Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ - Word16 *voice_factors, /* o : voicing factors Q15*/ - Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ - Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ - Word16 *lsf_new /* i : ISFs at the end of the frame Qx*/ - , - Word16 *gain_buf, /*Q14*/ + Decoder_State *st_fx, /* i/o: decoder static memory */ + Word16 dct_epit[], /* o : GSC excitation in DCT domain Qx*/ + const Word16 *Aq, /* i : LP filter coefficient Q12*/ + Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ + Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ const Word16 tdm_lp_reuse_flag, /* i : LPC reuse flag Q0*/ const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag Q0*/ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ @@ -525,7 +103,7 @@ void decod_audio_ivas_fx( } /* set bit-allocation */ - config_acelp1_IVAS( DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, st_fx->coder_type, st_fx->inactive_coder_type_flag, -1, 1, &nbits, NULL, st_fx->element_mode, &nbits /*dummy*/, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_cnt, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); + config_acelp1_fx( DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, st_fx->coder_type, st_fx->inactive_coder_type_flag, -1, 1, &nbits, NULL, st_fx->element_mode, &nbits /*dummy*/, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_cnt, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); /*---------------------------------------------------------------* * Decode energy dynamics @@ -735,7 +313,7 @@ void decod_audio_ivas_fx( Es_pred_dec_fx( &Es_pred, indice, nbits, 0 ); } - dec_pit_exc_ivas_fx( st_fx, Aq, st_fx->coder_type, Es_pred, pitch_buf, code, exc, bwe_exc, nb_subfr, gain_buf, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + dec_pit_exc_fx( st_fx, Aq, st_fx->coder_type, Es_pred, pitch_buf, code, exc, bwe_exc, nb_subfr, gain_buf, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); IF( LT_32( st_fx->core_brate, ACELP_9k60 ) ) { @@ -894,7 +472,7 @@ void decod_audio_ivas_fx( Word16 Q_exc_old = st_fx->Q_exc; move16(); - gsc_dec_ivas_fx( st_fx, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st_fx->coder_type, &last_bin, lsf_new, exc_wo_nf, &st_fx->Q_exc ); + gsc_dec_fx( st_fx, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st_fx->coder_type, &last_bin, lsf_new, exc_wo_nf, &st_fx->Q_exc ); IF( NE_16( Q_exc_old, st_fx->Q_exc ) ) { @@ -976,250 +554,17 @@ void decod_audio_ivas_fx( /* _None */ /*==========================================================================*/ -#ifndef REMOVE_EVS_DUPLICATES void gsc_dec_fx( - Decoder_State *st_fx, /* i/o: State structure */ - Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation Q_exc*/ - const Word16 pit_band_idx, /* i : bin position of the cut-off frequency Q0*/ - const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral) Q0*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q Q0*/ - const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ - const Word16 coder_type, /* i : coding type Q0*/ - Word16 *last_bin, /* i : last bin of bit allocation Q0*/ - const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ - Word16 Q_exc ) -{ - Word16 i, j, bit, nb_subbands, pvq_len; - Word16 bitallocation_band[MBANDS_GN_BITALLOC16k]; - Word16 bitallocation_exc[2]; - Word16 Ener_per_bd_iQ[MBANDS_GN_BITALLOC16k]; - Word16 max_ener_band[MBANDS_GN_BITALLOC16k]; - Word16 exc_diffQ[L_FRAME16k]; - Word16 bits_per_bands[MBANDS_GN_BITALLOC16k]; - Word16 concat_out[L_FRAME16k]; - Word16 inpulses_fx[NB_SFM]; - Word16 imaxpulse_fx[NB_SFM]; - Word16 mean_gain; - Word16 Mbands_gn = 16; - Word16 Qexc_diffQ = Q_PVQ_OUT; - Word32 L_tmp; - Word16 Q_tmp; - Word16 seed_init; - GSC_DEC_HANDLE hGSCDec; - hGSCDec = st_fx->hGSCDec; - move16(); - move16(); - - move16(); // for Mbands_gn - move16(); // for Qexc_diffQ - set16_fx( inpulses_fx, 0, NB_SFM ); - set16_fx( imaxpulse_fx, 0, NB_SFM ); - - /*--------------------------------------------------------------------------------------* - * Initialization - *--------------------------------------------------------------------------------------*/ - bit = bits_used; - move16(); - - set16_fx( exc_diffQ, 0, st_fx->L_frame ); - - /*--------------------------------------------------------------------------------------* - * Gain decoding - *--------------------------------------------------------------------------------------*/ - - test(); - IF( st_fx->bfi || st_fx->BER_detect ) - { - /* copy old gain */ - Copy( hGSCDec->old_y_gain_fx, Ener_per_bd_iQ, Mbands_gn ); /* Q_old_gain */ - mean_gain = mult_r( st_fx->lp_gainc_fx, 3277 ); /*Q3*/ - FOR( i = 0; i < Mbands_gn; i++ ) - { - Ener_per_bd_iQ[i] = add( Ener_per_bd_iQ[i], shl( mean_gain, 9 ) ); /*Q12*/ - move16(); - } - - st_fx->lp_gainc_fx = mult_r( st_fx->lp_gainc_fx, 32112 ); /*Q3*/ - move16(); - } - ELSE - { - mean_gain = gsc_gaindec_fx( st_fx, Ener_per_bd_iQ, st_fx->core_brate, hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); /* Q12 */ - - st_fx->lp_gainc_fx = mult_r( 640, mean_gain ); /*10 in Q6 x Q12 -> lp_gainc in Q3 */ - move16(); - } - - *last_bin = 0; - move16(); - test(); - IF( EQ_32( st_fx->core_brate, ACELP_8k00 ) && st_fx->bwidth != NB ) - { - bitallocation_exc[0] = 0; - move16(); - bitallocation_exc[1] = 0; - move16(); - } - - set16_fx( bitallocation_band, 0, MBANDS_GN ); - - test(); - IF( ( EQ_16( st_fx->bfi, 1 ) ) || st_fx->BER_detect ) - { - /*--------------------------------------------------------------------------------------* - * Copy old spectrum - * reduce spectral dynamic - * save spectrum - *--------------------------------------------------------------------------------------*/ - - test(); - IF( EQ_16( st_fx->last_good, INACTIVE_CLAS ) || EQ_16( st_fx->Last_GSC_noisy_speech_flag, 1 ) ) - { - FOR( i = 0; i < st_fx->L_frame; i++ ) - { - L_tmp = L_shr( L_mult( Random( &hGSCDec->seed_tcx ), 26214 ), 5 ); /*Q10*/ - L_tmp = L_mac( L_tmp, hGSCDec->Last_GSC_spectrum_fx[i], 6554 ); /* Q10 */ - hGSCDec->Last_GSC_spectrum_fx[i] = round_fx( L_tmp ); /*Q10*/ - move16(); - } - } - - Copy( hGSCDec->Last_GSC_spectrum_fx, exc_diffQ, st_fx->L_frame ); /* Q10 */ - - FOR( i = 0; i < st_fx->L_frame; i++ ) - { - hGSCDec->Last_GSC_spectrum_fx[i] = mult_r( hGSCDec->Last_GSC_spectrum_fx[i], 24576 ); /*Q10*/ - move16(); - } - } - ELSE - { - /*--------------------------------------------------------------------------------------* - * PVQ decoder - *--------------------------------------------------------------------------------------*/ - - bands_and_bit_alloc_fx( hGSCDec->cor_strong_limit, hGSCDec->noise_lev, st_fx->core_brate, Diff_len, bit, &bit, Ener_per_bd_iQ, - max_ener_band, bits_per_bands, &nb_subbands, NULL, NULL, &pvq_len, coder_type, st_fx->bwidth, st_fx->GSC_noisy_speech, - st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); - - { - pvq_core_dec_fx( st_fx, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, concat_out, &Q_tmp, bit, nb_subbands, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE ); - Scale_sig( concat_out, gsc_sfm_end[nb_subbands - 1], sub( Q_PVQ_OUT, Q_tmp ) ); /* Q_PVQ_OUT */ - } - seed_init = 0; - move16(); - - /* Reorder Q bands */ - FOR( j = 0; j < nb_subbands; j++ ) - { - Copy( concat_out + shl( j, 4 ), exc_diffQ + shl( max_ener_band[j], 4 ), 16 ); /* Q_PVQ_OUT */ - - *last_bin = s_max( *last_bin, max_ener_band[j] ); /* Q0 */ - move16(); - - bitallocation_band[max_ener_band[j]] = 1; /* Q0 */ - move16(); - - seed_init = add( seed_init, inpulses_fx[j] ); /* Q0 */ - } - test(); - IF( NE_16( st_fx->last_coder_type, AUDIO ) /* First audio frame */ - && NE_16( st_fx->last_coder_type, UNVOICED ) ) /* last_coder_type == INACTIVE is overwritten in update_dec to UNVOICED */ - { - FOR( j = 0; j < nb_subbands * 16; j++ ) - { - IF( concat_out[j] > 0 ) - { - seed_init = extract_l( L_shl( seed_init, 3 ) ); /* Q0 */ - } - if ( concat_out[j] < 0 ) - { - seed_init = add( seed_init, 3 ); /* Q0 */ - move16(); - } - } - - hGSCDec->seed_tcx = seed_init; /* Q0 */ - move16(); - } - test(); - IF( EQ_32( st_fx->core_brate, ACELP_8k00 ) && st_fx->bwidth != NB ) - { - if ( exc_diffQ[L_FRAME8k - 2] != 0 ) - { - bitallocation_exc[0] = 1; /* Q0 */ - move16(); - } - - if ( exc_diffQ[L_FRAME8k - 1] != 0 ) - { - bitallocation_exc[1] = 1; /* Q0 */ - move16(); - } - } - - Copy( exc_diffQ, hGSCDec->Last_GSC_spectrum_fx, st_fx->L_frame ); /* Q_PVQ_OUT */ - - /*--------------------------------------------------------------------------------------* - * Skip adaptive (pitch) contribution frequency band (no noise added over the time contribution) - * Find x pulses between 1.6-3.2kHz to code in the spectrum of the residual signal - * Gain is based on the inter-correlation gain between the pulses found and residual signal - *--------------------------------------------------------------------------------------*/ - - freq_dnw_scaling_fx( hGSCDec->cor_strong_limit, st_fx->coder_type, hGSCDec->noise_lev, st_fx->core_brate, exc_diffQ, Qexc_diffQ, st_fx->L_frame ); - } - - /*--------------------------------------------------------------------------------------* - * Estimate noise level - *--------------------------------------------------------------------------------------*/ - - highband_exc_dct_in_fx( st_fx->core_brate, mfreq_bindiv_loc, *last_bin, Diff_len, hGSCDec->noise_lev, pit_band_idx, exc_diffQ, - &hGSCDec->seed_tcx, Ener_per_bd_iQ, nb_subfr, exc_dct_in, st_fx->last_coder_type, bitallocation_band, lsf_new, - hGSCDec->last_exc_dct_in_fx, &hGSCDec->last_ener_fx, hGSCDec->last_bitallocation_band, bitallocation_exc, st_fx->bfi, coder_type, - st_fx->bwidth, exc_wo_nf, Qexc_diffQ, Q_exc, st_fx->GSC_noisy_speech, hGSCDec->lt_ener_per_band_fx, st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); - - exc_dct_in[0] = 0; - move16(); - - return; -} - -/*==========================================================================*/ -/* FUNCTION : void gsc_dec_ivas_fx () */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : Generic audio signal decoder */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) pit_band_idx : bin position of the cut-off frequency Q0 */ -/* _ (Word16) Diff_len : Lenght of the difference signal Q0 */ -/* _ (Word16) coder_type : coding type Q0 */ -/* _ (Word16) bits_used : Number of bit used before frequency Q Q0 */ -/* _ (Word16) nb_subfr : Number of subframe considered Q0 */ -/* _ (Word16) Qexc : Q format of exc_dct_in */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* Decoder_State *st_fx:Decoder State Structure */ -/* _ (Word16[]) exc_dct_in : dctof pitch-only excitation / total excitation Qexc*/ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _None */ -/*==========================================================================*/ -#endif -void gsc_dec_ivas_fx( - Decoder_State *st_fx, /* i/o: State structure */ - Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation Q_exc*/ + Decoder_State *st_fx, /* i/o: State structure */ + Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation Q_exc*/ const Word16 pit_band_idx, /* i : bin position of the cut-off frequency ` Q0*/ const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral) Q0*/ const Word16 bits_used, /* i : Number of bit used before frequency Q Q0*/ const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ const Word16 coder_type, /* i : coding type Q0*/ Word16 *last_bin, /* i : last bin of bit allocation Q0*/ - const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ + const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ + Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ Word16 *Q_exc ) { Word16 i, j, bit, nb_subbands, pvq_len; @@ -1310,13 +655,11 @@ void gsc_dec_ivas_fx( i--; } -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { mean_gain = gsc_gaindec_fx( st_fx, Ener_per_bd_iQ, brate_intermed_tbl[i], hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); /* Q3 */ } ELSE -#endif { mean_gain = gsc_gaindec_ivas_fx( st_fx, Ener_per_bd_iQ, brate_intermed_tbl[i], hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); /* Q3 */ } diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index 03f0e4b40..cfbc1581a 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -520,7 +520,7 @@ ivas_error ivas_core_dec_fx( Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, add( M, 1 ), sub( norm_s( sub( st->hFdCngDec->hFdCngCom->A_cng[0], 1 ) ), 3 ) ); // Qx } - IF( NE_32( ( error = acelp_core_dec_ivas_fx( st, output_16_fx[n], synth_16_fx[n], save_hb_synth_16_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx_16, sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hStereoCng, read_sid_info ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = acelp_core_dec_fx( st, output_16_fx[n], synth_16_fx[n], save_hb_synth_16_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx_16, sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hStereoCng, read_sid_info ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_dec/ivas_dirac_dec_fx.c b/lib_dec/ivas_dirac_dec_fx.c index 10b8059b9..9c319489e 100644 --- a/lib_dec/ivas_dirac_dec_fx.c +++ b/lib_dec/ivas_dirac_dec_fx.c @@ -2186,7 +2186,7 @@ void ivas_dirac_dec_render_sf_fx( move16(); - FOR( Word16 i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) + FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { FOR( Word16 j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { @@ -2195,7 +2195,7 @@ void ivas_dirac_dec_render_sf_fx( } } - FOR( Word16 i = 0; i < BINAURAL_CHANNELS; i++ ) + FOR( i = 0; i < BINAURAL_CHANNELS; i++ ) { FOR( Word16 j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { diff --git a/lib_dec/ivas_stereo_mdct_core_dec_fx.c b/lib_dec/ivas_stereo_mdct_core_dec_fx.c index 890e5fc9e..89cb92a4d 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec_fx.c +++ b/lib_dec/ivas_stereo_mdct_core_dec_fx.c @@ -1097,8 +1097,8 @@ static void run_min_stats_fx( { arr_tmp = power_spec; } - ApplyFdCng_ivas_fx( NULL, 0, arr_tmp, power_spec_q, NULL, NULL, NULL, st, st->bfi, 0 ); - /*=================================================*/ + + ApplyFdCng_fx( NULL, 0, arr_tmp, power_spec_q, NULL, NULL, NULL, st, st->bfi, 0 ); } /* restore VAD (see above) */ diff --git a/lib_dec/ivas_tcx_core_dec_fx.c b/lib_dec/ivas_tcx_core_dec_fx.c index aa5a379e8..0be01f7b8 100644 --- a/lib_dec/ivas_tcx_core_dec_fx.c +++ b/lib_dec/ivas_tcx_core_dec_fx.c @@ -875,11 +875,11 @@ void stereo_tcx_core_dec_fx( { Word16 buffer[L_FRAME16k]; lerp( signal_outFB_fx, buffer, st->L_frame, hTcxDec->L_frameTCX ); - ApplyFdCng_ivas_fx( buffer, 0 /* Q of buffer */, NULL, 0, NULL, NULL, NULL, st, st->bfi, 0 ); + ApplyFdCng_fx( buffer, 0 /* Q of buffer */, NULL, 0, NULL, NULL, NULL, st, st->bfi, 0 ); } ELSE { - ApplyFdCng_ivas_fx( signal_out_fx, 0, NULL, 0, NULL, NULL, NULL, st, st->bfi, 0 ); + ApplyFdCng_fx( signal_out_fx, 0, NULL, 0, NULL, NULL, NULL, st, st->bfi, 0 ); } } @@ -915,7 +915,7 @@ void stereo_tcx_core_dec_fx( test(); IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && st->idchan == 0 ) { - ApplyFdCng_ivas_fx( signal_out_fx, 0, NULL, 0, NULL, NULL, NULL, st, st->bfi, 0 ); + ApplyFdCng_fx( signal_out_fx, 0, NULL, 0, NULL, NULL, NULL, st, st->bfi, 0 ); } } @@ -923,6 +923,7 @@ void stereo_tcx_core_dec_fx( return; } + static void stereo_tcx_dec_mode_switch_reconf_ivas_fx( Decoder_State *st, /* i/o: decoder state structure */ const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ diff --git a/lib_dec/ivas_td_low_rate_dec_fx.c b/lib_dec/ivas_td_low_rate_dec_fx.c index 3191a8b4a..8f09c1c7d 100644 --- a/lib_dec/ivas_td_low_rate_dec_fx.c +++ b/lib_dec/ivas_td_low_rate_dec_fx.c @@ -127,7 +127,7 @@ void tdm_low_rate_dec_fx( tmp_nb_bits_tot = sub( tmp_nb_bits_tot, 1 ); /* Q0 */ } - gsc_dec_ivas_fx( st, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st->coder_type, &last_bin, lsf_new, exc_wo_nf_fx, &st->Q_exc ); + gsc_dec_fx( st, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st->coder_type, &last_bin, lsf_new, exc_wo_nf_fx, &st->Q_exc ); /*--------------------------------------------------------------------------------------* * iDCT transform @@ -193,14 +193,9 @@ void tdm_low_rate_dec_fx( * * Decode generic (GC), 2 subframes mode *---------------------------------------------------------------------*/ -/*---------------------------------------------------------------------* - * decod_gen_2sbfr_ivas_fx() - * - * Decode generic (GC), 2 subframes mode - *---------------------------------------------------------------------*/ -void decod_gen_2sbfr_ivas_fx( - Decoder_State *st, /* i/o: decoder static memory */ +void decod_gen_2sbfr_fx( + Decoder_State *st, /* i/o: decoder static memory */ const Word16 sharpFlag, /* i : formant sharpening flag `Q0*/ const Word16 *Aq, /* i : LP filter coefficient Q12*/ Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ @@ -263,7 +258,7 @@ void decod_gen_2sbfr_ivas_fx( * Decode pitch lag *----------------------------------------------------------------------*/ - *pt_pitch = pit_decode_ivas_fx( st, st->core_brate, 0, L_frame, i_subfr, GENERIC, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, 2 * L_SUBFR, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); /* Q6 */ + *pt_pitch = pit_decode_fx( st, st->core_brate, 0, L_frame, i_subfr, GENERIC, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, 2 * L_SUBFR, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); /* Q6 */ test(); test(); @@ -295,7 +290,7 @@ void decod_gen_2sbfr_ivas_fx( * Estimate spectrum tilt and voicing *--------------------------------------------------------------*/ - gain_dec_lbr_ivas_fx( st, GENERIC, i_subfr, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, gc_mem, gp_mem, 2 * L_SUBFR ); + gain_dec_lbr_fx( st, GENERIC, i_subfr, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, gc_mem, gp_mem, 2 * L_SUBFR ); st->tilt_code_fx = est_tilt_ivas_fx( exc + i_subfr, gain_pit, code, gain_code, &voice_fac, st->Q_exc, 2 * L_SUBFR, 0 ); /* Q15 */ move16(); @@ -312,10 +307,12 @@ void decod_gen_2sbfr_ivas_fx( Word16 gain_code16 = round_fx( L_shl( gain_code, st->Q_exc ) ); /*Q_exc*/ Acelp_dec_total_exc( exc, exc2, gain_code16, gain_pit, i_subfr, code, 2 * L_SUBFR ); + /*-----------------------------------------------------------------* * Prepare TBE excitation *-----------------------------------------------------------------*/ - prep_tbe_exc_ivas_fx( L_frame, 2 * L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/], bwe_exc, 0, NULL, st->Q_exc, T0, T0_frac, GENERIC, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); + + prep_tbe_exc_fx( L_frame, 2 * L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/], bwe_exc, 0, NULL, st->Q_exc, T0, T0_frac, GENERIC, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); voice_factors[i_subfr / L_SUBFR + 1] = voice_factors[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/]; /* Q15 */ move16(); @@ -323,6 +320,7 @@ void decod_gen_2sbfr_ivas_fx( * Excitation enhancements (update of total excitation signal) * called twice because adapting it to double the subfr length would need lot of modifications *----------------------------------------------------------------*/ + enhancer_ivas_fx2( st->core_brate, 0, GENERIC, i_subfr, L_frame, voice_fac, st->stab_fac_fx, norm_gain_code, gain_inov, &st->gc_threshold_fx, code, exc2, gain_pit, &st->dm_fx, st->Q_exc ); enhancer_ivas_fx2( st->core_brate, 0, GENERIC, i_subfr, L_frame, voice_fac, st->stab_fac_fx, norm_gain_code, gain_inov, &st->gc_threshold_fx, code + L_SUBFR, exc2 + L_SUBFR, gain_pit, &st->dm_fx, st->Q_exc ); diff --git a/lib_dec/lsf_dec_fx.c b/lib_dec/lsf_dec_fx.c index 9b7f77c79..913543db8 100644 --- a/lib_dec/lsf_dec_fx.c +++ b/lib_dec/lsf_dec_fx.c @@ -8,9 +8,11 @@ #include "rom_com.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ #include "ivas_prot_fx.h" + /*-------------------------------------------------------------------* * Local functions *-------------------------------------------------------------------*/ + static void dqlsf_CNG_fx( Decoder_State *st_fx, Word16 *lsf_q ); /*--------------------------------------------------------------------------------------* @@ -88,7 +90,6 @@ static void dqlsf_CNG_fx( /* _ (Word16*) lsp_new : LP filter coefficient Q15 */ /* _ (Word16*) lsp_mid : LP filter coefficient Q15 */ /*---------------------------------------------------------------------------*/ - /* _ (Word16[]) st_fx->lsf_adaptive_mean_fx : FEC - adaptive mean LSF */ /* vector for FEC Q(x2.56) */ /* _ (Word16[]) st_fx->mem_AR_fx : AR memory of LSF quantizer */ @@ -99,271 +100,16 @@ static void dqlsf_CNG_fx( /* _ None */ /*===========================================================================*/ -#ifndef REMOVE_EVS_DUPLICATES void lsf_dec_fx( - Decoder_State *st_fx, /* i/o: State structure */ - const Word16 tc_subfr, /* i : TC subframe index Q0*/ - Word16 *Aq, /* o : quantized A(z) for 4 subframes Q12*/ - Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ - Word16 *lsf_new, /* o : de-quantized LSF vector Q(x2.56)*/ - Word16 *lsp_new, /* o : de-quantized LSP vector Q15*/ - Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector Q15*/ - const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag Q0*/ - , - const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ -) -{ - Word16 i; - Word16 no_param_lpc; - Word16 param_lpc[NPRM_LPC_NEW]; - Word32 L_tmp; - Word16 nBits = 0; - move16(); - Word16 tmp_old[M + 1], tmp_new[M + 1]; - Word16 enr_old = 0, enr_new = 0; - move16(); - move16(); - Word16 lsf_diff, coder_type; - - /* initialize */ - coder_type = st_fx->coder_type; - if ( EQ_32( st_fx->core_brate, SID_2k40 ) ) - { - coder_type = INACTIVE; /* Q0 */ - move16(); - } - test(); - if ( EQ_16( coder_type, AUDIO ) && st_fx->GSC_IVAS_mode > 0 ) - { - coder_type = GENERIC; /* Q0 */ - move16(); - } - no_param_lpc = 0; - nBits = 0; - move16(); - move16(); - - /* Find the number of bits for LSF quantization */ - IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) - { - nBits = LSF_BITS_CNG; /* Q0 */ - move16(); - } - ELSE - { - test(); - IF( st_fx->nelp_mode_dec == 0 && st_fx->ppp_mode_dec == 0 ) - { - nBits = st_fx->acelp_cfg.lsf_bits; /* Q0 */ - move16(); - } - ELSE IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) - { - IF( EQ_16( coder_type, UNVOICED ) ) - { - nBits = 30; /* Q0 */ - move16(); - if ( st_fx->bwidth == NB ) - { - nBits = 32; /* Q0 */ - move16(); - } - } - } - ELSE IF( EQ_16( st_fx->ppp_mode_dec, 1 ) ) - { - nBits = 26; /* Q0 */ - move16(); - } - } - - /* LSF de-quantization */ - lsf_end_dec_fx( st_fx, 0, coder_type, st_fx->bwidth, nBits, lsf_new, param_lpc, LSF_Q_prediction, &no_param_lpc, - tdm_lsfQ_PCh ); - - /* convert quantized LSFs to LSPs */ - - lsf2lsp_fx( lsf_new, lsp_new, M, st_fx->sr_core ); - /* set seed_acelp used in UC mode */ - test(); - IF( EQ_16( coder_type, UNVOICED ) && GT_16( st_fx->element_mode, EVS_MONO ) ) - { - st_fx->seed_acelp = 0; - move16(); - FOR( i = no_param_lpc - 1; i >= 0; i-- ) - { - /* rightshift before *seed_acelp+param_lpc[i] to avoid overflows*/ - st_fx->seed_acelp = extract_l( L_add( imult3216( 31821L /* Q0 */, add( shr( ( st_fx->seed_acelp ), 1 ), param_lpc[i] ) ), 13849L /* Q0 */ ) ); /* Q0 */ - move16(); - } - } - IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) - { - /* return if SID frame (conversion to A(z) done in the calling function) */ - return; - } - - /*-------------------------------------------------------------------------------------* - * FEC - update adaptive LSF mean vector - *-------------------------------------------------------------------------------------*/ - - FOR( i = 0; i < M; i++ ) - { - L_tmp = L_mult( lsf_new[i], 10922 ); /*Q(x2.56+16)*/ - L_tmp = L_mac( L_tmp, st_fx->lsfoldbfi1_fx[i], 10922 ); /*Q(x2.56+16)*/ - L_tmp = L_mac( L_tmp, st_fx->lsfoldbfi0_fx[i], 10922 ); /*Q(x2.56+16)*/ - st_fx->lsf_adaptive_mean_fx[i] = round_fx( L_tmp ); /*Q(x2.56)*/ - move16(); - } - - test(); - test(); - IF( ( st_fx->prev_bfi && ( EQ_16( coder_type, TRANSITION ) ) && ( EQ_16( tc_subfr, sub( st_fx->L_frame, L_SUBFR ) ) ) ) ) - { - lsf_diff = 1205; - move16(); /*int_fs / (float)(2*(M+1)); = 470.588 -> 1205 in Q2.56 */ - if ( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - lsf_diff = 964; - move16(); /*int_fs / (float)(2*(M+1)); = 376.47 -> 964 in Q2.56 */ - } - st_fx->lsf_old_fx[0] = lsf_diff; - move16(); - - FOR( i = 1; i < M; i++ ) - { - st_fx->lsf_old_fx[i] = add( st_fx->lsf_old_fx[i - 1], lsf_diff ); /* Q2.56 */ - move16(); - } - lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, st_fx->sr_core ); - } - /*-------------------------------------------------------------------------------------* - * Mid-frame LSF decoding - * LSP interpolation and conversion of LSPs to A(z) - *-------------------------------------------------------------------------------------*/ - IF( st_fx->rate_switching_reset ) - { - /*extrapolation in case of unstable LSF convert*/ - Copy( lsp_new, st_fx->lsp_old_fx, M ); /* Q15 */ - Copy( lsf_new, st_fx->lsf_old_fx, M ); /* Q2.56 */ - } - { - /* Mid-frame LSF decoding */ - lsf_mid_dec_fx( st_fx, lsp_new, coder_type, lsp_mid ); - } - test(); - test(); - IF( !( st_fx->prev_bfi && ( EQ_16( coder_type, TRANSITION ) ) && ( EQ_16( tc_subfr, sub( st_fx->L_frame, L_SUBFR ) ) ) ) ) - { - IF( st_fx->prev_bfi ) - { - /* check, if LSP interpolation can be relaxed */ - E_LPC_f_lsp_a_conversion( st_fx->lsp_old_fx, tmp_old, M ); - enr_old = Enr_1_Az_fx( tmp_old, 2 * L_SUBFR ); /* Q3 */ - - E_LPC_f_lsp_a_conversion( lsp_new, tmp_new, M ); - enr_new = Enr_1_Az_fx( tmp_new, 2 * L_SUBFR ); /* Q3 */ - - IF( LT_16( enr_new, mult_r( 9830 /*0.3 Q15*/, enr_old ) ) ) - { - /* OLD CODE : if( st->safety_net == 1), replaced with a decision similar to MODE2 */ - st_fx->relax_prev_lsf_interp = -1; - move16(); - test(); - test(); - test(); - test(); - if ( st_fx->clas_dec == UNVOICED_CLAS || EQ_16( st_fx->clas_dec, SIN_ONSET ) || st_fx->clas_dec == INACTIVE_CLAS || EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) ) - { - st_fx->relax_prev_lsf_interp = 1; - move16(); - } - } - } - } - test(); - IF( EQ_16( st_fx->last_core, HQ_CORE ) && st_fx->core == ACELP_CORE ) - { - /* update old LSPs/LSFs in case of HQ->ACELP core switching */ - Copy( lsp_mid, st_fx->lsp_old_fx, M ); /* Q15 */ - lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core ); /* Q15 */ - } - test(); - IF( EQ_16( tdm_low_rate_mode, 1 ) && GT_16( coder_type, UNVOICED ) ) - { - // PMT("To be verified") - IF( EQ_16( st_fx->active_cnt, 1 ) ) - { - Copy( lsp_mid, st_fx->lsp_old_fx, M ); /* Q15 */ - lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core ); /* Q15 */ - Copy( lsp_new, lsp_mid, M ); /* Q15 */ - } - - /* LSP interpolation and conversion of LSPs to A(z) - two-subframe mode */ - int_lsp4_fx( st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, -2 ); - } - ELSE - { - /* LSP interpolation and conversion of LSPs to A(z) */ - int_lsp4_fx( st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, st_fx->relax_prev_lsf_interp ); - } - /*------------------------------------------------------------------* - * Check LSF stability (distance between old LSFs and current LSFs) - *------------------------------------------------------------------*/ - - IF( st_fx->element_mode == EVS_MONO ) - { - st_fx->stab_fac_fx = lsf_stab_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); /*Q15*/ - move16(); - } - ELSE - { - st_fx->stab_fac_fx = lsf_stab_ivas_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); /* Q15 */ - move16(); - } - - return; -} - -/*===========================================================================*/ -/* FUNCTION : lsf_dec_ivas_fx() */ -/*---------------------------------------------------------------------------*/ -/* PURPOSE : LSF decoder */ -/*---------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Struct) st_fx : decoder static memory */ -/* _ (Word16) L_frame : length of the frame */ -/* _ (Word16) coder_type : coding type */ -/* _ (Word16) bwidth : input signal bandwidth */ -/*---------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) Aq : LP filter coefficient Q12 */ -/* _ (Word16*) lsf_new : LP filter coefficient Q(x2.56) */ -/* _ (Word16*) lsp_new : LP filter coefficient Q15 */ -/* _ (Word16*) lsp_mid : LP filter coefficient Q15 */ -/*---------------------------------------------------------------------------*/ - -/* _ (Word16[]) st_fx->lsf_adaptive_mean_fx : FEC - adaptive mean LSF */ -/* vector for FEC Q(x2.56) */ -/* _ (Word16[]) st_fx->mem_AR_fx : AR memory of LSF quantizer */ -/* (past quantized LSFs without mean) Q(x2.56) */ -/* _ (Word16) st_fx->stab_fac_fx : LSF stability factor Q15 */ -/*---------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*===========================================================================*/ -#endif -void lsf_dec_ivas_fx( - Decoder_State *st_fx, /* i/o: State structure */ - const Word16 tc_subfr, /* i : TC subframe index Q0*/ - Word16 *Aq, /* o : quantized A(z) for 4 subframes Q12*/ - Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ - Word16 *lsf_new, /* o : de-quantized LSF vector Q(x2.56)*/ - Word16 *lsp_new, /* o : de-quantized LSP vector Q15*/ - Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector Q15*/ - const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag Q0*/ - , - const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ + Decoder_State *st_fx, /* i/o: State structure */ + const Word16 tc_subfr, /* i : TC subframe index Q0*/ + Word16 *Aq, /* o : quantized A(z) for 4 subframes Q12*/ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ + Word16 *lsf_new, /* o : de-quantized LSF vector Q(x2.56)*/ + Word16 *lsp_new, /* o : de-quantized LSP vector Q15*/ + Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector Q15*/ + const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag Q0*/ + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ ) { Word16 i; diff --git a/lib_dec/pit_dec_fx.c b/lib_dec/pit_dec_fx.c index e8cebedbd..38ec41cb2 100644 --- a/lib_dec/pit_dec_fx.c +++ b/lib_dec/pit_dec_fx.c @@ -319,246 +319,22 @@ void Mode2_delta_pit_dec( /* _ (Word16 ) pitch : close loop integer pitch Q6 */ /*=======================================================================*/ -#ifndef REMOVE_EVS_DUPLICATES -Word16 pit_decode_fx( /* o : floating pitch value */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : coding type */ - Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ - Word16 *T0, /* o : close loop integer pitch */ - Word16 *T0_frac, /* o : close loop fractional part of the pitch */ - Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ - Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ - const Word16 L_subfr /* i : subframe length */ -) -{ - Word16 pitch; /*Q2*/ - Word16 pitch_index, nBits, pit_flag; - - pitch_index = 0; - move16(); - - /*----------------------------------------------------------------* - * Set pit_flag = 0 for every subframe with absolute pitch search - *----------------------------------------------------------------*/ - pit_flag = i_subfr; - move16(); - - if ( EQ_16( i_subfr, PIT_DECODE_2XL_SUBFR ) ) - { - pit_flag = 0; - move16(); - } - - /*-------------------------------------------------------* - * Retrieve the pitch index - *-------------------------------------------------------*/ - IF( !Opt_AMR_WB ) - { - /*----------------------------------------------------------------* - * pitch Q: Set limit_flag to 0 for restrained limits, and 1 for extended limits - *----------------------------------------------------------------*/ - test(); - test(); - IF( i_subfr == 0 ) - { - *limit_flag = 1; - move16(); - - if ( EQ_16( coder_type, VOICED ) ) - { - *limit_flag = 2; - move16(); /* double-extended limits */ - } - test(); - if ( EQ_16( coder_type, GENERIC ) && EQ_32( core_brate, ACELP_7k20 ) ) - { - *limit_flag = 0; - move16(); - } - } - ELSE IF( EQ_16( i_subfr, 2 * L_SUBFR ) && EQ_32( coder_type, GENERIC ) && LE_32( core_brate, ACELP_13k20 ) ) - { - if ( GT_16( *T0, shr( add( PIT_FR1_EXTEND_8b, PIT_MIN ), 1 ) ) ) - { - *limit_flag = 0; - move16(); - } - } - - /*-------------------------------------------------------* - * Retrieve the number of Q bits - *-------------------------------------------------------*/ - - nBits = 0; - move16(); - IF( NE_16( coder_type, AUDIO ) ) - { - /* find the number of bits */ - nBits = st_fx->acelp_cfg.pitch_bits[shr( i_subfr, 6 )]; - move16(); - pitch_index = (Word16) get_next_indice_fx( st_fx, nBits ); - } - - /*-------------------------------------------------------* - * Pitch decoding in AUDIO mode - * (both ACELP@12k8 and ACELP@16k cores) - *-------------------------------------------------------*/ - IF( EQ_16( coder_type, AUDIO ) ) - { - test(); - if ( EQ_16( L_subfr, L_FRAME / 2 ) && i_subfr != 0 ) - { - pit_flag = L_SUBFR; - move16(); - } - if ( pit_flag == 0 ) - { - nBits = 10; - move16(); - } - if ( pit_flag != 0 ) - { - nBits = 6; - move16(); - } - - pitch_index = (Word16) get_next_indice_fx( st_fx, nBits ); - - test(); - test(); - IF( EQ_16( L_subfr, L_FRAME / 2 ) && i_subfr != 0 && GE_16( pitch_index, 32 ) ) /* safety check in case of bit errors */ - { - pitch_index = shr( pitch_index, 1 ); - st_fx->BER_detect = 1; - move16(); - } - - pit_Q_dec_fx( 0, pitch_index, nBits, 4, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect ); - } - ELSE IF( EQ_16( coder_type, VOICED ) ) - { - /*-------------------------------------------------------* - * Pitch decoding in VOICED mode - * (ACELP@12k8 core only) - *-------------------------------------------------------*/ - if ( EQ_16( i_subfr, 2 * L_SUBFR ) ) - { - pit_flag = i_subfr; - move16(); - } - - pit_Q_dec_fx( 0, pitch_index, nBits, 4, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect ); - } - ELSE - { - /*-------------------------------------------------------* - * Pitch decoding in GENERIC mode - * (both ACELP@12k8 and ACELP@16k cores) - *-------------------------------------------------------*/ - IF( EQ_16( L_frame, L_FRAME ) ) - { - pit_Q_dec_fx( 0, pitch_index, nBits, 8, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect ); - } - ELSE - { - pit16k_Q_dec_fx( pitch_index, nBits, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect ); - } - } - } - - /*-------------------------------------------------------* - * Pitch decoding in AMR-WB IO mode - *-------------------------------------------------------*/ - - ELSE - { - *limit_flag = 0; - move16(); - test(); - test(); - IF( i_subfr == 0 || ( EQ_16( i_subfr, 2 * L_SUBFR ) && EQ_32( core_brate, ACELP_8k85 ) ) ) - { - nBits = 8; - move16(); - } - ELSE - { - nBits = 5; - move16(); - } - IF( GT_32( core_brate, ACELP_8k85 ) ) - { - nBits = 6; - move16(); - test(); - if ( i_subfr == 0 || EQ_16( i_subfr, 2 * L_SUBFR ) ) - { - nBits = 9; - move16(); - } - } - - pitch_index = (Word16) get_next_indice_fx( st_fx, nBits ); - - pit_Q_dec_fx( 1, pitch_index, nBits, 8, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect ); - } - - /*-------------------------------------------------------* - * Compute floating pitch output - *-------------------------------------------------------*/ - - pitch = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); /* save subframe pitch values Q6 */ - - return pitch; -} - -/*======================================================================*/ -/* FUNCTION : pit_decode_ivas_fx() */ -/*-----------------------------------------------------------------------*/ -/* PURPOSE : calculate pitch value */ -/* */ -/*-----------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word32) core_brate : Core bitrate Q0 */ -/* _ (Word16) Opt_AMR_WB : flag indicating AMR-WB IO mode Q0 */ -/* _ (Word16) L_frame : length of the frame Q0 */ -/* _ (Word16) i_subfr : length of the frame Q0 */ -/* _ (Word16) coder_type : coding type Q0 */ -/* _ (Word16) L_subfr : subframe length */ -/*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16 *) T0 : close loop integer pitch */ -/* _ (Word16 *) T0_frac : close loop fractional part of the pitch */ -/* _ (Word16 ) pitch : pitch value Q6 */ -/*-----------------------------------------------------------------------*/ -/* INPUT OUTPUT ARGUMENTS */ -/* _ (Word16 *) T0_min : delta search min for sf 2 & 4 */ -/* _ (Word16 *) T0_max : delta search max for sf 2 & 4 */ -/*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ (Word16 ) pitch : close loop integer pitch Q6 */ -/*=======================================================================*/ - -#endif -Word16 pit_decode_ivas_fx( /* o : floating pitch value */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : coding type */ - Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ - Word16 *T0, /* o : close loop integer pitch */ - Word16 *T0_frac, /* o : close loop fractional part of the pitch */ - Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ - Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ - const Word16 L_subfr, /* i : subframe length */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6 */ +/*! r: floating pitch value */ +Word16 pit_decode_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame, /* i : length of the frame */ + Word16 i_subfr, /* i : subframe index */ + const Word16 coder_type, /* i : coding type */ + Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ + Word16 *T0, /* o : close loop integer pitch */ + Word16 *T0_frac, /* o : close loop fractional part of the pitch */ + Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ + Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ + const Word16 L_subfr, /* i : subframe length */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6 */ ) { Word16 pitch; /*Q2*/ diff --git a/lib_dec/post_dec_fx.c b/lib_dec/post_dec_fx.c index b5d56d8fb..cbcb225bc 100644 --- a/lib_dec/post_dec_fx.c +++ b/lib_dec/post_dec_fx.c @@ -139,21 +139,13 @@ void post_decoder( { st->hPFstat->on = 1; move16(); -#ifdef REMOVE_EVS_DUPLICATES - formant_post_filt_ivas_fx( st->hPFstat, synth, st->mem_Aq, synth2, L_frame, st->lp_noise, bitrate, 0 ); -#else formant_post_filt_fx( st->hPFstat, synth, st->mem_Aq, synth2, L_frame, st->lp_noise, bitrate, 0 ); -#endif } ELSE { st->hPFstat->on = 0; move16(); -#ifdef REMOVE_EVS_DUPLICATES - formant_post_filt_ivas_fx( st->hPFstat, synth, st->mem_Aq, synth2, L_frame, st->lp_noise, bitrate, 1 ); -#else formant_post_filt_fx( st->hPFstat, synth, st->mem_Aq, synth2, L_frame, st->lp_noise, bitrate, 1 ); -#endif } } @@ -176,10 +168,10 @@ void post_decoder( /* Update synth2 memory */ Copy( synth_buf2 + L_frame, hBPF->pst_old_syn_fx, NBPSF_PIT_MAX ); - return; } + void post_decoder_ivas_fx( Decoder_State *st, Word16 synth_buf[], // Q0 @@ -310,21 +302,13 @@ void post_decoder_ivas_fx( { st->hPFstat->on = 1; move16(); -#ifdef REMOVE_EVS_DUPLICATES - formant_post_filt_ivas_fx( st->hPFstat, synth, st->mem_Aq, synth2, L_frame, st->lp_noise, bitrate, 0 ); -#else formant_post_filt_fx( st->hPFstat, synth, st->mem_Aq, synth2, L_frame, st->lp_noise, bitrate, 0 ); -#endif } ELSE { st->hPFstat->on = 0; move16(); -#ifdef REMOVE_EVS_DUPLICATES - formant_post_filt_ivas_fx( st->hPFstat, synth, st->mem_Aq, synth2, L_frame, st->lp_noise, bitrate, 1 ); -#else formant_post_filt_fx( st->hPFstat, synth, st->mem_Aq, synth2, L_frame, st->lp_noise, bitrate, 1 ); -#endif } } diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c index 4c3f7152c..ceba860a1 100644 --- a/lib_enc/acelp_core_enc_fx.c +++ b/lib_enc/acelp_core_enc_fx.c @@ -394,14 +394,10 @@ ivas_error acelp_core_enc_fx( test(); IF( !nelp_mode && !ppp_mode ) { -#ifdef REMOVE_EVS_DUPLICATES - config_acelp1_IVAS( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, -#else - config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, -#endif - st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, st_fx->coder_type, st_fx->inactive_coder_type_flag, - tc_subfr_fx, 0, &nb_bits, unbits_fx, st_fx->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_fr_cnt_fx, - tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); + config_acelp1_fx( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, + st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, st_fx->coder_type, st_fx->inactive_coder_type_flag, + tc_subfr_fx, 0, &nb_bits, unbits_fx, st_fx->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_fr_cnt_fx, + tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); } /*-----------------------------------------------------------------* @@ -464,19 +460,16 @@ ivas_error acelp_core_enc_fx( { tc_classif_enc_fx( Q_new, st_fx->L_frame, &tc_subfr_fx, &position, attack_flag, st_fx->pitch[0], res_fx ); -#ifdef REMOVE_EVS_DUPLICATES - config_acelp1_IVAS( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, st_fx->L_frame, -#else - config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, st_fx->L_frame, -#endif - -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, -1, tc_subfr_fx, 1, NULL, unbits_fx, st_fx->element_mode, &uc_two_stage_flag, - tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_fr_cnt_fx, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); + config_acelp1_fx( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, st_fx->L_frame, + -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, -1, tc_subfr_fx, 1, NULL, unbits_fx, st_fx->element_mode, &uc_two_stage_flag, + tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_fr_cnt_fx, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); } /*---------------------------------------------------------------* * Calculation of prediction for scaled innovation energy * (for memory-less gain quantizer) *---------------------------------------------------------------*/ + IF( nb_bits > 0 ) { Es_pred_enc_fx( &Es_pred_fx, &indice, st_fx->L_frame, res_fx, st_fx->voicing_fx, nb_bits, 0, Q_new ); @@ -521,13 +514,9 @@ ivas_error acelp_core_enc_fx( lsp_mid_bck_fx, mCb1_fx, Bin_E_fx, Bin_E_old_fx, mem_syn_bck_fx, mem_w0_bck_fx, streaklimit_fx, pstreaklen_fx ); /* Configure ACELP bit allocation */ -#ifdef REMOVE_EVS_DUPLICATES - config_acelp1_IVAS( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, st_fx->L_frame, -#else - config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, st_fx->L_frame, -#endif - -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, st_fx->coder_type, st_fx->inactive_coder_type_flag, tc_subfr_fx, 0, &nb_bits, unbits_fx, 0, &uc_two_stage_flag, 0, 0, - st_fx->idchan, st_fx->active_fr_cnt_fx, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); + config_acelp1_fx( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, st_fx->L_frame, + -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, st_fx->coder_type, st_fx->inactive_coder_type_flag, tc_subfr_fx, 0, &nb_bits, unbits_fx, 0, &uc_two_stage_flag, 0, 0, + st_fx->idchan, st_fx->active_fr_cnt_fx, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); /* redo LSF quantization */ lsf_enc_fx( st_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, st_fx->Nb_ACELP_frames, tdm_low_rate_mode, st_fx->GSC_IVAS_mode, Q_new ); @@ -1185,7 +1174,7 @@ ivas_error acelp_core_enc_ivas_fx( test(); IF( !nelp_mode && !ppp_mode ) { - config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, st->inactive_coder_type_flag, tc_subfr, 0, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); + config_acelp1_fx( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, st->inactive_coder_type_flag, tc_subfr, 0, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); } /*-----------------------------------------------------------------* @@ -1322,7 +1311,7 @@ ivas_error acelp_core_enc_ivas_fx( { tc_classif_enc_fx( Q_new, st->L_frame, &tc_subfr, &position, attack_flag, st->pitch[0], res_fx ); - config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, -1, tc_subfr, 1, NULL, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); + config_acelp1_fx( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, -1, tc_subfr, 1, NULL, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); } /*---------------------------------------------------------------* @@ -1381,7 +1370,7 @@ ivas_error acelp_core_enc_ivas_fx( lsf_syn_mem_restore_ivas_fx( st, tilt_code_bck_fx, gc_threshold_bck_fx, clip_var_bck_fx, next_force_sf_bck, lsp_new, lsp_mid, clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsp_mid_bck_fx, Bin_E_fx, Bin_E_old_fx, mem_syn_bck_fx, mem_w0_bck_fx, streaklimit_fx, pstreaklen ); /* Configure ACELP bit allocation */ - config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, st->inactive_coder_type_flag, tc_subfr, 0, &nb_bits, unbits, 0, &uc_two_stage_flag, 0, 0, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); + config_acelp1_fx( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, st->inactive_coder_type_flag, tc_subfr, 0, &nb_bits, unbits, 0, &uc_two_stage_flag, 0, 0, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); /* redo LSF quantization */ lsf_enc_ivas_fx( st, lsf_new_fx, lsp_new, lsp_mid, Aq, tdm_low_rate_mode, 0, NULL, Q_new ); @@ -1390,6 +1379,7 @@ ivas_error acelp_core_enc_ivas_fx( calc_residu_fx( st, inp, res_fx, Aq ); st->hTdCngEnc->burst_ho_cnt = 0; move16(); + /* VOICED frames in SC-VBR */ encod_gen_voic_ivas_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, 0, Q_new ); } diff --git a/lib_enc/acelp_core_switch_enc_fx.c b/lib_enc/acelp_core_switch_enc_fx.c index 854f0ff67..52f5d4010 100644 --- a/lib_enc/acelp_core_switch_enc_fx.c +++ b/lib_enc/acelp_core_switch_enc_fx.c @@ -11,32 +11,17 @@ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ + /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ -static void encod_gen_voic_core_switch_fx( Encoder_State *st_fx, - const Word16 L_frame_fx, - const Word16 inp_fx[], - const Word16 Aq_fx[], - const Word16 A_fx[], - const Word16 T_op[], - Word16 *exc_fx, - const Word32 core_bitrate_fx, - Word16 shift, - Word16 Q_new ); -static void encod_gen_voic_core_switch_ivas_fx( Encoder_State *st_fx, - const Word16 L_frame_fx, - const Word16 inp_fx[], - const Word16 Aq_fx[], - const Word16 A_fx[], - const Word16 T_op[], - Word16 *exc_fx, - const Word32 core_bitrate_fx, - Word16 shift, - Word16 Q_new ); +static void encod_gen_voic_core_switch_fx( Encoder_State *st_fx, const Word16 L_frame_fx, const Word16 inp_fx[], const Word16 Aq_fx[], const Word16 A_fx[], const Word16 T_op[], Word16 *exc_fx, const Word32 core_bitrate_fx, Word16 shift, Word16 Q_new ); + +static void encod_gen_voic_core_switch_ivas_fx( Encoder_State *st_fx, const Word16 L_frame_fx, const Word16 inp_fx[], const Word16 Aq_fx[], const Word16 A_fx[], const Word16 T_op[], Word16 *exc_fx, const Word32 core_bitrate_fx, Word16 shift, Word16 Q_new ); static void bwe_switch_enc_fx( Encoder_State *st_fx, const Word16 *new_speech ); + static void bwe_switch_enc_ivas_fx( Encoder_State *st_fx, const Word16 *new_speech ); static Word16 dotprod_satcont( const Word16 *x, const Word16 *y, Word16 qx, Word16 qy, Word16 *qo, Word16 len, Word16 delta ); @@ -151,12 +136,8 @@ void acelp_core_switch_enc_fx( * Excitation encoding *----------------------------------------------------------------*/ -#ifdef REMOVE_EVS_DUPLICATES - config_acelp1_IVAS( ENC, st_fx->total_brate, cbrate, st_fx->core, -1, -1, st_fx->last_L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, -#else - config_acelp1( ENC, st_fx->total_brate, cbrate, st_fx->core, -1, -1, st_fx->last_L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, -#endif - GENERIC, st_fx->inactive_coder_type_flag, -1, -1, &j, &i, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, 0, 0 /*GSC_IVAS_mode*/ ); + config_acelp1_fx( ENC, st_fx->total_brate, cbrate, st_fx->core, -1, -1, st_fx->last_L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, + GENERIC, st_fx->inactive_coder_type_flag, -1, -1, &j, &i, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, 0, 0 /*GSC_IVAS_mode*/ ); encod_gen_voic_core_switch_fx( st_fx, st_fx->last_L_frame, inp, Aq, A, T_op, exc, cbrate, shift, Q_new ); @@ -279,8 +260,8 @@ void acelp_core_switch_enc_ivas_fx( * Excitation encoding *----------------------------------------------------------------*/ - config_acelp1_IVAS( ENC, st_fx->total_brate, cbrate, st_fx->core, -1, -1, st_fx->last_L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, - GENERIC, st_fx->inactive_coder_type_flag, -1, -1, &j, &i, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, 0, 0 /*GSC_IVAS_mode*/ ); + config_acelp1_fx( ENC, st_fx->total_brate, cbrate, st_fx->core, -1, -1, st_fx->last_L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, + GENERIC, st_fx->inactive_coder_type_flag, -1, -1, &j, &i, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, 0, 0 /*GSC_IVAS_mode*/ ); encod_gen_voic_core_switch_ivas_fx( st_fx, st_fx->last_L_frame, inp, Aq, A, T_op, exc, cbrate, shift, Q_new ); diff --git a/lib_enc/analy_lp_fx.c b/lib_enc/analy_lp_fx.c index 78a02eeec..9b6ff2108 100644 --- a/lib_enc/analy_lp_fx.c +++ b/lib_enc/analy_lp_fx.c @@ -3,17 +3,16 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "rom_com.h" /* Static table prototypes */ -#include "rom_enc.h" /* Static table prototypes */ -//#include "prot_fx.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com.h" /* Static table prototypes */ +#include "rom_enc.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* - * analy_lp() + * analy_lp_fx() * * Perform LP analysis * @@ -23,26 +22,26 @@ * - find interpolated LSPs and convert back to A(z) for all subframes * - update LSPs for the next frame *-------------------------------------------------------------------*/ -void analy_lp_ivas_fx( - const Word16 speech[], /* i :(Q_new) pointer to the speech frame */ - const Word16 L_frame, /* i :(q0) length of the frame */ - const Word16 L_look, /* i :(q0) look-ahead */ - Word32 *ener, /* o :(Q_r) residual energy from Levinson-Durbin */ - Word16 A[], /* o :(q14) A(z) filter coefficients */ - Word16 epsP_h[], /* o :(high part of epsP(Q_r)) LP analysis residual energies for each iteration */ - Word16 epsP_l[], /* o :(low part of epsP(Q_r)) LP analysis residual energies for each iteration */ - Word16 lsp_new[], /* o :(q15) current frame LSPs */ - Word16 lsp_mid[], /* o :(q15) current mid-frame LSPs */ - Word16 lsp_old[], /* i/o:(q15) previous frame unquantized LSPs */ - const Word16 Top[2], /* i :(q0) open loop pitch lag */ - const Word16 Tnc[2], /* i :(q15) open loop pitch gain */ - const Word32 Core_sr, /* i :(q0) Internal core sampling rate */ -#ifdef REMOVE_EVS_DUPLICATES - const Word16 element_mode, /* i : element mode */ -#endif - const Word16 sec_chan_low_rate, /* i :(q0) flag to signal second channel */ - Word16 Q_new, /*i: stores Q for speech*/ - Word16 *Q_r /*stores q for ener*/ ) + +void analy_lp_fx( + const Word16 speech[], /* i :(Q_new) pointer to the speech frame */ + const Word16 L_frame, /* i :(q0) length of the frame */ + const Word16 L_look, /* i :(q0) look-ahead */ + Word32 *ener, /* o :(Q_r) residual energy from Levinson-Durbin */ + Word16 A[], /* o :(q14) A(z) filter coefficients */ + Word16 epsP_h[], /* o :(high part of epsP(Q_r)) LP analysis residual energies for each iteration */ + Word16 epsP_l[], /* o :(low part of epsP(Q_r)) LP analysis residual energies for each iteration */ + Word16 lsp_new[], /* o :(q15) current frame LSPs */ + Word16 lsp_mid[], /* o :(q15) current mid-frame LSPs */ + Word16 lsp_old[], /* i/o:(q15) previous frame unquantized LSPs */ + const Word16 Top[2], /* i :(q0) open loop pitch lag */ + const Word16 Tnc[2], /* i :(q15) open loop pitch gain */ + const Word32 Core_sr, /* i :(q0) Internal core sampling rate */ + const Word16 element_mode, /* i : element mode */ + const Word16 sec_chan_low_rate, /* i :(q0) flag to signal second channel */ + Word16 Q_new, /* i : stores Q for speech */ + Word16 *Q_r /*stores q for ener*/ +) { Word16 r_h[M + 1]; /* Autocorrelations of windowed speech MSB */ Word16 r_l[M + 1]; /* Autocorrelations of windowed speech LSB */ @@ -77,9 +76,7 @@ void analy_lp_ivas_fx( /* Autocorrelations */ autocorr_fx( pt, M, r_h, r_l, &Q_r[1 - i_subfr], wind_length, wind, 0, 0 ); -#ifdef REMOVE_EVS_DUPLICATES IF( NE_16( element_mode, EVS_MONO ) ) -#endif { /*if ( r[0] < 100.0f && no_thr == 0 )*/ /*r[0] = 100.0f*/ @@ -132,101 +129,6 @@ void analy_lp_ivas_fx( return; } -#ifndef REMOVE_EVS_DUPLICATES -void analy_lp_fx( - const Word16 speech[], /* i : pointer to the speech frame Q_new*/ - const Word16 L_frame, /* i : length of the frame Q0*/ - const Word16 L_look, /* i : look-ahead Q0*/ - Word32 *ener, /* o : residual energy from Levinson-Durbin Q_r*/ - Word16 A[], /* o : A(z) filter coefficients Q14*/ - Word16 epsP_h[], /* o : LP analysis residual energies for each iteration Q_r*/ - Word16 epsP_l[], /* o : LP analysis residual energies for each iteration Q_r*/ - Word16 lsp_new[], /* o : current frame LSPs Q15*/ - Word16 lsp_mid[], /* o : current mid-frame LSPs Q15*/ - Word16 lsp_old[], /* i/o: previous frame unquantized LSPs Q15*/ - const Word16 Top[2], /* i : open loop pitch lag Q0*/ - const Word16 Tnc[2], /* i : open loop pitch gain Q15*/ - const Word32 Core_sr, /* i : Internal core sampling rate Q0*/ - const Word16 sec_chan_low_rate, /* i : flag to signal second channel Q0*/ - Word16 Q_new, - Word16 *Q_r ) -{ - Word16 r_h[M + 1]; /* Autocorrelations of windowed speech MSB */ - Word16 r_l[M + 1]; /* Autocorrelations of windowed speech LSB */ - Word32 LepsP[M + 1]; - Word16 i, i_subfr, wind_length = 0; - Word16 *lsp; - const Word16 *wind = NULL; - const Word16 *pt; - Word16 half_frame; - - IF( EQ_16( L_frame, L_FRAME ) ) - { - wind_length = L_LP; - move16(); - wind = Assym_window_W16fx; /* Q15 */ - } - ELSE /* L_frame == L_FRAME16k */ - { - wind_length = L_LP_16k; - move16(); - wind = assym_window_16k_fx; /* Q15 */ - } - lsp = lsp_mid; /* Q15 */ - half_frame = shr( L_frame, 1 ); - - FOR( i_subfr = 0; i_subfr <= 1; i_subfr++ ) - { - pt = speech + sub( add( half_frame, L_look ), wind_length ); - half_frame = shl( half_frame, 1 ); - - /* Autocorrelations */ - autocorr_fx( pt, M, r_h, r_l, &Q_r[1 - i_subfr], wind_length, wind, 0, 0 ); - - /* Lag windowing */ - adapt_lag_wind( r_h, r_l, M, Top[i_subfr], Tnc[i_subfr], Core_sr ); - - /* Levinson-Durbin */ - E_LPC_lev_dur( r_h, r_l, A, LepsP, M, NULL ); - FOR( i = 0; i <= M; i++ ) - { - L_Extract( LepsP[i], &epsP_h[i], &epsP_l[i] ); - } - /*Q_r[... might not be needed from external...*/ - Q_r[1 - i_subfr] = add( Q_r[1 - i_subfr], shl( Q_new, 1 ) ); - move16(); - - /* Conversion of A(z) to LSPs */ - E_LPC_a_lsp_conversion( A, lsp, lsp_old, M ); - - lsp = lsp_new; /* Q15 */ - } - IF( EQ_16( sec_chan_low_rate, 1 ) ) - { - /* LSP interpolation */ -#ifdef REMOVE_EVS_DUPLICATES - int_lsp4_ivas_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, -2 ); -#else - int_lsp4_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, -2 ); -#endif - } - ELSE - { - /* LSP interpolation */ -#ifdef REMOVE_EVS_DUPLICATES - int_lsp4_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, 0 ); -#else - int_lsp4_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, 0 ); -#endif - } - Copy( lsp_new, lsp_old, M ); /* Q15 */ - *ener = L_Comp( epsP_h[M], epsP_l[M] ); /* Q_r */ - move32(); - - return; -} -#endif - /*-------------------------------------------------------------------* * analy_lp_AMR_WB() * diff --git a/lib_enc/cod_ace_fx.c b/lib_enc/cod_ace_fx.c index b5c18d44b..e1914aeb5 100644 --- a/lib_enc/cod_ace_fx.c +++ b/lib_enc/cod_ace_fx.c @@ -366,14 +366,9 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision * IF( st->igf != 0 ) { -#ifdef REMOVE_EVS_DUPLICATES - prep_tbe_exc_ivas_fx( L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], - bwe_exc, gain_preQ, code_preQ, Q_new, T0, T0_frac, st->coder_type, st->core_brate, - st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); -#else - prep_tbe_exc_fx( L_frame, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], - bwe_exc, gain_preQ, code_preQ, Q_new, T0, T0_frac, st->coder_type, st->core_brate ); -#endif + prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], + bwe_exc, gain_preQ, code_preQ, Q_new, T0, T0_frac, st->coder_type, st->core_brate, + st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); } /*---------------------------------------------------------* diff --git a/lib_enc/enc_gen_voic_fx.c b/lib_enc/enc_gen_voic_fx.c index a60828a94..87bba1fae 100644 --- a/lib_enc/enc_gen_voic_fx.c +++ b/lib_enc/enc_gen_voic_fx.c @@ -363,20 +363,15 @@ void encod_gen_voic_fx( exc_fx[i + i_subfr_fx] = round_fx_o( Ltmp, &Overflow ); /* Q0 */ } } + /*-----------------------------------------------------------------* * Prepare TBE excitation *-----------------------------------------------------------------*/ -#ifdef REMOVE_EVS_DUPLICATES - prep_tbe_exc_ivas_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, - &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q_new, - T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate, - st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); -#else - prep_tbe_exc_fx( L_frame, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, + prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q_new, - T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate ); -#endif + T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate, + st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); /*-----------------------------------------------------------------* * Synthesize speech to update mem_syn[]. @@ -405,9 +400,11 @@ void encod_gen_voic_fx( hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; /* Q15 */ move16(); } + return; } + void encod_gen_voic_ivas_fx( Encoder_State *st_fx, /* i/o: state structure */ const Word16 speech_fx[], /* i : input speech Qnew -1 */ @@ -763,10 +760,10 @@ void encod_gen_voic_ivas_fx( * Prepare TBE excitation *-----------------------------------------------------------------*/ - prep_tbe_exc_ivas_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, - &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q_new, - T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate, - st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); + prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, + &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q_new, + T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate, + st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); /*-----------------------------------------------------------------* * Synthesize speech to update mem_syn[]. diff --git a/lib_enc/enc_tran_fx.c b/lib_enc/enc_tran_fx.c index 394b22c30..eba991f57 100644 --- a/lib_enc/enc_tran_fx.c +++ b/lib_enc/enc_tran_fx.c @@ -308,13 +308,8 @@ Word16 encod_tran_fx( * Prepare TBE excitation *-----------------------------------------------------------------*/ -#ifdef REMOVE_EVS_DUPLICATES - prep_tbe_exc_ivas_fx( L_frame_fx, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], - bwe_exc_fx, gain_preQ, code_preQ, Q_new, T0, T0_frac, st_fx->coder_type, st_fx->core_brate, st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); -#else - prep_tbe_exc_fx( L_frame_fx, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], - bwe_exc_fx, gain_preQ, code_preQ, Q_new, T0, T0_frac, st_fx->coder_type, st_fx->core_brate ); -#endif + prep_tbe_exc_fx( L_frame_fx, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], + bwe_exc_fx, gain_preQ, code_preQ, Q_new, T0, T0_frac, st_fx->coder_type, st_fx->core_brate, st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); /*-----------------------------------------------------------------* * Synthesize speech to update mem_syn[]. @@ -717,9 +712,9 @@ Word16 encod_tran_ivas_fx( * Prepare TBE excitation *-----------------------------------------------------------------*/ - prep_tbe_exc_ivas_fx( L_frame_fx, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], - bwe_exc_fx, gain_preQ, code_preQ, Q_new, T0, T0_frac, st_fx->coder_type, st_fx->core_brate, - st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); + prep_tbe_exc_fx( L_frame_fx, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], + bwe_exc_fx, gain_preQ, code_preQ, Q_new, T0, T0_frac, st_fx->coder_type, st_fx->core_brate, + st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); /*-----------------------------------------------------------------* * Synthesize speech to update mem_syn[]. diff --git a/lib_enc/ivas_core_pre_proc_front_fx.c b/lib_enc/ivas_core_pre_proc_front_fx.c index 67c4f256f..5f4a5dd60 100644 --- a/lib_enc/ivas_core_pre_proc_front_fx.c +++ b/lib_enc/ivas_core_pre_proc_front_fx.c @@ -1150,12 +1150,7 @@ ivas_error pre_proc_front_ivas_fx( move16(); } -#ifdef REMOVE_EVS_DUPLICATES - analy_lp_ivas_fx( inp_12k8_fx, L_FRAME, L_look, ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing_fx, INT_FS_12k8, element_mode, i, *Q_new, Q_r ); -#else - analy_lp_ivas_fx( inp_12k8_fx, L_FRAME, L_look, ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing_fx, - INT_FS_12k8, i, *Q_new, Q_r ); -#endif + analy_lp_fx( inp_12k8_fx, L_FRAME, L_look, ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing_fx, INT_FS_12k8, element_mode, i, *Q_new, Q_r ); FOR( Word16 idx = 0; idx < M + 1; idx++ ) { diff --git a/lib_enc/ivas_core_pre_proc_fx.c b/lib_enc/ivas_core_pre_proc_fx.c index 6fe6b6720..4fcb9e1ec 100644 --- a/lib_enc/ivas_core_pre_proc_fx.c +++ b/lib_enc/ivas_core_pre_proc_fx.c @@ -1134,20 +1134,11 @@ ivas_error ivas_compute_core_buffers_fx( IF( Q_new ) { -#ifdef REMOVE_EVS_DUPLICATES - analy_lp_ivas_fx( inp_16k_fx, L_FRAME16k, L_look, ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lspold_enc_fx, st->pitch, st->voicing_fx, INT_FS_16k, element_mode, 0, sub( *Q_new, 1 ), Q_r ); -#else - analy_lp_ivas_fx( inp_16k_fx, L_FRAME16k, L_look, ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lspold_enc_fx, st->pitch, st->voicing_fx, INT_FS_16k, 0, sub( *Q_new, 1 ), Q_r ); -#endif + analy_lp_fx( inp_16k_fx, L_FRAME16k, L_look, ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lspold_enc_fx, st->pitch, st->voicing_fx, INT_FS_16k, element_mode, 0, sub( *Q_new, 1 ), Q_r ); } ELSE { -#ifdef REMOVE_EVS_DUPLICATES - analy_lp_ivas_fx( inp_16k_fx, L_FRAME16k, L_look, ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lspold_enc_fx, st->pitch, st->voicing_fx, INT_FS_16k, element_mode, 0, -1, Q_r ); - -#else - analy_lp_ivas_fx( inp_16k_fx, L_FRAME16k, L_look, ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lspold_enc_fx, st->pitch, st->voicing_fx, INT_FS_16k, 0, -1, Q_r ); -#endif + analy_lp_fx( inp_16k_fx, L_FRAME16k, L_look, ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lspold_enc_fx, st->pitch, st->voicing_fx, INT_FS_16k, element_mode, 0, -1, Q_r ); } /*--------------------------------------------------------------* diff --git a/lib_enc/ivas_front_vad_fx.c b/lib_enc/ivas_front_vad_fx.c index f3cf05e63..9e2e1402e 100644 --- a/lib_enc/ivas_front_vad_fx.c +++ b/lib_enc/ivas_front_vad_fx.c @@ -637,11 +637,7 @@ ivas_error front_vad_spar_fx( hFrontVad->q_buffer_12k8 = Q_inp_12k8; move16(); -#ifdef REMOVE_EVS_DUPLICATES - analy_lp_ivas_fx( inp_12k8_fx, L_FRAME, L_LOOK_12k8, &res_energy_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing_fx, INT_FS_12k8, st->element_mode, 0, Q_inp_12k8, Q_r ); -#else - analy_lp_ivas_fx( inp_12k8_fx, L_FRAME, L_LOOK_12k8, &res_energy_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing_fx, INT_FS_12k8, 0 /* <-- sec_chan_low_rate */, Q_inp_12k8, Q_r ); -#endif + analy_lp_fx( inp_12k8_fx, L_FRAME, L_LOOK_12k8, &res_energy_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing_fx, INT_FS_12k8, st->element_mode, 0, Q_inp_12k8, Q_r ); FOR( Word16 i = 0; i <= M; i++ ) { diff --git a/lib_enc/ivas_td_low_rate_enc_fx.c b/lib_enc/ivas_td_low_rate_enc_fx.c index 77ddb35aa..d10527a24 100644 --- a/lib_enc/ivas_td_low_rate_enc_fx.c +++ b/lib_enc/ivas_td_low_rate_enc_fx.c @@ -365,11 +365,12 @@ void encod_gen_2sbfr( move16(); move16(); } + /*-----------------------------------------------------------------* * Prepare TBE excitation *-----------------------------------------------------------------*/ - prep_tbe_exc_ivas_fx( L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], bwe_exc, 0, NULL, Q_new, T0, T0_frac, coder_type, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); + prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], bwe_exc, 0, NULL, Q_new, T0, T0_frac, coder_type, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); voice_factors[i_subfr / L_SUBFR + 1] = voice_factors[i_subfr / L_SUBFR]; /* Q15 */ move16(); @@ -378,6 +379,7 @@ void encod_gen_2sbfr( * Synthesize speech to update mem_syn_flt[]. * Update A(z) filters *-----------------------------------------------------------------*/ + Syn_filt_s( 1, p_Aq, M, &exc[i_subfr], &syn[i_subfr], 2 * L_SUBFR, hLPDmem->mem_syn, 1 ); p_Aw += 2 * ( M + 1 ); p_Aq += 2 * ( M + 1 ); diff --git a/lib_enc/lsf_enc_fx.c b/lib_enc/lsf_enc_fx.c index 8fe425d74..b26532b15 100644 --- a/lib_enc/lsf_enc_fx.c +++ b/lib_enc/lsf_enc_fx.c @@ -289,13 +289,16 @@ void lsf_enc_fx( { int_lsp4_fx( st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, 0 ); } + /*------------------------------------------------------------------* * Check LSF stability (distance between old LSFs and current LSFs) *------------------------------------------------------------------*/ + IF( NE_32( st_fx->core_brate, SID_2k40 ) ) { st_fx->stab_fac_fx = lsf_stab_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); } + return; } @@ -1982,7 +1985,7 @@ static void first_VQstages( dist[1] = dist_buf + maxC; move16(); - set16_fx( idx_buf, 0, ( const Word16 )( 2 * stagesVQ * maxC ) ); + set16_fx( idx_buf, 0, (const Word16) ( 2 * stagesVQ * maxC ) ); set16_fx( parents, 0, maxC ); /* Set up inital distance vector */ @@ -2172,7 +2175,7 @@ static void first_VQstages_ivas_fx( dist[1] = dist_buf + maxC; move16(); - set16_fx( idx_buf, 0, ( const Word16 )( 2 * stagesVQ * maxC ) ); + set16_fx( idx_buf, 0, (const Word16) ( 2 * stagesVQ * maxC ) ); set16_fx( parents, 0, maxC ); /* Set up inital distance vector */ diff --git a/lib_enc/pre_proc_fx.c b/lib_enc/pre_proc_fx.c index e8d4a0722..cc8b64ca4 100644 --- a/lib_enc/pre_proc_fx.c +++ b/lib_enc/pre_proc_fx.c @@ -213,7 +213,7 @@ void pre_proc_fx( /*----------------------------------------------------------------* * Change the sampling frequency to 12.8 kHz *----------------------------------------------------------------*/ - modify_Fs_fx( signal_in, input_frame, st->input_Fs, new_inp_12k8, INT_FS_12k8, st->mem_decim_fx, ( const Word16 )( EQ_16( st->max_bwidth, NB ) ) ); + modify_Fs_fx( signal_in, input_frame, st->input_Fs, new_inp_12k8, INT_FS_12k8, st->mem_decim_fx, (const Word16) ( EQ_16( st->max_bwidth, NB ) ) ); Copy( new_inp_12k8, st->buf_speech_enc + L_FRAME32k, L_FRAME ); Scale_sig( st->buf_speech_enc + L_FRAME32k, L_FRAME, 1 ); /*------------------------------------------------------------------* @@ -414,11 +414,7 @@ void pre_proc_fx( alw_voicing[1] = st->voicing_fx[2]; move16(); -#ifdef REMOVE_EVS_DUPLICATES - analy_lp_ivas_fx( inp_12k8, L_FRAME, L_look, ener, A, epsP_h, epsP_l, lsp_new, lsp_mid, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing, INT_FS_12k8, EVS_MONO, 0, *Q_new, Q_r ); -#else - analy_lp_fx( inp_12k8, L_FRAME, L_look, ener, A, epsP_h, epsP_l, lsp_new, lsp_mid, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing, INT_FS_12k8, -1 /*IVAS_CODE !! LowRateFlag*/, *Q_new, Q_r ); -#endif + analy_lp_fx( inp_12k8, L_FRAME, L_look, ener, A, epsP_h, epsP_l, lsp_new, lsp_mid, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing, INT_FS_12k8, EVS_MONO, 0, *Q_new, Q_r ); lsp2lsf_fx( lsp_new, lsf_new, M, INT_FS_12k8 ); stab_fac = lsf_stab_fx( lsf_new, st->lsf_old1_fx, 0, L_FRAME ); @@ -1131,11 +1127,7 @@ void pre_proc_fx( Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); } -#ifdef REMOVE_EVS_DUPLICATES - analy_lp_ivas_fx( inp_16k, L_FRAME16k, L_look, ener, A, epsP_h, epsP_l, lsp_new, lsp_mid, st->lspold_enc_fx, st->pitch, st->voicing_fx, 16000, EVS_MONO, 0, *Q_new, Q_r ); -#else - analy_lp_fx( inp_16k, L_FRAME16k, L_look, ener, A, epsP_h, epsP_l, lsp_new, lsp_mid, st->lspold_enc_fx, st->pitch, st->voicing_fx, 16000, -1 /*IVAS_CODE !! LowRateFlag*/, *Q_new, Q_r ); -#endif + analy_lp_fx( inp_16k, L_FRAME16k, L_look, ener, A, epsP_h, epsP_l, lsp_new, lsp_mid, st->lspold_enc_fx, st->pitch, st->voicing_fx, 16000, EVS_MONO, 0, *Q_new, Q_r ); /*--------------------------------------------------------------* * Compute Weighted Input diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index d9389eb9c..9eb43c82b 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -41,9 +41,8 @@ #include "ivas_error_utils.h" #include "complex_basop.h" #include "ivas_stat_enc.h" -/*----------------------------------------------------------------------------------* - * Prototypes of RAM counting tool macros - *----------------------------------------------------------------------------------*/ + + ivas_error acelp_core_enc_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 inp_fx[], /* i : input signal of the current frame Q_new*/ @@ -68,57 +67,37 @@ ivas_error acelp_core_enc_fx( ); -void analy_lp_ivas_fx( - const Word16 speech[], /* i :(Q_new) pointer to the speech frame */ - const Word16 L_frame, /* i :(q0) length of the frame */ - const Word16 L_look, /* i :(q0) look-ahead */ - Word32 *ener, /* o :(Q_r) residual energy from Levinson-Durbin */ - Word16 A[], /* o :(q14) A(z) filter coefficients */ - Word16 epsP_h[], /* o :(high part of epsP(Q_r)) LP analysis residual energies for each iteration */ - Word16 epsP_l[], /* o :(low part of epsP(Q_r)) LP analysis residual energies for each iteration */ - Word16 lsp_new[], /* o :(q15) current frame LSPs */ - Word16 lsp_mid[], /* o :(q15) current mid-frame LSPs */ - Word16 lsp_old[], /* i/o:(q15) previous frame unquantized LSPs */ - const Word16 Top[2], /* i :(q0) open loop pitch lag */ - const Word16 Tnc[2], /* i :(q15) open loop pitch gain */ - const Word32 Core_sr, /* i :(q0) Internal core sampling rate */ -#ifdef REMOVE_EVS_DUPLICATES - const Word16 element_mode, /* i : element mode */ -#endif - const Word16 sec_chan_low_rate, /* i :(q0) flag to signal second channel */ - Word16 Q_new, /*i: stores Q for speech*/ - Word16 *Q_r /*stores q for ener*/ ); - -#ifndef REMOVE_EVS_DUPLICATES void analy_lp_fx( - const Word16 speech[], /* i : pointer to the speech frame Q_new*/ - const Word16 L_frame, /* i : length of the frame Q0*/ - const Word16 L_look, /* i : look-ahead Q0*/ - Word32 *ener, /* o : residual energy from Levinson-Durbin Q_r*/ - Word16 A[], /* o : A(z) filter coefficients Q14*/ - Word16 epsP_h[], /* o : LP analysis residual energies for each iteration Q_r*/ - Word16 epsP_l[], /* o : LP analysis residual energies for each iteration Q_r*/ - Word16 lsp_new[], /* o : current frame LSPs Q15*/ - Word16 lsp_mid[], /* o : current mid-frame LSPs Q15*/ - Word16 lsp_old[], /* i/o: previous frame unquantized LSPs Q15*/ - const Word16 Top[2], /* i : open loop pitch lag Q0*/ - const Word16 Tnc[2], /* i : open loop pitch gain Q15*/ - const Word32 Core_sr, /* i : Internal core sampling rate Q0*/ - const Word16 sec_chan_low_rate, /* i : flag to signal second channel Q0*/ - Word16 Q_new, - Word16 *Q_r ); -#endif - -void AVQ_cod_fx( /* o: comfort noise gain factor */ - const Word16 xri[], /* i: vector to quantize */ - Word16 xriq[], /* o: quantized normalized vector (assuming the bit budget is enough) */ - const Word16 NB_BITS, /* i: number of allocated bits */ - const Word16 Nsv, /* i: number of subvectors (lg=Nsv*8) */ - const Word16 Q_in_ref /* i: Scaling i */ + const Word16 speech[], /* i :(Q_new) pointer to the speech frame */ + const Word16 L_frame, /* i :(q0) length of the frame */ + const Word16 L_look, /* i :(q0) look-ahead */ + Word32 *ener, /* o :(Q_r) residual energy from Levinson-Durbin */ + Word16 A[], /* o :(q14) A(z) filter coefficients */ + Word16 epsP_h[], /* o :(high part of epsP(Q_r)) LP analysis residual energies for each iteration */ + Word16 epsP_l[], /* o :(low part of epsP(Q_r)) LP analysis residual energies for each iteration */ + Word16 lsp_new[], /* o :(q15) current frame LSPs */ + Word16 lsp_mid[], /* o :(q15) current mid-frame LSPs */ + Word16 lsp_old[], /* i/o:(q15) previous frame unquantized LSPs */ + const Word16 Top[2], /* i :(q0) open loop pitch lag */ + const Word16 Tnc[2], /* i :(q15) open loop pitch gain */ + const Word32 Core_sr, /* i :(q0) Internal core sampling rate */ + const Word16 element_mode, /* i : element mode */ + const Word16 sec_chan_low_rate, /* i :(q0) flag to signal second channel */ + Word16 Q_new, /* i : stores Q for speech */ + Word16 *Q_r /*stores q for ener*/ +); + +/*1 r: comfort noise gain factor */ +void AVQ_cod_fx( + const Word16 xri[], /* i: vector to quantize */ + Word16 xriq[], /* o: quantized normalized vector (assuming the bit budget is enough) */ + const Word16 NB_BITS, /* i: number of allocated bits */ + const Word16 Nsv, /* i: number of subvectors (lg=Nsv*8) */ + const Word16 Q_in_ref /* i: Scaling i */ ); void AVQ_encmux_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ const Word16 extl, /* i : extension layer */ Word16 xriq[], /* i/o: rounded subvectors [0..8*Nsv-1] followed by rounded bit allocations [8*Nsv..8*Nsv+Nsv-1] */ @@ -130,7 +109,7 @@ void AVQ_encmux_fx( ); void AVQ_encmux_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ const Word16 extl, /* i : extension layer */ Word16 xriq[], /* i/o: rounded subvectors [0..8*Nsv-1] followed by rounded bit allocations [8*Nsv..8*Nsv+Nsv-1] */ @@ -151,15 +130,15 @@ void bw_detect_fx( const Word16 mct_on, /* i : flag MCT mode */ const Word16 Q_spec ); -void core_switching_post_enc_fx( /*done */ - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 inp12k8[], /* i : i signal @12.8 kHz Qinp*/ - const Word16 inp16k[], /* i : i signal @16 kHz Qinp*/ - const Word16 A[], /* i : unquant. LP filter coefs. (Q12) */ - Word16 Qshift, - Word16 Q_new, - const Word16 Qsp, /* i/o : Q from acelp synthsis */ - Word16 *Qmus /* i/o : Q from mdct synthsis / Q of output synthesis */ +void core_switching_post_enc_fx( + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 inp12k8[], /* i : i signal @12.8 kHz Qinp*/ + const Word16 inp16k[], /* i : i signal @16 kHz Qinp*/ + const Word16 A[], /* i : unquant. LP filter coefs. (Q12) */ + Word16 Qshift, + Word16 Q_new, + const Word16 Qsp, /* i/o : Q from acelp synthsis */ + Word16 *Qmus /* i/o : Q from mdct synthsis / Q of output synthesis */ ); void core_switching_pre_enc_fx( @@ -170,8 +149,9 @@ void core_switching_pre_enc_fx( const Word16 last_element_mode /* i : last_element_mode Q0*/ ); -Word16 correlation_shift_fx( /* o : noise dependent voicing correction Q15 */ - const Word16 totalNoise_fx /* i/o: noise estimate over all critical bands Q8 */ +/*! r: noise dependent voicing correction Q15 */ +Word16 correlation_shift_fx( + const Word16 totalNoise_fx /* i/o: noise estimate over all critical bands Q8 */ ); void dtx_fx( diff --git a/lib_enc/transition_enc_fx.c b/lib_enc/transition_enc_fx.c index 5e50cac15..e0dd32927 100644 --- a/lib_enc/transition_enc_fx.c +++ b/lib_enc/transition_enc_fx.c @@ -212,13 +212,9 @@ void transition_enc_fx( IF( EQ_16( *tc_subfr, TC_0_0 ) ) { /* this is called only to compute unused bits */ -#ifdef REMOVE_EVS_DUPLICATES - config_acelp1_IVAS( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, -#else - config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, -#endif - L_FRAME, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, -1, TC_0_0, 3, NULL, unbits_ACELP, - st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); + config_acelp1_fx( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, + L_FRAME, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, -1, TC_0_0, 3, NULL, unbits_ACELP, + st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); } *clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, TRANSITION, xn_fx, gp_cl_fx, sub( shift_wsp, 1 ) ); @@ -328,13 +324,9 @@ void transition_enc_fx( IF( LE_16( sub( i_subfr, *tc_subfr ), L_SUBFR ) ) { -#ifdef REMOVE_EVS_DUPLICATES - config_acelp1_IVAS( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, -#else - config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, -#endif - st_fx->L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, -1, *tc_subfr, 2, NULL, - unbits_ACELP, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); + config_acelp1_fx( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, + st_fx->L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, -1, *tc_subfr, 2, NULL, + unbits_ACELP, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); } /*-----------------------------------------------------------------* @@ -1042,14 +1034,9 @@ void transition_enc_ivas_fx( IF( EQ_16( *tc_subfr, TC_0_0 ) ) { /* this is called only to compute unused bits */ - -#ifdef REMOVE_EVS_DUPLICATES - config_acelp1_IVAS( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, -#else - config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, -#endif - L_FRAME, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, -1, TC_0_0, 3, NULL, unbits_ACELP, - st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ + config_acelp1_fx( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, + L_FRAME, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, -1, TC_0_0, 3, NULL, unbits_ACELP, + st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); } @@ -1160,13 +1147,9 @@ void transition_enc_ivas_fx( IF( LE_16( sub( i_subfr, *tc_subfr ), L_SUBFR ) ) { -#ifdef REMOVE_EVS_DUPLICATES - config_acelp1_IVAS( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, -#else - config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, -#endif - st_fx->L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, -1, *tc_subfr, 2, NULL, - unbits_ACELP, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); + config_acelp1_fx( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, + st_fx->L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, -1, *tc_subfr, 2, NULL, + unbits_ACELP, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); } /*-----------------------------------------------------------------* -- GitLab From 1ecdfd6f7aecdf1da3655ac16fd8942d1f409f65 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 17 Apr 2025 15:52:49 +0200 Subject: [PATCH 2/3] rename file --- Workspace_msvc/lib_dec.vcxproj | 2 +- Workspace_msvc/lib_dec.vcxproj.filters | 6 +++--- ...celp_core_dec_ivas_fx.c => acelp_core_dec_fx.c} | 0 lib_dec/ivas_td_low_rate_dec_fx.c | 14 +++++++++++--- 4 files changed, 15 insertions(+), 7 deletions(-) rename lib_dec/{acelp_core_dec_ivas_fx.c => acelp_core_dec_fx.c} (100%) diff --git a/Workspace_msvc/lib_dec.vcxproj b/Workspace_msvc/lib_dec.vcxproj index 2839a5812..12f77b346 100644 --- a/Workspace_msvc/lib_dec.vcxproj +++ b/Workspace_msvc/lib_dec.vcxproj @@ -139,7 +139,7 @@ false - + diff --git a/Workspace_msvc/lib_dec.vcxproj.filters b/Workspace_msvc/lib_dec.vcxproj.filters index ebf15bd4c..25079058c 100644 --- a/Workspace_msvc/lib_dec.vcxproj.filters +++ b/Workspace_msvc/lib_dec.vcxproj.filters @@ -119,9 +119,6 @@ decoder_all_c - - decoder_all_c - decoder_all_c @@ -515,6 +512,9 @@ decoder_ivas_c + + decoder_all_c + diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_fx.c similarity index 100% rename from lib_dec/acelp_core_dec_ivas_fx.c rename to lib_dec/acelp_core_dec_fx.c diff --git a/lib_dec/ivas_td_low_rate_dec_fx.c b/lib_dec/ivas_td_low_rate_dec_fx.c index 8f09c1c7d..6419f8517 100644 --- a/lib_dec/ivas_td_low_rate_dec_fx.c +++ b/lib_dec/ivas_td_low_rate_dec_fx.c @@ -40,6 +40,13 @@ #include "prot_fx.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" + +/*-------------------------------------------------------------------* + * tdm_low_rate_dec_fx() + * + * Low-bitrate decoder + *-------------------------------------------------------------------*/ + void tdm_low_rate_dec_fx( Decoder_State *st, /* i/o: decoder static memory */ Word16 dct_epit[], /* o : GSC excitation in DCT domain Q_exc*/ @@ -188,6 +195,7 @@ void tdm_low_rate_dec_fx( return; } + /*---------------------------------------------------------------------* * decod_gen_2sbfr() * @@ -217,12 +225,12 @@ void decod_gen_2sbfr_fx( move32(); Word16 gain_inov = 0; /* Innovation gain */ move16(); - Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ - Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */ + Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ + Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */ Word16 voice_fac; /* voicing factor */ Word16 code[2 * L_SUBFR]; /* algebraic codevector */ const Word16 *p_Aq; /* Pointer to frame LP coefficient */ - Word16 *pt_pitch; /* pointer to Word16 pitch */ + Word16 *pt_pitch; /* pointer to Word16 pitch */ Word16 i_subfr; /* tmp variables */ Word16 L_frame; Word16 pitch_limit_flag; -- GitLab From 30d174cd2602b630f7ad4ea56061d8da79c6d5c5 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 17 Apr 2025 16:04:05 +0200 Subject: [PATCH 3/3] clang-format --- lib_enc/lsf_enc_fx.c | 4 ++-- lib_enc/pre_proc_fx.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_enc/lsf_enc_fx.c b/lib_enc/lsf_enc_fx.c index b26532b15..23ed7d0c2 100644 --- a/lib_enc/lsf_enc_fx.c +++ b/lib_enc/lsf_enc_fx.c @@ -1985,7 +1985,7 @@ static void first_VQstages( dist[1] = dist_buf + maxC; move16(); - set16_fx( idx_buf, 0, (const Word16) ( 2 * stagesVQ * maxC ) ); + set16_fx( idx_buf, 0, ( const Word16 )( 2 * stagesVQ * maxC ) ); set16_fx( parents, 0, maxC ); /* Set up inital distance vector */ @@ -2175,7 +2175,7 @@ static void first_VQstages_ivas_fx( dist[1] = dist_buf + maxC; move16(); - set16_fx( idx_buf, 0, (const Word16) ( 2 * stagesVQ * maxC ) ); + set16_fx( idx_buf, 0, ( const Word16 )( 2 * stagesVQ * maxC ) ); set16_fx( parents, 0, maxC ); /* Set up inital distance vector */ diff --git a/lib_enc/pre_proc_fx.c b/lib_enc/pre_proc_fx.c index cc8b64ca4..f7ebc8298 100644 --- a/lib_enc/pre_proc_fx.c +++ b/lib_enc/pre_proc_fx.c @@ -213,7 +213,7 @@ void pre_proc_fx( /*----------------------------------------------------------------* * Change the sampling frequency to 12.8 kHz *----------------------------------------------------------------*/ - modify_Fs_fx( signal_in, input_frame, st->input_Fs, new_inp_12k8, INT_FS_12k8, st->mem_decim_fx, (const Word16) ( EQ_16( st->max_bwidth, NB ) ) ); + modify_Fs_fx( signal_in, input_frame, st->input_Fs, new_inp_12k8, INT_FS_12k8, st->mem_decim_fx, ( const Word16 )( EQ_16( st->max_bwidth, NB ) ) ); Copy( new_inp_12k8, st->buf_speech_enc + L_FRAME32k, L_FRAME ); Scale_sig( st->buf_speech_enc + L_FRAME32k, L_FRAME, 1 ); /*------------------------------------------------------------------* -- GitLab