diff --git a/Workspace_msvc/lib_enc.vcxproj b/Workspace_msvc/lib_enc.vcxproj
index 6a96e575afec827336594943962333caa51f8154..015a20cde025ce587d8d70eb733ef7b1881703ad 100644
--- a/Workspace_msvc/lib_enc.vcxproj
+++ b/Workspace_msvc/lib_enc.vcxproj
@@ -239,12 +239,6 @@
-
-
-
-
-
-
@@ -281,18 +275,13 @@
-
-
-
-
-
@@ -424,7 +413,6 @@
-
diff --git a/Workspace_msvc/lib_enc.vcxproj.filters b/Workspace_msvc/lib_enc.vcxproj.filters
index 73bd7c7bbacacc2f72dff543481ac75bcd931406..612bf52a3b281c4ae23f65a6e699bf08cee784bb 100644
--- a/Workspace_msvc/lib_enc.vcxproj.filters
+++ b/Workspace_msvc/lib_enc.vcxproj.filters
@@ -19,12 +19,6 @@
enc_ivas_c
-
- enc_evs_c
-
-
- enc_evs_c
-
enc_evs_c
@@ -61,12 +55,6 @@
enc_evs_c
-
- enc_evs_c
-
-
- enc_evs_c
-
enc_evs_c
@@ -115,18 +103,6 @@
enc_evs_c
-
- enc_all_c
-
-
- enc_all_c
-
-
- enc_all_c
-
-
- enc_all_c
-
enc_all_c
@@ -196,12 +172,6 @@
enc_all_c
-
- enc_all_c
-
-
- enc_all_c
-
enc_all_c
@@ -217,9 +187,6 @@
enc_all_c
-
- enc_all_c
-
enc_all_c
@@ -433,9 +400,6 @@
enc_evs_c
-
- enc_evs_c
-
enc_ivas_c
@@ -451,9 +415,6 @@
enc_ivas_c
-
- enc_ivas_c
-
enc_ivas_c
diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h
index d0517ccce632d691c02ab50395d0481d83258e84..cee2bbaad8941a715a932bf864c0c4ab3cb4fc72 100644
--- a/lib_com/ivas_prot.h
+++ b/lib_com/ivas_prot.h
@@ -235,7 +235,7 @@ ivas_error pre_proc_front_ivas_fx(
const Word16 currFlatness_fx, /* i : flatness parameter Q7 */
const Word16 tdm_ratio_idx, /* i : Current Ratio_L index */
Word32 fr_bands_LR_fx[][2 * NB_BANDS], /* i : energy in frequency bands (fr_bands_LR_fx_q) */
- Word16 fr_bands_LR_fx_q,
+ Word16 fr_bands_LR_fx_q[CPE_CHANNELS],
const Word16 Etot_LR_fx[], /* i : total energy Left & Right channel Q8*/
Word32 lf_E_LR_fx[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels (lf_E_LR_fx_q) */
Word16 lf_E_LR_fx_q,
diff --git a/lib_com/prot.h b/lib_com/prot.h
index 5cfa2cd29e18bb1c2eecd4ae1a9ade4d39d45e71..4fe464c21ef78e6d99fd4efefab709fc08a8274a 100644
--- a/lib_com/prot.h
+++ b/lib_com/prot.h
@@ -2004,24 +2004,24 @@ void MDCT_selector(
const float enerBuffer[] /* i : energy buffer */
);
-ivas_error acelp_core_enc(
+ivas_error acelp_core_enc_ivas_fx(
Encoder_State *st, /* i/o: encoder state structure */
- const Word16 inp[], /* i : input signal of the current frame */
- Word16 A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes */
- Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes */
- const Word32 epsP[M + 1], /* i : LP prediction errors */
- Word16 lsp_new[M], /* i : LSPs at the end of the frame */
- Word16 lsp_mid[M], /* i : LSPs in the middle of the frame */
- const Word16 vad_hover_flag, /* i : VAD hangover flag */
- const Word16 attack_flag, /* i : attack flag (GSC or TC) */
- Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation 2*Q_new */
- Word16 *voice_factors_fx, /* o : voicing factors Q15 */
- Word16 old_syn_12k8_16k[], /* o : ACELP core synthesis at 12.8kHz or 16kHz to be used by SWB BWE */
+ const Word16 inp[], /* i : input signal of the current frame Q_new*/
+ Word16 A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12*/
+ Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes Q12*/
+ const Word32 epsP[M + 1], /* i : LP prediction errors Qx*/
+ Word16 lsp_new[M], /* i : LSPs at the end of the frame Q15*/
+ Word16 lsp_mid[M], /* i : LSPs in the middle of the frame Q15*/
+ const Word16 vad_hover_flag, /* i : VAD hangover flag Q0*/
+ const Word16 attack_flag, /* i : attack flag (GSC or TC) Q0*/
+ Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation st->prev_Q_bwe_exc*/
+ Word16 *voice_factors_fx, /* o : voicing factors Q15*/
+ Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE q_old_syn_12k8_16*/
Word16 *q_old_syn_12k8_16,
- Word16 pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */
- Word16 *unbits, /* o : number of unused bits */
- STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */
- Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */
+ Word16 pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe Q6*/
+ Word16 *unbits, /* o : number of unused bits Q0*/
+ STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */
+ Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel X2.56*/
Word16 Q_new );
ivas_error acelp_core_switch_dec_bfi(
@@ -6135,17 +6135,18 @@ int16_t RCcontextMapping_encode2_estimate_no_mem_s17_LCS(
CONTEXT_HM_CONFIG *hm_cfg /* context-based harmonic model configuration */
);
-int16_t RCcontextMapping_encode2_estimate_bandWise_start(
- int16_t *x,
- const int16_t nt,
- const int16_t target,
+Word16 RCcontextMapping_encode2_estimate_bandWise_start_fx(
+ Word16 *x, /* Q0 */
+ const Word16 nt, /* Q0 */
+ const Word16 target, /* Q0 */
HANDLE_RC_CONTEXT_MEM hContextMem );
-int16_t RCcontextMapping_encode2_estimate_bandWise(
- int16_t *x,
- const int16_t start_line,
- const int16_t end_line,
- HANDLE_RC_CONTEXT_MEM hContextMem );
+Word16 RCcontextMapping_encode2_estimate_bandWise_fx(
+ Word16 *x, /* Q0 */
+ const Word16 start_line, /* Q0 */
+ const Word16 end_line, /* Q0 */
+ HANDLE_RC_CONTEXT_MEM hContextMem /* Q0 */
+);
void tcx_get_windows_flt(
TCX_CONFIG_HANDLE hTcxCfg, /* i : TCX configuration */
@@ -6599,16 +6600,16 @@ void decoder_acelp(
float *bwe_exc /* o : excitation for SWB TBE */
);
-void writeTCXMode(
- Encoder_State *st, /* i/o: encoder state structure */
- BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
- const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/
- int16_t *nbits_start /* o : nbits start */
+void writeTCXMode_fx(
+ Encoder_State *st, /* i/o: encoder state structure */
+ BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
+ const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/
+ Word16 *nbits_start /* o : nbits start Q0*/
);
-void writeTCXWindowing(
- BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
- const int16_t overlap_mode /* i : overlap mode */
+void writeTCXWindowing_fx(
+ BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
+ const Word16 overlap_mode /* i : overlap mode Q0*/
);
void writeLPCparam(
diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h
index 715c49ae14e8eaefa4f0365c7dea8ad7b0a07b58..c8f00ee8a9fbb4e034f2ba88ad3c3666f3199022 100644
--- a/lib_com/prot_fx.h
+++ b/lib_com/prot_fx.h
@@ -9926,14 +9926,14 @@ void tcx_scalar_quantization_ivas_fx(
Word8 const *memQuantZeros_fx, /* i: coefficients to be set to 0 */
const Word16 alfe_flag );
-Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS(
- Word16 *x, /* Spectral coefficients */
- const Word16 nt, /* L - size of spectrum (no. of spectral coefficients) */
- Word16 *lastnz_out,
- Word16 *nEncoded, /* No. of spectral coefficients that can be coded without an overflow occuring */
- const Word16 target, /* Target bits */
- Word16 *stop,
- Word16 mode,
+Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx(
+ Word16 *x, /* Spectral coefficients Q0*/
+ const Word16 nt, /* L - size of spectrum (no. of spectral coefficients) Q0*/
+ Word16 *lastnz_out, /* Q0 */
+ Word16 *nEncoded, /* No. of spectral coefficients that can be coded without an overflow occuring Q0*/
+ const Word16 target, /* Target bits Q0*/
+ Word16 *stop, /* Q0 */
+ Word16 mode, /* Q0 */
CONTEXT_HM_CONFIG *hm_cfg /* context-based harmonic model configuration */
);
@@ -10956,12 +10956,12 @@ Word16 get_next_coeff_mapped_ivas_fx(
);
void RCcontextMapping_encode2_no_mem_s17_LCS_fx(
- BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
- Word16 *x,
- const Word16 nt,
- Word16 lastnz,
- const Word16 nbbits,
- const Word16 resQMaxBits,
+ BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
+ Word16 *x, /* Q0 */
+ const Word16 nt, /* Q0 */
+ Word16 lastnz, /* Q0 */
+ const Word16 nbbits, /* Q0 */
+ const Word16 resQMaxBits, /* Q0 */
CONTEXT_HM_CONFIG *hm_cfg );
void writeTCXparam_fx(
@@ -11081,16 +11081,16 @@ Word16 msvq_stage1_dct_recalc_candidates_fdcng_wb_fx(
);
void FEC_encode_ivas_fx(
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- const ACELP_config acelp_cfg, /* i/o: configuration of the ACELP */
- const Word16 *synth, /* i : pointer to synthesized speech for E computation */
- const Word16 coder_type, /* i : type of coder */
- Word16 clas, /* i : signal clas for current frame */
- const Word16 *fpit, /* i : close loop fractional pitch buffer Q6 */
- const Word16 *res, /* i : LP residual signal frame */
- Word16 *last_pulse_pos, /* i/o: Position of the last pulse */
- const Word16 L_frame, /* i : Frame length */
- const Word32 total_brate, /* i : total codec bitrate */
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ const ACELP_config acelp_cfg, /* i/o: configuration of the ACELP */
+ const Word16 *synth, /* i : pointer to synthesized speech for E computation Q_Synth*/
+ const Word16 coder_type, /* i : type of coder Q0*/
+ Word16 clas, /* i : signal clas for current frame Q0*/
+ const Word16 *fpit, /* i : close loop fractional pitch buffer Q6*/
+ const Word16 *res, /* i : LP residual signal frame Qx*/
+ Word16 *last_pulse_pos, /* i/o: Position of the last pulse Q0*/
+ const Word16 L_frame, /* i : Frame length Q0*/
+ const Word32 total_brate, /* i : total codec bitrate Q0*/
const Word16 Q_synth /* i : input scaling */
);
diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c
index dbef25ccbea2520ed74e6ef5715c2747b6c4e83f..78338d8e336dafbf4f44a2208c1dfb9e08bdf564 100644
--- a/lib_com/tools_fx.c
+++ b/lib_com/tools_fx.c
@@ -1029,10 +1029,13 @@ void scale_sig(
{
Word16 i;
- FOR( i = 0; i < lg; i++ )
+ IF( exp0 != 0 )
{
- x[i] = shl( x[i], exp0 );
- move16();
+ FOR( i = 0; i < lg; i++ )
+ {
+ x[i] = shl( x[i], exp0 );
+ move16();
+ }
}
}
diff --git a/lib_enc/ACcontextMapping_enc.c b/lib_enc/ACcontextMapping_enc.c
deleted file mode 100644
index 250bfcf1ba83a538bcbe37c040e151911684b936..0000000000000000000000000000000000000000
--- a/lib_enc/ACcontextMapping_enc.c
+++ /dev/null
@@ -1,712 +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
-#include "cnst.h"
-#include "rom_com.h"
-#include "prot.h"
-#include "ivas_prot.h" /* Range coder header file */
-#include "ivas_rom_com.h"
-#include "ivas_rom_enc.h"
-#include "wmc_auto.h"
-#include "prot_fx.h"
-
-
-/*-------------------------------------------------------------------*
- * ACcontextMapping_encode2_no_mem_s17_LC()
- *
- * Arithmetic encoder
- *-------------------------------------------------------------------*/
-/*-------------------------------------------------------------------*
- * find_last_nz_pair()
- *
- *
- *-------------------------------------------------------------------*/
-
-static Word16 find_last_nz_pair(
- const Word16 x[],
- const Word16 length,
- const CONTEXT_HM_CONFIG *hm_cfg )
-{
- Word16 last_nz, i;
- const Word16 *tmp;
-
- last_nz = 2;
- move16();
-
- IF( hm_cfg )
- {
- /* mapped kernel */
- tmp = hm_cfg->indexBuffer;
-
- FOR( i = length; i >= 4; i -= 2 )
- {
- test();
- IF( x[tmp[i - 2]] || x[tmp[i - 1]] )
- {
- last_nz = i;
- move16();
- BREAK;
- }
- }
- }
- ELSE
- {
- /* unmapped kernel */
-
- FOR( i = length; i >= 4; i -= 2 )
- {
- test();
- IF( x[i - 2] || x[i - 1] )
- {
- last_nz = i;
- move16();
- BREAK;
- }
- }
- }
-
- return last_nz;
-}
-
-
-/*-------------------------------------------------------------------*
- * ACcontextMapping_encode2_estimate_no_mem_s17_LC()
- *
- *
- *-------------------------------------------------------------------*/
-/*-------------------------------------------------------------------*
- * RCcontextMapping_encode2_estimate_no_mem_s17_LCS()
- *
- * Range coder bit-estimation
- *-------------------------------------------------------------------*/
-
-Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS(
- Word16 *x, /* Spectral coefficients */
- const Word16 nt, /* L - size of spectrum (no. of spectral coefficients) */
- Word16 *lastnz_out,
- Word16 *nEncoded, /* No. of spectral coefficients that can be coded without an overflow occuring */
- const Word16 target, /* Target bits */
- Word16 *stop,
- Word16 mode,
- CONTEXT_HM_CONFIG *hm_cfg /* context-based harmonic model configuration */
-)
-{
- /* Common variables */
- Word16 a1, b1;
- Word16 k, pki, lev1;
- UWord16 t;
- Word16 lastnz, lastnz2;
- Word16 rateFlag;
- Word32 bit_estimate_fx;
- Word16 bit_estimate_e;
- Word16 symbol;
- const UWord8 *lookup;
- Word32 nbits2_fx; // Q23
- Word16 nbits2_e; // Q23
-
- /* Initialization */
- bit_estimate_fx = 2 * ONE_IN_Q29;
- bit_estimate_e = 2;
- move32();
- nbits2_fx = 0;
- nbits2_e = 0;
- move32();
-
- /* bits to encode lastnz */
- k = 1;
- move16();
-
- WHILE( LT_16( k, nt / 2 ) )
- {
- bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, ONE_IN_Q30, 1, &bit_estimate_e );
- k = k << 1;
- /* check while condition */
- }
-
- nbits2_fx = bit_estimate_fx;
- nbits2_e = bit_estimate_e;
-
- IF( hm_cfg )
- {
- Word16 a1_i, b1_i;
- Word16 stop2;
- Word16 total_output_bits;
- Word16 nt_half;
- Word32 c[2], *ctx;
- Word32 p1, p2;
- Word16 ii[2];
- Word16 idx1, idx2, idx;
- Word16 numPeakIndicesOrig = 0, numHoleIndices = 0; /* only to avoid compiler warning */
- move16();
- move16();
-
- /* Rate flag */
- IF( GT_16( target, 400 ) )
- {
- rateFlag = 2 << NBITS_CONTEXT; /* Select context-A for higher bitrates */
- move16();
- }
- ELSE
- {
- rateFlag = 0; /* Select context-B for lower bitrates */
- move16();
- }
-
- nt_half = shr( nt, 1 );
- move16();
- stop2 = 0;
- move16();
- c[0] = c[1] = 0;
- move32();
- move32();
-
- /* Find last non-zero tuple in the mapped domain signal */
- lastnz = find_last_nz_pair( x, nt, hm_cfg );
-
- lastnz2 = 2;
- move16();
-
- /* mapped domain */
- numPeakIndicesOrig = hm_cfg->numPeakIndices;
- move16();
- hm_cfg->numPeakIndices = s_min( hm_cfg->numPeakIndices, lastnz );
- move16();
- numHoleIndices = sub( lastnz, hm_cfg->numPeakIndices );
-
- /* Mark hole indices beyond lastnz as pruned */
- FOR( k = numHoleIndices; k < hm_cfg->numHoleIndices; ++k )
- {
- hm_cfg->holeIndices[k] = add( hm_cfg->holeIndices[k], nt );
- move16();
- }
-
- ii[0] = numPeakIndicesOrig;
- move16();
- ii[1] = 0;
- move16();
-
- p1 = p2 = 0; /* to avoid compilation warnings */
- move32();
- move32();
-
- /* Main Loop through the 2-tuples */
- FOR( k = 0; k < lastnz; k += 2 )
- {
- a1_i = get_next_coeff_mapped_ivas_fx( ii, &p1, &idx1, hm_cfg );
- b1_i = get_next_coeff_mapped_ivas_fx( ii, &p2, &idx2, hm_cfg );
-
- idx = s_min( idx1, idx2 );
-
- /* Get context */
- ctx = &c[L_or( p1, p2 )];
-
- t = (UWord16) L_add( *ctx, rateFlag );
- IF( LT_16( nt_half, idx ) )
- {
- t = add( t, ( 1 << NBITS_CONTEXT ) );
- }
-
- /* Init current 2-tuple encoding */
- a1 = (Word16) abs( x[a1_i] );
- b1 = (Word16) abs( x[b1_i] );
- lev1 = -( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) );
-
- bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, s_min( a1, 1 ) * ONE_IN_Q30, 1, &bit_estimate_e );
- bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, s_min( b1, 1 ) * ONE_IN_Q30, 1, &bit_estimate_e );
-
- /* pre-compute address of ari_pk_s17_LC_ext[0][Val_esc] to avoid doing it multiple times inside the loop */
- lookup = &ari_lookup_s17_LC[t] + ( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) );
-
- /* check while condition */
- /* MSBs coding */
- WHILE( GE_16( s_max( a1, b1 ), A_THRES ) )
- {
- pki = lookup[lev1]; /* ESC symbol */
-
- bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC], 8, &bit_estimate_e );
- bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, 2 * ONE_IN_Q29, 2, &bit_estimate_e ); /* Add 2 LSB bits corresponding to the bit-plane */
-
- ( a1 ) = shr( a1, 1 );
- ( b1 ) = shr( b1, 1 );
-
- lev1 = s_min( add( lev1, ( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ) ), 2 << ( NBITS_CONTEXT + NBITS_RATEQ ) );
-
- /* check while condition */
- }
-
- pki = lookup[lev1];
-
- symbol = add( a1, i_mult( A_THRES, b1 ) );
- bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][symbol], 8, &bit_estimate_e );
-
- /* Should we truncate? */
- IF( GT_32( L_shr( bit_estimate_fx, sub( Q16, bit_estimate_e ) ), L_shl( target, Q15 ) ) )
- {
- stop2 = 1;
- move16();
-
- IF( *stop )
- {
- BREAK;
- }
- }
- ELSE
- {
- lastnz2 = add( b1_i, 1 );
- nbits2_fx = bit_estimate_fx;
- move32();
- nbits2_e = bit_estimate_e;
- move16();
- }
-
- /* Update context for next 2-tuple */
- IF( EQ_32( p1, p2 ) ) /* peak-peak or hole-hole context */
- {
- lev1 = shr( lev1, NBITS_CONTEXT + NBITS_RATEQ );
-
- IF( lev1 <= 0 )
- {
- t = add( 1, i_mult( add( a1, b1 ), add( lev1, 2 ) ) );
- }
- ELSE
- {
- t = add( 13, lev1 );
- }
-
- *ctx = L_add( imult3216( L_and( *ctx, 0xf ), 16 ), t );
- move32();
- }
- ELSE
- {
- /* mixed context */
-
- IF( s_and( idx1, 1 ) )
- {
- /* update first context */
- c[p1] = update_mixed_context_ivas_fx( c[p1], (Word16) abs( x[a1_i] ) );
- move32();
- }
-
- IF( s_and( idx2, 1 ) )
- {
- /* update second context */
- c[p2] = update_mixed_context_ivas_fx( c[p2], (Word16) abs( x[b1_i] ) );
- move32();
- }
- }
-
- } /*end of the 2-tuples loop*/
-
- total_output_bits = round_fx( L_shr( bit_estimate_fx, sub( Q15, bit_estimate_e ) ) );
-
- IF( *stop )
- {
- total_output_bits = round_fx( L_shr( nbits2_fx, sub( Q15, nbits2_e ) ) );
- }
-
- IF( stop2 )
- {
- stop2 = total_output_bits;
- move16();
- }
-
- *nEncoded = lastnz2;
- move16();
- *stop = stop2; /* If zero, it means no overflow occured during bit-estimation */
- move16();
- *lastnz_out = lastnz;
- move16();
-
- /* Restore hole indices beyond lastnz */
- FOR( k = numHoleIndices; k < hm_cfg->numHoleIndices; ++k )
- {
- hm_cfg->holeIndices[k] = sub( hm_cfg->holeIndices[k], nt );
- move16();
- }
- hm_cfg->numPeakIndices = numPeakIndicesOrig;
- move16();
-
- return round_fx( L_add( L_shr( nbits2_fx, sub( Q15, nbits2_e ) ), ONE_IN_Q14 ) );
- }
- ELSE /* if (!hm_cfg) */
- {
- Word16 esc_nb, cp, rateQ;
- UWord16 s;
- Word16 tot_bits2;
- Word16 overflow_flag = 0;
-
- /* Rate flag */
- IF( GT_16( target, 400 ) )
- {
- rateFlag = 2;
- move16();
- }
- ELSE
- {
- rateFlag = 0; /* Select context-B for lower bitrates */
- move16();
- }
-
- t = 0;
- move16();
- s = 0;
- move16();
- cp = 0;
- move16();
- lastnz = 1;
- move16();
- lastnz2 = 0;
- move16();
- tot_bits2 = 0;
- move16();
-
- /* Find last non-zero tuple in the mapped domain signal */
- FOR( lastnz = sub( nt, 2 ); lastnz >= 0; lastnz -= 2 )
- {
- test();
- IF( ( x[lastnz] != 0 ) || ( x[lastnz + 1] != 0 ) )
- {
- BREAK;
- }
- }
- lastnz = add( lastnz, 2 );
- IF( LT_16( lastnz, 2 ) )
- {
- lastnz = 2; /* At least one tuple is coded */
- move16();
- }
-
- lastnz2 = 2;
- move16();
-
- /* Main Loop through the 2-tuples */
- FOR( k = 0; k < lastnz; k += 2 )
- {
- /* Init current 2-tuple encoding */
- a1 = abs_s( x[k] );
- b1 = abs_s( x[k + 1] );
- lev1 = 0;
- move16();
- esc_nb = 0;
- move16();
- rateQ = add( rateFlag, (Word16) GT_16( k, shr( nt, 1 ) ) );
-
- bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, s_min( a1, 1 ) * ONE_IN_Q30, 1, &bit_estimate_e );
- bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, s_min( b1, 1 ) * ONE_IN_Q30, 1, &bit_estimate_e );
-
- /* pre-compute address of ari_pk_s17_LC_ext[0][Val_esc] to avoid doing it multiple times inside the loop */
- lookup = &ari_lookup_s17_LC[t + shl( rateQ, NBITS_CONTEXT )];
-
- /* check while condition */
- /* MSBs coding */
- WHILE( GE_16( s_max( a1, b1 ), A_THRES ) )
- {
- pki = lookup[( esc_nb << ( NBITS_CONTEXT + NBITS_RATEQ ) )];
-
- bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC], 8, &bit_estimate_e );
- bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, 2 * ONE_IN_Q29, 2, &bit_estimate_e ); /* Add 2 LSB bits corresponding to the bit-plane */
-
- ( a1 ) = shr( a1, 1 );
- ( b1 ) = shr( b1, 1 );
-
- lev1 = add( lev1, 1 );
- esc_nb = s_min( lev1, 3 );
-
- /* check while condition */
- }
-
- pki = lookup[( esc_nb << ( NBITS_CONTEXT + NBITS_RATEQ ) )];
-
- symbol = add( a1, i_mult( A_THRES, b1 ) );
- bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][symbol], 8, &bit_estimate_e );
-
- /* Should we truncate? */
- IF( GT_32( L_shr( bit_estimate_fx, sub( Q16, bit_estimate_e ) ), L_shl( target, Q15 ) ) ) /* Overflow occured */
- {
- overflow_flag = 1;
- move16();
- }
- ELSE
- {
- IF( abs_s( x[k] ) || abs_s( x[k + 1] ) ) /* No overflow & non-zero tuple */
- {
- nbits2_fx = bit_estimate_fx;
- nbits2_e = bit_estimate_e;
- move32();
- lastnz2 = add( k, 2 );
- }
- }
-
- /* Update context for next 2-tuple */
- IF( LT_16( esc_nb, 2 ) )
- {
- cp = add( 1, i_mult( add( a1, b1 ), add( esc_nb, 1 ) ) );
- }
- ELSE
- {
- cp = add( 12, esc_nb );
- }
- /*shift old bits and replace last 4 bits*/
- s = ( s << 4 ) + cp;
- t = ( s & 0xFF );
-
- } /*end of the 2-tuples loop*/
-
- tot_bits2 = round_fx( L_shr( nbits2_fx, sub( Q15, nbits2_e ) ) );
- IF( lastnz2 < lastnz ) /* Overflow occured because unable to code all tuples */
- {
- overflow_flag = 1;
- move16();
- }
- IF( EQ_16( mode, -1 ) )
- {
- tot_bits2 = round_fx( L_shr( bit_estimate_fx, sub( Q15, bit_estimate_e ) ) );
- }
- IF( overflow_flag == 0 ) /* No overflow */
- {
- *stop = 0;
- move16();
- }
- ELSE /* Overflow */
- {
- IF( *stop ){
- *stop = tot_bits2;
- move16();
- }
- ELSE
- {
- *stop = round_fx( L_shr( bit_estimate_fx, sub( Q15, bit_estimate_e ) ) );
- move16();
- }
-}
-
-*lastnz_out = lastnz;
-move16();
-*nEncoded = lastnz2;
-move16();
-/* Safety mechanism to avoid overflow */
-test();
-IF( EQ_16( lastnz2, 2 ) && EQ_16( overflow_flag, 1 ) )
-{
- FOR( k = 0; k < lastnz2; k++ )
- {
- x[k] = 0;
- move16();
- }
-}
-
-return tot_bits2;
-}
-}
-
-/*-------------------------------------------------------------------*
- * RCcontextMapping_encode2_estimate_bandWise_start()
- *
- * Range coder - start bandwise bit-estimation
- *-------------------------------------------------------------------*/
-
-Word16 RCcontextMapping_encode2_estimate_bandWise_start(
- Word16 *x,
- const Word16 nt,
- const Word16 target,
- HANDLE_RC_CONTEXT_MEM hContextMem )
-{
- Word16 i, k;
-
- /* Rate flag */
- IF( GT_16( target, 400 ) )
- {
- hContextMem->rateFlag = 2 << NBITS_CONTEXT;
- move16();
- }
- ELSE
- {
- hContextMem->rateFlag = 0;
- move16();
- }
-
- hContextMem->bit_estimate_fx = 2;
- move32();
- hContextMem->bit_estimate_e = Q31;
- move16();
-
-
- /* Init */
- hContextMem->nt_half = shr( nt, 1 );
- move16();
-
- /* bits to encode lastnz */
- k = 1;
- move16();
-
- WHILE( LT_16( k, hContextMem->nt_half ) )
- {
- hContextMem->bit_estimate_fx = L_add( hContextMem->bit_estimate_fx, 1 );
- move32();
-
- k = shl( k, 1 );
- /* check while condition */
- }
-
- /* bits to encode lastnz */
- hContextMem->nbits_old = extract_l( hContextMem->bit_estimate_fx );
- move16();
-
- hContextMem->ctx = 0;
- move16();
- hContextMem->lastnz = 2;
- move16();
-
- /* Find last non-zero tuple */
-
- FOR( i = nt; i >= 4; i -= 2 )
- {
- test();
- IF( x[i - 2] != 0 || x[i - 1] != 0 )
- {
- hContextMem->lastnz = i;
- move16();
- break;
- }
- }
- Word16 tmp2 = extract_l( hContextMem->bit_estimate_fx );
- Word16 tmp = norm_l( hContextMem->bit_estimate_fx );
- hContextMem->bit_estimate_e = sub( Q31, tmp );
- move16();
- hContextMem->bit_estimate_fx = L_shl( hContextMem->bit_estimate_fx, tmp );
- move32();
-
- return tmp2;
-}
-
-/*-------------------------------------------------------------------*
- * RCcontextMapping_encode2_estimate_bandWise()
- *
- * Range coder - bandwise bit-estimation
- *-------------------------------------------------------------------*/
-
-Word16 RCcontextMapping_encode2_estimate_bandWise(
- Word16 *x,
- const Word16 start_line,
- const Word16 end_line,
- HANDLE_RC_CONTEXT_MEM hContextMem )
-{
- Word16 a1, b1, a1_i, b1_i;
- Word16 k, pki, lev1;
- UWord16 t;
- Word16 bandBits = 0;
- move16();
- Word16 total_output_bits; /* No. of bits after finalization */
- Word16 symbol;
- const UWord8 *lookup;
- Word16 idx;
-
- /* Main Loop through the 2-tuples */
- /*hContextMem->nt_half = end_line >> 1;*/
- FOR( k = start_line; k < min( hContextMem->lastnz, end_line ); k += 2 )
- {
- a1_i = k;
- move16();
- b1_i = add( k, 1 );
-
- idx = k;
- move16();
-
- /* Get context */
- t = add( hContextMem->ctx, hContextMem->rateFlag );
- t = add( t, GE_16( hContextMem->nt_half, idx ) ? 0 : ( 1 << NBITS_CONTEXT ) );
-
- /* Init current 2-tuple encoding */
- a1 = abs_s( x[a1_i] );
- b1 = abs_s( x[b1_i] );
- lev1 = -( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) );
-
- /* Signs Bits */
- hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, s_min( a1, 1 ) * ONE_IN_Q30, Q1, &hContextMem->bit_estimate_e );
- hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, s_min( b1, 1 ) * ONE_IN_Q30, Q1, &hContextMem->bit_estimate_e );
-
- /* pre-compute address of ari_pk_s17_LC_ext[0][Val_esc] to avoid doing it multiple times inside the loop */
- lookup = &ari_lookup_s17_LC[t] + ( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) );
-
- /* check while condition */
- /* MSBs coding */
- WHILE( GE_16( s_max( a1, b1 ), A_THRES ) )
- {
- pki = lookup[lev1];
- hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC], Q8, &hContextMem->bit_estimate_e );
- hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, 2 * ONE_IN_Q29, Q2, &hContextMem->bit_estimate_e ); /* Add the 2 LSB bits that were shifted out */
- // hContextMem->bit_estimate = hContextMem->bit_estimate + ari_bit_estimate_s17_LC[pki][VAL_ESC];
- // hContextMem->bit_estimate += 2; /* Add the 2 LSB bits that were shifted out */
-
- ( a1 ) = shr( a1, 1 );
- ( b1 ) = shr( b1, 1 );
-
- lev1 = s_min( add( lev1, ( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ) ), 2 << ( NBITS_CONTEXT + NBITS_RATEQ ) );
- /* check while condition */
- }
-
- pki = lookup[lev1];
- symbol = add( a1, i_mult( A_THRES, b1 ) ); /* MSB symbol */
- hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][symbol], Q8, &hContextMem->bit_estimate_e );
- // hContextMem->bit_estimate = hContextMem->bit_estimate + ari_bit_estimate_s17_LC[pki][symbol];
-
- /* Update context */
- lev1 = shr( lev1, NBITS_CONTEXT + NBITS_RATEQ );
-
- IF( lev1 <= 0 )
- {
- t = add( 1, i_mult( add( a1, b1 ), add( lev1, 2 ) ) );
- }
- ELSE
- {
- t = add( 13, lev1 );
- }
-
- hContextMem->ctx = add( i_mult( s_and( hContextMem->ctx, 0xf ), 16 ), t );
-
- } /*end of the 2-tuples loop*/
- total_output_bits = round_fx( L_shr( hContextMem->bit_estimate_fx, sub( Q15, hContextMem->bit_estimate_e ) ) );
- // total_output_bits = (Word16) ( hContextMem->bit_estimate + 0.5f );
-
- bandBits = sub( total_output_bits, hContextMem->nbits_old );
- hContextMem->nbits_old = total_output_bits;
- move16();
-
- return bandBits;
-}
diff --git a/lib_enc/ACcontextMapping_enc_fx.c b/lib_enc/ACcontextMapping_enc_fx.c
index 21089de9fd00cfbd08cbc87a2f430cc26fd55f69..bae26790190447ebef64e2a6b592056991fff8d6 100644
--- a/lib_enc/ACcontextMapping_enc_fx.c
+++ b/lib_enc/ACcontextMapping_enc_fx.c
@@ -7,11 +7,14 @@
#include "options.h"
#include "basop_util.h"
#include "cnst.h"
+#include "prot.h"
#include "prot_fx.h"
#include "ivas_prot_fx.h"
#include "rom_com.h"
#include "ivas_rom_com.h"
+#include "ivas_rom_enc.h"
#include "prot_fx_enc.h"
+#include "ivas_prot.h" /* Range coder header file */
/*-------------------------------------------------------------------*
* ACcontextMapping_encode2_no_mem_s17_LC_fx()
@@ -29,11 +32,11 @@
*/
void ACcontextMapping_encode2_no_mem_s17_LC_fx(
BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
- Word16 *x,
- Word16 nt,
- Word16 lastnz,
- Word16 nbbits,
- Word16 resQMaxBits,
+ Word16 *x, /* Q0 */
+ Word16 nt, /* Q0 */
+ Word16 lastnz, /* Q0 */
+ Word16 nbbits, /* Q0 */
+ Word16 resQMaxBits, /* Q0 */
CONTEXT_HM_CONFIG *hm_cfg )
{
Word16 ptr[BITBUFSIZE];
@@ -57,7 +60,8 @@ void ACcontextMapping_encode2_no_mem_s17_LC_fx(
a1 = 0; /* to avoid compilation warnings */
b1 = 0; /* to avoid compilation warnings */
-
+ move16();
+ move16();
/* Rate flag */
rateFlag = 0;
@@ -75,41 +79,41 @@ void ACcontextMapping_encode2_no_mem_s17_LC_fx(
move16();
/* Bits for encoding the number of encoded tuples */
- nbbits_ntuples = sub( 14, norm_s( negate( nt ) ) );
+ nbbits_ntuples = sub( 14, norm_s( negate( nt ) ) ); /* Q0 */
t = 0;
move16();
- bp = nbbits_ntuples;
+ bp = nbbits_ntuples; /* Q0 */
move16();
nbbits_signs = 0;
move16();
nbbits_lsbs = 0;
move16();
- nbbits_m2 = sub( nbbits, 2 );
+ nbbits_m2 = sub( nbbits, 2 ); /* Q0 */
flag_overflow = 0;
move16();
IF( hm_cfg ) /* mapped domain */
{
- numPeakIndicesOrig = hm_cfg->numPeakIndices;
+ numPeakIndicesOrig = hm_cfg->numPeakIndices; /* Q0 */
move16();
- hm_cfg->numPeakIndices = s_min( hm_cfg->numPeakIndices, lastnz );
+ hm_cfg->numPeakIndices = s_min( hm_cfg->numPeakIndices, lastnz ); /* Q0 */
move16();
- numHoleIndices = sub( lastnz, hm_cfg->numPeakIndices );
+ numHoleIndices = sub( lastnz, hm_cfg->numPeakIndices ); /* Q0 */
/* Mark hole indices beyond lastnz as pruned */
FOR( k = numHoleIndices; k < hm_cfg->numHoleIndices; ++k )
{
- hm_cfg->holeIndices[k] = add( hm_cfg->holeIndices[k], nt );
+ hm_cfg->holeIndices[k] = add( hm_cfg->holeIndices[k], nt ); /* Q0 */
move16();
}
- ii[0] = numPeakIndicesOrig;
+ ii[0] = numPeakIndicesOrig; /* Q0 */
move16();
ii[1] = 0;
move16();
- get_next_coeff = get_next_coeff_mapped;
+ get_next_coeff = get_next_coeff_mapped; /* Q0 */
move16();
}
ELSE /* unmapped domain */
@@ -121,7 +125,7 @@ void ACcontextMapping_encode2_no_mem_s17_LC_fx(
move16();
move16();
- get_next_coeff = get_next_coeff_unmapped;
+ get_next_coeff = get_next_coeff_unmapped; /* Q0 */
move16();
/* Find last non-zero tuple */
@@ -133,7 +137,7 @@ void ACcontextMapping_encode2_no_mem_s17_LC_fx(
WHILE( s_or( x[lastnz - 1], x[lastnz - 2] ) == 0 )
{
- lastnz = sub( lastnz, 2 );
+ lastnz = sub( lastnz, 2 ); /* Q0 */
}
x[0] = a1;
move16();
@@ -150,21 +154,20 @@ void ACcontextMapping_encode2_no_mem_s17_LC_fx(
FOR( k = 0; k < lastnz; k += 2 )
{
/* First coefficient */
- a1_i = get_next_coeff( ii, &p1, &idx1, hm_cfg );
+ a1_i = get_next_coeff( ii, &p1, &idx1, hm_cfg ); /* Q0 */
/* Second coefficient */
- b1_i = get_next_coeff( ii, &p2, &idx2, hm_cfg );
+ b1_i = get_next_coeff( ii, &p2, &idx2, hm_cfg ); /* Q0 */
- idx = s_min( idx1, idx2 );
+ idx = s_min( idx1, idx2 ); /* Q0 */
/* Get context */
- ctx = &c[s_or( p1, p2 )];
- move16();
+ ctx = &c[s_or( p1, p2 )]; /* Q0 */
/* _DIFF_FLOAT_FIX_ float is using t as UWord16 */
- t = add( *ctx, rateFlag );
+ t = add( *ctx, rateFlag ); /* Q0 */
if ( GT_16( idx, nt_half ) )
{
- t = add( t, 1 << NBITS_CONTEXT );
+ t = add( t, 1 << NBITS_CONTEXT ); /* Q0 */
}
/* Init current 2-tuple encoding */
@@ -179,43 +182,43 @@ void ACcontextMapping_encode2_no_mem_s17_LC_fx(
move16();
}
- a1 = abs_s( x[a1_i] );
- b1 = abs_s( x[b1_i] );
+ a1 = abs_s( x[a1_i] ); /* Q0 */
+ b1 = abs_s( x[b1_i] ); /* Q0 */
lev1 = -1;
move16();
/*Copy states*/
ari_copy_states_fx( &as, &as_overflow );
- bp_overflow = bp;
+ bp_overflow = bp; /* Q0 */
move16();
- nbbits_signs_overflow = nbbits_signs;
+ nbbits_signs_overflow = nbbits_signs; /* Q0 */
move16();
- nbbits_lsbs_overflow = nbbits_lsbs;
+ nbbits_lsbs_overflow = nbbits_lsbs; /* Q0 */
move16();
/*Signs encoding*/
- signs[nbbits_signs] = lshr( x[a1_i], 15 );
+ signs[nbbits_signs] = lshr( x[a1_i], 15 ); /* Q0 */
move16();
if ( a1 > 0 )
{
- nbbits_signs = add( nbbits_signs, 1 );
+ nbbits_signs = add( nbbits_signs, 1 ); /* Q0 */
}
- signs[nbbits_signs] = lshr( x[b1_i], 15 );
+ signs[nbbits_signs] = lshr( x[b1_i], 15 ); /* Q0 */
move16();
if ( b1 > 0 )
{
- nbbits_signs = add( nbbits_signs, 1 );
+ nbbits_signs = add( nbbits_signs, 1 ); /* Q0 */
}
/* MSBs coding */
WHILE( GE_16( s_max( a1, b1 ), A_THRES ) )
{
- tmp = add( t, Tab_esc_nb[lev1 + 1] );
+ tmp = add( t, Tab_esc_nb[lev1 + 1] ); /* Q0 */
assert( tmp >= 0 && tmp < 4096 );
- pki = ari_lookup_s17_LC[tmp];
+ pki = ari_lookup_s17_LC[tmp]; /* Q0 */
move16();
- bp = ari_encode_14bits_ext_fx( ptr, bp, &as, VAL_ESC, ari_pk_s17_LC_ext[pki] );
+ bp = ari_encode_14bits_ext_fx( ptr, bp, &as, VAL_ESC, ari_pk_s17_LC_ext[pki] ); /* Q0 */
*lsbs_bits2-- = s_and( a1, 1 );
move16();
@@ -223,32 +226,32 @@ void ACcontextMapping_encode2_no_mem_s17_LC_fx(
move16();
/* LSBs bit counting */
- nbbits_lsbs = add( nbbits_lsbs, 2 );
+ nbbits_lsbs = add( nbbits_lsbs, 2 ); /* Q0 */
a1 = shr( a1, 1 );
b1 = shr( b1, 1 );
- lev1 = s_min( add( lev1, 1 ), 2 );
+ lev1 = s_min( add( lev1, 1 ), 2 ); /* Q0 */
}
- tmp = add( t, Tab_esc_nb[lev1 + 1] );
+ tmp = add( t, Tab_esc_nb[lev1 + 1] ); /* Q0 */
assert( tmp >= 0 && tmp < 4096 );
- pki = ari_lookup_s17_LC[tmp];
+ pki = ari_lookup_s17_LC[tmp]; /* Q0 */
move16();
- bp = ari_encode_14bits_ext_fx( ptr, bp, &as, add( a1, shl( b1, A_THRES_SHIFT ) ), ari_pk_s17_LC_ext[pki] );
+ bp = ari_encode_14bits_ext_fx( ptr, bp, &as, add( a1, shl( b1, A_THRES_SHIFT ) ), ari_pk_s17_LC_ext[pki] ); /* Q0 */
/* Check bit budget */
IF( GT_16( add( add( add( bp, extract_l( as.value ) ), nbbits_signs ), nbbits_lsbs ), nbbits_m2 ) )
{
ari_copy_states_fx( &as_overflow, &as );
- bp = bp_overflow;
+ bp = bp_overflow; /* Q0 */
move16();
IF( flag_overflow == 0 )
{
- nbbits_signs = nbbits_signs_overflow;
+ nbbits_signs = nbbits_signs_overflow; /* Q0 */
move16();
- nbbits_lsbs = nbbits_lsbs_overflow;
+ nbbits_lsbs = nbbits_lsbs_overflow; /* Q0 */
move16();
IF( hm_cfg )
{
@@ -264,14 +267,14 @@ void ACcontextMapping_encode2_no_mem_s17_LC_fx(
move16();
assert( t >= 0 && t < 4096 );
- pki = ari_lookup_s17_LC[t];
+ pki = ari_lookup_s17_LC[t]; /* Q0 */
move16();
- bp = ari_encode_14bits_ext_fx( ptr, bp, &as, 0, ari_pk_s17_LC_ext[pki] );
+ bp = ari_encode_14bits_ext_fx( ptr, bp, &as, 0, ari_pk_s17_LC_ext[pki] ); /* Q0 */
IF( GT_16( add( add( add( bp, extract_l( as.value ) ), nbbits_signs ), nbbits_lsbs ), nbbits_m2 ) )
{
ari_copy_states_fx( &as_overflow, &as );
- bp = bp_overflow;
+ bp = bp_overflow; /* Q0 */
move16();
BREAK;
}
@@ -297,27 +300,27 @@ void ACcontextMapping_encode2_no_mem_s17_LC_fx(
if ( lev1 == 0 )
t = add( t, t );
- *ctx = add( shl( s_and( *ctx, 0xf ), 4 ), add( t, 1 ) );
+ *ctx = add( shl( s_and( *ctx, 0xf ), 4 ), add( t, 1 ) ); /* Q0 */
move16();
}
ELSE /* mixed context */
{
IF( s_and( idx1, 1 ) ) /* update first context */
{
- c[p1] = update_mixed_context( c[p1], abs_s( x[a1_i] ) );
+ c[p1] = update_mixed_context( c[p1], abs_s( x[a1_i] ) ); /* Q0 */
move16();
}
IF( s_and( idx2, 1 ) ) /* update second context */
{
- c[p2] = update_mixed_context( c[p2], abs_s( x[b1_i] ) );
+ c[p2] = update_mixed_context( c[p2], abs_s( x[b1_i] ) ); /* Q0 */
move16();
}
}
} /*end of the 2-tuples loop*/
/* End arithmetic coder, overflow management */
- bp = ari_done_encoding_14bits_fx( ptr, bp, &as );
+ bp = ari_done_encoding_14bits_fx( ptr, bp, &as ); /* Q0 */
/* Overflow is detected */
IF( NE_16( k, lastnz ) )
@@ -325,20 +328,20 @@ void ACcontextMapping_encode2_no_mem_s17_LC_fx(
IF( hm_cfg )
{
/* Fill with zero to be sure that the decoder finishes the MSB decoding at the same position */
- tmp = sub( nbbits, add( nbbits_signs, nbbits_lsbs ) );
+ tmp = sub( nbbits, add( nbbits_signs, nbbits_lsbs ) ); /* Q0 */
set16_fx( &ptr[bp], 0, sub( tmp, bp ) );
bp = tmp;
move16();
}
if ( !hm_cfg )
{
- lastnz = k;
+ lastnz = k; /* Q0 */
move16();
}
}
/* Push number of encoded tuples */
- value = sub( shr( lastnz, 1 ), 1 );
+ value = sub( shr( lastnz, 1 ), 1 ); /* Q0 */
push_next_indice_fx( hBstr, value, nbbits_ntuples );
/* Push arithmetic coded bits */
@@ -346,17 +349,17 @@ void ACcontextMapping_encode2_no_mem_s17_LC_fx(
/* Push sign bits */
push_next_bits_fx( hBstr, signs, nbbits_signs );
- bp = add( bp, nbbits_signs );
+ bp = add( bp, nbbits_signs ); /* Q0 */
/*write residual Quantization bits*/
- tmp = s_min( sub( sub( nbbits, bp ), nbbits_lsbs ), resQMaxBits );
+ tmp = s_min( sub( sub( nbbits, bp ), nbbits_lsbs ), resQMaxBits ); /* Q0 */
FOR( k = 0; k < tmp; k++ )
{
- ptr[nbbits - 1 - nbbits_lsbs - k] = x[nt + k];
+ ptr[nbbits - 1 - nbbits_lsbs - k] = x[nt + k]; /* Q0 */
move16();
}
/* Write filler bits */
- tmp = sub( nbbits, add( bp, nbbits_lsbs ) );
+ tmp = sub( nbbits, add( bp, nbbits_lsbs ) ); /* Q0 */
FOR( ; k < tmp; ++k )
{
ptr[nbbits - 1 - nbbits_lsbs - k] = 0;
@@ -378,7 +381,7 @@ void ACcontextMapping_encode2_no_mem_s17_LC_fx(
*
*-------------------------------------------------------------------*/
static Word16 find_last_nz_pair(
- const Word16 x[],
+ const Word16 x[], /* Q0 */
Word16 length,
const CONTEXT_HM_CONFIG *hm_cfg )
{
@@ -387,7 +390,7 @@ static Word16 find_last_nz_pair(
if ( hm_cfg )
{
- tmp = hm_cfg->indexBuffer;
+ tmp = hm_cfg->indexBuffer; /* Q0 */
move16();
}
@@ -395,9 +398,9 @@ static Word16 find_last_nz_pair(
move16();
lobs[1] = shr( length, 1 ); /* length/2 */
move16();
- lobs[2] = add( lobs[1], shr( length, 2 ) );
+ lobs[2] = add( lobs[1], shr( length, 2 ) ); /* Q0 */
move16();
- lobs[3] = add( lobs[2], shr( length, 3 ) );
+ lobs[3] = add( lobs[2], shr( length, 3 ) ); /* Q0 */
move16();
last_nz = 0;
@@ -412,11 +415,11 @@ static Word16 find_last_nz_pair(
{
if ( x[tmp[i - 2]] != 0 )
{
- last_nz = s_max( last_nz, i );
+ last_nz = s_max( last_nz, i ); /* Q0 */
}
if ( x[tmp[i - 1]] != 0 )
{
- last_nz = s_max( last_nz, i );
+ last_nz = s_max( last_nz, i ); /* Q0 */
}
}
}
@@ -426,11 +429,11 @@ static Word16 find_last_nz_pair(
{
if ( x[i - 2] != 0 )
{
- last_nz = s_max( last_nz, i );
+ last_nz = s_max( last_nz, i ); /* Q0 */
}
if ( x[i - 1] != 0 )
{
- last_nz = s_max( last_nz, i );
+ last_nz = s_max( last_nz, i ); /* Q0 */
}
}
}
@@ -448,12 +451,12 @@ static Word16 find_last_nz_pair(
*
*-------------------------------------------------------------------*/
Word16 ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx(
- const Word16 *x,
- Word16 nt,
- Word16 *lastnz_out,
- Word16 *nEncoded,
- Word16 target,
- Word16 *stop,
+ const Word16 *x, /* Q0 */
+ Word16 nt, /* Q0 */
+ Word16 *lastnz_out, /* Q0 */
+ Word16 *nEncoded, /* Q0 */
+ Word16 target, /* Q0 */
+ Word16 *stop, /* Q0 */
CONTEXT_HM_CONFIG *hm_cfg )
{
Word16 a1, b1, a1_i, b1_i;
@@ -473,6 +476,8 @@ Word16 ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx(
Word16 p1, p2;
Word16 ii[2], idx1, idx2, idx;
Word16 numPeakIndicesOrig = 0, numHoleIndices = 0; /* initialize just to avoid compiler warning */
+ move16();
+ move16();
get_next_coeff_function get_next_coeff;
@@ -481,12 +486,12 @@ Word16 ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx(
move16();
if ( GT_16( target, 400 ) )
{
- rateFlag = 2 << NBITS_CONTEXT;
+ rateFlag = 2 << NBITS_CONTEXT; /* Q0 */
move16();
}
/* proba coded on 14bits -> proba=1 */
- proba = L_deposit_l( 16384 );
+ proba = L_deposit_l( 16384 ); /* Q0 */
/* Init */
nt_half = shr( nt, 1 );
@@ -497,13 +502,13 @@ Word16 ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx(
move16();
/* bits to encode lastnz + 2 bits headroom */
- nbits = sub( 2 + 14, norm_s( sub( nt, 1 ) ) );
- nbits_old = nbits;
+ nbits = sub( 2 + 14, norm_s( sub( nt, 1 ) ) ); /* Q0 */
+ nbits_old = nbits; /* Q0 */
move16();
- nbits = sub( nbits, target );
+ nbits = sub( nbits, target ); /* Q0 */
/* Find last non-zero tuple in the mapped domain signal */
- lastnz = find_last_nz_pair( x, nt, hm_cfg );
+ lastnz = find_last_nz_pair( x, nt, hm_cfg ); /* Q0 */
/* At least one tuple is coded */
lastnz2 = 2;
@@ -511,25 +516,25 @@ Word16 ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx(
IF( hm_cfg ) /* mapped domain */
{
- numPeakIndicesOrig = hm_cfg->numPeakIndices;
+ numPeakIndicesOrig = hm_cfg->numPeakIndices; /* Q0 */
move16();
- hm_cfg->numPeakIndices = s_min( hm_cfg->numPeakIndices, lastnz );
+ hm_cfg->numPeakIndices = s_min( hm_cfg->numPeakIndices, lastnz ); /* Q0 */
move16();
- numHoleIndices = sub( lastnz, hm_cfg->numPeakIndices );
+ numHoleIndices = sub( lastnz, hm_cfg->numPeakIndices ); /* Q0 */
/* Mark hole indices beyond lastnz as pruned */
FOR( k = numHoleIndices; k < hm_cfg->numHoleIndices; ++k )
{
- hm_cfg->holeIndices[k] = add( hm_cfg->holeIndices[k], nt );
+ hm_cfg->holeIndices[k] = add( hm_cfg->holeIndices[k], nt ); /* Q0 */
move16();
}
- ii[0] = numPeakIndicesOrig;
+ ii[0] = numPeakIndicesOrig; /* Q0 */
move16();
ii[1] = 0;
move16();
- get_next_coeff = get_next_coeff_mapped;
+ get_next_coeff = get_next_coeff_mapped; /* Q0 */
move16();
}
ELSE /* unmapped domain */
@@ -541,7 +546,7 @@ Word16 ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx(
move16();
move16();
- get_next_coeff = get_next_coeff_unmapped;
+ get_next_coeff = get_next_coeff_unmapped; /* Q0 */
move16();
}
@@ -549,38 +554,37 @@ Word16 ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx(
FOR( k = 0; k < lastnz; k += 2 )
{
/* First coefficient */
- a1_i = get_next_coeff( ii, &p1, &idx1, hm_cfg );
+ a1_i = get_next_coeff( ii, &p1, &idx1, hm_cfg ); /* Q0 */
/* Second coefficient */
- b1_i = get_next_coeff( ii, &p2, &idx2, hm_cfg );
+ b1_i = get_next_coeff( ii, &p2, &idx2, hm_cfg ); /* Q0 */
- idx = s_min( idx1, idx2 );
+ idx = s_min( idx1, idx2 ); /* Q0 */
/* Get context */
- ctx = &c[s_or( p1, p2 )];
- move16();
+ ctx = &c[s_or( p1, p2 )]; /* Q0 */
- t = add( *ctx, rateFlag );
+ t = add( *ctx, rateFlag ); /* Q0 */
if ( GT_16( idx, nt_half ) )
{
- t = add( t, 1 << NBITS_CONTEXT );
+ t = add( t, 1 << NBITS_CONTEXT ); /* Q0 */
}
/* Init current 2-tuple encoding */
- a1 = abs_s( x[a1_i] );
- b1 = abs_s( x[b1_i] );
+ a1 = abs_s( x[a1_i] ); /* Q0 */
+ b1 = abs_s( x[b1_i] ); /* Q0 */
lev1 = -( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) );
move16();
/* Signs Bits */
if ( a1 > 0 )
{
- nbits = add( nbits, 1 );
+ nbits = add( nbits, 1 ); /* Q0 */
}
if ( b1 > 0 )
{
- nbits = add( nbits, 1 );
+ nbits = add( nbits, 1 ); /* Q0 */
}
/* pre-compute address of ari_pk_s17_LC_ext[0][Val_esc] to avoid doing it multiple times inside the loop */
@@ -599,38 +603,38 @@ Word16 ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx(
cum_freq_norm_e = norm_s( cum_freq[0] );
cum_freq_norm = shl( cum_freq[0], cum_freq_norm_e );
proba = Mpy_32_16_1( proba, cum_freq_norm );
- proba = L_shl( proba, sub( 14, cum_freq_norm_e ) );
+ proba = L_shl( proba, sub( 14, cum_freq_norm_e ) ); /* Q14 + cum_freq_norm_e */
/*Number of leading zero computed in one cycle=norm_l() in BASOP*/
nlz = sub( norm_l( proba ), 2 );
- proba = L_shl( proba, sub( nlz, 15 ) );
+ proba = L_shl( proba, sub( nlz, 15 ) ); /* cum_freq_norm_e */
- nbits = add( nbits, nlz );
+ nbits = add( nbits, nlz ); /* Q0 */
/*addition added as shift not done in norm_l(): real shift = 14-nlz*/
/*proba is rounded down on 14 bits ->automatic over-estimation of bit consumption*/
a1 = shr( a1, 1 );
b1 = shr( b1, 1 );
- lev1 = s_min( add( lev1, 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ), 2 << ( NBITS_CONTEXT + NBITS_RATEQ ) );
+ lev1 = s_min( add( lev1, 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ), 2 << ( NBITS_CONTEXT + NBITS_RATEQ ) ); /* Q0 */
}
- pki = lookup[lev1];
+ pki = lookup[lev1]; /* Q0 */
move16();
- symbol = add( a1, shl( b1, A_THRES_SHIFT ) );
- cum_freq = ari_pk_s17_LC_ext[pki] + symbol; /* address calculation not counted */
+ symbol = add( a1, shl( b1, A_THRES_SHIFT ) ); /* Q0 */
+ cum_freq = ari_pk_s17_LC_ext[pki] + symbol; /* address calculation not counted */
/*p1*p2=proba on 28 bits: p=0.5->power(2,27)*/
cum_freq_norm = sub( cum_freq[0], cum_freq[1] );
cum_freq_norm_e = norm_s( cum_freq_norm );
cum_freq_norm = shl( cum_freq_norm, cum_freq_norm_e );
proba = Mpy_32_16_1( proba, cum_freq_norm );
- proba = L_shl( proba, sub( 15, cum_freq_norm_e ) );
+ proba = L_shl( proba, sub( 15, cum_freq_norm_e ) ); /* Q15 + cum_freq_norm_e */
/*Number of leading zero computed in one cycle=norm_l() in BASOP*/
nlz = sub( norm_l( proba ), 3 );
- proba = L_shl( proba, sub( nlz, 14 ) );
+ proba = L_shl( proba, sub( nlz, 14 ) ); /* cum_freq_norm_e */
- nbits = add( nbits, nlz );
+ nbits = add( nbits, nlz ); /* Q0 */
/*addition added as shift not done in norm_l(): real shift = 14-nlz*/
/*proba is rounded down on 14 bits ->automatic over-estimation of bit consumption*/
@@ -652,15 +656,15 @@ Word16 ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx(
test();
IF( hm_cfg || k == 0 || s_or( x[a1_i], x[b1_i] ) )
{
- nbits_old = add( nbits, target );
- lastnz2 = add( b1_i, 1 );
+ nbits_old = add( nbits, target ); /* Q0 */
+ lastnz2 = add( b1_i, 1 ); /* Q0 */
}
}
/* Update context for next 2-tuple */
IF( EQ_16( p1, p2 ) ) /* peak-peak or hole-hole context */
{
- lev1 = shr( lev1, NBITS_CONTEXT + NBITS_RATEQ );
+ lev1 = shr( lev1, NBITS_CONTEXT + NBITS_RATEQ ); /* Q0 */
if ( lev1 > 0 )
t = add( 12, lev1 );
if ( lev1 <= 0 )
@@ -668,46 +672,46 @@ Word16 ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx(
if ( lev1 == 0 )
t = add( t, t );
- *ctx = add( shl( s_and( *ctx, 0xf ), 4 ), add( t, 1 ) );
+ *ctx = add( shl( s_and( *ctx, 0xf ), 4 ), add( t, 1 ) ); /* Q0 */
move16();
}
ELSE /* mixed context */
{
IF( s_and( idx1, 1 ) ) /* update first context */
{
- c[p1] = update_mixed_context( c[p1], abs_s( x[a1_i] ) );
+ c[p1] = update_mixed_context( c[p1], abs_s( x[a1_i] ) ); /* Q0 */
move16();
}
IF( s_and( idx2, 1 ) ) /* update second context */
{
- c[p2] = update_mixed_context( c[p2], abs_s( x[b1_i] ) );
+ c[p2] = update_mixed_context( c[p2], abs_s( x[b1_i] ) ); /* Q0 */
move16();
}
}
} /* end of the 2-tuples loop */
- nbits = add( nbits, target );
+ nbits = add( nbits, target ); /* Q0 */
/* Output */
if ( *stop )
{
- nbits = nbits_old;
+ nbits = nbits_old; /* Q0 */
move16();
}
if ( stop2 )
{
- stop2 = nbits;
+ stop2 = nbits; /* Q0 */
move16();
}
- *nEncoded = lastnz2;
+ *nEncoded = lastnz2; /* Q0 */
move16();
- *stop = stop2;
+ *stop = stop2; /* Q0 */
move16();
if ( lastnz_out )
{
- *lastnz_out = lastnz;
+ *lastnz_out = lastnz; /* Q0 */
move16();
}
@@ -716,10 +720,10 @@ Word16 ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx(
/* Restore hole indices beyond lastnz */
FOR( k = numHoleIndices; k < hm_cfg->numHoleIndices; ++k )
{
- hm_cfg->holeIndices[k] = sub( hm_cfg->holeIndices[k], nt );
+ hm_cfg->holeIndices[k] = sub( hm_cfg->holeIndices[k], nt ); /* Q0 */
move16();
}
- hm_cfg->numPeakIndices = numPeakIndicesOrig;
+ hm_cfg->numPeakIndices = numPeakIndicesOrig; /* Q0 */
move16();
}
@@ -736,12 +740,12 @@ Word16 ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx(
*-------------------------------------------------------------------*/
void RCcontextMapping_encode2_no_mem_s17_LCS_fx(
- BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
- Word16 *x,
- const Word16 nt,
- Word16 lastnz,
- const Word16 nbbits,
- const Word16 resQMaxBits,
+ BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
+ Word16 *x, /* Q0 */
+ const Word16 nt, /* Q0 */
+ Word16 lastnz, /* Q0 */
+ const Word16 nbbits, /* Q0 */
+ const Word16 resQMaxBits, /* Q0 */
CONTEXT_HM_CONFIG *hm_cfg )
{
Word16 ptr[BITBUFSIZE];
@@ -760,6 +764,8 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx(
a1 = 0; /* to avoid compilation warnings */
b1 = 0; /* to avoid compilation warnings */
+ move16();
+ move16();
/* Init */
nt_half = shr( nt, 1 );
@@ -772,7 +778,7 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx(
WHILE( LT_16( k, shr( nt, 1 ) ) )
{
- nbbits_ntuples = add( nbbits_ntuples, 1 );
+ nbbits_ntuples = add( nbbits_ntuples, 1 ); /* Q0 */
k = shl( k, 1 );
}
@@ -809,20 +815,20 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx(
move32();
/* mapped domain */
- numPeakIndicesOrig = hm_cfg->numPeakIndices;
- hm_cfg->numPeakIndices = s_min( hm_cfg->numPeakIndices, lastnz );
- numHoleIndices = sub( lastnz, hm_cfg->numPeakIndices );
+ numPeakIndicesOrig = hm_cfg->numPeakIndices; /* Q0 */
+ hm_cfg->numPeakIndices = s_min( hm_cfg->numPeakIndices, lastnz ); /* Q0 */
+ numHoleIndices = sub( lastnz, hm_cfg->numPeakIndices ); /* Q0 */
move16();
move16();
/* Mark hole indices beyond lastnz as pruned */
FOR( k = numHoleIndices; k < hm_cfg->numHoleIndices; ++k )
{
- hm_cfg->holeIndices[k] = add( hm_cfg->holeIndices[k], nt );
+ hm_cfg->holeIndices[k] = add( hm_cfg->holeIndices[k], nt ); /* Q0 */
move16();
}
- ii[0] = numPeakIndicesOrig;
+ ii[0] = numPeakIndicesOrig; /* Q0 */
ii[1] = 0;
move16();
move16();
@@ -843,15 +849,15 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx(
FOR( k = 0; k < lastnz; k += 2 )
{
- a1_i = get_next_coeff_mapped_ivas_fx( ii, &p1, &idx1, hm_cfg );
- b1_i = get_next_coeff_mapped_ivas_fx( ii, &p2, &idx2, hm_cfg );
+ a1_i = get_next_coeff_mapped_ivas_fx( ii, &p1, &idx1, hm_cfg ); /* Q0 */
+ b1_i = get_next_coeff_mapped_ivas_fx( ii, &p2, &idx2, hm_cfg ); /* Q0 */
- idx = s_min( idx1, idx2 );
+ idx = s_min( idx1, idx2 ); /* Q0 */
/* Get context */
- ctx = &c[L_or( p1, p2 )];
+ ctx = &c[L_or( p1, p2 )]; /* Q0 */
- t = (UWord16) L_add( *ctx, rateFlag );
+ t = (UWord16) L_add( *ctx, rateFlag ); /* Q0 */
// t += ( nt_half >= idx ) ? 0 : ( 1 << NBITS_CONTEXT );
IF( LT_16( nt_half, idx ) )
{
@@ -859,8 +865,8 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx(
}
/* Init current 2-tuple encoding */
- a1 = abs_s( x[a1_i] );
- b1 = abs_s( x[b1_i] );
+ a1 = abs_s( x[a1_i] ); /* Q0 */
+ b1 = abs_s( x[b1_i] ); /* Q0 */
lev1 = -1;
move16();
@@ -879,7 +885,7 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx(
signs[nbbits_signs] = 1;
move16();
}
- nbbits_signs = add( nbbits_signs, 1 );
+ nbbits_signs = add( nbbits_signs, 1 ); /* Q0 */
}
IF( b1 > 0 )
@@ -895,13 +901,13 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx(
signs[nbbits_signs] = 1;
move16();
}
- nbbits_signs = add( nbbits_signs, 1 );
+ nbbits_signs = add( nbbits_signs, 1 ); /* Q0 */
}
/* MSBs coding */
WHILE( GE_16( s_max( a1, b1 ), A_THRES ) )
{
- pki = ari_lookup_s17_LC[t + ( ( lev1 + 1 ) << ( NBITS_CONTEXT + NBITS_RATEQ ) )];
+ pki = ari_lookup_s17_LC[t + ( ( lev1 + 1 ) << ( NBITS_CONTEXT + NBITS_RATEQ ) )]; /* Q0 */
move16();
rc_uni_enc_encode_symbol_fastS( &rc_st_enc, VAL_ESC, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 14 ); /* Encode ESC symbol */
@@ -911,15 +917,15 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx(
move16();
/* LSBs bit counting */
- nbbits_lsbs = add( nbbits_lsbs, 2 );
+ nbbits_lsbs = add( nbbits_lsbs, 2 ); /* Q0 */
a1 = shr( a1, 1 );
b1 = shr( b1, 1 );
- lev1 = s_min( add( lev1, 1 ), 2 );
+ lev1 = s_min( add( lev1, 1 ), 2 ); /* Q0 */
}
- pki = ari_lookup_s17_LC[t + ( ( lev1 + 1 ) << ( NBITS_CONTEXT + NBITS_RATEQ ) )];
+ pki = ari_lookup_s17_LC[t + ( ( lev1 + 1 ) << ( NBITS_CONTEXT + NBITS_RATEQ ) )]; /* Q0 */
move16();
rc_uni_enc_encode_symbol_fastS( &rc_st_enc, a1 + A_THRES * b1, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 14 ); /* Encode MSB symbol */
@@ -932,14 +938,14 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx(
IF( lev1 <= 0 )
{
- t = (UWord16) L_add( 1, L_mult0( add( a1, b1 ), add( lev1, 2 ) ) );
+ t = (UWord16) L_add( 1, L_mult0( add( a1, b1 ), add( lev1, 2 ) ) ); /* Q0 */
}
ELSE
{
- t = (UWord16) L_add( 13, lev1 );
+ t = (UWord16) L_add( 13, lev1 ); /* Q0 */
}
- *ctx = L_add( L_shl( L_and( *ctx, 0xf ), 4 ), t );
+ *ctx = L_add( L_shl( L_and( *ctx, 0xf ), 4 ), t ); /* Q0 */
move32();
}
ELSE
@@ -949,14 +955,14 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx(
IF( s_and( idx1, 1 ) )
{
/* update first context */
- c[p1] = update_mixed_context_ivas_fx( c[p1], abs_s( x[a1_i] ) );
+ c[p1] = update_mixed_context_ivas_fx( c[p1], abs_s( x[a1_i] ) ); /* Q0 */
move32();
}
IF( s_and( idx2, 1 ) )
{
/* update second context */
- c[p2] = update_mixed_context_ivas_fx( c[p2], abs_s( x[b1_i] ) );
+ c[p2] = update_mixed_context_ivas_fx( c[p2], abs_s( x[b1_i] ) ); /* Q0 */
move32();
}
}
@@ -994,7 +1000,7 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx(
WHILE( x[lastnz - 1] == 0 && x[lastnz - 2] == 0 )
{
test();
- lastnz = sub( lastnz, 2 );
+ lastnz = sub( lastnz, 2 ); /* Q0 */
}
x[0] = a1;
move16();
@@ -1010,8 +1016,8 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx(
{
/* Init current 2-tuple encoding */
- a1 = abs_s( x[k + 0] );
- b1 = abs_s( x[k + 1] );
+ a1 = abs_s( x[k + 0] ); /* Q0 */
+ b1 = abs_s( x[k + 1] ); /* Q0 */
lev1 = 0;
esc_nb = 0;
@@ -1032,7 +1038,7 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx(
signs[nbbits_signs] = 1;
move16();
}
- nbbits_signs = add( nbbits_signs, 1 );
+ nbbits_signs = add( nbbits_signs, 1 ); /* Q0 */
}
IF( b1 > 0 )
@@ -1048,10 +1054,10 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx(
signs[nbbits_signs] = 1;
move16();
}
- nbbits_signs = add( nbbits_signs, 1 );
+ nbbits_signs = add( nbbits_signs, 1 ); /* Q0 */
}
- rateQ = add( rateFlag, (Word16) GT_16( k, shr( nt, 1 ) ) );
+ rateQ = add( rateFlag, extract_l( GT_16( k, shr( nt, 1 ) ) ) );
/* MSBs coding */
WHILE( GE_16( s_max( a1, b1 ), A_THRES ) )
@@ -1066,17 +1072,17 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx(
move16();
/* LSBs bit counting */
- nbbits_lsbs = add( nbbits_lsbs, 2 );
+ nbbits_lsbs = add( nbbits_lsbs, 2 ); /* Q0 */
a1 = shr( a1, 1 );
b1 = shr( b1, 1 );
- lev1 = add( lev1, 1 );
- esc_nb = s_min( lev1, 3 );
+ lev1 = add( lev1, 1 ); /* Q0 */
+ esc_nb = s_min( lev1, 3 ); /* Q0 */
}
move16();
- pki = ari_lookup_s17_LC[t + ( ( rateQ ) << NBITS_CONTEXT ) + ( esc_nb << ( NBITS_CONTEXT + NBITS_RATEQ ) )];
+ pki = ari_lookup_s17_LC[t + ( ( rateQ ) << NBITS_CONTEXT ) + ( esc_nb << ( NBITS_CONTEXT + NBITS_RATEQ ) )]; /* Q0 */
rc_uni_enc_encode_symbol_fastS( &rc_st_enc, a1 + A_THRES * b1, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 14 ); /* Encode MSB symbol */
/*Confirm that there is no overflow, i.e. bit-budget has not exceeded */
@@ -1084,11 +1090,11 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx(
/* Update context for next 2-tuple */
IF( LT_16( esc_nb, 2 ) )
{
- cp = add( 1, imult1616( add( a1, b1 ), add( esc_nb, 1 ) ) );
+ cp = add( 1, imult1616( add( a1, b1 ), add( esc_nb, 1 ) ) ); /* Q0 */
}
ELSE
{
- cp = add( 12, esc_nb );
+ cp = add( 12, esc_nb ); /* Q0 */
}
/*Shift old 4 bits, replace last 4 bits*/
@@ -1099,13 +1105,13 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx(
}
/* Finish range encoder */
- rc_tot_bits = rc_uni_enc_finish( &rc_st_enc ); /* No. of bits consumed by range coder */
- bp = add( rc_tot_bits, nbbits_ntuples ); /* Update bitstream pointer */
+ rc_tot_bits = rc_uni_enc_finish( &rc_st_enc ); /* No. of bits consumed by range coder Q0*/
+ bp = add( rc_tot_bits, nbbits_ntuples ); /* Update bitstream pointer Q0*/
/* Cross-check that there is no overflow */
/* Push number of encoded tuples */
- value = sub( shr( lastnz, 1 ), 1 );
+ value = sub( shr( lastnz, 1 ), 1 ); /* Q0 */
push_next_indice( hBstr, value, nbbits_ntuples );
/* Push range coded bits from byte_buffer to bitstream */
@@ -1122,13 +1128,13 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx(
/* Push sign bits */
push_next_bits( hBstr, (UWord16 *) signs, nbbits_signs );
- bp = add( bp, nbbits_signs );
+ bp = add( bp, nbbits_signs ); /* Q0 */
/*write residual Quantization bits*/
FOR( k = 0; k < s_min( nbbits - bp - nbbits_lsbs, resQMaxBits ); k++ )
{
- ptr[nbbits - 1 - nbbits_lsbs - k] = x[nt + k];
+ ptr[nbbits - 1 - nbbits_lsbs - k] = x[nt + k]; /* Q0 */
move16();
}
/* Write filler bits */
@@ -1148,6 +1154,692 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx(
return;
}
+/*-------------------------------------------------------------------*
+ * find_last_nz_pair_fx()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+static Word16 find_last_nz_pair_fx(
+ const Word16 x[], /* Q0 */
+ const Word16 length,
+ const CONTEXT_HM_CONFIG *hm_cfg )
+{
+ Word16 last_nz, i;
+ const Word16 *tmp;
+
+ last_nz = 2;
+ move16();
+
+ IF( hm_cfg )
+ {
+ /* mapped kernel */
+ tmp = hm_cfg->indexBuffer;
+
+ FOR( i = length; i >= 4; i -= 2 )
+ {
+ test();
+ IF( x[tmp[i - 2]] || x[tmp[i - 1]] )
+ {
+ last_nz = i; /* Q0 */
+ move16();
+ BREAK;
+ }
+ }
+ }
+ ELSE
+ {
+ /* unmapped kernel */
+
+ FOR( i = length; i >= 4; i -= 2 )
+ {
+ test();
+ IF( x[i - 2] || x[i - 1] )
+ {
+ last_nz = i; /* Q0 */
+ move16();
+ BREAK;
+ }
+ }
+ }
+
+ return last_nz;
+}
+
+
+/*-------------------------------------------------------------------*
+ * RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx()
+ *
+ * Range coder bit-estimation
+ *-------------------------------------------------------------------*/
+
+Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx(
+ Word16 *x, /* Spectral coefficients Q0*/
+ const Word16 nt, /* L - size of spectrum (no. of spectral coefficients) Q0*/
+ Word16 *lastnz_out, /* Q0 */
+ Word16 *nEncoded, /* No. of spectral coefficients that can be coded without an overflow occuring Q0*/
+ const Word16 target, /* Target bits Q0*/
+ Word16 *stop, /* Q0 */
+ Word16 mode, /* Q0 */
+ CONTEXT_HM_CONFIG *hm_cfg /* context-based harmonic model configuration */
+)
+{
+ /* Common variables */
+ Word16 a1, b1;
+ Word16 k, pki, lev1;
+ UWord16 t;
+ Word16 lastnz, lastnz2;
+ Word16 rateFlag;
+ Word32 bit_estimate_fx;
+ Word16 bit_estimate_e;
+ Word16 symbol;
+ const UWord8 *lookup;
+ Word32 nbits2_fx; // Q23
+ Word16 nbits2_e;
+
+ /* Initialization */
+ bit_estimate_fx = 2 * ONE_IN_Q29;
+ bit_estimate_e = 2;
+ move32();
+ move16();
+
+ nbits2_fx = 0;
+ nbits2_e = 0;
+ move32();
+ move16();
+
+ /* bits to encode lastnz */
+ k = 1;
+ move16();
+
+ WHILE( LT_16( k, nt / 2 ) )
+ {
+ bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, ONE_IN_Q30, 1, &bit_estimate_e );
+ k = k << 1;
+ /* check while condition */
+ }
+
+ nbits2_fx = bit_estimate_fx; /* exp(bit_estimate_e) */
+ nbits2_e = bit_estimate_e;
+ move32();
+ move16();
+
+ IF( hm_cfg )
+ {
+ Word16 a1_i, b1_i;
+ Word16 stop2;
+ Word16 total_output_bits;
+ Word16 nt_half;
+ Word32 c[2], *ctx;
+ Word32 p1, p2;
+ Word16 ii[2];
+ Word16 idx1, idx2, idx;
+ Word16 numPeakIndicesOrig = 0, numHoleIndices = 0; /* only to avoid compiler warning */
+ move16();
+ move16();
+
+ /* Rate flag */
+ IF( GT_16( target, 400 ) )
+ {
+ rateFlag = 2 << NBITS_CONTEXT; /* Select context-A for higher bitrates */
+ move16();
+ }
+ ELSE
+ {
+ rateFlag = 0; /* Select context-B for lower bitrates */
+ move16();
+ }
+
+ nt_half = shr( nt, 1 );
+ move16();
+ stop2 = 0;
+ move16();
+ c[0] = c[1] = 0;
+ move32();
+ move32();
+
+ /* Find last non-zero tuple in the mapped domain signal */
+ lastnz = find_last_nz_pair_fx( x, nt, hm_cfg );
+
+ lastnz2 = 2;
+ move16();
+
+ /* mapped domain */
+ numPeakIndicesOrig = hm_cfg->numPeakIndices; /* Q0 */
+ move16();
+ hm_cfg->numPeakIndices = s_min( hm_cfg->numPeakIndices, lastnz ); /* Q0 */
+ move16();
+ numHoleIndices = sub( lastnz, hm_cfg->numPeakIndices ); /* Q0 */
+
+ /* Mark hole indices beyond lastnz as pruned */
+ FOR( k = numHoleIndices; k < hm_cfg->numHoleIndices; ++k )
+ {
+ hm_cfg->holeIndices[k] = add( hm_cfg->holeIndices[k], nt ); /* Q0 */
+ move16();
+ }
+
+ ii[0] = numPeakIndicesOrig; /* Q0 */
+ move16();
+ ii[1] = 0;
+ move16();
+
+ p1 = p2 = 0; /* to avoid compilation warnings */
+ move32();
+ move32();
+
+ /* Main Loop through the 2-tuples */
+ FOR( k = 0; k < lastnz; k += 2 )
+ {
+ a1_i = get_next_coeff_mapped_ivas_fx( ii, &p1, &idx1, hm_cfg ); /* Q0 */
+ b1_i = get_next_coeff_mapped_ivas_fx( ii, &p2, &idx2, hm_cfg ); /* Q0 */
+
+ idx = s_min( idx1, idx2 );
+
+ /* Get context */
+ ctx = &c[L_or( p1, p2 )];
+
+ t = (UWord16) L_add( *ctx, rateFlag );
+ IF( LT_16( nt_half, idx ) )
+ {
+ t = add( t, ( 1 << NBITS_CONTEXT ) );
+ }
+
+ /* Init current 2-tuple encoding */
+ a1 = (Word16) abs( x[a1_i] );
+ b1 = (Word16) abs( x[b1_i] );
+ lev1 = -( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) );
+
+ bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, s_min( a1, 1 ) * ONE_IN_Q30, 1, &bit_estimate_e ); /* exp(bit_estimate_e) */
+ bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, s_min( b1, 1 ) * ONE_IN_Q30, 1, &bit_estimate_e ); /* exp(bit_estimate_e) */
+
+ /* pre-compute address of ari_pk_s17_LC_ext[0][Val_esc] to avoid doing it multiple times inside the loop */
+ lookup = &ari_lookup_s17_LC[t] + ( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) );
+
+ /* check while condition */
+ /* MSBs coding */
+ WHILE( GE_16( s_max( a1, b1 ), A_THRES ) )
+ {
+ pki = lookup[lev1]; /* ESC symbol */
+
+ bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC], 8, &bit_estimate_e ); /* exp(bit_estimate_e) */
+ bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, 2 * ONE_IN_Q29, 2, &bit_estimate_e ); /* Add 2 LSB bits corresponding to the bit-plane exp(bit_estimate_e) */
+
+ a1 = shr( a1, 1 );
+ b1 = shr( b1, 1 );
+
+ lev1 = s_min( add( lev1, ( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ) ), 2 << ( NBITS_CONTEXT + NBITS_RATEQ ) );
+
+ /* check while condition */
+ }
+
+ pki = lookup[lev1];
+
+ symbol = add( a1, i_mult( A_THRES, b1 ) ); /* Q0 */
+ bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][symbol], 8, &bit_estimate_e ); /* exp(bit_estimate_e) */
+
+ /* Should we truncate? */
+ IF( GT_32( L_shr( bit_estimate_fx, sub( Q16, bit_estimate_e ) ), L_shl( target, Q15 ) ) )
+ {
+ stop2 = 1;
+ move16();
+
+ IF( *stop )
+ {
+ BREAK;
+ }
+ }
+ ELSE
+ {
+ lastnz2 = add( b1_i, 1 );
+ nbits2_fx = bit_estimate_fx;
+ move32();
+ nbits2_e = bit_estimate_e;
+ move16();
+ }
+
+ /* Update context for next 2-tuple */
+ IF( EQ_32( p1, p2 ) ) /* peak-peak or hole-hole context */
+ {
+ lev1 = shr( lev1, NBITS_CONTEXT + NBITS_RATEQ );
+
+ IF( lev1 <= 0 )
+ {
+ t = add( 1, i_mult( add( a1, b1 ), add( lev1, 2 ) ) );
+ }
+ ELSE
+ {
+ t = add( 13, lev1 );
+ }
+
+ *ctx = L_add( imult3216( L_and( *ctx, 0xf ), 16 ), t );
+ move32();
+ }
+ ELSE
+ {
+ /* mixed context */
+
+ IF( s_and( idx1, 1 ) )
+ {
+ /* update first context */
+ c[p1] = update_mixed_context_ivas_fx( c[p1], abs_s( x[a1_i] ) ); /* Q0 */
+ move32();
+ }
+
+ IF( s_and( idx2, 1 ) )
+ {
+ /* update second context */
+ c[p2] = update_mixed_context_ivas_fx( c[p2], abs_s( x[b1_i] ) ); /* Q0 */
+ move32();
+ }
+ }
+
+ } /*end of the 2-tuples loop*/
+
+ total_output_bits = round_fx( L_shr( bit_estimate_fx, sub( Q15, bit_estimate_e ) ) ); /* Q0 */
+
+ IF( *stop )
+ {
+ total_output_bits = round_fx( L_shr( nbits2_fx, sub( Q15, nbits2_e ) ) ); /* Q0 */
+ }
+
+ IF( stop2 )
+ {
+ stop2 = total_output_bits; /* Q0 */
+ move16();
+ }
+
+ *nEncoded = lastnz2; /* Q0 */
+ move16();
+ *stop = stop2; /* If zero, it means no overflow occured during bit-estimation Q0*/
+ move16();
+ *lastnz_out = lastnz; /* Q0 */
+ move16();
+
+ /* Restore hole indices beyond lastnz */
+ FOR( k = numHoleIndices; k < hm_cfg->numHoleIndices; ++k )
+ {
+ hm_cfg->holeIndices[k] = sub( hm_cfg->holeIndices[k], nt ); /* Q0 */
+ move16();
+ }
+ hm_cfg->numPeakIndices = numPeakIndicesOrig; /* Q0 */
+ move16();
+
+ return round_fx( L_add( L_shr( nbits2_fx, sub( Q15, nbits2_e ) ), ONE_IN_Q14 ) ); /* Q0 */
+ }
+ ELSE /* if (!hm_cfg) */
+ {
+ Word16 esc_nb, cp, rateQ;
+ UWord16 s;
+ Word16 tot_bits2;
+ Word16 overflow_flag = 0;
+ move16();
+
+ /* Rate flag */
+ IF( GT_16( target, 400 ) )
+ {
+ rateFlag = 2; /* Q0 */
+ move16();
+ }
+ ELSE
+ {
+ rateFlag = 0; /* Select context-B for lower bitrates */
+ move16();
+ }
+
+ t = 0;
+ move16();
+ s = 0;
+ move16();
+ cp = 0;
+ move16();
+ lastnz = 1;
+ move16();
+ lastnz2 = 0;
+ move16();
+ tot_bits2 = 0;
+ move16();
+
+ /* Find last non-zero tuple in the mapped domain signal */
+ FOR( lastnz = sub( nt, 2 ); lastnz >= 0; lastnz -= 2 )
+ {
+ test();
+ IF( ( x[lastnz] != 0 ) || ( x[lastnz + 1] != 0 ) )
+ {
+ BREAK;
+ }
+ }
+ lastnz = add( lastnz, 2 ); /* Q0 */
+ IF( LT_16( lastnz, 2 ) )
+ {
+ lastnz = 2; /* At least one tuple is coded Q0*/
+ move16();
+ }
+
+ lastnz2 = 2;
+ move16();
+
+ /* Main Loop through the 2-tuples */
+ FOR( k = 0; k < lastnz; k += 2 )
+ {
+ /* Init current 2-tuple encoding */
+ a1 = abs_s( x[k] ); /* Q0 */
+ b1 = abs_s( x[k + 1] ); /* Q0 */
+ lev1 = 0;
+ move16();
+ esc_nb = 0;
+ move16();
+ rateQ = add( rateFlag, extract_l( GT_16( k, shr( nt, 1 ) ) ) ); /* Q0 */
+
+ bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, s_min( a1, 1 ) * ONE_IN_Q30, 1, &bit_estimate_e ); /* exp(bit_estimate_e) */
+ bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, s_min( b1, 1 ) * ONE_IN_Q30, 1, &bit_estimate_e ); /* exp(bit_estimate_e) */
+
+ /* pre-compute address of ari_pk_s17_LC_ext[0][Val_esc] to avoid doing it multiple times inside the loop */
+ lookup = &ari_lookup_s17_LC[t + shl( rateQ, NBITS_CONTEXT )]; /* Q0 */
+
+ /* check while condition */
+ /* MSBs coding */
+ WHILE( GE_16( s_max( a1, b1 ), A_THRES ) )
+ {
+ pki = lookup[( esc_nb << ( NBITS_CONTEXT + NBITS_RATEQ ) )]; /* Q0 */
+ move16();
+
+ bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC], 8, &bit_estimate_e ); /* exp(bit_estimate_e) */
+ bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, 2 * ONE_IN_Q29, 2, &bit_estimate_e ); /* Add 2 LSB bits corresponding to the bit-plane exp(bit_estimate_e) */
+
+ a1 = shr( a1, 1 );
+ b1 = shr( b1, 1 );
+
+ lev1 = add( lev1, 1 );
+ esc_nb = s_min( lev1, 3 );
+
+ /* check while condition */
+ }
+
+ pki = lookup[( esc_nb << ( NBITS_CONTEXT + NBITS_RATEQ ) )]; /* Q0 */
+ move16();
+
+ symbol = add( a1, i_mult( A_THRES, b1 ) ); /* Q0 */
+ bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][symbol], 8, &bit_estimate_e ); /* exp(bit_estimate_e) */
+
+ /* Should we truncate? */
+ IF( GT_32( L_shr( bit_estimate_fx, sub( Q16, bit_estimate_e ) ), L_shl( target, Q15 ) ) ) /* Overflow occured */
+ {
+ overflow_flag = 1;
+ move16();
+ }
+ ELSE
+ {
+ IF( abs_s( x[k] ) || abs_s( x[k + 1] ) ) /* No overflow & non-zero tuple */
+ {
+ nbits2_fx = bit_estimate_fx; /* exp(bit_estimate_e) */
+ nbits2_e = bit_estimate_e;
+ move32();
+ move16();
+ lastnz2 = add( k, 2 );
+ }
+ }
+
+ /* Update context for next 2-tuple */
+ IF( LT_16( esc_nb, 2 ) )
+ {
+ cp = add( 1, i_mult( add( a1, b1 ), add( esc_nb, 1 ) ) ); /* Q0 */
+ }
+ ELSE
+ {
+ cp = add( 12, esc_nb ); /* Q0 */
+ }
+ /*shift old bits and replace last 4 bits*/
+ s = (UWord16) L_add( L_shl( s, 4 ), cp );
+ t = s_and( s, 0xFF );
+
+ } /*end of the 2-tuples loop*/
+
+ tot_bits2 = round_fx( L_shr( nbits2_fx, sub( Q15, nbits2_e ) ) );
+ IF( LT_16( lastnz2, lastnz ) ) /* Overflow occured because unable to code all tuples */
+ {
+ overflow_flag = 1;
+ move16();
+ }
+ IF( EQ_16( mode, -1 ) )
+ {
+ tot_bits2 = round_fx( L_shr( bit_estimate_fx, sub( Q15, bit_estimate_e ) ) ); /* Q0 */
+ }
+ IF( overflow_flag == 0 ) /* No overflow */
+ {
+ *stop = 0;
+ move16();
+ }
+ ELSE /* Overflow */
+ {
+ IF( *stop ){
+ *stop = tot_bits2; /* Q0 */
+ move16();
+ }
+ ELSE
+ {
+ *stop = round_fx( L_shr( bit_estimate_fx, sub( Q15, bit_estimate_e ) ) ); /* Q0 */
+ move16();
+ }
+}
+
+*lastnz_out = lastnz; /* Q0 */
+move16();
+*nEncoded = lastnz2; /* Q0 */
+move16();
+/* Safety mechanism to avoid overflow */
+test();
+IF( EQ_16( lastnz2, 2 ) && EQ_16( overflow_flag, 1 ) )
+{
+ FOR( k = 0; k < lastnz2; k++ )
+ {
+ x[k] = 0;
+ move16();
+ }
+}
+
+return tot_bits2;
+}
+}
+
+
+/*-------------------------------------------------------------------*
+ * RCcontextMapping_encode2_estimate_bandWise_start_fx()
+ *
+ * Range coder - start bandwise bit-estimation
+ *-------------------------------------------------------------------*/
+
+Word16 RCcontextMapping_encode2_estimate_bandWise_start_fx(
+ Word16 *x, /* Q0 */
+ const Word16 nt, /* Q0 */
+ const Word16 target, /* Q0 */
+ HANDLE_RC_CONTEXT_MEM hContextMem )
+{
+ Word16 i, k;
+
+ /* Rate flag */
+ IF( GT_16( target, 400 ) )
+ {
+ hContextMem->rateFlag = 2 << NBITS_CONTEXT;
+ move16();
+ }
+ ELSE
+ {
+ hContextMem->rateFlag = 0;
+ move16();
+ }
+
+ hContextMem->bit_estimate_fx = 2; /* Q0 */
+ move32();
+ hContextMem->bit_estimate_e = Q31;
+ move16();
+
+
+ /* Init */
+ hContextMem->nt_half = shr( nt, 1 );
+ move16();
+
+ /* bits to encode lastnz */
+ k = 1;
+ move16();
+
+ WHILE( LT_16( k, hContextMem->nt_half ) )
+ {
+ hContextMem->bit_estimate_fx = L_add( hContextMem->bit_estimate_fx, 1 ); /* exp(bit_estimate_e) */
+ move32();
+
+ k = shl( k, 1 );
+ /* check while condition */
+ }
+
+ /* bits to encode lastnz */
+ hContextMem->nbits_old = extract_l( hContextMem->bit_estimate_fx ); /* Q0 */
+ move16();
+
+ hContextMem->ctx = 0;
+ move16();
+ hContextMem->lastnz = 2;
+ move16();
+
+ /* Find last non-zero tuple */
+
+ FOR( i = nt; i >= 4; i -= 2 )
+ {
+ test();
+ IF( x[i - 2] != 0 || x[i - 1] != 0 )
+ {
+ hContextMem->lastnz = i;
+ move16();
+ BREAK;
+ }
+ }
+ Word16 tmp2 = extract_l( hContextMem->bit_estimate_fx );
+ Word16 tmp = norm_l( hContextMem->bit_estimate_fx );
+ hContextMem->bit_estimate_e = sub( Q31, tmp );
+ move16();
+ hContextMem->bit_estimate_fx = L_shl( hContextMem->bit_estimate_fx, tmp ); /* exp(bit_estimate_e) */
+ move32();
+
+ return tmp2;
+}
+
+/*-------------------------------------------------------------------*
+ * RCcontextMapping_encode2_estimate_bandWise_fx()
+ *
+ * Range coder - bandwise bit-estimation
+ *-------------------------------------------------------------------*/
+
+Word16 RCcontextMapping_encode2_estimate_bandWise_fx(
+ Word16 *x, /* Q0 */
+ const Word16 start_line, /* Q0 */
+ const Word16 end_line, /* Q0 */
+ HANDLE_RC_CONTEXT_MEM hContextMem )
+{
+ Word16 a1, b1, a1_i, b1_i;
+ Word16 k, pki, lev1;
+ UWord16 t;
+ Word16 bandBits = 0;
+ move16();
+ Word16 total_output_bits; /* No. of bits after finalization */
+ Word16 symbol;
+ const UWord8 *lookup;
+ Word16 idx;
+ Word16 tmp;
+
+ /* Main Loop through the 2-tuples */
+ /*hContextMem->nt_half = end_line >> 1;*/
+ FOR( k = start_line; k < min( hContextMem->lastnz, end_line ); k += 2 )
+ {
+ a1_i = k; /* Q0 */
+ move16();
+ b1_i = add( k, 1 ); /* Q0 */
+
+ idx = k;
+ move16();
+
+ /* Get context */
+ t = add( hContextMem->ctx, hContextMem->rateFlag ); /* Q0 */
+
+ IF( GE_16( hContextMem->nt_half, idx ) )
+ {
+ tmp = 0;
+ }
+ ELSE
+ {
+ tmp = ( 1 << NBITS_CONTEXT );
+ }
+
+ t = add( t, tmp ); /* Q0 */
+
+ /* Init current 2-tuple encoding */
+ a1 = abs_s( x[a1_i] ); /* Q0 */
+ b1 = abs_s( x[b1_i] ); /* Q0 */
+ lev1 = -( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ); /* Q0 */
+
+ /* Signs Bits */
+ hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, imult3216( ONE_IN_Q30, s_min( a1, 1 ) ), Q1, &hContextMem->bit_estimate_e ); /* exp(hContextMem->bit_estimate_e) */
+ hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, imult3216( ONE_IN_Q30, s_min( b1, 1 ) ), Q1, &hContextMem->bit_estimate_e ); /* exp(hContextMem->bit_estimate_e) */
+ move32();
+ move32();
+
+ /* pre-compute address of ari_pk_s17_LC_ext[0][Val_esc] to avoid doing it multiple times inside the loop */
+ lookup = &ari_lookup_s17_LC[t] + ( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) );
+
+ /* check while condition */
+ /* MSBs coding */
+ WHILE( GE_16( s_max( a1, b1 ), A_THRES ) )
+ {
+ pki = lookup[lev1]; /* Q0 */
+ move16();
+
+ hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC], Q8, &hContextMem->bit_estimate_e ); /* exp(hContextMem->bit_estimate_e) */
+ hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, 2 * ONE_IN_Q29, Q2, &hContextMem->bit_estimate_e ); /* Add the 2 LSB bits that were shifted out exp(hContextMem->bit_estimate_e) */
+ move32();
+ move32();
+
+ // hContextMem->bit_estimate = hContextMem->bit_estimate + ari_bit_estimate_s17_LC[pki][VAL_ESC];
+ // hContextMem->bit_estimate += 2; /* Add the 2 LSB bits that were shifted out */
+
+ a1 = shr( a1, 1 );
+ b1 = shr( b1, 1 );
+
+ lev1 = s_min( add( lev1, ( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ) ), 2 << ( NBITS_CONTEXT + NBITS_RATEQ ) ); /* Q0 */
+ /* check while condition */
+ }
+
+ pki = lookup[lev1]; /* Q0 */
+ move16();
+ symbol = add( a1, i_mult( A_THRES, b1 ) ); /* MSB symbol Q0*/
+ hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][symbol], Q8, &hContextMem->bit_estimate_e ); /* exp(bit_estimate_e) */
+ move32();
+ // hContextMem->bit_estimate = hContextMem->bit_estimate + ari_bit_estimate_s17_LC[pki][symbol];
+
+ /* Update context */
+ lev1 = shr( lev1, NBITS_CONTEXT + NBITS_RATEQ );
+
+ IF( lev1 <= 0 )
+ {
+ t = add( 1, i_mult( add( a1, b1 ), add( lev1, 2 ) ) ); /* Q0 */
+ }
+ ELSE
+ {
+ t = add( 13, lev1 ); /* Q0 */
+ }
+
+ hContextMem->ctx = add( i_mult( s_and( hContextMem->ctx, 0xf ), 16 ), t ); /* Q0 */
+ move16();
+
+ } /*end of the 2-tuples loop*/
+ total_output_bits = round_fx( L_shr( hContextMem->bit_estimate_fx, sub( Q15, hContextMem->bit_estimate_e ) ) ); /* Q0 */
+ // total_output_bits = (Word16) ( hContextMem->bit_estimate + 0.5f );
+
+ bandBits = sub( total_output_bits, hContextMem->nbits_old ); /* Q0 */
+ hContextMem->nbits_old = total_output_bits; /* Q0 */
+ move16();
+
+ return bandBits;
+}
+
+
#ifdef IVAS_CODE_RANGE_CODER
/*-------------------------------------------------------------------*
diff --git a/lib_enc/FEC_enc.c b/lib_enc/FEC_enc.c
deleted file mode 100644
index 3d5aa4f6b215a78e13905dd808f2ecf0e995115d..0000000000000000000000000000000000000000
--- a/lib_enc/FEC_enc.c
+++ /dev/null
@@ -1,216 +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
-#include "cnst.h"
-#include "prot.h"
-#include "rom_com.h"
-#include "wmc_auto.h"
-
-#include "ivas_prot_fx.h"
-#include "prot_fx.h"
-
-/*-------------------------------------------------------------------*
- * FEC_encode()
- *
- * Encoder supplementary information for FEC
- *-------------------------------------------------------------------*/
-
-void FEC_encode_ivas_fx(
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- const ACELP_config acelp_cfg, /* i/o: configuration of the ACELP */
- const Word16 *synth, /* i : pointer to synthesized speech for E computation */
- const Word16 coder_type, /* i : type of coder */
- Word16 clas, /* i : signal clas for current frame */
- const Word16 *fpit, /* i : close loop fractional pitch buffer Q6 */
- const Word16 *res, /* i : LP residual signal frame */
- Word16 *last_pulse_pos, /* i/o: Position of the last pulse */
- const Word16 L_frame, /* i : Frame length */
- const Word32 total_brate, /* i : total codec bitrate */
- const Word16 Q_synth /* i : input scaling */
-)
-{
- Word16 tmpS, index;
- Word16 maxi, sign, tmp_FER_pitch;
- Word32 enr_q, Ltmp;
- Word16 exp_enrq;
-
- tmpS = 0;
- move16();
- enr_q = 1;
- move16();
- sign = 0;
- move16();
- test();
- test();
- IF( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) && acelp_cfg.FEC_mode > 0 )
- {
- /*-----------------------------------------------------------------*
- * encode signal class (not needed for VC mode since it is clearly voiced) (2 bits)
- *-----------------------------------------------------------------*/
- IF( NE_16( coder_type, VOICED ) )
- {
- /* encode signal clas with 2 bits */
- test();
- IF( EQ_16( clas, UNVOICED_CLAS ) )
- {
- index = 0;
- move16();
- }
- ELSE IF( EQ_16( clas, VOICED_TRANSITION ) || EQ_16( clas, UNVOICED_TRANSITION ) )
- {
- index = 1;
- move16();
- }
- ELSE IF( EQ_16( clas, VOICED_CLAS ) )
- {
- index = 2;
- move16();
- }
- ELSE
- {
- index = 3;
- move16();
- }
- push_indice( hBstr, IND_FEC_CLAS, index, FEC_BITS_CLS );
- }
-
- /*-----------------------------------------------------------------*
- * encode frame energy (5 bits)
- *-----------------------------------------------------------------*/
- test();
- IF( GT_16( acelp_cfg.FEC_mode, 1 ) ) /* GENERIC and VOICED frames */
- {
- /* frame energy (maximum energy per pitch period for voiced frames or mean energy per sample over 2nd halframe for unvoiced frames) */
- /*frame_ener( L_frame, clas, synth, fpit[(L_frame>>6)-1], &enr_q, 0 );*/
- Word32 synth32[L_FRAME16k];
- Copy_Scale_sig_16_32( synth, synth32, L_FRAME16k, 0 );
- fer_energy_fx( L_frame, clas, synth32, Q_synth, shr_r( fpit[sub( shr( L_frame, 6 ), 1 )], 6 ), &enr_q, L_frame );
- exp_enrq = sub( 31, shl( Q_synth, 1 ) );
- IF( EQ_16( clas, VOICED_CLAS ) || EQ_16( clas, ONSET ) || EQ_16( clas, SIN_ONSET ) ) /* Voiced or Onset current frame */
- {
- exp_enrq = 31;
- move16();
- }
- /* linearly quantize the energy in the range 0 : FEC_ENR_STEP : 96 dB */
- /*tmpS = (short)( 10.0 * log10( enr_q + 0.001f ) / FEC_ENR_STEP )*/ /*To be converted fl_2_fx*/
-
- Ltmp = Mpy_32_32( BASOP_Util_Log10( enr_q, exp_enrq ), 894784853 /* 10 / FEC_ENR_STEP Q28 */ ); // Q 25 + 28 - 31 = Q22
- IF( Ltmp < 0 )
- {
- tmpS = extract_l( L_negate( L_shr( L_negate( Ltmp ), Q22 ) ) );
- }
- ELSE
- {
- tmpS = extract_l( L_shr( Ltmp, Q22 ) );
- }
-
- tmpS = s_min( tmpS, FEC_ENR_QLIMIT );
- tmpS = s_max( tmpS, 0 );
-
- push_indice( hBstr, IND_FEC_ENR, tmpS, FEC_BITS_ENR );
- }
- /*-----------------------------------------------------------------*
- * Encode last glottal pulse position (8 bits)
- *-----------------------------------------------------------------*/
- test();
- IF( GT_16( acelp_cfg.FEC_mode, 2 ) ) /* GENERIC frames */
- {
- /* retrieve the last glottal pulse position of the previous frame */
- /* use the current pitch information to scale or not the quantization */
- tmp_FER_pitch = shr( fpit[0], 6 ); /* take the 1st subframe pit, since it is easier to get on decoder side */
- sign = 0;
- move16();
- maxi = *last_pulse_pos;
- move16();
- IF( maxi < 0 )
- {
- sign = 1;
- move16();
- /*maxi = -maxi; */
- maxi = negate( maxi );
- }
-
- if ( GE_16( tmp_FER_pitch, 128 ) )
- {
- maxi = shr( maxi, 1 );
- }
-
- if ( GT_16( maxi, 127 ) )
- {
- /* better not use the glottal pulse position at all instead of using a wrong pulse */
- /* can happen only with pitch > 254 and max pit = 289 and should happen very rarely */
- maxi = 0;
- move16();
- }
-
- if ( EQ_16( sign, 1 ) )
- {
- maxi = add( maxi, 128 ); /* use 8 bits (MSB represent the sign of the pulse) */
- }
-
- push_indice( hBstr, IND_FEC_POS, maxi, FEC_BITS_POS );
- }
- maxi = 0;
- move16();
-
- /* If bitrate < 24k4, then the pitch
- is not represented in the same domain (12.k instead of 16k) */
- test();
- IF( GE_16( clas, VOICED_CLAS ) && GE_32( total_brate, ACELP_24k40 ) )
- {
- /*maxi = findpulse( L_frame, res, (short)(fpit[(L_frame>>6)-1]), 0, &sign ); */
- maxi = findpulse_fx( L_frame, res, shr_r( fpit[sub( shr( L_frame, 6 ), 1 )], 6 ), 0, &sign );
- if ( EQ_16( sign, 1 ) )
- {
- /*maxi = -maxi;*/
- maxi = negate( maxi );
- }
- }
-
- *last_pulse_pos = maxi;
- move16();
- }
- ELSE
- {
- *last_pulse_pos = 0;
- move16();
- }
-
- return;
-}
diff --git a/lib_enc/FEC_enc_fx.c b/lib_enc/FEC_enc_fx.c
index d35f18b61a9dcf5be4bf1727d91abeb852530913..20dced8d7f939e6fed40a47960b823873307fd2e 100644
--- a/lib_enc/FEC_enc_fx.c
+++ b/lib_enc/FEC_enc_fx.c
@@ -5,10 +5,12 @@
#include "options.h" /* Compilation switches */
#include "cnst.h" /* Common constants */
//#include "prot_fx.h" /* Function prototypes */
-#include "rom_com_fx.h" /* Static table prototypes */
-#include "rom_com.h" /* Static table prototypes */
-#include "prot_fx.h" /* Function prototypes */
-#include "prot_fx_enc.h" /* Function prototypes */
+#include "rom_com_fx.h" /* Static table prototypes */
+#include "rom_com.h" /* Static table prototypes */
+#include "prot_fx.h" /* Function prototypes */
+#include "prot_fx_enc.h" /* Function prototypes */
+#include "prot.h" /* Function prototypes */
+#include "ivas_prot_fx.h" /* Function prototypes */
/*============================================================================*/
@@ -37,18 +39,18 @@
/* */
/*============================================================================*/
void FEC_encode_fx(
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- const ACELP_config acelp_cfg, /* i/o: configuration of the ACELP */
- const Word16 *synth, /* i : pointer to synthesized speech for E computation */
- const Word16 coder_type, /* i : type of coder */
- Word16 clas, /* i : signal clas for current frame */
- const Word16 *fpit, /* i : close loop fractional pitch buffer */
- const Word16 *res, /* i : LP residual signal frame */
- Word16 *last_pulse_pos, /* i/o: Position of the last pulse */
- const Word16 L_frame, /* i : Frame length */
- const Word32 total_brate, /* i : total codec bitrate */
- const Word16 Q_new, /* i : input scaling */
- const Word16 shift /* i : scaling to get 12bits */
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ const ACELP_config acelp_cfg, /* i/o: configuration of the ACELP */
+ const Word16 *synth, /* i : pointer to synthesized speech for E computation Q_synth*/
+ const Word16 coder_type, /* i : type of coder Q0*/
+ Word16 clas, /* i : signal clas for current frame Q0*/
+ const Word16 *fpit, /* i : close loop fractional pitch buffer Q6*/
+ const Word16 *res, /* i : LP residual signal frame Qx*/
+ Word16 *last_pulse_pos, /* i/o: Position of the last pulse Q0*/
+ const Word16 L_frame, /* i : Frame length Q0*/
+ const Word32 total_brate, /* i : total codec bitrate Q0*/
+ const Word16 Q_new, /* i : input scaling */
+ const Word16 shift /* i : scaling to get 12bits */
)
{
Word16 tmpS, index;
@@ -99,20 +101,19 @@ void FEC_encode_fx(
/*-----------------------------------------------------------------*
* encode frame energy (5 bits)
*-----------------------------------------------------------------*/
- test();
IF( GT_16( acelp_cfg.FEC_mode, 1 ) ) /* GENERIC and VOICED frames */
{
/* frame energy (maximum energy per pitch period for voiced frames or mean energy per sample over 2nd halframe for unvoiced frames) */
/*frame_ener( L_frame, clas, synth, fpit[(L_frame>>6)-1], &enr_q, 0 );*/
- exp_enrq = frame_ener_fx( L_frame, clas, synth, shr_r( fpit[sub( shr( L_frame, 6 ), 1 )], 6 ), &enr_q, L_frame, Q_new, shift, 1 );
+ exp_enrq = frame_ener_fx( L_frame, clas, synth, shr_r( fpit[( L_frame >> 6 ) - 1], 6 ), &enr_q, L_frame, Q_new, shift, 1 );
/* linearly quantize the energy in the range 0 : FEC_ENR_STEP : 96 dB */
/*tmpS = (short)( 10.0 * log10( enr_q + 0.001f ) / FEC_ENR_STEP )*/ /*To be converted fl_2_fx*/
enr_lg_frac = Log2_norm_lc( enr_q );
- enr_lg_ent = sub( 30, exp_enrq );
- Ltmp = Mpy_32_16( enr_lg_ent, enr_lg_frac, LG10_s3_0 );
- tmpS = extract_h( L_shl( Ltmp, 1 ) );
+ enr_lg_ent = sub( 30, exp_enrq ); /* Q15 */
+ Ltmp = Mpy_32_16( enr_lg_ent, enr_lg_frac, LG10_s3_0 ); /* Q14 */
+ tmpS = extract_h( L_shl( Ltmp, 1 ) ); /* Q15 + 1 -> Q0*/
tmpS = s_min( tmpS, 31 );
tmpS = s_max( tmpS, 0 );
@@ -122,7 +123,6 @@ void FEC_encode_fx(
/*-----------------------------------------------------------------*
* Encode last glottal pulse position (8 bits)
*-----------------------------------------------------------------*/
- test();
IF( GT_16( acelp_cfg.FEC_mode, 2 ) ) /* GENERIC frames */
{
/* retrieve the last glottal pulse position of the previous frame */
@@ -130,14 +130,14 @@ void FEC_encode_fx(
tmp_FER_pitch = shr( fpit[0], 6 ); /* take the 1st subframe pit, since it is easier to get on decoder side */
sign = 0;
move16();
- maxi = *last_pulse_pos;
+ maxi = *last_pulse_pos; /* Q0 */
move16();
IF( maxi < 0 )
{
sign = 1;
move16();
/*maxi = -maxi; */
- maxi = negate( maxi );
+ maxi = negate( maxi ); /* Q0 */
}
if ( GE_16( tmp_FER_pitch, 128 ) )
@@ -155,7 +155,7 @@ void FEC_encode_fx(
if ( sign == 1 )
{
- maxi = add( maxi, 128 ); /* use 8 bits (MSB represent the sign of the pulse) */
+ maxi = add( maxi, 128 ); /* use 8 bits (MSB represent the sign of the pulse) Q0*/
}
push_indice_fx( hBstr, IND_FEC_POS, maxi, FEC_BITS_POS );
@@ -169,15 +169,15 @@ void FEC_encode_fx(
IF( GE_16( clas, VOICED_CLAS ) && GE_32( total_brate, ACELP_24k40 ) )
{
/*maxi = findpulse( L_frame, res, (short)(fpit[(L_frame>>6)-1]), 0, &sign ); */
- maxi = findpulse_fx( L_frame, res, shr_r( fpit[sub( shr( L_frame, 6 ), 1 )], 6 ), 0, &sign );
+ maxi = findpulse_fx( L_frame, res, shr_r( fpit[( L_frame >> 6 ) - 1], 6 ), 0, &sign ); /* Q0 */
if ( sign == 1 )
{
/*maxi = -maxi;*/
- maxi = negate( maxi );
+ maxi = negate( maxi ); /* Q0 */
}
}
- *last_pulse_pos = maxi;
+ *last_pulse_pos = maxi; /* Q0 */
move16();
}
ELSE
@@ -198,8 +198,8 @@ void FEC_encode_fx(
*-------------------------------------------------------------------*/
void FEC_lsf_estim_enc_fx(
- Encoder_State *st_fx, /* i : Encoder static memory */
- Word16 *lsf /* o : estimated LSF vector */
+ Encoder_State *st_fx, /* i : Encoder static memory */
+ Word16 *lsf /* o : estimated LSF vector Qlog2(2.56)*/
)
{
Word16 i;
@@ -222,7 +222,7 @@ void FEC_lsf_estim_enc_fx(
IF( EQ_16( st_fx->last_coder_type, UNVOICED ) )
{
/* clearly unvoiced */
- alpha = _ALPHA_UU_FX;
+ alpha = _ALPHA_UU_FX; /* Q15 */
move16();
}
ELSE
@@ -231,52 +231,54 @@ void FEC_lsf_estim_enc_fx(
test();
IF( EQ_16( st_fx->last_coder_type, AUDIO ) || EQ_16( st_fx->clas, INACTIVE_CLAS ) )
{
- alpha = 32604;
+ alpha = 32604; /* 0.995 in Q15 */
move16();
}
ELSE IF( EQ_16( st_fx->clas, UNVOICED_CLAS ) )
{
/* if stable, do not flatten the spectrum in the first erased frame */
/* alpha = st->stab_fac * (1.0f - 2.0f*ALPHA_U) + 2.0f*ALPHA_U; */
- alpha = add( mult( st_fx->stab_fac_fx, 32768 - _ALPHA_U_FX_X_2 ), _ALPHA_U_FX_X_2 );
+ alpha = add( mult( st_fx->stab_fac_fx, 32768 - _ALPHA_U_FX_X_2 ), _ALPHA_U_FX_X_2 ); /* Q15 */
}
ELSE IF( EQ_16( st_fx->clas, UNVOICED_TRANSITION ) )
{
- alpha = _ALPHA_UT_FX;
+ alpha = _ALPHA_UT_FX; /* Q15 */
move16();
}
ELSE IF( EQ_16( st_fx->clas, VOICED_CLAS ) || EQ_16( st_fx->clas, ONSET ) )
{
/* clearly voiced - mild convergence to the CNG spectrum for the first three erased frames */
- alpha = _ALPHA_V_FX;
+ alpha = _ALPHA_V_FX; /* Q15 */
move16();
}
ELSE IF( EQ_16( st_fx->clas, SIN_ONSET ) )
{
- alpha = _ALPHA_S_FX;
+ alpha = _ALPHA_S_FX; /* Q15 */
move16();
}
ELSE
{
/* long erasures and onsets - rapid convergence to the CNG spectrum */
- alpha = _ALPHA_VT_FX;
+ alpha = _ALPHA_VT_FX; /* Q15 */
move16();
}
}
/*----------------------------------------------------------------------*
* Extrapolate LSF vector
*----------------------------------------------------------------------*/
- tmp = sub( 32767, alpha );
+ tmp = sub( 32767, alpha ); /* Q15 */
/* extrapolate the old LSF vector */
FOR( i = 0; i < M; i++ )
{
/* calculate mean LSF vector */
/*lsf_mean[i] = BETA_FEC * lsf_mean[i] + (1-BETA_FEC) * st->lsf_adaptive_mean[i]; */
- lsf_mean[i] = mac_r( L_mult( BETA_FEC_FX, lsf_mean[i] ), 32768 - BETA_FEC_FX, st_fx->lsf_adaptive_mean_fx[i] );
+ lsf_mean[i] = mac_r( L_mult( BETA_FEC_FX, lsf_mean[i] ), 32768 - BETA_FEC_FX, st_fx->lsf_adaptive_mean_fx[i] ); /* Qlog2(2.56) */
+ move16();
/* move old LSF vector towards the mean LSF vector */
/* lsf[i] = alpha * st->lsf_old[i] + (1.0f - alpha) * lsf_mean[i]; */
- lsf[i] = mac_r( L_mult( alpha, st_fx->lsf_old_fx[i] ), tmp, lsf_mean[i] );
+ lsf[i] = mac_r( L_mult( alpha, st_fx->lsf_old_fx[i] ), tmp, lsf_mean[i] ); /* Qlog2(2.56) */
+ move16();
}
/* check LSF stability through LSF ordering */
@@ -291,3 +293,175 @@ void FEC_lsf_estim_enc_fx(
return;
}
+
+/*-------------------------------------------------------------------*
+ * FEC_encode()
+ *
+ * Encoder supplementary information for FEC
+ *-------------------------------------------------------------------*/
+
+void FEC_encode_ivas_fx(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ const ACELP_config acelp_cfg, /* i/o: configuration of the ACELP */
+ const Word16 *synth, /* i : pointer to synthesized speech for E computation Q_Synth*/
+ const Word16 coder_type, /* i : type of coder Q0*/
+ Word16 clas, /* i : signal clas for current frame Q0*/
+ const Word16 *fpit, /* i : close loop fractional pitch buffer Q6*/
+ const Word16 *res, /* i : LP residual signal frame Qx*/
+ Word16 *last_pulse_pos, /* i/o: Position of the last pulse Q0*/
+ const Word16 L_frame, /* i : Frame length Q0*/
+ const Word32 total_brate, /* i : total codec bitrate Q0*/
+ const Word16 Q_synth /* i : input scaling */
+)
+{
+ Word16 tmpS, index;
+ Word16 maxi, sign, tmp_FER_pitch;
+ Word32 enr_q, Ltmp;
+ Word16 exp_enrq;
+
+ tmpS = 0;
+ move16();
+ enr_q = 1;
+ move16();
+ sign = 0;
+ move16();
+ test();
+ test();
+ IF( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) && acelp_cfg.FEC_mode > 0 )
+ {
+ /*-----------------------------------------------------------------*
+ * encode signal class (not needed for VC mode since it is clearly voiced) (2 bits)
+ *-----------------------------------------------------------------*/
+ IF( NE_16( coder_type, VOICED ) )
+ {
+ /* encode signal clas with 2 bits */
+ test();
+ IF( clas == UNVOICED_CLAS )
+ {
+ index = 0;
+ move16();
+ }
+ ELSE IF( EQ_16( clas, VOICED_TRANSITION ) || EQ_16( clas, UNVOICED_TRANSITION ) )
+ {
+ index = 1;
+ move16();
+ }
+ ELSE IF( EQ_16( clas, VOICED_CLAS ) )
+ {
+ index = 2;
+ move16();
+ }
+ ELSE
+ {
+ index = 3;
+ move16();
+ }
+ push_indice( hBstr, IND_FEC_CLAS, index, FEC_BITS_CLS );
+ }
+
+ /*-----------------------------------------------------------------*
+ * encode frame energy (5 bits)
+ *-----------------------------------------------------------------*/
+ IF( GT_16( acelp_cfg.FEC_mode, 1 ) ) /* GENERIC and VOICED frames */
+ {
+ /* frame energy (maximum energy per pitch period for voiced frames or mean energy per sample over 2nd halframe for unvoiced frames) */
+ /*frame_ener( L_frame, clas, synth, fpit[(L_frame>>6)-1], &enr_q, 0 );*/
+ Word32 synth32[L_FRAME16k];
+ Copy_Scale_sig_16_32( synth, synth32, L_FRAME16k, 0 ); /* Qsynth */
+ fer_energy_fx( L_frame, clas, synth32, Q_synth, shr_r( fpit[( L_frame >> 6 ) - 1], 6 ), &enr_q, L_frame );
+ exp_enrq = sub( 31, shl( Q_synth, 1 ) );
+
+ test();
+ test();
+ if ( EQ_16( clas, VOICED_CLAS ) || EQ_16( clas, ONSET ) || EQ_16( clas, SIN_ONSET ) ) /* Voiced or Onset current frame */
+ {
+ exp_enrq = 31;
+ move16();
+ }
+ /* linearly quantize the energy in the range 0 : FEC_ENR_STEP : 96 dB */
+ /*tmpS = (short)( 10.0 * log10( enr_q + 0.001f ) / FEC_ENR_STEP )*/ /*To be converted fl_2_fx*/
+
+ Ltmp = Mpy_32_32( BASOP_Util_Log10( enr_q, exp_enrq ), 894784853 /* 10 / FEC_ENR_STEP Q28 */ ); // Q 25 + 28 - 31 = Q22
+ IF( Ltmp < 0 )
+ {
+ tmpS = extract_l( L_negate( L_shr( L_negate( Ltmp ), Q22 ) ) ); /* Q0 */
+ }
+ ELSE
+ {
+ tmpS = extract_l( L_shr( Ltmp, Q22 ) ); /* Q0 */
+ }
+
+ tmpS = s_min( tmpS, FEC_ENR_QLIMIT );
+ tmpS = s_max( tmpS, 0 );
+
+ push_indice( hBstr, IND_FEC_ENR, tmpS, FEC_BITS_ENR );
+ }
+ /*-----------------------------------------------------------------*
+ * Encode last glottal pulse position (8 bits)
+ *-----------------------------------------------------------------*/
+
+ IF( GT_16( acelp_cfg.FEC_mode, 2 ) ) /* GENERIC frames */
+ {
+ /* retrieve the last glottal pulse position of the previous frame */
+ /* use the current pitch information to scale or not the quantization */
+ tmp_FER_pitch = shr( fpit[0], 6 ); /* take the 1st subframe pit, since it is easier to get on decoder side */
+ sign = 0;
+ move16();
+ maxi = *last_pulse_pos; /* Q0 */
+ move16();
+ IF( maxi < 0 )
+ {
+ sign = 1;
+ move16();
+ /*maxi = -maxi; */
+ maxi = negate( maxi );
+ }
+
+ if ( GE_16( tmp_FER_pitch, 128 ) )
+ {
+ maxi = shr( maxi, 1 );
+ }
+
+ if ( GT_16( maxi, 127 ) )
+ {
+ /* better not use the glottal pulse position at all instead of using a wrong pulse */
+ /* can happen only with pitch > 254 and max pit = 289 and should happen very rarely */
+ maxi = 0;
+ move16();
+ }
+
+ if ( EQ_16( sign, 1 ) )
+ {
+ maxi = add( maxi, 128 ); /* use 8 bits (MSB represent the sign of the pulse) Q0*/
+ }
+
+ push_indice( hBstr, IND_FEC_POS, maxi, FEC_BITS_POS );
+ }
+ maxi = 0;
+ move16();
+
+ /* If bitrate < 24k4, then the pitch
+ is not represented in the same domain (12.k instead of 16k) */
+ test();
+ IF( GE_16( clas, VOICED_CLAS ) && GE_32( total_brate, ACELP_24k40 ) )
+ {
+ /*maxi = findpulse( L_frame, res, (short)(fpit[(L_frame>>6)-1]), 0, &sign ); */
+ maxi = findpulse_fx( L_frame, res, shr_r( fpit[( L_frame >> 6 ) - 1], 6 ), 0, &sign );
+ if ( EQ_16( sign, 1 ) )
+ {
+ /*maxi = -maxi;*/
+ maxi = negate( maxi );
+ }
+ }
+
+ *last_pulse_pos = maxi; /* Q0 */
+ move16();
+ }
+ ELSE
+ {
+ *last_pulse_pos = 0;
+ move16();
+ }
+
+ return;
+}
diff --git a/lib_enc/SNR_calc.c b/lib_enc/SNR_calc.c
deleted file mode 100644
index 8d4adb219f2e97f01fc9e529ffbc94de34a8fde5..0000000000000000000000000000000000000000
--- a/lib_enc/SNR_calc.c
+++ /dev/null
@@ -1,42 +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
-#include "prot.h"
-#include "rom_enc.h"
-#include "wmc_auto.h"
diff --git a/lib_enc/SNR_calc_fx.c b/lib_enc/SNR_calc_fx.c
index ab994602399f29238f738ea187e57a32e1c59e53..1213a6b320fbd2ea3ee38d2096fb8d866ecb7b89 100644
--- a/lib_enc/SNR_calc_fx.c
+++ b/lib_enc/SNR_calc_fx.c
@@ -10,6 +10,7 @@
#include "prot_fx_enc.h" /* Function prototypes */
#include "rom_enc.h"
#include "rom_com.h"
+#include "prot.h"
/*-------------------------------------------------------------------*
@@ -19,16 +20,15 @@
*-------------------------------------------------------------------*/
void calc_lf_snr_fx(
- Word32 *lf_snr_smooth, /* o : smoothed lf_snr*/
- Word32 *lf_snr, /* o : long time frequency domain
- SNR calculated by l_speech_snr and l_silence_snr*/
- const Word32 l_speech_snr, /* i : sum of active frames snr */
- const Word32 l_speech_snr_count, /* i : amount of the active frame */
- const Word32 l_silence_snr, /* i : sum of the nonactive frames snr*/
- const Word32 l_silence_snr_count, /* i : amount of the nonactive frame */
- const Word16 fg_energy_count, /* i : amount of the foreground energy frame */
- const Word16 bg_energy_count, /* i : amount of the background energy frame */
- const Word16 bw_index /* i : band width index*/
+ Word32 *lf_snr_smooth, /* o : smoothed lf_snr Q25*/
+ Word32 *lf_snr, /* o : long time frequency domain SNR calculated by l_speech_snr and l_silence_snr Q25*/
+ const Word32 l_speech_snr, /* i : sum of active frames snr Q16*/
+ const Word32 l_speech_snr_count, /* i : amount of the active frame Q0*/
+ const Word32 l_silence_snr, /* i : sum of the nonactive frames snr Q16*/
+ const Word32 l_silence_snr_count, /* i : amount of the nonactive frame Q0*/
+ const Word16 fg_energy_count, /* i : amount of the foreground energy frame Q0*/
+ const Word16 bg_energy_count, /* i : amount of the background energy frame Q0*/
+ const Word16 bw_index /* i : band width index Q0*/
)
{
@@ -36,18 +36,18 @@ void calc_lf_snr_fx(
Word16 q_divout, q_divout1;
- div1 = VAD_L_div( l_speech_snr, l_speech_snr_count, 16, 0, &q_divout );
- div2 = VAD_L_div( l_silence_snr, l_silence_snr_count, 16, 0, &q_divout1 );
- l_snr = VAD_L_ADD( div1, q_divout, L_negate( div2 ), q_divout1, &q_divout );
+ div1 = VAD_L_div( l_speech_snr, l_speech_snr_count, 16, 0, &q_divout ); /* q_divout */
+ div2 = VAD_L_div( l_silence_snr, l_silence_snr_count, 16, 0, &q_divout1 ); /* q_divout1 */
+ l_snr = VAD_L_ADD( div1, q_divout, L_negate( div2 ), q_divout1, &q_divout ); /* q_divout */
*lf_snr_smooth = MUL_F( *lf_snr_smooth, 29490 /* 0.9 Q15 */ );
move32();
- tmp = MUL_F( l_snr, 26214 );
- *lf_snr_smooth = VAD_L_ADD( *lf_snr_smooth, 25, tmp, add( 3, q_divout ), &q_divout1 );
+ tmp = MUL_F( l_snr, 26214 /* 0.8 in Q15 */ );
+ *lf_snr_smooth = VAD_L_ADD( *lf_snr_smooth, 25, tmp, add( 3, q_divout ), &q_divout1 ); /* q_divout1 */
move32();
- *lf_snr_smooth = L_shr( *lf_snr_smooth, sub( q_divout1, 25 ) );
+ *lf_snr_smooth = L_shr( *lf_snr_smooth, sub( q_divout1, 25 ) ); /* Q25 */
move32();
- l_snr = L_shr( l_snr, sub( q_divout, 25 ) );
+ l_snr = L_shr( l_snr, sub( q_divout, 25 ) ); /* Q25 */
test();
if ( ( LT_16( bg_energy_count, 56 ) ) || ( LT_16( fg_energy_count, 56 ) ) )
@@ -60,9 +60,9 @@ void calc_lf_snr_fx(
l_snr = L_sub( l_snr, 12079595 /* 0.36 Q25 */ );
l_snr = L_max( 0, l_snr );
- l_snr = L_min( l_snr, MAX_LF_SNR_TAB_FX[bw_index] );
+ l_snr = L_min( l_snr, MAX_LF_SNR_TAB_FX[bw_index] ); /* Q25 */
- *lf_snr = l_snr;
+ *lf_snr = l_snr; /* Q25 */
move32();
return;
}
@@ -73,14 +73,14 @@ void calc_lf_snr_fx(
*-------------------------------------------------------------------*/
void calc_lt_snr_fx(
VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */
- Word32 *lt_snr_org_fp, /* o : original long time SNR*/
- Word32 *lt_snr_fp, /* o : long time SNR calculated by fg_energy and bg_energy*/
- Word32 fg_energy, /* i : foreground energy sum */
- Word16 fg_energy_count, /* i : amount of the foreground energy frame */
- Word32 bg_energy, /* i : background energy sum */
- Word16 bg_energy_count, /* i : amount of the background energy frame */
- Word16 bw_index, /* i : band width index*/
- Word16 lt_noise_sp_center0 /* i : long time noise spectral center by 0*/
+ Word32 *lt_snr_org_fp, /* o : original long time SNR Q25*/
+ Word32 *lt_snr_fp, /* o : long time SNR calculated by fg_energy and bg_energy Q25*/
+ Word32 fg_energy, /* i : foreground energy sum Qx*/
+ Word16 fg_energy_count, /* i : amount of the foreground energy frame Q0*/
+ Word32 bg_energy, /* i : background energy sum Qx*/
+ Word16 bg_energy_count, /* i : amount of the background energy frame Q0*/
+ Word16 bw_index, /* i : band width index Q0*/
+ Word16 lt_noise_sp_center0 /* i : long time noise spectral center by 0 Q10*/
)
{
Word16 tmp_lt_noise_sp_center;
@@ -89,7 +89,7 @@ void calc_lt_snr_fx(
Word32 lt_snr, div1, div2, tmp;
- tmp_lt_noise_sp_center = sub( lt_noise_sp_center0, 1432 /* 1.4 Q10 */ );
+ tmp_lt_noise_sp_center = sub( lt_noise_sp_center0, 1432 /* 1.4 Q10 */ ); /* Q10 */
if ( GT_16( tmp_lt_noise_sp_center, 818 /* 0.8 Q10 */ ) )
{
tmp_lt_noise_sp_center = 818 /* 0.8 Q10 */;
@@ -103,28 +103,29 @@ void calc_lt_snr_fx(
}
div1 = MUL_F( fg_energy, bg_energy_count );
- div1 = VAD_L_ADD( div1, hVAD_CLDFB->fg_energy_scale, 1, 126, &q_div1 );
+ div1 = VAD_L_ADD( div1, hVAD_CLDFB->fg_energy_scale, 1, 126, &q_div1 ); /* q_div1 */
div2 = MUL_F( bg_energy, fg_energy_count );
- div2 = VAD_L_ADD( div2, hVAD_CLDFB->bg_energy_scale, 1, 126, &q_div2 );
- if ( div2 == 0 )
+ div2 = VAD_L_ADD( div2, hVAD_CLDFB->bg_energy_scale, 1, 126, &q_div2 ); /* q_div2 */
+ IF( div2 == 0 )
{
div2 = 1;
move32(); /* div2==0 , may occur for >30000 frames all zero input */
if ( div1 != 0 )
{
hVAD_CLDFB->bg_energy_scale = add( hVAD_CLDFB->fg_energy_scale, 50 );
+ move16();
}
}
- div2 = VAD_L_div( div1, div2, q_div1, q_div2, &q_divout );
+ div2 = VAD_L_div( div1, div2, q_div1, q_div2, &q_divout ); /* q_divout */
lt_snr_org = VAD_Log2( div2, q_divout );
- lt_snr_org = MUL_F( lt_snr_org, 9864 );
- lt_snr = lt_snr_org;
+ lt_snr_org = MUL_F( lt_snr_org, 9864 /* 0.3 in Q15 */ ); /* Q25 */
+ lt_snr = lt_snr_org; /* Q25 */
move32();
- *lt_snr_org_fp = lt_snr;
+ *lt_snr_org_fp = lt_snr; /* Q25 */
move32();
test();
- IF( LT_16( bg_energy_count, 56 ) || LT_16( fg_energy_count, 56 ) )
+ if ( LT_16( bg_energy_count, 56 ) || LT_16( fg_energy_count, 56 ) )
{
lt_snr = 70464302 /* 2.1 Q25 */;
move32();
@@ -132,26 +133,26 @@ void calc_lt_snr_fx(
IF( EQ_16( bw_index, CLDFBVAD_NB_ID ) )
{
- lt_snr = L_sub( L_shr( lt_snr, 1 ), 25165823 /* 0.75 Q25 */ );
+ lt_snr = L_sub( L_shr( lt_snr, 1 ), 25165823 /* 0.75 Q25 */ ); /* Q25 */
}
ELSE IF( EQ_16( bw_index, CLDFBVAD_WB_ID ) )
{
- lt_snr = L_sub( L_shr( lt_snr, 1 ), 25165823 /* 0.75 Q25 */ );
+ lt_snr = L_sub( L_shr( lt_snr, 1 ), 25165823 /* 0.75 Q25 */ ); /* Q25 */
}
ELSE
{
- lt_snr = MUL_F( lt_snr, 15073 /* 0.46 Q15 */ );
- lt_snr = L_sub( lt_snr, 23152557 /* 0.69 Q25 */ );
+ lt_snr = MUL_F( lt_snr, 15073 /* 0.46 Q15 */ ); /* Q25 */
+ lt_snr = L_sub( lt_snr, 23152557 /* 0.69 Q25 */ ); /* Q25 */
}
- tmp = MUL_F( lt_snr, 13107 /* 0.4 Q15 */ );
+ tmp = MUL_F( lt_snr, 13107 /* 0.4 Q15 */ ); /* Q25 */
- tmp = L_add( L_shr( tmp, 1 ), -26214 );
+ tmp = L_add( L_shr( tmp, 1 ), -26214 /* 0.0007 in Q25 */ );
- tmp = MUL_F( tmp, 13107 /* 0.4 Q15 */ );
+ tmp = MUL_F( tmp, 13107 /* 0.4 Q15 */ ); /* Q25 */
tmp = MUL_F( tmp, tmp_lt_noise_sp_center );
- lt_snr = VAD_L_ADD( lt_snr, 25, tmp, 19, &q_divout1 );
- lt_snr = L_shr( lt_snr, sub( q_divout1, 25 ) );
+ lt_snr = VAD_L_ADD( lt_snr, 25, tmp, 19, &q_divout1 ); /* q_divout1 */
+ lt_snr = L_shr( lt_snr, sub( q_divout1, 25 ) ); /* Q25 */
lt_snr = L_max( 0, lt_snr );
@@ -161,7 +162,7 @@ void calc_lt_snr_fx(
move32();
}
- *lt_snr_fp = lt_snr;
+ *lt_snr_fp = lt_snr; /* Q25 */
move32();
return;
}
@@ -172,9 +173,9 @@ void calc_lt_snr_fx(
*
*-------------------------------------------------------------------*/
void calc_snr_flux_fx(
- Word32 tsnr, /* i : time-domain SNR*/
- Word32 *pre_snr, /* i/o: time-domain SNR storage*/
- Word32 *snr_flux_fp /* o : average tsnr*/
+ Word32 tsnr, /* i : time-domain SNR Q25*/
+ Word32 *pre_snr, /* i/o: time-domain SNR storage Q25*/
+ Word32 *snr_flux_fp /* o : average tsnr Q25*/
)
{
Word32 i;
@@ -186,7 +187,7 @@ void calc_snr_flux_fx(
test();
IF( ( LT_32( L_shr( tsnr, 1 ), 43620759 /* 2.6f/2.0f Q25 */ ) ) && tsnr > 0 )
{
- pre_snr[0] = tsnr;
+ pre_snr[0] = tsnr; /* Q25 */
move32();
}
ELSE IF( tsnr <= 0 )
@@ -206,17 +207,17 @@ void calc_snr_flux_fx(
s16MaxCoefNorm = sub( ffr_getSfWord32( pre_snr, 32 ), 5 );
FOR( i = 0; i < 32; i++ )
{
- tmp = L_shl( pre_snr[i], s16MaxCoefNorm );
+ tmp = L_shl( pre_snr[i], s16MaxCoefNorm ); /* Q25 + s16MaxCoefNorm */
snr_flux = L_add( snr_flux, tmp );
}
snr_flux = L_shr( snr_flux, add( s16MaxCoefNorm, 5 ) );
- *snr_flux_fp = snr_flux;
+ *snr_flux_fp = snr_flux; /* Q25 */
move32();
/*update the tsnr storage pre_snr*/
FOR( i = PRE_SNR_NUM - 1; i > 0; i-- )
{
- pre_snr[i] = pre_snr[i - 1];
+ pre_snr[i] = pre_snr[i - 1]; /* Q25 */
move32();
}
return;
@@ -229,12 +230,12 @@ void calc_snr_flux_fx(
*
*-------------------------------------------------------------------*/
void snr_calc(
- VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */
- const Word16 sacle_sbpower, /* i : the Scaling of sbpower*/
- Word32 *snr, /* o : frequency domain SNR */
- Word32 *tsnr, /* o : time domain SNR */
- const Word32 frame_energy, /* i : current frame energy */
- const Word32 bwidth /* i : audio band width*/
+ VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */
+ const Word16 sacle_sbpower, /* i : the Scaling of sbpower */
+ Word32 *snr, /* o : frequency domain SNR Q25*/
+ Word32 *tsnr, /* o : time domain SNR Q25*/
+ const Word32 frame_energy, /* i : current frame energy sacle_sbpower*/
+ const Word32 bwidth /* i : audio band width Q0*/
)
{
Word32 i;
@@ -248,10 +249,12 @@ void snr_calc(
Word16 tmp_addQ1, tmp_addQ2, minscale, minscale1, minscale2, s16MaxCoefNorm, q_divout;
Word32 tmpspec_amp;
Word32 const CONSTfix = 1759218560;
- Word32 snr_tmpidx[12] = { 0 };
+ move32();
+ Word32 snr_tmpidx[12];
+ set_zero_fx( snr_tmpidx, 12 );
- SNR_sb_num = SNR_SUB_BAND_NUM[bwidth - CLDFBVAD_NB_ID];
+ SNR_sb_num = SNR_SUB_BAND_NUM[bwidth - CLDFBVAD_NB_ID]; /* Q0 */
move16();
sb_bg_energy = hVAD_CLDFB->sb_bg_energy;
frame_sb_energy = hVAD_CLDFB->frame_sb_energy;
@@ -262,14 +265,14 @@ void snr_calc(
move32();
FOR( i = 0; i < SNR_sb_num; i++ )
{
- div1 = VAD_L_ADD( frame_sb_energy[i], hVAD_CLDFB->frame_sb_energy_scale, CONSTfix, 44, &tmp_addQ1 );
- div2 = VAD_L_ADD( sb_bg_energy[i], hVAD_CLDFB->sb_bg_energy_scale, CONSTfix, 44, &tmp_addQ2 );
- tmp = VAD_L_div( div1, div2, tmp_addQ1, tmp_addQ2, &q_divout );
+ div1 = VAD_L_ADD( frame_sb_energy[i], hVAD_CLDFB->frame_sb_energy_scale, CONSTfix, 44, &tmp_addQ1 ); /* tmp_addQ1 */
+ div2 = VAD_L_ADD( sb_bg_energy[i], hVAD_CLDFB->sb_bg_energy_scale, CONSTfix, 44, &tmp_addQ2 ); /* tmp_addQ2 */
+ tmp = VAD_L_div( div1, div2, tmp_addQ1, tmp_addQ2, &q_divout ); /* q_divout */
tmp = VAD_Log2( tmp, q_divout );
if ( GT_32( tmp, -3355443 /* -0.10 Q25 */ ) )
{
- snr_tmpidx[i] = tmp;
+ snr_tmpidx[i] = tmp; /* Q25 */
move32();
}
}
@@ -277,21 +280,21 @@ void snr_calc(
s16MaxCoefNorm = sub( ffr_getSfWord32( snr_tmpidx, (Word16) SNR_sb_num ), 4 );
FOR( i = 0; i < SNR_sb_num; i++ )
{
- tmpspec_amp = L_shl( snr_tmpidx[i], s16MaxCoefNorm );
+ tmpspec_amp = L_shl( snr_tmpidx[i], s16MaxCoefNorm ); /* Q25 + s16MaxCoefNorm */
snr_tmp = L_add( snr_tmp, tmpspec_amp );
}
snr_tmp = L_max( 0, snr_tmp );
- snr_tmp = MUL_F( snr_tmp, BAND_MUL[bwidth - CLDFBVAD_NB_ID] );
- *snr = L_shr( snr_tmp, s16MaxCoefNorm );
+ snr_tmp = MUL_F( snr_tmp, BAND_MUL[bwidth - CLDFBVAD_NB_ID] ); /* Q25 + s16MaxCoefNorm */
+ *snr = L_shr( snr_tmp, s16MaxCoefNorm ); /* Q25 */
move32();
- IF( bwidth == CLDFBVAD_SWB_ID )
+ IF( EQ_32( bwidth, CLDFBVAD_SWB_ID ) )
{
IF( t_bg_energy )
{
minscale = norm_l( t_bg_energy );
minscale2 = sub( s_min( add( minscale, hVAD_CLDFB->scale_t_bg_energy ), 31 ), 1 );
- tmpsb_eg = L_shr( t_bg_energy, sub( hVAD_CLDFB->scale_t_bg_energy, minscale2 ) );
+ tmpsb_eg = L_shr( t_bg_energy, sub( hVAD_CLDFB->scale_t_bg_energy, minscale2 ) ); /* minscale2 */
constff = L_shr( 1, sub( 31, minscale2 ) );
}
ELSE
@@ -304,12 +307,12 @@ void snr_calc(
move16();
}
div2 = L_add( tmpsb_eg, constff );
- tmp = VAD_L_div( frame_energy, div2, sacle_sbpower, minscale2, &q_divout );
+ tmp = VAD_L_div( frame_energy, div2, sacle_sbpower, minscale2, &q_divout ); /* q_divout */
IF( tmp )
{
minscale = norm_l( tmp );
minscale2 = sub( s_min( add( minscale, q_divout ), 31 ), 1 );
- tmpsb_eg = L_shr( tmp, limitScale32( sub( q_divout, minscale2 ) ) );
+ tmpsb_eg = L_shr( tmp, limitScale32( sub( q_divout, minscale2 ) ) ); /* minscale2 */
constff = L_shr( 1, sub( 31, minscale2 ) );
tmp = L_add( tmpsb_eg, constff );
}
@@ -323,7 +326,7 @@ void snr_calc(
*tsnr = VAD_Log2( tmp, minscale2 );
move32();
#ifdef BASOP_NOGLOB
- *tsnr = L_add_sat( *tsnr, MUL_F( *tsnr, 6226 ) ); /* *tsnr *= 1.2; */
+ *tsnr = L_add_sat( *tsnr, MUL_F( *tsnr, 6226 ) ); /* *tsnr *= 1.2; Q25*/
#else
*tsnr = L_add( *tsnr, MUL_F( *tsnr, 6226 ) ); /* *tsnr *= 1.2; */
#endif
@@ -335,7 +338,7 @@ void snr_calc(
{
minscale = norm_l( frame_energy );
minscale1 = sub( s_min( add( minscale, sacle_sbpower ), 44 ), 1 );
- tmpframe_eg = L_shr( frame_energy, sub( sacle_sbpower, minscale1 ) );
+ tmpframe_eg = L_shr( frame_energy, sub( sacle_sbpower, minscale1 ) ); /* minscale1 */
constff = L_shr( CONSTfix, sub( 44, minscale1 ) );
}
ELSE
@@ -352,7 +355,7 @@ void snr_calc(
{
minscale = norm_l( t_bg_energy );
minscale2 = sub( s_min( add( minscale, hVAD_CLDFB->scale_t_bg_energy ), 44 ), 1 );
- tmpsb_eg = L_shr( t_bg_energy, sub( hVAD_CLDFB->scale_t_bg_energy, minscale2 ) );
+ tmpsb_eg = L_shr( t_bg_energy, sub( hVAD_CLDFB->scale_t_bg_energy, minscale2 ) ); /* minscale2 */
constff = L_shr( CONSTfix, sub( 44, minscale2 ) );
}
ELSE
@@ -365,29 +368,29 @@ void snr_calc(
move16();
}
div2 = L_add( tmpsb_eg, constff );
- tmp = VAD_L_div( div1, div2, minscale1, minscale2, &q_divout );
- *tsnr = VAD_Log2( tmp, q_divout );
+ tmp = VAD_L_div( div1, div2, minscale1, minscale2, &q_divout ); /* q_divout */
+ *tsnr = VAD_Log2( tmp, q_divout ); /* Q25 */
move32();
}
return;
}
Word32 construct_snr_thresh_fx(
- Word16 sp_center[], /* i : spectral center*/
- Word32 snr_flux, /* i : snr flux*/
- Word32 lt_snr, /* i : long time time domain snr*/
- Word32 l_snr, /* i : long time frequency domain snr*/
- Word32 continuous_speech_num, /* i : amount of continuous speech frames*/
- Word16 continuous_noise_num, /* i : amount of continuous noise frames*/
- Word32 fg_energy_est_start, /* i : whether if estimated energy*/
- Word16 bw_index /* i : band width index*/
+ Word16 sp_center[], /* i : spectral center Q10*/
+ Word32 snr_flux, /* i : snr flux Q25*/
+ Word32 lt_snr, /* i : long time time domain snr Q25*/
+ Word32 l_snr, /* i : long time frequency domain snr Q25*/
+ Word32 continuous_speech_num, /* i : amount of continuous speech frames Q0*/
+ Word16 continuous_noise_num, /* i : amount of continuous noise frames Q0*/
+ Word32 fg_energy_est_start, /* i : whether if estimated energy Q0*/
+ Word16 bw_index /* i : band width index Q0*/
)
{
Word32 bw_snr, tmp_snr, snr_delta, test_l_snr, tmp, div1, div2;
- snr_delta = COMVAD_INIT_SNR_DELTA_FX[bw_index];
+ snr_delta = COMVAD_INIT_SNR_DELTA_FX[bw_index]; /* Q25 */
move32();
bw_snr = lt_snr;
move32();
@@ -397,109 +400,108 @@ Word32 construct_snr_thresh_fx(
move32();
IF( EQ_16( bw_index, CLDFBVAD_SWB_ID ) )
{
-
IF( GT_16( sp_center[2], 2660 /* 2.6 Q10 */ ) )
{
- snr_delta = L_add( snr_delta, 1006633 /* 0.03 Q25 */ );
+ snr_delta = L_add( snr_delta, 1006633 /* 0.03 Q25 */ ); /* Q25 */
}
ELSE IF( GT_16( sp_center[2], 1637 /* 1.6 Q10 */ ) )
{
- snr_delta = L_add( snr_delta, 1677722 /* 0.05 Q25 */ );
+ snr_delta = L_add( snr_delta, 1677722 /* 0.05 Q25 */ ); /* Q25 */
}
ELSE IF( GT_16( sp_center[3], 1432 /* 1.4 Q10 */ ) )
{
- snr_delta = L_add( snr_delta, 3355443 /* 0.10 Q25 */ );
+ snr_delta = L_add( snr_delta, 3355443 /* 0.10 Q25 */ ); /* Q25 */
}
ELSE
{
- snr_delta = L_add( snr_delta, 13421773 /* 0.40 Q25 */ );
+ snr_delta = L_add( snr_delta, 13421773 /* 0.40 Q25 */ ); /* Q25 */
}
- tmp = MUL_F( l_snr, 3277 /* 0.1 Q15 */ );
+ tmp = MUL_F( l_snr, 3277 /* 0.1 Q15 */ ); /* Q25 */
tmp = L_add( tmp, 20132659 /* 0.6 Q25 */ );
test();
test();
IF( GT_32( continuous_speech_num, 8 ) && EQ_32( fg_energy_est_start, 1 ) )
{
- snr_delta = L_sub( snr_delta, 6710886 /* 0.2 Q25 */ );
+ snr_delta = L_sub( snr_delta, 6710886 /* 0.2 Q25 */ ); /* Q25 */
}
ELSE IF( GT_16( continuous_noise_num, 12 ) && ( GT_32( snr_flux, tmp ) ) )
{
- snr_delta = L_add( snr_delta, 3355443 /* 0.10 Q25 */ );
+ snr_delta = L_add( snr_delta, 3355443 /* 0.10 Q25 */ ); /* Q25 */
}
ELSE IF( GT_16( continuous_noise_num, 24 ) )
{
- snr_delta = L_add( snr_delta, 6710886 /* 0.2 Q25 */ );
+ snr_delta = L_add( snr_delta, 6710886 /* 0.2 Q25 */ ); /* Q25 */
}
ELSE IF( ( GT_16( continuous_noise_num, 4 ) ) )
{
- snr_delta = L_add( snr_delta, 3355443 /* 0.10 Q25 */ );
+ snr_delta = L_add( snr_delta, 3355443 /* 0.10 Q25 */ ); /* Q25 */
}
}
ELSE IF( EQ_16( bw_index, CLDFBVAD_WB_ID ) )
{
IF( GT_16( sp_center[2], 2660 /* 2.6 Q10 */ ) )
{
- snr_delta = L_add( snr_delta, 1006633 /* 0.03 Q25 */ );
+ snr_delta = L_add( snr_delta, 1006633 /* 0.03 Q25 */ ); /* Q25 */
}
ELSE IF( GT_16( sp_center[2], 1637 /* 1.6 Q10 */ ) )
{
- snr_delta = L_add( snr_delta, 1677722 /* 0.05 Q25 */ );
+ snr_delta = L_add( snr_delta, 1677722 /* 0.05 Q25 */ ); /* Q25 */
}
ELSE IF( GT_16( sp_center[3], 1432 /* 1.4 Q10 */ ) )
{
- snr_delta = L_add( snr_delta, 3355443 /* 0.10 Q25 */ );
+ snr_delta = L_add( snr_delta, 3355443 /* 0.10 Q25 */ ); /* Q25 */
}
ELSE
{
- snr_delta = L_add( snr_delta, 10066330 /* 0.30 Q25 */ );
+ snr_delta = L_add( snr_delta, 10066330 /* 0.30 Q25 */ ); /* Q25 */
}
- tmp = MUL_F( bw_snr, 3277 /* 0.1 Q15 */ );
- tmp = L_add( tmp, 20132659 /* 0.6 Q25 */ );
+ tmp = MUL_F( bw_snr, 3277 /* 0.1 Q15 */ ); /* Q25 */
+ tmp = L_add( tmp, 20132659 /* 0.6 Q25 */ ); /* Q25 */
test();
test();
IF( GT_32( continuous_speech_num, 8 ) && EQ_32( fg_energy_est_start, 1 ) )
{
- snr_delta = L_sub( snr_delta, 3355443 /* 0.10 Q25 */ );
+ snr_delta = L_sub( snr_delta, 3355443 /* 0.10 Q25 */ ); /* Q25 */
}
ELSE IF( GT_16( continuous_noise_num, 12 ) && ( GT_32( snr_flux, tmp ) ) )
{
- snr_delta = L_add( snr_delta, 3355443 /* 0.10 Q25 */ );
+ snr_delta = L_add( snr_delta, 3355443 /* 0.10 Q25 */ ); /* Q25 */
}
ELSE IF( GT_16( continuous_noise_num, 24 ) )
{
- snr_delta = L_add( snr_delta, 6710886 /* 0.20 Q25 */ );
+ snr_delta = L_add( snr_delta, 6710886 /* 0.20 Q25 */ ); /* Q25 */
}
ELSE IF( ( GT_16( continuous_noise_num, 4 ) ) )
{
- snr_delta = L_add( snr_delta, 3355443 /* 0.10 Q25 */ );
+ snr_delta = L_add( snr_delta, 3355443 /* 0.10 Q25 */ ); /* Q25 */
}
}
ELSE IF( EQ_16( bw_index, CLDFBVAD_NB_ID ) )
{
IF( GT_16( sp_center[2], 2660 /* 2.6 Q10 */ ) )
{
- snr_delta = L_add( snr_delta, 671089 /* 0.02 Q25 */ );
+ snr_delta = L_add( snr_delta, 671089 /* 0.02 Q25 */ ); /* Q25 */
}
ELSE IF( GT_16( sp_center[2], 1637 /* 1.6 Q10 */ ) )
{
- snr_delta = L_add( snr_delta, 1342177 /* 0.04 Q25 */ );
+ snr_delta = L_add( snr_delta, 1342177 /* 0.04 Q25 */ ); /* Q25 */
}
ELSE IF( GT_16( sp_center[2], 1494 /* 1.46 Q10 */ ) )
{
- snr_delta = L_add( snr_delta, 3355443 /* 0.10 Q25 */ );
+ snr_delta = L_add( snr_delta, 3355443 /* 0.10 Q25 */ ); /* Q25 */
}
ELSE
{
- snr_delta = L_add( snr_delta, 6039798 /* 0.18 Q25 */ );
+ snr_delta = L_add( snr_delta, 6039798 /* 0.18 Q25 */ ); /* Q25 */
}
- tmp = MUL_F( l_snr, 3277 /* 0.1 Q15 */ );
- div1 = L_add( tmp, 6710886 /* 0.2 Q25 */ );
- div2 = L_add( tmp, 20132659 /* 0.6 Q25 */ );
+ tmp = MUL_F( l_snr, 3277 /* 0.1 Q15 */ ); /* Q25 */
+ div1 = L_add( tmp, 6710886 /* 0.2 Q25 */ ); /* Q25 */
+ div2 = L_add( tmp, 20132659 /* 0.6 Q25 */ ); /* Q25 */
test();
test();
@@ -508,19 +510,19 @@ Word32 construct_snr_thresh_fx(
test();
IF( GT_32( continuous_speech_num, 80 ) && EQ_32( fg_energy_est_start, 1 ) && ( GT_16( sp_center[0], 1432 /* 1.4 Q10 */ ) ) )
{
- snr_delta = L_sub( snr_delta, 10737418 /* 0.32 Q25 */ );
+ snr_delta = L_sub( snr_delta, 10737418 /* 0.32 Q25 */ ); /* Q25 */
}
ELSE IF( GT_32( continuous_speech_num, 8 ) && EQ_32( fg_energy_est_start, 1 ) && ( GT_32( snr_flux, div1 ) ) )
{
- snr_delta = L_sub( snr_delta, 3355443 /* 0.10 Q25 */ );
+ snr_delta = L_sub( snr_delta, 3355443 /* 0.10 Q25 */ ); /* Q25 */
}
ELSE IF( GT_16( continuous_noise_num, 12 ) && ( GT_32( snr_flux, div2 ) ) )
{
- snr_delta = L_add( snr_delta, 3355443 /* 0.10 Q25 */ );
+ snr_delta = L_add( snr_delta, 3355443 /* 0.10 Q25 */ ); /* Q25 */
}
ELSE IF( GT_16( continuous_noise_num, 24 ) )
{
- snr_delta = L_add( snr_delta, 6710886 /* 0.2 Q25 */ );
+ snr_delta = L_add( snr_delta, 6710886 /* 0.2 Q25 */ ); /* Q25 */
}
}
ELSE
@@ -528,7 +530,7 @@ Word32 construct_snr_thresh_fx(
snr_delta = 33554431 /* 1.0 Q25 */;
move32();
}
- tmp_snr = L_add( snr_delta, test_l_snr );
+ tmp_snr = L_add( snr_delta, test_l_snr ); /* Q25 */
return tmp_snr;
diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c
deleted file mode 100644
index 241930867807386311380f3ce3de784c921ecad9..0000000000000000000000000000000000000000
--- a/lib_enc/acelp_core_enc.c
+++ /dev/null
@@ -1,970 +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
-#include "cnst.h"
-#include "rom_enc.h"
-#include "rom_com.h"
-#include "prot.h"
-#include "ivas_cnst.h"
-#include "ivas_prot.h"
-#include "ivas_prot_fx.h"
-#include "prot_fx.h"
-#include "prot_fx_enc.h"
-#include "ivas_rom_com.h"
-#include "wmc_auto.h"
-#include "options_warnings.h"
-
-#include "prot_fx_enc.h"
-#include "prot_fx.h"
-
-/*-------------------------------------------------------------------*
- * acelp_core_enc()
- *
- * ACELP core encoder
- *--------------------------------------------------------------------*/
-ivas_error acelp_core_enc(
- Encoder_State *st, /* i/o: encoder state structure */
- const Word16 inp[], /* i : input signal of the current frame */
- Word16 A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes*/
- Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes*/
- const Word32 epsP[M + 1], /* i : LP prediction errors */
- Word16 lsp_new[M], /* i : LSPs at the end of the frame */
- Word16 lsp_mid[M], /* i : LSPs in the middle of the frame */
- const Word16 vad_hover_flag, /* i : VAD hangover flag */
- const Word16 attack_flag, /* i : attack flag (GSC or TC) */
- Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation */
- Word16 *voice_factors_fx, /* o : voicing factors Q15 */
- Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */
- Word16 *q_old_syn_12k8_16,
- Word16 pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */
- Word16 *unbits, /* o : number of unused bits */
- STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */
- Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */
- Word16 Q_new )
-{
- Word16 i, nBits; /* reserved bits */
- LPD_state_HANDLE hLPDmem; /* i/o: acelp memories */
- Word16 tc_subfr; /* TC sub-frame indication */
- Word16 allow_cn_step;
- Word32 int_fs;
- Word16 nb_bits; /* parameters handling */
-
- /* SC-VBR - back-up memories for LSF quantizer and synthesis filter */
- Word16 pstreaklen;
- Word16 sid_bw = -1;
- Word16 next_force_sf_bck;
- Word16 uc_two_stage_flag;
- Word16 position;
- Word16 ppp_mode, nelp_mode;
- Word16 tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag;
-
- /* bitstream */
- BSTR_ENC_HANDLE hBstr = st->hBstr;
- Word16 old_exc_fx[L_EXC], *exc_fx; /* excitation signal buffer */
- Word16 lsf_new_fx[M]; /* ISFs at the end of the frame */
- Word16 Aq[NB_SUBFR16k * ( M + 1 )]; /* A(z) quantized for the 4 subframes */
- Word16 syn_fx[L_FRAME16k]; /* synthesis vector */
- Word16 res_fx[L_FRAME16k]; /* Residual signal for FER protection */
- Word16 exc2_fx[L_FRAME16k]; /* enhanced excitation */
- Word16 Es_pred_fx; /* predicited scaled innovation energy */
- Word16 tmp_noise_fx; /* NB post-filter long-term noise energy*/
- Word16 old_bwe_exc_fx[( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2]; /* excitation buffer Q_new */
- Word16 *bwe_exc_fx; /* excitation for SWB TBE Q_new */
- Word16 mem_MA_fx[M], mem_AR_fx[M], lsp_new_bck_fx[M], /*lsf_new_bck_fx[M],*/ lsp_mid_bck_fx[M], mem_syn_bck_fx[M];
- Word32 Bin_E_fx[L_FFT], Bin_E_old_fx[L_FFT / 2];
- Word16 clip_var_fx, mem_w0_bck_fx, streaklimit_fx;
-
-#ifdef MSAN_FIX
- set16_fx( old_bwe_exc_fx, 0, ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 );
- set16_fx( old_exc_fx, 0, L_EXC );
- set16_fx( Aq, 0, NB_SUBFR16k * ( M + 1 ) );
- set16_fx( syn_fx, 0, L_FRAME16k );
-#endif
-
- Word16 tilt_code_bck_fx;
- Word32 gc_threshold_bck_fx;
- Word16 clip_var_bck_fx[6];
- Word32 q_env_fx[NUM_ENV_CNG];
-#ifdef MSAN_FIX
- set32_fx( q_env_fx, 0, NUM_ENV_CNG );
-#endif
- Word16 exc3_fx[L_FRAME16k];
- Word16 syn1_fx[L_FRAME16k];
- Word16 *tdm_Pri_pitch_buf_fx;
-
- Word16 att_fx;
- Word16 tmpF_fx;
-
- test();
- IF( !st->Opt_AMR_WB && st->hBWE_TD != NULL )
- {
- Scale_sig( st->hBWE_TD->old_bwe_exc_fx, PIT16k_MAX * 2, sub( Q_new, st->prev_Q_new ) ); // Q_new
- }
- IF( st->hLPDmem )
- {
- Scale_sig( st->hLPDmem->old_exc, L_EXC_MEM, sub( Q_new, st->hLPDmem->q_lpd_old_exc ) ); // Q_new
- st->hLPDmem->q_lpd_old_exc = Q_new;
- move16();
- Scale_sig( st->hLPDmem->syn, M + 1, sub( Q_new, st->hLPDmem->q_lpd_syn ) ); // Q_new
- st->hLPDmem->q_lpd_syn = Q_new;
- move16();
- Scale_sig( st->hLPDmem->mem_syn, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); // Q_new -1
- Scale_sig( st->hLPDmem->mem_syn1_fx, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); // Q_new -1
- Scale_sig( st->hLPDmem->mem_syn2, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); // Q_new -1
- Scale_sig( st->hLPDmem->mem_syn3, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); // Q_new -1
- Scale_sig( st->hLPDmem->mem_syn_r, L_SYN_MEM, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); // Q_new -1
- st->hLPDmem->mem_w0 = shl_sat( st->hLPDmem->mem_w0, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); // Q_new -1
- move16();
- st->hLPDmem->q_mem_syn = sub( Q_new, 1 );
- move16();
- }
-
- Scale_sig32( st->Bin_E_old_fx, L_FFT / 2, sub( add( Q_new, Q_SCALE - 2 ), st->q_Bin_E_old ) ); // Q_new + Q_scale - 2
- st->q_Bin_E_old = add( Q_new, Q_SCALE - 2 );
- move16();
- Scale_sig32( st->Bin_E_fx, L_FFT, sub( add( Q_new, Q_SCALE - 2 ), st->q_Bin_E ) ); // Q_new + Q_scale - 2
- st->q_Bin_E = add( Q_new, Q_SCALE - 2 );
- move16();
-
- ivas_error error;
-
- error = IVAS_ERR_OK;
- move32();
-
- test();
- IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && LE_32( st->core_brate, SID_2k40 ) )
- {
- /* Core was ACELP because of DTX in MDCT-Stereo, but SID encoding for that is done in separate function */
- return error;
- }
-
- push_wmops( "acelp_core_enc" );
- /*------------------------------------------------------------------*
- * Initialization
- *------------------------------------------------------------------*/
-
- hLPDmem = st->hLPDmem;
-
- Es_pred_fx = 0;
- move16();
-
- exc_fx = old_exc_fx + L_EXC_MEM; /* pointer to excitation signal in the current frame */
- Copy( hLPDmem->old_exc, old_exc_fx, L_EXC_MEM );
- Scale_sig( old_exc_fx, L_EXC_MEM, sub( Q_new, hLPDmem->q_lpd_old_exc ) ); // Q_new
- IF( st->hBWE_TD != NULL )
- {
- bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2; /* pointer to BWE excitation signal in the current frame */
- Copy( st->hBWE_TD->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2 );
- }
- ELSE
- {
- bwe_exc_fx = NULL;
- }
-
- st->bpf_off = 0;
- move16();
-
- test();
- test();
- test();
- IF( EQ_16( st->last_core, HQ_CORE ) || EQ_16( st->last_codec_mode, MODE2 ) || EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) )
- {
- /* in case of HQ->ACELP switching, do not apply BPF */
- st->bpf_off = 1;
- move16();
- /* reset the GSC pre echo energy threshold in case of switching */
- if ( st->hGSCEnc != NULL )
- {
- st->hGSCEnc->Last_frame_ener_fx = MAX_32;
- move32();
- }
- }
-
- /* force safety-net LSFQ in the first frames after CNG segment */
- if ( LE_32( st->last_core_brate, SID_2k40 ) )
- {
- st->Nb_ACELP_frames = 0;
- move16();
- }
- st->Nb_ACELP_frames = add( st->Nb_ACELP_frames, 1 );
- move16();
-
- IF( EQ_16( st->L_frame, L_FRAME ) )
- {
- int_fs = INT_FS_12k8;
- move32();
- }
- ELSE
- {
- int_fs = INT_FS_16k;
- move32();
- }
-
- tmp_noise_fx = 0;
- move16();
- tc_subfr = -1;
- move16();
- position = -1;
- move16();
-
- /* SC-VBR temporary variables */
- pstreaklen = 0;
- move16();
- clip_var_fx = 0;
- move16();
- mem_w0_bck_fx = 0;
- move16();
- streaklimit_fx = 0;
- move16();
-
- /* channel-aware mode */
- reset_rf_indices_fx( st );
-
- /* VBR modes */
- IF( st->Opt_SC_VBR )
- {
- ppp_mode = st->hSC_VBR->ppp_mode;
- nelp_mode = st->hSC_VBR->nelp_mode;
- }
- ELSE
- {
- ppp_mode = 0;
- nelp_mode = 0;
- }
- move16();
- move16();
-
- test();
- /* TD stereo */
-
- IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) )
- {
- tdm_lp_reuse_flag = hStereoTD->tdm_lp_reuse_flag;
- tdm_low_rate_mode = hStereoTD->tdm_low_rate_mode;
- tdm_Pitch_reuse_flag = hStereoTD->tdm_Pitch_reuse_flag;
- tdm_Pri_pitch_buf_fx = hStereoTD->tdm_Pri_pitch_buf_fx;
- }
- ELSE
- {
- tdm_lp_reuse_flag = 0;
- tdm_low_rate_mode = 0;
- test();
- if ( EQ_16( st->element_mode, IVAS_SCE ) && st->low_rate_mode )
- {
- tdm_low_rate_mode = 1;
- move16();
- }
- tdm_Pitch_reuse_flag = 0;
- tdm_Pri_pitch_buf_fx = NULL;
- }
- move16();
- move16();
- move16();
-
- /*-----------------------------------------------------------------*
- * ACELP@12k8 / ACELP@16k switching
- *-----------------------------------------------------------------*/
-
- test();
- test();
- IF( NE_16( st->last_L_frame, st->L_frame ) && ( st->last_core == ACELP_CORE || EQ_16( st->last_core, AMR_WB_CORE ) ) )
- {
- /* in case of switching, do not apply BPF (flag employed also in updt_enc()) */
- st->bpf_off = 1;
- move16();
-
- /* force safety-net LSFQ in the first frames after ACELP@12k8/ACELP@16k switching */
- st->Nb_ACELP_frames = 1;
- move16();
-
- /* convert old quantized LSP vector */
- IF( EQ_16( st->L_frame, L_FRAME ) )
- {
- st->rate_switching_reset = lsp_convert_poly_fx( st->lsp_old_fx, st->L_frame, 0 );
- move16();
- }
- ELSE
- {
- st->rate_switching_reset = st->rate_switching_reset_16kHz;
- move16();
- Copy( st->lsp_old16k_fx, st->lsp_old_fx, M ); // Q15
- }
-
- /* convert old quantized LSF vector */
- lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, int_fs );
-
- /* interpolation of unquantized ISPs */
- IF( st->rate_switching_reset )
- {
- /*extrapolation in case of unstable LSP*/
- int_lsp4_ivas_fx( st->L_frame, lsp_mid, lsp_mid, lsp_new, A, M, 0 );
- }
- ELSE
- {
- int_lsp4_ivas_fx( st->L_frame, st->lsp_old_fx, lsp_mid, lsp_new, A, M, 0 );
- }
-
- /* Reset LPC mem */
- Copy( GEWB_Ave_fx, st->mem_AR_fx, M );
- set16_fx( st->mem_MA_fx, 0, M );
-
- /* update synthesis filter memories */
- synth_mem_updt2( st->L_frame, st->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn2, hLPDmem->mem_syn, ENC );
- Copy( hLPDmem->old_exc, old_exc_fx, L_EXC_MEM );
- Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn1_fx, M );
- Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn3, M );
-
- /* update Aw[] coefficients */
- weight_a_subfr_fx( shr( st->L_frame, 6 ), A, Aw, st->gamma, M );
- }
- IF( st->hLPDmem )
- {
- st->hLPDmem->q_mem_syn = sub( Q_new, 1 );
- move16();
- st->hLPDmem->q_lpd_old_exc = Q_new;
- move16();
- st->hLPDmem->q_lpd_syn = Q_new;
- move16();
- }
-
- test();
- test();
- if ( st->last_bwidth == NB && st->bwidth != NB && st->ini_frame != 0 )
- {
- st->rate_switching_reset = 1;
- move16();
- }
-
- /*----------------------------------------------------------------*
- * Encoding of CNG frames
- *----------------------------------------------------------------*/
- test();
- IF( EQ_32( st->core_brate, SID_2k40 ) || EQ_32( st->core_brate, FRAME_NO_DATA ) )
- {
- IF( EQ_16( st->cng_type, LP_CNG ) )
- {
- /* Run CNG post parameter update */
- cng_params_postupd_ivas_fx( st->hTdCngEnc->ho_circ_ptr, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hTdCngEnc->ho_env_circ_fx, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth );
-
- /* encode CNG parameters */
- CNG_enc_ivas_fx( st, Aq, inp, /*ener_fx,*/ lsp_mid, lsp_new, lsf_new_fx, &allow_cn_step, sub( Q_new, 1 ), q_env_fx, &sid_bw );
-
- /* comfort noise generation */
- CNG_exc_fx( st->core_brate, st->L_frame, &st->hTdCngEnc->Enew_fx, &st->hTdCngEnc->cng_seed, exc_fx, exc2_fx, &st->hTdCngEnc->lp_ener_fx, st->last_core_brate,
- &st->hDtxEnc->first_CNG, &st->hTdCngEnc->cng_ener_seed, bwe_exc_fx, allow_cn_step, &st->hTdCngEnc->last_allow_cn_step, sub( st->prev_Q_new, 1 ), sub( Q_new, 1 ), st->hTdCngEnc->num_ho,
- q_env_fx, st->hTdCngEnc->lp_env_fx, st->hTdCngEnc->old_env_fx, st->hTdCngEnc->exc_mem_fx, st->hTdCngEnc->exc_mem1_fx, &sid_bw, &st->hTdCngEnc->cng_ener_seed1, exc3_fx, st->Opt_AMR_WB, EVS_MONO );
-
- Scale_sig( exc_fx, st->L_frame, 1 );
- }
- ELSE
- {
- test();
- IF( EQ_32( st->core_brate, SID_2k40 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) )
- {
- FdCng_encodeSID_ivas_fx( st );
- st->hDtxEnc->last_CNG_L_frame = st->L_frame;
- move16();
- }
-
- Word16 Q_cngNoise = Q31, zero_flag = 0;
- move16();
- move16();
- FOR( Word16 j = 0; j < NPART; j++ )
- {
- IF( st->hFdCngEnc->hFdCngCom->cngNoiseLevel[j] != 0 )
- {
- zero_flag = 1;
- move16();
- BREAK;
- }
- }
- IF( zero_flag )
- {
- Q_cngNoise = getScaleFactor32( st->hFdCngEnc->hFdCngCom->cngNoiseLevel, NPART );
- }
- Scale_sig32( st->hFdCngEnc->hFdCngCom->cngNoiseLevel, NPART, Q_cngNoise );
- st->hFdCngEnc->hFdCngCom->cngNoiseLevelExp = sub( st->hFdCngEnc->hFdCngCom->cngNoiseLevelExp, Q_cngNoise );
- move16();
-
- generate_comfort_noise_enc_ivas_fx( st, Q_new, 1 );
- st->hTcxEnc->q_Txnq = Q_new;
- move16();
- Scale_sig( st->hFdCngEnc->hFdCngCom->A_cng, ( M + 1 ), sub( Q12, sub( 14, norm_s( st->hFdCngEnc->hFdCngCom->A_cng[0] ) ) ) );
- FdCng_exc( st->hFdCngEnc->hFdCngCom, &st->hDtxEnc->CNG_mode, st->L_frame, st->lsp_old_fx, st->hDtxEnc->first_CNG, st->hDtxEnc->lspCNG_fx, Aq, lsp_new, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx );
- Copy( exc2_fx, exc3_fx, st->L_frame );
-
- IF( EQ_32( st->core_brate, SID_2k40 ) )
- {
- IF( st->hTdCngEnc != NULL )
- {
- Word16 enr, enr_index;
- enr = cng_energy_ivas_fx( st->element_mode, st->bwidth, st->hDtxEnc->CNG_mode, st->hTdCngEnc->CNG_att_fx, exc_fx, st->L_frame, Q_new );
-
- /* calculate the energy quantization index */
- enr_index = add( enr, 512 /* Q8(2.0) */ ); /* enr + 2.0 */
- enr_index = extract_l( L_shr( L_mult0( enr_index, STEP_SID_FX ), 12 + 8 ) ); /* Q0 (8+12-(8+12)) */
-
- /* limit the energy quantization index */
- enr_index = s_min( enr_index, 127 );
- enr_index = s_max( enr_index, 0 );
- st->hTdCngEnc->old_enr_index = enr_index;
- move16();
- }
- }
- }
-
- /* Reset HO counter in the first SID frame */
- if ( st->hTdCngEnc != NULL )
- {
- st->hTdCngEnc->burst_ho_cnt = 0;
- move16();
- }
-
- Scale_sig( st->hLPDmem->mem_syn, M, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); // st->Q_syn
- Scale_sig( st->hLPDmem->mem_syn1_fx, M, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); // st->Q_syn
- Scale_sig( st->hLPDmem->mem_syn2, M, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); // st->Q_syn
- Scale_sig( st->hLPDmem->mem_syn3, M, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); // st->Q_syn
- Scale_sig( st->hLPDmem->mem_syn_r, L_SYN_MEM, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); // st->Q_syn
- st->hLPDmem->mem_w0 = shl_sat( st->hLPDmem->mem_w0, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); // st->Q_syn
- move16();
- st->hLPDmem->q_mem_syn = st->Q_syn;
- move16();
-
- /* synthesis at 12.8kHz sampling rate */
- syn_12k8_fx( st->L_frame, Aq, exc3_fx, syn1_fx, hLPDmem->mem_syn3, 1, sub( Q_new, 1 ), st->Q_syn );
-
- /* reset the encoder */
- CNG_reset_enc_fx( st, hLPDmem, pitch_buf, voice_factors_fx, 0 );
-
- /* update st->mem_syn1_flt for ACELP core switching */
- Copy( hLPDmem->mem_syn3, hLPDmem->mem_syn1_fx, M );
-
- /* update ACELP core synthesis filter memory */
- Copy( hLPDmem->mem_syn3, hLPDmem->mem_syn, M );
-
- /* update old synthesis buffer - needed for ACELP internal sampling rate switching */
- Copy( syn1_fx + sub( st->L_frame, L_SYN_MEM ), hLPDmem->mem_syn_r, L_SYN_MEM );
-
- /* save and delay synthesis to be used by SWB BWE */
- IF( st->hBWE_FD != NULL )
- {
- st->hBWE_FD->mem_deemph_old_syn_fx = shl_sat( st->hBWE_FD->mem_deemph_old_syn_fx, sub( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ) );
- move16();
- Scale_sig( st->hBWE_FD->old_syn_12k8_16k_fx, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ), sub( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ) );
- save_old_syn_fx( st->L_frame, syn1_fx, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx );
- *q_old_syn_12k8_16 = st->Q_syn;
- move16();
- st->hBWE_FD->q_mem_deemph_old_syn = st->Q_syn;
- move16();
- }
-
- Scale_sig( st->hLPDmem->syn, M + 1, sub( st->Q_syn, st->hLPDmem->q_lpd_syn ) );
- st->hLPDmem->q_lpd_syn = st->Q_syn;
- move16();
-
- /*Update MODE2 core switching memory*/
- deemph_fx( syn1_fx, st->preemph_fac, st->L_frame, &( hLPDmem->syn[M] ) );
- Copy( syn1_fx + add( st->L_frame, -M - 1 ), hLPDmem->syn, M + 1 );
- }
-
- /*----------------------------------------------------------------*
- * Encoding of all other frames
- *----------------------------------------------------------------*/
- ELSE
- {
-
- /*-----------------------------------------------------------------*
- * Configure ACELP bit allocation
- *-----------------------------------------------------------------*/
-
- Word16 temp = getScaleFactor16( st->hGSCEnc->last_exc_dct_in_fx, L_FRAME16k );
- Scale_sig( st->hGSCEnc->last_exc_dct_in_fx, L_FRAME16k, temp );
- st->hGSCEnc->Q_last_exc_dct_in = add( st->hGSCEnc->Q_last_exc_dct_in, temp );
- move16();
- nb_bits = 0;
- move16();
- st->acelp_cfg.FEC_mode = 0;
- move16();
- uc_two_stage_flag = 0;
- move16();
-
- test();
- IF( !nelp_mode && !ppp_mode )
- {
- config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode );
- }
-
- /*-----------------------------------------------------------------*
- * After inactive period, use the most up-to-date ISPs
- *-----------------------------------------------------------------*/
-
- test();
- test();
- IF( st->hDtxEnc != NULL && ( st->last_core_brate == FRAME_NO_DATA || EQ_32( st->last_core_brate, SID_2k40 ) ) )
- {
- Copy( st->hDtxEnc->lspCNG_fx, st->lsp_old_fx, M ); // Q15
- lsp2lsf_fx( st->hDtxEnc->lspCNG_fx, st->lsf_old_fx, M, int_fs );
- }
-
- /*-----------------------------------------------------------------*
- * Reset higher ACELP pre-quantizer in case of switching
- *-----------------------------------------------------------------*/
-
- IF( !st->use_acelp_preq )
- {
- st->mem_deemp_preQ_fx = 0;
- move16();
- st->mem_preemp_preQ_fx = 0;
- move16();
- st->last_code_preq = 0;
- move16();
- st->last_nq_preQ = 0;
- move16();
- }
- st->use_acelp_preq = 0;
- move16();
-
- /*-----------------------------------------------------------------*
- * LSF Quantization
- * A[z] calculation
- *-----------------------------------------------------------------*/
-
- /* SC-VBR & channel-aware mode - back-up memories for LSF quantizer and synthesis filter */
- lsf_syn_mem_backup_ivas_fx( st, &tilt_code_bck_fx, &gc_threshold_bck_fx, clip_var_bck_fx, &next_force_sf_bck, lsp_new, lsp_mid, &clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsp_mid_bck_fx, Bin_E_fx, Bin_E_old_fx, mem_syn_bck_fx, &mem_w0_bck_fx, &streaklimit_fx, &pstreaklen );
-
- IF( !tdm_lp_reuse_flag )
- {
- lsf_enc_ivas_fx( st, lsf_new_fx, lsp_new, lsp_mid, Aq, tdm_low_rate_mode, st->GSC_IVAS_mode, tdm_lsfQ_PCh, Q_new );
- }
- ELSE
- {
- const Word16 *pt_interp_2_fx;
-
- IF( NE_16( st->active_cnt, 1 ) )
- {
- Word16 beta_index;
- Word16 lsf_wgts_fx[M];
-
- /* intra_frame prediction for the LSFs */
- lsp2lsf_fx( lsp_new, lsf_new_fx, M, 12800 );
-
- Unified_weighting_fx( &st->Bin_E_fx[L_FFT / 2], add( Q_new, ( QSCALE - 2 ) ), lsf_new_fx, lsf_wgts_fx, st->bwidth == NB, (Word16) EQ_16( st->coder_type, UNVOICED ), st->sr_core, M );
-
- tdm_SCh_lsf_reuse_fx( ENC, st->element_brate, lsf_new_fx, lsp_new, tdm_lsfQ_PCh, lsf_wgts_fx, &beta_index );
-
- push_indice( hBstr, IND_IC_LSF_PRED, beta_index, TDM_IC_LSF_PRED_BITS );
- }
-
- pt_interp_2_fx = interpol_frac_12k8_fx;
-
- test();
- if ( EQ_16( tdm_low_rate_mode, 1 ) && GT_16( st->coder_type, UNVOICED ) )
- {
- pt_interp_2_fx = interpol_frac2_fx;
- }
-
- IF( EQ_16( st->active_cnt, 1 ) )
- {
- Copy( lsp_new, st->lsp_old_fx, M ); // Q15
- lsp2lsf_fx( lsp_new, st->lsf_old_fx, M, st->sr_core ); // Q x2.56
- lsp2lsf_fx( lsp_new, lsf_new_fx, M, st->sr_core ); // Q x2.56
- }
-
- /* LSP interpolation and conversion of LSPs to A(z) */
- int_lsp_fx( st->L_frame, st->lsp_old_fx, lsp_new, Aq, M, pt_interp_2_fx, 0 );
-
- /* Check LSF stability (distance between old LSFs and current LSFs) */
- st->stab_fac_fx = lsf_stab_fx( lsf_new_fx, st->lsf_old_fx, 0, st->L_frame ); // Q15
- }
- test();
- IF( EQ_16( st->last_core, HQ_CORE ) && st->element_mode > EVS_MONO )
- {
- /* Prepare ACB memory from last HQ frame */
- tmpF_fx = hLPDmem->old_exc[0];
- PREEMPH_FX( hLPDmem->old_exc, st->preemph_fac, st->L_frame, &tmpF_fx );
- Copy( hLPDmem->old_exc + sub( st->L_frame, M ), hLPDmem->mem_syn, M );
- Residu3_fx( Aq, hLPDmem->old_exc, old_exc_fx, st->L_frame, 0 );
- }
-
- test();
- IF( st->last_core != ACELP_CORE && st->element_mode > EVS_MONO )
- {
- /* Prepare ACB memory of old_bwe_exc */
- IF( EQ_16( st->L_frame, L_FRAME ) )
- {
- lerp( old_exc_fx, old_bwe_exc_fx, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC );
- }
- ELSE
- {
- lerp( old_exc_fx, old_bwe_exc_fx, L_EXC_MEM_DEC * 2, L_EXC_MEM_DEC );
- }
- }
-
- /*---------------------------------------------------------------*
- * Calculation of LP residual (filtering through A[z] filter)
- *---------------------------------------------------------------*/
-
- calc_residu_fx( st, inp, res_fx, Aq );
- calculate_hangover_attenuation_gain_ivas_fx( st, &att_fx, vad_hover_flag );
-
- IF( NE_16( att_fx, 32767 /* ONE_IN_Q15 */ ) )
- {
- v_multc_fixed_16_16( res_fx, att_fx, res_fx, st->L_frame );
- }
-
- /*-----------------------------------------------------------------*
- * Determine TC subframe classification
- *-----------------------------------------------------------------*/
-
- IF( EQ_16( st->coder_type, TRANSITION ) )
- {
- tc_classif_enc_fx( Q_new, st->L_frame, &tc_subfr, &position, attack_flag, st->pitch[0], res_fx );
-
- config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 1, NULL, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode );
- }
-
- /*---------------------------------------------------------------*
- * Calculation of prediction for scaled innovation energy
- * (for memory-less gain quantizer)
- *---------------------------------------------------------------*/
-
- IF( nb_bits > 0 )
- {
- Es_pred_enc_fx( &Es_pred_fx, &i, st->L_frame, res_fx, st->voicing_fx, nb_bits, uc_two_stage_flag, Q_new );
- push_indice( hBstr, IND_ES_PRED, i, nb_bits );
- }
-
- /*------------------------------------------------------------*
- * Encode excitation according to coding type
- *------------------------------------------------------------*/
- test();
- test();
- IF( tdm_low_rate_mode ) /* tdm stereo low rate mode */
- {
- IF( LE_16( st->coder_type, UNVOICED ) )
- {
- tdm_low_rate_enc( st, Aq, res_fx, syn_fx, exc_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, 0 /*attack_flag*/, lsf_new_fx, &tmp_noise_fx, Q_new );
- }
- ELSE /* GENERIC */
- {
- encod_gen_2sbfr( st, inp, Aw, Aq, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, Q_new, 0 );
- }
- }
- ELSE IF( nelp_mode )
- {
- /* SC-VBR - NELP frames */
- encod_nelp_ivas_fx( st, inp, Aw, Aq, res_fx, syn_fx, &tmp_noise_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, Q_new, 0 );
- }
-
- ELSE IF( EQ_16( st->coder_type, UNVOICED ) )
- {
- /* UNVOICED frames (Gauss. excitation) */
- encod_unvoiced_ivas_fx( st, inp, Aw, Aq, Es_pred_fx, uc_two_stage_flag, res_fx, syn_fx, &tmp_noise_fx, exc_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, Q_new, 0 );
- }
- ELSE IF( EQ_16( st->coder_type, TRANSITION ) )
- {
- encod_tran_ivas_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, tc_subfr, position, unbits, 0, Q_new );
- }
- ELSE IF( ppp_mode )
- {
- /* SC-VBR - PPP frames */
- IF( ( error = encod_ppp_ivas_fx( st, inp, Aw, Aq, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, Q_new, 0 ) ) != IVAS_ERR_OK )
- {
- return error;
- }
-
- IF( st->hSC_VBR->bump_up ) /* PPP failed, bump up */
- {
- /* restore memories of LSF quantizer and synthesis filter */
- lsf_syn_mem_restore_ivas_fx( st, tilt_code_bck_fx, gc_threshold_bck_fx, clip_var_bck_fx, next_force_sf_bck, lsp_new, lsp_mid, clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsp_mid_bck_fx, Bin_E_fx, Bin_E_old_fx, mem_syn_bck_fx, mem_w0_bck_fx, streaklimit_fx, pstreaklen );
- /* Configure ACELP bit allocation */
- config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, 0, &uc_two_stage_flag, 0, 0, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode );
-
- /* redo LSF quantization */
- lsf_enc_ivas_fx( st, lsf_new_fx, lsp_new, lsp_mid, Aq, tdm_low_rate_mode, 0, NULL, Q_new );
-
- /* recalculation of LP residual (filtering through A[z] filter) */
- calc_residu_fx( st, inp, res_fx, Aq );
- st->hTdCngEnc->burst_ho_cnt = 0;
- move16();
- /* VOICED frames in SC-VBR */
- encod_gen_voic_ivas_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, 0, Q_new );
- }
- }
- ELSE IF( EQ_16( st->coder_type, AUDIO ) || ( EQ_16( st->coder_type, INACTIVE ) && st->inactive_coder_type_flag ) )
- {
- /* AUDIO and INACTIVE frames (coded by GSC technology) */
- encod_audio_ivas_fx( st, inp, Aw, Aq, res_fx, syn_fx, exc_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, attack_flag, lsf_new_fx, &tmp_noise_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, Q_new, 0 );
- }
- ELSE
- {
- /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */
- encod_gen_voic_ivas_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, 0, Q_new );
- }
-
- FOR( i = 0; i < NB_SUBFR16k; i++ )
- {
- Scale_sig( &Aq[i * ( M + 1 )], ( M + 1 ), sub( Q12, sub( Q14, norm_s( Aq[i * ( M + 1 )] ) ) ) ); // Q12
- }
-
- /* update mem_syn1_flt for ACELP core switching */
- Copy( hLPDmem->mem_syn, hLPDmem->mem_syn1_fx, M );
-
- /* update old synthesis buffer - needed for ACELP internal sampling rate switching */
- Copy( syn_fx + sub( st->L_frame, L_SYN_MEM ), hLPDmem->mem_syn_r, L_SYN_MEM );
-
- Scale_sig( syn_fx, L_FRAME16k, sub( st->Q_syn, Q_new - 1 ) );
- /* save and delay synthesis to be used by SWB BWE */
- IF( st->hBWE_FD != NULL )
- {
- st->hBWE_FD->mem_deemph_old_syn_fx = shl_sat( st->hBWE_FD->mem_deemph_old_syn_fx, sub( s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ), st->hBWE_FD->q_mem_deemph_old_syn ) );
- move16();
- Scale_sig( st->hBWE_FD->old_syn_12k8_16k_fx, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ), sub( s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ), st->hBWE_FD->q_mem_deemph_old_syn ) );
-
- save_old_syn_fx( st->L_frame, syn_fx, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx );
- *q_old_syn_12k8_16 = s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn );
- move16();
- st->hBWE_FD->q_mem_deemph_old_syn = s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn );
- move16();
- Scale_sig( syn_fx, st->L_frame, sub( st->Q_syn, s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ) ) );
- }
-
- /*Update MODE2 core switching memory*/
- Copy( syn_fx, syn1_fx, st->L_frame );
-
- Scale_sig( st->hLPDmem->syn, M + 1, sub( st->Q_syn, st->hLPDmem->q_lpd_syn ) );
- st->hLPDmem->q_lpd_syn = st->Q_syn;
- move16();
-
- /*Update MODE2 core switching memory*/
- deemph_fx( syn1_fx, st->preemph_fac, st->L_frame, &( hLPDmem->syn[M] ) );
-
- Copy( syn1_fx + add( st->L_frame, -M - 1 ), hLPDmem->syn, M + 1 );
-
- test();
- IF( st->element_mode > EVS_MONO && st->hTcxEnc != NULL )
- {
- Copy( syn1_fx + shr( st->L_frame, 1 ), st->hTcxEnc->Txnq, shr( st->L_frame, 1 ) );
-#ifdef MSAN_FIX
- Scale_sig( st->hTcxEnc->Txnq + shr( st->L_frame, 1 ), sub( L_FRAME32k / 2 + 64, shr( st->L_frame, 1 ) ), sub( st->Q_syn, st->hTcxEnc->q_Txnq ) );
-#else
- Scale_sig( st->hTcxEnc->Txnq + shr( st->L_frame, 1 ), sub( L_FRAME32k / 2 + 64, shr( st->L_frame, 2 ) ), sub( st->Q_syn, st->hTcxEnc->q_Txnq ) );
-#endif
- st->hTcxEnc->q_Txnq = st->Q_syn;
- move16();
- }
-
- /*--------------------------------------------------------------------------------------*
- * Modify the excitation signal when the noise is stationary
- *--------------------------------------------------------------------------------------*/
- test();
- test();
- test();
- test();
- IF( !( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) && NE_16( nelp_mode, 1 ) && !( EQ_16( st->element_mode, IVAS_SCE ) && tdm_low_rate_mode ) )
- {
- /* exc2 buffer is needed only for updating of Aq[] which is needed for core switching */
- Copy( exc_fx, exc2_fx, st->L_frame );
-
- stat_noise_uv_enc_ivas_fx( st, epsP, lsp_new, lsp_mid, Aq, exc2_fx, uc_two_stage_flag, Q_new );
- }
-
- /*-----------------------------------------------------------------*
- * Encode supplementary information for Frame Error Concealment
- *-----------------------------------------------------------------*/
-
- Scale_sig( syn_fx, L_FRAME, sub( s_min( st->Q_syn, Q_new ), st->Q_syn ) );
-#ifdef MSAN_FIX
- Scale_sig( res_fx, st->L_frame, sub( s_min( st->Q_syn, Q_new ), Q_new ) );
-#else
- Scale_sig( res_fx, L_FRAME16k, sub( s_min( st->Q_syn, Q_new ), Q_new ) );
-#endif
- FEC_encode_ivas_fx( hBstr, st->acelp_cfg, syn_fx, st->coder_type, st->clas, pitch_buf, res_fx, &st->Last_pulse_pos, st->L_frame, st->total_brate, s_min( st->Q_syn, Q_new ) );
- IF( st->hBWE_TD != NULL )
- {
- IF( EQ_16( st->L_frame, L_FRAME ) )
- {
- Copy( Aq + 2 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) );
- }
- ELSE
- {
- Copy( Aq + 3 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) );
- }
- }
-
-
- } /* end of active inp coding */
-
- /*-----------------------------------------------------------------*
- * Write ACELP unused bits
- *-----------------------------------------------------------------*/
- test();
- test();
- IF( NE_32( st->core_brate, SID_2k40 ) && NE_32( st->core_brate, FRAME_NO_DATA ) && NE_32( st->core_brate, PPP_NELP_2k80 ) )
- {
- nBits = st->acelp_cfg.ubits;
- move16();
- WHILE( nBits > 0 )
- {
- i = s_min( nBits, 16 );
- push_indice( hBstr, IND_UNUSED, 0, i );
- nBits = sub( nBits, i );
- }
- }
-
- /*-----------------------------------------------------------------*
- * Apply non linearity in case of SWB TBE
- *-----------------------------------------------------------------*/
-
- IF( st->hBWE_TD != NULL )
- {
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- test();
- IF( ( EQ_16( st->last_Opt_SC_VBR, 1 ) && st->Opt_SC_VBR == 0 ) || ( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, WB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, WB_TBE ) && NE_16( st->last_extl, FB_TBE ) ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && !st->tdm_LRTD_flag ) )
- {
- st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0;
- move16();
- set16_fx( st->hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET );
- }
-
- test();
- test();
- test();
- test();
- test();
- test();
- IF( !st->Opt_SC_VBR && ( st->idchan == 0 || NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) )
- {
- /* Apply a non linearity to the SHB excitation */
- Copy_Scale_sig_16_32( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( sub( shl( Q_new, 1 ), sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc
- non_linearity_ivas_fx( bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, Q_new, st->coder_type, voice_factors_fx, st->L_frame );
- Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, negate( sub( shl( Q_new, 1 ), sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc
- }
-
- test();
- if ( EQ_32( st->core_brate, SID_2k40 ) || EQ_32( st->core_brate, FRAME_NO_DATA ) )
- {
- st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0;
- move16();
- }
- }
-
- /*-----------------------------------------------------------------*
- * Updates
- *-----------------------------------------------------------------*/
-
- IF( st->hBWE_TD != NULL )
- {
- st->Q_exc = Q_new;
- move16();
- }
-
- updt_enc_fx( st, old_exc_fx, pitch_buf, Es_pred_fx, Aq, lsf_new_fx, lsp_new, old_bwe_exc_fx );
- st->hLPDmem->q_lpd_old_exc = Q_new;
- move16();
-
- test();
- test();
- IF( st->hTdCngEnc != NULL && st->Opt_DTX_ON && GT_32( st->core_brate, SID_2k40 ) )
- {
- /* update CNG parameters in active frames */
- Word16 q_exc = st->hTdCngEnc->cng_Qexc_buf[0];
- move16();
- FOR( Word16 ii = 0; ii < HO_HIST_SIZE; ii++ )
- {
- q_exc = s_min( q_exc, st->hTdCngEnc->cng_Qexc_buf[ii] );
- }
- q_exc = s_min( q_exc, Q_new );
-
- Scale_sig( exc_fx, L_EXC - L_EXC_MEM, sub( q_exc, Q_new ) );
- FOR( Word16 ii = 0; ii < HO_HIST_SIZE; ii++ )
- {
- Scale_sig( st->hTdCngEnc->cng_exc2_buf + ii * L_FFT, L_FFT, sub( q_exc, st->hTdCngEnc->cng_Qexc_buf[ii] ) );
- st->hTdCngEnc->cng_Qexc_buf[ii] = q_exc;
- move16();
- }
- cng_params_upd_ivas_fx( lsp_new, exc_fx, st->L_frame, &st->hTdCngEnc->ho_circ_ptr, st->hTdCngEnc->ho_ener_circ_fx,
- &st->hTdCngEnc->ho_circ_size, st->hTdCngEnc->ho_lsp_circ_fx, q_exc, ENC, st->hTdCngEnc->ho_env_circ_fx, &st->hTdCngEnc->cng_buf_cnt,
- st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hDtxEnc->last_active_brate, st->element_mode,
- st->hFdCngEnc->hFdCngCom->CngBandwidth );
-
- IF( EQ_16( st->L_frame, L_FRAME ) )
- {
- /* store LSPs@16k, potentially to be used in CNG@16k */
- Copy( st->lsp_old16k_fx, &( st->hTdCngEnc->ho_lsp_circ2_fx[( st->hTdCngEnc->ho_circ_ptr ) * M] ), M );
- }
-
- /* set LSP@16k flag for the first buffer */
- IF( EQ_16( st->L_frame, L_FRAME ) )
- {
- st->hTdCngEnc->ho_16k_lsp[st->hTdCngEnc->ho_circ_ptr] = 0;
- }
- ELSE
- {
- st->hTdCngEnc->ho_16k_lsp[st->hTdCngEnc->ho_circ_ptr] = 1;
- }
- move16();
- /* efficient DTX hangover control */
- IF( GT_16( st->hTdCngEnc->burst_ho_cnt, 1 ) )
- {
- dtx_hangover_control_fx( st, lsp_new );
- }
- }
-
- /* SC-VBR update of average data rate */
- IF( EQ_16( st->vad_flag, 1 ) )
- {
- /* reset in case of bitrate switching in EVS */
- if ( st->hSC_VBR != NULL )
- {
- update_average_rate_fx( st->hSC_VBR, st->core_brate );
- }
- }
- pop_wmops();
-
- return error;
-}
diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c
index 66e34e2a58b614dace296d7eaea7ec8ceb7cc31b..55d440912ec0d92fa4e384fcfe6e1a91b8a70979 100644
--- a/lib_enc/acelp_core_enc_fx.c
+++ b/lib_enc/acelp_core_enc_fx.c
@@ -6,36 +6,39 @@
#include
#include "options.h" /* Compilation switches */
#include "cnst.h"
+#include "prot.h"
#include "prot_fx.h"
#include "stat_enc.h"
#include "rom_com.h"
-#include "rom_enc.h" /* Encoder static table prototypes */
-#include "rom_com_fx.h" /* Static table prototypes */
-//#include "prot_fx.h" /* Function prototypes */
+#include "rom_enc.h" /* Encoder static table prototypes */
+#include "rom_com_fx.h" /* Static table prototypes */
#include "prot_fx_enc.h" /* Function prototypes */
+#include "ivas_cnst.h"
+#include "ivas_prot.h"
+#include "ivas_prot_fx.h"
/*-------------------------------------------------------------------*
- * acelp_core_enc()
+ * acelp_core_enc_fx()
*
* ACELP core encoder
*--------------------------------------------------------------------*/
ivas_error acelp_core_enc_fx(
Encoder_State *st_fx, /* i/o: encoder state structure */
- const Word16 inp_fx[], /* i : input signal of the current frame */
- const Word32 ener_fx, /* i : residual energy from Levinson-Durbin*/
- Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes*/
- Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes*/
- const Word16 epsP_h_fx[M + 1], /* i : LP prediction errors */
- const Word16 epsP_l_fx[M + 1], /* i : LP prediction errors */
- Word16 lsp_new_fx[M], /* i : LSPs at the end of the frame */
- Word16 lsp_mid_fx[M], /* i : LSPs in the middle of the frame */
- Word16 vad_hover_flag_fx, /* i : VAD hangover flag */
- const Word16 attack_flag, /* i : attack flag (GSC or TC) */
- Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation */
- Word16 *voice_factors_fx, /* o : voicing factors */
- Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */
- Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe */
- Word16 *unbits_fx, /* o : number of unused bits */
+ const Word16 inp_fx[], /* i : input signal of the current frame Q_new*/
+ const Word32 ener_fx, /* i : residual energy from Levinson-Durbin Q6*/
+ Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12*/
+ Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes Q12*/
+ const Word16 epsP_h_fx[M + 1], /* i : LP prediction errors Qx*/
+ const Word16 epsP_l_fx[M + 1], /* i : LP prediction errors Qx*/
+ Word16 lsp_new_fx[M], /* i : LSPs at the end of the frame Q15*/
+ Word16 lsp_mid_fx[M], /* i : LSPs in the middle of the frame Q15*/
+ Word16 vad_hover_flag_fx, /* i : VAD hangover flag Q0*/
+ const Word16 attack_flag, /* i : attack flag (GSC or TC) Q0*/
+ Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation st->prev_Q_bwe_exc*/
+ Word16 *voice_factors_fx, /* o : voicing factors Q15*/
+ Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE q_old_syn*/
+ Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe Q6*/
+ Word16 *unbits_fx, /* o : number of unused bits Q0*/
const Word16 Q_new,
const Word16 shift
#ifdef ADD_LRTD
@@ -86,6 +89,7 @@ ivas_error acelp_core_enc_fx(
Word16 *tdm_Pri_pitch_buf;
Word16 uc_two_stage_flag;
Word16 att;
+ move16();
SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR;
DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc;
@@ -113,14 +117,15 @@ ivas_error acelp_core_enc_fx(
move16();
coder_type = st_fx->coder_type;
+ move16();
- exc_fx = old_exc_fx + L_EXC_MEM; /* pointer to excitation signal in the current frame */
- Copy( hLPDmem->old_exc, old_exc_fx, L_EXC_MEM );
+ exc_fx = old_exc_fx + L_EXC_MEM; /* pointer to excitation signal in the current frame */
+ Copy( hLPDmem->old_exc, old_exc_fx, L_EXC_MEM ); // q_lpd_old_exc
IF( hBWE_TD != NULL )
{
- bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2; /* pointer to BWE excitation signal in the current frame */
- Copy( hBWE_TD->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2 );
+ bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2; /* pointer to BWE excitation signal in the current frame */
+ Copy( hBWE_TD->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2 ); // Q_exc
}
ELSE
{
@@ -151,7 +156,8 @@ ivas_error acelp_core_enc_fx(
st_fx->Nb_ACELP_frames = 0;
move16();
}
- st_fx->Nb_ACELP_frames = add( st_fx->Nb_ACELP_frames, 1 );
+ st_fx->Nb_ACELP_frames = add( st_fx->Nb_ACELP_frames, 1 ); // Q0
+ move16();
int_fs_fx = INT_FS_16k_FX;
move16();
@@ -242,13 +248,14 @@ ivas_error acelp_core_enc_fx(
/* convert old quantized LSP vector */
IF( EQ_16( st_fx->L_frame, L_FRAME ) )
{
- st_fx->rate_switching_reset = lsp_convert_poly_fx( st_fx->lsp_old_fx, st_fx->L_frame, 0 );
+ st_fx->rate_switching_reset = lsp_convert_poly_fx( st_fx->lsp_old_fx, st_fx->L_frame, 0 ); // Q0
+ move16();
}
ELSE
{
- st_fx->rate_switching_reset = st_fx->rate_switching_reset_16kHz;
+ st_fx->rate_switching_reset = st_fx->rate_switching_reset_16kHz; // Q0
move16();
- Copy( st_fx->lsp_old16k_fx, st_fx->lsp_old_fx, M );
+ Copy( st_fx->lsp_old16k_fx, st_fx->lsp_old_fx, M ); // Q15
}
/* convert old quantized LSF vector */
@@ -266,14 +273,14 @@ ivas_error acelp_core_enc_fx(
}
/* Reset LPC mem */
- Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M );
+ Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); // x2.56
set16_fx( st_fx->mem_MA_fx, 0, M );
/* update synthesis filter memories */
synth_mem_updt2( st_fx->L_frame, st_fx->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn2, hLPDmem->mem_syn, ENC );
- Copy( hLPDmem->old_exc, old_exc_fx, L_EXC_MEM );
- Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn1_fx, M );
- Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn3, M );
+ Copy( hLPDmem->old_exc, old_exc_fx, L_EXC_MEM ); // q_lpd_old_exc
+ Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn1_fx, M ); // q_mem_syn
+ Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn3, M ); // q_mem_syn
/* update Aw[] coefficients */
weight_a_subfr_fx( shr( st_fx->L_frame, 6 ), A_fx, Aw_fx, st_fx->gamma, M );
@@ -320,24 +327,24 @@ ivas_error acelp_core_enc_fx(
FdCng_exc( st_fx->hFdCngEnc->hFdCngCom, &hDtxEnc->CNG_mode, st_fx->L_frame, st_fx->lsp_old_fx,
hDtxEnc->first_CNG, hDtxEnc->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx );
- Copy( exc2_fx, exc3_fx, st_fx->L_frame );
+ Copy( exc2_fx, exc3_fx, st_fx->L_frame ); // Q12
IF( EQ_32( st_fx->core_brate, SID_2k40 ) )
{
IF( hTdCngEnc != NULL )
{
/*IVAS_CODE CNG_att is missing */
- enr = cng_energy_fx( st_fx->element_mode, st_fx->bwidth, hDtxEnc->CNG_mode, /*st_fx->hTdCngEnc->CNG_att*/ 0, exc_fx, st_fx->L_frame, Q_new );
+ enr = cng_energy_fx( st_fx->element_mode, st_fx->bwidth, hDtxEnc->CNG_mode, /*st_fx->hTdCngEnc->CNG_att*/ 0, exc_fx, st_fx->L_frame, Q_new ); // Q8
/* calculate the energy quantization index */
enr_index = add( enr, 512 /* Q8(2.0) */ ); /* enr + 2.0 */
enr_index = extract_l( L_shr( L_mult0( enr_index, STEP_SID_FX ), 12 + 8 ) ); /* Q0 (8+12-(8+12)) */
/* limit the energy quantization index */
- enr_index = s_min( enr_index, 127 );
+ enr_index = s_min( enr_index, 127 ); // Q0
enr_index = s_max( enr_index, 0 );
- hTdCngEnc->old_enr_index = enr_index;
+ hTdCngEnc->old_enr_index = enr_index; /* Q0 */
move16();
}
}
@@ -361,7 +368,7 @@ ivas_error acelp_core_enc_fx(
Copy( hLPDmem->mem_syn3, hLPDmem->mem_syn, M );
/* update old synthesis buffer - needed for ACELP internal sampling rate switching */
- Copy( syn1_fx + st_fx->L_frame - L_SYN_MEM, hLPDmem->mem_syn_r, L_SYN_MEM );
+ Copy( syn1_fx + st_fx->L_frame - L_SYN_MEM, hLPDmem->mem_syn_r, L_SYN_MEM ); /* st_fx->Q_syn */
IF( hBWE_FD != NULL )
{
@@ -372,7 +379,7 @@ ivas_error acelp_core_enc_fx(
tmp16 = hLPDmem->syn[M];
move16();
E_UTIL_deemph2( sub( Q_new, 1 ), syn1_fx, st_fx->preemph_fac, st_fx->L_frame, &tmp16 );
- Copy( syn1_fx + st_fx->L_frame - M - 1, hLPDmem->syn, M + 1 );
+ Copy( syn1_fx + st_fx->L_frame - M - 1, hLPDmem->syn, M + 1 ); /* st_fx->Q_syn */
}
/*----------------------------------------------------------------*
@@ -408,7 +415,7 @@ ivas_error acelp_core_enc_fx(
test();
IF( st_fx->hDtxEnc != NULL && ( st_fx->last_core_brate == FRAME_NO_DATA || EQ_32( st_fx->last_core_brate, SID_2k40 ) ) )
{
- Copy( hDtxEnc->lspCNG_fx, st_fx->lsp_old_fx, M );
+ Copy( hDtxEnc->lspCNG_fx, st_fx->lsp_old_fx, M ); // Q15
lsp2lsf_fx( hDtxEnc->lspCNG_fx, st_fx->lsf_old_fx, M, int_fs_fx );
}
@@ -580,8 +587,7 @@ ivas_error acelp_core_enc_fx(
ELSE IF( EQ_16( coder_type, TRANSITION ) )
{
tc_subfr_fx = encod_tran_fx( st_fx, inp_fx, Aw_fx, Aq_fx, Es_pred_fx, res_fx, syn_fx,
- exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, tc_subfr_fx, position, unbits_fx, shift, Q_new );
- move16();
+ exc_fx, exc2_fx, pitch_buf_fx, voice_factors_fx, bwe_exc_fx, tc_subfr_fx, position, unbits_fx, shift, Q_new ); /* Q0 */
}
ELSE IF( hSC_VBR->ppp_mode )
{
@@ -632,7 +638,7 @@ ivas_error acelp_core_enc_fx(
}
/* update st->mem_syn1 for ACELP core switching */
- Copy( hLPDmem->mem_syn, hLPDmem->mem_syn1_fx, M );
+ Copy( hLPDmem->mem_syn, hLPDmem->mem_syn1_fx, M ); /* q_mem_syn */
/* update old synthesis buffer - needed for ACELP internal sampling rate switching */
Copy( syn_fx + st_fx->L_frame - L_SYN_MEM, hLPDmem->mem_syn_r, L_SYN_MEM );
@@ -643,25 +649,31 @@ ivas_error acelp_core_enc_fx(
save_old_syn_fx( st_fx->L_frame, syn_fx, old_syn_12k8_16k_fx, hBWE_FD->old_syn_12k8_16k_fx, st_fx->preemph_fac, &hBWE_FD->mem_deemph_old_syn_fx );
}
/*Update MODE2 core switching memory*/
- Copy( syn_fx, syn1_fx, st_fx->L_frame );
+ Copy( syn_fx, syn1_fx, st_fx->L_frame ); // Q_syn
E_UTIL_deemph2( sub( Q_new, 1 ), syn1_fx, st_fx->preemph_fac, st_fx->L_frame, &hLPDmem->syn[M] );
- Copy( syn1_fx + st_fx->L_frame - M - 1, hLPDmem->syn, M + 1 );
- IF( GT_16( st_fx->element_mode, EVS_MONO ) && st_fx->hTcxEnc != NULL )
+ Copy( syn1_fx + st_fx->L_frame - M - 1, hLPDmem->syn, M + 1 ); // Q_syn
+
+ test();
+ IF( st_fx->element_mode > EVS_MONO && st_fx->hTcxEnc != NULL )
{
- Copy( syn1_fx + st_fx->L_frame / 2, st_fx->hTcxEnc->Txnq, st_fx->L_frame / 2 );
+ Copy( syn1_fx + st_fx->L_frame / 2, st_fx->hTcxEnc->Txnq, st_fx->L_frame / 2 ); // Q_syn
}
/*--------------------------------------------------------------------------------------*
* Modify the excitation signal when the noise is stationary
*--------------------------------------------------------------------------------------*/
+ test();
+ test();
+ test();
+ test();
IF( !( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) && NE_16( nelp_mode, 1 ) && !( EQ_16( st_fx->element_mode, IVAS_SCE ) && tdm_low_rate_mode ) )
{
L_epsP[0] = L_Comp( epsP_h_fx[2], epsP_l_fx[2] );
move32();
L_epsP[1] = L_Comp( epsP_h_fx[M], epsP_l_fx[M] );
move32();
- Copy( exc_fx, exc2_fx, st_fx->L_frame );
+ Copy( exc_fx, exc2_fx, st_fx->L_frame ); // Q_new
stat_noise_uv_enc_fx( st_fx, L_epsP, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx, uc_two_stage_flag, Q_new );
}
@@ -677,11 +689,11 @@ ivas_error acelp_core_enc_fx(
{
IF( EQ_16( st_fx->L_frame, L_FRAME ) )
{
- Copy( Aq_fx + 2 * ( M + 1 ), hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) );
+ Copy( Aq_fx + 2 * ( M + 1 ), hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); // Q12
}
ELSE
{
- Copy( Aq_fx + 3 * ( M + 1 ), hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) );
+ Copy( Aq_fx + 3 * ( M + 1 ), hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); // Q12
}
}
} /* end of active inp coding */
@@ -695,13 +707,14 @@ ivas_error acelp_core_enc_fx(
IF( NE_32( st_fx->core_brate, SID_2k40 ) && NE_32( st_fx->core_brate, FRAME_NO_DATA ) && NE_32( st_fx->core_brate, PPP_NELP_2k80 ) )
{
/* reserved bits */
- nBits = st_fx->acelp_cfg.ubits;
+ nBits = st_fx->acelp_cfg.ubits; // Q0
+ move16();
WHILE( nBits > 0 )
{
- i = s_min( nBits, 16 );
+ i = s_min( nBits, 16 ); // Q0
push_indice_fx( st_fx->hBstr, IND_UNUSED, 0, i );
- nBits = sub( nBits, i );
+ nBits = sub( nBits, i ); // Q0
}
}
@@ -742,6 +755,7 @@ ivas_error acelp_core_enc_fx(
*-----------------------------------------------------------------*/
updt_enc_fx( st_fx, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, old_bwe_exc_fx );
+ test();
test();
IF( hTdCngEnc != NULL && ( st_fx->Opt_DTX_ON != 0 ) && ( GT_32( st_fx->core_brate, SID_2k40 ) ) )
{
@@ -753,7 +767,7 @@ ivas_error acelp_core_enc_fx(
IF( EQ_16( st_fx->L_frame, L_FRAME ) )
{
/* store LSPs@16k, potentially to be used in CNG@16k */
- Copy( st_fx->lsp_old16k_fx, &( hTdCngEnc->ho_lsp_circ2_fx[( hTdCngEnc->ho_circ_ptr ) * M] ), M );
+ Copy( st_fx->lsp_old16k_fx, &( hTdCngEnc->ho_lsp_circ2_fx[( hTdCngEnc->ho_circ_ptr ) * M] ), M ); // Q15
}
/* Set 16k LSP flag for CNG buffer */
@@ -773,6 +787,7 @@ ivas_error acelp_core_enc_fx(
}
/* SC-VBR update of average data rate */
+ test();
IF( EQ_16( st_fx->vad_flag, 1 ) && ( hSC_VBR != NULL ) )
{
update_average_rate_fx( hSC_VBR, st_fx->core_brate );
@@ -780,3 +795,925 @@ ivas_error acelp_core_enc_fx(
return error;
}
+
+/*-------------------------------------------------------------------*
+ * acelp_core_enc_ivas_fx()
+ *
+ * ACELP core encoder
+ *--------------------------------------------------------------------*/
+ivas_error acelp_core_enc_ivas_fx(
+ Encoder_State *st, /* i/o: encoder state structure */
+ const Word16 inp[], /* i : input signal of the current frame Q_new*/
+ Word16 A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12*/
+ Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes Q12*/
+ const Word32 epsP[M + 1], /* i : LP prediction errors Qx*/
+ Word16 lsp_new[M], /* i : LSPs at the end of the frame Q15*/
+ Word16 lsp_mid[M], /* i : LSPs in the middle of the frame Q15*/
+ const Word16 vad_hover_flag, /* i : VAD hangover flag Q0*/
+ const Word16 attack_flag, /* i : attack flag (GSC or TC) Q0*/
+ Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation st->prev_Q_bwe_exc*/
+ Word16 *voice_factors_fx, /* o : voicing factors Q15*/
+ Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE q_old_syn_12k8_16*/
+ Word16 *q_old_syn_12k8_16,
+ Word16 pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe Q6*/
+ Word16 *unbits, /* o : number of unused bits Q0*/
+ STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */
+ Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel X2.56*/
+ Word16 Q_new )
+{
+ Word16 i, nBits; /* reserved bits */
+ LPD_state_HANDLE hLPDmem; /* i/o: acelp memories */
+ Word16 tc_subfr; /* TC sub-frame indication */
+ Word16 allow_cn_step;
+ Word32 int_fs;
+ Word16 nb_bits; /* parameters handling */
+
+ /* SC-VBR - back-up memories for LSF quantizer and synthesis filter */
+ Word16 pstreaklen;
+ Word16 sid_bw = -1;
+ move16();
+ Word16 next_force_sf_bck;
+ Word16 uc_two_stage_flag;
+ Word16 position;
+ Word16 ppp_mode, nelp_mode;
+ Word16 tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag;
+
+ /* bitstream */
+ BSTR_ENC_HANDLE hBstr = st->hBstr;
+ Word16 old_exc_fx[L_EXC], *exc_fx; /* excitation signal buffer */
+ Word16 lsf_new_fx[M]; /* ISFs at the end of the frame */
+ Word16 Aq[NB_SUBFR16k * ( M + 1 )]; /* A(z) quantized for the 4 subframes */
+ Word16 syn_fx[L_FRAME16k]; /* synthesis vector */
+ Word16 res_fx[L_FRAME16k]; /* Residual signal for FER protection */
+ Word16 exc2_fx[L_FRAME16k]; /* enhanced excitation */
+ Word16 Es_pred_fx; /* predicited scaled innovation energy */
+ Word16 tmp_noise_fx; /* NB post-filter long-term noise energy*/
+ Word16 old_bwe_exc_fx[( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2]; /* excitation buffer Q_new */
+ Word16 *bwe_exc_fx; /* excitation for SWB TBE Q_new */
+ Word16 mem_MA_fx[M], mem_AR_fx[M], lsp_new_bck_fx[M], /*lsf_new_bck_fx[M],*/ lsp_mid_bck_fx[M], mem_syn_bck_fx[M];
+ Word32 Bin_E_fx[L_FFT], Bin_E_old_fx[L_FFT / 2];
+ Word16 clip_var_fx, mem_w0_bck_fx, streaklimit_fx;
+
+#ifdef MSAN_FIX
+ set16_fx( old_bwe_exc_fx, 0, ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 );
+ set16_fx( old_exc_fx, 0, L_EXC );
+ set16_fx( Aq, 0, NB_SUBFR16k * ( M + 1 ) );
+ set16_fx( syn_fx, 0, L_FRAME16k );
+#endif
+
+ Word16 tilt_code_bck_fx;
+ Word32 gc_threshold_bck_fx;
+ Word16 clip_var_bck_fx[6];
+ Word32 q_env_fx[NUM_ENV_CNG];
+#ifdef MSAN_FIX
+ set32_fx( q_env_fx, 0, NUM_ENV_CNG );
+#endif
+ Word16 exc3_fx[L_FRAME16k];
+ Word16 syn1_fx[L_FRAME16k];
+ Word16 *tdm_Pri_pitch_buf_fx;
+
+ Word16 att_fx;
+ Word16 tmpF_fx;
+
+ test();
+ IF( !st->Opt_AMR_WB && st->hBWE_TD != NULL )
+ {
+ Scale_sig( st->hBWE_TD->old_bwe_exc_fx, PIT16k_MAX * 2, sub( Q_new, st->prev_Q_new ) ); // Q_new
+ }
+ IF( st->hLPDmem )
+ {
+ Scale_sig( st->hLPDmem->old_exc, L_EXC_MEM, sub( Q_new, st->hLPDmem->q_lpd_old_exc ) ); // Q_new
+ st->hLPDmem->q_lpd_old_exc = Q_new;
+ move16();
+ Scale_sig( st->hLPDmem->syn, M + 1, sub( Q_new, st->hLPDmem->q_lpd_syn ) ); // Q_new
+ st->hLPDmem->q_lpd_syn = Q_new;
+ move16();
+ Scale_sig( st->hLPDmem->mem_syn, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); // Q_new -1
+ Scale_sig( st->hLPDmem->mem_syn1_fx, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); // Q_new -1
+ Scale_sig( st->hLPDmem->mem_syn2, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); // Q_new -1
+ Scale_sig( st->hLPDmem->mem_syn3, M, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); // Q_new -1
+ Scale_sig( st->hLPDmem->mem_syn_r, L_SYN_MEM, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); // Q_new -1
+ st->hLPDmem->mem_w0 = shl_sat( st->hLPDmem->mem_w0, sub( sub( Q_new, 1 ), st->hLPDmem->q_mem_syn ) ); // Q_new -1
+ move16();
+ st->hLPDmem->q_mem_syn = sub( Q_new, 1 );
+ move16();
+ }
+
+ Scale_sig32( st->Bin_E_old_fx, L_FFT / 2, sub( add( Q_new, Q_SCALE - 2 ), st->q_Bin_E_old ) ); // Q_new + Q_scale - 2
+ st->q_Bin_E_old = add( Q_new, Q_SCALE - 2 );
+ move16();
+ Scale_sig32( st->Bin_E_fx, L_FFT, sub( add( Q_new, Q_SCALE - 2 ), st->q_Bin_E ) ); // Q_new + Q_scale - 2
+ st->q_Bin_E = add( Q_new, Q_SCALE - 2 );
+ move16();
+
+ ivas_error error;
+
+ error = IVAS_ERR_OK;
+ move32();
+
+ test();
+ IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && LE_32( st->core_brate, SID_2k40 ) )
+ {
+ /* Core was ACELP because of DTX in MDCT-Stereo, but SID encoding for that is done in separate function */
+ return error;
+ }
+
+ push_wmops( "acelp_core_enc" );
+ /*------------------------------------------------------------------*
+ * Initialization
+ *------------------------------------------------------------------*/
+
+ hLPDmem = st->hLPDmem;
+
+ Es_pred_fx = 0;
+ move16();
+
+ exc_fx = old_exc_fx + L_EXC_MEM; /* pointer to excitation signal in the current frame */
+ Copy( hLPDmem->old_exc, old_exc_fx, L_EXC_MEM ); /* Q_new */
+ Scale_sig( old_exc_fx, L_EXC_MEM, sub( Q_new, hLPDmem->q_lpd_old_exc ) ); // Q_new
+ IF( st->hBWE_TD != NULL )
+ {
+ bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2; /* pointer to BWE excitation signal in the current frame */
+ Copy( st->hBWE_TD->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2 ); // Q_new
+ }
+ ELSE
+ {
+ bwe_exc_fx = NULL;
+ }
+
+ st->bpf_off = 0;
+ move16();
+
+ test();
+ test();
+ test();
+ IF( EQ_16( st->last_core, HQ_CORE ) || EQ_16( st->last_codec_mode, MODE2 ) || EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) )
+ {
+ /* in case of HQ->ACELP switching, do not apply BPF */
+ st->bpf_off = 1;
+ move16();
+ /* reset the GSC pre echo energy threshold in case of switching */
+ if ( st->hGSCEnc != NULL )
+ {
+ st->hGSCEnc->Last_frame_ener_fx = MAX_32;
+ move32();
+ }
+ }
+
+ /* force safety-net LSFQ in the first frames after CNG segment */
+ if ( LE_32( st->last_core_brate, SID_2k40 ) )
+ {
+ st->Nb_ACELP_frames = 0;
+ move16();
+ }
+ st->Nb_ACELP_frames = add( st->Nb_ACELP_frames, 1 );
+ move16();
+
+ IF( EQ_16( st->L_frame, L_FRAME ) )
+ {
+ int_fs = INT_FS_12k8;
+ move32();
+ }
+ ELSE
+ {
+ int_fs = INT_FS_16k;
+ move32();
+ }
+
+ tmp_noise_fx = 0;
+ move16();
+ tc_subfr = -1;
+ move16();
+ position = -1;
+ move16();
+
+ /* SC-VBR temporary variables */
+ pstreaklen = 0;
+ move16();
+ clip_var_fx = 0;
+ move16();
+ mem_w0_bck_fx = 0;
+ move16();
+ streaklimit_fx = 0;
+ move16();
+
+ /* channel-aware mode */
+ reset_rf_indices_fx( st );
+
+ /* VBR modes */
+ IF( st->Opt_SC_VBR )
+ {
+ ppp_mode = st->hSC_VBR->ppp_mode;
+ nelp_mode = st->hSC_VBR->nelp_mode;
+ }
+ ELSE
+ {
+ ppp_mode = 0;
+ nelp_mode = 0;
+ }
+ move16();
+ move16();
+
+ test();
+ /* TD stereo */
+
+ IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) )
+ {
+ tdm_lp_reuse_flag = hStereoTD->tdm_lp_reuse_flag; // Q0
+ tdm_low_rate_mode = hStereoTD->tdm_low_rate_mode; // Q0
+ tdm_Pitch_reuse_flag = hStereoTD->tdm_Pitch_reuse_flag; // Q0
+ tdm_Pri_pitch_buf_fx = hStereoTD->tdm_Pri_pitch_buf_fx; // Q6
+ move16();
+ move16();
+ move16();
+ }
+ ELSE
+ {
+ tdm_lp_reuse_flag = 0;
+ tdm_low_rate_mode = 0;
+ move16();
+ move16();
+
+ test();
+ if ( EQ_16( st->element_mode, IVAS_SCE ) && st->low_rate_mode )
+ {
+ tdm_low_rate_mode = 1;
+ move16();
+ }
+ tdm_Pitch_reuse_flag = 0;
+ move16();
+ tdm_Pri_pitch_buf_fx = NULL;
+ }
+
+ /*-----------------------------------------------------------------*
+ * ACELP@12k8 / ACELP@16k switching
+ *-----------------------------------------------------------------*/
+
+ test();
+ test();
+ IF( NE_16( st->last_L_frame, st->L_frame ) && ( st->last_core == ACELP_CORE || EQ_16( st->last_core, AMR_WB_CORE ) ) )
+ {
+ /* in case of switching, do not apply BPF (flag employed also in updt_enc()) */
+ st->bpf_off = 1;
+ move16();
+
+ /* force safety-net LSFQ in the first frames after ACELP@12k8/ACELP@16k switching */
+ st->Nb_ACELP_frames = 1;
+ move16();
+
+ /* convert old quantized LSP vector */
+ IF( EQ_16( st->L_frame, L_FRAME ) )
+ {
+ st->rate_switching_reset = lsp_convert_poly_fx( st->lsp_old_fx, st->L_frame, 0 ); // Q0
+ move16();
+ }
+ ELSE
+ {
+ st->rate_switching_reset = st->rate_switching_reset_16kHz; // Q0
+ move16();
+ Copy( st->lsp_old16k_fx, st->lsp_old_fx, M ); // Q15
+ }
+
+ /* convert old quantized LSF vector */
+ lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, int_fs );
+
+ /* interpolation of unquantized ISPs */
+ IF( st->rate_switching_reset )
+ {
+ /*extrapolation in case of unstable LSP*/
+ int_lsp4_ivas_fx( st->L_frame, lsp_mid, lsp_mid, lsp_new, A, M, 0 );
+ }
+ ELSE
+ {
+ int_lsp4_ivas_fx( st->L_frame, st->lsp_old_fx, lsp_mid, lsp_new, A, M, 0 );
+ }
+
+ /* Reset LPC mem */
+ Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); // Q2.56
+ set16_fx( st->mem_MA_fx, 0, M );
+
+ /* update synthesis filter memories */
+ synth_mem_updt2( st->L_frame, st->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn2, hLPDmem->mem_syn, ENC );
+ Copy( hLPDmem->old_exc, old_exc_fx, L_EXC_MEM ); // Q_new
+ Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn1_fx, M ); /* hLPDmem->q_mem_syn */
+ Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn3, M ); /* hLPDmem->q_mem_syn */
+
+ /* update Aw[] coefficients */
+ weight_a_subfr_fx( shr( st->L_frame, 6 ), A, Aw, st->gamma, M );
+ }
+ IF( st->hLPDmem )
+ {
+ st->hLPDmem->q_mem_syn = sub( Q_new, 1 );
+ move16();
+ st->hLPDmem->q_lpd_old_exc = Q_new;
+ move16();
+ st->hLPDmem->q_lpd_syn = Q_new;
+ move16();
+ }
+
+ test();
+ test();
+ if ( st->last_bwidth == NB && st->bwidth != NB && st->ini_frame != 0 )
+ {
+ st->rate_switching_reset = 1;
+ move16();
+ }
+
+ /*----------------------------------------------------------------*
+ * Encoding of CNG frames
+ *----------------------------------------------------------------*/
+ test();
+ IF( EQ_32( st->core_brate, SID_2k40 ) || st->core_brate == FRAME_NO_DATA )
+ {
+ IF( st->cng_type == LP_CNG )
+ {
+ /* Run CNG post parameter update */
+ cng_params_postupd_ivas_fx( st->hTdCngEnc->ho_circ_ptr, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hTdCngEnc->ho_env_circ_fx, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth );
+
+ /* encode CNG parameters */
+ CNG_enc_ivas_fx( st, Aq, inp, /*ener_fx,*/ lsp_mid, lsp_new, lsf_new_fx, &allow_cn_step, sub( Q_new, 1 ), q_env_fx, &sid_bw );
+
+ /* comfort noise generation */
+ CNG_exc_fx( st->core_brate, st->L_frame, &st->hTdCngEnc->Enew_fx, &st->hTdCngEnc->cng_seed, exc_fx, exc2_fx, &st->hTdCngEnc->lp_ener_fx, st->last_core_brate,
+ &st->hDtxEnc->first_CNG, &st->hTdCngEnc->cng_ener_seed, bwe_exc_fx, allow_cn_step, &st->hTdCngEnc->last_allow_cn_step, sub( st->prev_Q_new, 1 ), sub( Q_new, 1 ), st->hTdCngEnc->num_ho,
+ q_env_fx, st->hTdCngEnc->lp_env_fx, st->hTdCngEnc->old_env_fx, st->hTdCngEnc->exc_mem_fx, st->hTdCngEnc->exc_mem1_fx, &sid_bw, &st->hTdCngEnc->cng_ener_seed1, exc3_fx, st->Opt_AMR_WB, EVS_MONO );
+
+ Scale_sig( exc_fx, st->L_frame, 1 ); // Q_new + 1
+ }
+ ELSE
+ {
+ test();
+ IF( EQ_32( st->core_brate, SID_2k40 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) )
+ {
+ FdCng_encodeSID_ivas_fx( st );
+ st->hDtxEnc->last_CNG_L_frame = st->L_frame;
+ move16();
+ }
+
+ Word16 Q_cngNoise = Q31, zero_flag = 0;
+ move16();
+ move16();
+ FOR( Word16 j = 0; j < NPART; j++ )
+ {
+ IF( st->hFdCngEnc->hFdCngCom->cngNoiseLevel[j] != 0 )
+ {
+ zero_flag = 1;
+ move16();
+ BREAK;
+ }
+ }
+ IF( zero_flag )
+ {
+ Q_cngNoise = getScaleFactor32( st->hFdCngEnc->hFdCngCom->cngNoiseLevel, NPART );
+ }
+ Scale_sig32( st->hFdCngEnc->hFdCngCom->cngNoiseLevel, NPART, Q_cngNoise ); /* st->hFdCngEnc->hFdCngCom->cngNoiseLevelExp - Q_cngNoise */
+ st->hFdCngEnc->hFdCngCom->cngNoiseLevelExp = sub( st->hFdCngEnc->hFdCngCom->cngNoiseLevelExp, Q_cngNoise );
+ move16();
+
+ generate_comfort_noise_enc_ivas_fx( st, Q_new, 1 );
+ st->hTcxEnc->q_Txnq = Q_new;
+ move16();
+ Scale_sig( st->hFdCngEnc->hFdCngCom->A_cng, ( M + 1 ), sub( Q12, sub( 14, norm_s( st->hFdCngEnc->hFdCngCom->A_cng[0] ) ) ) ); /* Q12 */
+ FdCng_exc( st->hFdCngEnc->hFdCngCom, &st->hDtxEnc->CNG_mode, st->L_frame, st->lsp_old_fx, st->hDtxEnc->first_CNG, st->hDtxEnc->lspCNG_fx, Aq, lsp_new, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx );
+ Copy( exc2_fx, exc3_fx, st->L_frame ); // Q_new
+
+ IF( EQ_32( st->core_brate, SID_2k40 ) )
+ {
+ IF( st->hTdCngEnc != NULL )
+ {
+ Word16 enr, enr_index;
+ enr = cng_energy_ivas_fx( st->element_mode, st->bwidth, st->hDtxEnc->CNG_mode, st->hTdCngEnc->CNG_att_fx, exc_fx, st->L_frame, Q_new ); /* Q8 */
+
+ /* calculate the energy quantization index */
+ enr_index = add( enr, 512 /* Q8(2.0) */ ); /* enr + 2.0 */
+ enr_index = extract_l( L_shr( L_mult0( enr_index, STEP_SID_FX ), 12 + 8 ) ); /* Q0 (8+12-(8+12)) */
+
+ /* limit the energy quantization index */
+ enr_index = s_min( enr_index, 127 ); /* Q0 */
+ enr_index = s_max( enr_index, 0 );
+ st->hTdCngEnc->old_enr_index = enr_index; /* Q0 */
+ move16();
+ }
+ }
+ }
+
+ /* Reset HO counter in the first SID frame */
+ if ( st->hTdCngEnc != NULL )
+ {
+ st->hTdCngEnc->burst_ho_cnt = 0;
+ move16();
+ }
+
+ Scale_sig( st->hLPDmem->mem_syn, M, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); // st->Q_syn
+ Scale_sig( st->hLPDmem->mem_syn1_fx, M, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); // st->Q_syn
+ Scale_sig( st->hLPDmem->mem_syn2, M, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); // st->Q_syn
+ Scale_sig( st->hLPDmem->mem_syn3, M, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); // st->Q_syn
+ Scale_sig( st->hLPDmem->mem_syn_r, L_SYN_MEM, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); // st->Q_syn
+ st->hLPDmem->mem_w0 = shl_sat( st->hLPDmem->mem_w0, sub( st->Q_syn, st->hLPDmem->q_mem_syn ) ); // st->Q_syn
+ move16();
+ st->hLPDmem->q_mem_syn = st->Q_syn;
+ move16();
+
+ /* synthesis at 12.8kHz sampling rate */
+ syn_12k8_fx( st->L_frame, Aq, exc3_fx, syn1_fx, hLPDmem->mem_syn3, 1, sub( Q_new, 1 ), st->Q_syn );
+
+ /* reset the encoder */
+ CNG_reset_enc_fx( st, hLPDmem, pitch_buf, voice_factors_fx, 0 );
+
+ /* update st->mem_syn1_flt for ACELP core switching */
+ Copy( hLPDmem->mem_syn3, hLPDmem->mem_syn1_fx, M ); /* hLPDmem->q_mem_syn */
+
+ /* update ACELP core synthesis filter memory */
+ Copy( hLPDmem->mem_syn3, hLPDmem->mem_syn, M ); /* hLPDmem->q_mem_syn */
+
+ /* update old synthesis buffer - needed for ACELP internal sampling rate switching */
+ Copy( syn1_fx + sub( st->L_frame, L_SYN_MEM ), hLPDmem->mem_syn_r, L_SYN_MEM ); // st->Q_syn
+
+ /* save and delay synthesis to be used by SWB BWE */
+ IF( st->hBWE_FD != NULL )
+ {
+ st->hBWE_FD->mem_deemph_old_syn_fx = shl_sat( st->hBWE_FD->mem_deemph_old_syn_fx, sub( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ) ); /* st->Q_syn */
+ move16();
+ Scale_sig( st->hBWE_FD->old_syn_12k8_16k_fx, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ), sub( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ) ); /* st->Q_syn */
+ save_old_syn_fx( st->L_frame, syn1_fx, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx );
+ *q_old_syn_12k8_16 = st->Q_syn;
+ move16();
+ st->hBWE_FD->q_mem_deemph_old_syn = st->Q_syn;
+ move16();
+ }
+
+ Scale_sig( st->hLPDmem->syn, M + 1, sub( st->Q_syn, st->hLPDmem->q_lpd_syn ) ); /* st->Q_syn */
+ st->hLPDmem->q_lpd_syn = st->Q_syn;
+ move16();
+
+ /*Update MODE2 core switching memory*/
+ deemph_fx( syn1_fx, st->preemph_fac, st->L_frame, &( hLPDmem->syn[M] ) );
+ Copy( syn1_fx + add( st->L_frame, -M - 1 ), hLPDmem->syn, M + 1 ); /* st->Q_syn */
+ }
+
+ /*----------------------------------------------------------------*
+ * Encoding of all other frames
+ *----------------------------------------------------------------*/
+ ELSE
+ {
+
+ /*-----------------------------------------------------------------*
+ * Configure ACELP bit allocation
+ *-----------------------------------------------------------------*/
+
+ Word16 temp = getScaleFactor16( st->hGSCEnc->last_exc_dct_in_fx, L_FRAME16k );
+ Scale_sig( st->hGSCEnc->last_exc_dct_in_fx, L_FRAME16k, temp ); /* Q_last_exc_dct_in + temp */
+ st->hGSCEnc->Q_last_exc_dct_in = add( st->hGSCEnc->Q_last_exc_dct_in, temp );
+ move16();
+ nb_bits = 0;
+ move16();
+ st->acelp_cfg.FEC_mode = 0;
+ move16();
+ uc_two_stage_flag = 0;
+ move16();
+
+ test();
+ IF( !nelp_mode && !ppp_mode )
+ {
+ config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode );
+ }
+
+ /*-----------------------------------------------------------------*
+ * After inactive period, use the most up-to-date ISPs
+ *-----------------------------------------------------------------*/
+
+ test();
+ test();
+ IF( st->hDtxEnc != NULL && ( st->last_core_brate == FRAME_NO_DATA || EQ_32( st->last_core_brate, SID_2k40 ) ) )
+ {
+ Copy( st->hDtxEnc->lspCNG_fx, st->lsp_old_fx, M ); // Q15
+ lsp2lsf_fx( st->hDtxEnc->lspCNG_fx, st->lsf_old_fx, M, int_fs );
+ }
+
+ /*-----------------------------------------------------------------*
+ * Reset higher ACELP pre-quantizer in case of switching
+ *-----------------------------------------------------------------*/
+
+ IF( !st->use_acelp_preq )
+ {
+ st->mem_deemp_preQ_fx = 0;
+ move16();
+ st->mem_preemp_preQ_fx = 0;
+ move16();
+ st->last_code_preq = 0;
+ move16();
+ st->last_nq_preQ = 0;
+ move16();
+ }
+ st->use_acelp_preq = 0;
+ move16();
+
+ /*-----------------------------------------------------------------*
+ * LSF Quantization
+ * A[z] calculation
+ *-----------------------------------------------------------------*/
+
+ /* SC-VBR & channel-aware mode - back-up memories for LSF quantizer and synthesis filter */
+ lsf_syn_mem_backup_ivas_fx( st, &tilt_code_bck_fx, &gc_threshold_bck_fx, clip_var_bck_fx, &next_force_sf_bck, lsp_new, lsp_mid, &clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsp_mid_bck_fx, Bin_E_fx, Bin_E_old_fx, mem_syn_bck_fx, &mem_w0_bck_fx, &streaklimit_fx, &pstreaklen );
+
+ IF( !tdm_lp_reuse_flag )
+ {
+ lsf_enc_ivas_fx( st, lsf_new_fx, lsp_new, lsp_mid, Aq, tdm_low_rate_mode, st->GSC_IVAS_mode, tdm_lsfQ_PCh, Q_new );
+ }
+ ELSE
+ {
+ const Word16 *pt_interp_2_fx;
+
+ IF( NE_16( st->active_cnt, 1 ) )
+ {
+ Word16 beta_index;
+ Word16 lsf_wgts_fx[M];
+
+ /* intra_frame prediction for the LSFs */
+ lsp2lsf_fx( lsp_new, lsf_new_fx, M, 12800 );
+
+ Unified_weighting_fx( &st->Bin_E_fx[L_FFT / 2], add( Q_new, ( QSCALE - 2 ) ), lsf_new_fx, lsf_wgts_fx, st->bwidth == NB, (Word16) EQ_16( st->coder_type, UNVOICED ), st->sr_core, M );
+
+ tdm_SCh_lsf_reuse_fx( ENC, st->element_brate, lsf_new_fx, lsp_new, tdm_lsfQ_PCh, lsf_wgts_fx, &beta_index );
+
+ push_indice( hBstr, IND_IC_LSF_PRED, beta_index, TDM_IC_LSF_PRED_BITS );
+ }
+
+ pt_interp_2_fx = interpol_frac_12k8_fx;
+
+ test();
+ if ( EQ_16( tdm_low_rate_mode, 1 ) && GT_16( st->coder_type, UNVOICED ) )
+ {
+ pt_interp_2_fx = interpol_frac2_fx; // Q15
+ }
+
+ IF( EQ_16( st->active_cnt, 1 ) )
+ {
+ Copy( lsp_new, st->lsp_old_fx, M ); // Q15
+ lsp2lsf_fx( lsp_new, st->lsf_old_fx, M, st->sr_core ); // Q x2.56
+ lsp2lsf_fx( lsp_new, lsf_new_fx, M, st->sr_core ); // Q x2.56
+ }
+
+ /* LSP interpolation and conversion of LSPs to A(z) */
+ int_lsp_fx( st->L_frame, st->lsp_old_fx, lsp_new, Aq, M, pt_interp_2_fx, 0 );
+
+ /* Check LSF stability (distance between old LSFs and current LSFs) */
+ st->stab_fac_fx = lsf_stab_fx( lsf_new_fx, st->lsf_old_fx, 0, st->L_frame ); // Q15
+ move16();
+ }
+ test();
+ IF( EQ_16( st->last_core, HQ_CORE ) && st->element_mode > EVS_MONO )
+ {
+ /* Prepare ACB memory from last HQ frame */
+ tmpF_fx = hLPDmem->old_exc[0];
+ move16();
+ PREEMPH_FX( hLPDmem->old_exc, st->preemph_fac, st->L_frame, &tmpF_fx );
+ Copy( hLPDmem->old_exc + sub( st->L_frame, M ), hLPDmem->mem_syn, M ); /* Q_new */
+ Residu3_fx( Aq, hLPDmem->old_exc, old_exc_fx, st->L_frame, 0 );
+ }
+
+ test();
+ IF( st->last_core != ACELP_CORE && st->element_mode > EVS_MONO )
+ {
+ /* Prepare ACB memory of old_bwe_exc */
+ IF( EQ_16( st->L_frame, L_FRAME ) )
+ {
+ lerp( old_exc_fx, old_bwe_exc_fx, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC );
+ }
+ ELSE
+ {
+ lerp( old_exc_fx, old_bwe_exc_fx, L_EXC_MEM_DEC * 2, L_EXC_MEM_DEC );
+ }
+ }
+
+ /*---------------------------------------------------------------*
+ * Calculation of LP residual (filtering through A[z] filter)
+ *---------------------------------------------------------------*/
+
+ calc_residu_fx( st, inp, res_fx, Aq );
+ calculate_hangover_attenuation_gain_ivas_fx( st, &att_fx, vad_hover_flag );
+
+ IF( NE_16( att_fx, 32767 /* ONE_IN_Q15 */ ) )
+ {
+ v_multc_fixed_16_16( res_fx, att_fx, res_fx, st->L_frame );
+ }
+
+ /*-----------------------------------------------------------------*
+ * Determine TC subframe classification
+ *-----------------------------------------------------------------*/
+
+ IF( EQ_16( st->coder_type, TRANSITION ) )
+ {
+ tc_classif_enc_fx( Q_new, st->L_frame, &tc_subfr, &position, attack_flag, st->pitch[0], res_fx );
+
+ config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 1, NULL, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode );
+ }
+
+ /*---------------------------------------------------------------*
+ * Calculation of prediction for scaled innovation energy
+ * (for memory-less gain quantizer)
+ *---------------------------------------------------------------*/
+
+ IF( nb_bits > 0 )
+ {
+ Es_pred_enc_fx( &Es_pred_fx, &i, st->L_frame, res_fx, st->voicing_fx, nb_bits, uc_two_stage_flag, Q_new );
+ push_indice( hBstr, IND_ES_PRED, i, nb_bits );
+ }
+
+ /*------------------------------------------------------------*
+ * Encode excitation according to coding type
+ *------------------------------------------------------------*/
+ test();
+ test();
+ IF( tdm_low_rate_mode ) /* tdm stereo low rate mode */
+ {
+ IF( LE_16( st->coder_type, UNVOICED ) )
+ {
+ tdm_low_rate_enc( st, Aq, res_fx, syn_fx, exc_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, 0 /*attack_flag*/, lsf_new_fx, &tmp_noise_fx, Q_new );
+ }
+ ELSE /* GENERIC */
+ {
+ encod_gen_2sbfr( st, inp, Aw, Aq, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, Q_new, 0 );
+ }
+ }
+ ELSE IF( nelp_mode )
+ {
+ /* SC-VBR - NELP frames */
+ encod_nelp_ivas_fx( st, inp, Aw, Aq, res_fx, syn_fx, &tmp_noise_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, Q_new, 0 );
+ }
+
+ ELSE IF( EQ_16( st->coder_type, UNVOICED ) )
+ {
+ /* UNVOICED frames (Gauss. excitation) */
+ encod_unvoiced_ivas_fx( st, inp, Aw, Aq, Es_pred_fx, uc_two_stage_flag, res_fx, syn_fx, &tmp_noise_fx, exc_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, Q_new, 0 );
+ }
+ ELSE IF( EQ_16( st->coder_type, TRANSITION ) )
+ {
+ encod_tran_ivas_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, tc_subfr, position, unbits, 0, Q_new );
+ }
+ ELSE IF( ppp_mode )
+ {
+ /* SC-VBR - PPP frames */
+ IF( ( error = encod_ppp_ivas_fx( st, inp, Aw, Aq, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, Q_new, 0 ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+
+ IF( st->hSC_VBR->bump_up ) /* PPP failed, bump up */
+ {
+ /* restore memories of LSF quantizer and synthesis filter */
+ lsf_syn_mem_restore_ivas_fx( st, tilt_code_bck_fx, gc_threshold_bck_fx, clip_var_bck_fx, next_force_sf_bck, lsp_new, lsp_mid, clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsp_mid_bck_fx, Bin_E_fx, Bin_E_old_fx, mem_syn_bck_fx, mem_w0_bck_fx, streaklimit_fx, pstreaklen );
+ /* Configure ACELP bit allocation */
+ config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, 0, &uc_two_stage_flag, 0, 0, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode );
+
+ /* redo LSF quantization */
+ lsf_enc_ivas_fx( st, lsf_new_fx, lsp_new, lsp_mid, Aq, tdm_low_rate_mode, 0, NULL, Q_new );
+
+ /* recalculation of LP residual (filtering through A[z] filter) */
+ calc_residu_fx( st, inp, res_fx, Aq );
+ st->hTdCngEnc->burst_ho_cnt = 0;
+ move16();
+ /* VOICED frames in SC-VBR */
+ encod_gen_voic_ivas_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, 0, Q_new );
+ }
+ }
+ ELSE IF( EQ_16( st->coder_type, AUDIO ) || ( st->coder_type == INACTIVE && st->inactive_coder_type_flag ) )
+ {
+ /* AUDIO and INACTIVE frames (coded by GSC technology) */
+ encod_audio_ivas_fx( st, inp, Aw, Aq, res_fx, syn_fx, exc_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, attack_flag, lsf_new_fx, &tmp_noise_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, Q_new, 0 );
+ }
+ ELSE
+ {
+ /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */
+ encod_gen_voic_ivas_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, 0, Q_new );
+ }
+
+ FOR( i = 0; i < NB_SUBFR16k; i++ )
+ {
+ Scale_sig( &Aq[i * ( M + 1 )], ( M + 1 ), sub( Q12, sub( Q14, norm_s( Aq[i * ( M + 1 )] ) ) ) ); // Q12
+ }
+
+ /* update mem_syn1_flt for ACELP core switching */
+ Copy( hLPDmem->mem_syn, hLPDmem->mem_syn1_fx, M ); // Q_syn
+
+ /* update old synthesis buffer - needed for ACELP internal sampling rate switching */
+ Copy( syn_fx + sub( st->L_frame, L_SYN_MEM ), hLPDmem->mem_syn_r, L_SYN_MEM ); // st->Q_syn
+
+ Scale_sig( syn_fx, L_FRAME16k, sub( st->Q_syn, Q_new - 1 ) ); // Q_syn
+ /* save and delay synthesis to be used by SWB BWE */
+ IF( st->hBWE_FD != NULL )
+ {
+ st->hBWE_FD->mem_deemph_old_syn_fx = shl_sat( st->hBWE_FD->mem_deemph_old_syn_fx, sub( s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ), st->hBWE_FD->q_mem_deemph_old_syn ) ); // s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn )
+ move16();
+ Scale_sig( st->hBWE_FD->old_syn_12k8_16k_fx, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ), sub( s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ), st->hBWE_FD->q_mem_deemph_old_syn ) ); // s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn )
+
+ save_old_syn_fx( st->L_frame, syn_fx, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx );
+ *q_old_syn_12k8_16 = s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn );
+ move16();
+ st->hBWE_FD->q_mem_deemph_old_syn = s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn );
+ move16();
+ Scale_sig( syn_fx, st->L_frame, sub( st->Q_syn, s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ) ) ); // st->Q_syn
+ }
+
+ /*Update MODE2 core switching memory*/
+ Copy( syn_fx, syn1_fx, st->L_frame ); // st->Q_syn
+
+ Scale_sig( st->hLPDmem->syn, M + 1, sub( st->Q_syn, st->hLPDmem->q_lpd_syn ) ); // st->Q_syn
+ st->hLPDmem->q_lpd_syn = st->Q_syn;
+ move16();
+
+ /*Update MODE2 core switching memory*/
+ deemph_fx( syn1_fx, st->preemph_fac, st->L_frame, &( hLPDmem->syn[M] ) );
+
+ Copy( syn1_fx + add( st->L_frame, -M - 1 ), hLPDmem->syn, M + 1 ); // st->Q_syn
+
+ test();
+ IF( st->element_mode > EVS_MONO && st->hTcxEnc != NULL )
+ {
+ Copy( syn1_fx + shr( st->L_frame, 1 ), st->hTcxEnc->Txnq, shr( st->L_frame, 1 ) ); // st->Q_syn
+#ifdef MSAN_FIX
+ Scale_sig( st->hTcxEnc->Txnq + shr( st->L_frame, 1 ), sub( L_FRAME32k / 2 + 64, shr( st->L_frame, 1 ) ), sub( st->Q_syn, st->hTcxEnc->q_Txnq ) ); // st->Q_syn
+#else
+ Scale_sig( st->hTcxEnc->Txnq + shr( st->L_frame, 1 ), sub( L_FRAME32k / 2 + 64, shr( st->L_frame, 2 ) ), sub( st->Q_syn, st->hTcxEnc->q_Txnq ) );
+#endif
+ st->hTcxEnc->q_Txnq = st->Q_syn;
+ move16();
+ }
+
+ /*--------------------------------------------------------------------------------------*
+ * Modify the excitation signal when the noise is stationary
+ *--------------------------------------------------------------------------------------*/
+ test();
+ test();
+ test();
+ test();
+ IF( !( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) && NE_16( nelp_mode, 1 ) && !( EQ_16( st->element_mode, IVAS_SCE ) && tdm_low_rate_mode ) )
+ {
+ /* exc2 buffer is needed only for updating of Aq[] which is needed for core switching */
+ Copy( exc_fx, exc2_fx, st->L_frame ); // Q_new
+
+ stat_noise_uv_enc_ivas_fx( st, epsP, lsp_new, lsp_mid, Aq, exc2_fx, uc_two_stage_flag, Q_new );
+ }
+
+ /*-----------------------------------------------------------------*
+ * Encode supplementary information for Frame Error Concealment
+ *-----------------------------------------------------------------*/
+
+ Scale_sig( syn_fx, L_FRAME, sub( s_min( st->Q_syn, Q_new ), st->Q_syn ) ); // min( st->Q_syn, Q_new )
+#ifdef MSAN_FIX
+ Scale_sig( res_fx, st->L_frame, sub( s_min( st->Q_syn, Q_new ), Q_new ) ); // min( st->Q_syn, Q_new )
+#else
+ Scale_sig( res_fx, L_FRAME16k, sub( s_min( st->Q_syn, Q_new ), Q_new ) );
+#endif
+ FEC_encode_ivas_fx( hBstr, st->acelp_cfg, syn_fx, st->coder_type, st->clas, pitch_buf, res_fx, &st->Last_pulse_pos, st->L_frame, st->total_brate, s_min( st->Q_syn, Q_new ) );
+ IF( st->hBWE_TD != NULL )
+ {
+ IF( EQ_16( st->L_frame, L_FRAME ) )
+ {
+ Copy( Aq + 2 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); // Q12
+ }
+ ELSE
+ {
+ Copy( Aq + 3 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); // Q12
+ }
+ }
+
+
+ } /* end of active inp coding */
+
+ /*-----------------------------------------------------------------*
+ * Write ACELP unused bits
+ *-----------------------------------------------------------------*/
+ test();
+ test();
+ IF( NE_32( st->core_brate, SID_2k40 ) && st->core_brate != FRAME_NO_DATA && NE_32( st->core_brate, PPP_NELP_2k80 ) )
+ {
+ nBits = st->acelp_cfg.ubits; // Q0
+ move16();
+ WHILE( nBits > 0 )
+ {
+ i = s_min( nBits, 16 ); // Q0
+ push_indice( hBstr, IND_UNUSED, 0, i );
+ nBits = sub( nBits, i ); // Q0
+ }
+ }
+
+ /*-----------------------------------------------------------------*
+ * Apply non linearity in case of SWB TBE
+ *-----------------------------------------------------------------*/
+
+ IF( st->hBWE_TD != NULL )
+ {
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF( ( EQ_16( st->last_Opt_SC_VBR, 1 ) && st->Opt_SC_VBR == 0 ) || ( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, WB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, WB_TBE ) && NE_16( st->last_extl, FB_TBE ) ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && !st->tdm_LRTD_flag ) )
+ {
+ st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0;
+ move16();
+ set16_fx( st->hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET );
+ }
+
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF( !st->Opt_SC_VBR && ( st->idchan == 0 || NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) )
+ {
+ /* Apply a non linearity to the SHB excitation */
+ Copy_Scale_sig_16_32( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( sub( shl( Q_new, 1 ), sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc
+ non_linearity_ivas_fx( bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, Q_new, st->coder_type, voice_factors_fx, st->L_frame );
+ Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, negate( sub( shl( Q_new, 1 ), sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc
+ }
+
+ test();
+ if ( EQ_32( st->core_brate, SID_2k40 ) || st->core_brate == FRAME_NO_DATA )
+ {
+ st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0;
+ move16();
+ }
+ }
+
+ /*-----------------------------------------------------------------*
+ * Updates
+ *-----------------------------------------------------------------*/
+
+ if ( st->hBWE_TD != NULL )
+ {
+ st->Q_exc = Q_new;
+ move16();
+ }
+
+ updt_enc_fx( st, old_exc_fx, pitch_buf, Es_pred_fx, Aq, lsf_new_fx, lsp_new, old_bwe_exc_fx );
+ st->hLPDmem->q_lpd_old_exc = Q_new;
+ move16();
+
+ test();
+ test();
+ IF( st->hTdCngEnc != NULL && st->Opt_DTX_ON && GT_32( st->core_brate, SID_2k40 ) )
+ {
+ /* update CNG parameters in active frames */
+ Word16 q_exc = st->hTdCngEnc->cng_Qexc_buf[0];
+ move16();
+ FOR( Word16 ii = 0; ii < HO_HIST_SIZE; ii++ )
+ {
+ q_exc = s_min( q_exc, st->hTdCngEnc->cng_Qexc_buf[ii] );
+ }
+ q_exc = s_min( q_exc, Q_new );
+
+ Scale_sig( exc_fx, L_EXC - L_EXC_MEM, sub( q_exc, Q_new ) ); // q_exc
+ FOR( Word16 ii = 0; ii < HO_HIST_SIZE; ii++ )
+ {
+ Scale_sig( st->hTdCngEnc->cng_exc2_buf + ii * L_FFT, L_FFT, sub( q_exc, st->hTdCngEnc->cng_Qexc_buf[ii] ) ); // Q_exc
+ st->hTdCngEnc->cng_Qexc_buf[ii] = q_exc;
+ move16();
+ }
+ cng_params_upd_ivas_fx( lsp_new, exc_fx, st->L_frame, &st->hTdCngEnc->ho_circ_ptr, st->hTdCngEnc->ho_ener_circ_fx,
+ &st->hTdCngEnc->ho_circ_size, st->hTdCngEnc->ho_lsp_circ_fx, q_exc, ENC, st->hTdCngEnc->ho_env_circ_fx, &st->hTdCngEnc->cng_buf_cnt,
+ st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hDtxEnc->last_active_brate, st->element_mode,
+ st->hFdCngEnc->hFdCngCom->CngBandwidth );
+
+ IF( EQ_16( st->L_frame, L_FRAME ) )
+ {
+ /* store LSPs@16k, potentially to be used in CNG@16k */
+ Copy( st->lsp_old16k_fx, &( st->hTdCngEnc->ho_lsp_circ2_fx[( st->hTdCngEnc->ho_circ_ptr ) * M] ), M ); // Q15
+ }
+
+ /* set LSP@16k flag for the first buffer */
+ IF( EQ_16( st->L_frame, L_FRAME ) )
+ {
+ st->hTdCngEnc->ho_16k_lsp[st->hTdCngEnc->ho_circ_ptr] = 0;
+ }
+ ELSE
+ {
+ st->hTdCngEnc->ho_16k_lsp[st->hTdCngEnc->ho_circ_ptr] = 1;
+ }
+ move16();
+ /* efficient DTX hangover control */
+ IF( GT_16( st->hTdCngEnc->burst_ho_cnt, 1 ) )
+ {
+ dtx_hangover_control_fx( st, lsp_new );
+ }
+ }
+
+ /* SC-VBR update of average data rate */
+ IF( EQ_16( st->vad_flag, 1 ) )
+ {
+ /* reset in case of bitrate switching in EVS */
+ if ( st->hSC_VBR != NULL )
+ {
+ update_average_rate_fx( st->hSC_VBR, st->core_brate );
+ }
+ }
+ pop_wmops();
+
+ return error;
+}
diff --git a/lib_enc/acelp_core_switch_enc.c b/lib_enc/acelp_core_switch_enc.c
deleted file mode 100644
index 9d6f499db09e405ecf613f29cb1442072afc3305..0000000000000000000000000000000000000000
--- a/lib_enc/acelp_core_switch_enc.c
+++ /dev/null
@@ -1,44 +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
-#include "cnst.h"
-#include "rom_enc.h"
-#include "rom_com.h"
-#include "prot.h"
-#include "wmc_auto.h"
diff --git a/lib_enc/acelp_core_switch_enc_fx.c b/lib_enc/acelp_core_switch_enc_fx.c
index 029e3083ea893830d663c161a859cc83aa2943f9..b09f2396642259fa5a12b049819003c2491b40e4 100644
--- a/lib_enc/acelp_core_switch_enc_fx.c
+++ b/lib_enc/acelp_core_switch_enc_fx.c
@@ -71,11 +71,11 @@ void acelp_core_switch_enc_fx(
move16(); /* pointer to excitation signal in the current frame */
Copy( hLPDmem->old_exc, old_exc, L_EXC_MEM ); /*now old_exc has the same scaling as st_fx->old_exc; need to change later? */
- Copy( st_fx->old_Aq_12_8_fx, Aq, M + 1 );
- Copy( st_fx->old_Aq_12_8_fx, Aq + ( M + 1 ), M + 1 );
- T_op[0] = st_fx->pitch[0];
+ Copy( st_fx->old_Aq_12_8_fx, Aq, M + 1 ); /* Q12 */
+ Copy( st_fx->old_Aq_12_8_fx, Aq + ( M + 1 ), M + 1 ); /* Q12 */
+ T_op[0] = st_fx->pitch[0]; /* Q0 */
move16();
- T_op[1] = st_fx->pitch[1];
+ T_op[1] = st_fx->pitch[1]; /* Q0 */
move16();
/*----------------------------------------------------------------*
@@ -84,7 +84,7 @@ void acelp_core_switch_enc_fx(
IF( EQ_16( st_fx->last_L_frame, L_FRAME ) ) /* ACELP@12k8 core */
{
- inp = inp12k8;
+ inp = inp12k8; /* Q0 */
IF( GT_32( st_fx->core_brate, ACELP_24k40 ) )
{
@@ -97,7 +97,7 @@ void acelp_core_switch_enc_fx(
}
ELSE /* ACELP@16k core */
{
- inp = inp16k;
+ inp = inp16k; /* Q0 */
IF( LE_32( st_fx->core_brate, ACELP_8k00 ) )
{
@@ -139,9 +139,9 @@ void acelp_core_switch_enc_fx(
#else
IF( NE_16( st_fx->last_L_frame, L_FRAME ) )
{
- T_op[0] = shr( add( round_fx( L_shl( L_mult( 20480, T_op[0] ), 2 ) ), 1 ), 1 );
+ T_op[0] = shr( add( round_fx( L_shl( L_mult( 20480, T_op[0] ), 2 ) ), 1 ), 1 ); /* Q0 */
move16();
- T_op[1] = shr( add( round_fx( L_shl( L_mult( 20480, T_op[1] ), 2 ) ), 1 ), 1 );
+ T_op[1] = shr( add( round_fx( L_shl( L_mult( 20480, T_op[1] ), 2 ) ), 1 ), 1 ); /* Q0 */
move16();
}
#endif
@@ -170,11 +170,11 @@ void acelp_core_switch_enc_fx(
#else
FOR( i = 0; i < 20; i++ )
{
- hBstr->ind_list[IND_CORE_SWITCHING_CELP_SUBFRAME + i].value = hBstr->ind_list[TAG_ACELP_SUBFR_LOOP_START + i].value;
+ hBstr->ind_list[IND_CORE_SWITCHING_CELP_SUBFRAME + i].value = hBstr->ind_list[TAG_ACELP_SUBFR_LOOP_START + i].value; /* Q0 */
move16();
- hBstr->ind_list[IND_CORE_SWITCHING_CELP_SUBFRAME + i].nb_bits = hBstr->ind_list[TAG_ACELP_SUBFR_LOOP_START + i].nb_bits;
+ hBstr->ind_list[IND_CORE_SWITCHING_CELP_SUBFRAME + i].nb_bits = hBstr->ind_list[TAG_ACELP_SUBFR_LOOP_START + i].nb_bits; /* Q0 */
move16();
- hBstr->ind_list[TAG_ACELP_SUBFR_LOOP_START + i].nb_bits = -1;
+ hBstr->ind_list[TAG_ACELP_SUBFR_LOOP_START + i].nb_bits = -1; /* Q0 */
move16();
}
#endif
@@ -218,11 +218,11 @@ void acelp_core_switch_enc_ivas_fx(
move16(); /* pointer to excitation signal in the current frame */
Copy( hLPDmem->old_exc, old_exc, L_EXC_MEM ); /*now old_exc has the same scaling as st_fx->old_exc; need to change later? */
- Copy( st_fx->old_Aq_12_8_fx, Aq, M + 1 );
- Copy( st_fx->old_Aq_12_8_fx, Aq + ( M + 1 ), M + 1 );
- T_op[0] = st_fx->pitch[0];
+ Copy( st_fx->old_Aq_12_8_fx, Aq, M + 1 ); /* Q12 */
+ Copy( st_fx->old_Aq_12_8_fx, Aq + ( M + 1 ), M + 1 ); /* Q12 */
+ T_op[0] = st_fx->pitch[0]; /* Q12 */
move16();
- T_op[1] = st_fx->pitch[1];
+ T_op[1] = st_fx->pitch[1]; /* Q12 */
move16();
/*----------------------------------------------------------------*
@@ -231,7 +231,7 @@ void acelp_core_switch_enc_ivas_fx(
IF( EQ_16( st_fx->last_L_frame, L_FRAME ) ) /* ACELP@12k8 core */
{
- inp = inp12k8;
+ inp = inp12k8; /* Q0 */
IF( GT_32( st_fx->core_brate, ACELP_24k40 ) )
{
@@ -244,7 +244,7 @@ void acelp_core_switch_enc_ivas_fx(
}
ELSE /* ACELP@16k core */
{
- inp = inp16k;
+ inp = inp16k; /* Q0 */
IF( LE_32( st_fx->core_brate, ACELP_8k00 ) )
{
@@ -256,15 +256,15 @@ void acelp_core_switch_enc_ivas_fx(
}
ELSE
{
- cbrate = L_min( st_fx->core_brate, ACELP_22k60 );
+ cbrate = L_min( st_fx->core_brate, ACELP_22k60 ); /* Q0 */
}
}
IF( NE_16( st_fx->last_L_frame, L_FRAME ) )
{
- T_op[0] = shr( add( round_fx( L_shl( L_mult( 20480, T_op[0] ), 2 ) ), 1 ), 1 );
+ T_op[0] = shr( add( round_fx( L_shl( L_mult( 20480 /* 1.25 in Q14 */, T_op[0] ), 2 ) ), 1 ), 1 ); /* Q0 */
move16();
- T_op[1] = shr( add( round_fx( L_shl( L_mult( 20480, T_op[1] ), 2 ) ), 1 ), 1 );
+ T_op[1] = shr( add( round_fx( L_shl( L_mult( 20480 /* 1.25 in Q14 */, T_op[1] ), 2 ) ), 1 ), 1 ); /* Q0 */
move16();
}
@@ -280,7 +280,7 @@ void acelp_core_switch_enc_ivas_fx(
* bit-stream: modify the layer of sub frame CELP
*----------------------------------------------------------------*/
- i = find_indice( hBstr, TAG_ACELP_SUBFR_LOOP_START, &value, &nb_bits );
+ i = find_indice( hBstr, TAG_ACELP_SUBFR_LOOP_START, &value, &nb_bits ); /* Q0 */
while ( hBstr->ind_list[i].id == TAG_ACELP_SUBFR_LOOP_START )
{
@@ -312,13 +312,13 @@ void acelp_core_switch_enc_ivas_fx(
static void encod_gen_voic_core_switch_fx(
Encoder_State *st_fx, /* i/o: state structure */
- const Word16 L_frame, /* i : length of the frame */
- const Word16 inp[], /* i : input signal */
- const Word16 Aq[], /* i : LP coefficients */
- const Word16 A[], /* i : unquantized A(z) filter */
- const Word16 T_op[], /* i : open loop pitch */
- Word16 *exc, /* i/o: current non-enhanced excitation */
- const Word32 core_bitrate, /* i : switching frame bitrate */
+ const Word16 L_frame, /* i : length of the frame Q0*/
+ const Word16 inp[], /* i : input signal Q0*/
+ const Word16 Aq[], /* i : LP coefficients Q12*/
+ const Word16 A[], /* i : unquantized A(z) filter Q12*/
+ const Word16 T_op[], /* i : open loop pitch Q0*/
+ Word16 *exc, /* i/o: current non-enhanced excitation Q_exc*/
+ const Word32 core_bitrate, /* i : switching frame bitrate Q0*/
Word16 shift,
Word16 Q_new )
{
@@ -396,7 +396,7 @@ static void encod_gen_voic_core_switch_fx(
hTdCngEnc->burst_ho_cnt = 0;
move16();
- st_fx->L_frame = tmp16;
+ st_fx->L_frame = tmp16; /* Q0 */
move16();
/*------------------------------------------------------------------*
@@ -404,7 +404,7 @@ static void encod_gen_voic_core_switch_fx(
*------------------------------------------------------------------*/
- Copy( res, exc, L_SUBFR );
+ Copy( res, exc, L_SUBFR ); /* Q1 */
IF( EQ_16( L_frame, L_FRAME16k ) )
{
@@ -422,7 +422,7 @@ static void encod_gen_voic_core_switch_fx(
Scale_sig( h1, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */
/* scaling of xn[] to limit dynamic at 12 bits */
- Scale_sig( xn, L_SUBFR, shift );
+ Scale_sig( xn, L_SUBFR, shift ); /* Q_new */
/*----------------------------------------------------------------*
* Close-loop pitch search and quantization
@@ -430,7 +430,7 @@ static void encod_gen_voic_core_switch_fx(
*----------------------------------------------------------------*/
set16_fx( dummyF, -1, NB_SUBFR16k ); /* hack to signal ACELP->HQ switching frame */
pitch = pit_encode_fx( hBstr,
- st_fx->acelp_cfg.pitch_bits, core_bitrate, 0, L_frame, GENERIC, &pitch_limit_flag, 0, exc, L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn, 0 /*hStereoTD->tdm_Pitch_reuse_flag*/, dummyF /*hStereoTD->tdm_Pri_pitch_buf*/ );
+ st_fx->acelp_cfg.pitch_bits, core_bitrate, 0, L_frame, GENERIC, &pitch_limit_flag, 0, exc, L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn, 0 /*hStereoTD->tdm_Pitch_reuse_flag*/, dummyF /*hStereoTD->tdm_Pri_pitch_buf*/ ); /* Q6 */
/*-----------------------------------------------------------------*
* Find adaptive exitation
@@ -443,13 +443,13 @@ static void encod_gen_voic_core_switch_fx(
* or in case of floating point encoder & fixed p. decoder
*-----------------------------------------------------------------*/
- clip_gain = gp_clip_fx( st_fx->element_mode, core_bitrate, st_fx->voicing_fx, 0, GENERIC, xn, st_fx->clip_var_fx, sub( shift_wsp, 1 ) );
+ clip_gain = gp_clip_fx( st_fx->element_mode, core_bitrate, st_fx->voicing_fx, 0, GENERIC, xn, st_fx->clip_var_fx, sub( shift_wsp, 1 ) ); /* Q0 */
/*-----------------------------------------------------------------*
* LP filtering of the adaptive excitation, codebook target computation
*-----------------------------------------------------------------*/
- lp_flag = st_fx->acelp_cfg.ltf_mode;
- lp_select = lp_filt_exc_enc_fx( MODE1, GENERIC, 0, exc, h1, xn, y1, xn2, L_SUBFR, L_frame, g_corr, clip_gain, &gain_pit, &lp_flag );
+ lp_flag = st_fx->acelp_cfg.ltf_mode; /* Q0 */
+ lp_select = lp_filt_exc_enc_fx( MODE1, GENERIC, 0, exc, h1, xn, y1, xn2, L_SUBFR, L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); /* Q0 */
IF( EQ_16( lp_flag, NORMAL_OPERATION ) )
{
@@ -480,7 +480,7 @@ static void encod_gen_voic_core_switch_fx(
gp_clip_test_gain_pit_fx( st_fx->element_mode, core_bitrate, gain_pit, st_fx->clip_var_fx );
Lgcode = L_shl( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/
- gcode16 = round_fx( Lgcode );
+ gcode16 = round_fx( Lgcode ); /* Q0 */
hLPDmem->tilt_code = Est_tilt2( exc + 0, gain_pit, code, gain_code, &voice_fac, shift );
@@ -491,12 +491,12 @@ static void encod_gen_voic_core_switch_fx(
FOR( i = 0; i < L_SUBFR; i++ )
{
/* code in Q9, gain_pit in Q14 */
- L_tmp = L_mult( gcode16, code[i] );
+ L_tmp = L_mult( gcode16, code[i] ); /* Q10 */
#ifdef BASOP_NOGLOB
- L_tmp = L_shl_sat( L_tmp, 5 );
+ L_tmp = L_shl_sat( L_tmp, 5 ); /* Q15 */
L_tmp = L_mac_sat( L_tmp, exc[i], gain_pit );
- L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here */
- exc[i] = round_fx_sat( L_tmp );
+ L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here */
+ exc[i] = round_fx_sat( L_tmp ); /* Q_exc */
#else
L_tmp = L_shl( L_tmp, 5 );
L_tmp = L_mac( L_tmp, exc[i], gain_pit );
@@ -520,7 +520,7 @@ static void encod_gen_voic_core_switch_fx(
FOR( i = L_SUBFR; i < 2 * L_SUBFR; i++ )
{
#ifdef BASOP_NOGLOB
- exc[i] = round_fx_sat( L_shl_sat( L_mult_sat( exc[i], gain_pit ), 1 ) );
+ exc[i] = round_fx_sat( L_shl_sat( L_mult_sat( exc[i], gain_pit ), 1 ) ); /* Q_exc */
#else
exc[i] = round_fx( L_shl( L_mult( exc[i], gain_pit ), 1 ) );
#endif
@@ -531,13 +531,13 @@ static void encod_gen_voic_core_switch_fx(
static void encod_gen_voic_core_switch_ivas_fx(
Encoder_State *st_fx, /* i/o: state structure */
- const Word16 L_frame, /* i : length of the frame */
- const Word16 inp[], /* i : input signal */
- const Word16 Aq[], /* i : LP coefficients */
- const Word16 A[], /* i : unquantized A(z) filter */
- const Word16 T_op[], /* i : open loop pitch */
- Word16 *exc, /* i/o: current non-enhanced excitation */
- const Word32 core_bitrate, /* i : switching frame bitrate */
+ const Word16 L_frame, /* i : length of the frame Q0*/
+ const Word16 inp[], /* i : input signal Q0*/
+ const Word16 Aq[], /* i : LP coefficients Q12*/
+ const Word16 A[], /* i : unquantized A(z) filter Q12*/
+ const Word16 T_op[], /* i : open loop pitch Q0*/
+ Word16 *exc, /* i/o: current non-enhanced excitation Q_exc*/
+ const Word32 core_bitrate, /* i : switching frame bitrate Q0*/
Word16 shift,
Word16 Q_new )
{
@@ -607,14 +607,14 @@ static void encod_gen_voic_core_switch_ivas_fx(
* Calculation of LP residual (filtering through A[z] filter)
*------------------------------------------------------------------*/
- tmp16 = st_fx->L_frame;
+ tmp16 = st_fx->L_frame; /* Q0 */
move16();
st_fx->L_frame = L_SUBFR;
move16();
calc_residu_fx( st_fx, inp, res, Aq );
// hTdCngEnc->burst_ho_cnt = 0;
- st_fx->L_frame = tmp16;
+ st_fx->L_frame = tmp16; /* Q0 */
move16();
/*------------------------------------------------------------------*
@@ -622,7 +622,7 @@ static void encod_gen_voic_core_switch_ivas_fx(
*------------------------------------------------------------------*/
- Copy( res, exc, L_SUBFR );
+ Copy( res, exc, L_SUBFR ); /* Q_exc */
IF( EQ_16( L_frame, L_FRAME16k ) )
{
@@ -640,7 +640,7 @@ static void encod_gen_voic_core_switch_ivas_fx(
Scale_sig( h1, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */
/* scaling of xn[] to limit dynamic at 12 bits */
- Scale_sig( xn, L_SUBFR, shift );
+ Scale_sig( xn, L_SUBFR, shift ); /* Q_new */
/*----------------------------------------------------------------*
* Close-loop pitch search and quantization
@@ -648,7 +648,7 @@ static void encod_gen_voic_core_switch_ivas_fx(
*----------------------------------------------------------------*/
set16_fx( dummyF, -1, NB_SUBFR16k ); /* hack to signal ACELP->HQ switching frame */
pitch = pit_encode_ivas_fx( hBstr,
- st_fx->acelp_cfg.pitch_bits, core_bitrate, 0, L_frame, GENERIC, &pitch_limit_flag, 0, exc, L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn, 0 /*hStereoTD->tdm_Pitch_reuse_flag*/, dummyF /*hStereoTD->tdm_Pri_pitch_buf*/ );
+ st_fx->acelp_cfg.pitch_bits, core_bitrate, 0, L_frame, GENERIC, &pitch_limit_flag, 0, exc, L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn, 0 /*hStereoTD->tdm_Pitch_reuse_flag*/, dummyF /*hStereoTD->tdm_Pri_pitch_buf*/ ); /* Q6 */
/*-----------------------------------------------------------------*
* Find adaptive exitation
@@ -661,13 +661,13 @@ static void encod_gen_voic_core_switch_ivas_fx(
* or in case of floating point encoder & fixed p. decoder
*-----------------------------------------------------------------*/
- clip_gain = gp_clip_fx( st_fx->element_mode, core_bitrate, st_fx->voicing_fx, 0, GENERIC, xn, st_fx->clip_var_fx, sub( shift_wsp, 1 ) );
+ clip_gain = gp_clip_fx( st_fx->element_mode, core_bitrate, st_fx->voicing_fx, 0, GENERIC, xn, st_fx->clip_var_fx, sub( shift_wsp, 1 ) ); /* Q0 */
/*-----------------------------------------------------------------*
* LP filtering of the adaptive excitation, codebook target computation
*-----------------------------------------------------------------*/
- lp_flag = st_fx->acelp_cfg.ltf_mode;
- lp_select = lp_filt_exc_enc_ivas_fx( MODE1, GENERIC, 0, exc, h1, xn, y1, xn2, L_SUBFR, L_frame, g_corr, clip_gain, &gain_pit, &lp_flag );
+ lp_flag = st_fx->acelp_cfg.ltf_mode; /* Q0 */
+ lp_select = lp_filt_exc_enc_ivas_fx( MODE1, GENERIC, 0, exc, h1, xn, y1, xn2, L_SUBFR, L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); /* Q0 */
IF( EQ_16( lp_flag, NORMAL_OPERATION ) )
{
@@ -698,11 +698,11 @@ static void encod_gen_voic_core_switch_ivas_fx(
gp_clip_test_gain_pit_fx( st_fx->element_mode, core_bitrate, gain_pit, st_fx->clip_var_fx );
Lgcode = L_shl( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/
- gcode16 = round_fx( Lgcode );
+ gcode16 = round_fx( Lgcode ); /* Q0 */
// hLPDmem->tilt_code = Est_tilt2( exc + 0, gain_pit, code, gain_code, &voice_fac, shift );
// Q_new or shift ?? ->Qexc
- hLPDmem->tilt_code = est_tilt_ivas_fx( exc + 0, gain_pit, code, gain_code, &voice_fac, Q_new, L_SUBFR, 0 );
+ hLPDmem->tilt_code = est_tilt_ivas_fx( exc + 0, gain_pit, code, gain_code, &voice_fac, Q_new, L_SUBFR, 0 ); /* Q15 */
move16();
/*-----------------------------------------------------------------*
* Construct adaptive part of the excitation
@@ -711,12 +711,12 @@ static void encod_gen_voic_core_switch_ivas_fx(
FOR( i = 0; i < L_SUBFR; i++ )
{
/* code in Q9, gain_pit in Q14 */
- L_tmp = L_mult( gcode16, code[i] );
+ L_tmp = L_mult( gcode16, code[i] ); /* Q10 */
#ifdef BASOP_NOGLOB
- L_tmp = L_shl_sat( L_tmp, 5 );
+ L_tmp = L_shl_sat( L_tmp, 5 ); /* Q15 */
L_tmp = L_mac_sat( L_tmp, exc[i], gain_pit );
- L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here */
- exc[i] = round_fx_sat( L_tmp );
+ L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here */
+ exc[i] = round_fx_sat( L_tmp ); /* Q_exc */
#else
L_tmp = L_shl( L_tmp, 5 );
L_tmp = L_mac( L_tmp, exc[i], gain_pit );
@@ -741,7 +741,7 @@ static void encod_gen_voic_core_switch_ivas_fx(
FOR( i = L_SUBFR; i < 2 * L_SUBFR; i++ )
{
#ifdef BASOP_NOGLOB
- exc[i] = round_fx_sat( L_shl_sat( L_mult_sat( exc[i], gain_pit ), 1 ) );
+ exc[i] = round_fx_sat( L_shl_sat( L_mult_sat( exc[i], gain_pit ), 1 ) ); /* Q_exc */
#else
exc[i] = round_fx( L_shl( L_mult( exc[i], gain_pit ), 1 ) );
#endif
@@ -780,45 +780,47 @@ static void bwe_switch_enc_fx(
BSTR_ENC_HANDLE hBstr;
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
+ move32();
#endif
hBstr = st_fx->hBstr;
L = NS2SA_FX2( st_fx->input_Fs, FRAME_SIZE_NS );
/* set multiplication factor according to the sampling rate */
- tmp = extract_l( L_shr( st_fx->input_Fs, 14 ) );
- delta_fx = add( tmp, 1 );
+ tmp = extract_l( L_shr( st_fx->input_Fs, 14 ) ); /* Q0 */
+ delta_fx = add( tmp, 1 ); /* Q0 */
Fs_kHz = shl( delta_fx, 4 );
tmp = add( tmp, i_mult2( 3, ( sub( st_fx->last_L_frame, L_FRAME ) != 0 ) ) );
- ptmp = fpointers_tab[tmp];
+ ptmp = fpointers_tab[tmp]; /* Q15 */
move16();
- hp_filter_fx = ptmp;
- fdelay_fx = i_mult2( 16, delta_fx );
+ hp_filter_fx = ptmp; /* Q15 */
+ fdelay_fx = i_mult2( 16, delta_fx ); /* Q0 */
IF( EQ_16( st_fx->last_L_frame, L_FRAME ) )
{
- fdelay_fx = i_mult2( 20, delta_fx );
+ fdelay_fx = i_mult2( 20, delta_fx ); /* Q0 */
}
- n = i_mult2( N16_CORE_SW, delta_fx );
+ n = i_mult2( N16_CORE_SW, delta_fx ); /* Q0 */
set16_fx( tmp_mem_fx, 0, 2 * L_FILT48k );
set16_fx( tmp_mem2_fx, 0, 2 * L_FILT48k );
- Loverlapp_fx = i_mult2( delta_fx, SWITCH_OVERLAP_8k * 2 );
- gapsize_fx = i_mult2( delta_fx, NS2SA( 16000, SWITCH_GAP_LENGTH_NS ) );
+ Loverlapp_fx = i_mult2( delta_fx, SWITCH_OVERLAP_8k * 2 ); /* Q0 */
+ gapsize_fx = i_mult2( delta_fx, NS2SA( 16000, SWITCH_GAP_LENGTH_NS ) ); /* Q0 */
shift = sub( add( add( shr( L, 1 ), n ), Loverlapp_fx ), gapsize_fx );
- Copy( new_speech_fx + shift, synth_subfr_bwe_fx, add( gapsize_fx, fdelay_fx ) );
- Copy( new_speech_fx + sub( shift, fdelay_fx ), tmp_mem_fx, fdelay_fx );
+ Copy( new_speech_fx + shift, synth_subfr_bwe_fx, add( gapsize_fx, fdelay_fx ) ); /* Q0 */
+ Copy( new_speech_fx + sub( shift, fdelay_fx ), tmp_mem_fx, fdelay_fx ); /* Q0 */
- tmp = add( gapsize_fx, fdelay_fx );
- fir_fx( synth_subfr_bwe_fx, hp_filter_fx, synth_subfr_bwe_fx, tmp_mem_fx, tmp, fdelay_fx, 1, 0 );
- Copy( synth_subfr_bwe_fx + shr( fdelay_fx, 1 ), synth_subfr_bwe_fx, sub( gapsize_fx, shr( fdelay_fx, 1 ) ) );
+ tmp = add( gapsize_fx, fdelay_fx ); /* Q0 */
+ fir_fx( synth_subfr_bwe_fx, hp_filter_fx, synth_subfr_bwe_fx, tmp_mem_fx, tmp, fdelay_fx, 1, 0 ); /* Q0 */
+ Copy( synth_subfr_bwe_fx + shr( fdelay_fx, 1 ), synth_subfr_bwe_fx, sub( gapsize_fx, shr( fdelay_fx, 1 ) ) ); /* Q0 */
- tmp = i_mult2( Fs_kHz, 10 );
+ tmp = i_mult2( Fs_kHz, 10 ); /* Q0 */
fir_fx( new_speech_fx, hp_filter_fx, hb_synth_tmp_fx, tmp_mem2_fx, tmp, fdelay_fx, 1, 0 );
- min_sq_cross_fx = L_negate( 1 );
+ min_sq_cross_fx = -1;
+ move32();
Qsq = 0;
move16();
min_corr_fx = 0;
@@ -828,15 +830,15 @@ static void bwe_switch_enc_fx(
d1m_fx = 0;
move16();
- maxd1_fx = sub( tmp, add( gapsize_fx, fdelay_fx ) );
+ maxd1_fx = sub( tmp, add( gapsize_fx, fdelay_fx ) ); /* Q0 */
IF( EQ_16( delta_fx, 2 ) )
{
- maxd1_fx = shr( maxd1_fx, 1 );
+ maxd1_fx = shr( maxd1_fx, 1 ); /* Q0 */
}
ELSE IF( EQ_16( delta_fx, 3 ) )
{
- maxd1_fx = extract_h( L_mult( maxd1_fx, 10923 ) );
+ maxd1_fx = extract_h( L_mult( maxd1_fx, 10923 /* 0.333 in Q15 */ ) ); /* Q0 */
}
/* find delay */
@@ -870,21 +872,23 @@ static void bwe_switch_enc_fx(
push_indice_fx( hBstr, IND_CORE_SWITCHING_AUDIO_DELAY, d1m_fx, AUDIODELAYBITS );
- tmp = add( i_mult2( d1m_fx, delta_fx ), fdelay_fx );
- ptmp = &hb_synth_tmp_fx[tmp];
+ tmp = add( i_mult2( d1m_fx, delta_fx ), fdelay_fx ); /* Q0 */
+ ptmp = &hb_synth_tmp_fx[tmp]; /* Q0 */
move16();
E1_fx = dotprod_satcont( synth_subfr_bwe_fx, synth_subfr_bwe_fx, 0, 0, &q_tmp1, gapsize_fx, 1 );
E2_fx = dotprod_satcont( ptmp, ptmp, 0, 0, &q_tmp2, gapsize_fx, 1 );
IF( !E1_fx )
{
- E1_fx = shl( 1, 14 );
+ E1_fx = 1 << 14;
+ move16();
q_tmp1 = 14;
move16();
}
IF( !E2_fx )
{
- E2_fx = shl( 1, 14 );
+ E2_fx = 1 << 14;
+ move16();
q_tmp2 = 14;
move16();
}
@@ -898,7 +902,7 @@ static void bwe_switch_enc_fx(
#else
gain_fx = round_fx( Isqrt( L_tmp1 ) ); /*Q12 */
#endif
- ind1_fx = usquant_fx( gain_fx, &gain_fx, shr( MINVALUEOFFIRSTGAIN_FX, 1 ), shr( DELTAOFFIRSTGAIN_FX, 4 ), ( 1 << NOOFGAINBITS1 ) );
+ ind1_fx = usquant_fx( gain_fx, &gain_fx, shr( MINVALUEOFFIRSTGAIN_FX, 1 ), shr( DELTAOFFIRSTGAIN_FX, 4 ), ( 1 << NOOFGAINBITS1 ) ); /* Q0 */
push_indice_fx( hBstr, IND_CORE_SWITCHING_AUDIO_GAIN, ind1_fx, NOOFGAINBITS1 );
return;
@@ -1052,7 +1056,15 @@ static void bwe_switch_enc_ivas_fx(
}
-static Word16 dotprod_satcont( const Word16 *x, const Word16 *y, Word16 qx, Word16 qy, Word16 *qo, Word16 len, Word16 delta )
+static Word16 dotprod_satcont(
+ const Word16 *x, /* qx */
+ const Word16 *y, /* qy */
+ Word16 qx,
+ Word16 qy,
+ Word16 *qo,
+ Word16 len, /* Q0 */
+ Word16 delta /* Q0 */
+)
{
Word16 tmp_tabx[L_FRAME48k], tmp_taby[L_FRAME48k];
Word16 shift, q, ener, i;
@@ -1061,8 +1073,8 @@ static Word16 dotprod_satcont( const Word16 *x, const Word16 *y, Word16 qx, Word
Flag Overflow = 0;
#endif
- Copy( x, tmp_tabx, len );
- Copy( y, tmp_taby, len );
+ Copy( x, tmp_tabx, len ); /* qx */
+ Copy( y, tmp_taby, len ); /* qy */
shift = 0;
move16();
DO
@@ -1083,9 +1095,9 @@ static Word16 dotprod_satcont( const Word16 *x, const Word16 *y, Word16 qx, Word
{
FOR( i = 0; i < len; i += delta )
{
- tmp_tabx[i] = shr( tmp_tabx[i], 2 );
+ tmp_tabx[i] = shr( tmp_tabx[i], 2 ); /* qx - 2 */
move16();
- tmp_taby[i] = shr( tmp_taby[i], 2 );
+ tmp_taby[i] = shr( tmp_taby[i], 2 ); /* qx - 2 */
move16();
}
shift = add( shift, 4 );
diff --git a/lib_enc/acelp_enc_util.c b/lib_enc/acelp_enc_util.c
deleted file mode 100644
index eb574bd70a8cd1b2a23801d28b3bc6442f2644ac..0000000000000000000000000000000000000000
--- a/lib_enc/acelp_enc_util.c
+++ /dev/null
@@ -1,48 +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 "prot.h"
-#include "cnst.h"
-#include "rom_com.h"
-#include "wmc_auto.h"
-
-/*-------------------------------------------------------------------*
- * E_ACELP_toeplitz_mul()
- *
- * Multiplication of Toeplitz matrix with vector c, such that d = toeplitz(R)*c
- *-------------------------------------------------------------------*/
diff --git a/lib_enc/acelp_enc_util_fx.c b/lib_enc/acelp_enc_util_fx.c
index 8fb74129723e6127d02c26efde383be94b41d343..9992ce6ad1a3b10d6524f2e4219b29da9238b935 100644
--- a/lib_enc/acelp_enc_util_fx.c
+++ b/lib_enc/acelp_enc_util_fx.c
@@ -34,11 +34,12 @@
* Vector length is L_SUBFR
*/
Word16 E_ACELP_toeplitz_mul_fx(
- const Word16 R[],
- const Word16 c[],
- Word16 d[],
- const Word16 L_subfr,
- const Word16 highrate )
+ const Word16 R[], /* Q9 */
+ const Word16 c[], /* Qx */
+ Word16 d[], /* exp(j) */
+ const Word16 L_subfr, /* Q0 */
+ const Word16 highrate /* Q0 */
+)
{
static const Word16 step = 4;
Word16 k, j, i;
@@ -57,20 +58,20 @@ Word16 E_ACELP_toeplitz_mul_fx(
L_maxloc = L_deposit_l( 0 );
FOR( i = k; i < L_subfr; i += step )
{
- s = L_mult( R[i], c[0] );
+ s = L_mult( R[i], c[0] ); /* Q10 + Qx */
FOR( j = 1; j < i; j++ )
{
- s = L_mac( s, R[i - j], c[j] );
+ s = L_mac( s, R[i - j], c[j] ); /* Q10 + Qx */
}
FOR( ; j < L_subfr; j++ )
{
- s = L_mac( s, R[j - i], c[j] );
+ s = L_mac( s, R[j - i], c[j] ); /* Q10 + Qx */
}
y32[i] = s;
move32();
s = L_abs( s );
- L_maxloc = L_max( s, L_maxloc );
+ L_maxloc = L_max( s, L_maxloc ); /* Q10 + Qx */
}
/* tot += 3*max / 8 */
L_maxloc = L_shr( L_maxloc, 2 );
@@ -113,16 +114,16 @@ Word16 E_ACELP_toeplitz_mul_fx(
/* Limit exponent to avoid overflows elsewhere. */
j = s_min( sub( norm_l( L_tot ), 4 + 16 ), 15 - 16 ); /* 4 -> 16 x tot */
- Copy_Scale_sig_32_16( y32, d, L_subfr, j );
+ Copy_Scale_sig_32_16( y32, d, L_subfr, j ); /* exp(j) */
return j;
}
void E_ACELP_weighted_code(
- const Word16 code[], /* i: code */
- const Word16 H[], /* i: impulse response */
- Word16 Q, /* i: Q format of H */
- Word16 y[] /* o: weighted code */
+ const Word16 code[], /* i: code Q9*/
+ const Word16 H[], /* i: impulse response Q*/
+ Word16 Q, /* i: Q format of H */
+ Word16 y[] /* o: weighted code Q9*/
)
{
Word16 i, j, k, one, n, nz[L_SUBFR];
@@ -150,8 +151,8 @@ void E_ACELP_weighted_code(
set16_fx( y, 0, j );
FOR( k = 0; k < L_SUBFR - j; k++ )
{
- L_tmp = L_mult( code[j], H[k] );
- y[j + k] = extract_h( L_shl( L_tmp, Q ) );
+ L_tmp = L_mult( code[j], H[k] ); /* Q10 + Q */
+ y[j + k] = extract_h( L_shl( L_tmp, Q ) ); /* Q9 */
}
FOR( i = 1; i < n; ++i )
@@ -161,16 +162,16 @@ void E_ACELP_weighted_code(
FOR( k = 0; k < L_SUBFR - j; k++ )
{
L_tmp = L_mult( y[j + k], one );
- L_tmp = L_mac( L_tmp, code[j], H[k] );
- y[j + k] = extract_h( L_shl( L_tmp, Q ) );
+ L_tmp = L_mac( L_tmp, code[j], H[k] ); /* Q10 + Q */
+ y[j + k] = extract_h( L_shl( L_tmp, Q ) ); /* Q9*/
}
}
}
void E_ACELP_conv(
- const Word16 xn2[], /* i */
- const Word16 h2[], /* i */
- Word16 cn2[] /* o */
+ const Word16 xn2[], /* i Qx*/
+ const Word16 h2[], /* i Q12*/
+ Word16 cn2[] /* o Q0*/
)
{
Word16 i, k;
@@ -182,25 +183,25 @@ void E_ACELP_conv(
{
/*cn2[k] = xn2[k]; */
Word64 L_tmp_64;
- L_tmp_64 = W_deposit32_l( L_mult( xn2[k], 0x800 ) );
+ L_tmp_64 = W_deposit32_l( L_mult( xn2[k], 0x800 ) ); /* 4Q11 */
FOR( i = 0; i < k; i++ )
{
/*cn2[k]-=cn2[i]*h2[k-i];*/
L_tmp_64 = W_msu0_16_16( L_tmp_64, cn2[i], h2[k - i] ); /*h2 4Q11*/
}
- L_tmp = W_sat_l( L_tmp_64 );
+ L_tmp = W_sat_l( L_tmp_64 ); /* 4Q11 */
#ifdef BASOP_NOGLOB
- cn2[k] = round_fx_o( L_shl_o( L_tmp, 5, &Overflow ), &Overflow );
+ cn2[k] = round_fx_o( L_shl_o( L_tmp, 5, &Overflow ), &Overflow ); /* Q0 */
#else
cn2[k] = round_fx( L_shl( L_tmp, 5 ) );
#endif
}
}
-void E_ACELP_conv_ivas(
- const Word16 xn2[], /* i */
- const Word16 h2[], /* i */
- Word16 cn2[] /* o */
+void E_ACELP_conv_ivas_fx(
+ const Word16 xn2[], /* i Qx*/
+ const Word16 h2[], /* i Q12*/
+ Word16 cn2[] /* o Q0*/
)
{
Word16 i, k;
@@ -212,15 +213,15 @@ void E_ACELP_conv_ivas(
{
/*cn2[k] = xn2[k]; */
Word64 L_tmp_64;
- L_tmp_64 = W_deposit32_l( L_mult0( xn2[k], 0x800 ) );
+ L_tmp_64 = W_deposit32_l( L_mult0( xn2[k], 0x800 ) ); /* 4Q11 */
FOR( i = 0; i < k; i++ )
{
/*cn2[k]-=cn2[i]*h2[k-i];*/
L_tmp_64 = W_msu0_16_16( L_tmp_64, cn2[i], h2[k - i] ); /*h2 4Q11*/
}
- L_tmp = W_sat_l( L_tmp_64 );
+ L_tmp = W_sat_l( L_tmp_64 ); /* 4Q11 */
#ifdef BASOP_NOGLOB
- cn2[k] = round_fx_o( L_shl_o( L_tmp, 5, &Overflow ), &Overflow );
+ cn2[k] = round_fx_o( L_shl_o( L_tmp, 5, &Overflow ), &Overflow ); /* Q0*/
#else
cn2[k] = round_fx( L_shl( L_tmp, 5 ) );
#endif
@@ -228,11 +229,11 @@ void E_ACELP_conv_ivas(
}
}
void E_ACELP_build_code(
- Word16 nb_pulse, /* i */
- const Word16 codvec[], /* i */
- const Word16 sign[], /* i */
- Word16 code[], /* o */
- Word16 ind[] /* o */
+ Word16 nb_pulse, /* i Q0*/
+ const Word16 codvec[], /* i Q0*/
+ const Word16 sign[], /* i Q0*/
+ Word16 code[], /* o Q9*/
+ Word16 ind[] /* o Q0*/
)
{
Word16 i, k, val, index, track, tmp, vec[4];
@@ -252,42 +253,42 @@ void E_ACELP_build_code(
FOR( k = 0; k < nb_pulse; ++k )
{
- i = codvec[k]; /* read pulse position */
+ i = codvec[k]; /* read pulse position Q0*/
move16();
- val = sign[i]; /* read sign */
+ val = sign[i]; /* read sign Q0*/
move16();
index = shr( i, 2 ); /* pos of pulse (0..15) */
track = s_and( i, 4 - 1 ); /* i % 4; */
- tmp = add( code[i], _1_Q9 );
+ tmp = add( code[i], _1_Q9 ); /* Q9 */
if ( val <= 0 )
{
- tmp = sub( code[i], _1_Q9 );
+ tmp = sub( code[i], _1_Q9 ); /* Q9 */
}
- code[i] = tmp;
+ code[i] = tmp; /* Q9 */
move16();
if ( val <= 0 )
{
- index = add( index, 16 );
+ index = add( index, 16 ); /* Q0 */
}
/* Calculate Current Store Index (we started at -1) so we increment first */
- i = add( vec[track], 1 );
+ i = add( vec[track], 1 ); /* Q0 */
/* Save Next Store Index */
- vec[track] = i;
+ vec[track] = i; /* Q0 */
move16();
- ind[i] = index;
+ ind[i] = index; /* Q0 */
move16();
}
}
void E_ACELP_setup_pulse_search_pos(
- const PulseConfig *config, /* i: pulse configuration */
- Word16 k, /* i: interation number */
- UWord8 ipos[] /* o: pulse search positions */
+ const PulseConfig *config, /* i: pulse configuration */
+ Word16 k, /* i: interation number Q0*/
+ UWord8 ipos[] /* o: pulse search positions Q0*/
)
{
Word16 restpulses, iPulse;
@@ -308,30 +309,30 @@ void E_ACELP_setup_pulse_search_pos(
/* add tracks from left */
FOR( iPulse = 0; iPulse < restpulses; iPulse++ )
{
- ipos[config->nb_pulse - restpulses + iPulse] = (UWord8) iPulse;
+ ipos[config->nb_pulse - restpulses + iPulse] = (UWord8) iPulse; /* Q0 */
move16();
}
/* Put the same track on the next position, because the 1-pulse search
* will access it to determine if this could be in any track. */
- ipos[config->nb_pulse] = ipos[config->nb_pulse - 1];
+ ipos[config->nb_pulse] = ipos[config->nb_pulse - 1]; /* Q0 */
move16();
BREAK;
case TRACKPOS_FIXED_EVEN: /* fixed track positions, odd tracks */
/* odd tracks, switch order for every iteration */
- ipos[config->nb_pulse - restpulses] = (UWord8) s_and( lshl( k, 1 ), 2 );
- move16(); /* 0 for even k, 2 for odd */
- ipos[config->nb_pulse - restpulses + 1] = (UWord8) s_xor( ipos[config->nb_pulse - restpulses], 2 );
- move16(); /* 2 for even k, 0 for odd */
+ ipos[config->nb_pulse - restpulses] = (UWord8) s_and( lshl( k, 1 ), 2 ); /* Q0 */
+ move16(); /* 0 for even k, 2 for odd */
+ ipos[config->nb_pulse - restpulses + 1] = (UWord8) s_xor( ipos[config->nb_pulse - restpulses], 2 ); /* Q0 */
+ move16(); /* 2 for even k, 0 for odd */
BREAK;
case TRACKPOS_FIXED_TWO: /* two tracks instead of four */
/* Put the next track on the next position, because the 1-pulse search
* will access it to determine if this could be in any track. */
- ipos[config->nb_pulse] = (UWord8) s_and( add( ipos[config->nb_pulse - 1], 1 ), 3 );
+ ipos[config->nb_pulse] = (UWord8) s_and( add( ipos[config->nb_pulse - 1], 1 ), 3 ); /* Q0 */
move16();
BREAK;
default: /* one or three free track positions */
/* copy an extra position from table - 1pulse search will access this */
- ipos[config->nb_pulse] = E_ROM_tipos[add( shl( k, 2 ), config->nb_pulse )];
+ ipos[config->nb_pulse] = E_ROM_tipos[add( shl( k, 2 ), config->nb_pulse )]; /* Q0 */
move16();
BREAK;
}
diff --git a/lib_enc/amr_wb_enc.c b/lib_enc/amr_wb_enc.c
deleted file mode 100644
index 6056f600b461d55e0226c5ee5c53648597aabd79..0000000000000000000000000000000000000000
--- a/lib_enc/amr_wb_enc.c
+++ /dev/null
@@ -1,45 +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 "rom_enc.h"
-#include "rom_com.h"
-#include "prot.h"
-#include "wmc_auto.h"
-
-#include "prot_fx.h"
diff --git a/lib_enc/amr_wb_enc_fx.c b/lib_enc/amr_wb_enc_fx.c
index 7b177d99a067b14fa75e57f906fe7c541ac4cb7f..69c356b5ddb3e9055f0384bf43cdc91174a83ae6 100644
--- a/lib_enc/amr_wb_enc_fx.c
+++ b/lib_enc/amr_wb_enc_fx.c
@@ -25,8 +25,8 @@
void amr_wb_enc_fx(
Encoder_State *st, /* i/o: encoder state structure */
- const Word16 input_sp[], /* i : input signal */
- const Word16 n_samples /* i : number of input samples */
+ const Word16 input_sp[], /* i : input signal Q0*/
+ const Word16 n_samples /* i : number of input samples Q0*/
)
{
Word16 i, delay;
@@ -95,25 +95,28 @@ void amr_wb_enc_fx(
* Initialization
*------------------------------------------------------------------*/
- st->L_frame = L_FRAME;
+ st->L_frame = L_FRAME; /* Q0 */
move16();
- st->gamma = GAMMA1;
+ st->gamma = GAMMA1; /* Q15 */
move16();
- st->core = AMR_WB_CORE;
+ st->core = AMR_WB_CORE; /* Q0 */
move16();
- st->core_brate = st->total_brate;
+ st->core_brate = st->total_brate; /* Q0 */
move16();
- st->input_bwidth = st->last_input_bwidth;
+ st->input_bwidth = st->last_input_bwidth; /* Q0 */
move16();
- st->bwidth = st->last_bwidth;
+ st->bwidth = st->last_bwidth; /* Q0 */
move16();
st->coder_type = GENERIC;
move16();
input_frame = st->input_frame_fx;
move16(); /* frame length of the input signal */
st->extl = -1;
+ move16();
st->encoderPastSamples_enc = ( L_FRAME * 9 ) / 16;
+ move16();
st->encoderLookahead_enc = L_LOOK_12k8;
+ move16();
st->bpf_off = 0;
move16();
test();
@@ -140,18 +143,18 @@ void amr_wb_enc_fx(
set16_fx( old_inp, 0, L_INP_12k8 );
exc = old_exc + L_EXC_MEM; /* pointer to excitation signal in the current frame */
- Copy( hLPDmem->old_exc, old_exc, L_EXC_MEM );
+ Copy( hLPDmem->old_exc, old_exc, L_EXC_MEM ); /* q_lpd_old_exc */
new_inp = old_inp + L_INP_MEM; /* pointer to new samples of the input signal */
inp = new_inp - L_LOOK_12k8; /* pointer to current frame of input signal */
wsp = old_wsp + L_WSP_MEM; /* pointer to current frame of weighted signal */
- Copy( st->old_inp_12k8_fx, old_inp, L_INP_MEM );
- Copy( st->old_wsp_fx, old_wsp, L_WSP_MEM );
+ Copy( st->old_inp_12k8_fx, old_inp, L_INP_MEM ); /* exp_old_inp_12k8 */
+ Copy( st->old_wsp_fx, old_wsp, L_WSP_MEM ); /* exp(exp_old_wsp) */
- new_inp_16k = old_inp_16k + L_INP_MEM; /* pointer to new samples of the input signal in 16kHz core */
- inp_16k = new_inp_16k - L_LOOK_16k; /* pointer to the current frame of input signal in 16kHz core */
- Copy( st->old_inp_16k_fx, old_inp_16k, L_INP_MEM );
+ new_inp_16k = old_inp_16k + L_INP_MEM; /* pointer to new samples of the input signal in 16kHz core */
+ inp_16k = new_inp_16k - L_LOOK_16k; /* pointer to the current frame of input signal in 16kHz core */
+ Copy( st->old_inp_16k_fx, old_inp_16k, L_INP_MEM ); /* q_old_inp */
/* in case of switching, reset AMR-WB BWE memories */
test();
@@ -167,14 +170,14 @@ void amr_wb_enc_fx(
/* get delay to synchronize ACELP and MDCT frame */
delay = NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS );
- Copy( st->input_fx - delay, st->old_input_signal_fx, input_frame + delay );
+ Copy( st->input_fx - delay, st->old_input_signal_fx, input_frame + delay ); /* q_inp */
/*----------------------------------------------------------------*
* Buffering of input signal
* HP filtering
*----------------------------------------------------------------*/
- Copy( input_sp, st->input_fx, n_samples );
+ Copy( input_sp, st->input_fx, n_samples ); /* Q0 */
FOR( i = n_samples; i < input_frame; i++ )
{
st->input_fx[i] = 0;
@@ -195,25 +198,25 @@ void amr_wb_enc_fx(
/* in case of switching, do not apply BPF */
st->bpf_off = 1;
move16();
- st->rate_switching_reset = lsp_convert_poly_fx( st->lsp_old_fx, L_FRAME, 1 );
+ st->rate_switching_reset = lsp_convert_poly_fx( st->lsp_old_fx, L_FRAME, 1 ); /* Q0 */
/* convert old quantized LSF vector */
lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, INT_FS_FX );
/* Reset LPC mem */
- Copy( GEWB_Ave_fx, st->mem_AR_fx, M );
+ Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); /* x2.56 */
set16_fx( st->mem_MA_fx, 0, M );
/* update synthesis filter memories */
synth_mem_updt2( L_FRAME, st->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn1_fx, hLPDmem->mem_syn, ENC );
- Copy( hLPDmem->mem_syn1_fx, hLPDmem->mem_syn2, M );
+ Copy( hLPDmem->mem_syn1_fx, hLPDmem->mem_syn2, M ); /* q_mem_syn */
- Copy( hLPDmem->old_exc, old_exc, L_EXC_MEM );
- Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn3, M );
+ Copy( hLPDmem->old_exc, old_exc, L_EXC_MEM ); /* q_lpd_old_exc */
+ Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn3, M ); /* q_mem_syn */
/* lsp -> isp */
Copy( stable_ISP_fx, isp_tmp, M );
- lsp2isp_fx( st->lsp_old_fx, st->lsp_old_fx, isp_tmp, M );
+ lsp2isp_fx( st->lsp_old_fx, st->lsp_old_fx, isp_tmp, M ); /* Q15 */
}
/* update buffer of old subframe pitch values */
@@ -223,17 +226,17 @@ void amr_wb_enc_fx(
IF( EQ_16( st->last_L_frame, L_FRAME32k ) )
{
/* (float)12800/(float)32000; */
- tmp = 13107;
+ tmp = 13107; /* 0.4 in Q15 */
}
ELSE IF( EQ_16( st->last_L_frame, 512 ) )
{
/* (float)12800/(float)25600; */
- tmp = 16384;
+ tmp = 16384; /* 0.5 in Q15 */
}
ELSE /* st->last_L_frame == L_FRAME16k */
{
/* (float)12800/(float)16000; */
- tmp = 26214;
+ tmp = 26214; /* 0.8 in Q15 */
}
FOR( i = NB_SUBFR16k - NB_SUBFR; i < NB_SUBFR16k; i++ )
@@ -252,7 +255,7 @@ void amr_wb_enc_fx(
test();
if ( EQ_16( st->last_bwidth, NB ) && st->ini_frame != 0 )
{
- st->rate_switching_reset = 1;
+ st->rate_switching_reset = 1; /* Q0 */
move16();
}
@@ -263,8 +266,8 @@ void amr_wb_enc_fx(
modify_Fs_fx( st->input_fx, input_frame, st->input_Fs, new_inp, 12800, st->mem_decim_fx, 0, &Q_new_inp, &mem_decim_size );
/* update signal buffer */
- Copy( new_inp, st->buf_speech_enc + L_FRAME, L_FRAME );
- Scale_sig( st->buf_speech_enc + L_FRAME, L_FRAME, 1 );
+ Copy( new_inp, st->buf_speech_enc + L_FRAME, L_FRAME ); /* Q0 */
+ Scale_sig( st->buf_speech_enc + L_FRAME, L_FRAME, 1 ); /* Q1 */
/*------------------------------------------------------------------*
* Perform fixed preemphasis through 1 - g*z^-1
@@ -273,7 +276,6 @@ void amr_wb_enc_fx(
Preemph_scaled( new_inp, &Q_new, &st->mem_preemph_fx, st->Q_max, PREEMPH_FAC, 0, 1, L_Q_MEM, L_FRAME, st->last_coder_type, 1 );
Q_exp = sub( Q_new, st->Q_old );
- move16();
st->Q_old = Q_new;
move16();
@@ -281,7 +283,6 @@ void amr_wb_enc_fx(
hNoiseEst->ave_enr2_fx, hNoiseEst->fr_bands1_fx, hNoiseEst->fr_bands2_fx, st->Bin_E_old_fx );
Q_exp = sub( Q_new, st->prev_Q_new );
- move16();
Scale_mem_enc( Q_exp, old_inp_16k, old_exc, hBWE_TD->old_bwe_exc_fx, &( hLPDmem->mem_w0 ), hLPDmem->mem_syn, hLPDmem->mem_syn2,
&st->mem_deemp_preQ_fx, hGSCEnc->last_exc_dct_in_fx, hBWE_FD->old_input_lp_fx );
@@ -305,7 +306,8 @@ void amr_wb_enc_fx(
*----------------------------------------------------------------*/
st->vad_flag = wb_vad_fx( st, fr_bands, &noisy_speech_HO, &clean_speech_HO, &NB_speech_HO,
- &snr_sum_he, &localVAD_HE_SAD, &( st->flag_noisy_speech_snr ), Q_new, hVAD, hNoiseEst, st->lp_speech_fx, st->lp_noise_fx );
+ &snr_sum_he, &localVAD_HE_SAD, &( st->flag_noisy_speech_snr ), Q_new, hVAD, hNoiseEst, st->lp_speech_fx, st->lp_noise_fx ); /* Q0 */
+ move16();
if ( st->vad_flag == 0 )
{
@@ -322,12 +324,13 @@ void amr_wb_enc_fx(
IF( NE_16( st->last_core, AMR_WB_CORE ) )
{
- st->fd_cng_reset_flag = 1;
+ st->fd_cng_reset_flag = 1; /* Q0 */
move16();
}
ELSE IF( s_and( ( st->fd_cng_reset_flag > 0 ), (Word16) ( LT_16( st->fd_cng_reset_flag, 10 ) ) ) )
{
- st->fd_cng_reset_flag = add( st->fd_cng_reset_flag, 1 );
+ st->fd_cng_reset_flag = add( st->fd_cng_reset_flag, 1 ); /* Q0 */
+ move16();
}
ELSE
{
@@ -358,14 +361,14 @@ void amr_wb_enc_fx(
IF( NE_16( st->bwidth, NB ) )
{
- lp_bckr = Mean32( hNoiseEst->bckr_fx, 10 );
+ lp_bckr = Mean32( hNoiseEst->bckr_fx, 10 ); /* q_bckr */
}
ELSE
{
- lp_bckr = Mean32( hNoiseEst->bckr_fx + 1, 9 );
+ lp_bckr = Mean32( hNoiseEst->bckr_fx + 1, 9 ); /* q_bckr */
}
#ifdef BASOP_NOGLOB
- hp_bckr = L_shr( L_add_sat( hNoiseEst->bckr_fx[st->max_band - 1], hNoiseEst->bckr_fx[st->max_band] ), 1 );
+ hp_bckr = L_shr( L_add_sat( hNoiseEst->bckr_fx[st->max_band - 1], hNoiseEst->bckr_fx[st->max_band] ), 1 ); /* q_bckr */
#else
hp_bckr = L_shr( L_add( hNoiseEst->bckr_fx[st->max_band - 1], hNoiseEst->bckr_fx[st->max_band] ), 1 );
#endif
@@ -373,11 +376,11 @@ void amr_wb_enc_fx(
{
hp_bckr = L_deposit_l( 1 );
}
- tmp = BASOP_Util_Divide3232_Scale( lp_bckr, hp_bckr, &e_tmp );
+ tmp = BASOP_Util_Divide3232_Scale( lp_bckr, hp_bckr, &e_tmp ); /* exp(e_tmp) */
Ltmp = L_shr_r( L_deposit_h( tmp ), sub( 15, e_tmp ) );
- st->bckr_tilt_lt = L_add( Mpy_32_16_r( st->bckr_tilt_lt, 29491 ), Mpy_32_16_r( Ltmp, 3277 ) );
+ st->bckr_tilt_lt = L_add( Mpy_32_16_r( st->bckr_tilt_lt, 29491 ), Mpy_32_16_r( Ltmp, 3277 ) ); /* Q16 */
- corr_shift = correlation_shift_fx( hNoiseEst->totalNoise_fx );
+ corr_shift = correlation_shift_fx( hNoiseEst->totalNoise_fx ); /* Q15 */
/*----------------------------------------------------------------*
* WB, SWB and FB bandwidth detector
@@ -404,7 +407,7 @@ void amr_wb_enc_fx(
/* reset the OL pitch tracker memories during inactive frames */
pitch_ol_init_fx( &st->old_thres_fx, &st->old_pitch, &st->delta_pit, &st->old_corr_fx );
}
- old_pitch1 = st->pitch[1];
+ old_pitch1 = st->pitch[1]; /* Q0 */
move16();
analy_lp_AMR_WB_fx( inp, &ener, A, epsP_h, epsP_l, isp_new, st->lsp_old1_fx,
isf_new, st->old_pitch_la, st->old_voicing_la, Q_new, Q_r );
@@ -427,9 +430,9 @@ void amr_wb_enc_fx(
move16();
}
pitch_ol_fx( st->pitch, st->voicing_fx, &st->old_pitch, &st->old_corr_fx, corr_shift, &st->old_thres_fx, &st->delta_pit, st->old_wsp2_fx, wsp, st->mem_decim2_fx, relE, 0, st->bwidth, st->Opt_SC_VBR );
- st->old_pitch_la = st->pitch[2];
+ st->old_pitch_la = st->pitch[2]; /* Q0 */
move16();
- st->old_voicing_la = st->voicing_fx[2];
+ st->old_voicing_la = st->voicing_fx[2]; /* Q15 */
move16();
/* VAD parameters update */
@@ -495,16 +498,16 @@ void amr_wb_enc_fx(
CNG_reset_enc_fx( st, hLPDmem, pitch_buf, dummy_buf + L_FRAME, 0 );
/* update st->mem_syn1 for ACELP core switching */
- Copy( hLPDmem->mem_syn3, hLPDmem->mem_syn1_fx, M );
+ Copy( hLPDmem->mem_syn3, hLPDmem->mem_syn1_fx, M ); /* q_mem_syn */
/* update ACELP core synthesis filter memory */
- Copy( hLPDmem->mem_syn3, hLPDmem->mem_syn, M );
+ Copy( hLPDmem->mem_syn3, hLPDmem->mem_syn, M ); /* q_mem_syn */
/* update old synthesis buffer - needed for ACELP internal sampling rate switching */
- Copy( dummy_buf + L_FRAME - L_SYN_MEM, hLPDmem->mem_syn_r, L_SYN_MEM );
+ Copy( dummy_buf + L_FRAME - L_SYN_MEM, hLPDmem->mem_syn_r, L_SYN_MEM ); /* st->Q_syn */
/* Update MODE2 core switching memory */
E_UTIL_deemph2( sub( Q_new, 1 ), dummy_buf, PREEMPH_FAC, L_FRAME, &( hLPDmem->syn[M] ) );
- Copy( dummy_buf + L_FRAME - M - 1, hLPDmem->syn, M + 1 );
+ Copy( dummy_buf + L_FRAME - M - 1, hLPDmem->syn, M + 1 ); /* st->Q_syn */
}
/*----------------------------------------------------------------*
@@ -519,7 +522,7 @@ void amr_wb_enc_fx(
test();
IF( EQ_32( st->last_core_brate, FRAME_NO_DATA ) || EQ_32( st->last_core_brate, SID_1k75 ) )
{
- Copy( hDtxEnc->lspCNG_fx, st->lsp_old_fx, M );
+ Copy( hDtxEnc->lspCNG_fx, st->lsp_old_fx, M ); /* Q15 */
E_LPC_isp_isf_conversion( hDtxEnc->lspCNG_fx, st->lsf_old_fx, M );
set16_fx( old_exc, 0, L_EXC_MEM );
}
@@ -549,14 +552,14 @@ void amr_wb_enc_fx(
encod_amr_wb_fx( st, inp, Aw, Aq, res, syn, exc, exc2, pitch_buf, hf_gain_fx, inp_16k, shift, Q_new );
/* update st->mem_syn1 for ACELP core switching */
- Copy( hLPDmem->mem_syn, hLPDmem->mem_syn1_fx, M );
+ Copy( hLPDmem->mem_syn, hLPDmem->mem_syn1_fx, M ); /* st->q_mem_syn */
/* update old synthesis buffer - needed for ACELP internal sampling rate switching */
- Copy( syn + L_FRAME - L_SYN_MEM, hLPDmem->mem_syn_r, L_SYN_MEM );
+ Copy( syn + L_FRAME - L_SYN_MEM, hLPDmem->mem_syn_r, L_SYN_MEM ); /* st->Q_syn */
/* Update MODE2 core switching memory */
E_UTIL_deemph2( sub( Q_new, 1 ), syn, PREEMPH_FAC, L_FRAME, &( hLPDmem->syn[M] ) );
- Copy( syn + L_FRAME - M - 1, hLPDmem->syn, M + 1 );
+ Copy( syn + L_FRAME - M - 1, hLPDmem->syn, M + 1 ); /* st->Q_syn */
/*--------------------------------------------------------------------------------------*
* Write VAD information into the bitstream in AMR-WB IO mode
@@ -570,27 +573,27 @@ void amr_wb_enc_fx(
*-----------------------------------------------------------------*/
/* update old weighted speech buffer - for OL pitch analysis */
- Copy( &old_wsp[L_FRAME], st->old_wsp_fx, L_WSP_MEM );
+ Copy( &old_wsp[L_FRAME], st->old_wsp_fx, L_WSP_MEM ); /* exp(exp_old_wsp) */
/* update old input signal buffer */
- Copy( &old_inp[L_FRAME], st->old_inp_12k8_fx, L_INP_MEM );
+ Copy( &old_inp[L_FRAME], st->old_inp_12k8_fx, L_INP_MEM ); /* exp(exp_old_inp_12k8) */
/* update old input signal @16kHz buffer */
IF( GT_32( st->input_Fs, 8000 ) )
{
- Copy( &old_inp_16k[L_FRAME16k], st->old_inp_16k_fx, L_INP_MEM );
+ Copy( &old_inp_16k[L_FRAME16k], st->old_inp_16k_fx, L_INP_MEM ); /* exp(exp_old_inp_16k) */
}
/* update of old per-band energy spectrum */
- Copy32( fr_bands + NB_BANDS, hNoiseEst->enrO_fx, NB_BANDS );
+ Copy32( fr_bands + NB_BANDS, hNoiseEst->enrO_fx, NB_BANDS ); /* Q_new */
/* update the last bandwidth */
- st->last_input_bwidth = st->input_bwidth;
- st->last_bwidth = st->bwidth;
+ st->last_input_bwidth = st->input_bwidth; /* Q0 */
+ st->last_bwidth = st->bwidth; /* Q0 */
/* update signal buffers */
- Copy( new_inp, st->buf_speech_enc_pe + L_FRAME, L_FRAME );
- Copy( wsp, st->buf_wspeech_enc + L_FRAME + L_SUBFR, L_FRAME + L_LOOK_12k8 );
+ Copy( new_inp, st->buf_speech_enc_pe + L_FRAME, L_FRAME ); /* Q0 */
+ Copy( wsp, st->buf_wspeech_enc + L_FRAME + L_SUBFR, L_FRAME + L_LOOK_12k8 ); /* exp(exp_buf_wspeech_enc) */
updt_enc_fx( st, old_exc, pitch_buf, 0, Aq, isf_new, isp_new, dummy_buf );
/* update main codec parameters */
@@ -633,7 +636,7 @@ void amr_wb_enc_init_fx(
FOR( i = 0; i < GAIN_PRED_ORDER; i++ )
{
- hAmrwb_IO->past_qua_en_fx[i] = -14336; /* Q10gain quantization memory (used also in AMR-WB IO mode) */
+ hAmrwb_IO->past_qua_en_fx[i] = -14336; /* Q10 gain quantization memory (used also in AMR-WB IO mode) */
move16();
}
diff --git a/lib_enc/analy_lp.c b/lib_enc/analy_lp.c
deleted file mode 100644
index 2e657e155b94f2ee095cf1922c203d19c79fa7dc..0000000000000000000000000000000000000000
--- a/lib_enc/analy_lp.c
+++ /dev/null
@@ -1,54 +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 "rom_com.h"
-#include "prot.h"
-#include "wmc_auto.h"
-
-/*-------------------------------------------------------------------*
- * analy_lp()
- *
- * Perform LP analysis
- *
- * - autocorrelations + lag windowing
- * - Levinson-Durbin algorithm to find A(z)
- * - convert A(z) to LSPs
- * - find interpolated LSPs and convert back to A(z) for all subframes
- * - update LSPs for the next frame
- *-------------------------------------------------------------------*/
diff --git a/lib_enc/analy_lp_fx.c b/lib_enc/analy_lp_fx.c
index dc0e9c545f5edc38ce7b672e543496fa11f70e67..c2f9d0585d356c513226ee2059d219e835976724 100644
--- a/lib_enc/analy_lp_fx.c
+++ b/lib_enc/analy_lp_fx.c
@@ -63,7 +63,7 @@ void analy_lp_ivas_fx(
move16();
wind = assym_window_16k_fx; /*q15*/
}
- lsp = lsp_mid;
+ lsp = lsp_mid; /* Q15 */
half_frame = shr( L_frame, 1 );
FOR( i_subfr = 0; i_subfr <= 1; i_subfr++ )
@@ -105,7 +105,7 @@ void analy_lp_ivas_fx(
/* Conversion of A(z) to LSPs */
E_LPC_a_lsp_conversion( A, lsp, lsp_old, M );
- lsp = lsp_new;
+ lsp = lsp_new; /* Q15 */
}
IF( EQ_16( sec_chan_low_rate, 1 ) )
{
@@ -117,28 +117,28 @@ void analy_lp_ivas_fx(
/* LSP interpolation */
int_lsp4_ivas_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, 0 );
}
- Copy( lsp_new, lsp_old, M );
- *ener = L_Comp( epsP_h[M], epsP_l[M] );
+ Copy( lsp_new, lsp_old, M ); /* Q15 */
+ *ener = L_Comp( epsP_h[M], epsP_l[M] ); /* Q_r */
move32();
return;
}
void analy_lp_fx(
- const Word16 speech[], /* i : pointer to the speech frame */
- const Word16 L_frame, /* i : length of the frame */
- const Word16 L_look, /* i : look-ahead */
- Word32 *ener, /* o : residual energy from Levinson-Durbin */
- Word16 A[], /* o : A(z) filter coefficients */
- Word16 epsP_h[], /* o : LP analysis residual energies for each iteration */
- Word16 epsP_l[], /* o : LP analysis residual energies for each iteration */
- Word16 lsp_new[], /* o : current frame LSPs */
- Word16 lsp_mid[], /* o : current mid-frame LSPs */
- Word16 lsp_old[], /* i/o: previous frame unquantized LSPs */
- const Word16 Top[2], /* i : open loop pitch lag */
- const Word16 Tnc[2], /* i : open loop pitch gain */
- const Word32 Core_sr, /* i : Internal core sampling rate */
- const Word16 sec_chan_low_rate, /* i : flag to signal second channel */
+ const Word16 speech[], /* i : pointer to the speech frame Q_new*/
+ const Word16 L_frame, /* i : length of the frame Q0*/
+ const Word16 L_look, /* i : look-ahead Q0*/
+ Word32 *ener, /* o : residual energy from Levinson-Durbin Q_r*/
+ Word16 A[], /* o : A(z) filter coefficients Q14*/
+ Word16 epsP_h[], /* o : LP analysis residual energies for each iteration Q_r*/
+ Word16 epsP_l[], /* o : LP analysis residual energies for each iteration Q_r*/
+ Word16 lsp_new[], /* o : current frame LSPs Q15*/
+ Word16 lsp_mid[], /* o : current mid-frame LSPs Q15*/
+ Word16 lsp_old[], /* i/o: previous frame unquantized LSPs Q15*/
+ const Word16 Top[2], /* i : open loop pitch lag Q0*/
+ const Word16 Tnc[2], /* i : open loop pitch gain Q15*/
+ const Word32 Core_sr, /* i : Internal core sampling rate Q0*/
+ const Word16 sec_chan_low_rate, /* i : flag to signal second channel Q0*/
Word16 Q_new,
Word16 *Q_r )
{
@@ -155,15 +155,15 @@ void analy_lp_fx(
{
wind_length = L_LP;
move16();
- wind = Assym_window_W16fx;
+ wind = Assym_window_W16fx; /* Q15 */
}
ELSE /* L_frame == L_FRAME16k */
{
wind_length = L_LP_16k;
move16();
- wind = assym_window_16k_fx;
+ wind = assym_window_16k_fx; /* Q15 */
}
- lsp = lsp_mid;
+ lsp = lsp_mid; /* Q15 */
half_frame = shr( L_frame, 1 );
FOR( i_subfr = 0; i_subfr <= 1; i_subfr++ )
@@ -190,7 +190,7 @@ void analy_lp_fx(
/* Conversion of A(z) to LSPs */
E_LPC_a_lsp_conversion( A, lsp, lsp_old, M );
- lsp = lsp_new;
+ lsp = lsp_new; /* Q15 */
}
IF( EQ_16( sec_chan_low_rate, 1 ) )
{
@@ -202,8 +202,8 @@ void analy_lp_fx(
/* LSP interpolation */
int_lsp4_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, 0 );
}
- Copy( lsp_new, lsp_old, M );
- *ener = L_Comp( epsP_h[M], epsP_l[M] );
+ Copy( lsp_new, lsp_old, M ); /* Q15 */
+ *ener = L_Comp( epsP_h[M], epsP_l[M] ); /* Q_r */
move32();
return;
@@ -223,16 +223,16 @@ void analy_lp_fx(
*-------------------------------------------------------------------*/
void analy_lp_AMR_WB_fx(
- const Word16 speech[], /* i : pointer to the speech frame */
- Word32 *ener, /* o : residual energy from Levinson-Durbin */
- Word16 A[], /* o : A(z) filter coefficients */
- Word16 epsP_h[], /* o : LP analysis residual energies for each iteration */
- Word16 epsP_l[], /* o : LP analysis residual energies for each iteration */
- Word16 isp_new[], /* o : current frame ISPs */
- Word16 isp_old[], /* i/o: previous frame unquantized ISPs */
- Word16 isf_new[], /* o : current frame ISPs */
- Word16 Top, /* i : open loop pitch lag */
- Word16 Tnc, /* i : open loop pitch gain */
+ const Word16 speech[], /* i : pointer to the speech frame Q_new*/
+ Word32 *ener, /* o : residual energy from Levinson-Durbin Q_r*/
+ Word16 A[], /* o : A(z) filter coefficients Q14*/
+ Word16 epsP_h[], /* o : LP analysis residual energies for each iteration Q_r*/
+ Word16 epsP_l[], /* o : LP analysis residual energies for each iteration Q_r*/
+ Word16 isp_new[], /* o : current frame ISPs Q15*/
+ Word16 isp_old[], /* i/o: previous frame unquantized ISPs Q15*/
+ Word16 isf_new[], /* o : current frame ISPs Q15*/
+ Word16 Top, /* i : open loop pitch lag Q0*/
+ Word16 Tnc, /* i : open loop pitch gain Qx*/
Word16 Q_new,
Word16 *Q_r )
{
@@ -271,11 +271,11 @@ void analy_lp_AMR_WB_fx(
int_lsp_fx( L_FRAME, isp_old, isp_new, A, M, interpol_isp_amr_wb_fx, 1 );
/**ener = epsP[M];*/
- *ener = L_Comp( epsP_h[M], epsP_l[M] );
+ *ener = L_Comp( epsP_h[M], epsP_l[M] ); /* Q_r */
move32();
/* updates */
- Copy( isp_new, isp_old, M );
+ Copy( isp_new, isp_old, M ); /* Q15 */
return;
}
diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c
index 0bbd7b260ffd5d4c76c3ce49fa401d350d2bd869..d6d1967321bde39fba7352d54b01efd357fbae6f 100644
--- a/lib_enc/cod_tcx_fx.c
+++ b/lib_enc/cod_tcx_fx.c
@@ -3808,7 +3808,7 @@ void QuantizeTCXSpectrum_fx(
move16();
IF( st->element_mode > EVS_MONO )
{
- sqBits = RCcontextMapping_encode2_estimate_no_mem_s17_LCS( sqQ, L_spec, &lastnz, &nEncoded, sqTargetBits, &stop, 0, NULL );
+ sqBits = RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx( sqQ, L_spec, &lastnz, &nEncoded, sqTargetBits, &stop, 0, NULL );
}
ELSE
{
@@ -3822,7 +3822,7 @@ void QuantizeTCXSpectrum_fx(
/* Context Mapping */
IF( st->element_mode > EVS_MONO )
{
- sqBitsCtxHm = RCcontextMapping_encode2_estimate_no_mem_s17_LCS( sqQ, L_spec, &lastnzCtxHm, &nEncodedCtxHm, sqTargetBits - NumIndexBits, &stopCtxHm, 0, hm_cfg );
+ sqBitsCtxHm = RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx( sqQ, L_spec, &lastnzCtxHm, &nEncodedCtxHm, sqTargetBits - NumIndexBits, &stopCtxHm, 0, hm_cfg );
}
ELSE
{
@@ -3898,7 +3898,7 @@ void QuantizeTCXSpectrum_fx(
IF( st->element_mode > EVS_MONO )
{
- sqBits_noStop = sqBits = RCcontextMapping_encode2_estimate_no_mem_s17_LCS( sqQ, L_spec, prm_lastnz, &nEncoded, sqTargetBits, &stop, 0, NULL );
+ sqBits_noStop = sqBits = RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx( sqQ, L_spec, prm_lastnz, &nEncoded, sqTargetBits, &stop, 0, NULL );
move16();
}
ELSE
@@ -3987,7 +3987,7 @@ void QuantizeTCXSpectrum_fx(
IF( st->element_mode > EVS_MONO )
{
/* Fix: Use updated value for target bits (sqTargetBits + NumIndexBits) before computing non-mapped estimate */
- sqBitsCtxHm = RCcontextMapping_encode2_estimate_no_mem_s17_LCS( sqQ, L_spec, &lastnz, &nEncodedCtxHm, sqTargetBits + NumIndexBits, &stopCtxHm, 0, NULL );
+ sqBitsCtxHm = RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx( sqQ, L_spec, &lastnz, &nEncodedCtxHm, sqTargetBits + NumIndexBits, &stopCtxHm, 0, NULL );
}
ELSE
{
@@ -4062,7 +4062,7 @@ void QuantizeTCXSpectrum_fx(
move16();
IF( st->element_mode > EVS_MONO )
{
- sqBitsCtxHm = RCcontextMapping_encode2_estimate_no_mem_s17_LCS( sqQ, L_spec, &lastnzCtxHm, &nEncodedCtxHm, sqTargetBits - NumIndexBits, &stopCtxHm, 0, hm_cfg );
+ sqBitsCtxHm = RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx( sqQ, L_spec, &lastnzCtxHm, &nEncodedCtxHm, sqTargetBits - NumIndexBits, &stopCtxHm, 0, hm_cfg );
}
ELSE
{
@@ -4176,7 +4176,7 @@ void QuantizeTCXSpectrum_fx(
sqTargetBits = add( sqTargetBits, NumIndexBits );
ctxHmBits = sub( ctxHmBits, NumIndexBits );
}
- sqBits = RCcontextMapping_encode2_estimate_no_mem_s17_LCS( sqQ, L_spec, prm_lastnz, &nEncoded, sqTargetBits, &stop, 0, NULL );
+ sqBits = RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx( sqQ, L_spec, prm_lastnz, &nEncoded, sqTargetBits, &stop, 0, NULL );
}
ELSE
{
diff --git a/lib_enc/enc_nelp.c b/lib_enc/enc_nelp.c
deleted file mode 100644
index fd4f3cb7c53af6bc1a4a149c6db6799b8f39655e..0000000000000000000000000000000000000000
--- a/lib_enc/enc_nelp.c
+++ /dev/null
@@ -1,42 +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 "rom_com.h"
-#include "prot.h"
-#include "wmc_auto.h"
diff --git a/lib_enc/enc_nelp_fx.c b/lib_enc/enc_nelp_fx.c
index 004b43fd364f96b4fc9196af485e3aa38531e207..aedb1d2c2efda7795e84356d24d205564498b5e4 100644
--- a/lib_enc/enc_nelp_fx.c
+++ b/lib_enc/enc_nelp_fx.c
@@ -43,17 +43,17 @@
/*==============================================================================*/
void encod_nelp_fx(
Encoder_State *st_fx, /* i/o: state structure */
- const Word16 *speech_fx, /* i : input speech */
- const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */
- const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */
- Word16 *res_fx, /* o : residual signal */
- Word16 *synth_fx, /* o : core synthesis */
- Word16 *tmp_noise_fx, /* o : long-term noise energy */
- Word16 *exc_fx, /* i/o: current non-enhanced excitation */
- Word16 *exc2_fx, /* i/o: current enhanced excitation */
- Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */
- Word16 *voice_factors_fx, /* o : voicing factors */
- Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */
+ const Word16 *speech_fx, /* i : input speech Q_new-1*/
+ const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/
+ const Word16 Aq_fx[], /* i : 12k8 Lp coefficient Q12*/
+ Word16 *res_fx, /* o : residual signal Q_new*/
+ Word16 *synth_fx, /* o : core synthesis Q_new*/
+ Word16 *tmp_noise_fx, /* o : long-term noise energy Q0*/
+ Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/
+ Word16 *exc2_fx, /* i/o: current enhanced excitation Q_new*/
+ Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/
+ Word16 *voice_factors_fx, /* o : voicing factors Q15*/
+ Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_new*/
Word16 Q_new,
Word16 shift
@@ -69,6 +69,7 @@ void encod_nelp_fx(
Word16 saved_Q_new = Q_new;
Word16 reduce_gains = 0;
+ move16();
LPD_state_HANDLE hLPDmem = st_fx->hLPDmem;
SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR;
@@ -95,13 +96,13 @@ void encod_nelp_fx(
* target in residual domain "cn"
* - Compute impulse response, h1[], of weighted synthesis filter
*----------------------------------------------------------------*/
- Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR );
+ Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); /* Q_new */
find_targets_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx,
res_fx, L_SUBFR, p_Aw_fx, TILT_FAC_FX, xn_fx, NULL, h1_fx );
/* scale xn[] and h1[] to avoid overflow in dot_product12() */
- Scale_sig( xn_fx, L_SUBFR, shift ); /* scaling of xn[] to limit dynamic at 12 bits */
+ Scale_sig( xn_fx, L_SUBFR, shift ); /* scaling of xn[] to limit dynamic at 12 bits Q_new -1 + shift */
IF( i_subfr == 0 )
{
@@ -109,11 +110,12 @@ void encod_nelp_fx(
IF( EQ_16( hSC_VBR->Local_VAD, 1 ) && EQ_16( st_fx->bwidth, NB ) )
{
reduce_gains = 1;
+ move16();
}
nelp_encoder_fx( st_fx, res_fx, exc_nelp_fx, &Q_new, reduce_gains );
- Scale_sig( exc_nelp_fx, L_FRAME, ( saved_Q_new - Q_new ) );
+ Scale_sig( exc_nelp_fx, L_FRAME, ( saved_Q_new - Q_new ) ); /* saved_Q_new*/
}
@@ -137,7 +139,7 @@ void encod_nelp_fx(
move16();
}
- Copy( exc_nelp_fx, exc_fx, L_FRAME );
+ Copy( exc_nelp_fx, exc_fx, L_FRAME ); /* Q_new */
/*-----------------------------------------------------------------*
* Updates: last value of new target is stored in mem_w0
@@ -150,23 +152,23 @@ void encod_nelp_fx(
#endif
move16(); /*Q_new-1 */
hLPDmem->tilt_code = 0;
- move16(); /* purely unvoiced */
- hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code;
+ move16(); /* purely unvoiced */
+ hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; /* Q15 */
move16();
- Copy( exc_fx, exc2_fx, L_FRAME );
+ Copy( exc_fx, exc2_fx, L_FRAME ); /* Q_new */
hSC_VBR->prev_ppp_gain_pit_fx = 0;
move16();
hLPDmem->dm_fx.prev_state = 0;
move16();
- hLPDmem->dm_fx.prev_gain_pit[0] = hSC_VBR->prev_ppp_gain_pit_fx;
+ hLPDmem->dm_fx.prev_gain_pit[0] = hSC_VBR->prev_ppp_gain_pit_fx; /* Q14 */
move16();
FOR( j = 1; j < 5; j++ )
{
- hLPDmem->dm_fx.prev_gain_pit[j] = hLPDmem->dm_fx.prev_gain_pit[j - 1];
+ hLPDmem->dm_fx.prev_gain_pit[j] = hLPDmem->dm_fx.prev_gain_pit[j - 1]; /* Q14 */
move16();
}
interp_code_5over2_fx( exc2_fx, bwe_exc_fx, L_FRAME );
@@ -224,7 +226,7 @@ void encod_nelp_ivas_fx(
{
set16_fx( hSC_VBR->nelp_lp_fit_mem, 0, NELP_LP_ORDER * 2 );
}
- Scale_sig( hSC_VBR->nelp_lp_fit_mem, NELP_LP_ORDER * 2, sub( Q_new, st_fx->prev_Q_new ) );
+ Scale_sig( hSC_VBR->nelp_lp_fit_mem, NELP_LP_ORDER * 2, sub( Q_new, st_fx->prev_Q_new ) ); /* Q_new */
pz_filter_sp_fx( num_nelp_lp_fx, den_nelp_lp_fx, res_fx, res_fx, hSC_VBR->nelp_lp_fit_mem, NELP_LP_ORDER, NELP_LP_ORDER, L_FRAME, 3 ); /*16-Q of filter coeff*/
}
@@ -241,13 +243,13 @@ void encod_nelp_ivas_fx(
* target in residual domain "cn"
* - Compute impulse response, h1[], of weighted synthesis filter
*----------------------------------------------------------------*/
- Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR );
+ Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); /* Q_new */
find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx,
res_fx, L_SUBFR, p_Aw_fx, TILT_FAC_FX, xn_fx, NULL, h1_fx );
/* scale xn[] and h1[] to avoid overflow in dot_product12() */
- Scale_sig( xn_fx, L_SUBFR, shift ); /* scaling of xn[] to limit dynamic at 12 bits */
+ Scale_sig( xn_fx, L_SUBFR, shift ); /* scaling of xn[] to limit dynamic at 12 bits Q_new-1+shift */
IF( i_subfr == 0 )
{
@@ -260,7 +262,7 @@ void encod_nelp_ivas_fx(
nelp_encoder_ivas_fx( st_fx, res_fx, exc_nelp_fx, &Q_new, reduce_gains );
- Scale_sig( exc_nelp_fx, L_FRAME, ( saved_Q_new - Q_new ) );
+ Scale_sig( exc_nelp_fx, L_FRAME, ( saved_Q_new - Q_new ) ); /* saved_Q_new */
}
@@ -275,13 +277,13 @@ void encod_nelp_ivas_fx(
p_Aw_fx += ( M + 1 );
p_Aq_fx += ( M + 1 );
- *pitch_buf_fx = L_SUBFR_Q6;
+ *pitch_buf_fx = L_SUBFR_Q6; /* Q6 */
move16();
pitch_buf_fx++;
}
- Copy( exc_nelp_fx, exc_fx, L_FRAME );
+ Copy( exc_nelp_fx, exc_fx, L_FRAME ); /* Q_new */
/*-----------------------------------------------------------------*
* Updates: last value of new target is stored in mem_w0
@@ -298,19 +300,19 @@ void encod_nelp_ivas_fx(
hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code;
move16();
- Copy( exc_fx, exc2_fx, L_FRAME );
+ Copy( exc_fx, exc2_fx, L_FRAME ); /* Q_new */
hSC_VBR->prev_ppp_gain_pit_fx = 0;
move16();
hLPDmem->dm_fx.prev_state = 0;
move16();
- hLPDmem->dm_fx.prev_gain_pit[0] = hSC_VBR->prev_ppp_gain_pit_fx;
+ hLPDmem->dm_fx.prev_gain_pit[0] = hSC_VBR->prev_ppp_gain_pit_fx; /* Q14 */
move16();
FOR( j = 1; j < 5; j++ )
{
- hLPDmem->dm_fx.prev_gain_pit[j] = hLPDmem->dm_fx.prev_gain_pit[j - 1];
+ hLPDmem->dm_fx.prev_gain_pit[j] = hLPDmem->dm_fx.prev_gain_pit[j - 1]; /* Q14 */
move16();
}
interp_code_5over2_fx( exc2_fx, bwe_exc_fx, L_FRAME );
diff --git a/lib_enc/enc_pit_exc.c b/lib_enc/enc_pit_exc.c
deleted file mode 100644
index fd4f3cb7c53af6bc1a4a149c6db6799b8f39655e..0000000000000000000000000000000000000000
--- a/lib_enc/enc_pit_exc.c
+++ /dev/null
@@ -1,42 +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 "rom_com.h"
-#include "prot.h"
-#include "wmc_auto.h"
diff --git a/lib_enc/enc_pit_exc_fx.c b/lib_enc/enc_pit_exc_fx.c
index 9d75c82fc02612c1fc6cc3bb568490affa0826d4..54674da1e884ace3f39577d89a47d6c2a62cb795 100644
--- a/lib_enc/enc_pit_exc_fx.c
+++ b/lib_enc/enc_pit_exc_fx.c
@@ -48,21 +48,21 @@
/*=======================================================================*/
void enc_pit_exc_fx(
Encoder_State *st_fx, /* i/o: State structure */
- const Word16 *speech, /* i : Input speech */
- const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */
- const Word16 Aq[], /* i : 12k8 Lp coefficient */
- const Word16 Es_pred, /* i : predicted scaled innov. energy */
- const Word16 *res, /* i : residual signal */
- Word16 *synth, /* i/o: core synthesis */
- Word16 *exc, /* i/o: current non-enhanced excitation */
- Word16 *T0, /* i/o: close loop integer pitch */
- Word16 *T0_frac, /* i/o: close-loop pitch period - fractional part */
- Word16 *pitch_buf, /* i/o: Fractionnal per subframe pitch */
- const Word16 nb_subfr, /* i : Number of subframe considered */
- Word16 *gpit, /* o : pitch mean gpit */
- Word16 *saved_bit_pos, /* o : saved position in the bitstream before pitch contribution */
- const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
- const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */
+ const Word16 *speech, /* i : Input speech Q_new-1*/
+ const Word16 Aw[], /* i : weighted A(z) unquantized for subframes Q12*/
+ const Word16 Aq[], /* i : 12k8 Lp coefficient Q12*/
+ const Word16 Es_pred, /* i : predicted scaled innov. energy Q8*/
+ const Word16 *res, /* i : residual signal Q_new*/
+ Word16 *synth, /* i/o: core synthesis Q_new*/
+ Word16 *exc, /* i/o: current non-enhanced excitation Q_new*/
+ Word16 *T0, /* i/o: close loop integer pitch Q0*/
+ Word16 *T0_frac, /* i/o: close-loop pitch period - fractional part Q0*/
+ Word16 *pitch_buf, /* i/o: Fractionnal per subframe pitch Q6*/
+ const Word16 nb_subfr, /* i : Number of subframe considered Q0*/
+ Word16 *gpit, /* o : pitch mean gpit Q15*/
+ Word16 *saved_bit_pos, /* o : saved position in the bitstream before pitch contribution Q0*/
+ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/
+ const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer Q6*/
Word16 Q_new,
Word16 shift )
{
@@ -87,6 +87,7 @@ void enc_pit_exc_fx(
Word16 cum_gpit, gpit_tmp;
Word32 Local_BR, Pitch_BR;
Word16 Pitch_CT, unbits_PI = 0; /* saved bits for PI */
+ move16();
Word32 norm_gain_code;
Word16 pitch_limit_flag;
Word16 h2[PIT_EXC_L_SUBFR + ( M + 1 )]; /* Impulse response vector */
@@ -104,6 +105,7 @@ void enc_pit_exc_fx(
LPD_state_HANDLE hLPDmem = st_fx->hLPDmem;
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
+ move32();
#endif
/*------------------------------------------------------------------*
@@ -114,11 +116,13 @@ void enc_pit_exc_fx(
move16(); /* always extended pitch Q range */
use_fcb = 0;
unbits_PI = 0;
- test();
- test();
+ move16();
+ move16();
Pitch_CT = GENERIC;
move16();
+ test();
+ test();
IF( st_fx->GSC_IVAS_mode > 0 && ( st_fx->GSC_noisy_speech || GT_32( st_fx->core_brate, GSC_H_RATE_STG ) ) )
{
Local_BR = ACELP_8k00;
@@ -134,7 +138,7 @@ void enc_pit_exc_fx(
Local_BR = ACELP_9k60;
move32();
}
- Pitch_BR = st_fx->core_brate;
+ Pitch_BR = st_fx->core_brate; /* Q0 */
move32();
}
}
@@ -148,7 +152,7 @@ void enc_pit_exc_fx(
move16();
if ( EQ_16( st_fx->L_frame, L_FRAME16k ) )
{
- Pitch_BR = st_fx->core_brate;
+ Pitch_BR = st_fx->core_brate; /* Q0 */
move32();
}
}
@@ -157,12 +161,12 @@ void enc_pit_exc_fx(
Local_BR = ACELP_7k20;
move32();
- Pitch_BR = st_fx->core_brate;
+ Pitch_BR = st_fx->core_brate; /* Q0 */
move32();
Pitch_CT = AUDIO;
move16();
- if ( EQ_16( st_fx->L_frame, L_FRAME16k ) )
+ IF( EQ_16( st_fx->L_frame, L_FRAME16k ) )
{
Local_BR = ACELP_13k20;
move32();
@@ -188,9 +192,9 @@ void enc_pit_exc_fx(
cum_gpit = 0;
move16();
- L_subfr = mult_r( st_fx->L_frame, div_s( 1, nb_subfr ) );
+ L_subfr = mult_r( st_fx->L_frame, div_s( 1, nb_subfr ) ); /* Q0 */
- lp_flag = st_fx->acelp_cfg.ltf_mode;
+ lp_flag = st_fx->acelp_cfg.ltf_mode; /* Q0 */
test();
test();
@@ -245,27 +249,27 @@ void enc_pit_exc_fx(
* target in residual domain "cn"
* Compute impulse response, h1[], of weighted synthesis filter
*----------------------------------------------------------------*/
- Copy( &res[i_subfr], &exc[i_subfr], L_subfr );
- /* condition on target (compared to float) has been put outside the loop */
-#if 1 // ndef BUG_FIX
+ Copy( &res[i_subfr], &exc[i_subfr], L_subfr ); /* Q_new */
+ /* condition on target (compared to float) has been put outside the loop */
+#if 1 // ndef BUG_FIX
find_targets_fx( speech, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq,
res, L_subfr, p_Aw, st_fx->preemph_fac, xn, cn, h1 );
#else
find_targets_fx( speech, hGSCEnc->mem_syn_tmp_fx, i_subfr, &hLPDmem->mem_w0, p_Aq, /*_DIFF_FLOAT_FIX_ --> Here I think mem_syn_tmp_fx should be used */
res, L_subfr, p_Aw, st_fx->preemph_fac, xn, cn, h1 );
#endif
- Copy_Scale_sig( h1, h2, L_subfr, -2 );
+ Copy_Scale_sig( h1, h2, L_subfr, -2 ); /* Q13 */
Scale_sig( h1, L_subfr, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */
/* scaling of xn[] to limit dynamic at 12 bits */
- Scale_sig( xn, L_subfr, shift );
+ Scale_sig( xn, L_subfr, shift ); /* Q_new - 1 + shift */
/*----------------------------------------------------------------*
* Close-loop pitch search and quantization
* Adaptive exc. construction
*----------------------------------------------------------------*/
*pt_pitch = pit_encode_fx( hBstr, st_fx->acelp_cfg.pitch_bits, Pitch_BR, 0, st_fx->L_frame, Pitch_CT, &pitch_limit_flag, i_subfr, exc,
- L_subfr, st_fx->pitch, &T0_min, &T0_max, T0, T0_frac, h1, xn, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf );
+ L_subfr, st_fx->pitch, &T0_min, &T0_max, T0, T0_frac, h1, xn, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); /* Q6 */
/*-----------------------------------------------------------------*
* Find adaptive exitation
*-----------------------------------------------------------------*/
@@ -276,7 +280,7 @@ void enc_pit_exc_fx(
* or in case of floating point encoder & fixed p. decoder
*-----------------------------------------------------------------*/
- clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, AUDIO, xn, st_fx->clip_var_fx, sub( shift_wsp, 1 ) );
+ clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, AUDIO, xn, st_fx->clip_var_fx, sub( shift_wsp, 1 ) ); /* Q0 */
/*-----------------------------------------------------------------*
* Codebook target computation
@@ -284,7 +288,7 @@ void enc_pit_exc_fx(
*-----------------------------------------------------------------*/
lp_select = lp_filt_exc_enc_fx( MODE1, AUDIO, i_subfr, exc, h1,
- xn, y1, xn2, L_subfr, st_fx->L_frame, g_corr, clip_gain, &gain_pit, &lp_flag );
+ xn, y1, xn2, L_subfr, st_fx->L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); /* Q0 */
IF( EQ_16( lp_flag, NORMAL_OPERATION ) )
{
@@ -312,12 +316,12 @@ void enc_pit_exc_fx(
{
IF( GE_32( st_fx->core_brate, MIN_RATE_FCB ) )
{
- pit_idx = vquant_fx( &gain_pit, mean_gp_fx, &gain_pit, dic_gp_fx, 1, 32 );
+ pit_idx = vquant_fx( &gain_pit, mean_gp_fx, &gain_pit, dic_gp_fx, 1, 32 ); /* Q0 */
push_indice_fx( hBstr, IND_PIT_IDX, pit_idx, 5 );
}
ELSE
{
- pit_idx = vquant_fx( &gain_pit, mean_gp_fx, &gain_pit, dic_gp_fx, 1, 16 );
+ pit_idx = vquant_fx( &gain_pit, mean_gp_fx, &gain_pit, dic_gp_fx, 1, 16 ); /* Q0 */
push_indice_fx( hBstr, IND_PIT_IDX, pit_idx, 4 );
}
}
@@ -361,7 +365,7 @@ void enc_pit_exc_fx(
#endif
IF( use_fcb != 0 )
{
- hLPDmem->tilt_code = Est_tilt2( &exc[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift );
+ hLPDmem->tilt_code = Est_tilt2( &exc[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift ); /* Q15 */
move16();
}
ELSE
@@ -374,14 +378,15 @@ void enc_pit_exc_fx(
*-----------------------------------------------------------------*/
IF( use_fcb != 0 )
{
- Ltmp = L_mult( gcode16, y2[L_subfr - 1] );
+ Ltmp = L_mult( gcode16, y2[L_subfr - 1] ); /* Q10 + Q_new */
#ifdef BASOP_NOGLOB
- Ltmp = L_shl_o( Ltmp, add( 5, shift ), &Overflow );
+ Ltmp = L_shl_o( Ltmp, add( 5, shift ), &Overflow ); /* Q15 + Q_new + shift */
Ltmp = L_negate( Ltmp );
- Ltmp = L_mac_o( Ltmp, xn[L_subfr - 1], 16384, &Overflow );
- Ltmp = L_msu_o( Ltmp, y1[L_subfr - 1], gain_pit, &Overflow );
- Ltmp = L_shl_o( Ltmp, sub( 1, shift ), &Overflow );
- hLPDmem->mem_w0 = round_fx_o( Ltmp, &Overflow ); /*Q_new-1 */
+ Ltmp = L_mac_o( Ltmp, xn[L_subfr - 1], 16384, &Overflow ); /* Q_new + Q15 + shift */
+ Ltmp = L_msu_o( Ltmp, y1[L_subfr - 1], gain_pit, &Overflow ); /* Q_new + Q15 + shift */
+ Ltmp = L_shl_o( Ltmp, sub( 1, shift ), &Overflow ); /* Q_new + 15 */
+ hLPDmem->mem_w0 = round_fx_o( Ltmp, &Overflow ); /*Q_new-1 */
+ move16();
#else
Ltmp = L_mult( gcode16, y2[L_subfr - 1] );
Ltmp = L_shl( Ltmp, add( 5, shift ) );
@@ -394,11 +399,12 @@ void enc_pit_exc_fx(
}
ELSE
{
- Ltmp = L_mult( xn[L_subfr - 1], 16384 );
+ Ltmp = L_mult( xn[L_subfr - 1], 16384 ); /* Q_new + 14 -shift */
#ifdef BASOP_NOGLOB
- Ltmp = L_msu_sat( Ltmp, y1[L_subfr - 1], gain_pit );
- Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) );
- hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */
+ Ltmp = L_msu_sat( Ltmp, y1[L_subfr - 1], gain_pit ); /* Q_new + 14 -shift */
+ Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); /* Q_new + 15 */
+ hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */
+ move16();
#else
Ltmp = L_msu( Ltmp, y1[L_subfr - 1], gain_pit );
Ltmp = L_shl( Ltmp, sub( 1, shift ) );
@@ -415,12 +421,13 @@ void enc_pit_exc_fx(
FOR( i = 0; i < L_subfr; i++ )
{
/* code in Q9, gain_pit in Q14 */
- Ltmp = L_mult( gcode16, code[i] );
+ Ltmp = L_mult( gcode16, code[i] ); /* Q10 + Q_new */
#ifdef BASOP_NOGLOB
- Ltmp = L_shl_o( Ltmp, 5, &Overflow );
- Ltmp = L_mac_o( Ltmp, exc[i + i_subfr], gain_pit, &Overflow );
- Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here */
- exc[i + i_subfr] = round_fx_o( Ltmp, &Overflow );
+ Ltmp = L_shl_o( Ltmp, 5, &Overflow ); /* Q15 + Q_new */
+ Ltmp = L_mac_o( Ltmp, exc[i + i_subfr], gain_pit, &Overflow ); /* Q15 + Q_new */
+ Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here Q_new + Q16*/
+ exc[i + i_subfr] = round_fx_o( Ltmp, &Overflow ); /* Q_new */
+ move16();
#else
Ltmp = L_mult( gcode16, code[i] );
Ltmp = L_shl( Ltmp, 5 );
@@ -435,10 +442,10 @@ void enc_pit_exc_fx(
FOR( i = 0; i < L_subfr; i++ )
{
- Ltmp = L_mult( exc[i + i_subfr], gain_pit );
+ Ltmp = L_mult( exc[i + i_subfr], gain_pit ); /* Q15 + Q_new */
#ifdef BASOP_NOGLOB
- Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here */
- exc[i + i_subfr] = round_fx_sat( Ltmp );
+ Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here Q16 + Q_new */
+ exc[i + i_subfr] = round_fx_sat( Ltmp ); /* Q_new */
#else
Ltmp = L_shl( Ltmp, 1 ); /* saturation can occur here */
exc[i + i_subfr] = round_fx( Ltmp );
@@ -455,7 +462,7 @@ void enc_pit_exc_fx(
IF( EQ_16( L_subfr, 5 * L_SUBFR ) )
{
- cum_gpit = gpit_tmp;
+ cum_gpit = gpit_tmp; /* Q14 */
move16();
pt_pitch++;
*pt_pitch = *( pt_pitch - 1 );
@@ -478,7 +485,7 @@ void enc_pit_exc_fx(
{
IF( i_subfr == 0 )
{
- cum_gpit = mult_r( gpit_tmp, 13107 ); /* .4f*/
+ cum_gpit = mult_r( gpit_tmp, 13107 /* .4f in Q15 */ ); /* Q14 */
pt_pitch++;
*pt_pitch = *( pt_pitch - 1 );
move16();
@@ -488,7 +495,7 @@ void enc_pit_exc_fx(
}
ELSE
{
- cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 19660 ) ); /*0.6*/
+ cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 19660 /* 0.6 in Q15 */ ) ); /* Q14 */
pt_pitch++;
*pt_pitch = *( pt_pitch - 1 );
move16();
@@ -504,11 +511,11 @@ void enc_pit_exc_fx(
{
IF( i_subfr == 0 )
{
- cum_gpit = mult_r( gpit_tmp, 16384 );
+ cum_gpit = mult_r( gpit_tmp, 16384 /* 0.5 in Q15 */ ); /* Q14 */
}
ELSE
{
- cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 16384 ) );
+ cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 16384 /* 0.5 in Q15 */ ) ); /* Q14 */
}
p_Aw += 2 * ( M + 1 );
move16();
@@ -521,7 +528,7 @@ void enc_pit_exc_fx(
}
ELSE IF( EQ_16( L_subfr, 4 * L_SUBFR ) )
{
- cum_gpit = gpit_tmp;
+ cum_gpit = gpit_tmp; /* Q14 */
move16();
pt_pitch++;
@@ -541,11 +548,11 @@ void enc_pit_exc_fx(
IF( i_subfr == 0 )
{
- cum_gpit = mult_r( gpit_tmp, 8192 );
+ cum_gpit = mult_r( gpit_tmp, 8192 /* 0.25 in Q15 */ ); /* Q14 */
}
ELSE
{
- cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 8192 ) );
+ cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 8192 /* 0.25 in Q15 */ ) ); /* Q14 */
}
pt_pitch++;
@@ -564,21 +571,21 @@ void enc_pit_exc_fx(
void enc_pit_exc_ivas_fx(
Encoder_State *st_fx, /* i/o: State structure */
- const Word16 *speech, /* i : Input speech */
- const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */
- const Word16 Aq[], /* i : 12k8 Lp coefficient */
- const Word16 Es_pred, /* i : predicted scaled innov. energy */
- const Word16 *res, /* i : residual signal */
- Word16 *synth, /* i/o: core synthesis */
- Word16 *exc, /* i/o: current non-enhanced excitation */
- Word16 *T0, /* i/o: close loop integer pitch */
- Word16 *T0_frac, /* i/o: close-loop pitch period - fractional part */
- Word16 *pitch_buf, /* i/o: Fractionnal per subframe pitch */
- const Word16 nb_subfr, /* i : Number of subframe considered */
- Word16 *gpit, /* o : pitch mean gpit */
- Word16 *saved_bit_pos, /* o : saved position in the bitstream before pitch contribution */
- const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
- const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */
+ const Word16 *speech, /* i : Input speech Q_new-1*/
+ const Word16 Aw[], /* i : weighted A(z) unquantized for subframes Q12*/
+ const Word16 Aq[], /* i : 12k8 Lp coefficient Q12*/
+ const Word16 Es_pred, /* i : predicted scaled innov. energy Q8*/
+ const Word16 *res, /* i : residual signal Q_new*/
+ Word16 *synth, /* i/o: core synthesis Q_new*/
+ Word16 *exc, /* i/o: current non-enhanced excitation Q_new*/
+ Word16 *T0, /* i/o: close loop integer pitch Q0*/
+ Word16 *T0_frac, /* i/o: close-loop pitch period - fractional part Q0*/
+ Word16 *pitch_buf, /* i/o: Fractionnal per subframe pitch Q6*/
+ const Word16 nb_subfr, /* i : Number of subframe considered Q0*/
+ Word16 *gpit, /* o : pitch mean gpit Q15*/
+ Word16 *saved_bit_pos, /* o : saved position in the bitstream before pitch contribution Q0*/
+ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/
+ const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer Q6*/
Word16 Q_new,
Word16 shift )
{
@@ -620,6 +627,7 @@ void enc_pit_exc_ivas_fx(
LPD_state_HANDLE hLPDmem = st_fx->hLPDmem;
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
+ move32();
#endif
/*------------------------------------------------------------------*
@@ -630,13 +638,15 @@ void enc_pit_exc_ivas_fx(
move16(); /* always extended pitch Q range */
use_fcb = 0;
unbits_PI = 0;
- test();
- test();
+ move16();
+ move16();
Pitch_CT = GENERIC;
move16();
#ifdef MSAN_FIX
set16_fx( cn1, 0, PIT_EXC_L_SUBFR );
#endif
+ test();
+ test();
IF( st_fx->GSC_IVAS_mode > 0 && ( st_fx->GSC_noisy_speech || GT_32( st_fx->core_brate, GSC_H_RATE_STG ) ) )
{
Local_BR = ACELP_8k00;
@@ -706,9 +716,10 @@ void enc_pit_exc_ivas_fx(
cum_gpit = 0;
move16();
- L_subfr = mult_r( st_fx->L_frame, div_s( 1, nb_subfr ) );
+ L_subfr = mult_r( st_fx->L_frame, div_s( 1, nb_subfr ) ); /* Q0 */
lp_flag = st_fx->acelp_cfg.ltf_mode;
+ move16();
test();
test();
@@ -737,13 +748,14 @@ void enc_pit_exc_ivas_fx(
set16_fx( st_fx->acelp_cfg.fixed_cdk_index, 14, NB_SUBFR16k );
}
- *saved_bit_pos = st_fx->next_bit_pos_fx;
+ *saved_bit_pos = st_fx->next_bit_pos_fx; /* Q0 */
move16();
/*------------------------------------------------------------------*
* ACELP subframe loop
*------------------------------------------------------------------*/
cn = NULL;
+ test();
if ( EQ_16( L_subfr, L_SUBFR ) || EQ_16( L_subfr, L_SUBFR * 2 ) )
{
cn = cn1;
@@ -763,24 +775,25 @@ void enc_pit_exc_ivas_fx(
* target in residual domain "cn"
* Compute impulse response, h1[], of weighted synthesis filter
*----------------------------------------------------------------*/
- Copy( &res[i_subfr], &exc[i_subfr], L_subfr );
+ Copy( &res[i_subfr], &exc[i_subfr], L_subfr ); /* Q_new */
/* condition on target (compared to float) has been put outside the loop */
find_targets_ivas_fx( speech, hGSCEnc->mem_syn_tmp_fx, i_subfr, &hGSCEnc->mem_w0_tmp_fx, p_Aq,
res, L_subfr, p_Aw, st_fx->preemph_fac, xn, cn, h1 );
- Copy_Scale_sig( h1, h2, L_subfr, -2 );
+ Copy_Scale_sig( h1, h2, L_subfr, -2 ); /* Q13 */
Scale_sig( h1, L_subfr, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */
/* scaling of xn[] to limit dynamic at 12 bits */
- Scale_sig( xn, L_subfr, shift );
+ Scale_sig( xn, L_subfr, shift ); /* Q_new - 1 + shift */
/*----------------------------------------------------------------*
* Close-loop pitch search and quantization
* Adaptive exc. construction
*----------------------------------------------------------------*/
*pt_pitch = pit_encode_ivas_fx( hBstr, st_fx->acelp_cfg.pitch_bits, Pitch_BR, 0, st_fx->L_frame, Pitch_CT, &pitch_limit_flag, i_subfr, exc,
- L_subfr, st_fx->pitch, &T0_min, &T0_max, T0, T0_frac, h1, xn, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf );
+ L_subfr, st_fx->pitch, &T0_min, &T0_max, T0, T0_frac, h1, xn, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); /* Q6 */
+ move16();
/*-----------------------------------------------------------------*
* Find adaptive exitation
*-----------------------------------------------------------------*/
@@ -791,7 +804,7 @@ void enc_pit_exc_ivas_fx(
* or in case of floating point encoder & fixed p. decoder
*-----------------------------------------------------------------*/
- clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, AUDIO, xn, st_fx->clip_var_fx, sub( shift_wsp, 1 ) );
+ clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, AUDIO, xn, st_fx->clip_var_fx, sub( shift_wsp, 1 ) ); /* Q0 */
/*-----------------------------------------------------------------*
* Codebook target computation
@@ -799,7 +812,7 @@ void enc_pit_exc_ivas_fx(
*-----------------------------------------------------------------*/
lp_select = lp_filt_exc_enc_ivas_fx( MODE1, AUDIO, i_subfr, exc, h1,
- xn, y1, xn2, L_subfr, st_fx->L_frame, g_corr, clip_gain, &gain_pit, &lp_flag );
+ xn, y1, xn2, L_subfr, st_fx->L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); /* Q0 */
IF( EQ_16( lp_flag, NORMAL_OPERATION ) )
{
@@ -877,7 +890,7 @@ void enc_pit_exc_ivas_fx(
#endif
IF( use_fcb != 0 )
{
- hLPDmem->tilt_code = est_tilt_ivas_fx( &exc[i_subfr], gain_pit, code, gain_code, &voice_fac, Q_new, L_SUBFR, 0 );
+ hLPDmem->tilt_code = est_tilt_ivas_fx( &exc[i_subfr], gain_pit, code, gain_code, &voice_fac, Q_new, L_SUBFR, 0 ); // Q15
move16();
}
ELSE
@@ -931,12 +944,13 @@ void enc_pit_exc_ivas_fx(
FOR( i = 0; i < L_subfr; i++ )
{
/* code in Q9, gain_pit in Q14 */
- Ltmp = L_mult( gcode16, code[i] );
+ Ltmp = L_mult( gcode16, code[i] ); /* Q10 + Q_new */
#ifdef BASOP_NOGLOB
- Ltmp = L_shl_o( Ltmp, 5, &Overflow );
- Ltmp = L_mac_o( Ltmp, exc[i + i_subfr], gain_pit, &Overflow );
- Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here */
- exc[i + i_subfr] = round_fx_o( Ltmp, &Overflow );
+ Ltmp = L_shl_o( Ltmp, 5, &Overflow ); /* Q15 + Q_new */
+ Ltmp = L_mac_o( Ltmp, exc[i + i_subfr], gain_pit, &Overflow ); /* Q15 + Q_new */
+ Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here Q16 + Q_new */
+ exc[i + i_subfr] = round_fx_o( Ltmp, &Overflow ); /* Q_new */
+ move16();
#else
Ltmp = L_mult( gcode16, code[i] );
Ltmp = L_shl( Ltmp, 5 );
@@ -951,10 +965,11 @@ void enc_pit_exc_ivas_fx(
FOR( i = 0; i < L_subfr; i++ )
{
- Ltmp = L_mult( exc[i + i_subfr], gain_pit );
+ Ltmp = L_mult( exc[i + i_subfr], gain_pit ); /* Q15 + Q_new */
#ifdef BASOP_NOGLOB
- Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here */
- exc[i + i_subfr] = round_fx_sat( Ltmp );
+ Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here Q16 + Q_new */
+ exc[i + i_subfr] = round_fx_sat( Ltmp ); /* Q_new */
+ move16();
#else
Ltmp = L_shl( Ltmp, 1 ); /* saturation can occur here */
exc[i + i_subfr] = round_fx( Ltmp );
@@ -994,7 +1009,7 @@ void enc_pit_exc_ivas_fx(
{
IF( i_subfr == 0 )
{
- cum_gpit = mult_r( gpit_tmp, 13107 ); /* .4f*/
+ cum_gpit = mult_r( gpit_tmp, 13107 /* .4f in Q15 */ ); /* Q14 */
pt_pitch++;
*pt_pitch = *( pt_pitch - 1 );
move16();
@@ -1004,7 +1019,7 @@ void enc_pit_exc_ivas_fx(
}
ELSE
{
- cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 19660 ) ); /*0.6*/
+ cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 19660 /* 0.6 in Q15 */ ) ); /* Q14 */
pt_pitch++;
*pt_pitch = *( pt_pitch - 1 );
move16();
@@ -1020,11 +1035,11 @@ void enc_pit_exc_ivas_fx(
{
IF( i_subfr == 0 )
{
- cum_gpit = mult_r( gpit_tmp, 16384 );
+ cum_gpit = mult_r( gpit_tmp, 16384 /* 0.5 in Q15 */ ); /* Q14 */
}
ELSE
{
- cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 16384 ) );
+ cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 16384 /* 0.5 in Q15 */ ) ); /* Q14 */
}
p_Aw += 2 * ( M + 1 );
move16();
@@ -1057,11 +1072,11 @@ void enc_pit_exc_ivas_fx(
IF( i_subfr == 0 )
{
- cum_gpit = mult_r( gpit_tmp, 8192 );
+ cum_gpit = mult_r( gpit_tmp, 8192 /* 0.25 in Q15 */ ); /* Q14 */
}
ELSE
{
- cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 8192 ) );
+ cum_gpit = add( cum_gpit, mult_r( gpit_tmp, 8192 /* 0.25 in Q15 */ ) ); /* Q14 */
}
pt_pitch++;
diff --git a/lib_enc/enc_ppp.c b/lib_enc/enc_ppp.c
deleted file mode 100644
index e7a8ca967132cf8896fc4a231dbaf74eed596840..0000000000000000000000000000000000000000
--- a/lib_enc/enc_ppp.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/enc_ppp_fx.c b/lib_enc/enc_ppp_fx.c
index 775a863d3379a11e3bae50bc02bd3f27329329d0..f1a87d2d296ec128e7aa823519ec942206c2f42e 100644
--- a/lib_enc/enc_ppp_fx.c
+++ b/lib_enc/enc_ppp_fx.c
@@ -53,16 +53,16 @@ void E_LPC_f_lsp_a_conversion( const Word16 *lsp, Word16 *a, const Word16 m );
/*=======================================================================================*/
ivas_error encod_ppp_fx(
Encoder_State *st_fx, /* i/o: state structure */
- const Word16 speech_fx[], /* i : input speech Q_new*/
- const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */
- const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */
- Word16 *res_fx, /* i : residual signal Q_new*/
- Word16 *synth_fx, /* o : core synthesis Q-1*/
- Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/
- Word16 *exc2_fx, /* o : current enhanced excitation Q0*/
- Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/
- Word16 *voice_factors, /* o : voicing factors */
- Word16 *bwe_exc, /* o : excitation for SWB TBE */
+ const Word16 speech_fx[], /* i : input speech Q_new*/
+ const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/
+ const Word16 Aq_fx[], /* i : 12k8 Lp coefficient Q14*/
+ Word16 *res_fx, /* i : residual signal Q_new*/
+ Word16 *synth_fx, /* o : core synthesis Q-1*/
+ Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/
+ Word16 *exc2_fx, /* o : current enhanced excitation Q0*/
+ Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/
+ Word16 *voice_factors, /* o : voicing factors Q15*/
+ Word16 *bwe_exc, /* o : excitation for SWB TBE Q_new*/
Word16 Q_new,
Word16 shift )
{
@@ -77,6 +77,7 @@ ivas_error encod_ppp_fx(
Word16 shift_wsp = add( Q_new, shift );
Word16 rate_ctrl_fx;
Word16 saved_Q_new = Q_new;
+ move16();
LPD_state_HANDLE hLPDmem = st_fx->hLPDmem;
SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR;
BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
@@ -101,7 +102,7 @@ ivas_error encod_ppp_fx(
* Compute impulse response, h1[], of weighted synthesis filter
*----------------------------------------------------------------*/
- Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR );
+ Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); /* Q_new */
find_targets_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx,
res_fx, L_SUBFR, p_Aw_fx, TILT_FAC_FX, xn_fx, NULL, h1_fx );
@@ -130,7 +131,7 @@ ivas_error encod_ppp_fx(
return error;
}
- Scale_sig( exc_fx, L_FRAME, ( saved_Q_new - Q_new ) );
+ Scale_sig( exc_fx, L_FRAME, ( saved_Q_new - Q_new ) ); /* saved_Q_new */
if ( EQ_16( hSC_VBR->bump_up, 1 ) )
{
i_subfr = L_FRAME;
@@ -199,37 +200,38 @@ ivas_error encod_ppp_fx(
}
ELSE
{
- Copy( excQ_ppp_fx, exc_fx, L_FRAME );
+ Copy( excQ_ppp_fx, exc_fx, L_FRAME ); /* Q_new */
/*-----------------------------------------------------------------*
* Updates: last value of new target is stored in mem_w0
*-----------------------------------------------------------------*/
hLPDmem->mem_w0 = sub( shr( xn_fx[L_SUBFR - 1], shift ), shr( exc_fx[L_FRAME - 1], 1 ) ); /*Q_new-1 */
+ move16();
- Copy( exc_fx, exc2_fx, L_FRAME );
+ Copy( exc_fx, exc2_fx, L_FRAME ); /* Q_new */
hLPDmem->dm_fx.prev_state = 2;
- move16(); /*Q0 dispMem index 0 */
- hLPDmem->dm_fx.prev_gain_pit[0] = hSC_VBR->prev_ppp_gain_pit_fx;
- move16(); /*Q14 dispMem index 2 */
+ move16(); /*Q0 dispMem index 0 */
+ hLPDmem->dm_fx.prev_gain_pit[0] = hSC_VBR->prev_ppp_gain_pit_fx; /* Q14 */
+ move16(); /*Q14 dispMem index 2 */
FOR( k = 1; k < 5; k++ )
{
- hLPDmem->dm_fx.prev_gain_pit[k] = hLPDmem->dm_fx.prev_gain_pit[k - 1];
+ hLPDmem->dm_fx.prev_gain_pit[k] = hLPDmem->dm_fx.prev_gain_pit[k - 1]; /* Q14 */
move16();
}
- hLPDmem->tilt_code = hSC_VBR->prev_tilt_code_fx;
+ hLPDmem->tilt_code = hSC_VBR->prev_tilt_code_fx; /* Q15 */
move16();
- Copy( pitch_fx, pitch_buf_fx, NB_SUBFR );
- pitch_buf_fx[NB_SUBFR16k - 1] = pitch_fx[NB_SUBFR - 1];
+ Copy( pitch_fx, pitch_buf_fx, NB_SUBFR ); /* Q6 */
+ pitch_buf_fx[NB_SUBFR16k - 1] = pitch_fx[NB_SUBFR - 1]; /* Q6 */
interp_code_5over2_fx( exc2_fx, bwe_exc, L_FRAME );
set16_fx( voice_factors, 0, NB_SUBFR16k );
}
- hSC_VBR->rate_control = rate_ctrl_fx;
+ hSC_VBR->rate_control = rate_ctrl_fx; /* Q0 */
move16();
set16_fx( hSC_VBR->nelp_lp_fit_mem, 0, NELP_LP_ORDER * 2 );
@@ -239,16 +241,16 @@ ivas_error encod_ppp_fx(
ivas_error encod_ppp_ivas_fx(
Encoder_State *st_fx, /* i/o: state structure */
- const Word16 speech_fx[], /* i : input speech Q_new*/
- const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */
- const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */
- Word16 *res_fx, /* i : residual signal Q_new*/
- Word16 *synth_fx, /* o : core synthesis Q-1*/
- Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/
- Word16 *exc2_fx, /* o : current enhanced excitation Q0*/
- Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/
- Word16 *voice_factors, /* o : voicing factors */
- Word16 *bwe_exc, /* o : excitation for SWB TBE */
+ const Word16 speech_fx[], /* i : input speech Q_new*/
+ const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/
+ const Word16 Aq_fx[], /* i : 12k8 Lp coefficient Q12*/
+ Word16 *res_fx, /* i : residual signal Q_new*/
+ Word16 *synth_fx, /* o : core synthesis Q-1*/
+ Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/
+ Word16 *exc2_fx, /* o : current enhanced excitation Q0*/
+ Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/
+ Word16 *voice_factors, /* o : voicing factors Q15*/
+ Word16 *bwe_exc, /* o : excitation for SWB TBE Q_new*/
Word16 Q_new,
Word16 shift )
{
@@ -288,7 +290,7 @@ ivas_error encod_ppp_ivas_fx(
* Compute impulse response, h1[], of weighted synthesis filter
*----------------------------------------------------------------*/
- Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR );
+ Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); /* Q_new */
find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx,
res_fx, L_SUBFR, p_Aw_fx, TILT_FAC_FX, xn_fx, NULL, h1_fx );
@@ -301,7 +303,7 @@ ivas_error encod_ppp_ivas_fx(
{
FOR( k = 0; k < M; k++ )
{
- p_Aq_curr_fx[k] = p_Aq_fx[k + ( 3 * ( M + 1 ) ) + 1];
+ p_Aq_curr_fx[k] = p_Aq_fx[k + ( 3 * ( M + 1 ) ) + 1]; /* Q12 */
move16();
}
@@ -317,7 +319,7 @@ ivas_error encod_ppp_ivas_fx(
return error;
}
- Scale_sig( exc_fx, L_FRAME, sub( saved_Q_new, Q_new ) );
+ Scale_sig( exc_fx, L_FRAME, sub( saved_Q_new, Q_new ) ); /* saved_Q_new */
if ( EQ_16( hSC_VBR->bump_up, 1 ) )
{
i_subfr = L_FRAME;
@@ -386,7 +388,7 @@ ivas_error encod_ppp_ivas_fx(
}
ELSE
{
- Copy( excQ_ppp_fx, exc_fx, L_FRAME );
+ Copy( excQ_ppp_fx, exc_fx, L_FRAME ); /* Q_new */
/*-----------------------------------------------------------------*
* Updates: last value of new target is stored in mem_w0
@@ -394,7 +396,7 @@ ivas_error encod_ppp_ivas_fx(
hLPDmem->mem_w0 = sub( shr( xn_fx[L_SUBFR - 1], shift ), shr( exc_fx[L_FRAME - 1], 1 ) ); /*Q_new-1 */
- Copy( exc_fx, exc2_fx, L_FRAME );
+ Copy( exc_fx, exc2_fx, L_FRAME ); /* Q_new */
hLPDmem->dm_fx.prev_state = 2;
move16(); /*Q0 dispMem index 0 */
@@ -403,11 +405,11 @@ ivas_error encod_ppp_ivas_fx(
FOR( k = 1; k < 5; k++ )
{
- hLPDmem->dm_fx.prev_gain_pit[k] = hLPDmem->dm_fx.prev_gain_pit[k - 1];
+ hLPDmem->dm_fx.prev_gain_pit[k] = hLPDmem->dm_fx.prev_gain_pit[k - 1]; /* Q14 */
move16();
}
- hLPDmem->tilt_code = hSC_VBR->prev_tilt_code_fx;
+ hLPDmem->tilt_code = hSC_VBR->prev_tilt_code_fx; /* Q15 */
move16();
Copy( pitch_fx, pitch_buf_fx, NB_SUBFR );
pitch_buf_fx[NB_SUBFR16k - 1] = pitch_fx[NB_SUBFR - 1];
@@ -416,7 +418,7 @@ ivas_error encod_ppp_ivas_fx(
set16_fx( voice_factors, 0, NB_SUBFR16k );
}
- hSC_VBR->rate_control = rate_ctrl_fx;
+ hSC_VBR->rate_control = rate_ctrl_fx; /* Q0 */
move16();
set16_fx( hSC_VBR->nelp_lp_fit_mem, 0, NELP_LP_ORDER * 2 );
diff --git a/lib_enc/enc_prm.c b/lib_enc/enc_prm.c
index 1239a104c6ca7ec870e4cfb55f2167f8f2f14a4d..6c6ade036529b72b8094b3e06bc1ccb654ef6094 100644
--- a/lib_enc/enc_prm.c
+++ b/lib_enc/enc_prm.c
@@ -44,16 +44,16 @@
/*-------------------------------------------------------------------*
- * writeTCXMode()
+ * writeTCXMode_fx()
*
* write TCX mode
*--------------------------------------------------------------------*/
-void writeTCXMode(
- Encoder_State *st, /* i/o: encoder state structure */
- BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
- const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */
- Word16 *nbits_start /* o : nbits start */
+void writeTCXMode_fx(
+ Encoder_State *st, /* i/o: encoder state structure */
+ BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
+ const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/
+ Word16 *nbits_start /* o : nbits start Q0*/
)
{
UWord16 index;
@@ -110,8 +110,8 @@ void writeTCXMode(
}
/* retrieve the number of bits for signaling */
- idx = add( idx, 1 );
- nBits = extract_l( acelp_sig_tbl[idx] );
+ idx = add( idx, 1 ); /* Q0 */
+ nBits = extract_l( acelp_sig_tbl[idx] ); /* Q0 */
/* retrieve the signaling index */
idx = add( idx, 1 );
@@ -203,14 +203,14 @@ void writeTCXMode(
/*-------------------------------------------------------------------*
- * writeTCXWindowing()
+ * writeTCXWindowing_fx()
*
* write TCX transform type
*-------------------------------------------------------------------*/
-void writeTCXWindowing(
+void writeTCXWindowing_fx(
BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
- const Word16 overlap_mode /* i : overlap mode */
+ const Word16 overlap_mode /* i : overlap mode Q0*/
)
{
diff --git a/lib_enc/enc_prm_fx.c b/lib_enc/enc_prm_fx.c
index c67a3f447e06f266b3e8f0c986862d5b53e3e17e..d394fa2d3acbf5703f33934fcbf011e214f0b7a7 100644
--- a/lib_enc/enc_prm_fx.c
+++ b/lib_enc/enc_prm_fx.c
@@ -17,9 +17,10 @@
static void enc_prm_hm(
- Word16 *prm_hm,
+ Word16 *prm_hm, /* Q0 */
Encoder_State *st,
- Word16 L_frame )
+ Word16 L_frame /* Q0 */
+)
{
Word8 flag;
BSTR_ENC_HANDLE hBstr = st->hBstr;
@@ -55,9 +56,10 @@ static void enc_prm_hm(
}
}
static void enc_prm_hm_ivas_fx(
- Word16 *prm_hm,
+ Word16 *prm_hm, /* Q0 */
Encoder_State *st,
- Word16 L_frame )
+ Word16 L_frame /* Q0 */
+)
{
Word8 flag;
BSTR_ENC_HANDLE hBstr = st->hBstr;
@@ -100,9 +102,11 @@ static void enc_prm_hm_ivas_fx(
* encode RF parameters for ACELP and TCX partial copy *
*-----------------------------------------------------------------*/
-void enc_prm_rf_ivas_fx( Encoder_State *st,
- const Word16 rf_frame_type,
- const Word16 fec_offset )
+void enc_prm_rf_ivas_fx(
+ Encoder_State *st,
+ const Word16 rf_frame_type, /* Q0 */
+ const Word16 fec_offset /* Q0 */
+)
{
Word16 sfr, nb_subfr, n, index;
Word16 ltp_mode, ltf_mode, gains_mode;
@@ -111,7 +115,7 @@ void enc_prm_rf_ivas_fx( Encoder_State *st,
BSTR_ENC_HANDLE hBstr = st->hBstr;
- nb_subfr = st->nb_subfr;
+ nb_subfr = st->nb_subfr; /* Q0 */
move16();
/* partial copy bitstream writing */
test();
@@ -269,9 +273,11 @@ void enc_prm_rf_ivas_fx( Encoder_State *st,
/* write RF frame type last in the bitstream */
push_next_indice( hBstr, rf_frame_type, 3 );
}
-void enc_prm_rf_fx( Encoder_State *st,
- const Word16 rf_frame_type,
- const Word16 fec_offset )
+void enc_prm_rf_fx(
+ Encoder_State *st,
+ const Word16 rf_frame_type, /* Q0 */
+ const Word16 fec_offset /* Q0 */
+)
{
Word16 sfr, nb_subfr, n, index;
Word16 ltp_mode, ltf_mode, gains_mode;
@@ -280,7 +286,7 @@ void enc_prm_rf_fx( Encoder_State *st,
BSTR_ENC_HANDLE hBstr = st->hBstr;
- nb_subfr = st->nb_subfr;
+ nb_subfr = st->nb_subfr; /* Q0 */
/* partial copy bitstream writing */
test();
@@ -370,9 +376,9 @@ void enc_prm_rf_fx( Encoder_State *st,
/* ES pred */
push_next_indice_fx( hBstr, hRF->rf_indx_EsPred[fec_offset], 3 );
- ltp_mode = ACELP_LTP_MODE[1][1][rf_frame_type];
- ltf_mode = ACELP_LTF_MODE[1][1][rf_frame_type];
- gains_mode = ACELP_GAINS_MODE[1][1][rf_frame_type];
+ ltp_mode = ACELP_LTP_MODE[1][1][rf_frame_type]; /* Q0 */
+ ltf_mode = ACELP_LTF_MODE[1][1][rf_frame_type]; /* Q0 */
+ gains_mode = ACELP_GAINS_MODE[1][1][rf_frame_type]; /* Q0 */
/* Subframe parameters */
FOR( sfr = 0; sfr < nb_subfr; sfr++ )
@@ -446,13 +452,14 @@ void enc_prm_rf_fx( Encoder_State *st,
void enc_prm_fx(
const Word16 coder_type, /* (i) : coding type */
- Word16 param[], /* (i) : parameters */
- Word16 param_lpc[], /* (i) : LPC parameters */
+ Word16 param[], /* (i) : parameters Q0*/
+ Word16 param_lpc[], /* (i) : LPC parameters Q0*/
Encoder_State *st, /* i/o : quantization Analysis values */
- Word16 L_frame,
+ Word16 L_frame, /* Q0 */
CONTEXT_HM_CONFIG hm_cfg[],
- Word16 *bits_param_lpc,
- Word16 no_param_lpc )
+ Word16 *bits_param_lpc, /* Q0 */
+ Word16 no_param_lpc /* Q0 */
+)
{
Word16 j, k, n, sfr, core, last_core, *prm, tmp;
Word16 nbits_start, total_nbbits;
@@ -507,7 +514,7 @@ void enc_prm_fx(
move16();
move16();
j = 0;
- nbits_start = hBstr->nb_bits_tot;
+ nbits_start = hBstr->nb_bits_tot; /* Q0 */
/*--------------------------------------------------------------------------------*
@@ -517,7 +524,7 @@ void enc_prm_fx(
IF( EQ_16( st->mdct_sw, MODE1 ) )
{
/* Adjust st->bits_frame_core not to subtract MODE2 bandwidth signaling */
- st->bits_frame_core = add( st->bits_frame_core, FrameSizeConfig[st->frame_size_index].bandwidth_bits );
+ st->bits_frame_core = add( st->bits_frame_core, FrameSizeConfig[st->frame_size_index].bandwidth_bits ); /* Q0 */
/* Write MODE1 core mode signaling */
signalling_mode1_tcx20_enc_fx( st, 1 );
@@ -565,19 +572,19 @@ void enc_prm_fx(
}
/* retrieve the number of bits for signalling */
- nBits = (Word16) acelp_sig_tbl[++idx];
+ nBits = (Word16) acelp_sig_tbl[++idx]; /* Q0 */
/* retrieve the signalling index */
- idx = add( idx, 1 );
- start_idx = idx;
+ idx = add( idx, 1 ); /* Q0 */
+ start_idx = idx; /* Q0 */
tmp32 = SIG2IND_fx( coder_type, st->bwidth, st->sharpFlag, st->rf_mode );
WHILE( NE_32( acelp_sig_tbl[idx], tmp32 ) )
{
- idx = add( idx, 1 );
+ idx = add( idx, 1 ); /* Q0 */
}
push_next_indice_fx( hBstr, idx - start_idx, nBits );
push_next_indice_fx( hBstr, 0, 1 ); /* Indicate to the decoder that the core is ACELP*/
- nbits_start = 3;
+ nbits_start = 3; /* Q0 */
}
ELSE
{
@@ -612,7 +619,7 @@ void enc_prm_fx(
}
/* retrieve the number of bits for signalling */
- nBits = (Word16) acelp_sig_tbl[++idx];
+ nBits = (Word16) acelp_sig_tbl[++idx]; /* Q0 */
test();
test();
@@ -628,8 +635,8 @@ void enc_prm_fx(
}
/* retrieve the signalling index */
- idx = add( idx, 1 );
- start_idx = idx;
+ idx = add( idx, 1 ); /* Q0 */
+ start_idx = idx; /* Q0 */
tmp32 = SIG2IND_fx( st->hTcxCfg->coder_type, st->bwidth, st->sharpFlag, st->rf_mode );
WHILE( NE_32( acelp_sig_tbl[idx], tmp32 ) )
{
@@ -720,7 +727,7 @@ void enc_prm_fx(
st->glr_reset = 0;
move16();
- nbits_header = sub( hBstr->nb_bits_tot, nbits_start );
+ nbits_header = sub( hBstr->nb_bits_tot, nbits_start ); /* Q0 */
/*--------------------------------------------------------------------------------*
@@ -730,7 +737,7 @@ void enc_prm_fx(
IF( s_and( st->enableTcxLpc != 0, core != ACELP_CORE ) )
{
/* Encode the indices */
- nbits_lpc = enc_lsf_tcxlpc_fx( ¶m_lpc, hBstr );
+ nbits_lpc = enc_lsf_tcxlpc_fx( ¶m_lpc, hBstr ); /* Q0 */
}
ELSE
{
@@ -745,7 +752,7 @@ void enc_prm_fx(
move16();
}
- nbits_lpc = encode_lpc_avq_fx( hBstr, numlpc, param_lpc, st->core, st->element_mode );
+ nbits_lpc = encode_lpc_avq_fx( hBstr, numlpc, param_lpc, st->core, st->element_mode ); /* Q0 */
}
ELSE IF( EQ_16( st->lpcQuantization, 1 ) )
{
@@ -753,11 +760,11 @@ void enc_prm_fx(
test();
IF( EQ_32( st->sr_core, 16000 ) && EQ_16( coder_type, VOICED ) && EQ_16( core, ACELP_CORE ) )
{
- nbits_lpc = lsf_bctcvq_encprm_fx( hBstr, param_lpc, bits_param_lpc, no_param_lpc );
+ nbits_lpc = lsf_bctcvq_encprm_fx( hBstr, param_lpc, bits_param_lpc, no_param_lpc ); /* Q0 */
}
ELSE
{
- nbits_lpc = lsf_msvq_ma_encprm_fx( hBstr, param_lpc, core, coder_type, st->acelp_cfg.midLpc, bits_param_lpc, no_param_lpc );
+ nbits_lpc = lsf_msvq_ma_encprm_fx( hBstr, param_lpc, core, coder_type, st->acelp_cfg.midLpc, bits_param_lpc, no_param_lpc ); /* Q0 */
}
}
ELSE
@@ -787,7 +794,7 @@ void enc_prm_fx(
}
/* Mean energy (2 or 3 bits) */
- n = ACELP_NRG_BITS[st->acelp_cfg.nrg_mode];
+ n = ACELP_NRG_BITS[st->acelp_cfg.nrg_mode]; /* Q0 */
IF( n != 0 )
{
@@ -800,7 +807,7 @@ void enc_prm_fx(
{
/* Pitch lag (4, 5, 6, 8 or 9 bits) */
move16();
- n = ACELP_LTP_BITS_SFR[st->acelp_cfg.ltp_mode][sfr];
+ n = ACELP_LTP_BITS_SFR[st->acelp_cfg.ltp_mode][sfr]; /* Q0 */
IF( n != 0 )
{
@@ -841,7 +848,7 @@ void enc_prm_fx(
push_next_indice_fx( hBstr, prm[j++], bitcnt );
}
- j = add( j_old, 8 );
+ j = add( j_old, 8 ); /* Q0 */
}
/* Gains (5b, 6b or 7b / subfr) */
@@ -887,9 +894,9 @@ void enc_prm_fx(
j = add( j, 3 );
/* TCX spectral data */
- lg = L_frame;
+ lg = L_frame; /* Q0 */
move16();
- lgFB = st->hTcxCfg->tcx_coded_lines;
+ lgFB = st->hTcxCfg->tcx_coded_lines; /* Q0 */
move16();
IF( last_core == ACELP_CORE )
@@ -899,7 +906,7 @@ void enc_prm_fx(
lgFB = add( lgFB, shr( lgFB, 2 ) );
if ( st->hTcxCfg->lfacNext < 0 )
{
- lg = sub( lg, st->hTcxCfg->lfacNext );
+ lg = sub( lg, st->hTcxCfg->lfacNext ); /* Q0 */
}
}
@@ -912,7 +919,7 @@ void enc_prm_fx(
IF( st->hTcxCfg->fIsTNSAllowed )
{
WriteTnsData_fx( st->hTcxCfg->pCurrentTnsConfig, prm + j, &nTnsParams, st, &nTnsBits );
- j = add( j, nTnsParams );
+ j = add( j, nTnsParams ); /* Q0 */
}
hm_size = shl( mult( st->hTcxCfg->bandwidth, lg ), 1 );
@@ -950,17 +957,17 @@ void enc_prm_fx(
IGFEncWriteBitstream_fx( st->hIGFEnc, hBstr, &st->hIGFEnc->infoTotalBitsPerFrameWritten, IGF_GRID_LB_NORM, 1 );
}
}
- total_nbbits = sub( hBstr->nb_bits_tot, nbits_start );
+ total_nbbits = sub( hBstr->nb_bits_tot, nbits_start ); /* Q0 */
if ( EQ_16( st->rf_mode, 1 ) )
{
- total_nbbits = add( total_nbbits, st->rf_target_bits_write );
+ total_nbbits = add( total_nbbits, st->rf_target_bits_write ); /* Q0 */
}
- nbits_tcx = sub( st->bits_frame_core, total_nbbits );
+ nbits_tcx = sub( st->bits_frame_core, total_nbbits ); /* Q0 */
IF( hTcxEnc->tcx_lpc_shaped_ari != 0 )
{
push_next_bits_fx( hBstr, &prm[++j], nbits_tcx );
- j = add( j, nbits_tcx );
+ j = add( j, nbits_tcx ); /* Q0 */
}
ELSE
{
@@ -990,7 +997,7 @@ void enc_prm_fx(
move16();
IF( st->igf )
{
- nbits_igf = IGFEncWriteConcatenatedBitstream_fx( st->hIGFEnc, hBstr );
+ nbits_igf = IGFEncWriteConcatenatedBitstream_fx( st->hIGFEnc, hBstr ); /* Q0 */
}
FOR( k = 0; k < 2; k++ )
{
@@ -1004,7 +1011,7 @@ void enc_prm_fx(
j = 0;
move16();
- nbits_tcx = total_nbbits = sub( hBstr->nb_bits_tot, nbits_start );
+ nbits_tcx = total_nbbits = sub( hBstr->nb_bits_tot, nbits_start ); /* Q0 */
test();
IF( st->enablePlcWaveadjust && k )
@@ -1043,11 +1050,11 @@ void enc_prm_fx(
IF( s_and( k == 0, last_core == ACELP_CORE ) )
{
/* ACE->TCX transition */
- lg = add( lg, st->hTcxCfg->tcx_offset );
+ lg = add( lg, st->hTcxCfg->tcx_offset ); /* Q0 */
lgFB = add( lgFB, shr( lgFB, 1 ) );
if ( st->hTcxCfg->lfacNext < 0 )
{
- lg = sub( lg, st->hTcxCfg->lfacNext );
+ lg = sub( lg, st->hTcxCfg->lfacNext ); /* Q0 */
}
}
@@ -1084,9 +1091,9 @@ void enc_prm_fx(
}
j = add( j, NPRM_CTX_HM );
- total_nbbits = sub( hBstr->nb_bits_tot, nbits_start );
+ total_nbbits = sub( hBstr->nb_bits_tot, nbits_start ); /* Q0 */
- nbits_tcx = sub( shr( sub( add( sub( sub( sub( st->bits_frame_core, nbits_header ), nbits_lpc ), nbits_igf ), 1 ), k ), 1 ), sub( total_nbbits, nbits_tcx ) );
+ nbits_tcx = sub( shr( sub( add( sub( sub( sub( st->bits_frame_core, nbits_header ), nbits_lpc ), nbits_igf ), 1 ), k ), 1 ), sub( total_nbbits, nbits_tcx ) ); /* Q0 */
phm_cfg = NULL;
move16();
@@ -1109,7 +1116,7 @@ void enc_prm_fx(
*--------------------------------------------------------------------------------*/
- total_nbbits = sub( hBstr->nb_bits_tot, nbits_start );
+ total_nbbits = sub( hBstr->nb_bits_tot, nbits_start ); /* Q0 */
/* Check if total encoded bits does not exceed CBR target bits (->this must never happen) */
@@ -1132,10 +1139,10 @@ void enc_prm_fx(
void writeLPCparam_fx(
Encoder_State *st, /* i/o: encoder state structure */
BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
- const Word16 param_lpc[], /* i : LPC parameters to write */
- const Word16 bits_param_lpc[], /* i : bits per LPC parameter */
- const Word16 no_param_lpc, /* i : number of LPC parameters */
- Word16 *nbits_lpc /* o : LPC bits written */
+ const Word16 param_lpc[], /* i : LPC parameters to write Q0*/
+ const Word16 bits_param_lpc[], /* i : bits per LPC parameter Q0*/
+ const Word16 no_param_lpc, /* i : number of LPC parameters Q0*/
+ Word16 *nbits_lpc /* o : LPC bits written Q0*/
)
{
Word16 numlpc;
@@ -1144,7 +1151,7 @@ void writeLPCparam_fx(
IF( st->enableTcxLpc && st->core != ACELP_CORE )
{
/* Encode the indices */
- *nbits_lpc = enc_lsf_tcxlpc_ivas_fx( ¶m_lpc, hBstr );
+ *nbits_lpc = enc_lsf_tcxlpc_ivas_fx( ¶m_lpc, hBstr ); /* Q0 */
move16();
}
ELSE
@@ -1163,7 +1170,7 @@ void writeLPCparam_fx(
move16();
}
- *nbits_lpc = encode_lpc_avq_ivas_fx( hBstr, numlpc, param_lpc, st->core, st->element_mode );
+ *nbits_lpc = encode_lpc_avq_ivas_fx( hBstr, numlpc, param_lpc, st->core, st->element_mode ); /* Q0 */
move16();
}
ELSE IF( EQ_16( st->lpcQuantization, 1 ) )
@@ -1174,12 +1181,12 @@ void writeLPCparam_fx(
{
assert( st->element_mode == EVS_MONO );
- *nbits_lpc = lsf_bctcvq_encprm_ivas_fx( hBstr, param_lpc, bits_param_lpc, no_param_lpc );
+ *nbits_lpc = lsf_bctcvq_encprm_ivas_fx( hBstr, param_lpc, bits_param_lpc, no_param_lpc ); /* Q0 */
move16();
}
ELSE
{
- *nbits_lpc = lsf_msvq_ma_encprm_ivas_fx( hBstr, param_lpc, st->core, st->coder_type, st->acelp_cfg.midLpc, bits_param_lpc, no_param_lpc );
+ *nbits_lpc = lsf_msvq_ma_encprm_ivas_fx( hBstr, param_lpc, st->core, st->coder_type, st->acelp_cfg.midLpc, bits_param_lpc, no_param_lpc ); /* Q0 */
move16();
}
}
@@ -1199,17 +1206,18 @@ void writeLPCparam_fx(
*-------------------------------------------------------------------*/
void writeTCXparam_fx(
- Encoder_State *st, /* i/o: Encoder State handle */
- BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
- CONTEXT_HM_CONFIG hm_cfg[], /* i/o: HM config */
- Word16 param[], /* i : parameters */
- const Word16 nbits_header,
- const Word16 nbits_start,
- const Word16 nbits_lpc,
- const Word16 *no_param_tns, /* i : number of TNS parameters per subframe */
- Word16 p_param[2], /* i/o: pointer to parameters from previous bs writing */
- const Word16 target_bitsTCX10[2],
- const Word16 pre_past_flag )
+ Encoder_State *st, /* i/o: Encoder State handle */
+ BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
+ CONTEXT_HM_CONFIG hm_cfg[], /* i/o: HM config */
+ Word16 param[], /* i : parameters Q0*/
+ const Word16 nbits_header, /* Q0 */
+ const Word16 nbits_start, /* Q0 */
+ const Word16 nbits_lpc, /* Q0 */
+ const Word16 *no_param_tns, /* i : number of TNS parameters per subframe Q0*/
+ Word16 p_param[2], /* i/o: pointer to parameters from previous bs writing Q0*/
+ const Word16 target_bitsTCX10[2], /* Q0 */
+ const Word16 pre_past_flag /* Q0 */
+)
{
Word16 *prm;
Word16 j, k, nSubframes, core, last_core;
@@ -1264,7 +1272,7 @@ void writeTCXparam_fx(
test();
IF( LT_16( st->element_mode, IVAS_CPE_MDCT ) && k == 0 && st->igf && EQ_16( core, TCX_10_CORE ) )
{
- nbits_igf = IGFEncWriteConcatenatedBitstream_ivas_fx( st->hIGFEnc, hBstr );
+ nbits_igf = IGFEncWriteConcatenatedBitstream_ivas_fx( st->hIGFEnc, hBstr ); /* Q0 */
}
flag_ctx_hm = 0;
@@ -1274,7 +1282,7 @@ void writeTCXparam_fx(
j = 0;
move16();
- nbits_tcx = total_nbbits = sub( hBstr->nb_bits_tot, nbits_start );
+ nbits_tcx = total_nbbits = sub( hBstr->nb_bits_tot, nbits_start ); /* Q0 */
move16();
test();
@@ -1319,7 +1327,7 @@ void writeTCXparam_fx(
}
ELSE
{
- j = add( j, sub( p_param[k], 2 ) );
+ j = add( j, sub( p_param[k], 2 ) ); /* Q0 */
}
/* TCX spectral data */
@@ -1331,12 +1339,12 @@ void writeTCXparam_fx(
IF( post_part && k == 0 && last_core == ACELP_CORE )
{
/* ACE->TCX transition */
- lg = add( lg, st->hTcxCfg->tcx_offset );
- lgFB = add( lgFB, shr( lgFB, sub( 3, nSubframes ) ) );
+ lg = add( lg, st->hTcxCfg->tcx_offset ); /* Q0 */
+ lgFB = add( lgFB, shr( lgFB, sub( 3, nSubframes ) ) ); /* Q0 */
IF( st->hTcxCfg->lfacNext < 0 )
{
- lg = sub( lg, st->hTcxCfg->lfacNext );
+ lg = sub( lg, st->hTcxCfg->lfacNext ); /* Q0 */
}
}
@@ -1368,7 +1376,7 @@ void writeTCXparam_fx(
IF( no_param_tns && ( st->hTcxEnc->tnsData[k].nFilters < 0 ) )
{
/* a negative filter count means that the filters are identical to those in the first channel at the same sub-frame */
- nTnsParams = no_param_tns[k];
+ nTnsParams = no_param_tns[k]; /* Q0 */
move16();
}
ELSE
@@ -1377,14 +1385,14 @@ void writeTCXparam_fx(
}
IF( no_param_tns )
{
- nTnsBits = add( nTnsBits, 1 );
+ nTnsBits = add( nTnsBits, 1 ); /* Q0 */
}
- j = add( j, nTnsParams );
+ j = add( j, nTnsParams ); /* Q0 */
}
IF( post_part )
{
- hm_size = imult1616( mult( 2, st->hTcxCfg->bandwidth ), lg );
+ hm_size = imult1616( mult( 2, st->hTcxCfg->bandwidth ), lg ); /* Q0 */
test();
test();
@@ -1430,35 +1438,35 @@ void writeTCXparam_fx(
IGFEncWriteBitstream_ivas_fx( st->hIGFEnc, hBstr, &st->hIGFEnc->infoTotalBitsPerFrameWritten, gridIdx, 1 );
}
- total_nbbits = sub( hBstr->nb_bits_tot, nbits_start );
+ total_nbbits = sub( hBstr->nb_bits_tot, nbits_start ); /* Q0 */
IF( EQ_16( core, TCX_20_CORE ) )
{
IF( st->rf_mode )
{
- total_nbbits = add( total_nbbits, st->rf_target_bits_write );
+ total_nbbits = add( total_nbbits, st->rf_target_bits_write ); /* Q0 */
}
- nbits_tcx = sub( st->bits_frame_core, total_nbbits );
+ nbits_tcx = sub( st->bits_frame_core, total_nbbits ); /* Q0 */
}
ELSE /* TCX_10_CORE */
{
- nbits_tcx = sub( shr( sub( add( sub( sub( sub( st->bits_frame_core, nbits_header ), nbits_lpc ), nbits_igf ), 1 ), k ), 1 ), sub( total_nbbits, nbits_tcx ) );
+ nbits_tcx = sub( shr( sub( add( sub( sub( sub( st->bits_frame_core, nbits_header ), nbits_lpc ), nbits_igf ), 1 ), k ), 1 ), sub( total_nbbits, nbits_tcx ) ); /* Q0 */
}
}
ELSE
{
/*Context HM flag*/
- p_param[k] = j;
+ p_param[k] = j; /* Q0 */
move16();
}
}
ELSE
{
- nbits_tcx = st->bits_frame_channel;
+ nbits_tcx = st->bits_frame_channel; /* Q0 */
move16();
IF( EQ_16( core, TCX_10_CORE ) )
{
- nbits_tcx = sub( target_bitsTCX10[k], NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL );
+ nbits_tcx = sub( target_bitsTCX10[k], NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL ); /* Q0 */
}
}
@@ -1468,7 +1476,7 @@ void writeTCXparam_fx(
IF( st->hTcxEnc->tcx_lpc_shaped_ari && EQ_16( core, TCX_20_CORE ) )
{
push_next_bits( hBstr, (UWord16 *) &prm[++j], nbits_tcx );
- j = add( j, nbits_tcx );
+ j = add( j, nbits_tcx ); /* Q0 */
}
ELSE
{
diff --git a/lib_enc/enc_tran.c b/lib_enc/enc_tran.c
deleted file mode 100644
index fc894ba6cc3b0f6891e5522d7bdaa893786ada84..0000000000000000000000000000000000000000
--- a/lib_enc/enc_tran.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 "prot.h"
-#include "rom_com.h"
-#include "wmc_auto.h"
diff --git a/lib_enc/enc_tran_fx.c b/lib_enc/enc_tran_fx.c
index 918762a142a7b55ffc67677008e87b15832b4586..71e8b9e3b3253f984c4b6825d838e148c8c3624c 100644
--- a/lib_enc/enc_tran_fx.c
+++ b/lib_enc/enc_tran_fx.c
@@ -47,20 +47,20 @@
Word16 encod_tran_fx(
Encoder_State *st_fx, /* i/o: state structure */
- const Word16 speech_fx[], /* i : input speech */
- const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */
- const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */
- const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */
- const Word16 *res_fx, /* i : residual signal */
- Word16 *syn_fx, /* i/o: core synthesis */
- Word16 *exc_fx, /* i/o: current non-enhanced excitation */
- Word16 *exc2_fx, /* i/o: current enhanced excitation */
- Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe */
- Word16 *voice_factors, /* o : voicing factors */
- Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */
- Word16 tc_subfr, /* i/o: TC subframe classification */
- Word16 position, /* i : maximum of residual signal index */
- Word16 *unbits, /* i/o: number of unused bits */
+ const Word16 speech_fx[], /* i : input speech Q0*/
+ const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/
+ const Word16 Aq_fx[], /* i : 12k8 Lp coefficient Q12*/
+ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy Q8*/
+ const Word16 *res_fx, /* i : residual signal Q_new*/
+ Word16 *syn_fx, /* i/o: core synthesis Q_new*/
+ Word16 *exc_fx, /* i/o: current non-enhanced excitation Q0*/
+ Word16 *exc2_fx, /* i/o: current enhanced excitation Q0*/
+ Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe Q6*/
+ Word16 *voice_factors, /* o : voicing factors Q15*/
+ Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q0*/
+ Word16 tc_subfr, /* i/o: TC subframe classification Q0*/
+ Word16 position, /* i : maximum of residual signal index Q0*/
+ Word16 *unbits, /* i/o: number of unused bits Q0*/
const Word16 shift, /* i : Scaling to get 12 bits */
const Word16 Q_new /* i : Input scaling */
)
@@ -96,6 +96,7 @@ Word16 encod_tran_fx(
Word32 L_tmp;
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
+ move32();
#endif
BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR;
@@ -131,14 +132,14 @@ Word16 encod_tran_fx(
/**unbits = 0;move16();*/
Jopt_flag = 0;
move16();
- unbits_ACELP = *unbits;
+ unbits_ACELP = *unbits; /* Q0 */
move16();
*unbits = 0;
move16();
- p_Aw = Aw_fx;
- p_Aq = Aq_fx;
- pt_pitch = pitch_buf_fx;
+ p_Aw = Aw_fx; /* Q12 */
+ p_Aq = Aq_fx; /* Q12 */
+ pt_pitch = pitch_buf_fx; /* Q6 */
gain_preQ = 0;
move16();
set16_fx( code_preQ, 0, L_SUBFR );
@@ -156,7 +157,7 @@ Word16 encod_tran_fx(
* Compute impulse response, h1[], of weighted synthesis filter
*----------------------------------------------------------------*/
- Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR );
+ Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); /* Q_new */
find_targets_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq,
res_fx, L_SUBFR, p_Aw, st_fx->preemph_fac, xn, cn, h1 );
@@ -235,20 +236,20 @@ Word16 encod_tran_fx(
Lgcode = L_shl( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/
gcode16 = round_fx( Lgcode );
#endif
- hLPDmem->tilt_code = Est_tilt2( &exc_fx[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift );
+ hLPDmem->tilt_code = Est_tilt2( &exc_fx[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift ); /* Q15 */
/*-----------------------------------------------------------------*
* Update memory of the weighting filter
*-----------------------------------------------------------------*/
/*st->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]);*/
- L_tmp = L_mult( gcode16, y2[L_SUBFR - 1] );
- L_tmp = L_shl( L_tmp, add( 5, shift ) );
+ L_tmp = L_mult( gcode16, y2[L_SUBFR - 1] ); /* Q10 + Q_new */
+ L_tmp = L_shl( L_tmp, add( 5, shift ) ); /* Q15 + Q_new + shift */
L_tmp = L_negate( L_tmp );
L_tmp = L_mac( L_tmp, xn[L_SUBFR - 1], 16384 );
L_tmp = L_msu( L_tmp, y1[L_SUBFR - 1], gain_pit );
#ifdef BASOP_NOGLOB
- L_tmp = L_shl_sat( L_tmp, sub( 1, shift ) );
- hLPDmem->mem_w0 = round_fx_sat( L_tmp ); /*Q_new-1*/
+ L_tmp = L_shl_sat( L_tmp, sub( 1, shift ) ); /* Q_new + 15 */
+ hLPDmem->mem_w0 = round_fx_sat( L_tmp ); /*Q_new-1*/
#else
L_tmp = L_shl( L_tmp, sub( 1, shift ) );
hLPDmem->mem_w0 = round_fx( L_tmp ); /*Q_new-1*/
@@ -269,7 +270,7 @@ Word16 encod_tran_fx(
FOR( i = 0; i < L_SUBFR; i++ )
{
#ifdef BASOP_NOGLOB
- exc2_fx[i + i_subfr] = round_fx_sat( L_shl_sat( L_mult_sat( gain_pit, exc_fx[i + i_subfr] ), 1 ) );
+ exc2_fx[i + i_subfr] = round_fx_sat( L_shl_sat( L_mult_sat( gain_pit, exc_fx[i + i_subfr] ), 1 ) ); /* Q_new */
#else
exc2_fx[i + i_subfr] = round_fx( L_shl( L_mult( gain_pit, exc_fx[i + i_subfr] ), 1 ) );
#endif
@@ -277,10 +278,10 @@ Word16 encod_tran_fx(
}
ELSE
{
- Gain_pitX2 = shl( gain_pit, 1 );
+ Gain_pitX2 = shl( gain_pit, 1 ); /* Q15 */
FOR( i = 0; i < L_SUBFR; i++ )
{
- exc2_fx[i + i_subfr] = mult_r( Gain_pitX2, exc_fx[i + i_subfr] );
+ exc2_fx[i + i_subfr] = mult_r( Gain_pitX2, exc_fx[i + i_subfr] ); /* Q_new */
}
}
@@ -291,12 +292,12 @@ Word16 encod_tran_fx(
FOR( i = 0; i < L_SUBFR; i++ )
{
/* code in Q9, gain_pit in Q14 */
- L_tmp = L_mult( gcode16, code[i] );
+ L_tmp = L_mult( gcode16, code[i] ); /* Q10 + Q_new */
#ifdef BASOP_NOGLOB
- L_tmp = L_shl_o( L_tmp, 5, &Overflow );
- L_tmp = L_mac_o( L_tmp, exc_fx[i + i_subfr], gain_pit, &Overflow );
- L_tmp = L_shl_o( L_tmp, 1, &Overflow ); /* saturation can occur here */
- exc_fx[i + i_subfr] = round_fx_o( L_tmp, &Overflow );
+ L_tmp = L_shl_o( L_tmp, 5, &Overflow ); /* Q15 + Q_new */
+ L_tmp = L_mac_o( L_tmp, exc_fx[i + i_subfr], gain_pit, &Overflow ); /* Q15 + Q_new */
+ L_tmp = L_shl_o( L_tmp, 1, &Overflow ); /* saturation can occur here Q16 + Q_new */
+ exc_fx[i + i_subfr] = round_fx_o( L_tmp, &Overflow ); /* Q_new */
#else
L_tmp = L_shl( L_tmp, 5 );
L_tmp = L_mac( L_tmp, exc_fx[i + i_subfr], gain_pit );
@@ -319,9 +320,9 @@ Word16 encod_tran_fx(
L_tmp = L_shl_o( L_tmp, tmp1_fx, &Overflow ); /* Q16 + Q_exc */
tmp_fx = round_fx_o( L_tmp, &Overflow );
- exc2_fx[i + i_subfr] = add_o( exc2_fx[i + i_subfr], tmp_fx, &Overflow );
+ exc2_fx[i + i_subfr] = add_o( exc2_fx[i + i_subfr], tmp_fx, &Overflow ); /* Q_exc */
move16();
- exc_fx[i + i_subfr] = add_o( exc_fx[i + i_subfr], tmp_fx, &Overflow );
+ exc_fx[i + i_subfr] = add_o( exc_fx[i + i_subfr], tmp_fx, &Overflow ); /* Q_exc */
move16();
#else
L_tmp = L_shl( L_tmp, tmp1_fx ); /* Q16 + Q_exc */
@@ -439,9 +440,9 @@ Word16 encod_tran_fx(
IF( st_fx->Opt_SC_VBR )
{
/* SC-VBR */
- hSC_VBR->prev_ppp_gain_pit_fx = gain_pit;
+ hSC_VBR->prev_ppp_gain_pit_fx = gain_pit; /* Q14 */
move16();
- hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code;
+ hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; /* Q15 */
move16();
}
@@ -450,20 +451,20 @@ Word16 encod_tran_fx(
Word16 encod_tran_ivas_fx(
Encoder_State *st_fx, /* i/o: state structure */
- const Word16 speech_fx[], /* i : input speech */
- const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */
- const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */
- const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */
- const Word16 *res_fx, /* i : residual signal */
- Word16 *syn_fx, /* i/o: core synthesis */
- Word16 *exc_fx, /* i/o: current non-enhanced excitation */
- Word16 *exc2_fx, /* i/o: current enhanced excitation */
- Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe */
- Word16 *voice_factors, /* o : voicing factors */
- Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */
- Word16 tc_subfr, /* i/o: TC subframe classification */
- Word16 position, /* i : maximum of residual signal index */
- Word16 *unbits, /* i/o: number of unused bits */
+ const Word16 speech_fx[], /* i : input speech Q0*/
+ const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/
+ const Word16 Aq_fx[], /* i : 12k8 Lp coefficient Q12*/
+ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy Q8*/
+ const Word16 *res_fx, /* i : residual signal Q_new*/
+ Word16 *syn_fx, /* i/o: core synthesis Q_new*/
+ Word16 *exc_fx, /* i/o: current non-enhanced excitation Q0*/
+ Word16 *exc2_fx, /* i/o: current enhanced excitation Q0*/
+ Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe Q6*/
+ Word16 *voice_factors, /* o : voicing factors Q15*/
+ Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q0*/
+ Word16 tc_subfr, /* i/o: TC subframe classification Q0*/
+ Word16 position, /* i : maximum of residual signal index Q0*/
+ Word16 *unbits, /* i/o: number of unused bits Q0*/
const Word16 shift, /* i : Scaling to get 12 bits */
const Word16 Q_new /* i : Input scaling */
)
@@ -499,6 +500,7 @@ Word16 encod_tran_ivas_fx(
Word32 L_tmp;
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
+ move32();
#endif
BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR;
@@ -534,13 +536,13 @@ Word16 encod_tran_ivas_fx(
/**unbits = 0;move16();*/
Jopt_flag = 0;
move16();
- unbits_ACELP = *unbits;
+ unbits_ACELP = *unbits; /* Q0 */
move16();
*unbits = 0;
move16();
- p_Aw = Aw_fx;
- p_Aq = Aq_fx;
+ p_Aw = Aw_fx; /* Q12 */
+ p_Aq = Aq_fx; /* Q12 */
pt_pitch = pitch_buf_fx;
gain_preQ = 0;
move16();
@@ -559,7 +561,7 @@ Word16 encod_tran_ivas_fx(
* Compute impulse response, h1[], of weighted synthesis filter
*----------------------------------------------------------------*/
- Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR );
+ Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); /* Q_new */
find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq,
res_fx, L_SUBFR, p_Aw, st_fx->preemph_fac, xn, cn, h1 );
@@ -638,7 +640,7 @@ Word16 encod_tran_ivas_fx(
Lgcode = L_shl( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/
gcode16 = round_fx( Lgcode );
#endif
- hLPDmem->tilt_code = est_tilt_ivas_fx( &exc_fx[i_subfr], gain_pit, code, gain_code, &voice_fac, Q_new, L_SUBFR, 0 );
+ hLPDmem->tilt_code = est_tilt_ivas_fx( &exc_fx[i_subfr], gain_pit, code, gain_code, &voice_fac, Q_new, L_SUBFR, 0 ); // Q15
/*-----------------------------------------------------------------*
* Update memory of the weighting filter
*-----------------------------------------------------------------*/
@@ -672,7 +674,7 @@ Word16 encod_tran_ivas_fx(
FOR( i = 0; i < L_SUBFR; i++ )
{
#ifdef BASOP_NOGLOB
- exc2_fx[i + i_subfr] = round_fx_sat( L_shl_sat( L_mult_sat( gain_pit, exc_fx[i + i_subfr] ), 1 ) );
+ exc2_fx[i + i_subfr] = round_fx_sat( L_shl_sat( L_mult_sat( gain_pit, exc_fx[i + i_subfr] ), 1 ) ); /* Q_exc */
#else
exc2_fx[i + i_subfr] = round_fx( L_shl( L_mult( gain_pit, exc_fx[i + i_subfr] ), 1 ) );
#endif
@@ -683,7 +685,7 @@ Word16 encod_tran_ivas_fx(
Gain_pitX2 = shl( gain_pit, 1 );
FOR( i = 0; i < L_SUBFR; i++ )
{
- exc2_fx[i + i_subfr] = mult_r( Gain_pitX2, exc_fx[i + i_subfr] );
+ exc2_fx[i + i_subfr] = mult_r( Gain_pitX2, exc_fx[i + i_subfr] ); /* Q_exc */
}
}
@@ -694,12 +696,12 @@ Word16 encod_tran_ivas_fx(
FOR( i = 0; i < L_SUBFR; i++ )
{
/* code in Q9, gain_pit in Q14 */
- L_tmp = L_mult( gcode16, code[i] );
+ L_tmp = L_mult( gcode16, code[i] ); /* Q10 + Q_new */
#ifdef BASOP_NOGLOB
- L_tmp = L_shl_o( L_tmp, 5, &Overflow );
- L_tmp = L_mac_o( L_tmp, exc_fx[i + i_subfr], gain_pit, &Overflow );
- L_tmp = L_shl_o( L_tmp, 1, &Overflow ); /* saturation can occur here */
- exc_fx[i + i_subfr] = round_fx_o( L_tmp, &Overflow );
+ L_tmp = L_shl_o( L_tmp, 5, &Overflow ); /* Q15 + Q_new */
+ L_tmp = L_mac_o( L_tmp, exc_fx[i + i_subfr], gain_pit, &Overflow ); /* Q15 + Q_new */
+ L_tmp = L_shl_o( L_tmp, 1, &Overflow ); /* saturation can occur here Q16 + Q_new */
+ exc_fx[i + i_subfr] = round_fx_o( L_tmp, &Overflow ); /* Q_new */
#else
L_tmp = L_shl( L_tmp, 5 );
L_tmp = L_mac( L_tmp, exc_fx[i + i_subfr], gain_pit );
@@ -722,9 +724,9 @@ Word16 encod_tran_ivas_fx(
L_tmp = L_shl_o( L_tmp, tmp1_fx, &Overflow ); /* Q16 + Q_exc */
tmp_fx = round_fx_o( L_tmp, &Overflow );
- exc2_fx[i + i_subfr] = add_o( exc2_fx[i + i_subfr], tmp_fx, &Overflow );
+ exc2_fx[i + i_subfr] = add_o( exc2_fx[i + i_subfr], tmp_fx, &Overflow ); /* Q_exc */
move16();
- exc_fx[i + i_subfr] = add_o( exc_fx[i + i_subfr], tmp_fx, &Overflow );
+ exc_fx[i + i_subfr] = add_o( exc_fx[i + i_subfr], tmp_fx, &Overflow ); /* Q_exc */
move16();
#else
L_tmp = L_shl( L_tmp, tmp1_fx ); /* Q16 + Q_exc */
@@ -843,9 +845,9 @@ Word16 encod_tran_ivas_fx(
IF( st_fx->Opt_SC_VBR )
{
/* SC-VBR */
- hSC_VBR->prev_ppp_gain_pit_fx = gain_pit;
+ hSC_VBR->prev_ppp_gain_pit_fx = gain_pit; /* Q14 */
move16();
- hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code;
+ hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; /* Q15 */
move16();
}
diff --git a/lib_enc/find_uv.c b/lib_enc/find_uv.c
index 1d88484d856e7692e685ee0fc9c30e7b8023fe8c..923f7e2f23df518de4887d1e2921e5d59107f928 100644
--- a/lib_enc/find_uv.c
+++ b/lib_enc/find_uv.c
@@ -511,10 +511,9 @@ Word16 find_uv_ivas_fx( /* o : coding typ
test();
test();
test();
- test();
#ifdef BASOP_NOGLOB
if ( ( ( LT_16( add_o( mean_voi3, corr_shift, &Overflow ), add( 22774, mean_voi3_offset ) ) ) && /* normalized correlation low */
- ( LT_16( add_o( st_fx->voicing_fx[2], corr_shift, &Overflow ), 25887 ) ) && /* normalized correlation low on look-ahead - onset detection */
+ /*( LT_16( add_o( st_fx->voicing_fx[2], corr_shift, &Overflow ), 25887 ) ) && */ /* normalized correlation low on look-ahead - onset detection */
( LT_32( ee[0], 397 ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */
( LT_32( ee[1], 397 ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */
( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */
@@ -525,7 +524,7 @@ Word16 find_uv_ivas_fx( /* o : coding typ
|| ( flag_low_relE && ( LE_32( st_fx->old_dE1_fx, 245760 ) ) ) ) /* low relative frame energy (only for SC-VBR) */
#else
if ( ( ( LT_16( add( mean_voi3, corr_shift ), add( 22774, mean_voi3_offset ) ) ) && /* normalized correlation low */
- ( LT_16( add( st_fx->voicing_fx[2], corr_shift ), 25887 ) ) && /* normalized correlation low on look-ahead - onset detection */
+ /* ( LT_16( add( st_fx->voicing_fx[2], corr_shift ), 25887 ) ) && */ /* normalized correlation low on look-ahead - onset detection */
( LT_32( ee[0], 397 ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */
( LT_32( ee[1], 397 ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */
( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */
diff --git a/lib_enc/inov_enc_fx.c b/lib_enc/inov_enc_fx.c
index 725cad9132e818521df6c8cc3e363bcd326227ae..a2567535209f5e6777477e7da66811aa8bc78e3e 100644
--- a/lib_enc/inov_enc_fx.c
+++ b/lib_enc/inov_enc_fx.c
@@ -504,7 +504,7 @@ Word16 inov_encode_ivas_fx(
// Word16 Rw_e = E_ACELP_hh_corr( h2, Rw, L_SUBFR, 3 );
corr_hh_ivas_fx( h2, Rw, &Rw_q, L_subfr ); // Q(Rw) = Q11-2
- E_ACELP_conv_ivas( xn2, h2, cn ); // Qcn = Qxn2
+ E_ACELP_conv_ivas_fx( xn2, h2, cn ); // Qcn = Qxn2
/* dn_e -> Rw_e*Q_xn */
// Scale_sig(Rw, L_SUBFR, sub(5, Rw_e)); //Q9
diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c
index a68f0ad462d15c572d03516c7cbf7264774615ee..c38d03cc480a39d9118397d3f729a24abcc078cf 100644
--- a/lib_enc/ivas_core_enc.c
+++ b/lib_enc/ivas_core_enc.c
@@ -342,7 +342,7 @@ ivas_error ivas_core_enc(
/* ACELP core encoder */
Word16 Q_old_syn_12k8_16k = 0;
move16();
- IF( NE_32( ( error = acelp_core_enc( st, inp_fx[n], /*ener[n],*/ A_fx[n], Aw_fx[n], epsP_fx[n], lsp_new_fx[n], lsp_mid_fx[n], vad_hover_flag[0], attack_flag[n], bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx[n], &Q_old_syn_12k8_16k, pitch_buf_fx[n], &unbits[n], hStereoTD, tdm_lsfQ_PCh_fx, Q_new[n] ) ), IVAS_ERR_OK ) )
+ IF( NE_32( ( error = acelp_core_enc_ivas_fx( st, inp_fx[n], /*ener[n],*/ A_fx[n], Aw_fx[n], epsP_fx[n], lsp_new_fx[n], lsp_mid_fx[n], vad_hover_flag[0], attack_flag[n], bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx[n], &Q_old_syn_12k8_16k, pitch_buf_fx[n], &unbits[n], hStereoTD, tdm_lsfQ_PCh_fx, Q_new[n] ) ), IVAS_ERR_OK ) )
{
return error;
}
diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c
index 6c5abdb139b551c3e46c6d39082755cff48ca558..b41f6e81286a66c6815cfd585ec7862385a8544e 100644
--- a/lib_enc/ivas_core_pre_proc_front.c
+++ b/lib_enc/ivas_core_pre_proc_front.c
@@ -120,8 +120,8 @@ ivas_error pre_proc_front_ivas_fx(
const Word16 tdm_lsp_new_PCh_fx[M], /* i : unq. LSPs of primary channel Q15 */
const Word16 currFlatness_fx, /* i : flatness parameter Q7 */
const Word16 tdm_ratio_idx, /* i : Current Ratio_L index */
- Word32 fr_bands_LR_fx[][2 * NB_BANDS], /* i : energy in frequency bands (fr_bands_LR_fx_q) */
- Word16 fr_bands_LR_fx_q,
+ Word32 fr_bands_LR_fx[][2 * NB_BANDS], /* i : energy in frequency bands (fr_bands_LR_fx_q[]) */
+ Word16 fr_bands_LR_fx_q[CPE_CHANNELS],
const Word16 Etot_LR_fx[], /* i : total energy Left & Right channel Q8*/
Word32 lf_E_LR_fx[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels (lf_E_LR_fx_q) */
Word16 lf_E_LR_fx_q,
@@ -766,10 +766,6 @@ ivas_error pre_proc_front_ivas_fx(
&Etot_fx, st->min_band, st->max_band, st->Bin_E_fx, &st->q_Bin_E, st->Bin_E_old_fx, &st->q_Bin_E_old, PS_fx, &Qfact_PS,
lgBin_E_fx, band_energies_fx, &q_band_energies, fft_buff_fx, fft_buff_fx_q );
- Word16 Q_bands0 = 0, Q_bands1 = 0;
- move16();
- move16();
-
IF( hStereoClassif != NULL )
{
IF( GT_32( sub( st->lp_speech_fx, Etot_fx ), 25 << Q8 ) ) /*Q8*/
@@ -921,30 +917,38 @@ ivas_error pre_proc_front_ivas_fx(
test();
IF( lr_vad_enabled && st->idchan == 0 )
{
- Scale_sig32( hCPE->hFrontVad[0]->hNoiseEst->bckr_fx, NB_BANDS, sub( add( fr_bands_LR_fx_q, Q_SCALE ), hCPE->hFrontVad[0]->hNoiseEst->q_bckr ) );
- hCPE->hFrontVad[0]->hNoiseEst->q_bckr = add( fr_bands_LR_fx_q, Q_SCALE );
+ scale = add( L_norm_arr( hCPE->hFrontVad[0]->hNoiseEst->bckr_fx, NB_BANDS ), hCPE->hFrontVad[0]->hNoiseEst->q_bckr );
+ scale = s_min( scale, add( L_norm_arr( hCPE->hFrontVad[1]->hNoiseEst->bckr_fx, NB_BANDS ), hCPE->hFrontVad[1]->hNoiseEst->q_bckr ) );
+ scale = s_min( scale, add( L_norm_arr( fr_bands_LR_fx[0], 2 * NB_BANDS ), fr_bands_LR_fx_q[0] ) );
+ scale = s_min( scale, add( L_norm_arr( fr_bands_LR_fx[1], 2 * NB_BANDS ), fr_bands_LR_fx_q[1] ) );
+
+ scale_sig32( fr_bands_LR_fx[0], 2 * NB_BANDS, sub( scale, fr_bands_LR_fx_q[0] ) );
+ fr_bands_LR_fx_q[0] = scale;
move16();
- Scale_sig32( hCPE->hFrontVad[1]->hNoiseEst->bckr_fx, NB_BANDS, sub( add( fr_bands_LR_fx_q, Q_SCALE ), hCPE->hFrontVad[1]->hNoiseEst->q_bckr ) );
- hCPE->hFrontVad[1]->hNoiseEst->q_bckr = hCPE->hFrontVad[0]->hNoiseEst->q_bckr;
+ scale_sig32( fr_bands_LR_fx[1], 2 * NB_BANDS, sub( scale, fr_bands_LR_fx_q[1] ) );
+ fr_bands_LR_fx_q[1] = scale;
move16();
- Word32 Le_min_scaled0, Le_min_scaled1;
- Le_min_scaled0 = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( Q_bands0, QSCALE ) ) ), 1 ), 1 );
- Le_min_scaled1 = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( Q_bands1, QSCALE ) ) ), 1 ), 1 );
+ scale_sig32( hCPE->hFrontVad[0]->hNoiseEst->bckr_fx, NB_BANDS, sub( scale, hCPE->hFrontVad[0]->hNoiseEst->q_bckr ) );
+ hCPE->hFrontVad[0]->hNoiseEst->q_bckr = scale;
+ move16();
+ scale_sig32( hCPE->hFrontVad[1]->hNoiseEst->bckr_fx, NB_BANDS, sub( scale, hCPE->hFrontVad[1]->hNoiseEst->q_bckr ) );
+ hCPE->hFrontVad[1]->hNoiseEst->q_bckr = scale;
+ move16();
- noise_est_down_fx( fr_bands_LR_fx[0], hCPE->hFrontVad[0]->hNoiseEst->bckr_fx, tmpN_LR_fx[0], tmpE_LR_fx[0], st->min_band, st->max_band, &hCPE->hFrontVad[0]->hNoiseEst->totalNoise_fx, Etot_LR_fx[0], &hCPE->hFrontVad[0]->hNoiseEst->Etot_last_fx, &hCPE->hFrontVad[0]->hNoiseEst->Etot_v_h2_fx, Q_bands0, Le_min_scaled0 );
- noise_est_down_fx( fr_bands_LR_fx[1], hCPE->hFrontVad[1]->hNoiseEst->bckr_fx, tmpN_LR_fx[1], tmpE_LR_fx[1], st->min_band, st->max_band, &hCPE->hFrontVad[1]->hNoiseEst->totalNoise_fx, Etot_LR_fx[1], &hCPE->hFrontVad[1]->hNoiseEst->Etot_last_fx, &hCPE->hFrontVad[1]->hNoiseEst->Etot_v_h2_fx, Q_bands1, Le_min_scaled1 );
+ noise_est_down_ivas_fx( fr_bands_LR_fx[0], fr_bands_LR_fx_q[0], hCPE->hFrontVad[0]->hNoiseEst->bckr_fx, tmpN_LR_fx[0], tmpE_LR_fx[0], st->min_band, st->max_band, &hCPE->hFrontVad[0]->hNoiseEst->totalNoise_fx, Etot_LR_fx[0], &hCPE->hFrontVad[0]->hNoiseEst->Etot_last_fx, &hCPE->hFrontVad[0]->hNoiseEst->Etot_v_h2_fx );
+ noise_est_down_ivas_fx( fr_bands_LR_fx[1], fr_bands_LR_fx_q[1], hCPE->hFrontVad[1]->hNoiseEst->bckr_fx, tmpN_LR_fx[1], tmpE_LR_fx[1], st->min_band, st->max_band, &hCPE->hFrontVad[1]->hNoiseEst->totalNoise_fx, Etot_LR_fx[1], &hCPE->hFrontVad[1]->hNoiseEst->Etot_last_fx, &hCPE->hFrontVad[1]->hNoiseEst->Etot_v_h2_fx );
- corr_shiftL_fx = correlation_shift_fx( hCPE->hFrontVad[0]->hNoiseEst->totalNoise_fx );
- corr_shiftR_fx = correlation_shift_fx( hCPE->hFrontVad[1]->hNoiseEst->totalNoise_fx );
- q_tmpN_LR[0] = q_tmpE_LR[0] = add( Q_bands0, QSCALE );
+ q_tmpN_LR[0] = q_tmpE_LR[0] = scale;
move16();
move16();
- q_tmpN_LR[1] = q_tmpE_LR[1] = add( Q_bands1, QSCALE );
+ q_tmpN_LR[1] = q_tmpE_LR[1] = scale;
move16();
move16();
- }
+ corr_shiftL_fx = correlation_shift_fx( hCPE->hFrontVad[0]->hNoiseEst->totalNoise_fx );
+ corr_shiftR_fx = correlation_shift_fx( hCPE->hFrontVad[1]->hNoiseEst->totalNoise_fx );
+ }
*relE_fx = sub( Etot_fx, st->lp_speech_fx );
move16();
@@ -1226,8 +1230,8 @@ ivas_error pre_proc_front_ivas_fx(
old_pitch1 = st->pitch[1];
move16();
- Word16 shift1 = getScaleFactor16( old_wsp_fx, L_WSP_MEM );
- Word16 shift2 = getScaleFactor16( wsp_fx, L_WSP - L_WSP_MEM );
+ Word16 shift1 = norm_arr( old_wsp_fx, L_WSP_MEM );
+ Word16 shift2 = norm_arr( wsp_fx, L_WSP - L_WSP_MEM );
maximum_abs_16_fx( old_wsp_fx, L_WSP_MEM, &shift );
if ( !shift )
{
@@ -1241,15 +1245,17 @@ ivas_error pre_proc_front_ivas_fx(
move16();
}
shift = s_min( add( *q_old_wsp, shift1 ), add( Q_wsp, shift2 ) );
- Scale_sig( old_wsp_fx, L_WSP_MEM, sub( shift, *q_old_wsp ) );
- Scale_sig( wsp_fx, L_WSP - L_WSP_MEM, sub( shift, Q_wsp ) );
+ shift = s_min( shift, add( norm_arr( st->mem_decim2_fx, 3 ), st->Q_old_wsp2 ) );
+ shift = s_min( shift, add( norm_arr( st->old_wsp2_fx, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ), st->Q_old_wsp2 ) );
+ scale_sig( old_wsp_fx, L_WSP_MEM, sub( shift, *q_old_wsp ) );
+ scale_sig( wsp_fx, L_WSP - L_WSP_MEM, sub( shift, Q_wsp ) );
*q_old_wsp = shift;
move16();
Q_wsp = shift;
move16();
- Scale_sig( st->mem_decim2_fx, 3, sub( Q_wsp, st->Q_old_wsp2 ) ); // Q( mem_decim ) = Q( old_wsp2 )
- Scale_sig( st->old_wsp2_fx, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM, sub( Q_wsp, st->Q_old_wsp2 ) );
+ scale_sig( st->mem_decim2_fx, 3, sub( Q_wsp, st->Q_old_wsp2 ) ); // Q( mem_decim ) = Q( old_wsp2 )
+ scale_sig( st->old_wsp2_fx, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM, sub( Q_wsp, st->Q_old_wsp2 ) );
st->Q_old_wsp2 = Q_wsp;
move16();
@@ -1259,91 +1265,144 @@ ivas_error pre_proc_front_ivas_fx(
st->old_pitch_la = st->pitch[2];
move16();
+ /*Scaling to avoid 0 values*/
+ shift = L_norm_arr( st->hNoiseEst->enrO_fx, NB_BANDS );
+ scale_sig32( st->hNoiseEst->enrO_fx, NB_BANDS, shift );
+ st->hNoiseEst->q_enrO = add( st->hNoiseEst->q_enrO, shift );
+ move16();
+
test();
IF( lr_vad_enabled && st->idchan == 0 )
{
- FOR( i = 0; i < 2; i++ )
+ /*Scaling to avoid 0 values*/
+ FOR( Word16 j = 0; j < 2; j++ )
{
- shift = getScaleFactor32( tmpN_LR_fx[i], NB_BANDS );
- scale_sig32( tmpN_LR_fx[i], NB_BANDS, shift );
- q_tmpN_LR[i] = add( q_tmpN_LR[i], shift );
- move16();
-
- shift = getScaleFactor32( tmpE_LR_fx[i], NB_BANDS );
- scale_sig32( tmpE_LR_fx[i], NB_BANDS, shift );
- q_tmpE_LR[i] = add( q_tmpE_LR[i], shift );
+ shift = L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->enrO_fx, NB_BANDS );
+ scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->enrO_fx, NB_BANDS, shift );
+ hCPE->hFrontVad[j]->hNoiseEst->q_enrO = add( hCPE->hFrontVad[j]->hNoiseEst->q_enrO, shift );
move16();
}
}
- shift = getScaleFactor32( tmpN_fx, NB_BANDS );
- scale_sig32( tmpN_fx, NB_BANDS, shift );
- q_tmpN = add( q_tmpN, shift );
- shift = getScaleFactor32( tmpE_fx, NB_BANDS );
- scale_sig32( tmpE_fx, NB_BANDS, shift );
- q_tmpE = add( q_tmpE, shift );
-
- shift = getScaleFactor32( lf_E_fx, 2 * VOIC_BINS );
- scale_sig32( lf_E_fx, 2 * VOIC_BINS, shift );
- q_lf_E_fx = add( q_lf_E_fx, shift );
- shift = sub( getScaleFactor16( old_wsp_fx, L_WSP ), 3 );
- Scale_sig( old_wsp_fx, L_WSP, shift );
+ shift = sub( norm_arr( old_wsp_fx, L_WSP ), 3 );
+ scale_sig( old_wsp_fx, L_WSP, shift );
*q_old_wsp = add( *q_old_wsp, shift );
move16();
Q_wsp = *q_old_wsp;
move16();
+
Word16 q_fr_bands = Q30;
move16();
- q_fr_bands = s_min( q_fr_bands, q_tmpN );
- q_fr_bands = s_min( q_fr_bands, q_tmpE );
- q_fr_bands = s_min( q_fr_bands, sub( fr_bands_fx_q, 4 ) /* needs 4 gaurd bits for summation */ );
- q_fr_bands = s_min( q_fr_bands, st->hNoiseEst->q_bckr );
- q_fr_bands = s_min( q_fr_bands, st->hNoiseEst->fr_bands_fx_q );
- q_fr_bands = s_min( q_fr_bands, st->hNoiseEst->ave_enr_q );
- q_fr_bands = s_min( q_fr_bands, add( q_lf_E_fx, 2 ) );
+
+ shift = L_norm_arr( tmpN_fx, NB_BANDS );
+ q_fr_bands = s_min( q_fr_bands, add( q_tmpN, shift ) );
+ shift = L_norm_arr( tmpE_fx, NB_BANDS );
+ q_fr_bands = s_min( q_fr_bands, add( q_tmpE, shift ) );
+ shift = L_norm_arr( fr_bands_fx, 2 * NB_BANDS );
+ q_fr_bands = s_min( q_fr_bands, sub( add( fr_bands_fx_q, shift ), 4 ) /* needs 4 gaurd bits for summation */ );
+ shift = L_norm_arr( st->hNoiseEst->bckr_fx, NB_BANDS );
+ q_fr_bands = s_min( q_fr_bands, add( st->hNoiseEst->q_bckr, shift ) );
+ shift = s_min( L_norm_arr( st->hNoiseEst->fr_bands1_fx, NB_BANDS ), L_norm_arr( st->hNoiseEst->fr_bands2_fx, NB_BANDS ) );
+ q_fr_bands = s_min( q_fr_bands, add( st->hNoiseEst->fr_bands_fx_q, shift ) );
+ shift = s_min( L_norm_arr( st->hNoiseEst->ave_enr_fx, NB_BANDS ), L_norm_arr( st->hNoiseEst->ave_enr2_fx, NB_BANDS ) );
+ q_fr_bands = s_min( q_fr_bands, add( st->hNoiseEst->ave_enr_q, shift ) );
+ shift = L_norm_arr( lf_E_fx, 2 * VOIC_BINS );
+ q_fr_bands = s_min( q_fr_bands, add( add( q_lf_E_fx, shift ), 2 ) );
test();
IF( lr_vad_enabled && st->idchan == 0 )
{
+ shift = s_min( L_norm_arr( lf_E_LR_fx[0], 2 * VOIC_BINS ), L_norm_arr( lf_E_LR_fx[1], 2 * VOIC_BINS ) );
+ q_fr_bands = s_min( q_fr_bands, add( add( lf_E_LR_fx_q, shift ), 2 ) );
FOR( Word16 j = 0; j < 2; j++ )
{
- q_fr_bands = s_min( q_fr_bands, add( lf_E_LR_fx_q, 2 ) );
- q_fr_bands = s_min( q_fr_bands, q_tmpN_LR[j] );
- q_fr_bands = s_min( q_fr_bands, q_tmpE_LR[j] );
- q_fr_bands = s_min( q_fr_bands, fr_bands_LR_fx_q );
- q_fr_bands = s_min( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->q_bckr );
- q_fr_bands = s_min( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q );
- q_fr_bands = s_min( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q );
+ shift = L_norm_arr( fr_bands_LR_fx[j], 2 * NB_BANDS );
+ q_fr_bands = s_min( q_fr_bands, add( fr_bands_LR_fx_q[j], shift ) );
+ shift = L_norm_arr( tmpN_LR_fx[j], NB_BANDS );
+ q_fr_bands = s_min( q_fr_bands, add( q_tmpN_LR[j], shift ) );
+ shift = L_norm_arr( tmpE_LR_fx[j], NB_BANDS );
+ q_fr_bands = s_min( q_fr_bands, add( q_tmpE_LR[j], shift ) );
+ shift = L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->bckr_fx, NB_BANDS );
+ q_fr_bands = s_min( q_fr_bands, add( hCPE->hFrontVad[j]->hNoiseEst->q_bckr, shift ) );
+ shift = s_min( L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->fr_bands1_fx, NB_BANDS ), L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->fr_bands2_fx, NB_BANDS ) );
+ q_fr_bands = s_min( q_fr_bands, add( hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q, shift ) );
+ shift = s_min( L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->ave_enr_fx, NB_BANDS ), L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->ave_enr2_fx, NB_BANDS ) );
+ q_fr_bands = s_min( q_fr_bands, add( hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q, shift ) );
}
}
- Word16 q_inp_12k8 = *Q_new; // inp_12k8_fx
- move16();
- scale_sig32( lf_E_fx, 2 * VOIC_BINS, sub( sub( q_fr_bands, 2 ), q_lf_E_fx ) );
- q_lf_E_fx = sub( q_fr_bands, 2 );
scale_sig32( tmpN_fx, NB_BANDS, sub( q_fr_bands, q_tmpN ) );
q_tmpN = q_fr_bands;
+ move16();
scale_sig32( tmpE_fx, NB_BANDS, sub( q_fr_bands, q_tmpE ) );
q_tmpE = q_fr_bands;
+ move16();
+
+ scale_sig32( fr_bands_fx, 2 * NB_BANDS, sub( q_fr_bands, fr_bands_fx_q ) );
+ fr_bands_fx_q = q_fr_bands;
+ move16();
+
+ scale_sig32( st->hNoiseEst->bckr_fx, NB_BANDS, sub( q_fr_bands, st->hNoiseEst->q_bckr ) );
+ st->hNoiseEst->q_bckr = q_fr_bands;
+ move16();
+
+ scale_sig32( st->hNoiseEst->fr_bands1_fx, NB_BANDS, sub( q_fr_bands, st->hNoiseEst->fr_bands_fx_q ) );
+ scale_sig32( st->hNoiseEst->fr_bands2_fx, NB_BANDS, sub( q_fr_bands, st->hNoiseEst->fr_bands_fx_q ) );
+ st->hNoiseEst->fr_bands_fx_q = q_fr_bands;
+ move16();
+
+ scale_sig32( st->hNoiseEst->ave_enr_fx, NB_BANDS, sub( q_fr_bands, st->hNoiseEst->ave_enr_q ) );
+ scale_sig32( st->hNoiseEst->ave_enr2_fx, NB_BANDS, sub( q_fr_bands, st->hNoiseEst->ave_enr_q ) );
+ st->hNoiseEst->ave_enr_q = q_fr_bands;
+ move16();
+
+ scale_sig32( lf_E_fx, 2 * VOIC_BINS, sub( sub( q_fr_bands, 2 ), q_lf_E_fx ) );
+ q_lf_E_fx = sub( q_fr_bands, 2 );
test();
IF( lr_vad_enabled && st->idchan == 0 )
{
- FOR( i = 0; i < 2; i++ )
+ FOR( Word16 j = 0; j < 2; j++ )
{
- scale_sig32( tmpN_LR_fx[i], NB_BANDS, sub( q_fr_bands, q_tmpN_LR[i] ) );
- q_tmpN_LR[i] = q_fr_bands;
+ scale_sig32( lf_E_LR_fx[j], 2 * VOIC_BINS, sub( sub( q_fr_bands, 2 ), lf_E_LR_fx_q ) );
+ scale_sig32( fr_bands_LR_fx[j], 2 * NB_BANDS, sub( q_fr_bands, fr_bands_LR_fx_q[j] ) );
+
+ scale_sig32( tmpN_LR_fx[j], NB_BANDS, sub( q_fr_bands, q_tmpN_LR[j] ) );
+ q_tmpN_LR[j] = q_fr_bands;
+ move16();
+
+ scale_sig32( tmpE_LR_fx[j], NB_BANDS, sub( q_fr_bands, q_tmpE_LR[j] ) );
+ q_tmpE_LR[j] = q_fr_bands;
+ move16();
+
+ scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->bckr_fx, NB_BANDS, sub( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->q_bckr ) );
+ hCPE->hFrontVad[j]->hNoiseEst->q_bckr = q_fr_bands;
move16();
- scale_sig32( tmpE_LR_fx[i], NB_BANDS, sub( q_fr_bands, q_tmpE_LR[i] ) );
- q_tmpE_LR[i] = q_fr_bands;
+ scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->fr_bands1_fx, NB_BANDS, sub( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q ) );
+ scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->fr_bands2_fx, NB_BANDS, sub( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q ) );
+ hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q = q_fr_bands;
+ move16();
+
+ FOR( Word16 k = 0; k < NB_BANDS; k++ )
+ {
+ hCPE->hFrontVad[j]->hNoiseEst->fr_bands1_fx[k] = L_max( 1, hCPE->hFrontVad[j]->hNoiseEst->fr_bands1_fx[k] );
+ move32();
+ hCPE->hFrontVad[j]->hNoiseEst->fr_bands2_fx[k] = L_max( 1, hCPE->hFrontVad[j]->hNoiseEst->fr_bands2_fx[k] );
+ move32();
+ }
+
+ scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->ave_enr_fx, NB_BANDS, sub( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q ) );
+ scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->ave_enr2_fx, NB_BANDS, sub( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q ) );
+ hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q = q_fr_bands;
+ move16();
+ fr_bands_LR_fx_q[j] = q_fr_bands;
move16();
}
+ lf_E_LR_fx_q = q_fr_bands;
+ move16();
}
- scale_sig32( fr_bands_fx, 2 * NB_BANDS, sub( q_fr_bands, fr_bands_fx_q ) );
- fr_bands_fx_q = q_fr_bands;
- move16();
Copy_Scale_sig_32_16( st->Bin_E_fx, st->lgBin_E_fx, L_FFT / 2, sub( Q7, st->q_Bin_E ) );
/* Detection of very short stable pitch period */
@@ -1383,18 +1442,6 @@ ivas_error pre_proc_front_ivas_fx(
* Update estimated noise energy and voicing cut-off frequency
*-----------------------------------------------------------------*/
- scale_sig32( st->hNoiseEst->bckr_fx, NB_BANDS, sub( q_fr_bands, st->hNoiseEst->q_bckr ) );
- st->hNoiseEst->q_bckr = q_fr_bands;
- move16();
- scale_sig32( st->hNoiseEst->fr_bands1_fx, NB_BANDS, sub( q_fr_bands, st->hNoiseEst->fr_bands_fx_q ) );
- scale_sig32( st->hNoiseEst->fr_bands2_fx, NB_BANDS, sub( q_fr_bands, st->hNoiseEst->fr_bands_fx_q ) );
- st->hNoiseEst->fr_bands_fx_q = q_fr_bands;
- move16();
- scale_sig32( st->hNoiseEst->ave_enr_fx, NB_BANDS, sub( q_fr_bands, st->hNoiseEst->ave_enr_q ) );
- scale_sig32( st->hNoiseEst->ave_enr2_fx, NB_BANDS, sub( q_fr_bands, st->hNoiseEst->ave_enr_q ) );
- st->hNoiseEst->ave_enr_q = q_fr_bands;
- move16();
-
FOR( Word16 k = 0; k < NB_BANDS; k++ )
{
fr_bands_fx[k] = L_max( 1, fr_bands_fx[k] );
@@ -1404,60 +1451,9 @@ ivas_error pre_proc_front_ivas_fx(
noise_est_ivas_fx( st, old_pitch1, tmpN_fx, epsP_h, epsP_l, Etot_fx, *relE_fx, corr_shift_fx, tmpE_fx, fr_bands_fx, cor_map_sum_fx, &ncharX_fx, &sp_div_fx, &q_sp_div,
&non_staX_fx, loc_harm, lf_E_fx, &st->hNoiseEst->harm_cor_cnt, st->hNoiseEst->Etot_l_lp_fx, st->hNoiseEst->Etot_v_h2_fx, &st->hNoiseEst->bg_cnt, st->lgBin_E_fx, sub( q_fr_bands, QSCALE ), L_shl( E_MIN_IVAS_FX, sub( q_fr_bands, Q19 ) ), &dummy_fx, S_map_fx, hStereoClassif, NULL, st->ini_frame );
- /*Scaling to avoid 0 values*/
- shift = s_min( L_norm_arr( st->hNoiseEst->fr_bands1_fx, NB_BANDS ), L_norm_arr( st->hNoiseEst->fr_bands2_fx, NB_BANDS ) );
- scale_sig32( st->hNoiseEst->fr_bands1_fx, NB_BANDS, shift );
- scale_sig32( st->hNoiseEst->fr_bands2_fx, NB_BANDS, shift );
- st->hNoiseEst->fr_bands_fx_q = add( st->hNoiseEst->fr_bands_fx_q, shift );
- move16();
- shift = s_min( L_norm_arr( st->hNoiseEst->ave_enr_fx, NB_BANDS ), L_norm_arr( st->hNoiseEst->ave_enr2_fx, NB_BANDS ) );
- scale_sig32( st->hNoiseEst->ave_enr_fx, NB_BANDS, shift );
- scale_sig32( st->hNoiseEst->ave_enr2_fx, NB_BANDS, shift );
- st->hNoiseEst->ave_enr_q = add( st->hNoiseEst->ave_enr_q, shift );
- move16();
- shift = L_norm_arr( st->hNoiseEst->bckr_fx, NB_BANDS );
- scale_sig32( st->hNoiseEst->bckr_fx, NB_BANDS, shift );
- st->hNoiseEst->q_bckr = add( st->hNoiseEst->q_bckr, shift );
- move16();
- shift = L_norm_arr( st->hNoiseEst->enrO_fx, NB_BANDS );
- scale_sig32( st->hNoiseEst->enrO_fx, NB_BANDS, shift );
- st->hNoiseEst->q_enrO = add( st->hNoiseEst->q_enrO, shift );
- move16();
-
test();
IF( lr_vad_enabled && st->idchan == 0 )
{
- FOR( Word16 j = 0; j < 2; j++ )
- {
- scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->bckr_fx, NB_BANDS, sub( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->q_bckr ) );
- hCPE->hFrontVad[j]->hNoiseEst->q_bckr = q_fr_bands;
- move16();
- scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->fr_bands1_fx, NB_BANDS, sub( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q ) );
- scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->fr_bands2_fx, NB_BANDS, sub( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q ) );
- hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q = q_fr_bands;
- move16();
- scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->ave_enr_fx, NB_BANDS, sub( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q ) );
- scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->ave_enr2_fx, NB_BANDS, sub( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q ) );
- hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q = q_fr_bands;
- move16();
- shift = L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->bckr_fx, NB_BANDS );
- scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->bckr_fx, NB_BANDS, shift );
- hCPE->hFrontVad[j]->hNoiseEst->q_bckr = add( hCPE->hFrontVad[j]->hNoiseEst->q_bckr, shift );
- move16();
- shift = L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->enrO_fx, NB_BANDS );
- scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->enrO_fx, NB_BANDS, shift );
- hCPE->hFrontVad[j]->hNoiseEst->q_enrO = add( hCPE->hFrontVad[j]->hNoiseEst->q_enrO, shift );
- move16();
-
- FOR( Word16 k = 0; k < NB_BANDS; k++ )
- {
- hCPE->hFrontVad[j]->hNoiseEst->fr_bands1_fx[k] = L_max( 1, hCPE->hFrontVad[j]->hNoiseEst->fr_bands1_fx[k] );
- move32();
- hCPE->hFrontVad[j]->hNoiseEst->fr_bands2_fx[k] = L_max( 1, hCPE->hFrontVad[j]->hNoiseEst->fr_bands2_fx[k] );
- move32();
- }
- }
-
/* Run noise_est for Left and Right channel */
*loc_harmLR_fx = *loc_harm;
noise_est_ivas_fx( st, old_pitch1, tmpN_LR_fx[0], epsP_h, epsP_l, Etot_LR_fx[0], sub( Etot_LR_fx[0], hCPE->hFrontVad[0]->lp_speech_fx ), corr_shiftL_fx, tmpE_LR_fx[0], fr_bands_LR_fx[0], &cor_map_sum_LR_fx[0], &ncharX_LR_fx, &sp_div_LR_fx, &q_sp_div_LR,
@@ -1466,20 +1462,6 @@ ivas_error pre_proc_front_ivas_fx(
/* Note: the index [0] in the last argument is intended, the ini_frame counter is only maintained in the zero-th channel's VAD handle */
noise_est_ivas_fx( st, old_pitch1, tmpN_LR_fx[1], epsP_h, epsP_l, Etot_LR_fx[1], sub( Etot_LR_fx[1], hCPE->hFrontVad[1]->lp_speech_fx ), corr_shiftR_fx, tmpE_LR_fx[1], fr_bands_LR_fx[1], &cor_map_sum_LR_fx[1], &ncharX_LR_fx, &sp_div_LR_fx, &q_sp_div_LR,
&non_staX_LR_fx, loc_harmLR_fx, lf_E_LR_fx[1], &hCPE->hFrontVad[1]->hNoiseEst->harm_cor_cnt, hCPE->hFrontVad[1]->hNoiseEst->Etot_l_lp_fx, hCPE->hFrontVad[1]->hNoiseEst->Etot_v_h2_fx, &hCPE->hFrontVad[1]->hNoiseEst->bg_cnt, st->lgBin_E_fx, sub( q_fr_bands, QSCALE ), L_shl( E_MIN_IVAS_FX, sub( q_fr_bands, Q19 ) ), &dummy_fx, S_map_LR_fx, NULL, hCPE->hFrontVad[1], hCPE->hFrontVad[0]->ini_frame );
-
-
- /*Scaling to avoid 0 values*/
- FOR( Word16 j = 0; j < 2; j++ )
- {
- shift = s_min( L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->fr_bands1_fx, NB_BANDS ), L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->fr_bands2_fx, NB_BANDS ) );
- scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->fr_bands1_fx, NB_BANDS, shift );
- scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->fr_bands2_fx, NB_BANDS, shift );
- hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q = add( hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q, shift );
- shift = s_min( L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->ave_enr_fx, NB_BANDS ), L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->ave_enr2_fx, NB_BANDS ) );
- scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->ave_enr_fx, NB_BANDS, shift );
- scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->ave_enr2_fx, NB_BANDS, shift );
- hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q = add( hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q, shift );
- }
}
/*------------------------------------------------------------------*
@@ -1499,7 +1481,7 @@ ivas_error pre_proc_front_ivas_fx(
find_tilt_ivas_fx( fr_bands_fx, st->hNoiseEst->bckr_fx, ee_fx, st->pitch, st->voicing_fx, lf_E_fx, corr_shift_fx, st->input_bwidth, st->max_band, hp_E_fx, MODE1, q_fr_bands,
&( st->bckr_tilt_lt ), st->Opt_SC_VBR );
- st->coder_type = find_uv_ivas_fx( st, pitch_fr_fx, voicing_fr_fx, inp_12k8_fx, ee_fx, &dE1X_fx, corr_shift_fx, *relE_fx, Etot_fx, hp_E_fx, &flag_spitch, last_core_orig, hStereoClassif, q_inp_12k8, q_fr_bands );
+ st->coder_type = find_uv_ivas_fx( st, pitch_fr_fx, voicing_fr_fx, inp_12k8_fx, ee_fx, &dE1X_fx, corr_shift_fx, *relE_fx, Etot_fx, hp_E_fx, &flag_spitch, last_core_orig, hStereoClassif, *Q_new /*q_inp_12k8*/, q_fr_bands );
Copy_Scale_sig_16_32( st->lgBin_E_fx, st->Bin_E_fx, L_FFT / 2, sub( st->q_Bin_E, Q7 ) );
@@ -1593,10 +1575,10 @@ ivas_error pre_proc_front_ivas_fx(
ivas_long_enr_fx( st, -1, localVAD_HE_SAD, high_lpn_flag, hCPE->hFrontVad, CPE_CHANNELS, localVAD_HE_SAD_LR, Etot_LR_fx );
Copy32( fr_bands_LR_fx[0] + NB_BANDS, hCPE->hFrontVad[0]->hNoiseEst->enrO_fx, NB_BANDS );
- hCPE->hFrontVad[0]->hNoiseEst->q_enrO = fr_bands_LR_fx_q;
+ hCPE->hFrontVad[0]->hNoiseEst->q_enrO = fr_bands_LR_fx_q[0];
move16();
Copy32( fr_bands_LR_fx[1] + NB_BANDS, hCPE->hFrontVad[1]->hNoiseEst->enrO_fx, NB_BANDS );
- hCPE->hFrontVad[1]->hNoiseEst->q_enrO = fr_bands_LR_fx_q;
+ hCPE->hFrontVad[1]->hNoiseEst->q_enrO = fr_bands_LR_fx_q[1];
move16();
}
diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c
index bb3babe74d3bdbff285c174f23f8801d53c3039c..35d23ce31e2f74053b9004afc8fbd7bcf18fa54f 100644
--- a/lib_enc/ivas_cpe_enc.c
+++ b/lib_enc/ivas_cpe_enc.c
@@ -806,7 +806,7 @@ ivas_error ivas_cpe_enc_fx(
error = pre_proc_front_ivas_fx( NULL, hCPE, hCPE->element_brate, nb_bits_metadata, input_frame, n, old_inp_12k8_16fx[n], old_inp_16k_16fx[n],
&ener_fx[n], &relE_fx[n], A_fx[n], Aw_fx[n], epsP_fx[n], &epsP_fx_q[n], lsp_new_fx[n], lsp_mid_fx[n], &vad_hover_flag[n], &attack_flag[n],
realBuffer_fx[n], imagBuffer_fx[n], &q_re_im_buf[n], old_wsp_fx[n], &q_old_wsp, pitch_fr_fx[n], voicing_fr_fx[n], &loc_harm[n], &cor_map_sum_fx[n], &vad_flag_dtx[n], enerBuffer_fx[n], &enerBuffer_fx_exp[n],
- fft_buff_fx[n], &fft_buff_fx_q[n], A_fx[0], lsp_new_fx[0], currFlatness_fx[n], tdm_ratio_idx, fr_bands_fx, q_fr_bands[n], Etot_LR_fx, lf_E_fx, q_lf_E[n], localVAD_HE_SAD,
+ fft_buff_fx[n], &fft_buff_fx_q[n], A_fx[0], lsp_new_fx[0], currFlatness_fx[n], tdm_ratio_idx, fr_bands_fx, q_fr_bands, Etot_LR_fx, lf_E_fx, q_lf_E[n], localVAD_HE_SAD,
band_energies_LR_fx, q_band_energies_LR, 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, 0, 0, ivas_format, st_ivas->hMCT != NULL, ivas_total_brate, &Q_new[n]
#ifdef DEBUG_MODE_INFO
,
diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c
index 607740bfecb0d718dd192a251c2c57ce5a4d199f..1722d665ae2b36f672407a729693b28fc9d0d00b 100644
--- a/lib_enc/ivas_ism_enc.c
+++ b/lib_enc/ivas_ism_enc.c
@@ -237,11 +237,11 @@ ivas_error ivas_ism_enc_fx(
q_old_wsp = Q15;
move16();
-
+ Word16 q_fr_bands[2];
error = pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata[sce_id], input_frame, 0, old_inp_12k8_fx[sce_id][0], old_inp_16k_fx[sce_id][0],
&ener_fx[sce_id][0], &relE_fx[sce_id][0], A_fx[sce_id][0], Aw_fx[sce_id][0], epsP_fx[sce_id][0], &epsP_fx_q[sce_id][0], lsp_new_fx[sce_id][0], lsp_mid_fx[sce_id][0], &vad_hover_flag[sce_id][0], &attack_flag[sce_id][0],
realBuffer_fx[sce_id][0], imagBuffer_fx[sce_id][0], &q_re_im_buf[sce_id], old_wsp_fx[sce_id][0], &q_old_wsp, pitch_fr_fx[sce_id][0], voicing_fr_fx[sce_id][0], &loc_harm[sce_id][0], &cor_map_sum_fx[sce_id][0], &vad_flag_dtx[sce_id][0], enerBuffer_fx[sce_id][0], &enerBuffer_fx_exp[sce_id][0],
- fft_buff_fx[sce_id][0], &fft_buff_fx_q[sce_id][0], A_fx[sce_id][0], lsp_new_fx[sce_id][0], currFlatness_fx[0], 0, fr_bands_fx, 31, Etot_LR_fx, lf_E_fx, 31, localVAD_HE_SAD, NULL, 31, 0, 0, 0, 0, ISM_FORMAT, 0, st_ivas->hEncoderConfig->ivas_total_brate, &Q_new[sce_id][0]
+ fft_buff_fx[sce_id][0], &fft_buff_fx_q[sce_id][0], A_fx[sce_id][0], lsp_new_fx[sce_id][0], currFlatness_fx[0], 0, fr_bands_fx, q_fr_bands, Etot_LR_fx, lf_E_fx, 31, localVAD_HE_SAD, NULL, 31, 0, 0, 0, 0, ISM_FORMAT, 0, st_ivas->hEncoderConfig->ivas_total_brate, &Q_new[sce_id][0]
#ifdef DEBUG_MODE_INFO
,
st->id_element
diff --git a/lib_enc/ivas_mdct_core_enc.c b/lib_enc/ivas_mdct_core_enc.c
index 1313ba4f33bfef47235d49d5bdfc84d7f25df203..766892cc4a2f00578a1f3fc9722a55a107adf5cb 100644
--- a/lib_enc/ivas_mdct_core_enc.c
+++ b/lib_enc/ivas_mdct_core_enc.c
@@ -81,15 +81,15 @@ static void enc_prm_pre_mdct_fx(
* Header
*--------------------------------------------------------------------------------*/
- writeTCXMode( st, hBstr, MCT_flag, &nbits_start );
+ writeTCXMode_fx( st, hBstr, MCT_flag, &nbits_start );
/* write last_core for core switching and error concealment */
push_next_indice( hBstr, st->last_core != ACELP_CORE, 1 );
- writeTCXWindowing( hBstr, st->hTcxCfg->tcx_curr_overlap_mode );
+ writeTCXWindowing_fx( hBstr, st->hTcxCfg->tcx_curr_overlap_mode );
IF( EQ_16( st->core, TCX_10_CORE ) )
{
- writeTCXWindowing( hBstr, st->hTcxCfg->tcx_last_overlap_mode );
+ writeTCXWindowing_fx( hBstr, st->hTcxCfg->tcx_last_overlap_mode );
}
IF( st->last_core != ACELP_CORE )
diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c
index 52c899f08009118c9ce9eb584683339d96dde98b..75f1ede13062172a94b34d14f21ab0738638068f 100644
--- a/lib_enc/ivas_sce_enc.c
+++ b/lib_enc/ivas_sce_enc.c
@@ -249,10 +249,11 @@ ivas_error ivas_sce_enc_fx(
q_old_wsp = Q15;
move16();
+ Word16 q_fr_bands[2];
error = pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata, input_frame, 0, old_inp_12k8_fx[0], old_inp_16k_fx[0],
&ener_fx[0], &relE_fx[0], A_fx[0], Aw_fx[0], epsP_fx[0], &epsP_fx_q[0], lsp_new_fx[0], lsp_mid_fx[0], &vad_hover_flag[0], &attack_flag[0],
realBuffer_fx[0], imagBuffer_fx[0], &q_re_im_buf, old_wsp_fx[0], &q_old_wsp, pitch_fr_fx[0], voicing_fr_fx[0], &loc_harm[0], &cor_map_sum_fx[0], &vad_flag_dtx[0], enerBuffer_fx[0], &enerBuffer_fx_exp[0],
- fft_buff_fx[0], &fft_buff_fx_q[0], A_fx[0], lsp_new_fx[0], currFlatness_fx[0], 0, fr_bands_fx, 31, Etot_LR_fx, lf_E_fx, 31, localVAD_HE_SAD, NULL, 31, flag_16k_smc,
+ fft_buff_fx[0], &fft_buff_fx_q[0], A_fx[0], lsp_new_fx[0], currFlatness_fx[0], 0, fr_bands_fx, q_fr_bands, Etot_LR_fx, lf_E_fx, 31, localVAD_HE_SAD, NULL, 31, flag_16k_smc,
st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->force_front_vad : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_dtx_flag : 0, ivas_format, 0, st_ivas->hEncoderConfig->ivas_total_brate, &Q_new[0]
#ifdef DEBUG_MODE_INFO
,
diff --git a/lib_enc/ivas_stereo_ica_enc.c b/lib_enc/ivas_stereo_ica_enc.c
index 3cdf88902dab6b866b623ff6012926b12c89b365..17d98b765dbfc033e0c24669ab8fa213a0213032 100644
--- a/lib_enc/ivas_stereo_ica_enc.c
+++ b/lib_enc/ivas_stereo_ica_enc.c
@@ -481,10 +481,11 @@ static void utilCrossCorr_mod_fx(
}
E2 = sum2_32_exp_fx( buf2, len, &E2_exp, gb ); /* Q31-E2_exp */
- Word32 E1_mul = BASOP_Util_Add_Mant32Exp( E1, E1_exp, hStereoTCA->E1_mem_fx, hStereoTCA->E1_mem_exp, &E1_exp ); /* Q31-E1_exp */
- Word32 E2_mul = BASOP_Util_Add_Mant32Exp( E2, E2_exp, hStereoTCA->E2_mem_fx, hStereoTCA->E2_mem_exp, &E2_exp ); /* Q31-E2_exp */
+ Word16 temp1, temp2;
+ Word32 E1_mul = BASOP_Util_Add_Mant32Exp( E1, E1_exp, hStereoTCA->E1_mem_fx, hStereoTCA->E1_mem_exp, &temp1 ); /* Q31-temp1 */
+ Word32 E2_mul = BASOP_Util_Add_Mant32Exp( E2, E2_exp, hStereoTCA->E2_mem_fx, hStereoTCA->E2_mem_exp, &temp2 ); /* Q31-temp2 */
Word32 sqr_inp = Mpy_32_32( E1_mul, E2_mul );
- Word16 sq_exp = add( E1_exp, E2_exp );
+ Word16 sq_exp = add( temp1, temp2 );
IF( sqr_inp )
{
@@ -1103,8 +1104,8 @@ static void corrStatsEst_fx(
hStereoTCA->delay_0_mem_fx[MAX_DELAYREGLEN - 1] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( hStereoTCA->delay_0_mem_fx[MAX_DELAYREGLEN - 1], 429496730 /* 0.2 in Q31*/ ), hStereoTCA->delay_0_mem_exp, L_mult0( 26214 /* 0.8 in Q15*/, corrLagStats[0] ), Q16, &temp ); /* Q31-temp */
move32();
Word32 inpp = L_abs( BASOP_Util_Add_Mant32Exp( reg_prv_corr_fx, reg_prv_corr_exp, -hStereoTCA->delay_0_mem_fx[0], hStereoTCA->delay_0_mem_exp, &exp ) ); /* Q31-exp */
- inpp = L_shr( inpp, sub( Q31, exp ) ); /* Q0 */
- IF( GT_32( inpp, 25 ) )
+ inpp = L_shl_sat( inpp, sub( exp, 5 ) ); /* Q26 */
+ IF( GT_32( inpp, 1677721600 ) ) // 25 in Q26
{
set32_fx( &( hStereoTCA->delay_0_mem_fx[0] ), hStereoTCA->delay_0_mem_fx[MAX_DELAYREGLEN - 1], MAX_DELAYREGLEN - 1 );
hStereoTCA->delay_0_mem_exp = temp;
@@ -1715,6 +1716,7 @@ void stereo_tca_enc_fx(
scale_sig32( bufChanL_DS_fx, ADDED_MEM_DS, sub( s_min( hStereoTCA->memChan_DS_q, bufChan_q ), hStereoTCA->memChan_DS_q ) ); // s_min( hStereoTCA->memChan_DS_q, bufChan_q )
scale_sig32( bufChanR_DS_fx, ADDED_MEM_DS, sub( s_min( hStereoTCA->memChan_DS_q, bufChan_q ), hStereoTCA->memChan_DS_q ) ); // s_min( hStereoTCA->memChan_DS_q, bufChan_q )
+ scale_sig32( hStereoTCA->memdecim_fx, 12, sub( s_min( hStereoTCA->memChan_DS_q, bufChan_q ), hStereoTCA->memChan_DS_q ) ); // s_min( hStereoTCA->memChan_DS_q, bufChan_q )
bufChan_q = s_min( hStereoTCA->memChan_DS_q, bufChan_q );
q_com = bufChan_q;
@@ -1803,6 +1805,8 @@ void stereo_tca_enc_fx(
{
tempF_fx = 0;
move32();
+ corrEstStage2_exp = 0;
+ move16();
IF( !musicMode )
{
tempLag[0] = s_min( hStereoTCA->corrLagStats[2], hStereoTCA->prevCorrLagStats[2] ); /* Q0 */
@@ -1838,7 +1842,7 @@ void stereo_tca_enc_fx(
utilCrossCorr_fx( ptrChanL_fx, q_com, ptrChanR_fx, q_com, NULL, &tempF1_fx, &tempF1_exp, tempLag, input_frame, 0 );
test();
- IF( GT_32( tempF1_fx, tempF_fx ) || musicMode )
+ IF( ( BASOP_Util_Cmp_Mant32Exp( tempF1_fx, tempF1_exp, tempF_fx, corrEstStage2_exp ) > 0 ) || musicMode )
{
IF( tempS > 0 )
{
diff --git a/lib_enc/ivas_stereo_mdct_stereo_enc.c b/lib_enc/ivas_stereo_mdct_stereo_enc.c
index b0a5f85c4ae41f72696ab498d3f4a5c708a6fe64..4c73ba2e72f9b30f911376a6b6f285dd242152f5 100644
--- a/lib_enc/ivas_stereo_mdct_stereo_enc.c
+++ b/lib_enc/ivas_stereo_mdct_stereo_enc.c
@@ -955,7 +955,7 @@ static Word16 QuantSpecEstimateBits_fx(
stop = 0;
move16();
- sqBits = RCcontextMapping_encode2_estimate_no_mem_s17_LCS( sqQ, length, &lastnz, &nEncoded, nBitsAvailable, &stop, 0, NULL ); /*Q0*/
+ sqBits = RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx( sqQ, length, &lastnz, &nEncoded, nBitsAvailable, &stop, 0, NULL ); /*Q0*/
if ( stop != 0 )
{
@@ -1185,11 +1185,11 @@ static void MsStereoDecision_fx(
bitsBW = 0;
move16();
- RCcontextMapping_encode2_estimate_bandWise_start( quantSpecL, length, nBitsAvailable, ctxL );
- RCcontextMapping_encode2_estimate_bandWise_start( quantSpecR, length, nBitsAvailable, ctxR );
+ RCcontextMapping_encode2_estimate_bandWise_start_fx( quantSpecL, length, nBitsAvailable, ctxL );
+ RCcontextMapping_encode2_estimate_bandWise_start_fx( quantSpecR, length, nBitsAvailable, ctxR );
- bitsBW = add( bitsBW, RCcontextMapping_encode2_estimate_bandWise_start( quantSpecM, length, nBitsAvailable, ctxM ) ); /* Q0 */
- bitsBW = add( bitsBW, RCcontextMapping_encode2_estimate_bandWise_start( quantSpecS, length, nBitsAvailable, ctxS ) ); /* Q0 */
+ bitsBW = add( bitsBW, RCcontextMapping_encode2_estimate_bandWise_start_fx( quantSpecM, length, nBitsAvailable, ctxM ) ); /* Q0 */
+ bitsBW = add( bitsBW, RCcontextMapping_encode2_estimate_bandWise_start_fx( quantSpecS, length, nBitsAvailable, ctxS ) ); /* Q0 */
/*find_max_lastnz(ctxL,ctxR,ctxM,ctxS);*/
@@ -1200,10 +1200,10 @@ static void MsStereoDecision_fx(
const Word16 endline = sfbParam->sfbOffset[sfb + 1];
move16();
- bitsL = RCcontextMapping_encode2_estimate_bandWise( quantSpecL, startline, endline, ctxL );
- bitsR = RCcontextMapping_encode2_estimate_bandWise( quantSpecR, startline, endline, ctxR );
- bitsM = RCcontextMapping_encode2_estimate_bandWise( quantSpecM, startline, endline, ctxM );
- bitsS = RCcontextMapping_encode2_estimate_bandWise( quantSpecS, startline, endline, ctxS );
+ bitsL = RCcontextMapping_encode2_estimate_bandWise_fx( quantSpecL, startline, endline, ctxL );
+ bitsR = RCcontextMapping_encode2_estimate_bandWise_fx( quantSpecR, startline, endline, ctxR );
+ bitsM = RCcontextMapping_encode2_estimate_bandWise_fx( quantSpecM, startline, endline, ctxM );
+ bitsS = RCcontextMapping_encode2_estimate_bandWise_fx( quantSpecS, startline, endline, ctxS );
IF( LE_16( add( bitsM, bitsS ), add( bitsL, bitsR ) ) )
{
diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c
index bd64725e3b97ba80f01846af57683b3e6a7f7fd3..e8a81147a844e71cf9b809d1772a2017861d388e 100644
--- a/lib_enc/ivas_tcx_core_enc.c
+++ b/lib_enc/ivas_tcx_core_enc.c
@@ -347,7 +347,7 @@ void stereo_tcx_core_enc(
*--------------------------------------------------------------------------------*/
/* TCX20/TCX10 and coder type */
- writeTCXMode( st, hBstr, 0, /* MCT_flag */ &nbits_start );
+ writeTCXMode_fx( st, hBstr, 0, /* MCT_flag */ &nbits_start );
/* write last_core for error concealment */
q_ind_val = 0;
@@ -361,10 +361,10 @@ void stereo_tcx_core_enc(
push_next_indice( hBstr, q_ind_val, 1 );
/* write TCX overlap mode (1 bit: full, 2 bits: half or no overlap) */
- writeTCXWindowing( hBstr, st->hTcxCfg->tcx_curr_overlap_mode );
+ writeTCXWindowing_fx( hBstr, st->hTcxCfg->tcx_curr_overlap_mode );
IF( EQ_16( st->core, TCX_10_CORE ) )
{
- writeTCXWindowing( hBstr, st->hTcxCfg->tcx_last_overlap_mode );
+ writeTCXWindowing_fx( hBstr, st->hTcxCfg->tcx_last_overlap_mode );
}
assert( nbits_header == ( hBstr->nb_bits_tot - nbits_start ) );
diff --git a/lib_enc/nois_est_fx.c b/lib_enc/nois_est_fx.c
index b01121f1fae4bdea2452721bb2f8a61eef4c21e9..a52147004c2f8b19f42064d291e990a49da3ed3c 100644
--- a/lib_enc/nois_est_fx.c
+++ b/lib_enc/nois_est_fx.c
@@ -771,8 +771,9 @@ void noise_est_down_ivas_fx(
Word32 totalNoise_temp;
Word32 L_Etot, L_Etot_last, L_Etot_v_h2, L_Etot_v;
Word64 sum;
+ Word16 q_sum;
- e_min = L_shl( 7516193 /* 0.0035f in Q31 */, sub( q_fr_bands, Q31 ) ); // q_fr_bands
+ e_min = L_shl( E_MIN_FXQ31, sub( q_fr_bands, Q31 ) ); // q_fr_bands
L_Etot = L_shl( Etot, 16 ); /*Q24 for later AR1 computations*/
L_Etot_last = L_shl( *Etot_last, 16 );
@@ -789,14 +790,16 @@ void noise_est_down_ivas_fx(
{
sum = W_mac_32_32( sum, bckr[i], 1 ); // q_fr_bands+1
}
- if ( sum == 0 )
+ q_sum = add( q_fr_bands, 1 );
+ IF( sum == 0 )
{
- sum = 1; /* make sure log2_norm_lc does not cause table reading out of bounds */
- move64();
+ sum = W_mult0_32_32( E_MIN_FXQ31, add( sub( max_band, min_band ), 1 ) ); // Q31
+ q_sum = Q31;
+ move16();
}
e_Noise = W_norm( sum );
- totalNoise_temp = W_extract_h( W_shl( sum, e_Noise ) ); // q_fr_bands+e_Noise-31
- e_Noise = sub( 62, add( e_Noise, q_fr_bands ) ); // 31-(q_fr_bands+e_Noise-31)
+ totalNoise_temp = W_extract_h( W_shl( sum, e_Noise ) ); // q_sum+e_Noise-32
+ e_Noise = sub( 63, add( e_Noise, q_sum ) ); // 31-(q_sum+e_Noise-32)
/*totalNoise = 10.0f * (float)log10( *totalNoise );*/
f_Noise = Log2_norm_lc( totalNoise_temp ); // exponent of log => 30-0 = 30
diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h
index 900e4960cf96278a5ffba2aaefb79489d4809b3c..9b41c3974a6d174b605974ebb16f380a6b97eedd 100644
--- a/lib_enc/prot_fx_enc.h
+++ b/lib_enc/prot_fx_enc.h
@@ -46,21 +46,21 @@
*----------------------------------------------------------------------------------*/
ivas_error acelp_core_enc_fx(
Encoder_State *st_fx, /* i/o: encoder state structure */
- const Word16 inp_fx[], /* i : i signal of the current frame */
- const Word32 ener_fx, /* i : residual energy from Levinson-Durbin*/
- Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes*/
- Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes*/
- const Word16 epsP_h_fx[M + 1], /* i : LP prediction errors */
- const Word16 epsP_l_fx[M + 1], /* i : LP prediction errors */
- Word16 lsp_new_fx[M], /* i : LSPs at the end of the frame */
- Word16 lsp_mid_fx[M], /* i : LSPs in the middle of the frame */
- Word16 vad_hover_flag_fx, /* i : VAD hangover flag */
- const Word16 attack_flag, /* i : attack flag (GSC or TC) */
- Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation */
- Word16 *voice_factors_fx, /* o : voicing factors */
- Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */
- Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe */
- Word16 *unbits_fx, /* o : number of unused bits */
+ const Word16 inp_fx[], /* i : input signal of the current frame Q_new*/
+ const Word32 ener_fx, /* i : residual energy from Levinson-Durbin Q6*/
+ Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12*/
+ Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes Q12*/
+ const Word16 epsP_h_fx[M + 1], /* i : LP prediction errors Qx*/
+ const Word16 epsP_l_fx[M + 1], /* i : LP prediction errors Qx*/
+ Word16 lsp_new_fx[M], /* i : LSPs at the end of the frame Q15*/
+ Word16 lsp_mid_fx[M], /* i : LSPs in the middle of the frame Q15*/
+ Word16 vad_hover_flag_fx, /* i : VAD hangover flag Q0*/
+ const Word16 attack_flag, /* i : attack flag (GSC or TC) Q0*/
+ Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation st->prev_Q_bwe_exc*/
+ Word16 *voice_factors_fx, /* o : voicing factors Q15*/
+ Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE q_old_syn*/
+ Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe Q6*/
+ Word16 *unbits_fx, /* o : number of unused bits Q0*/
const Word16 Q_new,
const Word16 shift
#ifdef ADD_LRTD
@@ -88,20 +88,20 @@ void analy_lp_ivas_fx(
Word16 *Q_r /*stores q for ener*/ );
void analy_lp_fx(
- const Word16 speech[], /* i : pointer to the speech frame */
- const Word16 L_frame, /* i : length of the frame */
- const Word16 L_look, /* i : look-ahead */
- Word32 *ener, /* o : residual energy from Levinson-Durbin */
- Word16 A[], /* o : A(z) filter coefficients */
- Word16 epsP_h[], /* o : LP analysis residual energies for each iteration */
- Word16 epsP_l[], /* o : LP analysis residual energies for each iteration */
- Word16 lsp_new[], /* o : current frame LSPs */
- Word16 lsp_mid[], /* o : current mid-frame LSPs */
- Word16 lsp_old[], /* i/o: previous frame unquantized LSPs */
- const Word16 Top[2], /* i : open loop pitch lag */
- const Word16 Tnc[2], /* i : open loop pitch gain */
- const Word32 Core_sr, /* i : Internal core sampling rate */
- const Word16 sec_chan_low_rate, /* i : flag to signal second channel */
+ const Word16 speech[], /* i : pointer to the speech frame Q_new*/
+ const Word16 L_frame, /* i : length of the frame Q0*/
+ const Word16 L_look, /* i : look-ahead Q0*/
+ Word32 *ener, /* o : residual energy from Levinson-Durbin Q_r*/
+ Word16 A[], /* o : A(z) filter coefficients Q14*/
+ Word16 epsP_h[], /* o : LP analysis residual energies for each iteration Q_r*/
+ Word16 epsP_l[], /* o : LP analysis residual energies for each iteration Q_r*/
+ Word16 lsp_new[], /* o : current frame LSPs Q15*/
+ Word16 lsp_mid[], /* o : current mid-frame LSPs Q15*/
+ Word16 lsp_old[], /* i/o: previous frame unquantized LSPs Q15*/
+ const Word16 Top[2], /* i : open loop pitch lag Q0*/
+ const Word16 Tnc[2], /* i : open loop pitch gain Q15*/
+ const Word32 Core_sr, /* i : Internal core sampling rate Q0*/
+ const Word16 sec_chan_low_rate, /* i : flag to signal second channel Q0*/
Word16 Q_new,
Word16 *Q_r );
@@ -811,14 +811,14 @@ Word16 wb_vad_ivas_fx(
Word16 lp_noise /* i : long term noise energy */
);
-Word32 construct_snr_thresh_fx( Word16 sp_center[], /*(i) spectral center*/
- Word32 snr_flux, /*(i) snr flux*/
- Word32 lt_snr, /*(i) long time time domain snr*/
- Word32 l_snr, /*(i) long time frequency domain snr*/
- Word32 continuous_speech_num, /*(i) amount of continuous speech frames*/
- Word16 continuous_noise_num, /*(i) amount of continuous noise frames*/
- Word32 fg_energy_est_start, /*(i) whether if estimated energy*/
- Word16 bw_index /*(i) band width index*/
+Word32 construct_snr_thresh_fx( Word16 sp_center[], /*(i) spectral center Q10*/
+ Word32 snr_flux, /*(i) snr flux Q25*/
+ Word32 lt_snr, /*(i) long time time domain snr Q25*/
+ Word32 l_snr, /*(i) long time frequency domain snr Q25*/
+ Word32 continuous_speech_num, /*(i) amount of continuous speech frames Q0*/
+ Word16 continuous_noise_num, /*(i) amount of continuous noise frames Q0*/
+ Word32 fg_energy_est_start, /*(i) whether if estimated energy Q0*/
+ Word16 bw_index /*(i) band width index Q0*/
);
void sc_vbr_enc_init_fx(
@@ -1680,7 +1680,13 @@ void subband_FFT_fx(
Word32 Offset, /*(i) offset of the CLDFB*/
Word16 *fftoQ /*(o) the Scaling */
);
-Word16 E_ACELP_toeplitz_mul_fx( const Word16 R[], const Word16 c[], Word16 d[], const Word16 L_subfr, const Word16 highrate );
+Word16 E_ACELP_toeplitz_mul_fx(
+ const Word16 R[], /* Q9 */
+ const Word16 c[], /* Qx */
+ Word16 d[], /* exp(j) */
+ const Word16 L_subfr, /* Q0 */
+ const Word16 highrate /* Q0 */
+);
Word16 E_ACELP_code43bit_fx( const Word16 code[], UWord32 *ps, Word16 *p, UWord16 idxs[] );
void tc_classif_enc_fx(
const Word16 Q_new, /* i : scaling factor */
@@ -1843,74 +1849,85 @@ void Es_pred_enc_fx(
void encod_nelp_fx(
Encoder_State *st_fx, /* i/o: state structure */
- const Word16 *speech_fx, /* i : i speech */
- const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */
- const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */
- Word16 *res_fx, /* o : residual signal */
- Word16 *synth_fx, /* o : core synthesis */
- Word16 *tmp_noise_fx, /* o : long-term noise energy */
- Word16 *exc_fx, /* i/o: current non-enhanced excitation */
- Word16 *exc2_fx, /* i/o: current enhanced excitation */
- Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */
- Word16 *voice_factors_fx, /* o : voicing factors */
- Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */
+ const Word16 *speech_fx, /* i : input speech Q_new-1*/
+ const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/
+ const Word16 Aq_fx[], /* i : 12k8 Lp coefficient Q12*/
+ Word16 *res_fx, /* o : residual signal Q_new*/
+ Word16 *synth_fx, /* o : core synthesis Q_new*/
+ Word16 *tmp_noise_fx, /* o : long-term noise energy Q0*/
+ Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/
+ Word16 *exc2_fx, /* i/o: current enhanced excitation Q_new*/
+ Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/
+ Word16 *voice_factors_fx, /* o : voicing factors Q15*/
+ Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_new*/
Word16 Q_new,
Word16 shift
);
void encod_nelp_ivas_fx(
- Encoder_State *st_fx, /* i/o: state structure */
- const Word16 *speech_fx, /* i : input speech */
- const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */
- const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */
- Word16 *res_fx, /* o : residual signal */
- Word16 *synth_fx, /* o : core synthesis */
- Word16 *tmp_noise_fx, /* o : long-term noise energy */
- Word16 *exc_fx, /* i/o: current non-enhanced excitation */
- Word16 *exc2_fx, /* i/o: current enhanced excitation */
- Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */
- Word16 *voice_factors_fx, /* o : voicing factors */
- Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */
+ Encoder_State *st_fx, /* i/o: state structure */
+ const Word16 *speech_fx,
+ /* i : input speech */ /* Q_new-1 */
+ const Word16 Aw_fx[],
+ /* i : weighted A(z) unquantized for subframes */ /*exp(norm_s(Aw_fx[0])+1)*/
+ const Word16 Aq_fx[],
+ /* i : 12k8 Lp coefficient */ /*exp(norm_s(Aw_fx[0])+1)*/
+ Word16 *res_fx,
+ /* o : residual signal */ /* Q_new */
+ Word16 *synth_fx,
+ /* o : core synthesis */ /* Q_new */
+ Word16 *tmp_noise_fx,
+ /* o : long-term noise energy */ /* Q8 */
+ Word16 *exc_fx,
+ /* i/o: current non-enhanced excitation */ /* Q_new */
+ Word16 *exc2_fx,
+ /* i/o: current enhanced excitation */ /* Q_new */
+ Word16 *pitch_buf_fx,
+ /* o : floating pitch values for each subframe */ /* Q6 */
+ Word16 *voice_factors_fx,
+ /* o : voicing factors */ /* Q15 */
+ Word16 *bwe_exc_fx,
+ /* o : excitation for SWB TBE */ /* Q_new */
Word16 Q_new,
Word16 shift );
Word16 encod_tran_fx(
- Encoder_State *st_fx, /* i/o: state structure */
- const Word16 speech_fx[], /* i : i speech */
- const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */
- const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */
- const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */
- const Word16 *res_fx, /* i : residual signal */
- Word16 *syn_fx, /* i/o: core synthesis */
- Word16 *exc_fx, /* i/o: current non-enhanced excitation */
- Word16 *exc2_fx, /* i/o: current enhanced excitation */
- Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe */
- Word16 *voice_factors, /* o : voicing factors */
- Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */
- Word16 tc_subfr, /* i/o: TC subframe classification */
- Word16 position, /* i : maximum of residual signal index */
- Word16 *unbits, /* i/o: number of unused bits */
- const Word16 shift, /* i : Scaling to get 12 bits */
- const Word16 Q_new /* i : Input scaling */
+ Encoder_State *st_fx, /* i/o: state structure */
+ const Word16 speech_fx[], /* i : input speech Q0*/
+ const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/
+ const Word16 Aq_fx[], /* i : 12k8 Lp coefficient Q12*/
+ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy Q8*/
+ const Word16 *res_fx, /* i : residual signal Q_new*/
+ Word16 *syn_fx, /* i/o: core synthesis Q_new*/
+ Word16 *exc_fx, /* i/o: current non-enhanced excitation Q0*/
+ Word16 *exc2_fx, /* i/o: current enhanced excitation Q0*/
+ Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe Q6*/
+ Word16 *voice_factors, /* o : voicing factors Q15*/
+ Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q0*/
+ Word16 tc_subfr, /* i/o: TC subframe classification Q0*/
+ Word16 position, /* i : maximum of residual signal index Q0*/
+ Word16 *unbits, /* i/o: number of unused bits Q0*/
+ const Word16 shift, /* i : Scaling to get 12 bits */
+ const Word16 Q_new /* i : Input scaling */
);
Word16 encod_tran_ivas_fx(
Encoder_State *st_fx, /* i/o: state structure */
- const Word16 speech_fx[], /* i : input speech */
- const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */
- const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */
- const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */
- const Word16 *res_fx, /* i : residual signal */
- Word16 *syn_fx, /* i/o: core synthesis */
- Word16 *exc_fx, /* i/o: current non-enhanced excitation */
- Word16 *exc2_fx, /* i/o: current enhanced excitation */
- Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe */
- Word16 *voice_factors, /* o : voicing factors */
- Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */
- Word16 tc_subfr, /* i/o: TC subframe classification */
- Word16 position, /* i : maximum of residual signal index */
- Word16 *unbits, /* i/o: number of unused bits */
+ const Word16 speech_fx[], /* i : input speech Q0*/
+ const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/
+ const Word16 Aq_fx[], /* i : 12k8 Lp coefficient Q12*/
+ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy Q8*/
+ const Word16 *res_fx, /* i : residual signal Q_new*/
+ Word16 *syn_fx, /* i/o: core synthesis Q_new*/
+ Word16 *exc_fx, /* i/o: current non-enhanced excitation Q0*/
+ Word16 *exc2_fx, /* i/o: current enhanced excitation Q0*/
+ Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe Q6*/
+ Word16 *voice_factors, /* o : voicing factors Q15*/
+ Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q0*/
+ Word16 tc_subfr, /* i/o: TC subframe classification Q0*/
+ Word16 position, /* i : maximum of residual signal index Q0*/
+ Word16 *unbits, /* i/o: number of unused bits Q0*/
const Word16 shift, /* i : Scaling to get 12 bits */
const Word16 Q_new /* i : Input scaling */
);
@@ -2030,30 +2047,30 @@ void enc_acelp_tcx_main_fx(
Word16 *shift );
ivas_error encod_ppp_fx(
Encoder_State *st_fx, /* i/o: state structure */
- const Word16 speech_fx[], /* i : i speech Q_new*/
- const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */
- const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */
- Word16 *res_fx, /* i : residual signal Q_new*/
- Word16 *synth_fx, /* o : core synthesis Q-1*/
- Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/
- Word16 *exc2_fx, /* o : current enhanced excitation Q0*/
- Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/
- Word16 *voice_factors, /* o : voicing factors */
- Word16 *bwe_exc, /* o : excitation for SWB TBE */
+ const Word16 speech_fx[], /* i : input speech Q_new*/
+ const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/
+ const Word16 Aq_fx[], /* i : 12k8 Lp coefficient Q14*/
+ Word16 *res_fx, /* i : residual signal Q_new*/
+ Word16 *synth_fx, /* o : core synthesis Q-1*/
+ Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/
+ Word16 *exc2_fx, /* o : current enhanced excitation Q0*/
+ Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/
+ Word16 *voice_factors, /* o : voicing factors Q15*/
+ Word16 *bwe_exc, /* o : excitation for SWB TBE Q_new*/
Word16 Q_new,
Word16 shift );
ivas_error encod_ppp_ivas_fx(
Encoder_State *st_fx, /* i/o: state structure */
- const Word16 speech_fx[], /* i : input speech Q_new*/
- const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */
- const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */
- Word16 *res_fx, /* i : residual signal Q_new*/
- Word16 *synth_fx, /* o : core synthesis Q-1*/
- Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/
- Word16 *exc2_fx, /* o : current enhanced excitation Q0*/
- Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/
- Word16 *voice_factors, /* o : voicing factors */
- Word16 *bwe_exc, /* o : excitation for SWB TBE */
+ const Word16 speech_fx[], /* i : input speech Q_new*/
+ const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/
+ const Word16 Aq_fx[], /* i : 12k8 Lp coefficient Q12*/
+ Word16 *res_fx, /* i : residual signal Q_new*/
+ Word16 *synth_fx, /* o : core synthesis Q-1*/
+ Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/
+ Word16 *exc2_fx, /* o : current enhanced excitation Q0*/
+ Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/
+ Word16 *voice_factors, /* o : voicing factors Q15*/
+ Word16 *bwe_exc, /* o : excitation for SWB TBE Q_new*/
Word16 Q_new,
Word16 shift );
void encod_gen_voic_fx(
@@ -2243,10 +2260,10 @@ void E_ACELP_4tsearchx_ivas_fx(
Word16 element_mode );
void E_ACELP_weighted_code(
- const Word16 code[], /* i: code */
- const Word16 H[], /* i: impulse response */
- Word16 Q, /* i: Q format of H */
- Word16 y[] /* o: weighted code */
+ const Word16 code[], /* i: code Q9*/
+ const Word16 H[], /* i: impulse response Q*/
+ Word16 Q, /* i: Q format of H */
+ Word16 y[] /* o: weighted code Q9*/
);
void find_targets_fx(
const Word16 *speech, /* i : pointer to the speech frame Q_new-1*/
@@ -2343,12 +2360,12 @@ Word16 SearchPeriodicityIndex_fx(
);
Word16 ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx(
- const Word16 *x,
- Word16 nt,
- Word16 *lastnz,
- Word16 *nEncoded,
- Word16 target,
- Word16 *stop,
+ const Word16 *x, /* Q0 */
+ Word16 nt, /* Q0 */
+ Word16 *lastnz_out, /* Q0 */
+ Word16 *nEncoded, /* Q0 */
+ Word16 target, /* Q0 */
+ Word16 *stop, /* Q0 */
CONTEXT_HM_CONFIG *hm_cfg );
void tcx_arith_encode_envelope_fx(
@@ -2696,31 +2713,31 @@ void E_ACELP_pulsesign( const Word16 cn[], Word16 dn[], Word16 dn2[], Word16 sig
void E_ACELP_findcandidates( Word16 dn2[], Word16 dn2_pos[], Word16 pos_max[] );
void E_ACELP_setup_pulse_search_pos(
- const PulseConfig *config, /* i: pulse configuration */
- Word16 k, /* i: interation number */
- UWord8 ipos[] /* o: pulse search positions */
+ const PulseConfig *config, /* i: pulse configuration */
+ Word16 k, /* i: interation number Q0*/
+ UWord8 ipos[] /* o: pulse search positions Q0*/
);
void E_ACELP_build_code(
- Word16 nb_pulse, /* i */
- const Word16 codvec[], /* i */
- const Word16 sign[], /* i */
- Word16 code[], /* o */
- Word16 ind[] /* o */
+ Word16 nb_pulse, /* i Q0*/
+ const Word16 codvec[], /* i Q0*/
+ const Word16 sign[], /* i Q0*/
+ Word16 code[], /* o Q9*/
+ Word16 ind[] /* o Q0*/
);
void E_UTIL_f_convolve( const Word16 x[], const Word16 h[], Word16 y[], const Word16 size );
void E_ACELP_conv(
- const Word16 xn2[], /* i */
- const Word16 h2[], /* i */
- Word16 cn2[] /* o */
+ const Word16 xn2[], /* i Qx*/
+ const Word16 h2[], /* i Q12*/
+ Word16 cn2[] /* o Q0*/
);
-void E_ACELP_conv_ivas(
- const Word16 xn2[], /* i */
- const Word16 h2[], /* i */
- Word16 cn2[] /* o */
+void E_ACELP_conv_ivas_fx(
+ const Word16 xn2[], /* i Qx*/
+ const Word16 h2[], /* i Q12*/
+ Word16 cn2[] /* o Q0*/
);
void gPLC_encInfo_fx(
@@ -2844,11 +2861,11 @@ Word16 IGFEncWriteBitstream_fx( /**< ou
void ACcontextMapping_encode2_no_mem_s17_LC_fx(
BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
- Word16 *x,
- Word16 nt,
- Word16 lastnz,
- Word16 nbbits,
- Word16 resQMaxBits,
+ Word16 *x, /* Q0 */
+ Word16 nt, /* Q0 */
+ Word16 lastnz, /* Q0 */
+ Word16 nbbits, /* Q0 */
+ Word16 resQMaxBits, /* Q0 */
CONTEXT_HM_CONFIG *hm_cfg );
Word16 IGFEncWriteConcatenatedBitstream_fx( /**< out: Q0 | total number of bits written */
@@ -3050,33 +3067,32 @@ Word16 vad_proc_fx(
);
void calc_lf_snr_fx(
- Word32 *lf_snr_smooth, /* o : smoothed lf_snr*/
- Word32 *lf_snr, /* o : long time frequency domain
- SNR calculated by l_speech_snr and l_silence_snr*/
- const Word32 l_speech_snr, /* i : sum of active frames snr */
- const Word32 l_speech_snr_count, /* i : amount of the active frame */
- const Word32 l_silence_snr, /* i : sum of the nonactive frames snr*/
- const Word32 l_silence_snr_count, /* i : amount of the nonactive frame */
- const Word16 fg_energy_count, /* i : amount of the foreground energy frame */
- const Word16 bg_energy_count, /* i : amount of the background energy frame */
- const Word16 bw_index /* i : band width index*/
+ Word32 *lf_snr_smooth, /* o : smoothed lf_snr Q25*/
+ Word32 *lf_snr, /* o : long time frequency domain SNR calculated by l_speech_snr and l_silence_snr Q25*/
+ const Word32 l_speech_snr, /* i : sum of active frames snr Q16*/
+ const Word32 l_speech_snr_count, /* i : amount of the active frame Q0*/
+ const Word32 l_silence_snr, /* i : sum of the nonactive frames snr Q16*/
+ const Word32 l_silence_snr_count, /* i : amount of the nonactive frame Q0*/
+ const Word16 fg_energy_count, /* i : amount of the foreground energy frame Q0*/
+ const Word16 bg_energy_count, /* i : amount of the background energy frame Q0*/
+ const Word16 bw_index /* i : band width index Q0*/
);
void calc_lt_snr_fx(
VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */
- Word32 *lt_snr_org_fp, /* o : original long time SNR*/
- Word32 *lt_snr_fp, /* o : long time SNR calculated by fg_energy and bg_energy*/
- Word32 fg_energy, /* i : foreground energy sum */
- Word16 fg_energy_count, /* i : amount of the foreground energy frame */
- Word32 bg_energy, /* i : background energy sum */
- Word16 bg_energy_count, /* i : amount of the background energy frame */
- Word16 bw_index, /* i : band width index*/
- Word16 lt_noise_sp_center0 /* i : long time noise spectral center by 0*/
+ Word32 *lt_snr_org_fp, /* o : original long time SNR Q25*/
+ Word32 *lt_snr_fp, /* o : long time SNR calculated by fg_energy and bg_energy Q25*/
+ Word32 fg_energy, /* i : foreground energy sum Qx*/
+ Word16 fg_energy_count, /* i : amount of the foreground energy frame Q0*/
+ Word32 bg_energy, /* i : background energy sum Qx*/
+ Word16 bg_energy_count, /* i : amount of the background energy frame Q0*/
+ Word16 bw_index, /* i : band width index Q0*/
+ Word16 lt_noise_sp_center0 /* i : long time noise spectral center by 0 Q10*/
);
-void calc_snr_flux_fx( Word32 tsnr_fix, /*(i) time-domain SNR*/
- Word32 *pre_snr, /*(io)time-domain SNR storage*/
- Word32 *snr_flux /*(o) average tsnr*/
+void calc_snr_flux_fx( Word32 tsnr_fix, /*(i) time-domain SNR Q25*/
+ Word32 *pre_snr, /*(io)time-domain SNR storage Q25*/
+ Word32 *snr_flux /*(o) average tsnr Q25*/
);
Word16 vlpc_2st_cod_fx( /* o : number of allocated bits */
@@ -3259,26 +3275,26 @@ void amr_wb_enc_init_fx(
);
void snr_calc(
- VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */
- const Word16 sacle_sbpower, /* i : the Scaling of sbpower*/
- Word32 *snr, /* o : frequency domain SNR */
- Word32 *tsnr, /* o : time domain SNR */
- const Word32 frame_energy, /* i : current frame energy */
- const Word32 bwidth /* i : audio band width*/
+ VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */
+ const Word16 sacle_sbpower, /* i : the Scaling of sbpower */
+ Word32 *snr, /* o : frequency domain SNR Q25*/
+ Word32 *tsnr, /* o : time domain SNR Q25*/
+ const Word32 frame_energy, /* i : current frame energy sacle_sbpower*/
+ const Word32 bwidth /* i : audio band width Q0*/
);
void FEC_encode_fx(
- BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
- const ACELP_config acelp_cfg, /* i/o: configuration of the ACELP */
- const Word16 *synth, /* i : pointer to synthesized speech for E computation */
- const Word16 coder_type, /* i : type of coder */
- Word16 clas, /* i : signal clas for current frame */
- const Word16 *fpit, /* i : close loop fractional pitch buffer */
- const Word16 *res, /* i : LP residual signal frame */
- Word16 *last_pulse_pos, /* i/o: Position of the last pulse */
- const Word16 L_frame, /* i : Frame length */
- const Word32 total_brate, /* i : total codec bitrate */
- const Word16 Q_new, /* i : i scaling */
- const Word16 shift /* i : scaling to get 12bits */
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ const ACELP_config acelp_cfg, /* i/o: configuration of the ACELP */
+ const Word16 *synth, /* i : pointer to synthesized speech for E computation Q_synth*/
+ const Word16 coder_type, /* i : type of coder Q0*/
+ Word16 clas, /* i : signal clas for current frame Q0*/
+ const Word16 *fpit, /* i : close loop fractional pitch buffer Q6*/
+ const Word16 *res, /* i : LP residual signal frame Qx*/
+ Word16 *last_pulse_pos, /* i/o: Position of the last pulse Q0*/
+ const Word16 L_frame, /* i : Frame length Q0*/
+ const Word32 total_brate, /* i : total codec bitrate Q0*/
+ const Word16 Q_new, /* i : i scaling */
+ const Word16 shift /* i : scaling to get 12bits */
);
void updt_enc_fx(
@@ -3485,16 +3501,16 @@ void hf_cod_init_fx(
);
void analy_lp_AMR_WB_fx(
- const Word16 speech[], /* i : pointer to the speech frame */
- Word32 *ener, /* o : residual energy from Levinson-Durbin */
- Word16 A[], /* o : A(z) filter coefficients */
- Word16 epsP_h[], /* o : LP analysis residual energies for each iteration */
- Word16 epsP_l[], /* o : LP analysis residual energies for each iteration */
- Word16 isp_new[], /* o : current frame ISPs */
- Word16 isp_old[], /* i/o: previous frame unquantized ISPs */
- Word16 isf_new[], /* o : current frame ISPs */
- Word16 Top, /* i : open loop pitch lag */
- Word16 Tnc, /* i : open loop pitch gain */
+ const Word16 speech[], /* i : pointer to the speech frame Q_new*/
+ Word32 *ener, /* o : residual energy from Levinson-Durbin Q_r*/
+ Word16 A[], /* o : A(z) filter coefficients Q14*/
+ Word16 epsP_h[], /* o : LP analysis residual energies for each iteration Q_r*/
+ Word16 epsP_l[], /* o : LP analysis residual energies for each iteration Q_r*/
+ Word16 isp_new[], /* o : current frame ISPs Q15*/
+ Word16 isp_old[], /* i/o: previous frame unquantized ISPs Q15*/
+ Word16 isf_new[], /* o : current frame ISPs Q15*/
+ Word16 Top, /* i : open loop pitch lag Q0*/
+ Word16 Tnc, /* i : open loop pitch gain Qx*/
Word16 Q_new,
Word16 *Q_r );
@@ -3947,41 +3963,41 @@ Word16 gain_enc_gaus_fx( /* o : Return index of quant
);
void enc_pit_exc_fx(
Encoder_State *st_fx, /* i/o: State structure */
- const Word16 *speech, /* i : Input speech */
- const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */
- const Word16 Aq[], /* i : 12k8 Lp coefficient */
- const Word16 Es_pred, /* i : predicted scaled innov. energy */
- const Word16 *res, /* i : residual signal */
- Word16 *synth, /* i/o: core synthesis */
- Word16 *exc, /* i/o: current non-enhanced excitation */
- Word16 *T0, /* i/o: close loop integer pitch */
- Word16 *T0_frac, /* i/o: close-loop pitch period - fractional part */
- Word16 *pitch_buf, /* i/o: Fractionnal per subframe pitch */
- const Word16 nb_subfr, /* i : Number of subframe considered */
- Word16 *gpit, /* o : pitch mean gpit */
- Word16 *saved_bit_pos, /* o : saved position in the bitstream before pitch contribution */
- const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
- const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */
+ const Word16 *speech, /* i : Input speech Q_new-1*/
+ const Word16 Aw[], /* i : weighted A(z) unquantized for subframes Q12*/
+ const Word16 Aq[], /* i : 12k8 Lp coefficient Q12*/
+ const Word16 Es_pred, /* i : predicted scaled innov. energy Q8*/
+ const Word16 *res, /* i : residual signal Q_new*/
+ Word16 *synth, /* i/o: core synthesis Q_new*/
+ Word16 *exc, /* i/o: current non-enhanced excitation Q_new*/
+ Word16 *T0, /* i/o: close loop integer pitch Q0*/
+ Word16 *T0_frac, /* i/o: close-loop pitch period - fractional part Q0*/
+ Word16 *pitch_buf, /* i/o: Fractionnal per subframe pitch Q6*/
+ const Word16 nb_subfr, /* i : Number of subframe considered Q0*/
+ Word16 *gpit, /* o : pitch mean gpit Q15*/
+ Word16 *saved_bit_pos, /* o : saved position in the bitstream before pitch contribution Q0*/
+ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/
+ const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer Q6*/
Word16 Q_new,
Word16 shift );
void enc_pit_exc_ivas_fx(
Encoder_State *st_fx, /* i/o: State structure */
- const Word16 *speech, /* i : Input speech */
- const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */
- const Word16 Aq[], /* i : 12k8 Lp coefficient */
- const Word16 Es_pred, /* i : predicted scaled innov. energy */
- const Word16 *res, /* i : residual signal */
- Word16 *synth, /* i/o: core synthesis */
- Word16 *exc, /* i/o: current non-enhanced excitation */
- Word16 *T0, /* i/o: close loop integer pitch */
- Word16 *T0_frac, /* i/o: close-loop pitch period - fractional part */
- Word16 *pitch_buf, /* i/o: Fractionnal per subframe pitch */
- const Word16 nb_subfr, /* i : Number of subframe considered */
- Word16 *gpit, /* o : pitch mean gpit */
- Word16 *saved_bit_pos, /* o : saved position in the bitstream before pitch contribution */
- const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
- const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */
+ const Word16 *speech, /* i : Input speech Q_new-1*/
+ const Word16 Aw[], /* i : weighted A(z) unquantized for subframes Q12*/
+ const Word16 Aq[], /* i : 12k8 Lp coefficient Q12*/
+ const Word16 Es_pred, /* i : predicted scaled innov. energy Q8*/
+ const Word16 *res, /* i : residual signal Q_new*/
+ Word16 *synth, /* i/o: core synthesis Q_new*/
+ Word16 *exc, /* i/o: current non-enhanced excitation Q_new*/
+ Word16 *T0, /* i/o: close loop integer pitch Q0*/
+ Word16 *T0_frac, /* i/o: close-loop pitch period - fractional part Q0*/
+ Word16 *pitch_buf, /* i/o: Fractionnal per subframe pitch Q6*/
+ const Word16 nb_subfr, /* i : Number of subframe considered Q0*/
+ Word16 *gpit, /* o : pitch mean gpit Q15*/
+ Word16 *saved_bit_pos, /* o : saved position in the bitstream before pitch contribution Q0*/
+ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/
+ const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer Q6*/
Word16 Q_new,
Word16 shift );
@@ -4395,8 +4411,8 @@ Word16 noise_est_AR1_Qx( /* o: Qx y(n) */
Word16 alpha /*i : Q15 scaling of driving x(n) */
);
void FEC_lsf_estim_enc_fx(
- Encoder_State *st_fx, /* i : Encoder static memory */
- Word16 *lsf /* o : estimated LSF vector */
+ Encoder_State *st_fx, /* i : Encoder static memory */
+ Word16 *lsf /* o : estimated LSF vector Qlog2(2.56)*/
);
Word32 mslvq_cng_fx(
@@ -4692,8 +4708,8 @@ void destroy_encoder_fx(
void amr_wb_enc_fx(
Encoder_State *st, /* i/o: encoder state structure */
- const Word16 input_sp[], /* i : i signal */
- const Word16 n_samples /* i : number of i samples */
+ const Word16 input_sp[], /* i : i signal Q0*/
+ const Word16 n_samples /* i : number of i samples Q0*/
);
void writeLPCparam_fx(
diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c
index 0d7720f62451a5265dff778b68b43def20fe88b4..c6f2b8502bbb88c8c2896a5cf515adaf171a08a3 100644
--- a/lib_enc/tcx_utils_enc_fx.c
+++ b/lib_enc/tcx_utils_enc_fx.c
@@ -1805,7 +1805,7 @@ Word16 tcx_scalar_quantization_rateloop_ivas_fx(
IF( GT_16( element_mode, EVS_MONO ) )
{
- sqBits = RCcontextMapping_encode2_estimate_no_mem_s17_LCS( xq, L_frame, &lastnz, nEncoded, target, &stopFlag, 0, hm_cfg );
+ sqBits = RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx( xq, L_frame, &lastnz, nEncoded, target, &stopFlag, 0, hm_cfg );
}
ELSE
{