diff --git a/Workspace_msvc/lib_com.vcxproj b/Workspace_msvc/lib_com.vcxproj index 5b26a291129f7a52473b5e27eeb62f48de258b78..7a2aa8a7f66bcdd6ec2164f382b709a8b43cc925 100644 --- a/Workspace_msvc/lib_com.vcxproj +++ b/Workspace_msvc/lib_com.vcxproj @@ -277,7 +277,6 @@ - @@ -316,7 +315,6 @@ - diff --git a/Workspace_msvc/lib_com.vcxproj.filters b/Workspace_msvc/lib_com.vcxproj.filters index 5dabcfd91f636419343a3356e641aea94fe0f528..89b47a3fcf9b04744c7ba3e9fd1cfec159c27ca9 100644 --- a/Workspace_msvc/lib_com.vcxproj.filters +++ b/Workspace_msvc/lib_com.vcxproj.filters @@ -430,9 +430,6 @@ common_all_c - - common_all_c - common_all_c @@ -573,9 +570,6 @@ common_h - - common_h - common_h diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index 79a659eb08094da54b43617b4ee77772b5a21c66..d8d4563ed3a60fdf6325d71a81a73384c100f911 100644 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -1660,281 +1660,6 @@ static void decoder_selectCodec( return; } -/*-------------------------------------------------------------------* - * dec_prm_core() - * - * - *-------------------------------------------------------------------*/ - -static void dec_prm_core( - Decoder_State *st ) -{ - int16_t n, frame_size_index = -1; - - st->core = -1; - - if ( st->total_brate == FRAME_NO_DATA ) - { - st->m_frame_type = ZERO_FRAME; - } - else if ( st->total_brate == SID_2k40 ) - { - st->m_frame_type = SID_FRAME; - } - else - { - st->m_frame_type = ACTIVE_FRAME; - for ( n = 0; n < FRAME_SIZE_NB; ++n ) - { - if ( FrameSizeConfig[n].frame_bits == st->total_brate / FRAMES_PER_SEC ) - { - frame_size_index = n; - break; - } - } - - /* Get audio bandwidth info */ - st->bwidth = get_next_indice( st, FrameSizeConfig[frame_size_index].bandwidth_bits ); - st->bwidth += FrameSizeConfig[frame_size_index].bandwidth_min; - if ( st->bwidth > FB ) - { - st->bwidth = FB; - st->BER_detect = 1; - } - - if ( st->bwidth > SWB && st->total_brate < ACELP_16k40 ) - { - st->bwidth = SWB; - st->BER_detect = 1; - } - /* Skip reserved bit */ - get_next_indice_tmp( st, FrameSizeConfig[frame_size_index].reserved_bits ); - - if ( get_next_indice_1( st ) ) /* TCX */ - { - if ( get_next_indice_1( st ) ) - { - st->core = HQ_CORE; - } - else - { - st->core = TCX_20_CORE; - } - } - else /* ACELP */ - { - st->core = ACELP_CORE; - } - } - - return; -} - -/*-----------------------------------------------------------------* - * decision_matrix_core_dec() - * - * Read core signaling bits from the bitstream - * Set st->core, and st->bwidth if signalled together with the core. - *-----------------------------------------------------------------*/ - -static void decision_matrix_core_dec( - Decoder_State *st /* i/o: decoder state structure */ -) -{ - int16_t start_idx; - int32_t ind; - int16_t nBits; - - assert( st->bfi != 1 ); - - st->core = -1; - st->bwidth = -1; - - if ( st->total_brate == FRAME_NO_DATA || st->total_brate == SID_2k40 ) - { - st->core = ACELP_CORE; - } - /* SC-VBR */ - else if ( st->total_brate == PPP_NELP_2k80 ) - { - st->core = ACELP_CORE; - return; - } - - /*---------------------------------------------------------------------* - * ACELP/HQ core selection - *---------------------------------------------------------------------*/ - - if ( st->total_brate < ACELP_24k40 ) - { - st->core = ACELP_CORE; - } - else if ( st->total_brate >= ACELP_24k40 && st->total_brate <= ACELP_64k ) - { - /* read the ACELP/HQ core selection bit */ - st->core = get_next_indice( st, 1 ) * HQ_CORE; - } - else - { - st->core = HQ_CORE; - } - - /*-----------------------------------------------------------------* - * Read ACELP signaling bits from the bitstream - *-----------------------------------------------------------------*/ - - if ( st->core == ACELP_CORE ) - { - /* find the section in the ACELP signaling table corresponding to bitrate */ - start_idx = 0; - while ( acelp_sig_tbl[start_idx] != st->total_brate ) - { - start_idx++; - } - - /* skip the bitrate */ - start_idx += 1; - - /* retrieve the number of bits */ - nBits = (int16_t) acelp_sig_tbl[start_idx++]; - - /* retrieve the signaling indice */ - ind = acelp_sig_tbl[start_idx + get_next_indice( st, nBits )]; - st->bwidth = ( ind >> 3 ) & 0x7; - - /* convert signaling indice into signaling information */ - if ( ( ind & 0x7 ) == LR_MDCT ) - { - st->core = HQ_CORE; - } - } - - /*-----------------------------------------------------------------* - * Read HQ signaling bits from the bitstream - * Set HQ core type - *-----------------------------------------------------------------*/ - - if ( st->core == HQ_CORE ) - { - /* read the HQ/TCX core switching flag */ - if ( get_next_indice( st, 1 ) ) - { - st->core = TCX_20_CORE; - } - - /* For TCX: read/set band-width (needed for different I/O sampling rate support) */ - if ( st->core == TCX_20_CORE && st->total_brate > ACELP_16k40 ) - { - ind = get_next_indice( st, 2 ); - - if ( ind == 0 ) - { - st->bwidth = NB; - } - else if ( ind == 1 ) - { - st->bwidth = WB; - } - else if ( ind == 2 ) - { - st->bwidth = SWB; - } - else - { - st->bwidth = FB; - } - } - } - - return; -} - -/*-------------------------------------------------------------------* - * mdct_switching_dec() - * - * Set up MDCT core switching if indicated in the bitstream - *-------------------------------------------------------------------*/ - -void mdct_switching_dec_ivas_fx( - Decoder_State *st /* i/o: decoder state structure */ -) -{ - if ( !st->bfi ) - { - - if ( st->Opt_AMR_WB ) - { - return; - } - - - if ( st->total_brate == ACELP_13k20 || st->total_brate == ACELP_32k ) - { - st->mdct_sw_enable = MODE1; - } - else if ( ACELP_16k40 <= st->total_brate && st->total_brate <= ACELP_24k40 ) - { - st->mdct_sw_enable = MODE2; - } - - if ( st->codec_mode == MODE1 && st->mdct_sw_enable == MODE1 ) - { - /* Read ahead core signaling */ - int16_t next_bit_pos_save = st->next_bit_pos; - int16_t core_save = st->core; - int16_t bwidth_save = st->bwidth; - - decision_matrix_core_dec( st ); /* sets st->core */ - - if ( st->core == TCX_20_CORE ) - { - /* Trigger TCX */ - st->codec_mode = MODE2; - st->mdct_sw = MODE1; - } - else - { - /* Rewind bitstream */ - st->next_bit_pos = next_bit_pos_save; - if ( st->bfi ) - { - st->core = core_save; - st->bwidth = bwidth_save; - } - } - } - else if ( st->codec_mode == MODE2 && st->mdct_sw_enable == MODE2 ) - { - /* Read ahead core signaling */ - int16_t next_bit_pos_save = st->next_bit_pos; - int16_t core_save = st->core; - int16_t bwidth_save = st->bwidth; - - dec_prm_core( st ); /* sets st->core */ - - if ( st->core == HQ_CORE ) - { - /* Trigger HQ_CORE */ - st->codec_mode = MODE1; - st->mdct_sw = MODE2; - } - else - { - /* Rewind bitstream */ - st->next_bit_pos = next_bit_pos_save; - if ( st->bfi ) - { - st->core = core_save; - } - /* always reset bwidth, to not interfere with BER logic */ - st->bwidth = bwidth_save; - } - } - } - - return; -} - /*-------------------------------------------------------------------* * reset_elements() diff --git a/lib_com/bitstream_fx.c b/lib_com/bitstream_fx.c index d4938f399607265c110c754aa2eba32587d817b8..712a6905e67e78a5d38bc6406266f5d933fe86f3 100644 --- a/lib_com/bitstream_fx.c +++ b/lib_com/bitstream_fx.c @@ -143,29 +143,6 @@ void pack_bit( return; } -/*-------------------------------------------------------------------* - * unpack_bit() - * - * unpack a bit from packed octet - *-------------------------------------------------------------------*/ -static Word16 unpack_bit( - UWord8 **pt, /* i/o: pointer to octet array from which bit will be read */ - UWord8 *mask /* i/o: mask to indicate the bit in the octet */ -) -{ - Word16 bit; - - bit = s_and( **pt, *mask ) != 0; - *mask = (UWord8) shr( *mask, 1 ); - move16(); - IF( *mask == 0 ) - { - *mask = 0x80; - move16(); - ( *pt )++; - } - return bit; -} /*-------------------------------------------------------------------* * rate2AMRWB_IOmode() @@ -945,154 +922,6 @@ return; } -static void decoder_selectCodec( - Decoder_State *st, /* i/o: decoder state structure */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 bit0 ) -{ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - /* check if we are in AMR-WB IO mode */ - IF( EQ_32( total_brate, SID_1k75 ) || - EQ_32( total_brate, ACELP_6k60 ) || EQ_32( total_brate, ACELP_8k85 ) || EQ_32( total_brate, ACELP_12k65 ) || - EQ_32( total_brate, ACELP_14k25 ) || EQ_32( total_brate, ACELP_15k85 ) || EQ_32( total_brate, ACELP_18k25 ) || - EQ_32( total_brate, ACELP_19k85 ) || EQ_32( total_brate, ACELP_23k05 ) || EQ_32( total_brate, ACELP_23k85 ) ) - { - st->Opt_AMR_WB = 1; - move16(); - } - ELSE IF( total_brate != FRAME_NO_DATA ) - { - st->Opt_AMR_WB = 0; - move16(); - } - - /* select MODE1 or MODE2 */ - IF( st->Opt_AMR_WB ) - { - st->codec_mode = MODE1; - move16(); /**/ - } - ELSE - { - SWITCH( total_brate ) - { - case 0: - st->codec_mode = st->last_codec_mode; - move16(); - BREAK; - case 2400: - st->codec_mode = st->last_codec_mode; - move16(); - BREAK; - case 2800: - st->codec_mode = MODE1; - move16(); - BREAK; - case 7200: - st->codec_mode = MODE1; - move16(); - BREAK; - case 8000: - st->codec_mode = MODE1; - move16(); - BREAK; - case 9600: - st->codec_mode = MODE2; - move16(); - BREAK; - case 13200: - st->codec_mode = MODE1; - move16(); - BREAK; - case 16400: - st->codec_mode = MODE2; - move16(); - BREAK; - case 24400: - st->codec_mode = MODE2; - move16(); - BREAK; - case 32000: - st->codec_mode = MODE1; - move16(); - BREAK; - case 48000: - st->codec_mode = MODE2; - move16(); - BREAK; - case 64000: - st->codec_mode = MODE1; - move16(); - BREAK; - case 96000: - st->codec_mode = MODE2; - move16(); - BREAK; - case 128000: - st->codec_mode = MODE2; - move16(); - BREAK; - default: - /* validate that total_brate (derived from RTP packet or a file header) is one of the defined bit rates */ - st->codec_mode = st->last_codec_mode; - st->bfi = 1; - move16(); - move16(); - BREAK; - } - } - - IF( st->ini_frame == 0 ) - { - if ( EQ_16( st->codec_mode, -1 ) ) - { - st->codec_mode = MODE1; - move16(); - } - st->last_codec_mode = st->codec_mode; - move16(); - } - - /* set SID/CNG type */ - IF( EQ_32( total_brate, SID_2k40 ) ) - { - IF( EQ_16( bit0, G192_BIN0 ) ) - { - st->cng_type = LP_CNG; - move16(); - - /* force MODE1 when selecting LP_CNG */ - st->codec_mode = MODE1; - move16(); - } - ELSE - { - st->cng_type = FD_CNG; - move16(); - test(); - if ( EQ_16( st->last_codec_mode, MODE2 ) && EQ_32( st->last_total_brate, 13200 ) ) - { - st->codec_mode = MODE1; - move16(); - } - } - st->hTdCngDec->last_cng_type_fx = st->cng_type; /* CNG type switching at the first correctly received SID frame */ - move16(); - } - - - return; -} - - static void dec_prm_core( Decoder_State *st ) { Word16 n, frame_size_index, num_bits; @@ -1320,109 +1149,115 @@ static void decision_matrix_core_dec( * Set up MDCT core switching if indicated in the bit stream *-------------------------------------------------------------------*/ -static void mdct_switching_dec( +void mdct_switching_dec_fx( Decoder_State *st /* i/o: decoder state structure */ ) { - IF( st->Opt_AMR_WB != 0 ) - { - return; - } - - test(); - test(); - IF( EQ_32( st->total_brate, ACELP_13k20 ) || EQ_32( st->total_brate, ACELP_32k ) ) - { - st->mdct_sw_enable = MODE1; - move16(); - } - ELSE IF( LE_32( ACELP_16k40, st->total_brate ) && LE_32( st->total_brate, ACELP_24k40 ) ) + if ( !st->bfi ) { - st->mdct_sw_enable = MODE2; - move16(); - } - - test(); - test(); - IF( EQ_16( st->codec_mode, MODE1 ) && EQ_16( st->mdct_sw_enable, MODE1 ) ) - { - /* Read ahead core mode signaling */ - Word16 next_bit_pos_save; - Word16 core_save; - Word16 bwidth_save; - - next_bit_pos_save = st->next_bit_pos; - move16(); - core_save = st->core; - move16(); - bwidth_save = st->bwidth; - move16(); - - decision_matrix_core_dec( st ); /* sets st->core */ + IF( st->Opt_AMR_WB != 0 ) + { + return; + } - IF( EQ_16( st->core, TCX_20_CORE ) ) + test(); + test(); + IF( EQ_32( st->total_brate, ACELP_13k20 ) || EQ_32( st->total_brate, ACELP_32k ) ) { - /* Trigger TCX */ - st->codec_mode = MODE2; + st->mdct_sw_enable = MODE1; move16(); - st->mdct_sw = MODE1; + } + ELSE IF( LE_32( ACELP_16k40, st->total_brate ) && LE_32( st->total_brate, ACELP_24k40 ) ) + { + st->mdct_sw_enable = MODE2; move16(); } - ELSE + + test(); + test(); + IF( EQ_16( st->codec_mode, MODE1 ) && EQ_16( st->mdct_sw_enable, MODE1 ) ) { - /* Rewind bitstream */ - st->next_bit_pos = next_bit_pos_save; + /* Read ahead core mode signaling */ + Word16 next_bit_pos_save; + Word16 core_save; + Word16 bwidth_save; + + next_bit_pos_save = st->next_bit_pos; + move16(); + core_save = st->core; + move16(); + bwidth_save = st->bwidth; move16(); - IF( st->bfi != 0 ) + + decision_matrix_core_dec( st ); /* sets st->core */ + + IF( EQ_16( st->core, TCX_20_CORE ) ) { - st->core = core_save; + /* Trigger TCX */ + st->codec_mode = MODE2; move16(); - st->bwidth = bwidth_save; + st->mdct_sw = MODE1; + move16(); + } + ELSE + { + /* Rewind bitstream */ + st->next_bit_pos = next_bit_pos_save; move16(); + IF( st->bfi != 0 ) + { + st->core = core_save; + move16(); + st->bwidth = bwidth_save; + move16(); + } } } - } - ELSE IF( EQ_16( st->codec_mode, MODE2 ) && EQ_16( st->mdct_sw_enable, MODE2 ) ) - { - /* Read ahead core mode signaling */ - Word16 next_bit_pos_save; - Word16 core_save; - Word16 bwidth_save; - - next_bit_pos_save = st->next_bit_pos; - move16(); - core_save = st->core; - move16(); - bwidth_save = st->bwidth; - move16(); - - dec_prm_core( st ); /* sets st->core */ - - IF( EQ_16( st->core, HQ_CORE ) ) + ELSE IF( EQ_16( st->codec_mode, MODE2 ) && EQ_16( st->mdct_sw_enable, MODE2 ) ) { - /* Trigger HQ_CORE */ - st->codec_mode = MODE1; + /* Read ahead core mode signaling */ + Word16 next_bit_pos_save; + Word16 core_save; + Word16 bwidth_save; + + next_bit_pos_save = st->next_bit_pos; move16(); - st->mdct_sw = MODE2; + core_save = st->core; move16(); - } - ELSE - { - /* Rewind bitstream */ - st->next_bit_pos = next_bit_pos_save; + bwidth_save = st->bwidth; move16(); - if ( st->bfi != 0 ) + + dec_prm_core( st ); /* sets st->core */ + + IF( EQ_16( st->core, HQ_CORE ) ) { - st->core = core_save; + /* Trigger HQ_CORE */ + st->codec_mode = MODE1; + move16(); + st->mdct_sw = MODE2; + move16(); + } + ELSE + { + /* Rewind bitstream */ + st->next_bit_pos = next_bit_pos_save; + move16(); + if ( st->bfi != 0 ) + { + st->core = core_save; + move16(); + } + /* always reset bwidth, to not interfere with BER logic */ + st->bwidth = bwidth_save; move16(); } - /* always reset bwidth, to not interfere with BER logic */ - st->bwidth = bwidth_save; - move16(); } } + + return; } + /*-------------------------------------------------------------------* * BRATE2IDX_fx() * @@ -1548,594 +1383,84 @@ Word32 BIT_ALLOC_IDX_16KHZ_fx( Word32 brate, Word16 ctype, Word16 sfrm, Word16 t return L_temp; } + /*-------------------------------------------------------------------* - * read_indices_mime_handle_dtx() + * berCheck() * - * Handle DTX for MIME and RTP_DUMP decoding. - * Returns the actual total_brate. + * Check for bit errors in channel aware signalling. *-------------------------------------------------------------------*/ -static Word32 read_indices_mime_handle_dtx( - Decoder_State *st, - Word16 isAMRWB_IOmode, - Word16 core_mode, - Word32 total_brate, - Word16 sti, - Word16 speech_lost, - Word16 no_data ) +static void berCheck( + Decoder_State *st, /* i/o: decoder state structure */ + Word16 *coder_type /* i/o: coder type */ +) { - Word16 curr_ft_good_sp = 0; - Word16 speech_bad = 0; - Word16 sid_upd_bad = 0, sid_update = 0; - Word16 amrwb_sid_first = 0; /* derived from sti SID_FIRST indicator in AMRWB payload */ - move16(); - move16(); - move16(); - move16(); - move16(); - - /* keep st->CNG , st_bfi and total_brate updated for proper synthesis in DTX and FER */ - IF( GT_32( total_brate, SID_2k40 ) ) + /* In case of RF flag = 1, and valid RF packet with primary and partial copy */ + test(); + test(); + IF( ( EQ_16( st->bwidth, NB ) || EQ_16( st->bwidth, FB ) ) || ( GE_16( *coder_type, TRANSITION ) ) ) { - if ( NE_16( st->bfi, 1 ) ) /* so far derived from q bit in AMRWB/AMRWBIO cases */ + if ( EQ_16( st->use_partial_copy, 1 ) ) { - curr_ft_good_sp = 1; + st->use_partial_copy = 0; move16(); } - } - /* handle q_bit and lost_sp clash , assume worst case */ - IF( speech_lost != 0 ) /* overrides a good q_bit */ - { - curr_ft_good_sp = 0; + st->bfi = 1; + move16(); + st->bwidth = st->last_bwidth; + move16(); + st->BER_detect = 1; move16(); - st->bfi = 1; /* override qbit */ + *coder_type = GENERIC; move16(); } - /* now_bfi_fx has been set based on q_bit and ToC fields */ + return; +} +/*-------------------------------------------------------------------* + * getPartialCopyInfo() + * + * Check if the frame includes a partial copy for channel aware processing. + *-------------------------------------------------------------------*/ - /* SID_UPDATE check */ - test(); - IF( EQ_32( total_brate, SID_1k75 ) || EQ_32( total_brate, SID_2k40 ) ) +void getPartialCopyInfo( + Decoder_State *st, /* i/o: decoder state structure */ + Word16 *coder_type, + Word16 *sharpFlag ) +{ + Word16 nBits; + Word16 ind; + /* check the rf flag in the packet */ + get_rfFlag( st, &( st->rf_flag ), &nBits, &ind ); + + /* get rf frame type info */ + get_rfFrameType( st, &( st->rf_frame_type ) ); + + /* Get the FEC offset info */ + get_rf_fec_offset( st, &( st->rf_fec_offset ) ); + + /* reset number of target bits in case of rate switching */ + st->rf_target_bits = 0; + move16(); + + /* Get the number of bits used for RF*/ + IF( EQ_16( st->rf_flag, 1 ) ) { - IF( st->bfi == 0 ) + *coder_type = s_and( ind, 0x7 ); + move16(); + st->bwidth = s_and( shr( ind, 3 ), 0x7 ); + move16(); + *sharpFlag = s_and( shr( ind, 6 ), 0x1 ); + move16(); + st->codec_mode = MODE2; + move16(); + get_rfTargetBits( st->rf_frame_type, &( st->rf_target_bits ) ); + + IF( EQ_16( st->bfi, FRAMEMODE_FUTURE ) ) { - /* typically from q bit */ - sid_update = 1; - move16(); - } - ELSE - { - sid_upd_bad = 1; /* may happen in saving from e.g. a CS-connection */ - move16(); - } - } - - test(); - test(); - IF( isAMRWB_IOmode && total_brate == 0 && sti == 0 ) - { - IF( st->bfi ) - { - sid_upd_bad = 1; /* corrupt sid_first, signaled as bad sid */ - move16(); - } - ELSE - { - amrwb_sid_first = 1; /* 1-sti */ - move16(); - } - } - - test(); - test(); - test(); - test(); - IF( sid_upd_bad != 0 && ( ( isAMRWB_IOmode != 0 && st->Opt_AMR_WB == 0 ) || /* switch to AMRWBIO */ - ( NE_16( isAMRWB_IOmode, 1 ) && EQ_16( st->Opt_AMR_WB, 1 ) ) /* switch from AMRWBIO */ - ) ) - { - /* do not allow a normal start of CNG synthesis if this SID(with BER or FER) is a switch to/from AMRWBIO */ - sid_upd_bad = 0; /* revert this detection due to AMRWBIO/EVS mode switch */ - move16(); - total_brate = 0; - move32(); - no_data = 1; - move16(); - assert( st->bfi == 1 ); /* bfi stays 1 */ - } - - test(); - if ( GT_32( total_brate, SID_2k40 ) && EQ_16( st->bfi, 1 ) ) /* typically from q bit */ - { - speech_bad = 1; /* initial assumption, CNG synt state decides what to actually do */ - move16(); - } - /* all frame types decoded */ - - /* update CNG synthesis state */ - /* Decoder can only enter CNG-synthesis for CNG frame types (sid_upd, sid_bad, sid_first) */ - IF( st->CNG_fx != 0 ) - { - /* We were in CNG synthesis */ - if ( curr_ft_good_sp != 0 ) - { - /* only a good speech frame makes decoder leave CNG synthesis */ - st->CNG_fx = 0; - move16(); - } - } - ELSE - { - /* We were in SPEECH synthesis */ - /* only a received SID frame can make the decoder enter into CNG synthesis */ - test(); - test(); - if ( amrwb_sid_first || sid_update || sid_upd_bad ) - { - st->CNG_fx = 1; - move16(); - } - } - - /* Now modify bfi flag for the decoder's SPEECH/CNG synthesis logic */ - /* in SPEECH synthesis, make sure to activate speech plc for a received no_data frame, - no_data frames may be injected by the network or by the dejitter buffer */ - /* modify bfi_flag to stay/move into the correct decoder PLC section */ - test(); - if ( ( st->CNG_fx == 0 ) && ( no_data != 0 ) ) - { - /* treat no_data received in speech synthesis as SP_LOST frames, SPEECH PLC code will now become active */ - st->bfi = 1; - move16(); - /* total_brate= 0; always zero for no_data */ - } - - /* in CNG */ - /* handle bad speech frame(and bad sid frame) in the decoders CNG synthesis settings pair (total_brate, bfi) */ - test(); - test(); - test(); - test(); - IF( ( st->CNG_fx != 0 && ( speech_bad || speech_lost || no_data ) ) || /* SP_BAD or SPEECH_LOST) --> stay in CNG */ - sid_upd_bad ) /* SID_UPD_BAD --> start/stay CNG */ - { - st->bfi = 0; /* mark as good to not start speech PLC */ - move16(); - total_brate = 0; /* this zeroing needed for speech_bad, sid_bad frames */ - move32(); - } - - - /* now bfi, total_brate are set by RX-DTX handler:: - bfi==0, total_brate!=0 cng or speech pending bitrate - bfi==0, total_brate==0 cng will continue or start(sid_first, sid_bad) - bfi==1, total_brate!=0 speech plc - bfi==1, total_brate==0 , speech plc - */ - - - /* handle available AMRWB/AMRWBIO MIME header ToC rate-info at startup */ - test(); - test(); - test(); - test(); - IF( ( EQ_16( st->bfi, 1 ) && st->ini_frame == 0 ) && - ( ( st->amrwb_rfc4867_flag != 0 ) || ( st->amrwb_rfc4867_flag == 0 && isAMRWB_IOmode != 0 ) ) ) /*AMRWB ToC */ - { - Word32 init_rate; - - init_rate = total_brate; /* default , may have been modified from original ToC value */ - move32(); - - test(); - IF( speech_lost != 0 || no_data != 0 ) - { - init_rate = ACELP_12k65; /* make sure the decoder starts up in a selected AMRWB mode */ - move32(); - } - ELSE IF( speech_bad != 0 ) - { - init_rate = AMRWB_IOmode2rate[core_mode]; /* read from from ToC */ - move32(); - } - st->total_brate = init_rate; /* not updated on bfi as decoderSelectCodec is not called below */ - move32(); - st->core_brate = init_rate; - move32(); - } - - return total_brate; -} - - -/*-------------------------------------------------------------------* - * read_indices_mime_handle_sti_and_all_zero_bits() - * - * Handle STI and frames with all zero bits for MIME and RTP_DUMP decoding. - *-------------------------------------------------------------------*/ - -static void read_indices_mime_handle_sti_and_all_zero_bits( - Decoder_State *st, - Word32 *total_brate, - Word16 sti ) -{ - Word16 k; - - IF( sti == 0 ) - { - *total_brate = 0; /* signal received SID_FIRST as a good frame with no bits */ - move32(); - FOR( k = 0; k < 35; k++ ) - { - st->bfi = s_or( st->bfi, st->bit_stream[k] ); /* partity check of 35 zeroes, any single 1 gives BFI */ - move16(); - } - } - /* all zero bit SID_update results in a valid LP filter with extremely high LP-filter-gain */ - /* all zero bits signal may be a result of CS bit errors or erronesouly injected by gateways or bad dejitter handlers */ - IF( EQ_16( sti, 1 ) ) - { /*sid_update received */ - Word16 sum = 0; - move16(); - FOR( k = 0; k < 35; k++ ) - { - sum = add( sum, st->bit_stream[k] ); /* check of 35 zeroes */ - } - - if ( sum == 0 ) - { - st->bfi = 1; /* eventually becomes SID_UPD_BAD */ - move16(); - } - } -} - - -/*------------------------------------------------------------------------------------------* - * read_indices_mime() - * - * Read indices from MIME formatted bitstream to the buffer - * The magic word and number of channnels should be consumed before calling this function - *-------------------------------------------------------------------------------------------*/ - -Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem */ - Decoder_State *st, /* i/o: decoder state structure */ - FILE *file, /* i : bitstream file */ - Word16 rew_flag /* i : rewind flag (rewind file after reading) */ -) -{ - Word16 k, isAMRWB_IOmode, cmi, core_mode = -1, qbit, sti; - UWord8 header; - UWord8 pFrame[( MAX_BITS_PER_FRAME + 7 ) >> 3]; - UWord8 mask = 0x80, *pt_pFrame = pFrame; - UWord16 *bit_stream_ptr; - Word16 num_bits; - Word32 total_brate; - UWord16 utmp; - Word32 L_tmp; - Word16 speech_lost = 0, no_data = 0; - Word16 num_bytes_read; - - move16(); - move16(); - move16(); - move16(); - - st->BER_detect = 0; - move16(); - st->bfi = 0; - move16(); - st->mdct_sw_enable = 0; - move16(); - st->mdct_sw = 0; - move16(); - reset_indices_dec_fx( st ); - - /* read the FT Header field from the bitstream */ - IF( NE_32( fread( &header, sizeof( UWord8 ), 1, file ), 1 ) ) - { - IF( ferror( file ) ) - { - /* error during reading */ - fprintf( stderr, "\nError reading the bitstream !" ); - exit( -1 ); - } - ELSE - { - /* end of file reached */ - return 0; - } - } - - /* init local RXDTX flags */ - sti = -1; - move16(); - - IF( st->amrwb_rfc4867_flag != 0 ) - { - /* RFC 4867 - 5.3 .... - Each stored speech frame starts with a one-octet frame header with - the following format: - 0 1 2 3 4 5 6 7 - +-+-+-+-+-+-+-+-+ - |P| FT |Q|P|P| - +-+-+-+-+-+-+-+-+ - The FT field and the Q bit are defined in the same way as in - Section 4.3.2. The P bits are padding and MUST be set to 0, and MUST be ignored. */ - - isAMRWB_IOmode = 1; - move16(); - qbit = s_and( shr( header, 2 ), 0x01 ); /* b2 bit (b7 is the F bit ) */ - st->bfi = !qbit; - move16(); - core_mode = s_and( shr( header, 3 ), 0x0F ); /* b6..b3 */ - total_brate = AMRWB_IOmode2rate[core_mode]; /* get the frame length from the header */ - move32(); - } - ELSE - { - /*0 1 2 3 4 5 6 7 MS-bit ---> LS-bit - +-+-+-+-+-+-+-+-+ - |H|F|E|x| brate | - +-+-+-+-+-+-+-+-+ - where : - "E|x| brate " is the 6 bit "FT" -field - x is unused if E=0, (should be 0 ) - x is the q-bit if E=1, q==1(good), Q==0(bad, maybe bit errors in payload ) - H,F always 0 in RTP format. - */ - isAMRWB_IOmode = extract_l( GT_16( s_and( header, 0x20 ), 0 ) ); /* get EVS mode-from header */ /* b2 */ - core_mode = s_and( header, 0x0F ); /* b4,b5,b6,b7 */ - - IF( isAMRWB_IOmode ) - { - qbit = extract_l( GT_16( s_and( header, 0x10 ), 0 ) ); /* get Q bit, valid for IO rates */ /* b3 */ - total_brate = AMRWB_IOmode2rate[core_mode]; - move32(); - } - ELSE - { - qbit = 1; /* assume good q_bit for the unused EVS-mode bit, complete ToC validity checked later */ - move16(); - total_brate = PRIMARYmode2rate[core_mode]; - move32(); - } - st->bfi = !qbit; - move16(); - } - - - /* set up RX-DTX-handler input */ - if ( EQ_16( core_mode, 14 ) ) - { - /* SP_LOST */ - speech_lost = 1; - move16(); - } - if ( EQ_16( core_mode, 15 ) ) - { - /* NO_DATA unsent CNG frame OR any frame marked or injected as no_data by e.g a signaling layer or dejitter buffer */ - no_data = 1; - move16(); - } - - Mpy_32_16_ss( total_brate, 5243, &L_tmp, &utmp ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - num_bits = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ - st->total_num_bits = num_bits; - move16(); - - IF( total_brate < 0 ) - { - /* validate that total_brate (derived from RTP packet or a file header) is one of the defined bit rates */ - fprintf( stderr, "\n Error. Illegal total bit rate (= %d) in MIME ToC header \n", total_brate ); - /* num_bits = -1; not needed as BASOP multiplication preserves sign */ - } - - /* Check correctness of ToC headers */ - IF( st->amrwb_rfc4867_flag == 0 ) - { - /* EVS ToC header (FT field(b2-b7), H bit (b0), F bit (b1) , (EVS-modebit(b2)=0 unused(Qbit)(b3)==0) */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( isAMRWB_IOmode == 0 ) && ( ( num_bits < 0 ) || ( s_and( header, 0x80 ) > 0 ) || ( s_and( header, 0x40 ) > 0 ) || s_and( header, 0x30 ) != 0x00 ) ) - { - /* incorrect FT header */ - fprintf( stderr, "\nError in EVS FT ToC header(%02x) ! ", header ); - exit( -1 ); - } - ELSE IF( ( isAMRWB_IOmode != 0 ) && ( ( num_bits < 0 ) || ( s_and( header, 0x80 ) > 0 ) || ( s_and( header, 0x40 ) > 0 ) ) ) /* AMRWBIO */ - { - /* incorrect IO FT header */ - fprintf( stderr, "\nError in EVS(AMRWBIO) FT ToC header(%02x) ! ", header ); - exit( -1 ); - } - } - ELSE - { - /* legacy AMRWB ToC, is only using Padding bits which MUST be ignored */ - IF( num_bits < 0 ) - { - /* incorrect FT header */ - fprintf( stderr, "\nError in AMRWB RFC4867 Toc(FT) header(%02x) !", header ); - exit( -1 ); - } - } - - /* read serial stream of indices from file to the local buffer */ - num_bytes_read = extract_l( fread( pFrame, sizeof( UWord8 ), shr( add( num_bits, 7 ), 3 ), file ) ); - IF( NE_16( num_bytes_read, shr( add( num_bits, 7 ), 3 ) ) ) - { - fprintf( stderr, "\nError, invalid number of bytes read ! Exiting ! \n" ); - exit( -1 ); - } - - /* in case rew_flag is set, rewind the file and return */ - /* (used in io_dec() to attempt print out info about technologies and to initialize the codec ) */ - IF( rew_flag ) - { - st->total_brate = total_brate; /* used for the codec banner output */ - move32(); - test(); - test(); - IF( st->bfi == 0 && speech_lost == 0 && no_data == 0 ) - { - decoder_selectCodec( st, total_brate, unpack_bit( &pt_pFrame, &mask ) ? G192_BIN1 : G192_BIN0 ); - } - return 1; - } - - - /* unpack speech data */ - bit_stream_ptr = st->bit_stream; - FOR( k = 0; k < num_bits; k++ ) - { - IF( isAMRWB_IOmode ) - { - st->bit_stream[sort_ptr[core_mode][k]] = unpack_bit( &pt_pFrame, &mask ); - move16(); - bit_stream_ptr++; - } - ELSE - { - *bit_stream_ptr++ = unpack_bit( &pt_pFrame, &mask ); - move16(); - } - } - - /* unpack auxiliary bits */ - /* Note: the cmi bits are unpacked for demo purposes; */ - test(); - IF( isAMRWB_IOmode && EQ_32( total_brate, SID_1k75 ) ) - { - sti = unpack_bit( &pt_pFrame, &mask ); - cmi = shl( unpack_bit( &pt_pFrame, &mask ), 3 ); - cmi = s_or( cmi, shl( unpack_bit( &pt_pFrame, &mask ), 2 ) ); - cmi = s_or( cmi, shl( unpack_bit( &pt_pFrame, &mask ), 1 ) ); - cmi = s_or( cmi, unpack_bit( &pt_pFrame, &mask ) ); - - read_indices_mime_handle_sti_and_all_zero_bits( st, &total_brate, sti ); - } - - /*add two zero bytes for arithmetic coder flush*/ - FOR( k = 0; k < 2 * 8; ++k ) - { - *bit_stream_ptr++ = 0; - move16(); - } - - /* MIME RX_DTX handler */ - IF( !rew_flag ) - { - total_brate = read_indices_mime_handle_dtx( st, isAMRWB_IOmode, core_mode, total_brate, sti, speech_lost, no_data ); - } - - IF( st->bfi == 0 ) - { - /* select MODE1 or MODE2 in MIME */ - IF( *st->bit_stream ) - { - decoder_selectCodec( st, total_brate, G192_BIN1 ); - } - ELSE - { - decoder_selectCodec( st, total_brate, G192_BIN0 ); - } - /* a change of the total bitrate should not be known to the decoder, if the received frame was truly lost */ - st->total_brate = total_brate; - move32(); - mdct_switching_dec( st ); - } - /* else{ bfi stay in past synthesis mode(SP,CNG) } */ - - return 1; -} - -/*-------------------------------------------------------------------* - * berCheck() - * - * Check for bit errors in channel aware signalling. - *-------------------------------------------------------------------*/ - -static void berCheck( - Decoder_State *st, /* i/o: decoder state structure */ - Word16 *coder_type /* i/o: coder type */ -) -{ - /* In case of RF flag = 1, and valid RF packet with primary and partial copy */ - test(); - test(); - IF( ( EQ_16( st->bwidth, NB ) || EQ_16( st->bwidth, FB ) ) || ( GE_16( *coder_type, TRANSITION ) ) ) - { - if ( EQ_16( st->use_partial_copy, 1 ) ) - { - st->use_partial_copy = 0; - move16(); - } - - st->bfi = 1; - move16(); - st->bwidth = st->last_bwidth; - move16(); - st->BER_detect = 1; - move16(); - *coder_type = GENERIC; - move16(); - } - - return; -} - -/*-------------------------------------------------------------------* - * getPartialCopyInfo() - * - * Check if the frame includes a partial copy for channel aware processing. - *-------------------------------------------------------------------*/ - -void getPartialCopyInfo( - Decoder_State *st, /* i/o: decoder state structure */ - Word16 *coder_type, - Word16 *sharpFlag ) -{ - Word16 nBits; - Word16 ind; - /* check the rf flag in the packet */ - get_rfFlag( st, &( st->rf_flag ), &nBits, &ind ); - - /* get rf frame type info */ - get_rfFrameType( st, &( st->rf_frame_type ) ); - - /* Get the FEC offset info */ - get_rf_fec_offset( st, &( st->rf_fec_offset ) ); - - /* reset number of target bits in case of rate switching */ - st->rf_target_bits = 0; - move16(); - - /* Get the number of bits used for RF*/ - IF( EQ_16( st->rf_flag, 1 ) ) - { - *coder_type = s_and( ind, 0x7 ); - move16(); - st->bwidth = s_and( shr( ind, 3 ), 0x7 ); - move16(); - *sharpFlag = s_and( shr( ind, 6 ), 0x1 ); - move16(); - st->codec_mode = MODE2; - move16(); - get_rfTargetBits( st->rf_frame_type, &( st->rf_target_bits ) ); - - IF( EQ_16( st->bfi, FRAMEMODE_FUTURE ) ) - { - st->use_partial_copy = 1; + st->use_partial_copy = 1; move16(); /* now set the frame mode to normal mode */ test(); @@ -2418,148 +1743,6 @@ void get_NextCoderType_fx( move16(); } -/*-------------------------------------------------------------------* - * read_indices_from_djb_fx() - * - * Read indices from the de-jitter buffer payload (works also for AMR-WB IO mode) - *-------------------------------------------------------------------*/ - -void read_indices_from_djb_fx( - Decoder_State *st, /* i/o: decoder state structure */ - UWord8 *pt_stream, /* i : bitstream file */ - Word16 num_bits, /* i : input frame length in bits */ - Word16 isAMRWB_IOmode, - Word16 core_mode, - Word16 qbit, - Word16 partialframe, /* i : partial frame information */ - Word16 next_coder_type /* i : next coder type information */ -) -{ - Word16 k; - UWord8 mask = 0x80; - Word16 no_data = 0; - Word16 sti = -1; - UWord16 *bit_stream_ptr; - Word32 total_brate; - Word16 speech_lost = 0; - - move16(); - move16(); - move16(); - move16(); - - st->bfi = 0; - move16(); - st->BER_detect = 0; - move16(); - st->mdct_sw_enable = 0; - move16(); - st->mdct_sw = 0; - move16(); - reset_indices_dec_fx( st ); - - st->bfi = !qbit; - move16(); - total_brate = L_mult0( num_bits, 50 ); - st->total_num_bits = num_bits; - move16(); - - IF( num_bits == 0 ) /* guess type of missing frame for SP_LOST and NO_DATA */ - { - speech_lost = st->CNG_fx == 0; - move16(); - move16(); - no_data = st->CNG_fx != 0; - move16(); - } - - test(); - IF( partialframe || st->prev_use_partial_copy ) - { - st->next_coder_type = next_coder_type; - move16(); - } - ELSE - { - st->next_coder_type = INACTIVE; - move16(); - } - - if ( EQ_16( partialframe, 1 ) ) - { - st->bfi = 2; - move16(); - } - - /* unpack speech data */ - bit_stream_ptr = st->bit_stream; - /* convert bitstream from compact bytes to short values and store it in decoder state */ - FOR( k = 0; k < num_bits; k++ ) - { - test(); - IF( EQ_16( st->bitstreamformat, VOIP_RTPDUMP ) && isAMRWB_IOmode ) - { - st->bit_stream[sort_ptr[core_mode][k]] = unpack_bit( &pt_stream, &mask ); - move16(); - bit_stream_ptr++; - } - ELSE - { - *bit_stream_ptr++ = unpack_bit( &pt_stream, &mask ); - move16(); - } - } - - /* unpack auxiliary bits */ - test(); - IF( isAMRWB_IOmode && EQ_32( total_brate, SID_1k75 ) ) - { - IF( EQ_16( st->bitstreamformat, VOIP_RTPDUMP ) ) - { - /* A.2.2.1.3: AMR-WB SID_1k75 frame is followed by STI bit and CMI bits */ - sti = unpack_bit( &pt_stream, &mask ); - } - ELSE - { - /* VOIP_G192_RTP does not contain STI and CMI */ - sti = 1; - move16(); - } - read_indices_mime_handle_sti_and_all_zero_bits( st, &total_brate, sti ); - } - - /* add two zero bytes for arithmetic coder flush */ - FOR( k = 0; k < 8 * 2; ++k ) - { - *bit_stream_ptr++ = 0; - move16(); - } - - total_brate = read_indices_mime_handle_dtx( st, isAMRWB_IOmode, core_mode, total_brate, sti, speech_lost, no_data ); - /* st->CNG_fx set inside */ - - IF( NE_16( st->bfi, 1 ) ) - { - /* select Mode 1 or Mode 2 */ - IF( *st->bit_stream ) - { - decoder_selectCodec( st, total_brate, G192_BIN1 ); - } - ELSE - { - decoder_selectCodec( st, total_brate, G192_BIN0 ); - } - - - /* a change of the total bitrate should not be known to the decoder, if the received frame was truly lost */ - st->total_brate = total_brate; - move32(); - - mdct_switching_dec( st ); - } -} - - /*-------------------------------------------------------------------* * get_indice_preview() * diff --git a/lib_com/cldfb_evs.c b/lib_com/cldfb_evs.c index d74b9b64671902f550e2b560d4b3a3992a05ee3e..c28a534d63b01c63d73249732fba395ba4311f79 100644 --- a/lib_com/cldfb_evs.c +++ b/lib_com/cldfb_evs.c @@ -338,7 +338,7 @@ static void calcModulationAndFolding( Word16 *rY, } -/* cldfbAnalysisFiltering +/* cldfbAnalysis_fx Parameters: cldfbBank I/O: handle to analysis CLDFB filter struct @@ -356,14 +356,15 @@ static void calcModulationAndFolding( Word16 *rY, Returns: void */ -void cldfbAnalysisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, - Word32 **rAnalysis, - Word32 **iAnalysis, - CLDFB_SCALE_FACTOR *scaleFactor, - const Word16 *timeIn, // Q(15-timeIn_e) - const Word16 timeIn_e, - const Word16 nTimeSlots, - Word32 *pWorkBuffer // Qx +void cldfbAnalysis_fx( + HANDLE_CLDFB_FILTER_BANK cldfbBank, + Word32 **rAnalysis, + Word32 **iAnalysis, + CLDFB_SCALE_FACTOR *scaleFactor, + const Word16 *timeIn, // Q(15-timeIn_e) + const Word16 timeIn_e, + const Word16 nTimeSlots, + Word32 *pWorkBuffer // Qx ) { @@ -610,7 +611,7 @@ void cldfbAnalysisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, } -/* cldfbSynthesisFiltering +/* cldfbSynthesis_fx Parameters: cldfbBank I/O: handle to analysis CLDFB filter struct @@ -629,14 +630,15 @@ void cldfbAnalysisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, Returns: void */ -void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, - Word32 **rAnalysis, - Word32 **iAnalysis, - const CLDFB_SCALE_FACTOR *scaleFactor, - Word16 *timeOut, // Q(15-timeOut_e) - const Word16 timeOut_e, - const Word16 nTimeSlots, - Word32 *pWorkBuffer // Qx +void cldfbSynthesis_fx( + HANDLE_CLDFB_FILTER_BANK cldfbBank, + Word32 **rAnalysis, + Word32 **iAnalysis, + const CLDFB_SCALE_FACTOR *scaleFactor, + Word16 *timeOut, // Q(15-timeOut_e) + const Word16 timeOut_e, + const Word16 nTimeSlots, + Word32 *pWorkBuffer // Qx ) { Word16 i; @@ -1186,20 +1188,13 @@ void analysisCldfbEncoder_fx( } /* perform analysis */ - cldfbAnalysisFiltering( - st_fx->cldfbAnaEnc, - ppBuf_Real, - ppBuf_Imag, - scale, - timeIn, - 0, - CLDFB_NO_COL_MAX, - workBuffer ); + cldfbAnalysis_fx( st_fx->cldfbAnaEnc, ppBuf_Real, ppBuf_Imag, scale, timeIn, 0, CLDFB_NO_COL_MAX, workBuffer ); enerScale.lb_scale = negate( scale->lb_scale ); enerScale.lb_scale16 = negate( scale->lb_scale ); move16(); move16(); + /* get 16bit respresentation */ AnalysisPostSpectrumScaling_Fx( st_fx->cldfbAnaEnc, diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 40eb28b70619195bc08047052248b3a577a2a3d4..4255ca8428a927f38097e491ef3067a5cc2d6c78 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -2285,20 +2285,6 @@ ivas_error ivas_mct_dec_fx( const Word16 output_frame, /* i : output frame length per channel */ const Word16 nb_bits_metadata /* i : number of metadata bits */ ); -void swb_tbe_reset_synth_ivas_fx( - Word32 genSHBsynth_Hilbert_Mem[], - Word16 genSHBsynth_state_lsyn_filt_shb_local_fx[], - Word32 genSHBsynth_state_lsyn_filt_shb_local_fx_32[] ); - -void InitSWBdecBuffer_ivas_fx( - Decoder_State *st_fx /* i/o: SHB decoder structure */ -); - -void td_bwe_dec_init_ivas_fx( - Decoder_State *st_fx, /* i/o: SHB decoder structure */ - TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ - const Word32 output_Fs /* i : output sampling rate */ -); void ivas_dirac_dec_render_sf_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ diff --git a/lib_com/modif_fs.c b/lib_com/modif_fs.c index 7ed3cb59b62389a3fa6166306cc6d632a9d44885..10e64a57deb9efbc548a2416db10d1ec550d66cf 100644 --- a/lib_com/modif_fs.c +++ b/lib_com/modif_fs.c @@ -43,7 +43,8 @@ #include "wmc_auto.h" -void Interpolate_allpass_steep_32( +/* IVAS 32-bit variant */ +void Interpolate_allpass_steep_fx32( const Word32 *in_fx, /* i : input array of size N Qx */ Word32 *mem_fx, /* i/o: memory Qx */ const Word16 N, /* i : number of input samples */ @@ -101,6 +102,8 @@ void Interpolate_allpass_steep_32( return; } + +/* IVAS 32-bit variant */ void Decimate_allpass_steep_fx32( const Word32 *in, /* i : input array of size N Qx */ Word32 *mem, /* i/o: memory Qx */ @@ -251,7 +254,9 @@ void Decimate_allpass_steep_fx32( return; } -void interpolate_3_over_2_allpass_32( + +/* IVAS 32-bit variant */ +void interpolate_3_over_2_allpass_fx32( const Word32 *input, /* i : input signal Qx*/ const Word16 len, /* i : number of input samples */ Word32 *out, /* o : output signal Qx*/ @@ -377,8 +382,8 @@ void interpolate_3_over_2_allpass_32( return; } - -void interpolate_3_over_1_allpass_32( +/* IVAS 32-bit variant */ +void interpolate_3_over_1_allpass_fx32( const Word32 *input, /* i : input signal Qx */ const Word16 len, /* i : number of input samples */ Word32 *out, /* o : output signal */ diff --git a/lib_com/options.h b/lib_com/options.h index 4102e9726313ee065394a23234b0a1af9e53b0b5..c51d1033337389f71d2e4ca5fb255b75c48929dc 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -172,5 +172,6 @@ #define DOT_PROD_CHOLESKY_64BIT /* FhG: Issue 1323, optimized 64 bit implementation of dot_product_cholesky() */ #define OPT_BASOP_ADD_v1 /* optimizations to avoid usage of BASOP_Util_Add_MantExp */ #define FIX_ISSUE_1327 /* Ittiam: Fix for issue 1327: Glitch when stereo is switching from TD to FD*/ +#define NONBE_FIX_1402_WAVEADJUST /* VA: BASOP iisue 1402: fix waveform adjustment decoder PLC */ #define FIX_ISSUE_1376 /* VA: Fix for issue 1376 (issue with GSC excitation) */ #endif diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 5bb08604677c86881cd55666afb10b2fd0e42391..c4bc981629f5c35c7bcd84a120317cf40e711d33 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -1368,12 +1368,6 @@ Word16 BRATE2IDX16k_fx( Word32 brate ); Word32 BIT_ALLOC_IDX_fx( Word32 brate, Word16 ctype, Word16 sfrm, Word16 tc ); Word32 BIT_ALLOC_IDX_16KHZ_fx( Word32 brate, Word16 ctype, Word16 sfrm, Word16 tc ); -Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem */ - Decoder_State *st, /* i/o: decoder state structure */ - FILE *file, /* i : bitstream file */ - Word16 rew_flag /* i : rewind flag (rewind file after reading)*/ -); - void getPartialCopyInfo( Decoder_State *st, /* i : decoder state structure */ Word16 *coder_type, @@ -1405,19 +1399,6 @@ void get_NextCoderType_fx( Word16 *next_coder_type /* o : next coder type */ ); -void read_indices_from_djb_fx( - Decoder_State *st, /* i/o: decoder state structure */ - UWord8 *pt_stream, /* i : bitstream file */ - Word16 nbits /* i : number of bits */ - , - Word16 isAMRWB_IOmode, - Word16 core_mode, - Word16 qbit, - Word16 partialframe /* i : partial frame information */ - , - Word16 next_coder_type /* i : next coder type information */ -); - void evs_dec_previewFrame( UWord8 *bitstream, /* i : bitstream pointer */ Word16 bitstreamSize, /* i : bitstream size */ @@ -2632,49 +2613,70 @@ Word16 modify_Fs_intcub3m_sup_fx( /* o : length of output void Decimate_allpass_steep_fx( const Word16 *in_fx, - Word16 mem[], /* array of size: 2*ALLPASSSECTIONS_STEEP+1 */ - Word16 N, /* number of input samples */ - Word16 out_fx[] ); + Word16 mem[], /* array of size: 2*ALLPASSSECTIONS_STEEP+1 */ + Word16 N, /* number of input samples */ + Word16 out_fx[] /* o : output array of size N/2 */ +); + +void Decimate_allpass_steep_fx32( + const Word32 *in, /* i : input array of size N */ + Word32 *mem, /* i/o: memory */ + const Word16 N, /* i : number of input samples */ + Word32 *out /* o : output array of size N/2 */ +); void Interpolate_allpass_steep_fx( const Word16 *in_fx, - Word16 mem[], /* array of size: 2*ALLPASSSECTIONS_STEEP+1 */ - Word16 N, /* number of input samples */ - Word16 out_fx[] ); + Word16 mem[], /* array of size: 2*ALLPASSSECTIONS_STEEP+1 */ + Word16 N, /* number of input samples */ + Word16 out_fx[] /* o : output array of size 2*N */ +); + +void Interpolate_allpass_steep_fx32( + const Word32 *in_fx, /* i : input array of size N */ + Word32 *mem_fx, /* i/o: memory */ + const int16_t N, /* i : number of input samples */ + Word32 *out_fx /* o : output array of size 2*N */ +); void interpolate_3_over_2_allpass_fx( - const Word16 *input_fx, - /* i : input signal */ /* Q_input */ - const Word16 len, /* i : number of input samples */ - Word16 *out_fx, - /* o : output signal */ /* Q_input */ - Word16 *mem_fx, - /* i/o: memory */ /* Q_input */ - const Word16 *filt_coeff_fx /* i : filter coefficients */ /* Q15*/ + const Word16 *input_fx, /* i : input signal Q_input */ + const Word16 len, /* i : number of input samples */ + Word16 *out_fx, /* o : output signal Q_input */ + Word16 *mem_fx, /* i/o: memory Q_input */ + const Word16 *filt_coeff_fx /* i : filter coefficients Q15*/ +); + +void interpolate_3_over_2_allpass_fx32( + const Word32 *input, /* i : input signal Qx */ + const int16_t len, /* i : number of input samples */ + Word32 *out, /* o : output signal */ + Word32 *mem /* i/o: memory */ ); void interpolate_3_over_1_allpass_fx( - const Word16 *input_fx, - /* i : input signal */ /* Q_input */ - const Word16 len, /* i : number of input samples */ - Word16 *out_fx, - /* o : output signal */ /* Q_input */ - Word16 *mem_fx /* i/o: memory */ /* Q_input */ + const Word16 *input_fx, /* i : input signal Q_input */ + const Word16 len, /* i : number of input samples */ + Word16 *out_fx, /* o : output signal Q_input */ + Word16 *mem_fx /* i/o: memory Q_input */ +); + +void interpolate_3_over_1_allpass_fx32( + const Word32 *input, /* i : input signal Qx */ + const Word16 len, /* i : number of input samples */ + Word32 *out, /* o : output signal */ + Word32 *mem /* i/o: memory */ ); void decimate_2_over_3_allpass_fx( - const Word16 *input, - /* i : input signal */ /* Q_input */ - const Word16 len, /* i : number of input samples */ - Word16 *out_fx, - /* o : output signal */ /* Q_input */ - Word16 *mem_fx, - /* i/o: memory */ /* Q_input */ - const Word16 *filt_coeff_fx, - /* i : filter coefficients */ /* Q15*/ - const Word16 *lp_num_fx, /* i : Num Coefficients : Q15 */ - const Word16 *lp_den_fx, /* o : Den Coefficients : Q15 */ - Word16 *lp_mem_fx /* o : Filter memories : Q_input */ + const Word16 *input, /* i : input signal Q_input */ + const Word16 len, /* i : number of input samples */ + Word16 *out_fx, /* o : output signal Q_input */ + Word16 *mem_fx, /* i/o: memory Q_input */ + const Word16 *filt_coeff_fx, /* i : filter coefficients Q15 */ + const Word16 *lp_num_fx, /* i : Num Coefficients : Q15 */ + const Word16 *lp_den_fx, /* o : Den Coefficients : Q15 */ + Word16 *lp_mem_fx /* o : Filter memories : Q_input */ ); void retro_interp4_5_fx( @@ -2907,7 +2909,8 @@ void swb_tbe_reset_fx( void swb_tbe_reset_synth_fx( Word32 genSHBsynth_Hilbert_Mem[], - Word16 genSHBsynth_state_lsyn_filt_shb_local_fx[] ); + Word16 genSHBsynth_state_lsyn_filt_shb_local_fx[], + Word32 genSHBsynth_state_lsyn_filt_shb_local_fx_32[] ); void fb_tbe_reset_synth_fx( Word32 fbbwe_hpf_mem_fx[][4], @@ -3171,7 +3174,7 @@ void GenSHBSynth_fx( const Word16 L_frame, /* i : ACELP Frame length */ Word16 *syn_dm_phase ); -void GenSHBSynth_fx_32( +void GenSHBSynth_fx32( const Word32 *input_synspeech, /* i : input synthesized speech */ Word32 *shb_syn_speech_32k, /* o : output highband component */ Word32 Hilbert_Mem[], /* i/o: memory */ @@ -3192,7 +3195,7 @@ void ScaleShapedSHB_fx( Word16 n_mem3, Word16 prev_Q_bwe_syn2 ); -void ScaleShapedSHB_32( +void ScaleShapedSHB_fx32( const Word16 length, /* i : SHB overlap length */ Word32 *synSHB_fx, /* i/o: synthesized shb signal Qx */ Word32 *overlap_fx, /* i/o: buffer for overlap-add Qx */ @@ -4478,14 +4481,15 @@ void calcGainTemp_TBE_Fx( Word16 *pGainTemp_e, const Word16 code ); -Word16 procTecTfa_TBE_Fx( Word16 *hb_synth_Fx, - Word16 hb_synth_fx_exp, - Word16 *gain_m, - Word16 *gain_e, - Word16 flat_flag, - Word16 last_core, - Word16 l_subfr, - Word16 code ); +Word16 procTecTfa_TBE_Fx( + Word16 *hb_synth_Fx, + Word16 hb_synth_fx_exp, + Word16 *gain_m, + Word16 *gain_e, + Word16 flat_flag, + Word16 last_core, + Word16 l_subfr, + Word16 code ); void calcHiEnvLoBuff_Fix( const Word16 noCols, @@ -4756,24 +4760,26 @@ void r_fft_fx_lc( ); // cldfb_evs -void cldfbAnalysisFiltering( HANDLE_CLDFB_FILTER_BANK anaCldfb, /*!< Handle of Cldfb Analysis Bank */ - Word32 **cldfbReal, /*!< Pointer to real subband slots */ - Word32 **cldfbImag, /*!< Pointer to imag subband slots */ - CLDFB_SCALE_FACTOR *scaleFactor, /*!< Scale factors of CLDFB data */ - const Word16 *timeIn, /*!< Time signal */ - const Word16 timeIn_e, /*!< Time signal */ - const Word16 nTimeSlots, /*!< Time slots to be processed */ - Word32 *pWorkBuffer /*!< pointer to temporal working buffer */ -); - -void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK synCldfb, /*!< Handle of Cldfb Synthesis Bank */ - Word32 **CldfbBufferReal, /*!< Pointer to 32 bit real subband slots */ - Word32 **CldfbBufferImag, /*!< Pointer to 32 bit imag subband slots */ - const CLDFB_SCALE_FACTOR *scaleFactor, /*!< Scale factors of CLDFB data */ - Word16 *timeOut, /*!< Time signal */ - const Word16 timeOut_e, /*!< Target exponent for output signal */ - const Word16 nTimeSlots, /*!< number of time slots to be processed */ - Word32 *pWorkBuffer /*!< pointer to temporal working buffer */ +void cldfbAnalysis_fx( + HANDLE_CLDFB_FILTER_BANK anaCldfb, /*!< Handle of Cldfb Analysis Bank */ + Word32 **cldfbReal, /*!< Pointer to real subband slots */ + Word32 **cldfbImag, /*!< Pointer to imag subband slots */ + CLDFB_SCALE_FACTOR *scaleFactor, /*!< Scale factors of CLDFB data */ + const Word16 *timeIn, /*!< Time signal */ + const Word16 timeIn_e, /*!< Time signal */ + const Word16 nTimeSlots, /*!< Time slots to be processed */ + Word32 *pWorkBuffer /*!< pointer to temporal working buffer */ +); + +void cldfbSynthesis_fx( + HANDLE_CLDFB_FILTER_BANK synCldfb, /*!< Handle of Cldfb Synthesis Bank */ + Word32 **CldfbBufferReal, /*!< Pointer to 32 bit real subband slots */ + Word32 **CldfbBufferImag, /*!< Pointer to 32 bit imag subband slots */ + const CLDFB_SCALE_FACTOR *scaleFactor, /*!< Scale factors of CLDFB data */ + Word16 *timeOut, /*!< Time signal */ + const Word16 timeOut_e, /*!< Target exponent for output signal */ + const Word16 nTimeSlots, /*!< number of time slots to be processed */ + Word32 *pWorkBuffer /*!< pointer to temporal working buffer */ ); void configureCldfb( HANDLE_CLDFB_FILTER_BANK h_cldfb, /*!< CLDFB Handle */ @@ -5811,7 +5817,7 @@ Word16 tcx_ltp_decode_params( const Word16 pitres /* Q0 */ ); -void tcx_ltp_post( +void tcx_ltp_post_fx( Decoder_State *st, TCX_LTP_DEC_HANDLE hTcxLtpDec, Word16 core, /* Q0 */ @@ -5821,7 +5827,7 @@ void tcx_ltp_post( Word16 *tcx_buf /* Qx */ ); -void tcx_ltp_post32( +void tcx_ltp_post_fx32( Decoder_State *st, TCX_LTP_DEC_HANDLE hTcxLtpDec, Word16 core, /* Q0 */ @@ -5998,13 +6004,9 @@ Word32 calc_gain_inov( /* returns innovation gain /* Lib_dec */ ////////////////////////////////// // swb_tbe_dec.c - -void InitSWBdecBuffer_fx( - Decoder_State *swb_dnc_fx /* i/o: SHB decoder structure */ -); - void ResetSHBbuffer_Dec_fx( - Decoder_State *st_fx /* i/o: decoder state structure */ + TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + const Word16 extl /* i : BWE extension layer */ ); void wb_tbe_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ @@ -6063,41 +6065,39 @@ void tbe_read_bitstream_fx( ); void GenTransition_fx( - const Word16 *i, /* i : gain shape overlap buffer */ - const Word16 *old_hb_synth, /* i : synthesized HB from previous frame */ - Word16 length, /* i : targeted length of transition signal */ - Word16 *output, /* o : synthesized transitions signal */ - Word32 Hilbert_Mem[], /* i/o: memory */ - Word16 state_lsyn_filt_shb_local[], /* i/o: memory */ - Word16 mem_resamp_HB_32k[], /* i/o: memory */ - Word16 *syn_dm_phase, - Word32 output_Fs, - Word16 *up_mem, - Word16 rf_flag, - Word32 bitrate ); + TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + Word16 *output_HB, /* o : synthesized HB transitions signal st_fx->prev_Q_bwe_syn2 */ + const Word32 output_Fs, /* i : output sampling rate */ + Word16 rf_flag, /* i : RF flag */ + Word32 total_bitrate /* i : total bitrate */ +); + +void GenTransition_fx32( + TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */ + const Word32 output_Fs, /* i : output sampling rate : Q0 */ + const Word16 L_frame, /* i : ACELP frame length : Q0 */ + const Word16 prev_Qx ); void GenTransition_WB_fx( - const Word16 *i, /* i : gain shape overlap buffer */ - const Word16 *old_hb_synth, /* i : synthesized HB from previous frame */ - const Word16 prev_Qx, /* i : scaling of old_hb_synth */ - Word16 length, /* i : targeted length of transition signal */ - Word16 *output, /* o : synthesized transitions signal */ - Word16 state_lsyn_filt_shb1[], - Word16 state_lsyn_filt_shb2[], - Word32 output_Fs, - Word16 *up_mem ); -void TBEreset_dec_ivas_fx( - Decoder_State *st /* i/o: decoder state structure */ + TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + Word16 *output, /* o : synthesized transitions signal */ + const Word32 output_Fs /* i : output sampling rate */ +); + +void GenTransition_WB_fx32( + TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */ + const Word32 output_Fs /* i : output sampling rate */ ); void TBEreset_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 bandwidth /* i : bandwidth mode */ + Decoder_State *st_fx /* i/o: decoder state structure */ ); void td_bwe_dec_init_fx( - Decoder_State *st_fx, /* i/o: SHB decoder structure */ TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + const Word16 extl, /* i : BWE extension layer */ const Word32 output_Fs /* i : output sampling rate */ ); @@ -6311,82 +6311,136 @@ void td_cng_dec_init_fx( DEC_CORE_HANDLE st /* i/o: decoder state structure */ ); -void td_cng_dec_init_ivas_fx( - DEC_CORE_HANDLE st /* i/o: decoder state structure */ -); - // wavadjust_fec_dec_fx.c -void set_state( Word16 *state, Word16 num, Word16 N ); -void concealment_init_x( Word16 N, void *_plcInfo ); -void concealment_init_ivas_fx( +void set_state( + Word16 *state, + Word16 num, + Word16 N ); + +void concealment_init_x( const Word16 L_frameTCX, T_PLCInfo_HANDLE hPlcInfo ); -void concealment_update_x( Word16 bfi, Word16 curr_mode, Word16 harmonic, Word32 *invkoef, Word16 *invkoef_scale, void *_plcInfo ); -Word16 Sqrt_x_fast( Word32 value ); - -Word32 dot_w32_accuracy_x( Word16 *s1, Word16 *s2, Word16 nbits, Word16 N ); - -Word16 int_div_s_x( Word16 a, Word16 b ); - -Word16 GetW32Norm_x( Word32 *s, Word16 N ); - -Word16 harmo_x( Word32 *X, Word16 Framesize, Word16 pitch ); - -void LpFilter2_x( Word16 *x, Word16 *y, Word16 N ); -void sig_tilt_x( Word16 *s, Word16 FrameSize, Word32 *enr1, Word32 *enr2 ); - -void get_maxConv_and_pitch_x( Word16 *s_LP, Word16 s, Word16 e, Word16 N, Word32 *maxConv, Word16 *maxConv_bits, Word16 *pitch ); +void concealment_init_ivas_fx( + const Word16 L_frameTCX, + T_PLCInfo_HANDLE hPlcInfo ); -Word16 get_voicing_x( Word16 *s_LP, Word16 pitch, Word32 covMax, Word16 maxConv_bits, Word16 Framesize ); +void concealment_update_x( + const Word16 bfi, + const Word16 core, + const Word16 tonality, + Word32 *invkoef /*Qinvkoef_scale*/, + Word16 *invkoef_scale, + T_PLCInfo_HANDLE hPlcInfo ); -void pitch_modify_x( Word16 *s_LP, Word16 *voicing, Word16 *pitch, Word16 FrameSize ); +Word16 Sqrt_x_fast( + Word32 value ); -Word16 Is_Periodic_x( Word32 *mdct_data, Word16 cov_max, Word16 zp, Word32 ener, Word32 ener_mean, Word16 pitch, Word16 Framesize ); +Word32 dot_w32_accuracy_x( + Word16 *s1, + Word16 *s2, + Word16 nbits, + Word16 N ); -Word16 get_conv_relation_x( Word16 *s_LP, Word16 shift, Word16 N ); +Word16 int_div_s_x( + Word16 a, + Word16 b ); -void concealment_decode_fix( Word16 curr_mode, Word32 *invkoef, Word16 *invkoef_scale, void *_plcInfo ); +Word16 GetW32Norm_x( + Word32 *s, + Word16 N ); + +Word16 harmo_x( + Word32 *X, + Word16 Framesize, + Word16 pitch ); + +void LpFilter2_x( + Word16 *x, + Word16 *y, + Word16 N ); + +void sig_tilt_x( + Word16 *s, + Word16 FrameSize, + Word32 *enr1, + Word32 *enr2 ); + +void get_maxConv_and_pitch_x( + Word16 *s_LP, + Word16 s, + Word16 e, + Word16 N, + Word32 *maxConv, + Word16 *maxConv_bits, + Word16 *pitch ); + +Word16 get_voicing_x( + Word16 *s_LP, + Word16 pitch, + Word32 covMax, + Word16 maxConv_bits, + Word16 Framesize ); + +void pitch_modify_x( + Word16 *s_LP, + Word16 *voicing, + Word16 *pitch, + Word16 FrameSize ); + +Word16 Is_Periodic_x( + Word32 *mdct_data, + Word16 cov_max, + Word16 zp, + Word32 ener, + Word32 ener_mean, + Word16 pitch, + Word16 Framesize ); + +Word16 get_conv_relation_x( + Word16 *s_LP, + Word16 shift, + Word16 N ); + +void concealment_decode_fix( + Word16 curr_mode, + Word32 *invkoef, + Word16 *invkoef_scale, + T_PLCInfo_HANDLE hPlcInfo ); -Word32 Spl_Energy_x( const Word16 *vector, const Word16 vector_length, Word16 *scale_factor ); +Word32 Spl_Energy_x( + const Word16 *vector, + const Word16 vector_length, + Word16 *scale_factor ); -void Log10OfEnergy_x( const Word16 *s, Word32 *enerlogval, const Word16 len ); +void Log10OfEnergy_x( + const Word16 *s, + Word32 *enerlogval, + const Word16 len ); -void concealment_update2_x( const Word16 *outx_new, void *_plcInfo, const Word16 FrameSize ); +void concealment_update2_x( + const Word16 *outx_new, + T_PLCInfo_HANDLE hPlcInfo, + const Word16 FrameSize ); -Word16 ffr_getSfWord16( Word16 *vector, /*!< Pointer to i vector */ - Word16 len ); +Word16 ffr_getSfWord16( + Word16 *vector, /*!< Pointer to i vector */ + Word16 len ); -void waveform_adj2_fix( Word16 *overlapbuf, - Word16 *outx_new, - Word16 *data_noise, - Word16 *outx_new_n1, - Word16 *nsapp_gain, - Word16 *nsapp_gain_n, - Word16 *recovery_gain, - Word16 step_concealgain, - Word16 pitch, - Word16 Framesize, - Word16 delay, - Word16 bfi_cnt, - Word16 bfi ); +void waveform_adj2_fix( + T_PLCInfo_HANDLE hPlcInfo, + Word16 *overlapbuf, + Word16 *outx_new, + const Word16 delay, + const Word16 bfi_cnt, + const Word16 bfi ); -void concealment_signal_tuning_fx( Word16 bfi, - Word16 curr_mode, - Word16 *outx_new_fx, - void *_plcInfo, - Word16 nbLostCmpt, - Word16 pre_bfi, - Word16 *OverlapBuf_fx, - Word16 past_core_mode, - Word16 *outdata2_fx, - Decoder_State *st ); +void concealment_signal_tuning_fx( + Decoder_State *st, + const Word16 bfi, + Word16 *outx_new_fx /*Qoutx_new_fx*/, + const Word16 past_core ); -// TonalComponentDetect.c -/* Detect tonal components in the lastMDCTSpectrum, use - * secondLastPowerSpectrum for the precise location of the peaks and - * store them in indexOfTonalPeak. Updates lowerIndex, upperIndex, - * pNumIndexes accordingly. */ void DetectTonalComponents( Word16 indexOfTonalPeak[], Word16 lowerIndex[], @@ -6410,12 +6464,6 @@ void DetectTonalComponents( #endif ); -/* When called, the tonal components are already stored in - * indexOfTonalPeak. Detect tonal components in the lastMDCTSpectrum, - * use secondLastPowerSpectrum for the precise location of the peaks and - * then keep in indexOfTonalPeak only the tonal components that are - * again detected Updates indexOfTonalPeak, lowerIndex, upperIndex, - * phaseDiff, phases, pNumIndexes accordingly. */ void RefineTonalComponents( Word16 indexOfTonalPeak[], Word16 lowerIndex[], @@ -6514,26 +6562,13 @@ void TonalMDCTConceal_SaveFreqSignal_ivas_fx( const Word16 gain_tcx_exp, const Word16 infoIGFStartLine ); -/* The call to TonalMDCTConceal_UpdateState() should be called after TonalMDCTConceal_Apply. */ -TONALMDCTCONCEAL_ERROR TonalMDCTConceal_UpdateState( TonalMDCTConcealPtr self, - Word16 nNewSamples, - Word32 pitchLag, - Word16 badBlock, - Word8 tonalConcealmentActive ); - -/* The call to TonalMDCTConceal_SaveTimeSignal() should be at the - * place where the TD signal corresponds to the FD signal stored with TonalMDCTConceal_SaveFreqSignal. */ -void TonalMDCTConceal_SaveTimeSignal( - TonalMDCTConcealPtr hTonalMDCTConc, - Word16 *timeSignal, - Word16 nNewSamples ); +void TonalMDCTConceal_UpdateState( + TonalMDCTConcealPtr self, + Word16 nNewSamples, + Word32 pitchLag, + Word16 badBlock, + Word8 tonalConcealmentActive ); -/* Calculates MDST, power spectrum and performs peak detection. - * Uses the TD signal in pastTimeSignal; if pastTimeSignal is NULL, uses the - * TD signal stored using TonalMDCTConceal_SaveTimeSignal. If the - * second last frame was also lost, it is expected that pastTimeSignal - * could hold a signal somewhat different from the one stored in - * TonalMDCTConceal_SaveTimeSignal (e.g. including fade-out).*/ void TonalMDCTConceal_Detect( const TonalMDCTConcealPtr self, /*IN */ const Word32 pitchLag, /*IN */ @@ -6545,9 +6580,6 @@ void TonalMDCTConceal_Detect( #endif ); -/* Conceals the lost frame using the FD signal previously stored using - * TonalMDCTConceal_SaveFreqSignal. Stores the concealed harmonic part of - * the signal in mdctSpectrum, the rest of the spectrum is unchanged. */ void TonalMDCTConceal_Apply( const TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ Word32* mdctSpectrum, /*IN/OUT*/ @@ -6563,9 +6595,6 @@ void TonalMDCTConceal_Apply_ivas_fx( Word16 mdctSpectrum_exp[L_FRAME48k], /*IN */ const PsychoacousticParameters *psychParamsCurrent ); -/* Conceals the lost frame using the FD signal previously stored using - * TonalMDCTConceal_SaveFreqSignal. Stores the concealed noise part of - * the signal in mdctSpectrum, the rest of the spectrum is unchanged. */ void TonalMDCTConceal_InsertNoise_ivas_fx( const TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ Word32 *mdctSpectrum, @@ -6580,10 +6609,6 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( const Word16 cngLevelBackgroundTrace_e, const Word16 crossOverFreq ); - -/* Conceals the lost frame using the FD signal previously stored using - * TonalMDCTConceal_SaveFreqSignal. Stores the concealed noise part of - * the signal in mdctSpectrum, the rest of the spectrum is unchanged. */ void TonalMDCTConceal_InsertNoise( const TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ Word32 *mdctSpectrum, /*OUT*/ @@ -6596,24 +6621,12 @@ void TonalMDCTConceal_InsertNoise( const Word16concealment_noise[L_FRAME48k], #endif const Word16 crossOverFreq ); -/* Conceals the lost frame using the FD signal previously stored using - * TonalMDCTConceal_SaveFreqSignal. Stores the concealed harmonic part of - * the signal in mdctSpectrum, the rest of the spectrum is unchanged. */ -void TonalMDCTConceal_Apply( - const TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ - Word32* mdctSpectrum, /*IN/OUT*/ - Word16* mdctSpectrum_exp /*IN */ -#ifdef IVAS_CODE_MDCT_GSHAPE - , const PsychoacousticParameters* psychParamsCurrent) -#endif - ); -/* The call to TonalMDCTConceal_SaveTimeSignal() should be at the - * place where the TD signal corresponds to the FD signal stored with TonalMDCTConceal_SaveFreqSignal. */ void TonalMDCTConceal_SaveTimeSignal( TonalMDCTConcealPtr hTonalMDCTConc, Word16 *timeSignal, Word16 nNewSamples ); + void TonalMDCTConceal_SaveTimeSignal_ivas_fx( TonalMDCTConcealPtr hTonalMDCTConc, Word16 *timeSignal, @@ -8044,7 +8057,6 @@ ivas_error core_switching_post_dec_ivas_fx( Word16 *synth, /* i/o: output synthesis Qsynth*/ Word32 *output_fx, /* i/o: LB synth/upsampled LB synth Q4*/ Word16 output_mem_fx[], /* i : OLA memory from last TCX/HQ frame Qx*/ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo Q0*/ const Word16 output_frame, /* i : frame length Q0*/ const Word16 core_switching_flag, /* i : ACELP->HQ switching flag Q0*/ @@ -9588,9 +9600,9 @@ ivas_error acelp_core_dec_fx( // evs_dec_fx.c ivas_error evs_dec_fx( - Decoder_State *st_fx, /* i/o : Decoder state structure */ - Word16 output_sp[], /* o : output synthesis signal */ - frameMode_fx frameMode /* i : Decoder frame mode */ + Decoder_State *st_fx, /* i/o : Decoder state structure */ + Word16 output_sp[], /* o : output synthesis signal */ + FRAME_MODE frameMode /* i : Decoder frame mode */ ); void fft_cldfb_fx( @@ -9816,33 +9828,6 @@ void generate_masking_noise_dirac_ivas_fx( Word16 *q_cldfb ); // modif_fs/c -void interpolate_3_over_2_allpass_32( - const Word32 *input, /* i : input signal Qx */ - const int16_t len, /* i : number of input samples */ - Word32 *out, /* o : output signal */ - Word32 *mem /* i/o: memory */ -); - -void interpolate_3_over_1_allpass_32( - const Word32 *input, /* i : input signal */ - const int16_t len, /* i : number of input samples */ - Word32 *out, /* o : output signal */ - Word32 *mem /* i/o: memory */ -); -void Decimate_allpass_steep_fx32( - const Word32 *in, /* i : input array of size N */ - Word32 *mem, /* i/o: memory */ - const Word16 N, /* i : number of input samples */ - Word32 *out /* o : output array of size N/2 */ -); - -void Interpolate_allpass_steep_32( - const Word32 *in_fx, /* i : input array of size N */ - Word32 *mem_fx, /* i/o: memory */ - const int16_t N, /* i : number of input samples */ - Word32 *out_fx /* o : output array of size 2*N */ -); - void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_TDAC, Word16 *xn_buf, const Word16 *tcx_aldo_window_1, const PWord16 *tcx_aldo_window_1_trunc, const PWord16 *tcx_aldo_window_2, const PWord16 *tcx_mdct_window_half, const PWord16 *tcx_mdct_window_minimum, const PWord16 *tcx_mdct_window_trans, Word16 tcx_mdct_window_half_length, Word16 tcx_mdct_window_min_length, Word16 index, Word16 left_rect, Word16 tcx_offset, Word16 overlap, Word16 L_frame, Word16 L_frameTCX, Word16 L_spec_TCX5, Word16 L_frame_glob, Word16 frame_cnt, Word16 bfi, Word16 *old_out, Word16 *Q_old_wtda, Decoder_State *st, Word16 fullbandScale, Word16 *acelp_zir ); void IMDCT_ivas_fx( @@ -11561,7 +11546,7 @@ Decoder_State **reset_elements( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); -void mdct_switching_dec_ivas_fx( +void mdct_switching_dec_fx( Decoder_State *st /* i/o: decoder state structure */ ); @@ -11670,7 +11655,7 @@ ivas_error acelp_core_enc_ivas_fx( Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel X2.56*/ Word16 Q_new ); -void flip_and_downmix_generic_fx_32( +void flip_and_downmix_generic_fx32( Word32 input[], /* i : input spectrum Qx*/ Word32 output[], /* o : output spectrum Qx*/ const Word16 length, /* i : length of spectra */ @@ -11680,22 +11665,6 @@ void flip_and_downmix_generic_fx_32( Word16 *phase_state /* i/o: Phase state in case frequency isn't multiple of 50 Hz */ ); -void GenTransition_fixed( - TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ - Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */ - const Word32 output_Fs, /* i : output sampling rate : Q0 */ - const Word16 element_mode, /* i : element mode : Q0 */ - const Word16 L_frame, /* i : ACELP frame length : Q0 */ - const Word16 rf_flag, /* i : RF flag : Q0 */ - const Word32 total_brate, /* i : total bitrate : Q0 */ - const Word16 prev_Qx ); - -void GenTransition_WB_fixed( - TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ - Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */ - const Word32 output_Fs /* i : output sampling rate */ -); - Word16 quant_2p_2N1_fx( /* o: return (2*N)+1 bits */ const Word16 pos1, /* i: position of the pulse 1 */ const Word16 pos2, /* i: position of the pulse 2 */ diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index c96dcc88479af40b7cff82494dd4069a4dde2ebf..f99d498027a98db71cfbed521e46712659506917 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -693,21 +693,6 @@ typedef enum /*---------------------------------------------------------------* * IGF * *---------------------------------------------------------------*/ -/*----------------------------------------------------------------------------------* - * NB postfilter / formant postfilter static variables - *----------------------------------------------------------------------------------*/ -typedef struct pfstat_structure -{ - Word16 on; /* On/off flag */ - Word16 reset; /* reset flag */ - Word16 mem_pf_in[L_SUBFR]; /* Input memory Qqmem_pf_in */ - Word16 mem_stp[L_SUBFR]; /* 1/A(gamma1) memory Qqmem_stp*/ - Word16 mem_res2[DECMEM_RES2]; /* A(gamma2) residual Q_syn*/ - Word16 mem_zero[M]; /* null memory to compute i.r. of A(gamma2)/A(gamma1) Q_qmem_zero*/ - Word16 gain_prec; /*Q14*/ /* for gain adjustment */ - -} PFSTAT, *PFSTAT_HANDLE; - typedef struct { diff --git a/lib_com/swb_tbe_com.c b/lib_com/swb_tbe_com.c deleted file mode 100644 index 7905c7145b985c6cf56ef687f1c2d7600d03f363..0000000000000000000000000000000000000000 --- a/lib_com/swb_tbe_com.c +++ /dev/null @@ -1,296 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -/*==================================================================================== - EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 - ====================================================================================*/ - -#include -#include "options.h" -#include -#include "cnst.h" -#include "prot_fx.h" -#include "rom_com.h" -#include "wmc_auto.h" -#include - - -/*-----------------------------------------------------------------* - * Local function prototypes - *-----------------------------------------------------------------*/ - - -/*-------------------------------------------------------------------* - * flip_spectrum_and_decimby4() - * - * - *-------------------------------------------------------------------*/ - - -void GenSHBSynth_fx_32( - const Word32 *input_synspeech, /* i : input synthesized speech Qx*/ - Word32 *shb_syn_speech_32k, /* o : output highband component Qx*/ - Word32 Hilbert_Mem[], /* i/o: memory Qx*/ - Word32 state_lsyn_filt_shb_local[], /* i/o: memory Qx*/ - const Word16 L_frame, /* i : ACELP frame length */ - Word16 *syn_dm_phase ) -{ - Word32 speech_buf_32k[L_FRAME32k]; - Word16 i; - -#ifdef FIX_881_HILBERT_FILTER - Word16 shift = 0; - Word32 maxm32, input_synspeech_temp[L_FRAME16k]; - move16(); - - /* find the maximum value and derive the shift to improve precision of the Hilber filter */ - maxm32 = L_deposit_l( 0 ); - FOR( i = 0; i < L_FRAME16k; i++ ) - { - maxm32 = L_max( maxm32, L_abs( input_synspeech[i] ) ); - } - - FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) - { - maxm32 = L_max( maxm32, L_abs( state_lsyn_filt_shb_local[i] ) ); - } - - FOR( i = 0; i < HILBERT_MEM_SIZE; i++ ) - { - maxm32 = L_max( maxm32, L_abs( Hilbert_Mem[i] ) ); - } - - IF( maxm32 != 0 ) - { - shift = sub( norm_l( maxm32 ), 3 ); - - Copy_Scale_sig32( input_synspeech, input_synspeech_temp, L_FRAME16k, shift ); - Scale_sig32( state_lsyn_filt_shb_local, 2 * ALLPASSSECTIONS_STEEP, shift ); - Scale_sig32( Hilbert_Mem, HILBERT_MEM_SIZE, shift ); - } - ELSE - { - Copy32( input_synspeech, input_synspeech_temp, L_FRAME16k ); - } - - Interpolate_allpass_steep_32( input_synspeech_temp, state_lsyn_filt_shb_local, L_FRAME16k, speech_buf_32k ); -#else - Interpolate_allpass_steep_32( input_synspeech, state_lsyn_filt_shb_local, L_FRAME16k, speech_buf_32k ); -#endif - - IF( EQ_16( L_frame, L_FRAME ) ) - { - flip_and_downmix_generic_fx_32( speech_buf_32k, shb_syn_speech_32k, L_FRAME32k, Hilbert_Mem, Hilbert_Mem + HILBERT_ORDER1, Hilbert_Mem + ( HILBERT_ORDER1 + 2 * HILBERT_ORDER2 ), syn_dm_phase ); - } - ELSE - { - FOR( i = 0; i < L_FRAME32k; i++ ) - { - // shb_syn_speech_32k[i] = ( ( i % 2 ) == 0 ) ? ( -speech_buf_32k[i] ) : ( speech_buf_32k[i] ); - IF( i % 2 == 0 ) - { - shb_syn_speech_32k[i] = L_negate( speech_buf_32k[i] ); // Qx - } - ELSE - { - shb_syn_speech_32k[i] = speech_buf_32k[i]; // Qx - } - move32(); - } - } - -#ifdef FIX_881_HILBERT_FILTER - IF( maxm32 != 0 ) - { - Scale_sig32( shb_syn_speech_32k, L_FRAME32k, negate( shift ) ); - Scale_sig32( state_lsyn_filt_shb_local, 2 * ALLPASSSECTIONS_STEEP, negate( shift ) ); - Scale_sig32( Hilbert_Mem, HILBERT_MEM_SIZE, negate( shift ) ); - } -#endif - - return; -} -void ScaleShapedSHB_32( - const Word16 length, /* i : SHB overlap length */ - Word32 *synSHB_fx, /* i/o: synthesized shb signal Q_inp/Q_new */ - Word32 *overlap_fx, /* i/o: buffer for overlap-add Q_inp/Q_new */ - const Word16 *subgain_fx, /* i : subframe gain Q15 */ - const Word32 frame_gain_fx, /* i : frame gain Q18*/ - const Word16 *win_fx, /* i : window Q15 */ - const Word16 *subwin_fx, /* i : subframes window Q15 */ - Word16 *Q_inp, - Word16 *Q_new ) -{ - const Word16 *skip; - Word16 i, j, k, l_shb_lahead, l_frame; - Word16 join_length, num_join; - Word32 mod_syn_fx[L_FRAME16k + L_SHB_LAHEAD], L_tmp; - Word16 sum_gain_fx; - - /* initilaization */ - l_frame = L_FRAME16k; - l_shb_lahead = L_SHB_LAHEAD; - move16(); - move16(); - skip = skip_bands_SWB_TBE; - - IF( EQ_16( length, SHB_OVERLAP_LEN / 2 ) ) - { - skip = skip_bands_WB_TBE; - l_frame = L_FRAME16k / 4; - l_shb_lahead = L_SHB_LAHEAD / 4; - move16(); - move16(); - } - - /* apply gain for each subframe, and store noise output signal using overlap-add */ - set32_fx( mod_syn_fx, 0, l_frame + l_shb_lahead ); - - IF( EQ_16( length, SHB_OVERLAP_LEN / 2 ) ) - { - sum_gain_fx = 0; - move16(); - FOR( k = 0; k < shr( length, 1 ); k++ ) - { - sum_gain_fx = mult_r( subwin_fx[2 * k + 2], subgain_fx[0] ); - mod_syn_fx[skip[0] + k] = Mpy_32_16_1( synSHB_fx[skip[0] + k], sum_gain_fx ); - move32(); // Qx - mod_syn_fx[skip[0] + k + length / 2] = Mpy_32_16_1( synSHB_fx[skip[0] + k + length / 2], subgain_fx[0] ); // Qx - move32(); - } - FOR( i = 1; i < NUM_SHB_SUBFR / 2; i++ ) - { - FOR( k = 0; k < length; k++ ) - { - L_tmp = L_mult0( subwin_fx[k + 1], subgain_fx[i] ); - sum_gain_fx = round_fx( L_mac0( L_tmp, subwin_fx[length - k - 1], subgain_fx[i - 1] ) ); - mod_syn_fx[skip[i] + k] = L_shl( Mpy_32_16_1( synSHB_fx[skip[i] + k], sum_gain_fx ), 1 ); // Qx - move32(); - } - } - FOR( k = 0; k < shr( length, 1 ); k++ ) - { - sum_gain_fx = mult_r( subwin_fx[length - k * 2 - 2], subgain_fx[i - 1] ); - mod_syn_fx[skip[i] + k] = Mpy_32_16_1( synSHB_fx[skip[i] + k], sum_gain_fx ); // Qx - move32(); - } - } - ELSE - { - num_join = NUM_SHB_SUBFR / NUM_SHB_SUBGAINS; - join_length = i_mult( num_join, length ); - j = 0; - move16(); - move16(); - FOR( k = 0; k < length; k++ ) - { - mod_syn_fx[j] = Mpy_32_16_1( synSHB_fx[j], mult_r( subwin_fx[k + 1], subgain_fx[0] ) ); // Qx - move32(); - j = add( j, 1 ); - } - FOR( i = 0; i < NUM_SHB_SUBGAINS - 1; i++ ) - { - FOR( k = 0; k < join_length - length; k++ ) - { - mod_syn_fx[j] = Mpy_32_16_1( synSHB_fx[j], subgain_fx[i * num_join] ); // Qx - move32(); - j = add( j, 1 ); - } - - FOR( k = 0; k < length; k++ ) - { - L_tmp = L_mult0( subwin_fx[length - k - 1], subgain_fx[i * num_join] ); - mod_syn_fx[j] = L_shl( Mpy_32_16_1( synSHB_fx[j], round_fx( L_mac0( L_tmp, subwin_fx[k + 1], subgain_fx[( i + 1 ) * num_join] ) ) ), 1 ); // Qx - move32(); - j = add( j, 1 ); - } - } - FOR( k = 0; k < join_length - length; k++ ) - { - mod_syn_fx[j] = Mpy_32_16_1( synSHB_fx[j], subgain_fx[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); // Qx - move32(); - j = add( j, 1 ); - } - FOR( k = 0; k < length; k++ ) - { - mod_syn_fx[j] = Mpy_32_16_1( synSHB_fx[j], mult_r( subwin_fx[length - k - 1], subgain_fx[( NUM_SHB_SUBGAINS - 1 ) * num_join] ) ); // Qx - move32(); - j = add( j, 1 ); - } - } - - Word16 norm_shift = norm_l( frame_gain_fx ); - if ( frame_gain_fx == 0 ) - { - norm_shift = 31; - move16(); - } - - norm_shift = s_min( norm_shift, 14 ); - norm_shift = sub( norm_shift, 1 ); - - *Q_new = add( *Q_inp, sub( norm_shift, 13 ) ); // Q_new = Q_inp + min(norm_shift,14) - 14; - move16(); - FOR( i = 0; i < L_SHB_LAHEAD; i++ ) - { - overlap_fx[i] = L_shl( overlap_fx[i], sub( *Q_new, *Q_inp ) ); - move32(); - } - - FOR( i = 0; i < l_shb_lahead; i++ ) - { - synSHB_fx[i] = Mpy_32_32( mod_syn_fx[i], Mpy_32_16_1( L_shl( frame_gain_fx, norm_shift ), win_fx[i] ) ); // Q_new - synSHB_fx[i] = L_add( synSHB_fx[i], overlap_fx[i] ); - synSHB_fx[i + l_shb_lahead] = Mpy_32_32( mod_syn_fx[i], L_shl( frame_gain_fx, norm_shift ) ); // Q_new - move32(); - move32(); - move32(); - } - - FOR( ; i < l_frame; i++ ) - { - synSHB_fx[i] = Mpy_32_32( mod_syn_fx[i], L_shl( frame_gain_fx, norm_shift ) ); // Q_new - move32(); - } - - FOR( ; i < l_frame + l_shb_lahead; i++ ) - { - synSHB_fx[i] = L_shl( synSHB_fx[i], sub( *Q_new, *Q_inp ) ); - overlap_fx[i - l_frame] = Mpy_32_32( mod_syn_fx[i], Mpy_32_16_1( L_shl( frame_gain_fx, norm_shift ), win_fx[l_frame + l_shb_lahead - 1 - i] ) ); // Q_new - move32(); - move32(); - } - - *Q_inp = *Q_new; - move16(); - return; -} diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 946dcf778ecf1d15c46605be765d20fea8123d36..238478b1aa6a7b3875be079d3a96dbf15b9dc929 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -72,7 +72,7 @@ void swb_tbe_reset_fx( * Reset the extra parameters needed for synthesis of the SWB TBE output *-------------------------------------------------------------------*/ -void swb_tbe_reset_synth_ivas_fx( +void swb_tbe_reset_synth_fx( Word32 genSHBsynth_Hilbert_Mem[], Word16 genSHBsynth_state_lsyn_filt_shb_local_fx[], Word32 genSHBsynth_state_lsyn_filt_shb_local_fx_32[] ) @@ -80,17 +80,11 @@ void swb_tbe_reset_synth_ivas_fx( set32_fx( genSHBsynth_Hilbert_Mem, 0, HILBERT_MEM_SIZE ); set16_fx( genSHBsynth_state_lsyn_filt_shb_local_fx, 0, 2 * ALLPASSSECTIONS_STEEP ); - set32_fx( genSHBsynth_state_lsyn_filt_shb_local_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP ); - return; -} -void swb_tbe_reset_synth_fx( - Word32 genSHBsynth_Hilbert_Mem[], - Word16 genSHBsynth_state_lsyn_filt_shb_local_fx[] ) -{ - - set32_fx( genSHBsynth_Hilbert_Mem, 0, HILBERT_MEM_SIZE ); - set16_fx( genSHBsynth_state_lsyn_filt_shb_local_fx, 0, 2 * ALLPASSSECTIONS_STEEP ); + if ( genSHBsynth_state_lsyn_filt_shb_local_fx_32 != NULL ) + { + set32_fx( genSHBsynth_state_lsyn_filt_shb_local_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP ); + } return; } @@ -486,10 +480,12 @@ void flip_and_downmix_generic_fx( *phase_state = j; move16(); + return; } -void flip_and_downmix_generic_fx_32( + +void flip_and_downmix_generic_fx32( Word32 input[], /* i : input spectrum Qx*/ Word32 output[], /* o : output spectrum Qx*/ const Word16 length, /* i : length of spectra */ @@ -5079,6 +5075,92 @@ void GenSHBSynth_fx( } +/* IVAS 32-bit variant */ +void GenSHBSynth_fx32( + const Word32 *input_synspeech, /* i : input synthesized speech Qx*/ + Word32 *shb_syn_speech_32k, /* o : output highband component Qx*/ + Word32 Hilbert_Mem[], /* i/o: memory Qx*/ + Word32 state_lsyn_filt_shb_local[], /* i/o: memory Qx*/ + const Word16 L_frame, /* i : ACELP frame length */ + Word16 *syn_dm_phase ) +{ + Word32 speech_buf_32k[L_FRAME32k]; + Word16 i; + +#ifdef FIX_881_HILBERT_FILTER + Word16 shift = 0; + Word32 maxm32, input_synspeech_temp[L_FRAME16k]; + move16(); + + /* find the maximum value and derive the shift to improve precision of the Hilber filter */ + maxm32 = L_deposit_l( 0 ); + FOR( i = 0; i < L_FRAME16k; i++ ) + { + maxm32 = L_max( maxm32, L_abs( input_synspeech[i] ) ); + } + + FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) + { + maxm32 = L_max( maxm32, L_abs( state_lsyn_filt_shb_local[i] ) ); + } + + FOR( i = 0; i < HILBERT_MEM_SIZE; i++ ) + { + maxm32 = L_max( maxm32, L_abs( Hilbert_Mem[i] ) ); + } + + IF( maxm32 != 0 ) + { + shift = sub( norm_l( maxm32 ), 3 ); + + Copy_Scale_sig32( input_synspeech, input_synspeech_temp, L_FRAME16k, shift ); + Scale_sig32( state_lsyn_filt_shb_local, 2 * ALLPASSSECTIONS_STEEP, shift ); + Scale_sig32( Hilbert_Mem, HILBERT_MEM_SIZE, shift ); + } + ELSE + { + Copy32( input_synspeech, input_synspeech_temp, L_FRAME16k ); + } + + Interpolate_allpass_steep_fx32( input_synspeech_temp, state_lsyn_filt_shb_local, L_FRAME16k, speech_buf_32k ); +#else + Interpolate_allpass_steep_fx32( input_synspeech, state_lsyn_filt_shb_local, L_FRAME16k, speech_buf_32k ); +#endif + + IF( EQ_16( L_frame, L_FRAME ) ) + { + flip_and_downmix_generic_fx32( speech_buf_32k, shb_syn_speech_32k, L_FRAME32k, Hilbert_Mem, Hilbert_Mem + HILBERT_ORDER1, Hilbert_Mem + ( HILBERT_ORDER1 + 2 * HILBERT_ORDER2 ), syn_dm_phase ); + } + ELSE + { + FOR( i = 0; i < L_FRAME32k; i++ ) + { + // shb_syn_speech_32k[i] = ( ( i % 2 ) == 0 ) ? ( -speech_buf_32k[i] ) : ( speech_buf_32k[i] ); + IF( i % 2 == 0 ) + { + shb_syn_speech_32k[i] = L_negate( speech_buf_32k[i] ); // Qx + } + ELSE + { + shb_syn_speech_32k[i] = speech_buf_32k[i]; // Qx + } + move32(); + } + } + +#ifdef FIX_881_HILBERT_FILTER + IF( maxm32 != 0 ) + { + Scale_sig32( shb_syn_speech_32k, L_FRAME32k, negate( shift ) ); + Scale_sig32( state_lsyn_filt_shb_local, 2 * ALLPASSSECTIONS_STEEP, negate( shift ) ); + Scale_sig32( Hilbert_Mem, HILBERT_MEM_SIZE, negate( shift ) ); + } +#endif + + return; +} + + /*==============================================================================*/ /* FUNCTION : void ScaleShapedSHB_fx() */ /*------------------------------------------------------------------------------*/ @@ -5300,6 +5382,165 @@ void ScaleShapedSHB_fx( return; } + +/* IVAS 32-bit variant */ +void ScaleShapedSHB_fx32( + const Word16 length, /* i : SHB overlap length */ + Word32 *synSHB_fx, /* i/o: synthesized shb signal Q_inp/Q_new */ + Word32 *overlap_fx, /* i/o: buffer for overlap-add Q_inp/Q_new */ + const Word16 *subgain_fx, /* i : subframe gain Q15 */ + const Word32 frame_gain_fx, /* i : frame gain Q18*/ + const Word16 *win_fx, /* i : window Q15 */ + const Word16 *subwin_fx, /* i : subframes window Q15 */ + Word16 *Q_inp, + Word16 *Q_new ) +{ + const Word16 *skip; + Word16 i, j, k, l_shb_lahead, l_frame; + Word16 join_length, num_join; + Word32 mod_syn_fx[L_FRAME16k + L_SHB_LAHEAD], L_tmp; + Word16 sum_gain_fx; + + /* initilaization */ + l_frame = L_FRAME16k; + l_shb_lahead = L_SHB_LAHEAD; + move16(); + move16(); + skip = skip_bands_SWB_TBE; + + IF( EQ_16( length, SHB_OVERLAP_LEN / 2 ) ) + { + skip = skip_bands_WB_TBE; + l_frame = L_FRAME16k / 4; + l_shb_lahead = L_SHB_LAHEAD / 4; + move16(); + move16(); + } + + /* apply gain for each subframe, and store noise output signal using overlap-add */ + set32_fx( mod_syn_fx, 0, l_frame + l_shb_lahead ); + + IF( EQ_16( length, SHB_OVERLAP_LEN / 2 ) ) + { + sum_gain_fx = 0; + move16(); + FOR( k = 0; k < shr( length, 1 ); k++ ) + { + sum_gain_fx = mult_r( subwin_fx[2 * k + 2], subgain_fx[0] ); + mod_syn_fx[skip[0] + k] = Mpy_32_16_1( synSHB_fx[skip[0] + k], sum_gain_fx ); + move32(); // Qx + mod_syn_fx[skip[0] + k + length / 2] = Mpy_32_16_1( synSHB_fx[skip[0] + k + length / 2], subgain_fx[0] ); // Qx + move32(); + } + FOR( i = 1; i < NUM_SHB_SUBFR / 2; i++ ) + { + FOR( k = 0; k < length; k++ ) + { + L_tmp = L_mult0( subwin_fx[k + 1], subgain_fx[i] ); + sum_gain_fx = round_fx( L_mac0( L_tmp, subwin_fx[length - k - 1], subgain_fx[i - 1] ) ); + mod_syn_fx[skip[i] + k] = L_shl( Mpy_32_16_1( synSHB_fx[skip[i] + k], sum_gain_fx ), 1 ); // Qx + move32(); + } + } + FOR( k = 0; k < shr( length, 1 ); k++ ) + { + sum_gain_fx = mult_r( subwin_fx[length - k * 2 - 2], subgain_fx[i - 1] ); + mod_syn_fx[skip[i] + k] = Mpy_32_16_1( synSHB_fx[skip[i] + k], sum_gain_fx ); // Qx + move32(); + } + } + ELSE + { + num_join = NUM_SHB_SUBFR / NUM_SHB_SUBGAINS; + join_length = i_mult( num_join, length ); + j = 0; + move16(); + move16(); + FOR( k = 0; k < length; k++ ) + { + mod_syn_fx[j] = Mpy_32_16_1( synSHB_fx[j], mult_r( subwin_fx[k + 1], subgain_fx[0] ) ); // Qx + move32(); + j = add( j, 1 ); + } + FOR( i = 0; i < NUM_SHB_SUBGAINS - 1; i++ ) + { + FOR( k = 0; k < join_length - length; k++ ) + { + mod_syn_fx[j] = Mpy_32_16_1( synSHB_fx[j], subgain_fx[i * num_join] ); // Qx + move32(); + j = add( j, 1 ); + } + + FOR( k = 0; k < length; k++ ) + { + L_tmp = L_mult0( subwin_fx[length - k - 1], subgain_fx[i * num_join] ); + mod_syn_fx[j] = L_shl( Mpy_32_16_1( synSHB_fx[j], round_fx( L_mac0( L_tmp, subwin_fx[k + 1], subgain_fx[( i + 1 ) * num_join] ) ) ), 1 ); // Qx + move32(); + j = add( j, 1 ); + } + } + FOR( k = 0; k < join_length - length; k++ ) + { + mod_syn_fx[j] = Mpy_32_16_1( synSHB_fx[j], subgain_fx[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); // Qx + move32(); + j = add( j, 1 ); + } + FOR( k = 0; k < length; k++ ) + { + mod_syn_fx[j] = Mpy_32_16_1( synSHB_fx[j], mult_r( subwin_fx[length - k - 1], subgain_fx[( NUM_SHB_SUBGAINS - 1 ) * num_join] ) ); // Qx + move32(); + j = add( j, 1 ); + } + } + + Word16 norm_shift = norm_l( frame_gain_fx ); + if ( frame_gain_fx == 0 ) + { + norm_shift = 31; + move16(); + } + + norm_shift = s_min( norm_shift, 14 ); + norm_shift = sub( norm_shift, 1 ); + + *Q_new = add( *Q_inp, sub( norm_shift, 13 ) ); // Q_new = Q_inp + min(norm_shift,14) - 14; + move16(); + FOR( i = 0; i < L_SHB_LAHEAD; i++ ) + { + overlap_fx[i] = L_shl( overlap_fx[i], sub( *Q_new, *Q_inp ) ); + move32(); + } + + FOR( i = 0; i < l_shb_lahead; i++ ) + { + synSHB_fx[i] = Mpy_32_32( mod_syn_fx[i], Mpy_32_16_1( L_shl( frame_gain_fx, norm_shift ), win_fx[i] ) ); // Q_new + synSHB_fx[i] = L_add( synSHB_fx[i], overlap_fx[i] ); + synSHB_fx[i + l_shb_lahead] = Mpy_32_32( mod_syn_fx[i], L_shl( frame_gain_fx, norm_shift ) ); // Q_new + move32(); + move32(); + move32(); + } + + FOR( ; i < l_frame; i++ ) + { + synSHB_fx[i] = Mpy_32_32( mod_syn_fx[i], L_shl( frame_gain_fx, norm_shift ) ); // Q_new + move32(); + } + + FOR( ; i < l_frame + l_shb_lahead; i++ ) + { + synSHB_fx[i] = L_shl( synSHB_fx[i], sub( *Q_new, *Q_inp ) ); + overlap_fx[i - l_frame] = Mpy_32_32( mod_syn_fx[i], Mpy_32_16_1( L_shl( frame_gain_fx, norm_shift ), win_fx[l_frame + l_shb_lahead - 1 - i] ) ); // Q_new + move32(); + move32(); + } + + *Q_inp = *Q_new; + move16(); + return; +} + + /*-------------------------------------------------------------------* * ScaleShapedWB() * @@ -5315,15 +5556,11 @@ void ScaleShapedWB_fx( const Word16 *win, /* i : window Q15*/ const Word16 *subwin, /* i : subframes window Q15*/ const Word16 Q_bwe_exc, - Word16 L_frame /* i : Frame length - determines whether 12.8 or 16kHz core in-use */ - , - Word16 dynQ /* i : indicate whether output is dynamic Q, or Q0 */ - , - Word16 *Qx /* o : newly computed Q factor for synSHB */ - , - Word16 prev_Qx /* i : prev_Qx for memory scaling */ - , - Word32 *Hilbert_Mem /* i : Hilbert memory used for computing Qx */ + Word16 L_frame, /* i : Frame length - determines whether 12.8 or 16kHz core in-use */ + Word16 dynQ, /* i : indicate whether output is dynamic Q, or Q0 */ + Word16 *Qx, /* o : newly computed Q factor for synSHB */ + Word16 prev_Qx, /* i : prev_Qx for memory scaling */ + Word32 *Hilbert_Mem /* i : Hilbert memory used for computing Qx */ ) { const Word16 *skip; diff --git a/lib_com/tcx_ltp_fx.c b/lib_com/tcx_ltp_fx.c index 9d7cb9254a7f93061a7183406fb65853e8559889..322549a6f0841e9d147075092d263ad85526b9da 100644 --- a/lib_com/tcx_ltp_fx.c +++ b/lib_com/tcx_ltp_fx.c @@ -1252,7 +1252,7 @@ Word16 tcx_ltp_decode_params( return 0; } -void tcx_ltp_post( +void tcx_ltp_post_fx( Decoder_State *st, TCX_LTP_DEC_HANDLE hTcxLtpDec, Word16 core, /* Q0 */ @@ -1616,7 +1616,8 @@ void tcx_ltp_post( } -void tcx_ltp_post32( +/* IVAS 32-bit variant */ +void tcx_ltp_post_fx32( Decoder_State *st, TCX_LTP_DEC_HANDLE hTcxLtpDec, Word16 core, /* Q0 */ diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index 0efc7e9a5316bab644ef252d6cf4f01d3e2c5118..0f94a755880de6be2a664858de5c6671b0ab543f 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -554,7 +554,7 @@ ivas_error acelp_core_dec_fx( IF( st_fx->cng_type == LP_CNG ) { - CNG_dec_fx( st_fx, st_fx->last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step_fx, sid_bw, q_env ); + 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, @@ -1386,7 +1386,7 @@ ivas_error acelp_core_dec_fx( IF( NE_16( st_fx->element_mode, IVAS_CPE_DFT ) || use_cldfb_for_dft ) { /* analysis of the synthesis at internal sampling rate */ - cldfbAnalysisFiltering( st_fx->cldfbAna, realBuffer, imagBuffer, &scaleFactor, syn_fx, negate( st_fx->Q_syn ), CLDFB_NO_COL_MAX, workBuffer ); + 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(); @@ -1446,7 +1446,7 @@ ivas_error acelp_core_dec_fx( st_fx->Q_syn2 = st_fx->Q_syn; move16(); { - cldfbSynthesisFiltering( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, synth_out, negate( st_fx->Q_syn2 ), CLDFB_NO_COL_MAX, workBuffer ); + 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 ) ); diff --git a/lib_dec/acelp_core_switch_dec_fx.c b/lib_dec/acelp_core_switch_dec_fx.c index b2cc593b3d8f632ccaf1b29930f9abff5622399c..3217e2f2a296c4f7cbf5dca5fa76605116d06387 100644 --- a/lib_dec/acelp_core_switch_dec_fx.c +++ b/lib_dec/acelp_core_switch_dec_fx.c @@ -204,8 +204,7 @@ ivas_error acelp_core_switch_dec_fx( { return error; } - cldfbAnalysisFiltering( st_fx->cldfbAna, realBuffer, imagBuffer, &scaleFactor, synth_intFreq, - negate( st_fx->Q_syn ), CLDFB_NO_COL_MAX_SWITCH, workBuffer ); + cldfbAnalysis_fx( st_fx->cldfbAna, realBuffer, imagBuffer, &scaleFactor, synth_intFreq, negate( st_fx->Q_syn ), CLDFB_NO_COL_MAX_SWITCH, workBuffer ); cldfb_restore_memory( st_fx->cldfbAna ); /* CLDFB synthesis of the combined signal */ @@ -236,7 +235,7 @@ ivas_error acelp_core_switch_dec_fx( { return error; } - cldfbSynthesisFiltering( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, synth_subfr_out, 0, CLDFB_NO_COL_MAX_SWITCH, workBuffer ); + cldfbSynthesis_fx( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, synth_subfr_out, 0, CLDFB_NO_COL_MAX_SWITCH, workBuffer ); cldfb_restore_memory( st_fx->cldfbSyn ); *Q_syn = 0; move16(); @@ -578,8 +577,7 @@ ivas_error acelp_core_switch_dec_bfi_fx( { return error; } - cldfbAnalysisFiltering( st_fx->cldfbAna, realBuffer, imagBuffer, &scaleFactor, syn, - negate( st_fx->Q_syn ), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer ); + cldfbAnalysis_fx( st_fx->cldfbAna, realBuffer, imagBuffer, &scaleFactor, syn, negate( st_fx->Q_syn ), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer ); cldfb_restore_memory( st_fx->cldfbAna ); scaleFactor.hb_scale = scaleFactor.lb_scale; @@ -590,8 +588,8 @@ ivas_error acelp_core_switch_dec_bfi_fx( { return error; } - cldfbSynthesisFiltering( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, synth_out, - negate( st_fx->Q_syn ), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer ); + cldfbSynthesis_fx( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, synth_out, + negate( st_fx->Q_syn ), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer ); /* output to Q0 */ Scale_sig( synth_out, L_FRAME48k, negate( st_fx->Q_syn ) ); // Q0 @@ -830,7 +828,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( { return error; } - /*cldfbAnalysisFiltering( st_fx->cldfbAna, realBuffer, imagBuffer, &scaleFactor, syn, + /*cldfbAnalysis_fx( st_fx->cldfbAna, realBuffer, imagBuffer, &scaleFactor, syn, negate(st_fx->Q_syn), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer);*/ cldfbAnalysis_ivas_fx( syn32, realBuffer, imagBuffer, shr( st_fx->L_frame, 1 ), st_fx->cldfbAna ); cldfb_restore_memory_ivas_fx( st_fx->cldfbAna ); @@ -840,7 +838,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( { return error; } - /*cldfbSynthesisFiltering( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, synth_out, + /*cldfbSynthesis_fx( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, synth_out, negate(st_fx->Q_syn), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer );*/ Scale_sig32( st_fx->cldfbSyn->cldfb_state_fx, st_fx->cldfbSyn->cldfb_state_length, 1 ); // Q_cldfb_state+1 st_fx->cldfbSyn->Q_cldfb_state = add( st_fx->cldfbSyn->Q_cldfb_state, 1 ); diff --git a/lib_dec/amr_wb_dec_fx.c b/lib_dec/amr_wb_dec_fx.c index 6a427ca5344f5eecd8c45eb5aee4a14b775ddff8..db4ad2bb021122533aba2ec98cb77b9455a90804 100644 --- a/lib_dec/amr_wb_dec_fx.c +++ b/lib_dec/amr_wb_dec_fx.c @@ -214,11 +214,10 @@ ivas_error amr_wb_dec_fx( test(); IF( !st_fx->bfi && st_fx->prev_bfi && ( EQ_16( st_fx->last_codec_mode, MODE2 ) ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) ) { - /* v_multc(st_fx->old_out_fx, st_fx->plcInfo.recovery_gain, */ - /* st_fx->old_out_fx, st_fx->L_frameTCX); */ + /* v_multc(st_fx->old_out_fx, st_fx->hPlcInfo.recovery_gain, st_fx->old_out_fx, st_fx->L_frameTCX); */ FOR( i = 0; i < hTcxDec->L_frameTCX; i++ ) { - hHQ_core->old_out_fx[i] = shl( mult_r( hHQ_core->old_out_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); + hHQ_core->old_out_fx[i] = shl( mult_r( hHQ_core->old_out_fx[i], st_fx->hPlcInfo->recovery_gain ), 1 ); move16(); } } @@ -873,8 +872,7 @@ ivas_error amr_wb_dec_fx( bass_psfilter_fx( st_fx->hBPF, st_fx->Opt_AMR_WB, syn_fx, L_FRAME, pitch_buf_fx, st_fx->bpf_off, st_fx->stab_fac_fx, &st_fx->stab_fac_smooth_fx, GENERIC, st_fx->Q_syn, bpf_error_signal ); - cldfbAnalysisFiltering( st_fx->cldfbAna, realBuffer, imagBuffer, &scaleFactor, syn_fx, - negate( st_fx->Q_syn ), CLDFB_NO_COL_MAX, workBuffer ); + 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(); @@ -899,8 +897,9 @@ ivas_error amr_wb_dec_fx( move16(); } cldfb_synth_set_bandsToZero( st_fx, realBuffer, imagBuffer, CLDFB_NO_COL_MAX, scaleFactor ); + /* CLDFB synthesis of the combined signal */ - cldfbSynthesisFiltering( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, synth_out_fx, negate( st_fx->Q_syn2 ), CLDFB_NO_COL_MAX, workBuffer ); + cldfbSynthesis_fx( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, synth_out_fx, negate( st_fx->Q_syn2 ), CLDFB_NO_COL_MAX, workBuffer ); /* Bring CLDFB output to Q-1 */ Scale_sig( synth_out_fx, output_frame, negate( st_fx->Q_syn2 ) ); @@ -964,7 +963,7 @@ ivas_error amr_wb_dec_fx( test(); test(); - IF( !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && EQ_16( st_fx->last_codec_mode, MODE2 ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) && EQ_16( st_fx->plcInfo.concealment_method, TCX_NONTONAL ) && LT_32( st_fx->plcInfo.nbLostCmpt, 4 ) ) + IF( !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && EQ_16( st_fx->last_codec_mode, MODE2 ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) && EQ_16( st_fx->hPlcInfo->concealment_method, TCX_NONTONAL ) && LT_32( st_fx->hPlcInfo->nbLostCmpt, 4 ) ) { waveadj_rec = 1; move16(); @@ -1076,9 +1075,7 @@ ivas_error amr_wb_dec_fx( move16(); } - waveform_adj2_fix( st_fx->tonalMDCTconceal.secondLastPcmOut, synth_out_fx + tmps, st_fx->plcInfo.data_noise, &st_fx->plcInfo.outx_new_n1_fx, - &st_fx->plcInfo.nsapp_gain_fx, &st_fx->plcInfo.nsapp_gain_n_fx, &st_fx->plcInfo.recovery_gain, st_fx->plcInfo.step_concealgain_fx, - st_fx->plcInfo.Pitch_fx, st_fx->plcInfo.FrameSize, tmps, add( extract_l( st_fx->plcInfo.nbLostCmpt ), 1 ), st_fx->bfi ); + waveform_adj2_fix( st_fx->hPlcInfo, st_fx->hTonalMDCTConc->secondLastPcmOut, synth_out_fx + tmps, tmps, add( extract_l( st_fx->hPlcInfo->nbLostCmpt ), 1 ), st_fx->bfi ); } /* HP filter */ @@ -1096,7 +1093,7 @@ ivas_error amr_wb_dec_fx( move16(); Scale_sig( hTcxLtpDec->tcxltp_mem_in, delta, sub( st_fx->Q_syn2, st_fx->Qprev_synth_buffer_fx ) ); Scale_sig( hTcxLtpDec->tcxltp_mem_out, output_frame, sub( st_fx->Q_syn2, st_fx->Qprev_synth_buffer_fx ) ); - tcx_ltp_post( st_fx, hTcxLtpDec, ACELP_CORE, output_frame, 0, synth_out_fx, NULL ); + tcx_ltp_post_fx( st_fx, hTcxLtpDec, ACELP_CORE, output_frame, 0, synth_out_fx, NULL ); } /* final output of synthesis signal */ syn_output_fx( st_fx->codec_mode, synth_out_fx, output_frame, output_sp, st_fx->Q_syn2 ); diff --git a/lib_dec/bass_psfilter_fx.c b/lib_dec/bass_psfilter_fx.c index 75cabf160042c12159d477ea02f447c97ef37456..45cf7feed026f9c1ef1b419d1f21e5fb08b2691a 100644 --- a/lib_dec/bass_psfilter_fx.c +++ b/lib_dec/bass_psfilter_fx.c @@ -841,14 +841,7 @@ void addBassPostFilter_fx( } /* do the CLDFB anlysis of filtered signal */ - cldfbAnalysisFiltering( cldfbBank_bpf_Fx, - tmp_R_Fx, - tmp_I_Fx, - &scale, - harm_timeIn_Fx, - timeIn_e, - nTimeSlots, - workBuffer ); + cldfbAnalysis_fx( cldfbBank_bpf_Fx, tmp_R_Fx, tmp_I_Fx, &scale, harm_timeIn_Fx, timeIn_e, nTimeSlots, workBuffer ); /* now do the subtraction */ diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c index ab349773ee6e3948dc03edf782479bb9e57ce3c5..945f0ca758ed89671ff73a19fe0ba7ff25ab0357 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -1377,9 +1377,8 @@ void swb_CNG_dec_fx( Decoder_State *st_fx, /* i/o: State structure */ const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz Qsyn*/ Word16 *shb_synth_fx, /* o : high-band CNG synthesis Qx*/ - const Word16 sid_bw /* i : 0-NB/WB, 1-SWB SID Q0*/ - , - const Word16 Qsyn /* i : Q value of ACELP core synthesis */ + const Word16 sid_bw, /* i : 0-NB/WB, 1-SWB SID Q0*/ + const Word16 Qsyn /* i : Q value of ACELP core synthesis */ ) { test(); @@ -1393,18 +1392,18 @@ void swb_CNG_dec_fx( } st_fx->last_vad_fx = 0; move16(); - st_fx->hTdCngDec->burst_cnt = 0; + st_fx->hTdCngDec->burst_cnt_fx = 0; move16(); } ELSE { st_fx->last_vad_fx = 1; move16(); - st_fx->hTdCngDec->burst_cnt = add( st_fx->hTdCngDec->burst_cnt, 1 ); + st_fx->hTdCngDec->burst_cnt_fx = add( st_fx->hTdCngDec->burst_cnt_fx, 1 ); move16(); - if ( GT_16( st_fx->hTdCngDec->burst_cnt, 10 ) ) + if ( GT_16( st_fx->hTdCngDec->burst_cnt_fx, 10 ) ) { - st_fx->hTdCngDec->burst_cnt = 0; + st_fx->hTdCngDec->burst_cnt_fx = 0; move16(); } } @@ -1431,18 +1430,18 @@ void swb_CNG_dec_ivas_fx( } st_fx->last_vad_fx = 0; move16(); - st_fx->hTdCngDec->burst_cnt = 0; + st_fx->hTdCngDec->burst_cnt_fx = 0; move16(); } ELSE { st_fx->last_vad_fx = 1; move16(); - st_fx->hTdCngDec->burst_cnt = add_sat( st_fx->hTdCngDec->burst_cnt, 1 ); // saturation reached? + st_fx->hTdCngDec->burst_cnt_fx = add_sat( st_fx->hTdCngDec->burst_cnt_fx, 1 ); // saturation reached? move16(); - if ( GT_16( st_fx->hTdCngDec->burst_cnt, 10 ) ) + if ( GT_16( st_fx->hTdCngDec->burst_cnt_fx, 10 ) ) { - st_fx->hTdCngDec->burst_cnt = 0; + st_fx->hTdCngDec->burst_cnt_fx = 0; move16(); } } @@ -1466,6 +1465,7 @@ static void shb_CNG_decod_fx( { Word16 i; Word16 idx_ener_fx; + TD_CNG_DEC_HANDLE hTdCngDec; Word16 shb_lpcCNG_fx[LPC_SHB_ORDER + 1]; Word16 shb_lspCNG_fx[LPC_SHB_ORDER]; Word16 excTmp_fx[L_FRAME16k]; @@ -1489,7 +1489,9 @@ static void shb_CNG_decod_fx( move16(); Word16 q; TD_BWE_DEC_HANDLE hBWE_TD; + hBWE_TD = st_fx->hBWE_TD; + hTdCngDec = st_fx->hTdCngDec; IF( st_fx->bfi == 0 ) { @@ -1506,8 +1508,8 @@ static void shb_CNG_decod_fx( IF( st_fx->element_mode == EVS_MONO ) { /* de-quantization of SHB CNG parameters */ - L_tmp = L_mult( idx_ener_fx, 27400 ); /*Q14 */ - st_fx->last_shb_cng_ener_fx = extract_l( L_shr( L_sub( L_tmp, 295924 ), 6 ) ); /*Q8 */ + L_tmp = L_mult( idx_ener_fx, 27400 ); /*Q14 */ + hTdCngDec->last_shb_cng_ener_fx = extract_l( L_shr( L_sub( L_tmp, 295924 ), 6 ) ); /*Q8 */ move16(); } ELSE @@ -1519,21 +1521,21 @@ static void shb_CNG_decod_fx( /* SHB spectrum estimation */ - interp_fx = s_min( st_fx->shb_dtx_count_fx, 32 ); + interp_fx = s_min( hTdCngDec->shb_dtx_count_fx, 32 ); interp_fx = shl_sat( interp_fx, 10 ); /*Q15*/ FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - tmp2 = mult( interp_fx, st_fx->lsp_shb_prev_fx[i] ); /*Q14*/ - tmp = mult( sub( 32767, interp_fx ), st_fx->lsp_shb_prev_prev_fx[i] ); /*Q14*/ + tmp2 = mult( interp_fx, hTdCngDec->lsp_shb_prev_fx[i] ); /*Q14*/ + tmp = mult( sub( 32767, interp_fx ), hTdCngDec->lsp_shb_prev_prev_fx[i] ); /*Q14*/ shb_lspCNG_fx[i] = add( tmp2, tmp ); move16(); /*Q14*/ } IF( NE_16( st_fx->element_mode, IVAS_CPE_DFT ) ) { - if ( LT_16( st_fx->shb_dtx_count_fx, 1000 ) ) + if ( LT_16( hTdCngDec->shb_dtx_count_fx, 1000 ) ) { - st_fx->shb_dtx_count_fx = add( st_fx->shb_dtx_count_fx, 1 ); + hTdCngDec->shb_dtx_count_fx = add( hTdCngDec->shb_dtx_count_fx, 1 ); move16(); } } @@ -1555,10 +1557,10 @@ static void shb_CNG_decod_fx( wb_ener16_fx = round_fx( L_shl( wb_ener_fx, 10 ) ); /*wb_ener_fx in Q8 */ if ( !st_fx->first_CNG ) { - st_fx->wb_cng_ener_fx = wb_ener16_fx; + hTdCngDec->wb_cng_ener_fx = wb_ener16_fx; move16(); /*Q8 */ } - if ( GT_16( abs_s( sub( wb_ener16_fx, st_fx->wb_cng_ener_fx ) ), 3072 ) ) + if ( GT_16( abs_s( sub( wb_ener16_fx, hTdCngDec->wb_cng_ener_fx ) ), 3072 ) ) { allow_cn_step_fx = 1; move16(); @@ -1566,52 +1568,52 @@ static void shb_CNG_decod_fx( IF( EQ_16( allow_cn_step_fx, 1 ) ) { - st_fx->wb_cng_ener_fx = wb_ener16_fx; + hTdCngDec->wb_cng_ener_fx = wb_ener16_fx; move16(); /*Q8 */ } ELSE { - tmp = sub( wb_ener16_fx, st_fx->wb_cng_ener_fx ); /*Q8 */ - tmp = mult_r( tmp, 29491 ); /*Q8 */ - st_fx->wb_cng_ener_fx = add( st_fx->wb_cng_ener_fx, tmp ); /*Q8 */ + tmp = sub( wb_ener16_fx, hTdCngDec->wb_cng_ener_fx ); /*Q8 */ + tmp = mult_r( tmp, 29491 ); /*Q8 */ + hTdCngDec->wb_cng_ener_fx = add( hTdCngDec->wb_cng_ener_fx, tmp ); /*Q8 */ move16(); } test(); test(); IF( EQ_32( st_fx->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) && ( st_fx->bfi == 0 ) ) { - st_fx->last_wb_cng_ener_fx = st_fx->wb_cng_ener_fx; + hTdCngDec->last_wb_cng_ener_fx = hTdCngDec->wb_cng_ener_fx; move16(); if ( !st_fx->first_CNG ) { - st_fx->shb_cng_ener_fx = st_fx->last_shb_cng_ener_fx; + hTdCngDec->shb_cng_ener_fx = hTdCngDec->last_shb_cng_ener_fx; move16(); } } - gain_fx = sub( st_fx->wb_cng_ener_fx, st_fx->last_wb_cng_ener_fx ); /* Q8 */ + gain_fx = sub( hTdCngDec->wb_cng_ener_fx, hTdCngDec->last_wb_cng_ener_fx ); /* Q8 */ if ( GT_16( gain_fx, 15 ) ) { gain_fx = 15; move16(); } - step_fx = sub( add( gain_fx, st_fx->last_shb_cng_ener_fx ), st_fx->shb_cng_ener_fx ); /*Q8 */ + step_fx = sub( add( gain_fx, hTdCngDec->last_shb_cng_ener_fx ), hTdCngDec->shb_cng_ener_fx ); /*Q8 */ test(); IF( EQ_16( allow_cn_step_fx, 1 ) || GT_32( st_fx->last_core_brate, SID_2k40 ) ) { - st_fx->shb_cng_ener_fx = add( st_fx->shb_cng_ener_fx, step_fx ); /* Q8 */ + hTdCngDec->shb_cng_ener_fx = add( hTdCngDec->shb_cng_ener_fx, step_fx ); /* Q8 */ move16(); } ELSE { - st_fx->shb_cng_ener_fx = add( st_fx->shb_cng_ener_fx, mult( 8192, step_fx ) ); /*Q8 */ + hTdCngDec->shb_cng_ener_fx = add( hTdCngDec->shb_cng_ener_fx, mult( 8192, step_fx ) ); /*Q8 */ move16(); } /* generate white noise excitation */ FOR( i = 0; i < L_FRAME16k; i++ ) { - excTmp_fx[i] = shr_r( Random( &st_fx->swb_cng_seed ), 8 ); + excTmp_fx[i] = shr_r( Random( &hTdCngDec->swb_cng_seed ), 8 ); move16(); /*Q-8*/ } @@ -1632,23 +1634,23 @@ static void shb_CNG_decod_fx( ener_excSHB_fx = round_fx( L_tmp ); /*Qq */ IF( EQ_16( st_fx->last_vad_fx, 1 ) ) { - st_fx->trans_cnt_fx = 0; + hTdCngDec->trans_cnt_fx = 0; move16(); test(); - IF( GT_16( st_fx->hTdCngDec->burst_cnt, 3 ) && NE_16( st_fx->last_core, HQ_CORE ) ) + IF( GT_16( hTdCngDec->burst_cnt_fx, 3 ) && NE_16( st_fx->last_core, HQ_CORE ) ) { - st_fx->trans_cnt_fx = 5; + hTdCngDec->trans_cnt_fx = 5; move16(); } } - ener_fx = st_fx->shb_cng_ener_fx; + ener_fx = hTdCngDec->shb_cng_ener_fx; move16(); /*Q8 */ - IF( st_fx->trans_cnt_fx > 0 ) + IF( hTdCngDec->trans_cnt_fx > 0 ) { - i = extract_l( L_mult0( st_fx->trans_cnt_fx, 17 ) ); /*Q0 */ - ener_fx = add_sat( st_fx->shb_cng_ener_fx, mult( sin_table256_fx[i], sub_sat( st_fx->last_shb_ener_fx, st_fx->shb_cng_ener_fx ) ) ); /*Q8 */ - st_fx->trans_cnt_fx = sub( st_fx->trans_cnt_fx, 1 ); + i = extract_l( L_mult0( hTdCngDec->trans_cnt_fx, 17 ) ); /*Q0 */ + ener_fx = add_sat( hTdCngDec->shb_cng_ener_fx, mult( sin_table256_fx[i], sub_sat( hTdCngDec->last_shb_ener_fx, hTdCngDec->shb_cng_ener_fx ) ) ); /*Q8 */ + hTdCngDec->trans_cnt_fx = sub( hTdCngDec->trans_cnt_fx, 1 ); move16(); } @@ -1698,13 +1700,13 @@ static void shb_CNG_decod_fx( /* rescale the Hilbert memories to Q0 */ FOR( i = 0; i < HILBERT_MEM_SIZE; i++ ) { - hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] = L_shr( hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i], st_fx->prev_Q_bwe_syn2 ); /* st_fx->prev_Q_bwe_syn2 */ + hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] = L_shr( hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i], hBWE_TD->prev_Q_bwe_syn2 ); /* hBWE_TD->prev_Q_bwe_syn2 */ move32(); } FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { - hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i], st_fx->prev_Q_bwe_syn2 ); /* st_fx->prev_Q_bwe_syn2 */ + hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i], hBWE_TD->prev_Q_bwe_syn2 ); /* hBWE_TD->prev_Q_bwe_syn2 */ move16(); } } @@ -1712,10 +1714,10 @@ static void shb_CNG_decod_fx( IF( EQ_32( st_fx->output_Fs, 48000 ) ) { - interpolate_3_over_2_allpass_fx( shb_synth_fx, L_FRAME32k, shb_synth_fx, st_fx->interpol_3_2_cng_dec_fx, allpass_poles_3_ov_2 ); + interpolate_3_over_2_allpass_fx( shb_synth_fx, L_FRAME32k, shb_synth_fx, hTdCngDec->interpol_3_2_cng_dec_fx, allpass_poles_3_ov_2 ); } - ResetSHBbuffer_Dec_fx( st_fx ); + ResetSHBbuffer_Dec_fx( st_fx->hBWE_TD, st_fx->extl ); return; } @@ -1729,6 +1731,7 @@ static void shb_CNG_decod_ivas_fx( { Word16 i; Word16 idx_ener; + TD_CNG_DEC_HANDLE hTdCngDec; Word16 shb_lpcCNG_fx[LPC_SHB_ORDER + 1]; Word16 shb_lspCNG_fx[LPC_SHB_ORDER]; Word16 excTmp_fx[L_FRAME16k]; @@ -1750,7 +1753,9 @@ static void shb_CNG_decod_ivas_fx( Word16 allow_cn_step_fx; Word16 q; TD_BWE_DEC_HANDLE hBWE_TD; + hBWE_TD = st->hBWE_TD; + hTdCngDec = st->hTdCngDec; allow_cn_step_fx = 0; move16(); @@ -1770,37 +1775,37 @@ static void shb_CNG_decod_ivas_fx( /* de-quantization of SHB CNG parameters */ IF( st->element_mode == EVS_MONO ) { - st->hTdCngDec->last_shb_cng_ener_fx_32 = L_sub( L_mult0( idx_ener, 6850 ), 36991 ); // Q11 + hTdCngDec->last_shb_cng_ener_fx_32 = L_sub( L_mult0( idx_ener, 6850 ), 36991 ); // Q11 move32(); } ELSE { - st->hTdCngDec->last_shb_cng_ener_fx_32 = L_sub( L_mult0( idx_ener, 8807 ), 36991 ); // Q11 + hTdCngDec->last_shb_cng_ener_fx_32 = L_sub( L_mult0( idx_ener, 8807 ), 36991 ); // Q11 move32(); } } } /* SHB spectrum estimation */ - interp_fx = s_min( st->hTdCngDec->shb_dtx_count, 32 ); + interp_fx = s_min( hTdCngDec->shb_dtx_count_fx, 32 ); interp_fx = shl_sat( interp_fx, 10 ); /*Q15*/ FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - shb_lspCNG_fx[i] = add( mult_r( interp_fx, st->hTdCngDec->lsp_shb_prev_fx[i] ), mult_r( sub( 32767, interp_fx ), st->hTdCngDec->lsp_shb_prev_prev_fx[i] ) ); // Q14 + shb_lspCNG_fx[i] = add( mult_r( interp_fx, hTdCngDec->lsp_shb_prev_fx[i] ), mult_r( sub( 32767, interp_fx ), hTdCngDec->lsp_shb_prev_prev_fx[i] ) ); // Q14 move16(); } - IF( LE_16( st->hTdCngDec->shb_dtx_count, 1000 ) ) + IF( LE_16( hTdCngDec->shb_dtx_count_fx, 1000 ) ) { - st->hTdCngDec->shb_dtx_count = add( st->hTdCngDec->shb_dtx_count, 1 ); + hTdCngDec->shb_dtx_count_fx = add( hTdCngDec->shb_dtx_count_fx, 1 ); move16(); } E_LPC_lsf_lsp_conversion( shb_lspCNG_fx, tmp_lsp, LPC_SHB_ORDER ); /*Q14*/ E_LPC_f_lsp_a_conversion( tmp_lsp, shb_lpcCNG_fx, LPC_SHB_ORDER ); - Copy_Scale_sig( shb_lpcCNG_fx, st->hTdCngDec->shb_lpcCNG_fx, LPC_SHB_ORDER + 1, sub( norm_s( shb_lpcCNG_fx[0] ), -1 ) ); /* Q15 */ + Copy_Scale_sig( shb_lpcCNG_fx, hTdCngDec->shb_lpcCNG_fx, LPC_SHB_ORDER + 1, sub( norm_s( shb_lpcCNG_fx[0] ), -1 ) ); /* Q15 */ Copy_Scale_sig( shb_lpcCNG_fx, shb_lpcCNG_fx, LPC_SHB_ORDER + 1, sub( norm_s( shb_lpcCNG_fx[0] ), 2 ) ); /* Q12 */ @@ -1821,10 +1826,10 @@ static void shb_CNG_decod_ivas_fx( Word32 wb_ener32_fx = L_shl( wb_ener16_fx, 3 ); /*wb_ener_fx in Q11 */ if ( EQ_16( st->first_CNG, 0 ) ) { - st->hTdCngDec->wb_cng_ener_fx_32 = wb_ener32_fx; + hTdCngDec->wb_cng_ener_fx_32 = wb_ener32_fx; move32(); /*Q11 */ } - if ( GT_32( L_abs( L_sub( wb_ener32_fx, st->hTdCngDec->wb_cng_ener_fx_32 ) ), 24576 ) ) /* 12.0f in Q11 */ + if ( GT_32( L_abs( L_sub( wb_ener32_fx, hTdCngDec->wb_cng_ener_fx_32 ) ), 24576 ) ) /* 12.0f in Q11 */ { allow_cn_step_fx = 1; move16(); @@ -1832,52 +1837,52 @@ static void shb_CNG_decod_ivas_fx( IF( EQ_16( allow_cn_step_fx, 1 ) ) { - st->hTdCngDec->wb_cng_ener_fx_32 = wb_ener32_fx; + hTdCngDec->wb_cng_ener_fx_32 = wb_ener32_fx; move32(); /*Q11 */ } ELSE { - tmp = L_sub( wb_ener32_fx, st->hTdCngDec->wb_cng_ener_fx_32 ); /*Q11 */ - tmp = Mpy_32_16_1( tmp, 29491 ); /*Q11 */ - st->hTdCngDec->wb_cng_ener_fx_32 = L_add( st->hTdCngDec->wb_cng_ener_fx_32, tmp ); /*Q11 */ + tmp = L_sub( wb_ener32_fx, hTdCngDec->wb_cng_ener_fx_32 ); /*Q11 */ + tmp = Mpy_32_16_1( tmp, 29491 ); /*Q11 */ + hTdCngDec->wb_cng_ener_fx_32 = L_add( hTdCngDec->wb_cng_ener_fx_32, tmp ); /*Q11 */ move32(); } test(); test(); IF( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) && EQ_16( st->bfi, 0 ) ) { - st->hTdCngDec->last_wb_cng_ener_fx_32 = st->hTdCngDec->wb_cng_ener_fx_32; /* Q11 */ + hTdCngDec->last_wb_cng_ener_fx_32 = hTdCngDec->wb_cng_ener_fx_32; /* Q11 */ move32(); if ( !st->first_CNG ) { - st->hTdCngDec->shb_cng_ener_fx_32 = st->hTdCngDec->last_shb_cng_ener_fx_32; /* Q11 */ + hTdCngDec->shb_cng_ener_fx_32 = hTdCngDec->last_shb_cng_ener_fx_32; /* Q11 */ move32(); } } - gain_fx = L_sub( st->hTdCngDec->wb_cng_ener_fx_32, st->hTdCngDec->last_wb_cng_ener_fx_32 ); /*Q11 */ + gain_fx = L_sub( hTdCngDec->wb_cng_ener_fx_32, hTdCngDec->last_wb_cng_ener_fx_32 ); /*Q11 */ if ( GT_32( gain_fx, 30720 ) ) { gain_fx = 30720; move32(); } - step_fx = L_sub( L_add( gain_fx, st->hTdCngDec->last_shb_cng_ener_fx_32 ), st->hTdCngDec->shb_cng_ener_fx_32 ); /*Q11 */ + step_fx = L_sub( L_add( gain_fx, hTdCngDec->last_shb_cng_ener_fx_32 ), hTdCngDec->shb_cng_ener_fx_32 ); /*Q11 */ test(); IF( EQ_16( allow_cn_step_fx, 1 ) || GT_32( st->last_core_brate, SID_2k40 ) ) { - st->hTdCngDec->shb_cng_ener_fx_32 = L_add( st->hTdCngDec->shb_cng_ener_fx_32, step_fx ); /* Q11 */ + hTdCngDec->shb_cng_ener_fx_32 = L_add( hTdCngDec->shb_cng_ener_fx_32, step_fx ); /* Q11 */ move32(); } ELSE { - st->hTdCngDec->shb_cng_ener_fx_32 = L_add( st->hTdCngDec->shb_cng_ener_fx_32, L_shr( step_fx, 2 ) ); /*Q11 */ + hTdCngDec->shb_cng_ener_fx_32 = L_add( hTdCngDec->shb_cng_ener_fx_32, L_shr( step_fx, 2 ) ); /*Q11 */ move32(); } /* generate white noise excitation */ FOR( i = 0; i < L_FRAME16k; i++ ) { - excTmp_fx[i] = shr_r( Random( &st->hTdCngDec->swb_cng_seed ), 8 ); + excTmp_fx[i] = shr_r( Random( &hTdCngDec->swb_cng_seed ), 8 ); move16(); /*Q-8*/ } @@ -1896,29 +1901,26 @@ static void shb_CNG_decod_ivas_fx( L_tmp = L_shl( L_tmp, q ); q = sub( q, 32 ); ener_excSHB_fx = round_fx( L_tmp ); /*Qq */ -#ifdef MSAN_FIX + IF( EQ_16( st->last_vad_fx, 1 ) ) -#else - IF( EQ_16( st->last_vad, 1 ) ) -#endif { - st->hTdCngDec->trans_cnt = 0; + hTdCngDec->trans_cnt_fx = 0; move16(); test(); - if ( GT_16( st->hTdCngDec->burst_cnt, 3 ) && NE_16( st->last_core, HQ_CORE ) ) + if ( GT_16( hTdCngDec->burst_cnt_fx, 3 ) && NE_16( st->last_core, HQ_CORE ) ) { - st->hTdCngDec->trans_cnt = 5; + hTdCngDec->trans_cnt_fx = 5; move16(); } } - ener_fx = st->hTdCngDec->shb_cng_ener_fx_32; + ener_fx = hTdCngDec->shb_cng_ener_fx_32; move32(); /*Q11 */ - IF( GT_16( st->hTdCngDec->trans_cnt, 0 ) ) + IF( GT_16( st->hTdCngDec->trans_cnt_fx, 0 ) ) { - i = extract_l( L_mult0( st->hTdCngDec->trans_cnt, 17 ) ); /*Q0 */ - ener_fx = L_add( st->hTdCngDec->shb_cng_ener_fx_32, Mpy_32_16_1( L_sub( st->hTdCngDec->last_shb_ener_fx, st->hTdCngDec->shb_cng_ener_fx_32 ), sin_table256_fx[i] ) ); /*Q11 */ - st->hTdCngDec->trans_cnt = sub( st->hTdCngDec->trans_cnt, 1 ); + i = extract_l( L_mult0( hTdCngDec->trans_cnt_fx, 17 ) ); /*Q0 */ + ener_fx = L_add( hTdCngDec->shb_cng_ener_fx_32, Mpy_32_16_1( L_sub( hTdCngDec->last_shb_ener_fx_32, hTdCngDec->shb_cng_ener_fx_32 ), sin_table256_fx[i] ) ); /*Q11 */ + hTdCngDec->trans_cnt_fx = sub( hTdCngDec->trans_cnt_fx, 1 ); move16(); } @@ -1960,7 +1962,7 @@ static void shb_CNG_decod_ivas_fx( L_tmp = L_deposit_h( tmp_16 ); /*Q31 */ tmp_16 = sub( add( 5, exp ), add( q, exp1 ) ); L_gain_fx = Isqrt_lc( L_tmp, &tmp_16 ); /*Q31-Qtmp */ - st->hTdCngDec->shb_cng_gain_fx_32 = ener_fx; + hTdCngDec->shb_cng_gain_fx_32 = ener_fx; move32(); FOR( i = 0; i < L_FRAME16k; i++ ) { @@ -1974,13 +1976,13 @@ static void shb_CNG_decod_ivas_fx( /* rescale the Hilbert memories to Q0 */ FOR( i = 0; i < HILBERT_MEM_SIZE; i++ ) { - hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] = L_shr( hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i], st->prev_Q_bwe_syn2 ); /* st_fx->prev_Q_bwe_syn2 */ + hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] = L_shr( hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i], hBWE_TD->prev_Q_bwe_syn2 ); /* hBWE_TD->prev_Q_bwe_syn2 */ move32(); } FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { - hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i], st->prev_Q_bwe_syn2 ); /* st_fx->prev_Q_bwe_syn2 */ + hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i], hBWE_TD->prev_Q_bwe_syn2 ); /* hBWE_TD->prev_Q_bwe_syn2 */ move16(); } } @@ -1988,11 +1990,13 @@ static void shb_CNG_decod_ivas_fx( IF( EQ_32( st->output_Fs, 48000 ) ) { - interpolate_3_over_2_allpass_fx( shb_synth_fx, L_FRAME32k, shb_synth_fx, st->interpol_3_2_cng_dec_fx, allpass_poles_3_ov_2 ); + interpolate_3_over_2_allpass_fx( shb_synth_fx, L_FRAME32k, shb_synth_fx, hTdCngDec->interpol_3_2_cng_dec_fx, allpass_poles_3_ov_2 ); } Scale_sig( shb_synth_fx, L_FRAME48k, -3 ); /* Qx - 3 */ - ResetSHBbuffer_Dec_fx( st ); + + ResetSHBbuffer_Dec_fx( st->hBWE_TD, st->extl ); + return; } @@ -2005,62 +2009,6 @@ static void shb_CNG_decod_ivas_fx( void td_cng_dec_init_fx( DEC_CORE_HANDLE st /* i/o: decoder state structure */ ) -{ - TD_CNG_DEC_HANDLE hTdCngDec; - - hTdCngDec = st->hTdCngDec; - - hTdCngDec->cng_seed = RANDOM_INITSEED; - move16(); - hTdCngDec->cng_ener_seed = RANDOM_INITSEED; - move16(); - hTdCngDec->cng_ener_seed1 = RANDOM_INITSEED; - move16(); - hTdCngDec->old_enr_index = -1; - move16(); - hTdCngDec->Enew_fx = L_deposit_l( 0 ); /* Q6*/ - move16(); - hTdCngDec->last_allow_cn_step = 0; - move16(); - hTdCngDec->ho_hist_ptr = -1; - move16(); - hTdCngDec->ho_sid_bw = L_deposit_l( 0 ); - move16(); - set16_fx( hTdCngDec->ho_lsp_hist_fx, 0, HO_HIST_SIZE * M ); - set32_fx( hTdCngDec->ho_ener_hist_fx, 0, HO_HIST_SIZE ); - set32_fx( hTdCngDec->ho_env_hist_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG ); - hTdCngDec->ho_hist_size = 0; - move16(); - hTdCngDec->act_cnt = 0; - move16(); - hTdCngDec->ho_circ_ptr = -1; - move16(); - set16_fx( hTdCngDec->ho_lsp_circ_fx, 0, HO_HIST_SIZE * M ); - set32_fx( hTdCngDec->ho_ener_circ_fx, 0, HO_HIST_SIZE ); - set32_fx( hTdCngDec->ho_env_circ_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG ); - hTdCngDec->ho_circ_size = 0; - move16(); - - set16_fx( hTdCngDec->ho_16k_lsp, 0, HO_HIST_SIZE ); - hTdCngDec->act_cnt2 = 0; - move16(); - hTdCngDec->num_ho = 0; - move16(); - hTdCngDec->last_cng_type_fx = -1; - move16(); - set32_fx( hTdCngDec->lp_env_fx, 0, NUM_ENV_CNG ); - set16_fx( hTdCngDec->exc_mem_fx, 0, 24 ); - set16_fx( hTdCngDec->exc_mem1_fx, 0, 30 ); - set32_fx( hTdCngDec->old_env_fx, 0, NUM_ENV_CNG ); - hTdCngDec->burst_cnt = 0; - move16(); - - return; -} - -void td_cng_dec_init_ivas_fx( - DEC_CORE_HANDLE st /* i/o: decoder state structure */ -) { Word16 i; TD_CNG_DEC_HANDLE hTdCngDec; @@ -2080,6 +2028,8 @@ void td_cng_dec_init_ivas_fx( Copy( st->lsp_old_fx, st->lspCNG_fx, M ); // Q(15) hTdCngDec->last_allow_cn_step = 0; move16(); + hTdCngDec->shb_cng_ener_fx = -1541; // Q8 + move16(); hTdCngDec->shb_cng_ener_fx_32 = -12329; // -6.02 in Q(11) move32(); IF( st->element_mode != EVS_MONO ) @@ -2091,10 +2041,16 @@ void td_cng_dec_init_ivas_fx( move32(); } + hTdCngDec->wb_cng_ener_fx = -1541; // Q8 + move16(); hTdCngDec->wb_cng_ener_fx_32 = -12329; // Q(11) move32(); + hTdCngDec->last_wb_cng_ener_fx = -1541; // Q8 + move16(); hTdCngDec->last_wb_cng_ener_fx_32 = -12329; // Q(11) move32(); + hTdCngDec->last_shb_cng_ener_fx = -1541; // Q8 + move16(); hTdCngDec->last_shb_cng_ener_fx_32 = -12329; // Q(11) move32(); hTdCngDec->swb_cng_seed = RANDOM_INITSEED; @@ -2146,17 +2102,18 @@ void td_cng_dec_init_ivas_fx( move16(); } - hTdCngDec->shb_dtx_count = 0; + hTdCngDec->shb_dtx_count_fx = 0; move16(); - hTdCngDec->trans_cnt = 0; + hTdCngDec->trans_cnt_fx = 0; move16(); - hTdCngDec->burst_cnt = 0; + hTdCngDec->burst_cnt_fx = 0; move16(); - hTdCngDec->last_shb_ener_fx = 2; // 0.001 in Q11 + hTdCngDec->last_shb_ener_fx = 0; // Q8 + move16(); + hTdCngDec->last_shb_ener_fx_32 = 2; // 0.001 in Q11 move32(); - set16_fx( hTdCngDec->interpol_3_2_cng_dec_fx, 0, INTERP_3_2_MEM_LEN ); return; diff --git a/lib_dec/core_dec_init_fx.c b/lib_dec/core_dec_init_fx.c index dd268fe083ed61cdf5e23233a66d88a24d2148ae..967a93bfbb1a0f63da3846387ed0f3b0ccfb998e 100644 --- a/lib_dec/core_dec_init_fx.c +++ b/lib_dec/core_dec_init_fx.c @@ -836,7 +836,7 @@ void open_decoder_LPD_fx( st->Mode2_lp_gainp = L_deposit_l( 0 ); /* 15Q16 */ move32(); - st->prev_widow_left_rect = 0; + st->hTcxDec->prev_widow_left_rect = 0; move16(); if ( st->hTcxDec != NULL ) { @@ -1029,33 +1029,29 @@ void open_decoder_LPD_fx( test(); IF( EQ_16( st->ini_frame, 0 ) || LT_32( st->last_total_brate, HQ_48k ) || EQ_16( st->last_codec_mode, MODE1 ) || st->force_lpd_reset ) { - concealment_init_x( hTcxDec->L_frameTCX, &st->plcInfo ); + concealment_init_x( hTcxDec->L_frameTCX, st->hPlcInfo ); } } /* PLC: [TCX: Tonal Concealment] */ -#if 0 - PMT("handle to tonalMDCTconceal is missing") -#endif - //#ifdef ADD_IVAS_HTONALMDCTCONC test(); test(); - IF( /*st->ADD_IVAS_HTONALMDCTCONC != NULL &&*/ !( st->element_mode > EVS_MONO && NE_16( st->ini_frame, 0 ) && EQ_16( st->tonalMDCTconceal.nSamples, st->hTcxDec->L_frameTCX ) ) ) + IF( st->hTonalMDCTConc != NULL && !( st->element_mode > EVS_MONO && NE_16( st->ini_frame, 0 ) && EQ_16( st->hTonalMDCTConc->nSamples, st->hTcxDec->L_frameTCX ) ) ) { - st->tonalMDCTconceal.nScaleFactors = 0; + st->hTonalMDCTConc->nScaleFactors = 0; move16(); - st->tonalMDCTconceal.nSamples = 0; + st->hTonalMDCTConc->nSamples = 0; move16(); - st->tonalMDCTconceal.lastPcmOut = 0x0; + st->hTonalMDCTConc->lastPcmOut = 0x0; move16(); - st->tonalMDCTconceal.q_lastPcmOut = Q15; + st->hTonalMDCTConc->q_lastPcmOut = Q15; move16(); - st->tonalMDCTconceal.lastBlockData.tonalConcealmentActive = 0; + st->hTonalMDCTConc->lastBlockData.tonalConcealmentActive = 0; move16(); - st->tonalMDCTconceal.lastBlockData.nSamples = 0; + st->hTonalMDCTConc->lastBlockData.nSamples = 0; move16(); - TonalMDCTConceal_Init( &st->tonalMDCTconceal, hTcxDec->L_frameTCX, st->L_frame, FDNS_NPTS, st->hTcxCfg ); + TonalMDCTConceal_Init( st->hTonalMDCTConc, hTcxDec->L_frameTCX, st->L_frame, FDNS_NPTS, st->hTcxCfg ); } st->last_tns_active = 0; move16(); diff --git a/lib_dec/core_dec_switch_fx.c b/lib_dec/core_dec_switch_fx.c index 2fd3f1d2ec32c0b8b0308378c73062f344bbfe71..63c35f876e3da1d41836c8b99f588463a42c8502 100644 --- a/lib_dec/core_dec_switch_fx.c +++ b/lib_dec/core_dec_switch_fx.c @@ -197,11 +197,7 @@ void mode_switch_decoder_LPD_fx( ( EQ_16( st->bwidth, SWB ) && NE_16( st->last_extl, SWB_TBE ) ) || ( EQ_16( st->bwidth, FB ) && NE_16( st->last_extl, FB_TBE ) ) ) { -#ifdef IVAS_CODE TBEreset_dec_fx( st ); -#else - TBEreset_dec_fx( st, st->bwidth ); -#endif } ELSE { @@ -445,7 +441,7 @@ void mode_switch_decoder_LPD_ivas_fx( ( EQ_16( st->bwidth, SWB ) && NE_16( st->last_extl, SWB_TBE ) ) || ( EQ_16( st->bwidth, FB ) && NE_16( st->last_extl, FB_TBE ) ) ) { - TBEreset_dec_ivas_fx( st ); + TBEreset_dec_fx( st ); } ELSE { diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index 34a07b702ed4fac1e33760d93dc53e3eeea5987c..b913dedb10da4eabe98cd2fcfc7f5a6e642c482e 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -277,7 +277,7 @@ void bw_switching_pre_proc_fx( { st_fx->prev_ener_shb_fx = 0; move16(); - set16_fx( st_fx->prev_SWB_fenv_fx, 0, SWB_FENV ); + set16_fx( st_fx->hBWE_FD->prev_SWB_fenv_fx, 0, SWB_FENV ); } ELSE IF( ( ( st_fx->core == ACELP_CORE && ( EQ_16( st_fx->last_core, HQ_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) || EQ_16( st_fx->last_core, TCX_20_CORE ) ) ) || ( EQ_16( st_fx->core, st_fx->last_core ) && NE_16( st_fx->extl, st_fx->last_extl ) ) ) && GE_16( st_fx->last_bwidth, SWB ) ) { @@ -486,7 +486,7 @@ ivas_error core_switching_pre_dec_fx( { return error; } - cldfbAnalysisFiltering( st_fx->cldfbAna, realBuffer, imagBuffer, &scaleFactor, hTcxDec->syn_Overl, 0, no_col, workBuffer ); + cldfbAnalysis_fx( st_fx->cldfbAna, realBuffer, imagBuffer, &scaleFactor, hTcxDec->syn_Overl, 0, no_col, workBuffer ); cldfb_restore_memory( st_fx->cldfbAna ); scaleFactor.hb_scale = scaleFactor.lb_scale; @@ -497,7 +497,7 @@ ivas_error core_switching_pre_dec_fx( { return error; } - cldfbSynthesisFiltering( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, hHQ_core->fer_samples_fx, 0, no_col, workBuffer ); + cldfbSynthesis_fx( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, hHQ_core->fer_samples_fx, 0, no_col, workBuffer ); cldfb_restore_memory( st_fx->cldfbSyn ); } @@ -1150,7 +1150,7 @@ ivas_error core_switching_post_dec_fx( move16(); hBWE_FD->prev_weight_fx = 6554; move16(); /*0.2 in Q15*/ - st_fx->prev_fb_ener_adjust_fx = 0; + hBWE_FD->prev_fb_ener_adjust_fx = 0; move16(); } @@ -1202,8 +1202,8 @@ ivas_error core_switching_post_dec_fx( swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) ); - set16_fx( st_fx->GainShape_Delay, 0, NUM_SHB_SUBFR / 2 ); - swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); + set16_fx( hBWE_TD->GainShape_Delay_fx, 0, NUM_SHB_SUBFR / 2 ); + swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32 ); IF( EQ_16( output_frame, L_FRAME16k ) ) { @@ -1230,9 +1230,9 @@ ivas_error core_switching_post_dec_fx( test(); test(); test(); - IF( EQ_32( st_fx->output_Fs, 48000 ) && ( ( GT_32( st_fx->last_core_brate, SID_2k40 ) ) && ( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) ) ) + IF( st_fx->hTdCngDec != NULL && EQ_32( st_fx->output_Fs, 48000 ) && ( ( GT_32( st_fx->last_core_brate, SID_2k40 ) ) && ( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) ) ) { - set16_fx( st_fx->interpol_3_2_cng_dec_fx, 0, INTERP_3_2_MEM_LEN ); + set16_fx( st_fx->hTdCngDec->interpol_3_2_cng_dec_fx, 0, INTERP_3_2_MEM_LEN ); } /* reset FB TBE buffers */ @@ -1266,7 +1266,6 @@ ivas_error core_switching_post_dec_ivas_fx( Word16 *synth, /* i/o: output synthesis Qsynth*/ Word32 *output_fx, /* i/o: LB synth/upsampled LB synth Q4*/ Word16 output_mem_fx[], /* i : OLA memory from last TCX/HQ frame Qx*/ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo Q0*/ const Word16 output_frame, /* i : frame length Q0*/ const Word16 core_switching_flag, /* i : ACELP->HQ switching flag Q0*/ @@ -1514,11 +1513,12 @@ ivas_error core_switching_post_dec_ivas_fx( test(); test(); test(); - IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( ivas_format, ISM_FORMAT ) && EQ_16( st_fx->core, TCX_20_CORE ) /* <- means TCX in general, TCX10 is forbidden after ACELP */ ) ) && LE_32( st_fx->last_core_brate, SID_2k40 ) && GT_32( st_fx->core_brate, SID_2k40 ) ) + IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || ( st_fx->is_ism_format && EQ_16( st_fx->core, TCX_20_CORE ) /* <- means TCX in general, TCX10 is forbidden after ACELP */ ) ) && LE_32( st_fx->last_core_brate, SID_2k40 ) && GT_32( st_fx->core_brate, SID_2k40 ) ) { /* smooth transitions to avoid pops in car noise items */ smoothTransitionDtxToTcx_fx( synth, output_frame, delay_comp ); } + /* Reset memories of CLDFBs */ IF( st_fx->cldfbAna != NULL ) { @@ -1782,7 +1782,7 @@ ivas_error core_switching_post_dec_ivas_fx( move16(); hBWE_FD->prev_weight_fx = 6554; move16(); /*0.2 in Q15*/ - st_fx->prev_fb_ener_adjust_fx = 0; + hBWE_FD->prev_fb_ener_adjust_fx = 0; move16(); } @@ -1843,12 +1843,11 @@ ivas_error core_switching_post_dec_ivas_fx( swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) ); - set16_fx( st_fx->GainShape_Delay, 0, NUM_SHB_SUBFR / 2 ); - // swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); - swb_tbe_reset_synth_ivas_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32 ); + set16_fx( hBWE_TD->GainShape_Delay_fx, 0, NUM_SHB_SUBFR / 2 ); + swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32 ); - st_fx->hBWE_TD->prev_pow_exc16kWhtnd_fx32 = 1; /* Q0 1.f */ - st_fx->hBWE_TD->prev_mix_factor_fx = 32767; /* Q15 1.f */ + hBWE_TD->prev_pow_exc16kWhtnd_fx32 = 1; /* Q0 1.f */ + hBWE_TD->prev_mix_factor_fx = 32767; /* Q15 1.f */ move16(); move16(); @@ -1872,7 +1871,7 @@ ivas_error core_switching_post_dec_ivas_fx( } ELSE IF( st_fx->hBWE_TD != NULL && ( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) ) { - TBEreset_dec_ivas_fx( st_fx ); + TBEreset_dec_fx( st_fx ); } /* reset FB TBE buffers */ @@ -1904,9 +1903,9 @@ ivas_error core_switching_post_dec_ivas_fx( test(); test(); test(); - IF( EQ_32( st_fx->output_Fs, 48000 ) && ( ( GT_32( st_fx->last_core_brate, SID_2k40 ) ) && ( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) ) ) + IF( st_fx->hTdCngDec != NULL && EQ_32( st_fx->output_Fs, 48000 ) && ( ( GT_32( st_fx->last_core_brate, SID_2k40 ) ) && ( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) ) ) { - set16_fx( st_fx->interpol_3_2_cng_dec_fx, 0, INTERP_3_2_MEM_LEN ); + set16_fx( st_fx->hTdCngDec->interpol_3_2_cng_dec_fx, 0, INTERP_3_2_MEM_LEN ); } return error; @@ -2316,7 +2315,7 @@ ivas_error core_switching_pre_dec_ivas_fx( st->hHQ_core->last_max_pos_pulse = 0; move16(); - set16_fx( st->hHQ_core->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM ); + set16_fx( st->hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); st->hHQ_core->prev_frm_hfe2 = 0; st->hHQ_core->prev_stab_hfe2 = 0; move16(); @@ -2682,7 +2681,7 @@ ivas_error core_switching_pre_dec_ivas_fx( st->hHQ_core->last_max_pos_pulse = 0; move16(); - set16_fx( st->hHQ_core->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM ); + set16_fx( st->hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); st->hHQ_core->prev_frm_hfe2 = 0; st->hHQ_core->prev_stab_hfe2 = 0; move16(); @@ -2703,7 +2702,7 @@ ivas_error core_switching_pre_dec_ivas_fx( IF( NE_16( st->last_core, TCX_20_CORE ) && NE_16( st->last_core, TCX_10_CORE ) ) { set16_fx( st->hHQ_core->old_out_fx, 0, output_frame ); - set32_fx( st->hHQ_core->old_outLB_fx, 0, L_FRAME16k ); + set32_fx( st->hHQ_core->old_out_LB_fx32, 0, L_FRAME16k ); set16_fx( st->hHQ_core->old_out_LB_fx, 0, L_FRAME16k ); } @@ -2725,7 +2724,7 @@ ivas_error core_switching_pre_dec_ivas_fx( ELSE { set16_fx( st->hHQ_core->old_out_fx, 0, output_frame ); - set32_fx( st->hHQ_core->old_outLB_fx, 0, L_FRAME16k ); + set32_fx( st->hHQ_core->old_out_LB_fx32, 0, L_FRAME16k ); } } @@ -3147,12 +3146,11 @@ void ivas_bw_switching_pre_proc_fx( test(); IF( EQ_16( st->last_bwidth, 0 ) && LE_16( st->extl, SWB_CNG ) ) { - st->prev_ener_shb_fx = 0; move16(); IF( st->hBWE_FD != NULL ) { - set16_fx( st->prev_SWB_fenv_fx, 0, SWB_FENV ); + set16_fx( st->hBWE_FD->prev_SWB_fenv_fx, 0, SWB_FENV ); } } ELSE IF( ( ( ( st->core == ACELP_CORE ) && ( EQ_16( st->last_core, HQ_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || EQ_16( st->last_core, TCX_20_CORE ) ) ) || ( EQ_16( st->core, st->last_core ) && NE_16( st->extl, st->last_extl ) ) ) && GE_16( st->last_bwidth, SWB ) ) diff --git a/lib_dec/dec_LPD_fx.c b/lib_dec/dec_LPD_fx.c index f3443349a1a542e0ff66f85b2ba1650107e1c2f8..d5294eb7a0a9eed009f3475c4f24be9270a76377 100644 --- a/lib_dec/dec_LPD_fx.c +++ b/lib_dec/dec_LPD_fx.c @@ -455,7 +455,7 @@ void decoder_LPD_fx( } if ( bfi ) { - st->plcInfo.nbLostCmpt = add( st->plcInfo.nbLostCmpt, 1 ); + st->hPlcInfo->nbLostCmpt = add( st->hPlcInfo->nbLostCmpt, 1 ); move16(); } } @@ -634,7 +634,7 @@ void decoder_LPD_fx( /* PLC: [TCX: Tonal Concealment] */ /* Signal that this frame is not TCX */ - TonalMDCTConceal_UpdateState( &st->tonalMDCTconceal, 0, 0, 0, 0 ); + TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, 0, 0, 0, 0 ); IF( bfi == 0 ) { @@ -752,21 +752,18 @@ void decoder_LPD_fx( EQ_16( st->last_codec_mode, MODE2 ) ) ) { /* waveform adjustment */ + concealment_signal_tuning_fx( st, bfi, synthFB, past_core_mode ); - concealment_signal_tuning_fx( bfi, st->core, - synthFB, &st->plcInfo, st->nbLostCmpt, st->prev_bfi, - st->tonalMDCTconceal.secondLastPcmOut, - past_core_mode, st->tonalMDCTconceal.lastPcmOut, st ); test(); test(); test(); - IF( ( bfi || st->prev_bfi ) && st->plcInfo.Pitch_fx && ( ( st->plcInfo.concealment_method == TCX_NONTONAL ) ) ) + IF( ( bfi || st->prev_bfi ) && st->hPlcInfo->Pitch_fx && ( ( st->hPlcInfo->concealment_method == TCX_NONTONAL ) ) ) { lerp( synthFB, synth, L_frame, L_frameTCX ); test(); if ( !bfi && st->prev_bfi ) { - st->plcInfo.Pitch_fx = 0; + st->hPlcInfo->Pitch_fx = 0; move16(); } } @@ -774,7 +771,7 @@ void decoder_LPD_fx( IF( !bfi ) { - TonalMDCTConceal_SaveTimeSignal( &st->tonalMDCTconceal, synthFB, L_frameTCX ); + TonalMDCTConceal_SaveTimeSignal( st->hTonalMDCTConc, synthFB, L_frameTCX ); } #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT decoder_tcx_post_fx( st, synth, synthFB, Aq, bfi, 0 ); @@ -977,13 +974,13 @@ void decoder_LPD_fx( { if ( !bfi ) { - st->plcInfo.nbLostCmpt = 0; + st->hPlcInfo->nbLostCmpt = 0; move16(); } IF( st->core == 0 ) { - set_state( st->plcInfo.Transient, st->core, MAX_POST_LEN ); + set_state( st->hPlcInfo->Transient, st->core, MAX_POST_LEN ); } } diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 49a6b6f3b4b9003d6a23c734b575db6561908acb..510370aee17754504d869a36ce2a37fca6a74b0e 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -153,7 +153,7 @@ void decoder_tcx_fx( L_frameTCX = st->L_frameTCX_past; move16(); - left_rect = st->prev_widow_left_rect; + left_rect = hTcxDec->prev_widow_left_rect; move16(); IF( left_rect != 0 ) @@ -190,7 +190,7 @@ void decoder_tcx_fx( move16(); left_rect = 1; move16(); - st->prev_widow_left_rect = 1; + hTcxDec->prev_widow_left_rect = 1; move16(); } ELSE @@ -202,7 +202,7 @@ void decoder_tcx_fx( move16(); left_rect = 0; move16(); - st->prev_widow_left_rect = 0; + hTcxDec->prev_widow_left_rect = 0; move16(); } @@ -763,42 +763,42 @@ void decoder_tcx_fx( { IF( EQ_16( st->nbLostCmpt, 1 ) ) { - st->plcInfo.concealment_method = TCX_NONTONAL; + st->hPlcInfo->concealment_method = TCX_NONTONAL; move16(); /* tonal/non-tonal decision */ test(); test(); - IF( EQ_16( st->plcInfo.Transient[0], 1 ) && EQ_16( st->plcInfo.Transient[1], 1 ) && EQ_16( st->plcInfo.Transient[2], 1 ) ) + IF( EQ_16( st->hPlcInfo->Transient[0], 1 ) && EQ_16( st->hPlcInfo->Transient[1], 1 ) && EQ_16( st->hPlcInfo->Transient[2], 1 ) ) { Word16 sum_word16 = 0; move16(); FOR( i = 9; i >= 0; i-- ) { - sum_word16 = add( sum_word16, st->plcInfo.TCX_Tonality[i] ); + sum_word16 = add( sum_word16, st->hPlcInfo->TCX_Tonality[i] ); } if ( GE_16( sum_word16, 6 ) ) { - st->plcInfo.concealment_method = TCX_TONAL; + st->hPlcInfo->concealment_method = TCX_TONAL; move16(); } } if ( st->tonal_mdct_plc_active ) { - st->plcInfo.concealment_method = TCX_TONAL; + st->hPlcInfo->concealment_method = TCX_TONAL; move16(); } } if ( GT_16( L_frameTCX, hTcxDec->L_frameTCX ) ) { - st->plcInfo.concealment_method = TCX_TONAL; + st->hPlcInfo->concealment_method = TCX_TONAL; move16(); } - temp_concealment_method = st->plcInfo.concealment_method; + temp_concealment_method = st->hPlcInfo->concealment_method; move16(); if ( EQ_16( st->core, TCX_10_CORE ) ) @@ -810,7 +810,7 @@ void decoder_tcx_fx( /* get the starting location of the subframe in the frame */ IF( EQ_16( st->core, TCX_10_CORE ) ) { - st->plcInfo.subframe_fx = extract_l( L_mult0( frame_cnt, L_frameTCX_glob ) ); + st->hPlcInfo->subframe_fx = extract_l( L_mult0( frame_cnt, L_frameTCX_glob ) ); move16(); } } @@ -821,8 +821,7 @@ void decoder_tcx_fx( IF( bfi == 0 ) { - TonalMDCTConceal_SaveFreqSignal( &st->tonalMDCTconceal, x, x_e, L_frameTCX, - L_frame, gainlpc2, gainlpc2_e, gain_tcx_e ); + TonalMDCTConceal_SaveFreqSignal( st->hTonalMDCTConc, x, x_e, L_frameTCX, L_frame, gainlpc2, gainlpc2_e, gain_tcx_e ); } ELSE { @@ -852,8 +851,8 @@ void decoder_tcx_fx( Word16 exp1, exp2; Word32 E_2ndlast, E_last; - E_2ndlast = CalculateAbsEnergy_fx( 1, &( st->tonalMDCTconceal.lastBlockData.spectralData[0] ), infoIGFStartLine, &exp2 ); - E_last = CalculateAbsEnergy_fx( 1, &( st->tonalMDCTconceal.lastBlockData.spectralData[1] ), infoIGFStartLine, &exp1 ); + E_2ndlast = CalculateAbsEnergy_fx( 1, &( st->hTonalMDCTConc->lastBlockData.spectralData[0] ), infoIGFStartLine, &exp2 ); + E_last = CalculateAbsEnergy_fx( 1, &( st->hTonalMDCTConc->lastBlockData.spectralData[1] ), infoIGFStartLine, &exp1 ); BASOP_Util_Divide_MantExp( extract_h( E_2ndlast ), exp2, extract_h( E_last ), exp1, &tmp1, &tmp2 ); @@ -865,7 +864,7 @@ void decoder_tcx_fx( FOR( i = 0; i < infoIGFStartLine; i += 2 ) { move32(); - st->tonalMDCTconceal.lastBlockData.spectralData[i] = st->tonalMDCTconceal.lastBlockData.spectralData[i + 1]; + st->hTonalMDCTConc->lastBlockData.spectralData[i] = st->hTonalMDCTConc->lastBlockData.spectralData[i + 1]; } } ELSE IF( LT_16( tmp1, 4096 /*0.5 in Q13*/ ) ) @@ -873,7 +872,7 @@ void decoder_tcx_fx( FOR( i = 0; i < infoIGFStartLine; i += 2 ) { move32(); - st->tonalMDCTconceal.lastBlockData.spectralData[i + 1] = st->tonalMDCTconceal.lastBlockData.spectralData[i]; + st->hTonalMDCTConc->lastBlockData.spectralData[i + 1] = st->hTonalMDCTConc->lastBlockData.spectralData[i]; } } } @@ -892,7 +891,7 @@ void decoder_tcx_fx( tcxGetNoiseFillingTilt( A, M, L_frame, tmp, &noiseTiltFactor ); - TonalMDCTConceal_InsertNoise( &st->tonalMDCTconceal, x, &x_e, st->tonal_mdct_plc_active, &st->seed_tcx_plc, + TonalMDCTConceal_InsertNoise( st->hTonalMDCTConc, x, &x_e, st->tonal_mdct_plc_active, &st->seed_tcx_plc, noiseTiltFactor, f, #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT concealment_noise, @@ -980,7 +979,7 @@ void decoder_tcx_fx( test(); IF( bfi && st->tonal_mdct_plc_active ) { - TonalMDCTConceal_Apply( &st->tonalMDCTconceal, x, &x_e ); + TonalMDCTConceal_Apply( st->hTonalMDCTConc, x, &x_e ); } tmp32 = L_deposit_h( 0 ); @@ -996,11 +995,8 @@ void decoder_tcx_fx( tmp8 = 1; move16(); } - TonalMDCTConceal_UpdateState( &st->tonalMDCTconceal, - L_frameTCX, - tmp32, - bfi, - tmp8 ); + + TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, L_frameTCX, tmp32, bfi, tmp8 ); IF( st->enablePlcWaveadjust ) { @@ -1011,10 +1007,11 @@ void decoder_tcx_fx( IF( bfi && ( EQ_16( temp_concealment_method, TCX_NONTONAL ) ) ) { /* x_e =31-x_scale; */ - concealment_decode_fix( core, x, &x_e, &st->plcInfo ); + concealment_decode_fix( core, x, &x_e, st->hPlcInfo ); } + /* update spectrum buffer, tonality flag, etc. */ - concealment_update_x( bfi, core, st->tonality_flag, x, &x_e, &st->plcInfo ); + concealment_update_x( bfi, core, st->tonality_flag, x, &x_e, st->hPlcInfo ); } /*-----------------------------------------------------------* @@ -1305,7 +1302,7 @@ void decoder_tcx_post_fx( Decoder_State *st_fx, { test(); /* run lpc gain compensation not for waveform adjustment */ - IF( 0 == st_fx->enablePlcWaveadjust || EQ_16( st_fx->plcInfo.concealment_method, TCX_TONAL ) ) + IF( 0 == st_fx->enablePlcWaveadjust || EQ_16( st_fx->hPlcInfo->concealment_method, TCX_TONAL ) ) { UWord32 dmy; tmp32_1 /*gainHelperFB*/ = L_shl_r( L_deposit_h( hTcxDec->gainHelper ), sub( hTcxDec->gainHelper_e, 31 - 28 ) ); /*Q28*/ @@ -1475,20 +1472,19 @@ void decoder_tcx_post_fx( Decoder_State *st_fx, move16(); /* run lpc gain compensation not for waveform adjustment */ test(); - IF( 0 == st_fx->enablePlcWaveadjust || EQ_16( st_fx->plcInfo.concealment_method, TCX_TONAL ) ) + IF( 0 == st_fx->enablePlcWaveadjust || EQ_16( st_fx->hPlcInfo->concealment_method, TCX_TONAL ) ) { - st_fx->plcInfo.recovery_gain = extract_h( L_shl_o( Mpy_32_16_1( conceal_eof_gainFB, - st_fx->last_concealed_gain_syn_deemph ), - st_fx->last_concealed_gain_syn_deemph_e, &Overflow ) ); /*Q30->Q14*/ + st_fx->hPlcInfo->recovery_gain = extract_h( L_shl_o( Mpy_32_16_1( conceal_eof_gainFB, + st_fx->last_concealed_gain_syn_deemph ), + st_fx->last_concealed_gain_syn_deemph_e, &Overflow ) ); /*Q30->Q14*/ move16(); } ELSE { - st_fx->plcInfo.recovery_gain = extract_h( conceal_eof_gainFB ); /*Q14*/ + st_fx->hPlcInfo->recovery_gain = extract_h( conceal_eof_gainFB ); /*Q14*/ move16(); } - st_fx->plcInfo.step_concealgain_fx = - round_fx_sat( L_shl_sat( L_mult0( round_fx_sat( step ), round_fx_sat( L_shl_sat( L_mult0( st_fx->L_frame, getInvFrameLen( hTcxDec->L_frameTCX ) ), 8 ) ) ), 3 ) ); /*Q15*/ + st_fx->hPlcInfo->step_concealgain_fx = round_fx_sat( L_shl_sat( L_mult0( round_fx_sat( step ), round_fx_sat( L_shl_sat( L_mult0( st_fx->L_frame, getInvFrameLen( hTcxDec->L_frameTCX ) ), 8 ) ) ), 3 ) ); /*Q15*/ move16(); } @@ -1585,7 +1581,7 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, test(); test(); /* run lpc gain compensation not for waveform adjustment */ - IF( 0 == st_fx->enablePlcWaveadjust || ( st_fx->hPlcInfo != NULL && EQ_16( st_fx->plcInfo.concealment_method, TCX_TONAL ) ) ) + IF( 0 == st_fx->enablePlcWaveadjust || ( st_fx->hPlcInfo != NULL && EQ_16( st_fx->hPlcInfo->concealment_method, TCX_TONAL ) ) ) { UWord32 dmy; tmp32_1 /*gainHelperFB*/ = L_shl_r( L_deposit_h( hTcxDec->gainHelper ), sub( hTcxDec->gainHelper_e, 31 - 28 ) ); /*Q28*/ @@ -1804,22 +1800,22 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, } /* run lpc gain compensation not for waveform adjustment */ - test(); - IF( 0 == st_fx->enablePlcWaveadjust || EQ_16( st_fx->plcInfo.concealment_method, TCX_TONAL ) ) + IF( st_fx->hPlcInfo != NULL ) { - st_fx->plcInfo.recovery_gain = extract_h( L_shl_o( Mpy_32_16_1( conceal_eof_gainFB, - st_fx->last_concealed_gain_syn_deemph ), - st_fx->last_concealed_gain_syn_deemph_e, &Overflow ) ); /*Q30->Q14*/ - move16(); - } - ELSE - { - st_fx->plcInfo.recovery_gain = extract_h( conceal_eof_gainFB ); /*Q14*/ + test(); + IF( 0 == st_fx->enablePlcWaveadjust || EQ_16( st_fx->hPlcInfo->concealment_method, TCX_TONAL ) ) + { + st_fx->hPlcInfo->recovery_gain = extract_h( L_shl_o( Mpy_32_16_1( conceal_eof_gainFB, st_fx->last_concealed_gain_syn_deemph ), st_fx->last_concealed_gain_syn_deemph_e, &Overflow ) ); /*Q30->Q14*/ + move16(); + } + ELSE + { + st_fx->hPlcInfo->recovery_gain = extract_h( conceal_eof_gainFB ); /*Q14*/ + move16(); + } + st_fx->hPlcInfo->step_concealgain_fx = round_fx_sat( L_shl_sat( L_mult0( round_fx_sat( L_shr_sat( step, sub( 1, step_e ) ) ), round_fx_sat( L_shl_sat( L_mult0( st_fx->L_frame, getInvFrameLen( hTcxDec->L_frameTCX ) ), 8 ) ) ), 4 ) ); /*Q15*/ move16(); } - st_fx->plcInfo.step_concealgain_fx = - round_fx_sat( L_shl_sat( L_mult0( round_fx_sat( L_shr_sat( step, sub( 1, step_e ) ) ), round_fx_sat( L_shl_sat( L_mult0( st_fx->L_frame, getInvFrameLen( hTcxDec->L_frameTCX ) ), 8 ) ) ), 4 ) ); /*Q15*/ - move16(); } /*-----------------------------------------------------------* @@ -4410,7 +4406,11 @@ void decoder_tcx_noisefilling_fx( /* get the starting location of the subframe in the frame */ IF( EQ_16( st->core, TCX_10_CORE ) ) { +#ifdef NONBE_FIX_1402_WAVEADJUST + st->hPlcInfo->subframe_fx = extract_l( L_mult0( frame_cnt, L_frameTCX_glob ) ); +#else st->hPlcInfo->subframe = extract_l( L_mult0( frame_cnt, L_frameTCX_glob ) ); +#endif move16(); } } @@ -4801,11 +4801,11 @@ void decoder_tcx_noiseshaping_igf_fx( /* spectrum concealment */ IF( bfi && EQ_16( *temp_concealment_method, TCX_NONTONAL ) ) { - concealment_decode_fix( st->core, x_fx, x_e, &st->hPlcInfo ); + concealment_decode_fix( st->core, x_fx, x_e, st->hPlcInfo ); } /* update spectrum buffer, tonality flag, etc. */ - concealment_update_x( bfi, st->core, st->tonality_flag, x_fx, x_e, &st->hPlcInfo ); + concealment_update_x( bfi, st->core, st->tonality_flag, x_fx, x_e, st->hPlcInfo ); *x_len = s_max( *x_len, st->hPlcInfo->L_frameTCX ); move16(); diff --git a/lib_dec/er_util_fx.c b/lib_dec/er_util_fx.c index 8c94ecf987e1152e94d8c19b63da37c8bdaee5cf..9735129ec14bc56a1aed50c894ac3cf27a087b6a 100644 --- a/lib_dec/er_util_fx.c +++ b/lib_dec/er_util_fx.c @@ -439,8 +439,6 @@ Word16 GetPLCModeDecision_ivas_fx( test(); test(); test(); - // PMT("handle to tonalMDCTconceal is missing") - //#ifdef ADD_IVAS_HTONALMDCTCONC IF( ( st->hTonalMDCTConc != NULL && EQ_16( st->last_core, TCX_20_CORE ) ) && ( EQ_16( st->second_last_core, TCX_20_CORE ) ) && ( ( LE_32( st->old_fpitch, L_deposit_h( shr( st->L_frame, 1 ) ) ) ) || ( LE_16( hTcxDec->tcxltp_last_gain_unmodified, 13107 /*0.4f Q15*/ ) ) ) /* it is fine to call the detection even if no ltp information is available, meaning that st->old_fpitch == @@ -454,12 +452,8 @@ Word16 GetPLCModeDecision_ivas_fx( { pitch = L_add( st->old_fpitch, 0 ); /*Q16*/ } - // TonalMDCTConceal_Detect_ivas_fx(&st->tonalMDCTconceal, pitch, &numIndices - // , (st->element_mode == IVAS_CPE_MDCT ? &(st->hTcxCfg->psychParamsTCX20) : st->hTcxCfg->psychParamsCurrent) - //); - TonalMDCTConceal_Detect_ivas_fx( st->hTonalMDCTConc, pitch, &numIndices, ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ? &( st->hTcxCfg->psychParamsTCX20 ) : st->hTcxCfg->psychParamsCurrent ), - st->element_mode ); + TonalMDCTConceal_Detect_ivas_fx( st->hTonalMDCTConc, pitch, &numIndices, ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ? &( st->hTcxCfg->psychParamsTCX20 ) : st->hTcxCfg->psychParamsCurrent ), st->element_mode ); test(); test(); @@ -554,6 +548,7 @@ Word16 GetPLCModeDecision_fx( core = st->last_core_bfi; move16(); } + IF( EQ_16( st->nbLostCmpt, 1 ) ) { st->tonal_mdct_plc_active = 0; @@ -569,9 +564,7 @@ Word16 GetPLCModeDecision_fx( test(); test(); test(); - // PMT("handle to tonalMDCTconceal is missing") - //#ifdef ADD_IVAS_HTONALMDCTCONC - IF( ( /*st->ADD_IVAS_HTONALMDCTCONC != NULL &&*/ EQ_16( st->last_core, TCX_20_CORE ) ) && ( EQ_16( st->second_last_core, TCX_20_CORE ) ) && ( ( LE_32( st->old_fpitch, L_deposit_h( shr( st->L_frame, 1 ) ) ) ) || ( LE_16( hTcxDec->tcxltp_last_gain_unmodified, 13107 /*0.4f Q15*/ ) ) ) + IF( ( st->hTonalMDCTConc != NULL && EQ_16( st->last_core, TCX_20_CORE ) ) && ( EQ_16( st->second_last_core, TCX_20_CORE ) ) && ( ( LE_32( st->old_fpitch, L_deposit_h( shr( st->L_frame, 1 ) ) ) ) || ( LE_16( hTcxDec->tcxltp_last_gain_unmodified, 13107 /*0.4f Q15*/ ) ) ) /* it is fine to call the detection even if no ltp information is available, meaning that st->old_fpitch == st->tcxltp_second_last_pitch == st->L_frame */ @@ -585,24 +578,13 @@ Word16 GetPLCModeDecision_fx( { pitch = L_add( st->old_fpitch, 0 ); /*Q16*/ } - IF( st->element_mode == EVS_MONO ) - { - TonalMDCTConceal_Detect( &st->tonalMDCTconceal, pitch, &numIndices, st->element_mode -#ifdef ADD_IVAS_HTONALMDCTCONC - , - ( st->element_mode == IVAS_CPE_MDCT ? &( st->hTcxCfg->psychParamsTCX20 ) : st->hTcxCfg->psychParamsCurrent ) -#endif - ); - } - ELSE - { - TonalMDCTConceal_Detect( st->hTonalMDCTConc, pitch, &numIndices, st->element_mode -#ifdef ADD_IVAS_HTONALMDCTCONC - , - ( st->element_mode == IVAS_CPE_MDCT ? &( st->hTcxCfg->psychParamsTCX20 ) : st->hTcxCfg->psychParamsCurrent ) + + TonalMDCTConceal_Detect( st->hTonalMDCTConc, pitch, &numIndices, st->element_mode +#ifdef IVAS_CODE_MDCT_GSHAPE + , + ( st->element_mode == IVAS_CPE_MDCT ? &( st->hTcxCfg->psychParamsTCX20 ) : st->hTcxCfg->psychParamsCurrent ) #endif - ); - } + ); test(); test(); diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index f46e2934021ea18795a2339d6315b4da968b9148..74340b530f6fe9cc1c2733664b854cc317f057cf 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -16,9 +16,9 @@ *--------------------------------------------------------------------------*/ ivas_error evs_dec_fx( - Decoder_State *st_fx, /* i/o : Decoder state structure */ - Word16 output_sp[], /* o : output synthesis signal Q0*/ - frameMode_fx frameMode /* i : Decoder frame mode */ + Decoder_State *st_fx, /* i/o : Decoder state structure */ + Word16 output_sp[], /* o : output synthesis signal Q0*/ + FRAME_MODE frameMode /* i : Decoder frame mode */ ) { Word16 i, j, output_frame; @@ -53,8 +53,6 @@ ivas_error evs_dec_fx( Word16 Q_synth; Word16 Qpostd_prev; - Word32 *realBuffer[CLDFB_NO_COL_MAX], *imagBuffer[CLDFB_NO_COL_MAX]; - Word32 realBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; Word16 timeIn_e; TD_BWE_DEC_HANDLE hBWE_TD; HQ_DEC_HANDLE hHQ_core; @@ -97,15 +95,6 @@ ivas_error evs_dec_fx( move32(); st_fx->flag_ACELP16k = set_ACELP_flag( EVS_MONO, -1, st_fx->total_brate, 0, 0, -1, -1 ); - 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(); - } if ( st_fx->bfi == 0 ) { st_fx->extl = -1; @@ -154,16 +143,15 @@ ivas_error evs_dec_fx( test(); IF( !st_fx->bfi && st_fx->prev_bfi && ( EQ_16( st_fx->last_codec_mode, MODE2 ) ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) ) { - /* v_multc(st_fx->old_out_fx, st_fx->plcInfo.recovery_gain, */ - /* st_fx->old_out_fx, st_fx->L_frameTCX); */ + /* v_multc(st_fx->old_out_fx, st_fx->hPlcInfo.recovery_gain, st_fx->old_out_fx, st_fx->L_frameTCX); */ FOR( i = 0; i < hTcxDec->L_frameTCX; i++ ) { - hHQ_core->old_out_fx[i] = shl_sat( mult_r( hHQ_core->old_out_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); /*hHQ_core->exp_old_out*/ + hHQ_core->old_out_fx[i] = shl_sat( mult_r( hHQ_core->old_out_fx[i], st_fx->hPlcInfo->recovery_gain ), 1 ); /*hHQ_core->exp_old_out*/ move16(); } FOR( i = 0; i < st_fx->L_frame; i++ ) { - hHQ_core->old_out_LB_fx[i] = shl_sat( mult_r( hHQ_core->old_out_LB_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); /*hHQ_core->exp_old_out*/ + hHQ_core->old_out_LB_fx[i] = shl_sat( mult_r( hHQ_core->old_out_LB_fx[i], st_fx->hPlcInfo->recovery_gain ), 1 ); /*hHQ_core->exp_old_out*/ move16(); } /* attenuate PLC buffers, if no aldo window @@ -278,6 +266,7 @@ ivas_error evs_dec_fx( /*------------------------------------------------------------------* * Decoding *-----------------------------------------------------------------*/ + IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { /*------------------------------------------------------------------* @@ -301,6 +290,7 @@ ivas_error evs_dec_fx( } } } + IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { /*------------------------------------------------------------------* @@ -338,6 +328,7 @@ ivas_error evs_dec_fx( * ACELP core decoding * HQ core decoding *---------------------------------------------------------------------*/ + IF( EQ_16( st_fx->core, ACELP_CORE ) ) { /* ACELP core decoder */ @@ -359,10 +350,11 @@ ivas_error evs_dec_fx( * Postprocessing for ACELP/HQ core switching *---------------------------------------------------------------------*/ - if ( ( error = core_switching_post_dec_fx( st_fx, synth_fx, output_frame, core_switching_flag, st_fx->last_element_mode, &Qpostd ) ) != IVAS_ERR_OK ) + if ( ( error = core_switching_post_dec_fx( st_fx, synth_fx, output_frame, core_switching_flag, EVS_MONO, &Qpostd ) ) != IVAS_ERR_OK ) { return error; } + /*---------------------------------------------------------------------* * Pre-processing for bandwidth switching *---------------------------------------------------------------------*/ @@ -412,9 +404,11 @@ ivas_error evs_dec_fx( test(); IF( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) || ( NE_16( st_fx->coder_type, AUDIO ) && NE_16( st_fx->coder_type, INACTIVE ) && GT_32( st_fx->core_brate, SID_2k40 ) && EQ_16( st_fx->core, ACELP_CORE ) && GE_32( st_fx->output_Fs, 32000 ) && GT_16( st_fx->bwidth, NB ) && st_fx->bws_cnt > 0 && !st_fx->ppp_mode_dec && !( EQ_16( st_fx->nelp_mode_dec, 1 ) && EQ_16( st_fx->bfi, 1 ) ) ) ) { + /* SWB TBE decoder */ swb_tbe_dec_fx( st_fx, st_fx->coder_type, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, old_syn_12k8_16k_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, &hb_synth_fx_exp, pitch_buf_fx ); - /* FB TBE decoder/synthesis */ + + /* FB TBE decoder */ test(); IF( EQ_16( output_frame, L_FRAME48k ) && EQ_16( st_fx->extl, FB_TBE ) ) { @@ -463,6 +457,7 @@ ivas_error evs_dec_fx( /*---------------------------------------------------------------------* * SWB CNG *---------------------------------------------------------------------*/ + IF( GE_16( output_frame, L_FRAME32k ) ) { /* SHB CNG decoder */ @@ -511,7 +506,7 @@ ivas_error evs_dec_fx( test(); test(); test(); - IF( EQ_16( st_fx->core, ACELP_CORE ) && !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && EQ_16( st_fx->last_codec_mode, MODE2 ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) && EQ_16( st_fx->plcInfo.concealment_method, TCX_NONTONAL ) && LT_32( st_fx->plcInfo.nbLostCmpt, 4 ) ) + IF( EQ_16( st_fx->core, ACELP_CORE ) && !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && EQ_16( st_fx->last_codec_mode, MODE2 ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) && EQ_16( st_fx->hPlcInfo->concealment_method, TCX_NONTONAL ) && LT_32( st_fx->hPlcInfo->nbLostCmpt, 4 ) ) { tmps = 0; move16(); @@ -520,20 +515,8 @@ ivas_error evs_dec_fx( tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); /*Q0*/ } - waveform_adj2_fix( st_fx->tonalMDCTconceal.secondLastPcmOut, - synth_fx + tmps, - st_fx->plcInfo.data_noise, - &st_fx->plcInfo.outx_new_n1_fx, - &st_fx->plcInfo.nsapp_gain_fx, - &st_fx->plcInfo.nsapp_gain_n_fx, - &st_fx->plcInfo.recovery_gain, - st_fx->plcInfo.step_concealgain_fx, - st_fx->plcInfo.Pitch_fx, - st_fx->plcInfo.FrameSize, - tmps, - add( extract_l( st_fx->plcInfo.nbLostCmpt ), 1 ), - st_fx->bfi ); - st_fx->plcInfo.Pitch_fx = 0; + waveform_adj2_fix( st_fx->hPlcInfo, st_fx->hTonalMDCTConc->secondLastPcmOut, synth_fx + tmps, tmps, add( extract_l( st_fx->hPlcInfo->nbLostCmpt ), 1 ), st_fx->bfi ); + st_fx->hPlcInfo->Pitch_fx = 0; move16(); } @@ -630,6 +613,7 @@ ivas_error evs_dec_fx( Copy( tmp_buffer_fx, st_fx->hb_prev_synth_buffer_fx, tmps ); /*Q15 - hBWE_TD->prev_hb_synth_fx_exp*/ } + /* Delay hb_synth */ tmp16 = sub( hb_synth_fx_exp, hBWE_TD->prev_hb_synth_fx_exp ); IF( tmp16 != 0 ) @@ -699,7 +683,7 @@ ivas_error evs_dec_fx( fra = Log2_norm_lc( L_shl( L_tmp, exp ) ); exp = sub( sub( 30, shl( hb_synth_fx_exp, 1 ) ), exp ); L_tmp = Mpy_32_16( exp, fra, LG10 ); - st_fx->last_shb_ener_fx = round_fx_sat( L_shl_sat( L_tmp, 10 ) ); /*Q8*/ + st_fx->hTdCngDec->last_shb_ener_fx = round_fx_sat( L_shl_sat( L_tmp, 10 ) ); /*Q8*/ } } hBWE_TD->prev_hb_synth_fx_exp = hb_synth_fx_exp; @@ -709,17 +693,16 @@ ivas_error evs_dec_fx( delta = NS2SA_FX2( st_fx->output_Fs, TCXLTP_DELAY_NS ); /*Q0*/ Scale_sig( hTcxLtpDec->tcxltp_mem_in, delta, sub( Qpostd, Qpostd_prev ) ); /*Qpostd*/ Scale_sig( hTcxLtpDec->tcxltp_mem_out, output_frame, sub( Qpostd, Qpostd_prev ) ); /*Qpostd*/ - tcx_ltp_post( st_fx, hTcxLtpDec, ACELP_CORE, output_frame, 0, synth_fx, NULL ); - + tcx_ltp_post_fx( st_fx, hTcxLtpDec, ACELP_CORE, output_frame, 0, synth_fx, NULL ); /* final output of synthesis signal */ Copy( synth_fx, output_sp, output_frame ); /*Qpostd*/ } - ELSE /* MODE2 PART */ + ELSE /* Mode 2 */ { /* -------------------------------------------------------------- */ - /* CONCEALMENT */ + /* Mode 2 concealment */ /* -------------------------------------------------------------- */ concealWholeFrame = 0; @@ -759,11 +742,10 @@ ivas_error evs_dec_fx( /* -------------------------------------------------------------- */ - /* DECODE CORE */ + /* Decode core */ /* -------------------------------------------------------------- */ - dec_acelp_tcx_frame_fx( st_fx, &concealWholeFrame, output_sp, - st_fx->p_bpf_noise_buf, pcmbufFB, bwe_exc_extended_fx, voice_factors_fx, pitch_buf_fx ); + dec_acelp_tcx_frame_fx( st_fx, &concealWholeFrame, output_sp, st_fx->p_bpf_noise_buf, pcmbufFB, bwe_exc_extended_fx, voice_factors_fx, pitch_buf_fx ); concealWholeFrameTmp = concealWholeFrame; /*Q0*/ move16(); @@ -772,10 +754,10 @@ ivas_error evs_dec_fx( frameMode = FRAMEMODE_MISSING; move32(); } + IF( st_fx->igf ) { - - /* TBE interface */ + /* TBE for Mode 2 interface */ test(); test(); IF( ( st_fx->bfi == 0 || st_fx->last_core == ACELP_CORE ) && st_fx->core == ACELP_CORE ) @@ -881,29 +863,26 @@ ivas_error evs_dec_fx( IF( ( EQ_16( st_fx->bwidth, SWB ) || EQ_16( st_fx->bwidth, FB ) ) && ( ( EQ_16( st_fx->last_extl, SWB_TBE ) || EQ_16( st_fx->last_extl, FB_TBE ) ) && EQ_16( st_fx->last_codec_mode, MODE2 ) ) ) { - GenTransition_fx( hBWE_TD->syn_overlap_fx, hBWE_TD->old_tbe_synth_fx, shl( NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ), 1 ), hb_synth_fx, - hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, - hBWE_TD->mem_resamp_HB_32k_fx, - &( hBWE_TD->syn_dm_phase ), st_fx->output_Fs, hBWE_TD->int_3_over_2_tbemem_dec_fx, st_fx->rf_flag, st_fx->total_brate ); + GenTransition_fx( hBWE_TD, hb_synth_fx, st_fx->output_Fs, st_fx->rf_flag, st_fx->total_brate ); - hb_synth_fx_exp = st_fx->prev_Q_bwe_syn2; + hb_synth_fx_exp = hBWE_TD->prev_Q_bwe_syn2; move16(); } ELSE IF( EQ_16( st_fx->bwidth, WB ) && EQ_16( st_fx->last_extl, WB_TBE ) ) { - GenTransition_WB_fx( hBWE_TD->syn_overlap_fx, hBWE_TD->old_tbe_synth_fx, st_fx->prev_Qx, shl( NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ), 1 ), hb_synth_fx, - hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb_fx, st_fx->output_Fs, hBWE_TD->mem_resamp_HB_fx ); + GenTransition_WB_fx( hBWE_TD, hb_synth_fx, st_fx->output_Fs ); - hb_synth_fx_exp = st_fx->prev_Qx; + hb_synth_fx_exp = hBWE_TD->prev_Qx; move16(); } - TBEreset_dec_fx( st_fx, st_fx->bwidth ); + TBEreset_dec_fx( st_fx ); } ELSE IF( EQ_16( st_fx->last_codec_mode, MODE1 ) ) { swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) ); + IF( EQ_16( st_fx->extl, FB_TBE ) ) { set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); @@ -911,7 +890,8 @@ ivas_error evs_dec_fx( move16(); fb_tbe_reset_synth_fx( hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q, &hBWE_TD->prev_fbbwe_ratio_fx ); } - swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); + + swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32 ); } } } @@ -925,10 +905,23 @@ ivas_error evs_dec_fx( } /* -------------------------------------------------------------- */ - /* APPLY POSTPROC */ + /* Postprocessing */ /* -------------------------------------------------------------- */ { + Word32 *realBuffer[CLDFB_NO_COL_MAX], *imagBuffer[CLDFB_NO_COL_MAX]; + Word32 realBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + + 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(); + } + nab = s_min( st_fx->cldfbAna->no_channels, st_fx->cldfbSyn->no_channels ); /*Q0*/ st_fx->cldfbSyn->lsb = s_min( st_fx->cldfbAna->no_channels, st_fx->cldfbSyn->no_channels ); /*Q0*/ st_fx->cldfbSyn->usb = st_fx->cldfbSyn->no_channels; /*Q0*/ @@ -944,11 +937,12 @@ ivas_error evs_dec_fx( test(); IF( st_fx->hFdCngDec != NULL && ( EQ_32( st_fx->sr_core, 8000 ) || EQ_32( st_fx->sr_core, INT_FS_12k8 ) || EQ_32( st_fx->sr_core, INT_FS_16k ) ) && LE_32( st_fx->total_brate, ACELP_32k ) ) { - /*************************************** - In CLDFB domain: - - perform noise estimation during active frames - - do CNG during inactive frames - ****************************************/ + /* -------------------------------------------------------------- * + * In CLDFB domain: + * - perform noise estimation during active frames + * - do CNG during inactive frames + * -------------------------------------------------------------- */ + HANDLE_FD_CNG_DEC hFdCngDec = st_fx->hFdCngDec; noisy_speech_detection_fx( st_fx->hFdCngDec, st_fx->VAD && EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ), output_sp, 0 ); @@ -996,7 +990,7 @@ ivas_error evs_dec_fx( } Scale_sig( output_sp, st_fx->L_frame, timeIn_e ); /*timeIn_e*/ timeIn_e = negate( timeIn_e ); - cldfbAnalysisFiltering( st_fx->cldfbAna, realBuffer, imagBuffer, &st_fx->scaleFactor, output_sp, timeIn_e, CLDFB_NO_COL_MAX, workBuffer ); + cldfbAnalysis_fx( st_fx->cldfbAna, realBuffer, imagBuffer, &st_fx->scaleFactor, output_sp, timeIn_e, CLDFB_NO_COL_MAX, workBuffer ); st_fx->scaleFactor.hb_scale = st_fx->scaleFactor.lb_scale; move16(); } @@ -1009,6 +1003,7 @@ ivas_error evs_dec_fx( Copy( st_fx->hFdCngDec->hFdCngCom->A_cng, A, M + 1 ); /*Q12*/ update_decoder_LPD_cng( st_fx, st_fx->coder_type, timeDomainBuffer, A, st_fx->p_bpf_noise_buf ); + /* Generate additional comfort noise to mask potential coding artefacts */ test(); test(); @@ -1027,6 +1022,7 @@ ivas_error evs_dec_fx( move16(); } } + /* check if the CLDFB works on the right sample rate */ IF( NE_16( i_mult( st_fx->cldfbAna->no_channels, st_fx->cldfbAna->no_col ), st_fx->L_frame ) ) { @@ -1057,7 +1053,7 @@ ivas_error evs_dec_fx( } timeIn_e = negate( timeIn_e ); - cldfbAnalysisFiltering( st_fx->cldfbAna, realBuffer, imagBuffer, &st_fx->scaleFactor, timeDomainBuffer, timeIn_e, CLDFB_NO_COL_MAX, workBuffer ); + cldfbAnalysis_fx( st_fx->cldfbAna, realBuffer, imagBuffer, &st_fx->scaleFactor, timeDomainBuffer, timeIn_e, CLDFB_NO_COL_MAX, workBuffer ); } IF( st_fx->flag_cna == 0 ) @@ -1107,8 +1103,7 @@ ivas_error evs_dec_fx( } timeIn_e = s_min( 0, add( timeIn_e, 2 ) ); - cldfbSynthesisFiltering( st_fx->cldfbSyn, realBuffer, imagBuffer, &st_fx->scaleFactor, output_sp, timeIn_e, CLDFB_NO_COL_MAX, workBuffer ); - /*CLDFB output always in timeIn_e*/ + cldfbSynthesis_fx( st_fx->cldfbSyn, realBuffer, imagBuffer, &st_fx->scaleFactor, output_sp, timeIn_e, CLDFB_NO_COL_MAX, workBuffer ); /*CLDFB output always in timeIn_e*/ /* MODE1 MDCT to ACELP 2 transition */ delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); @@ -1232,11 +1227,11 @@ ivas_error evs_dec_fx( ( ( EQ_16( st_fx->last_core, ACELP_CORE ) ) && ( NE_16( st_fx->bwidth, NB ) && EQ_16( st_fx->last_codec_mode, MODE2 ) ) ) ) && ( GT_32( st_fx->output_Fs, 8000 ) ) ) { + /* Add the delayed hb_synth component to the delayed core synthesis */ add_vec_fx( output_sp, negate( timeIn_e ), hb_synth_fx, hb_synth_fx_exp, output_sp, negate( timeIn_e ), output_frame ); } } - IF( EQ_32( st_fx->output_Fs, 8000 ) ) { tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); /*Q0*/ @@ -1250,19 +1245,23 @@ ivas_error evs_dec_fx( test(); test(); test(); + /* TCX/ACELP/HQ-CORE->TCX */ IF( ( st_fx->bfi && GT_16( st_fx->last_core, ACELP_CORE ) ) || GT_16( st_fx->core, ACELP_CORE ) ) { test(); test(); test(); test(); + /* TCX / HQ-CORE / TD-TCX-PLC -> TCX / TD-TCX-PLC */ IF( GT_16( st_fx->last_core_bfi, ACELP_CORE ) || ( st_fx->bfi && st_fx->last_core > ACELP_CORE ) || ( st_fx->prev_bfi && st_fx->last_con_tcx ) ) { Copy_Scale_sig( hTcxDec->FBTCXdelayBuf, output_sp, tmps, negate( timeIn_e ) ); /*Q0*/ Copy_Scale_sig( pcmbufFB, output_sp + tmps, sub( hTcxDec->L_frameTCX, tmps ), negate( timeIn_e ) ); /*Q0*/ } + /* ACELP -> TCX */ ELSE { + /*cross-fading between LB-TCX and FB-TCX over 2.3125ms*/ Word16 step, alpha; i = 15; @@ -1297,6 +1296,7 @@ ivas_error evs_dec_fx( } } } + /* TCX/TD TCX PLC->ACELP */ ELSE IF( ( EQ_16( st_fx->last_codec_mode, MODE2 ) ) && ( GT_16( st_fx->last_core, ACELP_CORE ) ) ) { Word16 step, alpha; @@ -1323,11 +1323,10 @@ ivas_error evs_dec_fx( Scale_sig( output_sp, output_frame, timeIn_e ); /*timeIn_e*/ - tcx_ltp_post( st_fx, hTcxLtpDec, st_fx->core, output_frame /*hTcxDec->L_frameTCX*/, add( NS2SA_FX2( st_fx->output_Fs, ACELP_LOOK_NS ), tmps ), - output_sp, hTcxDec->FBTCXdelayBuf ); + tcx_ltp_post_fx( st_fx, hTcxLtpDec, st_fx->core, output_frame /*hTcxDec->L_frameTCX*/, add( NS2SA_FX2( st_fx->output_Fs, ACELP_LOOK_NS ), tmps ), output_sp, hTcxDec->FBTCXdelayBuf ); Copy( output_sp, synth_fx, output_frame ); /*timeIn_e*/ - } /* end of MODE2 */ + } /* end of Mode 2 */ /*----------------------------------------------------------------* diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index 86cf9784aa1eb3346aa7c52a16d78f7e2808f40e..714245514e4e3987f3e51f53e8e8aa2a4ca99834 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -490,30 +490,18 @@ void hq_core_dec_fx( test(); test(); test(); - IF( !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && EQ_16( st_fx->last_codec_mode, MODE2 ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) && st_fx->plcInfo.concealment_method == TCX_NONTONAL && LT_32( st_fx->plcInfo.nbLostCmpt, 4 ) ) + IF( !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && EQ_16( st_fx->last_codec_mode, MODE2 ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) && st_fx->hPlcInfo->concealment_method == TCX_NONTONAL && LT_32( st_fx->hPlcInfo->nbLostCmpt, 4 ) ) { - st_fx->plcInfo.recovery_gain = shl_sat( st_fx->plcInfo.recovery_gain, *Q_synth ); /* Q14 + Q_synth */ + st_fx->hPlcInfo->recovery_gain = shl_sat( st_fx->hPlcInfo->recovery_gain, *Q_synth ); /* Q14 + Q_synth */ move16(); - IF( st_fx->tonalMDCTconceal.q_lastPcmOut != 0 ) + IF( st_fx->hTonalMDCTConc->q_lastPcmOut != 0 ) { - Scale_sig( st_fx->tonalMDCTconceal.secondLastPcmOut, shr( st_fx->plcInfo.FrameSize, 1 ), negate( st_fx->tonalMDCTconceal.q_lastPcmOut ) ); - Scale_sig( st_fx->tonalMDCTconceal.lastPcmOut, st_fx->plcInfo.FrameSize, negate( st_fx->tonalMDCTconceal.q_lastPcmOut ) ); - st_fx->tonalMDCTconceal.q_lastPcmOut = 0; + Scale_sig( st_fx->hTonalMDCTConc->secondLastPcmOut, shr( st_fx->hPlcInfo->L_frameTCX, 1 ), negate( st_fx->hTonalMDCTConc->q_lastPcmOut ) ); + Scale_sig( st_fx->hTonalMDCTConc->lastPcmOut, st_fx->hPlcInfo->L_frameTCX, negate( st_fx->hTonalMDCTConc->q_lastPcmOut ) ); + st_fx->hTonalMDCTConc->q_lastPcmOut = 0; move16(); } - waveform_adj2_fix( st_fx->tonalMDCTconceal.secondLastPcmOut, - synth, - st_fx->plcInfo.data_noise, - &st_fx->plcInfo.outx_new_n1_fx, - &st_fx->plcInfo.nsapp_gain_fx, - &st_fx->plcInfo.nsapp_gain_n_fx, - &st_fx->plcInfo.recovery_gain, - st_fx->plcInfo.step_concealgain_fx, - st_fx->plcInfo.Pitch_fx, - st_fx->plcInfo.FrameSize, - 0, - add( extract_l( st_fx->plcInfo.nbLostCmpt ), 1 ), - st_fx->bfi ); + waveform_adj2_fix( st_fx->hPlcInfo, st_fx->hTonalMDCTConc->secondLastPcmOut, synth, 0, add( extract_l( st_fx->hPlcInfo->nbLostCmpt ), 1 ), st_fx->bfi ); } IF( GE_16( output_frame, L_FRAME16k ) ) @@ -1122,30 +1110,18 @@ void ivas_hq_core_dec_fx( test(); test(); test(); - IF( !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && EQ_16( st_fx->last_codec_mode, MODE2 ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) && EQ_16( st_fx->plcInfo.concealment_method, TCX_NONTONAL ) && LT_32( st_fx->plcInfo.nbLostCmpt, 4 ) ) + IF( !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && EQ_16( st_fx->last_codec_mode, MODE2 ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) && EQ_16( st_fx->hPlcInfo->concealment_method, TCX_NONTONAL ) && LT_32( st_fx->hPlcInfo->nbLostCmpt, 4 ) ) { - st_fx->plcInfo.recovery_gain = shl_sat( st_fx->plcInfo.recovery_gain, *Q_synth ); /* Q15 */ + st_fx->hPlcInfo->recovery_gain = shl_sat( st_fx->hPlcInfo->recovery_gain, *Q_synth ); /* Q15 */ move16(); - IF( st_fx->tonalMDCTconceal.q_lastPcmOut != 0 ) + IF( st_fx->hTonalMDCTConc->q_lastPcmOut != 0 ) { - Scale_sig( st_fx->tonalMDCTconceal.secondLastPcmOut, shr( st_fx->plcInfo.FrameSize, 1 ), negate( st_fx->tonalMDCTconceal.q_lastPcmOut ) ); - Scale_sig( st_fx->tonalMDCTconceal.lastPcmOut, st_fx->plcInfo.FrameSize, negate( st_fx->tonalMDCTconceal.q_lastPcmOut ) ); - st_fx->tonalMDCTconceal.q_lastPcmOut = 0; + Scale_sig( st_fx->hTonalMDCTConc->secondLastPcmOut, shr( st_fx->hPlcInfo->L_frameTCX, 1 ), negate( st_fx->hTonalMDCTConc->q_lastPcmOut ) ); + Scale_sig( st_fx->hTonalMDCTConc->lastPcmOut, st_fx->hPlcInfo->L_frameTCX, negate( st_fx->hTonalMDCTConc->q_lastPcmOut ) ); + st_fx->hTonalMDCTConc->q_lastPcmOut = 0; move16(); } - waveform_adj2_fix( st_fx->tonalMDCTconceal.secondLastPcmOut, - synth, - st_fx->plcInfo.data_noise, - &st_fx->plcInfo.outx_new_n1_fx, - &st_fx->plcInfo.nsapp_gain_fx, - &st_fx->plcInfo.nsapp_gain_n_fx, - &st_fx->plcInfo.recovery_gain, - st_fx->plcInfo.step_concealgain_fx, - st_fx->plcInfo.Pitch_fx, - st_fx->plcInfo.FrameSize, - 0, - add( extract_l( st_fx->plcInfo.nbLostCmpt ), 1 ), - st_fx->bfi ); + waveform_adj2_fix( st_fx->hPlcInfo, st_fx->hTonalMDCTConc->secondLastPcmOut, synth, 0, add( extract_l( st_fx->hPlcInfo->nbLostCmpt ), 1 ), st_fx->bfi ); } IF( GE_16( output_frame, L_FRAME16k ) ) @@ -1225,17 +1201,15 @@ void HQ_core_dec_init_fx( ) { set16_fx( hHQ_core->old_out_fx, 0, L_FRAME48k ); + set32_fx( hHQ_core->old_out_fx32, 0, L_FRAME48k ); set16_fx( hHQ_core->old_out_LB_fx, 0, L_FRAME32k ); - set32_fx( hHQ_core->oldOut_fx, 0, L_FRAME48k ); - set32_fx( hHQ_core->old_outLB_fx, 0, L_FRAME32k ); + set32_fx( hHQ_core->old_out_LB_fx32, 0, L_FRAME32k ); hHQ_core->Q_old_wtda = 15; hHQ_core->Q_old_postdec = 0; hHQ_core->Q_old_wtda_LB = 0; move16(); move16(); move16(); - move16(); - move16(); hHQ_core->last_hq_core_type = -1; /* Q0 */ move16(); diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index f96b8f59787008b5a1eb5bee0f584f417e4563c6..d72f0ec452223ac8c1d4ae9b65ea060f164b043a 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -61,7 +61,7 @@ void ivas_hq_pred_hb_bws_fx( IF( GE_16( st_fx->last_inner_frame, L_FRAME32k ) && st_fx->hBWE_FD != NULL ) { - set16_fx( st_fx->prev_SWB_fenv_fx, st_fx->prev_ener_shb_fx, SWB_FENV ); + set16_fx( st_fx->hBWE_FD->prev_SWB_fenv_fx, st_fx->prev_ener_shb_fx, SWB_FENV ); } return; @@ -125,7 +125,7 @@ void hq_pred_hb_bws_fx( IF( GE_16( st_fx->last_inner_frame, L_FRAME32k ) ) { - set16_fx( st_fx->prev_SWB_fenv_fx, st_fx->prev_ener_shb_fx, SWB_FENV ); + set16_fx( st_fx->hBWE_FD->prev_SWB_fenv_fx, st_fx->prev_ener_shb_fx, SWB_FENV ); } return; diff --git a/lib_dec/hq_lr_dec_fx.c b/lib_dec/hq_lr_dec_fx.c index 61c1d0938eef3222ee6e0366fbdcb2f284aa9f85..7d5d6a34b907255f65e9d83ee0e0224c686ba7aa 100644 --- a/lib_dec/hq_lr_dec_fx.c +++ b/lib_dec/hq_lr_dec_fx.c @@ -893,7 +893,7 @@ void hq_lr_dec_fx( test(); IF( GE_16( st_fx->last_inner_frame, L_FRAME32k ) && st_fx->hBWE_FD != NULL ) { - set16_fx( st_fx->prev_SWB_fenv_fx, st_fx->prev_ener_shb_fx, SWB_FENV ); + set16_fx( st_fx->hBWE_FD->prev_SWB_fenv_fx, st_fx->prev_ener_shb_fx, SWB_FENV ); } updat_prev_frm_fx( L_y2, L_yout, L_bwe_br, length_fx, inner_frame, bands_fx, st_fx->bwidth, *is_transient_fx, hqswb_clas_fx, &hHQ_core->prev_hqswb_clas, diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index bd8a2cbd3095c210f6ffa49344a60f66b826c58c..934433132a702fb29af374d0d171bda50ca6c123 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -126,7 +126,7 @@ ivas_error init_decoder_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n" ) ); } - fd_bwe_dec_init( st_fx, st_fx->hBWE_FD ); + fd_bwe_dec_init_fx( st_fx->hBWE_FD ); } ELSE { @@ -193,7 +193,6 @@ ivas_error init_decoder_fx( st_fx->last_voice_factor_fx = 0; // Q6 move16(); - set16_fx( st_fx->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB ); test(); test(); @@ -358,23 +357,9 @@ ivas_error init_decoder_fx( } st_fx->cng_type = -1; move16(); - st_fx->CNG_fx = 0; - move16(); /* RTXDTX handler CNG=1 nonCNG= 0,*/ - st_fx->prev_ft_speech_fx = 1; - move16(); /* RXDTX handeler previous frametype flag for G.192 format AMRWB SID_FIRST detection */ st_fx->first_CNG = 0; move16(); Copy( st_fx->lsp_old_fx, st_fx->lspCNG_fx, M ); // Q15 - st_fx->shb_cng_ener_fx = -1541; // Q8 - move16(); - st_fx->wb_cng_ener_fx = -1541; // Q8 - move16(); - st_fx->last_wb_cng_ener_fx = -1541; // Q8 - move16(); - st_fx->last_shb_cng_ener_fx = -1541; // Q8 - move16(); - st_fx->swb_cng_seed = RANDOM_INITSEED; - move16(); st_fx->CNG_mode = -1; move16(); @@ -383,22 +368,9 @@ ivas_error init_decoder_fx( st_fx->last_CNG_L_frame = L_FRAME; move16(); - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - st_fx->lsp_shb_prev_fx[i] = lsp_shb_prev_tbl_fx[i]; // Q15 - move16(); - st_fx->lsp_shb_prev_prev_fx[i] = st_fx->lsp_shb_prev_fx[i]; // Q15 - move16(); - } - st_fx->shb_dtx_count_fx = 0; - move16(); st_fx->last_vad_fx = 0; move16(); - st_fx->trans_cnt_fx = 0; - move16(); - st_fx->last_shb_ener_fx = 0; // Q8 - move16(); /* HF (6-7kHz) BWE */ move16(); @@ -507,6 +479,14 @@ ivas_error init_decoder_fx( { st_fx->hTcxCfg = NULL; } + + /* Tonal MDCT concealment data structure */ + + if ( ( st_fx->hTonalMDCTConc = (TonalMDCTConcealPtr) malloc( sizeof( TonalMDCTConceal_INSTANCE ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TonalMDCTConcealment\n" ) ); + } + st_fx->prev_coder_type = GENERIC; move16(); @@ -531,12 +511,10 @@ ivas_error init_decoder_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); } - td_bwe_dec_init_fx( st_fx, st_fx->hBWE_TD, st_fx->output_Fs ); + td_bwe_dec_init_fx( st_fx->hBWE_TD, st_fx->extl, st_fx->output_Fs ); -#ifdef MSAN_FIX - st_fx->hBWE_TD->prev_hb_synth_fx_exp = 31; + st_fx->prev_Q_bwe_exc = 31; move16(); -#endif } ELSE { @@ -748,6 +726,14 @@ ivas_error init_decoder_fx( st_fx->last_vbr_hw_BWE_disable_dec = 0; move16(); + /*-----------------------------------------------------------------* + * Mode 2 initialization + *-----------------------------------------------------------------*/ + + IF( ( st_fx->hPlcInfo = (T_PLCInfo_HANDLE) malloc( sizeof( T_PLCInfo ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PLC handle\n" ) ); + } st_fx->enablePlcWaveadjust = 0; move16(); @@ -827,8 +813,6 @@ ivas_error init_decoder_fx( move16(); st_fx->element_mode = EVS_MONO; /* element mode */ move16(); - st_fx->last_element_mode = st_fx->element_mode; /* element mode */ - move16(); st_fx->element_brate = -1; /* element bitrate */ move16(); st_fx->low_rate_mode = 0; /* low-rate mode flag */ @@ -1210,7 +1194,7 @@ ivas_error init_decoder_ivas_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); } - td_cng_dec_init_ivas_fx( st_fx ); + td_cng_dec_init_fx( st_fx ); } ELSE { @@ -1286,11 +1270,10 @@ ivas_error init_decoder_ivas_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); } - td_bwe_dec_init_ivas_fx( st_fx, st_fx->hBWE_TD, st_fx->output_Fs ); -#ifdef MSAN_FIX - st_fx->hBWE_TD->prev_hb_synth_fx_exp = 31; + td_bwe_dec_init_fx( st_fx->hBWE_TD, st_fx->extl, st_fx->output_Fs ); + + st_fx->prev_Q_bwe_exc = 31; move16(); -#endif } ELSE { @@ -1312,7 +1295,7 @@ ivas_error init_decoder_ivas_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n" ) ); } - fd_bwe_dec_init( st_fx, st_fx->hBWE_FD ); + fd_bwe_dec_init_fx( st_fx->hBWE_FD ); } ELSE { diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index 180e582f1b57f99a8de01946bc3dd14c35f9aa39..37c32a8b1b48043bd560da49d386c2a3321ff54f 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -48,6 +48,7 @@ * * Principal IVAS core decoder routine, where number of core channels is 1 or 2 *-------------------------------------------------------------------*/ + ivas_error ivas_core_dec_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ SCE_DEC_HANDLE hSCE, /* i/o: SCE decoder structure */ @@ -64,15 +65,13 @@ ivas_error ivas_core_dec_fx( Decoder_State **sts, *st; STEREO_ICBWE_DEC_HANDLE hStereoICBWE; STEREO_TD_DEC_DATA_HANDLE hStereoTD; + STEREO_CNG_DEC_HANDLE hStereoCng; + TD_BWE_DEC_HANDLE hBWE_TD; + FD_BWE_DEC_HANDLE hBWE_FD; Word16 sharpFlag[CPE_CHANNELS]; Word16 tmp_buffer_fx[L_FRAME48k]; - set16_fx( tmp_buffer_fx, 0, L_FRAME48k ); Word16 tmp16, tmp16_2, j; - tmp16 = 0; - move16(); Word16 Q_white_exc; - Q_white_exc = 0; - move16(); Word16 tmps, incr; Word32 bwe_exc_extended_fx[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; @@ -109,15 +108,8 @@ ivas_error ivas_core_dec_fx( move16(); move16(); - FOR( i = 0; i < CPE_CHANNELS; i++ ) - { - set16_fx( pitch_buf_fx[i], 0, NB_SUBFR16k ); - set16_fx( output_16_fx[i], 0, L_FRAME48k ); - } - Word16 tdm_lsfQ_PCh_fx[M], tdm_lspQ_PCh_fx[M]; Word32 conceal_eof_gain32; - Flag Overflow; error = IVAS_ERR_OK; @@ -146,9 +138,11 @@ ivas_error ivas_core_dec_fx( last_element_mode = IVAS_SCE; move16(); hStereoTD = NULL; + hStereoCng = NULL; p_output_mem_fx = NULL; nchan_out = 1; move16(); + test(); IF( st_ivas != NULL && EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) { @@ -170,8 +164,8 @@ ivas_error ivas_core_dec_fx( move16(); hStereoICBWE = hCPE->hStereoICBWE; hStereoTD = hCPE->hStereoTD; + hStereoCng = hCPE->hStereoCng; p_output_mem_fx = hCPE->output_mem_fx[1]; - nchan_out = hCPE->nchan_out; move16(); @@ -181,19 +175,12 @@ ivas_error ivas_core_dec_fx( move16(); } - IF( EQ_16( sts[0]->element_mode, IVAS_CPE_DFT ) ) + test(); + test(); + IF( EQ_16( sts[0]->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) { - test(); - IF( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) - { - use_cldfb_for_dft = 1; - move16(); - } - ELSE - { - use_cldfb_for_dft = 0; - move16(); - } + use_cldfb_for_dft = 1; + move16(); } } @@ -283,10 +270,8 @@ ivas_error ivas_core_dec_fx( IF( !st->bfi && st->prev_bfi && ( EQ_16( st->last_core_bfi, TCX_20_CORE ) || EQ_16( st->last_core_bfi, TCX_10_CORE ) ) && st->hTcxDec != NULL ) #endif { - conceal_eof_gain32 = L_shr_sat( st->hTcxDec->conceal_eof_gain32, sub( 16, st->hTcxDec->conceal_eof_gain_e ) ); // e = 31 - Q , 16 - e => 16 - (31 - Q) => Q - 15, // shr(16 -e ) = shr(Q -15) => 15 - Q ==> Q15 - FOR( i = 0; i < st->hTcxDec->L_frameTCX; i++ ) { L_tmp = Mpy_32_16_1( conceal_eof_gain32, st->hHQ_core->old_out_fx[i] ); // Q0 (15+1+0 - (15 + 1) @@ -309,6 +294,7 @@ ivas_error ivas_core_dec_fx( set16_fx( voice_factors_fx[n], 0, NB_SUBFR16k ); set32_fx( hb_synth_32_fx[n], 0, L_FRAME48k ); set16_fx( hb_synth_16_fx[n], 0, L_FRAME48k ); + /*------------------------------------------------------------------* * Decision matrix (selection of technologies) *-----------------------------------------------------------------*/ @@ -345,19 +331,18 @@ ivas_error ivas_core_dec_fx( /* MDCT stereo -> DFT stereo switching */ test(); - test(); - IF( hCPE != NULL && EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) + IF( EQ_16( last_element_mode, IVAS_CPE_MDCT ) && EQ_16( sts[0]->element_mode, IVAS_CPE_DFT ) ) { Word16 ovl, fade_len; IF( NE_16( sts[0]->L_frame, sts[0]->last_L_frame ) ) { #ifdef FIX_ISSUE_1237 - Copy_Scale_sig_16_32_no_sat( sts[0]->hHQ_core->old_out_LB_fx, sts[0]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, sts[0]->hHQ_core->Q_old_wtda_LB ) ); // Q11 + Copy_Scale_sig_16_32_no_sat( sts[0]->hHQ_core->old_out_LB_fx, sts[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k, sub( Q11, sts[0]->hHQ_core->Q_old_wtda_LB ) ); // Q11 #else - Copy_Scale_sig_16_32_DEPREC( sts[0]->hHQ_core->old_out_LB_fx, sts[0]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, sts[0]->hHQ_core->Q_old_wtda_LB ) ); // Q11 + Copy_Scale_sig_16_32_DEPREC( sts[0]->hHQ_core->old_out_LB_fx, sts[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k, sub( Q11, sts[0]->hHQ_core->Q_old_wtda_LB ) ); // Q11 #endif - L_lerp_fx_q11( sts[0]->hHQ_core->old_outLB_fx, sts[0]->hHQ_core->old_outLB_fx, sts[0]->L_frame, sts[0]->last_L_frame ); - Copy_Scale_sig_32_16( sts[0]->hHQ_core->old_outLB_fx, sts[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( sts[0]->hHQ_core->Q_old_wtda_LB, Q11 ) ); // Q_old_wtda_LB + L_lerp_fx_q11( sts[0]->hHQ_core->old_out_LB_fx32, sts[0]->hHQ_core->old_out_LB_fx32, sts[0]->L_frame, sts[0]->last_L_frame ); + Copy_Scale_sig_32_16( sts[0]->hHQ_core->old_out_LB_fx32, sts[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( sts[0]->hHQ_core->Q_old_wtda_LB, Q11 ) ); // Q_old_wtda_LB } IF( NE_16( sts[0]->L_frame, L_FRAME16k ) ) { @@ -370,9 +355,9 @@ ivas_error ivas_core_dec_fx( } test(); - if ( hCPE != NULL && hCPE->hStereoCng != NULL ) + if ( hStereoCng != NULL ) { - hCPE->hStereoCng->flag_cna_fade = 0; + hStereoCng->flag_cna_fade = 0; move16(); } @@ -413,7 +398,7 @@ ivas_error ivas_core_dec_fx( test(); IF( hCPE != NULL && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && hCPE->brate_surplus > 0 ) { - ivas_combined_format_brate_sanity_fx( hCPE->element_brate, sts[0]->core, sts[0]->total_brate, &( sts[0]->core_brate ), &( sts[0]->inactive_coder_type_flag ), &tmps ); + ivas_combined_format_brate_sanity_fx( element_brate, sts[0]->core, sts[0]->total_brate, &( sts[0]->core_brate ), &( sts[0]->inactive_coder_type_flag ), &tmps ); } /*------------------------------------------------------------------* @@ -467,6 +452,7 @@ ivas_error ivas_core_dec_fx( /*---------------------------------------------------------------------* * Preprocessing (preparing) for ACELP/HQ core switching *---------------------------------------------------------------------*/ + Word16 Q_olapBufferSynth, Q_olapBufferSynth2; Q_olapBufferSynth = Q15; /*Initializing with max values to avoid warnings*/ @@ -495,12 +481,14 @@ ivas_error ivas_core_dec_fx( * HQ core decoding *---------------------------------------------------------------------*/ + set16_fx( output_16_fx[n], 0, L_FRAME48k ); /* this is needed for instances like L_norm_arr( p_output_fx[i], L_FRAME48k ) */ + IF( st->core == ACELP_CORE ) { /* ACELP core decoder */ Word16 old_syn_12k8_16k_fx_16[L_FRAME16k]; - set16_fx( output_16_fx[n], 0, L_FRAME48k ); Word16 save_hb_synth_fx_arr[L_FRAME48k], *save_hb_synth_16_fx; + IF( save_hb_synth_32_fx ) { save_hb_synth_16_fx = save_hb_synth_fx_arr; @@ -534,24 +522,15 @@ 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( hCPE == NULL ) + 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_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, NULL, read_sid_info ) ), IVAS_ERR_OK ) ) - { - return error; - } - } - ELSE - { - 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, hCPE->hStereoCng, read_sid_info ) ), IVAS_ERR_OK ) ) - { - return error; - } + return error; } + #ifdef FIX_ISSUE_1237 Copy_Scale_sig_16_32_no_sat( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, st->Q_syn2 ) ); // Q_syn2->Q11 #else - Copy_Scale_sig_16_32_DEPREC( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, st->Q_syn2 ) ); // Q_syn2->Q11 + Copy_Scale_sig_16_32_DEPREC( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, st->Q_syn2 ) ); // Q_syn2->Q11 #endif Scale_sig( output_16_fx[n], L_FRAME48k, negate( st->Q_syn2 ) ); // Q0 IF( st->cldfbAna ) @@ -594,7 +573,6 @@ ivas_error ivas_core_dec_fx( IF( ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { Word16 Qsyn_temp; - STEREO_CNG_DEC_HANDLE hStereoCng; IVAS_FORMAT ivas_format; Qsyn_temp = st->Q_syn; @@ -620,14 +598,6 @@ ivas_error ivas_core_dec_fx( st->hHQ_core->Q_old_wtda = 0; move16(); - IF( hCPE == NULL ) - { - hStereoCng = NULL; - } - ELSE - { - hStereoCng = hCPE->hStereoCng; - } IF( st_ivas == NULL ) { ivas_format = 0; @@ -638,7 +608,9 @@ ivas_error ivas_core_dec_fx( ivas_format = st_ivas->ivas_format; move32(); } + stereo_tcx_core_dec_fx( st, frameMode[n], output_16_fx[n], synth_16_fx[n], pitch_buf_fx[n], sba_dirac_stereo_flag, hStereoTD, last_element_mode, flag_sec_CNA, hStereoCng, nchan_out, ivas_format ); + st->hHQ_core->Q_old_wtda_LB = st->hHQ_core->Q_old_wtda; move16(); Copy_Scale_sig_16_32_DEPREC( output_16_fx[n], output_32_fx[n], L_FRAME48k, Q11 ); // Q11 @@ -738,6 +710,7 @@ ivas_error ivas_core_dec_fx( move16(); move16(); sts = hCPE->hCoreCoder; + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { st = sts[ch]; @@ -781,19 +754,21 @@ ivas_error ivas_core_dec_fx( ELSE IF( EQ_16( hCPE->nchan_out, 1 ) ) { Word16 shift1, shift2; + sts[0] = hCPE->hCoreCoder[0]; sts[1] = hCPE->hCoreCoder[1]; - IF( LE_32( hCPE->last_element_brate, IVAS_SID_5k2 ) ) + IF( LE_32( last_element_brate, IVAS_SID_5k2 ) ) { sts[0]->hHQ_core->exp_old_out = sub( 15, sts[0]->hHQ_core->Q_old_wtda ); move16(); sts[1]->hHQ_core->exp_old_out = sub( 15, sts[1]->hHQ_core->Q_old_wtda ); move16(); } + updateBuffersForDmxMdctStereo_fx( hCPE, output_frame, output_32_fx[0], output_32_fx[1], synth_16_fx ); - IF( LE_32( hCPE->last_element_brate, IVAS_SID_5k2 ) ) + IF( LE_32( last_element_brate, IVAS_SID_5k2 ) ) { sts[0]->hHQ_core->Q_old_wtda = sub( 15, sts[0]->hHQ_core->exp_old_out ); move16(); @@ -836,7 +811,7 @@ ivas_error ivas_core_dec_fx( *---------------------------------------------------------------------*/ test(); - IF( EQ_16( sts[0]->element_mode, IVAS_CPE_TD ) && hCPE->hStereoCng != NULL ) + IF( EQ_16( sts[0]->element_mode, IVAS_CPE_TD ) && hStereoCng != NULL ) { /* To be cleaned up once the caller function is converted // These changes are for system testing of fixed changes made */ Word16 Q_c_PS_LT, Q_output; @@ -846,13 +821,13 @@ ivas_error ivas_core_dec_fx( move16(); Q_output = 11; move16(); - c_PS_LT_fx = L_deposit_h( hCPE->hStereoCng->c_PS_LT_fx ); + c_PS_LT_fx = L_deposit_h( hStereoCng->c_PS_LT_fx ); Q_c_PS_LT = Q31; move16(); stereo_cng_compute_PScorr_fx( output_32_fx[0], output_32_fx[1], &Q_output, &c_PS_LT_fx, Q_c_PS_LT, sts[0]->L_frame, sts[1]->L_frame ); - hCPE->hStereoCng->c_PS_LT_fx = extract_h( c_PS_LT_fx ); + hStereoCng->c_PS_LT_fx = extract_h( c_PS_LT_fx ); } /*---------------------------------------------------------------------* @@ -862,6 +837,8 @@ ivas_error ivas_core_dec_fx( FOR( n = 0; n < n_channels; n++ ) { st = sts[n]; + hBWE_TD = st->hBWE_TD; + hBWE_FD = st->hBWE_FD; /*---------------------------------------------------------------------* * TD-BWE for ACELP to TCX transitions @@ -907,7 +884,7 @@ ivas_error ivas_core_dec_fx( test(); test(); test(); - IF( ( st->last_core == ACELP_CORE ) && ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) && st->hBWE_TD != NULL ) + IF( ( st->last_core == ACELP_CORE ) && ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) && hBWE_TD != NULL ) { test(); test(); @@ -915,39 +892,40 @@ ivas_error ivas_core_dec_fx( test(); IF( ( EQ_16( st->bwidth, SWB ) || EQ_16( st->bwidth, FB ) ) && ( EQ_16( st->last_extl, SWB_TBE ) || EQ_16( st->last_extl, FB_TBE ) ) ) { - GenTransition_fixed( st->hBWE_TD, hb_synth_32_fx[n], output_Fs, st->element_mode, st->L_frame, st->rf_flag, st->total_brate, st->prev_Qx ); + GenTransition_fx32( hBWE_TD, hb_synth_32_fx[n], output_Fs, st->L_frame, hBWE_TD->prev_Qx ); } ELSE IF( EQ_16( st->bwidth, WB ) && EQ_16( st->last_extl, WB_TBE ) ) { - GenTransition_WB_fixed( st->hBWE_TD, hb_synth_32_fx[n], output_Fs ); + GenTransition_WB_fx32( hBWE_TD, hb_synth_32_fx[n], output_Fs ); } /* Memories Scaling */ - Copy_Scale_sig_32_16( st->hBWE_TD->syn_overlap_fx_32, st->hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, sub( st->prev_Q_bwe_syn2, Q11 ) ); // prev_Q_bwe_syn2 - Copy_Scale_sig_32_16( st->hBWE_TD->old_tbe_synth_fx_32, st->hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, sub( st->prev_Qx, Q11 ) ); // prev_Qx - Copy_Scale_sig_32_16( st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, ALLPASSSECTIONS_STEEP * 2, sub( st->prev_Qx, Q11 ) ); // prev_Qx - Copy_Scale_sig_32_16( st->hBWE_TD->state_lsyn_filt_shb_fx_32, st->hBWE_TD->state_lsyn_filt_shb_fx, ALLPASSSECTIONS_STEEP * 2, sub( st->prev_Qx, Q11 ) ); // prev_Qx - Copy_Scale_sig_32_16( st->hBWE_TD->mem_resamp_HB_fx_32, st->hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( st->prev_Qx, Q11 ) ); // prev_Qx + Copy_Scale_sig_32_16( hBWE_TD->syn_overlap_fx_32, hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, sub( hBWE_TD->prev_Q_bwe_syn2, Q11 ) ); // prev_Q_bwe_syn2 + Copy_Scale_sig_32_16( hBWE_TD->old_tbe_synth_fx_32, hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, sub( hBWE_TD->prev_Qx, Q11 ) ); // prev_Qx + Copy_Scale_sig_32_16( hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, hBWE_TD->state_lsyn_filt_dwn_shb_fx, ALLPASSSECTIONS_STEEP * 2, sub( hBWE_TD->prev_Qx, Q11 ) ); // prev_Qx + Copy_Scale_sig_32_16( hBWE_TD->state_lsyn_filt_shb_fx_32, hBWE_TD->state_lsyn_filt_shb_fx, ALLPASSSECTIONS_STEEP * 2, sub( hBWE_TD->prev_Qx, Q11 ) ); // prev_Qx + Copy_Scale_sig_32_16( hBWE_TD->mem_resamp_HB_fx_32, hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( hBWE_TD->prev_Qx, Q11 ) ); // prev_Qx } /* Memories Re-Scaling */ - IF( st->hBWE_TD != NULL ) + IF( hBWE_TD != NULL ) { #ifdef FIX_ISSUE_1237 - Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->syn_overlap_fx_32, L_SHB_LAHEAD, sub( Q11, st->prev_Q_bwe_syn2 ) ); // Q11 - Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->old_tbe_synth_fx, st->hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, sub( Q11, st->prev_Qx ) ); // Q11 - Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, ALLPASSSECTIONS_STEEP * 2, sub( Q11, st->prev_Qx ) ); // Q11 - Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->state_lsyn_filt_shb_fx, st->hBWE_TD->state_lsyn_filt_shb_fx_32, ALLPASSSECTIONS_STEEP * 2, sub( Q11, st->prev_Qx ) ); // Q11 - Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->mem_resamp_HB_fx_32, INTERP_3_1_MEM_LEN, sub( Q11, st->prev_Qx ) ); // Q11 + Copy_Scale_sig_16_32_no_sat( hBWE_TD->syn_overlap_fx, hBWE_TD->syn_overlap_fx_32, L_SHB_LAHEAD, sub( Q11, hBWE_TD->prev_Q_bwe_syn2 ) ); // Q11 + Copy_Scale_sig_16_32_no_sat( hBWE_TD->old_tbe_synth_fx, hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, sub( Q11, hBWE_TD->prev_Qx ) ); // Q11 + Copy_Scale_sig_16_32_no_sat( hBWE_TD->state_lsyn_filt_dwn_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, ALLPASSSECTIONS_STEEP * 2, sub( Q11, hBWE_TD->prev_Qx ) ); // Q11 + Copy_Scale_sig_16_32_no_sat( hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_shb_fx_32, ALLPASSSECTIONS_STEEP * 2, sub( Q11, hBWE_TD->prev_Qx ) ); // Q11 + Copy_Scale_sig_16_32_no_sat( hBWE_TD->mem_resamp_HB_fx, hBWE_TD->mem_resamp_HB_fx_32, INTERP_3_1_MEM_LEN, sub( Q11, hBWE_TD->prev_Qx ) ); // Q11 #else - Copy_Scale_sig_16_32_DEPREC( st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->syn_overlap_fx_32, L_SHB_LAHEAD, sub( Q11, st->prev_Q_bwe_syn2 ) ); // Q11 - Copy_Scale_sig_16_32_DEPREC( st->hBWE_TD->old_tbe_synth_fx, st->hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, sub( Q11, st->prev_Qx ) ); // Q11 - Copy_Scale_sig_16_32_DEPREC( st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, ALLPASSSECTIONS_STEEP * 2, sub( Q11, st->prev_Qx ) ); // Q11 - Copy_Scale_sig_16_32_DEPREC( st->hBWE_TD->state_lsyn_filt_shb_fx, st->hBWE_TD->state_lsyn_filt_shb_fx_32, ALLPASSSECTIONS_STEEP * 2, sub( Q11, st->prev_Qx ) ); // Q11 - Copy_Scale_sig_16_32_DEPREC( st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->mem_resamp_HB_fx_32, INTERP_3_1_MEM_LEN, sub( Q11, st->prev_Qx ) ); // Q11 + Copy_Scale_sig_16_32_DEPREC( hBWE_TD->syn_overlap_fx, hBWE_TD->syn_overlap_fx_32, L_SHB_LAHEAD, sub( Q11, st->prev_Q_bwe_syn2 ) ); // Q11 + Copy_Scale_sig_16_32_DEPREC( hBWE_TD->old_tbe_synth_fx, hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, sub( Q11, st->prev_Qx ) ); // Q11 + Copy_Scale_sig_16_32_DEPREC( hBWE_TD->state_lsyn_filt_dwn_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, ALLPASSSECTIONS_STEEP * 2, sub( Q11, st->prev_Qx ) ); // Q11 + Copy_Scale_sig_16_32_DEPREC( hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_shb_fx_32, ALLPASSSECTIONS_STEEP * 2, sub( Q11, st->prev_Qx ) ); // Q11 + Copy_Scale_sig_16_32_DEPREC( hBWE_TD->mem_resamp_HB_fx, hBWE_TD->mem_resamp_HB_fx_32, INTERP_3_1_MEM_LEN, sub( Q11, st->prev_Qx ) ); // Q11 #endif - Copy( st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->state_32and48k_WB_upsample_fx, ( 2 * ALLPASSSECTIONS_STEEP ) ); + Copy( hBWE_TD->mem_resamp_HB_fx, hBWE_TD->state_32and48k_WB_upsample_fx, ( 2 * ALLPASSSECTIONS_STEEP ) ); } + /*---------------------------------------------------------------------* * Postprocessing for ACELP/MDCT core switching *---------------------------------------------------------------------*/ @@ -961,32 +939,11 @@ ivas_error ivas_core_dec_fx( #ifdef FIX_ISSUE_1237 Copy_Scale_sig_16_32_no_sat( synth_16_fx[n], hSCE->save_synth_fx, output_frame, sub( hSCE->q_save_synth_fx, Q_synth ) ); // q_save_synth_fx #else - Copy_Scale_sig_16_32_DEPREC( synth_16_fx[n], hSCE->save_synth_fx, output_frame, sub( hSCE->q_save_synth_fx, Q_synth ) ); // q_save_synth_fx + Copy_Scale_sig_16_32_DEPREC( synth_16_fx[n], hSCE->save_synth_fx, output_frame, sub( hSCE->q_save_synth_fx, Q_synth ) ); // q_save_synth_fx #endif } - IVAS_FORMAT ivas_format; - IF( st_ivas != NULL ) - { - ivas_format = st_ivas->ivas_format; - move32(); - } - ELSE - { - ivas_format = UNDEFINED_FORMAT; - move32(); - } - IF( hCPE != NULL ) - { - last_element_mode = hCPE->last_element_mode; - move16(); - } - ELSE - { - last_element_mode = IVAS_SCE; - move16(); - } - IF( NE_32( ( error = core_switching_post_dec_ivas_fx( st, synth_16_fx[n], output_32_fx[n], p_output_mem_16, ivas_format, use_cldfb_for_dft, output_frame, 0 /*core_switching_flag*/, sba_dirac_stereo_flag, nchan_out, last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = core_switching_post_dec_ivas_fx( st, synth_16_fx[n], output_32_fx[n], p_output_mem_16, use_cldfb_for_dft, output_frame, 0 /*core_switching_flag*/, sba_dirac_stereo_flag, nchan_out, last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) { return error; } @@ -1000,7 +957,7 @@ ivas_error ivas_core_dec_fx( #ifdef FIX_ISSUE_1237 Copy_Scale_sig_16_32_no_sat( synth_16_fx[n], hSCE->save_synth_fx, output_frame, sub( hSCE->q_save_synth_fx, Q_synth ) ); // q_save_synth_fx #else - Copy_Scale_sig_16_32_DEPREC( synth_16_fx[n], hSCE->save_synth_fx, output_frame, sub( hSCE->q_save_synth_fx, Q_synth ) ); // q_save_synth_fx + Copy_Scale_sig_16_32_DEPREC( synth_16_fx[n], hSCE->save_synth_fx, output_frame, sub( hSCE->q_save_synth_fx, Q_synth ) ); // q_save_synth_fx #endif } @@ -1011,10 +968,11 @@ ivas_error ivas_core_dec_fx( test(); test(); test(); - IF( n == 0 && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->last_core == ACELP_CORE && st->core != ACELP_CORE && ( EQ_16( nchan_out, 1 ) || ( hCPE != NULL && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) ) ) + IF( n == 0 && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->last_core == ACELP_CORE && st->core != ACELP_CORE && ( EQ_16( nchan_out, 1 ) || EQ_16( last_element_mode, IVAS_CPE_DFT ) ) ) { Copy( sts[0]->previoussynth_fx, sts[1]->previoussynth_fx, st->hTcxDec->L_frameTCX ); } + /*---------------------------------------------------------------------* * Pre-processing for bandwidth switching *---------------------------------------------------------------------*/ @@ -1030,7 +988,7 @@ ivas_error ivas_core_dec_fx( #ifdef FIX_ISSUE_1237 Copy_Scale_sig_16_32_no_sat( st->delay_buf_out_fx, st->delay_buf_out32_fx, ( HQ_DELTA_MAX * HQ_DELAY_COMP ), sub( Q11, st->hHQ_core->Q_old_postdec ) ); // Q11 #else - Copy_Scale_sig_16_32_DEPREC( st->delay_buf_out_fx, st->delay_buf_out32_fx, ( HQ_DELTA_MAX * HQ_DELAY_COMP ), sub( Q11, st->hHQ_core->Q_old_postdec ) ); // Q11 + Copy_Scale_sig_16_32_DEPREC( st->delay_buf_out_fx, st->delay_buf_out32_fx, ( HQ_DELTA_MAX * HQ_DELAY_COMP ), sub( Q11, st->hHQ_core->Q_old_postdec ) ); // Q11 #endif } @@ -1060,17 +1018,17 @@ ivas_error ivas_core_dec_fx( test(); test(); - IF( NE_16( st->last_extl, WB_BWE ) && EQ_16( st->extl, WB_BWE ) && st->hBWE_FD != NULL ) + IF( NE_16( st->last_extl, WB_BWE ) && EQ_16( st->extl, WB_BWE ) && hBWE_FD != NULL ) { test(); if ( NE_16( st->last_extl, SWB_BWE ) && NE_16( st->last_extl, FB_BWE ) ) { - st->hBWE_FD->prev_mode = st->hBWE_FD->prev_mode; + hBWE_FD->prev_mode = hBWE_FD->prev_mode; move16(); } - st->hBWE_FD->prev_L_swb_norm = st->hBWE_FD->prev_L_swb_norm; + hBWE_FD->prev_L_swb_norm = hBWE_FD->prev_L_swb_norm; move16(); - st->hBWE_FD->prev_flag = st->hBWE_FD->prev_flag; + hBWE_FD->prev_flag = hBWE_FD->prev_flag; move16(); } @@ -1095,9 +1053,6 @@ ivas_error ivas_core_dec_fx( Q_synth_fx = Q_synth; move16(); - FD_BWE_DEC_HANDLE hBWE_FD; - hBWE_FD = st->hBWE_FD; - Copy_Scale_sig_32_16( output_32_fx[n], output_16_fx[n], L_FRAME48k, sub( Q_input, Q11 ) ); // Q_input Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, -( Q11 ) ); // Q0 test(); @@ -1128,9 +1083,9 @@ ivas_error ivas_core_dec_fx( Copy_Scale_sig_16_32_no_sat( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_input ) ); // Q11 // Q_input can get value <= -5 Copy_Scale_sig_16_32_no_sat( synth_16_fx[n], synth_32_fx[n], L_FRAME48k, sub( Q11, Q_synth_fx ) ); // Q11 #else - Copy_Scale_sig_16_32_DEPREC( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, sub( Q11, Q_hb_synth_fx ) ); // Q11 - Copy_Scale_sig_16_32_DEPREC( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_input ) ); // Q11 - Copy_Scale_sig_16_32_DEPREC( synth_16_fx[n], synth_32_fx[n], L_FRAME48k, sub( Q11, Q_synth_fx ) ); // Q11 + Copy_Scale_sig_16_32_DEPREC( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, sub( Q11, Q_hb_synth_fx ) ); // Q11 + Copy_Scale_sig_16_32_DEPREC( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_input ) ); // Q11 + Copy_Scale_sig_16_32_DEPREC( synth_16_fx[n], synth_32_fx[n], L_FRAME48k, sub( Q11, Q_synth_fx ) ); // Q11 #endif IF( hBWE_FD != NULL ) @@ -1138,15 +1093,15 @@ ivas_error ivas_core_dec_fx( #ifdef FIX_ISSUE_1237 Copy_Scale_sig_16_32_no_sat( hBWE_FD->L_old_wtda_swb_fx, hBWE_FD->L_old_wtda_swb_fx32, L_FRAME48k, sub( Q11, hBWE_FD->old_wtda_swb_fx_exp ) ); // Q11 #else - Copy_Scale_sig_16_32_DEPREC( hBWE_FD->L_old_wtda_swb_fx, hBWE_FD->L_old_wtda_swb_fx32, L_FRAME48k, sub( Q11, hBWE_FD->old_wtda_swb_fx_exp ) ); // Q11 + Copy_Scale_sig_16_32_DEPREC( hBWE_FD->L_old_wtda_swb_fx, hBWE_FD->L_old_wtda_swb_fx32, L_FRAME48k, sub( Q11, hBWE_FD->old_wtda_swb_fx_exp ) ); // Q11 #endif } - IF( st->hBWE_TD != NULL ) + IF( hBWE_TD != NULL ) { #ifdef FIX_ISSUE_1237 - Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->old_tbe_synth_fx, st->hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, sub( Q11, st->prev_Qx ) ); // Q11 + Copy_Scale_sig_16_32_no_sat( hBWE_TD->old_tbe_synth_fx, hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, sub( Q11, hBWE_TD->prev_Qx ) ); // Q11 #else - Copy_Scale_sig_16_32_DEPREC( st->hBWE_TD->old_tbe_synth_fx, st->hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, sub( Q11, st->prev_Qx ) ); // Q11 + Copy_Scale_sig_16_32_DEPREC( hBWE_TD->old_tbe_synth_fx, hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, sub( Q11, hBWE_TD->prev_Qx ) ); // Q11 #endif } @@ -1154,6 +1109,10 @@ ivas_error ivas_core_dec_fx( * SWB(FB) TBE decoding * SWB(FB) BWE decoding *---------------------------------------------------------------------*/ + + Q_white_exc = 0; + move16(); + test(); test(); test(); @@ -1174,12 +1133,10 @@ ivas_error ivas_core_dec_fx( IF( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) || ( NE_16( st->coder_type, AUDIO ) && NE_16( st->coder_type, INACTIVE ) && GE_32( st->core_brate, SID_2k40 ) && EQ_16( st->core, ACELP_CORE ) && !st->con_tcx && GE_32( output_Fs, 32000 ) && GT_16( st->bwidth, NB ) && st->bws_cnt > 0 ) ) { /* SWB TBE decoder */ - Q_white_exc = 0; - move16(); - ivas_swb_tbe_dec_fx( st, hStereoICBWE, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], old_syn_12k8_16k_fx[n], tmp_buffer_fx /*fb_exc*/, hb_synth_32_fx[n], pitch_buf_fx[n], &Q_white_exc ); - Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->syn_overlap_fx_32, L_SHB_LAHEAD, sub( Q11, st->prev_Q_bwe_syn2 ) ); // Q11 - Copy_Scale_sig_32_16( st->hBWE_TD->old_tbe_synth_fx_32, st->hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, sub( st->prev_Qx, Q11 ) ); // prev_Qx + + Copy_Scale_sig_16_32_no_sat( hBWE_TD->syn_overlap_fx, hBWE_TD->syn_overlap_fx_32, L_SHB_LAHEAD, sub( Q11, hBWE_TD->prev_Q_bwe_syn2 ) ); // Q11 + Copy_Scale_sig_32_16( hBWE_TD->old_tbe_synth_fx_32, hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, sub( hBWE_TD->prev_Qx, Q11 ) ); // prev_Qx IF( GT_16( Q_white_exc, 31 ) ) { @@ -1201,7 +1158,7 @@ ivas_error ivas_core_dec_fx( Scale_sig32( hb_synth_32_fx[n], output_frame, sub( Q11, Q_syn_hb ) ); // Q11 - Copy_Scale_sig_32_16( st->hBWE_FD->L_old_wtda_swb_fx32, st->hBWE_FD->L_old_wtda_swb_fx, output_frame, sub( hBWE_FD->old_wtda_swb_fx_exp, Q11 ) ); // old_wtda_swb_fx_exp + Copy_Scale_sig_32_16( hBWE_FD->L_old_wtda_swb_fx32, hBWE_FD->L_old_wtda_swb_fx, output_frame, sub( hBWE_FD->old_wtda_swb_fx_exp, Q11 ) ); // old_wtda_swb_fx_exp } /*---------------------------------------------------------------------* @@ -1253,8 +1210,8 @@ ivas_error ivas_core_dec_fx( #else Copy_Scale_sig_32_16( synth_32_fx[n], synth_fxl, L_FRAME48k, negate( add( Q11, q ) ) ); #endif - Scale_sig( st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, sub( Q8, st->prev_Q_bwe_syn ) ); // Q8 - Copy_Scale_sig_32_16( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, ( 2 * ALLPASSSECTIONS_STEEP ), sub( st->prev_Q_bwe_syn2, Q11 ) ); // prev_Q_bew_syn2 + Scale_sig( hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, sub( Q8, hBWE_TD->prev_Q_bwe_syn ) ); // Q8 + Copy_Scale_sig_32_16( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, ( 2 * ALLPASSSECTIONS_STEEP ), sub( hBWE_TD->prev_Q_bwe_syn2, Q11 ) ); // prev_Q_bew_syn2 swb_CNG_dec_ivas_fx( st, synth_fxl, hb_synth_16_fx[n], sid_bw[n], negate( q ) ); @@ -1264,13 +1221,14 @@ ivas_error ivas_core_dec_fx( Copy_Scale_sig_16_32_DEPREC( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, ( Q11 ) ); // Q11 } - Scale_sig( st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, negate( sub( Q8, st->prev_Q_bwe_syn ) ) ); // Q0 - Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, 2 * ALLPASSSECTIONS_STEEP, negate( sub( st->prev_Q_bwe_syn2, Q11 ) ) ); + Scale_sig( hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, negate( sub( Q8, hBWE_TD->prev_Q_bwe_syn ) ) ); // Q0 + Copy_Scale_sig_16_32_no_sat( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, 2 * ALLPASSSECTIONS_STEEP, negate( sub( hBWE_TD->prev_Q_bwe_syn2, Q11 ) ) ); } /*-------------------------------------------------------------------* * Inter-channel BWE decoding *-------------------------------------------------------------------*/ + test(); IF( n == 0 && GE_16( st->element_mode, IVAS_CPE_DFT ) ) { @@ -1319,18 +1277,20 @@ ivas_error ivas_core_dec_fx( IF( EQ_16( st->core, ACELP_CORE ) && !st->bfi && st->prev_bfi && GE_32( st->last_total_brate, HQ_48k ) && EQ_16( st->last_codec_mode, MODE2 ) && ( EQ_16( st->last_core_bfi, TCX_20_CORE ) || EQ_16( st->last_core_bfi, TCX_10_CORE ) ) && EQ_16( st->hPlcInfo->concealment_method, TCX_NONTONAL ) && LT_16( st->hPlcInfo->nbLostCmpt, 4 ) ) { tmps = NS2SA_FX2( output_Fs, DELAY_CLDFB_NS ); - IF( st->tonalMDCTconceal.q_lastPcmOut != 0 ) + IF( st->hTonalMDCTConc->q_lastPcmOut != 0 ) { - Scale_sig( st->tonalMDCTconceal.secondLastPcmOut, shr( st->plcInfo.FrameSize, 1 ), negate( st->tonalMDCTconceal.q_lastPcmOut ) ); - Scale_sig( st->tonalMDCTconceal.lastPcmOut, st->plcInfo.FrameSize, negate( st->tonalMDCTconceal.q_lastPcmOut ) ); - st->tonalMDCTconceal.q_lastPcmOut = 0; + Scale_sig( st->hTonalMDCTConc->secondLastPcmOut, shr( st->hPlcInfo->L_frameTCX, 1 ), negate( st->hTonalMDCTConc->q_lastPcmOut ) ); + Scale_sig( st->hTonalMDCTConc->lastPcmOut, st->hPlcInfo->L_frameTCX, negate( st->hTonalMDCTConc->q_lastPcmOut ) ); + st->hTonalMDCTConc->q_lastPcmOut = 0; move16(); } - waveform_adj2_fix( st->hTonalMDCTConc->secondLastPcmOut, synth_16_fx[n] + tmps, st->plcInfo.data_noise, &st->plcInfo.outx_new_n1_fx, - &st->plcInfo.nsapp_gain_fx, &st->plcInfo.nsapp_gain_n_fx, &st->plcInfo.recovery_gain, st->plcInfo.step_concealgain_fx, - st->plcInfo.Pitch_fx, st->plcInfo.FrameSize, tmps, add( st->hPlcInfo->nbLostCmpt, 1 ), st->bfi ); + waveform_adj2_fix( st->hPlcInfo, st->hTonalMDCTConc->secondLastPcmOut, synth_16_fx[n] + tmps, tmps, add( st->hPlcInfo->nbLostCmpt, 1 ), st->bfi ); +#ifdef NONBE_FIX_1402_WAVEADJUST + st->hPlcInfo->Pitch_fx = 0; +#else st->hPlcInfo->Pitch = 0; +#endif move16(); } } @@ -1467,24 +1427,13 @@ ivas_error ivas_core_dec_fx( { Word16 exp; Word32 fra; - SWITCH( output_frame ) + + tmp16 = 34; /*ouput_frame == L_FRAME 48k: Q15*/ + move16(); + if ( EQ_16( output_frame, L_FRAME32k ) ) { - case L_FRAME8k: - tmp16 = 205; - move16(); - BREAK; /*Q15*/ - case L_FRAME16k: - tmp16 = 102; - move16(); - BREAK; /*Q15*/ - case L_FRAME32k: - tmp16 = 51; - move16(); - BREAK; /*Q15*/ - case L_FRAME48k: - tmp16 = 34; - move16(); - BREAK; /*Q15*/ + tmp16 = 51; /*Q15*/ + move16(); } L_tmp = L_deposit_l( 2 ); /*0.001 in Q11*/ @@ -1504,9 +1453,9 @@ ivas_error ivas_core_dec_fx( L_tmp = BASOP_Util_Add_Mant32Exp( fra, 6, L_tmp, exp, &exp ); L_tmp = Mpy_32_16_1( L_tmp, 24660 ); exp = add( exp, 2 ); - st->last_shb_ener_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 7 ) ) ); /*Q8*/ + st->hTdCngDec->last_shb_ener_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 7 ) ) ); /*Q8*/ move16(); - st->hTdCngDec->last_shb_ener_fx = L_shl_sat( L_tmp, sub( exp, 20 ) ); /*Q11*/ + st->hTdCngDec->last_shb_ener_fx_32 = L_shl_sat( L_tmp, sub( exp, 20 ) ); /*Q11*/ move32(); } } @@ -1524,48 +1473,18 @@ ivas_error ivas_core_dec_fx( * - core switching in DFT stereo * - updates for potential TD->DFT stereo switching *----------------------------------------------------------------*/ - IF( hCPE != NULL ) - { - FOR( Word32 ch_ind = 0; ch_ind < n_channels; ch_ind++ ) - { - IF( hCPE->hCoreCoder[ch_ind] != NULL ) - { - IF( hCPE->hCoreCoder[ch_ind]->hHQ_core != NULL ) - { -#ifdef FIX_ISSUE_1237 - Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[ch_ind]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, hCPE->hCoreCoder[ch_ind]->hHQ_core->Q_old_wtda_LB ) ); // Q11 - Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out_fx, hCPE->hCoreCoder[ch_ind]->hHQ_core->oldOut_fx, L_FRAME48k, sub( Q11, hCPE->hCoreCoder[ch_ind]->hHQ_core->Q_old_wtda ) ); // Q11 -#else - Copy_Scale_sig_16_32_DEPREC( hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[ch_ind]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, hCPE->hCoreCoder[ch_ind]->hHQ_core->Q_old_wtda_LB ) ); // Q11 - Copy_Scale_sig_16_32_DEPREC( hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out_fx, hCPE->hCoreCoder[ch_ind]->hHQ_core->oldOut_fx, L_FRAME48k, sub( Q11, hCPE->hCoreCoder[ch_ind]->hHQ_core->Q_old_wtda ) ); // Q11 -#endif - } - } - } - } - IF( hSCE != NULL ) + IF( st->hHQ_core != NULL ) { - IF( hSCE->hCoreCoder[0] != NULL ) - { - IF( hSCE->hCoreCoder[0]->hHQ_core != NULL ) - { #ifdef FIX_ISSUE_1237 - Copy_Scale_sig_16_32_no_sat( hSCE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hSCE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, hSCE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ) ); // Q11 - Copy_Scale_sig_16_32_no_sat( hSCE->hCoreCoder[0]->hHQ_core->old_out_fx, hSCE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, sub( Q11, hSCE->hCoreCoder[0]->hHQ_core->Q_old_wtda ) ); // Q11 + Copy_Scale_sig_16_32_no_sat( st->hHQ_core->old_out_LB_fx, st->hHQ_core->old_out_LB_fx32, L_FRAME32k, sub( Q11, st->hHQ_core->Q_old_wtda_LB ) ); // Q11 + Copy_Scale_sig_16_32_no_sat( st->hHQ_core->old_out_fx, st->hHQ_core->old_out_fx32, L_FRAME48k, sub( Q11, st->hHQ_core->Q_old_wtda ) ); // Q11 #else - Copy_Scale_sig_16_32_DEPREC( hSCE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hSCE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, hSCE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ) ); // Q11 - Copy_Scale_sig_16_32_DEPREC( hSCE->hCoreCoder[0]->hHQ_core->old_out_fx, hSCE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, sub( Q11, hSCE->hCoreCoder[0]->hHQ_core->Q_old_wtda ) ); // Q11 + Copy_Scale_sig_16_32_DEPREC( st->hHQ_core->old_out_LB_fx, st->hHQ_core->old_out_LB_fx32, L_FRAME32k, sub( Q11, st->hHQ_core->Q_old_wtda_LB ) ); // Q11 + Copy_Scale_sig_16_32_DEPREC( st->hHQ_core->old_out_fx, st->hHQ_core->old_out_fx32, L_FRAME48k, sub( Q11, st->hHQ_core->Q_old_wtda ) ); // Q11 #endif - } - } } - Word16 exp_max; - Word32 output_fx_loc[L_FRAME48k]; - - exp_max = 0; - move16(); IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) { test(); @@ -1588,7 +1507,7 @@ ivas_error ivas_core_dec_fx( Word16 q; q = 11; move16(); - IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) + IF( EQ_16( last_element_mode, IVAS_CPE_MDCT ) ) { stereo_mdct2dft_update_fx( hCPE, output_32_fx[0], synth_32_fx[0] ); } @@ -1621,8 +1540,13 @@ ivas_error ivas_core_dec_fx( * Common updates *--------------------------------------------------------*/ - /*Scale Memories*/ + Word16 exp_max; + Word32 output_fx_loc[L_FRAME48k]; + exp_max = 0; + move16(); + + /*Scale Memories*/ test(); test(); test(); @@ -1664,11 +1588,11 @@ ivas_error ivas_core_dec_fx( st->q_prev_synth_buffer_fx = sub( exp_max, st->q_prev_synth_buffer_fx ); move16(); } + /* Save synthesis for HQ FEC */ save_synthesis_hq_fec_fx( st, NULL, output_fx_loc, output_frame, 0, hCPE ); /* Updates */ - ivas_updt_dec_common_fx( st, NORMAL_HQ_CORE, -1, output_32_fx[n], Q11 ); Scale_sig( st->delay_buf_out_fx, NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ), negate( exp_max ) ); // Q0 diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index 9e934cc888f116b241496c89510ac9ef449123d1..8e25e5116b95978e70911ac82986b8191dadc39d 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -125,9 +125,9 @@ ivas_error ivas_cpe_dec_fx( IF( hCPE->hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core ) { #ifdef FIX_ISSUE_1237 - Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx, hCPE->hCoreCoder[ind1]->hHQ_core->oldOut_fx, L_FRAME48k, sub( Q11, hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda ) ); // Q11 + Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx32, L_FRAME48k, sub( Q11, hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda ) ); // Q11 #else - Copy_Scale_sig_16_32_DEPREC( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx, hCPE->hCoreCoder[ind1]->hHQ_core->oldOut_fx, L_FRAME48k, sub( Q11, hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda ) ); // Q11 + Copy_Scale_sig_16_32_DEPREC( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx32, L_FRAME48k, sub( Q11, hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda ) ); // Q11 #endif } } @@ -136,9 +136,9 @@ ivas_error ivas_cpe_dec_fx( IF( hCPE->hCoreCoder[ind1]->hHQ_core ) { #ifdef FIX_ISSUE_1237 - Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda_LB ) ); // Q11 + Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx32, L_FRAME32k, sub( Q11, hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda_LB ) ); // Q11 #else - Copy_Scale_sig_16_32_DEPREC( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda_LB ) ); // Q11 + Copy_Scale_sig_16_32_DEPREC( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx32, L_FRAME32k, sub( Q11, hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda_LB ) ); // Q11 #endif hCPE->hCoreCoder[ind1]->hHQ_core->q_old_outLB_fx = Q11; move16(); @@ -155,7 +155,7 @@ ivas_error ivas_cpe_dec_fx( test(); IF( hCPE->hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core ) { - Copy_Scale_sig_32_16( hCPE->hCoreCoder[ind1]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx, L_FRAME48k, sub( hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda, Q11 ) ); // Q_old_wtda + Copy_Scale_sig_32_16( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx32, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx, L_FRAME48k, sub( hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda, Q11 ) ); // Q_old_wtda } } FOR( Word16 ind1 = 0; ind1 < 2; ind1++ ) @@ -163,7 +163,7 @@ ivas_error ivas_cpe_dec_fx( test(); IF( hCPE->hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core ) { - Copy_Scale_sig_32_16( hCPE->hCoreCoder[ind1]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda_LB, Q11 ) ); // Q_old_wtda + Copy_Scale_sig_32_16( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx32, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda_LB, Q11 ) ); // Q_old_wtda } } @@ -1097,8 +1097,6 @@ ivas_error create_cpe_dec( move32(); st->is_ism_format = 0; move16(); - st->ivas_format = st_ivas->ivas_format; - move32(); IF( NE_32( ( error = init_decoder_ivas_fx( st, n, st_ivas->mc_mode ) ), IVAS_ERR_OK ) ) { diff --git a/lib_dec/ivas_jbm_dec_fx.c b/lib_dec/ivas_jbm_dec_fx.c index 4fa2055bd1e67764d881a7a880745eccc5079af3..c5e3d451ac8a061b9ed755500cd4cf20354627de 100644 --- a/lib_dec/ivas_jbm_dec_fx.c +++ b/lib_dec/ivas_jbm_dec_fx.c @@ -409,7 +409,7 @@ ivas_error ivas_jbm_dec_tc_fx( move16(); FOR( i = 0; i < 2; i++ ) { - s = s_min( s, L_norm_arr( p_output_fx[i], L_FRAME48k ) - 11 ) /* Guard bits */; + s = s_min( s, L_norm_arr( p_output_fx[i], L_FRAME48k ) - 11 ) /* Guard bits */; // L_frame should be used instead of L_FRAME48k */ } FOR( i = 0; i < 2; i++ ) { @@ -435,11 +435,11 @@ ivas_error ivas_jbm_dec_tc_fx( IF( hCPE->hCoreCoder[0] != NULL ) { #ifdef FIX_ISSUE_1237 - Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); // q - Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); // q + Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); // q + Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, L_FRAME48k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); // q #else - Copy_Scale_sig_16_32_DEPREC( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); // q - Copy_Scale_sig_16_32_DEPREC( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); // q + Copy_Scale_sig_16_32_DEPREC( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); // q + Copy_Scale_sig_16_32_DEPREC( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, L_FRAME48k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); // q #endif hCPE->hCoreCoder[0]->hHQ_core->q_old_outLB_fx = q; move16(); @@ -550,8 +550,8 @@ ivas_error ivas_jbm_dec_tc_fx( IF( hCPE->hCoreCoder[0] != NULL ) { - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB - q ); // Q_old_wtda_LB - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, L_FRAME48k, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda - q ); // Q_old_wtda_LB + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB - q ); // Q_old_wtda_LB + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, L_FRAME48k, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda - q ); // Q_old_wtda_LB } IF( hCPE->hStereoDft != NULL ) { @@ -604,7 +604,7 @@ ivas_error ivas_jbm_dec_tc_fx( } } #else - scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 + scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 #endif scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA_FX2( 16000, DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // Q11 hCPE->hStereoDft->q_ap_fade_mem_fx = Q11; @@ -972,11 +972,11 @@ ivas_error ivas_jbm_dec_tc_fx( IF( hCPE->hCoreCoder[0] != NULL ) { #ifdef FIX_ISSUE_1237 - Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( q, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ) ); // q - Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, sub( q, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ) ); // q + Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k, sub( q, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ) ); // q + Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, L_FRAME48k, sub( q, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ) ); // q #else - Copy_Scale_sig_16_32_DEPREC( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( q, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ) ); // q - Copy_Scale_sig_16_32_DEPREC( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, sub( q, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ) ); // q + Copy_Scale_sig_16_32_DEPREC( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k, sub( q, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ) ); // q + Copy_Scale_sig_16_32_DEPREC( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, L_FRAME48k, sub( q, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ) ); // q #endif hCPE->hCoreCoder[0]->hHQ_core->q_old_outLB_fx = q; move16(); @@ -1033,8 +1033,8 @@ ivas_error ivas_jbm_dec_tc_fx( IF( hCPE->hCoreCoder[0] != NULL ) { - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB, q ) ); // Q_old_wtda_LB - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, L_FRAME48k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda, q ) ); // Q_old_wtda + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB, q ) ); // Q_old_wtda_LB + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, L_FRAME48k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda, q ) ); // Q_old_wtda } IF( hCPE->hStereoDft != NULL ) { @@ -1432,11 +1432,11 @@ ivas_error ivas_jbm_dec_tc_fx( IF( hCPE->hCoreCoder[0] != NULL ) { #ifdef FIX_ISSUE_1237 - Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); // q - Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); // q + Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); // q + Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, L_FRAME48k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); // q #else - Copy_Scale_sig_16_32_DEPREC( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); // q - Copy_Scale_sig_16_32_DEPREC( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); // q + Copy_Scale_sig_16_32_DEPREC( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); // q + Copy_Scale_sig_16_32_DEPREC( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, L_FRAME48k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); // q #endif hCPE->hCoreCoder[0]->hHQ_core->q_old_outLB_fx = q; move16(); @@ -1496,8 +1496,8 @@ ivas_error ivas_jbm_dec_tc_fx( IF( hCPE->hCoreCoder[0] != NULL ) { - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB, q ) ); // Q_old_wtda_LB - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, L_FRAME48k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda, q ) ); // Q_old_wtda + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB, q ) ); // Q_old_wtda_LB + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, L_FRAME48k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda, q ) ); // Q_old_wtda } IF( hCPE->hStereoDft != NULL ) { diff --git a/lib_dec/ivas_mct_dec_fx.c b/lib_dec/ivas_mct_dec_fx.c index 587614cee76efbb6188f4fd82f9cfb87151f50e3..4eb0ad68617c2b2b31848cca543a078f80302dd4 100644 --- a/lib_dec/ivas_mct_dec_fx.c +++ b/lib_dec/ivas_mct_dec_fx.c @@ -411,10 +411,10 @@ ivas_error ivas_mct_dec_fx( { #ifdef FIX_ISSUE_1237 Copy_Scale_sig_16_32_no_sat( synth_fx[n], synth_fx_32[n], L_FRAME48k, sub( Q11, ( sub( 15, e_sig[n] ) ) ) ); // Q11 - Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, hCPE->hCoreCoder[n]->hHQ_core->oldOut_fx, output_frame, sub( Q11, hCPE->hCoreCoder[n]->hHQ_core->Q_old_wtda ) ); + Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, hCPE->hCoreCoder[n]->hHQ_core->old_out_fx32, output_frame, sub( Q11, hCPE->hCoreCoder[n]->hHQ_core->Q_old_wtda ) ); #else Copy_Scale_sig_16_32_DEPREC( synth_fx[n], synth_fx_32[n], L_FRAME48k, sub( Q11, ( sub( 15, e_sig[n] ) ) ) ); // Q11 - Copy_Scale_sig_16_32_DEPREC( hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, hCPE->hCoreCoder[n]->hHQ_core->oldOut_fx, output_frame, sub( Q11, hCPE->hCoreCoder[n]->hHQ_core->Q_old_wtda ) ); + Copy_Scale_sig_16_32_DEPREC( hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, hCPE->hCoreCoder[n]->hHQ_core->old_out_fx32, output_frame, sub( Q11, hCPE->hCoreCoder[n]->hHQ_core->Q_old_wtda ) ); #endif ivas_post_proc_fx( NULL, hCPE, n, synth_fx_32[n], NULL, output_frame, 1, Q11 ); #ifdef MSAN_FIX @@ -448,7 +448,7 @@ ivas_error ivas_mct_dec_fx( { dirac_stereo_flag = 0; } - IF( NE_32( ( error = core_switching_post_dec_ivas_fx( sts[n], synth_fx[n], output_fx[( cpe_id * CPE_CHANNELS ) + n], output_mem_fx, st_ivas->ivas_format, 0, output_frame, 0 /*core_switching_flag*/, dirac_stereo_flag, -1, hCPE->last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = core_switching_post_dec_ivas_fx( sts[n], synth_fx[n], output_fx[( cpe_id * CPE_CHANNELS ) + n], output_mem_fx, 0, output_frame, 0 /*core_switching_flag*/, dirac_stereo_flag, -1, hCPE->last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_dec/ivas_post_proc_fx.c b/lib_dec/ivas_post_proc_fx.c index 9357394a5741ee2b152504f8db29d408374c4801..03fe4063ad13e3f19610201a8f66e306556a9622 100644 --- a/lib_dec/ivas_post_proc_fx.c +++ b/lib_dec/ivas_post_proc_fx.c @@ -92,7 +92,7 @@ void ivas_post_proc_fx( IF( NE_16( sts[n]->core, TCX_20_CORE ) && NE_16( sts[n]->core, TCX_10_CORE ) ) { /* TCX-LTP Postfilter: used in Mode 1 to update memories and to avoid discontinuities when the past frame was TCX */ - tcx_ltp_post32( sts[n], hTcxLtpDec, ACELP_CORE, output_frame, 0, synth, NULL, output_q ); + tcx_ltp_post_fx32( sts[n], hTcxLtpDec, ACELP_CORE, output_frame, 0, synth, NULL, output_q ); } ELSE { @@ -112,10 +112,10 @@ void ivas_post_proc_fx( { Word16 numZeros = (Word16) ( NS2SA_FX2( output_Fs, N_ZERO_MDCT_NS ) ); /*Q0*/ move16(); - Copy32( sts[n]->hHQ_core->oldOut_fx + numZeros, sts[n]->hTcxDec->FBTCXdelayBuf_32, delay_comp ); /*Q11*/ + Copy32( sts[n]->hHQ_core->old_out_fx32 + numZeros, sts[n]->hTcxDec->FBTCXdelayBuf_32, delay_comp ); /*Q11*/ } - tcx_ltp_post32( sts[n], hTcxLtpDec, sts[n]->core, output_frame, add( NS2SA_FX2( output_Fs, ACELP_LOOK_NS ), delay_comp ), synth, sts[n]->hTcxDec->FBTCXdelayBuf_32, output_q ); + tcx_ltp_post_fx32( sts[n], hTcxLtpDec, sts[n]->core, output_frame, add( NS2SA_FX2( output_Fs, ACELP_LOOK_NS ), delay_comp ), synth, sts[n]->hTcxDec->FBTCXdelayBuf_32, output_q ); } } } @@ -152,12 +152,12 @@ void ivas_post_proc_fx( IF( NE_16( sts[0]->core, TCX_20_CORE ) && NE_16( sts[0]->core, TCX_10_CORE ) ) { /* update memories and to avoid discontinuities when the past frame was TCX */ - tcx_ltp_post32( sts[0], hTcxLtpDec, ACELP_CORE, output_frame, 0, output[k], NULL, output_q ); + tcx_ltp_post_fx32( sts[0], hTcxLtpDec, ACELP_CORE, output_frame, 0, output[k], NULL, output_q ); } ELSE { /*Use channel 0 side info.*/ - tcx_ltp_post32( sts[0], hTcxLtpDec, TCX_20_CORE, output_frame, NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ), output[k], hCPE->output_mem_fx[k], output_q ); + tcx_ltp_post_fx32( sts[0], hTcxLtpDec, TCX_20_CORE, output_frame, NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ), output[k], hCPE->output_mem_fx[k], output_q ); } } } @@ -416,8 +416,8 @@ void stereo_dft_dec_core_switching_fx( delay_comp = NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ); /*Q0*/ move16(); - Copy32( &st->hHQ_core->oldOut_fx[nZeros - ( delay_comp + NS2SA( output_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) )], hCPE->input_mem_fx[0], NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); /*Q11*/ - Copy32( synth_fx, synth_tmp_fx, output_frame ); /*q*/ + Copy32( &st->hHQ_core->old_out_fx32[nZeros - ( delay_comp + NS2SA( output_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) )], hCPE->input_mem_fx[0], NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); /*Q11*/ + Copy32( synth_fx, synth_tmp_fx, output_frame ); /*q*/ Word16 mem_len; mem_len = NS2SA_FX2( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ); /*Q0*/ @@ -605,7 +605,7 @@ void stereo_dft_dec_core_switching_fx( Word16 numZeros = (Word16) ( NS2SA_FX2( st->sr_core, N_ZERO_MDCT_NS ) ); /*Q0*/ Word32 tmp_fade_fx[max( STEREO_DFT_ALLPASS_FADELEN_12k8, STEREO_DFT_ALLPASS_FADELEN_16k )]; - Copy32( st->hHQ_core->old_outLB_fx + numZeros, hCPE->hStereoDft->ap_fade_mem_fx, ap_fade_len ); /*st->hHQ_core->q_old_outLB_fx*/ + Copy32( st->hHQ_core->old_out_LB_fx32 + numZeros, hCPE->hStereoDft->ap_fade_mem_fx, ap_fade_len ); /*st->hHQ_core->q_old_outLB_fx*/ hCPE->hStereoDft->q_ap_fade_mem_fx = st->hHQ_core->q_old_outLB_fx; move16(); diff --git a/lib_dec/ivas_sce_dec_fx.c b/lib_dec/ivas_sce_dec_fx.c index 26dc691910c4c6c70d63c6e36c222b62852e9997..6e1893015fec3992e084426df2874572579b5d15 100644 --- a/lib_dec/ivas_sce_dec_fx.c +++ b/lib_dec/ivas_sce_dec_fx.c @@ -408,8 +408,6 @@ ivas_error create_sce_dec( move16(); st->is_ism_format = 0; move16(); - st->ivas_format = st_ivas->ivas_format; - move16(); test(); if ( EQ_16( (Word16) st_ivas->ivas_format, ISM_FORMAT ) || EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) ) @@ -456,7 +454,7 @@ ivas_error create_sce_dec( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); } - td_cng_dec_init_ivas_fx( st ); + td_cng_dec_init_fx( st ); } /*-----------------------------------------------------------------* diff --git a/lib_dec/ivas_stereo_icbwe_dec_fx.c b/lib_dec/ivas_stereo_icbwe_dec_fx.c index 3b32072f300c229e5c36211909bff0bb84024d22..04aeccbb525f0af2ccf95974b6d878db3f3c4332 100644 --- a/lib_dec/ivas_stereo_icbwe_dec_fx.c +++ b/lib_dec/ivas_stereo_icbwe_dec_fx.c @@ -630,7 +630,7 @@ void stereo_icBWE_dec_fx( Scale_sig32( shb_synth_nonref_fx, L_FRAME16k + L_SHB_LAHEAD, sub( tmp, Q_syn_shb ) ); /* tmp */ Scale_sig32( hStereoICBWE->mem_syn_shb_ola_nonref_fx, L_SHB_LAHEAD, sub( tmp, hStereoICBWE->prev_Q_syn_shb_ola_nonref ) ); /* tmp */ - ScaleShapedSHB_32( SHB_OVERLAP_LEN, shb_synth_nonref_fx, hStereoICBWE->mem_syn_shb_ola_nonref_fx, hStereoICBWE->gshapeRef_fx, ( Mpy_32_16_1( L_shl( hStereoICBWE->gFrameRef_fx, 1 ), mult_r( gsMapping_fx, 29492 /* 0.9 in Q15 */ ) ) ), window_shb_fx, subwin_shb_fx, &tmp, &temp1_fx ); + ScaleShapedSHB_fx32( SHB_OVERLAP_LEN, shb_synth_nonref_fx, hStereoICBWE->mem_syn_shb_ola_nonref_fx, hStereoICBWE->gshapeRef_fx, ( Mpy_32_16_1( L_shl( hStereoICBWE->gFrameRef_fx, 1 ), mult_r( gsMapping_fx, 29492 /* 0.9 in Q15 */ ) ) ), window_shb_fx, subwin_shb_fx, &tmp, &temp1_fx ); hStereoICBWE->prev_Q_syn_shb_ola_nonref = tmp; move16(); @@ -664,7 +664,7 @@ void stereo_icBWE_dec_fx( Q_syn_shb = tmp; move16(); - GenSHBSynth_fx_32( shb_synth_nonref_fx, error_fx, hStereoICBWE->memShbHilbert_nonref_fx, hStereoICBWE->memShbInterp_nonref_fx, st->L_frame, &( hStereoICBWE->syn_dm_phase_nonref ) ); + GenSHBSynth_fx32( shb_synth_nonref_fx, error_fx, hStereoICBWE->memShbHilbert_nonref_fx, hStereoICBWE->memShbInterp_nonref_fx, st->L_frame, &( hStereoICBWE->syn_dm_phase_nonref ) ); } ELSE { @@ -797,7 +797,7 @@ void stereo_icBWE_dec_fx( Scale_sig32( error_fx, L_FRAME32k, sub( tmp, Q_syn_shb ) ); /* tmp */ Scale_sig32( hStereoICBWE->memShb_fsout_nonref_fx, INTERP_3_2_MEM_LEN, sub( tmp, hStereoICBWE->prev_Q_fsout ) ); /* tmp */ - interpolate_3_over_2_allpass_32( error_fx, L_FRAME32k, synth_fx, hStereoICBWE->memShb_fsout_nonref_fx ); + interpolate_3_over_2_allpass_fx32( error_fx, L_FRAME32k, synth_fx, hStereoICBWE->memShb_fsout_nonref_fx ); hStereoICBWE->prev_Q_fsout = tmp; move16(); } @@ -1312,9 +1312,13 @@ void stereo_icBWE_decproc_fx( move32(); } } + /* reset BWE structs as they are only needed in the transition frame in MDCT Stereo */ - td_bwe_dec_init_ivas_fx( hCPE->hCoreCoder[0], hCPE->hCoreCoder[0]->hBWE_TD, output_Fs ); - fd_bwe_dec_init( hCPE->hCoreCoder[0], hCPE->hCoreCoder[0]->hBWE_FD ); + td_bwe_dec_init_fx( hCPE->hCoreCoder[0]->hBWE_TD, -1, output_Fs ); + fd_bwe_dec_init_fx( hCPE->hCoreCoder[0]->hBWE_FD ); + + hCPE->hCoreCoder[0]->prev_Q_bwe_exc = 31; + move16(); } test(); diff --git a/lib_dec/ivas_stereo_switching_dec_fx.c b/lib_dec/ivas_stereo_switching_dec_fx.c index cc9878367fdf68b0ffeabee82d134e9d0ece2db2..6bf2d7a45b18550a5ab240cefdd89b662016e6a4 100644 --- a/lib_dec/ivas_stereo_switching_dec_fx.c +++ b/lib_dec/ivas_stereo_switching_dec_fx.c @@ -420,11 +420,11 @@ ivas_error stereo_memory_dec_fx( test(); IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { - v_add_32( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[1]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, extract_l( Mpy_32_16_1( output_Fs, INV_FRAME_PER_SEC_Q15 ) ) ); /* exp(exp_old_out) */ - v_multc_fixed_16( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, 16384 /* 0.5 in Q15 */, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, extract_l( Mpy_32_16_1( output_Fs, INV_FRAME_PER_SEC_Q15 ) ) ); /* exp(exp_old_out) */ + v_add_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, hCPE->hCoreCoder[1]->hHQ_core->old_out_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, extract_l( Mpy_32_16_1( output_Fs, INV_FRAME_PER_SEC_Q15 ) ) ); /* exp(exp_old_out) */ + v_multc_fixed_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, 16384 /* 0.5 in Q15 */, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, extract_l( Mpy_32_16_1( output_Fs, INV_FRAME_PER_SEC_Q15 ) ) ); /* exp(exp_old_out) */ - v_add_32( hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[1]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k ); /* q_old_outLB_fx */ - v_multc_fixed_16( hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, 16384 /* 0.5 in Q15 */, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k ); /* exp(exp_old_out) */ + v_add_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, hCPE->hCoreCoder[1]->hHQ_core->old_out_LB_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k ); /* q_old_outLB_fx */ + v_multc_fixed_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, 16384 /* 0.5 in Q15 */, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k ); /* exp(exp_old_out) */ } /*--------------------------------------------------------------* @@ -501,7 +501,7 @@ ivas_error stereo_memory_dec_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); } - td_cng_dec_init_ivas_fx( st ); + td_cng_dec_init_fx( st ); } } @@ -576,7 +576,7 @@ ivas_error stereo_memory_dec_fx( move16(); len = NS2SA_FX2( st->output_Fs, 3000000 ); /* Q0 */ move16(); - Copy32( st->hHQ_core->oldOut_fx + nZeros, hCPE->output_mem_fx[1], len ); /* exp(exp_old_out) */ + Copy32( st->hHQ_core->old_out_fx32 + nZeros, hCPE->output_mem_fx[1], len ); /* exp(exp_old_out) */ } /* deallocated HQ-core for second channel */ @@ -626,16 +626,10 @@ ivas_error stereo_memory_dec_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); } - td_bwe_dec_init_ivas_fx( st, st->hBWE_TD, st->output_Fs ); + td_bwe_dec_init_fx( st->hBWE_TD, -1, st->output_Fs ); st->prev_Q_bwe_exc = 31; move16(); - st->prev_Qx = 0; - move16(); - st->prev_ener_fx_Q = 31; - move16(); - st->prev_frame_pow_exp = 0; - move16(); IF( ( st->hBWE_FD = (FD_BWE_DEC_HANDLE) malloc( sizeof( FD_BWE_DEC_DATA ) ) ) == NULL ) { @@ -643,19 +637,6 @@ ivas_error stereo_memory_dec_fx( } fd_bwe_dec_init_fx( st->hBWE_FD ); - set16_fx( st->prev_SWB_fenv_fx, 0, SWB_FENV ); - st->last_wb_bwe_ener_fx = 0; - move16(); - st->prev_fb_ener_adjust_fx = 0; - move16(); - - fd_bwe_dec_init( st, st->hBWE_FD ); - st->hBWE_FD->old_wtda_swb_fx_exp = 0; - move16(); - st->hBWE_FD->mem_imdct_exp_fx = 0; - move16(); - st->prev_Q_synth = 0; - move16(); } /* Allocated FD_CNG instance for primary channel*/ @@ -873,16 +854,10 @@ ivas_error stereo_memory_dec_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); } - td_bwe_dec_init_ivas_fx( st, st->hBWE_TD, st->output_Fs ); + td_bwe_dec_init_fx( st->hBWE_TD, -1, st->output_Fs ); st->prev_Q_bwe_exc = 31; move16(); - st->prev_Qx = 0; - move16(); - st->prev_ener_fx_Q = 31; - move16(); - st->prev_frame_pow_exp = 0; - move16(); IF( ( st->hBWE_FD = (FD_BWE_DEC_HANDLE) malloc( sizeof( FD_BWE_DEC_DATA ) ) ) == NULL ) { @@ -890,19 +865,6 @@ ivas_error stereo_memory_dec_fx( } fd_bwe_dec_init_fx( st->hBWE_FD ); - set16_fx( st->prev_SWB_fenv_fx, 0, SWB_FENV ); - st->last_wb_bwe_ener_fx = 0; - move16(); - st->prev_fb_ener_adjust_fx = 0; - move16(); - - fd_bwe_dec_init( st, st->hBWE_FD ); - st->hBWE_FD->old_wtda_swb_fx_exp = 0; - move16(); - st->hBWE_FD->mem_imdct_exp_fx = 0; - move16(); - st->prev_Q_synth = 0; - move16(); } } ELSE /* tdm_LRTD_flag == 0 */ @@ -1985,19 +1947,29 @@ void stereo_switching_dec( move16(); Copy( sts[0]->Q_subfr, sts[1]->Q_subfr, L_Q_MEM ); - sts[1]->prev_Q_bwe_syn = sts[0]->prev_Q_bwe_syn; - move16(); - sts[1]->prev_Q_bwe_syn2 = sts[0]->prev_Q_bwe_syn2; - move16(); + test(); + IF( sts[0]->hBWE_TD != NULL && sts[1]->hBWE_TD != NULL ) + { + sts[1]->hBWE_TD->prev_Q_bwe_syn = sts[0]->hBWE_TD->prev_Q_bwe_syn; + move16(); + sts[1]->hBWE_TD->prev_Q_bwe_syn2 = sts[0]->hBWE_TD->prev_Q_bwe_syn2; + move16(); + + sts[1]->hBWE_TD->prev_Q_bwe_exc_fb = sts[0]->hBWE_TD->prev_Q_bwe_exc_fb; + move16(); + sts[1]->hBWE_TD->prev_Qx = sts[0]->hBWE_TD->prev_Qx; + move16(); + } + + test(); + IF( sts[0]->hBWE_FD != NULL && sts[1]->hBWE_FD != NULL ) + { + sts[1]->hBWE_FD->prev_Q_synth = sts[0]->hBWE_FD->prev_Q_synth; + move16(); + } - sts[1]->prev_Q_bwe_exc_fb = sts[0]->prev_Q_bwe_exc_fb; - move16(); - sts[1]->prev_Qx = sts[0]->prev_Qx; - move16(); sts[1]->prev_Q_bwe_exc = sts[0]->prev_Q_bwe_exc; move16(); - sts[1]->prev_Q_synth = sts[0]->prev_Q_synth; - move16(); sts[1]->Q_syn = sts[0]->Q_syn; move16(); sts[1]->Q_syn2 = sts[0]->Q_syn2; @@ -2018,7 +1990,7 @@ void stereo_switching_dec( // 32bit buffer - Copy32( sts[0]->hHQ_core->oldOut_fx, sts[1]->hHQ_core->oldOut_fx, L_FRAME48k ); /* exp(exp_old_out) */ + Copy32( sts[0]->hHQ_core->old_out_fx32, sts[1]->hHQ_core->old_out_fx32, L_FRAME48k ); /* exp(exp_old_out) */ Copy32( sts[0]->delay_buf_out32_fx, sts[1]->delay_buf_out32_fx, HQ_DELTA_MAX * HQ_DELAY_COMP ); /* Q11 */ Copy32( sts[0]->hTcxDec->old_syn_Overl_32, sts[1]->hTcxDec->old_syn_Overl_32, 256 ); /* Q_old_syn_Overl*/ // 16 bit buffer @@ -2179,7 +2151,7 @@ void stereo_td2dft_update_fx( move16(); /* update buffers used for fading when switching to DFT Stereo */ - v_add_fx( sts[0]->hHQ_core->old_outLB_fx + nsLB, sts[1]->hHQ_core->old_outLB_fx + nsLB, hCPE->old_outLB_mdct_fx, old_outLB_len ); + v_add_fx( sts[0]->hHQ_core->old_out_LB_fx32 + nsLB, sts[1]->hHQ_core->old_out_LB_fx32 + nsLB, hCPE->old_outLB_mdct_fx, old_outLB_len ); L_lerp_fx_q11( hCPE->old_outLB_mdct_fx, hCPE->old_outLB_mdct_fx, STEREO_MDCT2DFT_FADE_LEN_48k, old_outLB_len ); #ifndef MSAN_FIX for ( i = 0; i < STEREO_MDCT2DFT_FADE_LEN_48k; i++ ) @@ -2190,7 +2162,7 @@ void stereo_td2dft_update_fx( hCPE->old_outLB_mdct_fx[i] = L_shr( hCPE->old_outLB_mdct_fx[i], 1 ); /* Q11 */ move32(); } - v_add_fx( sts[0]->hHQ_core->oldOut_fx + ns, sts[1]->hHQ_core->oldOut_fx + ns, hCPE->old_out_mdct_fx, old_out_len ); /* exp(exp_old_out) */ + v_add_fx( sts[0]->hHQ_core->old_out_fx32 + ns, sts[1]->hHQ_core->old_out_fx32 + ns, hCPE->old_out_mdct_fx, old_out_len ); /* exp(exp_old_out) */ #ifndef MSAN_FIX for ( int i = 0; i < STEREO_MDCT2DFT_FADE_LEN_48k; i++ ) #else diff --git a/lib_dec/ivas_tcx_core_dec_fx.c b/lib_dec/ivas_tcx_core_dec_fx.c index 07eba9e6420b1fb940e78273467317b8d61ae136..c187c351c462fe7ff3b8dcc5b1e91044a659c34d 100644 --- a/lib_dec/ivas_tcx_core_dec_fx.c +++ b/lib_dec/ivas_tcx_core_dec_fx.c @@ -639,18 +639,26 @@ void stereo_tcx_core_dec_fx( move16(); } /* waveform adjustment */ - concealment_signal_tuning_fx( bfi, st->core, synthFB_fx, &st->plcInfo, st->nbLostCmpt, st->prev_bfi, st->hTonalMDCTConc->secondLastPcmOut, st->last_core_bfi, st->hTonalMDCTConc->lastPcmOut, st ); + concealment_signal_tuning_fx( st, bfi, synthFB_fx, st->last_core_bfi ); test(); test(); test(); +#ifdef NONBE_FIX_1402_WAVEADJUST + IF( ( bfi || st->prev_bfi ) && st->hPlcInfo->Pitch_fx && EQ_16( st->hPlcInfo->concealment_method, TCX_NONTONAL ) ) +#else IF( ( bfi || st->prev_bfi ) && st->hPlcInfo->Pitch && EQ_16( st->hPlcInfo->concealment_method, TCX_NONTONAL ) ) +#endif { lerp( synthFB_fx, synth_fx, st->L_frame, hTcxDec->L_frameTCX ); if ( !bfi && st->prev_bfi ) { +#ifdef NONBE_FIX_1402_WAVEADJUST + st->hPlcInfo->Pitch_fx = 0; +#else st->hPlcInfo->Pitch = 0; +#endif move16(); } } diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index 56ffe39241e60f97f620e741969441c551f2d011..4135854479a9d968833714127c99c13762efa8f3 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -3396,7 +3396,7 @@ static ivas_error evs_dec_main_fx( move32(); hCoreCoder[0]->output_frame_fx = extract_l( Mult_32_16( hCoreCoder[0]->output_Fs, 0x0290 /*Q0*/ ) ); // Q0 move16(); - mdct_switching_dec_ivas_fx( hCoreCoder[0] ); + mdct_switching_dec_fx( hCoreCoder[0] ); FOR( ch = 0; ch < MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN; ch++ ) { diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index 530cd41d0fed9de98c364a56729a24119db8dc23..712ead8f460687baf4d0335122614e075e08e681 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -58,21 +58,7 @@ typedef enum FRAMEMODE_NORMAL = 0x0, /* frame available */ FRAMEMODE_MISSING = 0x1, /* frame missing => conceal */ FRAMEMODE_FUTURE = 0x2 -} FRAME_MODE, - frameMode_fx; - -typedef enum -{ - TONALMDCTCONCEAL_OK = 0, - - __error_codes_start = -100, - - TONALMDCTCONCEAL_NSAMPLES_LARGER_THAN_MAXBLOCKSIZE, - TONALMDCTCONCEAL_INVALIDPOINTER, - TONALMDCTCONCEAL_UNEXPECTED_ERROR, - - __error_codes_end -} TONALMDCTCONCEAL_ERROR; +} FRAME_MODE; /*---------------------------------------------------------------* @@ -174,12 +160,14 @@ typedef struct typedef struct { Word16 L_frameTCX; - Word16 FrameSize; +#ifndef NONBE_FIX_1402_WAVEADJUST Word16 Pitch; +#endif Word16 Pitch_fx; - +#ifndef NONBE_FIX_1402_WAVEADJUST Word16 T_bfi; +#endif Word8 T_bfi_fx; Word16 Transient[MAX_POST_LEN]; @@ -194,18 +182,16 @@ typedef struct Word32 ener_mean_fx; Word32 ener_fx; - Word16 zp; Word16 zp_fx; Word16 recovery_gain; /*outside waveformadjustment: Q14 - insinde waveformadjustment: Q15*/ Word16 step_concealgain_fx; Word16 concealment_method; - +#ifndef NONBE_FIX_1402_WAVEADJUST Word16 subframe; +#endif Word16 subframe_fx; - Word16 nbLostCmpt; - Word16 seed; } T_PLCInfo, *T_PLCInfo_HANDLE; @@ -219,17 +205,12 @@ typedef struct { UWord16 nSamples; UWord16 nSamplesCore; - - Float32 *spectralData_float; Word16 *spectralData; - Word16 spectralData_exp; Word16 *scaleFactors; - Word16 *scaleFactors_exp; Word16 scaleFactors_max_e; Word16 gain_tcx_exp; - Word16 blockIsValid; Word16 blockIsConcealed; Word16 tonalConcealmentActive; @@ -241,9 +222,7 @@ typedef struct UWord16 indexOfTonalPeak[MAX_NUMBER_OF_IDX]; UWord16 lowerIndex[MAX_NUMBER_OF_IDX]; UWord16 upperIndex[MAX_NUMBER_OF_IDX]; - - Word16 phaseDiff[MAX_NUMBER_OF_IDX]; // Q12 /* This one can be stored with 16 bits in range 0..2*PI */ - + Word16 phaseDiff[MAX_NUMBER_OF_IDX]; // Q12 /* This one can be stored with 16 bits in range 0..2*PI */ Word16 phase_currentFramePredicted[MAX_NUMBER_OF_IDX * GROUP_LENGTH]; // Q13 /* This one can be stored with 16 bits in range [-pi;pi] 2Q13, but the code has to be adapted to use moduo(2*PI) after adding */ } TonalComponentsInfo; @@ -262,21 +241,13 @@ typedef struct tonalmdctconceal blockData secondLastBlockData; Word16 scaleFactorsBuffers[2][FDNS_NPTS]; /* Contains also global gain. */ - Word16 scaleFactorsBuffers_exp[2][FDNS_NPTS]; - - Word16 spectralDataBuffers[2][L_FRAME_MAX]; /* 16 bits is enough, because it is stored before applying scale factors. Take care that power spectrum is also stored here. */ - + Word16 spectralDataBuffers[2][L_FRAME_MAX]; /* 16 bits is enough, because it is stored before applying scale factors. Take care that power spectrum is also stored here. */ Word16 timeDataBuffer[( 3 * L_FRAME_MAX ) / 2]; /* 16 bits are enough for the TD signal */ - Word16 *lastPcmOut; - Word16 *secondLastPcmOut; - Word16 q_lastPcmOut; - Word16 *secondLastPowerSpectrum; - Word16 secondLastPowerSpectrum_exp; Word32 scaleFactorsBackground_fx[FDNS_NPTS]; @@ -292,6 +263,7 @@ typedef struct tonalmdctconceal Word16 faded_signal_nrg_exp; Word16 nFramesLost; TonalComponentsInfo *pTCI; + } TonalMDCTConceal_INSTANCE, *TonalMDCTConcealPtr; @@ -396,8 +368,6 @@ typedef struct igfdec_instance_struct typedef struct tec_dec_structure { - - // fixed variable Word16 pGainTemp_m[CLDFB_NO_COL_MAX]; Word16 pGainTemp_e[CLDFB_NO_COL_MAX]; Word16 loBuffer[CLDFB_NO_COL_MAX + MAX_TEC_SMOOTHING_DEG]; @@ -426,12 +396,9 @@ typedef struct tcx_ltp_dec_structure Word32 tcxltp_mem_out_32[L_FRAME48k]; Word16 exp_tcxltp_mem_out; - Word16 tcxltp_pitch_int_post_prev; Word16 tcxltp_pitch_fr_post_prev; - Word16 tcxltp_gain_post_prev; - Word16 tcxltp_filt_idx_prev; } TCX_LTP_DEC_DATA, *TCX_LTP_DEC_HANDLE; @@ -483,7 +450,6 @@ typedef struct tcx_dec_structure Word16 FBTCXdelayBuf[111]; /* 2.3125ms at 48kHz -> 111 samples */ Word32 FBTCXdelayBuf_32[111]; /* 2.3125ms at 48kHz -> 111 samples */ - /*TCX resisual Q*/ Word16 resQBits[NB_DIV]; /* number of bits read for the residual Quantization in TCX*/ @@ -519,7 +485,6 @@ typedef struct tcx_dec_structure Word16 tcxConceal_recalc_exc; Word16 cummulative_damping_tcx; // Q15 - } TCX_DEC_DATA, *TCX_DEC_HANDLE; @@ -557,39 +522,43 @@ typedef struct WI_dec_structure /*----------------------------------------------------------------------------------* - * LD music post-filter + * NB postfilter / formant postfilter static variables *----------------------------------------------------------------------------------*/ -typedef struct ld_music_postfilt_structure +typedef struct pfstat_structure { - Word16 LDm_mem_etot_fx; /* LD music post-filter - total energy memory */ + Word16 on; /* On/off flag */ + Word16 reset; /* reset flag */ + Word16 mem_pf_in[L_SUBFR]; /* Input memory Qqmem_pf_in */ + Word16 mem_stp[L_SUBFR]; /* 1/A(gamma1) memory Qqmem_stp*/ + Word16 mem_res2[DECMEM_RES2]; /* A(gamma2) residual Q_syn*/ + Word16 mem_zero[M]; /* null memory to compute i.r. of A(gamma2)/A(gamma1) Q_qmem_zero*/ + Word16 gain_prec; /*Q14*/ /* for gain adjustment */ - Word16 LDm_last_music_flag; /* LD music post-filter - last music flag */ +} PFSTAT, *PFSTAT_HANDLE; - Word16 LDm_nb_thr_1; /* LD music post-filter - number of consecutive frames of level 1 */ - Word16 LDm_nb_thr_3; +/*----------------------------------------------------------------------------------* + * LD music post-filter + *----------------------------------------------------------------------------------*/ +typedef struct ld_music_postfilt_structure +{ + Word16 LDm_mem_etot_fx; /* LD music post-filter - total energy memory */ + Word16 LDm_last_music_flag; /* LD music post-filter - last music flag */ + Word16 LDm_nb_thr_1; /* LD music post-filter - number of consecutive frames of level 1 */ + Word16 LDm_nb_thr_3; Word16 dct_post_old_exc_fx[DCT_L_POST - OFFSET2]; - - Word16 LDm_thres_fx[4]; /* LD music post-filter - Classification threshold */ - - Word16 LDm_lt_diff_etot_fx[MAX_LT]; /* LD music post-filter - long-term total energy variation */ - + Word16 LDm_thres_fx[4]; /* LD music post-filter - Classification threshold */ + Word16 LDm_lt_diff_etot_fx[MAX_LT]; /* LD music post-filter - long-term total energy variation */ Word16 LDm_enh_lp_gbin_fx[VOIC_BINS_HR]; /* LD music post-filter - smoothed suppression gain, per bin FFT */ - - Word32 LDm_enh_lf_EO_fx[VOIC_BINS_HR]; /* LD music post-filter - old per bin E for previous half frame */ - - Word16 LDm_enh_min_ns_gain_fx; /* LD music post-filter - minimum suppression gain */ - - Word32 LDm_bckr_noise_fx[MBANDS_GN_LD]; /* LD music post-filter - background noise estimation per critical band */ + Word32 LDm_enh_lf_EO_fx[VOIC_BINS_HR]; /* LD music post-filter - old per bin E for previous half frame */ + Word16 LDm_enh_min_ns_gain_fx; /* LD music post-filter - minimum suppression gain */ + Word32 LDm_bckr_noise_fx[MBANDS_GN_LD]; /* LD music post-filter - background noise estimation per critical band */ Word16 filt_lfE_fx[DCT_L_POST]; - Word16 last_nonfull_music; - Word16 Old_ener_Q; /* Old energy scaling factor */ - } MUSIC_POSTFILT_DATA, *MUSIC_POSTFILT_HANDLE; /*----------------------------------------------------------------------------------* @@ -600,18 +569,13 @@ typedef struct bass_postfilt_structure { Word16 pst_old_syn_fx[NBPSF_PIT_MAX]; /* Bass post-filter - old synthesis buffer 1 Q_syn2-1*/ Word16 q_pst_old_syn; - Word16 pst_mem_deemp_err_fx; /* Bass post-filter - filter memory of noise LP filter Q_syn2-1*/ - - Word16 pst_lp_ener_fx; /* Bass post-filter - long-term energy Q8*/ - - Word16 Track_on_hist[L_TRACK_HIST]; /* Bass post-filter - History of half frame usage */ - + Word16 pst_mem_deemp_err_fx; /* Bass post-filter - filter memory of noise LP filter Q_syn2-1*/ + Word16 pst_lp_ener_fx; /* Bass post-filter - long-term energy Q8*/ + Word16 Track_on_hist[L_TRACK_HIST]; /* Bass post-filter - History of half frame usage */ Word16 vibrato_hist[L_TRACK_HIST]; /* Bass post-filter - History of frames declared as vibrato */ - // Word16 vibrato_hist[L_TRACK_HIST]; /* Bass post-filter - History of frames declared as vibrato */ Word16 psf_att_fx; /* Bass post-filter - post filter attenuation factor */ Word16 mem_mean_pit_fx[L_TRACK_HIST]; /* Bass post-filter - average pitch memory */ - } BPF_DEC_DATA, *BPF_DEC_HANDLE; /*------------------------------------------------------------------------------------------* @@ -620,75 +584,54 @@ typedef struct bass_postfilt_structure typedef struct td_cng_dec_structure { - Word16 cng_seed; /* DTX/CNG - seed for white noise random generator */ - // Word16 cng_seed; /*CNG and DTX - seed for white noise random generator*/ - Word32 Enew_fx; /* CNG and DTX - decoded residual energy Q6*/ - + Word16 cng_seed; /* DTX/CNG - seed for white noise random generator */ + Word32 Enew_fx; /* CNG and DTX - decoded residual energy Q6*/ Word16 old_enr_index; /* DTX/CNG - index of last encoded CNG energy */ - Word16 cng_ener_seed; /* DTX/CNG - seed for random generator for variation of excitation energy */ - Word16 cng_ener_seed1; - Word16 last_allow_cn_step; - - Word16 ho_hist_size; /* DTX/CNG - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ - - Word16 ho_hist_ptr; /* DTX/CNG - pointer for averaging buffers */ - + Word16 ho_hist_size; /* DTX/CNG - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ + Word16 ho_hist_ptr; /* DTX/CNG - pointer for averaging buffers */ Word32 ho_sid_bw; /* DTX/CNG - SID bandwidth flags */ - // Word32 ho_sid_bw; /* CNG and DTX - SID bandwidth flags */ Word16 ho_lsp_hist_fx[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ Word32 ho_ener_hist_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ /*Q6 */ Word32 ho_env_hist_fx[HO_HIST_SIZE * NUM_ENV_CNG]; - - - Word16 act_cnt; /* DTX/CNG - counter of active frames */ - - Word16 ho_circ_size; /* DTX/CNG - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ - - Word16 ho_circ_ptr; /* DTX/CNG - pointer for averaging buffers */ - // Word16 ho_circ_ptr; /* CNG and DTX - pointer for averaging buffers */ - + Word16 act_cnt; /* DTX/CNG - counter of active frames */ + Word16 ho_circ_size; /* DTX/CNG - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ + Word16 ho_circ_ptr; /* DTX/CNG - pointer for averaging buffers */ Word16 ho_lsp_circ_fx[HO_HIST_SIZE * M]; /* CNG and DTX - old LSP buffer for averaging */ Word32 ho_ener_circ_fx[HO_HIST_SIZE]; /* CNG and DTX - energy buffer for averaging */ /* Q6 */ Word32 ho_env_circ_fx[HO_HIST_SIZE * NUM_ENV_CNG]; - - - Word16 num_ho; /* DTX/CNG - number of selected hangover frames */ - + Word16 num_ho; /* DTX/CNG - number of selected hangover frames */ Word16 ho_16k_lsp[HO_HIST_SIZE]; /* DTX/CNG - 16k LSPs flags */ - // Word16 ho_16k_lsp[HO_HIST_SIZE]; /* DTX/CNG - 16k LSPs flags */ - - - Word16 act_cnt2; /* DTX/CNG - counter of active frames for CNG_mode switching */ - // Word16 act_cnt2; /* DTX/CNG - counter of active frames for CNG_mode switching */ + Word16 act_cnt2; /* DTX/CNG - counter of active frames for CNG_mode switching */ Word32 old_env_fx[20]; Word32 lp_env_fx[20]; Word16 exc_mem_fx[24]; Word16 exc_mem1_fx[30]; + Word16 interpol_3_2_cng_dec_fx[INTERP_3_2_MEM_LEN]; + + /* SWB DTX/CNG parameters */ + Word16 shb_cng_ener_fx; + Word32 shb_cng_ener_fx_32; // Q(11) Word16 shb_lpcCNG_fx[LPC_SHB_ORDER + 1]; /* Assumed in Q12 */ Word16 shb_cng_gain_fx; /* Assumed in Q8 */ + Word32 shb_cng_gain_fx_32; // Q(11) + Word16 wb_cng_ener_fx; + Word32 wb_cng_ener_fx_32; // Q(11) + Word16 last_wb_cng_ener_fx; + Word32 last_wb_cng_ener_fx_32; // Q(11) + Word16 last_shb_cng_ener_fx; + Word32 last_shb_cng_ener_fx_32; // Q(11) Word16 swb_cng_seed; - Word16 shb_dtx_count; - Word16 trans_cnt; - - Word16 interpol_3_2_cng_dec_fx[INTERP_3_2_MEM_LEN]; - - Word32 shb_cng_ener_fx_32; // Q(11) - Word32 shb_cng_gain_fx_32; // Q(11) - Word32 wb_cng_ener_fx_32; // Q(11) - Word32 last_wb_cng_ener_fx_32; // Q(11) - Word32 last_shb_cng_ener_fx_32; // Q(11) Word16 lsp_shb_prev_fx[LPC_SHB_ORDER]; // Q(14) Word16 lsp_shb_prev_prev_fx[LPC_SHB_ORDER]; // Q(14) - - Word16 burst_cnt; - Word32 last_shb_ener_fx; // Q(11) - - Word16 last_cng_type_fx; /* DTX/CNG - flag indicating last frame LP or CLDFB based SID/CNG */ - + Word16 shb_dtx_count_fx; + Word16 trans_cnt_fx; + Word16 burst_cnt_fx; + Word16 last_shb_ener_fx; + Word32 last_shb_ener_fx_32; // Q(11) } TD_CNG_DEC_DATA, *TD_CNG_DEC_HANDLE; @@ -704,36 +647,27 @@ typedef struct sc_vbr_dec_structure /* DTFS variables */ Word16 dtfs_dec_a_fx[MAXLAG_WI]; /*Variable Q format in dtfs_dec_Q*/ Word16 dtfs_dec_b_fx[MAXLAG_WI]; /*Variable Q format in dtfs_dec_Q*/ - Word16 dtfs_dec_lag; - Word16 dtfs_dec_nH; - Word16 dtfs_dec_nH_4kHz; - Word16 dtfs_dec_upper_cut_off_freq_of_interest_fx; /*Q0*/ Word16 dtfs_dec_upper_cut_off_freq_fx; /*Q0*/ Word16 ph_offset_D_fx; /* normalized by 2Pi Q15*/ Word16 lastLgainD_fx; /* previous gain value for the low band Q11*/ Word16 lastHgainD_fx; /* previous gain value for the high band Q11 */ Word16 lasterbD_fx[NUM_ERB_WB]; /* previous amplitude spectrum (ERB) Q13*/ - - Word16 dtfs_dec_Q; /*Q0*/ + Word16 dtfs_dec_Q; /*Q0*/ /* NELP decoder variables */ Word32 bp1_filt_mem_nb_dec_fx[14]; /* qfm currently Q0*/ Word16 bp1_filt_mem_wb_dec_fx[8]; /* qfm currently Q0*/ Word16 shape1_filt_mem_dec_fx[10]; /* qfm currently Q0*/ Word16 shape2_filt_mem_dec_fx[10]; /* qfm currently Q0*/ - Word16 shape3_filt_mem_dec_fx[10]; /* qfm currently Q0*/ - Word16 nelp_dec_seed; - Word16 FadeScale_fx; /*Q15*/ - } SC_VBR_DEC_DATA, *SC_VBR_DEC_HANDLE; /*----------------------------------------------------------------------------------* @@ -743,46 +677,24 @@ typedef struct sc_vbr_dec_structure typedef struct hq_nbfec_structure { Word16 prev_last_core; /* !!! note: the parameter is identical to last_core in IVAS */ - // Word16 prev_last_core; /* !!! note: the parameter is identical to last_core in IVAS */ Word16 diff_energy_fx; - Word16 stat_mode_out; - Word16 stat_mode_old; - - Word16 phase_mat_flag; - Word16 phase_mat_next; - Word16 old_Min_ind; - Word16 old_auOut_2fr_fx[L_FRAME8k * 2]; - Word16 old_out_pha_fx[2][N_LEAD_NB]; /* FEC for HQ Core, 0-phase matching old_out, 1-overlapping original old_out and phase matching old_out*/ - Word32 ynrm_values_fx[MAX_SB_NB][MAX_PGF]; - Word32 r_p_values_fx[MAX_SB_NB][MAX_ROW]; - Word16 Norm_gain_fx[SFM_N_NB]; - - /*Word16 old_hqswb_clas;*/ /* only used in inactive code, where it might probably be replaced by old_hqswb_clas_fx */ - - Word16 HQ_FEC_seed; - Word16 energy_MA_Curr_fx[2]; - Word16 prev_sign_switch[HQ_FEC_SIGN_SFM]; - Word16 prev_sign_switch_2[HQ_FEC_SIGN_SFM]; - Word32 old_coeffs_fx[L_FRAME8k]; /* HQ core - old coefficients (for FEC) */ - Word32 oldIMDCTout_fx[L_FRAME8k / 2]; - Word16 prev_oldauOut_fx[L_FRAME8k]; @@ -794,86 +706,52 @@ typedef struct hq_nbfec_structure typedef struct hq_dec_structure { - - Word32 oldOut_fx[L_FRAME48k]; /* HQ core - previous synthesis for OLA */ - Word16 old_out_fx[L_FRAME48k]; /* HQ core - previous synthesis for OLA */ + Word32 old_out_fx32[L_FRAME48k]; /* HQ core - previous synthesis for OLA */ + Word16 old_out_fx[L_FRAME48k]; /* HQ core - previous synthesis for OLA */ Word16 exp_old_out; - Word16 old_out_LB_fx[L_FRAME32k]; /* HQ core - previous synthesis for OLA for Low Band */ - Word32 old_outLB_fx[L_FRAME32k]; + Word32 old_out_LB_fx32[L_FRAME32k]; Word16 q_old_outLB_fx; - Word16 Q_old_wtda_LB; Word16 Q_old_wtda; Word16 Q_old_postdec; /*scaling of the output of core_switching_post_dec_fx() */ - Word16 last_hq_core_type; - Word16 old_is_transient[3]; /* HQ core - previous transient flag (for FEC) */ Word16 mem_norm[SFM_N_ENV_STAB]; /* Q0 */ - - Word16 mem_env_delta; /* Q11 */ - - Word16 no_att_hangover; /* Q0 */ - - Word32 energy_lt_fx; /* Q13 */ - + Word16 mem_env_delta; /* Q11 */ + Word16 no_att_hangover; /* Q0 */ + Word32 energy_lt_fx; /* Q13 */ Word16 hq_generic_seed; - Word16 prev_noise_level_fx[2]; /* Q15 */ - Word16 prev_hqswb_clas; - - Word16 prev_R; /* the table of bit allocation of last frame */ - - Word16 prev_SWB_peak_pos[SPT_SHORTEN_SBNUM]; - + Word16 prev_R; /* the table of bit allocation of last frame */ Word32 prev_coeff_out_fx[L_HQ_WB_BWE]; /* Q12 */ /* the coefficients of last frame */ Word16 prev_SWB_peak_pos_fx[SPT_SHORTEN_SBNUM]; - Word16 HqVoicing; Word16 fer_samples_fx[L_FRAME48k]; Word16 Q_fer_samples; Word32 prev_normq_fx[SFM_N_WB]; /* Q14 */ /* previous norms */ - - - Word32 prev_env_fx[SFM_N_WB]; /* previous noise envelopes */ - + Word32 prev_env_fx[SFM_N_WB]; /* previous noise envelopes */ Word16 prev_env_Q[SFM_N_WB]; - Word32 last_ni_gain_fx[BANDS_MAX]; - Word16 last_env_fx[BANDS_MAX]; - Word16 last_max_pos_pulse; /* pre-echo reduction */ - Word16 memfilt_lb_fx; /* Q0 */ - + Word16 memfilt_lb_fx; /* Q0 */ Word32 mean_prev_hb_fx; /* Q0 */ - - Word16 smoothmem_fx; /* Q15 */ - - Word32 mean_prev_fx; /* Q0 */ - + Word16 smoothmem_fx; /* Q15 */ + Word32 mean_prev_fx; /* Q0 */ Word32 mean_prev_nc_fx; /* Q0 */ - - Word16 wmold_hb_fx; /* Q15 */ - + Word16 wmold_hb_fx; /* Q15 */ Word16 prevflag; - Word16 pastpre; - - Word16 prev_frm_hfe2; - Word16 prev_stab_hfe2; - - Word16 prev_ni_ratio_fx; /* 15 */ - + Word16 prev_ni_ratio_fx; /* 15 */ Word16 prev_En_sb_fx[NB_SWB_SUBBANDS]; /* QsEn(4) */ /*----------------------------------------------------------------------------------* @@ -882,50 +760,30 @@ typedef struct hq_dec_structure /* HQ PHASE ECU internal state */ Word16 time_offs; - Word16 X_sav_fx[PH_ECU_SPEC_SIZE]; - Word16 Q_X_sav; - Word16 num_p; - Word16 plocs[MAX_PLOCS]; - Word32 plocsi_fx[MAX_PLOCS]; - Word16 env_stab_fx; - Word16 mem_norm_hqfec[SFM_N_ENV_STAB]; - Word16 mem_env_delta_hqfec; - Word16 env_stab_plc_fx; - Word16 env_stab_state_p_fx[NUM_ENV_STAB_PLC_STATES]; - Word16 envstabplc_hocnt; Word16 mag_chg_1st_fx[LGW_MAX]; /* i/o: per band magnitude modifier for transients*/ - - Word16 Xavg_fx[LGW_MAX]; /* Frequency group average gain to fade to */ - - Word16 beta_mute_fx; /* Factor for long-term mute */ + Word16 Xavg_fx[LGW_MAX]; /* Frequency group average gain to fade to */ + Word16 beta_mute_fx; /* Factor for long-term mute */ Word16 last_fec; - Word16 ph_ecu_HqVoicing; - Word16 oldHqVoicing; - Word16 oldgapsynth_fx[L_FRAME48k]; - Word16 ph_ecu_active; /* Set if Phase ECU was used in last bad frame */ - Word16 ni_seed_forfec; - Word16 ber_occured_in_pvq; /* flag for BER detection from PVQ routines */ - } HQ_DEC_DATA, *HQ_DEC_HANDLE; @@ -935,20 +793,15 @@ typedef struct hq_dec_structure typedef struct zero_bwe_dec_structure { - Word16 seed2; /* HF (6-7kHz) BWE - seed for random signal generator */ - - - Word16 mem_hp400_fx[6]; /* HF (6-7kHz) BWE - hp400 filter memory */ - Word16 q_mem_hp400_fx; - - Word16 mem_hf_fx[2 * L_FILT16k]; /* HF (6-7kHz) BWE - band-pass filter memory Q(-2-memExp1)*/ - - Word16 mem_syn_hf_fx[M]; /* HF (6-7kHz) BWE - synthesis filter memory Q0*/ - + Word16 seed2; /* HF (6-7kHz) BWE - seed for random signal generator */ + Word16 mem_hp400_fx[6]; /* HF (6-7kHz) BWE - hp400 filter memory */ + Word16 q_mem_hp400_fx; /* Exponent for mem_hp400_fx[] scaling */ + Word16 mem_hf_fx[2 * L_FILT16k]; /* HF (6-7kHz) BWE - band-pass filter memory Q(-2-memExp1)*/ + Word16 mem_syn_hf_fx[M]; /* HF (6-7kHz) BWE - synthesis filter memory Q0 */ Word16 delay_syn_hf_fx[NS2SA( 16000, DELAY_CLDFB_NS )]; /* HF (6-7kHz) BWE - To synchronise BWE content with postfiltered synthesis Q0*/ + Word16 mem_hp_interp_fx[INTERP_3_1_MEM_LEN]; /* HF (6-7 kHz) BWE - interp. memory */ + Word16 memExp1; /* Exponent for mem_hf_fx scaling */ - Word16 mem_hp_interp_fx[INTERP_3_1_MEM_LEN]; /* HF (6-7 kHz) BWE - interp. memory */ - Word16 memExp1; /* Exponent for mem_hf_fx scaling*/ } ZERO_BWE_DEC_DATA, *ZERO_BWE_DEC_HANDLE; @@ -960,147 +813,104 @@ typedef struct td_bwe_dec_structure { /* states for the filters used in generating SHB excitation from WB excitation */ Word16 state_lpc_syn_fx[LPC_SHB_ORDER]; - Word32 mem_csfilt_fx[2]; /* states for the filters used in generating SHB signal from SHB excitation*/ Word16 state_syn_shbexc_fx[L_SHB_LAHEAD]; - Word16 syn_overlap_fx[L_SHB_LAHEAD]; /* overlap buffer used to Adjust SHB Frame Gain*/ - Word32 syn_overlap_fx_32[L_SHB_LAHEAD]; /* overlap buffer used to Adjust SHB Frame Gain*/ + Word32 syn_overlap_fx_32[L_SHB_LAHEAD]; /* overlap buffer used to Adjust SHB Frame Gain, IVAS 32-bit variant */ /* previous frame parameters for frame error concealment */ Word16 lsp_prevfrm_fx[LPC_SHB_ORDER]; - Word32 GainFrame_prevfrm_fx; - Word16 GainShape_Delay_fx[NUM_SHB_SUBFR / 2]; - Word16 GainAttn_fx; - Word16 old_bwe_exc_fx[PIT16k_MAX * 2]; /*Q_exc*/ - Word16 bwe_seed[2]; - Word32 bwe_non_lin_prev_scale_fx; - Word16 old_bwe_exc_extended_fx[NL_BUFF_OFFSET]; - Word32 genSHBsynth_Hilbert_Mem_fx[HILBERT_MEM_SIZE]; Word16 mem_genSHBexc_filt_down_shb_fx[2 * ALLPASSSECTIONS_STEEP + 1]; - Word16 mem_genSHBexc_filt_down_wb2_fx[2 * ALLPASSSECTIONS_STEEP + 1]; - Word16 mem_genSHBexc_filt_down_wb3_fx[2 * ALLPASSSECTIONS_STEEP + 1]; - Word16 genSHBsynth_state_lsyn_filt_shb_local_fx[2 * ALLPASSSECTIONS_STEEP]; - Word32 genSHBsynth_state_lsyn_filt_shb_local_fx_32[2 * ALLPASSSECTIONS_STEEP]; - + Word32 genSHBsynth_state_lsyn_filt_shb_local_fx_32[2 * ALLPASSSECTIONS_STEEP]; /* IVAS 32-bit variant */ Word16 state_lsyn_filt_shb_fx[2 * ALLPASSSECTIONS_STEEP]; - Word32 state_lsyn_filt_shb_fx_32[2 * ALLPASSSECTIONS_STEEP]; - + Word32 state_lsyn_filt_shb_fx_32[2 * ALLPASSSECTIONS_STEEP]; /* IVAS 32-bit variant */ Word16 state_lsyn_filt_dwn_shb_fx[2 * ALLPASSSECTIONS_STEEP]; - Word32 state_lsyn_filt_dwn_shb_fx_32[2 * ALLPASSSECTIONS_STEEP]; - + Word32 state_lsyn_filt_dwn_shb_fx_32[2 * ALLPASSSECTIONS_STEEP]; /* IVAS 32-bit variant */ Word16 mem_resamp_HB_fx[INTERP_3_1_MEM_LEN]; - Word32 mem_resamp_HB_fx_32[INTERP_3_1_MEM_LEN]; - + Word32 mem_resamp_HB_fx_32[INTERP_3_1_MEM_LEN]; /* IVAS 32-bit variant */ Word16 mem_resamp_HB_32k_fx[2 * ALLPASSSECTIONS_STEEP + 1]; - Word32 mem_resamp_HB_32k_fx_32[2 * ALLPASSSECTIONS_STEEP + 1]; + Word32 mem_resamp_HB_32k_fx_32[2 * ALLPASSSECTIONS_STEEP + 1]; /* IVAS 32-bit variant */ + Word32 prev_pow_exc16kWhtnd_fx32; /* power of the LB excitation signal in the previous frame */ + Word16 prev_mix_factor_fx; /* mixing factor in the previous frame */ Word16 state_32and48k_WB_upsample_fx[2 * ALLPASSSECTIONS_STEEP]; /* !!! this memory in FLP is called mem_resamp_HB */ - Word32 prev_pow_exc16kWhtnd_fx32; /* power of the LB excitation signal in the previous frame */ - Word16 prev_mix_factor_fx; /* mixing factor in the previous frame */ - Word16 syn_dm_phase; - Word32 fbbwe_hpf_mem_fx[4][4]; - Word16 fbbwe_hpf_mem_fx_Q[4]; - Word32 prev_wb_bwe_frame_pow_fx; - Word32 prev_swb_bwe_frame_pow_fx; - Word32 prev_ener_fx; - Word16 prev_GainShape_fx; - Word16 fb_state_lpc_syn_fx[LPC_SHB_ORDER]; - Word16 fb_tbe_demph_fx; - Word16 prev_fbbwe_ratio_fx; - Word16 tbe_demph_fx; - Word16 tbe_premph_fx; - Word16 mem_stp_swb_fx[LPC_SHB_ORDER]; - Word16 *ptr_mem_stp_swb_fx; - Word16 gain_prec_swb_fx; - Word16 mem_zero_swb_fx[LPC_SHB_ORDER]; Word16 swb_lsp_prev_interp_fx[LPC_SHB_ORDER]; - Word32 prev1_shb_ener_sf_fx, prev2_shb_ener_sf_fx, prev3_shb_ener_sf_fx; - Word16 prev_res_shb_gshape_fx, prev_mixFactors_fx; - Word16 tilt_mem_fx; - Word16 prev_lsf_diff_fx[LPC_SHB_ORDER - 2]; /*Q15*/ - - Word16 prev_tilt_para_fx; /*Q10*/ - - Word16 cur_sub_Aq_fx[M + 1]; /*Q12*/ - + Word16 prev_tilt_para_fx; /*Q10*/ + Word16 cur_sub_Aq_fx[M + 1]; /*Q12*/ /* quantized data */ Word16 lsf_idx[NUM_Q_LSF]; - Word16 m_idx; - Word16 grid_idx; - Word16 idxSubGains; - Word16 idxFrameGain; - Word16 idx_shb_fr_gain; - Word16 idx_res_gs[NB_SUBFR16k]; - Word16 idx_mixFac; Word16 lsf_WB; - Word16 gFrame_WB; Word16 idxGain; Word16 old_core_synth_fx[L_FRAME16k]; - Word16 old_tbe_synth_fx[L_SHB_TRANSITION_LENGTH]; - Word32 old_tbe_synth_fx_32[L_SHB_TRANSITION_LENGTH]; + Word32 old_tbe_synth_fx_32[L_SHB_TRANSITION_LENGTH]; /* IVAS 32-bit variant */ Word16 int_3_over_2_tbemem_dec_fx[INTERP_3_2_MEM_LEN]; - Word32 int_3_over_2_tbemem_dec_fx_32[INTERP_3_2_MEM_LEN]; + Word32 int_3_over_2_tbemem_dec_fx_32[INTERP_3_2_MEM_LEN]; /* IVAS 32-bit variant */ Word16 old_hb_synth_fx[L_FRAME48k]; Word16 tilt_swb_fec_fx; /* FEC - SWB TBE TILT */ Word16 prev_hb_synth_fx_exp; - + Word16 prev_frame_pow_exp; + Word16 prev_ener_fx_Q; + Word16 prev_lpc_wb_fx[LPC_SHB_ORDER_WB]; + Word16 prev_Q_bwe_syn; + Word16 prev_Q_bwe_syn2; + Word16 prev_Q_bwe_exc_fb; + Word16 prev_Qx; } TD_BWE_DEC_DATA, *TD_BWE_DEC_HANDLE; @@ -1110,42 +920,27 @@ typedef struct td_bwe_dec_structure typedef struct fd_bwe_dec_structure { - Word16 old_wtda_wb_fx_exp; - Word16 L_old_wtda_swb_fx[L_FRAME48k]; Word32 L_old_wtda_swb_fx32[L_FRAME48k]; - Word16 old_wtda_swb_fx_exp; - Word16 old_syn_12k8_16k_fx[NS2SA( 16000, DELAY_FD_BWE_ENC_NS )]; /*Q_syn2-1*/ - Word16 mem_deemph_old_syn_fx; - Word16 prev_mode; - - + Word16 prev_SWB_fenv_fx[SWB_FENV]; Word16 prev_Energy_fx; - Word32 prev_Energy_wb_fx; - Word16 prev_L_swb_norm; - Word16 Seed; - Word16 memExp1; - Word16 prev_frica_flag; - Word16 mem_imdct_fx[L_FRAME48k]; - Word16 mem_imdct_exp_fx; - Word16 prev_td_energy_fx; - Word16 prev_weight_fx; - Word16 prev_flag; - + Word16 last_wb_bwe_ener_fx; + Word16 prev_Q_synth; + Word16 prev_fb_ener_adjust_fx; } FD_BWE_DEC_DATA, *FD_BWE_DEC_HANDLE; @@ -1156,22 +951,13 @@ typedef struct fd_bwe_dec_structure typedef struct hr_swb_bwe_dec_structure { - - Word16 bwe_highrate_seed; Word16 bwe_highrate_seed_fx; - Word16 t_audio_prev_fx[2 * END_FREQ_BWE_FULL_FB / 50 - NUM_NONTRANS_START_FREQ_COEF]; - Word16 t_audio_prev_fx_exp[NUM_TIME_SWITCHING_BLOCKS]; - - Word16 old_is_transient_hr_bwe; Word16 old_is_transient_hr_bwe_fx; - Word32 L_mem_EnergyLT_fx; - Word16 mem_EnergyLT_fx_exp; - } HR_BWE_DEC_DATA, *HR_BWE_DEC_HANDLE; @@ -1199,45 +985,26 @@ typedef struct amrwb_io_dec_structure { Word16 past_qua_en_fx[GAIN_PRED_ORDER]; /* gain quantization memory (used also in AMR-WB IO mode) */ - Word16 prev_r_fx; /* HF BWE - previous sub-frame gain */ - - Word16 fmerit_w_sm_fx; /* HF BWE - fmerit parameter memory */ - - Word16 frame_count; /* HF BWE - frame count */ - Word16 frame_count_fx; /* HF BWE - frame count */ - Word16 ne_min_fx; /* HF BWE - minimum Noise gate - short-term energy */ - - Word16 fmerit_m_sm_fx; /* HF BWE - memory of fmerit_m param */ - + Word16 prev_r_fx; /* HF BWE - previous sub-frame gain */ + Word16 fmerit_w_sm_fx; /* HF BWE - fmerit parameter memory */ + Word16 frame_count_fx; /* HF BWE - frame count */ + Word16 ne_min_fx; /* HF BWE - minimum Noise gate - short-term energy */ + Word16 fmerit_m_sm_fx; /* HF BWE - memory of fmerit_m param */ Word16 voice_fac_amr_wb_hf; /* HF BWE - voice factor */ - - Word16 unvoicing_fx; /* HF BWE - unvoiced parameter */ - - Word16 unvoicing_sm_fx; /* HF BWE - smoothed unvoiced parameter */ - - Word16 unvoicing_flag; /* HF BWE - unvoiced flag */ - Word16 unvoicing_flag_fx; /* HF BWE - unvoiced flag */ - - Word16 voicing_flag; /* HF BWE - voiced flag */ - Word16 voicing_flag_fx; /* HF BWE - voiced flag */ - - Word16 start_band_old; /* HF BWE - previous start point for copying frequency band */ - Word16 start_band_old_fx; /* HF BWE - previous start point for copying frequency band */ - Word32 OptCrit_old_fx; /* HF BWE - previous criterion value for deciding the start point */ + Word16 unvoicing_fx; /* HF BWE - unvoiced parameter */ + Word16 unvoicing_sm_fx; /* HF BWE - smoothed unvoiced parameter */ + Word16 unvoicing_flag_fx; /* HF BWE - unvoiced flag */ + Word16 voicing_flag_fx; /* HF BWE - voiced flag */ + Word16 start_band_old_fx; /* HF BWE - previous start point for copying frequency band */ + Word32 OptCrit_old_fx; /* HF BWE - previous criterion value for deciding the start point */ /* Improvement of unvoiced and audio signals in AMR-WB IO mode */ - Word16 UV_cnt; /* number of consecutives frames classified as UV */ - Word16 UV_cnt_fx; /* number of consecutives frames classified as UV */ - Word16 LT_UV_cnt_fx; /* long-term consecutives frames classified as UV */ - - Word16 Last_ener_fx; /* last_energy frame */ - + Word16 UV_cnt_fx; /* number of consecutives frames classified as UV */ + Word16 LT_UV_cnt_fx; /* long-term consecutives frames classified as UV */ + Word16 Last_ener_fx; /* last_energy frame */ Word16 lt_diff_etot_fx[MAX_LT]; /* stability estimation - long-term total energy variation */ - - Word16 old_Aq_fx[68]; /* old LPC filter coefficient */ - - Word16 lt_voice_fac_fx; /* average voice factor over 4 sub-frames */ - + Word16 old_Aq_fx[68]; /* old LPC filter coefficient */ + Word16 lt_voice_fac_fx; /* average voice factor over 4 sub-frames */ } AMRWB_IO_DEC_DATA, *AMRWB_IO_DEC_HANDLE; @@ -1255,115 +1022,74 @@ typedef struct Decoder_State * Common parameters *----------------------------------------------------------------------------------*/ - Word16 idchan; /* channel ID (audio channel number) */ - Word16 element_mode; /* element mode */ + Word16 idchan; /* channel ID (audio channel number) */ + Word16 element_mode; /* element mode */ +#ifdef DEBUGGING + Word16 id_element; /* element ID */ +#endif Word32 element_brate; /* element bitrate */ Word16 codec_mode; /* Mode 1 or 2 */ Word16 mdct_sw_enable; /* MDCT switching enable flag */ Word16 mdct_sw; /* MDCT switching indicator */ Word16 last_codec_mode; /* last used codec mode */ - UWord16 *bit_stream; /* pointer to bitstream buffer */ - - Word16 next_bit_pos; /* position of the next bit to be read from the bitstream */ - - Word16 bitstreamformat; /* Bitstream format flag (G.192/MIME/VOIP_G192_RTP/VOIP_RTPDUMP) */ - Word16 sdp_hf_only; /* RTP payload format parameter: only Header-Full format without zero padding for size collision avoidance */ - Word16 amrwb_rfc4867_flag; /* MIME from rfc4867 is used */ - Word16 total_num_bits; /* == st->total_brate / 50 */ - - Word16 BER_detect; /* flag to signal detected bit error in the bitstream */ - - Word32 output_Fs; /* output sampling rate */ - - Word16 output_frame_fx; /* Output frame length Q0*/ - - Word32 total_brate; /* total bitrate in kbps of the codec */ - - Word32 last_total_brate; /* last total bitrate in kbps of the codec */ - // Word32 last_total_brate_fx; /* last total bitrate in kbps of the codec Q0*/ - - Word32 last_total_brate_ber; /* last total bitrate in kbps of the codec - used only when first frame is lost and BER is detected afterwards */ - - Word16 bits_frame_nominal; /* avg bits per frame on active frame */ - Word32 last_bits_frame_nominal; /* last avg bits per frame on active frame */ - Word16 flag_ACELP16k; /* flag indicating use of ACELP core at 16kHz internal sampling rate */ - Word16 bits_frame_channel; /* bits frame channel */ - Word16 side_bits_frame_channel; /* bits frame channel */ - - Word16 core; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */ - - Word16 coder_type; /* coder type */ - Word16 transform_type[2]; /* TCX20/10/5 mode in each subframe */ - - Word32 core_brate; /* core bitrate */ - - Word32 last_core_brate; /* previous frame core bitrate */ - - Word16 extl; /* extension layer */ - - Word16 extl_orig; /* extension layer */ - - Word16 last_extl; /* previous extension layer */ - - Word32 extl_brate; /* extension layer bitrate */ - - Word32 extl_brate_orig; /* extension layer bitrate */ - - Word16 L_frame; /* ACELP core internal frame length */ - - Word16 bwidth; /* encoded signal bandwidth */ - - Word16 Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ - - Word16 Opt_VOIP_fx; /* flag indicating VOIP mode with JBM */ - - Word16 ini_frame; /* initialization frames counter */ - + UWord16 *bit_stream; /* pointer to bitstream buffer */ + Word16 next_bit_pos; /* position of the next bit to be read from the bitstream */ + Word16 bitstreamformat; /* Bitstream format flag (G.192/MIME/VOIP_G192_RTP/VOIP_RTPDUMP) */ + Word16 sdp_hf_only; /* RTP payload format parameter: only Header-Full format without zero padding for size collision avoidance */ + Word16 amrwb_rfc4867_flag; /* MIME from rfc4867 is used */ + Word16 total_num_bits; /* == st->total_brate / 50 */ + Word16 BER_detect; /* flag to signal detected bit error in the bitstream */ + Word32 output_Fs; /* output sampling rate */ + Word16 output_frame_fx; /* Output frame length Q0*/ + Word32 total_brate; /* total bitrate in kbps of the codec */ + Word32 last_total_brate; /* last total bitrate in kbps of the codec */ + Word32 last_total_brate_ber; /* last total bitrate in kbps of the codec - used only when first frame is lost and BER is detected afterwards */ + Word16 bits_frame_nominal; /* avg bits per frame on active frame */ + Word32 last_bits_frame_nominal; /* last avg bits per frame on active frame */ + Word16 flag_ACELP16k; /* flag indicating use of ACELP core at 16kHz internal sampling rate */ + Word16 bits_frame_channel; /* bits frame channel */ + Word16 side_bits_frame_channel; /* bits frame channel */ + Word16 core; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */ + Word16 coder_type; /* coder type */ + Word16 transform_type[2]; /* TCX20/10/5 mode in each subframe */ + Word32 core_brate; /* core bitrate */ + Word32 last_core_brate; /* previous frame core bitrate */ + Word16 extl; /* extension layer */ + Word16 extl_orig; /* extension layer */ + Word16 last_extl; /* previous extension layer */ + Word32 extl_brate; /* extension layer bitrate */ + Word32 extl_brate_orig; /* extension layer bitrate */ + Word16 L_frame; /* ACELP core internal frame length */ + Word16 bwidth; /* encoded signal bandwidth */ + Word16 Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ + Word16 Opt_VOIP_fx; /* flag indicating VOIP mode with JBM */ + Word16 ini_frame; /* initialization frames counter */ Word16 prev_coder_type; /* coding type of last frame */ Word16 low_rate_mode; /* low-rate mode flag */ Word16 last_low_rate_mode; /* previous frame low-rate mode flag */ Word16 inactive_coder_type_flag; /* inactive coder type flag (0 = AVQ / 1 = GSC) */ - Word16 CNG_fx; /* RXDTX handler: CNG=1, nonCNG=0 */ - Word16 prev_ft_speech_fx; /* RXDTX handler: previous frametype flag for G.192 format AMRWB SID_FIRST detection */ - - - // note_ : produces failures if added below their float parts - Word16 old_exc_fx[L_EXC_MEM_DEC]; /* old excitation Q_exc*/ - Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame Q2.56*/ - Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame Q15*/ - /*----------------------------------------------------------------------------------* * ACELP core parameters *----------------------------------------------------------------------------------*/ - - Word16 tilt_code_fx; /* tilt of code Q15*/ - - - Word16 mem_syn1_fx[M]; /* synthesis filter memory (for core switching and FD BWE) */ - Word16 mem_syn2_fx[M]; /* synthesis filter memory Q_syn*/ + Word16 old_exc_fx[L_EXC_MEM_DEC]; /* old excitation Q_exc*/ + Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame Q2.56*/ + Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame Q15*/ + Word16 tilt_code_fx; /* tilt of code Q15*/ + Word16 mem_syn1_fx[M]; /* synthesis filter memory (for core switching and FD BWE) */ + Word16 mem_syn2_fx[M]; /* synthesis filter memory Q_syn*/ Word16 mem_syn3_fx[M]; - - Word16 mem_deemph_fx; /* deemphasis filter memory Q_syn*/ - - Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean)(Qx2.56) */ - - Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual)(Qx2.56)*/ - - Word16 stab_fac_fx; /* LSF stability factor Q15*/ - + Word16 mem_deemph_fx; /* deemphasis filter memory Q_syn*/ + Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean)(Qx2.56) */ + Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual)(Qx2.56)*/ + Word16 stab_fac_fx; /* LSF stability factor Q15*/ Word16 stab_fac_smooth_fx; /* low-pass filtered stability factor Q15*/ - - Word16 last_coder_type; /* previous coder type */ - - Word16 agc_mem_fx[2]; /* memory of AGC for saturation control Q0*/ - + Word16 last_coder_type; /* previous coder type */ + Word16 agc_mem_fx[2]; /* memory of AGC for saturation control Q0*/ Word16 mid_lsf_int; - Word16 safety_net; - Word32 log_energy_diff_lt_fx; /*In range of word16*/ /*Q-15*/ Word16 stab_fac_smooth_lt_fx; /*In range of word16*/ /*Q-15*/ Word32 log_energy_old_fx; @@ -1376,145 +1102,88 @@ typedef struct Decoder_State Word16 no_scales_p_fx[MAX_NO_MODES_p][2]; /* LSF LVQ structure Q0*/ Word32 L_mem_hp_out_fx[5]; /* hp filter memory for synthesis */ - - Word16 GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ - - Word16 GSC_IVAS_mode; /* AC mode (GSC) - GSC IVAS mode */ - + Word16 GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ + Word16 GSC_IVAS_mode; /* AC mode (GSC) - GSC IVAS mode */ Word16 Last_GSC_noisy_speech_flag; /* AC mode (GSC) - mem of the past flag to indicate GSC osn SWB noisy speech */ - GSC_DEC_HANDLE hGSCDec; - - Word32 gc_threshold_fx; /* Noise enhancer - threshold for gain_code Q16*/ - + Word32 gc_threshold_fx; /* Noise enhancer - threshold for gain_code Q16*/ struct dispMem_fx dm_fx; /* Noise enhancer - phase dispersion algorithm memory */ ZERO_BWE_DEC_HANDLE hBWE_zero; /* HF (6-7kHz) BWE */ - Word16 unv_cnt; /* Stationary noise UV modification - unvoiced frame counter */ - - Word16 uv_count; /* Stationary noise UV modification - unvoiced counter */ - - Word16 act_count; /* Stationary noise UV modification - activation counter */ - - Word32 ge_sm_fx; /* Stationary noise UV modification - smoothed excitation gain Q(GE_SHIFT)*/ - - Word16 lspold_s_fx[M]; /* Stationary noise UV modification - old LSP vector Q15*/ - - Word16 noimix_seed; /* Stationary noise UV modification - mixture seed */ - - Word16 min_alpha_fx; /* Stationary noise UV modification - minimum alpha Q15*/ - - Word16 Q_stat_noise; /* Q of Exc_pe */ - - Word16 exc_pe_fx; /* Stationary noise UV modification - scale (Q_stat_noise) */ - + Word16 unv_cnt; /* Stationary noise UV modification - unvoiced frame counter */ + Word16 uv_count; /* Stationary noise UV modification - unvoiced counter */ + Word16 act_count; /* Stationary noise UV modification - activation counter */ + Word32 ge_sm_fx; /* Stationary noise UV modification - smoothed excitation gain Q(GE_SHIFT)*/ + Word16 lspold_s_fx[M]; /* Stationary noise UV modification - old LSP vector Q15*/ + Word16 noimix_seed; /* Stationary noise UV modification - mixture seed */ + Word16 min_alpha_fx; /* Stationary noise UV modification - minimum alpha Q15*/ + Word16 Q_stat_noise; /* Q of Exc_pe */ + Word16 exc_pe_fx; /* Stationary noise UV modification - scale (Q_stat_noise) */ Word16 Q_stat_noise_ge; /* Q of ge_sm_fx */ - - Word16 bfi; /* FEC - bad frame indicator */ - - Word16 prev_bfi; /* FEC - previous bad frame indicator */ - - Word16 prev_old_bfi; /* FEC - previous old bad frame indicator */ - - Word16 seed; /* FEC - seed for random generator for excitation */ - // Word16 seed_fx; /* FEC - seed for random generator for excitation Q0*/ - - - Word16 last_good; /* FEC - clas of last good received */ - - Word16 lp_gainp_fx; /* FEC - low-pass filtered pitch gain Q14 */ - - Word16 lp_gainc_fx; /* FEC - low-pass filtered code gain Q3*/ - - Word32 lp_ener_fx; /* FEC - low-pass filtered energy Q6*/ - - Word32 enr_old_fx; /* FEC - energy of the concealed frame Q0*/ - - Word16 bfi_pitch_fx; /* FEC - pitch for FEC */ - - Word16 bfi_pitch_frame; /* FEC - frame length when pitch for FEC is saved */ - + Word16 bfi; /* FEC - bad frame indicator */ + Word16 prev_bfi; /* FEC - previous bad frame indicator */ + Word16 prev_old_bfi; /* FEC - previous old bad frame indicator */ + Word16 seed; /* FEC - seed for random generator for excitation */ + Word16 last_good; /* FEC - clas of last good received */ + Word16 lp_gainp_fx; /* FEC - low-pass filtered pitch gain Q14 */ + Word16 lp_gainc_fx; /* FEC - low-pass filtered code gain Q3*/ + Word32 lp_ener_fx; /* FEC - low-pass filtered energy Q6*/ + Word32 enr_old_fx; /* FEC - energy of the concealed frame Q0*/ + Word16 bfi_pitch_fx; /* FEC - pitch for FEC */ + Word16 bfi_pitch_frame; /* FEC - frame length when pitch for FEC is saved */ Word16 old_pitch_buf_16_fx[2 * NB_SUBFR16k + 2]; /* FEC - buffer of old subframe pitch values Q6 */ Word32 old_pitch_buf_fx[2 * NB_SUBFR16k + 2]; /* FEC - buffer of old subframe pitch values 15Q16 */ - - Word16 upd_cnt; /* FEC - counter of frames since last update */ - - Word16 scaling_flag; /* FEC - flag to indicate energy control of syn */ - - Word32 lp_ener_FEC_av; /* FEC - averaged voiced signal energy Q0 */ - - Word32 lp_ener_FEC_max; /* FEC - averaged voiced signal energy Q0 */ - - Word16 old_enr_LP; /* FEC - LP filter gain Q5*/ - - Word16 prev_nbLostCmpt; /* FEC - compt for number of consecutive lost frame at the previous frame*/ - Word16 mode_lvq; /* FEC - index for LSF mean vector*/ - - - Word16 lsfoldbfi0_fx[M]; /* FEC - LSF vector of the previous frame (Qx2.56)*/ - - Word16 lsfoldbfi1_fx[M]; /* FEC - LSF vector of the past previous frame (Qx2.56) */ - - Word16 lsf_adaptive_mean_fx[M]; /* FEC - adaptive mean LSF vector for FEC (Qx2.56)*/ - - Word16 decision_hyst; /* FEC - hysteresis of the music/speech decision */ - - Word16 lp_ener_FER_fx; /* FEC - long-term active-signal average energy Q8*/ - - + Word16 upd_cnt; /* FEC - counter of frames since last update */ + Word16 scaling_flag; /* FEC - flag to indicate energy control of syn */ + Word32 lp_ener_FEC_av; /* FEC - averaged voiced signal energy Q0 */ + Word32 lp_ener_FEC_max; /* FEC - averaged voiced signal energy Q0 */ + Word16 old_enr_LP; /* FEC - LP filter gain Q5*/ + Word16 prev_nbLostCmpt; /* FEC - compt for number of consecutive lost frame at the previous frame*/ + Word16 mode_lvq; /* FEC - index for LSF mean vector*/ + Word16 lsfoldbfi0_fx[M]; /* FEC - LSF vector of the previous frame (Qx2.56)*/ + Word16 lsfoldbfi1_fx[M]; /* FEC - LSF vector of the past previous frame (Qx2.56) */ + Word16 lsf_adaptive_mean_fx[M]; /* FEC - adaptive mean LSF vector for FEC (Qx2.56)*/ + Word16 decision_hyst; /* FEC - hysteresis of the music/speech decision */ + Word16 lp_ener_FER_fx; /* FEC - long-term active-signal average energy Q8*/ WI_DEC_HANDLE hWIDec; - Word16 relax_prev_lsf_interp; - Word16 mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM]; /* FEC - memory of the synthesis signal for frame class estimation */ - Word16 bpf_off; /* Bass post-filter - do not use BPF when this flag is set to 1 */ - + Word16 bpf_off; /* Bass post-filter - do not use BPF when this flag is set to 1 */ BPF_DEC_HANDLE hBPF; /* Bass post-filter handle */ - HANDLE_CLDFB_FILTER_BANK cldfbAna; /* main analysis filter bank handle */ - - HANDLE_CLDFB_FILTER_BANK cldfbBPF; /* BPF analysis filter bank handle */ - - HANDLE_CLDFB_FILTER_BANK cldfbSyn; /* main synthesis filter bank handle */ - + HANDLE_CLDFB_FILTER_BANK cldfbAna; /* main analysis filter bank handle */ + HANDLE_CLDFB_FILTER_BANK cldfbBPF; /* BPF analysis filter bank handle */ + HANDLE_CLDFB_FILTER_BANK cldfbSyn; /* main synthesis filter bank handle */ HANDLE_CLDFB_FILTER_BANK cldfbSynHB; /* high band synthesis filter bank needed in SBA2Stereo DTX handling */ - Word16 last_active_bandsToZero_bwdec; Word16 last_flag_filter_NB; - Word16 perc_bwddec; /*Q14*/ - Word16 active_frame_cnt_bwddec; Word16 flag_buffer[20]; Word16 total_frame_cnt_bwddec; - Word32 avg_nrg_LT; - Word16 Ng_ener_ST_fx; /* Noise gate - short-term energy Q8*/ - Word16 last_L_frame; /* ACELP@16kHz - last value of st->L_frame */ - + Word16 last_L_frame; /* ACELP@16kHz - last value of st->L_frame */ Word16 mem_preemp_preQ_fx; /* ACELP@16kHz - prequantizer preemhasis memory */ - - Word16 last_nq_preQ; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */ - - Word16 last_code_preq; /* ACELP@16kHz - last coefficient of the pre-quantizer contribution */ - - Word16 use_acelp_preq; /* ACELP@16kHz - flag of prequantizer usage */ - + Word16 last_nq_preQ; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */ + Word16 last_code_preq; /* ACELP@16kHz - last coefficient of the pre-quantizer contribution */ + Word16 use_acelp_preq; /* ACELP@16kHz - flag of prequantizer usage */ /* NB and formant post-filter */ PFSTAT_HANDLE hPFstat; /* NB and formant post-filter states */ - Word16 psf_lp_noise_fx; - Word16 last_voice_factor_fx; /* Q6*/ - + Word16 last_voice_factor_fx; /* Q6*/ + Word16 prev_synth_buffer_fx[NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS )]; /*Updated IVAS size is 96*/ + Word32 prev_synth_buffer32_fx[NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS )]; + Word16 q_prev_synth_buffer_fx; + Word16 Qprev_synth_buffer_fx; Word16 old_bfi_cnt; /* HQ core - # of bfi until previous frame(for FEC) */ @@ -1523,23 +1192,16 @@ typedef struct Decoder_State *----------------------------------------------------------------------------------*/ Word16 first_CNG; /* DTX/CNG - first CNG frame flag */ - - Word16 cng_type; /* DTX/CNG - flag indicating LP or CLDFB based SID/CNG */ - - Word16 last_vad; - + Word16 cng_type; /* DTX/CNG - flag indicating LP or CLDFB based SID/CNG */ + Word16 last_vad_fx; Word32 last_active_brate; /* DTX/CNG - last active frame bitrate used for CNG_mode control */ + Word16 last_CNG_L_frame; /* DTX/CNG - last CNG frame length */ - Word16 last_CNG_L_frame; /* DTX/CNG - last CNG frame length */ - // Word16 last_CNG_L_frame_fx; /* DTX/CNG - last CNG frame length */ - - Word16 CNG_mode; /* DTX/CNG - mode for DTX configuration */ - // Word16 CNG_mode_fx; /* DTX/CNG - mode for DTX configuration */ + Word16 active_cnt; + Word16 CNG_mode; /* DTX/CNG - mode for DTX configuration */ Word16 lspCNG_fx[M]; /* CNG and DTX - LP filtered ISPs Q15*/ - Word16 active_cnt; - TD_CNG_DEC_HANDLE hTdCngDec; Word16 masa_sid_format; @@ -1556,20 +1218,12 @@ typedef struct Decoder_State SC_VBR_DEC_HANDLE hSC_VBR; Word16 last_ppp_mode_dec; - Word16 ppp_mode_dec; - Word16 last_nelp_mode_dec; - Word16 nelp_mode_dec; - - Word16 prev_gain_pit_dec_fx; /*Q14*/ - - + Word16 prev_gain_pit_dec_fx; /*Q14*/ Word16 prev_tilt_code_dec_fx; /*Q15*/ - Word16 vbr_hw_BWE_disable_dec; - Word16 last_vbr_hw_BWE_disable_dec; /*----------------------------------------------------------------------------------* @@ -1599,7 +1253,6 @@ typedef struct Decoder_State *----------------------------------------------------------------------------------*/ HR_BWE_DEC_HANDLE hBWE_FD_HR; - Word16 Qprev_synth_buffer_fx; /*----------------------------------------------------------------------------------* * HQ core parameters @@ -1608,26 +1261,18 @@ typedef struct Decoder_State HQ_DEC_HANDLE hHQ_core; Word16 last_core; - Word16 last_core_from_bs; /* last frame core as coded in TCX bitstream */ - // Word16 last_core_bs_fx; Word16 last_L_frame_ori; - Word16 previoussynth_fx[L_FRAME48k]; Word32 previoussynth_fx_32[L_FRAME48k]; - - Word16 old_synth_sw_fx[NS2SA( 48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS )]; - Word16 delay_buf_out_fx[HQ_DELTA_MAX * HQ_DELAY_COMP]; /*Q0*/ Word32 delay_buf_out32_fx[HQ_DELTA_MAX * HQ_DELAY_COMP]; /*Q11*/ - Word16 old_Aq_12_8_fx[M + 1]; /* Q12 old Aq[] for core switching */ Word32 old_Aq_12_8_fx_32[M + 1]; /* Q28 old Aq[] for core switching */ - - Word16 old_Es_pred_fx; /* old Es_pred for core switching */ + Word16 old_Es_pred_fx; /* old Es_pred for core switching */ HQ_NBFEC_HANDLE hHQ_nbfec; @@ -1638,74 +1283,41 @@ typedef struct Decoder_State TD_BWE_DEC_HANDLE hBWE_TD; Word16 old_bwe_delay; - Word16 hb_prev_synth_buffer_fx[NS2SA( 48000, DELAY_BWE_TOTAL_NS )]; /* WB/SWB bandwidth switching */ - Word16 tilt_wb_fx; // Q11 - - Word16 tilt_swb_fx; // Q24 - + Word16 tilt_wb_fx; // Q11 + Word16 tilt_swb_fx; // Q24 Word16 prev_ener_shb_fx; // Q1 - Word32 enerLH_fx; Word16 enerLH_fx_Q; - Word32 prev_enerLH_fx; // Q1 - Word32 enerLL_fx; Word16 enerLL_fx_Q; - Word32 prev_enerLL_fx; // Q1 - Word16 prev_fractive; - Word16 prev_bws_cnt; - Word16 bws_cnt; - Word16 bws_cnt1; - Word16 attenu_fx; - Word16 last_inner_frame; - Word16 last_bwidth; - Word16 t_audio_q_fx[L_FRAME]; - Word16 interpol_3_2_cng_dec_fx[INTERP_3_2_MEM_LEN]; - /*----------------------------------------------------------------------------------* * Fixed point only *----------------------------------------------------------------------------------*/ + Word16 Q_exc; Word16 Q_exc_cng; Word16 prev_Q_exc; Word16 Q_subfr[L_Q_MEM]; - Word16 prev_Q_bwe_syn; - Word16 prev_Q_bwe_syn2; - - Word16 prev_Q_bwe_exc_fb; - Word16 prev_Qx; - Word16 prev_Q_bwe_exc; - Word16 prev_Q_synth; - Word16 prev_SWB_fenv_fx[SWB_FENV]; - Word16 Q_syn; Word16 Q_syn2; Word16 Q_syn_cng; Word16 prev_Q_syn; - Word16 prev_frame_pow_exp; - Word16 prev_ener_fx_Q; - Word16 last_wb_bwe_ener_fx; - Word16 prev_fb_ener_adjust_fx; - - Word16 prev_synth_buffer_fx[NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS )]; /*Updated IVAS size is 96*/ - Word16 q_prev_synth_buffer_fx; - Word16 GainShape_Delay[NUM_SHB_SUBFR / 2]; - Word16 prev_lpc_wb_fx[LPC_SHB_ORDER_WB]; + Word16 prev_Q_bwe_exc; /*----------------------------------------------------------------------------------* * SWB BWE structure @@ -1713,22 +1325,6 @@ typedef struct Decoder_State FD_BWE_DEC_HANDLE hBWE_FD; - /*----------------------------------------------------------------------------------* - * SWB DTX/CNG parameters - *----------------------------------------------------------------------------------*/ - - Word16 shb_cng_ener_fx; - Word16 wb_cng_ener_fx; - Word16 last_wb_cng_ener_fx; - Word16 last_shb_cng_ener_fx; - Word16 swb_cng_seed; - Word16 lsp_shb_prev_prev_fx[LPC_SHB_ORDER]; - Word16 lsp_shb_prev_fx[LPC_SHB_ORDER]; - Word16 shb_dtx_count_fx; - Word16 last_vad_fx; - Word16 trans_cnt_fx; - Word16 last_shb_ener_fx; - /*----------------------------------------------------------------------------------* * LD music post-filter *----------------------------------------------------------------------------------*/ @@ -1738,6 +1334,7 @@ typedef struct Decoder_State /*----------------------------------------------------------------------------------* * TCX LTP decoder handle *----------------------------------------------------------------------------------*/ + TCX_LTP_DEC_HANDLE hTcxLtpDec; /*----------------------------------------------------------------------------------* @@ -1746,6 +1343,7 @@ typedef struct Decoder_State TCX_DEC_HANDLE hTcxDec; + /* in floating point implementation, different buffers are used: lp_error_ener <-> pst_lp_ener, mem_error <-> pst_mem_deemp_err */ Word32 lp_error_ener; Word32 mem_error; @@ -1774,43 +1372,25 @@ typedef struct Decoder_State Word16 L_frame_past; Word16 L_frameTCX_past; - Word16 lsfold_uw[M]; /* old lsf (unweighted) */ - - Word16 lspold_uw[M]; /* old lsp (unweighted) */ - - Word16 seed_tcx_plc; /* seed memory (for random function in TCX PLC) */ - - + Word16 lsfold_uw[M]; /* old lsf (unweighted) */ + Word16 lspold_uw[M]; /* old lsp (unweighted) */ + Word16 seed_tcx_plc; /* seed memory (for random function in TCX PLC) */ Word16 past_gpit; /* past gain of pitch (for frame recovery) */ Word32 past_gcode; /* past energy (!) of code (for frame recovery) */ /*15Q16*/ - - Word16 lsf_cng[M]; /* xSF coefficients used for CNG generation (long term) */ - - Word16 lspold_cng[M]; /* xSP coefficients used for CNG generation (long term) */ - - Word16 lsp_q_cng[M]; /* xSP coefficients used for CNG generation (short term interpolated) */ - - Word16 old_lsp_q_cng[M]; /* xSP coefficients used for CNG generation (short term interpolated) */ - - Word16 lsf_q_cng[M]; /* xSF coefficients used for CNG generation (short term interpolated) */ - - Word16 old_lsf_q_cng[M]; /* xSF: old quantized lsfs for background noise */ - - Word16 Aq_cng[( NB_SUBFR16k + 1 ) * ( M + 1 )]; /* LPC coefficients derived from CNG estimate */ - - Word16 mem_syn_unv_back[M]; /* filter memory for unvoiced synth */ - - Word16 plcBackgroundNoiseUpdated; /* flag: Is background noise estimate updated? */ - - Word16 last_gain_syn_deemph; /*Q15*/ - + Word16 lsf_cng[M]; /* xSF coefficients used for CNG generation (long term) */ + Word16 lspold_cng[M]; /* xSP coefficients used for CNG generation (long term) */ + Word16 lsp_q_cng[M]; /* xSP coefficients used for CNG generation (short term interpolated) */ + Word16 old_lsp_q_cng[M]; /* xSP coefficients used for CNG generation (short term interpolated) */ + Word16 lsf_q_cng[M]; /* xSF coefficients used for CNG generation (short term interpolated) */ + Word16 old_lsf_q_cng[M]; /* xSF: old quantized lsfs for background noise */ + Word16 Aq_cng[( NB_SUBFR16k + 1 ) * ( M + 1 )]; /* LPC coefficients derived from CNG estimate */ + Word16 mem_syn_unv_back[M]; /* filter memory for unvoiced synth */ + Word16 plcBackgroundNoiseUpdated; /* flag: Is background noise estimate updated? */ + Word16 last_gain_syn_deemph; /*Q15*/ Word16 last_gain_syn_deemph_e; - Word16 last_concealed_gain_syn_deemph; /*Q15*/ - Word16 last_concealed_gain_syn_deemph_e; - /* variables for framing */ Word16 nb_subfr; @@ -1828,10 +1408,7 @@ typedef struct Decoder_State /*Preemphasis factor*/ Word16 preemph_fac; /*0Q15*/ - - Word16 gamma; - Word16 inv_gamma; /*for AMR-WB like 6.4 to 7 kHz upsampling and noise filling*/ @@ -1841,34 +1418,22 @@ typedef struct Decoder_State Word16 last_core_bfi; /* PLC - mode in previous frame */ Word16 nbLostCmpt; /* PLC - compt for number of consecutive lost frame */ - Word32 old_fpitch; /* last pitch of previous frame */ /*15Q16*/ - + Word32 old_fpitch; /* last pitch of previous frame */ /*15Q16*/ Word32 old_fpitchFB; /* PLC - last pitch of previous FB frame (depends on output sr) */ /*15Q16*/ - - Word16 clas_dec; /* PLC - frame class at the decoder */ - - Word16 mem_pitch_gain[2 * NB_SUBFR16k + 2]; /* Pitch gain memory Q14 */ - - Word16 plc_use_future_lag; /* PLC - flag indicating if info (pitch lag / pitch gain) about future frame is usable */ + Word16 clas_dec; /* PLC - frame class at the decoder */ + Word16 mem_pitch_gain[2 * NB_SUBFR16k + 2]; /* Pitch gain memory Q14 */ + Word16 plc_use_future_lag; /* PLC - flag indicating if info (pitch lag / pitch gain) about future frame is usable */ Word32 Mode2_lp_gainc; /* 15Q16 low passed code gain used for concealment*/ Word32 Mode2_lp_gainp; /* 15Q16 low passed pitch gain used for concealment*/ - Word16 cummulative_damping; /*Q15*/ - Word16 cngTDLevel; Word16 cngTDLevel_e; - - Word16 prev_widow_left_rect; - Word16 reset_mem_AR; - Word16 classifier_Q_mem_syn; /*scalingfactor of mem_syn_clas_estim_fx in MODE2 */ - Word16 rate_switching_init; - /* LPC quantization */ Word16 lpcQuantization; Word16 numlpc; @@ -1882,8 +1447,6 @@ typedef struct Decoder_State Word16 last_ctx_hm_enabled; - struct tonalmdctconceal tonalMDCTconceal; - TonalMDCTConcealPtr hTonalMDCTConc; Word16 tonal_mdct_plc_active; Word16 last_tns_active; @@ -1908,7 +1471,6 @@ typedef struct Decoder_State Word16 enablePlcWaveadjust; Word16 tonality_flag; T_PLCInfo_HANDLE hPlcInfo; - T_PLCInfo plcInfo; Word16 VAD; Word16 flag_cna; @@ -1959,6 +1521,7 @@ typedef struct Decoder_State Word16 tec_flag; Word16 tfa_flag; TEC_DEC_HANDLE hTECDec; + /*----------------------------------------------------------------------------------* * IVAS parameters *----------------------------------------------------------------------------------*/ @@ -1968,21 +1531,11 @@ typedef struct Decoder_State Word16 cng_sba_flag; /* CNG in SBA flag */ /* MCT Channel mode indication: LFE, ignore channel? */ - // note_ : one extra value in evs ivas macro code MCT_CHAN_MODE mct_chan_mode; Word16 cng_ism_flag; /* CNG in ISM format flag */ Word16 is_ism_format; /* Indication whether the codec operates in ISM format */ - Word16 last_element_mode; /* element mode */ - // Word16 coder_type; /* low-rate mode flag */ - Word32 prev_synth_buffer32_fx[NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS )]; - -#ifdef DEBUGGING - Word16 id_element; /* element ID */ -#endif - IVAS_FORMAT ivas_format; /* format; corresponds to st_ivas->ivas_format, unless the signal gets transormed to a different domain for rendering */ - } Decoder_State, *DEC_CORE_HANDLE; #endif diff --git a/lib_dec/swb_bwe_dec_fx.c b/lib_dec/swb_bwe_dec_fx.c index b91dcdf328f1d9151f6574777ff24e73d0324304..42d2a9cc4a2e8015773e402e81b9751400538e11 100644 --- a/lib_dec/swb_bwe_dec_fx.c +++ b/lib_dec/swb_bwe_dec_fx.c @@ -19,6 +19,7 @@ * * predict SWB parameters for bandwidth switching *-------------------------------------------------------------------*/ + static Word16 para_pred_bws_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 *signal_wb_fx, /* i : wideband frequency signal Q_syn*/ @@ -27,6 +28,7 @@ static Word16 para_pred_bws_fx( { Word16 i, j, k; Word16 mode; + FD_BWE_DEC_HANDLE hBWE_FD; Word16 tmp, tmp_den, tmp_num; Word32 L_tmp, L_tmp_max; Word16 exp; @@ -39,6 +41,7 @@ static Word16 para_pred_bws_fx( Word16 coder_type = st_fx->coder_type; move16(); + hBWE_FD = st_fx->hBWE_FD; mode = NORMAL; move16(); @@ -226,16 +229,16 @@ static Word16 para_pred_bws_fx( FOR( i = 0; i < SWB_FENV; i++ ) { test(); - IF( NE_16( st_fx->prev_coder_type, coder_type ) && GT_16( mult_r( SWB_fenv_fx[i], 16384 ), st_fx->prev_SWB_fenv_fx[i] ) ) + IF( NE_16( st_fx->prev_coder_type, coder_type ) && GT_16( mult_r( SWB_fenv_fx[i], 16384 ), hBWE_FD->prev_SWB_fenv_fx[i] ) ) { /*SWB_fenv_fx[i] = add(mult_r(SWB_fenv_fx[i], 3277), mult_r(st_fx->prev_SWB_fenv_fx[i], 29491)); */ - SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 3277 ), st_fx->prev_SWB_fenv_fx[i], 29491 ) ); + SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 3277 ), hBWE_FD->prev_SWB_fenv_fx[i], 29491 ) ); move16(); } ELSE { /*SWB_fenv_fx[i] = add(mult_r(SWB_fenv_fx[i], st_fx->attenu_fx), mult_r(st_fx->prev_SWB_fenv_fx[i], sub(32767, st_fx->attenu_fx))); */ - SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], st_fx->attenu_fx ), st_fx->prev_SWB_fenv_fx[i], sub( 32767, st_fx->attenu_fx ) ) ); + SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], st_fx->attenu_fx ), hBWE_FD->prev_SWB_fenv_fx[i], sub( 32767, st_fx->attenu_fx ) ) ); move16(); } } @@ -257,9 +260,9 @@ static Word16 para_pred_bws_fx( { FOR( i = 0; i < SWB_FENV; i++ ) { - if ( GT_16( mult_r( SWB_fenv_fx[i], 16384 ), st_fx->prev_SWB_fenv_fx[i] ) ) + if ( GT_16( mult_r( SWB_fenv_fx[i], 16384 ), hBWE_FD->prev_SWB_fenv_fx[i] ) ) { - SWB_fenv_fx[i] = st_fx->prev_SWB_fenv_fx[i]; + SWB_fenv_fx[i] = hBWE_FD->prev_SWB_fenv_fx[i]; move16(); } } @@ -268,7 +271,7 @@ static Word16 para_pred_bws_fx( FOR( i = 0; i < SWB_FENV; i++ ) { /*SWB_fenv_fx[i] = add(mult_r(SWB_fenv_fx[i], 29491), mult_r(st_fx->prev_SWB_fenv_fx[i], 3277)); */ - SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 29491 ), st_fx->prev_SWB_fenv_fx[i], 3277 ) ); + SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 29491 ), hBWE_FD->prev_SWB_fenv_fx[i], 3277 ) ); move16(); } st_fx->attenu_fx = 3277; /*Q15*/ @@ -349,16 +352,18 @@ Word16 WB_BWE_gain_deq_fx( * * WB BWE decoder (only for 16kHz signals) *-------------------------------------------------------------------*/ -Word16 ivas_wb_bwe_dec_fx( /* o : Q_syn_hb */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 output[], /* i : suntehsis @ internal Fs Q_input */ - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - const Word16 output_frame, /* i : frame length */ - Word16 *voice_factors_fx, /* i : voicing factors Q15 */ - const Word16 pitch_buf_fx[], /* i : pitch buffer Q6 */ - Word16 *Qpost ) + +/* o : Q_syn_hb */ +Word16 ivas_wb_bwe_dec_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 output[], /* i : suntehsis @ internal Fs Q_input */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 output_frame, /* i : frame length */ + Word16 *voice_factors_fx, /* i : voicing factors Q15 */ + const Word16 pitch_buf_fx[], /* i : pitch buffer Q6 */ + Word16 *Qpost ) { Word16 mode; Word16 WB_fenv_fx[SWB_FENV]; @@ -421,7 +426,7 @@ Word16 ivas_wb_bwe_dec_fx( /* o : { /* de-quantization */ mode = WB_BWE_gain_deq_fx( st_fx, WB_fenv_fx ); - st_fx->last_wb_bwe_ener_fx = extract_l( Mpy_32_16_r( L_add( WB_fenv_fx[0], WB_fenv_fx[1] ), 16384 /*0.5f in Q15*/ ) ); + st_fx->hBWE_FD->last_wb_bwe_ener_fx = extract_l( Mpy_32_16_r( L_add( WB_fenv_fx[0], WB_fenv_fx[1] ), 16384 /*0.5f in Q15*/ ) ); move16(); } ELSE @@ -438,12 +443,12 @@ Word16 ivas_wb_bwe_dec_fx( /* o : } if ( NE_16( st_fx->last_extl, WB_BWE ) ) { - st_fx->prev_SWB_fenv_fx[0] = 0; + hBWE_FD->prev_SWB_fenv_fx[0] = 0; move16(); } - mode = WB_BWE_gain_pred_fx( WB_fenv_fx, ysynth_fx, coder_type, st_fx->prev_coder_type, st_fx->prev_SWB_fenv_fx[0], - voice_factors_fx, pitch_buf_fx, tmp_brate, st_fx->last_wb_bwe_ener_fx, Q_syn, st_fx->last_extl, st_fx->tilt_wb_fx ); + mode = WB_BWE_gain_pred_fx( WB_fenv_fx, ysynth_fx, coder_type, st_fx->prev_coder_type, hBWE_FD->prev_SWB_fenv_fx[0], + voice_factors_fx, pitch_buf_fx, tmp_brate, st_fx->hBWE_FD->last_wb_bwe_ener_fx, Q_syn, st_fx->last_extl, st_fx->tilt_wb_fx ); } } ELSE @@ -453,32 +458,34 @@ Word16 ivas_wb_bwe_dec_fx( /* o : move16(); FOR( i = 0; i < 2; i++ ) { - WB_fenv_fx[i] = mult_r( st_fx->prev_SWB_fenv_fx[i], 24576 ); + WB_fenv_fx[i] = mult_r( hBWE_FD->prev_SWB_fenv_fx[i], 24576 ); move16(); } } test(); IF( NE_16( st_fx->last_extl, WB_BWE ) || st_fx->bfi ) { - Copy( WB_fenv_fx, st_fx->prev_SWB_fenv_fx, 2 ); + Copy( WB_fenv_fx, hBWE_FD->prev_SWB_fenv_fx, 2 ); } exp = norm_l( hBWE_FD->prev_Energy_wb_fx ); - IF( GT_16( add( st_fx->prev_Q_synth, exp ), Q_syn ) ) + IF( GT_16( add( hBWE_FD->prev_Q_synth, exp ), Q_syn ) ) { - hBWE_FD->prev_Energy_wb_fx = L_shr( hBWE_FD->prev_Energy_wb_fx, sub( st_fx->prev_Q_synth, Q_syn ) ); + hBWE_FD->prev_Energy_wb_fx = L_shr( hBWE_FD->prev_Energy_wb_fx, sub( hBWE_FD->prev_Q_synth, Q_syn ) ); move32(); } ELSE { - Q_syn = add( st_fx->prev_Q_synth, exp ); + Q_syn = add( hBWE_FD->prev_Q_synth, exp ); hBWE_FD->prev_Energy_wb_fx = L_shl( hBWE_FD->prev_Energy_wb_fx, exp ); move32(); } + WB_BWE_decoding_fx( ysynth_fx, WB_fenv_fx, ysynth_32, L_FRAME16k, mode, - st_fx->last_extl, &hBWE_FD->prev_Energy_wb_fx, st_fx->prev_SWB_fenv_fx, &hBWE_FD->prev_L_swb_norm, + st_fx->last_extl, &hBWE_FD->prev_Energy_wb_fx, hBWE_FD->prev_SWB_fenv_fx, &hBWE_FD->prev_L_swb_norm, st_fx->extl, coder_type, st_fx->total_brate, &hBWE_FD->Seed, &hBWE_FD->prev_flag, st_fx->prev_coder_type, Q_syn, &Q_syn_hb ); + IF( EQ_32( st_fx->output_Fs, 32000 ) ) { set32_fx( &ysynth_32[L_FRAME16k], 0, L_FRAME16k ); @@ -487,7 +494,9 @@ Word16 ivas_wb_bwe_dec_fx( /* o : { set32_fx( &ysynth_32[L_FRAME16k], 0, L_FRAME32k ); } + Inverse_Transform( ysynth_32, &Q_syn_hb, t_audio32_tmp, 0, output_frame, output_frame, st_fx->element_mode ); + window_ola_fx( t_audio32_tmp, hb_synth_fx, &Q_syn_hb, hBWE_FD->mem_imdct_fx, &hBWE_FD->mem_imdct_exp_fx, output_frame, ALDO_WINDOW, ALDO_WINDOW, 0, 0, 0 ); @@ -497,13 +506,16 @@ Word16 ivas_wb_bwe_dec_fx( /* o : /* add HB synth from hf_synth() */ v_add_16( hb_synth_fx, synth_fx, hb_synth_fx, output_frame ); } + hBWE_FD->prev_mode = mode; move16(); - st_fx->prev_Q_synth = Q_syn; + hBWE_FD->prev_Q_synth = Q_syn; move16(); + return Q_syn_hb; } + Word16 wb_bwe_dec_fx( Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */ Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ @@ -560,7 +572,7 @@ Word16 wb_bwe_dec_fx( { /* de-quantization */ mode = WB_BWE_gain_deq_fx( st_fx, WB_fenv_fx ); - st_fx->last_wb_bwe_ener_fx = mult_r( add_sat( WB_fenv_fx[0], WB_fenv_fx[1] ), 16384 ); // this would not saturate if written like : rounf_fx(L_mac(L_mult(WB_fenv_fx[0], 16384), WB_fenv_fx[1], 16384)) + hBWE_FD->last_wb_bwe_ener_fx = mult_r( add_sat( WB_fenv_fx[0], WB_fenv_fx[1] ), 16384 ); // this would not saturate if written like : rounf_fx(L_mac(L_mult(WB_fenv_fx[0], 16384), WB_fenv_fx[1], 16384)) move16(); } ELSE @@ -579,12 +591,12 @@ Word16 wb_bwe_dec_fx( if ( NE_16( st_fx->last_extl, WB_BWE ) ) { - st_fx->prev_SWB_fenv_fx[0] = 0; + hBWE_FD->prev_SWB_fenv_fx[0] = 0; move16(); } - mode = WB_BWE_gain_pred_fx( WB_fenv_fx, ysynth_fx, coder_type, st_fx->prev_coder_type, st_fx->prev_SWB_fenv_fx[0], - voice_factors_fx, pitch_buf_fx, tmp_brate, st_fx->last_wb_bwe_ener_fx, Q_syn, st_fx->last_extl, st_fx->tilt_wb_fx ); + mode = WB_BWE_gain_pred_fx( WB_fenv_fx, ysynth_fx, coder_type, st_fx->prev_coder_type, hBWE_FD->prev_SWB_fenv_fx[0], + voice_factors_fx, pitch_buf_fx, tmp_brate, hBWE_FD->last_wb_bwe_ener_fx, Q_syn, st_fx->last_extl, st_fx->tilt_wb_fx ); } } ELSE @@ -594,32 +606,34 @@ Word16 wb_bwe_dec_fx( move16(); FOR( i = 0; i < 2; i++ ) { - WB_fenv_fx[i] = mult_r( st_fx->prev_SWB_fenv_fx[i], 24576 ); + WB_fenv_fx[i] = mult_r( hBWE_FD->prev_SWB_fenv_fx[i], 24576 ); move16(); } } test(); IF( NE_16( st_fx->last_extl, WB_BWE ) || st_fx->bfi ) { - Copy( WB_fenv_fx, st_fx->prev_SWB_fenv_fx, 2 ); + Copy( WB_fenv_fx, hBWE_FD->prev_SWB_fenv_fx, 2 ); } exp = norm_l( hBWE_FD->prev_Energy_wb_fx ); - IF( GT_16( add( st_fx->prev_Q_synth, exp ), Q_syn ) ) + IF( GT_16( add( hBWE_FD->prev_Q_synth, exp ), Q_syn ) ) { - hBWE_FD->prev_Energy_wb_fx = L_shr( hBWE_FD->prev_Energy_wb_fx, sub( st_fx->prev_Q_synth, Q_syn ) ); + hBWE_FD->prev_Energy_wb_fx = L_shr( hBWE_FD->prev_Energy_wb_fx, sub( hBWE_FD->prev_Q_synth, Q_syn ) ); move32(); } ELSE { - Q_syn = add( st_fx->prev_Q_synth, exp ); + Q_syn = add( hBWE_FD->prev_Q_synth, exp ); hBWE_FD->prev_Energy_wb_fx = L_shl( hBWE_FD->prev_Energy_wb_fx, exp ); move32(); } + WB_BWE_decoding_fx( ysynth_fx, WB_fenv_fx, ysynth_32, L_FRAME16k, mode, - st_fx->last_extl, &hBWE_FD->prev_Energy_wb_fx, st_fx->prev_SWB_fenv_fx, &hBWE_FD->prev_L_swb_norm, + st_fx->last_extl, &hBWE_FD->prev_Energy_wb_fx, hBWE_FD->prev_SWB_fenv_fx, &hBWE_FD->prev_L_swb_norm, st_fx->extl, coder_type, st_fx->total_brate, &hBWE_FD->Seed, &hBWE_FD->prev_flag, st_fx->prev_coder_type, Q_syn, &Q_syn_hb ); + IF( EQ_32( st_fx->output_Fs, 32000 ) ) { set32_fx( &ysynth_32[L_FRAME16k], 0, L_FRAME16k ); @@ -628,13 +642,15 @@ Word16 wb_bwe_dec_fx( { set32_fx( &ysynth_32[L_FRAME16k], 0, L_FRAME32k ); } + Inverse_Transform( ysynth_32, &Q_syn_hb, t_audio32_tmp, 0, output_frame, output_frame, st_fx->element_mode ); + window_ola_fx( t_audio32_tmp, hb_synth_fx, &Q_syn_hb, hBWE_FD->mem_imdct_fx, &hBWE_FD->mem_imdct_exp_fx, output_frame, ALDO_WINDOW, ALDO_WINDOW, 0, 0, 0 ); hBWE_FD->prev_mode = mode; move16(); - st_fx->prev_Q_synth = Q_syn; + hBWE_FD->prev_Q_synth = Q_syn; move16(); return Q_syn_hb; @@ -646,13 +662,15 @@ Word16 wb_bwe_dec_fx( * * Decoding of SWB parameters *-------------------------------------------------------------------*/ -Word16 swb_bwe_gain_deq_fx( /* o : BWE class */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 core, /* i : core : Q0 */ - Word16 *SWB_tenv, /* o : time-domain BWE envelope : Q0 */ - Word16 *SWB_fenv, /* o : frequency-domain BWE envelope : Q1 */ - const Word16 hr_flag, /* i : high rate flag : Q0 */ - const Word16 hqswb_clas /* i : HQ BWE class : Q0 */ + +/* o : BWE class */ +Word16 swb_bwe_gain_deq_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 core, /* i : core : Q0 */ + Word16 *SWB_tenv, /* o : time-domain BWE envelope : Q0 */ + Word16 *SWB_fenv, /* o : frequency-domain BWE envelope : Q1 */ + const Word16 hr_flag, /* i : high rate flag : Q0 */ + const Word16 hqswb_clas /* i : HQ BWE class : Q0 */ ) { Word16 index, mode, n_band; @@ -883,12 +901,14 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class * * SWB BWE decoder *-------------------------------------------------------------------*/ -Word16 swb_bwe_dec_fx( /*o :Q_syn_hb*/ - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis (might be rescaled inside wtda() ) Q0/Qpost */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ - const Word16 output_frame, /* i : frame length */ - Word16 *Qpost ) + +/*o : Q_syn_hb */ +Word16 swb_bwe_dec_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis (might be rescaled inside wtda() ) Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ + const Word16 output_frame, /* i : frame length */ + Word16 *Qpost ) { Word16 i, l_subfr; Word16 mode; @@ -997,19 +1017,19 @@ Word16 swb_bwe_dec_fx( /*o :Q_syn_hb*/ move16(); } - Copy( st_fx->prev_SWB_fenv_fx, SWB_fenv_fx, SWB_FENV ); + Copy( hBWE_FD->prev_SWB_fenv_fx, SWB_fenv_fx, SWB_FENV ); } /* reconstruction of MDCT spectrum of the error signal */ set32_fx( ysynth_32, 0, output_frame ); IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { - SWB_BWE_decoding_fx( ysynth_fx, SWB_fenv_fx, ysynth_32, L_FRAME32k - 80, mode, &frica_flag, &hBWE_FD->prev_Energy_fx, st_fx->prev_SWB_fenv_fx, + SWB_BWE_decoding_fx( ysynth_fx, SWB_fenv_fx, ysynth_32, L_FRAME32k - 80, mode, &frica_flag, &hBWE_FD->prev_Energy_fx, hBWE_FD->prev_SWB_fenv_fx, &hBWE_FD->prev_L_swb_norm, st_fx->tilt_wb_fx, &hBWE_FD->Seed, 80, &hBWE_FD->prev_weight_fx, st_fx->extl, Q_syn, st_fx->last_extl ); } ELSE { - SWB_BWE_decoding_fx( ysynth_fx, SWB_fenv_fx, ysynth_32, L_FRAME32k - 80, mode, &frica_flag, &hBWE_FD->prev_Energy_fx, st_fx->prev_SWB_fenv_fx, + SWB_BWE_decoding_fx( ysynth_fx, SWB_fenv_fx, ysynth_32, L_FRAME32k - 80, mode, &frica_flag, &hBWE_FD->prev_Energy_fx, hBWE_FD->prev_SWB_fenv_fx, &hBWE_FD->prev_L_swb_norm, st_fx->tilt_wb_fx, &hBWE_FD->Seed, 6, &hBWE_FD->prev_weight_fx, st_fx->extl, Q_syn, st_fx->last_extl ); } @@ -1040,11 +1060,11 @@ Word16 swb_bwe_dec_fx( /*o :Q_syn_hb*/ } ELSE IF( st_fx->bfi ) { - fb_ener_adjust_fx = st_fx->prev_fb_ener_adjust_fx; + fb_ener_adjust_fx = hBWE_FD->prev_fb_ener_adjust_fx; move16(); } - st_fx->prev_fb_ener_adjust_fx = fb_ener_adjust_fx; + hBWE_FD->prev_fb_ener_adjust_fx = fb_ener_adjust_fx; move16(); IF( EQ_16( mode, TRANSIENT ) ) { @@ -1158,23 +1178,18 @@ Word16 swb_bwe_dec_fx( /*o :Q_syn_hb*/ * Initialize FD BWE state structure at the decoder *-------------------------------------------------------------------*/ -void fd_bwe_dec_init( - Decoder_State *st_fx, /* i/o: decoder state structure */ +void fd_bwe_dec_init_fx( FD_BWE_DEC_HANDLE hBWE_FD /* i/o: FD BWE data handle */ ) { - hBWE_FD->old_wtda_wb_fx_exp = 0; - move16(); set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k ); hBWE_FD->old_wtda_swb_fx_exp = 0; move16(); - hBWE_FD->mem_imdct_exp_fx = 0; - move16(); hBWE_FD->prev_mode = NORMAL; move16(); - set16_fx( st_fx->prev_SWB_fenv_fx, 0, SWB_FENV ); + set16_fx( hBWE_FD->prev_SWB_fenv_fx, 0, SWB_FENV ); hBWE_FD->prev_Energy_fx = 0; move16(); hBWE_FD->prev_L_swb_norm = 8; @@ -1184,13 +1199,15 @@ void fd_bwe_dec_init( hBWE_FD->prev_frica_flag = 0; move16(); set16_fx( hBWE_FD->mem_imdct_fx, 0, L_FRAME48k ); + hBWE_FD->mem_imdct_exp_fx = 0; + move16(); hBWE_FD->prev_td_energy_fx = 0; move16(); hBWE_FD->prev_weight_fx = 6554; /*0.2 in Q15*/ move16(); hBWE_FD->prev_flag = 0; move16(); - st_fx->last_wb_bwe_ener_fx = 0; + hBWE_FD->last_wb_bwe_ener_fx = 0; move16(); hBWE_FD->prev_Energy_wb_fx = L_deposit_l( 0 ); move32(); @@ -1198,12 +1215,12 @@ void fd_bwe_dec_init( move16(); /* Previous frame LPC initialization for PPP */ - st_fx->prev_Q_synth = 0; + hBWE_FD->prev_Q_synth = 0; move16(); hBWE_FD->mem_deemph_old_syn_fx = 0; move16(); - st_fx->prev_fb_ener_adjust_fx = 0; + hBWE_FD->prev_fb_ener_adjust_fx = 0; move16(); return; @@ -1362,7 +1379,7 @@ Word16 swb_bwe_dec_fx32( move16(); } - Copy( st_fx->prev_SWB_fenv_fx, SWB_fenv_fx, SWB_FENV ); + Copy( hBWE_FD->prev_SWB_fenv_fx, SWB_fenv_fx, SWB_FENV ); } /* reconstruction of MDCT spectrum of the error signal */ @@ -1370,11 +1387,11 @@ Word16 swb_bwe_dec_fx32( IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { - SWB_BWE_decoding_fx( ysynth_fx, SWB_fenv_fx, yerror_fx, L_FRAME32k - 80, mode, &frica_flag, &hBWE_FD->prev_Energy_fx, st_fx->prev_SWB_fenv_fx, &hBWE_FD->prev_L_swb_norm, st_fx->tilt_wb_fx, &hBWE_FD->Seed, 80, &hBWE_FD->prev_weight_fx, st_fx->extl, Q_syn, st_fx->last_extl ); + SWB_BWE_decoding_fx( ysynth_fx, SWB_fenv_fx, yerror_fx, L_FRAME32k - 80, mode, &frica_flag, &hBWE_FD->prev_Energy_fx, hBWE_FD->prev_SWB_fenv_fx, &hBWE_FD->prev_L_swb_norm, st_fx->tilt_wb_fx, &hBWE_FD->Seed, 80, &hBWE_FD->prev_weight_fx, st_fx->extl, Q_syn, st_fx->last_extl ); } ELSE { - SWB_BWE_decoding_fx( ysynth_fx, SWB_fenv_fx, yerror_fx, L_FRAME32k - 80, mode, &frica_flag, &hBWE_FD->prev_Energy_fx, st_fx->prev_SWB_fenv_fx, &hBWE_FD->prev_L_swb_norm, st_fx->tilt_wb_fx, &hBWE_FD->Seed, 6, &hBWE_FD->prev_weight_fx, st_fx->extl, Q_syn, st_fx->last_extl ); + SWB_BWE_decoding_fx( ysynth_fx, SWB_fenv_fx, yerror_fx, L_FRAME32k - 80, mode, &frica_flag, &hBWE_FD->prev_Energy_fx, hBWE_FD->prev_SWB_fenv_fx, &hBWE_FD->prev_L_swb_norm, st_fx->tilt_wb_fx, &hBWE_FD->Seed, 6, &hBWE_FD->prev_weight_fx, st_fx->extl, Q_syn, st_fx->last_extl ); } test(); @@ -1404,11 +1421,11 @@ Word16 swb_bwe_dec_fx32( } ELSE IF( st_fx->bfi ) { - fb_ener_adjust_fx = st_fx->prev_fb_ener_adjust_fx; + fb_ener_adjust_fx = hBWE_FD->prev_fb_ener_adjust_fx; move16(); } - st_fx->prev_fb_ener_adjust_fx = fb_ener_adjust_fx; + hBWE_FD->prev_fb_ener_adjust_fx = fb_ener_adjust_fx; move16(); IF( EQ_16( mode, TRANSIENT ) ) { @@ -1544,35 +1561,3 @@ Word16 swb_bwe_dec_fx32( return Q_syn_hb; } - - -void fd_bwe_dec_init_fx( - FD_BWE_DEC_HANDLE hBWE_FD /* i/o: FD BWE data handle */ -) -{ - set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k ); - set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA_FX2( 16000, DELAY_FD_BWE_ENC_NS ) ); - hBWE_FD->prev_mode = NORMAL; - move16(); - hBWE_FD->prev_Energy_fx = 0; - move16(); - hBWE_FD->prev_L_swb_norm = 8; - move16(); - hBWE_FD->Seed = 21211; - move16(); - hBWE_FD->prev_frica_flag = 0; - move16(); - set16_fx( hBWE_FD->mem_imdct_fx, 0, L_FRAME48k ); - hBWE_FD->prev_td_energy_fx = 0; - move16(); - hBWE_FD->prev_weight_fx = 0; - move16(); - hBWE_FD->prev_flag = 0; - move16(); - hBWE_FD->prev_Energy_wb_fx = 0; - move32(); - hBWE_FD->mem_deemph_old_syn_fx = 0; - move16(); - - return; -} diff --git a/lib_dec/swb_bwe_dec_hr_fx.c b/lib_dec/swb_bwe_dec_hr_fx.c index 18867ce40bcd5d9ad0bb09e12c67b1212a9b31d0..9fae1ded560681fb2420b3bc487adbb7ab23ece4 100644 --- a/lib_dec/swb_bwe_dec_hr_fx.c +++ b/lib_dec/swb_bwe_dec_hr_fx.c @@ -1306,7 +1306,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB } FOR( i = 0; i < SWB_FENV; i++ ) { - st_fx->prev_SWB_fenv_fx[i] = st_fx->prev_ener_shb_fx; /*gain_e + 15*/ + st_fx->hBWE_FD->prev_SWB_fenv_fx[i] = st_fx->prev_ener_shb_fx; /*gain_e + 15*/ move16(); } diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index cc9b681fba0ff907e5ca3a4cd863242a66e6bba6..492c927b6e7fcf81fd3ce8eaedd017ab5b55660c 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -25,16 +25,8 @@ static void rescale_genWB_mem( Decoder_State *st_fx, Word16 sf ); static void Dequant_lower_LSF_fx( const Word16 lsf_idx[], Word16 lsf_q[] ); static void Map_higher_LSF_fx( Word16 lsf_q[], const Word16 m, const Word16 grid_in[] ); static void Dequant_mirror_point_fx( const Word16 lsf_q[], const Word16 m_idx, Word16 *m ); -Word16 dotp_loc( - const Word16 x[], /* i : vector x[] */ - const Word32 y[], /* i : vector y[] */ - const Word16 n /* i : vector length */ -); - -void find_max_mem_dec_m3( - Decoder_State *st, - Word16 *n_mem3 ); - +static Word16 dotp_loc( const Word16 x[], const Word32 y[], const Word16 n ); +static void find_max_mem_dec_m3( Decoder_State *st, Word16 *n_mem3 ); /* gain shape concealment code */ static void gradientGainShape( Decoder_State *st_fx, Word16 *GainShape, Word32 *GainFrame ); @@ -411,62 +403,14 @@ void rescale_genWB_mem( Decoder_State *st_fx, Word16 sf ) hBWE_TD->mem_csfilt_fx[i] = L_shl( hBWE_TD->mem_csfilt_fx[i], sf ); move32(); } -} - -void InitSWBdecBuffer_ivas_fx( - Decoder_State *st_fx /* i/o: SHB decoder structure */ -) -{ - TD_BWE_DEC_HANDLE hBWE_TD; - hBWE_TD = st_fx->hBWE_TD; - - set16_fx( hBWE_TD->old_bwe_exc_fx, 0, ( PIT16k_MAX * 2 ) ); - hBWE_TD->bwe_seed[0] = 23; - move16(); - hBWE_TD->bwe_seed[1] = 59; - move16(); - set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - hBWE_TD->bwe_non_lin_prev_scale_fx = 0; - move16(); - - set32_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, 0, HILBERT_MEM_SIZE ); - set16_fx( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, 0, 2 * ALLPASSSECTIONS_STEEP ); /* Interp all pass memory */ - set32_fx( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP ); /* Interp all pass memory */ - - hBWE_TD->syn_dm_phase = 0; - move16(); - hBWE_TD->prev_fbbwe_ratio_fx = 32767 /*1.0f Q15*/; - move16(); - - /* these are fd-bwe constants */ - hBWE_TD->prev_wb_bwe_frame_pow_fx = 4194l /*0.001f Q22*/; /* Q22 */ - move32(); - hBWE_TD->prev_swb_bwe_frame_pow_fx = 4194l /*0.001f Q22*/; /* Q22 */ - move32(); - st_fx->prev_Q_bwe_exc = 31; - move16(); - st_fx->prev_ener_fx_Q = 31; - move16(); - st_fx->prev_Qx = 0; - move16(); - st_fx->prev_frame_pow_exp = 0; - move16(); - st_fx->prev_Q_bwe_syn = 0; - move16(); - st_fx->prev_Q_bwe_syn2 = 0; - move16(); return; } -void InitSWBdecBuffer_fx( - Decoder_State *st_fx /* i/o: SHB decoder structure */ -) +static void InitSWBdecBuffer_fx( + TD_BWE_DEC_HANDLE hBWE_TD /* TD BWE data handle */ ) { - TD_BWE_DEC_HANDLE hBWE_TD; - hBWE_TD = st_fx->hBWE_TD; - set16_fx( hBWE_TD->old_bwe_exc_fx, 0, ( PIT16k_MAX * 2 ) ); hBWE_TD->bwe_seed[0] = 23; move16(); @@ -478,7 +422,8 @@ void InitSWBdecBuffer_fx( move16(); set32_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, 0, HILBERT_MEM_SIZE ); - set16_fx( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, 0, 2 * ALLPASSSECTIONS_STEEP ); /* Interp all pass memory */ + set16_fx( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, 0, 2 * ALLPASSSECTIONS_STEEP ); /* Interp all pass memory */ + set32_fx( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP ); /* Interp all pass memory */ hBWE_TD->syn_dm_phase = 0; move16(); @@ -490,31 +435,33 @@ void InitSWBdecBuffer_fx( move32(); hBWE_TD->prev_swb_bwe_frame_pow_fx = 4194l /*0.001f Q22*/; /* Q22 */ move32(); - st_fx->prev_Q_bwe_exc = 31; + hBWE_TD->prev_ener_fx_Q = 31; move16(); - st_fx->prev_ener_fx_Q = 31; + hBWE_TD->prev_Qx = 0; move16(); - st_fx->prev_Qx = 0; + hBWE_TD->prev_frame_pow_exp = 0; move16(); - st_fx->prev_frame_pow_exp = 0; + hBWE_TD->prev_Q_bwe_syn = 0; move16(); - st_fx->prev_Q_bwe_syn = 0; + hBWE_TD->prev_Q_bwe_syn2 = 0; move16(); - st_fx->prev_Q_bwe_syn2 = 0; + hBWE_TD->prev_hb_synth_fx_exp = 31; move16(); + return; } -void ResetSHBbuffer_Dec_fx( Decoder_State *st_fx /* i/o: SHB encoder structure */ ) +void ResetSHBbuffer_Dec_fx( + TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + const Word16 extl /* i : BWE extension layer */ +) { Word16 i; Word16 f; Word16 inc; - TD_BWE_DEC_HANDLE hBWE_TD; - hBWE_TD = st_fx->hBWE_TD; - IF( NE_16( st_fx->extl, WB_TBE ) ) + IF( NE_16( extl, WB_TBE ) ) { f = 1489; move16(); /* Q15 */ @@ -536,7 +483,7 @@ void ResetSHBbuffer_Dec_fx( Decoder_State *st_fx /* i/o: SHB encoder structure * set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); set16_fx( hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - IF( EQ_16( st_fx->extl, FB_TBE ) ) + IF( EQ_16( extl, FB_TBE ) ) { set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph_fx = 0; @@ -559,7 +506,7 @@ void ResetSHBbuffer_Dec_fx( Decoder_State *st_fx /* i/o: SHB encoder structure * /* States for FEC */ - IF( NE_16( st_fx->extl, WB_TBE ) ) + IF( NE_16( extl, WB_TBE ) ) { FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { @@ -595,7 +542,7 @@ void ResetSHBbuffer_Dec_fx( Decoder_State *st_fx /* i/o: SHB encoder structure * set16_fx( hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); hBWE_TD->gain_prec_swb_fx = 16384; /*Q14 =1*/ move16(); - set16_fx( &st_fx->GainShape_Delay[0], 0, NUM_SHB_SUBFR / 2 ); + set16_fx( hBWE_TD->GainShape_Delay_fx, 0, NUM_SHB_SUBFR / 2 ); hBWE_TD->prev_pow_exc16kWhtnd_fx32 = 1; /* Q0 1.f */ move32(); hBWE_TD->prev_mix_factor_fx = 32767; /*Q15 1.f*/ @@ -825,11 +772,11 @@ void ivas_wb_tbe_dec_fx( IF( EQ_32( st_fx->extl_brate, WB_TBE_0k35 ) ) { /* convert LSPs back into LP coeffs */ - lsp2lpc_fx( lpc_wb + 1, lsf_wb, st_fx->prev_lpc_wb_fx, LPC_SHB_ORDER_LBR_WB ); + lsp2lpc_fx( lpc_wb + 1, lsf_wb, hBWE_TD->prev_lpc_wb_fx, LPC_SHB_ORDER_LBR_WB ); set16_fx( lpc_wb + LPC_SHB_ORDER_LBR_WB + 1, 0, ( LPC_SHB_ORDER_WB - LPC_SHB_ORDER_LBR_WB ) ); FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { - st_fx->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; + hBWE_TD->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; move16(); } FOR( i = 1; i < LPC_SHB_ORDER_LBR_WB + 1; i++ ) @@ -843,10 +790,10 @@ void ivas_wb_tbe_dec_fx( ELSE { /* convert LSPs back into LP coeffs */ - lsp2lpc_fx( lpc_wb + 1, lsf_wb, st_fx->prev_lpc_wb_fx, LPC_SHB_ORDER_WB ); + lsp2lpc_fx( lpc_wb + 1, lsf_wb, hBWE_TD->prev_lpc_wb_fx, LPC_SHB_ORDER_WB ); FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { - st_fx->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; + hBWE_TD->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; move16(); } FOR( i = 1; i < LPC_SHB_ORDER_WB + 1; i++ ) @@ -1010,15 +957,15 @@ void ivas_wb_tbe_dec_fx( } curr_frame_pow_exp = add( n, n ); - IF( GT_16( st_fx->prev_frame_pow_exp, curr_frame_pow_exp ) ) + IF( GT_16( hBWE_TD->prev_frame_pow_exp, curr_frame_pow_exp ) ) { - curr_frame_pow = L_shr( curr_frame_pow, sub( st_fx->prev_frame_pow_exp, curr_frame_pow_exp ) ); - curr_frame_pow_exp = st_fx->prev_frame_pow_exp; + curr_frame_pow = L_shr( curr_frame_pow, sub( hBWE_TD->prev_frame_pow_exp, curr_frame_pow_exp ) ); + curr_frame_pow_exp = hBWE_TD->prev_frame_pow_exp; move16(); } ELSE { - hBWE_TD->prev_wb_bwe_frame_pow_fx = L_shr( hBWE_TD->prev_wb_bwe_frame_pow_fx, sub( curr_frame_pow_exp, st_fx->prev_frame_pow_exp ) ); + hBWE_TD->prev_wb_bwe_frame_pow_fx = L_shr( hBWE_TD->prev_wb_bwe_frame_pow_fx, sub( curr_frame_pow_exp, hBWE_TD->prev_frame_pow_exp ) ); move32(); } @@ -1074,7 +1021,7 @@ void ivas_wb_tbe_dec_fx( hBWE_TD->prev_wb_bwe_frame_pow_fx = curr_frame_pow; move32(); - st_fx->prev_frame_pow_exp = curr_frame_pow_exp; + hBWE_TD->prev_frame_pow_exp = curr_frame_pow_exp; move16(); /* generate 16kHz SHB signal (6 - 8 kHz) from 2kHz signal */ @@ -1132,8 +1079,10 @@ void ivas_wb_tbe_dec_fx( } n_mem = s_max( n_mem, 0 ); - if ( GT_16( sub( Qx, st_fx->prev_Qx ), n_mem ) ) - Qx = add( st_fx->prev_Qx, n_mem ); + if ( GT_16( sub( Qx, hBWE_TD->prev_Qx ), n_mem ) ) + { + Qx = add( hBWE_TD->prev_Qx, n_mem ); + } FOR( i = 0; i < ( L_FRAME16k + L_SHB_LAHEAD ) / 4; i++ ) { @@ -1143,13 +1092,13 @@ void ivas_wb_tbe_dec_fx( FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { - hBWE_TD->state_lsyn_filt_shb_fx[i] = shl( hBWE_TD->state_lsyn_filt_shb_fx[i], sub( Qx, st_fx->prev_Qx ) ); + hBWE_TD->state_lsyn_filt_shb_fx[i] = shl( hBWE_TD->state_lsyn_filt_shb_fx[i], sub( Qx, hBWE_TD->prev_Qx ) ); move16(); } FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { - hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] = shl( hBWE_TD->state_lsyn_filt_dwn_shb_fx[i], sub( Qx, st_fx->prev_Qx ) ); + hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] = shl( hBWE_TD->state_lsyn_filt_dwn_shb_fx[i], sub( Qx, hBWE_TD->prev_Qx ) ); move16(); } @@ -1163,56 +1112,58 @@ void ivas_wb_tbe_dec_fx( move16(); } - max = 0; - move16(); - FOR( cnt = 0; cnt < L_FRAME16k; cnt++ ) + IF( st_fx->hBWE_FD != NULL ) { - max = s_max( max, abs_s( synth[cnt] ) ); - } - - IF( max == 0 ) - { - st_fx->last_wb_bwe_ener_fx = 0; + max = 0; move16(); - } - ELSE - { - n = norm_s( max ); FOR( cnt = 0; cnt < L_FRAME16k; cnt++ ) { - synth_frac[cnt] = shl( synth[cnt], n ); /*Q14*/ - move16(); + max = s_max( max, abs_s( synth[cnt] ) ); } - n = sub( sub( 14, n ), Qx ); - Lacc = 0; - move32(); - FOR( i = 0; i < L_FRAME16k; i++ ) + IF( max == 0 ) { - L_tmp = L_mult( synth_frac[i], synth_frac[i] ); /* Q29 */ - Lacc = L_add( Lacc, L_shr( L_tmp, 7 ) ); /* Q22 */ + st_fx->hBWE_FD->last_wb_bwe_ener_fx = 0; + move16(); } + ELSE + { + n = norm_s( max ); + FOR( cnt = 0; cnt < L_FRAME16k; cnt++ ) + { + synth_frac[cnt] = shl( synth[cnt], n ); /*Q14*/ + move16(); + } + n = sub( sub( 14, n ), Qx ); - L_tmp = Mult_32_16( Lacc, 102 ); /* Q22 */ - exp = norm_l( L_tmp ); - tmp = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); - exp = sub( add( exp, 22 ), 30 ); - tmp = div_s( 16384, tmp ); - L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* Q(31-exp) */ - st_fx->last_wb_bwe_ener_fx = round_fx_sat( L_shl_sat( L_tmp, add( exp, sub( n, 12 ) ) ) ); /* Q3 */ - move16(); - } + Lacc = 0; + move32(); + FOR( i = 0; i < L_FRAME16k; i++ ) + { + L_tmp = L_mult( synth_frac[i], synth_frac[i] ); /* Q29 */ + Lacc = L_add( Lacc, L_shr( L_tmp, 7 ) ); /* Q22 */ + } + L_tmp = Mult_32_16( Lacc, 102 ); /* Q22 */ + exp = norm_l( L_tmp ); + tmp = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); + exp = sub( add( exp, 22 ), 30 ); + tmp = div_s( 16384, tmp ); + L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* Q(31-exp) */ + st_fx->hBWE_FD->last_wb_bwe_ener_fx = round_fx_sat( L_shl_sat( L_tmp, add( exp, sub( n, 12 ) ) ) ); /* Q3 */ + move16(); + } + } IF( EQ_32( st_fx->output_Fs, 32000 ) ) /* 32kHz sampling rate, but only WB output - interpolate */ { - Scale_sig( hBWE_TD->state_32and48k_WB_upsample_fx, 2 * ALLPASSSECTIONS_STEEP, sub( Qx, st_fx->prev_Qx ) ); + Scale_sig( hBWE_TD->state_32and48k_WB_upsample_fx, 2 * ALLPASSSECTIONS_STEEP, sub( Qx, hBWE_TD->prev_Qx ) ); Interpolate_allpass_steep_fx( synth, hBWE_TD->state_32and48k_WB_upsample_fx, L_FRAME16k, upsampled_synth ); Copy( upsampled_synth, synth, L_FRAME32k ); } ELSE IF( EQ_32( st_fx->output_Fs, 48000 ) ) { - Scale_sig( hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( Qx, st_fx->prev_Qx ) ); + Scale_sig( hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( Qx, hBWE_TD->prev_Qx ) ); ivas_interpolate_3_over_1_allpass_fx( synth, L_FRAME16k, upsampled_synth, hBWE_TD->mem_resamp_HB_fx ); Copy( upsampled_synth, synth, L_FRAME48k ); } @@ -1238,7 +1189,7 @@ void ivas_wb_tbe_dec_fx( move16(); hBWE_TD->prev_wb_bwe_frame_pow_fx = 4194l /*0.001f Q22*/; /* Q22 */ move32(); - st_fx->prev_frame_pow_exp = 0; + hBWE_TD->prev_frame_pow_exp = 0; move16(); } @@ -1265,7 +1216,7 @@ void ivas_wb_tbe_dec_fx( st_fx->prev_Q_bwe_exc = Q_bwe_exc; move16(); - st_fx->prev_Qx = Qx; + hBWE_TD->prev_Qx = Qx; move16(); return; @@ -1463,11 +1414,11 @@ void wb_tbe_dec_fx( IF( EQ_32( st_fx->extl_brate, WB_TBE_0k35 ) ) { /* convert LSPs back into LP coeffs */ - lsp2lpc_fx( lpc_wb + 1, lsf_wb, st_fx->prev_lpc_wb_fx, LPC_SHB_ORDER_LBR_WB ); + lsp2lpc_fx( lpc_wb + 1, lsf_wb, hBWE_TD->prev_lpc_wb_fx, LPC_SHB_ORDER_LBR_WB ); set16_fx( lpc_wb + LPC_SHB_ORDER_LBR_WB + 1, 0, LPC_SHB_ORDER_WB - LPC_SHB_ORDER_LBR_WB ); FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { - st_fx->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; + hBWE_TD->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; move16(); } FOR( i = 1; i < LPC_SHB_ORDER_LBR_WB + 1; i++ ) @@ -1481,10 +1432,10 @@ void wb_tbe_dec_fx( ELSE { /* convert LSPs back into LP coeffs */ - lsp2lpc_fx( lpc_wb + 1, lsf_wb, st_fx->prev_lpc_wb_fx, LPC_SHB_ORDER_WB ); + lsp2lpc_fx( lpc_wb + 1, lsf_wb, hBWE_TD->prev_lpc_wb_fx, LPC_SHB_ORDER_WB ); FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { - st_fx->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; + hBWE_TD->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; move16(); } FOR( i = 1; i < LPC_SHB_ORDER_WB + 1; i++ ) @@ -1648,15 +1599,15 @@ void wb_tbe_dec_fx( } curr_frame_pow_exp = add( n, n ); - IF( GT_16( st_fx->prev_frame_pow_exp, curr_frame_pow_exp ) ) + IF( GT_16( hBWE_TD->prev_frame_pow_exp, curr_frame_pow_exp ) ) { - curr_frame_pow = L_shr( curr_frame_pow, sub( st_fx->prev_frame_pow_exp, curr_frame_pow_exp ) ); - curr_frame_pow_exp = st_fx->prev_frame_pow_exp; + curr_frame_pow = L_shr( curr_frame_pow, sub( hBWE_TD->prev_frame_pow_exp, curr_frame_pow_exp ) ); + curr_frame_pow_exp = hBWE_TD->prev_frame_pow_exp; move16(); } ELSE { - hBWE_TD->prev_wb_bwe_frame_pow_fx = L_shr( hBWE_TD->prev_wb_bwe_frame_pow_fx, sub( curr_frame_pow_exp, st_fx->prev_frame_pow_exp ) ); + hBWE_TD->prev_wb_bwe_frame_pow_fx = L_shr( hBWE_TD->prev_wb_bwe_frame_pow_fx, sub( curr_frame_pow_exp, hBWE_TD->prev_frame_pow_exp ) ); move32(); } @@ -1710,7 +1661,7 @@ void wb_tbe_dec_fx( hBWE_TD->prev_wb_bwe_frame_pow_fx = curr_frame_pow; move32(); - st_fx->prev_frame_pow_exp = curr_frame_pow_exp; + hBWE_TD->prev_frame_pow_exp = curr_frame_pow_exp; move16(); /* generate 16kHz SHB signal (6 - 8 kHz) from 2kHz signal */ @@ -1737,13 +1688,17 @@ void wb_tbe_dec_fx( FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { if ( GT_16( abs_s( hBWE_TD->state_lsyn_filt_shb_fx[i] ), max ) ) + { max = abs_s( hBWE_TD->state_lsyn_filt_shb_fx[i] ); + } } FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { if ( GT_16( abs_s( hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] ), max ) ) + { max = abs_s( hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] ); + } } IF( EQ_32( st_fx->output_Fs, 32000 ) ) @@ -1768,8 +1723,10 @@ void wb_tbe_dec_fx( } n_mem = s_max( n_mem, 0 ); - if ( GT_16( sub( Qx, st_fx->prev_Qx ), n_mem ) ) - Qx = add( st_fx->prev_Qx, n_mem ); + if ( GT_16( sub( Qx, hBWE_TD->prev_Qx ), n_mem ) ) + { + Qx = add( hBWE_TD->prev_Qx, n_mem ); + } FOR( i = 0; i < ( L_FRAME16k + L_SHB_LAHEAD ) / 4; i++ ) { @@ -1779,13 +1736,13 @@ void wb_tbe_dec_fx( FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { - hBWE_TD->state_lsyn_filt_shb_fx[i] = shl( hBWE_TD->state_lsyn_filt_shb_fx[i], sub( Qx, st_fx->prev_Qx ) ); + hBWE_TD->state_lsyn_filt_shb_fx[i] = shl( hBWE_TD->state_lsyn_filt_shb_fx[i], sub( Qx, hBWE_TD->prev_Qx ) ); move16(); } FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { - hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] = shl( hBWE_TD->state_lsyn_filt_dwn_shb_fx[i], sub( Qx, st_fx->prev_Qx ) ); + hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] = shl( hBWE_TD->state_lsyn_filt_dwn_shb_fx[i], sub( Qx, hBWE_TD->prev_Qx ) ); move16(); } @@ -1799,56 +1756,58 @@ void wb_tbe_dec_fx( move16(); } - max = 0; - move16(); - FOR( cnt = 0; cnt < L_FRAME16k; cnt++ ) + IF( st_fx->hBWE_FD != NULL ) { - max = s_max( max, abs_s( synth[cnt] ) ); - } - - IF( max == 0 ) - { - st_fx->last_wb_bwe_ener_fx = 0; + max = 0; move16(); - } - ELSE - { - n = norm_s( max ); FOR( cnt = 0; cnt < L_FRAME16k; cnt++ ) { - synth_frac[cnt] = shl( synth[cnt], n ); /*Q14*/ - move16(); + max = s_max( max, abs_s( synth[cnt] ) ); } - n = sub( sub( 14, n ), Qx ); - Lacc = 0; - move32(); - FOR( i = 0; i < L_FRAME16k; i++ ) + IF( max == 0 ) { - L_tmp = L_mult( synth_frac[i], synth_frac[i] ); /* Q29 */ - Lacc = L_add( Lacc, L_shr( L_tmp, 7 ) ); /* Q22 */ + st_fx->hBWE_FD->last_wb_bwe_ener_fx = 0; + move16(); } + ELSE + { + n = norm_s( max ); + FOR( cnt = 0; cnt < L_FRAME16k; cnt++ ) + { + synth_frac[cnt] = shl( synth[cnt], n ); /*Q14*/ + move16(); + } + n = sub( sub( 14, n ), Qx ); - L_tmp = Mult_32_16( Lacc, 102 ); /* Q22 */ - exp = norm_l( L_tmp ); - tmp = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); - exp = sub( add( exp, 22 ), 30 ); - tmp = div_s( 16384, tmp ); - L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* Q(31-exp) */ - st_fx->last_wb_bwe_ener_fx = round_fx_sat( L_shl_sat( L_tmp, add( exp, sub( n, 12 ) ) ) ); /* Q3 */ - move16(); - } + Lacc = 0; + move32(); + FOR( i = 0; i < L_FRAME16k; i++ ) + { + L_tmp = L_mult( synth_frac[i], synth_frac[i] ); /* Q29 */ + Lacc = L_add( Lacc, L_shr( L_tmp, 7 ) ); /* Q22 */ + } + L_tmp = Mult_32_16( Lacc, 102 ); /* Q22 */ + exp = norm_l( L_tmp ); + tmp = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); + exp = sub( add( exp, 22 ), 30 ); + tmp = div_s( 16384, tmp ); + L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* Q(31-exp) */ + st_fx->hBWE_FD->last_wb_bwe_ener_fx = round_fx_sat( L_shl_sat( L_tmp, add( exp, sub( n, 12 ) ) ) ); /* Q3 */ + move16(); + } + } IF( EQ_32( st_fx->output_Fs, 32000 ) ) /* 32kHz sampling rate, but only WB output - interpolate */ { - Scale_sig( hBWE_TD->state_32and48k_WB_upsample_fx, 2 * ALLPASSSECTIONS_STEEP, sub( Qx, st_fx->prev_Qx ) ); + Scale_sig( hBWE_TD->state_32and48k_WB_upsample_fx, 2 * ALLPASSSECTIONS_STEEP, sub( Qx, hBWE_TD->prev_Qx ) ); Interpolate_allpass_steep_fx( synth, hBWE_TD->state_32and48k_WB_upsample_fx, L_FRAME16k, upsampled_synth ); Copy( upsampled_synth, synth, L_FRAME32k ); } ELSE IF( EQ_32( st_fx->output_Fs, 48000 ) ) { - Scale_sig( hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( Qx, st_fx->prev_Qx ) ); + Scale_sig( hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( Qx, hBWE_TD->prev_Qx ) ); interpolate_3_over_1_allpass_fx( synth, L_FRAME16k, upsampled_synth, hBWE_TD->mem_resamp_HB_fx ); Copy( upsampled_synth, synth, L_FRAME48k ); } @@ -1874,7 +1833,7 @@ void wb_tbe_dec_fx( move16(); hBWE_TD->prev_wb_bwe_frame_pow_fx = 4194l /*0.001f Q22*/; /* Q22 */ move32(); - st_fx->prev_frame_pow_exp = 0; + hBWE_TD->prev_frame_pow_exp = 0; move16(); } @@ -1901,7 +1860,7 @@ void wb_tbe_dec_fx( st_fx->prev_Q_bwe_exc = Q_bwe_exc; move16(); - st_fx->prev_Qx = Qx; + hBWE_TD->prev_Qx = Qx; move16(); return; @@ -2014,7 +1973,7 @@ void swb_tbe_dec_fx( move16(); shb_ener_sf_32 = L_deposit_l( 0 ); set16_fx( shaped_shb_excitationTemp, 0, L_FRAME16k ); - st_fx->shb_dtx_count_fx = 0; + st_fx->hTdCngDec->shb_dtx_count_fx = 0; move16(); is_fractive = 0; move16(); @@ -2269,7 +2228,7 @@ void swb_tbe_dec_fx( { FOR( j = 0; j < 4; j++ ) { - GainShape[add( i * 4, j )] = mult_r( st_fx->cummulative_damping, st_fx->GainShape_Delay[4 + i] ); + GainShape[add( i * 4, j )] = mult_r( st_fx->cummulative_damping, hBWE_TD->GainShape_Delay_fx[4 + i] ); move16(); } } @@ -2374,13 +2333,13 @@ void swb_tbe_dec_fx( } /* get the gainshape delay */ - Copy( &st_fx->GainShape_Delay[4], &st_fx->GainShape_Delay[0], NUM_SHB_SUBFR / 4 ); + Copy( &hBWE_TD->GainShape_Delay_fx[4], &hBWE_TD->GainShape_Delay_fx[0], NUM_SHB_SUBFR / 4 ); test(); IF( ( st_fx->rf_flag != 0 ) || EQ_32( st_fx->total_brate, ACELP_9k60 ) ) { FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { - st_fx->GainShape_Delay[i + 4] = s_min( s_max( GainShape[i * 4], 3277 /*0.1f Q15*/ ), 16384 /*0.5f Q15*/ ); + hBWE_TD->GainShape_Delay_fx[i + 4] = s_min( s_max( GainShape[i * 4], 3277 /*0.1f Q15*/ ), 16384 /*0.5f Q15*/ ); move16(); } } @@ -2388,7 +2347,7 @@ void swb_tbe_dec_fx( { FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { - st_fx->GainShape_Delay[i + 4] = GainShape[i * 4]; + hBWE_TD->GainShape_Delay_fx[i + 4] = GainShape[i * 4]; move16(); } } @@ -2600,8 +2559,11 @@ void swb_tbe_dec_fx( move16(); /* SWB CNG/DTX - update memories */ - Copy( st_fx->lsp_shb_prev_fx, st_fx->lsp_shb_prev_prev_fx, LPC_SHB_ORDER ); /* Q15 */ - Copy( lsf_shb, st_fx->lsp_shb_prev_fx, LPC_SHB_ORDER ); /* Q15 */ + if ( st_fx->hTdCngDec != NULL ) + { + Copy( st_fx->hTdCngDec->lsp_shb_prev_fx, st_fx->hTdCngDec->lsp_shb_prev_prev_fx, LPC_SHB_ORDER ); /* Q15 */ + Copy( lsf_shb, st_fx->hTdCngDec->lsp_shb_prev_fx, LPC_SHB_ORDER ); /* Q15 */ + } /* vind = (short)(mixFactors*8.0f); */ vind = shl( mixFactors, 3 - 15 ); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ @@ -2665,7 +2627,7 @@ void swb_tbe_dec_fx( Q_bwe_exc = sub( Q_bwe_exc, 16 ); /* Q_bwe_exc reflecting the single precision dynamic norm-ed buffers from here */ /* -------- end of rescaling memories -------- */ - Q_bwe_exc_fb = st_fx->prev_Q_bwe_exc_fb; + Q_bwe_exc_fb = hBWE_TD->prev_Q_bwe_exc_fb; move16(); IF( GT_32( st_fx->total_brate, ACELP_32k ) ) @@ -2682,26 +2644,26 @@ void swb_tbe_dec_fx( coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified, st_fx->extl, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf, shb_ener_sf_32, shb_res_gshape, shb_res_dummy, &vind, formant_fac, hBWE_TD->fb_state_lpc_syn_fx, - &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, st_fx->prev_Q_bwe_syn, st_fx->total_brate, st_fx->prev_bfi ); + &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, hBWE_TD->prev_Q_bwe_syn, st_fx->total_brate, st_fx->prev_bfi ); *Q_white_exc = Q_bwe_exc_fb; move16(); IF( EQ_16( st_fx->extl, FB_TBE ) ) { - st_fx->prev_Q_bwe_exc_fb = Q_bwe_exc_fb; + hBWE_TD->prev_Q_bwe_exc_fb = Q_bwe_exc_fb; move16(); } ELSE { /*Indirectly a memory reset of FB memories for next frame such that rescaling of memories would lead to 0 due to such high prev. Q value. 51 because of 31 + 20(shift of Q_bwe_exc_fb before de-emphasis)*/ - st_fx->prev_Q_bwe_exc_fb = 51; + hBWE_TD->prev_Q_bwe_exc_fb = 51; move16(); } /* rescale the TBE post proc memory */ FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->mem_stp_swb_fx[i] = shl( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, st_fx->prev_Q_bwe_syn ) ); + hBWE_TD->mem_stp_swb_fx[i] = shl( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_syn ) ); move16(); } @@ -2727,11 +2689,7 @@ void swb_tbe_dec_fx( curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc) */ } - Lscale = root_a_over_b_fx( curr_pow, - shl( Q_bwe_exc, 1 ), - prev_pow, - shl( Q_bwe_exc, 1 ), - &exp ); + Lscale = root_a_over_b_fx( curr_pow, shl( Q_bwe_exc, 1 ), prev_pow, shl( Q_bwe_exc, 1 ), &exp ); FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { @@ -3060,7 +3018,7 @@ void swb_tbe_dec_fx( /* if( ener_tmp_fx[i]*GainShape_tmp_fx[i] > st_fx->prev_ener_fx*st_fx->prev_GainShape_fx ) */ L_tmp1 = Mult_32_16( ener_tmp[i], GainShape_tmp[i] ); /* (2*Q_bwe_exc) */ L_tmp2 = Mult_32_16( hBWE_TD->prev_ener_fx, hBWE_TD->prev_GainShape_fx ); /* (2*st_fx->prev_ener_fx_Q) */ - tmp = sub( shl( Q_bwe_exc, 1 ), shl( st_fx->prev_ener_fx_Q, 1 ) ); + tmp = sub( shl( Q_bwe_exc, 1 ), shl( hBWE_TD->prev_ener_fx_Q, 1 ) ); L_tmp2 = L_shl_sat( L_tmp2, tmp ); /* new Q = (2*Q_bwe_exc) */ IF( GT_32( L_tmp1, L_tmp2 ) ) { @@ -3096,7 +3054,7 @@ void swb_tbe_dec_fx( move32(); hBWE_TD->prev_GainShape_fx = GainShape_tmp[i]; move16(); - st_fx->prev_ener_fx_Q = Q_bwe_exc; + hBWE_TD->prev_ener_fx_Q = Q_bwe_exc; move16(); } FOR( i = 0; i < NUM_SHB_SUBFR; i++ ) @@ -3113,13 +3071,13 @@ void swb_tbe_dec_fx( } ELSE { - st_fx->prev_ener_fx_Q = Q_bwe_exc; + hBWE_TD->prev_ener_fx_Q = Q_bwe_exc; move16(); } /* Back up the Q_bwe_exc associated with shaped_shb_excitation for the next frame*/ - st_fx->prev_Q_bwe_syn = Q_bwe_exc; + hBWE_TD->prev_Q_bwe_syn = Q_bwe_exc; move16(); /* Scale the shaped excitation */ @@ -3130,13 +3088,7 @@ void swb_tbe_dec_fx( GainFrame, /* Q18 */ window_shb_fx, subwin_shb_fx, - &Q_bwe_exc, &Qx, n_mem3, st_fx->prev_Q_bwe_syn2 ); - /* i: GainShape Q15 */ - /* i: GainFrame Q18 */ - /* i: shaped_shb_excitation Q_bwe_exc */ - /* o: shaped_shb_excitation Q_bwe_exc */ - /* o: st_fx->syn_overlap_fx Q_bwe_exc */ - + &Q_bwe_exc, &Qx, n_mem3, hBWE_TD->prev_Q_bwe_syn2 ); max = 0; move16(); @@ -3174,31 +3126,31 @@ void swb_tbe_dec_fx( curr_frame_pow_exp = sub( shl( add( Q_bwe_exc, n ), 1 ), 9 ); - tmp = sub( st_fx->prev_frame_pow_exp, curr_frame_pow_exp ); + tmp = sub( hBWE_TD->prev_frame_pow_exp, curr_frame_pow_exp ); IF( tmp > 0 ) /* shifting prev */ { IF( GT_16( tmp, 32 ) ) { - st_fx->prev_frame_pow_exp = add( curr_frame_pow_exp, 32 ); + hBWE_TD->prev_frame_pow_exp = add( curr_frame_pow_exp, 32 ); move16(); tmp = 32; move16(); } hBWE_TD->prev_swb_bwe_frame_pow_fx = L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, tmp ); move32(); - st_fx->prev_frame_pow_exp = curr_frame_pow_exp; + hBWE_TD->prev_frame_pow_exp = curr_frame_pow_exp; move16(); } ELSE /* shifting curr */ { IF( LT_16( tmp, -32 ) ) { - curr_frame_pow_exp = sub( st_fx->prev_frame_pow_exp, 32 ); + curr_frame_pow_exp = sub( hBWE_TD->prev_frame_pow_exp, 32 ); tmp = -32; move16(); } curr_frame_pow = L_shr( curr_frame_pow, -tmp ); - curr_frame_pow_exp = st_fx->prev_frame_pow_exp; + curr_frame_pow_exp = hBWE_TD->prev_frame_pow_exp; move16(); } test(); @@ -3363,10 +3315,9 @@ void swb_tbe_dec_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx = curr_frame_pow; move32(); - st_fx->prev_frame_pow_exp = curr_frame_pow_exp; + hBWE_TD->prev_frame_pow_exp = curr_frame_pow_exp; move16(); - { Word64 prev_ener_shb64 = 0; move64(); @@ -3377,7 +3328,6 @@ void swb_tbe_dec_fx( L_prev_ener_shb = W_sat_l( prev_ener_shb64 ); } - /* st->prev_ener_shb = sqrt(st->prev_ener_shb/L_FRAME16k) */ L_prev_ener_shb = Mult_32_16( L_prev_ener_shb, 26214 ); /* 2*Q_bwe_exc_mod+8; 26214=(1/L_FRAME16k) in Q23 */ st_fx->prev_ener_shb_fx = 0; @@ -3410,11 +3360,10 @@ void swb_tbe_dec_fx( L_tmp = Isqrt_lc( L_tmp, &exp ); tmp = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ } - set16_fx( st_fx->prev_SWB_fenv_fx, tmp, SWB_FENV ); /* Q1 */ - + set16_fx( st_fx->hBWE_FD->prev_SWB_fenv_fx, tmp, SWB_FENV ); /* Q1 */ /* rescale the memories if Q_bwe_exc is different from previous frame */ - sc = sub( Q_bwe_exc, st_fx->prev_Q_bwe_syn2 ); + sc = sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_syn2 ); IF( sc != 0 ) { FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) @@ -3577,10 +3526,11 @@ void swb_tbe_dec_fx( move32(); *Q_synth = Q_bwe_exc; move16(); - st_fx->prev_Q_bwe_syn2 = Q_bwe_exc; + hBWE_TD->prev_Q_bwe_syn2 = Q_bwe_exc; move16(); - st_fx->prev_Qx = Q_bwe_exc; + hBWE_TD->prev_Qx = Q_bwe_exc; move16(); + return; } @@ -3600,9 +3550,9 @@ static void gradientGainShape( /* the previous frame gainshape gradient and the gainshape gradient pattern for the current frame */ FOR( j = 0; j < 3; j++ ) { - GainGrad0[j] = sub( shr( st_fx->GainShape_Delay[j + 1], 1 ), shr( st_fx->GainShape_Delay[j], 1 ) ); + GainGrad0[j] = sub( shr( hBWE_TD->GainShape_Delay_fx[j + 1], 1 ), shr( hBWE_TD->GainShape_Delay_fx[j], 1 ) ); move16(); /* Q14 */ - GainGrad1[j] = sub( shr( st_fx->GainShape_Delay[j + 5], 1 ), shr( st_fx->GainShape_Delay[j + 4], 1 ) ); + GainGrad1[j] = sub( shr( hBWE_TD->GainShape_Delay_fx[j + 5], 1 ), shr( hBWE_TD->GainShape_Delay_fx[j + 4], 1 ) ); move16(); /* Q14 */ GainGradFEC[j + 1] = add( mult_r( GainGrad0[j], 13107 ), mult_r( GainGrad1[j], 19660 ) ); move16(); /* Q14 */ @@ -3631,17 +3581,17 @@ static void gradientGainShape( test(); IF( ( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) ) && ( GainGradFEC[0] > 0 ) ) { - GainShapeTemp[0] = add( shr( st_fx->GainShape_Delay[7], 1 ), GainGradFEC[0] ); + GainShapeTemp[0] = add( shr( hBWE_TD->GainShape_Delay_fx[7], 1 ), GainGradFEC[0] ); move16(); } ELSE IF( GainGradFEC[0] > 0 ) { - GainShapeTemp[0] = add( shr( st_fx->GainShape_Delay[7], 1 ), mult_r( GainGradFEC[0], 16384 ) ); + GainShapeTemp[0] = add( shr( hBWE_TD->GainShape_Delay_fx[7], 1 ), mult_r( GainGradFEC[0], 16384 ) ); move16(); /* Q14 */ } ELSE { - GainShapeTemp[0] = shr( st_fx->GainShape_Delay[7], 1 ); + GainShapeTemp[0] = shr( hBWE_TD->GainShape_Delay_fx[7], 1 ); move16(); /* Q14 */ } @@ -3874,7 +3824,9 @@ static void Dequant_mirror_point_fx( return; } -Word16 dotp_loc( + + +static Word16 dotp_loc( const Word16 x[], /* i : vector x[] Qx */ const Word32 y[], /* i : vector y[] Qy */ const Word16 n /* i : vector length */ @@ -4893,35 +4845,33 @@ void tbe_read_bitstream_fx( * buffer to fill the gap caused by the delay alignment buffer when * switching from TBE to IGF *---------------------------------------------------------------------*/ + void GenTransition_fx( - const Word16 *input, /* i : gain shape overlap buffer Q11 */ - const Word16 *old_hb_synth, /* i : synthesized HB from previous frame Q(15 - hb_synth_fx_exp)*/ - Word16 length, /* i : targeted length of transition signal */ - Word16 *output, /* o : synthesized transitions signal st_fx->prev_Q_bwe_syn2 */ - Word32 Hilbert_Mem[], /* i/o: memory st_fx->prev_Q_bwe_syn2 */ - Word16 state_lsyn_filt_shb_local[], /* i/o: memory st_fx->prev_Q_bwe_syn2*/ - Word16 mem_resamp_HB_32k[], /* i/o: memory */ - Word16 *syn_dm_phase, - Word32 target_fs, - Word16 *up_mem, - Word16 rf_flag, - Word32 bitrate ) + TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + Word16 *output_HB, /* o : synthesized HB transitions signal st_fx->prev_Q_bwe_syn2 */ + const Word32 output_Fs, /* i : output sampling rate */ + Word16 rf_flag, /* i : RF flag */ + Word32 total_bitrate /* i : total bitrate */ +) { - Word16 i; + Word16 i, length; Word16 syn_overlap_32k[L_FRAME32k]; Word32 L_tmp; Word16 ol_len = 2 * SHB_OVERLAP_LEN; + /* set targeted length of transition signal */ + length = shl( NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ), 1 ); + /* upsample overlap snippet */ - Interpolate_allpass_steep_fx( input, state_lsyn_filt_shb_local, SHB_OVERLAP_LEN, syn_overlap_32k ); + Interpolate_allpass_steep_fx( hBWE_TD->syn_overlap_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, SHB_OVERLAP_LEN, syn_overlap_32k ); /* perform spectral flip and downmix with overlap snippet to match HB synth */ test(); - IF( ( rf_flag != 0 ) || EQ_32( bitrate, ACELP_9k60 ) ) + IF( ( rf_flag != 0 ) || EQ_32( total_bitrate, ACELP_9k60 ) ) { - flip_and_downmix_generic_fx( syn_overlap_32k, syn_overlap_32k, 2 * SHB_OVERLAP_LEN, Hilbert_Mem, - Hilbert_Mem + HILBERT_ORDER1, Hilbert_Mem + ( HILBERT_ORDER1 + 2 * HILBERT_ORDER2 ), - syn_dm_phase ); + flip_and_downmix_generic_fx( syn_overlap_32k, syn_overlap_32k, 2 * SHB_OVERLAP_LEN, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, + hBWE_TD->genSHBsynth_Hilbert_Mem_fx + HILBERT_ORDER1, hBWE_TD->genSHBsynth_Hilbert_Mem_fx + ( HILBERT_ORDER1 + 2 * HILBERT_ORDER2 ), + &( hBWE_TD->syn_dm_phase ) ); } ELSE { @@ -4937,25 +4887,91 @@ void GenTransition_fx( /* cross fade of overlap snippet and mirrored HB synth from previous frame */ FOR( i = 0; i < ol_len; i++ ) { - L_tmp = L_mult( window_shb_32k_fx[i], old_hb_synth[L_SHB_TRANSITION_LENGTH - 1 - i] ); - output[i] = mac_r( L_tmp, window_shb_32k_fx[2 * L_SHB_LAHEAD - 1 - i], syn_overlap_32k[i] ); + L_tmp = L_mult( window_shb_32k_fx[i], hBWE_TD->old_tbe_synth_fx[L_SHB_TRANSITION_LENGTH - 1 - i] ); + output_HB[i] = mac_r( L_tmp, window_shb_32k_fx[2 * L_SHB_LAHEAD - 1 - i], syn_overlap_32k[i] ); move16(); } /* fill transition signal with mirrored HB synth from previous frame to fully fill delay alignment buffer gap */ FOR( ; i < length; i++ ) { - output[i] = old_hb_synth[L_SHB_TRANSITION_LENGTH - 1 - i]; + output_HB[i] = hBWE_TD->old_tbe_synth_fx[L_SHB_TRANSITION_LENGTH - 1 - i]; move16(); } - IF( EQ_32( target_fs, 48000 ) ) + IF( EQ_32( output_Fs, 48000 ) ) + { + interpolate_3_over_2_allpass_fx( output_HB, length, output_HB, hBWE_TD->int_3_over_2_tbemem_dec_fx, allpass_poles_3_ov_2 ); + } + ELSE IF( EQ_32( output_Fs, 16000 ) ) + { + Decimate_allpass_steep_fx( output_HB, hBWE_TD->mem_resamp_HB_32k_fx, L_FRAME32k, output_HB ); + } + + return; +} + +/* IVAS 32-bit variant */ +void GenTransition_fx32( + TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */ + const Word32 output_Fs, /* i : output sampling rate : Q0 */ + const Word16 L_frame, /* i : ACELP frame length : Q0 */ + const Word16 prev_Qx ) +{ + Word16 i, length; + + Word32 syn_overlap_32k_fx[2 * SHB_OVERLAP_LEN]; + + /* set targeted length of transition signal */ + length = i_mult( 2, NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ) ); + + /* upsample overlap snippet */ + Interpolate_allpass_steep_fx32( hBWE_TD->syn_overlap_fx_32, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, SHB_OVERLAP_LEN, syn_overlap_32k_fx ); + + /* perform spectral flip and downmix with overlap snippet to match HB synth */ + test(); + IF( EQ_16( L_frame, L_FRAME ) ) + { + flip_and_downmix_generic_fx32( syn_overlap_32k_fx, syn_overlap_32k_fx, 2 * SHB_OVERLAP_LEN, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_Hilbert_Mem_fx + HILBERT_ORDER1, hBWE_TD->genSHBsynth_Hilbert_Mem_fx + ( HILBERT_ORDER1 + 2 * HILBERT_ORDER2 ), &( hBWE_TD->syn_dm_phase ) ); + } + ELSE + { + FOR( i = 0; i < 2 * SHB_OVERLAP_LEN; i++ ) + { + IF( i % 2 == 0 ) + { + syn_overlap_32k_fx[i] = L_negate( syn_overlap_32k_fx[i] ); + } + ELSE + { + syn_overlap_32k_fx[i] = syn_overlap_32k_fx[i]; + } + move32(); + } + } + + /* cross fade of overlap snippet and mirrored HB synth from previous frame */ + FOR( i = 0; i < 2 * L_SHB_LAHEAD; i++ ) + { + outputHB_fx[i] = L_add_sat( Mpy_32_16_1( hBWE_TD->old_tbe_synth_fx_32[L_SHB_TRANSITION_LENGTH - 1 - i], window_shb_32k_fx[i] ), Mpy_32_16_1( syn_overlap_32k_fx[i], window_shb_32k_fx[2 * L_SHB_LAHEAD - 1 - i] ) ); + move32(); + } + + /* fill transition signal with mirrored HB synth from previous frame to fully fill delay alignment buffer gap */ + FOR( ; i < length; i++ ) + { + outputHB_fx[i] = L_shl( hBWE_TD->old_tbe_synth_fx[L_SHB_TRANSITION_LENGTH - 1 - i], sub( Q11, prev_Qx ) ); + move32(); + } + + IF( EQ_32( output_Fs, 48000 ) ) { - interpolate_3_over_2_allpass_fx( output, length, output, up_mem, allpass_poles_3_ov_2 ); + interpolate_3_over_2_allpass_fx32( outputHB_fx, length, outputHB_fx, hBWE_TD->int_3_over_2_tbemem_dec_fx_32 ); } - ELSE IF( EQ_32( target_fs, 16000 ) ) + ELSE IF( EQ_32( output_Fs, 16000 ) ) { - Decimate_allpass_steep_fx( output, mem_resamp_HB_32k, L_FRAME32k, output ); + Decimate_allpass_steep_fx32( outputHB_fx, hBWE_TD->mem_resamp_HB_32k_fx_32, L_FRAME32k, outputHB_fx ); } return; @@ -4963,32 +4979,29 @@ void GenTransition_fx( /*---------------------------------------------------------------------* - * GenTransition_WB_fx() + * GenTransition_WB() * *---------------------------------------------------------------------*/ void GenTransition_WB_fx( - const Word16 *input, /* i : gain shape overlap buffer */ - const Word16 *old_hb_synth, /* i : synthesized HB from previous frame */ - const Word16 prev_Qx, /* i : scaling of old_hb_synth */ - Word16 length, /* i : targeted length of transition signal */ - Word16 *output, /* o : synthesized transitions signal */ - Word16 state_lsyn_filt_shb1[], - Word16 state_lsyn_filt_shb2[], - Word32 output_Fs, - Word16 *up_mem ) + TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + Word16 *output, /* o : synthesized transitions signal */ + const Word32 output_Fs /* i : output sampling rate */ +) { - Word16 i; + Word16 i, length; Word32 L_tmp; Word16 speech_buf_16k1[L_FRAME16k], speech_buf_16k2[L_FRAME16k]; Word16 upsampled_synth[L_FRAME48k]; Word16 input_scaled[SHB_OVERLAP_LEN / 2]; - /* upsample overlap snippet */ - Copy_Scale_sig( input, input_scaled, SHB_OVERLAP_LEN / 2, prev_Qx ); - Interpolate_allpass_steep_fx( input_scaled, state_lsyn_filt_shb1, SHB_OVERLAP_LEN / 2, speech_buf_16k1 ); - Interpolate_allpass_steep_fx( speech_buf_16k1, state_lsyn_filt_shb2, SHB_OVERLAP_LEN, speech_buf_16k2 ); + /* set targeted length of transition signal */ + length = shl( NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ), 1 ); + /* upsample overlap snippet */ + Copy_Scale_sig( hBWE_TD->syn_overlap_fx, input_scaled, SHB_OVERLAP_LEN / 2, hBWE_TD->prev_Qx ); + Interpolate_allpass_steep_fx( input_scaled, hBWE_TD->state_lsyn_filt_shb_fx, SHB_OVERLAP_LEN / 2, speech_buf_16k1 ); + Interpolate_allpass_steep_fx( speech_buf_16k1, hBWE_TD->state_lsyn_filt_dwn_shb_fx, SHB_OVERLAP_LEN, speech_buf_16k2 ); /* perform spectral flip and downmix with overlap snippet to match HB synth */ FOR( i = 0; i < SHB_OVERLAP_LEN; i += 2 ) @@ -5000,7 +5013,7 @@ void GenTransition_WB_fx( /* cross fade of overlap snippet and mirrored HB synth from previous frame */ FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { - L_tmp = L_mult( window_shb_fx[i], old_hb_synth[L_SHB_TRANSITION_LENGTH - 1 - i] ); + L_tmp = L_mult( window_shb_fx[i], hBWE_TD->old_tbe_synth_fx[L_SHB_TRANSITION_LENGTH - 1 - i] ); output[i] = mac_r( L_tmp, window_shb_fx[L_SHB_LAHEAD - 1 - i], speech_buf_16k2[i] ); move16(); output[i] = mult_r( output[i], 21299 ); @@ -5010,105 +5023,116 @@ void GenTransition_WB_fx( /* fill transition signal with mirrored HB synth from previous frame to fully fill delay alignment buffer gap */ FOR( ; i < length; i++ ) { - output[i] = mult_r( old_hb_synth[L_SHB_TRANSITION_LENGTH - 1 - i], 21299 ); + output[i] = mult_r( hBWE_TD->old_tbe_synth_fx[L_SHB_TRANSITION_LENGTH - 1 - i], 21299 ); move16(); } /* upsampling if necessary */ IF( EQ_32( output_Fs, 32000 ) ) { - Interpolate_allpass_steep_fx( output, up_mem, L_FRAME16k, upsampled_synth ); + Interpolate_allpass_steep_fx( output, hBWE_TD->mem_resamp_HB_fx, L_FRAME16k, upsampled_synth ); Copy( upsampled_synth, output, L_FRAME32k ); } ELSE IF( EQ_32( output_Fs, 48000 ) ) { - interpolate_3_over_1_allpass_fx( output, L_FRAME16k, upsampled_synth, up_mem ); + interpolate_3_over_1_allpass_fx( output, L_FRAME16k, upsampled_synth, hBWE_TD->mem_resamp_HB_fx ); Copy( upsampled_synth, output, L_FRAME48k ); } return; } -/*---------------------------------------------------------------------* - * TBEreset_dec_fx() - * - *---------------------------------------------------------------------*/ -void TBEreset_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 bandwidth /* i : bandwidth mode */ +/* IVAS 32-bit variant */ +void GenTransition_WB_fx32( + TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */ + const Word32 output_Fs /* i : output sampling rate */ ) { - TD_BWE_DEC_HANDLE hBWE_TD; - hBWE_TD = st_fx->hBWE_TD; + Word16 i, length; + Word32 speech_buf_16k1_fx[SHB_OVERLAP_LEN], speech_buf_16k2_fx[2 * SHB_OVERLAP_LEN]; + Word32 upsampled_synth_fx[L_FRAME48k]; - IF( NE_16( st_fx->last_core, ACELP_CORE ) ) + /* set targeted length of transition signal */ + length = i_mult( 2, NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ) ); + + /* upsample overlap snippet */ + Interpolate_allpass_steep_fx32( hBWE_TD->syn_overlap_fx_32, hBWE_TD->state_lsyn_filt_shb_fx_32, SHB_OVERLAP_LEN / 2, speech_buf_16k1_fx ); + Interpolate_allpass_steep_fx32( speech_buf_16k1_fx, hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, SHB_OVERLAP_LEN, speech_buf_16k2_fx ); + + /* perform spectral flip and downmix with overlap snippet to match HB synth */ + FOR( i = 0; i < SHB_OVERLAP_LEN; i++ ) { - set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); - hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); + IF( i % 2 == 0 ) + { + speech_buf_16k2_fx[i] = L_negate( speech_buf_16k2_fx[i] ); + move32(); + } + ELSE + { + speech_buf_16k2_fx[i] = speech_buf_16k2_fx[i]; + move32(); + } + } + + /* cross fade of overlap snippet and mirrored HB synth from previous frame */ + FOR( i = 0; i < L_SHB_LAHEAD; i++ ) + { + outputHB_fx[i] = L_add( Mpy_32_16_1( hBWE_TD->old_tbe_synth_fx_32[L_SHB_TRANSITION_LENGTH - 1 - i], window_shb_fx[i] ), Mpy_32_16_1( speech_buf_16k2_fx[i], window_shb_fx[L_SHB_LAHEAD - 1 - i] ) ); + move32(); + outputHB_fx[i] = Mpy_32_16_1( outputHB_fx[i], 21299 ); move32(); - st_fx->prev_Q_bwe_exc = 31; - move16(); } - test(); - IF( EQ_16( bandwidth, WB ) ) + /* fill transition signal with mirrored HB synth from previous frame to fully fill delay alignment buffer gap */ + FOR( ; i < length; i++ ) { - wb_tbe_extras_reset_fx( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx ); - wb_tbe_extras_reset_synth_fx( hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb_fx, hBWE_TD->state_32and48k_WB_upsample_fx, hBWE_TD->mem_resamp_HB_fx ); + outputHB_fx[i] = hBWE_TD->old_tbe_synth_fx_32[L_SHB_TRANSITION_LENGTH - 1 - i]; + move32(); + outputHB_fx[i] = Mpy_32_16_1( outputHB_fx[i], 21299 ); + move32(); + } - set16_fx( hBWE_TD->mem_genSHBexc_filt_down_shb_fx, 0, 7 ); - set16_fx( hBWE_TD->state_lpc_syn_fx, 0, 10 ); - set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD / 4 ); - set16_fx( hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); - set32_fx( hBWE_TD->mem_csfilt_fx, 0, 2 ); + /* upsampling if necessary */ + IF( EQ_32( output_Fs, 32000 ) ) + { + Interpolate_allpass_steep_fx32( outputHB_fx, hBWE_TD->mem_resamp_HB_fx_32, L_FRAME16k, upsampled_synth_fx ); + Copy32( upsampled_synth_fx, outputHB_fx, L_FRAME32k ); } - ELSE IF( EQ_16( bandwidth, SWB ) || EQ_16( bandwidth, FB ) ) + ELSE IF( EQ_32( output_Fs, 48000 ) ) { - swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, - hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &( hBWE_TD->tbe_demph_fx ), - &( hBWE_TD->tbe_premph_fx ), hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) ); - - swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); - - set16_fx( st_fx->GainShape_Delay, 0, NUM_SHB_SUBFR / 2 ); - set16_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN ); - set32_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx_32, 0, INTERP_3_2_MEM_LEN ); - set16_fx( hBWE_TD->mem_resamp_HB_32k_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); - set32_fx( hBWE_TD->mem_resamp_HB_32k_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); - - IF( EQ_16( bandwidth, FB ) ) - { - st_fx->prev_fb_ener_adjust_fx = 0; - move16(); - set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - hBWE_TD->fb_tbe_demph_fx = 0; - move16(); - fb_tbe_reset_synth_fx( hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q, &hBWE_TD->prev_fbbwe_ratio_fx ); - } + interpolate_3_over_1_allpass_fx32( outputHB_fx, L_FRAME16k, upsampled_synth_fx, hBWE_TD->mem_resamp_HB_fx_32 ); + Copy32( upsampled_synth_fx, outputHB_fx, L_FRAME48k ); } return; } -void TBEreset_dec_ivas_fx( - Decoder_State *st /* i/o: decoder state structure */ + +/*---------------------------------------------------------------------* + * TBEreset_dec() + * + *---------------------------------------------------------------------*/ + +void TBEreset_dec_fx( + Decoder_State *st_fx /* i/o: decoder state structure */ ) { TD_BWE_DEC_HANDLE hBWE_TD; + hBWE_TD = st_fx->hBWE_TD; - hBWE_TD = st->hBWE_TD; - - IF( st->last_core != ACELP_CORE ) + IF( NE_16( st_fx->last_core, ACELP_CORE ) ) { set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); move32(); - st->prev_Q_bwe_exc = 31; + st_fx->prev_Q_bwe_exc = 31; move16(); } + test(); - IF( EQ_16( st->bwidth, WB ) ) + IF( EQ_16( st_fx->bwidth, WB ) ) { wb_tbe_extras_reset_fx( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx ); wb_tbe_extras_reset_synth_fx( hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb_fx, hBWE_TD->state_32and48k_WB_upsample_fx, hBWE_TD->mem_resamp_HB_fx ); @@ -5120,11 +5144,15 @@ void TBEreset_dec_ivas_fx( set32_fx( hBWE_TD->syn_overlap_fx_32, 0, L_SHB_LAHEAD ); set32_fx( hBWE_TD->mem_csfilt_fx, 0, 2 ); } - ELSE IF( EQ_16( st->bwidth, SWB ) || EQ_16( st->bwidth, FB ) ) + ELSE IF( EQ_16( st_fx->bwidth, SWB ) || EQ_16( st_fx->bwidth, FB ) ) { - swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) ); + swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, + hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &( hBWE_TD->tbe_demph_fx ), + &( hBWE_TD->tbe_premph_fx ), hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) ); + + swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32 ); - set16_fx( st->GainShape_Delay, 0, NUM_SHB_SUBFR / 2 ); + set16_fx( hBWE_TD->GainShape_Delay_fx, 0, NUM_SHB_SUBFR / 2 ); set16_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN ); set32_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx_32, 0, INTERP_3_2_MEM_LEN ); set16_fx( hBWE_TD->mem_resamp_HB_32k_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); @@ -5133,15 +5161,12 @@ void TBEreset_dec_ivas_fx( move32(); hBWE_TD->prev_mix_factor_fx = 32767; /* Q15 1.f */ move16(); - // swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); - swb_tbe_reset_synth_ivas_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32 ); - - IF( EQ_16( st->bwidth, FB ) ) + IF( EQ_16( st_fx->bwidth, FB ) ) { - if ( st->hBWE_FD != NULL ) + if ( st_fx->hBWE_FD != NULL ) { - st->prev_fb_ener_adjust_fx = 0; + st_fx->hBWE_FD->prev_fb_ener_adjust_fx = 0; move16(); } set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); @@ -5154,97 +5179,27 @@ void TBEreset_dec_ivas_fx( return; } + /*-------------------------------------------------------------------* * td_bwe_dec_init() * * Initialize TD BWE state structure at the decoder *-------------------------------------------------------------------*/ -void td_bwe_dec_init_ivas_fx( - Decoder_State *st_fx, /* i/o: SHB decoder structure */ - TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ - const Word32 output_Fs /* i : output sampling rate */ -) -{ - Word16 i; - - /* init. SHB buffers */; - InitSWBdecBuffer_ivas_fx( st_fx ); - - /* reset SHB buffers */ - ResetSHBbuffer_Dec_fx( st_fx ); - IF( EQ_32( output_Fs, 48000 ) ) - { - set32_fx( hBWE_TD->fbbwe_hpf_mem_fx[0], 0, 4 ); - set32_fx( hBWE_TD->fbbwe_hpf_mem_fx[1], 0, 4 ); - set32_fx( hBWE_TD->fbbwe_hpf_mem_fx[2], 0, 4 ); - set32_fx( hBWE_TD->fbbwe_hpf_mem_fx[3], 0, 4 ); - set16_fx( hBWE_TD->fbbwe_hpf_mem_fx_Q, 0, 4 ); - } - - set16_fx( hBWE_TD->mem_resamp_HB_fx, 0, INTERP_3_1_MEM_LEN ); - set32_fx( hBWE_TD->mem_resamp_HB_fx_32, 0, INTERP_3_1_MEM_LEN ); - set16_fx( hBWE_TD->mem_resamp_HB_32k_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); - set32_fx( hBWE_TD->mem_resamp_HB_32k_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); - - hBWE_TD->tilt_mem_fx = 0; - move16(); - set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2 ); - hBWE_TD->prev_tilt_para_fx = 0; - move16(); - set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, M + 1 ); - set16_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN ); - set32_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx_32, 0, INTERP_3_2_MEM_LEN ); - /* TD BWE post-processing */ - hBWE_TD->ptr_mem_stp_swb_fx = hBWE_TD->mem_stp_swb_fx + LPC_SHB_ORDER - 1; - set16_fx( hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); - - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - hBWE_TD->swb_lsp_prev_interp_fx[i] = swb_lsp_prev_interp_init[i]; - move16(); - } - - hBWE_TD->prev1_shb_ener_sf_fx = 32767; /* Q15*/ - move16(); - hBWE_TD->prev2_shb_ener_sf_fx = 32767; /* Q15*/ - move16(); - hBWE_TD->prev3_shb_ener_sf_fx = 32767; /* Q15*/ - move16(); - hBWE_TD->prev_res_shb_gshape_fx = 8192; /* 0.125 in Q14*/ - move16(); - hBWE_TD->prev_mixFactors_fx = 16384; /* 0.5 in Q15*/ - move16(); - hBWE_TD->prev_GainShape_fx = 0; - move16(); - st_fx->prev_Q_bwe_exc_fb = 51; - move16(); - set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); - hBWE_TD->fb_tbe_demph_fx = 0; - move16(); - - set16_fx( hBWE_TD->old_hb_synth_fx, 0, L_FRAME48k ); - - hBWE_TD->prev_ener_fx = L_deposit_l( 0 ); - move32(); - - return; -} - - void td_bwe_dec_init_fx( - Decoder_State *st_fx, /* i/o: SHB decoder structure */ TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ + const Word16 extl, /* i : BWE extension layer */ const Word32 output_Fs /* i : output sampling rate */ ) { Word16 i; /* init. SHB buffers */; - InitSWBdecBuffer_fx( st_fx ); + InitSWBdecBuffer_fx( hBWE_TD ); /* reset SHB buffers */ - ResetSHBbuffer_Dec_fx( st_fx ); + ResetSHBbuffer_Dec_fx( hBWE_TD, extl ); + IF( EQ_32( output_Fs, 48000 ) ) { set32_fx( hBWE_TD->fbbwe_hpf_mem_fx[0], 0, 4 ); @@ -5255,7 +5210,7 @@ void td_bwe_dec_init_fx( } set16_fx( hBWE_TD->mem_resamp_HB_fx, 0, INTERP_3_1_MEM_LEN ); - + set32_fx( hBWE_TD->mem_resamp_HB_fx_32, 0, INTERP_3_1_MEM_LEN ); set16_fx( hBWE_TD->mem_resamp_HB_32k_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); set32_fx( hBWE_TD->mem_resamp_HB_32k_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); @@ -5267,6 +5222,7 @@ void td_bwe_dec_init_fx( set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, M + 1 ); set16_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN ); set32_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx_32, 0, INTERP_3_2_MEM_LEN ); + /* TD BWE post-processing */ hBWE_TD->ptr_mem_stp_swb_fx = hBWE_TD->mem_stp_swb_fx + LPC_SHB_ORDER - 1; set16_fx( hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); @@ -5289,7 +5245,7 @@ void td_bwe_dec_init_fx( move16(); hBWE_TD->prev_GainShape_fx = 0; move16(); - st_fx->prev_Q_bwe_exc_fb = 51; + hBWE_TD->prev_Q_bwe_exc_fb = 51; move16(); set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph_fx = 0; @@ -5300,6 +5256,8 @@ void td_bwe_dec_init_fx( hBWE_TD->prev_ener_fx = L_deposit_l( 0 ); move32(); + set16_fx( hBWE_TD->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB ); + return; } @@ -5438,9 +5396,11 @@ static void rescale_genSHB_mem_dec_ivas( move16(); hBWE_TD->tbe_premph_fx = shl_r( hBWE_TD->tbe_premph_fx, sf ); move16(); + + return; } -void find_max_mem_dec_m3( +static void find_max_mem_dec_m3( Decoder_State *st, Word16 *n_mem3 ) { @@ -5567,7 +5527,7 @@ void ivas_swb_tbe_dec_fx( set16_fx( shaped_shb_excitationTemp_fx, 0, L_FRAME16k ); if ( st->hTdCngDec != NULL ) { - st->hTdCngDec->shb_dtx_count = 0; + st->hTdCngDec->shb_dtx_count_fx = 0; move16(); } is_fractive = 0; @@ -5825,7 +5785,7 @@ void ivas_swb_tbe_dec_fx( { FOR( j = 0; j < 4; j++ ) { - GainShape_fx[i * 4 + j] = mult_r( st->cummulative_damping, st->GainShape_Delay[4 + i] ); + GainShape_fx[i * 4 + j] = mult_r( st->cummulative_damping, hBWE_TD->GainShape_Delay_fx[4 + i] ); move16(); } } @@ -5922,10 +5882,10 @@ void ivas_swb_tbe_dec_fx( } /* get the gainshape delay */ - Copy( &st->GainShape_Delay[4], &st->GainShape_Delay[0], NUM_SHB_SUBFR / 4 ); + Copy( &hBWE_TD->GainShape_Delay_fx[4], &hBWE_TD->GainShape_Delay_fx[0], NUM_SHB_SUBFR / 4 ); FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { - st->GainShape_Delay[i + 4] = GainShape_fx[i * 4]; /*Q15*/ + hBWE_TD->GainShape_Delay_fx[i + 4] = GainShape_fx[i * 4]; /*Q15*/ move16(); } @@ -6225,7 +6185,7 @@ void ivas_swb_tbe_dec_fx( /* -------- end of rescaling memories -------- */ - Q_bwe_exc_fb = st->prev_Q_bwe_exc_fb; + Q_bwe_exc_fb = hBWE_TD->prev_Q_bwe_exc_fb; move16(); Q_shb = 0; @@ -6237,7 +6197,7 @@ void ivas_swb_tbe_dec_fx( st->coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st->extl, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_32, shb_res_gshape_fx, shb_res_dummy_fx, &vind, formant_fac_fx, hBWE_TD->fb_state_lpc_syn_fx, - &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, st->prev_Q_bwe_syn, st->total_brate, st->prev_bfi, + &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, hBWE_TD->prev_Q_bwe_syn, st->total_brate, st->prev_bfi, st->element_mode, st->flag_ACELP16k, nlExc16k_fx, mixExc16k_fx, st->extl_brate, MSFlag, NULL, &( hBWE_TD->prev_pow_exc16kWhtnd_fx32 ), &( hBWE_TD->prev_mix_factor_fx ), NULL, NULL ); @@ -6245,21 +6205,21 @@ void ivas_swb_tbe_dec_fx( move16(); IF( EQ_16( st->extl, FB_TBE ) ) { - st->prev_Q_bwe_exc_fb = Q_bwe_exc_fb; + hBWE_TD->prev_Q_bwe_exc_fb = Q_bwe_exc_fb; move16(); } ELSE { /*Indirectly a memory reset of FB memories for next frame such that rescaling of memories would lead to 0 due to such high prev. Q value. 51 because of 31 + 20(shift of Q_bwe_exc_fb before de-emphasis)*/ - st->prev_Q_bwe_exc_fb = 51; + hBWE_TD->prev_Q_bwe_exc_fb = 51; move16(); } /* rescale the TBE post proc memory */ FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->mem_stp_swb_fx[i] = shl_sat( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, st->prev_Q_bwe_syn ) ); + hBWE_TD->mem_stp_swb_fx[i] = shl_sat( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_syn ) ); move16(); } /* fill-in missing SHB excitation */ @@ -6301,11 +6261,7 @@ void ivas_swb_tbe_dec_fx( curr_pow_fx = L_shr( curr_pow_fx, 2 ); /* Q(2*Q_bwe_exc) */ } - Lscale = root_a_over_b_fx( curr_pow_fx, - shl( Q_bwe_exc, 1 ), - prev_pow_fx, - shl( Q_bwe_exc, 1 ), - &exp ); + Lscale = root_a_over_b_fx( curr_pow_fx, shl( Q_bwe_exc, 1 ), prev_pow_fx, shl( Q_bwe_exc, 1 ), &exp ); FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { @@ -6636,7 +6592,7 @@ void ivas_swb_tbe_dec_fx( { L_tmp1 = Mult_32_16( ener_tmp_fx[i], GainShape_tmp_fx[i] ); /* (2*Q_bwe_exc) */ L_tmp2 = Mult_32_16( hBWE_TD->prev_ener_fx, hBWE_TD->prev_GainShape_fx ); /* (2*st->prev_ener_fx_Q) */ - tmp = sub( shl( Q_bwe_exc, 1 ), shl( st->prev_ener_fx_Q, 1 ) ); + tmp = sub( shl( Q_bwe_exc, 1 ), shl( hBWE_TD->prev_ener_fx_Q, 1 ) ); L_tmp2 = L_shl_sat( L_tmp2, tmp ); /* new Q = (2*Q_bwe_exc) */ IF( GT_32( L_tmp1, L_tmp2 ) ) { @@ -6670,7 +6626,7 @@ void ivas_swb_tbe_dec_fx( move32(); hBWE_TD->prev_GainShape_fx = GainShape_tmp_fx[i]; move16(); - st->prev_ener_fx_Q = Q_bwe_exc; + hBWE_TD->prev_ener_fx_Q = Q_bwe_exc; move16(); } @@ -6688,10 +6644,10 @@ void ivas_swb_tbe_dec_fx( } ELSE { - st->prev_ener_fx_Q = Q_bwe_exc; + hBWE_TD->prev_ener_fx_Q = Q_bwe_exc; move16(); } - st->prev_Q_bwe_syn = Q_bwe_exc; + hBWE_TD->prev_Q_bwe_syn = Q_bwe_exc; move16(); @@ -6757,7 +6713,7 @@ void ivas_swb_tbe_dec_fx( GainFrame_fx, /* Q18 */ window_shb_fx, subwin_shb_fx, - &Q_bwe_exc, &Qx, n_mem3_new, st->prev_Q_bwe_syn2 ); + &Q_bwe_exc, &Qx, n_mem3_new, hBWE_TD->prev_Q_bwe_syn2 ); IF( hStereoICBWE != NULL ) { @@ -6802,31 +6758,31 @@ void ivas_swb_tbe_dec_fx( } } curr_frame_pow_exp = sub( shl( add( Q_bwe_exc, n ), 1 ), 9 ); - tmp = sub( st->prev_frame_pow_exp, curr_frame_pow_exp ); + tmp = sub( hBWE_TD->prev_frame_pow_exp, curr_frame_pow_exp ); IF( tmp > 0 ) /* shifting prev */ { IF( GT_16( tmp, 32 ) ) { - st->prev_frame_pow_exp = add( curr_frame_pow_exp, 32 ); + hBWE_TD->prev_frame_pow_exp = add( curr_frame_pow_exp, 32 ); move16(); tmp = 32; move16(); } hBWE_TD->prev_swb_bwe_frame_pow_fx = L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, tmp ); move32(); - st->prev_frame_pow_exp = curr_frame_pow_exp; + hBWE_TD->prev_frame_pow_exp = curr_frame_pow_exp; move16(); } ELSE /* shifting curr */ { IF( LT_16( tmp, -32 ) ) { - curr_frame_pow_exp = sub( st->prev_frame_pow_exp, 32 ); + curr_frame_pow_exp = sub( hBWE_TD->prev_frame_pow_exp, 32 ); tmp = -32; move16(); } curr_frame_pow_fx = L_shr( curr_frame_pow_fx, -tmp ); - curr_frame_pow_exp = st->prev_frame_pow_exp; + curr_frame_pow_exp = hBWE_TD->prev_frame_pow_exp; move16(); } test(); @@ -6992,7 +6948,7 @@ void ivas_swb_tbe_dec_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx = curr_frame_pow_fx; move32(); - st->prev_frame_pow_exp = curr_frame_pow_exp; + hBWE_TD->prev_frame_pow_exp = curr_frame_pow_exp; move16(); Word64 prev_ener_shb64 = 0; @@ -7035,7 +6991,7 @@ void ivas_swb_tbe_dec_fx( L_tmp = Isqrt_lc( L_tmp, &exp ); tmp = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ } - set16_fx( st->prev_SWB_fenv_fx, tmp, SWB_FENV ); /* Q1 */ + set16_fx( st->hBWE_FD->prev_SWB_fenv_fx, tmp, SWB_FENV ); /* Q1 */ } FOR( i = 0; i < L_FRAME16k; i++ ) @@ -7045,7 +7001,7 @@ void ivas_swb_tbe_dec_fx( } /* generate 32kHz SHB synthesis from 12.8(16)kHz signal */ - GenSHBSynth_fx_32( shaped_shb_excitation_fx_32, error_fx, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->L_frame, &( hBWE_TD->syn_dm_phase ) ); + GenSHBSynth_fx32( shaped_shb_excitation_fx_32, error_fx, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->L_frame, &( hBWE_TD->syn_dm_phase ) ); Copy_Scale_sig_32_16( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, 2 * ALLPASSSECTIONS_STEEP, -( Q11 - Q_bwe_exc ) ); Copy32( error_fx + L_FRAME32k - L_SHB_TRANSITION_LENGTH, hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH ); @@ -7112,7 +7068,7 @@ void ivas_swb_tbe_dec_fx( move32(); } } - interpolate_3_over_2_allpass_32( error_fx, L_FRAME32k, synth_fx, hBWE_TD->int_3_over_2_tbemem_dec_fx_32 ); + interpolate_3_over_2_allpass_fx32( error_fx, L_FRAME32k, synth_fx, hBWE_TD->int_3_over_2_tbemem_dec_fx_32 ); } ELSE IF( EQ_32( st->output_Fs, 32000 ) ) { @@ -7143,7 +7099,6 @@ void ivas_swb_tbe_dec_fx( Decimate_allpass_steep_fx32( error_fx, hBWE_TD->mem_resamp_HB_32k_fx_32, L_FRAME32k, synth_fx ); } - /* Update previous frame parameters for FEC */ Copy( lsf_shb_fx, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER ); IF( EQ_16( st->codec_mode, MODE1 ) ) @@ -7176,145 +7131,10 @@ void ivas_swb_tbe_dec_fx( move32(); hBWE_TD->prev_GainShape_fx = GainShape_fx[NUM_SHB_SUBFR - 1]; move16(); - st->prev_Q_bwe_syn2 = Q_bwe_exc; + hBWE_TD->prev_Q_bwe_syn2 = Q_bwe_exc; move16(); - st->prev_Qx = Q_bwe_exc; + hBWE_TD->prev_Qx = Q_bwe_exc; move16(); return; } - -void GenTransition_fixed( - TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ - Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */ - const Word32 output_Fs, /* i : output sampling rate : Q0 */ - const Word16 element_mode, /* i : element mode : Q0 */ - const Word16 L_frame, /* i : ACELP frame length : Q0 */ - const Word16 rf_flag, /* i : RF flag : Q0 */ - const Word32 total_brate, /* i : total bitrate : Q0 */ - const Word16 prev_Qx ) -{ - Word16 i, length; - - Word32 syn_overlap_32k_fx[2 * SHB_OVERLAP_LEN]; - - /* set targeted length of transition signal */ - length = i_mult( 2, NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ) ); - - /* upsample overlap snippet */ - Interpolate_allpass_steep_32( hBWE_TD->syn_overlap_fx_32, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, SHB_OVERLAP_LEN, syn_overlap_32k_fx ); - - /* perFORm spectral flip and downmix with overlap snippet to match HB synth */ - test(); - test(); - test(); - test(); - IF( ( ( element_mode == EVS_MONO ) && ( rf_flag || EQ_32( total_brate, ACELP_9k60 ) ) ) || ( ( element_mode > EVS_MONO ) && EQ_16( L_frame, L_FRAME ) ) ) - { - flip_and_downmix_generic_fx_32( syn_overlap_32k_fx, syn_overlap_32k_fx, 2 * SHB_OVERLAP_LEN, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_Hilbert_Mem_fx + HILBERT_ORDER1, hBWE_TD->genSHBsynth_Hilbert_Mem_fx + ( HILBERT_ORDER1 + 2 * HILBERT_ORDER2 ), &( hBWE_TD->syn_dm_phase ) ); - } - ELSE - { - FOR( i = 0; i < 2 * SHB_OVERLAP_LEN; i++ ) - { - IF( i % 2 == 0 ) - { - syn_overlap_32k_fx[i] = L_negate( syn_overlap_32k_fx[i] ); - } - ELSE - { - syn_overlap_32k_fx[i] = syn_overlap_32k_fx[i]; - } - move32(); - } - } - - /* cross fade of overlap snippet and mirrored HB synth from previous frame */ - FOR( i = 0; i < 2 * L_SHB_LAHEAD; i++ ) - { - outputHB_fx[i] = L_add_sat( Mpy_32_16_1( hBWE_TD->old_tbe_synth_fx_32[L_SHB_TRANSITION_LENGTH - 1 - i], window_shb_32k_fx[i] ), Mpy_32_16_1( syn_overlap_32k_fx[i], window_shb_32k_fx[2 * L_SHB_LAHEAD - 1 - i] ) ); - move32(); - } - - /* fill transition signal with mirrored HB synth from previous frame to fully fill delay alignment buffer gap */ - FOR( ; i < length; i++ ) - { - outputHB_fx[i] = L_shl( hBWE_TD->old_tbe_synth_fx[L_SHB_TRANSITION_LENGTH - 1 - i], sub( Q11, prev_Qx ) ); - move32(); - } - - IF( EQ_32( output_Fs, 48000 ) ) - { - interpolate_3_over_2_allpass_32( outputHB_fx, length, outputHB_fx, hBWE_TD->int_3_over_2_tbemem_dec_fx_32 ); - } - ELSE IF( EQ_32( output_Fs, 16000 ) ) - { - Decimate_allpass_steep_fx32( outputHB_fx, hBWE_TD->mem_resamp_HB_32k_fx_32, L_FRAME32k, outputHB_fx ); - } - - return; -} -void GenTransition_WB_fixed( - TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ - Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */ - const Word32 output_Fs /* i : output sampling rate */ -) -{ - Word16 i, length; - Word32 speech_buf_16k1_fx[SHB_OVERLAP_LEN], speech_buf_16k2_fx[2 * SHB_OVERLAP_LEN]; - Word32 upsampled_synth_fx[L_FRAME48k]; - - /* set targeted length of transition signal */ - length = i_mult( 2, NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ) ); - - /* upsample overlap snippet */ - Interpolate_allpass_steep_32( hBWE_TD->syn_overlap_fx_32, hBWE_TD->state_lsyn_filt_shb_fx_32, SHB_OVERLAP_LEN / 2, speech_buf_16k1_fx ); - Interpolate_allpass_steep_32( speech_buf_16k1_fx, hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, SHB_OVERLAP_LEN, speech_buf_16k2_fx ); - - /* perform spectral flip and downmix with overlap snippet to match HB synth */ - FOR( i = 0; i < SHB_OVERLAP_LEN; i++ ) - { - IF( i % 2 == 0 ) - { - speech_buf_16k2_fx[i] = L_negate( speech_buf_16k2_fx[i] ); - move32(); - } - ELSE - { - speech_buf_16k2_fx[i] = speech_buf_16k2_fx[i]; - move32(); - } - } - - /* cross fade of overlap snippet and mirrored HB synth from previous frame */ - FOR( i = 0; i < L_SHB_LAHEAD; i++ ) - { - outputHB_fx[i] = L_add( Mpy_32_16_1( hBWE_TD->old_tbe_synth_fx_32[L_SHB_TRANSITION_LENGTH - 1 - i], window_shb_fx[i] ), Mpy_32_16_1( speech_buf_16k2_fx[i], window_shb_fx[L_SHB_LAHEAD - 1 - i] ) ); - move32(); - outputHB_fx[i] = Mpy_32_16_1( outputHB_fx[i], 21299 ); - move32(); - } - - /* fill transition signal with mirrored HB synth from previous frame to fully fill delay alignment buffer gap */ - FOR( ; i < length; i++ ) - { - outputHB_fx[i] = hBWE_TD->old_tbe_synth_fx_32[L_SHB_TRANSITION_LENGTH - 1 - i]; - move32(); - outputHB_fx[i] = Mpy_32_16_1( outputHB_fx[i], 21299 ); - move32(); - } - - /* upsampling if necessary */ - IF( EQ_32( output_Fs, 32000 ) ) - { - Interpolate_allpass_steep_32( outputHB_fx, hBWE_TD->mem_resamp_HB_fx_32, L_FRAME16k, upsampled_synth_fx ); - Copy32( upsampled_synth_fx, outputHB_fx, L_FRAME32k ); - } - ELSE IF( EQ_32( output_Fs, 48000 ) ) - { - interpolate_3_over_1_allpass_32( outputHB_fx, L_FRAME16k, upsampled_synth_fx, hBWE_TD->mem_resamp_HB_fx_32 ); - Copy32( upsampled_synth_fx, outputHB_fx, L_FRAME48k ); - } - - return; -} diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index 043ae5601147dd6285fe45e12ef4eda036470997..650e8572bc7bbcaddb28a1a385df35933750cd1b 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -554,11 +554,12 @@ void TonalMDCTConceal_SaveFreqSignal_ivas_fx( } -TONALMDCTCONCEAL_ERROR TonalMDCTConceal_UpdateState( TonalMDCTConcealPtr hTonalMDCTConc, - Word16 nNewSamples, // Q0 - Word32 pitchLag, // Qx - Word16 badBlock, // Q0 - Word8 tonalConcealmentActive ) +void TonalMDCTConceal_UpdateState( + TonalMDCTConcealPtr hTonalMDCTConc, + Word16 nNewSamples, // Q0 + Word32 pitchLag, // Qx + Word16 badBlock, // Q0 + Word8 tonalConcealmentActive ) { Word8 newBlockIsValid; @@ -598,13 +599,16 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_UpdateState( TonalMDCTConcealPtr hTonalM hTonalMDCTConc->lastPitchLag = pitchLag; move32(); - return TONALMDCTCONCEAL_OK; + return; } -static void FindPhases( /* o: currenc phase [-pi;pi] 2Q13 */ - TonalMDCTConcealPtr const hTonalMDCTConc, /* i: pointer to internal structure */ - Word32 secondLastMDCT[], /* i: MDST spectrum data Qx +31 -diff_exp */ - Word32 secondLastMDST[], /* i: MDCT spectrum data Qx */ - Word16 diff_exp ) /* i: exp_MDST - exp_MDCT */ + + +/* o: currenc phase [-pi;pi] 2Q13 */ +static void FindPhases( + TonalMDCTConcealPtr const hTonalMDCTConc, /* i: pointer to internal structure */ + Word32 secondLastMDCT[], /* i: MDST spectrum data Qx +31 -diff_exp */ + Word32 secondLastMDST[], /* i: MDCT spectrum data Qx */ + Word16 diff_exp ) /* i: exp_MDST - exp_MDCT */ { Word16 i; Word16 l; @@ -624,6 +628,8 @@ static void FindPhases( /* o: currenc move16(); } } + + return; } #define BANDWIDTH 7.0f @@ -634,9 +640,10 @@ static void FindPhases( /* o: currenc #define N 931758243 /* FL2WORD32(sin(EVS_PI/BANDWIDTH)); */ #define J 31946 /* FL2WORD16(sin((3*EVS_PI)/BANDWIDTH)); */ -static void FindPhaseDifferences( /* o: Phase difference [-pi;pi] 2Q13*/ - TonalMDCTConcealPtr const hTonalMDCTConc, /* i: Pointer to internal structure */ - Word32 powerSpectrum[] ) /* i: Power spectrum data Qx */ +/* o: Phase difference [-pi;pi] 2Q13*/ +static void FindPhaseDifferences( + TonalMDCTConcealPtr const hTonalMDCTConc, /* i: Pointer to internal structure */ + Word32 powerSpectrum[] ) /* i: Power spectrum data Qx */ { Word16 i, k; Word16 *phaseDiff; diff --git a/lib_dec/updt_dec_fx.c b/lib_dec/updt_dec_fx.c index 67621c442f24536792690208ac8915c5649d0846..0e1b951bb4afc1e1b5e636f067099700fba78b32 100644 --- a/lib_dec/updt_dec_fx.c +++ b/lib_dec/updt_dec_fx.c @@ -249,17 +249,17 @@ void updt_IO_switch_dec_fx( { swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &hBWE_TD->tbe_demph_fx, &hBWE_TD->tbe_premph_fx, hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) ); - set16_fx( st_fx->GainShape_Delay, 0, NUM_SHB_SUBFR / 2 ); + set16_fx( hBWE_TD->GainShape_Delay_fx, 0, NUM_SHB_SUBFR / 2 ); hBWE_TD->prev_pow_exc16kWhtnd_fx32 = 1; /*Q0 1.f*/ move32(); hBWE_TD->prev_mix_factor_fx = 32767; /*Q15 1.f*/ move16(); - swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); + swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32 ); } IF( EQ_16( output_frame, L_FRAME48k ) ) { - st_fx->prev_fb_ener_adjust_fx = 0; + hBWE_FD->prev_fb_ener_adjust_fx = 0; move16(); set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph_fx = 0; @@ -740,7 +740,7 @@ void updt_dec_common_fx( IF( st_fx->hTcxDec != NULL && st_fx->enablePlcWaveadjust && !concealWholeFrameTmp && NE_16( st_fx->core, AMR_WB_CORE ) ) { /* update the parameters used in waveform adjustment */ - concealment_update2_x( (const Word16 *) synth, &st_fx->plcInfo, hTcxDec->L_frameTCX ); + concealment_update2_x( (const Word16 *) synth, st_fx->hPlcInfo, hTcxDec->L_frameTCX ); } st_fx->last_total_brate_ber = st_fx->total_brate; @@ -1163,7 +1163,7 @@ void ivas_updt_dec_common_fx( IF( st_fx->hTcxDec != NULL && st_fx->enablePlcWaveadjust && !concealWholeFrameTmp && NE_16( st_fx->core, AMR_WB_CORE ) ) { /* update the parameters used in waveform adjustment */ - concealment_update2_x( (const Word16 *) synth, &st_fx->plcInfo, hTcxDec->L_frameTCX ); + concealment_update2_x( (const Word16 *) synth, st_fx->hPlcInfo, hTcxDec->L_frameTCX ); } st_fx->last_total_brate_ber = st_fx->total_brate; diff --git a/lib_dec/waveadjust_fec_dec_fx.c b/lib_dec/waveadjust_fec_dec_fx.c index 80241a24c9f79d528f9c4e7004e9ab7a54348e6a..f993caa8d1650555dc32b1c8ff9c2dc53f5e3df0 100644 --- a/lib_dec/waveadjust_fec_dec_fx.c +++ b/lib_dec/waveadjust_fec_dec_fx.c @@ -35,28 +35,36 @@ void set_state( Word16 *state, Word16 num, Word16 N ) /*i/o: Qx */ } state[tmp] = num; move16(); + + return; } -void concealment_update_x( Word16 bfi, Word16 curr_mode, Word16 tonality, Word32 *invkoef /*Qinvkoef_scale*/, Word16 *invkoef_scale, void *_plcInfo ) +void concealment_update_x( + const Word16 bfi, + const Word16 core, + const Word16 tonality, + Word32 *invkoef /*Qinvkoef_scale*/, + Word16 *invkoef_scale, + T_PLCInfo_HANDLE hPlcInfo ) { - T_PLCInfo *plcInfo = (T_PLCInfo *) _plcInfo; - Word32 *data_reci2 = plcInfo->data_reci2_fx; - Word16 *tcx_tonality = plcInfo->TCX_Tonality; - Word16 FrameSize = plcInfo->FrameSize; - Word16 subframe = plcInfo->subframe_fx; + Word32 *data_reci2 = hPlcInfo->data_reci2_fx; + Word16 *tcx_tonality = hPlcInfo->TCX_Tonality; + Word16 L_frameTCX = hPlcInfo->L_frameTCX; + Word16 subframe = hPlcInfo->subframe_fx; Word16 i; move16(); move16(); - IF( EQ_16( curr_mode, 1 ) ) + + IF( EQ_16( core, TCX_20_CORE ) ) { - set_state( plcInfo->Transient, curr_mode, MAX_POST_LEN ); + set_state( hPlcInfo->Transient, core, MAX_POST_LEN ); - FOR( i = 0; i < FrameSize; i++ ) + FOR( i = 0; i < L_frameTCX; i++ ) { data_reci2[i] = invkoef[i]; move32(); } - plcInfo->data_reci2_scale = *invkoef_scale; + hPlcInfo->data_reci2_scale = *invkoef_scale; move16(); IF( !bfi ) { @@ -68,7 +76,7 @@ void concealment_update_x( Word16 bfi, Word16 curr_mode, Word16 tonality, Word32 IF( subframe == 0 ) { - set_state( plcInfo->Transient, curr_mode, MAX_POST_LEN ); + set_state( hPlcInfo->Transient, core, MAX_POST_LEN ); IF( !bfi ) { @@ -83,7 +91,7 @@ void concealment_update_x( Word16 bfi, Word16 curr_mode, Word16 tonality, Word32 { Word32 *ptr = data_reci2 + subframe; - Word16 FrameSize2 = shr( FrameSize, 1 ); + Word16 FrameSize2 = shr( L_frameTCX, 1 ); FOR( i = 0; i < FrameSize2; i++ ) { @@ -91,13 +99,15 @@ void concealment_update_x( Word16 bfi, Word16 curr_mode, Word16 tonality, Word32 move32(); } - plcInfo->data_reci2_scale = *invkoef_scale; + hPlcInfo->data_reci2_scale = *invkoef_scale; move16(); } } + return; } + static Word16 zero_pass_w32_x( const Word16 *s, const Word16 N ) /* i: Qx*/ /* o: 2*Qx-31*/ { Word16 i; @@ -601,15 +611,17 @@ Word16 get_conv_relation_x( Word16 *s_LP /*Qx*/, Word16 shIFt, Word16 N ) /*o :Q return tmp; } -static Word16 pitch_search_fx( Word16 *s /*Qs*/, /* lastPcmOut */ - Word16 *outx_new /*Qoutx_new*/, - Word16 Framesize, - Word16 *voicing /*Q15*/, - Word16 zp, /*Q0*/ - Word32 ener /*Q8*/, - Word32 ener_mean /*Q8*/, - Word32 *mdct_data /*Qmdct*/, - Word16 curr_mode ) + +static Word16 pitch_search_fx( + Word16 *s /*Qs*/, /* lastPcmOut */ + Word16 *outx_new /*Qoutx_new*/, + Word16 Framesize, + Word16 *voicing /*Q15*/, + Word16 zp, /*Q0*/ + Word32 ener /*Q8*/, + Word32 ener_mean /*Q8*/, + Word32 *mdct_data /*Qmdct*/, + Word16 curr_mode ) { Word16 pitch = 0; Word32 cov_max = L_deposit_l( 0 ), tilt_enr1, tilt_enr2; @@ -767,78 +779,85 @@ static Word16 pitch_search_fx( Word16 *s /*Qs*/, /* lastPcmOut */ return pitch; } -void concealment_init_x( Word16 N, void *_plcInfo ) +void concealment_init_x( + const Word16 L_frameTCX, + T_PLCInfo_HANDLE hPlcInfo ) { - T_PLCInfo *plcInfo = (T_PLCInfo *) _plcInfo; Word16 i; - plcInfo->FrameSize = N; + hPlcInfo->L_frameTCX = L_frameTCX; move16(); - plcInfo->Pitch_fx = 0; + hPlcInfo->Pitch_fx = 0; move16(); - plcInfo->T_bfi_fx = 0; + hPlcInfo->T_bfi_fx = 0; move16(); - plcInfo->outx_new_n1_fx = 0; + hPlcInfo->outx_new_n1_fx = 0; move16(); - plcInfo->nsapp_gain_fx = 0; + hPlcInfo->nsapp_gain_fx = 0; move16(); - plcInfo->nsapp_gain_n_fx = 0; + hPlcInfo->nsapp_gain_n_fx = 0; move16(); - plcInfo->ener_mean_fx = L_deposit_l( 15213 ); /*Q8 59.4260f*256*/ - plcInfo->ener_fx = L_deposit_l( 0 ); - plcInfo->zp_fx = N; + hPlcInfo->ener_mean_fx = L_deposit_l( 15213 ); /*Q8 59.4260f*256*/ + hPlcInfo->ener_fx = L_deposit_l( 0 ); + hPlcInfo->zp_fx = L_frameTCX; move16(); - plcInfo->recovery_gain = 0; + hPlcInfo->recovery_gain = 0; move16(); - plcInfo->step_concealgain_fx = 0; + hPlcInfo->step_concealgain_fx = 0; move16(); - plcInfo->concealment_method = TCX_NONTONAL; + hPlcInfo->concealment_method = TCX_NONTONAL; move16(); - plcInfo->subframe_fx = 0; + hPlcInfo->subframe_fx = 0; move16(); - plcInfo->nbLostCmpt = (Word16) L_deposit_l( 0 ); + hPlcInfo->nbLostCmpt = (Word16) L_deposit_l( 0 ); move16(); - plcInfo->seed = 21845; + hPlcInfo->seed = 21845; move16(); FOR( i = 0; i < TCX_TONALITY_INIT_CNT; i++ ) { - plcInfo->TCX_Tonality[i] = 1; + hPlcInfo->TCX_Tonality[i] = 1; move16(); } FOR( i = TCX_TONALITY_INIT_CNT; i < DEC_STATE_LEN; i++ ) { - plcInfo->TCX_Tonality[i] = 0; + hPlcInfo->TCX_Tonality[i] = 0; move16(); } FOR( i = 0; i < MAX_POST_LEN; i++ ) { - plcInfo->Transient[i] = 1; + hPlcInfo->Transient[i] = 1; move16(); } FOR( i = 0; i < L_FRAME_MAX; i++ ) { - plcInfo->data_reci2_fx[i] = L_deposit_l( 0 ); + hPlcInfo->data_reci2_fx[i] = L_deposit_l( 0 ); } + return; } + + void concealment_init_ivas_fx( const Word16 L_frameTCX, T_PLCInfo_HANDLE hPlcInfo ) { Word16 i; + hPlcInfo->L_frameTCX = L_frameTCX; move16(); - hPlcInfo->FrameSize = L_frameTCX; - move16(); +#ifndef NONBE_FIX_1402_WAVEADJUST hPlcInfo->Pitch = 0; move16(); +#endif hPlcInfo->Pitch_fx = 0; move16(); +#ifndef NONBE_FIX_1402_WAVEADJUST hPlcInfo->T_bfi = 0; move16(); +#endif hPlcInfo->T_bfi_fx = 0; move16(); hPlcInfo->outx_new_n1_fx = 0; @@ -849,8 +868,6 @@ void concealment_init_ivas_fx( move16(); hPlcInfo->ener_mean_fx = L_deposit_l( 15213 ); hPlcInfo->ener_fx = L_deposit_l( 0 ); - hPlcInfo->zp = L_frameTCX; - move16(); hPlcInfo->zp_fx = L_frameTCX; move16(); hPlcInfo->recovery_gain = 0; @@ -859,8 +876,10 @@ void concealment_init_ivas_fx( move16(); hPlcInfo->concealment_method = TCX_NONTONAL; move16(); +#ifndef NONBE_FIX_1402_WAVEADJUST hPlcInfo->subframe = 0; move16(); +#endif hPlcInfo->subframe_fx = 0; move16(); hPlcInfo->nbLostCmpt = (Word16) L_deposit_l( 0 ); @@ -900,21 +919,25 @@ static Word16 own_random_fix( /* o : output random value */ return ( *seed ); } -void concealment_decode_fix( Word16 curr_mode, Word32 *invkoef /*Qinvkoef_scale*/, Word16 *invkoef_scale, void *_plcInfo ) +void concealment_decode_fix( + Word16 curr_mode, + Word32 *invkoef /*Qinvkoef_scale*/, + Word16 *invkoef_scale, + T_PLCInfo_HANDLE hPlcInfo ) { - T_PLCInfo *plcInfo = (T_PLCInfo *) _plcInfo; Word16 i; - Word16 N = plcInfo->FrameSize; - Word16 *seed = &( plcInfo->seed ); + Word16 N = hPlcInfo->L_frameTCX; + Word16 *seed = &( hPlcInfo->seed ); Word16 sign; move16(); - IF( plcInfo->concealment_method == TCX_NONTONAL ) /* #define TCX_NONTONAL 0 */ + + IF( hPlcInfo->concealment_method == TCX_NONTONAL ) /* #define TCX_NONTONAL 0 */ { IF( EQ_16( curr_mode, 1 ) ) { /* copy the data of the last frame */ - MVR2R_WORD32( plcInfo->data_reci2_fx, invkoef, N ); - *invkoef_scale = plcInfo->data_reci2_scale; + MVR2R_WORD32( hPlcInfo->data_reci2_fx, invkoef, N ); + *invkoef_scale = hPlcInfo->data_reci2_scale; move16(); /* sign randomization */ FOR( i = 0; i < N; i++ ) @@ -928,6 +951,7 @@ void concealment_decode_fix( Word16 curr_mode, Word32 *invkoef /*Qinvkoef_scale* } } } + return; } @@ -1103,25 +1127,29 @@ Word32 con_Log10( Word32 i_s32Val /*Qi_s32Val*/, Word16 i_s16Q /*Q0*/ ) /*o; Q26 return s32Out; } -void concealment_update2_x( const Word16 *outx_new /*Qoutx_new*/, void *_plcInfo, const Word16 FrameSize ) +void concealment_update2_x( + const Word16 *outx_new /*Qoutx_new*/, + T_PLCInfo_HANDLE hPlcInfo, + const Word16 FrameSize ) { - T_PLCInfo *plcInfo = (T_PLCInfo *) _plcInfo; - - plcInfo->zp_fx = zero_pass_w32_x( outx_new, FrameSize ); + hPlcInfo->zp_fx = zero_pass_w32_x( outx_new, FrameSize ); move16(); - Log10OfEnergy_x( outx_new, &plcInfo->ener_fx, FrameSize ); /* Q8 */ + Log10OfEnergy_x( outx_new, &hPlcInfo->ener_fx, FrameSize ); /* Q8 */ test(); - IF( LT_16( plcInfo->zp_fx, 100 ) && GT_32( plcInfo->ener_fx, L_shl( 50, 8 ) ) ) + IF( LT_16( hPlcInfo->zp_fx, 100 ) && GT_32( hPlcInfo->ener_fx, L_shl( 50, 8 ) ) ) { - plcInfo->ener_mean_fx = L_add( Mpy_32_16_1( plcInfo->ener_mean_fx, 32112 /* 0.98 Q15 */ ), - Mpy_32_16_1( plcInfo->ener_fx, 655 /* 0.02 Q15 */ ) ); + hPlcInfo->ener_mean_fx = L_add( Mpy_32_16_1( hPlcInfo->ener_mean_fx, 32112 /* 0.98 Q15 */ ), + Mpy_32_16_1( hPlcInfo->ener_fx, 655 /* 0.02 Q15 */ ) ); move32(); } + return; } -static Word16 array_max_indx_fx( Word16 *s /*Qs*/, Word16 N ) +static Word16 array_max_indx_fx( + Word16 *s /*Qs*/, + Word16 N ) { Word16 i, indx = 0; move16(); @@ -1261,20 +1289,16 @@ static void add_noise( Word16 *const sbuf, /*Qsbuf*/ return; } -static Word16 waveform_adj_fix( Word16 *overlapbuf, /*Qoverlapbuf*/ - Word16 *outdata2, /*Qoutdata2*/ - Word16 *outx_new, /*Qoutx_new*/ - Word16 *data_noise, /*Qoutx_new*/ - Word16 *outx_new_n1, /*Q0*/ - Word16 *nsapp_gain, /*Q15*/ - Word16 *nsapp_gain_n, /*Q15*/ - Word16 Framesize, - Word8 T_bfi, - Word16 voicing, /*Q15*/ - Word16 curr_mode, - Word16 pitch /*Q0*/ ) +static Word16 waveform_adj_fix( + T_PLCInfo_HANDLE hPlcInfo, + Word16 *overlapbuf, /*Qoverlapbuf*/ + Word16 *outdata2, /*Qoutdata2*/ + Word16 *outx_new, /*Qoutx_new*/ + const Word16 Framesize, + const Word16 voicing, /*Q15*/ + const Word16 core ) { - Word16 i, zp1, zp2, Framesizediv2, s16MaxCoefNorm; + Word16 i, zp1, zp2, Framesizediv2, s16MaxCoefNorm, pitch; Word16 sbuf[L_FRAME_MAX]; Word16 tmp; @@ -1282,6 +1306,8 @@ static Word16 waveform_adj_fix( Word16 *overlapbuf, /*Qoverlapbuf*/ zp1 = zero_pass_w32_x( outdata2, Framesizediv2 ); zp2 = zero_pass_w32_x( outdata2 + Framesizediv2, Framesizediv2 ); + pitch = hPlcInfo->Pitch_fx; + /* judge if the pitch is usable */ tmp = 1; move16(); @@ -1300,7 +1326,11 @@ static Word16 waveform_adj_fix( Word16 *overlapbuf, /*Qoverlapbuf*/ test(); test(); test(); - IF( T_bfi && ( LE_16( pitch, Framesizediv2 ) ) && ( GT_16( Framesize, 256 ) ) && ( EQ_16( curr_mode, 1 ) ) ) +#ifdef NONBE_FIX_1402_WAVEADJUST + IF( hPlcInfo->T_bfi_fx && ( LE_16( pitch, Framesizediv2 ) ) && ( GT_16( Framesize, 256 ) ) && ( EQ_16( core, 1 ) ) ) +#else + IF( hPlcInfo->T_bfi && ( LE_16( pitch, Framesizediv2 ) ) && ( GT_16( Framesize, 256 ) ) && ( EQ_16( core, 1 ) ) ) +#endif { Word16 i1 = 0, i2 = 0; Word16 pos1, pos2, pos3; @@ -1383,15 +1413,18 @@ static Word16 waveform_adj_fix( Word16 *overlapbuf, /*Qoverlapbuf*/ last good frame) is still needed and overlapbuf overlaps outdata2 */ Copy( &sbuf[Framesize / 4], pitch125_data, shr( imult1616( 3, Framesize ), 2 ) ); - *nsapp_gain = 0; + hPlcInfo->nsapp_gain_fx = 0; move16(); - *nsapp_gain_n = sub( 32767, shr( voicing, 1 ) ); /* q15 */ + hPlcInfo->nsapp_gain_n_fx = sub( 32767, shr( voicing, 1 ) ); /* q15 */ tmp = Framesize; move16(); + /* use last good signal for noise generation */ - add_noise( sbuf, outx_new_n1, outdata2, tmp, nsapp_gain, nsapp_gain_n, 1 ); + add_noise( sbuf, &( hPlcInfo->outx_new_n1_fx ), outdata2, tmp, &( hPlcInfo->nsapp_gain_fx ), &( hPlcInfo->nsapp_gain_n_fx ), 1 ); + /* save current (noisy) output from IMDCT */ - MVR2R_WORD16( outx_new, data_noise, tmp ); + MVR2R_WORD16( outx_new, hPlcInfo->data_noise, tmp ); + /* overlapbuf can now be filled with sbuf, needed for subsequently lost frames */ Copy( pitch125_data, &overlapbuf[Framesize / 4], shr( imult1616( 3, Framesize ), 2 ) ); } @@ -1400,31 +1433,31 @@ static Word16 waveform_adj_fix( Word16 *overlapbuf, /*Qoverlapbuf*/ outx_new[i] = sbuf[i]; move16(); } + return pitch; } -void waveform_adj2_fix( Word16 *overlapbuf, /*Qoverlapbuf*/ - Word16 *outx_new, /*Qoutx_new*/ - Word16 *data_noise, /*Qoutx_new*/ - Word16 *outx_new_n1, /*Q0*/ - Word16 *nsapp_gain, /*Q15*/ - Word16 *nsapp_gain_n, /*Q15*/ - Word16 *recovery_gain, /*Q14*/ - Word16 step_concealgain, /*Q15*/ - Word16 pitch, /*Q0*/ - Word16 Framesize, - Word16 delay, - Word16 bfi_cnt, - Word16 bfi ) + +void waveform_adj2_fix( + T_PLCInfo_HANDLE hPlcInfo, + Word16 *overlapbuf, /*Qoverlapbuf*/ + Word16 *outx_new, /*Qoutx_new*/ + const Word16 delay, + const Word16 bfi_cnt, + const Word16 bfi ) { - Word16 i, n, tablescale, ratio, - dat, Framesizesubn, Framesizesubp, tmp16, s, ptable, temp_OUT, s16MaxCoefNorm, s16MaxCoefNorm2; + Word16 i, n, tablescale, ratio, dat, Framesizesubn, Framesizesubp, tmp16, s, ptable, temp_OUT, s16MaxCoefNorm, s16MaxCoefNorm2; Word16 sbuf[L_FRAME_MAX]; + Word16 pitch, L_frameTCX; + pitch = hPlcInfo->Pitch_fx; + move16(); + L_frameTCX = hPlcInfo->L_frameTCX; + move16(); n = 0; move16(); - Framesizesubn = sub( Framesize, n ); - Framesizesubp = sub( Framesize, pitch ); + Framesizesubn = sub( L_frameTCX, n ); + Framesizesubp = sub( L_frameTCX, pitch ); IF( pitch > 0 ) { WHILE( Framesizesubn > 0 ) @@ -1437,21 +1470,21 @@ void waveform_adj2_fix( Word16 *overlapbuf, /*Qoverlapbuf*/ move16(); } n = add( n, pitch ); - Framesizesubn = sub( Framesize, n ); + Framesizesubn = sub( L_frameTCX, n ); } - FOR( i = 0; i < Framesize; i++ ) + FOR( i = 0; i < L_frameTCX; i++ ) { overlapbuf[i] = sbuf[i]; move16(); } { - Word16 size = Framesize; - Word16 *noise_ptr = data_noise; + Word16 size = L_frameTCX; + Word16 *noise_ptr = hPlcInfo->data_noise; move16(); /* use last (noisy) output from IMDCT for noise generation */ - add_noise( sbuf, outx_new_n1, noise_ptr, size, nsapp_gain, nsapp_gain_n, 0 ); + add_noise( sbuf, &( hPlcInfo->outx_new_n1_fx ), noise_ptr, size, &( hPlcInfo->nsapp_gain_fx ), &( hPlcInfo->nsapp_gain_n_fx ), 0 ); /* save current (noisy) output from IMDCT */ IF( bfi ) @@ -1462,7 +1495,7 @@ void waveform_adj2_fix( Word16 *overlapbuf, /*Qoverlapbuf*/ test(); IF( EQ_16( bfi_cnt, 4 ) || bfi == 0 ) { - SWITCH( Framesize ) + SWITCH( L_frameTCX ) { case 160: { @@ -1510,40 +1543,40 @@ void waveform_adj2_fix( Word16 *overlapbuf, /*Qoverlapbuf*/ Word16 gain_zero_start = 10000; move16(); - IF( step_concealgain > 0 ) + IF( hPlcInfo->step_concealgain_fx > 0 ) { - gain_zero_start = BASOP_Util_Divide1616_Scale( *recovery_gain, step_concealgain, &s ); + gain_zero_start = BASOP_Util_Divide1616_Scale( hPlcInfo->recovery_gain, hPlcInfo->step_concealgain_fx, &s ); gain_zero_start = shl( gain_zero_start, sub( s, 14 ) ); /* q0 */ gain_zero_start = add( gain_zero_start, 1 ); } if ( delay > 0 ) { - Framesize = sub( Framesize, delay ); + L_frameTCX = sub( L_frameTCX, delay ); } - s16MaxCoefNorm = sub( ffr_getSfWord16( sbuf, Framesize ), 1 ); - s16MaxCoefNorm2 = ffr_getSfWord16( outx_new, Framesize ); - tmp16 = vadmin( gain_zero_start, Framesize ); + s16MaxCoefNorm = sub( ffr_getSfWord16( sbuf, L_frameTCX ), 1 ); + s16MaxCoefNorm2 = ffr_getSfWord16( outx_new, L_frameTCX ); + tmp16 = vadmin( gain_zero_start, L_frameTCX ); FOR( i = 0; i < tmp16; i++ ) { ratio = extract_l( L_shr( L_mult( i, ptable ), tablescale ) ); dat = shl( sbuf[i], s16MaxCoefNorm ); - temp_OUT = mult( *recovery_gain, sub( 32767, ratio ) ); + temp_OUT = mult( hPlcInfo->recovery_gain, sub( 32767, ratio ) ); outx_new[i] = round_fx_sat( L_add_sat( L_shr_sat( L_mult( temp_OUT, dat ), sub( s16MaxCoefNorm, 1 ) ), L_shr_sat( L_mult( shl( outx_new[i], s16MaxCoefNorm2 ), ratio ), s16MaxCoefNorm2 ) ) ); move16(); - *recovery_gain = sub_sat( *recovery_gain, shr_r( step_concealgain, 1 ) ); /* q14 */ + hPlcInfo->recovery_gain = sub_sat( hPlcInfo->recovery_gain, shr_r( hPlcInfo->step_concealgain_fx, 1 ) ); /* q14 */ } - FOR( i = gain_zero_start; i < Framesize; i++ ) + FOR( i = gain_zero_start; i < L_frameTCX; i++ ) { ratio = extract_l( L_shr( L_mult( i, ptable ), tablescale ) ); outx_new[i] = round_fx_sat( L_shr_sat( L_mult( shl( outx_new[i], s16MaxCoefNorm2 ), ratio ), s16MaxCoefNorm2 ) ); move16(); } - if ( *recovery_gain < 0 ) + if ( hPlcInfo->recovery_gain < 0 ) { - *recovery_gain = 0; + hPlcInfo->recovery_gain = 0; move16(); } } @@ -1551,9 +1584,9 @@ void waveform_adj2_fix( Word16 *overlapbuf, /*Qoverlapbuf*/ { /* overlap-and-add */ Word16 tmp; - s16MaxCoefNorm = sub( ffr_getSfWord16( sbuf, Framesize ), 1 ); - s16MaxCoefNorm2 = ffr_getSfWord16( outx_new, Framesize ); - FOR( i = 0; i < Framesize; i++ ) + s16MaxCoefNorm = sub( ffr_getSfWord16( sbuf, L_frameTCX ), 1 ); + s16MaxCoefNorm2 = ffr_getSfWord16( outx_new, L_frameTCX ); + FOR( i = 0; i < L_frameTCX; i++ ) { dat = shl( sbuf[i], s16MaxCoefNorm ); tmp = extract_l( L_shr( L_mult( i, ptable ), tablescale ) ); @@ -1564,7 +1597,7 @@ void waveform_adj2_fix( Word16 *overlapbuf, /*Qoverlapbuf*/ } ELSE { - FOR( i = 0; i < Framesize; i++ ) + FOR( i = 0; i < L_frameTCX; i++ ) { outx_new[i] = sbuf[i]; move16(); @@ -1574,71 +1607,44 @@ void waveform_adj2_fix( Word16 *overlapbuf, /*Qoverlapbuf*/ return; } -void concealment_signal_tuning_fx( Word16 bfi, Word16 curr_mode, Word16 *outx_new_fx /*Qoutx_new_fx*/, void *_plcInfo, Word16 nbLostCmpt, Word16 pre_bfi, Word16 *OverlapBuf_fx /*QOverlapBuf_fx*/, Word16 past_core_mode, Word16 *outdata2_fx /*Qoutdata2_fx*/, Decoder_State *st ) +void concealment_signal_tuning_fx( + Decoder_State *st, + const Word16 bfi, + Word16 *outx_new_fx /*Qoutx_new_fx*/, + const Word16 past_core ) { - T_PLCInfo *plcInfo = (T_PLCInfo *) _plcInfo; - Word16 FrameSize = plcInfo->FrameSize; - Word16 Pitch = plcInfo->Pitch_fx; + T_PLCInfo_HANDLE hPlcInfo = st->hPlcInfo; + Word16 L_frameTCX = hPlcInfo->L_frameTCX; Word16 voicing_fx = 0; + Word16 *OverlapBuf_fx = st->hTonalMDCTConc->secondLastPcmOut; + Word16 *outdata2_fx = st->hTonalMDCTConc->lastPcmOut; move16(); move16(); move16(); move16(); + IF( bfi ) { - test(); - IF( st->enablePlcWaveadjust && plcInfo->concealment_method == TCX_NONTONAL ) /* #define TCX_NONTONAL 0 */ + IF( st->enablePlcWaveadjust && hPlcInfo->concealment_method == TCX_NONTONAL ) /* #define TCX_NONTONAL 0 */ { - - IF( EQ_16( nbLostCmpt, 1 ) ) + IF( EQ_16( st->nbLostCmpt, 1 ) ) { - plcInfo->Pitch_fx = pitch_search_fx( outdata2_fx, - outx_new_fx, - FrameSize, - &voicing_fx, - plcInfo->zp_fx, - ( plcInfo->ener_fx ), - ( plcInfo->ener_mean_fx ), - plcInfo->data_reci2_fx, - curr_mode ); + hPlcInfo->Pitch_fx = pitch_search_fx( outdata2_fx, outx_new_fx, L_frameTCX, &voicing_fx, hPlcInfo->zp_fx, ( hPlcInfo->ener_fx ), ( hPlcInfo->ener_mean_fx ), hPlcInfo->data_reci2_fx, st->core ); move16(); - IF( plcInfo->Pitch_fx ) /* waveform adjustment for the first lost frame */ + IF( hPlcInfo->Pitch_fx ) /* waveform adjustment for the first lost frame */ { - plcInfo->Pitch_fx = waveform_adj_fix( OverlapBuf_fx, - outdata2_fx, - outx_new_fx, - plcInfo->data_noise, - &plcInfo->outx_new_n1_fx, - &plcInfo->nsapp_gain_fx, - &plcInfo->nsapp_gain_n_fx, - FrameSize, - plcInfo->T_bfi_fx, - voicing_fx, - curr_mode, - plcInfo->Pitch_fx ); + hPlcInfo->Pitch_fx = waveform_adj_fix( hPlcInfo, OverlapBuf_fx, outdata2_fx, outx_new_fx, L_frameTCX, voicing_fx, st->core ); move16(); } } - ELSE IF( LT_16( nbLostCmpt, 5 ) ) /* waveform adjustment for the 2nd~4th lost frame */ + ELSE IF( LT_16( st->nbLostCmpt, 5 ) ) /* waveform adjustment for the 2nd~4th lost frame */ { - waveform_adj2_fix( OverlapBuf_fx, - outx_new_fx, - plcInfo->data_noise, - &plcInfo->outx_new_n1_fx, - &plcInfo->nsapp_gain_fx, - &plcInfo->nsapp_gain_n_fx, - &plcInfo->recovery_gain, - plcInfo->step_concealgain_fx, - Pitch, - FrameSize, - 0, - nbLostCmpt, - bfi ); + waveform_adj2_fix( hPlcInfo, OverlapBuf_fx, outx_new_fx, 0, st->nbLostCmpt, bfi ); } } - plcInfo->T_bfi_fx = 1; + hPlcInfo->T_bfi_fx = 1; move16(); } ELSE @@ -1646,34 +1652,22 @@ void concealment_signal_tuning_fx( Word16 bfi, Word16 curr_mode, Word16 *outx_ne test(); test(); test(); - IF( pre_bfi && - past_core_mode != 0 && + IF( st->prev_bfi && + past_core != ACELP_CORE && GE_32( st->last_total_brate, 48000 ) && EQ_16( st->last_codec_mode, MODE2 ) ) { - IF( plcInfo->concealment_method == TCX_NONTONAL ) /* #define TCX_NONTONAL 0 */ + IF( hPlcInfo->concealment_method == TCX_NONTONAL ) /* #define TCX_NONTONAL 0 */ { - IF( LT_32( plcInfo->nbLostCmpt, 4 ) ) /* smoothing of the concealed signal with the good signal */ + IF( LT_32( hPlcInfo->nbLostCmpt, 4 ) ) /* smoothing of the concealed signal with the good signal */ { - waveform_adj2_fix( OverlapBuf_fx, - outx_new_fx, - plcInfo->data_noise, - &plcInfo->outx_new_n1_fx, - &plcInfo->nsapp_gain_fx, - &plcInfo->nsapp_gain_n_fx, - &plcInfo->recovery_gain, - plcInfo->step_concealgain_fx, - Pitch, - FrameSize, - 0, - add( extract_l( plcInfo->nbLostCmpt ), 1 ), - bfi ); + waveform_adj2_fix( hPlcInfo, OverlapBuf_fx, outx_new_fx, 0, add( extract_l( hPlcInfo->nbLostCmpt ), 1 ), bfi ); } } } ELSE { - plcInfo->T_bfi_fx = 0; + hPlcInfo->T_bfi_fx = 0; move16(); } } diff --git a/lib_enc/swb_pre_proc_fx.c b/lib_enc/swb_pre_proc_fx.c index 5c96a2f297d8eefba4346fa564f850c13f5b0b9a..acdd971fd67074ca0cb2f260f85eeee14323bc5a 100644 --- a/lib_enc/swb_pre_proc_fx.c +++ b/lib_enc/swb_pre_proc_fx.c @@ -715,8 +715,7 @@ void swb_pre_proc_fx( CldfbHB_ener = L_mult( sub( Cldfbtemp1, 1741 /*3.401 Q9*/ ), 3495 ); /* 3495 = Q19 log10(2)*0.1/log10(32768), Q = 19+9+1 = 29 */ hBWE_TD->cldfbHBLT = mac_r( CldfbHB_ener, 29491 /*0.9 Q15*/, hBWE_TD->cldfbHBLT ); /* cldfbHBLT is in Q13 */ } - cldfbSynthesisFiltering( st_fx->cldfbSynTd, realBufferFlipped, imagBufferFlipped, - cldfbScale, shb_speech_fx, 0, CLDFB_NO_COL_MAX, cldfbWorkBuffer ); + cldfbSynthesis_fx( st_fx->cldfbSynTd, realBufferFlipped, imagBufferFlipped, cldfbScale, shb_speech_fx, 0, CLDFB_NO_COL_MAX, cldfbWorkBuffer ); *Q_shb_spch = 0; /*shb_speech_fx : Q0*/ move16();