diff --git a/Workspace_msvc/lib_enc.vcxproj b/Workspace_msvc/lib_enc.vcxproj index 015a20cde025ce587d8d70eb733ef7b1881703ad..8e0d593a03940f6e01edb52fd2a07366dc5e59be 100644 --- a/Workspace_msvc/lib_enc.vcxproj +++ b/Workspace_msvc/lib_enc.vcxproj @@ -280,9 +280,7 @@ - - diff --git a/Workspace_msvc/lib_enc.vcxproj.filters b/Workspace_msvc/lib_enc.vcxproj.filters index 612bf52a3b281c4ae23f65a6e699bf08cee784bb..97eb07edc45edfeb2dd3beddc2bb1e55f5104e4c 100644 --- a/Workspace_msvc/lib_enc.vcxproj.filters +++ b/Workspace_msvc/lib_enc.vcxproj.filters @@ -181,15 +181,9 @@ enc_all_c - - enc_all_c - enc_all_c - - enc_all_c - enc_all_c diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 9b57bda42579d76953155bada93c89f395ba1796..48be311001eed26b4e5c41e5f6bf8157fdc6e029 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -11006,8 +11006,9 @@ void core_coder_mode_switch_ivas_fx( void configureFdCngEnc_ivas_fx( HANDLE_FD_CNG_ENC hFdCngEnc, /* i/o: Contains the variables related to the FD-based CNG process */ - const Word16 bwidth, - const Word32 total_brate ); + const Word16 bwidth, /* Q0 */ + const Word32 total_brate /* Q0 */ +); Word16 getTcxonly_ivas_fx( const Word16 element_mode, /* i : IVAS element mode */ diff --git a/lib_enc/ext_sig_ana.c b/lib_enc/ext_sig_ana.c deleted file mode 100644 index 9f9fa4c23133239f729cb22721f441ff8c4e71c0..0000000000000000000000000000000000000000 --- a/lib_enc/ext_sig_ana.c +++ /dev/null @@ -1,43 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2024 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 -#include "options.h" -#include -#include "prot.h" -#include "rom_com.h" -#include "wmc_auto.h" diff --git a/lib_enc/ext_sig_ana_fx.c b/lib_enc/ext_sig_ana_fx.c index ae88362c0f31505d60c492d5b9b5d7a4b384674d..079a0e61fecb501ee45b34041450550cd1ed1188 100644 --- a/lib_enc/ext_sig_ana_fx.c +++ b/lib_enc/ext_sig_ana_fx.c @@ -23,19 +23,19 @@ void core_signal_analysis_high_bitrate_fx( const Word16 *new_samples, /*i: 0Q15*/ - const Word16 T_op[3], /* i : open-loop pitch values for quantiz. */ - Word16 lsp_new[], - Word16 lsp_mid[], + const Word16 T_op[3], /* i : open-loop pitch values for quantiz. Q0*/ + Word16 lsp_new[], /* Q15 */ + Word16 lsp_mid[], /* Q15 */ Encoder_State *st, - Word16 pTnsSize[], - Word16 pTnsBits[], - Word16 param_core[], - Word16 *ltpBits, - const Word16 L_frame, - const Word16 L_frameTCX, - const Word16 last_element_mode, - const Word16 vad_hover_flag, /* i : VAD hangover flag */ - Word32 **spectrum, + Word16 pTnsSize[], /* Q0 */ + Word16 pTnsBits[], /* Q0 */ + Word16 param_core[], /* Q0 */ + Word16 *ltpBits, /* Q0 */ + const Word16 L_frame, /* Q0 */ + const Word16 L_frameTCX, /* Q0 */ + const Word16 last_element_mode, /* Q0 */ + const Word16 vad_hover_flag, /* i : VAD hangover flag Q0*/ + Word32 **spectrum, /* spectrum_e */ Word16 *spectrum_e, Word16 *Q_new ) { @@ -93,10 +93,10 @@ void core_signal_analysis_high_bitrate_fx( right_overlap = -1; move16(); - tcx10SizeFB = shl( st->hTcxCfg->tcx5SizeFB, 1 ); - tcx5SizeFB = st->hTcxCfg->tcx5SizeFB; + tcx10SizeFB = shl( st->hTcxCfg->tcx5SizeFB, 1 ); /* Q0 */ + tcx5SizeFB = st->hTcxCfg->tcx5SizeFB; /* Q0 */ move16(); - tcx10Size = shl( st->hTcxCfg->tcx5Size, 1 ); + tcx10Size = shl( st->hTcxCfg->tcx5Size, 1 ); /* Q0 */ /*--------------------------------------------------------------* * Input Signal Processing: copy, HP filter, pre-emphasis @@ -105,8 +105,8 @@ void core_signal_analysis_high_bitrate_fx( /* Copy Samples */ IF( st->tcxonly && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { - Copy( new_samples, st->new_speech_enc, L_frame ); - Scale_sig( st->new_speech_enc, L_frame, 1 ); + Copy( new_samples, st->new_speech_enc, L_frame ); /* Q0 */ + Scale_sig( st->new_speech_enc, L_frame, 1 ); /* Q1 */ } /*--------------------------------------------------------------* @@ -158,16 +158,16 @@ void core_signal_analysis_high_bitrate_fx( move16(); /* Rescale Memory */ - Scale_sig( st->old_inp_16k_fx, L_INP_MEM, sub( *Q_new, st->Q_old ) ); + Scale_sig( st->old_inp_16k_fx, L_INP_MEM, sub( *Q_new, st->Q_old ) ); /* Q_new */ IF( Q_exp != 0 ) { - Scale_sig( st->buf_speech_enc_pe, st->encoderPastSamples_enc + st->encoderLookahead_enc, Q_exp ); + Scale_sig( st->buf_speech_enc_pe, st->encoderPastSamples_enc + st->encoderLookahead_enc, Q_exp ); /* Q15 - exp_buf_speech_enc_pe + Q_exp */ Scale_sig( &( st->mem_wsp_enc ), 1, Q_exp ); } IF( EQ_16( hTcxEnc->tcxMode, TCX_10 ) ) { - Copy( ¶m_core[1 + NOISE_FILL_RANGES], ¶m_core[NPRM_DIV + 1 + NOISE_FILL_RANGES], LTPSIZE ); + Copy( ¶m_core[1 + NOISE_FILL_RANGES], ¶m_core[NPRM_DIV + 1 + NOISE_FILL_RANGES], LTPSIZE ); /* Q0 */ } @@ -178,19 +178,19 @@ void core_signal_analysis_high_bitrate_fx( { lsp[0] = lsp_new; lsp[1] = lsp_mid; - alw_pitch_lag_12k8[0] = st->pitch[0]; + alw_pitch_lag_12k8[0] = st->pitch[0]; /* Q0 */ move16(); - alw_pitch_lag_12k8[1] = st->pitch[1]; + alw_pitch_lag_12k8[1] = st->pitch[1]; /* Q0 */ move16(); - alw_voicing[0] = st->voicing_fx[0]; + alw_voicing[0] = st->voicing_fx[0]; /* Q15 */ move16(); - alw_voicing[1] = st->voicing_fx[1]; + alw_voicing[1] = st->voicing_fx[1]; /* Q15 */ move16(); - alw_pitch_lag_12k8_wc = s_min( alw_pitch_lag_12k8[0], alw_pitch_lag_12k8[1] ); - alw_voicing_wc = s_max( alw_voicing[0], alw_voicing[1] ); + alw_pitch_lag_12k8_wc = s_min( alw_pitch_lag_12k8[0], alw_pitch_lag_12k8[1] ); /* Q0 */ + alw_voicing_wc = s_max( alw_voicing[0], alw_voicing[1] ); /* Q15 */ } - overlap_mode[0] = last_overlap; /* Overlap between the last and the current frame */ + overlap_mode[0] = last_overlap; /* Overlap between the last and the current frame Q0*/ move16(); IF( EQ_16( hTcxEnc->tcxMode, TCX_20 ) ) @@ -200,14 +200,14 @@ void core_signal_analysis_high_bitrate_fx( transform_type[0] = TCX_20; transform_type[1] = TCX_20; move16(); - overlap_mode[1] = curr_overlap; /* Overlap between the current and the next frame */ + overlap_mode[1] = curr_overlap; /* Overlap between the current and the next frame Q0*/ move16(); IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { - alw_pitch_lag_12k8[0] = alw_pitch_lag_12k8_wc; + alw_pitch_lag_12k8[0] = alw_pitch_lag_12k8_wc; /* Q0 */ move16(); - alw_voicing[0] = alw_voicing_wc; + alw_voicing[0] = alw_voicing_wc; /* Q15 */ move16(); } } @@ -260,7 +260,7 @@ void core_signal_analysis_high_bitrate_fx( move16(); } } - overlap_mode[2] = curr_overlap; /* Overlap between the current and the next frame */ + overlap_mode[2] = curr_overlap; /* Overlap between the current and the next frame Q0*/ move16(); } IF( NE_16( transform_type[0], TCX_20 ) ) @@ -273,14 +273,14 @@ void core_signal_analysis_high_bitrate_fx( FOR( frameno = 0; frameno < nSubframes; frameno++ ) { - L_subframe = L_frameTCX; + L_subframe = L_frameTCX; /* Q0 */ move16(); if ( NE_16( nSubframes, 1 ) ) L_subframe = shr( L_frameTCX, 1 ); - lpc_left_overlap_mode = overlap_mode[frameno]; + lpc_left_overlap_mode = overlap_mode[frameno]; /* Q0 */ move16(); - lpc_right_overlap_mode = overlap_mode[frameno + 1]; + lpc_right_overlap_mode = overlap_mode[frameno + 1]; /* Q0 */ move16(); if ( EQ_16( lpc_left_overlap_mode, ALDO_WINDOW ) ) { @@ -319,7 +319,7 @@ void core_signal_analysis_high_bitrate_fx( FOR( i = 0; i < folding_offset; i++ ) { #ifdef BASOP_NOGLOB - tcx20Win[folding_offset + i] = sub_sat( tcx20Win[folding_offset + i], tcx20Win[folding_offset - 1 - i] ); + tcx20Win[folding_offset + i] = sub_sat( tcx20Win[folding_offset + i], tcx20Win[folding_offset - 1 - i] ); // Q0 #else tcx20Win[folding_offset + i] = sub( tcx20Win[folding_offset + i], tcx20Win[folding_offset - 1 - i] ); #endif @@ -339,18 +339,18 @@ void core_signal_analysis_high_bitrate_fx( FOR( i = 0; i < tmp; i++ ) { #ifdef BASOP_NOGLOB - tcx20Win[L_subframe + folding_offset - 1 - i] = add_sat( tcx20Win[L_subframe + folding_offset - 1 - i], tcx20Win[L_subframe + folding_offset + i] ); + tcx20Win[L_subframe + folding_offset - 1 - i] = add_sat( tcx20Win[L_subframe + folding_offset - 1 - i], tcx20Win[L_subframe + folding_offset + i] ); // Q0 #else tcx20Win[L_subframe + folding_offset - 1 - i] = add( tcx20Win[L_subframe + folding_offset - 1 - i], tcx20Win[L_subframe + folding_offset + i] ); #endif move16(); } /* 2xTCX5 */ - L_subframe = tcx5SizeFB; + L_subframe = tcx5SizeFB; /* Q0 */ move16(); tmpP16 = tcx20Win; - tmpP32 = spectrum[frameno]; + tmpP32 = spectrum[frameno]; /* exp(spectrum) */ assert( st->mct_chan_mode != MCT_CHAN_MODE_LFE ); FOR( i = 0; i < 2; i++ ) { @@ -411,7 +411,7 @@ void core_signal_analysis_high_bitrate_fx( FOR( i = 0; i < L_subframe; i++ ) { - tmp_buf[i] = Mpy_32_16_1( tmp_buf[i], tmp1 ); + tmp_buf[i] = Mpy_32_16_1( tmp_buf[i], tmp1 ); /* Q - 4 */ move32(); } Q = sub( Q, tmp2 ); @@ -579,9 +579,9 @@ void core_signal_analysis_high_bitrate_fx( /* group sub-windows: interleave bins according to their frequencies */ FOR( i = 0; i < tcx5SizeFB; i++ ) { - interleaveBuf[2 * i] = spectrum[frameno][i]; + interleaveBuf[2 * i] = spectrum[frameno][i]; /* exp(spectrum_e) */ move32(); - interleaveBuf[2 * i + 1] = spectrum[frameno][tcx5SizeFB + i]; + interleaveBuf[2 * i + 1] = spectrum[frameno][tcx5SizeFB + i]; /* exp(spectrum_e) */ move32(); } MVR2R_WORD32( interleaveBuf, spectrum[frameno], tcx10SizeFB ); @@ -617,7 +617,7 @@ void core_signal_analysis_high_bitrate_fx( } /* Copy memory */ - MVR2R_WORD16( lsp_new, st->lspold_enc_fx, M ); + MVR2R_WORD16( lsp_new, st->lspold_enc_fx, M ); /* Q15 */ } } @@ -632,20 +632,20 @@ void core_signal_analysis_high_bitrate_fx( void core_signal_analysis_high_bitrate_ivas_fx( const Word16 *new_samples, /*i: Q0 */ - const Word16 T_op[3], /* i : open-loop pitch values for quantiz. */ + const Word16 T_op[3], /* i : open-loop pitch values for quantiz. Q0*/ Word16 lsp_new[], /* Q15 */ Word16 lsp_mid[], /* Q15 */ Encoder_State *st, - Word16 pTnsSize[], - Word16 pTnsBits[], - Word16 param_core[], - Word16 *ltpBits, - Word32 *windowed_samples, - const Word16 L_frame, - const Word16 L_frameTCX, - const Word16 last_element_mode, - const Word16 vad_hover_flag, /* i : VAD hangover flag */ - Word32 **spectrum, + Word16 pTnsSize[], /* Q0 */ + Word16 pTnsBits[], /* Q0 */ + Word16 param_core[], /* Q0 */ + Word16 *ltpBits, /* Q0 */ + Word32 *windowed_samples, /* q_win */ + const Word16 L_frame, /* Q0 */ + const Word16 L_frameTCX, /* Q0 */ + const Word16 last_element_mode, /* Q0 */ + const Word16 vad_hover_flag, /* i : VAD hangover flag Q0*/ + Word32 **spectrum, /* exp(spectrum_e) */ Word16 *spectrum_e, Word16 *Q_new, Word16 *q_win ) @@ -717,15 +717,15 @@ void core_signal_analysis_high_bitrate_ivas_fx( test(); IF( st->tcxonly && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { - Copy( new_samples, st->new_speech_enc, L_frame ); - Scale_sig( st->new_speech_enc, L_frame, 1 ); // Q1 + Copy( new_samples, st->new_speech_enc, L_frame ); /* Q0 */ + Scale_sig( st->new_speech_enc, L_frame, 1 ); // Q1 } /*--------------------------------------------------------------* * TCX-LTP *---------------------------------------------------------------*/ - if ( st->element_mode == IVAS_CPE_DFT ) + if ( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { if ( st->element_mode > EVS_MONO ) { @@ -736,7 +736,7 @@ void core_signal_analysis_high_bitrate_ivas_fx( wspeech_fx = st->buf_wspeech_enc + st->L_frame + idiv1616( st->L_frame, st->nb_subfr ); } } - else if ( st->element_mode != IVAS_CPE_MDCT ) + else if ( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { speech_fx = st->buf_speech_enc + +st->encoderPastSamples_enc; speech_ltp_fx = st->hTcxEnc->buf_speech_ltp + st->encoderPastSamples_enc; @@ -746,7 +746,7 @@ void core_signal_analysis_high_bitrate_ivas_fx( { tcx_ltp_encode_ivas_fx( st, hTcxEnc->tcxMode, L_frame, wspeech_fx, NULL, wspeech_fx, T_op, ¶m_core[1 + NOISE_FILL_RANGES], ltpBits, NULL, disable_ltp, st->element_mode ); } - ELSE IF( st->element_mode != IVAS_CPE_MDCT ) + ELSE IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { tcx_ltp_encode_ivas_fx( st, hTcxEnc->tcxMode, L_frame, speech_fx + st->encoderLookahead_enc, speech_ltp_fx + st->encoderLookahead_enc, speech_fx + st->encoderLookahead_enc, T_op, ¶m_core[1 + NOISE_FILL_RANGES], ltpBits, NULL, disable_ltp, st->element_mode ); } @@ -775,14 +775,14 @@ void core_signal_analysis_high_bitrate_ivas_fx( IF( EQ_16( hTcxEnc->tcxMode, TCX_10 ) ) { - Copy( ¶m_core[1 + NOISE_FILL_RANGES], ¶m_core[NPRM_DIV + 1 + NOISE_FILL_RANGES], LTPSIZE ); + Copy( ¶m_core[1 + NOISE_FILL_RANGES], ¶m_core[NPRM_DIV + 1 + NOISE_FILL_RANGES], LTPSIZE ); // Q0 } IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { - lsp[0] = lsp_new; + lsp[0] = lsp_new; // Q15 move16(); - lsp[1] = lsp_mid; + lsp[1] = lsp_mid; // Q15 move16(); } @@ -792,19 +792,19 @@ void core_signal_analysis_high_bitrate_ivas_fx( IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { - alw_pitch_lag_12k8[0] = st->pitch[0]; + alw_pitch_lag_12k8[0] = st->pitch[0]; // Q0 move16(); - alw_pitch_lag_12k8[1] = st->pitch[1]; + alw_pitch_lag_12k8[1] = st->pitch[1]; // Q0 move16(); - alw_voicing[0] = st->voicing_fx[0]; + alw_voicing[0] = st->voicing_fx[0]; // Q15 move16(); - alw_voicing[1] = st->voicing_fx[1]; + alw_voicing[1] = st->voicing_fx[1]; // Q15 move16(); - alw_pitch_lag_12k8_wc = s_min( alw_pitch_lag_12k8[0], alw_pitch_lag_12k8[1] ); - alw_voicing_wc = s_max( alw_voicing[0], alw_voicing[1] ); + alw_pitch_lag_12k8_wc = s_min( alw_pitch_lag_12k8[0], alw_pitch_lag_12k8[1] ); // Q0 + alw_voicing_wc = s_max( alw_voicing[0], alw_voicing[1] ); // Q15 } - overlap_mode[0] = last_overlap; /* Overlap between the last and the current frame */ + overlap_mode[0] = last_overlap; /* Overlap between the last and the current frame Q0*/ move16(); IF( EQ_16( hTcxEnc->tcxMode, TCX_20 ) ) @@ -815,14 +815,14 @@ void core_signal_analysis_high_bitrate_ivas_fx( move16(); transform_type[1] = TCX_20; move16(); - overlap_mode[1] = curr_overlap; /* Overlap between the current and the next frame */ + overlap_mode[1] = curr_overlap; /* Overlap between the current and the next frame Q0*/ move16(); IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { - alw_pitch_lag_12k8[0] = alw_pitch_lag_12k8_wc; + alw_pitch_lag_12k8[0] = alw_pitch_lag_12k8_wc; // Q0 move16(); - alw_voicing[0] = alw_voicing_wc; + alw_voicing[0] = alw_voicing_wc; // Q15 move16(); } } @@ -875,7 +875,7 @@ void core_signal_analysis_high_bitrate_ivas_fx( move16(); } } - overlap_mode[2] = curr_overlap; /* Overlap between the current and the next frame */ + overlap_mode[2] = curr_overlap; /* Overlap between the current and the next frame Q0*/ move16(); } @@ -891,16 +891,16 @@ void core_signal_analysis_high_bitrate_ivas_fx( FOR( frameno = 0; frameno < nSubframes; frameno++ ) { - L_subframe = L_frameTCX; + L_subframe = L_frameTCX; // Q0 move16(); IF( NE_16( nSubframes, 1 ) ) { L_subframe = shr( L_frameTCX, 1 ); } - lpc_left_overlap_mode = overlap_mode[frameno]; + lpc_left_overlap_mode = overlap_mode[frameno]; // Q0 move16(); - lpc_right_overlap_mode = overlap_mode[frameno + 1]; + lpc_right_overlap_mode = overlap_mode[frameno + 1]; // Q0 move16(); if ( EQ_16( lpc_left_overlap_mode, ALDO_WINDOW ) ) { @@ -921,13 +921,31 @@ void core_signal_analysis_high_bitrate_ivas_fx( IF( windowed_samples != NULL ) /* store overlap data for later */ { assert( frameno == 0 ); - windowed_samples[0] = L_deposit_l( overlap_mode[frameno] ); - windowed_samples[1] = L_deposit_l( overlap_mode[frameno + 1] ); + windowed_samples[0] = L_deposit_l( overlap_mode[frameno] ); // Q0 + windowed_samples[1] = L_deposit_l( overlap_mode[frameno + 1] ); // Q0 } IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { + Word16 left_overlap_mode, right_overlap_mode; + if ( EQ_16( overlap_mode[frameno], ALDO_WINDOW ) ) + { + left_overlap_mode = FULL_OVERLAP; + } + else + { + left_overlap_mode = overlap_mode[frameno]; // Q0 + } + + if ( EQ_16( overlap_mode[frameno + 1], ALDO_WINDOW ) ) + { + right_overlap_mode = FULL_OVERLAP; + } + else + { + right_overlap_mode = overlap_mode[frameno + 1]; // Q0 + } /* Windowing of the 2xTCX5 subframes or 1xTCX10 or 1xTCX20 */ - WindowSignal( st->hTcxCfg, st->hTcxCfg->tcx_offsetFB, overlap_mode[frameno] == ALDO_WINDOW ? FULL_OVERLAP : overlap_mode[frameno], overlap_mode[frameno + 1] == ALDO_WINDOW ? FULL_OVERLAP : overlap_mode[frameno + 1], &left_overlap, &right_overlap, &hTcxEnc->speech_TCX[frameno * tcx10SizeFB], &L_subframe, mdstWin, 1, 1 ); + WindowSignal( st->hTcxCfg, st->hTcxCfg->tcx_offsetFB, left_overlap_mode, right_overlap_mode, &left_overlap, &right_overlap, &hTcxEnc->speech_TCX[frameno * tcx10SizeFB], &L_subframe, mdstWin, 1, 1 ); } } ELSE @@ -941,13 +959,13 @@ void core_signal_analysis_high_bitrate_ivas_fx( { assert( L_subframe + ( left_overlap + right_overlap ) / 2 < 2 * L_FRAME_MAX / nSubframes - L_FRAME_MAX / 8 ); win_len = add( L_subframe, shr( add( left_overlap, right_overlap ), 1 ) ); - windowed_samples[frameno * L_FRAME_MAX + 0] = L_deposit_l( overlap_mode[frameno] ); - windowed_samples[frameno * L_FRAME_MAX + 1] = L_deposit_l( overlap_mode[frameno + 1] ); - Copy_Scale_sig_16_32( tcx20Win, windowed_samples + frameno * L_FRAME_MAX + 2, L_subframe + ( left_overlap + right_overlap ) / 2, 0 ); - *q_win = s_min( *q_win, sub( L_norm_arr( windowed_samples + frameno * L_FRAME_MAX + 2, L_subframe + ( left_overlap + right_overlap ) / 2 ), 1 ) ); + windowed_samples[frameno * L_FRAME_MAX + 0] = L_deposit_l( overlap_mode[frameno] ); // Q0 + windowed_samples[frameno * L_FRAME_MAX + 1] = L_deposit_l( overlap_mode[frameno + 1] ); // Q0 + Copy_Scale_sig_16_32( tcx20Win, windowed_samples + add( imult1616( frameno, L_FRAME_MAX ), 2 ), add( L_subframe, shr( add( left_overlap, right_overlap ), 1 ) ), 0 ); + *q_win = s_min( *q_win, sub( L_norm_arr( windowed_samples + add( imult1616( frameno, L_FRAME_MAX ), 2 ), add( L_subframe, shr( add( left_overlap, right_overlap ), 1 ) ) ), 1 ) ); move16(); #ifdef MSAN_FIX - Scale_sig32( windowed_samples + frameno * L_FRAME_MAX + 2, win_len, *q_win ); + Scale_sig32( windowed_samples + frameno * L_FRAME_MAX + 2, win_len, *q_win ); // q_win #endif } } @@ -960,7 +978,7 @@ void core_signal_analysis_high_bitrate_ivas_fx( FOR( i = 0; i < folding_offset; i++ ) { #ifdef BASOP_NOGLOB - tcx20Win[folding_offset + i] = sub_sat( tcx20Win[folding_offset + i], tcx20Win[folding_offset - 1 - i] ); + tcx20Win[folding_offset + i] = sub_sat( tcx20Win[folding_offset + i], tcx20Win[folding_offset - 1 - i] ); // Q0 #else tcx20Win[folding_offset + i] = sub( tcx20Win[folding_offset + i], tcx20Win[folding_offset - 1 - i] ); #endif @@ -1005,7 +1023,7 @@ void core_signal_analysis_high_bitrate_ivas_fx( FOR( i = 0; i < tmp; i++ ) { #ifdef BASOP_NOGLOB - tcx20Win[L_subframe + folding_offset - 1 - i] = add_sat( tcx20Win[L_subframe + folding_offset - 1 - i], tcx20Win[L_subframe + folding_offset + i] ); + tcx20Win[L_subframe + folding_offset - 1 - i] = add_sat( tcx20Win[L_subframe + folding_offset - 1 - i], tcx20Win[L_subframe + folding_offset + i] ); // Q0 #else tcx20Win[L_subframe + folding_offset - 1 - i] = add( tcx20Win[L_subframe + folding_offset - 1 - i], tcx20Win[L_subframe + folding_offset + i] ); #endif @@ -1163,7 +1181,7 @@ void core_signal_analysis_high_bitrate_ivas_fx( IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { - L_subframe = idiv1616( L_frameTCX, nSubframes ); + L_subframe = idiv1616( L_frameTCX, nSubframes ); /* Q0 */ test(); IF( EQ_16( transform_type[frameno], TCX_20 ) && NE_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) @@ -1183,7 +1201,7 @@ void core_signal_analysis_high_bitrate_ivas_fx( FOR( i = 0; i < left_overlap / 2; i++ ) { #ifdef BASOP_NOGLOB - mdstWin[left_overlap / 2 + i] = add_sat( mdstWin[left_overlap / 2 + i], mdstWin[left_overlap / 2 - 1 - i] ); + mdstWin[left_overlap / 2 + i] = add_sat( mdstWin[left_overlap / 2 + i], mdstWin[left_overlap / 2 - 1 - i] ); // Q0 #else mdstWin[left_overlap / 2 + i] = add( mdstWin[left_overlap / 2 + i], mdstWin[left_overlap / 2 - 1 - i] ); #endif @@ -1225,7 +1243,7 @@ void core_signal_analysis_high_bitrate_ivas_fx( FOR( i = 0; i < right_overlap / 2; i++ ) { #ifdef BASOP_NOGLOB - mdstWin[L_subframe + left_overlap / 2 - 1 - i] = sub_sat( mdstWin[L_subframe + left_overlap / 2 - 1 - i], mdstWin[L_subframe + left_overlap / 2 + i] ); + mdstWin[L_subframe + left_overlap / 2 - 1 - i] = sub_sat( mdstWin[L_subframe + left_overlap / 2 - 1 - i], mdstWin[L_subframe + left_overlap / 2 + i] ); // Q0 #else mdstWin[L_subframe + left_overlap / 2 - 1 - i] = sub( mdstWin[L_subframe + left_overlap / 2 - 1 - i], mdstWin[L_subframe + left_overlap / 2 + i] ); #endif @@ -1360,9 +1378,9 @@ void core_signal_analysis_high_bitrate_ivas_fx( /* group sub-windows: interleave bins according to their frequencies */ FOR( i = 0; i < tcx5SizeFB; i++ ) { - interleaveBuf[2 * i] = hTcxEnc->spectrum_fx[frameno][i]; + interleaveBuf[2 * i] = hTcxEnc->spectrum_fx[frameno][i]; /* hTcxEnc->spectrum_e */ move32(); - interleaveBuf[2 * i + 1] = hTcxEnc->spectrum_fx[frameno][tcx5SizeFB + i]; + interleaveBuf[2 * i + 1] = hTcxEnc->spectrum_fx[frameno][tcx5SizeFB + i]; /* hTcxEnc->spectrum_e */ move32(); } MVR2R_WORD32( interleaveBuf, hTcxEnc->spectrum_fx[frameno], tcx10SizeFB ); diff --git a/lib_enc/fd_cng_enc.c b/lib_enc/fd_cng_enc.c index 47408845100650353abdfd4e1c633078c2dfd84a..5c493876bab2caeb84ae0a6f9db36e2bcd1c5371 100644 --- a/lib_enc/fd_cng_enc.c +++ b/lib_enc/fd_cng_enc.c @@ -73,39 +73,39 @@ * Perform noise estimation *-------------------------------------------------------------------*/ void perform_noise_estimation_enc_ivas_fx( - Word32 *band_energies, /* i: energy in critical bands without minimum noise floor MODE2_E_MIN */ + Word32 *band_energies, /* i: energy in critical bands without minimum noise floor MODE2_E_MIN band_energies_exp*/ Word16 band_energies_exp, - Word32 *enerBuffer, + Word32 *enerBuffer, /* enerBuffer_exp */ Word16 enerBuffer_exp, HANDLE_FD_CNG_ENC hFdCngEnc, /* i/o: CNG structure containing all buffers and variables */ - const Word32 input_Fs, /* i : input sampling rate */ + const Word32 input_Fs, /* i : input sampling rate Q0*/ CPE_ENC_HANDLE hCPE /* i : CPE encoder structure */ ) { Word16 i, j, s, s1, s2; Word16 numBands; - Word16 numCoreBands = hFdCngEnc->hFdCngCom->numCoreBands; + Word16 numCoreBands = hFdCngEnc->hFdCngCom->numCoreBands; /* Q0 */ move16(); - Word16 regularStopBand = hFdCngEnc->hFdCngCom->regularStopBand; + Word16 regularStopBand = hFdCngEnc->hFdCngCom->regularStopBand; /* Q0 */ move16(); - Word16 numSlots = hFdCngEnc->hFdCngCom->numSlots; + Word16 numSlots = hFdCngEnc->hFdCngCom->numSlots; /* Q0 */ move16(); assert( numSlots == 16 ); Word32 numSlots_inv_fx = 134217728; move32(); - Word32 *periodog = hFdCngEnc->hFdCngCom->periodog; + Word32 *periodog = hFdCngEnc->hFdCngCom->periodog; /* exp(peridog_exp) */ Word32 *ptr_per_fx = periodog; - Word16 npart = hFdCngEnc->hFdCngCom->npart; + Word16 npart = hFdCngEnc->hFdCngCom->npart; /* Q0 */ move16(); - Word16 nFFTpart = hFdCngEnc->hFdCngCom->nFFTpart; + Word16 nFFTpart = hFdCngEnc->hFdCngCom->nFFTpart; /* Q0 */ move16(); - Word16 nCLDFBpart = hFdCngEnc->hFdCngCom->nCLDFBpart; + Word16 nCLDFBpart = hFdCngEnc->hFdCngCom->nCLDFBpart; /* Q0 */ move16(); - Word16 *psize = hFdCngEnc->hFdCngCom->psize; + Word16 *psize = hFdCngEnc->hFdCngCom->psize; // 6Q9 Word32 *msPeriodog_fx = hFdCngEnc->msPeriodog_fx; - Word32 *msNoiseEst_fx = hFdCngEnc->msNoiseEst_fx; + Word32 *msNoiseEst_fx = hFdCngEnc->msNoiseEst_fx; /* exp(msNoiseEst_fx_exp) */ Word16 *msLogPeriodog_fx = hFdCngEnc->msLogPeriodog_fx; Word16 *msLogNoiseEst_fx = hFdCngEnc->msLogNoiseEst_fx; @@ -170,7 +170,7 @@ void perform_noise_estimation_enc_ivas_fx( /* Adjust to the desired time resolution by averaging the periodograms over the time slots */ FOR( j = numCoreBands; j < regularStopBand; j++ ) { - *ptr_per_fx = Mpy_32_32( enerBuffer[j], scaleEB_fx ); + *ptr_per_fx = Mpy_32_32( enerBuffer[j], scaleEB_fx ); /* exp(enerBuffer_exp) */ move32(); ptr_per_fx++; @@ -181,7 +181,7 @@ void perform_noise_estimation_enc_ivas_fx( hFdCngEnc->hFdCngCom->exp_cldfb_periodog = add( sub( enerBuffer_exp, 4 ), CLDFBscalingFactor_EXP ); move16(); - numBands = sub( regularStopBand, numCoreBands ); + numBands = sub( regularStopBand, numCoreBands ); /* Q0 */ IF( numBands > 0 ) { @@ -211,13 +211,13 @@ void perform_noise_estimation_enc_ivas_fx( FOR( i = 0; i < nFFTpart; i++ ) { - msPeriodog_fx[i] = L_shr( msPeriodog_fx[i], s1 ); + msPeriodog_fx[i] = L_shr( msPeriodog_fx[i], s1 ); /* hFdCngEnc->msPeriodog_fx_exp_fft */ move32(); } FOR( i = 0; i < nCLDFBpart; i++ ) { - msPeriodog_fx[nFFTpart + i] = L_shr( msPeriodog_fx[nFFTpart + i], s_min( 31, s2 ) ); + msPeriodog_fx[nFFTpart + i] = L_shr( msPeriodog_fx[nFFTpart + i], s_min( 31, s2 ) ); /* hFdCngEnc->msPeriodog_fx_exp_fft */ move32(); } } @@ -425,14 +425,14 @@ void FdCng_encodeSID_ivas_fx( /* NB last band energy compensation */ IF( hFdCngCom->CngBandwidth == NB ) { - hFdCngCom->sidNoiseEst[N - 1] = Mpy_32_16_1( hFdCngCom->sidNoiseEst[N - 1], NB_LAST_BAND_SCALE ); + hFdCngCom->sidNoiseEst[N - 1] = Mpy_32_16_1( hFdCngCom->sidNoiseEst[N - 1], NB_LAST_BAND_SCALE ); // exp(hFdCngCom->sidNoiseEstExp) move32(); } test(); IF( EQ_16( hFdCngCom->CngBandwidth, SWB ) && LE_32( hFdCngCom->CngBitrate, ACELP_13k20 ) ) { - hFdCngCom->sidNoiseEst[N - 1] = Mpy_32_16_1( hFdCngCom->sidNoiseEst[N - 1], SWB_13k2_LAST_BAND_SCALE ); + hFdCngCom->sidNoiseEst[N - 1] = Mpy_32_16_1( hFdCngCom->sidNoiseEst[N - 1], SWB_13k2_LAST_BAND_SCALE ); // exp(hFdCngCom->sidNoiseEstExp) move32(); } @@ -485,7 +485,7 @@ void FdCng_encodeSID_ivas_fx( *-------------------------------------------------------------------*/ void stereoFdCngCoherence_fx( Encoder_State **sts, /* i/o: core encoder structures */ - const Word16 last_element_mode, /* i : last element mode */ + const Word16 last_element_mode, /* i : last element mode Q0*/ Word16 fft_buf_fx[CPE_CHANNELS][2 * L_FFT], /* i : fft buffers for L and R channels fft_exp*/ Word16 fft_exp ) { @@ -508,9 +508,9 @@ void stereoFdCngCoherence_fx( /* case: at least one channel has triggered VAD -> ACTIVE FRAME */ IF( EQ_32( sts[0]->core_brate, -1 ) ) { - sts[1]->total_brate = sts[0]->total_brate; + sts[1]->total_brate = sts[0]->total_brate; /* Q0 */ move32(); - sts[1]->active_cnt = sts[0]->active_cnt; + sts[1]->active_cnt = sts[0]->active_cnt; /* Q0 */ move16(); if ( GE_32( sts[1]->active_cnt, CNG_TYPE_HO ) ) { @@ -520,9 +520,9 @@ void stereoFdCngCoherence_fx( } IF( EQ_32( sts[1]->core_brate, -1 ) ) { - sts[0]->total_brate = sts[1]->total_brate; + sts[0]->total_brate = sts[1]->total_brate; /* Q0 */ move32(); - sts[0]->active_cnt = sts[1]->active_cnt; + sts[0]->active_cnt = sts[1]->active_cnt; /* Q0 */ move16(); if ( GE_16( sts[0]->active_cnt, CNG_TYPE_HO ) ) { @@ -556,15 +556,15 @@ void stereoFdCngCoherence_fx( } /* synchronize SID counters */ - sts[0]->hDtxEnc->cnt_SID = s_min( sts[0]->hDtxEnc->cnt_SID, sts[1]->hDtxEnc->cnt_SID ); - sts[1]->hDtxEnc->cnt_SID = sts[0]->hDtxEnc->cnt_SID; + sts[0]->hDtxEnc->cnt_SID = s_min( sts[0]->hDtxEnc->cnt_SID, sts[1]->hDtxEnc->cnt_SID ); /* Q0 */ + sts[1]->hDtxEnc->cnt_SID = sts[0]->hDtxEnc->cnt_SID; /* Q0 */ move16(); move16(); } pt_fftL = fft_buf_fx[0]; pt_fftR = fft_buf_fx[1]; - mem = sts[0]->hFdCngEnc->mem_coherence_fx; + mem = sts[0]->hFdCngEnc->mem_coherence_fx; /* exp(sts[0]->hFdCngEnc->mem_coherence_exp) */ mem_exp = sts[0]->hFdCngEnc->mem_coherence_exp; FOR( i_subfr = 0; i_subfr < 2; i_subfr++ ) { @@ -579,28 +579,28 @@ void stereoFdCngCoherence_fx( move16(); move16(); - cr = BASOP_Util_Add_Mant32Exp( cr, cr_exp, L_add( L_mult( pt_fftL[0], pt_fftR[0] ), L_mult( pt_fftL[L_FFT / 2], pt_fftR[L_FFT / 2] ) ), shl( fft_exp, 1 ), &cr_exp ); - eL = BASOP_Util_Add_Mant32Exp( eL, eL_exp, L_add( L_mult( pt_fftL[0], pt_fftL[0] ), L_mult( pt_fftL[L_FFT / 2], pt_fftL[L_FFT / 2] ) ), shl( fft_exp, 1 ), &eL_exp ); - eR = BASOP_Util_Add_Mant32Exp( eR, eR_exp, L_add( L_mult( pt_fftR[0], pt_fftR[0] ), L_mult( pt_fftR[L_FFT / 2], pt_fftR[L_FFT / 2] ) ), shl( fft_exp, 1 ), &eR_exp ); + cr = BASOP_Util_Add_Mant32Exp( cr, cr_exp, L_add( L_mult( pt_fftL[0], pt_fftR[0] ), L_mult( pt_fftL[L_FFT / 2], pt_fftR[L_FFT / 2] ) ), shl( fft_exp, 1 ), &cr_exp ); /* exp(cr_exp) */ + eL = BASOP_Util_Add_Mant32Exp( eL, eL_exp, L_add( L_mult( pt_fftL[0], pt_fftL[0] ), L_mult( pt_fftL[L_FFT / 2], pt_fftL[L_FFT / 2] ) ), shl( fft_exp, 1 ), &eL_exp ); /* exp(eL_exp) */ + eR = BASOP_Util_Add_Mant32Exp( eR, eR_exp, L_add( L_mult( pt_fftR[0], pt_fftR[0] ), L_mult( pt_fftR[L_FFT / 2], pt_fftR[L_FFT / 2] ) ), shl( fft_exp, 1 ), &eR_exp ); /* exp(eR_exp) */ FOR( i = 1; i < L_FFT / 2; i++ ) { - cr = BASOP_Util_Add_Mant32Exp( cr, cr_exp, L_add( L_mult( pt_fftL[i], pt_fftR[i] ), L_mult( pt_fftL[L_FFT - i], pt_fftR[L_FFT - i] ) ), shl( fft_exp, 1 ), &cr_exp ); - ci = BASOP_Util_Add_Mant32Exp( ci, ci_exp, L_add( L_mult( -pt_fftL[i], pt_fftR[L_FFT - i] ), L_mult( pt_fftL[L_FFT - i], pt_fftR[i] ) ), shl( fft_exp, 1 ), &ci_exp ); - eL = BASOP_Util_Add_Mant32Exp( eL, eL_exp, L_add( L_mult( pt_fftL[i], pt_fftL[i] ), L_mult( pt_fftL[L_FFT - i], pt_fftL[L_FFT - i] ) ), shl( fft_exp, 1 ), &eL_exp ); - eR = BASOP_Util_Add_Mant32Exp( eR, eR_exp, L_add( L_mult( pt_fftR[i], pt_fftR[i] ), L_mult( pt_fftR[L_FFT - i], pt_fftR[L_FFT - i] ) ), shl( fft_exp, 1 ), &eR_exp ); + cr = BASOP_Util_Add_Mant32Exp( cr, cr_exp, L_add( L_mult( pt_fftL[i], pt_fftR[i] ), L_mult( pt_fftL[L_FFT - i], pt_fftR[L_FFT - i] ) ), shl( fft_exp, 1 ), &cr_exp ); /* exp(cr_exp) */ + ci = BASOP_Util_Add_Mant32Exp( ci, ci_exp, L_add( L_mult( -pt_fftL[i], pt_fftR[L_FFT - i] ), L_mult( pt_fftL[L_FFT - i], pt_fftR[i] ) ), shl( fft_exp, 1 ), &ci_exp ); /* exp(ci_exp) */ + eL = BASOP_Util_Add_Mant32Exp( eL, eL_exp, L_add( L_mult( pt_fftL[i], pt_fftL[i] ), L_mult( pt_fftL[L_FFT - i], pt_fftL[L_FFT - i] ) ), shl( fft_exp, 1 ), &eL_exp ); /* exp(eL_exp) */ + eR = BASOP_Util_Add_Mant32Exp( eR, eR_exp, L_add( L_mult( pt_fftR[i], pt_fftR[i] ), L_mult( pt_fftR[L_FFT - i], pt_fftR[L_FFT - i] ) ), shl( fft_exp, 1 ), &eR_exp ); /* exp(eR_exp) */ } test(); test(); IF( LE_32( sts[0]->ini_frame, 50 ) || ( sts[0]->vad_flag == 0 && sts[1]->vad_flag == 0 ) ) { - mem[0] = BASOP_Util_Add_Mant32Exp( Mpy_32_16_1( mem[0], 31129 /*0.95f*/ ), mem_exp[0], Mpy_32_16_1( cr, 1638 /*0.05f*/ ), cr_exp, &mem_exp[0] ); + mem[0] = BASOP_Util_Add_Mant32Exp( Mpy_32_16_1( mem[0], 31129 /*0.95f*/ ), mem_exp[0], Mpy_32_16_1( cr, 1638 /*0.05f*/ ), cr_exp, &mem_exp[0] ); /* exp(mem_exp[0]) */ move32(); - mem[1] = BASOP_Util_Add_Mant32Exp( Mpy_32_16_1( mem[1], 31129 /*0.95f*/ ), mem_exp[1], Mpy_32_16_1( ci, 1638 /*0.05f*/ ), ci_exp, &mem_exp[1] ); + mem[1] = BASOP_Util_Add_Mant32Exp( Mpy_32_16_1( mem[1], 31129 /*0.95f*/ ), mem_exp[1], Mpy_32_16_1( ci, 1638 /*0.05f*/ ), ci_exp, &mem_exp[1] ); /* exp(mem_exp[1]) */ move32(); - mem[2] = BASOP_Util_Add_Mant32Exp( Mpy_32_16_1( mem[2], 31129 /*0.95f*/ ), mem_exp[2], Mpy_32_16_1( eL, 1638 /*0.05f*/ ), eL_exp, &mem_exp[2] ); + mem[2] = BASOP_Util_Add_Mant32Exp( Mpy_32_16_1( mem[2], 31129 /*0.95f*/ ), mem_exp[2], Mpy_32_16_1( eL, 1638 /*0.05f*/ ), eL_exp, &mem_exp[2] ); /* exp(mem_exp[2]) */ move32(); - mem[3] = BASOP_Util_Add_Mant32Exp( Mpy_32_16_1( mem[3], 31129 /*0.95f*/ ), mem_exp[3], Mpy_32_16_1( eR, 1638 /*0.05f*/ ), eR_exp, &mem_exp[3] ); + mem[3] = BASOP_Util_Add_Mant32Exp( Mpy_32_16_1( mem[3], 31129 /*0.95f*/ ), mem_exp[3], Mpy_32_16_1( eR, 1638 /*0.05f*/ ), eR_exp, &mem_exp[3] ); /* exp(mem_exp[3]) */ move32(); } @@ -609,7 +609,7 @@ void stereoFdCngCoherence_fx( } Word16 sqr_inp, temp, sqr_out, sqr_inp_exp; - Word32 sqr_inp32 = BASOP_Util_Add_Mant32Exp( Mpy_32_32( mem[0], mem[0] ), shl( mem_exp[0], 1 ), Mpy_32_32( mem[1], mem[1] ), shl( mem_exp[1], 1 ), &sqr_inp_exp ); + Word32 sqr_inp32 = BASOP_Util_Add_Mant32Exp( Mpy_32_32( mem[0], mem[0] ), shl( mem_exp[0], 1 ), Mpy_32_32( mem[1], mem[1] ), shl( mem_exp[1], 1 ), &sqr_inp_exp ); /* exp(sqr_inp_exp) */ sqr_inp = BASOP_Util_Divide3232_Scale( sqr_inp32, Mpy_32_32( mem[2], mem[3] ), &temp ); sqr_inp_exp = add( temp, sub( sqr_inp_exp, add( mem_exp[2], mem_exp[3] ) ) ); sqr_out = Sqrt16( sqr_inp, &sqr_inp_exp ); @@ -666,13 +666,13 @@ void FdCngEncodeMDCTStereoSID_fx( FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { sts[ch] = hCPE->hCoreCoder[ch]; - lr_in_ptr_fx[ch] = &sts[ch]->hFdCngEnc->msNoiseEst_fx[0]; + lr_in_ptr_fx[ch] = &sts[ch]->hFdCngEnc->msNoiseEst_fx[0]; /* exp(sts[ch]->hFdCngEnc->msNoiseEst_fx_exp) */ lr_in_ptr_e[ch] = sts[ch]->hFdCngEnc->msNoiseEst_fx_exp; ms_ptr_fx[ch] = &logNoiseEst_fx[ch][0]; - lr_out_ptr_fx[ch] = &sts[ch]->hFdCngEnc->hFdCngCom->sidNoiseEst[0]; + lr_out_ptr_fx[ch] = &sts[ch]->hFdCngEnc->hFdCngCom->sidNoiseEst[0]; /* exp(sts[ch]->hFdCngEnc->hFdCngCom->sidNoiseEstExp) */ lr_out_ptr_e[ch] = sts[ch]->hFdCngEnc->hFdCngCom->sidNoiseEstExp; } - N = sts[0]->hFdCngEnc->npartDec; + N = sts[0]->hFdCngEnc->npartDec; /* Q0 */ move16(); set16_fx( weights_fx, ONE_IN_Q8, NPART ); @@ -733,14 +733,14 @@ void FdCngEncodeMDCTStereoSID_fx( move32(); FOR( p = N_GAIN_MIN; p < N_GAIN_MAX; p++ ) { - tmp32 = Mpy_32_32( ms_ptr_fx[ch][p], 165191050 ); // Q23 - gain_fx[ch] = L_add( gain_fx[ch], tmp32 ); // Q23 + tmp32 = Mpy_32_32( ms_ptr_fx[ch][p], 165191050 /* 0.07 in Q31*/ ); // Q23 + gain_fx[ch] = L_add( gain_fx[ch], tmp32 ); // Q23 move32(); } FOR( p = 0; p < N; p++ ) { - ms_ptr_fx[ch][p] = L_sub( ms_ptr_fx[ch][p], gain_fx[ch] ); + ms_ptr_fx[ch][p] = L_sub( ms_ptr_fx[ch][p], gain_fx[ch] ); // Q23 move32(); } } @@ -823,7 +823,7 @@ void FdCngEncodeMDCTStereoSID_fx( tmp = Inv16( N, &tmp_e ); FOR( p = 0; p < N; p++ ) { - gain_fx[ch] = L_add( gain_fx[ch], Mpy_32_16_1( ms_ptr_fx[ch][p], shl( tmp, tmp_e ) ) ); + gain_fx[ch] = L_add( gain_fx[ch], Mpy_32_16_1( ms_ptr_fx[ch][p], shl( tmp, tmp_e ) ) ); // Q23 move32(); } gain_fx[ch] = L_sub( L_shl( Mpy_32_16_1( E_fx[ch], shl( tmp, tmp_e ) ), Q23 - Q19 ), L_shl( gain_fx[ch], sub( ms_ptr_e, 8 ) ) ); // Q23 @@ -832,7 +832,7 @@ void FdCngEncodeMDCTStereoSID_fx( apply_scale( &gain_fx[ch], sts[ch]->hFdCngEnc->hFdCngCom->CngBandwidth, sts[ch]->element_brate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO ); /* quantize gain */ - gain_idx[ch] = (Word16) Mpy_32_32_r( L_add( gain_fx[ch], 251658240 ), 384 ); + gain_idx[ch] = (Word16) Mpy_32_32_r( L_add( gain_fx[ch], 251658240 ), 384 ); // Q23 move16(); gain_idx[ch] = s_max( 0, s_min( 127, gain_idx[ch] ) ); move16(); @@ -1008,14 +1008,14 @@ void FdCngEncodeDiracMDCTStereoSID_fx( move16(); FOR( p = N_GAIN_MIN; p < N_GAIN_MAX; p++ ) { - tmp32 = Mpy_32_32( ms_ptr_fx[0][p], 165191050 ); // Q23 - gain_fx[0] = L_add( gain_fx[0], tmp32 ); // Q23 + tmp32 = Mpy_32_32( ms_ptr_fx[0][p], 165191050 /* 0.07 in Q31 */ ); // Q23 + gain_fx[0] = L_add( gain_fx[0], tmp32 ); // Q23 move32(); } FOR( p = 0; p < N[0]; p++ ) { - ms_ptr_fx[0][p] = L_sub( ms_ptr_fx[0][p], gain_fx[0] ); + ms_ptr_fx[0][p] = L_sub( ms_ptr_fx[0][p], gain_fx[0] ); // Q23 move32(); } @@ -1035,7 +1035,7 @@ void FdCngEncodeDiracMDCTStereoSID_fx( extend_dctN_input_fx( ms_ptr_fx[0], dct_target_fx, N[0], tot_sig_ext_fx, FDCNG_VQ_MAX_LEN, invTrfMatrix_fx, FDCNG_VQ_DCT_MAXTRUNC, IDCT_T2_XX_21 ); /* use 18 basis vectors*/ - Copy32( tot_sig_ext_fx, ms_ptr_fx[0], FDCNG_VQ_MAX_LEN ); /* write extended result as input to VQ stage #1 */ + Copy32( tot_sig_ext_fx, ms_ptr_fx[0], FDCNG_VQ_MAX_LEN ); /* write extended result as input to VQ stage #1 Q23*/ } create_IDCT_N_Matrix_fx( invTrfMatrix_fx, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, sizeof( tmpRAM_fx ) / ( sizeof( Word32 ) ) ); @@ -1043,7 +1043,7 @@ void FdCngEncodeDiracMDCTStereoSID_fx( msvq_dec_fx( ivas_cdk_37bits_fx, NULL, NULL, FD_CNG_stages_37bits, N[0], FD_CNG_maxN_37bits, indices[0], 1, invTrfMatrix_fx, ms_ptr_fx[0], NULL, 7 ); shift = find_guarded_bits_fx( N[0] ); ms_ptr_e = sub( 31, sub( 20, shift ) ); - scale_sig32( ms_ptr_fx[1], N[1], sub( 8, ms_ptr_e ) ); + scale_sig32( ms_ptr_fx[1], N[1], sub( 8, ms_ptr_e ) ); /* Q31 - ms_ptr_e */ /* set S to zero */ set32_fx( ms_ptr_fx[1], 0, NPART ); @@ -1056,7 +1056,7 @@ void FdCngEncodeDiracMDCTStereoSID_fx( tmp = Inv16( N[0], &tmp_e ); FOR( p = 0; p < N[0]; p++ ) { - gain_fx[0] = L_add( gain_fx[0], Mpy_32_16_1( ms_ptr_fx[0][p], shl( tmp, tmp_e ) ) ); + gain_fx[0] = L_add( gain_fx[0], Mpy_32_16_1( ms_ptr_fx[0][p], shl( tmp, tmp_e ) ) ); // Q23 move32(); } gain_fx[0] = L_sub( L_shl( Mpy_32_16_1( E_fx[0], shl( tmp, tmp_e ) ), Q23 - Q18 ), L_shl( gain_fx[0], ms_ptr_e - 8 ) ); // Q23 @@ -1070,7 +1070,7 @@ void FdCngEncodeDiracMDCTStereoSID_fx( gain_idx[0] = s_max( 0, s_min( 127, gain_idx[0] ) ); move16(); - gain_fx[0] = Mpy_32_16_1( L_shl( sub( gain_idx[0], GAIN_Q_OFFSET_IVAS_FX_Q0 ), 23 ), 21845 ); // Q23 + gain_fx[0] = Mpy_32_16_1( L_shl( sub( gain_idx[0], GAIN_Q_OFFSET_IVAS_FX_Q0 ), 23 ), 21845 /* 0.66 in Q15 */ ); // Q23 move32(); gain_fx[1] = gain_fx[0]; // Q23 move32(); @@ -1089,9 +1089,9 @@ void FdCngEncodeDiracMDCTStereoSID_fx( tmp_e = -MAX_16; FOR( p = 0; p < N[ch]; p++ ) { - pow = L_shl( gain_fx[ch], sub( 8, ms_ptr_e ) ); - pow = L_add( ms_ptr_fx[ch][p], pow ); - pow = Mpy_32_32( pow, 214748365 ); /*pow = 0.1*/ + pow = L_shl( gain_fx[ch], sub( 8, ms_ptr_e ) ); /* Q31 - ms_ptr_e */ + pow = L_add( ms_ptr_fx[ch][p], pow ); /* Q31 - ms_ptr_e */ + pow = Mpy_32_32( pow, 214748365 /* 0.1 in Q31 */ ); /*pow = 0.1 Q31 - ms_ptr_e*/ lr_out_ptr_fx[ch][p] = BASOP_Util_fPow( 10, 31, pow, ms_ptr_e, &e_lr_out[p] ); tmp_e = s_max( tmp_e, e_lr_out[p] ); } @@ -1109,12 +1109,12 @@ void FdCngEncodeDiracMDCTStereoSID_fx( /* NB last band energy compensation */ IF( hFdCngCom->CngBandwidth == NB ) { - lr_out_ptr_fx[ch][N[ch] - 1] = Mpy_32_16_1( lr_out_ptr_fx[ch][N[ch] - 1], NB_LAST_BAND_SCALE ); + lr_out_ptr_fx[ch][N[ch] - 1] = Mpy_32_16_1( lr_out_ptr_fx[ch][N[ch] - 1], NB_LAST_BAND_SCALE ); // Q(31 - tmp_e) move32(); } ELSE IF( hFdCngCom->CngBandwidth == SWB && LE_32( hFdCngCom->CngBitrate, ACELP_13k20 ) ) { - lr_out_ptr_fx[ch][N[ch] - 1] = Mpy_32_16_1( lr_out_ptr_fx[ch][N[ch] - 1], SWB_13k2_LAST_BAND_SCALE ); + lr_out_ptr_fx[ch][N[ch] - 1] = Mpy_32_16_1( lr_out_ptr_fx[ch][N[ch] - 1], SWB_13k2_LAST_BAND_SCALE ); // Q(31 - tmp_e) move32(); } /* scale bands and get scalefactors */ diff --git a/lib_enc/fd_cng_enc_fx.c b/lib_enc/fd_cng_enc_fx.c index 34b67b2ff575ffc52bfd6e7505d1a74921c26d89..8591f2627520c77121199284c3c78f349c58c059 100644 --- a/lib_enc/fd_cng_enc_fx.c +++ b/lib_enc/fd_cng_enc_fx.c @@ -51,7 +51,10 @@ void createFdCngEnc_fx( HANDLE_FD_CNG_ENC *hFdCngEnc ) return; } -void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale ) +void initFdCngEnc_fx( + HANDLE_FD_CNG_ENC hsEnc, + Word32 input_Fs, /* Q0 */ + Word16 scale ) { Word16 j; HANDLE_FD_CNG_COM hsCom = hsEnc->hFdCngCom; @@ -65,7 +68,7 @@ void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale ) move16(); hsCom->numCoreBands = 16; move16(); - hsCom->regularStopBand = idiv1616U( extract_l( L_shr( input_Fs, 5 ) ), 25 ); + hsCom->regularStopBand = idiv1616U( extract_l( L_shr( input_Fs, 5 ) ), 25 ); /* Q0 */ move16(); if ( GT_16( hsCom->regularStopBand, 40 ) ) { @@ -88,7 +91,7 @@ void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale ) { hsCom->stopFFTbin = 256; move16(); - hsCom->stopBand = add( sub( hsCom->regularStopBand, hsCom->numCoreBands ), hsCom->stopFFTbin ); + hsCom->stopBand = add( sub( hsCom->regularStopBand, hsCom->numCoreBands ), hsCom->stopFFTbin ); /* Q0 */ move16(); hsCom->nFFTpart = 20; move16(); @@ -96,12 +99,12 @@ void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale ) initPartitions( sidparts_encoder_noise_est, SIZE_SIDPARTS_ENC_NOISE_EST, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_norm, &hsCom->psize_norm_exp, hsCom->psize_inv, 0 ); - hsCom->nCLDFBpart = sub( hsCom->npart, hsCom->nFFTpart ); + hsCom->nCLDFBpart = sub( hsCom->npart, hsCom->nFFTpart ); /* Q0 */ move16(); FOR( j = 0; j < hsCom->nCLDFBpart; j++ ) { - hsCom->CLDFBpart[j] = sub( hsCom->part[j + hsCom->nFFTpart], sub( 256, hsCom->startBand ) ); - hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[j + hsCom->nFFTpart]; + hsCom->CLDFBpart[j] = sub( hsCom->part[j + hsCom->nFFTpart], sub( 256, hsCom->startBand ) ); /* Q0 */ + hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[j + hsCom->nFFTpart]; /* Q15 */ move16(); move16(); } @@ -151,8 +154,9 @@ void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale ) * Configure FD_CNG * ************************************/ void configureFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, /* i/o: Contains the variables related to the FD-based CNG process */ - Word16 bandwidth, /* i: bandwidth */ - Word32 bitrate ) + Word16 bandwidth, /* i: bandwidth Q0*/ + Word32 bitrate /* Q0 */ +) { HANDLE_FD_CNG_COM hsCom = hsEnc->hFdCngCom; Word16 psizeDec[NPART]; @@ -169,7 +173,7 @@ void configureFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, /* i/o: Contains the variabl hsCom->CngBandwidth = SWB; move16(); } - hsCom->CngBitrate = bitrate; + hsCom->CngBitrate = bitrate; /* Q0 */ move32(); /* NB configuration */ @@ -212,16 +216,16 @@ void configureFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, /* i/o: Contains the variabl hsCom->FdCngSetup = FdCngSetup_swb2; } } - hsCom->fftlen = hsCom->FdCngSetup.fftlen; + hsCom->fftlen = hsCom->FdCngSetup.fftlen; /* Q0 */ move16(); - hsEnc->stopFFTbinDec = hsCom->FdCngSetup.stopFFTbin; + hsEnc->stopFFTbinDec = hsCom->FdCngSetup.stopFFTbin; /* Q0 */ move16(); /* Configure the SID quantizer and the Confort Noise Generator */ - hsEnc->startBandDec = hsCom->startBand; + hsEnc->startBandDec = hsCom->startBand; /* Q0 */ move16(); - hsEnc->stopBandDec = add( hsCom->FdCngSetup.sidPartitions[hsCom->FdCngSetup.numPartitions - 1], 1 ); + hsEnc->stopBandDec = add( hsCom->FdCngSetup.sidPartitions[hsCom->FdCngSetup.numPartitions - 1], 1 ); /* Q0 */ move16(); initPartitions( hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, @@ -277,8 +281,9 @@ void configureFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, /* i/o: Contains the variabl void configureFdCngEnc_ivas_fx( HANDLE_FD_CNG_ENC hFdCngEnc, /* i/o: Contains the variables related to the FD-based CNG process */ - const Word16 bwidth, - const Word32 total_brate ) + const Word16 bwidth, /* Q0 */ + const Word32 total_brate /* Q0 */ +) { HANDLE_FD_CNG_COM hsCom = hFdCngEnc->hFdCngCom; Word16 psizeDec[NPART]; @@ -288,14 +293,14 @@ void configureFdCngEnc_ivas_fx( set16_fx( psizeDec, 0, NPART ); - hsCom->CngBandwidth = bwidth; + hsCom->CngBandwidth = bwidth; /* Q0 */ move16(); IF( EQ_16( hsCom->CngBandwidth, FB ) ) { hsCom->CngBandwidth = SWB; move16(); } - hsCom->CngBitrate = total_brate; + hsCom->CngBitrate = total_brate; /* Q0 */ move32(); /* NB configuration */ @@ -338,16 +343,16 @@ void configureFdCngEnc_ivas_fx( hsCom->FdCngSetup = FdCngSetup_swb2; } } - hsCom->fftlen = hsCom->FdCngSetup.fftlen; + hsCom->fftlen = hsCom->FdCngSetup.fftlen; /* Q0 */ move16(); - hFdCngEnc->stopFFTbinDec = hsCom->FdCngSetup.stopFFTbin; + hFdCngEnc->stopFFTbinDec = hsCom->FdCngSetup.stopFFTbin; /* Q0 */ move16(); /* Configure the SID quantizer and the Confort Noise Generator */ - hFdCngEnc->startBandDec = hsCom->startBand; + hFdCngEnc->startBandDec = hsCom->startBand; /* Q0 */ move16(); - hFdCngEnc->stopBandDec = add( hsCom->FdCngSetup.sidPartitions[hsCom->FdCngSetup.numPartitions - 1], 1 ); + hFdCngEnc->stopBandDec = add( hsCom->FdCngSetup.sidPartitions[hsCom->FdCngSetup.numPartitions - 1], 1 ); /* Q0 */ move16(); initPartitions( hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, @@ -381,17 +386,17 @@ void configureFdCngEnc_ivas_fx( { case 512: hsCom->fftSineTab_fx = NULL; - hsCom->olapWinAna_fx = olapWinAna512_fx; - hsCom->olapWinSyn_fx = olapWinSyn256_fx; + hsCom->olapWinAna_fx = olapWinAna512_fx; /* Q30 */ + hsCom->olapWinSyn_fx = olapWinSyn256_fx; /* Q15 */ hsCom->fftlenShift = 8; move16(); hsCom->fftlenFac = 32767 /*1.0 Q15*/; move16(); BREAK; case 640: - hsCom->fftSineTab_fx = fftSineTab640_fx; - hsCom->olapWinAna_fx = olapWinAna640_fx; - hsCom->olapWinSyn_fx = olapWinSyn320_fx; + hsCom->fftSineTab_fx = fftSineTab640_fx; /* Q15 */ + hsCom->olapWinAna_fx = olapWinAna640_fx; /* Q30 */ + hsCom->olapWinSyn_fx = olapWinSyn320_fx; /* Q15 */ hsCom->fftlenShift = 9; move16(); hsCom->fftlenFac = 20480 /*0.625 Q15*/; @@ -440,8 +445,8 @@ void resetFdCngEnc_fx( /* st->totalNoise_fx; Q8 Noise estimator - total noise energy */ /* Detect fast increase of totalNoise */ - totalNoiseIncrease = sub( hNoiseEst->totalNoise_fx, st->last_totalNoise_fx ); - st->last_totalNoise_fx = hNoiseEst->totalNoise_fx; + totalNoiseIncrease = sub( hNoiseEst->totalNoise_fx, st->last_totalNoise_fx ); // Q8 + st->last_totalNoise_fx = hNoiseEst->totalNoise_fx; // Q8 move16(); IF( totalNoiseIncrease > 0 ) { @@ -449,17 +454,17 @@ void resetFdCngEnc_fx( { FOR( n = 0; n < TOTALNOISE_HIST_SIZE - 1; n++ ) { - st->totalNoise_increase_hist_fx[n] = st->totalNoise_increase_hist_fx[n + 1]; + st->totalNoise_increase_hist_fx[n] = st->totalNoise_increase_hist_fx[n + 1]; // Q8 move16(); } - st->totalNoise_increase_hist_fx[TOTALNOISE_HIST_SIZE - 1] = totalNoiseIncrease; + st->totalNoise_increase_hist_fx[TOTALNOISE_HIST_SIZE - 1] = totalNoiseIncrease; // Q8 move16(); } ELSE { - st->totalNoise_increase_hist_fx[st->totalNoise_increase_len] = totalNoiseIncrease; + st->totalNoise_increase_hist_fx[st->totalNoise_increase_len] = totalNoiseIncrease; // Q8 move16(); - st->totalNoise_increase_len = add( st->totalNoise_increase_len, 1 ); + st->totalNoise_increase_len = add( st->totalNoise_increase_len, 1 ); // Q0 } } ELSE @@ -471,7 +476,7 @@ void resetFdCngEnc_fx( move16(); FOR( n = 0; n < st->totalNoise_increase_len; n++ ) { - totalNoiseIncrease = add( totalNoiseIncrease, st->totalNoise_increase_hist_fx[n] ); + totalNoiseIncrease = add( totalNoiseIncrease, st->totalNoise_increase_hist_fx[n] ); // Q8 } test(); @@ -518,9 +523,9 @@ void resetFdCngEnc_fx( Returns: void */ -void perform_noise_estimation_enc_fx( Word32 *band_energies, /* i: energy in critical bands without minimum noise floor MODE2_E_MIN */ +void perform_noise_estimation_enc_fx( Word32 *band_energies, /* i: energy in critical bands without minimum noise floor MODE2_E_MIN band_energies_exp*/ Word16 band_energies_exp, /* i: exponent for energy in critical bands without minimum noise floor MODE2_E_MIN */ - Word32 *enerBuffer, + Word32 *enerBuffer, /* enerBuffer_exp */ Word16 enerBuffer_exp, HANDLE_FD_CNG_ENC st /* i/o: FD_CNG structure containing all buffers and variables */ ) @@ -560,8 +565,8 @@ void perform_noise_estimation_enc_fx( Word32 *band_energies, /* i: energy in /* preemphasis compensation and grouping of per bin energies into msPeriodog */ FOR( i = 0; i < nFFTpart; i++ ) { - tmp = L_add( L_shr( band_energies[i], 1 ), L_shr( band_energies[i + NB_BANDS], 1 ) ); - msPeriodog[i] = Mpy_32_16_1( tmp, preemphCompensation_fx[i] ); + tmp = L_add( L_shr( band_energies[i], 1 ), L_shr( band_energies[i + NB_BANDS], 1 ) ); /* exp(band_energies_exp) */ + msPeriodog[i] = Mpy_32_16_1( tmp, preemphCompensation_fx[i] ); /* exp(band_energies_exp + 4) */ move32(); } @@ -569,7 +574,7 @@ void perform_noise_estimation_enc_fx( Word32 *band_energies, /* i: energy in st->msPeriodog_fx_exp_fft = add( band_energies_exp, PREEMPH_COMPENSATION_EXP ); move16(); - numBands = sub( regularStopBand, numCoreBands ); + numBands = sub( regularStopBand, numCoreBands ); /* Q0 */ IF( numBands > 0 ) { @@ -577,7 +582,7 @@ void perform_noise_estimation_enc_fx( Word32 *band_energies, /* i: energy in FOR( j = numCoreBands; j < regularStopBand; j++ ) { - *ptr_per = Mpy_32_16_1( enerBuffer[j], st->hFdCngCom->scalingFactor ); + *ptr_per = Mpy_32_16_1( enerBuffer[j], st->hFdCngCom->scalingFactor ); /* exp(enerBuffer_exp) */ move32(); ptr_per++; @@ -612,13 +617,13 @@ void perform_noise_estimation_enc_fx( Word32 *band_energies, /* i: energy in FOR( i = 0; i < nFFTpart; i++ ) { - msPeriodog[i] = L_shr( msPeriodog[i], s1 ); + msPeriodog[i] = L_shr( msPeriodog[i], s1 ); // st->msPeriodog_fx_exp_fft move32(); } FOR( i = 0; i < nCLDFBpart; i++ ) { - msPeriodog[nFFTpart + i] = L_shr( msPeriodog[nFFTpart + i], s_min( 31, s2 ) ); + msPeriodog[nFFTpart + i] = L_shr( msPeriodog[nFFTpart + i], s_min( 31, s2 ) ); // st->msPeriodog_fx_exp_fft move32(); } } @@ -681,19 +686,18 @@ void perform_noise_estimation_enc_fx( Word32 *band_energies, /* i: energy in Returns: void */ -Word16 -AdjustFirstSID_fx( - Word16 npart, /* i : number of parts */ - Word32 *msPeriodog, /* i : pointer to periodog vector */ - Word16 msPeriodog_exp, /* i : exponent of periodog vector */ - Word32 *energy_ho, /* i/o : pointer to energy */ - Word16 *energy_ho_exp, /* i/o : pointer to exponent of energy */ - Word32 *msNoiseEst, /* i/o : pointer to estimated noise */ - Word16 *msNoiseEst_exp, /* i/o : pointer to exponent of estimated noise */ - Word32 *msNoiseEst_old, /* i/o : pointer to old estimated noise */ - Word16 *msNoiseEst_old_exp, /* i/o : pointer to exponent of old estimated noise */ - Word16 *active_frame_counter, /* i/o : pointer to active frame counter */ - Encoder_State *stcod /* i : pointer to Coder_State_Plus structure */ +Word16 AdjustFirstSID_fx( + Word16 npart, /* i : number of parts Q0*/ + Word32 *msPeriodog, /* i : pointer to periodog vector msPeriodog_exp */ + Word16 msPeriodog_exp, /* i : exponent of periodog vector */ + Word32 *energy_ho, /* i/o : pointer to energy energy_ho_exp*/ + Word16 *energy_ho_exp, /* i/o : pointer to exponent of energy */ + Word32 *msNoiseEst, /* i/o : pointer to estimated noise msNoiseEst_exp*/ + Word16 *msNoiseEst_exp, /* i/o : pointer to exponent of estimated noise */ + Word32 *msNoiseEst_old, /* i/o : pointer to old estimated noise msNoiseEst_old_exp*/ + Word16 *msNoiseEst_old_exp, /* i/o : pointer to exponent of old estimated noise */ + Word16 *active_frame_counter, /* i/o : pointer to active frame counter Q0*/ + Encoder_State *stcod /* i : pointer to Coder_State_Plus structure */ ) { Word16 i, sc, s1, s2, lambda, lambdaM1, invFac; @@ -706,7 +710,7 @@ AdjustFirstSID_fx( /* Detect the hangover period and the first SID frame at the beginning of each CNG phase */ /* First hangover frame */ - Copy32( msPeriodog, energy_ho, npart ); + Copy32( msPeriodog, energy_ho, npart ); /* exp(msPeriodog_exp) */ *energy_ho_exp = msPeriodog_exp; move16(); @@ -724,8 +728,8 @@ AdjustFirstSID_fx( /* active_frame_counter scaled by (1/1024.0) for compensation */ tmp32 = L_shl( L_deposit_l( add( *active_frame_counter, 1 ) ), WORD32_BITS - 1 - 10 ); tmp32 = BASOP_Util_InvLog2( Mpy_32_16_1( tmp32, -30877 /*-0.94229902485 Q15*/ ) ); - lambda = extract_h( tmp32 ); - lambdaM1 = extract_h( L_sub( 0x7FFFFFFF, tmp32 ) ); + lambda = extract_h( tmp32 ); /* Q15 */ + lambdaM1 = extract_h( L_sub( 0x7FFFFFFF /* 1.0f in Q31*/, tmp32 ) ); } invFac = getNormReciprocalWord16( 1 ); @@ -739,7 +743,7 @@ AdjustFirstSID_fx( FOR( i = 0; i < npart; i++ ) { - msNoiseEst_old[i] = Mpy_32_16_1( msNoiseEst_old[i], lambda ); + msNoiseEst_old[i] = Mpy_32_16_1( msNoiseEst_old[i], lambda ); /* exp(msNoiseEst_old) */ move32(); tmp32 = Mpy_32_16_1( Mpy_32_16_1( energy_ho[i], invFac ), lambdaM1 ); energy_ho[i] = L_add( L_shr( msNoiseEst_old[i], s1 ), L_shr( tmp32, s2 ) ); @@ -756,16 +760,16 @@ AdjustFirstSID_fx( move32(); FOR( i = 0; i < npart; i++ ) { - msNoiseEst_local = L_shr( msNoiseEst[i], s1 ); - energy_ho_local = L_shr( energy_ho[i], s2 ); + msNoiseEst_local = L_shr( msNoiseEst[i], s1 ); /* exp(msNoiseEst + s1) */ + energy_ho_local = L_shr( energy_ho[i], s2 ); /* exp(energy_ho_exp + s2) */ IF( GT_32( msNoiseEst_local, energy_ho_local ) ) { - msNoiseEst[i] = energy_ho_local; + msNoiseEst[i] = energy_ho_local; /* exp(energy_ho_exp + s2) */ move32(); } ELSE { - msNoiseEst[i] = msNoiseEst_local; + msNoiseEst[i] = msNoiseEst_local; /* exp(energy_ho_exp + s2) */ move32(); } if ( msNoiseEst[i] > 0 ) @@ -788,13 +792,13 @@ AdjustFirstSID_fx( IF( NE_32( stcod->core_brate, SID_2k40 ) && NE_32( stcod->core_brate, FRAME_NO_DATA ) ) { /* Count the number of active frames in a row */ - *active_frame_counter = add( *active_frame_counter, 1 ); + *active_frame_counter = add( *active_frame_counter, 1 ); /* Q0 */ move16(); } ELSE { /* Store the noise estimate obtained in the CNG phases */ - Copy32( msNoiseEst, msNoiseEst_old, npart ); + Copy32( msNoiseEst, msNoiseEst_old, npart ); /* exp(msNoiseEst_exp) */ *msNoiseEst_old_exp = *msNoiseEst_exp; move16(); } @@ -825,14 +829,14 @@ AdjustFirstSID_fx( Returns: void */ -static void msvq_encoder( const Word16 *const cb[], /* i : Codebook (indexed cb[*stages][levels][p]) scaled with 8 bits */ - Word16 u[], /* i : Vector to be encoded (prediction and mean removed) */ - const Word16 levels[], /* i : Number of levels in each stage */ - Word16 maxC, /* i : Tree search size */ - Word16 stages, /* i : Number of stages */ - Word16 N, /* i : Vector dimension */ - Word16 maxN, /* i : Codebook vector dimension */ - Word16 Idx[] /* o : Indices */ +static void msvq_encoder( const Word16 *const cb[], /* i : Codebook (indexed cb[*stages][levels][p]) scaled with 8 bits Q9.7*/ + Word16 u[], /* i : Vector to be encoded (prediction and mean removed) Q9.7*/ + const Word16 levels[], /* i : Number of levels in each stage Q0*/ + Word16 maxC, /* i : Tree search size Q0*/ + Word16 stages, /* i : Number of stages Q0*/ + Word16 N, /* i : Vector dimension Q0*/ + Word16 maxN, /* i : Codebook vector dimension Q0*/ + Word16 Idx[] /* o : Indices Q0*/ ) { Word32 *dist[2]; @@ -998,7 +1002,7 @@ static void msvq_encoder( const Word16 *const cb[], /* i : Codebook (indexed cb pTmp += N; /* Get indices that were used for parent node */ - Copy( indices[0] + parents[c] * stages, indices[1] + c * stages, s ); + Copy( indices[0] + parents[c] * stages, indices[1] + c * stages, s ); // Q0 } m = maxC; move16(); @@ -1728,10 +1732,10 @@ void generate_comfort_noise_enc_ivas_fx( Encoder_State *stcod, cngNoiseLevel = st->cngNoiseLevel; cngNoiseLevelExp = st->cngNoiseLevelExp; move16(); - ptr_level = cngNoiseLevel; + ptr_level = cngNoiseLevel; // cngNoiseLevelExp seed = &( st->seed ); - fftBuffer = st->fftBuffer; - timeDomainOutput = st->timeDomainBuffer; + fftBuffer = st->fftBuffer; // st->fftBuffer_exp + timeDomainOutput = st->timeDomainBuffer; // Q15 /* Generate Gaussian random noise in real and imaginary parts of the FFT bins @@ -1748,7 +1752,7 @@ void generate_comfort_noise_enc_ivas_fx( Encoder_State *stcod, randGaussExp = CNG_RAND_GAUSS_SHIFT; move16(); - cnt = sub( stenc->stopFFTbinDec, stenc->startBandDec ); + cnt = sub( stenc->stopFFTbinDec, stenc->startBandDec ); // Q)=0 IF( stenc->startBandDec == 0 ) { /* DC component in FFT */ @@ -1886,7 +1890,7 @@ void generate_comfort_noise_enc_ivas_fx( Encoder_State *stcod, seed_loc = st->seed; move16(); - N = st->frameSize; + N = st->frameSize; // Q0 move16(); N2 = shr( st->frameSize, 1 ); @@ -1942,7 +1946,7 @@ void generate_comfort_noise_enc_ivas_fx( Encoder_State *stcod, FOR( i = 0; i < N2; i++ ) { - timeDomainOutput[i] = add( timeDomainOutput[i], shl( hTcxEnc->Txnq[i], TCX_IMDCT_HEADROOM ) ); + timeDomainOutput[i] = add( timeDomainOutput[i], shl( hTcxEnc->Txnq[i], TCX_IMDCT_HEADROOM ) ); // Q15 move16(); } } @@ -1972,6 +1976,7 @@ void generate_comfort_noise_enc_ivas_fx( Encoder_State *stcod, preemph_fac = stcod->preemph_fac; move16(); Q_exc = Q_new; + move16(); Q_syn = sub( Q_new, 1 ); /* shift to be in the range of values supported by getNormReciprocalWord16() */ @@ -2093,12 +2098,12 @@ void generate_comfort_noise_enc_ivas_fx( Encoder_State *stcod, /*! r: CNG energy */ Word16 cng_energy_fx( - const Word16 element_mode, /* i : element mode */ - const Word16 bwidth, /* i : audio bandwidh */ - const Word16 CNG_mode, /* i : mode for DTX configuration */ - const Word16 CNG_att, /* i : attenuation factor for CNG */ - const Word16 *exc, /* i : input signal */ - const Word16 len, /* i : vector length */ + const Word16 element_mode, /* i : element mode Q0*/ + const Word16 bwidth, /* i : audio bandwidh Q0*/ + const Word16 CNG_mode, /* i : mode for DTX configuration Q0*/ + const Word16 CNG_att, /* i : attenuation factor for CNG Q7*/ + const Word16 *exc, /* i : input signal Q_new*/ + const Word16 len, /* i : vector length Q0*/ const Word16 Q_new /* i : Input scaling */ ) { @@ -2193,11 +2198,11 @@ Word16 cng_energy_fx( /*! r: CNG energy */ Word16 cng_energy_ivas_fx( - const Word16 element_mode, /* i : element mode */ - const Word16 bwidth, /* i : audio bandwidh */ - const Word16 CNG_mode, /* i : mode for DTX configuration */ - const Word16 CNG_att, /* i : attenuation factor for CNG Q7 */ - const Word16 *exc, /* i : input signal */ + const Word16 element_mode, /* i : element mode Q0*/ + const Word16 bwidth, /* i : audio bandwidh Q0*/ + const Word16 CNG_mode, /* i : mode for DTX configuration Q0*/ + const Word16 CNG_att, /* i : attenuation factor for CNG Q7*/ + const Word16 *exc, /* i : input signal Q_new*/ const Word16 len, /* i : vector length */ const Word16 Q_new /* i : Input scaling */ ) @@ -2264,11 +2269,13 @@ Word16 cng_energy_ivas_fx( { /* Bitrate adapted attenuation */ att = ENR_ATT_fx[CNG_mode]; + move16(); } ELSE { /* Use least attenuation for higher bitrates */ att = ENR_ATT_fx[4]; + move16(); } } ELSE diff --git a/lib_enc/find_tar.c b/lib_enc/find_tar.c deleted file mode 100644 index e7a8ca967132cf8896fc4a231dbaf74eed596840..0000000000000000000000000000000000000000 --- a/lib_enc/find_tar.c +++ /dev/null @@ -1,41 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2024 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 "cnst.h" -#include "prot.h" -#include "wmc_auto.h" diff --git a/lib_enc/find_tar_fx.c b/lib_enc/find_tar_fx.c index dc8477fc42db2aab8e4093e9f80a49bddde323a6..0c138308b5e25c0edc71f12620c0a543ac76d921 100644 --- a/lib_enc/find_tar_fx.c +++ b/lib_enc/find_tar_fx.c @@ -14,16 +14,16 @@ void find_targets_fx( const Word16 *speech, /* i : pointer to the speech frame Q_new-1*/ const Word16 *mem_syn, /* i : memory of the synthesis filter Q_new-1*/ - const Word16 i_subfr, /* i : subframe index */ + const Word16 i_subfr, /* i : subframe index Q0*/ Word16 *mem_w0, /* i/o: weighting filter denominator memory Q_new-1*/ const Word16 *p_Aq, /* i : interpolated quantized A(z) filter Q12*/ const Word16 *res, /* i : residual signal Q_new*/ - const Word16 L_subfr, /* i : length of vectors for gain quantization */ + const Word16 L_subfr, /* i : length of vectors for gain quantization Q0*/ const Word16 *Ap, /* i : unquantized A(z) filter with bandwidth expansion Q12*/ - Word16 tilt_fac, /* i : tilt factor Q15 */ + Word16 tilt_fac, /* i : tilt factor Q15*/ Word16 *xn, /* o : Close-loop Pitch search target vector Q_new-1*/ Word16 *cn, /* o : target vector in residual domain Q_new*/ - Word16 *h1 /* o : impulse response of weighted synthesis filter */ + Word16 *h1 /* o : impulse response of weighted synthesis filter Q14*/ ) { Word16 i; @@ -33,6 +33,7 @@ void find_targets_fx( Word32 Ltmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /*------------------------------------------------------------------------* * Find the target vector for excitation search: @@ -50,7 +51,7 @@ void find_targets_fx( FOR( i = 0; i < M; i++ ) { #ifdef BASOP_NOGLOB - temp[i] = sub_sat( speech[i + i_subfr - M], mem_syn[i] ); + temp[i] = sub_sat( speech[i + i_subfr - M], mem_syn[i] ); /* Q_new - 1 */ #else temp[i] = sub( speech[i + i_subfr - M], mem_syn[i] ); #endif @@ -77,7 +78,7 @@ void find_targets_fx( Scale_sig( cn, L_SUBFR / 2, 1 ); /* second half: res[] --> cn[] (approximated and faster) */ - Copy( &res[i_subfr + ( L_SUBFR / 2 )], cn + ( L_SUBFR / 2 ), L_SUBFR / 2 ); + Copy( &res[i_subfr + ( L_SUBFR / 2 )], cn + ( L_SUBFR / 2 ), L_SUBFR / 2 ); /* Q_new */ } /*---------------------------------------------------------------* @@ -89,13 +90,13 @@ void find_targets_fx( d = sub( scaleq, scale ); IF( d >= 0 ) { - Copy( p_Aq, Aqs, M + 1 ); + Copy( p_Aq, Aqs, M + 1 ); /* Q12 */ s = add( scaleq, 1 ); s2 = shr( 16384, d ); } ELSE { - Copy_Scale_sig( p_Aq, Aqs, M + 1, d ); + Copy_Scale_sig( p_Aq, Aqs, M + 1, d ); /* Q12 */ s = add( scale, 1 ); s2 = 16384; } @@ -103,32 +104,32 @@ void find_targets_fx( move16(); FOR( i = 0; i < M; i++ ) { - Ltmp = L_mult( Ap[i], s2 ); + Ltmp = L_mult( Ap[i], s2 ); /* Q27 */ FOR( j = 1; j <= i; j++ ) { -#ifdef BASOP_NOGLOB /* Critical Overflow , as well as those below*/ - Ltmp = L_msu_o( Ltmp, Aqs[j], h1[i - j], &Overflow ); +#ifdef BASOP_NOGLOB /* Critical Overflow , as well as those below*/ + Ltmp = L_msu_o( Ltmp, Aqs[j], h1[i - j], &Overflow ); /* Q27 */ #else Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); #endif } -#ifdef BASOP_NOGLOB /* Critical Overflow */ - h1[i] = round_fx_o( L_shl_o( Ltmp, s, &Overflow ), &Overflow ); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + h1[i] = round_fx_o( L_shl_o( Ltmp, s, &Overflow ), &Overflow ); /* Q11 + s */ #else h1[i] = round_fx( L_shl( Ltmp, s ) ); #endif } - Ltmp = L_mult( Ap[i], s2 ); + Ltmp = L_mult( Ap[i], s2 ); /* Q27 */ FOR( j = 1; j <= M; j++ ) { -#ifdef BASOP_NOGLOB /* Critical Overflow */ - Ltmp = L_msu_o( Ltmp, Aqs[j], h1[i - j], &Overflow ); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + Ltmp = L_msu_o( Ltmp, Aqs[j], h1[i - j], &Overflow ); /* Q27 */ #else Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); #endif } -#ifdef BASOP_NOGLOB /* Critical Overflow */ - h1[M] = round_fx_o( L_shl_o( Ltmp, s, &Overflow ), &Overflow ); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + h1[M] = round_fx_o( L_shl_o( Ltmp, s, &Overflow ), &Overflow ); /* Q11 + s */ #else h1[M] = round_fx( L_shl( Ltmp, s ) ); #endif @@ -136,17 +137,17 @@ void find_targets_fx( // PMT("should we used extended basop here for when the L_subfr > L_SUBFR, to prevent saturation/overflow and the subsequent loop\n") FOR( i = M + 1; i < L_subfr; i++ ) { - Ltmp = L_msu( 0, Aqs[1], h1[i - 1] ); + Ltmp = L_msu( 0, Aqs[1], h1[i - 1] ); /* Q27 */ FOR( j = 2; j <= M; j++ ) { -#ifdef BASOP_NOGLOB /* Critical Overflow */ - Ltmp = L_msu_o( Ltmp, Aqs[j], h1[i - j], &Overflow ); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + Ltmp = L_msu_o( Ltmp, Aqs[j], h1[i - j], &Overflow ); /* Q27 */ #else Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); #endif } -#ifdef BASOP_NOGLOB /* Critical Overflow */ - h1[i] = round_fx_o( L_shl_o( Ltmp, s, &Overflow ), &Overflow ); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + h1[i] = round_fx_o( L_shl_o( Ltmp, s, &Overflow ), &Overflow ); /* Q11 + s */ #else h1[i] = round_fx( L_shl( Ltmp, s ) ); #endif @@ -156,31 +157,31 @@ void find_targets_fx( s2 = shr( s2, 1 ); FOR( i = 0; i < M; i++ ) { - Ltmp = L_mult( Ap[i], s2 ); + Ltmp = L_mult( Ap[i], s2 ); /* Q27 */ FOR( j = 1; j <= i; j++ ) { - Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); + Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); /* Q27 */ } #ifdef BASOP_NOGLOB - h1[i] = round_fx( L_shl_o( Ltmp, s, &Overflow ) ); + h1[i] = round_fx( L_shl_o( Ltmp, s, &Overflow ) ); /* Q11 + s */ #else h1[i] = round_fx( L_shl( Ltmp, s ) ); #endif } - Ltmp = L_mult( Ap[i], s2 ); + Ltmp = L_mult( Ap[i], s2 ); /* Q27 */ FOR( j = 1; j <= M; j++ ) { - Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); + Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); /* Q27 */ } - h1[M] = round_fx( L_shl( Ltmp, s ) ); + h1[M] = round_fx( L_shl( Ltmp, s ) ); /* Q11 + s */ FOR( i = M + 1; i < L_subfr; i++ ) { - Ltmp = L_msu( 0, Aqs[1], h1[i - 1] ); + Ltmp = L_msu( 0, Aqs[1], h1[i - 1] ); /* Q27 */ FOR( j = 2; j <= M; j++ ) { - Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); + Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); /* Q27 */ } - h1[i] = round_fx( L_shl( Ltmp, s ) ); + h1[i] = round_fx( L_shl( Ltmp, s ) ); /* Q11 + s */ } } @@ -193,16 +194,16 @@ void find_targets_fx( void find_targets_ivas_fx( const Word16 *speech, /* i : pointer to the speech frame Q_new-1*/ const Word16 *mem_syn, /* i : memory of the synthesis filter Q_new-1*/ - const Word16 i_subfr, /* i : subframe index */ + const Word16 i_subfr, /* i : subframe index Q0*/ Word16 *mem_w0, /* i/o: weighting filter denominator memory Q_new-1*/ const Word16 *p_Aq, /* i : interpolated quantized A(z) filter Q12*/ const Word16 *res, /* i : residual signal Q_new*/ - const Word16 L_subfr, /* i : length of vectors for gain quantization */ + const Word16 L_subfr, /* i : length of vectors for gain quantization Q0*/ const Word16 *Ap, /* i : unquantized A(z) filter with bandwidth expansion Q12*/ - Word16 tilt_fac, /* i : tilt factor Q15 */ + Word16 tilt_fac, /* i : tilt factor Q15*/ Word16 *xn, /* o : Close-loop Pitch search target vector Q_new-1*/ Word16 *cn, /* o : target vector in residual domain Q_new*/ - Word16 *h1 /* o : impulse response of weighted synthesis filter */ + Word16 *h1 /* o : impulse response of weighted synthesis filter Q14*/ ) { Word16 i; @@ -229,7 +230,7 @@ void find_targets_ivas_fx( FOR( i = 0; i < M; i++ ) { #ifdef BASOP_NOGLOB - temp[i] = sub_sat( speech[i + i_subfr - M], mem_syn[i] ); + temp[i] = sub_sat( speech[i + i_subfr - M], mem_syn[i] ); /* Q_new - 1 */ #else temp[i] = sub( speech[i + i_subfr - M], mem_syn[i] ); #endif @@ -253,10 +254,10 @@ void find_targets_ivas_fx( preemph_copy_fx( xn, cn, tilt_fac, shr( L_subfr, 1 ), temp ); syn_filt_s_lc_fx( 1, Ap, cn, temp, shr( L_subfr, 1 ) ); /* Q-1 -> Q-2 */ Residu3_lc_fx( p_Aq, M, temp, cn, shr( L_subfr, 1 ), 1 ); /* Q-2 -> Q-1 */ - Scale_sig( cn, shr( L_subfr, 1 ), 1 ); + Scale_sig( cn, shr( L_subfr, 1 ), 1 ); /* Q_new */ /* second half: res[] --> cn[] (approximated and faster) */ - Copy( &res[i_subfr + shr( L_subfr, 1 )], cn + shr( L_subfr, 1 ), shr( L_subfr, 1 ) ); + Copy( &res[i_subfr + shr( L_subfr, 1 )], cn + shr( L_subfr, 1 ), shr( L_subfr, 1 ) ); /* Q_new */ } /*---------------------------------------------------------------* @@ -268,13 +269,13 @@ void find_targets_ivas_fx( d = sub( scaleq, scale ); IF( d >= 0 ) { - Copy( p_Aq, Aqs, M + 1 ); + Copy( p_Aq, Aqs, M + 1 ); /* Q12 */ s = add( scaleq, 1 ); s2 = shr( 16384, d ); } ELSE { - Copy_Scale_sig( p_Aq, Aqs, M + 1, d ); + Copy_Scale_sig( p_Aq, Aqs, M + 1, d ); /* Q12 */ s = add( scale, 1 ); s2 = 16384; } @@ -283,32 +284,32 @@ void find_targets_ivas_fx( move16(); FOR( i = 0; i < M; i++ ) { - Ltmp = L_mult( Ap[i], s2 ); + Ltmp = L_mult( Ap[i], s2 ); /* Q27 */ FOR( j = 1; j <= i; j++ ) { -#ifdef BASOP_NOGLOB /* Critical Overflow , as well as those below*/ - Ltmp = L_msu_o( Ltmp, Aqs[j], h1[i - j], &Overflow ); +#ifdef BASOP_NOGLOB /* Critical Overflow , as well as those below*/ + Ltmp = L_msu_o( Ltmp, Aqs[j], h1[i - j], &Overflow ); /* Q27 */ #else Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); #endif } -#ifdef BASOP_NOGLOB /* Critical Overflow */ - h1[i] = round_fx_o( L_shl_o( Ltmp, s, &Overflow ), &Overflow ); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + h1[i] = round_fx_o( L_shl_o( Ltmp, s, &Overflow ), &Overflow ); /* Q11 + s */ #else h1[i] = round_fx( L_shl( Ltmp, s ) ); #endif } - Ltmp = L_mult( Ap[i], s2 ); + Ltmp = L_mult( Ap[i], s2 ); /* Q27 */ FOR( j = 1; j <= M; j++ ) { -#ifdef BASOP_NOGLOB /* Critical Overflow */ - Ltmp = L_msu_o( Ltmp, Aqs[j], h1[i - j], &Overflow ); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + Ltmp = L_msu_o( Ltmp, Aqs[j], h1[i - j], &Overflow ); /* Q27 */ #else Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); #endif } -#ifdef BASOP_NOGLOB /* Critical Overflow */ - h1[M] = round_fx_o( L_shl_o( Ltmp, s, &Overflow ), &Overflow ); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + h1[M] = round_fx_o( L_shl_o( Ltmp, s, &Overflow ), &Overflow ); /* Q11 + s */ #else h1[M] = round_fx( L_shl( Ltmp, s ) ); #endif @@ -316,17 +317,17 @@ void find_targets_ivas_fx( // PMT("should we used extended basop here for when the L_subfr > L_SUBFR, to prevent saturation/overflow and the subsequent loop\n") FOR( i = M + 1; i < L_subfr; i++ ) { - Ltmp = L_msu( 0, Aqs[1], h1[i - 1] ); + Ltmp = L_msu( 0, Aqs[1], h1[i - 1] ); /* Q27 */ FOR( j = 2; j <= M; j++ ) { -#ifdef BASOP_NOGLOB /* Critical Overflow */ - Ltmp = L_msu_o( Ltmp, Aqs[j], h1[i - j], &Overflow ); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + Ltmp = L_msu_o( Ltmp, Aqs[j], h1[i - j], &Overflow ); /* Q27 */ #else Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); #endif } -#ifdef BASOP_NOGLOB /* Critical Overflow */ - h1[i] = round_fx_o( L_shl_o( Ltmp, s, &Overflow ), &Overflow ); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + h1[i] = round_fx_o( L_shl_o( Ltmp, s, &Overflow ), &Overflow ); /* Q11 + s */ #else h1[i] = round_fx( L_shl( Ltmp, s ) ); #endif @@ -336,31 +337,31 @@ void find_targets_ivas_fx( s2 = shr( s2, 1 ); FOR( i = 0; i < M; i++ ) { - Ltmp = L_mult( Ap[i], s2 ); + Ltmp = L_mult( Ap[i], s2 ); /* Q27 */ FOR( j = 1; j <= i; j++ ) { - Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); + Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); /* Q27 */ } #ifdef BASOP_NOGLOB - h1[i] = round_fx( L_shl_o( Ltmp, s, &Overflow ) ); + h1[i] = round_fx( L_shl_o( Ltmp, s, &Overflow ) ); /* Q11 + s */ #else h1[i] = round_fx( L_shl( Ltmp, s ) ); #endif } - Ltmp = L_mult( Ap[i], s2 ); + Ltmp = L_mult( Ap[i], s2 ); /* Q27 */ FOR( j = 1; j <= M; j++ ) { - Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); + Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); /* Q27 */ } - h1[M] = round_fx( L_shl( Ltmp, s ) ); + h1[M] = round_fx( L_shl( Ltmp, s ) ); /* Q11 + s */ FOR( i = M + 1; i < L_subfr; i++ ) { - Ltmp = L_msu( 0, Aqs[1], h1[i - 1] ); + Ltmp = L_msu( 0, Aqs[1], h1[i - 1] ); /* Q27 */ FOR( j = 2; j <= M; j++ ) { - Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); + Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); /* Q27 */ } - h1[i] = round_fx( L_shl( Ltmp, s ) ); + h1[i] = round_fx( L_shl( Ltmp, s ) ); /* Q11 + s */ } } diff --git a/lib_enc/find_tilt.c b/lib_enc/find_tilt.c index c5e16ed22962d9f18f21f00a79ac9c7b52fa7278..59a7412fd5b4392ad354db5e6b1581ecd0579597 100644 --- a/lib_enc/find_tilt.c +++ b/lib_enc/find_tilt.c @@ -56,21 +56,22 @@ * Find LF/HF energy ratio *-------------------------------------------------------------------*/ void find_tilt_ivas_fx( - const Word32 fr_bands[], /* i : energy in frequency bands Q_new*/ - const Word32 bckr[], /* i : per band background noise energy estimate Q_new*/ - Word32 ee[2], /* o : lf/hf E ration for present frame Q6*/ - const Word16 pitch[3], /* i : open loop pitch values for 3 half-frames Q0*/ - const Word16 voicing[3], /* i : normalized correlation for 3 half-frames Q15*/ - const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new - 2*/ - const Word16 corr_shift, /* i : normalized correlation correction Q15*/ - const Word16 bwidth, /* i : input signal bandwidth */ - const Word16 max_band, /* i : maximum critical band */ - Word32 hp_E[], /* o : energy in HF Q_new*/ - const Word16 codec_mode, /* i : MODE1 or MODE2 */ - const Word16 Q_new, /* i : scaling factor */ - Word32 *bckr_tilt_lt /* i/o: lf/hf E ratio of background noise Q16 */ + const Word32 fr_bands[], /* i : energy in frequency bands Q_new*/ + const Word32 bckr[], /* i : per band background noise energy estimate Q_new*/ + Word32 ee[2], /* o : lf/hf E ration for present frame Q6*/ + const Word16 pitch[3], /* i : open loop pitch values for 3 half-frames Q0*/ + const Word16 voicing[3], /* i : normalized correlation for 3 half-frames Q15*/ + const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new - 2*/ + const Word16 corr_shift, /* i : normalized correlation correction Q15*/ + const Word16 bwidth, /* i : input signal bandwidth Q0*/ + const Word16 max_band, /* i : maximum critical band Q0*/ + Word32 hp_E[], /* o : energy in HF Q_new*/ + const Word16 codec_mode, /* i : MODE1 or MODE2 Q0*/ + const Word16 Q_new, /* i : scaling factor */ + Word32 *bckr_tilt_lt /* i/o: lf/hf E ratio of background noise Q16*/ , - Word16 Opt_vbr_mode ) + Word16 Opt_vbr_mode /* Q0 */ +) { Word32 lp_bckr = 0, hp_bckr = 0, lp_E, Ltmp; const Word32 *pt_E, *pt_bands, *pt_bckr, *hf_bands, *tmp_E; @@ -94,10 +95,10 @@ void find_tilt_ivas_fx( { /* WB processing */ bin = BIN4_FX; - move16(); /* First useful frequency bin ~ 50 Hz */ - pt_bands = fr_bands; - tmp_E = lf_E; - pt_bckr = bckr; + move16(); /* First useful frequency bin ~ 50 Hz */ + pt_bands = fr_bands; /* Q_new */ + tmp_E = lf_E; /* Q_new - 2 */ + pt_bckr = bckr; /* Q_new */ nb_bands = 10; move16(); } @@ -124,7 +125,7 @@ void find_tilt_ivas_fx( lp_bckr = Mean32( pt_bckr, nb_bands ); /*hp_bckr = 0.5f * (bckr[max_band-1] + bckr[max_band]);*/ /* estimated noise E in last 2 critical bands */ #ifdef BASOP_NOGLOB - hp_bckr = L_shr( L_add_sat( bckr[max_band - 1], bckr[max_band] ), 1 ); + hp_bckr = L_shr( L_add_sat( bckr[max_band - 1], bckr[max_band] ), 1 ); /* Q_new - 1 */ #else hp_bckr = L_shr( L_add( bckr[max_band - 1], bckr[max_band] ), 1 ); #endif @@ -132,31 +133,31 @@ void find_tilt_ivas_fx( { hp_bckr = L_deposit_l( 1 ); } - Ltmp = BASOP_Util_Divide3232_Scale_cadence( lp_bckr, hp_bckr, &e_tmp ); - Ltmp = Mpy_32_16_r( Ltmp, 3277 ); + Ltmp = BASOP_Util_Divide3232_Scale_cadence( lp_bckr, hp_bckr, &e_tmp ); /* exp(e_tmp) */ + Ltmp = Mpy_32_16_r( Ltmp, 3277 /* 0.1 in Q15 */ ); Ltmp = L_shr_sat( Ltmp, sub( 15, e_tmp ) ); - *bckr_tilt_lt = L_add_sat( Mpy_32_16_r( *bckr_tilt_lt, 29491 ), Ltmp ); + *bckr_tilt_lt = L_add_sat( Mpy_32_16_r( *bckr_tilt_lt, 29491 ), Ltmp ); /* Q16 */ move32(); test(); - IF( EQ_16( codec_mode, MODE2 ) || Opt_vbr_mode == 1 ) + IF( EQ_16( codec_mode, MODE2 ) || EQ_16( Opt_vbr_mode, 1 ) ) { /*lp_bckr *= FACT;*/ /*hp_bckr *= FACT;*/ #ifdef BASOP_NOGLOB - lp_bckr = L_add_sat( L_shl_sat( lp_bckr, 1 ), lp_bckr ); - hp_bckr = L_add_sat( L_shl_sat( hp_bckr, 1 ), hp_bckr ); + lp_bckr = L_add_sat( L_shl_sat( lp_bckr, 1 ), lp_bckr ); /* Q_new */ + hp_bckr = L_add_sat( L_shl_sat( hp_bckr, 1 ), hp_bckr ); /* Q_new */ #else lp_bckr = L_add( L_shl( lp_bckr, 1 ), lp_bckr ); hp_bckr = L_add( L_shl( hp_bckr, 1 ), hp_bckr ); #endif } /*mean_voi = 0.5f * (voicing[1] + voicing[2]) + corr_shift;*/ - Ltmp = L_mult( voicing[1], 16384 ); - Ltmp = L_mac( Ltmp, voicing[2], 16384 ); + Ltmp = L_mult( voicing[1], 16384 /* 0.5 in Q15 */ ); // Q31 + Ltmp = L_mac( Ltmp, voicing[2], 16384 /* 0.5 in Q15 */ ); // Q31 #ifdef BASOP_NOGLOB - Ltmp = L_mac_o( Ltmp, corr_shift, 32767, &Overflow ); - mean_voi = round_fx_o( Ltmp, &Overflow ); + Ltmp = L_mac_o( Ltmp, corr_shift, 32767 /* 1.0f in Q15 */, &Overflow ); // Q31 + mean_voi = round_fx_o( Ltmp, &Overflow ); // Q15 #else Ltmp = L_mac( Ltmp, corr_shift, 32767 ); mean_voi = round_fx( Ltmp ); @@ -166,15 +167,15 @@ void find_tilt_ivas_fx( e_tmp = norm_s( pitch[2] ); m_tmp = shl( pitch[2], e_tmp ); - m_Fs = div_s( INT_FS_FX, m_tmp ); + m_Fs = div_s( INT_FS_FX, m_tmp ); /* exp(e_tmp) */ e_Fs = sub( 15, e_tmp ); f0 = shr( m_Fs, sub( e_Fs, 4 ) ); /* Q4 */ FOR( i = 0; i < 2; i++ ) { - /*hp_E[i] = 0.5f * (hf_bands[max_band-1] + hf_bands[max_band]) - hp_bckr; */ /* averaged E in last 2 critical bands */ - Ltmp = L_add( L_shr( hf_bands[max_band - 1], 1 ), L_shr( hf_bands[max_band], 1 ) ); - hp_E[i] = L_sub( Ltmp, hp_bckr ); + /*hp_E[i] = 0.5f * (hf_bands[max_band-1] + hf_bands[max_band]) - hp_bckr; */ /* averaged E in last 2 critical bands */ + Ltmp = L_add( L_shr( hf_bands[max_band - 1], 1 ), L_shr( hf_bands[max_band], 1 ) ); /* Q_new */ + hp_E[i] = L_sub( Ltmp, hp_bckr ); /* Q_new */ move32(); IF( Opt_vbr_mode == 0 ) { @@ -202,16 +203,16 @@ void find_tilt_ivas_fx( f1 = add( shr( f0, 1 ), f0 ); /* Middle between 2 harmonics */ f2 = f0; move16(); - WHILE( LE_16( freq, 20320 ) ) /* End frequency of 10th critical band */ + WHILE( LE_16( freq, 20320 /* 1270.0f in Q4 */ ) ) /* End frequency of 10th critical band */ { FOR( ; freq <= f1; freq += BIN4_FX ) { /* include only bins sufficiently close to harmonics */ - tmp = sub( freq, f2 ); + tmp = sub( freq, f2 ); /* Q4 */ IF( L_mac0( -(Word32) TH_D_FX * TH_D_FX, tmp, tmp ) < 0 ) { #ifdef BASOP_NOGLOB - lp_E = L_add_o( *pt_E, lp_E, &Overflow ); + lp_E = L_add_o( *pt_E, lp_E, &Overflow ); /* Q_new - 1 */ #else lp_E = L_add( *pt_E, lp_E ); #endif @@ -245,7 +246,7 @@ void find_tilt_ivas_fx( lp_E = L_sub( L_shr( m_tmp, sub( e_tmp, 1 ) ), lp_bckr ); #endif - pt_E = tmp_E + VOIC_BINS; /* Update for next half-frame */ + pt_E = tmp_E + VOIC_BINS; /* Update for next half-frame Q_new - 1 */ } ELSE /* Other than high-pitched voiced frames */ { @@ -271,7 +272,7 @@ void find_tilt_ivas_fx( m_tmp = extract_h( L_shl( lp_E, e_tmp ) ); e_hpE = norm_l( hp_E[i] ); m_hpE = extract_h( L_shl( hp_E[i], e_hpE ) ); - m_tmp = div_s( m_tmp, m_hpE ); + m_tmp = div_s( m_tmp, m_hpE ); /* e_tmp + e_hpE */ e_tmp = sub( e_tmp, e_hpE ); #ifdef BASOP_NOGLOB @@ -295,15 +296,15 @@ void find_tilt_ivas_fx( IF( EQ_16( bwidth, NB ) ) /* For NB input, compensate for the missing bands */ { #ifdef BASOP_NOGLOB - Ltmp = L_shl_o( ee[i], 3, &Overflow ); + Ltmp = L_shl_o( ee[i], 3, &Overflow ); /* Q6 */ #else Ltmp = L_shl( ee[i], 3 ); #endif IF( EQ_32( Ltmp, MAX_32 ) ) /* if Overflow: Compute with less precision */ { - Ltmp = Mult_32_16( ee[i], 24576 ); /* 6/8 */ + Ltmp = Mult_32_16( ee[i], 24576 /* 0.75 in Q15 */ ); /* 6/8 Q6*/ #ifdef BASOP_NOGLOB - ee[i] = L_shl_sat( Ltmp, 3 ); + ee[i] = L_shl_sat( Ltmp, 3 ); /* Q6 */ #else ee[i] = L_shl( Ltmp, 3 ); #endif @@ -311,7 +312,7 @@ void find_tilt_ivas_fx( } ELSE { - ee[i] = Mult_32_16( Ltmp, 24576 ); + ee[i] = Mult_32_16( Ltmp, 24576 /* 0.75 in Q15 */ ); move32(); /* 6/8 */ } } diff --git a/lib_enc/find_tilt_fx.c b/lib_enc/find_tilt_fx.c index f0c39eee21dafe9fe30de6bee54dbdd2d4a6854c..f29a9709cf2916b81760cdcb34bb47745ae9d20b 100644 --- a/lib_enc/find_tilt_fx.c +++ b/lib_enc/find_tilt_fx.c @@ -23,14 +23,15 @@ void find_tilt_fx( const Word16 voicing[3], /* i : normalized correlation for 3 half-frames Q15*/ const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new + Q_SCALE - 2*/ const Word16 corr_shift, /* i : normalized correlation correction Q15*/ - const Word16 bwidth, /* i : input signal bandwidth */ - const Word16 max_band, /* i : maximum critical band */ + const Word16 bwidth, /* i : input signal bandwidth Q0*/ + const Word16 max_band, /* i : maximum critical band Q0*/ Word32 hp_E[], /* o : energy in HF Q_new + Q_SCALE*/ - const Word16 codec_mode, /* i : MODE1 or MODE2 */ + const Word16 codec_mode, /* i : MODE1 or MODE2 Q0*/ const Word16 Q_new, /* i : scaling factor */ - Word32 *bckr_tilt_lt /* i/o: lf/hf E ratio of background noise Q16 */ + Word32 *bckr_tilt_lt /* i/o: lf/hf E ratio of background noise Q16*/ , - Word16 Opt_vbr_mode ) + Word16 Opt_vbr_mode /* Q0 */ +) { Word32 lp_bckr = 0, hp_bckr = 0, lp_E, Ltmp; const Word32 *pt_E, *pt_bands, *pt_bckr, *hf_bands, *tmp_E; @@ -41,8 +42,11 @@ void find_tilt_fx( Word16 m_cnt, e_cnt; Word16 m_hpE, e_hpE; Word16 scaling; + move32(); + move32(); #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /*-----------------------------------------------------------------* * Initializations @@ -53,10 +57,10 @@ void find_tilt_fx( { /* WB processing */ bin = BIN4_FX; - move16(); /* First useful frequency bin ~ 50 Hz */ - pt_bands = fr_bands; - tmp_E = lf_E; - pt_bckr = bckr; + move16(); /* First useful frequency bin ~ 50 Hz */ + pt_bands = fr_bands; /* Q_new + QSCALE */ + tmp_E = lf_E; /* Q_new + QSCALE - 2 */ + pt_bckr = bckr; /* Q_new + QSCALE */ nb_bands = 10; move16(); } @@ -64,9 +68,9 @@ void find_tilt_fx( { /* NB processing */ bin = add( shl( BIN4_FX, 1 ), BIN4_FX ); /* First useful frequency bin ~ 150 Hz */ - pt_bands = fr_bands + 1; /* Exlcude 1st critical band */ - tmp_E = lf_E + 2; /* Start at the 3rd bin (150 Hz) */ - pt_bckr = bckr + 1; /* Exlcude 1st critical band */ + pt_bands = fr_bands + 1; /* Exlcude 1st critical band Q_new + QSCALE*/ + tmp_E = lf_E + 2; /* Start at the 3rd bin (150 Hz) Q_new + QSCALE - 2*/ + pt_bckr = bckr + 1; /* Exlcude 1st critical band Q_new + QSCALE*/ nb_bands = 9; move16(); /* Nb. of "low" frequency bands taken into account in NB processing */ } @@ -75,15 +79,15 @@ void find_tilt_fx( * Find spectrum tilt *-----------------------------------------------------------------*/ - pt_E = tmp_E; /* Point at the 1st useful element of the per-bin energy vector */ - hf_bands = fr_bands; + pt_E = tmp_E; /* Point at the 1st useful element of the per-bin energy vector */ + hf_bands = fr_bands; /* Q_new + QSCALE */ /* bckr + voicing */ /*lp_bckr = mean( pt_bckr, nb_bands );*/ /* estimated noise E in first critical bands, up to 1270 Hz */ lp_bckr = Mean32( pt_bckr, nb_bands ); /*hp_bckr = 0.5f * (bckr[max_band-1] + bckr[max_band]);*/ /* estimated noise E in last 2 critical bands */ #ifdef BASOP_NOGLOB - hp_bckr = L_shr( L_add_sat( bckr[max_band - 1], bckr[max_band] ), 1 ); + hp_bckr = L_shr( L_add_sat( bckr[max_band - 1], bckr[max_band] ), 1 ); /* Q_new + QSCALE - 1 */ #else hp_bckr = L_shr( L_add( bckr[max_band - 1], bckr[max_band] ), 1 ); #endif @@ -93,7 +97,7 @@ void find_tilt_fx( } tmp = BASOP_Util_Divide3232_Scale( lp_bckr, hp_bckr, &e_tmp ); Ltmp = L_shr_r( L_deposit_h( tmp ), sub( 15, e_tmp ) ); - *bckr_tilt_lt = L_add( Mpy_32_16_r( *bckr_tilt_lt, 29491 ), Mpy_32_16_r( Ltmp, 3277 ) ); + *bckr_tilt_lt = L_add( Mpy_32_16_r( *bckr_tilt_lt, 29491 ), Mpy_32_16_r( Ltmp, 3277 ) ); /* Q16 */ test(); IF( EQ_16( codec_mode, MODE2 ) || Opt_vbr_mode == 1 ) @@ -101,7 +105,7 @@ void find_tilt_fx( /*lp_bckr *= FACT;*/ /*hp_bckr *= FACT;*/ #ifdef BASOP_NOGLOB - lp_bckr = L_add_sat( L_shl_sat( lp_bckr, 1 ), lp_bckr ); + lp_bckr = L_add_sat( L_shl_sat( lp_bckr, 1 ), lp_bckr ); /* Q_new + QSCALE */ hp_bckr = L_add_sat( L_shl_sat( hp_bckr, 1 ), hp_bckr ); #else lp_bckr = L_add( L_shl( lp_bckr, 1 ), lp_bckr ); @@ -109,11 +113,11 @@ void find_tilt_fx( #endif } /*mean_voi = 0.5f * (voicing[1] + voicing[2]) + corr_shift;*/ - Ltmp = L_mult( voicing[1], 16384 ); - Ltmp = L_mac( Ltmp, voicing[2], 16384 ); + Ltmp = L_mult( voicing[1], 16384 /* 0.5 in Q15 */ ); /* Q31 */ + Ltmp = L_mac( Ltmp, voicing[2], 16384 /* 0.5 in Q15 */ ); /* Q31 */ #ifdef BASOP_NOGLOB - Ltmp = L_mac_o( Ltmp, corr_shift, 32767, &Overflow ); - mean_voi = round_fx_o( Ltmp, &Overflow ); + Ltmp = L_mac_o( Ltmp, corr_shift, 32767, &Overflow ); /* Q31 */ + mean_voi = round_fx_o( Ltmp, &Overflow ); /* Q15 */ #else Ltmp = L_mac( Ltmp, corr_shift, 32767 ); mean_voi = round_fx( Ltmp ); @@ -123,23 +127,23 @@ void find_tilt_fx( e_tmp = norm_s( pitch[2] ); m_tmp = shl( pitch[2], e_tmp ); - m_Fs = div_s( INT_FS_FX, m_tmp ); + m_Fs = div_s( INT_FS_FX, m_tmp ); /* exp(e_tmp) */ e_Fs = sub( 15, e_tmp ); f0 = shr( m_Fs, sub( e_Fs, 4 ) ); /* Q4 */ FOR( i = 0; i < 2; i++ ) { - /*hp_E[i] = 0.5f * (hf_bands[max_band-1] + hf_bands[max_band]) - hp_bckr; */ /* averaged E in last 2 critical bands */ - Ltmp = L_add( L_shr( hf_bands[max_band - 1], 1 ), L_shr( hf_bands[max_band], 1 ) ); - hp_E[i] = L_sub( Ltmp, hp_bckr ); + /*hp_E[i] = 0.5f * (hf_bands[max_band-1] + hf_bands[max_band]) - hp_bckr; */ /* averaged E in last 2 critical bands */ + Ltmp = L_add( L_shr( hf_bands[max_band - 1], 1 ), L_shr( hf_bands[max_band], 1 ) ); /* Q_new + QSCALE */ + hp_E[i] = L_sub( Ltmp, hp_bckr ); /* Q_new + QSCALE */ IF( Opt_vbr_mode == 0 ) { - hp_E[i] = L_max( hp_E[i], L_shl( E_MIN_FX, Q_new ) ); + hp_E[i] = L_max( hp_E[i], L_shl( E_MIN_FX, Q_new ) ); /* Q_new + QSCALE */ move32(); } ELSE { - hp_E[i] = L_max( hp_E[i], L_shl( 1, scaling ) ); + hp_E[i] = L_max( hp_E[i], L_shl( 1, scaling ) ); /* Q_new + QSCALE */ move32(); } @@ -164,11 +168,11 @@ void find_tilt_fx( IF( L_mac0( -(Word32) TH_D_FX * TH_D_FX, tmp, tmp ) < 0 ) { #ifdef BASOP_NOGLOB - lp_E = L_add_o( *pt_E, lp_E, &Overflow ); + lp_E = L_add_o( *pt_E, lp_E, &Overflow ); /* Q_new + QSCALE - 2 */ #else lp_E = L_add( *pt_E, lp_E ); #endif - m_cnt = add( m_cnt, 1 ); + m_cnt = add( m_cnt, 1 ); /* Q0 */ } pt_E++; } @@ -189,11 +193,11 @@ void find_tilt_fx( e_cnt = norm_s( m_cnt ); m_cnt = shl( m_cnt, e_cnt ); - m_tmp = div_s( m_tmp, m_cnt ); + m_tmp = div_s( m_tmp, m_cnt ); /* exp(e_tmp + e_cnt) */ e_tmp = sub( e_tmp, e_cnt ); #ifdef BASOP_NOGLOB - lp_E = L_sub_o( L_shr_o( m_tmp, sub( e_tmp, 1 ), &Overflow ), lp_bckr, &Overflow ); + lp_E = L_sub_o( L_shr_o( m_tmp, sub( e_tmp, 1 ), &Overflow ), lp_bckr, &Overflow ); /* Q_new + QSCALE */ #else lp_E = L_sub( L_shr( m_tmp, sub( e_tmp, 1 ) ), lp_bckr ); #endif @@ -202,8 +206,8 @@ void find_tilt_fx( } ELSE /* Other than high-pitched voiced frames */ { - /*lp_E = mean( pt_bands, nb_bands ) - lp_bckr;*/ /* averaged E in first critical bands, up to 1270 Hz */ - lp_E = L_sub( Mean32( pt_bands, nb_bands ), lp_bckr ); + /*lp_E = mean( pt_bands, nb_bands ) - lp_bckr;*/ /* averaged E in first critical bands, up to 1270 Hz */ + lp_E = L_sub( Mean32( pt_bands, nb_bands ), lp_bckr ); /* Q_new + QSCALE */ } IF( Opt_vbr_mode == 0 ) { @@ -221,7 +225,7 @@ void find_tilt_fx( m_tmp = extract_h( L_shl( lp_E, e_tmp ) ); e_hpE = norm_l( hp_E[i] ); m_hpE = extract_h( L_shl( hp_E[i], e_hpE ) ); - m_tmp = div_s( m_tmp, m_hpE ); + m_tmp = div_s( m_tmp, m_hpE ); /* exp(e_tmp + e_hpE) */ e_tmp = sub( e_tmp, e_hpE ); #ifdef BASOP_NOGLOB @@ -248,7 +252,7 @@ void find_tilt_fx( #endif IF( EQ_32( Ltmp, MAX_32 ) ) /* if Overflow: Compute with less precision */ { - Ltmp = Mult_32_16( ee[i], 24576 ); /* 6/8 */ + Ltmp = Mult_32_16( ee[i], 24576 /* 0.75 in Q15 */ ); /* 6/8 Q6*/ #ifdef BASOP_NOGLOB ee[i] = L_shl_sat( Ltmp, 3 ); #else @@ -258,8 +262,8 @@ void find_tilt_fx( } ELSE { - ee[i] = Mult_32_16( Ltmp, 24576 ); - move32(); /* 6/8 */ + ee[i] = Mult_32_16( Ltmp, 24576 /* 0.75 in Q15 */ ); /* Q6 */ + move32(); /* 6/8 */ } } diff --git a/lib_enc/igf_enc.c b/lib_enc/igf_enc.c index b7a218b63cc550a0cdf17c4fa9fdccd8318a5f02..72b8e9920390824ae6622913f33ed353224ad7aa 100644 --- a/lib_enc/igf_enc.c +++ b/lib_enc/igf_enc.c @@ -477,14 +477,16 @@ static void IGF_CalculateEnvelope_ivas_fx( move16(); FOR( sb = swb_offset[sfb]; sb < swb_offset[sfb + 1]; sb++ ) { - sfbEnergyC = BASOP_Util_Add_Mant32Exp( sfbEnergyC, sfbEnergyC_e, pPowerSpectrum_fx[sb], e_ps, &sfbEnergyC_e ); + Word16 shift = norm_l( pPowerSpectrum_fx[sb] ); + sfbEnergyC = BASOP_Util_Add_Mant32Exp( sfbEnergyC, sfbEnergyC_e, L_shl( pPowerSpectrum_fx[sb], shift ), sub( e_ps, shift ), &sfbEnergyC_e ); // sfbEnergyTileR = BASOP_Util_Add_Mant32Exp( sfbEnergyTileR, sfbEnergyTileR_e, Mult_32_32( pMDCTSpectrum_fx[strt_cpy], pMDCTSpectrum_fx[strt_cpy] ), shl( e_mdct, 1 ), &sfbEnergyTileR_e ); Word64 tmp64 = W_mult_32_32( pMDCTSpectrum_fx[strt_cpy], pMDCTSpectrum_fx[strt_cpy] ); Word16 tmp64_e = W_norm( tmp64 ); tmp64 = W_shl( tmp64, tmp64_e ); sfbEnergyTileR = BASOP_Util_Add_Mant32Exp( sfbEnergyTileR, sfbEnergyTileR_e, W_extract_h( tmp64 ), shl( e_mdct, 1 ) - tmp64_e, &sfbEnergyTileR_e ); - sfbEnergyTileC = BASOP_Util_Add_Mant32Exp( sfbEnergyTileC, sfbEnergyTileC_e, pPowerSpectrum_fx[strt_cpy], e_ps, &sfbEnergyTileC_e ); + shift = norm_l( pPowerSpectrum_fx[strt_cpy] ); + sfbEnergyTileC = BASOP_Util_Add_Mant32Exp( sfbEnergyTileC, sfbEnergyTileC_e, L_shl( pPowerSpectrum_fx[strt_cpy], shift ), sub( e_ps, shift ), &sfbEnergyTileC_e ); strt_cpy = add( strt_cpy, 1 ); } diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c index c6f62d9216ce2cc85f2a2596c7d3ec1737c483f0..8177681ec65612ccc0ce363cc77550566e255b25 100644 --- a/lib_enc/ivas_core_pre_proc.c +++ b/lib_enc/ivas_core_pre_proc.c @@ -637,6 +637,7 @@ ivas_error pre_proc_ivas( ELSE { *inp_fx = inp_16k_fx; + Scale_sig( old_inp_12k8_fx, L_INP_12k8, sub( *Q_new, Q_old_inp_128k ) ); } /* Update VAD hangover frame counter in active frames */ @@ -1163,7 +1164,7 @@ ivas_error ivas_compute_core_buffers_fx( ELSE IF( GT_32( input_Fs, 8000 ) ) { lerp( st->old_inp_12k8_fx + L_INP_MEM - L_INP_MEM * 4 / 5, st->old_inp_16k_fx, L_INP_MEM, L_INP_MEM * 4 / 5 ); - Scale_sig( st->old_inp_16k_fx, L_INP_MEM, sub( -1 /* Q st->old_inp_16k_fx = -1 */, sub( 15, st->exp_old_inp_16k ) ) ); + Scale_sig( st->old_inp_16k_fx, L_INP_MEM, sub( -1 /* Q st->old_inp_16k_fx = -1 */, sub( 15, st->exp_old_inp_12k8 ) ) ); st->exp_old_inp_16k = Q16; // Q-1 move16(); } diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 5b5dc19b72ca25de2cb360d579f5250c51292fb6..357d3120ce631230143eae8d002dbfb158bf27a0 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -226,36 +226,40 @@ Word16 ffr_getSfWord32( const Word16 len /*!< Length of i vector */ ); void find_tilt_ivas_fx( - const Word32 fr_bands[], /* i : energy in frequency bands Q_new*/ - const Word32 bckr[], /* i : per band background noise energy estimate Q_new*/ - Word32 ee[2], /* o : lf/hf E ration for present frame Q_bckr*/ - const Word16 pitch[3], /* i : open loop pitch values for 3 half-frames Q0*/ - const Word16 voicing[3], /* i : normalized correlation for 3 half-frames Q15*/ - const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new - 2*/ - const Word16 corr_shift, /* i : normalized correlation correction Q15*/ - const Word16 bwidth, /* i : i signal bandwidth */ - const Word16 max_band, /* i : maximum critical band */ - Word32 hp_E[], /* o : energy in HF Q_new*/ - const Word16 codec_mode, /* i : MODE1 or MODE2 */ - const Word16 Q_new, /* i : scaling factor */ - Word32 *bckr_tilt_lt, - Word16 Opt_vbr_mode ); + const Word32 fr_bands[], /* i : energy in frequency bands Q_new*/ + const Word32 bckr[], /* i : per band background noise energy estimate Q_new*/ + Word32 ee[2], /* o : lf/hf E ration for present frame Q_bckr*/ + const Word16 pitch[3], /* i : open loop pitch values for 3 half-frames Q0*/ + const Word16 voicing[3], /* i : normalized correlation for 3 half-frames Q15*/ + const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new - 2*/ + const Word16 corr_shift, /* i : normalized correlation correction Q15*/ + const Word16 bwidth, /* i : input signal bandwidth Q0*/ + const Word16 max_band, /* i : maximum critical band Q0*/ + Word32 hp_E[], /* o : energy in HF Q_new*/ + const Word16 codec_mode, /* i : MODE1 or MODE2 Q0*/ + const Word16 Q_new, /* i : scaling factor */ + Word32 *bckr_tilt_lt /* i/o: lf/hf E ratio of background noise Q16*/ + , + Word16 Opt_vbr_mode /* Q0 */ +); void find_tilt_fx( - const Word32 fr_bands[], /* i : energy in frequency bands Q_new + Q_SCALE*/ - const Word32 bckr[], /* i : per band background noise energy estimate Q_new + Q_SCALE*/ - Word32 ee[2], /* o : lf/hf E ration for present frame Q6*/ - const Word16 pitch[3], /* i : open loop pitch values for 3 half-frames Q0*/ - const Word16 voicing[3], /* i : normalized correlation for 3 half-frames Q15*/ + const Word32 fr_bands[], /* i : energy in frequency bands Q_new + Q_SCALE*/ + const Word32 bckr[], /* i : per band background noise energy estimate Q_new + Q_SCALE*/ + Word32 ee[2], /* o : lf/hf E ration for present frame Q6*/ + const Word16 pitch[3], /* i : open loop pitch values for 3 half-frames Q0*/ + const Word16 voicing[3], /* i : normalized correlation for 3 half-frames Q15*/ const Word32 *lf_E, /* i : per bin energy for low frequencies Q_new + Q_SCALE - 2*/ - const Word16 corr_shift, /* i : normalized correlation correction Q15*/ - const Word16 bwidth, /* i : i signal bandwidth */ - const Word16 max_band, /* i : maximum critical band */ + const Word16 corr_shift, /* i : normalized correlation correction Q15*/ + const Word16 bwidth, /* i : input signal bandwidth Q0*/ + const Word16 max_band, /* i : maximum critical band Q0*/ Word32 hp_E[], /* o : energy in HF Q_new + Q_SCALE*/ - const Word16 codec_mode, /* i : MODE1 or MODE2 */ - const Word16 Q_new, /* i : scaling factor */ - Word32 *bckr_tilt_lt, - Word16 Opt_vbr_mode ); + const Word16 codec_mode, /* i : MODE1 or MODE2 Q0*/ + const Word16 Q_new, /* i : scaling factor */ + Word32 *bckr_tilt_lt /* i/o: lf/hf E ratio of background noise Q16*/ + , + Word16 Opt_vbr_mode /* Q0 */ +); Word16 find_uv_ivas_fx( /* o : coding type */ Encoder_State *st_fx, /* i/o: encoder state structure */ @@ -1796,12 +1800,12 @@ void generate_comfort_noise_enc_fx( Encoder_State *stcod, Word16 gen_exc ); Word16 cng_energy_fx( - const Word16 element_mode, /* i : element mode */ - const Word16 bwidth, /* i : audio bandwidh */ - const Word16 CNG_mode, /* i : mode for DTX configuration */ - const Word16 CNG_att, /* i : attenuation factor for CNG */ - const Word16 *exc, /* i : i signal */ - const Word16 len, /* i : vector length */ + const Word16 element_mode, /* i : element mode Q0*/ + const Word16 bwidth, /* i : audio bandwidh Q0*/ + const Word16 CNG_mode, /* i : mode for DTX configuration Q0*/ + const Word16 CNG_att, /* i : attenuation factor for CNG Q7*/ + const Word16 *exc, /* i : input signal Q_new*/ + const Word16 len, /* i : vector length Q0*/ const Word16 Q_new /* i : Input scaling */ ); @@ -1955,44 +1959,49 @@ void coder_acelp_rf_fx( /* Create an instance of type FD_CNG */ void createFdCngEnc_fx( HANDLE_FD_CNG_ENC *hFdCngEnc ); -void initFdCngEnc_fx( HANDLE_FD_CNG_ENC hsEnc, Word32 input_Fs, Word16 scale ); +void initFdCngEnc_fx( + HANDLE_FD_CNG_ENC hsEnc, + Word32 input_Fs, /* Q0 */ + Word16 scale ); /* Configure CLDFB-CNG */ void configureFdCngEnc_fx( HANDLE_FD_CNG_ENC hs, /* i/o: Contains the variables related to the CLDFB-based CNG process */ - Word16 bandwidth, /* i: bandwidth */ - Word32 bitrate ); + Word16 bandwidth, /* i: bandwidth Q0*/ + Word32 bitrate /* Q0 */ +); /* Perform noise estimation */ void perform_noise_estimation_enc_fx( - Word32 *band_energies, /* i: energy in critical bands without minimum noise floor MODE2_E_MIN */ + Word32 *band_energies, /* i: energy in critical bands without minimum noise floor MODE2_E_MIN exp_band_energies*/ Word16 exp_band_energies, - Word32 *enerBuffer, + Word32 *enerBuffer, /* enerBuffer_exp */ Word16 enerBuffer_exp, HANDLE_FD_CNG_ENC st ); /* i/o: FD_CNG structure containing all buffers and variables */ void perform_noise_estimation_enc_ivas_fx( - Word32 *band_energies, /* i: energy in critical bands without minimum noise floor MODE2_E_MIN */ + Word32 *band_energies, /* i: energy in critical bands without minimum noise floor MODE2_E_MIN band_energies_exp*/ Word16 band_energies_exp, - Word32 *enerBuffer, + Word32 *enerBuffer, /* enerBuffer_exp */ Word16 enerBuffer_exp, HANDLE_FD_CNG_ENC hFdCngEnc, /* i/o: CNG structure containing all buffers and variables */ - const Word32 input_Fs, /* i : input sampling rate */ + const Word32 input_Fs, /* i : input sampling rate Q0*/ CPE_ENC_HANDLE hCPE /* i : CPE encoder structure */ ); /* Adjust the noise estimator at the beginning of each CNG phase (encoder-side) */ -Word16 -AdjustFirstSID_fx( Word16 npart, - Word32 *msPeriodog, - Word16 msPeriodog_exp, - Word32 *energy_ho, - Word16 *energy_ho_exp, - Word32 *msNoiseEst, - Word16 *msNoiseEst_exp, - Word32 *msNoiseEst_old, - Word16 *msNoiseEst_old_exp, - Word16 *active_frame_counter, - Encoder_State *stcod ); +Word16 AdjustFirstSID_fx( + Word16 npart, /* i : number of parts Q0*/ + Word32 *msPeriodog, /* i : pointer to periodog vector msPeriodog_exp */ + Word16 msPeriodog_exp, /* i : exponent of periodog vector */ + Word32 *energy_ho, /* i/o : pointer to energy energy_ho_exp*/ + Word16 *energy_ho_exp, /* i/o : pointer to exponent of energy */ + Word32 *msNoiseEst, /* i/o : pointer to estimated noise msNoiseEst_exp*/ + Word16 *msNoiseEst_exp, /* i/o : pointer to exponent of estimated noise */ + Word32 *msNoiseEst_old, /* i/o : pointer to old estimated noise msNoiseEst_old_exp*/ + Word16 *msNoiseEst_old_exp, /* i/o : pointer to exponent of old estimated noise */ + Word16 *active_frame_counter, /* i/o : pointer to active frame counter Q0*/ + Encoder_State *stcod /* i : pointer to Coder_State_Plus structure */ +); void FdCng_encodeSID_ivas_fx( Encoder_State *st /* i/o: encoder state structure */ @@ -2269,31 +2278,30 @@ void E_ACELP_weighted_code( void find_targets_fx( const Word16 *speech, /* i : pointer to the speech frame Q_new-1*/ const Word16 *mem_syn, /* i : memory of the synthesis filter Q_new-1*/ - const Word16 i_subfr, /* i : subframe index */ + const Word16 i_subfr, /* i : subframe index Q0*/ Word16 *mem_w0, /* i/o: weighting filter denominator memory Q_new-1*/ const Word16 *p_Aq, /* i : interpolated quantized A(z) filter Q12*/ const Word16 *res, /* i : residual signal Q_new*/ - const Word16 L_subfr, /* i : length of vectors for gain quantization */ + const Word16 L_subfr, /* i : length of vectors for gain quantization Q0*/ const Word16 *Ap, /* i : unquantized A(z) filter with bandwidth expansion Q12*/ - Word16 tilt_fac, /* i : tilt factor Q15 */ + Word16 tilt_fac, /* i : tilt factor Q15*/ Word16 *xn, /* o : Close-loop Pitch search target vector Q_new-1*/ - Word16 *cn /* o : target vector in residual domain Q_new*/ - , - Word16 *h1 /* Q14 ?*/ + Word16 *cn, /* o : target vector in residual domain Q_new*/ + Word16 *h1 /* o : impulse response of weighted synthesis filter Q14*/ ); void find_targets_ivas_fx( const Word16 *speech, /* i : pointer to the speech frame Q_new-1*/ const Word16 *mem_syn, /* i : memory of the synthesis filter Q_new-1*/ - const Word16 i_subfr, /* i : subframe index */ + const Word16 i_subfr, /* i : subframe index Q0*/ Word16 *mem_w0, /* i/o: weighting filter denominator memory Q_new-1*/ const Word16 *p_Aq, /* i : interpolated quantized A(z) filter Q12*/ const Word16 *res, /* i : residual signal Q_new*/ - const Word16 L_subfr, /* i : length of vectors for gain quantization */ + const Word16 L_subfr, /* i : length of vectors for gain quantization Q0*/ const Word16 *Ap, /* i : unquantized A(z) filter with bandwidth expansion Q12*/ - Word16 tilt_fac, /* i : tilt factor Q15 */ + Word16 tilt_fac, /* i : tilt factor Q15*/ Word16 *xn, /* o : Close-loop Pitch search target vector Q_new-1*/ Word16 *cn, /* o : target vector in residual domain Q_new*/ - Word16 *h1 /* o : impulse response of weighted synthesis filter */ + Word16 *h1 /* o : impulse response of weighted synthesis filter Q14*/ ); void E_ACELP_adaptive_codebook( @@ -2399,38 +2407,38 @@ void QuantizeGain( Word16 n, Word16 *pGain, Word16 *pGain_e, Word16 *pQuantizedG void core_signal_analysis_high_bitrate_fx( const Word16 *new_samples, /*i: 0Q15*/ - const Word16 T_op[3], /* i : open-loop pitch values for quantiz. */ - Word16 lsp_new[], - Word16 lsp_mid[], + const Word16 T_op[3], /* i : open-loop pitch values for quantiz. Q0*/ + Word16 lsp_new[], /* Q15 */ + Word16 lsp_mid[], /* Q15 */ Encoder_State *st, - Word16 pTnsSize[], - Word16 pTnsBits[], - Word16 param_core[], - Word16 *ltpBits, - const Word16 L_frame, - const Word16 L_frameTCX, - const Word16 last_element_mode, - const Word16 vad_hover_flag, /* i : VAD hangover flag */ - Word32 **spectrum, + Word16 pTnsSize[], /* Q0 */ + Word16 pTnsBits[], /* Q0 */ + Word16 param_core[], /* Q0 */ + Word16 *ltpBits, /* Q0 */ + const Word16 L_frame, /* Q0 */ + const Word16 L_frameTCX, /* Q0 */ + const Word16 last_element_mode, /* Q0 */ + const Word16 vad_hover_flag, /* i : VAD hangover flag Q0*/ + Word32 **spectrum, /* spectrum_e */ Word16 *spectrum_e, Word16 *Q_new ); void core_signal_analysis_high_bitrate_ivas_fx( const Word16 *new_samples, /*i: Q0 */ - const Word16 T_op[3], /* i : open-loop pitch values for quantiz. */ + const Word16 T_op[3], /* i : open-loop pitch values for quantiz. Q0*/ Word16 lsp_new[], /* Q15 */ Word16 lsp_mid[], /* Q15 */ Encoder_State *st, - Word16 pTnsSize[], - Word16 pTnsBits[], - Word16 param_core[], - Word16 *ltpBits, - Word32 *windowed_samples, - const Word16 L_frame, - const Word16 L_frameTCX, - const Word16 last_element_mode, - const Word16 vad_hover_flag, /* i : VAD hangover flag */ - Word32 **spectrum, + Word16 pTnsSize[], /* Q0 */ + Word16 pTnsBits[], /* Q0 */ + Word16 param_core[], /* Q0 */ + Word16 *ltpBits, /* Q0 */ + Word32 *windowed_samples, /* q_win */ + const Word16 L_frame, /* Q0 */ + const Word16 L_frameTCX, /* Q0 */ + const Word16 last_element_mode, /* Q0 */ + const Word16 vad_hover_flag, /* i : VAD hangover flag Q0*/ + Word32 **spectrum, /* exp(spectrum_e) */ Word16 *spectrum_e, Word16 *Q_new, Word16 *q_win );