diff --git a/Workspace_msvc/lib_dec.vcxproj b/Workspace_msvc/lib_dec.vcxproj
index 8aeb0435cf299e0af585bf7f3bb30c71930745b5..d6dca84cae8e246c33bd03b0920e1a3d5a3d2bb2 100644
--- a/Workspace_msvc/lib_dec.vcxproj
+++ b/Workspace_msvc/lib_dec.vcxproj
@@ -144,6 +144,7 @@
false
+
diff --git a/Workspace_msvc/lib_dec.vcxproj.filters b/Workspace_msvc/lib_dec.vcxproj.filters
index c3704d1c3e4ac6e7234552216d5e4d3a99d3d421..fc5e0663853eaeb4805b1759cfd53f0bc7894275 100644
--- a/Workspace_msvc/lib_dec.vcxproj.filters
+++ b/Workspace_msvc/lib_dec.vcxproj.filters
@@ -1,894 +1,304 @@
-
+
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_evs_c
-
-
- decoder_all_c
-
-
- decoder_ivas_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_evs_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_evs_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_evs_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_all_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_evs_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_all_c
-
-
- decoder_evs_c
-
-
- decoder_evs_c
-
-
- decoder_all_c
-
-
- decoder_evs_c
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
- decoder_all_c
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
-
-
- decoder_ivas_c
-
-
- decoder_ivas_c
-
- decoder_ivas_c
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
- decoder_h
-
-
- decoder_h
-
-
- decoder_h
-
-
- decoder_h
-
-
- decoder_h
-
-
- decoder_h
-
-
- decoder_h
-
-
- decoder_h
-
-
- decoder_h
-
-
- decoder_h
-
-
- decoder_h
-
-
- decoder_h
-
-
- decoder_h
-
-
-
-
- {f63b6db2-97ec-4d8d-be9c-e798ac8bb645}
-
-
- {0853864e-7de7-411d-975b-5045652f22c3}
-
-
- {e29aae34-aeeb-45dd-a986-61b39890c5bb}
-
-
- {c33b80b3-67ce-466b-91c0-4adfc9efcb5c}
-
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/lib_com/enhancer_fx.c b/lib_com/enhancer_fx.c
index ab9e9f781426b55af7404efc6c2c044d3f9561e6..d53a9295124a399ae40f427079fb088c92779c94 100644
--- a/lib_com/enhancer_fx.c
+++ b/lib_com/enhancer_fx.c
@@ -278,6 +278,278 @@ void enhancer_fx(
}
}
+
+/*======================================================================================*/
+/* FUNCTION : enhancer_fx() */
+/*--------------------------------------------------------------------------------------*/
+/* PURPOSE : Enhancement of the excitation signal before synthesis */
+/*--------------------------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (Word32) core_brate : decoder bitrate */
+/* _ (Word16) Opt_AMR_WB : flag indicating AMR-WB IO mode */
+/* _ (Word16) coder_type : coder type */
+/* _ (Word16) i_subfr : subframe number */
+/* _ (Word16) voice_fac : subframe voicing estimation (Q15) */
+/* _ (Word16) stab_fac : LP filter stablility measure (Q15) */
+/* _ (Word32) norm_gain_code : normalised innovative cb. gain (Q16) */
+/* _ (Word16) gain_inov : gain of the unscaled innovation (Q12) */
+/* _ (Word16) gain_pit_fx : Pitch gain (Q14) */
+/* _ (Word16) Q_exc : Q of the excitation */
+/* _ (Word16) Enc : Encoder = 1; decoder = 0 */
+/*--------------------------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ (Word16*) voice_factors_fx : TBE voicing factor (Q15) */
+/*--------------------------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _ (Word32*) gc_threshold : gain code threshold (Q16) */
+/* _ (Word16*[]) code : innovation (Q12) */
+/* _ (Word16*[]) exc2 : adapt. excitation/total exc (Q0) */
+/* _ (struct dispMem_fx*) dm_fx : phase dispersion algorithm memory */
+/* (a[0]->Q0,a[1]->Q16,a[2-7]->Q14) */
+/*--------------------------------------------------------------------------------------*/
+
+/* _ None */
+/*--------------------------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : */
+/* _ None */
+/*======================================================================================*/
+void enhancer_ivas_fx(
+ const Word16 codec_mode, /* i : flag indicating Codec Mode */
+ const Word32 core_brate, /* i : decoder bitrate */
+ const int16_t cbk_index, /* i : */
+ const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */
+ const Word16 coder_type, /* i : coder type */
+ const Word16 i_subfr, /* i : subframe number */
+ const Word16 L_frame, /* i : frame size */
+ const Word16 voice_fac, /* i : subframe voicing estimation Q15 */
+ const Word16 stab_fac, /* i : LP filter stablility measure Q15 */
+ Word32 norm_gain_code, /* i : normalised innovative cb. gain Q16 */
+ const Word16 gain_inov, /* i : gain of the unscaled innovation Q12 */
+ Word32 *gc_threshold,/* i/o: gain code threshold Q16 */
+ Word16 *code, /* i/o: innovation Q12 */
+ Word16 *exc2, /* i/o: adapt. excitation/total exc. Q_exc*/
+ const Word16 gain_pit, /* i : quantized pitch gain Q14 */
+ struct dispMem_fx *dm_fx, /* i/o: phase dispersion algorithm memory */
+ const Word16 Q_exc /* i : Q of the excitation */
+)
+{
+ Word16 tmp, fac, *pt_exc2;
+ Word16 i;
+ Word32 L_tmp;
+ Word16 gain_code_hi;
+ Word16 pit_sharp, tmp16;
+ Word16 excp[L_SUBFR], sc;
+
+
+
+ pit_sharp = gain_pit;
+ move16(); /* to remove gcc warning */
+ pt_exc2 = exc2 + i_subfr;
+ move16();
+
+ /*------------------------------------------------------------*
+ * Phase dispersion to enhance noise at low bit rate
+ *------------------------------------------------------------*/
+
+ i = 2;
+ move16(); /* no dispersion */
+ IF(Opt_AMR_WB)
+ {
+ IF(LE_32(core_brate, ACELP_6k60))
+ {
+ i = 0;
+ move16(); /* high dispersion */
+ }
+ ELSE if (LE_32(core_brate, ACELP_8k85))
+ {
+ i = 1;
+ move16(); /* low dispersion */
+ }
+ }
+ ELSE IF( EQ_16(codec_mode, MODE1) && NE_16(coder_type, UNVOICED))
+
+ {
+ test();
+ test();
+ test();
+ test();
+ IF(LE_32(core_brate, ACELP_7k20))
+ {
+ i = 0;
+ move16(); /* high dispersion */
+ }
+ ELSE IF ((EQ_16(coder_type, GENERIC) || EQ_16(coder_type, TRANSITION) || EQ_16(coder_type, AUDIO) || EQ_16(coder_type, INACTIVE)) && LE_32(core_brate, ACELP_9k60))
+ {
+ i = 1;
+ move16(); /* low dispersion */
+ }
+ }
+ ELSE IF( EQ_16( codec_mode, MODE2 ) )
+ {
+ IF( ( NE_16( coder_type, VOICED ) && LE_16( cbk_index, 2 ) ) || ( EQ_16( coder_type, UNVOICED ) && EQ_16( L_frame, L_FRAME ) && LE_16( cbk_index, 10 ) ) || ( EQ_16( coder_type, UNVOICED ) && EQ_16( L_frame, L_FRAME16k ) && LE_16( cbk_index, 14 ) ) )
+ {
+ i = 0; /* high dispersion */
+ }
+ ELSE IF( NE_16( coder_type, VOICED ) && LE_16( cbk_index, 7 ) )
+ {
+ i = 1; /* low dispersion */
+ }
+ }
+ ELSE IF( EQ_16(codec_mode, MODE1) && EQ_16(coder_type, UNVOICED) && cbk_index /*uc_two_stage_flag*/ )
+ {
+ i = 0; /* high dispersion */
+ }
+
+ phase_dispersion_fx(norm_gain_code, gain_pit, code, i, dm_fx);
+
+ /*------------------------------------------------------------
+ * noise enhancer
+ *
+ * - Enhance excitation on noise. (modify gain of code)
+ * If signal is noisy and LPC filter is stable, move gain
+ * of code 1.5 dB toward gain of code threshold.
+ * This decreases by 3 dB noise energy variation.
+ *-----------------------------------------------------------*/
+
+ /* tmp = 0.5f * (1.0f - voice_fac) */
+#ifdef BASOP_NOGLOB
+ tmp = msu_r_sat(0x40000000, voice_fac, 16384); /*Q15 */ /* 1=unvoiced, 0=voiced */
+#else
+ tmp = msu_r(0x40000000, voice_fac, 16384); /*Q15 */ /* 1=unvoiced, 0=voiced */
+#endif
+ /* fac = stab_fac * tmp */
+ fac = mult(stab_fac, tmp); /*Q15*/
+
+ IF(LT_32(norm_gain_code, *gc_threshold))
+ {
+ L_tmp = Madd_32_16(norm_gain_code, norm_gain_code, 6226);/*Q16 */
+ L_tmp = L_min(L_tmp, *gc_threshold);/*Q16 */
+ }
+ ELSE
+ {
+ L_tmp = Mult_32_16(norm_gain_code, 27536);/*Q16 */
+ L_tmp = L_max(L_tmp, *gc_threshold); /*Q16 */
+ }
+ *gc_threshold = L_tmp;
+ move32(); /*Q16 */
+
+ /* gain_code = (fac * tmp) + (1.0 - fac) * gain_code ==> fac * (tmp - gain_code) + gain_code */
+ L_tmp = L_sub(L_tmp, norm_gain_code); /*Q16 */
+ norm_gain_code = Madd_32_16(norm_gain_code, L_tmp, fac);/*Q16 */
+
+ /* gain_code *= gain_inov - Inverse the normalization */
+ L_tmp = Mult_32_16(norm_gain_code, gain_inov); /*Q13*/ /* gain_inov in Q12 */
+
+ sc = 6;
+ move16();
+
+ gain_code_hi = round_fx(L_shl(L_tmp, add(Q_exc, 3))); /* in Q_exc */
+
+ /*------------------------------------------------------------*
+ * pitch enhancer
+ *
+ * - Enhance excitation on voiced. (HP filtering of code)
+ * On voiced signal, filtering of code by a smooth fir HP
+ * filter to decrease energy of code at low frequency.
+ *------------------------------------------------------------*/
+ test();
+ IF(!Opt_AMR_WB && EQ_16(coder_type, UNVOICED))
+ {
+ /* Copy(code, exc2, L_SUBFR) */
+ FOR(i = 0; i < L_SUBFR; i++)
+ {
+ pt_exc2[i] = round_fx(L_shl(L_mult(gain_code_hi, code[i]), sc)); /*Q0 */ /* code in Q12 (Q9 for encoder) */
+ }
+ }
+ ELSE
+ {
+ test();
+ test();
+ IF(Opt_AMR_WB && (EQ_32(core_brate,ACELP_8k85) || EQ_32(core_brate,ACELP_6k60)))
+ {
+#ifdef BASOP_NOGLOB
+ pit_sharp = shl_sat(gain_pit, 1); /* saturation can occur here Q14 -> Q15 */
+#else
+ pit_sharp = shl(gain_pit, 1); /* saturation can occur here Q14 -> Q15 */
+#endif
+ /* saturation takes care of "if (pit_sharp > 1.0) { pit_sharp=1.0; }" */
+ IF(GT_16(pit_sharp, 16384))
+ {
+ tmp16 = mult(pit_sharp, 8192);
+ FOR(i = 0; i < L_SUBFR; i++)
+ {
+ /* excp[i] = pt_exc2[i] * pit_sharp * 0.25 */
+ excp[i] = mult_r(pt_exc2[i], tmp16);
+ move16();
+ }
+ }
+ }
+
+ IF(EQ_16(L_frame, L_FRAME16k))
+ {
+ /* tmp = 0.150 * (1.0 + voice_fac) */
+ /* 0.30=voiced, 0=unvoiced */
+ tmp = mac_r(0x10000000L, voice_fac, 4915);/*Q15 */
+ }
+ ELSE
+ {
+ /* tmp = 0.125 * (1.0 + voice_fac) */
+ /* 0.25=voiced, 0=unvoiced */
+ tmp = mac_r(0x10000000L, voice_fac, 4096);/*Q15 */
+ }
+
+ /*-----------------------------------------------------------------
+ * Do a simple noncasual "sharpening": effectively an FIR
+ * filter with coefs [-tmp 1.0 -tmp] where tmp=0...0.25.
+ * This is applied to code and add_fxed to exc2
+ *-----------------------------------------------------------------*/
+ /* pt_exc2[0] += code[0] - tmp * code[1] */
+ L_tmp = L_deposit_h(code[0]); /* if Enc :Q9 * Q15 -> Q25 */
+ L_tmp = L_msu(L_tmp, code[1], tmp); /* Q12 * Q15 -> Q28 */
+ L_tmp = L_shl(L_mult(gain_code_hi, extract_h(L_tmp)), sc);
+ pt_exc2[0] = msu_r(L_tmp, -32768, pt_exc2[0]);
+ move16();/* in Q_exc */
+
+ FOR(i = 1; i < L_SUBFR - 1; i++)
+ {
+ /* pt_exc2[i] += code[i] - tmp * code[i-1] - tmp * code[i+1] */
+ L_tmp = L_msu(-32768, code[i], -32768);
+ L_tmp = L_msu(L_tmp, code[i + 1], tmp);
+ tmp16 = msu_r(L_tmp, code[i - 1], tmp);
+ L_tmp = L_shl(L_mult(gain_code_hi, tmp16), sc);
+#ifdef BASOP_NOGLOB
+ pt_exc2[i] = msu_r_sat(L_tmp, -32768, pt_exc2[i]);
+#else
+ pt_exc2[i] = msu_r(L_tmp, -32768, pt_exc2[i]);
+#endif
+ move16(); /* in Q_exc */
+ }
+
+ /* pt_exc2[L_SUBFR-1] += code[L_SUBFR-1] - tmp * code[L_SUBFR-2] */
+ L_tmp = L_deposit_h(code[L_SUBFR - 1]);/*Q28 */
+ L_tmp = L_msu(L_tmp, code[L_SUBFR - 2], tmp);/*Q28 */
+ L_tmp = L_shl(L_mult(gain_code_hi, extract_h(L_tmp)), sc);
+ pt_exc2[L_SUBFR - 1] = msu_r(L_tmp, -32768, pt_exc2[L_SUBFR - 1]);
+ move16();/* in Q_exc */
+ test();
+ test();
+ IF(Opt_AMR_WB && (EQ_32(core_brate,ACELP_8k85) || EQ_32(core_brate,ACELP_6k60)))
+ {
+ IF(GT_16(pit_sharp, 16384))
+ {
+ FOR(i = 0; i < L_SUBFR; i++)
+ {
+ /* excp[i] += pt_exc2[i] */
+ excp[i] = add(excp[i], pt_exc2[i]);
+ move16();
+ }
+ agc2_fx(pt_exc2, excp, L_SUBFR);
+ Copy(excp, pt_exc2, L_SUBFR);
+ }
+ }
+ }
+}
+
/*---------------------------------------------------------*
* Enhancement of the excitation signal before synthesis
*---------------------------------------------------------*/
diff --git a/lib_com/est_tilt_fx.c b/lib_com/est_tilt_fx.c
index addad1aeed7a19d234834a757b70bbd26ab97363..f54b4bc2139db8f60f4da37780fc42ef0d201819 100644
--- a/lib_com/est_tilt_fx.c
+++ b/lib_com/est_tilt_fx.c
@@ -93,7 +93,6 @@ Word16 est_tilt_fx( /* o : tilt of the code Q15 *
return tilt_code;
}
-#ifdef IVAS_FLOAT_FIXED
/*======================================================================*/
/* FUNCTION : est_tilt_ivas_fx() */
/*-----------------------------------------------------------------------*/
@@ -191,7 +190,6 @@ Word16 est_tilt_ivas_fx( /* o : tilt of the code Q15
return tilt_code;
}
-#endif
/*-------------------------------------------------------------------*
* Est_tilt2:
diff --git a/lib_com/fd_cng_com.c b/lib_com/fd_cng_com.c
index f584ad7aa6eda68749e0b0d984af57a59ef8438c..fe70ad2997a93e9783576a4832bc3b4b4e19f64a 100644
--- a/lib_com/fd_cng_com.c
+++ b/lib_com/fd_cng_com.c
@@ -1321,7 +1321,6 @@ void lpc_from_spectrum_flt(
return;
}
-
/*-------------------------------------------------------------------
* FdCng_exc_flt()
*
diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c
index 5832860074c7df44039e6224c2ad3e9c6bf00e03..9486566ece889f82b82e0d6b43f9e0cb9e886520 100644
--- a/lib_com/fd_cng_com_fx.c
+++ b/lib_com/fd_cng_com_fx.c
@@ -2411,7 +2411,7 @@ void AnalysisSTFT_fx(
FOR( i = 0; i < hFdCngCom->frameSize; i++ )
{
- olapBuffer[i + len] = shr( timeDomainInput[i], Q );
+ olapBuffer[i + len] = shr_sat( timeDomainInput[i], Q ); // Values above MAX_16 seen with 10dB tests in float code
move16();
}
@@ -2461,6 +2461,9 @@ void SynthesisSTFT (
scale = 0;
BASOP_rfft(fftBuffer, hFdCngCom->fftlen, &scale, 1);
fftBufferExp = add(fftBufferExp, scale);
+#ifdef IVAS_FLOAT_FIXED
+ hFdCngCom->fftBuffer_exp = fftBufferExp;
+#endif
fftBufferExp = add(fftBufferExp, hFdCngCom->fftlenShift);
/* Perform overlap-add */
diff --git a/lib_com/fft_fx_evs.c b/lib_com/fft_fx_evs.c
index b6ed50554002483c1ab0d0c71694b9e1898b65ef..9dec4315fa678832cad775d993a1d874600e8085 100644
--- a/lib_com/fft_fx_evs.c
+++ b/lib_com/fft_fx_evs.c
@@ -1382,7 +1382,7 @@ static void fft5_32_16fx(
/* T2 = KP951056516 * Ts + KP587785252 * Tt; */
L_tmp = Mult_32_16(KP951056516_16FX,Ts);
L_tmp = Madd_32_16(L_tmp,KP587785252_16FX,Tt);
- T2 = round_fx(L_tmp);
+ T2 = round_fx_sat(L_tmp);
/* T3 = KP951056516 * Tt - KP587785252 * Ts; */
L_tmp = Mult_32_16(KP951056516_16FX,Tt);
diff --git a/lib_com/gs_bitallocation_ivas_fx.c b/lib_com/gs_bitallocation_ivas_fx.c
index d2e2efe664815ff87c35001c5f8ccdd19eafd93d..2c9bb1737c08284c6a2842c7b7b879fbe9ed9e25 100644
--- a/lib_com/gs_bitallocation_ivas_fx.c
+++ b/lib_com/gs_bitallocation_ivas_fx.c
@@ -77,7 +77,7 @@ void bands_and_bit_alloc_ivas_fx(
Word16 tmp;
Word16 Ener_per_bd_iQ_tmp[MBANDS_GN_BITALLOC16k]; //Q13
Word16 pos, band;
- Word16 SWB_bit_budget;
+ Word32 SWB_bit_budget; // Q0 -> Q18
Word32 bits_per_bands[MBANDS_GN_BITALLOC16k]; //Q18
Word16 w_sum_bit;
Word16 fzero_val;
@@ -213,14 +213,14 @@ void bands_and_bit_alloc_ivas_fx(
{
IF(GSC_IVAS_mode > 0)
{
- SWB_bit_budget = *bit;
+ SWB_bit_budget = *bit; // Q0
st_band = 5;
set_l(bits_per_bands, 0, MBANDS_GN_BITALLOC16k);
/* 2- Decide the pourcentage of bits allocated to LF (between 50-75%) depending of the temporal contribution in GSC */
//bit_fracf = (-0.125f * Diff_len + 76.0f) / 100;
- bit_fracf = L_add(L_mult0(-328, Diff_len), 199229); //Q18
+ bit_fracf = L_add( Mpy_32_32( -2684355, L_shl( Diff_len, Q18 ) ), 199229 ); // Q18
//bit_fracf = check_bounds(bit_fracf, 0.50f, 0.75f);
bit_fracf = check_bounds_l(bit_fracf, 131072, 196608); //Q18
@@ -255,15 +255,15 @@ void bands_and_bit_alloc_ivas_fx(
IF(GSC_IVAS_mode == 1 && core_brate < GSC_L_RATE_STG)
{
//nb_bands_adj = 0.0125f * SWB_bit_budget - 0.75f;
- nb_bands_adj = L_sub(L_mult0(SWB_bit_budget, 3277), 196608); //Q18
+ nb_bands_adj = L_sub( Mpy_32_32( 26843546, L_shl( SWB_bit_budget, Q18 ) ), 196608 ); // Q18
}
ELSE IF(GSC_IVAS_mode != 2 && core_brate > GSC_H_RATE_STG)
{
//nb_bands_adj = 0.02f * SWB_bit_budget - 1.2f;
- nb_bands_adj = L_sub(L_mult0(5243, SWB_bit_budget), 314572); //Q18
+ nb_bands_adj = L_sub( Mpy_32_32( 42949673, L_shl( SWB_bit_budget, Q18 ) ), 314572 ); // Q18
}
//nb_bands_max = (int16_t)(nb_bands_max * nb_bands_adj + 0.5f);
- nb_bands_max = (Word16) L_shr(nb_bands_max * nb_bands_adj, Q18); //Q0
+ nb_bands_max = (Word16) L_shr_r(nb_bands_max * nb_bands_adj, Q18); //Q0
nb_bands_max = check_bounds_s(nb_bands_max, 5, nb_tot_bands);
//bit_fracf *= SWB_bit_budget;
@@ -272,7 +272,7 @@ void bands_and_bit_alloc_ivas_fx(
/* Estimation of the number of bit used in HF */
/* with only the first weigthing The number of bits in max_ener_band[st_band-1] = 17% of bit_fracf */
//mb = .17f * bit_fracf;
- mb = Mpy_32_32(1610612736, bit_fracf); //Q18
+ mb = Mpy_32_32(365072220, bit_fracf); //Q18
//mp = 2 * DSR_NB_PULSE);
mp = 2359296; //Q18
IF(core_brate < GSC_L_RATE_STG && GSC_IVAS_mode == 3)
@@ -298,26 +298,26 @@ void bands_and_bit_alloc_ivas_fx(
bit_adj = max(0, bit_adj);
nb_tot_bands = nb_bands_max - st_band;
//bit_fracf += bit_adj;
- bit_fracf = L_add( bit_fracf, bit_adj );
+ bit_fracf = L_add( bit_fracf, bit_adj ); //Q18
}
nb_tot_bands += st_band;
/* Allocate bits to LF */
//etmp = 0.23f;
- etmp = 7537; //Q15
+ Word32 etmp_32fx = 493921239; //Q15
FOR(j = 0; j < st_band; j++)
{
i = j;
max_ener_band[j] = i;
ener_vec[i] = MIN16B;
//bits_per_bands[j] = etmp * bit_fracf;
- bits_per_bands[j] = (Word32)W_shr(W_mult0_32_32(etmp, bit_fracf), 15); //33 - 15 = Q18
+ bits_per_bands[j] = Mpy_32_32(bit_fracf, etmp_32fx); //33 - 15 = Q18
//etmp -= 0.015f;
- etmp = sub(etmp, 492);
+ etmp_32fx = L_sub(etmp_32fx, 32212255);
}
//SWB_bit_budget -= bit_fracf;
- SWB_bit_budget -= (Word16)L_shr(bit_fracf, Q18);
+ SWB_bit_budget = L_sub(L_shl(SWB_bit_budget, Q18),bit_fracf); //Q0->Q18
/* Find low energy band in HF */
set_s(nb_pulse_per_band, 2, MBANDS_GN_BITALLOC16k);
@@ -347,7 +347,7 @@ void bands_and_bit_alloc_ivas_fx(
IF(nb_tot_bands > st_band)
{
//bit_fracf = DSR_NB_PULSE;
- mb = L_shl((SWB_bit_budget * 2 / (nb_tot_bands - st_band)), Q18) - mp;
+ mb = (SWB_bit_budget * 2 / (nb_tot_bands - st_band)) - mp; // Q18
bit_fracf = (mb - mp) / (nb_tot_bands - st_band);
mb = L_sub(mb, bit_fracf);
/* Do the distribution */
@@ -363,7 +363,7 @@ void bands_and_bit_alloc_ivas_fx(
bits_per_bands[max_ener_band[j]] = 1179648;
}
mb = L_sub(mb, bit_fracf);
- SWB_bit_budget = sub( SWB_bit_budget, (Word16) L_shr( bits_per_bands[max_ener_band[j]], Q18 ) );
+ SWB_bit_budget = L_sub( SWB_bit_budget, bits_per_bands[max_ener_band[j]] ); // Q18
}
}
@@ -375,7 +375,8 @@ void bands_and_bit_alloc_ivas_fx(
{
//bits_per_bands[i]++;
bits_per_bands[i] = L_add(bits_per_bands[i], 262144);
- SWB_bit_budget--;
+ //SWB_bit_budget--;
+ SWB_bit_budget = L_sub(SWB_bit_budget, 262144);
i--;
IF(i == -1)
{
@@ -456,7 +457,7 @@ void bands_and_bit_alloc_ivas_fx(
set32_fx(bits_per_bands, 0, MBANDS_GN);
/*bit_fracf = (1.0f/nb_bands)*(SWB_bit_budget); */
- bit_fracf = L_mult(div_s(1, nb_bands), shl(SWB_bit_budget, 2)); /* Q18 */
+ bit_fracf = L_mult(div_s(1, nb_bands), shl((Word16)SWB_bit_budget, 2)); /* Q18 */
nb_tot_bands = sub(nb_bands_max, 6);
nb_tot_bands = s_min(nb_tot_bands, 16);
@@ -653,7 +654,7 @@ void bands_and_bit_alloc_ivas_fx(
}
FOR(i = 0; i < imax; i++)
{
- bits_per_bands[i] = L_add(GSC_freq_bits_fx[bit_index],bit_fracf);
+ bits_per_bands[i] = L_add(GSC_freq_bits_fx_Q18[bit_index],bit_fracf);
move32();/* Q18 */
bit_index = add(bit_index,1);
}
@@ -680,7 +681,7 @@ void bands_and_bit_alloc_ivas_fx(
bit_index = add(bit_index_mem,10);
FOR(i = 0; i < 7; i++)
{
- bits_per_bands[i] = L_add(bits_per_bands[i],GSC_freq_bits_fx[bit_index]);
+ bits_per_bands[i] = L_add(bits_per_bands[i], GSC_freq_bits_fx_Q18[bit_index]);
move32();/*chk Q18 */
bit_index = add(bit_index,1);
}
diff --git a/lib_com/gs_gains_fx.c b/lib_com/gs_gains_fx.c
index c98b90ef8c579b9370b1e9aa3c1645a652fb96d6..db0f0f1db12de1ec492e5f3f7d50b4a11559d4c6 100644
--- a/lib_com/gs_gains_fx.c
+++ b/lib_com/gs_gains_fx.c
@@ -233,6 +233,54 @@ void Ener_per_band_comp_fx(
return;
}
+void Ener_per_band_comp_ivas_fx(
+ const Word16 exc_diff_fx[], /* i : target signal Q_exc_diff */
+ Word16 y_gain4_fx[], /* o : Energy per band to quantize Q12 */
+ const Word16 Q_exc, /* i : frame length */
+ const Word16 Mband, /* i : Max band */
+ const Word16 Eflag, /* i : flag of highest band */
+ const int16_t L_frame /* i : frame length */
+)
+{
+ const Word16 *pt_fx;
+ Word16 j;
+
+ pt_fx = exc_diff_fx;
+ FOR(j = 0; j < 2; j++)
+ {
+ y_gain4_fx[j] = Comp_band_log_ener(pt_fx, 8, Q_exc, 1);
+ move16();
+ pt_fx += 8;
+ }
+
+ FOR(j = 1; j < Mband - 2; j++)
+ {
+ y_gain4_fx[j + 1] = Comp_band_log_ener(pt_fx, 16, Q_exc, 0);
+ move16();
+ pt_fx += 16;
+ }
+
+ IF(EQ_16(Eflag, 1))
+ {
+ y_gain4_fx[j + 1] = Comp_band_log_ener(pt_fx, 32, Q_exc, -1);
+ move16();
+ pt_fx += 32;
+ }
+
+ if (L_frame == L_FRAME16k)
+ {
+ y_gain4_fx[j + 2] = Comp_band_log_ener(pt_fx, 32, Q_exc, -1);
+ move16();
+ //pt_fx += 32;
+
+ y_gain4_fx[j + 3] = Comp_band_log_ener(pt_fx, 64, Q_exc, -1);
+ move16();
+ pt_fx += 64;
+ }
+
+ return;
+}
+
/*-------------------------------------------------------------------*
* gsc_gainQ()
*
@@ -312,6 +360,7 @@ static void GSC_gain_adj(
*-------------------------------------------------------------------*/
static void GSC_gain_adj_ivas_fx(
const Word16 coder_type, /* i : Coder type */
+ const int16_t Mbands_gn, /* i : Number of band */
const Word32 core_brate, /* i : Bit rate */
const Word16 mean_g, /* i : Average gain Q12 */
Word16 *old_y_gain, /* i/o: Previous frame dequantized vector */
@@ -324,7 +373,7 @@ static void GSC_gain_adj_ivas_fx(
IF(NE_16(coder_type, INACTIVE) && NE_16(coder_type, UNVOICED))
{
- FOR(i = 0; i < MBANDS_GN; i++)
+ FOR(i = 0; i < Mbands_gn; i++)
{
old_y_gain[i] = y_gain_tmp[i];
move16();
@@ -368,7 +417,7 @@ static void GSC_gain_adj_ivas_fx(
}
/*mimic ACELP decay of energy for low rates*/
- FOR(i = 0; i < MBANDS_GN; i++)
+ FOR(i = 0; i < Mbands_gn; i++)
{
old_y_gain[i] = y_gain_tmp[i];
move16();
@@ -574,7 +623,12 @@ Word16 gsc_gaindec_ivas_fx( /* o : average frequency gain *
{
Word16 idx_g_fx, i;
Word16 mean_4g_fx;
+ Word16 Mbands_gn = MBANDS_GN;
Word16 y_gain_tmp3_fx[MBANDS_GN];
+ IF( EQ_16(st_fx->L_frame, L_FRAME16k ) )
+ {
+ Mbands_gn = MBANDS_GN16k;
+ }
test();
test();
@@ -681,22 +735,42 @@ Word16 gsc_gaindec_ivas_fx( /* o : average frequency gain *
}
ELSE
{
- idx_g_fx = (Word16)get_next_indice(st_fx, 6);
- VDQ_vec_fx(y_gainQ_fx, YG_mean16_fx, YG_dicMR_1_fx, idx_g_fx, 4);
+ if ( st_fx->L_frame == L_FRAME )
+ {
+ idx_g_fx = (Word16) get_next_indice( st_fx, 6 );
+ VDQ_vec_fx( y_gainQ_fx, YG_mean16_fx, YG_dicMR_1_fx, idx_g_fx, 4 );
- idx_g_fx = (Word16)get_next_indice(st_fx, 5);
- VDQ_vec_fx(y_gainQ_fx + 4, YG_mean16_fx + 4, YG_dicMR_2_fx, idx_g_fx, 4);
+ idx_g_fx = (Word16) get_next_indice( st_fx, 5 );
+ VDQ_vec_fx( y_gainQ_fx + 4, YG_mean16_fx + 4, YG_dicMR_2_fx, idx_g_fx, 4 );
- idx_g_fx = (Word16)get_next_indice(st_fx, 5);
- VDQ_vec_fx(y_gainQ_fx + 8, YG_mean16_fx + 8, YG_dicMR_3_fx, idx_g_fx, 4);
+ idx_g_fx = (Word16) get_next_indice( st_fx, 5 );
+ VDQ_vec_fx( y_gainQ_fx + 8, YG_mean16_fx + 8, YG_dicMR_3_fx, idx_g_fx, 4 );
- idx_g_fx = (Word16)get_next_indice(st_fx, 4);
- VDQ_vec_fx(y_gainQ_fx + 12, YG_mean16_fx + 12, YG_dicMR_4_fx, idx_g_fx, 4);
+ idx_g_fx = (Word16) get_next_indice( st_fx, 4 );
+ VDQ_vec_fx( y_gainQ_fx + 12, YG_mean16_fx + 12, YG_dicMR_4_fx, idx_g_fx, 4 );
+ }
+ else
+ {
+ idx_g_fx = get_next_indice( st_fx, 7 );
+ VDQ_vec_fx( y_gainQ_fx, YG_mean16HR_fx, YG_dicHR_1_fx, idx_g_fx, 4 );
+
+ idx_g_fx = get_next_indice( st_fx, 6 );
+ VDQ_vec_fx( y_gainQ_fx + 4, YG_mean16HR_fx + 4, YG_dicHR_2_fx, idx_g_fx, 4 );
+
+ idx_g_fx = get_next_indice( st_fx, 6 );
+ VDQ_vec_fx( y_gainQ_fx + 8, YG_mean16HR_fx + 8, YG_dicHR_3_fx, idx_g_fx, 4 );
+
+ idx_g_fx = get_next_indice( st_fx, 6 );
+ VDQ_vec_fx( y_gainQ_fx + 12, YG_mean16HR_16kHz_fx, YG_dicHR_4_16kHz_fx, idx_g_fx, 4 );
+
+ idx_g_fx = get_next_indice( st_fx, 3 );
+ VDQ_vec_fx( y_gainQ_fx + 16, YG_meanL2G_16kHz_fx, YG_dicL2G_16kHz_fx, idx_g_fx, 2 );
+ }
}
}
/* Gain adjustment to fit ACELP generic inactive coding gain at low rate */
- GSC_gain_adj_ivas_fx(coder_type_fx, core_brate_fx, mean_4g_fx, old_y_gain_fx, y_gainQ_fx, y_gainQ_fx);
+ GSC_gain_adj_ivas_fx(coder_type_fx, Mbands_gn, core_brate_fx, mean_4g_fx, old_y_gain_fx, y_gainQ_fx, y_gainQ_fx);
return mean_4g_fx;
diff --git a/lib_com/gs_inact_switching_fx.c b/lib_com/gs_inact_switching_fx.c
index 2602902d75a8ceecd0f7d6d2c9dec009610f4a39..8a52a8efcbeb14180e45dc6f63afe612a127937b 100644
--- a/lib_com/gs_inact_switching_fx.c
+++ b/lib_com/gs_inact_switching_fx.c
@@ -152,3 +152,122 @@ void Inac_swtch_ematch_fx(
return;
}
+
+
+void Inac_switch_ematch_ivas_fx(
+ Word16 exc2[], /* i/o: CELP/GSC excitation buffer Q_exc*/
+ Word16 dct_exc_tmp[], /* i : GSC excitation in DCT domain */
+ Word16 lt_ener_per_band[], /* i/o: Long term energy per band Q12 */
+ const Word16 coder_type, /* i : Coding mode */
+ const Word16 L_frame, /* i : Frame lenght */
+ const Word32 total_brate, /* i : total bit rate */
+ const Word16 Q_exc /* i : input and output format of exc2 */
+ , const Word16 bfi /* i : frame lost indicator */
+ , const Word16 last_core, /* i : Last core used */
+ const Word16 last_codec_mode /* i : Last codec mode */
+ , const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag*/
+ const Word16 element_mode /* i : element mode */
+)
+{
+ Word16 Ener_per_bd[MBANDS_GN16k];
+ Word16 ftmp;
+ Word16 *pt_exc;
+ Word16 j, i;
+
+ Word16 exp, frac;
+ Word32 L_tmp;
+
+ /*--------------------------------------------------------------------------
+ * average energy per band
+ *--------------------------------------------------------------------------*/
+
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF((EQ_16(coder_type, AUDIO) || (EQ_16(coder_type, UNVOICED) && EQ_16(tdm_low_rate_mode, 1))) && bfi == 0)
+ {
+ Ener_per_band_comp_ivas_fx(dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame);
+
+ /* reset long-term energy per band */
+ FOR(i = 0; i < MBANDS_GN; i++)
+ {
+ lt_ener_per_band[i] = Ener_per_bd[i];
+ move16();
+ }
+
+ }
+ ELSE IF(EQ_16(coder_type, VOICED) || EQ_16(coder_type, GENERIC) || EQ_16(coder_type, TRANSITION) || NE_16(last_core, ACELP_CORE) || NE_16(last_codec_mode, MODE1) || (GT_16(element_mode, EVS_MONO) && EQ_16(coder_type, UNVOICED)))
+ {
+ /* Find spectrum and energy per band for GC and VC frames */
+ edct_16fx(exc2, dct_exc_tmp, L_frame, 5, element_mode);
+
+ Ener_per_band_comp_ivas_fx(dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame);
+
+ /* reset long-term energy per band */
+ FOR(i = 0; i < MBANDS_GN; i++)
+ {
+ lt_ener_per_band[i] = Ener_per_bd[i];
+ move16();
+ }
+ }
+ ELSE IF(EQ_16(coder_type, INACTIVE) && LE_32(total_brate, MAX_GSC_INACTIVE_BRATE))
+ {
+ /* Find spectrum and energy per band for inactive frames */
+ edct_16fx(exc2, dct_exc_tmp, L_frame, 5, element_mode);
+ Ener_per_band_comp_ivas_fx(dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame);
+
+ /* More agressive smoothing in the first 50 frames */
+ pt_exc = dct_exc_tmp;
+ move16();
+ FOR(i = 0; i < MBANDS_GN; i++)
+ {
+ /* Compute smoothing gain to apply with gain limitation */
+ L_tmp = L_mult(ALPHA0_FX, lt_ener_per_band[i]); /*Q(15+12+1)=Q(28) */
+ L_tmp = L_mac(L_tmp, BETA0_FX, Ener_per_bd[i]); /*Q28 */
+ lt_ener_per_band[i] = round_fx(L_tmp); /*Q12 */
+
+ ftmp = sub(lt_ener_per_band[i], Ener_per_bd[i]); /*Q12 */
+
+ /* ftmp = (float)pow(10, ftmp);= pow(2,3.321928*ftmp);*/
+
+ L_tmp = L_mult(27213, ftmp); /*Q(13+12+1)=Q26 ; 27213=3.321928 in Q13 */
+ L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */
+ frac = L_Extract_lc(L_tmp, &exp); /* Extract exponent of ftmp */
+ ftmp = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */
+ /* output of Pow2() will be: */
+ /* 16384 < Pow2() <= 32767 */
+
+ exp = sub(exp, 14);
+ IF(LT_16(i, 2))
+ {
+ FOR(j = 0; j < 8; j++)
+ {
+ L_tmp = L_mult(*pt_exc, ftmp); /* Q_exc*Q0 -> Q(Q_exc+1) */
+ L_tmp = L_shl(L_tmp, add(exp, 15)); /* Q(Q_exc+1) -> Q(16+Q_exc)*/
+ *pt_exc = round_fx(L_tmp);
+ pt_exc++;
+ }
+ }
+ ELSE
+ {
+ FOR(j = 0; j < 16; j++)
+ {
+ L_tmp = L_mult(*pt_exc,ftmp); /* Q_exc*Q0 -> Q(Q_exc+1) */
+ L_tmp = L_shl(L_tmp, add(exp,15)); /* Q(Q_exc+1) -> Q(16+Q_exc)*/
+ *pt_exc = round_fx(L_tmp); /*Q_exc*/
+ pt_exc++;
+ }
+ }
+ }
+
+ /* Going back to time */
+ edct_16fx(dct_exc_tmp, exc2, L_frame, 5, element_mode);
+ }
+
+ return;
+}
\ No newline at end of file
diff --git a/lib_com/gs_noisefill_fx.c b/lib_com/gs_noisefill_fx.c
index 4fa9d6ae6214322665bc85dc000868b889fae7c5..8c6d55ffe311e166d9bed35e46e1f0949f8fff3f 100644
--- a/lib_com/gs_noisefill_fx.c
+++ b/lib_com/gs_noisefill_fx.c
@@ -1262,11 +1262,11 @@ void highband_exc_dct_in_ivas_fx(
test();
IF(EQ_32(core_brate, ACELP_8k00) && NE_16(bwidth, NB))
{
- Ener_per_band_comp_fx(exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, add(last_bin, 1), 0);
+ Ener_per_band_comp_ivas_fx(exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, add(last_bin, 1), 0, L_frame);
}
ELSE
{
- Ener_per_band_comp_fx(exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1);
+ Ener_per_band_comp_ivas_fx(exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1, L_frame);
IF(LT_16(nb_subfr, 4) && LT_16(L_frame, L_FRAME16k))
{
diff --git a/lib_com/isf_dec_amr_wb_fx.c b/lib_com/isf_dec_amr_wb_fx.c
index 11a9e7dd0b1a6773cb39fcf39e93e01b7abd8548..52aec845fdfbaa7b2b50ada86d3992550b95282e 100644
--- a/lib_com/isf_dec_amr_wb_fx.c
+++ b/lib_com/isf_dec_amr_wb_fx.c
@@ -160,7 +160,12 @@ void isf_dec_amr_wb_fx(
* Check ISF stability : distance between old ISF and current ISF
*------------------------------------------------------------------*/
- st->stab_fac_fx = lsf_stab_fx(isf_new, st->lsf_old_fx, 1, st->L_frame);
+ IF(EQ_16(st->element_mode, EVS_MONO)) {
+ st->stab_fac_fx = lsf_stab_fx(isf_new, st->lsf_old_fx, 1, st->L_frame);
+ }
+ else {
+ st->stab_fac_fx = lsf_stab_ivas_fx(isf_new, st->lsf_old_fx, 1, st->L_frame);
+ }
return;
}
diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h
index bd43fdb84abf1d299cbd7d86625b10de5417be0d..63843b4c060294ef71803e0cb60f347d7f0bb62b 100644
--- a/lib_com/ivas_cnst.h
+++ b/lib_com/ivas_cnst.h
@@ -590,6 +590,8 @@ typedef enum
#define STEREO_DFT_COH_MAXBAND 6
#define STEREO_DFT_SID_GIPD_NBITS 2
#define STEREO_DFT_FD_FILT 0.9f
+#define STEREO_DFT_FD_FILT_Q31 1932735283
+#define STEREO_DFT_FD_FILT_COMP_Q31 214748364 /* 1.0 - STEREO_DFT_FD_FILT */
#define STEREO_DFT_CNG_ITD_CNT 8
diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h
index c4b7a10dd7d754a07b427829d7e2957d06be3e50..c6672ea6ec0465b72eb88131affb8da01892832e 100644
--- a/lib_com/ivas_prot.h
+++ b/lib_com/ivas_prot.h
@@ -2394,6 +2394,17 @@ void tdm_SCh_lsf_reuse_fx(
);
#endif
+
+void tdm_SCh_lsf_reuse_ivas_fx(
+ const int16_t enc_dec, /* i : encoder/decoder flag */
+ const int32_t element_brate, /* i : element bitrate */
+ Word16 lsf_new[M], /* i/o: LSFs at the end of the frame */
+ Word16 lsp_new[M], /* i/o: LSPs at the end of the frame */
+ const Word16 tdm_lsfQ_PCh[M], /* i : primary channel LSFs (log2(2.56)) */
+ const Word16 lsf_wgts[M], /* i : LSF weights Q15? */
+ int16_t *beta_index /* i/o: quantization index */
+);
+
void tdm_SCh_lsf_reuse(
const int16_t enc_dec, /* i : encoder/decoder flag */
const int32_t element_brate, /* i : element bitrate */
diff --git a/lib_com/lsf_tools.c b/lib_com/lsf_tools.c
index e0634bdc7859936c56dd2a3495cd68f792cca8eb..6b4e9943e80ba7b95516b93ab293016f9d302546 100644
--- a/lib_com/lsf_tools.c
+++ b/lib_com/lsf_tools.c
@@ -2972,13 +2972,13 @@ void create_IDCT_N_Matrix_fx(
r_flip = len - 1;
FOR ( r = 0; r < ( len / 2 ); r_flip-- )
{
- r++;
#define WMC_TOOL_SKIP
ptr[r_flip][c] = ptr[r][c]; /* flipped */
ptr[r_flip][c1] = -( ptr[r][c1] ); /* flipped and sign swapped */
MOVE( 2 );
MULT( 1 ); /* for negate */
#undef WMC_TOOL_SKIP
+ r++;
}
}
diff --git a/lib_com/lsf_tools_fx.c b/lib_com/lsf_tools_fx.c
index 8a704846f61e1483cce34dab3ae9f4124fd2d26e..24586a23c9024ad4cfc53201585e21dbd62fd2f7 100644
--- a/lib_com/lsf_tools_fx.c
+++ b/lib_com/lsf_tools_fx.c
@@ -2216,6 +2216,110 @@ Word16 lsf_stab_fx( /* o : LP filter stability Q15*/
return tmp;
}
+
+/*========================================================================*/
+/* FUNCTION : lsf_stab_ivas_fx() */
+/*------------------------------------------------------------------------*/
+/* PURPOSE : Check LSF stability (distance between old LSFs and */
+/* current LSFs) */
+/*------------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (Word16) Opt_AMR_WB : flag indicating AMR-WB IO mode */
+/* _ (Word16*) lsf : LSPs from past frame Q(x2.56) */
+/* _ (Word16*) lsfold : LSPs from past frame Q(x2.56) */
+/*------------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/*------------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/*------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : */
+/* _ (Word16) stab_fac_fx : LP filter stability Q15 */
+/*========================================================================*/
+Word16 lsf_stab_ivas_fx( /* o : LP filter stability Q15*/
+ const Word16 *lsf, /* i : LSF vector Q(x2.56)*/
+ const Word16 *lsfold, /* i : old LSF vector Q(x2.56)*/
+ const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */
+ const Word16 L_frame /* i : frame length */
+)
+{
+ Word16 i, m;
+ Word32 L_tmp;
+ Word16 tmp, e;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+
+ /*-------------------------------------------------------------------*
+ * Check stability on lsf: distance between old lsf and current lsf
+ *-------------------------------------------------------------------*/
+ IF(Opt_AMR_WB)
+ {
+ m = M - 1;
+ move16();
+ //tmp = sub(lsf[0], lsfold[0]);
+ tmp = extract_l(L_sub(lsf[0], (UWord16)lsfold[0]));
+ //L_tmp = L_mult(tmp, tmp); /* Q1 */
+ L_tmp = L_mult0(shr(tmp, 1), tmp); /* Q-1 */
+ FOR(i = 1; i < m; i++)
+ {
+ //tmp = sub(lsf[i], lsfold[i]);
+ tmp = extract_l(L_sub(lsf[i], (UWord16)lsfold[i]));
+ //L_tmp = L_mac(L_tmp, tmp, tmp); /* Q1 */
+ L_tmp = L_mac0(L_tmp, shr(tmp, 1), tmp); /* Q-1 */
+ }
+ }
+ ELSE
+ {
+ m = M;
+ move16();
+ L_tmp = 0;
+ move32();
+ FOR(i = 0; i < m; i++)
+ {
+ //tmp = sub(lsf[i], lsfold[i]);
+ tmp = extract_l(L_sub(lsf[i], (UWord16)lsfold[i]));
+ //L_tmp = L_mac(L_tmp, tmp, tmp); /* Q1 */
+ L_tmp = L_mac0(L_tmp, shr(tmp, 1), tmp); /* Q-1 */
+ }
+ }
+
+ e = norm_l(L_tmp);
+ L_tmp = L_shl(L_tmp, e); /*Q(0+e)*/
+
+ IF(L_frame == L_FRAME16k)
+ {
+ /*stab_fac = (float)(1.25f - (tmp/625000.0f));*/
+ L_tmp = Mpy_32_16_1(L_tmp, 16777); /* 30-eQ(-1+e)*-21Q36 = 30-21-eQ31-9+e */
+ }
+ ELSE
+ {
+ /* stab_fac = (float)(1.25f - (tmp1/400000.0f*2.56=1024000)) */
+ L_tmp = Mpy_32_16_1(L_tmp, 26214); /* 30-eQ(-1+e)*-21Q36 = 30-21-eQ31-9+e */
+ }
+
+ e = sub(30 - 21 - 1, e);
+#ifdef BASOP_NOGLOB
+ tmp = round_fx_o(L_shl_o(L_tmp, e, &Overflow), &Overflow); /*Q12*/
+#else /* BASOP_NOGLOB */
+ tmp = round_fx(L_shl(L_tmp, e)); /*Q14*/
+#endif /* BASOP_NOGLOB */
+
+ //tmp = sub(20480, tmp); /* 1.25 - tmp in Q14 */
+ tmp = sub(5120, tmp); /* 1.25 - tmp in Q12 */
+#ifdef BASOP_NOGLOB
+ //tmp = shl_o(tmcp, 1, &Overflow); /* Q14 -> Q15 with saturation */
+ tmp = shl_sat(tmp, 3); /* Q12 -> Q15 with saturation */
+#else /* BASOP_NOGLOB */
+ tmp = shl(tmp, 1); /* Q14 -> Q15 with saturation */
+#endif
+
+ tmp = s_max(tmp, 0);
+
+ return tmp;
+}
+
/*-------------------------------------------------------------------*
* lsp2isp()
*
diff --git a/lib_com/mslvq_com_fx.c b/lib_com/mslvq_com_fx.c
index 1e8f89d64e2f1a65cb22e281e58b854f3bcf76a8..1ead3ba600ab240a1bbc69ffb60dd55bffefa58f 100644
--- a/lib_com/mslvq_com_fx.c
+++ b/lib_com/mslvq_com_fx.c
@@ -55,6 +55,15 @@ static void divide_64_32_fx(Word16 *xs, Word32 y, Word32 *result, Word32 *rem);
static Word16
decode_indexes_fx(Word16 * index, Word16 no_bits, const Word16 * p_scales, Word16 * p_no_scales,
Word32 * p_offset_scale1, Word32 * p_offset_scale2, Word16 * x_lvq, Word16 mode_glb, Word16 *scales);
+static int16_t decode_indexes_ivas_fx(
+ Word16 *index,
+ const Word16 no_bits,
+ const Word16 *p_scales, //Q11
+ const Word16 prediction_flag,
+ Word16 *x_lvq, //Q0
+ const Word16 mode_glb,
+ Word16 * scales_mslvq /* o: scale values for the decoded MSLVQ LSF codevector Q11*/
+);
static Word32 divide_32_32_fx(Word32 y, Word32 x, Word32 * rem);
static Word16 divide_16_16_fx(Word16 y, Word16 x, Word16 *rem);
static int16_t decode_indexes_ivas_fx(
@@ -675,7 +684,7 @@ Word16 deindex_lvq_ivas_fx(
FOR( i = 0; i < LATTICE_DIM; i++ )
{
L_tmp = L_mult( x_lvq[i], scales_mslvq[0] ); /* Q1+Q11+Q1 = Q13 */
- L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_p_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */
+ L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_p_ivas_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */
x_lvq[i] = round_fx( L_tmp );
}
}
@@ -684,7 +693,7 @@ Word16 deindex_lvq_ivas_fx(
FOR( i = LATTICE_DIM; i < 2 * LATTICE_DIM; i++ )
{
L_tmp = L_mult( x_lvq[i], scales_mslvq[1] ); /* Q1+Q11+Q1 = Q13 */
- L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_p_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */
+ L_tmp = L_shl( Mult_32_16( L_tmp, shl( sigma_p_ivas_fx[mode][i], 3 ) ), 15 ); /* Q13 + Q2 +x2.56 -Q15 */
x_lvq[i] = round_fx( L_tmp );
}
}
@@ -720,7 +729,8 @@ Word16 deindex_lvq_cng_fx(
Word16 ber_flag;
/* the MSLVQ structure in the second LP-CNG stage depends on the index from the first stage */
- mode_glb = add(START_CNG, idx_cv);
+ mode_glb = add(START_CNG, idx_cv);
+
mode = add(LVQ_COD_MODES, idx_cv);
p_scales = &scales_fx[0][0];
@@ -751,6 +761,63 @@ Word16 deindex_lvq_cng_fx(
}
+/*----------------------------------------------------------------------------------------------------*
+ * deindex_lvq_cng()
+ * Note:
+ * The sampling frequency for the LVQ CNG decoder frame can be determined by checking the fully decoded
+ * value of the highest order LSF coefficient. Thus sampling rate information, nor extra codebooks are
+ * not needed for deindex_lvq_cng(), since it is embedded inside the LSF codebooks.
+ *----------------------------------------------------------------------------------------------------*/
+
+Word16 deindex_lvq_cng_ivas_fx(
+ Word16 *index, /* i: index to be decoded, as an array of 3 short */
+ Word16 *x_lvq, /* o: decoded codevector Q9 */
+ Word16 idx_cv, /* i: relative mode_lvq, wrt START_CNG */
+ Word16 no_bits /* i: number of bits for lattice */
+)
+{
+ Word16 i;
+ Word32 L_tmp;
+ const Word16 *p_scales;
+ Word16 mode_glb, mode;
+ //note_ : renamed from scales as global declaration of scales is causing warning
+ Word16 scales_mslvq[2];
+ Word16 ber_flag;
+
+ /* the MSLVQ structure in the second LP-CNG stage depends on the index from the first stage */
+ mode_glb = add(START_CNG_IVAS, idx_cv);
+
+ mode = add(LVQ_COD_MODES, idx_cv);
+
+ p_scales = &scales_ivas_fx[0][0];
+ move16();
+ //ber_flag =
+ // decode_indexes_fx(index, no_bits, p_scales, p_no_scales, p_offset_scale1, p_offset_scale2, x_lvq, mode_glb, scales_mslvq);
+ ber_flag =
+ decode_indexes_ivas_fx(index, no_bits, p_scales, 0, x_lvq, mode_glb, scales_mslvq);
+
+ FOR(i = 0; i < LATTICE_DIM; i++)
+ {
+ L_tmp = L_mult(x_lvq[i], scales_mslvq[0]); /* Q1+Q11+Q1 = Q13 */
+ L_tmp = L_shl(Mult_32_16(L_tmp, shl(sigma_MSLVQ_fx[mode][i], 3)), 15); /* Q13 + Q2 +x2.56 -Q15 */
+ x_lvq[i] = round_fx(L_tmp);
+ }
+ FOR(i = LATTICE_DIM; i < 2 * LATTICE_DIM; i++)
+ {
+ L_tmp = L_mult(x_lvq[i], scales_mslvq[1]); /* Q1+Q11+Q1 = Q13 */
+ L_tmp = L_shl(Mult_32_16(L_tmp, shl(sigma_MSLVQ_fx[mode][i], 3)), 15); /* Q13 + Q2 +x2.56 -Q15 */
+ x_lvq[i] = round_fx(L_tmp);
+ }
+
+ /* check if permutting needed */
+ IF(cng_sort[idx_cv])
+ {
+ permute_fx(x_lvq, perm_MSLVQ[idx_cv]);
+ }
+
+ return ber_flag;
+}
+
/* combinatorial indexing */
static void idx2c_fx(
Word16 n, /* i : total number of positions (components)*/
diff --git a/lib_com/prot.h b/lib_com/prot.h
index f6ef4d6e995c641a8c1b34a2f0eb5f320bb86a3a..4c93e956b02af10bca34a405855ad8a669272314 100644
--- a/lib_com/prot.h
+++ b/lib_com/prot.h
@@ -4600,6 +4600,32 @@ ivas_error acelp_core_dec(
const int16_t read_sid_info /* i : read SID info flag */
);
+#ifdef IVAS_FLOAT_FIXED
+ivas_error acelp_core_dec_ivas_fx(
+ Decoder_State *st, /* i/o: decoder state structure */
+ float output[], /* o : synthesis @internal Fs */
+ float synth[], /* o : synthesis */
+ float save_hb_synth[], /* o : HB synthesis */
+ float bwe_exc_extended[], /* i/o: bandwidth extended excitation */
+ float *voice_factors, /* o : voicing factors */
+ float old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */
+ const int16_t sharpFlag, /* i : formant sharpening flag */
+ float pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */
+ int16_t *unbits, /* o : number of unused bits */
+ int16_t *sid_bw, /* o : 0-NB/WB, 1-SWB SID */
+ STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */
+ const float tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */
+ const float tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */
+ const int16_t use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */
+ const int16_t last_element_mode, /* i : last element mode */
+ const int32_t last_element_brate, /* i : last element bitrate */
+ const int16_t flag_sec_CNA, /* i : CNA flag for secondary channel */
+ const int16_t nchan_out, /* i : number of output channels */
+ STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */
+ const int16_t read_sid_info /* i : read SID info flag */
+);
+#endif
+
void bass_psfilter_init(
BPF_DEC_HANDLE hBPF /* o : BPF data handle */
);
@@ -8840,6 +8866,17 @@ void generate_stereo_masking_noise_fx(
STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */
const int16_t nchan_out /* i : number of output channels */
);
+
+void generate_stereo_masking_noise_16fx(
+ Word16 *syn, /* i/o: time-domain signal */
+ Word16 Q_syn,
+ Decoder_State *st, /* i/o: decoder state structure */
+ STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i : TD stereo structure */
+ const int16_t flag_sec_CNA, /* i : CNA flag for secondary channel */
+ const int16_t fadeOut, /* i : only fade out of previous state */
+ STEREO_CNG_DEC_HANDLE hStereoCng, /* i : Stereo CNG handle */
+ const int16_t nchan_out /* i : number of output channels */
+);
#endif
void apply_scale_flt(
@@ -8968,6 +9005,12 @@ void FdCng_decodeSID_flt(
Decoder_State *st /* i/o: decoder state structure */
);
+#ifdef IVAS_FLOAT_FIXED
+void FdCng_decodeSID_ivas_fx(
+ Decoder_State *st /* i/o: decoder state structure */
+);
+#endif
+
void FdCng_exc_flt(
HANDLE_FD_CNG_COM hFdCngCom,
int16_t *CNG_mode,
diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h
index 9b194e890d1b0cf2478c2d55765b8c2b1b0aaa1d..6f617fafa317acbfed1d69be9d61a0ca208c511e 100644
--- a/lib_com/prot_fx2.h
+++ b/lib_com/prot_fx2.h
@@ -883,6 +883,13 @@ Word16 lsf_stab_fx( /* o : LP filter stability Q15*/
const Word16 L_frame /* i : frame length */
);
+Word16 lsf_stab_ivas_fx( /* o : LP filter stability Q15*/
+ const Word16 *lsf, /* i : LSF vector Q(x2.56)*/
+ const Word16 *lsfold, /* i : old LSF vector Q(x2.56)*/
+ const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */
+ const Word16 L_frame /* i : frame length */
+);
+
void reorder_isf_fx(
Word16 *isf, /* i/o: ISFs in the frequency domain (0..0.5) */
const Word16 min_dist, /* i : minimum required distance */
@@ -928,6 +935,16 @@ Word16 vq_dec_lvq_fx(
Word16 *p_no_scales_p
);
+Word16 vq_dec_lvq_ivas_fx(
+ Word16 sf_flag, /* i : safety net flag */
+ Word16 x[], /* o : Decoded vector Q(x2.56)*/
+ Word16 indices[], /* i : Indices */
+ Word16 stages, /* i : Number of stages */
+ Word16 N, /* i : Vector dimension */
+ Word16 mode, /* (i): mode_lvq, or mode_lvq_p */
+ Word16 no_bits /* (i): no. bits for lattice */
+);
+
void a2rc_fx(const Word16 *a, Word16 *refl, Word16 lpcorder);
void lsp_weights_fx(
@@ -1550,7 +1567,14 @@ void Ener_per_band_comp_fx(
const Word16 Mband, /* i : Max band */
const Word16 Eflag
);
-
+void Ener_per_band_comp_ivas_fx(
+ const Word16 exc_diff_fx[], /* i : target signal Q_exc_diff */
+ Word16 y_gain4_fx[], /* o : Energy per band to quantize Q12 */
+ const Word16 Q_exc, /* i : frame length */
+ const Word16 Mband, /* i : Max band */
+ const Word16 Eflag, /* i : flag of highest band */
+ const int16_t L_frame /* i : frame length */
+);
void Comp_and_apply_gain_fx(
Word16 exc_diffQ[], /* i/o: Quantized excitation */
Word16 Ener_per_bd_iQ[], /* i : Target ener per band Q13 */
@@ -2563,6 +2587,19 @@ void tbe_celp_exc(
Word16 *bwe_exc_fx /* i/o: bandwitdh extension signal */
);
+void tbe_celp_exc_ivas(
+ const int16_t element_mode, /* i : element mode */
+ const int16_t idchan, /* i : channel ID */
+ const Word16 L_frame_fx, /* i : Frame lenght */
+ const int16_t L_subfr, /* i : subframe length */
+ const Word16 i_subfr_fx, /* i : sub frame */
+ const Word16 T0_fx, /* i : Integer pitch */
+ const Word16 T0_frac_fx, /* i : Fractional part of the pitch */
+ Word16 *error_fx, /* i/o: Error */
+ Word16 *bwe_exc_fx, /* i/o: bandwitdh extension signal */
+ const int16_t tdm_LRTD_flag /* i : LRTD stereo mode flag */
+);
+
void flip_and_downmix_generic_fx(
Word16 i[], /* i : i spectrum */
Word16 output[], /* o : output spectrum */
@@ -2816,7 +2853,6 @@ void prep_tbe_exc_fx(
#endif
);
-#ifdef IVAS_FLOAT_FIXED
void prep_tbe_exc_ivas_fx(
const Word16 L_frame_fx, /* i : length of the frame */
#if 1//def ADD_IVAS_TBE_CODE
@@ -2845,7 +2881,6 @@ void prep_tbe_exc_ivas_fx(
#endif
);
-#endif
Word16 swb_formant_fac_fx( /* o : Formant filter strength [0,1] */
const Word16 lpc_shb2, /* Q12 i : 2nd HB LPC coefficient */
Word16* tilt_mem /* i/o: Tilt smoothing memory */
@@ -3492,6 +3527,14 @@ Word16 deindex_lvq_fx(
Word16 *p_no_scales
);
+Word16 deindex_lvq_ivas_fx(
+ Word16 *index, /* i : index to be decoded, as an array of 3 Word16 */
+ Word16 *x_lvq, /* o : decoded codevector Q(x2.56) */
+ Word16 mode, /* i : LVQ coding mode/MSLVQ structure index (select scales & no_lead ), or idx_cv for CNG case */
+ Word16 sf_flag, /* i : safety net flag */
+ Word16 no_bits /* i : number of bits for lattice */
+);
+
Word16 deindex_lvq_cng_fx(
Word16 *index, /* i : index to be decoded, as an array of 3 short */
Word16 *x_lvq, /* o : decoded codevector Q9*/
@@ -3502,6 +3545,12 @@ Word16 deindex_lvq_cng_fx(
Word16 * p_no_scales
);
+Word16 deindex_lvq_cng_ivas_fx(
+ Word16 *index, /* i: index to be decoded, as an array of 3 short */
+ Word16 *x_lvq, /* o: decoded codevector Q9 */
+ Word16 idx_cv, /* i: relative mode_lvq, wrt START_CNG */
+ Word16 no_bits /* i: number of bits for lattice */
+);
//lsp_convert_poly_fx.c
Word16 lsp_convert_poly_fx(
@@ -4347,7 +4396,6 @@ Word16 est_tilt_fx( /* o : tilt of the code
#endif
);
-#ifdef IVAS_FLOAT_FIXED
Word16 est_tilt_ivas_fx( /* o : tilt of the code Q15 */
const Word16 *exc, /* i : adaptive excitation vector Qx */
const Word16 gain_pit, /* i : adaptive gain Q14 */
@@ -4360,7 +4408,6 @@ Word16 est_tilt_ivas_fx( /* o : tilt of the code Q15
const Word16 flag_tilt /* i : flag for special tilt */
#endif
);
-#endif
Word16 Est_tilt2( /* o : tilt of the code */
const Word16 *exc, /* i : adaptive excitation vector Qx */
@@ -5148,6 +5195,26 @@ void enhancer_fx(
const Word16 Q_exc /* i : Q of the excitation */
);
+void enhancer_ivas_fx(
+ const Word16 codec_mode, /* i : flag indicating Codec Mode */
+ const Word32 core_brate, /* i : decoder bitrate */
+ const int16_t cbk_index, /* i : */
+ const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */
+ const Word16 coder_type, /* i : coder type */
+ const Word16 i_subfr, /* i : subframe number */
+ const Word16 L_frame, /* i : frame size */
+ const Word16 voice_fac, /* i : subframe voicing estimation Q15 */
+ const Word16 stab_fac, /* i : LP filter stablility measure Q15 */
+ Word32 norm_gain_code, /* i : normalised innovative cb. gain Q16 */
+ const Word16 gain_inov, /* i : gain of the unscaled innovation Q12 */
+ Word32 *gc_threshold,/* i/o: gain code threshold Q16 */
+ Word16 *code, /* i/o: innovation Q12 */
+ Word16 *exc2, /* i/o: adapt. excitation/total exc. Q_exc*/
+ const Word16 gain_pit, /* i : quantized pitch gain Q14 */
+ struct dispMem_fx *dm_fx, /* i/o: phase dispersion algorithm memory */
+ const Word16 Q_exc /* i : Q of the excitation */
+);
+
Word16 E_UTIL_enhancer(
Word16 voice_fac, /* i : subframe voicing estimation Q15 */
Word16 stab_fac, /* i : LP filter stability measure Q15 */
@@ -5242,6 +5309,22 @@ void Inac_swtch_ematch_fx(
, const short last_core, /* i : Last core used */
const short last_codec_mode /* i : Last codec mode */
);
+
+void Inac_switch_ematch_ivas_fx(
+ Word16 exc2[], /* i/o: CELP/GSC excitation buffer Q_exc*/
+ Word16 dct_exc_tmp[], /* i : GSC excitation in DCT domain */
+ Word16 lt_ener_per_band[], /* i/o: Long term energy per band Q12 */
+ const Word16 coder_type, /* i : Coding mode */
+ const Word16 L_frame, /* i : Frame lenght */
+ const Word32 core_brate, /* i : Core bit rate */
+ const Word16 Q_exc /* i : input and output format of exc2 */
+ , const Word16 bfi /* i : frame lost indicator */
+ , const Word16 last_core, /* i : Last core used */
+ const Word16 last_codec_mode /* i : Last codec mode */
+ , const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag*/
+ const Word16 element_mode /* i : element mode */
+);
+
//igf_base_fx.c
Word16 IGF_ApplyTransFac( /**< out: Q0 | multiplication factor */
const Word16 val, /**< in: Q15 | input value for multiplication, Q15 */
@@ -5618,15 +5701,22 @@ void swb_CNG_dec_fx(
const Word16 Qsyn /* i : Q value of ACELP core synthesis */
);
-#ifdef IVAS_FLOAT_FIXED
-void td_cng_dec_init_ivas_fx(
- DEC_CORE_HANDLE st /* i/o: decoder state structure */
+void swb_CNG_dec_ivas_fx(
+ Decoder_State *st_fx, /* i/o: State structure */
+ const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz */
+ Word16 *shb_synth_fx, /* o : high-band CNG synthesis */
+ const Word16 sid_bw, /* i : 0-NB/WB, 1-SWB SID */
+ const Word16 Qsyn /* i : Q value of ACELP core synthesis */
);
-#endif
+
void td_cng_dec_init(
DEC_CORE_HANDLE st /* i/o: decoder state structure */
);
+void td_cng_dec_init_ivas_fx(
+ DEC_CORE_HANDLE st /* i/o: decoder state structure */
+);
+
//wavadjust_fec_dec_fx.c
void set_state(Word16 *state, Word16 num, Word16 N);
void concealment_init_x(Word16 N, void *_plcInfo);
@@ -6182,6 +6272,23 @@ void init_tcx_cfg_fx(
, Word16 *gain_buf /*Q14*/
);
+ void decod_audio_ivas_fx(
+ Decoder_State *st_fx, /* i/o: decoder static memory */
+ Word16 dct_epit[], /* o : GSC excitation in DCT domain */
+ const Word16 *Aq, /* i : LP filter coefficient */
+ Word16 *pitch_buf, /* o : floating pitch values for each subframe */
+ Word16 *voice_factors, /* o : voicing factors */
+ Word16 *exc, /* i/o: adapt. excitation exc */
+ Word16 *exc2, /* i/o: adapt. excitation/total exc */
+ Word16 *bwe_exc, /* o : excitation for SWB TBE */
+ Word16 *lsf_new /* i : ISFs at the end of the frame */
+ , Word16 *gain_buf, /*Q14*/
+ const Word16 tdm_lp_reuse_flag, /* i : LPC reuse flag */
+ const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */
+ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
+ const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */
+ );
+
void gsc_dec_fx(
Decoder_State *st_fx, /* i/o: State structure */
Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation */
@@ -6241,6 +6348,17 @@ void GSC_dec_init_ivas_fx(
Word32* norm_gain_code_fx /* o : norm. gain of the codebook excit. */
);
+ void gain_dec_tc_ivas_fx(
+ Decoder_State *st_fx, /* i/o: decoder state structure */
+ const Word16 *code_fx, /* i : algebraic code excitation */
+ const Word16 i_subfr_fx, /* i : subframe number */
+ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */
+ Word16 *gain_pit_fx, /* o : pitch gain */
+ Word32 *gain_code_fx, /* o : Quantized codeebook gain */
+ Word16 *gain_inov_fx, /* o : unscaled innovation gain */
+ Word32 *norm_gain_code_fx /* o : norm. gain of the codebook excit. */
+ );
+
void gain_dec_mless_fx(
Decoder_State *st_fx, /* i/o: decoder state structure */
const Word16 L_frame_fx, /* i : length of the frame */
@@ -6397,6 +6515,23 @@ void GSC_dec_init_ivas_fx(
#endif
);
+ void dec_pit_exc_ivas_fx(
+ Decoder_State* st_fx, /* i/o: decoder static memory */
+ const Word16* Aq_fx, /* i : LP filter coefficient */
+ const Word16 coder_type_fx, /* i : coding type */
+ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */
+ Word16* pitch_buf_fx, /* o : floating pitch values for each subframe */
+ Word16* code_fx, /* o : innovation */
+ Word16* exc_fx, /* i/o: adapt. excitation exc */
+ Word16* bwe_exc_fx, /* o : excitation for SWB TBE */
+ const Word16 nb_subfr_fx /* i : Number of subframe considered */
+ , Word16* gain_buf /*Q14*/
+#if 1//def ADD_LRTD
+ , const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
+ const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */
+#endif
+ );
+
//pit_dec_fx.c
Word32 Mode2_pit_decode( /* o: floating pitch value */
@@ -6458,7 +6593,6 @@ void GSC_dec_init_ivas_fx(
#endif
);
-#ifdef IVAS_FLOAT_FIXED
Word16 pit_decode_ivas_fx( /* o : floating pitch value */
Decoder_State *st_fx, /* i/o: decoder state structure */
const Word32 core_brate, /* i : core bitrate */
@@ -6477,7 +6611,6 @@ void GSC_dec_init_ivas_fx(
const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */
#endif
);
-#endif
void pit_Q_dec_fx(
const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */
@@ -6681,6 +6814,24 @@ void GSC_dec_init_ivas_fx(
const Word16 core
);
+
+#ifdef IVAS_FLOAT_FIXED
+ Word16 ivas_pvq_core_dec_fx(
+ Decoder_State *st_fx,
+ const Word16 *sfm_start,
+ const Word16 *sfm_end,
+ const Word16 *sfmsize,
+ Word16 coefs_quant[], /* o : output MDCT */
+ Word16 *Q_coefs,
+ Word16 bits_tot,
+ Word16 nb_sfm,
+ Word16 *R, /* Q3 */
+ Word16 *Rs,
+ Word16 *npulses,
+ Word16 *maxpulse,
+ const Word16 core);
+#endif
+
void decode_energies_fx(
Decoder_State *st_fx,
PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */
@@ -7702,6 +7853,22 @@ void generate_comfort_noise_dec_hf_ivas_fx(
Word16 *gain_buf
);
+ void decod_unvoiced_ivas_fx(
+ Decoder_State *st_fx, /* i/o: decoder static memory */
+ const Word16 *Aq_fx, /* Q12 i : LP filter coefficient */
+ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */
+ const int16_t uc_two_stage_flag, /* i : flag indicating two-stage UC */
+ const Word16 coder_type_fx, /* Q0 i : coding type */
+ Word16 *tmp_noise_fx, /* Q0 o : long term temporary noise energy */
+ Word16 *pitch_buf_fx, /* Q6 o : floating pitch values for each subframe*/
+ Word16 *voice_factors_fx, /* Q15 o : voicing factors */
+ Word16 *exc_fx, /* Q_X o : adapt. excitation exc */
+ Word16 *exc2_fx, /* Q_X o : adapt. excitation/total exc */
+ Word16 *bwe_exc_fx, /* Q_X i/o: excitation for SWB TBE */
+ Word16 Q_exc,
+ Word16 *gain_buf
+ );
+
//gaus_dec_fx.c
void gaus_dec_fx(
Decoder_State* st_fx, /* i/o: decoder static memory */
@@ -7748,6 +7915,24 @@ void generate_comfort_noise_dec_hf_ivas_fx(
Word16* gain_buf /*Q14*/
);
+ ivas_error decod_gen_voic_ivas_fx(
+ Decoder_State *st_fx, /* i/o: decoder static memory */
+ const Word16 L_frame, /* i : length of the frame */
+ const Word16 sharpFlag_fx, /* i : formant sharpening flag */
+ const Word16 *Aq_fx, /* i : LP filter coefficient */
+ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */
+ const Word16 do_WI_fx, /* i : do interpolation after a FER */
+ Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */
+ Word16 *voice_factors_fx, /* o : voicing factors */
+ Word16 *exc_fx, /* i/o: adapt. excitation exc */
+ Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */
+ Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */
+ Word16 *unbits, /* number of unused bits */
+ Word16 *gain_buf,
+ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
+ const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */
+ );
+
//dec_tran_fx.c
void decod_tran_fx(
Decoder_State *st_fx, /* i/o: decoder static memory */
@@ -8994,3 +9179,12 @@ void stereo_dft_dec_open(
const int32_t output_Fs, /* i : output sampling rate */
const int16_t nchan_transport /* i : number of transport channels */
);
+
+void ivas_bw_switching_pre_proc_fx(
+ Decoder_State *st, /* i/o: decoder state structure */
+ const Word32 last_element_brate, /* i : last element bitrate */
+ const Word16 nchan_out /* i : number of output channels */,
+ Word32 *old_syn_12k8_16k_fx,
+ Word16 Q,
+ Word16 Q_audio
+);
\ No newline at end of file
diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c
index 8f851e2fd270f412e03407fe0307f13309df13a0..4270ec3374b2013fc241a3d1da6be91604b1bd2d 100644
--- a/lib_com/rom_com.c
+++ b/lib_com/rom_com.c
@@ -2616,6 +2616,10 @@ const float interpol_frac2[NB_SUBFR] = {
0.5f, 0.5f, 1.0f, 1.0f
};
+const Word16 interpol_frac2_fx[NB_SUBFR] = {
+ 16384, 16384, 32767, 32767
+};
+
const float interpol_frac2_mid[NB_SUBFR*3] = {
0.25f, 0.75f, 0.0f,
0.25f, 0.75f, 0.0f,
@@ -3156,6 +3160,74 @@ const float gain_qua_mless_6b_stereo[64*2]=
1.199951F,1.863281F,
};
+const Word16 gain_qua_mless_6b_stereo_fx[64 * 2] =
+{
+ 570, 695,
+ 932, 535,
+ 972, 913,
+ 1305, 165,
+ 1503, 343,
+ 1942, 2102,
+ 2763, 440,
+ 2957, 1204,
+ 3163, 621,
+ 3232, 760,
+ 4215, 255,
+ 4415, 533,
+ 4884, 873,
+ 5395, 429,
+ 5601, 664,
+ 5724, 1615,
+ 6847, 1057,
+ 6849, 535,
+ 6889, 3303,
+ 7086, 335,
+ 7135, 766,
+ 8267, 616,
+ 8601, 907,
+ 8690, 442,
+ 9501, 1264,
+ 9517, 728,
+ 10050, 73,
+ 10243, 514,
+ 10723, 861,
+ 10884, 641,
+ 11005, 339,
+ 11919, 1623,
+ 11976, 1037,
+ 12219, 564,
+ 12286, 770,
+ 12858, 413,
+ 12944, 8191,
+ 13347, 684,
+ 13751, 502,
+ 13802, 873,
+ 13812, 1207,
+ 14417, 615,
+ 14633, 392,
+ 15119, 732,
+ 15214, 521,
+ 15247, 976,
+ 15509, 290,
+ 15936, 1440,
+ 16101, 603,
+ 16157, 448,
+ 16277, 799,
+ 16358, 2544,
+ 16863, 4652,
+ 17010, 1093,
+ 17073, 350,
+ 17348, 659,
+ 17583, 509,
+ 17853, 854,
+ 19087, 1756,
+ 19109, 405,
+ 19348, 727,
+ 19553, 566,
+ 19553, 1240,
+ 19659, 953
+};
+
const float gain_qua_mless_6b[64*2] =
{
0.1023f, 0.1385f,
@@ -5163,6 +5235,138 @@ const float gp_gamma_3sfr_7b[2 * 128] =
1.22262f, 1.46383f,
};
+const Word16 gp_gamma_3sfr_7b_fx[2 * 128] = //Q14/Q9
+{
+ 141, 207,
+ 268, 836,
+ 355, 385,
+ 470, 124,
+ 944, 265,
+ 1202, 503,
+ 1308, 640,
+ 1384, 150,
+ 1399, 75,
+ 1534, 323,
+ 1835, 1252,
+ 1872, 216,
+ 2297, 443,
+ 2495, 122,
+ 2697, 358,
+ 2849, 181,
+ 2920, 274,
+ 2937, 552,
+ 3353, 2982,
+ 3666, 394,
+ 3759, 1755,
+ 3790, 972,
+ 3838, 225,
+ 3929, 758,
+ 3973, 143,
+ 4075, 313,
+ 4329, 471,
+ 4689, 625,
+ 4938, 178,
+ 5073, 266,
+ 5216, 379,
+ 5519, 520,
+ 6089, 321,
+ 6149, 221,
+ 6247, 432,
+ 6254, 1083,
+ 6556, 131,
+ 6751, 733,
+ 6773, 587,
+ 7140, 17402,
+ 7257, 366,
+ 7295, 269,
+ 7314, 483,
+ 8121, 204,
+ 8214, 1515,
+ 8332, 538,
+ 8386, 842,
+ 8483, 314,
+ 8484, 660,
+ 8503, 395,
+ 9079, 455,
+ 9543, 249,
+ 9687, 1056,
+ 9724, 11493,
+ 9727, 336,
+ 9862, 603,
+ 10141, 158,
+ 10278, 498,
+ 10347, 393,
+ 10380, 751,
+ 10899, 287,
+ 11239, 564,
+ 11377, 210,
+ 11389, 437,
+ 11531, 926,
+ 11565, 339,
+ 11594, 684,
+ 11635, 7228,
+ 12176, 509,
+ 12240, 1235,
+ 12467, 381,
+ 12631, 254,
+ 12758, 809,
+ 12877, 458,
+ 12881, 620,
+ 13160, 313,
+ 13243, 1692,
+ 13441, 533,
+ 13620, 420,
+ 13855, 718,
+ 13895, 998,
+ 14047, 354,
+ 14150, 199,
+ 14170, 586,
+ 14358, 477,
+ 14770, 280,
+ 14777, 143,
+ 14810, 397,
+ 14965, 857,
+ 14984, 655,
+ 15112, 524,
+ 15406, 330,
+ 15535, 442,
+ 15599, 1120,
+ 15635, 4946,
+ 15823, 582,
+ 15891, 736,
+ 16161, 374,
+ 16216, 229,
+ 16265, 493,
+ 16607, 638,
+ 16610, 2511,
+ 16905, 803,
+ 16906, 433,
+ 16911, 310,
+ 16924, 1415,
+ 17161, 543,
+ 17656, 951,
+ 17694, 680,
+ 17736, 375,
+ 17982, 479,
+ 18345, 287,
+ 18372, 586,
+ 18469, 3627,
+ 18649, 183,
+ 18898, 2002,
+ 18925, 403,
+ 18959, 712,
+ 19244, 857,
+ 19306, 245,
+ 19447, 1203,
+ 19455, 334,
+ 19458, 526,
+ 19600, 455,
+ 19699, 623,
+ 19724, 1583,
+ 19788, 1001,
+ 20031, 749,
+};
+
const float gp_gamma_4sfr_7b[2 * 128] =
{
0.00614f, 0.34082f,
@@ -19608,6 +19812,27 @@ const float SVWB2_SN1[256] = {
2.34f, 15.23f, -68.75f, 83.20f, 293.75f, 169.53f, 126.17f, 195.70f, 218.75f, 108.20f, 41.80f, -96.09f, -140.23f, -300.00f, -319.53f, -416.02f,
-91.02f, -115.23f, -227.34f, -448.05f, -339.84f, 30.08f, 56.25f, 130.86f, 105.08f, 196.09f, 249.22f, 280.86f, 240.23f, 146.88f, 85.55f, 67.19f
};
+
+/* An 16-by-16 matrix */
+const Word16 SVWB2_SN1_fx[256] = {
+ -257, -385, -673, 926, 1408, 874, 735, 512, 624, 587, 493, 688, 845, 521, 428, 95,
+ -32, -90, 1046, 666, 329, -59, -324, -282, -712, -783, -229, 28, -354, -434, -497, -351,
+ 182, 111, 512, 746, 365, 91, -214, -477, -401, -496, -931, -1180, -1422, -1085, -456, -9,
+ -286, -387, -325, 317, 172, 274, 238, 550, 555, 574, 618, 717, 751, 611, 441, 233,
+ 96, 178, 203, -112, -464, -591, -212, 124, 32, 192, 244, 94, -41, -293, -507, -649,
+ -94, -164, 1011, 926, 688, 461, 593, 587, 398, 400, 351, 486, 482, 424, 294, 219,
+ -260, -356, -458, -252, -162, -350, -394, -255, 30, 173, 90, 64, 93, 157, 66, 2,
+ 43, 100, -48, -596, -852, -787, -569, -536, -780, -607, -169, -125, -75, 96, 98, 154,
+ 240, 203, 404, 79, -202, -555, -718, -1023, -1158, -1390, -1537, -774, -478, -173, -63, 272,
+ -164, -291, -405, 1049, 779, 349, 224, 12, 265, 37, -182, -446, -396, -81, -16, -146,
+ 75, 45, -248, -832, 729, 416, 499, 178, -115, 16, 79, 243, 265, 77, -69, -43,
+ 639, 705, 482, -40, -529, -198, -109, -399, -242, -433, -713, -811, -934, -777, -332, 26,
+ 110, 166, -54, -792, -974, 386, 190, 192, 67, -172, -141, -298, -539, -400, -139, 80,
+ 147, 307, 168, 52, -285, -270, -212, -179, 138, 200, 194, 64, 476, 673, 636, 500,
+ 5, 38, -176, 212, 752, 433, 322, 500, 560, 276, 107, -245, -358, -768, -817, -1065,
+ -233, -294, -581, -1147, -869, 77, 144, 335, 269, 501, 638, 719, 614, 376, 219, 172
+};
+
/* An 16-by-16 matrix */
const float SVWB2_SN2[256] = {
-39.45f, -51.17f, -213.28f, -326.17f, 191.02f, 196.09f, 204.30f, 116.02f, 53.52f, 77.73f, 105.47f, 67.19f, 7.03f, -19.92f, -57.81f, -24.61f,
@@ -19628,6 +19853,26 @@ const float SVWB2_SN2[256] = {
-2.73f, 31.64f, 57.03f, -77.73f, -77.34f, 15.23f, -5.86f, 39.45f, 17.58f, 22.66f, 211.72f, 204.69f, 77.34f, -50.39f, -126.95f, -175.00f
};
+/* An 16-by-16 matrix */
+const Word16 SVWB2_SN2_fx[256] = {
+ -100, -130, -545, -834, 489, 501, 523, 297, 137, 198, 270, 172, 17, -50, -147, -63,
+ 333, 351, 143, 142, 47, -137, -131, -323, -216, -32, 105, 264, 541, 425, 342, 153,
+ -93, -168, 184, 605, 372, 237, 186, 175, 307, 321, 448, 205, -128, -481, -477, -512,
+ -24, -30, 26, -47, -159, -88, -344, -130, -88, -280, -742, -901, -264, 176, 38, -26,
+ 258, 250, 114, -75, -186, -326, -360, -237, 268, 532, 236, -341, -556, -334, -181, -30,
+ 123, 241, 118, 205, 441, 172, 49, -158, -273, -214, -428, -729, -758, -532, -289, -112,
+ -160, -224, -512, 393, 460, 216, 179, -94, -78, -320, -473, 13, 224, 196, 127, 37,
+ -35, -65, 360, 164, -185, -563, -683, -357, -634, -61, 400, 133, -232, -264, -174, 32,
+ -140, -196, -470, -355, -532, -323, -268, -76, 260, 258, 218, 161, 206, 266, 234, 168,
+ 99, 109, -60, -368, -564, -49, 75, -60, -160, -654, -847, 162, 278, 76, -24, 42,
+ 12, 88, 124, -54, -91, 197, 289, 211, 240, 184, 10, 16, 560, 677, 619, 350,
+ -37, -91, 771, 654, 291, 165, 104, 43, -224, -365, -411, -78, -90, -20, 85, 168,
+ 45, 1, 58, 80, 293, 411, 443, 655, 604, 642, 624, 529, 373, 227, 166, 128,
+ -176, -124, -182, -131, -260, -127, 350, 460, 425, 260, -76, -400, -605, -506, -121, -49,
+ -96, -92, -274, -176, -220, -323, -399, -505, -610, -530, 124, 268, 235, 272, 128, 160,
+ -6, 80, 145, -198, -197, 38, -15, 100, 45, 58, 542, 524, 197, -128, -324, -448
+};
+
/* An 16-by-8 matrix */
const float SVWB2_AR1[128] = {
-10.94f, -15.23f, -47.66f, 28.91f, 115.63f, 58.20f, 57.42f, 46.88f, 58.20f, 14.45f, -4.30f, -64.06f, -87.11f, -116.80f, -113.67f, -125.39f,
@@ -20404,14 +20649,37 @@ const Word16 AUWB2_MA1_fx[512] =
-19, 43, 35, 40, 42, 55, 63, 101, 133, 194, 222, 152, 117, 145, 133, 213
};
+/* SVWB2_AR1 * 2.56f */
+const Word16 SVWB2_AR1_fx[128] = {
+ -28, -38, -122, 74, 296, 148, 146, 120, 148, 36, -11, -163, -223, -299, -290, -320,
+ -22, -30, -138, -319, -385, 159, 124, 51, 32, -44, -15, -78, -96, -53, 40, 64,
+ -96, -144, -205, -96, 80, 96, 152, 246, 206, 193, 265, 333, 320, 232, 131, 32,
+ 108, 106, 102, 37, -14, -17, -61, -144, -161, -160, -257, -404, -540, -316, -124, 18,
+ 22, 12, 34, -14, -52, -106, -144, -266, -346, -472, -401, -30, -4, -43, -88, -10,
+ -52, -117, -203, 415, 324, 171, 121, -31, 48, -31, -60, -65, 128, 193, 141, 67,
+ -47, -86, 430, 334, 193, 136, 85, 82, 1, -34, 47, 84, 2, -30, -77, -45,
+ -4, -14, -9, -38, -136, -242, -217, -54, -38, 179, 191, 61, 42, -3, 5, -37
+};
+
+/* SVWB2_AR2 * 2.56f */
+const Word16 SVWB2_AR2_fx[128] = {
+ 12, 16, -46, -156, -329, -293, 43, 141, 61, 15, -9, 29, -74, -41, -37, 16,
+ -47, -81, -136, 82, -33, -111, -268, -293, 109, 136, 53, -58, -51, 62, 64, 14,
+ -15, -19, -171, -347, 258, 161, 88, 13, -57, -26, -59, 24, 10, 14, -41, -8,
+ 33, 38, 139, 157, 31, 65, -14, 52, 63, 30, -8, -1, -182, -341, -344, -258,
+ 14, 16, 46, 6, -54, -64, -136, -132, -318, -303, 261, 146, -19, -57, -30, 30,
+ -34, -34, 21, 93, 163, 201, 290, 257, 225, 296, 209, 197, 72, 26, 57, 1,
+ 33, 66, 73, -8, -104, 44, 31, -13, 70, 72, -17, -48, 430, 373, 218, 92,
+ 1, -2, 74, 172, 67, -3, -34, -25, -156, -219, -432, -288, -181, -35, 113, 112
+};
const Word16 *const Quantizers_fx[] = { SVNB_SN1_fx, SVNB_SN2_fx, GETRNB_SN1_fx, GETRNB_SN2_fx, AUNB_SN1_fx,SVWB_SN1_fx, SVWB_SN2_fx, GETRWB_SN1_fx,
GETRWB_SN2_fx, AUWB_SN1_fx,/* U13, */
- TRWB2_SN1_fx, TRWB2_SN2_fx, AUWB2_SN1_fx, CNG_SN1_fx
+ TRWB2_SN1_fx, TRWB2_SN2_fx, AUWB2_SN1_fx, CNG_SN1_fx, SVWB2_SN1_fx, SVWB2_SN2_fx
};
const Word16 *const Quantizers_p_fx[] = { IAA_MA1_fx, UVD_MA1_fx, UVD_MA2_fx, UVWB_MA3_fx, GESVNB_AR1_fx, GESVNB_AR2_fx, GESVWB_AR1_fx, GESVWB_AR2_fx,
- GEWB2_MA1_fx,GEWB_MA1_fx, AUWB2_MA1_fx
+ GEWB2_MA1_fx,GEWB_MA1_fx, AUWB2_MA1_fx, SVWB2_AR1_fx, SVWB2_AR2_fx
};
const float vals[NO_LEADERS][MAX_NO_VALS]=
@@ -21765,6 +22033,29 @@ const Word16 sigma_p_fx[][16] =
{178, 205, 259, 258, 273, 285, 275, 289, 299, 300, 310, 320, 335, 329, 316, 269},
};
+const Word16 sigma_p_ivas_fx[][16] =
+{
+ {152, 164, 179, 170, 172, 176, 171, 169, 169, 174, 175, 216, 247, 304, 113, 110},
+ {131, 171, 178, 176, 174, 178, 178, 178, 135, 166, 167, 176, 183, 197, 199, 206},
+ {84, 89, 120, 142, 154, 175, 184, 186, 189, 181, 178, 198, 245, 190, 54, 28},
+ {138, 157, 200, 194, 189, 208, 207, 206, 214, 197, 186, 222, 311, 302, 103, 43},
+ {3},
+ {146, 165, 183, 194, 197, 202, 191, 190, 187, 186, 171, 189, 281, 311, 61, 34},
+ {142, 168, 184, 183, 187, 190, 187, 188, 189, 193, 200, 212, 231, 245, 169, 177},
+ {174, 164, 168, 197, 300, 372, 199, 59, 208, 208, 209, 218, 231, 246, 237, 232},
+ {91, 101, 147, 165, 174, 195, 207, 210, 218, 230, 230, 244, 268, 272, 269, 250},
+ {157, 192, 226, 210, 211, 228, 228, 241, 245, 246, 248, 263, 274, 275, 270, 251},
+ {3},
+ {131, 160, 183, 193, 202, 205, 203, 212, 212, 213, 217, 220, 229, 214, 203, 200},
+ {187, 221, 231, 229, 237, 232, 232, 236, 249, 259, 286, 284, 250, 238, 238, 296},
+ {3},
+ {127, 173, 226, 217, 264, 256, 290, 295, 297, 325, 334, 326, 302, 290, 275, 254},
+ {248, 300, 339, 344, 360, 350, 363, 361, 368, 391, 431, 433, 406, 400, 377, 467},
+ {3},
+ {141, 180, 213, 223, 232, 234, 242, 240, 250, 253, 268, 255, 245, 235, 227, 200},
+ {178, 205, 259, 258, 273, 285, 275, 289, 299, 300, 310, 320, 335, 329, 316, 269},
+};
+
const Word8 leaders_short[][MAX_NO_SCALES] =
{{ 0, 0, 0},
{ 1, 0, 0},
@@ -23205,6 +23496,26 @@ const float tbl_mid_gen_wb_4b[] =
0.3767f, 0.3565f, 0.3735f, 0.3687f, 0.1498f, -0.0124f, -0.0510f, -0.1065f, -0.0239f, 0.1375f, 0.2156f, 0.3068f, 0.3234f, 0.4213f, 0.5425f, 0.2117f
};
+const Word16 tbl_mid_gen_wb_4b_fx[] =
+{
+ 5532, 5133, 2125, 3516, 4905, 5624, 6338, 6918, 6854, 6354, 5345, 3996, 3603, 5588, 6962, 7511,
+ 4218, 4157, 4892, 6332, 5786, 2931, 2749, 2306, 3420, 4629, 5591, 6249, 6638, 7273, 7904, 8379,
+ 993, 369, 2927, 5138, 4840, 5892, 5331, 5158, 3956, 3130, 3324, 5022, 5292, 3974, 2488, 1119,
+ 1067, 2471, 6356, 4184, 3166, 3224, 3980, 5055, 4965, 4822, 3843, 2328, 1438, 916, 2514, 8248,
+ 3788, 949, 522, 1709, 1932, 3306, 3287, 4521, 5432, 5291, 5644, 6116, 6166, 5943, 5631, 2088,
+ 7865, 8237, 6466, 4043, 3793, 4589, 4885, 5405, 6002, 6746, 7203, 7361, 6982, 6157, 3994, 2143,
+ 2837, 7217, 7926, 7751, 7605, 7549, 6937, 6852, 6270, 5895, 5612, 5245, 4862, 3654, 3139, 6321,
+ 4317, 3387, 1035, 2799, 2769, 3400, 3054, 2246, 2307, 1829, 1456, 1007, 1055, 895, 782, 108,
+ 7164, 8021, 6869, 6458, 6311, 5505, 5577, 4491, 3934, 3760, 3244, 2798, 2498, 2166, 1950, 4759,
+ 5758, 5400, 1203, 687, 647, 963, 1486, 2000, 2998, 3179, 3634, 4296, 4465, 3719, 3275, 4785,
+ 1051, 1802, 6133, 6475, 6875, 6981, 7181, 7303, 7136, 7036, 7276, 7197, 6986, 7118, 6659, 5813,
+ 4095, 6275, 6049, 4850, 3198, 4942, 3257, 1456, 1327, 504, 559, 1472, 3985, 5835, 5772, 7356,
+ 6814, 7430, 4049, 2579, 4315, 2443, 3236, 3107, 2458, 2891, 2553, 1923, 1871, 2068, 3583, -188,
+ 412, 238, 247, 507, 498, 540, 811, 767, 679, 480, 416, 306, 574, 532, 731, 2227,
+ 8495, 9589, 8346, 7953, 7655, 7990, 8089, 8412, 8530, 8482, 8421, 8420, 8464, 8242, 7698, 7341,
+ 3085, 2920, 3059, 3020, 1227, -101, -417, -872, -195, 1126, 1766, 2513, 2649, 3451, 4444, 1734
+};
+
const float tbl_mid_gen_wb_5b[] =
{
0.7947f, 0.9837f, 0.8671f, 0.7440f, 0.7914f, 0.7161f, 0.7356f, 0.7865f, 0.8401f, 0.8431f, 0.8563f, 0.8033f, 0.6896f, 0.4937f, 0.3437f, 0.3075f,
@@ -28531,6 +28842,23 @@ const Word32 GSC_freq_bits_fx[] =
8126464, 25165824, 0, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_22k60*/ 26, 96, -1, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_16k40*/
8126464, 25165824, 0, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576, /* ACELP_22k60*/ 26, 96, -1, 28, 18, 13, 12,10,10, 5, 4, 4, 1, 0, 1, 3, 4, /* ACELP_16k40*/
};
+
+const Word32 GSC_freq_bits_fx_Q18[] =
+{
+ 5505024, 17301504, -1572864, 6553600, 3932160, 2883584, 2621440, 1310720, 0, 0, 1310720, 1048576, 0, 0, 1048576, 0, 0,
+ 5505024, 17301504, -1572864, 6553600, 3932160, 2883584, 2621440, 1310720, 0, 0, 1310720, 1048576, 0, 0, 1048576, 0, 0,
+ 5505024, 17301504, -1572864, 6553600, 3932160, 2883584, 2621440, 1310720, 0, 0, 1310720, 1048576, 0, 0, 1048576, 0, 0,
+ 5505024, 19398656, -1048576, 6815744, 4194304, 3145728, 2883584, 2359296, 0, 0, 1048576, 1048576, 262144, 262144, 786432, 0, 0,
+ 6815744, 20971520, -786432, 7340032, 4718592, 3407872, 3145728, 2359296, 0, 0, 1048576, 1048576, 262144, 262144, 786432, 0, 0,
+ 6815744, 25165824, -1048576, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576,
+ 6815744, 25165824, -1048576, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576,
+ 6815744, 25165824, -1048576, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576,
+ 6815744, 25165824, -1048576, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576,
+ 6815744, 25165824, -262144, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576,
+ 6815744, 25165824, -262144, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576,
+ 6815744, 25165824, 0, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576,
+ 6815744, 25165824, 0, 7340032, 4718592, 3407872, 3145728, 2621440, 2621440, 1310720, 1048576, 1048576, 262144, 0, 262144, 786432, 1048576,
+};
#else
const Word32 GSC_freq_bits_fx[] =
{
@@ -29873,6 +30201,15 @@ const float YG_mean16HR[] =
0.0358f, 0.0083f, 0.0398f, 0.0448f,
};
+const Word16 YG_mean16HR_fx[] =
+{
+ //Q12
+ -396, -191, -167, -135,
+ -60, -17, 45, 39,
+ 120, 81, 89, 67,
+ 146, 33, 163, 183,
+};
+
const float YG_dicHR_1[] =
{
-0.4774f, 0.1006f, 0.0327f, 0.0080f,
@@ -30005,6 +30342,138 @@ const float YG_dicHR_1[] =
-0.1389f, 0.2515f, 0.1029f, -0.3880f,
};
+const Word16 YG_dicHR_1_fx[] =
+{
+ //Q12
+ -1955, 412, 133, 32,
+ -340, 88, -42, 20,
+ -999, 314, -144, 456,
+ -429, -190, 186, 547,
+ -1057, 160, 243, -197,
+ -46, -81, -491, -223,
+ 143, 986, -113, 15,
+ 286, -313, 77, 3,
+ 249, -1251, 380, 305,
+ -1909, -258, 481, 86,
+ 902, 59, 42, -186,
+ -1969, -992, -335, 223,
+ -1913, -163, -465, -167,
+ -806, 1201, 24, 481,
+ -564, -1943, 212, 380,
+ -120, -691, -162, 138,
+ -966, 1009, 437, -464,
+ 434, 147, 185, 158,
+ -1944, -133, -313, 602,
+ -1029, 236, -612, -373,
+ -749, -571, -1008, -399,
+ 666, -954, -111, 88,
+ 186, -16, -174, 338,
+ -235, -314, 403, -244,
+ 285, 133, 85, -349,
+ -1981, -1506, -1290, 338,
+ -1977, -1925, -368, 876,
+ -1930, 256, 453, 667,
+ -1884, 259, -123, -779,
+ -813, 1087, -595, -1014,
+ 396, 66, -876, 412,
+ -543, 907, -657, 301,
+ -485, 612, 515, 777,
+ -362, 420, 417, -518,
+ -1754, 1307, 65, -1202,
+ -618, 705, -56, -56,
+ -1938, 1005, 561, 59,
+ 62, 521, -440, 319,
+ -1776, 1011, -279, -165,
+ 558, 357, -444, -47,
+ 801, -1998, 313, 319,
+ -1873, -826, -1691, -978,
+ -588, -294, -328, -1021,
+ -91, 513, -288, -530,
+ -1945, -1964, -350, -293,
+ -307, -1057, 203, -631,
+ 94, -1713, -548, -62,
+ 616, -11, -510, -780,
+ 682, -1574, 260, -441,
+ 507, -778, 522, -88,
+ 1321, -635, -432, -619,
+ 369, -615, -335, -1646,
+ 1026, -572, 265, -256,
+ 779, 127, -155, 356,
+ -462, -180, -637, 405,
+ 1329, 1071, 543, 784,
+ 434, -468, 120, -581,
+ 1293, -532, 60, 377,
+ 63, -1290, -336, 708,
+ 756, 42, 412, 607,
+ 731, 1003, 598, -1388,
+ -1818, -1666, 547, 185,
+ -1915, -802, 485, 789,
+ 907, 437, 455, 108,
+ 507, -102, 573, -109,
+ 1037, -1292, -691, 512,
+ 1428, 159, 20, 271,
+ 111, -826, -607, -563,
+ -622, -1328, -1391, -1000,
+ -15, 1094, 339, -684,
+ 448, 790, -439, -1617,
+ -1765, -943, -657, -675,
+ 107, -835, -1140, 241,
+ 33, 122, 520, 242,
+ 194, 204, 313, -1080,
+ 1308, 548, -711, -850,
+ 1520, 474, 334, -516,
+ 1091, -42, 347, -1543,
+ 1098, -219, 680, 139,
+ 855, -895, 613, -985,
+ -1631, -1550, 539, -1277,
+ 672, 905, -1057, 430,
+ 555, 659, -38, 450,
+ -1118, -53, 536, 487,
+ 563, -485, -204, 650,
+ -678, -930, 470, 425,
+ 1180, -259, -990, 319,
+ 993, 319, -362, 926,
+ 782, -254, -1447, -534,
+ -1946, 964, 86, 617,
+ -1651, 727, -813, 514,
+ -552, 395, 522, 124,
+ -1710, 579, 831, -542,
+ 34, 463, 143, 2,
+ -1742, -207, -642, -1517,
+ -1967, -740, 272, -606,
+ 663, 670, 58, -620,
+ 229, 274, 122, 677,
+ 65, 1144, 24, 693,
+ -1383, 1061, 630, 894,
+ 536, 539, 106, -31,
+ 1080, 774, -267, 67,
+ 355, 518, 609, -336,
+ 777, -735, 412, 551,
+ 219, -424, 392, 451,
+ -543, -1909, -189, -933,
+ -938, -178, 489, -1008,
+ -749, -1216, -440, -157,
+ 681, -355, -423, -19,
+ 299, 1053, -913, -506,
+ -258, 360, -1457, -38,
+ -264, 967, 519, 58,
+ -718, -1676, -1184, 185,
+ 741, -314, 184, 210,
+ -1780, -305, -1299, 167,
+ -1912, -1932, -1292, -970,
+ -1017, -520, -96, -136,
+ -1829, 500, -1244, -625,
+ -1041, -791, -461, 591,
+ 708, -1386, -1078, -956,
+ 339, 636, 509, 408,
+ -131, 106, -1202, -1118,
+ 818, 18, 477, -676,
+ 668, 1176, 422, -36,
+ 1074, -1259, 425, 267,
+ -281, 539, 31, 430,
+ -1196, 756, 338, 236,
+ -568, 1030, 421, -1589,
+};
const float YG_dicHR_2[] =
{
0.0357f, -0.0180f, -0.0164f, -0.0247f,
@@ -30073,6 +30542,75 @@ const float YG_dicHR_2[] =
-0.2243f, 0.0304f, -0.0379f, 0.0084f,
};
+const Word16 YG_dicHR_2_fx[] =
+{
+ //Q12
+ 146, -73, -67, -101,
+ -11, 330, -176, -609,
+ -283, -31, -381, -191,
+ -208, -81, 142, 234,
+ 141, -376, -66, -646,
+ 568, -38, -429, 160,
+ 166, 831, 89, -103,
+ 280, -881, -296, -82,
+ -117, -4, 340, -956,
+ 286, -136, -679, -410,
+ 141, 181, -197, 511,
+ -685, 648, 246, -365,
+ 625, -670, 591, 190,
+ -7, -296, -454, 235,
+ 840, 126, 652, 1064,
+ -428, -570, -18, -77,
+ -298, -973, 637, 380,
+ -774, -31, -333, -902,
+ -1509, 167, 471, -369,
+ 431, -1437, 124, 610,
+ -917, 511, 518, -1488,
+ -97, 262, -872, 247,
+ 549, -166, 602, -590,
+ 644, -1030, 796, -1279,
+ 525, -37, 212, 197,
+ 141, 345, 195, 211,
+ 91, -71, 674, 223,
+ -1343, -902, -27, 234,
+ -467, -981, -427, 725,
+ 176, -527, 85, 275,
+ -654, -859, 473, -873,
+ 671, -457, -326, 742,
+ 699, 613, -78, 457,
+ -487, 505, 231, 578,
+ -194, 927, -493, 529,
+ 635, 554, -917, 532,
+ -554, -12, -314, 611,
+ 172, 667, 532, -874,
+ 594, 270, -27, -378,
+ 388, -530, -1307, 274,
+ 647, 451, 670, 24,
+ 745, -470, 8, -260,
+ -725, -292, -1018, -32,
+ 95, 184, 330, -280,
+ -761, -135, 552, 250,
+ -415, -3, 197, -307,
+ 142, 702, 584, 755,
+ 450, 595, -1010, -525,
+ -455, -1143, -775, -639,
+ 228, 496, -1676, 399,
+ 82, 242, -532, 1222,
+ 125, -214, 319, 804,
+ -292, 380, -126, 70,
+ 96, -480, 407, -259,
+ -636, -148, 890, 1241,
+ 213, 404, -382, -7,
+ -315, 509, 660, 61,
+ 505, 18, 33, -1385,
+ -568, 716, -623, -338,
+ -440, 38, 972, -455,
+ -1420, 576, -1125, 668,
+ -1391, 481, 229, 593,
+ 335, -1464, 430, -375,
+ -918, 124, -155, 34,
+};
+
const float YG_dicHR_3[] =
{
-0.0426f, -0.0202f, -0.0387f, -0.0030f,
@@ -30141,11 +30679,86 @@ const float YG_dicHR_3[] =
-0.1584f, -0.0208f, -0.0269f, 0.1868f,
};
+const Word16 YG_dicHR_3_fx[] =
+{
+ //Q12
+ -174, -82, -158, -12,
+ 155, -403, 114, -132,
+ 188, 2, -231, -470,
+ 448, -222, -598, -103,
+ -353, 304, -1173, 420,
+ -43, -77, -533, 386,
+ 526, -57, 360, -247,
+ -837, -219, -344, 42,
+ -236, 88, -664, -226,
+ -1218, 66, 362, -529,
+ -398, 496, -300, 299,
+ 212, 508, -521, 80,
+ -267, -522, 45, 286,
+ -65, -1143, 154, -169,
+ 725, -1483, 883, -1459,
+ 9, -109, 334, -752,
+ -38, 860, -22, -333,
+ -487, 340, 202, -1529,
+ -349, 387, 645, -464,
+ -106, 73, 170, 427,
+ 180, 384, -292, 989,
+ 178, -505, 618, 375,
+ 481, 539, -1777, 1050,
+ 680, -792, 65, 136,
+ -1388, 798, -1090, 670,
+ -377, -507, -139, -580,
+ 301, 614, 194, 392,
+ -218, -1155, 341, 834,
+ 338, -1071, -1177, 673,
+ -406, 188, -92, -546,
+ -58, -656, 773, -540,
+ 461, 649, 840, -108,
+ -775, -352, 620, 233,
+ -390, 666, 601, 438,
+ -394, 1594, -299, 1009,
+ 367, 448, 291, -886,
+ 788, 76, 479, 531,
+ -77, -655, -500, -14,
+ 514, -1745, 497, 217,
+ 904, -963, 630, 1261,
+ 775, 224, -795, 520,
+ 291, -435, -112, 679,
+ 494, 1380, -1018, -186,
+ -75, 86, 731, 1048,
+ 65, 74, 617, 99,
+ 512, -46, 709, -1636,
+ -926, 1237, 1090, -812,
+ 40, 297, 97, -131,
+ 656, 770, 1176, 920,
+ 1313, -582, -1832, -912,
+ 490, -648, -43, -805,
+ -449, -882, -1473, -698,
+ 1028, 421, -151, -289,
+ 1089, 1107, -144, 760,
+ 188, 357, -638, -1027,
+ -337, -210, 300, -194,
+ 319, 223, -1587, -64,
+ 972, 1384, 786, -1026,
+ 928, -468, 1116, -198,
+ -1489, 642, 269, 385,
+ -627, 250, 153, 50,
+ -906, 613, -518, -436,
+ 379, 18, -68, 218,
+ -648, -85, -110, 765,
+};
+
const float YG_mean16HR_16kHz[] =
{
0.0837f, 0.0372f, 0.0912f, 0.0878f,
};
+const Word16 YG_mean16HR_16kHz_fx[] =
+{
+ //Q12
+ 342, 152, 373, 359
+};
+
const float YG_dicHR_4_16kHz[] =
{
0.0336f, 0.0267f, 0.0526f, 0.0053f,
@@ -30214,11 +30827,86 @@ const float YG_dicHR_4_16kHz[] =
-0.1695f, 0.1897f, 0.0702f, 0.0873f,
};
+const Word16 YG_dicHR_4_16kHz_fx[] =
+{
+ //Q12
+ 137, 109, 215, 21,
+ 328, -26, 537, -270,
+ -137, -851, -385, -703,
+ -537, -81, -244, -23,
+ -174, -425, -175, -351,
+ 861, 1100, 696, 574,
+ -150, -14, -390, -241,
+ -828, 166, 164, -151,
+ -226, 541, 204, -110,
+ 184, 820, -89, 264,
+ -26, 889, 709, 520,
+ 83, -176, -713, -276,
+ -149, -1318, 731, -193,
+ -324, -55, 118, 182,
+ 474, -493, -411, 52,
+ 156, -1459, -370, -71,
+ 513, 451, 973, 283,
+ 903, -296, 309, 121,
+ 1261, 296, 886, 702,
+ 984, -1204, 915, 15,
+ -401, 456, -316, 136,
+ 458, -1779, 335, -788,
+ 471, -796, 239, -331,
+ -390, -2265, 493, -305,
+ 469, -1946, 389, 280,
+ 150, 463, -725, 114,
+ -411, 99, -906, -128,
+ 628, 888, 1299, 1039,
+ 1454, 1377, 1415, 1350,
+ -1, 242, -164, -11,
+ 632, 621, 416, 695,
+ 396, -1030, 356, 492,
+ 48, -279, -98, -30,
+ -568, -212, -376, -571,
+ 275, 570, 382, 152,
+ 443, 75, 521, 418,
+ -1366, -1566, -2460, -2925,
+ -1059, 64, -585, -231,
+ 134, 489, -296, -380,
+ -1453, -890, -1200, -1157,
+ -27, 240, -1694, 47,
+ 464, 86, -204, -79,
+ 746, 462, 234, 57,
+ 1087, -738, 1095, 1050,
+ 922, 619, -412, 409,
+ -261, 35, 124, -313,
+ -794, 842, -992, 314,
+ 280, -465, 1028, 196,
+ 233, -346, 257, 183,
+ -1640, 244, -110, 28,
+ 377, 171, -57, 392,
+ -89, 368, 195, 456,
+ 501, 1327, 119, 980,
+ -64, -84, -417, 262,
+ -414, -558, -638, -102,
+ -1785, 392, -1756, -430,
+ -705, -299, -1189, -730,
+ -477, 347, -400, -367,
+ -93, -825, -20, -13,
+ -710, -540, 45, -265,
+ -151, -487, 380, -243,
+ -269, 32, 702, 143,
+ 206, -145, -27, -474,
+ -694, 777, 287, 357,
+};
+
const float YG_meanL2G_16kHz[] =
{
0.1036f, 0.1590f,
};
+const Word16 YG_meanL2G_16kHz_fx[] =
+{
+ //Q12
+ 424, 651,
+};
+
const float YG_dicL2G_16kHz[] =
{
-0.0624f, 0.0298f,
@@ -30231,6 +30919,18 @@ const float YG_dicL2G_16kHz[] =
0.2962f, 0.3062f,
};
+const Word16 YG_dicL2G_16kHz_fx[] =
+{
+ -255, 122,
+ 296, 314,
+ -226, -333,
+ 668, 668,
+ 101, -53,
+ -579, -647,
+ -1202, -1244,
+ 1213, 1254,
+};
+
const int16_t Odx_fft64[64] =
{
0,59,54,49,44,39,34,29,24,19,14,9,4,63,58,53,48,43,38,33,28,23,18,13,8,3,62,57,52,47,42,37,
diff --git a/lib_com/rom_com.h b/lib_com/rom_com.h
index 01effce6cf1bf0d6ac69e31bd1ab17bbc00ff793..3f805d8cb4f87d8b07dacd27a3e77722b621c192 100644
--- a/lib_com/rom_com.h
+++ b/lib_com/rom_com.h
@@ -237,6 +237,7 @@ extern const Word32 lag_window_25k6_32[NUM_LAGW_STRENGTHS][16];
extern const Word32 lag_window_32k_32[NUM_LAGW_STRENGTHS][16];
extern const Word32 lag_window_48k_32[16];
extern const float interpol_frac2[]; /* LPC interpolation coefficients for two-subframe mode */
+extern const Word16 interpol_frac2_fx[]; /* LPC interpolation coefficients for two-subframe mode */
extern const float interpol_frac2_mid[]; /* LPC interpolation coefficients with mid-ISFs for two-subframe mode */
extern const float interpol_frac_12k8[]; /* LPC interpolation coefficients */
extern const Word16 interpol_frac_fx[NB_SUBFR];
@@ -285,6 +286,7 @@ extern const TCX_LTP_FILTER tcxLtpFilters[12];
extern const float gain_qua_mless_7b[]; /* Gain quantization - gain quantization table */
extern const float gain_qua_mless_6b_stereo[]; /* Gain quantization - gain quantization table in IVAS */
+extern const Word16 gain_qua_mless_6b_stereo_fx[]; /* Gain quantization - gain quantization table in IVAS */
extern const float gain_qua_mless_6b[]; /* Gain quantization - gain quantization table */
extern const float gain_qua_mless_5b[]; /* Gain quantization - gain quantization table */
extern const Word16 gain_qua_mless_7b_fx[];
@@ -334,6 +336,7 @@ extern const Word16 gp_gamma_1sfr_7b_fx[];
extern const Word16 gp_gamma_1sfr_6b_fx[];
extern const Word16 gp_gamma_2sfr_7b_fx[];
extern const Word16 gp_gamma_2sfr_6b_fx[];
+extern const Word16 gp_gamma_3sfr_7b_fx[];
extern const Word16 gp_gamma_3sfr_6b_fx[];
extern const Word16 gp_gamma_4sfr_6b_fx[];
@@ -627,6 +630,7 @@ extern const float sigma_MSLVQ[][16];
extern const Word16 sigma_MSLVQ_fx[][16];
extern const float sigma_p[][16];
extern const Word16 sigma_p_fx[][16];
+extern const Word16 sigma_p_ivas_fx[][16];
extern const float inv_sigma_MSLVQ[][16];
extern const Word16 inv_sigma_MSLVQ_fx[][16];
extern const float inv_sigma_p[][16];
@@ -729,6 +733,7 @@ extern const float tbl_mid_gen_wb_2b[];
extern const float tbl_mid_gen_wb_4b[];
extern const float tbl_mid_gen_wb_5b[];
extern const Word16 tbl_mid_gen_wb_2b_fx[];
+extern const Word16 tbl_mid_gen_wb_4b_fx[];
extern const Word16 tbl_mid_gen_wb_5b_fx[];
extern const float tbl_mid_unv_wb_4b[];
@@ -1462,15 +1467,24 @@ extern const float Gain_dic3_NBHR[];
extern const Word16 Gain_dic3_NBHR_fx[];
extern const Word16 Gain_dic2_NBHR_fx[];
extern const float YG_mean16HR[];
+extern const Word16 YG_mean16HR_fx[];
extern const float YG_dicHR_1[];
+extern const Word16 YG_dicHR_1_fx[];
extern const float YG_dicHR_2[];
+extern const Word16 YG_dicHR_2_fx[];
extern const float YG_dicHR_3[];
+extern const Word16 YG_dicHR_3_fx[];
extern const float YG_mean16HR_16kHz[];
+extern const Word16 YG_mean16HR_16kHz_fx[];
extern const float YG_dicHR_4_16kHz[];
+extern const Word16 YG_dicHR_4_16kHz_fx[];
extern const float YG_meanL2G_16kHz[];
+extern const Word16 YG_meanL2G_16kHz_fx[];
extern const float YG_dicL2G_16kHz[];
+extern const Word16 YG_dicL2G_16kHz_fx[];
extern const int16_t GSC_freq_bits[];
extern const Word32 GSC_freq_bits_fx[];
+extern const Word32 GSC_freq_bits_fx_Q18[];
extern const int16_t GSC_freq_DL0_bits[];
extern const int16_t Compl_GSC_freq_bits[];
extern const float Gain_meanNB[];
diff --git a/lib_com/scale_mem_fx.c b/lib_com/scale_mem_fx.c
index 3e148d6299833034367efc9bb6dfc71ccd87b38b..511d48b96df44132cdef29ef6a8a82639e87ec3e 100644
--- a/lib_com/scale_mem_fx.c
+++ b/lib_com/scale_mem_fx.c
@@ -221,7 +221,7 @@ void Rescale_mem(
/* we add Q_syn which represents the actual scaling of the memories prev_Q_syn represents the last potential scaling */
tmp = sub(add(norm_s(tmp), -1), 3); /* -2 ... 12 */
}
- ELSE
+ ELSE IF(hPFstat != NULL)
{
FOR(i = 0; i < M; i++)
{
@@ -276,12 +276,15 @@ void Rescale_mem(
Scale_sig(mem_syn2, M, exp_scale);
Scale_sig(mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM, exp_scale);
/*Scale_sig(core_old_syn, L_SYN_MEM, exp_scale);*/
- Scale_sig(mem_deemph, 1, exp_scale);
- Scale_sig(pst_old_syn, NBPSF_PIT_MAX, exp_scale);
- Scale_sig(pst_mem_deemp_err, 1, exp_scale);
- Scale_sig(hPFstat->mem_pf_in, L_SUBFR, exp_scale); /* NB post_filter mem */
- Scale_sig(hPFstat->mem_res2, DECMEM_RES2, exp_scale); /* NB post_filter mem */
- Scale_sig(hPFstat->mem_stp, L_SUBFR, exp_scale); /* NB post_filter mem */
+ Scale_sig(mem_deemph, 1, exp_scale);
+ IF(hPFstat != NULL)
+ {
+ Scale_sig(pst_old_syn, NBPSF_PIT_MAX, exp_scale);
+ Scale_sig(pst_mem_deemp_err, 1, exp_scale);
+ Scale_sig(hPFstat->mem_pf_in, L_SUBFR, exp_scale); /* NB post_filter mem */
+ Scale_sig(hPFstat->mem_res2, DECMEM_RES2, exp_scale); /* NB post_filter mem */
+ Scale_sig(hPFstat->mem_stp, L_SUBFR, exp_scale); /* NB post_filter mem */
+ }
Scale_sig(mem_agc, 1, exp_scale); /* NB post_filter mem */
return;
}
diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c
index d37f614a7c6bfe142d114d42e2c15cf7a34c1704..50166970b989f1f43bb4600b647c8cb9fd6e562f 100644
--- a/lib_com/swb_tbe_com_fx.c
+++ b/lib_com/swb_tbe_com_fx.c
@@ -217,6 +217,93 @@ void tbe_celp_exc(
*error_fx = add(*error_fx,tmp_fx);/*error_fx in Q5*/
}
}
+
+/*-------------------------------------------------------------------*
+* swb_tbe_celp_exc_ivas()
+*
+* Compute tbe bwe celp excitation
+*-------------------------------------------------------------------*/
+void tbe_celp_exc_ivas(
+ const int16_t element_mode, /* i : element mode */
+ const int16_t idchan, /* i : channel ID */
+ const Word16 L_frame_fx, /* i : Frame lenght */
+ const int16_t L_subfr, /* i : subframe length */
+ const Word16 i_subfr_fx, /* i : sub frame */
+ const Word16 T0_fx, /* i : Integer pitch */
+ const Word16 T0_frac_fx, /* i : Fractional part of the pitch */
+ Word16 *error_fx, /* i/o: Error */
+ Word16 *bwe_exc_fx, /* i/o: bandwitdh extension signal */
+ const int16_t tdm_LRTD_flag /* i : LRTD stereo mode flag */
+)
+{
+ Word16 offset_fx, tmp_fx, i;
+
+ if (element_mode == IVAS_CPE_TD && idchan == 1 && !tdm_LRTD_flag)
+ {
+ return;
+ }
+
+ IF(EQ_16(L_frame_fx, L_FRAME))
+ {
+ /*offset = T0 * HIBND_ACB_L_FAC + (int) ((float) T0_frac * 0.25f * HIBND_ACB_L_FAC + 2 * HIBND_ACB_L_FAC + 0.5f) - 2 * HIBND_ACB_L_FAC;
+ for (i=0; i 0)
+ {
+ tmp_fx = shr(*error_fx, 5);/*Q0*/
+ }
+ ELSE
+ {
+ tmp_fx = negate(shr(abs_s(*error_fx),5));/*Q0*/
+ }
+
+ FOR(i = 0; i < L_subfr * HIBND_ACB_L_FAC; i++)
+ {
+ bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC - offset_fx + tmp_fx];
+ move16();
+ }
+ tmp_fx = extract_l(L_mult(T0_frac_fx, 1));/*Q3; 0.25 in Q2*/
+ tmp_fx = add(shl(T0_fx, 3), tmp_fx);/*Q3*/
+ tmp_fx = extract_l(L_mult(tmp_fx, 5));/*Q5, 2.5 in Q1*/
+ tmp_fx = sub(shl(offset_fx, 5), tmp_fx);/*Q5*/
+ *error_fx = add(*error_fx, tmp_fx);/*Q5*/
+ }
+ ELSE
+ {
+ /* offset = T0*2.5 + (int) ((float) T0_frac * 0.25f*2.5 + 2*2.5 + 0.5f) - 2*2.5; - case above*/
+ /* offset = T0*2 + (int) ((float) T0_frac * 0.25f*2 + 2*2 + 0.5f) - 2*2; - case here*/
+
+ /*(int) ((float) T0_frac * 0.25f*2 + 2*2 + 0.5f)*/
+ offset_fx = tbe_celp_exc_offset(T0_fx, T0_frac_fx, L_frame_fx);
+ IF(*error_fx > 0)
+ {
+ tmp_fx = shr(*error_fx,5);/*Q0*/
+ }
+ ELSE
+ {
+ tmp_fx = negate(shr(abs_s(*error_fx),5));/*Q0*/
+ }
+
+ FOR(i = 0; i < L_subfr * 2; i++)
+ {
+ bwe_exc_fx[i + i_subfr_fx * 2] = bwe_exc_fx[i + i_subfr_fx * 2 - offset_fx + tmp_fx];
+ move16();
+ }
+
+ /* error += (float) offset - (float) T0 * 2 - 0.5f * (float) T0_frac;*/
+ tmp_fx = extract_l(L_mult(T0_frac_fx,2));/*Q3; 0.5 in Q2*/
+ tmp_fx = add(shl(T0_fx,4),tmp_fx);/* now tmp_fx = "T0_fx*2+ 0.5f*T0_frac_fx" in Q3*/
+ tmp_fx = shl(tmp_fx,2);/*now above tmp_fx in Q5*/
+ tmp_fx = sub(shl(offset_fx,5),tmp_fx);/*move offset_fx to Q5, tmp_fx in Q5, ans tmp_fx in Q5*/
+ *error_fx = add(*error_fx,tmp_fx);/*error_fx in Q5*/
+ }
+}
+
/*===========================================================================*/
/* FUNCTION : flip_and_downmix_generic_fx() */
/*---------------------------------------------------------------------------*/
@@ -4778,7 +4865,6 @@ void prep_tbe_exc_fx(
return;
}
-#ifdef IVAS_FLOAT_FIXED
/*======================================================================================*/
/* FUNCTION : prep_tbe_exc_ivas_fx() */
/*--------------------------------------------------------------------------------------*/
@@ -4969,7 +5055,6 @@ void prep_tbe_exc_ivas_fx(
return;
}
-#endif
/*=============================================================================*/
/* FUNCTION : void swb_formant_fac_fx ( ) */
diff --git a/lib_dec/FEC_fx.c b/lib_dec/FEC_fx.c
index 49b41ab4182428f36f84132dcd0644872fddad89..06101344a685ebe0c9559d7b08e798d60118a49a 100644
--- a/lib_dec/FEC_fx.c
+++ b/lib_dec/FEC_fx.c
@@ -537,7 +537,12 @@ void FEC_exc_estim_fx(
st_fx->GSC_noisy_speech_fx = st_fx->Last_GSC_noisy_speech_flag_fx;
move16();
/* Replication of the last spectrum, with a slight downscaling of its dynamic */
- gsc_dec_fx( st_fx, exc_dct_in, hGSCDec->Last_GSC_pit_band_idx_fx, Diff_len, 0, st_fx->L_frame/L_SUBFR, st_fx->last_coder_type_fx, &last_bin_fx, lsf_new, NULL, st_fx->Q_exc );
+ if (st_fx->element_mode == EVS_MONO) {
+ gsc_dec_fx(st_fx, exc_dct_in, hGSCDec->Last_GSC_pit_band_idx_fx, Diff_len, 0, st_fx->L_frame / L_SUBFR, st_fx->last_coder_type_fx, &last_bin_fx, lsf_new, NULL, st_fx->Q_exc);
+ }
+ else {
+ gsc_dec_ivas_fx(st_fx, exc_dct_in, hGSCDec->Last_GSC_pit_band_idx_fx, Diff_len, 0, st_fx->L_frame / L_SUBFR, st_fx->last_coder_type_fx, &last_bin_fx, lsf_new, NULL, st_fx->Q_exc);
+ }
*tmp_noise = shr_r(st_fx->lp_gainc_fx,3); /*Q0*/
/* Transform back to time domain */
edct_16fx( exc_dct_in, exc, st_fx->L_frame, 5, st_fx->element_mode);
diff --git a/lib_dec/FEC_pitch_estim_fx.c b/lib_dec/FEC_pitch_estim_fx.c
index 85cf056ec80536d7e3dcc3c86cd54b3b33c27007..6d2445c881adf7293363bc0bf033283f70255cd4 100644
--- a/lib_dec/FEC_pitch_estim_fx.c
+++ b/lib_dec/FEC_pitch_estim_fx.c
@@ -63,7 +63,7 @@ void FEC_pitch_estim_fx(
#else
tmp16k2 = shl(tmp16k1,1); /*Q6 1.4f * old_pitch_buf[2*NB_SUBFR16k-1]*/
#endif
-#ifdef IVAS_CODE
+#if 1//def IVAS_CODE
test(); test();
IF (EQ_16(last_core, HQ_CORE) || EQ_16(last_core, TCX_20_CORE) || EQ_16(last_core, TCX_10_CORE))
#else
diff --git a/lib_dec/FEC_scale_syn_fx.c b/lib_dec/FEC_scale_syn_fx.c
index 0e45ca98d3efa345e7532e59bcf0ad6495ca0254..0502417be40df622af42964771c72bc29829c5dd 100644
--- a/lib_dec/FEC_scale_syn_fx.c
+++ b/lib_dec/FEC_scale_syn_fx.c
@@ -569,7 +569,7 @@ void FEC_scale_syn_fx(
test();
test();
- if( avoid_lpc_burst_on_recovery && (GT_16(enr_LP, 160))&&(LE_16(enr_LP,shl(*old_enr_LP,1))))
+ if( avoid_lpc_burst_on_recovery && (GT_16(enr_LP, 160))&&(LE_16(enr_LP,shl_sat(*old_enr_LP,1))))
{
gain1 = s_min(gain1, 16384);
}
diff --git a/lib_dec/LD_music_post_filter.c b/lib_dec/LD_music_post_filter.c
index aa204721808e61df5df79df4d5f0574c3582878e..70905877dea7266134d1f3ffe203f4ec2e086466 100644
--- a/lib_dec/LD_music_post_filter.c
+++ b/lib_dec/LD_music_post_filter.c
@@ -759,6 +759,8 @@ void music_postfilt_init_flt(
set_f( hMusicPF->filt_lfE, 1.0f, DCT_L_POST );
hMusicPF->last_nonfull_music = 0;
-
+#ifdef IVAS_FLOAT_FIXED
+ hMusicPF->Old_ener_Q = 0;
+#endif
return;
}
diff --git a/lib_dec/LD_music_post_filter_fx.c b/lib_dec/LD_music_post_filter_fx.c
index e47fd61b8f999640152f3420b65aa94eaa4bb167..7798bf609902d49efdb7f63d48cf9017076c14da 100644
--- a/lib_dec/LD_music_post_filter_fx.c
+++ b/lib_dec/LD_music_post_filter_fx.c
@@ -783,7 +783,7 @@ void Prep_music_postP_fx(
/*------------------------------------------------------------*
* Resetting some memories in case of switching
*------------------------------------------------------------*/
-#ifdef _DIFF_FLOAT_FIX_
+#if 1//def _DIFF_FLOAT_FIX_
IF( EQ_16(last_core,HQ_CORE) || EQ_16(last_core, TCX_20_CORE) || EQ_16(last_core, TCX_10_CORE) )
#else
IF(EQ_16(last_core, HQ_CORE))
diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c
new file mode 100644
index 0000000000000000000000000000000000000000..893ae36aae58417da521608edfdfd7813a104396
--- /dev/null
+++ b/lib_dec/acelp_core_dec_ivas_fx.c
@@ -0,0 +1,4101 @@
+/******************************************************************************************************
+
+ (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
+ Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
+ Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
+ contributors to this repository. All Rights Reserved.
+
+ This software is protected by copyright law and by international treaties.
+ The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
+ Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
+ Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
+ contributors to this repository retain full ownership rights in their respective contributions in
+ the software. This notice grants no license of any kind, including but not limited to patent
+ license, nor is any license granted by implication, estoppel or otherwise.
+
+ Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
+ contributions.
+
+ This software is provided "AS IS", without any express or implied warranties. The software is in the
+ development stage. It is intended exclusively for experts who have experience with such software and
+ solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
+ and fitness for a particular purpose are hereby disclaimed and excluded.
+
+ Any dispute, controversy or claim arising under or in relation to providing this software shall be
+ submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
+ accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
+ the United Nations Convention on Contracts on the International Sales of Goods.
+
+*******************************************************************************************************/
+
+/*====================================================================================
+ EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
+ ====================================================================================*/
+#include
+#include
+#include
+#include "options.h"
+#include "cnst.h"
+#include "rom_com.h"
+#include "prot.h"
+#include "prot_fx1.h"
+#include "prot_fx2.h"
+#include "ivas_cnst.h"
+#include "ivas_prot.h"
+#include "ivas_rom_com.h"
+#include "wmc_auto.h"
+
+#ifdef IVAS_FLOAT_FIXED
+/*-------------------------------------------------------------------*
+ * acelp_core_dec_ivas_fx()
+ *
+ * ACELP core decoder
+ *-------------------------------------------------------------------*/
+static void acelp_decoder_state_float2fix(Decoder_State *st, STEREO_CNG_DEC_HANDLE hStereoCng);
+static void acelp_decoder_state_fix2float(Decoder_State *st, STEREO_CNG_DEC_HANDLE hStereoCng);
+static void rescale_fdCngDec(HANDLE_FD_CNG_DEC hFdCngDec, Word16 old_NoiseExp);
+ivas_error acelp_core_dec_ivas_fx(
+ Decoder_State *st, /* i/o: decoder state structure */
+ float output[], /* o : synthesis @internal Fs */
+ float synth[], /* o : synthesis */
+ float save_hb_synth[], /* o : HB synthesis */
+ float bwe_exc_extended[], /* i/o: bandwidth extended excitation */
+ float *voice_factors, /* o : voicing factors */
+ float old_syn_12k8_16k[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE */
+ const int16_t sharpFlag, /* i : formant sharpening flag */
+ float pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */
+ int16_t *unbits, /* o : number of unused bits */
+ int16_t *sid_bw, /* o : 0-NB/WB, 1-SWB SID */
+ STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */
+ const float tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */
+ const float tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */
+ const int16_t use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */
+ const int16_t last_element_mode, /* i : last element mode */
+ const int32_t last_element_brate, /* i : last element bitrate */
+ const int16_t flag_sec_CNA, /* i : CNA flag for secondary channel */
+ const int16_t nchan_out, /* i : number of output channels */
+ STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */
+ const int16_t read_sid_info /* i : read SID info flag */
+)
+{
+ Word16 /*output_fx[960], synth_fx[960], save_hb_synth_fx[960],*/ voice_factors_fx[NB_SUBFR16k], old_syn_12k8_16k_fx[960], pitch_buf_out_fx[NB_SUBFR16k], tdm_lspQ_PCh_fx[M], tdm_lsfQ_PCh_fx[M];
+
+ for (int i = 0; i < M; i++) {
+ tdm_lsfQ_PCh_fx[i] = (Word16)(tdm_lsfQ_PCh[i] * 2.56f);
+ }
+ floatToFixed_arr((float *)tdm_lspQ_PCh, tdm_lspQ_PCh_fx, Q15, M);
+
+
+ //Word32 bwe_exc_extended_fx[960];
+ float old_exc[L_EXC_DEC], *exc; /* excitation signal buffer */
+ Word16 old_exc_fx[L_EXC_DEC], *exc_fx; /* excitation signal buffer */
+ float syn_tmp[L_FRAME16k + L_SUBFR], *syn; /* synthesis signal buffer */
+ Word16 syn_tmp_fx[L_FRAME16k + L_SUBFR], *psyn_fx; /* synthesis signal buffer */
+ int16_t output_frame; /* frame length at output sampling freq. */
+ float lsf_new[M]; /* LSFs at the end of the frame */
+ Word16 lsf_new_fx[M]; /* LSFs at the end of the frame Qlog2(2.56) */
+ float lsp_new[M]; /* LSPs at the end of the frame */
+ Word16 lsp_new_fx[M]; /* LSPs at the end of the frame Q15 */
+ float lsp_mid[M]; /* LSPs in the middle of the frame */
+ Word16 lsp_mid_fx[M]; /* LSPs in the middle of the frame */
+ float Aq[NB_SUBFR16k * ( M + 1 )]; /* A(q) quantized for the 4 subframes */
+ Word16 Aq_fx[NB_SUBFR16k * ( M + 1 )]; /* A(q) quantized for the 4 subframes */
+ float old_exc2[L_FRAME16k + L_EXC_MEM], *exc2; /* total excitation buffer */
+ Word16 old_exc2_fx[L_FRAME16k + L_EXC_MEM], *exc2_fx; /* total excitation buffer */
+ //float mem_tmp[M]; /* temporary synthesis filter memory */
+ Word16 mem_tmp_fx[M]; /* temporary synthesis filter memory */
+ //float enr_q; /* E information for FER protection */
+ Word32 enr_q_fx; /* E information for FER protection */
+ float tmp_noise; /* Long term temporary noise energy */
+ Word16 tmp_noise_fx; /* Long term temporary noise energy */
+ float Es_pred; /* predicted scaled innov. energy */
+ Word16 Es_pred_fx; /* predicted scaled innov. energy Q8 */
+ //float FEC_pitch; /* FEC pitch */
+ Word16 FEC_pitch_fx; /* FEC pitch */
+ float old_bwe_exc[( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 )]; /* excitation buffer */
+ Word16 old_bwe_exc_fx[( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 )]; /* excitation buffer */
+ float *bwe_exc; /* Excitation for SWB TBE */
+ Word16 *bwe_exc_fx; /* Excitation for SWB TBE */
+ int16_t i, j, int_fs;
+ int16_t tc_subfr;
+ int16_t allow_cn_step;
+ float temp_buf[L_FRAME16k + L_SYN_MEM];
+ Word16 temp_buf_fx[L_FRAME16k + L_SYN_MEM];
+ int16_t last_pulse_pos;
+ int16_t T0_tmp;
+ int16_t do_WI;
+ //float dct_buffer[DCT_L_POST];
+ Word16 dct_buffer_fx[DCT_L_POST];
+ //float exc_buffer[DCT_L_POST];
+ Word16 exc_buffer_fx[DCT_L_POST];
+ //float dct_exc_tmp[L_FRAME16k];
+ Word16 dct_exc_tmp_fx[L_FRAME16k];
+ float bpf_error_signal[L_FRAME16k];
+ int16_t nb_bits; /* number of bits */
+ int16_t indice; /* parameter indices to write */
+ float gain_buf[NB_SUBFR16k];
+ Word16 gain_buf_fx[NB_SUBFR16k];
+ Word16 syn_fx_tmp2[L_FRAME_16k];
+ Word16 pitch_buf_tmp[NB_SUBFR16k];
+ Word16 update_flg;
+ //float q_env[20];
+ Word32 q_env_fx[20];
+ //float exc3[L_FRAME16k];
+ Word16 exc3_fx[L_FRAME16k];
+ //float syn1_tmp[L_FRAME16k + 2], *syn1;
+ Word16 syn1_tmp_fx[L_FRAME16k + 2], *syn1_fx;
+ float *realBuffer[CLDFB_NO_COL_MAX], *imagBuffer[CLDFB_NO_COL_MAX];
+#ifdef IVAS_FLOAT_FIXED
+ Word32 *realBuffer_fx[CLDFB_NO_COL_MAX], *imagBuffer_fx[CLDFB_NO_COL_MAX];
+ Word32 realBufferTmp_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
+ Word32 imagBufferTmp_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
+#endif // IVAS_FLOAT_FIXED
+ float realBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
+ float imagBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
+ int16_t LSF_Q_prediction; /* LSF prediction mode */
+ Word16 avoid_lpc_burst_on_recovery;
+ //float tmpF;
+ Word16 tmpF_fx;
+ int16_t uc_two_stage_flag;
+ int16_t tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag;
+ //float *old_exc_s; /* Start of last excitation frame */
+ Word16 *old_exc_s_fx; /* Start of last excitation frame */
+ //float *p_tdm_Pri_pitch_buf;
+ Word16 *p_tdm_Pri_pitch_buf_fx;
+ int16_t local_element_mode;
+ ivas_error error;
+
+ Word32 bpf_error_signal_fx[L_FRAME16k];
+ Word16 bpf_error_signal_16fx[L_FRAME16k];
+ Word16 tmp;
+
+ error = IVAS_ERR_OK;
+
+ if ( st->element_mode == IVAS_CPE_MDCT && nchan_out == 1 && st->idchan == 1 && last_element_brate <= IVAS_SID_5k2 )
+ {
+ /* In MDCT-Stereo DTX with mono output, we can skip CNG for the second channel, except for the first inactive frame following an active period */
+ return error;
+ }
+
+ push_wmops( "acelp_core_dec" );
+
+ output_frame = (int16_t) ( st->output_Fs / FRAMES_PER_SEC );
+
+ acelp_decoder_state_float2fix(st, hStereoCng);
+ /*----------------------------------------------------------------*
+ * stereo SID and CNG frames processing
+ *----------------------------------------------------------------*/
+ if ( st->core_brate <= SID_2k40 && st->element_mode == IVAS_CPE_DFT && nchan_out == 2 )
+ {
+ if ( st->cng_type == FD_CNG )
+ {
+ //configureFdCngDec_flt( st->hFdCngDec, st->bwidth, ACELP_14k25, st->L_frame, st->last_L_frame, st->element_mode );
+ configureFdCngDec( st->hFdCngDec, st->bwidth, ACELP_14k25, st->L_frame, st->last_L_frame, st->element_mode );
+ Word16 old_NoiseEstExp = st->hFdCngDec->hFdCngCom->sidNoiseEstExp;
+ /* Only run parameter decoding in SID frames */
+ if ( st->core_brate == SID_2k40 )
+ {
+ //FdCng_decodeSID_flt( st );
+ FdCng_decodeSID_ivas_fx( st );
+ //FdCng_decodeSID(st->hFdCngDec->hFdCngCom, st );
+ rescale_fdCngDec(st->hFdCngDec, old_NoiseEstExp - st->hFdCngDec->hFdCngCom->sidNoiseEstExp);
+ }
+ for ( i = 0; i < NPART; i++ )
+ {
+ //st->hFdCngDec->hFdCngCom->sidNoiseEstLp_flt[i] = STEREO_DFT_FD_FILT * st->hFdCngDec->hFdCngCom->sidNoiseEstLp_flt[i] + ( 1 - STEREO_DFT_FD_FILT ) * st->hFdCngDec->hFdCngCom->sidNoiseEst_flt[i];
+ st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] = L_add( Mpy_32_32( STEREO_DFT_FD_FILT_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] ),
+ Mpy_32_32( STEREO_DFT_FD_FILT_COMP_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEst[i] ) );
+ }
+
+#ifdef IVAS_FLOAT_FIXED
+ /*st->hFdCngDec->hFdCngCom->sidNoiseEstExp = 31 - Q4;
+ for ( int p = 0; p < NPART; p++ )
+ {
+ st->hFdCngDec->hFdCngCom->sidNoiseEstLp[p] = (Word32) ( st->hFdCngDec->hFdCngCom->sidNoiseEstLp_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) ) );
+ st->hFdCngDec->hFdCngCom->sidNoiseEst[p] = (Word32) ( st->hFdCngDec->hFdCngCom->sidNoiseEst_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) ) );
+ }
+ for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ )
+ {
+ st->hFdCngDec->bandNoiseShape[p] = (Word32) ( st->hFdCngDec->bandNoiseShape_float[p] * ( 1u << ( 31 - st->hFdCngDec->bandNoiseShape_exp ) ) );
+ }*/
+
+ ApplyFdCng_fx( NULL, 0, NULL, NULL, NULL, NULL, st, 0, 0 );
+ if (st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0) {
+ Scale_sig32(st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp);
+ st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0;
+ }
+
+ /*for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ )
+ {
+ if ( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp <= 31 )
+ {
+ st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) );
+ }
+ else
+ {
+ st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] * ( 1u << ( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp - 31 ) ) );
+ }
+ }
+ for ( int p = 0; p < NPART; p++ )
+ {
+ st->hFdCngDec->hFdCngCom->sidNoiseEstLp_flt[p] = (float) st->hFdCngDec->hFdCngCom->sidNoiseEstLp[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) );
+ }
+ for ( int p = 0; p < 24; p++ )
+ {
+ st->hFdCngDec->partNoiseShape_float[p] = (float) st->hFdCngDec->partNoiseShape[p] / ( 1u << ( 31 - st->hFdCngDec->partNoiseShape_exp ) );
+ }*/
+#else
+ ApplyFdCng_flt( NULL, NULL, NULL, NULL, st, 0, 0 );
+#endif // IVAS_FLOAT_FIXED
+ }
+ else
+ {
+ //configureFdCngDec_flt( st->hFdCngDec, st->bwidth, ACELP_14k25, st->L_frame, st->last_L_frame, st->element_mode );
+ configureFdCngDec( st->hFdCngDec, st->bwidth, ACELP_14k25, st->L_frame, st->last_L_frame, st->element_mode );
+
+ /* decode CNG parameters */
+ //CNG_dec( st, last_element_mode, Aq, lsp_new, lsf_new, &allow_cn_step, sid_bw, q_env );
+ CNG_dec_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx);
+
+ /* comfort noise generation */
+ //CNG_exc( st->core_brate, st->L_frame, &st->hTdCngDec->Enew, &st->hTdCngDec->cng_seed, NULL, NULL, &st->lp_ener, st->last_core_brate, &st->first_CNG, &( st->hTdCngDec->cng_ener_seed ), NULL, allow_cn_step, &st->hTdCngDec->last_allow_cn_step, st->hTdCngDec->num_ho, q_env, st->hTdCngDec->lp_env, st->hTdCngDec->old_env, st->hTdCngDec->exc_mem, st->hTdCngDec->exc_mem1, sid_bw, &st->hTdCngDec->cng_ener_seed1, NULL, st->Opt_AMR_WB, st->element_mode );
+ CNG_exc_fx( st->core_brate, st->L_frame, &st->hTdCngDec->Enew_fx, &st->hTdCngDec->cng_seed, NULL, NULL, &st->lp_ener_fx, st->last_core_brate, &st->first_CNG, &( st->hTdCngDec->cng_ener_seed ), NULL, allow_cn_step, &st->hTdCngDec->last_allow_cn_step, st->prev_Q_exc, st->Q_exc, st->hTdCngDec->num_ho_fx, q_env_fx, st->hTdCngDec->lp_env_fx, st->hTdCngDec->old_env_fx, st->hTdCngDec->exc_mem_fx, st->hTdCngDec->exc_mem1_fx, sid_bw, &st->hTdCngDec->cng_ener_seed1, NULL, st->Opt_AMR_WB, st->element_mode );
+
+ //mvr2r( Aq, st->Aq_cng_float, M + 1 );
+ Copy( Aq_fx, st->Aq_cng, M + 1 );
+
+ /* update old LSP and LSF vector */
+ /*mvr2r( lsf_new, st->lsf_old, M );
+ mvr2r( lsp_new, st->lsp_old, M );*/
+ Copy( lsf_new_fx, st->lsf_old_fx, M );
+ Copy( lsp_new_fx, st->lsp_old_fx, M );
+
+ /*Local fix2float (to be removed)*/
+ fixedToFloat_arr(st->Aq_cng, st->Aq_cng_float, Q14 - norm_s(st->Aq_cng[0]), M + 1);
+ /*fixedToFloat_arr(Aq_fx, Aq, Q12, NB_SUBFR16k * (M + 1));
+ fixedToFloat_arr(lsp_new_fx, lsp_new, Q15, M);
+ for (i = 0; i < M; i++) {
+ lsf_new[i] = lsf_new_fx[i] / 2.56f;
+ }*/
+ }
+
+ set_f( output, 0, output_frame ); /* output and synth are not used in DFT domain CNG generation and the decoder output is unaffected if they are left uninitalized */
+ set_f( synth, 0, output_frame ); /* They are however read in a few places which causes errors in the valgrind tests. Simplest solution from a code perspective was to set them to zero. */
+
+ /* CN generation done in DFT domain */
+ pop_wmops();
+
+ acelp_decoder_state_fix2float(st, hStereoCng);
+
+ return error;
+ }
+
+ /*----------------------------------------------------------------*
+ * Active frames processing
+ *----------------------------------------------------------------*/
+
+ /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
+ for ( i = 0; i < CLDFB_NO_COL_MAX; i++ )
+ {
+ set_f( realBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX );
+ set_f( imagBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX );
+ realBuffer[i] = realBufferTmp[i];
+ imagBuffer[i] = imagBufferTmp[i];
+ }
+#ifdef IVAS_FLOAT_FIXED
+ for ( i = 0; i < CLDFB_NO_COL_MAX; i++ )
+ {
+ set32_fx( realBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX );
+ set32_fx( imagBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX );
+ realBuffer_fx[i] = realBufferTmp_fx[i];
+ imagBuffer_fx[i] = imagBufferTmp_fx[i];
+ }
+#endif // IVAS_FLOAT_FIXED
+ /*----------------------------------------------------------------*
+ * Initialization
+ *----------------------------------------------------------------*/
+
+ LSF_Q_prediction = -1;
+ set_f( syn_tmp, 0, L_SUBFR );
+ syn = syn_tmp + L_SUBFR;
+ /*syn1_tmp[0] = 0;
+ syn1_tmp[1] = 0;
+ syn1 = syn1_tmp + 2;*/
+
+ set_s(syn_tmp_fx, 0, L_SUBFR);
+ psyn_fx = syn_tmp_fx + L_SUBFR;
+ syn1_tmp_fx[0] = 0;
+ syn1_tmp_fx[1] = 0;
+ syn1_fx = syn1_tmp_fx + 2;
+
+ st->bpf_off = 0;
+
+ if ( st->last_core == HQ_CORE || st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE || ( st->element_mode == IVAS_CPE_DFT && st->last_core_brate <= SID_2k40 ) || ( st->element_mode == IVAS_CPE_MDCT && st->last_core_brate <= SID_2k40 ) )
+ {
+ /* in case of HQ->ACELP switching, do not apply BPF */
+ st->bpf_off = 1;
+
+ if ( st->hPFstat != NULL )
+ {
+ /* in case of core switching, reset post-filter memories */
+ st->hPFstat->on = 0;
+ }
+
+ if ( st->hGSCDec != NULL )
+ {
+ /* reset the GSC pre echo energy threshold in case of switching */
+ //st->hGSCDec->Last_frame_ener = (float) MAX_32;
+ st->hGSCDec->Last_frame_ener_fx = MAX_32;
+ }
+ }
+
+ if ( st->hGSCDec != NULL && st->prev_bfi > 0 )
+ {
+ /* reset the GSC pre echo energy threshold in case of FEC */
+ //st->hGSCDec->Last_frame_ener = (float) MAX_32;
+ st->hGSCDec->Last_frame_ener_fx = MAX_32;
+ }
+
+ if ( ( st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD ) && ( st->last_core_brate == SID_2k40 || st->last_core_brate == FRAME_NO_DATA ) )
+ {
+ /*set_zero( st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, FFTLEN );
+ set_zero( hStereoCng->olapBufferSynth22, FFTLEN );*/
+ set_s( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, FFTLEN );
+ set_s( hStereoCng->olapBufferSynth22_fx, 0, FFTLEN );
+ }
+
+ st->clas_dec = st->last_good_fx;
+ //enr_q = 0.0f;
+ Es_pred = 0.0f;
+ tmp_noise = 0.0f;
+
+ enr_q_fx = 0;
+ Es_pred_fx = 0;
+ tmp_noise_fx = 0;
+
+ //mvr2r( st->old_exc, old_exc, L_EXC_MEM_DEC );
+ Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC );
+ exc = old_exc + L_EXC_MEM_DEC;
+ exc_fx = old_exc_fx + L_EXC_MEM_DEC;
+
+ if ( st->hWIDec != NULL )
+ {
+ //mvr2r( st->hWIDec->old_exc2, old_exc2, L_EXC_MEM );
+ Copy( st->hWIDec->old_exc2_fx, old_exc2_fx, L_EXC_MEM );
+ }
+ else
+ {
+ //set_f( old_exc2, 0, L_EXC_MEM );
+ set_s( old_exc2_fx, 0, L_EXC_MEM );
+ }
+ exc2 = old_exc2 + L_EXC_MEM;
+ exc2_fx = old_exc2_fx + L_EXC_MEM;
+
+ if ( st->hBWE_TD != NULL )
+ {
+ //mvr2r( st->hBWE_TD->old_bwe_exc, old_bwe_exc, PIT16k_MAX * 2 );
+ Copy( st->hBWE_TD->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2 );
+ bwe_exc = old_bwe_exc + PIT16k_MAX * 2;
+ bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2;
+ }
+ else
+ {
+ bwe_exc = NULL;
+ bwe_exc_fx = NULL;
+ }
+
+ last_pulse_pos = 0;
+ do_WI = 0;
+ //st->GSC_noisy_speech = 0;
+ st->GSC_noisy_speech_fx = 0;
+ //st->relax_prev_lsf_interp = 0;
+ st->relax_prev_lsf_interp_fx = 0;
+ set_zero( gain_buf, NB_SUBFR16k );
+ set_s( gain_buf_fx, 0, NB_SUBFR16k );
+
+ if ( st->L_frame == L_FRAME )
+ {
+ st->gamma_float = GAMMA1_FLT;
+ st->gamma = GAMMA1;
+ st->preemph_fac_float = PREEMPH_FAC_FLT;
+ st->preemph_fac = PREEMPH_FAC;
+ int_fs = INT_FS_12k8;
+ }
+ else
+ {
+ st->gamma_float = GAMMA16k_FLT;
+ st->gamma = GAMMA16k;
+ st->preemph_fac_float = PREEMPH_FAC_16k_FLT;
+ st->preemph_fac = PREEMPH_FAC_16k;
+ int_fs = INT_FS_16k;
+ }
+
+ /* reset post-filter in case of switching */
+ if ( st->hPFstat != NULL && st->hPFstat->on == 0 )
+ {
+ st->hPFstat->reset = 1;
+ }
+
+ avoid_lpc_burst_on_recovery = 0;
+ if (st->last_con_tcx && NE_16(st->L_frameTCX_past, st->L_frame) && st->last_core != 0)
+ {
+ avoid_lpc_burst_on_recovery = 1;
+ }
+
+ /* TD stereo parameters */
+ if ( st->element_mode == IVAS_CPE_TD && 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;
+ //p_tdm_Pri_pitch_buf = hStereoTD->tdm_Pri_pitch_buf;
+ p_tdm_Pri_pitch_buf_fx = hStereoTD->tdm_Pri_pitch_buf_fx;
+ /*local float2fix, to be removed*/
+ floatToFixed_arr(hStereoTD->tdm_Pri_pitch_buf, hStereoTD->tdm_Pri_pitch_buf_fx, Q6, NB_SUBFR );
+ }
+ else
+ {
+ tdm_lp_reuse_flag = 0;
+ tdm_low_rate_mode = 0;
+ if ( st->element_mode == IVAS_SCE && st->low_rate_mode )
+ {
+ tdm_low_rate_mode = 1;
+ }
+ tdm_Pitch_reuse_flag = 0;
+ //p_tdm_Pri_pitch_buf = NULL;
+ p_tdm_Pri_pitch_buf_fx = NULL;
+ }
+
+ /*----------------------------------------------------------------*
+ * Updates in case of internal sampling rate switching
+ *----------------------------------------------------------------*/
+
+ if ( st->last_L_frame != st->L_frame && ( st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE ) )
+ {
+ int16_t dec;
+
+ if ( st->hPFstat->on != 0 )
+ {
+ int16_t mem_syn_r_size_old, mem_syn_r_size_new;
+
+ //mem_syn_r_size_old = (int16_t) ( 1.25 * st->last_L_frame / 20.f );
+ //mem_syn_r_size_new = (int16_t) ( 1.25 * st->L_frame / 20.f );
+ mem_syn_r_size_old = mult_r( 2048, st->last_L_frame );
+ mem_syn_r_size_new = mult_r( 2048, st->L_frame );
+ //lerp_flt( st->hPFstat->mem_stp_flt + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp_flt + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
+ lerp( st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
+ //lerp_flt( st->hPFstat->mem_pf_in_flt + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in_flt + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
+ lerp( st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
+ }
+
+ /* convert quantized LSP vector */
+ //st->rate_switching_reset = lsp_convert_poly( st->lsp_old, st->L_frame, 0 );
+ st->rate_switching_reset = lsp_convert_poly_fx( st->lsp_old_fx, st->L_frame, 0 );
+
+ /* convert old quantized LSF vector */
+ //lsp2lsf( st->lsp_old, st->lsf_old, M, int_fs );
+ lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, int_fs );
+
+ /* FEC - update adaptive LSF mean vector */
+ //mvr2r( st->lsf_old, st->lsfoldbfi1, M );
+ //mvr2r( st->lsf_old, st->lsfoldbfi0, M );
+ //mvr2r( st->lsf_old, st->lsf_adaptive_mean, M );
+ Copy( st->lsf_old_fx, st->lsfoldbfi1_fx, M );
+ Copy( st->lsf_old_fx, st->lsfoldbfi0_fx, M );
+ Copy( st->lsf_old_fx, st->lsf_adaptive_mean_fx, M );
+
+ /* Reset LPC mem */
+ if ( st->sr_core == INT_FS_16k )
+ {
+ //mvr2r( GEWB2_Ave, st->mem_AR, M );
+ Copy( GEWB2_Ave_fx, st->mem_AR_fx, M );
+ }
+ else
+ {
+ //mvr2r( GEWB_Ave, st->mem_AR, M );
+ Copy( GEWB_Ave_fx, st->mem_AR_fx, M );
+ }
+ //set_zero( st->mem_MA, M );
+ set_s( st->mem_MA_fx, 0, M );
+
+ /* update synthesis filter memories */
+ dec = DEC;
+ if ( st->element_mode != EVS_MONO )
+ {
+ dec = DEC_IVAS;
+ }
+ //synth_mem_updt2_flt( st->L_frame, st->last_L_frame, st->old_exc, st->mem_syn_r_float, st->mem_syn2, NULL, dec );
+ synth_mem_updt2( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, dec );
+ //mvr2r( st->old_exc, old_exc, L_EXC_MEM_DEC );
+ //mvr2r( st->mem_syn2, st->mem_syn1, M );
+ //mvr2r( st->mem_syn2, st->mem_syn3, M );
+ Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC );
+ Copy_Scale_sig(st->mem_syn2_fx, st->mem_syn1_fx, M, sub(-1, st->Q_syn)); /*Q-1*/
+ Copy( st->mem_syn2_fx, st->mem_syn3_fx, M );
+ }
+
+ /* update buffer of old subframe pitch values */
+ IF(NE_16(st->last_L_frame, st->L_frame))
+ {
+ IF(EQ_16(st->L_frame, L_FRAME))
+ {
+ IF(EQ_16(st->last_L_frame, L_FRAME32k))
+ {
+ //tmpF = (float) 12800 / (float) 32000;
+ tmpF_fx = 13107;
+ }
+ ELSE IF(EQ_16(st->last_L_frame, 512))
+ {
+ //tmpF = (float)12800/(float)25600;
+ tmpF_fx = 16384;
+ }
+ ELSE /* st->last_L_frame == L_FRAME16k */
+ {
+ //tmpF = (float) 12800 / (float) 16000;
+ tmpF_fx = 26214;
+ }
+
+ FOR(i = NB_SUBFR16k - NB_SUBFR; i < NB_SUBFR16k; i++)
+ {
+ //st->old_pitch_buf[i - 1] = tmpF * st->old_pitch_buf[i];
+ st->old_pitch_buf_fx[i - 1] = Mpy_32_16_1(st->old_pitch_buf_fx[i], tmpF_fx);
+ move32();
+ }
+
+ FOR(i = 2 * NB_SUBFR16k - NB_SUBFR; i < 2 * NB_SUBFR16k; i++)
+ {
+ //st->old_pitch_buf[i - 2] = tmpF * st->old_pitch_buf[i];
+ st->old_pitch_buf_fx[i - 2] = Mpy_32_16_1(st->old_pitch_buf_fx[i], tmpF_fx);
+ move32();
+ }
+ }
+ ELSE
+ {
+ move16();
+ Word16 exp = 0;
+ IF(EQ_16(st->last_L_frame,L_FRAME32k))
+ {
+ /* (float)16000/(float)32000; */
+ tmpF_fx = 16384;
+ }
+ ELSE IF(EQ_16(st->last_L_frame,512))
+ {
+ /* tmpF = (float)16000/(float)25600; */
+ tmpF_fx = 20480;
+ }
+ ELSE /* st->last_L_frame == L_FRAME12k8 */
+ {
+ /* tmpF = (float)16000/(float)12800; */
+ tmpF_fx = 20480; //Q14
+ exp = 1;
+ }
+
+ FOR(i = 2 * NB_SUBFR - 1; i >= NB_SUBFR; i--)
+ {
+ //st->old_pitch_buf[i + 2] = tmpF * st->old_pitch_buf[i];
+ st->old_pitch_buf_fx[i + 2] = Mpy_32_16_1( L_shl( st->old_pitch_buf_fx[i], exp ), tmpF_fx );
+ move32();
+ }
+ //st->old_pitch_buf[NB_SUBFR + 1] = st->old_pitch_buf[NB_SUBFR + 2];
+ st->old_pitch_buf_fx[NB_SUBFR + 1] = st->old_pitch_buf_fx[NB_SUBFR + 2];
+ move32();
+
+ FOR(i = NB_SUBFR - 1; i >= 0; i--)
+ {
+ //st->old_pitch_buf[i + 1] = tmpF * st->old_pitch_buf[i];
+ st->old_pitch_buf_fx[i + 1] = Mpy_32_16_1( L_shl( st->old_pitch_buf_fx[i], exp ), tmpF_fx );
+ move32();
+ }
+ //st->old_pitch_buf[0] = st->old_pitch_buf[1];
+ st->old_pitch_buf_fx[0] = st->old_pitch_buf_fx[1];
+ move32();
+ }
+ }
+
+ IF(NE_16(st->bfi_pitch_frame, st->L_frame))
+ {
+ IF(EQ_16(st->L_frame, L_FRAME))
+ {
+ move16();
+ IF(EQ_16(st->bfi_pitch_frame, L_FRAME32k))
+ {
+ /* (float)12800/(float)32000; */
+ tmpF_fx = 13107;
+ }
+ ELSE IF(EQ_16(st->bfi_pitch_frame, 512))
+ {
+ /* (float)12800/(float)25600; */
+ tmpF_fx = 16384;
+ }
+ ELSE /* st->bfi_pitch_frame == L_FRAME16k */
+ {
+ /* (float)12800/(float)16000; */
+ tmpF_fx = 26214;
+ }
+ //st->bfi_pitch *= tmpF;
+ //st->bfi_pitch_frame = L_FRAME;
+ st->bfi_pitch_fx32 = Mpy_32_16_1(st->bfi_pitch_fx32, tmpF_fx);
+ st->bfi_pitch_frame = L_FRAME;
+ move16();
+ }
+ ELSE
+ {
+ move16();
+ Word16 exp = 0;
+ IF(EQ_16(st->bfi_pitch_frame,L_FRAME32k))
+ {
+ /* (float)16000/(float)32000; */
+ tmpF_fx = 16384;
+ }
+ ELSE IF(EQ_16(st->bfi_pitch_frame,512))
+ {
+ /* tmpF = (float)16000/(float)25600; */
+ tmpF_fx = 20480;
+ }
+ ELSE /* st->bfi_pitch_frame == L_FRAME12k8 */
+ {
+ /* tmpF = (float)16000/(float)12800; */
+ tmpF_fx = 20480; //Q14
+ exp = 1;
+ }
+ //st->bfi_pitch *= tmpF;
+ //st->bfi_pitch_frame = L_FRAME16k;
+ st->bfi_pitch_fx32 = Mpy_32_16_1( L_shl( st->bfi_pitch_fx32, exp ), tmpF_fx );
+ st->bfi_pitch_frame = L_FRAME16k;
+ move16();
+ }
+ }
+ if (st->bfi_pitch_fx32 > MAX_16) {
+ assert(0 && "st->bfi_pitch_fx (Word16,Q6) is overflowing");
+ }
+ else {
+ st->bfi_pitch_fx = extract_l(st->bfi_pitch_fx32);
+ }
+
+ /*Local fix2float (to be removed)*/
+ fixedToFloat_arr(old_exc_fx, old_exc, st->Q_exc, L_EXC_DEC);
+ fixedToFloat_arr(old_exc2_fx, old_exc2, st->Q_exc, L_FRAME16k + L_EXC_MEM);
+ fixedToFloat_arr(old_bwe_exc_fx, old_bwe_exc, st->Q_exc, ((PIT16k_MAX + (L_FRAME16k + 1) + L_SUBFR16k) * 2));
+ fixedToFloat_arr(gain_buf_fx, gain_buf, Q14, NB_SUBFR16k);
+
+ if ( st->last_bwidth == NB && st->bwidth != NB && st->ini_frame != 0 )
+ {
+ st->rate_switching_reset = 1;
+ }
+
+ /*----------------------------------------------------------------------*
+ * GOOD frame
+ *----------------------------------------------------------------------*/
+
+ if ( !st->bfi )
+ {
+
+ /*----------------------------------------------------------------*
+ * Decoding of TC subframe classification
+ *----------------------------------------------------------------*/
+
+ tc_subfr = -1;
+ if ( st->coder_type_fx == TRANSITION )
+ {
+ tc_subfr = tc_classif( st );
+ }
+
+ /*----------------------------------------------------------------*
+ * Decoding of GSC IVAS mode
+ *----------------------------------------------------------------*/
+
+ if ( st->element_mode > EVS_MONO && st->idchan == 0 && !( st->core_brate == FRAME_NO_DATA || st->core_brate == SID_2k40 ) && !tdm_low_rate_mode )
+ {
+ if ( st->coder_type_fx == AUDIO || ( st->coder_type_fx == INACTIVE && st->total_brate <= MAX_GSC_INACTIVE_BRATE ) )
+ {
+ st->GSC_IVAS_mode = get_next_indice( st, 2 );
+ }
+ }
+
+ /*----------------------------------------------------------------*
+ * Decoding of inactive CNG frames
+ *----------------------------------------------------------------*/
+
+ if ( st->core_brate == FRAME_NO_DATA || st->core_brate == SID_2k40 )
+ {
+ /* decode CNG parameters */
+ if ( st->cng_type == LP_CNG )
+ {
+ //CNG_dec( st, last_element_mode, Aq, lsp_new, lsf_new, &allow_cn_step, sid_bw, q_env );
+ CNG_dec_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx );
+ for (int nsf = 0; nsf < NB_SUBFR16k; nsf++) {
+ Scale_sig(Aq_fx + (nsf * (M + 1)), M + 1, norm_s(Aq_fx[nsf * (M + 1)]) - Q2);
+ Aq_fx[nsf * (M + 1)] = ONE_IN_Q12;
+ }
+ Copy( Aq_fx, st->Aq_cng, M + 1 );
+ /*Local fix2float (to be removed)*/
+ fixedToFloat_arr(st->Aq_cng, st->Aq_cng_float, Q12, M + 1);
+
+ /* comfort noise generation */
+ local_element_mode = st->element_mode;
+ if ( ( nchan_out == 1 && st->element_mode == IVAS_CPE_DFT ) || ( st->masa_sid_format == 1 ) )
+ {
+ local_element_mode = IVAS_SCE; /* For DFT Stereo mono decoding, run CNG_exc as in SCE */
+ }
+ //CNG_exc( st->core_brate, st->L_frame, &st->hTdCngDec->Enew, &st->hTdCngDec->cng_seed, exc, exc2, &st->lp_ener, st->last_core_brate, &st->first_CNG, &( st->hTdCngDec->cng_ener_seed ), bwe_exc, allow_cn_step, &st->hTdCngDec->last_allow_cn_step, st->hTdCngDec->num_ho, q_env, st->hTdCngDec->lp_env, st->hTdCngDec->old_env, st->hTdCngDec->exc_mem, st->hTdCngDec->exc_mem1, sid_bw, &st->hTdCngDec->cng_ener_seed1, exc3, st->Opt_AMR_WB, local_element_mode );
+ CNG_exc_fx( st->core_brate, st->L_frame, &st->hTdCngDec->Enew_fx, &st->hTdCngDec->cng_seed, exc_fx, exc2_fx, &st->lp_ener_fx, st->last_core_brate, &st->first_CNG, &( st->hTdCngDec->cng_ener_seed ), bwe_exc_fx, allow_cn_step, &st->hTdCngDec->last_allow_cn_step, st->prev_Q_exc, st->Q_exc, st->hTdCngDec->num_ho_fx, q_env_fx, st->hTdCngDec->lp_env_fx, st->hTdCngDec->old_env_fx, st->hTdCngDec->exc_mem_fx, st->hTdCngDec->exc_mem1_fx, sid_bw, &st->hTdCngDec->cng_ener_seed1, exc3_fx, st->Opt_AMR_WB, local_element_mode );
+ //mvr2r( Aq, st->Aq_cng_float, M + 1 );
+
+ }
+ else
+ {
+
+ if ( st->core_brate == SID_2k40 && st->element_mode != IVAS_CPE_MDCT )
+ {
+ //FdCng_decodeSID_flt( st );
+ Word16 old_NoiseEstExp = st->hFdCngDec->hFdCngCom->sidNoiseEstExp;
+ FdCng_decodeSID_ivas_fx( st );
+ rescale_fdCngDec(st->hFdCngDec, old_NoiseEstExp - st->hFdCngDec->hFdCngCom->sidNoiseEstExp);
+ Scale_sig(st->hFdCngDec->hFdCngCom->A_cng, M + 1, norm_s(st->hFdCngDec->hFdCngCom->A_cng[0]) - Q2);
+ //st->hFdCngDec->hFdCngCom->A_cng[0] = ONE_IN_Q12;
+ *sid_bw = 0;
+ }
+
+ if ( st->element_mode == IVAS_CPE_DFT )
+ {
+ assert( nchan_out == 1 );
+
+ for ( i = 0; i < NPART; i++ )
+ {
+ //st->hFdCngDec->hFdCngCom->sidNoiseEstLp_flt[i] = STEREO_DFT_FD_FILT * st->hFdCngDec->hFdCngCom->sidNoiseEstLp_flt[i] + ( 1 - STEREO_DFT_FD_FILT ) * st->hFdCngDec->hFdCngCom->sidNoiseEst_flt[i];
+ st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] = L_add( Mpy_32_32( STEREO_DFT_FD_FILT_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] ),
+ Mpy_32_32( STEREO_DFT_FD_FILT_COMP_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEst[i] ) );
+ }
+#ifdef IVAS_FLOAT_FIXED
+ /*Word16 syn_fx[L_FRAME16k + L_SUBFR] = { 0 };
+ st->Q_syn = 0;
+ for ( int p = 0; p < L_FRAME16k; p++ )
+ {
+ syn_fx[L_SUBFR + p] = (Word16) ( syn[p] * ( 1u << st->Q_syn ) );
+ }*/
+ /* local float2fix (to be removed) */
+ /*for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ )
+ {
+ st->hFdCngDec->bandNoiseShape[p] = (Word32) ( st->hFdCngDec->bandNoiseShape_float[p] * ( 1u << ( 31 - st->hFdCngDec->bandNoiseShape_exp ) ) );
+ }
+ st->hFdCngDec->hFdCngCom->sidNoiseEstExp = 31 - Q4;
+ for ( int p = 0; p < NPART; p++ )
+ {
+ st->hFdCngDec->hFdCngCom->sidNoiseEstLp[p] = (Word32)(st->hFdCngDec->hFdCngCom->sidNoiseEstLp_flt[p] * (1u << (31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp)));
+ st->hFdCngDec->hFdCngCom->sidNoiseEst[p] = (Word32) ( st->hFdCngDec->hFdCngCom->sidNoiseEst_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) ) );
+ }
+ for (int p = 0; p < FFTCLDFBLEN; p++)
+ {
+ st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] = (Word32)(st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] * (1u << (31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp)));
+ }*/
+ Word16 new_sidNoiseEstExp = 31 - Q4;
+ Scale_sig32(st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, st->hFdCngDec->hFdCngCom->sidNoiseEstExp - new_sidNoiseEstExp);
+ Scale_sig32(st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART, st->hFdCngDec->hFdCngCom->sidNoiseEstExp - new_sidNoiseEstExp);
+ st->hFdCngDec->hFdCngCom->sidNoiseEstExp = new_sidNoiseEstExp;
+ Word16 new_cngNoiseLevelExp = 31 - Q4;
+ Scale_sig32(st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp - new_cngNoiseLevelExp);
+ st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = new_cngNoiseLevelExp;
+
+ ApplyFdCng_fx(psyn_fx, st->Q_syn, NULL, realBuffer, imagBuffer, NULL, st, 0, ( st->coder_type_fx == AUDIO && !st->GSC_noisy_speech_fx ) );
+ if (st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0) {
+ Scale_sig32(st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp);
+ st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0;
+ }
+
+ /*for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ )
+ {
+ if ( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp <= 31 )
+ {
+ st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) );
+ }
+ else
+ {
+ st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] * ( 1u << ( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp - 31 ) ) );
+ }
+ }
+ for ( int p = 0; p < NPART; p++ )
+ {
+ st->hFdCngDec->hFdCngCom->sidNoiseEstLp_flt[p] = (float) st->hFdCngDec->hFdCngCom->sidNoiseEstLp[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) );
+ }
+ for ( int p = 0; p < 24; p++ )
+ {
+ st->hFdCngDec->partNoiseShape_float[p] = (float) st->hFdCngDec->partNoiseShape[p] / ( 1u << ( 31 - st->hFdCngDec->partNoiseShape_exp ) );
+ }*/
+#else
+ ApplyFdCng_flt( syn, NULL, realBuffer, imagBuffer, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) );
+#endif // IVAS_FLOAT_FIXED
+ }
+
+ if ( !read_sid_info )
+ {
+ //float noise_lvl_highest;
+ Word32 noise_lvl_highest_fx;
+
+ //noise_lvl_highest = st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand - 1];
+ noise_lvl_highest_fx = st->hFdCngDec->hFdCngCom->cngNoiseLevel[st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand - 1];
+ for ( int16_t b = st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand; b < st->hFdCngDec->hFdCngCom->stopBand; b++ )
+ {
+ st->hFdCngDec->hFdCngCom->cngNoiseLevel[b] = noise_lvl_highest_fx;
+ }
+ }
+
+ //generate_comfort_noise_dec_flt( NULL, NULL, st, nchan_out );
+ generate_comfort_noise_dec(NULL, NULL, NULL, st, &(st->Q_exc), 1, nchan_out);
+
+ //FdCng_exc_flt( st->hFdCngDec->hFdCngCom, &st->CNG_mode, st->L_frame, st->lsp_old, st->first_CNG, st->lspCNG, Aq, lsp_new, lsf_new, exc, exc2, bwe_exc );
+ FdCng_exc(st->hFdCngDec->hFdCngCom, &st->CNG_mode, st->L_frame, st->lsp_old_fx, st->first_CNG, st->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx);
+
+ //mvr2r( exc2, exc3, st->L_frame );
+ Copy( exc2_fx, exc3_fx, st->L_frame );
+ }
+
+ Word16 delta_mem_scale = 3;
+ move16();
+ test();
+ if (LT_32(st->lp_ener_fx, 40) && EQ_16(st->cng_type, LP_CNG)) /* very low energy frames, less than 0.3125 */
+ {
+ delta_mem_scale = 0;
+ move16();
+ }
+ i = st->Q_exc;
+ Rescale_exc(st->hMusicPF->dct_post_old_exc_fx, exc_fx, bwe_exc_fx, st->hGSCDec->last_exc_dct_in_fx, st->L_frame,
+ st->L_frame* HIBND_ACB_L_FAC, 0, &(st->Q_exc), st->Q_subfr, NULL, 0, INACTIVE);
+ Rescale_mem(st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, delta_mem_scale,
+ &st->mem_deemph_fx, st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, 0, 0, NULL);
+ Copy_Scale_sig(exc2_fx, exc2_fx, st->L_frame, sub(st->Q_exc, i));
+
+ /* update past excitation signals for LD music post-filter */
+ if ( st->hMusicPF != NULL )
+ {
+ //mvr2r( st->hMusicPF->dct_post_old_exc + L_FRAME, st->hMusicPF->dct_post_old_exc, DCT_L_POST - L_FRAME - OFFSET2 );
+ Copy( st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 );
+ //mvr2r( exc2, st->hMusicPF->dct_post_old_exc + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME );
+ Copy( exc2_fx, st->hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME );
+
+ /* Update music post processing values */
+ /* Filter energies update */
+ for ( i = 0; i < DCT_L_POST; i++ )
+ {
+ //st->hMusicPF->filt_lfE[i] = 0.3f + 0.7f * st->hMusicPF->filt_lfE[i];
+ st->hMusicPF->filt_lfE_fx[i] = add( 9830, mult_r( 22937, st->hMusicPF->filt_lfE_fx[i] ) );
+ }
+ }
+
+
+ /* synthesis at 12.8kHz sampling rate */
+ //syn_12k8( st->L_frame, Aq, exc2, syn, st->mem_syn2, 1 );
+ Aq_fx[0] = ONE_IN_Q12;
+ syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn );
+ //syn_12k8( st->L_frame, Aq, exc3, syn1, st->mem_syn3, 1 );
+ syn_12k8_fx( st->L_frame, Aq_fx, exc3_fx, syn1_fx, st->mem_syn3_fx, 1, st->Q_exc, st->Q_syn );
+ st->Q_syn_cng = st->Q_syn;
+ st->Q_exc_cng = st->Q_exc;
+ /* reset the decoder */
+ //CNG_reset_dec( st, pitch_buf, voice_factors );
+ CNG_reset_dec_fx( st, pitch_buf_out_fx, voice_factors_fx );
+
+ /* update st->mem_syn1 for ACELP core switching */
+ //mvr2r( st->mem_syn3, st->mem_syn1, M );
+ Copy_Scale_sig( st->mem_syn3_fx, st->mem_syn1_fx, M, sub(-1, st->Q_syn));
+
+ /* update old synthesis for classification */
+ //mvr2r( syn1 + st->L_frame - L_SYN_MEM_CLAS_ESTIM, st->mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM );
+ Copy( syn1_fx + st->L_frame - L_SYN_MEM_CLAS_ESTIM, st->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM );
+
+ /* save and delay synthesis to be used by SWB BWE */
+ Copy_Scale_sig(syn1_fx, temp_buf_fx, st->L_frame, sub(-1, st->Q_syn));
+ if ( st->hBWE_FD != NULL )
+ {
+ //save_old_syn( st->L_frame, syn1, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k, st->preemph_fac_float, &st->hBWE_FD->mem_deemph_old_syn );
+ save_old_syn_fx(st->L_frame, syn1_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx);
+ }
+
+ }
+
+ /*----------------------------------------------------------------*
+ * Decoding of all other frames
+ *----------------------------------------------------------------*/
+
+ else
+ {
+
+ /*-----------------------------------------------------------------*
+ * Configure ACELP bit allocation
+ *-----------------------------------------------------------------*/
+
+ nb_bits = 0;
+ st->acelp_cfg.FEC_mode = 0;
+ uc_two_stage_flag = 0;
+
+ if ( !st->nelp_mode_dec_fx && !st->ppp_mode_dec_fx )
+ {
+ int16_t tc_subfr_tmp;
+
+ tc_subfr_tmp = tc_subfr;
+ if ( tc_subfr_tmp < L_SUBFR )
+ {
+ tc_subfr_tmp = 0;
+ }
+
+ if ( tc_subfr == TC_0_192 )
+ {
+ nb_bits = -1;
+ }
+
+ config_acelp1_IVAS( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, st->GSC_noisy_speech_fx, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type_fx, tc_subfr_tmp, 1, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode );
+
+ if ( st->coder_type_fx == TRANSITION && tc_subfr < L_SUBFR && st->L_frame == L_FRAME )
+ {
+ config_acelp1_IVAS( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, -1, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type_fx, tc_subfr, 2, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode );
+ }
+ }
+
+ /*-----------------------------------------------------------------*
+ * After CNG period, use the most up-to-date LSPs
+ *-----------------------------------------------------------------*/
+
+ if ( st->hTdCngDec != NULL && ( st->last_core_brate == FRAME_NO_DATA || st->last_core_brate == SID_2k40 ) )
+ {
+ //mvr2r( st->lspCNG, st->lsp_old, M );
+ Copy( st->lspCNG_fx, st->lsp_old_fx, M );
+ //lsp2lsf( st->lspCNG, st->lsf_old, M, int_fs );
+ lsp2lsf_fx( st->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_preemp_preQ = 0.0f;
+ st->mem_preemp_preQ_fx = 0;
+ //st->last_nq_preQ = 0;
+ st->last_nq_preQ_fx = 0;
+ st->last_code_preq = 0;
+ }
+ st->use_acelp_preq = 0;
+
+ /*-----------------------------------------------------------------*
+ * LSF de-quantization and interpolation
+ *-----------------------------------------------------------------*/
+
+ if ( !tdm_lp_reuse_flag )
+ {
+ //lsf_dec( st, tc_subfr, Aq, &LSF_Q_prediction, lsf_new, lsp_new, lsp_mid, tdm_low_rate_mode, tdm_lsfQ_PCh );
+ lsf_dec_fx( st, tc_subfr, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode/*, tdm_lsfQ_PCh*/ );
+ }
+ else
+ {
+ //const float *pt_interp_2;
+ const Word16 *pt_interp_2_fx;
+
+ if ( st->active_cnt != 1 )
+ {
+ int16_t beta_index;
+
+ beta_index = get_next_indice( st, TDM_IC_LSF_PRED_BITS );
+ //tdm_SCh_lsf_reuse( DEC, st->element_brate, lsf_new, lsp_new, tdm_lsfQ_PCh, NULL, &beta_index );
+ //tdm_SCh_lsf_reuse_ivas_fx( DEC, st->element_brate, lsf_new_fx, lsp_new_fx, tdm_lsfQ_PCh_fx, NULL, &beta_index );
+ tdm_SCh_lsf_reuse_fx(DEC, st->element_brate, lsf_new_fx, lsp_new_fx, tdm_lsfQ_PCh_fx, NULL, &beta_index);
+ }
+ else
+ {
+ //mvr2r( tdm_lspQ_PCh, lsp_new, M );
+ Copy( tdm_lspQ_PCh_fx, lsp_new_fx, M );
+ //mvr2r( tdm_lspQ_PCh, lsp_new, M );
+ Copy( tdm_lsfQ_PCh_fx, lsf_new_fx, M );
+ }
+
+ if ( st->rate_switching_reset )
+ {
+ /* extrapolation in case of unstable LSF convert */
+ //mvr2r( lsp_new, st->lsp_old, M );
+ Copy( lsp_new_fx, st->lsp_old_fx, M );
+ //mvr2r( lsf_new, st->lsf_old, M );
+ Copy( lsf_new_fx, st->lsf_old_fx, M );
+ }
+
+ //pt_interp_2 = interpol_frac_12k8;
+ pt_interp_2_fx = interpol_frac_fx;
+ if ( tdm_low_rate_mode == 1 && st->coder_type_fx > UNVOICED )
+ {
+ //pt_interp_2 = intercpol_frac2;
+ pt_interp_2_fx = interpol_frac2_fx;
+ }
+
+ if ( st->active_cnt == 1 )
+ {
+ //mvr2r( lsp_new, st->lsp_old, M );
+ Copy( lsp_new_fx, st->lsp_old_fx, M );
+ //lsp2lsf( lsp_new, st->lsf_old, M, st->sr_core );
+ lsp2lsf_fx( lsp_new_fx, st->lsf_old_fx, M, st->sr_core );
+ }
+
+ /* LSP interpolation and conversion of LSPs to A(z) */
+ //int_lsp( st->L_frame, st->lsp_old, lsp_new, Aq, M, pt_interp_2, 0 );
+ int_lsp_fx( st->L_frame, st->lsp_old_fx, lsp_new_fx, Aq_fx, M, pt_interp_2_fx, 0 );
+ /* Check LSF stability (distance between old LSFs and current LSFs) */
+ //st->stab_fac = lsf_stab( lsf_new, st->lsf_old, 0, st->L_frame );
+ st->stab_fac_fx = lsf_stab_ivas_fx( lsf_new_fx, st->lsf_old_fx, 0, st->L_frame );
+ }
+ for (int nsf = 0; nsf < NB_SUBFR16k; nsf++) {
+ Scale_sig(Aq_fx + (nsf * (M + 1)), M + 1, norm_s(Aq_fx[nsf * (M + 1)]) - Q2);
+ Aq_fx[nsf * (M + 1)] = ONE_IN_Q12;
+ }
+ if ( st->last_core == HQ_CORE && st->element_mode > EVS_MONO )
+ {
+ /* Prepare ACB memory from last HQ frame */
+ //old_exc_s = st->old_exc + L_EXC_MEM_DEC - st->L_frame;
+ old_exc_s_fx = st->old_exc_fx + L_EXC_MEM_DEC - st->L_frame;
+ //tmpF = *old_exc_s;
+ tmpF_fx = *old_exc_s_fx;
+ st->mem_deemph = old_exc_s_fx[st->L_frame - 1];
+ //preemph( old_exc_s, st->preemph_fac_float, L_FRAME16k, &tmpF );
+ preemph_fx( old_exc_s_fx, st->preemph_fac, L_FRAME16k, &tmpF_fx );
+ //mvr2r( old_exc_s + st->L_frame - M, st->mem_syn2, M );
+ Copy(old_exc_s_fx + st->L_frame - M, st->mem_syn2_fx, M );
+ //residu( Aq, M, old_exc_s, old_exc + L_EXC_MEM_DEC - st->L_frame, st->L_frame );
+ Residu3_fx( Aq_fx, old_exc_s_fx, old_exc_fx + L_EXC_MEM_DEC - st->L_frame, st->L_frame, 0 );
+ }
+
+ if ( st->last_core != ACELP_CORE && st->element_mode > EVS_MONO )
+ {
+ /* Prepare ACB memory of old_bwe_exc */
+ if ( st->L_frame == L_FRAME )
+ {
+ //lerp_flt( old_exc, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC );
+ lerp( old_exc_fx, old_bwe_exc_fx, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC );
+ }
+ else
+ {
+ //lerp_flt( old_exc, old_bwe_exc, L_EXC_MEM_DEC * 2, L_EXC_MEM_DEC );
+ lerp( old_exc_fx, old_bwe_exc_fx, L_EXC_MEM_DEC * 2, L_EXC_MEM_DEC );
+ }
+ }
+
+ /*-----------------------------------------------------------------*
+ * FEC - first good frame after lost frame(s) (possibility to correct the ACB)
+ *-----------------------------------------------------------------*/
+
+ if ( st->acelp_cfg.FEC_mode > 0 )
+ {
+ last_pulse_pos = 0;
+
+ /* decode the last glottal pulse position */
+ //T0_tmp = FEC_pos_dec( st, &last_pulse_pos, &enr_q, nb_bits );
+ T0_tmp = FEC_pos_dec_fx( st, &last_pulse_pos, &enr_q_fx, nb_bits );
+
+ if ( st->last_core != HQ_CORE || ( st->last_core == HQ_CORE && st->last_con_tcx ) )
+ {
+ if ( st->clas_dec == SIN_ONSET && last_pulse_pos != 0 && st->prev_bfi == 1 )
+ {
+ //FEC_SinOnset( old_exc + L_EXC_MEM_DEC - L_EXC_MEM, last_pulse_pos, T0_tmp, enr_q, Aq, st->L_frame );
+ FEC_SinOnset_fx( old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, last_pulse_pos, T0_tmp, enr_q_fx, Aq_fx, st->L_frame, st->Q_exc );
+ }
+ else if ( ( st->coder_type_fx == GENERIC || st->coder_type_fx == VOICED ) && last_pulse_pos != 0 && st->old_bfi_cnt == 1 && st->hWIDec != NULL )
+ {
+ //do_WI = FEC_enhACB( st->L_frame, st->last_L_frame, old_exc + L_EXC_MEM_DEC - L_EXC_MEM, T0_tmp, last_pulse_pos, st->bfi_pitch );
+ do_WI = FEC_enhACB_fx( st->L_frame, st->last_L_frame, old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, T0_tmp, last_pulse_pos, st->bfi_pitch_fx );
+ }
+ }
+ }
+
+ /*------------------------------------------------------------*
+ * In case of first frame after an erasure and transition from voiced to unvoiced or inactive
+ * redo the LPC interpolation
+ *------------------------------------------------------------*/
+
+ if ( st->stab_fac_fx == 0 && st->old_bfi_cnt > 0 && st->clas_dec != VOICED_CLAS && st->clas_dec != ONSET && st->relax_prev_lsf_interp_fx == 0 && !( st->element_mode == IVAS_CPE_TD && st->idchan == 1 ) )
+ {
+ //int_lsp4( st->L_frame, st->lsp_old, lsp_mid, lsp_new, Aq, M, 2 );
+ int_lsp4_fx( st->L_frame, st->lsp_old_fx, lsp_mid_fx, lsp_new_fx, Aq_fx, M, 2 );
+ }
+
+ /*---------------------------------------------------------------*
+ * Decoding of the scaled predicted innovation energy
+ *---------------------------------------------------------------*/
+
+ if ( nb_bits > 0 )
+ {
+ indice = get_next_indice( st, nb_bits );
+ //Es_pred_dec( &Es_pred, indice, nb_bits, uc_two_stage_flag );
+ Es_pred_dec_fx( &Es_pred_fx, indice, nb_bits, uc_two_stage_flag );
+ }
+
+ /*------------------------------------------------------------*
+ * Decode excitation according to coding type
+ *------------------------------------------------------------*/
+
+ if ( tdm_low_rate_mode ) /* tdm stereo low rate mode */
+ {
+ if ( st->coder_type_fx <= UNVOICED )
+ {
+ //tdm_low_rate_dec( st, dct_exc_tmp, &tmp_noise, pitch_buf, voice_factors, exc, exc2, bwe_exc, lsf_new );
+ tdm_low_rate_dec_fx( st, dct_exc_tmp_fx/*, &tmp_noise*/, pitch_buf_out_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, st->Q_exc );
+ }
+ else /* GENERIC */
+ {
+ //decod_gen_2sbfr( st, sharpFlag, Aq, pitch_buf, voice_factors, exc, exc2, bwe_exc, gain_buf, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf );
+ decod_gen_2sbfr_ivas_fx( st, sharpFlag, Aq_fx, pitch_buf_out_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx, st->Q_exc );
+
+ if ( st->element_mode == IVAS_CPE_TD )
+ {
+ //tmp_noise = st->lp_gainc;
+ tmp_noise_fx = shr_r(st->lp_gainc_fx, 3); /*Q0*/
+ }
+ }
+ }
+ else if ( st->nelp_mode_dec_fx )
+ {
+ /* SC-VBR - NELP frames */
+ Scale_sig(exc_fx - L_EXC_MEM, L_EXC_MEM, -st->Q_exc);
+ st->Q_exc = 0;
+ move16();
+ /* SC-VBR - NELP frames */
+ //decod_nelp( st, &tmp_noise, pitch_buf, exc, exc2, voice_factors, bwe_exc, st->bfi, gain_buf );
+ decod_nelp_fx( st, &tmp_noise_fx, pitch_buf_out_fx, exc_fx, exc2_fx, voice_factors_fx, bwe_exc_fx, &st->Q_exc, st->bfi, gain_buf_fx);
+ Rescale_exc(st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32)0, &(st->Q_exc), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type_fx);
+ }
+ else if ( st->coder_type_fx == UNVOICED )
+ {
+ /* UNVOICED frames */
+ //decod_unvoiced( st, Aq, Es_pred, uc_two_stage_flag, &tmp_noise, pitch_buf, voice_factors, exc, exc2, bwe_exc, gain_buf );
+ //decod_unvoiced_fx( st, Aq_fx, st->coder_type, &tmp_noise_fx, pitch_buf_out_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx);
+ decod_unvoiced_ivas_fx( st, Aq_fx, Es_pred_fx, uc_two_stage_flag, st->coder_type_fx, &tmp_noise_fx, pitch_buf_out_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, st->Q_exc, gain_buf_fx);
+ tmp_noise_fx = shr_r(st->lp_gainc_fx, 3); /*Q0*/
+ }
+ else if ( st->ppp_mode_dec_fx)
+ {
+ Scale_sig(exc_fx - L_EXC_MEM, L_EXC_MEM, -st->Q_exc);
+ st->Q_exc = 0;
+ /* SC-VBR - PPP frames */
+ //if ( ( error = decod_ppp( st, Aq, pitch_buf, exc, exc2, voice_factors, bwe_exc, gain_buf, st->bfi ) ) != IVAS_ERR_OK )
+ if ( ( error = decod_ppp_fx( st, Aq_fx, pitch_buf_out_fx, exc_fx, exc2_fx, st->bfi, gain_buf_fx, voice_factors_fx, bwe_exc_fx ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+
+ Rescale_exc(st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32)0, &(st->Q_exc), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type_fx);
+
+ }
+ else if ( st->coder_type_fx == TRANSITION )
+ {
+ //decod_tran( st, st->L_frame, tc_subfr, Aq, Es_pred, pitch_buf, voice_factors, exc, exc2, bwe_exc, unbits, sharpFlag, gain_buf );
+ decod_tran_fx( st, st->L_frame, tc_subfr, Aq_fx, Es_pred_fx, pitch_buf_out_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, sharpFlag, gain_buf_fx);
+ }
+ else if ( st->coder_type_fx == AUDIO || ( st->coder_type_fx == INACTIVE && st->inactive_coder_type_flag ) )
+ {
+ /* AUDIO and INACTIVE frames (coded by GSC technology) */
+ //decod_audio( st, dct_exc_tmp, Aq, &tmp_noise, pitch_buf, voice_factors, exc, exc2, bwe_exc, lsf_new, gain_buf, tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf );
+ decod_audio_ivas_fx( st, dct_exc_tmp_fx, Aq_fx, pitch_buf_out_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf_fx
+#if 1//def ADD_LRTD
+ , tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx
+#endif
+ );
+ tmp_noise_fx = shr_r(st->lp_gainc_fx, 3); /*Q0*/
+ }
+ else
+ {
+ /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */
+ //if ( ( error = decod_gen_voic( st, st->L_frame, sharpFlag, Aq, Es_pred, do_WI, pitch_buf, voice_factors, exc, exc2, bwe_exc, unbits, gain_buf, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf ) ) != IVAS_ERR_OK )
+ //if ( ( error = decod_gen_voic_fx( st, st->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI, pitch_buf_out_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf_fx/*, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx*/) ) != IVAS_ERR_OK )
+ if ( ( error = decod_gen_voic_ivas_fx( st, st->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI, pitch_buf_out_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+
+ if ( st->element_mode == IVAS_CPE_TD )
+ {
+ //tmp_noise = st->lp_gainc;
+ tmp_noise_fx = shr_r(st->lp_gainc_fx, 3); /*Q0*/
+ }
+ }
+
+ //printf("\nnextBitPos: %d ", st->next_bit_pos);
+ /* synthesis for ACELP core switching and SWB BWE */
+ //syn_12k8( st->L_frame, Aq, exc, temp_buf, st->mem_syn1, 1 );
+ syn_12k8_fx( st->L_frame, Aq_fx, exc_fx, temp_buf_fx, st->mem_syn1_fx, 1, st->Q_exc, -1);
+
+ /* save and delay synthesis to be used by SWB BWE */
+ if ( st->hBWE_FD != NULL )
+ {
+ //save_old_syn( st->L_frame, temp_buf, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k, st->preemph_fac_float, &st->hBWE_FD->mem_deemph_old_syn );
+ save_old_syn_fx( st->L_frame, temp_buf_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx );
+ }
+
+ /*-----------------------------------------------------------------*
+ * Apply energy matching when switching to inactive frames
+ *-----------------------------------------------------------------*/
+
+ //inact_switch_ematch( exc2, dct_exc_tmp, st->hGSCDec->lt_ener_per_band, st->coder_type, st->L_frame, st->total_brate, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode );
+ Inac_switch_ematch_ivas_fx( exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type_fx, st->L_frame, st->total_brate, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode );
+
+ /*------------------------------------------------------------*
+ * Decode information and modify the excitation signal of stationary unvoiced frames
+ *------------------------------------------------------------*/
+
+ if ( !( st->idchan == 1 && st->element_mode == IVAS_CPE_TD ) && st->nelp_mode_dec_fx != 1 && !( st->element_mode == IVAS_SCE && tdm_low_rate_mode ) )
+ {
+ //stat_noise_uv_dec( st, lsp_new, lsp_mid, Aq, exc2, uc_two_stage_flag );
+ stat_noise_uv_dec_fx(st, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx, uc_two_stage_flag);
+ }
+
+ /*------------------------------------------------------------*
+ * Save filter memory in case the synthesis is redone after scaling
+ * Synthesis at 12k8 Hz sampling rate
+ *------------------------------------------------------------*/
+
+ /* update past excitation signals for LD music post-filter */
+ if ( st->hMusicPF != NULL )
+ {
+ /*mvr2r( st->hMusicPF->dct_post_old_exc + L_FRAME, st->hMusicPF->dct_post_old_exc, DCT_L_POST - L_FRAME - OFFSET2 );
+ mvr2r( exc2, st->hMusicPF->dct_post_old_exc + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME );
+ mvr2r( st->hMusicPF->dct_post_old_exc, exc_buffer, DCT_L_POST - OFFSET2 );*/
+ Copy( st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 );
+ Copy( exc2_fx, st->hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME );
+ Copy( st->hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, DCT_L_POST - OFFSET2 );
+ }
+
+ if ( ( st->coder_type_fx == AUDIO && !st->GSC_noisy_speech_fx ) || ( st->GSC_IVAS_mode >= 1 && st->L_frame == L_FRAME ) )
+ {
+ int16_t last_coder_type = st->last_coder_type_fx;
+
+ if ( ( st->idchan == 1 && st->element_mode == IVAS_CPE_TD ) || ( st->GSC_IVAS_mode >= 1 && st->GSC_noisy_speech_fx == 0 ) )
+ {
+ last_coder_type = AUDIO;
+ }
+
+ Word16 qdct = 0;
+ /* Extrapolation of the last future part, windowing and high resolution DCT transform */
+ //Prep_music_postP( exc_buffer, dct_buffer, st->hMusicPF->filt_lfE, st->last_core, pitch_buf, st->hMusicPF->LDm_enh_lp_gbin );
+ Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, st->hMusicPF->filt_lfE_fx, st->last_core, pitch_buf_out_fx, st->hMusicPF->LDm_enh_lp_gbin_fx, st->Q_exc, &qdct);
+
+ /* LD music post-filter */
+ //LD_music_post_filter( st->hMusicPF, dct_buffer, dct_buffer, st->core_brate, AUDIO, last_coder_type );
+ LD_music_post_filter_fx( st->hMusicPF, dct_buffer_fx, dct_buffer_fx, st->core_brate, &st->hMusicPF->Old_ener_Q, AUDIO, last_coder_type, qdct );
+
+ /* Inverse DCT transform, retrieval of the aligned excitation, re-synthesis */
+ //mvr2r( st->mem_syn2, mem_tmp, M );
+ Copy( st->mem_syn2_fx, mem_tmp_fx, M );
+ //Post_music_postP( dct_buffer, exc_buffer, exc2, st->mem_syn2, st->mem_syn2, Aq, syn );
+ Post_music_postP_fx(dct_buffer_fx, exc2_fx, st->mem_syn2_fx, st->mem_syn2_fx, Aq_fx, psyn_fx, &st->Q_exc, &st->prev_Q_syn,
+ &st->Q_syn, st->mem_syn_clas_estim_fx, 0, &st->mem_deemph_fx, st->hBPF->pst_old_syn_fx,
+ &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, temp_buf_fx, mem_tmp_fx);
+ }
+ else
+ {
+ /* Core synthesis at 12.8kHz or 16kHz */
+ i = 1;
+ move16();
+ if (EQ_16(st->coder_type_fx, INACTIVE))
+ {
+ i = 0;
+ move16();
+ }
+ /* add extra headroom in case a CNA addition is likely (i.e. st_fx->psf_lp_noise_fx is close to the threshold) */
+ Word16 k = 0;
+ move16();
+ test();
+ test();
+ if (EQ_16(st->coder_type_fx, INACTIVE) && st->flag_cna&&GE_16(round_fx(L_shl(st->lp_noise, 1)), 15 << 7))
+ {
+ k = 1;
+ move16();
+ }
+
+ Rescale_mem(st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, 4, &st->mem_deemph_fx,
+ st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, i, k, temp_buf_fx);
+
+ //mvr2r( st->mem_syn2, mem_tmp, M );
+ Copy( st->mem_syn2_fx, mem_tmp_fx, M );
+ //syn_12k8( st->L_frame, Aq, exc2, syn, st->mem_syn2, 1 );
+ syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn);
+
+ if ( st->hMusicPF != NULL )
+ {
+ for ( i = 0; i < DCT_L_POST; i++ )
+ {
+ //st->hMusicPF->filt_lfE[i] = 0.3f + 0.7f * st->hMusicPF->filt_lfE[i];
+ st->hMusicPF->filt_lfE_fx[i] = round_fx(L_mac((1228 << (16)), 22938, st->hMusicPF->filt_lfE_fx[i]));
+ }
+ }
+ }
+
+ /*------------------------------------------------------------*
+ * FEC - Estimate the classification information
+ *------------------------------------------------------------*/
+
+ //FEC_clas_estim( syn, pitch_buf, st->L_frame, st->coder_type, st->codec_mode, st->mem_syn_clas_estim, &st->clas_dec, &st->lp_ener_bfi, st->Opt_AMR_WB, &st->decision_hyst, NULL, NULL, NULL, NULL, NULL, NULL, temp_buf, 0, 0, 0, 0, 0, 0, st->last_core_brate, st->acelp_cfg.FEC_mode );
+ FEC_clas_estim_fx(st, st->Opt_AMR_WB, st->L_frame, &st->clas_dec, st->coder_type_fx, pitch_buf_out_fx,
+ psyn_fx, &st->lp_ener_FER_fx, &st->decision_hyst,
+ NULL, NULL, NULL, NULL, 0, NULL, st->core_brate, st->Q_syn, temp_buf_fx,
+ st->mem_syn_clas_estim_fx, &st->classifier_Q_mem_syn,
+ 0, 0, 0, st->last_core_brate, st->acelp_cfg.FEC_mode);
+ /*------------------------------------------------------------*
+ * FEC - Estimate pitch
+ *------------------------------------------------------------*/
+
+ //FEC_pitch_estim( st->Opt_AMR_WB, st->last_core, st->L_frame, st->clas_dec, st->last_good, pitch_buf, st->old_pitch_buf, &st->bfi_pitch, &st->bfi_pitch_frame, &st->upd_cnt, st->coder_type );
+ FEC_pitch_estim_fx(st->Opt_AMR_WB, st->last_core, st->L_frame, st->clas_dec, st->last_good_fx, pitch_buf_out_fx, st->old_pitch_buf_fx,
+ &st->bfi_pitch_fx, &st->bfi_pitch_frame, &st->upd_cnt, st->coder_type_fx);
+
+ /*------------------------------------------------------------*
+ * FEC - Smooth the speech energy evolution when recovering after a BAD frame
+ * (smoothing is performed in the excitation domain and signal is resynthesized after)
+ *------------------------------------------------------------*/
+
+ move16();
+ Copy_Scale_sig(pitch_buf_out_fx, pitch_buf_tmp, NB_SUBFR16k, -Q6);
+ //FEC_scale_syn( st->L_frame, st->clas_dec, st->last_good, syn, pitch_buf, st->enr_old, enr_q, st->coder_type, LSF_Q_prediction, &st->scaling_flag, &st->lp_ener_FEC_av_float, &st->lp_ener_FEC_max_float, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, exc, exc2, Aq, &st->old_enr_LP_float, mem_tmp, st->mem_syn2, st->last_con_tcx && ( st->L_frameTCX_past != st->L_frame ) && ( st->last_core != ACELP_CORE ), 0 );
+ FEC_scale_syn_fx(st->L_frame, &update_flg, st->clas_dec, st->last_good_fx, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type_fx, LSF_Q_prediction,
+ &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate,
+ exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, avoid_lpc_burst_on_recovery, 0);
+
+ /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */
+ if ( ( st->idchan == 1 && st->element_mode == IVAS_CPE_TD && st->total_brate <= ACELP_7k20 ) || ( st->total_brate == ACELP_7k20 ) || ( st->total_brate == ACELP_8k00 ) )
+ {
+ //fer_energy( st->L_frame, st->clas_dec, syn, pitch_buf[( ( st->L_frame ) >> 6 ) - 1], &st->enr_old, st->L_frame );
+ frame_ener_fx(st->L_frame, st->clas_dec, psyn_fx, pitch_buf_tmp[sub(shr(st->L_frame, 6), 1)], &st->enr_old_fx, st->L_frame, st->Q_syn, 3, 0);
+ }
+ }
+
+ //printf("\n%f ",st->hBWE_FD->mem_deemph_old_syn);
+ /*printf("\n");
+ for (int nm = 0; nm < NS2SA(16000, DELAY_FD_BWE_ENC_NS); nm++) {
+ printf("%f ", st->hBWE_FD->old_syn_12k8_16k[nm]);
+ }*/
+ } /* End of GOOD FRAME */
+
+ /*----------------------------------------------------------------*
+ * BAD frame
+ *----------------------------------------------------------------*/
+
+ else
+ {
+ /* SC-VBR */
+ IF(EQ_16(st->last_nelp_mode_dec_fx, 1))
+ {
+ st->nelp_mode_dec_fx = 1;
+ move16();
+ }
+
+ /* long burst frame erasures */
+ IF(GT_16(st->nbLostCmpt, 5) && GE_16(st->clas_dec, VOICED_CLAS) && LT_16(st->clas_dec, INACTIVE_CLAS))
+ {
+ st->last_good_fx = VOICED_TRANSITION;
+ move16();
+ }
+
+ /* LSF estimation and A(z) calculation */
+ //lsf_dec_bfi_flt( MODE1, lsf_new, st->lsf_old, st->lsf_adaptive_mean, NULL, st->mem_MA, st->mem_AR, st->stab_fac, st->last_coder_type, st->L_frame, st->last_good, st->nbLostCmpt, 0, NULL, NULL, NULL, st->hGSCDec->Last_GSC_pit_band_idx, st->Opt_AMR_WB, st->bwidth );
+ lsf_dec_bfi(MODE1, lsf_new_fx, st->lsf_old_fx, st->lsf_adaptive_mean_fx, NULL, st->mem_MA_fx, st->mem_AR_fx, st->stab_fac_fx, st->last_coder_type_fx, st->L_frame, st->last_good_fx, st->nbLostCmpt, 0, NULL, NULL, NULL, st->hGSCDec->Last_GSC_pit_band_idx_fx, st->Opt_AMR_WB, 0, st->bwidth);
+
+ //FEC_lsf2lsp_interp_flt( st, st->L_frame, Aq, lsf_new, lsp_new );
+ FEC_lsf2lsp_interp(st, st->L_frame, Aq_fx, lsf_new_fx, lsp_new_fx);
+ for (int nsf = 0; nsf < NB_SUBFR16k; nsf++) {
+ Scale_sig(Aq_fx + (nsf * (M + 1)), M + 1, norm_s(Aq_fx[nsf * (M + 1)]) - Q2);
+ Aq_fx[nsf * (M + 1)] = ONE_IN_Q12;
+ }
+ if ( st->nelp_mode_dec_fx == 1 )
+ {
+ /* SC-VBR */
+ Scale_sig(exc_fx - L_EXC_MEM, L_EXC_MEM, -st->Q_exc);
+ st->Q_exc = 0;
+ move16();
+
+ //decod_nelp( st, &tmp_noise, pitch_buf, exc, exc2, voice_factors, bwe_exc, st->bfi, gain_buf );
+ decod_nelp_fx(st, &tmp_noise_fx, pitch_buf_out_fx, exc_fx, exc2_fx, voice_factors_fx, bwe_exc_fx, &st->Q_exc, st->bfi, gain_buf_fx);
+ FEC_pitch_fx = pitch_buf_out_fx[3];
+
+ Rescale_exc(st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32)0, &(st->Q_exc), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type_fx);
+ }
+ else
+ {
+ /* calculation of excitation signal */
+ //FEC_exc_estim( st, st->L_frame, exc, exc2, dct_exc_tmp, pitch_buf, voice_factors, &FEC_pitch, bwe_exc, lsf_new, &tmp_noise );
+ FEC_exc_estim_fx(st, st->L_frame, exc_fx, exc2_fx, dct_exc_tmp_fx, pitch_buf_out_fx, voice_factors_fx, &FEC_pitch_fx, bwe_exc_fx, lsf_new_fx, &st->Q_exc, &tmp_noise_fx);
+
+ Rescale_exc(NULL, exc_fx, bwe_exc_fx, st->hGSCDec->last_exc_dct_in_fx, st->L_frame, L_FRAME32k, (Word32)0,
+ &(st->Q_exc), st->Q_subfr, exc2_fx, st->L_frame, st->last_coder_type_fx);
+
+ //tmp_noise = st->lp_gainc;
+ tmp_noise_fx = shr_r(st->lp_gainc_fx, 3); /*Q0*/
+
+ /* SC-VBR */
+ //st->prev_gain_pit_dec = st->lp_gainp;
+ st->prev_gain_pit_dec_fx = st->lp_gainp_fx;
+ }
+
+ /* synthesis for ACELP core switching and SWB BWE */
+ //syn_12k8( st->L_frame, Aq, exc, temp_buf, st->mem_syn1, 1 );
+ syn_12k8_fx(st->L_frame, Aq_fx, exc_fx, temp_buf_fx, st->mem_syn1_fx, 1, st->Q_exc, -1);
+
+ /* save and delay synthesis to be used by SWB BWE */
+ if ( st->hBWE_FD != NULL )
+ {
+ //save_old_syn( st->L_frame, temp_buf, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k, st->preemph_fac_float, &st->hBWE_FD->mem_deemph_old_syn );
+ save_old_syn_fx(st->L_frame, temp_buf_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx);
+ }
+
+ /* Apply energy matching when switching to inactive frames */
+ //inact_switch_ematch( exc2, dct_exc_tmp, st->hGSCDec->lt_ener_per_band, st->coder_type, st->L_frame, st->total_brate, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode );
+ Inac_switch_ematch_ivas_fx(exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type_fx, st->L_frame, st->total_brate, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode);
+
+ /* update past excitation signals for LD music post-filter */
+ if ( st->hMusicPF != NULL )
+ {
+ //mvr2r( st->hMusicPF->dct_post_old_exc + L_FRAME, st->hMusicPF->dct_post_old_exc, DCT_L_POST - L_FRAME - OFFSET2 );
+ Copy(st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2);
+ //mvr2r( exc2, st->hMusicPF->dct_post_old_exc + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME );
+ Copy(exc2_fx, st->hMusicPF->dct_post_old_exc_fx + (DCT_L_POST - L_FRAME - OFFSET2), L_FRAME);
+
+ /* Update music post processing values */
+ /* Filter energies update */
+ for ( i = 0; i < DCT_L_POST; i++ )
+ {
+ //st->hMusicPF->filt_lfE[i] = 0.3f + 0.7f * st->hMusicPF->filt_lfE[i];
+ st->hMusicPF->filt_lfE_fx[i] = round_fx(L_mac((1228 << (16)), 22938, st->hMusicPF->filt_lfE_fx[i]));
+ }
+ /* Update circular buffer, keep last energy difference unchanged */
+ for ( i = 1; i < MAX_LT; i++ )
+ {
+ //st->hMusicPF->LDm_lt_diff_etot[i - 1] = st->hMusicPF->LDm_lt_diff_etot[i];
+ st->hMusicPF->LDm_lt_diff_etot_fx[i - 1] = st->hMusicPF->LDm_lt_diff_etot_fx[i];
+ }
+ }
+
+ /* synthesis at 12k8 Hz sampling rate */
+ /* add extra headroom in case a CNA addition is likely (i.e. st_fx->psf_lp_noise_fx is close to the threshold) */
+ Word16 k = 0;
+ move16();
+ test();
+ test();
+ if (EQ_16(st->coder_type_fx, INACTIVE) && st->flag_cna&&GE_16(round_fx(L_shl(st->lp_noise, 1)), 15 << 7))
+ {
+ k = 1;
+ move16();
+ }
+
+ Rescale_mem(st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, 4, &st->mem_deemph_fx,
+ st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, 1, k, temp_buf_fx);
+
+ if ( ( st->total_brate == ACELP_7k20 ) || ( st->total_brate == ACELP_8k00 ) )
+ {
+ //mvr2r( st->mem_syn2, mem_tmp, M );
+ Copy(st->mem_syn2_fx, mem_tmp_fx, M);
+ }
+ //syn_12k8( st->L_frame, Aq, exc2, syn, st->mem_syn2, 1 );
+ syn_12k8_fx(st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn);
+
+ /* update buffer for classifier */
+ if ( st->hWIDec != NULL )
+ {
+ //mvr2r( exc2 + st->L_frame - L_EXC_MEM, st->hWIDec->old_exc2, L_EXC_MEM );
+ Copy(exc2_fx + st->L_frame - L_EXC_MEM, st->hWIDec->old_exc2_fx, L_EXC_MEM);
+ //mvr2r( syn + st->L_frame - L_EXC_MEM, st->hWIDec->old_syn2, L_EXC_MEM );
+ Copy(psyn_fx + st->L_frame - L_EXC_MEM, st->hWIDec->old_syn2_fx, L_EXC_MEM);
+ }
+ st->prev_Q_exc_fr = st->Q_exc;
+ st->prev_Q_syn_fr = st->Q_syn;
+
+ //mvr2r( syn + st->L_frame - L_SYN_MEM_CLAS_ESTIM, st->mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM );
+ Copy(psyn_fx + st->L_frame - L_SYN_MEM_CLAS_ESTIM, st->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM);
+
+ /*------------------------------------------------------------*
+ * FEC - Smooth the speech energy evolution when recovering after a BAD frame
+ * (smoothing is performed in the excitation domain and signal is resynthesized after)
+ *------------------------------------------------------------*/
+
+ if ( ( st->total_brate == ACELP_7k20 ) || ( st->total_brate == ACELP_8k00 ) )
+ {
+ Copy_Scale_sig(pitch_buf_out_fx, pitch_buf_tmp, NB_SUBFR16k, -Q6);
+
+ //FEC_scale_syn( st->L_frame, st->clas_dec, st->last_good, syn, pitch_buf, st->enr_old, enr_q, st->coder_type, LSF_Q_prediction, &st->scaling_flag, &st->lp_ener_FEC_av_float, &st->lp_ener_FEC_max_float, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, exc, exc2, Aq, &st->old_enr_LP_float, mem_tmp, st->mem_syn2, st->last_con_tcx && ( st->L_frameTCX_past != st->L_frame ) && ( st->last_core != ACELP_CORE ), 0 );
+ FEC_scale_syn_fx(st->L_frame, &update_flg, st->clas_dec, st->last_good_fx, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type_fx, LSF_Q_prediction,
+ &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate,
+ exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, avoid_lpc_burst_on_recovery, 0);
+ }
+
+ /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */
+ //fer_energy( st->L_frame, st->last_good, syn, FEC_pitch, &st->enr_old, st->L_frame );
+ frame_ener_fx(st->L_frame, st->last_good_fx, psyn_fx, shr(add(FEC_pitch_fx, 32), 6), &st->enr_old_fx, st->L_frame, st->Q_syn, 3, 0);
+
+ if ( st->nelp_mode_dec_fx != 1 )
+ {
+ /* modify the excitation signal of stationary unvoiced frames */
+ //stat_noise_uv_mod( st->coder_type, 0, st->lsp_old, lsp_new, lsp_new, Aq, exc2, 1, &st->ge_sm, &st->uv_count, &st->act_count, st->lspold_s, &st->noimix_seed, &st->min_alpha, &st->exc_pe, st->core_brate, st->bwidth );
+ stat_noise_uv_mod_fx(st->coder_type_fx, 0, st->lsp_old_fx, lsp_new_fx, lsp_new_fx, Aq_fx, exc2_fx, st->Q_exc, 1, &st->ge_sm_fx,
+ &st->uv_count_fx, &st->act_count_fx, st->lspold_s_fx, &st->noimix_seed_fx, &st->min_alpha_fx,
+ &st->exc_pe_fx, st->core_brate, st->bwidth, &st->Q_stat_noise, &st->Q_stat_noise_ge);
+ }
+ }
+
+#ifdef IVAS_FLOAT_FIXED
+ //floatToFixed_arr(Aq, Aq_fx, Q12, NB_SUBFR16k * (M + 1));
+ IF(st->hBWE_TD != NULL)
+ {
+ IF(EQ_16(st->L_frame, L_FRAME))
+ {
+ //Copy_Scale_sig(Aq_fx + 2 * (M + 1), st->hBWE_TD->cur_sub_Aq_fx, norm_s((Aq_fx + 2 * (M + 1))[0]) - Q2,(M + 1));
+ Copy( Aq_fx + 2 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) );
+ }
+ ELSE
+ {
+ //Copy_Scale_sig( Aq_fx + 3 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, norm_s( (Aq_fx + 3 * (M + 1))[0] ) - Q2, ( M + 1 ) );
+ Copy( Aq_fx + 3 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) );
+ }
+ //fixedToFloat_arr(st->hBWE_TD->cur_sub_Aq_fx, st->hBWE_TD->cur_sub_Aq, Q12, M + 1);
+ }
+#else
+ if (st->hBWE_TD != NULL)
+ {
+ if (st->L_frame == L_FRAME)
+ {
+ mvr2r(Aq + 2 * (M + 1), st->hBWE_TD->cur_sub_Aq, (M + 1));
+ }
+ else
+ {
+ mvr2r(Aq + 3 * (M + 1), st->hBWE_TD->cur_sub_Aq, (M + 1));
+ }
+ }
+#endif
+
+ /*--------------------------------------------------------*
+ * Apply NB postfilter in case of 8kHz output
+ *--------------------------------------------------------*/
+#ifdef IVAS_FLOAT_FIXED
+ test();
+ IF(EQ_16(st->last_bwidth, NB) && st->hPFstat != NULL)
+ {
+ Copy(pitch_buf_out_fx, pitch_buf_tmp, NB_SUBFR16k);
+ IF(EQ_16(st->bwidth, NB))
+ {
+ st->hPFstat->on = 1;
+#ifdef IVAS_FLOAT_FIXED
+ move16();
+ nb_post_filt(st->L_frame, st->hPFstat, &st->psf_lp_noise_fx, tmp_noise_fx, psyn_fx, Aq_fx, pitch_buf_tmp, st->coder_type_fx, st->BER_detect, 0);
+
+#else
+ nb_post_filt_ivas(st->L_frame, L_SUBFR, st->hPFstat, &st->psf_lp_noise, tmp_noise, syn, Aq, pitch_buf, st->coder_type, st->BER_detect, 0);
+#endif
+ }
+ ELSE
+ {
+ st->hPFstat->on = 0;
+#ifdef IVAS_FLOAT_FIXED
+ nb_post_filt(st->L_frame, st->hPFstat, &st->psf_lp_noise_fx, tmp_noise_fx, psyn_fx, Aq_fx, pitch_buf_tmp, AUDIO, st->BER_detect, 0);
+
+#else
+ nb_post_filt_ivas(st->L_frame, L_SUBFR, st->hPFstat, &st->psf_lp_noise, tmp_noise, syn, Aq, pitch_buf, AUDIO, st->BER_detect, 0);
+#endif
+ }
+ }
+ else
+ {
+#ifdef IVAS_FLOAT_FIXED
+ st->psf_lp_noise_fx = round_fx(L_shl(st->lp_noise, 1));
+
+#else
+ st->psf_lp_noise = st->lp_noise_float;
+#endif
+ }
+#else
+ if (st->last_bwidth == NB && st->hPFstat != NULL)
+ {
+ if (st->bwidth == NB)
+ {
+ st->hPFstat->on = 1;
+ nb_post_filt_ivas(st->L_frame, L_SUBFR, st->hPFstat, &st->psf_lp_noise, tmp_noise, syn, Aq, pitch_buf, st->coder_type, st->BER_detect, 0);
+ }
+ else
+ {
+ st->hPFstat->on = 0;
+ nb_post_filt_ivas(st->L_frame, L_SUBFR, st->hPFstat, &st->psf_lp_noise, tmp_noise, syn, Aq, pitch_buf, AUDIO, st->BER_detect, 0);
+ }
+ }
+ else
+ {
+ st->psf_lp_noise = st->lp_noise_float;
+ }
+#endif
+
+ /*------------------------------------------------------------------*
+ * Perform fixed deemphasis through 1/(1 - g*z^-1)
+ *-----------------------------------------------------------------*/
+
+ /* update old synthesis buffer - needed for ACELP internal sampling rate switching */
+#ifdef IVAS_FLOAT_FIXED
+#ifdef IVAS_FLOAT_FIXED
+ Copy(psyn_fx + st->L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM);
+#else
+ mvr2r(syn + st->L_frame - L_SYN_MEM, st->mem_syn_r_float, L_SYN_MEM);
+#endif
+
+#ifdef IVAS_FLOAT_FIXED
+ deemph_fx(psyn_fx, st->preemph_fac, st->L_frame, &(st->mem_deemph_fx));
+ #else
+ deemph(syn, st->preemph_fac_float, st->L_frame, &(st->mem_deemph));
+#endif
+#ifdef IVAS_FLOAT_FIXED
+ unscale_AGC(psyn_fx, st->Q_syn, syn_fx_tmp2, st->agc_mem_fx, st->L_frame);
+ Copy(syn_fx_tmp2, psyn_fx, st->L_frame);
+#else
+ AGC_dec(syn, st->agc_mem2, st->L_frame);
+#endif
+
+#ifdef IVAS_FLOAT_FIXED
+ //floatToFixed_arr(syn, psyn_fx, st->Q_syn, L_FRAME16k);
+
+ IF(st->hTcxDec != NULL)
+ {
+ Copy_Scale_sig(psyn_fx + st->L_frame / 2, st->hTcxDec->old_syn_Overl, st->L_frame / 2, sub(-1, st->Q_syn)); /*Q-1*/
+ //fixedToFloat_arr(st->hTcxDec->old_syn_Overl, st->hTcxDec->old_syn_Overl_float, st->Q_syn - 1, st->L_frame / 2);
+ }
+ Copy_Scale_sig(psyn_fx + st->L_frame - M - 1, st->syn, M + 1, sub(0, st->Q_syn)); /*Q0*/
+ //fixedToFloat_arr(st->syn, st->syn_float, st->Q_syn, M + 1);
+#else
+ if (st->hTcxDec != NULL)
+ {
+ mvr2r(syn + st->L_frame / 2, st->hTcxDec->old_syn_Overl_float, st->L_frame / 2);
+ }
+ mvr2r(syn + st->L_frame - M - 1, st->syn_float, M + 1);
+#endif
+#else
+ mvr2r(syn + st->L_frame - L_SYN_MEM, st->mem_syn_r_float, L_SYN_MEM);
+ deemph(syn, st->preemph_fac_float, st->L_frame, &(st->mem_deemph));
+
+ AGC_dec(syn, st->agc_mem2, st->L_frame);
+
+ if (st->hTcxDec != NULL)
+ {
+ mvr2r(syn + st->L_frame / 2, st->hTcxDec->old_syn_Overl_float, st->L_frame / 2);
+ }
+ mvr2r(syn + st->L_frame - M - 1, st->syn_float, M + 1);
+#endif
+
+ /*------------------------------------------------------------------*
+ * Formant post-filter
+ *-----------------------------------------------------------------*/
+#ifdef IVAS_FLOAT_FIXED
+ //Word16 temp_buf_fx[L_FRAME16k + L_SYN_MEM];
+ test();
+ test();
+ test();
+ IF(st->hPFstat != NULL && GE_16(st->last_bwidth, WB) && (GT_32(st->core_brate, ACELP_24k40) || GT_16(st->element_mode, EVS_MONO)) && LE_32(st->core_brate, ACELP_32k))
+ {
+ st->hPFstat->on = 1;
+#ifdef IVAS_FLOAT_FIXED
+ /*----ftf conversions---*/
+ //floatToFixed_arr(syn, psyn_fx, st->Q_syn, st->L_frame);
+ Copy(psyn_fx, temp_buf_fx + L_SYN_MEM, L_FRAME16k);
+
+ set16_fx(st->hPFstat->mem_zero, 0, M);
+
+ formant_post_filt_fx(st->hPFstat, temp_buf_fx + L_SYN_MEM, Aq_fx, psyn_fx, st->L_frame, st->lp_noise, st->total_brate, 0);
+
+#else
+ mvr2r(syn, temp_buf + L_SYN_MEM, L_FRAME16k);
+ formant_post_filt_ivas(st->hPFstat, temp_buf + L_SYN_MEM, Aq, syn, st->L_frame, L_SUBFR, st->lp_noise_float, st->total_brate, 0);
+#endif
+ }
+ ELSE IF(st->hPFstat != NULL && GE_16(st->last_bwidth, WB))
+ {
+ IF(st->hPFstat->on)
+ {
+#ifdef IVAS_FLOAT_FIXED
+
+ Copy(st->hPFstat->mem_pf_in + L_SYN_MEM - M, temp_buf_fx, M);
+ Copy(psyn_fx, temp_buf_fx + M, L_SUBFR);
+
+ Residu3_fx(Aq_fx, temp_buf_fx + M, temp_buf_fx + M + L_SUBFR, L_SUBFR, 1);
+ E_UTIL_synthesis(1, Aq_fx, temp_buf_fx + M + L_SUBFR, temp_buf_fx, L_SUBFR, st->hPFstat->mem_stp + L_SYN_MEM - M, 0, M);
+ scale_st(psyn_fx, temp_buf_fx, &st->hPFstat->gain_prec, L_SUBFR);
+ Copy(temp_buf_fx, psyn_fx, L_SUBFR / 2);
+ blend_subfr2(temp_buf_fx + L_SUBFR / 2, psyn_fx + L_SUBFR / 2, psyn_fx + L_SUBFR / 2);
+
+#else
+ mvr2r(st->hPFstat->mem_pf_in_flt + L_SYN_MEM - M, temp_buf, M);
+ mvr2r(syn, temp_buf + M, L_SUBFR);
+ residu(Aq, M, temp_buf + M, temp_buf + M + L_SUBFR, L_SUBFR);
+ syn_filt(Aq, M, temp_buf + M + L_SUBFR, temp_buf, L_SUBFR, st->hPFstat->mem_stp_flt + L_SYN_MEM - M, 0);
+ scale_st_ivas(syn, temp_buf, &st->hPFstat->gain_prec_flt, L_SUBFR, -1);
+ mvr2r(temp_buf, syn, L_SUBFR / 2);
+ blend_subfr2_flt(temp_buf + L_SUBFR / 2, syn + L_SUBFR / 2, syn + L_SUBFR / 2);
+#endif
+ }
+ st->hPFstat->on = 0;
+ }
+#else
+ if (st->hPFstat != NULL && st->last_bwidth >= WB && (st->core_brate > ACELP_24k40 || st->element_mode > EVS_MONO) && st->core_brate <= ACELP_32k)
+ {
+ mvr2r(syn, temp_buf + L_SYN_MEM, L_FRAME16k);
+
+ st->hPFstat->on = 1;
+ formant_post_filt_ivas(st->hPFstat, temp_buf + L_SYN_MEM, Aq, syn, st->L_frame, L_SUBFR, st->lp_noise_float, st->total_brate, 0);
+ }
+ else if (st->hPFstat != NULL && st->last_bwidth >= WB)
+ {
+ if (st->hPFstat->on)
+ {
+ mvr2r(st->hPFstat->mem_pf_in_flt + L_SYN_MEM - M, temp_buf, M);
+ mvr2r(syn, temp_buf + M, L_SUBFR);
+ residu(Aq, M, temp_buf + M, temp_buf + M + L_SUBFR, L_SUBFR);
+ syn_filt(Aq, M, temp_buf + M + L_SUBFR, temp_buf, L_SUBFR, st->hPFstat->mem_stp_flt + L_SYN_MEM - M, 0);
+ scale_st_ivas(syn, temp_buf, &st->hPFstat->gain_prec_flt, L_SUBFR, -1);
+ mvr2r(temp_buf, syn, L_SUBFR / 2);
+ blend_subfr2_flt(temp_buf + L_SUBFR / 2, syn + L_SUBFR / 2, syn + L_SUBFR / 2);
+ }
+ st->hPFstat->on = 0;
+ }
+#endif
+
+ /*----------------------------------------------------------------*
+ * Comfort noise addition
+ *----------------------------------------------------------------*/
+
+ if ((st->hFdCngDec != NULL || st->idchan == 1) && st->element_mode != IVAS_CPE_MDCT)
+ {
+ if (st->element_mode == IVAS_CPE_TD || st->flag_cna || (st->cng_type == FD_CNG && st->total_brate <= ACELP_32k) || (st->cng_type == LP_CNG && st->core_brate <= SID_2k40))
+ {
+ /*VAD only for non inactive frame*/
+ st->VAD = st->VAD && (st->coder_type_fx != INACTIVE);
+
+ if (st->idchan == 0 && (st->flag_cna || (st->cng_type == FD_CNG && st->total_brate <= ACELP_32k) || (st->cng_type == LP_CNG && st->core_brate <= SID_2k40)))
+ {
+ /*Noisy speech detector*/
+ //noisy_speech_detection_flt(st->hFdCngDec, st->VAD, syn);
+ noisy_speech_detection(st->hFdCngDec, st->VAD, psyn_fx, st->Q_syn);
+
+ //st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt = 0.99f * st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt + 0.01f * (float)st->hFdCngDec->hFdCngCom->flag_noisy_speech;
+ st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r(st->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440/*0.99 Q15*/);
+ IF(st->hFdCngDec->hFdCngCom->flag_noisy_speech != 0)
+ {
+ st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add(st->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328/*0.01 Q15*/);
+ move16();
+ }
+#ifdef IVAS_FLOAT_FIXED
+ st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_deposit_h(st->hFdCngDec->hFdCngCom->likelihood_noisy_speech);
+#endif
+ }
+
+ if (st->idchan == 0)
+ {
+ //st->lp_noise_float = st->hFdCngDec->lp_noise_float;
+ st->lp_noise = st->hFdCngDec->lp_noise;
+ move32();
+ }
+
+ if (st->element_mode != IVAS_CPE_TD && !st->cng_ism_flag)
+ {
+ /*Noise estimate*/
+#ifdef IVAS_FLOAT_FIXED
+ //Word16 syn_fx[L_FRAME16k + L_SUBFR] = { 0 };
+ /*st->Q_syn = 0;
+ for ( int p = 0; p < L_FRAME16k; p++ )
+ {
+ syn_fx[L_SUBFR + p] = (Word16) ( syn[p] * ( 1u << st->Q_syn ) );
+ }*/
+ /*for (int p = 0; p < L_FRAME16k; p++)
+ {
+ psyn_fx[p] = (Word16)(syn[p] * (1u << st->Q_syn));
+ }*/
+ //for (int p = 0; p < st->L_frame; p++)
+ //{
+ // st->hFdCngDec->hFdCngCom->periodog[p] = (Word32)(st->hFdCngDec->hFdCngCom->periodog_flt[p] * (1u << (31 - st->hFdCngDec->hFdCngCom->periodog_exp)));
+ //}
+ //st->hFdCngDec->hFdCngCom->fftBuffer_exp = 31 - Q4;
+ //for (int p = 0; p < st->hFdCngDec->hFdCngCom->fftlen; p++)
+ //{
+ // st->hFdCngDec->hFdCngCom->fftBuffer[p] = (Word32)(st->hFdCngDec->hFdCngCom->fftBuffer_flt[p] * (1u << (31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp)));
+ //}
+ //st->hFdCngDec->msNoiseEst_exp = 31 - Q4; // Q4
+ //for (int p = 0; p < st->hFdCngDec->npart_shaping; p++)
+ //{
+ // st->hFdCngDec->msNoiseEst[p] = (Word32)(st->hFdCngDec->msNoiseEst_float[p] * (1u << (31 - st->hFdCngDec->msNoiseEst_exp)));
+ // st->hFdCngDec->msPeriodog[p] = (Word32)(st->hFdCngDec->msPeriodog_float[p] * (1u << (31 - st->hFdCngDec->msPeriodog_exp)));
+ // st->hFdCngDec->msPeriodog_ST_fx[p] = (Word32)(st->hFdCngDec->msPeriodog_ST[p] * (1u << (31 - st->hFdCngDec->msPeriodog_ST_exp)));
+ //}
+ //st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - Q4; // Q4
+ //for (int p = 0; p < FFTCLDFBLEN; p++)
+ //{
+ // st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] = (Word32)(st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] * (1u << (31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp)));
+ //}
+ //st->hFdCngDec->partNoiseShape_exp = 31 - Q4; // Q4
+ //floatToFixed_arrL(st->hFdCngDec->partNoiseShape_float, st->hFdCngDec->partNoiseShape, Q31 - st->hFdCngDec->partNoiseShape_exp, NPART);
+ //Scale_sig(syn_tmp_fx, L_FRAME16k + L_SUBFR, 0 - st->Q_syn); //Q0
+
+ /*==========================================================*/
+ //ApplyFdCng_fx( syn_fx + L_SUBFR, st->Q_syn, NULL, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) );
+ ApplyFdCng_fx(psyn_fx, st->Q_syn, NULL, realBuffer_fx, imagBuffer_fx, NULL, st, 0, (st->coder_type_fx == AUDIO && !st->GSC_noisy_speech_fx));
+ /*==========================================================*/
+ if (st->hFdCngDec->partNoiseShape_exp < 0) {
+ Scale_sig32(st->hFdCngDec->partNoiseShape, NPART, st->hFdCngDec->partNoiseShape_exp);
+ st->hFdCngDec->partNoiseShape_exp = 0;
+ }
+ if (st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0) {
+ Scale_sig32(st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp);
+ st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0;
+ }
+ //Scale_sig(syn_tmp_fx, L_FRAME16k + L_SUBFR, st->Q_syn); //Q_syn
+ //fixedToFloat_arrL(st->hFdCngDec->partNoiseShape, st->hFdCngDec->partNoiseShape_float, Q31 - st->hFdCngDec->partNoiseShape_exp, NPART);
+
+ //if (((st->m_frame_type == ACTIVE_FRAME) && ((st->bfi == 0 &&
+ // (psyn_fx == NULL ||
+ // (*psyn_fx(-FLT_MAX) &&
+ // *(psyn_fx + st->hFdCngDec->hFdCngCom->frameSize - 1) < FLT_MAX &&
+ // *(psyn_fx + st->hFdCngDec->hFdCngCom->frameSize - 1) > (-FLT_MAX))) &&
+ // ((((st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT && st->hFdCngDec->flag_dtx_mode) || !st->VAD || (st->ini_frame < 100 && st->is_ism_format)) &&
+ // !(st->cng_type == LP_CNG && st->hFdCngDec->flag_dtx_mode)) ||
+ // (st->element_mode == IVAS_CPE_TD)) &&
+ // (!st->BER_detect)) ||
+ // ((st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT) && (st->hFdCngDec->hFdCngCom->active_frame_counter > 0)) || ((st->bfi == 1) && (st->nbLostCmpt == 1)))) ||
+ // (st->m_frame_type == ZERO_FRAME) && (st != NULL && st->cng_type == LP_CNG))
+ //{
+ // {
+ // for (int p = 0; p < st->hFdCngDec->hFdCngCom->fftlen; p++)
+ // {
+ // st->hFdCngDec->hFdCngCom->fftBuffer_flt[p] = ((float)st->hFdCngDec->hFdCngCom->fftBuffer[p] / (1u << (31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp)));
+ // }
+
+ // for (int p = 0; p < (st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand); p++)
+ // {
+ // st->hFdCngDec->bandNoiseShape_float[p] = ((float)st->hFdCngDec->bandNoiseShape[p] / (1u << (31 - st->hFdCngDec->bandNoiseShape_exp)));
+ // }
+ // for (int p = 0; p < st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand; p++)
+ // {
+ // st->hFdCngDec->hFdCngCom->periodog_flt[p] = ((float)st->hFdCngDec->hFdCngCom->periodog[p] / (float)(1u << (31 - st->hFdCngDec->hFdCngCom->periodog_exp)));
+ // }
+ // for (int p = 0; p < st->hFdCngDec->npart_shaping; p++)
+ // {
+ // st->hFdCngDec->msPsd_float[p] = ((float)st->hFdCngDec->msPsd_fx[p] / (1u << (31 - st->hFdCngDec->msPsd_exp_fft)));
+ // st->hFdCngDec->msNoiseEst_float[p] = (float)st->hFdCngDec->msNoiseEst[p] / (1u << (31 - st->hFdCngDec->msNoiseEst_exp));
+ // st->hFdCngDec->msPeriodog_float[p] = ((float)st->hFdCngDec->msPeriodog[p] / (1u << (31 - st->hFdCngDec->msPeriodog_exp)));
+ // st->hFdCngDec->msPeriodog_ST[p] = ((float)st->hFdCngDec->msPeriodog_ST_fx[p] / (1u << (31 - st->hFdCngDec->msPeriodog_ST_exp)));
+ // }
+ // if (st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT)
+ // {
+ // for (int p = 0; p < L_FRAME16k - st->hFdCngDec->hFdCngCom->startBand; p++)
+ // {
+ // st->hFdCngDec->smoothed_psd[st->hFdCngDec->hFdCngCom->startBand + p] = ((float)st->hFdCngDec->smoothed_psd_fx[st->hFdCngDec->hFdCngCom->startBand + p] / (1u << (31 - st->hFdCngDec->msNoiseEst_exp)));
+ // }
+ // }
+ // }
+ // if (!((st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT) && (st->hFdCngDec->hFdCngCom->active_frame_counter > 0)))
+ // {
+ // st->hTcxDec->CngLevelBackgroundTrace_bfi = fix_to_float(st->hTcxDec->CngLevelBackgroundTrace_bfi_fx, (31 - st->hTcxDec->CngLevelBackgroundTrace_bfi_exp));
+ // st->cngTDLevel_float = fixedToFloat(st->cngTDLevel, (15 - st->cngTDLevel_e));
+ // for (int p = 0; p < (st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand); p++)
+ // {
+ // st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ((float)st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] / (1u << (31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp)));
+ // }
+ // IF(!(EQ_16(st->element_mode, IVAS_CPE_TD) || EQ_16(st->element_mode, IVAS_CPE_DFT)))
+ // {
+ // for (int p = 0; p < MSNUMSUBFR * NPART_SHAPING; p++)
+ // {
+ // if ((st->hFdCngDec->msMinBuf[p] == MAX_32))
+ // {
+ // st->hFdCngDec->msMinBuf_float[p] = FLT_MAX;
+ // }
+ // else
+ // {
+ // st->hFdCngDec->msMinBuf_float[p] = (float)st->hFdCngDec->msMinBuf[p] / (1u << (31 - 6)); // CNG_S = 6
+ // }
+ // }
+ // for (int p = 0; p < st->hFdCngDec->npart_shaping; p++)
+ // {
+ // st->hFdCngDec->msPeriodogBuf_float[p] = ((float)st->hFdCngDec->msPeriodogBuf[p] / (1u << Q9));
+ // st->hFdCngDec->msPsdFirstMoment_float[p] = ((float)st->hFdCngDec->msPsdFirstMoment[p] / (1u << Q9));
+ // st->hFdCngDec->msPsdSecondMoment_float[p] = ((float)st->hFdCngDec->msPsdSecondMoment[p] / (1u << Q19));
+ // st->hFdCngDec->msNoiseFloor_float[p] = ((float)st->hFdCngDec->msNoiseFloor[p] / (1u << Q9));
+ // st->hFdCngDec->msAlpha_float[p] = ((float)st->hFdCngDec->msAlpha[p] / (1u << Q31));
+ // st->hFdCngDec->msBminWin_float[p] = ((float)st->hFdCngDec->msBminWin[p] / (1u << Q27));
+ // st->hFdCngDec->msBminSubWin_float[p] = ((float)st->hFdCngDec->msBminSubWin[p] / (1u << Q27));
+ // if (st->hFdCngDec->msCurrentMin[p] == MAX_32)
+ // {
+ // st->hFdCngDec->msCurrentMin_float[p] = FLT_MAX;
+ // }
+ // else
+ // {
+ // st->hFdCngDec->msCurrentMin_float[p] = ((float)st->hFdCngDec->msCurrentMin[p] / (1u << (31 - (6 + 1 + 4)))); // exp : CNG_S + 1 + 4
+ // }
+ // if (st->hFdCngDec->msCurrentMinOut[p] == MAX_32)
+ // {
+ // st->hFdCngDec->msCurrentMinOut_float[p] = FLT_MAX;
+ // }
+ // else
+ // {
+ // st->hFdCngDec->msCurrentMinOut_float[p] = ((float)st->hFdCngDec->msCurrentMinOut[p] / (1u << (31 - 6)));
+ // }
+ // if (st->hFdCngDec->msCurrentMinSubWindow[p] == MAX_32)
+ // {
+ // st->hFdCngDec->msCurrentMinSubWindow_float[p] = FLT_MAX;
+ // }
+ // else
+ // {
+ // st->hFdCngDec->msCurrentMinSubWindow_float[p] = ((float)st->hFdCngDec->msCurrentMinSubWindow[p] / (1u << (31 - 6)));
+ // }
+ // }
+ // }
+ // if ( sum_f( st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt + st->hFdCngDec->hFdCngCom->startBand, st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ) > 0.01f )
+ // {
+ // if ( st->element_mode != IVAS_CPE_MDCT || st->core == ACELP_CORE )
+ // {
+ // int A_cng_q = 15 - norm_s( st->hFdCngDec->hFdCngCom->A_cng[0] );
+ // for ( int p = 0; p < M; p++ )
+ // {
+ // st->hFdCngDec->hFdCngCom->A_cng_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->A_cng[p] / ( 1u << A_cng_q ) );
+ // st->lspold_cng_float[p] = ( (float) st->lspold_cng[p] / ( 1u << Q15 ) );
+ // }
+ // }
+ // }
+ // }
+ //}
+#else
+ ApplyFdCng_flt(syn, NULL, realBuffer, imagBuffer, st, 0, (st->coder_type == AUDIO && !st->GSC_noisy_speech));
+#endif // IVAS_FLOAT_FIXED
+ }
+
+ if (!st->cna_dirac_flag)
+ {
+ /* CNA: Generate additional comfort noise to mask potential coding artefacts */
+ if (st->flag_cna && !(st->coder_type_fx == AUDIO && !(st->element_mode > EVS_MONO && st->GSC_noisy_speech_fx)))
+ {
+ if (st->element_mode == IVAS_CPE_TD && nchan_out == 2)
+ {
+ if (hStereoCng->flag_cna_fade)
+ {
+#ifndef IVAS_FLOAT_FIXED
+ generate_stereo_masking_noise(syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out);
+#else
+ //generate_stereo_masking_noise_fx(syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out);
+ generate_stereo_masking_noise_16fx(psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out);
+#endif
+ hStereoCng->flag_cna_fade = 0;
+ }
+ else
+ {
+ if (st->element_mode != last_element_mode && st->idchan == 0)
+ {
+ /* Clear memory for secondary channel CNA */
+ //set_f(hStereoCng->olapBufferSynth22, 0.0f, st->hFdCngDec->hFdCngCom->frameSize / 2);
+ set_s(hStereoCng->olapBufferSynth22_fx, 0, st->hFdCngDec->hFdCngCom->frameSize / 2);
+ }
+
+#ifndef IVAS_FLOAT_FIXED
+ generate_stereo_masking_noise(syn, st, hStereoTD, flag_sec_CNA, 0, hStereoCng, nchan_out);
+#else
+ //generate_stereo_masking_noise_fx(syn, st, hStereoTD, flag_sec_CNA, 0, hStereoCng, nchan_out);
+ generate_stereo_masking_noise_16fx(psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 0, hStereoCng, nchan_out);
+#endif
+ }
+ }
+ else if (st->element_mode != IVAS_CPE_DFT)
+ {
+ if (st->idchan == 0)
+ {
+ if (st->element_mode != last_element_mode)
+ {
+ //set_f(st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, 0.0f, st->hFdCngDec->hFdCngCom->fftlen);
+ set_s(st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen);
+ }
+ //generate_masking_noise_flt(syn, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0, 0, 0, st->element_mode, hStereoCng, nchan_out);
+ generate_masking_noise(psyn_fx, st->Q_syn, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0/*, 0, 0, st->element_mode, hStereoCng, nchan_out*/);
+ }
+ }
+ }
+ else if (st->flag_cna && st->coder_type_fx == AUDIO && ((st->last_core == ACELP_CORE && !(st->last_coder_type_fx == AUDIO && !(st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag_fx))) || st->last_core == TCX_20_CORE))
+ {
+ if (st->element_mode == IVAS_CPE_TD && nchan_out == 2)
+ {
+#ifndef IVAS_FLOAT_FIXED
+ generate_stereo_masking_noise(syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out);
+#else
+ //generate_stereo_masking_noise_fx(syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out);
+ generate_stereo_masking_noise_16fx(psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out);
+#endif
+ hStereoCng->flag_cna_fade = 1;
+ }
+ else
+ {
+ //v_multc(st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt + 5 * st->hFdCngDec->hFdCngCom->frameSize / 4, (float)(st->hFdCngDec->hFdCngCom->fftlen / 2), temp_buf, st->hFdCngDec->hFdCngCom->frameSize / 2);
+ //v_add(temp_buf, syn, syn, st->hFdCngDec->hFdCngCom->frameSize / 2);
+ FOR(i = 0; i < st->hFdCngDec->hFdCngCom->frameSize / 2; i++)
+ {
+ psyn_fx[i] = add(psyn_fx[i], shr_r(mult_r(st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st->hFdCngDec->hFdCngCom->frameSize / 4], st->hFdCngDec->hFdCngCom->fftlenFac), -st->Q_syn));
+ move16();
+ }
+ }
+ }
+ else
+ {
+ if (hStereoCng != NULL)
+ {
+ hStereoCng->flag_cna_fade = 1;
+ hStereoCng->enableSecCNA = 0;
+ }
+ }
+
+ if (st->element_mode == IVAS_CPE_TD)
+ {
+ /*Noise estimate*/
+ if (st->idchan == 0 && (nchan_out == 2 || (st->core_brate != FRAME_NO_DATA && st->core_brate != SID_2k40)))
+ {
+#ifdef IVAS_FLOAT_FIXED
+ //Word16 syn_fx[L_FRAME16k + L_SUBFR] = { 0 };
+ //st->Q_syn = 0;
+ //for (int p = 0; p < L_FRAME16k; p++)
+ //{
+ // psyn_fx[p] = (Word16)(syn[p] * (1u << st->Q_syn));
+ //}
+ //for (int p = 0; p < st->L_frame; p++)
+ //{
+ // st->hFdCngDec->hFdCngCom->periodog[p] = (Word32)(st->hFdCngDec->hFdCngCom->periodog_flt[p] * (1u << (31 - st->hFdCngDec->hFdCngCom->periodog_exp)));
+ //}
+ //st->hFdCngDec->hFdCngCom->fftBuffer_exp = 31 - Q4;
+ //for (int p = 0; p < st->hFdCngDec->hFdCngCom->fftlen; p++)
+ //{
+ // st->hFdCngDec->hFdCngCom->fftBuffer[p] = (Word32)(st->hFdCngDec->hFdCngCom->fftBuffer_flt[p] * (1u << (31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp)));
+ //}
+ //st->hFdCngDec->msNoiseEst_exp = 31 - Q4;
+ //for (int p = 0; p < st->hFdCngDec->npart_shaping; p++)
+ //{
+ // st->hFdCngDec->msNoiseEst[p] = (Word32)(st->hFdCngDec->msNoiseEst_float[p] * (1u << (31 - st->hFdCngDec->msNoiseEst_exp)));
+ // st->hFdCngDec->msPeriodog[p] = (Word32)(st->hFdCngDec->msPeriodog_float[p] * (1u << (31 - st->hFdCngDec->msPeriodog_exp)));
+ // st->hFdCngDec->msPeriodog_ST_fx[p] = (Word32)(st->hFdCngDec->msPeriodog_ST[p] * (1u << (31 - st->hFdCngDec->msPeriodog_ST_exp)));
+ //}
+ //st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - Q4;
+ //for (int p = 0; p < FFTCLDFBLEN; p++)
+ //{
+ // st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] = (Word32)(st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] * (1u << (31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp)));
+ //}
+ //st->hFdCngDec->partNoiseShape_exp = 31 - Q4; // Q4
+ //floatToFixed_arrL(st->hFdCngDec->partNoiseShape_float, st->hFdCngDec->partNoiseShape, Q31 - st->hFdCngDec->partNoiseShape_exp, NPART);
+
+ ApplyFdCng_fx(psyn_fx, st->Q_syn, NULL, realBuffer_fx, imagBuffer_fx, NULL, st, 0, (st->coder_type_fx == AUDIO && !st->GSC_noisy_speech_fx));
+ if (st->hFdCngDec->partNoiseShape_exp < 0) {
+ Scale_sig32(st->hFdCngDec->partNoiseShape, NPART, -st->hFdCngDec->partNoiseShape_exp);
+ st->hFdCngDec->partNoiseShape_exp = 0;
+ }
+ if (st->hFdCngDec->partNoiseShape_exp < 0) {
+ Scale_sig32(st->hFdCngDec->partNoiseShape, NPART, st->hFdCngDec->partNoiseShape_exp);
+ st->hFdCngDec->partNoiseShape_exp = 0;
+ }
+ if (st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0) {
+ Scale_sig32(st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp);
+ st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0;
+ }
+ //fixedToFloat_arrL(st->hFdCngDec->partNoiseShape, st->hFdCngDec->partNoiseShape_float, Q31 - st->hFdCngDec->partNoiseShape_exp, NPART);
+
+ //if (((st->m_frame_type == ACTIVE_FRAME) && ((st->bfi == 0 &&
+ // (psyn_fx == NULL ||
+ // (*psyn_fx(-FLT_MAX) &&
+ // *(psyn_fx + st->hFdCngDec->hFdCngCom->frameSize - 1) < FLT_MAX &&
+ // *(psyn_fx + st->hFdCngDec->hFdCngCom->frameSize - 1) > (-FLT_MAX))) &&
+ // ((((st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT && st->hFdCngDec->flag_dtx_mode) || !st->VAD || (st->ini_frame < 100 && st->is_ism_format)) &&
+ // !(st->cng_type == LP_CNG && st->hFdCngDec->flag_dtx_mode)) ||
+ // (st->element_mode == IVAS_CPE_TD)) &&
+ // (!st->BER_detect)) ||
+ // ((st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT) && (st->hFdCngDec->hFdCngCom->active_frame_counter > 0)) || ((st->bfi == 1) && (st->nbLostCmpt == 1)))) ||
+ // (st->m_frame_type == ZERO_FRAME) && (st != NULL && st->cng_type == LP_CNG))
+ //{
+ // {
+ // for (int p = 0; p < st->hFdCngDec->hFdCngCom->fftlen; p++)
+ // {
+ // st->hFdCngDec->hFdCngCom->fftBuffer_flt[p] = ((float)st->hFdCngDec->hFdCngCom->fftBuffer[p] / (1u << (31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp)));
+ // }
+
+ // for (int p = 0; p < (st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand); p++)
+ // {
+ // st->hFdCngDec->bandNoiseShape_float[p] = ((float)st->hFdCngDec->bandNoiseShape[p] / (1u << (31 - st->hFdCngDec->bandNoiseShape_exp)));
+ // }
+ // for (int p = 0; p < st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand; p++)
+ // {
+ // st->hFdCngDec->hFdCngCom->periodog_flt[p] = ((float)st->hFdCngDec->hFdCngCom->periodog[p] / (float)(1u << (31 - st->hFdCngDec->hFdCngCom->periodog_exp)));
+ // }
+ // for (int p = 0; p < st->hFdCngDec->npart_shaping; p++)
+ // {
+ // st->hFdCngDec->msPsd_float[p] = ((float)st->hFdCngDec->msPsd_fx[p] / (1u << (31 - st->hFdCngDec->msPsd_exp_fft)));
+ // st->hFdCngDec->msNoiseEst_float[p] = (float)st->hFdCngDec->msNoiseEst[p] / (1u << (31 - st->hFdCngDec->msNoiseEst_exp));
+ // st->hFdCngDec->msPeriodog_float[p] = ((float)st->hFdCngDec->msPeriodog[p] / (1u << (31 - st->hFdCngDec->msPeriodog_exp)));
+ // st->hFdCngDec->msPeriodog_ST[p] = ((float)st->hFdCngDec->msPeriodog_ST_fx[p] / (1u << (31 - st->hFdCngDec->msPeriodog_ST_exp)));
+ // }
+ // if (st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT)
+ // {
+ // for (int p = 0; p < L_FRAME16k - st->hFdCngDec->hFdCngCom->startBand; p++)
+ // {
+ // st->hFdCngDec->smoothed_psd[st->hFdCngDec->hFdCngCom->startBand + p] = ((float)st->hFdCngDec->smoothed_psd_fx[st->hFdCngDec->hFdCngCom->startBand + p] / (1u << (31 - st->hFdCngDec->msNoiseEst_exp)));
+ // }
+ // }
+ // }
+ // if (!((st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT) && (st->hFdCngDec->hFdCngCom->active_frame_counter > 0)))
+ // {
+ // st->hTcxDec->CngLevelBackgroundTrace_bfi = fix_to_float(st->hTcxDec->CngLevelBackgroundTrace_bfi_fx, (31 - st->hTcxDec->CngLevelBackgroundTrace_bfi_exp));
+ // st->cngTDLevel_float = fixedToFloat(st->cngTDLevel, (15 - st->cngTDLevel_e));
+ // for (int p = 0; p < (st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand); p++)
+ // {
+ // st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ((float)st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] / (1u << (31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp)));
+ // }
+ // IF(!(EQ_16(st->element_mode, IVAS_CPE_TD) || EQ_16(st->element_mode, IVAS_CPE_DFT)))
+ // {
+ // for (int p = 0; p < MSNUMSUBFR * NPART_SHAPING; p++)
+ // {
+ // if ((st->hFdCngDec->msMinBuf[p] == MAX_32))
+ // {
+ // st->hFdCngDec->msMinBuf_float[p] = FLT_MAX;
+ // }
+ // else
+ // {
+ // st->hFdCngDec->msMinBuf_float[p] = (float)st->hFdCngDec->msMinBuf[p] / (1u << (31 - 6)); // CNG_S = 6
+ // }
+ // }
+ // for (int p = 0; p < st->hFdCngDec->npart_shaping; p++)
+ // {
+ // st->hFdCngDec->msPeriodogBuf_float[p] = ((float)st->hFdCngDec->msPeriodogBuf[p] / (1u << Q9));
+ // st->hFdCngDec->msPsdFirstMoment_float[p] = ((float)st->hFdCngDec->msPsdFirstMoment[p] / (1u << Q9));
+ // st->hFdCngDec->msPsdSecondMoment_float[p] = ((float)st->hFdCngDec->msPsdSecondMoment[p] / (1u << Q19));
+ // st->hFdCngDec->msNoiseFloor_float[p] = ((float)st->hFdCngDec->msNoiseFloor[p] / (1u << Q9));
+ // st->hFdCngDec->msAlpha_float[p] = ((float)st->hFdCngDec->msAlpha[p] / (1u << Q31));
+ // st->hFdCngDec->msBminWin_float[p] = ((float)st->hFdCngDec->msBminWin[p] / (1u << Q27));
+ // st->hFdCngDec->msBminSubWin_float[p] = ((float)st->hFdCngDec->msBminSubWin[p] / (1u << Q27));
+ // if (st->hFdCngDec->msCurrentMin[p] == MAX_32)
+ // {
+ // st->hFdCngDec->msCurrentMin_float[p] = FLT_MAX;
+ // }
+ // else
+ // {
+ // st->hFdCngDec->msCurrentMin_float[p] = ((float)st->hFdCngDec->msCurrentMin[p] / (1u << (31 - (6 + 1 + 4)))); // exp : CNG_S + 1 + 4
+ // }
+ // if (st->hFdCngDec->msCurrentMinOut[p] == MAX_32)
+ // {
+ // st->hFdCngDec->msCurrentMinOut_float[p] = FLT_MAX;
+ // }
+ // else
+ // {
+ // st->hFdCngDec->msCurrentMinOut_float[p] = ((float)st->hFdCngDec->msCurrentMinOut[p] / (1u << (31 - 6)));
+ // }
+ // if (st->hFdCngDec->msCurrentMinSubWindow[p] == MAX_32)
+ // {
+ // st->hFdCngDec->msCurrentMinSubWindow_float[p] = FLT_MAX;
+ // }
+ // else
+ // {
+ // st->hFdCngDec->msCurrentMinSubWindow_float[p] = ((float)st->hFdCngDec->msCurrentMinSubWindow[p] / (1u << (31 - 6)));
+ // }
+ // }
+ // }
+ // if (sum_f(st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt + st->hFdCngDec->hFdCngCom->startBand, st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand) > 0.01f)
+ // {
+ // if (st->element_mode != IVAS_CPE_MDCT || st->core == ACELP_CORE)
+ // {
+ // int A_cng_q = 15 - norm_s(st->hFdCngDec->hFdCngCom->A_cng[0]);
+ // for (int p = 0; p < M; p++)
+ // {
+ // st->hFdCngDec->hFdCngCom->A_cng_flt[p] = ((float)st->hFdCngDec->hFdCngCom->A_cng[p] / (1u << A_cng_q));
+ // st->lspold_cng_float[p] = ((float)st->lspold_cng[p] / (1u << Q15));
+ // }
+ // }
+ // }
+ // }
+ //}
+#else
+ ApplyFdCng_flt(syn, NULL, realBuffer, imagBuffer, st, 0, (st->coder_type == AUDIO && !st->GSC_noisy_speech));
+#endif // IVAS_FLOAT_FIXED
+ }
+ }
+ }
+ }
+
+ if (!st->cna_dirac_flag)
+ {
+ if (st->flag_cna == 0 && st->L_frame == L_FRAME16k && st->last_flag_cna == 1 && ((st->last_core == ACELP_CORE && !(st->last_coder_type_fx == AUDIO && !(st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag_fx))) || st->last_core == AMR_WB_CORE))
+ {
+ //v_multc(st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt + 5 * st->L_frame / 4, 256.f, temp_buf, st->L_frame / 2);
+ //v_add(temp_buf, syn, syn, st->L_frame / 2);
+ FOR(i = 0; i < st->hFdCngDec->hFdCngCom->frameSize / 2; i++)
+ {
+ psyn_fx[i] = add(psyn_fx[i], shr_r(mult_r(st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st->hFdCngDec->hFdCngCom->frameSize / 4], st->hFdCngDec->hFdCngCom->fftlenFac), -st->Q_syn));
+ move16();
+ }
+ }
+
+ if (st->flag_cna == 0 || (st->coder_type_fx == AUDIO && !(st->element_mode > EVS_MONO && st->GSC_noisy_speech_fx)))
+ {
+ if (st->idchan == 0)
+ {
+ //set_f(st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, 0.f, st->hFdCngDec->hFdCngCom->fftlen);
+ set_s(st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen);
+ }
+ if (hStereoCng != NULL && st->idchan == 0)
+ {
+ //set_f(hStereoCng->olapBufferSynth22, 0.f, st->hFdCngDec->hFdCngCom->fftlen);
+ set_s(hStereoCng->olapBufferSynth22_fx, 0, st->hFdCngDec->hFdCngCom->fftlen);
+ }
+ }
+ }
+ }
+
+ /*----------------------------------------------------------------*
+ * Resample to the output sampling rate (8/16/32/48 kHz)
+ * Bass post-filter
+ *----------------------------------------------------------------*/
+
+ /* check if the CLDFB works on the right sample rate */
+ if ((st->cldfbAna->no_channels * st->cldfbAna->no_col) != st->L_frame)
+ {
+#ifdef IVAS_FLOAT_FIXED
+ /*Word16 old_len_ana, old_len_bpf;
+ Word16 new_len;*/
+
+ // The following lines are to calculate the length of the buffers before and
+ // after calling the function for fixed pt conversion. The calculations are taken
+ // based on the logic used in resampleCldfb_ivas_fx
+ //old_len_ana = st->cldfbAna->p_filter_length - st->cldfbAna->no_channels;
+ //old_len_bpf = st->cldfbBPF->p_filter_length - st->cldfbBPF->no_channels;
+ //new_len = 9 * (int16_t)(st->L_frame * FRAMES_PER_SEC * INV_CLDFB_BANDWIDTH + 0.5f);
+
+ //floatToFixed_arrL(st->cldfbAna->cldfb_state, st->cldfbAna->cldfb_state_fx, Q11, old_len_ana);
+ //floatToFixed_arrL(st->cldfbBPF->cldfb_state, st->cldfbBPF->cldfb_state_fx, Q10, old_len_bpf);
+
+ resampleCldfb_ivas_fx(st->cldfbAna, st->L_frame * FRAMES_PER_SEC);
+ resampleCldfb_ivas_fx(st->cldfbBPF, st->L_frame * FRAMES_PER_SEC);
+
+ /*fixedToFloat_arrL(st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_state, Q11, new_len);
+ fixedToFloat_arrL(st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_state, Q10, new_len);*/
+#else
+ resampleCldfb_ivas(st->cldfbAna, st->L_frame * FRAMES_PER_SEC);
+ resampleCldfb_ivas(st->cldfbBPF, st->L_frame * FRAMES_PER_SEC);
+#endif
+
+ if (st->ini_frame > 0)
+ {
+ st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels - st->cldfbAna->no_channels;
+ }
+ }
+
+ /* analyze pitch coherence for bass post-filter */
+
+#ifdef IVAS_FLOAT_FIXED
+
+ Word32 pitch_buf_fx_q20[12];
+
+ /*FOR(Word16 lp = 0; lp < 12; lp++)
+ {
+ st->old_pitch_buf_fx[lp] = (Word32)(st->old_pitch_buf[lp] * (1u << 20));
+ }*/
+ Scale_sig32(st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, Q4);
+ Word16 lim = st->L_frame / 64;
+ for (Word16 lp = 0; lp < lim; lp++)
+ {
+ //pitch_buf_fx[lp] = (Word32)(pitch_buf[lp] * (1u << 20));
+ pitch_buf_fx_q20[lp] = L_shl(pitch_buf_out_fx[lp], Q14);
+
+ }
+ bpf_pitch_coherence_fx(st, pitch_buf_fx_q20);
+ Scale_sig32(st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, -Q4);
+
+#else
+ bpf_pitch_coherence(st, pitch_buf);
+#endif
+
+ if (!(st->element_mode == IVAS_CPE_MDCT && st->bpf_off))
+ {
+#ifdef IVAS_FLOAT_FIXED
+ ///////////////////////////////////////////////////////////////////////////////
+ //Word16 pst_old_syn_exp;
+ //Word16 tmp_syn_exp;
+ //Word16 tmp_syn_fx[1]; // temporary. just one element because retro_interp4_5 only accesses syn[0]
+
+ //// Get exponents.
+ //f2me_buf_16(st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_fx, &pst_old_syn_exp, NBPSF_PIT_MAX);
+ //f2me_16(syn[0], &tmp_syn_fx[0], &tmp_syn_exp);
+ //tmp_syn_exp = s_max(tmp_syn_exp, pst_old_syn_exp); // max exp btween syn and pst_old_syn
+
+ //// Float to fix
+ //for (i = 0; i < NBPSF_PIT_MAX; i++)
+ //{
+ // st->hBPF->pst_old_syn_fx[i] = (Word16)(st->hBPF->pst_old_syn[i] * pow(2, 15 - tmp_syn_exp));
+ //}
+ //tmp_syn_fx[0] = (Word16)(syn[0] * pow(2, 15 - tmp_syn_exp));
+ ///////////////////////////////////////////////////////////////////////////////
+
+ //test();
+ //IF(NE_16(st->L_frame, st->last_L_frame) && NE_16(st->last_codec_mode, MODE2))
+ //{
+ // IF(EQ_16(st->L_frame, L_FRAME))
+ // {
+ // retro_interp5_4_fx(st->hBPF->pst_old_syn_fx);
+ // }
+ // ELSE IF(EQ_16(st->L_frame, L_FRAME16k))
+ // {
+ // retro_interp4_5_fx(tmp_syn_fx, st->hBPF->pst_old_syn_fx);
+ // }
+ //}
+
+ //// Fixed to float
+ //me2f_buf_16(st->hBPF->pst_old_syn_fx, tmp_syn_exp, st->hBPF->pst_old_syn, NBPSF_PIT_MAX);
+#else
+ if (st->L_frame != st->last_L_frame && st->last_codec_mode != MODE2)
+ {
+ if (st->L_frame == L_FRAME)
+ {
+ retro_interp5_4(st->hBPF->pst_old_syn);
+ }
+ else if (st->L_frame == L_FRAME16k)
+ {
+ retro_interp4_5(syn, st->hBPF->pst_old_syn);
+ }
+ }
+#endif
+ /* bass post-filter */
+#ifdef IVAS_FLOAT_FIXED
+ //Word16 tmp_syn_fx2[L_FRAME16k + L_SUBFR];
+ //Word16 tmp_Q_syn;
+ //Word16 tmp_pitch_buf_fx[NB_SUBFR16k];
+
+ //// Float to fixed
+ //tmp_Q_syn = -1; // Q0 + one guard bit = Q(-1)
+ //st->stab_fac_fx = float_to_fix16(st->stab_fac, Q15);
+ //st->stab_fac_smooth_fx = float_to_fix16(st->stab_fac_smooth, Q15);
+ //st->hBPF->pst_mem_deemp_err_fx = (Word16)floatToFixed(st->hBPF->pst_mem_deemp_err, tmp_Q_syn);
+ //st->hBPF->pst_lp_ener_fx = float_to_fix16(st->hBPF->pst_lp_ener, Q8);
+ //st->hBPF->psf_att_fx = float_to_fix16(st->hBPF->psf_att, Q15);
+ //for (i = 0; i < st->L_frame; i++)
+ //{
+ // tmp_syn_fx2[i] = (Word16)floatToFixed(syn[i], tmp_Q_syn);
+ //}
+ //for (i = 0; i < NBPSF_PIT_MAX; i++)
+ //{
+ // st->hBPF->pst_old_syn_fx[i] = (Word16)floatToFixed(st->hBPF->pst_old_syn[i], tmp_Q_syn);
+ //}
+ //for (i = 0; i < NB_SUBFR16k; i++)
+ //{
+ // tmp_pitch_buf_fx[i] = (Word16)floatToFixed(pitch_buf[i], Q6);
+ //}
+ //for (i = 0; i < L_TRACK_HIST; i++)
+ //{
+ // st->hBPF->mem_mean_pit_fx[i] = float_to_fix16(st->hBPF->mem_mean_pit[i], 0);
+ // st->hBPF->Track_on_hist_fx[i] = st->hBPF->Track_on_hist[i];
+ // st->hBPF->vibrato_hist_fx[i] = st->hBPF->vibrato_hist[i];
+ //}
+
+ //Word16 bpf_error_signal_fx_temp[L_FRAME16k];
+ //for (i = 0; i < L_FRAME16k; i++)
+ //{
+ // bpf_error_signal_fx_temp[i] = extract_h(bpf_error_signal_fx[i]);
+ //}
+
+ //bass_psfilter_fx(st->hBPF,
+ // st->Opt_AMR_WB,
+ // tmp_syn_fx2,
+ // st->L_frame,
+ // tmp_pitch_buf_fx, // Q6
+ // st->bpf_off,
+ // st->stab_fac_fx, // Q15
+ // &st->stab_fac_smooth_fx, // Q15
+ // st->coder_type,
+ // tmp_Q_syn,
+ // bpf_error_signal_fx_temp);
+
+ //for (i = 0; i < L_FRAME16k; i++)
+ //{
+ // bpf_error_signal_fx[i] = L_deposit_h(bpf_error_signal_fx_temp[i]);
+ //}
+
+ //// Fixed to float
+ //st->hBPF->pst_lp_ener = fix16_to_float(st->hBPF->pst_lp_ener_fx, Q8);
+ //st->stab_fac_smooth = fix16_to_float(st->stab_fac_smooth_fx, Q15);
+ //st->hBPF->mem_mean_pit[0] = fix16_to_float(st->hBPF->mem_mean_pit_fx[0], Q4);
+ //st->hBPF->psf_att = fix16_to_float(st->hBPF->psf_att_fx, Q15);
+ //for (i = 0; i < NBPSF_PIT_MAX; i++)
+ //{
+ // st->hBPF->pst_old_syn[i] = fixedToFloat(st->hBPF->pst_old_syn_fx[i], tmp_Q_syn);
+ //}
+ //for (i = 0; i < L_FRAME16k; i++)
+ //{
+ // bpf_error_signal[i] = fixedToFloat(bpf_error_signal_fx[i], tmp_Q_syn + 16);
+ //}
+ //for (i = 0; i < L_TRACK_HIST; i++)
+ //{
+ // st->hBPF->Track_on_hist[i] = st->hBPF->Track_on_hist_fx[i];
+ // st->hBPF->vibrato_hist[i] = st->hBPF->vibrato_hist_fx[i];
+ //}
+#else
+ bass_psfilter(st->hBPF, st->Opt_AMR_WB, syn, st->L_frame, pitch_buf, st->bpf_off, st->stab_fac, &st->stab_fac_smooth, st->coder_type, bpf_error_signal);
+#endif
+ }
+
+
+ IF( !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->bpf_off ) )
+ {
+ test();
+ IF( NE_16( st->L_frame, st->last_L_frame ) && NE_16( st->last_codec_mode, MODE2 ) )
+ {
+ IF( EQ_16( st->L_frame, L_FRAME ) )
+ {
+ retro_interp5_4_fx( st->hBPF->pst_old_syn_fx );
+ }
+ ELSE IF( EQ_16( st->L_frame, L_FRAME16k ) )
+ {
+ retro_interp4_5_fx( psyn_fx, st->hBPF->pst_old_syn_fx );
+ }
+ }
+
+ bass_psfilter_fx( st->hBPF, st->Opt_AMR_WB, psyn_fx, st->L_frame, pitch_buf_out_fx, st->bpf_off,
+ st->stab_fac_fx, &st->stab_fac_smooth_fx, st->coder_type_fx, st->Q_syn, bpf_error_signal_16fx);
+ }
+
+ {
+ /* Lccal fix2float (To be removed) */
+ for (i = 0; i < L_FRAME16k; i++)
+ {
+ bpf_error_signal[i] = fixedToFloat(bpf_error_signal_16fx[i], st->Q_syn);
+ }
+ for (int nsf = 0; nsf < NB_SUBFR16k; nsf++)
+ {
+ fixedToFloat_arr(Aq_fx + (nsf * (M + 1)), Aq + (nsf * (M + 1)), Q14 - norm_s(Aq_fx[nsf * (M + 1)]), (M + 1));
+ }
+ /*printf("\n");
+ for (int nm = 0; nm < M + 1; nm++) {
+ printf("%f ", Aq[nm]);
+ }*/
+ // Aq_fx[0] = ONE_IN_Q12;
+ if (st->hFdCngDec)
+ {
+ st->hFdCngDec->hFdCngCom->A_cng[0] = ONE_IN_Q12;
+ }
+ for (i = 0; i < M; i++)
+ {
+ lsf_new[i] = lsf_new_fx[i] / 2.56f;
+ }
+ fixedToFloat_arr(lsp_new_fx, lsp_new, Q15, M);
+ fixedToFloat_arr(lsp_mid_fx, lsp_mid, Q15, M);
+ float *tdm_lsfQ_PCh_out = (float *)tdm_lsfQ_PCh;
+ for (int idx = 0; idx < M; idx++)
+ {
+ tdm_lsfQ_PCh_out[idx] = tdm_lsfQ_PCh_fx[idx] / 2.56f;
+ }
+ fixedToFloat_arr(tdm_lspQ_PCh_fx, (float *)tdm_lspQ_PCh, Q15, M);
+ /*printf("\n");
+ for (int nm = 0; nm < M; nm++) {
+ printf("%f ", lsf_new[nm]);
+ }*/
+ fixedToFloat_arr(old_exc_fx, old_exc, st->Q_exc, L_EXC_DEC); // exc_fx
+ fixedToFloat_arr(old_exc2_fx, old_exc2, st->Q_exc, L_FRAME16k + L_EXC_MEM); // exc2_fx
+ fixedToFloat_arr(old_bwe_exc_fx, old_bwe_exc, st->Q_exc, ((PIT16k_MAX + (L_FRAME16k + 1) + L_SUBFR16k) * 2)); // bwe_exc_fx
+ fixedToFloat_arr(syn_tmp_fx, syn_tmp, st->Q_syn, L_FRAME16k + L_SUBFR); // psyn_fx
+ // fixedToFloat_arr(syn1_tmp_fx, syn1_tmp, st->Q_syn, L_FRAME16k + 2);
+ fixedToFloat_arr(temp_buf_fx, temp_buf, -1, L_FRAME16k + L_SYN_MEM);
+ Es_pred = fixedToFloat(Es_pred_fx, Q8);
+ // enr_q = fixedToFloat(enr_q_fx, 0);
+
+ // fixedToFloat_arr(dct_exc_tmp_fx, dct_exc_tmp, st->Q_exc, L_FRAME16k);
+ // if (p_tdm_Pri_pitch_buf_fx) fixedToFloat_arr(p_tdm_Pri_pitch_buf_fx, p_tdm_Pri_pitch_buf, Q6, NB_SUBFR);
+ fixedToFloat_arr(gain_buf_fx, gain_buf, Q14, NB_SUBFR16k);
+ tmp_noise = fixedToFloat(tmp_noise_fx, 0);
+ // fixedToFloat_arr(mem_tmp_fx, mem_tmp, st->Q_syn, M);
+ fixedToFloat_arr(pitch_buf_out_fx, pitch_buf, Q6, NB_SUBFR16k);
+ fixedToFloat_arr(voice_factors_fx, voice_factors, Q15, NB_SUBFR16k);
+ fixedToFloat_arr(old_syn_12k8_16k_fx, old_syn_12k8_16k, -1, st->L_frame);
+
+ acelp_decoder_state_fix2float(st, hStereoCng);
+
+ // set_zero(Aq, NB_SUBFR16k * (M + 1));
+ set16_fx(Aq_fx, 0, NB_SUBFR16k * (M + 1));
+ // set_zero(temp_buf, L_FRAME16k + L_SYN_MEM);
+ // set_f(syn_tmp, 0, L_FRAME16k + L_SUBFR);
+ set_s(syn_tmp_fx, 0, L_FRAME16k + L_SUBFR);
+
+
+ /* Reconvert for below blocks */
+ st->Q_syn = 0;
+ floatToFixed_arr(syn_tmp, syn_tmp_fx, st->Q_syn, L_FRAME16k);
+ // tmp_noise_fx = (Word16)floatToFixed(tmp_noise, 0);
+ if (st->last_bwidth == NB && st->hPFstat != NULL)
+ {
+ floatToFixed_arr(pitch_buf, pitch_buf_tmp, Q6, NB_SUBFR16k);
+ st->psf_lp_noise_fx = (Word16)floatToFixed(st->psf_lp_noise, Q8);
+ }
+ st->lp_noise = floatToFixed(st->lp_noise_float, Q23);
+ floatToFixed_arr(Aq, Aq_fx, Q12, NB_SUBFR16k * (M + 1));
+
+ /*---------------------*/
+ }
+
+ Word32 syn_tmp_32_fx[L_FRAME16k + L_SUBFR], *syn_32_fx;
+ set32_fx(syn_tmp_32_fx, 0, L_FRAME16k + L_SUBFR);
+ syn_32_fx = syn_tmp_32_fx + L_SUBFR;
+
+ if (st->element_mode != IVAS_CPE_DFT || use_cldfb_for_dft)
+ {
+ float realBufferSave[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
+ float imagBufferSave[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
+ float *pRealSave[CLDFB_NO_COL_MAX], *pImagSave[CLDFB_NO_COL_MAX];
+ for (i = 0; i < CLDFB_NO_COL_MAX; i++)
+ {
+ pRealSave[i] = realBufferSave[i];
+ pImagSave[i] = imagBufferSave[i];
+ }
+
+ if (st->p_bpf_noise_buf_float)
+ {
+ mvr2r(bpf_error_signal, st->p_bpf_noise_buf_float, st->L_frame);
+ }
+
+ /* analysis of the synthesis at internal sampling rate */
+
+#ifdef IVAS_FLOAT_FIXED
+ Word32 realBufferSave_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
+ Word32 imagBufferSave_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
+ Word32 *pRealSave_fx[CLDFB_NO_COL_MAX], *pImagSave_fx[CLDFB_NO_COL_MAX];
+ FOR(i = 0; i < CLDFB_NO_COL_MAX; i++)
+ {
+ pRealSave_fx[i] = realBufferSave_fx[i];
+ pImagSave_fx[i] = imagBufferSave_fx[i];
+ }
+ floatToFixed_arrL(bpf_error_signal, bpf_error_signal_fx, st->Q_syn - 1, st->L_frame);
+ IF(st->p_bpf_noise_buf_32)
+ {
+ Copy32(bpf_error_signal_fx, st->p_bpf_noise_buf_32, st->L_frame);
+ }
+
+ floatToFixed_arr(syn, psyn_fx, st->Q_syn, L_FRAME16k);
+ for (i = 0; i < L_FRAME16k; i++)
+ {
+ syn_32_fx[i] = L_shr(L_deposit_h(psyn_fx[i]), 4);
+ }
+
+ Word16 offset = sub(st->cldfbAna->p_filter_length, st->cldfbAna->no_channels);
+ floatToFixed_arrL(st->cldfbAna->cldfb_state, st->cldfbAna->cldfb_state_fx, Q12, offset);
+
+ cldfbAnalysis_ivas_fx(syn_32_fx, realBuffer_fx, imagBuffer_fx, -1, st->cldfbAna);
+
+ fixedToFloat_arrL(st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_state, Q12, offset);
+
+ for (i = 0; i < CLDFB_NO_COL_MAX; i++)
+ {
+ fixedToFloat_arrL(realBuffer_fx[i], realBuffer[i], Q12 - 5, CLDFB_NO_CHANNELS_MAX);
+ fixedToFloat_arrL(imagBuffer_fx[i], imagBuffer[i], Q12 - 5, CLDFB_NO_CHANNELS_MAX);
+ }
+#else
+ cldfbAnalysis_ivas(syn, realBuffer, imagBuffer, -1, st->cldfbAna);
+#endif
+
+ /* analysis and add the BPF error signal */
+#ifdef IVAS_FLOAT_FIXED
+ Word32 tmp_bpf_error_signal_fx[L_FRAME16k];
+ Word16 q_bpf_error_signal;
+ Word16 cldfb_state_offset = sub(st->cldfbBPF->p_filter_length, st->cldfbBPF->no_channels);
+
+ q_bpf_error_signal = Q6;
+
+ // Float to fixed
+ floatToFixed_arrL(bpf_error_signal, tmp_bpf_error_signal_fx, q_bpf_error_signal, L_FRAME16k);
+ for (i = 0; i < CLDFB_NO_COL_MAX; i++)
+ {
+ for (j = 0; j < CLDFB_NO_CHANNELS_MAX; j++)
+ {
+ realBuffer_fx[i][j] = floatToFixed(realBuffer[i][j], q_bpf_error_signal - 6);
+ imagBuffer_fx[i][j] = floatToFixed(imagBuffer[i][j], q_bpf_error_signal - 6);
+ }
+ }
+ for (i = 0; i < cldfb_state_offset; i++)
+ {
+ st->cldfbBPF->cldfb_state_fx[i] = float_to_fix(st->cldfbBPF->cldfb_state[i], q_bpf_error_signal);
+ }
+
+ tmp = -1;
+ move16();
+ IF(st->bpf_off)
+ {
+ tmp = 0;
+ move16();
+ }
+
+ addBassPostFilter_fx(tmp_bpf_error_signal_fx, tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF);
+
+ // Fixed to float
+ for (i = 0; i < CLDFB_NO_COL_MAX; i++)
+ {
+ for (j = 0; j < CLDFB_NO_CHANNELS_MAX; j++)
+ {
+ realBuffer[i][j] = fixedToFloat(realBuffer_fx[i][j], q_bpf_error_signal - 6);
+ imagBuffer[i][j] = fixedToFloat(imagBuffer_fx[i][j], q_bpf_error_signal - 6);
+ }
+ }
+ for (i = 0; i < cldfb_state_offset; i++)
+ {
+ st->cldfbBPF->cldfb_state[i] = fix_to_float(st->cldfbBPF->cldfb_state_fx[i], q_bpf_error_signal);
+ }
+#else
+ addBassPostFilter(bpf_error_signal, st->bpf_off ? 0 : -1, realBuffer, imagBuffer, st->cldfbBPF);
+#endif
+
+ /* set output mask for upsampling */
+#ifdef IVAS_FLOAT_FIXED
+ IF(EQ_16(st->bwidth, NB))
+ {
+ /* set NB mask for upsampling */
+ st->cldfbSyn->bandsToZero = sub(st->cldfbSyn->no_channels, 10);
+ }
+ ELSE IF(NE_16(st->cldfbSyn->bandsToZero, sub(st->cldfbSyn->no_channels, st->cldfbAna->no_channels)))
+ {
+ /* in case of BW switching, re-init to default */
+ st->cldfbSyn->bandsToZero = sub(st->cldfbSyn->no_channels, st->cldfbAna->no_channels);
+ }
+#else
+ if (st->bwidth == NB)
+ {
+ /* set NB mask for upsampling */
+ st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels - 10;
+ }
+ else if (st->cldfbSyn->bandsToZero != st->cldfbSyn->no_channels - st->cldfbAna->no_channels)
+ {
+ /* in case of BW switching, re-init to default */
+ st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels - st->cldfbAna->no_channels;
+ }
+#endif
+
+#ifdef IVAS_FLOAT_FIXED
+ IF(!st->cng_sba_flag || EQ_16(st->element_mode, IVAS_CPE_MDCT))
+ {
+ /*WB/SWB-FD_CNG*/
+ IF((EQ_32(st->core_brate, FRAME_NO_DATA) || EQ_32(st->core_brate, SID_2k40)) && (EQ_16(st->cng_type, FD_CNG)) && (LE_16(st->hFdCngDec->hFdCngCom->numCoreBands, st->cldfbSyn->no_channels)))
+ {
+ /* Float to fixed */
+ f2me_buf(st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt, st->hFdCngDec->hFdCngCom->cngNoiseLevel, &st->hFdCngDec->hFdCngCom->cngNoiseLevelExp, FFTCLDFBLEN);
+
+ // NOTE: this should be removed later.
+ //st->hFdCngDec->hFdCngCom->q_cngNoiseLevel = 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp;
+
+ Word16 tmpBufferScale = 0;
+ generate_comfort_noise_dec_hf_ivas_fx(realBuffer_fx, imagBuffer_fx, /*realBuffer, imagBuffer,*/ &tmpBufferScale, st->hFdCngDec->hFdCngCom, st->cng_ism_flag);
+
+ /* Fixed to float */
+ FOR(i = 0; i < st->hFdCngDec->hFdCngCom->numSlots; i++)
+ {
+ FOR( j = st->hFdCngDec->hFdCngCom->numCoreBands; j < st->hFdCngDec->hFdCngCom->regularStopBand; j++ )
+ {
+ realBuffer[i][j] = me2f(realBuffer_fx[i][j], tmpBufferScale + 15);
+ imagBuffer[i][j] = me2f(imagBuffer_fx[i][j], tmpBufferScale + 15);
+ }
+ }
+
+ IF(st->hFdCngDec->hFdCngCom->regularStopBand < st->cldfbSyn->no_channels)
+ {
+ st->cldfbSyn->bandsToZero = sub(st->cldfbSyn->no_channels, st->hFdCngDec->hFdCngCom->regularStopBand);
+ }
+ ELSE
+ {
+ st->cldfbSyn->bandsToZero = 0;
+ }
+ }
+ }
+#else
+ if (!st->cng_sba_flag || st->element_mode == IVAS_CPE_MDCT)
+ {
+ /*WB/SWB-FD_CNG*/
+ if ((st->core_brate == FRAME_NO_DATA || st->core_brate == SID_2k40) && (st->cng_type == FD_CNG) && (st->hFdCngDec->hFdCngCom->numCoreBands < st->cldfbSyn->no_channels))
+ {
+ generate_comfort_noise_dec_hf_flt(realBuffer, imagBuffer, st->hFdCngDec->hFdCngCom, st->cng_ism_flag);
+
+ if (st->hFdCngDec->hFdCngCom->regularStopBand < st->cldfbSyn->no_channels)
+ {
+ st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels - st->hFdCngDec->hFdCngCom->regularStopBand;
+ }
+ else
+ {
+ st->cldfbSyn->bandsToZero = 0;
+ }
+ }
+ }
+#endif
+
+ if (save_hb_synth != NULL)
+ {
+ /* save and then zero-out lowband */
+#ifdef IVAS_FLOAT_FIXED
+ Word32 save_hb_synth_fx[L_FRAME48k];
+ Word32 synth_fx[L_FRAME48k];
+
+ Word16 Q_real = 0, Q_imag = 0;
+ float max_real = 0.f, max_imag = 0.f;
+ for (i = 0; i < CLDFB_NO_COL_MAX; i++)
+ {
+ for ( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ )
+ {
+ max_real = (float)max(max_real, fabs(realBuffer[i][j]));
+ max_imag = (float)max(max_imag, fabs(imagBuffer[i][j]));
+ }
+ }
+ float max_val = max(max_real, max_imag);
+ Q_imag = norm_s((Word16)max_val);
+ Q_real = Q_imag;
+
+ for (i = 0; i < CLDFB_NO_COL_MAX; i++)
+ {
+ floatToFixed_arrL(realBuffer[i], realBuffer_fx[i], Q_real, CLDFB_NO_CHANNELS_MAX);
+ floatToFixed_arrL(imagBuffer[i], imagBuffer_fx[i], Q_real, CLDFB_NO_CHANNELS_MAX);
+ }
+ floatToFixed_arrL(st->cldfbSynHB->cldfb_state, st->cldfbSynHB->cldfb_state_fx, Q_real - 1, st->cldfbSynHB->p_filter_length);
+ floatToFixed_arrL(save_hb_synth, save_hb_synth_fx, Q_real - 1, L_FRAME48k);
+
+ FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ )
+ {
+ FOR(i = 0; i < CLDFB_NO_COL_MAX; i++)
+ {
+ realBufferSave_fx[i][j] = realBuffer_fx[i][j];
+ imagBufferSave_fx[i][j] = imagBuffer_fx[i][j];
+ IF(j < st->hFdCngDec->hFdCngCom->numCoreBands && i < st->hFdCngDec->hFdCngCom->numSlots)
+ {
+ realBuffer_fx[i][j] = 0;
+ imagBuffer_fx[i][j] = 0;
+ }
+ }
+ }
+
+ cldfbSynthesis_ivas_fx(realBuffer_fx, imagBuffer_fx, save_hb_synth_fx, -1, st->cldfbSynHB);
+
+ fixedToFloat_arrL(synth_fx, synth, Q_real - 1, L_FRAME48k);
+ fixedToFloat_arrL(st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_state, Q_real - 1, st->cldfbSynHB->p_filter_length);
+
+ /* restore lowband */
+ FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ )
+ {
+ FOR(i = 0; i < CLDFB_NO_COL_MAX; i++)
+ {
+ realBuffer_fx[i][j] = realBufferSave_fx[i][j];
+ imagBuffer_fx[i][j] = imagBufferSave_fx[i][j];
+ }
+ }
+ floatToFixed_arrL(st->cldfbSyn->cldfb_state, st->cldfbSyn->cldfb_state_fx, Q_real - 1, st->cldfbSyn->p_filter_length);
+ cldfbSynthesis_ivas_fx(pRealSave_fx, pImagSave_fx, synth_fx, -1, st->cldfbSyn);
+ fixedToFloat_arrL(synth_fx, synth, Q_real - 1, L_FRAME48k);
+ fixedToFloat_arrL(st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_state, Q_real - 1, st->cldfbSynHB->p_filter_length);
+#else
+ for (int16_t j = 0; j < CLDFB_NO_CHANNELS_MAX; j++)
+ {
+ for (i = 0; i < CLDFB_NO_COL_MAX; i++)
+ {
+ realBufferSave[i][j] = realBuffer[i][j];
+ imagBufferSave[i][j] = imagBuffer[i][j];
+ if (j < st->hFdCngDec->hFdCngCom->numCoreBands && i < st->hFdCngDec->hFdCngCom->numSlots)
+ {
+ realBuffer[i][j] = 0.0f;
+ imagBuffer[i][j] = 0.0f;
+ }
+ }
+ }
+ cldfbSynthesis_ivas(realBuffer, imagBuffer, save_hb_synth, -1, st->cldfbSynHB);
+
+ /* restore lowband */
+ for (int16_t j = 0; j < CLDFB_NO_CHANNELS_MAX; j++)
+ {
+ for (i = 0; i < CLDFB_NO_COL_MAX; i++)
+ {
+ realBuffer[i][j] = realBufferSave[i][j];
+ imagBuffer[i][j] = imagBufferSave[i][j];
+ }
+ }
+
+ cldfbSynthesis_ivas(pRealSave, pImagSave, synth, -1, st->cldfbSyn);
+#endif
+ }
+ else
+ {
+ /* synthesis of the combined signal */
+#ifdef IVAS_FLOAT_FIXED
+ Word16 Q_real = 0, Q_imag = 0;
+ float max_real = 0.f, max_imag = 0.f;
+ for (i = 0; i < CLDFB_NO_COL_MAX; i++)
+ {
+ for ( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++) {
+ max_real = (float)max(max_real, fabs(realBuffer[i][j]));
+ max_imag = (float)max(max_imag, fabs(imagBuffer[i][j]));
+ }
+ }
+ float max_val = max(max_real, max_imag);
+ Q_imag = norm_s((Word16)max_val);
+ Q_real = Q_imag;
+
+ for (i = 0; i < CLDFB_NO_COL_MAX; i++)
+ {
+ floatToFixed_arrL(realBuffer[i], realBuffer_fx[i], Q_real, CLDFB_NO_CHANNELS_MAX);
+ floatToFixed_arrL(imagBuffer[i], imagBuffer_fx[i], Q_real, CLDFB_NO_CHANNELS_MAX);
+ }
+ floatToFixed_arrL(st->cldfbSyn->cldfb_state, st->cldfbSyn->cldfb_state_fx, Q_real - 1, st->cldfbSyn->p_filter_length);
+ Word32 synth_fx[L_FRAME48k];
+ floatToFixed_arrL(synth, synth_fx, Q_real - 1, L_FRAME48k);
+
+ cldfbSynthesis_ivas_fx(realBuffer_fx, imagBuffer_fx, synth_fx, -1, st->cldfbSyn);
+
+ fixedToFloat_arrL(synth_fx, synth, Q_real - 1, L_FRAME48k);
+ fixedToFloat_arrL(st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_state, Q_real - 1, st->cldfbSyn->p_filter_length);
+#else
+ cldfbSynthesis_ivas(realBuffer, imagBuffer, synth, -1, st->cldfbSyn);
+#endif
+ }
+
+ /* save synthesis - needed in case of core switching */
+ mvr2r(synth, st->previoussynth, output_frame);
+
+ }
+ else
+ {
+ int16_t nSamples = NS2SA(st->L_frame * FRAMES_PER_SEC, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/); /* IVAS-64: optimization is likely possible here (don't resample the whole frame) */
+
+ /* analysis of the synthesis at internal sampling rate - needed for DFT stereo -> TD stereo switching */
+#ifdef IVAS_FLOAT_FIXED
+ floatToFixed_arr(syn, psyn_fx, st->Q_syn, L_FRAME16k);
+ for (i = 0; i < L_FRAME16k; i++)
+ {
+ syn_32_fx[i] = L_shr(L_deposit_h(psyn_fx[i]), 4);
+ }
+
+ Word16 offset = sub(st->cldfbAna->p_filter_length, st->cldfbAna->no_channels);
+ floatToFixed_arrL(st->cldfbAna->cldfb_state, st->cldfbAna->cldfb_state_fx, Q12, offset);
+
+ cldfbAnalysis_ivas_fx(syn_32_fx + st->L_frame - nSamples, realBuffer_fx, imagBuffer_fx, nSamples, st->cldfbAna);
+
+ fixedToFloat_arrL(st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_state, Q12, offset);
+
+ for (i = 0; i < CLDFB_NO_COL_MAX; i++)
+ {
+ fixedToFloat_arrL(realBuffer_fx[i], realBuffer[i], Q12 - 5, CLDFB_NO_CHANNELS_MAX);
+ fixedToFloat_arrL(imagBuffer_fx[i], imagBuffer[i], Q12 - 5, CLDFB_NO_CHANNELS_MAX);
+ }
+#else
+ cldfbAnalysis_ivas(syn + st->L_frame - nSamples, realBuffer, imagBuffer, nSamples, st->cldfbAna);
+#endif
+
+ /* analysis and add the BPF error signal - needed for DFT stereo -> TD stereo switching */
+#ifdef IVAS_FLOAT_FIXED
+ Word32 tmp_bpf_error_signal_fx[L_FRAME16k];
+ Word16 q_bpf_error_signal;
+ Word16 cldfb_state_offset = sub(st->cldfbBPF->p_filter_length, st->cldfbBPF->no_channels);
+
+ // Get Q-factor
+ q_bpf_error_signal = Q6;
+
+ // Float to fixed
+ floatToFixed_arrL(bpf_error_signal, tmp_bpf_error_signal_fx, q_bpf_error_signal, L_FRAME16k);
+ for (i = 0; i < CLDFB_NO_COL_MAX; i++)
+ {
+ for (j = 0; j < CLDFB_NO_CHANNELS_MAX; j++)
+ {
+ realBuffer_fx[i][j] = floatToFixed(realBuffer[i][j], q_bpf_error_signal - 6);
+ imagBuffer_fx[i][j] = floatToFixed(imagBuffer[i][j], q_bpf_error_signal - 6);
+ }
+ }
+ for (i = 0; i < cldfb_state_offset; i++)
+ {
+ st->cldfbBPF->cldfb_state_fx[i] = float_to_fix(st->cldfbBPF->cldfb_state[i], q_bpf_error_signal);
+ }
+
+ tmp = 0;
+ move16();
+ IF(!st->bpf_off)
+ {
+ tmp = nSamples;
+ move16();
+ }
+ addBassPostFilter_fx(tmp_bpf_error_signal_fx + st->L_frame - nSamples, tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF);
+
+ // Fixed to float
+ for (i = 0; i < CLDFB_NO_COL_MAX; i++)
+ {
+ for (j = 0; j < CLDFB_NO_CHANNELS_MAX; j++)
+ {
+ realBuffer[i][j] = fixedToFloat(realBuffer_fx[i][j], q_bpf_error_signal - 6);
+ imagBuffer[i][j] = fixedToFloat(imagBuffer_fx[i][j], q_bpf_error_signal - 6);
+ }
+ }
+ for (i = 0; i < cldfb_state_offset; i++)
+ {
+ st->cldfbBPF->cldfb_state[i] = fix_to_float(st->cldfbBPF->cldfb_state_fx[i], q_bpf_error_signal);
+ }
+#else
+ addBassPostFilter(bpf_error_signal + st->L_frame - nSamples, st->bpf_off ? 0 : nSamples, realBuffer, imagBuffer, st->cldfbBPF);
+#endif
+ /* synthesis of the combined signal - needed for DFT stereo -> TD stereo switching */
+#ifdef IVAS_FLOAT_FIXED
+ Word16 Q_real = 0, Q_imag = 0;
+ float max_real = 0.f, max_imag = 0.f;
+ for (i = 0; i < CLDFB_NO_COL_MAX; i++)
+ {
+ for ( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ )
+ {
+ max_real = (float)max(max_real, fabs(realBuffer[i][j]));
+ max_imag = (float)max(max_imag, fabs(imagBuffer[i][j]));
+ }
+ }
+ float max_val = max(max_real, max_imag);
+ Q_imag = norm_s((Word16)max_val);
+ Q_real = Q_imag;
+
+ for (i = 0; i < CLDFB_NO_COL_MAX; i++)
+ {
+ floatToFixed_arrL(realBuffer[i], realBuffer_fx[i], Q_real, CLDFB_NO_CHANNELS_MAX);
+ floatToFixed_arrL(imagBuffer[i], imagBuffer_fx[i], Q_real, CLDFB_NO_CHANNELS_MAX);
+ }
+ floatToFixed_arrL(st->cldfbSyn->cldfb_state, st->cldfbSyn->cldfb_state_fx, Q_real - 1, st->cldfbSyn->p_filter_length);
+ Word32 synth_fx[L_FRAME48k];
+ floatToFixed_arrL(synth, synth_fx, Q_real - 1, L_FRAME48k);
+
+ cldfbSynthesis_ivas_fx(realBuffer_fx, imagBuffer_fx, synth_fx /*dummy*/, NS2SA(st->output_Fs, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/), st->cldfbSyn);
+
+ fixedToFloat_arrL(synth_fx, synth, Q_real - 1, L_FRAME48k);
+ fixedToFloat_arrL(st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_state, Q_real - 1, st->cldfbSyn->p_filter_length);
+
+#else
+ cldfbSynthesis_ivas(realBuffer, imagBuffer, synth /*dummy*/, NS2SA(st->output_Fs, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/), st->cldfbSyn);
+#endif
+
+ if (st->p_bpf_noise_buf_float)
+ {
+ mvr2r(bpf_error_signal, st->p_bpf_noise_buf_float, st->L_frame);
+ }
+
+ set_f(synth, 0.0f, output_frame);
+ }
+
+ /* Copy output signal */
+ if (st->element_mode > EVS_MONO)
+ {
+ mvr2r(syn, output, st->L_frame);
+ }
+
+ /*-----------------------------------------------------------------*
+ * Bandwidth extension 6kHz-7kHz
+ *-----------------------------------------------------------------*/
+#ifdef IVAS_FLOAT_FIXED
+ IF( st->hBWE_zero != NULL )
+ {
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF( ( EQ_16( st->L_frame, L_FRAME ) && NE_16( st->bwidth, NB ) && GE_16( output_frame, L_FRAME16k ) &&
+ ( EQ_16( st->extl, -1 ) || EQ_16( st->extl, SWB_CNG ) || ( EQ_16( st->extl, WB_BWE ) && st->extl_brate == 0 && NE_16( st->coder_type_fx, AUDIO ) ) ) ) )
+ {
+ Word16 tmp_exp = 0;
+ floatToFixed_arr( Aq, Aq_fx, Q12, NB_SUBFR16k * ( M + 1 ) );
+ Word16 exc_fx[L_FRAME + L_SUBFR], exp_exc = 0, Q_exc = 0;
+ f2me_buf_16( exc, exc_fx, &exp_exc, L_FRAME );
+ Q_exc = 15 - exp_exc;
+ Word16 Q_syn2 = 0;
+ Word16 synth_fx[L_FRAME48k];
+ floatToFixed_arr( syn, psyn_fx, Q_syn2, L_FRAME + L_SUBFR );
+ floatToFixed_arr( synth, synth_fx, Q_syn2, L_FRAME + L_SUBFR );
+
+ floatToFixed_arr( st->hBWE_zero->delay_syn_hf, st->hBWE_zero->delay_syn_hf_fx, Q_syn2, NS2SA( 16000, DELAY_CLDFB_NS ) - 15 );
+ floatToFixed_arr( st->hBWE_zero->mem_hp_interp, st->hBWE_zero->mem_hp_interp_fx, 0, INTERP_3_1_MEM_LEN );
+ floatToFixed_arr( st->hBWE_zero->mem_syn_hf, st->hBWE_zero->mem_syn_hf_fx, 0, M );
+ floatToFixed_arr( st->hBWE_zero->mem_hf, st->hBWE_zero->mem_hf_fx, -2 - tmp_exp, L_FIR - 1 );
+ floatToFixed_arr( st->hBWE_zero->mem_hp400, st->hBWE_zero->mem_hp400_fx, Q_syn2, 6 );
+ Word16 output_subfr = output_frame / NB_SUBFR;
+
+ hf_synth_ivas_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc_fx,
+ psyn_fx, synth_fx, Q_exc, Q_syn2, st->hBWE_zero->delay_syn_hf_fx, &tmp_exp,
+ st->hBWE_zero->mem_hp_interp_fx, st->extl, st->CNG_mode, st->element_mode );
+
+ IF( st->hBWE_FD != NULL )
+ {
+ st->hBWE_FD->memExp1 = tmp_exp;
+ }
+
+ fixedToFloat_arr( synth_fx, synth, Q_syn2, output_subfr );
+ fixedToFloat_arr( psyn_fx, syn, Q_syn2 - 2, L_SUBFR );
+ fixedToFloat_arr( st->hBWE_zero->delay_syn_hf_fx, st->hBWE_zero->delay_syn_hf, 0, NS2SA( 16000, DELAY_CLDFB_NS ) - 15 );
+ fixedToFloat_arr( st->hBWE_zero->mem_hp_interp_fx, st->hBWE_zero->mem_hp_interp, 0, INTERP_3_1_MEM_LEN );
+ fixedToFloat_arr( st->hBWE_zero->mem_syn_hf_fx, st->hBWE_zero->mem_syn_hf, 0, M );
+ fixedToFloat_arr( st->hBWE_zero->mem_hf_fx, st->hBWE_zero->mem_hf, -2 - tmp_exp, L_FIR - 1 );
+ fixedToFloat_arr( st->hBWE_zero->mem_hp400_fx, st->hBWE_zero->mem_hp400, Q_syn2, 6 );
+ }
+ ELSE
+ {
+ hf_synth_reset_fx( st->hBWE_zero );
+ /*to be cleaned up*/
+ hf_synth_reset( st->hBWE_zero );
+ }
+ }
+#else
+ if (st->hBWE_zero != NULL)
+ {
+ if ((st->L_frame == L_FRAME && st->bwidth != NB && output_frame >= L_FRAME16k &&
+ (st->extl == -1 || st->extl == SWB_CNG || (st->extl == WB_BWE && st->extl_brate == 0 && st->coder_type != AUDIO))))
+ {
+ hf_synth(st->hBWE_zero, st->core_brate, output_frame, Aq, exc2, syn, synth);
+ }
+ else
+ {
+ hf_synth_reset(st->hBWE_zero);
+ }
+ }
+#endif
+
+ /*-----------------------------------------------------------------*
+ * Populate parameters for SWB TBE
+ *-----------------------------------------------------------------*/
+
+ if (st->hBWE_TD != NULL)
+ {
+ if ((!st->bfi && st->prev_bfi) || (st->last_vbr_hw_BWE_disable_dec == 1 && st->vbr_hw_BWE_disable_dec == 0) || ((st->extl == SWB_TBE || st->extl == WB_TBE || st->extl == FB_TBE) && st->last_extl != SWB_TBE && st->last_extl != WB_TBE && st->last_extl != FB_TBE) || (st->idchan == 1 && st->element_mode == IVAS_CPE_TD && !st->tdm_LRTD_flag))
+ {
+ st->hBWE_TD->bwe_non_lin_prev_scale = 0.0f;
+ set_f(st->hBWE_TD->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET);
+ }
+
+ if (!st->ppp_mode_dec && (st->idchan == 0 || st->element_mode != IVAS_CPE_TD || (st->idchan == 1 && st->element_mode == IVAS_CPE_TD && st->tdm_LRTD_flag)))
+ {
+#ifdef IVAS_FLOAT_FIXED
+ Word16 voice_factors_fx[5];
+ Word32 tmp_bwe_exc_extended_fx[L_FRAME32k + NL_BUFF_OFFSET];
+ Word32 tmp_old_bwe_exc_extended_fx[NL_BUFF_OFFSET];
+ Word16 e1, e2;
+ set32_fx( tmp_bwe_exc_extended_fx, 0, L_FRAME32k + NL_BUFF_OFFSET );
+
+ // Extract exponents.
+ f2me_buf_16( bwe_exc, bwe_exc_fx, &e1, L_FRAME32k );
+ f2me_buf( st->hBWE_TD->old_bwe_exc_extended, tmp_old_bwe_exc_extended_fx, &e2, NL_BUFF_OFFSET );
+ st->Q_exc = 15 - s_max( e1, e2 );
+ st->Q_exc = s_min( st->Q_exc, 14 ); // non_linearity_fx function crashes if Q == 15
+ // Float to fixed
+ for ( i = 0; i < ( st->L_frame == L_FRAME16k ? 5 : 4 ); i++ )
+ {
+ voice_factors_fx[i] = float_to_fix16( voice_factors[i], Q15 );
+ }
+ for ( i = 0; i < NL_BUFF_OFFSET; i++ )
+ {
+ tmp_old_bwe_exc_extended_fx[i] = floatToFixed( st->hBWE_TD->old_bwe_exc_extended[i], 2 * st->Q_exc );
+ }
+ for ( i = 0; i < L_FRAME32k; i++ )
+ {
+ bwe_exc_fx[i] = (Word16)floatToFixed( bwe_exc[i], st->Q_exc );
+ if (bwe_exc[i] != 0 && bwe_exc_fx[i] == 0)
+ {
+ // NOTE: This is done to avoid zero values when float values are too small.
+ // Else it will lead to a crash later in Interpolate_allpass_steep_32.
+ bwe_exc_fx[i] = 1;
+ }
+ }
+
+ /* update buffer memory */
+ Copy32( tmp_old_bwe_exc_extended_fx, tmp_bwe_exc_extended_fx, NL_BUFF_OFFSET );
+
+ non_linearity_ivas_fx( bwe_exc_fx, tmp_bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame );
+
+ /* update buffer memory */
+ Copy32( tmp_bwe_exc_extended_fx + L_FRAME32k, tmp_old_bwe_exc_extended_fx, NL_BUFF_OFFSET );
+
+ // Fixed to float
+ st->hBWE_TD->bwe_non_lin_prev_scale = fix_to_float( st->hBWE_TD->bwe_non_lin_prev_scale_fx, Q30 );
+ me2f_buf( tmp_bwe_exc_extended_fx, 31 - 2 * st->Q_exc, bwe_exc_extended, L_FRAME32k + NL_BUFF_OFFSET );
+ me2f_buf( tmp_old_bwe_exc_extended_fx, 31 - 2 * st->Q_exc, st->hBWE_TD->old_bwe_exc_extended, NL_BUFF_OFFSET );
+#else
+ non_linearity( bwe_exc, bwe_exc_extended, st->hBWE_TD->old_bwe_exc_extended, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale, st->coder_type, voice_factors, st->L_frame );
+#endif
+ }
+
+ if ( st->core_brate == FRAME_NO_DATA || st->core_brate == SID_2k40 )
+ {
+ st->hBWE_TD->bwe_non_lin_prev_scale = 0.0f;
+ }
+ }
+
+ /*----------------------------------------------------------------------*
+ * Updates
+ *----------------------------------------------------------------------*/
+
+#ifdef IVAS_FLOAT_FIXED
+ ////////////////////////////////////// Float to fix starts here ////////////////////////////////////////////////
+ Word16 tmp_Q_exc = 0;
+ Word16 tmp_old_exc_fx[L_EXC_DEC]; // Q_exc
+ Word16 tmp_old_bwe_exc_fx[((PIT16k_MAX + (L_FRAME16k + 1) + L_SUBFR16k) * 2)]; // Q_exc
+ Word16 tmp_pitch_buf_fx[NB_SUBFR16k]; // Q6
+ Word16 tmp_Es_pred_fx; // Q8
+ Word16 tmp_Aq_fx[NB_SUBFR16k * (M + 1)]; // Q12
+ Word16 tmp_lsf_new_fx[M]; // Qx2.56
+ Word16 tmp_lsp_new_fx[M]; // Q15
+ Word16 tmp_voice_factors_fx[NB_SUBFR16k]; // Q15
+ Word16 tmp_gain_buf_fx[NB_SUBFR16k]; // Q14
+
+ floatToFixed_arr(old_exc, tmp_old_exc_fx, tmp_Q_exc, L_EXC_DEC);
+ floatToFixed_arr(old_bwe_exc, tmp_old_bwe_exc_fx, tmp_Q_exc, ((PIT16k_MAX + (L_FRAME16k + 1) + L_SUBFR16k) * 2));
+ floatToFixed_arr(pitch_buf, tmp_pitch_buf_fx, Q6, NB_SUBFR16k);
+ tmp_Es_pred_fx = float_to_fix16(Es_pred, Q8);
+ floatToFixed_arr(Aq, tmp_Aq_fx, Q12, NB_SUBFR16k * (M + 1));
+ for (i = 0; i < M; i++)
+ {
+ tmp_lsf_new_fx[i] = (Word16)(lsf_new[i] * 2.56f);
+ }
+ floatToFixed_arr(lsp_new, tmp_lsp_new_fx, Q15, M);
+ floatToFixed_arr(voice_factors, tmp_voice_factors_fx, Q15, NB_SUBFR16k);
+ floatToFixed_arr(gain_buf, tmp_voice_factors_fx, Q14, NB_SUBFR16k);
+ st->Last_GSC_noisy_speech_flag_fx = st->Last_GSC_noisy_speech_flag;
+ st->coder_type_fx = st->coder_type;
+ if (st->hGSCDec != NULL)
+ {
+ st->hGSCDec->Last_GSC_pit_band_idx_fx = st->hGSCDec->Last_GSC_pit_band_idx;
+ st->hGSCDec->seed_tcx_fx = st->hGSCDec->seed_tcx;
+ }
+ st->GSC_noisy_speech_fx = st->GSC_noisy_speech;
+ st->last_ppp_mode_dec_fx = st->last_ppp_mode_dec;
+ st->ppp_mode_dec_fx = st->ppp_mode_dec;
+ st->nelp_mode_dec_fx = st->nelp_mode_dec;
+ st->vbr_hw_BWE_disable_dec_fx = st->vbr_hw_BWE_disable_dec;
+ // just outputs:
+ if (st->hGSCDec != NULL)
+ {
+ st->hGSCDec->noise_lev_fx = st->hGSCDec->noise_lev;
+ floatToFixed_arr(st->hGSCDec->old_y_gain, st->hGSCDec->old_y_gain_fx, Q12, MBANDS_GN);
+ floatToFixed_arr(st->hGSCDec->Last_GSC_spectrum, st->hGSCDec->Last_GSC_spectrum_fx, Q10, M);
+ }
+ st->last_coder_type_fx = st->last_coder_type;
+ st->Last_GSC_noisy_speech_flag_fx = st->Last_GSC_noisy_speech_flag;
+ if (st->hHQ_core != NULL)
+ st->hHQ_core->HqVoicing_fx = st->hHQ_core->HqVoicing;
+ st->old_ppp_mode_fx = st->old_ppp_mode;
+ st->last_ppp_mode_dec_fx = st->last_ppp_mode_dec;
+ st->last_nelp_mode_dec_fx = st->last_nelp_mode_dec;
+ st->last_vbr_hw_BWE_disable_dec_fx = st->last_vbr_hw_BWE_disable_dec;
+ floatToFixed_arr(st->old_exc, st->old_exc_fx, tmp_Q_exc, L_EXC_MEM_DEC);
+ for (i = 0; i < M; i++)
+ {
+ st->lsf_old_fx[i] = (Word16)(st->lsf_old[i] * 2.56f);
+ }
+ floatToFixed_arr(st->lsp_old, st->lsp_old_fx, Q15, M);
+ st->last_voice_factor_fx = float_to_fix16(st->last_voice_factor, Q15);
+ floatToFixed_arrL(st->old_pitch_buf, st->old_pitch_buf_fx, Q16, 2 * NB_SUBFR16k + 2);
+ floatToFixed_arr(st->mem_pitch_gain_float, st->mem_pitch_gain, Q14, 2 * NB_SUBFR16k + 2);
+ for (i = 0; i < M; i++)
+ {
+ st->lsfoldbfi1[i] = (Word16)(st->lsfoldbfi1_fx[i] * 2.56f);
+ st->lsfoldbfi0[i] = (Word16)(st->lsfoldbfi0_fx[i] * 2.56f);
+ }
+ floatToFixed_arr(st->old_Aq_12_8, st->old_Aq_12_8_fx, Q12, M + 1);
+ st->old_Es_pred_fx = float_to_fix16(st->old_Es_pred, Q8);
+ ////////////////////////////////////// Float to fix ends here ////////////////////////////////////////////////
+
+ updt_dec_fx( st, tmp_old_exc_fx, tmp_pitch_buf_fx, tmp_Es_pred_fx, tmp_Aq_fx, tmp_lsf_new_fx, tmp_lsp_new_fx, tmp_voice_factors_fx, tmp_old_bwe_exc_fx, tmp_gain_buf_fx );
+
+ ////////////////////////////////////// Fixed to float starts here ////////////////////////////////////////////
+ st->last_coder_type = st->last_coder_type_fx;
+ if (st->hGSCDec != NULL)
+ {
+ st->hGSCDec->noise_lev = st->hGSCDec->noise_lev_fx;
+ st->hGSCDec->Last_GSC_pit_band_idx = st->hGSCDec->Last_GSC_pit_band_idx_fx;
+ }
+ st->Last_GSC_noisy_speech_flag = st->Last_GSC_noisy_speech_flag_fx;
+ if (st->hHQ_core != NULL)
+ st->hHQ_core->HqVoicing = st->hHQ_core->HqVoicing_fx;
+ st->old_ppp_mode = st->old_ppp_mode_fx;
+ st->last_ppp_mode_dec = st->last_ppp_mode_dec_fx;
+ st->last_nelp_mode_dec = st->last_nelp_mode_dec_fx;
+ st->last_vbr_hw_BWE_disable_dec = st->last_vbr_hw_BWE_disable_dec_fx;
+ fixedToFloat_arr(st->old_exc_fx, st->old_exc, tmp_Q_exc, L_EXC_MEM_DEC);
+ IF(!st->Opt_AMR_WB && st->hBWE_TD != NULL)
+ fixedToFloat_arr(st->hBWE_TD->old_bwe_exc_fx, st->hBWE_TD->old_bwe_exc, tmp_Q_exc, PIT16k_MAX * 2);
+ for (i = 0; i < M; i++)
+ {
+ st->lsf_old[i] = st->lsf_old_fx[i] / 2.56f;
+ }
+ fixedToFloat_arr(st->lsp_old_fx, st->lsp_old, Q15, M);
+ st->last_voice_factor = fix16_to_float(st->last_voice_factor_fx, Q15);
+ if (st->hGSCDec != NULL)
+ {
+ fixedToFloat_arr(st->hGSCDec->Last_GSC_spectrum_fx, st->hGSCDec->Last_GSC_spectrum, Q10, M);
+ fixedToFloat_arr(st->hGSCDec->old_y_gain_fx, st->hGSCDec->old_y_gain, Q12, MBANDS_GN);
+ }
+ fixedToFloat_arrL(st->old_pitch_buf_fx, st->old_pitch_buf, Q16, 2 * NB_SUBFR16k + 2);
+ fixedToFloat_arr(st->mem_pitch_gain, st->mem_pitch_gain_float, Q14, 2 * NB_SUBFR16k + 2);
+ for (i = 0; i < M; i++)
+ {
+ st->lsfoldbfi1[i] = st->lsfoldbfi1_fx[i] / 2.56f;
+ st->lsfoldbfi0[i] = st->lsfoldbfi0_fx[i] / 2.56f;
+ }
+ fixedToFloat_arr(st->old_Aq_12_8_fx, st->old_Aq_12_8, Q12, M+1);
+ st->old_Es_pred = fix16_to_float(st->old_Es_pred_fx, Q8);
+ ////////////////////////////////////// Fixed to float ends here //////////////////////////////////////////////
+#else
+ updt_dec( st, old_exc, pitch_buf, Es_pred, Aq, lsf_new, lsp_new, voice_factors, old_bwe_exc, gain_buf );
+#endif
+
+#ifdef IVAS_FLOAT_FIXED
+ IF( GT_32( st->core_brate, SID_2k40 ) && st->hTdCngDec != NULL && st->hFdCngDec != NULL )
+ {
+ /* update CNG parameters in active frames */
+ Word16 lsp_new_fx[M];
+ Word16 exc_fx[L_EXC_DEC], Q_exc, exp_exc;
+ f2me_buf_16( exc, exc_fx, &exp_exc, st->L_frame );
+ Q_exc = 15 - exp_exc;
+ floatToFixed_arr( lsp_new, lsp_new_fx, Q15, M );
+ floatToFixed_arr( exc, exc_fx, Q_exc, st->L_frame );
+ floatToFixed_arrL( st->hTdCngDec->ho_ener_circ, st->hTdCngDec->ho_ener_circ_fx, Q6, HO_HIST_SIZE );
+ st->hTdCngDec->ho_circ_size_fx = st->hTdCngDec->ho_circ_size;
+ st->hTdCngDec->ho_circ_ptr_fx = st->hTdCngDec->ho_circ_ptr;
+ floatToFixed_arr( st->hTdCngDec->ho_lsp_circ, st->hTdCngDec->ho_lsp_circ_fx, Q15, HO_HIST_SIZE * M );
+ floatToFixed_arrL( st->hTdCngDec->ho_env_circ, st->hTdCngDec->ho_env_circ_fx, Q6, HO_HIST_SIZE * NUM_ENV_CNG );
+
+ cng_params_upd_ivas_fx( lsp_new_fx, exc_fx, st->L_frame, &st->hTdCngDec->ho_circ_ptr_fx, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size_fx,
+ st->hTdCngDec->ho_lsp_circ_fx, Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode,
+ st->hFdCngDec->hFdCngCom->CngBandwidth );
+
+ fixedToFloat_arr( lsp_new_fx, lsp_new, Q15, M );
+ fixedToFloat_arr( exc_fx, exc, Q_exc, st->L_frame );
+ fixedToFloat_arrL( st->hTdCngDec->ho_ener_circ_fx, st->hTdCngDec->ho_ener_circ, Q6, HO_HIST_SIZE );
+ st->hTdCngDec->ho_circ_size = st->hTdCngDec->ho_circ_size_fx;
+ st->hTdCngDec->ho_circ_ptr = st->hTdCngDec->ho_circ_ptr_fx;
+ fixedToFloat_arr( st->hTdCngDec->ho_lsp_circ_fx, st->hTdCngDec->ho_lsp_circ, Q15, HO_HIST_SIZE * M );
+ fixedToFloat_arrL( st->hTdCngDec->ho_env_circ_fx, st->hTdCngDec->ho_env_circ, Q6, HO_HIST_SIZE * NUM_ENV_CNG );
+
+ /* Set 16k LSP flag for CNG buffer */
+ st->hTdCngDec->ho_16k_lsp_fx[st->hTdCngDec->ho_circ_ptr_fx] = 0;
+ move16();
+ IF( NE_16( st->L_frame, L_FRAME ) )
+ {
+ st->hTdCngDec->ho_16k_lsp_fx[st->hTdCngDec->ho_circ_ptr_fx] = 1;
+ move16();
+ }
+ }
+#else
+ if (st->core_brate > SID_2k40 && st->hTdCngDec != NULL && st->hFdCngDec != NULL)
+ {
+ /* update CNG parameters in active frames */
+ cng_params_upd(lsp_new, exc, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ, DEC, st->hTdCngDec->ho_env_circ, NULL, NULL, NULL, st->last_active_brate, st->element_mode, st->hFdCngDec->hFdCngCom->CngBandwidth);
+ /* Set 16k LSP flag for CNG buffer */
+ st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = (st->L_frame == L_FRAME ? 0 : 1);
+ }
+#endif
+
+ pop_wmops();
+ return error;
+ }
+
+static void acelp_decoder_state_float2fix(Decoder_State *st, STEREO_CNG_DEC_HANDLE hStereoCng) {
+ Word16 i;
+ st->Q_exc = 0;
+ st->Q_exc_cng = 0;
+ st->prev_Q_exc = 0;
+ st->prev_Q_exc_fr = 0;
+ set_s(st->Q_subfr, 0, L_Q_MEM);
+ st->Q_syn = 0;
+ st->Q_syn_cng = 0;
+ st->classifier_Q_mem_syn = 0;
+ st->coder_type_fx = st->coder_type;
+ st->last_coder_type_fx = st->last_coder_type;
+ st->last_core_bs_fx = st->last_core_from_bs;
+#if 1
+ floatToFixed_arr(st->lsp_old, st->lsp_old_fx, Q15, M);
+ floatToFixed_arr(st->lspCNG, st->lspCNG_fx, Q15, M);
+ st->lp_ener_fx = floatToFixed(st->lp_ener, Q6);
+ for (i = 0; i < M; i++) {
+ st->lsf_old_fx[i] = (Word16)(st->lsf_old[i] * 2.56f);
+ st->mem_MA_fx[i] = (Word16)(st->mem_MA[i] * 2.56f);
+ st->mem_AR_fx[i] = (Word16)(st->mem_AR[i] * 2.56f);
+ st->lsfoldbfi1_fx[i] = (Word16)(st->lsfoldbfi1[i] * 2.56f);
+ st->lsfoldbfi0_fx[i] = (Word16)(st->lsfoldbfi0[i] * 2.56f);
+ st->lsf_adaptive_mean_fx[i] = (Word16)(st->lsf_adaptive_mean[i] * 2.56f);
+ }
+ floatToFixed_arr(st->old_exc, st->old_exc_fx, st->Q_exc, L_EXC_MEM_DEC);
+ floatToFixed_arr(st->mem_syn1, st->mem_syn1_fx, -1, M);
+ floatToFixed_arr(st->mem_syn2, st->mem_syn2_fx, st->Q_syn, M);
+ floatToFixed_arr(st->mem_syn3, st->mem_syn3_fx, st->Q_syn_cng, M);
+ floatToFixed_arr(st->mem_syn_r_float, st->mem_syn_r, st->Q_syn, L_SYN_MEM);
+ st->mem_preemp_preQ_fx = float_to_fix16(st->mem_preemp_preQ, Q10);
+ floatToFixed_arrL(st->old_pitch_buf, st->old_pitch_buf_fx, Q16, 2 * NB_SUBFR16k + 2);
+ //st->bfi_pitch_fx = float_to_fix16(st->bfi_pitch, Q6);
+ st->bfi_pitch_fx32 = floatToFixed(st->bfi_pitch, Q6);
+ if (hStereoCng) {
+ floatToFixed_arr(hStereoCng->olapBufferSynth22, hStereoCng->olapBufferSynth22_fx, st->Q_syn, FFTLEN);
+ }
+ /* st->mem_deemph_fx will need to be handled with proper Q */
+ st->mem_deemph_fx = (Word16)floatToFixed((Word16)check_bounds_l((Word32)st->mem_deemph, -32768, 32767), st->Q_syn);
+ floatToFixed_arr(st->agc_mem2, st->agc_mem_fx, st->prev_Q_syn - 1, 2);
+ /*Flags (should be unified!)*/
+ st->last_nq_preQ_fx = st->last_nq_preQ;
+ st->safety_net_fx = st->safety_net;
+ st->nelp_mode_dec_fx = st->nelp_mode_dec;
+ st->last_nelp_mode_dec_fx = st->last_nelp_mode_dec;
+ st->ppp_mode_dec_fx = st->ppp_mode_dec;
+ st->relax_prev_lsf_interp_fx = st->relax_prev_lsf_interp;
+ st->last_good_fx = st->last_good;
+ st->unv_cnt_fx = st->unv_cnt;
+ st->uv_count_fx = st->uv_count;
+ st->act_count_fx = st->act_count;
+ st->GSC_noisy_speech_fx = st->GSC_noisy_speech;
+ st->Last_GSC_noisy_speech_flag_fx = st->Last_GSC_noisy_speech_flag;
+ st->mid_lsf_int_fx = st->mid_lsf_int;
+ st->old_bfi_cnt = st->old_bfi_cnt_fx;
+
+ /* dec_exc */
+ st->lp_gainc_fx = float_to_fix16(st->lp_gainc, Q3);
+ st->tilt_code_fx = float_to_fix16(st->tilt_code, Q15);
+ floatToFixed_arr(st->tilt_code_dec, st->tilt_code_dec_fx, Q15, NB_SUBFR16k);
+ st->dm_fx.prev_state = float_to_fix16(st->dispMem[0], 0);
+ st->dm_fx.prev_gain_code = floatToFixed(st->dispMem[1], Q16);
+ floatToFixed_arr(&(st->dispMem[2]), st->dm_fx.prev_gain_pit, Q14, 6);
+ st->gc_threshold_fx = floatToFixed(st->gc_threshold, Q16);
+ st->stab_fac_fx = float_to_fix16(st->stab_fac, Q15);
+ st->prev_gain_pit_dec_fx = float_to_fix16(st->prev_gain_pit_dec, Q14);
+ st->prev_tilt_code_dec_fx = float_to_fix16(st->prev_tilt_code_dec, Q15);
+ st->lp_gainp_fx = float_to_fix16(st->lp_gainp, Q14);
+ st->past_gpit = float_to_fix16(st->past_gpit_float, Q14);
+
+ /* Bad frame */
+ floatToFixed_arr(st->lspold_s, st->lspold_s_fx, Q15, M);
+ floatToFixed_arr(st->mem_pitch_gain_float, st->mem_pitch_gain, Q14, 2 * NB_SUBFR16k + 2);
+ st->min_alpha_fx = float_to_fix16(st->min_alpha, Q15);
+ st->ge_sm_fx = (Word16)floatToFixed(st->ge_sm, st->Q_stat_noise_ge);
+ st->last_voice_factor_fx = float_to_fix16(st->last_voice_factor, Q15);
+
+
+ /* After dec_exc */
+ st->lp_ener_FER_fx = float_to_fix16(st->lp_ener_bfi, Q8);
+ st->enr_old_fx = floatToFixed(st->enr_old, 0);
+ st->old_enr_LP = (Word16)floatToFixed((Word16)check_bounds_l((Word32)st->old_enr_LP_float, -32768, 32767), Q3);
+ st->lp_ener_FEC_av = floatToFixed(st->lp_ener_FEC_av_float, 0);
+ st->lp_ener_FEC_max = floatToFixed(st->lp_ener_FEC_max_float, 0);
+ floatToFixed_arr(st->mem_syn_clas_estim, st->mem_syn_clas_estim_fx, st->classifier_Q_mem_syn, L_SYN_MEM_CLAS_ESTIM);
+ st->exc_pe_fx = (Word16)floatToFixed(st->exc_pe, st->Q_stat_noise);
+ st->psf_lp_noise_fx = float_to_fix16(st->psf_lp_noise, Q8);
+ st->lp_noise = floatToFixed(st->lp_noise_float, Q23);
+ floatToFixed_arr(st->syn_float, st->syn, 0, M + 1);
+ floatToFixed_arr(st->lspold_cng_float, st->lspold_cng, Q15, M);
+
+ /* CLDFB */
+ Word16 old_len_ana, old_len_bpf;
+ // The following lines are to calculate the length of the buffers before and
+ // after calling the function for fixed pt conversion. The calculations are taken
+ // based on the logic used in resampleCldfb_ivas_fx
+ old_len_ana = st->cldfbAna->p_filter_length - st->cldfbAna->no_channels;
+ old_len_bpf = st->cldfbBPF->p_filter_length - st->cldfbBPF->no_channels;
+
+ floatToFixed_arrL(st->cldfbAna->cldfb_state, st->cldfbAna->cldfb_state_fx, Q11, old_len_ana);
+ floatToFixed_arrL(st->cldfbBPF->cldfb_state, st->cldfbBPF->cldfb_state_fx, Q10, old_len_bpf);
+
+ st->stab_fac_smooth_fx = float_to_fix16(st->stab_fac_smooth, Q15);
+
+ //hBPF
+ if (st->hBPF) {
+ floatToFixed_arr(st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_fx, st->Q_syn2 - 1, NBPSF_PIT_MAX);
+ st->hBPF->pst_mem_deemp_err_fx = (Word16)floatToFixed(st->hBPF->pst_mem_deemp_err, st->Q_syn2 - 1);
+ floatToFixed_arr(st->hBPF->mem_mean_pit, st->hBPF->mem_mean_pit_fx, Q4, L_TRACK_HIST);
+ Copy(st->hBPF->Track_on_hist, st->hBPF->Track_on_hist_fx, L_TRACK_HIST);
+ Copy(st->hBPF->vibrato_hist, st->hBPF->vibrato_hist_fx, L_TRACK_HIST);
+ st->hBPF->pst_lp_ener_fx = float_to_fix16(st->hBPF->pst_lp_ener, Q8);
+ st->hBPF->psf_att_fx = float_to_fix16(st->hBPF->psf_att, Q15);
+ }
+
+ //FdCng
+ if ( st->hFdCngDec )
+ {
+ floatToFixed_arrL( st->hFdCngDec->hFdCngCom->sidNoiseEst_flt, st->hFdCngDec->hFdCngCom->sidNoiseEst, Q31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp, NPART );
+ floatToFixed_arrL( st->hFdCngDec->hFdCngCom->sidNoiseEstLp_flt, st->hFdCngDec->hFdCngCom->sidNoiseEstLp, Q31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp, NPART );
+ st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = Q31 - 4;
+ floatToFixed_arrL(st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt, st->hFdCngDec->hFdCngCom->cngNoiseLevel, Q31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp, FFTCLDFBLEN);
+ floatToFixed_arr(st->hFdCngDec->hFdCngCom->A_cng_flt, st->hFdCngDec->hFdCngCom->A_cng, Q12, M + 1);
+ st->hFdCngDec->hFdCngCom->A_cng[0] = 4096;
+ floatToFixed_arr(st->hFdCngDec->hFdCngCom->exc_cng_flt, st->hFdCngDec->hFdCngCom->exc_cng, st->Q_exc_cng, L_FRAME16k);
+ //floatToFixed_arrL(st->hFdCngDec->hFdCngCom->fftBuffer_flt, st->hFdCngDec->hFdCngCom->fftBuffer, st->Q_syn, FFTLEN);
+ floatToFixed_arr(st->hFdCngDec->hFdCngCom->timeDomainBuffer_flt, st->hFdCngDec->hFdCngCom->timeDomainBuffer, st->Q_syn_cng, L_FRAME16k);
+ floatToFixed_arr(st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, st->hFdCngDec->hFdCngCom->olapBufferSynth, st->hFdCngDec->hFdCngCom->fftlenShift, FFTLEN);
+ floatToFixed_arr(st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->hFdCngDec->hFdCngCom->fftlenShift, FFTLEN);
+ st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = float_to_fix16(st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt, Q15);
+ floatToFixed_arrL( st->hFdCngDec->bandNoiseShape_float, st->hFdCngDec->bandNoiseShape, Q31 - st->hFdCngDec->bandNoiseShape_exp, FFTLEN2);
+ st->hFdCngDec->partNoiseShape_exp = 31 - Q4;
+ floatToFixed_arrL( st->hFdCngDec->partNoiseShape_float, st->hFdCngDec->partNoiseShape, Q31 - st->hFdCngDec->partNoiseShape_exp, NPART);
+
+ /*CNA: ApplyFdCng*/
+ if ((st->hFdCngDec != NULL || st->idchan == 1) && st->element_mode != IVAS_CPE_MDCT)
+ {
+ if (st->element_mode == IVAS_CPE_TD || st->flag_cna || (st->cng_type == FD_CNG && st->total_brate <= ACELP_32k) || (st->cng_type == LP_CNG && st->core_brate <= SID_2k40))
+ {
+ if (st->element_mode != IVAS_CPE_TD && !st->cng_ism_flag)
+ {
+ st->hFdCngDec->hFdCngCom->fftBuffer_exp = st->hFdCngDec->msNoiseEst_exp = Q31 - Q4; //st->hFdCngDec->hFdCngCom->periodog_exp = st->hFdCngDec->msPsd_exp_fft = st->hFdCngDec->msPeriodog_exp = st->hFdCngDec->msPeriodog_ST_exp = 31 - Q4; Q4
+ floatToFixed_arrL(st->hFdCngDec->hFdCngCom->periodog_flt, st->hFdCngDec->hFdCngCom->periodog, Q31 - st->hFdCngDec->hFdCngCom->periodog_exp, PERIODOGLEN);
+ floatToFixed_arrL(st->hFdCngDec->hFdCngCom->fftBuffer_flt, st->hFdCngDec->hFdCngCom->fftBuffer, Q31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp, st->hFdCngDec->hFdCngCom->fftlen);
+ floatToFixed_arrL(st->hFdCngDec->msPsd_float, st->hFdCngDec->msPsd_fx, Q31 - st->hFdCngDec->msPsd_exp_fft, NPART_SHAPING);
+ floatToFixed_arrL(st->hFdCngDec->msNoiseEst_float, st->hFdCngDec->msNoiseEst, Q31 - st->hFdCngDec->msNoiseEst_exp, st->hFdCngDec->npart_shaping);
+ floatToFixed_arrL(st->hFdCngDec->msPeriodog_float, st->hFdCngDec->msPeriodog, Q31 - st->hFdCngDec->msPeriodog_exp, st->hFdCngDec->npart_shaping);
+ floatToFixed_arrL(st->hFdCngDec->msPeriodog_ST, st->hFdCngDec->msPeriodog_ST_fx, Q31 - st->hFdCngDec->msPeriodog_ST_exp, st->hFdCngDec->npart_shaping);
+ if (st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT)
+ {
+ floatToFixed_arrL(st->hFdCngDec->smoothed_psd, st->hFdCngDec->smoothed_psd_fx, Q31 - st->hFdCngDec->msNoiseEst_exp, L_FRAME16k - st->hFdCngDec->hFdCngCom->startBand);
+ }
+ //st->hTcxDec->CngLevelBackgroundTrace_bfi_fx = floatToFixed(st->hTcxDec->CngLevelBackgroundTrace_bfi, (31 - st->hTcxDec->CngLevelBackgroundTrace_bfi_exp));
+ //st->cngTDLevel = float_to_fix16(st->cngTDLevel_float, (15 - st->cngTDLevel_e));
+ //floatToFixed_arrL(st->hFdCngDec->msMinBuf_float, st->hFdCngDec->msMinBuf, Q31 - Q6, MSNUMSUBFR * NPART_SHAPING); // CNG_S = 6
+ //floatToFixed_arr(st->hFdCngDec->msPeriodogBuf_float, st->hFdCngDec->msPeriodogBuf, Q9, NPART_SHAPING);
+ //floatToFixed_arr(st->hFdCngDec->msPsdFirstMoment_float, st->hFdCngDec->msPsdFirstMoment, Q9, NPART_SHAPING);
+ //floatToFixed_arrL(st->hFdCngDec->msPsdSecondMoment_float, st->hFdCngDec->msPsdSecondMoment, Q19, NPART_SHAPING);
+ //floatToFixed_arr(st->hFdCngDec->msNoiseFloor_float, st->hFdCngDec->msNoiseFloor, Q9, NPART_SHAPING);
+ //floatToFixed_arrL(st->hFdCngDec->msAlpha_float, st->hFdCngDec->msAlpha, Q31, NPART_SHAPING);
+ //floatToFixed_arrL(st->hFdCngDec->msBminWin_float, st->hFdCngDec->msBminWin, Q27, NPART_SHAPING);
+ //floatToFixed_arrL(st->hFdCngDec->msBminSubWin_float, st->hFdCngDec->msBminSubWin, Q27, NPART_SHAPING);
+ //floatToFixed_arrL(st->hFdCngDec->msCurrentMin_float, st->hFdCngDec->msCurrentMin, Q31 - (Q6 + Q1 + Q4), NPART_SHAPING);// exp : CNG_S + 1 + 4
+ //floatToFixed_arrL(st->hFdCngDec->msCurrentMinOut_float, st->hFdCngDec->msCurrentMinOut, Q31 - Q6, NPART_SHAPING);
+ //floatToFixed_arrL(st->hFdCngDec->msCurrentMinSubWindow_float, st->hFdCngDec->msCurrentMinSubWindow, Q31 - Q6, NPART_SHAPING);// exp : CNG_S + 1 + 4
+ }
+ }
+ }
+ }
+
+ //TdCng
+ if (st->hTdCngDec)
+ {
+ st->hTdCngDec->old_enr_index_fx = st->hTdCngDec->old_enr_index;
+ st->hTdCngDec->Enew_fx = floatToFixed(st->hTdCngDec->Enew, Q6);
+ st->hTdCngDec->ho_hist_ptr_fx = st->hTdCngDec->ho_hist_ptr;
+ st->hTdCngDec->ho_hist_size_fx = st->hTdCngDec->ho_hist_size;
+ st->hTdCngDec->num_ho_fx = st->hTdCngDec->num_ho;
+ st->hTdCngDec->act_cnt2_fx = st->hTdCngDec->act_cnt2;
+ st->hTdCngDec->act_cnt_fx = st->hTdCngDec->act_cnt;
+ st->hTdCngDec->ho_circ_ptr_fx = st->hTdCngDec->ho_circ_ptr;
+ st->hTdCngDec->ho_circ_size_fx = st->hTdCngDec->ho_circ_size;
+ Copy(st->hTdCngDec->ho_16k_lsp, st->hTdCngDec->ho_16k_lsp_fx, HO_HIST_SIZE);
+ floatToFixed_arr(st->hTdCngDec->ho_lsp_circ, st->hTdCngDec->ho_lsp_circ_fx, Q15, HO_HIST_SIZE * M);
+ floatToFixed_arr(st->hTdCngDec->ho_lsp_hist, st->hTdCngDec->ho_lsp_hist_fx, Q15, HO_HIST_SIZE * M);
+ floatToFixed_arrL(st->hTdCngDec->ho_ener_circ, st->hTdCngDec->ho_ener_circ_fx, Q6, HO_HIST_SIZE);
+ floatToFixed_arrL(st->hTdCngDec->ho_ener_hist, st->hTdCngDec->ho_ener_hist_fx, Q6, HO_HIST_SIZE);
+ st->hTdCngDec->ho_sid_bw_fx = st->hTdCngDec->ho_sid_bw;
+ floatToFixed_arrL(st->hTdCngDec->ho_env_circ, st->hTdCngDec->ho_env_circ_fx, Q6, HO_HIST_SIZE * NUM_ENV_CNG);
+ floatToFixed_arrL(st->hTdCngDec->ho_env_hist, st->hTdCngDec->ho_env_hist_fx, Q6, HO_HIST_SIZE * NUM_ENV_CNG);
+ floatToFixed_arrL(st->hTdCngDec->old_env, st->hTdCngDec->old_env_fx, Q6, 20);
+ floatToFixed_arrL(st->hTdCngDec->lp_env, st->hTdCngDec->lp_env_fx, Q6, 20);
+ floatToFixed_arr(st->hTdCngDec->exc_mem, st->hTdCngDec->exc_mem_fx, st->Q_exc, 24);
+ floatToFixed_arr(st->hTdCngDec->exc_mem1, st->hTdCngDec->exc_mem1_fx, st->Q_exc, 30);
+ }
+
+ /*PFSTAT_HANDLE*/
+ if (st->hPFstat) {
+ floatToFixed_arr(st->hPFstat->mem_pf_in_flt, st->hPFstat->mem_pf_in, st->Q_syn, L_SUBFR);
+ floatToFixed_arr(st->hPFstat->mem_stp_flt, st->hPFstat->mem_stp, st->Q_syn, L_SUBFR);
+ floatToFixed_arr(st->hPFstat->mem_res2_flt, st->hPFstat->mem_res2, st->Q_syn, DECMEM_RES2);
+ floatToFixed_arr(st->hPFstat->mem_zero_flt, st->hPFstat->mem_zero, st->Q_syn, M);
+ st->hPFstat->gain_prec = float_to_fix16(st->hPFstat->gain_prec_flt, Q14);
+ }
+
+ /*WI_DEC_HANDLE*/
+ if (st->hWIDec) {
+ floatToFixed_arr(st->hWIDec->old_exc2, st->hWIDec->old_exc2_fx, st->prev_Q_exc_fr, L_EXC_MEM);
+ floatToFixed_arr(st->hWIDec->old_syn2, st->hWIDec->old_syn2_fx, st->prev_Q_syn_fr, L_EXC_MEM);
+ }
+
+ /*TD_BWE_DEC_HANDLE*/
+ if (st->hBWE_TD) {
+ floatToFixed_arr(st->hBWE_TD->old_bwe_exc, st->hBWE_TD->old_bwe_exc_fx, st->Q_exc, PIT16k_MAX * 2);
+ floatToFixed_arr(st->hBWE_TD->cur_sub_Aq, st->hBWE_TD->cur_sub_Aq_fx, Q12, M + 1);
+ }
+
+ /*GSC_DEC_HANDLE*/
+ if (st->hGSCDec) {
+ if (st->hGSCDec->Last_frame_ener >= (float)MAX_32) {
+ st->hGSCDec->Last_frame_ener_fx = MAX_32;
+ }
+ else {
+ st->hGSCDec->Last_frame_ener_fx = floatToFixed(st->hGSCDec->Last_frame_ener, 0);
+ }
+ st->hGSCDec->seed_tcx_fx = st->hGSCDec->seed_tcx;
+ st->hGSCDec->cor_strong_limit_fx = st->hGSCDec->cor_strong_limit;
+ floatToFixed_arr(st->hGSCDec->old_y_gain, st->hGSCDec->old_y_gain_fx, Q12, MBANDS_GN16k);
+ st->hGSCDec->noise_lev_fx = st->hGSCDec->noise_lev;
+ floatToFixed_arr(st->hGSCDec->lt_ener_per_band, st->hGSCDec->lt_ener_per_band_fx, Q12, MBANDS_GN16k);
+ floatToFixed_arr(st->hGSCDec->Last_GSC_spectrum, st->hGSCDec->Last_GSC_spectrum_fx, Q10, L_FRAME16k);
+ st->hGSCDec->Last_GSC_pit_band_idx_fx = st->hGSCDec->Last_GSC_pit_band_idx;
+ floatToFixed_arr(st->hGSCDec->last_exc_dct_in, st->hGSCDec->last_exc_dct_in_fx, st->Q_exc, L_FRAME16k);
+ // st->hGSCDec->last_ener_fx = float_to_fix16(st->hGSCDec->last_ener, 0);
+ Copy(st->hGSCDec->last_bitallocation_band, st->hGSCDec->last_bitallocation_band_fx, 6);
+ }
+
+ /*TCX_DEC_HANDLE*/
+ if (st->hTcxDec) {
+ floatToFixed_arr(st->hTcxDec->syn_Overl_float, st->hTcxDec->syn_Overl, 0, L_FRAME32k / 2);
+ floatToFixed_arr(st->hTcxDec->old_syn_Overl_float, st->hTcxDec->old_syn_Overl, -1, st->L_frame / 2);
+ }
+
+ /*MUSIC_POSTFILT_HANDLE*/
+ if (st->hMusicPF) {
+ floatToFixed_arr(st->hMusicPF->dct_post_old_exc, st->hMusicPF->dct_post_old_exc_fx, st->Q_exc, DCT_L_POST - OFFSET2);
+ floatToFixed_arr(st->hMusicPF->filt_lfE, st->hMusicPF->filt_lfE_fx, Q15, DCT_L_POST);
+ floatToFixed_arr(st->hMusicPF->LDm_enh_lp_gbin, st->hMusicPF->LDm_enh_lp_gbin_fx, Q14, VOIC_BINS_HR);
+ st->hMusicPF->LDm_enh_min_ns_gain_fx = float_to_fix16(st->hMusicPF->LDm_enh_min_ns_gain, Q15);
+ floatToFixed_arrL(st->hMusicPF->LDm_enh_lf_EO, st->hMusicPF->LDm_enh_lf_EO_fx, Q10, VOIC_BINS_HR);
+ floatToFixed_arr(st->hMusicPF->LDm_lt_diff_etot, st->hMusicPF->LDm_lt_diff_etot_fx, Q15, MAX_LT);
+ st->hMusicPF->LDm_mem_etot_fx = float_to_fix16(st->hMusicPF->LDm_mem_etot, Q8);
+ st->hMusicPF->LDm_nb_thr_3_fx = st->hMusicPF->LDm_nb_thr_3;
+ st->hMusicPF->LDm_nb_thr_1_fx = st->hMusicPF->LDm_nb_thr_1;
+ floatToFixed_arr(st->hMusicPF->LDm_thres, st->hMusicPF->LDm_thres_fx, Q12, 4);
+ st->hMusicPF->LDm_last_music_flag_fx = st->hMusicPF->LDm_last_music_flag;
+ st->hMusicPF->last_nonfull_music_fx = st->hMusicPF->last_nonfull_music;
+ floatToFixed_arrL(st->hMusicPF->LDm_bckr_noise, st->hMusicPF->LDm_bckr_noise_fx, Q10, MBANDS_GN_LD);
+ }
+
+ /*FD_BWE_DEC_HANDLE*/
+ if (st->hBWE_FD) {
+ floatToFixed_arr(st->hBWE_FD->old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, -1, NS2SA(16000, DELAY_FD_BWE_ENC_NS));
+ st->hBWE_FD->mem_deemph_old_syn_fx = extract_l( floatToFixed( st->hBWE_FD->mem_deemph_old_syn, -1 ) );
+ }
+
+#else
+ st->Q_exc = 0;
+ st->Q_syn = 0;
+ for (i = 0; i < M; i++) {
+ st->lsf_old_fx[i] = (Word16)(st->lsf_old[i] * 2.56f);
+ st->mem_MA_fx[i] = (Word16)(st->mem_MA[i] * 2.56f);
+ st->mem_AR_fx[i] = (Word16)(st->mem_AR[i] * 2.56f);
+ st->lsfoldbfi1_fx[i] = (Word16)(st->lsfoldbfi1[i] * 2.56f);
+ st->lsfoldbfi0_fx[i] = (Word16)(st->lsfoldbfi0[i] * 2.56f);
+ st->lsf_adaptive_mean_fx[i] = (Word16)(st->lsf_adaptive_mean[i] * 2.56f);
+ }
+ floatToFixed_arr(st->lsp_old, st->lsp_old_fx, Q15, M);
+ st->tilt_code_fx = float_to_fix16(st->tilt_code, Q15);
+ floatToFixed_arr(st->old_exc, st->old_exc_fx, st->prev_Q_exc, L_EXC_MEM_DEC);
+ floatToFixed_arr(st->mem_syn1, st->mem_syn1_fx, -1, M);
+ floatToFixed_arr(st->mem_syn2, st->mem_syn2_fx, st->Q_syn, M);
+ floatToFixed_arr(st->mem_syn3, st->mem_syn3_fx, st->Q_syn, M);
+ st->mem_deemph_fx = (Word16)floatToFixed(st->mem_deemph, st->Q_syn);
+ st->stab_fac_fx = float_to_fix16(st->stab_fac, Q15);
+ st->stab_fac_smooth_fx = float_to_fix16(st->stab_fac_smooth, Q15);
+ floatToFixed_arr(st->agc_mem2, st->agc_mem_fx, st->Q_syn - 1, 2);
+ //st->mid_lsf_int_fx = st->mid_lsf_int;
+ st->safety_net_fx = st->safety_net;
+ //st->GSC_noisy_speech_fx = st->GSC_noisy_speech;
+ //st->Last_GSC_noisy_speech_flag_fx = st->Last_GSC_noisy_speech_flag;
+ st->gc_threshold_fx = floatToFixed(st->gc_threshold, Q16);
+ st->dm_fx.prev_state = float_to_fix16(st->dispMem[0], 0);
+ st->dm_fx.prev_gain_code = floatToFixed(st->dispMem[1], Q16);
+ floatToFixed_arr(&(st->dispMem[2]), st->dm_fx.prev_gain_pit, Q14, 6);
+ //st->unv_cnt_fx = st->unv_cnt;
+ //st->uv_count_fx = st->uv_count;
+ //st->act_count_fx = st->act_count;
+ st->ge_sm_fx = (Word16)floatToFixed(st->ge_sm, st->Q_stat_noise_ge);
+ floatToFixed_arr(st->lspold_s, st->lspold_s_fx, Q15, M);
+ //st->noimix_seed_fx = st->noimix_seed;
+ st->min_alpha_fx = float_to_fix16(st->min_alpha, Q15);
+ st->exc_pe_fx = (Word16)floatToFixed(st->exc_pe, st->Q_stat_noise);
+ st->lp_gainp_fx = float_to_fix16(st->lp_gainp, Q14);
+ st->lp_gainc_fx = float_to_fix16(st->lp_gainc, Q3);
+ st->lp_ener_fx = floatToFixed(st->lp_ener, Q6);
+ st->enr_old_fx = floatToFixed(st->enr_old, 0);
+ st->bfi_pitch_fx = float_to_fix16(st->bfi_pitch, Q6);
+ floatToFixed_arrL(st->old_pitch_buf, st->old_pitch_buf_fx, Q16, 2 * NB_SUBFR16k + 2);
+ st->lp_ener_FEC_av = floatToFixed(st->lp_ener_FEC_av_float, 0);
+ st->lp_ener_FEC_max = floatToFixed(st->lp_ener_FEC_max_float, 0);
+ st->old_enr_LP = float_to_fix16(st->old_enr_LP_float, st->Q_exc);
+ //st->last_good_fx = st->last_good;
+ st->lp_ener_FER_fx = float_to_fix16(st->lp_ener_bfi, Q8);
+ //st->relax_prev_lsf_interp_fx = st->relax_prev_lsf_interp;
+ floatToFixed_arr(st->mem_syn_clas_estim, st->mem_syn_clas_estim_fx, st->Q_syn, L_SYN_MEM_CLAS_ESTIM);
+ // cldfbAna
+ // cldfbBPF
+ // cldfbSyn
+ st->perc_bwddec = float_to_fix16(st->perc_bwddec_float, Q14);
+ st->avg_nrg_LT = floatToFixed(st->avg_nrg_LT_float, 0);
+ st->Ng_ener_ST_fx = float_to_fix16(st->ng_ener_ST, Q8);
+ st->mem_preemp_preQ_fx = float_to_fix16(st->mem_preemp_preQ, 0);
+ //st->last_nq_preQ_fx = st->last_nq_preQ;
+ st->psf_lp_noise_fx = float_to_fix16(st->psf_lp_noise, Q8);
+ st->last_voice_factor_fx = float_to_fix16(st->last_voice_factor, Q15);
+ floatToFixed_arr(st->hTcxDec->old_syn_Overl_float, st->hTcxDec->old_syn_Overl, -1, st->L_frame / 2);
+ floatToFixed_arr(st->Aq_cng_float, st->Aq_cng, 0, (NB_SUBFR16k + 1)*(M + 1));
+ floatToFixed_arr(st->hBWE_TD->old_bwe_exc, st->hBWE_TD->old_bwe_exc_fx, st->Q_exc, PIT16k_MAX * 2);
+ floatToFixed_arr(st->hBWE_TD->cur_sub_Aq, st->hBWE_TD->cur_sub_Aq_fx, Q14, M + 1);
+ floatToFixed_arr(st->syn_float, st->syn, 0, M + 1);
+ /*GSC_DEC_HANDLE*/
+ if (st->hGSCDec) {
+ st->hGSCDec->seed_tcx_fx = st->hGSCDec->seed_tcx;
+ st->hGSCDec->cor_strong_limit_fx = st->hGSCDec->cor_strong_limit;
+ floatToFixed_arr(st->hGSCDec->old_y_gain, st->hGSCDec->old_y_gain_fx, Q15, MBANDS_GN);
+ st->hGSCDec->noise_lev_fx = st->hGSCDec->noise_lev;
+ floatToFixed_arr(st->hGSCDec->lt_ener_per_band, st->hGSCDec->lt_ener_per_band_fx, Q12, MBANDS_GN);
+ if (st->hGSCDec->Last_frame_ener >= (float)MAX_32) {
+ st->hGSCDec->Last_frame_ener_fx = MAX_32;
+ }
+ else {
+ st->hGSCDec->Last_frame_ener_fx = float_to_fix(st->hGSCDec->Last_frame_ener, 0);
+ }
+ floatToFixed_arr(st->hGSCDec->Last_GSC_spectrum, st->hGSCDec->Last_GSC_spectrum_fx, Q10, L_FRAME);
+ st->hGSCDec->Last_GSC_pit_band_idx_fx = st->hGSCDec->Last_GSC_pit_band_idx;
+ floatToFixed_arr(st->hGSCDec->last_exc_dct_in, st->hGSCDec->last_exc_dct_in_fx, st->Q_exc, L_FRAME);
+ st->hGSCDec->last_ener_fx = float_to_fix16(st->hGSCDec->last_ener, Q8);
+ Copy(st->hGSCDec->last_bitallocation_band, st->hGSCDec->last_bitallocation_band_fx, 6);
+ }
+ /*ZERO_BWE_DEC_HANDLE*/
+ if (st->hBWE_zero) {
+ st->hBWE_zero->seed2_fx = st->hBWE_zero->seed2;
+ floatToFixed_arr(st->hBWE_zero->mem_hp400, st->hBWE_zero->mem_hp400_fx, st->Q_syn, 4);
+ floatToFixed_arr(st->hBWE_zero->mem_hf, st->hBWE_zero->mem_hf_fx, st->Q_syn, L_FIR - 1);
+ floatToFixed_arr(st->hBWE_zero->mem_syn_hf, st->hBWE_zero->mem_syn_hf_fx, st->Q_syn, M);
+ floatToFixed_arr(st->hBWE_zero->delay_syn_hf, st->hBWE_zero->delay_syn_hf_fx, st->Q_syn, NS2SA(16000, DELAY_CLDFB_NS));
+ floatToFixed_arr(st->hBWE_zero->mem_hp_interp, st->hBWE_zero->mem_hp_interp_fx, st->Q_syn, INTERP_3_1_MEM_LEN);
+ }
+ /*WI_DEC_HANDLE*/
+ if (st->hWIDec) {
+ floatToFixed_arr(st->hWIDec->old_exc2, st->hWIDec->old_exc2_fx, st->Q_exc, L_EXC_MEM);
+ floatToFixed_arr(st->hWIDec->old_syn2, st->hWIDec->old_syn2_fx, st->Q_syn, L_EXC_MEM);
+ }
+ /*BPF_DEC_HANDLE*/
+ floatToFixed_arr(st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_fx, st->Q_syn, NBPSF_PIT_MAX);
+ st->hBPF->pst_mem_deemp_err_fx = (Word16)floatToFixed(st->hBPF->pst_mem_deemp_err, st->Q_syn);
+ st->hBPF->pst_lp_ener_fx = float_to_fix16(st->hBPF->pst_lp_ener, Q8);
+ Copy(st->hBPF->Track_on_hist, st->hBPF->Track_on_hist_fx, L_TRACK_HIST);
+ Copy(st->hBPF->vibrato_hist, st->hBPF->vibrato_hist_fx, L_TRACK_HIST);
+ st->hBPF->psf_att_fx = float_to_fix16(st->hBPF->psf_att, Q15);
+ floatToFixed_arr(st->hBPF->mem_mean_pit, st->hBPF->mem_mean_pit_fx, Q4, L_TRACK_HIST);
+ /*PFSTAT_HANDLE*/
+ floatToFixed_arr(st->hPFstat->mem_pf_in_flt, st->hPFstat->mem_pf_in, st->Q_syn, L_SUBFR);
+ floatToFixed_arr(st->hPFstat->mem_stp_flt, st->hPFstat->mem_stp, st->Q_syn, L_SUBFR);
+ floatToFixed_arr(st->hPFstat->mem_res2_flt, st->hPFstat->mem_res2, st->Q_syn, DECMEM_RES2);
+ floatToFixed_arr(st->hPFstat->mem_res2_flt, st->hPFstat->mem_res2, st->Q_syn, M);
+ st->hPFstat->gain_prec = float_to_fix16(st->hPFstat->gain_prec_flt, Q14);
+ /*Missing parameters*/
+ st->prev_gain_pit_dec_fx = float_to_fix16(st->prev_gain_pit_dec, Q14);
+ floatToFixed_arr(st->tilt_code_dec, st->tilt_code_dec_fx, Q15, NB_SUBFR16k);
+ floatToFixed_arr(st->previoussynth, st->previoussynth_fx, 0, L_FRAME48k);
+ floatToFixed_arr(st->old_Aq_12_8, st->old_Aq_12_8_fx, Q14, M + 1);
+ st->old_Es_pred_fx = float_to_fix16(st->old_Es_pred, Q8);
+ floatToFixed_arr(st->mem_pitch_gain_float, st->mem_pitch_gain, Q14, 2 * NB_SUBFR16k + 2);
+ floatToFixed_arr(st->mem_syn_r_float, st->mem_syn_r, st->Q_syn, L_SYN_MEM);
+ floatToFixed_arr(st->bpf_noise_buf_float, st->bpf_noise_buf, st->Q_syn, L_FRAME16k);
+ st->prev_tilt_code_dec_fx = float_to_fix16(st->prev_tilt_code_dec, Q15);
+ st->last_coder_type_fx = st->last_coder_type;
+#endif
+}
+
+static void acelp_decoder_state_fix2float(Decoder_State *st, STEREO_CNG_DEC_HANDLE hStereoCng) {
+ Word16 i;
+ st->coder_type = st->coder_type_fx;
+ st->last_coder_type = st->last_coder_type;
+ st->last_core_from_bs = st->last_core_bs_fx;
+ st->prev_Q_syn = st->Q_syn;
+ st->Q_syn2 = st->Q_syn;
+#if 1
+ fixedToFloat_arr(st->lsp_old_fx, st->lsp_old, Q15, M);
+ fixedToFloat_arr(st->lspCNG_fx, st->lspCNG, Q15, M);
+ st->lp_ener = fixedToFloat(st->lp_ener_fx, Q6);
+ for (i = 0; i < M; i++) {
+ st->lsf_old[i] = st->lsf_old_fx[i] / 2.56f;
+ st->mem_MA[i] = st->mem_MA_fx[i] / 2.56f;
+ st->mem_AR[i] = st->mem_AR_fx[i] / 2.56f;
+ st->lsfoldbfi1[i] = st->lsfoldbfi1_fx[i] / 2.56f;
+ st->lsfoldbfi0[i] = st->lsfoldbfi0_fx[i] / 2.56f;
+ st->lsf_adaptive_mean[i] = st->lsf_adaptive_mean_fx[i] / 2.56f;
+ }
+ fixedToFloat_arr(st->old_exc_fx, st->old_exc, st->Q_exc, L_EXC_MEM_DEC);
+ fixedToFloat_arr(st->mem_syn1_fx, st->mem_syn1, -1, M);
+ fixedToFloat_arr(st->mem_syn2_fx, st->mem_syn2, st->Q_syn, M);
+ fixedToFloat_arr(st->mem_syn3_fx, st->mem_syn3, st->Q_syn_cng, M);
+ fixedToFloat_arr(st->mem_syn_r, st->mem_syn_r_float, st->Q_syn, L_SYN_MEM);
+ fixedToFloat_arrL(st->old_pitch_buf_fx, st->old_pitch_buf, Q16, 2 * NB_SUBFR16k + 2);
+ st->mem_preemp_preQ = fixedToFloat(st->mem_preemp_preQ_fx, Q10);
+ st->bfi_pitch = fixedToFloat(st->bfi_pitch_fx, Q6);
+ if (hStereoCng) {
+ fixedToFloat_arr(hStereoCng->olapBufferSynth22_fx, hStereoCng->olapBufferSynth22, st->Q_syn, FFTLEN);
+ }
+ st->mem_deemph = fixedToFloat(st->mem_deemph_fx, st->Q_syn);
+ fixedToFloat_arr(st->agc_mem_fx, st->agc_mem2, st->Q_syn - 1, 2);
+
+ /*Flags (should be unified!)*/
+ st->last_nq_preQ = st->last_nq_preQ_fx;
+ st->safety_net = st->safety_net_fx;
+ st->nelp_mode_dec = st->nelp_mode_dec_fx;
+ st->last_nelp_mode_dec = st->last_nelp_mode_dec_fx;
+ st->ppp_mode_dec = st->ppp_mode_dec_fx;
+ st->relax_prev_lsf_interp = st->relax_prev_lsf_interp_fx;
+ st->last_good = st->last_good_fx;
+ st->unv_cnt = st->unv_cnt_fx;
+ st->uv_count = st->uv_count_fx;
+ st->act_count = st->act_count_fx;
+ st->GSC_noisy_speech = st->GSC_noisy_speech_fx;
+ st->Last_GSC_noisy_speech_flag = st->Last_GSC_noisy_speech_flag_fx;
+ st->mid_lsf_int = st->mid_lsf_int_fx;
+ st->old_bfi_cnt_fx = st->old_bfi_cnt;
+
+ /* dec_exc */
+ st->lp_gainc = fixedToFloat(st->lp_gainc_fx, Q3);
+ st->tilt_code = fixedToFloat(st->tilt_code_fx, Q15);
+ fixedToFloat_arr(st->tilt_code_dec_fx, st->tilt_code_dec, Q15, NB_SUBFR16k);
+ st->dispMem[0] = fixedToFloat(st->dm_fx.prev_state, 0);
+ st->dispMem[1] = fixedToFloat(st->dm_fx.prev_gain_code, Q16);
+ fixedToFloat_arr(st->dm_fx.prev_gain_pit, &(st->dispMem[2]), Q14, 6);
+ st->gc_threshold = fixedToFloat(st->gc_threshold_fx, Q16);
+ st->stab_fac = fixedToFloat(st->stab_fac_fx, Q15);
+ st->prev_gain_pit_dec = fixedToFloat(st->prev_gain_pit_dec_fx, Q14);
+ st->prev_tilt_code_dec = fixedToFloat(st->prev_tilt_code_dec_fx, Q15);
+ st->lp_gainp = fixedToFloat(st->lp_gainp_fx, Q14);
+ st->lp_gainc = fixedToFloat(st->lp_gainc_fx, Q3);
+ st->past_gpit_float = fixedToFloat(st->past_gpit, Q14);
+
+ /* Bad frame */
+ fixedToFloat_arr(st->lspold_s_fx, st->lspold_s, Q15, M);
+ fixedToFloat_arr(st->mem_pitch_gain, st->mem_pitch_gain_float, Q14, 2 * NB_SUBFR16k + 2);
+ st->min_alpha = fixedToFloat(st->min_alpha_fx, Q15);
+ st->ge_sm = fixedToFloat(st->ge_sm_fx, st->Q_stat_noise_ge);
+ st->last_voice_factor = fixedToFloat(st->last_voice_factor_fx, Q15);
+ st->exc_pe = fixedToFloat(st->exc_pe_fx, st->Q_stat_noise);
+
+
+ /* After dec_exc */
+ st->lp_ener_bfi = fixedToFloat(st->lp_ener_FER_fx, Q8);
+ st->enr_old = fixedToFloat(st->enr_old_fx, 0);
+ st->old_enr_LP_float = fixedToFloat(st->old_enr_LP, Q3);
+ st->lp_ener_FEC_av_float = fixedToFloat(st->lp_ener_FEC_av, 0);
+ st->lp_ener_FEC_max_float = fixedToFloat(st->lp_ener_FEC_max, 0);
+ fixedToFloat_arr(st->mem_syn_clas_estim_fx, st->mem_syn_clas_estim, st->classifier_Q_mem_syn, L_SYN_MEM_CLAS_ESTIM);
+ st->psf_lp_noise = fixedToFloat(st->psf_lp_noise_fx, Q8);
+ st->lp_noise_float = fixedToFloat(st->lp_noise, Q23);
+ fixedToFloat_arr(st->syn, st->syn_float, 0, M + 1);
+ fixedToFloat_arr(st->lspold_cng, st->lspold_cng_float, Q15, M);
+
+ /* CLDFB */
+ Word16 new_len;
+ new_len = 9 * (int16_t)(st->L_frame * FRAMES_PER_SEC * INV_CLDFB_BANDWIDTH + 0.5f);
+ fixedToFloat_arrL(st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_state, Q11, new_len);
+ fixedToFloat_arrL(st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_state, Q10, new_len);
+
+ st->stab_fac_smooth = fixedToFloat(st->stab_fac_smooth_fx, Q15);
+
+ //hBPF
+ if (st->hBPF) {
+ fixedToFloat_arr(st->hBPF->pst_old_syn_fx, st->hBPF->pst_old_syn, st->Q_syn2 - 1, NBPSF_PIT_MAX);
+ st->hBPF->pst_mem_deemp_err = fixedToFloat(st->hBPF->pst_mem_deemp_err_fx, st->Q_syn2 - 1);
+ fixedToFloat_arr(st->hBPF->mem_mean_pit_fx, st->hBPF->mem_mean_pit, Q4, L_TRACK_HIST);
+ Copy(st->hBPF->Track_on_hist_fx, st->hBPF->Track_on_hist, L_TRACK_HIST);
+ Copy(st->hBPF->vibrato_hist_fx, st->hBPF->vibrato_hist, L_TRACK_HIST);
+ st->hBPF->pst_lp_ener = fixedToFloat(st->hBPF->pst_lp_ener_fx, Q8);
+ st->hBPF->psf_att = fixedToFloat(st->hBPF->psf_att_fx, Q15);
+ }
+
+ //FdCng
+ if ( st->hFdCngDec )
+ {
+ fixedToFloat_arrL( st->hFdCngDec->hFdCngCom->sidNoiseEst, st->hFdCngDec->hFdCngCom->sidNoiseEst_flt, Q31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp, NPART );
+ fixedToFloat_arrL(st->hFdCngDec->hFdCngCom->sidNoiseEstLp, st->hFdCngDec->hFdCngCom->sidNoiseEstLp_flt, Q31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp, NPART);
+ fixedToFloat_arrL( st->hFdCngDec->hFdCngCom->cngNoiseLevel, st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt, Q31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp, FFTCLDFBLEN );
+ fixedToFloat_arr( st->hFdCngDec->hFdCngCom->A_cng, st->hFdCngDec->hFdCngCom->A_cng_flt, Q12, M + 1 );
+ fixedToFloat_arr(st->hFdCngDec->hFdCngCom->exc_cng, st->hFdCngDec->hFdCngCom->exc_cng_flt, st->Q_exc_cng, L_FRAME16k);
+ //fixedToFloat_arrL(st->hFdCngDec->hFdCngCom->fftBuffer, st->hFdCngDec->hFdCngCom->fftBuffer_flt, st->Q_exc, FFTLEN);
+ fixedToFloat_arr(st->hFdCngDec->hFdCngCom->timeDomainBuffer, st->hFdCngDec->hFdCngCom->timeDomainBuffer_flt, 0, L_FRAME16k);
+ fixedToFloat_arr(st->hFdCngDec->hFdCngCom->olapBufferSynth, st->hFdCngDec->hFdCngCom->olapBufferSynth_flt, st->hFdCngDec->hFdCngCom->fftlenShift, FFTLEN);
+ fixedToFloat_arr(st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, st->hFdCngDec->hFdCngCom->fftlenShift, FFTLEN);
+ st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt = fixedToFloat(st->hFdCngDec->hFdCngCom->likelihood_noisy_speech, Q15);
+ fixedToFloat_arrL(st->hFdCngDec->bandNoiseShape, st->hFdCngDec->bandNoiseShape_float, Q31 - st->hFdCngDec->bandNoiseShape_exp, FFTLEN2);
+ fixedToFloat_arrL(st->hFdCngDec->partNoiseShape, st->hFdCngDec->partNoiseShape_float, Q31 - st->hFdCngDec->partNoiseShape_exp, NPART);
+
+ /*CNA: ApplyFdCng*/
+ if ((st->hFdCngDec != NULL || st->idchan == 1) && st->element_mode != IVAS_CPE_MDCT)
+ {
+ if (st->element_mode == IVAS_CPE_TD || st->flag_cna || (st->cng_type == FD_CNG && st->total_brate <= ACELP_32k) || (st->cng_type == LP_CNG && st->core_brate <= SID_2k40))
+ {
+ if (st->element_mode != IVAS_CPE_TD && !st->cng_ism_flag)
+ {
+ if (
+ ((st->m_frame_type == ACTIVE_FRAME) && ((st->bfi == 0 &&
+ ((((st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT && st->hFdCngDec->flag_dtx_mode) || !st->VAD || (st->ini_frame < 100 && st->is_ism_format)) &&
+ !(st->cng_type == LP_CNG && st->hFdCngDec->flag_dtx_mode)) ||
+ (st->element_mode == IVAS_CPE_TD)) &&
+ (!st->BER_detect)) ||
+ ((st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT) && (st->hFdCngDec->hFdCngCom->active_frame_counter > 0)) || ((st->bfi == 1) && (st->nbLostCmpt == 1)))) ||
+ (st->m_frame_type == ZERO_FRAME) && (st != NULL && st->cng_type == LP_CNG)
+ )
+ {
+ fixedToFloat_arrL(st->hFdCngDec->hFdCngCom->periodog, st->hFdCngDec->hFdCngCom->periodog_flt, Q31 - st->hFdCngDec->hFdCngCom->periodog_exp, PERIODOGLEN);
+ fixedToFloat_arrL(st->hFdCngDec->hFdCngCom->fftBuffer, st->hFdCngDec->hFdCngCom->fftBuffer_flt, Q31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp, st->hFdCngDec->hFdCngCom->fftlen);
+ fixedToFloat_arrL(st->hFdCngDec->msPsd_fx, st->hFdCngDec->msPsd_float, Q31 - st->hFdCngDec->msPsd_exp_fft, st->hFdCngDec->npart_shaping);
+ fixedToFloat_arrL(st->hFdCngDec->msNoiseEst, st->hFdCngDec->msNoiseEst_float, Q31 - st->hFdCngDec->msNoiseEst_exp, st->hFdCngDec->npart_shaping);
+ fixedToFloat_arrL(st->hFdCngDec->msPeriodog, st->hFdCngDec->msPeriodog_float, Q31 - st->hFdCngDec->msPeriodog_exp, st->hFdCngDec->npart_shaping);
+ fixedToFloat_arrL(st->hFdCngDec->msPeriodog_ST_fx, st->hFdCngDec->msPeriodog_ST, Q31 - st->hFdCngDec->msPeriodog_ST_exp, st->hFdCngDec->npart_shaping);
+ if (st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT)
+ {
+ fixedToFloat_arrL(st->hFdCngDec->smoothed_psd_fx, st->hFdCngDec->smoothed_psd, Q31 - st->hFdCngDec->msNoiseEst_exp, L_FRAME16k - st->hFdCngDec->hFdCngCom->startBand);
+ }
+ if (!((st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT) && (st->hFdCngDec->hFdCngCom->active_frame_counter > 0)))
+ {
+ st->hTcxDec->CngLevelBackgroundTrace_bfi = fixedToFloat(st->hTcxDec->CngLevelBackgroundTrace_bfi_fx, (31 - st->hTcxDec->CngLevelBackgroundTrace_bfi_exp));
+ st->cngTDLevel_float = fixedToFloat(st->cngTDLevel, (15 - st->cngTDLevel_e));
+ IF(!(EQ_16(st->element_mode, IVAS_CPE_TD) || EQ_16(st->element_mode, IVAS_CPE_DFT)))
+ {
+ for (int p = 0; p < MSNUMSUBFR * NPART_SHAPING; p++)
+ {
+ if ((st->hFdCngDec->msMinBuf[p] == MAX_32))
+ {
+ st->hFdCngDec->msMinBuf_float[p] = FLT_MAX;
+ }
+ else
+ {
+ st->hFdCngDec->msMinBuf_float[p] = (float)st->hFdCngDec->msMinBuf[p] / (1u << (31 - 6)); // CNG_S = 6
+ }
+ }
+ fixedToFloat_arr(st->hFdCngDec->msPeriodogBuf, st->hFdCngDec->msPeriodogBuf_float, Q9, st->hFdCngDec->npart_shaping);
+ fixedToFloat_arr(st->hFdCngDec->msPsdFirstMoment, st->hFdCngDec->msPsdFirstMoment_float, Q9, st->hFdCngDec->npart_shaping);
+ fixedToFloat_arrL(st->hFdCngDec->msPsdSecondMoment, st->hFdCngDec->msPsdSecondMoment_float, Q19, st->hFdCngDec->npart_shaping);
+ fixedToFloat_arr(st->hFdCngDec->msNoiseFloor, st->hFdCngDec->msNoiseFloor_float, Q9, st->hFdCngDec->npart_shaping);
+ fixedToFloat_arrL(st->hFdCngDec->msAlpha, st->hFdCngDec->msAlpha_float, Q31, st->hFdCngDec->npart_shaping);
+ fixedToFloat_arrL(st->hFdCngDec->msBminWin, st->hFdCngDec->msBminWin_float, Q27, st->hFdCngDec->npart_shaping);
+ fixedToFloat_arrL(st->hFdCngDec->msBminSubWin, st->hFdCngDec->msBminSubWin_float, Q27, st->hFdCngDec->npart_shaping);
+ for (int p = 0; p < st->hFdCngDec->npart_shaping; p++)
+ {
+ if (st->hFdCngDec->msCurrentMin[p] == MAX_32)
+ {
+ st->hFdCngDec->msCurrentMin_float[p] = FLT_MAX;
+ }
+ else
+ {
+ st->hFdCngDec->msCurrentMin_float[p] = ((float)st->hFdCngDec->msCurrentMin[p] / (1u << (31 - (6 + 1 + 4)))); // exp : CNG_S + 1 + 4
+ }
+ if (st->hFdCngDec->msCurrentMinOut[p] == MAX_32)
+ {
+ st->hFdCngDec->msCurrentMinOut_float[p] = FLT_MAX;
+ }
+ else
+ {
+ st->hFdCngDec->msCurrentMinOut_float[p] = ((float)st->hFdCngDec->msCurrentMinOut[p] / (1u << (31 - 6)));
+ }
+ if (st->hFdCngDec->msCurrentMinSubWindow[p] == MAX_32)
+ {
+ st->hFdCngDec->msCurrentMinSubWindow_float[p] = FLT_MAX;
+ }
+ else
+ {
+ st->hFdCngDec->msCurrentMinSubWindow_float[p] = ((float)st->hFdCngDec->msCurrentMinSubWindow[p] / (1u << (31 - 6)));
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ //TdCng
+ if (st->hTdCngDec)
+ {
+ st->hTdCngDec->old_enr_index = st->hTdCngDec->old_enr_index_fx;
+ st->hTdCngDec->Enew = fixedToFloat(st->hTdCngDec->Enew_fx, Q6);
+ st->hTdCngDec->ho_hist_ptr = st->hTdCngDec->ho_hist_ptr_fx;
+ st->hTdCngDec->ho_hist_size = st->hTdCngDec->ho_hist_size_fx;
+ st->hTdCngDec->num_ho = st->hTdCngDec->num_ho_fx;
+ st->hTdCngDec->act_cnt2 = st->hTdCngDec->act_cnt2_fx;
+ st->hTdCngDec->act_cnt = st->hTdCngDec->act_cnt_fx;
+ st->hTdCngDec->ho_circ_ptr = st->hTdCngDec->ho_circ_ptr_fx;
+ st->hTdCngDec->ho_circ_size = st->hTdCngDec->ho_circ_size_fx;
+ Copy(st->hTdCngDec->ho_16k_lsp_fx, st->hTdCngDec->ho_16k_lsp, HO_HIST_SIZE);
+ fixedToFloat_arr(st->hTdCngDec->ho_lsp_circ_fx, st->hTdCngDec->ho_lsp_circ, Q15, HO_HIST_SIZE * M);
+ fixedToFloat_arr(st->hTdCngDec->ho_lsp_hist_fx, st->hTdCngDec->ho_lsp_hist, Q15, HO_HIST_SIZE * M);
+ fixedToFloat_arrL(st->hTdCngDec->ho_ener_circ_fx, st->hTdCngDec->ho_ener_circ, Q6, HO_HIST_SIZE);
+ fixedToFloat_arrL(st->hTdCngDec->ho_ener_hist_fx, st->hTdCngDec->ho_ener_hist, Q6, HO_HIST_SIZE);
+ st->hTdCngDec->ho_sid_bw = (Word16) st->hTdCngDec->ho_sid_bw_fx;
+ fixedToFloat_arrL(st->hTdCngDec->ho_env_circ_fx, st->hTdCngDec->ho_env_circ, Q6, HO_HIST_SIZE * NUM_ENV_CNG);
+ fixedToFloat_arrL(st->hTdCngDec->ho_env_hist_fx, st->hTdCngDec->ho_env_hist, Q6, HO_HIST_SIZE * NUM_ENV_CNG);
+ fixedToFloat_arrL(st->hTdCngDec->old_env_fx, st->hTdCngDec->old_env, Q6, 20);
+ fixedToFloat_arrL(st->hTdCngDec->lp_env_fx, st->hTdCngDec->lp_env, Q6, 20);
+ fixedToFloat_arr(st->hTdCngDec->exc_mem_fx, st->hTdCngDec->exc_mem, st->Q_exc, 24);
+ fixedToFloat_arr(st->hTdCngDec->exc_mem1_fx, st->hTdCngDec->exc_mem1, st->Q_exc, 30);
+ }
+
+ /*PFSTAT_HANDLE*/
+ if (st->hPFstat) {
+ fixedToFloat_arr(st->hPFstat->mem_pf_in, st->hPFstat->mem_pf_in_flt, st->Q_syn, L_SUBFR);
+ fixedToFloat_arr(st->hPFstat->mem_stp, st->hPFstat->mem_stp_flt, st->Q_syn, L_SUBFR);
+ fixedToFloat_arr(st->hPFstat->mem_res2, st->hPFstat->mem_res2_flt, st->Q_syn, DECMEM_RES2);
+ fixedToFloat_arr(st->hPFstat->mem_zero, st->hPFstat->mem_zero_flt, st->Q_syn, M);
+ st->hPFstat->gain_prec_flt = fixedToFloat(st->hPFstat->gain_prec, Q14);
+ }
+
+ /*WI_DEC_HANDLE*/
+ if (st->hWIDec) {
+ fixedToFloat_arr(st->hWIDec->old_exc2_fx, st->hWIDec->old_exc2, st->prev_Q_exc_fr, L_EXC_MEM);
+ fixedToFloat_arr(st->hWIDec->old_syn2_fx, st->hWIDec->old_syn2, st->prev_Q_syn_fr, L_EXC_MEM);
+ }
+
+ /*TD_BWE_DEC_HANDLE*/
+ if (st->hBWE_TD) {
+ fixedToFloat_arr(st->hBWE_TD->old_bwe_exc_fx, st->hBWE_TD->old_bwe_exc, st->Q_exc, PIT16k_MAX * 2);
+ fixedToFloat_arr(st->hBWE_TD->cur_sub_Aq_fx, st->hBWE_TD->cur_sub_Aq, Q12, M + 1);
+ }
+
+ /*GSC_DEC_HANDLE*/
+ if (st->hGSCDec) {
+ st->hGSCDec->Last_frame_ener = fixedToFloat(st->hGSCDec->Last_frame_ener_fx, 0);
+ st->hGSCDec->seed_tcx = st->hGSCDec->seed_tcx_fx;
+ st->hGSCDec->cor_strong_limit = st->hGSCDec->cor_strong_limit_fx;
+ fixedToFloat_arr(st->hGSCDec->old_y_gain_fx, st->hGSCDec->old_y_gain, Q12, MBANDS_GN16k);
+ st->hGSCDec->noise_lev = st->hGSCDec->noise_lev_fx;
+ fixedToFloat_arr(st->hGSCDec->lt_ener_per_band_fx, st->hGSCDec->lt_ener_per_band, Q12, MBANDS_GN16k);
+ fixedToFloat_arr(st->hGSCDec->Last_GSC_spectrum_fx, st->hGSCDec->Last_GSC_spectrum, Q10, L_FRAME16k);
+ st->hGSCDec->Last_GSC_pit_band_idx = st->hGSCDec->Last_GSC_pit_band_idx_fx;
+ fixedToFloat_arr(st->hGSCDec->last_exc_dct_in_fx, st->hGSCDec->last_exc_dct_in, st->Q_exc, L_FRAME16k);
+ st->hGSCDec->last_ener = fixedToFloat(st->hGSCDec->last_ener_fx, 0);
+ Copy(st->hGSCDec->last_bitallocation_band_fx, st->hGSCDec->last_bitallocation_band, 6);
+ }
+
+ /*TCX_DEC_HANDLE*/
+ if (st->hTcxDec) {
+ fixedToFloat_arr(st->hTcxDec->syn_Overl, st->hTcxDec->syn_Overl_float, 0, L_FRAME32k / 2);
+ fixedToFloat_arr(st->hTcxDec->old_syn_Overl, st->hTcxDec->old_syn_Overl_float, -1, st->L_frame / 2);
+ }
+
+ /*MUSIC_POSTFILT_HANDLE*/
+ if (st->hMusicPF) {
+ fixedToFloat_arr(st->hMusicPF->dct_post_old_exc_fx, st->hMusicPF->dct_post_old_exc, st->Q_exc, DCT_L_POST - OFFSET2);
+ fixedToFloat_arr(st->hMusicPF->filt_lfE_fx, st->hMusicPF->filt_lfE, Q15, DCT_L_POST);
+ fixedToFloat_arr(st->hMusicPF->LDm_enh_lp_gbin_fx, st->hMusicPF->LDm_enh_lp_gbin, Q14, VOIC_BINS_HR);
+ st->hMusicPF->LDm_enh_min_ns_gain = fixedToFloat(st->hMusicPF->LDm_enh_min_ns_gain_fx, Q15);
+ fixedToFloat_arrL(st->hMusicPF->LDm_enh_lf_EO_fx, st->hMusicPF->LDm_enh_lf_EO, Q10, VOIC_BINS_HR);
+ fixedToFloat_arr(st->hMusicPF->LDm_lt_diff_etot_fx, st->hMusicPF->LDm_lt_diff_etot, Q15, MAX_LT);
+ st->hMusicPF->LDm_mem_etot = fixedToFloat(st->hMusicPF->LDm_mem_etot_fx, Q8);
+ st->hMusicPF->LDm_nb_thr_3 = st->hMusicPF->LDm_nb_thr_3_fx;
+ st->hMusicPF->LDm_nb_thr_1 = st->hMusicPF->LDm_nb_thr_1_fx;
+ fixedToFloat_arr(st->hMusicPF->LDm_thres_fx, st->hMusicPF->LDm_thres, Q12, 4);
+ st->hMusicPF->LDm_last_music_flag = st->hMusicPF->LDm_last_music_flag_fx;
+ st->hMusicPF->last_nonfull_music = st->hMusicPF->last_nonfull_music_fx;
+ fixedToFloat_arrL(st->hMusicPF->LDm_bckr_noise_fx, st->hMusicPF->LDm_bckr_noise, Q10, MBANDS_GN_LD);
+ }
+
+ /*FD_BWE_DEC_HANDLE*/
+ if (st->hBWE_FD) {
+ fixedToFloat_arr(st->hBWE_FD->old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k, -1, NS2SA(16000, DELAY_FD_BWE_ENC_NS));
+ st->hBWE_FD->mem_deemph_old_syn = fixedToFloat(st->hBWE_FD->mem_deemph_old_syn_fx, -1);
+ }
+
+#else
+ Word32 i;
+ for (i = 0; i < M; i++) {
+ st->lsf_old[i] = st->lsf_old_fx[i] / 2.56f;
+ st->mem_MA[i] = st->mem_MA_fx[i] / 2.56f;
+ st->mem_AR[i] = st->mem_AR_fx[i] / 2.56f;
+ st->lsfoldbfi1[i] = st->lsfoldbfi1_fx[i] / 2.56f;
+ st->lsfoldbfi0[i] = st->lsfoldbfi0_fx[i] / 2.56f;
+ st->lsf_adaptive_mean[i] = st->lsf_adaptive_mean_fx[i] / 2.56f;
+ }
+ fixedToFloat_arr(st->lsp_old_fx, st->lsp_old, Q15, M);
+ st->tilt_code = fixedToFloat(st->tilt_code_fx, Q15);
+ fixedToFloat_arr(st->old_exc_fx, st->old_exc, st->Q_exc, L_EXC_MEM_DEC);
+ fixedToFloat_arr(st->mem_syn1_fx, st->mem_syn1, -1, M);
+ fixedToFloat_arr(st->mem_syn2_fx, st->mem_syn2, st->Q_syn, M);
+ fixedToFloat_arr(st->mem_syn3_fx, st->mem_syn3, st->Q_syn, M);
+ st->mem_deemph = fixedToFloat(st->mem_deemph_fx, st->Q_syn);
+ st->stab_fac = fixedToFloat(st->stab_fac_fx, Q15);
+ st->stab_fac_smooth = fixedToFloat(st->stab_fac_smooth_fx, Q15);
+ fixedToFloat_arr(st->agc_mem_fx, st->agc_mem2, st->Q_syn - 1, 2);
+ //st->mid_lsf_int = st->mid_lsf_int_fx;
+ st->safety_net = st->safety_net_fx;
+ //st->GSC_noisy_speech = st->GSC_noisy_speech_fx;
+ //st->Last_GSC_noisy_speech_flag = st->Last_GSC_noisy_speech_flag_fx;
+ st->gc_threshold = fixedToFloat(st->gc_threshold_fx, Q16);
+ st->dispMem[0] = fixedToFloat(st->dm_fx.prev_state, 0);
+ st->dispMem[1] = fixedToFloat(st->dm_fx.prev_gain_code, Q16);
+ fixedToFloat_arr(st->dm_fx.prev_gain_pit, &(st->dispMem[2]), Q14, 6);
+ //st->unv_cnt = st->unv_cnt_fx;
+ //st->uv_count = st->uv_count_fx;
+ //st->act_count = st->act_count_fx;
+ st->ge_sm = fixedToFloat(st->ge_sm_fx, st->Q_stat_noise_ge);
+ fixedToFloat_arr(st->lspold_s_fx, st->lspold_s, Q15, M);
+ //st->noimix_seed = st->noimix_seed_fx;
+ st->min_alpha = fixedToFloat(st->min_alpha_fx, Q15);
+ st->exc_pe = fixedToFloat(st->exc_pe_fx, st->Q_stat_noise);
+ st->lp_gainp = fixedToFloat(st->lp_gainp_fx, Q14);
+ st->lp_gainc = fixedToFloat(st->lp_gainc_fx, Q3);
+ st->lp_ener = fixedToFloat(st->lp_ener_fx, Q6);
+ st->enr_old = fixedToFloat(st->enr_old_fx, 0);
+ st->bfi_pitch = fixedToFloat(st->bfi_pitch_fx, Q6);
+ fixedToFloat_arrL(st->old_pitch_buf_fx, st->old_pitch_buf, Q16, 2 * NB_SUBFR16k + 2);
+ st->lp_ener_FEC_av_float = fixedToFloat(st->lp_ener_FEC_av, 0);
+ st->lp_ener_FEC_max_float = fixedToFloat(st->lp_ener_FEC_max, 0);
+ st->old_enr_LP_float = fixedToFloat(st->old_enr_LP, st->Q_exc);
+ //st->last_good = st->last_good_fx;
+ st->lp_ener_bfi = fixedToFloat(st->lp_ener_FER_fx, Q8);
+ //st->relax_prev_lsf_interp = st->relax_prev_lsf_interp_fx;
+ fixedToFloat_arr(st->mem_syn_clas_estim_fx, st->mem_syn_clas_estim, st->Q_syn, L_SYN_MEM_CLAS_ESTIM);
+ // cldfbAna
+ // cldfbBPF
+ // cldfbSyn
+ st->perc_bwddec_float = fixedToFloat(st->perc_bwddec, Q14);
+ st->avg_nrg_LT_float = fixedToFloat(st->avg_nrg_LT, 0);
+ st->ng_ener_ST = fixedToFloat(st->Ng_ener_ST_fx, Q8);
+ st->mem_preemp_preQ = fixedToFloat(st->mem_preemp_preQ_fx, 0);
+ //st->last_nq_preQ = st->last_nq_preQ_fx;
+ st->psf_lp_noise = fixedToFloat(st->psf_lp_noise_fx, Q8);
+ st->last_voice_factor = fixedToFloat(st->last_voice_factor_fx, Q15);
+ fixedToFloat_arr(st->hTcxDec->old_syn_Overl, st->hTcxDec->old_syn_Overl_float, -1, st->L_frame / 2);
+ fixedToFloat_arr(st->Aq_cng, st->Aq_cng_float, 0, (NB_SUBFR16k + 1)*(M + 1));
+ fixedToFloat_arr(st->hBWE_TD->old_bwe_exc_fx, st->hBWE_TD->old_bwe_exc, st->Q_exc, PIT16k_MAX * 2);
+ fixedToFloat_arr(st->hBWE_TD->cur_sub_Aq_fx, st->hBWE_TD->cur_sub_Aq, Q14, M + 1);
+ fixedToFloat_arr(st->syn, st->syn_float, 0, M + 1);
+ /*GSC_DEC_HANDLE*/
+ if (st->hGSCDec) {
+ st->hGSCDec->seed_tcx = st->hGSCDec->seed_tcx_fx;
+ st->hGSCDec->cor_strong_limit = st->hGSCDec->cor_strong_limit_fx;
+ fixedToFloat_arr(st->hGSCDec->old_y_gain_fx, st->hGSCDec->old_y_gain, Q15, MBANDS_GN);
+ st->hGSCDec->noise_lev = st->hGSCDec->noise_lev_fx;
+ fixedToFloat_arr(st->hGSCDec->lt_ener_per_band_fx, st->hGSCDec->lt_ener_per_band, Q12, MBANDS_GN);
+ st->hGSCDec->Last_frame_ener = fixedToFloat(st->hGSCDec->Last_frame_ener_fx, 0);
+ fixedToFloat_arr(st->hGSCDec->Last_GSC_spectrum_fx, st->hGSCDec->Last_GSC_spectrum, Q10, L_FRAME);
+ st->hGSCDec->Last_GSC_pit_band_idx = st->hGSCDec->Last_GSC_pit_band_idx_fx;
+ fixedToFloat_arr(st->hGSCDec->last_exc_dct_in_fx, st->hGSCDec->last_exc_dct_in, st->Q_exc, L_FRAME);
+ st->hGSCDec->last_ener = fixedToFloat(st->hGSCDec->last_ener_fx, Q8);
+ Copy(st->hGSCDec->last_bitallocation_band_fx, st->hGSCDec->last_bitallocation_band, 6);
+ }
+ /*ZERO_BWE_DEC_HANDLE*/
+ if (st->hBWE_zero) {
+ st->hBWE_zero->seed2 = st->hBWE_zero->seed2_fx;
+ fixedToFloat_arr(st->hBWE_zero->mem_hp400_fx, st->hBWE_zero->mem_hp400, st->Q_syn, 4);
+ fixedToFloat_arr(st->hBWE_zero->mem_hf_fx, st->hBWE_zero->mem_hf, st->Q_syn, L_FIR - 1);
+ fixedToFloat_arr(st->hBWE_zero->mem_syn_hf_fx, st->hBWE_zero->mem_syn_hf, st->Q_syn, M);
+ fixedToFloat_arr(st->hBWE_zero->delay_syn_hf_fx, st->hBWE_zero->delay_syn_hf, st->Q_syn, NS2SA(16000, DELAY_CLDFB_NS));
+ fixedToFloat_arr(st->hBWE_zero->mem_hp_interp_fx, st->hBWE_zero->mem_hp_interp, st->Q_syn, INTERP_3_1_MEM_LEN);
+ }
+ /*WI_DEC_HANDLE*/
+ if (st->hWIDec) {
+ fixedToFloat_arr(st->hWIDec->old_exc2_fx, st->hWIDec->old_exc2, st->Q_exc, L_EXC_MEM);
+ fixedToFloat_arr(st->hWIDec->old_syn2_fx, st->hWIDec->old_syn2, st->Q_syn, L_EXC_MEM);
+ }
+ /*BPF_DEC_HANDLE*/
+ if (st->hBPF) {
+ fixedToFloat_arr(st->hBPF->pst_old_syn_fx, st->hBPF->pst_old_syn, st->Q_syn, NBPSF_PIT_MAX);
+ st->hBPF->pst_mem_deemp_err = fixedToFloat(st->hBPF->pst_mem_deemp_err_fx, st->Q_syn);
+ st->hBPF->pst_lp_ener = fixedToFloat(st->hBPF->pst_lp_ener_fx, Q8);
+ Copy(st->hBPF->Track_on_hist_fx, st->hBPF->Track_on_hist, L_TRACK_HIST);
+ Copy(st->hBPF->vibrato_hist_fx, st->hBPF->vibrato_hist, L_TRACK_HIST);
+ st->hBPF->psf_att = fixedToFloat(st->hBPF->psf_att_fx, Q15);
+ fixedToFloat_arr(st->hBPF->mem_mean_pit_fx, st->hBPF->mem_mean_pit, Q4, L_TRACK_HIST);
+ }
+ /*PFSTAT_HANDLE*/
+ if (st->hPFstat) {
+ fixedToFloat_arr(st->hPFstat->mem_pf_in, st->hPFstat->mem_pf_in_flt, st->Q_syn, L_SUBFR);
+ fixedToFloat_arr(st->hPFstat->mem_stp, st->hPFstat->mem_stp_flt, st->Q_syn, L_SUBFR);
+ fixedToFloat_arr(st->hPFstat->mem_res2, st->hPFstat->mem_res2_flt, st->Q_syn, DECMEM_RES2);
+ fixedToFloat_arr(st->hPFstat->mem_res2, st->hPFstat->mem_res2_flt, st->Q_syn, M);
+ st->hPFstat->gain_prec_flt = fixedToFloat(st->hPFstat->gain_prec, Q14);
+ }
+ /*Missing parameters*/
+ st->prev_gain_pit_dec = fixedToFloat(st->prev_gain_pit_dec_fx, Q14);
+ fixedToFloat_arr(st->tilt_code_dec_fx, st->tilt_code_dec, Q15, NB_SUBFR16k);
+ fixedToFloat_arr(st->previoussynth_fx, st->previoussynth, 0, L_FRAME48k);
+ fixedToFloat_arr(st->old_Aq_12_8_fx, st->old_Aq_12_8, Q14, M + 1);
+ st->old_Es_pred = fixedToFloat(st->old_Es_pred_fx, Q8);
+ fixedToFloat_arr(st->mem_pitch_gain, st->mem_pitch_gain_float, Q14, 2 * NB_SUBFR16k + 2);
+ fixedToFloat_arr(st->mem_syn_r, st->mem_syn_r_float, st->Q_syn, L_SYN_MEM);
+ fixedToFloat_arr(st->bpf_noise_buf, st->bpf_noise_buf_float, st->Q_syn, L_FRAME16k);
+ st->prev_tilt_code_dec = fixedToFloat(st->prev_tilt_code_dec_fx, Q15);
+ st->last_coder_type = st->last_coder_type_fx;
+#endif
+}
+
+static void rescale_fdCngDec(HANDLE_FD_CNG_DEC hFdCngDec, Word16 Exp_diff) {
+ Scale_sig32(hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, Exp_diff);
+ /*Scale_sig32(hFdCngDec->hFdCngCom->sidNoiseEst, NPART, -Exp_diff);
+ hFdCngDec->hFdCngCom->sidNoiseEstExp += Exp_diff;
+ Scale_sig32(hFdCngDec->hFdCngCom->cngNoiseLevel, NPART, -Exp_diff);
+ hFdCngDec->hFdCngCom->cngNoiseLevelExp += Exp_diff;*/
+}
+
+#endif
\ No newline at end of file
diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c
index 8c0e048818e016e93680c836b61f4b16c30d8314..bc698d2b21ec52081c0a1d93efd4bea5eb9a409c 100644
--- a/lib_dec/cng_dec_fx.c
+++ b/lib_dec/cng_dec_fx.c
@@ -6,6 +6,7 @@
#include "options.h" /* Compilation switches */
#include "cnst.h"
#include "rom_com.h"
+#include "prot.h"
#include "prot_fx1.h"
#include "prot_fx2.h"
#include "ivas_cnst.h"
@@ -20,6 +21,10 @@ void E_LPC_f_lsp_a_conversion(const Word16 *isp, Word16 *a, const Word16 m);
static void shb_CNG_decod_fx( Decoder_State *st_fx, const Word16 *synth_fx, Word16 *shb_synth_fx, const Word16 sid_bw,const Word16 Qsyn);
+#ifdef IVAS_FLOAT_FIXED
+static void shb_CNG_decod_ivas_fx( Decoder_State *st_fx, const Word16 *synth_fx, Word16 *shb_synth_fx, const Word16 sid_bw, const Word16 Qsyn );
+#endif
+
/*-----------------------------------------------------------------*
* Decode residual signal energy
*-----------------------------------------------------------------*/
@@ -719,6 +724,45 @@ void swb_CNG_dec_fx(
return;
}
+#ifdef IVAS_FLOAT_FIXED
+void swb_CNG_dec_ivas_fx(
+ Decoder_State *st_fx, /* i/o: State structure */
+ const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz */
+ Word16 *shb_synth_fx, /* o : high-band CNG synthesis */
+ const Word16 sid_bw /* i : 0-NB/WB, 1-SWB SID */
+ ,const Word16 Qsyn /* i : Q value of ACELP core synthesis */
+)
+{
+ test();
+ IF ( st_fx->core_brate == FRAME_NO_DATA || EQ_32(st_fx->core_brate, SID_2k40))
+ {
+ /* SHB SID decoding and CNG */
+ test();
+ IF (st_fx->cng_type == LP_CNG && EQ_16(st_fx->extl, SWB_CNG))
+ {
+ shb_CNG_decod_ivas_fx( st_fx, synth_fx, shb_synth_fx, sid_bw, Qsyn );
+ }
+ st_fx->last_vad_fx = 0;
+ move16();
+ st_fx->hTdCngDec->burst_cnt_fx = 0;
+ move16();
+ }
+ ELSE
+ {
+ st_fx->last_vad_fx = 1;
+ move16();
+ st_fx->hTdCngDec->burst_cnt_fx = add(st_fx->hTdCngDec->burst_cnt_fx, 1);
+ IF ( GT_16(st_fx->hTdCngDec->burst_cnt_fx, 10))
+ {
+ st_fx->hTdCngDec->burst_cnt_fx = 0;
+ move16();
+ }
+ }
+
+ return;
+}
+#endif
+
/*---------------------------------------------------------------------*
* shb_CNG_decod()
*
@@ -996,111 +1040,277 @@ static void shb_CNG_decod_fx(
return;
}
-/*-------------------------------------------------------------------*
- * td_cng_dec_init()
- *
- *
- *-------------------------------------------------------------------*/
-
#ifdef IVAS_FLOAT_FIXED
-void td_cng_dec_init_ivas_fx(
- DEC_CORE_HANDLE st /* i/o: decoder state structure */
+static void shb_CNG_decod_ivas_fx(
+ Decoder_State *st, /* i/o: State structure */
+ const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz */
+ Word16 *shb_synth_fx, /* o : high-band CNG synthesis */
+ const int16_t sid_bw, /* i : 0-NB/WB, 1-SWB SID */
+ const Word16 Qsyn
)
{
- TD_CNG_DEC_HANDLE hTdCngDec;
Word16 i;
+ Word16 idx_ener;
+ Word16 shb_lpcCNG_fx[LPC_SHB_ORDER+1];
+ Word16 shb_lspCNG_fx[LPC_SHB_ORDER];
+ Word16 excTmp_fx[L_FRAME16k];
+ Word16 excSHB_fx[L_FRAME16k];
+ Word16 tmp_lsp[LPC_SHB_ORDER];
+ Word16 ener_excSHB_fx;
+ Word32 wb_ener_fx;
+ Word16 wb_ener16_fx;
+ Word32 L_gain_fx;
+ Word32 gain_fx;
+ Word16 shb_syn16k_fx[L_FRAME16k];
+ Word32 tmp;
+ Word32 step_fx;
+ Word16 interp_fx;
+ Word32 ener_fx;
+ Word16 exp,exp1;
+ Word16 fra;
+ Word32 L_tmp;
+ Word16 allow_cn_step_fx=0;
+ Word16 q;
+ TD_BWE_DEC_HANDLE hBWE_TD;
+ hBWE_TD = st->hBWE_TD;
- hTdCngDec = st->hTdCngDec;
+ IF ( EQ_16(st->bfi, 0) )
+ {
+ IF ( EQ_32(st->core_brate, SID_2k40) && EQ_16(sid_bw, 1) )
+ {
+ idx_ener = get_next_indice( st, 4 );
- hTdCngDec->cng_seed_fx = RANDOM_INITSEED;
- move16();
- hTdCngDec->cng_ener_seed_fx = RANDOM_INITSEED;
- move16();
- hTdCngDec->cng_ener_seed1_fx = RANDOM_INITSEED;
- move16();
- hTdCngDec->old_enr_index_fx = -1;
- move16();
- hTdCngDec->Enew_fx = L_deposit_l( 0 );
- hTdCngDec->last_allow_cn_step_fx = 0;
- move16();
- Copy( st->lsp_old, st->lspCNG, M );
- st->shb_cng_ener_fx = -1541;
- move16();
- IF( st->element_mode != EVS_MONO )
+ IF ( EQ_16(idx_ener, 0) )
+ {
+ idx_ener = -15;
+ move16();
+ }
+
+ /* de-quantization of SHB CNG parameters */
+ IF ( EQ_16(st->element_mode, EVS_MONO) )
+ {
+ st->hTdCngDec->last_shb_cng_ener_fx_32 = L_sub(L_mult0(idx_ener, 6850), 36991); // Q11
+ }
+ ELSE
+ {
+ st->hTdCngDec->last_shb_cng_ener_fx_32 = L_sub(L_mult0(idx_ener, 8807), 36991); // Q11
+ }
+ }
+ }
+
+ /* SHB spectrum estimation */
+ interp_fx = s_min(st->hTdCngDec->shb_dtx_count,32);
+#ifdef BASOP_NOGLOB
+ interp_fx = shl_sat(interp_fx, 10); /*Q15*/
+#else
+ interp_fx = shl(interp_fx, 10); /*Q15*/
+#endif
+
+ FOR ( i = 0; i < LPC_SHB_ORDER; i++ )
{
- set16_fx( hTdCngDec->shb_lpcCNG_fx, 0.0f, LPC_SHB_ORDER + 1 );
- hTdCngDec->shb_lpcCNG_fx[0] = 4096;
- hTdCngDec->shb_cng_gain_fx = -20992; /* a dB value approximately corresponding to shb index 0(used as index -15) */
+ shb_lspCNG_fx[i] = add( mult_r( interp_fx, st->hTdCngDec->lsp_shb_prev_fx[i] ), mult_r( sub( 32767, interp_fx ), st->hTdCngDec->lsp_shb_prev_prev_fx[i]) ); //Q14
}
- st->wb_cng_ener_fx = -1541;
- move16();
- st->last_wb_cng_ener_fx = -1541;
- move16();
- st->last_shb_cng_ener_fx = -1541;
- move16();
- st->swb_cng_seed_fx = RANDOM_INITSEED;
- move16();
- hTdCngDec->ho_hist_ptr_fx = -1;
- move16();
- hTdCngDec->ho_sid_bw_fx = L_deposit_l( 0 );
- set16_fx( hTdCngDec->ho_lsp_hist_fx, 0, HO_HIST_SIZE * M );
- set32_fx( hTdCngDec->ho_ener_hist_fx, 0, HO_HIST_SIZE );
- set32_fx( hTdCngDec->ho_env_hist_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG );
- hTdCngDec->ho_hist_size_fx = 0;
- move16();
- hTdCngDec->act_cnt_fx = 0;
- move16();
- hTdCngDec->ho_circ_ptr_fx = -1;
- move16();
- set16_fx( hTdCngDec->ho_lsp_circ_fx, 0, HO_HIST_SIZE * M );
- set32_fx( hTdCngDec->ho_ener_circ_fx, 0, HO_HIST_SIZE );
- set32_fx( hTdCngDec->ho_env_circ_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG );
- hTdCngDec->ho_circ_size_fx = 0;
- move16();
- set16_fx( hTdCngDec->ho_16k_lsp_fx, 0, HO_HIST_SIZE );
- hTdCngDec->act_cnt2_fx = 0;
- move16();
- hTdCngDec->num_ho_fx = 0;
- move16();
- hTdCngDec->last_cng_type_fx = -1;
- move16();
- set32_fx( hTdCngDec->lp_env_fx, 0, NUM_ENV_CNG );
- set16_fx( hTdCngDec->exc_mem_fx, 0, 24 );
- set16_fx( hTdCngDec->exc_mem1_fx, 0, 30 );
- set32_fx( hTdCngDec->old_env_fx, 0, NUM_ENV_CNG );
- st->CNG_mode = -1;
- move16();
+ IF ( LE_16(st->hTdCngDec->shb_dtx_count, 1000) )
+ {
+ st->hTdCngDec->shb_dtx_count = add(st->hTdCngDec->shb_dtx_count, 1);
+ }
+
+ E_LPC_lsf_lsp_conversion(shb_lspCNG_fx, tmp_lsp, LPC_SHB_ORDER); /*Q14*/
+ E_LPC_f_lsp_a_conversion(tmp_lsp, shb_lpcCNG_fx, LPC_SHB_ORDER);
- FOR( i = 0; i < LPC_SHB_ORDER; i++ )
+ Copy_Scale_sig( shb_lpcCNG_fx, shb_lpcCNG_fx, LPC_SHB_ORDER+1, sub(norm_s(shb_lpcCNG_fx[0]),2) ); /* Q12 */
+
+ mvs2s(shb_lpcCNG_fx, st->hTdCngDec->shb_lpcCNG_fx, LPC_SHB_ORDER + 1);
+
+ /* SHB energy estimation */
+ wb_ener_fx = L_deposit_l(1);/*Q1 */
+ IF ( NE_16(st->element_mode, IVAS_CPE_DFT) )
{
- IF( st->element_mode != EVS_MONO )
+ FOR(i = 0; i < L_FRAME32k; i++)
{
- st->lsp_shb_prev_fx[i] = ivas_lsp_shb_prev_tbl_fx[i];
- move16();
+ wb_ener_fx = L_add(wb_ener_fx, Mpy_32_16_1(L_mult0(synth_fx[i], synth_fx[i]), 51)); /* 2*Qsyn */
}
- ELSE
+ }
+ exp = norm_l(wb_ener_fx);
+ fra = Log2_norm_lc(L_shl(wb_ener_fx, exp));
+ exp = sub(30, add(exp, shl(Qsyn, 1)));
+ wb_ener_fx = Mpy_32_16(exp, fra, LG10);
+ wb_ener16_fx = round_fx(L_shl(wb_ener_fx, 10)); /*wb_ener_fx in Q8 */
+ Word32 wb_ener32_fx = L_shl(wb_ener16_fx, 3); /*wb_ener_fx in Q11 */
+ IF ( EQ_16(st->first_CNG, 0) )
+ {
+ st->hTdCngDec->wb_cng_ener_fx_32 = wb_ener32_fx;
+ move32();/*Q11 */
+ }
+ IF ( GT_32(L_abs(L_sub(wb_ener32_fx,st->hTdCngDec->wb_cng_ener_fx_32)),24576))
+ {
+ allow_cn_step_fx = 1;
+ move16();
+ }
+
+ IF ( EQ_16(allow_cn_step_fx, 1))
+ {
+ st->hTdCngDec->wb_cng_ener_fx_32 = wb_ener32_fx;
+ move32(); /*Q11 */
+ }
+ ELSE
+ {
+ tmp = L_sub(wb_ener32_fx, st->hTdCngDec->wb_cng_ener_fx_32); /*Q11 */
+ tmp = Mpy_32_16_1(tmp, 29491); /*Q11 */
+ st->hTdCngDec->wb_cng_ener_fx_32 = L_add(st->hTdCngDec->wb_cng_ener_fx_32, tmp); /*Q11 */
+ }
+ test();
+ test();
+ IF ( EQ_32(st->core_brate, SID_2k40)&&EQ_16(sid_bw,1)&&st->bfi==0)
+ {
+ st->hTdCngDec->last_wb_cng_ener_fx_32 = st->hTdCngDec->wb_cng_ener_fx_32;
+ move32();
+
+ IF ( st->first_CNG == 0 )
{
- st->lsp_shb_prev_fx[i] = lsp_shb_prev_tbl_fx[i];
- move16();
+ st->hTdCngDec->shb_cng_ener_fx_32 = st->hTdCngDec->last_shb_cng_ener_fx_32;
+ move32();
}
- st->lsp_shb_prev_prev_fx[i] = st->lsp_shb_prev_fx[i];
+ }
+
+ gain_fx = L_sub(st->hTdCngDec->wb_cng_ener_fx_32, st->hTdCngDec->last_wb_cng_ener_fx_32); /*Q11 */
+ IF (GT_32(gain_fx, 30720))
+ {
+ gain_fx = 30720;
+ move32();
+ }
+ step_fx = L_sub(L_add(gain_fx, st->hTdCngDec->last_shb_cng_ener_fx_32), st->hTdCngDec->shb_cng_ener_fx_32); /*Q11 */
+ test();
+ IF ( EQ_16(allow_cn_step_fx,1)||GT_32(st->last_core_brate,SID_2k40))
+ {
+ st->hTdCngDec->shb_cng_ener_fx_32 = L_add(st->hTdCngDec->shb_cng_ener_fx_32, step_fx);
+ }
+ ELSE
+ {
+ st->hTdCngDec->shb_cng_ener_fx_32 = L_add(st->hTdCngDec->shb_cng_ener_fx_32, L_shr(step_fx, 2)); /*Q11 */
+ }
+ /* generate white noise excitation */
+ FOR ( i=0; ihTdCngDec->swb_cng_seed), 8);
+ move16();/*Q-8*/
+ }
+
+ /* synthesis filtering */
+ Syn_filt_s( 0, shb_lpcCNG_fx, LPC_SHB_ORDER, excTmp_fx, excSHB_fx, L_FRAME16k, hBWE_TD->state_lpc_syn_fx, 1 );
+
+
+ /* synthesis signal gain shaping */
+ L_tmp = 0;
+ FOR ( i=0; ilast_vad, 1))
+ {
+ st->hTdCngDec->trans_cnt = 0;
move16();
+ test();
+ IF ( GT_16(st->hTdCngDec->burst_cnt, 3)&&NE_16(st->last_core,HQ_CORE))
+ {
+ st->hTdCngDec->trans_cnt = 5;
+ move16();
+ }
}
- st->shb_dtx_count_fx = 0;
- move16();
- st->trans_cnt_fx = 0;
- move16();
- st->last_shb_ener_fx = 0;
- move16();
- set16_fx( st->interpol_3_2_cng_dec_fx, 0, INTERP_3_2_MEM_LEN );
- hTdCngDec->burst_cnt_fx = 0;
- move16();
+ ener_fx = st->hTdCngDec->shb_cng_ener_fx_32;
+ move32();/*Q11 */
+ IF ( GT_16(st->hTdCngDec->trans_cnt, 0) )
+ {
+ i = extract_l(L_mult0(st->hTdCngDec->trans_cnt, 17)); /*Q0 */
+ ener_fx = L_add(st->hTdCngDec->shb_cng_ener_fx_32, Mpy_32_16_1(L_sub(st->hTdCngDec->last_shb_ener_fx, st->hTdCngDec->shb_cng_ener_fx_32), sin_table256_fx[i])); /*Q11 */
+ st->hTdCngDec->trans_cnt = sub(st->hTdCngDec->trans_cnt, 1);
+ }
+
+ tmp = L_shr(Mpy_32_16_1(ener_fx, 3277), 3); /*Q8 */
+ IF(tmp > 32767) abort();
+ Word16 tmp_16 = (Word16)tmp;
+ L_tmp = L_mult(27213, tmp_16); /*Q22, 27213=3.321928 in Q13 */
+ L_tmp = L_shr(L_tmp, 6); /*Q16 */
+ L_tmp = L_add(L_tmp, 10<<16);
+ IF( LT_32(L_tmp, 0) )
+ {
+ L_tmp = 0;
+ move32();
+ }
+ fra = L_Extract_lc(L_tmp, &exp);
+ L_tmp = L_shl(Pow2(exp, fra), 5); /*Q5 */
+ L_tmp = L_shr(L_tmp, 10);
+ IF( L_tmp == 0 )
+ {
+ L_tmp = 1; /*Q5 */
+ }
+ exp = norm_l(L_tmp);
+ L_tmp = L_shl(L_tmp, exp); /*Q31*/
+ tmp_16 = extract_h(L_tmp); /*Q15*/
+ exp = sub(exp, 16);
+ exp1 = norm_s(ener_excSHB_fx);
+ fra = shl(ener_excSHB_fx, exp1); /*Q15*/
+ IF ( GT_16(fra,tmp_16))
+ {
+ fra = shr(fra, 1); /*Q15*/
+ exp1 = sub(exp1, 1);
+ }
+ tmp_16 = div_s(fra, tmp_16); /*Q15*/
+
+ L_tmp = L_deposit_h(tmp_16); /*Q31 */
+ tmp_16 = -(q+exp1)+(5+exp);
+ L_gain_fx = Isqrt_lc(L_tmp, &tmp_16); /*Q31-Qtmp */
+ st->hTdCngDec->shb_cng_gain_fx_32 = ener_fx;
+ move32();
+ FOR ( i=0; ilast_extl, SWB_TBE)||EQ_16(st->last_extl,FB_TBE))
+ {
+ /* rescale the Hilbert memories to Q0 */
+ FOR(i = 0; i < HILBERT_MEM_SIZE ; i++)
+ {
+ hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] = L_shr(hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i], st->prev_Q_bwe_syn2);
+ move32();
+ }
+
+ FOR(i = 0; i < 2*ALLPASSSECTIONS_STEEP; i++ )
+ {
+ hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shr(hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i], st->prev_Q_bwe_syn2);
+ }
+
+ }
+ GenSHBSynth_fx( shb_syn16k_fx, shb_synth_fx, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st->L_frame, &(hBWE_TD->syn_dm_phase) );
+
+ IF ( EQ_32(st->output_Fs,48000))
+ {
+ interpolate_3_over_2_allpass_fx( shb_synth_fx, L_FRAME32k, shb_synth_fx, st->interpol_3_2_cng_dec_fx, allpass_poles_3_ov_2 );
+ }
+
+ ResetSHBbuffer_Dec_fx( st );
+#if 1 // TODO: To be removed later
+ ResetSHBbuffer_Dec( st->hBWE_TD, st->extl );
+#endif
return;
}
#endif
+
+/*-------------------------------------------------------------------*
+ * td_cng_dec_init()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
void td_cng_dec_init(
DEC_CORE_HANDLE st /* i/o: decoder state structure */
)
@@ -1175,3 +1385,106 @@ void td_cng_dec_init(
return;
}
+#ifdef IVAS_FLOAT_FIXED
+void td_cng_dec_init_ivas_fx(
+ DEC_CORE_HANDLE st /* i/o: decoder state structure */
+)
+{
+ Word16 i;
+ TD_CNG_DEC_HANDLE hTdCngDec;
+
+ hTdCngDec = st->hTdCngDec;
+
+ hTdCngDec->cng_seed = RANDOM_INITSEED;
+ move16();
+ hTdCngDec->cng_ener_seed = RANDOM_INITSEED;
+ move16();
+ hTdCngDec->cng_ener_seed1 = RANDOM_INITSEED;
+ move16();
+ hTdCngDec->old_enr_index = -1;
+ move16();
+ hTdCngDec->Enew_fx = 0;
+ move32();
+ mvs2s( st->lsp_old_fx, st->lspCNG_fx, M ); //Q(15)
+ hTdCngDec->last_allow_cn_step = 0;
+ move16();
+ hTdCngDec->shb_cng_ener_fx_32 = -12329; // -6.02 in Q(11)
+ move32();
+ IF ( NE_16(st->element_mode, EVS_MONO) )
+ {
+ set16_fx( hTdCngDec->shb_lpcCNG_fx, 0, LPC_SHB_ORDER + 1 );
+ hTdCngDec->shb_lpcCNG_fx[0] = 32767; // 1 in Q(15)
+ move16();
+ hTdCngDec->shb_cng_gain_fx_32 = -167936; //-82.0 in Q(11) /* a dB value approximately corresponding to shb index 0(used as index -15) */
+ move32();
+ }
+
+ hTdCngDec->wb_cng_ener_fx_32 = -12329; // Q(11)
+ move32();
+ hTdCngDec->last_wb_cng_ener_fx_32 = -12329; // Q(11)
+ move32();
+ hTdCngDec->last_shb_cng_ener_fx_32 = -12329; // Q(11)
+ move32();
+ hTdCngDec->swb_cng_seed = RANDOM_INITSEED;
+ move16();
+ hTdCngDec->ho_hist_ptr = -1;
+ move16();
+ hTdCngDec->ho_sid_bw = 0;
+ move16();
+ set16_fx( hTdCngDec->ho_lsp_hist_fx, 0, HO_HIST_SIZE * M );
+ set32_fx( hTdCngDec->ho_ener_hist_fx, 0, HO_HIST_SIZE );
+ set32_fx( hTdCngDec->ho_env_hist_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG );
+ hTdCngDec->ho_hist_size = 0;
+ move16();
+ hTdCngDec->act_cnt = 0;
+ move16();
+ hTdCngDec->ho_circ_ptr = -1;
+ move16();
+ set16_fx( hTdCngDec->ho_lsp_circ_fx, 0, HO_HIST_SIZE * M );
+ set32_fx( hTdCngDec->ho_ener_circ_fx, 0, HO_HIST_SIZE );
+ set32_fx( hTdCngDec->ho_env_circ_fx, 0, HO_HIST_SIZE * NUM_ENV_CNG );
+ hTdCngDec->ho_circ_size = 0;
+ move16();
+
+ set16_fx( hTdCngDec->ho_16k_lsp, 0, HO_HIST_SIZE );
+ st->CNG_mode = -1;
+ move16();
+ hTdCngDec->act_cnt2 = 0;
+ move16();
+ hTdCngDec->num_ho = 0;
+ move16();
+ set32_fx( hTdCngDec->lp_env_fx, 0, NUM_ENV_CNG );
+ set16_fx( hTdCngDec->exc_mem_fx, 0, 24 );
+ set16_fx( hTdCngDec->exc_mem1_fx, 0, 30 );
+ set32_fx( hTdCngDec->old_env_fx, 0, NUM_ENV_CNG );
+
+ FOR ( i = 0; i < LPC_SHB_ORDER; i++ )
+ {
+ IF ( NE_16(st->element_mode, EVS_MONO) )
+ {
+ hTdCngDec->lsp_shb_prev_fx[i] = div_s( shr( i + 1, 1 ), LPC_SHB_ORDER + 1 );
+ }
+ ELSE
+ {
+ hTdCngDec->lsp_shb_prev_fx[i] = div_s( shr(i, 1), LPC_SHB_ORDER );
+ }
+ hTdCngDec->lsp_shb_prev_prev_fx[i] = hTdCngDec->lsp_shb_prev_fx[i];
+ move16();
+ }
+
+ hTdCngDec->shb_dtx_count = 0;
+ move16();
+ hTdCngDec->trans_cnt = 0;
+ move16();
+ hTdCngDec->burst_cnt = 0;
+ move16();
+
+ hTdCngDec->last_shb_ener_fx = 2; // 0.001 in Q11
+ move32();
+
+
+ set16_fx( hTdCngDec->interpol_3_2_cng_dec_fx, 0, INTERP_3_2_MEM_LEN );
+
+ return;
+}
+#endif
diff --git a/lib_dec/core_switching_dec.c b/lib_dec/core_switching_dec.c
index ed78f5f09748e407bb5570e14a18a8b8f4d28775..c1da36b10b4cdaed8c6fb6933baaad569f7f276c 100644
--- a/lib_dec/core_switching_dec.c
+++ b/lib_dec/core_switching_dec.c
@@ -1917,7 +1917,160 @@ void bw_switching_pre_proc(
return;
}
+#ifdef IVAS_FLOAT_FIXED
+void ivas_bw_switching_pre_proc_fx(
+ Decoder_State *st, /* i/o: decoder state structure */
+ const Word32 last_element_brate, /* i : last element bitrate */
+ const Word16 nchan_out /* i : number of output channels */,
+ Word32 *old_syn_12k8_16k_fx,
+ Word16 Q,
+ Word16 Q_audio
+)
+{
+ Word16 i;
+ Word32 syn_dct_fx[L_FRAME];
+ Word32 L_tmp;
+
+
+ Flag Overflow = 0;
+
+ IF ( GT_16( st->element_mode, EVS_MONO ) )
+ {
+ IF ( EQ_16( st->core, ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) && st->hBWE_FD != NULL && !( LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( nchan_out, 2 ) ) && !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( nchan_out, 1 ) && EQ_16( st->idchan, 1 ) && LE_32( last_element_brate, IVAS_SID_5k2 ) ) )
+ {
+ /* Calculate tilt of the ACELP core synthesis - needed in SWB BWE decoding */
+ st->tilt_wb_fx = ivas_calc_tilt_bwe_fx( old_syn_12k8_16k_fx, Q , st->L_frame );
+ st->tilt_wb = fix16_to_float(st->tilt_wb_fx, 11);
+ }
+
+ return;
+ }
+
+ IF ( EQ_16( st->core, ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) )
+ {
+ /*----------------------------------------------------------------------*
+ * Calculate tilt of the ACELP core synthesis
+ *----------------------------------------------------------------------*/
+
+ st->tilt_wb_fx = ivas_calc_tilt_bwe_fx( old_syn_12k8_16k_fx, Q, st->L_frame );
+ st->tilt_wb = fix16_to_float(st->tilt_wb_fx, 11);
+ /*-------------------------------------------------------------------------------*
+ * Calculate frequency energy of 0~3.2kHz and 3.2~6.4kHz the ACELP core synthesis
+ *-------------------------------------------------------------------------------*/
+ edct_fx(old_syn_12k8_16k_fx, syn_dct_fx, L_FRAME, &Q);
+ st->enerLL = EPSILON;
+ Word64 W_tmp = 0;
+ Word32 tmp;
+ Word16 shift;
+ FOR ( i = 0; i < L_FRAME / 2; i++ )
+ {
+ W_tmp = W_add(W_tmp, W_shr( W_mult0_32_32( syn_dct_fx[i], syn_dct_fx[i]), Q) );
+ }
+ shift = W_norm(W_tmp);
+ W_tmp = W_shl(W_tmp, shift);
+ tmp = W_extract_h(W_tmp);
+ tmp = L_shr(tmp, 8);
+
+ tmp = getSqrtWord32(tmp);
+ st->enerLL = fixedToFloat(tmp, (Q + shift - 32) / 2); // Q / 2
+ st->enerLL_fx = tmp;
+
+ st->enerLH = EPSILON;
+ W_tmp = 0;
+ FOR ( ; i < L_FRAME; i++ )
+ {
+ W_tmp = W_add(W_tmp, W_shr(W_mult0_32_32(syn_dct_fx[i], syn_dct_fx[i]), Q) );
+ }
+ shift = W_norm(W_tmp);
+ W_tmp = W_shl(W_tmp, shift);
+ tmp = W_extract_h(W_tmp); // Q = Q + shift - 32
+ tmp = L_shr(tmp, 7); // divide by 128
+ tmp = getSqrtWord32(tmp);
+ st->enerLH = fixedToFloat(tmp, (Q + shift - 32) / 2); // Q / 2
+ st->enerLH_fx = tmp;
+
+ }
+ ELSE
+ {
+ IF ( st->hHQ_core->old_is_transient[0] )
+ {
+ Word64 W_tmp = 0;
+ Word32 tmp, L_tmp = 0;
+ Word16 shift;
+ FOR ( i = 0; i < 32; i++ )
+ {
+ L_tmp = L_mac0_o(L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i], &Overflow);
+ }
+ tmp = L_shr(L_tmp, 5); // divide by 32
+ tmp = getSqrtWord32(tmp);
+ st->enerLL = fixedToFloat(tmp, Q_audio); // Q / 2
+ st->enerLL_fx = tmp;
+
+ st->enerLH = EPSILON;
+ L_tmp = 0;
+ FOR ( ; i < 64; i++ )
+ {
+ L_tmp = L_mac0_o(L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i], &Overflow);
+ }
+
+ tmp = L_shr(L_tmp, 5); // divide by 32
+ tmp = getSqrtWord32(tmp);
+ st->enerLH = fixedToFloat(tmp, Q_audio); // Q / 2
+ st->enerLH_fx = tmp;
+ }
+ ELSE
+ {
+ st->enerLL = EPSILON;
+ Word32 tmp, L_tmp = 0;
+ Word16 shift;
+ L_tmp = 0;
+ FOR ( i = 0; i < L_FRAME / 2; i++ )
+ {
+ L_tmp = L_mac0_o(L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i], &Overflow);
+ }
+ tmp = L_shr(L_tmp, 5); // divide by 32
+ tmp = getSqrtWord32(tmp);
+ st->enerLL = fixedToFloat(tmp, Q_audio); // Q / 2
+ st->enerLL_fx = tmp;
+
+ L_tmp = 0;
+ FOR ( ; i < L_FRAME; i++ )
+ {
+ L_tmp = L_mac0_o(L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i], &Overflow);
+ }
+ tmp = L_shr(L_tmp, 5); // divide by 32
+ tmp = getSqrtWord32(tmp);
+ st->enerLL = fixedToFloat(tmp, Q_audio); // Q / 2
+ st->enerLL_fx = tmp;
+ }
+ }
+
+ IF ( EQ_16( st->last_bwidth, 0 ) && LE_16( st->extl, SWB_CNG ) )
+ {
+ st->prev_ener_shb = 0.0f;
+ st->prev_ener_shb_fx = 0;
+ IF ( st->hBWE_FD != NULL )
+ {
+ set_f( st->hBWE_FD->prev_SWB_fenv, 0, SWB_FENV );
+ set_s(st->hBWE_FD->prev_SWB_fenv_fx, 0, SWB_FENV);
+ }
+ }
+ ELSE IF ( ( ( EQ_16( st->core, ACELP_CORE ) && ( EQ_16( st->last_core, HQ_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || EQ_16( st->last_core, TCX_20_CORE ) ) ) || ( EQ_16( st->core, st->last_core ) && NE_16( st->extl, st->last_extl ) ) ) && GE_16( st->last_bwidth, SWB ) )
+ {
+ st->attenu1 = 0.1f;
+ st->attenu_fx = 3277;
+ }
+
+ IF ( EQ_16( st->last_core, HQ_CORE ) || ( EQ_16( st->last_core, ACELP_CORE ) && !( EQ_16( st->last_extl, WB_TBE ) || EQ_16( st->last_extl, SWB_TBE ) || EQ_16( st->last_extl, FB_TBE ) ) && GT_32( st->core_brate, ACELP_8k00 ) ) )
+ {
+ st->prev_fractive = 0;
+ st->prev_fractive_fx = 0;
+ }
+
+ return;
+}
+#endif
/*---------------------------------------------------------------------*
* core_switch_lb_upsamp()
*
diff --git a/lib_dec/dec_gen_voic_fx.c b/lib_dec/dec_gen_voic_fx.c
index d32daf5149074d4242d5309683a8d0b2de2a975e..bc9aceb53ab8ff3e14503f7231bb3ac6713ce0fe 100644
--- a/lib_dec/dec_gen_voic_fx.c
+++ b/lib_dec/dec_gen_voic_fx.c
@@ -468,3 +468,469 @@ ivas_error decod_gen_voic_fx(
return error;
}
+
+/*======================================================================*/
+/* FUNCTION : decod_gen_voic_ivas_fx() */
+/*----------------------------------------------------------------------*/
+/* PURPOSE : Decode generic (GC), voiced (VC) and AMR-WB IO frames */
+/* */
+/*----------------------------------------------------------------------*/
+/* GLOBAL INPUT ARGUMENTS : */
+/* _ (Struct) st_fx : decoder static memory */
+/* _ (Word16) L_frame : length of the frame */
+
+/* _ (Word16[]) Aq_fx : LP filter coefficient Q12 */
+/* _ (Word16) Es_pred_fx : predicted scaled innov. energy Q8 */
+/* _ (Word16[]) pitch_buf_fx : floating pitch values for each subframe Q6*/
+/* _ (Word16[]) voice_factors_fx: frame error rate Q15 */
+/*----------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ (Word16[]) exc_fx : adapt. excitation exc (Q_exc) */
+/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q_exc) */
+/*----------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : */
+/* _ None */
+/*======================================================================*/
+
+ivas_error decod_gen_voic_ivas_fx(
+ Decoder_State *st_fx, /* i/o: decoder static memory */
+ const Word16 L_frame, /* i : length of the frame */
+ const Word16 sharpFlag_fx, /* i : formant sharpening flag */
+ const Word16 *Aq_fx, /* i : LP filter coefficient */
+ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */
+ const Word16 do_WI_fx, /* i : do interpolation after a FER */
+ Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */
+ Word16 *voice_factors_fx, /* o : voicing factors */
+ Word16 *exc_fx, /* i/o: adapt. excitation exc */
+ Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */
+ Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */
+ Word16 *unbits, /* number of unused bits */
+ Word16 *gain_buf,
+ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
+ const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */
+)
+{
+
+
+ Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx;/* integer pitch variables */
+ Word16 gain_pit_fx = 0; /* pitch gain Q14 */
+ Word32 gain_code_fx = 0; /* gain/normalized gain of the algebraic excitation Q16 */
+ Word32 norm_gain_code_fx = 0; /* normalized gain of the algebraic excitation Q16 */
+ Word16 gain_inov_fx = 0; /* Innovation gain Q12 */
+ Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */
+ Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */
+ Word16 voice_fac_fx; /* voicing factor Q15 */
+ Word16 code_fx[L_SUBFR]; /* algebraic codevector Q12 */
+
+ const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12 */
+ Word16 *pt_pitch_fx; /* pointer to floating pitch Q6 */
+ Word16 i_subfr_fx, i; /* tmp variables */
+ Word16 error_fx = 0;
+ Word16 gain_preQ_fx = 0; /* Gain of prequantizer excitation */
+ Word16 code_preQ_fx[L_SUBFR]; /* Prequantizer excitation */
+ Word32 norm_gain_preQ_fx;
+ Word16 pitch_limit_flag_fx;
+
+ Word16 tmp1_fx, gain_code16;
+ Word32 L_tmp_GC;
+ Word32 L_tmp;
+
+ Word16 harm_flag_acelp;
+
+ Word16 shft_prev, ph_offset_fx;
+ Word32 prev_res_nrg;
+ Word32 prev_spch_nrg;
+ Word32 curr_res_nrg;
+ Word32 curr_spch_nrg;
+ Word16 rint_bfi_pitch, rint_pitch;
+ Word16 fraca, fracb, expa, expb, scale, exp1;
+ Word16 *p_exc;
+ Word16 mem_tmp_fx[M];
+ Word16 syn_tmp_fx[L_FRAME16k];
+ Word16 shft_curr;
+ Word16 *p_syn;
+ Word16 sp_enratio, Qsp_enratio;
+ Word16 enratio, Qenratio;
+ DTFS_STRUCTURE *PREVP, *CURRP;
+ Word16 S_fx[PIT_MAX * 4 + 1], C_fx[PIT_MAX * 4 + 1];
+ Word16 dummy2[2];
+ Word16 out_fx[L_FRAME16k];
+
+ Word16 pf_temp1[MAXLAG_WI]; /*may not need more than MAXLAG_WI/2+1 */
+ Word16 pf_temp2[MAXLAG_WI];
+ Word16 pf_temp[MAXLAG_WI];
+ Word16 pf_n2[MAXLAG_WI];
+ MUSIC_POSTFILT_HANDLE hMusicPF;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+ hMusicPF = st_fx->hMusicPF;
+
+ GSC_DEC_HANDLE hGSCDec;
+ hGSCDec = st_fx->hGSCDec;
+ ivas_error error;
+
+ error = IVAS_ERR_OK;
+
+ T0_fx = PIT_MIN;
+ move16();
+ T0_frac_fx = 0;
+ move16();
+
+ /* read harmonicity flag */
+ harm_flag_acelp = 0;
+ move16();
+ test();
+ test();
+ IF((GE_32(st_fx->core_brate, MIN_BRATE_AVQ_EXC) && LE_32(st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD)) && EQ_16(st_fx->coder_type_fx, GENERIC))
+ {
+ harm_flag_acelp = (Word16)get_next_indice(st_fx, 1);
+ }
+
+ /*------------------------------------------------------------------*
+ * ACELP subframe loop
+ *------------------------------------------------------------------*/
+
+ p_Aq_fx = Aq_fx;
+ move16(); /* pointer to interpolated LPC parameters */
+ pt_pitch_fx = pitch_buf_fx;
+ move16(); /* pointer to the pitch buffer */
+ norm_gain_preQ_fx = 0;
+ move16();
+ gain_preQ_fx = 0;
+ move16();
+ set16_fx(code_preQ_fx, 0, L_SUBFR);
+
+ FOR(i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR)
+ {
+ /*----------------------------------------------------------------------*
+ * Decode pitch lag
+ *----------------------------------------------------------------------*/
+
+ /**pt_pitch_fx = pit_decode_fx(st_fx, st_fx->core_brate, 0, L_frame, i_subfr_fx, st_fx->coder_type_fx, &pitch_limit_flag_fx,
+ &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_SUBFR);*/
+ *pt_pitch_fx = pit_decode_ivas_fx(st_fx, st_fx->core_brate, 0, L_frame, i_subfr_fx, st_fx->coder_type_fx, &pitch_limit_flag_fx,
+ &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_SUBFR, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf);
+ move16(); /*Q6*/
+
+ /*--------------------------------------------------------------*
+ * Find the adaptive codebook vector
+ *--------------------------------------------------------------*/
+
+ pred_lt4(&exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP);
+
+ //tbe_celp_exc(L_frame, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx);
+ tbe_celp_exc_ivas(st_fx->element_mode, st_fx->idchan, L_frame, L_SUBFR, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx, st_fx->tdm_LRTD_flag);
+
+ /*--------------------------------------------------------------*
+ * LP filtering of the adaptive excitation
+ *--------------------------------------------------------------*/
+ lp_filt_exc_dec_fx(st_fx, MODE1, i_subfr_fx, L_SUBFR, L_frame, st_fx->acelp_cfg.ltf_mode, exc_fx);
+ /*-----------------------------------------------------------------*
+ * Transform-domain contribution decoding (active frames)
+ *-----------------------------------------------------------------*/
+
+ test();
+ IF(GE_32(st_fx->core_brate, MIN_BRATE_AVQ_EXC) && NE_16(st_fx->coder_type_fx, INACTIVE))
+ {
+ gain_code_fx = 0;
+ move16();
+ transf_cdbk_dec_fx(st_fx, harm_flag_acelp, i_subfr_fx, Es_pred_fx, gain_code_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits);
+ }
+
+ /*--------------------------------------------------------------*
+ * Innovation decoding
+ *--------------------------------------------------------------*/
+
+ inov_decode_fx(st_fx, st_fx->core_brate, 0, L_frame, sharpFlag_fx, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_SUBFR);
+
+ /*--------------------------------------------------------------*
+ * Gain decoding
+ * Estimate spectrum tilt and voicing
+ *--------------------------------------------------------------*/
+
+ IF(LE_32(st_fx->core_brate, ACELP_8k00))
+ {
+ gain_dec_lbr_fx(st_fx, st_fx->coder_type_fx, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_SUBFR);
+ }
+ ELSE IF(GT_32(st_fx->core_brate, ACELP_32k))
+ {
+ gain_dec_SQ_fx(st_fx, i_subfr_fx, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx);
+ }
+ ELSE
+ {
+ gain_dec_mless_fx(st_fx, L_frame, st_fx->coder_type_fx, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx);
+ }
+ st_fx->tilt_code_fx = est_tilt_ivas_fx(exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR, 0);
+
+ /*-----------------------------------------------------------------*
+ * Transform domain contribution decoding
+ *-----------------------------------------------------------------*/
+ test();
+ IF(GE_32(st_fx->total_brate, MAX_GSC_INACTIVE_BRATE) && EQ_16(st_fx->coder_type_fx, INACTIVE))
+ {
+ transf_cdbk_dec_fx(st_fx, harm_flag_acelp, i_subfr_fx, Es_pred_fx, gain_code_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits);
+ }
+
+ /* update LP filtered gains for the case of frame erasures */
+ lp_gain_updt_fx(i_subfr_fx, gain_pit_fx, L_add(norm_gain_code_fx, norm_gain_preQ_fx), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame);
+
+ /*----------------------------------------------------------------------*
+ * Find the total excitation
+ *----------------------------------------------------------------------*/
+
+ IF(EQ_16(L_frame, L_FRAME)) /* Rescaling for 12.8k core */
+ {
+ Rescale_exc(hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC], hGSCDec->last_exc_dct_in_fx,
+ L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type_fx);
+
+ }
+ ELSE /* Rescaling for 16k core */
+ {
+
+ L_tmp_GC = L_max(gain_code_fx, L_shl(gain_preQ_fx,16)); /* Chose the maximum of gain_code or the prequantizer excitation x4 to keep some room*/
+ Rescale_exc(hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * 2], hGSCDec->last_exc_dct_in_fx,
+ L_SUBFR, L_SUBFR * 2, L_tmp_GC, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type_fx);
+ }
+
+ gain_code16 = round_fx(L_shl(gain_code_fx, st_fx->Q_exc)); /*Q_exc*/
+
+ /*-----------------------------------------------------------------*
+ * Add the ACELP pre-quantizer contribution
+ *-----------------------------------------------------------------*/
+
+ IF(gain_preQ_fx != 0)
+ {
+ tmp1_fx = add(15 - Q_AVQ_OUT_DEC - 2, st_fx->Q_exc);
+ FOR(i = 0; i < L_SUBFR; i++)
+ {
+ Word32 Ltmp1;
+ /* Contribution from AVQ layer */
+ Ltmp1 = L_mult(gain_preQ_fx, code_preQ_fx[i]); /* Q2 + Q6 -> Q9*/
+ Ltmp1 = L_shl(Ltmp1, tmp1_fx); /* Q16 + Q_exc */
+
+ /* Compute exc2 */
+ L_tmp = L_shl(L_mult(gain_pit_fx, exc_fx[i + i_subfr_fx]), 1);
+ exc2_fx[i + i_subfr_fx] = round_fx(L_add(L_tmp, Ltmp1));
+
+ /* code in Q9, gain_pit in Q14 */
+ L_tmp = L_mult(gain_code16, code_fx[i]);
+ L_tmp = L_shl(L_tmp, 5);
+ L_tmp = L_mac(L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx);
+ L_tmp = L_shl(L_tmp, 1); /* saturation can occur here */
+
+ exc_fx[i + i_subfr_fx] = round_fx(L_add(L_tmp, Ltmp1));
+ }
+ }
+ ELSE
+ {
+ Acelp_dec_total_exc(exc_fx, exc2_fx, gain_code16, gain_pit_fx, i_subfr_fx, code_fx, L_SUBFR);
+ }
+
+ /*-----------------------------------------------------------------*
+ * Prepare TBE excitation
+ *-----------------------------------------------------------------*/
+
+ /*prep_tbe_exc_fx(L_frame, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx,
+ &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx,
+ st_fx->Q_exc, T0_fx, T0_frac_fx, st_fx->coder_type_fx, st_fx->core_brate);*/
+ prep_tbe_exc_ivas_fx(L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx,
+ &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx,
+ st_fx->Q_exc, T0_fx, T0_frac_fx, st_fx->coder_type_fx, st_fx->core_brate,
+ st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag);
+
+
+ /*----------------------------------------------------------------*
+ * Excitation enhancements (update of total excitation signal)
+ *----------------------------------------------------------------*/
+
+ test();
+ IF(GT_32(st_fx->core_brate, ACELP_32k) || EQ_16(st_fx->coder_type_fx, INACTIVE))
+ {
+ Copy(exc_fx + i_subfr_fx, exc2_fx + i_subfr_fx, L_SUBFR);
+ }
+ ELSE
+ {
+ enhancer_fx(st_fx->core_brate, 0, st_fx->coder_type_fx, i_subfr_fx, L_frame, voice_fac_fx, st_fx->stab_fac_fx,
+ norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &(st_fx->dm_fx), st_fx->Q_exc);
+ }
+
+ p_Aq_fx += (M + 1);
+ move16();
+ pt_pitch_fx++;
+ gain_buf[i_subfr_fx / L_SUBFR] = gain_pit_fx;
+ move16();
+ }
+
+ /* FEC fast recovery */
+
+ IF(do_WI_fx)
+ {
+ /* shft_prev = L_EXC_MEM - rint_new_fx(st_fx->bfi_pitch_fx);*/
+ L_tmp = L_shl(L_deposit_l(st_fx->bfi_pitch_fx), 10); /*Q16*/
+ rint_bfi_pitch = rint_new_fx(L_tmp); /*Q0*/
+ shft_prev = sub(L_EXC_MEM, rint_bfi_pitch); /*Q0*/
+
+ p_exc = st_fx->hWIDec->old_exc2_fx + shft_prev;
+ p_syn = st_fx->hWIDec->old_syn2_fx + shft_prev;
+ move16();
+ move16();
+
+ prev_res_nrg = L_deposit_l(1);
+ prev_spch_nrg = L_deposit_l(1);
+ FOR(i = 0; i < rint_bfi_pitch; i++)
+ {
+#ifdef BASOP_NOGLOB
+ prev_res_nrg = L_mac0_sat(prev_res_nrg, *p_exc, *p_exc); /* 2*st_fx->prev_Q_exc_fr */
+ prev_spch_nrg = L_mac0_sat(prev_spch_nrg, *p_syn, *p_syn); /* 2*st_fx->prev_Q_syn_fr */
+#else
+ prev_res_nrg = L_mac0(prev_res_nrg, *p_exc, *p_exc); /* 2*st_fx->prev_Q_exc_fr */
+ prev_spch_nrg = L_mac0(prev_spch_nrg, *p_syn, *p_syn); /* 2*st_fx->prev_Q_syn_fr */
+#endif
+ p_exc++;
+ p_syn++;
+ }
+
+ Copy(st_fx->mem_syn2_fx, mem_tmp_fx, M);
+
+ syn_12k8_fx(st_fx->L_frame, Aq_fx, exc2_fx, syn_tmp_fx, mem_tmp_fx, 1, st_fx->Q_exc, st_fx->Q_syn);
+
+ L_tmp = L_shl(L_deposit_l(pitch_buf_fx[NB_SUBFR16k - 1]), 10); /*Q16*/
+ rint_pitch = rint_new_fx(L_tmp); /*Q0*/
+ shft_curr = sub(st_fx->L_frame, rint_pitch); /*Q0*/
+
+ p_exc = exc2_fx + shft_curr;
+ move16();
+ p_syn = syn_tmp_fx + shft_curr;
+ move16();
+
+ curr_res_nrg = L_deposit_l(1);
+ curr_spch_nrg = L_deposit_l(1);
+ FOR(i = 0; i < rint_pitch; i++)
+ {
+ curr_res_nrg = L_mac0(curr_res_nrg, *p_exc, *p_exc); /* 2*st_fx->Q_exc */
+ curr_spch_nrg = L_mac0(curr_spch_nrg, *p_syn, *p_syn); /* 2*st_fx->Q_syn */
+ p_exc++;
+ p_syn++;
+ }
+
+ /* enratio = (curr_res_nrg / prev_res_nrg); */
+ IF(prev_res_nrg > 0)
+ {
+ expa = norm_l(prev_res_nrg);
+ fraca = extract_h(L_shl(prev_res_nrg, expa));
+ expa = sub(30, expa + (2 * st_fx->prev_Q_exc_fr));
+
+ expb = norm_l(curr_res_nrg);
+ fracb = round_fx(L_shl(curr_res_nrg, expb));
+ expb = sub(30, expb + (2 * st_fx->Q_exc));
+
+ scale = shr(sub(fraca, fracb), 15);
+ fracb = shl(fracb, scale);
+ expb = sub(expb, scale);
+
+ enratio = div_s(fracb, fraca);
+ exp1 = sub(expb, expa);
+ Qenratio = 15 - exp1;
+ }
+ ELSE
+ {
+ enratio = 0;
+ Qenratio = 0;
+ }
+
+ /* sp_enratio = curr_spch_nrg/prev_spch_nrg */
+ IF(prev_spch_nrg > 0)
+ {
+ expa = norm_l(prev_spch_nrg);
+ fraca = extract_h(L_shl(prev_spch_nrg, expa));
+ expa = sub(30, expa + (2 * st_fx->prev_Q_syn_fr));
+
+ expb = norm_l(curr_spch_nrg);
+ fracb = round_fx(L_shl(curr_spch_nrg, expb));
+ expb = sub(30, expb + (2 * st_fx->Q_syn));
+
+ scale = shr(sub(fraca, fracb), 15);
+ fracb = shl(fracb, scale);
+ expb = sub(expb, scale);
+
+ sp_enratio = div_s(fracb, fraca);
+ exp1 = sub(expb, expa);
+ Qsp_enratio = 15 - exp1;
+ }
+ ELSE
+ {
+ sp_enratio = 0;
+ Qsp_enratio = 0;
+ }
+
+ test();
+ test();
+ test();
+ test();
+#ifdef BASOP_NOGLOB
+ IF(GT_16(shl_ro(enratio, 15 - Qenratio, &Overflow), 8192) && /*compare with 0.25 in Q15*/
+ LT_16(shl_ro(enratio, 10 - Qenratio, &Overflow), 15360) && /*compare with 15.0 in Q10*/
+ GT_16(shl_ro(sp_enratio, 15 - Qsp_enratio, &Overflow), 4915) &&/*compare with 0.15 in Q15*/
+ st_fx->bfi_pitch_fx < 9600 && /*Q6*/
+ pitch_buf_fx[sub(NB_SUBFR16k, 1)] < 9600) /*Q6*/
+#else
+ IF(GT_16(shl_r(enratio, 15 - Qenratio), 8192) && /*compare with 0.25 in Q15*/
+ LT_16(shl_r(enratio, 10 - Qenratio), 15360) && /*compare with 15.0 in Q10*/
+ GT_16(shl_r(sp_enratio, 15 - Qsp_enratio), 4915) &&/*compare with 0.15 in Q15*/
+ st_fx->bfi_pitch_fx < 9600 && /*Q6*/
+ pitch_buf_fx[sub(NB_SUBFR16k, 1)] < 9600) /*Q6*/
+#endif
+ {
+ IF((error = DTFS_new_fx(&PREVP)) != IVAS_ERR_OK)
+ {
+ return error;
+ }
+
+ IF((error = DTFS_new_fx(&CURRP)) != IVAS_ERR_OK)
+ {
+ return error;
+ }
+
+ GetSinCosTab_fx(rint_bfi_pitch, S_fx, C_fx);
+ DTFS_to_fs_fx(st_fx->hWIDec->old_exc2_fx + shft_prev, rint_bfi_pitch, PREVP, (Word16)st_fx->output_Fs, do_WI_fx, S_fx, C_fx);
+ PREVP->Q = add(PREVP->Q, st_fx->prev_Q_exc_fr);
+
+ GetSinCosTab_fx(rint_pitch, S_fx, C_fx);
+ DTFS_to_fs_fx(exc2_fx + shft_curr, rint_pitch, CURRP, (Word16)st_fx->output_Fs, do_WI_fx, S_fx, C_fx);
+ CURRP->Q = add(CURRP->Q, st_fx->Q_exc);
+
+ ph_offset_fx = 0;
+ move16();
+ if ((error = WIsyn_fx(*PREVP, CURRP, dummy2, &(ph_offset_fx), out_fx, (Word16)st_fx->L_frame, 1, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2)) != IVAS_ERR_OK)
+ {
+ return error;
+ }
+
+
+ Copy_Scale_sig(out_fx, exc2_fx, st_fx->L_frame, st_fx->Q_exc);
+ Copy_Scale_sig(out_fx, exc_fx, st_fx->L_frame, st_fx->Q_exc);
+
+ /* update bwe_exc for SWB-TBE */
+ FOR(i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR)
+ {
+ interp_code_4over2_fx(exc_fx + i_subfr_fx, bwe_exc_fx + (i_subfr_fx * 2), L_SUBFR);
+ }
+
+ count_free(PREVP);
+ count_free(CURRP);
+ }
+
+ }
+
+ /* SC-VBR */
+ st_fx->prev_gain_pit_dec_fx = gain_pit_fx;
+ move16(); /*Q14*/
+ st_fx->prev_tilt_code_dec_fx = st_fx->tilt_code_fx;
+ move16(); /*Q15*/
+
+ return error;
+}
diff --git a/lib_dec/dec_higher_acelp_fx.c b/lib_dec/dec_higher_acelp_fx.c
index 4e389a66ad6b9040c45c846bffacbe96b205bc2f..1e41cc6f0405fd337c51bcf3998c3b268428b620 100644
--- a/lib_dec/dec_higher_acelp_fx.c
+++ b/lib_dec/dec_higher_acelp_fx.c
@@ -161,11 +161,11 @@ void transf_cdbk_dec_fx(
IF (GT_16(st_fx->element_mode, EVS_MONO) && NE_16(st_fx->coder_type_fx, INACTIVE) && GE_32(st_fx->core_brate, MIN_BRATE_AVQ_EXC) && LE_32(st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD) && !harm_flag_acelp && code_preQ[0] != 0)
{
//PMT("Fixed point taking accound of the scaling needs to be done here ")
- IF (GT_16(abs_s(st_fx->last_code_preq), shl(abs_s(code_preQ[0]),4)))
+ IF (GT_16(abs_s(st_fx->last_code_preq), shl_sat(abs_s(code_preQ[0]),4)))
{
st_fx->mem_preemp_preQ /= 16;
}
- ELSE IF (GT_16(abs_s((st_fx->last_code_preq)), shl(abs_s(code_preQ[0]),3)))
+ ELSE IF (GT_16(abs_s((st_fx->last_code_preq)), shl_sat(abs_s(code_preQ[0]),3)))
{
st_fx->mem_preemp_preQ /= 8;
}
diff --git a/lib_dec/dec_pit_exc_fx.c b/lib_dec/dec_pit_exc_fx.c
index 7976bf6492d8a482643b0c82abec6663756167c3..1d719409207b46871ce3eeb9d4feb32ac6d9c67a 100644
--- a/lib_dec/dec_pit_exc_fx.c
+++ b/lib_dec/dec_pit_exc_fx.c
@@ -403,3 +403,399 @@ void dec_pit_exc_fx(
return;
}
+
+/*==========================================================================*/
+/* FUNCTION : void dec_pit_exc_ivas_fx() */
+/*--------------------------------------------------------------------------*/
+/* PURPOSE : Decode pitch only contribution */
+/*--------------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (Word16*) Aq_fx : LP filter coefficient Q12 */
+/* _ (Word16) coder_type_fx : coding type Q0 */
+/* _ (Word16) nb_subfr_fx :Number of subframe considered */
+/* _ (Word16) Es_pred_fx :predicted scaled innov. energy */
+/*--------------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ (Word16*) pitch_buf_fx : floating pitch values for each subframe Q6 */
+/* _ (Word16*) code_fx : innovation */
+/*--------------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* Decoder_State_fx *st_fx : decoder state structure */
+/* _ (Word16*) exc_fx : adapt. excitation exc */
+/*--------------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : */
+/* _ None */
+/*==========================================================================*/
+void dec_pit_exc_ivas_fx(
+ Decoder_State *st_fx, /* i/o: decoder static memory */
+ const Word16 *Aq_fx, /* i : LP filter coefficient */
+ const Word16 coder_type_fx, /* i : coding type */
+ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */
+ Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */
+ Word16 *code_fx, /* o : innovation */
+ Word16 *exc_fx, /* i/o: adapt. excitation exc */
+ Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */
+ const Word16 nb_subfr_fx /* i : Number of subframe considered */
+ , Word16 *gain_buf /*Q14*/
+#if 1//def ADD_LRTD
+ , const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
+ const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */
+#endif
+)
+{
+ Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx;/* integer pitch variables */
+ Word16 gain_pit_fx = 0; /* pitch gain Q14 */
+ Word32 gain_code_fx; /* gain/normalized gain of the algebraic excitation Q16 */
+ Word32 norm_gain_code_fx; /* normalized gain of the algebraic excitation Q16 */
+ Word16 gain_inov_fx; /* Innovation gain Q12 */
+ Word16 voice_fac_fx; /* voicing factor Q15 */
+ Word16 L_subfr_fx, pit_idx_fx;
+ const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12 */
+ Word16 *pt_pitch_fx; /* pointer to floating pitch Q6 */
+ Word16 i_subfr_fx, i; /* tmp variables */
+ Word32 Local_BR_fx, Pitch_BR_fx;
+ Word16 pitch_limit_flag, Pitch_CT_fx;
+ Word16 exc2_bidon[L_SUBFR * 2];
+ Word16 *pt_gain; /* Pointer to floating gain values for each subframe */
+
+ Word16 gain_code16, gain_pitx2;
+ Word32 L_tmp;
+ Word16 nbits;
+ GSC_DEC_HANDLE hGSCDec;
+ hGSCDec = st_fx->hGSCDec;
+
+ MUSIC_POSTFILT_HANDLE hMusicPF;
+ hMusicPF = st_fx->hMusicPF;
+
+ Word16 use_fcb;
+ Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */
+ Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+
+ use_fcb = 0;
+ move16();
+ test(); test(); test();
+ IF(GT_16(st_fx->GSC_IVAS_mode, 0) && (EQ_16(st_fx->GSC_noisy_speech_fx, 1) || GT_32(st_fx->core_brate, GSC_H_RATE_STG)))
+ {
+ Local_BR_fx = ACELP_8k00;
+ Pitch_CT_fx = GENERIC;
+ Pitch_BR_fx = ACELP_8k00;
+ move32(); move32(); move16();
+ IF(EQ_16(st_fx->L_frame, L_FRAME16k))
+ {
+ Local_BR_fx = ACELP_14k80;
+ IF(GT_16(st_fx->GSC_IVAS_mode, 0))
+ {
+ Local_BR_fx = ACELP_9k60;
+ move32();
+ }
+ Pitch_BR_fx = st_fx->core_brate;
+ move32();
+ }
+ }
+ ELSE IF(EQ_16(st_fx->GSC_noisy_speech_fx, 1))
+ {
+ Local_BR_fx = ACELP_7k20;
+ move32();
+ Pitch_CT_fx = GENERIC;
+ move16();
+ Pitch_BR_fx = ACELP_7k20;
+ move32();
+ IF(EQ_16(st_fx->L_frame, L_FRAME16k))
+ {
+ Pitch_BR_fx = st_fx->core_brate;
+ move32();
+ }
+ }
+ ELSE
+ {
+ Local_BR_fx = ACELP_7k20;
+ move32();
+ Pitch_CT_fx = AUDIO;
+ move16();
+ Pitch_BR_fx = st_fx->core_brate;
+ move32();
+ IF(EQ_16(st_fx->L_frame, L_FRAME16k))
+ {
+ Pitch_BR_fx = ACELP_13k20;
+ move32();
+ Pitch_CT_fx = GENERIC;
+ move16();
+ }
+ }
+ L_subfr_fx = mult_r(st_fx->L_frame, div_s(1, nb_subfr_fx)); /* TV2Opt : this could be less complex with 2 ifs*/
+
+
+ gain_code_fx = 0;
+ move16();
+ pitch_limit_flag = 1;
+ move16();/* always extended pitch Q range */
+ test(); test(); test(); test(); test(); test();
+ IF(((GE_32(st_fx->core_brate, MIN_RATE_FCB) || (EQ_16(st_fx->GSC_noisy_speech_fx, 1) && ((EQ_16(st_fx->L_frame, L_FRAME) && GE_32(st_fx->core_brate, ACELP_13k20)) || (EQ_16(st_fx->L_frame, L_FRAME16k) && GE_32(st_fx->core_brate, GSC_H_RATE_STG)) || st_fx->GSC_IVAS_mode == 0))) && EQ_16(L_subfr_fx, L_SUBFR)))
+ {
+ use_fcb = 1; move16();
+ }
+ ELSE IF(GT_16(st_fx->GSC_IVAS_mode, 0) && EQ_16(L_subfr_fx, 2 * L_SUBFR) && LT_16(st_fx->GSC_IVAS_mode, 3))
+ {
+ use_fcb = 2;
+ st_fx->acelp_cfg.fcb_mode = 1;
+ move16(); move16();
+ set16_fx(st_fx->acelp_cfg.gains_mode, 6, 4);
+ set16_fx(st_fx->acelp_cfg.pitch_bits, 9, 4);
+ set16_fx(st_fx->acelp_cfg.fixed_cdk_index, 14, 5);
+ }
+ /*------------------------------------------------------------------*
+ * ACELP subframe loop
+ *------------------------------------------------------------------*/
+ p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */
+ pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */
+ pt_gain = gain_buf; /* pointer to the gain buffer */
+ FOR(i_subfr_fx = 0; i_subfr_fx < st_fx->L_frame; i_subfr_fx += L_subfr_fx)
+ {
+ /*----------------------------------------------------------------------*
+ * Decode pitch lag
+ *----------------------------------------------------------------------*/
+ *pt_pitch_fx = pit_decode_ivas_fx(st_fx, Pitch_BR_fx, 0, st_fx->L_frame, i_subfr_fx, Pitch_CT_fx, &pitch_limit_flag, &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_subfr_fx
+#if 1//def ADD_LRTD
+ , tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf
+#endif
+ );
+ move16();
+
+ /*--------------------------------------------------------------*
+ * Find the adaptive codebook vector.
+ *--------------------------------------------------------------*/
+
+ pred_lt4(&exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_subfr_fx + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP);
+
+ /*--------------------------------------------------------------*
+ * Innovation decoding
+ *--------------------------------------------------------------*/
+
+ IF(EQ_16(use_fcb, 1))
+ {
+ inov_decode_fx(st_fx, Local_BR_fx, 0, st_fx->L_frame, 1, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx);
+ /*--------------------------------------------------------------*
+ * Gain decoding
+ * Estimate spectrum tilt and voicing
+ *--------------------------------------------------------------*/
+
+ gain_dec_mless_fx(st_fx, st_fx->L_frame, LOCAL_CT, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx);
+
+ st_fx->tilt_code_fx = est_tilt_ivas_fx(exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0
+#if 1//def ADD_LRTD
+ , L_subfr_fx, 0
+#endif
+ );
+ }
+ ELSE IF(EQ_16(use_fcb, 2)) /* IVAS only */
+ {
+ /*inov_decode_fx(st_fx, Local_BR_fx, 0, st_fx->L_frame, 1, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx);*/
+ inov_decode_fx(st_fx, st_fx->core_brate, 0, st_fx->L_frame, 0, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx);
+ /*--------------------------------------------------------------*
+ * Gain decoding
+ * Estimate spectrum tilt and voicing
+ *--------------------------------------------------------------*/
+
+ gain_dec_lbr_fx(st_fx, GENERIC, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_subfr_fx);
+
+ st_fx->tilt_code_fx = est_tilt_ivas_fx(exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0
+#if 1//def ADD_LRTD
+ , L_subfr_fx, 0
+#endif
+ );
+
+ }
+ ELSE
+ {
+ nbits = 5;
+ IF(LT_32(st_fx->core_brate, MIN_RATE_FCB))
+ {
+ nbits = 4;
+ }
+ move16();
+
+ set16_fx(code_fx, 0, L_SUBFR);
+ gain_code_fx = L_deposit_l(0);
+ st_fx->tilt_code_fx = 0;
+ move16();
+ pit_idx_fx = (Word16)get_next_indice(st_fx, nbits);
+ move16();
+
+ gain_pit_fx = add(9590,dic_gp_fx[pit_idx_fx]);
+ move16(); /*Q14 0.5853 in Q14 9590*/
+
+ if (st_fx->BER_detect) /* Bitstream is corrupted, use the past pitch gain */
+ {
+ gain_pit_fx = st_fx->lp_gainp_fx;
+ move16();
+ }
+#ifdef BASOP_NOGLOB
+ gain_code_fx = L_mult0(s_max(sub(32767, shl_o(gain_pit_fx, 1, &Overflow)), 16384), st_fx->lp_gainc_fx); /* Use gain pitch and past gain code as an indicator to help finding the best scaling value. gain_code_fx used a temp var*/
+#else
+ gain_code_fx = L_mult0(s_max(sub(32767, shl(gain_pit_fx,1)), 16384), st_fx->lp_gainc_fx); /* Use gain pitch and past gain code as an indicator to help finding the best scaling value. gain_code_fx used a temp var*/
+#endif
+ }
+
+ /*----------------------------------------------------------------------*
+ * Find the total excitation
+ *----------------------------------------------------------------------*/
+
+ Rescale_exc(hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC], hGSCDec->last_exc_dct_in_fx,
+ L_subfr_fx, L_subfr_fx * HIBND_ACB_L_FAC, gain_code_fx, &(st_fx->Q_exc), st_fx->Q_subfr, NULL, i_subfr_fx, coder_type_fx);
+
+ gain_code16 = round_fx(L_shl(gain_code_fx, st_fx->Q_exc)); /*Q_exc*/
+
+ IF(NE_16(use_fcb, 0))
+ {
+ Acelp_dec_total_exc(exc_fx, exc2_bidon - i_subfr_fx, gain_code16, gain_pit_fx, i_subfr_fx, code_fx, L_subfr_fx);
+ }
+ ELSE
+ {
+ IF(norm_s(s_or(gain_pit_fx, 1)) == 0)
+ {
+ FOR(i = 0; i < L_subfr_fx; i++)
+ {
+ L_tmp = L_shl(L_mult(gain_pit_fx, exc_fx[i + i_subfr_fx]), 1); /*Q16+Q_exc*/
+ exc_fx[i + i_subfr_fx] = round_fx(L_tmp); /*Q_exc*/
+ }
+ }
+ ELSE
+ {
+ gain_pitx2 = shl(gain_pit_fx, 1); /*Q15*/
+
+ FOR(i = 0; i < L_subfr_fx; i++)
+ {
+ L_tmp = L_mult(gain_pitx2, exc_fx[i + i_subfr_fx]); /*Q16+Q_exc*/
+ exc_fx[i + i_subfr_fx] = round_fx(L_tmp); /*Q_exc*/
+ }
+ }
+ }
+
+ IF(EQ_16(L_subfr_fx, L_FRAME16k))
+ {
+ /* update gains for FEC - equivalent to lp_gain_updt() */
+ st_fx->lp_gainp_fx = gain_pit_fx; move16();
+ st_fx->lp_gainc_fx = 0; move32();
+
+ pt_pitch_fx++;
+ *pt_pitch_fx = *(pt_pitch_fx - 1);
+ pt_pitch_fx++;
+ *pt_pitch_fx = *(pt_pitch_fx - 1);
+ pt_pitch_fx++;
+ *pt_pitch_fx = *(pt_pitch_fx - 1);
+ pt_pitch_fx++;
+ *pt_pitch_fx = *(pt_pitch_fx - 1);
+ pt_pitch_fx++;
+ move16(); move16(); move16(); move16(); move16();
+ p_Aq_fx += 5 * (M + 1);
+ }
+ ELSE IF(EQ_16(L_subfr_fx, L_FRAME16k / 2))
+ {
+ IF(i_subfr_fx == 0)
+ {
+ pt_pitch_fx++;
+ *pt_pitch_fx = *(pt_pitch_fx - 1);
+ pt_pitch_fx++;
+ p_Aq_fx += 2 * (M + 1);
+ move16(); move16(); move16(); move16();
+
+ /* update gains for FEC - equivalent to lp_gain_updt() */
+ st_fx->lp_gainp_fx = extract_h(L_mult(6554, gain_pit_fx)); /*Q14 (3/15 in Q15 9830)*/
+ st_fx->lp_gainc_fx = 0; move32();
+ }
+ ELSE
+ {
+ pt_pitch_fx++;
+ *pt_pitch_fx = *(pt_pitch_fx - 1);
+ pt_pitch_fx++;
+ *pt_pitch_fx = *(pt_pitch_fx - 1);
+ pt_pitch_fx++;
+ p_Aq_fx += 3 * (M + 1);
+ move16(); move16(); move16(); move16();
+
+ /* update gains for FEC - equivalent to lp_gain_updt() */
+ st_fx->lp_gainp_fx = extract_h(L_mult(26214, gain_pit_fx)); /*Q14 (12/15 in Q15 9830)*/
+ st_fx->lp_gainc_fx = 0; move32();
+ }
+ }
+ ELSE IF(EQ_16(L_subfr_fx, 128)) /*2*L_SUBFR*/
+ {
+ p_Aq_fx += 2 * (M + 1);
+ move16();
+ pt_pitch_fx++;
+ *pt_pitch_fx = *(pt_pitch_fx - 1);
+ move16();
+ pt_pitch_fx++;
+ *pt_gain = gain_pit_fx;
+ move16();
+ pt_gain++;
+ *pt_gain = *(pt_gain - 1);
+ move16();
+ pt_gain++;
+ IF(i_subfr_fx == 0)
+ {
+ /* update gains for FEC - equivalent to lp_gain_updt() */
+ st_fx->lp_gainp_fx = extract_h(L_mult(9830, gain_pit_fx)); /*Q14 (3/10 in Q15 9830)*/
+ st_fx->lp_gainc_fx = 0;
+ move16();
+ }
+ ELSE
+ {
+ /* update gains for FEC - equivalent to lp_gain_updt() */
+ st_fx->lp_gainp_fx = extract_h(L_mult(22938,gain_pit_fx)); /*Q14 (7/10 in Q15 22938)*/
+ st_fx->lp_gainc_fx = 0;
+ move16();
+ }
+ }
+ ELSE IF(EQ_16(L_subfr_fx, 256)) /*4*L_SUBFR*/
+ {
+ pt_pitch_fx++;
+ *pt_pitch_fx = *(pt_pitch_fx - 1);
+ move16();
+ pt_pitch_fx++;
+ *pt_pitch_fx = *(pt_pitch_fx - 1);
+ move16();
+ pt_pitch_fx++;
+ *pt_pitch_fx = *(pt_pitch_fx - 1);
+ move16();
+ pt_pitch_fx++;
+ *pt_gain = gain_pit_fx;
+ move16();
+ pt_gain++;
+ *pt_gain = *(pt_gain - 1);
+ move16();
+ pt_gain++;
+ *pt_gain = *(pt_gain - 1);
+ move16();
+ pt_gain++;
+ *pt_gain = *(pt_gain - 1);
+ move16();
+ pt_gain++;
+ p_Aq_fx += 4 * (M + 1);
+ move16();
+
+ /* update gains for FEC - equivalent to lp_gain_updt() */
+ st_fx->lp_gainp_fx = gain_pit_fx;
+ move16();
+ st_fx->lp_gainc_fx = 0;
+ move16();
+ }
+ ELSE
+ {
+ p_Aq_fx += (M + 1);
+ move16();
+ pt_pitch_fx++;
+ move16();
+ *pt_gain = gain_pit_fx;
+ move16();
+ pt_gain++;
+
+ lp_gain_updt_fx(i_subfr_fx, gain_pit_fx, 0, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, st_fx->L_frame);
+ }
+ }
+
+ return;
+}
\ No newline at end of file
diff --git a/lib_dec/dec_tran_fx.c b/lib_dec/dec_tran_fx.c
index 7e5dde3cdbefc8f3396c5dce10f294a6c09b4067..f3ff2dfec8605e20cd3752616ececbb113ba8952 100644
--- a/lib_dec/dec_tran_fx.c
+++ b/lib_dec/dec_tran_fx.c
@@ -131,7 +131,12 @@ void decod_tran_fx(
IF( Jopt_flag == 0 )
{
/* 2/3-bit decoding */
- gain_dec_tc_fx( st_fx, code_fx, i_subfr,Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx);
+ if (st_fx->element_mode == EVS_MONO) {
+ gain_dec_tc_fx(st_fx, code_fx, i_subfr, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx);
+ }
+ else {
+ gain_dec_tc_ivas_fx(st_fx, code_fx, i_subfr, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx);
+ }
}
ELSE
{
@@ -150,7 +155,7 @@ void decod_tran_fx(
/* update LP filtered gains for the case of frame erasures */
lp_gain_updt_fx( i_subfr, gain_pit_fx, L_add(norm_gain_code_fx,norm_gain_preQ_fx), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame_fx );
- st_fx->tilt_code_fx = est_tilt_fx( exc_fx+i_subfr, gain_pit_fx, code_fx, gain_code_fx,&voice_fac_fx,st_fx->Q_exc);
+ st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx+i_subfr, gain_pit_fx, code_fx, gain_code_fx,&voice_fac_fx,st_fx->Q_exc, L_SUBFR, 0);
/*----------------------------------------------------------------------*
* Find the total excitation
diff --git a/lib_dec/dec_uv_fx.c b/lib_dec/dec_uv_fx.c
index f37cee3d477a8e934d4c8a2d97bf4d011d6b54c5..8fe4e3afaa4731359c150e9cd6bf6854b4e169d0 100644
--- a/lib_dec/dec_uv_fx.c
+++ b/lib_dec/dec_uv_fx.c
@@ -7,6 +7,20 @@
#include "prot_fx1.h" /* Function prototypes */
#include "prot_fx2.h" /* Function prototypes */
+static void gain_dec_gacelp_uv(
+ Word16 index, /* i : Quantization index vector Q0 */
+ Word16 *code, /* i : algebraic code excitation Q9 */
+ Word16 *code2, /* i : algebraic code excitation Q9 */
+ Word16 mean_ener, /* i : Q8 */
+ Word16 lcode, /* i : Subframe size Q0 */
+ Word16 *gain_pit, /* o : Quantized pitch gain 1Q14 */
+ Word32 *gain_code, /* o : Quantized codebook gain Q16 */
+ Word32 *gain_code2, /* o : Quantized codebook gain Q16 */
+ Word16 *past_gpit, /* i/o: past gain of pitch 1Q14 */
+ Word32 *past_gcode, /* i/o: past energy of code Q16 */
+ Word16 *gain_inov /* o : unscaled innovation gain 3Q12 */
+);
+
/*-------------------------------------------------------------------*
* decod_unvoiced()
*
@@ -86,3 +100,256 @@ void decod_unvoiced_fx(
return;
}
+
+/*-------------------------------------------------------------------*
+ * decod_unvoiced()
+ *
+ * Decode unvoiced (UC) frames
+ *-------------------------------------------------------------------*/
+
+void decod_unvoiced_ivas_fx(
+ Decoder_State *st_fx, /* i/o: decoder static memory */
+ const Word16 *Aq_fx, /* Q12 i : LP filter coefficient */
+ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */
+ const int16_t uc_two_stage_flag, /* i : flag indicating two-stage UC */
+ const Word16 coder_type_fx, /* Q0 i : coding type */
+ Word16 *tmp_noise_fx, /* Q0 o : long term temporary noise energy */
+ Word16 *pitch_buf_fx, /* Q6 o : floating pitch values for each subframe*/
+ Word16 *voice_factors_fx, /* Q15 o : voicing factors */
+ Word16 *exc_fx, /* Q_X o : adapt. excitation exc */
+ Word16 *exc2_fx, /* Q_X o : adapt. excitation/total exc */
+ Word16 *bwe_exc_fx, /* Q_X i/o: excitation for SWB TBE */
+ Word16 Q_exc,
+ Word16 *gain_buf
+)
+{
+ Word16 gain_pit_fx = 0; /* Quantized pitch gain */
+ Word32 gain_code_fx; /* Quantized algebraic codeebook gain */
+ Word32 gain_code2_fx;
+ Word16 gain_inov_fx; /* inovation gain */
+ Word32 norm_gain_code_fx; /* normalized algebraic codeebook gain */
+ Word16 voice_fac_fx; /* Voicing factor */
+ Word16 code_fx[L_SUBFR]; /* algebraic codevector */
+ Word16 i_subfr_fx;
+ const Word16 *p_Aq_fx;
+ Word16 *pt_pitch_fx;
+ Word16 code2_fx[L_SUBFR];
+
+ test();
+ IF(EQ_16(st_fx->last_ppp_mode_dec_fx, 1) || EQ_16(st_fx->last_nelp_mode_dec_fx, 1))
+ {
+ /* SC_VBR - reset the decoder, to avoid memory not updated issue for this unrealistic case */
+ CNG_reset_dec_fx(st_fx, pitch_buf_fx, voice_factors_fx);
+ }
+
+ p_Aq_fx = Aq_fx;
+ move16(); /*Q12*/ /* pointer to interpolated LPC parameters */
+ pt_pitch_fx = pitch_buf_fx;
+ move16(); /* pointer to the pitch buffer */
+
+ FOR(i_subfr_fx = 0; i_subfr_fx < L_FRAME; i_subfr_fx += L_SUBFR)
+ {
+ if (!uc_two_stage_flag) {
+ /*----------------------------------------------------------------*
+ * Unvoiced subframe processing
+ *----------------------------------------------------------------*/
+
+ gaus_dec_fx(st_fx, i_subfr_fx, code_fx, &norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, &gain_inov_fx, &st_fx->tilt_code_fx,
+ &voice_fac_fx, &gain_pit_fx, pt_pitch_fx, exc_fx, &gain_code_fx, exc2_fx, bwe_exc_fx, &(st_fx->Q_exc), st_fx->Q_subfr);
+ }
+ else {/*----------------------------------------------------------------*
+ * Unvoiced subframe processing in two stages
+ *----------------------------------------------------------------*/
+
+ /* No adaptive codebook (UC) */
+ set16_fx(exc_fx + i_subfr_fx, 0, L_SUBFR);
+
+ *pt_pitch_fx = shl(L_SUBFR, Q6);
+
+ /*--------------------------------------------------------------*
+ * Innovation decoding
+ *--------------------------------------------------------------*/
+
+ //inov_decode(st, st->core_brate, 0, L_FRAME, 1, i_subfr, p_Aq, st->tilt_code, *pt_pitch, code, L_SUBFR);
+ inov_decode_fx(st_fx, st_fx->core_brate, 0, L_FRAME, 1, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_SUBFR);
+
+ /*-------------------------------------------------------*
+ * Generate Gaussian excitation *
+ *-------------------------------------------------------*/
+
+ //gaus_L2_dec_flt(code2, st->tilt_code, p_Aq, FORMANT_SHARPENING_G1_FLT, &(st->seed_acelp));
+ gaus_L2_dec(code2_fx, st_fx->tilt_code_fx, p_Aq_fx, FORMANT_SHARPENING_G1, &(st_fx->seed_acelp));
+
+ /*-----------------------------------------------------------------*
+ * Gain encoding
+ *-----------------------------------------------------------------*/
+
+ Word16 index = get_next_indice(st_fx, st_fx->acelp_cfg.gains_mode[i_subfr_fx / L_SUBFR]);
+ //gain_dec_gacelp_uv_flt(index, code, code2, Es_pred, L_SUBFR, &gain_pit, &gain_code, &gain_code2, &(st->past_gpit_float), &norm_gain_code, &gain_inov);
+ gain_dec_gacelp_uv(index, code_fx, code2_fx, Es_pred_fx, L_SUBFR, &gain_pit_fx, &gain_code_fx, &gain_code2_fx, &(st_fx->past_gpit), &norm_gain_code_fx, &gain_inov_fx);
+
+ //st->tilt_code = est_tilt(exc + i_subfr, gain_pit, code, gain_code, &voice_fac, L_SUBFR, 0);
+ st_fx->tilt_code_fx = est_tilt_ivas_fx(exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, Q_exc, L_SUBFR, 0);
+
+ /* update LP filtered gains for the case of frame erasures */
+ //lp_gain_updt(i_subfr, gain_pit, norm_gain_code, &st->lp_gainp, &st->lp_gainc, L_FRAME);
+ lp_gain_updt_fx(i_subfr_fx, gain_pit_fx, norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_FRAME);
+
+ /*-------------------------------------------------------*
+ * - Find the total excitation. *
+ *-------------------------------------------------------*/
+
+ for (int i = 0; i < L_SUBFR; i++)
+ {
+ /*exc2[i + i_subfr] = gain_pit * exc[i + i_subfr]; //Q14
+ exc2[i + i_subfr] += gain_code2 * code2[i]; //Q16
+ exc[i + i_subfr] = exc2[i + i_subfr] + gain_code * code[i];*/ //Q16
+ exc2_fx[i + i_subfr_fx] = shl( mult_r( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 2 ); // Q_exc
+ exc2_fx[i + i_subfr_fx] = add( exc2_fx[i + i_subfr_fx], extract_l( L_shr( Mpy_32_16_1( gain_code2_fx, code2_fx[i] ), Q10 - Q_exc ) ) ); // Q_exc
+ exc_fx[i + i_subfr_fx] = add( exc2_fx[i + i_subfr_fx], extract_l( L_shr( Mpy_32_16_1( gain_code_fx, code_fx[i] ), Q10 - Q_exc ) ) ); // Q_exc
+ }
+ //Scale_sig(code_fx, L_SUBFR, 3); //Q12
+ }
+ *tmp_noise_fx = extract_h(norm_gain_code_fx); /*Q16*/
+
+ /*----------------------------------------------------------------*
+ * Excitation enhancements (update of total excitation signal)
+ *----------------------------------------------------------------*/
+
+ /*enhancer_fx(st_fx->core_brate, 0, coder_type_fx, i_subfr_fx, L_FRAME, voice_fac_fx, st_fx->stab_fac_fx,
+ norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &(st_fx->dm_fx), st_fx->Q_exc);*/
+ enhancer_ivas_fx(MODE1, st_fx->core_brate, uc_two_stage_flag, 0, coder_type_fx, i_subfr_fx, L_FRAME, voice_fac_fx, st_fx->stab_fac_fx,
+ norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx/*Q9/Q12?*/, exc2_fx, gain_pit_fx, &(st_fx->dm_fx), st_fx->Q_exc);
+
+ voice_factors_fx[i_subfr_fx / L_SUBFR] = 0;
+ move16();
+
+ interp_code_5over2_fx(&exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC], L_SUBFR);
+
+ p_Aq_fx += (M + 1);
+ move16();
+ pt_pitch_fx++;
+ st_fx->tilt_code_dec_fx[i_subfr_fx / L_SUBFR] = st_fx->tilt_code_fx;
+ move16();
+ }
+
+ /* SC-VBR */
+ st_fx->prev_gain_pit_dec_fx = gain_pit_fx;
+ move16();
+
+ set16_fx(gain_buf, 0, NB_SUBFR);
+
+ return;
+}
+
+
+/*---------------------------------------------------------------------*
+ * gain_dec_gacelp_uv
+ *
+ * Decoding of pitch and codebook gains for Unvoiced mode
+ *---------------------------------------------------------------------*/
+
+static void gain_dec_gacelp_uv(
+ Word16 index, /* i : Quantization index vector Q0 */
+ Word16 *code, /* i : algebraic code excitation Q9 */
+ Word16 *code2, /* i : algebraic code excitation Q9 */
+ Word16 mean_ener, /* i : Q8 */
+ Word16 lcode, /* i : Subframe size Q0 */
+ Word16 *gain_pit, /* o : Quantized pitch gain 1Q14 */
+ Word32 *gain_code, /* o : Quantized codebook gain Q16 */
+ Word32 *gain_code2, /* o : Quantized codebook gain Q16 */
+ Word16 *past_gpit, /* i/o: past gain of pitch 1Q14 */
+ Word32 *past_gcode, /* i/o: past energy of code Q16 */
+ Word16 *gain_inov /* o : unscaled innovation gain 3Q12 */
+)
+{
+ Word16 i, exp_L_tmp1;
+ Word16 exp_gcode;
+ Word16 g_code;
+ Word32 L_tmp, L_tmp1;
+ Word32 pred_nrg_frame;
+ Word16 exp_gcode2, g_code2, norm_code2;
+ Word16 index2, s;
+
+
+
+
+ /* pred_nrg_frame = (float)pow(10.0,mean_ener/20.0); */
+ L_tmp = L_mult(mean_ener, 10885/*0.166096f * 2 Q15*/); /* 6Q25 */
+ pred_nrg_frame = BASOP_Util_InvLog2(L_sub(L_tmp, 503316480l/*15.f Q25*/)); /* 15Q16 */
+
+ /*-----------------------------------------------------------------*
+ * Prediction gains
+ *-----------------------------------------------------------------*/
+ /* gain_inov = 1.0f / sqrt((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */
+ L_tmp = calc_gain_inov(code, lcode, NULL, NULL);
+ *gain_inov = round_fx(L_shl(L_tmp, 15 - 3)); /* gain_inov in Q12 */
+
+ /* gcode = pred_nrg_frame * (*gain_inov); */
+ L_tmp = Mpy_32_16_1(pred_nrg_frame, *gain_inov); /* 18Q13 */
+ i = norm_l(L_tmp);
+ g_code = round_fx(L_shl(L_tmp, i));
+ exp_gcode = sub(18, i);
+
+ /* norm_code2 = 1.0f / sqrt((dot_product(code2, code2, lcode) + 0.01f) / lcode); */
+ L_tmp = calc_gain_inov(code2, lcode, NULL, NULL);
+ norm_code2 = round_fx(L_shl(L_tmp, 15 - 3)); /* Q12 */
+
+ /* g_code2 = pred_nrg_frame * norm_code2; */
+ L_tmp = Mpy_32_16_1(pred_nrg_frame, norm_code2); /* 18Q13 */
+ i = norm_l(L_tmp);
+ g_code2 = round_fx(L_shl(L_tmp, i));
+ exp_gcode2 = sub(18, i);
+
+ /*-----------------------------------------------------------------*
+ * Decode pitch gain
+ *-----------------------------------------------------------------*/
+ *gain_pit = 0;
+ move16();
+ *past_gpit = *gain_pit;
+ move16();
+
+ /*-----------------------------------------------------------------*
+ * past gains for error concealment
+ *-----------------------------------------------------------------*/
+ index2 = shr(index, 5);
+ index = s_and(index, 0x1F);
+
+ /**gain_code= (float)pow(10.f,(((index*1.25f)-20.f)/20.f))*gcode;*/
+
+ L_tmp = L_mac(-111465139l/*-0.166096*20.0f Q25*/, shl(index, 16 - 7), 6803/*0.166096f*1.25f Q15*/);
+
+ i = add(1, extract_l(L_shr(L_tmp, 25)));
+ L_tmp = L_lshl(L_tmp, 6);
+ L_tmp = L_and(0x7FFFFFFF, L_tmp);
+
+ L_tmp = Pow2(30, round_fx(L_tmp));
+ L_tmp = L_shl(L_tmp, i - (31 - 16)); /* Q16 */
+
+ /* *past_gcode = L_tmp * pred_nrg_frame; */
+ i = norm_l(L_tmp);
+ L_tmp1 = L_shl(L_tmp, i);
+ exp_L_tmp1 = sub(15, i);
+
+ i = norm_l(pred_nrg_frame);
+ L_tmp1 = Mpy_32_32(L_tmp1, L_shl(pred_nrg_frame, i));
+ exp_L_tmp1 = add(exp_L_tmp1, sub(15, i));
+
+ *past_gcode = L_shl(L_tmp1, sub(exp_L_tmp1, 15)); /* Q16 */ move32();
+
+ *gain_code = L_shl(Mpy_32_16_1(*past_gcode, *gain_inov), 3);
+ move32();
+
+
+ L_tmp = Mpy_32_16_1(*gain_code, BASOP_Util_Divide1616_Scale(g_code2, g_code, &s));
+ L_tmp = L_shl(L_tmp, sub(sub(add(s, exp_gcode2), exp_gcode), 2)); /* Q16 */
+ L_tmp1 = L_add(L_tmp, 0);
+ FOR(i = 0; i < index2; i++)
+ {
+ L_tmp1 = L_add(L_tmp1, L_tmp);
+ }
+ *gain_code2 = L_tmp1;
+
+
+ return;
+}
\ No newline at end of file
diff --git a/lib_dec/evs_dec.c b/lib_dec/evs_dec.c
index 90b425678770311875be3569946e45df16d7cb1c..744daf9a548048272cdc4a466fc0ad96c24b94f1 100644
--- a/lib_dec/evs_dec.c
+++ b/lib_dec/evs_dec.c
@@ -45,6 +45,40 @@
#include "prot_fx1.h"
#include "prot_fx2.h"
#endif
+
+#ifdef IVAS_FLOAT_FIXED
+static Word16 norm_arr_l(float *arr, int size);
+static Word16 norm(float num);
+
+static Word16 norm(float num) {
+ if ((Word32)num == 0) return 31;
+ return norm_l((Word32)num);
+}
+static Word16 norm_arr_l(float *arr, int size)
+{
+ Word16 q = 31;
+ for (int i = 0; i < size; i++)
+ if (arr[i] != 0)
+ {
+ q = min(q, norm(arr[i]));
+ }
+ return q;
+}
+static Word16 s_norm(float num) {
+ if ((Word16)num == 0) return 15;
+ return norm_s((Word16)num);
+}
+static Word16 norm_arr_s(float *arr, int size)
+{
+ Word16 q = 15;
+ for (int i = 0; i < size; i++)
+ if (arr[i] != 0)
+ {
+ q = min(q, s_norm(arr[i]));
+ }
+ return q;
+}
+#endif
/*--------------------------------------------------------------------------*
* evs_dec_flt()
*
@@ -513,7 +547,20 @@ ivas_error evs_dec_flt(
*---------------------------------------------------------------------*/
push_wmops( "BWE_decoding" );
+#ifdef IVAS_FLOAT_FIXED
+ Word32 old_syn_12k8_16k_fx[L_FRAME16k];
+ Word16 norm = norm_arr_l(old_syn_12k8_16k, L_FRAME), q_old_syn, q_audio;
+ Word16 gb = find_guarded_bits_fx(L_FRAME16k);
+ floatToFixed_arrL(old_syn_12k8_16k, old_syn_12k8_16k_fx, norm - gb, L_FRAME16k);
+ q_old_syn = norm - gb;
+ norm = norm_arr_s(st->t_audio_q, L_FRAME);
+ gb = find_guarded_bits_fx(L_FRAME);
+ floatToFixed_arr(st->t_audio_q, st->t_audio_q_fx, norm - gb, L_FRAME);
+ q_audio = norm - gb;
+ ivas_bw_switching_pre_proc_fx(st, -1, 1, old_syn_12k8_16k_fx, q_old_syn, q_audio);
+#else
bw_switching_pre_proc( st, old_syn_12k8_16k, -1, 1 );
+#endif
/*---------------------------------------------------------------------*
* WB TBE decoding
diff --git a/lib_dec/fd_cng_dec.c b/lib_dec/fd_cng_dec.c
index a1fe9e106452fd81575bc25766181eb51256f775..fe75a28b238e061f41c10ddd22e8e67197b1f8fe 100644
--- a/lib_dec/fd_cng_dec.c
+++ b/lib_dec/fd_cng_dec.c
@@ -48,6 +48,8 @@
#include "prot_fx1.h"
#include "prot_fx2.h"
#include "ivas_prot_fx.h"
+#include "basop_util.h"
+#include "rom_basop_util.h"
/*-------------------------------------------------------------------
* Local constants
@@ -570,6 +572,11 @@ void configureFdCngDec_fx(
hsCom->fftSineTab_flt = NULL;
hsCom->olapWinAna_flt = olapWinAna512;
hsCom->olapWinSyn_flt = olapWinSyn256;
+
+ hsCom->fftlenShift = 8;
+ move16();
+ hsCom->fftlenFac = 32767/*1.0 Q15*/;
+ move16();
BREAK;
case 640:
hsCom->olapWinAna_fx = olapWinAna640_fx;
@@ -580,11 +587,18 @@ void configureFdCngDec_fx(
hsCom->fftSineTab_flt = fftSineTab640;
hsCom->olapWinAna_flt = olapWinAna640;
hsCom->olapWinSyn_flt = olapWinSyn320;
+
+ hsCom->fftlenShift = 9;
+ move16();
+ hsCom->fftlenFac = 20480/*0.625 Q15*/;
+ move16();
BREAK;
default:
assert( !"Unsupported FFT length for FD-based CNG" );
BREAK;
}
+ BASOP_getTables(&hsCom->olapWinAna, NULL, NULL, shr(hsCom->fftlen, 1));
+ BASOP_getTables(&hsCom->olapWinSyn, NULL, NULL, shr(hsCom->fftlen, 2));
hsCom->frameSize = shr( hsCom->fftlen, 1 );
return;
@@ -1568,6 +1582,108 @@ void FdCng_decodeSID_flt(
}
+
+#ifdef IVAS_FLOAT_FIXED
+/*-------------------------------------------------------------------
+ * FdCng_decodeSID_flt()
+ *
+ * Decode the FD-CNG bitstream
+ *-------------------------------------------------------------------*/
+
+void FdCng_decodeSID_ivas_fx(
+ Decoder_State *st /* i/o: decoder state structure */
+)
+{
+ int16_t N;
+ Word32 *sidNoiseEst;
+ Word32 gain;
+ Word16 i, index;
+ Word32 v[32];
+ Word16 indices[32];
+ HANDLE_FD_CNG_COM hFdCngCom;
+ Word32 *invTrfMatrix_fx;
+ Word32 tmpRAM_fx[FDCNG_VQ_MAX_LEN][FDCNG_VQ_DCT_MAXTRUNC];
+
+ const Word16 gain_q_offset = (Word16)((st->element_mode == EVS_MONO) ? GAIN_Q_OFFSET_EVS : GAIN_Q_OFFSET_IVAS); //Q0
+
+ invTrfMatrix_fx = (Word32 *)tmpRAM_fx;
+
+ hFdCngCom = (st->hFdCngDec)->hFdCngCom;
+
+ sidNoiseEst = hFdCngCom->sidNoiseEst;
+
+ N = hFdCngCom->npart;
+ gain = 0;
+ hFdCngCom->sid_frame_counter++;
+
+ /* Read bitstream */
+ for (i = 0; i < FD_CNG_stages_37bits; i++)
+ {
+ indices[i] = get_next_indice(st, bits_37bits[i]);
+ }
+
+ index = get_next_indice(st, 7);
+
+ /* MSVQ decoder */
+
+ if (st->element_mode != EVS_MONO)
+ {
+ create_IDCT_N_Matrix_fx(invTrfMatrix_fx, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, sizeof(tmpRAM_fx) / (sizeof(Word32)));
+ msvq_dec_fx(ivas_cdk_37bits_fx, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 1, invTrfMatrix_fx, v, NULL, 7);
+ }
+ else
+ { /* Legacy EVS_MONO MSVQ tables */
+ msvq_dec_fx(cdk_37bits, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 0, NULL, v, NULL, 7);
+ }
+
+
+ /* Decode gain */
+ //gain = ((float)index - gain_q_offset) / 1.5f;
+ gain = L_mult0((index - gain_q_offset), 21845); // Q15
+
+ /* Apply gain and undo log */
+ Word16 res_exp[NPART];
+ Word16 max_res_exp = 0;
+ for (i = 0; i < N; i++)
+ {
+ //sidNoiseEst_flt[i] = (float)pow(10.f, (v[i] + gain) / 10.f);
+ sidNoiseEst[i] = BASOP_util_Pow2( Mpy_32_32( L_add(v[i], gain), LOG_10_BASE_2_BY_10_Q31), Q16, &res_exp[i]);
+ if (max_res_exp < res_exp[i]) {
+ max_res_exp = res_exp[i];
+ }
+ }
+
+ for (i = 0; i < N; i++) {
+ sidNoiseEst[i] = L_shr(sidNoiseEst[i], max_res_exp - res_exp[i]);
+ }
+
+ hFdCngCom->sidNoiseEstExp = max_res_exp;
+
+ /* NB last band energy compensation */
+
+ if (hFdCngCom->CngBandwidth == NB)
+ {
+ //sidNoiseEst_flt[N - 1] *= NB_LAST_BAND_SCALE_FLT;
+ sidNoiseEst[N - 1] = Mpy_32_16_1(sidNoiseEst[N - 1], NB_LAST_BAND_SCALE);
+ }
+
+ if (hFdCngCom->CngBandwidth == SWB && hFdCngCom->CngBitrate <= ACELP_13k20)
+ {
+ //sidNoiseEst_flt[N - 1] *= SWB_13k2_LAST_BAND_SCALE_FLT;
+ sidNoiseEst[N - 1] = Mpy_32_16_1(sidNoiseEst[N - 1], SWB_13k2_LAST_BAND_SCALE);
+ }
+
+ //scalebands_flt(sidNoiseEst_flt, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, hFdCngCom->cngNoiseLevel_flt, 1);
+ scalebands(sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, hFdCngCom->cngNoiseLevel, 1);
+ hFdCngCom->cngNoiseLevelExp = hFdCngCom->sidNoiseEstExp;
+
+ //lpc_from_spectrum_flt(hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, st->preemph_fac_float);
+ lpc_from_spectrum(hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, st->preemph_fac);
+
+ return;
+}
+#endif
+
/*-------------------------------------------------------------------
* noisy_speech_detection_flt()
*
@@ -2733,6 +2849,199 @@ void generate_stereo_masking_noise_fx(
return;
}
+
+
+/*-------------------------------------------------------------------
+ * generate_stereo_masking_noise_16fx()
+ *
+ * Generate additional comfort noise (kind of noise filling)
+ *-------------------------------------------------------------------*/
+
+void generate_stereo_masking_noise_16fx(
+ Word16 *syn, /* i/o: time-domain signal */
+ Word16 Q_syn,
+ Decoder_State *st, /* i/o: decoder state structure */
+ STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i : TD stereo structure */
+ const int16_t flag_sec_CNA, /* i : CNA flag for secondary channel */
+ const int16_t fadeOut, /* i : only fade out of previous state */
+ STEREO_CNG_DEC_HANDLE hStereoCng, /* i : Stereo CNG handle */
+ const int16_t nchan_out /* i : number of output channels */
+)
+{
+ HANDLE_FD_CNG_COM hFdCngCom;
+ Word32 gamma_fx, scale_fx /*, SP_ratio_fx needs to be integrated*/;
+ Word32 Np_fx[L_FRAME16k];
+ Word32 Ns_fx[L_FRAME16k];
+ Word32 N1_fx[L_FRAME16k];
+ Word32 N2_fx[L_FRAME16k];
+ Word16 N1_fx_exp, N2_fx_exp;
+ int16_t i;
+
+ IF(st->idchan == 0)
+ {
+ hFdCngCom = st->hFdCngDec->hFdCngCom;
+ // mvr2r(hStereoCng->olapBufferSynth22, Ns, hFdCngCom->frameSize / 2);
+ // mvr2r(hFdCngCom->olapBufferSynth2_flt, Np, hFdCngCom->frameSize / 2);
+ for (i = 0; i < hFdCngCom->frameSize / 2; i++)
+ {
+ Ns_fx[i] = float_to_fix(hStereoCng->olapBufferSynth22[i], Q6);
+ Np_fx[i] = float_to_fix(hFdCngCom->olapBufferSynth2_flt[i], Q6);
+ }
+ set_l(&Np_fx[hFdCngCom->frameSize / 2], 0, hFdCngCom->frameSize / 2);
+ set_l(&Ns_fx[hFdCngCom->frameSize / 2], 0, hFdCngCom->frameSize / 2);
+
+ IF(!fadeOut)
+ {
+ // generate_masking_noise_flt(N1, hFdCngCom, hFdCngCom->frameSize, 0, 1, 0, st->element_mode, hStereoCng, nchan_out);
+ generate_masking_noise_ivas_fx(N1_fx, &N1_fx_exp, hFdCngCom, hFdCngCom->frameSize, 0, 1, 0, st->element_mode, hStereoCng, nchan_out); // N1_fx Q6
+ /* Generate masking noise for secondary channel */
+ IF(flag_sec_CNA)
+ {
+ // generate_masking_noise_flt(N2, hFdCngCom, hFdCngCom->frameSize, 0, 1, 1, st->element_mode, hStereoCng, nchan_out);
+ generate_masking_noise_ivas_fx(N2_fx, &N2_fx_exp, hFdCngCom, hFdCngCom->frameSize, 0, 1, 1, st->element_mode, hStereoCng, nchan_out); // N2_fx Q6
+ // gamma = hStereoCng->c_PS_LT * hStereoCng->c_PS_LT;
+ gamma_fx = float_to_fix(hStereoCng->c_PS_LT * hStereoCng->c_PS_LT, Q30);
+ // scale = 1.0f;
+ scale_fx = ONE_IN_Q30;
+ // if (gamma < 0.9f)
+ IF(gamma_fx < 966367642)
+ {
+ // gamma = gamma / (1 - gamma);
+ // gamma = (float)sqrt(gamma + 1) - (float)sqrt(gamma);
+ // scale = 1.0f / (float)sqrt(1 + gamma * gamma);
+ Word16 exp_gamma = 0;
+ Word16 divisor1 = Inv16((Word16)L_shr(L_sub(ONE_IN_Q30, gamma_fx), Q15), &exp_gamma); // Q15-exp_gamma
+ gamma_fx = L_shl(Mpy_32_16_1(gamma_fx, divisor1), exp_gamma); // Q30
+ Word16 exp_gamma1 = Q1, exp_gamma2 = Q1, exp_gamma3 = Q1;
+ gamma_fx = Sqrt32(L_add(gamma_fx, ONE_IN_Q30), &exp_gamma1);
+ // gamma_fx = L_shl( gamma_fx, exp_gamma1 );
+ Word32 temp = Sqrt32(gamma_fx, &exp_gamma2); // Q31-exp_gamma1
+ gamma_fx = L_sub(gamma_fx, L_shl(temp, exp_gamma2 - exp_gamma1)); // Q31-exp_gamma1
+ gamma_fx = L_shl(gamma_fx, exp_gamma1 - Q1); // Q30
+ Word32 divisor2 = Sqrt32(L_add(ONE_IN_Q30, L_shl(Mpy_32_32(gamma_fx, gamma_fx), Q1)), &exp_gamma3); // Q31 - exp_gamma3
+ scale_fx = L_shl(divide3232(ONE_IN_Q30, divisor2), Q15 + exp_gamma3); // Q30
+ }
+ ELSE
+ {
+ gamma_fx = 0;
+ }
+
+ FOR(i = 0; i < 2 * hFdCngCom->frameSize / 4; i++)
+ {
+ // Np[i] += scale * (N1[i] + gamma * N2[i]);
+ // Ns[i] += scale * sign(hStereoCng->c_PS_LT) * (N1[i] - gamma * N2[i]);
+ Np_fx[i] = L_add(Np_fx[i],
+ Mpy_32_32(scale_fx, L_shl(L_add(N1_fx[i], Mpy_32_32(gamma_fx, L_shl(N2_fx[i], Q1))), Q1))); // Q6
+ Word32 add2 = Mpy_32_32(scale_fx, L_shl(L_sub(N1_fx[i], Mpy_32_32(gamma_fx, L_shl(N2_fx[i], Q1))), Q1)); // Q6
+ if (hStereoCng->c_PS_LT < 0.0f)
+ {
+ add2 = L_negate(add2);
+ }
+ Ns_fx[i] = L_add(Ns_fx[i], add2);
+ }
+ FOR(; i < hFdCngCom->frameSize; i++)
+ {
+ // Np[i] = scale * (N1[i] + gamma * N2[i]);
+ // Ns[i] = scale * sign(hStereoCng->c_PS_LT) * (N1[i] - gamma * N2[i]);
+ Np_fx[i] = Mpy_32_32(scale_fx, L_shl(L_add(N1_fx[i], Mpy_32_32(gamma_fx, L_shl(N2_fx[i], Q1))), Q1)); // Q6
+ Ns_fx[i] = Mpy_32_32(scale_fx, L_shl(L_sub(N1_fx[i], Mpy_32_32(gamma_fx, L_shl(N2_fx[i], Q1))), Q1)); // Q6
+ IF(hStereoCng->c_PS_LT < 0.0f)
+ {
+ Ns_fx[i] = L_negate(Ns_fx[i]);
+ }
+ }
+ /* Below code to be converted */
+ //float gamma = fix_to_float(gamma_fx, Q30);
+ //float scale = fix_to_float(scale_fx, Q30);
+ //scale *= (float)(hFdCngCom->fftlen / 2);
+ Word32 scale_fx_tmp = Mpy_32_32(scale_fx, L_shl(hFdCngCom->fftlen / 2, Q22)); // Q21
+ // scale_fx = L_shr(scale_fx, Q1) * hFdCngCom->fftlen;
+ for (i = 0; i < hFdCngCom->frameSize / 2; i++)
+ {
+ //hFdCngCom->olapBufferSynth2_flt[i] = scale * (hFdCngCom->olapBufferSynth2_flt[i + 5 * hFdCngCom->frameSize / 4] + gamma * hStereoCng->olapBufferSynth22[i + 5 * hFdCngCom->frameSize / 4]);
+ //hStereoCng->olapBufferSynth22[i] = sign(hStereoCng->c_PS_LT) * scale * (hFdCngCom->olapBufferSynth2_flt[i + 5 * hFdCngCom->frameSize / 4] - gamma * hStereoCng->olapBufferSynth22[i + 5 * hFdCngCom->frameSize / 4]);
+ hFdCngCom->olapBufferSynth2[i] = (Word16)L_shr(Mpy_32_32(scale_fx_tmp,
+ L_add(L_shr(hFdCngCom->olapBufferSynth2[i + 5 * hFdCngCom->frameSize / 4], Q15),
+ Mpy_32_16_1(gamma_fx, hStereoCng->olapBufferSynth22_fx[i + 5 * hFdCngCom->frameSize / 4]))),
+ Q14); // Q_olap
+ hStereoCng->olapBufferSynth22_fx[i] = (Word16)L_shr(Mpy_32_32(scale_fx_tmp,
+ L_sub(L_shr(hFdCngCom->olapBufferSynth2[i + 5 * hFdCngCom->frameSize / 4], Q15),
+ Mpy_32_16_1(gamma_fx, hStereoCng->olapBufferSynth22_fx[i + 5 * hFdCngCom->frameSize / 4]))),
+ Q14); // Q_olap
+ }
+ }
+ else
+ {
+ FOR( i = 0; i < hFdCngCom->frameSize / 2; i++ )
+ {
+ // Np[i] += N1[i];
+ Np_fx[i] = L_add( Np_fx[i], N1_fx[i] ); // Q6
+ }
+ // mvr2r(&N1[hFdCngCom->frameSize / 2], &Np[hFdCngCom->frameSize / 2], hFdCngCom->frameSize / 2);
+ mvl2l( &N1_fx[hFdCngCom->frameSize / 2], &Np_fx[hFdCngCom->frameSize / 2], hFdCngCom->frameSize / 2 );
+ // float scale = (float)(hFdCngCom->fftlen / 2);
+ scale_fx = L_shl( hFdCngCom->fftlen / 2, Q22 ); // Q21
+ for ( i = 0; i < hFdCngCom->frameSize; i++ )
+ {
+ // hFdCngCom->olapBufferSynth2_flt[i] = scale * hFdCngCom->olapBufferSynth2_flt[i + 5 * hFdCngCom->frameSize / 4];
+ hFdCngCom->olapBufferSynth2[i] = (Word16) L_shr( Mpy_32_16_1( scale_fx, hFdCngCom->olapBufferSynth2[i + 5 * hFdCngCom->frameSize / 4] ), Q6 ); // Q_olap
+ }
+ }
+ }
+ else
+ {
+ set_s(hFdCngCom->olapBufferSynth2, 0, hFdCngCom->frameSize / 2);
+ set_s(hStereoCng->olapBufferSynth22_fx, 0, hFdCngCom->frameSize / 2);
+ }
+ if (flag_sec_CNA)
+ {
+ // mvr2r(Ns, hStereoCng->maskingNoiseS, hFdCngCom->frameSize);
+ for (i = 0; i < hFdCngCom->frameSize; i++)
+ {
+ hStereoCng->maskingNoiseS[i] = fix_to_float(Ns_fx[i], Q6);
+ }
+ hStereoCng->enableSecCNA = 1;
+ }
+ else
+ {
+ set_s(hStereoCng->olapBufferSynth22_fx, 0, hFdCngCom->frameSize);
+ }
+
+ /* add masking noise */
+ // v_add(Np, syn, syn, hFdCngCom->frameSize);
+ for (i = 0; i < hFdCngCom->frameSize; i++)
+ {
+ syn[i] = syn[i] + (Word16)L_shr(Np_fx[i], Q16 + Q6 - Q_syn); // Q_syn
+ }
+ }
+ else if (hStereoCng->enableSecCNA)
+ {
+ //float SP_ratio = hStereoTD->SP_ratio_LT; /* Use long-term SP ratio based on L/R synthesis */
+ Word16 SP_ratio_fx = float_to_fix16(hStereoTD->SP_ratio_LT, Q15); /* Use long-term SP ratio based on L/R synthesis */
+ Word16 prevSP_ratio_fx = float_to_fix16(hStereoTD->prevSP_ratio, Q15); /* Use long-term SP ratio based on L/R synthesis */
+ /* scale and add masking noise */
+ for (i = 0; i < *hStereoCng->frameSize / 4; i++)
+ {
+ //float scale = ( ( hStereoTD->prevSP_ratio * ( *hStereoCng->frameSize / 4 - (float) i ) + SP_ratio * (float) i ) / ( *hStereoCng->frameSize / 4 ) );
+ Word16 scale_fx_tmp = (Word16)(((Word32)prevSP_ratio_fx * (*hStereoCng->frameSize / 4 - i) + SP_ratio_fx * i) / (*hStereoCng->frameSize / 4)); //Q15
+ //syn[i] += scale * hStereoCng->maskingNoiseS[i];
+ syn[i] = add(syn[i], mult(scale_fx_tmp, float_to_fix16(hStereoCng->maskingNoiseS[i], Q15)));
+ }
+ for (; i < *hStereoCng->frameSize / 2; i++)
+ {
+ //syn[i] += SP_ratio * hStereoCng->maskingNoiseS[i];
+ syn[i] = add(syn[i], mult(SP_ratio_fx, float_to_fix16(hStereoCng->maskingNoiseS[i], Q15)));
+ }
+ for (; i < *hStereoCng->frameSize; i++)
+ {
+ //syn[i] += SP_ratio * hStereoCng->maskingNoiseS[i];
+ syn[i] = add(syn[i], mult(SP_ratio_fx, float_to_fix16(hStereoCng->maskingNoiseS[i], Q15)));
+ }
+ hStereoTD->prevSP_ratio = hStereoTD->SP_ratio_LT;
+ }
+
+ return;
+}
#endif
/*-------------------------------------------------------------------
diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c
index eebd085cd6d43cde98043204cd518de4df803262..b215d98b4f36c8e50e6df347c00cfc1eed576ef7 100644
--- a/lib_dec/fd_cng_dec_fx.c
+++ b/lib_dec/fd_cng_dec_fx.c
@@ -2958,6 +2958,11 @@ void FdCng_decodeSID (HANDLE_FD_CNG_COM st, Decoder_State *corest)
Word16 sidNoiseEst_Exp;
Word16 preemph_fac;
+#ifdef IVAS_FLOAT_FIXED
+ Word32 *invTrfMatrix_fx;
+ Word32 tmpRAM_fx[FDCNG_VQ_MAX_LEN][FDCNG_VQ_DCT_MAXTRUNC];
+ invTrfMatrix_fx = (Word32 *)tmpRAM_fx;
+#endif
sidNoiseEst = st->sidNoiseEst;
@@ -2980,20 +2985,30 @@ void FdCng_decodeSID (HANDLE_FD_CNG_COM st, Decoder_State *corest)
index = get_next_indice(corest, 7);
/* MSVQ decoder */
- msvq_decoder (
- cdk_37bits,
- stages_37bits,
- N,
- maxN_37bits,
- indices,
- v16
- );
-
- FOR (i=0; ielement_mode != EVS_MONO) {
+ create_IDCT_N_Matrix_fx(invTrfMatrix_fx, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, sizeof(tmpRAM_fx) / (sizeof(Word32)));
+ msvq_dec_fx(ivas_cdk_37bits_fx, NULL, NULL, stages_37bits, N, maxN_37bits, indices, 1, invTrfMatrix_fx, v, NULL, 7);
+ }
+ else
+#endif
{
- v[i] = L_deposit_h(v16[i]);
+ msvq_decoder(
+ cdk_37bits,
+ stages_37bits,
+ N,
+ maxN_37bits,
+ indices,
+ v16
+ );
+
+ FOR(i = 0; i < N; i++)
+ {
+ v[i] = L_deposit_h(v16[i]);
+ }
}
+
/* decode gain, format gain: Q9.23 */
gain = L_shl(L_deposit_l(index),WORD32_BITS-1-8);
gain = L_sub(gain,503316480l/*60.0 Q23*/);
diff --git a/lib_dec/gain_dec_fx.c b/lib_dec/gain_dec_fx.c
index 360d05a87515cded5f8420d95a2308b4b00ba7f2..ae2980894ada757899237f6c471f9fcdefc28f6d 100644
--- a/lib_dec/gain_dec_fx.c
+++ b/lib_dec/gain_dec_fx.c
@@ -53,7 +53,7 @@ void Es_pred_dec_fx(
*Es_pred = Es_pred_qua_4b_fx[enr_idx];
move16();
BREAK;
-#ifdef IVAS_GAIN_MOD
+#if 1//def IVAS_GAIN_MOD
case 3:
*Es_pred = Es_pred_qua_3b_fx[enr_idx];
break;
@@ -64,7 +64,7 @@ void Es_pred_dec_fx(
BREAK;
}
}
-#ifdef IVAS_GAIN_MOD
+#if 1//def IVAS_GAIN_MOD
ELSE
{
*Es_pred = Es_pred_qua_4b_no_ltp_fx[enr_idx];
@@ -201,6 +201,138 @@ void gain_dec_tc_fx(
return;
}
+
+/*======================================================================================*/
+/* FUNCTION : void gain_dec_tc_ivas_fx () */
+/*--------------------------------------------------------------------------------------*/
+/* PURPOSE : Decoding of pitch and codebook gains and updating long term energies */
+/*--------------------------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* Word32 core_brate_fx i : core bitrate */
+/* Word16 *code_fx i : algebraic code excitation */
+/* Word16 L_frame_fx i : length of the frame */
+/* Word16 i_subfr_fx i : subframe number */
+/* Word16 tc_subfr_fx i : TC subframe index */
+/* Word16 Es_pred_fx i : predicted scaled innov. energy Q8 */
+/*--------------------------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* Word16 *gain_pit_fx o : pitch gain Q14 */
+/* Word32 *gain_code_fx o : Quantized codeebook gain Q16 */
+/* Word16 *gain_inov_fx o : unscaled innovation gain Q12 */
+/* Word32 *norm_gain_code_fx o : norm. gain of the codebook excit. Q16 */
+/*--------------------------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/*--------------------------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : */
+/* _ None */
+/*--------------------------------------------------------------------------------------*/
+/* CALLED FROM : */
+/*======================================================================================*/
+
+void gain_dec_tc_ivas_fx(
+ Decoder_State *st_fx, /* i/o: decoder state structure */
+ const Word16 *code_fx, /* i : algebraic code excitation */
+ const Word16 i_subfr_fx, /* i : subframe number */
+ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */
+ Word16 *gain_pit_fx, /* o : pitch gain */
+ Word32 *gain_code_fx, /* o : Quantized codeebook gain */
+ Word16 *gain_inov_fx, /* o : unscaled innovation gain */
+ Word32 *norm_gain_code_fx /* o : norm. gain of the codebook excit. */
+)
+{
+ Word16 index, nBits;
+ Word16 gcode0_fx;
+ Word16 Ei_fx;
+ Word16 expg, expg2, e_tmp, f_tmp, exp_gcode0, tmp_fx, frac;
+ Word32 L_tmp, L_tmp1;
+ Word16 wgain_code=0;
+ move16();
+ *gain_pit_fx = 0;
+ move16();
+
+ /*----------------------------------------------------------------*
+ * find number of bits for gain dequantization
+ *----------------------------------------------------------------*/
+ nBits = st_fx->acelp_cfg.gains_mode[shr(i_subfr_fx, 6)];
+ /*-----------------------------------------------------------------*
+ * calculate the predicted gain code
+ *-----------------------------------------------------------------*/
+
+ /*Ecode = (dotp( code, code, L_SUBFR) + 0.01f) / L_SUBFR;
+ *gain_inov = 1.0f / (float)sqrt( Ecode );*/
+ L_tmp = Dot_product12(code_fx, code_fx, L_SUBFR, &expg);
+ expg = sub(expg, 18 + 6); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */
+ expg2 = expg;
+ move16();
+ L_tmp1 = L_tmp; /* sets to 'L_tmp' in 1 clock */
+ move32();
+ L_tmp = Isqrt_lc(L_tmp, &expg);
+
+ *gain_inov_fx = extract_h(L_shl(L_tmp, sub(expg, 3)));
+ move16(); /* gain_inov in Q12 */
+
+
+ /* Ei = 10 * (float)log10( Ecode );*/
+ e_tmp = norm_l(L_tmp1);
+ f_tmp = Log2_norm_lc(L_shl(L_tmp1, e_tmp));
+ e_tmp = sub(expg2,add(1,e_tmp));
+ L_tmp1 = Mpy_32_16(e_tmp, f_tmp, 12330); /* Q13 */ /* 10*log10(2) in Q12*/
+ Ei_fx = round_fx(L_shl(L_tmp1, 11)); /* Q8 */
+ /* gcode0 = (float) pow(10, 0.05 * (Es_pred - Ei));*/
+ gcode0_fx = sub(Es_pred_fx, Ei_fx); /* Q8 */
+
+ /*-----------------------------------------------------------------*
+ * gcode0 = pow(10.0, gcode0/20)
+ * = pow(2, 3.321928*gcode0/20)
+ * = pow(2, 0.166096*gcode0)
+ *-----------------------------------------------------------------*/
+ L_tmp = L_mult(gcode0_fx, 21771); /* *0.166096 in Q17 -> Q26 */
+ L_tmp = L_shr(L_tmp, 10); /* From Q26 to Q16 */
+ frac = L_Extract_lc(L_tmp, &exp_gcode0); /* Extract exponent of gcode0 */
+ gcode0_fx = extract_l(Pow2(14, frac));/* Put 14 as exponent so that */
+ /* output of Pow2() will be: */
+ /* 16384 < Pow2() <= 32767 */
+ exp_gcode0 = sub(exp_gcode0, 14);
+ /*------------------------------------------------------------------------------------------*
+ * Select the gain quantization table and dequantize the gain
+ *------------------------------------------------------------------------------------------*/
+
+ /* index = (Word16)get_indice( st_fx,"gain_code", i_subfr_fx, ACELP_CORE);move16();*/
+ index = (Word16)get_next_indice( st_fx, nBits );
+ move16();
+
+
+ IF( GT_16(nBits,3))
+ {
+ wgain_code = gain_dequant_fx( index, G_CODE_MIN_TC_Q15, G_CODE_MAX_TC_Q0, nBits, &expg );
+ wgain_code = shl(wgain_code,add(expg,12)); /* wgain_code in Q12*/
+ }
+ ELSE /* nBits == 3 */
+ {
+ wgain_code = shr(tbl_gain_code_tc_fx[index], 1); //Q12
+ move16();
+ }
+
+ /*-----------------------------------------------------------------*
+ * decode normalized codebook gain
+ *-----------------------------------------------------------------*/
+
+ /* *gain_code *= gcode0;*/
+ L_tmp = L_shl(L_mult(wgain_code, gcode0_fx), 1); /* Q12*Q0+1 -> Q14 */
+ *gain_code_fx= L_shl(L_tmp, add(exp_gcode0, 2));
+ move32(); /* Q14 -> Q16 */
+
+ /**norm_gain_code = *gain_code / *gain_inov;*/
+ expg = sub(norm_s(*gain_inov_fx),1);
+ expg = s_max(expg, 0);
+
+ tmp_fx = div_s(shr(8192,expg),*gain_inov_fx);
+ *norm_gain_code_fx = L_shr(Mult_32_16(*gain_code_fx, tmp_fx),sub(1,expg));
+ move32();
+
+ return;
+}
+
/*======================================================================================*/
/* FUNCTION : gain_dec_mless_fx() */
/*--------------------------------------------------------------------------------------*/
@@ -346,7 +478,7 @@ void gain_dec_mless_fx(
IF (GT_16(st_fx->element_mode, EVS_MONO) )
{
//PMT("gain_qua_mless_6b_stereo to fixed point")
- //qua_table_fx = gain_qua_mless_6b_stereo;
+ qua_table_fx = gain_qua_mless_6b_stereo_fx;
}
BREAK;
}
@@ -505,7 +637,7 @@ void gain_dec_lbr_fx(
move32();
L_tmp = Isqrt_lc(L_tmp, &expg);
- *gain_inov_fx = extract_h(L_shl(L_tmp, sub(expg, 3))); /* gain_inov in Q12 */
+ *gain_inov_fx = extract_h(L_shl_sat(L_tmp, sub(expg, 3))); /* gain_inov in Q12 */
/*-----------------------------------------------------------------*
@@ -684,11 +816,11 @@ void gain_dec_lbr_fx(
move16();
cdbk_fx = gp_gamma_3sfr_6b_fx;
-#ifdef IVAS_GAIN_MOD
+#if 1//def IVAS_GAIN_MOD
IF(EQ_16(nBits, 7))
{
cdbk_fx = gp_gamma_3sfr_7b_fx;
- PMT("verify if gp_gamma_3sfr_7b_fx is correct")
+ //PMT("verify if gp_gamma_3sfr_7b_fx is correct")
}
#endif
move16(); /* Q14/Q9*/
diff --git a/lib_dec/gs_dec.c b/lib_dec/gs_dec.c
index 40908cdf13f5dcebfc90ff203942692c6422f6df..bec4c17d269f9eb2d207720c4e5994b841d5e409 100644
--- a/lib_dec/gs_dec.c
+++ b/lib_dec/gs_dec.c
@@ -711,7 +711,7 @@ void GSC_dec_init_ivas(
{
hGSCDec->seed_tcx = 15687;
hGSCDec->cor_strong_limit = 1;
- set_f( hGSCDec->old_y_gain, 0, MBANDS_GN );
+ set_f( hGSCDec->old_y_gain, 0, MBANDS_GN16k);
hGSCDec->noise_lev = NOISE_LEVEL_SP0;
set_f( hGSCDec->Last_GSC_spectrum, 0.0f, L_FRAME16k );
hGSCDec->Last_GSC_pit_band_idx = 0;
diff --git a/lib_dec/gs_dec_fx.c b/lib_dec/gs_dec_fx.c
index 460a3da49ea0093bf4a863327a76c44fc982c371..73d7265910efe2733a59103d73d09aa1b4646ed0 100644
--- a/lib_dec/gs_dec_fx.c
+++ b/lib_dec/gs_dec_fx.c
@@ -504,6 +504,504 @@ void decod_audio_fx(
return;
}
+/*=========================================================================*/
+/* FUNCTION : void decod_audio_ivas_fx(); */
+/*-------------------------------------------------------------------------*/
+/* PURPOSE : Decode audio (AC) frames */
+/*-------------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (Word16[]) Aq : LP filter coefficient Q12 */
+/* _ (Word16) coder_type : coding type Q0 */
+/* _(Word16) Q_exc :Q format of excitation */
+/*-------------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ (Word16[]) pitch_buf_fx : floating pitch values for each subframe Q6*/
+/* _ (Word16[]) voice_factors_fx: frame error rate Q15 */
+/*--------------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* Decoder_State *st_fx : decoder memory structure */
+/* _ (Word16[]) exc_fx : adapt. excitation exc (Q_exc) */
+/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q_exc) */
+/*--------------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : */
+/* _ None */
+/*==========================================================================*/
+void decod_audio_ivas_fx(
+ Decoder_State *st_fx, /* i/o: decoder static memory */
+ Word16 dct_epit[], /* o : GSC excitation in DCT domain */
+ const Word16 *Aq, /* i : LP filter coefficient */
+ Word16 *pitch_buf, /* o : floating pitch values for each subframe */
+ Word16 *voice_factors, /* o : voicing factors */
+ Word16 *exc, /* i/o: adapt. excitation exc */
+ Word16 *exc2, /* i/o: adapt. excitation/total exc */
+ Word16 *bwe_exc, /* o : excitation for SWB TBE */
+ Word16 *lsf_new /* i : ISFs at the end of the frame */
+ , Word16 *gain_buf, /*Q14*/
+ const Word16 tdm_lp_reuse_flag, /* i : LPC reuse flag */
+ const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */
+ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */
+ const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */
+)
+{
+ Word16 tmp_nb_bits_tot, pit_band_idx;
+ Word16 code[4 * L_SUBFR];
+ Word16 Diff_len, nb_subfr, i;
+ Word16 nb_frame_flg;
+ Word16 Es_pred = 0;
+ Word16 Len, max_len;
+ Word16 gsc_attack_flag;
+
+ Word16 low_pit;
+ Word16 last_bin;
+ Word16 nbits;
+
+ Word16 exc_wo_nf[L_FRAME16k];
+ GSC_DEC_HANDLE hGSCDec;
+ hGSCDec = st_fx->hGSCDec;
+
+
+ /*---------------------------------------------------------------*
+ * Initialization
+ *---------------------------------------------------------------*/
+ Diff_len = 0;
+ move16();
+
+ /* decode GSC attack flag (used to reduce possible pre-echo) */
+ gsc_attack_flag = (Word16)get_next_indice(st_fx, 1);
+
+ /* decode GSC SWB speech flag */
+ test();
+#if 0// !defined ADD_LRTD
+ IF(NE_16(st_fx->coder_type_fx, INACTIVE) && GE_32(st_fx->total_brate, ACELP_13k20))
+#else
+ if (st_fx->GSC_IVAS_mode >= 1 || (st_fx->coder_type_fx != INACTIVE && ((st_fx->element_mode == EVS_MONO && st_fx->total_brate >= ACELP_13k20) ||
+ (st_fx->element_mode > EVS_MONO && st_fx->total_brate > MIN_BRATE_GSC_NOISY_FLAG && st_fx->bwidth >= SWB && !st_fx->flag_ACELP16k))))
+#endif
+ {
+ st_fx->GSC_noisy_speech_fx = (Word16)get_next_indice(st_fx, 1);
+ }
+
+ /* safety check in case of bit errors */
+ test();
+ IF(st_fx->GSC_noisy_speech_fx && LT_16(st_fx->bwidth, SWB) && st_fx->GSC_IVAS_mode == 0)
+ {
+ st_fx->BER_detect = 1;
+ move16();
+ st_fx->GSC_noisy_speech_fx = 0;
+ move16();
+ }
+ /* set bit-allocation */
+#if 1//def ADD_LRTD
+ config_acelp1_IVAS(DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech_fx, &(st_fx->acelp_cfg), st_fx->next_bit_pos, st_fx->coder_type_fx, -1, 1, &nbits, NULL, st_fx->element_mode, &nbits /*dummy*/, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_cnt, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode);
+#else
+ config_acelp1(DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech_fx, &(st_fx->acelp_cfg), st_fx->next_bit_pos, st_fx->coder_type_fx, -1, 1, &nbits, NULL, st_fx->element_mode, &nbits /*dummy*/, 0, 0, st_fx->idchan, st_fx->active_cnt, 0, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode);
+#endif
+ /*---------------------------------------------------------------*
+ * Decode energy dynamics
+ *---------------------------------------------------------------*/
+#if 1// defined ADD_LRTD
+ test(); test();
+ IF(st_fx->GSC_IVAS_mode >= 1 || (EQ_16(st_fx->GSC_noisy_speech_fx, 1) && st_fx->GSC_IVAS_mode == 0))
+#else
+ IF(EQ_16(st_fx->GSC_noisy_speech_fx, 1))
+#endif
+ {
+ nb_subfr = NB_SUBFR;
+ move16();
+ hGSCDec->cor_strong_limit_fx = 0;
+ move16();
+ hGSCDec->noise_lev_fx = NOISE_LEVEL_SP3;
+ move16();
+#if 1//def ADD_LRTD
+ if (st_fx->GSC_IVAS_mode >= 1)
+ {
+ if (st_fx->core_brate < GSC_L_RATE_STG && st_fx->GSC_IVAS_mode < 3)
+ {
+ nb_subfr = 2;
+ }
+ hGSCDec->noise_lev_fx = NOISE_LEVEL_SP2;
+
+ if (st_fx->GSC_IVAS_mode == 3) /* Music like */
+ {
+ hGSCDec->noise_lev_fx = NOISE_LEVEL_SP0;
+ }
+ else if (st_fx->GSC_noisy_speech_fx == 0) /* speech like but not noisy */
+ {
+ hGSCDec->noise_lev_fx = NOISE_LEVEL_SP3;
+ }
+ }
+#endif
+ }
+ ELSE
+ {
+ IF(LE_32(st_fx->core_brate,ACELP_8k00))
+ {
+ hGSCDec->noise_lev_fx = add((Word16)get_next_indice(st_fx, 2), NOISE_LEVEL_SP2);
+ }
+ ELSE
+ {
+ hGSCDec->noise_lev_fx = add((Word16)get_next_indice(st_fx, 3), NOISE_LEVEL_SP0);
+ }
+
+ /*---------------------------------------------------------------*
+ * Decode number of subframes
+ *---------------------------------------------------------------*/
+ #if 1//def ADD_LRTD
+ if (st_fx->L_frame == L_FRAME16k && (st_fx->core_brate <= ACELP_13k20 || st_fx->coder_type_fx == INACTIVE))
+ {
+ hGSCDec->cor_strong_limit_fx = 0;
+ nb_subfr = 1;
+ }
+ else
+ #endif
+ {
+ hGSCDec->cor_strong_limit_fx = 1;
+ move16();
+ nb_subfr = SWNB_SUBFR;
+ move16();
+
+ IF(GE_32(st_fx->core_brate,ACELP_9k60))
+ {
+ nbits = 1;
+ move16();
+ #if 1//def ADD_LRTD
+ if (st_fx->L_frame == L_FRAME16k && st_fx->core_brate >= MIN_RATE_4SBFR)
+ {
+ nbits = 2;
+ }
+ #endif
+ nb_frame_flg = (Word16)get_next_indice(st_fx, nbits);
+
+ IF(s_and(nb_frame_flg,0x1) == 0)
+ {
+ nb_subfr = 2 * SWNB_SUBFR;
+ move16();
+ hGSCDec->cor_strong_limit_fx = 0;
+ move16();
+ }
+ #if 1//def ADD_LRTD
+ else if (st_fx->L_frame == L_FRAME16k && st_fx->core_brate >= MIN_RATE_4SBFR)
+ {
+ nb_subfr = 2 * SWNB_SUBFR; /* cor_strong already set to 1 */
+ }
+
+ if ((nb_frame_flg >> 1) == 1)
+ {
+ nb_subfr *= 2;
+ }
+ #endif
+ }
+ }
+ }
+#if 1
+ if (st_fx->L_frame == L_FRAME16k && nb_subfr == NB_SUBFR)
+ {
+ nb_subfr = NB_SUBFR16k;
+ }
+#endif
+ /*---------------------------------------------------------------*
+ * Decode the last band where the adaptive (pitch) contribution is significant
+ *---------------------------------------------------------------*/
+
+ IF(LT_32(st_fx->core_brate, CFREQ_BITRATE))
+ {
+ nbits = 3;
+ move16();
+ test();
+ if (LT_32(st_fx->core_brate, ACELP_9k60) && (EQ_16(st_fx->coder_type_fx, INACTIVE)))
+ {
+ nbits = 1;
+ move16();
+ }
+ }
+ ELSE
+ {
+ nbits = 4;
+ move16();
+ }
+ test();
+ IF(LT_32(st_fx->core_brate, ACELP_9k60) && NE_16(st_fx->coder_type_fx, INACTIVE))
+ {
+ pit_band_idx = 1;
+ move16();
+ }
+ ELSE
+ {
+ pit_band_idx = (Word16)get_next_indice(st_fx, nbits);
+ }
+
+ IF(pit_band_idx != 0)
+ {
+ IF(LT_32(st_fx->core_brate, ACELP_9k60))
+ {
+ pit_band_idx = 7 + BAND1k2;
+ move16(); /* At low rate, if pitch model is chosen, then for to be use on extented and constant frequency range */
+ }
+ ELSE
+ {
+ pit_band_idx = add(pit_band_idx, BAND1k2);
+ }
+
+ /* detect bit errors in the bitstream */
+ IF(GT_16(pit_band_idx, 13)) /* The maximum decodable index is 10 + BAND1k2 (3) = 13 */
+ {
+ pit_band_idx = 13;
+ move16();
+ st_fx->BER_detect = 1;
+ move16();
+ }
+ Diff_len = mfreq_loc_div_25[pit_band_idx];
+ move16();
+ }
+ hGSCDec->Last_GSC_pit_band_idx_fx = pit_band_idx;
+ move16();
+
+
+ /*--------------------------------------------------------------------------------------*
+ * Decode adaptive (pitch) excitation contribution
+ * Reset unvaluable part of the adaptive (pitch) excitation contribution
+ *--------------------------------------------------------------------------------------*/
+ IF(GT_16(pit_band_idx, BAND1k2))
+ {
+ /*---------------------------------------------------------------*
+ * Decode adaptive (pitch) excitation contribution
+ *---------------------------------------------------------------*/
+ test();
+#if 1//def ADD_LRTD
+ if (!(st_fx->GSC_IVAS_mode > 0 && st_fx->L_frame / nb_subfr == 2 * L_SUBFR && st_fx->GSC_IVAS_mode < 3) &&
+ ((st_fx->core_brate >= MIN_RATE_FCB || st_fx->GSC_noisy_speech_fx) &&
+ ((nb_subfr == NB_SUBFR && st_fx->L_frame == L_FRAME) || (nb_subfr == NB_SUBFR16k && st_fx->L_frame == L_FRAME16k))))
+#else
+ IF(EQ_16(st_fx->GSC_noisy_speech_fx, 1) && EQ_16(nb_subfr, NB_SUBFR))
+#endif
+ {
+ Word16 indice;
+ nbits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx(st_fx->core_brate, GENERIC, -1, -1)];
+ move16();
+ IF(GT_16(st_fx->element_mode, EVS_MONO))
+ {
+ nbits = 5;
+ move16();
+ }
+
+ indice = get_next_indice(st_fx, nbits);
+
+ Es_pred_dec_fx(&Es_pred, indice, nbits, 0);
+ }
+#if 1//def ADD_LRTD
+ dec_pit_exc_ivas_fx(st_fx, Aq, st_fx->coder_type_fx, Es_pred, pitch_buf, code, exc, bwe_exc, nb_subfr, gain_buf, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf);
+#else
+ dec_pit_exc_fx(st_fx, Aq, st_fx->coder_type_fx, Es_pred, pitch_buf, code, exc, bwe_exc, nb_subfr, gain_buf);
+#endif
+ IF(LT_32(st_fx->core_brate, ACELP_9k60))
+ {
+ minimum_fx(pitch_buf, shr(st_fx->L_frame, 6), &low_pit);
+ low_pit = shr(low_pit, 6); /*Q6 -> Q0 */
+
+ IF(LT_16(low_pit, 64))
+ {
+ pit_band_idx = 9 + BAND1k2;
+ move16();
+ if (EQ_16(st_fx->bwidth, NB))
+ {
+ pit_band_idx = 7 + BAND1k2;
+ move16();
+ }
+ }
+ ELSE IF(LT_16(low_pit, 128))
+ {
+ pit_band_idx = 5 + BAND1k2;
+ move16();
+ }
+ ELSE
+ {
+ pit_band_idx = 3 + BAND1k2;
+ move16();
+ }
+
+ Diff_len = mfreq_loc_div_25[pit_band_idx];
+ move16();
+ hGSCDec->Last_GSC_pit_band_idx_fx = pit_band_idx;
+ move16();
+ }
+
+ /*---------------------------------------------------------------*
+ * DCT transform
+ *---------------------------------------------------------------*/
+ edct_16fx(exc, dct_epit, st_fx->L_frame, 7, st_fx->element_mode);
+
+ /*---------------------------------------------------------------*
+ * Reset unvaluable part of the adaptive (pitch) excitation contribution
+ *---------------------------------------------------------------*/
+
+ max_len = sub(st_fx->L_frame, Diff_len);
+
+ if (EQ_16(st_fx->bwidth, NB))
+ {
+ max_len = sub(160, Diff_len);
+ }
+
+ Len = 80;
+ move16();
+ if (max_len < 80)
+ {
+ Len = max_len;
+ move16();
+ }
+
+ test();
+ IF(EQ_32(st_fx->core_brate, ACELP_8k00) && NE_16(st_fx->bwidth, NB))
+ {
+ FOR(i = 0; i < max_len; i++)
+ {
+ dct_epit[i + Diff_len] = 0;
+ move16();
+ }
+ }
+ ELSE
+ {
+ FOR(i = 0; i < Len; i++)
+ {
+ dct_epit[i + Diff_len] = mult_r(dct_epit[i + Diff_len],sm_table_fx[i]);
+ move16();
+ }
+
+ FOR(; i < max_len; i++)
+ {
+ dct_epit[i + Diff_len] = 0;
+ move16();
+ }
+ }
+ //PMT("in the rare case of 4 subfr, bfi_pitch_fx might be wrong")
+ st_fx->bfi_pitch_fx = mean_fx(pitch_buf, nb_subfr);
+ move16();
+ st_fx->bfi_pitch_frame = st_fx->L_frame;
+ move16();
+
+ Diff_len = add(Diff_len, 1);
+ st_fx->bpf_off = 0;
+ move16();
+ }
+ ELSE
+ {
+ /* No adaptive (pitch) excitation contribution */
+ st_fx->bpf_off = 1;
+ move16();
+ set16_fx(dct_epit, 0, st_fx->L_frame);
+
+ IF(EQ_16(st_fx->L_frame, L_FRAME16k))
+ {
+ set16_fx(pitch_buf, shl(L_SUBFR16k, 6), NB_SUBFR16k);
+ }
+ ELSE
+ {
+ set16_fx(pitch_buf, shl(L_SUBFR, 6), NB_SUBFR);
+ }
+
+ set16_fx(gain_buf, 0, NB_SUBFR16k);
+
+ st_fx->bfi_pitch_fx = shl(L_SUBFR,6);
+ st_fx->bfi_pitch_frame = st_fx->L_frame;
+ move16();
+ st_fx->lp_gainp_fx = 0;
+ move16();
+ st_fx->lp_gainc_fx = 0;
+ move16();
+ st_fx->tilt_code_fx = 0;
+ move16();
+ pit_band_idx = 0;
+ move16();
+ Diff_len = 0;
+ move16();
+ }
+
+ /*--------------------------------------------------------------------------------------*
+ * GSC decoder
+ *--------------------------------------------------------------------------------------*/
+
+ /* find the current total number of bits used */
+
+ tmp_nb_bits_tot = st_fx->next_bit_pos;
+ move16();
+#if 1//def IVAS_CODE
+ if (st_fx->extl_brate_orig > 0)
+#else
+ if (st_fx->extl_brate > 0)
+#endif
+ {
+ /* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */
+ tmp_nb_bits_tot = sub(tmp_nb_bits_tot, 1);
+ }
+
+
+ test();
+#if 1//defined ADD_LRTD
+ test();
+ if (EQ_16(st_fx->coder_type_fx, INACTIVE) && LE_32(st_fx->core_brate, ACELP_9k60) && st_fx->idchan == 0)
+#else
+ if (EQ_16(st_fx->coder_type_fx, INACTIVE) && LE_32(st_fx->core_brate, ACELP_9k60))
+#endif
+ {
+ tmp_nb_bits_tot = add(tmp_nb_bits_tot, 5);
+ }
+
+#if 1//ydef ADD_LRTD
+ IF(EQ_16(st_fx->idchan, 1))
+ {
+ tmp_nb_bits_tot = add(tmp_nb_bits_tot, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS);
+ IF(EQ_16(st_fx->tdm_LRTD_flag, 1))
+ {
+ tmp_nb_bits_tot = sub(tmp_nb_bits_tot, STEREO_BITS_TCA);
+ }
+ }
+#endif
+ //gsc_dec_fx(st_fx, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st_fx->coder_type_fx, &last_bin, lsf_new, exc_wo_nf, st_fx->Q_exc );
+ gsc_dec_ivas_fx(st_fx, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st_fx->coder_type_fx, &last_bin, lsf_new, exc_wo_nf, st_fx->Q_exc);
+ /*--------------------------------------------------------------------------------------*
+ * iDCT transform
+ *--------------------------------------------------------------------------------------*/
+
+ edct_16fx(dct_epit, exc, st_fx->L_frame, 7, st_fx->element_mode);
+ edct_16fx(exc_wo_nf, exc_wo_nf, st_fx->L_frame, 7, st_fx->element_mode);
+ /*----------------------------------------------------------------------*
+ * Remove potential pre-echo in case an onset has been detected
+ *----------------------------------------------------------------------*/
+
+ pre_echo_att_fx(&hGSCDec->Last_frame_ener_fx, exc, gsc_attack_flag
+ , st_fx->Q_exc, st_fx->last_coder_type_fx, st_fx->L_frame);
+
+ /*--------------------------------------------------------------------------------------*
+ * Update BWE excitation
+ *--------------------------------------------------------------------------------------*/
+
+ if (st_fx->hBWE_TD != NULL)
+ {
+ set16_fx(voice_factors, 0, NB_SUBFR16k);
+ IF(EQ_16(st_fx->L_frame, L_FRAME16k))
+ {
+ interp_code_4over2_fx(exc, bwe_exc, st_fx->L_frame);
+ }
+ ELSE
+ {
+ interp_code_5over2_fx(exc, bwe_exc, L_FRAME);
+ }
+ }
+ /*--------------------------------------------------------------------------------------*
+ * Updates
+ *--------------------------------------------------------------------------------------*/
+
+ Copy(exc, exc2, st_fx->L_frame);
+ Copy(exc_wo_nf, exc, st_fx->L_frame);
+
+ /*--------------------------------------------------------------------------------------*
+ * Channel aware mode parameters
+ *--------------------------------------------------------------------------------------*/
+
+ set16_fx(st_fx->tilt_code_dec_fx, 0, NB_SUBFR16k);
+
+ return;
+}
+
/*==========================================================================*/
/* FUNCTION : void gsc_dec_fx () */
/*--------------------------------------------------------------------------*/
@@ -1015,6 +1513,7 @@ void gsc_dec_ivas_fx(
#endif
{
pvq_core_dec_fx(st_fx, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, concat_out, &Q_tmp, bit, nb_subbands, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE);
+ //ivas_pvq_core_dec_fx(st_fx, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, concat_out, &Q_tmp, bit, nb_subbands, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE);
Scale_sig(concat_out, gsc_sfm_end[nb_subbands - 1], sub(Q_PVQ_OUT, Q_tmp));
}
seed_init = 0;
diff --git a/lib_dec/init_dec.c b/lib_dec/init_dec.c
index adabf549f5075b3b8b2427ee91ed3f5a28590238..d9e1c0a25f59cf1905dfa3ef0627d44fc23dd512 100644
--- a/lib_dec/init_dec.c
+++ b/lib_dec/init_dec.c
@@ -104,6 +104,8 @@ ivas_error init_decoder(
/* LSF initilalizations */
mvr2r( GEWB_Ave, st->mem_AR, M );
+ init_lvq_fx(st->offset_scale1_fx, st->offset_scale2_fx, st->offset_scale1_p_fx, st->offset_scale2_p_fx, st->no_scales_fx, st->no_scales_p_fx);
+
set_f( st->mem_MA, 0, M );
set_f( st->dispMem, 0, 8 );
@@ -198,6 +200,31 @@ ivas_error init_decoder(
st->old_bfi_cnt = 0;
+#ifdef IVAS_FLOAT_FIXED
+ /* Initializaing Q factors*/
+ st->Q_syn = 0;
+ move16();
+ st->Q_syn2 = 0;
+ move16();
+ st->Q_syn_cng = 0;
+ move16();
+ st->prev_Q_syn = 0;
+ move16();
+ st->prev_Q_syn_fr = 0;
+ move16();
+ st->Q_exc = 0;
+ move16();
+ st->Q_exc_cng = 0;
+ move16();
+ st->prev_Q_exc = 0;
+ move16();
+ st->prev_Q_exc_fr = 0;
+ move16();
+ st->Q_stat_noise_ge = GE_SHIFT;
+ move16();
+ st->Q_stat_noise = 0;
+ move16();
+#endif
/*-----------------------------------------------------------------*
* parameters for AC mode (GSC)
*-----------------------------------------------------------------*/
diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c
index 8a3634b170d245d5d08a9e4dccf6808cb0c87757..3283fc721eb6957d662170927ba9e307efd29ff9 100644
--- a/lib_dec/init_dec_fx.c
+++ b/lib_dec/init_dec_fx.c
@@ -1291,10 +1291,43 @@ ivas_error init_decoder_ivas_fx(
return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n"));
}
-#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available.
- td_cng_dec_init_flt(st_fx);
-#endif
- td_cng_dec_init_ivas_fx(st_fx);
+#ifdef IVAS_FLOAT_FIXED
+#if 1 // Float To Fix conversions
+ floatToFixed_arr(st_fx->hTdCngDec->shb_lpcCNG, st_fx->hTdCngDec->shb_lpcCNG_fx, 15, LPC_SHB_ORDER + 1);
+ st_fx->hTdCngDec->shb_cng_gain_fx_32 = floatToFixed(st_fx->hTdCngDec->shb_cng_gain, 11);
+ floatToFixed_arr(st_fx->lsp_old, st_fx->lsp_old_fx, 15, M);
+#endif // Float to fix conversions
+
+ td_cng_dec_init_ivas_fx( st_fx );
+
+#if 1 // Fix to float conversions
+ st_fx->hTdCngDec->Enew = fix_to_float(st_fx->hTdCngDec->Enew_fx, 6);
+ fixedToFloat_arr(st_fx->lspCNG_fx, st_fx->lspCNG, 15, M);
+ st_fx->hTdCngDec->shb_cng_ener = fix_to_float(st_fx->hTdCngDec->shb_cng_ener_fx_32, 11);
+ fixedToFloat_arr(st_fx->hTdCngDec->shb_lpcCNG_fx, st_fx->hTdCngDec->shb_lpcCNG, 15, LPC_SHB_ORDER + 1);
+ st_fx->hTdCngDec->shb_cng_gain = fix_to_float(st_fx->hTdCngDec->shb_cng_gain_fx_32, 11);
+ st_fx->hTdCngDec->wb_cng_ener = fix_to_float(st_fx->hTdCngDec->wb_cng_ener_fx_32, 11);
+ st_fx->hTdCngDec->last_wb_cng_ener = fix_to_float(st_fx->hTdCngDec->last_wb_cng_ener_fx_32, 11);
+ st_fx->hTdCngDec->last_shb_cng_ener = fix_to_float(st_fx->hTdCngDec->last_shb_cng_ener_fx_32, 11);
+ fixedToFloat_arr(st_fx->hTdCngDec->ho_lsp_hist_fx, st_fx->hTdCngDec->ho_lsp_hist, 15, HO_HIST_SIZE * M);
+ fixedToFloat_arrL(st_fx->hTdCngDec->ho_ener_hist_fx, st_fx->hTdCngDec->ho_ener_hist, 15, HO_HIST_SIZE);
+ fixedToFloat_arrL(st_fx->hTdCngDec->ho_env_hist_fx, st_fx->hTdCngDec->ho_env_hist, 15, HO_HIST_SIZE * NUM_ENV_CNG);
+ fixedToFloat_arr(st_fx->hTdCngDec->ho_lsp_circ_fx, st_fx->hTdCngDec->ho_lsp_circ, 15, HO_HIST_SIZE * M);
+ fixedToFloat_arrL(st_fx->hTdCngDec->ho_ener_circ_fx, st_fx->hTdCngDec->ho_ener_circ, 15, HO_HIST_SIZE);
+ fixedToFloat_arrL(st_fx->hTdCngDec->ho_env_circ_fx, st_fx->hTdCngDec->ho_env_circ, 15, HO_HIST_SIZE * NUM_ENV_CNG);
+ fixedToFloat_arrL(st_fx->hTdCngDec->lp_env_fx, st_fx->hTdCngDec->lp_env, 15, NUM_ENV_CNG);
+ fixedToFloat_arr(st_fx->hTdCngDec->exc_mem_fx, st_fx->hTdCngDec->exc_mem, 15, 24);
+ fixedToFloat_arr(st_fx->hTdCngDec->exc_mem1_fx, st_fx->hTdCngDec->exc_mem1, 15, 30);
+ fixedToFloat_arrL(st_fx->hTdCngDec->old_env_fx, st_fx->hTdCngDec->old_env, 15, NUM_ENV_CNG);
+ fixedToFloat_arr(st_fx->hTdCngDec->lsp_shb_prev_fx, st_fx->hTdCngDec->lsp_shb_prev, 15, LPC_SHB_ORDER);
+ fixedToFloat_arr(st_fx->hTdCngDec->lsp_shb_prev_prev_fx, st_fx->hTdCngDec->lsp_shb_prev_prev, 15, LPC_SHB_ORDER);
+ fixedToFloat_arr(st_fx->hTdCngDec->interpol_3_2_cng_dec_fx, st_fx->hTdCngDec->interpol_3_2_cng_dec, 15, INTERP_3_2_MEM_LEN);
+
+
+#endif // Fix to float conversions
+#else
+ td_cng_dec_init_flt( st_fx );
+#endif // IVAS_FLOAT_FIXED
}
ELSE
{
diff --git a/lib_dec/inov_dec_fx.c b/lib_dec/inov_dec_fx.c
index 563775f3e5c4c2f66ccc41cf03bb6552f4c1ec89..cc5ae4c6f8233c2de7756c62cb581fa034d661e8 100644
--- a/lib_dec/inov_dec_fx.c
+++ b/lib_dec/inov_dec_fx.c
@@ -70,7 +70,7 @@ void inov_decode_fx(
IF ( !Opt_AMR_WB )
{
-#ifdef IVAS_CODE
+#if 1//def IVAS_CODE
if (st_fx->acelp_cfg.fcb_mode)
{
int16_t i;
@@ -85,28 +85,32 @@ void inov_decode_fx(
if (nBits == 8)
{
//dec_acelp_1t64(st_fx, code, L_subfr);
+ dec_acelp_1t64_fx(st_fx, code, L_subfr);
}
else
{
//dec_acelp_fast(st_fx, nBits, code, L_subfr);
+ dec_acelp_fast_fx(st_fx, nBits, code, L_subfr);
+ }
+ }
+ else if ((st_fx->idchan == 1 && st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] <= 7) || (st_fx->idchan == 0 && st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] <= 3))
+ {
+ if (st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] == 0)
+ {
+ //dec_acelp_1t64(st_fx, code, L_SUBFR);
+ dec_acelp_1t64_fx(st_fx, code, L_SUBFR);
+ }
+ else
+ {
+ //dec_acelp_fast(st_fx, st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], code, L_SUBFR);
+ dec_acelp_fast_fx(st_fx, st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], code, L_SUBFR);
}
}
- //else if ((st_fx->idchan == 1 && st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] <= 7) || (st_fx->idchan == 0 && st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] <= 3))
- //{
- // if (st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] == 0)
- // {
- // dec_acelp_1t64(st_fx, code, L_SUBFR);
- // }
- // else
- // {
- // dec_acelp_fast(st_fx, st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], code, L_SUBFR);
- // }
- //}
else
{
wordcnt = ACELP_FIXED_CDK_BITS(st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]) >> 4;
bitcnt = ACELP_FIXED_CDK_BITS(st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]) & 15;
-PMT("CONDITION above is missing -> idchan")
+//PMT("CONDITION above is missing -> idchan")
for (i = 0; i < wordcnt; i++)
{
indexing_indices[i] = get_next_indice(st_fx, 16);
@@ -121,7 +125,7 @@ PMT("CONDITION above is missing -> idchan")
}
else
{
- set16_fx(code, 0.0f, L_SUBFR);
+ set16_fx(code, 0, L_SUBFR);
}
}
else
diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c
index dd5f0b88bbcc791c7fe55688df2190316fd5988b..8a4d1d9bbe83eefb24a36ce7b2bf678352e67b38 100644
--- a/lib_dec/ivas_core_dec.c
+++ b/lib_dec/ivas_core_dec.c
@@ -61,6 +61,39 @@ int16_t dbgwrite2_txt(
return 0;
}
+#ifdef IVAS_FLOAT_FIXED
+static Word16 norm_arr_l(float *arr, int size);
+static Word16 norm(float num);
+
+static Word16 norm(float num) {
+ if ((Word32)num == 0) return 31;
+ return norm_l((Word32)num);
+}
+static Word16 norm_arr_l(float *arr, int size)
+{
+ Word16 q = 31;
+ for (int i = 0; i < size; i++)
+ if (arr[i] != 0)
+ {
+ q = min(q, norm(arr[i]));
+ }
+ return q;
+}
+static Word16 s_norm(float num) {
+ if ((Word16)num == 0) return 15;
+ return norm_s((Word16)num);
+}
+static Word16 norm_arr_s(float *arr, int size)
+{
+ Word16 q = 15;
+ for (int i = 0; i < size; i++)
+ if (arr[i] != 0)
+ {
+ q = min(q, s_norm(arr[i]));
+ }
+ return q;
+}
+#endif
/*-------------------------------------------------------------------*
* ivas_core_dec()
@@ -123,12 +156,12 @@ ivas_error ivas_core_dec(
int16_t nchan_out;
float *save_hb_synth;
ivas_error error;
- Word16 tmp1, tmp2;
- Word32 L_tmp;
+ Word16 tmp1, tmp2;
+ Word32 L_tmp;
#ifdef IVAS_FLOAT_FIXED
- Word16 hb_synth_fx[6][L_FRAME48k]; /*not sure about number of channels so kept it as 6 will change it later*/
- Word32 hb_synth_32[6][L_FRAME48k];
+ Word16 hb_synth_fx[6][L_FRAME48k]; /*not sure about number of channels so kept it as 6 will change it later*/
+ Word32 hb_synth_32[6][L_FRAME48k];
#endif
error = IVAS_ERR_OK;
@@ -150,7 +183,7 @@ ivas_error ivas_core_dec(
sts = hCPE->hCoreCoder;
}
- //core_coding_part will go in this loop, once the things are done
+ //core_coding_part will go in this loop, once the things are done
for ( k = 0; k < n_channels; k++ )
{
if ( sts[k]->hTcxDec != NULL )
@@ -743,10 +776,17 @@ ivas_error ivas_core_dec(
if ( st->core == ACELP_CORE )
{
/* ACELP core decoder */
- if ( ( error = acelp_core_dec( st, output[n], synth[n], save_hb_synth, bwe_exc_extended[n], voice_factors[n], old_syn_12k8_16k[n], sharpFlag[n], pitch_buf[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lspQ_PCh, tdm_lsfQ_PCh, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hCPE == NULL ? NULL : hCPE->hStereoCng, read_sid_info ) ) != IVAS_ERR_OK )
+#ifdef IVAS_FLOAT_FIXED
+ if ( ( error = acelp_core_dec_ivas_fx( st, output[n], synth[n], save_hb_synth, bwe_exc_extended[n], voice_factors[n], old_syn_12k8_16k[n], sharpFlag[n], pitch_buf[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lspQ_PCh, tdm_lsfQ_PCh, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hCPE == NULL ? NULL : hCPE->hStereoCng, read_sid_info ) ) != IVAS_ERR_OK )
{
return error;
}
+#else
+ if ((error = acelp_core_dec(st, output[n], synth[n], save_hb_synth, bwe_exc_extended[n], voice_factors[n], old_syn_12k8_16k[n], sharpFlag[n], pitch_buf[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lspQ_PCh, tdm_lsfQ_PCh, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hCPE == NULL ? NULL : hCPE->hStereoCng, read_sid_info)) != IVAS_ERR_OK)
+ {
+ return error;
+ }
+#endif
}
if ( ( st->core == TCX_20_CORE || st->core == TCX_10_CORE ) && st->element_mode != IVAS_CPE_MDCT )
@@ -1341,7 +1381,21 @@ ivas_error ivas_core_dec(
* Pre-processing for bandwidth switching
*---------------------------------------------------------------------*/
- bw_switching_pre_proc( st, old_syn_12k8_16k[n], last_element_brate, nchan_out );
+#ifdef IVAS_FLOAT_FIXED
+ Word32 old_syn_12k8_16k_fx[L_FRAME16k];
+ Word16 norm = norm_arr_l(old_syn_12k8_16k[n], L_FRAME), q_old_syn, q_audio;
+ Word16 gb = find_guarded_bits_fx(L_FRAME16k);
+ floatToFixed_arrL(old_syn_12k8_16k[n], old_syn_12k8_16k_fx, norm - gb, L_FRAME16k);
+ q_old_syn = norm - gb;
+ norm = norm_arr_s(st->t_audio_q, L_FRAME);
+ gb = find_guarded_bits_fx(L_FRAME);
+ floatToFixed_arr(st->t_audio_q, st->t_audio_q_fx, norm - gb, L_FRAME);
+ q_audio = norm - gb;
+
+ ivas_bw_switching_pre_proc_fx( st, last_element_brate, nchan_out, old_syn_12k8_16k_fx, q_old_syn, q_audio );
+#else
+ bw_switching_pre_proc( st, old_syn_12k8_16k, last_element_brate, nchan_out );
+#endif
/*---------------------------------------------------------------------*
* WB TBE decoding
@@ -1577,7 +1631,40 @@ ivas_error ivas_core_dec(
if ( ( output_frame >= L_FRAME32k && st->hTdCngDec != NULL ) || ( st->element_mode == IVAS_CPE_DFT && st->bwidth >= SWB && st->hTdCngDec != NULL ) )
{
/* SHB CNG decoder */
+#ifdef IVAS_FLOAT_FIXED
+ st->hTdCngDec->shb_cng_gain_fx_32 = float_to_fix(st->hTdCngDec->shb_cng_gain, Q11);
+ st->hTdCngDec->shb_cng_ener_fx_32 = float_to_fix(st->hTdCngDec->shb_cng_ener, Q11);
+ st->hTdCngDec->last_shb_cng_ener_fx_32 = float_to_fix(st->hTdCngDec->last_shb_cng_ener, Q11);
+ floatToFixed_arr(st->hBWE_TD->state_lpc_syn, st->hBWE_TD->state_lpc_syn_fx, Q8, 10);
+ st->hTdCngDec->wb_cng_ener_fx_32 = float_to_fix(st->hTdCngDec->wb_cng_ener, Q11);
+ st->hTdCngDec->last_wb_cng_ener_fx_32 = float_to_fix(st->hTdCngDec->last_wb_cng_ener, Q11);
+ floatToFixed_arr16(st->hTdCngDec->lsp_shb_prev, st->hTdCngDec->lsp_shb_prev_fx, Q14, 10);
+ floatToFixed_arr16(st->hTdCngDec->lsp_shb_prev_prev, st->hTdCngDec->lsp_shb_prev_prev_fx, Q14, 10);
+ Word16 q = -2;
+ Word16 synth_fx[960], hb_synth_fx[960];
+ floatToFixed_arr16(synth[n], synth_fx, q, 960);
+ floatToFixed_arr16(hb_synth[n], hb_synth_fx, q, 960);
+ st->prev_Q_bwe_syn2 = 0;
+ floatToFixed_arr16(st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, 0, 6);
+ floatToFixed_arrL(st->hBWE_TD->genSHBsynth_Hilbert_Mem, st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, 0, 21);
+
+ swb_CNG_dec_ivas_fx( st, synth_fx, hb_synth_fx, sid_bw[n], q );
+
+ fixedToFloat_arr(synth_fx, synth[n], q, 960);
+ fixedToFloat_arr(hb_synth_fx, hb_synth[n], q, 960);
+ st->hTdCngDec->shb_cng_gain = fix_to_float(st->hTdCngDec->shb_cng_gain_fx_32, Q11);
+ st->hTdCngDec->shb_cng_ener = fix_to_float(st->hTdCngDec->shb_cng_ener_fx_32, Q11);
+ st->hTdCngDec->last_shb_cng_ener = fix_to_float(st->hTdCngDec->last_shb_cng_ener_fx_32, Q11);
+ fixedToFloat_arr(st->hBWE_TD->state_lpc_syn_fx, st->hBWE_TD->state_lpc_syn, Q8, 10);
+ st->hTdCngDec->wb_cng_ener = fix_to_float(st->hTdCngDec->wb_cng_ener_fx_32, Q11);
+ st->hTdCngDec->last_wb_cng_ener = fix_to_float(st->hTdCngDec->last_wb_cng_ener_fx_32, Q11);
+ fixedToFloat_arr(st->hTdCngDec->lsp_shb_prev_fx, st->hTdCngDec->lsp_shb_prev, Q14, 10);
+ fixedToFloat_arr(st->hTdCngDec->lsp_shb_prev_prev_fx, st->hTdCngDec->lsp_shb_prev_prev, Q14, 10);
+ fixedToFloat_arr(st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, 0, 6);
+ fixedToFloat_arrL(st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, st->hBWE_TD->genSHBsynth_Hilbert_Mem, 0, 21);
+#else
swb_CNG_dec( st, synth[n], hb_synth[n], sid_bw[n] );
+#endif
}
/*-------------------------------------------------------------------*
diff --git a/lib_dec/ivas_ism_metadata_dec.c b/lib_dec/ivas_ism_metadata_dec.c
index 9cd0bf26aaa085cba358d1df733e5340221d81d4..16cbe46ee3ae312443bfd825c952a49903300053 100644
--- a/lib_dec/ivas_ism_metadata_dec.c
+++ b/lib_dec/ivas_ism_metadata_dec.c
@@ -1203,7 +1203,7 @@ ivas_error ivas_ism_metadata_dec_fx(
set_s( md_diff_flag, 1, nchan_ism );
- update_last_metadata( nchan_ism, hIsmMeta, md_diff_flag );
+ update_last_metadata_fx( nchan_ism, hIsmMeta, md_diff_flag );
FOR ( ch = 0; ch < *nchan_transport; ch++ )
{
diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c
index 14451534701684773febcdbda528115692583c18..d409451abc9dd9fcd01fb3733d2b4cf7ddf41a9a 100644
--- a/lib_dec/ivas_jbm_dec.c
+++ b/lib_dec/ivas_jbm_dec.c
@@ -406,10 +406,41 @@ ivas_error ivas_jbm_dec_tc(
}
else /* ISM_MODE_DISC */
{
+#ifdef IVAS_FLOAT_FIXED
+ FOR( Word16 ind = 0; ind < st_ivas->nchan_ism; ind++ )
+ {
+ st_ivas->hIsmMetaData[ind]->azimuth_fx = (Word32) ( st_ivas->hIsmMetaData[ind]->azimuth * ( 1 << 22 ) );
+ st_ivas->hIsmMetaData[ind]->elevation_fx = (Word32) ( st_ivas->hIsmMetaData[ind]->elevation * ( 1 << 22 ) );
+ st_ivas->hIsmMetaData[ind]->last_azimuth_fx = (Word32) ( st_ivas->hIsmMetaData[ind]->last_azimuth * ( 1 << 22 ) );
+ st_ivas->hIsmMetaData[ind]->last_elevation_fx = (Word32) ( st_ivas->hIsmMetaData[ind]->last_elevation * ( 1 << 22 ) );
+ st_ivas->hIsmMetaData[ind]->last_true_azimuth_fx = (Word32) ( st_ivas->hIsmMetaData[ind]->last_true_azimuth * ( 1 << 22 ) );
+ st_ivas->hIsmMetaData[ind]->last_true_elevation_fx = (Word32) ( st_ivas->hIsmMetaData[ind]->last_true_elevation * ( 1 << 22 ) );
+ st_ivas->hIsmMetaData[ind]->radius_fx = (Word16) ( st_ivas->hIsmMetaData[ind]->radius * ( 1 << 9 ) );
+ st_ivas->hIsmMetaData[ind]->yaw_fx = (Word32) ( st_ivas->hIsmMetaData[ind]->yaw * ( 1 << 22 ) );
+ st_ivas->hIsmMetaData[ind]->pitch_fx = (Word32) ( st_ivas->hIsmMetaData[ind]->pitch * ( 1 << 22 ) );
+ }
+ IF( ( error = ivas_ism_metadata_dec_fx( ivas_total_brate, st_ivas->nchan_ism, &( st_ivas->nchan_transport ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, NULL, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, st_ivas->hSCE[0]->hCoreCoder[0] ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+ FOR( Word16 ind = 0; ind < st_ivas->nchan_ism; ind++ )
+ {
+ st_ivas->hIsmMetaData[ind]->azimuth = (float) ( st_ivas->hIsmMetaData[ind]->azimuth_fx ) / (float) ( 1 << 22 );
+ st_ivas->hIsmMetaData[ind]->elevation = (float) ( st_ivas->hIsmMetaData[ind]->elevation_fx ) / (float) ( 1 << 22 );
+ st_ivas->hIsmMetaData[ind]->last_azimuth = (float) ( st_ivas->hIsmMetaData[ind]->last_azimuth_fx ) / (float) ( 1 << 22 );
+ st_ivas->hIsmMetaData[ind]->last_elevation = (float) ( st_ivas->hIsmMetaData[ind]->last_elevation_fx ) / (float) ( 1 << 22 );
+ st_ivas->hIsmMetaData[ind]->last_true_azimuth = (float) ( st_ivas->hIsmMetaData[ind]->last_true_azimuth_fx ) / (float) ( 1 << 22 );
+ st_ivas->hIsmMetaData[ind]->last_true_elevation = (float) ( st_ivas->hIsmMetaData[ind]->last_true_elevation_fx ) / (float) ( 1 << 22 );
+ st_ivas->hIsmMetaData[ind]->radius = (float) ( st_ivas->hIsmMetaData[ind]->radius_fx ) / (float) ( 1 << 9 );
+ st_ivas->hIsmMetaData[ind]->yaw = (float) ( st_ivas->hIsmMetaData[ind]->yaw_fx ) / (float) ( 1 << 22 );
+ st_ivas->hIsmMetaData[ind]->pitch = (float) ( st_ivas->hIsmMetaData[ind]->pitch_fx ) / (float) ( 1 << 22 );
+ }
+#else
if ( ( error = ivas_ism_metadata_dec( ivas_total_brate, st_ivas->nchan_ism, &( st_ivas->nchan_transport ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, NULL, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, st_ivas->hSCE[0]->hCoreCoder[0] ) ) != IVAS_ERR_OK )
{
return error;
}
+#endif
}
for ( n = 0; n < st_ivas->nchan_transport; n++ )
@@ -1165,13 +1196,116 @@ ivas_error ivas_jbm_dec_tc(
/* MASA metadata decoding */
#ifdef IVAS_FLOAT_FIXED
- IF( ( error = ivas_masa_decode( st_ivas, st_ivas->hCPE[0]->hCoreCoder[0], &nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
+ // Float to fix conversion starts here.
+ FOR( Word32 l = 0; l < st_ivas->nchan_ism; l++ )
+ {
+ st_ivas->hMasaIsmData->q_azimuth_old_fx[l] = float_to_fix( st_ivas->hMasaIsmData->q_azimuth_old[l], Q22 );
+ }
+ IF( st_ivas->hMasa->hMasaLfeSynth != NULL )
+ {
+ FOR( Word32 j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ )
+ {
+ st_ivas->hMasa->hMasaLfeSynth->lfeToTotalEnergyRatio_fx[j] = float_to_fix16( st_ivas->hMasa->hMasaLfeSynth->lfeToTotalEnergyRatio[j], Q14 );
+ }
+ }
+ IF( st_ivas->hSpatParamRendCom != NULL )
+ {
+ FOR( Word16 i = 0; i < st_ivas->hSpatParamRendCom->dirac_md_buffer_length; i++ )
+ {
+ FOR( Word16 j = 0; j < st_ivas->hSpatParamRendCom->num_freq_bands; j++ )
+ {
+ st_ivas->hSpatParamRendCom->diffuseness_vector_fx[i][j] = float_to_fix( st_ivas->hSpatParamRendCom->diffuseness_vector[i][j], 30 );
+ st_ivas->hSpatParamRendCom->energy_ratio1_fx[i][j] = float_to_fix( st_ivas->hSpatParamRendCom->energy_ratio1[i][j], 30 );
+ IF( EQ_16( st_ivas->hQMetaData->no_directions, 2 ) )
+ {
+ st_ivas->hSpatParamRendCom->energy_ratio2_fx[i][j] = float_to_fix( st_ivas->hSpatParamRendCom->energy_ratio2[i][j], 30 );
+ st_ivas->hSpatParamRendCom->spreadCoherence2_fx[i][j] = float_to_fix16( st_ivas->hSpatParamRendCom->spreadCoherence2[i][j], 15 );
+ }
+ st_ivas->hSpatParamRendCom->surroundingCoherence_fx[i][j] = float_to_fix16( st_ivas->hSpatParamRendCom->surroundingCoherence[i][j], 15 );
+ st_ivas->hSpatParamRendCom->spreadCoherence_fx[i][j] = float_to_fix16( st_ivas->hSpatParamRendCom->spreadCoherence[i][j], 15 );
+ }
+ }
+ }
+ // Float to fix conversion ends here.
+
+ IF( ( error = ivas_masa_decode_fx( st_ivas, st_ivas->hCPE[0]->hCoreCoder[0], &nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+
+ // Fix to float conversion starts here.
+ IF( st_ivas->hSpatParamRendCom != NULL )
+ {
+ FOR( Word16 i = 0; i < st_ivas->hSpatParamRendCom->dirac_md_buffer_length; i++ )
+ {
+ FOR( Word16 j = 0; j < st_ivas->hSpatParamRendCom->num_freq_bands; j++ )
+ {
+ st_ivas->hSpatParamRendCom->energy_ratio1[i][j] = fix_to_float( st_ivas->hSpatParamRendCom->energy_ratio1_fx[i][j], 30 );
+ st_ivas->hSpatParamRendCom->diffuseness_vector[i][j] = fix_to_float( st_ivas->hSpatParamRendCom->diffuseness_vector_fx[i][j], 30 );
+ IF( EQ_16( st_ivas->hQMetaData->no_directions, 2 ) )
+ {
+ st_ivas->hSpatParamRendCom->energy_ratio2[i][j] = fix_to_float( st_ivas->hSpatParamRendCom->energy_ratio2_fx[i][j], 30 );
+ st_ivas->hSpatParamRendCom->spreadCoherence2[i][j] = fix_to_float( st_ivas->hSpatParamRendCom->spreadCoherence2_fx[i][j], 15 );
+ }
+ st_ivas->hSpatParamRendCom->surroundingCoherence[i][j] = fix_to_float( st_ivas->hSpatParamRendCom->surroundingCoherence_fx[i][j], 15 );
+ st_ivas->hSpatParamRendCom->spreadCoherence[i][j] = fix_to_float( st_ivas->hSpatParamRendCom->spreadCoherence_fx[i][j], 15 );
+ }
+ }
+ }
+ FOR( Word16 d = 0; d < max( st_ivas->hMasa->config.numberOfDirections, st_ivas->hQMetaData->no_directions ); d++ )
+ {
+ FOR( Word16 j = 0; j < max( st_ivas->hMasa->config.numCodingBands, st_ivas->hQMetaData->q_direction[0].cfg.nbands ); j++ )
+ {
+ FOR( Word16 k = 0; k < MAX_PARAM_SPATIAL_SUBFRAMES; k++ )
+ {
+ st_ivas->hQMetaData->q_direction[d].band_data[j].elevation[k] = fix_to_float( st_ivas->hQMetaData->q_direction[d].band_data[j].elevation_fx[k], Q22 );
+ st_ivas->hQMetaData->q_direction[d].band_data[j].azimuth[k] = fix_to_float( st_ivas->hQMetaData->q_direction[d].band_data[j].azimuth_fx[k], Q22 );
+ st_ivas->hQMetaData->q_direction[d].band_data[j].energy_ratio[k] = fix_to_float( st_ivas->hQMetaData->q_direction[d].band_data[j].energy_ratio_fx[k], Q30 );
+ }
+ }
+ }
+ FOR( Word32 l = 0; l < st_ivas->nchan_ism; l++ )
+ {
+ st_ivas->hMasaIsmData->q_azimuth_old[l] = fix_to_float( st_ivas->hMasaIsmData->q_azimuth_old_fx[l], Q22 );
+ }
+ IF( st_ivas->hMasaIsmData != NULL )
+ {
+ FOR( Word32 k = 0; k < MAX_PARAM_SPATIAL_SUBFRAMES; k++ )
+ {
+ FOR( Word32 j = 0; j < MASA_FREQUENCY_BANDS; j++ )
+ {
+ st_ivas->hMasaIsmData->masa_to_total_energy_ratio[k][j] = fix_to_float( st_ivas->hMasaIsmData->masa_to_total_energy_ratio_fx[k][j], Q30 );
+ }
+ }
+ }
+ st_ivas->hMasa->data.dir_decode_quality = fix16_to_float( st_ivas->hMasa->data.dir_decode_quality_fx, Q14 );
+ IF( st_ivas->hMasa->hMasaLfeSynth != NULL )
+ {
+ FOR ( Word16 j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ )
+ {
+ st_ivas->hMasa->hMasaLfeSynth->lfeToTotalEnergyRatio[j] = fix16_to_float( st_ivas->hMasa->hMasaLfeSynth->lfeToTotalEnergyRatio_fx[j], Q14 );
+ }
+ }
+ IF( st_ivas->hSpatParamRendCom != NULL )
+ {
+ FOR( Word16 i = 0; i < st_ivas->hSpatParamRendCom->numIsmDirections; i++ )
+ {
+ FOR( Word16 block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ )
+ {
+ FOR( Word16 b = 0; b < st_ivas->hSpatParamRendCom->num_freq_bands; b++ )
+ {
+ st_ivas->hMasaIsmData->energy_ratio_ism[i][block][b] = fix_to_float( st_ivas->hMasaIsmData->energy_ratio_ism_fx[i][block][b], Q30 );
+ }
+ }
+ }
+ }
+ // Fixed to float conversion ends here.
#else
if ( ( error = ivas_masa_decode( st_ivas, st_ivas->hCPE[0]->hCoreCoder[0], &nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
-#endif
{
return error;
}
+#endif
/* Configuration of combined-format bit-budget distribution */
ivas_set_surplus_brate_dec( st_ivas, &ism_total_brate );
diff --git a/lib_dec/ivas_sce_dec_fx.c b/lib_dec/ivas_sce_dec_fx.c
index 2a369911fff31c60ce64b718fe18bb1897e9a424..ccda77544935005e37732189499ef71f2d320f2f 100644
--- a/lib_dec/ivas_sce_dec_fx.c
+++ b/lib_dec/ivas_sce_dec_fx.c
@@ -400,11 +400,43 @@ ivas_error create_sce_dec(
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) );
}
-#ifndef IVAS_FLOAT_FIXED_TO_BE_REMOVED
- td_cng_dec_init( st );
+#ifdef IVAS_FLOAT_FIXED
+#if 1 // Float To Fix conversions
+ floatToFixed_arr(st->hTdCngDec->shb_lpcCNG, st->hTdCngDec->shb_lpcCNG_fx, 15, LPC_SHB_ORDER + 1);
+ st->hTdCngDec->shb_cng_gain_fx_32 = floatToFixed(st->hTdCngDec->shb_cng_gain, 11);
+ floatToFixed_arr(st->lsp_old, st->lsp_old_fx, 15, M);
+#endif // Float to fix conversions
+
+ td_cng_dec_init_ivas_fx( st );
+
+#if 1 // Fix to float conversions
+ st->hTdCngDec->Enew = fix_to_float(st->hTdCngDec->Enew_fx, 6);
+ fixedToFloat_arr(st->lspCNG_fx, st->lspCNG, 15, M);
+ st->hTdCngDec->shb_cng_ener = fix_to_float(st->hTdCngDec->shb_cng_ener_fx_32, 11);
+ fixedToFloat_arr(st->hTdCngDec->shb_lpcCNG_fx, st->hTdCngDec->shb_lpcCNG, 15, LPC_SHB_ORDER + 1);
+ st->hTdCngDec->shb_cng_gain = fix_to_float(st->hTdCngDec->shb_cng_gain_fx_32, 11);
+ st->hTdCngDec->wb_cng_ener = fix_to_float(st->hTdCngDec->wb_cng_ener_fx_32, 11);
+ st->hTdCngDec->last_wb_cng_ener = fix_to_float(st->hTdCngDec->last_wb_cng_ener_fx_32, 11);
+ st->hTdCngDec->last_shb_cng_ener = fix_to_float(st->hTdCngDec->last_shb_cng_ener_fx_32, 11);
+ fixedToFloat_arr(st->hTdCngDec->ho_lsp_hist_fx, st->hTdCngDec->ho_lsp_hist, 15, HO_HIST_SIZE * M);
+ fixedToFloat_arrL(st->hTdCngDec->ho_ener_hist_fx, st->hTdCngDec->ho_ener_hist, 15, HO_HIST_SIZE);
+ fixedToFloat_arrL(st->hTdCngDec->ho_env_hist_fx, st->hTdCngDec->ho_env_hist, 15, HO_HIST_SIZE * NUM_ENV_CNG);
+ fixedToFloat_arr(st->hTdCngDec->ho_lsp_circ_fx, st->hTdCngDec->ho_lsp_circ, 15, HO_HIST_SIZE * M);
+ fixedToFloat_arrL(st->hTdCngDec->ho_ener_circ_fx, st->hTdCngDec->ho_ener_circ, 15, HO_HIST_SIZE);
+ fixedToFloat_arrL(st->hTdCngDec->ho_env_circ_fx, st->hTdCngDec->ho_env_circ, 15, HO_HIST_SIZE * NUM_ENV_CNG);
+ fixedToFloat_arrL(st->hTdCngDec->lp_env_fx, st->hTdCngDec->lp_env, 15, NUM_ENV_CNG);
+ fixedToFloat_arr(st->hTdCngDec->exc_mem_fx, st->hTdCngDec->exc_mem, 15, 24);
+ fixedToFloat_arr(st->hTdCngDec->exc_mem1_fx, st->hTdCngDec->exc_mem1, 15, 30);
+ fixedToFloat_arrL(st->hTdCngDec->old_env_fx, st->hTdCngDec->old_env, 15, NUM_ENV_CNG);
+ fixedToFloat_arr(st->hTdCngDec->lsp_shb_prev_fx, st->hTdCngDec->lsp_shb_prev, 15, LPC_SHB_ORDER);
+ fixedToFloat_arr(st->hTdCngDec->lsp_shb_prev_prev_fx, st->hTdCngDec->lsp_shb_prev_prev, 15, LPC_SHB_ORDER);
+ fixedToFloat_arr(st->hTdCngDec->interpol_3_2_cng_dec_fx, st->hTdCngDec->interpol_3_2_cng_dec, 15, INTERP_3_2_MEM_LEN);
+
+
+#endif // Fix to float conversions
#else
td_cng_dec_init_flt( st );
-#endif // IVAS_FLOAT_FIXED_TO_BE_REMOVED
+#endif // IVAS_FLOAT_FIXED
}
/*-----------------------------------------------------------------*
diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h
index 19a7404063b8461fa7e7bc4c464a2edccd7d97ca..d11b7aa0eca746e247e32100f35c4ef4a3d5a345 100644
--- a/lib_dec/ivas_stat_dec.h
+++ b/lib_dec/ivas_stat_dec.h
@@ -404,6 +404,7 @@ typedef struct stereo_td_dec_data_structure
int16_t tdm_lp_reuse_flag; /* Flag that indicate if it is possible to reuse the LP coefficient from the primary channel or not */
int16_t tdm_low_rate_mode; /* secondary channel low rate mode flag */
float tdm_Pri_pitch_buf[NB_SUBFR];
+ Word16 tdm_Pri_pitch_buf_fx[NB_SUBFR];
int16_t tdm_Pitch_reuse_flag;
int16_t tdm_LRTD_flag;
int16_t flag_skip_DMX; /* flag that indicates whether the TD downmixing is skipped */
diff --git a/lib_dec/ivas_td_low_rate_dec.c b/lib_dec/ivas_td_low_rate_dec.c
index d1a50780800434bb8139dd0271d7ad267a427ad5..a7c9f40d53ba995a3128f6eac87a7efb8769cc72 100644
--- a/lib_dec/ivas_td_low_rate_dec.c
+++ b/lib_dec/ivas_td_low_rate_dec.c
@@ -185,7 +185,7 @@ void tdm_low_rate_dec(
Copy(st->hGSCDec->last_bitallocation_band, st->hGSCDec->last_bitallocation_band_fx, 6);
st->GSC_noisy_speech_fx = st->GSC_noisy_speech;
st->lp_gainc_fx = float_to_fix16(st->lp_gainc, Q3);
- st->bfi_pitch_fx = float_to_fix16(st->bfi_pitch, Q6);
+ st->bfi_pitch_fx = float_to_fix16(st->bfi_pitch, 0);
st->tilt_code_fx = float_to_fix16(st->tilt_code, Q15);
floatToFixed_arr(st->tilt_code_dec, st->tilt_code_dec_fx, Q15, NB_SUBFR16k);
st->last_good_fx = st->last_good;
@@ -235,7 +235,7 @@ void tdm_low_rate_dec(
Copy(st->hGSCDec->last_bitallocation_band_fx, st->hGSCDec->last_bitallocation_band, 6);
st->GSC_noisy_speech = st->GSC_noisy_speech_fx;
st->lp_gainc = fixedToFloat(st->lp_gainc_fx, Q3);
- st->bfi_pitch = fixedToFloat(st->bfi_pitch_fx, Q6);
+ st->bfi_pitch = fixedToFloat(st->bfi_pitch_fx, 0);
st->tilt_code = fixedToFloat(st->tilt_code_fx, Q15);
fixedToFloat_arr(st->tilt_code_dec_fx, st->tilt_code_dec, Q15, NB_SUBFR16k);
/*hGSCDec end*/
@@ -536,7 +536,7 @@ void decod_gen_2sbfr(
Copy( st->hGSCDec->last_bitallocation_band, st->hGSCDec->last_bitallocation_band_fx, 6 );
st->GSC_noisy_speech_fx = st->GSC_noisy_speech;
st->lp_gainc_fx = float_to_fix16( st->lp_gainc, Q3 );
- st->bfi_pitch_fx = float_to_fix16( st->bfi_pitch, Q6 );
+ st->bfi_pitch_fx = float_to_fix16( st->bfi_pitch, 0 );
st->tilt_code_fx = float_to_fix16( st->tilt_code, Q15 );
floatToFixed_arr( st->tilt_code_dec, st->tilt_code_dec_fx, Q15, NB_SUBFR16k );
st->dm_fx.prev_state = float_to_fix16(st->dispMem[0], 0);
@@ -596,7 +596,7 @@ void decod_gen_2sbfr(
Copy( st->hGSCDec->last_bitallocation_band_fx, st->hGSCDec->last_bitallocation_band, 6 );
st->GSC_noisy_speech = st->GSC_noisy_speech_fx;
st->lp_gainc = fixedToFloat( st->lp_gainc_fx, Q3 );
- st->bfi_pitch = fixedToFloat( st->bfi_pitch_fx, Q6 );
+ st->bfi_pitch = fixedToFloat( st->bfi_pitch_fx, 0 );
st->tilt_code = fixedToFloat( st->tilt_code_fx, Q15 );
fixedToFloat_arr( st->tilt_code_dec_fx, st->tilt_code_dec, Q15, NB_SUBFR16k );
st->dispMem[0] = fixedToFloat(st->dm_fx.prev_state, 0);
diff --git a/lib_dec/lsf_dec_fx.c b/lib_dec/lsf_dec_fx.c
index 0d3532e59b8d8e524acd5ca1943f9938c33fb706..333c20c5e0fa51c588e2c35dceb5d216604bb5ff 100644
--- a/lib_dec/lsf_dec_fx.c
+++ b/lib_dec/lsf_dec_fx.c
@@ -45,9 +45,14 @@ static void dqlsf_CNG_fx(
move16();
/* deindex_lvq_cng decoder does not need to know the sampling rate, the sampling rate data is embedded inside the LSF coefficients */
- ber_flag=
- deindex_lvq_cng_fx( &indice[1], lsf_q, indice[0], LSF_BITS_CNG-4, &st_fx->offset_scale1_fx[0][0], &st_fx->offset_scale2_fx[0][0], &st_fx->no_scales_fx[0][0]);
-
+ IF (EQ_16(st_fx->element_mode, EVS_MONO)) {
+ ber_flag =
+ deindex_lvq_cng_fx(&indice[1], lsf_q, indice[0], LSF_BITS_CNG - 4, &st_fx->offset_scale1_fx[0][0], &st_fx->offset_scale2_fx[0][0], &st_fx->no_scales_fx[0][0]);
+ }
+ ELSE {
+ ber_flag =
+ deindex_lvq_cng_ivas_fx(&indice[1], lsf_q, indice[0], LSF_BITS_CNG - 4);
+ }
st_fx->BER_detect = s_or(ber_flag, st_fx->BER_detect);
/* The sampling frequency of the LP-CNG frame can be determined by checking the value of the highest order LSF coefficient (last coefficient).
@@ -279,13 +284,13 @@ void lsf_dec_fx(
Copy( lsp_mid, st_fx->lsp_old_fx, M );
lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core);
}
-#ifdef ADD_LRTD
+#if 1//def ADD_LRTD
IF (EQ_16(tdm_low_rate_mode, 1) && GT_16(coder_type, UNVOICED))
{
- PMT("To be verified")
- IF (EQ_16(st_fx->active_cnt_fx, 1) )
+ //PMT("To be verified")
+ IF (EQ_16(st_fx->active_cnt, 1) )
{
- Copy(lsp_mid, st_fx->lsp_old, M);
+ Copy(lsp_mid, st_fx->lsp_old_fx, M);
lsp2lsf_fx(lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core);
Copy(lsp_new, lsp_mid, M);
}
@@ -303,7 +308,14 @@ void lsf_dec_fx(
* Check LSF stability (distance between old LSFs and current LSFs)
*------------------------------------------------------------------*/
- st_fx->stab_fac_fx = lsf_stab_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); /*Q15*/
+ IF( EQ_16(st_fx->element_mode, EVS_MONO ) )
+ {
+ st_fx->stab_fac_fx = lsf_stab_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); /*Q15*/
+ }
+ else
+ {
+ st_fx->stab_fac_fx = lsf_stab_ivas_fx(lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame );
+ }
return;
}
@@ -864,7 +876,7 @@ void lsf_mid_dec_fx(
ratio = tbl_mid_gen_wb_5b_fx;
BREAK;
}
-#ifdef IVAS_CODE
+#if 1//def IVAS_CODE
case 4:
{
ratio = tbl_mid_gen_wb_4b_fx;
diff --git a/lib_dec/pit_dec_fx.c b/lib_dec/pit_dec_fx.c
index f9693f7caf0715b6a371b96d3ce65d557c747fcd..a847853f99a1c7ab6e6ab230ebeeb1202c677b33 100644
--- a/lib_dec/pit_dec_fx.c
+++ b/lib_dec/pit_dec_fx.c
@@ -564,7 +564,6 @@ printf("function not tested yet\n");
return pitch;
}
-#ifdef IVAS_FLOAT_FIXED
/*======================================================================*/
/* FUNCTION : pit_decode_ivas_fx() */
/*-----------------------------------------------------------------------*/
@@ -845,7 +844,6 @@ Word16 pit_decode_ivas_fx( /* o : floating pitch value
return pitch;
}
-#endif
/*----------------------------------------------------------*
* pit_Q_dec_fx()
diff --git a/lib_dec/rst_dec_fx.c b/lib_dec/rst_dec_fx.c
index 21d28bf27587f27cadf60b58b27bb796ab06c7b0..2e7848c70d5dfd2b852e56c296a2c6aeb8b24f2d 100644
--- a/lib_dec/rst_dec_fx.c
+++ b/lib_dec/rst_dec_fx.c
@@ -79,7 +79,10 @@ void CNG_reset_dec_fx(
st_fx->bpf_off = 1;
move16();
/* Reset active frame counter */
- st_fx->hTdCngDec->act_cnt2_fx = 0;
+ if (st_fx->hTdCngDec != NULL)
+ {
+ st_fx->hTdCngDec->act_cnt2_fx = 0;
+ }
move16();
return;
diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h
index 5d8f83466136a4536f2d2942935566473e0fd11a..85e21bfabeb4a0e3ce69e399cb8960a66c66f310 100644
--- a/lib_dec/stat_dec.h
+++ b/lib_dec/stat_dec.h
@@ -948,10 +948,25 @@ typedef struct td_cng_dec_structure
int16_t shb_dtx_count;
int16_t trans_cnt;
+#ifdef IVAS_FLOAT_FIXED
+ Word16 interpol_3_2_cng_dec_fx[INTERP_3_2_MEM_LEN];
+
+ Word32 shb_cng_ener_fx_32; // Q(11)
+ Word32 shb_cng_gain_fx_32; //Q(11)
+ Word32 wb_cng_ener_fx_32; // Q(11)
+ Word32 last_wb_cng_ener_fx_32; // Q(11)
+ Word32 last_shb_cng_ener_fx_32; // Q(11)
+ Word16 lsp_shb_prev_fx[LPC_SHB_ORDER]; //Q(14)
+ Word16 lsp_shb_prev_prev_fx[LPC_SHB_ORDER]; //Q(14)
+
+#endif
int16_t burst_cnt;
Word16 burst_cnt_fx;
float last_shb_ener;
+#ifdef IVAS_FLOAT_FIXED
+ Word32 last_shb_ener_fx; //Q(11)
+#endif
Word16 last_cng_type_fx; /* DTX/CNG - flag indicating last frame LP or CLDFB based SID/CNG */
@@ -2000,6 +2015,7 @@ typedef struct Decoder_State
float bfi_pitch; /* FEC - pitch for FEC */
Word16 bfi_pitch_fx; /* FEC - pitch for FEC */
+ Word32 bfi_pitch_fx32; /* FEC - pitch for FEC */
int16_t bfi_pitch_frame; /* FEC - frame length when pitch for FEC is saved */
//Word16 bfi_pitch_frame_fx; /*FEC - frame length when pitch for FEC is saved Q0*/
@@ -2308,6 +2324,7 @@ typedef struct Decoder_State
* Fixed point only
*----------------------------------------------------------------------------------*/
Word16 Q_exc;
+ Word16 Q_exc_cng;
Word16 prev_Q_exc;
Word16 Q_subfr[L_Q_MEM];
@@ -2320,8 +2337,9 @@ typedef struct Decoder_State
Word16 prev_Q_synth;
Word16 prev_SWB_fenv_fx[SWB_FENV];
- Word16 Q_syn2;
- Word16 Q_syn;
+ Word16 Q_syn;
+ Word16 Q_syn2;
+ Word16 Q_syn_cng;
Word16 prev_Q_syn;
Word16 prev_frame_pow_exp;
Word16 prev_ener_fx_Q;
diff --git a/lib_dec/swb_tbe_dec.c b/lib_dec/swb_tbe_dec.c
index 8664d2c01972156d2d840234d54cd4407efd022a..ff07e8d78399a85b7be8a9eb7cfb7a0d9e3c2f53 100644
--- a/lib_dec/swb_tbe_dec.c
+++ b/lib_dec/swb_tbe_dec.c
@@ -1072,7 +1072,8 @@ void swb_tbe_dec(
}
else
{
- scale = (float) sqrt( curr_pow / prev_pow );
+ /* individual sqrt to avoid infinite (nan) value due to acelp_core_dec changes */
+ scale = (float) (sqrt( curr_pow ) /sqrt( prev_pow ));
}
for ( i = 0; i < L_SHB_LAHEAD; i++ )