diff --git a/Workspace_msvc/lib_com.vcxproj b/Workspace_msvc/lib_com.vcxproj
index d85ee4e992988bc51c341be16924c9e8a5cd9550..1dbc36e30ccfdae2ab2d6bf9f324012e36e5aa57 100644
--- a/Workspace_msvc/lib_com.vcxproj
+++ b/Workspace_msvc/lib_com.vcxproj
@@ -176,8 +176,11 @@
+
+
+
@@ -186,10 +189,12 @@
+
+
@@ -229,6 +234,7 @@
+
@@ -241,23 +247,32 @@
+
+
+
+
+
+
+
+
+
@@ -269,9 +284,12 @@
+
+
+
@@ -286,9 +304,11 @@
+
+
@@ -310,7 +330,8 @@
-
+
+
diff --git a/Workspace_msvc/lib_com.vcxproj.filters b/Workspace_msvc/lib_com.vcxproj.filters
index 91091b0ad1b5b1b585cf7b5be5b9978cd0f53ff6..965c775616157139aca19be30adbe811ad59ed76 100644
--- a/Workspace_msvc/lib_com.vcxproj.filters
+++ b/Workspace_msvc/lib_com.vcxproj.filters
@@ -518,6 +518,64 @@
common_all_c
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_all_c
+
+
+ common_evs_c
+
+
+ common_all_c
+
+
+
+ common_evs_c
+
+
+ common_evs_c
+
+
+ common_evs_c
+
+
+ common_evs_c
+
+
+ common_evs_c
+
+
+ common_evs_c
+
+
+ common_evs_c
+
+
+ common_all_c
+
@@ -582,15 +640,14 @@
common_h
-
- common_h
-
common_h
common_h
+
+
@@ -606,4 +663,4 @@
{b95b7bed-a666-4a00-9332-2b528638503e}
-
\ No newline at end of file
+
diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c
index 6c184d69cc0f71b83175f51004eb81f03b80f8a1..2061de6a3168dbde5b09c17bcc9bc9414515463f 100644
--- a/lib_com/basop_util.c
+++ b/lib_com/basop_util.c
@@ -40,10 +40,12 @@
#include "complex_basop.h"
#include "basop_util.h"
#include "rom_com.h"
+#include "rom_basic_math.h"
#include "basop_settings.h"
#include "control.h"
#include "cnst.h"
+
#define WMC_TOOL_SKIP
extern const Word32 SqrtTable[32];
@@ -54,12 +56,6 @@ extern const Word16 ISqrtDiffTable[32];
extern const Word32 InvTable[32];
extern const Word16 InvDiffTable[32];
-static __inline Word16 L_Extract_lc(const Word32 L_32, Word16 *p_hi)
-{
- *p_hi = extract_h(L_32);
- return lshr(extract_l(L_32), 1);
-
-}
Word32 BASOP_Util_Log2(
Word32 x )
@@ -1740,20 +1736,6 @@ Word16 BASOP_Util_Divide3216_Scale(
}
-static const Word16 table_pow2[32] = {
- 16384, 16743, 17109, 17484, 17867, 18258, 18658, 19066, 19484, 19911,
- 20347, 20792, 21247, 21713, 22188, 22674, 23170, 23678, 24196, 24726,
- 25268, 25821, 26386, 26964, 27554, 28158, 28774, 29405, 30048, 30706,
- 31379, 32066
-};
-/* table of table_pow2[i+1] - table_pow2[i] */
-static const Word16 table_pow2_diff_x32[32] = {
- 11488, 11712, 12000, 12256, 12512, 12800, 13056, 13376, 13664, 13952,
- 14240, 14560, 14912, 15200, 15552, 15872, 16256, 16576, 16960, 17344,
- 17696, 18080, 18496, 18880, 19328, 19712, 20192, 20576, 21056, 21536,
- 21984, 22432
-};
-
Word32 Pow2( /* o Q0 : result (range: 0<=val<=0x7fffffff) */
Word16 exponant, /* i Q0 : Integer part. (range: 0<=val<=30) */
Word16 fraction /* i Q15 : Fractional part. (range: 0.0<=val<1.0) */
@@ -1795,45 +1777,6 @@ Word32 Pow2( /* o Q0 : result (range: 0<=val<=0x7fffffff
*
*************************************************************************/
-static const Word32 L_table[32] = {
- -32768L, 95322112L, 187793408L, 277577728L,
- 364871680L, 449740800L, 532381696L, 612859904L,
- 691306496L, 767787008L, 842432512L, 915308544L,
- 986546176L, 1056210944L, 1124302848L, 1190887424L,
- 1256095744L, 1319993344L, 1382580224L, 1443921920L,
- 1504083968L, 1563131904L, 1621000192L, 1677885440L,
- 1733722112L, 1788510208L, 1842380800L, 1895399424L,
- 1947435008L, 1998618624L, 2049015808L, 2098626560L
-};
-
-static const Word16 table_diff[32] = {
- 1455, 1411, 1370, 1332, 1295, 1261, 1228, 1197,
- 1167, 1139, 1112, 1087, 1063, 1039, 1016, 995,
- 975, 955, 936, 918, 901, 883, 868, 852,
- 836, 822, 809, 794, 781, 769, 757, 744
-};
-
-Word16 Log2_norm_lc( /* o : Fractional part of Log2. (range: 0<=val<1) */
- Word32 L_x /* i : input value (normalized) */
-)
-{
- Word16 i, a;
- Word16 y;
-
-
- L_x = L_shr( L_x, 9 );
- a = extract_l( L_x ); /* Extract b10-b24 of fraction */
- a = lshr( a, 1 );
-
- i = mac_r( L_x, -32 * 2 - 1, 16384 ); /* Extract b25-b31 minus 32 */
-
- y = mac_r( L_table[i], table_diff[i], a ); /* table[i] << 16 - diff*a*2 */
-
-
- return y;
-}
-
-
Word32 BASOP_Util_fPow(
Word32 base_m,
Word16 base_e,
@@ -2133,29 +2076,6 @@ Word32 BASOP_Util_Add_Mant32Exp /* o : normalized result mantissa */
return ( L_tmp );
}
-static const Word32 L_table_isqrt[48] = {
- 2147418112L, 2083389440L, 2024669184L, 1970667520L,
- 1920794624L, 1874460672L, 1831403520L, 1791098880L,
- 1753415680L, 1717960704L, 1684602880L, 1653145600L,
- 1623326720L, 1595080704L, 1568276480L, 1542782976L,
- 1518469120L, 1495334912L, 1473183744L, 1451950080L,
- 1431633920L, 1412169728L, 1393491968L, 1375469568L,
- 1358168064L, 1341521920L, 1325465600L, 1309933568L,
- 1294991360L, 1280507904L, 1266548736L, 1252982784L,
- 1239875584L, 1227161600L, 1214775296L, 1202847744L,
- 1191182336L, 1179910144L, 1168965632L, 1158283264L,
- 1147863040L, 1137770496L, 1127940096L, 1118306304L,
- 1108934656L, 1099825152L, 1090912256L, 1082261504L
-};
-/* table of table_isqrt[i] - table_isqrt[i+1] */
-static const Word16 table_isqrt_diff[48] = {
- 977, 896, 824, 761, 707, 657, 615, 575,
- 541, 509, 480, 455, 431, 409, 389, 371,
- 353, 338, 324, 310, 297, 285, 275, 264,
- 254, 245, 237, 228, 221, 213, 207, 200,
- 194, 189, 182, 178, 172, 167, 163, 159,
- 154, 150, 147, 143, 139, 136, 132, 130
-};
static const Word16 shift_lc[] = { 9, 10 };
@@ -2197,15 +2117,6 @@ Word32 Isqrt_lc1(
return L_tmp;
}
-static const Word16 sqrt_table[49] = {
- 16384, 16888, 17378, 17854, 18318, 18770, 19212,
- 19644, 20066, 20480, 20886, 21283, 21674, 22058,
- 22435, 22806, 23170, 23530, 23884, 24232, 24576,
- 24915, 25249, 25580, 25905, 26227, 26545, 26859,
- 27170, 27477, 27780, 28081, 28378, 28672, 28963,
- 29251, 29537, 29819, 30099, 30377, 30652, 30924,
- 31194, 31462, 31727, 31991, 32252, 32511, 32767
-};
/*! r: output value, Q31 */
Word32 Sqrt_l(
diff --git a/lib_com/basop_util.h b/lib_com/basop_util.h
index 85500c1e9793d2d25148238b5d7d4b49960d5425..0a406bf01514b8910914e84ea0c6e0c428bd7c13 100644
--- a/lib_com/basop_util.h
+++ b/lib_com/basop_util.h
@@ -43,6 +43,7 @@
#include "typedef.h"
#include "basop32.h"
#include "math_32.h"
+#include "log2.h"
#define LD_DATA_SCALE ( 6 )
@@ -695,30 +696,6 @@ Word32 Pow2( /* o : Q0 : result (range: 0<=val<=0x7ffff
Word16 fraction /* i : Q15 : Fractionnal part. (range: 0.0<=val<1.0) */
);
-/*************************************************************************
- *
- * FUNCTION: Log2_norm()
- *
- * PURPOSE: Computes log2(L_x, exp), where L_x is positive and
- * normalized, and exp is the normalisation exponent
- * If L_x is negative or zero, the result is 0.
- *
- * DESCRIPTION:
- * The function Log2(L_x) is approximated by a table and linear
- * interpolation. The following steps are used to compute Log2(L_x)
- *
- * 1- exponent = 30-norm_exponent
- * 2- i = bit25-b31 of L_x; 32<=i<=63 (because of normalization).
- * 3- a = bit10-b24
- * 4- i -=32
- * 5- fraction = table[i]<<16 - (table[i] - table[i+1]) * a * 2
- *
- *************************************************************************/
-
-Word16 Log2_norm_lc( /* o : Fractional part of Log2. (range: 0<=val<1) */
- Word32 L_x /* i : input value (normalized) */
-);
-
/*************************************************************************
*
* FUNCTION: BASOP_Util_fPow()
diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c
index 2c743fd6ff5f52654b60341f519996f0e78e66b8..99b31f30bf7ac120e628ef4b51671b27daca81dc 100644
--- a/lib_com/bitstream.c
+++ b/lib_com/bitstream.c
@@ -2714,7 +2714,7 @@ void evs_dec_previewFrame_float(
void dtx_read_padding_bits(
- DEC_CORE_HANDLE_FLOAT st,
+ DEC_CORE_HANDLE st,
const int16_t num_bits )
{
/* TODO: temporary hack, need to decide what to do with core-coder bitrate */
diff --git a/lib_com/bitstream_fx.c b/lib_com/bitstream_fx.c
index 38d9dc9fe5b2e2330290a2cc4a4acf236244640d..4f848c31a2da61db1d9a6c758b1cd8f326e5a2f1 100644
--- a/lib_com/bitstream_fx.c
+++ b/lib_com/bitstream_fx.c
@@ -383,7 +383,7 @@ void push_next_bits_fx(
*-------------------------------------------------------------------*/
UWord16 get_next_indice_fx( /* o : value of the indice */
- Decoder_State_fx *st_fx, /* i/o: decoder state structure */
+ Decoder_State *st_fx, /* i/o: decoder state structure */
Word16 nb_bits /* i : number of bits that were used to quantize the indice */
)
{
@@ -420,7 +420,7 @@ UWord16 get_next_indice_fx( /* o : value of the indice */
*-------------------------------------------------------------------*/
UWord16 get_next_indice_1_fx( /* o : value of the indice */
- Decoder_State_fx *st_fx /* i/o: decoder state structure */
+ Decoder_State *st_fx /* i/o: decoder state structure */
)
{
/* detect corrupted bitstream */
@@ -446,7 +446,7 @@ UWord16 get_next_indice_1_fx( /* o : value of the indice */
*-------------------------------------------------------------------*/
void get_next_indice_tmp_fx(
- Decoder_State_fx *st_fx, /* o : decoder state structure */
+ Decoder_State *st_fx, /* o : decoder state structure */
Word16 nb_bits /* i : number of bits that were used to quantize the indice */
)
{
@@ -461,7 +461,7 @@ void get_next_indice_tmp_fx(
*-------------------------------------------------------------------*/
UWord16 get_indice_fx( /* o : value of the indice */
- Decoder_State_fx *st_fx, /* i/o: decoder state structure */
+ Decoder_State *st_fx, /* i/o: decoder state structure */
Word16 pos, /* i : absolute position in the bitstream (update after the read) */
Word16 nb_bits /* i : number of bits that were used to quantize the indice */
)
@@ -497,7 +497,7 @@ UWord16 get_indice_fx( /* o : value of the indice */
*-------------------------------------------------------------------*/
UWord16 get_indice_1_fx( /* o : value of the indice */
- Decoder_State_fx *st_fx, /* i/o: decoder state structure */
+ Decoder_State *st_fx, /* i/o: decoder state structure */
Word16 pos /* i : absolute position in the bitstream (update after the read) */
)
{
@@ -547,7 +547,7 @@ void reset_indices_enc_fx(
*-------------------------------------------------------------------*/
void reset_indices_dec_fx(
- Decoder_State_fx *st_fx
+ Decoder_State *st_fx
)
{
st_fx->next_bit_pos_fx = 0;
@@ -791,7 +791,7 @@ void indices_to_serial_generic(
static void decoder_selectCodec(
- Decoder_State_fx *st, /* i/o: decoder state structure */
+ Decoder_State *st, /* i/o: decoder state structure */
const Word32 total_brate, /* i : total bitrate */
const Word16 bit0
)
@@ -939,7 +939,7 @@ static void decoder_selectCodec(
-void dec_prm_core(Decoder_State_fx *st)
+void dec_prm_core(Decoder_State *st)
{
Word16 n, frame_size_index, num_bits;
UWord16 lsb;
@@ -1027,7 +1027,7 @@ void dec_prm_core(Decoder_State_fx *st)
*-----------------------------------------------------------------*/
void decision_matrix_core_dec(
- Decoder_State_fx *st /* i/o: decoder state structure */
+ Decoder_State *st /* i/o: decoder state structure */
)
{
Word16 start_idx;
@@ -1162,7 +1162,7 @@ void decision_matrix_core_dec(
*-------------------------------------------------------------------*/
static void mdct_switching_dec(
- Decoder_State_fx *st /* i/o: decoder state structure */
+ Decoder_State *st /* i/o: decoder state structure */
)
{
IF(st->Opt_AMR_WB_fx != 0)
@@ -1396,7 +1396,7 @@ Word32 BIT_ALLOC_IDX_16KHZ_fx(Word32 brate, Word16 ctype, Word16 sfrm, Word16 tc
*-------------------------------------------------------------------*/
Word16 read_indices_fx( /* o : 1 = reading OK, 0 = problem */
- Decoder_State_fx *st, /* i/o: decoder state structure */
+ Decoder_State *st, /* i/o: decoder state structure */
FILE *file, /* i : bitstream file */
Word16 rew_flag /* i : rewind flag (rewind file after reading)*/
)
@@ -1696,7 +1696,7 @@ Word16 read_indices_fx( /* o : 1 = reading OK, 0 = problem
*-------------------------------------------------------------------*/
static Word32 read_indices_mime_handle_dtx(
- Decoder_State_fx *st,
+ Decoder_State *st,
Word16 isAMRWB_IOmode,
Word16 core_mode,
Word32 total_brate,
@@ -1853,7 +1853,7 @@ static Word32 read_indices_mime_handle_dtx(
*-------------------------------------------------------------------*/
static void read_indices_mime_handle_sti_and_all_zero_bits(
- Decoder_State_fx *st,
+ Decoder_State *st,
Word32 *total_brate,
Word16 sti
)
@@ -1894,7 +1894,7 @@ static void read_indices_mime_handle_sti_and_all_zero_bits(
*-------------------------------------------------------------------------------------------*/
Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem */
- Decoder_State_fx *st, /* i/o: decoder state structure */
+ Decoder_State *st, /* i/o: decoder state structure */
FILE *file, /* i : bitstream file */
Word16 rew_flag /* i : rewind flag (rewind file after reading) */
)
@@ -2120,7 +2120,7 @@ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem
*-------------------------------------------------------------------*/
static void berCheck(
- Decoder_State_fx *st, /* i/o: decoder state structure */
+ Decoder_State *st, /* i/o: decoder state structure */
Word16 *coder_type /* i/o: coder type */
)
{
@@ -2155,7 +2155,7 @@ static void berCheck(
*-------------------------------------------------------------------*/
void getPartialCopyInfo(
- Decoder_State_fx *st, /* i/o: decoder state structure */
+ Decoder_State *st, /* i/o: decoder state structure */
Word16 *coder_type,
Word16 *sharpFlag
)
@@ -2215,7 +2215,7 @@ void getPartialCopyInfo(
*-------------------------------------------------------------------*/
void get_rfFlag(
- Decoder_State_fx *st, /* i: decoder state structure */
+ Decoder_State *st, /* i: decoder state structure */
Word16 *rf_flag, /* o : check for the RF flag */
Word16 *nBits,
Word16 *ind
@@ -2271,7 +2271,7 @@ void get_rfFlag(
*-------------------------------------------------------------------*/
void get_rfFrameType(
- Decoder_State_fx *st, /* i : decoder state structure */
+ Decoder_State *st, /* i : decoder state structure */
Word16 *rf_frame_type /* o : RF frame type */
)
{
@@ -2309,7 +2309,7 @@ void get_rfFrameType(
*-------------------------------------------------------------------*/
void get_rf_fec_offset(
- Decoder_State_fx *st, /* i : decoder state structure */
+ Decoder_State *st, /* i : decoder state structure */
Word16 *rf_fec_offset /* o : RF fec offset */
)
{
@@ -2450,7 +2450,7 @@ void get_NextCoderType_fx(
*-------------------------------------------------------------------*/
void read_indices_from_djb_fx(
- Decoder_State_fx *st, /* i/o: decoder state structure */
+ Decoder_State *st, /* i/o: decoder state structure */
UWord8 *pt_stream, /* i : bitstream file */
Word16 num_bits, /* i : input frame length in bits */
Word16 isAMRWB_IOmode,
diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c
index a7dd5512f38665f95e80616ee205aa8aac76d663..6aecdb7f3bc8a039e3f68f4b75f0213539133b7f 100644
--- a/lib_com/cldfb.c
+++ b/lib_com/cldfb.c
@@ -757,7 +757,7 @@ void resampleCldfb(
timeOffset = hs->p_filter_length - hs->no_channels;
/*low complexity-resampling only stored previous samples that are needed for next frame modulation */
- lerp( hs->cldfb_state, hs->cldfb_state, timeOffset, timeOffsetold );
+ lerp_flt( hs->cldfb_state, hs->cldfb_state, timeOffset, timeOffsetold );
return;
}
@@ -1192,7 +1192,7 @@ void cldfb_restore_memory(
/* adjust sample rate if it was changed in the meanwhile */
if ( hs->memory_length != size )
{
- lerp( hs->cldfb_state, hs->cldfb_state, size, hs->memory_length );
+ lerp_flt( hs->cldfb_state, hs->cldfb_state, size, hs->memory_length );
}
hs->memory_length = 0;
diff --git a/lib_com/gs_gains_fx.c b/lib_com/gs_gains_fx.c
index fd6d8855e9c68037ebf3e2cb4dd3a11a9363c33f..5898093c0e560ab4f20c88e2e6f9d00fab58b2d1 100644
--- a/lib_com/gs_gains_fx.c
+++ b/lib_com/gs_gains_fx.c
@@ -41,12 +41,6 @@
#include "prot_fx2.h"
#include "stl.h"
-static __inline Word16 L_Extract_lc(const Word32 L_32, Word16 *p_hi)
-{
- *p_hi = extract_h(L_32);
- return lshr(extract_l(L_32), 1);
-
-}
/*-------------------------------------------------------------------*
* Local constants
*-------------------------------------------------------------------*/
@@ -330,7 +324,7 @@ static void GSC_gain_adj(
/* _ (Word16) : average frequency gain */
/*==========================================================================*/
Word16 gsc_gaindec_fx( /* o : average frequency gain */
- Decoder_State_fx *st_fx, /* i/o: decoder state structure */
+ Decoder_State *st_fx, /* i/o: decoder state structure */
Word16 y_gainQ_fx[], /* o : quantized gain per band */
const Word32 core_brate_fx, /* i : core used */
Word16 old_y_gain_fx[], /* i/o: AR gain quantizer for low rate */
diff --git a/lib_com/hq2_bit_alloc_fx.c b/lib_com/hq2_bit_alloc_fx.c
index e52909a83153644a23b3292fe7d276311fa86712..a9efb0ac58c5018c2c77483161ae9e29cfc0eb09 100644
--- a/lib_com/hq2_bit_alloc_fx.c
+++ b/lib_com/hq2_bit_alloc_fx.c
@@ -1,7 +1,39 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 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.
+
+*******************************************************************************************************/
+
#include
#include "options.h"
-#include "prot_fx_2.h"
-
+#include "prot_fx2.h"
+#include "rom_com.h"
#define MIN_BITS_FIX 0 /* QRk=18 */
#define HQ_16k40_BIT (HQ_16k40/50) /* 16400/50=328 */
@@ -14,6 +46,12 @@
#define BITS_FACT_0p97 15892 /* (Word16)(0.97f*(float)pow(2, Qbf)+0.5f) */
#define BITS_FACT_0p92 15073 /* (Word16)(0.92f*(float)pow(2, Qbf)+0.5f) */
+ /*-------------------------------------------------------------------*
+ * Bits2indvsb()
+ *
+ * Bit allocation to individual SB's in a group
+ *-------------------------------------------------------------------*/
+
void Bits2indvsb_fx(
const Word32 *L_be, /* i : Qbe Band Energy of sub-band */
const Word16 start_band, /* i : Q0 start band indices */
@@ -211,3 +249,695 @@ void Bits2indvsb_fx(
return;
}
+/*-------------------------------------------------------------------*
+ * hq2_bit_alloc_har()
+ *
+ * Bit allocation mechanism for HQ_HARMONIC mode
+ *-------------------------------------------------------------------*/
+
+void hq2_bit_alloc_har_fx(
+ const Word32 *L_y, /* i : Qbe band energy of sub-vectors */
+ Word16 B_fx, /* i : Q0 number of available bits */
+ const Word16 N_fx, /* i : Q0 number of sub-vectors */
+ Word32 *L_Rsubband, /* o : QRk sub-band bit-allocation vector */
+ Word16 p2a_bands_fx, /* i : highfreq bands */
+ const Word32 L_core_brate, /* i : Q0 core bit rate */
+ Word16 p2a_flags_fx[], /* i/o: Q0 p2a_flags */
+ const Word16 band_width_fx[] /* i : Q0 table of band_width */
+)
+{
+ Word16 i, j, k;
+
+ Word32 L_norm_sum; /* Qbe */
+ Word32 L_Ravg_sub[GRP_SB]; /* Qbe */
+ Word32 L_temp_band_energy[BANDS_MAX]; /* Qbe */
+
+ Word16 j_fx, k_fx, Bits_grp_fx[GRP_SB];
+
+ Word32 L_temp_band_energydiff[BANDS_MAX];
+ Word16 G1_BE_DIFF_POS_fx; /* Q0 */
+ Word32 L_G1_BE_DIFF_VAL; /* Qbe Word32 */
+ Word16 final_gr_fact_pos_fx, gmax_range_fx[2], temp_fx;
+ Word16 bits_fact_fx, bits_fact1_fx; /* Q? */
+ Word16 grp_rngmax_fx[2] = { 0 };
+ Word16 index_fx[NB_SWB_SUBBANDS_HAR], y_index_fx[NB_SWB_SUBBANDS_HAR], esthf_bits_fx, grp_bit_avg_fx, harmonic_band_fx;
+ Word32 L_norm_sum_avg;
+ Word32 L_norm_diff; /* Qbe */
+ Word16 bits_allocweigh_fx; /* Q15 */
+ Word16 grp_bound_fx[5];
+ Word32 L_grp_thr[GRP_SB]; /* not require Word32 precission */
+ Word16 lf_hf_ge_r_fx; /* Q15 */
+ Word32 L_avg_enhf_en_diff; /* Qbe */
+
+ Word16 B_norm_fx;
+
+ Word32 L_temp, L_temp2;
+ Word16 exp, frac;
+
+ Word32 L_THR1, L_THR2, L_THR3;
+
+ Word16 exp_norm;
+ Word16 norm_sum_fx;
+ Word16 Qns; /* Q value for norm_sum_fx */
+ Word16 Inv_norm_sum_fx; /* 1/norm_sum */
+ Word16 QIns; /* Q value for Inv_norm_sum_fx */
+
+ Word16 exp_normn, exp_normd;
+ Word16 div_fx;
+
+ Word16 Inv_p2a_bands_fx;
+ Word16 QIpb;
+
+ Word16 exp_shift;
+
+ L_THR1 = L_shl(L_deposit_l(THR1), SWB_BWE_LR_QRk);
+ L_THR2 = L_shl(L_deposit_l(THR2), SWB_BWE_LR_QRk);
+ L_THR3 = L_shl(L_deposit_l(THR3), SWB_BWE_LR_QRk);
+
+ set16_fx(Bits_grp_fx, 0, GRP_SB);
+
+ /* Initialize subbands bits allocation vector based on harmonic bands */
+ harmonic_band_fx = add(sub(N_fx, p2a_bands_fx), 1);
+ /*printf("harmonic_band= %d %d\n", harmonic_band, harmonic_band_fx);*/
+ FOR(k = 0; k < N_fx; k++)
+ {
+ L_Rsubband[k] = (Word32)(C1_QRk);
+ move32(); /* Constant Value */
+ L_temp_band_energy[k] = L_y[k];
+ move32(); /* SWB_BWE_LR_Qbe */
+ }
+ final_gr_fact_pos_fx = 2;
+ move16();
+ bits_fact_fx = C1_Qbf;
+ move16();
+ bits_fact1_fx = C1_Qbf;
+ move16();
+
+ gmax_range_fx[0] = G1_RANGE;
+ move16();
+ gmax_range_fx[1] = G1G2_RANGE;
+ move16();
+
+ IF(EQ_32(L_core_brate, HQ_16k40))
+ {
+ gmax_range_fx[1] = add(gmax_range_fx[1], 2);
+ move16();
+ }
+
+ /* decide each group range, for grouping spectral coefficients */
+ grp_rngmax_fx[1] = 16;
+ move16();
+ grp_rngmax_fx[0] = 7;
+ move16();
+ temp_fx = 0;
+ move16();
+ FOR(i = 0; i < 2; i++)
+ {
+ j_fx = gmax_range_fx[i];
+ move16();
+ k_fx = 0;
+ move16();
+ WHILE(GE_32(L_temp_band_energy[gmax_range_fx[i] - 1], L_temp_band_energy[j_fx]) && LT_16(j_fx, grp_rngmax_fx[i]))
+ {
+ test();
+ k_fx = add(k_fx, 1);
+ j_fx = add(j_fx, 1);
+ }
+
+ temp_fx = k_fx;
+ move16();
+ IF(GT_16(temp_fx, 1))
+ {
+ FOR(temp_fx = 2; temp_fx <= k_fx; )
+ {
+ IF(LT_32(L_temp_band_energy[gmax_range_fx[i] + temp_fx - 1], L_temp_band_energy[gmax_range_fx[i] + temp_fx]))
+ {
+ BREAK;
+ }
+ ELSE IF(GE_32(L_temp_band_energy[gmax_range_fx[i] + temp_fx - 1], L_temp_band_energy[gmax_range_fx[i] + temp_fx]))
+ {
+ temp_fx = add(temp_fx, 1);;
+ IF(GT_16(temp_fx, k_fx))
+ {
+ temp_fx = sub(temp_fx, 1);
+ BREAK;
+ }
+ }
+ }
+
+ gmax_range_fx[i] = add(gmax_range_fx[i], temp_fx);
+ move16();
+ }
+ ELSE
+ {
+ gmax_range_fx[i] = add(gmax_range_fx[i], temp_fx);
+ move16();
+ }
+ }
+
+ grp_bound_fx[0] = 0;
+ move16();
+ FOR(i = 1; i < GRP_SB - 1; i++)
+ {
+ grp_bound_fx[i] = gmax_range_fx[i - 1];
+ move16();
+ }
+ grp_bound_fx[i] = harmonic_band_fx;
+ move16();
+ grp_bound_fx[i + 1] = N_fx;
+ move16();
+
+
+ FOR(i = 0; i < GRP_SB; i++)
+ {
+ L_Ravg_sub[i] = L_deposit_l(0);
+ FOR(j = grp_bound_fx[i]; j < grp_bound_fx[i + 1]; j++)
+ {
+ IF(L_temp_band_energy[j] > 0x0L)
+ {
+ L_Ravg_sub[i] = L_add(L_Ravg_sub[i], L_temp_band_energy[j]);
+ move32();
+ }
+ }
+ }
+
+ L_temp_band_energydiff[0] = L_temp_band_energy[0];
+ move32();
+ FOR(j = 1; j < harmonic_band_fx; j++)
+ {
+ L_temp_band_energydiff[j] = L_abs(L_sub(L_temp_band_energy[j], L_temp_band_energy[j - 1]));
+ move32();
+ }
+
+ G1_BE_DIFF_POS_fx = 0;
+ move16();
+ L_G1_BE_DIFF_VAL = L_deposit_l(0);
+
+ FOR(j = 1; j < harmonic_band_fx; j++)
+ {
+ IF(GT_32(L_temp_band_energydiff[j], L_G1_BE_DIFF_VAL))
+ {
+ G1_BE_DIFF_POS_fx = j;
+ move16();
+ L_G1_BE_DIFF_VAL = L_temp_band_energydiff[j];
+ }
+ }
+
+ test();
+ test();
+ IF(LT_16(G1_BE_DIFF_POS_fx, gmax_range_fx[0]) && G1_BE_DIFF_POS_fx > 0)
+ {
+ final_gr_fact_pos_fx = 0;
+ move16();
+ }
+ ELSE IF(GE_16(G1_BE_DIFF_POS_fx, gmax_range_fx[0]) && LT_16(G1_BE_DIFF_POS_fx, gmax_range_fx[1]))
+ {
+ final_gr_fact_pos_fx = 1;
+ move16();
+ }
+ ELSE
+ {
+ final_gr_fact_pos_fx = 2;
+ move16();
+ }
+
+ test();
+ IF(final_gr_fact_pos_fx == 0 || EQ_16(final_gr_fact_pos_fx, 1))
+ {
+ IF(EQ_32(L_core_brate, HQ_16k40))
+ {
+ bits_fact_fx = BITS_FACT_1p10;
+ move16(); /* 1.10f; */ /* G1 */
+ bits_fact1_fx = BITS_FACT_0p92;
+ move16(); /* 0.92f; */ /* G3 */
+ }
+ ELSE
+ {
+ bits_fact_fx = BITS_FACT_1p05;
+ move16(); /* 1.05f; */ /* G1 */
+ bits_fact1_fx = BITS_FACT_0p97;
+ move16(); /* 0.97f; */ /* G3 */
+ }
+ }
+ ELSE
+ {
+ IF(EQ_32(L_core_brate, HQ_16k40))
+ {
+ bits_fact_fx = BITS_FACT_0p97;
+ move16(); /* 0.97f; */ /* G1 */
+ bits_fact1_fx = BITS_FACT_1p00;
+ move16(); /* 1.00f; */ /* G3 */
+ }
+ ELSE
+ {
+ bits_fact_fx = BITS_FACT_0p92;
+ move16(); /* 0.92f; */ /* G1 */
+ bits_fact1_fx = BITS_FACT_1p00;
+ move16(); /* 1.00f; */ /* G3 */
+ }
+ }
+
+ j = sub(N_fx, harmonic_band_fx);
+ FOR(i = 0; i < j; i++)
+ {
+ y_index_fx[i] = extract_h(L_shl(L_temp_band_energy[harmonic_band_fx + i], sub(16, SWB_BWE_LR_Qbe)));
+ index_fx[i] = add(harmonic_band_fx, i);
+ move16();
+ }
+
+ reordvct_fx(y_index_fx, sub(N_fx, harmonic_band_fx), index_fx);
+
+ /* Log2 */
+ L_temp = L_deposit_l(band_width_fx[index_fx[0]]);
+ exp = norm_l(L_temp);
+ frac = Log2_norm_lc(L_shl(L_temp, exp));
+ exp = sub(30, exp);
+ L_temp = L_Comp(exp, frac);
+ /* ceil */
+ if (L_and(0x0000ffff, L_temp) > 0)
+ {
+ L_temp = L_add(L_temp, 0x00010000);
+ }
+ esthf_bits_fx = extract_h(L_temp);
+
+ L_grp_thr[0] = L_THR1;
+ move32();
+ L_grp_thr[1] = L_THR2;
+ move32();
+ L_grp_thr[2] = L_THR3;
+ move32();
+ L_grp_thr[3] = L_shl(L_deposit_l(esthf_bits_fx), SWB_BWE_LR_QRk);
+ move16();
+
+ L_norm_sum = L_deposit_l(1);
+ FOR(i = 0; i < 3; i++)
+ {
+ L_norm_sum = L_add(L_norm_sum, L_Ravg_sub[i]);
+ }
+
+ /*reserve bits for HF coding */
+ L_temp = L_add(L_norm_sum, L_Ravg_sub[GRP_SB - 1]);
+ exp_normn = norm_l(L_temp);
+ exp_normn = sub(exp_normn, 1);
+ exp_normd = norm_s(N_fx);
+
+ div_fx = div_l(L_shl(L_temp, exp_normn), shl(N_fx, exp_normd)); /* (Qbe+exp_normn)-(0+exp_normd)-1) */
+ L_norm_sum_avg = L_shr(L_deposit_h(div_fx), add(sub(exp_normn, exp_normd), 15)); /* -> Qbe */
+
+ exp_norm = norm_l(L_norm_sum);
+ norm_sum_fx = extract_h(L_shl(L_norm_sum, exp_norm)); /* SWB_BWE_LR_Qbe+exp_norm-16 */
+ Qns = sub(add(SWB_BWE_LR_Qbe, exp_norm), 16);
+
+ Inv_norm_sum_fx = div_s(0x4000 /* Q15 */, norm_sum_fx);
+ QIns = sub(31, exp_norm); /* 14 - (14+exp_norm-16) + 15 */
+
+ grp_bit_avg_fx = div_s_ss(B_fx, GRP_SB); /* Q0 */
+
+ exp_normd = norm_s(p2a_bands_fx);
+ Inv_p2a_bands_fx = div_s(0x3fff, shl(p2a_bands_fx, exp_normd)); /* 14-exp_normd+15 */
+ QIpb = sub(29, exp_normd);
+
+ L_temp = L_shl(Mult_32_16(L_Ravg_sub[GRP_SB - 1], Inv_p2a_bands_fx), sub(SWB_BWE_LR_Qbe, sub(QIpb, 1)));
+ L_norm_diff = L_sub(L_temp, L_norm_sum_avg); /* Qbe */
+
+ L_temp = Mult_32_16(L_Ravg_sub[GRP_SB - 1], sub(GRP_SB, 1)); /* Qbe+0+1 */
+ L_temp = Mult_32_16(L_temp, Inv_norm_sum_fx); /* Qbe+1+QIpb+1 */
+ lf_hf_ge_r_fx = round_fx(L_shl(L_temp, sub(15 + 16, sub(add(SWB_BWE_LR_Qbe, QIns), 30))));
+
+ exp_normn = norm_s(norm_sum_fx);
+ exp_normn = sub(exp_normn, 1);
+ exp_normd = norm_s(harmonic_band_fx);
+
+ div_fx = div_s(shl(norm_sum_fx, exp_normn), shl(harmonic_band_fx, exp_normd));
+ L_avg_enhf_en_diff = L_sub(L_temp_band_energy[index_fx[0]], L_shl(L_deposit_h(div_fx), sub(sub(SWB_BWE_LR_Qbe, (add(Qns, sub(exp_normn, exp_normd)))), 31))); /* Qbe - (Qns+exp_normn-(exp_normd)+15) -16 */
+
+ test();
+ IF(GT_16(lf_hf_ge_r_fx, 26214) && GT_32(L_avg_enhf_en_diff, (Word32)(8 << SWB_BWE_LR_Qbe))) /* 0.8=26214.4(Q15) 8.0f=131072(Qbe) */
+ {
+ bits_allocweigh_fx = 6554;
+ move16(); /* 0.2 6553.6(Q15) */
+ if (L_norm_diff < 0x0L)
+ {
+ bits_allocweigh_fx = 13107;
+ move16(); /* 0.4 13107.2(Q15) */
+ }
+
+ /*allocate bits*/
+ /*Bits_grp[GRP_SB-1] = (short)min((grp_bit_avg/p2a_bands + bits_allocweigh*norm_diff),10);*/
+ L_temp = L_mult(grp_bit_avg_fx, Inv_p2a_bands_fx); /* Q0+QIpb+1 */
+ L_temp2 = Mult_32_16(L_norm_diff, bits_allocweigh_fx); /* Qbe+Q15-15 */
+
+ L_temp = L_shr(L_temp, add(QIpb, 1));
+ L_temp = L_add(L_shl(L_temp, SWB_BWE_LR_Qbe), L_temp2);
+
+ Bits_grp_fx[GRP_SB - 1] = extract_h(L_shl(L_temp, sub(16, SWB_BWE_LR_Qbe)));
+ Bits_grp_fx[GRP_SB - 1] = s_min(Bits_grp_fx[GRP_SB - 1], 10);
+ move16();
+
+ if (LT_16(Bits_grp_fx[GRP_SB - 1], esthf_bits_fx))
+ {
+ Bits_grp_fx[GRP_SB - 1] = 0;
+ move16();
+ }
+ B_fx = sub(B_fx, Bits_grp_fx[GRP_SB - 1]);
+ }
+
+ exp_shift = sub(add(SWB_BWE_LR_Qbe, QIns), 47); /* (SWB_BWE_LR_Qbe+14+1+QIns-15-16) */
+ exp_norm = norm_s(B_fx);
+ B_norm_fx = shl(B_fx, exp_norm);
+ exp_shift = add(exp_shift, exp_norm);
+
+ IF(EQ_16(final_gr_fact_pos_fx, 1))
+ {
+ L_temp = Mult_32_16(L_Ravg_sub[1], extract_h(L_mult(bits_fact_fx, B_norm_fx)));
+ L_temp = Mult_32_16(L_temp, Inv_norm_sum_fx);
+ Bits_grp_fx[1] = extract_h(L_shr(L_temp, exp_shift));
+
+ L_temp = Mult_32_16(L_Ravg_sub[2], extract_h(L_mult(bits_fact1_fx, B_norm_fx)));
+ L_temp = Mult_32_16(L_temp, Inv_norm_sum_fx);
+ Bits_grp_fx[2] = extract_h(L_shr(L_temp, exp_shift));
+
+ Bits_grp_fx[0] = sub(sub(B_fx, Bits_grp_fx[1]), Bits_grp_fx[2]);
+ move16();
+ }
+ ELSE
+ {
+ L_temp = Mult_32_16(L_Ravg_sub[0], extract_h(L_mult(bits_fact_fx, B_norm_fx)));
+ L_temp = Mult_32_16(L_temp, Inv_norm_sum_fx);
+ Bits_grp_fx[0] = extract_h(L_shr(L_temp, exp_shift));
+
+ L_temp = Mult_32_16(L_Ravg_sub[2], extract_h(L_mult(bits_fact1_fx, B_norm_fx)));
+ L_temp = Mult_32_16(L_temp, Inv_norm_sum_fx);
+ Bits_grp_fx[2] = extract_h(L_shr(L_temp, exp_shift));
+
+ Bits_grp_fx[1] = sub(sub(B_fx, Bits_grp_fx[0]), Bits_grp_fx[2]);
+ move16();
+ }
+
+ IF(LT_16(Bits_grp_fx[2], THR2))
+ {
+ Bits_grp_fx[1] = add(Bits_grp_fx[1], Bits_grp_fx[2]);
+ move16();
+ Bits_grp_fx[2] = 0;
+ move16();
+ }
+
+ FOR(i = 0; i < GRP_SB; i++)
+ {
+ IF(Bits_grp_fx[i] > 0)
+ {
+ Bits2indvsb_fx(L_temp_band_energy, grp_bound_fx[i], grp_bound_fx[i + 1], Bits_grp_fx[i], L_grp_thr[i], L_Rsubband, p2a_flags_fx);
+ }
+ ELSE
+ {
+ set32_fx(L_Rsubband + grp_bound_fx[i], 0x0L, sub(grp_bound_fx[i + 1], grp_bound_fx[i]));
+ IF(EQ_16(i, GRP_SB - 1))
+ {
+ set16_fx(p2a_flags_fx + grp_bound_fx[i], 0, sub(grp_bound_fx[i + 1], grp_bound_fx[i]));
+ }
+ }
+ }
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * hq2_bit_alloc()
+ *
+ * HQ2 bit-allocation
+ *--------------------------------------------------------------------------*/
+
+Word32 hq2_bit_alloc_fx(
+ const Word32 L_band_energy[], /* i : band energy of each subband */
+ const Word16 bands, /* i : total number of subbands in a frame */
+ Word32 L_Rk[], /* i/o: Bit allocation/Adjusted bit alloc. */
+ Word16 *bit_budget_fx, /* i/o: bit bugdet */
+ Word16 *p2a_flags, /* i : HF tonal indicator */
+ const Word16 weight_fx, /* i : weight */
+ const Word16 band_width[], /* i : Sub band bandwidth */
+ const Word16 num_bits, /* i : available bits */
+ const Word16 hqswb_clas, /* i : HQ2 class information */
+ const Word16 bwidth, /* i : input bandwidth */
+ const Word16 is_transient /* i : indicator HQ_TRANSIENT or not */
+)
+{
+ Word16 j, k;
+ Word16 tmp;
+ Word16 bit_budget_norm_fx;
+
+ Word32 L_Rcalc, L_Ravg, L_Rcalc1;
+
+ Word16 exp_normn, exp_normd;
+
+ Word16 Rcnt_fx;
+
+ Word16 div_fx;
+ Word16 Qdiv;
+
+ Word32 L_tmp;
+ Word16 tmp_fx;
+
+ Word32 L_maxxy;
+ Word16 maxdex_fx;
+ Word32 L_dummy;
+
+ Word16 bit_budget_temp_fx;
+
+ Word16 negflag;
+
+ Word32 L_THR1, L_THR2, L_THR3;
+
+ L_THR1 = L_shl(L_deposit_l(THR1), SWB_BWE_LR_QRk);
+ L_THR2 = L_shl(L_deposit_l(THR2), SWB_BWE_LR_QRk);
+ L_THR3 = L_shl(L_deposit_l(THR3), SWB_BWE_LR_QRk);
+
+ /* Init Rk to non-zero values for bands to be allocated bits */
+ IF(LE_16(num_bits, HQ_16k40_BIT))
+ {
+ set32_fx(L_Rk, (Word32)(C1_QRk), bands); /* 1< 0)
+ {
+ L_Ravg = L_add(L_Ravg, L_shl(L_band_energy[k], sub(SWB_BWE_LR_QRk, SWB_BWE_LR_Qbe))); /* SWB_BWE_LR_QRk-SWB_BWE_LR_Qbe */
+ Rcnt_fx = add(Rcnt_fx, 1);
+ }
+ }
+ /* Ravg Qband_energy */
+
+ /*L_Ravg /= Rcnt; */
+ exp_normd = norm_l(L_Ravg);
+ exp_normd = sub(exp_normd, 1);
+ exp_normn = norm_s(Rcnt_fx);
+
+ tmp = shl(Rcnt_fx, exp_normn);
+ tmp = s_max(tmp, 1);
+ IF(L_Ravg > 0)
+ {
+ div_fx = div_l(L_shl(L_Ravg, exp_normd), tmp); /* Qdiv = 14+exp_normd-(exp_normn)-1 */
+ }
+ ELSE
+ {
+ div_fx = div_l(L_shl(L_abs(L_Ravg), exp_normd), tmp); /* Qdiv = 14+exp_normd-(exp_normn)-1 */
+ div_fx = negate(div_fx);
+ }
+
+ Qdiv = sub(sub(add(SWB_BWE_LR_QRk, exp_normd), exp_normn), 1);
+
+ L_Ravg = L_shr(L_deposit_l(div_fx), sub(Qdiv, SWB_BWE_LR_QRk));
+
+ exp_normd = norm_s(*bit_budget_fx);
+ exp_normd = sub(exp_normd, 1);
+ bit_budget_norm_fx = shl(*bit_budget_fx, exp_normd);
+ div_fx = 0;
+ move16();
+
+ test();
+ IF(bit_budget_norm_fx > 0 && LT_16(bit_budget_norm_fx, tmp))
+ {
+ div_fx = div_s(bit_budget_norm_fx, tmp);
+ }
+ Qdiv = add(sub(exp_normd, exp_normn), 15);
+ FOR(k = 0; k < bands; k++)
+ {
+ IF(L_Rk[k] > 0)
+ {
+ /*Rk[k] = ((float) *bit_budget / Rcnt + weight * (band_energy[k] - Ravg)); */
+
+ L_tmp = Mult_32_16(L_sub(L_shl(L_band_energy[k], sub(SWB_BWE_LR_QRk, SWB_BWE_LR_Qbe)), L_Ravg), weight_fx); /* SWB_BWE_LR_QRk + Q13 - 15 */
+ L_tmp = L_shl(L_tmp, 2); /* -> SWB_BWE_LR_QRk */
+
+ L_Rk[k] = L_add(L_shr(L_deposit_l(div_fx), sub(Qdiv, SWB_BWE_LR_QRk)), L_tmp);
+ move32();
+ }
+ }
+
+ negflag = 0;
+ move16();
+ L_Rcalc = L_deposit_l(0);
+ FOR(k = 0; k < bands; k++)
+ {
+ IF(LT_32(L_Rk[k], MIN_BITS_FIX))
+ {
+ L_Rk[k] = L_deposit_l(0);
+ negflag = 1;
+ move16();
+ }
+ L_Rcalc = L_add(L_Rcalc, L_Rk[k]); /*SWB_BWE_LR_QRk */
+ }
+
+ /* prune noiselike bands with low allocation */
+ test();
+ IF(LE_16(num_bits, HQ_16k40_BIT) && negflag == 0)
+ {
+ L_maxxy = L_deposit_l(0);
+ maxdex_fx = -1;
+ move16();
+ L_Rcalc = L_deposit_l(0);
+
+ /* find worst under-allocation */
+ FOR(k = sub(bands, 1); k >= 0; k--)
+ {
+ tmp_fx = s_min(band_width[k], s_max(12, shr(band_width[k], 2)));
+ L_dummy = L_sub(L_shl(L_deposit_l(tmp_fx), SWB_BWE_LR_QRk), L_Rk[k]); /*SWB_BWE_LR_QRk */
+ test();
+ test();
+ IF(p2a_flags[k] == 0 && GT_32(L_dummy, L_maxxy) && L_Rk[k] > 0)
+ {
+ maxdex_fx = k;
+ move16();
+ L_maxxy = L_dummy; /*SWB_BWE_LR_QRk */
+ move32();
+ }
+ }
+
+ /* prune worst allocation and recalculate total allocation */
+ if (GT_16(maxdex_fx, -1))
+ {
+ L_Rk[maxdex_fx] = L_deposit_l(0);
+ }
+ FOR(k = 0; k < bands; k++)
+ {
+ L_Rcalc = L_add(L_Rcalc, L_Rk[k]); /*SWB_BWE_LR_QRk */
+ }
+ }
+ test();
+ test();
+ IF(EQ_32(L_Rcalc, L_Rcalc1) && EQ_16(bwidth, SWB))
+ {
+ /* Reallocate bits to individual subbands for HQ_NORMAL mode */
+ /* if bits allocated to subbands areless than predefined threshold */
+ test();
+ IF(EQ_16(hqswb_clas, HQ_NORMAL) && LT_16(num_bits, HQ_16k40_BIT))
+ {
+ L_dummy = L_deposit_l(0);
+ FOR(k = 0; k < bands; k++)
+ {
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF(LT_16(k, 11) && LT_32(L_Rk[k], L_THR1))
+ {
+ L_Rk[k] = L_deposit_l(0);
+ }
+ ELSE IF(GE_16(k, 11) && LT_16(k, 16) && LT_32(L_Rk[k], L_THR2))
+ {
+ L_Rk[k] = L_deposit_l(0);
+ }
+ ELSE if (GE_16(k, 16) && LT_16(k, bands) && LT_32(L_Rk[k], L_THR3))
+ {
+ L_Rk[k] = L_deposit_l(0);
+ }
+
+ L_dummy = L_add(L_dummy, L_Rk[k]);
+ }
+
+ IF(EQ_32(L_dummy, L_Rcalc))
+ {
+ test();
+ IF(EQ_16(hqswb_clas, HQ_NORMAL) && LT_16(num_bits, HQ_16k40_BIT))
+ {
+ bit_budget_temp_fx = *bit_budget_fx;
+ move16();
+ FOR(k = 0; k < NB_SWB_SUBBANDS; k++)
+ {
+ test();
+ IF(p2a_flags[bands - NB_SWB_SUBBANDS + k] == 1 && L_Rk[bands - NB_SWB_SUBBANDS + k] == 0)
+ {
+ p2a_flags[bands - NB_SWB_SUBBANDS + k] = 0;
+ move16();
+ bit_budget_temp_fx = sub(bit_budget_temp_fx, bits_lagIndices_modeNormal[k]);
+ }
+ }
+
+ IF(LT_16(bit_budget_temp_fx, *bit_budget_fx))
+ {
+ *bit_budget_fx = bit_budget_temp_fx;
+ move16();
+ /* a negative *bit_budget_fx may occur here due to Bit Errors */
+ /* handled outside this function to properly set flag: st_fx->BER_detect */
+ }
+ ELSE IF(EQ_16(bit_budget_temp_fx, *bit_budget_fx))
+ {
+ BREAK;
+ }
+ }
+ ELSE
+ {
+ BREAK;
+ }
+ }
+ }
+ ELSE
+ {
+ BREAK;
+ }
+ }
+ ELSE IF(EQ_32(L_Rcalc, L_Rcalc1) && NE_16(bwidth, SWB))
+ {
+ BREAK;
+ }
+
+ L_Rcalc1 = L_Rcalc;
+ move32();
+
+ }
+
+ return L_Rcalc;
+}
+
diff --git a/lib_com/hq2_core_com.c b/lib_com/hq2_core_com.c
index bd3119b3796ce2161ef59f1821c93e8db69bfc79..6b5bdd04aebe77cec614a3977c132f60e385059b 100644
--- a/lib_com/hq2_core_com.c
+++ b/lib_com/hq2_core_com.c
@@ -304,7 +304,7 @@ void reverse_transient_frame_energies(
}
#define WMC_TOOL_SKIP
-void bit_allocation_second_fx(
+void bit_allocation_second_fx2(
Word32 *Rk,
Word32 *Rk_sort,
Word16 BANDS,
diff --git a/lib_com/hq2_core_com_fx.c b/lib_com/hq2_core_com_fx.c
new file mode 100644
index 0000000000000000000000000000000000000000..05eebc81a38bff7c8fe3e55b2e66a606c80b8a07
--- /dev/null
+++ b/lib_com/hq2_core_com_fx.c
@@ -0,0 +1,814 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 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.
+
+*******************************************************************************************************/
+
+
+#include
+#include "options.h"
+#include "cnst.h" /* Audio core constants */
+#include "rom_com.h" /* Static table prototypes */
+#include "prot_fx2.h"
+
+
+
+ /*--------------------------------------------------------------------------*
+ * mdct_spectrum_denorm()
+ *
+ *
+ *--------------------------------------------------------------------------*/
+
+void mdct_spectrum_denorm_fx(
+ const Word16 inp_vector[], /* i : Q0 : */
+ Word32 L_y2[], /* i/o : Qs : decoded spectrum */
+ const Word16 band_start[], /* i : Q0 : table of start freq for every subband */
+ const Word16 band_end[], /* i : Q0 : table of end freq for every subband */
+ const Word16 band_width[], /* i : Q0 : table of bandwidth for every subband */
+ const Word32 L_band_energy[], /* i : Qbe : band energy */
+ const Word16 npulses[], /* i : Q0 : number of coded spectrum */
+ const Word16 bands, /* i : Q0 : number of subbands */
+ const Word16 ld_slope_fx, /* i : Q15 : */
+ const Word16 pd_thresh_fx /* i : Q15 : */
+)
+{
+ Word16 i, k;
+ Word32 L_Eyy;
+ Word32 L_tmp, L_temp;
+ Word16 temp_fx, temp_lo_fx, temp_hi_fx;
+ Word32 L_inp_tmp[L_FRAME48k];
+ Word16 exp_norm;
+ Word16 exp_safe;
+ Word16 exp_normn, exp_normd;
+
+ Word16 pd_fx;
+ Word16 Qpd;
+
+ Word16 div_pd_fx;
+ Word16 Qdivpd;
+ Word32 L_div_pd;
+
+ Word16 frac, exp;
+
+ Word16 gain_tweak_fx;
+ Word16 Qtweak;
+
+ Word16 exp_shift;
+
+ Word16 QEyy;
+ Word16 pow_fx;
+ Word16 Qpow;
+ Word16 Qdiv;
+ Word16 Qgamma;
+ Word16 gamma_fx;
+
+ Word16 cond_fx;
+
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+
+ exp_safe = 4; /* safe bit for overflow */
+
+ FOR(k = 0; k < bands; k++)
+ {
+ L_tmp = L_deposit_l(0);
+ FOR(i = band_start[k]; i <= band_end[k]; i++)
+ {
+ L_inp_tmp[i] = L_mult(inp_vector[i], inp_vector[i]);
+ move32(); /* Q0+Q0+1 */
+ L_tmp = L_or(L_tmp, L_inp_tmp[i]);
+ }
+ exp_norm = norm_l(L_tmp);
+ exp_norm = sub(exp_norm, exp_safe);
+
+ L_Eyy = L_deposit_l(0);
+ FOR(i = band_start[k]; i <= band_end[k]; i++)
+ {
+ /*Eyy += (float) inp_vector[i] * inp_vector[i]; */
+ L_Eyy = L_add(L_Eyy, L_shl(L_inp_tmp[i], exp_norm)); /* Q1+exp_norm */
+ }
+ QEyy = add(1, exp_norm);
+
+ IF(L_Eyy > 0x0L)
+ {
+ /* Set gamma to be pulse gain which results in perfect quantized subband energy */
+ /*gamma = (float) sqrt (pow (2.0f, band_energy[k]) / Eyy); */
+
+ /* Pow part (pow(2.0f, band_energy) ) */
+ L_temp = L_shr(L_band_energy[k], sub(SWB_BWE_LR_Qbe, 16));
+ temp_lo_fx = L_Extract_lc(L_temp, &temp_hi_fx);
+ Qpow = sub(14, temp_hi_fx);
+ pow_fx = extract_l(Pow2(14, temp_lo_fx)); /* Qpow */
+
+ /* Div part ( pow (2.0f, band_energy[i])/Eyy ) */
+ exp_normn = norm_s(pow_fx);
+ exp_normn = sub(exp_normn, 1);
+ exp_normd = norm_l(L_Eyy);
+ temp_fx = div_s(shl(pow_fx, exp_normn), extract_h(L_shl(L_Eyy, exp_normd)));
+ Qdiv = add(sub(add(Qpow, exp_normn), add(QEyy, exp_normd)), 31);
+
+ exp_norm = norm_s(temp_fx);
+ temp_fx = shl(temp_fx, exp_norm);
+ Qdiv = add(Qdiv, exp_norm);
+
+ /* Sqrt part sqrt(pow (2.0f, band_energy[i])/Eyy) */
+ Qgamma = add(Qdiv, 16);
+ IF(s_and(Qdiv, 1) == 0) /* Qdiv % 2 == 0 */
+ {
+ L_temp = Sqrt_l(L_shr(L_deposit_h(temp_fx), 1), &exp_norm);
+ L_temp = L_shr(L_temp, exp_norm);
+ Qgamma = sub(shr(Qgamma, 1), 1);
+ gamma_fx = round_fx(L_temp);
+ }
+ ELSE
+ {
+ L_temp = Sqrt_l(L_deposit_h(temp_fx), &exp_norm);
+ L_temp = L_shr(L_temp, exp_norm);
+ Qgamma = shr(Qgamma, 1);
+ gamma_fx = round_fx(L_temp);
+ }
+
+ /* Adjust gamma based on pulse density (0 bit MSE gain estimator) */
+ /*pd = (float) npulses[k] / band_width[k]; */
+ exp_normn = norm_s(npulses[k]);
+ exp_normn = sub(exp_normn, 1);
+ exp_normd = norm_s(band_width[k]);
+ pd_fx = div_s(shl(npulses[k], exp_normn), shl(band_width[k], exp_normd));
+ Qpd = add(sub(exp_normn, exp_normd), 15);
+
+#ifdef BASOP_NOGLOB
+ cond_fx = sub(shl_o(pd_fx, sub(15, Qpd), &Overflow), pd_thresh_fx/*Q15*/);
+#else /* BASOP_NOGLOB */
+ cond_fx = sub(shl(pd_fx, sub(15, Qpd)), pd_thresh_fx/*Q15*/);
+#endif
+ Overflow = 0;
+ move16(); /* allow overflow happen. */
+ IF(cond_fx < 0)
+ {
+ /*gain_tweak = (float) pow (2.0f, (ld_slope * log2_f (pd / pd_thresh))); */
+ /* Div part */
+ exp_normn = norm_s(pd_fx);
+ exp_normn = sub(exp_normn, 1);
+ exp_normd = norm_s(pd_thresh_fx);
+ div_pd_fx = div_s(shl(pd_fx, exp_normn), shl(pd_thresh_fx, exp_normd)); /* Qpd+exp_normn - (15 + exp_normd) + 15 */
+ Qdivpd = add(sub(add(Qpd, exp_normn), add(15, exp_normd)), 15);
+
+ /* Log2 part */
+ exp_norm = norm_s(div_pd_fx);
+ L_div_pd = L_deposit_h(shl(div_pd_fx, exp_norm));
+ Qdivpd = add(add(Qdivpd, exp_norm), 16);
+
+ frac = Log2_norm_lc(L_div_pd);
+ exp = sub(30, Qdivpd);
+ L_tmp = L_Comp(exp, frac); /* Q16 */
+
+ /* Mult part */
+ L_tmp = Mpy_32_16_1(L_tmp, ld_slope_fx);
+
+ /* Pow part */
+ temp_lo_fx = L_Extract_lc(L_tmp, &temp_hi_fx);
+ Qtweak = sub(14, temp_hi_fx);
+ gain_tweak_fx = extract_l(Pow2(14, temp_lo_fx));
+
+ /*gamma *= gain_tweak; */
+ L_tmp = L_mult(gamma_fx, gain_tweak_fx); /* Qgamma+Qtweak+1 */
+ exp_norm = norm_l(L_tmp);
+#ifdef BASOP_NOGLOB
+ gamma_fx = round_fx_o(L_shl_o(L_tmp, exp_norm, &Overflow), &Overflow);
+#else
+ gamma_fx = round_fx(L_shl(L_tmp, exp_norm));
+#endif
+ Qgamma = sub(add(add(Qgamma, Qtweak), exp_norm), 15);/*Qgamma+Qtweak+1+exp_norm-16; */
+ }
+
+ exp_shift = sub(SWB_BWE_LR_Qs - 1, Qgamma);
+ FOR(i = band_start[k]; i <= band_end[k]; i++)
+ {
+ /*y2[i] = gamma * inp_vector[i]; */
+ L_tmp = L_mult(gamma_fx, (Word16)inp_vector[i]); /* Qgamma+0+1=Qgamma+1 */
+ L_y2[i] = L_shl(L_tmp, exp_shift);
+ move32();
+ }
+ }
+ }
+
+ return;
+}
+/*==========================================================================*/
+/* FUNCTION : void hq2_core_configure_fx() */
+/*--------------------------------------------------------------------------*/
+/* PURPOSE : */
+/*--------------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/*--------------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* Word16 *qint o: Q13 */
+/* Word16 *eref o: Q10 */
+/* Word16 *bit_alloc_weight o: Q13 */
+/* Word16 *p2a_th o: Q11 */
+/* Word16 *pd_thresh o: Q15 */
+/* Word16 *ld_slope o: Q15 */
+/* Word16 *ni_coef o: Q14 */
+/*--------------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/*--------------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : */
+/* _ None */
+/*--------------------------------------------------------------------------*/
+/* CALLED FROM : */
+/*==========================================================================*/
+
+void hq2_core_configure_fx(
+ const Word16 frame_length,
+ const Word16 num_bits,
+ const Word16 is_transient,
+ Word16 *bands,
+ Word16 *length,
+ Word16 band_width[],
+ Word16 band_start[],
+ Word16 band_end[],
+ Word32 *L_qint,
+ Word16 *eref,
+ Word16 *bit_alloc_weight,
+ Word16 *gqlevs,
+ Word16 *Ngq,
+ Word16 *p2a_bands,
+ Word16 *p2a_th,
+ Word16 *pd_thresh,
+ Word16 *ld_slope,
+ Word16 *ni_coef,
+ Word32 L_bwe_br
+)
+{
+ const Xcore_Config *xcore_config_fx;
+
+ Word16 i, k;
+ Word16 bands_sh;
+
+ xcore_config_fx = &xcore_config_32kHz_013200bps_long; /* default set for VC Warning */
+
+ IF(EQ_16(frame_length, L_FRAME8k))
+ {
+ IF(is_transient)
+ {
+ IF(LE_16(num_bits, ACELP_7k20 / FRAMES_PER_SEC))
+ {
+ xcore_config_fx = &xcore_config_8kHz_007200bps_short;
+ }
+ ELSE IF(LE_16(num_bits, ACELP_8k00 / FRAMES_PER_SEC))
+ {
+ xcore_config_fx = &xcore_config_8kHz_008000bps_short;
+ }
+ ELSE IF(LE_16(num_bits, ACELP_13k20 / FRAMES_PER_SEC))
+ {
+ xcore_config_fx = &xcore_config_8kHz_013200bps_short;
+ }
+ ELSE
+ {
+ xcore_config_fx = &xcore_config_8kHz_016400bps_short;
+ }
+ }
+ ELSE
+ {
+ IF(LE_16(num_bits, ACELP_7k20 / FRAMES_PER_SEC))
+ {
+ xcore_config_fx = &xcore_config_8kHz_007200bps_long;
+ }
+ ELSE IF(LE_16(num_bits, ACELP_8k00 / FRAMES_PER_SEC))
+ {
+ xcore_config_fx = &xcore_config_8kHz_008000bps_long;
+ }
+ ELSE IF(LE_16(num_bits, ACELP_13k20 / FRAMES_PER_SEC))
+ {
+ xcore_config_fx = &xcore_config_8kHz_013200bps_long;
+ }
+ ELSE
+ {
+ xcore_config_fx = &xcore_config_8kHz_016400bps_long;
+ }
+ }
+ }
+ ELSE IF(EQ_16(frame_length, L_FRAME16k))
+ {
+ IF(is_transient)
+ {
+ IF(LE_16(num_bits, ACELP_13k20 / FRAMES_PER_SEC))
+ {
+ xcore_config_fx = &xcore_config_16kHz_013200bps_short;
+ move16();
+ }
+ ELSE if (LE_16(num_bits, ACELP_16k40 / FRAMES_PER_SEC))
+ {
+ xcore_config_fx = &xcore_config_16kHz_016400bps_short;
+ move16();
+ }
+ }
+ ELSE
+ {
+ IF(LE_16(num_bits, ACELP_13k20 / FRAMES_PER_SEC))
+ {
+ xcore_config_fx = &xcore_config_16kHz_013200bps_long;
+ move16();
+ }
+ ELSE if (LE_16(num_bits, ACELP_16k40 / FRAMES_PER_SEC))
+ {
+ xcore_config_fx = &xcore_config_16kHz_016400bps_long;
+ move16();
+ }
+ }
+ }
+ ELSE /* (frame_length == SWB) */
+ {
+ IF(is_transient)
+ {
+ IF(LE_32(L_bwe_br, ACELP_13k20))
+ {
+ xcore_config_fx = &xcore_config_32kHz_013200bps_short;
+ move16();
+ }
+ ELSE if (LE_32(L_bwe_br, ACELP_16k40))
+ {
+ xcore_config_fx = &xcore_config_32kHz_016400bps_short;
+ move16();
+ }
+ }
+ ELSE
+ {
+ IF(LE_32(L_bwe_br, ACELP_13k20))
+ {
+ xcore_config_fx = &xcore_config_32kHz_013200bps_long;
+ move16();
+ }
+ ELSE if (LE_32(L_bwe_br, ACELP_16k40))
+ {
+ xcore_config_fx = &xcore_config_32kHz_016400bps_long;
+ move16();
+ }
+ }
+ }
+
+ *bands = xcore_config_fx->bands;
+ move16();
+ *length = xcore_config_fx->bw;
+ move16();
+ *L_qint = xcore_config_fx->L_qint;
+ move32();
+
+ *eref = xcore_config_fx->eref;
+ move16();
+ *bit_alloc_weight = xcore_config_fx->bit_alloc_weight;
+ move16();
+ *gqlevs = xcore_config_fx->gqlevs;
+ move16();
+ *Ngq = xcore_config_fx->Ngq;
+ move16();
+
+ *p2a_bands = xcore_config_fx->p2a_bands;
+ move16();
+ *p2a_th = xcore_config_fx->p2a_th;
+ move16();
+
+ *pd_thresh = xcore_config_fx->pd_thresh;
+ move16();
+ *ld_slope = xcore_config_fx->ld_slope;
+ move16();
+ *ni_coef = xcore_config_fx->ni_coef;
+ move16();
+
+ /*mvs2s_fx (xcore_config_fx->band_width, band_width, *bands); */
+ Copy(xcore_config_fx->band_width, band_width, *bands);
+
+ /* Expand band_width[] table for short windows */
+ IF(is_transient)
+ {
+ bands_sh = *bands;
+ move16();
+ *bands = shl(bands_sh, 2);
+ *length = shl(*length, 2);
+
+ FOR(i = 1; i <= 3; i++)
+ {
+ FOR(k = 0; k < bands_sh; k++)
+ {
+ band_width[i * bands_sh + k] = band_width[k];
+ move16();
+ }
+ }
+ }
+
+ /* Formulate band_start and band_end tables from band_width table */
+ band_start[0] = 0;
+ move16();
+ band_end[0] = sub(band_width[0], 1);
+ move16();
+ FOR(k = 1; k < *bands; k++)
+ {
+ band_start[k] = add(band_start[k - 1], band_width[k - 1]);
+ move16();
+ band_end[k] = sub(add(band_start[k], band_width[k]), 1);
+ move16();
+ }
+
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * reverse_transient_frame_energies()
+ *
+ *
+ *--------------------------------------------------------------------------*/
+
+void reverse_transient_frame_energies_fx(
+ Word32 L_band_energy[], /* o : Q14 : band energies */
+ const Word16 bands /* i : Q0 : number of bands */
+)
+{
+ Word16 k, k1, k2;
+ Word32 L_be;
+ Word16 bands_2, bands_4, bands_8;
+ Word32 *p_be1, *p_be2;
+
+ bands_2 = shr(bands, 1);
+ bands_4 = shr(bands, 2);
+ bands_8 = shr(bands, 3);
+
+ k1 = bands_4;
+ k2 = sub(bands_2, 1);
+ p_be1 = &L_band_energy[k1];
+ p_be2 = &L_band_energy[k2];
+ FOR(k = 0; k < bands_8; k++)
+ {
+ L_be = *p_be1;
+ move32();
+ *p_be1 = *p_be2;
+ move32();
+ *p_be2 = L_be;
+ move32();
+ p_be1++;
+ p_be2--;
+ }
+
+ k1 = sub(bands, bands_4); /* 3*bands/4 */
+ k2 = sub(bands, 1);
+ p_be1 = &L_band_energy[k1];
+ p_be2 = &L_band_energy[k2];
+ FOR(k = 0; k < bands_8; k++)
+ {
+ L_be = *p_be1;
+ move32();
+ *p_be1 = *p_be2;
+ move32();
+ *p_be2 = L_be;
+ move32();
+ p_be1++;
+ p_be2--;
+ }
+
+ return;
+}
+
+
+/*--------------------------------------------------------------------------*
+ * spt_shorten_domain_pre()
+ *
+ * Compute shorten subband if previous frame has spectral peak.
+ *--------------------------------------------------------------------------*/
+
+void spt_shorten_domain_pre_fx(
+ const Word16 band_start[], /* i: Starting position of sub band */
+ const Word16 band_end[], /* i: End position of sub band */
+ const Word16 prev_SWB_peak_pos[], /* i: Spectral peak */
+ const Word16 BANDS, /* i: total number of bands */
+ const Word32 L_bwe_br, /* i: bitrate information */
+ Word16 new_band_start[], /* o: Starting position of new shorten sub band */
+ Word16 new_band_end[], /* o: End position of new shorten sub band */
+ Word16 new_band_width[] /* o: new sub band bandwidth */
+)
+{
+ Word16 j;
+ Word16 k;
+ Word16 kpos;
+
+ Word16 new_band_width_half;
+ const Word16 *p_bw_SPT_tbl; /* pointer of bw_SPT_tbl */
+
+ p_bw_SPT_tbl = bw_SPT_tbl[0];
+ if (EQ_32(L_bwe_br, HQ_16k40))
+ {
+ p_bw_SPT_tbl = bw_SPT_tbl[1];
+ }
+
+ kpos = 0;
+ j = 0;
+ move16();
+ FOR(k = sub(BANDS, SPT_SHORTEN_SBNUM); k < BANDS; k++)
+ {
+ IF(prev_SWB_peak_pos[kpos] != 0)
+ {
+ new_band_width[j] = p_bw_SPT_tbl[j];
+
+ /*shorten the bandwidth for pulse resolution*/
+ new_band_width_half = shr(new_band_width[j], 1);
+ move16();
+ new_band_start[j] = sub(prev_SWB_peak_pos[kpos], new_band_width_half);
+ move16();
+ new_band_end[j] = add(prev_SWB_peak_pos[kpos], new_band_width_half);
+ move16();
+
+ IF(LT_16(new_band_start[j], band_start[k]))
+ {
+ new_band_start[j] = band_start[k];
+ move16();
+ new_band_end[j] = add(new_band_start[j], sub(new_band_width[j], 1));
+ move16();
+ }
+ ELSE IF(GT_16(new_band_end[j], band_end[k]))
+ {
+ new_band_end[j] = band_end[k];
+ move16();
+ new_band_start[j] = sub(new_band_end[j], sub(new_band_width[j], 1));
+ move16();
+ }
+ }
+ ELSE
+ {
+ new_band_width[j] = p_bw_SPT_tbl[j];
+
+ /*shorten the bandwidth for pulse resolution*/
+ new_band_width_half = shr(new_band_width[j], 1);
+ move16();
+ new_band_start[j] = sub(shr(add(band_start[k], band_end[k]), 1), new_band_width_half);
+ move16();
+ new_band_end[j] = add(shr(add(band_start[k], band_end[k]), 1), new_band_width_half);
+ move16();
+ }
+
+ kpos = add(kpos, 1);
+ j = add(j, 1);
+ }
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * spt_shorten_domain_band_save()
+ *
+ * Store the original subband information
+ *--------------------------------------------------------------------------*/
+
+void spt_shorten_domain_band_save_fx(
+ const Word16 bands, /* i: total subband */
+ const Word16 band_start[], /* i: starting position of subband */
+ const Word16 band_end[], /* i: end position of subband */
+ const Word16 band_width[], /* i: band width of subband */
+ Word16 org_band_start[], /* o: starting position of subband */
+ Word16 org_band_end[], /* o: end position of subband */
+ Word16 org_band_width[] /* o: band width of subband */
+)
+{
+ Word16 k;
+ Word16 kpos;
+
+ kpos = 0;
+ move16();
+ FOR(k = sub(bands, SPT_SHORTEN_SBNUM); k < bands; k++)
+ {
+ org_band_start[kpos] = band_start[k];
+ move16();
+ org_band_end[kpos] = band_end[k];
+ move16();
+ org_band_width[kpos] = band_width[k];
+ move16();
+ kpos = add(kpos, 1);
+ }
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * spt_shorten_domain_band_restore()
+ *
+ * Restrore the subband information
+ *--------------------------------------------------------------------------*/
+
+void spt_shorten_domain_band_restore_fx(
+ const Word16 bands, /* i: total subband */
+ Word16 band_start[], /* i/o: starting position of subband */
+ Word16 band_end[], /* i/o: end position of subband */
+ Word16 band_width[], /* i/o: band width of subband */
+ const Word16 org_band_start[], /* o: starting position of subband */
+ const Word16 org_band_end[], /* o: end position of subband */
+ const Word16 org_band_width[] /* o: band width of subband */
+)
+{
+ Word16 k;
+ Word16 kpos;
+
+ kpos = 0;
+ move16();
+ FOR(k = sub(bands, SPT_SHORTEN_SBNUM); k < bands; k++)
+ {
+ band_start[k] = org_band_start[kpos];
+ move16();
+ band_end[k] = org_band_end[kpos];
+ move16();
+ band_width[k] = org_band_width[kpos];
+ move16();
+ kpos = add(kpos, 1);
+ }
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * spt_swb_peakpos_tmp_save
+ *
+ * Save Peak position for every higher subband
+ *--------------------------------------------------------------------------*/
+
+void spt_swb_peakpos_tmp_save_fx(
+ const Word32 L_y2[], /* i: coded spectral information */
+ const Word16 bands, /* i: total number of bands */
+ const Word16 band_start[], /* i: starting position of subband */
+ const Word16 band_end[], /* i: end position of subband */
+ Word16 prev_SWB_peak_pos_tmp[] /* o: spectral peaks */
+)
+{
+
+ Word16 i, j, k;
+ Word32 L_peak_max;
+ Word32 L_abs_y2;
+
+ j = 0;
+ move16();
+ FOR(k = sub(bands, SPT_SHORTEN_SBNUM); k < bands; k++)
+ {
+ L_peak_max = L_deposit_l(0);
+ prev_SWB_peak_pos_tmp[j] = 0;
+ move16();
+ FOR(i = band_start[k]; i <= band_end[k]; i++)
+ {
+ L_abs_y2 = L_abs(L_y2[i]);
+ move32();
+ IF(LT_32(L_peak_max, L_abs_y2))
+ {
+ L_peak_max = L_abs_y2;
+ move32();
+ prev_SWB_peak_pos_tmp[j] = i;
+ move16();
+ }
+ }
+ j = add(j, 1);
+ }
+ return;
+}
+
+//already present need this one because appropriate and uses basops other than previous one.
+
+void bit_allocation_second_fx(
+ Word32 *Rk,
+ Word32 *Rk_sort,
+ Word16 BANDS,
+ const Word16 *band_width,
+ Word16 *k_sort,
+ Word16 *k_num,
+ const Word16 *p2a_flags,
+ const Word16 p2a_bands,
+ const Word16 *last_bitalloc,
+ const Word16 input_frame
+)
+{
+ Word16 k, k2 = 0;
+ Word16 ever_bits[BANDS_MAX], ever_sort[BANDS_MAX];/*Q12 */
+ Word16 class_flag = 0;
+ Word16 rk_temp = 32767, ever_temp = 32767;/*Q12 */
+ Word16 exp;
+ Word16 tmp;
+ Word32 L_tmp;
+
+ FOR(k = 0; k < BANDS; k++)
+ {
+ test();
+ test();
+ test();
+ IF(((GE_16(k_sort[k], sub(BANDS, p2a_bands))) && (EQ_16(p2a_flags[k_sort[k]], 1))) ||
+ ((GE_16(k_sort[k], sub(BANDS, 2))) && (EQ_16(last_bitalloc[sub(k_sort[k], sub(BANDS, 2))], 1))))
+ {
+ exp = norm_s(band_width[k_sort[k]]);
+ tmp = shl(band_width[k_sort[k]], exp);/*Q(exp) */
+ tmp = div_s(16384, tmp);/*Q(15+14-exp = 29-exp) */
+ L_tmp = Mult_32_16(Rk_sort[k], tmp);/* Q(16+29-exp-15 = 30-exp) */
+ tmp = sub(18, exp);
+ ever_bits[k] = extract_l(L_shr(L_tmp, tmp));/*Q12 */
+ IF(LT_16(ever_bits[k], rk_temp))
+ {
+ rk_temp = ever_bits[k];
+ move16();
+ k2 = k;
+ move16();
+ }
+ class_flag = 1;
+ }
+ }
+ test();
+ IF(class_flag == 0 || EQ_16(input_frame, L_FRAME8k))
+ {
+ FOR(k = 0; k < BANDS; k++)
+ {
+ test();
+ IF(LT_16(k_sort[k], sub(BANDS, p2a_bands)) && Rk_sort[k] > 0)
+ {
+ exp = norm_s(band_width[k_sort[k]]);
+ tmp = shl(band_width[k_sort[k]], exp);/*Q(exp) */
+ tmp = div_s(16384, tmp);/*Q(15+14-exp = 29-exp) */
+ L_tmp = Mult_32_16(Rk_sort[k], tmp);/* Q(16+29-exp-15 = 30-exp) */
+ tmp = sub(18, exp);
+ ever_sort[k] = extract_l(L_shr(L_tmp, tmp));/*Q12 */
+ IF(LT_16(ever_sort[k], ever_temp))
+ {
+ ever_temp = ever_sort[k];
+ move16();
+ k2 = k;
+ move16();
+ }
+ }
+ }
+ }
+
+ k_num[0] = k2;
+ IF(EQ_16(k_sort[k2], sub(BANDS, 1)))
+ {
+ FOR(k = 0; k < BANDS; k++)
+ {
+ if (EQ_16(k_sort[k], sub(k_sort[k2], 1)))
+ {
+ k_num[1] = k;
+ move16();
+ }
+ }
+ }
+ ELSE IF(k_sort[k2] == 0)
+ {
+ FOR(k = 0; k < BANDS; k++)
+ {
+ if (EQ_16(k_sort[k], add(k_sort[k2], 1)))
+ {
+ k_num[1] = k;
+ move16();
+ }
+ }
+ }
+ ELSE
+ {
+ IF(LT_32(Rk[sub(k_sort[k2],1)],Rk[add(k_sort[k2],1)]))
+ {
+ FOR(k = 0; k < BANDS; k++)
+ {
+ if (EQ_16(k_sort[k],sub(k_sort[k2],1)))
+ {
+ k_num[1] = k;
+ move16();
+ }
+ }
+ }
+ ELSE
+ {
+ FOR(k = 0; k < BANDS; k++)
+ {
+ if (EQ_16(k_sort[k],add(k_sort[k2],1)))
+ {
+ k_num[1] = k;
+ move16();
+ }
+ }
+ }
+ }
+}
diff --git a/lib_com/hq2_noise_inject.c b/lib_com/hq2_noise_inject.c
index ed48dab7b908ac6e257549f5396e3a23f565996c..9f70f4971c89e8b36f46377dd766907d4417f17d 100644
--- a/lib_com/hq2_noise_inject.c
+++ b/lib_com/hq2_noise_inject.c
@@ -273,3 +273,5 @@ void hq2_noise_inject(
return;
}
+
+
diff --git a/lib_com/hq2_noise_inject_fx.c b/lib_com/hq2_noise_inject_fx.c
new file mode 100644
index 0000000000000000000000000000000000000000..7bec83457e9037b1ae18e409eb86944614765e2b
--- /dev/null
+++ b/lib_com/hq2_noise_inject_fx.c
@@ -0,0 +1,683 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 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.
+
+*******************************************************************************************************/
+
+#include
+#include "options.h"
+#include "prot_fx2.h"
+#include "oper_32b.h"
+#include "move.h"
+#include "count.h"
+
+ /*--------------------------------------------------------------------------*
+ * hq2_noise_inject()
+ *
+ * HQ2 noise injection for WB signals
+ *--------------------------------------------------------------------------*/
+void hq2_noise_inject_fx(
+ Word32 L_y2[],
+ const Word16 band_start[],
+ const Word16 band_end[],
+ const Word16 band_width[],
+ Word32 Ep_fx[],
+ Word32 Rk_fx[],
+ const Word16 npulses[],
+ Word16 ni_seed,
+ const Word16 bands,
+ const Word16 ni_start_band,
+ const Word16 bw_low,
+ const Word16 bw_high,
+ const Word32 enerL_fx,
+ const Word32 enerH_fx,
+ Word32 last_ni_gain_fx[],
+ Word16 last_env_fx[],
+ Word16 *last_max_pos_pulse,
+ Word16 *p2a_flags,
+ Word16 p2a_bands,
+ const Word16 hqswb_clas,
+ const Word16 bwidth,
+ const Word32 bwe_br
+)
+{
+ Word32 L_tmp, L_tmp2, L_tmp2x, L_tmp3, L_tmp1;
+ Word16 exp, exp2, Q_speech;
+ Word16 pd_fx[BANDS_MAX], rand_fx, peak_fx[BANDS_MAX], fac_fx;
+
+ Word16 tmp, tmpx, tmp1, tmp2, tmp3, tmp4, Q_env_fx[BANDS_MAX], Q_Ep_fx[BANDS_MAX];
+
+ Word16 Qs = SWB_BWE_LR_Qs;
+ Word32 env_fx[BANDS_MAX];
+ Word16 env_fx2[BANDS_MAX];
+ Word32 ni_gain_fx[BANDS_MAX];
+ Word16 y2hat_fx[L_FRAME48k];
+
+ Word16 i, j, k, ni_end_band, satur, count[BANDS_MAX], max_pos_pulse, pos;
+ Word16 sb = bands;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+
+ satur = 0;
+ move16();
+
+ FOR(i = 0; i < bands; i++)
+ {
+#ifdef BASOP_NOGLOB
+ Ep_fx[i] = L_shl_o(Ep_fx[i], 6, &Overflow);/* Q-6 -> Q0 */ move32();
+#else /* BASOP_NOGLOB */
+ Ep_fx[i] = L_shl(Ep_fx[i], 6);/* Q-6 -> Q0 */ move32();
+#endif /* BASOP_NOGLOB */
+ }
+
+ tmp = add(band_end[bands - 1], 1);
+ FOR(k = 0; k < tmp; k++)
+ {
+ y2hat_fx[k] = (Word16)L_min(L_max(L_shr(L_y2[k], Qs), -32768), 32767);
+ move16(); /* Extract_l or something else is missing here */
+ }
+
+ test();
+ test();
+ test();
+ test();
+ IF((EQ_16(hqswb_clas, HQ_HARMONIC) || EQ_16(hqswb_clas, HQ_NORMAL)) && (EQ_32(bwe_br, HQ_16k40) || EQ_32(bwe_br, HQ_13k20)) && EQ_16(bwidth, SWB))
+ {
+ sb = 17;
+ move16();
+ if (EQ_32(bwe_br, HQ_16k40))
+ {
+ sb = 19;
+ move16();
+ }
+ }
+
+ /* calculate the envelopes/ the decoded peak coeff./number of the decoded coeff./ the last subbands of the bit-allocated/saturation of bit-allocation */
+ ni_end_band = bands;
+ max_pos_pulse = bands;
+ FOR(k = ni_start_band; k < ni_end_band; k++)
+ {
+ tmp = div_s(1, band_width[k]); /*Q15 */
+ L_tmp = Mult_32_16(Rk_fx[k], tmp);/*Q(16+15-15=16) */
+ pd_fx[k] = extract_h(L_shl(L_tmp, 10)); /*16+10-16 =Q10 */
+
+ L_tmp2 = Ep_fx[k];/*Q0 */
+ move32();
+ L_tmp = L_max(1, L_tmp2);
+ exp = norm_l(L_tmp);
+ tmp = extract_h(L_shl(L_tmp, exp));
+
+ L_tmp3 = (Word32)band_width[k];
+ move32();
+ exp2 = norm_l(L_tmp3);
+ tmp2 = extract_h(L_shl(L_tmp3, exp2));
+
+ exp2 = sub(exp, exp2); /* Denormalize and substract */
+
+ tmp3 = sub(tmp2, tmp);
+ if (tmp3 > 0)
+ {
+ tmp2 = shr(tmp2, 1);
+ }
+ if (tmp3 > 0)
+ {
+ exp2 = add(exp2, 1);
+ }
+ tmp = div_s(tmp2, tmp);
+ L_tmp = L_deposit_h(tmp);
+ L_tmp = Isqrt_lc(L_tmp, &exp2);
+ env_fx[k] = L_tmp;
+ move32();/*Q(31-exp2) move32(); */
+ Q_env_fx[k] = sub(31, exp2);
+ move16();
+ tmp = sub(17, Q_env_fx[k]);
+#ifdef BASOP_NOGLOB
+ env_fx2[k] = extract_h(L_shl_o(env_fx[k], tmp, &Overflow));/*Q1 */
+#else /* BASOP_NOGLOB */
+ env_fx2[k] = extract_h(L_shl(env_fx[k], tmp));/*Q1 */
+#endif /* BASOP_NOGLOB */
+ peak_fx[k] = 0;
+ move16();
+ count[k] = 0;
+ move16();
+
+ IF(npulses[k] != 0)
+ {
+ FOR(i = band_start[k]; i <= band_end[k]; i++)
+ {
+ L_tmp = L_mult0(y2hat_fx[i], y2hat_fx[i]); /*0 */
+#ifdef BASOP_NOGLOB
+ Ep_fx[k] = L_sub_o(Ep_fx[k], L_tmp, &Overflow);
+#else /* BASOP_NOGLOB */
+ Ep_fx[k] = L_sub(Ep_fx[k], L_tmp);
+#endif /* BASOP_NOGLOB */
+ move32();/*0 */
+ IF(GT_16(abs_s(y2hat_fx[i]), peak_fx[k]))
+ {
+ peak_fx[k] = abs_s(y2hat_fx[i]);
+ move16();/*0 */
+ }
+
+ IF(y2hat_fx[i] != 0)
+ {
+ count[k] = add(count[k], 1);
+ move16();
+ }
+ }
+
+ max_pos_pulse = k;
+ L_tmp2 = Ep_fx[k];
+ move32();
+ L_tmp = L_max(1, L_tmp2);
+ exp = norm_l(L_tmp);
+ tmp = extract_h(L_shl(L_tmp, exp));
+
+ L_tmp3 = (Word32)band_width[k];
+ exp2 = norm_l(L_tmp3);
+ tmp2 = extract_h(L_shl(L_tmp3, exp2));
+
+ exp2 = sub(exp, exp2); /* Denormalize and substract */
+
+ tmp3 = sub(tmp2, tmp);
+ if (tmp3 > 0)
+ {
+ tmp2 = shr(tmp2, 1);
+ }
+ if (tmp3 > 0)
+ {
+ exp2 = add(exp2, 1);
+ }
+ tmp = div_s(tmp2, tmp);
+ L_tmp = L_deposit_h(tmp);
+ L_tmp = Isqrt_lc(L_tmp, &exp2);
+ Ep_fx[k] = L_tmp;
+ move32();/*Q(31-exp2) */
+ Q_Ep_fx[k] = sub(31, exp2);
+ move16();
+ }
+ ELSE
+ {
+ Ep_fx[k] = env_fx[k];
+ move32();/*Q(Q_env_fx[k]) */
+ Q_Ep_fx[k] = Q_env_fx[k];
+ move16();/*31-exp2 */
+ }
+ }
+
+ FOR(k = ni_start_band; k < ni_end_band; k++)
+ {
+ /* calculate the noise gain */
+ satur = 0;
+ move16();
+ if (GE_16(pd_fx[k], 819))
+ {
+ satur = 1;
+ move16();
+ }
+
+ test();
+ IF(satur == 0 && Ep_fx[k] > 0)
+ {
+ IF(npulses[k] != 0)
+ {
+ IF(EQ_16(bwidth, SWB))
+ {
+ IF(NE_16(hqswb_clas, HQ_TRANSIENT))
+ {
+ IF(peak_fx[k] != 0)
+ {
+ Q_speech = norm_s(peak_fx[k]);
+ tmp = shl(peak_fx[k], Q_speech);/*Q(Q_speech) */
+ tmp = div_s(16384, tmp);/*Q(15+14-Q_speech) */
+ }
+ ELSE
+ {
+ tmp = 0x7fff;
+ move16();
+ Q_speech = 0;
+ move16();
+ }
+ L_tmp2x = Mult_32_16(Ep_fx[k], tmp);/* Q(Q_Ep_fx[k]+29-Q_speech-15 = Q_Ep_fx[k]-Q_speech+14) */
+ tmp = sub(Q_Ep_fx[k], Q_speech);
+ tmpx = add(tmp, 1);
+ tmp2 = extract_l(L_shr(L_tmp2x, s_min(tmpx, 31)));/*Q13 Ep[k]/peak[k] */
+
+ IF(EQ_16(hqswb_clas, HQ_HARMONIC))
+ {
+ tmp = sub(1536, pd_fx[k]); /*Q10 */
+ tmp3 = shl(tmp, 4); /*Q14 */
+ L_tmp = Mult_32_16(env_fx[k], tmp3);/*Q(Q_env_fx[k]+14-15 = Q_env_fx[k]-1) */
+ L_tmp = Mult_32_16(L_tmp, 6144);/*Q(Q_env_fx[k]-1+10-15 = Q_env_fx[k]-6) */
+
+ IF(peak_fx[k] != 0)
+ {
+ Q_speech = norm_s(peak_fx[k]);
+ tmp = shl(peak_fx[k], Q_speech);/*Q(Q_speech) */
+ tmp = div_s(16384, tmp);/*Q(15+14-Q_speech) */
+ }
+ ELSE
+ {
+ tmp = 0x7fff;
+ move16();
+ Q_speech = 0;
+ move16();
+ }
+
+ L_tmp2 = Mult_32_16(Ep_fx[k], tmp);/* Q(Q_Ep_fx[k]+29-Q_speech-15=Q_Ep_fx[k]-Q_speech+14) */
+ L_tmp3 = Mult_32_16(L_tmp, tmp);/* Q(Q_env_fx[k]-6+29-Q_speech-15=Q_env_fx[k]-Q_speech+8) */
+ L_tmp = Mult_32_32(L_tmp2, L_tmp3); /*Q(Q_Ep_fx[k]-Q_speech+14+Q_env_fx[k]-Q_speech+8-31=Q_Ep_fx[k]+Q_env_fx[k]-2*Q_speech-9) */
+
+ tmp = add(Q_Ep_fx[k], Q_env_fx[k]);
+ tmp = sub(tmp, Q_speech);
+ tmp = sub(tmp, Q_speech);
+ tmp = sub(37, tmp);
+ tmp1 = extract_h(L_shl(L_tmp, tmp));/*Q12 //6.0f*(1.5f - pd[k])*env[k]*Ep[k]/(peak[k]*peak[k]) */
+
+ fac_fx = tmp1;
+ move16();/*Q12 */
+ if (GT_16(k, sb))
+ {
+ fac_fx = mult(24576, tmp2);/*//Q(14+13-15=12) */
+ }
+ }
+ ELSE
+ {
+ IF(LE_16(k,sb))
+ {
+ tmp = sub(1536,pd_fx[k]); /*Q10 */
+ tmp3 = shl(tmp,4); /*Q14 */
+ L_tmp = Mult_32_16(L_tmp2x,tmp3);/*Q(Q_Ep_fx[k]-Q_speech+14+14-15 = Q_Ep_fx[k]-Q_speech+13) */
+ L_tmp = Mult_32_16(L_tmp,20480);/*Q(Q_Ep_fx[k]-Q_speech+13+12-15 = Q_Ep_fx[k]-Q_speech+10) */
+ fac_fx = extract_h(L_shl(L_tmp,sub(add(18,Q_speech),Q_Ep_fx[k])));/*Q_Ep_fx[k]-Q_speech+10 +18+Q_speech-Q_Ep_fx[k] -16 =12 */
+ }
+ ELSE
+ {
+ fac_fx = shl(mult(32767,tmp2),1);/*//Q(13+13-15+1=12) */
+ }
+ }
+ }
+ ELSE
+ {
+ fac_fx = 4505;
+ move16();/*Q12 */
+ }
+ }
+ ELSE
+ {
+ tmp = sub(1536,pd_fx[k]); /*Q10 */
+ tmp2 = s_min(1024,tmp); /*q10 */
+ tmp2 = shl(tmp2,4); /*Q14 */
+ L_tmp = Mult_32_16(env_fx[k],tmp2);/*Q(Q_env_fx[k]+14-15 = Q_env_fx[k]-1) */
+ L_tmp = Mult_32_16(L_tmp,20480);/*Q(Q_env_fx[k]-1+10-15 = Q_env_fx[k]-6) */
+
+ IF(peak_fx[k] != 0)
+ {
+ Q_speech = norm_s(peak_fx[k]);
+ tmp = shl(peak_fx[k],Q_speech);/*Q(Q_speech) */
+ tmp = div_s(16384,tmp);/*Q(15+14-Q_speech) */
+ }
+ ELSE
+ {
+ tmp = 0x7fff;
+ move16();
+ Q_speech = 0;
+ move16();
+ }
+
+ L_tmp2 = Mult_32_16(Ep_fx[k],tmp);/* Q(Q_Ep_fx[k]+29-Q_speech-15=Q_Ep_fx[k]-Q_speech+14) */
+ L_tmp3 = Mult_32_16(L_tmp,tmp);/* Q(Q_env_fx[k]-6+29-Q_speech-15=Q_env_fx[k]-Q_speech+8) */
+ L_tmp = Mult_32_32(L_tmp2,L_tmp3); /*Q(Q_Ep_fx[k]-Q_speech+14+Q_env_fx[k]-Q_speech+8-31=Q_Ep_fx[k]+Q_env_fx[k]-2*Q_speech-9) */
+
+ tmp = add(Q_Ep_fx[k],Q_env_fx[k]);
+ tmp = sub(tmp,Q_speech);
+ tmp = sub(tmp,Q_speech);
+ tmp = sub(37,tmp);
+
+ fac_fx = extract_h(L_shl(L_tmp,tmp));/*Q12 */
+
+ test();
+ IF(GT_16(k,1) && LT_16(k,sub(ni_end_band,1)))
+ {
+ IF(env_fx2[k] != 0)
+ {
+ Q_speech = norm_s(env_fx2[k]);
+ tmp = shl(env_fx2[k],Q_speech);/*Q(Q_speech+1) */
+ tmp = div_s(16384,tmp);/*Q(15+14-Q_speech-1=28-Q_speech) */
+ Q_speech = sub(28,Q_speech);
+ }
+ ELSE
+ {
+ tmp = 0x7fff;
+ move16();
+ Q_speech = 0;
+ move16();
+ }
+ tmp1 = mult(env_fx2[add(k,1)],16384);/*Q(1+15-15=1) Q1 */
+ tmp2 = sub(env_fx2[k],tmp1);
+ tmp1 = mult(env_fx2[k],16384);/*Q(1+15-15=1) Q1 */
+ tmp3 = sub(tmp1,env_fx2[sub(k,1)]);
+ tmp1 = mult(peak_fx[k],16384);/*Q(0+15-15=0) Q0 */
+ tmp4 = sub(tmp1,shr(env_fx2[k],1));
+ test();
+ test();
+ test();
+ IF(count[add(k,1)] == 0 && tmp2 > 0 && tmp3 < 0)
+ {
+ L_tmp = L_mult(env_fx2[add(k,1)],tmp);/* Q(1+Q_speech+1 = Q_speech+2) */
+ L_tmp = Mult_32_16(L_tmp,24576); /*Q(Q_speech+2+14-15=Q_speech+1) */
+ fac_fx = extract_h(L_shl(L_tmp,sub(27,Q_speech)));/*Q12 */
+ }
+ ELSE IF(count[sub(k,1)] == 0 && tmp4 > 0)
+ {
+ L_tmp = L_mult(env_fx2[sub(k,1)],tmp); /* Q(1+Q_speech+1 = Q_speech+2) */
+#ifdef BASOP_NOGLOB
+ fac_fx = extract_h(L_shl_o(L_tmp, sub(26, Q_speech), &Overflow));/*Q12 */
+#else
+ fac_fx = extract_h(L_shl(L_tmp,sub(26,Q_speech)));/*Q12 */
+#endif
+ }
+ }
+
+ test();
+ IF(GE_16(k,sub(ni_end_band,p2a_bands)) && EQ_16(bwidth,WB))
+ {
+ L_tmp = Mult_32_16(enerH_fx, bw_low);
+ L_tmp2 = Mult_32_16(enerL_fx, bw_high);
+ L_tmp = L_sub(L_tmp,L_tmp2);
+ tmp1 = mult(peak_fx[k],16384);/*Q(0+15-15=0) Q0 */
+ tmp4 = sub(tmp1,shr(env_fx2[k],1));
+ test();
+ IF(L_tmp > 0 && tmp4 < 0)
+ {
+ IF(peak_fx[k] != 0)
+ {
+ Q_speech = norm_s(peak_fx[k]);
+ tmp = shl(peak_fx[k],Q_speech);/*Q(Q_speech) */
+ tmp = div_s(16384,tmp);/*Q(15+14-Q_speech) */
+ }
+ ELSE
+ {
+ tmp = 0x7fff;
+ move16();
+ Q_speech = 0;
+ move16();
+ }
+ L_tmp2 = Mult_32_16(Ep_fx[k],tmp);/* Q(Q_Ep_fx[k]+29-Q_speech-15 = Q_Ep_fx[k]-Q_speech+14) */
+ tmp = sub(Q_Ep_fx[k],Q_speech);
+ tmp = add(tmp,1);
+ tmp = extract_l(L_shr(L_tmp2,tmp));/*Q13 */
+ tmp = sub(16384,tmp);/*Q13 */
+ fac_fx = extract_h(L_shl(L_mult(fac_fx,tmp),2));/*Q12*/
+ }
+
+ IF(p2a_flags[k] == 0)
+ {
+ L_tmp2 = Mult_32_16(Ep_fx[k],fac_fx);/*Q(Q_Ep_fx[k]+12-15 = Q_Ep_fx[k]-3) */
+ Q_speech = norm_l(L_tmp2);
+ tmp = extract_h(L_shl(L_tmp2,Q_speech));/*Q(Q_Ep_fx[k]-3+Q_speech-16 = Q_Ep_fx[k]+Q_speech-19) */
+ IF(tmp != 0)
+ {
+ tmp = div_s(16384,tmp);/*Q(15+14-Q_Ep_fx[k]-Q_speech+19 = 48-Q_Ep_fx[k]-Q_speech) */
+ L_tmp2 = Mult_32_16(env_fx[k],tmp);/*Q(Q_env_fx[k]+48-Q_Ep_fx[k]-Q_speech-15 = Q_env_fx[k]-Q_Ep_fx[k]-Q_speech+33) */
+ L_tmp2 = Mult_32_16(L_tmp2,20480);/*Q(Q_env_fx[k]-Q_Ep_fx[k]-Q_speech+33+14-15 = Q_env_fx[k]-Q_Ep_fx[k]-Q_speech+32) */
+ tmp = sub(Q_env_fx[k],Q_Ep_fx[k]);
+ tmp = sub(tmp,Q_speech);
+ tmp = add(tmp,25);
+ L_tmp = L_shr(L_tmp2,tmp);/*Q7 */
+ tmp = extract_l(L_min(L_tmp,192));/* */
+ fac_fx = extract_h(L_shl(L_mult(fac_fx,tmp),8));/*Q12 */
+ }
+ ELSE
+ {
+ tmp = 0x7fff;/*Q0 */
+ L_tmp2 = Mult_32_16(env_fx[k],tmp);/*Q(Q_env_fx[k]+0-15 = Q_env_fx[k]-15) */
+ L_tmp2 = Mult_32_16(L_tmp2,20480);/*Q(Q_env_fx[k]-15+14-15 = Q_env_fx[k]-16) */
+ tmp = sub(Q_env_fx[k],23);
+ L_tmp = L_shr(L_tmp2,tmp);/*Q7 */
+ tmp = extract_l((L_min(L_tmp,192)));/* */
+ fac_fx = extract_h(L_shl(L_mult(fac_fx,tmp),8));/*Q12 */
+ }
+ }
+ }
+ }
+ }
+ ELSE
+ {
+ fac_fx = 4505;
+ move16();
+ test();
+ if (EQ_16(hqswb_clas,HQ_HARMONIC) && EQ_16(bwidth,SWB))
+ {
+ fac_fx = 3277;
+ move16();
+ }
+ }
+
+ L_tmp = Mult_32_16(Ep_fx[k], fac_fx);/*Q(Q_Ep_fx[k]+12-15 = Q_Ep_fx[k]-3) */
+#ifdef BASOP_NOGLOB
+ ni_gain_fx[k] = L_shr_o(L_tmp, sub(Q_Ep_fx[k], 20), &Overflow);
+#else /* BASOP_NOGLOB */
+ ni_gain_fx[k] = L_shr(L_tmp, sub(Q_Ep_fx[k], 20));
+#endif
+ move32();/*Q17 */
+ }
+ ELSE
+ {
+ ni_gain_fx[k] = L_deposit_l(0);
+ }
+
+ /* smooth the noise gain between the current frame and the previous frame */
+ pos = s_max(max_pos_pulse, *last_max_pos_pulse);
+ move16();
+ if (EQ_16(bwidth, SWB))
+ {
+ pos = sub(ni_end_band, 1);
+ move16();
+ }
+
+ IF(LE_16(k, pos))
+ {
+ test();
+ IF(k > 0 && LT_16(sub(k, ni_end_band), -1))
+ {
+ tmp1 = mult(last_env_fx[k], 16384);/*Q(1+15-15=1) Q1 */
+ tmp2 = sub(env_fx2[k], tmp1);/*>0 */
+ tmp1 = mult(env_fx2[k], 16384);/*Q(1+15-15=1) Q1 */
+ tmp3 = sub(tmp1, last_env_fx[k]);/*<0 */
+ L_tmp = L_add((Word32)env_fx2[k], (Word32)env_fx2[sub(k, 1)]);
+ L_tmp = L_add(L_tmp, (Word32)env_fx2[add(k, 1)]);/*Q1 */
+ L_tmp1 = L_add((Word32)last_env_fx[k], (Word32)last_env_fx[sub(k, 1)]);
+ L_tmp1 = L_add(L_tmp1, (Word32)last_env_fx[add(k, 1)]);/*Q1 */
+ L_tmp2 = Mult_32_16(L_tmp1, 16384);/*Q(1+15-15) Q1 */
+ L_tmp2 = L_sub(L_tmp, L_tmp2);/*>0 */
+ L_tmp3 = Mult_32_16(L_tmp, 16384);/*Q(1+15-15) Q1 */
+ L_tmp3 = L_sub(L_tmp3, L_tmp1);/*<0 */
+ test();
+ test();
+ test();
+ IF((tmp2 > 0 && tmp3 < 0) || (L_tmp2 > 0 && L_tmp3 < 0))
+ {
+ IF(GT_32(ni_gain_fx[k], last_ni_gain_fx[k]))
+ {
+ L_tmp = Mult_32_16(ni_gain_fx[k], 6554);/*Q(17+15-15 = 17) */
+ L_tmp1 = Mult_32_16(last_ni_gain_fx[k], 26214);/*Q17 */
+ ni_gain_fx[k] = L_add(L_tmp, L_tmp1);
+ move32();
+ }
+ ELSE
+ {
+ L_tmp = Mult_32_16(ni_gain_fx[k],19661);/*Q(17+15-15 = 17) */
+ L_tmp1 = Mult_32_16(last_ni_gain_fx[k],13107);/*Q17 */
+ ni_gain_fx[k] = L_add(L_tmp,L_tmp1);
+ move32();
+ }
+ }
+ }
+ ELSE IF(add(sub(k, ni_end_band), 1) == 0)
+ {
+ tmp1 = mult(last_env_fx[k], 16384);/*Q(1+15-15=1) Q1 */
+ tmp2 = sub(env_fx2[k], tmp1);/*>0 */
+ tmp1 = mult(env_fx2[k], 16384);/*Q(1+15-15=1) Q1 */
+ tmp3 = sub(tmp1, last_env_fx[k]);/*<0 */
+ L_tmp = L_add((Word32)env_fx2[k], (Word32)env_fx2[sub(k, 1)]);/*Q1 */
+ L_tmp1 = L_add((Word32)last_env_fx[k], (Word32)last_env_fx[sub(k, 1)]);/*Q1 */
+ L_tmp2 = Mult_32_16(L_tmp1, 16384);/*Q(1+15-15) Q1 */
+ L_tmp2 = L_sub(L_tmp, L_tmp2);/*>0 */
+ L_tmp3 = Mult_32_16(L_tmp, 16384);/*Q(1+15-15) Q1 */
+ L_tmp3 = L_sub(L_tmp3, L_tmp1);/*<0 */
+
+ test();
+ test();
+ test();
+ IF((tmp2 > 0 && tmp3 < 0) || (L_tmp2 > 0 && L_tmp3 < 0))
+ {
+ IF(GT_32(ni_gain_fx[k], last_ni_gain_fx[k]))
+ {
+ L_tmp = Mult_32_16(ni_gain_fx[k], 6554);/*Q(17+15-15 = 17) */
+ L_tmp1 = Mult_32_16(last_ni_gain_fx[k], 26214);/*Q17 */
+ ni_gain_fx[k] = L_add(L_tmp, L_tmp1);
+ move32();
+ }
+ ELSE
+ {
+ L_tmp = Mult_32_16(ni_gain_fx[k],19661);/*Q(17+15-15 = 17) */
+ L_tmp1 = Mult_32_16(last_ni_gain_fx[k],13107);/*Q17 */
+ ni_gain_fx[k] = L_add(L_tmp,L_tmp1);
+ move32();
+ }
+ }
+ }
+ }
+
+ /* inject noise into the non-decoded coeffs */
+ test();
+ test();
+ IF(add(sub(k, ni_end_band), p2a_bands) >= 0 && p2a_flags[k] == 0 && NE_16(bwidth, SWB))
+ {
+ FOR(i = band_start[k]; i <= band_end[k]; i++)
+ {
+ IF(L_y2[i] != 0)
+ {
+ L_y2[i] = Mult_32_16(L_y2[i], 26215);
+ move32();/*Q(12+15-15=12) */
+ }
+ }
+ }
+
+ test();
+ test();
+ test();
+ IF(EQ_16(k, max_pos_pulse) && add(sub(k, bands), p2a_bands) < 0 && NE_16(satur, 1) && NE_16(bwidth, SWB))
+ {
+ j = 0;
+ Q_speech = norm_l(ni_gain_fx[k]);
+ tmp = extract_h(L_shl(ni_gain_fx[k], Q_speech));/*Q(Q_speech+1) */
+ IF(tmp != 0)
+ {
+ tmp = div_s(16384, tmp);/*Q(15+14-Q_speech-1 = 28-Q_speech) */
+ L_tmp = Mult_32_16(Ep_fx[k], tmp); /*Q(Q_Ep_fx[k]+28-Q_speech-15 = Q_Ep_fx[k]+13-Q_speech) */
+ tmp = sub(Q_Ep_fx[k], Q_speech);
+ tmp = sub(15, tmp);
+#ifdef BASOP_NOGLOB
+ tmp = extract_h(L_shl_o(L_tmp, tmp, &Overflow));/*Q12 */
+#else
+ tmp = extract_h(L_shl(L_tmp, tmp));/*Q12 */
+#endif
+ }
+ ELSE
+ {
+ tmp = 0x7fff;/*Q0 */
+ L_tmp = Mult_32_16(Ep_fx[k],tmp); /*Q(Q_Ep_fx[k]+0-15 = Q_Ep_fx[k]-15) */
+ tmp = sub(43,Q_Ep_fx[k]);
+#ifdef BASOP_NOGLOB
+ tmp = extract_h(L_shl_o(L_tmp,tmp, &Overflow));/*Q12 */
+#else
+ tmp = extract_h(L_shl(L_tmp,tmp));/*Q12 */
+#endif
+ }
+ fac_fx = s_max(tmp, 4096);/*Q12 */
+
+ FOR(i = band_start[k]; i <= band_end[k]; i++)
+ {
+ IF(L_y2[i] == 0)
+ {
+ rand_fx = Random(&ni_seed); /*Q15 */
+ IF(band_width[k] != 0)
+ {
+ Q_speech = norm_s(band_width[k]);
+#ifdef BASOP_NOGLOB
+ tmp = shl_o(band_width[k], Q_speech, &Overflow);/*Q(Q_speech) */
+#else
+ tmp = shl(band_width[k], Q_speech);/*Q(Q_speech) */
+#endif
+ tmp = div_s(16384, tmp);/*Q(15+14-Q_speech) */
+ }
+ ELSE
+ {
+ tmp = 0x7fff;
+ Q_speech = 0;
+ }
+ tmp1 = sub(fac_fx, 4096);/*Q12 */
+ L_tmp = L_mult(tmp1, j);/*Q13 */
+ L_tmp = Mult_32_16(L_tmp, tmp);/*Q(13+29-Q_speech-15 = 27-Q_speech) */
+#ifdef BASOP_NOGLOB
+ tmp = extract_h(L_shl_o(L_tmp, add(1, Q_speech), &Overflow));/*Q12 */
+#else
+ tmp = extract_h(L_shl(L_tmp, add(1, Q_speech)));/*Q12 */
+#endif
+ tmp = sub(fac_fx, tmp);/*Q12 */
+ L_tmp = Mult_32_16(ni_gain_fx[k], tmp);/*Q(17+12-15=14) */
+ L_y2[i] = L_add(L_y2[i], L_shr(Mult_32_16(L_tmp, rand_fx), 2));
+ move32();/*Q12 */
+ }
+ j = add(j, 1);
+ }
+ }
+ ELSE
+ {
+ FOR(i = band_start[k]; i <= band_end[k]; i++)
+ {
+ IF(L_y2[i] == 0)
+ {
+ rand_fx = Random(&ni_seed); /*Q15 */
+ L_tmp = Mult_32_16(ni_gain_fx[k],rand_fx);/*Q(17+15-15=17) */
+ L_y2[i] = L_add(L_y2[i],L_shr(L_tmp,5));
+ move32();/*Q12 */
+ }
+ }
+ }
+ }
+
+ Copy(env_fx2, last_env_fx, ni_end_band);
+ Copy32(ni_gain_fx, last_ni_gain_fx, ni_end_band);
+ *last_max_pos_pulse = max_pos_pulse;
+ move16();
+ return;
+}
diff --git a/lib_com/hq_tools_fx.c b/lib_com/hq_tools_fx.c
index 058c08df2872543d08e33f5b486eb69a1df976aa..fe8902a9a1c3e15fbe24129144392e49d2d0abea 100644
--- a/lib_com/hq_tools_fx.c
+++ b/lib_com/hq_tools_fx.c
@@ -47,12 +47,7 @@
static void overlap_hq_bwe_fx(const Word32 *hq_swb_overlap_buf, Word32 *coeff_out, const Word16 n_swb_overlap_offset,
const Word16 n_swb_overlap, const Word16 *R, const Word16 num_env_bands, const Word16 num_sfm, const Word16 *sfm_end);
-static __inline Word16 L_Extract_lc(const Word32 L_32, Word16 *p_hi)
-{
- *p_hi = extract_h(L_32);
- return lshr(extract_l(L_32), 1);
-}
/*--------------------------------------------------------------------------*
* hq_swb_harmonic_calc_norm_envelop()
@@ -1672,7 +1667,7 @@ static void update_rsubband_fx(const Word16 nb_sfm,
}
Word16 get_nor_delta_hf_fx(
- Decoder_State_fx *st,
+ Decoder_State *st,
Word16 *ynrm,
Word16 *Rsubband, /* Q3 */
const Word16 num_env_bands,
diff --git a/lib_com/index_pvq_opt_fx.c b/lib_com/index_pvq_opt_fx.c
new file mode 100644
index 0000000000000000000000000000000000000000..fae04e95385bd4c27a31ccf9fe0252340d40a51a
--- /dev/null
+++ b/lib_com/index_pvq_opt_fx.c
@@ -0,0 +1,1186 @@
+/*====================================================================================
+ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
+ ====================================================================================*/
+
+#include
+#include
+#include "options.h"
+#include "cnst.h" /* Common constants */
+#include "rom_com.h" /* Static table prototypes */
+#include "prot_fx1.h"
+#include "prot_fx2.h"
+#include "basop_util.h"
+
+#define N_OPT_FX 5 /* complexity setting, direct functional calculation limit & low dim recursion limit */
+#define TABLE_LIM_OPT_FX 96 /* odd divisor table , N-row_recursion limit setting, due to dim */
+
+
+/* local typedefs for optimized pvq indexing, used locally c-file to vectorize common function calls */
+typedef void (*VEC2INDFUNCM) (const Word16* , Word16* , UWord32*, UWord32*);
+typedef UWord32 (*NFUNCM) (Word16);
+typedef UWord32 (*H_FUNCM) ( UWord32 );
+typedef void (*IND2VECFUNCM) ( Word16, Word16, UWord32, Word16* ) ;
+typedef void (*NDIM_FUNCM) ( Word16, Word16, UWord32, Word16* );
+
+/* local constants for indexing functions */
+#define SIGNBIT_FX 0x80000000u
+#define SIGNBIT_SHRT_FX 0x8000
+#define UDIVBY3_FX 2863311531U
+
+/*-------------------------------------------------------------------*
+ * f_odd_exact_div_opt_fx()
+ *
+ * find 1/(den1*2+1) * ( num1p*num2p - num3) ,
+ * if the result is known a priori to be exactly a 32bit UWord32
+ *-------------------------------------------------------------------*/
+static
+UWord32 f_odd_exact_div_opt_fx( /* o : see Eq. */
+ UWord32 num1p, /* i : see Eq. */ /* (2n-1) or n , i.e can be short also */
+ UWord32 num2p, /* i : see Eq. */
+ UWord32 num3, /* i : see Eq. */
+ Word16 den1 /* i : see Eq. */ /*range [0..127] can be made to short */
+)
+{
+ UWord32 UL_tmp;
+ UL_tmp = UL_Mpy_32_32(exactdivodd[den1],UL_subNsD(UL_Mpy_32_32(num1p,num2p),num3));
+
+ return (UL_tmp);
+}
+
+/*---------------------------------------------------------------------------*
+ * f_even_exact_div_opt_fx()
+ *
+ * returns (num1p*num2p - num3 )/ den1
+ * if the result is known a priori to be exactly a 32bit unsigned integer
+ *--------------------------------------------------------------------------*/
+static
+UWord32 f_even_exact_div_opt_fx( /* o : see Eq. */
+ UWord32 UL_num1p, /* i : see Eq. 2n-1 or n can be short input */
+ UWord32 UL_num2p, /* i : see Eq. range should be larger than num1p */
+ UWord32 UL_num3, /* i : see Eq. */
+ Word16 den1 /* i : see Eq. */
+)
+{
+ UWord32 UL_tmp, UL_oddfactor;
+ Word16 den1_m1, even_sh;
+ UWord32 UL_tmp_h;
+ UWord16 sgn;
+
+ den1_m1 = sub(den1,1); /* remove top bit */
+ even_sh = sub(15, norm_s(s_xor(den1_m1, den1))); /* STL signed ops ok as den1 <= 127 */
+
+ UL_oddfactor = exactdivodd[lshr(den1_m1,even_sh)];
+ move32();
+ even_sh = sub(even_sh,1);
+
+
+ Mpy_32_32_uu(UL_num1p, UL_num2p, &UL_tmp_h, &UL_tmp); /* cost ~4 */
+ UL_tmp = UL_subNs(UL_tmp,UL_num3,&sgn); /* may wrap for underflow */
+ if(sgn) /* underflow */
+ {
+ UL_tmp_h = UL_subNsD(UL_tmp_h,1U); /* single basicop -> if */
+ }
+ UL_tmp = UL_or(UL_lshl(UL_tmp_h,sub(32,even_sh)), UL_lshr(UL_tmp,even_sh));
+ /* total cost 9-11 , old solution had 15-16*/
+
+ /* now use tabled modular multiplicative inverse for the odd part division */
+ return UL_Mpy_32_32(UL_tmp, UL_oddfactor);
+}
+
+/* direct calculation functions for smaller dimensions to speed up indexing
+
+N_MPVQ(1,k) = 1;
+N_MPVQ(2,k) = k*2;
+N_MPVQ(3,k) = 1+2*(k^2);
+N_MPVQ(4,k) = k/3 * 4*(k^2+2);
+N_MPVQ(5,k) = 1 + 2*(k*k*(5+k*k))/3;
+N_MPVQ(*,k) = iterations = 1 + A(n,k) + A(n+1,k);
+
+N_PVQ(n,k) = 2*N_MPVQ(n,k);
+
+
+A(1,k) = 1;
+A(2,k) = -1 + 2k;
+A(3,k) = 1+2(k-1)k;
+A(4,k) = 1/3*(((4k-6)k+8)*k-3),
+A(5,k) = 1/3*(3+ k(10+2(k-2)k)k-8);
+A(*,k) = recursive iterations;
+
+
+U(n,k) = (A(n,k)-1)/2;
+U(1,k) = 0;
+U(2,k) = k-1;
+U(3,k) = k*(k-1)
+U(4,k) = (1/3)*((k - 1)*(2*k^2 - k + 3))
+U(5,k) = (1/3)*(k*(k - 1)*(k^2 - k + 4))
+U(*,k) = recursive iterations;
+
+U(n,k) = U(k,n);
+U(n,k) = func(n, U(n,k-1), U(n,k-2) , 1/(k-1) );
+U(n,k) = 1 + U(n-1,k-1) + U(n-1,k) + U(n,k-1);
+U(n,k) = 1 + A(n-1,k-1)>>1 + A(n-1,k)>>1 + A(n,k-1)>>1; A(n,k) is always odd if k>0
+*/
+
+/*-------------------------------------------------------------------*
+ * a_three_fx()
+ *-------------------------------------------------------------------*/
+static
+UWord32 a_three_fx( /* o: offset for dim 3 */
+ UWord32 k_val /* i: nb unit pulses */
+) /* k_val may be higher than 16 bit signed */
+{
+ IF( k_val )
+ {
+ /* return (ONE_U + k_val*((k_val - ONE_U) << ONE)); */
+ return UL_addNsD(1U,UL_Mpy_32_32(k_val,UL_lshl(UL_subNsD(k_val,1U),1)));
+ }
+ ELSE
+ {
+ return 0;
+ }
+}
+
+/*-------------------------------------------------------------------*
+ * a_four_fx()
+ *-------------------------------------------------------------------*/
+static
+UWord32 a_four_fx( /* o: offset for dim 4 */
+ UWord32 k_val /* i: nb unit pulses */
+)
+{
+ UWord32 UL_2k;
+ IF(k_val)
+ {
+ /* return UDIVBY3*((k_val<0,k=0) */
+ h_mem[1] = UL_deposit_l(1); /* A(*,k=1) */
+
+ UL_k_val_in = UL_deposit_l(k_val_in);
+ IF(EQ_16(dim_in,2))
+ {
+ FOR( k_val = 2 ; k_val <= UL_k_val_in ; k_val++ )
+ {
+ h_mem[k_val] = UL_subNsD(UL_lshl(k_val,1),1U);
+ move32(); /* A(2, 2 .. k ) */
+ }
+ h_mem[k_val] = UL_k_val_in;
+ move32(); /* U(2,k+1) */
+ }
+ ELSE
+ {
+ k_val_prev = UL_deposit_l(1U);
+ FOR(k_val_curr = 2; k_val_curr<=UL_k_val_in; k_val_curr++)
+ {
+ h_mem[k_val_curr] = UL_addNsD(1U , UL_Mpy_32_32(k_val_curr, UL_lshl(k_val_prev,1)));
+ move32();
+ k_val_prev = UL_addNsD(k_val_curr, 0U); /* 1 op*/
+ }
+ h_mem[k_val_curr] = UL_Mpy_32_32(k_val_curr,k_val_prev);
+ move32(); /* % U(3,k_val_in+1) u_three(k+1) */
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * a_fwd_fx()
+ *
+ * create offsets for A(n,k) from lower A(n-1,k)
+ *-------------------------------------------------------------------*/
+static
+void a_fwd_fx(
+ UWord32 *a_in, /* i/o: offsets */
+ Word16 n_items /* i : items, k's */
+)
+{
+ UWord32 a_1, a_in0 ;
+ Word16 i ;
+ UWord32* a_in_prev_ptr;
+
+ a_in0 = UL_deposit_l(1);
+
+ a_in_prev_ptr=&(a_in[-1]); /* single loop ptr setup not counted; */
+ FOR(i=1; i<=n_items; i++) /* basic A fwd row recursion */
+ {
+ a_1 = UL_addNsD(a_in0, UL_addNsD(a_in_prev_ptr[i], a_in[i])) ;
+ a_in_prev_ptr[i] = a_in0;
+ move32();
+ a_in0 = UL_addNsD(a_1, 0U);
+ }
+ a_in_prev_ptr[i] = a_in0;
+ move32();
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * a_bwd_fx()
+ *
+ * create offsets for A(n,k) from higher A(n+1,k)
+ *-------------------------------------------------------------------*/
+static
+void a_bwd_fx(
+ UWord32 *a_in, /* i/o: offsets */
+ Word16 n_items /* i: n_items */
+)
+{
+ UWord32 a_1, a_in0;
+ Word16 i;
+ UWord32* a_in_prev_ptr;
+
+ a_in0 = UL_deposit_l(0);
+ a_in_prev_ptr = &(a_in[-1]);
+
+ FOR(i = 1; i<=n_items; i++) /*basic A reverse row recursion */
+ {
+ /* 2x[i] ptr memory access below are treated as ptr access */
+ a_1 = UL_subNsD(UL_subNsD(a_in[i], a_in0), a_in_prev_ptr[i]);
+ a_in_prev_ptr[i] = a_in0;
+ move32();
+ a_in0 = UL_addNsD(a_1, 0U);
+
+ }
+ a_in_prev_ptr[i] = a_in0;
+ move32();
+ return;
+}
+
+static
+UWord32 direct_row_A2U_rec_calc_fx(Word16 dim_in , Word16 k_val_in, UWord32 a_km2, UWord32 a_km1)
+{
+ /* U(n,k) = (A(n,k-2)-1)/2 + ((2*n-1)*A(n,k-1) - A(n,k-2) )/2*(k-1) */
+ /* U(n,k) = floor(A(n,k-2)/2) + (n*A(n,k-1) - floor(A(n,k-1)/2) - floor(A(n,k-2)/2) +1 )/(k-1) */
+ /* U(n,k) = floor(A(n,k-2)/2) + (n*A(n,k-1) - (floor(A(n,k-1)/2) + floor(A(n,k-2)/2) +1) )/(k-1) */
+
+ UWord32 km2_size, UL_um2, UL_dim ;
+ Word16 divisor;
+
+ divisor = sub(k_val_in,1);
+ UL_um2 = UL_lshr(a_km2,1U);
+ UL_dim = UL_deposit_l(dim_in);
+ km2_size = UL_addNsD(UL_addNsD(UL_lshr(a_km1,1), UL_um2), 1U);
+ IF(s_and(divisor,0x1) != 0)
+ {
+ /* odd */
+ return UL_addNsD(UL_um2, f_odd_exact_div_opt_fx( UL_dim, a_km1, km2_size, shr(divisor,1)));
+ }
+ ELSE
+ {
+ /* even divisor, */
+ return UL_addNsD(UL_um2, f_even_exact_div_opt_fx(UL_dim, a_km1, km2_size, divisor));
+ }
+}
+
+static
+void a_u_fwd_fx(UWord32 *a_u_in,
+ Word16 k_val_in,
+ Word16 mem_size_m1)
+{
+ UWord32 u_kp1_prev, u_kp1;
+ UWord32 u_k_prev ;
+
+ u_kp1_prev = a_u_in[mem_size_m1];
+ move32(); /* previous n U (n,k+1) value*/
+ u_k_prev = UL_lshr(a_u_in[k_val_in],1); /* previous n A(n,k) value*/
+
+ a_fwd_fx(&a_u_in[1], k_val_in); /* a_u_in[k==ZERO] = zero if n>0 */
+
+ /* low dynamic last offset entry mixed recursion */
+ /* used for size calculation */
+ /* U(n,k+1) = 1 + U(n-1,k+1) + U(n-1,k) + U(n,k) */
+ /* U(n,k+1) = 1 + U(n-1,k+1) + (A(n-1,k)-1)/2 + (A(n,k)-1)/2 */
+ /* Note, A(n,k) always odd for k>0 , subtracted one always shifted out */
+
+ u_kp1 = UL_lshr(a_u_in[k_val_in],1);
+ a_u_in[mem_size_m1] = UL_addNsD(1U, UL_addNsD(u_kp1_prev, UL_addNsD(u_k_prev,u_kp1)));
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * nm_h_prep_opt_fx()
+ *
+ * find and return N_MPVQ(n,k) and also offsets A(n, 0 to k ) and U(n,k+1).
+ *-------------------------------------------------------------------*/
+static
+UWord32 nm_h_prep_opt_fx( /* o: msize for dim */
+ Word16 dim_in, /* i: dimension */
+ Word16 k_val_in, /* i: nb unit pulses */
+ UWord32 *h /* o: A/U offsets array */
+)
+{
+ Word16 mem_size_m1, k_val,tmp ;
+ Word16 dim_tmp, d_start;
+ UWord32 h_saveA, h_saveB, u_kp1,a_k; /* registers for alternating A(n,k-1), A(n,k-2)*/
+ UWord32 numDsub1;
+ Word16 end_loop, add_last_odd ;
+
+ h[0] = UL_deposit_l(0); /* % A(=>0,k=0) */
+ h[1] = UL_deposit_l(1); /* % A(*,k=1) */
+
+ mem_size_m1 = add(k_val_in,1);
+
+ assert(dim_in > N_OPT_FX); /* code now optimized with direct functions for dim <= N_OPT_FX ) */
+ IF( (GT_16(k_val_in, TABLE_LIM_OPT_FX)))
+ {
+ d_start = 2;
+ move16();
+ if( GE_16(dim_in,3))
+ {
+ /* start from A(3), U(3) */
+ d_start = 3;
+ move16(); /* single op */
+ }
+ initOffsets_fx(d_start, h, k_val_in);
+ FOR(dim_tmp = d_start; dim_tmp < dim_in; dim_tmp++)
+ {
+ a_u_fwd_fx(h, k_val_in, mem_size_m1);
+ }
+ a_k = h[k_val_in];
+ move32();
+ u_kp1 = h[mem_size_m1];
+ move32();
+ }
+ ELSE
+ {
+ numDsub1 = UL_deposit_l(sub(shl(dim_in,1),1));
+ h[2] = numDsub1;
+ move32();
+
+ /* interleaved " odd, even [odd]" divisor calls */
+ h_saveA = numDsub1;
+ move32();
+ h_saveB = UL_deposit_l(1);
+
+ /* OPT: makes sure that the STL FOR loop is not broken */
+ tmp = sub(k_val_in,3);
+ add_last_odd = 0;
+ move16() ; /*k_val_in=0 1 2*/
+ if(tmp == 0)
+ {
+ add_last_odd = 1;
+ move16(); /*k_val_in =3 */
+ }
+ k_val = 3;
+ move16();
+ IF( tmp > 0 )
+ {
+ /* k_val_in = 3,4, 5,6, 7 ... */
+ end_loop = mem_size_m1;
+ move16();
+ add_last_odd = s_and(k_val_in,0x1) ;
+ move16(); /* odd -> 0x00100*/
+ /* even loop limits, and odd tail exists , and */
+ if(NE_16(add_last_odd,0))
+ {
+ end_loop = sub(end_loop,1); /* make initial loop to even number of (odd-even )pairs *//* one basicop */
+ }
+ FOR(k_val = 3; k_val < end_loop ; k_val++ )
+ {
+ /* the optimized non broken loop k=(3,4)(5,6)...(odd,even)*/
+ /* A(n,k) = A(n,k-2) + ((2*n-1)*A(n,k-1)-A(n,k-2)) /(k-1) */
+ /* first odd k, even divisor */
+ h_saveB = UL_addNsD(h_saveB, f_even_exact_div_opt_fx(numDsub1, h_saveA, h_saveB, sub(k_val,1)));
+ h[k_val] = h_saveB;
+ move32();
+
+ /* next even k, odd divisor */
+ /*k_val++; */
+ h_saveA = UL_addNsD(h_saveA, f_odd_exact_div_opt_fx(numDsub1, h_saveB, h_saveA,shr(k_val,1)));
+ k_val++; /* ptr incr */
+ h[k_val] = h_saveA;
+ move32();
+ }
+ }
+
+ if(NE_16(add_last_odd,0))
+ {
+ /* add a last odd call as needed , not to be called if k_val_in is [0,1,2] */
+ h_saveB = UL_addNsD(h_saveB,f_even_exact_div_opt_fx(numDsub1, h_saveA, h_saveB, sub(k_val,1)));
+ h[k_val_in] = h_saveB;
+ move32();
+ }
+
+ /* always do the last (k+1) recursion based on U(n,k+1) = func( A(n-2,k+1), A(n-1,k+1) ) */
+ a_k = h[k_val_in] ;
+ move32();
+ u_kp1 = direct_row_A2U_rec_calc_fx(dim_in, mem_size_m1 , h[sub(mem_size_m1,2)], a_k );
+ h[mem_size_m1] = u_kp1;
+ move32();
+ }
+
+ /* N_MPVQ(n,k) = 1 + U(n,k+1) + U(n,k) = 1 + U(n,k+1) + floor(A(n,k))/2) ; */ /* as A(n,k) always odd */
+ return ( UL_addNsD(1U, UL_addNsD(u_kp1, UL_lshr(a_k,1))));
+}
+
+/*
+ find_amp_split_offset_func_mem_fx()
+ find first offset in range 0..k_val_in that is less than ind_in
+ using a tree search with direct function calls [ or memory iteration]
+*/
+static
+Word16 find_amp_split_offset_func_mem_fx( /* o: found k_value */
+ UWord32 ind_in,
+ Word16 high, /* i: k_val_in (high bound) */
+ H_FUNCM h_func_ptr, /* i: offset function pointer */
+ UWord32 *UL_tmp_offset) /* o: offset found */
+{
+ Word16 not_ready, low, k_test=0;
+ UWord16 sgn ;
+ UWord32 UL_tmp;
+ /* split over A(n,k) = h_mem(k), or use direct A function evaluation */
+
+ low = 0;
+ move16();
+ move32(); /* account for adaptive function ptr setup */
+ not_ready = 1 ;
+ move16();
+
+ WHILE( not_ready != 0)
+ {
+ k_test = shr(add(low,high),1); /*% split range in half */
+ *UL_tmp_offset = (*h_func_ptr)(UL_deposit_l(k_test)); /* call direct A offset-function */
+
+ UL_tmp = UL_subNs(*UL_tmp_offset, ind_in, &sgn );
+ IF ( sgn )
+ {
+ /* (*tmp_offset < ind_in) */
+ low = add(1, k_test) ;
+ if( GE_16(k_test ,high))
+ {
+ not_ready = 0;
+ move16(); /* single basicop */
+ }
+ }
+ ELSE
+ {
+ /* (ind_in <= *tmp_offset ) */
+ high = sub(k_test,1);
+ if( UL_tmp == 0)
+ {
+ /* (*tmp_offset == ind_in) */
+ not_ready = 0;
+ move16(); /* single basicop */
+ }
+ }
+ }
+ return k_test;
+}
+
+/*
+ get_lead_sign_fx()
+ updated index and return leading sign
+*/
+static
+Word16 get_lead_sign_fx(UWord32 *ind)
+{
+ Word16 leading_sign;
+
+ leading_sign = 1;
+ move16();
+ if( UL_and(*ind,1) != 0 )
+ {
+ /* leading sign stored in LSB */
+ leading_sign = -1;
+ move16();
+ }
+ (*ind) = UL_lshr(*ind,1);
+
+ return leading_sign;
+}
+
+/*-------------------------------------------------------------------*
+ * mind2vec_one_fx()
+ *-------------------------------------------------------------------*/
+static
+void mind2vec_one_fx(
+ Word16 k_val_in, /* i: nb unit pulses */
+ Word16 leading_sign, /* i: leading sign -1, 0, 1*/
+ UWord32 ind, /* i: index */ /* parameter needed as it is used in a function array */
+ Word16* vec_out /* o: pulse train */
+)
+{
+ /* NB input k_val_in can be zero */
+ /* *vec_out = leading_sign*k_val_in; */
+ *vec_out = (Word16)ind; /* dummy assignment to avoid gcc "unused parameter" warning for ind, i.e no move16() needed */
+
+ /* *vec_out = extract_l(L_mult0(leading_sign,k_val_in)); move16(); // 3 ops */
+ if( leading_sign < 0 )
+ {
+ k_val_in = negate(k_val_in); /* single basicop --> if */
+ }
+ *vec_out = k_val_in;
+ move16(); /* 1 op */
+}
+
+static
+void mind2vec_two_fx(
+ Word16 k_val_in, /* i: nb unit pulses */
+ Word16 leading_sign, /* i: leading sign -1,0, 1 */
+ UWord32 ind_in, /* i: index */
+ Word16 *vec_out /* o: pulse train */
+)
+{
+ UWord32 UL_ind_tmp;
+ Word16 val1;
+
+ IF (ind_in == 0)
+ {
+ /* ind_in == 0 */
+ mind2vec_one_fx( k_val_in,leading_sign,ind_in,vec_out);
+ }
+ ELSE IF ( EQ_16((Word16)u_extract_l(ind_in), sub(shl(k_val_in,1),1)))
+ {
+ /* signed ops fine as 2*KMAX << 32767) */
+ /* (ind_in == ( (unsigned int)(k_val_in<dim; i++)
+ {
+ vec_out[i]=0;
+ move16(); /* set all of short vector to zero , required for fast/early exit logic */
+ }
+
+ leading_sign = 1;
+ move16();
+ if(entry->lead_sign_ind != 0)
+ {
+ leading_sign = -1;
+ move16();
+ }
+
+ IF(entry->k_val != 0)
+ {
+ IF(GT_16(entry->dim,N_OPT_FX)) /* N_OPT_FX */
+ {
+ /* generic */
+ mind2vec_fx(entry->dim, entry->k_val, leading_sign, entry->index, vec_out, h_mem);
+ }
+ ELSE
+ {
+ /* specialized functions, with direct offset calculations */
+ (mind2vec_f_fx[entry->dim])(entry->k_val, leading_sign, entry->index, vec_out);
+ }
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+* vec2mind_one_fx()
+*-------------------------------------------------------------------*/
+static
+void vec2mind_one_fx(
+ const Word16* vec_in, /* i : PVQ pulse train */
+ Word16 *k_val_out_ptr , /* o : number of unit pulses */ /* parameter needed as it is used in a function array */
+ UWord32 *next_sign_ind, /* i/o: next sign ind */
+ UWord32* ind /* o: MPVQ index */
+)
+{
+ *ind = (Word32)(*k_val_out_ptr) ; /* dummy assignment to avoid gcc "unused parameter" warning for *k_val_out_ptr, i.e no move32 needed() */
+ *ind = UL_deposit_l(0);
+
+ *next_sign_ind = UL_deposit_l(0);
+ if( *vec_in < 0 )
+ {
+ *next_sign_ind = UL_deposit_l(1); /*single basicop */
+ }
+ return ;
+}
+
+/*-------------------------------------------------------------------*
+* vec2mind_two_fx()
+*-------------------------------------------------------------------*/
+static
+void vec2mind_two_fx(
+ const Word16* vec_in, /* i : PVQ pulse train */
+ Word16 *k_val_out_ptr , /* o : number of unit pulses */
+ UWord32 *next_sign_ind, /* i/o: next sign ind */
+ UWord32* ind /* o: MPVQ index */
+)
+{
+ UWord32 lead_sign_ind_add;
+ Word16 abs0,abs1,abs01,sptr;
+
+ abs0 = abs_s(vec_in[0]);
+ abs1 = abs_s(vec_in[1]);
+ abs01 = add(abs0, abs1);
+ *k_val_out_ptr = abs01;
+ move16(); /* can be zero */
+ *ind = UL_deposit_l(0); /* [KMAX 0 ] , and dual zeros */
+
+ *next_sign_ind = UL_deposit_h(SIGNBIT_SHRT_FX); /* "unset" sign flag set */ /* dual zeroes can happen in a recursive encoding call */
+
+
+ IF( abs01 != 0 )
+ {
+ sptr = 0;
+ move16(); /*used as ptr to vec0 or vec1 value */
+ *next_sign_ind = UL_deposit_l(sptr);
+
+ test();
+ IF(abs0 != 0 && abs1 != 0 )
+ {
+ /* likely most frequent/common case */
+ /* [ KMAX-1 1],[ KMAX-1 -1] ... [ 1 +(KMAX-1) ],[ 1 -(KMAX-1)] */
+ /* sign always shifted to first pos */
+ lead_sign_ind_add = UL_deposit_l(1) ;
+ if( vec_in[1] < 0)
+ {
+ lead_sign_ind_add = UL_deposit_l(2); /* single op */
+ }
+ *ind = UL_addNsD(UL_deposit_l((UWord16)lshl(sub(abs1,1),1)),lead_sign_ind_add);
+ }
+ ELSE
+ {
+ /* one value is a zero */
+ IF( abs0 == 0 )
+ {
+ /* [ 0 KMAX]*/
+ *ind = UL_deposit_l((UWord16) sub(lshl(abs1,1),1));
+ sptr = 1;
+ move16();
+ }
+ }
+
+ /* *next_sign_ind= (unsigned int)(vec_in[*next_sign_ind]<0); */
+ if( vec_in[sptr] < 0 )
+ {
+ *next_sign_ind = UL_deposit_l(1); /*single instruction */
+ }
+ }
+ return;
+}
+
+static
+void enc_push_sign(Word16 val, UWord32* next_sign_ind, UWord32 *index)
+{
+ /*
+ % Check if the leading sign 'bit' is to be added
+ % here the leading sign bit is put in LSB as it saves about 3 cycles in sign-decoding
+ % (one can also put it in the MSB , but then one needs to access h_mem twice and shift the sign bit into position )
+ */
+ test();
+ IF( (UL_and(*next_sign_ind,SIGNBIT_FX) == 0) && (val != 0))
+ {
+ *index = UL_addNsD(UL_lshl(*index,1),*next_sign_ind);
+ }
+
+ /* push sign to next non_zero position */
+ /* *next_sign_ind = *next_sign_ind ;*/ /* default is to keep stored sign index */
+ if( val < 0 )
+ {
+ *next_sign_ind = UL_deposit_l(1); /* single basicop */
+ }
+ if( val > 0)
+ {
+ *next_sign_ind = UL_deposit_l(0); /* single basicop */
+ }
+}
+
+/*-------------------------------------------------------------------*
+ * vec2mind_gen345_fx( vec_in kval, next_dim_func , offset_func,....)
+ * generic call saves PROM ,
+ *-------------------------------------------------------------------*/
+
+static
+void vec2mind_gen345_fx(
+ const Word16* vec_in, /* i : PVQ abs pulse train */
+ Word16 *k_val_out_ptr, /* o : number of unit pulses */
+ UWord32 *next_sign_ind , /* i/o: next sign ind */
+ UWord32* index , /* o: MPVQ index */
+ VEC2INDFUNCM vec2indfunc_ptr, /* i: */
+ H_FUNCM a_func_ptr /*i: offset function */
+)
+{
+ Word16 tmp_val;
+
+ tmp_val = vec_in[0];
+ move16();
+ move32(); /* adaptive function call setup */
+ (*vec2indfunc_ptr)(&vec_in[1], k_val_out_ptr, next_sign_ind, index);
+
+ enc_push_sign(tmp_val, next_sign_ind, index);
+
+ move32(); /* adaptive function call setup */
+ *index = UL_addNsD(*index,(*a_func_ptr)(UL_deposit_l(*k_val_out_ptr)));
+
+ *k_val_out_ptr = add(*k_val_out_ptr, abs_s(tmp_val));
+
+ return ;
+}
+
+/*-------------------------------------------------------------------*
+ * vec2mind_three_fx()
+ *-------------------------------------------------------------------*/
+static
+void vec2mind_three_fx(
+ const Word16* vec_in, /* i : PVQ pulse train */
+ Word16* k_val_out_ptr, /* o : number of unit pulses */
+ UWord32 *next_sign_ind, /* i/o: next sign ind */
+ UWord32 *index /* o: MPVQ index */
+)
+{
+ vec2mind_gen345_fx(vec_in,k_val_out_ptr, next_sign_ind, index, vec2mind_two_fx, a_three_fx);
+ return ;
+}
+
+
+/*-------------------------------------------------------------------*
+ * vec2mind_four_fx()
+ *-------------------------------------------------------------------*/
+static
+void vec2mind_four_fx(
+ const Word16* vec_in, /* i : PVQ pulse train */
+ Word16* k_val_out_ptr, /* o : number of unit pulses */
+ UWord32* next_sign_ind , /* i/o: next sign ind */
+ UWord32* index /* o: MPVQ index */
+)
+{
+ vec2mind_gen345_fx(vec_in, k_val_out_ptr, next_sign_ind, index, vec2mind_three_fx, a_four_fx);
+ return ;
+}
+
+/*-------------------------------------------------------------------*
+ * vec2mind_five_fx()
+ *-------------------------------------------------------------------*/
+static
+void vec2mind_five_fx(
+ const Word16* vec_in, /* i : PVQ abs pulse train */
+ Word16 *k_val_out_ptr, /* o : number of unit pulses */
+ UWord32 *next_sign_ind , /* i/o: next sign ind */
+ UWord32* index /* o: MPVQ index */
+)
+{
+ vec2mind_gen345_fx(vec_in,k_val_out_ptr, next_sign_ind, index, vec2mind_four_fx, a_five_fx);
+ return ;
+}
+
+/*-------------------------------------------------------------------*
+* vec2mind_fx()
+*-------------------------------------------------------------------*/
+static
+void vec2mind_fx(Word16 dim_in, /* i : dim */
+ Word16 k_val_in, /* i : number of unit pulses */
+ const Word16* vec_in, /* i : PVQ pulse train */
+ UWord32 *next_sign_ind, /* o : pushed leading sign */
+ UWord32 *index , /* o : MPVQ index */
+ UWord32 *N_MPVQ_ptr, /* o : size(N_MPVQ(dim,K_val_in))*/
+ UWord32* h_mem) /* o : offsets */
+{
+ Word16 pos, mem_size_m1, k_val_acc, tmp_val;
+ UWord32 tmp_h;
+
+ /*
+ %% main steps
+ % quick encode two rightmost pos
+ % for every position from dim-3 to 0 (right to left)
+ % check if an sign is to be encoded ,
+ % add its offset
+ % check(and add) amplitude offset(for accumulated pulse sum) up to this point
+ % update total pulse sum
+ % update offset vector recursively (except for pos==0 )
+ % end
+ % calculate size
+ */
+
+ mem_size_m1 = add(k_val_in,1);
+ *next_sign_ind = UL_deposit_h(SIGNBIT_SHRT_FX); /* highest bit set signals no sign found yet, should always be 0 or 1 out, */
+
+ pos = sub(dim_in,2); /* adress 2nd last sample */
+ vec2mind_two_fx(&vec_in[pos],&k_val_acc,next_sign_ind ,index);
+ initOffsets_fx( 3, h_mem, k_val_in) ; /* start recursions at 3rd sample */
+
+ tmp_h = h_mem[k_val_acc];
+ move32();
+ FOR (pos--; pos>=0; pos--)
+ {
+ tmp_val = vec_in[pos];
+ move16();
+ enc_push_sign(tmp_val, next_sign_ind, index);
+
+ /* now add indexing offset up to this reverse (r_l) accumulated amplitude point */
+ *index = UL_addNsD(*index, tmp_h); /* k_val_acc==0 ==>0 */
+
+ /* k_val_acc = k_val_acc + vec_abs[pos];*/ /* now increase acc k value for next N */
+ k_val_acc = add(k_val_acc, abs_s(tmp_val));
+
+ IF( pos != 0 )
+ {
+ a_u_fwd_fx(h_mem, k_val_in ,mem_size_m1);
+ /* update A(n,k=1:k_val_in) and U(n,k_val_in+1) */
+ /* NB here (k_val_in + 2 elements always has to be updated */
+ }
+ tmp_h = UL_addNsD(h_mem[k_val_acc], 0U);
+ }
+
+ /* size is needed for the subseqent arithmetic encoding/transmission of the index.
+ use relation N_MPVQ(n,K) = 1 + (A(n, K)-1)/2 + U(n, 1 + K)
+ = N_MPVQ(n,K) = 1 + (A(n, K)>>1) + U(n, 1 + K) , as A(n,K) is odd) */
+ *N_MPVQ_ptr = UL_addNsD(1U,UL_addNsD(UL_lshr(tmp_h,1),h_mem[ mem_size_m1]));
+ move32();/* calc total size */
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * mpvq_encode_vec_fx()
+ *
+ * returns struct with lead sign index, MPVQ-index, dim and N_MPVQ size
+ *-------------------------------------------------------------------------*/
+
+PvqEntry mpvq_encode_vec_fx( /* o : leading_sign_index, index, size, k_val */
+ const Word16* vec_in, /* i : signed pulse train */
+ Word16 dim_in, /* i : dimension */
+ Word16 k_val_local /* i : nb unit pulses */
+)
+{
+ PvqEntry result;
+ UWord32 h_mem[ 1 + KMAX_NON_DIRECT_FX + 1 ] ; /* now always assign max offset buffer for dim 6 ,
+ actually only 1+k_val_in+1 needed ) */
+ UWord32 lead_sign_ind;
+
+ VEC2INDFUNCM vec2mind_f[1+N_OPT_FX] = { (VEC2INDFUNCM)NULL, vec2mind_one_fx, vec2mind_two_fx, vec2mind_three_fx, vec2mind_four_fx, vec2mind_five_fx };
+
+ result.k_val = k_val_local;
+ move16();
+ result.dim = dim_in;
+ move16();
+ /* NB , k_val_local may be changed in some sub encoding routines */
+ IF( GT_16(dim_in, N_OPT_FX))
+ {
+ /* use the generic dimension function */
+ vec2mind_fx(dim_in, k_val_local, vec_in, &lead_sign_ind, &result.index, &result.size, h_mem);
+ }
+ ELSE /* if (dim_in<=N_OPT), h_mem not used */
+ {
+ move32(); /* adaptive function ptr setup */
+ (vec2mind_f[dim_in])(vec_in, &k_val_local, &lead_sign_ind, &result.index);
+ result.size = direct_msize_fx(dim_in, k_val_local);
+ }
+ result.lead_sign_ind = u_extract_l(lead_sign_ind);
+
+ return result;
+}
+
+
diff --git a/lib_com/isf_dec_amr_wb_fx.c b/lib_com/isf_dec_amr_wb_fx.c
new file mode 100644
index 0000000000000000000000000000000000000000..0c1f66031b1866fc0e828b259ac2fbbf3797ca5e
--- /dev/null
+++ b/lib_com/isf_dec_amr_wb_fx.c
@@ -0,0 +1,357 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 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.
+
+*******************************************************************************************************/
+
+#include
+#include "options.h" /* Compilation switches */
+#include "cnst.h" /* Common constants */
+#include "rom_com.h" /* Static table prototypes */
+#include "prot_fx2.h" /* Function prototypes */
+
+#ifdef _MSC_VER
+void E_LPC_isf_isp_conversion(const Word16 isf[], Word16 isp[], const Word16 m);
+#endif
+
+
+/*---------------------------------------------------------------------*
+* isf_dec_amr_wb()
+*
+* Decoding of ISF parameters in AMR-WB IO mode
+*---------------------------------------------------------------------*/
+
+void isf_dec_amr_wb_fx(
+ Decoder_State *st, /* i/o: State structure */
+ Word16 *Aq, /* o : quantized A(z) for 4 subframes */
+ Word16 *isf_new, /* o : de-quantized ISF vector */
+ Word16 *isp_new /* o : de-quantized ISP vector */
+)
+{
+ Word16 i;
+ Word16 indice[7];
+ Word32 L_tmp;
+
+ set16_fx(indice, -1, 7);
+
+ /*---------------------------------*
+ * ISF de-quantization of SID frames
+ *---------------------------------*/
+
+ IF(EQ_32(st->core_brate_fx, SID_1k75))
+ {
+
+ indice[0] = (Word16)get_next_indice_fx(st, 6);
+ move16();
+ indice[1] = (Word16)get_next_indice_fx(st, 6);
+ move16();
+ indice[2] = (Word16)get_next_indice_fx(st, 6);
+ move16();
+ indice[3] = (Word16)get_next_indice_fx(st, 5);
+ move16();
+ indice[4] = (Word16)get_next_indice_fx(st, 5);
+ move16();
+
+ disf_ns_28b_fx(indice, isf_new);
+
+ reorder_isf_fx(isf_new, ISF_GAP_FX, M, Fs_2);
+
+ E_LPC_isf_isp_conversion(isf_new, isp_new, M);
+ /* return if SID frame (conversion to A(z) done in the calling function) */
+ return;
+ }
+
+ /*-----------------------------------------------------------------*
+ * ISF de-quantization of all other frames
+ *-----------------------------------------------------------------*/
+
+ IF(EQ_32(st->core_brate_fx, ACELP_6k60))
+ {
+ indice[0] = (Word16)get_next_indice_fx(st, 8);
+ move16();
+ indice[1] = (Word16)get_next_indice_fx(st, 8);
+ move16();
+ indice[2] = (Word16)get_next_indice_fx(st, 7);
+ move16();
+ indice[3] = (Word16)get_next_indice_fx(st, 7);
+ move16();
+ indice[4] = (Word16)get_next_indice_fx(st, 6);
+ move16();
+
+ disf_2s_36b_fx(indice, isf_new, st->mem_AR_fx, st->mem_MA_fx, 1);
+ }
+ ELSE
+ {
+ indice[0] = (Word16)get_next_indice_fx(st, 8);
+ move16();
+ indice[1] = (Word16)get_next_indice_fx(st, 8);
+ move16();
+ indice[2] = (Word16)get_next_indice_fx(st, 6);
+ move16();
+ indice[3] = (Word16)get_next_indice_fx(st, 7);
+ move16();
+ indice[4] = (Word16)get_next_indice_fx(st, 7);
+ move16();
+ indice[5] = (Word16)get_next_indice_fx(st, 5);
+ move16();
+ indice[6] = (Word16)get_next_indice_fx(st, 5);
+ move16();
+
+ disf_2s_46b_fx(indice, isf_new, st->mem_AR_fx, st->mem_MA_fx,1);
+ }
+ reorder_isf_fx(isf_new, ISF_GAP_FX, M, Fs_2);
+ /* convert quantized ISFs to ISPs */
+ E_LPC_isf_isp_conversion(isf_new, isp_new, M);
+
+ /*-------------------------------------------------------------------------------------*
+ * FEC - update adaptive mean ISF vector
+ *-------------------------------------------------------------------------------------*/
+
+ FOR(i = 0; i < M; i++)
+ {
+ /*st->lsf_adaptive_mean[i] = (st->lsfoldbfi1[i] + st->lsfoldbfi0[i] + isf_new[i]) / 3;*/
+ L_tmp = L_mult(st->lsfoldbfi1_fx[i], 10923);
+ L_tmp = L_mac(L_tmp, st->lsfoldbfi0_fx[i], 10923);
+ st->lsf_adaptive_mean_fx[i] = round_fx(L_mac(L_tmp, isf_new[i], 10923));
+ }
+
+ /*-------------------------------------------------------------------------------------*
+ * ISP interpolation
+ * A(z) calculation
+ *-------------------------------------------------------------------------------------*/
+
+ if (st->rate_switching_reset)
+ {
+ /*extrapolation instead of interpolation*/
+ Copy(isp_new, st->lsp_old_fx, M);
+ Copy(isf_new, st->lsf_old_fx, M);
+ }
+
+ /* ISP interpolation and A(z) calculation */
+ int_lsp_fx(L_FRAME, st->lsp_old_fx, isp_new, Aq, M, interpol_isp_amr_wb_fx, 1);
+
+ /*------------------------------------------------------------------*
+ * 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_fx);
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * disf_ns_28b()
+ *
+ * ISF de-quantizer for SID_1k75 frames (only for AMR-WB IO mode)
+ *-------------------------------------------------------------------*/
+
+void disf_ns_28b_fx(
+ Word16 *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */
+ Word16 *isf_q /* o : ISF in the frequency domain (0..6400) */
+)
+{
+ Word16 i;
+
+ FOR(i = 0; i < 2; i++)
+ {
+ isf_q[i] = dico1_ns_28b_fx[indice[0] * 2 + i];
+ move16();
+ }
+
+ FOR(i = 0; i < 3; i++)
+ {
+ isf_q[i + 2] = dico2_ns_28b_fx[indice[1] * 3 + i];
+ move16();
+ isf_q[i + 5] = dico3_ns_28b_fx[indice[2] * 3 + i];
+ move16();
+ }
+
+ FOR(i = 0; i < 4; i++)
+ {
+ isf_q[i + 8] = dico4_ns_28b_fx[indice[3] * 4 + i];
+ move16();
+ isf_q[i + 12] = dico5_ns_28b_fx[indice[4] * 4 + i];
+ move16();
+ }
+
+ FOR(i = 0; i < M; i++)
+ {
+ isf_q[i] = add(isf_q[i], mean_isf_noise_amr_wb_fx[i]);
+ move16();
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * disf_2s_46b()
+ *
+ * ISF de-quantizer for 46b. codebooks (only for AMR-WB IO mode)
+ *-------------------------------------------------------------------*/
+
+void disf_2s_46b_fx(
+ Word16 *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */
+ Word16 *isf_q, /* o : quantized ISFs in the cosine domain */
+ Word16 *mem_AR, /* o : quantizer memory for AR model */
+ Word16 *mem_MA, /* i/o: quantizer memory for MA model */
+ const Word16 enc_dec /* i : encoder (0), decoder (1) G722.2 FER */
+)
+{
+ Word16 i;
+
+ IF(enc_dec != 0) /* Redirection for G722.2 compatibility */
+ {
+ i = 0;
+ move16();
+ WHILE(NE_16(Indirect_dico1[i], indice[0]))
+ {
+ i = add(i, 1);
+ }
+ indice[0] = i;
+ move16();
+ }
+
+ FOR(i = 0; i < 9; i++)
+ {
+ isf_q[i] = dico1_isf_fx[indice[0] * 9 + i];
+ move16();
+ }
+
+ FOR(i = 0; i < 7; i++)
+ {
+ isf_q[i + 9] = dico2_isf_fx[indice[1] * 7 + i];
+ move16();
+ }
+
+ FOR(i = 0; i < 3; i++)
+ {
+ isf_q[i] = add(isf_q[i], dico21_isf_46b_fx[indice[2] * 3 + i]);
+ move16();
+ isf_q[i + 3] = add(isf_q[i + 3], dico22_isf_46b_fx[indice[3] * 3 + i]);
+ move16();
+ isf_q[i + 6] = add(isf_q[i + 6], dico23_isf_46b_fx[indice[4] * 3 + i]);
+ move16();
+ isf_q[i + 9] = add(isf_q[i + 9], dico24_isf_46b_fx[indice[5] * 3 + i]);
+ move16();
+ }
+
+ FOR(i = 0; i < 4; i++)
+ {
+ isf_q[i + 12] = add(isf_q[i + 12], dico25_isf_46b_fx[indice[6] * 4 + i]);
+ move16();
+ }
+
+ FOR(i = 0; i < M; i++)
+ {
+ mem_AR[i] = add(isf_q[i], mult_r(MU_MA_FX, mem_MA[i]));
+ move16(); /* Update with quantized ISF vector for AR model */
+ mem_MA[i] = isf_q[i];
+ move16(); /* Update with quantized prediction error for MA model */
+ isf_q[i] = add(mem_AR[i], mean_isf_amr_wb_fx[i]);
+ move16(); /* Quantized ISFs */
+ }
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * disf_2s_36b()
+ *
+ * ISF de-quantizer for 36b. codebooks (only for AMR-WB IO mode)
+ *-------------------------------------------------------------------*/
+
+void disf_2s_36b_fx(
+ Word16 *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */
+ Word16 *isf_q, /* o : quantized ISFs in the cosine domain */
+ Word16 *mem_AR, /* i/o: quantizer memory for AR model */
+ Word16 *mem_MA, /* i/o: quantizer memory for MA model */
+ const Word16 enc_dec /* i : encoder (0), decoder (1) G722.2 FER */
+)
+{
+ Word16 i;
+ const Word16 *pt_dico1;
+
+ IF(enc_dec != 0) /* Redirection for G722.2 interoperability */
+ {
+ i = 0;
+ move16();
+ WHILE(NE_16(Indirect_dico1[i], indice[0]))
+ {
+ i = add(i, 1);
+ }
+ indice[0] = i;
+ move16();
+ }
+
+
+ pt_dico1 = dico1_isf_fx; /* Pointer of the 1st stage, 1st plit */
+
+ FOR(i = 0; i < 9; i++)
+ {
+ isf_q[i] = pt_dico1[indice[0] * 9 + i];
+ move16();
+ }
+
+ FOR(i = 0; i < 7; i++)
+ {
+ isf_q[i + 9] = dico2_isf_fx[indice[1] * 7 + i];
+ move16();
+ }
+
+ FOR(i = 0; i < 5; i++)
+ {
+ isf_q[i] = add(isf_q[i], dico21_isf_36b_fx[indice[2] * 5 + i]);
+ move16();
+ }
+
+ FOR(i = 0; i < 4; i++)
+ {
+ isf_q[i + 5] = add(isf_q[i + 5], dico22_isf_36b_fx[indice[3] * 4 + i]);
+ move16();
+ }
+
+ FOR(i = 0; i < 7; i++)
+ {
+ isf_q[i + 9] = add(isf_q[i + 9], dico23_isf_36b_fx[indice[4] * 7 + i]);
+ move16();
+ }
+
+ FOR(i = 0; i < M; i++)
+ {
+ mem_AR[i] = add(isf_q[i], mult_r(MU_MA_FX, mem_MA[i]));
+ move16(); /* Update with quantized ISF vector for AR model */
+ mem_MA[i] = isf_q[i];
+ move16(); /* Update with quantized prediction error for MA model */
+ isf_q[i] = mem_AR[i] + mean_isf_amr_wb_fx[i];
+ move16(); /* Quantized ISFs */
+ }
+
+ return;
+}
diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h
index 7dbe1f64a88dcf2038112387d7cff3f3cbede05c..7af0edb72e4e61e638b949db0e6ba68f913a9835 100644
--- a/lib_com/ivas_prot.h
+++ b/lib_com/ivas_prot.h
@@ -404,7 +404,7 @@ void copy_decoder_config(
);
void destroy_core_dec(
- DEC_CORE_HANDLE_FLOAT hCoreCoder /* i/o: core decoder structure */
+ DEC_CORE_HANDLE hCoreCoder /* i/o: core decoder structure */
);
void ivas_destroy_dec(
@@ -773,7 +773,7 @@ float rand_triangular_signed(
int16_t *seed );
void dtx_read_padding_bits(
- DEC_CORE_HANDLE_FLOAT st,
+ DEC_CORE_HANDLE st,
const int16_t num_bits
);
@@ -1022,7 +1022,7 @@ ivas_error ivas_ism_metadata_dec(
const PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i : Param ISM Config Handle */
int16_t *ism_extended_metadata_flag, /* i/o: Extended metadata active in renderer */
int16_t *ism_extmeta_cnt, /* i/o: Number of change frames observed */
- DEC_CORE_HANDLE_FLOAT st0 /* i : core-coder handle */
+ DEC_CORE_HANDLE st0 /* i : core-coder handle */
);
diff --git a/lib_com/lag_wind.c b/lib_com/lag_wind.c
index fdaa4a7a7c4d6560bcfde0820a9a264d67479915..12ecb3f6cd996f764c4f86b4ead53ffe91f7ca0f 100644
--- a/lib_com/lag_wind.c
+++ b/lib_com/lag_wind.c
@@ -38,6 +38,8 @@
#include
#include "options.h"
#include "prot.h"
+#include "prot_fx1.h"
+#include "prot_fx2.h"
#include "cnst.h"
#include "rom_com.h"
#include "wmc_auto.h"
@@ -46,17 +48,20 @@
* Local constants
*-------------------------------------------------------------------*/
-#define kLagWinThGain1 0.6f
-#define kLagWinThGain2 0.3f
+#define kLagWinThGain1_flt 0.6f
+#define kLagWinThGain2_flt 0.3f
+
+#define kLagWinThGain1 19661 /* 0.6f in Q15 */
+#define kLagWinThGain2 9830 /* 0.3f in Q15 */
/*-------------------------------------------------------------*
- * procedure lag_wind() *
+ * procedure lag_wind_flt() *
* ~~~~~~~~~ *
* lag windowing of the autocorrelations *
*-------------------------------------------------------------*/
-void lag_wind(
+void lag_wind_flt(
float r[], /* i/o: autocorrelations */
const int16_t m, /* i : order of LP filter */
const int32_t sr_core, /* i : sampling rate */
@@ -73,29 +78,29 @@ void lag_wind(
case 8000:
assert( m <= 16 );
assert( strength == LAGW_STRONG );
- wnd = lag_window_8k;
+ wnd = lag_window_8k_flt;
break;
case 12800:
assert( m <= 16 );
- wnd = lag_window_12k8[strength];
+ wnd = lag_window_12k8_flt[strength];
break;
case 16000:
assert( m <= 16 );
- wnd = lag_window_16k[strength];
+ wnd = lag_window_16k_flt[strength];
break;
case 24000:
case 25600:
assert( m <= 16 );
- wnd = lag_window_25k6[strength];
+ wnd = lag_window_25k6_flt[strength];
break;
case 32000:
assert( m <= 16 );
- wnd = lag_window_32k[strength];
+ wnd = lag_window_32k_flt[strength];
break;
case 48000:
assert( m <= 16 );
assert( strength == LAGW_STRONG );
- wnd = lag_window_48k;
+ wnd = lag_window_48k_flt;
break;
default:
assert( !"Lag window not implemented for this sampling rate" );
@@ -111,12 +116,12 @@ void lag_wind(
}
/*-------------------------------------------------------------*
- * procedure adapt_lag_wind()
+ * procedure adapt_lag_wind_fx()
*
*
*-------------------------------------------------------------*/
-void adapt_lag_wind(
+void adapt_lag_wind_fx(
float r[], /* i/o: autocorrelations */
const int16_t m, /* i : order of LP filter */
const int16_t Top, /* i : open loop pitch lags from curr. frame (or NULL if n/a) */
@@ -133,7 +138,7 @@ void adapt_lag_wind(
if ( pitch_lag < 80 )
{
- if ( pitch_gain > kLagWinThGain1 )
+ if ( pitch_gain > kLagWinThGain1_flt )
{
strength = LAGW_STRONG;
}
@@ -144,7 +149,7 @@ void adapt_lag_wind(
}
else if ( pitch_lag < 160 )
{
- if ( pitch_gain > kLagWinThGain2 )
+ if ( pitch_gain > kLagWinThGain2_flt )
{
strength = LAGW_MEDIUM;
}
@@ -158,7 +163,122 @@ void adapt_lag_wind(
strength = LAGW_WEAK;
}
- lag_wind( r, m, sr_core, strength );
+ lag_wind_flt( r, m, sr_core, strength );
return;
}
+
+
+/*-------------------------------------------------------------*
+ * procedure lag_wind: *
+ * ~~~~~~~~~ *
+ * lag windowing of the autocorrelations *
+ *-------------------------------------------------------------*/
+
+void lag_wind(
+ Word16 r_h[], /* in/out: autocorrelations */
+ Word16 r_l[], /* in/out: autocorrelations */
+ Word16 m, /* input : order of LP filter */
+ Word32 sr_core, /* input : sampling rate */
+ Word16 strength /* input : LAGW_WEAK, LAGW_MEDIUM, or LAGW_STRONG */
+)
+{
+ Word16 i;
+ Word32 tmp;
+ const Word16 *wnd_h, *wnd_l;
+
+
+ assert(0 <= strength && strength <= NUM_LAGW_STRENGTHS);
+ SWITCH(sr_core)
+ {
+ case 8000:
+ assert(m <= 16);
+ assert(strength == LAGW_STRONG);
+ wnd_h = lag_window_8k[0];
+ wnd_l = lag_window_8k[1];
+ BREAK;
+ case 12800:
+ assert(m <= 16);
+ wnd_h = lag_window_12k8[strength][0];
+ wnd_l = lag_window_12k8[strength][1];
+ BREAK;
+ case 16000:
+ assert(m <= 16);
+ wnd_h = lag_window_16k[strength][0];
+ wnd_l = lag_window_16k[strength][1];
+ BREAK;
+ case 24000:
+ case 25600:
+ assert(m <= 16);
+ wnd_h = lag_window_25k6[strength][0];
+ wnd_l = lag_window_25k6[strength][1];
+ BREAK;
+ case 32000:
+ assert(m <= 16);
+ wnd_h = lag_window_32k[strength][0];
+ wnd_l = lag_window_32k[strength][1];
+ BREAK;
+ case 48000:
+ assert(m <= 16);
+ assert(strength == LAGW_STRONG);
+ wnd_h = lag_window_48k[0];
+ wnd_l = lag_window_48k[1];
+ BREAK;
+ default:
+ assert(!"Lag window not implemented for this sampling rate");
+ return;
+ }
+
+ FOR(i = 1; i <= m; i++)
+ {
+ tmp = Mpy_32(r_h[i], r_l[i], wnd_h[i - 1], wnd_l[i - 1]);
+ L_Extract(tmp, &r_h[i], &r_l[i]);
+ }
+
+}
+
+void adapt_lag_wind(
+ Word16 r_h[], /* in/out: autocorrelations */
+ Word16 r_l[], /* in/out: autocorrelations */
+ Word16 m, /* input : order of LP filter */
+ const Word16 Top, /* input : open loop pitch lag */
+ const Word16 Tnc, /* input : open loop pitch gain */
+ Word32 sr_core /* input : sampling rate */
+)
+{
+ Word16 strength, pitch_lag;
+ Word16 pitch_gain;
+
+ pitch_lag = Top;
+ move16();
+ pitch_gain = Tnc;
+ move16();
+
+ IF(LT_16(pitch_lag, 80))
+ {
+ strength = LAGW_STRONG;
+ move16();
+ if (LE_16(pitch_gain, kLagWinThGain1))
+ {
+ strength = LAGW_MEDIUM;
+ move16();
+ }
+ }
+ ELSE IF(LT_16(pitch_lag, 160))
+ {
+ strength = LAGW_MEDIUM;
+ move16();
+ if (LE_16(pitch_gain, kLagWinThGain2))
+ {
+ strength = LAGW_WEAK;
+ move16();
+ }
+ }
+ ELSE
+ {
+ strength = LAGW_WEAK;
+ move16();
+ }
+
+ lag_wind(r_h, r_l, m, sr_core, strength);
+}
diff --git a/lib_com/lerp.c b/lib_com/lerp.c
index 60e7bf628e415ed8bef6c440aaee372eb04f9dbb..832217dc63ea3b1a9c0eda2a722dc9150dba44db 100644
--- a/lib_com/lerp.c
+++ b/lib_com/lerp.c
@@ -37,6 +37,8 @@
#include
#include "options.h"
#include "prot.h"
+#include "prot_fx1.h"
+#include "prot_fx2.h"
#include "wmc_auto.h"
@@ -44,16 +46,16 @@
* Local function prototypes
*-------------------------------------------------------------*/
-static void lerp_proc( const float *f, float *f_out, const int16_t bufferNewSize, const int16_t bufferOldSize );
+static void lerp_proc_flt( const float *f, float *f_out, const int16_t bufferNewSize, const int16_t bufferOldSize );
/*-------------------------------------------------------------*
- * procedure lerp() *
+ * procedure lerp_flt() *
* *
* *
*-------------------------------------------------------------*/
-void lerp(
+void lerp_flt(
const float *f,
float *f_out,
const int16_t bufferNewSize,
@@ -75,7 +77,7 @@ void lerp(
tmpNewSize = bufferNewSize;
}
- lerp_proc( f, f_out, tmpNewSize, bufferOldSize );
+ lerp_proc_flt( f, f_out, tmpNewSize, bufferOldSize );
f = f_out;
bufferOldSize = tmpNewSize;
@@ -92,7 +94,7 @@ void lerp(
tmpNewSize = bufferNewSize;
}
- lerp_proc( f, f_out, tmpNewSize, bufferOldSize );
+ lerp_proc_flt( f, f_out, tmpNewSize, bufferOldSize );
f = f_out;
bufferOldSize = tmpNewSize;
@@ -101,19 +103,19 @@ void lerp(
}
else
{
- lerp_proc( f, f_out, bufferNewSize, bufferOldSize );
+ lerp_proc_flt( f, f_out, bufferNewSize, bufferOldSize );
}
return;
}
/*-------------------------------------------------------------*
- * procedure lerp_proc() *
+ * procedure lerp_proc_flt() *
* *
* *
*-------------------------------------------------------------*/
-static void lerp_proc(
+static void lerp_proc_flt(
const float *f,
float *f_out,
const int16_t bufferNewSize,
@@ -181,3 +183,202 @@ static void lerp_proc(
return;
}
+
+
+/*-------------------------------------------------------------*
+ * Local constants
+ *-------------------------------------------------------------*/
+
+#define shift_e (16-1)
+#define pos_e (16-1)
+ /*-------------------------------------------------------------*
+ * Local function prototypes
+ *-------------------------------------------------------------*/
+
+static void lerp_proc(Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOldSize);
+
+/*-------------------------------------------------------------*
+ * procedure lerp() *
+ * *
+ * *
+ *-------------------------------------------------------------*/
+
+void lerp(Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOldSize)
+{
+ Word16 tmp1, tmp2, tmpexp;
+ BASOP_Util_Divide_MantExp(bufferNewSize, 0, bufferOldSize, 0, &tmp1, &tmpexp);
+ tmp1 = shr(tmp1, 3); /*Q12*/
+ tmp1 = shl(tmp1, tmpexp);
+
+ BASOP_Util_Divide_MantExp(bufferOldSize, 0, bufferNewSize, 0, &tmp2, &tmpexp);
+ tmp2 = shr(tmp2, 3); /*Q12*/
+ tmp2 = shl(tmp2, tmpexp);
+ test();
+ test();
+ IF(GT_16(tmp1, 16224 /*3,9609375 in Q12*/))
+ {
+ Word16 tmpNewSize = shl(bufferOldSize, 1);
+ WHILE(GT_16(bufferNewSize, bufferOldSize))
+ {
+ BASOP_Util_Divide_MantExp(bufferNewSize, 0, bufferOldSize, 0, &tmp1, &tmpexp);
+ tmp1 = shr(tmp1, 3); /*Q12*/
+ tmp1 = shl(tmp1, tmpexp);
+ test();
+ IF(LE_16(tmp1, 16224 /*3,9609375 in Q12*/))
+ {
+ tmpNewSize = bufferNewSize;
+ }
+
+ lerp_proc(f, f_out, tmpNewSize, bufferOldSize);
+
+ f = f_out;
+ bufferOldSize = tmpNewSize;
+ tmpNewSize = shl(tmpNewSize, 1);
+ }
+ }
+ ELSE IF(GT_16(tmp2, 16224 /*3,9609375 in Q12*/))
+ {
+ Word16 tmpNewSize = shr(bufferOldSize, 1);
+ WHILE(LT_16(bufferNewSize, bufferOldSize))
+ {
+ BASOP_Util_Divide_MantExp(bufferOldSize, 0, bufferNewSize, 0, &tmp2, &tmpexp);
+ tmp2 = shr(tmp2, 3); /*Q12*/
+ tmp2 = shl(tmp2, tmpexp);
+ test();
+ IF(LE_16(tmp2, 16224 /*3,9609375 in Q12*/))
+ {
+ tmpNewSize = bufferNewSize;
+ }
+
+ lerp_proc(f, f_out, tmpNewSize, bufferOldSize);
+
+ f = f_out;
+ bufferOldSize = tmpNewSize;
+ tmpNewSize = shr(tmpNewSize, 1);
+ }
+ }
+ else
+ {
+ lerp_proc(f, f_out, bufferNewSize, bufferOldSize);
+ }
+}
+/*-------------------------------------------------------------*
+ * procedure lerp_proc() *
+ * *
+ * *
+ *-------------------------------------------------------------*/
+static void lerp_proc(Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOldSize)
+{
+
+ Word16 i, idx, n;
+ Word16 diff;
+ Word32 pos, shift;
+ Word16 buf[2 * L_FRAME_MAX];
+ Word16 *ptr;
+
+ ptr = f_out;
+ test();
+ test();
+ test();
+ if (((f <= f_out) && (f + bufferOldSize >= f_out)) || ((f_out <= f) && (f_out + bufferNewSize >= f)))
+ {
+ ptr = buf;
+ move16();
+ }
+
+ IF(EQ_16(bufferNewSize, bufferOldSize))
+ {
+ Copy(f, f_out, bufferNewSize);
+ return;
+ }
+
+ shift = L_shl(L_deposit_l(div_s(bufferOldSize, shl(bufferNewSize, 4))), 4 - shift_e + 16);
+
+ pos = L_sub(L_shr(shift, 1), 32768l/*1.0f Q15*/);
+
+ /* Adjust interpolation shift to avoid accessing beyond end of input buffer. */
+ if (LT_32(shift, 19661l/*0.3f Q16*/))
+ {
+ pos = L_sub(pos, 8520l/*0.13f Q16*/);
+ }
+
+ assert(pos_e == shift_e);
+
+ /* first point of interpolation */
+ IF(pos < 0)
+ {
+
+ diff = shr(extract_l(pos), 1);
+ /*buf[0]=f[0]+pos*(f[1]-f[0]);*/
+ move16();
+#ifdef BASOP_NOGLOB
+ *ptr++ = add_sat(f[0], msu_r(L_mult(diff, f[1]), diff, f[0]));
+#else
+ *ptr++ = add(f[0], msu_r(L_mult(diff, f[1]), diff, f[0]));
+#endif
+ }
+ ELSE
+ {
+
+ idx = extract_h(pos);
+
+ diff = lshr(extract_l(pos), 1);
+
+ move16();
+#ifdef BASOP_NOGLOB
+ *ptr++ = add_sat(f[idx], msu_r_sat(L_mult(diff, f[idx + 1]), diff, f[idx]));
+#else
+ *ptr++ = add(f[idx], msu_r(L_mult(diff, f[idx + 1]), diff, f[idx]));
+#endif
+ }
+
+ pos = L_add(pos, shift);
+ idx = s_max(0, extract_h(pos));
+
+ n = sub(bufferNewSize, 1);
+ FOR(i = 1; i < n; i++)
+ {
+ diff = lshr(extract_l(pos), 1);
+ if (pos < 0)
+ {
+ diff = sub(16384/*0.5f Q15*/, diff);
+ }
+ move16();
+#ifdef BASOP_NOGLOB
+ *ptr++ = add_sat(f[idx], msu_r_sat(L_mult(diff, f[idx + 1]), diff, f[idx]));
+#else
+ *ptr++ = add(f[idx], msu_r(L_mult(diff, f[idx + 1]), diff, f[idx]));
+#endif
+
+
+
+ pos = L_add(pos, shift);
+ idx = extract_h(pos);
+ }
+
+ /* last point */
+
+ if (GT_32(pos, L_deposit_h(sub(bufferOldSize, 1))))
+ {
+ idx = sub(bufferOldSize, 2);
+ }
+ assert(idx <= 2 * L_FRAME_MAX);
+
+ /* diff = t - point;*/
+ diff = lshr(extract_l(L_shr(L_sub(pos, L_deposit_h(idx)), 1)), 1);
+
+ move16();
+#ifdef BASOP_NOGLOB
+ *ptr++ = add_sat(f[idx], shl_sat(msu_r_sat(L_mult(diff, f[idx + 1]), diff, f[idx]), 1));
+#else
+ *ptr++ = add(f[idx], shl(msu_r(L_mult(diff, f[idx + 1]), diff, f[idx]), 1));
+#endif
+ test();
+ test();
+ test();
+ IF(((f <= f_out) && (f + bufferOldSize >= f_out)) || ((f_out <= f) && (f_out + bufferNewSize >= f)))
+ {
+ Copy(buf, f_out, bufferNewSize);
+ }
+
+}
diff --git a/lib_com/log2.c b/lib_com/log2.c
new file mode 100644
index 0000000000000000000000000000000000000000..424580a0356e032a2ccb31e8ebbd1659383ab8de
--- /dev/null
+++ b/lib_com/log2.c
@@ -0,0 +1,218 @@
+/********************************************************************************
+*
+* File : log2.c
+* Purpose : Computes log2(L_x)
+*
+********************************************************************************
+*/
+
+/*
+********************************************************************************
+* INCLUDE FILES
+********************************************************************************
+*/
+#include "stl.h"
+#include "math_op.h"
+#include
+#include "rom_basic_math.h"
+#include "options.h"
+
+#define LW_SIGN (Word32)0x80000000 /* sign bit */
+#define LW_MIN (Word32)0x80000000
+#define LW_MAX (Word32)0x7fffffff
+
+#define SW_SIGN (Word16)0x8000 /* sign bit for Word16 type */
+#define SW_MIN (Word16)0x8000 /* smallest Ram */
+#define SW_MAX (Word16)0x7fff /* largest Ram */
+
+
+/*
+********************************************************************************
+* PUBLIC PROGRAM CODE
+********************************************************************************
+*/
+
+/*************************************************************************
+ *
+ * FUNCTION: Log2_norm_lc()
+ *
+ * PURPOSE: Computes log2(L_x, exp), where L_x is positive and
+ * normalized, and exp is the normalisation exponent
+ * If L_x is negative or zero, the result is 0.
+ *
+ * DESCRIPTION:
+ * The function Log2(L_x) is approximated by a table and linear
+ * interpolation. The following steps are used to compute Log2(L_x)
+ *
+ * 1- exponent = 30-norm_exponent
+ * 2- i = bit25-b31 of L_x; 32<=i<=63 (because of normalization).
+ * 3- a = bit10-b24
+ * 4- i -=32
+ * 5- fraction = table[i]<<16 - (table[i] - table[i+1]) * a * 2
+ *
+ *************************************************************************/
+Word16 Log2_norm_lc ( /* (o) : Fractional part of Log2. (range: 0<=val<1) */
+ Word32 L_x /* (i) : input value (normalized) */
+)
+{
+ Word16 i, a;
+ Word16 y;
+
+ if (L_x <= 0)
+ L_x = L_deposit_h(0x4000);
+
+ L_x = L_shr (L_x, 9);
+ a = extract_l (L_x); /* Extract b10-b24 of fraction */
+ a = lshr(a, 1);
+
+ i = mac_r(L_x, -32*2-1, 16384); /* Extract b25-b31 minus 32 */
+
+ y = mac_r(L_table_Log2_norm_lc[i], table_diff_Log2_norm_lc[i], a); /* table[i] << 16 - diff*a*2 */
+
+ return y;
+}
+
+Word32 log10_fx(Word32 Linput)
+{
+ Word16 n1, frac, p1, p2, q1;
+ Word32 Ltemp1, Ltemp2;
+ Word32 L_tmp;
+
+ if (Linput<=0) return(LW_MIN);
+ n1=norm_l(Linput);
+ Ltemp1=(Word32)L_shl(Linput,n1);
+
+ Ltemp2=L_mult(extract_h(Ltemp1),0x40);
+ frac=extract_l(Ltemp2);
+
+ p1=log2_tab[sub(extract_h(Ltemp2),0x20)];
+ p2=log2_tab[sub(extract_h(Ltemp2),0x1F)];
+ Ltemp2=L_mult(n1,0x200);
+ n1=extract_l(Ltemp2);
+
+ Ltemp1=L_add(L_deposit_h(p1),0x8000); /* Add rounding bit */
+
+ IF(frac >= 0)
+ {
+ Ltemp1=L_sub(Ltemp1,(Word32)L_mult0(p1,frac));
+ Ltemp1=L_add(Ltemp1,(Word32)L_mult0(p2,frac));
+ }
+ ELSE
+ {
+ L_tmp = L_add(65536,frac);
+ L_tmp = L_tmp*p1;
+ Ltemp1=L_sub(Ltemp1,L_tmp);
+
+ L_tmp = L_add(65536,frac);
+ L_tmp = L_tmp*p2;
+ Ltemp1=L_add(Ltemp1,L_tmp);
+ }
+ q1=extract_h(Ltemp1);
+ Ltemp1=L_mult(q1,0x6054);
+ Ltemp1=L_msu(Ltemp1,0x6054,n1);
+ return(L_shr(Ltemp1,1));
+
+}
+
+Word32 pow_10(Word32 x , Word16 *Q)
+{
+ Word16 xl,xh, t1, t2, n;
+ Word32 Ltemp1;
+ Word32 Lacc;
+ Word32 L_tmp;
+ Word16 n1,i;
+ Word16 count = 0;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+
+ move16();;
+
+ xl=extract_l(x);
+ xh=extract_h(x);
+
+ IF(xl < 0)
+ {
+ L_tmp = L_add(65536,xl);
+ Ltemp1=(Word32) (0x6a4d*L_tmp );
+ }
+ ELSE
+ {
+ Ltemp1=L_mult0(0x6a4d,xl);
+ }
+ Ltemp1=L_add(L_shr(Ltemp1,16),L_shr(L_mult(xh,0x6a4d),1));
+
+
+ Lacc=L_sub(-1L, Ltemp1); /* Lacc=~Lacc, 1's complement */
+ t1=extract_l(L_shr(Lacc,7));
+
+ Ltemp1=L_shr(Ltemp1,7);
+ n1 = extract_h(Ltemp1);
+ n=sub(n1,14);
+ *Q = 14; move16();
+ IF(t1<0)
+ {
+ L_tmp = L_add(65536,t1);
+ t2=extract_h(L_tmp*L_tmp);
+ }
+ ELSE
+ {
+ t2=extract_h(L_mult0(t1,t1));
+ }
+
+ Lacc = L_deposit_h(0x1FEF);
+ IF(t2 < 0)
+ {
+ L_tmp = L_add(65536,t2);
+ Lacc = L_add(Lacc,(Word32)(L_tmp*0x057C));
+ }
+ ELSE
+ {
+ Lacc = L_add(Lacc,(Word32)L_mult0(t2,0x057C));
+ }
+
+ IF(t1 < 0)
+ {
+ L_tmp = L_add(65536,t1);
+ Lacc = L_sub(Lacc,(Word32)(L_tmp*0x155C));
+ }
+ ELSE
+ {
+ Lacc = L_sub(Lacc,(Word32)L_mult0(t1,0x155C));
+ }
+
+ L_tmp = Lacc;
+ FOR(i =1 ;i <= n ;i++)
+ {
+ Overflow = 0; move16();
+#ifdef BASOP_NOGLOB /* Critical Overflow */
+ L_tmp = L_shl_o(L_tmp,i, &Overflow);
+#else
+ L_tmp = L_shl(L_tmp,i);
+#endif
+ IF(Overflow)
+ {
+ count = add(count,1);
+ }
+ }
+ *Q = sub(*Q,count); move16();
+
+ return(L_shl(Lacc,sub(n,count)));
+
+}
+
+Word16 Log2_lc( /* (o) : Fractional part of Log2. (range: 0<=val<1) */
+ Word32 L_x, /* (i) : input value */
+ Word16 *exponent /* (o) : Integer part of Log2. (range: 0<=val<=30) */
+)
+{
+ Word16 exp;
+
+ if (L_x <= 0)
+ L_x = L_deposit_l(0x1);
+
+ exp = norm_l (L_x);
+ *exponent = sub(30, exp); move16();
+
+ return Log2_norm_lc(L_shl(L_x, exp));
+}
diff --git a/lib_com/log2.h b/lib_com/log2.h
new file mode 100644
index 0000000000000000000000000000000000000000..a8ff32e657ffa5008e1dc24b51779acd94127dbc
--- /dev/null
+++ b/lib_com/log2.h
@@ -0,0 +1,40 @@
+/********************************************************************************
+*
+* File : log2.h
+* Purpose : Computes log2(L_x)
+*
+********************************************************************************
+*/
+#ifndef log2_h
+#define log2_h "$Id $"
+
+/*
+********************************************************************************
+* INCLUDE FILES
+********************************************************************************
+*/
+#include "typedef.h"
+#include "log2.h"
+
+/*
+********************************************************************************
+* DEFINITION OF DATA TYPES
+********************************************************************************
+*/
+
+/*
+********************************************************************************
+* DECLARATION OF PROTOTYPES
+********************************************************************************
+*/
+Word16 Log2_norm_lc ( /* (o) : Fractional part of Log2. (range: 0<=val<1) */
+ Word32 L_x /* (i) : input value (normalized) */
+);
+
+Word32 log10_fx(Word32 Linput);
+Word32 pow_10(Word32 x, Word16 *Q);
+Word16 Log2_lc( /* (o) : Fractional part of Log2. (range: 0<=val<1) */
+ Word32 L_x, /* (i) : input value */
+ Word16 *exponent /* (o) : Integer part of Log2. (range: 0<=val<=30) */
+);
+#endif
diff --git a/lib_com/logqnorm_fx.c b/lib_com/logqnorm_fx.c
index 407c1b71f812812ed0dc27cea715ff37cabdb168..dd51093459b19b7dbd363eccd165fb4a12261786 100644
--- a/lib_com/logqnorm_fx.c
+++ b/lib_com/logqnorm_fx.c
@@ -34,53 +34,19 @@
#include "options.h" /* Compilation switches */
#include "prot_fx2.h" /* Function prototypes */
#include "rom_com.h" /* Static table prototypes */
-#include "ivas_cnst.h" /* Common constants */
-
-#define THREN2POW 1518500250L
-
-void calc_norm_fx(
- const Word32 *L_x, /* i : Input vector. Qx */
- const Word16 qx, /* i : Q value of input */
- Word16 *norm, /* o : Quantization indices for norms Q0 */
- Word16 *normlg, /* o : Quantized norms in log2 Q0 */
- const Word16 start_band, /* i : Indice of band to start coding Q0 */
- const Word16 num_bands, /* i : Number of bands Q0 */
- const Word16 *band_len, /* i : Length of bands Q0 */
- const Word16 *band_start /* i : Start of bands Q0 */
-)
-{
- Word16 nrm;
- Word16 band;
- Word16 tmp;
-
- set16_fx(norm, 0, start_band);
- logqnorm_fx(&L_x[band_start[start_band]], qx, &nrm, 32, band_len[start_band], 0);
- norm[start_band] = nrm;
- move16();
- normlg[start_band] = dicnlg2[nrm];
- move16();
-
- tmp = add(start_band, num_bands);
- FOR(band = add(start_band, 1); band < tmp; band++)
- {
- logqnorm_fx(&L_x[band_start[band]], qx, &nrm, 40, band_len[band], 0);
-
- norm[band] = nrm;
- move16();
- normlg[band] = dicnlg2[nrm];
- move16();
- }
-
- return;
-}
+#include "cnst.h" /* Common constants */
+ /*--------------------------------------------------------------------------*
+ * Local constants
+ *--------------------------------------------------------------------------*/
+#define THREN2POW 1518500250L
-/*--------------------------------------------------------------------------*
- * logqnorm_fx
- *
- * Log quantization for norms of sub-vectors
- *--------------------------------------------------------------------------*/
+ /*--------------------------------------------------------------------------*
+ * logqnorm_fx
+ *
+ * Log quantization for norms of sub-vectors
+ *--------------------------------------------------------------------------*/
void logqnorm_fx(
const Word32 *L_x, /* i : coefficient vector Qx */
@@ -215,4 +181,46 @@ void logqnorm_2_fx(
}
return;
-}
\ No newline at end of file
+}
+
+/*--------------------------------------------------------------------------
+ * calc_norm_fx()
+ *
+ * Calculate the norms for the spectral envelope
+ *--------------------------------------------------------------------------*/
+
+void calc_norm_fx(
+ const Word32 *L_x, /* i : Input vector. Qx */
+ const Word16 qx, /* i : Q value of input */
+ Word16 *norm, /* o : Quantization indices for norms Q0 */
+ Word16 *normlg, /* o : Quantized norms in log2 Q0 */
+ const Word16 start_band, /* i : Indice of band to start coding Q0 */
+ const Word16 num_bands, /* i : Number of bands Q0 */
+ const Word16 *band_len, /* i : Length of bands Q0 */
+ const Word16 *band_start /* i : Start of bands Q0 */
+)
+{
+ Word16 nrm;
+ Word16 band;
+ Word16 tmp;
+
+ set16_fx(norm, 0, start_band);
+ logqnorm_fx(&L_x[band_start[start_band]], qx, &nrm, 32, band_len[start_band], 0);
+ norm[start_band] = nrm;
+ move16();
+ normlg[start_band] = dicnlg2[nrm];
+ move16();
+
+ tmp = add(start_band, num_bands);
+ FOR(band = add(start_band, 1); band < tmp; band++)
+ {
+ logqnorm_fx(&L_x[band_start[band]], qx, &nrm, 40, band_len[band], 0);
+
+ norm[band] = nrm;
+ move16();
+ normlg[band] = dicnlg2[nrm];
+ move16();
+ }
+
+ return;
+}
diff --git a/lib_com/lpc_tools_fx.c b/lib_com/lpc_tools_fx.c
index 3505da50dd28f47834fc1aed1b80a00251c5d220..c423f284fd768c5c8c70e711db9b2e40fd777556 100644
--- a/lib_com/lpc_tools_fx.c
+++ b/lib_com/lpc_tools_fx.c
@@ -54,122 +54,115 @@
*-----------------------------------------------------------------*/
-static __inline Word16 L_Extract_lc(const Word32 L_32, Word16 *p_hi)
-{
- *p_hi = extract_h(L_32);
- return lshr(extract_l(L_32), 1);
-
-}
-
/*---------------------------------------------------------------------*
* autocorr()
*
* Compute autocorrelations of input signal
*---------------------------------------------------------------------*/
void autocorr_fx(
- const Word16 x[], /* i : Input signal */
- const Word16 m, /* i : LPC order Q0 */
- Word16 r_h[], /* o : Autocorrelations (msb) Q15 */
- Word16 r_l[], /* o : Autocorrelations (lsb) */
- Word16 *Q_r, /* o : normalisation shift of r Q0 */
- const Word16 len, /* i : Frame lenght */
- const Word16* wind, /* i : Window used */
- Word16 rev_flag,
- const Word16 sym_flag /* i : symmetric window flag */
+ const Word16 x[], /* i : Input signal */
+ const Word16 m, /* i : LPC order Q0 */
+ Word16 r_h[], /* o : Autocorrelations (msb) Q15 */
+ Word16 r_l[], /* o : Autocorrelations (lsb) */
+ Word16 *Q_r, /* o : normalisation shift of r Q0 */
+ const Word16 len, /* i : Frame lenght */
+ const Word16* wind, /* i : Window used */
+ Word16 rev_flag,
+ const Word16 sym_flag /* i : symmetric window flag */
)
{
- Word16 i, j, norm, shift, y[MAX_LEN_LP];
- Word16 fact;
- Word32 L_sum, L_tmp;
-
- IF(EQ_16(rev_flag, 1))
- {
- /* Windowing of signal */
- FOR(i = 0; i < len; i++)
- {
- y[i] = mult_r(x[i], wind[len - i - 1]);
- move16();
- }
- }
- ELSE IF(EQ_16(sym_flag, 1))
- {
- /* symmetric window of even length */
- FOR(i = 0; i < len / 2; i++)
- {
- y[i] = mult_r(x[i], wind[i]);
- move16();
- }
- FOR(; i < len; i++)
- {
- y[i] = mult_r(x[i], wind[len - i - 1]);
- move16();
- }
- }
- ELSE /* assymetric window */
- {
- FOR(i = 0; i < len; i++)
- {
- y[i] = mult_r(x[i], wind[i]);
- move16();
- }
- }
-
-
- /* calculate energy of signal */
- L_sum = L_deposit_h(16); /* sqrt(256), avoid overflow after rounding */
- FOR(i = 0; i < len; i += 2)
- {
- L_tmp = L_mult0(y[i], y[i]);
- L_tmp = L_and(L_tmp, ~(128 - 1));
- L_tmp = L_mac0(L_tmp, y[i + 1], y[i + 1]);
- L_tmp = L_shr(L_tmp, 7);
- L_sum = L_add(L_sum, L_tmp);
- }
-
- /* scale signal to avoid overflow in autocorrelation */
- norm = norm_l(L_sum);
- shift = sub(4, shr(norm, 1));
-
- IF(shift > 0)
- {
- fact = lshr(-32768, shift);
- FOR(i = 0; i < len; i++)
- {
- y[i] = mult_r(y[i], fact);
- move16();
- }
- }
- ELSE
- {
- shift = 0;
- move16();
- }
-
- /* Compute and normalize r[0] */
- L_sum = L_mac(1, y[0], y[0]);
- FOR(i = 1; i < len; i++)
- {
- L_sum = L_mac(L_sum, y[i], y[i]);
- }
- norm = norm_l(L_sum);
- L_sum = L_shl(L_sum, norm);
- L_Extract(L_sum, &r_h[0], &r_l[0]); /* Put in DPF format (see oper_32b) */
-
- /* Compute r[1] to r[m] */
- FOR(i = 1; i <= m; i++)
- {
- L_sum = L_mult(y[0], y[i]);
- FOR(j = 1; j < len - i; j++)
- {
- L_sum = L_mac(L_sum, y[j], y[j + i]);
- }
-
- L_sum = L_shl(L_sum, norm);
- L_Extract(L_sum, &r_h[i], &r_l[i]); /* Put in DPF format (see oper_32b) */
- }
-
- *Q_r = sub(norm, shl(shift, 1));
- move16();
+ Word16 i, j, norm, shift, y[MAX_LEN_LP];
+ Word16 fact;
+ Word32 L_sum, L_tmp;
+
+ IF(EQ_16(rev_flag,1))
+ {
+ /* Windowing of signal */
+ FOR (i = 0; i < len; i++)
+ {
+ y[i] = mult_r(x[i], wind[len-i-1]);
+ move16();
+ }
+ }
+ ELSE IF( EQ_16(sym_flag,1))
+ {
+ /* symmetric window of even length */
+ FOR( i=0; i 0)
+ {
+ fact = lshr(-32768, shift);
+ FOR (i = 0; i < len; i++)
+ {
+ y[i] = mult_r(y[i], fact);
+ move16();
+ }
+ }
+ ELSE
+ {
+ shift = 0;
+ move16();
+ }
+
+ /* Compute and normalize r[0] */
+ L_sum = L_mac(1, y[0], y[0]);
+ FOR (i = 1; i < len; i++)
+ {
+ L_sum = L_mac(L_sum, y[i], y[i]);
+ }
+ norm = norm_l(L_sum);
+ L_sum = L_shl(L_sum, norm);
+ L_Extract(L_sum, &r_h[0], &r_l[0]); /* Put in DPF format (see oper_32b) */
+
+ /* Compute r[1] to r[m] */
+ FOR (i = 1; i <= m; i++)
+ {
+ L_sum = L_mult(y[0],y[i]);
+ FOR (j = 1; j < len - i; j++)
+ {
+ L_sum = L_mac(L_sum, y[j], y[j + i]);
+ }
+
+ L_sum = L_shl(L_sum, norm);
+ L_Extract(L_sum, &r_h[i], &r_l[i]); /* Put in DPF format (see oper_32b) */
+ }
+
+ *Q_r = sub(norm, shl(shift, 1));
+ move16();
}
/*****************************************************************************
@@ -214,35 +207,35 @@ void autocorr_fx(
*****************************************************************************
*/
static
-Word32 Div_32_opt(Word32 L_num, Word16 denom_hi, Word16 denom_lo)
+Word32 Div_32_opt (Word32 L_num, Word16 denom_hi, Word16 denom_lo)
{
- Word16 approx /*, hi, lo, n_hi , n_lo*/;
- Word32 L_32;
+ Word16 approx /*, hi, lo, n_hi , n_lo*/;
+ Word32 L_32;
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
- Flag Overflow = 0;
+ Flag Overflow = 0;
#endif
- /* First approximation: 1 / L_denom = 1/denom_hi */
+ /* First approximation: 1 / L_denom = 1/denom_hi */
- approx = div_s((Word16)0x3fff, denom_hi);
+ approx = div_s ((Word16) 0x3fff, denom_hi);
- /* 1/L_denom = approx * (2.0 - L_denom * approx) */
+ /* 1/L_denom = approx * (2.0 - L_denom * approx) */
- L_32 = Msu_32_16((Word32)0x7fffffffL, denom_hi, denom_lo, approx);
+ L_32 = Msu_32_16 ((Word32) 0x7fffffffL, denom_hi, denom_lo, approx);
- L_32 = Mpy_32_16_1(L_32, approx);
+ L_32 = Mpy_32_16_1(L_32, approx);
- /* L_num * (1/L_denom) */
+ /* L_num * (1/L_denom) */
- L_32 = Mpy_32_32(L_num, L_32);
+ L_32 = Mpy_32_32(L_num, L_32);
#ifdef BASOP_NOGLOB
- L_32 = L_shl_o(L_32, 2, &Overflow);
+ L_32 = L_shl_o (L_32, 2, &Overflow);
#else /* BASOP_NOGLOB */
- L_32 = L_shl(L_32, 2);
+ L_32 = L_shl (L_32, 2);
#endif /* BASOP_NOGLOB */
- return (L_32);
+ return (L_32);
}
/*
@@ -263,222 +256,222 @@ Word32 Div_32_opt(Word32 L_num, Word16 denom_hi, Word16 denom_lo)
* void
*/
Word16 E_LPC_lev_dur(const Word16 Rh[], const Word16 Rl[], Word16 A[],
- Word32 epsP[], const Word16 order
- , Word16 *mem
-)
+ Word32 epsP[], const Word16 order
+ ,Word16 *mem
+ )
{
- return(E_LPC_lev_dur_stab(Rh, Rl, A, epsP, order, mem, 32750)); /* 0.99945 in Q15 */
+ return(E_LPC_lev_dur_stab(Rh, Rl, A, epsP, order, mem, 32750)); /* 0.99945 in Q15 */
}
Word16 E_LPC_lev_dur_stab(const Word16 Rh[], const Word16 Rl[], Word16 A[],
- Word32 epsP[], const Word16 order,
- Word16 *mem, Word16 k_max
-)
+ Word32 epsP[], const Word16 order,
+ Word16 *mem, Word16 k_max
+ )
{
- Word16 i, j, k;
- Word16 hi, lo;
- Word16 Kh, Kl; /* reflection coefficient; hi and lo */
- Word16 alp_h, alp_l, alp_exp; /* Prediction gain; hi lo and exponent */
- Word32 t0, t1, t2; /* temporary variables */
- Word16 flag;
- Word16 Ah[TCXLTP_LTP_ORDER + 1], Al[TCXLTP_LTP_ORDER + 1]; /* LPC coef. in double prec. */
+ Word16 i, j, k;
+ Word16 hi, lo;
+ Word16 Kh, Kl; /* reflection coefficient; hi and lo */
+ Word16 alp_h, alp_l, alp_exp; /* Prediction gain; hi lo and exponent */
+ Word32 t0, t1, t2; /* temporary variables */
+ Word16 flag;
+ Word16 Ah[TCXLTP_LTP_ORDER + 1], Al[TCXLTP_LTP_ORDER + 1]; /* LPC coef. in double prec. */
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
- Flag Overflow = 0;
+ Flag Overflow = 0;
#endif
- BASOP_SATURATE_WARNING_OFF
- if (epsP != NULL)
- {
- epsP[0] = L_Comp(Rh[0], Rl[0]);
- move32();
- }
-
- flag = 0;
- move16();
-
- /* K = A[1] = -R[1] / R[0] */
- t1 = L_Comp(Rh[1], Rl[1]); /* R[1] in Q31 */
- t2 = L_abs(t1); /* abs R[1] */
- t0 = L_deposit_l(0);
- IF(Rh[0] != 0)
- {
- t0 = Div_32_opt(t2, Rh[0], Rl[0]); /* R[1]/R[0] in Q31 */
- /* Cause a difference in MODE1 due to different implementation of div32*/
- }
- if (t1 > 0)
- {
- t0 = L_negate(t0); /* -R[1]/R[0] */
- }
- Kl = L_Extract_lc(t0, &Kh); /* K in DPF */
- t0 = L_shr(t0, 4); /* A[1] in Q27 */
- L_Extract(t0, &Ah[1], &Al[1]); /* A[1] in DPF */
-
- /* Alpha = R[0] * (1-K**2) */
- t0 = Sqr_32(Kh, Kl); /* K*K in Q31 */
- t0 = L_abs(t0); /* Some case <0 !! */
- t0 = L_sub((Word32)0x7fffffffL, t0); /* 1 - K*K in Q31 */
- lo = L_Extract_lc(t0, &hi); /* DPF format */
- t0 = Mpy_32(Rh[0], Rl[0], hi, lo); /* Alpha in Q31 */
- if (epsP != NULL)
- {
- epsP[1] = t0;
- move32();
- }
-
- /* Normalize Alpha */
- alp_exp = norm_l(t0);
- t0 = L_shl(t0, alp_exp);
- alp_l = L_Extract_lc(t0, &alp_h);
- /* DPF format */
-
- /*--------------------------------------*
- * ITERATIONS I=2 to m
- *--------------------------------------*/
-
- FOR(i = 2; i <= order; i++)
- {
- /* t0 = SUM(R[j]*A[i-j], j=1, i-1) + R[i] */
- t0 = L_deposit_l(0);
- FOR(j = 1; j < i; j++)
- {
- t0 = Mac_32(t0, Rh[j], Rl[j], Ah[i - j], Al[i - j]);
- }
+ BASOP_SATURATE_WARNING_OFF_EVS
+ if(epsP!=NULL)
+ {
+ epsP[0] = L_Comp(Rh[0], Rl[0]);
+ move32();
+ }
+
+ flag=0;
+ move16();
+
+ /* K = A[1] = -R[1] / R[0] */
+ t1 = L_Comp(Rh[1], Rl[1]); /* R[1] in Q31 */
+ t2 = L_abs(t1); /* abs R[1] */
+ t0 = L_deposit_l(0);
+ IF (Rh[0] != 0)
+ {
+ t0 = Div_32_opt(t2, Rh[0], Rl[0]); /* R[1]/R[0] in Q31 */
+ /* Cause a difference in MODE1 due to different implementation of div32*/
+ }
+ if (t1 > 0)
+ {
+ t0 = L_negate(t0); /* -R[1]/R[0] */
+ }
+ Kl = L_Extract_lc(t0, &Kh); /* K in DPF */
+ t0 = L_shr(t0, 4); /* A[1] in Q27 */
+ L_Extract(t0, &Ah[1], &Al[1]); /* A[1] in DPF */
+
+ /* Alpha = R[0] * (1-K**2) */
+ t0 = Sqr_32(Kh, Kl); /* K*K in Q31 */
+ t0 = L_abs(t0); /* Some case <0 !! */
+ t0 = L_sub((Word32) 0x7fffffffL, t0); /* 1 - K*K in Q31 */
+ lo = L_Extract_lc(t0, &hi); /* DPF format */
+ t0 = Mpy_32(Rh[0], Rl[0], hi, lo); /* Alpha in Q31 */
+ if(epsP!=NULL)
+ {
+ epsP[1] = t0;
+ move32();
+ }
+
+ /* Normalize Alpha */
+ alp_exp = norm_l(t0);
+ t0 = L_shl(t0, alp_exp);
+ alp_l = L_Extract_lc(t0, &alp_h);
+ /* DPF format */
+
+ /*--------------------------------------*
+ * ITERATIONS I=2 to m
+ *--------------------------------------*/
+
+ FOR (i = 2; i <= order; i++)
+ {
+ /* t0 = SUM(R[j]*A[i-j], j=1, i-1) + R[i] */
+ t0 = L_deposit_l(0);
+ FOR (j = 1; j < i; j++)
+ {
+ t0 = Mac_32(t0, Rh[j], Rl[j], Ah[i - j], Al[i - j]);
+ }
#ifdef BASOP_NOGLOB
- t0 = L_shl_o(t0, 4, &Overflow); /* result in Q27 -> convert to Q31 */
+ t0 = L_shl_o(t0, 4, &Overflow); /* result in Q27 -> convert to Q31 */
#else /* BASOP_NOGLOB */
- t0 = L_shl(t0, 4); /* result in Q27 -> convert to Q31 */
+ t0 = L_shl(t0, 4); /* result in Q27 -> convert to Q31 */
#endif /* BASOP_NOGLOB */
- /* No overflow possible */
+ /* No overflow possible */
- /* Compose and add R[i] in Q3 */
+ /* Compose and add R[i] in Q3 */
#ifdef BASOP_NOGLOB
- t0 = L_mac_o(t0, Rl[i], 1, &Overflow);
- t0 = L_msu_o(t0, Rh[i], -32768, &Overflow);
+ t0 = L_mac_o(t0, Rl[i], 1, &Overflow);
+ t0 = L_msu_o(t0, Rh[i], -32768, &Overflow);
#else /* BASOP_NOGLOB */
- t0 = L_mac(t0, Rl[i], 1);
- t0 = L_msu(t0, Rh[i], -32768);
+ t0 = L_mac(t0, Rl[i], 1);
+ t0 = L_msu(t0, Rh[i], -32768);
#endif /* BASOP_NOGLOB */
- /* K = -t0 / Alpha */
- t1 = L_abs(t0);
- t2 = L_deposit_l(0);
- IF(alp_h != 0)
- {
- t2 = Div_32_opt(t1, alp_h, alp_l); /* abs(t0)/Alpha */
- /* Cause a difference in MODE1 due to different implementation of div32*/
- }
-
- if (t0 > 0)
- {
- t2 = L_negate(t2); /* K =-t0/Alpha */
- }
+ /* K = -t0 / Alpha */
+ t1 = L_abs(t0);
+ t2 = L_deposit_l(0);
+ IF (alp_h != 0)
+ {
+ t2 = Div_32_opt(t1, alp_h, alp_l); /* abs(t0)/Alpha */
+ /* Cause a difference in MODE1 due to different implementation of div32*/
+ }
+
+ if (t0 > 0)
+ {
+ t2 = L_negate(t2); /* K =-t0/Alpha */
+ }
#ifdef BASOP_NOGLOB
- t2 = L_shl_o(t2, alp_exp, &Overflow); /* denormalize; compare to Alpha */
+ t2 = L_shl_o(t2, alp_exp, &Overflow); /* denormalize; compare to Alpha */
#else /* BASOP_NOGLOB */
- t2 = L_shl(t2, alp_exp); /* denormalize; compare to Alpha */
+ t2 = L_shl(t2, alp_exp); /* denormalize; compare to Alpha */
#endif /* BASOP_NOGLOB */
- test();
- if ((mem != NULL) && ((GT_16(abs_s(extract_h(t2)), k_max))))
- {
- flag = 1;
- move16();/* Test for unstable filter. If unstable keep old A(z) */
- }
- if ((mem != NULL) && ((LT_32(L_abs(t2), 5))))
- {
- flag = 1;
- move16(); /*R matrix not reliable (R saturated for many coeff), keep old A(z) */
- }
- Kl = L_Extract_lc(t2, &Kh); /* K in DPF */
-
- /*------------------------------------------*
- * Compute new LPC coeff. -> An[i]
- * An[j]= A[j] + K*A[i-j] , j=1 to i-1
- * An[i]= K
- *------------------------------------------*/
-
- k = mult_r(i, 16384);
- FOR(j = 1; j < k; j++)
- {
- /* Do two Iterations Together to Allow Direct Update of Ah & Al */
- t0 = Mac_32(L_Comp(Ah[j], Al[j]), Kh, Kl, Ah[i - j], Al[i - j]);
- t1 = Mac_32(L_Comp(Ah[i - j], Al[i - j]), Kh, Kl, Ah[j], Al[j]);
- L_Extract(t0, &Ah[j], &Al[j]);
- L_Extract(t1, &Ah[i - j], &Al[i - j]);
- }
- IF(s_and(i, 1) == 0)
- {
- t0 = Mac_32(L_Comp(Ah[j], Al[j]), Kh, Kl, Ah[i - j], Al[i - j]);
- L_Extract(t0, &Ah[j], &Al[j]);
- }
- t2 = L_shr(t2, 4); /* t2 = K in Q31 ->convert to Q27 */
- L_Extract(t2, &Ah[i], &Al[i]); /* An[i] in Q27 */
-
- /* Alpha = Alpha * (1-K**2) */
+ test();
+ if ((mem!=NULL) && ((GT_16(abs_s(extract_h(t2)), k_max))))
+ {
+ flag=1;
+ move16();/* Test for unstable filter. If unstable keep old A(z) */
+ }
+ if ((mem!=NULL) && ((LT_32(L_abs(t2), 5))))
+ {
+ flag=1;
+ move16(); /*R matrix not reliable (R saturated for many coeff), keep old A(z) */
+ }
+ Kl = L_Extract_lc(t2, &Kh); /* K in DPF */
+
+ /*------------------------------------------*
+ * Compute new LPC coeff. -> An[i]
+ * An[j]= A[j] + K*A[i-j] , j=1 to i-1
+ * An[i]= K
+ *------------------------------------------*/
+
+ k = mult_r(i, 16384);
+ FOR (j = 1; j < k; j++)
+ {
+ /* Do two Iterations Together to Allow Direct Update of Ah & Al */
+ t0 = Mac_32(L_Comp(Ah[j], Al[j]), Kh, Kl, Ah[i-j], Al[i-j]);
+ t1 = Mac_32(L_Comp(Ah[i-j], Al[i-j]), Kh, Kl, Ah[j], Al[j]);
+ L_Extract(t0, &Ah[j], &Al[j]);
+ L_Extract(t1, &Ah[i-j], &Al[i-j]);
+ }
+ IF (s_and(i, 1) == 0)
+ {
+ t0 = Mac_32(L_Comp(Ah[j], Al[j]), Kh, Kl, Ah[i-j], Al[i-j]);
+ L_Extract(t0, &Ah[j], &Al[j]);
+ }
+ t2 = L_shr(t2, 4); /* t2 = K in Q31 ->convert to Q27 */
+ L_Extract(t2, &Ah[i], &Al[i]); /* An[i] in Q27 */
+
+ /* Alpha = Alpha * (1-K**2) */
#ifdef BASOP_NOGLOB
- t1 = L_mult_o(Kh, Kh, &Overflow); /* K*K in Q31 */
+ t1 = L_mult_o(Kh, Kh, &Overflow); /* K*K in Q31 */
#else /* BASOP_NOGLOB */
- t1 = L_mult(Kh, Kh); /* K*K in Q31 */
+ t1 = L_mult(Kh, Kh); /* K*K in Q31 */
#endif /* BASOP_NOGLOB */
- t0 = L_mac(t1, mult(Kh, Kl), 2);
- t0 = L_abs(t0); /* Some case <0 !! */
- t0 = L_sub((Word32)0x7fffffffL, t0); /* 1 - K*K in Q31 */
- lo = L_Extract_lc(t0, &hi); /* DPF format */
- t0 = Mpy_32(alp_h, alp_l, hi, lo); /* Alpha in Q31 */
-
-
- /* store denormalized alpha in epsP */
- t1 = L_shr(t0, alp_exp);
- if (epsP != NULL)
- {
- epsP[i] = t1;
- move32();
- }
-
- /* Normalize Alpha */
- j = norm_l(t0);
- t0 = L_shl(t0, j);
- alp_l = L_Extract_lc(t0, &alp_h);/* DPF format */
- alp_exp = add(alp_exp, j); /* Add normalization to alp_exp */
- }
-
- /* Adaptive scaling */
- t1 = L_deposit_l(0);
- FOR(i = 1; i <= order; i++)
- {
- t0 = L_Comp(Ah[i], Al[i]);
- t1 = L_max(t1, L_abs(t0));
- }
- k = s_min(norm_l(t1), 3);
- A[0] = shl(2048, k);
- move16();
- FOR(i = 1; i <= order; i++)
- {
- t0 = L_Comp(Ah[i], Al[i]);
+ t0 = L_mac(t1, mult(Kh, Kl), 2);
+ t0 = L_abs(t0); /* Some case <0 !! */
+ t0 = L_sub((Word32) 0x7fffffffL, t0); /* 1 - K*K in Q31 */
+ lo = L_Extract_lc(t0, &hi); /* DPF format */
+ t0 = Mpy_32(alp_h, alp_l, hi, lo); /* Alpha in Q31 */
+
+
+ /* store denormalized alpha in epsP */
+ t1 = L_shr(t0, alp_exp);
+ if(epsP!=NULL)
+ {
+ epsP[i] = t1;
+ move32();
+ }
+
+ /* Normalize Alpha */
+ j = norm_l(t0);
+ t0 = L_shl(t0, j);
+ alp_l = L_Extract_lc(t0, &alp_h);/* DPF format */
+ alp_exp = add(alp_exp, j); /* Add normalization to alp_exp */
+ }
+
+ /* Adaptive scaling */
+ t1 = L_deposit_l(0);
+ FOR (i = 1; i <= order; i++)
+ {
+ t0 = L_Comp(Ah[i], Al[i]);
+ t1 = L_max( t1, L_abs(t0) );
+ }
+ k = s_min( norm_l( t1 ), 3 );
+ A[0] = shl( 2048, k );
+ move16();
+ FOR (i = 1; i <= order; i++)
+ {
+ t0 = L_Comp(Ah[i], Al[i]);
#ifdef BASOP_NOGLOB
- A[i] = round_fx_o(L_shl_o(t0, k, &Overflow), &Overflow);
+ A[i] = round_fx_o(L_shl_o(t0, k, &Overflow), &Overflow);
#else
- A[i] = round_fx(L_shl(t0, k));
+ A[i] = round_fx(L_shl(t0, k));
#endif
- }
-
- BASOP_SATURATE_WARNING_ON
- IF(mem != NULL)
- {
- /* Enforce stable LPC filter - parcorr[0] and parcorr[1] are not LPC coeffiecients */
- IF(flag)
- {
- Copy(mem, A, order + 1);
- }
- ELSE /* If stable LPC filter, store into memories */
- {
- Copy(A, mem, order + 1);
- }
- }
-
-
- return(flag);
+ }
+
+ BASOP_SATURATE_WARNING_ON_EVS
+ IF (mem != NULL)
+ {
+ /* Enforce stable LPC filter - parcorr[0] and parcorr[1] are not LPC coeffiecients */
+ IF(flag)
+ {
+ Copy(mem, A, order + 1);
+ }
+ ELSE /* If stable LPC filter, store into memories */
+ {
+ Copy(A, mem, order + 1);
+ }
+ }
+
+
+ return(flag);
}
/*
@@ -498,165 +491,165 @@ Word16 E_LPC_lev_dur_stab(const Word16 Rh[], const Word16 Rl[], Word16 A[],
*/
void E_LPC_a_add_tilt(const Word16 *a, Word16 *ap, Word16 gamma, Word16 m)
{
- Word16 i;
- Word32 Amax, Atmp[M + 2];
- Word16 shift;
-
-
-
-
- Amax = L_mult(16384, a[0]);
- FOR(i = 1; i <= m; i++)
- {
- Atmp[i] = L_sub(L_mult(16384, a[i]), L_mult0(gamma, a[i - 1]));
- move32();
- Amax = L_max(Amax, L_abs(Atmp[i]));
- }
- Atmp[m + 1] = L_negate(L_mult0(gamma, a[m]));
- move32();
- Amax = L_max(Amax, L_abs(Atmp[m + 1]));
- shift = norm_l(Amax);
- ap[0] = shl(a[0], sub(shift, 1));
- move16();
- FOR(i = 1; i <= m; i++)
- {
- ap[i] = round_fx(L_shl(Atmp[i], shift));
- }
- ap[m + 1] = round_fx(L_shl(Atmp[m + 1], shift));
+ Word16 i;
+ Word32 Amax, Atmp[M+2];
+ Word16 shift;
+
+
+
+
+ Amax = L_mult( 16384, a[0] );
+ FOR (i = 1; i <= m; i++)
+ {
+ Atmp[i] = L_sub( L_mult(16384, a[i]), L_mult0(gamma, a[i-1]) );
+ move32();
+ Amax = L_max( Amax, L_abs( Atmp[i] ) );
+ }
+ Atmp[m+1] = L_negate( L_mult0(gamma, a[m]) );
+ move32();
+ Amax = L_max( Amax, L_abs( Atmp[m+1] ) );
+ shift = norm_l( Amax );
+ ap[0] = shl( a[0], sub(shift,1) );
+ move16();
+ FOR (i = 1; i <= m; i++)
+ {
+ ap[i] = round_fx( L_shl( Atmp[i], shift ) );
+ }
+ ap[m+1] = round_fx( L_shl( Atmp[m+1], shift ) );
}
void E_LPC_int_lpc_tcx(const Word16 lsp_old[], /* input : LSPs from past frame Q15 */
- const Word16 lsp_new[], /* input : LSPs from present frame Q15 */
- Word16 a[] /* output: interpolated LP coefficients Q12 */
-)
+ const Word16 lsp_new[], /* input : LSPs from present frame Q15 */
+ Word16 a[] /* output: interpolated LP coefficients Q12 */
+ )
{
- Word16 i, lsp[M];
+ Word16 i, lsp[M];
- FOR(i = 0; i < M; i++)
- {
- /*lsp[i] = lsp_old[i]*0.125f + lsp_new[i]*0.875f;*/
- lsp[i] = round_fx(L_mac(L_mult(lsp_old[i], 4096), lsp_new[i], 28672));
- }
- E_LPC_f_lsp_a_conversion(lsp, a, M);
+ FOR (i = 0; i < M; i++)
+ {
+ /*lsp[i] = lsp_old[i]*0.125f + lsp_new[i]*0.875f;*/
+ lsp[i] = round_fx(L_mac(L_mult(lsp_old[i],4096),lsp_new[i],28672));
+ }
+ E_LPC_f_lsp_a_conversion(lsp, a, M);
- return;
+ return;
}
static void lsp_reorder(
- Word16 *lsp, /* (I/O): LSP vector (acos() domain) Q13*1.2732 */
- Word16 min_dist, /* (I): minimum required distance Q13*1.2732 */
- Word16 lpcorder /* (I): LPC order Q0 */
+ Word16 *lsp, /* (I/O): LSP vector (acos() domain) Q13*1.2732 */
+ Word16 min_dist, /* (I): minimum required distance Q13*1.2732 */
+ Word16 lpcorder /* (I): LPC order Q0 */
)
{
- Word16 i;
- Word16 lsp_min, lsp_max;
-
-
- /* Verify the LSF ordering and minimum GAP */
- lsp_min = min_dist;
- move16();
- FOR(i = 0; i < lpcorder; ++i)
- {
- lsp[i] = s_max(lsp[i], lsp_min);
- move16();
- lsp_min = add(lsp[i], min_dist);
- }
-
- /* Reverify the LSF ordering and minimum GAP in the reverse order (security) */
- lsp_max = sub(32767, min_dist);
-
- /* If danger of unstable filter in case of resonance in HF */
- lpcorder = sub(lpcorder, 1);
- IF(GT_16(lsp[lpcorder], lsp_max))
- {
- /* Reverify the minimum LSF gap in the reverse sense */
- FOR(i = lpcorder; i >= 0; --i)
- {
- lsp[i] = s_min(lsp[i], lsp_max);
- move16();
- lsp_max = sub(lsp[i], min_dist);
- }
- }
+ Word16 i;
+ Word16 lsp_min, lsp_max;
+
+
+ /* Verify the LSF ordering and minimum GAP */
+ lsp_min = min_dist;
+ move16();
+ FOR (i=0; i=0; --i)
+ {
+ lsp[i] = s_min(lsp[i], lsp_max);
+ move16();
+ lsp_max = sub(lsp[i], min_dist);
+ }
+ }
}
/* Approximate unweighting */
Word16 E_LPC_lsp_unweight(
- /* const */ Word16 lsp_w[], /* (I): weighted xSP Q15 */
- Word16 lsp_uw[], /* (O): unweighted xSP Q15 */
- Word16 lsf_uw[], /* (O): unweighted LSF Q1*1.28 */
- Word16 inv_gamma, /* (I): inverse weighting factor Q14 */
- Word16 lpcorder /* (I): prediction order Q0 */
+ /* const */ Word16 lsp_w[], /* (I): weighted xSP Q15 */
+ Word16 lsp_uw[], /* (O): unweighted xSP Q15 */
+ Word16 lsf_uw[], /* (O): unweighted LSF Q1*1.28 */
+ Word16 inv_gamma, /* (I): inverse weighting factor Q14 */
+ Word16 lpcorder /* (I): prediction order Q0 */
)
{
- Word16 lsp_w_orig[M], lsp_w_diff[M], mean, step; /* Q13*1.2732 */
- const lsp_unw_triplet *unw_coeffs = NULL;
- Word16 i;
-
- step = 0; /* to avoid compilation warnings */
-
-
- assert(lpcorder == 16);
-
- /* Table selection */
- IF(EQ_16(inv_gamma, GAMMA16k_INV))
- {
- unw_coeffs = p16_gamma0_94to1;
- move16();
- }
- ELSE IF(EQ_16(inv_gamma, GAMMA1_INV))
- {
- unw_coeffs = p16_gamma0_92to1;
- move16();
- }
- ELSE
- {
- assert(0);
- }
-
- /* step = M_PI/(float)(lpcorder+1); */
- step = 1927;
- move16();
- mean = 0;
- move16();
-
- /* Apply acos() and get mean removed version */
- FOR(i = 0; i < lpcorder; ++i)
- {
- mean = add(mean, step);
- lsp_w_orig[i] = shl(xsp_to_xsf(lsp_w[i]), 1);
- move16();
- lsp_w_diff[i] = sub(lsp_w_orig[i], mean);
- move16();
- }
-
- /* Approximate unweighting by 3-tap FIR */
- lsp_uw[0] = add(lsp_w_orig[0], round_fx(L_shl(L_mac0(L_mult0(unw_coeffs[0][1], lsp_w_diff[0]), unw_coeffs[0][2], lsp_w_diff[1]), 2)));
- FOR(i = 1; i < lpcorder - 1; ++i)
- {
- lsp_uw[i] = add(lsp_w_orig[i], round_fx(L_shl(L_mac0(L_mac0(L_mult0(unw_coeffs[i][0], lsp_w_diff[i - 1]), unw_coeffs[i][1], lsp_w_diff[i]), unw_coeffs[i][2], lsp_w_diff[i + 1]), 2)));
- move16();
- }
- lsp_uw[i] = add(lsp_w_orig[i], round_fx(L_shl(L_mac0(L_mult0(unw_coeffs[i][0], lsp_w_diff[i - 1]), unw_coeffs[i][1], lsp_w_diff[i]), 2)));
- move16();
-
- /* Reorder */
- lsp_reorder(lsp_uw, 256, lpcorder);
-
- /* Convert to LSF, apply cos() */
- FOR(i = 0; i < lpcorder; ++i)
- {
- lsf_uw[i] = shr_r(lsp_uw[i], 1);
- move16();
- lsp_uw[i] = xsf_to_xsp(lsf_uw[i]);
- move16();
- }
-
- return 0;
+ Word16 lsp_w_orig[M], lsp_w_diff[M], mean, step; /* Q13*1.2732 */
+ const lsp_unw_triplet *unw_coeffs = NULL;
+ Word16 i;
+
+ step = 0; /* to avoid compilation warnings */
+
+
+ assert(lpcorder == 16);
+
+ /* Table selection */
+ IF (EQ_16(inv_gamma, GAMMA16k_INV))
+ {
+ unw_coeffs = p16_gamma0_94to1;
+ move16();
+ }
+ ELSE IF (EQ_16(inv_gamma, GAMMA1_INV))
+ {
+ unw_coeffs = p16_gamma0_92to1;
+ move16();
+ }
+ ELSE
+ {
+ assert(0);
+ }
+
+ /* step = M_PI/(float)(lpcorder+1); */
+ step = 1927;
+ move16();
+ mean = 0;
+ move16();
+
+ /* Apply acos() and get mean removed version */
+ FOR (i=0; i 0.01f*2^27/2^30 */
- Word32 tmp_epsP;
-
-
-
- mM1 = sub(m, 1);
-
- s = getScaleFactor32(r, add(m, 1));
- IF(s != 0)
- {
- scale_sig32(r, add(m, 1), s); /* scale in-place */
- }
-
- g1 = r;
- Copy32(r + 1, g0, m);
-
- /* compute g0[0]/g1[0], where g0[0] < g1[0] */
- temp16 = negate(divide3232(g0[0], g1[0]));
- reflCoeff[0] = temp16;
- move16();
- move32();
- epsP[0] = r[0];
-
-
- FOR(i = 0; i < mM1; i++)
- {
- /* g1[0] = g0[0]*temp16 + g1[0]; */
- tmp32 = Mpy_32_16_1(g0[0], temp16);
- g1[0] = L_add(g1[0], tmp32);
- move32();
-
- mMi = sub(m, i);
- FOR(j = 1; j < mMi; j++)
- {
- /* g0[j-1] = g0[j] + g1[j]*temp16;
- g1[j] = g0[j]*temp16 + g1[j]; */
- g0[j - 1] = L_add(g0[j], Mpy_32_16_1(g1[j], temp16));
- move32();
- g1[j] = L_add(g1[j], Mpy_32_16_1(g0[j], temp16));
+ Word16 i, j, temp16, mM1, mMi, s;
+ Word32 g0[M], *g1, tmp32;
+ const Word32 min_epsP = 1; /* > 0.01f*2^27/2^30 */
+ Word32 tmp_epsP;
+
+
+
+ mM1 = sub(m,1);
+
+ s = getScaleFactor32(r,add(m,1));
+ IF (s!=0)
+ {
+ scale_sig32(r,add(m,1),s); /* scale in-place */
+ }
+
+ g1 = r;
+ Copy32(r+1,g0,m);
+
+ /* compute g0[0]/g1[0], where g0[0] < g1[0] */
+ temp16 = negate(divide3232(g0[0], g1[0]));
+ reflCoeff[0] = temp16;
+ move16();
+ move32();
+ epsP[0] = r[0];
+
+
+ FOR (i=0; i= 0; specix++);*/
- WHILE(mult(s, spec_r[specix]) >= 0) specix = add(specix, 1);
+ /*check for next zero crossing*/
+ /*for (; s*spec_r[specix] >= 0; specix++);*/
+ WHILE (mult(s,spec_r[specix]) >= 0) specix = add(specix, 1);
- tmp = divide1616(spec_r[specix - 1], sub(spec_r[specix - 1], spec_r[specix]));
- move16();
- /*lsf[lsfix] = L_add(L_deposit_h(sub(specix,1)) , L_shl(L_deposit_l(tmp),1));*/ /*Q16*/
- lsf[lsfix] = add(shl(sub(specix, 1), 7), shr((tmp), 8)); /*7Q8*/
+ tmp = divide1616(spec_r[specix-1], sub(spec_r[specix-1],spec_r[specix] ) );
+ move16();
+ /*lsf[lsfix] = L_add(L_deposit_h(sub(specix,1)) , L_shl(L_deposit_l(tmp),1));*/ /*Q16*/
+ lsf[lsfix] = add(shl(sub(specix,1),7) , shr((tmp),8)); /*7Q8*/
- lsfix++;
+ lsfix++;
- /*check for the next zero crossing*/
- /*for (; s*spec_i[specix] >= 0; specix++);*/
+ /*check for the next zero crossing*/
+ /*for (; s*spec_i[specix] >= 0; specix++);*/
- WHILE(mult(s, spec_i[specix]) >= 0) specix = add(specix, 1);
+ WHILE (mult(s,spec_i[specix]) >= 0) specix = add(specix, 1);
- tmp = divide1616(spec_i[specix - 1], sub(spec_i[specix - 1], spec_i[specix]));
- move16();
- /*lsf[lsfix] = L_add(L_deposit_h(sub(specix,1)) , L_shl(L_deposit_l(tmp),1));*/ /*Q16*/
- lsf[lsfix] = add(shl(sub(specix, 1), 7), shr((tmp), 8)); /*7Q8*/
+ tmp = divide1616(spec_i[specix-1], sub(spec_i[specix-1],spec_i[specix]) );
+ move16();
+ /*lsf[lsfix] = L_add(L_deposit_h(sub(specix,1)) , L_shl(L_deposit_l(tmp),1));*/ /*Q16*/
+ lsf[lsfix] = add(shl(sub(specix,1),7) , shr((tmp),8)); /*7Q8*/
- lsfix++;
+ lsfix++;
- spec_r[speclen] = s;
- move16();
- spec_i[speclen] = s;
- move16();
+ spec_r[speclen] = s;
+ move16();
+ spec_i[speclen] = s;
+ move16();
- s = negate(s);
- }
+ s = negate(s);
+ }
- IF(LT_16(lsfix, 16))
- {
- FOR(i = 0; i < 16; i++)
- {
- lsf[i] = old_lsf[i];
- move16();
- }
- }
+ IF (LT_16(lsfix,16))
+ {
+ FOR(i=0; i<16; i++)
+ {
+ lsf[i] = old_lsf[i];
+ move16();
+ }
+ }
- return;
+ return;
}
-void E_LPC_a_lsf_isf_conversion(Word16 *lpcCoeffs, Word16 *lsf, const Word16 *old_lsf, Word16 lpcOrder, Word8 lpcRep)
+void E_LPC_a_lsf_isf_conversion(Word16 *lpcCoeffs, Word16 *lsf, const Word16 *old_lsf, Word16 lpcOrder, Word8 lpcRep)
{
- Word32 RealFFT[128];
- Word32 ImagFFT[128];
- Word16 RealOut[130];
- Word16 ImagOut[130];
- Word32 *ptrReal;
- Word32 *ptrImag;
- Word16 n, i, j, step, scale;
- const PWord16 *ptwiddle, *pwn17, *pwn17i;
- PWord16 *pwn15, *pwn15i, tmpw15;
- Word16 N = 256;
- Word16 s[4];
- Word32 L_tmp, L_tmp1, L_tmp3;
- Word16 lpc[19];
+ Word32 RealFFT[128];
+ Word32 ImagFFT[128];
+ Word16 RealOut[130];
+ Word16 ImagOut[130];
+ Word32 *ptrReal;
+ Word32 *ptrImag;
+ Word16 n, i, j, step, scale;
+ const PWord16 *ptwiddle, *pwn17, *pwn17i;
+ PWord16 *pwn15, *pwn15i, tmpw15;
+ Word16 N = 256;
+ Word16 s[4];
+ Word32 L_tmp, L_tmp1, L_tmp3;
+ Word16 lpc[19];
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
- Flag Overflow = 0;
+ Flag Overflow = 0;
#endif
- /* half length FFT */
- scale = add(norm_s(lpcCoeffs[0]), 1) + 5;
- move16();
-
- /*s = [sum(a) ((-1).^(1:length(a)))*a];*/
- L_tmp = L_deposit_h(0);
- FOR(j = 0; j <= lpcOrder; j++)
- {
- L_tmp = L_mac(L_tmp, lpcCoeffs[j], 0x800);
- }
- /*s[1] = round_fx(L_tmp); move16();*/
-
- L_tmp1 = L_deposit_h(0);
- FOR(j = 0; j < lpcOrder / 2; j++)
- {
- L_tmp1 = L_msu(L_tmp1, lpcCoeffs[2 * j], 0x800);
- L_tmp1 = L_mac(L_tmp1, lpcCoeffs[2 * j + 1], 0x800);
- }
- L_tmp1 = L_msu(L_tmp1, lpcCoeffs[2 * j], 0x800);
- /*s[2] = round_fx(L_tmp1); move16();*/
-
-
- L_tmp3 = L_add(L_tmp1, L_tmp);
- IF(L_tmp3 != 0)
- {
- s[1] = BASOP_Util_Divide3232_Scale(L_sub(L_tmp1, L_tmp), L_tmp3, &step);
- move16();
- /*s[1] = BASOP_Util_Divide1616_Scale(sub(s[2],s[1]),add(s[2],s[1]), &step); move16();*/
- BASOP_SATURATE_WARNING_OFF
- s[0] = negate(shr(-32768, step + 1));
- move16();
- s[2] = negate(shr(-32768, step + 1));
- move16();
- BASOP_SATURATE_WARNING_ON
- }
- ELSE
- {
- s[1] = 16384 / 4;
- move16();
- s[0] = 0;
- move16();
- s[2] = 0;
- move16();
- }
- s[0] = shr(s[0], 1);
- s[1] = shr(s[1], 1);
- s[2] = shr(s[2], 1);
- lpc[0] = mult_r(lpcCoeffs[0], s[0]);
- move16();
- L_tmp = L_mult(s[0], lpcCoeffs[1]);
- lpc[1] = mac_r(L_tmp, lpcCoeffs[1 - 1], s[1]);
- move16();
-
- FOR(n = 2; n < 17; n++)
- {
- L_tmp = L_mult(s[0], lpcCoeffs[n]);
- L_tmp = L_mac(L_tmp, lpcCoeffs[n - 1], s[1]);
- lpc[n] = mac_r(L_tmp, lpcCoeffs[n - 2], s[2]);
- move16();
- }
- lpc[18] = mult_r(lpcCoeffs[16], s[0]);
- move16();
- L_tmp = L_mult(s[0], lpcCoeffs[15]);
- lpc[17] = mac_r(L_tmp, lpcCoeffs[16], s[1]);
- move16();
-
- scale = sub(getScaleFactor16(lpc, 19), SCALEFACTOR16_5);
-
- ptrReal = RealFFT;
- ptrImag = ImagFFT;
-
- FOR(j = 0; j < 9; j++)
- {
- ptrReal[j * 8] = L_shl(L_deposit_h(lpc[2 * j]), scale);
- ptrImag[j * 8] = L_shl(L_deposit_h(lpc[2 * j + 1]), scale);
- }
- ptrReal[j * 8] = L_shl(L_deposit_h(lpc[2 * j]), scale);
- ptrImag[j * 8] = 0;
- move16();
- j++;
-
- FOR(; j < 16; j++)
- {
- ptrReal[j * 8] = L_deposit_h(0);
- ptrImag[j * 8] = L_deposit_h(0);
- }
-
- //fft16(ptrReal, ptrImag, 8, 0);
-
- ptrReal++;
- ptrImag++;
-
- FOR(i = 1; i < 8; i++)
- {
- ptwiddle = w_a[i - 1];
-
- ptrReal[0] = L_shl(L_deposit_h(lpc[0]), scale);
- ptrImag[0] = L_shl(L_deposit_h(lpc[1]), scale);
-
- FOR(j = 1; j < 9; j++)
- {
- ptrReal[j * 8] = L_shl(L_msu(L_mult(lpc[2 * j], ptwiddle->v.re), lpc[2 * j + 1], ptwiddle->v.im), scale);
- move32();
- ptrImag[j * 8] = L_shl(L_mac(L_mult(lpc[2 * j + 1], ptwiddle->v.re), lpc[2 * j], ptwiddle->v.im), scale);
- move32();
- ptwiddle++;
- }
-
- ptrReal[j * 8] = L_shl(L_mac(0, lpc[2 * j], ptwiddle->v.re), scale);
- move32();
- ptrImag[j * 8] = L_shl(L_mac(0, lpc[2 * j], ptwiddle->v.im), scale);
- move32();
- ptwiddle++;
- j++;
- FOR(; j < 16; j++)
- {
- ptrReal[j * 8] = L_deposit_h(0);
- ptrImag[j * 8] = L_deposit_h(0);
- ptwiddle++;
- }
-
- //fft16(ptrReal, ptrImag, 8, 0);
-
- ptrReal++;
- ptrImag++;
-
- }
-
- /* pre-twiddle */
- BASOP_getTables(NULL, &ptwiddle, &step, 128);
- IF(lpcRep != 0)
- {
- pwn17i = &w19N[126];
- pwn17 = w19N;
- }
- ELSE
- {
- pwn17i = &w18N[126];
- pwn17 = w18N;
- }
-
- pwn15 = &tmpw15;
- pwn15i = &tmpw15;
-
- RealOut[0] = round_fx(2 * L_add(RealFFT[0], ImagFFT[0]));
- ImagOut[0] = 0;
- move16();
-
- RealOut[128] = 0;
- move16();
- ImagOut[128] = round_fx(L_sub(L_add(RealFFT[0], RealFFT[0]), L_add(ImagFFT[0], ImagFFT[0])));
-
- ptwiddle += 8;
- FOR(i = 1; i <= N / 2 / 4; i++)
- {
- Word16 ReAr = extract_h(L_add(RealFFT[i], RealFFT[N / 2 - i]));
- Word16 ReBr = extract_h(L_sub(RealFFT[N / 2 - i], RealFFT[i]));
- Word16 ImAr = extract_h(L_sub(ImagFFT[i], ImagFFT[N / 2 - i]));
- Word16 ImBr = extract_h(L_add(ImagFFT[i], ImagFFT[N / 2 - i]));
- BASOP_SATURATE_WARNING_OFF
+ /* half length FFT */
+ scale = add(norm_s(lpcCoeffs[0]),1)+5;
+ move16();
+
+ /*s = [sum(a) ((-1).^(1:length(a)))*a];*/
+ L_tmp = L_deposit_h(0);
+ FOR(j=0; j<=lpcOrder; j++)
+ {
+ L_tmp = L_mac(L_tmp, lpcCoeffs[j], 0x800);
+ }
+ /*s[1] = round_fx(L_tmp); move16();*/
+
+ L_tmp1 = L_deposit_h(0);
+ FOR(j=0; jv.re), lpc[2*j+1],ptwiddle->v.im),scale);
+ move32();
+ ptrImag[j*8] = L_shl(L_mac(L_mult(lpc[2*j+1],ptwiddle->v.re), lpc[2*j],ptwiddle->v.im),scale);
+ move32();
+ ptwiddle++;
+ }
+
+ ptrReal[j*8] = L_shl(L_mac(0,lpc[2*j],ptwiddle->v.re),scale);
+ move32();
+ ptrImag[j*8] = L_shl(L_mac(0, lpc[2*j],ptwiddle->v.im),scale);
+ move32();
+ ptwiddle++;
+ j++;
+ FOR(; j<16; j++)
+ {
+ ptrReal[j*8] = L_deposit_h(0);
+ ptrImag[j*8] = L_deposit_h(0);
+ ptwiddle++;
+ }
+
+ //fft16(ptrReal, ptrImag, 8, 0);
+
+ ptrReal++;
+ ptrImag++;
+
+ }
+
+ /* pre-twiddle */
+ BASOP_getTables(NULL, &ptwiddle, &step, 128);
+ IF (lpcRep != 0)
+ {
+ pwn17i = &w19N[126];
+ pwn17 = w19N;
+ }
+ ELSE
+ {
+ pwn17i = &w18N[126];
+ pwn17 = w18N;
+ }
+
+ pwn15 = &tmpw15;
+ pwn15i = &tmpw15;
+
+ RealOut[0] = round_fx(2*L_add(RealFFT[0], ImagFFT[0]));
+ ImagOut[0] = 0;
+ move16();
+
+ RealOut[128] = 0;
+ move16();
+ ImagOut[128] = round_fx(L_sub(L_add(RealFFT[0],RealFFT[0]), L_add(ImagFFT[0], ImagFFT[0])));
+
+ ptwiddle += 8;
+ FOR(i=1; i<=N/2/4; i++)
+ {
+ Word16 ReAr = extract_h(L_add(RealFFT[i],RealFFT[N/2-i]));
+ Word16 ReBr = extract_h(L_sub(RealFFT[N/2-i], RealFFT[i]));
+ Word16 ImAr = extract_h(L_sub(ImagFFT[i], ImagFFT[N/2-i]));
+ Word16 ImBr = extract_h(L_add(ImagFFT[i], ImagFFT[N/2-i]));
+ BASOP_SATURATE_WARNING_OFF_EVS
#ifdef BASOP_NOGLOB
- tmpw15.v.re = mac_ro(L_mult(ptwiddle->v.re, pwn17->v.re), ptwiddle->v.im, pwn17->v.im, &Overflow);
- tmpw15.v.im = msu_ro(L_mult(ptwiddle->v.re, pwn17->v.im), ptwiddle->v.im, pwn17->v.re, &Overflow);
+ tmpw15.v.re = mac_ro(L_mult(ptwiddle->v.re, pwn17->v.re), ptwiddle->v.im, pwn17->v.im, &Overflow);
+ tmpw15.v.im = msu_ro(L_mult(ptwiddle->v.re, pwn17->v.im), ptwiddle->v.im, pwn17->v.re, &Overflow);
#else /* BASOP_NOGLOB */
- tmpw15.v.re = mac_r(L_mult(ptwiddle->v.re, pwn17->v.re), ptwiddle->v.im, pwn17->v.im);
- tmpw15.v.im = msu_r(L_mult(ptwiddle->v.re, pwn17->v.im), ptwiddle->v.im, pwn17->v.re);
+ tmpw15.v.re = mac_r(L_mult(ptwiddle->v.re, pwn17->v.re), ptwiddle->v.im, pwn17->v.im);
+ tmpw15.v.im = msu_r(L_mult(ptwiddle->v.re, pwn17->v.im), ptwiddle->v.im, pwn17->v.re);
#endif /* BASOP_NOGLOB */
- BASOP_SATURATE_WARNING_ON
- RealOut[i] = mac_r(L_msu(L_msu(L_mult(ReAr, pwn17->v.re), ImAr, pwn17->v.im), ReBr, pwn15->v.im), ImBr, pwn15->v.re);
- move16();
- ImagOut[i] = mac_r(L_mac(L_mac(L_mult(ReAr, pwn17->v.im), ImAr, pwn17->v.re), ReBr, pwn15->v.re), ImBr, pwn15->v.im);
- move16();
- BASOP_SATURATE_WARNING_OFF
+ BASOP_SATURATE_WARNING_ON_EVS
+ RealOut[i] = mac_r(L_msu(L_msu(L_mult(ReAr, pwn17->v.re),ImAr, pwn17->v.im), ReBr, pwn15->v.im), ImBr, pwn15->v.re);
+ move16();
+ ImagOut[i] = mac_r(L_mac(L_mac(L_mult(ReAr, pwn17->v.im), ImAr, pwn17->v.re), ReBr, pwn15->v.re), ImBr, pwn15->v.im);
+ move16();
+ BASOP_SATURATE_WARNING_OFF_EVS
#ifdef BASOP_NOGLOB
- tmpw15.v.re = msu_ro(L_mult(ptwiddle->v.im, pwn17i->v.im), ptwiddle->v.re, pwn17i->v.re, &Overflow);
- tmpw15.v.im = mac_ro(L_mult(ptwiddle->v.re, pwn17i->v.im), ptwiddle->v.im, pwn17i->v.re, &Overflow);
+ tmpw15.v.re = msu_ro(L_mult(ptwiddle->v.im, pwn17i->v.im), ptwiddle->v.re, pwn17i->v.re, &Overflow);
+ tmpw15.v.im = mac_ro(L_mult(ptwiddle->v.re, pwn17i->v.im), ptwiddle->v.im, pwn17i->v.re, &Overflow);
#else /* BASOP_NOGLOB */
- tmpw15.v.re = msu_r(L_mult(ptwiddle->v.im, pwn17i->v.im), ptwiddle->v.re, pwn17i->v.re);
- tmpw15.v.im = mac_r(L_mult(ptwiddle->v.re, pwn17i->v.im), ptwiddle->v.im, pwn17i->v.re);
+ tmpw15.v.re = msu_r(L_mult(ptwiddle->v.im, pwn17i->v.im), ptwiddle->v.re, pwn17i->v.re);
+ tmpw15.v.im = mac_r(L_mult(ptwiddle->v.re, pwn17i->v.im), ptwiddle->v.im, pwn17i->v.re);
#endif /* BASOP_NOGLOB */
- BASOP_SATURATE_WARNING_ON
- RealOut[N / 2 - i] = msu_r(L_mac(L_mac(L_mult(ReAr, pwn17i->v.re), ImAr, pwn17i->v.im), ImBr, pwn15i->v.re), ReBr, pwn15i->v.im);
- move16();
- ImagOut[N / 2 - i] = msu_r(L_msu(L_msu(L_mult(ReAr, pwn17i->v.im), ImAr, pwn17i->v.re), ReBr, pwn15i->v.re), ImBr, pwn15i->v.im);
- move16();
-
- ptwiddle += 8;
- pwn17++;
- pwn17i--;
- }
-
- ptwiddle -= 16;
- /*change real with imaginary for ptwiddle*/
- FOR(; i < N / 2 / 2; i++)
- {
- Word16 ReAr = extract_h(L_add(RealFFT[i], RealFFT[N / 2 - i]));
- Word16 ReBr = extract_h(L_sub(RealFFT[N / 2 - i], RealFFT[i]));
- Word16 ImAr = extract_h(L_sub(ImagFFT[i], ImagFFT[N / 2 - i]));
- Word16 ImBr = extract_h(L_add(ImagFFT[i], ImagFFT[N / 2 - i]));
- BASOP_SATURATE_WARNING_OFF
+ BASOP_SATURATE_WARNING_ON_EVS
+ RealOut[N/2-i] = msu_r(L_mac(L_mac(L_mult(ReAr, pwn17i->v.re), ImAr, pwn17i->v.im), ImBr, pwn15i->v.re), ReBr, pwn15i->v.im);
+ move16();
+ ImagOut[N/2-i] = msu_r(L_msu(L_msu(L_mult(ReAr, pwn17i->v.im), ImAr, pwn17i->v.re), ReBr, pwn15i->v.re), ImBr, pwn15i->v.im);
+ move16();
+
+ ptwiddle += 8;
+ pwn17++;
+ pwn17i--;
+ }
+
+ ptwiddle -= 16;
+ /*change real with imaginary for ptwiddle*/
+ FOR(; iv.im, pwn17->v.re), ptwiddle->v.re, pwn17->v.im, &Overflow);
- tmpw15.v.im = msu_ro(L_mult(ptwiddle->v.im, pwn17->v.im), ptwiddle->v.re, pwn17->v.re, &Overflow);
+ tmpw15.v.re = mac_ro(L_mult(ptwiddle->v.im, pwn17->v.re), ptwiddle->v.re, pwn17->v.im, &Overflow);
+ tmpw15.v.im = msu_ro(L_mult(ptwiddle->v.im, pwn17->v.im), ptwiddle->v.re, pwn17->v.re, &Overflow);
#else /* BASOP_NOGLOB */
- tmpw15.v.re = mac_r(L_mult(ptwiddle->v.im, pwn17->v.re), ptwiddle->v.re, pwn17->v.im);
- tmpw15.v.im = msu_r(L_mult(ptwiddle->v.im, pwn17->v.im), ptwiddle->v.re, pwn17->v.re);
+ tmpw15.v.re = mac_r(L_mult(ptwiddle->v.im, pwn17->v.re), ptwiddle->v.re, pwn17->v.im);
+ tmpw15.v.im = msu_r(L_mult(ptwiddle->v.im, pwn17->v.im), ptwiddle->v.re, pwn17->v.re);
#endif /* BASOP_NOGLOB */
- BASOP_SATURATE_WARNING_ON
- RealOut[i] = mac_r(L_msu(L_msu(L_mult(ReAr, pwn17->v.re), ImAr, pwn17->v.im), ReBr, pwn15->v.im), ImBr, pwn15->v.re);
- move16();
- ImagOut[i] = mac_r(L_mac(L_mac(L_mult(ReAr, pwn17->v.im), ImAr, pwn17->v.re), ReBr, pwn15->v.re), ImBr, pwn15->v.im);
- move16();
- BASOP_SATURATE_WARNING_OFF
+ BASOP_SATURATE_WARNING_ON_EVS
+ RealOut[i] = mac_r(L_msu(L_msu(L_mult(ReAr, pwn17->v.re),ImAr, pwn17->v.im), ReBr, pwn15->v.im), ImBr, pwn15->v.re);
+ move16();
+ ImagOut[i] = mac_r(L_mac(L_mac(L_mult(ReAr, pwn17->v.im), ImAr, pwn17->v.re), ReBr, pwn15->v.re), ImBr, pwn15->v.im);
+ move16();
+ BASOP_SATURATE_WARNING_OFF_EVS
#ifdef BASOP_NOGLOB
- tmpw15.v.re = msu_ro(L_mult(ptwiddle->v.re, pwn17i->v.im), ptwiddle->v.im, pwn17i->v.re, &Overflow);
- tmpw15.v.im = mac_ro(L_mult(ptwiddle->v.im, pwn17i->v.im), ptwiddle->v.re, pwn17i->v.re, &Overflow);
+ tmpw15.v.re = msu_ro(L_mult(ptwiddle->v.re, pwn17i->v.im), ptwiddle->v.im, pwn17i->v.re, &Overflow);
+ tmpw15.v.im = mac_ro(L_mult(ptwiddle->v.im, pwn17i->v.im), ptwiddle->v.re, pwn17i->v.re, &Overflow);
#else /* BASOP_NOGLOB */
- tmpw15.v.re = msu_r(L_mult(ptwiddle->v.re, pwn17i->v.im), ptwiddle->v.im, pwn17i->v.re);
- tmpw15.v.im = mac_r(L_mult(ptwiddle->v.im, pwn17i->v.im), ptwiddle->v.re, pwn17i->v.re);
+ tmpw15.v.re = msu_r(L_mult(ptwiddle->v.re, pwn17i->v.im), ptwiddle->v.im, pwn17i->v.re);
+ tmpw15.v.im = mac_r(L_mult(ptwiddle->v.im, pwn17i->v.im), ptwiddle->v.re, pwn17i->v.re);
#endif
- BASOP_SATURATE_WARNING_ON
- RealOut[N / 2 - i] = msu_r(L_mac(L_mac(L_mult(ReAr, pwn17i->v.re), ImAr, pwn17i->v.im), ImBr, pwn15i->v.re), ReBr, pwn15i->v.im);
- move16();
- ImagOut[N / 2 - i] = msu_r(L_msu(L_msu(L_mult(ReAr, pwn17i->v.im), ImAr, pwn17i->v.re), ReBr, pwn15i->v.re), ImBr, pwn15i->v.im);
- move16();
-
- ptwiddle -= 8;
- pwn17++;
- pwn17i--;
- }
- ptwiddle += 0;
- {
- Word16 ReAr = extract_h(L_add(RealFFT[i], RealFFT[N / 2 - i]));
- Word16 ReBr = extract_h(L_sub(RealFFT[N / 2 - i], RealFFT[i]));
- Word16 ImAr = extract_h(L_sub(ImagFFT[i], ImagFFT[N / 2 - i]));
- Word16 ImBr = extract_h((L_negate(L_add(ImagFFT[i], ImagFFT[N / 2 - i]))));
- BASOP_SATURATE_WARNING_OFF
- tmpw15.v.re = mac_r(L_mult(ptwiddle->v.im, pwn17->v.re), ptwiddle->v.re, pwn17->v.im);
- tmpw15.v.im = msu_r(L_mult(ptwiddle->v.im, pwn17->v.im), ptwiddle->v.re, pwn17->v.re);
- BASOP_SATURATE_WARNING_ON
- RealOut[i] = msu_r(L_msu(L_msu(L_mult(ReAr, pwn17->v.re), ImAr, pwn17->v.im), ReBr, pwn15->v.im), ImBr, pwn15->v.re);
- move16();
- ImagOut[i] = msu_r(L_mac(L_mac(L_mult(ReAr, pwn17->v.im), ImAr, pwn17->v.re), ReBr, pwn15->v.re), ImBr, pwn15->v.im);
- move16();
- }
-
- spec2isf(RealOut, ImagOut, 128, lsf, old_lsf);
- IF(lpcRep == 0)
- {
- lsf[lpcOrder - 1] = shl(lpcCoeffs[lpcOrder], add(norm_s(lpcCoeffs[0]), 1));
- move16(); /* From Qx to Q15 with saturation */
- lsf[lpcOrder - 1] = xsp_to_xsf(lsf[lpcOrder - 1]);
- move16();
- lsf[lpcOrder - 1] = shr(lsf[lpcOrder - 1], 1);
- move16();
- }
+ BASOP_SATURATE_WARNING_ON_EVS
+ RealOut[N/2-i] = msu_r(L_mac(L_mac(L_mult(ReAr, pwn17i->v.re), ImAr, pwn17i->v.im), ImBr, pwn15i->v.re), ReBr, pwn15i->v.im);
+ move16();
+ ImagOut[N/2-i] = msu_r(L_msu(L_msu(L_mult(ReAr, pwn17i->v.im), ImAr, pwn17i->v.re), ReBr, pwn15i->v.re), ImBr, pwn15i->v.im);
+ move16();
+
+ ptwiddle -= 8;
+ pwn17++;
+ pwn17i--;
+ }
+ ptwiddle += 0;
+ {
+ Word16 ReAr = extract_h(L_add(RealFFT[i],RealFFT[N/2-i]));
+ Word16 ReBr = extract_h(L_sub(RealFFT[N/2-i], RealFFT[i]));
+ Word16 ImAr = extract_h(L_sub(ImagFFT[i], ImagFFT[N/2-i]));
+ Word16 ImBr = extract_h((L_negate(L_add(ImagFFT[i], ImagFFT[N/2-i]))));
+ BASOP_SATURATE_WARNING_OFF_EVS
+ tmpw15.v.re = mac_r(L_mult(ptwiddle->v.im, pwn17->v.re), ptwiddle->v.re, pwn17->v.im);
+ tmpw15.v.im = msu_r(L_mult(ptwiddle->v.im, pwn17->v.im), ptwiddle->v.re, pwn17->v.re);
+ BASOP_SATURATE_WARNING_ON_EVS
+ RealOut[i] = msu_r(L_msu(L_msu(L_mult(ReAr, pwn17->v.re), ImAr, pwn17->v.im), ReBr, pwn15->v.im), ImBr, pwn15->v.re);
+ move16();
+ ImagOut[i] = msu_r(L_mac(L_mac(L_mult(ReAr, pwn17->v.im), ImAr, pwn17->v.re), ReBr, pwn15->v.re), ImBr, pwn15->v.im);
+ move16();
+ }
+
+ spec2isf(RealOut, ImagOut, 128, lsf, old_lsf);
+ IF (lpcRep == 0)
+ {
+ lsf[lpcOrder - 1] = shl(lpcCoeffs[lpcOrder], add(norm_s(lpcCoeffs[0]),1));
+ move16(); /* From Qx to Q15 with saturation */
+ lsf[lpcOrder - 1] = xsp_to_xsf(lsf[lpcOrder - 1]);
+ move16();
+ lsf[lpcOrder - 1] = shr(lsf[lpcOrder - 1], 1);
+ move16();
+ }
}
-
diff --git a/lib_com/lsf_tools_fx.c b/lib_com/lsf_tools_fx.c
index 863c551c5f5d2e47f99d3d0493af1ead63383f5f..84f43d3cceaaf13ab5ed2b851241e45a048c1bec 100644
--- a/lib_com/lsf_tools_fx.c
+++ b/lib_com/lsf_tools_fx.c
@@ -157,7 +157,7 @@ static Word16 chebyshev(Word16 x, Word32 *f, const Word16 n, const Word16 shift)
t0 = L_add(t0, *f++); /* t0 = x*b1 - b2 + 0.5*f[n] */
- BASOP_SATURATE_WARNING_OFF
+ BASOP_SATURATE_WARNING_OFF_EVS
#ifdef BASOP_NOGLOB
t0 = L_shl_o(t0, shift, &Overflow); /* Qx to Q30 with saturation */
cheb = round_fx_o(t0, &Overflow); /* Result in Q14 */
@@ -166,7 +166,7 @@ static Word16 chebyshev(Word16 x, Word32 *f, const Word16 n, const Word16 shift)
cheb = round_fx(t0); /* Result in Q14 */
#endif /* BASOP_NOGLOB */
cheb = s_max(-32767, cheb); /* to avoid saturation */
- BASOP_SATURATE_WARNING_ON
+ BASOP_SATURATE_WARNING_ON_EVS
return (cheb);
}
@@ -463,7 +463,7 @@ void E_LPC_f_isp_a_conversion(const Word16 *isp, Word16 *a, const Word16 m)
/* a[NC] = 0.5*f1[NC]*(1.0 + isp[m-1]) */
t0 = Madd_32_16(f1[nc], f1[nc], isp[m - 1]);
- BASOP_SATURATE_WARNING_OFF /*overflow handling in loop expression*/
+ BASOP_SATURATE_WARNING_OFF_EVS /*overflow handling in loop expression*/
#ifdef BASOP_NOGLOB
t0 = L_shl_o(t0, q, &Overflow);
@@ -474,7 +474,7 @@ void E_LPC_f_isp_a_conversion(const Word16 *isp, Word16 *a, const Word16 m)
t0n = L_sub(t0 , 0x7FFFFFFF); /*check for positive overflow*/
t0p = L_sub(t0, 0x80000000); /*check for negative overflow*/
#endif /* BASOP_NOGLOB */
- BASOP_SATURATE_WARNING_ON
+ BASOP_SATURATE_WARNING_ON_EVS
q = sub(q,1); /*decrease q in case of overflow*/
} WHILE(t0n == 0 || t0p == 0); /*in case of overflow, recalculate coefficients*/
@@ -1086,9 +1086,9 @@ void E_LPC_a_lsp_conversion(
IF(y != 0)
{
x = sub(xhigh, xlow);
- BASOP_SATURATE_WARNING_OFF
+ BASOP_SATURATE_WARNING_OFF_EVS
tmp = abs_s(y);
- BASOP_SATURATE_WARNING_ON
+ BASOP_SATURATE_WARNING_ON_EVS
exp = norm_s(tmp);
if (exp)
tmp = shl(tmp, exp);
diff --git a/lib_com/modif_fs.c b/lib_com/modif_fs.c
index c0f3c56ce37faa9c270429681f8a6a0b68e2fa7b..65541fc36ff71e8a4751b205becd79bc1f14ce54 100644
--- a/lib_com/modif_fs.c
+++ b/lib_com/modif_fs.c
@@ -159,7 +159,7 @@ int16_t modify_Fs(
/* Autocorrelations */
autocorr( signal_ana + mem_len_ana + lg - LEN_WIN_SSS, r, M, LEN_WIN_SSS, wind_sss, 0, 0, 0 );
- lag_wind( r, M, fin, LAGW_STRONG );
+ lag_wind_flt( r, M, fin, LAGW_STRONG );
/* Levinson-Durbin */
lev_dur( A, r, M, epsP );
@@ -632,7 +632,7 @@ void interpolate_3_over_2_allpass(
float out1_buff[L_FRAME32k * 3];
float *out1;
float mem_temp;
- const float *filt_coeff = allpass_poles_3_ov_2;
+ const float *filt_coeff = allpass_poles_3_ov_2_flt;
out1 = out1_buff;
@@ -705,7 +705,7 @@ void decimate_2_over_3_allpass(
float *in;
float out1_buff[L_FRAME48k * 2];
float tmp;
- const float *filt_coeff = allpass_poles_3_ov_2;
+ const float *filt_coeff = allpass_poles_3_ov_2_flt;
const float *lp_num = decimate_3_ov_2_lowpass_num;
const float *lp_den = decimate_3_ov_2_lowpass_den;
@@ -784,7 +784,7 @@ void interpolate_3_over_1_allpass(
float Vu[2], Vm[2], Vl[2]; /* Outputs of three cascaded allpass stages (upper, middle, and lower) */
float *out1;
float mem_temp;
- const float *filt_coeff = allpass_poles_3_ov_2;
+ const float *filt_coeff = allpass_poles_3_ov_2_flt;
out1 = &out[0];
diff --git a/lib_com/modif_fs_fx.c b/lib_com/modif_fs_fx.c
new file mode 100644
index 0000000000000000000000000000000000000000..3c0de0a191a7b4f3b1cd77f05fc09757e12aa896
--- /dev/null
+++ b/lib_com/modif_fs_fx.c
@@ -0,0 +1,1462 @@
+/*====================================================================================
+ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
+ ====================================================================================*/
+
+#include
+#include "options.h" /* Compilation switches */
+#include "cnst.h" /* Common constants */
+#include "prot_fx1.h"
+#include "prot_fx2.h"
+#include "rom_com.h" /* Static table prototypes */
+#include
+#include "rom_enc.h" /* prototypes */
+#include "basop_util.h"
+
+/*-----------------------------------------------------------------*
+ * Local functions
+ *-----------------------------------------------------------------*/
+
+
+
+/*==============================================================================*/
+/* FUNCTION : modify_Fs_fx ( ) */
+/*------------------------------------------------------------------------------*/
+/* PURPOSE : Modify sampling freq by interpolation */
+/*------------------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* const Word16 sigIn_fx[] signal to decimate Q_syn2-1 */
+/* const Word16 lg length of input */
+/* const Word16 fin frequency of input Q0 */
+/* const Word16 fout frequency of output Q0 */
+/*------------------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* Word16 sigOut_fx[] decimated signal Q_syn2-1 */
+/*------------------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* Word16 mem_fx[] filter memory Q_syn2-1 */
+/*------------------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : */
+/* _ None. */
+/*------------------------------------------------------------------------------*/
+/* CALLED FROM : TX/RX */
+/*==============================================================================*/
+Word16 modify_Fs_fx( /* o : length of output Q0 */
+ const Word16 sigIn_fx[], /* i : signal to decimate Q0 */
+ Word16 lg, /* i : length of input Q0 */
+ const Word32 fin, /* i : frequency of input Q0 */
+ Word16 sigOut_fx[], /* o : decimated signal Q0 */
+ const Word32 fout, /* i : frequency of output Q0 */
+ Word16 mem_fx[], /* i/o: filter memory Q0 */
+ const Word16 nblp /* i : flag indicating if NB low-pass is applied */
+)
+{
+ Word16 i;
+
+ Word16 lg_out, fac_num, fac_den, filt_len, frac, temp_n, mem_len;
+ Word16 num_den;
+ Word16 datastep, fracstep;
+ Word16 *sigIn_ptr, *sigPtr;
+ Word16 signal_tab_fx[3*L_FILT_MAX + L_FRAME48k], *signal_fx, *signal_ana_fx; /* 3* as 2* for memory and 1* for future prediction */
+ Word16 A_fx[M+1], r_fx_h[M+1], r_fx_l[M+1];
+ Word16 mem_len_ana;
+ Word16 plus_sample_in;
+ Word16 j;
+ Word16 mu_preemph_fx;
+ Word16 mem_preemph_fx;
+ Word16 Q_r;
+ Word16 mem_lev_fx[18];
+ Word32 t0, t1, t2, L_tmp; /* temporary variables */
+ Word32 LepsP[M+1];
+ Word16 flag_low_order = 0;
+ Word16 filt_len_tmp;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+ const Resampling_cfg *cfg_ptr_fx;
+
+ /*-------------------------------------------------------------------*
+ * Find the resampling configuration
+ *-------------------------------------------------------------------*/
+
+ /* check if fin and fout are the same */
+ IF (EQ_32(fin,fout))
+ {
+ /* just copy the signal_fx and quit */
+ Copy(sigIn_fx, sigOut_fx, lg);
+
+ return lg;
+ }
+ ELSE
+ {
+ /* find the resampling configuration in the lookup table */
+ cfg_ptr_fx = &resampling_cfg_tbl[0];
+ WHILE ( (cfg_ptr_fx->fin_fx != 0) && !(EQ_32(cfg_ptr_fx->fin_fx,fin)&&EQ_32(cfg_ptr_fx->fout_fx,fout)))
+ {
+ test();
+ test();
+ cfg_ptr_fx++;
+ }
+
+
+ /* find config with NB 4kHz low-pass */
+ test();
+ test();
+ IF ( nblp && (GT_32(fin, 8000))&&(EQ_32(fout,12800)))
+ {
+ flag_low_order = 1;
+ move16();
+ cfg_ptr_fx++;
+ WHILE ( (cfg_ptr_fx->fin_fx != 0) && !( (EQ_32(cfg_ptr_fx->fin_fx, fin))&&(EQ_32(cfg_ptr_fx->fout_fx,fout))))
+ {
+ test();
+ test();
+ cfg_ptr_fx++;
+ }
+ }
+
+ /*-------------------------------------------------------------------*
+ * Retrieve and/or calculate the resampling parameters
+ *-------------------------------------------------------------------*/
+ fac_num = cfg_ptr_fx->fac_num_fx;
+ move16();/*Q0*/
+ fac_den = cfg_ptr_fx->fac_den_fx;
+ move16();
+
+ IF(GE_16(lg,L_FRAME))
+ {
+ lg_out = cfg_ptr_fx->lg_out ;
+ move16();
+ }
+ ELSE
+ {
+ lg_out = idiv1616(i_mult2(lg, fac_num), fac_den);
+ }
+ filt_len = cfg_ptr_fx->filt_len_fx;
+ move16();
+ plus_sample_in = 0;
+ move16();/*default, regular delay*/
+ frac = 0;
+ move16();
+
+ test();
+ IF ( (EQ_32(fin, 8000))&&(EQ_32(fout,12800)))
+ {
+ plus_sample_in = 7;
+ move16();
+ frac = 4;
+ move16();
+ }
+
+ mem_len = shl(filt_len,1);
+ signal_fx = signal_tab_fx+2*L_FILT_MAX + sub(L_FRAME48k, add(mem_len, lg));
+ signal_ana_fx = signal_fx;
+ mem_len_ana = mem_len;
+ move16();
+ }
+
+
+ /*-------------------------------------------------------------------*
+ * Resample
+ *-------------------------------------------------------------------*/
+ /* append filter memory */
+ Copy(mem_fx, signal_fx, mem_len);
+
+ sigPtr = signal_fx + mem_len;
+ Copy(sigIn_fx, sigPtr, lg);
+
+ IF(plus_sample_in > 0)
+ {
+ autocorr_fx( signal_ana_fx+mem_len_ana+lg-LEN_WIN_SSS, 1, r_fx_h, r_fx_l, &Q_r, LEN_WIN_SSS, wind_sss_fx, 0, 0 );
+
+
+ t1 = L_Comp(r_fx_h[1], r_fx_l[1]); /* R[1] in Q31 */
+ t2 = L_abs(t1); /* abs R[1] */
+ t0 = L_deposit_l(0);
+ IF (r_fx_h[0] != 0)
+ {
+ t0 = Div_32(t2, r_fx_h[0], r_fx_l[0]); /* R[1]/R[0] in Q31 */
+ }
+ if (t1 < 0)
+ {
+ t0 = L_negate(t0); /* R[1]/R[0] */
+ }
+
+
+
+ mu_preemph_fx = extract_h(t0); /*r_fx[1] / r_fx[0]; */
+ mem_preemph_fx = signal_ana_fx[mem_len_ana+lg-LEN_WIN_SSS - 1];
+ move16();
+ preemph_fx(signal_ana_fx+mem_len_ana+lg-LEN_WIN_SSS, mu_preemph_fx, LEN_WIN_SSS, &mem_preemph_fx);
+
+
+ /* Autocorrelations */
+ autocorr_fx( signal_ana_fx+mem_len_ana+lg-LEN_WIN_SSS, M, r_fx_h, r_fx_l, &Q_r,
+ LEN_WIN_SSS, wind_sss_fx, 0, 0 );
+
+ /* Lag windowing */
+ lag_wind( r_fx_h, r_fx_l, M, fin, LAGW_STRONG );
+
+ /* Levinson-Durbin */
+ set16_fx(mem_lev_fx, 0, 18 );
+ E_LPC_lev_dur(r_fx_h, r_fx_l, A_fx, LepsP, M, NULL);
+
+ Copy_Scale_sig( A_fx, A_fx, M+1, sub(norm_s(A_fx[0]),2) );
+
+ FOR (i=0; ifilter_fx, frac, fac_num, filt_len_tmp ));
+
+ frac = add(frac,fracstep);
+
+ j = sub(fac_num, frac);
+ if (j < 0)
+ {
+ frac = sub(frac,fac_num);
+ }
+ sigIn_ptr += add(lshr(j, 15), datastep);
+ }
+ /* rescaling */
+ test();
+ IF ((GT_16(fac_num,fac_den))==((cfg_ptr_fx->flags_fx&RS_INV_FAC)!=0))
+ {
+ IF(LT_16(fac_num, fac_den))
+ {
+ num_den = div_s(fac_num,fac_den);/*Q15*/
+ test();
+ IF( GT_32(fin, 16000)&&EQ_16(lg_out,512))
+ {
+
+ FOR( i=0; iflags_fx&RS_INV_FAC)!=0))
+ {
+ FOR( i=0; i Q(-QSR) */
+ }
+
+ /* length of the interpolated signal */
+ /*lg_out = (short)(lg * fout / fin); */
+
+ /* cc[x][3]*s*s*s + cc[x][2]*s*s + cc[x][1]*s + cc[x][0]; indexes relatives of s : -1 0 1 2 */
+ /* d : cc[x][0] = s[0] */
+ /* b : cc[x][2] =(s[-1]+s[1])/2-s[0] */
+ /* a : cc[x][3] = (s[-1]+s[2]-s[0]-s[1]-4*cc[x][2]) / 6 */
+ /* c : cc[x][1] = s[1]-s[0]-cc[x][3]-cc[x][2] */
+
+ /* coef inits using memory (indexes < 0) */
+ /* cc[2][] : indexes -2 -1 0 1 */
+ cptr = &(cc[2][0]);
+ cptr[0] = mult_r(sigin_sr[-1], 10923);
+ move16(); /* sigIn[-1]/3 */
+ cptr[2] = sub(shr(add(sigin_sr[-2], sigin_sr[0]), 1), sigin_sr[-1]);
+ move16(); /* (sigIn[-2]+sigIn[0])/2-sigIn[-1]; */
+ cptr[3] = sub(mult_r(sub(add(sigin_sr[-2], sigin_sr[1]), add(sigin_sr[-1], sigin_sr[0])), 5461), mult_r(cptr[2],21845));
+ move16(); /*(sigIn[-2]+sigIn[1]-sigIn[-1]-sigIn[0]) / 6 - 4/6*cc[2][2]);*/
+ cptr[1] = sub(sub(sigin_sr[0], sigin_sr[-1]), add(cptr[3], cptr[2]));
+ move16();
+
+ /* cc[3][] : indexes -1 0 1 2 */
+ cptr = &(cc[3][0]);
+ cptr[0] = mult_r(sigin_sr[0], 10923);
+ move16();/* sigIn[-1]/3 */
+ cptr[2] = sub(shr(add(sigin_sr[-1], sigin_sr[1]), 1), sigin_sr[0]);
+ move16(); /* (sigIn[-1]+sigIn[1])/2-sigIn[0]; */
+ cptr[3] = sub(mult_r(sub(add(sigin_sr[-1], sigin_sr[2]), add(sigin_sr[0], sigin_sr[1])), 5461), mult_r(cptr[2],21845));
+ move16(); /*(sigIn[-2]+sigIn[1]-sigIn[-1]-sigIn[0]) / 6 - 4/6*cc[2][2]);*/
+ cptr[1] = sub(sub(sigin_sr[1], sigin_sr[0]), add(cptr[3], cptr[2]));
+ move16();
+
+ sigOutptr = sigOut;
+ cind = -1;
+ move16();
+ move16(); /* for the move */
+ IF( EQ_32(fin, 12800))
+ {
+ if( EQ_32(fout, 8000))
+ {
+ cind = 0;
+ move16();
+ }
+ if( EQ_32(fout, 16000))
+ {
+ cind = 1;
+ move16();
+ }
+ if( EQ_32(fout, 32000))
+ {
+ cind = 2;
+ move16();
+ }
+ if( EQ_32(fout, 48000))
+ {
+ cind = 3;
+ move16();
+ }
+ }
+ IF( EQ_32(fin, 16000))
+ {
+ if( EQ_32(fout, 12800))
+ {
+ cind = 4;
+ move16();
+ }
+ if( EQ_32(fout, 32000))
+ {
+ cind = 5;
+ move16();
+ }
+ if( EQ_32(fout, 48000))
+ {
+ cind = 6;
+ move16();
+ }
+
+ }
+ ctptr = &(ct2[cind][0]);
+ lg_out = mult_r(shl(lg,2),ctptr[13]);
+ *delayout = ctptr[9];
+ move16();
+
+ if( EQ_16(ctptr[12], 15))
+ {
+ cu = cu15_fx;
+ move16();/*pointer*/
+ }
+
+ if( EQ_16(ctptr[12],4))
+ {
+ cu = cu4_fx;
+ move16();/*pointer*/
+ }
+
+ k2d = sub(ctptr[12], 1); /* shift of index in cu with respect to the next sample (ex 1.25 -> 0.25 ) */
+ fk1 = shl(k2d, 1);
+ k3d = sub(fk1, 1); /* to compurte index in cu with respect to the last sample with - sign (ex 1.25 -> -0.75 ) */
+
+ kk = 0;
+ move16();
+ i = 0;
+ move16();
+
+ lim = sub(lg, ctptr[11]);
+ lim2 = sub(lg, 3);
+ lim3 = ctptr[10];
+ move16();
+ WHILE(LT_16(i, lim2))
+ {
+ if(GE_16(i, lim))
+ {
+ lim3 = sub(ctptr[11], 3); /* last, incomplete period*/
+ }
+ *sigOutptr++ = sigIn[i];
+ move16();
+ FOR(k = 0; k < lim3; k++)
+ {
+ cptr = &(cc[kk][0]);
+ cptr[0] = mult_r(sigin_sr[i+1], 10923);
+ move16();/* sigIn[-1]/3 */
+ cptr[2] = sub(shr(add(sigin_sr[i], sigin_sr[i+2]), 1), sigin_sr[i+1]);
+ move16(); /* (sigIn[-1]+sigIn[1])/2-sigIn[0]; */
+ cptr[3] = sub(mult_r(sub(add(sigin_sr[i], sigin_sr[i+3]), add(sigin_sr[i+1], sigin_sr[i+2])), 5461), mult_r(cptr[2],21845));
+ move16(); /*(sigIn[-1]+sigIn[1]-sigIn[0]-sigIn[1]) / 6 - 4/6*cc[3][2]);*/
+ cptr[1] = sub(sub(sigin_sr[i+2], sigin_sr[i+1]), add(cptr[3], cptr[2]));
+ move16();
+ i = add(i,1);
+
+ i2 = sub(kk, 2);
+ i1 = sub(kk, 1);
+ if( i1 < 0 )
+ {
+ i1 = add(i1, 4);
+ }
+
+ if( i2 < 0 )
+ {
+ i2 = add(i2, 4);
+ }
+ inc = ctptr[8];
+ move16();
+ FOR(k1 = ctptr[k]; k1 < fk1; k1 += inc)
+ {
+ k2 = sub(k1, k2d);
+ k3 = sub(k3d, k1);
+ cptr = &(cc[i2][0]);
+ uptr = &(cu[k1][0]);
+ vv32 = L_mult( 8192, *cptr++);
+ vv32 = L_mac(vv32, *uptr++, *cptr++);
+ vv32 = L_mac(vv32, *uptr++, *cptr++);
+ vv32 = L_mac(vv32, *uptr++, *cptr++); /* Q13*Q(-QSR) -> Q(13-QSR+1) 32 bits*/
+ cptr = &(cc[i1][0]);
+ uptr = &(cu[k2][0]);
+ vv32 = L_mac(vv32, 8192, *cptr++);
+ vv32 = L_mac(vv32, *uptr++, *cptr++);
+ vv32 = L_mac(vv32, *uptr++, *cptr++);
+ vv32 = L_mac(vv32, *uptr++, *cptr++);
+ cptr = &(cc[kk][0]);
+ uptr = &(cu[k3][0]);
+ vv32 = L_mac(vv32, 8192, *cptr++);
+ vv32 = L_msu(vv32, *uptr++, *cptr++);
+ vv32 = L_mac(vv32, *uptr++, *cptr++);
+ vv32 = L_msu(vv32, *uptr++, *cptr++);
+ vv32 = L_shl(vv32, (QSR+2)); /* Q(13-QSR+1) -> Q16 */
+ *sigOutptr++ = round_fx(vv32); /* Q16 -> Q0*/
+ }
+
+ kk = add(kk, 1);
+ if( EQ_16(kk, 4))
+ {
+ kk = 0;
+ move16();
+ }
+ }
+ }
+
+
+ kk = sub(kk, 1);
+ if( kk < 0 )
+ {
+ kk = 3;
+ move16();
+ }
+
+ if( EQ_16(ctptr[10], 1))
+ {
+ *sigOutptr++ = sigIn[i];
+ move16();
+ }
+
+ FOR(k1 = ctptr[k]; k1 < fk1; k1 += inc)
+ {
+ k2 = sub(k1, k2d);
+
+ cptr = &(cc[kk][0]);
+ uptr = &(cu[k2][0]);
+ vv32 = L_mult( 8192, *cptr++);
+ vv32 = L_mac(vv32, *uptr++, *cptr++);
+ vv32 = L_mac(vv32, *uptr++, *cptr++);
+ vv32 = L_mac(vv32, *uptr++, *cptr++); /* Q13*Q(-QSR) -> Q(13-QSR+1) 32 bits*/
+ vv32 = L_shl(vv32, (QSR+2)); /* Q(13-QSR+1) -> Q16 */
+ *sigOutptr++ = i_mult(round_fx(vv32), 3);
+ move16();/* Q16 -> Q0*/
+ }
+
+ if( LT_16(ctptr[10], 3))
+ {
+ *sigOutptr++ = sigIn[add(i, 1)];
+ move16();
+ }
+
+ FOR( k1 = ctptr[add(k, 1)]; k1 < fk1; k1 += inc )
+ {
+ cptr = &(cc[kk][0]);
+ uptr = &(cu[k1][0]);
+ vv32 = L_mult( 8192, *cptr++);
+ vv32 = L_mac(vv32, *uptr++, *cptr++);
+ vv32 = L_mac(vv32, *uptr++, *cptr++);
+ vv32 = L_mac(vv32, *uptr++, *cptr++); /* Q13*Q(-QSR) -> Q(13-QSR+1) 32 bits*/
+ vv32 = L_shl(vv32, (QSR+2)); /* Q(13-QSR+1) -> Q16 */
+ *sigOutptr++ = i_mult(round_fx(vv32), 3);
+ move16();/* Q16 -> Q0*/
+ }
+
+ if( EQ_16(ctptr[10], 1))
+ {
+ *sigOutptr = sigIn[add(i, 2)];
+ move16();
+ }
+ }
+
+ free(sigin_sr_tab);
+
+ return lg_out;
+}
+
+/*====================================================================*/
+/* FUNCTION : Decimate_allpass_steep_fx1 () */
+/*-------------------------------------------------------------------*/
+/* PURPOSE : decimation by a factor 2 */
+/*-------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (const Word16 *) in_fx : input speech, Q0 */
+/* _ (Word16 []) mem: Stateinfo, Q0 */
+/* Size: 2*ALLPASSSECTIONS_STEEP+1 */
+/* _ (Word16) N: Number of Input samples */
+/* _ (Word16 []) out_fx :Output arry of size N/2 Q0 */
+/*-------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ (Word16 []) out_fx : output-signal, Q0 */
+/* _ (Word16 []) mem:gets updated, Q0 */
+/*-------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/*-------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : _ None. */
+/*===================================================================*/
+
+
+void Decimate_allpass_steep_fx(
+ const Word16 *in_fx,
+ Word16 mem[], /* array of size: 2*ALLPASSSECTIONS_STEEP+1 */
+ Word16 N, /* number of input samples */
+ Word16 out_fx[]) /* array of size N/2 */
+{
+
+ Word16 k;
+ Word16 temp[ ALLPASSSECTIONS_STEEP ];
+ Word32 Lacc, Lacc1;
+ Word16 temp1, temp2;
+ Word16 sum = 0;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+ move16();
+
+ /*upper allpass filter chain */
+
+
+ FOR ( k = 0; k < N/2; k++ )
+ {
+
+ Lacc = L_deposit_h( mem[0] ); /* Q(16+x) */
+#ifdef BASOP_NOGLOB
+ Lacc = L_mac_o(Lacc, AP1_STEEP_FX[0], in_fx[2 * k], &Overflow); /* Q(16+x) */
+#else
+ Lacc = L_mac( Lacc, AP1_STEEP_FX[0], in_fx[2*k] ); /* Q(16+x) */
+#endif
+ Lacc1 = L_deposit_h( in_fx[2*k] ); /* Q16+Qx */
+ temp1 = extract_h( Lacc ); /* Qx */
+#ifdef BASOP_NOGLOB
+ Lacc1 = L_msu_o( Lacc1, AP1_STEEP_FX[0], temp1, &Overflow ); /* Q16+Qx */
+#else
+ Lacc1 = L_msu( Lacc1, AP1_STEEP_FX[0], temp1 ); /* Q16+Qx */
+#endif
+ mem[0] = extract_h( Lacc1 ); /* Qx */
+ temp[0] = temp1;
+ move16();
+
+ Lacc1 = L_deposit_h( mem[1] ); /* Q16+Qx */
+#ifdef BASOP_NOGLOB
+ Lacc1 = ( L_mac_o( Lacc1, AP1_STEEP_FX[1], temp1, &Overflow )); /* Q16+Qx */
+#else
+ Lacc1 = ( L_mac( Lacc1, AP1_STEEP_FX[1], temp1 )); /* Q16+Qx */
+#endif
+
+ temp2 = extract_h( Lacc1 ); /* Qx */
+#ifdef BASOP_NOGLOB
+ Lacc = L_msu_o( Lacc, AP1_STEEP_FX[1], temp2 , &Overflow); /* Q16+Qx */
+#else
+ Lacc = L_msu( Lacc, AP1_STEEP_FX[1], temp2 ); /* Q16+Qx */
+#endif
+ mem[1] = extract_h(Lacc); /* Qx */
+ temp[1] = temp2;
+ move16();
+
+
+ Lacc = L_deposit_h( mem[ ALLPASSSECTIONS_STEEP-1 ] ); /* Q(16+x) */
+#ifdef BASOP_NOGLOB
+ out_fx[ k ] = extract_h( L_mac_o( Lacc, AP1_STEEP_FX[ ALLPASSSECTIONS_STEEP-1 ], temp2, &Overflow )); /* Qx format */
+ mem[ALLPASSSECTIONS_STEEP - 1] = extract_h(L_msu_o(Lacc1, AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], out_fx[k], &Overflow)); /* Qx */
+#else
+ out_fx[ k ] = extract_h( L_mac( Lacc, AP1_STEEP_FX[ ALLPASSSECTIONS_STEEP-1 ], temp2 )); /* Qx format */
+ mem[ALLPASSSECTIONS_STEEP - 1] = extract_h(L_msu(Lacc1, AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], out_fx[k])); /* Qx */
+#endif
+
+ }
+
+ /* lower allpass filter chain */
+
+ Lacc = L_deposit_h( mem[ ALLPASSSECTIONS_STEEP ] ); /* Q(16+x) */
+#ifdef BASOP_NOGLOB
+ Lacc = L_mac_o( Lacc, AP2_STEEP_FX[0], mem[2*ALLPASSSECTIONS_STEEP], &Overflow ); /*Q(16+x) */
+#else
+ Lacc = L_mac( Lacc, AP2_STEEP_FX[0], mem[2*ALLPASSSECTIONS_STEEP] ); /*Q(16+x) */
+#endif
+ Lacc1 = L_deposit_h( mem[2*ALLPASSSECTIONS_STEEP] ); /* Q(16+x) */
+ temp1 = extract_h( Lacc ); /* Qx */
+#ifdef BASOP_NOGLOB
+ Lacc1 = L_msu_o( Lacc1, AP2_STEEP_FX[0], temp1, &Overflow ); /* Q(16+x) */
+#else
+ Lacc1 = L_msu( Lacc1, AP2_STEEP_FX[0], temp1 ); /* Q(16+x) */
+#endif
+ mem[ ALLPASSSECTIONS_STEEP ] = extract_h( Lacc1 );
+ temp[0] = temp1;
+ move16();
+
+ Lacc1 = L_deposit_h( mem[ ALLPASSSECTIONS_STEEP+1 ] ); /* Q(16+x) */
+#ifdef BASOP_NOGLOB
+ Lacc1 = L_mac_o( Lacc1, AP2_STEEP_FX[1], temp1, &Overflow); /* Q(16+x) */
+#else
+ Lacc1 = L_mac( Lacc1, AP2_STEEP_FX[1], temp1 ); /* Q(16+x) */
+#endif
+ temp2 = extract_h( Lacc1 ); /* Qx */
+ temp[1] = temp2;
+ move16();
+#ifdef BASOP_NOGLOB
+ Lacc = L_msu_o( Lacc, AP2_STEEP_FX[1], temp2, &Overflow ); /* Q(16+x) */
+#else
+ Lacc = L_msu( Lacc, AP2_STEEP_FX[1], temp2 ); /* Q(16+x) */
+#endif
+ mem[ALLPASSSECTIONS_STEEP+1] = extract_h( Lacc ); /* Qx */
+
+
+ Lacc = L_deposit_h( mem[2*ALLPASSSECTIONS_STEEP-1] ); /* Q(16+x) */
+#ifdef BASOP_NOGLOB
+ Lacc = L_mac_o( Lacc, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP-1], temp2, &Overflow); /* Q(16+x) temp[ALLPASSSECTIONS_STEEP-1] */
+#else
+ Lacc = L_mac( Lacc, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP-1], temp2 ); /* Q(16+x) temp[ALLPASSSECTIONS_STEEP-1] */
+#endif
+ temp[2] = extract_h( Lacc ); /* temp[2] in Qx */
+#ifdef BASOP_NOGLOB
+ Lacc1 = L_msu_o( Lacc1, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP-1], temp[2], &Overflow ); /* Q(16+x) */
+#else
+ Lacc1 = L_msu( Lacc1, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP-1], temp[2] ); /* Q(16+x) */
+#endif
+ mem[ 2*ALLPASSSECTIONS_STEEP-1 ] = extract_h( Lacc1 ); /* Qx */
+
+ sum = mult_r( out_fx[0], 16384 ); /* Qx */
+ out_fx[0] = add( sum, mult_r(temp[ALLPASSSECTIONS_STEEP-1], 16384 )); /* Qx */ move16();
+
+
+ FOR ( k = 1; k < N/2; k++)
+ {
+
+
+ Lacc = L_deposit_h( mem[ ALLPASSSECTIONS_STEEP ] ); /* Q(16+x) */
+#ifdef BASOP_NOGLOB
+ Lacc = L_mac_o(Lacc, AP2_STEEP_FX[0], in_fx[2*k-1], &Overflow); /* Q(16+x):temp[0] */
+#else
+ Lacc = L_mac(Lacc, AP2_STEEP_FX[0], in_fx[2*k-1] ); /* Q(16+x):temp[0] */
+#endif
+ Lacc1 = L_deposit_h( in_fx[ 2*k-1 ] ); /* Q(16+x) */
+ temp1 = extract_h( Lacc ); /* Qx */
+#ifdef BASOP_NOGLOB
+ Lacc1 = L_msu_o( Lacc1, AP2_STEEP_FX[0], temp1, &Overflow ); /* Q(16+x) */
+#else
+ Lacc1 = L_msu( Lacc1, AP2_STEEP_FX[0], temp1 ); /* Q(16+x) */
+#endif
+
+ mem[ALLPASSSECTIONS_STEEP] = extract_h( Lacc1 ); /* Qx */
+ temp[0] = temp1;
+ move16();
+
+
+ Lacc1 = L_deposit_h( mem[ ALLPASSSECTIONS_STEEP+1 ] ); /* Q(16+x) */
+#ifdef BASOP_NOGLOB
+ Lacc1 = L_mac_o(Lacc1,AP2_STEEP_FX[1],temp1, &Overflow); /* Q(16+x) */
+#else
+ Lacc1 = L_mac(Lacc1,AP2_STEEP_FX[1],temp1); /* Q(16+x) */
+#endif
+ temp2 = extract_h( Lacc1 ); /* Qx */
+ temp[1] = temp2;
+ move16();
+#ifdef BASOP_NOGLOB
+ Lacc = L_msu_o(Lacc,AP2_STEEP_FX[1],temp2, &Overflow); /* Q(16+x) */
+#else
+ Lacc = L_msu(Lacc,AP2_STEEP_FX[1],temp2); /* Q(16+x) */
+#endif
+ mem[ALLPASSSECTIONS_STEEP+1]= extract_h(Lacc); /* Qx */
+
+
+ Lacc = L_deposit_h( mem[2*ALLPASSSECTIONS_STEEP-1] ); /* Q(16+x) */
+#ifdef BASOP_NOGLOB
+ Lacc = L_mac_o( Lacc, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP-1], temp[1], &Overflow); /* Q(16+x) temp[ALLPASSSECTIONS_STEEP-1] */
+#else
+ Lacc = L_mac( Lacc, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP-1], temp[1] ); /* Q(16+x) temp[ALLPASSSECTIONS_STEEP-1] */
+#endif
+ temp[2] = extract_h( Lacc ); /*temp[2] in Qx */
+#ifdef BASOP_NOGLOB
+ Lacc1 = L_msu_o( Lacc1, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP-1], temp[2], &Overflow ); /* Q(16+x) */
+#else
+ Lacc1 = L_msu( Lacc1, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP-1], temp[2] ); /* Q(16+x) */
+#endif
+ mem[2*ALLPASSSECTIONS_STEEP-1] = extract_h( Lacc1 ); /* Qx */
+
+
+
+ sum = mult_r( out_fx[k], 16384 ); /* Qx */
+ out_fx[k] = add( sum, mult_r( temp[ALLPASSSECTIONS_STEEP-1], 16384 ) );
+ move16(); /* Qx */
+
+ }
+
+ /* z^(-1) */
+
+ mem[ 2*ALLPASSSECTIONS_STEEP ] = in_fx[ N-1 ];
+ move16(); /* Qx */
+
+}
+
+
+/*-------------------------------------------------------------------*
+ * Interpolate_allpass_steep()
+ *
+ * Interpolation by a factor 2
+ *-------------------------------------------------------------------*/
+
+void Interpolate_allpass_steep_fx(
+ const Word16 *in_fx,
+ Word16 mem[], /* array of size: 2*ALLPASSSECTIONS_STEEP+1 */
+ Word16 N, /* number of input samples */
+ Word16 out_fx[]) /* array of size 2*N */
+{
+
+ Word16 k;
+ Word32 Lacc=0, Lacc1=0;
+ Word16 temp1, temp2;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+ /*** State in Q0,in_fx Q0, AP1_STEEP in Q15 AP2_STEEP in Q15 OP in Q0 ************/
+ /*upper allpass filter chain */
+
+ FOR (k=0; k 0);
+
+ mem_fx_11 = mem_fx[11];
+ move16();
+ mem_fx_7 = mem_fx[7];
+ move16();
+ mem_fx_3 = mem_fx[3];
+ move16();
+ FOR (i = 0; i < loop_len; i++ )
+ {
+ /* Lower branch */
+ /*Vl0 = mem[8] + filt_coeff[6] * (*in - mem[9]);
+ Vl1 = mem[9] + filt_coeff[7] * (Vl0 - mem[10]);
+ mem[11] = mem[10] + filt_coeff[8] * (Vl1 - mem[11]); */
+ tmp = mult_r(filt_coeff_fx[6], sub(*in++, mem_fx[9]));
+ if (i == 0)
+ {
+ Vl0 = add(mem_fx[8] , tmp);
+ }
+ if (i != 0)
+ {
+ Vl0 = add(*(in-4) , tmp);
+ }
+ Vl1 = add(mem_fx[9] , mult_r(filt_coeff_fx[7], sub(Vl0, mem_fx[10])));
+ mem_fx_11 = add(mem_fx[10], mult_r(filt_coeff_fx[8], sub(Vl1, mem_fx_11)));
+
+ /* mem[8] = *in++;
+ mem[9] = Vl0;
+ mem[10] = Vl1;
+ *out1 = mem[11]; */
+
+ mem_fx[9] = Vl0;
+ move16();
+ mem_fx[10] = Vl1;
+ move16();
+
+ /* Middle branch */
+ /* Vm0 = mem[4] + filt_coeff[3] * (*in - mem[5]);
+ Vm1 = mem[5] + filt_coeff[4] * (Vm0-mem[6]);
+ mem[7] = mem[6] + filt_coeff[5] * (Vm1-mem[7]); */
+ tmp = mult_r(filt_coeff_fx[3], sub(*in++, mem_fx[5]));
+ if (i == 0)
+ {
+ Vm0 = add(mem_fx[4] , tmp);
+ }
+ if (i != 0)
+ {
+ Vm0 = add(*(in-4), tmp);
+ }
+ Vm1 = add(mem_fx[5] , mult_r(filt_coeff_fx[4], sub(Vm0, mem_fx[6])));
+ mem_fx_7 = add(mem_fx[6], mult_r(filt_coeff_fx[5], sub(Vm1, mem_fx_7)));
+
+ mem_fx[5] = Vm0;
+ move16();
+ mem_fx[6] = Vm1;
+ move16();
+ out = add(mem_fx_11, mem_fx_7);
+
+ /* Upper branch */
+ /* Vu0 = mem[0] + filt_coeff[0] * ( *in - mem[1] );
+ Vu1 = mem[1] + filt_coeff[1] * ( Vu0 - mem[2] );
+ mem[3] = mem[2] + filt_coeff[2] * ( Vu1 - mem[3] ); */
+ tmp = mult_r(filt_coeff_fx[0], sub(*in++, mem_fx[1]));
+ if (i == 0)
+ {
+ Vu0 = add(mem_fx[0] , tmp);
+ }
+ if (i != 0)
+ {
+ Vu0 = add(*(in-4), tmp);
+ }
+ Vu1 = add(mem_fx[1] , mult_r(filt_coeff_fx[1], sub(Vu0, mem_fx[2])));
+ mem_fx_3 = add(mem_fx[2] , mult_r(filt_coeff_fx[2], sub(Vu1, mem_fx_3)));
+
+ mem_fx[1] = Vu0;
+ move16();
+ mem_fx[2] = Vu1;
+ move16();
+ *out1++ = add(out, mem_fx_3);
+ move16();
+ }
+ mem_fx[8] = *(in-3);
+ move16();
+ mem_fx[4] = *(in-2);
+ move16();
+ mem_fx[0] = *(in-1);
+ move16();
+ mem_fx[11] = mem_fx_11;
+ move16();
+ mem_fx[7] = mem_fx_7;
+ move16();
+ mem_fx[3] = mem_fx_3;
+ move16();
+
+ Scale_sig(mem_fx, 12, negate(sc));
+ Scale_sig(out_fx, loop_len, negate(sc));
+ Scale_sig(lp_mem_fx, 6, negate(sc));
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * retro_interp4_5_fx()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void retro_interp4_5_fx(
+ const Word16 *syn_fx,
+ Word16 *pst_old_syn_fx
+)
+{
+ Word16 *pf5, *pf4;
+ Word16 c;
+
+ /* resample st->pst_old_syn in a reverse way to preserve time-alignment */
+ pf4 = (Word16*) &pst_old_syn_fx[58];
+ pf5 = (Word16*) pst_old_syn_fx;
+ FOR (c=0; c<57; c++)
+ {
+ *pf5++ = pf4[0];
+ move16();
+ /* *pf5++ = 0.2f * pf4[0] + 0.8f * pf4[1]; */
+ *pf5++ = mac_r(L_mult(6554, pf4[0]), 26214, pf4[1]);
+ move16();
+ /* *pf5++ = 0.4f * pf4[1] + 0.6f * pf4[2]; */
+ *pf5++ = mac_r(L_mult(13107, pf4[1]), 19661, pf4[2]);
+ move16();
+ /* *pf5++ = 0.6f * pf4[2] + 0.4f * pf4[3]; */
+ *pf5++ = mac_r(L_mult(19661, pf4[2]), 13107, pf4[3]);
+ move16();
+ /* *pf5++ = 0.8f * pf4[3] + 0.2f * pf4[4]; */
+ *pf5++ = mac_r(L_mult(26214, pf4[3]), 6554, pf4[4]);
+ move16();
+ pf4+=4;
+ }
+ *pf5++ = pf4[0];
+ move16();
+ /* *pf5++ = 0.2f * pf4[0] + 0.8f * pf4[1]; */
+ *pf5++ = mac_r(L_mult(6554, pf4[0]), 26214, pf4[1]);
+ move16();
+ /* *pf5++ = 0.4f * pf4[1] + 0.6f * pf4[2]; */
+ *pf5++ = mac_r(L_mult(13107, pf4[1]), 19661, pf4[2]);
+ move16();
+ /* *pf5++ = 0.6f * pf4[2] + 0.4f * pf4[3]; */
+ *pf5++ = mac_r(L_mult(19661, pf4[2]), 13107, pf4[3]);
+ move16();
+ /* *pf5++ = 0.8f * pf4[3] + 0.2f * syn[0]; */
+ *pf5++ = mac_r(L_mult(26214, pf4[3]), 6554, syn_fx[0]);
+ move16();
+ /* all samples processed: NBPSF_PIT_MAX = 290 = (58*5) */
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * retro_interp5_4_fx()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void retro_interp5_4_fx(
+ Word16 *pst_old_syn_fx
+)
+{
+ Word16 *pf5, *pf4;
+ Word16 c;
+
+ /* resample st->pst_old_syn in a reverse way to preserve time-alignment */
+ pf4 = (Word16*) &pst_old_syn_fx[NBPSF_PIT_MAX-1];
+ pf5 = pf4;
+ FOR (c=0; c<58; c++)
+ {
+ /* *pf4-- = 0.75f * pf5[0] + 0.25f * pf5[-1]; */
+ *pf4-- = mac_r(L_mult(24576, pf5[0]), 8192, pf5[-1]);
+ move16();
+ /* *pf4-- = 0.50f * pf5[-1] + 0.50f * pf5[-2]; */
+ *pf4-- = mac_r(L_mult(16384, pf5[-1]), 16384, pf5[-2]);
+ move16();
+ /* *pf4-- = 0.25f * pf5[-2] + 0.75f * pf5[-3]; */
+ *pf4-- = mac_r(L_mult(8192, pf5[-2]), 24576, pf5[-3]);
+ move16();
+ *pf4-- = pf5[-4];
+ move16();
+ pf5-=5;
+ }
+ /* all samples processed: NBPSF_PIT_MAX = 290 = (58*5) */
+
+ return;
+}
+
diff --git a/lib_com/mslvq_com_fx.c b/lib_com/mslvq_com_fx.c
index d0ecef3d98db8d3257d86a0d464346741f758c19..b04a7a57fbc4c38d86cd65e8287e5afa68f1e5c4 100644
--- a/lib_com/mslvq_com_fx.c
+++ b/lib_com/mslvq_com_fx.c
@@ -40,64 +40,464 @@
* Local functions
*-----------------------------------------------------------------*/
+static void make_offset_scale_fx(Word16 j, const Word32 tab_no_cv[], const Word16 no_ld[],
+ Word16 no_scl, Word32 offset_scale[][MAX_NO_SCALES + 1]);
+static void init_offset_fx(Word32 offset_scale1[][MAX_NO_SCALES + 1], Word32 offset_scale2[][MAX_NO_SCALES + 1],
+ Word32 offset_scale1_p[][MAX_NO_SCALES + 1], Word32 offset_scale2_p[][MAX_NO_SCALES + 1],
+ Word16 no_scales[][2], Word16 no_scales_p[][2]);
static void decode_comb_fx(Word32 index, Word16 *cv, Word16 idx_lead);
-static void divide_64_32_fx(Word16 *xs, Word32 y, Word32 *result, Word32 *rem);
-static void decode_leaders_fx(Word16 index, Word16 idx_lead, Word16 *cv);
static void decode_sign_pc1_fx(Word16 *c, Word16 idx_sign, Word16 parity);
-static void idx2c_fx(Word16 n, Word16 *p, Word16 k, Word16 val);
static void put_value_fx(Word16 *cv, Word16 *p, Word16 val, Word16 dim, Word16 no_new_val);
+static void decode_leaders_fx(Word16 index, Word16 idx_lead, Word16 *cv);
+static void idx2c_fx(Word16 n, Word16 *p, Word16 k, Word16 val);
+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 Word32 divide_32_32_fx(Word32 y, Word32 x, Word32 * rem);
static Word16 divide_16_16_fx(Word16 y, Word16 x, Word16 *rem);
-static void put_value_fx(
- Word16 *cv, /* i/o : input codevector Q1*/
- Word16 *p, /* i : array with positions */
- Word16 val, /* i : value to be inserted Q1*/
- Word16 dim, /* i : vector dimension */
- Word16 no_new_val /* i : number of values to be inserted */
+/* used in CNG-LP coding */
+void permute_fx(
+ Word16 *pTmp1, /* i/o: vector whose components are to be permuted */
+ const Word16 *perm /* i : permutation info (indexes that should be interchanged), max two perms */
)
{
- Word16 cv_out[LATTICE_DIM];
- Word16 i, occ[LATTICE_DIM], cnt, limit;
+ Word16 p1, p2;
+ Word16 tmp;
+
+ p1 = perm[0];
+ move16();
+ p2 = perm[1];
+ move16();
+ tmp = pTmp1[p1];
+ move16();
+ pTmp1[p1] = pTmp1[p2];
+ move16();
+ move16();
+ pTmp1[p2] = tmp;
+ move16();
+ p1 = perm[2];
+ move16();
+
+ IF(GT_16(p1, -1))
+ {
+ p2 = perm[3];
+ move16();
+ tmp = pTmp1[p1];
+ move16();
+ pTmp1[p1] = pTmp1[p2];
+ move16();
+ move16();
+ pTmp1[p2] = tmp;
+ move16();
+ }
+
+ return;
+}
+
+
+void init_lvq_fx(
+ Word32 offset_scale1[][MAX_NO_SCALES + 1], /* o: lattice truncation index offset for the first LSF subvector - safety net structures*/
+ Word32 offset_scale2[][MAX_NO_SCALES + 1], /* o: lattice truncation index offset for the second LSF subvector - safety net structures*/
+ Word32 offset_scale1_p[][MAX_NO_SCALES + 1], /* o: lattice truncation index offset for the first LSF subvector - predictive structures*/
+ Word32 offset_scale2_p[][MAX_NO_SCALES + 1], /* o: lattice truncation index offset for the second LSF subvector - predictive structures*/
+ Word16 no_scales[][2], /* o: number of truncations for each LSF subvector at each MSLVQ structure - safety net */
+ Word16 no_scales_p[][2] /* o: number of truncations for each LSF subvector at each MSLVQ structure - predictive */
+)
+{
+ Word16 i, j;
+ /* safety-net mode */
+ FOR(i = 0; i < MAX_NO_MODES; i++)
+ {
+ j = 0;
+ move16();
+ test();
+ WHILE((LT_16(j, MAX_NO_SCALES)) && (no_lead_fx[i][j] > 0))
+ {
+ j++;
+ }
+ no_scales[i][0] = j;
+ move16();
+ j = MAX_NO_SCALES;
+ move16();
+ test();
+ WHILE((LT_16(j, shl(MAX_NO_SCALES, 1))) && (no_lead_fx[i][j] > 0))
+ {
+ j++;
+ }
+ no_scales[i][1] = sub(j, MAX_NO_SCALES);
+ move16();
+ }
+ /* predictive mode */
+ FOR(i = 0; i < MAX_NO_MODES_p; i++)
+ {
+ j = 0;
+ move16();
+ WHILE((LT_16(j, MAX_NO_SCALES)) && (no_lead_p_fx[i][j] > 0))
+ {
+ j++;
+ }
+ no_scales_p[i][0] = j;
+ move16();
+ j = MAX_NO_SCALES;
+ move16();
+ WHILE((LT_16(j, shl(MAX_NO_SCALES, 1))) && (no_lead_p_fx[i][j] > 0))
+ {
+ j++;
+ }
+ no_scales_p[i][1] = sub(j, MAX_NO_SCALES);
+ move16();
+ }
+ /* index offsets for each truncation */
+ init_offset_fx(offset_scale1, offset_scale2, offset_scale1_p, offset_scale2_p, no_scales, no_scales_p);
+}
+
+/* make_offset_scale_fx() - calculates scale offset values for a particular MSLVQ structure */
+static
+void make_offset_scale_fx(
+ Word16 j, /* i: MSLVQ structure index */
+ const Word32 tab_no_cv[], /* i: cummulated number of codevectors in each leader class */
+ const Word16 no_ld[], /* i: number of leaders in each truncation for the MSLVQ structure j*/
+ Word16 no_scl, /* i: number of truncations in the MSLVQ structure j */
+ Word32 offset_scale[][MAX_NO_SCALES + 1]/* o: offset values */
+)
+{
+ Word16 i;
+
+ offset_scale[j][0] = L_deposit_l(1);
+ FOR(i = 1; i <= no_scl; i++)
+ {
+ offset_scale[j][i] = L_add(offset_scale[j][sub(i, 1)], tab_no_cv[no_ld[sub(i, 1)]]);
+ move32();
+ }
+
+ return;
+}
+
+void init_offset_fx(
+ Word32 offset_scale1[][MAX_NO_SCALES + 1], /* o: lattice truncation index offset for the first LSF subvector - safety net structures*/
+ Word32 offset_scale2[][MAX_NO_SCALES + 1], /* o: lattice truncation index offset for the second LSF subvector - safety net structures*/
+ Word32 offset_scale1_p[][MAX_NO_SCALES + 1],/* o: lattice truncation index offset for the first LSF subvector - predictive structures*/
+ Word32 offset_scale2_p[][MAX_NO_SCALES + 1],/* o: lattice truncation index offset for the second LSF subvector - predictive structures*/
+ Word16 no_scales[][2], /* i: number of truncations for each LSF subvector at each MSLVQ structure - safety net */
+ Word16 no_scales_p[][2] /* i: number of truncations for each LSF subvector at each MSLVQ structure - predictive */
+)
+{
+ Word16 j;
+ /* safety-net */
+ FOR(j = 0; j < MAX_NO_MODES; j++)
+ {
+ make_offset_scale_fx(j, table_no_cv_fx, no_lead_fx[j], no_scales[j][0], offset_scale1);
+ make_offset_scale_fx(j, table_no_cv_fx, &no_lead_fx[j][MAX_NO_SCALES], no_scales[j][1], offset_scale2);
+ }
+ /* predictive modes AR and MA */
+ FOR(j = 0; j < MAX_NO_MODES_p; j++)
+ {
+ make_offset_scale_fx(j, table_no_cv_fx, no_lead_p_fx[j], no_scales_p[j][0], offset_scale1_p);
+ make_offset_scale_fx(j, table_no_cv_fx, &no_lead_p_fx[j][MAX_NO_SCALES], no_scales_p[j][1], offset_scale2_p);
+ }
+
+ offset_scale1[MAX_NO_MODES][0] = 1;
+ move32();
+ offset_scale2[MAX_NO_MODES][0] = 1;
+ move32();
+ offset_scale1_p[MAX_NO_MODES_p][0] = 1;
+ move32();
+ offset_scale2_p[MAX_NO_MODES_p][0] = 1;
+ move32();
+
+ return;
+}
+
+static Word16
+decode_indexes_fx(
+ Word16 * index, /* i: LSF vector index, written as array of Word16 because it generally uses more than 16 bits */
+ Word16 no_bits, /* i: number of bits for the index */
+ const Word16 * p_scales, /* i: scale values for the MSLVQ structures */
+ Word16 * p_no_scales, /* i: number of truncations for each MSLVQ structure */
+ Word32 * p_offset_scale1, /* i: scale index offset for first LSF subvector */
+ Word32 * p_offset_scale2, /* i: scale index offset for second LSF subvector */
+ Word16 * x_lvq, /* o: decoded LSF vector in Q1 */
+ Word16 mode_glb, /* i: index of LSLVQ structure */
+ //note_ : renamed from scales
+ Word16 * scales_mslvq /* o: scale values for the decoded MSLVQ LSF codevector */
+)
+{
+ Word32 index1 = 0, index2 = 0;
+ Word16 len_scales = MAX_NO_SCALES * 2, no_modes;
+ Word16 i, im1, idx_scale;
+ Word16 tmp;
+
+ no_modes = MAX_NO_SCALES + 1;
+ move16();
+
+ IF(LE_16(no_bits, shl(LEN_INDICE, 1))) /* the third short is not used */
+ {
+ index[2] = 0;
+ move16();
+ if (LE_16(no_bits, LEN_INDICE))
+ {
+ index[1] = 0;
+ move16();
+ }
+ }
+
+ /* safety check in case of bit errors */
+ FOR(i = 0; i < 3; i++)
+ {
+ IF(index[i] < 0)
+ {
+ set16_fx(x_lvq, 0, 2 * LATTICE_DIM);
+ scales_mslvq[0] = 0;
+ scales_mslvq[1] = 0;
+ index[i] = 0;
+ return 1;
+ }
+ }
+
+ /* first subvector */
+ tmp = i_mult2(mode_glb, no_modes);
+
+ IF(p_offset_scale2[add(tmp, p_no_scales[add(shl(mode_glb, 1), 1)])] > 0)
+ {
+ divide_64_32_fx(index, p_offset_scale2[tmp + p_no_scales[add(shl(mode_glb, 1), 1)]], &index1, &index2);
+ }
+ ELSE
+ {
+ index1 = L_deposit_l(index[0]); /* this is for very low bitrates, so there is no loss in truncation */
+ index2 = L_deposit_l(0);
+ }
+ IF(index1 == 0)
+ {
+ FOR(i = 0; i < LATTICE_DIM; i++)
+ {
+ x_lvq[i] = 0;
+ move16();
+ }
+ scales_mslvq[0] = 0;
+ }
+ ELSE
+ {
+ IF(GE_32(index1, p_offset_scale1[mode_glb*no_modes + p_no_scales[mode_glb * 2]]))
+ {
+ /* safety check in case of bit errors */
+ set16_fx(x_lvq, 0, 2 * LATTICE_DIM);
+ scales_mslvq[0] = 0;
+ scales_mslvq[1] = 0;
+ return 1;
+ }
+
+ /* find idx_scale */
+ i = 1;
+ move16();
+ WHILE(LE_16(i, p_no_scales[mode_glb * 2]) && GE_32(index1,p_offset_scale1[mode_glb*no_modes + i]))
+ {
+ i = add(i,1);
+ }
+ idx_scale = sub(i,1);
+ move16();
+ index1 = L_sub(index1, p_offset_scale1[tmp + idx_scale]);
+
+ /* find idx_leader */
+ i = 1;
+ move16();
+
+ WHILE(GE_32(index1, table_no_cv_fx[i]))
+ {
+ i = add(i, 1);
+ }
+ im1 = sub(i,1);
+ decode_comb_fx(L_sub(index1,table_no_cv_fx[im1]), x_lvq, im1);
+ scales_mslvq[0] = p_scales[mode_glb*len_scales + idx_scale];
+ }
+
+ /* second subvector */
+ IF(index2 == 0)
+ {
+ FOR(i = LATTICE_DIM; i < 2 * LATTICE_DIM; i++)
+ {
+ x_lvq[i] = 0;
+ move16();
+ }
+ scales_mslvq[1] = 0;
+ move16();
+ }
+ ELSE
+ {
+ /* find the index for the scale/truncation */
+ i = 1;
+ move16();
+ WHILE(GE_32(index2, p_offset_scale2[tmp + i]))
+ {
+ i = add(i, 1);
+ }
+
+ idx_scale = sub(i,1);
+ index2 = L_sub(index2, p_offset_scale2[add(tmp,idx_scale)]);
+ /* find the index of the leader vector */
+ i = 1;
+ move16();
+ WHILE(GE_32(index2, table_no_cv_fx[i]))
+ {
+ i = add(i, 1);
+ }
+ im1 = sub(i,1);
+ decode_comb_fx(index2 - table_no_cv_fx[im1], &x_lvq[LATTICE_DIM], im1);
+ scales_mslvq[1] = p_scales[add(i_mult2(mode_glb,len_scales),add(MAX_NO_SCALES,idx_scale))];
+ move16();
+ }
+
+ return 0;
+}
+
+Word16 deindex_lvq_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 */
+ Word32 *p_offset_scale1, /* i : offset for first subvector */
+ Word32 *p_offset_scale2, /* i : offset for the second subvector */
+ Word16 *p_no_scales /* i : number of scales for each truncation and each MSLVQ structure */
+)
+{
+ Word16 i;
+ const Word16 * p_scales;
+ Word16 mode_glb;
+ Word32 L_tmp;
+ //note_ : renamed from scales
+ Word16 scales_mslvq[2];
+ Word16 ber_flag;
+
+ IF(EQ_16(sf_flag, 1))
+ {
+ mode_glb = add(offset_lvq_modes_SN_fx[mode], offset_in_lvq_mode_SN_fx[mode][sub(no_bits, min_lat_bits_SN_fx[mode])]);
+ p_scales = &scales_fx[0][0];
+ move16();
+ }
+ ELSE
+ {
+ mode_glb = add(offset_lvq_modes_pred_fx[mode], offset_in_lvq_mode_pred_fx[mode][sub(no_bits,min_lat_bits_pred_fx[mode])]);
+ p_scales = &scales_p_fx[0][0];
+ move16();
+ }
+
+ /* decode the lattice index into the lattice codevectors for the two subvectors */
+ 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); /* x_lvq is here Q1 */
+
+
+ IF(EQ_16(sf_flag, 1))
+ {
+ /* safety-net case*/
+ IF(scales_mslvq[0])
+ {
+ FOR(i = 0; i < LATTICE_DIM; i++)
+ {
+ L_tmp = L_mult(x_lvq[i], scales_mslvq[0]); /* Q1+Q11+Q1 = Q13 */
+ /* Increase calculation accuracy by shifting more to the left and using rounding instead of truncation*/
+ 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);
+ }
+ }
+ IF(scales_mslvq[1])
+ {
+ 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);
+ }
+ }
+ }
+ ELSE
+ {
+ /* predictive mode AR or MA */
+ IF(scales_mslvq[0])
+ {
+ 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 */
+ x_lvq[i] = round_fx(L_tmp);
+
+ }
+ }
+ IF(scales_mslvq[1])
+ {
+ 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 */
+ x_lvq[i] = round_fx(L_tmp);
+ }
+ }
+ }
+
+ return ber_flag;
+}
+
+/*----------------------------------------------------------------------------------------------------*
+ * 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_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 */
+ Word32 * p_offset_scale1, /* i: scale index offset for first LSF subvector */
+ Word32 * p_offset_scale2, /* i: scale index offset for second LSF subvector */
+ Word16 * p_no_scales /* i: number of scales for each MSLVQ structure and each subvector */
+)
+{
+ 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, idx_cv);
+ mode = add(LVQ_COD_MODES, idx_cv);
- limit = add(dim, no_new_val);
- FOR(i = 0; i < limit; i++)
- {
- occ[i] = 0;
- move16();
- }
+ p_scales = &scales_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);
- FOR(i = 0; i < no_new_val; i++)
+ FOR(i = 0; i < LATTICE_DIM; i++)
{
- cv_out[p[i]] = val;
- move16();
- occ[p[i]] = 1;
- move16();
+ 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);
}
-
- cnt = 0;
- move16();
- FOR(i = 0; i < limit; i++)
+ FOR(i = LATTICE_DIM; i < 2 * LATTICE_DIM; i++)
{
- if (occ[i] == 0)
- {
- cv_out[i] = cv[cnt++];
- move16();
- }
+ 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);
}
- FOR(i = 0; i < limit; i++)
+ /* check if permutting needed */
+ IF(cng_sort[idx_cv])
{
- cv[i] = cv_out[i];
- move16();
+ permute_fx(x_lvq, perm_MSLVQ[idx_cv]);
}
- return;
+ return ber_flag;
}
+
+/* combinatorial indexing */
static void idx2c_fx(
Word16 n, /* i : total number of positions (components)*/
Word16 *p, /* o : array with positions of the k components */
@@ -141,68 +541,128 @@ static void idx2c_fx(
return;
}
-
-static Word16 divide_16_16_fx(Word16 y, /* i */
- Word16 x, /* i */
- Word16 *rem /* o */
+/* combinatorial deindexing */
+static void decode_comb_fx(
+ Word32 index, /* i : index to be decoded */
+ Word16 *cv, /* o : decoded codevector Q1*/
+ Word16 idx_lead /* i : leader class index */
)
{
- Word16 result, t, tmp;
- Word16 i, ny, nx, nyx;
+ Word16 idx_sign;
+ idx_sign = extract_l(div_l(L_shl(index, 1), pi0[idx_lead])); /*(index/pi0_fx[idx_lead]); */
+ index = L_sub(index, L_mult0(idx_sign, pi0[idx_lead]));
+ decode_leaders_fx(extract_l(index), idx_lead, cv);
+ decode_sign_pc1_fx(cv, idx_sign, pl_par[idx_lead]);
- IF(LT_32(y, x))
+ return;
+}
+void decode_sign_pc1_fx(
+ Word16 *c, /* o : decoded codevector Q1*/
+ Word16 idx_sign, /* i : sign index */
+ Word16 parity /* i : parity flag (+1/-1/0) */
+)
+{
+ Word16 i, len = LATTICE_DIM, cnt_neg = 1;
+
+ if (parity)
{
- result = 0;
- move16();
- *rem = y;
- move16();
+ len = sub(len, 1);
}
- ELSE
- {
- result = 0;
- move16();
- IF(y == 0)
- {
- ny = 0;
- move16();
- }
- ELSE
+ FOR(i = 0; i < len; i++)
+ {
+ IF(c[i] > 0)
{
- ny = sub(15, norm_s(y));
+ /*if (idx_sign % 2) */
+ IF(s_and(idx_sign, 1))
+ {
+ c[i] = negate(c[i]);
+ move16();
+ cnt_neg = negate(cnt_neg);
+ move16();
+ }
+ idx_sign = shr(idx_sign, 1); /* >>= 1; */
}
- IF(x == 0)
+ }
+
+ IF(LT_16(len, LATTICE_DIM))
+ {
+ IF(NE_16(cnt_neg, parity))
{
- nx = 0;
+ c[len] = negate(c[len]);
move16();
}
- ELSE
- {
- nx = sub(15, norm_s(x));
- }
+ }
- nyx = sub(ny,nx);
+ return;
+}
- t = s_and(shr(y, add(nyx,1)),sub(shl(1,sub(nx,1)),1));
- FOR(i = 0; i <= nyx; i++)
- {
- t = add(shl(t,1), s_and(shr(y,sub(nyx,i)),1)); /* L_and(y,L_shl(1, sub(nyx,i)))); */
- result = shl(result,1);
- tmp = sub(t,x);
- IF(tmp >= 0)
- {
- result = add(result,1);
- t = tmp;
- move16();
- }
- }
- *rem = t;
+
+static void decode_leaders_fx(
+ Word16 index, /* i : index to be decoded */
+ Word16 idx_lead, /* i : leader class index */
+ Word16 *cv /* o : decoded codevector Q1*/
+)
+{
+ Word16 i, no_vals_loc, no_vals_last, p[LATTICE_DIM], dim_loc, n_crt;
+ Word16 index1;
+ Word16 val_crt;
+
+ no_vals_loc = no_vals[idx_lead];
+ move16();
+ val_crt = vals_fx[idx_lead][no_vals_loc - 1];
+ move16(); /*Q1 */
+ no_vals_last = no_vals_ind[idx_lead][no_vals_loc - 1];
+ move16();
+
+ FOR(i = 0; i < no_vals_last; i++)
+ {
+ cv[i] = val_crt;
+ move16(); /*Q1 */
+ }
+
+ val_crt = 1;
+ move16();
+ dim_loc = no_vals_last;
+ move16();
+
+ SWITCH(no_vals_loc)
+ {
+ case 1:
+ BREAK;
+ case 2:
+ idx2c_fx(LATTICE_DIM, p, no_vals_ind[idx_lead][0], index);
+ put_value_fx(cv, p, vals_fx[idx_lead][0], no_vals_last, no_vals_ind[idx_lead][0]);
+ BREAK;
+ case 4:
+ dim_loc = add(dim_loc, no_vals_ind[idx_lead][2]);
+ n_crt = no_vals_ind[idx_lead][2];
+ index1 = divide_16_16_fx(index, C_VQ[dim_loc][n_crt], &index); /* index1 = index/C_VQ_fx[dim_loc][n_crt]; */
+ /*index = sub(index, i_mult2(index1, C_VQ_fx[dim_loc][n_crt]) ); */ /* index-= index1*C_VQ_fx[dim_loc][n_crt]; */ move16();
+ idx2c_fx(dim_loc, p, n_crt, index);
+ put_value_fx(cv, p, vals_fx[idx_lead][2], no_vals_last, no_vals_ind[idx_lead][2]); /* Q1 */
+ index = index1;
+ move16();
+ /* no break */
+ case 3:
+ dim_loc = add(dim_loc, no_vals_ind[idx_lead][1]);
+ n_crt = no_vals_ind[idx_lead][1];
+ move16();
+ index1 = divide_16_16_fx(index, C_VQ[dim_loc][n_crt], &index);
+ /*index = sub(index, i_mult2(index1, C_VQ_fx[dim_loc][n_crt]));move16(); */
+ idx2c_fx(dim_loc, p, n_crt, index);
+ put_value_fx(cv, p, vals_fx[idx_lead][1], sub(dim_loc, n_crt), n_crt);
+ idx2c_fx(LATTICE_DIM, p, no_vals_ind[idx_lead][0], index1);
move16();
+ put_value_fx(cv, p, vals_fx[idx_lead][0], dim_loc, no_vals_ind[idx_lead][0]);
+ BREAK;
}
- return result;
+
+ return;
}
+/* divide_32_32_fx() :Division reminder - rem is the reminder of the division between y and x. */
static Word32 divide_32_32_fx(Word32 y, /* i */
Word32 x, /* i */
Word32 *rem /* o */
@@ -262,108 +722,66 @@ static Word32 divide_32_32_fx(Word32 y, /* i */
return result;
}
-static void decode_leaders_fx(
- Word16 index, /* i : index to be decoded */
- Word16 idx_lead, /* i : leader class index */
- Word16 *cv /* o : decoded codevector Q1*/
+/* divide_32_32_fx() :Division reminder for Word16 - rem is the reminder of the division between y and x. */
+static Word16 divide_16_16_fx(Word16 y, /* i */
+ Word16 x, /* i */
+ Word16 *rem /* o */
)
{
- Word16 i, no_vals_loc, no_vals_last, p[LATTICE_DIM], dim_loc, n_crt;
- Word16 index1;
- Word16 val_crt;
-
- no_vals_loc = no_vals[idx_lead];
- move16();
- val_crt = vals_fx[idx_lead][no_vals_loc - 1];
- move16(); /*Q1 */
- no_vals_last = no_vals_ind[idx_lead][no_vals_loc - 1];
- move16();
-
- FOR(i = 0; i < no_vals_last; i++)
- {
- cv[i] = val_crt;
- move16(); /*Q1 */
- }
+ Word16 result, t, tmp;
+ Word16 i, ny, nx, nyx;
- val_crt = 1;
- move16();
- dim_loc = no_vals_last;
- move16();
- SWITCH(no_vals_loc)
+ IF(LT_32(y, x))
{
- case 1:
- BREAK;
- case 2:
- idx2c_fx(LATTICE_DIM, p, no_vals_ind[idx_lead][0], index);
- put_value_fx(cv, p, vals_fx[idx_lead][0], no_vals_last, no_vals_ind[idx_lead][0]);
- BREAK;
- case 4:
- dim_loc = add(dim_loc, no_vals_ind[idx_lead][2]);
- n_crt = no_vals_ind[idx_lead][2];
- index1 = divide_16_16_fx(index, C_VQ[dim_loc][n_crt], &index); /* index1 = index/C_VQ[dim_loc][n_crt]; */
- /*index = sub(index, i_mult2(index1, C_VQ[dim_loc][n_crt]) ); */ /* index-= index1*C_VQ[dim_loc][n_crt]; */ move16();
- idx2c_fx(dim_loc, p, n_crt, index);
- put_value_fx(cv, p, vals_fx[idx_lead][2], no_vals_last, no_vals_ind[idx_lead][2]); /* Q1 */
- index = index1;
- move16();
- /* no break */
- case 3:
- dim_loc = add(dim_loc, no_vals_ind[idx_lead][1]);
- n_crt = no_vals_ind[idx_lead][1];
+ result = 0;
move16();
- index1 = divide_16_16_fx(index, C_VQ[dim_loc][n_crt], &index);
- /*index = sub(index, i_mult2(index1, C_VQ[dim_loc][n_crt]));move16(); */
- idx2c_fx(dim_loc, p, n_crt, index);
- put_value_fx(cv, p, vals_fx[idx_lead][1], sub(dim_loc, n_crt), n_crt);
- idx2c_fx(LATTICE_DIM, p, no_vals_ind[idx_lead][0], index1);
+ *rem = y;
move16();
- put_value_fx(cv, p, vals_fx[idx_lead][0], dim_loc, no_vals_ind[idx_lead][0]);
- BREAK;
}
+ ELSE
+ {
- return;
-}
-
-void decode_sign_pc1_fx(
- Word16 *c, /* o : decoded codevector Q1*/
- Word16 idx_sign, /* i : sign index */
- Word16 parity /* i : parity flag (+1/-1/0) */
-)
-{
- Word16 i, len = LATTICE_DIM, cnt_neg = 1;
+ result = 0;
+ move16();
+ IF(y == 0)
+ {
+ ny = 0;
+ move16();
+ }
+ ELSE
+ {
+ ny = sub(15, norm_s(y));
+ }
+ IF(x == 0)
+ {
+ nx = 0;
+ move16();
+ }
+ ELSE
+ {
+ nx = sub(15, norm_s(x));
+ }
- if (parity)
- {
- len = sub(len, 1);
- }
+ nyx = sub(ny,nx);
- FOR(i = 0; i < len; i++)
- {
- IF(c[i] > 0)
+ t = s_and(shr(y, add(nyx,1)),sub(shl(1,sub(nx,1)),1));
+ FOR(i = 0; i <= nyx; i++)
{
- /*if (idx_sign % 2) */
- IF(s_and(idx_sign, 1))
+ t = add(shl(t,1), s_and(shr(y,sub(nyx,i)),1)); /* L_and(y,L_shl(1, sub(nyx,i)))); */
+ result = shl(result,1);
+ tmp = sub(t,x);
+ IF(tmp >= 0)
{
- c[i] = negate(c[i]);
- move16();
- cnt_neg = negate(cnt_neg);
+ result = add(result,1);
+ t = tmp;
move16();
}
- idx_sign = shr(idx_sign, 1); /* >>= 1; */
- }
- }
-
- IF(LT_16(len, LATTICE_DIM))
- {
- IF(NE_16(cnt_neg, parity))
- {
- c[len] = negate(c[len]);
- move16();
}
+ *rem = t;
+ move16();
}
-
- return;
+ return result;
}
static void divide_64_32_fx(
@@ -416,245 +834,48 @@ static void divide_64_32_fx(
return;
}
-static void decode_comb_fx(
- Word32 index, /* i : index to be decoded */
- Word16 *cv, /* o : decoded codevector Q1*/
- Word16 idx_lead /* i : leader class index */
-)
-{
- Word16 idx_sign;
-
- idx_sign = extract_l(div_l(L_shl(index, 1), pi0[idx_lead])); /*(index/pi0[idx_lead]); */
- index = L_sub(index, L_mult0(idx_sign, pi0[idx_lead]));
- decode_leaders_fx(extract_l(index), idx_lead, cv);
- decode_sign_pc1_fx(cv, idx_sign, pl_par[idx_lead]);
-
- return;
-}
-
-static Word16
-decode_indexes_fx(
- Word16 * index, /* i: LSF vector index, written as array of Word16 because it generally uses more than 16 bits */
- Word16 no_bits, /* i: number of bits for the index */
- const Word16 * p_scales, /* i: scale values for the MSLVQ structures */
- Word16 * p_no_scales, /* i: number of truncations for each MSLVQ structure */
- Word32 * p_offset_scale1, /* i: scale index offset for first LSF subvector */
- Word32 * p_offset_scale2, /* i: scale index offset for second LSF subvector */
- Word16 * x_lvq, /* o: decoded LSF vector in Q1 */
- Word16 mode_glb, /* i: index of LSLVQ structure */
- Word16 * inp_scales /* o: scale values for the decoded MSLVQ LSF codevector */
+static void put_value_fx(
+ Word16 *cv, /* i/o : input codevector Q1*/
+ Word16 *p, /* i : array with positions */
+ Word16 val, /* i : value to be inserted Q1*/
+ Word16 dim, /* i : vector dimension */
+ Word16 no_new_val /* i : number of values to be inserted */
)
{
- Word32 index1 = 0, index2 = 0;
- Word16 len_scales = MAX_NO_SCALES * 2, no_modes;
- Word16 i, im1, idx_scale;
- Word16 tmp;
-
- no_modes = MAX_NO_SCALES + 1;
- move16();
+ Word16 cv_out[LATTICE_DIM];
+ Word16 i, occ[LATTICE_DIM], cnt, limit;
- IF(LE_16(no_bits, shl(LEN_INDICE, 1))) /* the third short is not used */
+ limit = add(dim, no_new_val);
+ FOR(i = 0; i < limit; i++)
{
- index[2] = 0;
+ occ[i] = 0;
move16();
- if (LE_16(no_bits, LEN_INDICE))
- {
- index[1] = 0;
- move16();
- }
- }
-
- /* safety check in case of bit errors */
- FOR(i = 0; i < 3; i++)
- {
- IF(index[i] < 0)
- {
- set16_fx(x_lvq, 0, 2 * LATTICE_DIM);
- inp_scales[0] = 0;
- inp_scales[1] = 0;
- index[i] = 0;
- return 1;
- }
- }
-
- /* first subvector */
- tmp = i_mult2(mode_glb, no_modes);
-
- IF(p_offset_scale2[add(tmp, p_no_scales[add(shl(mode_glb, 1), 1)])] > 0)
- {
- divide_64_32_fx(index, p_offset_scale2[tmp + p_no_scales[add(shl(mode_glb, 1), 1)]], &index1, &index2);
- }
- ELSE
- {
- index1 = L_deposit_l(index[0]); /* this is for very low bitrates, so there is no loss in truncation */
- index2 = L_deposit_l(0);
- }
- IF(index1 == 0)
- {
- FOR(i = 0; i < LATTICE_DIM; i++)
- {
- x_lvq[i] = 0;
- move16();
- }
- inp_scales[0] = 0;
- }
- ELSE
- {
- IF(GE_32(index1, p_offset_scale1[mode_glb*no_modes + p_no_scales[mode_glb * 2]]))
- {
- /* safety check in case of bit errors */
- set16_fx(x_lvq, 0, 2 * LATTICE_DIM);
- inp_scales[0] = 0;
- inp_scales[1] = 0;
- return 1;
}
- /* find idx_scale */
- i = 1;
- move16();
- WHILE(LE_16(i, p_no_scales[mode_glb * 2]) && GE_32(index1,p_offset_scale1[mode_glb*no_modes + i]))
+ FOR(i = 0; i < no_new_val; i++)
{
- i = add(i,1);
+ cv_out[p[i]] = val;
+ move16();
+ occ[p[i]] = 1;
+ move16();
}
- idx_scale = sub(i,1);
- move16();
- index1 = L_sub(index1, p_offset_scale1[tmp + idx_scale]);
- /* find idx_leader */
- i = 1;
+ cnt = 0;
move16();
-
- WHILE(GE_32(index1, table_no_cv[i]))
- {
- i = add(i, 1);
- }
- im1 = sub(i,1);
- decode_comb_fx(L_sub(index1,table_no_cv[im1]), x_lvq, im1);
- inp_scales[0] = p_scales[mode_glb*len_scales + idx_scale];
- }
-
- /* second subvector */
- IF(index2 == 0)
+ FOR(i = 0; i < limit; i++)
{
- FOR(i = LATTICE_DIM; i < 2 * LATTICE_DIM; i++)
+ if (occ[i] == 0)
{
- x_lvq[i] = 0;
+ cv_out[i] = cv[cnt++];
move16();
}
- inp_scales[1] = 0;
- move16();
- }
- ELSE
- {
- /* find the index for the scale/truncation */
- i = 1;
- move16();
- WHILE(GE_32(index2, p_offset_scale2[tmp + i]))
- {
- i = add(i, 1);
- }
-
- idx_scale = sub(i,1);
- index2 = L_sub(index2, p_offset_scale2[add(tmp,idx_scale)]);
- /* find the index of the leader vector */
- i = 1;
- move16();
- WHILE(GE_32(index2, table_no_cv[i]))
- {
- i = add(i, 1);
- }
- im1 = sub(i,1);
- decode_comb_fx(index2 - table_no_cv[im1], &x_lvq[LATTICE_DIM], im1);
- inp_scales[1] = p_scales[add(i_mult2(mode_glb,len_scales),add(MAX_NO_SCALES,idx_scale))];
- move16();
}
- return 0;
-}
-
-Word16 deindex_lvq_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 */
- Word32 *p_offset_scale1, /* i : offset for first subvector */
- Word32 *p_offset_scale2, /* i : offset for the second subvector */
- Word16 *p_no_scales /* i : number of scales for each truncation and each MSLVQ structure */
-)
-{
- Word16 i;
- const Word16 * p_scales;
- Word16 mode_glb;
- Word32 L_tmp;
- Word16 scales_arr[2];
- Word16 ber_flag;
-
- IF(EQ_16(sf_flag, 1))
- {
- mode_glb = add(offset_lvq_modes_SN[mode], offset_in_lvq_mode_SN[mode][sub(no_bits, min_lat_bits_SN[mode])]);
- p_scales = &scales_fx[0][0];
- move16();
- }
- ELSE
+ FOR(i = 0; i < limit; i++)
{
- mode_glb = add(offset_lvq_modes_pred_fx[mode], offset_in_lvq_mode_pred[mode][sub(no_bits,min_lat_bits_pred[mode])]);
- p_scales = &scales_p_fx[0][0];
+ cv[i] = cv_out[i];
move16();
}
- /* decode the lattice index into the lattice codevectors for the two subvectors */
- ber_flag =
- decode_indexes_fx(index, no_bits, p_scales, p_no_scales, p_offset_scale1,
- p_offset_scale2, x_lvq, mode_glb, scales_arr); /* x_lvq is here Q1 */
-
-
- IF(EQ_16(sf_flag, 1))
- {
- /* safety-net case*/
- IF(scales_arr[0])
- {
- FOR(i = 0; i < LATTICE_DIM; i++)
- {
- L_tmp = L_mult(x_lvq[i], scales_arr[0]); /* Q1+Q11+Q1 = Q13 */
- /* Increase calculation accuracy by shifting more to the left and using rounding instead of truncation*/
- 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);
- }
- }
- IF(scales_arr[1])
- {
- FOR(i = LATTICE_DIM; i < 2 * LATTICE_DIM; i++)
- {
- L_tmp = L_mult(x_lvq[i], scales_arr[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);
- }
- }
- }
- ELSE
- {
- /* predictive mode AR or MA */
- IF(scales_arr[0])
- {
- FOR(i = 0; i < LATTICE_DIM; i++)
- {
- L_tmp = L_mult(x_lvq[i],scales_arr[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 */
- x_lvq[i] = round_fx(L_tmp);
-
- }
- }
- IF(scales_arr[1])
- {
- FOR(i = LATTICE_DIM; i < 2 * LATTICE_DIM; i++)
- {
- L_tmp = L_mult(x_lvq[i],scales_arr[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 */
- x_lvq[i] = round_fx(L_tmp);
- }
- }
- }
-
- return ber_flag;
+ return;
}
\ No newline at end of file
diff --git a/lib_com/nelp_fx.c b/lib_com/nelp_fx.c
new file mode 100644
index 0000000000000000000000000000000000000000..c1619501f4a61b3d990eb86e5469a59a9d7ded7d
--- /dev/null
+++ b/lib_com/nelp_fx.c
@@ -0,0 +1,247 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 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.
+
+*******************************************************************************************************/
+
+#include
+#include "options.h"
+#include "rom_com.h"
+#include "prot_fx2.h"
+
+
+
+/*===================================================================*/
+/* FUNCTION : dequantize_uvg_fx() */
+/*-------------------------------------------------------------------*/
+/* PURPOSE : This function returns the quantized gain
+ vector given the indices in the gain
+ quantization tables */
+/*-------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (Word16) iG1 : index into UVG1CB_fx table (Q0) */
+/* _ (Word16*) iG2 : indices into UVG2CB_fx (Q0) */
+/* - (Word32) Fs : output sampling rate */
+/*-------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ (Word16*) G : Output quantized gain vector */
+/*-------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _ None. */
+/*-------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : */
+/* _ None. */
+/*===================================================================*/
+Word16 dequantize_uvg_fx(
+ const Word16 iG1, /* i: gain 1 index */
+ const Word16* iG2, /* i: gain 2 index */
+ Word16* G, /* o: quantized gain */
+ const Word16 bwidth_fx, /* i: bandwidth */
+ const Word16 do_scale
+)
+{
+ Word16 i, k;
+ const Word16(*UVG1CB)[2] = NULL;
+ const Word16(*UVG2CB1)[5] = NULL;
+ const Word16(*UVG2CB2)[5] = NULL;
+ Word16 frac, exp, sc;
+ Word32 L_tmp;
+ Word16 Q_gain = 0;
+
+ IF(EQ_16(bwidth_fx, NB))
+ {
+ UVG1CB = UVG1CB_NB_FX;
+ move16();
+ UVG2CB1 = UVG2CB1_NB_FX;
+ move16();
+ UVG2CB2 = UVG2CB2_NB_FX;
+ move16();
+ }
+ ELSE IF(EQ_16(bwidth_fx, WB) || EQ_16(bwidth_fx, SWB))
+ {
+ test();
+ UVG1CB = UVG1CB_WB_FX;
+ move16();
+ UVG2CB1 = UVG2CB1_WB_FX;
+ move16();
+ UVG2CB2 = UVG2CB2_WB_FX;
+ move16();
+ }
+
+ IF(!do_scale)
+ {
+ sc = 11;
+ move16();
+ }
+ ELSE
+ {
+ test();
+ IF((LT_16(UVG1CB[iG1][0], 4096)) && (LT_16(UVG1CB[iG1][1],4096))) /* if x < 1, where 10^x is used for gain computation */
+ {
+ sc = 8;
+ move16();
+ Q_gain = 3;
+ move16();
+ }
+ ELSE
+ {
+ sc = 11;
+ move16();
+ }
+ }
+
+ FOR(i = 0; i < 2; i++)
+ {
+ FOR(k = 0; k < 5; k++)
+ {
+ IF(i == 0)
+ {
+ /* pow(10.0, UVG1CB[iG1][i]) = pow(2.0,UVG1CB[iG1][i]*3.321928 */
+ L_tmp = L_mult(UVG1CB[iG1][i], 27213); /* Q(13+13+1)->Q27 */
+ L_tmp = L_shr_r(L_tmp, 11); /* Q16 */
+ frac = L_Extract_lc(L_tmp, &exp);
+ frac = extract_l(Pow2(14, frac));
+ G[i * 5 + k] = round_fx(L_shl(L_mult(frac, UVG2CB1[iG2[i]][k]), exp - sc)); /* Q0 */
+ }
+ ELSE IF(EQ_16(i, 1))
+ {
+ L_tmp = L_mult(UVG1CB[iG1][i], 27213); /* Q(13+13+1)->Q27 */
+ L_tmp = L_shr_r(L_tmp, 11); /* Q16 */
+ frac = L_Extract_lc(L_tmp, &exp);
+ frac = extract_l(Pow2(14, frac));
+ G[i * 5 + k] = round_fx(L_shl(L_mult(frac, UVG2CB2[iG2[i]][k]), exp - sc)); /* Q0 */
+ }
+ }
+ }
+ return Q_gain;
+}
+
+/*===================================================================*/
+/* FUNCTION : generate_nelp_excitation_fx */
+/*-------------------------------------------------------------------*/
+/* PURPOSE : This function computes the random
+ excitation scaled by gain */
+/*-------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (Word16*) Gains : Gain vector (Q_exc) */
+/* _ (Word16) gain_fac : gain factor (Q14) */
+/*-------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ (Word16*) seed : Random seed (Q0) */
+/* _ (Word16*) output : excitation output (Q_exc) */
+/*-------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _ None. */
+/*-------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : */
+/* _ None. */
+/*===================================================================*/
+void generate_nelp_excitation_fx(
+ Word16 *seed, /* i/o: random number seed */
+ const Word16 *Gains, /* i : excitation gains Q_exc*/
+ Word16 *output, /* o : excitation output */
+ const Word16 gain_fac /* i : gain factor */
+)
+{
+ Word16 i, len, j;
+ Word16 tmp[31], tmp1[31], tmpf, L16;
+ Word16 k1, k2, I[31], tmpi;
+ Word32 L32;
+ Word16 cnt;
+
+ FOR(i = 0; i < 10; i++)
+ {
+ IF(EQ_16(i, 9))
+ {
+ len = 31;
+ move16();
+ cnt = 8;
+ move16();
+ }
+ ELSE
+ {
+ len = 25;
+ move16();
+ cnt = 6;
+ move16();
+ }
+
+ FOR(j = 0; j < len; j++)
+ {
+ L32 = L_mult0(*seed, 0x0209); /* L32 = *seed*521; */
+
+ L16 = extract_l(L_add(L32, 259));
+ *seed = L16;
+ move16(); /* Q0 */
+ tmp[j] = *seed;
+ move16(); /* Q15, tmp[j]=*seed/32768 */
+
+ tmp1[j] = abs_s(tmp[j]);
+ I[j] = j;
+ move16();
+ }
+
+ j = sub(len, 1);
+ FOR(k1 = 0; k1 < j; k1++)
+ {
+ FOR(k2 = add(k1, 1); k2 < len; k2++)
+ {
+ IF(GT_16(tmp1[k2], tmp1[k1]))
+ {
+ tmpi = I[k2];
+ move16();
+ tmpf = tmp1[k2];
+ move16();
+ tmp1[k2] = tmp1[k1];
+ move16();
+ I[k2] = I[k1];
+ move16();
+ tmp1[k1] = tmpf;
+ move16();
+ I[k1] = tmpi;
+ move16();
+ }
+ }
+ }
+
+ /*using a factor of 1.37 to compensate for the ~ 2.5 ( or 2.73) dB diff between this scheme and EVS-UV */
+ FOR(j = 0; j < cnt; j++)
+ {
+ L16 = mult_r(tmp[I[j]], gain_fac); /* Q14 */
+ L16 = mult_r(L16, 0x6EDA); /* Q13 */
+
+ output[i * 25 + I[j]] = round_fx(L_shl(L_mult(L16, Gains[i]), 2)); /* Q_exc */
+ }
+ FOR(; j < len; j++)
+ {
+ output[i * 25 + I[j]] = 0;
+ move16();
+ }
+ }
+}
diff --git a/lib_com/oper_32b.c b/lib_com/oper_32b.c
index 7753c9ae93c46f64a80af5d389c4d4c83977417a..de85bc267e058523a64a78f9d61e36fbba89d7f9 100644
--- a/lib_com/oper_32b.c
+++ b/lib_com/oper_32b.c
@@ -47,36 +47,29 @@ void L_Extract (Word32 L_32, Word16 *hi, Word16 *lo)
return;
}
-static __inline Word16 L_Extract_lc(const Word32 L_32, Word16 *p_hi)
+/*****************************************************************************
+ * *
+ * Function L_Extract_lc() *
+ * *
+ * Extract from a 32 bit integer two 16 bit DPF. *
+ * (lo is returned, store to memory is not accounted for) *
+ * *
+ * Arguments: *
+ * *
+ * L_32 : 32 bit integer. *
+ * 0x8000 0000 <= L_32 <= 0x7fff ffff. *
+ * hi : b16 to b31 of L_32 *
+ * lo : (L_32 - hi<<16)>>1 *
+ *****************************************************************************
+*/
+
+Word16 L_Extract_lc (Word32 L_32, Word16 *hi)
{
- *p_hi = extract_h(L_32);
- return lshr(extract_l(L_32), 1);
+ *hi = extract_h (L_32);
+ return lshr(extract_l(L_32), 1);
}
-///*****************************************************************************
-// * *
-// * Function L_Extract_lc() *
-// * *
-// * Extract from a 32 bit integer two 16 bit DPF. *
-// * (lo is returned, store to memory is not accounted for) *
-// * *
-// * Arguments: *
-// * *
-// * L_32 : 32 bit integer. *
-// * 0x8000 0000 <= L_32 <= 0x7fff ffff. *
-// * hi : b16 to b31 of L_32 *
-// * lo : (L_32 - hi<<16)>>1 *
-// *****************************************************************************
-//*/
-//
-//Word16 L_Extract_lc (Word32 L_32, Word16 *hi)
-//{
-// *hi = extract_h (L_32);
-//
-// return lshr(extract_l(L_32), 1);
-//}
-
/*****************************************************************************
* *
* Function L_Comp() *
diff --git a/lib_com/oper_32b.h b/lib_com/oper_32b.h
index 9fa3328ab4924072e4b79d1ce8039b672e5121da..70d1c59dbd989669878651ca1654d9311631bfdd 100644
--- a/lib_com/oper_32b.h
+++ b/lib_com/oper_32b.h
@@ -4,7 +4,7 @@
#define _OPER_32b_H
void L_Extract (Word32 L_32, Word16 *hi, Word16 *lo);
-//Word16 L_Extract_lc (Word32 L_32, Word16 *hi);
+Word16 L_Extract_lc (Word32 L_32, Word16 *hi);
Word32 L_Comp (Word16 hi, Word16 lo);
Word32 Mpy_32 (Word16 hi1, Word16 lo1, Word16 hi2, Word16 lo2);
Word32 Mac_32 (Word32 L_num, Word16 hi1, Word16 lo1, Word16 hi2, Word16 lo2);
diff --git a/lib_com/ppp_fx.c b/lib_com/ppp_fx.c
new file mode 100644
index 0000000000000000000000000000000000000000..167f5809ab493c4ca179e6634df934e19eeb272d
--- /dev/null
+++ b/lib_com/ppp_fx.c
@@ -0,0 +1,152 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 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.
+
+*******************************************************************************************************/
+
+#include
+#include "options.h"
+#include "cnst.h"
+#include "prot_fx2.h"
+
+ /*===================================================================*/
+ /* FUNCTION : Interpol_delay_fx () */
+ /*-------------------------------------------------------------------*/
+ /* PURPOSE : Interpolate pitch lag for a subframe */
+ /*-------------------------------------------------------------------*/
+ /* INPUT ARGUMENTS : */
+ /* _ (Word16) last_fx: previous frame delay, Q0 */
+ /* _ (Word16) current_fx: current frame delay, Q0 */
+ /* _ (Word16) SubNum : subframe number */
+ /*-------------------------------------------------------------------*/
+ /* OUTPUT ARGUMENTS : */
+ /* */
+ /* _ (Word16 []) out_fx : 3 Intepolated delays, Q4 */
+ /*-------------------------------------------------------------------*/
+ /* INPUT/OUTPUT ARGUMENTS : */
+ /* _ None */
+ /*-------------------------------------------------------------------*/
+ /* RETURN ARGUMENTS : _ None. */
+ /*===================================================================*/
+ /* NOTE: this function uses a 5 entry table frac_fx (Q4 unsigned) */
+ /*===================================================================*/
+
+void Interpol_delay_fx(Word16 *out_fx, Word16 last_fx, Word16 current_fx,
+ Word16 SubNum, const Word16* frac_fx)
+{
+ Word16 i, temp;
+ Word32 L_add1, L_add2;
+
+ FOR(i = 0; i < 3; i++)
+ {
+ temp = sub(16, frac_fx[SubNum + i]);/* Q4 */
+ L_add1 = L_shr(L_mult(last_fx, temp), 1);/* Q4 */
+ L_add2 = L_shr(L_mult(current_fx, frac_fx[SubNum + i]), 1);/* Q4 */
+ out_fx[i] = (Word16)L_add(L_add1, L_add2);
+ move16();/* Q4 */
+
+ }
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * deemph_lpc()
+ *
+ * De-emphasis of LP coefficients
+ * convolve LPC with [1 -PREEMPH_FAC] to de-emphasise LPC
+ *--------------------------------------------------------------------*/
+
+void deemph_lpc_fx(
+ const Word16 *p_Aq_curr_fx, /* i : LP coefficients current frame */
+ const Word16 *p_Aq_old_fx, /* i : LP coefficients previous frame */
+ Word16 *LPC_de_curr_fx, /* o : De-emphasized LP coefficients current frame in Q12 */
+ Word16 *LPC_de_old_fx, /* o : De-emphasized LP coefficients previous frame in Q12 */
+ const Word16 deemph_old
+)
+{
+ Word16 k, temp;
+ Word16 b_fx[M + 2];/* Q12 */
+ Word16 a_fx[2] = { -22282, 32767 };/* Q15 {-PREEMPH_FAC,1.0} */
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+ b_fx[0] = 4096;
+ move16();/* 1 in Q12 */
+ FOR(k = 0; k < M; k++)
+ {
+ b_fx[k + 1] = p_Aq_curr_fx[k];
+ move16();/* Q12 */
+ }
+ b_fx[M + 1] = 0;
+ move16();
+
+ FOR(k = 0; k <= M; k++)
+ {
+ /* LPC_de_curr[k] = a[0]*b[k] + a[1]*b[k+1]; */
+ temp = mult(a_fx[0], b_fx[k]);/* Q12 */
+#ifdef BASOP_NOGLOB
+ LPC_de_curr_fx[k] = add_o(temp, b_fx[k + 1], &Overflow);
+#else
+ LPC_de_curr_fx[k] = add(temp, b_fx[k + 1]);
+#endif
+ move16();/* Q12 */
+ }
+
+ IF(EQ_16(deemph_old, 1))
+ {
+
+ /* ignoring the 1st value which is 1.0 in this case */
+ b_fx[0] = 4096;
+ move16();/* 1 in Q12 */
+ FOR(k = 0; k < M; k++)
+ {
+ b_fx[k + 1] = p_Aq_old_fx[k + 1];
+ move16();
+ }
+ b_fx[M + 1] = 0;
+ move16();
+
+ FOR(k = 0; k <= M; k++)
+ {
+ /* LPC_de_old[k] = a[0]*b[k] + a[1]*b[k+1]; */
+ temp = mult(a_fx[0], b_fx[k]);/* Q12 */
+#ifdef BASOP_NOGLOB
+ LPC_de_old_fx[k] = add_o(temp, b_fx[k + 1], &Overflow);
+#else
+ LPC_de_old_fx[k] = add(temp, b_fx[k + 1]);
+#endif
+ move16();/* Q12 */
+ }
+ }
+
+
+ return; /* both outputs LPC_de_curr_fx and LPC_de_old_fx are in Q12 */
+}
+
+
diff --git a/lib_com/preemph_fx.c b/lib_com/preemph_fx.c
new file mode 100644
index 0000000000000000000000000000000000000000..8fc92a9eff0a0988917d2034065df4d006820ea4
--- /dev/null
+++ b/lib_com/preemph_fx.c
@@ -0,0 +1,159 @@
+/*====================================================================================
+ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
+ ====================================================================================*/
+#include
+#include "options.h" /* Compilation switches */
+#include "prot_fx1.h"
+#include "prot_fx2.h"
+/*-------------------------------------------------------------*
+ * preemph_copy_fx()
+ *
+ * Preemphasis: filtering through 1 - mu z^-1
+ *-------------------------------------------------------------*/
+void preemph_copy_fx(
+ const Word16 x[], /* i : input signal Qx */
+ Word16 y[], /* o : output signal Qx */
+ const Word16 mu, /* i : preemphasis coefficient Q15 */
+ const Word16 lg, /* i : vector size Q0 */
+ Word16 *mem /* i/o: memory (x[-1]) Qx */
+)
+{
+ Word16 i, temp;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+ temp = x[lg - 1];
+ move16();
+ FOR (i = sub(lg, 1); i > 0; i--)
+ {
+#ifdef BASOP_NOGLOB
+ y[i] = msu_ro(L_deposit_h(x[i]), x[i - 1], mu, &Overflow);
+#else
+ y[i] = msu_r(L_deposit_h(x[i]), x[i - 1], mu);
+#endif
+ move16();
+ }
+#ifdef BASOP_NOGLOB
+ y[0] = msu_ro(L_deposit_h(x[0]), *mem, mu, &Overflow);
+#else
+ y[0] = msu_r(L_deposit_h(x[0]), *mem, mu);
+#endif
+ move16();
+
+ *mem = temp;
+ move16();
+}
+
+/*
+ * E_UTIL_f_preemph2
+ *
+ * Parameters:
+ * shift I: scale output
+ * signal I/O: signal Qx/Qx+shift
+ * mu I: preemphasis factor Q15
+ * L I: vector size
+ * mem I/O: memory (x[-1])
+ *
+ * Function:
+ * Filtering through 1 - mu z^-1
+ *
+ * Returns:
+ * void
+ */
+void E_UTIL_f_preemph2(Word16 shift, Word16 *signal, const Word16 mu, const Word16 lg, Word16 *mem)
+{
+ Word16 i, temp;
+ Word32 L_tmp;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+ temp = signal[lg - 1];
+ move16();
+
+ FOR (i = sub(lg, 1); i > 0; i--)
+ {
+ L_tmp = L_mult(signal[i], 16384);
+#ifdef BASOP_NOGLOB
+ L_tmp = L_msu0_o(L_tmp, signal[i - 1], mu, &Overflow);
+ L_tmp = L_shl_o(L_tmp, add(shift,1), &Overflow);
+ signal[i] = round_fx_o(L_tmp, &Overflow);
+#else
+ L_tmp = L_msu0(L_tmp, signal[i - 1], mu);
+ L_tmp = L_shl(L_tmp, add(shift,1));
+ signal[i] = round_fx(L_tmp);
+#endif
+ }
+
+ L_tmp = L_mult(signal[0], 16384);
+#ifdef BASOP_NOGLOB
+ L_tmp = L_msu0_o(L_tmp, *mem, mu, &Overflow);
+ L_tmp = L_shl_o(L_tmp, add(shift,1), &Overflow);
+ signal[0] = round_fx_o(L_tmp, &Overflow);
+#else
+ L_tmp = L_msu0(L_tmp, *mem, mu);
+ L_tmp = L_shl(L_tmp, add(shift,1));
+ signal[0] = round_fx(L_tmp);
+#endif
+
+ *mem = temp;
+ move16();
+
+ return;
+}
+
+
+Word16 E_UTIL_f_preemph3(Word16 *signal, const Word16 mu, const Word16 lg, Word16 *mem, Word16 bits)
+{
+ Word16 i, QVal, mus, tmp_fixed, Q_new;
+ Word32 L_tmp, L_maxloc;
+
+
+
+ QVal = shl(1, sub(15,bits));
+ mus = shr(mu, bits);
+
+ L_tmp = L_mult(signal[0], QVal);
+ L_tmp = L_msu(L_tmp, *mem, mus);
+ L_maxloc = L_abs(L_tmp);
+
+ FOR (i = 1; i < lg; i++)
+ {
+ L_tmp = L_mult(signal[i], QVal);
+ L_tmp = L_msu(L_tmp, signal[i - 1], mus);
+ L_tmp = L_abs(L_tmp);
+ L_maxloc = L_max(L_tmp, L_maxloc);
+ }
+
+ tmp_fixed = extract_h(L_maxloc);
+
+ Q_new = Q_MAX;
+ move16();
+ IF (tmp_fixed != 0)
+ {
+ Q_new = sub(norm_s(tmp_fixed), bits);
+ Q_new = s_max(Q_new, 0);
+ Q_new = s_min(Q_new, Q_MAX);
+ }
+
+ tmp_fixed = signal[lg - 1];
+ move16();
+
+ FOR (i = sub(lg,1); i > 0; i--)
+ {
+ L_tmp = L_mult(signal[i], QVal);
+ L_tmp = L_msu(L_tmp, signal[i - 1], mus);
+ L_tmp = L_shl(L_tmp, Q_new);
+ signal[i] = round_fx(L_tmp);
+ }
+
+ L_tmp = L_mult(signal[0], QVal);
+ L_tmp = L_msu(L_tmp, *mem, mus);
+ L_tmp = L_shl(L_tmp, Q_new);
+ signal[0] = round_fx(L_tmp);
+
+ *mem = tmp_fixed;
+ move16();
+
+ return Q_new;
+}
+
diff --git a/lib_com/prot.h b/lib_com/prot.h
index b5103bfaf42dbe73a8061ce5a2846b1e7db4a230..b9d5796a3ad42c3e0ad4eecac0a65c90ceedbb56 100644
--- a/lib_com/prot.h
+++ b/lib_com/prot.h
@@ -114,11 +114,6 @@
} \
} /* Otherwise, the 2nd arg is stored at the address of the first arg. */
-static __inline Word16 L_Extract_lc( const Word32 L_32, Word16 *p_hi )
-{
- *p_hi = extract_h( L_32 );
- return lshr( extract_l( L_32 ), 1 );
-}
/*----------------------------------------------------------------------------------*
* MODE1 prototypes
@@ -1017,7 +1012,7 @@ void syn_filt(
const int16_t update_m /* i : update memory flag: 0 --> no memory update */
); /* 1 --> update of memory */
-void synth_mem_updt2(
+void synth_mem_updt2_flt(
const int16_t L_frame, /* i : frame length */
const int16_t last_L_frame, /* i : frame length */
float old_exc[], /* i/o: excitation buffer */
@@ -1828,7 +1823,7 @@ Word16 ratio_float(
);
/*! r: Angle between 0 and EVS_PI/2 radian (Q14) */
-Word16 atan2_fx(
+Word16 atan2_fx_flt(
const Word32 y, /* i : near side (Argument must be positive) (Q15) */
const Word32 x /* i : opposite side (Q15) */
);
@@ -2016,7 +2011,7 @@ Word16 GetScale_fx(
Word32 *surplus_fx /*Q16*/
);
-void bit_allocation_second_fx(
+void bit_allocation_second_fx2(
Word32 *Rk,
Word32 *Rk_sort,
Word16 BANDS,
@@ -2132,7 +2127,7 @@ void TCQLSBdec(
float *mbuffer,
int16_t bcount );
-void bit_allocation_second_fx(
+void bit_allocation_second_fx2(
Word32 *Rk,
Word32 *Rk_sort,
Word16 BANDS,
@@ -4514,7 +4509,7 @@ void updt_dec_common(
);
void td_cng_dec_init(
- DEC_CORE_HANDLE_FLOAT st /* i/o: decoder state structure */
+ DEC_CORE_HANDLE st /* i/o: decoder state structure */
);
void CNG_dec(
@@ -5739,7 +5734,7 @@ int32_t intLimCDivPos(
);
/*! r: Approximate integer division */
-int16_t shrtCDivSignedApprox(
+int16_t shrtCDivSignedApprox_flt(
const int16_t num, /* i : numerator */
const int16_t den /* i : denominator */
);
@@ -5891,7 +5886,7 @@ void wb_tbe_extras_reset_synth(
float state_lsyn_filt_dwn_shb[],
float mem_resamp_HB[] );
-void tbe_celp_exc(
+void tbe_celp_exc_flt(
const int16_t element_mode, /* i : element mode */
const int16_t idchan, /* i : channel ID */
float *bwe_exc, /* i/o: BWE excitation */
@@ -6642,14 +6637,14 @@ void fcb_pulse_track_joint_decode(
const int16_t *pulse_num,
const int16_t track_num );
-void lag_wind(
+void lag_wind_flt(
float r[], /* i/o: autocorrelations */
const int16_t m, /* i : order of LP filter */
const int32_t sr_core, /* i : sampling rate */
const int16_t strength /* i : LAGW_WEAK, LAGW_MEDIUM, or LAGW_STRONG */
);
-void adapt_lag_wind(
+void adapt_lag_wind_fx(
float r[], /* i/o: autocorrelations */
const int16_t m, /* i : order of LP filter */
const int16_t Top, /* i : open loop pitch lags from curr. frame (or NULL if n/a) */
@@ -8671,7 +8666,7 @@ void deleteFdCngDec(
HANDLE_FD_CNG_DEC *hFdCngDec );
void initFdCngDec(
- DEC_CORE_HANDLE_FLOAT st /* i/o: decoder state structure */
+ DEC_CORE_HANDLE st /* i/o: decoder state structure */
);
void configureFdCngDec(
@@ -9301,7 +9296,7 @@ void tcx5TnsUngrouping(
float *spectrum,
const int16_t enc_dec );
-void lerp(
+void lerp_flt(
const float *f,
float *f_out,
const int16_t bufferNewSize,
@@ -9973,7 +9968,7 @@ void IGFSCFDecoderDecode(
);
/*! r: offset value */
-int16_t tbe_celp_exc_offset(
+int16_t tbe_celp_exc_offset_flt(
const int16_t T0, /* i : Integer pitch */
const int16_t T0_frac /* i : Fractional part of the pitch */
);
diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h
index 49ddc41fe6c5c0237db07ed58108085b9202f656..04a7ec065c11b4a4f47cc25ebd68032445119635 100644
--- a/lib_com/prot_fx2.h
+++ b/lib_com/prot_fx2.h
@@ -32,11 +32,30 @@
#ifndef PROT_FX2_H
#define PROT_FX2_H
+/*----------------------------------------------------------------------------------*
+ * Prototypes of RAM counting tool macros
+ *----------------------------------------------------------------------------------*/
+
+#ifdef RAM_COUNTING_TOOL
+#define count_malloc( n1 ) MALLOC_FCT_CALL( n1 )
+#define count_calloc( n1, n2 ) CALLOC_FCT_CALL( n1, n2 )
+#define count_free( ptr ) FREE_FCT_CALL( ptr )
+#else
+#define count_malloc( n1 ) malloc( n1 )
+#define count_calloc( n1, n2 ) calloc( n1, n2 )
+#define count_free( ptr ) free( ptr )
+#endif
+
+#define dynamic_malloc( n1 ) malloc( n1 )
+#define dynamic_calloc( n1, n2 ) calloc( n1, n2 )
+#define dynamic_free( n1 ) free( n1 )
#include "ivas_cnst.h"
#include "stat_enc.h"
#include "stat_dec.h"
#include "ivas_error.h"
+#include "ivas_error_utils.h"
+
Word32 Mult_32_16(
Word32 a,
@@ -90,6 +109,12 @@ void Scale_sig(
const Word16 exp0 /* i : exponent: x = round(x << exp) Qx ?exp */
);
+//tools.c
+Word32 sum2_fx( /* o : sum of all squared vector elements Q(2x+1)*/
+ const Word16 *vec, /* i : i vector Qx*/
+ const Word16 lvec /* i : length of i vector */
+);
+
/*========================================================================================================/
mslvq_com_fx.c
/========================================================================================================*/
@@ -340,7 +365,7 @@ void map_hq_generic_fenv_norm_fx(
);
Word16 get_nor_delta_hf_fx(
- Decoder_State_fx *st,
+ Decoder_State *st,
Word16 *ynrm,
Word16 *Rsubband, /* Q3 */
const Word16 num_env_bands,
@@ -742,7 +767,7 @@ bitstream_fx.c
/========================================================================================================*/
UWord16 get_next_indice_fx( /* o : value of the indice */
- Decoder_State_fx *st_fx, /* i/o: decoder state structure */
+ Decoder_State *st_fx, /* i/o: decoder state structure */
Word16 nb_bits /* i : number of bits that were used to quantize the indice */
);
@@ -771,27 +796,27 @@ void push_next_bits_fx(
);
UWord16 get_next_indice_fx( /* o : value of the indice */
- Decoder_State_fx *st_fx, /* i/o: decoder state structure */
+ Decoder_State *st_fx, /* i/o: decoder state structure */
Word16 nb_bits /* i : number of bits that were used to quantize the indice */
);
UWord16 get_next_indice_1_fx( /* o : value of the indice */
- Decoder_State_fx *st_fx /* i/o: decoder state structure */
+ Decoder_State *st_fx /* i/o: decoder state structure */
);
void get_next_indice_tmp_fx(
- Decoder_State_fx *st_fx, /* i/o: decoder state structure */
+ Decoder_State *st_fx, /* i/o: decoder state structure */
Word16 nb_bits /* i : number of bits that were used to quantize the indice */
);
UWord16 get_indice_fx( /* o : value of the indice */
- Decoder_State_fx *st_fx, /* i/o: decoder state structure */
+ Decoder_State *st_fx, /* i/o: decoder state structure */
Word16 pos, /* i : absolute position in the bitstream */
Word16 nb_bits /* i : number of bits that were used to quantize the indice */
);
UWord16 get_indice_1_fx( /* o : value of the indice */
- Decoder_State_fx *st_fx, /* i/o: decoder state structure */
+ Decoder_State *st_fx, /* i/o: decoder state structure */
Word16 pos /* i : absolute position in the bitstream */
);
@@ -800,7 +825,7 @@ void reset_indices_enc_fx(
);
void reset_indices_dec_fx(
- Decoder_State_fx *st_fx /* i/o: decoder state structure */
+ Decoder_State *st_fx /* i/o: decoder state structure */
);
void write_indices_fx(
@@ -826,11 +851,11 @@ void indices_to_serial_generic(
);
void dec_prm_core(
- Decoder_State_fx *st
+ Decoder_State *st
);
void decision_matrix_core_dec(
- Decoder_State_fx *st /* i/o: decoder state structure */
+ Decoder_State *st /* i/o: decoder state structure */
);
Word16 BRATE2IDX_fx(Word32 brate);
@@ -840,37 +865,37 @@ Word32 BIT_ALLOC_IDX_fx(Word32 brate, Word16 ctype, Word16 sfrm, Word16 tc);
Word32 BIT_ALLOC_IDX_16KHZ_fx(Word32 brate, Word16 ctype, Word16 sfrm, Word16 tc);
Word16 read_indices_fx( /* o : 1 = OK, 0 = something wrong */
- Decoder_State_fx *st_fx, /* i/o: decoder state structure */
+ Decoder_State *st_fx, /* i/o: decoder state structure */
FILE *file, /* i : bitstream file */
Word16 rew_flag /* i : rewind flag (rewind file after reading) */
);
Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem */
- Decoder_State_fx *st, /* i/o: decoder state structure */
+ Decoder_State *st, /* i/o: decoder state structure */
FILE *file, /* i : bitstream file */
Word16 rew_flag /* i : rewind flag (rewind file after reading)*/
);
void getPartialCopyInfo(
- Decoder_State_fx *st, /* i : decoder state structure */
+ Decoder_State *st, /* i : decoder state structure */
Word16 *coder_type,
Word16 *sharpFlag
);
void get_rfFlag(
- Decoder_State_fx *st, /* i : decoder state structure */
+ Decoder_State *st, /* i : decoder state structure */
Word16 *rf_flag, /* o : check for the RF flag */
Word16 *nBits,
Word16 *ind
);
void get_rfFrameType(
- Decoder_State_fx *st, /* i : decoder state structure */
+ Decoder_State *st, /* i : decoder state structure */
Word16 *rf_frame_type /* o : RF frame type */
);
void get_rf_fec_offset(
- Decoder_State_fx *st, /* i : decoder state structure */
+ Decoder_State *st, /* i : decoder state structure */
Word16 *rf_fec_offset /* o : RF fec offset */
);
@@ -885,7 +910,7 @@ void get_NextCoderType_fx(
);
void read_indices_from_djb_fx(
- Decoder_State_fx *st, /* i/o: decoder state structure */
+ Decoder_State *st, /* i/o: decoder state structure */
UWord8 *pt_stream, /* i : bitstream file */
Word16 nbits /* i : number of bits */
, Word16 isAMRWB_IOmode
@@ -1010,7 +1035,7 @@ void ifft_rel_fx(
);
//gs_gains_fx.c
Word16 gsc_gaindec_fx( /* o : average frequency gain */
- Decoder_State_fx *st_fx, /* i/o: decoder state structure */
+ Decoder_State *st_fx, /* i/o: decoder state structure */
Word16 y_gainQ_fx[], /* o : quantized gain per band */
const Word32 core_brate_fx, /* i : core used */
Word16 old_y_gain_fx[], /* i/o: AR gain quantizer for low rate */
@@ -1197,12 +1222,1358 @@ void Comp_and_apply_gain_fx(
//gs_preech.c
void pre_echo_att_fx(
- Word32* Last_frame_ener_fx, /* i/o: Energy of the last frame 2*Q_new+1*/
- Word16* exc_fx, /* i/o: Excitation of the current frame Q_new*/
- const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) */
- const Word16 Q_new,
- const Word16 last_coder_type_fx, /* i : Last coding mode */
- const Word16 L_frame /* i : Frame length*/
+ Word32* Last_frame_ener_fx, /* i/o: Energy of the last frame 2*Q_new+1*/
+ Word16* exc_fx, /* i/o: Excitation of the current frame Q_new*/
+ const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) */
+ const Word16 Q_new,
+ const Word16 last_coder_type_fx, /* i : Last coding mode */
+ const Word16 L_frame /* i : Frame length*/
+
+);
+
+/*========================================================================================================/
+swb_bwe_com_lr_fx.c
+/========================================================================================================*/
+
+typedef struct GainItemStr_fx
+{
+ Word16 nmrValue_fx;
+ Word16 gainIndex_fx;
+} GainItem_fx;
+
+void GetPredictedSignal_fx(
+ const Word16 *predBuf_fx, /* i: Q8 */
+ Word32 *L_outBuf, /* o: Q9 */
+ const Word16 lag_fx, /* i: Q0 */
+ const Word16 fLen_fx, /* i: Q0 */
+ const Word16 lagGains_fx, /* i: Qgain */
+ const Word16 Qgain /* i: Q0 */
+);
+
+void Get20Log10Spec_fx(
+ const Word32 *L_inBuf, /* i : i Q_inBuf */
+ Word16 *outBuf_fx, /* o : output Q7 */
+ const Word16 fLen, /* i : loop length */
+ const Word16 Q_inBuf /* i : Qvalue of L_inBuf */
+);
+
+void GetSynthesizedSpecThinOut_fx(
+ const Word16 *predBuf_fx, /* i : Qss: prediction buffer (i.e., lowband) */
+ const Word16 Qss, /* i : Q value of i vector */
+ Word32 *L_outBuf, /* o : QsL: synthesized spectrum */
+ Word16 QsL, /* o : Q value of synthesized spectrum */
+ const Word16 nBands_fx, /* i : Q0: number of subbands calculated */
+ const Word16 *sbWidth_fx, /* i : Q0: subband lengths */
+ const Word16 *lagIndices_fx, /* i : Q0: lowband index for each subband */
+ const Word16 *lagGains_fx, /* i : Qgain: lagGain for each subband */
+ const Word16 *QlagGains_fx, /* i : Q0: Q value of lagGains_fx */
+ const Word16 predBufLen_fx /* i : Q0: lowband length */
+);
+
+void GetlagGains_fx(
+ const Word16 *predBuf_fx, /* i: Qss Low freq. Smoothed Spectrum */
+ const Word16 Qss, /* i: Q0 Q value of predBuf */
+ const Word32 *L_band_energy, /* i: Qbe Band Energy */
+ const Word16 Qbe, /* i: Q0 Q value of band energy */
+ const Word16 nBands, /* i: Q0 number of SWB subbands */
+ const Word16 *sbWidth, /* i: Q0 width of SWB subbands */
+ const Word16 *lagIndices, /* i: Q0 lagIndices */
+ const Word16 predBufLen, /* i: Q0 length of predBuf */
+ Word16 *lagGains_fx, /* o: QlagGains lagGains */
+ Word16 *QlagGains /* o: Q0 Q value of lagGains */
+);
+
+void Gettonl_scalfact_fx
+(
+ Word32 *L_outBuf, /* i/o: QsL synthesized spectrum */
+ Word16 QsL, /* i : Q0 Q value for outBuf */
+ const Word32 *L_codbuf, /* i : QsL core coder */
+ const Word16 fLenLow, /* i : Q0 lowband length */
+ const Word16 fLenHigh, /* i : Q0 highband length */
+ const Word16 harmonic_band, /* i : Q0 total number of Low frequency bands */
+ const Word16 bands, /* i : Q0 total number of subbands in a frame */
+ Word32 *L_band_energy, /* i : Qbe band energy of each subband */
+ Word16 Qbe, /* i : Q0 Q value for band_energy */
+ const Word16 *band_start, /* i : Q0 subband start indices */
+ const Word16 *band_end, /* i : Q0 subband end indices */
+ const Word16 p2aflags[], /* i : Q0 missing bands in the core coder */
+ Word32 L_be_tonal[], /* i : QbeL tonal energy */
+ Word16 QbeL, /* i : Q0 Q value for be_tonal */
+ GainItem_fx *pk_sf_fx, /* i : toanl information for Sparse filling */
+ Word16 Qss, /* i : Q0 Q value for pk_sf.nmrValue */
+ Word16 *pul_res_pk /* i : Q0 pulse resolution information */
+);
+
+void SpectrumSmoothing_fx(
+ const Word32 *L_inBuf, /* i : Qs Low band MDCT */
+ Word16 *outBuf_fx, /* o : Qss output */
+ Word16 *Qss, /* o : Q0 Q value of output vector */
+ const Word16 fLen, /* i : Q0 length */
+ const Word16 th_cut_fx /* i : Qss threshold of cut */
+);
+
+void SpectrumSmoothing_nss_fx(
+ const Word32 *L_inBuf, /* i : lowband MDCT */
+ Word16 *outBuf_fx, /* o : output */
+ Word16 *Qss, /* o : Q value for output vector */
+ const Word16 fLen /* i : length */
+);
+
+void hf_parinitiz_fx(
+ const Word32 L_total_brate,
+ const Word16 hqswb_clas_fx,
+ Word16 lowlength_fx,
+ Word16 highlength_fx,
+ Word16 wBands_fx[],
+ const Word16 **subband_search_offset_fx,
+ const Word16 **subband_offsets_fx,
+ Word16 *nBands_fx,
+ Word16 *nBands_search_fx,
+ Word16 *swb_lowband_fx,
+ Word16 *swb_highband_fx
+);
+
+void noise_extr_corcod_fx(
+ Word32 L_spectra[], /* i : QsL core coder */
+ const Word32 L_spectra_ni[], /* i : QsL core coder with sparse filling */
+ Word16 sspectra_fx[], /* o : Qss Smoothed tonal information from core coder */
+ Word16 sspectra_diff_fx[], /* o : Qss non tonal infomration for gap filling */
+ Word16 sspectra_ni_fx[], /* o : Qss smoothed core coder */
+ const Word16 fLenLow_fx, /* i : Q0 low frequency bands width */
+ Word16 prev_hqswb_clas_fx, /* i : Q0 classification information */
+ Word16 *prev_ni_ratio_fx, /* i : Q15 noise paraemeter */
+ Word16 *Qss /* o : Q0 Q value for sspectra_*_fx */
+);
+
+void sqrt_32n_16_fx(
+ Word32 L_in, /* i : i vector (Word32) */
+ Word16 Qin, /* i : Q value for L_in */
+ Word16 *out_fx, /* o : sqrt i vector (Word16) */
+ Word16 *Qout /* o : Q value for out_fx */
+);
+
+Word16 div_s_ss( /* o: result of division (Word16 Q0) */
+ const Word16 n, /* i: numerator (Word16 Q0 */
+ const Word16 d /* i: denominator (Word16 Q0) */
+);
+
+void noiseinj_hf_fx(
+ Word32 L_xSynth_har[], /* i/o : Qs gap filled information */
+ Word16 Qs, /* i : Q0 Q value for xSynth_har */
+ Word32 L_th_g[], /* i : Qs level adjustment information */
+ Word32 L_band_energy[], /* i : Qbe subband energies */
+ Word16 Qbe, /* i : Q0 Q value for band_energy */
+ Word16 *prev_En_sb_fx, /* i/o : QsEn smoothed sqrt band Energies */
+ const Word16 p2a_flags_fx[], /* i : Q0 Missing bands in the core coder */
+ const Word16 BANDS_fx, /* i : Q0 total bands */
+ const Word16 band_start_fx[], /* i : Q0 band start indices */
+ const Word16 band_end_fx[], /* i : Q0 band end indices */
+ const Word16 fLenLow_fx, /* i : Q0 low frequency bandwidth */
+ const Word16 fLenHigh_fx /* i : Q0 SWB frequency bandwidth */
+);
+
+void post_hq2_swb_fx
+(
+ const Word32 L_m[], /* i : input_signal */
+ const Word16 lowlength_fx, /* i : lowband length */
+ const Word16 highlength_fx, /* i : highband length */
+ const Word16 hqswb_clas_fx, /* i : HQ2 class information */
+ const Word16 har_bands_fx, /* i : Number of LF harmonic bands */
+ const Word16 bands_fx, /* i : Total number of Subbands in a frame */
+ const Word16 p2a_flags_fx[], /* i : HF tonal indicator */
+ const Word16 band_start_fx[], /* i : band start of each SB */
+ const Word16 band_end_fx[], /* i : band end of each SB */
+ Word32 L_y2[], /* o : output signal */
+ Word16 npulses_fx[] /* i/o : Number of coded spectrum */
+);
+
+void preset_hq2_swb_fx
+(
+ const Word16 hqswb_clas_fx, /* i : HQ2 class information */
+ const Word16 band_end_fx[], /* i : band end of each SB */
+ Word16 *har_bands_fx, /* i/o : Number of LF harmonic bands */
+ Word16 p2a_bands_fx, /* i : flag for peakness */
+ const Word16 length_fx, /* i : processed band length */
+ const Word16 bands_fx, /* i : Total number of Subbands in a frame */
+ Word16 *lowlength_fx, /* o : lowband length */
+ Word16 *highlength_fx, /* o : highband length */
+ Word32 L_m[] /* o : MDCT */
+);
+
+void return_bits_normal2_fx(
+ Word16 *bit_budget_fx, /* i/o : bit budget */
+ const Word16 p2a_flags_fx[], /* i : HF tonal indicator */
+ const Word16 bands_fx, /* i : Total number of Subbands in a frame */
+ const Word16 bits_lagIndices_fx[] /* i : bits for lagIndices */
+);
+
+Word16 spectrumsmooth_noiseton_fx( /* o : Qss ss_min */
+ Word32 L_spectra[], /* i : Qs core coder */
+ /*Word16 Qs,*/ /* i : Q0 Q value for spectra, spectra_ni */
+ const Word32 L_spectra_ni[], /* i : Qs core coder with sparse filling */
+ Word16 sspectra_fx[], /* o : Qss Smoothed tonal information from core coder */
+ Word16 sspectra_diff_fx[], /* o : Qss non tonal infomration for gap filling */
+ Word16 sspectra_ni_fx[], /* o : Qss smoothed core coder */
+ Word16 *Qss, /* o : Q0 Q value for sspectra* */
+ const Word16 fLenLow_fx, /* i : Q0 low frequency boundaries */
+ Word16 *ni_seed_fx /* io : Q0 random seed */
+);
+
+void ton_ene_est_fx(
+ Word32 L_xSynth_har[], /* i/o: QsL buffer with non tonal compoents */
+ const Word16 QsL, /* i : Q0 Q value for xSynth_har */
+ Word32 L_be_tonal[], /* o : QbeL tonal energy of the missing bands */
+ Word16* QbeL, /* o : Q0 Q value for be_tonal */
+ const Word32 L_band_energy[], /* i : Qbe subband energies */
+ const Word16 Qbe, /* i : Q0 Q value for band_energy */
+ const Word16 band_start[], /* i : Q0 subband start indices */
+ const Word16 band_end[], /* i : Q0 subband end indices */
+ const Word16 band_width[], /* i : Q0 subband widths */
+ const Word16 fLenLow, /* i : Q0 low frequency width */
+ const Word16 fLenHigh, /* i : Q0 High frequency width */
+ const Word16 bands, /* i : Q0 total subbands */
+ const Word16 har_bands, /* i : Q0 total number of harmonics bands */
+ const Word16 ni_lvl_fx, /* i : Q11 noise enve for the hf bands */
+ GainItem_fx pk_sf_fx[], /* i : */
+ const Word16 Qss, /* i : Q0 Q value for GainItem_fx->nmrValue */
+ const Word16* pul_res /* i : Q0 tonal resolution */
+);
+
+void norm_vec_32_16_scale_fx(
+ Word32 *L_vec_in, /* i : i vector */
+ Word16 Qin, /* i : Q value for i vector */
+ Word16 length_fx, /* i :vector size */
+ Word16 *vec_out_fx, /* o : output vectror */
+ Word16 *Qout, /* o : Q value for output vectro */
+ Word16 exp_safe /* i : suppress left shift: for prevend overflow on sum */
+);
+
+void updat_prev_frm_fx(
+ Word32 L_y2[], /* i/o: core coder buffer */
+ Word32 L_t_audio[], /* o: core coder buffer */
+ Word32 L_bwe_br, /* i: core bitrate */
+ Word16 length_fx, /* i: frame length coded bw */
+ const Word16 inner_frame_fx, /* i: i frame length */
+ Word16 bands_fx, /* i: sub band resolution */
+ Word16 bwidth_fx, /* i: NB/WB/SWB indicator */
+ const Word16 is_transient_fx, /* i: signal class information */
+ Word16 hqswb_clas_fx, /* i: signal class information */
+ Word16 *prev_hqswb_clas_fx, /* o: update signal class information */
+ Word16 prev_SWB_peak_pos_fx[], /* o: update core coder last coded peaks*/
+ Word16 prev_SWB_peak_pos_tmp_fx[], /* o: update core coder last coded peaks*/
+ Word16 *prev_frm_hfe2_fx, /* o: update harmonics */
+ Word16 *prev_stab_hfe2_fx, /* o: update harmonics */
+ Word16 bws_cnt_fx /* i: band width detector */
+);
+
+void convert_lagIndices_pls2smp_fx(
+ Word16 lagIndices_in_fx[],
+ Word16 nBands_search_fx,
+ Word16 lagIndices_out_fx[],
+ const Word16 sspectra_fx[],
+ const Word16 sbWidth_fx[],
+ const Word16 fLenLow_fx
+);
+
+void get_sigma_fx_har(
+ const Word32 L_x_abs[], /* i: Qi absolute i */
+ const Word16 Qi, /* i: Q0 Q value of x_abs */
+ const Word16 avg_fx, /* i: Qavg average of x_abs */
+ const Word16 Qavg, /* i: Q0 Q value of avg */
+ const Word16 length_fx, /* i: Q0 length */
+ Word16 *sigma_fx, /* o: Qsigma sigma */
+ Word16 *Qsigma /* o: Q0 Q value of sigma */
+);
+
+void genhf_noise_fx(
+ const Word16 noise_flr_fx[], /* i : Qss smoothed non tonal */ /* sspectra_diff_fx:Qss */
+ const Word16 Qss, /* i : Q0 Q value */
+ Word32 L_xSynth_har[], /* o : QsL hf non tonal components */ /* xSynth_har:QsL */
+ const Word16 QsL, /* i : Q0 Q value */
+ const Word16* predBuf_fx, /* i : Qss smoothed tonal compone */ /* sspectra:Qss */
+ const Word16 bands, /* i : Q0 total number of subbands in a frame */
+ const Word16 harmonic_band, /* i : Q0 Number of LF harmonic frames */
+ const Word16 har_freq_est2, /* i : Q0 harmonic signal parameter */
+ const Word16 pos_max_hfe2, /* i : Q0 last pulse in core coder */
+ Word16* pul_res, /* o : Q0 pulse resolution */
+ GainItem_fx pk_sf_fx[], /* o : representative region */
+ const Word16 fLenLow, /* i : Q0 low frequency length */
+ const Word16 fLenHigh, /* i : Q0 high frequency length */
+ const Word16 sbWidth[], /* i : Q0 bandwidth for high bands */
+ const Word16 lagIndices[], /* i : Q0 correlation indices for most representative */
+ const Word16 subband_offsets[], /* i : Q0 band offsets for HF reconstruction */
+ const Word16 subband_search_offset[]/* i : Q0 most representative regions offsets in LF */
+);
+
+Word16 har_est_fx(
+ Word32 L_spectra[], /* i : coded spectrum */
+ Word16 N, /* i : length of the desired spectrum */
+ Word16 *har_freq_est1, /* i/o: Estimation harmonics 1 */
+ Word16 *har_freq_est2, /* o : Estimation harmonics 2 */
+ Word16 *flag_dis, /* i/o: flag for BWE reconstruction */
+ Word16 *prev_frm_hfe2, /* i/o: Estimated harmonic update */
+ const Word16 subband_search_offset[], /* i : Subband Search range */
+ const Word16 sbWidth[], /* i : Subband Search range */
+ Word16 *prev_stab_hfe2 /* i/o: Estimated harmonic position */
+);
+
+void FindNBiggest2_simple_fx_har(
+ const Word32 *L_inBuf, /* i : i buffer (searched) */
+ const Word16 Qabs_in, /* i : Q value of i buffer */
+ GainItem_fx *pk_sf_fx, /* o : N biggest components found */
+ const Word16 nIdx_fx, /* i : search length */
+ Word16 *n_fx, /* i : number of components searched (N biggest) */
+ Word16 n_nbiggestsearch
+);
+
+Word16 get_usebit_npswb_fx(
+ Word16 hqswb_clas_fx
+);
+
+
+/*========================================================================================================/
+isf_dec_amr_wb_fx.c
+/========================================================================================================*/
+
+void disf_2s_36b_fx(
+ Word16 *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */
+ Word16 *isf_q, /* o : quantized ISFs in the cosine domain */
+ Word16 *mem_AR, /* i/o: quantizer memory for AR model */
+ Word16 *mem_MA, /* i/o: quantizer memory for MA model */
+ const Word16 enc_dec /* i : encoder (0), decoder (1) G722.2 FER */
+);
+
+void disf_2s_46b_fx(
+ Word16 *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */
+ Word16 *isf_q, /* o : quantized ISFs in the cosine domain */
+ Word16 *mem_AR, /* o : quantizer memory for AR model */
+ Word16 *mem_MA, /* i/o: quantizer memory for MA model */
+ const Word16 enc_dec /* i : encoder (0), decoder (1) G722.2 FER */
+);
+
+void disf_ns_28b_fx(
+ Word16 *indice,
+ Word16 *isf_q
+);
+
+void isf_dec_amr_wb_fx(
+ Decoder_State *st, /* i/o: State structure */
+ Word16 *Aq, /* o : quantized A(z) for 4 subframes */
+ Word16 *isf_new, /* o : de-quantized ISF vector */
+ Word16 *isp_new /* o : de-quantized ISP vector */
+);
+
+/*========================================================================================================/
+hq2_noise_inject.c fix part
+/========================================================================================================*/
+
+void hq2_noise_inject_fx(
+ Word32 L_y2[],
+ const Word16 band_start[],
+ const Word16 band_end[],
+ const Word16 band_width[],
+ Word32 Ep_fx[],
+ Word32 Rk_fx[],
+ const Word16 npulses[],
+ Word16 ni_seed,
+ const Word16 bands,
+ const Word16 ni_start_band,
+ const Word16 bw_low,
+ const Word16 bw_high,
+ const Word32 enerL_fx,
+ const Word32 enerH_fx,
+ Word32 last_ni_gain_fx[],
+ Word16 last_env_fx[],
+ Word16 *last_max_pos_pulse,
+ Word16 *p2a_flags,
+ Word16 p2a_bands,
+ const Word16 hqswb_clas,
+ const Word16 bwidth,
+ const Word32 bwe_br
+);
+
+/*========================================================================================================/
+hq2_bit_alloc_fx.c
+/========================================================================================================*/
+
+void Bits2indvsb_fx(
+ const Word32 *L_be, /* i : Q14 Band Energy of sub-band */
+ const Word16 start_band, /* i : Q0 start band indices */
+ const Word16 end_band, /* i : Q0 end band indices */
+ const Word16 Bits, /* i : Q0 Total number of bits allocated to a group */
+ const Word32 L_Bits_needed, /* i : Q0 smallest bit number for allocation in group */
+ Word32 *L_Rsubband, /* o : Q18 bit allocation of sub-band */
+ Word16 *p2aflags_fx /* i/o: Q0 peaky/noise subband flag */
+);
+
+void hq2_bit_alloc_har_fx(
+ const Word32 *L_y, /* i : Q14 band energy of sub-vectors */
+ Word16 B_fx, /* i : Q0 number of available bits */
+ const Word16 N_fx, /* i : Q0 number of sub-vectors */
+ Word32 *L_Rsubband, /* o : Q18 sub-band bit-allocation vector */
+ Word16 p2a_bands_fx, /* i : Q0 highfreq bands */
+ const Word32 L_core_brate, /* i : Q0 core bit rate */
+ Word16 p2a_flags_fx[], /* i/o: Q0 p2a_flags */
+ const Word16 band_width_fx[] /* i : Q0 table of band_width */
+);
+
+Word32 hq2_bit_alloc_fx(
+ const Word32 L_band_energy[], /* i : band energy of each subband */
+ const Word16 bands, /* i : total number of subbands in a frame */
+ Word32 L_Rk[], /* i/o: Bit allocation/Adjusted bit alloc. */
+ Word16 *bit_budget_fx, /* i/o: bit bugdet */
+ Word16 *p2a_flags, /* i : HF tonal indicator */
+ const Word16 weight_fx, /* i : weight */
+ const Word16 band_width[], /* i : Sub band bandwidth */
+ const Word16 num_bits, /* i : available bits */
+ const Word16 hqswb_clas, /* i : HQ2 class information */
+ const Word16 bwidth, /* i : i bandwidth */
+ const Word16 is_transient /* i : indicator HQ_TRANSIENT or not */
+);
+
+void reordvct_fx(
+ Word16 *y, /* i/o: vector to rearrange */
+ const Word16 N, /* i : dimensions */
+ Word16 *idx /* o : reordered vector index */
+);
+
+/*========================================================================================================/
+nelp_fx.c
+/========================================================================================================*/
+
+Word16 dequantize_uvg_fx(
+ const Word16 iG1, /* i: gain 1 index */
+ const Word16* iG2, /* i: gain 2 index */
+ Word16* G, /* o: quantized gain */
+ const Word16 bandwidth, /* i: bandwidth */
+ const Word16 do_scale
+);
+
+void generate_nelp_excitation_fx(
+ Word16* seed, /* i/o: random number seed */
+ const Word16* Gains, /* i : excitation gains Q_exc*/
+ Word16* output, /* o : excitation output */
+ const Word16 gain_fac /* i : gain factor */
+);
+
+/*========================================================================================================/
+ppp_fx.c
+/========================================================================================================*/
+
+void Interpol_delay_fx(
+ Word16 *out_fx,
+ Word16 last_fx,
+ Word16 current_fx,
+ Word16 SubNum,
+ const Word16* frac_fx
+);
+
+void deemph_lpc_fx(
+ const Word16* p_Aq_curr_fx, /* i : LP coefficients current frame */
+ const Word16* p_Aq_old_fx, /* i : LP coefficients previous frame */
+ Word16* LPC_de_curr_fx, /* o : De-emphasized LP coefficients current frame in Q12 */
+ Word16* LPC_de_old_fx, /* o : De-emphasized LP coefficients previous frame in Q12 */
+ const Word16 deemph_old
+);
+
+/*========================================================================================================/
+hq2_core_com_fx.c
+/========================================================================================================*/
+
+void mdct_spectrum_denorm_fx(
+ const Word16 inp_vector[], /* i : Q0 : */
+ Word32 L_y2[], /* i/o : Qs : decoded spectrum */
+ const Word16 band_start[], /* i : Q0 : table of start freq for every subband */
+ const Word16 band_end[], /* i : Q0 : table of end freq for every subband */
+ const Word16 band_width[], /* i : Q0 : table of bandwidth for every subband */
+ const Word32 L_band_energy[], /* i : Qbe : band energy */
+ const Word16 npulses[], /* i : Q0 : number of coded spectrum */
+ const Word16 bands, /* i : Q0 : numbers of subbands */
+ const Word16 ld_slope_fx, /* i : Q15 : */
+ const Word16 pd_thresh_fx /* i : Q15 : */
+);
+
+void hq2_core_configure_fx(
+ const Word16 frame_length,
+ const Word16 num_bits,
+ const Word16 is_transient,
+ Word16 *bands,
+ Word16 *length,
+ Word16 band_width[],
+ Word16 band_start[],
+ Word16 band_end[],
+ Word32 *L_qint,
+ Word16 *eref,
+ Word16 *bit_alloc_weight,
+ Word16 *gqlevs,
+ Word16 *Ngq,
+ Word16 *p2a_bands,
+ Word16 *p2a_th,
+ Word16 *pd_thresh,
+ Word16 *ld_slope,
+ Word16 *ni_coef,
+ Word32 L_bwe_br
+);
+
+void reverse_transient_frame_energies_fx(
+ Word32 L_band_energy[], /* o : Q14 : band energies */
+ const Word16 bands /* i : Q0 : number of bands */
+);
+
+void spt_shorten_domain_pre_fx(
+ const Word16 band_start[], /* i: Starting position of sub band */
+ const Word16 band_end[], /* i: End position of sub band */
+ const Word16 prev_SWB_peak_pos[], /* i: Spectral peak */
+ const Word16 BANDS, /* i: total number of bands */
+ const Word32 L_bwe_br, /* i: bitrate information */
+ Word16 new_band_start[], /* o: Starting position of new shorten sub band */
+ Word16 new_band_end[], /* o: End position of new shorten sub band */
+ Word16 new_band_width[] /* o: new sub band bandwidth */
+);
+
+void spt_shorten_domain_band_save_fx(
+ const Word16 bands, /* i: total subband */
+ const Word16 band_start[], /* i: starting position of subband */
+ const Word16 band_end[], /* i: end position of subband */
+ const Word16 band_width[], /* i: band width of subband */
+ Word16 org_band_start[], /* o: starting position of subband */
+ Word16 org_band_end[], /* o: end position of subband */
+ Word16 org_band_width[] /* o: band width of subband */
+);
+
+void spt_shorten_domain_band_restore_fx(
+ const Word16 bands, /* i: total subband */
+ Word16 band_start[], /* i/o: starting position of subband */
+ Word16 band_end[], /* i/o: end position of subband */
+ Word16 band_width[], /* i/o: band width of subband */
+ const Word16 org_band_start[], /* o: starting position of subband */
+ const Word16 org_band_end[], /* o: end position of subband */
+ const Word16 org_band_width[] /* o: band width of subband */
+);
+
+void spt_swb_peakpos_tmp_save_fx(
+ const Word32 L_y2[], /* i: coded spectral information */
+ const Word16 bands, /* i: total number of bands */
+ const Word16 band_start[], /* i: starting position of subband */
+ const Word16 band_end[], /* i: end position of subband */
+ Word16 prev_SWB_peak_pos_tmp[] /* o: spectral peaks */
+);
+
+void bit_allocation_second_fx(
+ Word32 *Rk,
+ Word32 *Rk_sort,
+ Word16 BANDS,
+ const Word16 *band_width,
+ Word16 *k_sort,
+ Word16 *k_num,
+ const Word16 *p2a_flags,
+ const Word16 p2a_bands,
+ const Word16 *last_bitalloc,
+ const Word16 input_frame
+);
+
+//synth_filt_fix.c
+
+Word32 syn_kern_16(
+ Word32 L_tmp,
+ const Word16 a[],
+ const Word16 y[]
+);
+
+void syn_filt_s_lc_fx(
+ const Word16 shift, /* i : scaling to apply Q0 */
+ const Word16 a[], /* i : LP filter coefficients Q12 */
+ const Word16 x[], /* i : i signal Qx */
+ Word16 y[], /* o : output signal Qx-s */
+ const Word16 lg /* i : size of filtering Q0 */
+);
+
+void Syn_filt_s(
+ const Word16 shift, /* i : scaling to apply Q0 */
+ const Word16 a[], /* i : LP filter coefficients Q12 */
+ const Word16 m, /* i : order of LP filter Q0 */
+ const Word16 x[], /* i : i signal Qx */
+ Word16 y[], /* o : output signal Qx-s */
+ const Word16 lg, /* i : size of filtering Q0 */
+ Word16 mem[], /* i/o: memory associated with this filtering. Qx-s */
+ const Word16 update /* i : 0=no update, 1=update of memory. Q0 */
+);
+
+void E_UTIL_synthesis(const Word16 shift, const Word16 a[], const Word16 x[], Word16 y[],
+ const Word16 lg, Word16 mem[], const Word16 update, const Word16 m);
+
+void synth_mem_updt2(
+ const Word16 L_frame, /* i : frame length */
+ const Word16 last_L_frame, /* i : frame length */
+ Word16 old_exc[], /* i/o: excitation buffer */
+ Word16 mem_syn_r[], /* i/o: synthesis filter memory */
+ Word16 mem_syn2[], /* o : synthesis filter memory for find_target */
+ Word16 mem_syn[], /* o : synthesis filter memory for find_target */
+ const Word16 dec /* i : flag for decoder indication */
+);
+
+
+//lerp.c
+void lerp(Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 bufferOldSize);
+
+
+//index_pvq_opt.c
+
+PvqEntry mpvq_encode_vec_fx( /* o : leading_sign_index, index, size, k_val */
+ const Word16* vec_in, /* i : signed pulse train */
+ Word16 dim_in, /* i : dimension */
+ Word16 k_val_local /* i : nb unit pulses */
+);
+
+//weight_a_fx.c
+void weight_a_subfr_fx(
+ const Word16 nb_subfr, /* i : number of subframes */
+ const Word16 *A, /* i : LP filter coefficients Q12 */
+ Word16 *Aw, /* o : weighted LP filter coefficients Q12 */
+ const Word16 gamma, /* i : weighting factor */
+ const Word16 m /* i : order of LP filter */
+);
+
+void weight_a_lc_fx(
+ const Word16 a[], /* i: LP filter coefficients Q12 */
+ Word16 ap[], /* o: weighted LP filter coefficients Q12 */
+ const Word16 *gammatbl, /* i: weighting factor Q15 */
+ const Word16 m /* i: order of LP filter Q0 */
+);
+
+void weight_a_fx(
+ const Word16 a[], /* i: LP filter coefficients Q12 */
+ Word16 ap[], /* o: weighted LP filter coefficients Q12 */
+ const Word16 gamma, /* i: weighting factor Q15 */
+ const Word16 m /* i: order of LP filter Q0 */
+);
+
+//residu_fx.c
+void Residu3_lc_fx(
+ const Word16 a[], /* i : prediction coefficients Q12 */
+ const Word16 m, /* i : order of LP filter Q0 */
+ const Word16 x[], /* i : input signal (usually speech) Qx */
+ Word16 y[], /* o : output signal (usually residual) Qx */
+ const Word16 lg, /* i : vector size Q0 */
+ const Word16 shift
+);
+
+void Residu3_10_fx(
+ const Word16 a[], /* i : prediction coefficients Q12 */
+ const Word16 x[], /* i : input signal (usually speech) Qx */
+ /* (note that values x[-10..-1] are needed) */
+ Word16 y[], /* o : output signal (usually residual) Qx */
+ const Word16 lg, /* i : vector size Q0 */
+ const Word16 shift
+);
+
+void Residu3_fx(
+ const Word16 a[], /* i : prediction coefficients Q12 */
+ const Word16 x[], /* i : input signal (usually speech) Qx */
+ /* (note that values x[-M..-1] are needed) */
+ Word16 y[], /* o : output signal (usually residual) Qx */
+ const Word16 lg, /* i : vector size Q0 */
+ const Word16 shift
+);
+
+void calc_residu_fx(
+ Encoder_State *st, /* i/o: state structure */
+ const Word16 *speech, /* i : weighted speech signal */
+ Word16 *res, /* o : residual signal */
+ const Word16 *p_Aq /* i : quantized LP filter coefficients */
+);
+
+//inerpol_lc.c
+Word32 Interpol_lc_fx( /* o : interpolated value Qx+16 */
+ const Word16 *x, /* i : input vector Q0 */
+ const Word16 *win, /* i : interpolation window Q14 */
+ const Word16 frac, /* i : fraction (0..up_samp) Q0 */
+ const Word16 up_samp, /* i : upsampling factor Q0 */
+ const Word16 nb_coef /* i : number of coefficients Q0 */
+);
+
+
+//modif_fs_fx.c
+Word16 modify_Fs_fx( /* o : length of output Q0 */
+ const Word16 sigIn_fx[], /* i : signal to decimate Q0 */
+ Word16 lg, /* i : length of input Q0 */
+ const Word32 fin, /* i : frequency of input Q0 */
+ Word16 sigOut_fx[], /* o : decimated signal Q0 */
+ const Word32 fout, /* i : frequency of output Q0 */
+ Word16 mem_fx[], /* i/o: filter memory Q0 */
+ const Word16 nblp /* i : flag indicating if NB low-pass is applied */
+);
+
+Word16 modify_Fs_intcub3m_sup_fx( /* o : length of output */
+ const Word16 sigIn[], /* i : signal to decimate with memory of 2 samples (indexes -2 & -1) */
+ const Word16 lg, /* i : length of input (suppose that lg is such that lg_out is integer, ex multiple of 5 in case of 16kHz to 12.8 kHz) */
+ const Word32 fin, /* i : frequency of input */
+ Word16 sigOut[], /* o : decimated signal */
+ const Word32 fout, /* i : frequency of output */
+ Word16 *delayout /* o : delay of output */
+);
+
+void Decimate_allpass_steep_fx(
+ const Word16 *in_fx,
+ Word16 mem[], /* array of size: 2*ALLPASSSECTIONS_STEEP+1 */
+ Word16 N, /* number of input samples */
+ Word16 out_fx[]);
+
+void Interpolate_allpass_steep_fx(
+ const Word16 *in_fx,
+ Word16 mem[], /* array of size: 2*ALLPASSSECTIONS_STEEP+1 */
+ Word16 N, /* number of input samples */
+ Word16 out_fx[]);
+
+void interpolate_3_over_2_allpass_fx(
+ const Word16 *input_fx, /* i : input signal */ /* Q_input */
+ const Word16 len, /* i : number of input samples */
+ Word16 *out_fx, /* o : output signal */ /* Q_input */
+ Word16 *mem_fx, /* i/o: memory */ /* Q_input */
+ const Word16 *filt_coeff_fx /* i : filter coefficients */ /* Q15*/
+);
+
+void interpolate_3_over_1_allpass_fx(
+ const Word16 *input_fx, /* i : input signal */ /* Q_input */
+ const Word16 len, /* i : number of input samples */
+ Word16 *out_fx, /* o : output signal */ /* Q_input */
+ Word16 *mem_fx /* i/o: memory */ /* Q_input */
+);
+
+void decimate_2_over_3_allpass_fx(
+ const Word16 *input, /* i : input signal */ /* Q_input */
+ const Word16 len, /* i : number of input samples */
+ Word16 *out_fx, /* o : output signal */ /* Q_input */
+ Word16 *mem_fx, /* i/o: memory */ /* Q_input */
+ const Word16 *filt_coeff_fx, /* i : filter coefficients */ /* Q15*/
+ const Word16 *lp_num_fx, /* i : Num Coefficients : Q15 */
+ const Word16 *lp_den_fx, /* o : Den Coefficients : Q15 */
+ Word16 *lp_mem_fx /* o : Filter memories : Q_input */
+);
+
+void retro_interp4_5_fx(
+ const Word16 *syn_fx,
+ Word16 *pst_old_syn_fx
+);
+
+void retro_interp5_4_fx(
+ Word16 *pst_old_syn_fx
+);
+
+//lag_wind.c
+
+void adapt_lag_wind(
+ Word16 r_h[], /* in/out: autocorrelations */
+ Word16 r_l[], /* in/out: autocorrelations */
+ Word16 m, /* i : order of LP filter */
+ const Word16 Top, /* i : open loop pitch lag */
+ const Word16 Tnc, /* i : open loop pitch gain */
+ Word32 sr_core /* i : sampling rate */
+);
+
+void lag_wind(
+ Word16 r_h[], /* in/out: autocorrelations */
+ Word16 r_l[], /* in/out: autocorrelations */
+ Word16 m, /* i : order of LP filter */
+ Word32 sr_core, /* i : sampling rate */
+ Word16 strength /* i : LAGW_WEAK, LAGW_MEDIUM, or LAGW_STRONG */
+);
+
+//preemp_fx.c
+#define preemph_fx(signal,mu,L,mem) preemph_copy_fx((signal),(signal),(mu),(L),(mem))
+
+void preemph_copy_fx(
+ const Word16 x[], /* i : i signal Qx */
+ Word16 y[], /* o : output signal Qx */
+ const Word16 mu, /* i : preemphasis coefficient Q15 */
+ const Word16 lg, /* i : vector size Q0 */
+ Word16 *mem /* i/o: memory (x[-1]) Qx */
+);
+
+void E_UTIL_f_preemph2(Word16 shift, Word16 *signal, const Word16 mu, const Word16 lg, Word16 *mem);
+
+Word16 E_UTIL_f_preemph3(Word16 *signal, const Word16 mu, const Word16 lg, Word16 *mem, Word16 bits);
+
+
+//swb_tbe_com_fx.c
+
+void swb_tbe_reset_fx(
+ Word32 mem_csfilt[],
+ Word16 mem_genSHBexc_filt_down_shb[],
+ Word16 state_lpc_syn[],
+ Word16 syn_overlap[],
+ Word16 state_syn_shbexc[],
+ Word16 *tbe_demph,
+ Word16 *tbe_premph,
+ Word16 mem_stp_swb[],
+ Word16 *gain_prec_swb
+);
+
+void swb_tbe_reset_synth_fx(
+ Word32 genSHBsynth_Hilbert_Mem[],
+ Word16 genSHBsynth_state_lsyn_filt_shb_local_fx[]
+);
+
+void fb_tbe_reset_synth_fx(
+ Word32 fbbwe_hpf_mem_fx[][4],
+ Word16 fbbwe_hpf_mem_fx_Q[],
+ Word16 *prev_fbbwe_ratio_fx
+);
+
+Word16 tbe_celp_exc_offset(
+ const Word16 T0_fx, /* i : Integer pitch */
+ const Word16 T0_frac_fx, /* i : Fractional part of the pitch */
+ const Word16 L_frame /* i : frame lenght */
+);
+
+void tbe_celp_exc(
+ const Word16 L_frame_fx, /* i : Frame lenght */
+ 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 */
+);
+
+void flip_and_downmix_generic_fx(
+ Word16 i[], /* i : i spectrum */
+ Word16 output[], /* o : output spectrum */
+ const Word16 length, /* i : length of spectra */
+ Word32 mem1_ext[HILBERT_ORDER1], /* i/o: Hilbert filter memory */
+ Word32 mem2_ext[2 * HILBERT_ORDER2], /* i/o: memory */
+ Word32 mem3_ext[2 * HILBERT_ORDER2], /* i/o: memory */
+ Word16 *phase_state /* i/o: Phase state in case frequency isn't multiple of 50 Hz */
+);
+
+void Calc_rc0_h(
+ Word16 * h, /* i : impulse response of composed filter */
+ Word16 * rc0 /* o : 1st parcor */
+);
+
+void PostShortTerm_fx(
+ Word16 *sig_in, /* i : i signal (pointer to current subframe */
+ Word16 *lpccoeff, /* i : LPC coefficients for current subframe */
+ Word16 *sig_out, /* o : postfiltered output */
+ Word16 *mem_stp, /* i/o: postfilter memory*/
+ Word16 *ptr_mem_stp, /* i/o: pointer to postfilter memory*/
+ Word16 *ptr_gain_prec, /* i/o: for gain adjustment*/
+ Word16 *mem_zero, /* i/o: null memory to compute h_st*/
+ const Word16 formant_fac_fx /* i : Strength of post-filter*/
+);
+
+void flip_spectrum_and_decimby4_fx(
+ const Word16 i[], /* i : i spectrum */
+ Word16 output[], /* o : output spectrum */
+ const Word16 length, /* i : vector length */
+ Word16 mem1[], /* i/o : memory */
+ Word16 mem2[], /* i/o : memory */
+ const Word16 ramp_flag /* i : flag to trigger slow ramp-up of output following change of core */
+);
+
+void GenShapedWBExcitation_fx(
+ Word16 *excSHB, /* o : synthesized shaped shb exctiation */
+ const Word16 *lpc_shb, /* i : lpc coefficients */
+ Word16 *exc4kWhtnd, /* o : whitened synthesized shb excitation */
+ Word32 *mem_csfilt, /* i/o : memory */
+ Word16 *mem_genSHBexc_filt_down1, /* i/o : memory */
+ Word16 *mem_genSHBexc_filt_down2, /* i/o : memory */
+ Word16 *mem_genSHBexc_filt_down3, /* i/o : memory */
+ Word16 *state_lpc_syn, /* i/o : memory */
+ const Word16 coder_type, /* i : coding type */
+ const Word16 *bwe_exc_extended, /* i : bandwidth extended exciatation */
+ const Word16 Q_bwe_exc,
+ Word16 bwe_seed[], /* i/o : random number generator seed */
+ const Word16 voice_factors[], /* i : voicing factor */
+ const Word16 signal_type
+ , const Word16 igf_flag
+);
+
+void GenWBSynth_fx(
+ const Word16 *input_synspeech, /* i : i synthesized speech */
+ Word16 *shb_syn_speech_16k, /* o : output highband compnent */
+ Word16 *state_lsyn_filt_shb1, /* i/o: memory */
+ Word16 *state_lsyn_filt_shb2 /* i/o: memory */
+);
+
+void GenShapedSHBExcitation_fx(
+ Word16* excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/
+ const Word16* lpc_shb, /* i : lpc coefficients Q12*/
+ Word16* White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc */
+ Word32* mem_csfilt, /* i/o: memory */
+ Word16* mem_genSHBexc_filt_down_shb, /* i/o: memory */
+ Word16* state_lpc_syn, /* i/o: memory */
+ const Word16 coder_type, /* i : coding type */
+ const Word16* bwe_exc_extended, /* i : bandwidth extended excitation */
+ Word16 bwe_seed[], /* i/o: random number generator seed */
+ Word16 voice_factors[], /* i : voicing factor*/
+ const Word16 extl, /* i : extension layer */
+ Word16* tbe_demph, /* i/o: de-emphasis memory */
+ Word16* tbe_premph, /* i/o: pre-emphasis memory */
+ Word16* lpc_shb_sf, /* i: LP coefficients */
+ const Word32 shb_ener_sf_32, /* i: i shb ener, Q31 */
+ Word16* shb_res_gshape, /* i: i res gain shape, Q14 */
+ Word16* shb_res,
+ Word16* vf_ind,
+ const Word16 formant_fac, /* i : Formant sharpening factor [0..1] */
+ Word16 fb_state_lpc_syn[], /* i/o: memory */
+ Word16* fb_tbe_demph, /* i/o: fb de-emphasis memory */
+ Word16* Q_bwe_exc,
+ Word16* Q_bwe_exc_fb,
+ const Word16 Q_shb,
+ Word16 n_mem2, /* i : n_mem2 scale factor to adjust 24.4/32kbps memories */
+ Word16 prev_Q_bwe_syn, /* i : st_fx->prev_Q_bwe_syn */
+ const Word32 bitrate,
+ const Word16 prev_bfi
+#ifdef ADD_IVAS_TBE_CODE
+ , /* i : previous frame was concealed */
+ const Word16 element_mode, /* i : element mode */
+ const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */
+ Word16* nlExc16k, /* i/o: NL exc for IC-BWE */
+ Word16* mixExc16k, /* i/o: exc spreading for IC-BWE */
+ const Word32 extl_brate, /* i : extension layer bitarte */
+ const Word16 MSFlag, /* i : Multi Source flag */
+ Word16 EnvSHBres_4k[], /* i/o: TD envelope of the SHB residual signal */
+ Word16* prev_pow_exc16kWhtnd, /* i/o: power of the LB excitation signal in the previous frame */
+ Word16* prev_mix_factor, /* i/o: mixing factor in the previous frame */
+ Word16* Env_error, /* o : error in SHB residual envelope modelling*/
+ Word16 Env_error_part[] /* o : per-segment error in SHB residual envelope modelling */
+#endif
+);
+
+void GenSHBSynth_fx(
+ const Word16 *shb_target_speech, /* i : i synthesized speech */
+ Word16 *shb_syn_speech_32k, /* o : output highband component */
+ Word32 Hilbert_Mem[], /* i/o: memory */
+ Word16 genSHBsynth_allpass_mem[], /* i/o: memory */
+ const Word16 L_frame, /* i : ACELP Frame length */
+ Word16 *syn_dm_phase
+);
+
+void ScaleShapedSHB_fx(
+ const Word16 length, /* i : SHB overlap length */
+ Word16 *synSHB, /* i/o: synthesized shb signal */
+ Word16 *overlap, /* i/o: buffer for overlap-add */
+ const Word16 *subgain, /* i : subframe gain */
+ const Word32 frame_gain, /* i : frame gain */
+ const Word16 *win, /* i : window */
+ const Word16 *subwin, /* i : subframes window */
+ Word16 *Q_bwe_exc
+ , Word16 *Qx
+ , Word16 n_mem3
+ , Word16 prev_Q_bwe_syn2
+);
+
+void ScaleShapedWB_fx(
+ const Word16 length, /* i : SHB overlap length */
+ Word16* synSHB, /* i/o : synthesized shb signal */
+ Word16* overlap, /* i/o : buffer for overlap-add */
+ const Word16* subgain, /* i : subframe gain */
+ const Word32 frame_gain, /* i : frame gain */
+ const Word16* win, /* i : window */
+ const Word16* subwin, /* i : subframes window */
+ const Word16 Q_bwe_exc
+ , Word16 L_frame /* i : Frame length - determines whether 12.8 or 16kHz core in-use */
+ , Word16 dynQ /* i : indicate whether output is dynamic Q, or Q0 */
+ , Word16* Qx /* o : newly computed Q factor for synSHB */
+ , Word16 prev_Qx /* i : prev_Qx for memory scaling */
+ , Word32* Hilbert_Mem /* i : Hilbert memory used for computing Qx */
+);
+
+void non_linearity_fx(
+ const Word16 i[], /* i : i signal Q_inp */
+ Word32 output[], /* o : output signal 2*Q_inp */
+ const Word16 length, /* i : i length */
+ Word32 *prev_scale, /* i/o: memory Q30 */
+ Word16 Q_inp,
+ Word16 coder_type, /* i : Coder Type */
+ Word16 *voice_factors, /* i : Voice Factors */
+ const Word16 L_frame /* i : ACELP frame length */
+);
+
+void interp_code_5over2_fx(
+ const Word16 inp_code[], /* i : i vector */
+ Word16 interp_code[], /* o : output vector */
+ const Word16 inp_length /* i : length of i vector */
+);
+
+void interp_code_4over2_fx(
+ const Word16 inp_code_fx[], /* i : i vector Qx */
+ Word16 interp_code_fx[], /* o : output vector Qx */
+ const Word16 inp_length /* i : length of i vector */
+);
+
+void wb_tbe_extras_reset_synth_fx(Word16 state_lsyn_filt_shb[], Word16 state_lsyn_filt_dwn_shb[],
+ Word16 state_32and48k_WB_upsample[]
+ , Word16 state_resamp_HB[]
+);
+
+void elliptic_bpf_48k_generic_fx(
+ const Word16 input_fx[], /* i : i signal */
+ Word16 *Q_input_fx,
+ Word16 output_fx[], /* o : output signal */
+ Word32 memory_fx[][4], /* i/o: 4 arrays of 4 for memory */
+ Word16 memory_fx_Q[],
+ const Word16 full_band_bpf[][5] /* i : filter coefficients b0,b1,b2,a0,a1,a2 Q13 */
+);
+
+void synthesise_fb_high_band_fx(
+ const Word16 excitation_in[], /* i : full band excitation */
+ Word16 Q_fb_exc,
+ Word16 output[], /* o : high band speech - 14.0 to 20 kHz */
+ const Word32 fb_exc_energy, /* i : full band excitation energy */
+ const Word16 ratio, /* i : energy ratio */
+ const Word16 L_frame, /* i : ACELP frame length */
+ const Word16 bfi, /* i : fec flag */
+ Word16 *prev_fbbwe_ratio, /* o : previous frame energy for FEC */
+ Word32 bpf_memory[][4], /* i/o: memory for elliptic bpf 48k */
+ Word16 bpf_memory_Q[],
+ Word16 Qout
+);
+
+void prep_tbe_exc_fx(
+ const Word16 L_frame_fx, /* i : length of the frame */
+#ifdef ADD_IVAS_TBE_CODE
+ const Word16 L_subfr,
+#endif
+ const Word16 i_subfr_fx, /* i : subframe index */
+ const Word16 gain_pit_fx, /* i : Pitch gain Q14*/
+ const Word32 gain_code_fx, /* i : algebraic codebook gain 16+Q_exc*/
+ const Word16 code_fx[], /* i : algebraic excitation Q9*/
+ const Word16 voice_fac_fx, /* i : voicing factor Q15*/
+ Word16 *voice_factors_fx, /* o : TBE voicing factor Q15*/
+ Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/
+ const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */
+ const Word16 code_preQ_fx[],/* i : prequantizer excitation */
+ const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */
+ Word16 T0, /* i : integer pitch variables Q0 */
+ Word16 T0_frac, /* i : Fractional pitch variables Q0*/
+ const Word16 coder_type, /* i : coding type */
+ Word32 core_brate /* i :core bitrate */
+#ifdef ADD_IVAS_TBE_CODE
+ , const Word16 element_mode, /* i : element mode */
+ const Word16 idchan, /* i : channel ID */
+ const Word16 flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */
+ const Word16 tdm_LRTD_flag /* i : LRTD stereo mode flag */
+#endif
+);
+
+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 */
+);
+
+void wb_tbe_extras_reset_fx(
+ Word16 mem_genSHBexc_filt_down_wb2[],
+ Word16 mem_genSHBexc_filt_down_wb3[]
+);
+
+Word16 get_tbe_bits_fx(
+ const Word32 total_brate, /* o : TBE bit consumption per frame */
+ const Word16 bwidth, /* i : overall bitrate */
+ const Word16 rf_mode /* i : bandwidht mode */
+);
+
+//pvq_com_fx
+
+UWord32 intLimCDivPos_fx(
+ UWord32 NUM,
+ Word16 DEN
+);
+
+Word16 shrtCDivSignedApprox(
+ const Word16 num,
+ const Word16 den
+);
+
+void obtainEnergyQuantizerDensity_fx(
+ const Word16 L,
+ const Word16 R,
+ Word16 *Density
+);
+
+void dsDirac2Dirac_fx(
+ const Word16 dsDiracIndex,
+ Word16 *diracs
+);
+
+void dsDiracPerQuanta_fx(
+ const Word16 td,
+ const Word16 t_quanta,
+ const Word16 dsm,
+ const unsigned char* const *frQuanta,
+ Word16 *DsIdx
+);
+
+void QuantaPerDsDirac_fx(
+ const Word16 td, /* i : Length of vector segment */
+ const Word16 dsDiracIndex, /* i : Quanta table index */
+ const unsigned char* const* dimFrQuanta, /* i : Quanta lookup table */
+ Word16* Quanta /* i : Quanta */
+);
+
+void conservativeL1Norm_fx(
+ const Word16 L, /* i : Length of vector segment */
+ const Word16 Qvec, /* i : Assigned number of quanta */
+ const Word16 Fcons, /* i : Conservative rounding flag */
+ const Word16 Qavail, /* i : Input quanta remaining */
+ const Word16 Qreserv, /* i : Input quanta in reservoir */
+ const Word16 Dspec, /* i : assigned diracs from bitalloc */
+ Word16* Dvec, /* o : actual number of diracs */
+ Word16* Qspare, /* o : Output quanta remaining */
+ Word16* Qreservplus, /* o : Output quanta in reservoir */
+ Word16* Dspecplus /* o : Output number of diracs */
+);
+
+void bandBitsAdjustment_fx(
+ const Word16 Brc, /* i : Current number of read quanta in range coder */
+ const UWord32 INTrc, /* i : Range coder state */
+ const Word16 Bavail, /* i : Available number of quanta */
+ const Word16 Nbands, /* i : Number of bands */
+ const Word16 D, /* i : Remaining number of bands to encode */
+ const Word16 L, /* i : Size of current band */
+ const Word16 Bband, /* i : Quanta allocation for current band */
+ const Word16 Breserv, /* i : Quanta reservoir */
+ Word16* Bband_adj, /* o : Actual used number of quanta */
+ Word16* Brem, /* o : Quanta remaining */
+ Word16* Breservplus /* o : Quanta pool size */
+);
+
+void densityAngle2RmsProjDec_fx(
+ const Word16 D, /* i : density */
+ const Word16 indexphi, /* i : decoded index from AR dec */
+ Word16* oppQ15, /* o : opposite */
+ Word16* nearQ15, /* o : near */
+ Word16* oppRatioQ3 /* o : ratio */
+);
+
+void densityAngle2RmsProjEnc_fx(
+ const Word16 D, /* i : density */
+ const Word16 phiQ14uq, /* i : angle */
+ Word16* indexphi, /* o : index */
+ Word16* oppQ15, /* o : opposite */
+ Word16* nearQ15, /* o : near */
+ Word16* oppRatioQ3 /* o : ratio */
+);
+
+void NearOppSplitAdjustment_fx(
+ const Word16 qband,
+ const Word16 qzero,
+ const Word16 Qac,
+ const UWord32 INTac,
+ const Word16 qglobal,
+ const Word16 FlagCons,
+ const Word16 Np,
+ const Word16 Nhead,
+ const Word16 Ntail,
+ const Word16 Nnear,
+ const Word16 Nopp,
+ Word16 oppRQ3,
+ Word16 *qnear,
+ Word16 *qopp,
+ Word16 *qglobalupd
+);
+
+void apply_gain_fx(
+ const Word16 *ord, /* i : Indices for energy order */
+ const Word16 *band_start, /* i : Sub band start indices */
+ const Word16 *band_end, /* i : Sub band end indices */
+ const Word16 num_sfm, /* i : Number of bands */
+ const Word16 *gains, /* i : Band gain vector Q12 */
+ Word16 *xq /* i/o: Float synthesis / Gain adjusted synth Q15/Q12 */
+);
+
+void fine_gain_quant_fx(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ const Word16 *ord, /* i : Indices for energy order */
+ const Word16 num_sfm, /* i : Number of bands */
+ const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */
+ Word16 *fg_pred, /* i/o: Predicted gains / Corrected gains Q12 */
+ const Word16 *gopt /* i : Optimal gains Q12 */
+);
+
+void srt_vec_ind16_fx(
+ const Word16 *linear, /* linear i */
+ Word16 *srt, /* sorted output*/
+ Word16 *I, /* index for sorted output */
+ Word16 length
+);
+
+Word16 atan2_fx(
+ const Word32,
+ const Word32
+);
+
+//rang_com_fx.c
+Word16 rc_get_bits2_fx( /* o: Number of bits needed */
+ const Word16 N, /* i: Number of bits currently used */
+ const UWord32 range /* i: Range of range coder */
+);
+
+void rangeCoderFinalizationFBits_fx(
+ Word16 Brc, /* i : Current number of decoded bits */
+ UWord32 INTrc, /* i : Range coder state */
+ Word16* FBits /* i : Fractional finalization bits */
);
+//wi_fx.c
+
+ivas_error DTFS_new_fx(DTFS_STRUCTURE** dtfs_out);
+
+
+void DTFS_copy_fx(
+ DTFS_STRUCTURE *Xout_fx, /* o: DTFS structure */
+ DTFS_STRUCTURE Xinp_fx /* i: DTFS structure */
+);
+
+void DTFS_sub_fx(
+ DTFS_STRUCTURE* tmp,/* o: X1 - X2 */
+ DTFS_STRUCTURE X1, /* i: DTFS i 1 */
+ DTFS_STRUCTURE X2 /* i: DTFS i 2 */
+);
+
+Word16 DTFS_alignment_full_fx(
+ DTFS_STRUCTURE X1_DTFS_fx, /* i : reference DTFS */
+ DTFS_STRUCTURE X2_DTFS_fx, /* i : DTFS to shift */
+ Word16 ph_offset_fx, /* i : resolution */
+ Word16 *S_fx,
+ Word16 *C_fx
+ , Word16 FR_flag
+);
+
+void DTFS_phaseShift_fx(DTFS_STRUCTURE *X_fx, Word16 ph, Word16 Lag, Word16 *S_fx, Word16 *C_fx);
+
+void Q2phaseShift_fx(DTFS_STRUCTURE *X_fx, Word16 ph, Word16 Lag, Word16 *S_fx, Word16 *C_fx);
+
+void DTFS_zeroPadd_fx(Word16 N_fx, DTFS_STRUCTURE *X_fx);
+
+void DTFS_to_fs_fx(
+ const Word16* x, /* i : time domain signal */
+ Word16 N, /* i : Length of i vector */
+ DTFS_STRUCTURE* X_fx, /* o : DTFS structure with a, b, lag */
+ const Word16 Fs, /* i : sampling rate */
+ const Word16 FR_flag, /* i : FR flag */
+ Word16* S_fx,
+ Word16* C_fx
+);
+
+void DTFS_zeroFilter_fx(
+ DTFS_STRUCTURE *X_fx,
+ Word16 *LPC,
+ Word16 N,
+ Word16 *S_fx,
+ Word16 *C_fx
+);
+
+void DTFS_poleFilter_fx_9(DTFS_STRUCTURE *X_fx, Word16 *pf_temp1, Word16 *pf_temp2, Word16 *pf_temp, Word16 *pf_n2_temp1);
+
+void DTFS_adjustLag_fx(
+ DTFS_STRUCTURE *X_DTFS_FX, /* i/o : DTFS to adjust lag for */
+ Word16 N_fx /* i : Target lag */
+);
+
+Word32 DTFS_getEngy_fx(DTFS_STRUCTURE *X_fx);
+
+Word32 DTFS_getEngy_P2A_fx(DTFS_STRUCTURE *X_fx);
+
+void DTFS_car2pol_fx(
+ DTFS_STRUCTURE *X_fx /* i/o : DTFS structure a, b, lag */
+);
+
+Word32 DTFS_setEngyHarm_fx(
+ Word16 f1_fx, /* i : lower band freq of i to control energy */
+ Word16 f2_fx, /* i : upper band freq of i to control energy */
+ Word16 g1_fx, /* i : lower band freq of output to control energy */
+ Word16 g2_fx, /* i : upper band freq of output to control energy */
+ Word32 en2_fx, /* i : Target Energy to set the DTFS to */
+ Word16 Qen2_fx, /* i : Input Q format for en2 */
+ Word16 *Qa_fx, /* i : Output Q format for x->a */
+ DTFS_STRUCTURE *X_fx /* i/o: DTFS to adjust the energy of */
+);
+
+void DTFS_to_erb_fx(
+ const DTFS_STRUCTURE X_fx, /* i : DTFS i */
+ Word16 *out_fx /* o : ERB output */
+);
+
+void erb_slot_fx(
+ Word16 lag_fx, /* i : i lag */
+ Word16 *out_fx, /* o : ERB slots */
+ Word16 *mfreq_fx, /* i : ERB frequencies */
+ Word16 num_erb_fx /* i : number of ERBs */
+);
+
+void DTFS_erb_inv_fx(
+ Word16 *in_fx, /* i : ERB inpt */
+ Word16 *slot_fx, /* i : ERB slots filled based on lag */
+ Word16 *mfreq_fx, /* i : erb frequence edges */
+ DTFS_STRUCTURE *X_fx, /* o : DTFS after erb-inv */
+ Word16 num_erb_fx /* i : Number of ERB bands */
+);
+
+void erb_add_fx(
+ Word16 *curr_erb_fx, /* i/o: current ERB */
+ Word16 l_fx, /* i : current lag */
+ const Word16 *prev_erb_fx, /* i : previous ERB */
+ Word16 pl_fx, /* i : previous lag */
+ const Word16 *index_fx, /* i : ERB index */
+ Word16 num_erb_fx /* i : number of ERBs */
+);
+
+void quant_target_fx(DTFS_STRUCTURE *X_fx, const Word16 *curr_lpc, Word16 *w, Word16 *target,
+ Word16 *sin_tab, Word16 *cos_tab);
+
+ivas_error WIsyn_fx(
+ DTFS_STRUCTURE PREVCW_FX, /* i : Prev frame DTFS */
+ DTFS_STRUCTURE* CURR_CW_DTFS_FX, /* i/o: Curr frame DTFS */
+ const Word16* curr_lpc_fx, /* i : LPC */
+ Word16* ph_offset_fx, /* i/o: Phase offset to line up at end of frame */
+ Word16* out_fx, /* o : Waveform Interpolated time domain signal */
+ const Word16 N, /* i : Number of output samples to generate */
+ const Word16 FR_flag, /* i : called for post-smoothing in FR */
+ Word16* S_fx,
+ Word16* C_fx,
+ Word16* pf_temp1,
+ Word16* pf_temp2,
+ Word16* pf_temp,
+ Word16* pf_n2
+);
+
+Word16 ppp_extract_pitch_period_fx(
+ const Word16 *in, /* i : i residual */
+ Word16 *out, /* o : output residual */
+ Word16 l, /* i : lag */
+ Word16 *out_of_bound, /* o : out of bound flag */
+ Word16 Qres
+
+);
+
+void DTFS_peaktoaverage_fx(
+ DTFS_STRUCTURE X_fx, /* i : DTFS */
+ Word32 *pos_fx, /* o : positive peak to ave */
+ Word16 *Qpos, /* o : positive peak to ave Q format */
+ Word32 *neg_fx, /* o : negative peak to ave */
+ Word16 *Qneg /* o : negative peak to ave Q format */
+);
+
+void rshiftHarmBand_fx(DTFS_STRUCTURE *X_fx, Word16 lband_fx, Word16 hband_fx, Word16 shift_fx);
+
+void GetSinCosTab_fx(Word16 L, Word16 *sinTab, Word16 *cosTab);
+
+void r_fft_4_fx(Word16 * farray_ptr_fx, Word16 size, Word16 stage, Word16 isign);
+
+void copy_phase_fx(DTFS_STRUCTURE *X1_fx, DTFS_STRUCTURE X2_fx, DTFS_STRUCTURE *retX_fx);
+
+Word32 getSpEngyFromResAmp_fx(DTFS_STRUCTURE *X_fx, Word16 lband, Word16 hband,
+ const Word16 *curr_lpc, Word16 *sin_tab,
+ Word16 *cos_tab);
+
+void DTFS_poleFilter_fx(DTFS_STRUCTURE *X_fx, Word16 *LPC, Word16 N, Word16 *S_fx, Word16 *C_fx);
+
+void poleFilter_setup_fx(const Word16 *LPC, Word16 N, DTFS_STRUCTURE X_fx, Word16 *S_fx, Word16 *C_fx, Word16 *pf_temp1, Word16 *pf_temp2, Word16 *pf_temp, Word16 *pf_n2_temp1);
+
+Word32 DTFS_getEngy_band_wb_fx(
+ DTFS_STRUCTURE X_fx,
+ Word16 lband,
+ Word16 hband
+);
#endif
\ No newline at end of file
diff --git a/lib_com/pvq_com.c b/lib_com/pvq_com.c
index f31c4dc7d7e961864963df164d1537d6534c5a0b..05596fa1172beac9c3a792d0203e1e91c9202470 100644
--- a/lib_com/pvq_com.c
+++ b/lib_com/pvq_com.c
@@ -48,7 +48,7 @@
*-------------------------------------------------------------------*/
/*! r: Approximate integer division for negative input */
-int16_t shrtCDivSignedApprox(
+int16_t shrtCDivSignedApprox_flt(
const int16_t num, /* i : numerator */
const int16_t den /* i : denominator */
)
@@ -791,7 +791,7 @@ Word16 ratio_float(
}
/*-----------------------------------------------------------------------------
- * atan2_fx():
+ * atan2_fx_flt():
*
* Approximates arctan piecewise with various 4th to 5th order least square fit
* polynomials for input in 5 segments:
@@ -803,7 +803,7 @@ Word16 ratio_float(
*---------------------------------------------------------------------------*/
/*! r: Angle between 0 and EVS_PI/2 radian (Q14) */
-Word16 atan2_fx(
+Word16 atan2_fx_flt(
const Word32 y, /* i : near side (Argument must be positive) (Q15) */
const Word32 x /* i : opposite side (Q15) */
)
diff --git a/lib_com/pvq_com_fx.c b/lib_com/pvq_com_fx.c
new file mode 100644
index 0000000000000000000000000000000000000000..31cf8bb752ac8fe113b9322c7e2ed0f4d4fe4285
--- /dev/null
+++ b/lib_com/pvq_com_fx.c
@@ -0,0 +1,768 @@
+/*====================================================================================
+ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
+ ====================================================================================*/
+#include
+#include "options.h" /* Compilation switches */
+#include "prot_fx1.h"
+#include "prot_fx2.h" /* Function prototypes */
+#include "cnst.h" /* Common constants */
+#include "rom_com.h" /* Static table prototypes */
+
+ /*! r: Approximate integer division for positive input using lookup table */
+UWord32 intLimCDivPos_fx(
+ UWord32 NUM,
+ Word16 DEN
+)
+{
+ UWord32 UL_ru, UL_rl;
+ Mpy_32_32_uu(UL_lshl(NUM, 1), intLimCDivInvDQ31[DEN], &UL_ru, &UL_rl);
+ return UL_ru;
+}
+
+/*! r: Approximate integer division for signed input using lookup table */
+static Word32 intLimCDivSigned_fx(
+ Word32 NUM,
+ Word16 DEN
+)
+{
+ Word32 L_tmp;
+
+ L_tmp = intLimCDivPos_fx( L_abs(NUM) , DEN);
+ if (NUM < 0)
+ {
+ L_tmp= L_negate(L_tmp); /* one op */
+ }
+ return L_tmp;
+}
+
+/*! r: Approximate integer division for negative input */
+Word16 shrtCDivSignedApprox(
+ const Word16 num,
+ const Word16 den
+)
+{
+ Word16 pool_part;
+
+ pool_part = extract_h( L_mult( negate(abs_s(num)), lim_neg_inv_tbl_fx[den] ));
+ /* neg_in always, positive out always, so that positive truncation(rounding) is used */
+ if ( num < 0 )
+ {
+ pool_part = negate(pool_part); /* make negative, one op */
+ }
+ return pool_part;
+}
+
+static void nearProjQ15_fx(
+ const Word16 x, /* i : input coefficient */
+ Word16* result /* o : projection */
+)
+{
+ const Word16 a[4] = {14967, -25518, 3415, 32351};
+ Word32 b;
+ UWord16 lsb;
+
+ b = L_deposit_l(a[0]);
+ b = L_shl((Word32)add(a[1], extract_h(L_mult0((Word16)b, x))), 1);
+ Mpy_32_16_ss(b, x, &b, &lsb);
+ b = L_add((Word32)a[2], b);
+ Mpy_32_16_ss(b, x, &b, &lsb);
+ b = L_add((Word32)a[3], b);
+ *result = extract_l(b);
+ return ;
+}
+
+/*-------------------------------------------------------------------*
+ * obtainEnergyQuantizerDensity_fx()
+ *
+ *
+ *-------------------------------------------------------------------*/
+void obtainEnergyQuantizerDensity_fx(
+ const Word16 L, /* i : left vector energy */
+ const Word16 R, /* i : right vector energy */
+ Word16* Density /* o : quantizer density */
+)
+{
+ Word16 Rnrg, den, n;
+
+ den = sub(shl(L, 1), 1);
+ IF( den <= 67 )
+ {
+ Rnrg = extract_l(intLimCDivPos_fx( L_deposit_l(R) , den));
+ }
+ ELSE
+ {
+ n = norm_s(den);
+ Rnrg = shr(div_s(R, shl(den, n)), sub(15, n));
+ }
+ Rnrg = add(Rnrg, 28);
+
+ Rnrg = s_min(Rnrg, 56);
+ Rnrg = s_min(Rnrg, sub(R, 96));
+
+ Rnrg = s_max(Rnrg, 3);
+ *Density = obtainEnergyQuantizerDensity_f[Rnrg];
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * dsDirac2Dirac_fx()
+ *
+ *
+ *-------------------------------------------------------------------*/
+void dsDirac2Dirac_fx(
+ const Word16 dsDiracIndex, /* i : input index */
+ Word16* diracs /* o : number of diracs */
+)
+{
+ *diracs = dsDiracsTab[dsDiracIndex];
+ return;
+}
+
+void dsDiracPerQuanta_fx(
+ const Word16 td, /* i : Length of vector segment */
+ const Word16 t_quanta, /* i : Assigned number of quanta */
+ const Word16 dsm, /* i : Conservative rounding flag */
+ const unsigned char* const* frQuanta, /* i : Quanta lookup table */
+ Word16* DsIdx /* o : Lookup table index */
+)
+{
+ const unsigned char *sv;
+ Word16 nsv;
+ Word16 t_quanta_o;
+ Word16 dsIndex;
+ Word16 i;
+
+ sv = frQuanta[td];
+ nsv = sv[0];
+
+ t_quanta_o = sub(t_quanta, QUANTAQ3OFFSET);
+
+ IF (GE_16(t_quanta_o, sv[nsv]))
+ {
+ *DsIdx = nsv;
+ move16();
+ return ;
+ }
+
+ IF (LE_16(t_quanta_o, sv[1]))
+ {
+ *DsIdx = 1;
+ move16();
+ return ;
+ }
+
+
+ dsIndex = shl(1, frQuanta[0][td]);
+ if (GT_16(t_quanta_o, sv[shr(nsv, 1) ]))
+ {
+ dsIndex = sub(nsv, dsIndex );
+ }
+ FOR (i = sub(frQuanta[0][td], 1); i >= 0; i--)
+ {
+ dsIndex = add(dsIndex, shl(sub(shl(lshr(sub(sv[dsIndex], t_quanta_o), 15), 1), 1), i));
+ }
+
+ dsIndex = add(dsIndex, lshr(sub(sv[dsIndex], t_quanta_o), 15));
+ dsIndex = sub(dsIndex, lshr(sub(1, dsIndex), 15));
+
+ IF (EQ_16(dsm, PVQ_CONS))
+ {
+ *DsIdx=dsIndex;
+ move16();
+ return;
+ }
+ *DsIdx = add(dsIndex, lshr(sub(add(sv[add(dsIndex,1)], sv[dsIndex]), shl(t_quanta_o, 1)), 15));
+ return;
+}
+
+void QuantaPerDsDirac_fx(
+ const Word16 td, /* i : Length of vector segment */
+ const Word16 dsDiracIndex, /* i : Quanta table index */
+ const unsigned char* const* dimFrQuanta, /* i : Quanta lookup table */
+ Word16* Quanta /* i : Quanta */
+)
+{
+ *Quanta = dimFrQuanta[td][dsDiracIndex];
+ move16();
+ if(dsDiracIndex == 0)
+ {
+ *Quanta = -1; /* single op */ move16();
+ }
+ *Quanta = add(*Quanta, QUANTAQ3OFFSET);
+ return ;
+}
+
+void conservativeL1Norm_fx(
+ const Word16 L, /* i : Length of vector segment */
+ const Word16 Qvec, /* i : Assigned number of quanta */
+ const Word16 Fcons, /* i : Conservative rounding flag */
+ const Word16 Qavail, /* i : Input quanta remaining */
+ const Word16 Qreserv, /* i : Input quanta in reservoir */
+ const Word16 Dspec, /* i : assigned diracs from bitalloc */
+ Word16* Dvec, /* o : actual number of diracs */
+ Word16* Qspare, /* o : Output quanta remaining */
+ Word16* Qreservplus, /* o : Output quanta in reservoir */
+ Word16* Dspecplus /* o : Output number of diracs */
+)
+{
+
+ Word16 Minit, Mprime;
+ Word16 Qtestminus;
+ const unsigned char *frQuantaL;
+
+ frQuantaL = hBitsN[L];
+
+ *Qreservplus = add(Qreserv, sub(Qvec, QUANTAQ3OFFSET));
+
+ dsDiracPerQuanta_fx(L, Qvec, Fcons, hBitsN, &Minit);
+
+ Mprime = Minit;
+ move16();
+ DO
+ {
+ Qtestminus = (short)frQuantaL[Mprime];
+ move16();
+ *Qspare = sub(Qavail, Qtestminus);
+ Mprime = sub(Mprime, 1);
+ }
+ WHILE ( (Mprime >= 0) && LT_16(*Qspare, QUANTAQ3OFFSET ));
+
+ if(Mprime < 0)
+ {
+ *Qspare = add(Qavail, QUANTAQ3OFFSET); /* single op */
+ }
+ dsDirac2Dirac_fx(add(Mprime, 1), Dvec);
+
+ *Dspecplus = add(Dspec, *Dvec);
+ *Qreservplus = sub(*Qreservplus, (short)frQuantaL[Minit]);
+ *Qspare = sub(*Qspare, QUANTAQ3OFFSET);
+
+ return;
+}
+
+
+
+
+
+void bandBitsAdjustment_fx(
+ const Word16 Brc, /* i : Current number of read quanta in range coder */
+ const UWord32 INTrc, /* i : Range coder state */
+ const Word16 Bavail, /* i : Available number of quanta */
+ const Word16 Nbands, /* i : Number of bands */
+ const Word16 D, /* i : Remaining number of bands to encode */
+ const Word16 L, /* i : Size of current band */
+ const Word16 Bband, /* i : Quanta allocation for current band */
+ const Word16 Breserv, /* i : Quanta reservoir */
+ Word16* Bband_adj, /* o : Actual used number of quanta */
+ Word16* Brem, /* o : Quanta remaining */
+ Word16* Breservplus /* o : Quanta pool size */
+)
+{
+ Word16 Btemp;
+ Word16 Bff;
+ Word32 L_tmp;
+
+ rangeCoderFinalizationFBits_fx(Brc, INTrc, &Bff);
+
+ IF(LT_16(D, Nbands))
+ {
+ L_tmp = L_deposit_l(sub(Breserv, Bff));
+ Btemp = extract_l(intLimCDivSigned_fx(L_tmp, s_min(D, 3))); /* result always fits in Word16 */
+ *Breservplus = add(Bband, Breserv);
+ }
+ ELSE
+ {
+ Btemp = 0;
+ move16();
+ *Breservplus = add(Bband, Bff);
+ }
+ *Bband_adj = s_min(extract_l(L_mult(L, 40)), Bband);
+ *Brem = sub(Bavail, Bff);
+ *Bband_adj = s_min(*Brem, add(*Bband_adj, Btemp));
+ *Bband_adj = s_max(0, *Bband_adj);
+ return;
+}
+
+
+
+static Word16 Ratio_base2Q11_fx( /* o : Q11 */
+ const Word16 opp, /* i : opposite Q15 */
+ const Word16 near /* i : near Q15 */
+)
+{
+ Word16 mc, nc, ms, ns, d, z;
+ Word16 result;
+ Word32 acc;
+
+ ns = norm_s(opp ); /* exponent */
+ nc = norm_s(near ); /* exponent */
+
+ ms = shl(opp, ns); /* mantissa */
+ mc = shl(near, nc); /* mantissa */
+
+ acc = L_mac(538500224L, mc, -2776); /* a0*mc + a1, acc(Q27), a0(Q11), a1(Q27) */
+ z = mac_r(acc, ms, -2776); /* z in Q11, a0 in Q11 */
+ d = sub(ms, mc); /* d in Q15 */
+ z = mult_r(z, d); /* z in Q11 */
+
+ result = add(z, shl(sub(nc, ns), 11));
+
+ return result;
+}
+
+static void Ratio_rQ3_fx(
+ Word16 opp, /* i : opposite */
+ Word16 near, /* i : near */
+ Word16* result /* o : ratio */
+)
+{
+ Word16 tmp;
+
+ tmp = add(1<<7 , Ratio_base2Q11_fx(opp, near));
+ *result = shr(tmp, 8);
+ return ;
+}
+
+
+void densityAngle2RmsProjDec_fx(
+ const Word16 D, /* i : density */
+ const Word16 indexphi, /* i : decoded index from AR dec */
+ Word16* oppQ15, /* o : opposite */
+ Word16* nearQ15, /* o : near */
+ Word16* oppRatioQ3 /* o : ratio */
+)
+{
+ Word16 phiQ14q;
+ Word16 oppTail, nearTail;
+
+ phiQ14q = (Word16)intLimCDivPos_fx(L_shl(L_deposit_l(indexphi), 13), shr(D, 1));
+ if (indexphi < 0)
+ {
+ phiQ14q = 1 << 13; /* one op */ move16();
+ }
+
+ oppTail = shr(sub(16320, phiQ14q), 15);
+ nearTail = shr(sub(phiQ14q, 64), 15);
+
+ IF (s_or(oppTail, nearTail) < 0)
+ {
+ *oppQ15 = s_and(oppTail, (1 << 15) - 1);
+ *nearQ15 = s_and(nearTail, (1 << 15) - 1);
+ *oppRatioQ3 = shl(add(1, shl(nearTail, 1)), 14);
+ }
+ ELSE
+ {
+ nearProjQ15_fx( shl(sub(1 << 14, phiQ14q), 1), oppQ15);
+ nearProjQ15_fx(shl(phiQ14q, 1), nearQ15);
+ Ratio_rQ3_fx(*oppQ15, *nearQ15, oppRatioQ3);
+ }
+
+ return;
+}
+
+void densityAngle2RmsProjEnc_fx(
+ const Word16 D, /* i : density */
+ const Word16 phiQ14uq, /* i : angle */
+ Word16* indexphi, /* o : index */
+ Word16* oppQ15, /* o : opposite */
+ Word16* nearQ15, /* o : near */
+ Word16* oppRatioQ3 /* o : ratio */
+)
+{
+ *indexphi = mult_r(shl(D, 1), phiQ14uq);
+ if (s_and(D, 1) > 0)
+ {
+ *indexphi = -1; /* one op */ move16();
+ }
+ densityAngle2RmsProjDec_fx(D, *indexphi, oppQ15, nearQ15, oppRatioQ3);
+
+ return;
+}
+
+void NearOppSplitAdjustment_fx(
+ const Word16 qband, /* i : quanta for current band */
+ const Word16 qzero, /* i : range coder finalization quanta */
+ const Word16 Qac, /* i : range coder current quanta */
+ const UWord32 INTac, /* i : range coder state */
+ const Word16 qglobal, /* i : quanta input */
+ const Word16 FlagCons, /* i : conservative rounding flag */
+ const Word16 Np, /* i : number of parts */
+ const Word16 Nhead, /* i : first part */
+ const Word16 Ntail, /* i : remaining parts */
+ const Word16 Nnear, /* i : length of near component */
+ const Word16 Nopp, /* i : length of opposite component */
+ Word16 oppRQ3, /* i : ratio */
+ Word16* qnear, /* o : quantized near */
+ Word16* qopp, /* o : quantized opposite */
+ Word16* qglobalupd /* o : quanta remaining */
+)
+{
+
+ Word16 qac, qboth, qskew, qavg, qmin, Midx;
+ Word32 L_QIb, L_qnum;
+ Word16 QIb, QIa;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+
+ rangeCoderFinalizationFBits_fx(Qac, INTac, &qac);
+ qboth = sub(qband, sub(qac, qzero));
+ /* skew calc code */
+ qskew = 0 ;
+ move16();
+ IF (GT_16(Nhead, 1))
+ {
+ qavg = extract_h(L_shl(intLimCDivSigned_fx((Word32)qboth, Np),16)); /* qboth may be negative */
+ dsDiracPerQuanta_fx(Ntail, qavg, FlagCons, hBitsN, &Midx );
+ QuantaPerDsDirac_fx(Nhead, Midx, hBitsN, &qmin);
+ qskew = sub(qavg, qmin);
+ qskew = s_max(0, qskew);
+ } /* end of skew calc code*/
+
+ QIa = add(extract_l(intLimCDivPos_fx((UWord32)L_deposit_l(Nopp), Nnear)), 1); /* always positive Word16 out */
+ L_qnum = L_sub( L_deposit_l(sub(sub(add(qband, qzero), qac), qskew)), L_mult0(Nopp, oppRQ3));
+
+ L_QIb = L_deposit_l(0);
+ IF (L_qnum > 0)
+ {
+ L_QIb = (Word32) intLimCDivPos_fx(L_qnum, QIa);
+ }
+ *qnear = qboth;
+#ifdef BASOP_NOGLOB
+ QIb = extract_h(L_shl_o(L_QIb, 16, &Overflow)); /* may saturate */
+#else
+ QIb = extract_h(L_shl(L_QIb, 16)); /* may saturate */
+#endif
+ if (LE_16(QIb, qboth))
+ {
+ *qnear = QIb;
+ }
+ *qopp = sub(qboth, *qnear);
+ *qglobalupd = sub(qglobal, sub(qac, qzero));
+
+ return;
+}
+
+
+/*--------------------------------------------------------------------------*
+ * apply_gain()
+ *
+ * Apply gain
+ *--------------------------------------------------------------------------*/
+
+void apply_gain_fx(
+ const Word16 *ord, /* i : Indices for energy order */
+ const Word16 *band_start, /* i : Sub band start indices */
+ const Word16 *band_end, /* i : Sub band end indices */
+ const Word16 num_sfm, /* i : Number of bands */
+ const Word16 *gains, /* i : Band gain vector Q12 */
+ Word16 *xq /* i/o: Float synthesis / Gain adjusted synth Q15/Q12 */
+)
+{
+ Word16 band,i;
+ Word16 g; /* Q12 */
+
+ FOR ( band = 0; band < num_sfm; band++)
+ {
+ g = gains[ord[band]];
+
+ FOR( i = band_start[band]; i < band_end[band]; i++)
+ {
+ /*xq[i] *= g; */
+ xq[i] = mult_r(g, xq[i]);
+ move16(); /*12+15+1-16=12 */
+ }
+ }
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * fine_gain_quant()
+ *
+ * Fine gain quantization
+ *--------------------------------------------------------------------------*/
+
+void fine_gain_quant_fx(
+ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
+ const Word16 *ord, /* i : Indices for energy order */
+ const Word16 num_sfm, /* i : Number of bands */
+ const Word16 *gain_bits, /* i : Gain adjustment bits per sub band */
+ Word16 *fg_pred, /* i/o: Predicted gains / Corrected gains Q12 */
+ const Word16 *gopt /* i : Optimal gains Q12 */
+)
+{
+ Word16 band;
+ Word16 gbits;
+ Word16 idx;
+ Word16 gain_db,gain_dbq;
+ Word16 err;
+
+ Word16 tmp1, tmp2, exp1, exp2;
+ Word32 L_tmp;
+ UWord16 lsb;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+
+ FOR ( band = 0; band < num_sfm; band++)
+ {
+ gbits = gain_bits[ord[band]];
+ test();
+ IF ( fg_pred[band] != 0 && gbits > 0 )
+ {
+ exp1 = norm_s(gopt[band]);
+ exp1 = sub(exp1, 1);
+ tmp1 = shl(gopt[band], exp1);
+ exp2 = norm_s(fg_pred[band]);
+ tmp2 = shl(fg_pred[band], exp2);
+ exp1 = add(15, sub(exp1, exp2));
+ err = div_s(tmp1, tmp2);
+ tmp1 = norm_s(err);
+ exp2 = Log2_norm_lc(L_deposit_h(shl(err, tmp1)));
+ tmp1 = sub(14, tmp1);
+ tmp1 = sub(tmp1, exp1);
+ L_tmp = L_Comp(tmp1, exp2);
+ Mpy_32_16_ss(L_tmp, 24660, &L_tmp, &lsb); /* 24660 = 20*log10(2) in Q12 */ /*16+12-15=13 */
+#ifdef BASOP_NOGLOB
+ gain_db = round_fx(L_shl_o(L_tmp, 17, &Overflow));
+#else /* BASOP_NOGLOB */
+ gain_db = round_fx(L_shl(L_tmp, 17));
+#endif
+
+ idx = squant_fx(gain_db, &gain_dbq, finegain_fx[gbits-1], gain_cb_size[gbits-1]);
+ push_indice_fx( hBstr, IND_PVQ_FINE_GAIN, idx, gbits );
+
+ L_tmp = L_mult0(gain_dbq, 21771); /* 21771=0.05*log2(10) */ /* 14+17=31 */
+ L_tmp = L_shr(L_tmp, 15);
+ tmp1 = L_Extract_lc(L_tmp, &exp1);
+ tmp1 = abs_s(tmp1);
+ tmp1 = extract_l(Pow2(14, tmp1));
+ exp1 = sub(14, exp1);
+
+ L_tmp = L_mult0(fg_pred[band], tmp1); /*12+exp1 */
+ fg_pred[band] = round_fx(L_shl(L_tmp, sub(16, exp1))); /*12+exp1+16-exp1-16=12 */
+ }
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * srt_vec_ind()
+ *
+ * sort vector and save sorting indeces
+ *-------------------------------------------------------------------*/
+
+void srt_vec_ind16_fx (
+ const Word16 *linear,/* linear input */
+ Word16 *srt, /* sorted output*/
+ Word16 *I, /* index for sorted output */
+ Word16 length
+)
+{
+ Word16 pos,npos;
+ Word16 idxMem;
+ Word16 valMem;
+
+ /*initilize */
+ FOR (pos = 0; pos < length; pos++)
+ {
+ I[pos] = pos;
+ move16();
+ }
+
+ Copy(linear, srt,length);
+
+ /* now iterate */
+ FOR (pos = 0; pos < (length - 1); pos++)
+ {
+ FOR (npos = (pos + 1); npos < length; npos++)
+ {
+ IF (LT_16(srt[npos], srt[pos]))
+ {
+ idxMem = I[pos];
+ move16();
+ I[pos] = I[npos];
+ move16();
+ I[npos] = idxMem;
+ move16();
+
+ valMem = srt[pos];
+ move16();
+ srt[pos] = srt[npos];
+ move16();
+ srt[npos] = valMem;
+ move16();
+ }
+ }
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------------------
+ * atan2_fx():
+ *
+ * Approximates arctan piecewise with various 4th to 5th order least square fit
+ * polynomials for input in 5 segments:
+ * - 0.0 to 1.0
+ * - 1.0 to 2.0
+ * - 2.0 to 4.0
+ * - 4.0 to 8.0
+ * - 8.0 to infinity
+ *---------------------------------------------------------------------------*/
+Word16 atan2_fx( /* o: Angle between 0 and PI/2 radian (Q14) */
+ const Word32 y, /* i : near side (Argument must be positive) (Q15) */
+ const Word32 x /* i : opposite side (Q15) */
+)
+{
+ Word32 acc, arg;
+ Word16 man, expo, reciprocal;
+ Word16 angle, w, z;
+
+ IF (x == 0)
+ {
+ return 25736; /* PI/2 in Q14 */
+ }
+ man = ratio(y, x, &expo); /* man in Q14 */
+ expo = sub(expo, (15 - 14)); /* Now, man is considered in Q15 */
+ arg = L_shr((Word32)man, expo);
+
+ IF (L_shr(arg, 3+15) != 0)
+ /*===============================*
+ * 8.0 <= x < infinity *
+ *===============================*/
+ {
+ /* atan(x) = PI/2 - 1/x + 1/(3x^3) - 1/(5x^5) + ...
+ * ~ PI/2 - 1/x, for x >= 8.
+ */
+ expo = norm_l(arg);
+ man = extract_h(L_shl(arg, expo));
+ reciprocal = div_s(0x3fff, man);
+ expo = sub(15 + 1, expo);
+ reciprocal = shr(reciprocal, expo); /* Q14 */
+ angle = sub(25736, reciprocal); /* Q14 (PI/2 - 1/x) */
+
+ /* For 8.0 <= x < 10.0, 1/(5x^5) is not completely negligible.
+ * For more accurate result, add very small correction term.
+ */
+ if (LT_32(L_shr(arg, 15), 10L))
+ {
+ angle = add(angle, 8); /* Add tiny correction term. */
+ }
+ }
+ ELSE IF (L_shr(arg, 2+15) != 0)
+ /*==========================*
+ * 4.0 <= x < 8.0 *
+ *==========================*/
+ {
+ /* interval: [3.999, 8.001]
+ * atan(x) ~ (((a0*x + a1)*x + a2)*x + a3)*x + a4
+ * = (((a0*8*y + a1)*8*y + a2)*8*y + a3)*8*y + a4 Substitute 8*y -> x
+ * = (((a0*8^3*y + a1*8^2)*y + a2*8)*y + a3)*8*y + a4
+ * = ((( c0*y + c1)*y + c2)*y + c3)*8*y + c4,
+ * where y = x/8
+ * and a0 = -1.28820869667651e-04, a1 = 3.88263533346295e-03,
+ * a2 = -4.64216306484597e-02, a3 = 2.75986060068931e-01,
+ * a4 = 7.49208077809799e-01.
+ */
+ w = extract_l(L_shr(arg, 3)); /* Q15 y = x/8 */
+ acc = L_add(533625337L, 0); /* Q31 c1 = a1*8^2 */
+ z = mac_r(acc, w, -2161); /* Q15 c0 = a0*8^3 */
+ acc = L_add(-797517542L, 0); /* Q31 c2 = a2*8 */
+ z = mac_r(acc, w, z); /* Q15 */
+ acc = L_add(592675551L, 0); /* Q31 c3 = a3 */
+ z = mac_r(acc, w, z); /* z (in:Q15, out:Q12) */
+ acc = L_add(201114012L, 0); /* Q28 c4 = a4 */
+ acc = L_mac(acc, w, z); /* Q28 */
+ angle = extract_l(L_shr(acc, (28 - 14))); /* Q14 result of atan(x), where 4 <= x < 8 */
+ }
+ ELSE IF (L_shr(arg, 1+15) != 0)
+ /*==========================*
+ * 2.0 <= x < 4.0 *
+ *==========================*/
+ {
+ /* interval: [1.999, 4.001]
+ * atan(x) ~ (((a0*x + a1)*x + a2)*x + a3)*x + a4
+ * = (((a0*4*y + a1)*4*y + a2)*4*y + a3)*4*y + a4 Substitute 4*y -> x
+ * = (((a0*16*y + a1*4)*y + a2)*4*y + a3)*4*y + a4
+ * = (((a0*32*y + a1*8)*y + a2*2)*2*y + a3)*4*y + a4
+ * = ((( c0*y + c1)*y + c2)*2*y + c3)*4*y + c4,
+ * where y = x/4
+ * and a0 = -0.00262378195660943, a1 = 0.04089687039888652,
+ * a2 = -0.25631148958325911, a3 = 0.81685854627399479,
+ * a4 = 0.21358070563097167
+ * */
+ w = extract_l(L_shr(arg, 2)); /* Q15 y = x/4 */
+ acc = L_add(702602883L, 0); /* Q31 c1 = a1*8 */
+ z = mac_r(acc, w, -2751); /* Q15 c0 = a0*32 */
+ acc = L_add(-1100849465L, 0); /* Q31 c2 = a2*2 */
+ z = mac_r(acc, w, z); /* z (in:Q15, out:Q14) */
+ acc = L_add(877095185L, 0); /* Q30 c3 = a3 */
+ z = mac_r(acc, w, z); /* z (in:Q14, out:Q12) */
+ acc = L_add(57332634L, 0); /* Q28 c4 = a4 */
+ acc = L_mac(acc, w, z); /* Q28 */
+ angle = extract_l(L_shr(acc, (28 - 14))); /* Q14 result of atan(x) where 2 <= x < 4 */
+ }
+ ELSE IF (L_shr(arg, 15) != 0)
+ /*==========================*
+ * 1.0 <= x < 2.0 *
+ *==========================*/
+ {
+ /* interval: [0.999, 2.001]
+ * atan(x) ~ (((a0*x + 1)*x + a2)*x + a3)*x + a4
+ * = (((a0*2*y + a1)*2*y + a2)*2*y + a3)*2*y + a4 Substitute 2*y -> x
+ * = (((a0*4*y + a1*2)*y + a2)*2*y + a3)*2*y + a4
+ * = (((a0*4*y + a1*2)*y + a2)*y + a3/2)*4*y + a4
+ * = ((( c0*y + c1)*y + c2)*y + c3)*4*y + c4,
+ * where y = x/2
+ * and a0 = -0.0160706457245251, a1 = 0.1527106504065224,
+ * a2 = -0.6123208404800871, a3 = 1.3307896976322915,
+ * a4 = -0.0697089375247448
+ */
+ w = extract_l(L_shr(arg, 1)); /* Q15 y= x/2 */
+ acc = L_add(655887249L, 0); /* Q31 c1 = a1*2 */
+ z = mac_r(acc, w, -2106); /* Q15 c0 = a0*4 */
+ acc = L_add(-1314948992L, 0); /* Q31 c2 = a2 */
+ z = mac_r(acc, w, z);
+ acc = L_add(1428924557L, 0); /* Q31 c3 = a3/2 */
+ z = mac_r(acc, w, z); /* z (in:Q15, out:Q13) */
+ acc = L_add(-37424701L, 0); /* Q29 c4 = a4 */
+ acc = L_mac(acc, w, z); /* Q29 */
+ angle = extract_l(L_shr(acc, (29 - 14))); /* Q14 result of atan(x) where 1 <= x < 2 */
+ }
+ ELSE
+ /*==========================*
+ * 0.0 <= x < 1.0 *
+ *==========================*/
+ {
+ /* interval: [-0.001, 1.001]
+ * atan(x) ~ ((((a0*x + a1)*x + a2)*x + a3)*x + a4)*x + a5
+ * = ((((a0*2*x + a1*2)*x/2 + a2)*x + a3)*x + a4)*x + a5
+ * = (((( c0*x + c1)*x/2 + c2)*x + c3)*x + c4)*x + c5
+ * where
+ * a0 = -5.41182677118661e-02, a1 = 2.76690449232515e-01,
+ * a2 = -4.63358392562492e-01, a3 = 2.87188466598566e-02,
+ * a4 = 9.97438122814383e-01, a5 = 5.36158556179092e-05.
+ */
+ w = extract_l(arg); /* Q15 */
+ acc = L_add(1188376431L, 0); /* Q31 c1 = a1*2 */
+ z = mac_r(acc, w, -3547); /* Q15 c0 = a0*2 */
+ acc = L_add(-995054571L, 0); /* Q31 c2 = a2 */
+ z = extract_h(L_mac0(acc, w, z)); /* Q15 non-fractional mode multiply */
+ acc = L_add(61673254L, 0); /* Q31 c3 = a3 */
+ z = mac_r(acc, w, z);
+ acc = L_add(2141982059L, 0); /* Q31 c4 = a4 */
+ z = mac_r(acc, w, z);
+ acc = L_add(115139L, 0); /* Q31 c5 = a5 */
+ acc = L_mac(acc, w, z); /* Q31 */
+ angle = extract_l(L_shr(acc, 31 - 14)); /* Q14 result of atan(x), where 0 <= x < 1 */
+ }
+
+ return angle; /* Q14 between 0 and PI/2 radian. */
+}
+
+
+
diff --git a/lib_com/range_com_fx.c b/lib_com/range_com_fx.c
new file mode 100644
index 0000000000000000000000000000000000000000..4caa38392785060d064bca8ee5f92583e839b6cd
--- /dev/null
+++ b/lib_com/range_com_fx.c
@@ -0,0 +1,68 @@
+/*====================================================================================
+ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
+ ====================================================================================*/
+
+#include
+#include "options.h" /* Compilation switches */
+#include "cnst.h" /* Common constants */
+#include "prot_fx1.h"
+#include "prot_fx2.h" /* Function prototypes */
+
+
+/*-------------------------------------------------------------------*
+ * rc_get_bits2()
+ *
+ * Get number of bits needed to finalize range coder
+ *-------------------------------------------------------------------*/
+
+Word16 rc_get_bits2_fx( /* o: Number of bits needed */
+ const Word16 N, /* i: Number of bits currently used */
+ const UWord32 range /* i: Range of range coder */
+)
+{
+ return add(add(N, 2), norm_ul(range));
+}
+
+/*-------------------------------------------------------------------*
+ * rangeCoderFinalizationFBits()
+ *
+ * Fractional (Q3) bits for range coder finalization
+ *-------------------------------------------------------------------*/
+
+void rangeCoderFinalizationFBits_fx(
+ Word16 Brc, /* i : Current number of decoded bits */
+ UWord32 INTrc, /* i : Range coder state */
+ Word16* FBits /* i : Fractional finalization bits */
+)
+{
+ Word32 L_Bq15;
+ UWord32 h, UL_tmp;
+ UWord16 Bq15ui16, l;
+ Word16 B, E, x, k;
+ *FBits = shl(add(Brc, 32), 3);
+
+ B = sub(30, norm_ul(INTrc));
+ x = sub(B, RCF_INIT_SHIFT );
+ L_Bq15 = 0;
+ move16();
+ if (x >= 0)
+ {
+ L_Bq15 = (Word32)UL_lshr(INTrc, x);
+ }
+
+ E = 2;
+ move16();
+ FOR(k = 1; k < 4; k++)
+ {
+ Bq15ui16 = u_extract_l(L_shr(L_Bq15, s_and(E, 1)));
+ UL_tmp = UL_lshl(UL_deposit_l(Bq15ui16), 1);
+ Mpy_32_16_uu(UL_tmp, Bq15ui16, &h , &l);
+ L_Bq15 = (Word32) h;
+ E = add(shl(B, 1), extract_l(L_lshr(L_sub(((1L << 16) - 1L), L_Bq15), 31)));
+ B = E;
+ move16();
+ }
+ *FBits = sub(*FBits, B);
+ return;
+}
+
diff --git a/lib_com/reordvct_fx.c b/lib_com/reordvct_fx.c
new file mode 100644
index 0000000000000000000000000000000000000000..b5158b9d8ca0eec5372398efc990bd425db2459e
--- /dev/null
+++ b/lib_com/reordvct_fx.c
@@ -0,0 +1,86 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 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.
+
+*******************************************************************************************************/
+
+#include
+#include "options.h" /* Compilation switches */
+#include "prot_fx2.h" /* Function prototypes */
+
+
+ /*--------------------------------------------------------------------------*
+ * reordvct()
+ *
+ * Rearrange a vector in decreasing order
+ *--------------------------------------------------------------------------*/
+
+void reordvct_fx(
+ Word16 *y, /* i/o: vector to rearrange */
+ const Word16 N, /* i : dimensions */
+ Word16 *idx /* o : reordered vector index */
+)
+{
+ Word16 i, j, k, n, im, temp;
+
+ n = sub(N, 1);
+ move16();
+ FOR(i = 0; i < n; i++)
+ {
+ im = i;
+ move16();
+ k = add(i, 1);
+ move16();
+ FOR(j = k; j < N; j++)
+ {
+ if (LT_16(y[im], y[j]))
+ {
+ im = j;
+ move16();
+ }
+ }
+
+ temp = y[i];
+ move16();
+ y[i] = y[im];
+ move16();
+ y[im] = temp;
+ move16();
+ j = idx[i];
+ move16();
+ idx[i] = idx[im];
+ move16();
+ idx[im] = j;
+ move16();
+ }
+
+ return;
+}
+
+
diff --git a/lib_com/residu_fx.c b/lib_com/residu_fx.c
new file mode 100644
index 0000000000000000000000000000000000000000..2c3624a5d88dea59ce90901cfac4df60c933d96e
--- /dev/null
+++ b/lib_com/residu_fx.c
@@ -0,0 +1,215 @@
+/*====================================================================================
+ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
+ ====================================================================================*/
+
+#include
+#include "options.h" /* Compilation switches */
+#include "cnst.h" /* Common constants */
+#include "rom_com.h" /* Static table prototypes */
+#include "prot_fx1.h"
+#include "prot_fx2.h"
+
+/*--------------------------------------------------------------------*
+ * Residu3_lc_fx:
+ *
+ * Compute the LP residual by filtering the input speech through A(z)
+ * Output is in Qx
+ *
+ * Optimized Version: Use when Past[0..m-1] is 0 & a[0] is 1 (in Q12)
+ *--------------------------------------------------------------------*/
+void Residu3_lc_fx(
+ const Word16 a[], /* i : prediction coefficients Q12 */
+ const Word16 m, /* i : order of LP filter Q0 */
+ const Word16 x[], /* i : input signal (usually speech) Qx */
+ Word16 y[], /* o : output signal (usually residual) Qx */
+ const Word16 lg, /* i : vector size Q0 */
+ const Word16 shift
+)
+{
+ Word16 i, j;
+ Word32 s;
+ Word16 q;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+
+ q = add( norm_s(a[0]), 1 );
+ if (shift > 0)
+ {
+ q = add(q, shift);
+ }
+#ifdef BASOP_NOGLOB
+ *y++ = shl_o(x[0], shift, &Overflow);
+#else
+ *y++ = shl(x[0], shift);
+#endif
+ move16();
+
+ FOR (i = 1; i < m; i++)
+ {
+#ifdef BASOP_NOGLOB
+ s = L_mult_o(x[i], a[0], &Overflow);
+#else
+ s = L_mult(x[i], a[0]);
+#endif
+ /* Stop at i to Avoid Mults with Zeros */
+ FOR (j = 1; j <= i; j++)
+ {
+#ifdef BASOP_NOGLOB
+ s = L_mac_o(s, x[i-j], a[j], &Overflow);
+#else
+ s = L_mac(s, x[i-j], a[j]);
+#endif
+ }
+
+#ifdef BASOP_NOGLOB
+ s = L_shl_o(s, q, &Overflow);
+ *y++ = round_fx_o(s, &Overflow);
+#else
+ s = L_shl(s, q);
+ *y++ = round_fx(s);
+#endif
+ }
+
+ FOR (; i < lg; i++)
+ {
+#ifdef BASOP_NOGLOB
+ s = L_mult_o(x[i], a[0], &Overflow);
+#else
+ s = L_mult(x[i], a[0]);
+#endif
+ FOR (j = 1; j <= m; j++)
+ {
+#ifdef BASOP_NOGLOB
+ s = L_mac_o(s, x[i-j], a[j], &Overflow);
+#else
+ s = L_mac(s, x[i-j], a[j]);
+#endif
+ }
+
+#ifdef BASOP_NOGLOB
+ s = L_shl_o(s, q, &Overflow);
+ *y++ = round_fx_o(s, &Overflow);
+#else
+ s = L_shl(s, q);
+ *y++ = round_fx(s);
+#endif
+ }
+}
+
+/*--------------------------------------------------------------------*
+ * Residu3_10_fx:
+ *
+ * Compute the LP residual by filtering the input speech through A(z)
+ * Output is in Qx
+ *--------------------------------------------------------------------*/
+void Residu3_10_fx(
+ const Word16 a[], /* i : prediction coefficients Q12 */
+ const Word16 x[], /* i : input signal (usually speech) Qx */
+ /* (note that values x[-10..-1] are needed) */
+ Word16 y[], /* o : output signal (usually residual) Qx */
+ const Word16 lg, /* i : vector size Q0 */
+ const Word16 shift
+)
+{
+ Word16 i,j;
+ Word32 s;
+ Word64 s64;
+ Word16 q;
+ q = add( norm_s(a[0]), 1 );
+ if (shift != 0)
+ q = add(q, shift);
+ FOR (i = 0; i < lg; i++)
+ {
+ s64 = 0;
+ FOR (j = 0; j <= 10; j++)
+ {
+ s64 = W_mac_16_16(s64, x[i-j], a[j]);
+ }
+ s = W_shl_sat_l(s64, q);
+ y[i] = round_fx(s);
+ }
+}
+/*--------------------------------------------------------------------*
+ * Residu3_fx:
+ *
+ * Compute the LP residual by filtering the input speech through A(z)
+ * Output is in Qx
+ *--------------------------------------------------------------------*/
+void Residu3_fx(
+ const Word16 a[], /* i : prediction coefficients Q12 */
+ const Word16 x[], /* i : input signal (usually speech) Qx */
+ /* (note that values x[-M..-1] are needed) */
+ Word16 y[], /* o : output signal (usually residual) Qx */
+ const Word16 lg, /* i : vector size Q0 */
+ const Word16 shift
+)
+{
+ Word16 i, j;
+ Word64 s64;
+ Word32 s32;
+ Word16 q;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+ q = add( norm_s(a[0]), 1 );
+ if (shift != 0)
+ q = add(q, shift);
+ FOR (i = 0; i < lg; i++)
+ {
+ s64 = 0;
+ FOR (j = 0; j <= 15; j++)
+ {
+ s64 = W_mac_16_16(s64, x[i-j], a[j]);
+ }
+ s64 = W_mac_16_16(s64, x[i-16], a[16]);
+ s32 = W_shl_sat_l(s64, q);
+#ifdef BASOP_NOGLOB
+ y[i] = round_fx_o( s32, &Overflow );
+#else /* BASOP_NOGLOB */
+ y[i] = round_fx( s32 );
+#endif
+ }
+}
+/*==========================================================================*/
+/* FUNCTION : void calc_residu() */
+/*--------------------------------------------------------------------------*/
+/* PURPOSE : Compute the LP residual by filtering the input through */
+/* A(z) in all subframes */
+/*--------------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* Word16 *speech i : weighted speech signal Qx */
+/* Word16 L_frame i : order of LP filter Q0 */
+/* Word16 *p_Aq i : quantized LP filter coefficients Q12 */
+/*--------------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* Word16 *res o : residual signal Qx+1 */
+/*--------------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/*--------------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : */
+/* _ None */
+/*--------------------------------------------------------------------------*/
+/* CALLED FROM : */
+/*==========================================================================*/
+
+void calc_residu_fx(
+ Encoder_State *st, /* i/o: state structure */
+ const Word16 *speech, /* i : weighted speech signal */
+ Word16 *res, /* o : residual signal */
+ const Word16 *p_Aq /* i : quantized LP filter coefficients */
+)
+{
+ Word16 i_subfr;
+
+ FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR )
+ {
+ /* calculate the residual signal */
+ Residu3_fx( p_Aq, &speech[i_subfr], &res[i_subfr], L_SUBFR, 1 );
+
+ /* next subframe */
+ p_Aq += (M+1);
+ }
+ return;
+}
+
diff --git a/lib_com/rom_basic_math.c b/lib_com/rom_basic_math.c
new file mode 100644
index 0000000000000000000000000000000000000000..ac3e9623ef3861a2170245d17787d529215078d4
--- /dev/null
+++ b/lib_com/rom_basic_math.c
@@ -0,0 +1,91 @@
+#include "options.h" /* Compilation switches */
+#include "cnst.h" /* Decoder static structure */
+#include "stl.h"
+
+/* math_op.c */
+const Word32 L_table_isqrt[48] =
+{
+ 2147418112L, 2083389440L, 2024669184L, 1970667520L,
+ 1920794624L, 1874460672L, 1831403520L, 1791098880L,
+ 1753415680L, 1717960704L, 1684602880L, 1653145600L,
+ 1623326720L, 1595080704L, 1568276480L, 1542782976L,
+ 1518469120L, 1495334912L, 1473183744L, 1451950080L,
+ 1431633920L, 1412169728L, 1393491968L, 1375469568L,
+ 1358168064L, 1341521920L, 1325465600L, 1309933568L,
+ 1294991360L, 1280507904L, 1266548736L, 1252982784L,
+ 1239875584L, 1227161600L, 1214775296L, 1202847744L,
+ 1191182336L, 1179910144L, 1168965632L, 1158283264L,
+ 1147863040L, 1137770496L, 1127940096L, 1118306304L,
+ 1108934656L, 1099825152L, 1090912256L, 1082261504L
+};
+
+/* table of table_isqrt[i] - table_isqrt[i+1] */
+const Word16 table_isqrt_diff[48] =
+{
+ 977, 896, 824, 761, 707, 657, 615, 575,
+ 541, 509, 480, 455, 431, 409, 389, 371,
+ 353, 338, 324, 310, 297, 285, 275, 264,
+ 254, 245, 237, 228, 221, 213, 207, 200,
+ 194, 189, 182, 178, 172, 167, 163, 159,
+ 154, 150, 147, 143, 139, 136, 132, 130
+};
+
+const Word16 shift_Isqrt_lc[] = {9,10};
+
+const Word16 table_pow2[32] =
+{
+ 16384, 16743, 17109, 17484, 17867, 18258, 18658, 19066, 19484, 19911,
+ 20347, 20792, 21247, 21713, 22188, 22674, 23170, 23678, 24196, 24726,
+ 25268, 25821, 26386, 26964, 27554, 28158, 28774, 29405, 30048, 30706,
+ 31379, 32066
+};
+
+/* table of table_pow2[i+1] - table_pow2[i] */
+const Word16 table_pow2_diff_x32[32] =
+{
+ 11488, 11712, 12000, 12256, 12512, 12800, 13056, 13376, 13664, 13952,
+ 14240, 14560, 14912, 15200, 15552, 15872, 16256, 16576, 16960, 17344,
+ 17696, 18080, 18496, 18880, 19328, 19712, 20192, 20576, 21056, 21536,
+ 21984, 22432
+};
+
+const Word16 sqrt_table[49] =
+{
+ 16384, 16888, 17378, 17854, 18318, 18770, 19212,
+ 19644, 20066, 20480, 20886, 21283, 21674, 22058,
+ 22435, 22806, 23170, 23530, 23884, 24232, 24576,
+ 24915, 25249, 25580, 25905, 26227, 26545, 26859,
+ 27170, 27477, 27780, 28081, 28378, 28672, 28963,
+ 29251, 29537, 29819, 30099, 30377, 30652, 30924,
+ 31194, 31462, 31727, 31991, 32252, 32511, 32767
+};
+
+/* log2.c */
+const Word32 L_table_Log2_norm_lc[32] =
+{
+ -32768L, 95322112L, 187793408L, 277577728L,
+ 364871680L, 449740800L, 532381696L, 612859904L,
+ 691306496L, 767787008L, 842432512L, 915308544L,
+ 986546176L, 1056210944L, 1124302848L, 1190887424L,
+ 1256095744L, 1319993344L, 1382580224L, 1443921920L,
+ 1504083968L, 1563131904L, 1621000192L, 1677885440L,
+ 1733722112L, 1788510208L, 1842380800L, 1895399424L,
+ 1947435008L, 1998618624L, 2049015808L, 2098626560L
+};
+
+const Word16 table_diff_Log2_norm_lc[32] =
+{
+ 1455, 1411, 1370, 1332, 1295, 1261, 1228, 1197,
+ 1167, 1139, 1112, 1087, 1063, 1039, 1016, 995,
+ 975, 955, 936, 918, 901, 883, 868, 852,
+ 836, 822, 809, 794, 781, 769, 757, 744
+};
+
+const Word16 log2_tab[33]={
+ 0x7800, 0x782D, 0x785A, 0x7884, 0x78AE, 0x78D6, 0x78FE, 0x7924,
+ 0x794A, 0x796E, 0x7992, 0x79B4, 0x79D6, 0x79F8, 0x7A18, 0x7A38,
+ 0x7A57, 0x7A75, 0x7A93, 0x7AB1, 0x7ACD, 0x7AE9, 0x7B05, 0x7B20,
+ 0x7B3B, 0x7B55, 0x7B6F, 0x7B88, 0x7BA1, 0x7BB9, 0x7BD1, 0x7BE9,
+ 0x7C00
+};
+
diff --git a/lib_com/rom_basic_math.h b/lib_com/rom_basic_math.h
new file mode 100644
index 0000000000000000000000000000000000000000..7c7fec415905df24eac4b8fd372d432b62800a9e
--- /dev/null
+++ b/lib_com/rom_basic_math.h
@@ -0,0 +1,26 @@
+#include "options.h" /* Compilation switches */
+#include "cnst.h" /* Decoder static structure */
+#include "stl.h"
+
+
+/* math_op.c */
+extern const Word32 L_table_isqrt[48];
+
+/* table of table_isqrt[i] - table_isqrt[i+1] */
+extern const Word16 table_isqrt_diff[48];
+
+extern const Word16 shift_Isqrt_lc[];
+
+extern const Word16 table_pow2[32];
+
+/* table of table_pow2[i+1] - table_pow2[i] */
+extern const Word16 table_pow2_diff_x32[32];
+
+extern const Word16 sqrt_table[49];
+
+/* log2.c */
+extern const Word32 L_table_Log2_norm_lc[32];
+
+extern const Word16 table_diff_Log2_norm_lc[32];
+
+extern const Word16 log2_tab[33];
diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c
index 903657fe1cd2ffd3a0816d888de0907752fbca37..d22a47a3a67e231e6f2f04bafb96902c15423418 100644
--- a/lib_com/rom_com.c
+++ b/lib_com/rom_com.c
@@ -707,7 +707,24 @@ const float wind_sss[LEN_WIN_SSS] = /* window for subsampling */
0.989767f, 0.992307f, 0.994488f, 0.996307f, 0.997765f, 0.998859f, 0.999589f, 0.999954f,
1.000000f, 0.979530f, 0.918958f, 0.820763f, 0.688967f, 0.528964f, 0.347305f, 0.151428f
};
-
+const Word16 wind_sss_fx[LEN_WIN_SSS] = /*window for subsampling*/
+{
+ 2621, 2627, 2645, 2675, 2717, 2771, 2836, 2914,
+ 3003, 3103, 3216, 3340, 3475, 3621, 3779, 3948,
+ 4127, 4318, 4519, 4730, 4952, 5184, 5426, 5677,
+ 5938, 6209, 6488, 6777, 7074, 7379, 7693, 8015,
+ 8344, 8681, 9025, 9375, 9733, 10097, 10466, 10842,
+ 11223, 11609, 12000, 12395, 12795, 13198, 13605, 14016,
+ 14429, 14845, 15263, 15683, 16105, 16527, 16951, 17376,
+ 17800, 18225, 18649, 19072, 19495, 19916, 20335, 20752,
+ 21166, 21578, 21987, 22392, 22794, 23191, 23585, 23973,
+ 24357, 24735, 25108, 25474, 25835, 26189, 26537, 26877,
+ 27210, 27536, 27853, 28163, 28464, 28757, 29041, 29316,
+ 29582, 29838, 30085, 30322, 30549, 30765, 30972, 31167,
+ 31352, 31526, 31690, 31842, 31983, 32112, 32230, 32337,
+ 32432, 32515, 32586, 32646, 32694, 32730, 32754, 32766,
+ 32767, 32096, 30111, 26894, 22575, 17333, 11380, 4962
+};
/*----------------------------------------------------------------------------------*
* Low-pass FIR filter for low-frequency post-filtering @ 8kHz
* fir1(240,(3900/32000),hanning(241))*5
@@ -915,7 +932,7 @@ const float hamcos_window[L_LP_AMR_WB] =
/* LAGW_STRONG */
-const float lag_window_8k[17] =
+const float lag_window_8k_flt[17] =
{
1.0001f,
0.998890285694f, 0.995568526105f, 0.990056789412f, 0.982391584471f,
@@ -924,7 +941,7 @@ const float lag_window_8k[17] =
0.828908210054f, 0.804427224606f, 0.778937582562f, 0.752582535421f
};
-const float lag_window_12k8[NUM_LAGW_STRENGTHS][17] =
+const float lag_window_12k8_flt[NUM_LAGW_STRENGTHS][17] =
{
/* LAGW_WEAK */
{
@@ -952,7 +969,7 @@ const float lag_window_12k8[NUM_LAGW_STRENGTHS][17] =
}
};
-const float lag_window_16k[NUM_LAGW_STRENGTHS][17] =
+const float lag_window_16k_flt[NUM_LAGW_STRENGTHS][17] =
{
/* LAGW_WEAK */
{
@@ -980,7 +997,7 @@ const float lag_window_16k[NUM_LAGW_STRENGTHS][17] =
}
};
-const float lag_window_25k6[NUM_LAGW_STRENGTHS][17] =
+const float lag_window_25k6_flt[NUM_LAGW_STRENGTHS][17] =
{
/* LAGW_WEAK */
{
@@ -1008,7 +1025,7 @@ const float lag_window_25k6[NUM_LAGW_STRENGTHS][17] =
}
};
-const float lag_window_32k[NUM_LAGW_STRENGTHS][17] =
+const float lag_window_32k_flt[NUM_LAGW_STRENGTHS][17] =
{
/* LAGW_WEAK */
{
@@ -1037,7 +1054,7 @@ const float lag_window_32k[NUM_LAGW_STRENGTHS][17] =
};
/* LAGW_STRONG */
-const float lag_window_48k[17] =
+const float lag_window_48k_flt[17] =
{
1.0001f,
0.999969157962f, 0.999876637555f, 0.999722455899f, 0.999506641521f,
@@ -1046,6 +1063,88 @@ const float lag_window_48k[17] =
0.994801176082f, 0.993973102356f, 0.993084457589f, 0.992135405511f
};
+const Word16 lag_window_8k[2][16] = /* LAGW_STRONG */
+{
+ /* h */ { 32728, 32619, 32438, 32187, 31867, 31480, 31029, 30517, 29946, 29321, 28645, 27923, 27158, 26356, 25521, 24658 },
+ /* l */ { 11904, 17280, 30720, 25856, 24192, 28992, 24384, 7360, 19456, 14720, 22080, 12928, 31040, 27328, 22080, 5184 }
+};
+const Word16 lag_window_12k8[NUM_LAGW_STRENGTHS][2][16] =
+{
+ /* LAGW_WEAK */
+ {
+ /* h */ { 32763, 32758, 32750, 32739, 32725, 32707, 32687, 32663, 32637, 32607, 32574, 32538, 32498, 32456, 32411, 32362 },
+ /* l */ { 4736, 13312, 16896, 15360, 8896, 30464, 14528, 27008, 2496, 6720, 7296, 4480, 31424, 22976, 12160, 32384 }
+},
+/* LAGW_MEDIUM */
+{
+ /* h */ { 32758, 32739, 32707, 32663, 32607, 32538, 32456, 32362, 32257, 32139, 32009, 31867, 31714, 31549, 31374, 31187 },
+ /* l */ { 13312, 15360, 30464, 27008, 6720, 4480, 22976, 32384, 3520, 5888, 11200, 24192, 17472, 29376, 576, 3136 }
+},
+/* LAGW_STRONG */
+{
+ /* h */ { 32750, 32707, 32637, 32538, 32411, 32257, 32075, 31867, 31633, 31374, 31089, 30780, 30449, 30094, 29718, 29321 },
+ /* l */ { 16896, 30464, 2496, 4480, 12160, 3520, 24256, 24192, 20736, 576, 18240, 31488, 128, 16704, 11520, 14720 }
+}
+};
+const Word16 lag_window_16k[NUM_LAGW_STRENGTHS][2][16] =
+{
+ /* LAGW_WEAK */
+ {
+ /* h */ { 32763, 32760, 32755, 32748, 32739, 32728, 32715, 32700, 32682, 32663, 32642, 32619, 32594, 32567, 32538, 32507 },
+ /* l */ { 23360, 22272, 20672, 18304, 15360, 11904, 8000, 3648, 31808, 27008, 22080, 17280, 12608, 8256, 4480, 1344 }
+},
+/* LAGW_MEDIUM */
+{
+ /* h */ { 32760, 32748, 32728, 32700, 32663, 32619, 32567, 32507, 32438, 32362, 32279, 32187, 32088, 31981, 31867, 31746 },
+ /* l */ { 22272, 18304, 11904, 3648, 27008, 17280, 8256, 1344, 30720, 32384, 8256, 25856, 21824, 31360, 24192, 3072 }
+},
+/* LAGW_STRONG */
+{
+ /* h */ { 32755, 32728, 32682, 32619, 32538, 32438, 32322, 32187, 32036, 31867, 31682, 31480, 31263, 31029, 30780, 30517 },
+ /* l */ { 20672, 11904, 31808, 17280, 4480, 30720, 2944, 25856, 8320, 24192, 16896, 28992, 5824, 24384, 31488, 7360 }
+}
+};
+const Word16 lag_window_25k6[NUM_LAGW_STRENGTHS][2][16] =
+{
+ /* LAGW_WEAK */
+ {
+ /* h */ { 32764, 32763, 32761, 32758, 32754, 32750, 32745, 32739, 32732, 32725, 32716, 32707, 32698, 32687, 32676, 32663 },
+ /* l */ { 10752, 4736, 5568, 13312, 28096, 16896, 12672, 15360, 25024, 8896, 32576, 30464, 2624, 14528, 832, 27008 }
+},
+/* LAGW_MEDIUM */
+{
+ /* h */ { 32763, 32758, 32750, 32739, 32725, 32707, 32687, 32663, 32637, 32607, 32574, 32538, 32498, 32456, 32411, 32362 },
+ /* l */ { 4736, 13312, 16896, 15360, 8896, 30464, 14528, 27008, 2496, 6720, 7296, 4480, 31424, 22976, 12160, 32384 }
+},
+/* LAGW_STRONG */
+{
+ /* h */ { 32761, 32750, 32732, 32707, 32676, 32637, 32591, 32538, 32478, 32411, 32337, 32257, 32169, 32075, 31975, 31867 },
+ /* l */ { 5568, 16896, 25024, 30464, 832, 2496, 3328, 4480, 7040, 12160, 21440, 3520, 25728, 24256, 1216, 24192 }
+}
+};
+const Word16 lag_window_32k[NUM_LAGW_STRENGTHS][2][16] =
+{
+ /* LAGW_WEAK */
+ {
+ /* h */ { 32764, 32763, 32762, 32760, 32758, 32755, 32752, 32748, 32744, 32739, 32734, 32728, 32722, 32715, 32707, 32700 },
+ /* l */ { 15424, 23360, 14720, 22272, 13312, 20672, 11328, 18304, 8704, 15360, 5504, 11904, 1792, 8000, 30464, 3648 }
+},
+/* LAGW_MEDIUM */
+{
+ /* h */ { 32763, 32760, 32755, 32748, 32739, 32728, 32715, 32700, 32682, 32663, 32642, 32619, 32594, 32567, 32538, 32507 },
+ /* l */ { 23360, 22272, 20672, 18304, 15360, 11904, 8000, 3648, 31808, 27008, 22080, 17280, 12608, 8256, 4480, 1344 }
+},
+/* LAGW_STRONG */
+{
+ /* h */ { 32762, 32755, 32744, 32728, 32707, 32682, 32653, 32619, 32581, 32538, 32490, 32438, 32382, 32322, 32257, 32187 },
+ /* l */ { 14720, 20672, 8704, 11904, 30464, 31808, 16384, 17280, 2240, 4480, 24704, 30720, 23168, 2944, 3520, 25856 }
+}
+};
+const Word16 lag_window_48k[2][16] = /* LAGW_STRONG */
+{
+ /* h */ { 32763, 32760, 32755, 32748, 32739, 32728, 32715, 32700, 32682, 32663, 32642, 32619, 32594, 32567, 32538, 32507 },
+ /* l */ { 23360, 22272, 20672, 18304, 15360, 11904, 8000, 3648, 31808, 27008, 22080, 17280, 12608, 8256, 4480, 1344 }
+};
/*----------------------------------------------------------------------------------*
* LP analysis - grid of points for evaluating Chebyshev polynomials
@@ -1974,6 +2073,8 @@ const float interpol_isp_amr_wb[NB_SUBFR] = {
0.45f, 0.8f, 0.96f, 1.0f
};
+const Word16 interpol_isp_amr_wb_fx[] = { 14746, 26214, 31457, 32767 };
+
const float interpol_frac_16k[NB_SUBFR16k] = {
0.2f, 0.4f, 0.6f, 0.8f, 1.0f
};
@@ -4298,6 +4399,309 @@ const float fir_6k_7k[31] =
-0.001005f
};
+const Word16 no_lead_fx[][MAX_NO_SCALES * 2] =
+{
+ { 1, 0, 0, 1, 0, 0, }, /* 14 */
+ { 2, 0, 0, 1, 0, 0, }, /* 15 */
+ { 4, 2, 0, 1, 0, 0, }, /* 18 */
+ { 4, 2, 0, 2, 0, 0, }, /* 19 */
+ { 7, 5, 2, 5, 4, 2, }, /* 25 */
+ { 8, 8, 3, 8, 6, 2, }, /* 28 */ /* mode UV WB*/
+ { 4, 2, 0, 1, 0, 0, }, /* 18 */
+ { 4, 0, 0, 2, 1, 0, }, /* 19 */
+ { 9, 8, 8, 2, 2, 1, }, /* 24 */
+ { 8, 5, 2, 5, 2, 1, }, /* 25 */
+ { 18, 16, 8, 5, 5, 1, }, /* 29 */
+ { 24, 21, 10, 8, 8, 2, }, /* 32 */ /* mode UV NB*/
+
+ { 2, 0, 0, 2, 0, 0, }, /* 17 */
+ { 4, 2, 0, 1, 0, 0, }, /* 18 */
+ { 7, 5, 2, 2, 0, 0, }, /* 21 */
+ { 5, 2, 1, 4, 1, 0, }, /* 22 */
+ { 8, 5, 2, 5, 2, 0, }, /* 25 */
+ { 8, 7, 4, 5, 3, 2, },
+ { 8, 8, 4, 6, 5, 2, },
+ { 13, 8, 5, 6, 5, 2, },
+ { 13, 8, 5, 8, 6, 2, },
+ { 13, 8, 5, 11, 8, 2, }, /* 30 */
+ { 24, 21, 8, 9, 8, 2, }, /* 32 */
+ { 23, 18, 8, 13, 11, 3, },
+ { 23, 21, 8, 17, 13, 4, }, /* 34 */
+ { 31, 31, 17, 26, 25, 9, }, /* 37 */ /* mode V WB*/
+ { 2, 0, 0, 2, 2, 0, }, /* 17 */
+ { 4, 2, 0, 1, 0, 0, }, /* 18 */
+ { 7, 5, 2, 2, 2, 0, }, /* 22 */
+ { 8, 7, 2, 2, 2, 0, }, /* 23 */
+ { 11, 8, 2, 2, 2, 0, }, /* 24 */
+ { 13, 13, 9, 2, 2, 0, }, /* 25 */
+ { 13, 11, 7, 5, 2, 0, }, /* 27 */
+ { 18, 14, 9, 5, 5, 2, }, /* 29 */
+ { 31, 31, 14, 11, 11, 5, }, /* 34 */
+ { 31, 31, 27, 24, 21, 14, }, /* 37 */ /* mode V NB */
+ { 5, 4, 0, 0, 0, 0, }, /* 12 (11.883) */
+ { 2, 0, 0, 2, 0, 0, }, /* 16 (15.826) */
+ { 4, 2, 0, 2, 0, 0, }, /* 19 (18.572) */
+ { 5, 4, 0, 2, 0, 0, }, /* 20 (19.796) */
+ { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */
+ { 8, 7, 2, 2, 0, 0, }, /* 22 (21.776) */
+ { 5, 5, 2, 4, 2, 0, }, /* 23 (22.959) */
+ { 8, 8, 5, 4, 2, 0, }, /* 25 (24.992) */
+ { 8, 8, 7, 5, 2, 0, }, /* 26 (25.904) */
+ { 13, 9, 8, 5, 2, 0, }, /* 27 (26.829) */
+ { 13, 11, 8, 5, 5, 1, }, /* 28 (27.989) */
+ { 13, 9, 8, 8, 5, 2, }, /* 29 (28.984) */
+ { 22, 16, 10, 6, 5, 2, }, /* 30 (29.980) */
+ { 21, 14, 10, 8, 7, 2, }, /* 31 (30.966) */
+ { 24, 21, 10, 8, 8, 2, }, /* 32 (31.995) */ /* G WB*/
+
+ { 5, 4, 1, 0, 0, 0, }, /* 12 (11.925) */
+ { 2, 0, 0, 2, 0, 0, }, /* 16 (15.826) */
+ { 5, 4, 1, 1, 0, 0, }, /* 19 (18.745) */
+ { 5, 4, 1, 2, 0, 0, }, /* 20 (19.838) */
+ { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */
+ { 8, 5, 2, 2, 1, 0, }, /* 22 (21.985) */
+ { 9, 8, 5, 2, 1, 0, }, /* 23 (22.815) */
+ { 14, 13, 8, 2, 2, 0, }, /* 25 (24.996) */
+ { 13, 8, 7, 4, 2, 0, }, /* 26 (25.993) */
+ { 13, 9, 8, 5, 2, 2, }, /* 27 (26.954) */
+ { 18, 13, 8, 5, 2, 2, }, /* 28 (27.992) */
+ { 21, 13, 11, 5, 3, 2, }, /* 29 (28.996) */
+ { 22, 21, 13, 5, 5, 2, }, /* 30 (29.988) */
+ { 23, 21, 17, 7, 5, 2, }, /* 31 (30.962) */
+ { 27, 23, 21, 8, 5, 2, }, /* 32 (31.987) */ /* G NB*/
+ { 2, 0, 0, 2, 0, 0, }, /* 17 */
+ { 4, 2, 0, 1, 0, 0, }, /* 18 */
+ { 4, 1, 0, 4, 0, 0, }, /* 21 */
+ { 5, 2, 0, 4, 1, 0, }, /* 22 */
+ { 8, 5, 2, 4, 0, 0, }, /* 24 */
+ { 8, 5, 2, 5, 2, 0, }, /* 25 */
+ { 14, 10, 5, 5, 5, 1, }, /* 28 */
+ { 14, 10, 5, 8, 8, 4, }, /* 30 */
+ { 13, 10, 5, 13, 8, 8, },
+ { 23, 21, 8, 8, 8, 4, },
+ { 23, 18, 5, 13, 8, 8, }, /* 33 */
+ /* mode T WB */
+ { 2, 0, 0, 2, 2, 0, }, /* 17 */
+ { 4, 2, 0, 1, 0, 0, }, /* 18 */
+ { 7, 5, 2, 2, 2, 0, }, /* 22 */
+ { 8, 7, 4, 2, 2, 0, }, /* 23 */
+ { 11, 8, 5, 2, 2, 0, }, /* 24 */
+ { 18, 8, 5, 2, 2, 0, }, /* 25 */
+ { 16, 8, 5, 5, 5, 2, }, /* 28 */
+ { 28, 23, 8, 5, 5, 5, }, /* 31 */
+ { 31, 31, 8, 5, 5, 7, }, /* 32 */ /* mode T NB */
+
+ { 18, 18, 11, 9, 6, 5, }, /* 31 */
+ { 24, 23, 13, 9, 6, 5, }, /* 32 */ /* mode G 16k */
+
+ { 24, 23, 13, 9, 6, 5, }, /* 32 (31.998) */
+ { 36, 31, 18, 9, 6, 5, }, /* 33 (32.983) */ /* T 16k */
+
+ { 2, 0, 0, 2, 2, 0, }, /* 17 */
+ { 7, 5, 2, 2, 0, 0, }, /* 21 */
+ { 7, 5, 2, 2, 2, 0, }, /* 22 */
+ { 9, 8, 3, 4, 2, 0, }, /* 25 */
+ { 11, 9, 8, 4, 2, 0, }, /* 26 */
+ { 48, 48, 34, 13, 11, 9 }, /* 36 */ /* mode AUDIO_WB 36 + 4 + 1 */
+
+ { 22, 10, 3, 0, 0, 0 }, /* 17 */
+ { 6, 6, 2, 2, 0, 0 }, /* 21 */
+ { 6, 6, 2, 2, 2, 0 }, /* 22 */
+ { 23, 10, 3, 2, 2, 0 }, /* 26 */
+ { 32, 16, 3, 2, 2, 0 }, /* 27 */ /* AUDIO_NB */
+ { 39, 30, 12, 2, 2, 0 }, /* 28 */ /* AUDIO_NB */
+ { 11, 9, 8, 4, 2, 0, }, /* 26 */
+ { 48, 48, 48, 13, 9, 8 }, /* 36 */ /* mode AUDIO_WB 16k 15-36 + 4 + 1*/
+ { 8, 7, 2, 2, 0, 0, }, /* 22 (21.776) */
+ { 13, 13, 5, 5, 5, 0, }, /* 28 (27.994) */
+ { 18, 17, 5, 5, 5, 1, }, /* 29 (28.996) */
+ { 17, 13, 5, 8, 6, 2, }, /* 30 (29.991) */
+ { 23, 21, 8, 9, 8, 3, }, /* 32 (31.992) */
+ { 31, 29, 16, 8, 8, 3, }, /* 33 (32.993) */
+ { 31, 25, 16, 12, 8, 8, }, /* 34 (33.968) */
+ { 46, 48, 18, 18, 18, 12, }, /* 37 (36.995) */ /* VOICED 16k */
+ { 14, 12, 9, 2, 2, 0, }, /* 25 (24.980) */
+ { 15, 13, 3, 2, 2, 0, }, /* 25 (24.974) */
+ { 17, 3, 0, 2, 2, 1, }, /* 25 (24.852) */
+ { 13, 10, 3, 2, 2, 2, }, /* 25 (24.994) */
+ { 14, 13, 8, 2, 2, 0, }, /* 25 (24.996) */
+ { 7, 3, 0, 5, 3, 1, }, /* 25 (24.671) */
+ { 4, 3, 2, 6, 6, 5, }, /* 25 (24.936) */
+ { 4, 2, 0, 9, 9, 3, }, /* 25 (24.955) */
+ { 4, 2, 0, 9, 8, 2, }, /* 25 (24.853) */
+ { 4, 2, 0, 9, 7, 6, }, /* 25 (24.881) */
+ { 6, 3, 0, 6, 3, 2, }, /* 25 (24.939) */
+ { 3, 2, 0, 9, 8, 5, }, /* 25 (24.996) */
+ { 2, 2, 0, 15, 3, 3, }, /* 25 (24.310) */
+ { 4, 2, 0, 9, 9, 3, }, /* 25 (24.955) */
+ { 4, 4, 2, 7, 6, 3, }, /* 25 (24.984) */
+ { 3, 2, 0, 9, 7, 6, }, /* 25 (24.866) */
+
+};
+
+const Word16 no_lead_p_fx[][MAX_NO_SCALES * 2] =
+{
+
+ { 2, 1, 0, 0, 0, 0, }, /* 9 (8.464) */
+ { 4, 2, 0, 2, 0, 0, }, /* 19 (18.572) */
+ { 5, 5, 2, 4, 2, 0, }, /* 23 (22.959) */
+ { 8, 5, 2, 4, 0, 0, }, /* 24 (23.949) */
+ { 8, 8, 5, 4, 2, 0, }, /* 25 (24.992) */
+ { 13, 11, 5, 5, 2, 0, }, /* 27 (26.902) */
+ { 11, 10, 5, 6, 5, 2, }, /* 28 (27.996) */
+ { 14, 13, 5, 7, 5, 2, }, /* 29 (28.937) */
+ { 16, 13, 5, 8, 7, 2, }, /* 30 (29.954) */
+ { 21, 21, 5, 8, 5, 2, }, /* 31 (30.978) */
+ { 24, 21, 5, 8, 8, 4, }, /* 32 (31.978) */
+ { 32, 23, 5, 13, 11, 5, }, /* 34 (33.975) */
+ { 36, 31, 8, 16, 13, 5, }, /* 35 (34.975) */
+ { 45, 35, 16, 18, 13, 5, }, /* 36 (35.889) */
+ { 45, 35, 16, 38, 31, 8, }, /* 39 (38.488) */ /* V WB*/ /* 14 */
+
+ { 2, 0, 0, 0, 0, 0, }, /* 8 (7.913) */
+ { 4, 2, 0, 2, 0, 0, }, /* 19 (18.572) */
+ { 8, 7, 2, 2, 2, 0, }, /* 23 (22.773) */
+ { 13, 11, 5, 2, 1, 0, }, /* 24 (23.999) */
+ { 8, 8, 5, 4, 2, 0, }, /* 25 (24.992) */
+ { 13, 11, 5, 5, 2, 1, }, /* 27 (26.962) */
+ { 13, 11, 5, 5, 5, 2, }, /* 28 (27.835) */
+ { 14, 13, 5, 7, 5, 2, }, /* 29 (28.937) */
+ { 23, 21, 5, 5, 5, 2, }, /* 30 (29.969) */
+ { 23, 18, 5, 8, 5, 2, }, /* 31 (30.952) */
+ { 24, 21, 5, 8, 8, 4, }, /* 32 (31.978) */
+ { 43, 41, 13, 9, 8, 5, }, /* 34 (33.992) */
+ { 43, 36, 13, 13, 10, 5, }, /* 35 (35.000) */
+ { 43, 40, 13, 17, 13, 9, }, /* 36 (35.980) */
+ { 43, 42, 13, 31, 30, 18, }, /* 39 (38.512) */ /* V NB*/ /* 29 */
+
+ { 2, 0, 0, 1, 0, 0, }, /* 15 (14.733) */
+ { 5, 4, 1, 1, 0, 0, }, /* 19 (18.745) */
+ { 8, 7, 2, 2, 0, 0, }, /* 22 (21.776) */
+ { 10, 9, 5, 2, 0, 0, }, /* 23 (22.791) */
+ { 14, 13, 8, 2, 0, 0, }, /* 24 (23.999) */
+ { 14, 13, 8, 2, 2, 0, }, /* 25 (24.996) */
+ { 18, 17, 13, 2, 2, 0, }, /* 26 (25.934) */
+ { 14, 13, 8, 5, 4, 0, }, /* 28 (27.969) */
+ { 18, 17, 13, 5, 4, 2, }, /* 29 (28.996) */
+ { 22, 21, 13, 5, 5, 2, }, /* 30 (29.988) */
+ { 31, 23, 21, 5, 5, 2, }, /* 31 (30.931) */
+ { 27, 23, 21, 8, 5, 2, }, /* 32 (31.987) */
+ { 31, 23, 21, 9, 8, 5, }, /* 33 (32.982) */
+ { 32, 31, 24, 11, 8, 5, }, /* 34 (33.967) */
+ { 32, 32, 28, 13, 11, 8, }, /* 35 (34.994) */ /* G WB*/ /* 44 */
+
+ { 2, 0, 0, 1, 0, 0, }, /* 15 (14.733) */
+ { 5, 4, 2, 1, 0, 0, }, /* 19 (18.792) */
+ { 8, 5, 2, 2, 1, 0, }, /* 22 (21.985) */
+ { 8, 7, 2, 2, 2, 0, }, /* 23 (22.773) */
+ { 13, 11, 2, 2, 1, 0, }, /* 24 (23.932) */
+ { 16, 13, 2, 2, 2, 0, }, /* 25 (24.955) */
+ { 21, 17, 2, 2, 2, 0, }, /* 26 (25.991) */
+ { 13, 12, 2, 5, 5, 2, }, /* 28 (27.979) */
+ { 18, 16, 2, 5, 5, 2, }, /* 29 (28.878) */
+ { 23, 21, 2, 5, 5, 2, }, /* 30 (29.954) */
+ { 32, 28, 2, 5, 5, 2, }, /* 31 (30.893) */
+ { 38, 31, 2, 7, 5, 2, }, /* 32 (31.963) */
+ { 33, 31, 2, 8, 8, 4, }, /* 33 (32.997) */
+ { 42, 31, 2, 9, 9, 8, }, /* 34 (33.986) */
+ { 42, 31, 2, 13, 11, 9, }, /* 35 (34.952) */ /* G NB*/ /* 59 */
+
+ { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */
+ { 8, 8, 5, 4, 2, 0, }, /* 25 (24.992) */
+ { 13, 8, 5, 4, 2, 0, }, /* 26 */
+ { 13, 8, 5, 8, 6, 2, }, /* 29 */
+ { 13, 8, 5, 9, 8, 5, }, /* 30 */
+ { 48, 48, 48, 36, 36, 28 }, /* 40 */ /* mode 7 AUDIO_WB */ /* 65*/
+
+ { 7, 5, 2, 2, 0, 0 }, /* 21 */
+ { 13, 13, 9, 2, 2, 0 }, /* 25 */
+ { 18, 18, 9, 2, 2, 0 }, /* 26 */
+ { 24, 23, 10, 5, 4, 2 }, /* 30 */
+ { 31, 31, 12, 5, 5, 2 }, /* 31 */ /*AUDIO_NB */ /* 70 */
+ { 43, 34, 12, 5, 5, 4 }, /* 32 */ /*AUDIO_NB */ /* 71 */
+ { 13, 8, 5, 9, 8, 5, }, /* 30 */
+ { 48, 48, 45, 45, 31, 25 }, /* 40 */ /* mode AUDIO_WB 16k */ /* 73*/
+
+ { 2, 0, 0, 2, 2, 0, }, /* 17 (16.823) */
+ { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */
+ { 7, 5, 2, 2, 2, 0, }, /* 22 (21.907) */
+ { 13, 11, 10, 2, 2, 0, }, /* 25 (24.863) */
+ { 18, 18, 10, 2, 2, 0, }, /* 26 (25.921) */
+ { 13, 9, 9, 5, 2, 0, }, /* 27 (26.837) */
+ { 40, 28, 25, 18, 17, 2, }, /* 36 (35.998) */ /* INACTIVE NB*/ /* 80*/
+
+ { 18, 17, 11, 0, 0, 0, }, /* 17 (16.932) */
+ { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */
+ { 8, 5, 2, 2, 1, 0, }, /* 22 (21.985) */
+ { 13, 13, 9, 2, 2, 0, }, /* 25 (24.845) */
+ { 18, 18, 12, 2, 2, 0, }, /* 26 (25.999) */
+ { 23, 23, 16, 2, 2, 0, }, /* 27 (26.981) */
+ { 36, 32, 24, 17, 13, 13, }, /* 36 (35.929) */ /* INACTIVE WB */ /* 87 */
+
+ { 2, 2, 0, 2, 0, 0, }, /* 17 (16.823) */
+ { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */
+ { 8, 5, 2, 2, 1, 0, }, /* 22 (21.985) */
+ { 13, 13, 9, 2, 2, 0, }, /* 25 (24.845) */
+ { 18, 17, 13, 2, 2, 0, }, /* 26 (25.934) */
+ { 23, 22, 17, 2, 2, 0, }, /* 27 (26.914) */
+ { 34, 32, 24, 16, 16, 13, }, /* 36 (35.915) */ /* INACTIVE WB 16k*/ /* 94 */
+
+ { 4, 2, 0, 1, 0, 0, }, /* 18 (17.479) */
+ { 5, 4, 0, 1, 0, 0, }, /* 19 (18.703) */
+ { 8, 7, 2, 2, 0, 0, }, /* 22 (21.776) */
+ { 10, 9, 5, 2, 0, 0, }, /* 23 (22.791) */
+ { 15, 13, 5, 2, 0, 0, }, /* 24 (23.999) */
+ { 18, 16, 8, 5, 5, 1, }, /* 29 (28.966) */
+ { 42, 32, 31, 5, 5, 2, }, /* 32 (31.990) */ /* UNVOICED NB*/ /* 100 */
+
+ { 1, 0, 0, 1, 0, 0, }, /* 14 (13.640) */
+ { 2, 0, 0, 1, 0, 0, }, /* 15 (14.733) */
+ { 4, 2, 0, 1, 0, 0, }, /* 18 (17.479) */
+ { 4, 2, 0, 2, 0, 0, }, /* 19 (18.572) */
+ { 5, 4, 0, 2, 0, 0, }, /* 20 (19.796) */
+ { 8, 8, 5, 4, 2, 0, }, /* 25 (24.992) */
+ { 11, 10, 5, 6, 5, 2, }, /* 28 (27.996) */ /* UNVOICED WB */ /* 106 */
+ { 9, 3, 0, 4, 0, 0, }, /* 24 (23.818) */
+ { 18, 13, 10, 8, 3, 0, }, /* 30 (29.992) */
+ { 24, 18, 10, 9, 3, 0, }, /* 31 (30.998) */
+ { 32, 25, 10, 9, 3, 0, }, /* 32 (31.987) */
+ { 42, 31, 10, 12, 3, 2, }, /* 34 (33.994) */
+ { 44, 32, 27, 15, 3, 2, }, /* 35 (35.000) */
+ { 44, 32, 25, 19, 3, 2, }, /* 36 (35.994) */
+ { 48, 39, 32, 35, 15, 3, }, /* 39 (38.301) */ /* VOICED 16k */
+ { 11, 10, 5, 4, 2, 0, }, /* 26 (25.917) */ /* 107 */
+ { 23, 23, 17, 8, 7, 2, }, /* 32 (31.980) */
+ { 32, 31, 18, 9, 7, 5, }, /* 33 (32.990) */
+ { 31, 31, 18, 11, 9, 8, }, /* 34 (33.974) */
+ { 32, 32, 20, 13, 12, 8, }, /* 35 (34.989) */
+ { 32, 32, 23, 18, 17, 8, }, /* 36 (35.988) */
+ { 32, 32, 23, 23, 22, 10, }, /* 37 (36.989) */ /* GENERIC 16k*/ /* 113 */
+
+ { 2, 0, 0, 2, 0, 0, }, /* 16 (15.826) */ /* 114 */
+ { 7, 5, 2, 2, 0, 0, }, /* 21 (20.910) */
+ { 14, 13, 8, 2, 0, 0, }, /* 24 (23.999) */
+ { 8, 8, 5, 4, 2, 0, }, /* 25 (24.992) */
+ { 11, 10, 5, 4, 2, 0, }, /* 26 (25.917) */
+ { 16, 13, 8, 4, 2, 0, }, /* 27 (26.883) */
+ { 13, 13, 8, 5, 4, 2, }, /* 28 (27.901) */
+ { 23, 18, 13, 5, 5, 2, }, /* 30 (29.916) */
+ { 23, 23, 13, 7, 5, 2, }, /* 31 (30.993) */
+ { 23, 23, 17, 8, 7, 2, }, /* 32 (31.980) */
+ { 32, 31, 24, 8, 7, 2, }, /* 33 (32.958) */
+ { 42, 32, 31, 9, 9, 4, }, /* 34 (33.987) */
+ { 40, 32, 29, 12, 9, 9, }, /* 35 (34.994) */
+ { 40, 32, 31, 17, 11, 11, }, /* 36 (35.968) */
+ { 41, 32, 31, 20, 18, 13, }, /* 37 (36.971) */ /* GENERIC 12.8k MA*/ /* 128 */
+
+ { 11, 10, 5, 4, 2, 0, }, /* 26 (25.917) */ /* 129 */
+ { 23, 23, 17, 8, 7, 2, }, /* 32 (31.980) */
+ { 31, 31, 18, 9, 8, 2, }, /* 33 (32.995) */
+ { 48, 32, 24, 9, 8, 3, }, /* 34 (33.993) */
+ { 48, 32, 28, 11, 10, 3, }, /* 35 (34.992) */
+ { 48, 37, 32, 16, 12, 4, }, /* 36 (35.997) */
+ { 48, 37, 32, 18, 17, 12, }, /* 37 (36.961) */ /* AUDIO 16k */
+};
+
/*----------------------------------------------------------------------------------*
* Enhacer - 2.0 - 6.4 kHz impulse response with phase dispersion in freq. domain
*----------------------------------------------------------------------------------*/
@@ -4918,6 +5322,12 @@ const float mean_isf_amr_wb[M] =
1576.906494f
};
+const Word16 mean_isf_amr_wb_fx[M] =
+{
+ 738, 1326, 2336, 3578, 4596, 5662, 6711, 7730,
+ 8750, 9753,10705, 11728, 12833, 13971,15043, 4037
+};
+
/*----------------------------------------------------------------------------------*
* Mean ISF vector for SID frames (only in AMR-WB IO mode)
*----------------------------------------------------------------------------------*/
@@ -4942,6 +5352,53 @@ const float mean_isf_noise_amr_wb[M] =
1485.457031f
};
+const Word16 mean_isf_noise_amr_wb_fx[M] =
+{
+ 478, 1100, 2213, 3267, 4219, 5222, 6198, 7240,
+ 8229, 9153,10098, 11108, 12144, 13184,14165, 3803
+};
+
+/* ISF codebook - common 1st stage, 1st split (only in AMR-WB IO mode) */
+/*------------------------------------------------------*
+ * Indirection for 1st stage 1st split of 46 bit cb. :
+ The transmitted_index = indirect_dico1[found_index];
+ *------------------------------------------------------*/
+const Word16 Indirect_dico1[SIZE_BK1] =
+{
+ 2, 6, 18, 22, 34, 35, 38, 50,
+ 66, 67, 70, 82, 98, 99, 102, 130,
+ 131, 134, 146, 150, 162, 178, 194, 198,
+ 210, 226, 230, 242, 0, 1, 3, 4,
+ 5, 7, 8, 9, 10, 11, 12, 13,
+ 14, 15, 16, 17, 19, 20, 21, 23,
+ 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 36, 37, 39, 40, 41, 42,
+ 43, 44, 45, 46, 47, 48, 49, 51,
+ 52, 53, 54, 55, 56, 57, 58, 59,
+ 60, 61, 62, 63, 64, 65, 68, 69,
+ 71, 72, 73, 74, 75, 76, 77, 78,
+ 79, 80, 81, 83, 84, 85, 86, 87,
+ 88, 89, 90, 91, 92, 93, 94, 95,
+ 96, 97, 100, 101, 103, 104, 105, 106,
+ 107, 108, 109, 110, 111, 112, 113, 114,
+ 115, 116, 117, 118, 119, 120, 121, 122,
+ 123, 124, 125, 126, 127, 128, 129, 132,
+ 133, 135, 136, 137, 138, 139, 140, 141,
+ 142, 143, 144, 145, 147, 148, 149, 151,
+ 152, 153, 154, 155, 156, 157, 158, 159,
+ 160, 161, 163, 164, 165, 166, 167, 168,
+ 169, 170, 171, 172, 173, 174, 175, 176,
+ 177, 179, 180, 181, 182, 183, 184, 185,
+ 186, 187, 188, 189, 190, 191, 192, 193,
+ 195, 196, 197, 199, 200, 201, 202, 203,
+ 204, 205, 206, 207, 208, 209, 211, 212,
+ 213, 214, 215, 216, 217, 218, 219, 220,
+ 221, 222, 223, 224, 225, 227, 228, 229,
+ 231, 232, 233, 234, 235, 236, 237, 238,
+ 239, 240, 241, 243, 244, 245, 246, 247,
+ 248, 249, 250, 251, 252, 253, 254, 255
+};
+
/*----------------------------------------------------------------------------------*
* Initial LSF memory
*----------------------------------------------------------------------------------*/
@@ -4992,6 +5449,34 @@ const float gaus_dico[190] =
-0.0106f, -0.0540f, 0.1642f, -0.0598f, -0.0065f, 0.1146f,
0.0863f, 0.0129f, 0.1816f, 0.0672f
};
+/*table in Q12*/
+const Word16 gaus_dico_fx[190] =
+{
+ -399, -125, 523, -466, 305, -658, -809, 47,
+ -141, -171, -583, -259, 296, 1334, -285, -401,
+ -478, -418, 140, -540, 177, -1089, 130, -292,
+ 143, 492, -310, -862, -320, 388, 546, 84,
+ -1202, 107, 108, 340, 239, -130, 930, 342,
+ 153, -264, -763, -113, 387, -535, 83, -856,
+ -361, -421, 120, 396, -367, 640, 817, 222,
+ -1017, -82, -120, 890, 340, -384, 47, 339,
+ -505, -430, 161, 979, 890, -267, 104, 508,
+ -150, -194, 442, 193, 413, -24, 395, -43,
+ -217, 69, -398, 167, 116, -936, -95, 1466,
+ -435, 461, 862, -136, -94, 1311, -371, 68,
+ 134, -296, -156, -564, -48, -487, 647, 315,
+ 513, -101, -685, -318, -344, -644, -66, 851,
+ 414, -29, 509, 414, 502, 399, 557, 649,
+ -299, 750, 546, -756, -12, -365, 593, -707,
+ 394, -131, -375, -62, -914, -256, -424, 64,
+ 464, -1140, 280, 91, -83, -288, -550, 389,
+ 52, -1228, 6, -430, 74, 205, -478, -148,
+ -592, 282, -73, 1212, 42, 580, -334, 484,
+ -765, 443, 649, 271, -739, 375, 613, -460,
+ -208, 235, -120, -49, -311, 605, 875, 521,
+ 202, -506, -548, -1088, -43, -221, 673, -245,
+ -27, 469, 353, 53, 744, 275
+};
const float gaus_dico_swb[256] =
{
@@ -5028,6 +5513,43 @@ const float gaus_dico_swb[256] =
0.02153429f, 0.22880882f, -0.13646534f, 0.03881640f, -0.02896636f, 0.09774253f, -0.13509314f, -0.08713179f,
0.13485038f, 0.06968338f, 0.19561967f, 0.07884958f, -0.10365590f, -0.10321335f, -0.09081125f, -0.00147976f
};
+const Word16 gaus_dico_swb_fx[256] =
+{
+ /*Q15 */
+ 709, 11759, -5333, -2701, 2397, -18, -4286, 2368,
+ -4576, -1584, -900, -940, 3676, 5441, -44, 2234,
+ -5698, 3082, -2671, 1666, -640, -3343, -1005, -1689,
+ 2048, 281, -3935, -3723, 5628, 385, -746, -3243,
+ -3332, -7228, -1748, -206, -5474, 2554, 2861, 3168,
+ 5039, 588, -508, -8167, 6549, -3433, 2187, -3666,
+ -5874, 2767, 8370, 1038, 6434, 6279, 625, 4030,
+ -1031, 1823, 9896, -1395, 2712, -1110, -742, 6142,
+ -4456, -10487, -144, -5104, 1968, -312, 6176, 2173,
+ 2334, -240, 2712, 7460, 2219, -3116, -56, 2770,
+ 5577, -1225, 770, 3557, 2246, 2322, 3077, 41,
+ 992, -4971, 441, -5039, 4913, 3811, 1142, -1283,
+ -6578, 4171, -1473, -3793, -5008, 1984, -1138, -1185,
+ 5646, 1014, -5118, 7141, 2656, -7241, -3538, 2337,
+ 7239, -504, -943, -10129, 702, -3811, -302, 2435,
+ 5090, 3744, 2335, -3904, -1401, -1662, -7256, 6484,
+ -6864, -5428, 1954, -7316, -1420, -1542, 5442, 311,
+ 3698, -1343, -2974, 8756, 324, -1903, 2580, 2635,
+ 4236, -1851, 3147, -772, -708, -3830, 2601, -1889,
+ -3444, -762, 3939, 3206, -7406, -837, -1167, -438,
+ 3707, -1015, -7472, 1849, 4277, 1459, -3047, -3760,
+ 740, -7134, -3753, -3092, 209, -12121, 1398, 2266,
+ 2505, -7974, -1121, -3481, -5644, 1329, 4532, 958,
+ 5311, -4258, -3195, -1769, -3055, 4399, -15, 10182,
+ 4503, 1912, -1574, 5054, -3163, 4881, -5364, 1925,
+ -1205, -6432, 2305, -8917, -1422, 514, -3001, 3928,
+ 2321, 360, -355, 1477, -3492, -4570, 1913, 2772,
+ -1380, -5161, 3812, 2614, 2204, -3135, 1244, -3066,
+ -4446, -6389, 4899, -5250, 1372, 1999, 1122, 5312,
+ 1310, -1189, -3310, 6403, 3818, 7734, 1620, -8533,
+ 706, 7498, -4472, 1272, -949, 3203, -4427, -2855,
+ 4419, 2283, 6410, 2584, -3397, -3382, -2976, -48,
+};
+
/*----------------------------------------------------------------------------------*
* CLDFB tables
@@ -7805,6 +8327,7 @@ const float olapWinSyn320[320] =
};
+
/*-------------------------------------------------------------------*
* AMR-WB ISF codebook - common 1st stage for 46bit and 36bit codebooks,
* 2 splits
@@ -8079,6 +8602,294 @@ const float dico1_isf[] =
-25.8195f, -90.5090f, -174.4579f, -208.3670f, -308.3139f, -74.5783f, -38.9631f, -104.3672f, 142.1591f
};
+const Word16 dico1_isf_fx[] =
+{
+ 740, 1263, 1292, 1006, 997, 1019, 1017, 976, 923,
+ 557, 946, 1049, 867, 846, 990, 1112, 1262, 1241,
+ 633, 898, 996, 756, 662, 683, 783, 909, 996,
+ 830, 736, 278, 820, 1254, 686, 712, 1039, 473,
+ 503, 885, 1508, 1307, 1282, 1172, 1119, 1209, 1061,
+ 416, 719, 989, 1227, 1001, 1052, 954, 741, 1044,
+ 585, 1132, 1233, 1091, 1247, 1433, 1512, 1448, 1314,
+ -31, 469, 803, 659, 619, 658, 843, 987, 1113,
+ 842, 1678, 1841, 1549, 1474, 1256, 1082, 905, 742,
+ 370, 1216, 1768, 1633, 1212, 636, 22, -330, 71,
+ 73, 738, 893, 968, 993, 1768, 2273, 1840, 1391,
+ 1513, 1714, 1238, 534, 276, 315, 461, 459, 508,
+ 421, 1293, 1640, 1623, 1742, 1617, 1499, 1284, 1006,
+ -95, 752, 1680, 1569, 1618, 1436, 1200, 980, 712,
+ -78, 831, 1194, 1110, 1378, 1481, 1492, 1365, 1217,
+ 670, 1208, 1168, 860, 742, 601, 528, 403, 309,
+ 397, 621, 966, 752, 579, 398, 400, 329, 252,
+ 510, 864, 1108, 807, 939, 902, 925, 717, 481,
+ 539, 835, 913, 719, 617, 544, 591, 565, 642,
+ 162, 889, 654, 108, -34, 244, 488, 561, 532,
+ -62, 1033, 1308, 1035, 1127, 1098, 1029, 961, 823,
+ -14, 945, 990, 801, 755, 815, 847, 913, 892,
+ 394, 1765, 1666, 1339, 1117, 806, 642, 479, 380,
+ 529, 1851, 2003, 1228, 622, -41, -416, 344, 819,
+ 635, 1058, 883, 492, 372, 312, 317, 274, 241,
+ 279, 966, 1642, 1478, 1463, 1123, 795, 525, 339,
+ 457, 955, 1177, 1214, 1427, 1457, 1345, 917, 539,
+ 148, 751, 1515, 1105, 867, 606, 474, 448, 399,
+ 579, 1081, 1035, 390, 3, -263, -198, -82, 38,
+ 18, -68, -12, 313, 761, 405, 249, 111, -76,
+ -91, 827, 948, 648, 613, 535, 522, 490, 421,
+ 41, -44, -281, -472, 652, 534, 193, 135, -90,
+ 41, -121, -356, -60, 663, 307, 61, -48, -344,
+ -118, -204, 328, 512, 870, 793, 610, 402, 186,
+ 156, 293, 74, -338, -475, -897, -594, -161, -497,
+ 226, 131, -138, 307, 169, -271, -164, -387, -624,
+ 62, -32, -61, -252, -541, -828, -1027, -523, -662,
+ 102, -61, 141, 112, -270, -251, -541, 25, -150,
+ 6, -132, -356, -686, -96, -322, -522, -31, -326,
+ -36, -209, -521, -229, 307, -132, -5, -99, -384,
+ 60, -51, -237, -668, -973, -407, -708, -75, -172,
+ 26, -138, -266, 111, -302, 43, -278, -356, -359,
+ 570, 822, 496, -154, -312, -92, 137, 279, 371,
+ -146, 368, 409, 68, 6, 77, 167, 202, 162,
+ -103, 294, 607, 415, 483, 462, 480, 431, 408,
+ -120, -338, -612, -524, 584, 331, 92, 433, 276,
+ -178, -293, -154, -41, 269, 100, -9, 213, 160,
+ -218, -304, 463, 454, 397, 273, 202, 286, 273,
+ -232, 7, 6, -388, -472, -427, -378, -167, -100,
+ -294, -183, 134, -47, 101, -88, -84, -117, -3,
+ 57, 17, -202, -634, -989, -1119, -533, 176, -36,
+ 120, -28, 23, 111, -319, 318, -22, -77, 266,
+ -271, -464, -434, -658, -640, -385, -385, -99, -69,
+ -198, -259, -266, -44, -39, -139, -137, 171, 66,
+ 9, -145, -377, -846, -1000, -111, -325, 342, 135,
+ -81, -286, -380, 192, -57, 307, 76, -24, -140,
+ 677, 702, 247, 56, 249, 141, -105, -236, -99,
+ 36, -39, -69, 348, 198, -93, 322, 91, -72,
+ -127, -376, -657, 139, 623, 223, 501, 306, 220,
+ -113, -384, -796, 504, 438, 85, 213, -83, -194,
+ -174, -422, 7, 1155, 1089, 1182, 1003, 945, 806,
+ 8, -126, -317, -103, -351, -695, -98, -268, -537,
+ 33, -103, -290, 167, -39, -407, 44, -208, -375,
+ 104, -23, -64, -291, -637, -851, -1084, -61, -112,
+ -75, -306, -434, 218, -148, -354, -680, -133, -216,
+ -121, -377, -718, -97, -130, -361, -156, -379, -599,
+ -56, -254, -586, 235, 157, -214, 11, -260, -149,
+ -124, -267, -397, -580, -593, -527, -805, -385, 346,
+ -193, -440, -708, -351, -141, -255, -499, -147, -185,
+ 448, 660, 494, 208, 509, 461, 338, 291, 149,
+ -223, 88, 335, 159, 212, 191, 286, 308, 205,
+ -171, -242, 514, 362, 295, 524, 552, 694, 585,
+ -64, -308, -448, -21, 284, 786, 446, 289, 92,
+ -218, -390, -7, 169, 206, 330, 352, 408, 358,
+ -36, 702, 959, 859, 861, 1115, 1269, 1357, 1305,
+ -133, -341, -65, 678, 417, 440, 486, 518, 780,
+ 33, -44, -191, -344, -461, -755, -201, 217, -31,
+ -353, -547, -44, 123, -61, -68, -79, 29, 60,
+ 73, -57, -406, -766, -1243, -1203, 240, 400, 165,
+ -73, -282, -601, -213, -171, -375, 332, 35, -103,
+ -29, -207, -553, -476, -638, -908, 172, -22, -135,
+ -192, -239, -164, -103, -111, -47, 153, 125, 110,
+ -1, -203, -570, -1030, -1424, -535, 155, 1, 147,
+ -333, -653, -865, -197, -158, -21, -44, 95, 108,
+ 389, 588, 490, 33, -237, -524, -628, -136, -260,
+ 40, -177, -462, 453, 862, 380, 131, -130, -405,
+ -76, -281, -741, -742, 898, 619, 277, 71, -222,
+ -32, -265, -556, -25, 994, 682, 305, 126, -165,
+ -69, -349, -585, 234, 1158, 903, 626, 510, 251,
+ -1, -99, -272, -210, -603, -351, -540, -811, -383,
+ -16, -230, -504, 410, 149, -205, -343, -651, -639,
+ 103, -9, -227, -205, -562, -781, -1079, -1208, -156,
+ 143, 63, -135, -67, -317, -602, -784, -1154, -640,
+ -144, -391, -674, -622, -200, -254, -660, -947, -395,
+ -40, -250, -625, 27, 543, 94, -131, -386, -673,
+ -123, -371, -757, -451, -564, -614, -415, -711, -35,
+ -116, -309, -593, -268, 239, -33, -338, -650, -135,
+ 94, 251, 554, 57, -312, -423, -154, -57, 235,
+ -268, -71, 381, 114, -44, -87, 125, 173, 133,
+ -131, -19, 1149, 670, 486, 356, 309, 369, 296,
+ -223, -501, -899, -722, -70, 6, 131, 310, 394,
+ -99, -303, -517, 249, 64, -53, 135, -11, 453,
+ -147, -399, -730, -401, 817, 738, 802, 749, 575,
+ -154, -435, -739, 800, 593, 366, 529, 318, 326,
+ -224, 45, -39, -387, -515, -518, -608, -384, -321,
+ -315, -377, 143, -101, -113, -377, -177, -144, -12,
+ 117, 40, -239, -651, -1051, -581, -737, -990, -328,
+ 26, -50, -157, -23, -453, -283, -531, -546, 192,
+ -252, -501, -743, -589, -627, -499, -328, -118, -72,
+ -324, -494, -244, -306, -144, -177, -262, -135, -78,
+ -36, -234, -519, -961, -1290, -314, -479, -371, -45,
+ -95, -292, -535, -8, -300, 112, -164, -277, 198,
+ -99, -128, 880, 836, 579, 351, 23, -95, -217,
+ -27, -258, 124, 1011, 597, 425, 144, 7, -73,
+ -69, -300, -683, -435, 1132, 899, 504, 332, 109,
+ -74, -323, -637, 563, 1074, 608, 371, 105, -49,
+ -259, -121, 1440, 1334, 1628, 1490, 1438, 1223, 933,
+ -82, -306, -613, -222, -378, -675, -545, -671, -845,
+ 53, -124, -347, 422, 52, -125, -270, -529, 9,
+ 79, -89, -320, -662, -999, -1199, -1243, -676, -297,
+ -68, -273, -611, 137, -146, -397, -627, -845, -220,
+ -112, -346, -797, -826, 234, -132, -188, -278, -522,
+ -159, -405, -734, -419, 293, 74, -167, -167, 184,
+ -153, -437, -833, -1080, -336, -472, -561, -340, -253,
+ -169, -423, -820, -904, -131, -19, -346, -604, 31,
+ 33, -31, 312, 62, -148, 49, -59, 564, 486,
+ -306, -333, 194, -44, 67, 72, 147, 205, 243,
+ -207, -49, 1360, 983, 969, 991, 1014, 1110, 973,
+ -211, -172, 883, 627, 711, 674, 705, 798, 746,
+ -88, -325, -763, -974, 687, 908, 514, 382, 172,
+ -292, -612, -805, 63, 131, 270, 259, 352, 348,
+ -235, -84, 955, 818, 1120, 1289, 1559, 1480, 1285,
+ -180, -461, -614, 657, 691, 745, 854, 783, 713,
+ -97, -309, -477, -614, -777, -734, -768, -526, -472,
+ -344, -476, -35, -169, 49, -77, -150, -240, -141,
+ -52, -268, -639, -919, -1278, -1113, -342, -333, -151,
+ -68, -242, -585, -73, -209, -478, -159, -429, 133,
+ -197, -499, -1005, -1268, -272, -224, -105, -67, 17,
+ -363, -618, -414, -116, -62, 20, 10, 116, 108,
+ -195, -475, -906, -1260, -891, -441, -277, -142, -28,
+ -226, -519, -950, -700, -275, -266, -116, -105, 82,
+ 404, 511, 520, 327, 17, -194, -333, -536, -586,
+ -114, -130, 276, 237, 204, 342, 135, -16, -111,
+ 191, 180, -137, -467, 272, 106, -95, 17, -192,
+ -80, -290, -626, 194, 598, 196, 21, -281, 77,
+ 137, 367, 534, 764, 670, 382, 296, 153, 84,
+ 303, 497, 144, -85, -125, -539, -482, -464, -764,
+ 233, 347, 68, -147, 169, -210, -242, -226, -482,
+ 307, 422, 154, -175, -386, -722, -724, -904, -1015,
+ 309, 308, 160, -60, -470, -420, -598, -791, -219,
+ 68, 121, -137, -560, -146, -446, -515, -494, -729,
+ 130, 53, -227, 46, 474, 32, -161, -192, -490,
+ 213, 164, -71, -465, -876, -161, -456, -587, -48,
+ 218, 117, 39, 177, -194, -88, -226, -418, 50,
+ 210, 547, 569, 279, 121, -44, -50, 10, -84,
+ 58, 140, 182, -5, 267, 117, 106, 211, 198,
+ 153, 559, 872, 460, 222, 108, 188, 180, 183,
+ 158, 119, 284, -153, -271, 229, 87, 110, -57,
+ -183, 82, 118, 21, 13, 40, 118, 191, 185,
+ 163, 56, 609, 341, 50, 329, 68, 266, 218,
+ 100, 206, 18, -304, -107, -436, -487, -65, -306,
+ -86, 154, 134, -30, -45, -73, -104, -80, -96,
+ 245, 330, 10, -440, -849, -1082, 79, 40, -265,
+ 196, 372, 272, -181, -493, -389, 275, 80, -59,
+ 2, -12, -246, -505, -100, -436, 21, -187, -431,
+ -221, -48, 36, -271, -186, -147, -109, 26, 71,
+ 213, 140, 72, -351, -620, -84, -363, 69, 46,
+ 91, 167, -3, -95, -99, -105, -48, 114, 147,
+ 259, 249, 172, 607, 406, 52, 59, -189, -320,
+ 115, -85, -54, 574, 128, 226, -59, -253, 130,
+ 39, 364, 757, 940, 728, 660, 659, 583, 770,
+ -115, -338, -760, -471, 394, 37, 441, 178, 6,
+ -57, -305, -525, 796, 453, 188, -4, -114, 248,
+ 71, 444, 797, 731, 1096, 1157, 1222, 1029, 811,
+ 135, 359, 551, 425, 749, 815, 874, 704, 502,
+ 132, 247, 0, -206, -449, -750, -258, -514, -633,
+ 248, 249, 91, 121, -195, -499, -90, -282, -435,
+ 78, 20, -277, -623, -983, -1224, -415, -458, -639,
+ 347, 509, 208, -179, -464, -728, -76, -237, -486,
+ -103, -343, -756, -713, -265, -609, -191, -398, -636,
+ -121, -383, -749, 567, 252, -36, -354, -417, -50,
+ 204, 100, -149, -650, -1081, -47, -7, -263, 111,
+ -46, -180, -267, -324, -562, -394, -692, 398, 292,
+ 482, 670, 683, 624, 442, 165, 116, 36, -149,
+ 108, 247, 291, 247, 355, 122, 109, 224, 296,
+ 292, 349, 725, 482, 388, 329, 429, 620, 667,
+ -34, 197, 213, -127, 84, 494, 620, 575, 375,
+ 126, 207, 172, 167, 362, 202, 296, 395, 455,
+ -6, 250, 539, 467, 636, 801, 1149, 1287, 1118,
+ 27, 240, 369, 280, 440, 411, 634, 892, 953,
+ 159, 170, -58, -395, -797, -690, 77, -211, -334,
+ -5, -28, -13, -74, -335, -603, 300, 88, -205,
+ 82, -33, -364, -698, -1203, -1153, 110, -146, -289,
+ 113, 1, -243, -588, -994, -496, 414, 160, 42,
+ -56, -247, -440, -693, -996, -479, 11, -178, -357,
+ -151, -353, -327, -211, -340, 141, 65, 425, 453,
+ 34, -169, -455, -932, -1215, 138, 499, 256, 324,
+ 68, 139, -15, -547, -478, 17, 306, 502, 481,
+ -32, -134, 445, 129, -143, -244, -503, -507, -599,
+ 61, -140, -345, 496, 458, -2, 20, -227, -514,
+ 215, 519, 920, 1053, 1090, 791, 528, 290, 155,
+ -54, -233, -647, -602, 639, 294, -2, -167, -442,
+ -78, -315, -791, -113, 820, 403, 158, -116, -356,
+ -105, -379, -236, 1224, 893, 749, 568, 356, 214,
+ -17, -199, -144, 50, -283, -247, -578, -846, -1087,
+ 69, -11, -381, -206, 209, -284, -387, -416, -716,
+ 39, -5, -145, -374, -682, -909, -1074, -1169, -1066,
+ 287, 226, 67, -221, -662, -171, -421, -642, -707,
+ -132, -348, -538, -448, -20, -4, -354, -748, -933,
+ 4, -75, -289, -598, 317, 52, -208, -297, -559,
+ -88, -264, -358, -589, -631, -248, -523, -822, -1071,
+ 70, -8, 54, -314, -515, 92, -146, -274, -493,
+ 199, 62, 391, 158, -141, 71, -219, -203, -207,
+ 152, 40, 329, 162, -29, 48, -149, 108, 127,
+ 267, 722, 1256, 882, 625, 248, 8, -81, -60,
+ -58, -138, -291, -600, -12, -2, -39, 147, 117,
+ -107, -345, -513, 459, 76, 92, -272, 388, 262,
+ 362, 516, 203, -409, -716, -831, -331, 185, 209,
+ -117, -391, -298, 671, 292, 538, 257, 166, -38,
+ -102, -319, -194, -283, -573, -262, -579, -219, -444,
+ -235, 78, 11, -168, -101, -229, -263, -321, -123,
+ 70, 50, -170, -599, -996, -588, -263, -516, -455,
+ 394, 363, 229, -136, -538, 21, -183, -348, -201,
+ -124, -368, -640, -879, -847, -209, -409, -494, -515,
+ -127, -341, -541, -425, -510, -10, -252, -473, -291,
+ 84, -69, -201, -676, -868, 103, -311, -132, -320,
+ 5, -173, -188, -297, -628, 197, -57, 7, -11,
+ 49, -160, 56, 558, 111, 33, -311, -440, -463,
+ -1, -246, -307, 862, 453, 139, -170, -355, -232,
+ -197, -38, 1702, 1331, 1252, 950, 692, 504, 426,
+ -108, -344, -861, -1172, 444, 354, 88, -46, -220,
+ -53, -321, -494, 1113, 744, 364, 198, -34, -75,
+ -69, 199, 897, 1140, 1343, 1183, 977, 742, 522,
+ 122, 44, -269, 27, -155, -562, -307, -590, -773,
+ 154, 42, -160, 252, -129, -305, -471, -733, -371,
+ 135, 185, -82, -416, -722, -913, -504, -743, -880,
+ 149, 214, -84, -329, -680, -835, -426, -661, -81,
+ -128, -380, -735, -998, -337, 17, -182, -467, -697,
+ -84, -290, -510, -592, 13, 440, 154, -38, -279,
+ 70, -61, -246, -727, -1047, -80, -381, -535, -704,
+ 178, -2, -146, -670, -938, 482, 138, 63, 65,
+ -11, 15, 772, 443, 142, -20, -209, -126, -161,
+ -32, -249, 95, 552, 124, 30, -343, 82, -86,
+ -163, -257, 899, 1097, 906, 751, 502, 390, 294,
+ -51, -258, -447, -806, -368, 763, 464, 364, 183,
+ -166, -374, -367, 87, 35, 399, 418, 856, 833,
+ -205, -310, 588, 778, 785, 1065, 1118, 1245, 1157,
+ -173, -312, 107, 345, 400, 790, 870, 1113, 1001,
+ -7, -120, -387, -410, -614, -943, -226, -384, -491,
+ -203, -288, -51, -331, -90, -178, -408, -573, -338,
+ 56, -29, -273, -627, -1041, -798, -247, -467, 148,
+ 66, -2, -205, -205, -575, -349, -57, -352, -58,
+ -45, -225, -471, -924, -497, 77, -32, 44, -135,
+ -277, -491, -497, -502, -424, -202, -137, 77, 96,
+ 26, -179, -469, -1008, -1260, 262, -35, -132, -259,
+ -66, -232, -447, -533, -789, -191, -100, -267, 364,
+ 111, 43, -287, -423, -608, -987, -922, -799, -827,
+ 77, 76, -101, -260, -549, -850, -88, -231, -329,
+ 75, 24, -66, -269, -427, -528, -773, 201, -5,
+ 67, 7, -61, -320, -487, 12, -200, -242, -94,
+ 27, -54, -149, -354, -661, -594, -450, -481, 560,
+ 31, -69, -246, -549, -1141, -178, -232, -275, -288,
+ 16, -84, -176, 7, -83, -210, -246, -424, -589,
+ 63, -60, -201, -90, -269, -400, -685, -1218, -258,
+ 169, 217, 142, -71, -243, -433, -504, -511, -537,
+ 6, -105, -234, -321, -188, -131, -307, -521, -1319,
+ -34, -151, -369, 11, 44, -95, -280, -500, 160,
+ 31, -37, -163, -334, 288, 89, -150, -86, -299,
+ -35, -161, -362, -74, -74, -263, 240, 9, -153,
+ -45, -208, -529, -896, 89, 24, -130, -313, -373,
+ 234, 276, 197, -10, -236, -162, -134, -85, -112,
+ 42, -73, 133, 392, 98, 72, -153, -162, -99,
+ -3, -145, -338, 408, 401, 133, -52, -296, -501,
+ 3, -109, -152, -85, -56, 42, -145, 703, 205,
+ -49, -149, -281, -134, -121, -41, -21, 16, 958,
+ 30, -107, -196, -463, -523, 490, 236, 70, -128,
+ -33, -161, -364, -148, 757, 516, 250, 43, -65,
+ -34, -193, -244, 750, 527, 349, 234, 172, 134,
+ -64, -223, -379, 55, 28, 248, 793, 442, 320,
+ 29, -85, -298, -622, -888, 127, 206, 387, 460,
+ -48, -170, -477, -876, 573, 635, 440, 375, 311,
+ 42, 3, -212, -441, -718, -821, 388, 373, 211,
+ -106, -155, 1092, 459, 570, 561, 506, 604, 514,
+ -144, -264, 0, 460, 619, 877, 916, 1273, 921
+};
+
/*-------------------------------------------------------------------*
* 1nd stage, 2nd split: ISF9 to ISF15
*-------------------------------------------------------------------*/
@@ -8343,6 +9154,267 @@ const float dico2_isf[] =
-91.5009f, -186.5192f, -95.3213f, -190.6698f, -103.7853f, 133.5730f, -129.6124f
};
+/* ISF codebook - common 1st stage, 2nd split (only in AMR-WB IO mode) */
+const Word16 dico2_isf_fx[] =
+{
+ 1357, 1313, 1136, 784, 438, 181, 145,
+ 636, 648, 667, 568, 442, 217, 362,
+ 427, 440, 674, 524, 332, 117, -417,
+ 121, 295, 468, 465, 230, 44, -221,
+ -147, -240, 149, 80, 390, 278, 106,
+ -418, -556, 552, 511, 235, 144, -95,
+ 43, 193, 274, 150, 67, 34, -273,
+ -43, -126, 171, 416, 282, 63, -354,
+ -372, -86, -344, -108, -94, -182, -89,
+ -600, -840, -200, 465, 258, -11, -253,
+ -48, 329, 97, -290, -543, -795, -354,
+ -570, -117, 187, 10, -133, -416, -76,
+ -618, -129, -247, -371, 45, -76, 277,
+ -1022, -1079, 126, 474, 254, 127, 52,
+ -281, 76, -167, -361, -283, -551, -283,
+ -119, -52, -1, 134, -32, -204, -415,
+ 1064, 827, 637, 684, 464, 209, 12,
+ 482, 416, 449, 371, 335, 294, 194,
+ 719, 576, 365, 135, 113, 91, -199,
+ 298, 176, 493, 366, 194, 163, 36,
+ -35, -236, -259, -36, -4, 99, 152,
+ -98, -306, -27, 228, 90, 111, -86,
+ 91, 13, -211, -258, -106, 86, -64,
+ 73, -35, -57, -31, 162, 35, -192,
+ -109, -335, -629, -66, -61, -128, 322,
+ -495, -669, -728, 193, 31, -220, 122,
+ 324, 95, -89, -91, -409, -710, -154,
+ 0, -234, 92, 33, -343, -609, -220,
+ -343, -408, -476, -655, -153, 82, 222,
+ -490, -745, -255, 49, -48, 135, -127,
+ 119, -67, -328, -390, -272, -545, -56,
+ -57, -130, -10, -7, -164, -47, -22,
+ 984, 1064, 961, 568, 210, -27, 16,
+ 811, 691, 754, 514, 224, -35, 166,
+ 662, 704, 618, 386, 57, -211, -257,
+ 510, 359, 418, 393, 91, -144, -18,
+ -193, -31, -27, 223, 89, -143, 24,
+ -112, -98, 471, 319, 185, 3, 175,
+ 252, 146, -47, 272, 48, -211, -234,
+ 146, 69, 203, 364, 68, -52, 51,
+ -259, -478, -697, -349, -758, -501, 63,
+ -501, -769, -289, 79, -311, -497, -106,
+ 251, 53, -235, -469, -895, -884, 145,
+ -416, -551, 140, -133, -523, -775, 44,
+ -326, -423, -713, -497, -86, -431, 99,
+ -757, -772, -160, -76, -46, -32, 379,
+ 85, -35, -200, -401, -663, -1040, -247,
+ -180, -330, -92, -376, 27, -183, -110,
+ 1279, 1086, 781, 502, 324, 164, 157,
+ 682, 466, 449, 277, 146, 28, 409,
+ 635, 472, 390, 107, -232, -538, -139,
+ 196, 396, 332, 213, 209, -29, -81,
+ 150, -95, -312, 76, -77, -320, -50,
+ 46, 9, 47, 175, 139, 30, 384,
+ 218, 206, -24, -250, -96, -276, -183,
+ 26, 119, 38, 14, -4, -133, -52,
+ -477, -614, -987, -715, -631, -813, 200,
+ -744, -1009, -1065, -745, -631, -171, 18,
+ -137, -251, -483, -613, -980, -1203, 12,
+ -605, -767, -562, -686, -1088, -515, 58,
+ -202, -428, -782, -1072, -96, -234, -179,
+ -480, -709, -1070, -897, -131, -92, 321,
+ -145, -193, -512, -729, -572, -765, -210,
+ -331, -585, -525, -631, -281, -208, -303,
+ 1165, 1104, 939, 828, 716, 426, 155,
+ 6, -109, 820, 778, 415, 113, -27,
+ 381, 339, 314, 265, 121, -9, -474,
+ -373, 47, 584, 442, 99, -231, -113,
+ -496, -38, -285, 262, 305, 170, 4,
+ -587, -556, 69, 66, 471, 354, 13,
+ -138, 70, -18, 106, 67, 167, -302,
+ -445, -141, 185, 191, 151, 83, -133,
+ -257, -521, -720, -198, 134, -46, -182,
+ -819, -1168, -777, 512, 359, 95, -113,
+ 137, -2, -74, -138, -401, -114, -371,
+ -242, -466, 204, 223, -31, -212, -192,
+ -532, -637, -466, -686, 256, 277, -139,
+ -1141, -1244, -381, -75, -54, 14, 88,
+ -311, 115, -143, -499, -343, 124, -416,
+ -616, -147, -135, 43, -4, 121, -369,
+ 835, 783, 641, 390, 355, 350, 64,
+ 72, 194, 443, 467, 436, 219, 372,
+ 464, 369, 192, 4, -156, -72, -226,
+ 57, 206, 303, 205, 188, 101, 265,
+ -40, -205, -488, -184, 276, 64, -26,
+ -217, -433, -297, 137, 328, 308, -289,
+ 378, 81, -308, -465, 57, -37, 227,
+ -100, 24, -36, -151, 199, 8, 143,
+ -426, -697, -1059, -133, 388, 161, 321,
+ -644, -1023, -1271, 39, 66, -123, 70,
+ 372, 177, -173, -556, -553, -304, -189,
+ -117, -369, -425, -122, -462, -152, -73,
+ -649, -850, -1189, -767, 497, 360, 222,
+ -798, -1139, -1455, -190, 430, 234, 179,
+ 42, -94, -405, -692, 38, -202, -246,
+ -169, -366, -290, -88, -64, 32, -292,
+ 1010, 923, 938, 710, 465, 230, 342,
+ 217, 300, 1054, 675, 68, -458, -179,
+ 78, 453, 316, 18, -237, -496, -243,
+ 167, 21, 424, 215, -91, -303, -170,
+ -290, -81, -70, -67, 40, 54, -59,
+ -353, -427, -90, 53, 94, 9, 54,
+ -28, 318, 283, 15, -240, -58, 79,
+ -75, -121, 229, 35, 58, 6, -133,
+ -351, -514, -744, -834, -705, -137, 164,
+ -1124, -1388, -1055, -230, -73, 40, 36,
+ -163, -233, -532, -785, -1170, -697, 96,
+ -788, -959, -246, -430, -624, -165, -8,
+ -856, -540, -630, -907, -337, -70, 76,
+ -937, -1042, -659, -733, -208, 199, -26,
+ -523, 78, -98, -501, -869, -890, -81,
+ -624, -703, -45, -348, -25, 87, -186,
+ 1005, 823, 546, 249, 90, -22, 207,
+ 298, 397, 381, 319, 200, 62, 303,
+ 473, 379, 133, -247, -632, -441, 75,
+ 284, 208, 391, 115, -25, 44, 95,
+ -72, 79, -95, -63, -129, -293, 203,
+ -164, -349, 115, 122, 69, -1, 378,
+ 348, 170, 99, 58, -179, -302, 188,
+ -190, -2, 150, 23, -51, -11, 216,
+ -615, -863, -1090, -1427, -802, -48, -6,
+ -961, -1276, -1548, -727, -58, 56, 223,
+ -124, -255, -561, -988, -1277, -148, -82,
+ -480, -660, -891, -1191, -1339, -325, 20,
+ -621, -917, -1296, -1350, 264, 289, 50,
+ -844, -1022, -1345, -1329, -293, 46, 278,
+ -260, -468, -829, -1176, -533, -560, -78,
+ -215, -484, -822, -1233, -791, 15, -138,
+ 1301, 1317, 1262, 1048, 716, 357, -64,
+ 578, 824, 925, 802, 630, 362, 102,
+ 470, 925, 767, 514, 327, 190, -112,
+ 225, 492, 495, 437, 598, 384, -45,
+ 43, 82, -42, 175, 519, 342, -64,
+ -304, -154, 159, 576, 403, 221, 327,
+ 214, 244, 122, -62, 312, 92, -160,
+ 218, 208, 310, 268, 306, 323, -199,
+ -285, -269, -79, -124, -143, -153, 236,
+ -205, -384, -426, 344, 59, -185, -184,
+ -272, 247, 126, -210, -518, -468, 78,
+ -99, -120, 502, 160, -280, -557, 304,
+ -423, -17, -283, -443, 215, 212, -140,
+ -564, -684, -228, 510, 361, 130, 323,
+ -428, 335, 98, -65, 36, -215, -246,
+ -362, 51, 364, -16, -234, 150, -165,
+ 914, 883, 751, 653, 676, 464, -153,
+ 631, 545, 535, 720, 596, 360, -81,
+ 783, 712, 512, 439, 341, 251, -391,
+ 497, 417, 249, 372, 295, 173, -193,
+ 128, -110, -385, 93, 39, 173, -231,
+ 216, -59, -253, 462, 389, 154, 69,
+ 455, 270, -4, -337, -49, 233, -322,
+ 307, 143, 53, 218, 128, 236, -156,
+ -37, -186, -240, -411, -110, 9, 399,
+ -140, -365, -628, 258, 380, 214, 277,
+ 131, 454, 177, -285, -520, 108, -214,
+ 77, -141, 201, -123, -490, -131, 60,
+ -14, -194, -521, -741, 273, 362, -33,
+ -362, -566, -287, -228, 161, 237, 317,
+ -269, 195, -75, -375, -204, 11, 77,
+ -128, -264, -156, -223, -475, 265, 27,
+ 1238, 1147, 916, 689, 432, 210, -280,
+ 800, 664, 879, 726, 411, 160, -164,
+ 454, 686, 536, 275, 147, 46, 111,
+ 303, 486, 512, 355, 241, 181, -69,
+ 79, 92, 29, 147, 233, 52, 17,
+ -171, 289, 131, 439, 271, 3, -10,
+ 413, 241, 144, 174, 155, -2, 14,
+ 58, 217, 247, 219, 149, 175, -18,
+ 228, -8, -240, -206, -513, -191, 202,
+ -96, -272, -454, 33, -300, -575, 46,
+ -10, -108, -246, -347, -770, -535, 9,
+ -326, -430, -61, -321, -704, -299, 201,
+ -1, -280, -603, -419, -185, 18, -36,
+ -516, -522, -379, -291, -181, -97, 27,
+ -159, -313, -525, -224, -510, -831, -197,
+ -292, -459, -59, -310, -562, -143, -351,
+ 1066, 912, 631, 389, 207, 86, -224,
+ 596, 512, 596, 505, 314, 122, -48,
+ 787, 861, 441, -93, -303, 33, -190,
+ 257, 469, 337, 51, 15, 298, -93,
+ 295, 73, -119, 25, 36, 23, 108,
+ -28, -3, -32, 114, 21, 185, 107,
+ 482, 305, 15, -279, -319, 52, 96,
+ 226, 46, 115, 72, -136, 133, -125,
+ 18, -207, -559, -590, -503, -482, 321,
+ -571, -789, -951, -172, -441, -538, 113,
+ 181, 14, -310, -641, -1001, -202, 159,
+ -136, -393, -433, -513, -911, -144, -22,
+ 72, -265, -706, -954, -159, 53, 332,
+ -338, -591, -852, -383, -395, 56, 44,
+ 43, -158, -464, -897, -631, -157, -294,
+ -161, -128, -328, -573, -483, -125, 11,
+ 1017, 906, 1051, 1005, 679, 341, -102,
+ 359, 334, 1567, 1314, 723, 105, 10,
+ -65, 726, 529, 301, 220, 43, -273,
+ -510, 436, 719, 566, 358, 179, 114,
+ -560, 298, 133, -120, 342, 225, 14,
+ -899, -101, 217, 617, 400, 146, -58,
+ -41, 352, 82, -196, 39, 121, -167,
+ -212, 59, 447, 284, 423, 250, -169,
+ -371, -484, -596, 30, -41, 249, 22,
+ -372, -650, -794, 477, 445, 216, -79,
+ -352, 275, 17, -443, -929, 92, 19,
+ -699, -696, 431, 264, -49, -310, 182,
+ -978, -217, -430, -400, 101, 261, 72,
+ -929, -889, -357, -13, 463, 378, 236,
+ -826, 56, 30, -299, -360, -128, -51,
+ -878, -299, -111, 75, 65, 36, 3,
+ 817, 368, -25, 354, 697, 591, -173,
+ 309, 212, 222, 751, 484, 140, -56,
+ 593, 379, 70, -8, 258, 180, 110,
+ 165, -46, 255, 297, 219, 273, 105,
+ 160, -70, -358, -181, 379, 330, 319,
+ -238, -369, -198, 740, 580, 319, -143,
+ 201, 109, -202, -456, 328, 276, -141,
+ 203, 170, 111, 42, 207, 360, 188,
+ -345, -399, -513, -233, 650, 422, 81,
+ -635, -961, -1220, 463, 539, 204, 209,
+ 202, -25, -194, -498, -787, 193, -143,
+ -449, -538, 195, -106, -331, 68, 62,
+ -228, -477, -840, -576, 317, 128, 283,
+ -671, -937, -807, -114, 391, 335, -62,
+ 246, 2, -314, -679, -303, 180, -88,
+ -107, -272, 90, -198, -28, 290, -112,
+ 885, 1149, 1021, 712, 496, 281, -83,
+ 269, 492, 787, 643, 347, 70, 124,
+ 336, 636, 499, 92, -229, -179, 191,
+ 26, 402, 564, 340, 149, -11, 135,
+ -440, 561, 470, 204, -72, -186, 140,
+ -720, 14, 355, 229, 68, -133, 465,
+ 110, 310, 103, 12, 106, 29, 158,
+ -178, 113, 161, 142, 121, 115, 27,
+ -651, -414, -645, -152, -164, -13, -429,
+ -639, -944, -681, -104, -81, 52, -189,
+ -663, -164, -316, -683, -954, -205, -83,
+ -609, -669, -172, -517, -694, 283, -80,
+ -646, -152, -383, -678, -246, -40, -143,
+ -747, -796, -745, -390, -98, 43, 275,
+ -599, -199, -398, -433, -436, -538, 31,
+ -1107, -568, -376, -265, -126, -21, 1,
+ 847, 573, 308, 392, 305, 101, 55,
+ 273, 293, 201, 267, 346, 201, 123,
+ 727, 480, 226, 2, -65, -138, 164,
+ 273, 208, 173, 292, 12, 253, 174,
+ 340, 207, 180, 88, 116, 46, 475,
+ -460, -166, -30, 13, 110, 173, 396,
+ 137, 88, 43, -137, -94, 34, 284,
+ 96, -14, 226, 40, 63, 70, 130,
+ -467, -735, -1012, -1174, -307, 305, -67,
+ -612, -920, -1146, -567, -8, 92, -25,
+ -182, -271, -492, -754, -857, 287, -75,
+ -494, -787, -689, -683, -709, 137, -326,
+ -288, -550, -903, -1105, 334, 321, -62,
+ -354, -653, -834, -445, 1, 377, -152,
+ -162, -306, -608, -937, -297, 247, -192,
+ -234, -477, -244, -488, -266, 342, -332
+};
+
/*-------------------------------------------------------------------*
* AMR-WB ISF codebook - 46bits, 2 stages, 1st stage common with the
* 36bit codebook,5 splits in the 2nd stage
@@ -8428,6 +9500,75 @@ const float dico21_isf_46b[] =
-50.7563f, -41.0679f, -38.2745f
};
+/* ISF codebook - 46b, 2nd stage, 1st split (only in AMR-WB IO mode) */
+const Word16 dico21_isf_46b_fx[] =
+{
+ 329, 409, 249,
+ -33, 505, 160,
+ -29, -14, 582,
+ -262, 127, 354,
+ 145, 237, 175,
+ -152, 245, 122,
+ 27, 42, 340,
+ -84, -93, 311,
+ 285, 222, -156,
+ 47, -43, -504,
+ 234, 121, 385,
+ 104, -317, 45,
+ 176, 195, 8,
+ 104, -59, -94,
+ 177, 53, 192,
+ -34, -127, 152,
+ 570, 277, -34,
+ -67, -329, -639,
+ -157, -272, 462,
+ -177, -462, 198,
+ 322, 179, 115,
+ -386, 171, 19,
+ 19, -12, 195,
+ -120, -252, 201,
+ 304, 36, -336,
+ -128, -221, -380,
+ 171, -185, 296,
+ -242, -312, 23,
+ 198, 39, 16,
+ -3, -177, -111,
+ 111, -93, 76,
+ -92, -223, 4,
+ 177, 406, -44,
+ -168, 380, -149,
+ -4, 273, 331,
+ -420, 513, 277,
+ 21, 247, 47,
+ -58, 131, -2,
+ -3, 134, 180,
+ -145, 40, 175,
+ 189, 74, -145,
+ -27, -45, -325,
+ 370, -114, -21,
+ -83, -415, -173,
+ 77, 95, -51,
+ -40, -30, -67,
+ 71, 88, 86,
+ -35, -98, 14,
+ 69, 197, -334,
+ -196, 79, -231,
+ -348, -137, 218,
+ -352, -89, -85,
+ 47, 201, -130,
+ -165, 37, -15,
+ -43, 3, 86,
+ -161, -108, 79,
+ 83, 21, -237,
+ -81, -149, -238,
+ 150, -186, -251,
+ -186, -249, -162,
+ -19, 66, -139,
+ -26, -50, -181,
+ 24, 11, 0,
+ -130, -105, -98
+};
+
/*-------------------------------------------------------------------*
* 2nd stage, 2nd split: ISF3 to ISF5
*-------------------------------------------------------------------*/
@@ -8564,6 +9705,139 @@ const float dico22_isf_46b[] =
93.1589f, -21.5846f, -101.7248f
};
+/* ISF codebook - 46b, 2nd stage, 2st split (only in AMR-WB IO mode) */
+const Word16 dico22_isf_46b_fx[] =
+{
+ -127, 310, 42,
+ -242, 197, 5,
+ -151, 84, -17,
+ -214, 127, -149,
+ -247, -131, 159,
+ -268, -267, -95,
+ -217, 1, -79,
+ -271, -80, -185,
+ -45, 436, 159,
+ 165, 199, 391,
+ -33, 81, 187,
+ -66, -42, 355,
+ -298, -57, 343,
+ -108, -537, 226,
+ -144, -23, 193,
+ 176, -402, 87,
+ 53, 296, 25,
+ -84, 253, -104,
+ -58, 105, -126,
+ -169, 174, -314,
+ -48, 44, -294,
+ -164, -417, -242,
+ -139, 3, -194,
+ -155, -207, -211,
+ 119, 322, 213,
+ 333, 50, 380,
+ 237, 247, -2,
+ 466, -16, 201,
+ 238, -255, -107,
+ 67, -440, -149,
+ 122, -88, -139,
+ 88, -247, -73,
+ -41, 231, 167,
+ -62, 155, 16,
+ -65, 16, 77,
+ -68, -2, -63,
+ -151, -300, 160,
+ -18, -333, 54,
+ -56, -94, 5,
+ 2, -190, 14,
+ 92, 148, 209,
+ 108, 9, 272,
+ 108, 35, 110,
+ 142, -85, 145,
+ 47, -157, 279,
+ 3, -320, 246,
+ 43, -72, 68,
+ 86, -217, 135,
+ 36, 140, 79,
+ 56, 175, -49,
+ 26, 45, 3,
+ 73, 55, -101,
+ 109, -183, -242,
+ -4, -283, -242,
+ 48, -68, -48,
+ -6, -153, -122,
+ 161, 196, 96,
+ 232, 80, 190,
+ 165, 97, 11,
+ 258, -31, 71,
+ 267, -77, -91,
+ 311, -209, 87,
+ 152, -14, -22,
+ 150, -149, 9,
+ -324, 557, 187,
+ -384, 307, 46,
+ -251, 27, 77,
+ -365, 77, -52,
+ -482, -84, 160,
+ -424, -515, -64,
+ -294, -120, -4,
+ -476, -116, -109,
+ -97, 318, 365,
+ 106, 627, 445,
+ -190, 120, 287,
+ -146, 65, 619,
+ -427, 242, 363,
+ -361, -371, 432,
+ -347, 102, 168,
+ -629, 195, -14,
+ -65, 476, -47,
+ -297, 320, -168,
+ -55, 356, -264,
+ -391, 82, -286,
+ -51, -31, -556,
+ -178, -399, -586,
+ -205, -49, -360,
+ -343, -238, -337,
+ 220, 457, 58,
+ 561, 467, 259,
+ 340, 270, -168,
+ 450, 77, -280,
+ 60, 167, -413,
+ 133, -252, -492,
+ 216, 157, -290,
+ 282, 0, -495,
+ -226, 293, 183,
+ -157, 135, 122,
+ -158, -59, 39,
+ -133, -118, -97,
+ -332, -309, 113,
+ -160, -425, -6,
+ -149, -211, 24,
+ -80, -277, -90,
+ -11, 125, 338,
+ 130, -71, 465,
+ 5, -45, 184,
+ 237, -95, 253,
+ -139, -197, 297,
+ -19, -300, 511,
+ -63, -152, 139,
+ 250, -289, 336,
+ 124, 339, -150,
+ 34, 176, -208,
+ 171, 166, -116,
+ 94, 38, -229,
+ 75, -65, -339,
+ -78, -205, -385,
+ 0, -30, -163,
+ -56, -110, -242,
+ 321, 244, 194,
+ 505, 238, -1,
+ 317, 116, 65,
+ 309, 88, -74,
+ 452, -51, -50,
+ 334, -217, -290,
+ 211, 41, -152,
+ 238, -55, -260
+};
+
/*-------------------------------------------------------------------*
* 2nd stage, 3rd split: ISF6 to ISF8
*-------------------------------------------------------------------*/
@@ -8700,6 +9974,139 @@ const float dico23_isf_46b[] =
124.6250f, -81.8382f, -127.0619f
};
+/* ISF codebook - 46b, 2nd stage, 3rd split (only in AMR-WB IO mode) */
+const Word16 dico23_isf_46b_fx[] =
+{
+ -10, 151, 359,
+ 136, 298, 223,
+ 255, -104, 290,
+ 423, 6, 183,
+ -270, -269, -98,
+ -52, -82, 13,
+ -82, -274, -97,
+ 90, -246, -72,
+ -299, -70, 421,
+ -88, 365, 430,
+ 187, -318, 381,
+ 380, 37, 488,
+ -373, -316, 79,
+ -308, -101, 5,
+ -135, -451, 8,
+ 72, -421, -154,
+ 180, 170, -121,
+ 62, 177, -40,
+ 326, 80, -105,
+ 248, 263, -5,
+ -168, -181, -221,
+ -2, -23, -158,
+ -14, -149, -121,
+ 119, -91, -147,
+ 119, 332, -153,
+ 49, 303, 34,
+ 442, -55, -69,
+ 217, 454, 58,
+ -359, -187, -375,
+ -42, 50, -274,
+ -8, -267, -249,
+ 85, -86, -346,
+ -77, -40, 345,
+ 89, 134, 219,
+ 156, -80, 160,
+ 108, 40, 116,
+ -158, -206, 29,
+ 5, -32, 175,
+ -65, -158, 146,
+ 55, -78, 73,
+ -114, -222, 353,
+ -47, 81, 211,
+ 49, -151, 268,
+ 105, 4, 302,
+ -263, -132, 183,
+ -151, -28, 201,
+ -177, -307, 166,
+ 101, -221, 130,
+ 74, 58, -98,
+ 32, 44, 13,
+ 194, 30, -142,
+ 170, 96, 8,
+ -136, -119, -91,
+ -65, 8, -55,
+ 3, -188, 12,
+ 45, -63, -49,
+ 149, -21, -19,
+ 24, 144, 95,
+ 254, -22, 60,
+ 161, 196, 96,
+ -158, -61, 48,
+ -70, 33, 82,
+ -23, -321, 58,
+ 155, -147, 5,
+ -364, 328, 77,
+ -21, 453, 173,
+ -108, 82, 630,
+ 367, 263, 208,
+ -300, -62, -176,
+ -205, 143, -158,
+ -169, -410, -264,
+ 257, -269, -100,
+ -636, 289, -2,
+ -292, 627, 173,
+ -382, -363, 387,
+ 248, 524, 447,
+ -521, -111, -107,
+ -395, 118, -274,
+ -343, -680, -125,
+ -172, -447, -663,
+ 75, 148, -367,
+ -79, 263, -94,
+ 249, 148, -286,
+ 380, 271, -162,
+ -142, -4, -186,
+ -57, 111, -125,
+ -35, -108, -254,
+ 100, 29, -242,
+ -80, 303, -264,
+ -78, 464, -57,
+ 248, -22, -494,
+ 661, 662, 44,
+ -193, -40, -330,
+ -178, 145, -337,
+ -90, -199, -400,
+ -40, -23, -498,
+ -192, 114, 315,
+ -41, 244, 190,
+ 88, -97, 485,
+ 241, 80, 212,
+ -246, 40, 87,
+ -156, 147, 134,
+ -2, -334, 239,
+ 308, -203, 110,
+ -459, 251, 422,
+ -218, 310, 228,
+ -86, -346, 654,
+ 184, 175, 425,
+ -481, -63, 169,
+ -349, 117, 188,
+ -125, -560, 310,
+ 158, -416, 94,
+ 46, 171, -192,
+ -63, 157, 14,
+ 256, -35, -271,
+ 322, 123, 53,
+ -214, 4, -76,
+ -156, 86, -18,
+ 128, -197, -232,
+ 265, -90, -98,
+ -308, 332, -145,
+ -131, 308, 58,
+ 509, 59, -339,
+ 562, 196, -14,
+ -378, 100, -47,
+ -234, 202, 1,
+ 104, -270, -493,
+ 319, -210, -325
+};
+
/*-------------------------------------------------------------------*
* 2nd stage, 4th split: ISF9 to ISF11
*-------------------------------------------------------------------*/
@@ -8740,6 +10147,43 @@ const float dico24_isf_46b[] =
9.3252f, 52.8599f, 21.3451f
};
+/* ISF codebook - 46b, 2nd stage, 4th split (only in AMR-WB IO mode) */
+const Word16 dico24_isf_46b_fx[] =
+{
+ -79, -89, -4,
+ -171, 77, -211,
+ 160, -193, 98,
+ 120, -103, 323,
+ 32, -22, -129,
+ 72, 78, -268,
+ 182, -76, -66,
+ 309, 99, -145,
+ -229, -157, -84,
+ -383, 98, -71,
+ -90, -352, 12,
+ -284, -178, 178,
+ -65, -125, -166,
+ -87, -175, -351,
+ 42, -198, -48,
+ 154, -140, -243,
+ -77, 18, 108,
+ -39, 355, 91,
+ 87, 8, 155,
+ -4, 158, 239,
+ 128, 95, -54,
+ 7, 246, -124,
+ 258, 15, 89,
+ 206, 216, 98,
+ -201, 9, 18,
+ -312, 233, 204,
+ -39, -174, 155,
+ -144, -9, 284,
+ -57, 70, -69,
+ -157, 187, 18,
+ 54, -30, 23,
+ 24, 135, 55
+};
+
/*-------------------------------------------------------------------*
* 2nd stage, 1st split: ISF12 to ISF15
*-------------------------------------------------------------------*/
@@ -8780,6 +10224,44 @@ const float dico25_isf_46b[] =
-35.4129f, -58.9663f, 65.8078f, -102.2045f
};
+/* ISF codebook - 46b, 2nd stage, 5th split (only in AMR-WB IO mode) */
+const Word16 dico25_isf_46b_fx[] =
+{
+ 169, 142, -119, 115,
+ 206, -20, 94, 226,
+ -106, 313, -21, 16,
+ -62, 161, 71, 255,
+ -89, 101, -185, 125,
+ 72, -30, -201, 344,
+ -258, 33, -8, 81,
+ -104, -154, 72, 296,
+ 144, -68, -268, -25,
+ 81, -78, -87, 106,
+ 22, 155, -186, -119,
+ -46, -28, 27, 91,
+ -114, -37, -175, -33,
+ -94, -222, -189, 122,
+ -132, -119, -191, -270,
+ -172, -173, 18, -43,
+ 279, 135, -42, -128,
+ 187, -86, 229, -138,
+ 159, 240, 140, 46,
+ 69, 25, 227, 77,
+ 21, 115, 13, 8,
+ 68, -248, 126, 81,
+ -150, 137, 207, -9,
+ -154, -133, 289, 67,
+ 143, -37, -86, -326,
+ 180, -32, 19, -23,
+ 26, 168, 116, -233,
+ -32, -26, 118, -78,
+ 3, -8, -45, -115,
+ 57, -215, -54, -83,
+ -209, 112, -22, -167,
+ -91, -151, 168, -262
+};
+
+
/*-------------------------------------------------------------------*
* AMR-WB ISF codebook - 36bits, 2 stages, 1st stage common with the
* 46bit codebook,3 splits in the 2nd stage
@@ -8927,6 +10409,139 @@ const float dico21_isf_36b[] =
3.3643f, -11.1758f, -92.5898f, -201.1381f, 102.8789f
};
+/* ISF codebook - 36b, 2nd stage, 1st split (only in AMR-WB IO mode) */
+const Word16 dico21_isf_36b_fx[] =
+{
+ -52, -96, 212, 315, -73,
+ 82, -204, 363, 136, -197,
+ -126, -331, 183, 218, 143,
+ -49, -41, 557, 230, 72,
+ 2, -73, 163, 377, 221,
+ 133, 111, 278, 215, -110,
+ -102, -20, 284, 113, 273,
+ 84, 319, 290, 18, 85,
+ -25, -5, 125, 132, -204,
+ -38, -5, 286, -9, -356,
+ -140, -256, 92, 117, -189,
+ -144, 191, 313, 51, -98,
+ 167, -10, 44, 247, 36,
+ 381, 197, 238, 74, 6,
+ 38, -408, 29, -3, -85,
+ 92, 266, 157, -25, -200,
+ 161, -121, 70, 84, -140,
+ -16, -86, 112, -94, -189,
+ -269, -270, 351, 107, -24,
+ -68, -67, 492, -103, -155,
+ -53, -131, 62, 122, 10,
+ 135, 84, 283, -55, -120,
+ -12, -219, 331, -81, 167,
+ 220, -136, 147, -172, -42,
+ 140, -95, -109, -88, -194,
+ 0, -2, -4, -33, -381,
+ -66, -217, 152, -186, -402,
+ 244, 108, 156, -140, -395,
+ 113, -136, -196, 110, -24,
+ 214, 118, 11, -64, -131,
+ -110, -286, -6, -332, 16,
+ 94, 97, 79, -291, -205,
+ -5, -39, -20, 252, -96,
+ 76, 174, 101, 163, 61,
+ -69, -239, -55, 399, 6,
+ -115, 319, 164, 275, 196,
+ -15, 36, -47, 331, 121,
+ 226, 209, 271, 325, 184,
+ 13, -80, -218, 471, 353,
+ 288, 378, 16, -51, 251,
+ 174, 116, 52, 149, -279,
+ 235, 276, 39, 120, -48,
+ 0, -108, -108, 241, -339,
+ -93, 534, 45, 33, -87,
+ 194, 149, -71, 405, -44,
+ 409, 370, 81, -186, -154,
+ 25, -102, -448, 124, -173,
+ 22, 408, -110, -310, -214,
+ -26, 23, -83, 114, 14,
+ -110, 164, 52, 223, -82,
+ 37, -25, -263, 306, -15,
+ -466, 415, 292, 165, -18,
+ 29, -19, -171, 155, 182,
+ 179, 144, -27, 231, 258,
+ -103, -247, -396, 238, 113,
+ 375, -154, -109, -4, 156,
+ 98, 85, -292, -5, -124,
+ 116, 139, -116, -98, -294,
+ -14, -83, -278, -117, -378,
+ 106, 33, -106, -344, -484,
+ 119, 17, -412, 138, 166,
+ 384, 101, -204, 88, -156,
+ -121, -284, -300, -1, -166,
+ 280, 33, -152, -313, -81,
+ -37, 22, 229, 153, 37,
+ -60, -83, 236, -8, -41,
+ -169, -228, 126, -20, 363,
+ -235, 17, 364, -156, 156,
+ -25, -30, 72, 144, 156,
+ 153, -26, 256, 97, 144,
+ -21, -37, 48, -65, 250,
+ 63, 77, 273, -128, 124,
+ -129, -26, 40, 9, -115,
+ -6, 82, 38, -90, -182,
+ -336, -13, 28, 158, 91,
+ -30, 241, 137, -170, -17,
+ 146, 14, -11, 33, 61,
+ 192, 197, 54, -84, 85,
+ 23, -200, -78, -29, 140,
+ 122, 237, 106, -341, 136,
+ -57, -142, -85, -16, -74,
+ -59, -90, -8, -187, -20,
+ -211, -267, 216, -179, -110,
+ -50, -7, 220, -267, -70,
+ -57, -42, -17, -15, 71,
+ 32, 21, 63, -137, 33,
+ -137, -175, 104, -68, 97,
+ -67, -43, 133, -301, 221,
+ -116, -200, -81, -92, -272,
+ -64, -41, -54, -244, -220,
+ -287, -242, -50, -87, -89,
+ -245, 236, 102, -166, -295,
+ 66, 24, -162, -71, 95,
+ 66, 136, -90, -220, -36,
+ -98, -161, -222, -188, 29,
+ -18, 18, -19, -415, 9,
+ 49, 61, 100, 39, -56,
+ -111, 82, 135, -31, 52,
+ -90, -153, -93, 189, 182,
+ -214, 295, 119, -74, 284,
+ 2, 137, 37, 47, 182,
+ 92, 117, 184, -53, 373,
+ -21, -14, -35, 136, 391,
+ 146, 129, -164, -28, 333,
+ 92, 80, -84, 100, -134,
+ -8, 217, -32, 3, -47,
+ -151, 251, -215, 142, 92,
+ -224, 310, -172, -275, 98,
+ 159, 155, -177, 112, 53,
+ 205, 27, 8, -240, 192,
+ 169, 120, -319, -201, 106,
+ 11, 36, -86, -237, 455,
+ -109, -154, -163, 174, -55,
+ -38, 32, -101, -78, -59,
+ -205, -321, -97, 69, 79,
+ -310, 44, 18, -185, 34,
+ -115, -20, -148, -39, 203,
+ -29, 154, -30, -158, 166,
+ -45, -131, -317, -24, 363,
+ -165, -205, -112, -222, 265,
+ -32, -44, -150, 54, -193,
+ -6, -38, -255, -169, -115,
+ -266, 87, -189, -36, -169,
+ -60, -87, -266, -436, -170,
+ -68, -81, -278, 24, 38,
+ -23, -19, -155, -256, 141,
+ -61, -226, -565, -175, 71,
+ 9, -29, -237, -515, 263
+};
+
/*-------------------------------------------------------------------*
* 2nd stage, 2nd split: ISF5 to ISF8
*-------------------------------------------------------------------*/
@@ -9063,6 +10678,139 @@ const float dico22_isf_36b[] =
62.3479f, -93.6059f, 19.4353f, -14.9112f
};
+/* ISF codebook - 36b, 2nd stage, 2nd split (only in AMR-WB IO mode) */
+const Word16 dico22_isf_36b_fx[] =
+{
+ -298, -6, 95, 31,
+ -213, -87, -122, 261,
+ 4, -49, 208, 14,
+ -129, -110, 30, 118,
+ -214, 258, 110, -235,
+ -41, -18, -126, 120,
+ 103, 65, 127, -37,
+ 126, -36, -24, 25,
+ -138, -67, -278, -186,
+ -164, -194, -201, 78,
+ -211, -87, -51, -221,
+ -174, -79, -94, -39,
+ 23, -6, -157, -240,
+ 22, -110, -153, -68,
+ 148, -5, -2, -149,
+ -1, -135, -39, -179,
+ 68, 360, -117, -15,
+ 137, 47, -278, 146,
+ 136, 260, 135, 65,
+ 61, 116, -45, 97,
+ 231, 379, 87, -120,
+ 338, 177, -272, 3,
+ 266, 156, 28, -69,
+ 260, 84, -85, 86,
+ -266, 154, -256, -182,
+ -17, -65, -304, -6,
+ -40, 175, -151, -180,
+ -27, 27, -87, -63,
+ 121, 114, -166, -469,
+ 159, -66, -323, -231,
+ 214, 152, -141, -212,
+ 137, 36, -184, -51,
+ -282, -237, 40, 10,
+ -48, -235, -37, 251,
+ -54, -323, 136, 29,
+ -88, -174, 213, 198,
+ -390, 99, -63, -375,
+ 107, -169, -164, 424,
+ 69, -111, 141, -167,
+ 74, -129, 65, 144,
+ -353, -207, -205, -109,
+ -160, -386, -355, 98,
+ -176, -493, -20, -143,
+ -252, -432, -2, 216,
+ -90, -174, -168, -411,
+ 13, -284, -229, -160,
+ -87, -279, 34, -251,
+ -75, -263, -58, -42,
+ 420, 53, -211, -358,
+ 384, -35, -374, 396,
+ 68, -228, 323, -2,
+ 167, -307, 192, 194,
+ 459, 329, -5, -332,
+ 375, 79, -7, 313,
+ 282, -124, 200, -92,
+ 271, -162, -70, 180,
+ -157, -298, -514, -309,
+ 58, -163, -546, 18,
+ 124, -364, 167, -238,
+ 83, -411, -117, 96,
+ 140, -112, -388, -624,
+ 259, -133, -317, 41,
+ 163, -130, -64, -334,
+ 226, -165, -124, -110,
+ -466, -61, 6, 229,
+ -153, 205, -145, 242,
+ -159, 48, 195, 148,
+ -58, 28, 31, 279,
+ -303, 185, 279, -4,
+ -61, 197, 59, 86,
+ -114, 123, 168, -52,
+ 35, 36, 100, 126,
+ -407, 102, -77, -40,
+ -338, -1, -342, 156,
+ -179, 105, -34, -97,
+ -185, 84, -35, 108,
+ -133, 107, -91, -357,
+ -180, 54, -229, 24,
+ -44, 47, 47, -182,
+ -66, 13, 45, 4,
+ -339, 251, 64, 226,
+ -42, 101, -350, 275,
+ -99, 398, 142, 121,
+ 111, 12, -102, 260,
+ 0, 505, 260, -94,
+ 161, 285, -96, 224,
+ -4, 206, 314, 33,
+ 167, 139, 88, 204,
+ -235, 316, -60, -25,
+ -8, -150, -312, 201,
+ -36, 292, 61, -104,
+ -40, 174, -162, 42,
+ -21, 402, -29, -351,
+ 21, 152, -360, -93,
+ 57, 191, 212, -196,
+ 76, 158, -21, -69,
+ -328, -185, 331, 119,
+ -53, 285, 56, 337,
+ -107, -24, 405, 29,
+ -18, 137, 272, 277,
+ -255, 22, 173, -191,
+ 295, 322, 325, 302,
+ 21, -27, 332, -178,
+ 119, 13, 271, 129,
+ -455, -180, 116, -191,
+ -227, 62, -148, 524,
+ -176, -287, 282, -157,
+ -243, 13, 199, 430,
+ -59, -49, 115, -365,
+ 72, -172, -137, 93,
+ -138, -126, 141, -84,
+ 5, -124, 38, -20,
+ -258, 311, 601, 213,
+ 94, 130, -61, 502,
+ -1, -157, 485, 313,
+ 146, -74, 158, 345,
+ 276, 135, 280, -57,
+ 490, 252, 99, 43,
+ 267, -74, 429, 105,
+ 278, -23, 119, 94,
+ -542, 488, 257, -115,
+ -84, -244, -438, 478,
+ -113, -545, 387, 101,
+ -95, -306, 111, 498,
+ 95, 166, 22, -301,
+ 420, -15, -58, -78,
+ 270, 29, 122, -282,
+ 160, -240, 50, -38
+};
+
/*-------------------------------------------------------------------*
* 2nd stage, 3rd split: ISF9 to ISF15
*-------------------------------------------------------------------*/
@@ -9135,6 +10883,75 @@ const float dico23_isf_36b[] =
54.6610f, -1.6150f, -14.3009f, 99.1775f, -24.2467f, 36.0557f, -42.7052f
};
+/* ISF codebook - 36b, 2nd stage, 3rd split (only in AMR-WB IO mode) */
+const Word16 dico23_isf_36b_fx[] =
+{
+ 81, -18, 68, -27, -122, -280, -4,
+ 45, -177, 209, -30, -136, -74, 131,
+ -44, 101, -75, -88, -48, -137, -54,
+ -245, -28, 63, -18, -112, -103, 58,
+ -79, -6, 220, -65, 114, -35, -50,
+ 109, -65, 143, -114, 129, 76, 125,
+ 166, 90, -61, -242, 186, -74, -43,
+ -46, -92, 49, -227, 24, -155, 39,
+ 67, 85, 99, -42, 53, -184, -281,
+ 142, -122, 0, 21, -142, -15, -17,
+ 223, 92, -21, -48, -82, -14, -167,
+ 51, -37, -243, -30, -90, 18, -56,
+ 54, 105, 74, 86, 69, 13, -101,
+ 196, 72, -89, 43, 65, 19, 39,
+ 121, 34, 131, -82, 25, 213, -156,
+ 101, -102, -136, -21, 57, 214, 22,
+ 36, -124, 205, 204, 58, -156, -83,
+ 83, -117, 137, 137, 85, 116, 44,
+ -92, -148, -68, 11, -102, -197, -220,
+ -76, -185, -58, 132, -26, -183, 85,
+ -7, -31, -2, 23, 205, -151, 10,
+ -27, -37, -5, -18, 292, 131, 1,
+ 117, -168, 9, -93, 80, -59, -125,
+ -182, -244, 98, -24, 135, -22, 94,
+ 221, 97, 106, 42, 43, -160, 83,
+ 25, -64, -21, 6, 14, -15, 154,
+ 126, 15, -140, 150, -10, -207, -114,
+ 79, -63, -211, -70, -28, -217, 165,
+ 46, 38, -22, 281, 132, -62, 109,
+ 112, 54, -112, -93, 208, 27, 296,
+ 115, 10, -147, 41, 216, 42, -276,
+ 50, -115, -254, 167, 117, -2, 61,
+ 17, 144, 34, -72, -186, -150, 272,
+ -29, -66, -89, -95, -149, 129, 251,
+ 122, 0, -50, -234, -91, 36, 26,
+ -105, -102, -88, -121, -236, -7, -11,
+ -204, 109, 5, -191, 105, -15, 163,
+ -80, 32, -24, -209, 41, 294, 70,
+ -106, -94, -204, -118, 120, -50, -37,
+ -82, -241, 46, -131, -29, 150, -55,
+ 33, 155, 120, -89, -8, 7, 62,
+ 213, 82, 61, 18, -161, 144, 152,
+ 30, 131, 65, -87, -255, -17, -107,
+ -8, 85, -64, 51, -162, 223, -53,
+ -134, 261, 69, -56, 218, 72, -111,
+ 2, 155, -113, -87, 49, 85, -28,
+ -163, 42, -1, -196, 7, 39, -245,
+ 14, -137, -79, 11, -160, 202, -293,
+ -94, 33, 208, 100, 56, -44, 326,
+ -78, -41, 232, 13, -142, 227, 80,
+ -16, -87, 201, 33, -133, 15, -183,
+ -58, -192, -47, 184, -128, 133, 99,
+ -205, 11, -155, 78, 52, 72, 141,
+ -246, 26, 99, 151, 59, 115, -64,
+ -79, -47, -16, -14, 6, 47, -43,
+ -72, -178, -27, 162, 112, 43, -174,
+ -175, 238, 186, 71, -54, -188, -76,
+ -225, 233, 39, -39, -158, 122, 44,
+ -26, 43, 84, 130, -93, -51, 22,
+ 3, 92, -150, 136, -182, -57, 97,
+ -131, 179, -78, 80, 91, -165, 90,
+ -2, 148, 15, 130, 65, 175, 117,
+ -138, 114, -137, 132, 3, -10, -186,
+ 140, -4, -37, 254, -62, 92, -109
+};
+
/*-------------------------------------------------------------------*
* AMR-WB ISF codebook for SID - 28bits, 1 stage, 5 splits
*
@@ -9219,6 +11036,75 @@ const float dico1_ns_28b[64*2] =
103.9035f, 438.8237f
};
+/* ISF codebook for SID frames - 28b, 1st split */
+const Word16 dico1_ns_28b_fx[] =
+{
+ -269, -673,
+ -222, -537,
+ -233, -430,
+ -138, -451,
+ -212, -331,
+ -192, -241,
+ -87, -231,
+ -191, -128,
+ -70, -106,
+ -164, -6,
+ 74, -179,
+ 27, -33,
+ -102, 74,
+ -162, 115,
+ -94, 172,
+ -6, 130,
+ -143, 234,
+ 14, 218,
+ -65, 270,
+ 88, 182,
+ -124, 341,
+ -44, 381,
+ 38, 335,
+ 117, 274,
+ -112, 454,
+ 74, 431,
+ -5, 488,
+ 175, 384,
+ -83, 561,
+ 122, 529,
+ 21, 601,
+ 229, 481,
+ 231, 303,
+ 226, 608,
+ 300, 372,
+ 210, 187,
+ 306, 265,
+ 328, 473,
+ 382, 331,
+ 371, 132,
+ 139, 58,
+ 365, 21,
+ 250, -82,
+ 443, 218,
+ 483, 110,
+ 426, 415,
+ 579, 222,
+ 518, 333,
+ 573, 448,
+ 455, 529,
+ 685, 329,
+ 332, 580,
+ 595, 593,
+ 468, 645,
+ 762, 517,
+ 326, 709,
+ 485, 793,
+ 130, 684,
+ 671, 737,
+ 354, 876,
+ 88, 806,
+ -65, 706,
+ -35, 1016,
+ 266, 1123
+};
+
/*-------------------------------------------------------------------*
* 1st stage, 2ndt split: ISF2 to ISF4
*-------------------------------------------------------------------*/
@@ -9291,6 +11177,75 @@ const float dico2_ns_28b[64*3] =
488.2212f, 389.4155f, 415.1465f
};
+/* ISF codebook for SID frames - 28b, 2nd spilt */
+const Word16 dico2_ns_28b_fx[] =
+{
+ -824, -884, -949,
+ -805, -456, -418,
+ -442, -438, -541,
+ -217, -578, -793,
+ -168, -444, -582,
+ -287, -492, -274,
+ -552, -297, -300,
+ -163, -333, -358,
+ -370, -232, -232,
+ -175, -358, -159,
+ -381, -21, -357,
+ -184, -159, -162,
+ -53, -191, -280,
+ 18, -267, -215,
+ -138, 61, -283,
+ 71, -95, -294,
+ 13, -156, -546,
+ 0, -83, -79,
+ 44, 97, -316,
+ 178, -52, -213,
+ 222, -261, -422,
+ 237, -118, -44,
+ 141, 145, -132,
+ 363, 81, -287,
+ 213, 65, 34,
+ -107, 94, -5,
+ 91, -29, 126,
+ -355, 51, -41,
+ -219, -76, 145,
+ -63, 100, 244,
+ -719, 44, 27,
+ -572, -124, 155,
+ -423, 133, 315,
+ -917, 71, 224,
+ -268, 318, 131,
+ -93, -190, 420,
+ -97, 122, 491,
+ -79, 317, 355,
+ 130, 100, 325,
+ 86, -293, 210,
+ 133, 258, 161,
+ 176, -73, 465,
+ 195, 300, 384,
+ 348, 22, 221,
+ 376, 183, 409,
+ 377, 286, 202,
+ 242, 213, 659,
+ 257, 565, 248,
+ 344, 408, -76,
+ 405, 440, 509,
+ 612, 385, 379,
+ 536, 607, 216,
+ -56, 582, 192,
+ 100, 517, 567,
+ -365, 448, 445,
+ 728, 347, 10,
+ 505, 357, 759,
+ 636, 582, 658,
+ 335, 517, 852,
+ 378, 809, 572,
+ -195, 878, 829,
+ 529, 707, 987,
+ 918, 726, 392,
+ 1250, 997, 1063
+};
+
/*-------------------------------------------------------------------*
* 1st stage, 3rd split: ISF5 to ISF7
*-------------------------------------------------------------------*/
@@ -9363,6 +11318,75 @@ const float dico3_ns_28b[64*3] =
579.1823f, 650.5953f, 732.6415f
};
+/* ISF codebook for SID frames - 28b, 3rd spilt */
+const Word16 dico3_ns_28b_fx[] =
+{
+ -805, -838, -774,
+ -522, -627, -828,
+ -477, -486, -603,
+ -295, -481, -634,
+ -366, -384, -393,
+ -186, -414, -396,
+ -237, -394, -106,
+ -252, -202, -275,
+ -61, -177, -442,
+ -84, -198, -199,
+ -179, -125, -31,
+ -72, -47, -163,
+ -298, -220, 215,
+ -64, -168, 251,
+ -133, 156, -59,
+ -30, -2, 127,
+ 54, 66, -61,
+ -233, 21, 251,
+ 209, -50, 32,
+ 33, 194, 136,
+ -117, -18, 475,
+ 202, 46, 309,
+ 256, 185, 53,
+ 35, 200, 390,
+ 200, 263, 242,
+ -216, 302, 294,
+ 128, 358, 0,
+ 19, 431, 287,
+ 224, 447, 280,
+ 367, 165, 213,
+ 397, 314, 319,
+ 383, 379, 75,
+ 277, 325, 462,
+ 394, 505, 334,
+ 251, 98, -213,
+ 450, 153, 448,
+ 565, 226, 76,
+ 470, 383, 502,
+ 635, 390, 278,
+ 237, 135, 620,
+ 342, 401, 649,
+ 331, 551, 518,
+ 130, 418, 592,
+ 531, 306, 737,
+ 729, 389, 580,
+ 497, 557, 699,
+ 296, 383, 874,
+ 283, 624, 759,
+ 126, 622, 476,
+ 559, 595, 472,
+ 382, 770, 616,
+ 719, 613, 745,
+ 540, 639, 928,
+ 517, 826, 801,
+ 684, 811, 604,
+ 752, 786, 857,
+ 933, 661, 350,
+ 694, 450, 1061,
+ 562, 911, 1051,
+ 824, 813, 1104,
+ 758, 1047, 882,
+ 1140, 917, 889,
+ 1039, 1246, 1426,
+ 1483, 1666, 1876
+};
+
/*-------------------------------------------------------------------*
* 1st stage, 4th split: ISF8 to ISF11
*-------------------------------------------------------------------*/
@@ -9403,6 +11427,43 @@ const float dico4_ns_28b[32*4] =
620.4818f, 690.0919f, 671.0975f, 590.9387f
};
+/* ISF codebook for SID frames - 28b, 4th spilt */
+const Word16 dico4_ns_28b_fx[] =
+{
+ -776, -854, -891, -920,
+ -552, -610, -663, -741,
+ -321, -370, -476, -565,
+ 274, -160, -456, 201,
+ 265, 67, -160, -306,
+ -8, -210, 79, 272,
+ 163, 236, 307, 308,
+ 578, 317, 64, 298,
+ -9, 197, 342, 620,
+ 343, 232, 314, 622,
+ 173, 149, 548, 527,
+ 356, 370, 481, 376,
+ 135, 444, 488, 556,
+ 391, 471, 487, 653,
+ 228, 424, 576, 835,
+ 422, 372, 722, 682,
+ 295, 673, 693, 635,
+ 539, 596, 590, 449,
+ 475, 618, 659, 818,
+ 735, 517, 491, 673,
+ 602, 346, 257, 877,
+ 625, 635, 849, 720,
+ 727, 818, 698, 595,
+ 653, 481, 690, 1139,
+ 814, 762, 704, 908,
+ 507, 747, 898, 936,
+ 848, 855, 924, 785,
+ 646, 1037, 882, 795,
+ 772, 845, 1024, 1151,
+ 1133, 983, 818, 921,
+ 940, 1068, 1252, 1302,
+ 1588, 1767, 1718, 1513
+};
+
/*-------------------------------------------------------------------*
* 1st stage, 5th split: ISF12 to ISF15
*-------------------------------------------------------------------*/
@@ -9443,6 +11504,43 @@ const float dico5_ns_28b[32*4] =
527.5430f, 471.6736f, 394.4862f, 127.2615f
};
+/* ISF codebook for SID frames - 28b, 5th spilt */
+const Word16 dico5_ns_28b_fx[] =
+{
+ -810, -879, -945, -254,
+ 248, 184, 671, 128,
+ 288, 703, 918, 99,
+ 658, 558, 662, 219,
+ 552, 585, 910, 208,
+ 559, 804, 759, 119,
+ 606, 774, 921, -139,
+ 782, 761, 748, 208,
+ 756, 708, 983, 56,
+ 544, 864, 1010, 152,
+ 737, 698, 987, 299,
+ 771, 924, 879, 103,
+ 536, 785, 961, 405,
+ 667, 916, 801, 328,
+ 738, 705, 773, 439,
+ 823, 871, 992, 355,
+ 640, 1004, 1052, 369,
+ 724, 822, 949, 597,
+ 415, 655, 729, 482,
+ 1009, 896, 793, 363,
+ 908, 803, 687, -25,
+ 1016, 838, 1011, 189,
+ 947, 1112, 942, 222,
+ 914, 1049, 981, 527,
+ 956, 987, 1011, -120,
+ 781, 1049, 1121, 92,
+ 1178, 1053, 884, 47,
+ 1123, 1059, 1182, 118,
+ 933, 972, 1277, 357,
+ 1109, 918, 1101, 503,
+ 1039, 1286, 1220, 317,
+ 1351, 1207, 1010, 326
+};
+
const Word16 means_nb_31bits_ma_lsf[16] = { 861 /*336.3281f*1.28f Q1*/, 1360 /*531.2500f*1.28f Q1*/, 2270 /*886.7188f*1.28f Q1*/, 3243 /*1266.7969f*1.28f Q1*/, 4171 /*1629.2969f*1.28f Q1*/, 5052 /*1973.4375f*1.28f Q1*/, 6012 /*2348.4375f*1.28f Q1*/, 6776 /*2646.8750f*1.28f Q1*/, 7676 /*2998.4375f*1.28f Q1*/, 8428 /*3292.1875f*1.28f Q1*/, 9194 /*3591.4062f*1.28f Q1*/, 9744 /*3806.2500f*1.28f Q1*/, 10580 /*4132.8125f*1.28f Q1*/, 11911 /*4652.7344f*1.28f Q1*/, 13440 /*5250.0000f*1.28f Q1*/, 15061 /*5883.2031f*1.28f Q1*/ };
const Word16 means_wb_31bits_ma_lsf[16] = { 818 /*319.5312f*1.28f Q1*/, 1403 /*548.0469f*1.28f Q1*/, 2392 /*934.3750f*1.28f Q1*/, 3465 /*1353.5156f*1.28f Q1*/, 4429 /*1730.0781f*1.28f Q1*/, 5428 /*2120.3125f*1.28f Q1*/, 6414 /*2505.4688f*1.28f Q1*/, 7323 /*2860.5469f*1.28f Q1*/, 8304 /*3243.7500f*1.28f Q1*/, 9221 /*3601.9531f*1.28f Q1*/, 10162 /*3969.5312f*1.28f Q1*/, 11091 /*4332.4219f*1.28f Q1*/, 12125 /*4736.3281f*1.28f Q1*/, 13153 /*5137.8906f*1.28f Q1*/, 14241 /*5562.8906f*1.28f Q1*/, 15266 /*5963.2812f*1.28f Q1*/ };
@@ -12150,6 +14248,7 @@ const int16_t no_vals_ind[NO_LEADERS][MAX_NO_VALS]=
{1,2,5,0}
};
+
const int16_t C_VQ[LATTICE_DIM+1][LATTICE_DIM+1] =
{
{1,0,0,0,0,0,0,0,0},
@@ -12163,6 +14262,19 @@ const int16_t C_VQ[LATTICE_DIM+1][LATTICE_DIM+1] =
{1,8,28,56,70,56,28,8,1}
};
+const Word16 C_VQ_fx[LATTICE_DIM + 1][LATTICE_DIM + 1] =
+{
+ {1,0,0,0,0,0,0,0,0},
+ {1,1,0,0,0,0,0,0,0},
+ {1,2,1,0,0,0,0,0,0},
+ {1,3,3,1,0,0,0,0,0},
+ {1,4,6,4,1,0,0,0,0},
+ {1,5,10,10,5,1,0,0,0},
+ {1,6,15,20,15,6,1,0,0},
+ {1,7,21,35,35,21,7,1,0},
+ {1,8,28,56,70,56,28,8,1}
+};
+
const UWord32 table_no_cv[] =
{
0, 112, 240, 1360, 1376, 2400, 4192, 5536, 9120, 9376, 18336, 18448, 25616, 26640, 33808, 40528, 40752,
@@ -12170,12 +14282,21 @@ const UWord32 table_no_cv[] =
238928, 274768, 274784, 275808, 311648, 333152, 340320, 367200, 410208, 423648, 423760, 425104, 425232, 446736, 500496, 522000, 0
};
+const Word32 table_no_cv_fx[] = { 0, 112, 240, 1360, 1376, 2400, 4192, 5536, 9120, 9376, 18336, 18448, 25616, 26640, 33808, 40528, 40752,
+ 49712, 56880, 83760, 84208, 88688, 95856, 117360, 124528, 142448, 153200, 155888, 159472, 195312, 198896, 199920,
+ 235760, 236880, 238928, 274768, 274784, 275808, 311648, 333152, 340320, 367200, 410208, 423648,423760, 425104, 425232, 446736, 500496, 522000
+ ,0
+};
+
+
const int16_t pi0[] =
{
28,1,70,8,8,28,168,28,1,280,28,56,8,56,420,56, 70, 56,420, 56, 280, 56, 168, 28, 560, 168,336,28,280,28,8,
280,70, 8, 1120, 8, 8, 280, 168, 56, 420, 336, 840, 28, 168, 1, 168, 420, 168
};
+
+
const float pl_HQ[] = /* vectors in first layers */
{
1, 1, 0, 0, 0, 0, 0, 0, /* 112, 4, 28 */
@@ -12235,6 +14356,7 @@ const float pl_HQ[] = /* vectors in first layers */
const int16_t cng_sort[] = {/*5f */1,1,0,1,0,0, /* 4f */0,1,0,1,0,0,1,1,1,1};
+
const int16_t perm_MSLVQ[][4] =
{
/* 5f*/
@@ -12265,6 +14387,7 @@ const int16_t pl_par[] = /* 1 if even number of signs */
0, 0, 0, 0, -1, 1, -1, 1, 0, 0, 0, 0, 0, 1, -1, 1, -1
};
+
const float scales[][MAX_NO_SCALES*2]= /* 2 subvectors */
{
{1.528f, 0.000f, 0.000f, 1.532f, 0.000f, 0.000f, }, /* 14 */
@@ -13892,12 +16015,18 @@ const UWord8 no_lead_p_idx[][2] = {
const int16_t min_lat_bits_SN[] = {-1, -1, 17, 12, 17, 17, -1, -1, 17, 12, 17, 17, -1, -1, 22, -1, 32, 26 };
+const Word16 min_lat_bits_SN_fx[] = { -1, -1, 17, 12, 17, 17, -1, -1, 17, 12, 17, 17, -1, -1, 22, -1, 32, 26 };
+
const int16_t min_lat_bits_pred[] = {17, 18, 9, 15, -1, 21, 17, 14, 9, 15, -1, 21, 17, -1, 24, 26, -1, 26, 16};
+const Word16 min_lat_bits_pred_fx[] = { 17, 18, 9, 15, -1, 21, 17, 14, 9, 15, -1, 21, 17, -1, -1, 26, -1, 26, 16 };
+
const int16_t offset_lvq_modes_SN[] = {-1,-1,33,64,96, 129,-1,-1,12,43,79,109,-1,-1,137,-1,107,135,
112
}; /* CNG */
+const Word16 offset_lvq_modes_SN_fx[] = { -1,-1,26,51,77,96,-1,-1,12,36,66,90,-1,-1,105,-1,88,102,112 }; /* CNG */
+
const int16_t offset_lvq_modes_pred[] = {119, 153, 31, 67, -1, 102, 126, 160, 0, 46, -1, 82, 146, -1, 175, 191, -1, 225, 203};
const Word16 offset_lvq_modes_pred_fx[] = { 74, 95, 15, 45, -1, 66, 81, 102, 0, 30, -1, 60, 88, -1, 109, 117, -1, 139, 124 };
@@ -13922,6 +16051,29 @@ const int16_t offset_in_lvq_mode_SN[][21] =
{0,1}, /* T 16k */
{0}, /* A 16k */
};
+
+const Word16 offset_in_lvq_mode_SN_fx[][21] =
+{
+ {0}, /* I NB */
+ {0,1,1,1,1,1,2,3,3,3,3,4,4,4,5}, /* UV NB*/
+ {0,1,1,1,1,2,3,4,5,5,6,6,7,7,7,7,7,8,8,8,9}, /* V NB */
+ {0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G NB */
+ {0,1,1,1,1,2,3,4,5,5,5,6,6,6,7,8}, /* T NB */
+ {0,0,0,0,1,2,2,2,2,3,4,5}, /* A NB */
+ {0}, /* I WB */
+ {0,1,1,1,2,3,3,3,3,3,3,4,4,4,5}, /* UV WB*/
+ {0,1,1,1,2,3,3,3,4,5,6,7,8,9,9,10,11,12,12,12,13}, /* V WB */
+ {0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G WB */
+ {0,1,1,1,2,3,3,4,5,5,5,6,6,7,8,9,10}, /* T WB */
+ {0,0,0,0,1,2,2,2,3,4,4,4,4,4,4,4,4,4,4,5}, /* A WB */
+ {0},
+ {0},
+ {0,0,0,0,0,0,1,2,3,3,4,5,6,6,6,7}, /* V 16k */
+ {0}, /* G 16k */
+ {0,1}, /* T 16k */
+ {0}, /*{0,0,0,0,0,0,0,0,0,0,1} */ /* A 16k */
+};
+
const int16_t offset_in_lvq_mode_pred[][32] =
{
{0,0,0,0,1,2,2,2,3,4,5,5,5,5,5,5,5,5,5,6}, /* I NB */
@@ -13945,6 +16097,29 @@ const int16_t offset_in_lvq_mode_pred[][32] =
{1}, /* G WB MA*/
};
+const Word16 offset_in_lvq_mode_pred_fx[][32] =
+{
+ {0,0,0,0,1,2,2,2,3,4,5,5,5,5,5,5,5,5,5,6}, /* I NB */
+ {0,1,1,1,2,3,4,4,4,4,4,5,5,5,6}, /* UV NB */
+ {0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,3,4,4,5,6,7,8,9,10,10,11,12,13,13,13,14}, /* V NB */
+ {0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G NB */
+ {0}, /* T NB */
+ {0,0,0,0,1,2,2,2,2,3,4,5}, /* A NB */
+ {0,0,0,0,1,2,2,2,3,4,5,5,5,5,5,5,5,5,5,6}, /* I WB */
+ {0,1,1,1,2,3,4,4,4,4,4,5,5,5,6}, /* UV WB */
+ {0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,3,4,4,5,6,7,8,9,10,10,11,12,13,13,13,14}, /* V WB */
+ {0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G WB */
+ {0}, /* T WB */
+ {0,0,0,0,1,2,2,2,3,4,4,4,4,4,4,4,4,4,4,5}, /* A WB */
+ {0,0,0,0,1,2,2,2,3,4,5,5,5,5,5,5,5,5,5,6}, /* I 16k */
+ {0}, /* UV 16k */
+ {0,0,0,0,0,0,1,2,3,3,4,5,6,6,6,7}, /* V 16k */
+ {0,0,0,0,0,0,1,2,3,4,5,6}, /* G 16k */
+ {0}, /* T 16k */
+ {0,0,0,0,0,0,1,2,3,4,5,6}, /* A 16k */
+ {0,0,0,0,0,1,1,1,2,3,4,5,6,6,7,8,9,10,11,12,13,14}, /* G WB MA*/
+};
+
/*-----------------------------------------------------------------*
* BC-TCVQ frame-end quantization tables (BC-TCVQ is used in Voiced mode for 16kHz isf)
*-----------------------------------------------------------------*/
@@ -14838,6 +17013,9 @@ const float AP1_STEEP[ALLPASSSECTIONS_STEEP] =
const float AP2_STEEP[ALLPASSSECTIONS_STEEP] =
{ 0.22063024829630f, 0.63593943961708f, 0.94151583095682f };
+const Word16 AP1_STEEP_FX[ALLPASSSECTIONS_STEEP] = { 1985, 14072, 26500 }; /*Q15 Format */
+const Word16 AP2_STEEP_FX[ALLPASSSECTIONS_STEEP] = { 7230, 20838, 30852 }; /*Q15 Format */
+
const float cos_fb_exc[32] =
{
9.536743164062500e-007f,9.353497034680913e-007f,8.810801546133007e-007f,7.929511980364623e-007f,6.743495646333031e-007f,5.298330165715015e-007f,3.649553264040151e-007f,1.860525884467279e-007f,
@@ -14846,6 +17024,15 @@ const float cos_fb_exc[32] =
0.000000000000000e+000f,1.860527589769845e-007f,3.649554969342717e-007f,5.298331871017581e-007f,6.743496783201408e-007f,7.929513117233000e-007f,8.810802683001384e-007f,9.353497603115102e-007f
};
+const Word16 cos_fb_exc_fx[32] = /* Q15 */
+{
+ /*Q35*/
+ 32767, 32138, 30274, 27246, 23170, 18205, 12540, 6393,
+ 0, -6393, -12540, -18205, -23170, -27246, -30274, -32138,
+ -32768, -32138, -30274, -27246, -23170, -18205, -12540, -6393,
+ 0, 6393, 12540, 18205, 23170, 27246, 30274, 32138,
+};
+
const float recip_order[15] =
{
0.0000000f, 1.0000000f, 0.5000000f, 0.3333333f, 0.2500000f,
@@ -14867,6 +17054,19 @@ const float Hilbert_coeffs[4*NUM_HILBERTS][HILBERT_ORDER1+1] =
{ 1.0f, 0.0f, -1.10711669921875f, 0.0f, 0.15289306640625f, 0.0f} /* den_Imag[1] */
};
+const Word16 Hilbert_coeffs_fx[4 * NUM_HILBERTS][HILBERT_ORDER1 + 1] = /* Q14 */
+{
+ { 0, 14320, 0, -30699, 0, 16384}, /* num_Real[0] */
+ {11897, 0, -28240, 0, 16384, 0}, /* num_Imag[0] */
+ {16384, 0, -30699, 0, 14320, 0}, /* den_Real[0] */
+ {16384, 0, -28240, 0, 11897, 0}, /* den_Imag[0] */
+ {7671, 0, -23855, 0, 16384, 0}, /* num_Real[1] */
+ { 2505, 0, -18139, 0, 16384, 0}, /* num_Imag[1] */
+ {16384, 0, -23855, 0, 7671, 0}, /* den_Imag[1] */
+ {16384, 0, -18139, 0, 2505, 0}, /* den_Imag[1] */
+};
+
+
/* Overlap add window for SHB excitation used in analysis and synthesis */
const float window_shb[L_SHB_LAHEAD]= /* sin, 1, sin */
{
@@ -14982,7 +17182,25 @@ const float win_flatten[ L_FRAME16k/2]=
0.977164044f, 0.97999639f, 0.982644839f, 0.985108376f, 0.987386059f, 0.989477014f, 0.99138044f, 0.993095607f,
0.99462186f, 0.995958613f, 0.997105353f, 0.998061642f, 0.998827114f, 0.999401474f, 0.999784503f, 0.999976054f
};
-
+const Word16 win_flatten_fx[L_FRAME16k / 2] = /*Q15 */
+{
+ 3, 13, 28, 50, 78, 113, 154, 200, 254, 313,
+ 378, 450, 528, 611, 701, 797, 899, 1006, 1120, 1239,
+ 1365, 1496, 1632, 1775, 1923, 2076, 2235, 2400, 2569, 2745,
+ 2925, 3110, 3301, 3496, 3697, 3902, 4112, 4327, 4546, 4770,
+ 4999, 5232, 5469, 5710, 5955, 6205, 6458, 6715, 6976, 7240,
+ 7508, 7779, 8054, 8331, 8612, 8896, 9183, 9472, 9764, 10059,
+ 10356, 10655, 10956, 11260, 11566, 11873, 12182, 12493, 12805, 13119,
+ 13434, 13750, 14067, 14385, 14703, 15023, 15342, 15663, 15983, 16304,
+ 16625, 16945, 17265, 17586, 17905, 18224, 18542, 18860, 19176, 19492,
+ 19806, 20119, 20431, 20741, 21049, 21355, 21660, 21963, 22263, 22561,
+ 22857, 23150, 23441, 23729, 24014, 24297, 24576, 24852, 25125, 25395,
+ 25661, 25923, 26182, 26437, 26689, 26936, 27179, 27418, 27653, 27884,
+ 28110, 28332, 28549, 28761, 28969, 29172, 29370, 29563, 29751, 29934,
+ 30112, 30284, 30451, 30613, 30769, 30920, 31065, 31205, 31338, 31467,
+ 31589, 31705, 31816, 31921, 32020, 32113, 32199, 32280, 32355, 32423,
+ 32486, 32542, 32592, 32636, 32673, 32704, 32730, 32748, 32761, 32767
+};
const float win_flatten_4k[ L_FRAME16k/8]=
{
0.000385482f, 0.003465772f, 0.00960736f, 0.018772382f, 0.030904332f, 0.045928413f, 0.063751996f, 0.084265194f,
@@ -14991,7 +17209,14 @@ const float win_flatten_4k[ L_FRAME16k/8]=
0.673058529f, 0.709329869f, 0.744310621f, 0.777785117f, 0.809546975f, 0.839400373f, 0.867161255f, 0.892658465f,
0.915734806f, 0.936248004f, 0.954071587f, 0.969095668f, 0.981227618f, 0.99039264f, 0.996534228f, 0.999614518f
};
-
+const Word16 win_flatten_4k_fx[L_FRAME16k / 8] = /*Q15 */
+{
+ 13, 114, 315, 615, 1013, 1505, 2089, 2761,
+ 3517, 4353, 5263, 6241, 7282, 8378, 9525, 10713,
+ 11937, 13188, 14458, 15741, 17027, 18310, 19580, 20831,
+ 22055, 23243, 24390, 25486, 26527, 27505, 28415, 29251,
+ 30007, 30679, 31263, 31755, 32153, 32453, 32654, 32755
+};
const float wb_bwe_lsfvq_cbook_8bit[256*6] =
{
0.064311408f, 0.10468847f, 0.15634165f, 0.20375369f, 0.28696818f, 0.40275119f,
@@ -15653,6 +17878,16 @@ const float full_band_bpf_1[6][5] =
{ 1.0000000000000E+00f, 2.5823882989829E+00f, 3.2419903202957E+00f, 2.1041782509434E+00f, 6.8348510539492E-01f}
};
+const Word16 full_band_bpf_1_fx[6][5] = /*in Q13*/
+{
+ { 789, 802, 248, 802, 789},
+ { 789, 1199, 838, 1199, 789},
+ { 789, 136, -1123, 136, 789},
+ { 8192, 19654, 24391, 17059, 6561},
+ { 8192, 15339, 20118, 13819, 6190},
+ { 8192, 21155, 26558, 17237, 5599}
+};
+
/* 12th order elliptic Bandpass filter at 16.3 to 19.8 kHz sampled at 48 kHz b0,b1,b2,a0,a1,a2 */
const float full_band_bpf_2[6][5] =
{
@@ -15664,6 +17899,16 @@ const float full_band_bpf_2[6][5] =
{ 1.0000000000000E+00f, 2.8681737877693E+00f, 3.8085295994769E+00f, 2.5421873471575E+00f, 7.9182537841461E-01f}
};
+const Word16 full_band_bpf_2_fx[6][5] = /*in Q13*/
+{
+ { 492, 912, 974, 912, 492},
+ { 492, 1161, 1353, 1161, 492},
+ { 492, 259, -311, 259, 492},
+ { 8192, 22912, 30622, 21214, 7143},
+ { 8192, 20364, 27329, 18844, 6886},
+ { 8192, 23496, 31199, 20826, 6487}
+};
+
/* 12th order elliptic Bandpass filter at 15.4 to 20.0 kHz sampled at 48 kHz b0,b1,b2,a0,a1,a2 */
const float full_band_bpf_3[6][5] =
{
@@ -15675,6 +17920,15 @@ const float full_band_bpf_3[6][5] =
{1.0000000000000E+00f, 2.7689100300130E+00f, 3.5940097427365E+00f, 2.3681560760262E+00f, 7.4233948915492E-01f}
};
+const Word16 full_band_bpf_3_fx[6][5] = /*in Q13*/
+{
+ {611, 888, 717, 888, 611},
+ {611, 1211, 1214, 1211, 611},
+ {611, 197, -671, 197, 611},
+ {8192, 21727, 28230, 19588, 6871},
+ {8192, 18438, 24377, 16796, 6567},
+ {8192, 22683, 29442, 19400, 6081}
+};
/* 4-bit/3-bit TD SWB BWE differential LSF scalar quantizer tables */
const float lsf_q_cb_4b[16] =
@@ -15708,7 +17962,7 @@ const float lsf_grid[4][5] =
const float grid_smoothing[5] = { 0.2f, 0.35f, 0.5f, 0.75f, 0.8f };
-const float allpass_poles_3_ov_2[9] =
+const float allpass_poles_3_ov_2_flt[9] =
{
0.072265625000000f,
0.626983642578125f,
@@ -15721,6 +17975,18 @@ const float allpass_poles_3_ov_2[9] =
0.990966796875000f
};
+const Word16 allpass_poles_3_ov_2[9] = /* Q15 */
+{
+ 2368,
+ 20545,
+ 30606,
+ 25520,
+ 7188,
+ 31808,
+ 28575,
+ 14384,
+ 32472
+};
const float decimate_3_ov_2_lowpass_num[3] =
{
0.195271809895833f,
@@ -15782,6 +18048,13 @@ const float F_2_5[64] =
const int16_t swb_bwe_trans_subband[SWB_FENV_TRANS+1] = {240, 316, 392, 476, 560};
const int16_t swb_bwe_trans_subband_width[SWB_FENV_TRANS] = {76, 76, 84, 84};
+
+const Word16 sqrt_swb_bwe_trans_subband_width_fx[SWB_FENV_TRANS] = { 17854, 17854, 18770, 18770 };/*Q11 */
+
+const Word16 sqrt_swb_bwe_subband_fx_L1[SWB_FENV] = { 16384, 20066, 16384, 20066, 16384, 20066, 16384, 20066, 20066, 20066, 20066, 20066, 23170, 23170 }; /*Q12 */
+
+const Word16 sqrt_swb_bwe_subband_fx_L2[SWB_FENV / 2] = { 25905, 25905, 25905, 25905, 28378, 28378, 32767 }; /*Q12 */
+
const int16_t swb_bwe_subband[SWB_FENV+1] = {240, 256, 280, 296, 320, 336, 360, 376, 400, 424, 448, 472, 496, 528, 560};
const Word16 fb_bwe_subband[DIM_FB + 1] = { 640, 680, 720, 800 };
const Word16 fb_bwe_sm_subband[DIM_FB] = { 656, 696, 760 };
@@ -16393,6 +18666,9 @@ const int16_t subband_search_offsets[NB_SWB_SUBBANDS] =
{
0, 0, 64, 64
};
+
+
+
/* SPT : shorten subband length table */
const Word16 bw_SPT_tbl[2][SPT_SHORTEN_SBNUM]=
{
@@ -16404,6 +18680,7 @@ const Word16 bw_SPT_tbl[2][SPT_SHORTEN_SBNUM]=
/* Harmonic Mode */
const int16_t bits_lagIndices_mode0_Har[NB_SWB_SUBBANDS_HAR_SEARCH_SB] = {1,1};
+
/* 13.2 kbps */
const int16_t subband_offsets_sub5_13p2kbps_Har[NB_SWB_SUBBANDS_HAR] =
{
@@ -17528,6 +19805,22 @@ const float finegain_3[8] = {-1.0000000f, -0.7142857f, -0.4285714f, -0.1428571f,
const float finegain_4[16] = {-1.3234321f, -1.1164439f, -0.9153915f, -0.7248241f, -0.5453916f, -0.3807825f, -0.2259278f, -0.0836715f, 0.0576803f, 0.1999166f, 0.3715899f, 0.5541582f, 0.7598588f, 0.9764980f, 1.2082281f, 1.4567725f};
const float finegain_5[32] = {-1.3099370f, -1.1532731f, -0.9939113f, -0.8627403f, -0.7693628f, -0.6901322f, -0.6188556f, -0.5438313f, -0.4899869f, -0.4145289f, -0.3440915f, -0.2936875f, -0.2241453f, -0.1636186f, -0.1052746f, -0.0292431f, 0.0273763f, 0.0848355f, 0.1443042f, 0.2095194f, 0.2794882f, 0.3366661f, 0.4131591f, 0.4740591f, 0.5545165f, 0.6196313f, 0.6719442f, 0.7650533f, 0.9012053f, 1.0432675f, 1.2264170f, 1.5085750f};
const float * const finegain[5] = { finegain_1, finegain_2, finegain_3, finegain_4, finegain_5 };
+const Word16 finegain_1_fx[2] = { -12204, 12647 }; /* Q14 */
+const Word16 finegain_2_fx[4] = { -17773, -5925, 6010, 18769 }; /* Q14 */
+const Word16 finegain_3_fx[8] = { -16384, -11703, -7022, -2341, 2341, 7022, 11703, 16384 }; /* Q14 */
+const Word16 finegain_4_fx[16] = /* Q14 */
+{
+ -21683, -18292, -14998, -11876, -8936, -6239, -3702, -1371,
+ 945, 3275, 6088, 9079, 12450, 15999, 19796, 23868
+};
+const Word16 finegain_5_fx[32] = /* Q14 */
+{
+ -21462, -18895, -16284, -14135, -12605, -11307, -10139, -8910,
+ -8028, -6792, -5638, -4812, -3672, -2681, -1725, -479,
+ 449, 1390, 2364, 3433, 4579, 5516, 6769, 7767,
+ 9085, 10152, 11009, 12535, 14765, 17093, 20094, 24716
+};
+const Word16* finegain_fx[5] = { finegain_1_fx, finegain_2_fx, finegain_3_fx, finegain_4_fx, finegain_5_fx };
const uint8_t hBitsMinus1_N01[2] = {1, 7};
@@ -21126,6 +23419,44 @@ const float UVG1CB_WB[UVG1_CBSIZE][2] =
{ 3.185808f, 3.172863f, },
};
+/* NELP gain tables */
+
+const Word16 UVG1CB_WB_FX[UVG1_CBSIZE][2] = /* Q13 */
+{
+ { -2224, -2114, },
+ { 12666, 12314, },
+ { 3723, 9690, },
+ { 17880, 17978, },
+ { 4136, 3946, },
+ { 11605, 21280, },
+ { 9777, 9340, },
+ { 21701, 21627, },
+ { 1088, 1679, },
+ { 13993, 13697, },
+ { 10443, 5214, },
+ { 19702, 19692, },
+ { 5458, 5317, },
+ { 17051, 16918, },
+ { 14206, 8503, },
+ { 24330, 24271, },
+ { -118, -279, },
+ { 11615, 14863, },
+ { 6898, 6544, },
+ { 18913, 18637, },
+ { 1142, 6811, },
+ { 15995, 16070, },
+ { 6921, 13182, },
+ { 22857, 22741, },
+ { 3017, 2260, },
+ { 14952, 14992, },
+ { 8176, 8093, },
+ { 20721, 20549, },
+ { 7441, 2370, },
+ { 17897, 13988, },
+ { 10986, 10966, },
+ { 26098, 25992, },
+};
+
const float UVG1CB_NB[UVG1_CBSIZE][2] =
{
{ -0.584898f, -0.629564f, },
@@ -21162,6 +23493,42 @@ const float UVG1CB_NB[UVG1_CBSIZE][2] =
{ 2.297758f, 2.282144f, },
};
+const Word16 UVG1CB_NB_FX[UVG1_CBSIZE][2] = /* Q13 */
+{
+ { -4791, -5157, },
+ { 4824, 4937, },
+ { -3443, 3610, },
+ { 5539, 15293, },
+ { -469, -3986, },
+ { 7977, 8157, },
+ { 2748, 2492, },
+ { 14070, 14014, },
+ { -2486, -2863, },
+ { 6033, 5892, },
+ { 2678, -441, },
+ { 11741, 11804, },
+ { -256, -847, },
+ { 9153, 8922, },
+ { -106, 5979, },
+ { 16876, 16741, },
+ { -3584, -3873, },
+ { 3511, 9538, },
+ { 401, 416, },
+ { 11082, 10550, },
+ { -1418, -1725, },
+ { 8988, 5255, },
+ { 6275, 1137, },
+ { 15372, 15247, },
+ { -3899, 301, },
+ { 6976, 7095, },
+ { 1581, 1453, },
+ { 12988, 12824, },
+ { 2692, -3093, },
+ { 9778, 10153, },
+ { 3938, 3628, },
+ { 18823, 18695, },
+};
+
const float UVG2CB1_WB[UVG2_CBSIZE][5] =
{
{ 0.223040f, 0.241651f, 0.363680f, 1.453550f, 0.639043f, },
@@ -21230,6 +23597,74 @@ const float UVG2CB1_WB[UVG2_CBSIZE][5] =
{ 7.419703f, 4.514918f, 3.368681f, 1.171582f, 0.557291f, },
};
+const Word16 UVG2CB1_WB_FX[UVG2_CBSIZE][5] = /* Q12 */
+{
+ { 914, 990, 1490, 5954, 2618, },
+ { 5599, 4621, 4078, 3493, 3057, },
+ { 4930, 4031, 2999, 2150, 1706, },
+ { 7722, 3021, 1804, 1478, 1452, },
+ { 1171, 1390, 6895, 2592, 1486, },
+ { 4155, 4287, 4409, 4515, 4577, },
+ { 3633, 3661, 3694, 3711, 3736, },
+ { 13212, 5009, 2611, 2175, 2048, },
+ { 3716, 2887, 2253, 1965, 1723, },
+ { 7141, 4567, 3434, 2970, 2396, },
+ { 2856, 3038, 3259, 3481, 3709, },
+ { 5929, 5459, 4923, 4448, 4084, },
+ { 980, 1024, 1550, 5686, 8038, },
+ { 3516, 7354, 10392, 3619, 2856, },
+ { 2598, 3093, 3582, 4780, 5965, },
+ { 1962, 10993, 5020, 2861, 2587, },
+ { 796, 916, 1010, 1175, 7720, },
+ { 4445, 4406, 4344, 4249, 4175, },
+ { 1454, 6493, 2611, 1758, 1765, },
+ { 6296, 7686, 4763, 2945, 2203, },
+ { 1502, 1573, 1895, 2981, 5464, },
+ { 4750, 4829, 4909, 4929, 4895, },
+ { 3644, 3774, 3922, 4037, 4116, },
+ { 9051, 7403, 6003, 4746, 4081, },
+ { 1558, 1869, 2331, 3000, 3595, },
+ { 4671, 4646, 4614, 4553, 4482, },
+ { 2262, 2608, 3158, 3890, 4468, },
+ { 5556, 5441, 6824, 7146, 5724, },
+ { 1470, 1550, 2016, 11169, 3828, },
+ { 5488, 6270, 6771, 8202, 9281, },
+ { 3477, 3693, 4113, 4460, 4705, },
+ { 10877, 17984, 10194, 7291, 2824, },
+ { 1327, 1498, 1476, 1667, 2138, },
+ { 4463, 4299, 4094, 3880, 3731, },
+ { 3188, 3164, 3156, 3104, 3140, },
+ { 9757, 5690, 3366, 2296, 1792, },
+ { 1731, 1753, 12406, 4082, 2247, },
+ { 3866, 4060, 5007, 5274, 5225, },
+ { 3998, 3957, 3900, 3839, 3789, },
+ { 18040, 9417, 5567, 3465, 2504, },
+ { 2160, 2532, 2895, 2577, 2321, },
+ { 5052, 4789, 4490, 4203, 3953, },
+ { 3381, 3415, 3458, 3496, 3536, },
+ { 6166, 5811, 5440, 5035, 4650, },
+ { 2839, 3389, 5057, 7558, 10414, },
+ { 3875, 4431, 5183, 6310, 7166, },
+ { 4311, 4130, 3571, 3070, 8555, },
+ { 8791, 8260, 7299, 6243, 5421, },
+ { 1191, 1237, 1368, 1814, 11819, },
+ { 2486, 5729, 6150, 4222, 3667, },
+ { 4018, 3825, 3600, 3388, 3256, },
+ { 7504, 5817, 4989, 4065, 3322, },
+ { 1430, 1962, 5546, 4096, 4681, },
+ { 5393, 5378, 5324, 5230, 5052, },
+ { 4041, 4090, 4132, 4159, 4181, },
+ { 12469, 9221, 5735, 3617, 2501, },
+ { 2482, 2565, 2768, 3088, 3461, },
+ { 5209, 5080, 4905, 4706, 4522, },
+ { 3139, 3362, 3647, 3910, 4156, },
+ { 7139, 6588, 5941, 5251, 4674, },
+ { 1719, 1866, 7993, 7634, 3987, },
+ { 3587, 5289, 7882, 13519, 16095, },
+ { 2409, 2515, 2749, 7316, 4636, },
+ { 30391, 18493, 13798, 4799, 2283, },
+};
+
const float UVG2CB2_WB[UVG2_CBSIZE][5] =
{
{ 0.382157f, 0.339570f, 0.399108f, 1.276274f, 0.654653f, },
@@ -21298,6 +23733,74 @@ const float UVG2CB2_WB[UVG2_CBSIZE][5] =
{ 0.296171f, 0.760591f, 1.599661f, 5.561118f, 5.121441f, },
};
+const Word16 UVG2CB2_WB_FX[UVG2_CBSIZE][5] = /* Q12 */
+{
+ { 1565, 1391, 1635, 5228, 2681, },
+ { 2156, 2558, 6205, 5561, 3944, },
+ { 2039, 2406, 3094, 3409, 3968, },
+ { 5090, 5065, 4989, 4858, 4764, },
+ { 1436, 1736, 2816, 2362, 2400, },
+ { 4375, 4425, 4465, 4478, 4493, },
+ { 4648, 4081, 3550, 2981, 2667, },
+ { 1705, 1950, 3679, 7828, 9895, },
+ { 2839, 1826, 1443, 1210, 1245, },
+ { 1387, 1410, 1768, 8873, 4383, },
+ { 4022, 3784, 3565, 3316, 3096, },
+ { 9983, 7147, 5225, 3742, 3027, },
+ { 6769, 2357, 1531, 1448, 1556, },
+ { 4591, 4671, 4735, 4765, 4789, },
+ { 4308, 4198, 4052, 3896, 3769, },
+ { 2288, 2550, 4922, 8294, 14878, },
+ { 1361, 1480, 1511, 1991, 10450, },
+ { 2933, 3131, 3694, 4687, 5201, },
+ { 3984, 3048, 2479, 2644, 5514, },
+ { 5353, 5480, 5488, 5434, 5437, },
+ { 3319, 2881, 2528, 2152, 1927, },
+ { 4873, 4748, 4578, 4407, 4257, },
+ { 6185, 4396, 3751, 3400, 2899, },
+ { 2159, 8067, 7534, 5121, 3640, },
+ { 2265, 10177, 3803, 2588, 2441, },
+ { 2188, 2206, 4293, 12691, 5893, },
+ { 3587, 3651, 3760, 3864, 3960, },
+ { 13158, 9752, 7171, 5431, 5364, },
+ { 5710, 4173, 2928, 2090, 1774, },
+ { 3531, 3831, 4641, 5787, 6622, },
+ { 4395, 4356, 4281, 4194, 4111, },
+ { 2243, 2476, 5814, 3965, 27176, },
+ { 1575, 1667, 7544, 3005, 1984, },
+ { 2583, 2511, 11684, 5765, 4807, },
+ { 3632, 3458, 3277, 3114, 2971, },
+ { 8569, 6778, 5866, 5515, 5141, },
+ { 3267, 3035, 2940, 2782, 2691, },
+ { 3929, 4249, 4577, 4877, 5162, },
+ { 4443, 4173, 3864, 3590, 3337, },
+ { 3998, 4725, 5728, 6873, 7885, },
+ { 4369, 2824, 2237, 1648, 1404, },
+ { 1000, 1022, 1477, 2682, 15276, },
+ { 3916, 3851, 3766, 3664, 3591, },
+ { 13206, 4485, 3230, 3897, 3648, },
+ { 10002, 3515, 2393, 2233, 2211, },
+ { 4603, 4836, 5071, 5259, 5411, },
+ { 3919, 4035, 4177, 4304, 4419, },
+ { 3046, 8332, 16475, 11172, 10858, },
+ { 1027, 1007, 1196, 1578, 5937, },
+ { 1892, 2422, 3227, 3920, 7400, },
+ { 3584, 3532, 3508, 3470, 3437, },
+ { 5363, 6155, 6805, 6854, 6811, },
+ { 4038, 3512, 3030, 2636, 2332, },
+ { 6760, 6124, 5235, 4299, 3687, },
+ { 4125, 6528, 4068, 3238, 3483, },
+ { 5020, 5905, 7082, 8554, 9623, },
+ { 1399, 5868, 3069, 1726, 1655, },
+ { 4691, 4234, 3974, 3757, 9616, },
+ { 3978, 4003, 4003, 3983, 3960, },
+ { 2103, 16858, 9252, 4860, 4727, },
+ { 8043, 5294, 3970, 3098, 2583, },
+ { 4680, 5109, 5576, 5965, 6275, },
+ { 4867, 4584, 4276, 3958, 3682, },
+ { 1213, 3115, 6552, 22778, 20977, },
+};
+
const float UVG2CB1_NB[UVG2_CBSIZE][5] =
{
@@ -21367,6 +23870,74 @@ const float UVG2CB1_NB[UVG2_CBSIZE][5] =
{ 3.747086f, 2.672835f, 1.889530f, 1.215477f, 0.841197f, },
};
+const Word16 UVG2CB1_NB_FX[UVG2_CBSIZE][5] = /* Q12 */
+{
+ { 773, 785, 785, 785, 860, },
+ { 3560, 3521, 3410, 3265, 3167, },
+ { 1766, 2982, 10273, 3790, 2248, },
+ { 4986, 4753, 4496, 4172, 3922, },
+ { 2036, 2030, 2009, 1973, 1897, },
+ { 3291, 3554, 3868, 4126, 4345, },
+ { 3207, 3122, 3026, 2913, 2797, },
+ { 13220, 6844, 3967, 2746, 2466, },
+ { 1553, 1627, 1392, 1766, 3679, },
+ { 5379, 4640, 3844, 3254, 2635, },
+ { 1600, 1622, 2430, 9446, 4214, },
+ { 5115, 5200, 5311, 5365, 5343, },
+ { 6229, 3008, 1989, 1622, 1597, },
+ { 1726, 2114, 7046, 6162, 4301, },
+ { 1004, 1056, 1841, 6006, 7101, },
+ { 6388, 9659, 4510, 2774, 2113, },
+ { 1060, 1153, 1400, 1733, 2121, },
+ { 3448, 3523, 3612, 3683, 3770, },
+ { 1496, 2045, 2910, 3563, 4058, },
+ { 4419, 4592, 4795, 4921, 4978, },
+ { 1407, 5314, 2788, 1675, 1350, },
+ { 4210, 4225, 4227, 4186, 4169, },
+ { 2247, 8245, 4392, 2522, 1709, },
+ { 7211, 6741, 6110, 5397, 4680, },
+ { 3602, 2286, 1577, 1229, 1148, },
+ { 6674, 5227, 3576, 2448, 1901, },
+ { 954, 1035, 1079, 1683, 9558, },
+ { 4011, 5853, 8979, 7138, 4484, },
+ { 2784, 2702, 2637, 2546, 2471, },
+ { 4414, 4065, 4627, 4208, 9275, },
+ { 2771, 3012, 3357, 3735, 4066, },
+ { 19742, 8603, 3943, 2546, 2085, },
+ { 1132, 1123, 1107, 1093, 1114, },
+ { 3913, 3838, 3733, 3630, 3548, },
+ { 948, 1565, 6063, 2654, 1667, },
+ { 6159, 5567, 4884, 4241, 3770, },
+ { 925, 1164, 1585, 6062, 3090, },
+ { 3818, 4037, 4322, 4536, 4726, },
+ { 4291, 3894, 3441, 3006, 2733, },
+ { 8544, 6487, 4962, 3812, 2970, },
+ { 1744, 1758, 1704, 1633, 1576, },
+ { 4416, 4259, 4044, 3810, 3628, },
+ { 1919, 2159, 3323, 13977, 7898, },
+ { 5952, 5731, 5419, 5061, 4732, },
+ { 2775, 2812, 2507, 2540, 6585, },
+ { 3436, 3960, 4661, 5975, 6274, },
+ { 3082, 3150, 3246, 3337, 3404, },
+ { 4089, 16018, 8285, 4116, 2704, },
+ { 1419, 1425, 1400, 1371, 1363, },
+ { 3825, 3890, 3953, 3993, 4015, },
+ { 2498, 2689, 2846, 3011, 3213, },
+ { 5122, 5024, 4881, 4691, 4524, },
+ { 2285, 2325, 2317, 2313, 2271, },
+ { 4493, 4529, 4517, 4478, 4443, },
+ { 9138, 3969, 2522, 2222, 2415, },
+ { 10009, 8719, 7292, 5837, 4532, },
+ { 831, 908, 1039, 1656, 6813, },
+ { 2070, 5478, 5174, 3911, 3694, },
+ { 1577, 1565, 1635, 2583, 13154, },
+ { 5590, 5788, 5922, 6752, 7063, },
+ { 4061, 3497, 2710, 2099, 1716, },
+ { 2750, 3118, 16574, 7891, 3651, },
+ { 2598, 3072, 3809, 4906, 5172, },
+ { 15348, 10948, 7740, 4979, 3446, },
+};
+
const float UVG2CB2_NB[UVG2_CBSIZE][5]=
{
{ 0.234676f, 0.211553f, 0.198300f, 0.188137f, 0.189102f, },
@@ -21435,6 +24006,74 @@ const float UVG2CB2_NB[UVG2_CBSIZE][5]=
{ 2.340990f, 6.501577f, 3.762808f, 3.059604f, 2.127793f, },
};
+const Word16 UVG2CB2_NB_FX[UVG2_CBSIZE][5] = /* Q12 */
+{
+ { 961, 867, 812, 771, 775, },
+ { 2544, 2686, 3010, 3605, 5048, },
+ { 1524, 1818, 2889, 3029, 3046, },
+ { 4195, 4301, 4421, 4497, 4580, },
+ { 2026, 1990, 1965, 1943, 1939, },
+ { 4338, 4156, 3963, 3750, 3590, },
+ { 7732, 2904, 1804, 1407, 1513, },
+ { 1613, 2353, 11315, 5764, 4291, },
+ { 1519, 1462, 1434, 1341, 1294, },
+ { 1627, 1710, 2163, 9654, 5615, },
+ { 2322, 7293, 3251, 2020, 2066, },
+ { 4967, 5112, 5174, 5203, 5230, },
+ { 1590, 1449, 1943, 5947, 3563, },
+ { 7747, 5170, 3268, 2392, 2082, },
+ { 3970, 3559, 3164, 2774, 2493, },
+ { 1993, 2210, 3204, 3717, 23534, },
+ { 1185, 1236, 1423, 2115, 4772, },
+ { 3935, 3840, 3714, 3583, 3477, },
+ { 1640, 1550, 1800, 2609, 10880, },
+ { 4067, 4437, 4811, 5108, 5536, },
+ { 1472, 1367, 1533, 2132, 7352, },
+ { 4310, 4284, 4216, 4117, 4057, },
+ { 10817, 4587, 2611, 2066, 2037, },
+ { 2089, 2427, 4698, 14635, 7517, },
+ { 2529, 1561, 1209, 976, 945, },
+ { 2908, 3070, 4055, 5862, 6448, },
+ { 2676, 2861, 3115, 3295, 3408, },
+ { 2932, 14330, 6533, 3739, 3462, },
+ { 3681, 3079, 2559, 2151, 1903, },
+ { 5636, 5316, 4978, 4690, 4425, },
+ { 2298, 7228, 6976, 4251, 3347, },
+ { 2504, 3421, 6784, 8483, 15064, },
+ { 1253, 1180, 1136, 1094, 1076, },
+ { 3451, 3524, 3600, 3646, 3707, },
+ { 1701, 2030, 6574, 4746, 4451, },
+ { 4688, 4751, 4762, 4727, 4722, },
+ { 2977, 2363, 1883, 1563, 1399, },
+ { 5080, 4685, 4275, 3835, 3513, },
+ { 5445, 3828, 2851, 2242, 1948, },
+ { 1929, 5037, 17760, 8346, 6300, },
+ { 1839, 1782, 1680, 1586, 1534, },
+ { 3086, 3472, 4031, 4950, 9695, },
+ { 3199, 3052, 2896, 2751, 2622, },
+ { 5822, 5782, 5727, 5566, 5478, },
+ { 1548, 2234, 6748, 2562, 1722, },
+ { 6699, 5216, 4475, 3531, 3028, },
+ { 3773, 3628, 3460, 3279, 3155, },
+ { 1581, 1672, 2929, 20221, 16432, },
+ { 1210, 1215, 1389, 1678, 2177, },
+ { 3863, 3886, 3937, 3961, 3989, },
+ { 1541, 1745, 1829, 3479, 15563, },
+ { 4444, 4952, 5573, 6056, 6545, },
+ { 2460, 2397, 2284, 2133, 2041, },
+ { 4808, 4676, 4493, 4322, 4213, },
+ { 15031, 6644, 3315, 2900, 2885, },
+ { 4003, 4760, 6946, 8274, 8401, },
+ { 5001, 2495, 1594, 1337, 1365, },
+ { 3428, 3706, 4073, 4457, 4670, },
+ { 3326, 3277, 3222, 3142, 3088, },
+ { 6162, 6317, 6494, 6459, 6530, },
+ { 2659, 2599, 2537, 2482, 2546, },
+ { 8554, 6902, 5233, 4116, 3650, },
+ { 4643, 4099, 3616, 3201, 2895, },
+ { 9589, 26630, 15412, 12532, 8715, },
+};
+
const float frac_4sf[NB_SUBFR+2] = {0.25f,0.5f,0.75f,1.0f,1.0f,1.0f};
/* ERB table for PPP-ampl-quant */
@@ -21449,6 +24088,12 @@ const float erb_NB[NUM_ERB_NB+1] = {0.0f, 92.8061f, 185.6121f, 278.4182f, 371.22
3733.7f, 4000.0f+1.0f
};
+/* ERB table for PPP-ampl-quant */
+const Word16 erb_WB_fx[NUM_ERB_WB + 1] = { 0, 238, 475, 713, 950, 1188, 1426, 1663, 1911, 2185, 2490, 2826, 3205, 3624, 4094, 4620, 5210, 5875, 6626, 7478, 8448, 9558, 11264, 13568, 16387 };
+
+
+/* ERB table for PPP-ampl-quant */
+const Word16 erb_NB_fx[NUM_ERB_NB + 1] = { 0, 238, 475, 713, 950, 1188, 1426, 1663, 1911, 2185, 2490, 2826, 3205, 3624, 4094, 4620, 5210, 5875, 6626, 7478, 8448, 9558, 10243 };
@@ -21523,6 +24168,74 @@ const float AmpCB1_WB[64][10] =
{ -0.6131592f, -0.7923584f, 0.2189941f, 0.3343506f, 0.1785889f, 0.7132568f, 0.3502197f, 0.2432861f, -0.1719971f, 0.5898438f, },
};
+const Word16 AmpCB1_WB_fx[640] =
+{
+ 5655, 1589, -653, 3568, -3173, -1852, -3204, -4623, -2100, -5103,
+ -923, -67, -7152, -4958, -2019, -1810, -8532, -648, 6581, 8043,
+ 160, 778, -1535, 863, 5482, 1674, -3576, 123, -3163, -3595,
+ -852, -53, -1080, -2683, -3199, -950, -1353, 6258, -1431, 1249,
+ 2059, 677, 146, 1011, 956, -2022, -25, 300, 421, -5859,
+ 1027, -452, -7343, -1052, 3818, 1099, -1005, 659, -511, -658,
+ 2091, 720, -600, 145, -1504, -1716, -442, -2172, -1505, 2702,
+ 731, 1473, -213, -4120, -2976, 688, 3205, 1213, 679, 232,
+ 3672, 4770, -1198, -298, -1714, -3669, -2833, -664, -1859, -2380,
+ -1169, -1593, -453, 295, -1225, -3110, -1776, 2112, 2710, 3333,
+ 1022, 1248, 1091, 1164, 1200, 1782, -809, -2306, -3124, -2194,
+ -1567, 465, 2223, -1301, -463, -2157, 729, 2279, -1938, 610,
+ 437, -803, -1025, 775, -171, -637, 163, 2251, 316, -1663,
+ -4123, -20, -2827, -1529, -1436, 3447, 79, -274, 1650, 4097,
+ 2369, 927, 448, -449, 293, -239, -1028, -4805, 1354, 431,
+ -2219, -490, -3849, 1639, -2925, 817, 1485, 2527, 5444, -1994,
+ 1476, 506, -1643, 2003, -1676, -788, -1681, -2011, 1389, 452,
+ 593, 3, -1200, -3987, -1634, -4310, -686, 882, 6235, 2420,
+ -196, -1257, -2038, -498, 1394, 671, -2302, -809, -446, 3644,
+ -1643, -2304, -828, 105, -323, -3906, -960, 7324, 3095, -786,
+ 95, 633, 1266, 750, 1509, -2033, -3134, 432, 1028, -1825,
+ 1258, 256, -3249, -6868, -523, -325, -1779, 4313, 2524, 3433,
+ -600, -410, -88, 410, -1182, -1140, -1448, -1344, -5074, 6054,
+ 2194, 1505, -681, -2408, 1376, 1389, 1209, 1048, -4199, -2939,
+ 1855, 1744, -1344, -1431, -1955, -1805, -4992, 512, 624, 2749,
+ -3446, -1215, -3764, -2169, -3601, -1321, 67, 4326, 6624, 5816,
+ -334, -1746, -441, -754, 1853, 3889, -595, -493, 441, -811,
+ -48, -764, -1473, -683, 603, -1754, 780, 698, 1084, 1713,
+ 560, -808, -754, -2890, -1205, -318, -1021, 3195, 5693, -4603,
+ 1343, -1061, -2441, -1784, 721, 267, 227, -622, 3013, -768,
+ -472, 90, 13, 290, 1055, 948, 1617, -2368, -1087, 1103,
+ -4784, -3872, 5125, -2518, -215, 6962, 1095, -1521, 2091, -2962,
+ 2285, 1117, 1174, 2635, -1907, -1012, 814, -417, -2162, -2805,
+ -1188, -707, -808, -1757, 260, -1093, -3957, -3266, 4132, 5980,
+ 177, -1478, 960, 2029, 3989, 597, -3062, -3940, -1688, 236,
+ -1559, 150, 2432, 348, -242, -2014, -1027, 6298, -2957, -3960,
+ 1090, 1014, -1261, -744, -954, -938, -3713, -3272, 5356, -2356,
+ -1439, 3808, -2330, -4437, 5177, -3606, -1382, 1824, 407, 325,
+ 649, 330, 85, 206, -415, 183, -646, 602, -2656, 808,
+ 1039, 29, -3202, -6168, -3640, 3736, 4183, 3959, 330, 339,
+ 2701, 343, 1501, 1879, -3194, -4648, -1630, 1656, -1578, -84,
+ -3065, -4126, 24, -260, 263, -1705, -1289, 2432, 1229, 7481,
+ 2586, 1696, 646, -1773, -792, 1932, -1908, -1897, -1129, 112,
+ -5667, -1592, 2253, -980, 1581, 211, 5277, 4846, -288, -159,
+ 956, 1196, 771, -973, -1785, -516, -1015, 847, 614, -791,
+ -442, -1594, -4632, -4392, -416, 1398, 2570, 752, 264, 6570,
+ 1655, 546, 1238, -1362, -1330, -2005, 3590, -2155, -184, -1224,
+ -1452, -1533, -534, 1010, -1707, 801, 3628, -289, 2414, 132,
+ 2643, -2813, -4524, 5092, -7362, 740, 428, -510, 81, -1209,
+ 616, 1454, 1861, -3958, -4084, 189, -1219, -875, 3764, 2086,
+ -1554, -2071, 1515, 3392, 12, -686, -2414, -1382, 176, 1685,
+ 2055, -5698, 1582, 4117, -4846, -2922, 610, 2082, 4682, -2487,
+ 348, 2258, -338, -1379, 1472, 618, -202, -1122, -76, -2468,
+ -1216, -986, -327, -1441, 102, 403, -2105, 2411, 1510, 1288,
+ -715, -577, 1074, 2533, -3521, -3449, 2140, -751, -307, 3805,
+ 158, -1385, -404, -1378, -1948, 3785, 4216, 2667, -1894, -1559,
+ 1037, 1371, 989, -205, -333, -4784, -3429, -1283, 3299, 859,
+ -4922, -5481, -1196, -1748, -720, 516, 113, 4590, 7071, 4345,
+ -5729, -3862, 3590, 1463, 7094, 4991, 854, -66, -1630, -686,
+ -923, -3266, -1988, 2345, 785, -1420, 3004, 2934, -1245, -65,
+ -2696, -3088, -1438, 614, 1584, -239, -1552, 580, 6285, -1673,
+ -1598, -4018, -1909, 747, 3191, 366, 1467, -1933, 2759, 2804,
+ 518, 193, -1149, -3108, 441, 1458, 2791, -4131, 2694, 3372,
+ -5023, -6491, 1794, 2739, 1463, 5843, 2869, 1993, -1409, 4832
+};
+
const float AmpCB2_WB[64][NUM_ERB_WB-11] =
{
{ -0.6440430f, -0.9412842f, -0.4294434f, -0.2949219f, -0.0466309f, 0.0389404f, -0.2319336f, -0.1098633f, 0.2105713f, 0.1079102f, 0.4969482f, },
@@ -21591,6 +24304,81 @@ const float AmpCB2_WB[64][NUM_ERB_WB-11] =
{ -0.0743408f, 0.4204102f, 0.0687256f, 0.4670410f, 0.1961670f, 0.4636230f, 0.1690674f, 0.4763184f, -0.2429199f, -0.4978027f, -0.3062744f, },
};
+const Word16 AmpCB2_WB_fx[64 * (NUM_ERB_WB - 13)] =
+{
+ -5276, -7711, -3518, -2416, -382, 319, -1900, -900, 1725, 884,
+ 4071, -4052, -2430, -336, 2136, 3006, 591, -3893, -2731, 2625,
+ 2390, -1047, -883, -3368, -4235, -3726, 189, -1803, 784, 2336,
+ 206, -2140, 3001, -730, -2279, 85, -3395, 4367, 2214, -254,
+ -3114, -2348, 2763, 686, -7495, -6618, 3164, -3957, -2681, -2049,
+ 1659, 3634, 2962, 1574, 379, -2478, 2861, 616, 1124, 205,
+ -3075, -348, -2006, -90, 761, 1157, -114, -9460, -2786, -3254,
+ -1120, -1500, -446, 2835, -314, 3205, 2115, -837, -261, 36,
+ 80, -485, 1133, 2124, -1031, -401, -3166, 1145, -1616, -3425,
+ -3071, -6891, -4198, 2292, 5160, -46, 1430, 280, 1378, 1700,
+ -1673, -1126, 5270, 5096, -975, -1070, 1314, -2389, -2982, 20,
+ -3218, -892, -636, -876, -302, -2923, -3240, 4121, 1625, -557,
+ 994, 544, 2657, 7133, -273, -3530, -1419, 1431, -936, -2622,
+ 303, 75, -5444, -5549, 4183, 1248, 3474, -789, 2375, -1778,
+ 1660, 1520, -1433, -4047, 531, 7001, 695, 1889, 4261, -2791,
+ -1557, -2980, -316, 415, 1134, 1501, -6923, 521, -3134, -1812,
+ 1848, 676, -1733, 734, 2207, 2029, -476, -1976, -161, 29,
+ 7147, -1774, 720, -1070, -372, -1626, -6473, -2448, -5235, -2651,
+ -1800, -1477, -767, 1335, 471, 4857, 888, 593, -370, 196,
+ 907, 174, 557, -720, -1339, 1590, 37, -1247, -1307, 276,
+ -1739, -6032, -3088, -2499, -497, -393, -569, 3003, 2694, 3751,
+ 4652, -258, -1305, 175, 189, -344, -2381, -1992, 463, 529,
+ -6375, 3966, -3558, -3001, -640, 3117, 1120, 966, 1316, -561,
+ 27, 2794, 2831, 3512, 3453, -418, -2319, -6741, -3443, 80,
+ 1281, 1691, 1500, -591, -739, 2385, -4676, -5822, -1437, 730,
+ 3593, -437, 1090, 3497, -1932, 2854, 4858, 2654, 947, 1879,
+ -4115, 2700, -3092, -1524, 225, -8272, -6736, -1277, 2991, 2983,
+ 1129, -1661, 2817, 468, 491, -744, 390, 677, 8129, -3130,
+ -687, -433, 1488, -3763, -177, -581, -764, 39, 1537, -2203,
+ -1678, 263, -1214, 2175, -1857, 3097, -894, 4207, -1943, -834,
+ 1513, -4123, 3981, 6041, 653, -757, -313, -3024, -4614, -3139,
+ -2966, 178, 4956, -427, -41, 2376, 1008, -1351, -92, 978,
+ 1998, 5146, 2069, 117, -1754, -2756, 4425, 168, -1807, -1761,
+ -1215, 178, -1562, -3369, -919, -2576, 3614, 4968, -30, -396,
+ -1151, -1146, 868, 1073, -359, 2732, 546, 4431, -321, -1081,
+ 1410, -3214, -2316, -4889, -2460, -3844, -7323, -1438, -1488, 1849,
+ 4037, 2421, 2697, -2372, -1877, 670, 3674, -907, 888, -3703,
+ 375, -1278, -1477, 2501, -936, -1682, -1353, -335, -4440, 383,
+ -2730, -2130, -1105, 1588, 3340, 4816, -4023, 502, -4146, 236,
+ 4481, 589, -3696, 826, -97, 222, -8037, -2244, 142, 810,
+ -2195, 1315, 656, 1901, -485, 317, 1512, 1465, -2026, 1853,
+ 929, 1670, -2736, -463, -836, -4946, -134, 2769, 2972, -5148,
+ -3147, 913, -1483, 267, -1560, 3903, 1507, 1105, -1496, 210,
+ -1196, 3764, 601, 1630, 3842, 6374, -1293, -4555, -3087, 199,
+ -1917, -3331, -2317, -1774, 479, 3712, 2729, 1309, -3047, -514,
+ 861, -213, 1317, -2035, 4369, 5228, 942, -3052, -2316, -3377,
+ 1123, -65, 2507, 2711, -2096, -2164, -2634, -5215, -3919, 1551,
+ -47, 1990, 2370, 2025, -2401, 4833, -3879, -162, -3081, 501,
+ -510, 2744, -907, 253, -1746, -2520, 3418, -1461, 2140, 2507,
+ 135, 1457, 3195, -1277, -2558, -66, 10850, -1633, -1051, -3436,
+ -1617, 1438, -1231, -1744, 696, -348, 3434, 2121, -1629, -2460,
+ -4065, 1159, -1288, 2843, 697, -862, 4, 966, -444, -1860,
+ 1450, 6426, 5544, 1456, -2826, -1303, -2778, -1278, -6656, -3241,
+ -7083, 2234, 204, 1753, 803, 499, 1641, 87, 1471, -1325,
+ 398, 2983, 4340, -1382, 735, -600, -4671, -254, 2327, -1008,
+ -144, -1453, -1806, -1669, 395, -3285, -1803, -2119, 1232, 2914,
+ 1480, 8610, 1788, 2644, 1359, 3783, -110, -1339, -1337, -3427,
+ -630, -1189, -2560, 976, 483, -2744, -3653, -1289, 2910, -2437,
+ 3171, 1479, 157, 823, 4631, -1910, 3736, -424, -155, -5470,
+ -741, 3829, -2794, -55, -1447, -3469, -1947, 2914, -61, -3430,
+ 3544, -1867, 2986, 1009, -1051, 725, 2933, 2926, 5849, 257,
+ -2666, 6286, -2282, -2998, -2576, -975, -3655, -1867, -5040, -1440,
+ 3542, -603, 4806, -2808, -1633, 1388, 1149, -1616, -1851, 2122,
+ 4477, 2485, 1376, 721, 2174, -3072, 1378, -2574, -37, 1322,
+ -1646, -3612, 4443, 1612, -3403, 711, 132, 119, -227, 5059,
+ 2892, 840, 5462, -3471, -1340, 2097, 143, 1750, -3052, -1932,
+ -6352, -4166, -645, 4317, 633, 3681, 2811, 2346, 2374, -2999,
+ -1265, -210, 5115, 4652, 1305, 3704, -1456, -307, -457, -1455,
+ -3580, 674, 2215, 2458, -3021, -66, 2535, -652, 1226, 685,
+ 875, -1753, -1164, -609, 3444, 563, 3826, 1607, 3798, 1385,
+ 3902, -1990, -4078, -2509
+};
+
const float AmpCB1_NB[64][10] =
{
{ -0.1654053f, 0.0225830f, -0.0270996f, -0.0269775f, 0.2412109f, 0.3807373f, 0.0659180f, 0.1627197f, -0.4450684f, -0.3065186f, },
@@ -21659,6 +24447,74 @@ const float AmpCB1_NB[64][10] =
{ 0.3857422f, 0.0058594f, -0.2855225f, -0.7182617f, -0.0224609f, -0.0063477f, 0.0157471f, 0.6589355f, 0.0461426f, -0.0391846f, },
};
+const Word16 AmpCB1_NB_fx[640] =
+{
+ -1355, 185, -222, -221, 1976, 3119, 540, 1333, -3646, -2511,
+ -979, 1664, 2087, 951, 787, -1687, -855, 1594, 1264, -4990,
+ -1957, -215, -850, 1369, -113, 2541, -2904, 743, 634, -657,
+ -3438, -2047, 706, 85, -596, -50, 212, 944, 118, 1380,
+ -1203, -78, -213, -1811, -781, -1970, 6607, -2971, 147, -1483,
+ 38, 5607, 5222, -4567, -4040, -2259, -3110, -2120, 932, -236,
+ -1052, 1039, -872, 334, -919, 2761, 3320, -5828, 53, 1063,
+ -1064, -75, -1015, -2137, -722, 565, 629, 1961, -454, 866,
+ -888, 2652, 1996, -2170, -885, 3325, -645, -1898, -984, -643,
+ -1008, 2472, 2400, -3708, -2408, -1051, 2029, 1357, -636, -470,
+ -1307, 655, 663, 29, 892, -95, -91, -2966, -1610, 2657,
+ -2175, -3170, -3799, -3065, 1130, 1351, 3814, 2791, 1478, 1520,
+ -1326, -520, -692, 899, 1979, -397, -407, 450, -569, -611,
+ -1228, 864, 2549, 3067, -2511, -4737, -2701, -304, 680, 1426,
+ -1070, -19, -1582, -2813, -1832, 3010, 250, -613, 3390, -171,
+ -1450, -417, -773, -651, -405, -2304, -780, 6656, -3270, -1322,
+ 70, 5105, 3202, -83, -925, -458, 1203, -1582, -4158, -3630,
+ -1702, -849, -55, -986, -1963, -1140, -1942, 3347, 3526, -435,
+ -1429, -2089, -1620, -1271, 2851, 2184, -2472, 3216, 2885, -2922,
+ -1217, 86, -186, -279, -746, 1288, 3016, -651, -2719, 317,
+ -1307, -127, -1110, 1389, 212, 1783, 2619, -1718, 1795, -4086,
+ -1295, 743, 301, -1823, -223, -651, -1774, -405, 1687, 2031,
+ -865, 1059, -391, 505, -2739, -2773, 16, -2960, 3071, 3325,
+ -791, 2301, 435, 107, -4039, 801, -1224, 1854, -1039, 507,
+ -518, 997, 837, 3311, 506, 1026, -232, -1920, -3904, 406,
+ -1857, -529, -776, -700, -663, -1520, 1699, 814, 2084, -477,
+ -1341, -1123, -2564, -2784, 2457, 3223, -959, 385, -1864, 3754,
+ -1351, -1347, -2229, -2882, -1061, -1499, -3028, 3302, 2250, 5539,
+ -957, -340, 27, 1508, 167, -3513, 1689, 2577, -1810, -516,
+ -1061, 2171, 1774, 2031, 923, -1933, -1640, -2881, 859, -834,
+ 408, 2462, 2073, 2107, -2671, 1140, -3497, -2497, 2984, -2707,
+ -1762, -2524, -2196, 279, -2580, 477, 2306, 4645, 693, -909,
+ -1089, 1952, 3034, -1790, 786, -1149, -3117, 3605, -1933, -1886,
+ -959, 934, 246, -2177, -2440, 1356, 871, 3472, 2558, -4512,
+ -782, 1262, 893, 1979, 2386, -1809, -4357, -392, -1928, 1576,
+ -1751, -327, -1018, -617, -2370, -2910, 4230, -90, -1361, 3596,
+ -1069, -315, -162, -339, -313, 33, 4684, 2811, -2717, -3684,
+ 695, 4567, -745, -2311, -776, -2600, -827, -1040, -997, 2480,
+ -1549, -748, -622, -260, 1460, 1116, -302, -2529, 2156, -42,
+ -1318, -568, -266, -446, -2212, 2690, -4669, 5325, -2022, 1358,
+ -1312, 2293, 1528, 706, 970, -291, 383, -683, -1532, -1843,
+ -1379, 845, 1218, 395, -1884, 14, 676, -1711, 795, 290,
+ -742, 386, -435, 411, 1311, 549, -4181, -4922, 1497, 4465,
+ -1722, -699, -1958, -4126, -3727, -655, 1553, 1793, 4933, 3055,
+ -1260, -618, 535, -2008, 3802, -3784, 2527, -833, 193, -1062,
+ -866, 823, 1562, 147, -623, -1808, -1099, 694, -577, 745,
+ -2282, -4139, -3171, 76, 25, -1077, 477, 545, 6081, 3244,
+ -1332, -785, 98, -1681, -3603, -3937, 524, 4648, 1114, 2547,
+ -1145, 407, 2030, 3120, -1739, -513, -518, 1325, -1700, -2860,
+ -1427, 520, -1040, -792, -366, -2174, -522, -240, 5660, -3163,
+ -1449, -1653, -1507, 581, 1338, -2627, -1863, 1831, 1301, 2106,
+ -1252, 974, 199, 68, -69, -869, 864, 2373, -5818, 2873,
+ 26, 972, 359, -561, -390, 376, 225, 517, 649, -1767,
+ -653, 2167, 882, -698, 214, -4084, -4134, 2092, 2798, -523,
+ -1002, 486, 648, -1082, 404, -1490, 1560, -4984, 5614, -1441,
+ -1024, -311, 427, 356, -2342, 215, -2312, 445, -2378, 5111,
+ -568, 85, 1328, 1847, 3506, 1183, -2521, -2070, -794, -1881,
+ -485, 1121, 1242, 1301, -4365, -2222, 2602, -387, 1498, -1344,
+ -1272, -1365, -2207, -213, -1877, 2858, 849, -915, 333, 2488,
+ -2019, -2048, -1461, -1930, -1409, -400, 490, -2222, 1276, 7305,
+ -1530, -1741, -2663, 3159, 1162, -1490, 1516, -1498, 1222, 838,
+ 1325, 5387, 3888, 1944, -1706, -2890, -1905, -3901, -3207, 206,
+ -1411, -959, -292, -396, -1547, -84, -4405, -1073, 5532, 1796,
+ 3160, 48, -2339, -5884, -184, -52, 129, 5398, 378, -321
+};
+
const float AmpCB2_NB[64][NUM_ERB_NB-11] =
{
{ -0.3272705f, -0.5357666f, -0.5212402f, -0.5770264f, -0.0291748f, 0.2365723f, 0.2133789f, 0.2821045f, 0.5249023f, },
@@ -21727,6 +24583,67 @@ const float AmpCB2_NB[64][NUM_ERB_NB-11] =
{ 0.4123535f, 0.6411133f, 0.6176758f, 0.4884033f, 0.1588135f, 0.0512695f, -0.1547852f, -0.3433838f, -0.5122070f, },
};
+const Word16 AmpCB2_NB_fx[64 * (NUM_ERB_NB - 13)] =
+{
+ -2681, -4389, -4270, -4727, -239, 1938, 1748, 2311, 4300, -3957,
+ -1299, 3487, 1595, -377, 295, -1193, -1588, 2112, -1573, -6362,
+ -504, 1796, -2521, -68, 1322, 1223, 2263, -503, -3906, 3686,
+ -3899, -139, 2086, 48, 349, 547, -6387, 1340, -1467, -1062,
+ -193, 1325, -1190, 2394, 1671, -1982, -2597, -390, -1504, 2271,
+ -379, -2350, 4071, 70, -955, -883, -1770, -1065, -2443, -1779,
+ -1101, -661, 6325, 1871, -2673, 3596, 3773, -681, 3340, -1418,
+ 701, -4253, -3931, -1840, -2388, -2677, -3545, -41, 3675, 3843,
+ 2198, -1713, -324, 599, 1323, 1827, -4909, -1668, 616, 2608,
+ 360, -1769, -5263, -1278, 3490, 1935, 1355, -1298, 952, 1801,
+ 449, 251, -1021, -3666, 479, 3497, 1542, -2234, -3414, -4483,
+ -5785, 1406, 1207, 2984, 1767, 3262, -799, -3124, 5237, 460,
+ 2007, -1525, -2106, -770, 546, 137, 401, -1308, 969, 204,
+ -1626, -589, -4257, 1744, 2836, 2383, 2740, -423, 3166, 1920,
+ -690, -3000, -4489, 2523, -6693, -5135, -739, -1919, 1228, 2354,
+ 3340, 1902, 1069, -3185, -2614, 2764, -212, -2061, -1377, 698,
+ 3694, -125, -954, -4132, -404, 4297, 1294, 1765, 2446, -2287,
+ -1387, -14, 508, 1149, 9, -437, 519, -420, 450, -751,
+ -1632, -1391, -2208, -1955, -1170, 4818, 1112, 1086, -782, 1337,
+ 846, -3434, 569, 1721, -776, -2723, 1207, 982, -1432, -887,
+ 315, -3031, 3452, 765, -1263, -2146, 2959, -2619, 1507, 1312,
+ 4087, 3125, 1637, -1402, -45, -3193, 1397, -2611, -3641, -2478,
+ -1706, 588, 199, 3721, 1217, -1249, -1196, 7228, 996, 879,
+ -1339, 11, -971, -1680, 716, -39, 233, 1945, 1548, -1476,
+ 550, -2277, 307, 7413, 2094, -1631, -569, -1351, -198, -483,
+ -515, -1347, -212, -2649, -519, 195, 2944, -795, 1470, 654,
+ -1448, 3156, 1369, 3966, 3382, -2782, -4255, -1157, -212, 392,
+ 861, 5064, 4740, -2513, -3413, -552, -2298, -575, 1130, 1178,
+ 1568, 4591, 1238, 367, 1626, 600, -5889, 163, -3742, -3650,
+ -3911, 716, 919, -1501, 55, 1807, 3801, -5571, -4635, 1225,
+ 3211, 3804, 1491, -906, 100, 404, -1742, -1878, -2140, 1651,
+ 1640, 3976, -3432, -1149, 1365, 2042, 392, 768, -1534, 1096,
+ 3811, -211, -2067, -1315, -4167, 1145, -2747, -149, 5296, -735,
+ 438, 56, -404, -159, -2164, -959, 3492, -690, -688, -1081,
+ 2762, -1191, 654, 2051, -2144, -3210, -1823, 743, 686, -751,
+ 2483, 160, 1279, 3246, 1874, 2488, 1192, -5977, -478, 120,
+ -349, -65, -2350, -222, -1678, -3584, 1114, 3269, 1462, -1114,
+ -138, 2360, -2762, 720, -3822, 2523, 216, 1170, 4398, -4229,
+ -1850, 1272, 383, 1736, -383, -1295, 85, -132, 1133, 1505,
+ 1467, -2389, -2175, 4028, -2752, 241, -4353, -2103, -562, 817,
+ 3959, 5471, 1941, -1598, -2349, 201, 1412, -796, 2791, -4226,
+ 3227, -1992, -159, -159, 4085, -1549, 1020, -2179, -776, -2088,
+ -147, -42, 1880, -1029, 4982, -2056, 111, 1420, 2141, 302,
+ -2574, -986, -477, -3697, -2349, -2064, -335, -220, 5857, 57,
+ -7, -5407, -546, -353, 2866, 137, -136, 3508, 992, -2059,
+ -2034, -1127, -189, -300, -2153, 3606, 2523, -3727, 1526, -3797,
+ 2134, 4352, -920, -459, 2722, 1784, -71, -3030, -877, 1967,
+ -1645, -4432, 512, 39, 1757, 2875, -947, 1842, 1365, 1500,
+ 851, 594, -2892, -404, 3327, -3078, -1575, -1258, -973, -191,
+ -390, 45, 627, -227, 1624, -143, 215, 2157, 4846, 5335,
+ 3397, -199, -4443, -3091, -283, -216, 1237, -1478, -5639, -775,
+ 525, 2107, 2469, 2934, -255, 2438, 824, 5973, -1820, -1330,
+ -1202, -2433, 900, 650, -5654, 2891, -1539, -453, 1662, 231,
+ -145, 1661, 741, -332, 1221, 1809, 943, 4831, -1588, -4619,
+ 65, -790, -985, -893, 3374, 3148, 289, 2947, -4980, -661,
+ -427, 1441, 7696, 158, -1914, -2069, -1717, -418, 2657, 4219,
+ 1505, -1096, 601, -1466, -1754, -479, -159, 3378, 5252, 5060,
+ 4001, 1301, 420, -1268, -2813, -4196
+};
const float PowerCB_WB[64][2] =
@@ -21879,6 +24796,17 @@ const float sinc[8][12] =
{-339.0f/16384.0f,409.0f/16384.0f,-514.0f/16384.0f,694.0f/16384.0f,-1063.0f/16384.0f,2281.0f/16384.0f,15966.0f/16384.0f,-1773.0f/16384.0f,939.0f/16384.0f,-638.0f/16384.0f,484.0f/16384.0f,-388.0f/16384.0f,},
};
+const Word16 sinc_fx[8][12] = /* sinc for warp/extrapolate, in Q14 */
+{
+ {0,0,0,0,0,16384,0,0,0,0,0,0,},
+ {-388,484,-638,939,-1773,15966,2281,-1063,694,-514,409,-339,},
+ {-701,868,-1134,1639,-2949,14751,4917,-2106,1341,-982,776,-640,},
+ {-895,1101,-1427,2029,-3503,12849,7709,-2964,1835,-1328,1042,-856,},
+ {-947,1159,-1489,2086,-3476,10430,10430,-3476,2086,-1489,1159,-947,},
+ {-856,1042,-1328,1835,-2964,7709,12849,-3503,2029,-1427,1101,-895,},
+ {-640,776,-982,1341,-2106,4917,14751,-2949,1639,-1134,868,-701,},
+ {-339,409,-514,694,-1063,2281,15966,-1773,939,-638,484,-388,},
+};
/*----------------------------------------------------------------------------------*
* Highrate SWB BWE tables
*----------------------------------------------------------------------------------*/
@@ -22152,6 +25080,50 @@ const int16_t ct2[7][13] =
/*48*/ {18, 18, 18, 18, 18, 0, 0, 0, 5, 2, 1, 4, 15},
};
+const Word16 cu15_fx[28][3] = /*Q13*/
+{
+ /* xx/3, xx*xx/3, xx*xx*xx/3 xx v */
+ /* 0:*/ { 182, 12, 1 }, /* 1/15 */
+ /* 1:*/ { 364, 49, 6 }, /* 2/15 */
+ /* 2:*/ { 546, 109, 22 }, /* 3/15 */
+ /* 3:*/ { 728, 194, 52 }, /* 4/15 */
+ /* 4:*/ { 910, 303, 101 }, /* 5/15 */
+ /* 5:*/ { 1092, 437, 175 }, /* 6/15 */
+ /* 6:*/ { 1274, 595, 278 }, /* 7/15 */
+ /* 7:*/ { 1456, 777, 414 }, /* 8/15 */
+ /* 8:*/ { 1638, 983, 590 }, /* 9/15 */
+ /* 9:*/ { 1820, 1214, 809 }, /* 10/15 */
+ /*10:*/ { 2002, 1468, 1077 }, /* 11/15 */
+ /*11:*/ { 2185, 1748, 1398 }, /* 12/15 */
+ /*12:*/ { 2367, 2051, 1778 }, /* 13/15 */
+ /*13:*/ { 2549, 2379, 2220 }, /* 14/15 */
+ /*14:*/ { 2913, 3107, 3314 }, /* 16/15 */
+ /*15:*/ { 3095, 3507, 3975 }, /* 17/15 */
+ /*16:*/ { 3277, 3932, 4719 }, /* 18/15 */
+ /*17:*/ { 3459, 4381, 5550 }, /* 19/15 */
+ /*18:*/ { 3641, 4855, 6473 }, /* 20/15 */
+ /*19:*/ { 3823, 5352, 7493 }, /* 21/15 */
+ /*20:*/ { 4005, 5874, 8615 }, /* 22/15 */
+ /*21:*/ { 4187, 6420, 9844 }, /* 23/15 */
+ /*22:*/ { 4369, 6991, 11185 }, /* 24/15 */
+ /*23:*/ { 4551, 7585, 12642 }, /* 25/15 */
+ /*24:*/ { 4733, 8204, 14221 }, /* 26/15 */
+ /*25:*/ { 4915, 8847, 15925 }, /* 27/15 */
+ /*26:*/ { 5097, 9515, 17761 }, /* 28/15 */
+ /*27:*/ { 5279, 10207, 19733 }, /* 29/15 */
+};
+
+const Word16 cu4_fx[6][3] = /*Q13*/
+{
+ /* xx/3, xx*xx/3, xx*xx*xx/3 xx v */
+ /* 0:*/ { 683, 171, 43 }, /* 1/4 */
+ /* 1:*/ { 1365, 683, 341 }, /* 2/4 */
+ /* 2:*/ { 2048, 1536, 1152 }, /* 3/4 */
+ /* 3:*/ { 3413, 4267, 5333 }, /* 5/4 */
+ /* 4:*/ { 4096, 6144, 9216 }, /* 6/4 */
+ /* 5:*/ { 4779, 8363, 14635 }, /* 7/4 */
+};
+
/*----------------------------------------------------------------------------------*
* hp filter for filtering random part of excitation in frame error concealment
@@ -25051,7 +28023,6 @@ const Word16 f_atan_expand_range[MAXSFTAB - (MINSFTAB - 1)] =
/* pi/4 = 0.785398163397448 = pi/2/ATO_SCALE */
};
-const Word16 shift_Isqrt_lc[] = { 9,10 };
const Word16 Grid[GRID100_POINTS + 1] =
{
@@ -26089,4 +29060,127 @@ const Word16 inter4_1_fx[32] =
32, -26, -12, 0
};
+const Word16 wac_h[LPC_SHB_ORDER] =
+{
+ 32763,
+ 32751,
+ 32731,
+ 32703,
+ 32667,
+ 32622,
+ 32570,
+ 32510,
+ 32442,
+ 32366
+};
+
+const Word16 wac_l[LPC_SHB_ORDER] =
+{
+ 31381,
+ 27317,
+ 20869,
+ 12529,
+ 2980,
+ 25869,
+ 16731,
+ 9600,
+ 5926,
+ 7354
+};
+
+const Word16 dsDiracsTab[65] =
+{
+ 0, 1, 2, 3, 4, 5, 6, 7,
+ 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 23, 25,
+ 27, 29, 31, 33, 35, 37, 39, 43,
+ 47, 51, 55, 59, 63, 67, 71, 75,
+ 83, 91, 99, 107, 115, 123, 131, 139,
+ 147, 163, 179, 195, 211, 227, 243, 259,
+ 275, 291, 323, 355, 387, 419, 451, 483,
+ 512
+};
+
+const Word16 pwf_fx[17] =
+{
+ 22938, 16056, 11239, 7868, 5507, 3855, 2699, 1889,
+ 1322, 926, 648, 454, 317, 222, 156, 109,
+ 76
+};
+
+const Word32 inverse_table[] =
+{
+ 0,
+ 134217728, 67108864, 44739242, 33554432, 26843545, 22369621, 19173961, 16777216, 14913080, 13421772, 12201611, 11184810, 10324440, 9586980, 8947848, 8388608, 7895160, 7456540, 7064090, 6710886, 6391320, 6100805, 5835553, 5592405, 5368709, 5162220, 4971026, 4793490, 4628197, 4473924, 4329604, 4194304, 4067203, 3947580, 3834792, 3728270, 3627506, 3532045, 3441480, 3355443, 3273603, 3195660, 3121342, 3050402, 2982616, 2917776, 2855696, 2796202, 2739137, 2684354, 2631720, 2581110, 2532409, 2485513, 2440322, 2396745, 2354696, 2314098, 2274876, 2236962, 2200290, 2164802, 2130440, 2097152, 2064888, 2033601, 2003249, 1973790, 1945184, 1917396, 1890390, 1864135, 1838599, 1813753, 1789569, 1766022, 1743087, 1720740, 1698958, 1677721, 1657008, 1636801, 1617081, 1597830, 1579032, 1560671, 1542732, 1525201, 1508064, 1491308, 1474920, 1458888, 1443201, 1427848, 1412818, 1398101, 1383687, 1369568, 1355734, 1342177, 1328888, 1315860, 1303084, 1290555, 1278264, 1266204, 1254371, 1242756, 1231355, 1220161, 1209168, 1198372, 1187767, 1177348, 1167110, 1157049, 1147160, 1137438, 1127880, 1118481, 1109237, 1100145, 1091201, 1082401, 1073741, 1065220, 1056832, 1048576, 1040447, 1032444, 1024562, 1016800, 1009155, 1001624, 994205, 986895, 979691, 972592, 965595, 958698, 951898, 945195, 938585, 932067, 925639, 919299, 913045, 906876, 900790, 894784, 888859, 883011, 877240, 871543, 865920, 860370, 854889, 849479, 844136, 838860, 833650, 828504, 823421, 818400, 813440, 808540, 803698, 798915, 794187, 789516, 784898, 780335, 775825, 771366, 766958, 762600, 758292, 754032, 749819, 745654, 741534, 737460, 733430, 729444, 725501, 721600, 717741, 713924, 710146, 706409, 702710, 699050, 695428, 691843, 688296, 684784, 681308, 677867, 674460, 671088, 667749, 664444, 661171, 657930, 654720, 651542, 648394, 645277, 642190, 639132, 636102, 633102, 630130, 627185, 624268, 621378, 618514, 615677, 612866, 610080, 607320, 604584, 601873, 599186, 596523, 593883, 591267, 588674, 586103, 583555, 581029, 578524, 576041, 573580, 571139, 568719, 566319, 563940, 561580, 559240, 556920, 554618, 552336, 550072, 547827, 545600, 543391, 541200, 539027, 536870, 534731, 532610, 530504, 528416, 526344,
+};
+
+const Word16 cos_diff_table[512] =
+{
+ SHC(0xFFFF), SHC(0xFFF8), SHC(0xFFF4), SHC(0xFFEF), SHC(0xFFE9), SHC(0xFFE5), SHC(0xFFE0), SHC(0xFFDB),
+ SHC(0xFFD6), SHC(0xFFD2), SHC(0xFFCC), SHC(0xFFC7), SHC(0xFFC3), SHC(0xFFBE), SHC(0xFFB8), SHC(0xFFB4),
+ SHC(0xFFB0), SHC(0xFFAA), SHC(0xFFA5), SHC(0xFFA1), SHC(0xFF9C), SHC(0xFF97), SHC(0xFF92), SHC(0xFF8E),
+ SHC(0xFF89), SHC(0xFF84), SHC(0xFF80), SHC(0xFF7B), SHC(0xFF76), SHC(0xFF71), SHC(0xFF6D), SHC(0xFF69),
+ SHC(0xFF64), SHC(0xFF5F), SHC(0xFF5B), SHC(0xFF56), SHC(0xFF52), SHC(0xFF4D), SHC(0xFF49), SHC(0xFF45),
+ SHC(0xFF40), SHC(0xFF3C), SHC(0xFF38), SHC(0xFF33), SHC(0xFF2F), SHC(0xFF2B), SHC(0xFF27), SHC(0xFF23),
+ SHC(0xFF1E), SHC(0xFF1B), SHC(0xFF16), SHC(0xFF13), SHC(0xFF0E), SHC(0xFF0B), SHC(0xFF06), SHC(0xFF03),
+ SHC(0xFEFF), SHC(0xFEFB), SHC(0xFEF8), SHC(0xFEF3), SHC(0xFEF1), SHC(0xFEEC), SHC(0xFEE9), SHC(0xFEE5),
+ SHC(0xFEE2), SHC(0xFEDF), SHC(0xFEDB), SHC(0xFED8), SHC(0xFED4), SHC(0xFED1), SHC(0xFECE), SHC(0xFECB),
+ SHC(0xFEC7), SHC(0xFEC5), SHC(0xFEC1), SHC(0xFEBF), SHC(0xFEBB), SHC(0xFEB9), SHC(0xFEB6), SHC(0xFEB3),
+ SHC(0xFEB0), SHC(0xFEAE), SHC(0xFEAB), SHC(0xFEA8), SHC(0xFEA6), SHC(0xFEA3), SHC(0xFEA1), SHC(0xFE9F),
+ SHC(0xFE9C), SHC(0xFE9A), SHC(0xFE98), SHC(0xFE95), SHC(0xFE94), SHC(0xFE91), SHC(0xFE8F), SHC(0xFE8E),
+ SHC(0xFE8B), SHC(0xFE8A), SHC(0xFE88), SHC(0xFE86), SHC(0xFE85), SHC(0xFE83), SHC(0xFE81), SHC(0xFE80),
+ SHC(0xFE7F), SHC(0xFE7D), SHC(0xFE7B), SHC(0xFE7B), SHC(0xFE79), SHC(0xFE79), SHC(0xFE77), SHC(0xFE76),
+ SHC(0xFE75), SHC(0xFE74), SHC(0xFE73), SHC(0xFE73), SHC(0xFE72), SHC(0xFE71), SHC(0xFE71), SHC(0xFE70),
+ SHC(0xFE6F), SHC(0xFE70), SHC(0xFE6E), SHC(0xFE6F), SHC(0xFE6E), SHC(0xFE6E), SHC(0xFE6E), SHC(0xFE6E),
+ SHC(0xFE6E), SHC(0xFE6E), SHC(0xFE6E), SHC(0xFE6E), SHC(0xFE6F), SHC(0xFE6E), SHC(0xFE70), SHC(0xFE6F),
+ SHC(0xFE70), SHC(0xFE71), SHC(0xFE71), SHC(0xFE72), SHC(0xFE73), SHC(0xFE73), SHC(0xFE74), SHC(0xFE75),
+ SHC(0xFE76), SHC(0xFE77), SHC(0xFE79), SHC(0xFE79), SHC(0xFE7B), SHC(0xFE7B), SHC(0xFE7D), SHC(0xFE7F),
+ SHC(0xFE80), SHC(0xFE81), SHC(0xFE83), SHC(0xFE85), SHC(0xFE86), SHC(0xFE88), SHC(0xFE8A), SHC(0xFE8B),
+ SHC(0xFE8E), SHC(0xFE8F), SHC(0xFE91), SHC(0xFE94), SHC(0xFE95), SHC(0xFE98), SHC(0xFE9A), SHC(0xFE9C),
+ SHC(0xFE9F), SHC(0xFEA1), SHC(0xFEA3), SHC(0xFEA6), SHC(0xFEA8), SHC(0xFEAB), SHC(0xFEAE), SHC(0xFEB0),
+ SHC(0xFEB3), SHC(0xFEB6), SHC(0xFEB9), SHC(0xFEBB), SHC(0xFEBF), SHC(0xFEC1), SHC(0xFEC5), SHC(0xFEC7),
+ SHC(0xFECB), SHC(0xFECE), SHC(0xFED1), SHC(0xFED4), SHC(0xFED8), SHC(0xFEDB), SHC(0xFEDF), SHC(0xFEE2),
+ SHC(0xFEE5), SHC(0xFEE9), SHC(0xFEEC), SHC(0xFEF1), SHC(0xFEF3), SHC(0xFEF8), SHC(0xFEFB), SHC(0xFEFF),
+ SHC(0xFF03), SHC(0xFF06), SHC(0xFF0B), SHC(0xFF0E), SHC(0xFF13), SHC(0xFF16), SHC(0xFF1B), SHC(0xFF1E),
+ SHC(0xFF23), SHC(0xFF27), SHC(0xFF2B), SHC(0xFF2F), SHC(0xFF33), SHC(0xFF38), SHC(0xFF3C), SHC(0xFF40),
+ SHC(0xFF45), SHC(0xFF49), SHC(0xFF4D), SHC(0xFF52), SHC(0xFF56), SHC(0xFF5B), SHC(0xFF5F), SHC(0xFF64),
+ SHC(0xFF69), SHC(0xFF6D), SHC(0xFF71), SHC(0xFF76), SHC(0xFF7B), SHC(0xFF80), SHC(0xFF84), SHC(0xFF89),
+ SHC(0xFF8E), SHC(0xFF92), SHC(0xFF97), SHC(0xFF9C), SHC(0xFFA1), SHC(0xFFA5), SHC(0xFFAA), SHC(0xFFB0),
+ SHC(0xFFB4), SHC(0xFFB8), SHC(0xFFBE), SHC(0xFFC3), SHC(0xFFC7), SHC(0xFFCC), SHC(0xFFD2), SHC(0xFFD6),
+ SHC(0xFFDB), SHC(0xFFE0), SHC(0xFFE5), SHC(0xFFE9), SHC(0xFFEF), SHC(0xFFF4), SHC(0xFFF8), SHC(0xFFFF),
+ SHC(0x0001), SHC(0x0008), SHC(0x000C), SHC(0x0011), SHC(0x0017), SHC(0x001B), SHC(0x0020), SHC(0x0025),
+ SHC(0x002A), SHC(0x002E), SHC(0x0034), SHC(0x0039), SHC(0x003D), SHC(0x0042), SHC(0x0048), SHC(0x004C),
+ SHC(0x0050), SHC(0x0056), SHC(0x005B), SHC(0x005F), SHC(0x0064), SHC(0x0069), SHC(0x006E), SHC(0x0072),
+ SHC(0x0077), SHC(0x007C), SHC(0x0080), SHC(0x0085), SHC(0x008A), SHC(0x008F), SHC(0x0093), SHC(0x0097),
+ SHC(0x009C), SHC(0x00A1), SHC(0x00A5), SHC(0x00AA), SHC(0x00AE), SHC(0x00B3), SHC(0x00B7), SHC(0x00BB),
+ SHC(0x00C0), SHC(0x00C4), SHC(0x00C8), SHC(0x00CD), SHC(0x00D1), SHC(0x00D5), SHC(0x00D9), SHC(0x00DD),
+ SHC(0x00E2), SHC(0x00E5), SHC(0x00EA), SHC(0x00ED), SHC(0x00F2), SHC(0x00F5), SHC(0x00FA), SHC(0x00FD),
+ SHC(0x0101), SHC(0x0105), SHC(0x0108), SHC(0x010D), SHC(0x010F), SHC(0x0114), SHC(0x0117), SHC(0x011B),
+ SHC(0x011E), SHC(0x0121), SHC(0x0125), SHC(0x0128), SHC(0x012C), SHC(0x012F), SHC(0x0132), SHC(0x0135),
+ SHC(0x0139), SHC(0x013B), SHC(0x013F), SHC(0x0141), SHC(0x0145), SHC(0x0147), SHC(0x014A), SHC(0x014D),
+ SHC(0x0150), SHC(0x0152), SHC(0x0155), SHC(0x0158), SHC(0x015A), SHC(0x015D), SHC(0x015F), SHC(0x0161),
+ SHC(0x0164), SHC(0x0166), SHC(0x0168), SHC(0x016B), SHC(0x016C), SHC(0x016F), SHC(0x0171), SHC(0x0172),
+ SHC(0x0175), SHC(0x0176), SHC(0x0178), SHC(0x017A), SHC(0x017B), SHC(0x017D), SHC(0x017F), SHC(0x0180),
+ SHC(0x0181), SHC(0x0183), SHC(0x0185), SHC(0x0185), SHC(0x0187), SHC(0x0187), SHC(0x0189), SHC(0x018A),
+ SHC(0x018B), SHC(0x018C), SHC(0x018D), SHC(0x018D), SHC(0x018E), SHC(0x018F), SHC(0x018F), SHC(0x0190),
+ SHC(0x0191), SHC(0x0190), SHC(0x0192), SHC(0x0191), SHC(0x0192), SHC(0x0192), SHC(0x0192), SHC(0x0192),
+ SHC(0x0192), SHC(0x0192), SHC(0x0192), SHC(0x0192), SHC(0x0191), SHC(0x0192), SHC(0x0190), SHC(0x0191),
+ SHC(0x0190), SHC(0x018F), SHC(0x018F), SHC(0x018E), SHC(0x018D), SHC(0x018D), SHC(0x018C), SHC(0x018B),
+ SHC(0x018A), SHC(0x0189), SHC(0x0187), SHC(0x0187), SHC(0x0185), SHC(0x0185), SHC(0x0183), SHC(0x0181),
+ SHC(0x0180), SHC(0x017F), SHC(0x017D), SHC(0x017B), SHC(0x017A), SHC(0x0178), SHC(0x0176), SHC(0x0175),
+ SHC(0x0172), SHC(0x0171), SHC(0x016F), SHC(0x016C), SHC(0x016B), SHC(0x0168), SHC(0x0166), SHC(0x0164),
+ SHC(0x0161), SHC(0x015F), SHC(0x015D), SHC(0x015A), SHC(0x0158), SHC(0x0155), SHC(0x0152), SHC(0x0150),
+ SHC(0x014D), SHC(0x014A), SHC(0x0147), SHC(0x0145), SHC(0x0141), SHC(0x013F), SHC(0x013B), SHC(0x0139),
+ SHC(0x0135), SHC(0x0132), SHC(0x012F), SHC(0x012C), SHC(0x0128), SHC(0x0125), SHC(0x0121), SHC(0x011E),
+ SHC(0x011B), SHC(0x0117), SHC(0x0114), SHC(0x010F), SHC(0x010D), SHC(0x0108), SHC(0x0105), SHC(0x0101),
+ SHC(0x00FD), SHC(0x00FA), SHC(0x00F5), SHC(0x00F2), SHC(0x00ED), SHC(0x00EA), SHC(0x00E5), SHC(0x00E2),
+ SHC(0x00DD), SHC(0x00D9), SHC(0x00D5), SHC(0x00D1), SHC(0x00CD), SHC(0x00C8), SHC(0x00C4), SHC(0x00C0),
+ SHC(0x00BB), SHC(0x00B7), SHC(0x00B3), SHC(0x00AE), SHC(0x00AA), SHC(0x00A5), SHC(0x00A1), SHC(0x009C),
+ SHC(0x0097), SHC(0x0093), SHC(0x008F), SHC(0x008A), SHC(0x0085), SHC(0x0080), SHC(0x007C), SHC(0x0077),
+ SHC(0x0072), SHC(0x006E), SHC(0x0069), SHC(0x0064), SHC(0x005F), SHC(0x005B), SHC(0x0056), SHC(0x0050),
+ SHC(0x004C), SHC(0x0048), SHC(0x0042), SHC(0x003D), SHC(0x0039), SHC(0x0034), SHC(0x002E), SHC(0x002A),
+ SHC(0x0025), SHC(0x0020), SHC(0x001B), SHC(0x0017), SHC(0x0011), SHC(0x000C), SHC(0x0008), SHC(0x0001)
+};
+
/* clang-format on */
+
diff --git a/lib_com/rom_com.h b/lib_com/rom_com.h
index bee23e92d462afde4255c129cfe4f8dff78e7482..ae35d190c50e71c0fbe115f58e979de2763d2db4 100644
--- a/lib_com/rom_com.h
+++ b/lib_com/rom_com.h
@@ -199,20 +199,31 @@ extern const float grid40[]; /* Table of grid points for evaluati
extern const float grid100[]; /* Table of 100 grid points for evaluating Chebyshev polynomials */
extern const float wind_sss[LEN_WIN_SSS]; /* window for modify_sf ana */
+extern const Word16 wind_sss_fx[LEN_WIN_SSS]; /*window for modify_sf ana*/
+
extern const float filter5_39s320_120[]; /* LP FIR filter for 8kHz signal resampling */
extern const Word16 filter5_39s320_120_fx[];
-extern const float lag_window_8k[17];
-extern const float lag_window_12k8[][17];
-extern const float lag_window_16k[][17];
-extern const float lag_window_25k6[][17];
-extern const float lag_window_32k[][17];
-extern const float lag_window_48k[17];
+extern const float lag_window_8k_flt[17];
+extern const float lag_window_12k8_flt[][17];
+extern const float lag_window_16k_flt[][17];
+extern const float lag_window_25k6_flt[][17];
+extern const float lag_window_32k_flt[][17];
+extern const float lag_window_48k_flt[17];
+extern const Word16 lag_window_8k[2][16];
+extern const Word16 lag_window_12k8[NUM_LAGW_STRENGTHS][2][16];
+extern const Word16 lag_window_16k[NUM_LAGW_STRENGTHS][2][16];
+extern const Word16 lag_window_25k6[NUM_LAGW_STRENGTHS][2][16];
+extern const Word16 lag_window_32k[NUM_LAGW_STRENGTHS][2][16];
+extern const Word16 lag_window_48k[2][16];
extern const float interpol_frac2[]; /* 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 float interpol_isp_amr_wb[]; /* LPC interpolation coefficients for AMR-WB interoperable mode */
+
+extern const Word16 interpol_isp_amr_wb_fx[];
+
extern const float interpol_frac_16k[]; /* LPC interpolation coefficients @ 16kHz */
extern const Word16 interpol_frac_16k_fx[NB_SUBFR16k];
extern const float interpol_frac_mid[]; /* LPC interpolation coefficients with mid-ISFs */
@@ -304,6 +315,9 @@ extern const float b_hp400[]; /* HF (6-7kHz) BWE - 400Hz HP filter coefficient
extern const float a_hp400[]; /* HF (6-7kHz) BWE - 400Hz HP filter coefficients */
extern const float fir_6k_7k[]; /* HF (6-7kHz) BWE - 6.0 - 7.0 kHz BP filter coefficients */
+extern const Word16 no_lead_fx[][MAX_NO_SCALES * 2];
+extern const Word16 no_lead_p_fx[][MAX_NO_SCALES * 2];
+
extern const float low_H[]; /* Enhacer - 2.0 - 6.4 kHz impulse response with phase dispersion */
extern const float mid_H[]; /* Enhancer - 3.2 - 6.4 kHz impulse response with phase dispersion */
@@ -348,31 +362,65 @@ extern const int16_t hq_swb_bwe_nb_bits[];
/*----------------------------------------------------------------------------------*
* ISF quantization (AMR-WB IO mode)
*----------------------------------------------------------------------------------*/
+extern const Word16 Indirect_dico1[SIZE_BK1];
extern const float mean_isf_amr_wb[M]; /* Mean ISF vector (only in AMR-WB IO mode) */
+
+extern const Word16 mean_isf_amr_wb_fx[M]; /* Mean ISF vector (only in AMR-WB IO mode) */
+
extern const float mean_isf_noise_amr_wb[]; /* Mean ISF vector for SID frame (only in AMR-WB IO mode) */
+
+extern const Word16 mean_isf_noise_amr_wb_fx[]; /* Mean ISF vector for SID frame (only in AMR-WB IO mode) */
+
extern const float gaus_dico[]; /* Gaussian codebook */
+extern const Word16 gaus_dico_fx[];
extern const float gaus_dico_swb[]; /* Gaussian codebook for SWB TBE */
+extern const Word16 gaus_dico_swb_fx[];
extern const float dico1_isf[]; /* ISF codebook - common 1st stage, 1st split (only in AMR-WB IO mode) */
+
+extern const Word16 dico1_isf_fx[]; /* ISF codebook - common 1st stage, 1st split (only in AMR-WB IO mode) */
+
extern const float dico2_isf[]; /* ISF codebook - common 1st stage, 2nd split (only in AMR-WB IO mode) */
+extern const Word16 dico2_isf_fx[]; /* ISF codebook - common 1st stage, 2nd split (only in AMR-WB IO mode) */
+
extern const float dico21_isf_46b[]; /* ISF codebook - 46b, 2nd stage, 1st split (only in AMR-WB IO mode) */
extern const float dico22_isf_46b[]; /* ISF codebook - 46b, 2nd stage, 2st split (only in AMR-WB IO mode) */
extern const float dico23_isf_46b[]; /* ISF codebook - 46b, 2nd stage, 3rd split (only in AMR-WB IO mode) */
extern const float dico24_isf_46b[]; /* ISF codebook - 46b, 2nd stage, 4th split (only in AMR-WB IO mode) */
extern const float dico25_isf_46b[]; /* ISF codebook - 46b, 2nd stage, 5th split (only in AMR-WB IO mode) */
+extern const Word16 dico21_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 1st split (only in AMR-WB IO mode) */
+extern const Word16 dico22_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 2st split (only in AMR-WB IO mode) */
+extern const Word16 dico23_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 3rd split (only in AMR-WB IO mode) */
+extern const Word16 dico24_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 4th split (only in AMR-WB IO mode) */
+extern const Word16 dico25_isf_46b_fx[]; /* ISF codebook - 46b, 2nd stage, 5th split (only in AMR-WB IO mode) */
+
extern const float dico21_isf_36b[]; /* ISF codebook - 36b, 2nd stage, 1st split (only in AMR-WB IO mode) */
+
+extern const Word16 dico21_isf_36b_fx[]; /* ISF codebook - 36b, 2nd stage, 1st split (only in AMR-WB IO mode) */
+
extern const float dico22_isf_36b[]; /* ISF codebook - 36b, 2nd stage, 2nd split (only in AMR-WB IO mode) */
+
+extern const Word16 dico22_isf_36b_fx[]; /* ISF codebook - 36b, 2nd stage, 2nd split (only in AMR-WB IO mode) */
+
extern const float dico23_isf_36b[]; /* ISF codebook - 36b, 2nd stage, 3rd split (only in AMR-WB IO mode) */
+extern const Word16 dico23_isf_36b_fx[]; /* ISF codebook - 36b, 2nd stage, 3rd split (only in AMR-WB IO mode) */
+
extern const float dico1_ns_28b[]; /* ISF codebook for SID frames - 28b, 1st split */
extern const float dico2_ns_28b[]; /* ISF codebook for SID frames - 28b, 2nd spilt */
extern const float dico3_ns_28b[]; /* ISF codebook for SID frames - 28b, 3rd spilt */
extern const float dico4_ns_28b[]; /* ISF codebook for SID frames - 28b, 4th spilt */
extern const float dico5_ns_28b[]; /* ISF codebook for SID frames - 28b, 5th spilt */
+extern const Word16 dico1_ns_28b_fx[]; /* ISF codebook for SID frames - 28b, 1st split */
+extern const Word16 dico2_ns_28b_fx[]; /* ISF codebook for SID frames - 28b, 2nd spilt */
+extern const Word16 dico3_ns_28b_fx[]; /* ISF codebook for SID frames - 28b, 3rd spilt */
+extern const Word16 dico4_ns_28b_fx[]; /* ISF codebook for SID frames - 28b, 4th spilt */
+extern const Word16 dico5_ns_28b_fx[]; /* ISF codebook for SID frames - 28b, 5th spilt */
+
extern const float dico1_cng_ev[];
extern const float dico2_cng_ev[];
extern const float dico3_cng_ev[];
@@ -424,9 +472,16 @@ extern const int16_t CBbits[];
extern const int16_t CBbits_p[];
extern const float vals[NO_LEADERS][MAX_NO_VALS];
extern const Word16 vals_fx[NO_LEADERS][MAX_NO_VALS];
+
extern const int16_t no_vals[NO_LEADERS];
+//extern const Word16 no_vals_fx[NO_LEADERS];
+
extern const int16_t no_vals_ind[NO_LEADERS][MAX_NO_VALS];
+//extern const Word16 no_vals_ind_fx[NO_LEADERS][MAX_NO_VALS];
+
extern const int16_t C_VQ[LATTICE_DIM + 1][LATTICE_DIM + 1];
+//extern const Word16 C_VQ_fx[LATTICE_DIM + 1][LATTICE_DIM + 1];
+
extern const int16_t BitsVQ[];
extern const int16_t BitsVQ_p[];
extern const UWord8 no_lead_idx[][2];
@@ -445,20 +500,42 @@ extern const Word16 scales_p_fx[][MAX_NO_SCALES * 2];
extern const int16_t predmode_tab_float[][6];
extern const Word16 predmode_tab[][6];
extern const float pl_HQ[];
+
extern const int16_t pi0[];
+//extern const Word16 pi0_fx[];
+
extern const UWord32 table_no_cv[];
+extern const Word32 table_no_cv_fx[];
+
extern const int16_t pl_par[];
+//extern const Word16 pl_par_fx[]; /* 1 if even number of signs */
+
extern const float *const Quantizers[];
extern const float *const Quantizers_p[];
extern const Word16 * const Quantizers_p_fx[];
extern const Word16 * const Quantizers_fx[];
+
extern const int16_t cng_sort[];
+//extern const Word16 cng_sort_fx[];
+
extern const int16_t perm_MSLVQ[][4];
+//extern const Word16 perm_MSLVQ_fx[][4];
+
extern const int16_t min_lat_bits_SN[];
+extern const Word16 min_lat_bits_SN_fx[];
+
extern const int16_t min_lat_bits_pred[];
+extern const Word16 min_lat_bits_pred_fx[];
+
extern const int16_t offset_in_lvq_mode_SN[][21];
+extern const Word16 offset_in_lvq_mode_SN_fx[][21];
+
extern const int16_t offset_in_lvq_mode_pred[][32];
+extern const Word16 offset_in_lvq_mode_pred_fx[][32];
+
extern const int16_t offset_lvq_modes_SN[];
+extern const Word16 offset_lvq_modes_SN_fx[];
+
extern const int16_t offset_lvq_modes_pred[];
extern const Word16 offset_lvq_modes_pred_fx[];
@@ -597,16 +674,22 @@ extern const float interpol_frac_shb[];
extern const float AP1_STEEP[]; /* All pass filter coeffs for interpolation and decimation by a factor of 2 */
extern const float AP2_STEEP[]; /* All pass filter coeffs for interpolation and decimation by a factor of 2 */
+extern const Word16 AP1_STEEP_FX[]; /* All pass filter coeffs for interpolation and decimation by a factor of 2 */
+extern const Word16 AP2_STEEP_FX[]; /* All pass filter coeffs for interpolation and decimation by a factor of 2 */
+
extern const float STEPS[]; /* Granuality in conversion from lpc to lsp */
extern const float cos_fb_exc[];
+extern const Word16 cos_fb_exc_fx[32];
extern const float recip_order[];
extern const float win_lpc_shb[]; /* Window for calculating SHB LPC coeffs */
extern const float win_lpc_hb_wb[];
extern const float ola_win_shb_switch_fold[];
extern const float win_flatten[]; /* Window for calculating whitening filter for SHB excitation */
+extern const Word16 win_flatten_fx[];
extern const float win_flatten_4k[]; /* Window for calculating whitening filter for WB excitation */
+extern const Word16 win_flatten_4k_fx[];
extern const float window_shb[]; /* Overlap add window for SHB excitation used in anal and synth */
extern const float window_shb_32k[]; /* Upsampled overlap add window for SHB excitation used transition generation */
extern const float subwin_shb[]; /* Short overlap add window for SHB excitation used in anal and synth */
@@ -614,6 +697,8 @@ extern const float window_wb[];
extern const float subwin_wb[]; /* Short overlap add window for SHB excitation used in anal and synth */
extern const float Hilbert_coeffs[4 * NUM_HILBERTS][HILBERT_ORDER1 + 1];
+extern const Word16 Hilbert_coeffs_fx[4 * NUM_HILBERTS][HILBERT_ORDER1 + 1];
+
extern const float wac[];
extern const float wac_swb[];
@@ -629,6 +714,9 @@ extern const float SHBCB_FrameGain16[];
extern const float full_band_bpf_1[][5];
extern const float full_band_bpf_2[][5];
extern const float full_band_bpf_3[][5];
+extern const Word16 full_band_bpf_1_fx[][5];
+extern const Word16 full_band_bpf_2_fx[][5];
+extern const Word16 full_band_bpf_3_fx[][5];
extern const float lsf_q_cb_4b[]; /* 4 bit differential scalar quantizer table for TD SWB BWE LSFs 1 and 2*/
extern const float lsf_q_cb_3b[]; /* 3 bit differential scalar quantizer table for TD SWB BWE LSFs 3, 4 and 5*/
@@ -645,7 +733,8 @@ extern const float swb_hr_env_code1[]; /* HR SWB BWE - envelope Q table - fir
extern const float swb_hr_env_code2[]; /* HR SWB BWE - envelope Q table - second two subabnds in non-transient frames*/
extern const float swb_hr_env_code3[]; /* HR SWB BWE - envelope Q table - two subabnds in transient frames */
-extern const float allpass_poles_3_ov_2[];
+extern const float allpass_poles_3_ov_2_flt[];
+extern const Word16 allpass_poles_3_ov_2[];
extern const float decimate_3_ov_2_lowpass_num[];
extern const float decimate_3_ov_2_lowpass_den[];
@@ -662,6 +751,11 @@ extern const float F_2_5[64];
extern const int16_t swb_bwe_trans_subband[];
extern const int16_t swb_bwe_trans_subband_width[];
+
+extern const Word16 sqrt_swb_bwe_trans_subband_width_fx[];
+extern const Word16 sqrt_swb_bwe_subband_fx_L1[];
+extern const Word16 sqrt_swb_bwe_subband_fx_L2[];
+
extern const int16_t swb_bwe_subband[];
extern const Word16 fb_bwe_subband[];
extern const Word16 fb_bwe_sm_subband[];
@@ -700,6 +794,8 @@ extern const float hp12800_16000[];
extern const double cu15[28][3];
extern const double cu4[6][3];
+extern const Word16 cu15_fx[28][3];
+extern const Word16 cu4_fx[6][3];
extern const int16_t ct2[7][13];
/*------------------------------------------------------------------------------*
@@ -856,7 +952,7 @@ extern const int16_t nextstate[STATES][2];
extern const int16_t fine_gain_bits[];
extern const float *const finegain[];
-
+extern const Word16* finegain_fx[5];
extern const uint8_t hBitsMinus1_N01[2];
extern const uint8_t hBitsMinus1_N02[65];
extern const uint8_t hBitsMinus1_N03[65];
@@ -950,10 +1046,12 @@ extern const int16_t bits_lagIndices_modeNormal[NB_SWB_SUBBANDS];
extern const int16_t subband_offsets_12KBPS[NB_SWB_SUBBANDS];
extern const int16_t subband_offsets_16KBPS[NB_SWB_SUBBANDS];
extern const int16_t subband_search_offsets[NB_SWB_SUBBANDS];
+
extern const int16_t bw_SPT_tbl[2][SPT_SHORTEN_SBNUM];
/* HQ_HARMONIC mode */
extern const int16_t bits_lagIndices_mode0_Har[NB_SWB_SUBBANDS_HAR_SEARCH_SB];
+
extern const int16_t subband_offsets_sub5_13p2kbps_Har[NB_SWB_SUBBANDS_HAR];
extern const int16_t subband_search_offsets_13p2kbps_Har[NB_SWB_SUBBANDS_HAR_SEARCH_SB];
extern const int16_t subband_offsets_sub5_16p4kbps_Har[NB_SWB_SUBBANDS_HAR];
@@ -985,24 +1083,41 @@ extern const float UVG1CB_WB[UVG1_CBSIZE][2];
extern const float UVG2CB1_WB[UVG2_CBSIZE][5];
extern const float UVG2CB2_WB[UVG2_CBSIZE][5];
+extern const Word16 UVG1CB_WB_FX[UVG1_CBSIZE][2];
+extern const Word16 UVG2CB1_WB_FX[UVG2_CBSIZE][5];
+extern const Word16 UVG2CB2_WB_FX[UVG2_CBSIZE][5];
+
extern const float UVG1CB_NB[UVG1_CBSIZE][2];
extern const float UVG2CB1_NB[UVG2_CBSIZE][5];
extern const float UVG2CB2_NB[UVG2_CBSIZE][5];
+extern const Word16 UVG1CB_NB_FX[UVG1_CBSIZE][2];
+extern const Word16 UVG2CB1_NB_FX[UVG2_CBSIZE][5];
+extern const Word16 UVG2CB2_NB_FX[UVG2_CBSIZE][5];
+
extern const float frac_4sf[NB_SUBFR + 2];
extern const float erb_WB[NUM_ERB_WB + 1];
extern const float erb_NB[NUM_ERB_NB + 1];
+extern const Word16 erb_WB_fx[NUM_ERB_WB + 1];
+extern const Word16 erb_NB_fx[NUM_ERB_NB + 1];
+
extern const float AmpCB1_WB[64][10];
+extern const Word16 AmpCB1_WB_fx[640];
extern const float AmpCB2_WB[64][NUM_ERB_WB - 11];
+extern const Word16 AmpCB2_WB_fx[64 * (NUM_ERB_WB - 13)];
extern const float AmpCB1_NB[64][10];
+extern const Word16 AmpCB1_NB_fx[640];
+
extern const float AmpCB2_NB[64][NUM_ERB_NB - 11];
+extern const Word16 AmpCB2_NB_fx[64 * (NUM_ERB_NB - 13)];
extern const float PowerCB_WB[64][2];
extern const float PowerCB_NB[64][2];
extern const float sinc[8][12];
+extern const Word16 sinc_fx[8][12];
extern const float hvq_thr_adj[5];
extern const float hvq_peak_cb[1024];
@@ -1487,7 +1602,7 @@ extern const int16_t config_LSF_BWE[];
//basops
extern const Word32 BASOP_util_normReciprocal[CHEAP_NORM_SIZE];
extern const Word16 f_atan_expand_range[MAXSFTAB - (MINSFTAB - 1)];
-extern const Word16 shift_Isqrt_lc[];
+
extern const Word16 Grid[];
extern const Word16 pwAlpha[10];
@@ -1497,4 +1612,10 @@ extern const Word16 acos_slope[128];
extern const Word16 cos_coef_new[4];
extern const Word16 cos_table[512];
extern const Word16 inter4_1_fx[];
+extern const Word16 wac_h[];
+extern const Word16 wac_l[];
+extern const short dsDiracsTab[65];
+extern const Word16 pwf_fx[17];
+extern const Word32 inverse_table[];
+extern const Word16 cos_diff_table[512];
#endif
diff --git a/lib_com/scale_mem_fx.c b/lib_com/scale_mem_fx.c
index 1b7f34b37beaef16be04cd9d9999fe4d258bd751..2232c6425fdcca289e6241eac884e7501192fc0e 100644
--- a/lib_com/scale_mem_fx.c
+++ b/lib_com/scale_mem_fx.c
@@ -286,6 +286,7 @@ void Rescale_mem(
return;
}
+//note_ : also present in tools_fx.c which one to take is an issue?
/*-------------------------------------------------------------------*
* Scale_sig32
* Note: In order to save complexity, call function only, if exp0 != 0
diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h
index 4ac58a89ad37b73fd0b3a9a495b95a4033383815..819d5837c79c54f8e2975de512a5254f578bb266 100644
--- a/lib_com/stat_com.h
+++ b/lib_com/stat_com.h
@@ -61,11 +61,18 @@ typedef struct
int16_t lag;
int16_t nH;
int16_t nH_4kHz;
+ // lag and lag_fx to be same
+ Word16 lag_fx;
+ Word16 nH_fx;
+ Word16 nH_4kHz_fx;
+
float upper_cut_off_freq_of_interest;
float upper_cut_off_freq;
Word16 upper_cut_off_freq_of_interest_fx;
Word16 upper_cut_off_freq_fx;
int32_t sampling_rate;
+ Word16 Fs_fx;
+ Word16 Q;
} DTFS_STRUCTURE;
typedef struct
diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c
index 3e685fd3fe6bd64e1415316cf3f3ddca0776cfec..1ff2476a441e6de9717474d2d45ac522bd9e475a 100644
--- a/lib_com/swb_bwe_com_fx.c
+++ b/lib_com/swb_bwe_com_fx.c
@@ -33,10 +33,352 @@
#include
#include "options.h"
#include "prot_fx2.h"
+#include "prot_fx1.h"
#include "basop_util.h"
#include "rom_com.h"
+ /*==========================================================================*/
+ /* FUNCTION : Word16 WB_BWE_gain_pred_fx () */
+ /*--------------------------------------------------------------------------*/
+ /* PURPOSE : predict WB frequency envelopes for 0b WB BWE */
+ /*--------------------------------------------------------------------------*/
+ /* INPUT ARGUMENTS : */
+ /* _Word16 *core_dec_freq i : Frequency domain core decoded signal */
+ /* _Word16 coder_type i : coding type */
+ /* _Word16 prev_coder_type i : coding type of last frame */
+ /* _Word16 prev_WB_fenv i : envelope for last frame */
+ /* _Word16 *voice_factors i : voicing factors //Q15 */
+ /* _Word16 pitch_buf[] i : pitch buffer //Q6 */
+ /* _Word16 last_core_brate i : previous frame core bitrate */
+ /* _Word16 last_wb_bwe_ener i : previous frame wb bwe signal energy */
+ /*--------------------------------------------------------------------------*/
+ /* OUTPUT ARGUMENTS : */
+ /* _Word16 *WB_fenv, o : WB frequency envelopes Q3 */
+ /*--------------------------------------------------------------------------*/
+ /* INPUT/OUTPUT ARGUMENTS : */
+ /*--------------------------------------------------------------------------*/
+ /* RETURN ARGUMENTS : */
+ /* _Word16 mode */
+ /*--------------------------------------------------------------------------*/
+ /* CALLED FROM : */
+ /*==========================================================================*/
+
+Word16 WB_BWE_gain_pred_fx(
+ Word16 *WB_fenv, /* o : WB frequency envelopes */
+ const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */
+ const Word16 coder_type, /* i : coding type */
+ Word16 prev_coder_type, /* i : coding type of last frame */
+ Word16 prev_WB_fenv, /* i : envelope for last frame */
+ Word16 *voice_factors, /* i : voicing factors //Q15 */
+ const Word16 pitch_buf[], /* i : pitch buffer //Q6 */
+ Word32 last_core_brate, /* i : previous frame core bitrate */
+ Word16 last_wb_bwe_ener, /* i : previous frame wb bwe signal energy */
+ Word16 Q_syn, /* i : synthesis scaling */
+ Word16 last_extl_fx, /* i : extl. layer for last frame */
+ Word16 tilt_wb_fx
+)
+{
+ Word32 enerL;
+ Word16 n_freq, mode, pitch;
+ Word16 ener_var_flag = 0;
+ Word16 voice_factor, enerL_16, enerL_40, enerL_64;
+ Word16 env_var_flag = 0;
+ Word16 exp;
+ Word16 tmp, tmp1;
+ Word32 L_tmp;
+ Word32 L_WB_fenv0, L_WB_fenv1;
+ Word16 pitch_buf_tmp[4];
+ Word16 alfa = 32767;
+ move16();
+
+ mode = NORMAL;
+ move16();
+
+ enerL = L_deposit_l(0);
+ FOR(n_freq = 128; n_freq < 192; n_freq++)
+ {
+#ifdef BASOP_NOGLOB
+ enerL = L_mac0_sat(enerL, core_dec_freq[n_freq], core_dec_freq[n_freq]); /*2(Q_syn) */
+#else
+ enerL = L_mac0(enerL, core_dec_freq[n_freq], core_dec_freq[n_freq]); /*2(Q_syn) */
+#endif
+ }
+
+ L_WB_fenv0 = L_deposit_l(0);
+ FOR(n_freq = 192; n_freq < 224; n_freq++)
+ {
+#ifdef BASOP_NOGLOB
+ L_WB_fenv0 = L_mac0_sat(L_WB_fenv0, core_dec_freq[n_freq], core_dec_freq[n_freq]);/*2*Q_syn */
+#else
+ L_WB_fenv0 = L_mac0(L_WB_fenv0, core_dec_freq[n_freq], core_dec_freq[n_freq]);/*2*Q_syn */
+#endif
+ }
+
+ L_WB_fenv1 = L_deposit_l(0);
+ FOR(n_freq = 224; n_freq < 256; n_freq++)
+ {
+#ifdef BASOP_NOGLOB
+ L_WB_fenv1 = L_mac0_sat(L_WB_fenv1, core_dec_freq[n_freq], core_dec_freq[n_freq]);/*2*Q_syn */
+#else
+ L_WB_fenv1 = L_mac0(L_WB_fenv1, core_dec_freq[n_freq], core_dec_freq[n_freq]);/*2*Q_syn */
+#endif
+ }
+
+ L_tmp = sum16_32_fx(voice_factors, 4);
+ voice_factor = extract_l(L_shr(L_tmp, 2));/*Q13 */
+ Copy_Scale_sig(pitch_buf, pitch_buf_tmp, 4, -1);
+ pitch = sum16_fx(pitch_buf_tmp, 4);
+ move16(); /*Q5 */
+
+ L_tmp = L_shr(enerL, 4);
+ test();
+ IF(GT_32(L_max(L_WB_fenv1, L_WB_fenv0), L_tmp) && GT_16(9856, pitch))
+ {
+ ener_var_flag = 1;
+ move16();
+ }
+
+ test();
+#ifdef BASOP_NOGLOB
+ IF(GT_32(L_WB_fenv0, L_shl_sat(L_WB_fenv1, 1)))
+#else
+ IF(GT_32(L_WB_fenv0, L_shl(L_WB_fenv1, 1)))
+#endif
+ {
+ exp = norm_l(L_WB_fenv0);
+ tmp = extract_h(L_shl(L_WB_fenv0, exp));
+ tmp = div_s(16384, tmp); /*Q(15+14-2*Q_syn-exp) */
+ L_tmp = L_shr(Mult_32_16(L_shl(L_WB_fenv1, 1), tmp), sub(15, exp));/*2*Q_syn+15+exp-15->2*Q_syn+exp */
+ /*L_tmp Q15 */
+ tmp = extract_l(L_tmp);
+ alfa = s_max(tmp, 3277);/*Q15 */
+ L_WB_fenv0 = Mult_32_16(L_WB_fenv0, alfa);/*2*Q_syn+15-15->2*Q_syn */
+ }
+#ifdef BASOP_NOGLOB
+ ELSE IF(GT_32(L_WB_fenv1, L_shl_sat(L_WB_fenv0, 1)) && NE_16(coder_type, UNVOICED))
+#else
+ ELSE IF(GT_32(L_WB_fenv1, L_shl(L_WB_fenv0, 1)) && NE_16(coder_type, UNVOICED))
+#endif
+ {
+ exp = norm_l(L_WB_fenv1);
+ tmp = extract_h(L_shl(L_WB_fenv1, exp));
+ tmp = div_s(16384, tmp); /*Q(15+14-2*Q_syn-exp) */
+ L_tmp = L_shr(Mult_32_16(L_shl(L_WB_fenv0, 1), tmp), sub(15, exp));/*2*Q_syn+15+exp-15->2*Q_syn+exp */
+ /*L_tmp Q15 */
+ tmp = extract_l(L_tmp);
+ alfa = s_max(tmp, 3277);/*Q15 */
+ L_WB_fenv1 = Mult_32_16(L_WB_fenv1, alfa);/*2*Q_syn+15-15->2*Q_syn */
+ }
+
+ if (L_WB_fenv0 == 0)
+ {
+ L_WB_fenv0 = L_deposit_l(1);
+ }
+
+ if (L_WB_fenv1 == 0)
+ {
+ L_WB_fenv1 = L_deposit_l(1);
+ }
+
+ if (enerL == 0)
+ {
+ enerL = L_deposit_l(1);
+ }
+
+#ifdef BASOP_NOGLOB
+ L_tmp = L_add_sat(L_WB_fenv0, L_WB_fenv1); /* In 2*Q_syn */
+#else
+ L_tmp = L_add(L_WB_fenv0, L_WB_fenv1); /* In 2*Q_syn */
+#endif
+ exp = norm_l(L_tmp);
+ tmp = extract_h(L_shl(L_tmp, exp));
+ /*exp = sub(exp, 30-(2*Q_syn+6)); //+6(/64) */
+ exp = sub(exp, sub(30, add(shl(Q_syn, 1), 6))); /*+6(/64) */
+
+ tmp = div_s(16384, tmp);
+ L_tmp = L_deposit_h(tmp);
+ L_tmp = Isqrt_lc(L_tmp, &exp);
+
+#ifdef BASOP_NOGLOB
+ WB_fenv[0] = round_fx_sat(L_shl_sat(L_tmp, sub(exp, 12))); /* Q3 */
+#else
+ WB_fenv[0] = round_fx(L_shl(L_tmp, sub(exp, 12))); /* Q3 */
+#endif
+ test();
+ test();
+ IF(NE_16(coder_type, AUDIO) && NE_16(coder_type, UNVOICED) && ener_var_flag == 0)
+ {
+#ifdef BASOP_NOGLOB
+ WB_fenv[0] = add_sat(WB_fenv[0], mult_r_sat(WB_fenv[0], 16384));
+#else
+ WB_fenv[0] = add(WB_fenv[0], mult_r(WB_fenv[0], 16384));
+#endif
+ move16();
+ }
+
+ exp = norm_l(enerL);
+ tmp = extract_h(L_shl(enerL, exp));
+ exp = sub(exp, sub(30, shl(Q_syn, 1)));
+
+ tmp = div_s(16384, tmp);
+ L_tmp = L_deposit_h(tmp);
+ L_tmp = Isqrt_lc(L_tmp, &exp);
+#ifdef BASOP_NOGLOB
+ enerL_16 = round_fx_sat(L_shl_sat(L_tmp, sub(exp, 15))); /* Q0 */
+#else
+ enerL_16 = round_fx(L_shl(L_tmp, sub(exp, 15))); /* Q0 */
+#endif
+ enerL_40 = mult_r(6554, enerL_16); /*1/40 in Q18 ->Q3 */
+
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF(NE_16(coder_type, TRANSITION) && NE_16(coder_type, AUDIO) && NE_16(coder_type, UNVOICED) &&
+ GT_16(enerL_40, WB_fenv[0]) && GT_16(alfa, 29491) && !(EQ_16(coder_type, prev_coder_type) &&
+ GT_16(WB_fenv[0], prev_WB_fenv)))
+ {
+ IF(WB_fenv[0] != 0)
+ {
+ exp = norm_s(WB_fenv[0]);
+ tmp = div_s(shl(1, sub(14, exp)), WB_fenv[0]); /*Q(29-exp-3) */
+ L_tmp = L_mult(enerL_40, tmp); /*Q(30-exp) */
+#ifdef BASOP_NOGLOB
+ tmp = round_fx_sat(L_shl_sat(L_tmp, sub(exp, 2))); /*Q12 */
+#else
+ tmp = round_fx(L_shl(L_tmp, sub(exp, 2))); /*Q12 */
+#endif
+ tmp = s_min(tmp, 16384);
+ L_tmp = L_shr(L_mult0(tmp, WB_fenv[0]), 12);/*Q15 */
+ WB_fenv[0] = extract_l(L_tmp);/*Q3 */
+ }
+
+ IF(GT_16(WB_fenv[0], prev_WB_fenv))
+ {
+ /*WB_fenv[0]= add(mult_r(9830, WB_fenv[0]), mult_r(22938, prev_WB_fenv)); move16();//Q3 */
+ WB_fenv[0] = round_fx(L_mac(L_mult(9830, WB_fenv[0]), 22938, prev_WB_fenv));/*Q3 */
+ }
+ }
+
+ L_tmp = L_mult0(voice_factor, 77);
+ tmp1 = extract_l(L_shr(L_tmp, 13));
+
+ exp = norm_s(pitch);
+ tmp = div_s(shl(1, sub(14, exp)), pitch); /*Q(29-exp-5) */
+ L_tmp = L_mult0(tmp1, tmp); /*29-exp-5->24-exp */
+#ifdef BASOP_NOGLOB
+ tmp = round_fx_sat(L_shl_sat(L_tmp, add(exp, 6))); /*14 */
+#else
+ tmp = round_fx(L_shl(L_tmp, add(exp, 6))); /*14 */
+#endif
+ tmp1 = s_max(tmp, 8192);
+ alfa = s_min(24576, tmp1);/*Q14 */
+
+ L_tmp = L_mult0(alfa, WB_fenv[0]);/*Q14+Q3->Q17 */
+ L_tmp = L_shr(L_tmp, 14);/*Q3 */
+ tmp = extract_l(L_tmp);
+
+ enerL = L_deposit_l(enerL_16);
+ enerL = L_shl(enerL, 6); /*Q6 */
+#ifdef BASOP_NOGLOB
+ tmp1 = i_mult_sat(3, WB_fenv[0]);/*Q3 */
+#else
+ tmp1 = i_mult(3, WB_fenv[0]);/*Q3 */
+#endif
+ L_tmp = L_mult0(tmp1, WB_fenv[0]); /*Q6 */
+
+ test();
+ test();
+ test();
+ IF(GT_16(shr(enerL_16, 3), tmp) && GT_32(enerL, L_tmp) && NE_16(prev_coder_type, UNVOICED) && WB_fenv[0] != 0)
+ {
+ env_var_flag = 1;
+ move16();
+ enerL_64 = mult_r(4096, enerL_16);/* 1/64 in Q18 ->Q3 */
+
+ exp = norm_s(WB_fenv[0]);
+ tmp = div_s(shl(1, sub(14, exp)), WB_fenv[0]); /*Q(29-exp-3) */
+ L_tmp = L_mult(enerL_64, tmp); /*Q(30-exp) */
+#ifdef BASOP_NOGLOB
+ tmp = round_fx_sat(L_shl_sat(L_tmp, sub(exp, 2))); /*Q12 */
+#else
+ tmp = round_fx(L_shl(L_tmp, sub(exp, 2))); /*Q12 */
+#endif
+ tmp = s_min(tmp, 16384);
+ L_tmp = L_shr(L_mult0(tmp, WB_fenv[0]), 12);/*Q3 */
+ WB_fenv[0] = extract_l(L_tmp);/*Q3 */
+
+ IF(GT_16(WB_fenv[0], prev_WB_fenv))
+ {
+ /*WB_fenv[0] = add(mult_r(9830, WB_fenv[0]), mult_r(22938, prev_WB_fenv));//Q3 */
+ WB_fenv[0] = round_fx(L_mac(L_mult(9830, WB_fenv[0]), 22938, prev_WB_fenv));/*Q3 */
+ }
+ }
+
+ test();
+ IF(EQ_16(coder_type, UNVOICED) || EQ_16(prev_coder_type, UNVOICED))
+ {
+ WB_fenv[0] = shr(WB_fenv[0], 1);
+ move16();/*Q3 */
+ }
+
+ IF(NE_16(coder_type, AUDIO))
+ {
+ tmp = mult_r(voice_factor, 19661); /*Q12 */
+ tmp = s_max(tmp, 4096);
+ exp = norm_s(tmp);
+ tmp = div_s(shl(1, sub(14, exp)), tmp); /*Q(29-exp-12) */
+ L_tmp = L_mult(WB_fenv[0], tmp); /*Q(21-exp) */
+
+ WB_fenv[0] = round_fx(L_shl(L_tmp, sub(exp, 2))); /*Q3 */
+ tmp1 = mult_r(328, pitch);/*Q7 */
+ tmp = s_min(s_max(tmp1, 16), 256);/*Q7 */
+ L_tmp = L_shr(L_mult0(WB_fenv[0], tmp), 7);/*Q3 */
+ /*WB_fenv[0] = saturate(L_tmp); //Q3 */
+#ifdef BASOP_NOGLOB
+ WB_fenv[0] = round_fx_sat(L_shl_sat(L_tmp, 16)); /*Q3 */
+#else
+ WB_fenv[0] = round_fx(L_shl(L_tmp, 16)); /*Q3 */
+#endif
+ }
+ test();
+ IF(GT_32(last_core_brate, ACELP_8k00) && GT_16(WB_fenv[0], last_wb_bwe_ener))
+ {
+ /*WB_fenv[0]= add(mult_r(29491, last_wb_bwe_ener), mult_r(3277, WB_fenv[0]));//Q3 */
+ WB_fenv[0] = round_fx(L_mac(L_mult(29491, last_wb_bwe_ener), 3277, WB_fenv[0]));/*Q3 */
+ }
+
+ IF(NE_16(last_extl_fx, WB_BWE) && LT_16(tilt_wb_fx, 128))
+ {
+ WB_fenv[0] = mult_r(s_min(16384, shl(tilt_wb_fx, 8)), WB_fenv[0]);
+ }
+
+ IF(env_var_flag == 1)
+ {
+ WB_fenv[1] = add(WB_fenv[0], mult_r(WB_fenv[0], 16384));
+ move16();
+ WB_fenv[0] = mult_r(24576, WB_fenv[0]);
+ move16();/*Q3 */
+ }
+ ELSE
+ {
+ WB_fenv[1] = WB_fenv[0];
+ move16();
+ }
+
+ test();
+ IF(EQ_16(coder_type, UNVOICED) || EQ_16(prev_coder_type, UNVOICED))
+ {
+ WB_fenv[1] = shr(WB_fenv[1], 1);
+ move16();/*Q3 */
+ }
+
+ return (mode);
+}
+
/*-------------------------------------------------------------------*
* calc_norm_envelop_lf_fx()
*
@@ -53,77 +395,1853 @@ void calc_norm_envelop_lf_fx(
Word16 *efreq /* i : ending frequency index */
)
{
- Word16 lookback, env_index, n_freq, n_lag_now, n_lag;
-
- *sfreq = 2;
+ Word16 lookback, env_index, n_freq, n_lag_now, n_lag;
+
+ *sfreq = 2;
+ move16();
+ IF(EQ_16(hq_generic_offset, HQ_GENERIC_FOFFSET_24K4))
+ {
+ *efreq = 146;
+ move16();
+ if (EQ_16(HQ_mode, HQ_GEN_FB))
+ {
+ *efreq = 306;
+ move16();
+ }
+ IF(LT_16(add(shl(sub(328, *efreq), 1), 1), *L_swb_norm))
+ {
+ *L_swb_norm = add(shl(sub(328, *efreq), 1), 1);
+ }
+ }
+ ELSE
+ {
+ *efreq = 130;
+ move16();
+ if (EQ_16(HQ_mode, HQ_GEN_FB))
+ {
+ *efreq = 290;
+ move16();
+ }
+ IF(LT_16(add(shl(sub(400,*efreq),1),1),*L_swb_norm))
+ {
+ *L_swb_norm = add(shl(sub(400,*efreq),1),1);
+ }
+ }
+ lookback = shr(*L_swb_norm, 1);
+ env_index = 0;
+ move16();
+ n_lag_now = *L_swb_norm;
+ move16();
+
+ FOR(n_freq = 0; n_freq < lookback; n_freq++)
+ {
+ Word16 tmp;
+ Word32 L_tmp;
+
+ L_tmp = L_deposit_l(1);
+ tmp = add(lookback, n_freq);
+ FOR(n_lag = 0; n_lag < tmp; n_lag++)
+ {
+ L_tmp = L_add(L_tmp, L_abs(SWB_signal[n_lag]));
+ }
+ envelope[env_index] = L_tmp;
+ move32();
+ env_index = add(env_index, 1);
+ }
+
+ FOR(; n_freq < *efreq; n_freq++)
+ {
+ /* Apply MA filter */
+ Word32 L_tmp = L_deposit_l(1);
+ FOR(n_lag = 0; n_lag < n_lag_now; n_lag++)
+ {
+ L_tmp = L_add(L_tmp, L_abs(SWB_signal[add(sub(n_freq, lookback), n_lag)]));
+ }
+
+ envelope[env_index] = L_tmp;
+ move32();
+ env_index = add(env_index, 1);
+ }
+
+ return;
+}
+/*-------------------------------------------------------------------*
+ * calc_normal_length()
+ *
+ *-------------------------------------------------------------------*/
+
+void calc_normal_length_fx(
+ const Word16 core, /* i : core */
+ const Word16 *sp, /* i : input signal */
+ const Word16 mode, /* i : input mode */
+ const Word16 extl, /* i : extension layer */
+ Word16 *L_swb_norm, /* o : normalize length */
+ Word16 *prev_L_swb_norm, /*i/o : last normalize length */
+ Word16 Q_syn
+)
+{
+ Word16 i, n_freq, n_band, THRES;
+ const Word16 *pit;
+ Word16 peak, mag;
+ Word16 L_swb_norm_trans, L_swb_norm_norm, L_swb_norm_harm, L_swb_norm_cur;
+ Word16 N;
+ Word32 L_mean, L_tmp, L_tmp1;
+
+ THRES = 4;
+ move16();
+ test();
+ test();
+ if (EQ_16(core, HQ_CORE) || EQ_16(extl, SWB_BWE) || EQ_16(extl, FB_BWE))
+ {
+ THRES = 8;
+ move16();
+ }
+
+ N = 16;
+ move16();
+ test();
+ test();
+ if (EQ_16(core, HQ_CORE) && (EQ_16(mode, HQ_HARMONIC) || EQ_16(mode, HQ_HVQ)))
+ {
+ N = 13;
+ move16();
+ }
+
+ n_band = 0;
+ move16();
+ pit = sp;
+ move16();/*Q_syn */
+ FOR(i = 0; i < N; i++)
+ {
+ peak = 0;
+ move16();
+ L_mean = L_deposit_l(0);
+
+ FOR(n_freq = 0; n_freq < 16; n_freq++)
+ {
+ mag = abs_s(*pit);
+
+ peak = s_max(peak, mag);
+ L_mean = L_add(L_mean, mag);/*Q_syn */
+ pit++;
+ }
+
+ L_tmp = L_mult0(peak, 15 + THRES);/*Q_syn */
+ IF(EQ_16(THRES, 8))
+ {
+ L_tmp1 = L_shl(Mult_32_16(L_mean, 32767), 3);
+ }
+ ELSE
+ {
+ L_tmp1 = L_shl(Mult_32_16(L_mean,32767), 2);
+ }
+
+ test();
+ if (GT_32(L_tmp, L_tmp1) && (GT_16(peak, shl(10, Q_syn))))
+ {
+ n_band = add(1, n_band);
+ }
+ }
+
+ IF(EQ_16(core, ACELP_CORE))
+ {
+ L_swb_norm_trans = add(4, mult(n_band, 8192));
+ L_swb_norm_norm = add(8, mult(n_band, 16384));
+
+ L_tmp = L_add(65536, L_mult0(n_band, 4096)); /*Q16 */
+ L_swb_norm_harm = s_max(round_fx(L_shl(L_tmp, 5)), 24); /* Q0 */
+
+ IF(EQ_16(mode, HARMONIC))
+ {
+ L_swb_norm_cur = L_swb_norm_harm;
+ move16();
+ }
+ ELSE IF(EQ_16(mode, NORMAL))
+ {
+ L_swb_norm_cur = L_swb_norm_norm;
+ move16();
+ }
+ ELSE
+ {
+ L_swb_norm_cur = L_swb_norm_trans;
+ move16();
+ }
+ *L_swb_norm = shr(add(L_swb_norm_cur, *prev_L_swb_norm), 1);
+ move16();
+ *prev_L_swb_norm = L_swb_norm_cur;
+ move16();
+ }
+ ELSE
+ {
+ test();
+ IF(EQ_16(mode,HQ_HARMONIC) || EQ_16(mode,HQ_HVQ))
+ {
+ L_tmp = L_add(65536, L_mult(n_band, 2560));
+ L_swb_norm_cur = round_fx(L_shl(L_tmp, 5));/*Q0 */
+ }
+ ELSE
+ {
+ L_tmp = L_add(65536, L_mult(n_band, 2048)); /*Q16 */
+ L_swb_norm_cur = round_fx(L_shl(L_tmp, 3));/*Q0 */
+ }
+
+ /**L_swb_norm = add(mult_r(L_swb_norm_cur, 3277), mult_r(*prev_L_swb_norm, 29491)); */
+ *L_swb_norm = round_fx(L_mac(L_mult(L_swb_norm_cur, 3277), *prev_L_swb_norm, 29491));
+ *prev_L_swb_norm = L_swb_norm_cur;
+ move16();
+ }
+
+ return;
+}
+/*-------------------------------------------------------------------*
+ * calc_tilt_bwe()
+ *
+ * calculate tilt parameter
+ *-------------------------------------------------------------------*/
+
+Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 */
+ const Word16 *sp, /* i : input signal */
+ const Word16 exp_sp, /* i : Exp of inp signal */
+ const Word16 N /* i : signal length */
+)
+{
+ Word16 i, j;
+ Word32 L_ener, L_ener_tot, L_temp;
+ Word16 tmp1, tmp2;
+ const Word16 *ptr;
+ Word16 exp2;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+
+ BASOP_SATURATE_WARNING_OFF_EVS
+
+ /* this is required for adaptative precision energy summation loop, do not remove */
+ Overflow = 0;
+ move16();
+ exp2 = 0;
+ move16();
+
+ ptr = sp;
+ move16();
+ L_ener_tot = L_deposit_l(1);
+
+ /* Divide Frame Length by 32 */
+ FOR(j = shr(N, 5); j > 0; j--)
+ {
+#ifdef BASOP_NOGLOB /* Critical Overflow and all those below*/
+ tmp1 = mult_ro(*ptr++, 8192, &Overflow); /* Divide by 4 */
+#else
+ tmp1 = mult_r(*ptr++, 8192); /* Divide by 4 */
+#endif
+ L_ener = L_mult0(tmp1, tmp1);
+ /* With the shift by 4 and the L_mult0, no overflow possible for 32 samples */
+ FOR(i = 1; i < 32; i++)
+ {
+#ifdef BASOP_NOGLOB /* Critical Overflow */
+ tmp1 = mult_ro(*ptr++, 8192, &Overflow); /* Divide by 4 */
+ L_ener = L_mac0_o(L_ener, tmp1, tmp1, &Overflow);
+#else
+ tmp1 = mult_r(*ptr++, 8192); /* Divide by 4 */
+ L_ener = L_mac0(L_ener, tmp1, tmp1);
+#endif
+ }
+#ifdef BASOP_NOGLOB /* Critical Overflow */
+ L_ener = L_shr_o(L_ener, exp2, &Overflow);
+ L_temp = L_add_o(L_ener_tot, L_ener, &Overflow);
+#else
+ L_ener = L_shr(L_ener, exp2);
+ L_temp = L_add(L_ener_tot, L_ener);
+#endif
+ IF(Overflow != 0)
+ {
+ L_ener_tot = L_shr(L_ener_tot, 1);
+ L_ener = L_shr(L_ener, 1);
+ exp2 = add(exp2, 1);
+ /* this is required, do not remove */
+ Overflow = 0;
+ move16();
+ }
+#ifdef BASOP_NOGLOB /* Critical Overflow */
+ L_ener_tot = L_add_o(L_ener_tot, L_ener, &Overflow);
+#else
+ L_ener_tot = L_add(L_ener_tot, L_ener);
+#endif
+ }
+#ifdef BASOP_NOGLOB
+ L_ener = L_deposit_l(abs_s(sub_o(sp[1], sp[0], &Overflow)));
+#else
+ L_ener = L_deposit_l(abs_s(sub(sp[1], sp[0])));
+#endif
+ FOR(i = 2; i < N; i++)
+ {
+ /* Eq to (sp[i] - sp[i-1]) * (sp[i-1] - sp[i-2]) < 0 */
+#ifdef BASOP_NOGLOB
+ tmp1 = sub_o(sp[i], sp[i - 1], &Overflow);
+ tmp2 = sub_o(sp[i - 1], sp[i - 2], &Overflow);
+#else
+ tmp1 = sub(sp[i], sp[i - 1]);
+ tmp2 = sub(sp[i - 1], sp[i - 2]);
+#endif
+ tmp2 = mult(tmp1, tmp2);
+ tmp1 = abs_s(tmp1);
+ /* to Get either 0 or -1 in 'tmp2' */
+ tmp2 = shr(tmp2, 15);
+ /* this allows this code */
+ L_ener = L_msu0(L_ener, tmp2, tmp1);
+ /* instead of this one */
+ /* test(); */
+ /* if (tmp2 < 0) */
+ /* { */
+ /* L_ener = L_mac0(L_ener, 1, tmp1); */
+ /* } */
+ /* it saves one op */
+ }
+
+ tmp1 = norm_l(L_ener_tot);
+ L_temp = L_shl(L_ener_tot, tmp1);
+ tmp1 = sub(add(31 + 4, exp2), add(tmp1, shl(exp_sp, 1)));
+ L_temp = Isqrt_lc(L_temp, &tmp1);
+
+ /* *tilt_flt = (float)(r1/sqrt(r0)); */
+ exp2 = norm_l(L_ener);
+ L_temp = Mult_32_16(L_temp, round_fx(L_shl(L_ener, exp2)));
+ exp2 = sub(exp2, tmp1);
+ exp2 = add(exp2, exp_sp);
+
+ /* Put in Q24 */
+ L_temp = L_shr(L_temp, sub(exp2, 24));
+
+ BASOP_SATURATE_WARNING_ON_EVS
+
+ return L_temp;
+}
+/*-------------------------------------------------------------------*
+ * calc_norm_envelop()
+ *
+ * calculate normalized parameter
+ *-------------------------------------------------------------------*/
+
+void calc_norm_envelop_fx(
+ const Word16 SWB_signal[], /* i : SWB spectrum Q_syn*/
+ Word32 *envelope, /* o : normalized envelope Q_syn*/
+ const Word16 L_swb_norm, /* i : length of envelope Q0 */
+ const Word16 SWB_flength, /* i : Length of input/output */
+ const Word16 st_offset /* i : offset */
+)
+{
+ Word16 i, lookback, env_index, n_freq, n_lag_now, n_lag, tmp;
+
+ lookback = shr(L_swb_norm, 1);
+ move16();
+ env_index = add(swb_bwe_subband[0], st_offset);
+ n_lag_now = L_swb_norm;
+ move16();
+ tmp = sub(add(SWB_flength, st_offset), L_swb_norm);
+ FOR(n_freq = sub(add(swb_bwe_trans_subband[0], st_offset), lookback); n_freq < tmp; n_freq++)
+ {
+ /* Apply MA filter */
+ Word32 L_tmp = L_deposit_l(0);
+ FOR(n_lag = 0; n_lag < n_lag_now; n_lag++)
+ {
+ L_tmp = L_add(L_tmp, abs_s(SWB_signal[n_freq + n_lag]));
+ }
+ envelope[env_index] = L_tmp;
+ move32();
+ env_index++;
+ }
+
+ i = 0;
+ move16();
+ tmp = sub(add(SWB_flength, st_offset), lookback);
+ FOR(n_freq = sub(add(SWB_flength, st_offset), L_swb_norm); n_freq < tmp; n_freq++)
+ {
+ Word32 L_tmp;
+
+ n_lag_now = sub(L_swb_norm, i);
+ /* Apply MA filter */
+ L_tmp = L_deposit_l(0);
+ FOR(n_lag = 0; n_lag < n_lag_now; n_lag++)
+ {
+ L_tmp = L_add(L_tmp, abs_s(SWB_signal[n_freq + n_lag]));
+ }
+ envelope[env_index] = L_tmp;
+ move32();
+ env_index++;
+ i++;
+ }
+
+ return;
+}
+
+/*==========================================================================*/
+/* FUNCTION : void WB_BWE_decoding_fx () */
+/*--------------------------------------------------------------------------*/
+/* PURPOSE : WB BWE decoder */
+/*--------------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _Word16 *core_dec_freq i : Frequency domain core decoded signal Q_syn*/
+/* _Word16 *WB_fenv i : WB frequency envelopes Q3 */
+/* _Word16 WB_flength i : Length of input/output */
+/* _Word16 mode i : classification for WB signal */
+/* _Word16 prev_mode i : classification for last frame */
+/* _Word16 last_extl i : extl. layer for last frame */
+/* _Word16 extl i : extension layer */
+/* _Word16 coder_type i : coding type */
+/* _Word16 total_brate i : core layer bitrate */
+/* _Word16 prev_coder_type i : coding type of last frame */
+/* _Word16 Q_syn i : Q format */
+/*--------------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _Word16 *WB_signal, o : WB signal in MDCT domain Q_syn */
+/*--------------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _Word32 *prev_Energy, i/o: energy for last frame Q_syn */
+/* _Word16 *prev_WB_fenv, i/o: envelope for last frame Q3 */
+/* _Word16 *prev_L_wb_norm, i/o: length for last frame wb norm Q0 */
+/* _Word16 *Seed, i/o: random generator seed Q15 */
+/* _Word16 *prev_flag, i/o: attenu flag of last frame Q0 */
+/*--------------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : */
+/* _ None */
+/*--------------------------------------------------------------------------*/
+/* CALLED FROM : */
+/*==========================================================================*/
+void WB_BWE_decoding_fx(
+ const Word16 *core_dec_freq,/* i : Frequency domain core decoded signal */
+ Word16 *WB_fenv, /* i : WB frequency envelopes */
+ Word32 *WB_signal_32, /* o : WB signal in MDCT domain */
+ const Word16 WB_flength, /* i : Length of input/output */
+ const Word16 mode, /* i : classification for WB signal */
+ const Word16 last_extl, /* i : extl. layer for last frame */
+ Word32 *prev_Energy, /* i/o: energy for last frame */
+ Word16 *prev_WB_fenv, /* i/o: envelope for last frame */
+ Word16 *prev_L_wb_norm, /* i/o: length for last frame wb norm */
+ const Word16 extl, /* i : extension layer */
+ const Word16 coder_type, /* i : coding type */
+ const Word32 total_brate, /* i : core layer bitrate */
+ Word16 *Seed, /* i/o: random generator seed */
+ Word16 *prev_flag, /* i/o: attenu flag of last frame */
+ Word16 prev_coder_type, /* i : coding type of last frame */
+ Word16 Q_syn,
+ Word16 *Q_syn_hb /*o : Q value of WB_signal_32 */
+)
+{
+ Word16 n_freq, n_band;
+ Word16 i, L;
+ Word32 envelope[L_FRAME16k];
+ Word32 energy, EnergyL;
+ Word32 *pit1;
+ Word16 WB_signal[L_FRAME16k];
+ Word16 L_wb_norm, wfenv[2];
+ Word16 alfa, beta;
+ Word16 flag = 0;
+ Word16 core_type = 1;
+ Word16 tmp, tmp1, exp, tmp2;
+ Word32 L_tmp, L_tmp1, L_tmp2;
+ Word32 prev_ener_alpha, prev_ener_beta;
+ Word16 signum[L_FRAME16k];
+ Word16 inv_L_wb_norm, weight;
+
+ calc_normal_length_fx(ACELP_CORE, core_dec_freq, mode, extl, &L_wb_norm, prev_L_wb_norm, Q_syn);
+ set32_fx(WB_signal_32, 0, L_FRAME16k);
+ set16_fx(WB_signal, 0, L_FRAME16k);
+
+ /* copy excitation */
+ test();
+ if (NE_16(coder_type, AUDIO) && LE_32(total_brate, ACELP_8k00))
+ {
+ core_type = 0;
+ move16();
+ }
+
+ IF(core_type == 0)
+ {
+ Copy(&core_dec_freq[160], &WB_signal[240], 80);
+ }
+ ELSE
+ {
+ Copy(&core_dec_freq[80], &WB_signal[240], 80);
+ }
+
+ /* calculate envelope */
+ calc_norm_envelop_fx(WB_signal, envelope, L_wb_norm, WB_flength, 0);
+ test();
+ IF(coder_type != UNVOICED && total_brate <= ACELP_8k00)
+ {
+ exp = norm_s(L_wb_norm);
+ inv_L_wb_norm = shl(div_s(shl(1, sub(14, exp)), L_wb_norm), sub(exp, 14)); /* Q(15) */
+ IF(NE_16(mode, HARMONIC))
+ {
+ tmp = add(shl(inv_L_wb_norm, 1), inv_L_wb_norm);
+ weight = s_max(s_min(tmp, 16384), 8192);
+ }
+ ELSE
+ {
+ weight = 8192;
+ move16();
+ }
+ FOR(n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[4]; n_freq++)
+ {
+ signum[n_freq] = 1;
+ IF(WB_signal[n_freq] < 0)
+ {
+ signum[n_freq] = -1;
+ move16();
+ WB_signal[n_freq] = negate(WB_signal[n_freq]);
+ move16();
+ }
+ L_tmp = Mult_32_16(envelope[n_freq], inv_L_wb_norm); /* Q_syn */
+ L_tmp = Mult_32_16(L_tmp, 14746); /* Q_syn */
+ L_tmp1 = L_deposit_l(WB_signal[n_freq]); /* Q_syn */
+ L_tmp = L_sub(L_tmp1, L_tmp); /* Q_syn */
+ WB_signal[n_freq] = extract_l(L_tmp); /* Q_syn */
+ IF(L_tmp > 0)
+ {
+ tmp = sub(18022, weight); /* Q15 */
+ WB_signal[n_freq] = extract_l(Mult_32_16(L_tmp, tmp)); /* Q_syn */
+ }
+
+ IF(NE_16(signum[n_freq], 1))
+ {
+ WB_signal[n_freq] = negate(WB_signal[n_freq]);
+ move16();
+ }
+ }
+ }
+
+ /* Normalize with envelope */
+ FOR(n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[4]; n_freq++)
+ {
+ IF(envelope[n_freq] != 0)
+ {
+ exp = norm_l(envelope[n_freq]);
+ tmp = extract_h(L_shl(envelope[n_freq], exp));
+ exp = sub(sub(30, exp), Q_syn);
+ tmp = div_s(16384, tmp);
+ L_tmp = L_shr(L_mult0(WB_signal[n_freq], tmp), add(exp, Q_syn)); /*Q15 */
+ WB_signal[n_freq] = extract_l(L_tmp); /*Q15 */
+ }
+ ELSE
+ {
+ WB_signal[n_freq] = shl(WB_signal[n_freq],sub(15,Q_syn)); /*Q15 */ move16();
+ }
+ }
+
+ L = 1;
+ move16();
+ if (EQ_16(mode, HARMONIC))
+ {
+ L = 4;
+ move16();
+ }
+
+ IF(EQ_16(coder_type, UNVOICED))
+ {
+ FOR(n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[4]; n_freq++)
+ {
+ *Seed = extract_l(L_mac0(20101L, *Seed, 12345));
+ L_tmp = L_shl(*Seed, add(Q_syn, 1));
+ WB_signal_32[n_freq] = L_tmp;
+ move32();
+ }
+ }
+ ELSE
+ {
+ FOR(n_band = 0; n_band < 4; n_band += L)
+ {
+ energy = L_deposit_l(0);
+ FOR(n_freq = swb_bwe_subband[n_band]; n_freq < swb_bwe_subband[n_band + L]; n_freq++)
+ {
+ L_tmp = L_mult(WB_signal[n_freq],WB_signal[n_freq]); /*Q31 */
+ energy = L_add(energy,L_shr(L_tmp,6)); /*Q25 */
+ }
+
+ tmp = sub(swb_bwe_subband[n_band + L] , swb_bwe_subband[n_band]);
+ tmp = div_s(1,tmp);/*Q15 */
+ energy = Mult_32_16(energy,tmp); /*Q(15+25-15)->Q(25) */
+
+ exp = norm_l(energy);
+ L_tmp1 = L_shl(energy, exp);
+ exp = 31 - exp - (25);
+ move16();
+ L_tmp1 = Isqrt_lc(L_tmp1, &exp); /*Q(31-exp) */
+
+ FOR(n_freq = swb_bwe_subband[n_band]; n_freq < swb_bwe_subband[n_band + L]; n_freq++)
+ {
+ L_tmp2 = Mult_32_16(L_tmp1, WB_signal[n_freq]);
+ WB_signal_32[n_freq] = L_shl(L_tmp2, sub(add(exp, Q_syn), 15));
+ move32();
+ }
+ }
+ }
+
+ EnergyL = L_deposit_l(0);
+ IF(core_type == 1)
+ {
+ test();
+ IF(NE_16(prev_coder_type, AUDIO) && LE_32(total_brate, ACELP_8k00))
+ {
+ FOR(i = 160; i < 240; i++)
+ {
+ EnergyL = L_add(abs_s(core_dec_freq[i]), EnergyL);
+ }
+ }
+ ELSE
+ {
+ FOR(i = 80; i < 240; i++)
+ {
+ EnergyL = L_add(abs_s(core_dec_freq[i]),EnergyL);
+ }
+ }
+
+ IF(LE_32(total_brate, ACELP_8k00))
+ {
+ alfa = 26214;
+ move16(); /*0.8f in Q15; */
+ beta = 10240;
+ move16();/*1.25f in Q13; */
+ }
+ ELSE
+ {
+ alfa = 16384;
+ move16();/* 0.5f in Q15; */
+ beta = 16384;
+ move16();/*2.0f in Q13 */
+ }
+ }
+ ELSE
+ {
+ IF(EQ_16(prev_coder_type,AUDIO))
+ {
+ FOR(i = 80; i < 240; i++)
+ {
+ EnergyL = L_add(abs_s(core_dec_freq[i]), EnergyL);/*Q_syn */
+ }
+ }
+ ELSE
+ {
+ FOR(i = 160; i < 240; i++)
+ {
+ EnergyL = L_add(abs_s(core_dec_freq[i]), EnergyL);
+ }
+ }
+
+ test();
+ IF(EQ_16(prev_coder_type,coder_type) && GT_16(WB_fenv[0],prev_WB_fenv[0]))
+ {
+ alfa = 13107;
+ move16();/*.4 in Q15 */
+ beta = 20480;
+ move16(); /*2.5 in Q13 */
+ }
+ ELSE
+ {
+ alfa = 19661;
+ move16();/*.6 in Q15 */
+ beta = 13681;
+ move16();/*1.67 in Q13 */
+ }
+
+ test();
+ test();
+ test();
+ IF(EQ_16(coder_type,GENERIC) || (GT_32(EnergyL,L_shr(*prev_Energy,1)) && GT_32(*prev_Energy,L_shr(EnergyL,1)) && EQ_16(*prev_flag,1)))
+ {
+ WB_fenv[0] = shr(WB_fenv[0], 1);
+ move16();
+ WB_fenv[1] = shr(WB_fenv[1], 1);
+ move16();
+ flag = 1;
+ move16();
+ }
+ }
+ L_tmp1 = Mult_32_16(EnergyL, prev_WB_fenv[0]);/*Qsyn+3-15 */
+ L_tmp2 = Mult_32_16(*prev_Energy, WB_fenv[0]);/*Q_syn+3-15 */
+ prev_ener_alpha = Mult_32_16(*prev_Energy, alfa);/*Q_syn+15-15->Q_syn */
+ prev_ener_beta = L_shl(Mult_32_16(*prev_Energy, beta), 2); /*Q_syn+13-15+2 ->Q_syn */
+
+ test();
+ test();
+ IF((EQ_16(mode, HARMONIC) && GT_16(shr(WB_fenv[0], 2), WB_fenv[1])) || EQ_16(mode, NORMAL))
+ {
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF(EQ_16(last_extl, WB_BWE) &&
+ ((EQ_16(prev_coder_type, AUDIO) && NE_16(coder_type, AUDIO)) ||
+ (NE_16(prev_coder_type, AUDIO) && EQ_16(coder_type, AUDIO))) && LE_32(total_brate, ACELP_8k00))
+ {
+ IF(GT_16(WB_fenv[0], prev_WB_fenv[0]))
+ {
+ /*wfenv[0]= add(mult_r(9830, WB_fenv[0]), mult_r(22938, prev_WB_fenv[0]));//Q3 */
+ wfenv[0] = round_fx(L_mac(L_mult(9830, WB_fenv[0]), 22938, prev_WB_fenv[0]));/*Q3 */
+ /*wfenv[1]= add(mult_r(9830, WB_fenv[1]), mult_r(22938, prev_WB_fenv[1]));//Q3 */
+ wfenv[1] = round_fx(L_mac(L_mult(9830, WB_fenv[1]), 22938, prev_WB_fenv[1]));/*Q3 */
+ }
+ ELSE
+ {
+ /*wfenv[0]= add(mult_r(16384,WB_fenv[0]),mult_r(16384,prev_WB_fenv[0]));//Q3 */
+ wfenv[0] = round_fx(L_mac(L_mult(16384,WB_fenv[0]),16384,prev_WB_fenv[0]));/*Q3 */
+ /*wfenv[1]= add(mult_r(13108,WB_fenv[1]),mult_r(13108,prev_WB_fenv[1]));//Q3 */
+ wfenv[1] = round_fx(L_mac(L_mult(13108,WB_fenv[1]),13108,prev_WB_fenv[1]));/*Q3 */
+ }
+ }
+ ELSE IF(EQ_16(last_extl, WB_BWE) && LT_32(L_tmp1, L_tmp2) && GT_16(WB_fenv[0], prev_WB_fenv[0]) &&
+ NE_16(coder_type, AUDIO) && NE_16(coder_type, UNVOICED) && LE_32(total_brate, ACELP_8k00))
+ {
+ /*wfenv[0]= add(mult_r(9830,WB_fenv[0]),mult_r(22938,prev_WB_fenv[0]));//Q3 */
+ wfenv[0] = round_fx(L_mac(L_mult(9830, WB_fenv[0]), 22938, prev_WB_fenv[0]));/*Q3 */
+ /*wfenv[1]= add(mult_r(9830,WB_fenv[1]),mult_r(22938,prev_WB_fenv[1]));//Q3 */
+ wfenv[1] = round_fx(L_mac(L_mult(9830, WB_fenv[1]), 22938, prev_WB_fenv[1]));/*Q3 */
+ }
+ ELSE IF(EQ_16(last_extl, WB_BWE) && GT_32(EnergyL, prev_ener_alpha) && GT_32(prev_ener_beta, EnergyL) &&
+ NE_16(prev_coder_type, UNVOICED))
+ {
+ /*wfenv[0] = add(shr(WB_fenv[0],1), shr(prev_WB_fenv[0],1));//Q3 */
+ wfenv[0] = round_fx(L_mac(L_mult(WB_fenv[0], 16384), prev_WB_fenv[0], 16384));/*Q3 */
+ /*wfenv[1] = add(shr(WB_fenv[1],1), shr(prev_WB_fenv[1],1));//Q3 */
+ wfenv[1] = round_fx(L_mac(L_mult(WB_fenv[1], 16384), prev_WB_fenv[1], 16384));/*Q3 */
+ }
+ ELSE
+ {
+ wfenv[0] = WB_fenv[0];
+ move16();
+ wfenv[1] = WB_fenv[1];
+ move16();
+ }
+ FOR(n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[2]; n_freq++)
+ {
+ WB_signal_32[n_freq] = Mult_32_16(WB_signal_32[n_freq], wfenv[0]);
+ move32();/* Q_syn+3+1 */
+ }
+
+ FOR(n_freq = swb_bwe_subband[2]; n_freq < swb_bwe_subband[4]; n_freq++)
+ {
+ WB_signal_32[n_freq] = Mult_32_16(WB_signal_32[n_freq], wfenv[1]);
+ move32();/* Q_syn+3+1 */
+ }
+
+ prev_WB_fenv[0] = wfenv[0];
+ move16();
+ prev_WB_fenv[1] = wfenv[1];
+ move16();
+ }
+ ELSE
+ {
+ wfenv[0] = add(shr(WB_fenv[0],1), shr(WB_fenv[1],1));/*Q3 */
+
+ test();
+ test();
+ IF(EQ_16(last_extl,WB_BWE) && GT_32(EnergyL,L_shr(*prev_Energy,1)) && GT_32(*prev_Energy,L_shr(EnergyL,1)))
+ {
+ L_tmp1 = L_mac(L_mult(8192,wfenv[0]),12288, prev_WB_fenv[0]);
+ wfenv[0] = round_fx(L_mac(L_tmp1, 12288, prev_WB_fenv[1]));
+ }
+ FOR(n_freq = swb_bwe_subband[0]; n_freq < swb_bwe_subband[4]; n_freq++)
+ {
+ WB_signal_32[n_freq] = Mult_32_16(WB_signal_32[n_freq], wfenv[0]);
+ move32();/* Q_syn+3+1 */
+ }
+ prev_WB_fenv[0] = wfenv[0];
+ move16();
+ prev_WB_fenv[1] = wfenv[0];
+ move16();
+ }
+
+ *prev_flag = flag;
+ move16();
+ *prev_Energy = EnergyL;
+ move32();
+ pit1 = &WB_signal_32[240];
+
+ FOR(n_freq = 0; n_freq < 16; n_freq++)
+ {
+ tmp1 = extract_l(L_mult0(n_freq, 1638));/*Q15 */
+ tmp2 = add(6554, tmp1);/*Q15 */
+ L_tmp1 = Mult_32_16(*pit1, tmp2); /*Q_syn+3+1 */
+ *(pit1++) = L_tmp1;
+ move32();
+ }
+
+ IF(EQ_16(core_type, 1))
+ {
+ pit1 = &WB_signal_32[280];
+ FOR(n_freq = 0; n_freq < 40; n_freq++)
+ {
+ tmp1 = extract_l(L_mult0(n_freq, 655));/*Q15 */
+ tmp2 = sub(32767, tmp1);
+ L_tmp1 = Mult_32_16(*pit1, tmp2); /*Q_syn+3+1 */
+ *(pit1++) = L_tmp1;
+ move32();
+ }
+ }
+ ELSE
+ {
+ pit1 = &WB_signal_32[300];
+ FOR(n_freq = 0; n_freq < 20; n_freq++)
+ {
+ tmp1 = extract_l(L_mult0(n_freq, 1311));/*Q15 */
+ tmp2 = sub(32767, tmp1);
+ L_tmp1 = Mult_32_16(*pit1, tmp2); /*Q_syn+3+1 */
+ *(pit1++) = L_tmp1;
+ move32();
+ }
+ }
+ pit1 = &WB_signal_32[240];
+ tmp = Find_Max_Norm32(pit1, 80);
+ FOR(i = 0; i < 80; i++)
+ {
+ L_tmp = *pit1;
+ *(pit1++) = L_shl(L_tmp, sub(tmp, 1));
+ move32();
+ }
+ *Q_syn_hb = add(Q_syn, add(tmp, 3));
+ return;
+}
+
+
+/*==========================================================================*/
+/* FUNCTION : void SWB_BWE_decoding_fx() */
+/*--------------------------------------------------------------------------*/
+/* PURPOSE : SWB BWE decoder */
+/*--------------------------------------------------------------------------*/
+/* INPUT ARGUMENTS */
+/* _(Word16*) core_dec_freq :Frequency domain core decoded signal Q_syn */
+/* _(Word16) SWB_flength :Length of input/output Q0 */
+/* _(Word16) mode :classification for SWB signal */
+/* _(Word16) tilt_nb :tilt of synthesis wb signal Q11 */
+/* _(Word16) st_offset :offset value due to different core */
+/* _(Word16) Q_syn :Q format */
+/*--------------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _(Word16*)SWB_fenv : SWB frequency envelopes Q1 */
+/* _(Word16*)prev_Energy : energy for last frame Q3 */
+/* _(Word16*)prev_SWB_fenv : envelope for last frame Q1 */
+/* _(Word16*)prev_L_swb_norm : length for last frame wb norm Q0 */
+/* _(Word16*)Seed : random generator seed Q0 */
+/*--------------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _(Word16*)SWB_signal : SWB signal in MDCT domain Q0 */
+/* _(Word16*)frica_flag : fricative signal flag Q0 */
+/*--------------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : */
+/* _ None */
+/*--------------------------------------------------------------------------*/
+
+void SWB_BWE_decoding_fx(
+ const Word16 *core_dec_freq,/* i : Frequency domain core decoded signal */
+ Word16 *SWB_fenv, /* i/o: SWB frequency envelopes */
+ Word32 *SWB_signal_32, /* o : SWB signal in MDCT domain */
+ const Word16 SWB_flength, /* i : Length of input/output */
+ const Word16 mode, /* i : classification for SWB signal */
+ Word16 *frica_flag, /* o : fricative signal flag */
+ Word16 *prev_Energy, /* i/o: energy for last frame */
+ Word16 *prev_SWB_fenv, /* i/o: envelope for last frame */
+ Word16 *prev_L_swb_norm, /* i/o: length for last frame wb norm */
+ const Word16 tilt_nb, /* i : tilt of synthesis wb signal */
+ Word16 *Seed, /* i/o: random generator seed */
+ const Word16 st_offset, /* i : offset value due to different core */
+ Word16 *prev_weight, /* i/o: excitation weight value of last frame */
+ const Word16 extl, /* i : extension layer */
+ Word16 Q_syn
+ , const Word16 last_extl /* i : extension layer of last frame */
+)
+{
+ Word16 n_freq, n_band, L, L_swb_norm;
+ Word32 *pit1_32;
+ Word16 *pit1;
+ Word32 envelope[L_FRAME32k];
+ Word32 fenvL, EnergyL, Energy, energy, L_mean;
+ Word16 fenvL_16, EnergyL_16, Energy_16, tmp, exp, exp1;
+ Word16 SWB_signal[L_FRAME32k];
+ Word16 mean, factor, factor1, tmp1, tmp2, tmp3, tmp_exp, tmp_ener, weight, wfenv;
+ Word32 L_tmp, L_tmp3, L_tmp4, Ltmp_ener, L_tmp1;
+ Word32 L_energy;
+ Word16 signum[L_FRAME32k];
+ Word16 inv_L_swb_norm;
+
+ fenvL = L_deposit_l(0);
+ EnergyL = L_deposit_l(0);
+ FOR(n_freq = 224 + st_offset; n_freq < swb_bwe_trans_subband[0] + st_offset; n_freq++)
+ {
+#ifdef BASOP_NOGLOB
+ fenvL = L_mac0_sat(fenvL, core_dec_freq[n_freq], core_dec_freq[n_freq]); /*2*Q_syn */
+#else
+ fenvL = L_mac0(fenvL, core_dec_freq[n_freq], core_dec_freq[n_freq]); /*2*Q_syn */
+#endif
+ }
+
+ FOR(n_freq = 16; n_freq < L_FRAME; n_freq++)
+ {
+#ifdef BASOP_NOGLOB
+ EnergyL = L_mac0_sat(EnergyL, core_dec_freq[n_freq], core_dec_freq[n_freq]); /*2*Q_syn */
+#else
+ EnergyL = L_mac0(EnergyL, core_dec_freq[n_freq], core_dec_freq[n_freq]); /*2*Q_syn */
+#endif
+ }
+
+ fenvL_16 = 0;
+ move16();
+ IF(fenvL != 0)
+ {
+ exp = norm_l(fenvL); /* In 2*Q_syn */
+ tmp = extract_h(L_shl(fenvL, exp));
+ exp = sub(exp, sub(30, add(shl(Q_syn, 1), 4))); /*+4(/16) */
+
+ tmp = div_s(16384, tmp);
+ L_tmp = L_deposit_h(tmp);
+ L_tmp = Isqrt_lc(L_tmp, &exp);
+
+ fenvL_16 = round_fx(L_shl(L_tmp, sub(exp, 12))); /* Q3 */
+ }
+ IF(GT_16(fenvL_16, shl(SWB_fenv[0], 5)))
+ {
+ fenvL_16 = shl(SWB_fenv[0], 2);
+ move16();
+ }
+ EnergyL = Mult_32_16(EnergyL, 17476); /*2*Q_syn+3; 17476=(1/15) in Q18 */
+ EnergyL_16 = 0;
+ move16();
+ IF(EnergyL != 0)
+ {
+ exp = norm_l(EnergyL); /* In 2*Q_syn+3 */
+ tmp = extract_h(L_shl(EnergyL, exp));
+ exp = sub(exp, sub(30, add(shl(Q_syn, 1), 3 + 4))); /*+4(/16) */
+
+ tmp = div_s(16384, tmp);
+ L_tmp = L_deposit_h(tmp);
+ L_tmp = Isqrt_lc(L_tmp, &exp);
+
+#ifdef BASOP_NOGLOB
+ EnergyL_16 = round_fx_sat(L_shl_sat(L_tmp, sub(exp, 12))); /* Q3 */
+#else
+ EnergyL_16 = round_fx(L_shl(L_tmp, sub(exp, 12))); /* Q3 */
+#endif
+ }
+ calc_normal_length_fx(ACELP_CORE, core_dec_freq, mode, extl, &L_swb_norm, prev_L_swb_norm, Q_syn);
+
+ set16_fx(SWB_signal, 0, L_FRAME32k);
+ IF(EQ_16(mode, TRANSIENT))
+ {
+ Energy = L_deposit_l(0);
+ FOR(n_band = 0; n_band < SWB_FENV_TRANS; n_band++)
+ {
+ Energy = L_mac(Energy, SWB_fenv[n_band], SWB_fenv[n_band]); /*Q(2*1+1)->Q3 */
+ }
+ exp = norm_s(SWB_FENV_TRANS);
+ tmp = div_s(shl(1, sub(14, exp)), SWB_FENV_TRANS); /*Q(29-exp) */
+ L_tmp = Mult_32_16(Energy, tmp); /*Q(3+29-exp+1-16)->Q(17-exp) */
+ Energy_16 = round_fx(L_shl(L_tmp, add(exp, 2))); /*Q3 */
+
+ /* Reconstruct excitation from LF signal */
+ Copy(&core_dec_freq[112], &SWB_signal[240 + st_offset], 128);
+ Copy(&core_dec_freq[112], &SWB_signal[368 + st_offset], 128);
+ Copy(&core_dec_freq[176], &SWB_signal[496 + st_offset], 64);
+
+ /* calculate envelope */
+ calc_norm_envelop_fx(SWB_signal, envelope, L_swb_norm, SWB_flength, st_offset);
+
+ /* Normalize with envelope */
+ tmp_exp = sub(15, Q_syn);
+ FOR(n_freq = swb_bwe_trans_subband[0] + st_offset; n_freq < swb_bwe_trans_subband[SWB_FENV_TRANS] + st_offset; n_freq++)
+ {
+ IF(envelope[n_freq] != 0)
+ {
+ exp = norm_l(envelope[n_freq]);
+ tmp = extract_h(L_shl(envelope[n_freq], exp));
+ exp = sub(sub(30, exp), Q_syn);
+ tmp = div_s(16384, tmp); /*Q(15+exp) */
+ L_tmp = L_shr(L_mult0(SWB_signal[n_freq], tmp), add(exp, Q_syn)); /*Q15 */
+ SWB_signal[n_freq] = extract_l(L_tmp); /*Q15 */
+ }
+ ELSE
+ {
+ SWB_signal[n_freq] = shl(SWB_signal[n_freq], tmp_exp);
+ move16();/*Q15 */
+ }
+ }
+
+ FOR(n_band = 0; n_band < SWB_FENV_TRANS; n_band++)
+ {
+ energy = L_deposit_l(0);
+ tmp = add(swb_bwe_trans_subband[n_band + 1], st_offset);
+ FOR(n_freq = add(swb_bwe_trans_subband[n_band], st_offset); n_freq < tmp; n_freq++)
+ {
+#ifdef BASOP_NOGLOB
+ L_tmp = L_mult_sat(SWB_signal[n_freq], SWB_signal[n_freq]); /*Q31 */
+ energy = L_add_sat(energy, L_shr(L_tmp, 6)); /*Q25 */
+#else
+ L_tmp = L_mult(SWB_signal[n_freq], SWB_signal[n_freq]); /*Q31 */
+ energy = L_add(energy, L_shr(L_tmp, 6)); /*Q25 */
+#endif
+ }
+
+ IF(energy == 0)
+ {
+ Ltmp_ener = L_mult(sqrt_swb_bwe_trans_subband_width_fx[n_band], SWB_fenv[n_band]);/*Q13 */
+ tmp = add(swb_bwe_trans_subband[n_band + 1], st_offset);
+ FOR(n_freq = add(swb_bwe_trans_subband[n_band], st_offset); n_freq < tmp; n_freq++)
+ {
+ SWB_signal_32[n_freq] = L_shl(Mult_32_16(Ltmp_ener, SWB_signal[n_freq]), 2 + Q_syn);
+ move32();/*15+Qsyn */
+ }
+ }
+ ELSE
+ {
+ exp1 = norm_s(swb_bwe_trans_subband_width[n_band]);
+ tmp = div_s(shl(1,sub(14,exp1)),swb_bwe_trans_subband_width[n_band]); /*Q(29-exp1) */
+ energy = Mult_32_16(energy,tmp); /*Q(29-exp1+25-15)->Q(-exp1+39) */
+
+ exp = norm_l(energy);
+ L_tmp = L_shl(energy,exp);
+ /*exp = 31-exp-(-exp1+39); */
+ exp = sub(sub(exp1,exp),8);
+ L_tmp = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */
+
+ Ltmp_ener = Mult_32_16(L_tmp,SWB_fenv[n_band]);/*Q(31-exp+1+1-16)->Q(17-exp) */
+ tmp = add(swb_bwe_trans_subband[n_band + 1],st_offset);
+ tmp_exp = add(Q_syn,sub(exp,2));
+ FOR(n_freq = add(swb_bwe_trans_subband[n_band],st_offset); n_freq < tmp; n_freq++)
+ {
+ SWB_signal_32[n_freq] = L_shl(Mult_32_16(Ltmp_ener,SWB_signal[n_freq]), tmp_exp);
+ move32(); /*15+Qsyn */
+ }
+ }
+ }
+
+ FOR(n_band = 0; n_band < 8; n_band++)
+ {
+ L_tmp = L_mult(SWB_fenv[n_band / 4], SWB_fenv[n_band / 4]); /*Q3 */
+ prev_SWB_fenv[n_band] = round_fx(L_shl(L_tmp, 14)); /*Q1 */
+ }
+
+ FOR(n_band = 0; n_band < 6; n_band++)
+ {
+ L_tmp = L_mult(SWB_fenv[2 + n_band / 3], SWB_fenv[2 + n_band / 3]); /*Q3 */
+ prev_SWB_fenv[8 + n_band] = round_fx(L_shl(L_tmp, 14)); /*Q1 */
+ }
+
+ *prev_weight = 16384;
+ move16();
+ }
+ ELSE
+ {
+ Energy_16 = 0;
+ move16();
+ L_energy = L_deposit_l(0);
+ FOR(n_band = 0; n_band < SWB_FENV; n_band++)
+ {
+ L_energy = L_add(L_energy,SWB_fenv[n_band]); /*Q1 */
+ }
+ exp = norm_s(SWB_FENV);
+ tmp = div_s(shl(1,sub(14,exp)),SWB_FENV); /*Q(29-exp) */
+ L_tmp = Mult_32_16(L_energy,tmp); /*Q(1+29-exp+1)->Q(15-exp) */
+ Energy_16 = round_fx(L_shl(L_tmp,add(exp,4))); /*Q3 */
+
+ IF(NE_16(last_extl, SWB_BWE) && NE_16(last_extl,FB_BWE))
+ {
+ IF(Energy_16 < shr(EnergyL_16, 4) && EQ_16(extl, FB_BWE))
+ {
+ FOR(n_band = 0; n_band < SWB_FENV; n_band++)
+ {
+ SWB_fenv[n_band] = mult_r(SWB_fenv[n_band], 6554);
+ }
+ fenvL_16 = mult_r(fenvL_16, 6554);
+ }
+ Copy(SWB_fenv, prev_SWB_fenv, SWB_FENV);
+ }
+
+ IF(mode == HARMONIC)
+ {
+ Copy(core_dec_freq, &SWB_signal[240 + st_offset], 240);
+ Copy(&core_dec_freq[128], &SWB_signal[480 + st_offset], 80);
+ /* calculate envelope */
+ calc_norm_envelop_fx(SWB_signal, envelope, L_swb_norm, SWB_flength, st_offset);
+ }
+ ELSE
+ {
+ test();
+ test();
+ test();
+ test();
+ test();
+ test();
+ IF(EQ_16(mode, NOISE) || ((GT_16(Energy_16,EnergyL_16) || (GT_16(tilt_nb,14336) && GT_16(Energy_16,shr(EnergyL_16,1))) ||
+ GT_16(tilt_nb,24576)) && GT_16(Energy_16,600) && GT_16(fenvL_16,200)))
+ {
+ tmp = add(swb_bwe_subband[SWB_FENV], st_offset);
+ FOR(n_freq = add(swb_bwe_subband[0],st_offset); n_freq < tmp; n_freq++)
+ {
+ *Seed = extract_l(L_mac0(20101L, 12345,*Seed));
+ SWB_signal[n_freq] = mult_r(*Seed, 32767);
+ move16();/*Q15 */
+ }
+ if (NE_16(mode, NOISE))
+ {
+ *frica_flag = 1;
+ move16();
+ }
+ }
+ ELSE
+ {
+ /* modify SHB frequency envelopes when SHB spectrum is unflat */
+ FOR(n_band = 0; n_band < 13; n_band++)
+ {
+ IF(GT_16(mult_r(SWB_fenv[n_band],29491), SWB_fenv[n_band + 1]))
+ {
+ tmp = extract_l(L_mac0(26214, n_band, 492)); /*Q15; 0.015 in Q15 = 492 */
+ SWB_fenv[n_band + 1] = mult_r(SWB_fenv[n_band + 1], tmp);
+ move16();/*Q1 */
+ }
+
+ IF(GT_16(mult_r(SWB_fenv[n_band + 1],29491),SWB_fenv[n_band]))
+ {
+ tmp = extract_l(L_mac0(26214, n_band,492)); /*Q15; 0.015 in Q15 = 492 */
+ SWB_fenv[n_band] = mult_r(SWB_fenv[n_band],tmp);
+ move16();/*Q1 */
+ }
+ }
+ Copy(&core_dec_freq[112], &SWB_signal[240 + st_offset], 128);
+ Copy(&core_dec_freq[112], &SWB_signal[368 + st_offset], 128);
+ Copy(&core_dec_freq[176], &SWB_signal[496 + st_offset], 64);
+
+#ifdef BASOP_NOGLOB
+ tmp1 = add_sat(abs_s(SWB_signal[368 + st_offset]), abs_s(SWB_signal[369 + st_offset])); /*Q_syn */
+ tmp2 = add_sat(abs_s(SWB_signal[365 + st_offset]), abs_s(SWB_signal[366 + st_offset])); /*Q_syn */
+#else
+ tmp1 = add(abs_s(SWB_signal[368 + st_offset]), abs_s(SWB_signal[369 + st_offset])); /*Q_syn */
+ tmp2 = add(abs_s(SWB_signal[365 + st_offset]), abs_s(SWB_signal[366 + st_offset])); /*Q_syn */
+#endif
+ pit1 = &SWB_signal[368 + st_offset];
+ move16();
+
+ test();
+ IF((tmp2 == 0) || (LT_16(tmp2, mult_r(tmp1, 9830))))
+ {
+ tmp3 = 9830;
+ move16();/*0.3 in Q15 */
+ WHILE(LT_16(tmp3,32767))
+ {
+ *pit1 = mult_r(*pit1,tmp3);
+ move16(); /*Q_syn */
+ pit1++;
+#ifdef BASOP_NOGLOB
+ tmp3 = add_sat(tmp3, 3277); /*Q15 */
+#else
+ tmp3 = add(tmp3, 3277); /*Q15 */
+#endif
+ }
+ }
+ ELSE IF(LT_16(tmp2, tmp1))
+ {
+ exp = norm_s(tmp1);
+ tmp = div_s(shl(1,sub(14,exp)),tmp1); /*Q(29-exp) */
+#ifdef BASOP_NOGLOB
+ tmp3 = round_fx_sat(L_shl_sat(L_mult(tmp2,tmp),add(exp,2))); /*Q15 */
+#else
+ tmp3 = round_fx(L_shl(L_mult(tmp2,tmp),add(exp,2))); /*Q15 */
+#endif
+ WHILE(LT_16(tmp3, 32767))
+ {
+ *pit1 = mult_r(*pit1,tmp3);
+ move16(); /*Q_syn */
+ pit1++;
+#ifdef BASOP_NOGLOB
+ tmp3 = add_sat(tmp3,3277); /*Q15 */
+#else
+ tmp3 = add(tmp3,3277); /*Q15 */
+#endif
+ }
+ }
+
+ pit1 = &SWB_signal[367 + st_offset];
+ move16();
+ IF(GT_16(mult_r(tmp1,6554),tmp2))
+ {
+ /*20480 = 5 in Q12 */
+ FOR(tmp3 = 20480; tmp3 > 4096; tmp3 -= 2048)
+ {
+ *pit1 = round_fx(L_shl(L_mult(*pit1,tmp3),3)); /*Q_syn */
+ pit1--;
+ }
+ }
+
+#ifdef BASOP_NOGLOB
+ tmp1 = add_sat(abs_s(SWB_signal[496 + st_offset]),abs_s(SWB_signal[497 + st_offset])); /*Q_syn */
+ tmp2 = add_sat(add_sat(abs_s(SWB_signal[492 + st_offset]),abs_s(SWB_signal[493 + st_offset])),add_sat(abs_s(SWB_signal[494 + st_offset]),abs_s(SWB_signal[495 + st_offset])));
+#else
+ tmp1 = add(abs_s(SWB_signal[496 + st_offset]),abs_s(SWB_signal[497 + st_offset])); /*Q_syn */
+ tmp2 = add(add(abs_s(SWB_signal[492 + st_offset]),abs_s(SWB_signal[493 + st_offset])),add(abs_s(SWB_signal[494 + st_offset]),abs_s(SWB_signal[495 + st_offset])));
+#endif
+ pit1 = &SWB_signal[496 + st_offset];
+ move16();
+
+ test();
+ IF((tmp2 == 0) || (LT_16(tmp2,mult_r(tmp1,9830))))
+ {
+ tmp3 = 9830;
+ move16(); /*0.3 in Q15 */
+ WHILE(LT_16(tmp3,32767))
+ {
+ *pit1 = mult_r(*pit1,tmp3);
+ move16(); /*Q_syn */
+ pit1++;
+#ifdef BASOP_NOGLOB
+ tmp3 = add_sat(tmp3, 3277); /*Q15 */
+#else
+ tmp3 = add(tmp3, 3277); /*Q15 */
+#endif
+ }
+ }
+ ELSE IF(LT_16(tmp2,tmp1))
+ {
+ exp = norm_s(tmp1);
+ tmp = div_s(shl(1,sub(14,exp)),tmp1); /*Q(29-exp) */
+#ifdef BASOP_NOGLOB
+ tmp3 = round_fx_sat(L_shl_sat(L_mult(tmp2,tmp),add(exp,2))); /*Q15 */
+#else
+ tmp3 = round_fx(L_shl(L_mult(tmp2,tmp),add(exp,2))); /*Q15 */
+#endif
+ WHILE(LT_16(tmp3,32767))
+ {
+ *pit1 = mult_r(*pit1,tmp3);
+ move16();/*Q_syn */
+ pit1++;
+#ifdef BASOP_NOGLOB
+ tmp3 = add_sat(tmp3, 3277); /*Q15 */
+#else
+ tmp3 = add(tmp3, 3277); /*Q15 */
+#endif
+ }
+ }
+ pit1 = &SWB_signal[495 + st_offset];
+
+ L_tmp3 = L_deposit_h(tmp1); /*Q17 */
+ L_tmp4 = Mult_32_16(L_tmp3,1638); /*Q17 */
+ exp = 14;
+ move16();
+ IF(tmp2 != 0)
+ {
+ exp = norm_s(tmp2);
+ tmp = div_s(shl(1,sub(14,exp)),tmp2); /*Q(29-exp) */
+ L_tmp3 = L_shr(L_mult(tmp1,tmp),1); /*Q(30-exp+1)->Q(30-exp) (+1) due to *0.5 */
+ L_tmp4 = Mult_32_16(L_tmp3,1638); /*Q(30-exp) */
+ }
+
+ L_tmp1 = L_shl(1L,sub(30,exp));
+ WHILE(GT_32(L_tmp3,L_tmp1))
+ {
+ L_tmp = Mult_32_16(L_tmp3,*pit1); /*Q(16-exp) */
+ *pit1-- = round_fx(L_shl(L_tmp,exp)); /*Q_syn */
+ L_tmp3 = L_sub(L_tmp3,L_tmp4);
+ }
+
+ /* calculate envelope */
+ calc_norm_envelop_fx(SWB_signal, envelope, L_swb_norm, SWB_flength, st_offset);
+ }
+ }
+
+ /* Normalize with envelope */
+ test();
+ IF(*frica_flag == 0 && NE_16(mode, NOISE))
+ {
+ L = add(swb_bwe_subband[0],st_offset);
+ exp = norm_s(L_swb_norm);
+ inv_L_swb_norm = shl(div_s(shl(1,sub(14,exp)),L_swb_norm),sub(exp,14)); /* Q15 */
+
+ IF(NE_16(mode,HARMONIC))
+ {
+ tmp = add(shl(inv_L_swb_norm,1), inv_L_swb_norm);
+ weight = s_max(s_min(tmp,16384), 6554);
+ }
+ ELSE
+ {
+ weight = 6554;
+ move16();
+ }
+
+ weight = mac_r(L_mult(13107,weight) , 19661,(*prev_weight));
+
+ FOR(n_freq = L; n_freq < swb_bwe_subband[SWB_FENV] + st_offset; n_freq++)
+ {
+ signum[n_freq] = 1;
+ IF(SWB_signal[n_freq] < 0)
+ {
+ signum[n_freq] = -1;
+ move16();
+ SWB_signal[n_freq] = negate(SWB_signal[n_freq]);
+ move16();
+ }
+ L_tmp = Mult_32_16(envelope[n_freq],inv_L_swb_norm); /* Q_syn */
+ L_tmp1 = L_deposit_l(SWB_signal[n_freq]); /* Q_syn */
+ L_tmp = L_sub(L_tmp1,L_tmp); /* Q_syn */
+ IF(L_tmp > 0)
+ {
+ tmp = shr(weight,1); /* Q14 */
+ tmp = sub(19661,tmp); /* Q14 */
+ SWB_signal[n_freq] = extract_l(L_shl(Mult_32_16(L_tmp,tmp),1)); /* Q_syn */
+ }
+ ELSE
+ {
+ SWB_signal[n_freq] = extract_l(L_tmp); /* Q_syn */
+ }
+
+ IF(NE_16(signum[n_freq],1))
+ {
+ SWB_signal[n_freq] = negate(SWB_signal[n_freq]);
+ move16();
+ }
+ }
+
+ tmp_exp = sub(15,Q_syn);
+ FOR(n_freq = L; n_freq < swb_bwe_subband[SWB_FENV] + st_offset; n_freq++)
+ {
+ IF(envelope[n_freq] != 0)
+ {
+ exp = norm_l(envelope[n_freq]);
+ tmp = extract_h(L_shl(envelope[n_freq], exp));
+ exp = sub(sub(30,exp), Q_syn);
+ tmp = div_s(16384,tmp); /* Q(15+exp) */
+ L_tmp = L_shr(L_mult0(SWB_signal[n_freq],tmp), add(exp,Q_syn)); /* Q15 */
+ SWB_signal[n_freq] = extract_l(L_tmp); /* Q15 */
+ }
+ ELSE
+ {
+ SWB_signal[n_freq] = shl(SWB_signal[n_freq], tmp_exp);
+ move16(); /* Q15 */
+ }
+ }
+ *prev_weight = weight;
+ }
+ ELSE
+ {
+ exp = norm_s(L_swb_norm);
+ tmp = shl(div_s(shl(1,sub(14,exp)),L_swb_norm),sub(exp,14)); /* Q15 */
+ tmp = add(shl(tmp,1),tmp);
+ *prev_weight = s_max(s_min(tmp,16384),6554); /* Q15 */
+ }
+
+ IF(EQ_16(mode,HARMONIC))
+ {
+ pit1 = &SWB_signal[swb_bwe_subband[0] + st_offset];
+ move16();
+ FOR(n_band = 0; n_band < 19; n_band++)
+ {
+ L_mean = L_deposit_l(0);
+ FOR(n_freq = 0; n_freq < 16; n_freq++)
+ {
+ L_mean = L_add(L_mean,abs_s(*pit1)); /*Q15 */
+ pit1++;
+ }
+ mean = extract_l(Mult_32_16(L_mean,2048)); /*Q15 */
+ pit1 -= 16;
+ move16();
+ FOR(n_freq = 0; n_freq < 16; n_freq++)
+ {
+ if (LT_16(abs_s(*pit1),mean))
+ {
+ *pit1 = mult_r(*pit1,6554); /*Q15*/ move16();
+ }
+ pit1++;
+ }
+ }
+ }
+
+ L = 1;
+ move16();
+ if (EQ_16(mode,HARMONIC))
+ {
+ L = 2;
+ move16();
+ }
+
+ FOR(n_band = 0; n_band < SWB_FENV; n_band += L)
+ {
+ energy = L_deposit_l(0);
+ tmp = add(swb_bwe_subband[n_band + L],st_offset);
+ FOR(n_freq = add(swb_bwe_subband[n_band],st_offset); n_freq < tmp; n_freq++)
+ {
+ L_tmp = L_mult(SWB_signal[n_freq],SWB_signal[n_freq]); /*Q31 */
+ energy = L_add(energy,L_shr(L_tmp,6)); /*Q25 */
+ }
+
+ IF(energy == 0)
+ {
+ tmp_ener = sqrt_swb_bwe_subband_fx_L1[n_band];/*Q12 */ move16();
+ if (NE_16(L,1))
+ {
+ tmp_ener = sqrt_swb_bwe_subband_fx_L2[shr(n_band, 1)];/*Q12 */ move16();
+ }
+
+ tmp = add(swb_bwe_subband[n_band + L],st_offset);
+ tmp_exp = sub(Q_syn,12);
+ FOR(n_freq = add(swb_bwe_subband[n_band],st_offset); n_freq < tmp; n_freq++)
+ {
+ SWB_signal_32[n_freq] = L_shl(L_mult(tmp_ener,SWB_signal[n_freq]),tmp_exp); /*Qsyn */
+ }
+ }
+ ELSE
+ {
+ tmp = sub(swb_bwe_subband[n_band + L], swb_bwe_subband[n_band]);
+ exp1 = norm_s(tmp);
+ tmp = div_s(shl(1,sub(14,exp1)), tmp); /*Q(29-exp1) */
+ energy = Mult_32_16(energy, tmp); /*Q(29-exp1+25-15)->Q(-exp1+39) */
+
+ exp = norm_l(energy);
+ L_tmp = L_shl(energy, exp);
+ /*exp = 31-exp-(-exp1+39);move16(); */
+ exp = sub(sub(exp1,exp),8);
+ Ltmp_ener = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */
+
+ tmp = add(swb_bwe_subband[n_band + L],st_offset);
+ tmp_exp = add(Q_syn,sub(exp,15));
+ FOR(n_freq = add(swb_bwe_subband[n_band],st_offset); n_freq < tmp; n_freq++)
+ {
+ SWB_signal_32[n_freq] = L_shl(Mult_32_16(Ltmp_ener,SWB_signal[n_freq]),tmp_exp);
+ move32();/*Qsyn+16 */
+ }
+ }
+ }
+
+ IF(GT_16(*prev_Energy,add(Energy_16,shr(Energy_16,2))) && Energy_16 > 0)
+ {
+ weight = shr(div_s(Energy_16,*prev_Energy),1); /*Q15 */
+ }
+ ELSE
+ {
+ weight = 16384;
+ move16();/*Q15 */
+ }
+ L_tmp = L_mult(weight, prev_SWB_fenv[0]); /*Q17 */
+ L_tmp = L_mac(L_tmp, sub(32767, weight), SWB_fenv[0]);/*Q17 */
+ wfenv = round_fx(L_tmp); /*Q1 */
+
+ tmp = norm_s(wfenv);
+ IF(GT_16(tmp,4))
+ {
+ tmp = 12;
+ move16();
+ factor = fenvL_16;
+ move16();/*Q3 */
+ factor1 = mult_r(sub(shl(wfenv,2),fenvL_16),4096); /*Q3 */
+ }
+ ELSE
+ {
+ tmp = 14;
+ move16();
+ factor = shr(fenvL_16,2);/*Q1 */
+ factor1 = mult_r(sub(wfenv,factor), 4096); /*Q1 */
+ }
+
+ tmp2 = add(add(swb_bwe_subband[0],8),st_offset);
+ FOR(n_freq = add(swb_bwe_subband[0],st_offset); n_freq < tmp2; n_freq++)
+ {
+ L_tmp1 = Mult_32_16(SWB_signal_32[n_freq], factor);
+ SWB_signal_32[n_freq] = L_shl(L_tmp1, tmp - 1);
+ move32();/*15+Qsyn */
+ factor = add(factor, factor1); /*Q3 */
+ }
+
+ FOR(n_band = 0; n_band < 12; n_band++)
+ {
+ L_tmp = L_mult(weight, prev_SWB_fenv[n_band + 1]); /*Q17 */
+ L_tmp = L_mac(L_tmp, sub(32767,weight), SWB_fenv[n_band + 1]);/*Q17 */
+ wfenv = round_fx(L_tmp); /*Q1 */
+ factor = SWB_fenv[n_band];
+ move16(); /*Q1 */
+ factor1 = mult_r(sub(wfenv,SWB_fenv[n_band]), smooth_factor_fx[n_band]); /*Q1 */
+ tmp = norm_s(factor);
+ IF(GT_16(tmp,4))
+ {
+ tmp = 12;
+ move16();
+ factor = shl(factor, 2);
+ factor1 = shl(factor1, 2);
+ }
+ ELSE
+ {
+ tmp = 14;
+ move16();
+ }
+
+ tmp2 = add(swb_bwe_sm_subband[n_band + 1],st_offset);
+ FOR(; n_freq < tmp2; n_freq++)
+ {
+ L_tmp1 = Mult_32_16(SWB_signal_32[n_freq], factor);
+ SWB_signal_32[n_freq] = L_shl(L_tmp1, tmp - 1);
+ move32(); /*15+Qsyn */
+ factor = add(factor, factor1); /*Q1 */
+ }
+ }
+ L_tmp = L_mult(weight, prev_SWB_fenv[13]); /*Q17 */
+ L_tmp = L_mac(L_tmp,sub(32767,weight), SWB_fenv[13]);/*Q17 */
+ wfenv = round_fx(L_tmp); /*Q1 */
+ factor = SWB_fenv[12];
+ move16();/*Q1 */
+ factor1 = mult_r(sub(wfenv, SWB_fenv[12]), smooth_factor_fx[12]); /*Q1 */
+ tmp2 = add(swb_bwe_sm_subband[13],st_offset);
+ FOR(; n_freq < tmp2; n_freq++)
+ {
+ L_tmp1 = Mult_32_16(SWB_signal_32[n_freq], factor);
+ SWB_signal_32[n_freq] = L_shl(L_tmp1,13);
+ move32();/*15+Qsyn */
+ factor = add(factor,factor1); /*Q1 */
+ }
+
+ FOR(n_band = 13; n_band < SWB_FENV; n_band++)
+ {
+ L_tmp = L_mult(weight, prev_SWB_fenv[n_band]); /*Q17 */
+ L_tmp = L_mac(L_tmp,sub(32767, weight), SWB_fenv[n_band]);/*Q17 */
+ wfenv = round_fx(L_tmp); /*Q1 */
+ tmp2 = add(swb_bwe_subband[n_band + 1],st_offset);
+ FOR(; n_freq < tmp2; n_freq++)
+ {
+ L_tmp1 = Mult_32_16(SWB_signal_32[n_freq], factor);
+ SWB_signal_32[n_freq] = L_shl(L_tmp1,13);
+ move32(); /*15+Qsyn */
+ }
+ }
+ FOR(n_band = 0; n_band < SWB_FENV; n_band++)
+ {
+ prev_SWB_fenv[n_band] = SWB_fenv[n_band];
+ move16();/*Q1 */
+ }
+ }
+ pit1_32 = &SWB_signal_32[240 + st_offset]; /*15+Qsyn */
+ FOR(n_freq = 0; n_freq < 4; n_freq++)
+ {
+ L_tmp1 = Mult_32_16(*pit1_32, 16384); /*15+Qsyn */
+ *(pit1_32++) = L_tmp1;
+ move32();
+ }
+ *prev_Energy = Energy_16;
+ move16();
+
+ return;
+}
+
+/*==========================================================================*/
+/* FUNCTION : void time_envelop_shaping_fx() */
+/*--------------------------------------------------------------------------*/
+/* PURPOSE : Time shaping of SHB signal */
+/*--------------------------------------------------------------------------*/
+/* INPUT ARGUMENTS */
+/* _(Word16) L :length */
+/* _(Word16) Q_syn :Q format */
+/*--------------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _None */
+/*--------------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _(Word16[])werr : SHB synthesis */
+/* _(Word16[])SWB_tenv : frequency envelope */
+/*--------------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : */
+/* _ None */
+/*--------------------------------------------------------------------------*/
+void time_envelop_shaping_fx(
+ Word16 werr[], /* i/o: SHB synthesis Q_synth*/
+ Word32 SWB_tenv[], /* i/o: frequency envelope Q15*/
+ const Word16 L, /* i : frame length */
+ Word16 *Q_synth
+)
+{
+ Word16 *pit;
+ Word32 Energy;
+ Word16 i, j;
+ Word16 tmp_ener, Energy_16;
+ Word16 exp_L, exp, frac, tmp, inv_L;
+ Word32 L_tmp;
+
+ pit = werr;
move16();
- IF(EQ_16(hq_generic_offset, HQ_GENERIC_FOFFSET_24K4))
+ exp_L = norm_s(L);
+ inv_L = div_s(shl(1, sub(14, exp_L)), L); /*Q(29-exp_L) */
+ FOR(i = 0; i < SWB_TENV; i++)
{
- *efreq = 146;
+ Energy = L_deposit_l(0);
+ FOR(j = 0; j < L / 4; j++)
+ {
+#ifdef BASOP_NOGLOB
+ Energy = L_mac0_sat(Energy, *pit, *pit); /*(2*Q_synth) */
+#else
+ Energy = L_mac0(Energy, *pit, *pit); /*(2*Q_synth) */
+#endif
+ pit++;
+ }
+ Energy = Mult_32_16(Energy, inv_L); /*Q(29-exp_L-15) -> Q(-exp_L+14+2*Q_synth) */
+ Energy_16 = 0;
move16();
- if (EQ_16(HQ_mode, HQ_GEN_FB))
+ /*exp = 31-(-exp_L+14 +(2*(*Q_synth))); */
+ exp = sub(17, sub(shl((*Q_synth), 1), exp_L));
+
+ IF(Energy != 0)
{
- *efreq = 306;
+ exp = norm_l(Energy);
+ frac = extract_h(L_shl(Energy, exp));
+ /*exp = sub(exp, 30-(-exp_L+14-2+(2*(*Q_synth)))); */
+ exp = sub(exp, sub(30, add(sub(shl((*Q_synth), 1), exp_L), 14 - 2)));
+
+ tmp = div_s(16384, frac);
+ L_tmp = L_deposit_h(tmp);
+ Energy = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */
+ Energy_16 = round_fx(L_shl(Energy, sub(exp, 15))); /*Q0 */
+ }
+
+ test();
+#ifdef BASOP_NOGLOB
+ IF(LT_32(SWB_tenv[i], 65536) && LT_32(Energy, L_shl_sat(SWB_tenv[i], sub(16, exp))))
+#else
+ IF(LT_32(SWB_tenv[i], 65536) && LT_32(Energy, L_shl(SWB_tenv[i], sub(16, exp))))
+#endif
+ {
+ *Q_synth = add(*Q_synth, 3);
move16();
}
- IF(LT_16(add(shl(sub(328, *efreq), 1), 1), *L_swb_norm))
+ ELSE
{
- *L_swb_norm = add(shl(sub(328, *efreq), 1), 1);
+ pit -= L / 4;
+ move16();
+ tmp_ener = 0;
+ move16();
+ exp = 0;
+ move16();
+
+ IF(Energy_16 != 0)
+ {
+ exp = norm_s(Energy_16);
+ tmp_ener = div_s(shl(1,sub(14,exp)), Energy_16); /*Q(29-exp) */
+ }
+
+ L_tmp = Mult_32_16(SWB_tenv[i], tmp_ener); /*Q(29-exp) */
+ tmp = round_fx(L_tmp); /*Q(13-exp) */
+
+ FOR(j = 0; j < L / 4; j++)
+ {
+#ifdef BASOP_NOGLOB
+ *pit = round_fx_sat(L_shl_sat(L_mult(tmp, *pit), sub(exp,1))); /*Q(13-exp+1)->Q(14-exp)->Qsyn-3 */
+#else
+ *pit = round_fx(L_shl(L_mult(tmp, *pit), sub(exp,1))); /*Q(13-exp+1)->Q(14-exp)->Qsyn-3 */
+#endif
+ pit++;
+ }
}
}
- ELSE
+
+ return;
+}
+
+/*==========================================================================*/
+/* FUNCTION : void time_reduce_pre_echo_fx() */
+/*--------------------------------------------------------------------------*/
+/* PURPOSE : Windowing and time-domain aliasing */
+/*--------------------------------------------------------------------------*/
+/* INPUT ARGUMENTS */
+/* _(Word16*) synth :ACELP core synthesis Q_syn */
+/* _(Word16) L :subframe length */
+/* _(Word16) Q_syn :Q format */
+/*--------------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _(Word16*)error : SHB BWE synthesis Q_syn */
+/* _(Word16)prev_td_energy : last td energy Q_syn */
+/*--------------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _None */
+/*--------------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : */
+/* _ None */
+/*--------------------------------------------------------------------------*/
+void time_reduce_pre_echo_fx(
+ const Word16 *synth, /* i : ACELP core synthesis Q_syn*/
+ Word16 *error, /* i/o: SHB BWE synthesis Q0*/
+ Word16 prev_td_energy, /* o : last td energy Q0*/
+ const Word16 L, /* i : subframe length */
+ Word16 Q_syn,
+ Word16 Q_synth
+)
+{
+ Word16 i, j, pos = 0, Len;
+ Word32 energy;
+ Word16 energy_16;
+ Word32 energyL[4];
+ Word16 tmp_ener;
+ Word16 *pit;
+ Word16 tmpi, tmp_exp;
+ Word16 exp_L, exp, frac, inv_L, exp_j, tmp;
+ Word32 L_tmp, L_tmp1, Ltmp_ener;
+
+ exp_L = norm_s(L);
+ inv_L = div_s(shl(1, sub(14, exp_L)), L); /*Q(29-exp_L) */
+ FOR(i = 0; i < 4; i++)
{
- *efreq = 130;
- move16();
- if (EQ_16(HQ_mode, HQ_GEN_FB))
+ Len = i_mult(L, i);
+
+ L_tmp = L_deposit_l(0);
+ FOR(j = 0; j < L; j++)
{
- *efreq = 290;
- move16();
+ L_tmp = L_mac0(L_tmp, synth[Len + j], synth[Len + j]); /*2*Q_syn */
}
- IF(LT_16(add(shl(sub(400,*efreq),1),1),*L_swb_norm))
+ energyL[i] = Mult_32_16(L_shr(L_tmp, sub(14, exp_L)), inv_L);
+ move32(); /*Q(2*Q_syn +29-exp_L-15 - (14-exp_L) ) -> Q(2*Q_syn) */
+
+ IF(energyL[i] != 0)
{
- *L_swb_norm = add(shl(sub(400,*efreq),1),1);
+ exp = norm_l(energyL[i]);
+ frac = extract_h(L_shl(energyL[i], exp));
+ exp = sub(exp, sub(30, shl(Q_syn, 1)));
+
+ tmp = div_s(16384, frac);
+ L_tmp = L_deposit_h(tmp);
+ L_tmp = Isqrt_lc(L_tmp, &exp);
+ energyL[i] = L_shl(L_tmp, sub(exp, 16));
+ move32();/* Q15 */
}
}
- lookback = shr(*L_swb_norm, 1);
- env_index = 0;
- move16();
- n_lag_now = *L_swb_norm;
- move16();
- FOR(n_freq = 0; n_freq < lookback; n_freq++)
+ FOR(i = 0; i < 3; i++)
{
- Word16 tmp;
- Word32 L_tmp;
-
- L_tmp = L_deposit_l(1);
- tmp = add(lookback, n_freq);
- FOR(n_lag = 0; n_lag < tmp; n_lag++)
+ L_tmp = Mult_32_16(energyL[i], 29491); /*Q14 */
+ test();
+ IF(GT_32(L_shr(energyL[i + 1], 1), L_tmp) && GT_32(energyL[i + 1], 1638400))
{
- L_tmp = L_add(L_tmp, L_abs(SWB_signal[n_lag]));
+ pos = add(i, 1);
+ move16();
+ BREAK;
}
- envelope[env_index] = L_tmp;
- move32();
- env_index = add(env_index, 1);
}
- FOR(; n_freq < *efreq; n_freq++)
+ IF(pos > 0)
{
- /* Apply MA filter */
- Word32 L_tmp = L_deposit_l(1);
- FOR(n_lag = 0; n_lag < n_lag_now; n_lag++)
+ if (LT_16(pos, 3))
{
- L_tmp = L_add(L_tmp, L_abs(SWB_signal[add(sub(n_freq, lookback), n_lag)]));
+ pos = add(pos, 1);
+ }
+ energy = L_deposit_l(0);
+ j = i_mult(L, pos);
+ move16();
+ FOR(i = 0; i < j; i++)
+ {
+#ifdef BASOP_NOGLOB
+ energy = L_mac0_sat(energy, error[i], error[i]); /*Q(2*Q_synth) */
+#else
+ energy = L_mac0(energy, error[i], error[i]); /*Q(2*Q_synth) */
+#endif
}
- envelope[env_index] = L_tmp;
- move32();
- env_index = add(env_index, 1);
+ exp_j = norm_s(j);
+ tmp = div_s(shl(1, sub(14, exp_j)), j); /*Q(29-exp_j) */
+ energy = Mult_32_16(energy, tmp); /*Q(29-exp_j+1-16) -> Q(-exp_j+14 +2*Q_synth) */
+ energy_16 = 0;
+ move16();
+
+ IF(energy != 0)
+ {
+ exp = norm_l(energy);
+ frac = extract_h(L_shl(energy, exp));
+ /*exp = sub(exp, 30-(-exp_j+14 +2*Q_synth)); */
+ exp = sub(exp, sub(14, sub(shl(Q_synth, 1), exp_j)));
+ tmp = div_s(16384, frac);
+ L_tmp = L_deposit_h(tmp);
+ energy = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */
+ energy_16 = round_fx(L_shl(energy, sub(exp, 15))); /*Q0 */
+ }
+
+ tmp = mult_r(energy_16, 6554); /*Q0 */
+ if (LT_16(prev_td_energy, tmp))
+ {
+ prev_td_energy = tmp;
+ move16();
+ }
+
+ tmp_ener = 0;
+ move16();
+ exp = 0;
+ move16();
+ IF(energy_16 != 0)
+ {
+ exp = norm_s(energy_16);
+ tmp_ener = div_s(shl(1, sub(14, exp)), energy_16); /*Q(29-exp) */
+ }
+ L_tmp = L_mult(prev_td_energy, tmp_ener); /*Q(30-exp) */
+ tmp_exp = add(1, exp);
+ FOR(i = 0; i < j; i++)
+ {
+#ifdef BASOP_NOGLOB
+ error[i] = round_fx_sat(L_shl_sat(Mult_32_16(L_tmp, error[i]), tmp_exp)); /*Q(30-exp+1-16)->Q(15-exp)->Q_synth */
+#else
+ error[i] = round_fx(L_shl(Mult_32_16(L_tmp, error[i]), tmp_exp)); /*Q(30-exp+1-16)->Q(15-exp)->Q_synth */
+#endif
+ }
+
+ energy = L_deposit_l(0);
+ FOR(i = j; i < (j + L); i++)
+ {
+#ifdef BASOP_NOGLOB
+ energy = L_mac0_sat(energy, error[i], error[i]); /*(2*Q_synth) */
+#else
+ energy = L_mac0(energy, error[i], error[i]); /*(2*Q_synth) */
+#endif
+ }
+
+ energy = Mult_32_16(energy, inv_L); /*Q(29-exp_L+1-16) -> Q(-exp_L+14) */
+ energy_16 = 0;
+ move16();
+ IF(energy != 0)
+ {
+ exp = norm_l(energy);
+ frac = extract_h(L_shl(energy, exp));
+ /*exp = sub(exp, 30-(-exp_L+14+2*Q_synth)); */
+ exp = sub(exp, sub(14, sub(shl(Q_synth, 1), exp_L)));
+
+ tmp = div_s(16384, frac);
+ L_tmp = L_deposit_h(tmp);
+ energy = Isqrt_lc(L_tmp, &exp); /*Q(31-exp) */
+ energy_16 = round_fx(L_shl(energy, sub(exp, 15))); /*Q0 */
+ }
+
+ tmp_ener = 0;
+ move16();
+ exp = 0;
+ move16();
+ IF(energy_16 != 0)
+ {
+ exp = norm_s(energy_16);
+ tmp_ener = div_s(shl(1, sub(14, exp)), energy_16); /*Q(29-exp) */
+ }
+ Ltmp_ener = L_mult(prev_td_energy, tmp_ener); /*Q(30-exp) */
+ L_tmp1 = L_shl(1, sub(30, exp));
+
+ pit = &error[j];
+ move16();
+ FOR(i = 0; i < L; i++)
+ {
+ tmpi = round_fx(L_shl(L_mult(i, inv_L), add(1, exp_L))); /*Q15 */
+ L_tmp = L_sub(L_tmp1, Ltmp_ener); /*Q(30-exp) */
+ L_tmp = Mult_32_16(L_tmp, tmpi); /*Q(30-exp) */
+ L_tmp = L_add(Ltmp_ener, L_tmp); /*Q(30-exp) */
+ tmp = round_fx(L_shl(Mult_32_16(L_tmp, *pit), add(1, exp))); /*Q0 */
+ *pit++ = tmp;
+ }
}
return;
}
+/*-------------------------------------------------------------------*
+ * calc_normal_length_fx_32()
+ *
+ *-------------------------------------------------------------------*/
void calc_normal_length_fx_32(
const Word16 core, /* i : core : Q0 */
const Word32 *sp, /* i : input signal : Q12 */
@@ -240,6 +2358,68 @@ void calc_normal_length_fx_32(
return;
}
+
+/*-------------------------------------------------------------------*
+ * calc_norm_envelop_fx_32()
+ *
+ *-------------------------------------------------------------------*/
+void calc_norm_envelop_fx_32(
+ const Word32 SWB_signal_fx[], /* i : SWB spectrum : Q12 */
+ Word32 *envelope_fx, /* o : normalized envelope : Q16 */
+ const Word16 L_swb_norm, /* i : length of envelope : Q0 */
+ const Word16 SWB_flength, /* i : Length of input/output : Q0 */
+ const Word16 st_offset /* i : offset : Q0 */
+)
+{
+ Word16 i, lookback, env_index, n_freq, n_lag_now, n_lag, tmp;
+
+ lookback = L_swb_norm / 2;
+ move16();
+ env_index = swb_bwe_subband[0] + st_offset;
+ move16();
+ n_lag_now = L_swb_norm;
+ move16();
+ tmp = sub(add(SWB_flength, st_offset), L_swb_norm);
+ FOR(n_freq = sub(add(swb_bwe_trans_subband[0], st_offset), lookback); n_freq < tmp; n_freq++)
+ {
+ /* Apply MA filter */
+ envelope_fx[env_index] = 0;
+ move16();
+ FOR(n_lag = 0; n_lag < n_lag_now; n_lag++)
+ {
+ envelope_fx[env_index] = L_add(envelope_fx[env_index], L_abs(SWB_signal_fx[add(n_freq, n_lag)]));
+ move32();
+ }
+ env_index++;
+ }
+ i = 0;
+ move16();
+ tmp = sub(add(SWB_flength, st_offset), lookback);
+ FOR(n_freq = sub(add(SWB_flength, st_offset), L_swb_norm); n_freq < tmp; n_freq++)
+ {
+ Word32 L_tmp;
+
+ n_lag_now = L_swb_norm - i;
+ move16();
+ /* Apply MA filter */
+ L_tmp = L_deposit_l(0);
+ FOR(n_lag = 0; n_lag < n_lag_now; n_lag++)
+ {
+ L_tmp = L_add(L_tmp, L_abs(SWB_signal_fx[n_freq + n_lag]));
+ }
+ envelope_fx[env_index] = L_tmp;
+ move32();
+ env_index = add(env_index, 1);
+ i++;
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * hq_generic_decoding_fx()
+ *
+ *-------------------------------------------------------------------*/
void hq_generic_decoding_fx(
const Word16 HQ_mode, /* i : HQ mode : Q0 */
Word32 *coeff_out1_fx, /* i/o: BWE input & temporary buffer : Q12 */
@@ -786,4 +2966,40 @@ void hq_generic_decoding_fx(
}
return;
-}
\ No newline at end of file
+}
+
+
+
+/*-------------------------------------------------------------------*
+ * save_old_syn()
+ *
+ * Save and delay the ACELP core synthesis signal by
+ * DELAY_FD_BWE_ENC_xxkx to be used by SWB BWE
+ *-------------------------------------------------------------------*/
+
+void save_old_syn_fx(
+ const Word16 L_frame, /* i : frame length */
+ const Word16 syn[], /* i : ACELP synthesis */
+ Word16 old_syn[], /* o : old synthesis buffer */
+ Word16 old_syn_mem[], /* i/o: old synthesis buffer memory */
+ const Word16 preemph_fac, /* i : preemphasis factor */
+ Word16 *mem_deemph /* i/o: deemphasis filter memory */
+)
+{
+ Word16 tmps;
+
+ tmps = NS2SA(16000, DELAY_FD_BWE_ENC_16k_NS);
+ move16();
+ if (EQ_16(L_frame, L_FRAME))
+ {
+ tmps = NS2SA(12800, DELAY_FD_BWE_ENC_12k8_NS);
+ move16();
+ }
+ Copy(old_syn_mem, old_syn, tmps);
+ Copy(syn, old_syn + tmps, L_frame - tmps);
+ Copy(syn + L_frame - tmps, old_syn_mem, tmps);
+
+ deemph_fx(old_syn, preemph_fac, L_frame, mem_deemph);
+
+ return;
+}
diff --git a/lib_com/swb_bwe_com_lr_fx.c b/lib_com/swb_bwe_com_lr_fx.c
new file mode 100644
index 0000000000000000000000000000000000000000..3a9ea99991fc6ee80882e67d632d4894905043dc
--- /dev/null
+++ b/lib_com/swb_bwe_com_lr_fx.c
@@ -0,0 +1,3426 @@
+/******************************************************************************************************
+
+ (C) 2022-2023 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.
+
+*******************************************************************************************************/
+
+#include
+#include "options.h"
+#include "cnst.h"
+#include "prot_fx2.h"
+#include "rom_com.h"
+
+#include
+
+
+ /*-------------------------------------------------------------------*
+ * GetPredictedSignal()
+ *
+ * Routine for calculating the predicted signal
+ *-------------------------------------------------------------------*/
+void GetPredictedSignal_fx(
+ const Word16 *predBuf_fx, /* i: Q8 */
+ Word32 *L_outBuf, /* o: Q9 */
+ const Word16 lag_fx, /* i: Q0 */
+ const Word16 fLen_fx, /* i: Q0 */
+ const Word16 lagGains_fx, /* i: Qgain */
+ const Word16 Qgain /* i: Q0 */
+)
+{
+ Word16 i;
+ const Word16 *p_predBuf;
+ Word32 *p_L_outBuf;
+
+ p_predBuf = predBuf_fx + lag_fx;
+ p_L_outBuf = L_outBuf;
+
+ FOR(i = 0; i < fLen_fx; i++)
+ {
+ /* Q8 x Q0 --> Q9, 9+7-16=Q0 */
+ *p_L_outBuf++ = L_shr(L_mult(*p_predBuf++, lagGains_fx), Qgain);
+ move32();
+ }
+}
+
+/*-------------------------------------------------------------------*
+ * est_freq_har_decis_fx()
+ *
+ * Harmonic frequency decision matrix
+ *-------------------------------------------------------------------*/
+static
+void est_freq_har_decis_fx(
+ Word16 *har_freq_est1, /* o: harmonic analysis 1 */
+ Word16 *har_freq_est2, /* o: harmonic analysis 2 */
+ Word16 sharp, /* i: pka-avg for group 1 */
+ Word16 sharp1, /* i: pka-avg for group 2 */
+ Word16 hfe_est_countk1, /* i: group pks count 1 */
+ Word16 hfe_est_countk2, /* i: group pks count 2 */
+ Word16 k, /* i: group count */
+ Word16 k1, /* i: */
+ Word16 k2, /* i: */
+ Word16 *prev_frm_hfe2 /* i: harmonic estimation */
+)
+{
+ Word16 temp_hfe2 = 0;
+ Word16 har_freq_est2_2;
+ Word16 prev_frm_hfe2_2;
+
+ IF(k != 0)
+ {
+ *har_freq_est1 = div_s_ss(sharp, k);
+ }
+
+ test();
+ test();
+ IF(GT_16(k1, 1))
+ {
+ *har_freq_est2 = div_s_ss(sharp1, k1);
+ }
+ ELSE IF(LT_16(k1, 2) && (k2 != 0 || GT_16(k, 1)))
+ {
+ *har_freq_est2 = *har_freq_est1;
+ move16();
+ }
+ ELSE
+ {
+ test();
+ test();
+ test();
+ IF((hfe_est_countk1 != 0 || hfe_est_countk2 != 0) && (k1 == 0 && k2 == 0))
+ {
+ *har_freq_est2 = (*har_freq_est1);
+ move16();
+ }
+ ELSE
+ {
+ *har_freq_est2 = shl(*har_freq_est1, 1);
+ move16();
+ }
+ }
+
+ /* Consider Estimation Error upto 200Hz */
+ test();
+ test();
+ test();
+ har_freq_est2_2 = shl(*har_freq_est2, 1);
+ prev_frm_hfe2_2 = shl(*prev_frm_hfe2, 1);
+ IF(*prev_frm_hfe2 != 0 && (LT_16(abs_s(sub(*prev_frm_hfe2, *har_freq_est2)), 10) || LT_16(abs_s(sub(*prev_frm_hfe2, har_freq_est2_2)), 10)))
+ {
+ *har_freq_est2 = *prev_frm_hfe2;
+ move16();
+ }
+ ELSE IF(*prev_frm_hfe2 != 0 && LT_16(abs_s(sub(*har_freq_est2, prev_frm_hfe2_2)), 10))
+ {
+ *har_freq_est2 = prev_frm_hfe2_2;
+ move16();
+ }
+ ELSE
+ {
+ temp_hfe2 = shr(add(*prev_frm_hfe2, *har_freq_est2), 1);
+ move16();
+
+ IF(LT_16(abs_s(sub(temp_hfe2, *prev_frm_hfe2)), 2))
+ {
+ temp_hfe2 = *prev_frm_hfe2;
+ move16();
+ *har_freq_est2 = temp_hfe2;
+ move16();
+ }
+ }
+
+ test();
+ test();
+ if (LT_16(*har_freq_est2, *har_freq_est1) && (GT_16(k, 1) && LT_16(k1, 2)))
+ {
+ *har_freq_est2 = *har_freq_est1;
+ move16();
+ }
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * har_est_fx()
+ *
+ * Harmonic Structure analysis using LF spectrum
+ *--------------------------------------------------------------------------*/
+
+Word16 har_est_fx(
+ Word32 L_spectra[], /* i : coded spectrum */
+ Word16 N, /* i : length of the desired spectrum */
+ Word16 *har_freq_est1, /* i/o: Estimation harmonics 1 */
+ Word16 *har_freq_est2, /* o : Estimation harmonics 2 */
+ Word16 *flag_dis, /* i/o: flag for BWE reconstruction */
+ Word16 *prev_frm_hfe2, /* i/o: Estimated harmonic update */
+ const Word16 subband_search_offset[], /* i : Subband Search range */
+ const Word16 sbWidth[], /* i : Subband Search range */
+ Word16 *prev_stab_hfe2 /* i/o: Estimated harmonic position */
+)
+{
+ Word32 L_peak;
+ Word32 L_input_abs[L_FRAME32k], L_blk_peak[30];
+ Word32 L_blk_peak_te[30];
+ Word32 L_blk_peak_max;
+ Word32 *p_L_blk_peak, *pm1_L_blk_peak;
+
+ Word16 i, j, q, k, k1, k2;
+ Word16 blk_end, blk_st;
+ Word16 peak_pos, blk_peak_pos[30], diff_peak_pos[30], sharp, sharp1;
+ Word16 min_har_pos;
+ Word16 blk_peak_pos_te[30];
+ Word16 temp;
+ Word16 hfe_est_countk, hfe_est_countk1, hfe_est_countk2;
+ Word16 r1, r2, r3;
+ Word16 start_pos;
+ Word16 blk_peak_pos_max;
+
+ Word16 nlags, nlags_half, ct_hfsb2, sum_diff;
+ Word16 blk_peak_pos_hfsb2[30], diff_peak_pos_hfsb2[30];
+ Word16 rem_hfe2, q_diffpos_hfe2, diff_posmax_hfe2, q_diffpos_prevhfe2;
+
+ Word16 blk_end_LEN;
+
+ Word16 *p_blk_peak_pos, *pm1_blk_peak_pos;
+ Word16 *p_diff_peak_pos, *pm1_diff_peak_pos;
+ Word16 blk_peak_max_idx, blk_peak_pos_max_diff, diff_peak_pos_te[30];
+ Word16 thr1, thr2;
+
+ set32_fx(L_input_abs, 0x0L, L_FRAME32k);
+ set32_fx(L_blk_peak, 0x0L, 30);
+ set16_fx(blk_peak_pos, 0, 30);
+ set16_fx(blk_peak_pos_te, 0, 30);
+
+ rem_hfe2 = 0;
+ move16();
+ q_diffpos_hfe2 = 0;
+ move16();
+ diff_posmax_hfe2 = 0;
+ move16();
+ q_diffpos_prevhfe2 = 0;
+ move16();
+
+ set16_fx(diff_peak_pos, 0, 30);
+
+ r1 = SWB_HAR_RAN1;
+ move16();
+ r2 = SWB_HAR_RAN2;
+ move16();
+ r3 = SWB_HAR_RAN3;
+ move16();
+ start_pos = r1;
+ move16();
+
+ /* Copy the abs values of LF spectrum*/
+ FOR(i = start_pos; i < N; i++)
+ {
+ L_input_abs[i] = L_abs(L_spectra[i]);
+ move32();
+ }
+
+ blk_end = div_s_ss(N, LR_BLK_LEN);
+ blk_st = div_s_ss(start_pos, LR_BLK_LEN);
+
+ /*if( N/(LR_BLK_LEN) - blk_end > 0.0f) */
+ blk_end_LEN = i_mult(blk_end, LR_BLK_LEN);
+ if (GT_16(N, blk_end_LEN))
+ {
+ blk_end = add(blk_end, 1);
+ }
+
+ /* initialization of over buffer for fractional point */
+ temp = i_mult(blk_end, LR_BLK_LEN);
+ FOR(i = N; i < temp; i++)
+ {
+ L_input_abs[i] = L_deposit_l(0);
+ }
+
+ q = start_pos;
+ move16();
+
+ /* Block Processing, to detect the spectral peaks*/
+ FOR(i = blk_st; i < blk_end; i++)
+ {
+ L_peak = L_deposit_l(0);
+ peak_pos = 0;
+ move16();
+
+ FOR(j = 0; j < LR_BLK_LEN; j++)
+ {
+ IF(GT_32(L_input_abs[q], L_peak))
+ {
+ L_peak = L_input_abs[q];
+ move32();
+ peak_pos = q;
+ move16();
+ }
+
+ test();
+ test();
+ test();
+ IF(GT_16(i, blk_st) && L_input_abs[q] != 0x0L && EQ_32(L_input_abs[q], L_peak) && LT_16(sub(peak_pos, blk_peak_pos[i - 1]), LR_HLF_PK_BLK_LEN))
+ {
+ L_peak = L_input_abs[q];
+ move32();
+ peak_pos = q;
+ move16();
+ }
+ q = add(q, 1);
+ }
+
+ L_blk_peak[i] = L_peak;
+ move32();
+ blk_peak_pos[i] = peak_pos;
+ move16();
+ }
+
+ p_L_blk_peak = &L_blk_peak[blk_st];
+ pm1_L_blk_peak = &L_blk_peak[sub(blk_st, 1)];
+ p_blk_peak_pos = &blk_peak_pos[blk_st];
+ pm1_blk_peak_pos = &blk_peak_pos[sub(blk_st, 1)];
+ FOR(i = blk_st; i < blk_end; i++)
+ {
+ IF(GT_16(i, blk_st))
+ {
+
+ test();
+ IF(*p_blk_peak_pos != 0 && *pm1_blk_peak_pos != 0)
+ {
+ IF(LT_16(sub(*p_blk_peak_pos, *pm1_blk_peak_pos), LR_LOWBAND_DIF_PK_LEN))
+ {
+ IF(GT_32(*p_L_blk_peak, *pm1_L_blk_peak))
+ {
+ *pm1_L_blk_peak = L_deposit_l(0);
+ *pm1_blk_peak_pos = 0;
+ move16();
+ }
+ ELSE
+ {
+ *p_L_blk_peak = *pm1_L_blk_peak;
+ move32();
+ *p_blk_peak_pos = *pm1_blk_peak_pos;
+ move16();
+ *pm1_L_blk_peak = L_deposit_l(0);
+ *pm1_blk_peak_pos = 0;
+ move16();
+ }
+ }
+ }
+ }
+ p_L_blk_peak++;
+ pm1_L_blk_peak++;
+
+ p_blk_peak_pos++;
+ pm1_blk_peak_pos++;
+ }
+
+ /* peak counts in each group */
+ j = 0;
+ move16();
+ hfe_est_countk = 0;
+ move16();
+ hfe_est_countk1 = 0;
+ move16();
+ hfe_est_countk2 = 0;
+ move16();
+ FOR(i = blk_st; i < blk_end; i++)
+ {
+ IF(blk_peak_pos[i] != 0)
+ {
+ blk_peak_pos_te[j] = blk_peak_pos[i];
+ move16();
+ IF(LT_16(blk_peak_pos[i], r2))
+ {
+ hfe_est_countk = add(hfe_est_countk, 1);
+ }
+ ELSE IF(LT_16(blk_peak_pos[i], r3))
+ {
+ hfe_est_countk1 = add(hfe_est_countk1, 1);
+ }
+ ELSE
+ {
+ hfe_est_countk2 = add(hfe_est_countk2, 1);
+ }
+ L_blk_peak_te[j] = L_blk_peak[i];
+ move32();
+ j = add(j, 1);
+ }
+ }
+
+ min_har_pos = SWB_HAR_RAN1;
+ move16();
+ temp = 0;
+ move16();
+ L_blk_peak_max = L_blk_peak_te[0];
+ move32();
+ blk_peak_pos_max = blk_peak_pos_te[0];
+ move16();
+ blk_peak_max_idx = 0;
+ move16();
+
+
+ p_diff_peak_pos = &diff_peak_pos[1];
+ pm1_diff_peak_pos = &diff_peak_pos[1 - 1];
+ FOR(i = 1; i < j; i++)
+ {
+ *pm1_diff_peak_pos = sub(blk_peak_pos_te[i], blk_peak_pos_te[sub(i, 1)]);
+ if (LE_16(*pm1_diff_peak_pos, min_har_pos))
+ {
+ min_har_pos = *pm1_diff_peak_pos;
+ move16();
+ }
+
+ IF(GT_32(L_blk_peak_te[sub(i, 1)], L_blk_peak_max))
+ {
+ L_blk_peak_max = L_blk_peak_te[sub(i, 1)];
+ move32();
+ blk_peak_pos_max = blk_peak_pos_te[sub(i, 1)];
+ move16();
+ blk_peak_max_idx = sub(i, 1);
+ }
+
+ temp = add(temp, 1);
+
+ p_diff_peak_pos++;
+ pm1_diff_peak_pos++;
+ }
+ blk_peak_pos_max_diff = diff_peak_pos[blk_peak_max_idx];
+ move16();
+
+ /* Decision for BWE reconstruction */
+ test();
+ test();
+ test();
+ IF((LT_16(hfe_est_countk, 2) && LT_16(hfe_est_countk1, 2) && LT_16(hfe_est_countk2, 2)) || GE_16(min_har_pos, SWB_HAR_RAN1))
+ {
+ *flag_dis = 0;
+ move16();
+ test();
+ test();
+ test();
+ if ((EQ_16(hfe_est_countk, 1) && EQ_16(hfe_est_countk1, 1)) && (EQ_16(hfe_est_countk2, 1) || hfe_est_countk2 == 0))
+ {
+ *flag_dis = 1;
+ move16();
+ }
+ }
+ thr1 = add(blk_peak_pos_max_diff, LR_LOWBAND_DIF_PK_LEN);
+ FOR(i = 0; i < temp; i++)
+ {
+ if (LT_16(thr1, diff_peak_pos[i]))
+ {
+ diff_peak_pos[i] = 0;
+ move16();
+ }
+ }
+ Copy(diff_peak_pos, diff_peak_pos_te, temp);
+ set16_fx(diff_peak_pos, -1, temp);
+ j = 0;
+ FOR(i = 0; i < temp; i++)
+ {
+ IF(diff_peak_pos_te[i] != 0)
+ {
+ diff_peak_pos[j] = diff_peak_pos_te[i];
+ move16();
+ j = add(j, 1);
+ }
+ }
+ temp = j;
+ move16();
+
+ /* harmonic estimation analysis to perform BWE Reconstruction */
+ IF(*flag_dis)
+ {
+ sharp = 0;
+ move16();
+ k = 0;
+ move16();
+ k1 = 0;
+ move16();
+ sharp1 = 0;
+ move16();
+ k2 = 0;
+ move16();
+
+ q = 1;
+ move16();
+ thr1 = add(min_har_pos, LR_LOWBAND_DIF_PK_LEN);
+ thr2 = add(min_har_pos, shl(LR_LOWBAND_DIF_PK_LEN, 1));
+ FOR(i = 0; i < temp; i++)
+ {
+ test();
+ test();
+ IF(LE_16(diff_peak_pos[i], thr1) && diff_peak_pos[i] > 0)
+ {
+ sharp = add(sharp, diff_peak_pos[i]);
+ k = add(k, 1);
+ }
+ ELSE IF(LE_16(diff_peak_pos[i], thr2) && diff_peak_pos[i] > 0)
+ {
+ sharp1 = add(sharp1, diff_peak_pos[i]);
+ k1 = add(k1, 1);
+ }
+ ELSE IF(diff_peak_pos[i] > 0)
+ {
+ k2 = add(k2, 1);
+ }
+ q = add(q, 1);
+ }
+
+ est_freq_har_decis_fx(har_freq_est1, har_freq_est2, sharp, sharp1, hfe_est_countk1, hfe_est_countk2, k, k1, k2, prev_frm_hfe2);
+
+ blk_peak_pos_max = blk_peak_pos_te[sub(temp, 1)];
+ move16();
+
+ test();
+ test();
+ IF((*prev_stab_hfe2) > 0 && (*prev_frm_hfe2) > 0 && *prev_stab_hfe2 < N)
+ {
+ rem_hfe2 = sub(*har_freq_est2, extract_h(L_shl(L_mult(div_s_ss(*har_freq_est2, *prev_frm_hfe2), *prev_frm_hfe2), 15)));
+ diff_posmax_hfe2 = abs_s(sub(blk_peak_pos_max, *prev_stab_hfe2));
+ IF(rem_hfe2 == 0)
+ {
+ test();
+ IF(LT_16(diff_posmax_hfe2, 9) || *har_freq_est2 == 0)
+ {
+ blk_peak_pos_max = *prev_stab_hfe2;
+ move16();
+ }
+ ELSE
+ {
+ q_diffpos_hfe2 = div_s_ss(diff_posmax_hfe2, *har_freq_est2);
+ q_diffpos_prevhfe2 = div_s_ss(diff_posmax_hfe2, *prev_frm_hfe2);
+ test();
+ IF(LT_16(q_diffpos_hfe2, 10) || LT_16(q_diffpos_prevhfe2,10))
+ {
+ blk_peak_pos_max = *prev_stab_hfe2;
+ move16();
+ }
+ ELSE
+ {
+ *prev_stab_hfe2 = blk_peak_pos_max;
+ move16();
+ }
+ }
+ }
+ ELSE
+ {
+ *prev_stab_hfe2 = blk_peak_pos_max;
+ move16();
+ }
+ }
+ ELSE
+ {
+ *prev_stab_hfe2 = blk_peak_pos_max;
+ move16();
+ }
+
+ test();
+ if (*har_freq_est1 == 0 || *har_freq_est2 == 0)
+ {
+ *flag_dis = 0;
+ move16();
+ }
+ }
+
+ IF(*flag_dis == 0)
+ {
+ IF(*prev_frm_hfe2 != 0)
+ {
+ *har_freq_est2 = *prev_frm_hfe2;
+ move16();
+ }
+ ELSE
+ {
+ nlags = shl(1, bits_lagIndices_mode0_Har[0]);
+ nlags_half = shr(nlags, 1);
+ ct_hfsb2 = 0;
+ move16();
+ FOR(i = 0; i < j; i++)
+ {
+ test();
+ IF(GE_16(blk_peak_pos_te[i], sub(subband_search_offset[0], nlags_half))
+ &&
+ LT_16(blk_peak_pos_te[i], add(add(subband_search_offset[0], sbWidth[0]), nlags_half)))
+ {
+ blk_peak_pos_hfsb2[ct_hfsb2] = blk_peak_pos_te[i];
+ move16();
+ ct_hfsb2 = add(ct_hfsb2, 1);
+ move16();
+ }
+ }
+
+ IF(GT_16(ct_hfsb2, 1))
+ {
+ sum_diff = 0;
+ move16();
+ FOR(i = 1; i < ct_hfsb2; i++)
+ {
+ diff_peak_pos_hfsb2[i - 1] = sub(blk_peak_pos_hfsb2[i], blk_peak_pos_hfsb2[i - 1]);
+ sum_diff = add(sum_diff, diff_peak_pos_hfsb2[i - 1]);
+ }
+ *har_freq_est2 = div_s_ss(sum_diff, ct_hfsb2);
+ }
+ ELSE
+ {
+ *har_freq_est2 = min_har_pos;
+ move16();
+ }
+ }
+ }
+ return blk_peak_pos_max;
+}
+
+void genhf_noise_fx(
+ const Word16 noise_flr_fx[], /* i : Qss smoothed non tonal */ /* sspectra_diff_fx:Qss */
+ const Word16 Qss, /* i : Q0 Q value */
+ Word32 L_xSynth_har[], /* o : QsL hf non tonal components */ /* xSynth_har:QsL */
+ const Word16 QsL, /* i : Q0 Q value */
+ const Word16 *predBuf_fx, /* i : Qss smoothed tonal compone */ /* sspectra:Qss */
+ const Word16 bands, /* i : Q0 total number of subbands in a frame */
+ const Word16 harmonic_band, /* i : Q0 Number of LF harmonic frames */
+ const Word16 har_freq_est2, /* i : Q0 harmonic signal parameter */
+ const Word16 pos_max_hfe2, /* i : Q0 last pulse in core coder */
+ Word16 *pul_res, /* o : Q0 pulse resolution */
+ GainItem_fx pk_sf_fx[], /* o : representative region */
+ const Word16 fLenLow, /* i : Q0 low frequency length */
+ const Word16 fLenHigh, /* i : Q0 high frequency length */
+ const Word16 sbWidth[], /* i : Q0 bandwidth for high bands */
+ const Word16 lagIndices[], /* i : Q0 correlation indices for most representative */
+ const Word16 subband_offsets[], /* i : Q0 band offsets for HF reconstruction */
+ const Word16 subband_search_offset[]/* i : Q0 most representative regions offsets in LF */
+)
+{
+ Word16 k, j, ii, st_pos, dst_pos;
+ Word16 nlags[NB_SWB_SUBBANDS_HAR_SEARCH_SB];
+ Word32 L_tmpbuf[L_FRAME32k];
+ Word16 hfband_end[NB_SWB_SUBBANDS];
+ Word16 rem_hfe,/*last_peakpos,*/ temp_last_peakpos, i, l, pos, res;
+ Word16 hf_pulse_peaks_fx[160], pulse_peak_sb_fx[320]; /* Qss */
+ Word16 st_last_peakpos;
+ Word16 tmp_fx;
+
+ set32_fx(L_tmpbuf, 0x0L, L_FRAME32k);
+ FOR(k = 0; k < 3; k++)
+ {
+ hfband_end[k] = add(fLenLow, subband_offsets[k + 1]);
+ move16();
+ }
+ hfband_end[3] = add(fLenLow, fLenHigh);
+ move16();
+
+ tmp_fx = sub(sub(fLenLow, pos_max_hfe2), 1);
+ rem_hfe = div_s_ss(tmp_fx, har_freq_est2);
+
+ st_last_peakpos = add(pos_max_hfe2, i_mult(rem_hfe, har_freq_est2));
+
+ temp_last_peakpos = st_last_peakpos;
+ move16();
+ i = 0;
+ move16();
+
+ FOR(k = 0; k < 2; k++)
+ {
+ nlags[k] = shl(1, bits_lagIndices_mode0_Har[k]);
+
+ l = 0;
+ move16();
+ WHILE(LT_16(st_last_peakpos, add(fLenLow, subband_offsets[k])))
+ {
+ st_last_peakpos = add(st_last_peakpos, har_freq_est2);
+ }
+ st_last_peakpos = sub(st_last_peakpos, har_freq_est2);
+
+ IF(k == 0)
+ {
+ st_pos = add(sub(subband_search_offset[k], shr(nlags[k], 1)), lagIndices[k]);
+
+ /*Copy the LF Smoothed Noise to the HF*/
+ FOR(j = 0; j < sbWidth[k]; j++)
+ {
+ L_xSynth_har[j] = L_shl(L_deposit_l(noise_flr_fx[st_pos + j]), sub(QsL, Qss));
+
+ L_tmpbuf[j] = L_xSynth_har[j];
+ move32();
+ IF(predBuf_fx[st_pos + j] != 0x0)
+ {
+ hf_pulse_peaks_fx[l] = predBuf_fx[st_pos + j];
+ move16(); /* Qss */
+ l = add(l, 1);
+ }
+ }
+ }
+ ELSE
+ {
+ st_pos = sub(add(subband_search_offset[k], shr(nlags[k], 1)), lagIndices[k]);
+ dst_pos = sub(st_pos, sbWidth[k]);
+ ii = sbWidth[k - 1];
+ move16();
+ /*Copy the LF Smoothed Noise floor to the HF*/
+ FOR(j = st_pos; j > (dst_pos); j--)
+ {
+ IF(GE_16(ii, add(sbWidth[k],sbWidth[k - 1])))
+ {
+ BREAK;
+ }
+
+ /*xSynth_har[ii] = noise_flr[j];*/
+ L_xSynth_har[ii] = L_shl(L_deposit_l(noise_flr_fx[j]), sub(QsL, Qss));
+ L_tmpbuf[ii] = L_xSynth_har[ii];
+ move32();
+ IF(predBuf_fx[j] != 0x0)
+ {
+ hf_pulse_peaks_fx[l] = predBuf_fx[j];
+ move16();
+ l = add(l, 1);
+ }
+ ii = add(ii, 1);
+ }
+ }
+ pos = 0;
+ move16();
+ FOR(j = 0; j < l; j++)
+ {
+ st_last_peakpos = add(st_last_peakpos, har_freq_est2);
+ IF(LT_16(st_last_peakpos, hfband_end[k]))
+ {
+ pk_sf_fx[k * 8 + pos].nmrValue_fx = hf_pulse_peaks_fx[j];
+ move16(); /* Qss */
+ pk_sf_fx[k * 8 + pos].gainIndex_fx = sub(st_last_peakpos, fLenLow);
+ move16();
+ pul_res[k] = add(pul_res[k], 1);
+ move16();
+ pulse_peak_sb_fx[i] = hf_pulse_peaks_fx[j];
+ move16(); /* Qss */
+ i = add(i, 1);
+ pos = add(pos, 1);
+ }
+ }
+ st_last_peakpos = temp_last_peakpos;
+ move16();
+ }
+ res = sub(i, 1);
+ l = 1;
+ move16();
+ ii = sub(sub(hfband_end[k - 1], fLenLow), 1);
+ tmp_fx = sub(bands, harmonic_band);
+ FOR(; k < tmp_fx; k++)
+ {
+ Word16 tmp2;
+
+ tmp2 = (sub(hfband_end[k], fLenLow));
+ FOR(j = sub(hfband_end[k - 1], fLenLow); j < tmp2; j++)
+ {
+ L_xSynth_har[j] = L_tmpbuf[ii];
+ move32();
+ L_tmpbuf[j] = L_xSynth_har[j];
+ move32();
+ ii = sub(ii, 1);
+ }
+ pos = 0;
+ move16();
+ WHILE(LT_16(st_last_peakpos, hfband_end[k - 1]))
+ {
+ st_last_peakpos = add(st_last_peakpos, har_freq_est2);
+ }
+ WHILE(LT_16(st_last_peakpos, hfband_end[k]) && LT_16(pul_res[k], pul_res[2 - l]) && LE_16(l, 2))
+ {
+ test();
+ test();
+ pk_sf_fx[k * 8 + pos].nmrValue_fx = pulse_peak_sb_fx[res];
+ move16(); /* Qss */
+ pk_sf_fx[k * 8 + pos].gainIndex_fx = sub(st_last_peakpos, fLenLow);
+ move16();
+ pul_res[k] = add(pul_res[k], 1);
+ move16();
+ res = sub(res, 1);
+ pos = add(pos, 1);
+ st_last_peakpos = add(st_last_peakpos, har_freq_est2);
+ }
+ l = add(l, 1);
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * SmoothSpec()
+ *
+ * Smoothes specified samples using moving average method. The number
+ * of points in the average is given by 'span'. Note that current
+ * implementation does not accept 'span' to be smaller than 'fLen'.
+ *-------------------------------------------------------------------*/
+static
+void SmoothSpec_fx(
+ Word16 *inBuf, /* i : Input spectrum Q8 */
+ Word16 *outBuf, /* o : Smoothed spectrum Q8 */
+ Word16 num_subband /* i : subband number */
+)
+{
+ Word16 i, tmp;
+ Word16 span1; /* */
+ Word16 nItems, inItems; /* inverse */
+ Word32 L_sum; /* */
+ Word16 *oldPtr, *newPtr;/* */
+ Word16 hi, lo;
+ /* ======== Q8 ======== */
+ span1 = shr(MA_LEN, 1);
+
+ /*-- First sample. --*/
+ L_sum = L_deposit_l(*inBuf);
+ *outBuf++ = *inBuf;
+ move16();
+
+ oldPtr = inBuf;
+ newPtr = inBuf + 2;
+
+ /*-- Handle start. --*/
+ inBuf++;
+ L_sum = L_mac0(L_sum, 0x0001, *inBuf);
+
+ /* nItems = 3 --> inItems = 1/3 = 0.33f, 85(Q8) */
+ /* 1/3 = 0.3333f -> 0x2AAA Q15 */
+ inItems = 0x2AAA;
+ move16();
+ FOR(i = 1; i < span1; i++)
+ {
+ L_sum = L_mac0(L_sum, 0x0001, *newPtr++);
+
+ lo = L_Extract_lc(L_sum, &hi);
+ *outBuf++ = round_fx(L_shl(Mpy_32_16(hi, lo, inItems), 16)); /* Q(8+15+1-16)=Q8 -> Q(8+16-16)=Q8 */
+
+ L_sum = L_mac0(L_sum, 0x0001, *newPtr++);
+ /* nItems += 2,
+ * only used value is 5 -->
+ * inItems = 1/5 = 0.2f, 51(Q8)
+ */
+ /* 1/5 = 0.2f -> 0x1999 Q15 */
+ inItems = 0x1999;
+ move16();
+ inBuf++;
+ }
+
+ inBuf++;
+ L_sum = L_mac0(L_sum, 0x0001, *newPtr++);
+
+ lo = L_Extract_lc(L_sum, &hi);
+ /* 4681 (in Q15) = 0.1428 = 1/7 */
+ *outBuf++ = round_fx(L_shl(Mpy_32_16(hi, lo, 4681), 16)); /* Q(8+15+1-16)=Q8 -> Q(8+16-16)=Q8 */
+ i = add(i, 1);
+
+ /*-- Moving average. --*/
+ tmp = sub(num_subband, span1);
+ FOR(; i < tmp; i++)
+ {
+ L_sum = L_mac0(L_sum, 0x0001, *newPtr++);
+ L_sum = L_msu0(L_sum, 0x0001, *oldPtr++);
+
+ lo = L_Extract_lc(L_sum, &hi);
+ /* 4681 (in Q15) = 0.1428 = 1/7 */
+ *outBuf++ = round_fx(L_shl(Mpy_32_16(hi, lo, 4681), 16)); /* Q(8+15+1-16)=Q8 -> Q(8+16-16)=Q8 */
+ inBuf++;
+ }
+
+ /*-- Handle end. --*/
+ /* nItems = span - 2; (nItems = 5, so we can maintain inItems = 1/5 = 0.2f from above) */
+ nItems = sub(MA_LEN, 2);
+ L_sum = L_msu0(L_sum, 0x0001, *oldPtr++);
+
+ tmp = sub(num_subband, 1);
+ FOR(; i < tmp; i++)
+ {
+ L_sum = L_msu0(L_sum, 0x0001, *oldPtr++);
+
+ lo = L_Extract_lc(L_sum, &hi);
+ *outBuf++ = round_fx(L_shl(Mpy_32_16(hi, lo, inItems), 16)); /* Q(8+15+1-16)=Q8 -> Q(8+16-16)=Q8 */
+
+ /* nItems -= 2; */
+ nItems = sub(nItems, 2);
+
+ /* 1.0f -> 0x7fff Q15 */
+ inItems = 0x7fff;
+ move16();
+ if (EQ_16(nItems, 3))
+ {
+ /* 1/3 = 0.333f -> 0x2AAA Q15 */
+ inItems = 0x2AAA;
+ move16();
+ }
+ L_sum = L_msu0(L_sum, 0x0001, *oldPtr++);
+
+ inBuf++;
+ }
+
+ /*-- Last sample. --*/
+ *outBuf = *inBuf;
+ move16();
+}
+
+/*-------------------------------------------------------------------*
+ * SpectrumSmoothing()
+ *
+ * Smoothing of the low-frequency envelope
+ *-------------------------------------------------------------------*/
+
+void SpectrumSmoothing_fx(
+ const Word32 *L_inBuf, /* i : Qs Low band MDCT */
+ Word16 *outBuf_fx, /* o : Qss output */
+ Word16 *Qss, /* o : Q0 Q value of output vector */
+ const Word16 fLen, /* i : Q0 length */
+ const Word16 th_cut_fx /* i : Qss threshold of cut */
+)
+{
+ /* internal variable */
+ Word16 i, j, k;
+
+ Word16 num_subband_smooth_fx;
+ Word16 num_subband_smooth_pre_fx;
+
+ Word16 exp_normd;
+ Word16 exp_shift;
+
+ Word16 max_val_norm_fx;
+
+ Word16 Qmax_val_norm[L_FRAME32k / L_SB];
+
+ Word32 L_inBuf_abs;
+ Word32 L_inBuf_pss[L_FRAME32k];
+ Word32 L_max_val[L_FRAME32k / L_SB];
+ Word16 outBuf_pss_fx[L_FRAME32k];
+
+ Word16 m, n;
+ Word16 cnt_zero_cont;
+ Word16 n_list[BANDS_MAX];
+ Word16 reset_flag;
+ Word16 pp, pk;
+ Word16 exp_norm;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+
+ *Qss = 10;
+
+ num_subband_smooth_pre_fx = mult(fLen, 21845); /* 1/L_SB = 1/12 = 21845(Q18) Q = exp_normn-18 */
+ num_subband_smooth_fx = shr(num_subband_smooth_pre_fx, 18 - 15);
+ IF(NE_16(num_subband_smooth_pre_fx, shl(num_subband_smooth_fx, 18 - 15)))
+ {
+ num_subband_smooth_fx++;
+ }
+
+ FOR(i = 0; i < fLen; i++)
+ {
+ L_inBuf_pss[i] = L_inBuf[i];
+ move32();
+ outBuf_pss_fx[i] = 0;
+ move16();
+ }
+
+ FOR(i = fLen; i < fLen + (num_subband_smooth_fx * L_SB - fLen); i++)
+ {
+ L_inBuf_pss[i] = L_deposit_l(0);
+ outBuf_pss_fx[i] = 0;
+ move16();
+ }
+
+ j = 0;
+ FOR(i = 0; i < num_subband_smooth_fx; i++)
+ {
+ L_max_val[i] = L_deposit_l(0);
+ FOR(k = 0; k < L_SB; k++)
+ {
+ L_inBuf_abs = L_abs(L_inBuf_pss[j]);
+ if (LT_32(L_max_val[i], L_inBuf_abs))
+ {
+ L_max_val[i] = L_inBuf_abs;
+ move32();
+ }
+
+ j++;
+ }
+ }
+
+ /* convert to maximum amplitude frequency log scale envelope */
+ j = 0;
+ FOR(i = 0; i < num_subband_smooth_fx; i++)
+ {
+ /* max_val_norm = 10.0f / (max_val[i] + 0.001f); */
+ /* 10.0f : 0x2800, Q10 */
+ IF(GT_32(L_max_val[i], 0x1L))
+ {
+ exp_normd = norm_l(L_max_val[i]);
+#ifdef BASOP_NOGLOB
+ max_val_norm_fx = div_s(0x2800, round_fx_o(L_shl_o(L_max_val[i], exp_normd, &Overflow), &Overflow)); /* Q10-(Qs+exp_normd-16) */
+#else
+ max_val_norm_fx = div_s(0x2800, round_fx(L_shl(L_max_val[i], exp_normd))); /* Q10-(Qs+exp_normd-16) */
+#endif
+ Qmax_val_norm[i] = sub(10 - 12 + 16 + 15, exp_normd);
+ move16(); /* 10 - (12+exp_normd-16) +15 */;
+ }
+ ELSE
+ {
+ max_val_norm_fx = 0;
+ move16();
+ Qmax_val_norm[i] = 0;
+ move16();
+ }
+
+ exp_shift = sub(*Qss, add(Qmax_val_norm[i], -19));
+ FOR(k = 0; k < L_SB; k++)
+ {
+ exp_norm = norm_l(L_inBuf_pss[j]);
+ IF(L_inBuf_pss[j] == 0x0L)
+ {
+ outBuf_pss_fx[j] = 0;
+ move16();
+ }
+ ELSE IF(LT_32(L_abs(L_inBuf_pss[j]), L_max_val[i]))
+ {
+ IF(L_inBuf_pss[j] >= 0)
+ {
+#ifdef BASOP_NOGLOB
+ outBuf_pss_fx[j] = round_fx_o(L_shl_o(Mpy_32_16_r(L_shl_o(L_inBuf_pss[j], exp_norm, &Overflow), max_val_norm_fx), sub(exp_shift, exp_norm), &Overflow), &Overflow);
+#else
+ outBuf_pss_fx[j] = round_fx(L_shl(Mpy_32_16_r(L_shl(L_inBuf_pss[j], exp_norm), max_val_norm_fx), sub(exp_shift, exp_norm)));
+#endif
+ move32();
+ }
+ ELSE
+ {
+#ifdef BASOP_NOGLOB
+ outBuf_pss_fx[j] = negate(round_fx_o(L_shl_o(Mpy_32_16_r(L_shl_o(L_abs(L_inBuf_pss[j]), exp_norm, &Overflow), max_val_norm_fx), sub(exp_shift, exp_norm), &Overflow), &Overflow));
+#else
+ outBuf_pss_fx[j] = negate(round_fx(L_shl(Mpy_32_16_r(L_shl(L_abs(L_inBuf_pss[j]), exp_norm), max_val_norm_fx), sub(exp_shift, exp_norm))));
+#endif
+ }
+ }
+ ELSE
+ {
+ /* CLIP, for avoiding computational difference */
+ outBuf_pss_fx[j] = 0x2800;
+ move16();
+ if (L_inBuf_pss[j] < 0x0L)
+ {
+ outBuf_pss_fx[j] = -0x2800;
+ move16();
+ }
+ }
+ j++;
+ }
+ }
+
+ k = 0;
+ move16();
+ m = 0;
+ move16();
+ n = 0;
+ move16();
+ reset_flag = 0;
+ move16();
+ n_list[0] = 0;
+ move16();
+ FOR(j = 0; j < num_subband_smooth_fx; j++)
+ {
+ cnt_zero_cont = 0;
+ move16();
+ FOR(i = 0; i < L_SB; i++)
+ {
+ cnt_zero_cont = add(cnt_zero_cont, 1);
+ if (outBuf_pss_fx[k] != 0)
+ {
+ cnt_zero_cont = 0;
+ move16();
+ }
+ k = add(k, 1);
+ }
+
+ IF(cnt_zero_cont != 0)
+ {
+ test();
+ IF(GT_16(j, div_s_ss(subband_search_offsets[0], L_SB)) && reset_flag == 0)
+ {
+ n = 0;
+ move16();
+ reset_flag = 1;
+ move16();
+ }
+ n_list[n] = j;
+ move16();
+ n = add(n, 1);
+ }
+
+ test();
+ if (EQ_16(reset_flag, 1) && EQ_16(n, 1))
+ {
+ m = 0;
+ move16();
+ }
+
+ pk = sub(k, L_SB);
+ IF(GT_16(cnt_zero_cont, mult_r(L_SB, 24576))) /* cnt_zero_cont > 3*L_SB/4 */
+ {
+ pp = round_fx(L_shl(L_mult(n_list[m], L_SB), 15));
+ FOR(i = 0; i < L_SB; i++)
+ {
+ if (outBuf_pss_fx[pk + i] == 0)
+ {
+ outBuf_pss_fx[pk + i] = shr(outBuf_pss_fx[pp + i], 1);
+ move16();
+ }
+ }
+ m = add(m, 1);
+ }
+ }
+
+ FOR(i = 0; i < fLen; i++)
+ {
+ outBuf_fx[i] = 0x0;
+ move16();
+ if (GT_16(abs_s(outBuf_pss_fx[i]), th_cut_fx))
+ {
+ outBuf_fx[i] = outBuf_pss_fx[i];
+ move16();
+ }
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * Get20Log10Spec()
+ *
+ * Calculates 20*log10() for the specified samples. Input and output buffers can be the same.
+ *-------------------------------------------------------------------*/
+
+void Get20Log10Spec_fx(
+ const Word32 *L_inBuf, /* i : input Q_inBuf */ /* L_inBuf >=0, so L_abs is omitted. */
+ Word16 *outBuf_fx, /* o : output Q7 */
+ const Word16 fLen, /* i : loop length */
+ const Word16 Q_inBuf /* i : Qvalue of L_inBuf */
+)
+{
+ Word16 i;
+ Word16 exp, frac;
+
+ Word32 L_tmp;
+
+ Word32 L_lamda;
+ Word16 Q_inBuf_1;
+
+ Q_inBuf_1 = sub(Q_inBuf, 1);
+ L_lamda = L_shl(1L, Q_inBuf_1); /* +1 : Q_inBuf -> Q_inBuf-1 for overflow problem */
+
+ FOR(i = 0; i < fLen; i++)
+ {
+ /*outBuf++ = (float) (20.0f * log10(fabs(*inBuf + 1.0))); */
+ L_tmp = L_add(L_shr(*L_inBuf++, 1), L_lamda);
+ exp = 31;
+ move16();
+ if (L_tmp != 0x0L)
+ {
+ exp = norm_l(L_tmp);
+ }
+ frac = Log2_norm_lc(L_shl(L_tmp, exp));
+ exp = sub(30, exp);
+ exp = sub(exp, Q_inBuf_1);
+ L_tmp = L_Comp(exp, frac);
+
+ L_tmp = Mpy_32_16_1(L_tmp, 24660); /* 6.0206 in Q12 */
+ L_tmp = L_shl(L_tmp, 2 + 8); /* Q7 */
+ *outBuf_fx++ = round_fx(L_tmp);
+ }
+
+ return;
+}
+/*-------------------------------------------------------------------*
+ * convert_lagIndices_pls2smp()
+ *
+ *
+ *-------------------------------------------------------------------*/
+void convert_lagIndices_pls2smp_fx(
+ Word16 lagIndices_in_fx[],
+ Word16 nBands_search_fx,
+ Word16 lagIndices_out_fx[],
+ const Word16 sspectra_fx[],
+ const Word16 sbWidth_fx[],
+ const Word16 fLenLow_fx
+)
+{
+ Word16 sb;
+ Word16 i, cnt;
+
+ FOR(sb = 0; sb < nBands_search_fx; sb++)
+ {
+ cnt = 0;
+ move16();
+ i = 0;
+ move16();
+
+ WHILE(LE_16(cnt, lagIndices_in_fx[sb]))
+ {
+ if (sspectra_fx[subband_search_offsets[sb] + i] != 0)
+ {
+ cnt = add(cnt, 1);
+ }
+
+ i = add(i, 1);
+
+ IF(GE_16(add(subband_search_offsets[sb], add(i, sbWidth_fx[sb])), fLenLow_fx))
+ {
+ BREAK;
+ }
+ }
+
+ lagIndices_out_fx[sb] = add(sub(i, 1), subband_search_offsets[sb]);
+ move16();
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * get_usebit_npswb()
+ *
+ *
+ *-------------------------------------------------------------------*/
+Word16 get_usebit_npswb_fx(
+ Word16 hqswb_clas_fx
+)
+{
+ Word16 i;
+ Word16 bits;
+ Word16 up_lmt;
+ const Word16 *bits_req;
+
+ up_lmt = 0;
+ move16();
+ bits_req = bits_lagIndices_modeNormal;
+ move16();
+ bits = 0;
+ move16();
+
+ IF(EQ_16(hqswb_clas_fx, HQ_NORMAL))
+ {
+ up_lmt = NB_SWB_SUBBANDS;
+ move16();
+ bits_req = bits_lagIndices_modeNormal;
+ move16();
+ }
+ ELSE IF(EQ_16(hqswb_clas_fx, HQ_HARMONIC))
+ {
+ up_lmt = NB_SWB_SUBBANDS_HAR_SEARCH_SB;
+ move16();
+ bits_req = bits_lagIndices_mode0_Har;
+ move16();
+ bits = 2;
+ move16(); /*noise gain*/
+ }
+
+ FOR(i = 0; i < up_lmt; i++)
+ {
+ bits = add(bits, bits_req[i]);
+ move16();
+ }
+
+ return bits;
+}
+/*-------------------------------------------------------------------*
+ * SpectrumSmoothing_nss()
+ *
+ *
+ *-------------------------------------------------------------------*/
+void SpectrumSmoothing_nss_fx(
+ const Word32 *L_inBuf, /* i : lowband MDCT */
+ Word16 *outBuf_fx, /* o : output */
+ Word16 *Qss, /* o : Q value of output vector */
+ const Word16 fLen /* i : length */
+)
+{
+ /* internal variable */
+ Word16 i, k;
+
+ Word16 inBuf_fx[L_FRAME32k];
+ Word16 Qm;
+ Word32 L_tmp[L_FRAME32k];
+
+ Word16 num_subband_smooth_fx;
+ Word16 exp_tmp;
+
+ Word16 inBufw_fx[L_FRAME32k + L_SB_NSS];
+ Word16 outBufw_fx[L_FRAME32k + L_SB_NSS];
+ Word32 L_outBufw[L_FRAME32k + L_SB_NSS];
+ Word16 Qo[NUM_SUBBAND_SMOOTH_MAX];
+
+ Word16 avg_val_fx;
+ Word32 L_avg_val;
+ Word16 r0_fx;
+ Word32 L_r0;
+ Word32 L_temp;
+ Word16 temp_fx;
+
+ Word16 max_peak_fx;
+
+ Word16 smr_fx;
+ Word32 L_smr;
+
+ Word32 L_temp_sum_1[NUM_SUBBAND_SMOOTH_MAX];
+ Word32 L_temp_sum_2[NUM_SUBBAND_SMOOTH_MAX];
+ Word32 L_temp_sum_3[NUM_SUBBAND_SMOOTH_MAX];
+
+
+ Word16 temp_sum_smooth_fx[NUM_SUBBAND_SMOOTH_MAX];
+ Word16 temp_sum_div_fx[NUM_SUBBAND_SMOOTH_MAX];
+ Word16 Qsumdiv[NUM_SUBBAND_SMOOTH_MAX];
+ Word32 L_temp1;
+ Word16 temp_hi;
+ Word16 temp_lo;
+
+
+ Word16 avg_val2_fx;
+ Word32 L_avg_val2;
+ Word16 Qavg_val;
+ Word16 Qsmr;
+ Word16 exp, frac;
+
+ Word16 clip_cof_fx;
+
+ Word16 thre_fx, thre_fx_neg;
+ Word16 thre_min_fx;
+
+ Word16 temp_sum_log_fx[NUM_SUBBAND_SMOOTH_MAX];
+ Word16 exp_norm;
+ Word16 exp_normn;
+ Word16 exp_normd;
+ Word16 exp_shift;
+
+ L_tmp[0] = L_deposit_l(0);
+ FOR(i = 0; i < fLen; i++)
+ {
+ L_tmp[0] = L_or(L_tmp[0], L_abs(L_inBuf[i]));
+ }
+ exp_norm = norm_l(L_tmp[0]);
+ Qm = sub(exp_norm, 4); /* Qm = sub(add(12, exp_norm), 16); */
+
+ FOR(i = 0; i < fLen; i++)
+ {
+ L_tmp[i] = L_shl(L_inBuf[i], exp_norm); /* Q(12+exp_norm) */ move32();
+ inBuf_fx[i] = round_fx(L_tmp[i]); /* Qm */
+ }
+
+ num_subband_smooth_fx = shr(fLen, 3); /* L_SB_NSS=8 shr(target, 3); */
+
+ /* buffer copy for fractional point */
+ FOR(i = 0; i < fLen; i++)
+ {
+ inBufw_fx[i] = inBuf_fx[i];
+ move16();
+ outBufw_fx[i] = 0;
+ move16();
+ }
+
+ /* initialization of over buffer for fractional point */
+ k = add(fLen, L_SB_NSS);
+ FOR(i = fLen; i < k; i++)
+ {
+ inBufw_fx[i] = 0;
+ move16();
+ outBufw_fx[i] = 0;
+ move16();
+ }
+
+ L_avg_val = L_deposit_l(0);
+ FOR(i = 0; i < fLen; i++)
+ {
+ L_r0 = L_abs(L_deposit_l(inBufw_fx[i]));
+ L_avg_val = L_add(L_avg_val, L_r0);
+ }
+ exp_normn = norm_l(L_avg_val);
+ exp_normn = sub(exp_normn, 1);
+ exp_normd = norm_s(fLen);
+ avg_val_fx = div_l(L_shl(L_avg_val, exp_normn), shl(fLen, exp_normd)); /* (Qs+exp_norm+exp_normn) - (exp_normd) - 15 */
+ Qavg_val = sub(add(Qm, sub(exp_normn, exp_normd)), 1);
+
+ max_peak_fx = 0;
+ move16();
+ FOR(i = 0; i < fLen; i++)
+ {
+ r0_fx = abs_s(inBufw_fx[i]);
+ if (LT_16(max_peak_fx, r0_fx))
+ {
+ max_peak_fx = r0_fx;
+ move16(); /* Qm */
+ }
+ }
+
+ /*smr = 10.0f * (float)log10( max_peak/(avg_val + 1.0e-20) + 1.0e-20 ); */
+ exp_normn = norm_s(max_peak_fx);
+ exp_normn = sub(exp_normn, 1);
+
+ avg_val_fx = s_max(avg_val_fx, 0x1);
+ exp_normd = norm_s(avg_val_fx);
+
+ smr_fx = div_s(shl(max_peak_fx, exp_normn), shl(avg_val_fx, exp_normd)); /* Q(exp_normn-exp_normd+15) */
+ exp_tmp = sub(exp_normn, exp_normd);
+ L_smr = L_deposit_h(smr_fx); /* Q+16 -> Q(exp_normn-exp_normd+15+16) */
+ Qsmr = add(sub(add(Qm, exp_tmp), Qavg_val), 31);
+
+ L_temp = L_add(L_shr(L_smr, 1), 0x1L); /* add minimum value */
+ exp = norm_l(L_temp);
+ frac = Log2_norm_lc(L_shl(L_temp, exp));
+ exp = sub(30, exp);
+ exp = sub(exp, sub(Qsmr, 1));
+ L_temp = L_Comp(exp, frac);
+
+ L_temp = Mpy_32_16_1(L_temp, 12330); /* 3.0103 in Q12 */
+ L_temp = L_shl(L_temp, 2 + 8); /* Q7 */
+ smr_fx = round_fx(L_temp);
+
+ FOR(i = 0; i < num_subband_smooth_fx; i++)
+ {
+ L_temp_sum_1[i] = L_deposit_l(0);
+ L_temp_sum_2[i] = L_deposit_l(0);
+
+ FOR(k = 0; k < L_SB_NSS_HALF; k++)
+ {
+ L_temp_sum_1[i] = L_add(L_temp_sum_1[i], extract_l(abs_s(inBufw_fx[k + L_SB_NSS * i]))); /* Qm */ move32();
+ }
+
+ FOR(k = L_SB_NSS_HALF; k < L_SB_NSS; k++)
+ {
+ L_temp_sum_2[i] = L_add(L_temp_sum_2[i], extract_l(abs_s(inBufw_fx[k + L_SB_NSS * i]))); /* Qm */ move32();
+ }
+
+ L_temp_sum_1[i] = L_shr(L_temp_sum_1[i], 2); /* *0.25 guarantee low-side 16bit for L_temp_sum_* */ move32();
+ L_temp_sum_2[i] = L_shr(L_temp_sum_2[i], 2); /* *0.25 */ move32();
+ L_temp_sum_3[i] = L_mult(extract_l(L_temp_sum_1[i]), extract_l(L_temp_sum_2[i])); /* Qm*2+1 */ move32();
+
+ IF(L_temp_sum_3[i] == 0)
+ {
+ L_temp_sum_3[i] = L_shl(L_add(L_temp_sum_1[i], L_temp_sum_2[i]), add(Qm, 1)); /*Q(Qm+Qm+1) */ move32();
+ }
+ }
+
+ exp_norm = add(shl(Qm, 1), 1);
+ Get20Log10Spec_fx(L_temp_sum_3, temp_sum_log_fx, num_subband_smooth_fx, exp_norm);
+
+ /* temp_sum_log_fx // *0.5 Q7 -> Q8 (not change) */
+ SmoothSpec_fx(temp_sum_log_fx, temp_sum_smooth_fx, num_subband_smooth_fx);
+
+ FOR(i = 0; i < num_subband_smooth_fx; i++)
+ {
+ L_temp1 = L_mult(temp_sum_smooth_fx[i], 1360); /* Q8+Q13+1=Q22, 1360(Q13) = 0.1660 = 3.321928(log2^10) * 0.05 */
+ L_temp1 = L_shr(L_temp1, 6); /* Q22 -> Q16 */
+ L_temp1 = L_negate(L_temp1);
+ temp_lo = L_Extract_lc(L_temp1, &temp_hi);
+ Qsumdiv[i] = sub(14, temp_hi);
+ temp_sum_div_fx[i] = extract_l(Pow2(14, temp_lo)); /* Qsumdiv[i] */
+ exp_norm = norm_s(temp_sum_div_fx[i]);
+ temp_sum_div_fx[i] = shl(temp_sum_div_fx[i], exp_norm);
+ move16();
+ Qsumdiv[i] = add(Qsumdiv[i], exp_norm);
+ move16();
+ }
+
+ *Qss = 31;
+ move16();
+ FOR(i = 0; i < num_subband_smooth_fx; i++)
+ {
+ Qo[i] = add(add(Qm, Qsumdiv[i]), 1);
+ L_temp1 = 0x0L;
+ FOR(k = 0; k < L_SB_NSS; k++)
+ {
+ L_outBufw[k + L_SB_NSS * i] = L_mult(inBufw_fx[k + L_SB_NSS * i], temp_sum_div_fx[i]);
+ move32();
+ L_temp1 = L_or(L_temp1, L_abs(L_outBufw[k + L_SB_NSS * i]));
+ }
+ exp_norm = 31;
+ if (L_temp1 != 0x0L)
+ {
+ exp_norm = norm_l(L_temp1);
+ }
+ FOR(k = 0; k < L_SB_NSS; k++)
+ {
+ L_outBufw[k + L_SB_NSS * i] = L_shl(L_outBufw[k + L_SB_NSS * i], exp_norm);
+ move32();
+ }
+ Qo[i] = add(Qo[i], exp_norm);
+ move16();
+ *Qss = s_min(*Qss, Qo[i]);
+ move16();
+ }
+
+ FOR(i = 0; i < num_subband_smooth_fx; i++)
+ {
+ exp_shift = sub(*Qss, Qo[i]);
+ exp_shift = s_max(-31, exp_shift);
+ FOR(k = 0; k < L_SB_NSS; k++)
+ {
+ L_outBufw[k + L_SB_NSS * i] = L_shl(L_outBufw[k + L_SB_NSS * i], exp_shift);
+ move16();
+ outBufw_fx[k + L_SB_NSS * i] = round_fx(L_outBufw[k + L_SB_NSS * i]);
+ }
+ }
+ *Qss = sub(*Qss, 16);
+
+ L_avg_val2 = L_deposit_l(0);
+ FOR(i = 0; i < fLen; i++)
+ {
+ L_r0 = L_abs(L_deposit_l(outBufw_fx[i]));
+ L_avg_val2 = L_add(L_avg_val2, L_r0); /* Qss */
+ }
+
+ exp_normn = norm_l(L_avg_val2);
+ exp_normn = sub(exp_normn, 1);
+ exp_normd = norm_s(fLen);
+ temp_fx = div_l(L_shl(L_avg_val2, exp_normn), shl(fLen, exp_normd)); /* Q(obw+exp_normn - exp_normd) - 1 */
+ avg_val2_fx = shr(temp_fx, sub(sub(exp_normn, exp_normd), 1)); /* Qss */
+
+ /*clip_cof = smr - 16.0f; */
+ clip_cof_fx = sub(smr_fx, 2048); /* 2048: 16.0f (Q7) */
+ if (clip_cof_fx < 0)
+ {
+ clip_cof_fx = 0;
+ move16();
+ }
+ /*clip_cof += 2.5f; */
+ clip_cof_fx = add(clip_cof_fx, 320); /* 320: 2.5f (Q7) */
+
+ thre_fx = round_fx(L_shl(L_mult(avg_val2_fx, clip_cof_fx), 8)); /* Q(Qss+7+1) -> Qss */
+ thre_fx_neg = negate(thre_fx);
+ thre_min_fx = shr(avg_val2_fx, 2); /* *0.25f // Qss */
+
+ FOR(i = 0; i < fLen; i++)
+ {
+ IF(GT_16(abs_s(outBufw_fx[i]), thre_fx))
+ {
+ temp_fx = thre_fx;
+ move16();
+ if (outBufw_fx[i] < 0)
+ {
+ temp_fx = thre_fx_neg;
+ move16();
+ }
+ outBufw_fx[i] = temp_fx;
+ move16();
+ }
+
+ if (LT_16(abs_s(outBufw_fx[i]), thre_min_fx))
+ {
+ outBufw_fx[i] = 0;
+ move16();
+ }
+ }
+
+ FOR(i = 0; i < fLen; i++)
+ {
+ outBuf_fx[i] = outBufw_fx[i];
+ move16(); /* Qss */
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * return_bits_normal2
+ *
+ * arrange bit_budget when HQ_NORMAL
+ *-------------------------------------------------------------------*/
+
+void return_bits_normal2_fx(
+ Word16 *bit_budget_fx, /* i/o : bit budget */
+ const Word16 p2a_flags_fx[], /* i : HF tonal indicator */
+ const Word16 bands_fx, /* i : Total number of Subbands in a frame */
+ const Word16 bits_lagIndices_fx[] /* i : bits for lagIndices */
+)
+{
+ Word16 i;
+ const Word16 *p_p2a_flags_fx;
+
+ p_p2a_flags_fx = &p2a_flags_fx[sub(bands_fx, NB_SWB_SUBBANDS)];
+ FOR(i = 0; i < NB_SWB_SUBBANDS; i++)
+ {
+ if (EQ_16(*p_p2a_flags_fx++, 1))
+ {
+ *bit_budget_fx = add(*bit_budget_fx, bits_lagIndices_fx[i]);
+ move16();
+ }
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * preset_hq2_swb
+ *
+ * preset before swb_bwe_{enc,dec}_lr
+ *-------------------------------------------------------------------*/
+
+void preset_hq2_swb_fx
+(
+ const Word16 hqswb_clas_fx, /* i : HQ2 class information */
+ const Word16 band_end_fx[], /* i : band end of each SB */
+ Word16 *har_bands_fx, /* i/o : Number of LF harmonic bands */
+ Word16 p2a_bands_fx, /* i : flag for peakness */
+ const Word16 length_fx, /* i : processed band length */
+ const Word16 bands_fx, /* i : Total number of Subbands in a frame */
+ Word16 *lowlength_fx, /* o : lowband length */
+ Word16 *highlength_fx, /* o : highband length */
+ Word32 L_m[] /* o : MDCT */
+)
+{
+ IF(EQ_16(hqswb_clas_fx, HQ_HARMONIC))
+ {
+ *har_bands_fx = add(sub(bands_fx, p2a_bands_fx), 1);
+ move16();
+ *lowlength_fx = add(band_end_fx[*har_bands_fx - 1], 1);
+ move16();
+ }
+ ELSE
+ {
+ *lowlength_fx = add(band_end_fx[bands_fx - NB_SWB_SUBBANDS - 1], 1);
+ move16();
+ }
+
+ *highlength_fx = sub(length_fx, *lowlength_fx);
+ move16();
+
+ set32_fx(L_m, 0, length_fx);
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * preset_hq2_swb
+ *
+ * post process after swb_bwe_{enc,dec}_lr
+ *-------------------------------------------------------------------*/
+
+void post_hq2_swb_fx
+(
+ const Word32 L_m[], /* i : input_signal */
+ const Word16 lowlength_fx, /* i : lowband length */
+ const Word16 highlength_fx, /* i : highband length */
+ const Word16 hqswb_clas_fx, /* i : HQ2 class information */
+ const Word16 har_bands_fx, /* i : Number of LF harmonic bands */
+ const Word16 bands_fx, /* i : Total number of Subbands in a frame */
+ const Word16 p2a_flags_fx[], /* i : HF tonal indicator */
+ const Word16 band_start_fx[], /* i : band start of each SB */
+ const Word16 band_end_fx[], /* i : band end of each SB */
+ Word32 L_y2[], /* o : output signal */
+ Word16 npulses_fx[] /* i/o : Number of coded spectrum */
+)
+{
+ Word16 i, k;
+
+ /* copy the scratch buffer to the output */
+ Copy32(&L_m[lowlength_fx], &L_y2[lowlength_fx], highlength_fx);
+
+ IF(EQ_16(hqswb_clas_fx, HQ_HARMONIC))
+ {
+ k = har_bands_fx;
+ move16();
+ }
+ ELSE
+ {
+ k = sub(bands_fx, NB_SWB_SUBBANDS);
+ move16();
+ }
+
+ FOR(; k < bands_fx; k++)
+ {
+ test();
+ IF(p2a_flags_fx[k] == 0 && npulses_fx[k] == 0)
+ {
+ FOR(i = band_start_fx[k]; i <= band_end_fx[k]; i++)
+ {
+ if (L_y2[i] != 0)
+ {
+ npulses_fx[k] = add(npulses_fx[k], 1);
+ move16();
+ }
+ }
+ }
+ }
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * GetSynthesizedSpecThinOut()
+ *
+ * Synthesize the spectrum in generic subband coding
+ *--------------------------------------------------------------------------*/
+
+void GetSynthesizedSpecThinOut_fx(
+ const Word16 *predBuf_fx, /* i : Qss: prediction buffer (i.e., lowband) */
+ const Word16 Qss, /* i : Q value of input vector */
+ Word32 *L_outBuf, /* o : QsL: synthesized spectrum */
+ Word16 QsL, /* o : Q value of synthesized spectrum */
+ const Word16 nBands_fx, /* i : Q0: number of subbands calculated */
+ const Word16 *sbWidth_fx, /* i : Q0: subband lengths */
+ const Word16 *lagIndices_fx, /* i : Q0: lowband index for each subband */
+ const Word16 *lagGains_fx, /* i : Qgain: lagGain for each subband */
+ const Word16 *QlagGains_fx, /* i : Q0: Q value of lagGains_fx */
+ const Word16 predBufLen_fx /* i : Q0: lowband length */
+)
+{
+ Word16 i, sb;
+ Word16 fLen_fx, lag_fx;
+
+ const Word16 *ptr_predBuf_fx;
+ Word32 *ptr_L_outBuf;
+ Word32 *ptr_L_in_outBuf;
+
+ Word16 exp_shift;
+
+ ptr_L_in_outBuf = L_outBuf;
+ ptr_L_outBuf = L_outBuf;
+
+ FOR(sb = 0; sb < nBands_fx; sb++)
+ {
+ fLen_fx = sbWidth_fx[sb];
+ lag_fx = lagIndices_fx[sb];
+
+ if (GT_16(add(lag_fx, fLen_fx), predBufLen_fx))
+ {
+ /* should never happen */
+ lag_fx = sub(predBufLen_fx, fLen_fx);
+ }
+ ptr_predBuf_fx = predBuf_fx + lag_fx;
+
+
+ exp_shift = sub(add(add(Qss, QlagGains_fx[sb]), 1), QsL);
+
+ FOR(i = 0; i < fLen_fx; i++)
+ {
+ IF(*ptr_predBuf_fx >= 0x0L)
+ {
+ *ptr_L_outBuf++ = L_shr(L_mult(*ptr_predBuf_fx++, lagGains_fx[sb]), exp_shift);
+ move32(); /* Qss+QlagGains+1 -> QsL */
+ }
+ ELSE
+ {
+ *ptr_L_outBuf++ = L_negate(L_shr(L_mult(abs_s(*ptr_predBuf_fx++), lagGains_fx[sb]), exp_shift));
+ move32(); /* Qss+QlagGains+1 -> QsL */
+ }
+ }
+ }
+
+ ptr_L_outBuf = ptr_L_in_outBuf;
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * div_s_ss
+ *
+ * compute division with Word16 Q0. ex. 10/2 -> 5
+ *--------------------------------------------------------------------------*/
+
+Word16 div_s_ss( /* o: result of division (Word16 Q0) */
+ const Word16 n, /* i: numerator (Word16 Q0 */
+ const Word16 d /* i: denominator (Word16 Q0) */
+)
+{
+ Word16 norm_n, norm_d;
+ Word16 ns, ds;
+ Word16 res;
+
+ test();
+ IF(n == 0 || d == 0)
+ {
+ return 0;
+ }
+
+ norm_n = norm_s(n);
+ norm_n = sub(norm_n, 1);
+ ns = shl(n, norm_n);
+
+ norm_d = norm_s(d);
+ ds = shl(d, norm_d);
+
+ res = shr(div_s(ns, ds), add(sub(norm_n, norm_d), 15));
+
+ return res;
+}
+/*-------------------------------------------------------------------*
+ * hf_parinitiz()
+ *
+ *
+ *-------------------------------------------------------------------*/
+void hf_parinitiz_fx(
+ const Word32 L_total_brate,
+ const Word16 hqswb_clas_fx,
+ Word16 lowlength_fx,
+ Word16 highlength_fx,
+ Word16 wBands_fx[],
+ const Word16 **subband_search_offset_fx,
+ const Word16 **subband_offsets_fx,
+ Word16 *nBands_fx,
+ Word16 *nBands_search_fx,
+ Word16 *swb_lowband_fx,
+ Word16 *swb_highband_fx
+)
+{
+ *swb_lowband_fx = lowlength_fx;
+ move16();
+ *swb_highband_fx = highlength_fx;
+ move16();
+
+ IF(EQ_16(hqswb_clas_fx, HQ_HARMONIC))
+ {
+ /* Mode dependent initializations (performed every frame in case mode-switching implemented) */
+ *nBands_fx = NB_SWB_SUBBANDS_HAR;
+ move16();
+ *nBands_search_fx = NB_SWB_SUBBANDS_HAR_SEARCH_SB;
+ move16();
+
+ IF(EQ_32(L_total_brate, HQ_13k20))
+ {
+ wBands_fx[0] = SWB_SB_BW_LEN0_12KBPS_HAR;
+ move16();
+ wBands_fx[1] = SWB_SB_BW_LEN1_12KBPS_HAR;
+ move16();
+ wBands_fx[2] = SWB_SB_BW_LEN2_12KBPS_HAR;
+ move16();
+ wBands_fx[3] = SWB_SB_BW_LEN3_12KBPS_HAR;
+ move16();
+ *subband_offsets_fx = subband_offsets_sub5_13p2kbps_Har;
+ move16();
+ *subband_search_offset_fx = subband_search_offsets_13p2kbps_Har;
+ move16();
+ }
+ ELSE
+ {
+ wBands_fx[0] = SWB_SB_BW_LEN0_16KBPS_HAR;
+ move16();
+ wBands_fx[1] = SWB_SB_BW_LEN1_16KBPS_HAR;
+ move16();
+ wBands_fx[2] = SWB_SB_BW_LEN2_16KBPS_HAR;
+ move16();
+ wBands_fx[3] = SWB_SB_BW_LEN3_16KBPS_HAR;
+ move16();
+ *subband_offsets_fx = subband_offsets_sub5_16p4kbps_Har;
+ move16();
+ *subband_search_offset_fx = subband_search_offsets_16p4kbps_Har;
+ move16();
+ }
+ }
+ ELSE
+ {
+ /* Mode-dependent initializations (performed every frame in case mode-switching implemented) */
+ *nBands_fx = NB_SWB_SUBBANDS;
+ move16();
+ *nBands_search_fx = NB_SWB_SUBBANDS;
+ move16();
+
+ IF(EQ_32(L_total_brate, HQ_13k20))
+ {
+ wBands_fx[0] = SWB_SB_LEN0_12KBPS;
+ move16();
+ wBands_fx[1] = SWB_SB_LEN1_12KBPS;
+ move16();
+ wBands_fx[2] = SWB_SB_LEN2_12KBPS;
+ move16();
+ wBands_fx[3] = SWB_SB_LEN3_12KBPS;
+ move16();
+ *subband_offsets_fx = subband_offsets_12KBPS;
+ move16();
+ }
+ ELSE
+ {
+ wBands_fx[0] = SWB_SB_LEN0_16KBPS;
+ move16();
+ wBands_fx[1] = SWB_SB_LEN1_16KBPS;
+ move16();
+ wBands_fx[2] = SWB_SB_LEN2_16KBPS;
+ move16();
+ wBands_fx[3] = SWB_SB_LEN3_16KBPS;
+ move16();
+ *subband_offsets_fx = subband_offsets_16KBPS;
+ move16();
+ }
+ }
+
+ return;
+}
+
+void GetlagGains_fx(
+ const Word16 *predBuf_fx, /* i: Qss Low freq. Smoothed Spectrum */
+ const Word16 Qss, /* i: Q0 Q value of predBuf */
+ const Word32 *L_band_energy, /* i: Qbe Band Energy */
+ const Word16 Qbe, /* i: Q0 Q value of band energy */
+ const Word16 nBands, /* i: Q0 number of SWB subbands */
+ const Word16 *sbWidth, /* i: Q0 width of SWB subbands */
+ const Word16 *lagIndices, /* i: Q0 lagIndices */
+ const Word16 predBufLen, /* i: Q0 length of predBuf */
+ Word16 *lagGains_fx, /* o: QlagGains lagGains */
+ Word16 *QlagGains /* o: Q0 Q value of lagGains */
+)
+{
+ Word16 i;
+ Word16 sb, fLen, lag;
+
+ Word32 L_outBuf[L_FRAME32k];
+
+ Word16 *ptr_ssBuf_fx;
+ Word32 L_lagEnergy;
+ Word16 Qene;
+
+ Word16 temp_lo_fx, temp_hi_fx;
+ Word16 pow_fx;
+ Word16 Qpow;
+ Word16 exp_normd, exp_normn;
+ Word16 Qdiv;
+ Word16 exp_norm;
+
+ Word16 temp_fx;
+ Word32 L_temp;
+
+ Word16 ssBuf_fx[L_FRAME32k];
+ Word16 exp_norm_ss;
+
+ exp_norm_ss = 2;
+ move16();
+ FOR(i = 0; i < predBufLen; i++)
+ {
+ ssBuf_fx[i] = shr(predBuf_fx[i], exp_norm_ss);
+ move16(); /* Qss+exp_norm_ss */
+ }
+
+ FOR(sb = 0; sb < nBands; sb++)
+ {
+ fLen = sbWidth[sb];
+ move16();
+ lag = lagIndices[sb];
+ move16();
+
+ IF(GT_16(add(lag, fLen), predBufLen))
+ {
+ /* should never happen */
+ lag = sub(predBufLen, fLen);
+ move16();
+ }
+
+ GetPredictedSignal_fx(predBuf_fx, L_outBuf, lag, fLen, 0x7fff, 15);
+
+ ptr_ssBuf_fx = ssBuf_fx + lag;
+ L_lagEnergy = L_deposit_l(0);
+ FOR(i = 0; i < fLen; i++)
+ {
+ L_lagEnergy = L_mac(L_lagEnergy, *ptr_ssBuf_fx, *ptr_ssBuf_fx); /* (Qss-exp_norm_ss)*2+1 */
+ ptr_ssBuf_fx++;
+ }
+ Qene = add(shl(sub(Qss, exp_norm_ss), 1), 1);
+
+ IF(L_lagEnergy != 0x0L)
+ {
+ /* lagGains[sb] = (float)sqrt( pow(2.0f, band_energy[sb]) / lagEnergy ); */
+ /* Pow part (pow(2.0f, band_energy) ) */
+ L_temp = L_shr(L_band_energy[sb], sub(Qbe, 16)); /* Qbe -> Q16 */
+ temp_lo_fx = L_Extract_lc(L_temp, &temp_hi_fx);
+ Qpow = sub(14, temp_hi_fx);
+ pow_fx = extract_l(Pow2(14, temp_lo_fx)); /* Qpow */
+
+ /* Div part ( pow (2.0f, band_energy[i])/lagEenegy ) */
+ exp_normn = norm_s(pow_fx);
+ exp_normn = sub(exp_normn, 1);
+ exp_normd = norm_l(L_lagEnergy);
+ temp_fx = div_s(shl(pow_fx, exp_normn), extract_h(L_shl(L_lagEnergy, exp_normd)));
+ Qdiv = add(sub(add(Qpow, exp_normn), add(Qene, exp_normd)), 31);
+
+ exp_norm = norm_s(temp_fx);
+ temp_fx = shl(temp_fx, exp_norm);
+ Qdiv = add(Qdiv, exp_norm);
+
+ /* Sqrt part sqrt(pow (2.0f, band_energy[i])/lagEnergy) */
+ QlagGains[sb] = add(Qdiv, 16);
+ IF(s_and(Qdiv, 1) == 0) /* Qdiv % 2 == 0 */
+ {
+ L_temp = Sqrt_l(L_shr(L_deposit_h(temp_fx), 1), &exp_norm);
+ L_temp = L_shr(L_temp, exp_norm);
+ QlagGains[sb] = sub(shr(QlagGains[sb], 1), 1);
+ move16();
+ lagGains_fx[sb] = round_fx(L_temp);
+ }
+ ELSE
+ {
+ L_temp = Sqrt_l(L_deposit_h(temp_fx), &exp_norm);
+ L_temp = L_shr(L_temp, exp_norm);
+ QlagGains[sb] = shr(QlagGains[sb], 1);
+ move16();
+ lagGains_fx[sb] = round_fx(L_temp);
+ }
+ }
+ ELSE
+ {
+ /* lagGains[sb] = 0.0f; */
+ lagGains_fx[sb] = 0;
+ move16();
+ QlagGains[sb] = 15;
+ move16();
+ }
+ }
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * noise_extr_corcod()
+ * Spectrum normalization for the core coder
+ *--------------------------------------------------------------------------*/
+
+void noise_extr_corcod_fx(
+ Word32 L_spectra[], /* i : QsL core coder */
+ const Word32 L_spectra_ni[], /* i : QsL core coder with sparse filling */
+ Word16 sspectra_fx[], /* o : Qss Smoothed tonal information from core coder */
+ Word16 sspectra_diff_fx[], /* o : Qss non tonal infomration for gap filling */
+ Word16 sspectra_ni_fx[], /* o : Qss smoothed core coder */
+ const Word16 fLenLow_fx, /* i : Q0 low frequency bands width */
+ Word16 prev_hqswb_clas_fx, /* i : Q0 classification information */
+ Word16 *prev_ni_ratio_fx, /* i : Q15 noise parameter */
+ Word16 *Qss /* o : Q0 Q value for sspectra_*_fx */
+)
+{
+ Word16 i, pulse_num_fx;
+ Word32 L_spectra_diff[L_FRAME32k]; /* QsL */
+ Word16 Qss_s, Qss_d;
+ Word16 ni_ratio_fx, ni_ratio_cur_fx, br_adj_fx; /* Q15 */
+ Word16 tmp_fx;
+ Word16 exp_normn, exp_normd, exp_shift;
+ Word16 exp_norm;
+
+ /*Spectrum Smoothing for tonal signals*/
+ SpectrumSmoothing_nss_fx(L_spectra, sspectra_fx, &Qss_s, fLenLow_fx);
+ Copy(sspectra_fx, sspectra_ni_fx, fLenLow_fx);
+ tmp_fx = 0;
+ FOR(i = 0; i < fLenLow_fx; i++)
+ {
+ tmp_fx |= abs_s(sspectra_fx[i]);
+ logic16();
+ }
+ exp_norm = norm_s(tmp_fx);
+ FOR(i = 0; i < fLenLow_fx; i++)
+ {
+ sspectra_fx[i] = shl(sspectra_fx[i], exp_norm);
+ move16();
+ }
+ Qss_s = add(Qss_s, exp_norm);
+
+ /*noise extraction*/
+ FOR(i = 0; i < fLenLow_fx; i++)
+ {
+ L_spectra_diff[i] = L_sub(L_spectra_ni[i], L_spectra[i]);
+ move32();
+ }
+ SpectrumSmoothing_nss_fx(L_spectra_diff, sspectra_diff_fx, &Qss_d, fLenLow_fx);
+ tmp_fx = 0;
+ FOR(i = 0; i < fLenLow_fx; i++)
+ {
+ tmp_fx |= abs_s(sspectra_diff_fx[i]);
+ logic16();
+ }
+ exp_norm = norm_s(tmp_fx);
+ FOR(i = 0; i < fLenLow_fx; i++)
+ {
+ sspectra_diff_fx[i] = shl(sspectra_diff_fx[i], exp_norm);
+ move16();
+ }
+ Qss_d = add(Qss_d, exp_norm);
+
+ IF(LT_16(Qss_s, Qss_d))
+ {
+ *Qss = Qss_s;
+ move16();
+ exp_shift = sub(Qss_d, *Qss);
+ FOR(i = 0; i < fLenLow_fx; i++)
+ {
+ sspectra_diff_fx[i] = shr(sspectra_diff_fx[i], exp_shift);
+ move16();
+ }
+ }
+ ELSE
+ {
+ *Qss = Qss_d;
+ move16();
+ exp_shift = sub(Qss_s, *Qss);
+ FOR(i = 0; i < fLenLow_fx; i++)
+ {
+ sspectra_fx[i] = shr(sspectra_fx[i], exp_shift);
+ move16();
+ sspectra_ni_fx[i] = shr(sspectra_ni_fx[i], exp_shift);
+ move16();
+ }
+ }
+
+ /*Smoothing the noise components*/
+ br_adj_fx = 29491; /* br_adj = 0.9f; Q15 */
+
+ pulse_num_fx = 0;
+ move16();
+ FOR(i = 0; i < fLenLow_fx; i++)
+ {
+ if (L_spectra[i] != 0x0L)
+ {
+ pulse_num_fx = add(pulse_num_fx, 1);
+ }
+ }
+
+ ni_ratio_cur_fx = 0x0;
+ move16();
+ IF(pulse_num_fx != 0)
+ {
+ /*ni_ratio_cur = (fLenLow-pulse_num)/(fLenLow+0.0f);*/
+ tmp_fx = sub(fLenLow_fx, pulse_num_fx);
+ exp_normn = norm_s(tmp_fx);
+ exp_normn = sub(exp_normn, 1);
+ exp_normd = norm_s(fLenLow_fx);
+ ni_ratio_cur_fx = div_s(shl(tmp_fx, exp_normn), shl(fLenLow_fx, exp_normd)); /* exp_normn - exp_normd + 15 */
+ ni_ratio_cur_fx = shl(ni_ratio_cur_fx, sub(exp_normn, exp_normd)); /* 15 - (exp_normn - exp-normd + 15) */
+
+ /*ni_ratio_cur *= br_adj;*/
+ ni_ratio_cur_fx = mult_r(ni_ratio_cur_fx, br_adj_fx);
+ }
+
+ IF(EQ_16(prev_hqswb_clas_fx, HQ_HARMONIC))
+ {
+ IF(GT_16(ni_ratio_cur_fx, *prev_ni_ratio_fx))
+ {
+ /* 0.8: 26214(Q15) 0.2: 6554(Q15) */
+ ni_ratio_fx = mac_r(L_mult(ni_ratio_cur_fx, 26214), *prev_ni_ratio_fx, 6554);
+ }
+ ELSE
+ {
+ /* 0.6: 19661(Q15) 0.4: 13107(Q15) */
+ ni_ratio_fx = mac_r(L_mult(ni_ratio_cur_fx, 19661), *prev_ni_ratio_fx, 13107);
+ }
+ }
+ ELSE
+ {
+ /* 0.7: 22938(Q15) */
+ ni_ratio_fx = mult_r(ni_ratio_cur_fx, 22938);
+ }
+ *prev_ni_ratio_fx = ni_ratio_fx;
+ move16();
+
+ FOR(i = 0; i < fLenLow_fx; i++)
+ {
+ sspectra_diff_fx[i] = mult_r(sspectra_diff_fx[i], ni_ratio_fx);
+ move16();
+ sspectra_ni_fx[i] = add(sspectra_fx[i], sspectra_diff_fx[i]);
+ move16();
+ }
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * ton_ene_est()
+ * band energies for missing bands in the core coder
+ *--------------------------------------------------------------------------*/
+
+void ton_ene_est_fx(
+ Word32 L_xSynth_har[], /* i/o: QsL buffer with non tonal compoents */
+ const Word16 QsL, /* i : Q0 Q value for xSynth_har */
+ Word32 L_be_tonal[], /* o : QbeL tonal energy of the missing bands */
+ Word16 *QbeL, /* o : Q0 Q value for be_tonal */
+ const Word32 L_band_energy[], /* i : Qbe subband energies */
+ const Word16 Qbe, /* i : Q0 Q value for band_energy */
+ const Word16 band_start[], /* i : Q0 subband start indices */
+ const Word16 band_end[], /* i : Q0 subband end indices */
+ const Word16 band_width[], /* i : Q0 subband widths */
+ const Word16 fLenLow, /* i : Q0 low frequency width */
+ const Word16 fLenHigh, /* i : Q0 High frequency width */
+ const Word16 bands, /* i : Q0 total subbands */
+ const Word16 har_bands, /* i : Q0 total number of harmonics bands */
+ const Word16 ni_lvl_fx, /* i : Q11 noise enve for the hf bands */
+ GainItem_fx pk_sf_fx[], /* i : */
+ const Word16 Qss, /* i : Q0 Q value for GainItem_fx->nmrValue */
+ const Word16 *pul_res /* i : Q0 tonal resolution */
+)
+{
+ Word16 i, j, k;
+ Word16 exp_norm;
+ Word16 Inv_band_width_fx[BANDS_MAX];
+ Word16 QInvBW[BANDS_MAX];
+
+ Word16 xSynth_har_fx[L_FRAME32k];
+ Word16 QxSynth; /* Q value for xSynth_har_fx */
+ Word16 QxSynth_sft; /* Q value for xSynth_har_fx */
+
+ Word16 sb_ton_loc_fx[SWB_HAR_RAN1]; /* Q0 */
+ Word16 sb_ton_fx[SWB_HAR_RAN1]; /* Qss */
+ Word16 ni_gain_fx[NB_SWB_SUBBANDS];
+ Word16 Qni_gain;
+ Word16 avg_pe_fx[NB_SWB_SUBBANDS];
+ Word16 Qavg_pe[NB_SWB_SUBBANDS];
+ Word16 QsN; /* Q value for xSynth_har after multipy ni_lvl */
+ Word16 exp_safe; /* overflow prevent shift */
+
+ Word16 pos, count_pos_st, count_pos_end;
+ Word16 pul_res_bnd[NB_SWB_SUBBANDS];
+ Word16 peak_fx[NB_SWB_SUBBANDS]; /* Qss */
+
+ Word32 L_E;
+ Word16 QE;
+ Word16 temp_lo_fx, temp_hi_fx;
+ Word32 L_temp;
+ Word16 exp_pow;
+ Word32 L_band_energy_Linear[BANDS_MAX];
+
+ Word16 exp_normd, exp_normn;
+
+ Word16 E_r_fx;
+ Word16 QE_r; /* Q value for E_r_fx */
+
+ Word16 exp_shift;
+
+ Word16 E_r_shift_fx;
+ Word16 fac_fx;
+ Word16 Qtemp;
+ Word16 temp2_fx, Qtemp2;
+ Word16 temp_fx;
+
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+
+ *QbeL = 3;
+ move16();
+ Qni_gain = 8;
+ move16();
+
+ FOR(k = 0; k < bands; k++)
+ {
+ exp_norm = norm_s(band_width[k]);
+ exp_norm = sub(exp_norm, 1);
+ Inv_band_width_fx[k] = div_s(0x1fff, shl(band_width[k], exp_norm)); /* */
+ QInvBW[k] = sub(28, exp_norm); /* 13-exp_norm+15 */ move16();
+ }
+
+ set16_fx(sb_ton_loc_fx, -1, SWB_HAR_RAN1);
+ set16_fx(ni_gain_fx, 0, NB_SWB_SUBBANDS);
+ set16_fx(avg_pe_fx, 0, NB_SWB_SUBBANDS);
+ set16_fx(Qavg_pe, 0, NB_SWB_SUBBANDS);
+ set16_fx(sb_ton_fx, 0, NB_SWB_SUBBANDS);
+ set16_fx(peak_fx, 0, NB_SWB_SUBBANDS);
+ FOR(i = 0; i < fLenHigh; i++)
+ {
+ L_xSynth_har[i] = Mult_32_16(L_xSynth_har[i], ni_lvl_fx); /* QsL(=12)+11-15=8 */ move32();
+ }
+ QsN = sub(add(QsL, 11), 15);
+
+ exp_safe = 4; /*move16();*/
+ norm_vec_32_16_scale_fx(L_xSynth_har, QsN, fLenHigh, xSynth_har_fx, &QxSynth, exp_safe);
+
+ pos = 0;
+ move16();
+ i = sub(bands, har_bands);
+ FOR(k = 0; k < i; k++)
+ {
+ FOR(j = 0; j < pul_res[k]; j++)
+ {
+ sb_ton_loc_fx[pos] = pk_sf_fx[k * 8 + j].gainIndex_fx;
+ move16();
+ sb_ton_fx[pos] = pk_sf_fx[k * 8 + j].nmrValue_fx;
+ move16();
+ pos = add(pos, 1);
+ }
+ }
+ k = 0;
+ move16();
+ pos = 0;
+ move16();
+ DO
+ {
+ count_pos_st = pos;
+ WHILE(sb_ton_loc_fx[pos] <= (band_end[k + har_bands] - fLenLow) && sb_ton_loc_fx[pos] >= 0)
+ {
+ pos = add(pos, 1);
+ }
+ count_pos_end = pos;
+ move16();
+ pul_res_bnd[k] = sub(count_pos_end, count_pos_st);
+ move16();
+ if (pul_res_bnd[k] > 0)
+ {
+ peak_fx[k] = abs_s(sb_ton_fx[count_pos_st]);
+ move16();
+ }
+ k = add(k, 1);
+ } WHILE(LT_16(k, NB_SWB_SUBBANDS));
+
+ k = 0;
+ move16();
+ /*energy calculation for tonal components*/
+ FOR(i = har_bands; i < bands; i++)
+ {
+ L_E = sum2_fx(&xSynth_har_fx[sub(band_start[i], fLenLow)], band_width[i]);
+ QE = add(shl(QxSynth, 1), 1); /* QxSynth*2+1 */
+
+ /* E_r = (float) E/(float)pow(2.0f,band_energy[i]); -> E * pow(2.0f, -band_energy) */
+ /* Pow Part */
+ L_temp = L_shr(L_band_energy[i], sub(Qbe, 16));
+ temp_lo_fx = L_Extract_lc(L_temp, &temp_hi_fx);
+
+ exp_pow = sub(14, temp_hi_fx);
+ L_band_energy_Linear[i] = Pow2(14, temp_lo_fx);
+ move32(); /* Qexp_pow */
+ L_band_energy_Linear[i] = L_shl(L_band_energy_Linear[i], sub(*QbeL, exp_pow));
+
+ /* Div Part */
+ E_r_fx = 0x7fff;
+ move16();
+ QE_r = 0;
+ move16();
+ IF(L_band_energy_Linear[i] != 0x0L)
+ {
+ exp_normd = norm_l(L_E);
+ exp_normd = sub(exp_normd, 1);
+ exp_normn = norm_l(L_band_energy_Linear[i]);
+
+ E_r_fx = div_s(extract_h(L_shl(L_E, exp_normd)), extract_h(L_shl(L_band_energy_Linear[i], exp_normn)));
+ /* QE_r = (QE-16) - (QbeL+exp_normn-16) + 15; */
+ QE_r = add(sub(add(QE, exp_normd), add(*QbeL, exp_normn)), 15);
+ }
+
+ L_E = L_shl(L_E, sub(*QbeL, QE));
+ QE = *QbeL;
+
+ /* 0.06=15729(Q18) */
+ exp_shift = sub(18, QE_r);
+#ifdef BASOP_NOGLOB
+ E_r_shift_fx = shl_o(E_r_fx, exp_shift, &Overflow);
+#else
+ E_r_shift_fx = shl(E_r_fx, exp_shift);
+#endif
+ IF(LT_16(E_r_shift_fx, 15729)) /* E_r < 0.06 */
+ {
+ /* avg_pe[k] = (float) sqrt(pow(2.0f,band_energy[i])/band_width[i]); */
+ /* Pre SQRT part */
+ /*L_temp = Mpy_32_16_1(L_band_energy_Linear[i], Inv_band_width_fx[i]);*/ /* QbeL + QInvBW -15 */
+ L_temp = Mult_32_16(L_band_energy_Linear[i], Inv_band_width_fx[i]); /* QbeL + QInvBW -15 */
+ Qtemp = sub(add(*QbeL, QInvBW[i]), 15);
+
+ sqrt_32n_16_fx(L_temp, Qtemp, &avg_pe_fx[k], &Qavg_pe[k]);
+
+ fac_fx = 19661; /* 0.6(Q15) */
+ IF(pul_res_bnd[k] != 0)
+ {
+ /* Div Part */
+ L_temp = Mult_32_16(L_E, Inv_band_width_fx[i]); /* QE+exp_norm+QInvBW[i]+1 */
+ Qtemp = sub(add(QE, QInvBW[i]), 15);
+
+ /* SQRT Part */
+ sqrt_32n_16_fx(L_temp, Qtemp, &temp2_fx, &Qtemp2);
+
+ /* Div Part */
+ exp_normd = norm_s(temp2_fx);
+ exp_normd = sub(exp_normd, 1);
+ exp_normn = norm_s(peak_fx[k]);
+
+ fac_fx = div_s(shl(temp2_fx, exp_normd), shl(peak_fx[k], exp_normn));
+ fac_fx = shl(fac_fx, sub(add(Qss, exp_normn), add(Qtemp2, exp_normd))); /* Qtemp2+exp_normd-(Qss+exp_normn)+15 -> 15*/
+
+ }
+
+ ni_gain_fx[k] = mult_r(avg_pe_fx[k], fac_fx); /* Qavg_pe[k] */ move16();
+
+ L_temp = L_mult(ni_gain_fx[k], ni_gain_fx[k]);
+ L_temp = Mult_32_16(L_temp, E_r_fx);
+
+ /* 0.12f: 257698038 (Q31) */
+#ifdef BASOP_NOGLOB
+ if (GE_32(L_shl_o(L_temp, sub(31, add(add(shl(Qavg_pe[k], 1), QE_r), 1 - 15)), &Overflow), 257698038))
+#else
+ if (GE_32(L_shl(L_temp, sub(31, add(add(shl(Qavg_pe[k], 1), QE_r), 1 - 15))), 257698038))
+#endif
+ {
+ ni_gain_fx[k] = mult_r(1638, ni_gain_fx[k]); /* 0.05 : 1638(Q15) */ move16();
+ }
+ Overflow = 0;
+ move16();
+ ni_gain_fx[k] = shl(ni_gain_fx[k], sub(Qni_gain, Qavg_pe[k]));
+ assert(Qni_gain == 8); /* 358 is '(short)(1.4*pow(2,Qni_gain))' */
+ ni_gain_fx[k] = s_max(ni_gain_fx[k], 358); /* 1.4 -> 22938(Q14) */
+
+ exp_shift = QsL - (QxSynth + Qni_gain + 1); /* QsL - (QxSynth+Qni_gain+1) */
+ FOR(j = band_start[i]; j <= band_end[i]; j++)
+ {
+ L_xSynth_har[j - fLenLow] = L_shl(L_mult(xSynth_har_fx[j - fLenLow], ni_gain_fx[k]), exp_shift); /* QsL - (QxSynth+Qni_gain+1) */ move32();
+ }
+
+ exp_safe = 4; /* move16(); */
+ norm_vec_32_16_scale_fx(&L_xSynth_har[band_start[i] - fLenLow], QsL, band_width[i], &xSynth_har_fx[band_start[i] - fLenLow], &QxSynth_sft, exp_safe);
+
+ L_E = sum2_fx(&xSynth_har_fx[sub(band_start[i], fLenLow)], band_width[i]);
+ QE = add(shl(QxSynth_sft, 1), 1);
+
+ L_E = L_shl(L_E, sub(*QbeL, QE));
+ QE = *QbeL;
+ }
+ ELSE
+ {
+ /* Q8 -> Q12 */
+ FOR(j = band_start[i]; j <= band_end[i]; j++)
+ {
+ L_xSynth_har[j - fLenLow] = L_shl(L_xSynth_har[j - fLenLow], 4); /* Q8(12+11-15) -> Q12 */ move32();
+ }
+ }
+
+ k = add(k, 1);
+
+ L_be_tonal[i] = L_sub(L_band_energy_Linear[i], L_E);
+
+ IF(L_be_tonal[i] < 0x0L)
+ {
+ L_E = L_deposit_l(0);
+ FOR(j = (band_start[i] - fLenLow); j <= (band_end[i] - fLenLow); j++)
+ {
+ temp_fx = round_fx(L_shl(L_xSynth_har[j], (*QbeL + 7) / 2)); /* (12+x-16)*2+1 => QbeL */
+ L_xSynth_har[j] = L_shr(L_xSynth_har[j], 2); /* 1/4 */ move32();
+ L_E = L_mac(L_E, temp_fx, temp_fx);
+ }
+
+ L_E = L_shr(L_E, 4); /* 1/4 */
+ L_be_tonal[i] = L_sub(L_band_energy_Linear[i], L_E);
+ move32();
+ }
+ }
+
+ return;
+}
+
+
+/*--------------------------------------------------------------------------*
+ * Gettonl_scalfact()
+ * Gap filling for the core coder
+ *--------------------------------------------------------------------------*/
+void Gettonl_scalfact_fx
+(
+ Word32 *L_outBuf, /* i/o: QsL synthesized spectrum */
+ Word16 QsL, /* i : Q0 Q value for outBuf */
+ const Word32 *L_codbuf, /* i : QsL core coder */
+ const Word16 fLenLow, /* i : Q0 lowband length */
+ const Word16 fLenHigh, /* i : Q0 highband length */
+ const Word16 harmonic_band, /* i : Q0 total number of Low frequency bands */
+ const Word16 bands, /* i : Q0 total number of subbands in a frame */
+ Word32 *L_band_energy, /* i : Qbe band energy of each subband */
+ Word16 Qbe, /* i : Q0 Q value for band_energy */
+ const Word16 *band_start, /* i : Q0 subband start indices */
+ const Word16 *band_end, /* i : Q0 subband end indices */
+ const Word16 p2aflags[], /* i : Q0 missing bands in the core coder */
+ Word32 L_be_tonal[], /* i : QbeL tonal energy */
+ Word16 QbeL, /* i : Q0 Q value for be_tonal */
+ GainItem_fx *pk_sf_fx, /* i : toanl information for Sparse filling */
+ Word16 Qss, /* i : Q0 Q value for pk_sf.nmrValue */
+ Word16 *pul_res_pk /* i : Q0 pulse resolution information */
+)
+{
+ Word16 i, j, tmp;
+ Word16 sb_ton_fx[SWB_HAR_RAN1]; /* Qss */
+ Word16 sb_ton_loc_fx[SWB_HAR_RAN1]; /* Q0 */
+ Word32 L_est_ton_ene[NB_SWB_SUBBANDS]; /* QetEne */
+ Word16 QetEne;
+ Word16 band_sf_fx[SWB_HAR_RAN1]; /* Qton_sf */
+ Word16 pos_fx, k_fx, pos_tmp_fx; /* Q0 */
+ Word16 exp_safe;
+ Word16 temp_fx;
+ Word16 Qtemp;
+
+ Word16 band_pos_fx;
+ Word16 count_pos_st_fx, count_pos_end_fx;
+
+ Word16 exp_normd, exp_normn;
+
+ Word16 ton_sf_fx; /* Qton_sf */
+ Word16 Qton_sf;
+
+ Word16 step_fx; /* Q15 */
+ Word32 L_temp;
+
+ Word16 enrd_r_fx; /* Q15 */
+
+ Word32 L_band_energy_Linear[BANDS_MAX]; /* QbeL */
+ Word16 temp_hi_fx, temp_lo_fx;
+ Word16 exp_pow;
+ Word16 exp_shift;
+
+ Word16 Qbsf2[SWB_HAR_RAN1];
+
+ Qton_sf = sub(sub(QsL, Qss), 1);
+
+ enrd_r_fx = 29491;
+ move16(); /* 0.9: 29491.2(Q15) */
+
+ set32_fx(L_est_ton_ene, 0x0L, NB_SWB_SUBBANDS);
+ set16_fx(sb_ton_loc_fx, -1, SWB_HAR_RAN1);
+
+ /* Get the tonal information for sparse filling */
+ pos_fx = 0;
+ move16();
+ FOR(k_fx = 0; k_fx < sub(bands, harmonic_band); k_fx++)
+ {
+ FOR(j = 0; j < pul_res_pk[k_fx]; j++)
+ {
+ sb_ton_loc_fx[pos_fx] = pk_sf_fx[k_fx * 8 + j].gainIndex_fx;
+ move16();
+ sb_ton_fx[pos_fx] = pk_sf_fx[k_fx * 8 + j].nmrValue_fx;
+ move16();
+ pos_fx = add(pos_fx, 1);
+ }
+ }
+ k_fx = 0;
+ move16();
+ pos_fx = 0;
+ move16();
+ pos_tmp_fx = 0;
+ move16();
+
+ DO
+ {
+ band_pos_fx = add(k_fx, harmonic_band);
+ count_pos_st_fx = pos_fx;
+ move16();
+ WHILE(LE_16(sb_ton_loc_fx[pos_fx], sub(band_end[band_pos_fx], fLenLow)) && sb_ton_loc_fx[pos_fx] >= 0)
+ {
+ test();
+ pos_fx = add(pos_fx, 1);
+ }
+ count_pos_end_fx = pos_fx;
+ move16();
+
+ exp_safe = 2; /* move16(); */
+ QetEne = add(shl(sub(Qss, exp_safe), 1), 1);
+ L_temp = L_add(L_est_ton_ene[k_fx], 0);
+ FOR(i = count_pos_st_fx; i < count_pos_end_fx; i++)
+ {
+ temp_fx = shr(sb_ton_fx[i], exp_safe);
+ L_temp = L_mac(L_temp, temp_fx, temp_fx);
+ }
+ L_est_ton_ene[k_fx] = L_temp;
+ move32();
+
+ IF(L_est_ton_ene[k_fx] <= 0x0L)
+ {
+ /* 1.0 */
+ L_est_ton_ene[k_fx] = L_deposit_l(32767);
+ QetEne = 15;
+ }
+
+ /*ton_sf= (float) sqrt(be_tonal[band_pos]/est_ton_ene[k]);*/ /* be_tonal: QbeL, est_ton_ene: (Qss-exp_safe)*2+1 */
+ /* Div Part */
+ exp_normd = norm_l(L_be_tonal[band_pos_fx]);
+ exp_normd = sub(exp_normd, 1);
+ exp_normn = norm_l(L_est_ton_ene[k_fx]);
+
+ ton_sf_fx = 0x0;
+ move16();
+ IF(L_be_tonal[band_pos_fx] > 0x0L)
+ {
+ ton_sf_fx = div_l(L_shl(L_be_tonal[band_pos_fx], exp_normd), extract_h(L_shl(L_est_ton_ene[k_fx], exp_normn))); /* QbeL+exp_normd - (QetEne+exp_normn-16) - 1 */
+ }
+
+ /* Sqrt Part */
+ /*sqrt_32n_16_fx(L_deposit_h(ton_sf_fx), (QbeL+exp_normd)-(QetEne+exp_normn-16)-1+16, &ton_sf_fx, &Qton_sf);*/
+ sqrt_32n_16_fx(L_deposit_h(ton_sf_fx), add(sub(add(QbeL, exp_normd), add(QetEne, exp_normn)), 31), &ton_sf_fx, &Qton_sf);
+
+ FOR(i = count_pos_st_fx; i < count_pos_end_fx; i++)
+ {
+ band_sf_fx[pos_tmp_fx] = ton_sf_fx;
+ move16();
+ Qbsf2[pos_tmp_fx] = Qton_sf;
+ move16();
+ pos_tmp_fx = add(pos_tmp_fx, 1);
+ }
+ k_fx = add(k_fx, 1);
+ } WHILE(LT_16(k_fx, NB_SWB_SUBBANDS));
+
+ /* Gap filling for the core coder */
+ /* 0.077=20185(Q18) */
+ L_temp = L_mult(20185, fLenHigh); /* 18+0+1= 19 */
+ exp_normn = norm_l(L_temp);
+
+ step_fx = div_s(0x3fff, extract_h(L_shl(L_temp, exp_normn)));
+ step_fx = shl(step_fx, sub(exp_normn, 11)); /* 15 - (14-(19+exp_normn-16)+15) */ /* Q15 */
+
+ pos_tmp_fx = 0;
+ move16();
+ tmp = sub(bands, harmonic_band);
+ FOR(k_fx = 0; k_fx < tmp; k_fx++)
+ {
+ band_pos_fx = add(k_fx, harmonic_band);
+
+ IF(L_be_tonal[band_pos_fx] > 0x0L)
+ {
+ /* enrd_r *=(float)sqrt(be_tonal[band_pos]/pow(2.0f,band_energy[band_pos])); */
+ /* Pow Part */
+ L_temp = L_shr(L_band_energy[band_pos_fx], sub(Qbe, 16));
+ temp_lo_fx = L_Extract_lc(L_temp, &temp_hi_fx);
+ exp_pow = sub(14, temp_hi_fx);
+ L_band_energy_Linear[band_pos_fx] = Pow2(14, temp_lo_fx);
+ move32(); /* Qexp_pow */
+ L_band_energy_Linear[band_pos_fx] = L_shl(L_band_energy_Linear[band_pos_fx], sub(QbeL, exp_pow));
+
+ /* Div Part */
+ exp_normd = norm_l(L_be_tonal[band_pos_fx]);
+ exp_normd = sub(exp_normd, 1);
+ exp_normn = norm_l(L_band_energy_Linear[band_pos_fx]);
+ temp_fx = div_l(L_shl(L_be_tonal[band_pos_fx], exp_normd), extract_h(L_shl(L_band_energy_Linear[band_pos_fx], exp_normn))); /* QbeL+exp_normd-(QbeL+exp_normn-16)-1 */
+ sqrt_32n_16_fx(L_deposit_h(temp_fx), add(sub(exp_normd, exp_normn), 31), &temp_fx, &Qtemp);
+ enrd_r_fx = extract_h(L_shl(L_mult(enrd_r_fx, temp_fx), sub(15, Qtemp)));
+
+ enrd_r_fx = sub(enrd_r_fx, step_fx);
+ }
+ ELSE
+ {
+ enrd_r_fx = 0x0;
+ move16();
+ }
+
+ IF(EQ_16(p2aflags[band_pos_fx], 1))
+ {
+ FOR(i = band_start[band_pos_fx]; i <= band_end[band_pos_fx]; i++)
+ {
+ L_outBuf[i - fLenLow] = L_codbuf[i];
+ move32();
+ }
+ }
+ ELSE
+ {
+ pos_fx = 0;
+ move16();
+ pos_fx = add(pos_fx, pos_tmp_fx);
+ exp_shift = sub(sub(QsL, Qss), 1);
+ FOR(j = 0; j < pul_res_pk[k_fx]; j++)
+ {
+ /*outBuf[pk_sf[k*8+j].gainIndex] = pk_sf[k*8+j].nmrValue*band_sf[pos]*enrd_r;*/
+ /* outBuf:QsL , pk_sf.nmrValue:Qss, band_sf:Qbsf2(Qton_sf), enrd_r:Q15 */
+ L_outBuf[pk_sf_fx[k_fx * 8 + j].gainIndex_fx] = L_shl(Mult_32_16(L_mult(band_sf_fx[pos_fx], enrd_r_fx), pk_sf_fx[k_fx * 8 + j].nmrValue_fx), sub(exp_shift ,Qbsf2[pos_fx]));
+ move32(); /* QsL - (Qbsf2[pos_fx]+Qss+16-15) */
+
+ pos_fx = add(pos_fx, 1);
+ }
+ }
+ pos_tmp_fx = add(pos_tmp_fx, pul_res_pk[k_fx]);
+
+ }
+
+ return;
+}
+
+
+
+/*-------------------------------------------------------------------*
+ * sqrt_32n_16_fx()
+ *
+ * Routine for Sqrt
+ *-------------------------------------------------------------------*/
+void sqrt_32n_16_fx(
+ Word32 L_in, /* i : input vector (Word32) */
+ Word16 Qin, /* i : Q value for L_in */
+ Word16 *out_fx, /* o : sqrt input vector (Word16) */
+ Word16 *Qout /* o : Q value for out_fx */
+)
+{
+ Word16 exp_norm;
+ Word32 L_in_t;
+ Word16 Qin_t;
+
+ /* Input Normalization */
+ exp_norm = norm_l(L_in);
+ L_in_t = L_shl(L_in, exp_norm);
+ Qin_t = add(Qin, exp_norm);
+
+ /* SQRT part */
+ IF(s_and(Qin_t, 1) == 0)
+ {
+ L_in_t = Sqrt_l(L_shr(L_in_t, 1), &exp_norm);
+ L_in_t = L_shr(L_in_t, exp_norm);
+ *Qout = sub(shr(Qin_t, 1), 1);
+ }
+ ELSE
+ {
+ L_in_t = Sqrt_l(L_in_t, &exp_norm);
+ L_in_t = L_shr(L_in_t, exp_norm);
+ *Qout = shr(Qin_t, 1);
+ }
+ *out_fx = round_fx(L_in_t);
+}
+
+/*-------------------------------------------------------------------*
+ * norm_vec_32_16_scale_fx()
+ *
+ * Routine for normilization and convert Word32 to Word16
+ *-------------------------------------------------------------------*/
+void norm_vec_32_16_scale_fx(
+ Word32 *L_vec_in, /* i : input vector */
+ Word16 Qin, /* i : Q value for input vector */
+ Word16 length_fx, /* i :vector size */
+ Word16 *vec_out_fx, /* o : output vectror */
+ Word16 *Qout, /* o : Q value for output vectro */
+ Word16 exp_safe /* i : suppress left shift: for prevend overflow on sum */
+)
+{
+ Word16 i;
+ Word32 L_temp;
+ Word16 exp_norm, exp_shift;
+
+ L_temp = L_deposit_l(0);
+ FOR(i = 0; i < length_fx; i++)
+ {
+ L_temp = L_or(L_temp, L_abs(L_vec_in[i]));
+ }
+ exp_norm = norm_l(L_temp);
+
+ exp_shift = sub(exp_norm, exp_safe);
+ *Qout = sub(add(Qin, exp_shift), 16);
+ FOR(i = 0; i < length_fx; i++)
+ {
+ vec_out_fx[i] = round_fx(L_shl(L_vec_in[i], exp_shift));
+ }
+}
+
+void get_sigma_fx_har(
+ const Word32 L_x_abs[], /* i: Qi absolute input */
+ const Word16 Qi, /* i: Q0 Q value of x_abs */
+ const Word16 avg_fx, /* i: Qavg average of x_abs */
+ const Word16 Qavg, /* i: Q0 Q value of avg */
+ const Word16 length_fx, /* i: Q0 length */
+ Word16 *sigma_fx, /* o: Qsigma sigma */
+ Word16 *Qsigma /* o: Q0 Q value of sigma */
+)
+{
+ Word16 i;
+ Word32 L_d;
+ Word16 d_fx;
+
+ Word16 length1_fx;
+ Word16 exp_normd;
+ Word16 exp_normn;
+ Word16 exp_shift;
+
+ Word16 exp_norm;
+
+ Word32 L_temp;
+
+ Word16 temp_fx;
+
+ Word32 L_tmp;
+ Word32 L_x_abs_sh[L_FRAME32k];
+ Word16 Qd;
+
+ Word16 exp_safe;
+
+ exp_safe = 4;
+ move16(); /* max 103 < 2^7 -> 4+4=8 */
+
+ L_tmp = L_deposit_l(0);
+ FOR(i = 0; i < length_fx; i++)
+ {
+ L_tmp = L_or(L_tmp, L_x_abs[i]);
+ }
+ exp_norm = norm_l(L_tmp);
+ exp_norm = sub(exp_norm, exp_safe);
+ FOR(i = 0; i < length_fx; i++)
+ {
+ L_x_abs_sh[i] = L_shl(L_x_abs[i], exp_norm);
+ }
+
+ L_d = L_deposit_l(0);
+ FOR(i = 0; i < length_fx; i++)
+ {
+ temp_fx = extract_h(L_x_abs_sh[i]);
+ L_d = L_mac(L_d, temp_fx, temp_fx); /* (Qi+exp_norm-16)*2+1 */
+ }
+ Qd = add(shl(sub(add(Qi, exp_norm), 16), 1), 1);
+ IF(L_d == 0x0L)
+ {
+ *sigma_fx = 0;
+ move16();
+ *Qsigma = 15;
+ move16();
+ return;
+ }
+
+ /* d /= (length-1); */
+ length1_fx = sub(length_fx, 1);
+
+ /* d /= (length-1); */
+ exp_normn = norm_l(L_d);
+ exp_normn = sub(exp_normn, 1);
+ exp_normd = norm_s(length1_fx);
+
+ exp_shift = sub(sub(exp_normn, exp_normd), 1);
+ d_fx = div_l(L_shl(L_d, exp_normn), shl(length1_fx, exp_normd)); /* Qabs*2+1+exp_normn - exp_normd - 1 */
+ L_d = L_shr(L_deposit_l(d_fx), exp_shift); /* Qabs*2+1 + 16 */
+ /* Qd = ((Qd+exp_normn) - exp_normd-exp_shift -1); */
+ Qd = sub(sub(add(Qd, exp_normn), add(exp_normd, exp_shift)), 1);
+
+ /* d -= avg*avg; */
+ IF(avg_fx != 0x0)
+ {
+ L_tmp = L_mult(avg_fx, avg_fx); /* Qavg*2+1 */
+ L_tmp = L_shr(L_tmp, sub(add(shl(Qavg, 1), 1), Qd));
+ L_d = L_sub(L_d, L_tmp);
+ }
+
+ exp_norm = norm_l(L_d);
+ L_d = L_shl(L_d, exp_norm);
+ Qd = add(Qd, exp_norm);
+
+ /* sigma = (float)sqrt(d); */
+ IF(s_and(Qd, 1) == 0)/* Qd % 2 == 0 */
+ {
+ L_temp = Sqrt_l(L_shr(L_d, 1), &exp_norm);
+ L_temp = L_shr(L_temp, exp_norm);
+ *Qsigma = sub(shr(Qd, 1), 1);
+ *sigma_fx = round_fx(L_temp);
+ }
+ ELSE
+ {
+ L_temp = Sqrt_l(L_d, &exp_norm);
+ L_temp = L_shr(L_temp, exp_norm);
+ *Qsigma = shr(Qd, 1);
+ *sigma_fx = round_fx(L_temp);
+ }
+
+ return;
+}
+
+void FindNBiggest2_simple_fx_har(
+ const Word32 *L_inBuf, /* i : input buffer (searched) */
+ const Word16 Qabs_in, /* i : Q value of input buffer */
+ GainItem_fx *pk_sf_fx, /* o : N biggest components found */
+ const Word16 nIdx_fx, /* i : search length */
+ Word16 *n_fx, /* i : number of components searched (N biggest) */
+ Word16 n_nbiggestsearch /* i : */
+)
+{
+ Word16 j;
+ Word32 L_avg_in;
+ Word32 L_abs_in[400];
+ Word32 L_abs_in_sft[400];
+ Word16 avg_in_fx;
+ Word32 L_max_in;
+ Word16 Qavg_in;
+
+ Word16 exp_normd;
+ Word16 exp_normn;
+
+ Word16 temp_fx;
+
+ Word16 sigma_fx;
+ Word16 Qsigma;
+
+ Word16 peak_cnt_fx;
+ Word32 L_thr;
+ Word32 L_temp;
+
+ L_max_in = L_deposit_l(0);
+ L_avg_in = L_deposit_l(0);
+
+ FOR(j = 0; j < nIdx_fx; j++)
+ {
+ L_abs_in[j] = L_abs(L_inBuf[j]); /* Qabs_in */
+ L_abs_in_sft[j] = L_shr(L_abs_in[j], 8); /* 8 is safe shift */
+
+ if (LT_32(L_max_in, L_abs_in_sft[j]))
+ {
+ L_max_in = L_abs_in_sft[j];
+ move32();
+ }
+
+ L_avg_in = L_add(L_avg_in, L_abs_in_sft[j]);
+ }
+
+ /*avg_in /= (float)nIdx;*/
+ avg_in_fx = 0;
+ move16();
+ Qavg_in = 15;
+ move16();
+ IF(L_avg_in != 0)
+ {
+ exp_normn = norm_l(L_avg_in);
+ exp_normn = sub(exp_normn, 1);
+ L_avg_in = L_shl(L_avg_in, exp_normn);
+ exp_normd = norm_s(nIdx_fx);
+ temp_fx = shl(nIdx_fx, exp_normd);
+ avg_in_fx = div_l(L_avg_in, temp_fx);
+ Qavg_in = sub(add(sub(Qabs_in, 8), exp_normn), add(exp_normd, 1));
+ }
+
+ peak_cnt_fx = 0;
+ move16();
+ IF(LE_32(L_max_in, 0x1))
+ {
+ FOR(j = 0; j < n_nbiggestsearch; j++)
+ {
+ pk_sf_fx[peak_cnt_fx].nmrValue_fx = 0x0;
+ move16();
+ pk_sf_fx[peak_cnt_fx].gainIndex_fx = j;
+ move16();
+ peak_cnt_fx = add(peak_cnt_fx, 1);
+ }
+ }
+
+ get_sigma_fx_har(L_abs_in, Qabs_in, avg_in_fx, Qavg_in, nIdx_fx, &sigma_fx, &Qsigma);
+
+ temp_fx = mult_r(sigma_fx, 18841); /* 18841 = 1.15(Q14) Qsigma + Q14 + 1 */
+ L_thr = L_add(extract_l(avg_in_fx), L_shr(extract_l(temp_fx), sub(sub(Qsigma, 1), Qavg_in)));
+ L_thr = L_shr(L_thr, sub(Qavg_in, Qabs_in));
+
+ IF(LT_16(peak_cnt_fx, n_nbiggestsearch))
+ {
+ FOR(j = 0; j < nIdx_fx; j++)
+ {
+ IF(GT_32(L_abs_in[j], L_thr))
+ {
+ pk_sf_fx[peak_cnt_fx].nmrValue_fx = round_fx(L_abs_in[j]); /* Qabs_in-16 */
+ pk_sf_fx[peak_cnt_fx].gainIndex_fx = j;
+ move16();
+ L_abs_in[j] = L_deposit_l(0);
+ peak_cnt_fx = add(peak_cnt_fx, 1);
+ move16();
+ }
+
+ IF(EQ_16(peak_cnt_fx, n_nbiggestsearch))
+ {
+ BREAK;
+ }
+ }
+ }
+
+ /* thr *= (0.3f / n_nbiggestsearch) * peak_cnt + 0.7f; */
+ /* 0.3=19661(Q16) */
+ temp_fx = div_s_ss(19661, n_nbiggestsearch);
+ L_temp = L_mult(temp_fx, peak_cnt_fx); /* 16+0+1 */
+ temp_fx = add(round_fx(L_shl(L_temp, 14)), 22938); /* shift: 17+14-16 -> 15 */ /* 0.7(22937.6:Q15)*/
+ L_thr = Mult_32_16(L_thr, temp_fx);
+
+ IF(LT_16(peak_cnt_fx, n_nbiggestsearch))
+ {
+ FOR(j = 0; j < nIdx_fx; j++)
+ {
+ IF(GT_32(L_abs_in[j], L_thr))
+ {
+ pk_sf_fx[peak_cnt_fx].nmrValue_fx = round_fx(L_abs_in[j]); /* Qabs_in-16 */
+ pk_sf_fx[peak_cnt_fx].gainIndex_fx = j;
+ move16();
+ L_abs_in[j] = L_deposit_l(0);
+ peak_cnt_fx = add(peak_cnt_fx, 1);
+ move16();
+ }
+
+ IF(EQ_16(peak_cnt_fx, n_nbiggestsearch))
+ {
+ BREAK;
+ }
+ }
+ }
+
+ /* thr *= (0.6f / n_nbiggestsearch) * peak_cnt + 0.3f; */
+ /* 0.6=19661(Q15) */
+ temp_fx = div_s_ss(19661, n_nbiggestsearch);
+ L_temp = L_mult(temp_fx, peak_cnt_fx); /* 15+0+1 */
+ temp_fx = add(round_fx(L_shl(L_temp, 15)), 9830); /* shift: 16+15-16 -> 15 */ /* 0.3(9830.4:Q15)*/
+
+ L_thr = Mult_32_16(L_thr, temp_fx);
+ IF(LT_16(peak_cnt_fx, n_nbiggestsearch))
+ {
+ FOR(j = 0; j < nIdx_fx; j++)
+ {
+ IF(GT_32(L_abs_in[j], L_thr))
+ {
+ pk_sf_fx[peak_cnt_fx].nmrValue_fx = round_fx(L_abs_in[j]); /* Qabs_in-16 */
+ pk_sf_fx[peak_cnt_fx].gainIndex_fx = j;
+ move16();
+ L_abs_in[j] = L_deposit_l(0);
+ peak_cnt_fx = add(peak_cnt_fx, 1);
+ move16();
+ }
+
+ IF(EQ_16(peak_cnt_fx, n_nbiggestsearch))
+ {
+ BREAK;
+ }
+ }
+ }
+
+ *n_fx = peak_cnt_fx;
+ move16();
+}
+
+/*--------------------------------------------------------------------------*
+ * spectrumsmooth_noiseton()
+ * Spectrum normalization for the the core coder
+ *--------------------------------------------------------------------------*/
+Word16 spectrumsmooth_noiseton_fx( /* o : Qss ss_min */
+ Word32 L_spectra[], /* i : Qs core coder */
+ /*Word16 Qs,*/ /* i : Q0 Q value for spectra, spectra_ni */
+ const Word32 L_spectra_ni[], /* i : Qs core coder with sparse filling */
+ Word16 sspectra_fx[], /* o : Qss Smoothed tonal information from core coder */
+ Word16 sspectra_diff_fx[], /* o : Qss non tonal infomration for gap filling */
+ Word16 sspectra_ni_fx[], /* o : Qss smoothed core coder */
+ Word16 *Qss, /* o : Q0 Q value for sspectra* */
+ const Word16 fLenLow_fx, /* i : Q0 low frequency boundaries */
+ Word16 *ni_seed_fx /* io : Q0 random seed */
+)
+{
+ Word16 i;
+ Word32 L_spectra_diff[L_FRAME32k];
+ Word16 ni_ratio_fx; /* Q15 */
+ Word16 ss_min_fx; /* Q10 */
+ Word16 cut_sig_th_fx; /* Q10 */
+ Word16 cut_ni_th_fx; /* Q10 */
+ Word16 pcnt_fx, sign_fx;
+ Word16 exp_normn, exp_normd;
+
+ Word16 ratio_fx;
+ Word32 L_temp;
+ Word32 L_spectra_rm[L_FRAME32k];
+ Word32 L_cut_input = 410;
+ Word16 rand_a_fx[L_FRAME32k];
+
+
+ /* pre-prepare random array for float-fix interoperability */
+ FOR(i = 0; i < fLenLow_fx; i++)
+ {
+ rand_a_fx[i] = Random(ni_seed_fx);
+ }
+
+
+ /*Get the pulse resolution for the core coder*/
+ pcnt_fx = 0;
+ move16();
+ FOR(i = 0; i < fLenLow_fx; i++)
+ {
+ if (L_spectra[i] != 0x0L)
+ {
+ pcnt_fx = add(pcnt_fx, 1);
+ }
+ }
+
+ /*ni_ratio = 4.0f*(pcnt)/(fLenLow+0.0f);*/
+ exp_normn = norm_s(pcnt_fx);
+ exp_normn = sub(exp_normn, 1);
+ exp_normd = norm_s(fLenLow_fx);
+
+ ni_ratio_fx = div_s(shl(pcnt_fx, exp_normn), shl(fLenLow_fx, exp_normd)); /* exp_normn - exp_normd + 15 - 2 */
+
+ ni_ratio_fx = shl(ni_ratio_fx, add(sub(exp_normd, exp_normn), 2)); /* 15 - (exp_normn-exp_normd+15-2) */
+
+ /*ni_ratio = min(0.9f, ni_ratio);*/
+ ni_ratio_fx = s_min(29491, ni_ratio_fx); /* 0.9: 29491(Q15) */
+
+ move16();
+
+ ss_min_fx = mult_r(ni_ratio_fx, 10240); /* Q15+Q10-15 = Q10 */ /* 10.0: 10240(Q10) */
+ cut_sig_th_fx = shr(ss_min_fx, 2); /* 1/4 */
+ cut_sig_th_fx = s_max(973, cut_sig_th_fx); /* 0.95: 972.8(Q10) */
+
+ /*core coder normalization for gap filling*/
+ FOR(i = 0; i < fLenLow_fx; i++)
+ {
+ L_spectra_rm[i] = L_deposit_l(0);
+ if (GE_32(L_abs(L_spectra[i]), L_cut_input))
+ {
+ L_spectra_rm[i] = L_spectra[i];
+ move32();
+ }
+ }
+ SpectrumSmoothing_fx(L_spectra_rm, sspectra_fx, Qss, fLenLow_fx, cut_sig_th_fx);
+
+ /*Extract noise informaton from the core coder*/
+ Copy(sspectra_fx, sspectra_ni_fx, fLenLow_fx);
+ FOR(i = 0; i < fLenLow_fx; i++)
+ {
+ L_spectra_diff[i] = L_sub(L_spectra_ni[i], L_spectra[i]);
+ move32();
+ }
+ cut_ni_th_fx = 0x0;
+ move16();
+ /*normalize sparse filled components*/
+ FOR(i = 0; i < fLenLow_fx; i++)
+ {
+ L_spectra_rm[i] = L_deposit_l(0);
+ if (GE_32(L_abs(L_spectra_diff[i]), L_cut_input))
+ {
+ L_spectra_rm[i] = L_spectra_diff[i];
+ move32();
+ }
+ }
+ SpectrumSmoothing_fx(L_spectra_rm, sspectra_diff_fx, Qss, fLenLow_fx, cut_ni_th_fx);
+
+ /*Normalized corecoder for Gap filling */
+ /* ratio = 1 - ss_min/10.0 */
+ ratio_fx = sub(0x7fff, shl(mult_r(ss_min_fx, 3277), 15 - 10)); /* Q15 */
+ FOR(i = 0; i < fLenLow_fx; i++)
+ {
+ sign_fx = 0;
+ move16();
+ if (sspectra_fx[i] < 0)
+ {
+ sign_fx = 1;
+ move16();
+ }
+ IF(GT_16(abs_s(sspectra_fx[i]), ss_min_fx))
+ {
+ /*sspectra[i] = sign*((10-ss_min)/10.0f*(float)fabs(sspectra[i])+ss_min);*/
+ sspectra_fx[i] = add(mult_r(ratio_fx, abs_s(sspectra_fx[i])), ss_min_fx);
+ IF(sign_fx != 0)
+ {
+ sspectra_fx[i] = negate(sspectra_fx[i]);
+ move16();
+ }
+ }
+ IF(sspectra_fx[i] != 0x0)
+ {
+ sspectra_ni_fx[i] = sspectra_fx[i];
+ move16();
+ }
+ ELSE
+ {
+ sspectra_ni_fx[i] = mult_r(sspectra_diff_fx[i], ni_ratio_fx);
+ move16();
+ }
+
+ IF(sspectra_ni_fx[i] == 0x0)
+ {
+ /*sspectra_ni[i] = 0.5f*10.0f*ni_ratio* own_random(ni_seed)/32768.0f;*/
+ L_temp = L_mult(ni_ratio_fx, 20480); /* ni_ratio*5 */
+ L_temp = Mult_32_16(L_temp, rand_a_fx[i]); /* Q28 */
+ sspectra_ni_fx[i] = round_fx(L_shr(L_temp, 2)); /* Qss */
+ }
+ }
+
+ return(ss_min_fx);
+}
+
+/*--------------------------------------------------------------------------*
+ * noiseinj_hf()
+ * level adjustments for the missing bands in the core coder
+ *--------------------------------------------------------------------------*/
+void noiseinj_hf_fx(
+ Word32 L_xSynth_har[], /* i/o : Qs gap filled information */
+ Word16 Qs, /* i : Q0 Q value for xSynth_har */
+ Word32 L_th_g[], /* i : Qs level adjustment information */
+ Word32 L_band_energy[], /* i : Qbe subband energies */
+ Word16 Qbe, /* i : Q0 Q value for band_energy */
+ Word16 *prev_En_sb_fx, /* i/o : QsEn smoothed sqrt band Energies */
+ const Word16 p2a_flags_fx[], /* i : Q0 Missing bands in the core coder */
+ const Word16 BANDS_fx, /* i : Q0 total bands */
+ const Word16 band_start_fx[], /* i : Q0 band start indices */
+ const Word16 band_end_fx[], /* i : Q0 band end indices */
+ const Word16 fLenLow_fx, /* i : Q0 low frequency bandwidth */
+ const Word16 fLenHigh_fx /* i : Q0 SWB frequency bandwidth */
+)
+{
+ Word16 k, i;
+
+ Word16 *p_prev_En_sb_fx;
+ Word16 QbeL = 7; /* Don't need 3, because this E only use under th samples */ /* QsEn=3 */
+
+ Word16 map_pulse_t_fx[L_FRAME32k];
+ Word16 map_pulse_fx[L_FRAME32k];
+
+ Word16 QsEn = 4; /* kiken */
+ Word32 L_En[NB_SWB_SUBBANDS];
+ Word32 *p_L_En;
+ Word16 QE;
+ Word16 sqrt_En_fx[NB_SWB_SUBBANDS]; /* QsEn */
+ Word16 *p_sqrt_En_fx; /* QsEn */
+
+ Word16 Enn_sm_sb_fx[NB_SWB_SUBBANDS];
+ Word16 *p_Enn_sm_sb_fx;
+
+ Word16 exp_safe;
+ Word16 xSynth_har_fx[L_FRAME32k];
+ Word16 QxSynth;
+
+ Word16 Qtemp;
+
+ Word16 ni_scale_fx; /* Q14 */
+
+ Word16 temp_fx;
+ Word32 L_temp;
+
+ Word16 exp_normn, exp_normd;
+ Word16 div_fx;
+ Word16 Qdiv;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+ set16_fx(map_pulse_t_fx, 0, band_end_fx[BANDS_fx - 1] + 1);
+ set16_fx(map_pulse_fx, 0, band_end_fx[BANDS_fx - 1] + 1);
+
+ /*level adjust the missing bands in the core coder */
+ exp_safe = 4; /*move16();*/
+ norm_vec_32_16_scale_fx(L_xSynth_har, Qs, fLenHigh_fx, xSynth_har_fx, &QxSynth, exp_safe);
+ QE = add(shl(QxSynth, 1), 1);
+
+ p_L_En = L_En;
+ p_sqrt_En_fx = sqrt_En_fx;
+ FOR(k = sub(BANDS_fx, NB_SWB_SUBBANDS); k < BANDS_fx; k++)
+ {
+ *p_L_En = L_deposit_l(0);
+ IF(p2a_flags_fx[k] == 0)
+ {
+ FOR(i = band_start_fx[k]; i <= band_end_fx[k]; i++)
+ {
+ IF(LE_32(L_abs(L_xSynth_har[i - fLenLow_fx]), L_th_g[k - (BANDS_fx - NB_SWB_SUBBANDS)]))
+ {
+ *p_L_En = L_mac(*p_L_En, xSynth_har_fx[i - fLenLow_fx], xSynth_har_fx[i - fLenLow_fx]);
+ }
+ ELSE
+ {
+ map_pulse_t_fx[i] = 1;
+ move16();
+ }
+ }
+ *p_L_En = L_shl(*p_L_En, sub(QbeL, QE));
+ move32();
+ /**p_L_En = (float)sqrt(*p_En);*/
+ sqrt_32n_16_fx(*p_L_En, QbeL, p_sqrt_En_fx, &Qtemp);
+#ifdef BASOP_NOGLOB
+ *p_sqrt_En_fx = shl_o(*p_sqrt_En_fx, sub(QsEn, Qtemp), &Overflow); /* -> Q2 */ move16();
+#else
+ *p_sqrt_En_fx = shl(*p_sqrt_En_fx, sub(QsEn, Qtemp)); /* -> Q2 */ move16();
+#endif
+ }
+ p_L_En++;
+ p_sqrt_En_fx++;
+ }
+
+ p_sqrt_En_fx = sqrt_En_fx;
+ p_Enn_sm_sb_fx = Enn_sm_sb_fx;
+ p_prev_En_sb_fx = prev_En_sb_fx;
+ FOR(k = BANDS_fx - NB_SWB_SUBBANDS; k < BANDS_fx; k++)
+ {
+ *p_Enn_sm_sb_fx = prev_En_sb_fx[k - (BANDS_fx - NB_SWB_SUBBANDS)];
+ move16(); /* QsEn */
+ IF(p2a_flags_fx[k] == 0)
+ {
+ L_temp = Mult_32_16(L_band_energy[k], 26214); /* 0.8: 26214(Q15) */
+ temp_fx = round_fx(L_shl(L_temp, sub(QsEn, sub(Qbe, 16))));
+ IF(LT_16(*p_prev_En_sb_fx, temp_fx))
+ {
+ /**p_Enn_sm_sb = (0.15f*(*p_En)) + (0.85f*prev_En_sb[k-(BANDS-NB_SWB_SUBBANDS)]);*/
+ /* 0.15: 4915.2(Q15) 0.85: 27852.80(Q15) */
+ *p_Enn_sm_sb_fx = round_fx(L_mac(L_mult(*p_sqrt_En_fx, 4915), *p_prev_En_sb_fx, 27853));
+ }
+ ELSE
+ {
+ /**p_Enn_sm_sb = (0.8f*(*p_En)) + (0.2f*prev_En_sb[k-(BANDS-NB_SWB_SUBBANDS)]);*/
+ /* 0.8: 26214.4(Q15) 0.2:6553.6(Q15) */
+ *p_Enn_sm_sb_fx = round_fx(L_mac(L_mult(*p_sqrt_En_fx, 26214), *p_prev_En_sb_fx, 6554));
+ }
+ }
+
+ p_Enn_sm_sb_fx++;
+ p_sqrt_En_fx++;
+ p_prev_En_sb_fx++;
+ }
+
+ p_sqrt_En_fx = sqrt_En_fx;
+ p_Enn_sm_sb_fx = Enn_sm_sb_fx;
+ p_prev_En_sb_fx = prev_En_sb_fx;
+ map_pulse_fx[fLenLow_fx] = (map_pulse_t_fx[fLenLow_fx] | map_pulse_t_fx[fLenLow_fx + 1]);
+ logic16();
+ move16();
+ FOR(i = fLenLow_fx + 1; i < band_end_fx[BANDS_fx - 1]; i++)
+ {
+ map_pulse_fx[i] = (map_pulse_t_fx[i - 1] | map_pulse_t_fx[i] | map_pulse_t_fx[i + 1]);
+ logic16();
+ logic16();
+ move16();
+ }
+ map_pulse_fx[i] = (map_pulse_t_fx[i - 1] | map_pulse_t_fx[i]);
+ logic16();
+ move16();
+
+ FOR(k = BANDS_fx - NB_SWB_SUBBANDS; k < BANDS_fx; k++)
+ {
+ test();
+ IF(p2a_flags_fx[k] == 0 && *p_sqrt_En_fx != 0x0)
+ {
+ /*ni_scale = sqrt((*p_Enn_sm_sb)/(*p_En));*/
+ /* Div Part */
+ exp_normn = norm_s(*p_Enn_sm_sb_fx);
+ exp_normn = sub(exp_normn, 1);
+ exp_normd = norm_s(*p_sqrt_En_fx);
+ div_fx = div_s(shl(*p_Enn_sm_sb_fx, exp_normn), shl(*p_sqrt_En_fx, exp_normd));
+ Qdiv = add(sub(exp_normn, exp_normd), 15);
+
+ /* SQRT Part */
+ sqrt_32n_16_fx(L_deposit_h(div_fx), add(Qdiv, 16), &ni_scale_fx, &Qtemp);
+#ifdef BASOP_NOGLOB
+ ni_scale_fx = shl_o(ni_scale_fx, sub(14, Qtemp), &Overflow);
+#else
+ ni_scale_fx = shl(ni_scale_fx, sub(14, Qtemp));
+#endif
+ ni_scale_fx = s_min(20408, ni_scale_fx); /* 1.25=20408.0(Q14) */
+
+ ni_scale_fx = s_max(12288, ni_scale_fx); /* 0.75=12288.0(Q14) */
+
+ ni_scale_fx = mult_r(ni_scale_fx, 26214); /* 0.8=26214.4(Q15) -> Q14 */
+ FOR(i = band_start_fx[k]; i <= band_end_fx[k]; i++)
+ {
+ IF(LE_32(L_abs(L_xSynth_har[i - fLenLow_fx]), L_th_g[k - (BANDS_fx - NB_SWB_SUBBANDS)]))
+ {
+ IF(map_pulse_fx[i] == 0)
+ {
+ L_xSynth_har[i - fLenLow_fx] = L_shl(Mult_32_16(L_xSynth_har[i - fLenLow_fx], ni_scale_fx), 1); /* Q12+Q14-15-1 = Q12 */ move32();
+ }
+ }
+ }
+ *p_prev_En_sb_fx = *p_Enn_sm_sb_fx;
+ move16();
+ }
+ p_Enn_sm_sb_fx++;
+ p_sqrt_En_fx++;
+ p_prev_En_sb_fx++;
+ }
+
+ return;
+}
+
+/*--------------------------------------------------------------------------*
+ * updat_prev_frm()
+ *
+ *
+ *--------------------------------------------------------------------------*/
+void updat_prev_frm_fx(
+ Word32 L_y2[], /* i/o: core coder buffer */
+ Word32 L_t_audio[], /* o: core coder buffer */
+ Word32 L_bwe_br, /* i: core bitrate */
+ Word16 length_fx, /* i: frame length coded bw */
+ const Word16 inner_frame_fx, /* i: input frame length */
+ Word16 bands_fx, /* i: sub band resolution */
+ Word16 bwidth_fx, /* i: NB/WB/SWB indicator */
+ const Word16 is_transient_fx, /* i: signal class information */
+ Word16 hqswb_clas_fx, /* i: signal class information */
+ Word16 *prev_hqswb_clas_fx, /* o: update signal class information */
+ Word16 prev_SWB_peak_pos_fx[], /* o: update core coder last coded peaks*/
+ Word16 prev_SWB_peak_pos_tmp_fx[], /* o: update core coder last coded peaks*/
+ Word16 *prev_frm_hfe2_fx, /* o: update harmonics */
+ Word16 *prev_stab_hfe2_fx, /* o: update harmonics */
+ Word16 bws_cnt_fx /* i: band width detector */
+)
+{
+ Word16 i, j, k;
+ Word16 k1_fx, k2_fx;
+ Word16 length1_fx, length2_fx, length3_fx;
+
+ /* Copy the coded MDCT coefficient to the output buffer */
+ IF(!is_transient_fx)
+ {
+ /* Copy the scratch buffer to the output */
+ Copy32(L_y2, L_t_audio, length_fx);
+
+ /* If the input frame is larger than coded bandwidth, zero out uncoded MDCT coefficients */
+ IF(GT_16(inner_frame_fx, length_fx))
+ {
+ set32_fx(L_t_audio + length_fx, 0x0L, sub(inner_frame_fx, length_fx));
+ }
+ }
+ ELSE /* transient frame */
+ {
+ test();
+ IF(EQ_16(inner_frame_fx, length_fx) || bws_cnt_fx > 0)
+ {
+ /* Copy the scratch buffer to the output */
+ Copy32(L_y2, L_t_audio, length_fx);
+ }
+ ELSE
+ {
+ /* length/NUM_TIME_SWITCHING_BLOCKS */
+ /*length1_fx = div_s_ss(length_fx, NUM_TIME_SWITCHING_BLOCKS); */
+ length1_fx = shr(length_fx, 2); /* length1 = length/NUM_TIME_SWITCHING_BLOCKS */
+ /* inner_frame/NUM_TIME_SWITCHING_BLOCKS */
+ /*length2_fx = div_s_ss(inner_frame_fx, NUM_TIME_SWITCHING_BLOCKS); */
+ length2_fx = shr(inner_frame_fx, 2); /* length2 = inner_frame/NUM_TIME_SWITCHING_BLOCKS */
+ /* (inner_frame-length)/NUM_TIME_SWITCHING_BLOCKS */
+ /*length3_fx = div_s_ss(sub(inner_frame_fx, length_fx), NUM_TIME_SWITCHING_BLOCKS); */
+ length3_fx = shr(sub(inner_frame_fx, length_fx) ,2); /* (inner_frame-length)/NUM_TIME_SWITCHING_BLOCKS */
+
+ k1_fx = 0;
+ move16();
+ k2_fx = 0;
+ move16();
+
+ /* un-collapse transient frame and interleave zeros */
+ FOR(i = 0; i < NUM_TIME_SWITCHING_BLOCKS; i++)
+ {
+ /*k1 = i*length/NUM_TIME_SWITCHING_BLOCKS; */
+ /*k2 = i*inner_frame/NUM_TIME_SWITCHING_BLOCKS; */
+
+ Copy32(L_y2 + k1_fx, L_t_audio + k2_fx, length1_fx);
+ set32_fx(L_t_audio + k2_fx + length1_fx, 0x0L, length3_fx);
+
+ k1_fx = add(k1_fx, length1_fx);
+ k2_fx = add(k2_fx, length2_fx);
+
+ }
+ }
+ }
+
+ IF((EQ_32(L_bwe_br, HQ_16k40) || EQ_32(L_bwe_br, HQ_13k20)) && EQ_16(bwidth_fx, SWB))
+ {
+ *prev_hqswb_clas_fx = hqswb_clas_fx;
+ move16();
+ IF(NE_16(hqswb_clas_fx, HQ_HARMONIC))
+ {
+ *prev_frm_hfe2_fx = 0;
+ move16();
+ *prev_stab_hfe2_fx = 0;
+ move16();
+ }
+ }
+ ELSE
+ {
+ *prev_hqswb_clas_fx = is_transient_fx;
+ move16();
+ }
+
+ test();
+ test();
+ test();
+ IF((EQ_32(L_bwe_br, HQ_16k40) || EQ_32(L_bwe_br, HQ_13k20)) && EQ_16(bwidth_fx, SWB) && EQ_16(hqswb_clas_fx, HQ_NORMAL))
+ {
+ j = 0;
+ move16();
+ FOR(k = sub(bands_fx, SPT_SHORTEN_SBNUM); k < bands_fx; k++)
+ {
+ prev_SWB_peak_pos_fx[j] = prev_SWB_peak_pos_tmp_fx[j];
+ move16();
+ j = add(j, 1);
+ }
+ }
+
+ return;
+}
diff --git a/lib_com/swb_tbe_com.c b/lib_com/swb_tbe_com.c
index b99ba26cb67a440930dd4af60e014e9fb77a5dee..521b083a1c20f38e3c65f32edc7bffe28bcdc99e 100644
--- a/lib_com/swb_tbe_com.c
+++ b/lib_com/swb_tbe_com.c
@@ -105,13 +105,13 @@ void swb_tbe_reset_synth(
/*-------------------------------------------------------------------*
- * tbe_celp_exc_offset()
+ * tbe_celp_exc_offset_flt()
*
* Compute tbe bwe celp excitation offset
*-------------------------------------------------------------------*/
/*! r: offset value */
-int16_t tbe_celp_exc_offset(
+int16_t tbe_celp_exc_offset_flt(
const int16_t T0, /* i : Integer pitch */
const int16_t T0_frac /* i : Fractional part of the pitch */
)
@@ -1870,12 +1870,12 @@ static void Estimate_mix_factors(
}
/*-------------------------------------------------------------------*
- * tbe_celp_exc() *
+ * tbe_celp_exc_flt() *
* *
* Prepare adaptive part of TBE excitation *
*-------------------------------------------------------------------*/
-void tbe_celp_exc(
+void tbe_celp_exc_flt(
const int16_t element_mode, /* i : element mode */
const int16_t idchan, /* i : channel ID */
float *bwe_exc, /* i/o: BWE excitation */
@@ -1899,7 +1899,7 @@ void tbe_celp_exc(
if ( L_frame == L_FRAME )
{
- offset = tbe_celp_exc_offset( T0, T0_frac );
+ offset = tbe_celp_exc_offset_flt( T0, T0_frac );
for ( i = 0; i < L_subfr * HIBND_ACB_L_FAC; i++ )
{
diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c
new file mode 100644
index 0000000000000000000000000000000000000000..0c5fd52341d3627d68e08765dd7886889ef85f31
--- /dev/null
+++ b/lib_com/swb_tbe_com_fx.c
@@ -0,0 +1,4266 @@
+/*====================================================================================
+ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
+ ====================================================================================*/
+
+
+#include
+#include "options.h"
+#include "cnst.h" /* Common constants */
+#include "rom_com.h" /* Static table prototypes */
+#include "prot_fx1.h"
+#include "prot_fx2.h"
+#include "basop_util.h"
+
+/*-----------------------------------------------------------------*
+* Local function prototypes
+*-----------------------------------------------------------------*/
+
+static void create_random_vector_fx( Word16 output[], const Word16 length, Word16 seed[] );
+static void flip_spectrum_fx( const Word16 input[], Word16 output[], const Word16 length );
+static void Calc_st_filt_tbe(Word16 * apond2,Word16 * apond1,Word16 * parcor0,Word16 * sig_ltp_ptr,Word16 * mem_zero );
+static void Hilbert_transform_fx( Word32 tmp_R[], Word32 tmp_I[], Word32 *tmpi_R, Word32 *tmpi_I, const Word16 length, const Word16 HB_stage_id );
+static void Hilbert_transform_sp_fx( Word16 tmp_R[], Word16 tmp_I[], Word32 *tmpi_R, Word32 *tmpi_I, const Word16 length, const Word16 HB_stage_id );
+void Estimate_mix_factors_fx( const Word16 *shb_res, const Word16 Q_shb, const Word16 *exc16kWhtnd, const Word16 Q_bwe_exc, const Word16 *White_exc16k_frac,
+ const Word16 Q_frac, const Word32 pow1, const Word16 Q_pow1, const Word32 pow22, const Word16 Q_pow22, Word16 *vf_modified, Word16 *vf_ind );
+
+/*-------------------------------------------------------------------*
+* swb_tbe_reset()
+*
+* Reset the SWB TBE encoder
+*-------------------------------------------------------------------*/
+
+void swb_tbe_reset_fx(
+ Word32 mem_csfilt[],
+ Word16 mem_genSHBexc_filt_down_shb[],
+ Word16 state_lpc_syn[],
+ Word16 syn_overlap[],
+ Word16 state_syn_shbexc[],
+ Word16* tbe_demph,
+ Word16* tbe_premph,
+ Word16 mem_stp_swb[],
+ Word16* gain_prec_swb
+)
+{
+ set32_fx( mem_csfilt, 0, 2 );
+ set16_fx( mem_genSHBexc_filt_down_shb, 0, (2*ALLPASSSECTIONS_STEEP+1));
+ set16_fx( state_lpc_syn, 0, LPC_SHB_ORDER );
+
+ set16_fx( syn_overlap, 0, L_SHB_LAHEAD );
+ set16_fx( state_syn_shbexc, 0, L_SHB_LAHEAD );
+
+ *tbe_demph = 0;
+ move16();
+ *tbe_premph = 0;
+ move16();
+
+ set16_fx(mem_stp_swb, 0, LPC_SHB_ORDER);
+ *gain_prec_swb = 16384;
+ move16();/*Q14 = 1 */
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+* swb_tbe_reset_synth()
+*
+* Reset the extra parameters needed for synthesis of the SWB TBE output
+*-------------------------------------------------------------------*/
+
+
+void swb_tbe_reset_synth_fx(
+ Word32 genSHBsynth_Hilbert_Mem[],
+ Word16 genSHBsynth_state_lsyn_filt_shb_local_fx[] )
+{
+
+ set32_fx( genSHBsynth_Hilbert_Mem, 0, HILBERT_MEM_SIZE );
+ set16_fx( genSHBsynth_state_lsyn_filt_shb_local_fx, 0, 2*ALLPASSSECTIONS_STEEP );
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * fb_tbe_reset_synth_fx()
+ *
+ * reset of FB TBE memories
+ *-------------------------------------------------------------------*/
+
+void fb_tbe_reset_synth_fx(
+ Word32 fbbwe_hpf_mem_fx[][4],
+ Word16 fbbwe_hpf_mem_fx_Q[],
+ Word16 *prev_fbbwe_ratio_fx
+)
+{
+ set32_fx( fbbwe_hpf_mem_fx[0], 0, 4 );
+ set32_fx( fbbwe_hpf_mem_fx[1], 0, 4 );
+ set32_fx( fbbwe_hpf_mem_fx[2], 0, 4 );
+ set32_fx( fbbwe_hpf_mem_fx[3], 0, 4 );
+ set16_fx( fbbwe_hpf_mem_fx_Q, 0, 4 );
+ *prev_fbbwe_ratio_fx = 1;
+ move16(); /*should be set to 1.0f, scaling unknown */
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+ * tbe_celp_exc_offset()
+ *
+ * Compute tbe bwe celp excitation offset
+ *-------------------------------------------------------------------*/
+
+Word16 tbe_celp_exc_offset(
+ const Word16 T0_fx, /* i : Integer pitch */
+ const Word16 T0_frac_fx, /* i : Fractional part of the pitch */
+ const Word16 L_frame /* i : frame lenght */
+)
+{
+ Word16 offset_fx, tmp_fx, tmp1_fx, tmp2_fx, tmp_fac;
+ tmp_fac = 320;
+ move16(); /*2.5 in Q7*/
+ if(EQ_16(L_frame, L_FRAME16k))
+ {
+ tmp_fac = 256;
+ move16(); /*2.0 in Q7*/
+ }
+ tmp_fx = extract_l(L_mult(T0_frac_fx,32));/*Q8, 0.25 in Q7*/
+ tmp_fx = add(512,tmp_fx);/*Q8; 2 in Q8*/
+ tmp_fx = mult_r(tmp_fx,tmp_fac);/*Q16->Q0; 2.5 in Q7 or 2.0 in Q7 */
+
+ tmp1_fx = sub(T0_fx,2);/*Q0*/
+
+ tmp2_fx = shl(tmp1_fx,1);/*Q0 */
+
+ IF(EQ_16(L_frame, L_FRAME))
+ {
+ tmp2_fx = add(shl(tmp1_fx,1),shr(tmp1_fx,1));/*Q0; (5/2 = 2 + 1/2)*/
+ }
+
+ offset_fx = add(tmp_fx,tmp2_fx);/*Q0*/
+
+ return offset_fx;
+}
+
+/*-------------------------------------------------------------------*
+* swb_tbe_celp_exc()
+*
+* Compute tbe bwe celp excitation
+*-------------------------------------------------------------------*/
+void tbe_celp_exc(
+ const Word16 L_frame_fx, /* i : Frame lenght */
+ 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 */
+)
+{
+ Word16 offset_fx, tmp_fx, i;
+ 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; i0)
+ {
+ tmp_fx = shr(*error_fx,5);/*Q0*/
+ }
+ ELSE
+ {
+ tmp_fx = negate(shr(abs_s(*error_fx),5));/*Q0*/
+ }
+
+ FOR (i=0; i0)
+ {
+ tmp_fx = shr(*error_fx,5);/*Q0*/
+ }
+ ELSE
+ {
+ tmp_fx = negate(shr(abs_s(*error_fx),5));/*Q0*/
+ }
+
+ FOR (i=0; i= period )
+ {
+ *phase_state = 0;
+ move16();
+ }
+
+ i = 0;
+ move16();
+ j = *phase_state;
+ move16();
+
+ WHILE ( i < length )
+ {
+ WHILE ( ( j < period ) && ( i < length ) )
+ {
+ L_tmp = Mult_32_16( tmp_R[i + 4], local_cos_table[j] ); /*//Qx+16 */
+ L_tmp = Madd_32_16( L_tmp, tmp_I[i + 4], local_negsin_table[j] ); /*Qx+16 */
+ output[i] = round_fx( L_tmp ); /*Qx */
+ i++ ;
+ j++ ;
+ }
+
+ if ( j >= period )
+ {
+ j = 0;
+ move16();
+ }
+ }
+
+ *phase_state = j;
+ move16();
+ return;
+}
+
+
+/*----------------------------------------------
+ * Hilbert transform - Double precision
+ *------------------------------------------------*/
+static void Hilbert_transform_fx(
+ Word32 tmp_R[], /* i: Real component of HB */
+ Word32 tmp_I[], /* i: Real component of HB */
+ Word32 tmpi_R[], /* o: Real component of HB */
+ Word32 tmpi_I[], /* o: Imag. component of HB */
+ const Word16 length, /* i: input length */
+ const Word16 HB_stage_id /* i: HB transform stage */
+)
+{
+ Word16 i, hb_filter_stage, offset;
+ Word32 L_tmp;
+
+ hb_filter_stage = 2*HB_stage_id;
+ offset = 0;
+ move16();
+ if( HB_stage_id == 0 )
+ {
+ offset = 1;
+ move16();
+ }
+
+ test();
+ test();
+ IF (HB_stage_id == 0 || HB_stage_id == 2)
+ {
+ FOR ( i = 0; i < length; i++ )
+ {
+ L_tmp = Mult_32_16( tmp_R[i + 4], Hilbert_coeffs_fx[hb_filter_stage][0 + offset] ); /*Qx+15 */
+ L_tmp = Madd_32_16( L_tmp, tmp_R[i + 2], Hilbert_coeffs_fx[hb_filter_stage][2 + offset] ); /*Qx+15 */
+ L_tmp = Madd_32_16( L_tmp, tmp_R[i] , Hilbert_coeffs_fx[hb_filter_stage][4 + offset] );/*Qx+15 */
+ tmpi_R[i] = L_shl( L_tmp, 1 );
+ move32(); /*Qx+16 */
+
+ L_tmp = Mult_32_16( tmp_I[i + 4 + offset], Hilbert_coeffs_fx[hb_filter_stage+1][0] ); /*Qx+15 */
+ L_tmp = Madd_32_16( L_tmp, tmp_I[i + 2 + offset], Hilbert_coeffs_fx[hb_filter_stage+1][2] ); /*Qx+15 */
+ L_tmp = Madd_32_16( L_tmp, tmp_I[i + offset] , Hilbert_coeffs_fx[hb_filter_stage+1][4] ); /*Qx+15 */
+ tmpi_I[i] = L_shl( L_tmp, 1 );
+ move32(); /*Qx+16 */
+ }
+ }
+ ELSE IF (HB_stage_id == 1 || HB_stage_id == 3)
+ {
+ FOR ( i = 0; i < length; i++ )
+ {
+
+ L_tmp = Mult_32_16( tmpi_R[i + 2], Hilbert_coeffs_fx[hb_filter_stage][2] ); /*Qx+15 */
+ L_tmp = Madd_32_16( L_tmp, tmpi_R[i] , Hilbert_coeffs_fx[hb_filter_stage][4] ); /*Qx+15 */
+ tmpi_R[i + 4] = L_sub( tmp_R[i], L_shl( L_tmp, 1 ) );
+ move32();/*Qx+16 */
+
+ L_tmp = Mult_32_16( tmpi_I[i + 2], Hilbert_coeffs_fx[hb_filter_stage+1][2] ); /*Qx+15 */
+ L_tmp = Madd_32_16( L_tmp, tmpi_I[i] , Hilbert_coeffs_fx[hb_filter_stage+1][4] ); /*Qx+15 */
+ tmpi_I[i + 4] = L_sub( tmp_I[i], L_shl( L_tmp, 1 ) );
+ move32(); /*Qx+16 */
+ }
+ }
+}
+
+
+/*----------------------------------------------
+* Hilbert transform - Single precision Stage 0
+*------------------------------------------------*/
+static void Hilbert_transform_sp_fx(
+ Word16 tmp_R[], /* i: Real component of HB */
+ Word16 tmp_I[], /* i: Real component of HB */
+ Word32 tmpi_R[], /* o: Real component of HB */
+ Word32 tmpi_I[], /* o: Imag. component of HB */
+ const Word16 length, /* i: input length */
+ const Word16 HB_stage_id /* i: HB transform stage */
+)
+{
+ Word16 i, hb_filter_stage, offset;
+ Word32 L_tmp;
+
+ hb_filter_stage = shl(HB_stage_id,1);
+ offset = 0;
+ move16();
+ if( HB_stage_id == 0 )
+ {
+ offset = 1;
+ move16();
+ }
+
+ /* Hilbert single precision stage 0 */
+ FOR ( i = 0; i < length; i++ )
+ {
+ L_tmp = L_mult( tmp_R[i + 4], Hilbert_coeffs_fx[hb_filter_stage][0 + offset] ); /*Qx */
+ L_tmp = L_mac ( L_tmp, tmp_R[i + 2], Hilbert_coeffs_fx[hb_filter_stage][2 + offset] ); /*Qx */
+ L_tmp = L_mac ( L_tmp, tmp_R[i] , Hilbert_coeffs_fx[hb_filter_stage][4 + offset] ); /*Qx */
+ tmpi_R[i] = L_shl ( L_tmp, 1 );
+ move32(); /*Qx+16 */
+
+ L_tmp = L_mult( tmp_I[i + 4 + offset], Hilbert_coeffs_fx[hb_filter_stage+1][0] ); /*Qx */
+ L_tmp = L_mac ( L_tmp, tmp_I[i + 2 + offset], Hilbert_coeffs_fx[hb_filter_stage+1][2] ); /*Qx */
+ L_tmp = L_mac ( L_tmp, tmp_I[i + offset] , Hilbert_coeffs_fx[hb_filter_stage+1][4] ); /*Qx */
+ tmpi_I[i] = L_shl ( L_tmp, 1 );
+ move32(); /*Qx+16 */
+ }
+
+ return;
+}
+
+
+/*----------------------------------------------
+ * flip_spectrum_fx
+ *----------------------------------------------*/
+void flip_spectrum_fx(
+ const Word16 input[], /* i : input spectrum */
+ Word16 output[], /* o : output spectrum */
+ const Word16 length /* i : vector length */
+)
+{
+ Word16 i;
+
+ FOR ( i = 0; i < length; i = i + 2 )
+ {
+ output[i] = negate( input[i] );
+ move16();
+ output[i + 1] = input[i + 1];
+ move16();
+ }
+
+ return;
+}
+
+
+/*----------------------------------------------------------------------------
+ * calc_rc0_h
+ *
+ * computes 1st parcor from composed filter impulse response
+ *---------------------------------------------------------------------------*/
+void Calc_rc0_h(
+ Word16 * h, /* i : impulse response of composed filter */
+ Word16 * rc0 /* o : 1st parcor */
+)
+{
+ Word32 L_acc;
+ Word16 *ptrs;
+ Word16 acf0, acf1;
+ Word16 temp, sh_acf;
+ Word16 i;
+
+ /* computation of the autocorrelation function acf */
+ L_acc = L_mult(h[0], h[0]);
+ FOR(i = 1; i < LONG_H_ST; i++)
+ {
+ L_acc = L_mac(L_acc, h[i], h[i]);
+ }
+ sh_acf = norm_l(L_acc);
+ L_acc = L_shl(L_acc, sh_acf);
+ acf0 = extract_h(L_acc);
+
+ ptrs = h;
+
+ temp = *ptrs++;
+ move16();
+ L_acc = L_mult(temp, *ptrs);
+ FOR(i = 1; i < LONG_H_ST - 1; i++)
+ {
+ temp = *ptrs++;
+ move16();
+ L_acc = L_mac(L_acc, temp, *ptrs);
+ }
+ L_acc = L_shl(L_acc, sh_acf);
+ acf1 = extract_h(L_acc);
+
+ /* Compute 1st parcor */
+ if (acf0 == 0)
+ {
+ *rc0 = 0;
+ move16();
+ return;
+ }
+
+ IF (LT_16(acf0, abs_s(acf1)))
+ {
+ *rc0 = 0;
+ move16();
+ return;
+ }
+ *rc0 = div_s(abs_s(acf1), acf0);
+ move16();
+ if (acf1 > 0)
+ {
+ *rc0 = negate(*rc0);
+ move16();
+ }
+}
+
+static void Calc_st_filt_tbe(
+ Word16 * apond2, /* i : coefficients of numerator */
+ Word16 * apond1, /* i : coefficients of denominator */
+ Word16 * parcor0, /* o : 1st parcor calcul. on composed filter */
+ Word16 * sig_ltp_ptr, /* i/o: i of 1/A(gamma1) : scaled by 1/g0 */
+ Word16 * mem_zero /* i : All zero memory */
+)
+{
+ Word32 L_g0;
+
+ Word16 h[LONG_H_ST];
+
+ Word16 g0, temp;
+ Word16 i;
+ temp = sub( 2, norm_s( apond2[0] ) );
+ /* compute i.r. of composed filter apond2 / apond1 */
+ Syn_filt_s(temp, apond1, LPC_SHB_ORDER, apond2, h, LONG_H_ST, mem_zero, 0);
+ /* compute 1st parcor */
+ Calc_rc0_h(h, parcor0);
+
+ /* compute g0 */
+ L_g0 = L_mult0(1, abs_s(h[0]));
+ FOR (i = 1; i < LONG_H_ST; i++)
+ {
+ L_g0 = L_mac0(L_g0, 1, abs_s(h[i]));
+ }
+ g0 = extract_h(L_shl(L_g0, 14));
+
+ /* Scale signal i of 1/A(gamma1) */
+ IF (GT_16(g0, 1024))
+ {
+ temp = div_s(1024, g0); /* temp = 2**15 / gain0 */
+ FOR (i = 0; i < L_SUBFR16k; i++)
+ {
+ sig_ltp_ptr[i] = mult_r(sig_ltp_ptr[i], temp);
+ move16();
+ }
+ }
+}
+
+static void filt_mu_fx(
+ const Word16 *sig_in, /* i : signal (beginning at sample -1) */
+ Word16 *sig_out, /* o : output signal */
+ const Word16 parcor0, /* i : parcor0 (mu = parcor0 * gamma3) */
+ Word16 SubFrameLength /* i : the length of subframe */
+)
+{
+ Word16 n;
+ Word16 mu, ga, temp;
+ const Word16 *ptrs;
+ Word16 tmp,exp;
+
+
+ IF ( EQ_16(SubFrameLength ,L_SUBFR ))
+ {
+ IF (parcor0 > 0)
+ {
+ mu = mult_r(parcor0 , GAMMA3_PLUS_FX);
+ }
+ ELSE
+ {
+ mu = mult_r(parcor0 , GAMMA3_MINUS_FX);
+ }
+ }
+ ELSE
+ {
+ IF(parcor0 > 0)
+ {
+ mu = mult_r( parcor0 , GAMMA3_PLUS_WB_FX);
+ }
+ ELSE
+ {
+ mu = mult_r( parcor0 , GAMMA3_MINUS_WB_FX);
+ }
+ }
+
+ tmp = abs_s(mu);
+ tmp = sub(32767 , tmp);
+ exp = norm_s(tmp);
+ tmp = div_s(shl(1,sub(14,exp)),tmp);/*(14 - exp) */
+ ga = shl(tmp ,exp);/*Q14 */
+
+
+ /* ga = (float) 1. / ((float) 1. - (float) fabs (mu)); */
+
+ ptrs = sig_in; /* points on sig_in(-1) */
+
+ FOR (n = 0; n < SubFrameLength; n++)
+ {
+ temp = mult_r(mu , (*ptrs++));
+ temp = add (temp ,*ptrs );/*Q12 */
+ sig_out[n] = shl(mult_r( ga , temp),1);
+ move16();/*Q12 */
+ }
+
+ return;
+}
+
+static void scale_st_swb(
+ const Word16 * sig_in_fx, /* i : postfilter i signal */
+ Word16 * sig_out_fx, /* i/o: postfilter o signal */
+ Word16 * gain_prec_fx, /* i/o: last value of gain for subframe */
+ Word16 SubFrameLength
+)
+{
+ Word16 i;
+ Word16 agc_fac1_para_fx;
+ Word16 agc_fac_para_fx;
+ Word32 L_acc,L_temp;
+ Word16 g0_fx, gain_fx;
+ Word16 scal_in, scal_out;
+ Word16 s_g_in, s_g_out,sh_g0,temp;
+
+
+ IF ( EQ_16(SubFrameLength ,L_SUBFR ))
+ {
+ agc_fac1_para_fx = AGC_FAC1_FX;
+ move16();
+ agc_fac_para_fx = AGC_FAC_FX;
+ move16();
+ }
+ ELSE /*IF( SubFrameLength == L_SUBFR16k ) */
+ {
+ agc_fac1_para_fx = AGC_FAC1_WB_FX;
+ move16();
+ agc_fac_para_fx = AGC_FAC_WB_FX;
+ move16();
+ }
+
+ /* compute input gain */
+ L_acc = L_mult0(1, abs_s(sig_in_fx[0]));/*0 +Q_bwe_exc-1 */
+ FOR (i = 1; i < SubFrameLength; i++)
+ {
+ L_acc = L_mac0(L_acc, 1, abs_s(sig_in_fx[i])); /*Q_bwe_exc-1 */
+ }
+
+ g0_fx = 0;
+ move16();
+ IF (L_acc != 0L)
+ {
+ scal_in = norm_l(L_acc);
+ L_acc = L_shl(L_acc, scal_in);
+ s_g_in = extract_h(L_acc); /* normalized */
+
+ /* Compute o gain */
+ L_acc = L_mult0(1, abs_s(sig_out_fx[0]));
+ FOR (i = 1; i < SubFrameLength; i++)
+ {
+ L_acc = L_mac0(L_acc, 1, abs_s(sig_out_fx[i]));
+ }
+ IF (L_acc == 0L)
+ {
+ *gain_prec_fx = 0;
+ move16();
+
+ return;
+ }
+
+ scal_out = norm_l(L_acc);
+ L_acc = L_shl(L_acc, scal_out);
+ s_g_out = extract_h(L_acc); /* normalized */
+
+
+ sh_g0 = add(scal_in, 1);
+ sh_g0 = sub(sh_g0, scal_out); /* scal_in - scal_out + 1 */
+ IF (LT_16(s_g_in, s_g_out))
+ {
+ g0_fx = div_s(s_g_in, s_g_out); /* s_g_in/s_g_out in Q15 */
+ }
+ ELSE
+ {
+ temp = sub(s_g_in, s_g_out); /* sufficient since normalized */
+ g0_fx = shr(div_s(temp, s_g_out), 1);
+ g0_fx = add(g0_fx, (Word16) 0x4000); /* s_g_in/s_g_out in Q14 */
+ sh_g0 = sub(sh_g0, 1);
+ }
+ /* L_gain_in/L_gain_out in Q14 */
+ /* overflows if L_gain_in > 2 * L_gain_out */
+ g0_fx = shr(g0_fx, sh_g0); /* sh_g0 may be >0, <0, or =0 */
+
+ g0_fx = mult_r(g0_fx, agc_fac1_para_fx); /* L_gain_in/L_gain_out * AGC_FAC1_FX */
+ }
+ /* compute gain(n) = AGC_FAC gain(n-1) + (1-AGC_FAC)gain_in/gain_out */
+ /* sig_out(n) = gain(n) sig_out(n) */
+ gain_fx = *gain_prec_fx;
+ move16(); /*14 */
+ FOR (i = 0; i < SubFrameLength; i++)
+ {
+ temp = mult_r(agc_fac_para_fx, gain_fx);/*15 +14 -15 =14 */
+ gain_fx = add(temp, g0_fx); /* in Q14 */
+ L_temp = L_mult(gain_fx, sig_out_fx[i]);/*14 + Q_bwe_exc-1 +1 = 14 + Q_bwe_exc */
+#ifdef BASOP_NOGLOB
+ L_temp = L_shl_sat(L_temp, 1); /*14 + Q_bwe_exc +1 */
+ sig_out_fx[i] = round_fx_sat(L_temp); /*Q_bwe_exc +15 -16 = Q_bwe_exc-1 */
+#else
+ L_temp = L_shl(L_temp, 1); /*14 + Q_bwe_exc +1 */
+ sig_out_fx[i] = round_fx(L_temp); /*Q_bwe_exc +15 -16 = Q_bwe_exc-1 */
+#endif
+ }
+ *gain_prec_fx =gain_fx;
+ move16();
+
+ return;
+}
+
+void PostShortTerm_fx(
+ Word16 *sig_in, /* i : input signal (pointer to current subframe */
+ Word16 *lpccoeff, /* i : LPC coefficients for current subframe */
+ Word16 *sig_out, /* o : postfiltered output */
+ Word16 *mem_stp, /* i/o: postfilter memory*/
+ Word16 *ptr_mem_stp, /* i/o: pointer to postfilter memory*/
+ Word16 *ptr_gain_prec, /* i/o: for gain adjustment*/
+ Word16 *mem_zero, /* i/o: null memory to compute h_st*/
+ const Word16 formant_fac_fx /* i : Strength of post-filter*/
+)
+{
+ Word16 apond1_fx[LPC_SHB_ORDER+1]; /* denominator coeff.*/
+ Word16 apond2_fx[LONG_H_ST]; /* numerator coeff. */
+ Word16 sig_ltp_fx[L_SUBFR16k +1]; /* residual signal */
+ /*Word16 lpccoeff_fx[LPC_SHB_ORDER+1];//Q12 */
+ Word16 g1_fx,g2_fx,parcor0_fx; /*Q15 */
+ Word16 tmp;
+
+ parcor0_fx = 0;
+ move16();
+ set16_fx( apond1_fx, 0, LPC_SHB_ORDER+1 );
+ set16_fx( apond2_fx, 0, LONG_H_ST );
+ set16_fx( sig_ltp_fx, 0, L_SUBFR16k+1 );
+
+ /* Obtain post-filter weights */
+ tmp = extract_h(L_mult(GAMMA_SHARP_FX,formant_fac_fx));/*Q15 */
+ g1_fx = add(GAMMA0_FX,tmp);/*Q15 */
+ g2_fx = sub(GAMMA0_FX,tmp);/*Q15 */
+
+ /* Compute weighted LPC coefficients */
+ weight_a_fx(lpccoeff, apond1_fx, g1_fx, LPC_SHB_ORDER);
+ weight_a_fx(lpccoeff, apond2_fx, g2_fx, LPC_SHB_ORDER);
+ /* o: apond1_fx, apond2_fx in Q12 */
+
+ /* Compute A(gamma2) residual */
+ Residu3_10_fx( apond2_fx, sig_in, sig_ltp_fx+1, L_SUBFR16k, 0 );
+ /* o: sig_ltp_fx in Q_bwe_exc */
+
+ /* Save last output of 1/A(gamma1) */
+ sig_ltp_fx[0] = *ptr_mem_stp;
+ move16();
+
+ /* Control short term pst filter gain and compute parcor0 */
+ Calc_st_filt_tbe(apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx+1, mem_zero);
+ /* o: parcor0 in Q15 */
+ /* i/o: sig_ltp_fx in Q_bwe_exc */
+
+ /* 1/A(gamma1) filtering, mem_stp is updated */
+ Syn_filt_s(0,apond1_fx,LPC_SHB_ORDER,sig_ltp_fx+1,sig_ltp_fx+1,L_SUBFR16k,mem_stp,1);
+
+ /* (1 + mu z-1) tilt filtering */
+ filt_mu_fx(sig_ltp_fx, sig_out, parcor0_fx, L_SUBFR16k);
+ /* o: sig_out in Q_bwe_exc */
+
+ /* gain control */
+ scale_st_swb(sig_in, sig_out, ptr_gain_prec, L_SUBFR16k );
+
+ return;
+}
+
+void flip_spectrum_and_decimby4_fx(
+ const Word16 input[], /* i : input spectrum Q_inp */
+ Word16 output[], /* o : output spectrum Q_inp */
+ const Word16 length, /* i : vector length */
+ Word16 mem1[], /* i/o : memory Q_inp */
+ Word16 mem2[], /* i/o : memory Q_inp */
+ const Word16 ramp_flag /*i: flag to trigger slow ramp-up of output following change of core (HQ to ACELP or 12k8 to 16k ACELP) */
+)
+{
+ Word16 i;
+ Word16 factor, tmp[L_FRAME16k/2];
+ Word16 tmp1, tmp2;
+ Word16 input_change[L_FRAME16k];
+
+ IF ( ramp_flag )
+ {
+ factor = div_s( 4, length ); /* Q15 */
+ FOR ( i = 0; i < length / 4; i += 2)
+ {
+ tmp1 = extract_l( L_mult0( i, factor ) ); /* Q15 */
+ tmp2 = extract_l( L_mult0( add( i, 1 ), factor ) ); /*Q15 */
+ input_change[i] = negate( mult_r( input[i], tmp1 ) );
+ move16();
+ input_change[i + 1] = mult_r( input[i + 1], tmp2 );
+ move16();
+ }
+ }
+ ELSE
+ {
+ i = 0;
+ move16();
+ }
+
+ FOR (; i < length; i = i + 2 )
+ {
+ input_change[i] = negate( input[i] );
+ move16();
+ input_change[i + 1] = input[i + 1];
+ move16();
+ }
+
+ Decimate_allpass_steep_fx( input_change, mem1, length, tmp );
+ Decimate_allpass_steep_fx( tmp, mem2, length / 2, output );
+
+ return;
+}
+
+
+/*==========================================================================*/
+/* FUNCTION : void GenShapedWBExcitation_fx () */
+/*--------------------------------------------------------------------------*/
+/* PURPOSE : Synthesize spectrally shaped highband excitation signal for the wideband */
+/*--------------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _Word16 *lpc_shb i : lpc coefficients Q12 */
+/* _Word16 coder_type i : coding type */
+/* _Word16 *bwe_exc_extended i : bwidth extended exciatation Q_bwe_exc*/
+/* _Word16 Q_bwe_exc i : Q format */
+/* _Word16 voice_factors[] i : voicing factor Q15 */
+/*--------------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _Word16 *excSHB o : synthesized shaped shb exctiation Q_bwe_exc*/
+/* _Word16 *exc4kWhtnd o : whitened synthesized shb excitation Q_bwe_exc*/
+/*--------------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _Word32 *mem_csfilt i/o : memory Q_bwe_exc+16*/
+/* _Word16 *mem_genSHBexc_filt_down1 i/o : memory Q_bwe_exc */
+/* _Word16 *mem_genSHBexc_filt_down2 i/o : memory Q_bwe_exc */
+/* _Word16 *mem_genSHBexc_filt_down3 i/o : memory Q_bwe_exc */
+/* _Word16 *state_lpc_syn i/o : memory Q_bwe_exc */
+/* _Word16 bwe_seed[] i/o : random number generator seed */
+/*--------------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : */
+/* _ None */
+/*--------------------------------------------------------------------------*/
+/* CALLED FROM : */
+/*==========================================================================*/
+void GenShapedWBExcitation_fx(
+ Word16* excSHB, /* o : synthesized shaped shb exctiation Q_bwe_exc*/
+ const Word16* lpc_shb, /* i : lpc coefficients Q12*/
+ Word16* exc4kWhtnd, /* o : whitened synthesized shb excitation Q_bwe_exc*/
+ Word32* mem_csfilt, /* i/o : memory Q_bwe_exc+16*/
+ Word16* mem_genSHBexc_filt_down1, /* i/o : memory Q_bwe_exc*/
+ Word16* mem_genSHBexc_filt_down2, /* i/o : memory Q_bwe_exc*/
+ Word16* mem_genSHBexc_filt_down3, /* i/o : memory Q_bwe_exc*/
+ Word16* state_lpc_syn, /* i/o : memory Q_bwe_exc*/
+ const Word16 coder_type, /* i : coding type */
+ const Word16* bwe_exc_extended, /* i : bwidth extended exciatation Q_bwe_exc*/
+ const Word16 Q_bwe_exc, Word16 bwe_seed[], /* i/o : random number generator seed */
+ const Word16 voice_factors[], /* i : voicing factor Q15*/
+ const Word16 uv_flag, /* i : unvoiced flag */
+ const Word16 igf_flag
+)
+{
+ Word16 i, j, k;
+ Word16 wht_fil_mem [ LPC_WHTN_ORDER_WB ];
+ Word16 lpc_whtn[ LPC_WHTN_ORDER_WB + 1];
+ Word16 R_h[LPC_WHTN_ORDER_WB + 2], R_l[LPC_WHTN_ORDER_WB + 2];
+ Word16 Q_R;
+ Word16 excTmp[ L_FRAME16k];
+ Word16 excTmp2[ L_FRAME16k / 4];
+ Word16 excTmp2_frac[ L_FRAME16k / 4];
+ Word16 exc4k[ L_FRAME16k / 4];
+ Word16 exc4k_frac[ L_FRAME16k / 4];
+ Word32 exc4k_32[ L_FRAME16k / 4];
+ Word32 pow1, pow22;
+ Word16 scale;
+ Word32 excNoisyEnv[ L_FRAME16k / 4];
+ Word16 csfilt_num2[1] = {1638}; /* Q15*/
+ Word16 neg_csfilt_den2[2] = {-32768, 31457}; /* Q15 */
+ Word32 L_tmp, Ltemp1, Ltemp2;
+ Word16 temp1, temp2, exp;
+ Word32 Lmax;
+ Word16 max_val, n1, n2, sc;
+ Word32 LepsP[LPC_WHTN_ORDER_WB+1];
+ Word16 tmp_vfac;
+ Word16 avg_voice_fac;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+
+ /*0.25f*sum_f(voice_factors, NB_SUBFR)*/
+ L_tmp = L_mult(voice_factors[0], 8192);
+ FOR (i=1; i 0.35f*/
+ {
+ csfilt_num2[0] = 6554;
+ move16(); /*Q15 -> 0.2f*/
+ neg_csfilt_den2[1] = 26214;
+ move16(); /*Q15 -> 0.8f*/
+ }
+ ELSE IF( igf_flag != 0 && ( EQ_16(coder_type, UNVOICED)||LT_16(avg_voice_fac,6654))) /*Q15 -> 0.2f*/
+ {
+ csfilt_num2[0] = 328;
+ move16(); /*Q15 -> 0.01f*/
+ neg_csfilt_den2[1] = 32440;
+ move16(); /*Q15 -> 0.99f*/
+ }
+ set16_fx( wht_fil_mem, 0, LPC_WHTN_ORDER_WB );
+ Decimate_allpass_steep_fx( bwe_exc_extended, mem_genSHBexc_filt_down1, L_FRAME32k, excTmp );
+ flip_spectrum_and_decimby4_fx( excTmp, exc4k, L_FRAME16k, mem_genSHBexc_filt_down2, mem_genSHBexc_filt_down3, 0 );
+
+ IF ( uv_flag )
+ {
+ create_random_vector_fx( exc4kWhtnd, L_FRAME16k / 4, bwe_seed );
+ IF ( LT_16( Q_bwe_exc, 5 ))
+ {
+
+ FOR ( i = 0; i < L_FRAME16k / 4; i++ )
+ {
+ exc4kWhtnd[i] = shl_r( exc4kWhtnd[i], sub( Q_bwe_exc, 5 ) );/*Q(Q_bwe_exc)/Q5(if Q_bwe_exc > 5) */
+ }
+ }
+ }
+ ELSE
+ {
+ autocorr_fx( exc4k, LPC_WHTN_ORDER_WB + 1, R_h, R_l, &Q_R,
+ L_FRAME16k / 4, win_flatten_4k_fx, 0, 1 );
+
+ /* Ensure R[0] isn't zero when entering Levinson Durbin */
+ R_l[0] = s_max( R_l[0], 1 );
+ move16();
+ FOR ( i = 1; i <= LPC_WHTN_ORDER_WB; i++ )
+ {
+ L_tmp = Mpy_32( R_h[i], R_l[i], wac_h[i - 1], wac_l[i - 1] );
+ L_Extract( L_tmp, &R_h[i], &R_l[i] );
+ }
+
+ E_LPC_lev_dur(R_h, R_l, lpc_whtn, LepsP, LPC_WHTN_ORDER_WB, NULL);
+
+ Copy_Scale_sig( lpc_whtn, lpc_whtn, LPC_WHTN_ORDER_WB+1, sub(norm_s(lpc_whtn[0]),2) );
+
+ fir_fx( exc4k, lpc_whtn, exc4kWhtnd, wht_fil_mem, L_FRAME16k / 4,
+ LPC_WHTN_ORDER_WB, 0, 3 );
+
+ /* Ensure pow1 is greater than zero when computing normalization */
+ max_val = 0;
+ FOR ( i = 0; i < L_FRAME16k / 4; i++ )
+ {
+ excTmp2[i] = abs_s( exc4kWhtnd[i] );
+ move16(); /* Q_bwe_exc */
+ max_val = s_max( max_val, excTmp2[i] );
+ move16();
+ }
+
+ IF ( max_val == 0 )
+ {
+ pow1 = 1;
+ move16();
+ n1 = 0;
+ move16();
+ }
+ ELSE
+ {
+ n1 = norm_s( max_val );
+ FOR ( i = 0; i < L_FRAME16k / 4; i++ )
+ {
+#ifdef BASOP_NOGLOB
+ excTmp2_frac[i] = shl_o( excTmp2[i], n1, &Overflow );
+#else
+ excTmp2_frac[i] = shl( excTmp2[i], n1 );
+#endif
+ move16(); /* Q14 */
+ }
+ n1 = sub( sub( 14, n1 ), Q_bwe_exc );
+ pow1 = 1;
+ FOR ( i = 0; i < L_FRAME16k / 4; i++ )
+ {
+#ifdef BASOP_NOGLOB
+ L_tmp = L_mult_o( excTmp2_frac[i], excTmp2_frac[i], &Overflow); /* Q29 */
+ pow1 = L_add_o( pow1, L_shr( L_tmp, 7 ), &Overflow); /* Q22 */
+#else
+ L_tmp = L_mult( excTmp2_frac[i], excTmp2_frac[i] ); /* Q29 */
+ pow1 = L_add( pow1, L_shr( L_tmp, 7 ) ); /* Q22 */
+#endif
+ }
+ }
+
+ FOR ( i = 0; i < L_FRAME16k / 4; i++ )
+ {
+#ifdef BASOP_NOGLOB
+ excNoisyEnv[i] = L_add_o( *mem_csfilt, L_mult_o( csfilt_num2[0], excTmp2[i], &Overflow ), &Overflow);
+#else
+ excNoisyEnv[i] = L_add( *mem_csfilt, L_mult( csfilt_num2[0], excTmp2[i] ) );
+#endif
+ move32(); /* Q_bwe_exc+16 */
+ *mem_csfilt = Mult_32_16( excNoisyEnv[i], neg_csfilt_den2[1] );
+ move32(); /* Q_bwe_exc+16 */
+ }
+
+ create_random_vector_fx( exc4k, L_FRAME16k / 4, bwe_seed );
+
+ /* Ensure pow22 is greater than zero when computing normalization */
+ Lmax = 0;
+ FOR ( i = 0; i < L_FRAME16k / 4; i++ )
+ {
+ exc4k_32[i] = Mult_32_16( excNoisyEnv[i], exc4k[i] );
+ move32();/* Q_bwe_exc+6 */
+ Lmax = L_max( Lmax, L_abs( exc4k_32[i] ) );
+ }
+
+ IF ( Lmax == 0 )
+ {
+ pow22 = 1;
+ move16();
+ n2 = 0;
+ move16();
+ set16_fx( exc4k_frac, 0, L_FRAME16k / 4 );
+ }
+ ELSE
+ {
+ n2 = norm_l( Lmax );
+ FOR ( i = 0; i < L_FRAME16k / 4; i++ )
+ {
+#ifdef BASOP_NOGLOB
+ exc4k_frac[i] = extract_h( L_shl_o( exc4k_32[i], n2, &Overflow ) ); /* Q(14-n2) */
+#else
+ exc4k_frac[i] = extract_h( L_shl( exc4k_32[i], n2 ) ); /* Q(14-n2) */
+#endif
+ }
+ n2 = 30 - n2 - ( Q_bwe_exc + 6 );
+ pow22 = 1;
+ FOR ( i = 0; i < L_FRAME16k / 4; i++ )
+ {
+#ifdef BASOP_NOGLOB
+ L_tmp = L_mult_o( exc4k_frac[i], exc4k_frac[i], &Overflow); /* Q29 */
+ pow22 = L_add_o( pow22, L_shr( L_tmp, 7 ), &Overflow); /* Q22 */
+#else
+ L_tmp = L_mult( exc4k_frac[i], exc4k_frac[i] ); /* Q29 */
+ pow22 = L_add( pow22, L_shr( L_tmp, 7 ) ); /* Q22 */
+#endif
+ }
+ }
+
+ test();
+ test();
+ IF( EQ_16(coder_type, UNVOICED)||(igf_flag!=0&<_16(avg_voice_fac,6654)))
+ {
+ L_tmp = root_a_over_b_fx( pow1, sub( 22, shl( n1, 1 ) ), pow22, sub( 22, shl( n2, 1 ) ), &exp );
+#ifdef BASOP_NOGLOB
+ scale = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow); /*Q15 */
+#else
+ scale = round_fx( L_shl( L_tmp, exp ) ); /*Q15 */
+#endif
+ sc = sub( add( n2, Q_bwe_exc ), 14 );
+ FOR ( i = 0; i < L_FRAME16k / 4; i++ )
+ {
+#ifdef BASOP_NOGLOB
+ exc4kWhtnd[i] = round_fx_o( L_shl_o( L_mult_o( exc4k_frac[i], scale, &Overflow), sc, &Overflow), &Overflow); /* Q_bwe_exc+n2-10+16+ Q_bwe_exc + n2 -14 -16 = //Q_bwe_exc */
+#else
+ exc4kWhtnd[i] = round_fx( L_shl( L_mult( exc4k_frac[i], scale ), sc ) ); /* Q_bwe_exc+n2-10+16+ Q_bwe_exc + n2 -14 -16 = //Q_bwe_exc */
+#endif
+ }
+ }
+ ELSE
+ {
+ sc = sub( add( n2, Q_bwe_exc ), 14 ); /* Q_bwe_exc+n2-14*/
+
+ k = 0;
+ FOR ( i = 0; i < 4; i++ )
+ {
+ test();
+ IF( igf_flag != 0 && EQ_16(coder_type, VOICED))
+ {
+ /*tmp_vfac = 2*voice_factors[i];
+ tmp_vfac = min(1, tmp_vfac);*/
+#ifdef BASOP_NOGLOB
+ tmp_vfac = shl_o(voice_factors[i], 1, &Overflow);
+#else
+ BASOP_SATURATE_WARNING_OFF_EVS
+ tmp_vfac = shl(voice_factors[i], 1);
+ BASOP_SATURATE_WARNING_ON_EVS
+#endif
+ }
+ ELSE
+ {
+ tmp_vfac = voice_factors[i];
+ move16();
+ }
+
+ Ltemp1 = root_a_fx( L_deposit_h( tmp_vfac ), 31, &exp );
+#ifdef BASOP_NOGLOB
+ temp1 = round_fx_o( L_shl_o( Ltemp1, exp, &Overflow ), &Overflow ); /* Q15 */
+#else
+ temp1 = round_fx( L_shl( Ltemp1, exp ) ); /* Q15 */
+#endif
+ L_tmp = Mult_32_16( pow1, sub( 32767, tmp_vfac ) ); /* Q22*/
+ Ltemp2 = root_a_over_b_fx( L_tmp, sub( 22, shl( n1, 1 ) ), pow22, sub( 22, shl( n2, 1 ) ), &exp );
+#ifdef BASOP_NOGLOB
+ temp2 = round_fx_o( L_shl_o( Ltemp2, exp, &Overflow ), &Overflow ); /* Q15 */
+#else
+ temp2 = round_fx( L_shl( Ltemp2, exp ) ); /* Q15 */
+#endif
+ FOR ( j = 0; j < L_FRAME16k / 16; j++ )
+ {
+#ifdef BASOP_NOGLOB
+ L_tmp = L_mult_o( temp1, exc4kWhtnd[k], &Overflow );/* Q(16+Q_bwe_exc) */
+ L_tmp = L_add_o( L_tmp, L_shl_o( L_mult_o( temp2, exc4k_frac[k], &Overflow), sc, &Overflow), &Overflow); /* Q(16+Q_bwe_exc) */
+ exc4kWhtnd[k] = round_fx_o( L_tmp, &Overflow); /* Q_bwe_exc */
+#else
+ L_tmp = L_mult( temp1, exc4kWhtnd[k] );/* Q(16+Q_bwe_exc) */
+ L_tmp = L_add( L_tmp, L_shl( L_mult( temp2, exc4k_frac[k] ), sc ) ); /* Q(16+Q_bwe_exc) */
+ exc4kWhtnd[k] = round_fx( L_tmp ); /* Q_bwe_exc */
+#endif
+ k++;
+ }
+ }
+ }
+ }
+
+ Syn_filt_s( 0, lpc_shb, LPC_SHB_ORDER_WB, exc4kWhtnd, excSHB, L_FRAME16k / 4, state_lpc_syn, 1 );
+
+
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+* GenWBSynth()
+*
+* Generate 16 KHz sampled highband component from synthesized highband
+*-------------------------------------------------------------------*/
+
+void GenWBSynth_fx(
+ const Word16* input_synspeech, /* i : input synthesized speech Qx*/
+ Word16* shb_syn_speech_16k, /* o : output highband compnent Qx*/
+ Word16* state_lsyn_filt_shb1, /* i/o: memory Qx*/
+ Word16* state_lsyn_filt_shb2 /* i/o: memory Qx*/
+)
+{
+ Word16 speech_buf_16k1[L_FRAME16k], speech_buf_16k2[L_FRAME16k];
+ Word16 i, maxm, nor;
+ Word16 input_synspeech_temp[L_FRAME16k / 4];
+
+ maxm = 0;
+ move16();
+ FOR(i = 0; i 0 && len <= L_FRAME16k);
+
+ K = (int16_t)(len_h / 2); /* length of FIR filter memory = half of the total filter length */
+ w = 1.0f / len_h; /* MA filtering coefficient */
+
+ /* copy filter memory to the input buffer */
+ if (mem_h != NULL)
+ {
+ mvr2r(mem_h, buf_in, K);
+ }
+ else
+ {
+ /* no memory available, use the first len_h/2 samples as memory */
+ p_in = buf_in;
+ for (k = 0; k < K; k++)
+ {
+ *p_in++ = (float)fabs(inp[k]) * w;
+ }
+ }
+
+ /* take the absolute value of the input signal and copy it to the input buffer */
+ /* multiply each value by 1 / filter length */
+ p_in = &buf_in[K];
+ for (k = 0; k < len; k++)
+ {
+ *p_in++ = (float)fabs(inp[k]) * w;
+ }
+
+ /* update filter memory from the end of the input buffer */
+ if (mem_h != NULL)
+ {
+ mvr2r(&buf_in[len], mem_h, K);
+ }
+
+ /* do MA filtering */
+ out[0] = sum_f(buf_in, len_h);
+ p_out = &buf_in[0]; /* pointer to leaving sample */
+ p_in = &buf_in[len_h]; /* pointer to entering sample*/
+ for (k = 1; k < len - K; k++)
+ {
+ out[k] = out[k - 1] - *p_out++ + *p_in++;
+ }
+
+ /* use IIR filtering to extrapolate the last K samples */
+ p_in = &buf_in[len - K];
+ p_out = &out[len - K];
+ p_prev = p_out - 1;
+ for (k = 0; k < K; k++)
+ {
+ *p_out++ = 0.05f * (*p_in++) + 0.95f * (*p_prev++);
+ }
+
+ return;
+}
+#endif
+/*======================================================================================*/
+/* FUNCTION : void GenShapedSHBExcitation_fx () */
+/*--------------------------------------------------------------------------------------*/
+/* PURPOSE : Synthesize spectrally shaped highband excitation signal */
+/*--------------------------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _(Word16) coder_type : coding type Q_bwe_exc */
+/* _(Word16) bwidth : input signal bwidth Q0 */
+/* _(Word16*) bwe_exc_extended :bwidth extended exciatation Q_bwe_exc */
+/* _(Word16[]) voice_factors :voicing factors Q15 */
+/* _(Word16*) lpc_shb :lpc coefficients Q12 */
+/* _(Word16*) Q_bwe_exc :Q Format of bwe_exc_extended */
+/* _(Word16) L_frame : Frame length - determines whether 12.8 or 16kHz core */
+/* _(Word16) last_L_frame : last L_frame */
+/*--------------------------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _(Word16*)excSHB :synthesized shaped shb excitation Q_bwe_exc */
+/* _(Word16*)White_exc16k :white excitation for the Fullband extension Q_bwe_exc */
+/* _(Word16*)slope :slope +ve (high freq > low freq), -ve or neutral Q12 */
+/*--------------------------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _(Word16*)mem_csfilt :memory */
+/* _(Word16*)mem_genSHBexc_filt_down_shb :memory */
+/* _(Word16*)state_lpc_syn :memory */
+/* _(Word16[]) bwe_seed :random number generator seed */
+/* _(Word16[]) lpf_14k_mem :memory */
+/* _(Word32[])Hilbert_Mem :memory */
+/*--------------------------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : */
+/* _ None */
+/*--------------------------------------------------------------------------------------*/
+/* CALLED FROM : RX */
+/*======================================================================================*/
+void GenShapedSHBExcitation_fx(
+ Word16 *excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/
+ const Word16 *lpc_shb, /* i : lpc coefficients Q12*/
+ Word16 *White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc */
+ Word32 *mem_csfilt, /* i/o: memory */
+ Word16 *mem_genSHBexc_filt_down_shb, /* i/o: memory */
+ Word16 *state_lpc_syn, /* i/o: memory */
+ const Word16 coder_type, /* i : coding type */
+ const Word16 *bwe_exc_extended, /* i : bwidth extended excitation */
+ Word16 bwe_seed[], /* i/o: random number generator seed */
+ Word16 voice_factors[], /* i : voicing factor*/
+ const Word16 extl, /* i : extension layer */
+ Word16 *tbe_demph, /* i/o: de-emphasis memory */
+ Word16 *tbe_premph, /* i/o: pre-emphasis memory */
+ Word16 *lpc_shb_sf, /* i: LP coefficients */
+ const Word32 shb_ener_sf_32, /* i: input shb ener, Q31 */
+ Word16 *shb_res_gshape, /* i: input res gain shape, Q14 */
+ Word16 *shb_res,
+ Word16 *vf_ind,
+ const Word16 formant_fac, /* i : Formant sharpening factor [0..1] */
+ Word16 fb_state_lpc_syn[], /* i/o: memory */
+ Word16 *fb_tbe_demph, /* i/o: fb de-emphasis memory */
+ Word16 *Q_bwe_exc,
+ Word16 *Q_bwe_exc_fb,
+ const Word16 Q_shb,
+ Word16 n_mem2, /* i : n_mem2 scale factor to adjust 24.4/32kbps memories */
+ Word16 prev_Q_bwe_syn, /* i : st_fx->prev_Q_bwe_syn */
+ const Word32 bitrate,
+ const Word16 prev_bfi
+#ifdef ADD_IVAS_TBE_CODE
+ , /* i : previous frame was concealed */
+ const Word16 element_mode, /* i : element mode */
+ const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */
+ Word16* nlExc16k, /* i/o: NL exc for IC-BWE */
+ Word16* mixExc16k, /* i/o: exc spreading for IC-BWE */
+ const Word32 extl_brate, /* i : extension layer bitarte */
+ const Word16 MSFlag, /* i : Multi Source flag */
+ Word16 EnvSHBres_4k[], /* i/o: TD envelope of the SHB residual signal */
+ Word16* prev_pow_exc16kWhtnd, /* i/o: power of the LB excitation signal in the previous frame */
+ Word16* prev_mix_factor, /* i/o: mixing factor in the previous frame */
+ Word16* Env_error, /* o : error in SHB residual envelope modelling*/
+ Word16 Env_error_part[] /* o : per-segment error in SHB residual envelope modelling */
+#endif
+)
+{
+ Word16 i, j, k;
+ Word16 wht_fil_mem[LPC_WHTN_ORDER];
+ Word16 lpc_whtn[LPC_WHTN_ORDER + 1];
+ Word16 R_h[LPC_WHTN_ORDER+ 2]; /* Autocorrelations of windowed speech MSB */
+ Word16 R_l[LPC_WHTN_ORDER+ 2]; /* Autocorrelations of windowed speech LSB */
+ Word16 Q_R;
+ Word32 LepsP[LPC_WHTN_ORDER+1];
+ Word16 exc32k[L_FRAME32k], exc16k[L_FRAME16k];
+ Word32 pow1, pow22;
+ Word16 scale, temp1, temp2;
+
+ Word16 excTmp2[L_FRAME16k];
+ Word16 *White_exc16k;
+ Word16 excNoisyEnv[L_FRAME16k];
+ Word16 csfilt_num2[1] = {6554}; /*0.2 in Q15 */
+ Word16 neg_csfilt_den2[2] = {-32767, 26214}; /* {1.0f, -0.8f} */
+ Word16 varEnvShape;
+ Word16 fb_deemph_fac = 15729; /*0.48f in Q15 */
+ Word16 exc16kWhtnd[L_FRAME16k];
+
+ Word32 L_tmp;
+ Word16 vf_tmp;
+ Word16 tmp, exp, tmp2;
+ Word16 voiceFacEst[NB_SUBFR16k];
+ Word16 zero_mem[LPC_SHB_ORDER];
+ Word32 syn_shb_ener_sf[4];
+ Word16 tempSHB[80];
+ Word16 Q_pow1, Q_pow22;
+
+ Word32 L_tmp2, L_tmp3, L_tmp4;
+ Word16 temp;
+
+ Word16 White_exc16k_FB_temp[L_FRAME16k];
+ Word32 White_exc16k_32[L_FRAME16k];
+ Word16 Q_temp;
+ Word16 prev_Q_bwe_exc_fb;
+
+#ifdef ADD_IVAS_TBE_CODE
+ Word32 tempD;
+ Word16 alpha, step, mem_csfilt_left, mem_csfilt_right, excNoisyEnvLeft[L_FRAME16k], excNoisyEnvRight[L_FRAME16k];
+ Word16 cbsize;
+ Word16 mix_factor, old_fact, new_fact, fact, old_scale, new_scale, step_scale;
+ Word16 c0, c1, c2, c3, c4, c5, g1, g2, g, den;
+ Word16 EnvWhiteExc16k[L_FRAME16k], EnvExc16kWhtnd[L_FRAME16k];
+ Word16 EnvWhiteExc16k_4k[L_FRAME4k] = { 0 }, EnvExc16kWhtnd_4k[L_FRAME4k] = { 0 };
+ Word16 flag_plosive;
+ Word16 delta;
+ Word16 c0_part[NUM_SHB_SUBGAINS], c1_part[NUM_SHB_SUBGAINS], c2_part[NUM_SHB_SUBGAINS], c3_part[NUM_SHB_SUBGAINS], c4_part[NUM_SHB_SUBGAINS], c5_part[NUM_SHB_SUBGAINS];
+
+ mix_factor = 0.0f;
+#endif
+ set16_fx( zero_mem, 0, LPC_SHB_ORDER );
+ set16_fx( wht_fil_mem, 0, LPC_WHTN_ORDER );
+
+ FOR(i = 0; i < L_FRAME32k; i=i+2)
+ {
+ exc32k[i] = negate(bwe_exc_extended[i]);
+ move16();
+ exc32k[i+1] = bwe_exc_extended[i+1];
+ move16();
+ }
+
+ /* Decimate by 2 */
+ Decimate_allpass_steep_fx( exc32k, mem_genSHBexc_filt_down_shb, 2*L_FRAME16k, exc16k );
+ /* i: exc32k in Q_bwe_exc */
+ /* o: exc16k in Q_bwe_exc */
+
+ autocorr_fx( exc16k, LPC_WHTN_ORDER + 1, R_h, R_l, &Q_R, L_FRAME16k, win_flatten_fx, 0, 1 );
+ /* Ensure R[0] isn't zero when entering Levinson Durbin */
+ R_l[0] = s_max( R_l[0], 1 );
+ move16();
+ FOR ( i = 1; i <= LPC_WHTN_ORDER; i++ )
+ {
+ L_tmp = Mpy_32( R_h[i], R_l[i], wac_h[i - 1], wac_l[i - 1] );
+ L_Extract( L_tmp, &R_h[i], &R_l[i] );
+ }
+ E_LPC_lev_dur(R_h, R_l, lpc_whtn, LepsP, LPC_WHTN_ORDER, NULL);
+ Copy_Scale_sig( lpc_whtn, lpc_whtn, LPC_WHTN_ORDER+1, sub(norm_s(lpc_whtn[0]),2) );
+ fir_fx( exc16k, lpc_whtn, exc16kWhtnd, wht_fil_mem, L_FRAME16k, LPC_WHTN_ORDER, 0, 3 );
+
+ /* i: exc16k in Q_bwe_exc */
+ /* o: exc16kWhtnd in Q_bwe_exc */
+
+#ifdef ADD_IVAS_TBE_CODE
+ IF(GE_32(extl_brate, SWB_TBE_2k8))
+#else
+ IF(GE_32(bitrate, ACELP_24k40))
+#endif
+ {
+ temp2 = 0;
+ move16();
+ FOR(j = 0; j < 4; j++)
+ {
+ temp1 = shb_res_gshape[j];
+ move16();
+ FOR(i = 0; i < 80; i++)
+ {
+ exc16kWhtnd[temp2 + i] = round_fx(L_shl(L_mult( exc16kWhtnd[temp2 + i], temp1 ), 1));
+ /* exc16kWhtnd in Q_bwe_exc, shb_res_gshape in Q14 */
+ }
+ temp2 = add(temp2, 80);
+ }
+ }
+
+ /* Estimate pow1 associated with Low band nonlinear extended excitation */
+ /* pow1=0.00001f */
+ tmp = sub(shl(*Q_bwe_exc, 1), 31);
+#ifdef BASOP_NOGLOB
+ pow1 = L_shl_sat(21475l/*0.00001f Q31*/, tmp); /* 0.00001f in 2*(Q_bwe_exc) */
+#else
+ pow1 = L_shl(21475l/*0.00001f Q31*/, tmp); /* 0.00001f in 2*(Q_bwe_exc) */
+#endif
+ FOR( k = 0; k < L_FRAME16k; k++)
+ {
+ /*excTmp2[k ] = (float)(fabs(exc16kWhtnd[k]));*/
+ excTmp2[k] = abs_s( exc16kWhtnd[k] );
+ move16();
+
+ /* pow1 += exc16kWhtnd[k] * exc16kWhtnd[k]; */
+#ifdef BASOP_NOGLOB
+ pow1 = L_mac0_sat( pow1, exc16kWhtnd[k], exc16kWhtnd[k] ); /* 2*Q_bwe_exc */
+#else
+ pow1 = L_mac0( pow1, exc16kWhtnd[k], exc16kWhtnd[k] ); /* 2*Q_bwe_exc */
+#endif
+ }
+ Q_pow1 = shl(*Q_bwe_exc,1);
+
+ test();
+#ifdef ADD_IVAS_TBE_CODE
+ IF(EQ_16(flag_ACELP16k,0))
+#else
+ IF( (LE_32( bitrate, ACELP_13k20 ))&&(GE_32(bitrate,ACELP_7k20)))
+#endif
+ {
+ /* varEnvShape = mean_fx(voice_factors, 4); */
+ /* unroll the loop */
+ L_tmp = L_mult(voice_factors[0], 8192);
+ L_tmp = L_mac(L_tmp, voice_factors[1], 8192 );
+ L_tmp = L_mac(L_tmp, voice_factors[2], 8192 );
+ varEnvShape = mac_r(L_tmp, voice_factors[3], 8192 ); /* varEnvShape in Q15 */
+ }
+ ELSE /* 16k core */
+ {
+ /* varEnvShape = mean_fx(voice_factors, 5); */
+ /* unroll the loop */
+ L_tmp = L_mult(voice_factors[0], 6554);
+ L_tmp = L_mac(L_tmp, voice_factors[1], 6554 );
+ L_tmp = L_mac(L_tmp, voice_factors[2], 6554 );
+ L_tmp = L_mac(L_tmp, voice_factors[3], 6554 );
+ varEnvShape = mac_r(L_tmp, voice_factors[4], 6554 ); /* varEnvShape in Q15 */
+ }
+
+ IF ( EQ_16(extl, FB_TBE))
+ {
+ /*pow(varEnvShape,3) */
+ tmp = mult_r(varEnvShape, varEnvShape);
+ tmp = mult_r(tmp, varEnvShape);
+
+ /* max_val((0.68f - (float)pow(varEnvShape, 3)), 0.48f); */
+ fb_deemph_fac = sub(22282/*0.68f Q15*/, tmp);
+ fb_deemph_fac = s_max(fb_deemph_fac, 15729/*0.48f Q15*/);
+ }
+
+ /*varEnvShape = 1.09875f - 0.49875f * varEnvShape; */
+ varEnvShape = msu_r(1179773824l/*0.549375f Q31*/, 8172/*0.249375f Q15*/, varEnvShape);
+
+ /*varEnvShape = min( max_val(varEnvShape, 0.6f), 0.999f); */
+ varEnvShape = s_max(varEnvShape, 9830/*0.3f Q15*/);
+ varEnvShape = s_min(varEnvShape, 16368/*0.4995f Q15*/);
+ varEnvShape = shl(varEnvShape, 1);
+ csfilt_num2[0] = sub(MAX_16, varEnvShape);
+ move16();
+ neg_csfilt_den2[1] = varEnvShape;
+ move16();
+
+ test();
+ test();
+ test();
+#ifdef ADD_IVAS_TBE_CODE
+ IF (EQ_16(element_mode, EVS_MONO) && *mem_csfilt == 0 && ( (EQ_32( bitrate, ACELP_9k60 ))||(EQ_32(bitrate,ACELP_16k40))||(EQ_32(bitrate,ACELP_24k40))))
+#else
+ IF ( *mem_csfilt == 0 && ( (EQ_32( bitrate, ACELP_9k60 ))||(EQ_32(bitrate,ACELP_16k40))||(EQ_32(bitrate,ACELP_24k40))))
+#endif
+ {
+ /* pre-init smoothing filter to avoid energy drop outs */
+ L_tmp = L_mult(excTmp2[0], 1638);
+ FOR (i = 1; i < L_SUBFR16k/4; i++)
+ {
+ L_tmp = L_mac(L_tmp, excTmp2[i], 1638); /*1638 = 1/20 in Q15*/
+ }
+ /*L_tmp = sum(excTmp2, L_SUBFR16k/4)*(1/20) where L_SUBFR16k/4 =20 */
+
+ /* don't apply for FB in case the FB start-frame was potentially lost - White_exc16k is very sensitive to enery mismatch between enc - dec */
+ /* rather stick to the more conservative approach, to avoid potential clippings */
+ test();
+ IF( !(prev_bfi && EQ_16(extl, FB_TBE)))
+ {
+ /* use weak smoothing for 1st frame after switching to make filter recover more quickly */
+ varEnvShape = 26214/*0.8f Q15*/;
+ move16();
+ csfilt_num2[0] = sub(MAX_16, varEnvShape);
+ move16();
+ neg_csfilt_den2[1] = varEnvShape;
+ move16();
+ }
+
+ *mem_csfilt = Mult_32_16( L_tmp, varEnvShape );
+ move32();
+ }
+#ifdef ADD_IVAS_TBE_CODE
+ if (MSFlag > 0)
+ {
+ varEnvShape = 0.995f;
+ csfilt_num2[0] = 1.0f - varEnvShape;
+ csfilt_den2[1] = -varEnvShape;
+ }
+
+ White_exc16k = exc16k;
+
+ /* Track the low band envelope */
+ if (element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_DFT)
+ {
+ if (extl_brate != SWB_TBE_1k10 && extl_brate != SWB_TBE_1k75)
+ {
+ mem_csfilt_left = 0.0f;
+ mem_csfilt_right = 0.0f;
+ for (k = 0; k < L_FRAME16k; k++)
+ {
+ excNoisyEnvLeft[k] = mem_csfilt_left + csfilt_num2[0] * excTmp2[k];
+ mem_csfilt_left = -csfilt_den2[1] * excNoisyEnvLeft[k];
+ excNoisyEnvRight[L_FRAME16k - k - 1] = mem_csfilt_right + csfilt_num2[0] * excTmp2[L_FRAME16k - k - 1];
+ mem_csfilt_right = -csfilt_den2[1] * excNoisyEnvRight[L_FRAME16k - k - 1];
+ }
+
+ alpha = 0.0f;
+ step = 1.0f / L_FRAME16k;
+ for (k = 0; k < L_FRAME16k; k++)
+ {
+ excNoisyEnv[k] = alpha * excNoisyEnvLeft[k] + (1 - alpha) * excNoisyEnvRight[k];
+ alpha += step;
+ }
+ }
+ }
+ else
+#endif
+ {
+ /* Track the low band envelope */
+ L_tmp = *mem_csfilt;
+ move32();
+ FOR(i = 0; i < L_FRAME16k; i++)
+ {
+ excNoisyEnv[i] = mac_r(L_tmp, csfilt_num2[0], excTmp2[i]);
+ move16();
+ /* excNoisyEnv : Q_bwe_exc,
+ *mem_csfilt: Q_bwe_exc+16, excTmp2: Q_bwe_exc, csfilt_num2[0] Q15 */
+ L_tmp = L_mult(excNoisyEnv[i], neg_csfilt_den2[1]); /* Q_bwe_exc+16 */
+ }
+ *mem_csfilt = L_tmp;
+ move32();
+ }
+#ifdef ADD_IVAS_TBE_CODE
+ if (extl_brate == SWB_TBE_1k10 || extl_brate == SWB_TBE_1k75)
+ {
+ /* generate gaussian (white) excitation */
+ for (k = 0; k < L_FRAME16k; k++)
+ {
+ White_exc16k[k] = (float)own_random(&bwe_seed[0]);
+ }
+
+ /* normalize the amplitude of the gaussian excitation to that of the LB exc. */
+ pow22 = POW_EXC16k_WHTND;
+ v_multc(White_exc16k, (float)sqrt(pow1 / pow22), White_exc16k, L_FRAME16k);
+ }
+ else
+#endif
+ {
+ /* create a random excitation - Reuse exc16k memory */
+ White_exc16k = exc16k;
+ create_random_vector_fx(White_exc16k, L_FRAME, bwe_seed);
+ create_random_vector_fx(White_exc16k + L_FRAME, L_FRAME16k - L_FRAME, bwe_seed);
+
+ L_tmp = L_deposit_l(0);
+ tmp = add(*Q_bwe_exc, 1);
+ FOR(k = 0; k < L_FRAME16k; k++)
+ {
+#ifdef BASOP_NOGLOB
+ L_tmp4 = L_shl_sat(L_deposit_l(White_exc16k[k]), tmp);
+#else
+ L_tmp4 = L_shl(L_deposit_l(White_exc16k[k]), tmp);
+#endif
+ if (excNoisyEnv[k] != 0)
+ {
+ L_tmp4 = L_mult(excNoisyEnv[k], White_exc16k[k]);/* (Q_bwe_exc) +5 +1*/
+ }
+ White_exc16k_32[k] = L_tmp4;
+ move32();
+ L_tmp = L_max(L_tmp, L_abs(White_exc16k_32[k]));
+ }
+ Q_temp = norm_l(L_tmp);
+ if (L_tmp == 0)
+ {
+ Q_temp = 31;
+ }
+ /*Copy_Scale_sig( White_exc16k, White_exc16k, L_FRAME16k, sub(NOISE_QFAC, 5) );)*/
+ /* White_exc16k in Q6 */
+
+ /* calculate pow22 */
+ /* pow22=0.00001f */
+ tmp = sub(shl(sub(*Q_bwe_exc, NOISE_QADJ), 1), 31);
+ pow22 = L_shl(21475l/*0.00001f Q31*/, tmp); /* 0.00001f in 2*(Q_bwe_exc-NOISE_QADJ) */
+ tmp = sub(NOISE_QFAC, 5);
+ FOR(k = 0; k < L_FRAME16k; k++)
+ {
+ /* White_exc16k[k] *= excNoisyEnv[k]; */
+ White_exc16k[k] = mult_r(excNoisyEnv[k], shl(White_exc16k[k], tmp));
+ move16();
+ /* i: excNoisyEnv in (Q_bwe_exc) */
+ /* i: White_exc16k in Q6 */
+ /* o: White_exc16k in (Q_bwe_exc-NOISE_QADJ) */
+ /* pow22 += White_exc16k[k] * White_exc16k[k]; */
+#ifdef BASOP_NOGLOB
+ pow22 = L_mac0_sat(pow22, White_exc16k[k], White_exc16k[k]); /* 2*(Q_bwe_exc-NOISE_QADJ)*/
+#else
+ pow22 = L_mac0(pow22, White_exc16k[k], White_exc16k[k]); /* 2*(Q_bwe_exc-NOISE_QADJ)*/
+#endif
+ }
+ /*Q_pow22 = sub( shl(*Q_bwe_exc,1), 18 );*/
+ Q_pow22 = shl(sub(*Q_bwe_exc, NOISE_QADJ), 1);
+ }
+
+#ifdef ADD_IVAS_TBE_CODE
+ flag_plosive = 0;
+ move16();
+ test(); test(); test();
+ IF(GE_32(extl_brate, SWB_TBE_2k8) || EQ_32(extl_brate, SWB_TBE_1k10) || EQ_32(extl_brate, SWB_TBE_1k75)))
+#else
+ IF( GE_32(bitrate, ACELP_24k40))
+#endif
+ {
+ IF( EQ_16(*vf_ind,20)) /* encoder side */
+ {
+#ifdef ADD_IVAS_TBE_CODE
+ if (extl_brate == SWB_TBE_1k10 || extl_brate == SWB_TBE_1k75)
+ {
+ /* calculate TD envelopes of exc16kWhtnd and White_exc16k */
+ find_td_envelope(White_exc16k, L_FRAME16k, 20, NULL, EnvWhiteExc16k);
+ find_td_envelope(exc16kWhtnd, L_FRAME16k, 20, NULL, EnvExc16kWhtnd);
+
+ for (k = 0; k < L_FRAME4k; k++)
+ {
+ EnvWhiteExc16k_4k[k] = EnvWhiteExc16k[4 * k];
+ EnvExc16kWhtnd_4k[k] = EnvExc16kWhtnd[4 * k];
+ }
+
+ /* calculate the optimal mix factor */
+ c0 = c1 = c2 = c3 = c4 = c5 = 0.0f;
+ for (i = 0; i < NUM_SHB_SUBGAINS; i++)
+ {
+ c0_part[i] = sum2_f(&EnvExc16kWhtnd_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS);
+ c1_part[i] = -2.0f * dotp(&EnvSHBres_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], &EnvExc16kWhtnd_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS);
+ c2_part[i] = sum2_f(&EnvWhiteExc16k_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS);
+ c3_part[i] = -2.0f * dotp(&EnvSHBres_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], &EnvWhiteExc16k_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS);
+ c4_part[i] = 2.0f * dotp(&EnvExc16kWhtnd_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], &EnvWhiteExc16k_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS);
+ c5_part[i] = sum2_f(&EnvSHBres_4k[i * L_FRAME4k / NUM_SHB_SUBGAINS], L_FRAME4k / NUM_SHB_SUBGAINS);
+
+ c0 += c0_part[i];
+ c1 += c1_part[i];
+ c2 += c2_part[i];
+ c3 += c3_part[i];
+ c4 += c4_part[i];
+ c5 += c5_part[i];
+ }
+
+ den = 4.0f * c0 * c2 - c4 * c4;
+ g1 = (c3 * c4 - 2 * c1 * c2) / den;
+ g2 = (c1 * c4 - 2 * c0 * c3) / den;
+
+ *Env_error = 0.0f;
+ flag_plosive = 0;
+ for (i = 0; i < NUM_SHB_SUBGAINS; i++)
+ {
+ Env_error_part[i] = c5_part[i] + g1 * g1 * c0_part[i] + g1 * c1_part[i] + g2 * g2 * c2_part[i] + g2 * c3_part[i] + g1 * g2 * c4_part[i];
+ *Env_error += Env_error_part[i];
+
+ if (Env_error_part[i] > THR_ENV_ERROR_PLOSIVE)
+ {
+ /* envelope error is too high -> likely a plosive */
+ flag_plosive = 1;
+ }
+ }
+
+ if (flag_plosive)
+ {
+ /* plosive detected -> set the mixing factor to 0 */
+ *vf_ind = 0;
+ mix_factor = 0.0f;
+ }
+ else
+ {
+ /* normalize gain */
+ g = g2 / (g1 + g2);
+
+ /* quantization of the mixing factor */
+ cbsize = 1 << NUM_BITS_SHB_VF;
+ delta = 1.0f / (cbsize - 1);
+ if (g > 1.0f)
+ {
+ g = 1.0f;
+ }
+ else if (g < delta)
+ {
+ /* prevent low gains to be quantized to 0 as this is reserved for plosives */
+ g = delta;
+ }
+
+ *vf_ind = usquant(g, &mix_factor, 0.0f, 1.0f / (cbsize - 1), cbsize);
+ }
+ }
+ else
+#endif
+ {
+ Estimate_mix_factors_fx(shb_res, Q_shb, exc16kWhtnd, *Q_bwe_exc, White_exc16k,
+ (*Q_bwe_exc - NOISE_QADJ), pow1, Q_pow1, pow22, Q_pow22, voiceFacEst, vf_ind);
+ tmp = voiceFacEst[0];
+ tmp2 = MAX_16;
+ if (LE_16(tmp, 22938/*0.7f Q15*/))
+ {
+ tmp2 = 26214/*0.8f Q15*/;
+ }
+ }
+ }
+ ELSE /* decoder side */
+ {
+#ifdef ADD_IVAS_TBE_CODE
+ if (extl_brate == SWB_TBE_1k10 || extl_brate == SWB_TBE_1k75)
+ {
+ if (*vf_ind == 0)
+ {
+ mix_factor = 0.0f;
+ flag_plosive = 1;
+ }
+ else
+ {
+ mix_factor = usdequant(*vf_ind, 0.0f, 1.0f / ((1 << NUM_BITS_SHB_VF) - 1));
+ }
+ }
+ else
+#endif
+ {
+ /* *vf_ind is an integer scale by 0.125f*/
+ tmp = shl(*vf_ind, (15 - 3));
+ tmp2 = MAX_16;
+ if( LE_16(tmp, 22938/*0.7f Q15*/))
+ {
+ tmp2 = 26214/*0.8f Q15*/;
+ }
+ }
+ }
+#ifdef ADD_IVAS_TBE_CODE
+ IF (NE_32(extl_brate, SWB_TBE_1k10) && NE_32(extl_brate, SWB_TBE_1k75) )
+#endif
+ {
+ voice_factors[0] = mult_r(voice_factors[0], tmp2);
+ move16();
+ voice_factors[1] = mult_r(voice_factors[1], tmp2);
+ move16();
+ voice_factors[2] = mult_r(voice_factors[2], tmp2);
+ move16();
+ voice_factors[3] = mult_r(voice_factors[3], tmp2);
+ move16();
+ voice_factors[4] = mult_r(voice_factors[4], tmp2);
+ move16();
+ }
+ }
+#ifdef ADD_IVAS_TBE_CODE
+ if (element_mode >= IVAS_CPE_DFT && nlExc16k != NULL)
+ {
+ /* save buffers for IC-BWE */
+ mvr2r(exc16kWhtnd, nlExc16k, L_FRAME16k);
+ v_multc(White_exc16k, (float)sqrt(pow1 / pow22), mixExc16k, L_FRAME16k);
+ }
+#endif
+
+ tmp = sub(Q_temp, 3);
+ FOR ( k = 0; k < L_FRAME16k; k++ )
+ {
+ White_exc16k_FB[k] = round_fx(L_shl(White_exc16k_32[k], tmp)); /* Q_bwe_exc +5 +1 +Q_temp -16 -3 */
+ }
+ prev_Q_bwe_exc_fb = *Q_bwe_exc_fb;
+ *Q_bwe_exc_fb = sub(add(*Q_bwe_exc, Q_temp), 13);
+
+ deemph_fx( White_exc16k, PREEMPH_FAC, L_FRAME16k, tbe_demph );
+ /* i/o: White_exc16k (Q_bwe_exc-NOISE_QADJ) */
+ /* i: tbe_demph (Q_bwe_exc-NOISE_QADJ) */
+#ifdef ADD_IVAS_TBE_CODE
+ if (extl_brate == SWB_TBE_1k10 || extl_brate == SWB_TBE_1k75)
+ {
+ if (!flag_plosive) /* use only LB excitation in case of plosives */
+ {
+ /* re-scale gaussian excitation at the beginning to gradually move from old energy to new energy */
+ old_scale = (float)sqrt(*prev_pow_exc16kWhtnd / pow1);
+ new_scale = 1.0f;
+ step_scale = (new_scale - old_scale) / (L_FRAME16k / 2);
+ scale = old_scale;
+
+ /* interpolate between the old and the new value of the mixing factor */
+ old_fact = *prev_mix_factor;
+ new_fact = mix_factor;
+ step = (new_fact - old_fact) / (L_FRAME16k / 2);
+ fact = old_fact;
+
+ /* mixing of LB and gaussian excitation in the first half of the frame */
+ for (k = 0; k < L_FRAME16k / 2; k++)
+ {
+ exc16kWhtnd[k] = (float)fact * (White_exc16k[k] * scale) + (float)(1 - fact) * exc16kWhtnd[k];
+ fact += step;
+ scale += step_scale;
+ }
+
+ /* mixing of LB and gaussian excitation in the second half of the frame */
+ for (; k < L_FRAME16k; k++)
+ {
+ exc16kWhtnd[k] = (float)new_fact * White_exc16k[k] + (float)(1 - new_fact) * exc16kWhtnd[k];
+ }
+ }
+ preemph(exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph);
+ }
+ else
+#endif
+ {
+#ifdef ADD_IVAS_TBE_CODE
+ if (coder_type == UNVOICED || MSFlag == 1)
+#else
+ IF(EQ_16(coder_type, UNVOICED))
+#endif
+ {
+ L_tmp = root_a_over_b_fx(pow1, Q_pow1, pow22, Q_pow22, &exp);
+ scale = round_fx(L_shl(L_tmp, exp)); /*Q15 */
+
+ FOR(k = 0; k < L_FRAME16k; k++)
+ {
+ /* White_exc16k: (Q_bwe_exc-NOISE_QADJ), scale: Q15 */
+ L_tmp = L_mult(White_exc16k[k], scale);
+ /* L_tmp: (Q_bwe_exc-NOISE_QADJ) + 15 + 1 */
+ exc16kWhtnd[k] = round_fx(L_shl(L_tmp, NOISE_QADJ));
+ /* exc16kWhtnd: Q_bwe_exc */
+ }
+ preemph_fx(exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph);
+ /* i/o: exc16kWhtnd (Q_bwe_exc) */
+ /* i/o: tbe_premph (Q_bwe_exc) */
+ }
+ ELSE
+ {
+ Word16 nbSubFr, lSubFr;
+ Word16 tempQ15;
+ Word32 tempQ31;
+ /*nbSubFr = ( bitrate < ACELP_24k40 )? NB_SUBFR : NB_SUBFR16k;*/
+ nbSubFr = NB_SUBFR16k;
+ lSubFr = (L_FRAME16k / NB_SUBFR16k);
+ IF(LT_32(bitrate, ACELP_24k40))
+ {
+ nbSubFr = NB_SUBFR;
+ move16();
+ lSubFr = (L_FRAME16k / NB_SUBFR);
+ move16();
+ }
+ k = 0;
+ FOR(i = 0; i < nbSubFr; i++)
+ {
+ test();
+ IF(EQ_16(coder_type, VOICED) && (LT_32(bitrate,ACELP_24k40)))
+ {
+ exp = 0;
+ tempQ15 = Sqrt16(voice_factors[i], &exp); /* Q15 */
+ temp = shl(tempQ15, exp); /* Q15 exc16kWhtnd scale factor */
+ exp = 0;
+ tempQ15 = Sqrt16(temp, &exp); /* Q15 */
+ temp1 = shl(tempQ15, exp); /* Q15 exc16kWhtnd scale factor */
+
+ /*temp2 = root_a_over_b_fx( pow1 * (1.0f - temp), pow22 ); */
+ temp = sub(MAX_16, temp);
+ tempQ31 = Mult_32_16(pow1, temp);
+ L_tmp = root_a_over_b_fx(tempQ31, Q_pow1, pow22, Q_pow22, &exp);
+#ifdef BASOP_NOGLOB
+ temp2 = round_fx_sat(L_shl_sat(L_tmp, exp)); /* Q15 whiteEnvShapedExc scale factor */
+#else
+ temp2 = round_fx(L_shl(L_tmp, exp)); /* Q15 whiteEnvShapedExc scale factor */
+#endif
+ }
+ ELSE
+ {
+ /* Adjust noise mixing for formant sharpening filter */
+ tempQ15 = mult_r(SWB_NOISE_MIX_FAC_FX, formant_fac);
+ /* vf_tmp = voice_factors[i] * (1.0f - vf_tmp); */
+ vf_tmp = sub(MAX_16, tempQ15);
+ vf_tmp = mult_r(voice_factors[i], vf_tmp);
+
+ exp = 0;
+ tempQ15 = Sqrt16(vf_tmp, &exp); /* Q15 */
+ temp1 = shl(tempQ15, exp); /* Q15 exc16kWhtnd scale factor */
+
+ /*temp2 = root_a_over_b(pow1 * (1.0f - vf_tmp), pow22); */
+ temp = sub(MAX_16, vf_tmp);
+ tempQ31 = Mult_32_16(pow1, temp);
+ L_tmp = root_a_over_b_fx(tempQ31, Q_pow1, pow22, Q_pow22, &exp);
+#ifdef BASOP_NOGLOB
+ temp2 = round_fx_sat(L_shl_sat(L_tmp, exp)); /* Q15 whiteEnvShapedExc scale factor */
+#else
+ temp2 = round_fx(L_shl(L_tmp, exp)); /* Q15 whiteEnvShapedExc scale factor */
+#endif
+ }
+
+ FOR(j = 0; j < lSubFr; j++)
+ {
+ /*exc16kWhtnd[k+j] = temp1 * exc16kWhtnd[k+j] + temp2 * White_exc16k[k+j]; */
+ L_tmp = L_mult(temp2, White_exc16k[k + j]); /* 16+(Q_bwe_exc-NOISE_QADJ)*/
+#ifdef BASOP_NOGLOB
+ L_tmp = L_shl_sat(L_tmp, NOISE_QADJ); /* 16+(Q_bwe_exc) */
+ exc16kWhtnd[k + j] = mac_r_sat(L_tmp, temp1, exc16kWhtnd[k + j]);
+#else
+ L_tmp = L_shl(L_tmp, NOISE_QADJ); /* 16+(Q_bwe_exc) */
+ exc16kWhtnd[k + j] = mac_r(L_tmp, temp1, exc16kWhtnd[k + j]);
+#endif
+ move16();
+ /* Q_bwe_exc */
+ }
+ k = add(k, lSubFr);
+
+ /* estimate the pre-emph factor */
+ tempQ15 = sub(MAX_16, voice_factors[i]);
+ exp = 0;
+ temp = Sqrt16(tempQ15, &exp);
+ temp = shl(temp, exp - 1);
+
+ temp2 = add(temp, shl(temp1, -1)); /* shift right by 1 to avoid overflow */
+ temp = div_s(temp, temp2); /* Q15 */
+ temp = mult_r(PREEMPH_FAC, temp);
+
+ preemph_fx(&exc16kWhtnd[i * lSubFr], temp, lSubFr, tbe_premph);
+ /* exc16kWhtnd: Q_bwe_exc;
+ tbe_premph: Q_bwe_exc*/
+ }
+ }
+ }
+
+#ifdef ADD_IVAS_TBE_CODE
+ IF ( LT_32(extl_brate, SWB_TBE_2k8))
+#else
+ IF ( LT_32(bitrate, ACELP_24k40))
+#endif
+ {
+ Syn_filt_s(0, lpc_shb, LPC_SHB_ORDER, exc16kWhtnd, excSHB, L_FRAME16k, state_lpc_syn, 1 );
+ /* i: exc16kWhtnd in Q_bwe_exc */
+ /* o: excSHB in Q_bwe_exc */
+ }
+ ELSE
+ {
+ set16_fx( zero_mem, 0, LPC_SHB_ORDER);
+
+ Syn_filt_s(0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, tempSHB, 80, zero_mem, 1);
+ syn_shb_ener_sf[0] = L_shr(sum2_fx(tempSHB, 80),3);
+ move32();
+
+ Syn_filt_s(0, lpc_shb_sf+(LPC_SHB_ORDER+1), LPC_SHB_ORDER, exc16kWhtnd+ 80, tempSHB, 80, zero_mem, 1 );
+ syn_shb_ener_sf[1] = L_shr(sum2_fx(tempSHB, 80),3);
+ move32();
+
+ Syn_filt_s(0, lpc_shb_sf+2*(LPC_SHB_ORDER+1), LPC_SHB_ORDER, exc16kWhtnd+160, tempSHB, 80, zero_mem, 1 );
+ syn_shb_ener_sf[2] = L_shr(sum2_fx(tempSHB, 80),3);
+ move32();
+
+ Syn_filt_s(0, lpc_shb_sf+3*(LPC_SHB_ORDER+1), LPC_SHB_ORDER, exc16kWhtnd+240, tempSHB, 80, zero_mem, 1 );
+ syn_shb_ener_sf[3] = L_shr(sum2_fx(tempSHB, 80),3);
+ move32();
+
+ /* i: exc16kWhtnd in Q_bwe_exc */
+ /* o: tempSHB in Q_bwe_exc */
+ /* o: syn_shb_ener_sf in (2*Q_bwe_exc+1) */
+ IF(LE_32(bitrate,ACELP_32k))
+ {
+ L_tmp = sum32_fx(syn_shb_ener_sf, 4);
+
+ /* find root_a(tempSHB[0]) = root_a_over_b(shb_ener_sf[0]), L_tmp) */
+ tmp = shl(Q_shb, 1);
+ tmp2 = add(shl(*Q_bwe_exc, 1), 1);
+ L_tmp2 = root_a_over_b_fx(shb_ener_sf_32, tmp, L_tmp, tmp2, &exp); /* L_tmp2 in (Q31-exp) */
+
+ *Q_bwe_exc = sub(*Q_bwe_exc, exp);
+ move16(); /* compensate for the exp shift */
+ tmp2 = add( prev_Q_bwe_syn, n_mem2 );
+ IF( GT_16( *Q_bwe_exc, tmp2))
+ {
+ L_tmp2 = L_shl(L_tmp2, sub(tmp2, *Q_bwe_exc));
+ *Q_bwe_exc = tmp2;
+ move16();
+ }
+ FOR(i = 0; i < L_FRAME16k; i++)
+ {
+ L_tmp3 = Mult_32_16(L_tmp2, exc16kWhtnd[i]); /* *Q_bwe_exc + (31-exp) - 15 */
+ exc16kWhtnd[i] = round_fx(L_tmp3); /* *Q_bwe_exc - exp */
+ }
+ }
+ /* i: L_tmp2 in (Q31-exp) */
+ /* i: exc16kWhtnd in Q_bwe_exc */
+ /* o: exc16kWhtnd in Q_bwe_exc: (Q_bwe_exc-exp) */
+
+ /* Rescale the past memories: LP synth and SHB look ahead buffers */
+ tmp = sub(*Q_bwe_exc, prev_Q_bwe_syn);
+ FOR( i = 0; i < LPC_SHB_ORDER; i++ )
+ {
+ state_lpc_syn[i] = shl( state_lpc_syn[i], tmp );
+ move16();
+ }
+ FOR( i = -L_SHB_LAHEAD; i < 0; i++ )
+ {
+ excSHB[i] = shl(excSHB[i], tmp);
+ move16();
+ }
+ /* Do mem_stp_swb_fx scaling before PostShortTerm_fx */
+
+ Syn_filt_s(0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, excSHB, 80, state_lpc_syn, 1 );
+ Syn_filt_s(0, lpc_shb_sf+(LPC_SHB_ORDER+1), LPC_SHB_ORDER, exc16kWhtnd+ 80, excSHB+ 80, 80, state_lpc_syn, 1 );
+ Syn_filt_s(0, lpc_shb_sf+2*(LPC_SHB_ORDER+1), LPC_SHB_ORDER, exc16kWhtnd+160, excSHB+160, 80, state_lpc_syn, 1 );
+ Syn_filt_s(0, lpc_shb_sf+3*(LPC_SHB_ORDER+1), LPC_SHB_ORDER, exc16kWhtnd+240, excSHB+240, 80, state_lpc_syn, 1 );
+ /* i: exc16kWhtnd in (Q_bwe_exc) */
+ /* o: excSHB in (Q_bwe_exc) */
+ }
+
+ IF ( EQ_16(extl, FB_TBE))
+ {
+ tmp = sub( add(*Q_bwe_exc_fb, 20), prev_Q_bwe_exc_fb );
+ Scale_sig( fb_state_lpc_syn, LPC_SHB_ORDER, tmp );
+ Scale_sig( fb_tbe_demph, 1, tmp );
+ Syn_filt_s(0, lpc_shb, LPC_SHB_ORDER, White_exc16k_FB, White_exc16k_FB_temp, L_FRAME16k, fb_state_lpc_syn, 1 );
+ /* i: White_exc16k_FB in (14-n2) */
+ /* o: White_exc16k_FB_temp in (14-n2) */
+
+ FOR( i=0; i<10; i++ )
+ {
+ FOR( j=0; j<32; ++j )
+ {
+ White_exc16k_FB_temp[i*32+j] = mult_r(White_exc16k_FB_temp[i*32+j], cos_fb_exc_fx[j]);
+ move16();
+ }
+ }
+
+ *Q_bwe_exc_fb = add(*Q_bwe_exc_fb, 20);
+ move16(); /**Q_bwe_exc_fb +35 +1 -16*/
+ flip_spectrum_fx( White_exc16k_FB_temp, White_exc16k_FB, L_FRAME16k );
+
+ deemph_fx( White_exc16k_FB, fb_deemph_fac, L_FRAME16k, fb_tbe_demph );
+
+ }
+ ELSE
+ {
+ set16_fx( White_exc16k_FB, 0, L_FRAME16k);
+ }
+
+#ifdef ADD_IVAS_TBE_CODE
+ *prev_pow_exc16kWhtnd = pow1;
+ *prev_mix_factor = mix_factor;
+#endif
+ return;
+}
+
+
+/*====================================================================================*/
+/* FUNCTION : void GenSHBSynth_fx() */
+/*------------------------------------------------------------------------------------*/
+/* PURPOSE :Generate 32 KHz sampled highband component from synthesized highband*/
+/*------------------------------------------------------------------------------------*/
+/* INPUT ARGUMENTS */
+/* _(Word16*)input_synspeech :input synthesized speech */
+/* _(Word16) L_frame :ACELP frame length */
+/*------------------------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _(Word16*)shb_syn_speech_32k : output highband component */
+/*------------------------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _(Word16[]) allpass_mem : memory */
+/* _(Word32[]) Hilbert_Mem : memory */
+/*------------------------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : */
+/* _ None */
+/*------------------------------------------------------------------------------------*/
+
+void GenSHBSynth_fx(
+ const Word16* input_synspeech, /* i : input synthesized speech */
+ Word16* shb_syn_speech_32k, /* o : output highband component */
+ Word32 Hilbert_Mem[], /* i/o: memory */
+ Word16 allpass_mem[], /* i/o: memory */
+ const Word16 L_frame, /* i : ACELP frame length */
+ Word16* syn_dm_phase
+)
+{
+ Word16 i, speech_buf_32k[L_FRAME32k];
+ Word16 maxm, nor, nor32, shift;
+ Word16 input_synspeech_temp[L_FRAME16k];
+ Word32 maxm32;
+
+
+ maxm = 0;
+ move16();
+ maxm32 = L_deposit_l(0);
+ FOR(i = 0; i (Q_bwe_exc + Q_gFr_norm - 13) */
+
+ /* check for headroom of previous buff memories: overlap, Hilbert, and interp all-pass mem */
+ tmpQ15 = add( prev_Q_bwe_syn2, n_mem3 );
+ if( GT_16( *Q_bwe_exc, tmpQ15))
+ {
+ *Q_bwe_exc = tmpQ15;
+ move16();
+ }
+
+ *Qx = *Q_bwe_exc;
+
+ /* rescale the overlap memory */
+ FOR( i = 0; i < L_SHB_LAHEAD; i++ )
+ {
+ temp2 = 1;
+ if( overlap[i] < 0 )
+ {
+ temp2 = -1;
+ }
+ temp1 = abs_s(overlap[i]);
+ temp1 = shl( temp1, (*Q_bwe_exc - prev_Q_bwe_syn2) );
+ move16(); /* Q_bwe_exc + Q_gFr_norm - 13 */
+ overlap[i] = i_mult(temp1, temp2);
+ }
+
+ FOR ( i = 0; i < l_shb_lahead; i++ )
+ {
+ L_tmp = Mult_32_16(mod_syn[i], gain_frame_Q16); /* Q_bwe_exc + 16 + Q_gFr_norm + 2 - 15 */
+ L_tmp2 = Mult_32_16(L_tmp, win[i]); /* (Q_bwe_exc + 16 + Q_gFr_norm + 2 - 15) + 15 + (1-16) */
+ synSHB[i] = mac_r(L_tmp2, overlap[i], MAX_16);
+ move16(); /* Q_bwe_exc + Q_gFr_norm - 13 */
+ synSHB[i+l_shb_lahead] = round_fx(L_tmp); /* Q_bwe_exc + Q_gFr_norm - 13 */
+ }
+
+ FOR ( ; i < l_frame; i++ )
+ {
+ L_tmp = Mult_32_16( mod_syn[i], gain_frame_Q16); /* Q_bwe_exc + 16 + Q_gFr_norm + 2 - 15 */
+ synSHB[i] = round_fx( L_tmp ); /* Q_bwe_exc + Q_gFr_norm - 13 */
+ }
+
+ l_frame_tmp = add(l_frame, l_shb_lahead);
+ FOR ( ; i < l_frame_tmp; i++ )
+ {
+ L_tmp = Mult_32_16( mod_syn[i], gain_frame_Q16); /* Q_bwe_exc + 16 + Q_gFr_norm + 2 - 15 */
+ L_tmp = Mult_32_16(L_tmp, win[l_frame + l_shb_lahead - 1 - i]); /* (Q_bwe_exc + 16 + Q_gFr_norm + 2 - 15) + 15 + (1-16) */
+ overlap[i - l_frame] = round_fx( L_tmp ); /* Q_bwe_exc + Q_gFr_norm - 13 */
+ }
+
+ return;
+}
+/*-------------------------------------------------------------------*
+ * ScaleShapedWB()
+ *
+ *
+ *-------------------------------------------------------------------*/
+
+void ScaleShapedWB_fx(
+ const Word16 length, /* i : SHB overlap length */
+ Word16* synSHB, /* i/o : synthesized shb signal Q_bwe_exc/Qx */
+ Word16* overlap, /* i/o : buffer for overlap-add Q_bwe_exc/Qx */
+ const Word16* subgain, /* i : subframe gain Q15*/
+ const Word32 frame_gain, /* i : frame gain Q18 */
+ const Word16* win, /* i : window Q15*/
+ const Word16* subwin, /* i : subframes window Q15*/
+ const Word16 Q_bwe_exc
+ ,Word16 L_frame /* i : Frame length - determines whether 12.8 or 16kHz core in-use */
+ ,Word16 dynQ /* i : indicate whether output is dynamic Q, or Q0 */
+ ,Word16* Qx /* o : newly computed Q factor for synSHB */
+ ,Word16 prev_Qx /* i : prev_Qx for memory scaling */
+ ,Word32* Hilbert_Mem /* i : Hilbert memory used for computing Qx */
+)
+{
+ const Word16* skip;
+ Word16 i, j, k, l_shb_lahead, l_frame, l_frame_tmp;
+ Word16 join_length, num_join;
+ Word32 mod_syn[L_FRAME16k+L_SHB_LAHEAD];
+ Word16 sum_gain;
+ Word32 L_tmp;
+ Word16 max_val, abs_sig, sc1, sc2, shift, max_headroom, min_shift, max_shift, max_shift2;
+ /* Init */
+ set32_fx( mod_syn, 0, L_FRAME16k+L_SHB_LAHEAD );
+
+ /* apply gain for each subframe, and store noise output signal using overlap-add */
+ IF ( EQ_16(length,SHB_OVERLAP_LEN / 2 ))
+ {
+ /* WB Gain shape and gain frame application with overlap */
+ skip = skip_bands_WB_TBE;
+ move16();
+ l_frame = L_FRAME16k / 4;
+ move16();
+ l_shb_lahead = L_SHB_LAHEAD / 4;
+ move16();
+
+ sum_gain = 0;
+ move16();
+ FOR ( k = 0; k < length / 2; k++ )
+ {
+ sum_gain = mult_r( subwin[2 * k + 2], subgain[0] ); /* Q15 */
+ mod_syn[skip[0] + k] = L_mult( sum_gain, synSHB[skip[0] + k] );
+ move32();/* Q_bwe_exc + 16 */
+ mod_syn[skip[0] + k + length / 2] = L_mult( subgain[0], synSHB[skip[0] + k + length / 2] );
+ move32();/* Q_bwe_exc + 16 */
+ }
+ FOR ( i = 1; i < NUM_SHB_SUBFR / 2; i++ )
+ {
+ FOR ( k = 0; k < length; k++ )
+ {
+ L_tmp = L_mult0( subwin[k + 1], subgain[i] ); /* Q30 */
+ sum_gain = round_fx( L_mac0( L_tmp, subwin[length - k - 1], subgain[i - 1] ) ); /* Q14 */
+ mod_syn[skip[i] + k] = L_shl( L_mult( sum_gain, synSHB[skip[i] + k] ), 1 );
+ move32(); /* Q_bwe_exc + 16 */
+ }
+ }
+ FOR ( k = 0; k < length / 2; k++ )
+ {
+ sum_gain = mult_r( subwin[length - 2 * k - 2], subgain[i - 1] ); /* Q15 */
+ mod_syn[skip[i] + k] = L_mult( sum_gain, synSHB[skip[i] + k] );
+ move32();/* Q_bwe_exc + 16 */
+ }
+ }
+ ELSE
+ {
+ /* SWB Gain shape and gain frame application with overlap */
+ l_frame = L_FRAME16k;
+ move16();
+ l_shb_lahead = L_SHB_LAHEAD;
+ move16();
+ skip = skip_bands_SWB_TBE;
+ move16();
+
+ num_join = NUM_SHB_SUBFR / NUM_SHB_SUBGAINS;
+ move16();
+ join_length = i_mult2( num_join, length );
+ j = 0; /* ptr*/
+ FOR ( k = 0; k < length; k++ )
+ {
+ sum_gain = mult_r( subwin[k + 1], subgain[0] ); /* Q15 */
+ mod_syn[j] = L_mult( synSHB[j], sum_gain );
+ move32(); /* Q_bwe_exc + 16 */
+ j++;
+ }
+
+ FOR ( i = 0; i < NUM_SHB_SUBGAINS - 1; i++ )
+ {
+ FOR ( k = 0; k < join_length - length; k++ )
+ {
+ mod_syn[j] = L_mult( synSHB[j], subgain[i * num_join] );
+ move32(); /* Q_bwe_exc + 16 */
+ j++;
+ }
+
+ FOR ( k = 0; k < length; k++ )
+ {
+ L_tmp = L_mult0( subwin[k + 1], subgain[i_mult2(( i + 1 ), num_join)] ); /* Q30 */
+ sum_gain = round_fx( L_mac0( L_tmp, subwin[length - k - 1], subgain[i_mult2(i, num_join)] ) );/*Q14 */
+ mod_syn[j] = L_shl( L_mult( sum_gain, synSHB[j] ), 1 );
+ move32(); /* Q_bwe_exc + 16 */
+ j++;
+ }
+ }
+ FOR ( k = 0; k < join_length - length; k++ )
+ {
+ mod_syn[j] = L_mult( synSHB[j], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] );
+ move32(); /* Q_bwe_exc + 16 */
+ j++;
+ }
+ FOR ( k = 0; k < length; k++ )
+ {
+ sum_gain = mult_r( subwin[length - k - 1], subgain[( NUM_SHB_SUBGAINS - 1 ) *num_join] ); /* Q15 */
+ mod_syn[j] = L_mult( synSHB[j], sum_gain );
+ move32(); /* Q_bwe_exc + 16 */
+ j++;
+ }
+ }
+
+
+
+ max_val = 0;
+ move16();
+ FOR( i = 0; i < l_frame + l_shb_lahead; i++ )
+ {
+ abs_sig = abs_s( round_fx(mod_syn[i]) );
+ if(GT_16(abs_sig,max_val))
+ {
+ max_val = abs_sig;
+ move16();
+ }
+ }
+
+ FOR( i = 0; i < HILBERT_MEM_SIZE; i++ )
+ {
+ abs_sig = abs_s( round_fx(Hilbert_Mem[i]) );
+ if(GT_16(abs_sig,max_val))
+ {
+ max_val = abs_sig;
+ move16();
+ }
+ }
+
+ sc1 = norm_s( max_val ); /* max_val headroom in mod_syn[] */
+ sc2 = norm_s( round_fx(frame_gain));/* headroom in GainFrame */
+
+ IF(dynQ == 0 )
+ {
+ shift = sub(13, Q_bwe_exc); /* earlier = (10 - Q_bwe_exc) but we changed GainFrame Q21 to Q18 */
+ *Qx = 0;
+ }
+ ELSE IF (EQ_16(L_frame,L_FRAME)) /* 12.8k core */
+ {
+ max_headroom = sub(add(sc1,sc2),4); /* Max headroom after multiplying = sc1 + sc2 -3 (keep 3 bit extra headroom) */
+ /* 12.8k core needs extra headroom than 16k core */
+ /* otherwise Hilbert transform inside flip_and_downmix have saturation, causes ringing in output */
+
+ /* Qx = (Q_bwe_exc+3) + shift - 16 */
+ /* make sure 14 > Qx > 2 */
+ min_shift = 2-(Q_bwe_exc+3-16);
+ max_shift = 13-(Q_bwe_exc+3-16);
+ max_shift2 = s_min(max_shift,max_headroom); /* avoid shifting more than the available max_val headroom to avoid overflow */
+
+ shift = s_min(min_shift,max_shift2);
+ *Qx = (Q_bwe_exc+3) + shift - 16;
+ }
+ ELSE /* 16k core */
+ {
+ max_headroom = sub(add(sc1,sc2),1); /* Max headroom after multiplying = sc1 + sc2 -1 (keep 1 bit extra headroom) */
+
+ /* Qx = (Q_bwe_exc+3) + shift - 16 */
+ /* make sure 14 > Qx > 3 */
+ min_shift = 3-(Q_bwe_exc+3-16);
+ max_shift = 13-(Q_bwe_exc+3-16);
+ max_shift2 = s_min(max_shift,max_headroom); /* avoid shifting more than the available max_val headroom to avoid overflow */
+
+ shift = s_min(min_shift,max_shift2);
+ *Qx = (Q_bwe_exc+3) + shift - 16;
+ }
+
+ /* bring memory st_fx->syn_overlap_fx[] = overlap[i] to new Q = Qx to prepare for addition */
+ FOR ( i = 0; i < l_shb_lahead; i++ )
+ {
+ overlap[i] = shl(overlap[i], (*Qx - prev_Qx));
+ }
+
+ FOR ( i = 0; i < l_shb_lahead; i++ )
+ {
+ /* mod_syn in (16+Q_bwe_exc), frame_gain in Q18 */
+ L_tmp = Mult_32_32( mod_syn[i], frame_gain ); /* L_tmp in (Q_bwe_exc+3) */
+ synSHB[i] = round_fx( L_shl( Mult_32_16( L_tmp, win[i] ), shift) ); /* Qx */
+ synSHB[i] = add( synSHB[i], overlap[i] );
+ move16(); /* Qx */
+ synSHB[i + l_shb_lahead] = round_fx( L_shl( L_tmp, shift) ); /* Qx */
+ }
+
+ FOR ( ; i < l_frame; i++ )
+ {
+ L_tmp = Mult_32_32( mod_syn[i], frame_gain); /* L_tmp in (Q_bwe_exc+3) */
+ synSHB[i] = round_fx( L_shl(L_tmp, shift) ); /* Qx; */
+ }
+
+ l_frame_tmp = add(l_frame, l_shb_lahead);
+ FOR ( ; i < l_frame_tmp; i++ )
+ {
+ L_tmp = Mult_32_32( mod_syn[i], frame_gain ); /* (Q_bwe_exc+3) */
+ overlap[i - l_frame] = round_fx( L_shl( Mult_32_16( L_tmp, win[l_frame + l_shb_lahead - 1 - i] ), shift ) ); /* Qx */
+ }
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * non_linearity()
+ *
+ * Apply a non linearity to the SHB excitation
+ * -------------------------------------------------------------------*/
+
+static Word32 non_linearity_scaled_copy(
+ const Word16 input[],
+ Word16 j,
+ const Word16 length,
+ Word32 output[],
+ Word32 prev_scale,
+ const Word16 scale_step,
+ const Word16 en_abs
+)
+{
+ Word16 i;
+ Word32 L_tmp;
+
+
+ IF (en_abs)
+ {
+ FOR ( i = 0; i < j; i++ )
+ {
+ L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */
+ L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */
+ output[i] = L_tmp;
+ move32();
+
+ L_tmp = Mult_32_16( prev_scale, scale_step ); /* Q29 */
+ prev_scale = L_shl( L_tmp, 1 ); /* Q30 */
+ }
+ FOR ( ; i < length; i++ )
+ {
+ L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */
+ L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */
+ output[i] = L_tmp;
+ move32();
+ }
+ }
+ ELSE
+ {
+ FOR ( i = 0; i < j; i++ )
+ {
+ L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */
+ L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */
+
+ if ( input[i] < 0 )
+ {
+ L_tmp = L_negate(L_tmp);
+ }
+ output[i] = L_tmp;
+ move32();
+
+ L_tmp = Mult_32_16( prev_scale, scale_step ); /* Q29 */
+ prev_scale = L_shl( L_tmp, 1 ); /* Q30 */
+ }
+
+ FOR ( ; i < length; i++ )
+ {
+#ifdef BASOP_NOGLOB
+ L_tmp = L_mult_sat( input[i], input[i]); /* 2*Q_inp+1 */
+#else /* BASOP_NOGLOB */
+ L_tmp = L_mult( input[i], input[i] ); /* 2*Q_inp+1 */
+#endif /* BASOP_NOGLOB */
+ L_tmp = Mult_32_32( L_tmp, prev_scale ); /* 2*Q_inp */
+
+ if ( input[i] < 0 )
+ {
+ L_tmp = L_negate(L_tmp);
+ }
+ output[i] = L_tmp;
+ move32();
+ }
+ }
+ return prev_scale;
+}
+
+/*==========================================================================*/
+/* FUNCTION : void non_linearity() */
+/*--------------------------------------------------------------------------*/
+/* PURPOSE : Apply a non linearity to the SHB excitation */
+/*--------------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* Word16 input[] i : input signal Q_inp */
+/* Word16 length i : input length */
+/*--------------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* Word32 output[] o : output signal 2*Q_inp */
+/*--------------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* Word32 *prev_scale i/o: memory Q30 */
+/*--------------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : */
+/* _ None */
+/*--------------------------------------------------------------------------*/
+/* CALLED FROM : */
+/*==========================================================================*/
+
+void non_linearity_fx(
+ const Word16 input[], /* i : input signal Q_inp */
+ Word32 output[], /* o : output signal 2*Q_inp */
+ const Word16 length, /* i : input length */
+ Word32* pPrevScale, /* i/o: memory Q30 */
+ Word16 Q_inp,
+ Word16 coder_type, /* i : Coder Type */
+ Word16 *voice_factors, /* i : Voice Factors */
+ const Word16 L_frame /* i : ACELP frame length */
+
+)
+{
+ Word16 i, j;
+ Word16 max_val=0;
+ Word32 scale;
+ Word16 scale_step;
+ Word16 exp, tmp;
+ Word16 e_tmp, f_tmp;
+ Word16 frac;
+ Word32 L_tmp;
+ Word32 L_tmp1;
+
+ Word16 en_abs = 0;
+ Word16 v_fac = 0;
+ Word16 ths;
+ Word16 nframes;
+ Word32 prev_scale;
+ Word16 length_half;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+
+
+ IF ( EQ_16(L_frame, L_FRAME16k ))
+ {
+ nframes = 5;
+ move16();
+ ths = 17817;
+ move16(); /* 0.87*5 in Q12 */
+ }
+ ELSE
+ {
+ nframes = 4;
+ move16();
+ ths = 15400;
+ move16(); /* 0.94*4 in Q12 */
+ }
+
+
+ FOR ( i = 0; i < nframes; i++ )
+ {
+ v_fac = add( v_fac, shr( voice_factors[i], 3 ) ); /* Q12 */
+ }
+
+ test();
+ if ( EQ_16( coder_type, VOICED )&>_16(v_fac,ths))
+ {
+ en_abs = 1;
+ move16();
+ }
+
+ length_half = shr(length, 1);
+ prev_scale = *pPrevScale;
+ move32();
+
+
+
+ /* Delay Alignment in FX is done inside swb_tbe_enc_fx() */
+
+ FOR ( i = j = 0; i < length_half; i++ )
+ {
+ tmp = abs_s(input[i]);
+ if(GT_16(tmp,max_val))
+ {
+ j = i;
+ move16();
+ }
+ max_val = s_max(max_val, tmp);
+
+ }
+
+
+ IF ( GT_16(max_val, shl(1,Q_inp)))
+ {
+ exp = norm_s( max_val );
+ tmp = div_s( shl(1, sub( 14, exp)), max_val ); /* Q(29-exp-Q_inp) */
+ scale = L_shl( L_mult( 21955, tmp ), add(exp, sub(Q_inp,14)) ); /* Q31 */
+ }
+ ELSE
+ {
+ scale = 1438814044;
+ move32(); /* Q31; 0.67 in Q31 */
+ }
+
+ test();
+ IF ( prev_scale <= 0 || GT_32( Mult_32_16( prev_scale, 32 ), scale ))
+ {
+ scale_step = 16384;
+ move16(); /* Q14 */
+ prev_scale = L_shr( scale, 1 ); /* Q30 */
+ }
+ ELSE
+ {
+
+ /* Computing log2(scale) */
+ IF ( j == 0 )
+ {
+ scale_step = 32767;
+ move16();
+ }
+ ELSE
+ {
+ e_tmp = norm_l( scale );
+ f_tmp = Log2_norm_lc( L_shl( scale, e_tmp ) );
+ e_tmp = sub(-1, e_tmp);
+ L_tmp = Mpy_32_16( e_tmp, f_tmp, 32767 ); /* Q16 */
+
+ /* Computing log2(prev_scale) */
+ e_tmp = norm_l( prev_scale );
+ f_tmp = Log2_norm_lc( L_shl( prev_scale, e_tmp ) );
+ e_tmp = negate(e_tmp);
+ L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 32767 ); /* Q16 */
+
+ /* log2(scale / prev_scale) = log2(scale) - log2(prev_scale) */
+ L_tmp = L_sub( L_tmp, L_tmp1 ); /* Q16 */
+
+ /* Computing 1/j */
+ exp = norm_s( j );
+ tmp = div_s( shl(1, sub( 14, exp)), j ); /* Q(29-exp) */
+
+ /* (log2(scale / prev_scale))/length */
+#ifdef BASOP_NOGLOB
+ L_tmp = L_shl_o( Mult_32_16( L_tmp, tmp ), sub(exp, 14), &Overflow ); /* Q(16+29-exp+1-16+exp-14)->Q16 */
+#else
+ L_tmp = L_shl( Mult_32_16( L_tmp, tmp ), sub(exp, 14) ); /* Q(16+29-exp+1-16+exp-14)->Q16 */
+#endif
+
+ frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */
+
+ tmp = extract_l( Pow2( 14, frac ) );
+#ifdef BASOP_NOGLOB
+ scale_step = shl_o( tmp, exp, &Overflow ); /* Q14 */
+#else
+ scale_step = shl( tmp, exp ); /* Q14 */
+#endif
+ }
+ }
+
+ prev_scale = non_linearity_scaled_copy( input, j, length_half, output, prev_scale, scale_step, en_abs );
+
+ max_val = 0;
+ move16();
+ j = shr(length, 1);
+ FOR ( i = length_half; i < length; i++ )
+ {
+ tmp = abs_s(input[i]);
+ if(GT_16(tmp,max_val))
+ {
+ j = i;
+ move16();
+ }
+ max_val = s_max(max_val, tmp);
+ }
+
+ IF ( GT_16( max_val, shl( 1, Q_inp ) ))
+ {
+ exp = norm_s( max_val );
+ tmp = div_s( shl(1, sub( 14, exp)), max_val ); /* Q(29-exp-Q_inp) */
+#ifdef BASOP_NOGLOB
+ scale = L_shl_o( L_mult( 21955, tmp ), add(exp, sub(Q_inp, 14)), &Overflow ); /* Q31 */
+#else
+ scale = L_shl( L_mult( 21955, tmp ), add(exp, sub(Q_inp, 14)) ); /* Q31 */
+#endif
+ }
+ ELSE
+ {
+ scale = 1438814044;
+ move32(); /* Q31; 0.67 in Q31 */
+ }
+
+ test();
+ IF ( prev_scale <= 0 || GT_32( Mult_32_16( prev_scale, 32 ), scale ))
+ {
+ scale_step = 16384;
+ move16(); /*Q14 */
+ prev_scale = L_shr( scale, 1 ); /*Q30 */
+ }
+ ELSE
+ {
+ /*scale_step = (float) exp(1.0f / (float) (j - length/2) * (float) log(scale / prev_scale)); */
+ /* Computing log2(scale) */
+ IF ( EQ_16(j,length_half))
+ {
+ scale_step = 32767;
+ move16();/*Q14 */
+ }
+ ELSE
+ {
+ e_tmp = norm_l( scale );
+ f_tmp = Log2_norm_lc( L_shl( scale, e_tmp ) );
+ e_tmp = sub(-e_tmp, 1);
+ L_tmp = Mpy_32_16( e_tmp, f_tmp, 32767 ); /* Q16 */
+
+ /* Computing log2(prev_scale) */
+ e_tmp = norm_l( prev_scale );
+ f_tmp = Log2_norm_lc( L_shl( prev_scale, e_tmp ) );
+ e_tmp = negate(e_tmp);
+ L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 32767 ); /* Q16 */
+
+ /* log2(scale / prev_scale) = log2(scale) - log2(prev_scale) */
+ L_tmp = L_sub( L_tmp, L_tmp1 ); /* Q16 */
+
+ /* Computing 1/(j - length/2) */
+
+ tmp = sub( j, length_half );
+ exp = norm_s( tmp );
+
+
+ tmp = div_s( shl(1, sub( 14, exp)), tmp ); /* Q(29-exp) */
+
+ /* (log2(scale / prev_scale))/length */
+#ifdef BASOP_NOGLOB
+ L_tmp = L_shl_o( Mult_32_16( L_tmp, tmp ), sub(exp,14), &Overflow); /*Q(16+29-exp+1-16+exp-14)->Q16 */
+#else
+ L_tmp = L_shl( Mult_32_16( L_tmp, tmp ), sub(exp,14) ); /*Q(16+29-exp+1-16+exp-14)->Q16 */
+#endif
+
+ frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */
+
+ tmp = extract_l( Pow2( 14, frac ) );
+#ifdef BASOP_NOGLOB
+ scale_step = shl_o( tmp, exp, &Overflow ); /*Q14 */
+#else
+ scale_step = shl( tmp, exp ); /*Q14 */
+#endif
+ }
+ }
+
+ prev_scale = non_linearity_scaled_copy( input+length_half, sub(j, length_half), sub(length, length_half), output+length_half, prev_scale, scale_step, en_abs );
+
+ *pPrevScale = prev_scale;
+ move32();
+
+ /* Delay Alignment in FX is done inside swb_tbe_enc_fx() */
+
+ return;
+}
+
+
+
+
+/*-------------------------------------------------------------------*
+* create_random_vector()
+*
+* creates random number vector
+* Note: the abs(max_val) value coming out of create_random_vector should
+* fit into the precision of Q6.
+* -------------------------------------------------------------------*/
+
+void create_random_vector_fx(
+ Word16 output[], /* o : output random vector Q5*/
+ const Word16 length, /* i : length of random vector */
+ Word16 seed[] /* i/o: start seed */
+)
+{
+ Word16 i, j, k;
+ Word16 scale1, scale2;
+ Word32 L_tmp;
+
+ L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[0] ) ) );/*Q23 */
+ j = extract_l( L_shr( L_tmp, 23 ) );
+ j = s_and( j, 0xff );
+
+ L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[1] ) ) );/*Q23 */
+ k = extract_l( L_shr( L_tmp, 23 ) );
+ k = s_and( k, 0xff );
+
+ WHILE ( EQ_16(k,j))
+ {
+ L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[1] ) ) );/*Q23 */
+ k = extract_l( L_shr( L_tmp, 23 ) );
+ k = s_and( k, 0xff );
+ }
+
+ scale1 = 18021;
+ move16(); /* 200.00f * 0.35f/0.1243f; */
+ if ( Random( &seed[0] ) < 0 )
+ {
+ scale1 = -18021;
+ move16(); /*Q5 */ /* -200.00f * 0.35f/0.1243f; */
+ }
+
+ scale2 = 7208;
+ move16(); /* 80.00f * 0.35f/0.1243f; */
+ if ( Random( &seed[1] ) < 0 )
+ {
+ scale2 = -7208;
+ move16(); /*Q5 */ /* -80.00f * 0.35f/0.1243f; */
+ }
+
+ FOR ( i = 0; i < length; i++ )
+ {
+ j = s_and( j, 0xff );
+ k = s_and( k, 0xff );
+ output[i] = round_fx( L_add( L_mult( scale1, gaus_dico_swb_fx[j] ), L_mult( scale2, gaus_dico_swb_fx[k] ) ) ); /*Q5 */
+ j++;
+ k++;
+ }
+
+ return;
+}
+
+
+/*======================================================================================*/
+/* FUNCTION : interp_code_5over2_fx() */
+/*--------------------------------------------------------------------------------------*/
+/* PURPOSE : Used to interpolate the excitation from the core sample rate */
+/* of 12.8 kHz to 32 kHz. */
+/* Simple linear interpolator - No need FOR precision here. */
+/*--------------------------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (Word16[]) inp_code_fx : input vector (Q12) */
+/* _ (Word16) inp_length : length of input vector */
+/*--------------------------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ (Word16[]) interp_code_fx : output vector (Q12) */
+/*--------------------------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _ None */
+/*--------------------------------------------------------------------------------------*/
+
+/* _ None */
+/*--------------------------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : */
+/* _ None */
+/*======================================================================================*/
+
+void interp_code_5over2_fx(
+ const Word16 inp_code_fx[], /* i : input vector Qx*/
+ Word16 interp_code_fx[], /* o : output vector Qx*/
+ const Word16 inp_length /* i : length of input vector */
+)
+{
+ Word16 i, kk, kkp1, i_len2;
+ Word32 Ltemp;
+ Word16 factor_i_fx[5] = {6554, 19661, 32767, 19661, 6554};
+ Word16 factor_j_fx[5] = {26214, 13107, 0, 13107, 26214};
+
+ interp_code_fx[0] = inp_code_fx[0];
+ move16();/* Qx */
+
+ Ltemp = L_mult( inp_code_fx[0], factor_i_fx[3] );/* Q(16+x) */
+ Ltemp = L_mac( Ltemp, inp_code_fx[1], factor_j_fx[3] );/* Q(16+x) */
+ interp_code_fx[1] = round_fx( Ltemp );/*Qx */
+
+ Ltemp = L_mult( inp_code_fx[0], factor_i_fx[4] );/*Q(16+x) */
+ Ltemp = L_mac( Ltemp, inp_code_fx[1], factor_j_fx[4] );/*Q(16+x) */
+ interp_code_fx[2] = round_fx( Ltemp ); /* Qx */
+
+ kk = 1;
+ move16();
+ kkp1 = 2;
+ move16();
+ i = 3;
+ move16();
+ /*i_len2 = ( inp_length - 2 ) * HIBND_ACB_L_FAC; */ /*HIBND_ACB_L_FAC == 5/2 */
+ i_len2 = sub(inp_length, 2);
+ i_len2 = shr(add(shl(i_len2, 2),i_len2),1); /* rounding below during shr makes it non BE*/
+
+ FOR ( ; i < i_len2; i += 5 )
+ {
+ Ltemp = L_mult( inp_code_fx[kk], factor_j_fx[0] );/*Q(16+x) */
+ Ltemp = L_mac( Ltemp, inp_code_fx[kkp1], factor_i_fx[0] );/*Q(16+x) */
+ interp_code_fx[i] = round_fx( Ltemp );/*Qx */
+
+ Ltemp = L_mult( inp_code_fx[kk], factor_j_fx[1] );/*Q(16+x) */
+ Ltemp = L_mac( Ltemp, inp_code_fx[kkp1], factor_i_fx[1] );/*Q(16+x) */
+ interp_code_fx[i + 1] = round_fx( Ltemp );/*Qx */
+
+ Ltemp = L_mult( inp_code_fx[kkp1], factor_i_fx[2] );/*Q(16+x) */
+ interp_code_fx[i + 2] = round_fx( Ltemp );/*Qx */
+
+ kk++;
+ kkp1++;
+
+ Ltemp = L_mult( inp_code_fx[kk], factor_i_fx[3] );/*Q(16+x) */
+ Ltemp = L_mac( Ltemp, inp_code_fx[kkp1], factor_j_fx[3] );/*Q(16+x) */
+ interp_code_fx[i + 3] = round_fx( Ltemp ); /*Qx */
+
+ Ltemp = L_mult( inp_code_fx[kk], factor_i_fx[4] );/*Q(16+x) */
+ Ltemp = L_mac( Ltemp, inp_code_fx[kkp1], factor_j_fx[4] );/*Q(16+x) */
+ interp_code_fx[i + 4] = round_fx( Ltemp ); /*Qx */
+
+ kk++;
+ kkp1++;
+ }
+
+ Ltemp = L_mult( inp_code_fx[kk], factor_j_fx[0] );/*Q(16+x) */
+ interp_code_fx[i] = round_fx( Ltemp ); /*Qx */
+
+ Ltemp = L_mult( inp_code_fx[kk], factor_j_fx[1] );/*Q(16+x) */
+ interp_code_fx[i + 1] = round_fx( Ltemp ); /*Qx */
+
+ return;
+}
+
+
+
+/*======================================================================================*/
+/* FUNCTION : interp_code_4over2_fx() */
+/*--------------------------------------------------------------------------------------*/
+/* PURPOSE : Used to interpolate the excitation from the core sample rate */
+/* of 16 kHz to 32 kHz. */
+/* Simple linear interpolator - No need for precision here. */
+/*--------------------------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (Word16[]) inp_code_fx : input vector (Qx) */
+/* _ (Word16) inp_length : length of input vector */
+/*--------------------------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ (Word16[]) interp_code_fx : output vector (Qx) */
+/*--------------------------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _ None */
+/*--------------------------------------------------------------------------------------*/
+
+/* _ None */
+/*--------------------------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : */
+/* _ None */
+/*======================================================================================*/
+
+void interp_code_4over2_fx(
+ const Word16 inp_code_fx[], /* i : input vector Qx*/
+ Word16 interp_code_fx[], /* o : output vector Qx*/
+ const Word16 inp_length /* i : length of input vector */
+)
+{
+ Word16 i, j;
+ j = 0;
+ move16();
+ FOR ( i = 0; i < inp_length - 1; i++ )
+ {
+ interp_code_fx[j] = inp_code_fx[i];
+ move16();/*Qx */
+ interp_code_fx[j + 1] = add( shr( inp_code_fx[i], 1 ), shr( inp_code_fx[i + 1], 1 ) );
+ move16();
+ move16();/*Qx */
+ j = add( j, 2 );
+ }
+
+ interp_code_fx[j] = inp_code_fx[i];
+ move16();
+ interp_code_fx[j + 1] = shr( inp_code_fx[i], 1 );
+ move16();/*Qx */
+
+ return;
+}
+
+
+/*-------------------------------------------------------------------*
+* wb_tbe_extras_reset_synth()
+*
+* Reset the extra parameters only required for WB TBE synthesis
+*-------------------------------------------------------------------*/
+
+void wb_tbe_extras_reset_synth_fx(
+ Word16 state_lsyn_filt_shb[],
+ Word16 state_lsyn_filt_dwn_shb[],
+ Word16 state_32and48k_WB_upsample[],
+ Word16 state_resamp_HB[]
+)
+{
+ set16_fx( state_lsyn_filt_shb, 0, 2 * ALLPASSSECTIONS_STEEP );
+ set16_fx( state_lsyn_filt_dwn_shb, 0, 2 * ALLPASSSECTIONS_STEEP );
+ set16_fx( state_32and48k_WB_upsample, 0, 2 * ALLPASSSECTIONS_STEEP );
+ set16_fx( state_resamp_HB, 0, INTERP_3_1_MEM_LEN );
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+ * elliptic_bpf_48k_generic()
+ *
+ * 18th-order elliptic bandpass filter at 14.0 to 20 kHz sampled at 48 kHz
+ * Implemented as 3 fourth order sections cascaded.
+ *-------------------------------------------------------------------*/
+
+void elliptic_bpf_48k_generic_fx(
+ const Word16 input_fx[], /* i : input signal */
+ Word16 *Q_input_fx,
+ Word16 output_fx[], /* o : output signal */
+ Word32 memory_fx2[][4], /* i/o: 4 arrays of 4 for memory */
+ Word16 memory_fx_Q[],
+ const Word16 full_band_bpf_fx[][5] /* i : filter coefficients b0,b1,b2,a0,a1,a2 Q13 */
+)
+{
+ Word16 i,j;
+ Word16 memory_fx0[4][4], memory_fx[4][4], Q_temp, Q_temp2;
+ Word32 L_tmp[L_FRAME48k], L_tmp2[L_FRAME48k], L_output[L_FRAME48k], L_tmpX, memory2_fx[4][4], L_tmpMax;
+ Word32 memory2_fx_2[4], memory2_fx_3[4];
+
+ FOR( i=0; i<4; i++ )
+ {
+ memory_fx0[0][i] = extract_l(memory_fx2[0][i]);
+#ifdef BASOP_NOGLOB
+ memory_fx[0][i] =shl_sat(memory_fx0[0][i],sub(*Q_input_fx,memory_fx_Q[0]));
+ memory2_fx[1][i] = L_shl_sat(memory_fx2[1][i], sub(add(*Q_input_fx, 11), memory_fx_Q[1]));
+ memory2_fx[2][i] = L_shl_sat(memory_fx2[2][i], sub(add(*Q_input_fx, 6), memory_fx_Q[2]));
+ memory2_fx[3][i] = L_shl_sat(memory_fx2[3][i], sub(add(*Q_input_fx, 1), memory_fx_Q[3]));
+#else
+ memory_fx[0][i] =shl(memory_fx0[0][i],sub(*Q_input_fx,memory_fx_Q[0]));
+ memory2_fx[1][i] = L_shl(memory_fx2[1][i], sub(add(*Q_input_fx, 11), memory_fx_Q[1]));
+ memory2_fx[2][i] = L_shl(memory_fx2[2][i], sub(add(*Q_input_fx, 6), memory_fx_Q[2]));
+ memory2_fx[3][i] = L_shl(memory_fx2[3][i], sub(add(*Q_input_fx, 1), memory_fx_Q[3]));
+#endif
+ }
+
+ L_tmpX = L_shr(L_mult(memory_fx[0][0],full_band_bpf_fx[0][4]),3);/*Q_input_fx + 13 + 1 - 3*/
+ L_tmpX = L_add(L_shr(L_mult(memory_fx[0][1],full_band_bpf_fx[0][3]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/
+ L_tmpX = L_add(L_shr(L_mult(memory_fx[0][2],full_band_bpf_fx[0][2]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/
+ L_tmpX = L_add(L_shr(L_mult(memory_fx[0][3],full_band_bpf_fx[0][1]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/
+ L_tmpX = L_add(L_shr(L_mult(input_fx[0],full_band_bpf_fx[0][0]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/
+#ifdef BASOP_NOGLOB
+ L_tmpX = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(memory2_fx[1][3],full_band_bpf_fx[3][1]),2));/*Q_input_fx + 11 + 13 -15 +2*/
+ L_tmpX = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(memory2_fx[1][2],full_band_bpf_fx[3][2]),2));/*Q_input_fx + 11 + 13 -15 +2*/
+ L_tmpX = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(memory2_fx[1][1],full_band_bpf_fx[3][3]),2));/*Q_input_fx + 11 + 13 -15 +2*/
+ L_tmp[0] = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(memory2_fx[1][0],full_band_bpf_fx[3][4]),2));/*Q_input_fx + 11 + 13 -15 +2*/ move32();
+#else
+ L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][3],full_band_bpf_fx[3][1]),2));/*Q_input_fx + 11 + 13 -15 +2*/
+ L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][2],full_band_bpf_fx[3][2]),2));/*Q_input_fx + 11 + 13 -15 +2*/
+ L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][1],full_band_bpf_fx[3][3]),2));/*Q_input_fx + 11 + 13 -15 +2*/
+ L_tmp[0] = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][0],full_band_bpf_fx[3][4]),2));/*Q_input_fx + 11 + 13 -15 +2*/ move32();
+#endif
+
+ L_tmpX = L_shr(L_mult(memory_fx[0][1],full_band_bpf_fx[0][4]),3);/*Q_input_fx + 13 + 1 - 3*/
+ L_tmpX = L_add(L_shr(L_mult(memory_fx[0][2],full_band_bpf_fx[0][3]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/
+ L_tmpX = L_add(L_shr(L_mult(memory_fx[0][3],full_band_bpf_fx[0][2]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/
+ L_tmpX = L_add(L_shr(L_mult(input_fx[0],full_band_bpf_fx[0][1]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/
+ L_tmpX = L_add(L_shr(L_mult(input_fx[1],full_band_bpf_fx[0][0]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/
+#ifdef BASOP_NOGLOB
+ L_tmpX = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(L_tmp[0],full_band_bpf_fx[3][1]),2));/*Q_input_fx + 11 + 13 -15 +2*/
+ L_tmpX = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(memory2_fx[1][3],full_band_bpf_fx[3][2]),2));/*Q_input_fx + 11 + 13 -15 +2*/
+ L_tmpX = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(memory2_fx[1][2],full_band_bpf_fx[3][3]),2));/*Q_input_fx + 11 + 13 -15 +2*/
+ L_tmp[1] = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(memory2_fx[1][1],full_band_bpf_fx[3][4]),2));/*Q_input_fx + 11 + 13 -15 +2*/ move32();
+#else
+ L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(L_tmp[0],full_band_bpf_fx[3][1]),2));/*Q_input_fx + 11 + 13 -15 +2*/
+ L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][3],full_band_bpf_fx[3][2]),2));/*Q_input_fx + 11 + 13 -15 +2*/
+ L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][2],full_band_bpf_fx[3][3]),2));/*Q_input_fx + 11 + 13 -15 +2*/
+ L_tmp[1] = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][1],full_band_bpf_fx[3][4]),2));/*Q_input_fx + 11 + 13 -15 +2*/ move32();
+#endif
+
+ L_tmpX = L_shr(L_mult(memory_fx[0][2],full_band_bpf_fx[0][4]),3);/*Q_input_fx + 13 + 1 - 3*/
+ L_tmpX = L_add(L_shr(L_mult(memory_fx[0][3],full_band_bpf_fx[0][3]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/
+ L_tmpX = L_add(L_shr(L_mult(input_fx[0],full_band_bpf_fx[0][2]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/
+ L_tmpX = L_add(L_shr(L_mult(input_fx[1],full_band_bpf_fx[0][1]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/
+ L_tmpX = L_add(L_shr(L_mult(input_fx[2],full_band_bpf_fx[0][0]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/
+#ifdef BASOP_NOGLOB
+ L_tmpX = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(L_tmp[1],full_band_bpf_fx[3][1]),2));/*Q_input_fx + 11 + 13 -15 +2*/
+ L_tmpX = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(L_tmp[0],full_band_bpf_fx[3][2]),2));/*Q_input_fx + 11 + 13 -15 +2*/
+ L_tmpX = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(memory2_fx[1][3],full_band_bpf_fx[3][3]),2));/*Q_input_fx + 11 + 13 -15 +2*/
+ L_tmp[2] = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(memory2_fx[1][2],full_band_bpf_fx[3][4]),2));/*Q_input_fx + 11 + 13 -15 +2*/ move32();
+#else
+ L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(L_tmp[1],full_band_bpf_fx[3][1]),2));/*Q_input_fx + 11 + 13 -15 +2*/
+ L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(L_tmp[0],full_band_bpf_fx[3][2]),2));/*Q_input_fx + 11 + 13 -15 +2*/
+ L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][3],full_band_bpf_fx[3][3]),2));/*Q_input_fx + 11 + 13 -15 +2*/
+ L_tmp[2] = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][2],full_band_bpf_fx[3][4]),2));/*Q_input_fx + 11 + 13 -15 +2*/ move32();
+#endif
+ L_tmpX = L_shr(L_mult(memory_fx[0][3],full_band_bpf_fx[0][4]),3);/*Q_input_fx + 13 + 1 - 3*/
+ L_tmpX = L_add(L_shr(L_mult(input_fx[0],full_band_bpf_fx[0][3]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/
+ L_tmpX = L_add(L_shr(L_mult(input_fx[1],full_band_bpf_fx[0][2]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/
+ L_tmpX = L_add(L_shr(L_mult(input_fx[2],full_band_bpf_fx[0][1]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/
+ L_tmpX = L_add(L_shr(L_mult(input_fx[3],full_band_bpf_fx[0][0]),3),L_tmpX);/*Q_input_fx + 13 + 1 - 3*/
+#ifdef BASOP_NOGLOB
+ L_tmpX = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(L_tmp[2],full_band_bpf_fx[3][1]),2));/*Q_input_fx + 11 + 13 -15 +2*/
+ L_tmpX = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(L_tmp[1],full_band_bpf_fx[3][2]),2));/*Q_input_fx + 11 + 13 -15 +2*/
+ L_tmpX = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(L_tmp[0],full_band_bpf_fx[3][3]),2));/*Q_input_fx + 11 + 13 -15 +2*/
+ L_tmp[3] = L_sub_sat(L_tmpX,L_shl_sat(Mult_32_16(memory2_fx[1][3],full_band_bpf_fx[3][4]),2));/*Q_input_fx + 11 + 13 -15 +2*/ move32();
+#else
+ L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(L_tmp[2],full_band_bpf_fx[3][1]),2));/*Q_input_fx + 11 + 13 -15 +2*/
+ L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(L_tmp[1],full_band_bpf_fx[3][2]),2));/*Q_input_fx + 11 + 13 -15 +2*/
+ L_tmpX = L_sub(L_tmpX,L_shl(Mult_32_16(L_tmp[0],full_band_bpf_fx[3][3]),2));/*Q_input_fx + 11 + 13 -15 +2*/
+ L_tmp[3] = L_sub(L_tmpX,L_shl(Mult_32_16(memory2_fx[1][3],full_band_bpf_fx[3][4]),2));/*Q_input_fx + 11 + 13 -15 +2*/ move32();
+#endif
+ FOR( i=4; i0)
+ {
+ expa = norm_l(temp_p1_p3);
+ fraca = extract_h(L_shl(temp_p1_p3,expa));
+ expa = sub(30,expa);
+
+ expb = norm_l(temp_p1_p2);
+#ifdef BASOP_NOGLOB
+ fracb = round_fx_o(L_shl_o(temp_p1_p2,expb, &Overflow), &Overflow);
+#else
+ fracb = round_fx(L_shl(temp_p1_p2,expb));
+#endif
+ expb = sub(30,expb);
+
+ num_flag = 0;
+ move16();
+ IF(fraca<0)
+ {
+ num_flag = 1;
+ move16();
+ fraca = negate(fraca);
+ }
+
+ den_flag = 0;
+ move16();
+ IF(fracb<0)
+ {
+ den_flag = 1;
+ move16();
+ fracb = negate(fracb);
+ }
+
+ scale = shr(sub(fraca,fracb),15);
+ fracb = shl(fracb,scale);
+ expb = sub(expb,scale);
+
+ tmp = div_s(fracb,fraca);
+ exp1 = sub(expb,expa);
+ tmp = shl(tmp,exp1);
+
+ if(NE_16(num_flag,den_flag))
+ {
+ tmp = negate(tmp);
+ }
+ }
+ ELSE
+ {
+ tmp = 0;
+ }
+
+ vf_modified[0] = s_min(s_max(tmp, 3277 /* 0.1f in Q15*/), 32440 /* 0.99f in Q15 */);
+ move16();
+
+ *vf_ind = usquant_fx(vf_modified[0], &tmp1, 4096 /* 0.125 in Q15 */, 2048 /* 0.125 in Q14 */, shl(1,NUM_BITS_SHB_VF));
+ move16();
+
+ vf_modified[0] = tmp1;
+ move16();
+ vf_modified[1] = tmp1;
+ move16();
+ vf_modified[2] = tmp1;
+ move16();
+ vf_modified[3] = tmp1;
+ move16();
+ vf_modified[4] = tmp1;
+ move16();
+
+ /* vf_modified in Q15 */
+
+ return;
+}
+#ifdef ADD_IVAS_TBE_CODE
+/*-------------------------------------------------------------------*
+ * tbe_celp_exc() *
+ * *
+ * Prepare adaptive part of TBE excitation *
+ *-------------------------------------------------------------------*/
+
+void tbe_celp_exc(
+ const int16_t element_mode, /* i : element mode */
+ const int16_t idchan, /* i : channel ID */
+ float* bwe_exc, /* i/o: BWE excitation */
+ const int16_t L_frame, /* i : frame length */
+ const int16_t L_subfr, /* i : subframe length */
+ const int16_t i_subfr, /* i : subframe index */
+ const int16_t T0, /* i : integer pitch lag */
+ const int16_t T0_frac, /* i : fraction of lag */
+ float* error, /* i/o: error */
+ const int16_t tdm_LRTD_flag /* i : LRTD stereo mode flag */
+)
+{
+ int16_t i, offset;
+
+ if (element_mode == IVAS_CPE_TD && idchan == 1 && !tdm_LRTD_flag)
+ {
+ return;
+ }
+
+ if (L_frame == L_FRAME)
+ {
+ offset = tbe_celp_exc_offset(T0, T0_frac);
+
+ for (i = 0; i < L_subfr * HIBND_ACB_L_FAC; i++)
+ {
+ bwe_exc[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc[i + i_subfr * HIBND_ACB_L_FAC - offset + (int16_t)*error];
+ }
+ *error += (float)offset - (float)T0 * HIBND_ACB_L_FAC - 0.25f * HIBND_ACB_L_FAC * (float)T0_frac;
+ }
+ else
+ {
+ offset = T0 * 2 + (int16_t)((float)T0_frac * 0.5f + 4 + 0.5f) - 4;
+ for (i = 0; i < L_subfr * 2; i++)
+ {
+ bwe_exc[i + i_subfr * 2] = bwe_exc[i + i_subfr * 2 - offset + (int16_t)*error];
+ }
+ *error += (float)offset - (float)T0 * 2 - 0.5f * (float)T0_frac;
+ }
+
+ return;
+}
+#endif
+/*======================================================================================*/
+/* FUNCTION : prep_tbe_exc_fx() */
+/*--------------------------------------------------------------------------------------*/
+/* PURPOSE : Prepare TBE excitation */
+/*--------------------------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (Word16) L_frame_fx : length of the frame */
+/* _ (Word16) i_subfr_fx : subframe index */
+/* _ (Word16) gain_pit_fx : Pitch gain (14) */
+/* _ (Word32) gain_code_fx : algebraic codebook gain (Q(16+Q_exc)) */
+/* _ (Word16*[]) code_fx : algebraic excitation (Q9) */
+/* _ (Word16) voice_fac_fx : voicing factor (Q15) */
+/* _ (Word16) gain_preQ_fx : prequantizer excitation gain */
+/* _ (Word16[]) code_preQ_fx : prequantizer excitation */
+/*--------------------------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ (Word16*[]) voice_factors_fx : TBE voicing factor (Q15) */
+/*--------------------------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _ (Word16[]) bwe_exc_fx : excitation for TBE (Q_exc) */
+/*--------------------------------------------------------------------------------------*/
+
+/* _ None */
+/*--------------------------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : */
+/* _ None */
+/*======================================================================================*/
+
+void prep_tbe_exc_fx(
+ const Word16 L_frame_fx, /* i : length of the frame */
+#ifdef ADD_IVAS_TBE_CODE
+ const Word16 L_subfr,
+#endif
+ const Word16 i_subfr_fx, /* i : subframe index */
+ const Word16 gain_pit_fx, /* i : Pitch gain Q14*/
+ const Word32 gain_code_fx, /* i : algebraic codebook gain 16+Q_exc*/
+ const Word16 code_fx[], /* i : algebraic excitation Q9*/
+ const Word16 voice_fac_fx, /* i : voicing factor Q15*/
+ Word16 *voice_factors_fx, /* o : TBE voicing factor Q15*/
+ Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/
+ const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */
+ const Word16 code_preQ_fx[], /* i : prequantizer excitation */
+ const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */
+ Word16 T0, /* i : integer pitch variables Q0 */
+ Word16 T0_frac, /* i : Fractional pitch variables Q0*/
+ const Word16 coder_type, /* i : coding type */
+ Word32 core_brate
+#ifdef ADD_IVAS_TBE_CODE
+ , /* i : core bitrate */
+ const int16_t element_mode, /* i : element mode */
+ const int16_t idchan, /* i : channel ID */
+ const int16_t flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */
+ const int16_t tdm_LRTD_flag /* i : LRTD stereo mode flag */
+#endif
+)
+{
+ Word16 i;
+ Word16 tmp_code_fx[2*L_SUBFR * HIBND_ACB_L_FAC];
+ Word16 tmp_code_preInt_fx[L_SUBFR];
+ Word16 gain_code16 = 0;
+ Word16 tmp /*, tmp1, tmp2*/;
+ /*Word16 random_code[L_SUBFR * HIBND_ACB_L_FAC];*/
+ Word16 pitch;
+
+ Word32 L_tmp, Ltemp1, Ltemp2;
+ Word32 tempQ31;
+ Word16 tempQ15;
+#ifndef ADD_IVAS_TBE_CODE
+ Word16 L_subfr = L_SUBFR;
+#endif
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+
+ /**voice_factors = VF_0th_PARAM + VF_1st_PARAM * voice_fac + VF_2nd_PARAM * voice_fac * voice_fac;
+ = VF_0th_PARAM + voice_fac * (VF_1st_PARAM + VF_2nd_PARAM * voice_fac )
+ *voice_factors = min( max_val(0.0f, *voice_factors), 1.0f); */
+ tempQ31 = L_deposit_h( VF_1st_PARAM_FX );
+ tempQ15 = mac_r(tempQ31, VF_2nd_PARAM_FX, voice_fac_fx);
+ tempQ31 = L_deposit_h( VF_0th_PARAM_FX );
+ *voice_factors_fx = mac_r(tempQ31, voice_fac_fx, tempQ15);
+
+ tmp = 32767;
+ move16();
+
+#ifdef BASOP_NOGLOB
+ pitch = shl_o( add( shl_o( T0, 2, &Overflow ), T0_frac ), 5, &Overflow ); /* Q7 */
+#else /* BASOP_NOGLOB */
+ pitch = shl( add( shl( T0, 2 ), T0_frac ), 5 ); /* Q7 */
+#endif /* BASOP_NOGLOB */
+
+ test();
+ test();
+ IF ( ( ( EQ_16(coder_type,VOICED))||(GT_16(pitch,14784)))&&(GT_32(core_brate,ACELP_8k00)))
+ {
+ tmp = MAX_16;
+ move16();
+ *voice_factors_fx = mult_r( *voice_factors_fx, tmp );
+ }
+
+ *voice_factors_fx = s_min(s_max(*voice_factors_fx, 0), MAX_16);
+ move16();
+#ifdef ADD_IVAS_TBE_CODE
+ IF (EQ_16(element_mode, IVAS_CPE_TD) && EQ_16(idchan, 1) && !tdm_LRTD_flag)
+ {
+ IF (flag_TD_BWE && i_subfr == 0)
+ {
+ set16_fx(bwe_exc, 0, L_FRAME32k);
+ }
+ return;
+ }
+
+#endif
+ IF ( EQ_16(L_frame_fx,L_FRAME))
+ {
+ interp_code_5over2_fx( code_fx, tmp_code_fx, L_subfr); /* code: Q9, tmp_code: Q9 */
+#ifdef BASOP_NOGLOB
+ gain_code16 = round_fx_o( L_shl_o( gain_code_fx, Q_exc, &Overflow ), &Overflow); /*Q_exc */
+#else
+ gain_code16 = round_fx( L_shl( gain_code_fx, Q_exc ) ); /*Q_exc */
+#endif
+ FOR ( i = 0; i < L_subfr* HIBND_ACB_L_FAC; i++ )
+ {
+ L_tmp = L_mult( gain_code16, tmp_code_fx[i] ); /* Q9 + Q_exc + 1*/
+ L_tmp = L_shl( L_tmp, 5 ); /* Q9 + Q_exc + Q6*/
+ L_tmp = L_mac( L_tmp, gain_pit_fx, bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] ); /*Q15+Q_exc */
+#ifdef BASOP_NOGLOB
+ L_tmp = L_shl_o( L_tmp, 1 , &Overflow); /*16+Q_exc */ /* saturation can occur here */
+ bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] = round_fx_o(L_tmp, &Overflow); /*Q_exc */
+#else /* BASOP_NOGLOB */
+ L_tmp = L_shl( L_tmp, 1 ); /*16+Q_exc */ /* saturation can occur here */
+ bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] = round_fx( L_tmp ); /*Q_exc */
+#endif /* BASOP_NOGLOB */
+ }
+ }
+ ELSE
+ {
+ IF( gain_preQ_fx != 0 )
+ {
+ FOR( i = 0; i < L_subfr; i++ )
+ {
+ /*code in the encoder is Q9 and there is no <<1 with Mult_32_16 Q16 * Q9 -> Q9 */
+ Ltemp1 = Mult_32_16(gain_code_fx, code_fx[i]); /* Q16 + Q9 + 1 - 16 = Q10 */
+ Ltemp2 = L_mult(gain_preQ_fx, code_preQ_fx[i]); /*Q2 * Q10 -> Q12 */
+
+#ifdef BASOP_NOGLOB
+ Ltemp1 = L_shl_o(Ltemp1, Q_exc + 6 /*Q_exc+16-19*/, &Overflow); /*Q_exc+16 */
+ Ltemp2 = L_shl_o( Ltemp2, Q_exc+4 /*Q_exc+16-13*/, &Overflow) ; /*Q_exc+16 */
+
+ tmp_code_preInt_fx[i] = round_fx_o(L_add_o(Ltemp1, Ltemp2, &Overflow), &Overflow); /* Q_exc */
+#else /* BASOP_NOGLOB */
+ Ltemp1 = L_shl( Ltemp1, Q_exc+6 /*Q_exc+16-19*/) ; /*Q_exc+16 */
+ Ltemp2 = L_shl( Ltemp2, Q_exc+4 /*Q_exc+16-13*/ ) ; /*Q_exc+16 */
+
+ tmp_code_preInt_fx[i] = round_fx(L_add(Ltemp1, Ltemp2)); /* Q_exc */
+#endif /* BASOP_NOGLOB */
+ }
+ }
+ ELSE
+ {
+ FOR( i = 0; i < L_subfr; i++ )
+ {
+ /*code in the encoder is Q9 and there is no <<1 with Mult_32_16 Q16 * Q9 -> Q9 */
+ Ltemp1 = Mult_32_16(gain_code_fx, code_fx[i]); /* Q16 + Q9 + 1 - 16 = Q10 */
+#ifdef BASOP_NOGLOB
+ Ltemp1 = L_shl_o( Ltemp1, Q_exc+6 /*Q_exc+16-19*/, &Overflow) ; /*Q_exc+16 */
+ tmp_code_preInt_fx[i] = round_fx_o(Ltemp1, &Overflow); /* Q_exc */
+#else
+ Ltemp1 = L_shl( Ltemp1, Q_exc+6 /*Q_exc+16-19*/) ; /*Q_exc+16 */
+ tmp_code_preInt_fx[i] = round_fx(Ltemp1); /* Q_exc */
+#endif
+ }
+ }
+
+ interp_code_4over2_fx( tmp_code_preInt_fx, tmp_code_fx, L_subfr); /* o: tmp_code in Q_exc */
+ FOR ( i = 0; i < L_subfr * 2; i++ )
+ {
+ L_tmp = L_mult(gain_pit_fx, bwe_exc_fx[i + i_subfr_fx*2]); /*Q14+Q_exc+1 */
+#ifdef BASOP_NOGLOB
+ tmp = round_fx_o(L_shl_o(L_tmp, 1 /* (Q_exc+16)-(14+Q_exc+1)*/, &Overflow), &Overflow); /* tmp in Q_exc */
+ bwe_exc_fx[i + i_subfr_fx * 2] = add_o(tmp, tmp_code_fx[i], &Overflow); /*Q_exc */ move16();
+#else /* BASOP_NOGLOB */
+ tmp = round_fx(L_shl(L_tmp, 1 /* (Q_exc+16)-(14+Q_exc+1)*/ )); /* tmp in Q_exc */
+ bwe_exc_fx[i + i_subfr_fx * 2] = add(tmp, tmp_code_fx[i]); /*Q_exc */ move16();
+#endif
+ }
+ }
+
+ return;
+}
+
+
+/*=============================================================================*/
+/* FUNCTION : void swb_formant_fac_fx ( ) */
+/*------------------------------------------------------------------------------*/
+/* PURPOSE : * Find strength of adaptive formant postfilter using tilt */
+/* of the high band. The 2nd lpc coefficient is used as a tilt approximation. */
+/*------------------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* const Word16 lpc_shb2 : 2nd HB LPC coefficient Q12 */
+/*------------------------------------------------------------------------------*/
+/*INPUT/OUTPUT ARGUMENTS : */
+/* Word16 *tilt_mem Q12 */
+/* OUTPUT ARGUMENTS : */
+/*------------------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : */
+/* formant_fac :Formant filter strength [0,1] Q15 */
+/*------------------------------------------------------------------------------*/
+/* CALLED FROM : */
+/*==============================================================================*/
+
+Word16 swb_formant_fac_fx( /* o : Formant filter strength [0,1] */
+ const Word16 lpc_shb2, /* Q12 i : 2nd HB LPC coefficient */
+ Word16* tilt_mem /* i/o: Tilt smoothing memory (Q12) */
+)
+{
+ Word16 formant_fac;
+ Word16 tmp;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+
+ /* Smoothen tilt value */
+ /* tmp = 0.5f * (float)fabs(lpc_shb2) + 0.5f * *tilt_mem; */
+ tmp = mult_r( 16384, abs_s( lpc_shb2 ) );
+ tmp = add( tmp, mult_r( 16384, *tilt_mem ) ); /* Q12 */
+ *tilt_mem = tmp;
+ move16();/*Q12 */
+ /* Map to PF strength */
+ /* formant_fac = (tmp - SWB_TILT_LOW)*SWB_TILT_DELTA; */
+ tmp = sub( tmp, SWB_TILT_LOW_FX ); /* Q12 */
+ formant_fac = mult_r( tmp, SWB_TILT_DELTA_FX ); /* Q12 */
+
+
+ IF ( GT_16( formant_fac, 4096 ))
+ {
+ formant_fac = 4096;
+ move16();
+ }
+ ELSE if ( formant_fac < 0 )
+ {
+ formant_fac = 0;
+ move16();
+ }
+ /* now formant_fac in Q12 */
+
+ /* formant_fac = 1.0f - 0.5f*formant_fac */
+ tmp = mult_r(16384, formant_fac); /* 0.5 in Q12 */
+#ifdef BASOP_NOGLOB
+ formant_fac = shl_o(sub(4096,tmp),3, &Overflow);
+#else
+ formant_fac = shl(sub(4096,tmp),3);
+#endif
+ return formant_fac; /*Q15 */
+}
+
+
+void wb_tbe_extras_reset_fx(
+ Word16 mem_genSHBexc_filt_down_wb2[],
+ Word16 mem_genSHBexc_filt_down_wb3[] )
+{
+ set16_fx( mem_genSHBexc_filt_down_wb2, 0, 2*ALLPASSSECTIONS_STEEP+1 );
+ set16_fx( mem_genSHBexc_filt_down_wb3, 0, 2*ALLPASSSECTIONS_STEEP+1 );
+
+ return;
+}
+
+/*-------------------------------------------------------------------*
+* get_tbe_bits() *
+* *
+* Determine TBE bit consumption per frame from bitrate *
+*-------------------------------------------------------------------*/
+
+
+Word16 get_tbe_bits_fx(
+ const Word32 total_brate, /* o : TBE bit consumption per frame */
+ const Word16 bwidth, /* i : overall bitrate */
+ const Word16 rf_mode /* i : bandwidht mode */
+)
+{
+ Word16 i, bits = 0;
+
+ IF( EQ_16(rf_mode,1))
+ {
+ /* TBE bits for core, primary frame */
+ test();
+ test();
+ IF( (EQ_16(bwidth, WB ))&&(EQ_32(total_brate,ACELP_13k20)))
+ {
+ /* Gain frame: 4, Gain shapes: 0, and LSFs: 2 */
+ bits = NUM_BITS_SHB_FrameGain_LBR_WB + NUM_BITS_LBR_WB_LSF;
+ move16();
+ }
+ ELSE IF( (EQ_16(bwidth, SWB ))&&(EQ_32(total_brate,ACELP_13k20)))
+ {
+ /* Gain frame: 5, Gain shapes: 5, and lowrate LSFs: 8 */
+ bits = NUM_BITS_SHB_FRAMEGAIN + NUM_BITS_SHB_SUBGAINS + 8;
+ move16();
+ }
+ }
+ ELSE
+ {
+ test();
+ test();
+ IF( (EQ_16(bwidth, WB ))&&(EQ_32(total_brate,ACELP_9k60)))
+ {
+ bits = NUM_BITS_LBR_WB_LSF + NUM_BITS_SHB_FrameGain_LBR_WB;
+ move16();
+ }
+ ELSE IF( (EQ_16( bwidth, SWB ))||(EQ_16(bwidth,FB)))
+ {
+ test();
+ IF( EQ_32(total_brate, ACELP_9k60))
+ {
+ bits = NUM_BITS_SHB_FRAMEGAIN + NUM_BITS_SHB_SUBGAINS + 8;
+ move16();
+ }
+ ELSE IF( (GE_32( total_brate, ACELP_13k20 ))&&(LE_32(total_brate,ACELP_32k)))
+ {
+ bits = NUM_BITS_SHB_SUBGAINS + NUM_BITS_SHB_FRAMEGAIN + NUM_LSF_GRID_BITS + MIRROR_POINT_BITS;
+ move16();
+
+ FOR ( i=0; i ACELP@16k switching
*--------------------------------------------------------------------*/
-void synth_mem_updt2(
+void synth_mem_updt2_flt(
const int16_t L_frame, /* i : frame length */
const int16_t last_L_frame, /* i : frame length */
float old_exc[], /* i/o: excitation buffer */
@@ -128,11 +128,11 @@ void synth_mem_updt2(
/* Residual and update old_exc */
if ( dec >= DEC )
{
- lerp( old_exc + L_EXC_MEM_DEC - ( last_L_frame + last_L_frame / 2 ), old_exc + L_EXC_MEM_DEC - ( L_frame + L_frame / 2 ), L_frame + L_frame / 2, last_L_frame + last_L_frame / 2 );
+ lerp_flt( old_exc + L_EXC_MEM_DEC - ( last_L_frame + last_L_frame / 2 ), old_exc + L_EXC_MEM_DEC - ( L_frame + L_frame / 2 ), L_frame + L_frame / 2, last_L_frame + last_L_frame / 2 );
}
else
{
- lerp( old_exc + L_EXC_MEM - last_L_frame, old_exc + L_EXC_MEM - L_frame, L_frame, last_L_frame );
+ lerp_flt( old_exc + L_EXC_MEM - last_L_frame, old_exc + L_EXC_MEM - L_frame, L_frame, last_L_frame );
}
/*Resamp memory*/
@@ -140,7 +140,7 @@ void synth_mem_updt2(
mem_syn_r_size_old = (int16_t) ( 1.25 * last_L_frame / 20.f );
mem_syn_r_size_new = (int16_t) ( 1.25 * L_frame / 20.f );
- lerp( mem_syn_r + L_SYN_MEM - mem_syn_r_size_old, mem_syn_r + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
+ lerp_flt( mem_syn_r + L_SYN_MEM - mem_syn_r_size_old, mem_syn_r + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
if ( dec == DEC_IVAS )
{
diff --git a/lib_com/syn_filt_fx.c b/lib_com/syn_filt_fx.c
new file mode 100644
index 0000000000000000000000000000000000000000..a8aa91a021baa0cbfe96d6fff188da68fb7e86b5
--- /dev/null
+++ b/lib_com/syn_filt_fx.c
@@ -0,0 +1,326 @@
+/*====================================================================================
+ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
+ ====================================================================================*/
+
+#include
+#include "options.h" /* Compilation switches */
+#include "cnst.h" /* Common constants */
+#include "rom_com.h" /* Static table prototypes */
+#include "prot_fx1.h"
+#include "prot_fx2.h"
+#include "stl.h"
+
+static Word32 syn_kern_2(Word32 L_tmp, const Word16 a[], const Word16 y[])
+{
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+#ifdef BASOP_NOGLOB
+ L_tmp = L_msu_o(L_tmp, y[-1], a[1], &Overflow);
+ return L_msu_o(L_tmp, y[-2], a[2], &Overflow);
+#else
+ L_tmp = L_msu(L_tmp, y[-1], a[1]);
+ return L_msu(L_tmp, y[-2], a[2]);
+#endif
+}
+
+static Word32 syn_kern_4(Word32 L_tmp, const Word16 a[], const Word16 y[])
+{
+ L_tmp = syn_kern_2(L_tmp, a, y);
+ return syn_kern_2(L_tmp, a+2, y-2);
+}
+
+static Word32 syn_kern_6(Word32 L_tmp, const Word16 a[], const Word16 y[])
+{
+ L_tmp = syn_kern_4(L_tmp, a, y);
+ return syn_kern_2(L_tmp, a+4, y-4);
+}
+
+static Word32 syn_kern_8(Word32 L_tmp, const Word16 a[], const Word16 y[])
+{
+ L_tmp = syn_kern_4(L_tmp, a, y);
+ return syn_kern_4(L_tmp, a+4, y-4);
+}
+
+static Word32 syn_kern_10(Word32 L_tmp, const Word16 a[], const Word16 y[])
+{
+ L_tmp = syn_kern_8(L_tmp, a, y);
+ return syn_kern_2(L_tmp, a+8, y-8);
+}
+
+Word32 syn_kern_16(Word32 L_tmp, const Word16 a[], const Word16 y[])
+{
+ L_tmp = syn_kern_8(L_tmp, a, y);
+ return syn_kern_8(L_tmp, a+8, y-8);
+}
+
+static Word32 syn_kern_24(Word32 L_tmp, const Word16 a[], const Word16 y[])
+{
+ L_tmp = syn_kern_16(L_tmp, a, y);
+ return syn_kern_8(L_tmp, a+16, y-16);
+}
+
+/*------------------------------------------------------------------*
+ * Syn_filt_s_lc:
+ *
+ * perform the synthesis filtering 1/A(z).
+ * Optimized Version when No Memory, Past is Set to 0
+ *------------------------------------------------------------------*/
+void syn_filt_s_lc_fx(
+ const Word16 shift, /* i : scaling to apply Q0 */
+ const Word16 a[], /* i : LP filter coefficients Q12 */
+ const Word16 x[], /* i : input signal Qx */
+ Word16 y[], /* o : output signal Qx-s */
+ const Word16 lg /* i : size of filtering Q0 */
+)
+{
+ Word16 i, j;
+ Word32 L_tmp;
+ Word16 a0;
+ Word16 q;
+
+
+ q = add( norm_s(a[0]), 1 );
+ a0 = shr(a[0], shift); /* input / 2^shift */
+
+ /*-----------------------------------------------------------------------*
+ * Do the filtering
+ *-----------------------------------------------------------------------*/
+ FOR (i = 0; i < M; i++)
+ {
+ L_tmp = L_mult(*x++, a0);
+ /* Stop at i to Avoid Mults with Zeros */
+ FOR (j = 1; j <= i; j++)
+ {
+ L_tmp = L_msu(L_tmp, y[-j], a[j]);
+ }
+
+ L_tmp = L_shl(L_tmp, q);
+ *y++ = round_fx(L_tmp);
+ }
+
+ FOR (; i < lg; i++)
+ {
+ L_tmp = syn_kern_16(L_mult(*x++, a0), a, y);
+ L_tmp = L_shl(L_tmp, q);
+ *y++ = round_fx(L_tmp);
+ }
+}
+
+/*------------------------------------------------------------------*
+ * Syn_filt_s:
+ *
+ * perform the synthesis filtering 1/A(z).
+ *------------------------------------------------------------------*/
+void Syn_filt_s(
+ const Word16 shift, /* i : scaling to apply Q0 */
+ const Word16 a[], /* i : LP filter coefficients Q12 */
+ const Word16 m, /* i : order of LP filter Q0 */
+ const Word16 x[], /* i : input signal Qx */
+ Word16 y[], /* o : output signal Qx-s */
+ const Word16 lg, /* i : size of filtering Q0 */
+ Word16 mem[], /* i/o: memory associated with this filtering. Qx-s */
+ const Word16 update /* i : 0=no update, 1=update of memory. Q0 */
+)
+{
+ E_UTIL_synthesis(shift, a, x, y, lg, mem, update, m);
+}
+
+
+/*
+ * E_UTIL_synthesis
+ *
+ * Parameters:
+ * shift i : scaling to apply for a[0] Q0
+ * a[] i : LP filter coefficients Qx
+ * x[] i : input signal Qx
+ * y[] o : output signal Qx-s
+ * lg i : size of filtering Q0
+ * mem[] i/o: memory associated with this filtering. Qx-s
+ * update i : 0=no update, 1=update of memory. Q0
+ * m i : order of LP filter Q0
+ *
+ * Function:
+ * Perform the synthesis filtering 1/A(z).
+ * Memory size is always M.
+ *
+ * Returns:
+ * void
+ */
+void E_UTIL_synthesis(const Word16 shift, const Word16 a[], const Word16 x[], Word16 y[],
+ const Word16 lg, Word16 mem[], const Word16 update, const Word16 m
+ )
+{
+ Word16 i, j, a0;
+ Word32 L_tmp;
+ Word16 q;
+ Word32 (*syn_kern)(Word32 L_tmp, const Word16 a[], const Word16 y[]) = NULL;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+
+ if (EQ_16(m, 6))
+ {
+ syn_kern = syn_kern_6;
+ }
+ if (EQ_16(m, 10))
+ {
+ syn_kern = syn_kern_10;
+ }
+ if (EQ_16(m, 16))
+ {
+ syn_kern = syn_kern_16;
+ }
+ if (EQ_16(m, 24))
+ {
+ syn_kern = syn_kern_24;
+ }
+ assert(syn_kern != NULL);
+ q = add( norm_s(a[0]), 1 );
+
+
+
+ /*-----------------------------------------------------------------------*
+ * Set Memory Pointer at End for Backward Access
+ *-----------------------------------------------------------------------*/
+ mem += m; /*move16();*/
+
+#ifdef BASOP_NOGLOB
+ a0 = shr_o(a[0], shift, &Overflow); /* input / 2^shift */
+#else
+ a0 = shr(a[0], shift); /* input / 2^shift */
+#endif
+ /*-----------------------------------------------------------------------*
+ * Do the filtering
+ *-----------------------------------------------------------------------*/
+ /* Filtering Only from Input + Memory */
+ L_tmp = syn_kern(L_mult(a0, *x++), a, mem);
+#ifdef BASOP_NOGLOB
+ L_tmp = L_shl_o(L_tmp, q, &Overflow);
+ *y++ = round_fx_o(L_tmp, &Overflow);
+#else
+ L_tmp = L_shl(L_tmp, q);
+ *y++ = round_fx(L_tmp);
+#endif
+
+ /* Filtering from Input + Mix of Memory & Output Signal Past */
+ FOR (i = 1; i < m; i++)
+ {
+ L_tmp = L_mult(a0, *x++);
+ /* Process Output Signal Past */
+ FOR (j = 1; j <= i; j++)
+ {
+#ifdef BASOP_NOGLOB
+ L_tmp = L_msu_o(L_tmp, a[j], y[-j], &Overflow);
+#else
+ L_tmp = L_msu(L_tmp, a[j], y[-j]);
+#endif
+ }
+ /* Process Memory */
+ FOR (; j <= m; j++)
+ {
+ L_tmp = L_msu(L_tmp, a[j], mem[i-j]);
+ }
+#ifdef BASOP_NOGLOB
+ L_tmp = L_shl_o(L_tmp, q, &Overflow);
+ *y++ = round_fx_o(L_tmp, &Overflow);
+#else
+ L_tmp = L_shl(L_tmp, q);
+ *y++ = round_fx(L_tmp);
+#endif
+ }
+
+ /* Filtering from Input + Output Signal Past */
+ FOR (; i < lg; i++)
+ {
+ L_tmp = syn_kern(L_mult(a0, *x++), a, y);
+#ifdef BASOP_NOGLOB
+ L_tmp = L_shl_o(L_tmp, q, &Overflow);
+ *y++ = round_fx_o(L_tmp, &Overflow);
+#else /* BASOP_NOGLOB */
+ L_tmp = L_shl(L_tmp, q);
+ *y++ = round_fx(L_tmp);
+#endif
+ }
+
+ /*-----------------------------------------------------------------------*
+ * Update memory if required
+ *-----------------------------------------------------------------------*/
+ IF (update != 0)
+ {
+ FOR (i = 0; i < m; i++)
+ {
+ *--mem = *--y;
+ move16();
+ }
+ }
+
+ return;
+}
+
+
+
+/*-------------------------------------------------------------------*
+ * synth_mem_updt2()
+ *
+ * Update of synthesis filter memories in case of ACELP@12k8 <-> ACELP@16k switching
+ *--------------------------------------------------------------------*/
+
+void synth_mem_updt2(
+ const Word16 L_frame, /* i : frame length */
+ const Word16 last_L_frame, /* i : frame length */
+ Word16 old_exc[], /* i/o: excitation buffer */
+ Word16 mem_syn_r[], /* i/o: synthesis filter memory */
+ Word16 mem_syn2[], /* o : synthesis filter memory for find_target */
+ Word16 mem_syn[], /* o : synthesis filter memory for find_target */
+ const Word16 dec /* i : flag for decoder indication */
+)
+{
+ Word16 mem_syn_r_size_old, mem_syn_r_size_new;
+
+ /* Residual and update old_exc */
+ IF( GE_16(dec, DEC))
+ {
+ lerp( old_exc+L_EXC_MEM_DEC-(last_L_frame+last_L_frame/2), old_exc+L_EXC_MEM_DEC-(L_frame+L_frame/2), L_frame+L_frame/2, last_L_frame+last_L_frame/2 );
+ }
+ ELSE
+ {
+ lerp( old_exc+L_EXC_MEM-last_L_frame, old_exc+L_EXC_MEM-L_frame, L_frame, last_L_frame );
+ }
+#ifdef ADD_LRTD
+ IF (EQ_16(dec, DEC_IVAS) )
+ {
+ IF (EQ_16(L_frame, L_FRAME16k))
+ {
+ /* find scaling factor */
+ PME()
+ en1 = 1.25f * sum2_f(mem_syn2, M);
+ en2 = sum2_f(mem_syn_r + L_SYN_MEM - M, M);
+
+ loc_rat = sqrtf(en2) / (sqrtf(en1) + 0.01f);
+ /* scale synthesis filter memory */
+ FOR (i = 0; i < M; i++)
+ {
+ mem_syn_r[L_SYN_MEM - M + i] *= loc_rat;
+ }
+ }
+ }
+#endif
+ /*Resamp memory*/
+ /*Size of LPC syn memory*/
+ /* 1.25/20.0 = 1.0/16.0 -> shift 4 to the right. */
+ mem_syn_r_size_old = shr(last_L_frame, 4);
+ mem_syn_r_size_new = shr(L_frame, 4);
+
+ lerp( mem_syn_r + L_SYN_MEM - mem_syn_r_size_old, mem_syn_r + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
+
+ Copy( mem_syn_r+L_SYN_MEM-M, mem_syn2, M );
+
+ IF( mem_syn != NULL )
+ {
+ Copy( mem_syn2, mem_syn, M );
+ }
+
+}
+
+
diff --git a/lib_com/tcx_mdct_window.c b/lib_com/tcx_mdct_window.c
index 05a70cdc908d1d9158d01339ed96565852d07916..fe6c00041c407c72776a536d5494f63f51f32824 100644
--- a/lib_com/tcx_mdct_window.c
+++ b/lib_com/tcx_mdct_window.c
@@ -98,7 +98,7 @@ void mdct_window_sine(
}
else
{
- lerp( window_table, window, n, buf_in_size );
+ lerp_flt( window_table, window, n, buf_in_size );
}
}
diff --git a/lib_com/tcx_utils.c b/lib_com/tcx_utils.c
index 0747a7572bedc0e02500cbea8f9661f92ac23201..eac1c1cb8280680b39ba91e46d31a1fbb7885400 100644
--- a/lib_com/tcx_utils.c
+++ b/lib_com/tcx_utils.c
@@ -334,7 +334,7 @@ void tcx_windowing_synthesis_current_frame(
}
else
{
- lerp( acelp_zir, tmp, acelp_zir_len, acelp_zir_len * FSCALE_DENOM / fullbandScale );
+ lerp_flt( acelp_zir, tmp, acelp_zir_len, acelp_zir_len * FSCALE_DENOM / fullbandScale );
acelp_zir = tmp;
}
@@ -381,7 +381,7 @@ void tcx_windowing_synthesis_current_frame(
}
else
{
- lerp( acelp_zir, tmp, acelp_zir_len * fullbandScale / FSCALE_DENOM, acelp_zir_len );
+ lerp_flt( acelp_zir, tmp, acelp_zir_len * fullbandScale / FSCALE_DENOM, acelp_zir_len );
acelp_zir_len = acelp_zir_len * fullbandScale / FSCALE_DENOM;
acelp_zir = tmp;
diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c
index cc3545d072e0441fde588b8ee3d5bf836fecaccd..c2355b1a3a9b28e77510d326396097727caf2ce6 100644
--- a/lib_com/tools_fx.c
+++ b/lib_com/tools_fx.c
@@ -55,12 +55,6 @@
const Word16 b_hp400_fx[3] = { 3660, -7320, 3660 }; /* Q12 (/4) */
const Word16 a_hp400_fx[3] = { 16384, 29280, -14160 };
-static __inline Word16 L_Extract_lc(const Word32 L_32, Word16 *p_hi)
-{
- *p_hi = extract_h(L_32);
- return lshr(extract_l(L_32), 1);
-
-}
int16_t norm_ul(uint32_t UL_var1)
{
diff --git a/lib_com/typedef.h b/lib_com/typedef.h
index 7b17aed924303c7a906f35c6c6241a5e5f481bab..02183e7c53e9099913b099dd65ed3bcce9f57f46 100644
--- a/lib_com/typedef.h
+++ b/lib_com/typedef.h
@@ -128,6 +128,8 @@ typedef int Flag;
typedef float Float32;
+typedef unsigned short int UNS_Word16; /* 16 bit "register" (sw*) */
+
#ifndef TYPEDEF_INITIALIZED
#error types in typedef.h not initialized
#endif
diff --git a/lib_com/weight_a_fx.c b/lib_com/weight_a_fx.c
new file mode 100644
index 0000000000000000000000000000000000000000..73a735455b39a3c2bd79a32c42acd99cb853b898
--- /dev/null
+++ b/lib_com/weight_a_fx.c
@@ -0,0 +1,219 @@
+/*====================================================================================
+ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
+ ====================================================================================*/
+#include
+#include "options.h" /* Compilation switches */
+#include "rom_com.h" /* Static table prototypes */
+#include "prot_fx1.h"
+#include "prot_fx2.h"
+#include
+
+/*------------------------------------------------------------------
+ * weight_a_subfr()
+ *
+ * Weighting of LP filter coefficients for multiple subframes,
+ * ap[i] = a[i] * (gamma^i)
+ *------------------------------------------------------------------*/
+
+void weight_a_subfr_fx(
+ const Word16 nb_subfr, /* i : number of subframes */
+ const Word16 *A, /* i : LP filter coefficients Q12 */
+ Word16 *Aw, /* o : weighted LP filter coefficients Q12 */
+ const Word16 gamma, /* i : weighting factor */
+ const Word16 order /* i : order of LP filter */
+)
+{
+ Word16 k, orderp1;
+
+ /* Smoothing aka spreading aka masking envelope generation */
+ orderp1 = add(order,1);
+ FOR (k=0; k
+#include "options.h"
+#include "prot_fx1.h"
+#include "prot_fx2.h"
+#include "rom_com.h"
+#include "log2.h"
+
+/*-------------------------------------------------------------------*
+ * Local constants
+ *-------------------------------------------------------------------*/
+#define WARP_OS_RATE 8
+#define LL 256
+#define LL_OS (WARP_OS_RATE*LL)
+#define OSLENGTH 12
+#define CUTFREE_ABS_RANGE 6
+#define CUTFREE_REL_RANGE 0.25
+#define CUTFREE_ABS_RANGE_Q3 48
+#define CUTFREE_REL_RANGE_Q2 1
+#define WI_THRESHLD 0.8
+#define WI_SAMPLE_THLD 20
+
+/*#define _POLY1(x, c) ((c)[0] * (x) + (c)[1]) */
+/*#define _POLY2(x, c) (_POLY1((x), (c)) * (x) + (c)[2]) */
+/*#define _POLY3(x, c) (_POLY2((x), (c)) * (x) + (c)[3]) */
+
+/*-------------------------------------------------------------------*
+ * Local functions
+ *--------------------------------------------------------------------*/
+
+static Word32 DTFS_setEngy_fx(DTFS_STRUCTURE* X_DTFS_FX, Word32 en2_fx);
+
+/*-------------------------------------------------------------------*
+* DTFS_new_fx()
+*
+* DTFS structure initialization.
+*-------------------------------------------------------------------*/
+ivas_error DTFS_new_fx(
+ DTFS_STRUCTURE** dtfs_out
+)
+{
+
+ Word16 i ;
+
+ DTFS_STRUCTURE* dtfs_fx = NULL;
+ dtfs_fx = (DTFS_STRUCTURE *) calloc(1,sizeof(DTFS_STRUCTURE));
+ //PMT("verif mem alloc")
+ IF (dtfs_fx == NULL)
+ {
+ return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTFS (SC-VBR) structure\n"));
+ }
+
+ dtfs_fx->lag_fx = 0 ;
+ move16();
+ dtfs_fx->nH_fx=0;
+ move16();
+ dtfs_fx->nH_4kHz_fx=0;
+ move16();
+ dtfs_fx->upper_cut_off_freq_of_interest_fx=3300;
+ move16();
+ dtfs_fx->upper_cut_off_freq_fx=4000;
+ move16();
+ dtfs_fx->Q = 0;
+ move16();
+
+ FOR(i=0; ia_fx[i] = 0;
+ move16();
+ dtfs_fx->b_fx[i] = 0;
+ move16();
+ }
+ *dtfs_out = dtfs_fx;
+ return IVAS_ERR_OK;
+}
+/*-------------------------------------------------------------------*
+* DTFS_copy_fx()
+*
+* Copy from one DTFS STRUCTURE to another.
+*-------------------------------------------------------------------*/
+
+void DTFS_copy_fx(
+ DTFS_STRUCTURE *Xout_fx, /* o: DTFS structure */
+ DTFS_STRUCTURE Xinp_fx /* i: DTFS structure */
+)
+
+{
+
+ Word16 k;
+ FOR(k=0; ka_fx[k]=Xinp_fx.a_fx[k];
+ move16();
+ }
+
+ FOR(k=0; kb_fx[k]=Xinp_fx.b_fx[k];
+ move16();
+ }
+
+ Xout_fx->lag_fx=Xinp_fx.lag_fx;
+ move16();
+ Xout_fx->nH_fx=Xinp_fx.nH_fx;
+ move16();
+ Xout_fx->nH_4kHz_fx=Xinp_fx.nH_4kHz_fx;
+ move16();
+ Xout_fx->upper_cut_off_freq_of_interest_fx=Xinp_fx.upper_cut_off_freq_of_interest_fx;
+ move16();
+ Xout_fx->upper_cut_off_freq_fx=Xinp_fx.upper_cut_off_freq_fx;
+ move16();
+ Xout_fx->Q = Xinp_fx.Q;
+ move16();
+ return;
+
+}
+
+
+/*-------------------------------------------------------------------*
+* DTFS_sub_fx()
+*
+* Subtract one DTFS STRUCTURE from another.
+*-------------------------------------------------------------------*/
+void DTFS_sub_fx(
+ DTFS_STRUCTURE *tmp,/* o: X1 - X2 */
+ DTFS_STRUCTURE X1, /* i: DTFS input 1 */
+ DTFS_STRUCTURE X2 /* i: DTFS input 2 */
+)
+{
+ Word16 i ,sft, tmp_loop;
+ sft = sub(X1.Q,X2.Q);
+
+ IF(sft>0)
+ {
+ tmp_loop = shr(X1.lag_fx,1);
+ FOR(i=0; i<=tmp_loop; i++)
+ {
+
+ tmp->a_fx[i] = sub(shr(X1.a_fx[i],sft),X2.a_fx[i]);
+ move16();
+ tmp->b_fx[i] = sub(shr(X1.b_fx[i],sft),X2.b_fx[i]);
+ move16();
+ }
+ tmp->Q = X2.Q;
+ move16();
+ }
+ ELSE
+ {
+ tmp_loop = shr(X1.lag_fx,1);
+ FOR(i=0; i<=tmp_loop; i++)
+ {
+
+ tmp->a_fx[i] = sub(X1.a_fx[i],shl(X2.a_fx[i],sft));
+ move16();
+ tmp->b_fx[i] = sub(X1.b_fx[i],shl(X2.b_fx[i],sft));
+ move16();
+ }
+ tmp->Q = X1.Q;
+ move16();
+ }
+ tmp->lag_fx = s_max(X1.lag_fx, X2.lag_fx) ;
+ tmp->nH_fx=s_max(X1.nH_fx,X2.nH_fx);
+ tmp->nH_4kHz_fx=s_max(X1.nH_4kHz_fx,X2.nH_4kHz_fx);
+ tmp->upper_cut_off_freq_of_interest_fx=X1.upper_cut_off_freq_of_interest_fx;
+ move16();
+ tmp->upper_cut_off_freq_fx=X1.upper_cut_off_freq_fx;
+ move16();
+ return ;
+}
+/*-------------------------------------------------------------------*
+ * DTFS_fast_fs_inv()
+ *
+ * DTFS inverse.
+ *-------------------------------------------------------------------*/
+
+static void DTFS_fast_fs_inv_fx( DTFS_STRUCTURE *X_fx,Word16 *out_fx, Word16 N_fx, Word16 LOG2N)
+{
+ Word16 i, M_2, N_2, s;
+ Word16 dbuf_fx[256+1];
+
+ M_2=s_min(shr(X_fx->lag_fx,1),X_fx->nH_fx);
+ move16();
+ N_2=shr(N_fx,1);
+ s=negate(X_fx->Q);
+
+ dbuf_fx[0]=X_fx->a_fx[0];
+ move16();
+ dbuf_fx[1]=0;
+ move16();
+
+ FOR (i=1; i<=M_2; i++)
+ {
+ dbuf_fx[2*i]=shl_r(X_fx->a_fx[i],s);
+ move16();
+ dbuf_fx[2*i+1]=shl_r(X_fx->b_fx[i],s);
+ move16();
+ }
+
+ FOR ( ; i 0 )
+ {
+ fshift_fx = n_fx ;
+ move16();
+ maxcorr_fx = L_add(wcorr_fx, 0);
+ Qmaxcorr = Qcorr;
+ move16();
+ }
+ }
+
+ return fshift_fx ;
+}
+
+
+/*===========================================================================*/
+/* FUNCTION : DTFS_alignment_full_fx () */
+/*---------------------------------------------------------------------------*/
+/* PURPOSE : search for alignment */
+/*---------------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (struct DTFS_STRUCTURE) X1_DTFS_fx : a_fx/b_fx in X1_DTFS_fx.Q */
+/* _ (struct DTFS_STRUCTURE) X2_DTFS_fx : a_fx/b_fx in X2_DTFS_fx.Q */
+/* _ (Word16 *) S_fx: sin(2pi*n/(4*lag)) table, Q15 */
+/* _ (Word16 *) C_fx: cos(2pi*n/(4*lag)) table, Q15 */
+/*---------------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ (Word16) fshift_fx : Q1 */
+/*---------------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _ None */
+/*---------------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : _ None. */
+/*---------------------------------------------------------------------------*/
+/* CALLED FROM : TX */
+/*===========================================================================*/
+
+Word16 DTFS_alignment_full_fx(
+ DTFS_STRUCTURE X1_DTFS_fx,
+ DTFS_STRUCTURE X2_DTFS_fx,
+ Word16 ph_offset_fx,
+ Word16 *S_fx,
+ Word16 *C_fx,
+ Word16 FR_flag
+)
+{
+ Word16 temp, temp1, k, start, end, HalfLag, ab1[MAXLAG_WI], ab2[MAXLAG_WI] ;
+ Word16 n, fshift_fx;
+ Word32 corr_fx, maxcorr_fx;
+ Word16 Eshift, Adiff_fx;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+
+ /* Calculating the expected alignment shift */
+ Eshift = mult_r(ph_offset_fx, shl(X2_DTFS_fx.lag_fx, 7)); /* confirmed I<2 by smv12.org, Q7 */
+ find_rem((Word16)L_FRAME, shr(add(X2_DTFS_fx.lag_fx, X1_DTFS_fx.lag_fx), 1), &temp);
+ temp = add(shl(temp, 7), Eshift); /* Q7 */
+
+ IF (temp<0)
+ {
+ temp = add(temp, shl(X1_DTFS_fx.lag_fx, 7)); /* Q7 */
+ }
+ find_rem(temp, shl(X1_DTFS_fx.lag_fx, 7), &Eshift); /* Q7 */
+ Eshift=shl(shr(Eshift,7),1); /* Q1 but integer */
+
+ IF (GT_16(X2_DTFS_fx.lag_fx,60))
+ {
+ Adiff_fx = shl(X2_DTFS_fx.lag_fx,1-3); /* lag_fx/8 in Q1 */
+ }
+ ELSE
+ {
+ Adiff_fx = shl(X2_DTFS_fx.lag_fx,1-2); /* lag_fx/4 in Q1 */
+ }
+
+
+ IF (X1_DTFS_fx.lag_fx < X2_DTFS_fx.lag_fx)
+ {
+ DTFS_zeroPadd_fx(X2_DTFS_fx.lag_fx,&X1_DTFS_fx) ;
+ }
+
+ maxcorr_fx = L_add(MIN_32, 0);
+ HalfLag = s_min(shr(X2_DTFS_fx.lag_fx, 1),X2_DTFS_fx.nH_4kHz_fx);
+
+ FOR (k=0; k<=HalfLag; k++)
+ {
+#ifdef BASOP_NOGLOB
+ ab1[k] = round_fx_o(L_mac_o(L_mult_o(X1_DTFS_fx.a_fx[k], X2_DTFS_fx.a_fx[k], &Overflow), X1_DTFS_fx.b_fx[k], X2_DTFS_fx.b_fx[k], &Overflow), &Overflow); /* Q(-15); */
+ ab2[k] = round_fx_o(L_msu_o(L_mult_o(X1_DTFS_fx.b_fx[k], X2_DTFS_fx.a_fx[k], &Overflow), X1_DTFS_fx.a_fx[k], X2_DTFS_fx.b_fx[k], &Overflow), &Overflow); /* Q(-15); */
+#else
+ ab1[k] = round_fx(L_mac(L_mult(X1_DTFS_fx.a_fx[k], X2_DTFS_fx.a_fx[k]), X1_DTFS_fx.b_fx[k], X2_DTFS_fx.b_fx[k])); /* Q(-15); */
+ ab2[k] = round_fx(L_msu(L_mult(X1_DTFS_fx.b_fx[k], X2_DTFS_fx.a_fx[k]), X1_DTFS_fx.a_fx[k], X2_DTFS_fx.b_fx[k])); /* Q(-15); */
+#endif
+ }
+ IF (FR_flag == 0)
+ {
+ start=sub(Eshift, Adiff_fx); /*Q1*/
+ end=add(Eshift, Adiff_fx); /*Q1*/
+ }
+ ELSE
+ {
+ /*
+ in FR mode, we cannot save and cary forward ph_offset as in VBR mode encoder "ph_offset_E_fx",
+ so we set ph_offset_fx = 0, as a result we cannot accurately estimate the expected alignment shift Eshift to limit the search,
+ so we search the full range [0 to X2_DTFS_fx.lag_fx] similar to FL
+ */
+ start=0; /*Q1*/
+ end=shl(X2_DTFS_fx.lag_fx,1); /*Q1*/
+ }
+
+ fshift_fx=start;
+ move16(); /*Q1*/
+
+ FOR (n=start; n<=end; n++) /*n in Q1*/
+ {
+ /* Q1 */
+ corr_fx = L_deposit_l(0);
+ temp = 0;
+ move16();
+ temp1 = add(n,shl(X2_DTFS_fx.lag_fx,1)); /* add lag_fx in Q1to make positive */
+ FOR (k=0; k<=HalfLag; k++)
+ {
+#ifdef BASOP_NOGLOB
+ corr_fx = L_mac_o(corr_fx, ab1[k], C_fx[(2*temp)%(4*X2_DTFS_fx.lag_fx)], &Overflow);
+ corr_fx = L_mac_o(corr_fx, ab2[k], S_fx[(2*temp)%(4*X2_DTFS_fx.lag_fx)], &Overflow);
+ temp = add_o(temp, temp1, &Overflow);
+#else
+ corr_fx = L_mac(corr_fx, ab1[k], C_fx[(2*temp)%(4*X2_DTFS_fx.lag_fx)]);
+ corr_fx = L_mac(corr_fx, ab2[k], S_fx[(2*temp)%(4*X2_DTFS_fx.lag_fx)]);
+ temp = add(temp, temp1);
+#endif
+ }
+
+ if (GT_32(corr_fx, maxcorr_fx))
+ {
+ fshift_fx = n ; /* Q1 */ move16();
+ maxcorr_fx = L_add(corr_fx, 0);
+ }
+ }
+
+ return fshift_fx ; /*Q1*/
+}
+/*===================================================================*/
+/* FUNCTION : DTFS_phaseShift_fx () */
+/*-------------------------------------------------------------------*/
+/* PURPOSE : Phase is shifted by 2pi*ph/Lag */
+/*-------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (Word16) ph: shift index, Q7 */
+/* _ (Word16) Lag: Pitch Lag value as for shift */
+/* _ (Word16 *) S_fx: sin(2pi*n/(4*lag)) table, Q15 */
+/* _ (Word16 *) C_fx: cos(2pi*n/(4*lag)) table, Q15 */
+/*-------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ None. */
+/*-------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _ (struct DTFS_fx) X1 : a/b in X1.Q */
+/*-------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : _ None. */
+/*-------------------------------------------------------------------*/
+/* CALLED FROM : TX/RX */
+/*===================================================================*/
+
+void DTFS_phaseShift_fx( DTFS_STRUCTURE *X_fx,Word16 ph, Word16 Lag, Word16 *S_fx, Word16 *C_fx)
+{
+ Word16 k ;
+ Word16 temp, HalfLag;
+ Word32 L_temp, L_temp2;
+
+ L_temp2 = L_deposit_l(0);
+ HalfLag = s_min(shr(X_fx->lag_fx, 1),X_fx->nH_fx);
+
+ IF (ph>0)
+ {
+ FOR (k=0; k<=HalfLag; k++)
+ {
+ temp = X_fx->a_fx[k];
+ L_temp = L_shr(L_temp2, 5); /* Q2 */
+ X_fx->a_fx[k] = round_fx(L_msu(L_mult(temp, C_fx[L_temp%(4*Lag)]), X_fx->b_fx[k], S_fx[L_temp%(4*Lag)])) ; /* X.Q */
+ X_fx->b_fx[k] = round_fx(L_mac(L_mult(X_fx->b_fx[k], C_fx[L_temp%(4*Lag)]), temp, S_fx[L_temp%(4*Lag)])) ;
+ L_temp2 = L_add(L_temp2, ph);
+ }
+ }
+
+ IF (ph<0)
+ {
+ FOR (k=0; k<=HalfLag; k++)
+ {
+ temp = X_fx->a_fx[k];
+ L_temp = L_shr(L_negate(L_temp2), 5); /* Q2 */
+ X_fx->a_fx[k] = round_fx(L_mac(L_mult(temp, C_fx[L_temp%(4*Lag)]), X_fx->b_fx[k], S_fx[L_temp%(4*Lag)])) ; /* X.Q */
+ X_fx->b_fx[k] = round_fx(L_msu(L_mult(X_fx->b_fx[k], C_fx[L_temp%(4*Lag)]), temp, S_fx[L_temp%(4*Lag)])) ;
+ L_temp2 = L_add(L_temp2, ph);
+ }
+ }
+ return;
+}
+
+/*===================================================================*/
+/* FUNCTION : Q2phaseShift_fx () */
+/*-------------------------------------------------------------------*/
+/* PURPOSE : Phase is shifted by 2pi*ph/Lag */
+/*-------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (Word16) ph: shift index, Q2 */
+/* _ (Word16) Lag: Pitch Lag value as for shift */
+/* _ (Word16 *) S_fx: sin(2pi*n/(4*lag)) table, Q15 */
+/* _ (Word16 *) C_fx: cos(2pi*n/(4*lag)) table, Q15 */
+/*-------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ None. */
+/*-------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _ (struct DTFS_STRUCTURE) X_fx : a/b in X_fx->Q */
+/*-------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : _ None. */
+/*-------------------------------------------------------------------*/
+/* CALLED FROM : TX/RX */
+/*===================================================================*/
+
+void Q2phaseShift_fx(
+ DTFS_STRUCTURE *X_fx,
+ Word16 ph,
+ Word16 Lag,
+ Word16 *S_fx,
+ Word16 *C_fx
+)
+{
+ Word16 k ;
+ Word16 temp, HalfLag;
+ Word32 temp2;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+ temp2 = L_deposit_l(0);
+
+ HalfLag = s_min(shr(X_fx->lag_fx, 1),X_fx->nH_fx);
+
+
+ IF (ph>0)
+ {
+ FOR (k=0; k<=HalfLag; k++)
+ {
+ temp = X_fx->a_fx[k];
+#ifdef BASOP_NOGLOB
+ X_fx->a_fx[k] = round_fx_o(L_msu_o(L_mult_o(temp, C_fx[temp2%(4*Lag)], &Overflow), X_fx->b_fx[k], S_fx[temp2%(4*Lag)], &Overflow), &Overflow) ; /* X.Q */
+ X_fx->b_fx[k] = round_fx_o(L_mac_o(L_mult_o(X_fx->b_fx[k], C_fx[temp2%(4*Lag)], &Overflow), temp, S_fx[temp2%(4*Lag)], &Overflow), &Overflow) ;
+ temp2 = L_add_o(temp2, (Word32)ph, &Overflow);
+#else
+ X_fx->a_fx[k] = round_fx(L_msu(L_mult(temp, C_fx[temp2 % (4 * Lag)]), X_fx->b_fx[k], S_fx[temp2 % (4 * Lag)])); /* X.Q */
+ X_fx->b_fx[k] = round_fx(L_mac(L_mult(X_fx->b_fx[k], C_fx[temp2 % (4 * Lag)]), temp, S_fx[temp2 % (4 * Lag)]));
+ temp2 = L_add(temp2, (Word32)ph);
+#endif
+ }
+ }
+
+
+
+ IF (ph<0)
+ {
+ FOR (k=0; k<=HalfLag; k++)
+ {
+ temp = X_fx->a_fx[k];
+#ifdef BASOP_NOGLOB
+ X_fx->a_fx[k] = round_fx_o(L_mac_o(L_mult_o(temp, C_fx[temp2%(4*Lag)], &Overflow), X_fx->b_fx[k], S_fx[temp2%(4*Lag)], &Overflow), &Overflow) ; /* X.Q */
+ X_fx->b_fx[k] = round_fx_o(L_msu_o(L_mult_o(X_fx->b_fx[k], C_fx[temp2%(4*Lag)], &Overflow), temp, S_fx[temp2%(4*Lag)], &Overflow), &Overflow) ;
+ temp2 = add_o((Word16)temp2, negate(ph), &Overflow);
+#else
+ X_fx->a_fx[k] = round_fx(L_mac(L_mult(temp, C_fx[temp2%(4*Lag)]), X_fx->b_fx[k], S_fx[temp2%(4*Lag)])) ; /* X.Q */
+ X_fx->b_fx[k] = round_fx(L_msu(L_mult(X_fx->b_fx[k], C_fx[temp2%(4*Lag)]), temp, S_fx[temp2%(4*Lag)])) ;
+ temp2 = add((Word16)temp2, negate(ph));
+#endif
+ }
+ }
+}
+/*===================================================================*/
+/* FUNCTION : DTFS_zeroPadd_fx () */
+/*-------------------------------------------------------------------*/
+/* PURPOSE : zeroPadding */
+/*-------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (Word16) N_fx: length , Q0 */
+/*-------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ None. */
+/*-------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _ (struct DTFS_STRUCTURE) X_fx : a/b in X_fx.Q i.e Q6 */
+/* _ (Word16) lag: pitch lag of *X_fx, Q0 */
+/*-------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : _ None. */
+/*-------------------------------------------------------------------*/
+/* CALLED FROM : TX/RX */
+/*===================================================================*/
+
+void DTFS_zeroPadd_fx(
+ Word16 N_fx,
+ DTFS_STRUCTURE *X_fx
+)
+{
+ Word16 i, start, end ,diff_fx,rem_fx;
+
+ if (EQ_16(N_fx,X_fx->lag_fx))
+ {
+ return ;
+ }
+ start = add(shr(X_fx->lag_fx,1), 1);
+ end = shr(N_fx, 1);
+
+ move16();
+ FOR (i=start; i<=end; i++)
+ {
+ X_fx->a_fx[i]=0;
+ move16();
+ X_fx->b_fx[i]=0;
+ move16();
+ }
+
+ X_fx->lag_fx = N_fx ;
+ move16();
+
+ /* recompute nH for new lag */
+ diff_fx = find_rem(12800,X_fx->lag_fx,&rem_fx);
+ X_fx->nH_fx = find_rem(X_fx->upper_cut_off_freq_fx,diff_fx,&rem_fx);
+
+ if(GE_16(sub(X_fx->upper_cut_off_freq_fx,shr((Word16)L_mult(diff_fx,X_fx->nH_fx),1)),diff_fx))
+ {
+ X_fx->nH_fx = add(X_fx->nH_fx,1);
+ }
+}
+/*===================================================================*/
+/* FUNCTION : to_fs_fx () */
+/*-------------------------------------------------------------------*/
+/* PURPOSE : */
+/*-------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (Word16 *) x: input time domain series. Q0 */
+/* _ (Word16) N: Lag */
+/* _ (struct DTFS_STRUCTURE) PREVCW_FX: a/b in PREVCW_FX.Q */
+/* _ (Word16 *) S_fx: sin(2pi*n/(4*lag)) table, Q15 */
+/* _ (Word16 *) C_fx: cos(2pi*n/(4*lag)) table, Q15 */
+/*-------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ (struct DTFS_STRUCTURE) (Word16 a[]) : in Q */
+/* _ (struct DTFS_STRUCTURE) (Word16 b[]) : in Q */
+/* _ (struct DTFS_STRUCTURE) (Word16 lag) : Q0 */
+/* _ (struct DTFS_STRUCTURE) (Word16 Q ) : Q value of a/b */
+/*-------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _ None. */
+/*-------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : _ None. */
+/*-------------------------------------------------------------------*/
+/* CALLED FROM : TX/RX */
+/*===================================================================*/
+void DTFS_to_fs_fx(
+ const Word16 *x, /* i : time domain signal */
+ Word16 N, /* i : Length of input vector */
+ DTFS_STRUCTURE *X_fx, /* o : DTFS structure with a, b, lag */
+ const Word16 Fs, /* i : sampling rate */
+ const Word16 FR_flag, /* i : FR flag */
+ Word16 *S_fx,
+ Word16 *C_fx
+)
+
+{
+ Word16 n,temp,temp_neg,inv_lag,sum,diff_fx;
+ Word16 nH, k, nH_band, nH_4kHz;
+ Word32 L_temp, Lx0;
+ Word32 L_a, L_b,L_tmp;
+ Word32 La[MAXLAG_WI], Lb[MAXLAG_WI], Labmax;
+ Word16 exp,tmp;
+ Word32 L_tmp1;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+
+ IF (!FR_flag)
+ {
+ IF (EQ_16(Fs,16000))
+ {
+ X_fx->upper_cut_off_freq_of_interest_fx=4000;
+ move16();
+ X_fx->upper_cut_off_freq_fx=6400;
+ move16();
+ X_fx->Fs_fx=INT_FS_FX;
+ move16();
+ }
+ ELSE IF (EQ_16(Fs,8000))
+ {
+ X_fx->upper_cut_off_freq_of_interest_fx=3300;
+ move16();
+ X_fx->upper_cut_off_freq_fx=4000;
+ move16();
+ X_fx->Fs_fx=INT_FS_FX;
+ move16();
+ }
+ }
+ ELSE
+ {
+ X_fx->upper_cut_off_freq_of_interest_fx=8000;
+ move16();
+ X_fx->upper_cut_off_freq_fx=8000;
+ move16();
+ X_fx->Fs_fx=16000;
+ move16();
+ }
+ X_fx->lag_fx = N ;
+ move16();
+
+ exp = norm_s(X_fx->lag_fx);
+ tmp = div_s(shl(1,sub(14,exp)),X_fx->lag_fx); /* Q29-exp */
+#ifdef BASOP_NOGLOB
+ L_tmp1 = L_mult_o(12800,tmp, &Overflow); /* Q(30-exp) */
+ diff_fx = extract_h(L_shl_o(L_tmp1,sub(exp,14), &Overflow)); /* Q0 */
+#else
+ L_tmp1 = L_mult(12800,tmp); /* Q(30-exp) */
+ diff_fx = extract_h(L_shl(L_tmp1,sub(exp,14))); /* Q0 */
+#endif
+
+ exp = norm_s(diff_fx);
+ tmp = div_s(shl(1,sub(14,exp)),diff_fx); /* Q29-exp */
+#ifdef BASOP_NOGLOB
+ L_tmp1 = L_mult_o(X_fx->upper_cut_off_freq_fx,tmp, &Overflow); /* Q(30-exp) */
+ nH_band = extract_h(L_shl_o(L_tmp1,sub(exp,14), &Overflow)); /* Q0 */
+#else
+ L_tmp1 = L_mult(X_fx->upper_cut_off_freq_fx,tmp); /* Q(30-exp) */
+ nH_band = extract_h(L_shl(L_tmp1,sub(exp,14))); /* Q0 */
+#endif
+ nH_4kHz = mult(10240,(X_fx->lag_fx)); /* 4000/12800 in Q15 */
+
+ if(GE_16(sub(X_fx->upper_cut_off_freq_fx,shr((Word16)L_mult(diff_fx,nH_band),1)),diff_fx))
+ {
+ nH_band = add(nH_band,1);
+ }
+
+ if(GE_16(sub(4000,shr((Word16)L_mult(diff_fx,nH_4kHz),1)),diff_fx))
+ {
+ nH_4kHz = add(nH_4kHz,1);
+ }
+
+ /* Number of harmonics excluding the ones at 0 and at pi */
+ nH = shr(sub(N,1),1);
+
+ /* The DC component */
+ X_fx->a_fx[0] = 0 ;
+ move16();
+ X_fx->b_fx[0] = 0 ;
+ move16();
+
+ exp = norm_s(N);
+ tmp = div_s(shl(1,(sub(14,exp))),N);
+#ifdef BASOP_NOGLOB
+ L_tmp = L_shl_o(tmp,add(exp,6), &Overflow);
+ inv_lag = round_fx_o(L_tmp, &Overflow);
+#else
+ L_tmp = L_shl(tmp,add(exp,6));
+ inv_lag = round_fx(L_tmp);
+#endif
+ Lx0 = L_deposit_h(x[0]);
+ Labmax = L_deposit_l(0);
+ FOR ( k=1; k<=nH; k++ )
+ {
+ L_a = L_shr(Lx0,1) ; /* Q16 */
+
+ L_b = L_deposit_l(0);
+ sum = k;
+ move16();
+ temp = k;
+ move16();
+ FOR ( n=1; nb_fx[k] = 0 ;
+ move16();
+ }
+
+ temp = norm_l(Labmax);
+ if (Labmax==0)
+ {
+ temp = 31;
+ move16();
+ }
+
+ FOR ( k=1; k<=nH; k++ )
+ {
+#ifdef BASOP_NOGLOB
+ X_fx->a_fx[k]=round_fx_o(L_shl_o(La[k], temp, &Overflow), &Overflow); /* Q(8+temp-16)=Q(temp-8) */
+ X_fx->a_fx[k]=mult_ro(X_fx->a_fx[k], inv_lag, &Overflow);
+ move16(); /* Q(temp-8+19+1-16)=Q(temp-4) of a[k]*2.0/N */
+ X_fx->b_fx[k]=round_fx_o(L_shl_o(Lb[k], temp, &Overflow), &Overflow); /* Q(8+temp-16)=Q(temp-8) */
+ X_fx->b_fx[k]=mult_ro(X_fx->b_fx[k], inv_lag, &Overflow);
+ move16(); /* Q(temp-8+19+1-16)=Q(temp-4) of b[k]*2.0/N */
+#else
+ X_fx->a_fx[k]=round_fx(L_shl(La[k], temp)); /* Q(8+temp-16)=Q(temp-8) */
+ X_fx->a_fx[k]=mult_r(X_fx->a_fx[k], inv_lag);
+ move16(); /* Q(temp-8+19+1-16)=Q(temp-4) of a[k]*2.0/N */
+ X_fx->b_fx[k]=round_fx(L_shl(Lb[k], temp)); /* Q(8+temp-16)=Q(temp-8) */
+ X_fx->b_fx[k]=mult_r(X_fx->b_fx[k], inv_lag);
+ move16(); /* Q(temp-8+19+1-16)=Q(temp-4) of b[k]*2.0/N */
+#endif
+ }
+
+ /* IF ( N%2 == 0 ) */
+ IF ( s_and(N,1) == 0 )
+ {
+#ifdef BASOP_NOGLOB
+ X_fx->a_fx[k]=round_fx_o(L_shl_o(La[k], temp, &Overflow), &Overflow); /* Q(8+temp-16)=Q(temp-8) */
+ X_fx->a_fx[k]=mult_ro(X_fx->a_fx[k], inv_lag, &Overflow);
+#else
+ X_fx->a_fx[k]=round_fx(L_shl(La[k], temp)); /* Q(8+temp-16)=Q(temp-8) */
+ X_fx->a_fx[k]=mult_r(X_fx->a_fx[k], inv_lag);
+#endif
+ move16(); /* Q(temp-8+19+1-16)=Q(temp-4) of a[k]*1.0/N */
+ X_fx->b_fx[k]=0;
+ move16();
+ }
+
+ X_fx->Q=sub(temp, 4);
+
+ tmp = s_min(shr(X_fx->lag_fx,1),sub(MAXLAG_WI,1));
+ FOR(k=add(nH_band,1); k<=tmp; k++)
+ {
+ X_fx->a_fx[k]=0;
+ move16();
+ X_fx->b_fx[k]=0;
+ move16();
+ }
+ X_fx->nH_fx=nH_band;
+ move16();
+ X_fx->nH_4kHz_fx=nH_4kHz;
+ move16();
+ return;
+}
+
+
+/*===================================================================*/
+/* FUNCTION : DTFS_transform_fx () */
+/*-------------------------------------------------------------------*/
+/* PURPOSE : */
+/*-------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (struct DTFS_STRUCTURE) X_fx: a/b in X1.Q, lag in Q0 */
+/* _ (struct DTFS_STRUCTURE) X2_fx. a/b in X2.Q, lag in Q0 */
+/* _ (Word16 *) phase_fx: 2pi normalized, Q12 */
+/* _ (Word16) N: length of series. */
+/*-------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ (Word16 *) out_fx: output transformed series. Q0. */
+/*-------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _ None. */
+/*-------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : _ None. */
+/*-------------------------------------------------------------------*/
+/* CALLED FROM : TX/RX */
+/*===================================================================*/
+static void DTFS_transform_fx(
+ DTFS_STRUCTURE X_fx, /* i : Starting DTFS to use in WI */
+ DTFS_STRUCTURE X2_fx, /* i : Ending DTFS to use in WI */
+ const Word32 *phase_fx, /* i : Phase contour */
+ Word16 *out_fx, /* o : Output time domain waveform */
+ Word16 N, /* i : Number of samples to generate */
+ const Word16 FR_flag /* i : Flag to indicate called in FR context */
+)
+{
+
+ Word16 i, j ;
+ Word32 L_temp_fx;
+ Word16 w_fx;
+ Word16 inv1_fx, inv2_fx, inv_fx, q1, q2;
+ Word32 Lw_fx,temp32_fx;
+ Word16 x2_256_fx[256], x1_256_fx[256];
+ Word16 k, m, l1;
+ Word32 x_r_fx[256] = { 0 };
+ Word32 tmptmp3_40_fx;
+ Word16 temp_w;
+ Word16 N1;
+ Word16 nrg_flag = 0;
+ Word32 L_tmp;
+ Word16 tmp, tmp1, tmp2, frac, exp1, exp2;
+ Word16 expa, expb, fraca, fracb, scale;
+
+ ivas_error error;
+
+ DTFS_STRUCTURE* tmp1_dtfs_fx;
+ DTFS_STRUCTURE* tmp2_dtfs_fx;
+ DTFS_STRUCTURE* tmp3_dtfs_fx;
+
+ error = IVAS_ERR_OK;
+
+ IF ((error = DTFS_new_fx(&tmp1_dtfs_fx)) != IVAS_ERR_OK)
+ {
+ IVAS_ERROR(error, "Error creating DTFS structure 1");
+ }
+ IF ((error = DTFS_new_fx(&tmp2_dtfs_fx)) != IVAS_ERR_OK)
+ {
+ IVAS_ERROR(error, "Error creating DTFS structure 2");
+ }
+ IF ((error = DTFS_new_fx(&tmp3_dtfs_fx)) != IVAS_ERR_OK)
+ {
+ IVAS_ERROR(error, "Error creating DTFS structure 3");
+ }
+
+ DTFS_copy_fx(tmp1_dtfs_fx,X_fx);
+ DTFS_copy_fx(tmp2_dtfs_fx,X2_fx);
+
+ tmp2 = 0; /* to avoid compilation warnings */
+
+
+ DTFS_fast_fs_inv_fx(tmp1_dtfs_fx,x1_256_fx,256,8);
+ DTFS_fast_fs_inv_fx(tmp2_dtfs_fx,x2_256_fx,256,8);
+
+
+
+ /* L_temp_fx=invert_dp((Word40)N,4,&n,1); = 1/M, Q(61-n) */
+ /* inv1_fx=round_fx(L_temp_fx); = 1/M in Q(45-n) */
+ /* q1=sub(n,15); */
+ exp1 = norm_s(N);
+ inv1_fx = div_s(shl(1,sub(14,exp1)),N); /* 29-exp1 */
+ q1=add(exp1,1);
+
+ tmp1 = sub(X_fx.lag_fx,N);
+ exp2 = norm_s(tmp1);
+
+ if(tmp1<0)
+ {
+ tmp2 = negate(tmp1);
+ }
+ tmp = div_s(shl(1,(14- exp2)),tmp2); /* 29-exp2 */
+ L_tmp = L_shl(tmp,16);
+
+ if(tmp1<0)
+ {
+ L_tmp = L_negate(L_tmp);
+ }
+
+ q2=sub(exp2,3);
+
+
+
+ /*L_temp_fx=(Word32) Mpy_32_16(extract_h(L_tmp),extract_l(L_tmp),22904); move32(); */ /* L_temp=log(0.2)*log10(e)/(lag-M), Q(61-n) */
+ L_temp_fx= Mult_32_16(L_tmp,22904); /* L_temp=log(0.2)*log10(e)/(lag-M), Q(61-n) */
+ inv2_fx=round_fx(L_temp_fx); /* log(0.2)*log10(e)/(lag-M), Q(45-n) */
+ /* q2=sub(n,19); */ /* adjust Q factor to Q26 */
+
+
+ IF (GT_16(sub(N, WI_SAMPLE_THLD), X_fx.lag_fx))
+ {
+ inv_fx = inv2_fx;
+ move16();
+ }
+ ELSE
+ {
+ inv_fx = inv1_fx;
+ move16();
+ exp2 = exp1;
+ move16();
+ }
+
+ Lw_fx = L_deposit_l(inv_fx);
+
+ FOR (i=0; i 16+13+1 */ /*27-exp2 */
+ L_tmp = L_shl(L_tmp, sub(exp2,add(q2,11)));
+ frac = L_Extract_lc(L_tmp, &exp1); /* Extract exponent */
+ L_temp_fx =Pow2(14, frac);
+ exp1 = sub(exp1,14);
+ L_temp_fx = L_shl(L_temp_fx,add(exp1,15)); /* Q15 */
+
+ w_fx=sub(16384,extract_h(L_shl(L_temp_fx,15))); /* w_fx in Q14 1- exp(- (i+1) * log(.2)/(lag-M)) */
+ }
+ ELSE
+ {
+ w_fx=round_fx(L_shl(Lw_fx,q1)); /* Q14 */
+ }
+ }
+ ELSE
+ {
+ IF (nrg_flag)
+ {
+ w_fx=round_fx(L_shl(Lw_fx,q1)); /* Q14 */
+ }
+ ELSE
+ {
+
+ N1 = sub(N , tmp2_dtfs_fx->lag_fx);
+
+ IF (LT_16(i,N1))
+ /* w = (i+1)/N1; */
+ {
+
+ /* w = (i+1)/N1; */
+ IF(N1)
+ {
+ expa = norm_s(N1);
+ fraca = shl(N1,expa);
+ expa = sub(14,expa);
+
+ tmp = add(i,1);
+ expb = norm_s(tmp);
+ fracb = shl(tmp,expb);
+ expb = sub(14,expb);
+
+ scale = shr(sub(fraca,fracb),15);
+ fracb = shl(fracb,scale);
+ expb = sub(expb,scale);
+
+ w_fx = div_s(fracb,fraca);
+ exp1 = sub(expb,expa);
+ w_fx = shl(w_fx,exp1-1); /*Q14*/
+ }
+ ELSE
+ {
+ w_fx = 0;
+ }
+
+ Lw_fx=L_deposit_h(w_fx);
+
+
+ }
+ ELSE
+ {
+ w_fx = 16384;
+ move16();
+ }
+ }
+ }
+
+ Lw_fx=L_add(Lw_fx,inv_fx); /* (i+1)*inv */
+ /* mapping phase to 8x256 length signal */
+ temp32_fx = phase_fx[i]; /* Q(27-11)=Q16 due to multiplication by pow(2.0,11) */
+ j = rint_new_fx(temp32_fx);
+ j = s_and(j,0x07ff);
+
+ /* k=j%8; */
+ k=s_and(j,7);
+ l1=shr(j,3); /* reminder and quotient */
+
+ temp_w = sub( 16384, w_fx );
+ tmptmp3_40_fx = L_deposit_l(0);
+
+ FOR (j=0; j<12; j++)
+ {
+ m=(1000*LL+l1-OSLENGTH/2+j)%LL; /* use circular addressing */
+ x_r_fx[m] = L_mac( L_mult( x1_256_fx[m], temp_w), x2_256_fx[m], w_fx);
+ }
+ tmptmp3_40_fx = L_deposit_l(0);
+
+
+ FOR (j=0; j<12; j++)
+ {
+ m=(1000*LL+l1-OSLENGTH/2+j)%LL; /* use circular addressing */
+ tmptmp3_40_fx=L_add(tmptmp3_40_fx, Mult_32_16(x_r_fx[m],sinc_fx[k][j]));
+
+ }
+ out_fx[i] = round_fx(L_shl(tmptmp3_40_fx,2));
+ }
+
+
+ count_free(tmp1_dtfs_fx);
+ count_free(tmp2_dtfs_fx);
+ count_free(tmp3_dtfs_fx);
+ return;
+}
+/*===================================================================*/
+/* FUNCTION : zeroFilter_fx() */
+/*-------------------------------------------------------------------*/
+/* PURPOSE : zero filtering */
+/*-------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (Word16) lpc[] : lpc coefficients in Q12 */
+/* _ (Word16) N : lpc order */
+/* _ (Word16) this->lag: in Q0 */
+/* _ (Word16 *) S_fx: sin(2pi*n/(4*lag)) table, Q15 */
+/* _ (Word16 *) C_fx: cos(2pi*n/(4*lag)) table, Q15 */
+/*-------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ None. */
+/*-------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _ (Word16) this->a[] : in Q(this->Q) */
+/* _ (Word16) this->b[] : in Q(this->Q) */
+/* _ (Word16) this->Q: in Q0 */
+/*-------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : _ None. */
+/*-------------------------------------------------------------------*/
+/* CALLED FROM : TX/RX */
+/*===================================================================*/
+
+void DTFS_zeroFilter_fx(
+ DTFS_STRUCTURE *X_fx,
+ Word16 *LPC,
+ Word16 N,
+ Word16 *S_fx,
+ Word16 *C_fx
+)
+{
+ Word32 sum1_fx, sum2_fx ;
+ Word16 k, n, HalfLag ;
+ Word16 temp, temp1, temp2;
+ Word32 L_temp1, L_temp2;
+ Word16 Qmin, Qab[MAXLAG_WI], na, nb;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+ Qmin = 32767;
+ move16();
+ HalfLag = s_min(shr(X_fx->lag_fx, 1),X_fx->nH_fx);
+ FOR ( k=0 ; k<=HalfLag ; k++ )
+ {
+ temp = k;
+ move16();
+ temp2 = k;
+ move16();
+
+ /* Calculate sum1 and sum2 */
+ sum1_fx = L_deposit_h(4096); /* 1: Q(12+15+1) */
+ sum2_fx = L_deposit_l(0);
+
+ FOR ( n=0 ; nlag_fx)], &Overflow) ; /* Q(12+15+1) */
+ sum2_fx = L_mac_o(sum2_fx, LPC[n], S_fx[(4*temp2)%(4*X_fx->lag_fx)], &Overflow) ;
+#else
+ sum1_fx = L_mac(sum1_fx, LPC[n], C_fx[(4*temp2)%(4*X_fx->lag_fx)]) ; /* Q(12+15+1) */
+ sum2_fx = L_mac(sum2_fx, LPC[n], S_fx[(4*temp2)%(4*X_fx->lag_fx)]) ;
+#endif
+ temp2 = add(temp2, temp);
+ }
+
+#ifdef BASOP_NOGLOB
+ temp1 = round_fx_o(sum1_fx, &Overflow); /* Q(12+15+1-16)=Q(12) */
+ temp2 = round_fx_o(sum2_fx, &Overflow); /* Q(12) */
+
+ /* Calculate the circular convolution */
+ L_temp1 = L_mult_o(temp1, X_fx->a_fx[k], &Overflow);
+ L_temp1 = L_msu_o(L_temp1, temp2, X_fx->b_fx[k], &Overflow); /* Q(12+Q+1) */
+ L_temp2 = L_mult_o(temp1, X_fx->b_fx[k], &Overflow);
+ L_temp2 = L_mac_o(L_temp2, temp2, X_fx->a_fx[k], &Overflow); /* Q(12+Q+1) */
+#else
+ temp1 = round_fx(sum1_fx); /* Q(12+15+1-16)=Q(12) */
+ temp2 = round_fx(sum2_fx); /* Q(12) */
+
+ /* Calculate the circular convolution */
+ L_temp1 = L_mult(temp1, X_fx->a_fx[k]);
+ L_temp1 = L_msu(L_temp1, temp2, X_fx->b_fx[k]); /* Q(12+Q+1) */
+ L_temp2 = L_mult(temp1, X_fx->b_fx[k]);
+ L_temp2 = L_mac(L_temp2, temp2, X_fx->a_fx[k]); /* Q(12+Q+1) */
+#endif
+ /* normalization */
+ na = norm_l(L_temp1);
+ if (L_temp1==0)
+ {
+ na=31;
+ move16();
+ }
+ nb = norm_l(L_temp2);
+ if (L_temp2==0)
+ {
+ nb=31;
+ move16();
+ }
+
+ if (LT_16(na, nb))
+ {
+ nb=na;
+ move16();
+ }
+#ifdef BASOP_NOGLOB
+ X_fx->a_fx[k] = round_fx_o((Word32)L_shl_o(L_temp1, nb, &Overflow), &Overflow); /* Q(13+Q+nb-16)=Q(Q+nb-3) */
+ X_fx->b_fx[k] = round_fx_o((Word32)L_shl_o(L_temp2, nb, &Overflow), &Overflow); /* Q(Q+nb-3) */
+#else
+ X_fx->a_fx[k] = round_fx((Word32)L_shl(L_temp1, nb)); /* Q(13+Q+nb-16)=Q(Q+nb-3) */
+ X_fx->b_fx[k] = round_fx((Word32)L_shl(L_temp2, nb)); /* Q(Q+nb-3) */
+#endif
+
+ Qab[k] = sub(nb, 3);
+
+ if (LT_16(Qab[k], Qmin))
+ {
+ Qmin = Qab[k];
+ move16();
+ }
+ }
+ /* bring to the same Q */
+ FOR ( k=0 ; k<=HalfLag ; k++ )
+ {
+#ifdef BASOP_NOGLOB
+ X_fx->a_fx[k] = shl_o(X_fx->a_fx[k], sub(Qmin, Qab[k]), &Overflow);
+ move16(); /* Q(Q+Qab[k]+Qmin-Qab[k]=Q(Q+Qmin) */
+ X_fx->b_fx[k] = shl_o(X_fx->b_fx[k], sub(Qmin, Qab[k]), &Overflow);
+ move16(); /* Q(Q+Qmin) */
+#else
+ X_fx->a_fx[k] = shl(X_fx->a_fx[k], sub(Qmin, Qab[k]));
+ move16(); /* Q(Q+Qab[k]+Qmin-Qab[k]=Q(Q+Qmin) */
+ X_fx->b_fx[k] = shl(X_fx->b_fx[k], sub(Qmin, Qab[k]));
+ move16(); /* Q(Q+Qmin) */
+#endif
+ }
+
+ X_fx->Q = add(X_fx->Q, Qmin);
+ move16();
+ return;
+}
+/*===================================================================*/
+/* FUNCTION : DTFS_poleFilter_fx() */
+/*-------------------------------------------------------------------*/
+/* PURPOSE : pole filtering */
+/*-------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (Word16) lpc[] : lpc coefficients in Q12 */
+/* _ (Word16) N : lpc order */
+/* _ (Word16) lag: in Q0 */
+/* _ (Word16 *) C_fx: cos(2pi*n/(4*lag)) table, Q15 */
+/* _ (Word16 *) S_fx: sin(2pi*n/(4*lag)) table, Q15 */
+/* _ (Word16 *) C_fx: cos(2pi*n/(4*lag)) table, Q15 */
+/*-------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ None */
+/*-------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _ (Word16) this->a[] : in Q(this->Q) */
+/* _ (Word16) this->b[] : in Q(this->Q) */
+/* _ (Word16) this->Q: in Q0 */
+/*-------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : _ None. */
+/*-------------------------------------------------------------------*/
+/* CALLED FROM : TX/RX */
+/*===================================================================*/
+
+/* PORTING: Handling the functions with variable no. of arguments */
+
+void DTFS_poleFilter_fx_9(
+ DTFS_STRUCTURE *X_fx,
+ Word16 *pf_temp1,
+ Word16 *pf_temp2,
+ Word16 *pf_temp,
+ Word16 *pf_n2_temp1
+)
+{
+ Word16 temp, temp1, temp2, HalfLag ;
+ Word32 sum1_fx, sum2_fx;
+ Word32 L_temp1, L_temp2;
+ Word16 k,n2_temp1, na, nb;
+ Word16 Qmin, Qab[MAXLAG_WI];
+
+ Qmin = 32767;
+ move16();
+ HalfLag = s_min(shr(X_fx->lag_fx, 1),X_fx->nH_fx);
+ FOR ( k=0; k<=HalfLag; k++ )
+ {
+ temp = temp2 = k;
+ move16();
+ move16();
+ /* Calculate sum1 and sum2 */
+
+ n2_temp1 = pf_n2_temp1[k];
+ move16();
+
+ temp1 = pf_temp1[k];
+ move16();/* Q(12+15+1+n2-16)=Q(12+n2) */
+ temp2 = pf_temp2[k];
+ move16();/* Q(12+n2) */
+
+ /* Calculate the circular convolution */
+
+ L_temp1 = L_mac(L_mult(temp1, X_fx->a_fx[k]), temp2, X_fx->b_fx[k]); /* Q(12+n2+Q+1)=Q(13+n2+Q) */
+ L_temp2 = L_msu(L_mult(temp1, X_fx->b_fx[k]), temp2, X_fx->a_fx[k]); /* Q(12+n2+Q+1)=Q(13+n2+Q) */
+
+ temp = pf_temp[k];
+ move16(); /* Q(61-25-2*n2-temp1-16)=Q(20-2*n2-temp1) */
+
+ sum1_fx = Mult_32_16(L_temp1, temp); /* Q(13+n2+Q+15+exp-15) = Q(13+n2+Q+exp) */
+ sum2_fx = Mult_32_16(L_temp2, temp);
+ /* normalization */
+ na = norm_l(sum1_fx);
+ if(sum1_fx==0)
+ {
+ na = 31;
+ move16();
+ }
+ nb = norm_l(sum2_fx);
+ if(sum2_fx==0)
+ {
+ nb = 31;
+ move16();
+ }
+
+ if (LT_16(na, nb))
+ {
+ nb=na;
+ move16();
+ }
+ nb=sub(nb,1); /* leave one more sign bit */
+ X_fx->a_fx[k] = round_fx((Word32)L_shl(sum1_fx, nb)); /* Q(-3+n2+Q+exp+nb ) */
+ X_fx->b_fx[k] = round_fx((Word32)L_shl(sum2_fx, nb));
+
+ Qab[k] = add(sub(nb, 3), n2_temp1);
+
+ if (LT_16(Qab[k], Qmin))
+ {
+ Qmin = Qab[k];
+ move16();
+ }
+ }
+ /* bring to the same Q */
+ move16();
+ FOR ( k=0; k<=HalfLag; k++ )
+ {
+ X_fx->a_fx[k] = shl(X_fx->a_fx[k], sub(Qmin, Qab[k]));
+ move16(); /* Q(Q+Qab[k]+Qmin-Qab[k])=Q(Q+Qmin) */
+ X_fx->b_fx[k] = shl(X_fx->b_fx[k], sub(Qmin, Qab[k]));
+ move16(); /* Q(Q+Qab[k]+Qmin-Qab[k])=Q(Q+Qmin) */
+ }
+
+ X_fx->Q = add(X_fx->Q, Qmin);
+ return;
+}
+/*===================================================================*/
+/* FUNCTION : DTFS_adjustLag_fx () */
+/*-------------------------------------------------------------------*/
+/* PURPOSE : */
+/*-------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (Word16) N_fx: lag value, Q0 */
+/*-------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ (struct DTFS_fx) : a/b in X1.Q */
+/*-------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _ (struct DTFS_fx) X1 : lag in Q0 */
+/*-------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : _ None. */
+/*-------------------------------------------------------------------*/
+/* CALLED FROM : TX/RX */
+/*===================================================================*/
+
+void DTFS_adjustLag_fx(
+ DTFS_STRUCTURE *X_DTFS_FX, /* i/o : DTFS to adjust lag for */
+ Word16 N_fx /* i : Target lag */
+)
+{
+ Word32 en_fx;
+ Word32 temp32_fx,tempnH_fx,mul1_fx,mul2_fx;
+ Word16 k,diff_fx;
+ Word16 exp,tmp;
+ Word32 L_tmp;
+
+ if (EQ_16(N_fx,X_DTFS_FX->lag_fx))
+ {
+ return ;
+ }
+
+ IF(GT_16(N_fx,X_DTFS_FX->lag_fx))
+ {
+ DTFS_zeroPadd_fx(N_fx,X_DTFS_FX);
+ }
+ ELSE
+ {
+ en_fx = DTFS_getEngy_fx(X_DTFS_FX); /* Q = 2*(X_DTFS_FX->Q) */
+
+ tmp = s_min(shr(X_DTFS_FX->lag_fx,1),X_DTFS_FX->nH_fx);
+ FOR( k = add(shr(N_fx,1),1) ; k<= tmp ; k++)
+ {
+ X_DTFS_FX->a_fx[k] = 0;
+ move16();
+ X_DTFS_FX->b_fx[k] = 0;
+ move16();
+ }
+ DTFS_setEngy_fx(X_DTFS_FX,en_fx);
+ X_DTFS_FX->lag_fx = N_fx ;
+ move16();
+
+
+ /* recompute nH for new lag */
+ exp = norm_s(X_DTFS_FX->lag_fx);
+ tmp = div_s(shl(1,sub(14,exp)),X_DTFS_FX->lag_fx);/* 29 - exp */
+ L_tmp = L_mult0(12800,tmp);
+ temp32_fx = L_shl(L_tmp,sub(exp,23));
+ diff_fx = (Word16) L_shl(L_tmp,sub(exp,29));
+
+
+ exp = norm_s(diff_fx);
+ tmp = div_s(shl(1,sub(14,exp)),diff_fx);/* 29 - exp */
+ L_tmp = L_mult0(X_DTFS_FX->upper_cut_off_freq_fx,tmp);
+ X_DTFS_FX->nH_fx = (Word16) L_shl(L_tmp,sub(exp,29));
+
+ L_tmp = L_mult0(4000,tmp);
+ tempnH_fx = L_shl(L_tmp,sub(exp,23));
+ X_DTFS_FX->nH_4kHz_fx = extract_l(L_shl(L_tmp, sub(exp,29)));
+
+
+ if(GE_16(sub(X_DTFS_FX->upper_cut_off_freq_fx, shr((Word16)L_mult(diff_fx,X_DTFS_FX->nH_fx),1)), diff_fx))
+ {
+ X_DTFS_FX->nH_fx = add(X_DTFS_FX->nH_fx,1);
+ move16();
+ }
+
+ mul1_fx = L_shl(temp32_fx,13);/* Q19 */
+ mul2_fx = L_shl((Word32)X_DTFS_FX->nH_4kHz_fx,18);/* Q18 */
+ tempnH_fx = Mult_32_32(mul1_fx,mul2_fx);/* Q6 */
+ tempnH_fx = L_sub((Word32)256000,tempnH_fx);/* Q6 */
+
+ if(GE_32(tempnH_fx,temp32_fx))
+ {
+ X_DTFS_FX->nH_4kHz_fx = add(X_DTFS_FX->nH_4kHz_fx,1);
+ move16();
+ }
+ }
+ return;
+}
+/*===================================================================*/
+/* FUNCTION : DTFS_getEngy_fx () */
+/*-------------------------------------------------------------------*/
+/* PURPOSE : */
+/*-------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (struct DTFS_STRUCTURE) : a/b in X_fx.Q i.e Q6, lag in Q0*/
+/*-------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : _ None */
+/*-------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : _ None */
+/*-------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : */
+/* _ (Word40) en_fx: output energy, 2*X1.Q */
+/*-------------------------------------------------------------------*/
+/* CALLED FROM : TX/RX */
+/*===================================================================*/
+
+
+Word32 DTFS_getEngy_fx(
+ DTFS_STRUCTURE *X_fx
+)
+{
+ Word16 k, HalfLag_fx;
+ Word32 en_fx=0;
+ Word16 temp_a_fx,temp_b_fx;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+ HalfLag_fx = shr(sub(X_fx->lag_fx, 1), 1);
+ HalfLag_fx = s_min(HalfLag_fx,X_fx->nH_fx);
+ FOR (k=1; k<=HalfLag_fx; k++)
+ {
+ temp_a_fx = X_fx->a_fx[k];
+ move16();
+ temp_b_fx = X_fx->b_fx[k];
+ move16();
+
+#ifdef BASOP_NOGLOB
+ en_fx = L_mac0_o(en_fx, temp_a_fx, temp_a_fx, &Overflow);
+ en_fx = L_mac0_o(en_fx, temp_b_fx, temp_b_fx, &Overflow);
+#else
+ en_fx = L_mac0(en_fx, temp_a_fx, temp_a_fx);
+ en_fx = L_mac0(en_fx, temp_b_fx, temp_b_fx);
+#endif
+ }
+
+ en_fx = L_shr(en_fx, 1);
+ temp_a_fx = X_fx->a_fx[0];
+#ifdef BASOP_NOGLOB
+ en_fx = L_mac0_o(en_fx,temp_a_fx, temp_a_fx, &Overflow);
+#else
+ en_fx = L_mac0(en_fx,temp_a_fx, temp_a_fx);
+#endif
+ /* IF (X_fx->lag_fx%2 == 0) */
+ IF (s_and(X_fx->lag_fx,1) == 0)
+ {
+ temp_a_fx = X_fx->a_fx[k];
+ move16();
+ temp_b_fx = X_fx->b_fx[k];
+ move16();
+
+#ifdef BASOP_NOGLOB
+ en_fx = L_mac0_o(en_fx, temp_a_fx, temp_a_fx, &Overflow);
+ en_fx = L_mac0_o(en_fx, temp_b_fx, temp_b_fx, &Overflow);
+#else
+ en_fx = L_mac0(en_fx, temp_a_fx, temp_a_fx);
+ en_fx = L_mac0(en_fx, temp_b_fx, temp_b_fx);
+#endif
+ }
+
+ return en_fx ; /* 2*X1.Q+1=Q13 */
+}
+
+
+
+/*===================================================================*/
+/* FUNCTION : DTFS_getEngy_P2A_fx () */
+/*-------------------------------------------------------------------*/
+/* PURPOSE : */
+/*-------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (struct DTFS_STRUCTURE) : a/b in X_fx.Q, lag in Q0 */
+/*-------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : _ None */
+/*-------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : _ None */
+/*-------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : */
+/* _ (Word40) en_fx: output energy, 2*X1.Q */
+/*-------------------------------------------------------------------*/
+/* CALLED FROM : TX/RX */
+/*===================================================================*/
+
+Word32 DTFS_getEngy_P2A_fx(
+ DTFS_STRUCTURE *X_fx
+)
+{
+ Word16 k, HalfLag_fx;
+ Word32 en_fx=0;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+ HalfLag_fx = shr(sub(X_fx->lag_fx, 1), 1);
+ HalfLag_fx = s_min(HalfLag_fx,X_fx->nH_fx);
+ FOR (k=1; k<=HalfLag_fx; k++)
+ {
+#ifdef BASOP_NOGLOB
+ en_fx = L_mac0_o(en_fx, X_fx->a_fx[k], X_fx->a_fx[k], &Overflow);
+ en_fx = L_mac0_o(en_fx, X_fx->b_fx[k], X_fx->b_fx[k], &Overflow);
+#else
+ en_fx = L_mac0(en_fx, X_fx->a_fx[k], X_fx->a_fx[k]);
+ en_fx = L_mac0(en_fx, X_fx->b_fx[k], X_fx->b_fx[k]);
+#endif
+ }
+ en_fx = L_shr(en_fx, 1);
+#ifdef BASOP_NOGLOB
+ en_fx = L_mac0_o(en_fx,X_fx->a_fx[0], X_fx->a_fx[0], &Overflow);
+#else
+ en_fx = L_mac0(en_fx,X_fx->a_fx[0], X_fx->a_fx[0]);
+#endif
+ /* IF (X_fx->lag_fx%2 == 0) */
+ IF (s_and(X_fx->lag_fx,1) == 0)
+ {
+#ifdef BASOP_NOGLOB
+ en_fx = L_mac0_o(en_fx, X_fx->a_fx[k], X_fx->a_fx[k], &Overflow);
+ en_fx = L_mac0_o(en_fx, X_fx->b_fx[k], X_fx->b_fx[k], &Overflow);
+#else
+ en_fx = L_mac0(en_fx, X_fx->a_fx[k], X_fx->a_fx[k]);
+ en_fx = L_mac0(en_fx, X_fx->b_fx[k], X_fx->b_fx[k]);
+#endif
+ }
+
+ return en_fx ; /* 2*X1.Q */
+}
+
+
+
+/*===================================================================*/
+/* FUNCTION : DTFS_setEngy_fx ( ) */
+/*-------------------------------------------------------------------*/
+/* PURPOSE : */
+/*-------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (Word40) en2_fx: 2*X1.Q+1 i.e. Q13 */
+/*-------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ (Word40) en1_fx : 2*X1.Q+1 i.e. Q13 */
+/*-------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _ (struct DTFS_STRUCTURE) X_DTFS_FX : a/b in X1.Q i.e. Q6, */
+/* lag in Q0 */
+/*-------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : _ None. */
+/*-------------------------------------------------------------------*/
+/* CALLED FROM : TX/RX */
+/*===================================================================*/
+
+static Word32 DTFS_setEngy_fx(
+ DTFS_STRUCTURE *X_DTFS_FX,
+ Word32 en2_fx
+)
+{
+ Word16 k, HalfLag_fx ;
+ Word32 en1_fx;
+ Word32 L_temp_fx;
+ Word16 expa,expb,fraca,fracb,scale,tmp,exp;
+ Word32 L_tmp,factor_fx;
+
+ HalfLag_fx = s_min(shr(X_DTFS_FX->lag_fx, 1),X_DTFS_FX->nH_fx);
+ move16();
+ en1_fx = DTFS_getEngy_fx(X_DTFS_FX);
+ move16();
+
+ if (en1_fx == 0)
+ {
+ return 0;
+ }
+
+ IF (en2_fx==0)
+ {
+ factor_fx=0;
+ }
+ ELSE
+ {
+ expa = norm_l(en2_fx);
+ fraca = extract_h(L_shl(en2_fx,expa));
+ expa = sub(30, add(expa,shl(X_DTFS_FX->Q, 1)));
+
+
+ expb = norm_l(en1_fx);
+ fracb = round_fx(L_shl(en1_fx,expb));
+ expb = sub(30, add(expb, shl(X_DTFS_FX->Q, 1)));
+
+
+ scale = shr(sub(fraca,fracb),15);
+ fracb = shl(fracb,scale);
+ expb = sub(expb,scale);
+
+ tmp = div_s(fracb,fraca);
+ exp = sub(expb,expa);
+
+ L_tmp = Isqrt_lc(L_deposit_h(tmp),&exp); /* Q(31-exp) */
+ factor_fx = L_shr(L_tmp,1);
+
+ }
+
+ FOR (k=0; k<=HalfLag_fx; k++)
+ {
+ L_temp_fx = Mult_32_16(factor_fx, X_DTFS_FX->a_fx[k]); /* Q(temp+X1.Q-15) */
+ X_DTFS_FX->a_fx[k] = round_fx(L_temp_fx); /* Q(temp+X1.Q-15-16)=Q(temp+X1.Q-31); */
+
+ L_temp_fx =Mult_32_16(factor_fx, X_DTFS_FX->b_fx[k]); /* Q(temp+X1.Q-15) */
+ X_DTFS_FX->b_fx[k] = round_fx(L_temp_fx); /* Q(temp+X1.Q-15-16)=Q(temp+X1.Q-31); */
+
+ }
+
+
+ return en1_fx ;/* 2*X1.Q+1 = Q13 */
+}
+
+/*===================================================================*/
+/* FUNCTION : struct DTFS_car2pol_fx () */
+/*-------------------------------------------------------------------*/
+/* PURPOSE : Cartesian to polar representation */
+/* returning amplitudes and 0 phases */
+/*-------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (struct DTFS_STRUCTURE) X_fx : prototype in Cartesian domain*/
+/* (Word16) lag: length of prototype in time domain */
+/* (Word16 []) a,b: re/im of harmonics, normalized */
+/* (Word16) Q: norm factor of a/b */
+/*-------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ (struct DTFS_STRUCTURE) X_fx : prototype in polar domain */
+/* (Word16) lag: length of prototype in time domain */
+/* (Word16 []) a: amplitude of harmonics, normalized */
+/* (Word16 []) b: phase of harmonics,cleared to 0 */
+/* (Word16) Q: norm factor of a */
+/*-------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _ None */
+/*-------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : _ None. */
+/*-------------------------------------------------------------------*/
+/* CALLED FROM : TX/RX */
+/*===================================================================*/
+/* NOTE: output X.b (angle) is not computed and should be ignored */
+/* When phases are needed, such as in QPPP, instead uses the */
+/* Cartesian representation to avoid computing phases by arctan*/
+/*===================================================================*/
+void DTFS_car2pol_fx(
+ DTFS_STRUCTURE *X_fx /* i/o : DTFS structure a, b, lag */
+)
+
+{
+ Word16 k, HalfLag_fx ;
+ Word32 Ltemp_fx;
+ Word32 Lacc_fx;
+ Word16 exp,tmp,frac;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+ HalfLag_fx = s_min(shr(sub(X_fx->lag_fx,1),1),X_fx->nH_fx);
+ FOR ( k=1 ; k<=HalfLag_fx; k++ )
+ {
+
+ Lacc_fx=L_mult(X_fx->a_fx[k],X_fx->a_fx[k]); /* a[k]^2, 2Q+1 */
+#ifdef BASOP_NOGLOB
+ Lacc_fx=L_mac_o(Lacc_fx,X_fx->b_fx[k],X_fx->b_fx[k], &Overflow); /* a[k]^2+b[k]^2, 2Q+1 */
+#else
+ Lacc_fx=L_mac(Lacc_fx,X_fx->b_fx[k],X_fx->b_fx[k]); /* a[k]^2+b[k]^2, 2Q+1 */
+#endif
+ Lacc_fx=L_shr(Lacc_fx,3); /* Lacc=(a[k]^2+b[k]^2)/4, 2Q */
+
+ IF(Lacc_fx)
+ {
+ exp = norm_l(Lacc_fx);
+ frac = extract_h(L_shl(Lacc_fx,exp)); /* Q14 */
+ exp = sub(exp, sub(30,(2*X_fx->Q)));
+
+ tmp = div_s(16384,frac); /* Q15 */
+ Ltemp_fx = Isqrt_lc(L_deposit_h(tmp),&exp); /* Q(31-exp) */
+
+ X_fx->a_fx[k]=extract_h(L_shl(Ltemp_fx, sub(add(X_fx->Q, exp), 15))); /* Q */
+ }
+ ELSE
+ {
+ X_fx->a_fx[k] = 0;
+ move16();
+ }
+
+ X_fx->b_fx[k]= 0;
+ move16(); /* clear b[k] */
+ }
+
+
+ IF (s_and(X_fx->lag_fx,1) == 0)
+ {
+ IF(X_fx->a_fx[k])
+ {
+ Lacc_fx=L_mult0(X_fx->a_fx[k],X_fx->a_fx[k]); /* a[k]^2, 2Q+1 */
+ Lacc_fx=L_mac0(Lacc_fx,X_fx->b_fx[k],X_fx->b_fx[k]); /* a[k]^2+b[k]^2, 2Q+1 */
+
+ exp = norm_l(Lacc_fx);
+ frac = extract_h(L_shl(Lacc_fx,exp)); /* Q14 */
+ exp = sub(exp,sub(30,shl(X_fx->Q,1)));
+
+ tmp = div_s(16384,frac); /* Q15 */
+ Ltemp_fx = Isqrt_lc(L_deposit_h(tmp),&exp); /* Q(31-exp) */
+
+ X_fx->a_fx[k]=extract_h(L_shl(Ltemp_fx, sub(add(X_fx->Q, exp), 15))); /* Q */
+ }
+ ELSE
+ {
+ X_fx->a_fx[k] = 0;
+ move16();
+ }
+
+ X_fx->b_fx[k]= 0;
+ move16(); /* clear b[k]; */
+ }
+ return;
+}
+
+
+/*==============================================================================*/
+/* FUNCTION : DTFS_setEngyHarm_fx ( ) */
+/*------------------------------------------------------------------------------*/
+/* PURPOSE : Set a band of harmonics to specified energy */
+/*----------------------------------------------------------------------- ------*/
+/* INPUT ARGUMENTS : */
+/* _ (struct DTFS_fx) : lag in Q0 */
+/* _ (Word16) f1_fx: lower bound of input, normalized by 12800, Q15 */
+/* _ (Word16) f2_fx: upper bound of input, normalized by 12800, Q15 */
+/* _ (Word16) g1_fx: lower bound of output, normalized by 12800, Q15 */
+/* _ (Word16) g2_fx: upper bound of output, normalized by 12800, Q15 */
+/* _ (Word32) en2_fx: in Q(Qen2) */
+/* _ (Word16) Qen2_fx: Q value of en2 */
+/*---------------------------------------------------------------------------- --*/
+/* OUTPUT ARGUMENTS : */
+/* _ (Word16) Qa_fx: Q value of output a[]. */
+/*----------------------------------------------------------------------------- -*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _(struct DTFS_STRUCTURE) : a_fx[] in X1_fx.Q at start, then changed to */
+/* *Qa later. */
+/*---------------------------------------------------------------------------- --*/
+/* RETURN ARGUMENTS : _ None. */
+/* _ (Word32) en1_fx: Q(2*X1.Q) */
+/*----------------------------------------------------------------------------- -*/
+/* CALLED FROM : TX/RX */
+/*============================================================================== */
+/* NOTE: This function cannot change Q because it works on a band */
+/* of harmonics, instead of the whole DTFS */
+/*============================================================================== */
+Word32 DTFS_setEngyHarm_fx(
+ Word16 f1_fx, /* i : lower band freq of input to control energy */
+ Word16 f2_fx, /* i : upper band freq of input to control energy */
+ Word16 g1_fx, /* i : lower band freq of output to control energy */
+ Word16 g2_fx, /* i : upper band freq of output to control energy */
+ Word32 en2_fx, /* i : Target Energy to set the DTFS to */
+ Word16 Qen2_fx, /* i : Input Q format for en2 */
+ Word16 *Qa_fx, /* i : Output Q format for x->a */
+ DTFS_STRUCTURE *X_fx /* i/o: DTFS to adjust the energy of */
+)
+{
+
+ Word16 k, count=0, HalfLag_fx;
+ Word16 f_low_fx, f_high_fx, g_low_fx, g_high_fx;
+ Word32 L_temp_fx, factor_fx;
+ Word32 en1_fx;
+ Word32 Lacc;
+ Word16 exp,tmp,expa,expb,fraca,fracb,scale;
+ Word32 L_tmp;
+ Word32 Lacc_max = 0;
+ Word16 expp=0;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+
+
+ f_low_fx=mult(f1_fx,X_fx->lag_fx); /* Q0 */
+ f_high_fx=mult(f2_fx,X_fx->lag_fx); /* Q0 */
+ g_low_fx=mult(g1_fx,X_fx->lag_fx); /* Q0 */
+ g_high_fx=mult(g2_fx,X_fx->lag_fx); /* Q0 */
+ HalfLag_fx = s_min(f_high_fx,shl(X_fx->nH_fx,1));
+
+ Lacc = L_deposit_l(0);
+ FOR (k=f_low_fx+1 ; k<=HalfLag_fx; k++)
+ {
+#ifdef BASOP_NOGLOB
+ Lacc = L_mac0_o(Lacc, X_fx->a_fx[k], X_fx->a_fx[k], &Overflow); /* 2*X1.Q */
+#else
+ Lacc = L_mac0(Lacc, X_fx->a_fx[k], X_fx->a_fx[k]); /* 2*X1.Q */
+#endif
+ Lacc_max = L_max( Lacc_max, Lacc);
+
+ count=add(count,1);
+ }
+
+ IF( GE_32( Lacc_max, 2147483647 ))
+ {
+ tmp = sub(HalfLag_fx, f_low_fx);
+ exp = norm_s(tmp);
+ expp = sub(15,exp);
+
+ Lacc = L_deposit_l(0);
+ FOR( k=f_low_fx+1; k<=HalfLag_fx; k++ )
+ {
+#ifdef BASOP_NOGLOB
+ L_tmp = L_mult_o( X_fx->a_fx[k], X_fx->a_fx[k], &Overflow);
+ Lacc = L_add_o(Lacc, L_shr(L_tmp,expp), &Overflow); /* 2*X1.Q-expp */
+#else
+ L_tmp = L_mult( X_fx->a_fx[k], X_fx->a_fx[k] );
+ Lacc = L_add(Lacc, L_shr(L_tmp,expp)); /* 2*X1.Q-expp */
+#endif
+ count=add(count,1);
+ }
+ }
+
+ if (count <= 0)
+ {
+ count = 1;
+ move16();
+ }
+
+ exp = norm_s(count);
+ tmp = div_s(shl(1,sub(14,exp)),count);/* 29 - exp */
+#ifdef BASOP_NOGLOB
+ en1_fx = L_shl_o( Mult_32_16(Lacc , tmp), sub(exp,14), &Overflow);
+#else
+ en1_fx = L_shl( Mult_32_16(Lacc , tmp), sub(exp,14));
+#endif
+ test();
+ IF (en1_fx>0 && en2_fx > 0)
+ {
+ /* factor_fx = sqrt_divide_dp((Word40)en2_fx, en1_fx, sub(Qen2_fx, shl(X_fx->Q, 1)), &temp_fx,1); : Q(temp) */
+ expa = norm_l(en2_fx);
+ fraca = extract_h(L_shl(en2_fx,expa));
+ expa = sub(30,add(expa,Qen2_fx));
+
+
+ expb = norm_l(en1_fx);
+#ifdef BASOP_NOGLOB
+ fracb = round_fx_o(L_shl_o(en1_fx,expb, &Overflow), &Overflow);
+#else
+ fracb = round_fx(L_shl(en1_fx,expb));
+#endif
+ IF( GE_32( Lacc_max, 2147483647 ))
+ {
+ expb = sub( 30, add( expb, sub(shl(X_fx->Q, 1),expp) ) );
+ }
+ ELSE
+ {
+ expb = sub(30, add(expb, shl(X_fx->Q, 1)));
+ }
+
+ scale = shr(sub(fraca,fracb),15);
+ fracb = shl(fracb,scale);
+ expb = sub(expb,scale);
+
+ tmp = div_s(fracb,fraca);
+ exp = sub(expb,expa);
+
+ L_tmp = Isqrt_lc(L_deposit_h(tmp),&exp); /* Q(31-exp) */
+
+ IF( GE_32( Lacc_max, 2147483647 ))
+ {
+ factor_fx = L_shr(L_tmp,add(1,s_min(2,expp)));
+ }
+ ELSE
+ {
+ factor_fx = L_shr(L_tmp,1);
+ }
+
+
+ }
+ ELSE
+ {
+ factor_fx = L_deposit_l(0);
+ }
+
+ HalfLag_fx = s_min(g_high_fx,shl(X_fx->nH_fx,1));
+ FOR (k=g_low_fx+1; k<=HalfLag_fx; k++)
+ {
+ /*L_temp_fx =(Word32)Mpy_32_16(extract_h(factor_fx),extract_l(factor_fx), X_fx->a_fx[k]); move32(); */ /* Q(temp+X1.Q-15) */
+ L_temp_fx = Mult_32_16(factor_fx, X_fx->a_fx[k]); /* Q(temp+X1.Q-15) */
+#ifdef BASOP_NOGLOB
+ X_fx->a_fx[k] = round_fx_o(L_temp_fx, &Overflow); /* Q(temp+X1.Q-15-16)=Q(temp+X1.Q-31); */
+#else
+ X_fx->a_fx[k] = round_fx(L_temp_fx); /* Q(temp+X1.Q-15-16)=Q(temp+X1.Q-31); */
+#endif
+ }
+
+ if ( GE_32( Lacc_max, 2147483647 ))
+ {
+ *Qa_fx = sub( sub(X_fx->Q,add(1,s_min(2,expp))) , exp);
+ }
+ else
+ {
+ *Qa_fx = sub( sub(X_fx->Q,1) , exp);
+ }
+
+ return en1_fx; /* Q(2*X1.Q) */
+
+
+}
+/*===================================================================*/
+/* FUNCTION : cubicPhase_fx () */
+/*-------------------------------------------------------------------*/
+/* PURPOSE : Compute cubic phase track for WI synthesis */
+/*-------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (Word16) ph1_fx : initial phase, Q15 (normalized by 2pi) */
+/* _ (Word16) ph2_fx : final phase, Q15 (normalized by 2pi) */
+/* _ (Word16) L1 : previous pitch lag, Q0 */
+/* _ (Word16) L2 : current pitch lag, Q0 */
+/* _ (Word16) N : length of phase track, Q0 */
+/*-------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ (Word32 []) phOut_fx : phase track, Q27 (normalized by 2pi) */
+/*-------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _ None */
+/*-------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : _ None. */
+/*-------------------------------------------------------------------*/
+/* CALLED FROM : TX/RX */
+/*===================================================================*/
+/* NOTE: This function outputs phase in (-1,1) */
+/*===================================================================*/
+static void cubicPhase_fx(
+ Word16 ph1_fx, /* i : phase offset */
+ Word16 ph2_fx, /* i : phase 2 */
+ const Word16 L1, /* i : previous lag */
+ const Word16 L2, /* i : current lag */
+ Word16 N, /* i : input length */
+ Word32* phOut_fx /* o : cubic phase output */
+)
+{
+ Word16 n;
+ Word16 n2;
+ Word16 f1, f2; /* invert of L1, L2, Q19 */
+ Word16 factor, temp;
+ Word16 c0, c1, c2, c3; /* cubic polynomial coefficients */
+ /* Q33, Q27, Q19, Q15 respectively */
+ Word32 Ltemp1, Ltemp2, Ltemp3,Ltemp4,Ltemp;
+ Word16 tmp,exp;
+ Word32 Lacc;
+ Word16 expa,expb,fraca,fracb,scale;
+ Word32 L_tmp,L_tmp1;
+ Word16 num_flag,den_flag;
+ Word32 N2;
+ Word16 dbgshft;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+ num_flag = 0;
+ den_flag = 0;
+
+ N=sub(N,L2);
+
+ exp = norm_s(L1);
+ tmp = div_s(shl(1,sub(14,exp)),L1);
+ L_tmp = L_shl(tmp,exp+6);
+ f1 = round_fx(L_tmp);
+
+ exp = norm_s(L2);
+ tmp = div_s(shl(1,sub(14,exp)),L2);
+ L_tmp = L_shl(tmp,exp+6);
+ Ltemp4 = inverse_table[L2];
+ f2 = round_fx(L_tmp);
+
+ c3 = ph1_fx;
+ move16(); /* c3 in Q15 */
+ c2 = f1;
+ move16();/* c2 in Q19 */
+
+ Ltemp1 = L_sub(ph1_fx,ph2_fx); /* Ltemp1=ph1_fx-ph2_fx, Q15 */
+ Ltemp2 = L_add(f1,f2); /* Ltemp2=0.5*(f1+f2), Q20 */
+ temp = extract_l(Ltemp2);/* Q20 */
+
+ IF(temp<0)
+ {
+ L_tmp1 = L_shl(L_add(65536,temp),14); /* Q30 */
+ L_tmp = Mult_32_16(L_tmp1,N); /* 30-15=15 */
+ Ltemp2 = L_shl(L_tmp,1);
+ }
+ ELSE
+ {
+ Ltemp2 = (Word32)L_mult0(N,temp); /* Ltemp2=0.5*N*(f1+f2), Q20 */
+ }
+
+ Ltemp1 = L_add(L_shl(Ltemp1,5),Ltemp2); /* Ltemp1=ph1_fx - ph2_fx + 0.5*N*(f2+f1), Q16, Q20 */
+
+ factor = round_fx(L_shr(Ltemp1,4)); /* factor in Q0 */
+
+ c1 = sub(f2,f1); /* c1=f2-f1, Q19 */
+ Ltemp1 = L_sub(ph2_fx,ph1_fx); /* Q15 */
+ Ltemp2 = L_mult(N,f1); /* Ltemp2=N*f1, Q20 */
+ Ltemp2 = L_sub(L_shl(L_deposit_h(factor),4),Ltemp2); /* Ltemp2=factor-N*f1, Q20 */
+ Ltemp1 = L_add(Ltemp2,L_shl(Ltemp1,5)); /* Ltemp1 in Q20 */
+
+ IF(GT_16(N,180))
+ {
+ Ltemp2 = L_shl(L_mult0(N,N),14);
+ Ltemp2 = L_shl(Mult_32_16(Ltemp2,N),1);
+
+ /* IF(N%2) */
+ if(s_and(N,1) == 1)
+ {
+ Ltemp2 = L_add(Ltemp2,1);
+ }
+ }
+ ELSE
+ {
+ Ltemp2=L_shr(L_mult(N,N),1);
+ Ltemp2 = L_mult0(N,extract_l(Ltemp2)); /* Ltemp2=N^3 */
+ }
+ Ltemp3 = L_mult(N,c1); /* Q20 */
+ Ltemp3 = L_sub(Ltemp3,L_shl(Ltemp1,1)); /* Ltemp3=N*c1-2*Ltemp1, Q20 */
+
+
+#ifdef BASOP_NOGLOB
+ IF (GE_32(L_abs(Ltemp3),L_shl_o(Ltemp2,8, &Overflow)))
+#else
+ IF (GE_32(L_abs(Ltemp3),L_shl(Ltemp2,8)))
+#endif
+ {
+ Lacc = L_add(MIN_32, 0);
+ if (Ltemp3 > 0)
+ {
+ Lacc = L_add(MAX_32, 0);
+ }
+
+ c0 = extract_h(Lacc); /* c0 in Q33 */
+ }
+ ELSE
+ {
+ expa = norm_l(Ltemp3);
+#ifdef BASOP_NOGLOB
+ fraca = extract_h(L_shl_o(Ltemp3,expa, &Overflow));
+#else
+ fraca = extract_h(L_shl(Ltemp3,expa));
+#endif
+ expa = sub(30,add(expa, 20));
+ if(fraca<0)
+ {
+ num_flag = 1;
+ move16();
+ }
+
+ expb = norm_l(Ltemp2);
+#ifdef BASOP_NOGLOB
+ fracb = extract_h(L_shl_o(Ltemp2,expb, &Overflow));
+#else
+ fracb = extract_h(L_shl(Ltemp2,expb));
+#endif
+ expb = sub(30,expb);
+ if(fracb<0)
+ {
+ den_flag = 1;
+ move16();
+ }
+
+ if(num_flag)
+ {
+ fraca = negate(fraca);
+ }
+ if(den_flag)
+ {
+ fracb = negate(fracb);
+ }
+ scale = shr(sub(fracb,fraca),15);
+#ifdef BASOP_NOGLOB
+ fraca = shl_o(fraca,scale, &Overflow);
+#else
+ fraca = shl(fraca,scale);
+#endif
+ expa = sub(expa,scale);
+
+ tmp = div_s(fraca,fracb); /* 15-exp */
+ exp = sub(expa,expb);
+ test();
+ if(num_flag && !den_flag)
+ {
+ tmp = negate(tmp);
+ }
+ test();
+ if(den_flag && !num_flag)
+ {
+ tmp = negate(tmp);
+ }
+
+#ifdef BASOP_NOGLOB
+ Lacc = L_shl_o(tmp,add(exp,34), &Overflow);
+ Lacc = L_add_o(Lacc,0x08000, &Overflow);
+#else
+ Lacc = L_shl(tmp,add(exp,34));
+ Lacc = L_add(Lacc,0x08000);
+#endif
+ c0 = extract_h(Lacc); /* c0 in Q33 */
+ }
+
+ Ltemp1 = L_mult(N,N); /* Ltemp1=2*N*N */
+ Ltemp1 = L_add(Ltemp1,L_shr(Ltemp1,1)); /* Ltemp1=3*N*N, max is 3*140*140 */
+
+ /* patch added for time warping support, where N can be more than 140 */
+ dbgshft= norm_l(Ltemp1);
+ Ltemp1= L_shl(Ltemp1,dbgshft);
+ temp = extract_h(Ltemp1);
+ Ltemp1 = (Word32)L_shl((Word32)L_mult0(c0,temp), sub(16,dbgshft)); /* Ltemp1=3*N*N*c0, Q33 */
+ /* Patch end */
+
+ num_flag = den_flag = 0;
+ move16();
+ move16();
+ Ltemp1 = L_sub(L_shr(L_deposit_h(c1),2),Ltemp1); /* Ltemp1=c1-3*N*N*c0, Q33 */
+
+ expa = norm_l(Ltemp1);
+ fraca = extract_h(L_shl(Ltemp1,expa));
+ expa = sub(30,add(expa, 33));
+ if(fraca<0)
+ {
+ num_flag = 1;
+ move16();
+ }
+
+ expb = norm_l(N);
+ fracb = extract_h(L_shl(N,expb));
+ expb = sub(30,expb);
+ if(fracb<0)
+ {
+ den_flag = 1;
+ move16();
+ }
+
+ if(num_flag)
+ {
+ fraca = negate(fraca);
+ }
+ if(den_flag)
+ {
+ fracb = negate(fracb);
+ }
+ scale = shr(sub(fracb,fraca),15);
+ fraca = shl(fraca,scale);
+ expa = sub(expa,scale);
+
+ tmp = div_s(fraca,fracb); /* 15-exp */
+ exp = sub(expa,expb);
+ test();
+ if(num_flag && !den_flag)
+ {
+ tmp = negate(tmp);
+ }
+ test();
+ if(den_flag && !num_flag)
+ {
+ tmp = negate(tmp);
+ }
+
+ Lacc = L_shl(tmp,exp+27);
+ Lacc = L_add(Lacc,0x08000);
+ c1 = extract_h(Lacc); /* c1 in Q27 */
+
+
+ /* Computation of the phase value at each sample point */
+ /* ph[n]= c0*n^3+c1*n^2+c2*n+c3, Q15 */
+ phOut_fx[0] = L_shl(ph1_fx,11);/* Q27 */
+
+ IF(LT_16(N,181))
+ {
+ FOR (n=1; n=diff_fx)/* Q0 compare */
+ {
+ nH_band_fx = add(nH_band_fx,1);/* Q0 */
+ }
+
+ n=s_min(shr(lag_fx,1),nH_band_fx);
+ exp = norm_s(lag_fx);
+ tmp = div_s(shl(1,sub(14,exp)),lag_fx); /* Q29-exp */
+ L_tmp = L_shl(tmp, add(exp,6));
+ diff_fx =round_fx(L_tmp);
+
+ j=0;
+ move16();
+ FOR (i=0; i<=n; i++)
+ {
+ Ltemp_fx=L_mult(diff_fx,i); /* Ltemp=i*diff, Q20 */
+ /* freq=round32_16(L_shl(Ltemp,11)); : freq=i*diff, Q15 */
+
+ IF (EQ_16(num_erb_fx,NUM_ERB_NB))
+ {
+ Ltemp_fx=L_min(Ltemp_fx,0x050000); /* 0x50000=0.3125 in Q20 (4000Hz) */
+ }
+ ELSE IF (EQ_16(num_erb_fx,NUM_ERB_WB))
+ {
+ Ltemp_fx=L_min(Ltemp_fx,0x080000); /* 0x80000=0.5 in Q20 (6400Hz) */
+ }
+
+ FOR ( ; jlag_fx);
+ tmp = div_s(shl(1,sub(14,exp)),X_fx->lag_fx);/* 29-exp */
+ diff_fx= shl(tmp,exp-10); /* Q19 */
+
+ min_q = EVS_SW_MAX;
+ move16();
+ X_fx->a_fx[0]=0;
+ move16();
+
+ HalfLag_fx=s_min(shr(X_fx->lag_fx,1),X_fx->nH_fx);
+
+ j=1;
+ move16();
+ FOR (i=1 ; i<=HalfLag_fx; i++)
+ {
+ Ltemp_fx=L_mult(diff_fx,i); /* Ltemp=i*diff, Q20 */
+ freq_fx=round_fx(L_shl(Ltemp_fx,11)); /* Q15 */
+
+ freq_fx=s_min(freq_fx,upper_cut_off_freq_fx); /* 0x4000 is 0.5 in Q15 */
+
+ FOR ( ; j=0)
+ {
+ d2=sub(freq_fx,f_fx[j-1]);
+ Ltemp_fx=L_mac(L_mult(amp_fx[j],d2),amp_fx[j-1],d1); /* Q29 */
+ d2=sub(f_fx[j],f_fx[j-1]); /* Q15 */
+ /* Ltemp2_fx=invert_dp((Word40)d2, 4, &n,1); : Ltemp2=1/d2, Q(61-15-n) */
+ exp = norm_s(d2);
+ tmp = div_s(shl(1,sub(14,exp)),d2);/* 29-exp */
+ /* L_tmp = L_shr(tmp,8); */
+ Ltemp2_fx = L_shl(tmp,16);
+ n = add(exp,16);
+
+ d1h=extract_h(Ltemp_fx);
+ d1l=extract_l(Ltemp_fx);
+ d2h=extract_h(Ltemp2_fx);
+ d2l=extract_l(Ltemp2_fx);
+ Ltemp_fx=(Word32)L_mult0(d1h,d2l);
+ Lacc_fx=L_mac0((Word32)Ltemp_fx,d2h,d1l);
+ Ltemp_fx=L_add((Word32)L_shr(Lacc_fx,15),L_mult(d1h,d2h)); /* 46-n+29-31 */
+ d2h=norm_l(Ltemp_fx); /* d2h is 0 IF Ltemp=0 */
+ if( Ltemp_fx == 0 )
+ {
+ d2h = 31;
+ move16();
+ }
+#ifdef BASOP_NOGLOB
+ X_fx->a_fx[i]=round_fx_o(L_shl_o(Ltemp_fx,d2h, &Overflow), &Overflow); /* Q(28-n+d2h) */
+#else
+ X_fx->a_fx[i]=round_fx(L_shl(Ltemp_fx,d2h)); /* Q(28-n+d2h) */
+#endif
+ q[i]=add(sub(28,n),d2h);
+ min_q=s_min(min_q,q[i]);
+
+ BREAK ;
+ }
+ }
+ }
+ /* block normalize a[i] */
+ FOR (i=1; i<=HalfLag_fx; i++)
+ {
+ X_fx->a_fx[i]=shl(X_fx->a_fx[i],sub(min_q,q[i]));
+ move16();
+ }
+
+ X_fx->Q=min_q;
+ return;
+}
+
+
+/*===================================================================*/
+/* FUNCTION : erb_add_fx () */
+/*-------------------------------------------------------------------*/
+/* PURPOSE : Reconstruct current erb amplitude for QPPP */
+/*-------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (Word16) pl_fx : previous pitch lag, Q0 */
+/* _ (Word16) l_fx : current pitch lag, Q0 */
+/* _ (Word16 []) prev_erb_fx : Previous erb amplitude, Q13 */
+/* _ (Word16 []) index_fx: quantized differential erb index */
+/*-------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ (Word16 []) curr_erb_fx : Current erb amplitude, Q13 */
+/*-------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _ None */
+/*-------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : _ None. */
+/*-------------------------------------------------------------------*/
+/* CALLED FROM : TX/RX */
+/*===================================================================*/
+
+void erb_add_fx(
+ Word16 *curr_erb_fx, /* i/o: current ERB */
+ Word16 l_fx, /* i : current lag */
+ const Word16 *prev_erb_fx, /* i : previous ERB */
+ Word16 pl_fx, /* i : previous lag */
+ const Word16 *index_fx, /* i : ERB index */
+ Word16 num_erb_fx /* i : number of ERBs */
+)
+{
+ Word16 i ;
+ Word16 pslot_fx[NUM_ERB_WB],cslot_fx[NUM_ERB_WB],t_prev_erb_fx[NUM_ERB_WB];
+ Word16 tmp_fx,tmp2_fx,tmp_loop;
+ const Word16 *AmpCB1_fx = NULL; /*move16(); */
+
+ IF (EQ_16(num_erb_fx,NUM_ERB_NB))
+ {
+ AmpCB1_fx=AmpCB1_NB_fx;
+ move16();
+ }
+ ELSE IF (EQ_16(num_erb_fx,NUM_ERB_WB))
+ {
+ AmpCB1_fx=AmpCB1_WB_fx;
+ move16();
+ }
+
+ erb_slot_fx(l_fx,cslot_fx,t_prev_erb_fx,num_erb_fx);
+ erb_slot_fx(pl_fx,pslot_fx,t_prev_erb_fx,num_erb_fx);
+
+ FOR (i=0; i=0; i--)
+ {
+
+ IF (pslot_fx[i] != 0)
+ {
+ tmp_fx = t_prev_erb_fx[i];
+ move16(); /* Q13 */
+ }
+ ELSE
+ {
+ t_prev_erb_fx[i] = tmp_fx;
+ move16(); /* Q13 */
+ }
+ }
+ }
+
+ tmp_fx = add(shl(index_fx[0],3),shl(index_fx[0],1)); /* tmp_fx=10*index_fx[0] */
+ FOR (i=1; i<11; i++)
+ {
+
+ IF (cslot_fx[i]!=0)
+ {
+ curr_erb_fx[i] = add(AmpCB1_fx[sub(add(tmp_fx,i),1)],t_prev_erb_fx[i]);
+ move16();/* Q13+Q13=Q13 */
+ curr_erb_fx[i] = s_max(0, curr_erb_fx[i]);
+ move16();
+ }
+ ELSE
+ curr_erb_fx[i] = 0;
+ move16();
+ }
+
+ tmp_fx = add(shl(index_fx[1],3),index_fx[1]); /* tmp=9*index[1] */
+ tmp2_fx = mult(shl(index_fx[1],6),5632);/* temp=11*index_fx[1] */
+ tmp_loop = sub(num_erb_fx,2);
+ FOR (i=11; iQ,1),13); /* tmp=2Q-13, Q factor of getSpEngy... output */
+ Ltemp3=L_shl(L_mult(tmp,24660),9); /* Ltemp3=(2Q-13)*10log10(2), Q23, 24660=10log10(2) in Q13 */
+
+ Ltemp1 = getSpEngyFromResAmp_fx(X_fx,0, 2828,curr_lpc, sin_tab, cos_tab);
+ Ltemp1=log10_fx(Ltemp1);
+
+ /* subtract 10log10(2)*(2Q-13), Q23 */
+ Ltemp1=L_sub(Ltemp1,Ltemp3);
+ Ltemp1=L_max(0,Ltemp1);
+ Ltemp2 = getSpEngyFromResAmp_fx(X_fx,2828,X_fx->upper_cut_off_freq_fx,curr_lpc, sin_tab, cos_tab);
+ Ltemp2=log10_fx(Ltemp2 ); /* Ltemp1=10log10(eng_hb), Q23, need to adjust for Q factor of energy (2Q-13) */
+ Ltemp2=L_sub(Ltemp2,Ltemp3); /* Ltemp2 in Q23 */
+
+ Ltemp2=L_max(0,Ltemp2);
+
+ /* Getting the Speech Domain Energy LOG Ratio */
+
+ Lacc = L_add(Ltemp1,Ltemp2);
+ exp = norm_l(Lacc);
+ tmp = round_fx(L_shl(Lacc,exp));
+ exp = sub(sub(30,exp),23);
+ IF(tmp)
+ tmp = div_s(16384,tmp); /* 15+exp1 */
+ ELSE
+ tmp = 0;
+ Ltemp = L_deposit_h(tmp);
+
+ tmp=round_fx(Ltemp); /* tmp in Q(22-n) */
+ Ltemp1= Mult_32_16(Ltemp1,tmp); /* Q(30-n) */
+ n=sub(8,exp);
+ w[0]=round_fx(L_shl(Ltemp1,n)); /* w[0] in Q15 */
+ Ltemp2= Mult_32_16(Ltemp2,tmp);
+ w[1]=round_fx(L_shl(Ltemp2,n)); /* w[1] in Q15 */
+
+ logLag=log10_fx(X_fx->lag_fx); /* logLag=10*log10(lag), Q23 */
+ Ltemp3=L_shl(L_mult(shl(X_fx->Q,1),24660),9); /* Ltemp3=2Q*10log10(2), Q23 */
+ /* Process low band */
+ Ltemp=DTFS_setEngyHarm_fx(236, 2828, 0, 2828, 1, 0, &Ql,X_fx); /* Ql is norm factor of low band a[], Ltemp is energy in 2Q */
+ /* Compensate for Q factor of energy to get log10(lag*eng) */
+ Ltemp=log10_fx(Ltemp); /* Ltemp=10log10(eng), Q23 */
+ Ltemp=L_add(L_sub(Ltemp,Ltemp3),logLag); /* Ltemp=10*log10(lag*eng), Q23 */
+
+ target[0]=round_fx(L_shl(Mult_32_16(Ltemp,0x6666),1)); /* Q11 */
+
+ /* Process high band */
+ Ltemp=DTFS_setEngyHarm_fx(2828, X_fx->upper_cut_off_freq_of_interest_fx, 2828, X_fx->upper_cut_off_freq_fx, 1, 0, &Qh,X_fx);
+ Ltemp=log10_fx(Ltemp);
+ Ltemp=L_add(L_sub(Ltemp,Ltemp3),logLag); /* Ltemp=10*log10(lag*eng), Q23 */
+ target[1]=round_fx(L_shl(Mult_32_16(Ltemp,0x6666),1)); /* Q11 */
+
+ /* Need to unify the Q factors of both bands */
+ X_fx->Q=s_min(Ql,Qh); /* set Q factor to be the smaller one */
+ n=sub(Ql,Qh); /* compare band Q factors */
+
+ IF (n<0) rshiftHarmBand_fx(X_fx,2828, X_fx->upper_cut_off_freq_fx,n);
+ ELSE IF (n>0) rshiftHarmBand_fx(X_fx,0, 2828, sub(Qh,Ql));
+}
+
+/*==========================================================================*/
+/* FUNCTION : WIsyn_fx () */
+/*--------------------------------------------------------------------------*/
+/* PURPOSE : */
+/*--------------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (struct DTFS_STRUCTURE) PREVCW_FX: a/b in PREVCW_FX.Q */
+/* _ (struct DTFS_fx *) CURRCW_DTFS_out: a/b in CURRCW_DTFS_out->Q */
+/* _ (Word16 *) curr_lpc_fx: lpc coefficients in Q12 */
+/* _ (Word16 *) ph_offset_fx: in Q15, normalized by 2pi */
+/* _ (Word16 *) S_fx: sin(2pi*n/(4*lag)) table, Q15 */
+/* _ (Word16 *) C_fx: cos(2pi*n/(4*lag)) table, Q15 */
+/* _ (Word16 *) N: length, Q0 */
+/*--------------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ (Word16 *) out_fx: Q0 */
+/*--------------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _ (struct DTFS_STRUCTURE *) CURRCW_DTFS_out: a/b in CURRCW_DTFS_out->Q*/
+/* _ (Word16 *) ph_offset_fx: in Q15, normalized by 2pi */
+/*--------------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : _ None. */
+/*==========================================================================*/
+ivas_error WIsyn_fx(
+ DTFS_STRUCTURE PREVCW_FX, /* i : Prev frame DTFS */
+ DTFS_STRUCTURE* CURRCW_DTFS_out, /* i/o: Curr frame DTFS */
+ const Word16* curr_lpc_fx, /* i : LPC */
+ Word16* ph_offset_fx, /* i/o: Phase offset to line up at end of frame */
+ Word16* out_fx, /* o : Waveform Interpolated time domain signal */
+ const Word16 N, /* i : Number of output samples to generate */
+ const Word16 FR_flag, /* i : called for post-smoothing in FR */
+ Word16 * S_fx,
+ Word16* C_fx,
+ Word16 *pf_temp1,
+ Word16 *pf_temp2,
+ Word16 *pf_temp,
+ Word16 *pf_n2
+)
+{
+ Word16 i;
+ UWord16 I=1, flag=0;
+ /* Word16 *phase_fx = (Word16*)malloc(sizeof(Word16) * (2*N)); new operator used size 2*N */
+ Word32 phase_fx[WI_FX_phase_fx];
+ Word16 alignment_fx;
+ Word16 tmp_fx, temp;
+ Word32 L_temp;
+ Word16 exp,tmp;
+ Word32 L_tmp;
+ /* prev_lsp_fx; */
+
+
+ DTFS_STRUCTURE *CURRCW_DTFS_FX;
+ ivas_error error;
+
+ error = IVAS_ERR_OK;
+
+ IF ((error = DTFS_new_fx(&CURRCW_DTFS_FX)) != IVAS_ERR_OK)
+ {
+ return IVAS_ERROR(error, "Error creating new DTFS structure\n");
+ }
+ IF(LT_16(PREVCW_FX.Q, CURRCW_DTFS_out->Q))
+ {
+ temp = sub(CURRCW_DTFS_out->Q, PREVCW_FX.Q);
+ tmp = s_min(shr(CURRCW_DTFS_out->lag_fx, 1), CURRCW_DTFS_out->nH_fx);
+ FOR(i = 0; i <= tmp; i++)
+ {
+ CURRCW_DTFS_out->a_fx[i] = shr(CURRCW_DTFS_out->a_fx[i], temp);
+ move16();
+ CURRCW_DTFS_out->b_fx[i] = shr(CURRCW_DTFS_out->b_fx[i], temp);
+ move16();
+ }
+ CURRCW_DTFS_out->Q = PREVCW_FX.Q;
+ move16();
+ }
+
+
+ IF(LT_16(CURRCW_DTFS_out->Q, PREVCW_FX.Q))
+ {
+ temp = sub(PREVCW_FX.Q, CURRCW_DTFS_out->Q);
+ tmp = s_min(shr(PREVCW_FX.lag_fx, 1), PREVCW_FX.nH_fx);
+ FOR(i = 0; i <= tmp; i++)
+ {
+ PREVCW_FX.a_fx[i] = shr(PREVCW_FX.a_fx[i], temp);
+ move16();
+ PREVCW_FX.b_fx[i] = shr(PREVCW_FX.b_fx[i], temp);
+ move16();
+ }
+ PREVCW_FX.Q = CURRCW_DTFS_out->Q;
+ move16();
+ }
+
+ DTFS_copy_fx(CURRCW_DTFS_FX, *CURRCW_DTFS_out);
+
+ /* Calculating the expected alignment shift */
+ alignment_fx = mult_r(*ph_offset_fx, shl(PREVCW_FX.lag_fx, 7)); /* confirmed I<2 by smv12.org, Q7 */
+
+
+ IF (EQ_16(flag,1))
+ alignment_fx = extract_l(L_shr(L_mult(alignment_fx, I), 1)) ; /* Q7 */
+
+ /* Calculating the expected alignment shift */
+ find_rem((Word16)N, shr(add(PREVCW_FX.lag_fx, CURRCW_DTFS_FX->lag_fx), 1), &temp);
+ temp = add(shl(temp, 7), alignment_fx); /* Q7 */
+
+
+ IF (temp<0)
+ temp = add(temp,shl(CURRCW_DTFS_FX->lag_fx,7)); /* Q7 */
+
+ find_rem(temp,shl(CURRCW_DTFS_FX->lag_fx, 7),&tmp_fx); /* Q7 */
+ IF (FR_flag==0)
+ {
+ alignment_fx = DTFS_alignment_weight_fx(&PREVCW_FX, *CURRCW_DTFS_FX,tmp_fx, curr_lpc_fx, curr_lpc_fx, S_fx,
+ C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2);
+ move16();/* Q7 */
+ }
+ ELSE
+ {
+ alignment_fx = DTFS_alignment_full_fx(PREVCW_FX, *CURRCW_DTFS_FX, *ph_offset_fx, S_fx, C_fx
+ ,FR_flag
+ );
+
+ /*alignment_fx is in Q1, we make it Q7*/
+ alignment_fx = shl(alignment_fx,6);
+ }
+
+
+ IF (GE_16(alignment_fx,shl(CURRCW_DTFS_FX->lag_fx, 7)))
+ {
+ temp=sub(alignment_fx, shl(CURRCW_DTFS_FX->lag_fx, 7));
+ tmp = shl(CURRCW_DTFS_FX->lag_fx, 7);
+ exp = norm_s(tmp);
+ tmp = div_s(shl(1,sub(14,exp)),tmp);/* 22-exp */
+ L_tmp =L_shl(L_mult(temp,tmp),exp+1);
+ tmp_fx = round_fx(L_tmp);
+ }
+ ELSE IF (alignment_fx<0)
+ {
+ temp=negate(alignment_fx);
+ tmp = shl(CURRCW_DTFS_FX->lag_fx, 7);
+ exp = norm_s(tmp);
+ tmp = div_s(shl(1,sub(14,exp)),tmp);/* 22-exp */
+ L_tmp =L_shl(L_mult(temp,tmp),exp+1);
+ tmp_fx = negate( round_fx(L_tmp));
+ }
+ ELSE
+ {
+ temp=alignment_fx;
+ move16();
+ tmp = shl(CURRCW_DTFS_FX->lag_fx, 7);
+ exp = norm_s(tmp);
+ tmp = div_s(shl(1,sub(14,exp)),tmp);/* 22-exp */
+ L_tmp =L_shl(L_mult(temp,tmp),exp+1);
+ tmp_fx = round_fx(L_tmp);
+ }
+
+ DTFS_phaseShift_fx(CURRCW_DTFS_FX, alignment_fx, CURRCW_DTFS_FX->lag_fx, S_fx, C_fx) ; /* Qmin */
+ DTFS_phaseShift_fx(CURRCW_DTFS_out, alignment_fx, CURRCW_DTFS_out->lag_fx, S_fx, C_fx);/* Qmin */
+
+ /* Compute the cubic phase track and transform to 1-D signal */
+ cubicPhase_fx(*ph_offset_fx, tmp_fx, PREVCW_FX.lag_fx , CURRCW_DTFS_FX->lag_fx, N, phase_fx) ;
+
+ temp = shr(add(PREVCW_FX.lag_fx,CURRCW_DTFS_FX->lag_fx),1); /* Q0 */
+
+ IF (FR_flag==0)
+ {
+ DTFS_transform_fx(PREVCW_FX,*CURRCW_DTFS_FX, phase_fx, out_fx, N, 0) ;
+ }
+ ELSE
+ {
+ DTFS_transform_fx (PREVCW_FX, *CURRCW_DTFS_FX, phase_fx, out_fx, N, 1) ;
+ }
+
+
+ /* Adjust the phase offset and wrap it between 0 and 2pi */
+
+//PMT("NEED a complete verification of mem flow and assignment")
+
+
+ IF (EQ_16(flag,2))
+ {
+ L_temp = L_shr(L_mult(tmp_fx, I), 1); /* Q15 */
+ }
+ ELSE
+ {
+ L_temp = L_deposit_l(tmp_fx); /* Q15 */
+ }
+
+
+ FOR ( ; L_temp < 0; L_temp += 0x8000L)
+ {
+ /* empty loop */
+ }
+ L_temp = L_temp&0x7fff;
+ move16(); /* fraction part */
+ *ph_offset_fx = extract_l(L_temp);
+
+ /* free(phase_fx) ; */
+ free(CURRCW_DTFS_FX);
+ return error;
+}
+
+
+
+/*===================================================================*/
+/* FUNCTION : ppp_extract_pitch_period_fx () */
+/*-------------------------------------------------------------------*/
+/* PURPOSE : Update background noise estimate, signal energy */
+/* estimate, and band snrs */
+/*-------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (Word16 []) in : residual input, Q0 */
+/* _ (Word16) l : pitch lag, Q0 */
+/*-------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ (Word16 []) out : pitch period prototype, Q0 */
+/* _ (Word16*) out_of_bound : pitch lag, Q0 */
+/*-------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _ None */
+/*-------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : */
+/* _ (Word16) spike_near_edge : Q0 */
+/*===================================================================*/
+Word16 ppp_extract_pitch_period_fx(
+ const Word16 *in, /* i : input residual */
+ Word16 *out, /* o : output residual */
+ Word16 l, /* i : lag */
+ Word16 *out_of_bound, /* o : out of bound flag */
+ Word16 Qres
+
+)
+{
+ Word16 i,j,k;
+ Word16 spike=0,range;
+ Word16 max=0;
+ const Word16 *ptr=in+L_FRAME-l;
+ Word32 en1 = 0,Lacc,L_tmp;
+ Word16 spike_near_edge=0,scale;
+ Word16 pos_max,neg_max;
+ Word16 spike_pos=0,spike_neg=0;
+ Word16 x,tmp,expa,fraca,expb,fracb,scale1,exp;
+
+ pos_max = -0x8000L;
+ move16();
+ neg_max = 0;
+ move16();
+ *out_of_bound=0;
+ move16();
+
+ en1 = L_deposit_l(0);
+ FOR (i=0 ; i0)
+ {
+ spike_pos=spike;
+ move16();
+ /* search for neg spike around the pos spike */
+ FOR(j=spike-10; j0)
+ tmp = add(tmp,4);/* Q3 */
+ ELSE
+ tmp = sub(tmp,4);/* Q3 */
+ range = shr(tmp,3);/* Q0 */
+
+ test();
+ IF((LT_16(spike,range))||(GE_16(add(spike,range),l)))
+ {
+ /* need to grab from one lag before
+ ensure that there is no array bound read */
+
+ IF(LT_16(sub(L_FRAME,l),l))
+ {
+ *out_of_bound=1;
+ move16();
+ return spike_near_edge;
+ }
+ spike_near_edge=1;
+ move16();
+ }
+
+ IF(LT_16(spike,range))
+ {
+ tmp = add(l,sub(spike,range));
+ FOR(i=0; i=in)
+ {
+ FOR(ptr-=l; i= 0)
+ {
+ if (GT_32(L_temp,maxPosEn_fx))
+ {
+ maxPosEn_fx = L_temp ; /* Q(1) */
+ }
+ }
+ ELSE
+ {
+ if (GT_32(L_temp,maxNegEn_fx))
+ {
+ maxNegEn_fx = L_temp ; /* Q(1) */
+ }
+ }
+ }
+
+
+ IF (L_sum==0)
+ {
+ *pos_fx=*neg_fx=0;
+ move16();
+ move16();
+ }
+ ELSE
+ {
+ IF (maxPosEn_fx==0)
+ {
+ *pos_fx=0;
+ *Qpos=31;
+ }
+ ELSE
+ {
+ expa = norm_l(maxPosEn_fx);
+#ifdef BASOP_NOGLOB
+ fraca = extract_h(L_shl_o(maxPosEn_fx,expa, &Overflow));
+#else
+ fraca = extract_h(L_shl(maxPosEn_fx,expa));
+#endif
+ expa = sub(30,add(expa,1));
+
+
+ expb = norm_l(L_sum);
+#ifdef BASOP_NOGLOB
+ fracb = round_fx_o(L_shl_o(L_sum,expb, &Overflow), &Overflow);
+#else
+ fracb = round_fx(L_shl(L_sum,expb));
+#endif
+ expb = sub(30,add(expb,shl(X_fx.Q,1)));
+
+
+ scale = shr(sub(fraca,fracb),15);
+#ifdef BASOP_NOGLOB
+ fracb = shl_o(fracb,scale, &Overflow);
+#else
+ fracb = shl(fracb,scale);
+#endif
+ expb = sub(expb,scale);
+
+ tmp = div_s(fracb,fraca);
+ exp = sub(expb,expa);
+
+ L_tmp = Isqrt_lc(L_deposit_h(tmp),&exp); /* Q(31-exp) */
+ *pos_fx = L_tmp;
+ *Qpos = sub(31, exp);
+
+ }
+
+ IF (maxNegEn_fx==0)
+ {
+ *neg_fx=0;
+ *Qneg=31;
+ }
+ ELSE
+ {
+
+ expa = norm_l(maxNegEn_fx);
+#ifdef BASOP_NOGLOB
+ fraca = extract_h(L_shl_o(maxNegEn_fx,expa, &Overflow));
+#else
+ fraca = extract_h(L_shl(maxNegEn_fx,expa));
+#endif
+ expa = 30-expa- 1;
+
+
+ expb = norm_l(L_sum);
+#ifdef BASOP_NOGLOB
+ fracb = round_fx_o(L_shl_o(L_sum,expb, &Overflow), &Overflow);
+#else
+ fracb = round_fx(L_shl(L_sum,expb));
+#endif
+ expb = 30-expb - (2*X_fx.Q);
+
+
+ scale = shr(sub(fraca,fracb),15);
+#ifdef BASOP_NOGLOB
+ fracb = shl_o(fracb,scale, &Overflow);
+#else
+ fracb = shl(fracb,scale);
+#endif
+ expb = sub(expb,scale);
+
+ tmp = div_s(fracb,fraca);
+ exp = sub(expb,expa);
+
+ L_tmp = Isqrt_lc(L_deposit_h(tmp),&exp); /* Q(31-exp) */
+ *neg_fx = L_tmp;
+ *Qneg = 31 - exp;
+
+ }
+
+ }
+}
+
+/*===================================================================*/
+/* FUNCTION : struct DTFS_fx:: rshiftHarmBand_fx() */
+/*-------------------------------------------------------------------*/
+/* PURPOSE : Right-shift harmonics in band to align Q factor */
+/*-------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (Word16) lband: lower band boundary, Q15 */
+/* _ (Word16) hband: upper band boundary, Q15 */
+/* _ (Word16) shift: right shift value, Q0 (must be <0) */
+/*-------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ None */
+/*-------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _ (struct DTFS_fx) X : prototype in polar domain */
+/* (Word16) lag: length of prototype in time domain */
+/* (Word16 []) a: amplitude of harmonics, normalized */
+/*-------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : _ None. */
+/*-------------------------------------------------------------------*/
+/* CALLED FROM : TX/RX */
+/*===================================================================*/
+/* NOTE: This function should be called after two consecutive calls */
+/* to setEngyHarm_fx, because the norm factor outputs from */
+/* the two previous calls might be different */
+/*===================================================================*/
+void rshiftHarmBand_fx( DTFS_STRUCTURE *X_fx,Word16 lband_fx, Word16 hband_fx, Word16 shift_fx)
+{
+ Word16 k_fx, HalfLag_fx;
+ Word16 low_fx, high_fx;
+
+ low_fx=mult(lband_fx,X_fx->lag_fx); /* low=lband*lag, Q0 */
+ high_fx=mult(hband_fx,X_fx->lag_fx); /* high=hband*lag, Q0 */
+ HalfLag_fx = s_min(high_fx,shl(X_fx->nH_fx,1));
+
+ FOR (k_fx=low_fx+1; k_fx<=HalfLag_fx; k_fx++)
+ {
+ X_fx->a_fx[k_fx]=shl_r(X_fx->a_fx[k_fx],shift_fx);
+ move16(); /* right shift and round */
+ }
+}
+
+/*===================================================================*/
+/* FUNCTION : GetSinCosTab_fx () */
+/*-------------------------------------------------------------------*/
+/* PURPOSE : Compute sine & cosine table given pitch lag, */
+/* by interpolating the 512-entry cosine table. */
+/* sin(2pi/4L*n) & cos(2pi/4L*n) for n=0,1,... 4L-1 */
+/*-------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (Word16) L : Pitch lag, Q0 */
+/*-------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ (Word16 []) sinTab, Q15 : sin(2pi/4L*n), n=0,1,...,4L-1 */
+/* _ (Word16 []) cosTab, Q15 : cos(2pi/4L*n), n=0,1,...,4L-1 */
+/*-------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _ None */
+/*-------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : _ None. */
+/*-------------------------------------------------------------------*/
+/* CALLED FROM : TX/RX */
+/*===================================================================*/
+/* NOTE: This function interpolates cos_table for better accuracy */
+/*===================================================================*/
+void GetSinCosTab_fx(Word16 L, Word16 *sinTab, Word16 *cosTab)
+{
+ Word16 i, L4;
+ Word16 dl, t1, w, dt;
+ /* Word16 t2; */
+ Word32 invL; /* 1/4L in Q25 */
+ Word32 Ltemp, Lw;
+ Word32 L_tmp;
+
+ invL = L_shr(inverse_table[L],4);
+
+ L4=shl(L,2);
+ Lw = L_deposit_l(0);
+ FOR (i=0 ; i 0; k -= size)
+ {
+ K=add(K,1); /* K=512/size */
+ }
+ n_2=shr(size,1);
+ FOR (i=1; i<=stage; i++) ii_table[i-1]=shr(size,i);
+
+ /* Rearrange the input array in bit reversed order */
+ j = 0;
+ move16();
+ FOR (i = 0 ; i < size - 2; i = i + 2)
+ {
+ move16();
+ move16();
+ move16();
+ move16();
+ move16();
+ move16();
+
+ IF (GT_16(j,i))
+ {
+ ftmp_fx = *(farray_ptr_fx + i);
+ *(farray_ptr_fx + i) = *(farray_ptr_fx + j);
+ *(farray_ptr_fx + j) = (Word16) ftmp_fx;
+
+ ftmp_fx = *(farray_ptr_fx + i + 1);
+ *(farray_ptr_fx + i + 1) = *(farray_ptr_fx + j + 1);
+ *(farray_ptr_fx + j + 1) = (Word16)ftmp_fx;
+ }
+
+ k = n_2;
+ move16();
+ WHILE (j >= k)
+ {
+ j = sub(j, k);
+ k = shr(k, 1);
+ }
+ j += k;
+ }
+
+ /* The FFT part */
+
+
+
+ IF (isign == 1)
+ {
+ FOR (i = 0; i < stage; i++) /* i is stage counter */
+ {
+ jj = shl(2, i); /* FFT size */
+ kk = shl(jj, 1); /* 2 * FFT size */
+
+ move16();
+
+ ii = ii_table[i]; /* 2 * number of FFT's */
+
+ FOR (j = 0; j < jj; j = j + 2) /* j is sample counter */
+ {
+ ji = j * ii; /* ji is phase table index */
+
+ FOR (k = j; k < size; k = k + kk) /* k is butterfly top */
+ {
+ kj = add(k, jj); /* kj is butterfly bottom */
+ temp_sand = s_and((ji*K+384),511);
+ /* Butterfly computations */
+ /* ftmp_real_fx = L_sub(L_mult(*(farray_ptr_fx + kj), cos_table[ji*K]), */
+ /* L_mult(*(farray_ptr_fx + kj + 1), cos_table[(ji*K+384)%512])); */
+ ftmp_real_fx = L_msu(L_mult(*(farray_ptr_fx + kj), cos_table[ji*K]),
+ *(farray_ptr_fx + kj + 1), cos_table[temp_sand]);
+
+ /* ftmp_imag_fx = L_add(L_mult(*(farray_ptr_fx + kj + 1), cos_table[ji*K]), */
+ /* L_mult(*(farray_ptr_fx + kj), cos_table[(ji*K+384)%512])); */
+ ftmp_imag_fx = L_mac(L_mult(*(farray_ptr_fx + kj + 1), cos_table[ji*K]),
+ *(farray_ptr_fx + kj), cos_table[temp_sand]);
+
+ tmp1 = round_fx(ftmp_real_fx);
+ tmp2 = round_fx(ftmp_imag_fx);
+
+ tmp = sub(*(farray_ptr_fx + k), tmp1);
+ *(farray_ptr_fx + kj) = shr(tmp, 1);
+ move16();
+
+ tmp = sub(*(farray_ptr_fx + k + 1), tmp2);
+ *(farray_ptr_fx + kj + 1) = shr(tmp, 1);
+ move16();
+
+ tmp = add(*(farray_ptr_fx + k), tmp1);
+ *(farray_ptr_fx + k) = shr(tmp, 1);
+ move16();
+
+ tmp = add(*(farray_ptr_fx + k + 1), tmp2);
+ *(farray_ptr_fx + k + 1) = shr(tmp, 1);
+ move16();
+ }
+ }
+ }
+
+ /* The IFFT part */
+ }
+ ELSE
+ {
+ FOR (i = 0; i < stage; i++) /* i is stage counter */
+ {
+ jj = shl(2, i); /* FFT size */
+ kk = shl(jj, 1); /* 2 * FFT size */
+ ii = ii_table[i]; /* 2 * number of FFT's */
+
+ FOR (j = 0; j < jj; j = j + 2) /* j is sample counter */
+ {
+ ji = j * ii; /* ji is phase table index */
+
+ FOR (k = j; k < size; k = k + kk) /* k is butterfly top */
+ {
+ kj = add(k, jj); /* kj is butterfly bottom */
+ temp_sand = s_and((ji*K+384),511);
+ /* Butterfly computations */
+ /* ftmp_real_fx = L_add(L_mult(*(farray_ptr_fx + kj), cos_table[ji*K]), */
+ /* L_mult(*(farray_ptr_fx + kj + 1), cos_table[(ji*K+384)%512])); */
+ ftmp_real_fx = L_mac(L_mult(*(farray_ptr_fx + kj), cos_table[ji*K]),
+ *(farray_ptr_fx + kj + 1), cos_table[temp_sand]);
+
+ /* ftmp_imag_fx = L_sub(L_mult(*(farray_ptr_fx + kj + 1), cos_table[ji*K]), */
+ /* L_mult(*(farray_ptr_fx + kj), cos_table[(ji*K+384)%512])); */
+ ftmp_imag_fx = L_msu(L_mult(*(farray_ptr_fx + kj + 1), cos_table[ji*K]),
+ *(farray_ptr_fx + kj), cos_table[temp_sand]);
+
+ tmp1 = round_fx(ftmp_real_fx);
+ tmp2 = round_fx(ftmp_imag_fx);
+
+ *(farray_ptr_fx + kj) = sub(*(farray_ptr_fx + k), tmp1);
+ move16();
+ *(farray_ptr_fx + kj + 1) = sub(*(farray_ptr_fx + k + 1), tmp2);
+ move16();
+ *(farray_ptr_fx + k) = add(*(farray_ptr_fx + k), tmp1);
+ move16();
+ *(farray_ptr_fx + k + 1) = add(*(farray_ptr_fx + k + 1), tmp2);
+ move16();
+ }
+ }
+ }
+ }
+
+} /* end of c_fft () */
+
+
+void r_fft_4_fx(Word16 * farray_ptr_fx, Word16 size, Word16 stage, Word16 isign)
+{
+
+ Word16 ftmp1_real_fx, ftmp1_imag_fx, ftmp2_real_fx, ftmp2_imag_fx;
+ Word32 Lftmp1_real_fx, Lftmp1_imag_fx;
+ Word16 i, j,temp_sand;
+ Word32 Ltmp1_fx, Ltmp2_fx;
+ Word16 n_2, k, K;
+
+ n_2 = shr(size,1);
+ K=0;
+ move16();
+
+ FOR (k = 256; k > 0; k -= size)
+ {
+ K = add(K,1); /* K=512/size */
+ }
+
+ /* The FFT part */
+ IF (isign == 1)
+ {
+ /* Perform the complex FFT */
+ c_fft_wi_fx(farray_ptr_fx, size, stage, isign);
+
+ /* First, handle the DC and foldover frequencies */
+ ftmp1_real_fx = *farray_ptr_fx;
+ ftmp2_real_fx = *(farray_ptr_fx + 1);
+ *farray_ptr_fx = add(ftmp1_real_fx, ftmp2_real_fx);
+ *(farray_ptr_fx + 1) = sub(ftmp1_real_fx, ftmp2_real_fx);
+
+ /* Now, handle the remaining positive frequencies */
+ j = size - 2;
+ FOR (i = 2; i <= n_2; i = i + 2 )
+ {
+ ftmp1_real_fx = add(*(farray_ptr_fx + i), *(farray_ptr_fx + j));
+ ftmp1_imag_fx = sub(*(farray_ptr_fx + i + 1), *(farray_ptr_fx + j + 1));
+ ftmp2_real_fx = add(*(farray_ptr_fx + i + 1), *(farray_ptr_fx + j + 1));
+ ftmp2_imag_fx = sub(*(farray_ptr_fx + j), *(farray_ptr_fx + i));
+
+ Lftmp1_real_fx = L_deposit_h(ftmp1_real_fx);
+ Lftmp1_imag_fx = L_deposit_h(ftmp1_imag_fx);
+ temp_sand = s_and((i*K+384),511);
+ /* Ltmp1_fx = L_sub(L_mult(ftmp2_real_fx, cos_table[i*K]), L_mult(ftmp2_imag_fx, cos_table[(i*K+384)%512])); */
+ Ltmp1_fx = L_msu(L_mult(ftmp2_real_fx, cos_table[i*K]), ftmp2_imag_fx, cos_table[temp_sand]);
+ *(farray_ptr_fx + i) = round_fx(L_shr(L_add(Lftmp1_real_fx, Ltmp1_fx), 1));
+
+ /* Ltmp1_fx = L_add(L_mult(ftmp2_imag_fx, cos_table[i*K]), L_mult(ftmp2_real_fx, cos_table[(i*K+384)%512])); */
+ Ltmp1_fx = L_mac(L_mult(ftmp2_imag_fx, cos_table[i*K]), ftmp2_real_fx, cos_table[temp_sand]);
+ *(farray_ptr_fx + i + 1) = round_fx(L_shr(L_add(Lftmp1_imag_fx, Ltmp1_fx), 1));
+
+ /* Ltmp1_fx = L_add(L_mult(ftmp2_real_fx, cos_table[j*K]), L_mult(ftmp2_imag_fx, cos_table[(j*K+384)%512])); */
+ Ltmp1_fx = L_mac(L_mult(ftmp2_real_fx, cos_table[j*K]), ftmp2_imag_fx, cos_table[temp_sand]);
+ *(farray_ptr_fx + j) = round_fx(L_shr(L_add(Lftmp1_real_fx, Ltmp1_fx), 1));
+
+ /* Ltmp1_fx = L_add(L_negate(L_mult(ftmp2_imag_fx, cos_table[j*K])), L_mult(ftmp2_real_fx, cos_table[(j*K+384)%512])); */
+ Ltmp1_fx = L_msu(L_mult(ftmp2_real_fx, cos_table[temp_sand]), ftmp2_imag_fx, cos_table[j*K]);
+ Ltmp2_fx = L_sub(Ltmp1_fx, Lftmp1_imag_fx);
+ *(farray_ptr_fx + j + 1) = round_fx(L_shr(Ltmp2_fx, 1));
+ j = size - i;
+ }
+
+ }
+ ELSE
+ {
+
+ /* First, handle the DC and foldover frequencies */
+
+ move16();
+ move16();
+
+ ftmp1_real_fx = *farray_ptr_fx;
+ ftmp2_real_fx = *(farray_ptr_fx + 1);
+ *farray_ptr_fx = shr(add(ftmp1_real_fx, ftmp2_real_fx), 1);
+ move16();
+ *(farray_ptr_fx + 1) = shr(sub(ftmp1_real_fx, ftmp2_real_fx), 1);
+ move16();
+
+ /* Now, handle the remaining positive frequencies */
+ FOR (i = 2; i <= n_2; i += 2)
+ {
+ j = sub(size, i);
+
+ ftmp1_real_fx = add(*(farray_ptr_fx + i), *(farray_ptr_fx + j));
+ ftmp1_imag_fx = sub(*(farray_ptr_fx + i + 1), *(farray_ptr_fx + j + 1));
+ ftmp2_real_fx = negate(add(*(farray_ptr_fx + j + 1), *(farray_ptr_fx + i + 1)));
+ ftmp2_imag_fx = negate(sub(*(farray_ptr_fx + j), *(farray_ptr_fx + i)));
+
+ Lftmp1_real_fx = L_deposit_h(ftmp1_real_fx);
+ Lftmp1_imag_fx = L_deposit_h(ftmp1_imag_fx);
+ temp_sand = s_and((i*K+384),511);
+ /* Ltmp1_fx = L_add(L_mult(ftmp2_real_fx, cos_table[i*K]), L_mult(ftmp2_imag_fx, cos_table[(i*K+384)%512])); */
+ Ltmp1_fx = L_mac(L_mult(ftmp2_real_fx, cos_table[i*K]), ftmp2_imag_fx, cos_table[ temp_sand]);
+ *(farray_ptr_fx + i) = round_fx(L_shr(L_add(Lftmp1_real_fx, Ltmp1_fx), 1));
+
+ /* Ltmp1_fx = L_sub(L_mult(ftmp2_imag_fx, cos_table[i*K]), L_mult(ftmp2_real_fx, cos_table[(i*K+384)%512])); */
+ Ltmp1_fx = L_msu(L_mult(ftmp2_imag_fx, cos_table[i*K]), ftmp2_real_fx, cos_table[ temp_sand]);
+ *(farray_ptr_fx + i + 1) = round_fx(L_shr(L_add(Lftmp1_imag_fx, Ltmp1_fx), 1));
+
+ /* Ltmp1_fx = L_sub(L_mult(ftmp2_real_fx, cos_table[j*K]), L_mult(ftmp2_imag_fx, cos_table[(j*K+384)%512])); */
+ Ltmp1_fx = L_msu(L_mult(ftmp2_real_fx, cos_table[j*K]), ftmp2_imag_fx, cos_table[temp_sand]);
+ *(farray_ptr_fx + j) = round_fx(L_shr(L_add(Lftmp1_real_fx, Ltmp1_fx), 1));
+
+ /* Ltmp1_fx = L_negate(L_add(L_mult(ftmp2_imag_fx, cos_table[j*K]), L_mult(ftmp2_real_fx, cos_table[(j*K+384)%512]))); */
+ Ltmp1_fx = L_negate(L_mac(L_mult(ftmp2_imag_fx, cos_table[j*K]), ftmp2_real_fx, cos_table[temp_sand]));
+ Ltmp2_fx = L_sub(Ltmp1_fx, Lftmp1_imag_fx);
+ *(farray_ptr_fx + j + 1) = round_fx(L_shr(Ltmp2_fx, 1));
+ }
+
+ /* Perform the complex IFFT */
+ c_fft_wi_fx(farray_ptr_fx, size, stage, isign);
+
+ }
+
+}
+
+
+/*===================================================================*/
+/* FUNCTION : struct DTFS_fx::copy_phase_fx () */
+/*-------------------------------------------------------------------*/
+/* PURPOSE : Retain the amplitudes of a prototype X2, but copy*/
+/* the phases of another prototype X1 of same length*/
+/* over to make a new prototype */
+/*-------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (struct DTFS_fx) X1 : prototype in Cartesian domain */
+/* (Word16) X1.lag: length of prototype in time domain*/
+/* (Word16 []) X1.a,b: re/im of harmonics, normalized */
+/* (Word16) X1.Q: norm factor of X2.a/b */
+/* _ (struct DTFS_fx) X2 : prototype in polar domain */
+/* (Word16) X2.lag: should be same as X1.lag */
+/* (Word16 []) X2.a:amplitude of harmonics, normalized*/
+/* (Word16 []) X2.b: phase of harmonics, don't care */
+/* (Word16) X2.Q: norm factor of X2.a */
+/*-------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ None */
+/*-------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _ None */
+/*-------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : */
+/* _ (struct DTFS_fx) X : prototype in Cartesian domain */
+/* The amplitudes of this prototype are from X2 */
+/* and the phases are from X1 */
+/*-------------------------------------------------------------------*/
+/* CALLED FROM : TX/RX */
+/*===================================================================*/
+/* X.a[k]=2*X2.a[k]/sqrt(X1.a[k]^2+X1.b[k]^2)*X1.a[k] */
+/* X.b[k]=2*X2.a[k]/sqrt(X1.a[k]^2+X1.b[k]^2)*X1.b[k] */
+/*===================================================================*/
+void copy_phase_fx( DTFS_STRUCTURE *X1_fx, DTFS_STRUCTURE X2_fx, DTFS_STRUCTURE *retX_fx)
+{
+ /* DTFS_fx X; */
+ Word16 k, q, sn, cn, HalfLag;
+ Word16 d1h, d1l;
+ Word32 Ltemp_fx,L_tmp;
+ Word32 Lacc_fx;
+ Word16 exp,tmp,exp1;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+ move16();
+
+ retX_fx->lag_fx=X1_fx->lag_fx;
+ retX_fx->Q = sub(X2_fx.Q,1); /* equivalent to 2x MIN_FX(shr(sub(X_fx->lag_fx,1),1),X_fx->nH_fx) */
+ HalfLag = s_min(shr(X1_fx->lag_fx,1),X1_fx->nH_fx);
+ move16();
+ FOR ( k=1; k<=HalfLag; k++ )
+ {
+#ifdef BASOP_NOGLOB
+ Lacc_fx=L_mult_o(X1_fx->a_fx[k],X1_fx->a_fx[k], &Overflow);
+ Lacc_fx = L_mac_o(Lacc_fx,X1_fx->b_fx[k],X1_fx->b_fx[k], &Overflow); /* 2*Q+1 */
+#else
+ Lacc_fx=L_mult(X1_fx->a_fx[k],X1_fx->a_fx[k]);
+ Lacc_fx = L_mac(Lacc_fx,X1_fx->b_fx[k],X1_fx->b_fx[k]); /* 2*Q+1 */
+#endif
+
+ exp = norm_l(Lacc_fx);
+ tmp = extract_h(L_shl(Lacc_fx,exp));
+ exp1 = sub(sub(30,exp),2*X1_fx->Q+1);
+
+ IF(tmp)
+ tmp = div_s(16384,tmp); /* 15+exp1 */
+ ELSE
+ tmp = 0;
+ tmp = shr(tmp,1);
+ q = 15+exp1+16-1;
+
+ IF(tmp)
+ {
+ exp = norm_s(tmp);
+ tmp = shl(tmp, exp);
+ tmp = div_s(16384, tmp);
+ L_tmp = L_deposit_h(tmp);
+ Ltemp_fx = Isqrt_lc(L_tmp,&exp); /* Q(31-exp) */
+ }
+ ELSE
+ Ltemp_fx = 0;
+
+ if (s_and(q, 1))
+ Ltemp_fx = Mult_32_16(Ltemp_fx, 23170); /* 23170 is 1/sqrt(2) in Q15 */
+
+ q = shr(q,1); /* Ltemp_fx in Q(q+16) */
+
+ d1h=extract_h(Ltemp_fx);
+ d1l=extract_l(Ltemp_fx);
+#ifdef BASOP_NOGLOB
+ Ltemp_fx = L_mult0(X1_fx->b_fx[k],d1l);
+ Ltemp_fx = L_add_o(L_shr(Ltemp_fx,15),L_mult_o(X1_fx->b_fx[k],d1h, &Overflow), &Overflow); /* sin(w) in Q(q+16+Q-15) */
+ sn = round_fx_o(L_shl_o(Ltemp_fx,sub(30,add(q,X1_fx->Q)), &Overflow), &Overflow); /* Q15 */
+ retX_fx->b_fx[k] = mult_ro(X2_fx.a_fx[k],sn, &Overflow); /* X2_fx.Q */
+
+ Ltemp_fx = L_mult0(X1_fx->a_fx[k],d1l);
+ Ltemp_fx = L_add_o(L_shr(Ltemp_fx,15),L_mult_o(X1_fx->a_fx[k],d1h, &Overflow), &Overflow); /* cos(w) in Q(q+Q+1) */
+ cn = round_fx_o(L_shl_o(Ltemp_fx,sub(30,add(q,X1_fx->Q)), &Overflow), &Overflow); /* Q15 */
+ retX_fx->a_fx[k] = mult_ro(X2_fx.a_fx[k],cn, &Overflow); /* X2_fx.Q */
+#else
+ Ltemp_fx = L_mult0(X1_fx->b_fx[k], d1l);
+ Ltemp_fx = L_add(L_shr(Ltemp_fx, 15), L_mult(X1_fx->b_fx[k], d1h)); /* sin(w) in Q(q+16+Q-15) */
+ sn = round_fx(L_shl(Ltemp_fx, sub(30, add(q, X1_fx->Q)))); /* Q15 */
+ retX_fx->b_fx[k] = mult_r(X2_fx.a_fx[k], sn); /* X2_fx.Q */
+
+ Ltemp_fx = L_mult0(X1_fx->a_fx[k], d1l);
+ Ltemp_fx = L_add(L_shr(Ltemp_fx, 15), L_mult(X1_fx->a_fx[k], d1h)); /* cos(w) in Q(q+Q+1) */
+ cn = round_fx(L_shl(Ltemp_fx, sub(30, add(q, X1_fx->Q)))); /* Q15 */
+ retX_fx->a_fx[k] = mult_r(X2_fx.a_fx[k], cn); /* X2_fx.Q */
+#endif
+ }
+ k=sub(k,1);
+
+
+ IF (s_and(X1_fx->lag_fx,1)==0)
+ {
+ retX_fx->a_fx[k] = shr(retX_fx->a_fx[k],1);
+ move16();
+ retX_fx->b_fx[k] = shr(retX_fx->b_fx[k],1);
+ move16();
+ }
+}
+
+
+
+/*===================================================================*/
+/* FUNCTION : getSpEngyFromResAmp_fx () */
+/*-------------------------------------------------------------------*/
+/* PURPOSE : Get band energy */
+/*-------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (struct DTFS_STRUCTURE) X_fx : prototype in polar domain */
+/* (Word16) lag: length of prototype in time domain */
+/* (Word16 []) a: amplitude of harmonics, normalized */
+/* (Word16) Q: norm factor of a */
+/* _ (Word16 []) curr_lpc: LPC coefficients, Q12 */
+/* _ (Word16) lband: lower frequency bound, Q15 */
+/* _ (Word16) hband: upper frequency bound, Q15 */
+/* _ (Word16 []) sin_tab: sine table based on lag, Q15 */
+/* _ (Word16 []) cos_tab: cosine table based on lag, Q15 */
+/*-------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ None */
+/*-------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _ None */
+/*-------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : */
+/* _ (Word32) en: energy of the specified frequency band, */
+/* Q factor is 2Q-13 */
+/*-------------------------------------------------------------------*/
+/* CALLED FROM : TX */
+/*===================================================================*/
+Word32 getSpEngyFromResAmp_fx( DTFS_STRUCTURE *X_fx,Word16 lband, Word16 hband,
+ const Word16 *curr_lpc, Word16 *sin_tab,
+ Word16 *cos_tab)
+{
+ Word16 i, k, k4, n, M_fx, HalfLag;
+ Word16 fdiff, freq;
+ Word32 Ltemp;
+ Word32 Lacc;
+ Word32 Re, Im; /* Q27 */
+ Word32 en;
+ Word16 exp,tmp,expa,fraca,expb,fracb,scale;
+ Word32 L_tmp;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+ en = L_deposit_l(0);
+
+ if (EQ_16(hband,X_fx->upper_cut_off_freq_fx))
+ {
+ hband = 0x2803;
+ move16(); /* 4001.0/12800 in Q15 */
+ }
+ M_fx=shl(X_fx->lag_fx,2); /* M_fx=4*lag */
+
+ /* Ltemp=invert_dp(X_fx->lag_fx, 4, &n,1); : Ltemp=1/lag, Q(61-n) */
+ /* fdiff=round_fx(L_shl(Ltemp,sub(n,26))); : fdiff=1/lag, Q19 */
+
+ exp = norm_s(X_fx->lag_fx);
+ tmp = div_s(shl(1,sub(14,exp)),X_fx->lag_fx);
+ L_tmp = L_shl(tmp ,add(exp,6));
+ fdiff = round_fx(L_tmp);
+
+ HalfLag = s_min(shr(X_fx->lag_fx,1),X_fx->nH_4kHz_fx);
+ FOR (k=0; k<=HalfLag; k++)
+ {
+ Ltemp=L_mult(fdiff,k); /* Ltemp=k*fdiff, Q20 */
+ freq=extract_h(L_shl(Ltemp,11)); /* k*fdiff in Q15 */
+
+ test();
+ IF (LT_16(freq,hband)&&GE_16(freq,lband))
+ {
+ Lacc = L_add(0x10000000, 0); /* Re=1.0, Q28 */
+ k4=shl(k,2); /* k4=4*k */
+
+ n=k4;
+ move16();
+ FOR (i=0; ia_fx[k],X_fx->a_fx[k]); /* 2*a[k]^2 in 2Q */
+ /* Ltemp=(Word32)L_sat32_40(divide_dp(Ltemp,Lacc,-19,1)); : Ltemp in Q(2Q-13) */
+
+ if(Lacc<0)
+ {
+ Lacc = L_negate(Lacc);
+ }
+
+ IF(Lacc)
+ {
+
+ expa = norm_l(Lacc);
+ fraca = extract_h(L_shl(Lacc,expa));
+ expa = sub(30,add(expa,23));
+
+
+ expb = norm_l(Ltemp);
+ fracb = round_fx(L_shl(Ltemp,expb));
+ expb = sub(30,add(expb, shl(X_fx->Q,1)));
+
+ scale = shr(sub(fraca,fracb),15);
+ fracb = shl(fracb,scale);
+ expb = sub(expb,scale);
+
+ tmp = div_s(fracb,fraca); /* 15-exp */
+ exp = sub(expb,expa);
+#ifdef BASOP_NOGLOB
+ Ltemp = L_shl_o(tmp, sub(add(shl(X_fx->Q,1),exp), 27), &Overflow) ;
+#else
+ Ltemp = L_shl(tmp, sub(add(shl(X_fx->Q,1),exp), 27)) ;
+#endif
+ }
+ ELSE
+ {
+ Ltemp = L_deposit_l(0);
+ }
+
+ test();
+ IF (X_fx->lag_fx%2==0 && EQ_16(k,shr(X_fx->lag_fx,1)))
+ en=L_add(en,L_shr(Ltemp,1));
+ ELSE
+ en=L_add(en,Ltemp); /* en in 2Q-13 */
+ }
+
+ }
+ return(en); /* en in 2Q-13 */
+}
+/*===================================================================*/
+/* FUNCTION : DTFS_poleFilter_fx() */
+/*-------------------------------------------------------------------*/
+/* PURPOSE : pole filtering */
+/*-------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (Word16) lpc[] : lpc coefficients in Q12 */
+/* _ (Word16) N : lpc order */
+/* _ (Word16) X_fx->lag_fx: in Q0 */
+/* _ (Word16 *) S_fx: sin(2pi*n/(4*lag)) table, Q15 */
+/* _ (Word16 *) C_fx: cos(2pi*n/(4*lag)) table, Q15 */
+/*-------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ None */
+/*-------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _ (Word16) X_fx->a_fx[] : in Q(X_fx->Q) */
+/* _ (Word16) X_fx->b_fx[] : in Q(X_fx->Q) */
+/* _ (Word16) X_fx->Q: in Q0 */
+/*-------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : _ None. */
+/*-------------------------------------------------------------------*/
+/* CALLED FROM : TX/RX */
+/*===================================================================*/
+
+void DTFS_poleFilter_fx( DTFS_STRUCTURE *X_fx,Word16 *LPC, Word16 N, Word16 *S_fx, Word16 *C_fx)
+{
+ Word16 temp, temp1, temp2, HalfLag ;
+ Word32 sum1_fx, sum2_fx;
+ Word32 sum, L_temp1, L_temp2;
+ Word16 k, n, na, nb;
+ Word16 Qmin, Qab[MAXLAG_WI];
+ Word16 exp,tmp;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+ Qmin = 32767;
+ move16();
+ HalfLag = s_min(shr(X_fx->lag_fx, 1),X_fx->nH_fx);
+ FOR ( k=0; k<=HalfLag; k++ )
+ {
+ temp2 = k;
+ move16();
+ /* Calculate sum1 and sum2 */
+ sum1_fx = L_deposit_h(4096); /* 1: Q(12+15+1) */
+
+ sum2_fx = L_deposit_l(0);
+ FOR ( n=0 ; nlag_fx)], &Overflow) ; /* Q(12+15+1) */
+ sum2_fx = L_mac_o(sum2_fx, LPC[n], S_fx[(4*temp2)%(4*X_fx->lag_fx)], &Overflow) ; /* Q(12+15+1) */
+#else
+ sum1_fx = L_mac(sum1_fx, LPC[n], C_fx[(4*temp2)%(4*X_fx->lag_fx)]) ; /* Q(12+15+1) */
+ sum2_fx = L_mac(sum2_fx, LPC[n], S_fx[(4*temp2)%(4*X_fx->lag_fx)]) ; /* Q(12+15+1) */
+#endif
+ temp2 = add(temp2, k);
+ }
+
+
+#ifdef BASOP_NOGLOB
+ temp1 = round_fx_o(sum1_fx, &Overflow); /* Q(12+15+1-16)=Q(12) */
+ temp2 = round_fx_o(sum2_fx, &Overflow); /* Q(12) */
+ /* Calculate the circular convolution */
+ sum = L_mac_o(L_mult_o(temp1, temp1, &Overflow), temp2, temp2, &Overflow); /* Q(12+12+1)=Q(25) */
+#else
+ temp1 = round_fx(sum1_fx); /* Q(12+15+1-16)=Q(12) */
+ temp2 = round_fx(sum2_fx); /* Q(12) */
+ /* Calculate the circular convolution */
+ sum = L_mac(L_mult(temp1, temp1), temp2, temp2); /* Q(12+12+1)=Q(25) */
+#endif
+
+ L_temp1 = L_mult(temp1, X_fx->a_fx[k]);
+#ifdef BASOP_NOGLOB
+ L_temp1 = L_mac_o(L_temp1, temp2, X_fx->b_fx[k], &Overflow); /* Q(12+Q+1)=Q(13+Q) */
+#else
+ L_temp1 = L_mac(L_temp1, temp2, X_fx->b_fx[k]); /* Q(12+Q+1)=Q(13+Q) */
+#endif
+ L_temp2 = L_mult(temp1, X_fx->b_fx[k]);
+#ifdef BASOP_NOGLOB
+ L_temp2 = L_msu_o(L_temp2, temp2, X_fx->a_fx[k], &Overflow); /* Q(12+Q+1)=Q(13+Q) */
+#else
+ L_temp2 = L_msu(L_temp2, temp2, X_fx->a_fx[k]); /* Q(12+Q+1)=Q(13+Q) */
+#endif
+ IF(sum)
+ {
+ exp = norm_l(sum);
+ temp1 = exp;
+ tmp = extract_h(L_shl(sum,exp));
+ exp = sub(sub(30,exp),25);
+ tmp = div_s(16384,tmp); /* Q(15+exp) */
+ sum = L_shl(tmp ,16 );
+ temp = round_fx(sum);
+ }
+ ELSE
+ {
+ sum =0;
+ move16();
+ temp =0;
+ move16();
+ temp1 =0;
+ move16();
+
+ }
+ sum1_fx = Mult_32_16(L_temp1, temp); /* Q(13+Q+20-temp1-15)=Q(Q-temp1+18) */
+ sum2_fx = Mult_32_16(L_temp2, temp); /* Q(Q-temp1+18) */
+
+ /* normalization */
+ na = norm_l(sum1_fx);
+ if (sum1_fx==0)
+ {
+ na = 31;
+ move16();
+ }
+ nb = norm_l(sum2_fx);
+ if (sum2_fx==0)
+ {
+ nb = 31;
+ move16();
+ }
+
+ if (LT_16(na, nb))
+ {
+ nb=na;
+ move16();
+ }
+ nb=sub(nb,1); /* leave one more sign bit */
+ X_fx->a_fx[k] = round_fx(L_shl(sum1_fx, nb)); /* Q(Q-temp1+22+nb-16)=Q(Q-temp1+nb+2) */
+ X_fx->b_fx[k] = round_fx(L_shl(sum2_fx, nb)); /* Q(Q-temp1+nb+2) */
+
+ Qab[k] = add(sub(add(nb, 2), temp1),X_fx->Q);
+
+ if (LT_16(Qab[k], Qmin))
+ {
+ Qmin = Qab[k];
+ move16();
+ }
+ }
+ /* bring to the same Q */
+ FOR ( k=0; k<=HalfLag; k++ )
+ {
+ X_fx->a_fx[k] = shl(X_fx->a_fx[k], sub(Qmin, Qab[k]));
+ move16(); /* Q(Q+Qab[k]+Qmin-Qab[k])=Q(Q+Qmin) */
+ X_fx->b_fx[k] = shl(X_fx->b_fx[k], sub(Qmin, Qab[k]));
+ move16(); /* Q(Q+Qab[k]+Qmin-Qab[k])=Q(Q+Qmin) */
+ }
+
+ X_fx->Q = Qmin;
+}
+/*===================================================================*/
+/* FUNCTION : poleFilter_setup_fx() */
+/*-------------------------------------------------------------------*/
+/* PURPOSE : Sets up pole filtering LPC dependent intermediate*/
+/* values to be used by poleFilter */
+/*-------------------------------------------------------------------*/
+/* INPUT ARGUMENTS : */
+/* _ (Word16) lpc[] : lpc coefficients in Q12 */
+/* _ (Word16) N : lpc order */
+/* _ (Word16) lag : in Q0 */
+/* _ (Word16 *) S_fx: sin(2pi*n/(4*lag)) table, Q15 */
+/* _ (Word16 *) C_fx: cos(2pi*n/(4*lag)) table, Q15 */
+/*-------------------------------------------------------------------*/
+/* OUTPUT ARGUMENTS : */
+/* _ None */
+/*-------------------------------------------------------------------*/
+/* INPUT/OUTPUT ARGUMENTS : */
+/* _ None */
+/*-------------------------------------------------------------------*/
+/* RETURN ARGUMENTS : _ None. */
+/*-------------------------------------------------------------------*/
+/* CALLED FROM : TX/RX */
+/*===================================================================*/
+
+void poleFilter_setup_fx(const Word16 *LPC, Word16 N, DTFS_STRUCTURE X_fx, Word16 *S_fx, Word16 *C_fx, Word16 *pf_temp1, Word16 *pf_temp2, Word16 *pf_temp, Word16 *pf_n2_temp1)
+{
+ Word16 temp1, temp2, HalfLag ;
+ Word32 sum1_fx, sum2_fx;
+ Word32 sum;
+ Word16 k, n, n1, n2;
+ Word16 exp,tmp;
+#ifdef BASOP_NOGLOB_DECLARE_LOCAL
+ Flag Overflow = 0;
+#endif
+ HalfLag = s_min(shr(X_fx.lag_fx, 1),X_fx.nH_fx);
+
+ FOR ( k=0; k<=HalfLag; k++ )
+ {
+ temp2 = k;
+ move16();
+ /* Calculate sum1 and sum2 */
+ sum1_fx = L_deposit_h(4096); /* 1: Q(12+15+1) */
+
+ sum2_fx = L_deposit_l(0);
+ FOR ( n=0 ; nnbLostCmpt, st->last_good, st->old_pitch_buf, L_frame == L_FRAME ? &st->old_pitch_buf[2 * NB_SUBFR - 1] : &st->old_pitch_buf[2 * NB_SUBFR16k - 1], &predPitchLag, L_frame == L_FRAME ? PIT_MIN_DOUBLEEXTEND : PIT16k_MIN_EXTEND, L_frame == L_FRAME ? PIT_MAX : PIT16k_MAX, st->mem_pitch_gain, 0, 0, &extrapolationFailed, L_frame / L_SUBFR );
+ pitch_pred_linear_fit( st->nbLostCmpt, st->last_good, st->old_pitch_buf, L_frame == L_FRAME ? &st->old_pitch_buf[2 * NB_SUBFR - 1] : &st->old_pitch_buf[2 * NB_SUBFR16k - 1], &predPitchLag, L_frame == L_FRAME ? PIT_MIN_DOUBLEEXTEND : PIT16k_MIN_EXTEND, L_frame == L_FRAME ? PIT_MAX : PIT16k_MAX, st->mem_pitch_gain_float, 0, 0, &extrapolationFailed, L_frame / L_SUBFR );
new_pit = (int16_t) ( predPitchLag + 0.5f );
diff --git a/lib_dec/FEC_clas_estim.c b/lib_dec/FEC_clas_estim.c
index e514326be3abbe89de0209011db6386818f92a7c..584a99ce15beb6f6d180e0103b173714f8311706 100644
--- a/lib_dec/FEC_clas_estim.c
+++ b/lib_dec/FEC_clas_estim.c
@@ -423,7 +423,7 @@ void FEC_clas_estim(
int16_t oldLenClasBuff, newLenClasBuff;
oldLenClasBuff = (int16_t) ( L_SYN_MEM_CLAS_ESTIM * L_FRAME / L_frame );
newLenClasBuff = L_SYN_MEM_CLAS_ESTIM;
- lerp( &mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - oldLenClasBuff], &mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - newLenClasBuff], newLenClasBuff, oldLenClasBuff );
+ lerp_flt( &mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - oldLenClasBuff], &mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - newLenClasBuff], newLenClasBuff, oldLenClasBuff );
}
synth = old_synth + L_SYN_MEM_CLAS_ESTIM; /* Set pointer to current frame */
diff --git a/lib_dec/acelp_core_dec.c b/lib_dec/acelp_core_dec.c
index 73ba7b138c95be6818ca99d6b3ce43c633b65103..13c2bddfadfebe664916868a4ceba79afece982e 100644
--- a/lib_dec/acelp_core_dec.c
+++ b/lib_dec/acelp_core_dec.c
@@ -164,7 +164,7 @@ ivas_error acelp_core_dec(
/* 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 );
- mvr2r( Aq, st->Aq_cng, M + 1 );
+ mvr2r( Aq, st->Aq_cng_float, M + 1 );
/* update old LSP and LSF vector */
mvr2r( lsf_new, st->lsf_old, M );
@@ -268,14 +268,14 @@ ivas_error acelp_core_dec(
if ( st->L_frame == L_FRAME )
{
- st->gamma = GAMMA1_FLT;
- st->preemph_fac = PREEMPH_FAC_FLT;
+ st->gamma_float = GAMMA1_FLT;
+ st->preemph_fac_float = PREEMPH_FAC_FLT;
int_fs = INT_FS_12k8;
}
else
{
- st->gamma = GAMMA16k_FLT;
- st->preemph_fac = PREEMPH_FAC_16k_FLT;
+ st->gamma_float = GAMMA16k_FLT;
+ st->preemph_fac_float = PREEMPH_FAC_16k_FLT;
int_fs = INT_FS_16k;
}
@@ -319,8 +319,8 @@ ivas_error acelp_core_dec(
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 );
- lerp( 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_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_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_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 );
}
/* convert quantized LSP vector */
@@ -351,7 +351,7 @@ ivas_error acelp_core_dec(
{
dec = DEC_IVAS;
}
- synth_mem_updt2( st->L_frame, st->last_L_frame, st->old_exc, st->mem_syn_r, st->mem_syn2, NULL, dec );
+ synth_mem_updt2_flt( st->L_frame, st->last_L_frame, st->old_exc, st->mem_syn_r_float, st->mem_syn2, 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 );
@@ -504,7 +504,7 @@ ivas_error acelp_core_dec(
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 );
- mvr2r( Aq, st->Aq_cng, M + 1 );
+ mvr2r( Aq, st->Aq_cng_float, M + 1 );
}
else
{
@@ -574,7 +574,7 @@ ivas_error acelp_core_dec(
/* save and delay synthesis to be used by SWB BWE */
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, &st->hBWE_FD->mem_deemph_old_syn );
+ 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 );
}
}
@@ -693,7 +693,7 @@ ivas_error acelp_core_dec(
old_exc_s = st->old_exc + L_EXC_MEM_DEC - st->L_frame;
tmpF = *old_exc_s;
st->mem_deemph = old_exc_s[st->L_frame - 1];
- preemph( old_exc_s, st->preemph_fac, L_FRAME16k, &tmpF );
+ preemph( old_exc_s, st->preemph_fac_float, L_FRAME16k, &tmpF );
mvr2r( old_exc_s + st->L_frame - M, st->mem_syn2, M );
residu( Aq, M, old_exc_s, old_exc + L_EXC_MEM_DEC - st->L_frame, st->L_frame );
}
@@ -703,11 +703,11 @@ ivas_error acelp_core_dec(
/* Prepare ACB memory of old_bwe_exc */
if ( st->L_frame == L_FRAME )
{
- lerp( old_exc, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC );
+ lerp_flt( old_exc, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC );
}
else
{
- lerp( old_exc, old_bwe_exc, L_EXC_MEM_DEC * 2, L_EXC_MEM_DEC );
+ lerp_flt( old_exc, old_bwe_exc, L_EXC_MEM_DEC * 2, L_EXC_MEM_DEC );
}
}
@@ -823,7 +823,7 @@ ivas_error acelp_core_dec(
/* 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, &st->hBWE_FD->mem_deemph_old_syn );
+ 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 );
}
/*-----------------------------------------------------------------*
@@ -905,7 +905,7 @@ ivas_error acelp_core_dec(
* (smoothing is performed in the excitation domain and signal is resynthesized after)
*------------------------------------------------------------*/
- 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, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, exc, exc2, Aq, &st->old_enr_LP, 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( 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 );
/* 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 ) )
@@ -962,7 +962,7 @@ ivas_error acelp_core_dec(
/* 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, &st->hBWE_FD->mem_deemph_old_syn );
+ 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 );
}
/* Apply energy matching when switching to inactive frames */
@@ -1009,7 +1009,7 @@ ivas_error acelp_core_dec(
if ( ( st->total_brate == ACELP_7k20 ) || ( st->total_brate == ACELP_8k00 ) )
{
- 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, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, exc, exc2, Aq, &st->old_enr_LP, 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( 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 );
}
/* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */
@@ -1053,7 +1053,7 @@ ivas_error acelp_core_dec(
}
else
{
- st->psf_lp_noise = st->lp_noise;
+ st->psf_lp_noise = st->lp_noise_float;
}
/*------------------------------------------------------------------*
@@ -1061,8 +1061,8 @@ ivas_error acelp_core_dec(
*-----------------------------------------------------------------*/
/* update old synthesis buffer - needed for ACELP internal sampling rate switching */
- mvr2r( syn + st->L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM );
- deemph( syn, st->preemph_fac, st->L_frame, &( st->mem_deemph ) );
+ 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 );
@@ -1070,7 +1070,7 @@ ivas_error acelp_core_dec(
{
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, M + 1 );
+ mvr2r( syn + st->L_frame - M - 1, st->syn_float, M + 1 );
/*------------------------------------------------------------------*
* Formant post-filter
@@ -1081,7 +1081,7 @@ ivas_error acelp_core_dec(
mvr2r( syn, temp_buf + L_SYN_MEM, L_FRAME16k );
st->hPFstat->on = 1;
- formant_post_filt( st->hPFstat, temp_buf + L_SYN_MEM, Aq, syn, st->L_frame, L_SUBFR, st->lp_noise, st->total_brate, 0 );
+ formant_post_filt( 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 )
{
@@ -1119,7 +1119,7 @@ ivas_error acelp_core_dec(
if ( st->idchan == 0 )
{
- st->lp_noise = st->hFdCngDec->lp_noise_float;
+ st->lp_noise_float = st->hFdCngDec->lp_noise_float;
}
if ( st->element_mode != IVAS_CPE_TD && !st->cng_ism_flag )
@@ -1267,9 +1267,9 @@ ivas_error acelp_core_dec(
pRealSave[i] = realBufferSave[i];
pImagSave[i] = imagBufferSave[i];
}
- if ( st->p_bpf_noise_buf )
+ if ( st->p_bpf_noise_buf_float)
{
- mvr2r( bpf_error_signal, st->p_bpf_noise_buf, st->L_frame );
+ mvr2r( bpf_error_signal, st->p_bpf_noise_buf_float, st->L_frame );
}
/* analysis of the synthesis at internal sampling rate */
@@ -1362,9 +1362,9 @@ ivas_error acelp_core_dec(
/* synthesis of the combined signal - needed for DFT stereo -> TD stereo switching */
cldfbSynthesis( realBuffer, imagBuffer, synth /*dummy*/, NS2SA( st->output_Fs, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ), st->cldfbSyn );
- if ( st->p_bpf_noise_buf )
+ if ( st->p_bpf_noise_buf_float)
{
- mvr2r( bpf_error_signal, st->p_bpf_noise_buf, st->L_frame );
+ mvr2r( bpf_error_signal, st->p_bpf_noise_buf_float, st->L_frame );
}
set_f( synth, 0.0f, output_frame );
diff --git a/lib_dec/amr_wb_dec.c b/lib_dec/amr_wb_dec.c
index 3c0c7c56e0ab17b24bf094c4f6becd74a2c1f4b8..33f980502362d23deeaf4c9e0c0347058ca786aa 100644
--- a/lib_dec/amr_wb_dec.c
+++ b/lib_dec/amr_wb_dec.c
@@ -216,8 +216,8 @@ ivas_error amr_wb_dec(
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 );
- lerp( 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_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_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_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 );
}
/* convert old quantized LSP vector */
@@ -236,7 +236,8 @@ ivas_error amr_wb_dec(
set_zero( st->mem_MA, M );
/* update synthesis filter memories */
- synth_mem_updt2( L_FRAME, st->last_L_frame, st->old_exc, st->mem_syn_r, st->mem_syn2, NULL, DEC );
+
+ synth_mem_updt2_flt( L_FRAME, st->last_L_frame, st->old_exc, st->mem_syn_r_float, st->mem_syn2, 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 );
@@ -492,7 +493,7 @@ ivas_error amr_wb_dec(
* (smoothing is performed in the excitation domain and signal is resynthesized after)
*------------------------------------------------------------*/
- FEC_scale_syn( L_FRAME, st->clas_dec, st->last_good, syn, pitch_buf, st->enr_old, enr_q, -1, MOVING_AVERAGE, &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, exc, exc2, Aq, &st->old_enr_LP, 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( L_FRAME, st->clas_dec, st->last_good, syn, pitch_buf, st->enr_old, enr_q, -1, MOVING_AVERAGE, &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 );
/* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */
fer_energy( L_FRAME, st->clas_dec, syn, pitch_buf[3], &st->enr_old, L_FRAME );
@@ -556,7 +557,7 @@ ivas_error amr_wb_dec(
* (smoothing is performed in the excitation domain and signal is resynthesized after)
*------------------------------------------------------------*/
- FEC_scale_syn( L_FRAME, st->clas_dec, st->last_good, syn, pitch_buf, st->enr_old, enr_q, -1, MOVING_AVERAGE, &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, exc, exc2, Aq, &st->old_enr_LP, mem_tmp, st->mem_syn2, 0, 0 );
+ FEC_scale_syn( L_FRAME, st->clas_dec, st->last_good, syn, pitch_buf, st->enr_old, enr_q, -1, MOVING_AVERAGE, &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, 0, 0 );
/* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */
fer_energy( L_FRAME, st->last_good, syn, FEC_pitch, &st->enr_old, L_FRAME );
@@ -585,7 +586,7 @@ ivas_error amr_wb_dec(
*-----------------------------------------------------------------*/
/* update old synthesis buffer - needed for ACELP internal sampling rate switching */
- mvr2r( syn + L_FRAME - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM );
+ mvr2r( syn + L_FRAME - L_SYN_MEM, st->mem_syn_r_float, L_SYN_MEM );
deemph( syn, PREEMPH_FAC_FLT, L_FRAME, &( st->mem_deemph ) );
@@ -594,7 +595,7 @@ ivas_error amr_wb_dec(
{
mvr2r( syn + L_FRAME / 2, st->hTcxDec->old_syn_Overl_float, L_FRAME / 2 );
}
- mvr2r( syn + L_FRAME - M - 1, st->syn, M + 1 );
+ mvr2r( syn + L_FRAME - M - 1, st->syn_float, M + 1 );
/*------------------------------------------------------------------*
* Formant post-filter
@@ -626,7 +627,7 @@ ivas_error amr_wb_dec(
noisy_speech_detection( st->hFdCngDec, st->VAD, syn );
st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = 0.99f * st->hFdCngDec->hFdCngCom->likelihood_noisy_speech + 0.01f * (float) st->hFdCngDec->hFdCngCom->flag_noisy_speech;
- st->lp_noise = st->hFdCngDec->lp_noise_float;
+ st->lp_noise_float = st->hFdCngDec->lp_noise_float;
if ( st->flag_cna && ( st->psf_lp_noise >= 15.f ) )
{
diff --git a/lib_dec/arith_coder_dec.c b/lib_dec/arith_coder_dec.c
index f9fe8da682a7928780cdaf457b3df278c3adc377..b2609cd730eb18dcfa71a1b2337b26cbe4f848b9 100644
--- a/lib_dec/arith_coder_dec.c
+++ b/lib_dec/arith_coder_dec.c
@@ -165,7 +165,7 @@ void tcx_arith_decode_envelope(
assert( hTcxDec->enableTcxLpc );
gamma_w = 1.0f;
- gamma_uw = 1.0f / st->gamma;
+ gamma_uw = 1.0f / st->gamma_float;
#define WMC_TOOL_SKIP
tcx_arith_render_envelope( A_ind, L_frame, L_spec, FL2WORD16( hTcxCfg->preemph_fac_flt), FL2WORD16( gamma_w ), FL2WORD16( 0.5f * gamma_uw ), env );
diff --git a/lib_dec/cng_dec.c b/lib_dec/cng_dec.c
index 833eba5ecb39ab2fb76ca012cf988ef6c0c986f7..3362a88cc3baf54a9d42c316ed08fba4289156a3 100644
--- a/lib_dec/cng_dec.c
+++ b/lib_dec/cng_dec.c
@@ -766,7 +766,7 @@ static void shb_CNG_decod(
*-------------------------------------------------------------------*/
void td_cng_dec_init(
- DEC_CORE_HANDLE_FLOAT st /* i/o: decoder state structure */
+ DEC_CORE_HANDLE st /* i/o: decoder state structure */
)
{
int16_t i;
diff --git a/lib_dec/core_dec_init.c b/lib_dec/core_dec_init.c
index eeff41b769551aad9e8acc614fec8a5bd3e33641..8f5f014f06de7f433ff74e9a2a31754ad7c0b43f 100644
--- a/lib_dec/core_dec_init.c
+++ b/lib_dec/core_dec_init.c
@@ -102,582 +102,581 @@ void open_decoder_LPD(
st->nb_subfr = NB_SUBFR;
}
st->bits_frame = (int16_t) ( ( (float) st->L_frame / (float) st->fscale ) * (float) FSCALE_DENOM / 128.0f * (float) total_brate / 100.0f + 0.49f );
-
- st->TcxBandwidth = getTcxBandwidth( bwidth );
- st->narrowBand = ( bwidth == NB ) ? 1 : 0;
- encoderLookahead = ( L_LOOK_12k8 * st->fscale ) / FSCALE_DENOM;
- encoderLookaheadFB = ( L_LOOK_12k8 * fscaleFB ) / FSCALE_DENOM;
-
- if ( st->element_mode == IVAS_CPE_MDCT )
- {
- st->pit_res_max = initPitchLagParameters( 12800, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max );
- hTcxDec->pit_max_TCX = (int16_t) ( st->pit_max * st->output_Fs / 12800 );
- hTcxDec->pit_min_TCX = (int16_t) ( st->pit_min * st->output_Fs / 12800 );
- }
- else
- {
- st->pit_res_max = initPitchLagParameters( st->sr_core, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max );
- if ( hTcxDec != NULL )
- {
- hTcxDec->pit_max_TCX = (int16_t) ( st->pit_max * st->output_Fs / st->sr_core );
- hTcxDec->pit_min_TCX = (int16_t) ( st->pit_min * st->output_Fs / st->sr_core );
- }
- }
-
- if ( st->ini_frame == 0 )
- {
- st->pit_res_max_past = st->pit_res_max;
- }
-
- /*Preemphasis param*/
- if ( st->fscale < ( 16000 * FSCALE_DENOM ) / 12800 )
- {
- st->preemph_fac = PREEMPH_FAC_FLT; /*NB*/
- }
- else if ( st->fscale < ( 24000 * FSCALE_DENOM ) / 12800 )
- {
- st->preemph_fac = PREEMPH_FAC_16k_FLT; /*WB*/
- }
- else
- {
- st->preemph_fac = PREEMPH_FAC_SWB_FLT; /*SWB*/
- }
-
- if ( st->sr_core == INT_FS_16k )
- {
- st->gamma = GAMMA16k_FLT;
- }
- else if ( st->sr_core > INT_FS_16k && st->element_mode == IVAS_CPE_MDCT )
- {
- st->gamma = GAMMA16k_FLT;
- }
- else
- {
- st->gamma = GAMMA1_FLT;
- }
-
- /* LPC quantization */
- if ( st->sr_core <= INT_FS_16k && st->tcxonly == 0 )
- {
- st->lpcQuantization = 1;
- }
- else
- {
- st->lpcQuantization = 0;
- }
-
- if ( st->tcxonly == 0 )
- {
- st->numlpc = 1;
- }
- else
- {
- st->numlpc = 2;
- }
-
- /* Initialize TBE */
- st->prev_coder_type = GENERIC;
- if ( st->hBWE_TD != NULL )
- {
- set_f( st->hBWE_TD->prev_lsf_diff, 0.5f, LPC_SHB_ORDER - 2 );
- st->hBWE_TD->prev_tilt_para = 0.0f;
- set_zero( st->hBWE_TD->cur_sub_Aq, M + 1 );
- }
-
- if ( st->hIGFDec != NULL )
- {
- if ( !is_init || st->element_mode != IVAS_CPE_MDCT )
- {
- init_tcx_cfg( st->hTcxCfg, total_brate, st->sr_core, st->output_Fs, st->L_frame, st->bwidth, st->hTcxDec->L_frameTCX, st->fscale, encoderLookahead, encoderLookaheadFB, st->preemph_fac, st->tcxonly, st->rf_flag, st->igf, st->hIGFDec->infoIGFStopFreq, st->element_mode, st->ini_frame, MCT_flag );
- }
- else
- {
- st->hTcxCfg->tcx_curr_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW;
- st->hTcxCfg->last_aldo = 1;
- }
- }
-
- if ( st->hTECDec != NULL )
- {
- resetTecDec( st->hTECDec );
- }
-
- if ( st->element_mode != IVAS_SCE )
- {
- st->flag_cna = 0;
- }
- if ( st->ini_frame == 0 )
- {
- st->flag_cna = 0;
- st->last_flag_cna = 0;
- }
-
- /* Static vectors to zero */
- if ( st->ini_frame == 0 )
- {
- st->last_is_cng = 0;
-
- st->rate_switching_reset = 0;
-
- if ( st->hTcxDec != NULL )
- {
- reset_tcx_overl_buf( st->hTcxDec );
-
- set_zero( st->hTcxDec->syn_OverlFB_float, L_FRAME_MAX / 2 );
- set_zero( st->hTcxDec->old_synth_float, OLD_SYNTH_INTERNAL_DEC );
-
- set_zero( st->hTcxDec->synth_history, L_PROT48k + L_FRAME_MAX );
- }
-
- set_zero( st->syn, M + 1 );
-
- set_zero( st->mem_syn_r, L_SYN_MEM );
-
- mem_syn_r_size_old = 0; /* just to avoid MSVC warnings */
- mem_syn_r_size_new = 0; /* just to avoid MSVC warnings */
-
- st->con_tcx = 0;
- }
- else
- {
- /* Reset old_synth in case of core sampling rate switching and Mode 1/2 switching*/
- if ( st->hTcxDec != NULL && ( ( st->L_frame != st->last_L_frame ) || ( st->last_codec_mode == MODE1 && st->element_mode == EVS_MONO ) ) )
- {
- set_zero( st->hTcxDec->old_synth_float, OLD_SYNTH_INTERNAL_DEC );
- }
-
- /*Compute size of old and new memories*/
- 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 );
-
- /*Reset LPC mem*/
- if ( ( st->L_frame != st->last_L_frame ) || ( st->last_core == AMR_WB_CORE ) || ( st->last_core == HQ_CORE ) )
- {
- set_zero( st->mem_MA, M );
- if ( st->sr_core == INT_FS_16k )
- {
- mvr2r( GEWB2_Ave, st->mem_AR, M );
- }
- else
- {
- mvr2r( GEWB_Ave, st->mem_AR, M );
- }
- }
-
- /*Mode 1/2 switching*/
- if ( st->last_codec_mode == MODE1 && st->element_mode == EVS_MONO )
- {
- mvr2r( st->lsp_old, st->lspold_uw, M );
- mvr2r( st->lsf_old, st->lsfold_uw, M );
- set_zero( st->syn, M );
- }
- if ( st->last_core == AMR_WB_CORE )
- {
- st->last_core = ACELP_CORE;
- st->last_core_bfi = ACELP_CORE;
- }
-
- if ( ( ( st->element_mode != IVAS_CPE_DFT ) || ( st->element_mode == IVAS_CPE_DFT && st->prev_bfi ) ) && st->last_codec_mode == MODE1 && st->last_core == ACELP_CORE )
- {
- /* Switching from Mode 1 ACELP */
- st->last_core_bfi = ACELP_CORE;
- acelp_plc_mdct_transition( st );
- }
-
- if ( st->last_codec_mode == MODE2 &&
- st->L_frame != st->last_L_frame &&
- ( ( st->m_frame_type == SID_FRAME && st->last_core > ACELP_CORE ) ||
- ( st->last_core > ACELP_CORE && st->core > ACELP_CORE ) || st->prev_bfi ) )
- {
- lerp( st->hHQ_core->old_outLB, st->hHQ_core->old_outLB, st->L_frame, st->last_L_frame );
- }
-
- /* Rate switching */
- if ( st->last_codec_mode == MODE1 && st->last_core == HQ_CORE )
- {
- /* Switching from MDCT */
-
- /*Reset of ACELP memories*/
- st->rate_switching_reset = 1;
- st->tilt_code = TILT_CODE;
- set_zero( st->old_exc, L_EXC_MEM_DEC );
- set_zero( st->syn, 1 + M );
- set_zero( st->mem_syn2, M );
-
- /*OLA -> zero */
- if ( st->hTcxDec != NULL )
- {
- reset_tcx_overl_buf( st->hTcxDec );
- }
-
- if ( st->hTcxCfg != NULL )
- {
- mvr2r( st->hHQ_core->old_out + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->syn_OverlFB_float, st->hTcxCfg->tcx_mdct_window_lengthFB );
- st->hTcxCfg->last_aldo = 1; /*It was previously ALDO*/
- st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW;
- }
-
- /*OLA for Mode 2 TCX always reset in Mode switching cases*/
- if ( st->hHQ_core != NULL )
- {
- set_f( st->hHQ_core->old_outLB, 0, st->L_frame );
- }
-
- st->last_core_bfi = TCX_20_CORE;
-
- if ( st->hPFstat != NULL )
- {
- st->hPFstat->on = 0;
- }
-
- /* reset CLDFB memories */
- cldfb_reset_memory( st->cldfbAna );
- cldfb_reset_memory( st->cldfbBPF );
- cldfb_reset_memory( st->cldfbSyn );
- if ( st->cldfbSynHB != NULL )
- {
- cldfb_reset_memory( st->cldfbSynHB );
- }
- }
- else if ( ( st->L_frame != st->last_L_frame ) && ( st->L_frame <= L_FRAME16k ) && ( st->last_L_frame <= L_FRAME16k ) ) /* Rate switching between 12.8 and 16 kHz*/
- {
- /*Interpolation of ACELP memories*/
-
- /* convert quantized LSP vector */
- st->rate_switching_reset = lsp_convert_poly( st->lsp_old, st->L_frame, 0 );
- lsp2a_stab( st->lsp_old, st->old_Aq_12_8, M );
-
- lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core );
- mvr2r( st->lsp_old, st->lspold_uw, M );
- mvr2r( st->lsf_old, st->lsfold_uw, M );
-
- if ( !st->last_con_tcx )
- {
- synth_mem_updt2( st->L_frame, st->last_L_frame, st->old_exc, st->mem_syn_r, st->mem_syn2, NULL, DEC );
- }
-
- /*mem of deemphasis stayed unchanged.*/
- }
- else if ( st->L_frame != st->last_L_frame ) /* Rate switching involving TCX only modes */
- {
- /*Partial reset of ACELP memories*/
- st->rate_switching_reset = 1;
-
- /*reset partly some memories*/
- st->tilt_code = TILT_CODE;
- if ( !st->last_con_tcx )
- {
- set_zero( st->old_exc, L_EXC_MEM_DEC );
- }
- set_zero( st->old_Aq_12_8, M + 1 );
-
- /*Resamp others memories*/
- /*Size of LPC syn memory*/
- lerp( st->mem_syn_r + L_SYN_MEM - mem_syn_r_size_old, st->mem_syn_r + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
- mvr2r( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2, M );
- }
- /* update of lsf_old only needed in BASOP */
- /* else if( !st->tcxonly && (st->L_frame == L_FRAME16k) && (st->last_total_brate > ACELP_32k) ) */
- /* { */
- /* lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core ); */
- /* } */
- }
-
- if ( st->last_bwidth == NB && st->bwidth != NB && st->ini_frame != 0 )
- {
- st->rate_switching_reset = 1;
- }
-
- if ( st->hTcxDec != NULL )
- {
- st->hTcxDec->old_synth_len = 2 * st->L_frame;
- st->hTcxDec->old_synth_lenFB = 2 * st->hTcxDec->L_frameTCX;
- }
-
- /* bass pf reset */
- st->bpf_gain_param = 0;
- if ( st->hBPF != NULL )
- {
- set_f( st->hBPF->pst_old_syn, 0, NBPSF_PIT_MAX );
- }
-
- /* Formant postfilter */
- if ( st->ini_frame == 0 )
- {
- /* do nothing */
- }
- else if ( st->last_codec_mode == MODE2 )
- {
- if ( !st->tcxonly )
- {
- if ( st->hPFstat->on )
- {
- lerp( 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_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 );
- }
- else
- {
- set_zero( st->hPFstat->mem_stp_flt, L_SYN_MEM );
- set_zero( st->hPFstat->mem_pf_in_flt, L_SYN_MEM );
- st->hPFstat->reset = 1;
- st->hPFstat->gain_prec_flt = 1.f;
- }
- }
- else if ( st->hPFstat->on )
- {
- lerp( 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_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 );
- }
- }
- else
- {
- /*codec mode switching*/
-
- /*reset post-filter except for Narrowband*/
- if ( ( (int16_t) ( st->output_Fs / FRAMES_PER_SEC ) ) != L_FRAME8k )
- {
- if ( st->hPFstat != NULL )
- {
- st->hPFstat->reset = 1;
- if ( st->hPFstat->on != 0 )
- {
- st->hPFstat->reset = 0;
- lerp( 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_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 );
- }
- }
- }
- else
- {
- /*feed last value old_synth as it is used for pre-emphasis mem*/
- if ( st->hTcxDec != NULL )
- {
- st->hTcxDec->old_synth_float[st->hTcxDec->old_synth_len - 1] = st->syn[M];
- }
- if ( st->hBPF != NULL )
- {
- st->hBPF->pst_old_syn[NBPSF_PIT_MAX - 1] = st->syn[M];
- }
- }
- }
-
- /* lsf and lsp initialization */
- if ( st->ini_frame == 0 )
- {
- mvr2r( st->lsp_old, st->lspold_uw, M );
- mvr2r( st->lsf_old, st->lsfold_uw, M );
-
- set_zero( st->lsf_cng, M );
- }
-
- st->seed_tcx_plc = RANDOM_INITSEED;
- st->past_gpit = 0.0f;
- st->past_gcode = 0.0f;
- st->gc_threshold = 0.0f;
-
- lsf2lsp( st->lsf_cng, st->lspold_cng, M, INT_FS_12k8 );
- lsp2a_stab( st->lspold_cng, st->Aq_cng, M );
- st->plcBackgroundNoiseUpdated = 0;
- mvr2r( st->lsf_old, st->lsf_q_cng, M );
- mvr2r( st->lsf_old, st->old_lsf_q_cng, M );
- mvr2r( st->lsp_old, st->lsp_q_cng, M );
- mvr2r( st->lsp_old, st->old_lsp_q_cng, M );
- set_zero( st->mem_syn_unv_back, M );
- st->last_gain_syn_deemph = 1.f;
-
- if ( st->last_codec_mode == MODE1 || st->ini_frame == 0 )
- {
- /* this assumes that MODE1 fades out in the frequency domain -
- otherwise some data from MODE1 would be needed here */
- st->last_concealed_gain_syn_deemph = 1.f;
- if ( hTcxDec != NULL )
- {
- hTcxDec->conceal_eof_gain_float = 1.0f;
- }
- }
- /* Post processing */
- set_zero( st->mem_Aq, NB_SUBFR16k * ( M + 1 ) );
-
- st->lp_ener_bfi = 60.0f;
- if ( st->ini_frame == 0 )
- {
- st->prev_bfi = 0;
- st->last_core_bfi = -1;
- if ( st->hTcxDec != NULL )
- {
- hTcxDec->tcxConceal_recalc_exc = 0;
- }
- }
- st->prev_old_bfi = 0;
-
- if ( st->hTcxDec != NULL )
- {
- st->hTcxDec->noise_filling_index[0] = st->hTcxDec->noise_filling_index[1] = 0;
- st->hTcxDec->tnsActive[0] = st->hTcxDec->tnsActive[1] = 0;
- set_f( st->hTcxDec->ltpGainMemory, 0.0f, N_LTP_GAIN_MEMS );
- }
-
- mvr2r( st->lsf_old, st->lsf_adaptive_mean, M );
- mvr2r( st->lsf_old, st->lsfoldbfi0, M );
- mvr2r( st->lsf_old, st->lsfoldbfi1, M );
-
- st->clas_dec = UNVOICED_CLAS;
-
- if ( !st->last_con_tcx )
- {
- st->old_enr_LP = 0.0f; /* LP filter E of last good voiced frame or local LP filter E in TD TCX PLC */
- }
-
- if ( st->prev_bfi )
- {
- /* calculate energy at the end of the previous frame */
- if ( st->core == ACELP_CORE && st->last_core == HQ_CORE )
- {
- fer_energy( st->hTcxDec->L_frameTCX, UNVOICED_CLAS, st->previoussynth, -1, &st->enr_old, 1 );
- }
- }
- else
- {
- st->last_good = UNVOICED_CLAS; /* last good received frame for concealment */
- st->enr_old = 0.0f; /* energy at the end of the previous frame */
- }
- st->lp_gainc = 0.0f;
- st->lp_gainp = 0.0f;
-
- if ( st->hTcxDec != NULL )
- {
- st->hTcxDec->prev_widow_left_rect = 0;
-
- if ( is_init || MCT_flag || !( st->element_mode == IVAS_CPE_MDCT && st->element_mode == last_element_mode ) )
- {
- st->hTcxDec->CngLevelBackgroundTrace_bfi = PLC_MIN_CNG_LEV_FLT;
- st->hTcxDec->NoiseLevelIndex_bfi = PLC_MIN_STAT_BUFF_SIZE - 1;
- st->hTcxDec->CurrLevelIndex_bfi = 0;
- st->hTcxDec->LastFrameLevel_bfi = PLC_MIN_CNG_LEV_FLT;
- set_f( st->hTcxDec->NoiseLevelMemory_bfi, PLC_MIN_CNG_LEV_FLT, PLC_MIN_STAT_BUFF_SIZE );
-
- st->hTcxDec->cummulative_damping_tcx_float = 1.0f;
- }
- }
-
- st->cummulative_damping = 1.0f;
-
- for ( i = 0; i < 2 * NB_SUBFR16k + 2; i++ )
- {
- st->old_pitch_buf[i] = (float) st->pit_min;
- }
-
- for ( i = 0; i < 2 * NB_SUBFR16k + 2; i++ )
- {
- st->mem_pitch_gain[i] = 1.f;
- }
-
- st->old_fpitch = (float) st->pit_min;
-
- st->rate_switching_init = 1;
-
- st->reset_mem_AR = 0;
-
- /* For phase dispersion */
- set_zero( st->dispMem, 8 );
-
- st->voice_fac = -1; /* purely unvoiced */
-
- /* TCX-LTP */
- if ( hTcxLtpDec != NULL )
- {
- tcxltp_dec_init( hTcxLtpDec, st->ini_frame, st->last_codec_mode, st->element_mode, st->pit_max, st->sr_core );
- }
-
- /* TCX */
- if ( hTcxDec != NULL )
- {
- st->old_fpitchFB = (float) hTcxDec->pit_min_TCX;
-
- if ( st->ini_frame == 0 || ( st->last_codec_mode == MODE1 && st->element_mode == EVS_MONO ) )
- {
- hTcxDec->tcxltp_last_gain_unmodified_float = 0.f;
- }
-
- /* TCX */
- hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri( total_brate, st->rf_flag, st->element_mode );
-
- hTcxDec->envWeighted = 0;
- }
-
- if ( st->hBPF != NULL )
- {
- st->hBPF->pst_mem_deemp_err = 0.0f;
- }
-
- if ( st->tcxonly )
- {
- st->p_bpf_noise_buf = NULL;
- }
- else
- {
- st->p_bpf_noise_buf = st->bpf_noise_buf;
- }
-
- if ( bwidth == SWB && ( total_brate == ACELP_16k40 || total_brate == ACELP_24k40 ) && st->element_mode == EVS_MONO )
- {
- st->tec_tfa = 1;
- }
- else
- {
- st->tec_tfa = 0;
- }
-
- st->tec_flag = 0;
- st->tfa_flag = 0;
-
- /* needed in decoder to read the bitstream */
- st->enableGplc = 0;
-
- st->flagGuidedAcelp = 0;
- st->tonal_mdct_plc_active = 0;
- st->T0_4th = L_SUBFR;
- st->guidedT0 = st->T0_4th;
-
- if ( st->hPlcInfo != NULL && total_brate >= HQ_48k && st->element_mode == EVS_MONO )
- {
- st->enablePlcWaveadjust = 1;
-
- if ( st->hTcxDec != NULL && ( st->ini_frame == 0 || last_total_brate < HQ_48k || st->last_codec_mode == MODE1 || st->force_lpd_reset ) )
- {
- concealment_init( st->hTcxDec->L_frameTCX, st->hPlcInfo );
- }
- }
- else
- {
- st->enablePlcWaveadjust = 0;
- }
-
- /* PLC: [TCX: Tonal Concealment] */
- if ( st->hTonalMDCTConc != NULL && !( st->element_mode > EVS_MONO && st->ini_frame != 0 && st->hTonalMDCTConc->nSamples == st->hTcxDec->L_frameTCX ) )
- {
- st->hTonalMDCTConc->nScaleFactors = 0;
- st->hTonalMDCTConc->nSamples = 0;
- st->hTonalMDCTConc->lastPcmOut_float = 0x0;
- st->hTonalMDCTConc->lastBlockData.tonalConcealmentActive = 0;
- st->hTonalMDCTConc->lastBlockData.nSamples = 0;
-
- TonalMDCTConceal_Init( st->hTonalMDCTConc, st->hTcxDec->L_frameTCX, st->L_frame, FDNS_NPTS, st->hTcxCfg );
- }
-
- st->last_tns_active = 0;
- st->second_last_tns_active = 0;
- st->second_last_core = -1;
-
- if ( st->hTcxCfg != NULL &&
- st->element_mode != EVS_MONO )
- {
- st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( is_init ? total_brate : st->bits_frame_nominal * FRAMES_PER_SEC, st->igf, st->element_mode );
- }
- if ( hTcxDec != NULL )
- {
- hTcxDec->tcxltp_second_last_pitch_float = st->old_fpitch;
- hTcxDec->tcxltp_third_last_pitch_float = st->old_fpitch;
+ st->TcxBandwidth_float = getTcxBandwidth(bwidth);
+ st->narrowBand = (bwidth == NB) ? 1 : 0;
+ encoderLookahead = (L_LOOK_12k8 * st->fscale) / FSCALE_DENOM;
+ encoderLookaheadFB = (L_LOOK_12k8 * fscaleFB) / FSCALE_DENOM;
+
+ if (st->element_mode == IVAS_CPE_MDCT)
+ {
+ st->pit_res_max = initPitchLagParameters(12800, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max);
+ hTcxDec->pit_max_TCX = (int16_t)(st->pit_max * st->output_Fs / 12800);
+ hTcxDec->pit_min_TCX = (int16_t)(st->pit_min * st->output_Fs / 12800);
+ }
+ else
+ {
+ st->pit_res_max = initPitchLagParameters(st->sr_core, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max);
+ if (hTcxDec != NULL)
+ {
+ hTcxDec->pit_max_TCX = (int16_t)(st->pit_max * st->output_Fs / st->sr_core);
+ hTcxDec->pit_min_TCX = (int16_t)(st->pit_min * st->output_Fs / st->sr_core);
+ }
+ }
+
+ if (st->ini_frame == 0)
+ {
+ st->pit_res_max_past = st->pit_res_max;
+ }
+
+ /*Preemphasis param*/
+ if (st->fscale < (16000 * FSCALE_DENOM) / 12800)
+ {
+ st->preemph_fac_float = PREEMPH_FAC_FLT; /*NB*/
+ }
+ else if (st->fscale < (24000 * FSCALE_DENOM) / 12800)
+ {
+ st->preemph_fac_float = PREEMPH_FAC_16k_FLT; /*WB*/
+ }
+ else
+ {
+ st->preemph_fac_float = PREEMPH_FAC_SWB_FLT; /*SWB*/
+ }
+
+ if (st->sr_core == INT_FS_16k)
+ {
+ st->gamma_float = GAMMA16k_FLT;
+ }
+ else if (st->sr_core > INT_FS_16k && st->element_mode == IVAS_CPE_MDCT)
+ {
+ st->gamma_float = GAMMA16k_FLT;
+ }
+ else
+ {
+ st->gamma_float = GAMMA1_FLT;
+ }
+
+ /* LPC quantization */
+ if (st->sr_core <= INT_FS_16k && st->tcxonly == 0)
+ {
+ st->lpcQuantization = 1;
+ }
+ else
+ {
+ st->lpcQuantization = 0;
+ }
+
+ if (st->tcxonly == 0)
+ {
+ st->numlpc = 1;
+ }
+ else
+ {
+ st->numlpc = 2;
+ }
+
+ /* Initialize TBE */
+ st->prev_coder_type = GENERIC;
+ if (st->hBWE_TD != NULL)
+ {
+ set_f(st->hBWE_TD->prev_lsf_diff, 0.5f, LPC_SHB_ORDER - 2);
+ st->hBWE_TD->prev_tilt_para = 0.0f;
+ set_zero(st->hBWE_TD->cur_sub_Aq, M + 1);
+ }
+
+ if (st->hIGFDec != NULL)
+ {
+ if (!is_init || st->element_mode != IVAS_CPE_MDCT)
+ {
+ init_tcx_cfg(st->hTcxCfg, total_brate, st->sr_core, st->output_Fs, st->L_frame, st->bwidth, st->hTcxDec->L_frameTCX, st->fscale, encoderLookahead, encoderLookaheadFB, st->preemph_fac_float, st->tcxonly, st->rf_flag, st->igf, st->hIGFDec->infoIGFStopFreq, st->element_mode, st->ini_frame, MCT_flag);
+ }
+ else
+ {
+ st->hTcxCfg->tcx_curr_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW;
+ st->hTcxCfg->last_aldo = 1;
+ }
+ }
+
+ if (st->hTECDec != NULL)
+ {
+ resetTecDec(st->hTECDec);
+ }
+
+ if (st->element_mode != IVAS_SCE)
+ {
+ st->flag_cna = 0;
+ }
+ if (st->ini_frame == 0)
+ {
+ st->flag_cna = 0;
+ st->last_flag_cna = 0;
+ }
+
+ /* Static vectors to zero */
+ if (st->ini_frame == 0)
+ {
+ st->last_is_cng = 0;
+
+ st->rate_switching_reset = 0;
+
+ if (st->hTcxDec != NULL)
+ {
+ reset_tcx_overl_buf(st->hTcxDec);
+
+ set_zero(st->hTcxDec->syn_OverlFB_float, L_FRAME_MAX / 2);
+ set_zero(st->hTcxDec->old_synth_float, OLD_SYNTH_INTERNAL_DEC);
+
+ set_zero(st->hTcxDec->synth_history, L_PROT48k + L_FRAME_MAX);
+ }
+
+ set_zero(st->syn_float, M + 1);
+
+ set_zero(st->mem_syn_r_float, L_SYN_MEM);
+
+ mem_syn_r_size_old = 0; /* just to avoid MSVC warnings */
+ mem_syn_r_size_new = 0; /* just to avoid MSVC warnings */
+
+ st->con_tcx = 0;
+ }
+ else
+ {
+ /* Reset old_synth in case of core sampling rate switching and Mode 1/2 switching*/
+ if (st->hTcxDec != NULL && ((st->L_frame != st->last_L_frame) || (st->last_codec_mode == MODE1 && st->element_mode == EVS_MONO)))
+ {
+ set_zero(st->hTcxDec->old_synth_float, OLD_SYNTH_INTERNAL_DEC);
+ }
+
+ /*Compute size of old and new memories*/
+ 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);
+
+ /*Reset LPC mem*/
+ if ((st->L_frame != st->last_L_frame) || (st->last_core == AMR_WB_CORE) || (st->last_core == HQ_CORE))
+ {
+ set_zero(st->mem_MA, M);
+ if (st->sr_core == INT_FS_16k)
+ {
+ mvr2r(GEWB2_Ave, st->mem_AR, M);
+ }
+ else
+ {
+ mvr2r(GEWB_Ave, st->mem_AR, M);
+ }
+ }
+
+ /*Mode 1/2 switching*/
+ if (st->last_codec_mode == MODE1 && st->element_mode == EVS_MONO)
+ {
+ mvr2r(st->lsp_old, st->lspold_uw_float, M);
+ mvr2r(st->lsf_old, st->lsfold_uw_float, M);
+ set_zero(st->syn_float, M);
+ }
+ if (st->last_core == AMR_WB_CORE)
+ {
+ st->last_core = ACELP_CORE;
+ st->last_core_bfi = ACELP_CORE;
+ }
+
+ if (((st->element_mode != IVAS_CPE_DFT) || (st->element_mode == IVAS_CPE_DFT && st->prev_bfi)) && st->last_codec_mode == MODE1 && st->last_core == ACELP_CORE)
+ {
+ /* Switching from Mode 1 ACELP */
+ st->last_core_bfi = ACELP_CORE;
+ acelp_plc_mdct_transition(st);
+ }
+
+ if (st->last_codec_mode == MODE2 &&
+ st->L_frame != st->last_L_frame &&
+ ((st->m_frame_type == SID_FRAME && st->last_core > ACELP_CORE) ||
+ (st->last_core > ACELP_CORE && st->core > ACELP_CORE) || st->prev_bfi))
+ {
+ lerp_flt(st->hHQ_core->old_outLB, st->hHQ_core->old_outLB, st->L_frame, st->last_L_frame);
+ }
+
+ /* Rate switching */
+ if (st->last_codec_mode == MODE1 && st->last_core == HQ_CORE)
+ {
+ /* Switching from MDCT */
+
+ /*Reset of ACELP memories*/
+ st->rate_switching_reset = 1;
+ st->tilt_code = TILT_CODE;
+ set_zero(st->old_exc, L_EXC_MEM_DEC);
+ set_zero(st->syn_float, 1 + M);
+ set_zero(st->mem_syn2, M);
+
+ /*OLA -> zero */
+ if (st->hTcxDec != NULL)
+ {
+ reset_tcx_overl_buf(st->hTcxDec);
+ }
+
+ if (st->hTcxCfg != NULL)
+ {
+ mvr2r(st->hHQ_core->old_out + NS2SA(st->output_Fs, N_ZERO_MDCT_NS), st->hTcxDec->syn_OverlFB_float, st->hTcxCfg->tcx_mdct_window_lengthFB);
+ st->hTcxCfg->last_aldo = 1; /*It was previously ALDO*/
+ st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW;
+ }
+
+ /*OLA for Mode 2 TCX always reset in Mode switching cases*/
+ if (st->hHQ_core != NULL)
+ {
+ set_f(st->hHQ_core->old_outLB, 0, st->L_frame);
+ }
+
+ st->last_core_bfi = TCX_20_CORE;
+
+ if (st->hPFstat != NULL)
+ {
+ st->hPFstat->on = 0;
+ }
+
+ /* reset CLDFB memories */
+ cldfb_reset_memory(st->cldfbAna);
+ cldfb_reset_memory(st->cldfbBPF);
+ cldfb_reset_memory(st->cldfbSyn);
+ if (st->cldfbSynHB != NULL)
+ {
+ cldfb_reset_memory(st->cldfbSynHB);
+ }
+ }
+ else if ((st->L_frame != st->last_L_frame) && (st->L_frame <= L_FRAME16k) && (st->last_L_frame <= L_FRAME16k)) /* Rate switching between 12.8 and 16 kHz*/
+ {
+ /*Interpolation of ACELP memories*/
+
+ /* convert quantized LSP vector */
+ st->rate_switching_reset = lsp_convert_poly(st->lsp_old, st->L_frame, 0);
+ lsp2a_stab(st->lsp_old, st->old_Aq_12_8, M);
+
+ lsp2lsf(st->lsp_old, st->lsf_old, M, st->sr_core);
+ mvr2r(st->lsp_old, st->lspold_uw_float, M);
+ mvr2r(st->lsf_old, st->lsfold_uw_float, M);
+
+ if (!st->last_con_tcx)
+ {
+ synth_mem_updt2_flt(st->L_frame, st->last_L_frame, st->old_exc, st->mem_syn_r_float, st->mem_syn2, NULL, DEC);
+ }
+
+ /*mem of deemphasis stayed unchanged.*/
+ }
+ else if (st->L_frame != st->last_L_frame) /* Rate switching involving TCX only modes */
+ {
+ /*Partial reset of ACELP memories*/
+ st->rate_switching_reset = 1;
+
+ /*reset partly some memories*/
+ st->tilt_code = TILT_CODE;
+ if (!st->last_con_tcx)
+ {
+ set_zero(st->old_exc, L_EXC_MEM_DEC);
+ }
+ set_zero(st->old_Aq_12_8, M + 1);
+
+ /*Resamp others memories*/
+ /*Size of LPC syn memory*/
+ lerp_flt(st->mem_syn_r_float + L_SYN_MEM - mem_syn_r_size_old, st->mem_syn_r_float + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old);
+ mvr2r(st->mem_syn_r_float + L_SYN_MEM - M, st->mem_syn2, M);
+ }
+ /* update of lsf_old only needed in BASOP */
+ /* else if( !st->tcxonly && (st->L_frame == L_FRAME16k) && (st->last_total_brate > ACELP_32k) ) */
+ /* { */
+ /* lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core ); */
+ /* } */
+ }
+
+ if (st->last_bwidth == NB && st->bwidth != NB && st->ini_frame != 0)
+ {
+ st->rate_switching_reset = 1;
+ }
+
+ if (st->hTcxDec != NULL)
+ {
+ st->hTcxDec->old_synth_len = 2 * st->L_frame;
+ st->hTcxDec->old_synth_lenFB = 2 * st->hTcxDec->L_frameTCX;
+ }
+
+ /* bass pf reset */
+ st->bpf_gain_param = 0;
+ if (st->hBPF != NULL)
+ {
+ set_f(st->hBPF->pst_old_syn, 0, NBPSF_PIT_MAX);
+ }
+
+ /* Formant postfilter */
+ if (st->ini_frame == 0)
+ {
+ /* do nothing */
+ }
+ else if (st->last_codec_mode == MODE2)
+ {
+ if (!st->tcxonly)
+ {
+ if (st->hPFstat->on)
+ {
+ 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_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);
+ }
+ else
+ {
+ set_zero(st->hPFstat->mem_stp_flt, L_SYN_MEM);
+ set_zero(st->hPFstat->mem_pf_in_flt, L_SYN_MEM);
+ st->hPFstat->reset = 1;
+ st->hPFstat->gain_prec_flt = 1.f;
+ }
+ }
+ else if (st->hPFstat->on)
+ {
+ 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_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);
+ }
+ }
+ else
+ {
+ /*codec mode switching*/
+
+ /*reset post-filter except for Narrowband*/
+ if (((int16_t)(st->output_Fs / FRAMES_PER_SEC)) != L_FRAME8k)
+ {
+ if (st->hPFstat != NULL)
+ {
+ st->hPFstat->reset = 1;
+ if (st->hPFstat->on != 0)
+ {
+ st->hPFstat->reset = 0;
+ 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_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);
+ }
+ }
+ }
+ else
+ {
+ /*feed last value old_synth as it is used for pre-emphasis mem*/
+ if (st->hTcxDec != NULL)
+ {
+ st->hTcxDec->old_synth_float[st->hTcxDec->old_synth_len - 1] = st->syn_float[M];
+ }
+ if (st->hBPF != NULL)
+ {
+ st->hBPF->pst_old_syn[NBPSF_PIT_MAX - 1] = st->syn_float[M];
+ }
+ }
+ }
+
+ /* lsf and lsp initialization */
+ if (st->ini_frame == 0)
+ {
+ mvr2r(st->lsp_old, st->lspold_uw_float, M);
+ mvr2r(st->lsf_old, st->lsfold_uw_float, M);
+
+ set_zero(st->lsf_cng_float, M);
+ }
+
+ st->seed_tcx_plc = RANDOM_INITSEED;
+ st->past_gpit_float = 0.0f;
+ st->past_gcode_float = 0.0f;
+ st->gc_threshold = 0.0f;
+
+ lsf2lsp(st->lsf_cng_float, st->lspold_cng_float, M, INT_FS_12k8);
+ lsp2a_stab(st->lspold_cng_float, st->Aq_cng_float, M);
+ st->plcBackgroundNoiseUpdated = 0;
+ mvr2r(st->lsf_old, st->lsf_q_cng_float, M);
+ mvr2r(st->lsf_old, st->old_lsf_q_cng_float, M);
+ mvr2r(st->lsp_old, st->lsp_q_cng_float, M);
+ mvr2r(st->lsp_old, st->old_lsp_q_cng_float, M);
+ set_zero(st->mem_syn_unv_back_float, M);
+ st->last_gain_syn_deemph_float = 1.f;
+
+ if (st->last_codec_mode == MODE1 || st->ini_frame == 0)
+ {
+ /* this assumes that MODE1 fades out in the frequency domain -
+ otherwise some data from MODE1 would be needed here */
+ st->last_concealed_gain_syn_deemph_float = 1.f;
+ if (hTcxDec != NULL)
+ {
+ hTcxDec->conceal_eof_gain_float = 1.0f;
+ }
+ }
+ /* Post processing */
+ set_zero(st->mem_Aq_float, NB_SUBFR16k * (M + 1));
+
+ st->lp_ener_bfi = 60.0f;
+ if (st->ini_frame == 0)
+ {
+ st->prev_bfi = 0;
+ st->last_core_bfi = -1;
+ if (st->hTcxDec != NULL)
+ {
+ hTcxDec->tcxConceal_recalc_exc = 0;
+ }
+ }
+ st->prev_old_bfi = 0;
+
+ if (st->hTcxDec != NULL)
+ {
+ st->hTcxDec->noise_filling_index[0] = st->hTcxDec->noise_filling_index[1] = 0;
+ st->hTcxDec->tnsActive[0] = st->hTcxDec->tnsActive[1] = 0;
+ set_f(st->hTcxDec->ltpGainMemory, 0.0f, N_LTP_GAIN_MEMS);
+ }
+
+ mvr2r(st->lsf_old, st->lsf_adaptive_mean, M);
+ mvr2r(st->lsf_old, st->lsfoldbfi0, M);
+ mvr2r(st->lsf_old, st->lsfoldbfi1, M);
+
+ st->clas_dec = UNVOICED_CLAS;
+
+ if (!st->last_con_tcx)
+ {
+ st->old_enr_LP_float = 0.0f; /* LP filter E of last good voiced frame or local LP filter E in TD TCX PLC */
+ }
+
+ if (st->prev_bfi)
+ {
+ /* calculate energy at the end of the previous frame */
+ if (st->core == ACELP_CORE && st->last_core == HQ_CORE)
+ {
+ fer_energy(st->hTcxDec->L_frameTCX, UNVOICED_CLAS, st->previoussynth, -1, &st->enr_old, 1);
+ }
+ }
+ else
+ {
+ st->last_good = UNVOICED_CLAS; /* last good received frame for concealment */
+ st->enr_old = 0.0f; /* energy at the end of the previous frame */
+ }
+ st->lp_gainc = 0.0f;
+ st->lp_gainp = 0.0f;
+
+ if (st->hTcxDec != NULL)
+ {
+ st->hTcxDec->prev_widow_left_rect = 0;
+
+ if (is_init || MCT_flag || !(st->element_mode == IVAS_CPE_MDCT && st->element_mode == last_element_mode))
+ {
+ st->hTcxDec->CngLevelBackgroundTrace_bfi = PLC_MIN_CNG_LEV_FLT;
+ st->hTcxDec->NoiseLevelIndex_bfi = PLC_MIN_STAT_BUFF_SIZE - 1;
+ st->hTcxDec->CurrLevelIndex_bfi = 0;
+ st->hTcxDec->LastFrameLevel_bfi = PLC_MIN_CNG_LEV_FLT;
+ set_f(st->hTcxDec->NoiseLevelMemory_bfi, PLC_MIN_CNG_LEV_FLT, PLC_MIN_STAT_BUFF_SIZE);
+
+ st->hTcxDec->cummulative_damping_tcx_float = 1.0f;
+ }
+ }
+
+ st->cummulative_damping_float = 1.0f;
+
+ for (i = 0; i < 2 * NB_SUBFR16k + 2; i++)
+ {
+ st->old_pitch_buf[i] = (float)st->pit_min;
+ }
+
+ for (i = 0; i < 2 * NB_SUBFR16k + 2; i++)
+ {
+ st->mem_pitch_gain_float[i] = 1.f;
+ }
+
+ st->old_fpitch_float = (float)st->pit_min;
+
+ st->rate_switching_init = 1;
+
+ st->reset_mem_AR = 0;
+
+ /* For phase dispersion */
+ set_zero(st->dispMem, 8);
+
+ st->voice_fac_float = -1; /* purely unvoiced */
+
+ /* TCX-LTP */
+ if (hTcxLtpDec != NULL)
+ {
+ tcxltp_dec_init(hTcxLtpDec, st->ini_frame, st->last_codec_mode, st->element_mode, st->pit_max, st->sr_core);
+ }
+
+ /* TCX */
+ if (hTcxDec != NULL)
+ {
+ st->old_fpitchFB_float = (float)hTcxDec->pit_min_TCX;
+
+ if (st->ini_frame == 0 || (st->last_codec_mode == MODE1 && st->element_mode == EVS_MONO))
+ {
+ hTcxDec->tcxltp_last_gain_unmodified_float = 0.f;
+ }
+
+ /* TCX */
+ hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri(total_brate, st->rf_flag, st->element_mode);
+
+ hTcxDec->envWeighted = 0;
+ }
+
+ if (st->hBPF != NULL)
+ {
+ st->hBPF->pst_mem_deemp_err = 0.0f;
+ }
+
+ if (st->tcxonly)
+ {
+ st->p_bpf_noise_buf_float = NULL;
+ }
+ else
+ {
+ st->p_bpf_noise_buf_float = st->bpf_noise_buf_float;
+ }
+
+ if (bwidth == SWB && (total_brate == ACELP_16k40 || total_brate == ACELP_24k40) && st->element_mode == EVS_MONO)
+ {
+ st->tec_tfa = 1;
+ }
+ else
+ {
+ st->tec_tfa = 0;
+ }
+
+ st->tec_flag = 0;
+ st->tfa_flag = 0;
+
+ /* needed in decoder to read the bitstream */
+ st->enableGplc = 0;
+
+ st->flagGuidedAcelp = 0;
+ st->tonal_mdct_plc_active = 0;
+ st->T0_4th = L_SUBFR;
+ st->guidedT0 = st->T0_4th;
+
+ if (st->hPlcInfo != NULL && total_brate >= HQ_48k && st->element_mode == EVS_MONO)
+ {
+ st->enablePlcWaveadjust = 1;
+
+ if (st->hTcxDec != NULL && (st->ini_frame == 0 || last_total_brate < HQ_48k || st->last_codec_mode == MODE1 || st->force_lpd_reset))
+ {
+ concealment_init(st->hTcxDec->L_frameTCX, st->hPlcInfo);
+ }
+ }
+ else
+ {
+ st->enablePlcWaveadjust = 0;
+ }
+
+ /* PLC: [TCX: Tonal Concealment] */
+ if (st->hTonalMDCTConc != NULL && !(st->element_mode > EVS_MONO && st->ini_frame != 0 && st->hTonalMDCTConc->nSamples == st->hTcxDec->L_frameTCX))
+ {
+ st->hTonalMDCTConc->nScaleFactors = 0;
+ st->hTonalMDCTConc->nSamples = 0;
+ st->hTonalMDCTConc->lastPcmOut_float = 0x0;
+ st->hTonalMDCTConc->lastBlockData.tonalConcealmentActive = 0;
+ st->hTonalMDCTConc->lastBlockData.nSamples = 0;
+
+ TonalMDCTConceal_Init(st->hTonalMDCTConc, st->hTcxDec->L_frameTCX, st->L_frame, FDNS_NPTS, st->hTcxCfg);
+ }
+
+ st->last_tns_active = 0;
+ st->second_last_tns_active = 0;
+ st->second_last_core = -1;
+
+ if (st->hTcxCfg != NULL &&
+ st->element_mode != EVS_MONO)
+ {
+ st->hTcxCfg->fIsTNSAllowed = getTnsAllowed(is_init ? total_brate : st->bits_frame_nominal * FRAMES_PER_SEC, st->igf, st->element_mode);
+ }
+ if (hTcxDec != NULL)
+ {
+ hTcxDec->tcxltp_second_last_pitch_float = st->old_fpitch_float;
+ hTcxDec->tcxltp_third_last_pitch_float = st->old_fpitch_float;
}
if ( ( total_brate == ACELP_9k60 || total_brate == ACELP_16k40 || total_brate == ACELP_24k40 ) && st->element_mode == EVS_MONO )
@@ -790,7 +789,7 @@ void acelp_plc_mdct_transition(
delay_comp = NS2SA( st->output_Fs, DELAY_CLDFB_NS ); /*CLDFB delay*/
mvr2r( st->hHQ_core->fer_samples + delay_comp, st->hTcxDec->syn_OverlFB_float, st->hTcxDec->L_frameTCX / 2 );
- lerp( st->hHQ_core->fer_samples + delay_comp, st->hTcxDec->syn_Overl_float, st->L_frame / 2, st->hTcxDec->L_frameTCX / 2 ); /*ACELP(bfi)->TCX(rect)*/
+ lerp_flt( st->hHQ_core->fer_samples + delay_comp, st->hTcxDec->syn_Overl_float, st->L_frame / 2, st->hTcxDec->L_frameTCX / 2 ); /*ACELP(bfi)->TCX(rect)*/
/*old_out needed for MODE1 routine and syn_Overl_TDAC for MODE2 routine*/
set_f( st->hHQ_core->old_out, 0, nz );
mvr2r( st->hHQ_core->fer_samples + delay_comp, st->hHQ_core->old_out + nz, W1 );
@@ -801,7 +800,7 @@ void acelp_plc_mdct_transition(
}
set_f( &st->hHQ_core->old_out[W1 + nz], 0, nz );
- lerp( st->hHQ_core->old_out, st->hHQ_core->old_outLB, st->L_frame, st->hTcxDec->L_frameTCX );
+ lerp_flt( st->hHQ_core->old_out, st->hHQ_core->old_outLB, st->L_frame, st->hTcxDec->L_frameTCX );
mvr2r( st->hHQ_core->old_out + nz, st->hTcxDec->syn_Overl_TDACFB_float, st->hTcxDec->L_frameTCX / 2 );
nz = NS2SA( st->sr_core, N_ZERO_MDCT_NS );
diff --git a/lib_dec/core_dec_reconf.c b/lib_dec/core_dec_reconf.c
index f05cf8e573eba5555d5f7ed42b50b5724009e6d5..f0519b6292da891572a0cf8e97644d6be841ed23 100644
--- a/lib_dec/core_dec_reconf.c
+++ b/lib_dec/core_dec_reconf.c
@@ -138,12 +138,12 @@ void reconfig_decoder_LPD(
if ( st->hTcxDec != NULL )
{
- lerp( st->hTcxDec->old_syn_Overl_float, st->hTcxDec->old_syn_Overl_float, newLen, oldLen );
- lerp( st->hTcxDec->syn_Overl_float, st->hTcxDec->syn_Overl_float, newLen, oldLen );
+ lerp_flt( st->hTcxDec->old_syn_Overl_float, st->hTcxDec->old_syn_Overl_float, newLen, oldLen );
+ lerp_flt( st->hTcxDec->syn_Overl_float, st->hTcxDec->syn_Overl_float, newLen, oldLen );
if ( st->prev_bfi && st->last_core_bfi == ACELP_CORE )
{
- lerp( st->hTcxDec->syn_Overl_TDAC_float, st->hTcxDec->syn_Overl_TDAC_float, newLen, oldLen );
+ lerp_flt( st->hTcxDec->syn_Overl_TDAC_float, st->hTcxDec->syn_Overl_TDAC_float, newLen, oldLen );
}
}
}
@@ -164,7 +164,7 @@ void reconfig_decoder_LPD(
oldLen = L_SYN_MEM_CLAS_ESTIM;
newLen = L_SYN_MEM_CLAS_ESTIM * st->L_frame / st->last_L_frame;
}
- lerp( &st->mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - oldLen], &st->mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - newLen], newLen, oldLen );
+ lerp_flt( &st->mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - oldLen], &st->mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - newLen], newLen, oldLen );
}
}
else
diff --git a/lib_dec/core_dec_switch.c b/lib_dec/core_dec_switch.c
index d093afc3dac3e7333651688e12a8dd80f25c4883..a0d36c9ae06f6985f773f9f22c4dffd433e997d8 100644
--- a/lib_dec/core_dec_switch.c
+++ b/lib_dec/core_dec_switch.c
@@ -132,7 +132,7 @@ void mode_switch_decoder_LPD(
{
st->narrowBand = 0;
}
- st->TcxBandwidth = getTcxBandwidth( bwidth );
+ st->TcxBandwidth_float = getTcxBandwidth( bwidth );
if ( st->hTcxCfg != NULL )
{
@@ -153,8 +153,8 @@ void mode_switch_decoder_LPD(
if ( hTcxDec->envWeighted && !hTcxDec->enableTcxLpc )
{
- mvr2r( st->lspold_uw, st->lsp_old, M );
- mvr2r( st->lsfold_uw, st->lsf_old, M );
+ mvr2r( st->lspold_uw_float, st->lsp_old, M );
+ mvr2r( st->lsfold_uw_float, st->lsf_old, M );
hTcxDec->envWeighted = 0;
}
diff --git a/lib_dec/core_switching_dec.c b/lib_dec/core_switching_dec.c
index a7e1f9313f07cdde5fba9cabc055e601a10392f8..965c7519902d70dad7499127a9e0805e816af7a9 100644
--- a/lib_dec/core_switching_dec.c
+++ b/lib_dec/core_switching_dec.c
@@ -76,14 +76,14 @@ ivas_error core_switching_pre_dec(
{
mvr2r( st->mem_syn2, st->mem_syn1, M );
set_f( st->agc_mem2, 0, 2 );
- st->mem_deemph = st->syn[M];
+ st->mem_deemph = st->syn_float[M];
st->bpf_off = 1;
if ( st->hBPF != NULL )
{
set_f( st->hBPF->pst_old_syn, 0, NBPSF_PIT_MAX );
st->hBPF->pst_mem_deemp_err = 0;
}
- st->psf_lp_noise = st->lp_noise;
+ st->psf_lp_noise = st->lp_noise_float;
/* reset old HB synthesis buffer */
if ( st->last_L_frame == L_FRAME )
@@ -209,7 +209,7 @@ ivas_error core_switching_pre_dec(
if ( !st->last_con_tcx && st->last_core_bfi == ACELP_CORE && st->core == HQ_CORE )
{
- lerp( st->hTcxDec->syn_Overl_float, st->hHQ_core->fer_samples + delay_comp, output_frame / 2, st->last_L_frame / 2 );
+ lerp_flt( st->hTcxDec->syn_Overl_float, st->hHQ_core->fer_samples + delay_comp, output_frame / 2, st->last_L_frame / 2 );
/*Set to zero the remaining part*/
set_f( st->hHQ_core->fer_samples + delay_comp + output_frame / 2, 0, ( output_frame / 2 ) - delay_comp );
}
@@ -236,7 +236,7 @@ ivas_error core_switching_pre_dec(
oldLenClasBuff = L_SYN_MEM_CLAS_ESTIM;
newLenClasBuff = L_SYN_MEM_CLAS_ESTIM * st->L_frame / st->last_L_frame;
}
- lerp( &st->mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - oldLenClasBuff], &st->mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - newLenClasBuff], newLenClasBuff, oldLenClasBuff );
+ lerp_flt( &st->mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - oldLenClasBuff], &st->mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - newLenClasBuff], newLenClasBuff, oldLenClasBuff );
}
}
else
@@ -340,7 +340,7 @@ ivas_error core_switching_pre_dec(
else if ( st->L_frame < L_FRAME16k )
{
/* resample from 16kHz to 12.8kHZ */
- synth_mem_updt2( st->L_frame, L_FRAME16k, st->old_exc, st->mem_syn_r, st->mem_syn2, NULL, DEC );
+ synth_mem_updt2_flt( st->L_frame, L_FRAME16k, st->old_exc, st->mem_syn_r_float, st->mem_syn2, NULL, DEC );
}
if ( st->hBWE_TD != NULL )
@@ -511,14 +511,14 @@ ivas_error core_switching_pre_dec(
{
if ( st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD )
{
- lerp( st->hFdCngDec->hFdCngCom->olapBufferAna + st->last_L_frame, st->hFdCngDec->hFdCngCom->olapBufferAna + st->L_frame, st->L_frame, st->last_L_frame );
+ lerp_flt( st->hFdCngDec->hFdCngCom->olapBufferAna + st->last_L_frame, st->hFdCngDec->hFdCngCom->olapBufferAna + st->L_frame, st->L_frame, st->last_L_frame );
}
- lerp( st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->L_frame * 2, st->last_L_frame * 2 );
+ lerp_flt( st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->L_frame * 2, st->last_L_frame * 2 );
if ( st->total_brate <= SID_2k40 && st->last_total_brate <= SID_2k40 )
{
- lerp( st->hFdCngDec->hFdCngCom->olapBufferSynth, st->hFdCngDec->hFdCngCom->olapBufferSynth, st->L_frame * 2, st->last_L_frame * 2 );
+ lerp_flt( st->hFdCngDec->hFdCngCom->olapBufferSynth, st->hFdCngDec->hFdCngCom->olapBufferSynth, st->L_frame * 2, st->last_L_frame * 2 );
if ( st->L_frame == L_FRAME )
{
@@ -1213,9 +1213,9 @@ static void core_switch_lb_upsamp(
cldfbAnalysis( output, realBuffer, imagBuffer, CLDFB_OVRLP_MIN_SLOTS * st->cldfbAna->no_channels, st->cldfbAna );
/* analysis and add the BPF error signal */
- if ( st->p_bpf_noise_buf )
+ if ( st->p_bpf_noise_buf_float)
{
- addBassPostFilter( st->p_bpf_noise_buf, st->bpf_off ? 0 : CLDFB_OVRLP_MIN_SLOTS * st->cldfbBPF->no_channels, realBuffer, imagBuffer, st->cldfbBPF );
+ addBassPostFilter( st->p_bpf_noise_buf_float, st->bpf_off ? 0 : CLDFB_OVRLP_MIN_SLOTS * st->cldfbBPF->no_channels, realBuffer, imagBuffer, st->cldfbBPF );
}
/* set output mask for upsampling */
diff --git a/lib_dec/dec_LPD.c b/lib_dec/dec_LPD.c
index 558a0f1c2fe4fbf529770e116701a41baea7af0f..8c984392606e05e88fcbd27c389640d540fedd0e 100644
--- a/lib_dec/dec_LPD.c
+++ b/lib_dec/dec_LPD.c
@@ -208,8 +208,8 @@ void decoder_LPD(
{
if ( hTcxDec->envWeighted )
{
- mvr2r( st->lspold_uw, st->lsp_old, M );
- mvr2r( st->lsfold_uw, st->lsf_old, M );
+ mvr2r( st->lspold_uw_float, st->lsp_old, M );
+ mvr2r( st->lsfold_uw_float, st->lsf_old, M );
hTcxDec->envWeighted = 0;
}
@@ -278,14 +278,14 @@ void decoder_LPD(
mvr2r( &lsf[M], st->mem_AR, M );
hTcxDec->envWeighted = 1;
- E_LPC_lsp_unweight_float( &lsp[M], lspnew_uw, lsfnew_uw, 1.0f / st->gamma );
+ E_LPC_lsp_unweight_float( &lsp[M], lspnew_uw, lsfnew_uw, 1.0f / st->gamma_float);
}
else
{
if ( hTcxDec->envWeighted )
{
- mvr2r( st->lspold_uw, st->lsp_old, M );
- mvr2r( st->lsfold_uw, st->lsf_old, M );
+ mvr2r( st->lspold_uw_float, st->lsp_old, M );
+ mvr2r( st->lsfold_uw_float, st->lsf_old, M );
hTcxDec->envWeighted = 0;
}
@@ -342,26 +342,26 @@ void decoder_LPD(
if ( st->nbLostCmpt == 1 )
{
- mvr2r( st->lsf_old, st->old_lsf_q_cng, M );
- mvr2r( st->lsp_old, st->old_lsp_q_cng, M );
+ mvr2r( st->lsf_old, st->old_lsf_q_cng_float, M );
+ mvr2r( st->lsp_old, st->old_lsp_q_cng_float, M );
}
lsfBase = PlcGetlsfBase( st->lpcQuantization, st->narrowBand, st->sr_core );
- dlpc_bfi( st->L_frame, lsfnew_uw, st->lsfold_uw, st->last_good, st->nbLostCmpt, st->mem_MA, st->mem_AR, &( st->stab_fac ), st->lsf_adaptive_mean, st->numlpc, st->lsf_cng, st->plcBackgroundNoiseUpdated, st->lsf_q_cng, st->old_lsf_q_cng, lsfBase );
+ dlpc_bfi( st->L_frame, lsfnew_uw, st->lsfold_uw_float, st->last_good, st->nbLostCmpt, st->mem_MA, st->mem_AR, &( st->stab_fac ), st->lsf_adaptive_mean, st->numlpc, st->lsf_cng_float, st->plcBackgroundNoiseUpdated, st->lsf_q_cng_float, st->old_lsf_q_cng_float, lsfBase );
hTcxDec->envWeighted = 0;
- mvr2r( st->lspold_uw, lsp, M );
- mvr2r( st->lsfold_uw, lsf, M );
+ mvr2r( st->lspold_uw_float, lsp, M );
+ mvr2r( st->lsfold_uw_float, lsf, M );
for ( k = 0; k < st->numlpc; k++ )
{
mvr2r( &lsfnew_uw[k * M], &lsf[( k + 1 ) * M], M );
lsf2lsp( &lsf[( k + 1 ) * M], &lsp[( k + 1 ) * M], M, st->sr_core );
- lsf2lsp( st->lsf_q_cng, st->lsp_q_cng, M, st->sr_core );
+ lsf2lsp( st->lsf_q_cng_float, st->lsp_q_cng_float, M, st->sr_core );
mvr2r( &lsp[( k + 1 ) * M], &lspnew_uw[k * M], M );
}
@@ -467,7 +467,7 @@ void decoder_LPD(
else
{
int_lsp( L_frame, &lsp[0], &lsp[M], Aq, M, interpol_frac_12k8, 0 );
- int_lsp( L_frame, st->old_lsp_q_cng, st->lsp_q_cng, st->Aq_cng, M, interpol_frac_12k8, 0 );
+ int_lsp( L_frame, st->old_lsp_q_cng_float, st->lsp_q_cng_float, st->Aq_cng_float, M, interpol_frac_12k8, 0 );
}
}
}
@@ -476,9 +476,9 @@ void decoder_LPD(
{
/* PLC: [TCX: TD PLC] */
con_tcx( st, &synthFB[0], -1.f, NULL, 0, NULL );
- lerp( synthFB, synth, st->L_frame, st->hTcxDec->L_frameTCX );
+ lerp_flt( synthFB, synth, st->L_frame, st->hTcxDec->L_frameTCX );
st->con_tcx = 1;
- set_f( &st->mem_pitch_gain[2], st->lp_gainp, st->nb_subfr );
+ set_f( &st->mem_pitch_gain_float[2], st->lp_gainp, st->nb_subfr );
}
else
{
@@ -500,8 +500,8 @@ void decoder_LPD(
/* PLC: [ACELP: general]
* PLC: Use the ACELP like concealment */
con_acelp( Aq, st->core_ext_mode, &synth[0], pitch, pit_gain, st->stab_fac, st, pitch_buf, voice_factors, ptr_bwe_exc );
- mvr2r( &st->mem_pitch_gain[2], &st->mem_pitch_gain[st->nb_subfr + 2], st->nb_subfr );
- set_zero( &st->mem_pitch_gain[2], st->nb_subfr );
+ mvr2r( &st->mem_pitch_gain_float[2], &st->mem_pitch_gain_float[st->nb_subfr + 2], st->nb_subfr );
+ set_zero( &st->mem_pitch_gain_float[2], st->nb_subfr );
}
else
{
@@ -514,8 +514,8 @@ void decoder_LPD(
for ( i = 0; i < st->nb_subfr; i++ )
{
- st->mem_pitch_gain[2 + ( 2 * st->nb_subfr - 1 ) - i] = st->mem_pitch_gain[2 + ( st->nb_subfr - 1 ) - i];
- st->mem_pitch_gain[2 + ( st->nb_subfr - 1 ) - i] = pit_gain[i];
+ st->mem_pitch_gain_float[2 + ( 2 * st->nb_subfr - 1 ) - i] = st->mem_pitch_gain_float[2 + ( st->nb_subfr - 1 ) - i];
+ st->mem_pitch_gain_float[2 + ( st->nb_subfr - 1 ) - i] = pit_gain[i];
}
}
}
@@ -523,7 +523,7 @@ void decoder_LPD(
/* LPC for ACELP/BWE */
if ( st->narrowBand || st->sr_core == INT_FS_12k8 || st->sr_core == INT_FS_16k )
{
- mvr2r( Aq, st->mem_Aq, nb_subfr * ( M + 1 ) );
+ mvr2r( Aq, st->mem_Aq_float, nb_subfr * ( M + 1 ) );
}
/* PLC: [TCX: Tonal Concealment] */
@@ -629,7 +629,7 @@ void decoder_LPD(
if ( ( bfi || st->prev_bfi ) && st->hPlcInfo->Pitch && st->hPlcInfo->concealment_method == TCX_NONTONAL )
{
- lerp( synthFB, synth, L_frame, L_frameTCX );
+ lerp_flt( synthFB, synth, L_frame, L_frameTCX );
if ( !bfi && st->prev_bfi )
{
@@ -650,8 +650,8 @@ void decoder_LPD(
/* LPC Interpolation for BWE/post-processing */
if ( st->narrowBand || st->sr_core == INT_FS_12k8 || st->sr_core == INT_FS_16k )
{
- int_lsp( L_frame, st->lspold_uw, lspnew_uw, Aq, M, interpol_frac_12k8, 0 );
- mvr2r( Aq, st->mem_Aq, nb_subfr * ( M + 1 ) );
+ int_lsp( L_frame, st->lspold_uw_float, lspnew_uw, Aq, M, interpol_frac_12k8, 0 );
+ mvr2r( Aq, st->mem_Aq_float, nb_subfr * ( M + 1 ) );
}
}
}
@@ -667,9 +667,9 @@ void decoder_LPD(
float pitch_C[4];
/* note: the classifier needs the pitch only for tcx_only == 0, i.e. not for TCX10 */
- pitch_C[0] = pitch_C[1] = pitch_C[2] = pitch_C[3] = (float) floor( st->old_fpitch + 0.5f );
+ pitch_C[0] = pitch_C[1] = pitch_C[2] = pitch_C[3] = (float) floor( st->old_fpitch_float + 0.5f );
- FEC_clas_estim( synth, pitch_C, st->L_frame, st->tcxonly ? GENERIC : st->core_ext_mode, st->codec_mode, st->mem_syn_clas_estim, &st->clas_dec, &st->lp_ener_bfi, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, hTcxLtpDec->tcxltp ? hTcxDec->tcxltp_last_gain_unmodified_float : -1.0f, st->narrowBand, CLASSIFIER_TCX, bfi, st->preemph_fac, st->tcxonly, st->last_core_brate, -1 );
+ FEC_clas_estim( synth, pitch_C, st->L_frame, st->tcxonly ? GENERIC : st->core_ext_mode, st->codec_mode, st->mem_syn_clas_estim, &st->clas_dec, &st->lp_ener_bfi, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, hTcxLtpDec->tcxltp ? hTcxDec->tcxltp_last_gain_unmodified_float : -1.0f, st->narrowBand, CLASSIFIER_TCX, bfi, st->preemph_fac_float, st->tcxonly, st->last_core_brate, -1 );
}
}
@@ -686,7 +686,7 @@ void decoder_LPD(
}
else
{
- fer_energy( L_frame, st->clas_dec, synth, st->old_fpitch, &st->enr_old, L_frame );
+ fer_energy( L_frame, st->clas_dec, synth, st->old_fpitch_float, &st->enr_old, L_frame );
}
}
@@ -703,7 +703,7 @@ void decoder_LPD(
}
/* use latest LPC set */
- st->old_enr_LP = enr_1_Az( Aq + offset, L_SUBFR );
+ st->old_enr_LP_float = enr_1_Az( Aq + offset, L_SUBFR );
}
@@ -713,21 +713,21 @@ void decoder_LPD(
mvr2r( synth_bufFB + L_frameTCX, st->hTcxDec->old_synthFB, st->hTcxDec->old_synth_lenFB );
mvr2r( st->hHQ_core->old_out + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB + st->hTcxDec->old_synth_lenFB, NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) );
- mvr2r( &lspnew_uw[( st->numlpc - 1 ) * M], st->lspold_uw, M );
- mvr2r( &lsfnew_uw[( st->numlpc - 1 ) * M], st->lsfold_uw, M );
+ mvr2r( &lspnew_uw[( st->numlpc - 1 ) * M], st->lspold_uw_float, M );
+ mvr2r( &lsfnew_uw[( st->numlpc - 1 ) * M], st->lsfold_uw_float, M );
if ( bfi == 1 )
{
- mvr2r( st->lspold_uw, st->lsp_old, M ); /* for recovery */
- mvr2r( st->lsfold_uw, st->lsf_old, M ); /* for recovery */
+ mvr2r( st->lspold_uw_float, st->lsp_old, M ); /* for recovery */
+ mvr2r( st->lsfold_uw_float, st->lsf_old, M ); /* for recovery */
}
else
{
mvr2r( &lsp[st->numlpc * M], st->lsp_old, M );
mvr2r( &lsf[st->numlpc * M], st->lsf_old, M );
}
- mvr2r( st->lsp_q_cng, st->old_lsp_q_cng, M );
- mvr2r( st->lsf_q_cng, st->old_lsf_q_cng, M );
+ mvr2r( st->lsp_q_cng_float, st->old_lsp_q_cng_float, M );
+ mvr2r( st->lsf_q_cng_float, st->old_lsf_q_cng_float, M );
/* Update MODE1 CNG parameters */
if ( !st->tcxonly && st->hTdCngDec != NULL )
@@ -739,9 +739,9 @@ void decoder_LPD(
assert( st->L_frame == L_FRAME );
mvr2r( synth + L_FRAME - L_LP, buf, L_LP );
tmp = synth[L_FRAME - L_LP - 1];
- preemph( buf, st->preemph_fac, L_LP, &tmp );
+ preemph( buf, st->preemph_fac_float, L_LP, &tmp );
autocorr( buf, r, M, L_LP, LP_assym_window, 0, 0, 0 );
- lag_wind( r, M, INT_FS_12k8, LAGW_WEAK );
+ lag_wind_flt( r, M, INT_FS_12k8, LAGW_WEAK );
lev_dur( A, r, M, NULL );
a2lsp_stab( A, lsptmp, &lspnew_uw[0] );
residu( A, M, buf + L_LP - L_FRAME, res, L_FRAME );
diff --git a/lib_dec/dec_ace.c b/lib_dec/dec_ace.c
index 527baafd8ec155be007b3429ee6885e5e343d057..2ff764e1117b815f01e19ccf65c67eb1bde4ccf0 100644
--- a/lib_dec/dec_ace.c
+++ b/lib_dec/dec_ace.c
@@ -149,17 +149,17 @@ void decoder_acelp(
/* Update of synthesis filter memories in case of 12k8 core */
if ( st->prev_bfi && st->last_con_tcx && st->L_frame < L_FRAME16k )
{
- synth_mem_updt2( st->L_frame, L_FRAME16k, st->old_exc, st->mem_syn_r, st->mem_syn2, NULL, DEC );
+ synth_mem_updt2_flt( st->L_frame, L_FRAME16k, st->old_exc, st->mem_syn_r_float, st->mem_syn2, NULL, DEC );
}
- if ( st->last_con_tcx && st->old_enr_LP )
+ if ( st->last_con_tcx && st->old_enr_LP_float )
{
float enr_LP, ratio_float;
/* rescale excitation buffer if LPC energies differs too much */
enr_LP = enr_1_Az( A, L_SUBFR );
- ratio_float = st->old_enr_LP / enr_LP;
+ ratio_float = st->old_enr_LP_float / enr_LP;
if ( ratio_float < 0.8 )
{
v_multc( st->old_exc, ratio_float, st->old_exc, L_EXC_MEM_DEC );
@@ -304,7 +304,7 @@ void decoder_acelp(
if ( st->igf )
{
- tbe_celp_exc( st->element_mode, st->idchan, bwe_exc, L_frame, L_SUBFR, i_subfr, T0, T0_frac, &error, 0 );
+ tbe_celp_exc_flt( st->element_mode, st->idchan, bwe_exc, L_frame, L_SUBFR, i_subfr, T0, T0_frac, &error, 0 );
}
pitch_buffer[i_subfr / L_SUBFR] = (float) T0 + (float) T0_frac / (float) T0_res;
@@ -350,17 +350,17 @@ void decoder_acelp(
if ( st->acelp_cfg.gains_mode[i_subfr / L_SUBFR] != 0 )
{
- decode_acelp_gains( code, acelp_cfg.gains_mode[i_subfr / L_SUBFR], Es_pred, &gain_pit, &gain_code, &prm, &( st->past_gpit ), &( st->past_gcode ), &gain_inov, L_SUBFR, code2, &gain_code2 );
+ decode_acelp_gains( code, acelp_cfg.gains_mode[i_subfr / L_SUBFR], Es_pred, &gain_pit, &gain_code, &prm, &( st->past_gpit_float), &( st->past_gcode_float), &gain_inov, L_SUBFR, code2, &gain_code2 );
}
if ( st->use_partial_copy && st->rf_frame_type == RF_ALLPRED )
{
- st->past_gcode = 0.0f;
+ st->past_gcode_float = 0.0f;
}
if ( st->use_partial_copy && st->rf_frame_type == RF_NOPRED )
{
- st->past_gpit = 0.004089f;
+ st->past_gpit_float = 0.004089f;
}
/*----------------------------------------------------------*
@@ -368,7 +368,7 @@ void decoder_acelp(
* - tilt of code: 0.0 (unvoiced) to 0.5 (voiced) *
*----------------------------------------------------------*/
- st->tilt_code = est_tilt( exc + i_subfr, gain_pit, code, gain_code, &( st->voice_fac ), L_SUBFR, acelp_cfg.voice_tilt );
+ st->tilt_code = est_tilt( exc + i_subfr, gain_pit, code, gain_code, &( st->voice_fac_float), L_SUBFR, acelp_cfg.voice_tilt );
pgainT[i_subfr / L_SUBFR] = gain_pit;
@@ -410,14 +410,14 @@ void decoder_acelp(
if ( st->igf != 0 )
{
- prep_tbe_exc( L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, st->voice_fac, &voice_factors[i_subfr / L_SUBFR], bwe_exc, gain_preQ, code_preQ, T0, st->coder_type, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, 0 );
+ prep_tbe_exc( L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, st->voice_fac_float, &voice_factors[i_subfr / L_SUBFR], bwe_exc, gain_preQ, code_preQ, T0, st->coder_type, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, 0 );
}
/*---------------------------------------------------------*
* Enhance the excitation *
*---------------------------------------------------------*/
- enhancer( MODE2, -1, acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 0, st->coder_type, L_frame, st->voice_fac, stab_fac, st->past_gcode, gain_inov, &( st->gc_threshold ), code, &exc2[i_subfr], gain_pit, st->dispMem );
+ enhancer( MODE2, -1, acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 0, st->coder_type, L_frame, st->voice_fac_float, stab_fac, st->past_gcode_float, gain_inov, &( st->gc_threshold ), code, &exc2[i_subfr], gain_pit, st->dispMem );
} /* !RF_NELP frame partial copy */
@@ -431,8 +431,8 @@ void decoder_acelp(
* update lp_filtered gains for the case of frame erasure
*-----------------------------------------------------------------*/
- st->lp_gainp += weights[i_subfr / L_SUBFR] * st->past_gpit;
- st->lp_gainc += weights[i_subfr / L_SUBFR] * st->past_gcode;
+ st->lp_gainp += weights[i_subfr / L_SUBFR] * st->past_gpit_float;
+ st->lp_gainc += weights[i_subfr / L_SUBFR] * st->past_gcode_float;
/*----------------------------------------------------------*
* - update pitch lag for guided ACELP *
@@ -460,9 +460,9 @@ void decoder_acelp(
{
exc[i] = 0.0f;
}
- int_lsp( L_frame, st->old_lsp_q_cng, st->lsp_q_cng, st->Aq_cng, M, interpol_frac_12k8, 0 );
+ int_lsp( L_frame, st->old_lsp_q_cng_float, st->lsp_q_cng_float, st->Aq_cng_float, M, interpol_frac_12k8, 0 );
- p_A = st->Aq_cng;
+ p_A = st->Aq_cng_float;
if ( st->last_good < UNVOICED_TRANSITION )
{
mvr2r( st->mem_syn2, mem_syn, M );
@@ -485,9 +485,9 @@ void decoder_acelp(
set_zero( mem, M );
h1[0] = 1.0f;
syn_filt( pA, M, h1, h1, L_SUBFR, mem, 0 ); /* impulse response of LPC */
- deemph( h1, st->preemph_fac, L_SUBFR, &tmp ); /* impulse response of deemph */
+ deemph( h1, st->preemph_fac_float, L_SUBFR, &tmp ); /* impulse response of deemph */
/* impulse response level = gain introduced by synthesis+deemphasis */
- st->last_gain_syn_deemph = (float) sqrt( dotp( h1, h1, L_SUBFR ) );
+ st->last_gain_syn_deemph_float = (float) sqrt( dotp( h1, h1, L_SUBFR ) );
/*-----------------------------------------------------------*
* PLC: [ACELP: Fade-out]
@@ -495,22 +495,22 @@ void decoder_acelp(
*-----------------------------------------------------------*/
/* Do the classification */
- FEC_clas_estim( syn, pitch_buf, st->L_frame, st->core_ext_mode, st->codec_mode, st->mem_syn_clas_estim, &st->clas_dec, &st->lp_ener_bfi, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1.0f, st->narrowBand, CLASSIFIER_ACELP, 0, st->preemph_fac, st->tcxonly, st->last_core_brate, -1 );
+ FEC_clas_estim( syn, pitch_buf, st->L_frame, st->core_ext_mode, st->codec_mode, st->mem_syn_clas_estim, &st->clas_dec, &st->lp_ener_bfi, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1.0f, st->narrowBand, CLASSIFIER_ACELP, 0, st->preemph_fac_float, st->tcxonly, st->last_core_brate, -1 );
/* Update Pitch Lag memory */
mvr2r( &st->old_pitch_buf[L_frame / L_SUBFR], st->old_pitch_buf, L_frame / L_SUBFR );
mvr2r( pitch_buf, &st->old_pitch_buf[L_frame / L_SUBFR], L_frame / L_SUBFR );
- FEC_scale_syn( st->L_frame, st->clas_dec, st->last_good, syn, pitch_buf, st->enr_old, 0, st->coder_type, LSF_Q_prediction, &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, exc, exc2, A, &st->old_enr_LP, mem_back, mem_syn, st->last_con_tcx && ( st->L_frameTCX_past != st->L_frame ) && ( st->last_core != ACELP_CORE ), ( st->clas_dec == ONSET || ( st->last_good >= VOICED_TRANSITION && st->last_good < INACTIVE_CLAS ) ) );
+ FEC_scale_syn( st->L_frame, st->clas_dec, st->last_good, syn, pitch_buf, st->enr_old, 0, 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, A, &st->old_enr_LP_float, mem_back, mem_syn, st->last_con_tcx && ( st->L_frameTCX_past != st->L_frame ) && ( st->last_core != ACELP_CORE ), ( st->clas_dec == ONSET || ( st->last_good >= VOICED_TRANSITION && st->last_good < INACTIVE_CLAS ) ) );
/* update ACELP synthesis memory */
mvr2r( mem_syn, st->mem_syn2, M );
- mvr2r( syn + L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM );
+ mvr2r( syn + L_frame - L_SYN_MEM, st->mem_syn_r_float, L_SYN_MEM );
- tmp = st->syn[M];
- deemph( syn, st->preemph_fac, L_frame, &tmp );
+ tmp = st->syn_float[M];
+ deemph( syn, st->preemph_fac_float, L_frame, &tmp );
mvr2r( syn + L_frame - ( L_frame / 2 ), st->hTcxDec->old_syn_Overl_float, L_frame / 2 );
- mvr2r( syn + L_frame - M - 1, st->syn, M + 1 );
+ mvr2r( syn + L_frame - M - 1, st->syn_float, M + 1 );
mvr2r( syn, synth, L_frame );
if ( st->hBWE_TD != NULL )
@@ -535,8 +535,8 @@ void decoder_acelp(
st->old_Es_pred = Es_pred;
hTcxDec->tcxltp_third_last_pitch_float = hTcxDec->tcxltp_second_last_pitch_float;
- hTcxDec->tcxltp_second_last_pitch_float = st->old_fpitch;
- st->old_fpitch = pitch_buf[( L_frame / L_SUBFR ) - 1];
+ hTcxDec->tcxltp_second_last_pitch_float = st->old_fpitch_float;
+ st->old_fpitch_float = pitch_buf[( L_frame / L_SUBFR ) - 1];
return;
}
diff --git a/lib_dec/dec_acelp_tcx_main.c b/lib_dec/dec_acelp_tcx_main.c
index 98e641563d5a0d69af1cd7ebd757edf006433244..94febad5e786f360bec721cbc8136bf7719dbc65 100644
--- a/lib_dec/dec_acelp_tcx_main.c
+++ b/lib_dec/dec_acelp_tcx_main.c
@@ -220,11 +220,11 @@ static void decode_frame_type(
configureFdCngDec( st->hFdCngDec, st->bwidth, st->rf_flag == 1 && st->total_brate == ACELP_13k20 ? ACELP_9k60 : st->total_brate, st->L_frame, st->last_L_frame, st->element_mode );
if ( st->last_L_frame != st->L_frame && st->L_frame <= L_FRAME16k && st->last_L_frame <= L_FRAME16k )
{
- lerp( st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->L_frame * 2, st->last_L_frame * 2 );
+ lerp_flt( st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->L_frame * 2, st->last_L_frame * 2 );
if ( st->m_frame_type == SID_FRAME && st->hFdCngDec->hFdCngCom->frame_type_previous != ACTIVE_FRAME )
{
- lerp( st->hFdCngDec->hFdCngCom->olapBufferSynth, st->hFdCngDec->hFdCngCom->olapBufferSynth, st->L_frame * 2, st->last_L_frame * 2 );
- lerp( hStereoCng->olapBufferSynth22, hStereoCng->olapBufferSynth22, st->L_frame * 2, st->last_L_frame * 2 );
+ lerp_flt( st->hFdCngDec->hFdCngCom->olapBufferSynth, st->hFdCngDec->hFdCngCom->olapBufferSynth, st->L_frame * 2, st->last_L_frame * 2 );
+ lerp_flt( hStereoCng->olapBufferSynth22, hStereoCng->olapBufferSynth22, st->L_frame * 2, st->last_L_frame * 2 );
if ( st->L_frame == L_FRAME )
{
@@ -251,11 +251,11 @@ static void decode_frame_type(
if ( st->tcxonly )
{
- st->p_bpf_noise_buf = NULL;
+ st->p_bpf_noise_buf_float = NULL;
}
else
{
- st->p_bpf_noise_buf = st->bpf_noise_buf;
+ st->p_bpf_noise_buf_float = st->bpf_noise_buf_float;
}
}
}
@@ -350,7 +350,7 @@ void dec_acelp_tcx_frame(
else
{
st->core_brate = st->total_brate;
- bpf_noise_buf = st->p_bpf_noise_buf;
+ bpf_noise_buf = st->p_bpf_noise_buf_float;
}
}
diff --git a/lib_dec/dec_gen_voic.c b/lib_dec/dec_gen_voic.c
index 9f9e7cec8d5bf72c1e085028ac95dec355a01ab0..0e8285c82e4b95f2901186b211d2e5df799223ef 100644
--- a/lib_dec/dec_gen_voic.c
+++ b/lib_dec/dec_gen_voic.c
@@ -123,7 +123,7 @@ ivas_error decod_gen_voic(
pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac, L_SUBFR + 1, inter4_2, L_INTERPOL2, PIT_UP_SAMP );
- tbe_celp_exc( st->element_mode, st->idchan, bwe_exc, L_frame, L_SUBFR, i_subfr, T0, T0_frac, &error_flag, st->tdm_LRTD_flag );
+ tbe_celp_exc_flt( st->element_mode, st->idchan, bwe_exc, L_frame, L_SUBFR, i_subfr, T0, T0_frac, &error_flag, st->tdm_LRTD_flag );
/*--------------------------------------------------------------*
* LP filtering of the adaptive excitation
diff --git a/lib_dec/dec_prm.c b/lib_dec/dec_prm.c
index db690f6a97409cf8d9cf5bebb5e150fac8ba4470..508db037581f346c72eb970d52639616b6f8114f 100644
--- a/lib_dec/dec_prm.c
+++ b/lib_dec/dec_prm.c
@@ -551,7 +551,7 @@ void getTCXparam(
{
if ( core == TCX_20_CORE )
{
- hm_size = (int16_t) ( 2.0f * st->TcxBandwidth * (float) lg );
+ hm_size = (int16_t) ( 2.0f * st->TcxBandwidth_float * (float) lg );
if ( hTcxDec->tcx_lpc_shaped_ari && st->last_core_from_bs != ACELP_CORE )
{
@@ -562,7 +562,7 @@ void getTCXparam(
}
else
{
- hm_size = (int16_t) ( 2.0f * st->TcxBandwidth * (float) lgFB );
+ hm_size = (int16_t) ( 2.0f * st->TcxBandwidth_float * (float) lgFB );
nbits_tcx = ( ( st->bits_frame_core - bits_common - nbits_igf + 1 - k ) >> 1 ) - ( ( st0->next_bit_pos - start_bit_pos ) - nbits_tcx );
}
diff --git a/lib_dec/dec_tcx.c b/lib_dec/dec_tcx.c
index b4ee39eeea761759cc843c68ee752658cbef97ab..6715f5ece7041b36adfd928ec7e4b54539642735 100644
--- a/lib_dec/dec_tcx.c
+++ b/lib_dec/dec_tcx.c
@@ -200,7 +200,7 @@ void decoder_tcx_post(
}
else
{
- gainCNG = st->cngTDLevel / ( level_syn + 0.01f );
+ gainCNG = st->cngTDLevel_float / ( level_syn + 0.01f );
}
if ( st->nbLostCmpt == 1 )
{
@@ -230,7 +230,7 @@ void decoder_tcx_post(
{
if ( ( !st->enablePlcWaveadjust || st->hPlcInfo->concealment_method == TCX_TONAL ) && !st->use_partial_copy )
{
- st->hPlcInfo->recovery_gain_float = conceal_eof_gainFB * st->last_concealed_gain_syn_deemph;
+ st->hPlcInfo->recovery_gain_float = conceal_eof_gainFB * st->last_concealed_gain_syn_deemph_float;
}
else
{
@@ -253,17 +253,17 @@ void decoder_tcx_post(
st->old_pitch_buf[0] = st->old_pitch_buf[st->nb_subfr];
st->old_pitch_buf[1] = st->old_pitch_buf[st->nb_subfr + 1];
mvr2r( &st->old_pitch_buf[st->nb_subfr + 2], &st->old_pitch_buf[2], st->nb_subfr );
- set_f( &st->old_pitch_buf[st->nb_subfr + 2], st->old_fpitch, st->nb_subfr );
- st->bfi_pitch = st->old_fpitch;
+ set_f( &st->old_pitch_buf[st->nb_subfr + 2], st->old_fpitch_float, st->nb_subfr );
+ st->bfi_pitch = st->old_fpitch_float;
st->bfi_pitch_frame = st->L_frame;
- st->mem_pitch_gain[2 * st->nb_subfr + 1] = st->mem_pitch_gain[st->nb_subfr + 1];
- st->mem_pitch_gain[2 * st->nb_subfr] = st->mem_pitch_gain[st->nb_subfr];
+ st->mem_pitch_gain_float[2 * st->nb_subfr + 1] = st->mem_pitch_gain_float[st->nb_subfr + 1];
+ st->mem_pitch_gain_float[2 * st->nb_subfr] = st->mem_pitch_gain_float[st->nb_subfr];
for ( i = 0; i < st->nb_subfr; i++ )
{
- st->mem_pitch_gain[2 * st->nb_subfr - 1 - i] = st->mem_pitch_gain[st->nb_subfr - 1 - i];
- st->mem_pitch_gain[st->nb_subfr - 1 - i] = hTcxDec->tcxltp_last_gain_unmodified_float;
+ st->mem_pitch_gain_float[2 * st->nb_subfr - 1 - i] = st->mem_pitch_gain_float[st->nb_subfr - 1 - i];
+ st->mem_pitch_gain_float[st->nb_subfr - 1 - i] = hTcxDec->tcxltp_last_gain_unmodified_float;
}
return;
@@ -317,7 +317,7 @@ void IMDCT(
if ( st->element_mode != EVS_MONO && frame_cnt == 0 && !bfi && st->prev_bfi && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) && !hTcxCfg->last_aldo )
{
- v_multc( old_syn_overl, hTcxDec->conceal_eof_gain_float * st->last_concealed_gain_syn_deemph, old_syn_overl, overlap );
+ v_multc( old_syn_overl, hTcxDec->conceal_eof_gain_float * st->last_concealed_gain_syn_deemph_float, old_syn_overl, overlap );
}
if ( ( L_frameTCX == hTcxDec->L_frameTCX >> 1 ) && st->tcxonly )
@@ -533,7 +533,7 @@ void IMDCT(
/* get LPC from that signal part to use for acelp zir smoothing */
ham_cos_window( &window_buf[0], analysis_len / 2, analysis_len / 2 );
autocorr( &buf[0], &r[0], M, analysis_len, &window_buf[0], 0, 0, 0 );
- lag_wind( r, M, L_frame_glob * FRAMES_PER_SEC, LAGW_STRONG );
+ lag_wind_flt( r, M, L_frame_glob * FRAMES_PER_SEC, LAGW_STRONG );
lev_dur( &st->old_Aq_12_8[0], &r[0], M, NULL );
}
@@ -721,7 +721,7 @@ void decoder_tcx_invQ(
*-----------------------------------------------------------------*/
/* Init lengths */
- gamma1 = st->gamma;
+ gamma1 = st->gamma_float;
if ( hTcxDec->enableTcxLpc )
{
@@ -917,7 +917,7 @@ void decoder_tcx_invQ(
{
if ( hTcxDec->envWeighted )
{
- gamma = st->gamma;
+ gamma = st->gamma_float;
}
else
{
@@ -929,7 +929,7 @@ void decoder_tcx_invQ(
if ( hTcxDec->enableTcxLpc )
{
- gamma = hTcxDec->cummulative_damping_tcx_float * ( st->gamma - 1 ) + 1;
+ gamma = hTcxDec->cummulative_damping_tcx_float * ( st->gamma_float - 1 ) + 1;
}
else
{
@@ -950,7 +950,7 @@ void decoder_tcx_invQ(
set_zero( mem, M );
h1[0] = 1.0f;
syn_filt( Ap, M, h1, h1, L_SUBFR, mem, 0 ); /* impulse response of LPC */
- deemph( h1, st->preemph_fac, L_SUBFR, &tmp2 ); /* impulse response of deemph */
+ deemph( h1, st->preemph_fac_float, L_SUBFR, &tmp2 ); /* impulse response of deemph */
}
/* impulse response level = gain introduced by synthesis+deemphasis */
@@ -958,11 +958,11 @@ void decoder_tcx_invQ(
{
if ( st->element_mode == IVAS_CPE_MDCT )
{
- st->last_gain_syn_deemph = 0.0;
+ st->last_gain_syn_deemph_float = 0.0;
}
else
{
- st->last_gain_syn_deemph = (float) sqrt( dotp( h1, h1, L_SUBFR ) );
+ st->last_gain_syn_deemph_float = (float) sqrt( dotp( h1, h1, L_SUBFR ) );
}
/*for avoiding compiler warnings*/
@@ -977,7 +977,7 @@ void decoder_tcx_invQ(
}
else
{
- gainCompensate = st->last_gain_syn_deemph / (float) sqrt( dotp( h1, h1, L_SUBFR ) );
+ gainCompensate = st->last_gain_syn_deemph_float / (float) sqrt( dotp( h1, h1, L_SUBFR ) );
}
if ( st->nbLostCmpt == 1 )
@@ -987,10 +987,10 @@ void decoder_tcx_invQ(
}
else
{
- hTcxDec->stepCompensate_float = ( st->last_concealed_gain_syn_deemph - gainCompensate ) / st->L_frame;
- hTcxDec->gainHelper_float = st->last_concealed_gain_syn_deemph;
+ hTcxDec->stepCompensate_float = ( st->last_concealed_gain_syn_deemph_float - gainCompensate ) / st->L_frame;
+ hTcxDec->gainHelper_float = st->last_concealed_gain_syn_deemph_float;
}
- st->last_concealed_gain_syn_deemph = gainCompensate;
+ st->last_concealed_gain_syn_deemph_float = gainCompensate;
}
/*-----------------------------------------------------------*
@@ -1411,7 +1411,7 @@ void decoder_tcx_noiseshaping_igf(
if ( st->hTonalMDCTConc != NULL && st->element_mode != IVAS_CPE_MDCT )
{
- TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, L_frameTCX, ( hTcxDec->tcxltp_last_gain_unmodified_float > 0 ) ? st->old_fpitch : 0, bfi, bfi && st->tonal_mdct_plc_active );
+ TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, L_frameTCX, ( hTcxDec->tcxltp_last_gain_unmodified_float > 0 ) ? st->old_fpitch_float : 0, bfi, bfi && st->tonal_mdct_plc_active );
}
if ( st->enablePlcWaveadjust )
@@ -1738,21 +1738,21 @@ void decoder_tcx_imdct(
st->second_last_tns_active = st->last_tns_active;
st->last_tns_active = hTcxCfg->fIsTNSAllowed & fUseTns;
hTcxDec->tcxltp_third_last_pitch_float = hTcxDec->tcxltp_second_last_pitch_float;
- hTcxDec->tcxltp_second_last_pitch_float = st->old_fpitch;
- st->old_fpitch = hTcxLtpDec->tcxltp_pitch_int + hTcxLtpDec->tcxltp_pitch_fr / (float) st->pit_res_max;
+ hTcxDec->tcxltp_second_last_pitch_float = st->old_fpitch_float;
+ st->old_fpitch_float = hTcxLtpDec->tcxltp_pitch_int + hTcxLtpDec->tcxltp_pitch_fr / (float) st->pit_res_max;
if ( st->element_mode == IVAS_CPE_MDCT )
{
- st->old_fpitch *= (float) L_frame_glob / (float) L_FRAME;
+ st->old_fpitch_float *= (float) L_frame_glob / (float) L_FRAME;
}
if ( st->element_mode > EVS_MONO )
{
- st->old_fpitchFB = st->old_fpitch * (float) L_frameTCX_glob / (float) L_frame_glob;
+ st->old_fpitchFB_float = st->old_fpitch_float * (float) L_frameTCX_glob / (float) L_frame_glob;
}
else
{
- st->old_fpitchFB = st->old_fpitch * (float) L_frameTCX / (float) L_frame;
+ st->old_fpitchFB_float = st->old_fpitch_float * (float) L_frameTCX / (float) L_frame;
}
}
diff --git a/lib_dec/dec_uv.c b/lib_dec/dec_uv.c
index dc4cc306975284c42ce666f568086c66f670b9fd..f6c9b913b119f28647d7c9a609a1b531649b2d5a 100644
--- a/lib_dec/dec_uv.c
+++ b/lib_dec/dec_uv.c
@@ -120,7 +120,7 @@ void decod_unvoiced(
*-----------------------------------------------------------------*/
index = get_next_indice( st, st->acelp_cfg.gains_mode[i_subfr / L_SUBFR] );
- gain_dec_gacelp_uv( index, code, code2, Es_pred, L_SUBFR, &gain_pit, &gain_code, &gain_code2, &( st->past_gpit ), &norm_gain_code, &gain_inov );
+ gain_dec_gacelp_uv( index, code, code2, Es_pred, L_SUBFR, &gain_pit, &gain_code, &gain_code2, &( st->past_gpit_float), &norm_gain_code, &gain_inov );
st->tilt_code = est_tilt( exc + i_subfr, gain_pit, code, gain_code, &voice_fac, L_SUBFR, 0 );
diff --git a/lib_dec/er_dec_acelp.c b/lib_dec/er_dec_acelp.c
index b87a846879515d3b5255840ef5ffe48f049f296e..829ed27f3059a8072e2afc2a29a2e7ea4a42d697 100644
--- a/lib_dec/er_dec_acelp.c
+++ b/lib_dec/er_dec_acelp.c
@@ -116,7 +116,7 @@ void con_acelp(
T0 = st->guidedT0;
}
- pitch_pred_linear_fit( st->nbLostCmpt, st->last_good, st->old_pitch_buf, &st->old_fpitch, &predPitchLag, st->pit_min, st->pit_max, st->mem_pitch_gain, 0, st->plc_use_future_lag, &extrapolationFailed, st->nb_subfr );
+ pitch_pred_linear_fit( st->nbLostCmpt, st->last_good, st->old_pitch_buf, &st->old_fpitch_float, &predPitchLag, st->pit_min, st->pit_max, st->mem_pitch_gain_float, 0, st->plc_use_future_lag, &extrapolationFailed, st->nb_subfr );
T0 = (int16_t) ( predPitchLag + 0.5f );
if ( extrapolationFailed )
@@ -151,7 +151,7 @@ void con_acelp(
}
else
{
- tmp_tc = st->old_fpitch; /* take the previous frame last pitch*/
+ tmp_tc = st->old_fpitch_float; /* take the previous frame last pitch*/
}
/* PLC: [ACELP: Fade-out]
@@ -160,11 +160,11 @@ void con_acelp(
if ( st->nbLostCmpt == 1 )
{
- st->cummulative_damping = 1.0f;
+ st->cummulative_damping_float = 1.0f;
}
else
{
- st->cummulative_damping *= alpha;
+ st->cummulative_damping_float *= alpha;
}
/*-----------------------------------------------------------------*
@@ -208,7 +208,7 @@ void con_acelp(
{
/* pitch cycle is first low-pass filtered */
/*get filter coefficients*/
- genPlcFiltBWAdap( st->sr_core, &lpFiltAdapt[0], 0, st->cummulative_damping );
+ genPlcFiltBWAdap( st->sr_core, &lpFiltAdapt[0], 0, st->cummulative_damping_float);
for ( i = 0; i < Tc; i++ )
{
*pt_exc++ = ( lpFiltAdapt[0] * pt1_exc[-1] + lpFiltAdapt[1] * pt1_exc[0] + lpFiltAdapt[2] * pt1_exc[1] );
@@ -258,13 +258,13 @@ void con_acelp(
{
if ( fUseExtrapolatedPitch != 0 )
{
- get_subframe_pitch( st->nb_subfr, st->old_fpitch, predPitchLag, pitch_buf );
+ get_subframe_pitch( st->nb_subfr, st->old_fpitch_float, predPitchLag, pitch_buf );
- PulseResynchronization( harmonic_exc_buf, exc, L_frame, st->nb_subfr, st->old_fpitch, predPitchLag );
+ PulseResynchronization( harmonic_exc_buf, exc, L_frame, st->nb_subfr, st->old_fpitch_float, predPitchLag );
}
else
{
- set_f( pitch_buf, st->old_fpitch, st->nb_subfr );
+ set_f( pitch_buf, st->old_fpitch_float, st->nb_subfr );
}
}
@@ -291,11 +291,11 @@ void con_acelp(
if ( st->flagGuidedAcelp == 1 )
{
- st->old_fpitch = (float) T0;
+ st->old_fpitch_float = (float) T0;
}
else
{
- st->old_fpitch = predPitchLag;
+ st->old_fpitch_float = predPitchLag;
}
}
@@ -391,13 +391,13 @@ void con_acelp(
}
/*get filter coefficients*/
- genPlcFiltBWAdap( st->sr_core, &hp_filt[0], 1, st->cummulative_damping );
+ genPlcFiltBWAdap( st->sr_core, &hp_filt[0], 1, st->cummulative_damping_float);
/* PLC: [ACELP: Fade-out]
* PLC: retrieve background level */
tmp = 1.0f;
- gainSynthDeemph = getLevelSynDeemph( &( tmp ), A, L_SUBFR, st->preemph_fac, L_frame / L_SUBFR );
- gainCNG = st->cngTDLevel / gainSynthDeemph;
+ gainSynthDeemph = getLevelSynDeemph( &( tmp ), A, L_SUBFR, st->preemph_fac_float, L_frame / L_SUBFR );
+ gainCNG = st->cngTDLevel_float / gainSynthDeemph;
gain = st->lp_gainc; /* start-of-the-frame gain */
@@ -434,7 +434,7 @@ void con_acelp(
{
float tilt_code;
- tilt_code = (float) ( 0.10f * ( 1.0f + st->voice_fac ) );
+ tilt_code = (float) ( 0.10f * ( 1.0f + st->voice_fac_float) );
gain_inov *= ( 1.f - tilt_code );
}
@@ -460,7 +460,7 @@ void con_acelp(
*pt_exc++ *= ( gain_inov * gain );
}
- st->past_gcode = gain;
+ st->past_gcode_float = gain;
if ( st->last_good < UNVOICED_TRANSITION )
{
@@ -522,7 +522,7 @@ void con_acelp(
}
else
{
- mvr2r( st->mem_syn_unv_back, mem_syn_unv, M );
+ mvr2r( st->mem_syn_unv_back_float, mem_syn_unv, M );
}
/* voiced synth */
@@ -538,7 +538,7 @@ void con_acelp(
set_zero( mem, M );
h1[0] = 1.0f;
syn_filt( p_A, M, h1, h1, L_SUBFR, mem, 0 ); /* impulse response of LPC */
- deemph( h1, st->preemph_fac, L_SUBFR, &tmp ); /* impulse response of deemph */
+ deemph( h1, st->preemph_fac_float, L_SUBFR, &tmp ); /* impulse response of deemph */
/* impulse response level = gain introduced by synthesis+deemphasis */
gain_lpc[i_subfr / L_SUBFR] = 1.f / (float) sqrt( dotp( h1, h1, L_SUBFR ) );
p_A += ( M + 1 );
@@ -550,14 +550,14 @@ void con_acelp(
for ( i = 0; i < L_SUBFR; i++ )
{
- exc[i_subfr + i] *= st->last_gain_syn_deemph * gain_lpc[j];
+ exc[i_subfr + i] *= st->last_gain_syn_deemph_float * gain_lpc[j];
}
j++;
}
for ( i = L_frame; i < L_frame + L_frame / 2; i++ )
{
- exc[i] *= st->last_gain_syn_deemph * gain_lpc[3];
+ exc[i] *= st->last_gain_syn_deemph_float * gain_lpc[3];
}
p_A = A;
@@ -575,7 +575,7 @@ void con_acelp(
/* unvoiced synth */
tmp = 0;
- p_A = st->Aq_cng;
+ p_A = st->Aq_cng_float;
for ( i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR )
{
@@ -583,7 +583,7 @@ void con_acelp(
set_zero( mem, M );
h1[0] = 1.0f;
syn_filt( p_A, M, h1, h1, L_SUBFR, mem, 0 ); /* impulse response of LPC */
- deemph( h1, st->preemph_fac, L_SUBFR, &tmp ); /* impulse response of deemph */
+ deemph( h1, st->preemph_fac_float, L_SUBFR, &tmp ); /* impulse response of deemph */
/* impulse response level = gain introduced by synthesis+deemphasis */
gain_lpc[i_subfr / L_SUBFR] = 1.f / (float) sqrt( dotp( h1, h1, L_SUBFR ) );
p_A += ( M + 1 );
@@ -595,16 +595,16 @@ void con_acelp(
for ( i = 0; i < L_SUBFR; i++ )
{
- exc_unv[i_subfr + i] *= st->last_gain_syn_deemph * gain_lpc[j];
+ exc_unv[i_subfr + i] *= st->last_gain_syn_deemph_float * gain_lpc[j];
}
j++;
}
for ( i = L_frame; i < L_frame + L_frame / 2; i++ )
{
- exc_unv[i] *= st->last_gain_syn_deemph * gain_lpc[j - 1];
+ exc_unv[i] *= st->last_gain_syn_deemph_float * gain_lpc[j - 1];
}
- p_A = st->Aq_cng;
+ p_A = st->Aq_cng_float;
for ( i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR )
{
@@ -612,7 +612,7 @@ void con_acelp(
p_A += ( M + 1 );
}
- mvr2r( mem_syn_unv, st->mem_syn_unv_back, M );
+ mvr2r( mem_syn_unv, st->mem_syn_unv_back_float, M );
if ( st->last_good < UNVOICED_TRANSITION )
{
@@ -637,7 +637,7 @@ void con_acelp(
/* update buffer for the classification */
- FEC_clas_estim( syn, pitch_buf, st->L_frame, coder_type, st->codec_mode, st->mem_syn_clas_estim, &( st->clas_dec ), &st->lp_ener_bfi, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1.0f, st->narrowBand, 0, 1, st->preemph_fac, st->tcxonly, st->last_core_brate, -1 );
+ FEC_clas_estim( syn, pitch_buf, st->L_frame, coder_type, st->codec_mode, st->mem_syn_clas_estim, &( st->clas_dec ), &st->lp_ener_bfi, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1.0f, st->narrowBand, 0, 1, st->preemph_fac_float, st->tcxonly, st->last_core_brate, -1 );
/* Update Pitch Lag memory */
mvr2r( &st->old_pitch_buf[L_frame / L_SUBFR], st->old_pitch_buf, L_frame / L_SUBFR );
@@ -648,11 +648,11 @@ void con_acelp(
/* update ACELP synthesis memory */
mvr2r( mem_syn, st->mem_syn2, M );
- mvr2r( syn + L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM );
+ mvr2r( syn + L_frame - L_SYN_MEM, st->mem_syn_r_float, L_SYN_MEM );
/* Deemphasis and output synth */
- tmp_deemph = st->syn[M];
- deemph( syn, st->preemph_fac, L_frame + L_frame / 2, &tmp_deemph );
+ tmp_deemph = st->syn_float[M];
+ deemph( syn, st->preemph_fac_float, L_frame + L_frame / 2, &tmp_deemph );
mvr2r( syn, synth, L_frame );
mvr2r( syn + L_frame - L_frame / 2, st->hTcxDec->old_syn_Overl_float, L_frame / 2 );
@@ -660,7 +660,7 @@ void con_acelp(
/* save last half frame if next frame is TCX */
mvr2r( syn + L_frame, st->hTcxDec->syn_Overl_TDAC_float, L_frame / 2 );
- mvr2r( syn + L_frame - M - 1, st->syn, 1 + M );
+ mvr2r( syn + L_frame - M - 1, st->syn_float, 1 + M );
/* update old_Aq */
mvr2r( p_A - ( M + 1 ), st->old_Aq_12_8, M + 1 );
@@ -706,15 +706,15 @@ void con_acelp(
}
/* update memory for full band */
- lerp( st->hTcxDec->syn_Overl_TDAC_float, st->hTcxDec->syn_Overl_TDACFB_float, st->hTcxDec->L_frameTCX / 2, L_frame / 2 );
- lerp( st->hTcxDec->syn_Overl_float, st->hTcxDec->syn_OverlFB_float, st->hTcxDec->L_frameTCX / 2, L_frame / 2 );
- lerp( st->hHQ_core->old_outLB, st->hHQ_core->old_out, st->hTcxDec->L_frameTCX, L_frame );
+ lerp_flt( st->hTcxDec->syn_Overl_TDAC_float, st->hTcxDec->syn_Overl_TDACFB_float, st->hTcxDec->L_frameTCX / 2, L_frame / 2 );
+ lerp_flt( st->hTcxDec->syn_Overl_float, st->hTcxDec->syn_OverlFB_float, st->hTcxDec->L_frameTCX / 2, L_frame / 2 );
+ lerp_flt( st->hHQ_core->old_outLB, st->hHQ_core->old_out, st->hTcxDec->L_frameTCX, L_frame );
/* copy total excitation exc2 as 16kHz for acelp mode1 decoding */
if ( st->hWIDec != NULL )
{
- lerp( exc, st->hWIDec->old_exc2, L_EXC_MEM, L_frame );
- lerp( syn, st->hWIDec->old_syn2, L_EXC_MEM, L_frame );
+ lerp_flt( exc, st->hWIDec->old_exc2, L_EXC_MEM, L_frame );
+ lerp_flt( syn, st->hWIDec->old_syn2, L_EXC_MEM, L_frame );
}
st->bfi_pitch = pitch_buf[st->nb_subfr - 1];
st->bfi_pitch_frame = L_frame;
diff --git a/lib_dec/er_dec_tcx.c b/lib_dec/er_dec_tcx.c
index cac126d12319a88a8d6102fe0cf56dd0baa81027..c6c8a040d113ca10fe2364ba26b04ac07bbe0e83 100644
--- a/lib_dec/er_dec_tcx.c
+++ b/lib_dec/er_dec_tcx.c
@@ -91,7 +91,7 @@ void con_tcx(
W2 = st->hTcxCfg->tcx_mdct_window_lengthFB / 2;
/* take the previous frame last pitch */
- Tc = (int16_t) ( st->old_fpitchFB + 0.5f );
+ Tc = (int16_t) ( st->old_fpitchFB_float + 0.5f );
set_zero( buf, OLD_EXC_SIZE_DEC + L_FRAME_MAX + L_FRAME_MAX / NB_SUBFR + 1 + L_FRAME_MAX / 2 );
@@ -108,7 +108,7 @@ void con_tcx(
/* apply pre-emphasis to the signal */
mem = synth[-( L_frame / 2 + hTcxDec->pit_max_TCX + 2 * M ) - 1];
- preemph( &synth[-( L_frame / 2 + hTcxDec->pit_max_TCX + 2 * M )], st->preemph_fac, L_frame / 2 + hTcxDec->pit_max_TCX + 2 * M, &mem );
+ preemph( &synth[-( L_frame / 2 + hTcxDec->pit_max_TCX + 2 * M )], st->preemph_fac_float, L_frame / 2 + hTcxDec->pit_max_TCX + 2 * M, &mem );
st->lp_gainc = 0.0f;
st->lp_gainp = get_gain_flt( synth - 2 * L_subfr, synth - 2 * L_subfr - Tc, 2 * L_subfr, NULL );
@@ -129,7 +129,7 @@ void con_tcx(
autocorr( &( synth[-L_frame - 1] ), r, M, L_frame, ana_window, 0, 0, 0 );
/* Lag windowing */
- lag_wind( r, M, st->output_Fs, LAGW_STRONG );
+ lag_wind_flt( r, M, st->output_Fs, LAGW_STRONG );
/* Levinson Durbin */
lev_dur( A_local, r, M, NULL );
@@ -146,7 +146,7 @@ void con_tcx(
/* apply pre-emphasis to the signal */
mem = synth[-L_frame - 1];
- preemph( &synth[-L_frame], st->preemph_fac, L_frame, &mem );
+ preemph( &synth[-L_frame], st->preemph_fac_float, L_frame, &mem );
mvr2r( st->old_Aq_12_8, A_local, M + 1 );
offset = L_frame / 2;
@@ -189,7 +189,7 @@ void con_tcx(
}
else
{
- pitch_pred_linear_fit( st->nbLostCmpt, st->last_good, old_pitch_buf, &( st->old_fpitchFB ), &predPitchLag, hTcxDec->pit_min_TCX, hTcxDec->pit_max_TCX, st->mem_pitch_gain, st->output_Fs > 25600, st->plc_use_future_lag, &extrapolationFailed, st->nb_subfr );
+ pitch_pred_linear_fit( st->nbLostCmpt, st->last_good, old_pitch_buf, &( st->old_fpitchFB_float ), &predPitchLag, hTcxDec->pit_min_TCX, hTcxDec->pit_max_TCX, st->mem_pitch_gain_float, st->output_Fs > 25600, st->plc_use_future_lag, &extrapolationFailed, st->nb_subfr );
T0 = (int16_t) ( predPitchLag + 0.5f );
@@ -248,13 +248,13 @@ void con_tcx(
if ( fUseExtrapolatedPitch != 0 )
{
- get_subframe_pitch( st->nb_subfr, st->old_fpitch, predPitchLag * st->L_frame / L_frame, pitch_buf );
+ get_subframe_pitch( st->nb_subfr, st->old_fpitch_float, predPitchLag * st->L_frame / L_frame, pitch_buf );
- PulseResynchronization( buf, exc, L_frame, st->nb_subfr, st->old_fpitchFB, predPitchLag );
+ PulseResynchronization( buf, exc, L_frame, st->nb_subfr, st->old_fpitchFB_float, predPitchLag );
}
else
{
- set_f( pitch_buf, st->old_fpitch, st->nb_subfr );
+ set_f( pitch_buf, st->old_fpitch_float, st->nb_subfr );
}
if ( st->nbLostCmpt == 1 )
@@ -270,7 +270,7 @@ void con_tcx(
if ( fUseExtrapolatedPitch != 0 )
{
- st->old_fpitchFB = predPitchLag;
+ st->old_fpitchFB_float = predPitchLag;
}
st->bpf_gain_param = 0;
@@ -279,11 +279,11 @@ void con_tcx(
if ( st->nbLostCmpt == 1 )
{
- st->cummulative_damping = 1;
+ st->cummulative_damping_float = 1;
}
else
{
- st->cummulative_damping *= alpha;
+ st->cummulative_damping_float *= alpha;
}
gain = 1.0f;
@@ -301,18 +301,18 @@ void con_tcx(
gain -= step;
}
- offset = max( ( (int16_t) ( st->old_fpitchFB + 0.5f ) ) - L_frame / 2, 0 );
+ offset = max( ( (int16_t) ( st->old_fpitchFB_float + 0.5f ) ) - L_frame / 2, 0 );
mvr2r( exc + L_frame - offset, st->hTcxDec->old_excFB, L_frame / 2 + offset );
/* copy old_exc as 16kHz for acelp decoding */
if ( st->nbLostCmpt == 1 )
{
- lerp( exc - L_frame / 2, st->old_exc, L_EXC_MEM_DEC, L_frame + L_frame / 2 );
+ lerp_flt( exc - L_frame / 2, st->old_exc, L_EXC_MEM_DEC, L_frame + L_frame / 2 );
}
else
{
mvr2r( st->old_exc + L_FRAME16k, st->old_exc, L_FRAME16k / 2 );
- lerp( exc, st->old_exc + L_FRAME16k / 2, L_FRAME16k, L_frame );
+ lerp_flt( exc, st->old_exc + L_FRAME16k / 2, L_FRAME16k, L_frame );
}
}
else
@@ -424,7 +424,7 @@ void con_tcx(
{
for ( i = 0; i < L_frame + L_frame / 2 + L_FIR_FER2; i++ )
{
- noise[i] = ( 1 - st->cummulative_damping ) * noise[i] + st->cummulative_damping * dotp( &noise[i], hp_filt, L_FIR_FER2 );
+ noise[i] = ( 1 - st->cummulative_damping_float) * noise[i] + st->cummulative_damping_float * dotp( &noise[i], hp_filt, L_FIR_FER2 );
}
}
}
@@ -433,11 +433,11 @@ void con_tcx(
tmp = 1.0f;
if ( A_cng != NULL )
{
- gainSynthDeemph = getLevelSynDeemph( &( tmp ), A_cng, L_frame / 4, st->preemph_fac, 1 ) / 4.f;
+ gainSynthDeemph = getLevelSynDeemph( &( tmp ), A_cng, L_frame / 4, st->preemph_fac_float, 1 ) / 4.f;
}
else
{
- gainSynthDeemph = getLevelSynDeemph( &( tmp ), A_local, L_frame / 4, st->preemph_fac, 1 );
+ gainSynthDeemph = getLevelSynDeemph( &( tmp ), A_local, L_frame / 4, st->preemph_fac_float, 1 );
}
if ( st->tcxonly )
{
@@ -457,7 +457,7 @@ void con_tcx(
}
else
{
- gainCNG = st->cngTDLevel / gainSynthDeemph;
+ gainCNG = st->cngTDLevel_float / gainSynthDeemph;
}
gain = st->lp_gainc; /* start-of-the-frame gain */
@@ -527,12 +527,12 @@ void con_tcx(
/* copy old_exc as 16kHz for acelp decoding */
if ( st->nbLostCmpt == 1 )
{
- lerp( exc, st->old_exc, L_EXC_MEM_DEC, L_frame + L_frame / 2 );
+ lerp_flt( exc, st->old_exc, L_EXC_MEM_DEC, L_frame + L_frame / 2 );
}
else
{
mvr2r( st->old_exc + L_FRAME16k, st->old_exc, L_FRAME16k / 2 );
- lerp( exc, st->old_exc + L_FRAME16k / 2, L_FRAME16k, L_frame );
+ lerp_flt( exc, st->old_exc + L_FRAME16k / 2, L_FRAME16k, L_frame );
}
}
@@ -568,7 +568,7 @@ void con_tcx(
for ( i = 0; i < M; i++ )
{
- lsp_fade[i] = alpha_delayed * lsp_local[i] + alpha_inv * st->lspold_cng[i];
+ lsp_fade[i] = alpha_delayed * lsp_local[i] + alpha_inv * st->lspold_cng_float[i];
}
lsp2a_stab( lsp_fade, A_local, M );
@@ -584,16 +584,16 @@ void con_tcx(
/* copy mem_syn as 16kHz */
mem_syn_r_size_new = (int16_t) ( 1.25 * L_FRAME16k / 20.f );
- mvr2r( syn + L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM );
- lerp( st->mem_syn_r + L_SYN_MEM - mem_syn_r_size_old, st->mem_syn_r + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
- mvr2r( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2, M );
+ mvr2r( syn + L_frame - L_SYN_MEM, st->mem_syn_r_float, L_SYN_MEM );
+ lerp_flt( st->mem_syn_r_float + L_SYN_MEM - mem_syn_r_size_old, st->mem_syn_r_float + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
+ mvr2r( st->mem_syn_r_float + L_SYN_MEM - M, st->mem_syn2, M );
/* Deemphasis and output synth and ZIR */
- deemph( syn, st->preemph_fac, L_frame + L_frame / 2, &tmp_deemph );
- mvr2r( syn + L_frame - M - 1, st->syn, 1 + M );
+ deemph( syn, st->preemph_fac_float, L_frame + L_frame / 2, &tmp_deemph );
+ mvr2r( syn + L_frame - M - 1, st->syn_float, 1 + M );
- lerp( syn + L_frame - L_frame / 2, st->hTcxDec->old_syn_Overl_float, st->L_frame / 2, L_frame / 2 );
+ lerp_flt( syn + L_frame - L_frame / 2, st->hTcxDec->old_syn_Overl_float, st->L_frame / 2, L_frame / 2 );
mvr2r( syn + L_frame - n, st->hHQ_core->old_out, L_frame - n );
for ( i = 0; i < W1; i++ )
@@ -609,8 +609,8 @@ void con_tcx(
/* copy total excitation exc2 as 16kHz for ACELP MODE1 decoding */
if ( st->hWIDec != NULL )
{
- lerp( exc, st->hWIDec->old_exc2, L_EXC_MEM, L_frame );
- lerp( syn, st->hWIDec->old_syn2, L_EXC_MEM, L_frame );
+ lerp_flt( exc, st->hWIDec->old_exc2, L_EXC_MEM, L_frame );
+ lerp_flt( syn, st->hWIDec->old_syn2, L_EXC_MEM, L_frame );
}
st->bfi_pitch = pitch_buf[st->nb_subfr - 1];
st->bfi_pitch_frame = st->L_frame;
@@ -642,11 +642,11 @@ void con_tcx(
synth[-1] = pre_emph_buf;
/* update memory for low band */
- lerp( st->hTcxDec->syn_OverlFB_float, st->hTcxDec->syn_Overl_float, st->L_frame / 2, L_frame / 2 );
- lerp( st->hTcxDec->syn_Overl_TDACFB_float, st->hTcxDec->syn_Overl_TDAC_float, st->L_frame / 2, L_frame / 2 );
- lerp( st->hHQ_core->old_out, st->hHQ_core->old_outLB, st->L_frame, L_frame );
+ lerp_flt( st->hTcxDec->syn_OverlFB_float, st->hTcxDec->syn_Overl_float, st->L_frame / 2, L_frame / 2 );
+ lerp_flt( st->hTcxDec->syn_Overl_TDACFB_float, st->hTcxDec->syn_Overl_TDAC_float, st->L_frame / 2, L_frame / 2 );
+ lerp_flt( st->hHQ_core->old_out, st->hHQ_core->old_outLB, st->L_frame, L_frame );
- st->old_enr_LP = enr_1_Az( A_local, L_SUBFR );
+ st->old_enr_LP_float = enr_1_Az( A_local, L_SUBFR );
return;
}
diff --git a/lib_dec/er_util.c b/lib_dec/er_util.c
index c599ad2a4976b64460be542bd4af21fc58ae97ff..2800621a84dd7756e16057928b43931dac769762 100644
--- a/lib_dec/er_util.c
+++ b/lib_dec/er_util.c
@@ -265,7 +265,7 @@ int16_t GetPLCModeDecision(
/* update mem_lag according to info available on future frame */
st->old_pitch_buf[2 * st->nb_subfr] = (float) st->guidedT0;
st->old_pitch_buf[2 * st->nb_subfr + 1] = (float) st->guidedT0;
- st->mem_pitch_gain[0] = st->mem_pitch_gain[1] = 1.f;
+ st->mem_pitch_gain_float[0] = st->mem_pitch_gain_float[1] = 1.f;
}
if ( ( st->last_core > ACELP_CORE && hTcxDec->tcxltp_last_gain_unmodified_float != 0 ) || ( st->flagGuidedAcelp == 1 ) )
{
@@ -303,14 +303,14 @@ int16_t GetPLCModeDecision(
st->tonal_mdct_plc_active = 0;
if ( !( st->rf_flag && st->use_partial_copy && ( st->rf_frame_type == RF_TCXTD1 || st->rf_frame_type == RF_TCXTD2 ) ) )
{
- if ( st->hTonalMDCTConc != NULL && st->last_core == TCX_20_CORE && st->second_last_core == TCX_20_CORE && ( ( st->old_fpitch <= 0.5f * st->L_frame ) || ( hTcxDec->tcxltp_last_gain_unmodified_float <= 0.4f ) )
+ if ( st->hTonalMDCTConc != NULL && st->last_core == TCX_20_CORE && st->second_last_core == TCX_20_CORE && ( ( st->old_fpitch_float <= 0.5f * st->L_frame ) || ( hTcxDec->tcxltp_last_gain_unmodified_float <= 0.4f ) )
/* it is fine to call the detection even if no ltp information
is available, meaning that st->old_fpitch ==
st->tcxltp_second_last_pitch == st->L_frame */
- && ( st->old_fpitch == hTcxDec->tcxltp_second_last_pitch_float ) && !st->last_tns_active && !st->second_last_tns_active )
+ && ( st->old_fpitch_float == hTcxDec->tcxltp_second_last_pitch_float ) && !st->last_tns_active && !st->second_last_tns_active )
{
- TonalMDCTConceal_Detect( st->hTonalMDCTConc, ( hTcxDec->tcxltp_last_gain_unmodified_float > 0 ) ? st->old_fpitch : 0, &numIndices,
+ TonalMDCTConceal_Detect( st->hTonalMDCTConc, ( hTcxDec->tcxltp_last_gain_unmodified_float > 0 ) ? st->old_fpitch_float : 0, &numIndices,
( st->element_mode == IVAS_CPE_MDCT ? &( st->hTcxCfg->psychParamsTCX20 ) : st->hTcxCfg->psychParamsCurrent ) );
if ( ( numIndices > 10 ) || ( ( numIndices > 5 ) && ( fabs( hTcxDec->tcxltp_third_last_pitch_float - hTcxDec->tcxltp_second_last_pitch_float ) < 0.5f ) ) || ( ( numIndices > 0 ) && ( ( st->last_good <= UNVOICED_TRANSITION ) || ( hTcxDec->tcxltp_last_gain_unmodified_float <= 0.4f ) ) && ( fabs( hTcxDec->tcxltp_third_last_pitch_float - hTcxDec->tcxltp_second_last_pitch_float ) < 0.5f ) ) )
diff --git a/lib_dec/evs_dec.c b/lib_dec/evs_dec.c
index 63b4092adff24daeb98348ba8697c7eec40f613c..7bd86c44dfb84b08d606216c467149a86b4a0c07 100644
--- a/lib_dec/evs_dec.c
+++ b/lib_dec/evs_dec.c
@@ -514,7 +514,7 @@ ivas_error evs_dec(
* Decode core
* -------------------------------------------------------------- */
- dec_acelp_tcx_frame( st, &concealWholeFrame, output, st->p_bpf_noise_buf, pcmbufFB, bwe_exc_extended, voice_factors, pitch_buf, NULL );
+ dec_acelp_tcx_frame( st, &concealWholeFrame, output, st->p_bpf_noise_buf_float, pcmbufFB, bwe_exc_extended, voice_factors, pitch_buf, NULL );
concealWholeFrameTmp = concealWholeFrame;
if ( st->bfi )
@@ -666,7 +666,7 @@ ivas_error evs_dec(
st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = 0.99f * st->hFdCngDec->hFdCngCom->likelihood_noisy_speech + 0.01f * (float) st->hFdCngDec->hFdCngCom->flag_noisy_speech;
- st->lp_noise = st->hFdCngDec->lp_noise_float;
+ st->lp_noise_float = st->hFdCngDec->lp_noise_float;
ApplyFdCng( output, NULL, realBuffer, imagBuffer, st, concealWholeFrame, 0 );
@@ -695,7 +695,7 @@ ivas_error evs_dec(
mvr2r( st->hFdCngDec->hFdCngCom->timeDomainBuffer, timeDomainBuffer, st->L_frame );
mvr2r( st->hFdCngDec->hFdCngCom->A_cng, A, M + 1 );
- update_decoder_LPD_cng( st, timeDomainBuffer, A, st->p_bpf_noise_buf );
+ update_decoder_LPD_cng( st, timeDomainBuffer, A, st->p_bpf_noise_buf_float);
/* Generate additional comfort noise to mask potential coding artefacts */
if ( st->flag_cna )
@@ -732,9 +732,9 @@ ivas_error evs_dec(
set_f( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0.f, st->hFdCngDec->hFdCngCom->fftlen );
}
- if ( st->p_bpf_noise_buf )
+ if ( st->p_bpf_noise_buf_float)
{
- addBassPostFilter( st->p_bpf_noise_buf, -1, realBuffer, imagBuffer, st->cldfbBPF );
+ addBassPostFilter( st->p_bpf_noise_buf_float, -1, realBuffer, imagBuffer, st->cldfbBPF );
}
if ( st->output_Fs > 8000 && st->hTECDec != NULL )
diff --git a/lib_dec/fd_cng_dec.c b/lib_dec/fd_cng_dec.c
index 4fbc443c0fa1888c1fe91d8214e87d41281074fe..c21953128b4660c34ee8aa9b32df2b63d11ec692 100644
--- a/lib_dec/fd_cng_dec.c
+++ b/lib_dec/fd_cng_dec.c
@@ -103,7 +103,7 @@ ivas_error createFdCngDec(
*-------------------------------------------------------------------*/
void initFdCngDec(
- DEC_CORE_HANDLE_FLOAT st /* i/o: decoder state structure */
+ DEC_CORE_HANDLE st /* i/o: decoder state structure */
)
{
HANDLE_FD_CNG_DEC hFdCngDec;
@@ -468,7 +468,7 @@ void ApplyFdCng(
{
st->hTcxDec->CngLevelBackgroundTrace_bfi = (float) sqrt( ( sum_f( cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / L_frame );
}
- st->cngTDLevel = (float) sqrt( ( sum_f( cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / st->L_frame );
+ st->cngTDLevel_float = (float) sqrt( ( sum_f( cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / st->L_frame );
}
else if ( st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT )
{
@@ -499,9 +499,9 @@ void ApplyFdCng(
else if ( st->element_mode != IVAS_CPE_MDCT || st->core == ACELP_CORE )
{
lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, 0.f );
- a2lsp_stab( hFdCngCom->A_cng, lsp_cng, st->lspold_cng );
- mvr2r( lsp_cng, st->lspold_cng, M );
- lsp2lsf( lsp_cng, st->lsf_cng, M, sr_core );
+ a2lsp_stab( hFdCngCom->A_cng, lsp_cng, st->lspold_cng_float);
+ mvr2r( lsp_cng, st->lspold_cng_float, M );
+ lsp2lsf( lsp_cng, st->lsf_cng_float, M, sr_core );
}
st->plcBackgroundNoiseUpdated = 1;
}
@@ -528,7 +528,7 @@ void ApplyFdCng(
/* This sets the new CNG levels until a SID update overwrites it */
mvr2r( hFdCngDec->bandNoiseShape_float, cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ); /* This sets the new CNG levels until a SID update overwrites it */
- st->cngTDLevel = (float) sqrt( ( sum_f( cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / L_frame );
+ st->cngTDLevel_float = (float) sqrt( ( sum_f( cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / L_frame );
break;
}
@@ -1022,7 +1022,7 @@ void FdCng_decodeSID(
scalebands( sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, hFdCngCom->cngNoiseLevel, 1 );
- lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, st->preemph_fac );
+ lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, st->preemph_fac_float);
return;
}
@@ -1294,7 +1294,7 @@ void generate_comfort_noise_dec(
mvr2r( st->old_Aq_12_8, old_Aq, M + 1 );
old_exc = st->old_exc + L_EXC_MEM_DEC - ( N / 2 );
old_syn_pe = st->mem_syn2;
- old_syn = st->syn[M];
+ old_syn = st->syn_float[M];
for ( i = 0; i < N / 2; i++ )
{
@@ -1320,7 +1320,7 @@ void generate_comfort_noise_dec(
tmp = old_syn;
- deemph( noise, st->preemph_fac, N, &tmp );
+ deemph( noise, st->preemph_fac_float, N, &tmp );
for ( i = 0; i < N / 2; i++ )
{
@@ -2029,7 +2029,7 @@ void FdCngDecodeMDCTStereoSID(
CPE_DEC_HANDLE hCPE /* i/o: CPE decoder state structure */
)
{
- DEC_CORE_HANDLE_FLOAT sts[CPE_CHANNELS];
+ DEC_CORE_HANDLE sts[CPE_CHANNELS];
HANDLE_FD_CNG_COM hFdCngCom;
float *ms_ptr[CPE_CHANNELS];
float *lr_ptr[CPE_CHANNELS];
@@ -2112,7 +2112,7 @@ void FdCngDecodeMDCTStereoSID(
scalebands( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, hFdCngCom->cngNoiseLevel, 1 );
- lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, sts[ch]->preemph_fac );
+ lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, sts[ch]->preemph_fac_float);
}
if ( hCPE->nchan_out == 1 && hCPE->last_element_brate <= IVAS_SID_5k2 )
@@ -2138,7 +2138,7 @@ void FdCngDecodeDiracMDCTStereoSID(
CPE_DEC_HANDLE hCPE /* i/o: CPE decoder state structure */
)
{
- DEC_CORE_HANDLE_FLOAT sts[CPE_CHANNELS];
+ DEC_CORE_HANDLE sts[CPE_CHANNELS];
HANDLE_FD_CNG_COM hFdCngCom;
float *ms_ptr[CPE_CHANNELS];
float *lr_ptr[CPE_CHANNELS];
@@ -2199,7 +2199,7 @@ void FdCngDecodeDiracMDCTStereoSID(
scalebands( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, hFdCngCom->cngNoiseLevel, 1 );
- lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, sts[ch]->preemph_fac );
+ lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, sts[ch]->preemph_fac_float);
}
sts[0]->hFdCngDec->hFdCngCom->coherence = 0.0f;
sts[1]->hFdCngDec->hFdCngCom->coherence = 0.0f;
diff --git a/lib_dec/hq_core_dec.c b/lib_dec/hq_core_dec.c
index 1de3c78d23253de67e666396908d6d826259591a..749e7f23fa673511375bef4ac003b04c869de3d8 100644
--- a/lib_dec/hq_core_dec.c
+++ b/lib_dec/hq_core_dec.c
@@ -381,7 +381,7 @@ void hq_core_dec(
if ( st->bfi )
{
/* Rough resampling, but reduces energy loss in case of switch to ACELP in first good frame */
- lerp( t_audio_q, wtda_audio_LB, st->L_frame, inner_frame );
+ lerp_flt( t_audio_q, wtda_audio_LB, st->L_frame, inner_frame );
v_multc( t_audio_q, 0.5f, wtda_audio_LB, st->L_frame );
}
else
@@ -485,8 +485,8 @@ void hq_core_dec(
}
mvr2r( &st->old_pitch_buf[st->L_frame / L_SUBFR], st->old_pitch_buf, st->L_frame / L_SUBFR );
set_f( &st->old_pitch_buf[st->L_frame / L_SUBFR], (float) L_SUBFR, st->L_frame / L_SUBFR );
- mvr2r( &st->mem_pitch_gain[2], &st->mem_pitch_gain[st->L_frame / L_SUBFR + 2], st->L_frame / L_SUBFR );
- set_zero( &st->mem_pitch_gain[2], st->L_frame / L_SUBFR );
+ mvr2r( &st->mem_pitch_gain_float[2], &st->mem_pitch_gain_float[st->L_frame / L_SUBFR + 2], st->L_frame / L_SUBFR );
+ set_zero( &st->mem_pitch_gain_float[2], st->L_frame / L_SUBFR );
/* Move LB excitation to old_exc memory in case of switch HQ->ACELP */
if ( st->element_mode > EVS_MONO )
diff --git a/lib_dec/init_dec.c b/lib_dec/init_dec.c
index 0ba639e2e5c6ed03d4134f05dd0eaa941ec6794e..2a493472baec31a9ab26f3f3f9132af1635cfaf2 100644
--- a/lib_dec/init_dec.c
+++ b/lib_dec/init_dec.c
@@ -138,11 +138,11 @@ ivas_error init_decoder(
/* FEC */
st->scaling_flag = 0;
- st->lp_ener_FEC_av = 5.0e5f;
- st->lp_ener_FEC_max = 5.0e5f;
+ st->lp_ener_FEC_av_float = 5.0e5f;
+ st->lp_ener_FEC_max_float = 5.0e5f;
st->prev_bfi = 0;
st->lp_ener_bfi = 60.0f;
- st->old_enr_LP = 0.0f;
+ st->old_enr_LP_float = 0.0f;
st->lp_ener = 0.0f;
st->enr_old = 0.0f;
st->bfi_pitch = (float) L_SUBFR;
@@ -522,12 +522,12 @@ ivas_error init_decoder(
st->cldfbSynHB = NULL;
st->last_active_bandsToZero_bwdec = 0;
- st->perc_bwddec = 0.0f;
+ st->perc_bwddec_float = 0.0f;
st->last_flag_filter_NB = 0;
st->active_frame_cnt_bwddec = 0;
st->total_frame_cnt_bwddec = 0;
set_s( st->flag_buffer, 0, 20 );
- st->avg_nrg_LT = 0.0f;
+ st->avg_nrg_LT_float = 0.0f;
/*-----------------------------------------------------------------*
* Noise gate parameters
@@ -713,8 +713,8 @@ ivas_error init_decoder(
st->hFdCngDec = NULL;
}
- st->cngTDLevel = 0.f;
- st->lp_noise = -20.0f;
+ st->cngTDLevel_float = 0.f;
+ st->lp_noise_float = -20.0f;
st->force_lpd_reset = 0;
/*-----------------------------------------------------------------*
diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c
index c3e1bfa886a79e2d1d85f4c1b5dbae040cee8b70..f7c534d8cb3592a7b6aa266c51238a19c7f411a8 100644
--- a/lib_dec/ivas_core_dec.c
+++ b/lib_dec/ivas_core_dec.c
@@ -190,8 +190,8 @@ ivas_error ivas_core_dec(
if ( !st->bfi && st->prev_bfi && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) && st->hTcxDec != NULL )
{
- v_multc( st->hHQ_core->old_out, st->hTcxDec->conceal_eof_gain_float * st->last_concealed_gain_syn_deemph, st->hHQ_core->old_out, st->hTcxDec->L_frameTCX );
- v_multc( st->hHQ_core->old_outLB, st->hTcxDec->conceal_eof_gain_float * st->last_concealed_gain_syn_deemph, st->hHQ_core->old_outLB, st->L_frame );
+ v_multc( st->hHQ_core->old_out, st->hTcxDec->conceal_eof_gain_float * st->last_concealed_gain_syn_deemph_float, st->hHQ_core->old_out, st->hTcxDec->L_frameTCX );
+ v_multc( st->hHQ_core->old_outLB, st->hTcxDec->conceal_eof_gain_float * st->last_concealed_gain_syn_deemph_float, st->hHQ_core->old_outLB, st->L_frame );
}
set_f( voice_factors[n], 0.f, NB_SUBFR16k );
@@ -230,15 +230,15 @@ ivas_error ivas_core_dec(
int16_t ovl, fade_len;
if ( sts[0]->L_frame != sts[0]->last_L_frame )
{
- lerp( sts[0]->hHQ_core->old_outLB, sts[0]->hHQ_core->old_outLB, sts[0]->L_frame, sts[0]->last_L_frame );
+ lerp_flt( sts[0]->hHQ_core->old_outLB, sts[0]->hHQ_core->old_outLB, sts[0]->L_frame, sts[0]->last_L_frame );
}
if ( sts[0]->L_frame != L_FRAME16k )
{
ovl = (int16_t) ( STEREO_DFT32MS_OVL_16k * ( (float) sts[0]->L_frame / L_FRAME16k ) );
- lerp( hCPE->input_mem_LB[0], hCPE->input_mem_LB[0], ovl, STEREO_DFT32MS_OVL_16k );
+ lerp_flt( hCPE->input_mem_LB[0], hCPE->input_mem_LB[0], ovl, STEREO_DFT32MS_OVL_16k );
fade_len = (int16_t) ( STEREO_MDCT2DFT_FADE_LEN_48k * ( (float) sts[0]->L_frame / L_FRAME16k ) );
- lerp( hCPE->old_outLB_mdct, hCPE->old_outLB_mdct, fade_len, STEREO_MDCT2DFT_FADE_LEN_48k );
+ lerp_flt( hCPE->old_outLB_mdct, hCPE->old_outLB_mdct, fade_len, STEREO_MDCT2DFT_FADE_LEN_48k );
}
}
diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c
index a82d2fcefa72e60b313f307258c3e4aa8265af87..8b7b8ce131ebb014898e168201946bf790a9fa60 100644
--- a/lib_dec/ivas_cpe_dec.c
+++ b/lib_dec/ivas_cpe_dec.c
@@ -707,7 +707,7 @@ ivas_error create_cpe_dec(
break;
}
- if ( ( st = (DEC_CORE_HANDLE_FLOAT) malloc( sizeof( Decoder_State ) ) ) == NULL )
+ if ( ( st = (DEC_CORE_HANDLE) malloc( sizeof( Decoder_State ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n" ) );
}
diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c
index ef39567593998b17d14bdc318af97655a85e1cda..86643b6462c64b6e3a55e7ce6b8cfcd88b6ea98a 100644
--- a/lib_dec/ivas_init_dec.c
+++ b/lib_dec/ivas_init_dec.c
@@ -1935,7 +1935,7 @@ ivas_error ivas_init_decoder(
*-------------------------------------------------------------------------*/
void destroy_core_dec(
- DEC_CORE_HANDLE_FLOAT hCoreCoder /* i/o: core decoder structure */
+ DEC_CORE_HANDLE hCoreCoder /* i/o: core decoder structure */
)
{
destroy_cldfb_decoder( hCoreCoder );
diff --git a/lib_dec/ivas_ism_metadata_dec.c b/lib_dec/ivas_ism_metadata_dec.c
index eb48b62bc602d1535851edee87f02b5558d115d5..c4b07078dc0d303b6f16665629b5455bb9b9e948 100644
--- a/lib_dec/ivas_ism_metadata_dec.c
+++ b/lib_dec/ivas_ism_metadata_dec.c
@@ -45,9 +45,9 @@
* Local functions
*-----------------------------------------------------------------------*/
-static void decode_angle_indices( DEC_CORE_HANDLE_FLOAT st0, ISM_METADATA_ANGLE_HANDLE angle, const int16_t non_diegetic_flag, int16_t *flag_abs_azimuth );
+static void decode_angle_indices( DEC_CORE_HANDLE st0, ISM_METADATA_ANGLE_HANDLE angle, const int16_t non_diegetic_flag, int16_t *flag_abs_azimuth );
-static int16_t decode_radius( DEC_CORE_HANDLE_FLOAT st0, int16_t *last_radius_idx, int16_t *flag_abs_radius );
+static int16_t decode_radius( DEC_CORE_HANDLE st0, int16_t *last_radius_idx, int16_t *flag_abs_radius );
/*-------------------------------------------------------------------------*
@@ -149,7 +149,7 @@ ivas_error ivas_ism_metadata_dec(
const PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i : Param ISM Config Handle */
int16_t *ism_extmeta_active, /* i/o: Extended metadata active in renderer */
int16_t *ism_extmeta_cnt, /* i/o: Number of change frames observed */
- DEC_CORE_HANDLE_FLOAT st0 /* i : core-coder handle */
+ DEC_CORE_HANDLE st0 /* i : core-coder handle */
)
{
int16_t ch, nb_bits_start = 0, last_bit_pos;
@@ -703,7 +703,7 @@ ivas_error ivas_ism_metadata_dec_create(
*-------------------------------------------------------------------------*/
static void decode_angle_indices(
- DEC_CORE_HANDLE_FLOAT st0, /* i/o: bitstream handle */
+ DEC_CORE_HANDLE st0, /* i/o: bitstream handle */
ISM_METADATA_ANGLE_HANDLE angle, /* i/o: angle handle */
const int16_t non_diegetic_flag, /* i : Non diegetic flag */
int16_t *flag_abs_angle1 /* o : Azimuth/yaw encoding mode */
@@ -857,7 +857,7 @@ static void decode_angle_indices(
*-------------------------------------------------------------------------*/
static int16_t decode_radius(
- DEC_CORE_HANDLE_FLOAT st0, /* i/o: bitstream handle */
+ DEC_CORE_HANDLE st0, /* i/o: bitstream handle */
int16_t *last_radius_idx, /* i/o: last radius index */
int16_t *flag_abs_radius /* o : Radius encoding mode */
)
@@ -943,7 +943,7 @@ void ivas_ism_metadata_sid_dec(
int16_t nBits_azimuth, nBits_elevation, nBits_coh, nBits_sce_id;
int16_t md_diff_flag[MAX_NUM_OBJECTS];
ISM_MODE ism_mode_bstr;
- DEC_CORE_HANDLE_FLOAT st0;
+ DEC_CORE_HANDLE st0;
ISM_METADATA_HANDLE hIsmMetaData;
int16_t next_bit_pos_orig;
uint16_t bstr_meta[IVAS_SID_5k2 / FRAMES_PER_SEC], *bstr_orig;
diff --git a/lib_dec/ivas_mdct_core_dec.c b/lib_dec/ivas_mdct_core_dec.c
index eb607477606ae78b2cd4ae5df7ab1488c197d485..8b4436b9afc7e23a9865c4969b2ce77292480f4d 100644
--- a/lib_dec/ivas_mdct_core_dec.c
+++ b/lib_dec/ivas_mdct_core_dec.c
@@ -870,9 +870,9 @@ void ivas_mdct_core_reconstruct(
con_tcx( st, &synthFB[0], hCPE->hStereoMdct->lastCoh, &sts[0]->seed_acelp, ( sts[1]->core != ACELP_CORE ) ? 1 : 0, &st->hFdCngDec->hFdCngCom->A_cng[0] );
}
- lerp( synthFB, synth, st->L_frame, st->hTcxDec->L_frameTCX );
+ lerp_flt( synthFB, synth, st->L_frame, st->hTcxDec->L_frameTCX );
st->con_tcx = 1;
- set_f( &st->mem_pitch_gain[2], st->lp_gainp, st->nb_subfr );
+ set_f( &st->mem_pitch_gain_float[2], st->lp_gainp, st->nb_subfr );
/* PLC: [TCX: Tonal Concealment] */
/* Signal that this frame is not TCX */
@@ -897,7 +897,7 @@ void ivas_mdct_core_reconstruct(
}
else
{
- fer_energy( st->L_frame, st->clas_dec, synth, st->old_fpitch, &st->enr_old, st->L_frame );
+ fer_energy( st->L_frame, st->clas_dec, synth, st->old_fpitch_float, &st->enr_old, st->L_frame );
}
}
@@ -910,13 +910,13 @@ void ivas_mdct_core_reconstruct(
mvr2r( st->hHQ_core->old_out + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB + st->hTcxDec->old_synth_lenFB, NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) );
}
- mvr2r( st->lsp_q_cng, st->old_lsp_q_cng, M );
- mvr2r( st->lsf_q_cng, st->old_lsf_q_cng, M );
+ mvr2r( st->lsp_q_cng_float, st->old_lsp_q_cng_float, M );
+ mvr2r( st->lsf_q_cng_float, st->old_lsf_q_cng_float, M );
st->last_is_cng = 0;
/* Postfiltering */
- post_decoder( st, synth_buf, pit_gain[ch], pitch[ch], x[ch][0], st->p_bpf_noise_buf );
+ post_decoder( st, synth_buf, pit_gain[ch], pitch[ch], x[ch][0], st->p_bpf_noise_buf_float);
if ( signal_outFB[ch] )
{
@@ -1067,7 +1067,7 @@ void ivas_mdct_core_tns_ns(
if ( ( bfi || MCT_flag ) && st->hTonalMDCTConc != NULL )
{
- TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, L_frameTCX[ch], ( st->hTcxDec->tcxltp_last_gain_unmodified_float > 0 ) ? st->old_fpitch : 0, bfi, bfi && st->tonal_mdct_plc_active );
+ TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, L_frameTCX[ch], ( st->hTcxDec->tcxltp_last_gain_unmodified_float > 0 ) ? st->old_fpitch_float : 0, bfi, bfi && st->tonal_mdct_plc_active );
}
}
diff --git a/lib_dec/ivas_post_proc.c b/lib_dec/ivas_post_proc.c
index 728242c0efec684c415c73aab0ee51ce2c870ad5..e29366eb68b74dde43cbb3dd7fc4151153c5f13d 100644
--- a/lib_dec/ivas_post_proc.c
+++ b/lib_dec/ivas_post_proc.c
@@ -191,8 +191,8 @@ void stereo_dft_dec_core_switching(
/* resample DFT analysis memories in case of internal sampling rate change */
if ( st->last_L_frame != st->L_frame && st->last_L_frame <= L_FRAME16k && st->L_frame <= L_FRAME16k )
{
- lerp( hCPE->input_mem_LB[0], hCPE->input_mem_LB[0], NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ), NS2SA( st->last_L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) );
- lerp( hCPE->input_mem_BPF[0], hCPE->input_mem_BPF[0], NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ), NS2SA( st->last_L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) );
+ lerp_flt( hCPE->input_mem_LB[0], hCPE->input_mem_LB[0], NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ), NS2SA( st->last_L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) );
+ lerp_flt( hCPE->input_mem_BPF[0], hCPE->input_mem_BPF[0], NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ), NS2SA( st->last_L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) );
}
if ( st->prev_bfi && !( st->last_core_bfi == ACELP_CORE && st->last_con_tcx == 1 ) )
@@ -210,12 +210,12 @@ void stereo_dft_dec_core_switching(
mvr2r( &output[st->L_frame - NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS )], hCPE->hStereoDft->buff_LBTCX_mem, NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) );
/* BPF */
- if ( st->p_bpf_noise_buf && st->core != HQ_CORE )
+ if ( st->p_bpf_noise_buf_float && st->core != HQ_CORE )
{
- stereo_dft_dec_analyze( hCPE, st->p_bpf_noise_buf, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_BPF, 2, 0 );
+ stereo_dft_dec_analyze( hCPE, st->p_bpf_noise_buf_float, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_BPF, 2, 0 );
}
/* st->p_bpf_noise_buf not updated for HQ core -> skip analysis and set input memory to zero */
- else if ( st->p_bpf_noise_buf && st->core == HQ_CORE )
+ else if ( st->p_bpf_noise_buf_float && st->core == HQ_CORE )
{
set_zero( hCPE->input_mem_BPF[0], STEREO_DFT32MS_OVL_16k );
}
@@ -286,7 +286,7 @@ void stereo_dft_dec_core_switching(
stereo_dft_dec_analyze( hCPE, output, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_LB_ADD, 1, 0 );
/* BPF */
- if ( st->p_bpf_noise_buf )
+ if ( st->p_bpf_noise_buf_float)
{
set_zero( hCPE->input_mem_BPF[0], NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) );
}
@@ -308,7 +308,7 @@ void stereo_dft_dec_core_switching(
if ( ( st->last_L_frame <= L_FRAME16k && st->L_frame <= L_FRAME16k ) || ( sba_dirac_stereo_dtx_flag && st->core_brate == SID_2k40 && st->cng_type == FD_CNG ) )
{
/* In case of a TCX to ACELP switch, retrieve the LB-TCX memories for the first STEREO_DFT32MS_OVL_NS NS of OLA */
- lerp( hCPE->hStereoDft->buff_LBTCX_mem, hCPE->input_mem_LB[0], NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ), NS2SA( st->last_L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) );
+ lerp_flt( hCPE->hStereoDft->buff_LBTCX_mem, hCPE->input_mem_LB[0], NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ), NS2SA( st->last_L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) );
}
if ( sba_dirac_stereo_dtx_flag && st->core_brate == SID_2k40 && st->cng_type == FD_CNG )
@@ -333,9 +333,9 @@ void stereo_dft_dec_core_switching(
stereo_dft_dec_analyze( hCPE, output, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0 );
/* BPF */
- if ( st->p_bpf_noise_buf )
+ if ( st->p_bpf_noise_buf_float)
{
- stereo_dft_dec_analyze( hCPE, st->p_bpf_noise_buf, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_BPF, 0, 0 );
+ stereo_dft_dec_analyze( hCPE, st->p_bpf_noise_buf_float, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_BPF, 0, 0 );
}
}
else
@@ -354,9 +354,9 @@ void stereo_dft_dec_core_switching(
stereo_dft_dec_analyze( hCPE, output, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0 );
/* BPF */
- if ( st->p_bpf_noise_buf )
+ if ( st->p_bpf_noise_buf_float)
{
- stereo_dft_dec_analyze( hCPE, st->p_bpf_noise_buf, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_BPF, 0, 0 );
+ stereo_dft_dec_analyze( hCPE, st->p_bpf_noise_buf_float, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_BPF, 0, 0 );
}
/* Fading-in TD-BWE, Fading-out FB-TCX*/
@@ -401,16 +401,16 @@ void stereo_dft_dec_core_switching(
/* this needs an indication for sba2stereo in general */
else if ( hCPE->element_mode == IVAS_SCE && st->last_core_brate <= SID_2k40 && st->cng_type == FD_CNG )
{
- lerp( hCPE->input_mem[0], hCPE->input_mem_LB[0], NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ), NS2SA( output_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) );
+ lerp_flt( hCPE->input_mem[0], hCPE->input_mem_LB[0], NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ), NS2SA( output_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) );
}
/* ACELP synthesis @ internal sampling rate */
stereo_dft_dec_analyze( hCPE, output, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0 );
/* BPF */
- if ( st->p_bpf_noise_buf )
+ if ( st->p_bpf_noise_buf_float)
{
- stereo_dft_dec_analyze( hCPE, st->p_bpf_noise_buf, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_BPF, 0, 0 );
+ stereo_dft_dec_analyze( hCPE, st->p_bpf_noise_buf_float, DFT, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_BPF, 0, 0 );
}
/* BWE */
@@ -523,7 +523,7 @@ void stereo_dft_dec_core_switching(
{
if ( !use_cldfb_for_dft ) /* Skip this for DFT Stereo mono output at non-residual bitrates */
{
- lerp( output, synth, output_frame, hCPE->hCoreCoder[0]->L_frame ); /* Dirty resampling, but should be good enough for ECU analysis */
+ lerp_flt( output, synth, output_frame, hCPE->hCoreCoder[0]->L_frame ); /* Dirty resampling, but should be good enough for ECU analysis */
}
if ( !use_cldfb_for_dft || ( ( st->core_brate == FRAME_NO_DATA || st->core_brate == SID_2k40 ) && st->cng_type == LP_CNG && st->extl == SWB_CNG && hCPE->nchan_out == 1 ) )
{
diff --git a/lib_dec/ivas_sce_dec.c b/lib_dec/ivas_sce_dec.c
index 96f69a8b7e88cd679d96070584a376ca6797d580..39a622fb77a541e0f54d49d920e42e8634f6edc6 100644
--- a/lib_dec/ivas_sce_dec.c
+++ b/lib_dec/ivas_sce_dec.c
@@ -326,7 +326,7 @@ ivas_error create_sce_dec(
* Core Coder, 1 instance: allocate and initialize
*-----------------------------------------------------------------*/
- if ( ( st = (DEC_CORE_HANDLE_FLOAT) malloc( sizeof( Decoder_State ) ) ) == NULL )
+ if ( ( st = (DEC_CORE_HANDLE) malloc( sizeof( Decoder_State ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n" ) );
}
diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h
index 33231c298ec2e49f48b8dc731729ceb60f42dc0c..b4eef45cc571d793fa8190fb0399dfbd642401f6 100644
--- a/lib_dec/ivas_stat_dec.h
+++ b/lib_dec/ivas_stat_dec.h
@@ -683,7 +683,7 @@ typedef struct sce_dec_data_structure
int32_t last_element_brate; /* SCE last total bitrate in bps */
/* core coder handle */
- DEC_CORE_HANDLE_FLOAT hCoreCoder[1];
+ DEC_CORE_HANDLE hCoreCoder[1];
float prev_hb_synth[NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS )]; /* HB synthesis synchro buffer */
@@ -711,7 +711,7 @@ typedef struct cpe_dec_data_structure
float lt_es_em;
/* core coder handle */
- DEC_CORE_HANDLE_FLOAT hCoreCoder[CPE_CHANNELS];
+ DEC_CORE_HANDLE hCoreCoder[CPE_CHANNELS];
/* stereo data handles */
STEREO_DFT_DEC_DATA_HANDLE hStereoDft; /* DFT stereo data structure */
diff --git a/lib_dec/ivas_stereo_cng_dec.c b/lib_dec/ivas_stereo_cng_dec.c
index e93a7fda0580072447a080ca444ce1a8c327bd4f..00545ed10af33e4bd5144de344fd52f5ed5011f7 100644
--- a/lib_dec/ivas_stereo_cng_dec.c
+++ b/lib_dec/ivas_stereo_cng_dec.c
@@ -309,8 +309,8 @@ static void stereo_dft_generate_comfort_noise(
/* Deemphasis */
dmpf[0] = 1.0f;
- dmpf[1] = -st->preemph_fac;
- mvr2r( st->Aq_cng, Atmp, M + 1 );
+ dmpf[1] = -st->preemph_fac_float;
+ mvr2r( st->Aq_cng_float, Atmp, M + 1 );
conv( Atmp, dmpf, cngNoiseLevel_upd, M + 2 );
if ( st->L_frame == L_FRAME )
@@ -585,12 +585,12 @@ static void stereo_dft_generate_comfort_noise(
if ( hStereoCng->last_act_element_mode == IVAS_CPE_TD && chan > 0 )
{
- st1->lp_noise = 0.9f * st1->lp_noise + 0.1f * 10.f * log10f( lp_noise + DELTA );
+ st1->lp_noise_float = 0.9f * st1->lp_noise_float + 0.1f * 10.f * log10f( lp_noise + DELTA );
}
else if ( chan == 0 )
{
st->hFdCngDec->lp_noise_float = 0.9f * st->hFdCngDec->lp_noise_float + 0.1f * 10.f * log10f( lp_noise + DELTA );
- st->lp_noise = st->hFdCngDec->lp_noise_float;
+ st->lp_noise_float = st->hFdCngDec->lp_noise_float;
st->hFdCngDec->hFdCngCom->flag_noisy_speech = ( st->hFdCngDec->lp_speech_float - st->hFdCngDec->lp_noise_float ) < 28.f;
st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = 0.99f * st->hFdCngDec->hFdCngCom->likelihood_noisy_speech + 0.01f * st->hFdCngDec->hFdCngCom->flag_noisy_speech;
}
@@ -759,13 +759,13 @@ void stereo_cng_compute_PScorr(
if ( L_frame_0 > L_frame_1 )
{
outputPptr = output[0];
- lerp( output[1], outputResamp, L_frame_0, L_frame_1 );
+ lerp_flt( output[1], outputResamp, L_frame_0, L_frame_1 );
outputSptr = outputResamp;
}
else if ( L_frame_1 > L_frame_0 )
{
outputSptr = output[1];
- lerp( output[0], outputResamp, L_frame_1, L_frame_0 );
+ lerp_flt( output[0], outputResamp, L_frame_1, L_frame_0 );
outputPptr = outputResamp;
}
else
diff --git a/lib_dec/ivas_stereo_mdct_core_dec.c b/lib_dec/ivas_stereo_mdct_core_dec.c
index a22d7af071725d3b0f12f2e842e2f1fb59b037a9..f2e527b3e458a96ac90c53034c0a00ffd21b7aa8 100644
--- a/lib_dec/ivas_stereo_mdct_core_dec.c
+++ b/lib_dec/ivas_stereo_mdct_core_dec.c
@@ -323,7 +323,7 @@ void stereo_mdct_core_dec(
}
}
- TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, L_frameTCX[ch], ( st->hTcxDec->tcxltp_last_gain_unmodified_float > 0 ) ? st->old_fpitch : 0, bfi, bfi && st->tonal_mdct_plc_active );
+ TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, L_frameTCX[ch], ( st->hTcxDec->tcxltp_last_gain_unmodified_float > 0 ) ? st->old_fpitch_float : 0, bfi, bfi && st->tonal_mdct_plc_active );
}
mvs2s( ms_mask[0], hCPE->hStereoMdct->prev_ms_mask[0], MAX_SFB );
@@ -629,7 +629,7 @@ static void run_min_stats(
st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = 0.99f * st->hFdCngDec->hFdCngCom->likelihood_noisy_speech + 0.01f * (float) st->hFdCngDec->hFdCngCom->flag_noisy_speech;
- st->lp_noise = st->hFdCngDec->lp_noise_float;
+ st->lp_noise_float = st->hFdCngDec->lp_noise_float;
}
if ( will_estimate_noise_on_channel[0] || will_estimate_noise_on_channel[1] || st->bfi )
diff --git a/lib_dec/ivas_stereo_mdct_stereo_dec.c b/lib_dec/ivas_stereo_mdct_stereo_dec.c
index 11874d39e180201242f91f175ac271aaff3588ea..92e566ffb3a206f69dbd74dbf739b21dbcffd2d8 100644
--- a/lib_dec/ivas_stereo_mdct_stereo_dec.c
+++ b/lib_dec/ivas_stereo_mdct_stereo_dec.c
@@ -434,7 +434,7 @@ ivas_error initMdctStereoDtxData(
for ( ch = 0; ch < CPE_CHANNELS; ch++ )
{
- DEC_CORE_HANDLE_FLOAT st = hCPE->hCoreCoder[ch];
+ DEC_CORE_HANDLE st = hCPE->hCoreCoder[ch];
if ( st->hFdCngDec == NULL )
{
diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c
index 2628d53fa2879114492205591b3254d056ef91fd..0c153d7c001ebd30b0a9d829a6305b27e175ee80 100644
--- a/lib_dec/ivas_stereo_switching_dec.c
+++ b/lib_dec/ivas_stereo_switching_dec.c
@@ -55,7 +55,7 @@
*-------------------------------------------------------------------*/
static ivas_error allocate_CoreCoder_TCX(
- DEC_CORE_HANDLE_FLOAT st /* i/o: Core decoder state structure */
+ DEC_CORE_HANDLE st /* i/o: Core decoder state structure */
)
{
if ( st->hTcxDec == NULL )
@@ -135,7 +135,7 @@ static ivas_error allocate_CoreCoder_TCX(
*-------------------------------------------------------------------*/
static ivas_error allocate_CoreCoder(
- DEC_CORE_HANDLE_FLOAT st /* i/o: Core decoder state structure */
+ DEC_CORE_HANDLE st /* i/o: Core decoder state structure */
)
{
ivas_error error;
@@ -222,7 +222,7 @@ static ivas_error allocate_CoreCoder(
*-------------------------------------------------------------------*/
static void deallocate_CoreCoder_TCX(
- DEC_CORE_HANDLE_FLOAT st /* i/o: Core decoder state structure */
+ DEC_CORE_HANDLE st /* i/o: Core decoder state structure */
)
{
if ( st->hTcxDec != NULL )
@@ -260,7 +260,7 @@ static void deallocate_CoreCoder_TCX(
*-------------------------------------------------------------------*/
static void deallocate_CoreCoder(
- DEC_CORE_HANDLE_FLOAT st /* i/o: Core decoder state structure */
+ DEC_CORE_HANDLE st /* i/o: Core decoder state structure */
)
{
if ( st->hGSCDec != NULL )
@@ -350,7 +350,7 @@ ivas_error stereo_memory_dec(
const int16_t nchan_transport /* i : number of transport channels*/
)
{
- DEC_CORE_HANDLE_FLOAT st;
+ DEC_CORE_HANDLE st;
int16_t i, n, delay_comp_DFT;
ivas_error error;
@@ -1227,11 +1227,11 @@ void synchro_synthesis(
{
if ( sts[n]->core == ACELP_CORE )
{
- lerp( hCPE->input_mem_LB[n], tmp_out_TD[n], dft32ms_ovl, NS2SA( sts[n]->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) );
+ lerp_flt( hCPE->input_mem_LB[n], tmp_out_TD[n], dft32ms_ovl, NS2SA( sts[n]->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) );
}
else /* TCX/HQ core */
{
- lerp( hCPE->input_mem_LB[n], tmp_out_TD[n], dft32ms_ovl, NS2SA( sts[n]->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) );
+ lerp_flt( hCPE->input_mem_LB[n], tmp_out_TD[n], dft32ms_ovl, NS2SA( sts[n]->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) );
/* use TCX synchro memory (perfect signal is available) */
for ( i = delay_diff; i < dft32ms_ovl; i++ )
@@ -1257,7 +1257,7 @@ void synchro_synthesis(
{
tmpF = 1.0f / (float) delay_diff;
- /* cross-fading between regular output synthesis and lerp() resampled synthesis in 3.125 - 1.25 ms OLA part */
+ /* cross-fading between regular output synthesis and lerp_flt() resampled synthesis in 3.125 - 1.25 ms OLA part */
for ( i = 0; i < delay_diff; i++ )
{
p_output_mem[n][i] = ( output[n][output_frame - dft32ms_ovl + delay_cldfb + i] * ( delay_diff - i ) + tmp_out_TD2[n][i] * i ) * tmpF;
@@ -1506,7 +1506,7 @@ void stereo_switching_dec(
set_f( sts[0]->mem_syn1, 0, M );
set_f( sts[0]->mem_syn2, 0, M );
set_f( sts[0]->mem_syn3, 0, M );
- set_f( sts[0]->mem_syn_r, 0.0f, L_SYN_MEM );
+ set_f( sts[0]->mem_syn_r_float, 0.0f, L_SYN_MEM );
sts[1]->last_L_frame = sts[0]->last_L_frame;
@@ -1520,7 +1520,7 @@ void stereo_switching_dec(
sts[1]->prev_bfi = sts[0]->prev_bfi;
set_f( sts[1]->old_pitch_buf, (float) L_SUBFR, 2 * NB_SUBFR16k );
- sts[1]->old_fpitchFB = 2 * (float) L_SUBFR;
+ sts[1]->old_fpitchFB_float = 2 * (float) L_SUBFR;
/* reset CLDFB memories */
cldfb_reset_memory( sts[1]->cldfbAna );
@@ -1535,7 +1535,7 @@ void stereo_switching_dec(
set_f( sts[1]->mem_syn1, 0, M );
set_f( sts[1]->mem_syn2, 0, M );
set_f( sts[1]->mem_syn3, 0, M );
- set_f( sts[1]->mem_syn_r, 0.0f, L_SYN_MEM );
+ set_f( sts[1]->mem_syn_r_float, 0.0f, L_SYN_MEM );
sts[1]->last_L_frame = sts[0]->last_L_frame;
@@ -1617,9 +1617,9 @@ void stereo_td2dft_update(
mvr2r( output + sts[n]->L_frame - ovl, hCPE->input_mem_LB[n], ovl );
/* update DFT analysis overlap memory @internal_fs: BPF */
- if ( sts[n]->p_bpf_noise_buf )
+ if ( sts[n]->p_bpf_noise_buf_float)
{
- mvr2r( sts[n]->p_bpf_noise_buf + sts[n]->L_frame - ovl, hCPE->input_mem_BPF[n], ovl );
+ mvr2r( sts[n]->p_bpf_noise_buf_float + sts[n]->L_frame - ovl, hCPE->input_mem_BPF[n], ovl );
}
/* update DFT analysis overlap memory @output_Fs: BWE */
@@ -1640,9 +1640,9 @@ void stereo_td2dft_update(
mvr2r( output + sts[n]->L_frame - ovl, hCPE->input_mem_LB[n], ovl );
/* BPF */
- if ( n == 0 && sts[n]->p_bpf_noise_buf )
+ if ( n == 0 && sts[n]->p_bpf_noise_buf_float)
{
- mvr2r( sts[n]->p_bpf_noise_buf + sts[n]->L_frame - ovl, hCPE->input_mem_BPF[n], ovl );
+ mvr2r( sts[n]->p_bpf_noise_buf_float + sts[n]->L_frame - ovl, hCPE->input_mem_BPF[n], ovl );
}
/* TCX synthesis (it was already delayed in TD stereo in core_switching_post_dec()) */
@@ -1659,7 +1659,7 @@ void stereo_td2dft_update(
/* update DFT stereo OLA memories */
/*set_zero( hCPE->input_mem_LB[n], STEREO_DFT32MS_OVL_16k );*/
- lerp( output + sts[n]->L_frame - ovl, hCPE->input_mem_LB[n], STEREO_DFT32MS_OVL_16k, ovl );
+ lerp_flt( output + sts[n]->L_frame - ovl, hCPE->input_mem_LB[n], STEREO_DFT32MS_OVL_16k, ovl );
/* TCX synthesis (it was already delayed in TD stereo in core_switching_post_dec()) */
@@ -1679,7 +1679,7 @@ void stereo_td2dft_update(
/* update buffers used for fading when switching to DFT Stereo */
v_add( sts[0]->hHQ_core->old_outLB + nsLB, sts[1]->hHQ_core->old_outLB + nsLB, hCPE->old_outLB_mdct, old_outLB_len );
- lerp( hCPE->old_outLB_mdct, hCPE->old_outLB_mdct, STEREO_MDCT2DFT_FADE_LEN_48k, old_outLB_len );
+ lerp_flt( hCPE->old_outLB_mdct, hCPE->old_outLB_mdct, STEREO_MDCT2DFT_FADE_LEN_48k, old_outLB_len );
v_multc( hCPE->old_outLB_mdct, 0.5f, hCPE->old_outLB_mdct, STEREO_MDCT2DFT_FADE_LEN_48k );
v_add( sts[0]->hHQ_core->old_out + ns, sts[1]->hHQ_core->old_out + ns, hCPE->old_out_mdct, old_out_len );
diff --git a/lib_dec/ivas_tcx_core_dec.c b/lib_dec/ivas_tcx_core_dec.c
index bb6ebf50ac344f9efb9dd6acd0e1ef8fd8550ad0..ad11712213ae3e2463b56090b71594a21543b059 100644
--- a/lib_dec/ivas_tcx_core_dec.c
+++ b/lib_dec/ivas_tcx_core_dec.c
@@ -229,11 +229,11 @@ void stereo_tcx_core_dec(
/* for bass postfilter */
if ( st->tcxonly )
{
- st->p_bpf_noise_buf = NULL;
+ st->p_bpf_noise_buf_float = NULL;
}
else
{
- st->p_bpf_noise_buf = st->bpf_noise_buf;
+ st->p_bpf_noise_buf_float = st->bpf_noise_buf_float;
set_s( pitch, L_SUBFR, st->nb_subfr );
set_zero( pit_gain, st->nb_subfr );
}
@@ -301,14 +301,14 @@ void stereo_tcx_core_dec(
mvr2r( &lsf[M], st->mem_AR, M );
hTcxDec->envWeighted = 1;
- E_LPC_lsp_unweight_float( &lsp[M], lspnew_uw, lsfnew_uw, 1.0f / st->gamma );
+ E_LPC_lsp_unweight_float( &lsp[M], lspnew_uw, lsfnew_uw, 1.0f / st->gamma_float);
}
else
{
if ( hTcxDec->envWeighted )
{
- mvr2r( st->lspold_uw, st->lsp_old, M );
- mvr2r( st->lsfold_uw, st->lsf_old, M );
+ mvr2r( st->lspold_uw_float, st->lsp_old, M );
+ mvr2r( st->lsfold_uw_float, st->lsf_old, M );
hTcxDec->envWeighted = 0;
}
@@ -348,25 +348,25 @@ void stereo_tcx_core_dec(
if ( st->nbLostCmpt == 1 )
{
- mvr2r( st->lsf_old, st->old_lsf_q_cng, M );
- mvr2r( st->lsp_old, st->old_lsp_q_cng, M );
+ mvr2r( st->lsf_old, st->old_lsf_q_cng_float, M );
+ mvr2r( st->lsp_old, st->old_lsp_q_cng_float, M );
}
lsfBase = PlcGetlsfBase( st->lpcQuantization, st->narrowBand, st->sr_core );
- dlpc_bfi( st->L_frame, lsfnew_uw, st->lsfold_uw, st->last_good, st->nbLostCmpt, st->mem_MA, st->mem_AR, &( st->stab_fac ), st->lsf_adaptive_mean, st->numlpc, st->lsf_cng, st->plcBackgroundNoiseUpdated, st->lsf_q_cng, st->old_lsf_q_cng, lsfBase );
+ dlpc_bfi( st->L_frame, lsfnew_uw, st->lsfold_uw_float, st->last_good, st->nbLostCmpt, st->mem_MA, st->mem_AR, &( st->stab_fac ), st->lsf_adaptive_mean, st->numlpc, st->lsf_cng_float, st->plcBackgroundNoiseUpdated, st->lsf_q_cng_float, st->old_lsf_q_cng_float, lsfBase );
hTcxDec->envWeighted = 0;
- mvr2r( st->lspold_uw, lsp, M );
- mvr2r( st->lsfold_uw, lsf, M );
+ mvr2r( st->lspold_uw_float, lsp, M );
+ mvr2r( st->lsfold_uw_float, lsf, M );
for ( k = 0; k < st->numlpc; k++ )
{
mvr2r( &lsfnew_uw[k * M], &lsf[( k + 1 ) * M], M );
lsf2lsp( &lsf[( k + 1 ) * M], &lsp[( k + 1 ) * M], M, st->sr_core );
- lsf2lsp( st->lsf_q_cng, st->lsp_q_cng, M, st->sr_core );
+ lsf2lsp( st->lsf_q_cng_float, st->lsp_q_cng_float, M, st->sr_core );
mvr2r( &lsp[( k + 1 ) * M], &lspnew_uw[k * M], M );
}
@@ -404,19 +404,19 @@ void stereo_tcx_core_dec(
{
/*LPC interpolation*/
int_lsp( st->L_frame, &lsp[0], &lsp[M], Aq, M, interpol_frac_12k8, 0 );
- int_lsp( st->L_frame, st->old_lsp_q_cng, st->lsp_q_cng, st->Aq_cng, M, interpol_frac_12k8, 0 );
+ int_lsp( st->L_frame, st->old_lsp_q_cng_float, st->lsp_q_cng_float, st->Aq_cng_float, M, interpol_frac_12k8, 0 );
}
/* PLC: [TCX: TD PLC] */
con_tcx( st, &synthFB[0], -1.f, NULL, 0, NULL );
- lerp( synthFB, synth, st->L_frame, hTcxDec->L_frameTCX );
+ lerp_flt( synthFB, synth, st->L_frame, hTcxDec->L_frameTCX );
st->con_tcx = 1;
- set_f( &st->mem_pitch_gain[2], st->lp_gainp, st->nb_subfr );
+ set_f( &st->mem_pitch_gain_float[2], st->lp_gainp, st->nb_subfr );
/* LPC for ACELP/BWE */
if ( st->narrowBand || st->sr_core == INT_FS_12k8 || st->sr_core == INT_FS_16k )
{
- mvr2r( Aq, st->mem_Aq, st->nb_subfr * ( M + 1 ) );
+ mvr2r( Aq, st->mem_Aq_float, st->nb_subfr * ( M + 1 ) );
}
/* PLC: [TCX: Tonal Concealment] */
@@ -522,7 +522,7 @@ void stereo_tcx_core_dec(
if ( ( bfi || st->prev_bfi ) && st->hPlcInfo->Pitch && st->hPlcInfo->concealment_method == TCX_NONTONAL )
{
- lerp( synthFB, synth, st->L_frame, hTcxDec->L_frameTCX );
+ lerp_flt( synthFB, synth, st->L_frame, hTcxDec->L_frameTCX );
if ( !bfi && st->prev_bfi )
{
@@ -543,8 +543,8 @@ void stereo_tcx_core_dec(
/* LPC Interpolation for BWE/post-processing */
if ( st->narrowBand || st->sr_core == INT_FS_12k8 || st->sr_core == INT_FS_16k )
{
- int_lsp( st->L_frame, st->lspold_uw, lspnew_uw, Aq, M, interpol_frac_12k8, 0 );
- mvr2r( Aq, st->mem_Aq, st->nb_subfr * ( M + 1 ) );
+ int_lsp( st->L_frame, st->lspold_uw_float, lspnew_uw, Aq, M, interpol_frac_12k8, 0 );
+ mvr2r( Aq, st->mem_Aq_float, st->nb_subfr * ( M + 1 ) );
}
}
}
@@ -559,10 +559,10 @@ void stereo_tcx_core_dec(
float pitch_C[4];
/* note: the classifier needs the pitch only for tcx_only == 0, i.e. not for TCX10 */
- set_f( pitch_C, floorf( st->old_fpitch + 0.5f ), 4 );
+ set_f( pitch_C, floorf( st->old_fpitch_float + 0.5f ), 4 );
/* note: codec_mode is forced to MODE2, since FEC_clas_estim() considers only TCX being in Mode2*/
- FEC_clas_estim( synth, pitch_C, st->L_frame, st->tcxonly ? GENERIC : st->core_ext_mode, MODE2, st->mem_syn_clas_estim, &st->clas_dec, &st->lp_ener_bfi, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, hTcxLtpDec->tcxltp ? hTcxDec->tcxltp_last_gain_unmodified_float : -1.0f, st->narrowBand, CLASSIFIER_TCX, bfi, st->preemph_fac, st->tcxonly, st->last_core_brate, -1 );
+ FEC_clas_estim( synth, pitch_C, st->L_frame, st->tcxonly ? GENERIC : st->core_ext_mode, MODE2, st->mem_syn_clas_estim, &st->clas_dec, &st->lp_ener_bfi, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, hTcxLtpDec->tcxltp ? hTcxDec->tcxltp_last_gain_unmodified_float : -1.0f, st->narrowBand, CLASSIFIER_TCX, bfi, st->preemph_fac_float, st->tcxonly, st->last_core_brate, -1 );
}
}
@@ -579,14 +579,14 @@ void stereo_tcx_core_dec(
}
else
{
- fer_energy( st->L_frame, st->clas_dec, synth, st->old_fpitch, &st->enr_old, st->L_frame );
+ fer_energy( st->L_frame, st->clas_dec, synth, st->old_fpitch_float, &st->enr_old, st->L_frame );
}
}
if ( !bfi && st->clas_dec >= VOICED_TRANSITION && st->clas_dec < INACTIVE_CLAS )
{
/* use latest LPC set */
- st->old_enr_LP = enr_1_Az( Aq, L_SUBFR );
+ st->old_enr_LP_float = enr_1_Az( Aq, L_SUBFR );
}
/* Update past buffers */
@@ -595,21 +595,21 @@ void stereo_tcx_core_dec(
mvr2r( synth_bufFB + hTcxDec->L_frameTCX, hTcxDec->old_synthFB, hTcxDec->old_synth_lenFB );
mvr2r( st->hHQ_core->old_out + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB + hTcxDec->old_synth_lenFB, NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) );
- mvr2r( &lspnew_uw[( st->numlpc - 1 ) * M], st->lspold_uw, M );
- mvr2r( &lsfnew_uw[( st->numlpc - 1 ) * M], st->lsfold_uw, M );
+ mvr2r( &lspnew_uw[( st->numlpc - 1 ) * M], st->lspold_uw_float, M );
+ mvr2r( &lsfnew_uw[( st->numlpc - 1 ) * M], st->lsfold_uw_float, M );
if ( bfi == 1 )
{
- mvr2r( st->lspold_uw, st->lsp_old, M ); /* for recovery */
- mvr2r( st->lsfold_uw, st->lsf_old, M ); /* for recovery */
+ mvr2r( st->lspold_uw_float, st->lsp_old, M ); /* for recovery */
+ mvr2r( st->lsfold_uw_float, st->lsf_old, M ); /* for recovery */
}
else
{
mvr2r( &lsp[st->numlpc * M], st->lsp_old, M );
mvr2r( &lsf[st->numlpc * M], st->lsf_old, M );
}
- mvr2r( st->lsp_q_cng, st->old_lsp_q_cng, M );
- mvr2r( st->lsf_q_cng, st->old_lsf_q_cng, M );
+ mvr2r( st->lsp_q_cng_float, st->old_lsp_q_cng_float, M );
+ mvr2r( st->lsf_q_cng_float, st->old_lsf_q_cng_float, M );
/* Update CNG parameters */
if ( !st->tcxonly && st->hTdCngDec != NULL )
@@ -622,9 +622,9 @@ void stereo_tcx_core_dec(
mvr2r( synth + L_FRAME - L_LP, buf, L_LP );
tmp = synth[L_FRAME - L_LP - 1];
- preemph( buf, st->preemph_fac, L_LP, &tmp );
+ preemph( buf, st->preemph_fac_float, L_LP, &tmp );
autocorr( buf, r, M, L_LP, LP_assym_window, 0, 0, 0 );
- lag_wind( r, M, INT_FS_12k8, LAGW_WEAK );
+ lag_wind_flt( r, M, INT_FS_12k8, LAGW_WEAK );
lev_dur( A, r, M, NULL );
a2lsp_stab( A, lsptmp, &lspnew_uw[0] );
residu( A, M, buf + L_LP - L_FRAME, res, L_FRAME );
@@ -645,7 +645,7 @@ void stereo_tcx_core_dec(
st->last_is_cng = 0;
/* Postfiltering */
- post_decoder( st, synth_buf, pit_gain, pitch, signal_out, st->p_bpf_noise_buf );
+ post_decoder( st, synth_buf, pit_gain, pitch, signal_out, st->p_bpf_noise_buf_float);
if ( signal_outFB )
{
@@ -689,14 +689,14 @@ void stereo_tcx_core_dec(
st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = 0.99f * st->hFdCngDec->hFdCngCom->likelihood_noisy_speech + 0.01f * (float) st->hFdCngDec->hFdCngCom->flag_noisy_speech;
- st->lp_noise = st->hFdCngDec->lp_noise_float;
+ st->lp_noise_float = st->hFdCngDec->lp_noise_float;
if ( st->element_mode != IVAS_CPE_TD )
{
if ( ivas_format == ISM_FORMAT )
{
float buffer[L_FRAME16k];
- lerp( signal_outFB, buffer, st->L_frame, hTcxDec->L_frameTCX );
+ lerp_flt( signal_outFB, buffer, st->L_frame, hTcxDec->L_frameTCX );
ApplyFdCng( buffer, NULL, NULL, NULL, st, st->bfi, 0 );
}
else
diff --git a/lib_dec/ivas_td_low_rate_dec.c b/lib_dec/ivas_td_low_rate_dec.c
index 646c6561d6e6c82394daec981ccf5eef0d237faa..7b5115c36bf3f57c84142e63d7bece062bd41df5 100644
--- a/lib_dec/ivas_td_low_rate_dec.c
+++ b/lib_dec/ivas_td_low_rate_dec.c
@@ -228,7 +228,7 @@ void decod_gen_2sbfr(
*pt_pitch = pit_decode( st, st->core_brate, 0, L_frame, i_subfr, GENERIC, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, 2 * L_SUBFR, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf );
- tbe_celp_exc( st->element_mode, st->idchan, bwe_exc, L_frame, 2 * L_SUBFR, i_subfr, T0, T0_frac, &error, st->tdm_LRTD_flag );
+ tbe_celp_exc_flt( st->element_mode, st->idchan, bwe_exc, L_frame, 2 * L_SUBFR, i_subfr, T0, T0_frac, &error, st->tdm_LRTD_flag );
/*--------------------------------------------------------------*
* Find the adaptive codebook vector
diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c
index f47c399027be4bd503741f6bff3b4ac435cb2cc5..bda7ff1dab7a3d7bba59046dc7ce5174c5bf4e55 100644
--- a/lib_dec/lib_dec.c
+++ b/lib_dec/lib_dec.c
@@ -586,7 +586,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial(
if ( hIvasDec->hVoIP != NULL && hIvasDec->hVoIP->hCurrentDataUnit != NULL )
{
- DEC_CORE_HANDLE_FLOAT st = hIvasDec->st_ivas->hSCE[0]->hCoreCoder[0];
+ DEC_CORE_HANDLE st = hIvasDec->st_ivas->hSCE[0]->hCoreCoder[0];
st->ini_frame = 0;
st->prev_use_partial_copy = 0;
hIvasDec->st_ivas->hDecoderConfig->ivas_total_brate = hIvasDec->hVoIP->hCurrentDataUnit->dataSize * FRAMES_PER_SEC;
@@ -607,7 +607,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial(
/* Update redundant frame information in EVS (pre- read indices) */
if ( hIvasDec->mode == IVAS_DEC_MODE_EVS && hIvasDec->hVoIP != NULL && hIvasDec->hVoIP->hCurrentDataUnit != NULL )
{
- DEC_CORE_HANDLE_FLOAT st = hIvasDec->st_ivas->hSCE[0]->hCoreCoder[0];
+ DEC_CORE_HANDLE st = hIvasDec->st_ivas->hSCE[0]->hCoreCoder[0];
st->bit_stream = serial;
if ( hIvasDec->hVoIP->hCurrentDataUnit->partial_frame || st->prev_use_partial_copy )
@@ -636,7 +636,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial(
hIvasDec->hVoIP->hCurrentDataUnit != NULL &&
hIvasDec->hVoIP->hCurrentDataUnit->partial_frame != 0 )
{
- DEC_CORE_HANDLE_FLOAT st = hIvasDec->st_ivas->hSCE[0]->hCoreCoder[0];
+ DEC_CORE_HANDLE st = hIvasDec->st_ivas->hSCE[0]->hCoreCoder[0];
st->codec_mode = MODE2;
st->use_partial_copy = 1;
}
@@ -2641,7 +2641,7 @@ static ivas_error evs_dec_main(
float *floatBuf,
int16_t *pcmBuf )
{
- DEC_CORE_HANDLE_FLOAT *hCoreCoder;
+ DEC_CORE_HANDLE *hCoreCoder;
float output[MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN][L_FRAME48k];
float mixer_left, mixer_rigth;
float *p_output[MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN];
diff --git a/lib_dec/post_dec.c b/lib_dec/post_dec.c
index eb081a17579b101c112c5a87ed1192638e392f11..f54dba875cc21995ca9e79fa5b0708d2dec1dbea 100644
--- a/lib_dec/post_dec.c
+++ b/lib_dec/post_dec.c
@@ -117,7 +117,7 @@ void post_decoder(
/* NB Post-filter (pitch+formant post-filter) */
mvr2r( synth, synth_buf, L_frame );
tmp = synth[-1];
- preemph( synth_buf, st->preemph_fac, L_frame, &tmp );
+ preemph( synth_buf, st->preemph_fac_float, L_frame, &tmp );
tmp = 0.0f;
for ( i = 0; i < nb_subfr; i++ )
@@ -133,18 +133,18 @@ void post_decoder(
if ( st->bwidth == NB )
{
st->hPFstat->on = 1;
- nb_post_filt( L_frame, L_SUBFR, st->hPFstat, &tmp, 0, synth_buf, st->mem_Aq, pitch_buf, GENERIC, st->BER_detect, st->lp_noise > LP_NOISE_THRESH_FLT ? 1 : ( ( st->core != ACELP_CORE ) || ( st->coder_type == UNVOICED ) ) );
+ nb_post_filt( L_frame, L_SUBFR, st->hPFstat, &tmp, 0, synth_buf, st->mem_Aq_float, pitch_buf, GENERIC, st->BER_detect, st->lp_noise_float > LP_NOISE_THRESH_FLT ? 1 : ( ( st->core != ACELP_CORE ) || ( st->coder_type == UNVOICED ) ) );
}
else
{
st->hPFstat->on = 0;
- nb_post_filt( L_frame, L_SUBFR, st->hPFstat, &tmp, 0, synth_buf, st->mem_Aq, pitch_buf, AUDIO, st->BER_detect, st->lp_noise > LP_NOISE_THRESH_FLT ? 1 : ( ( st->core != ACELP_CORE ) || ( st->coder_type == UNVOICED ) ) );
+ nb_post_filt( L_frame, L_SUBFR, st->hPFstat, &tmp, 0, synth_buf, st->mem_Aq_float, pitch_buf, AUDIO, st->BER_detect, st->lp_noise_float > LP_NOISE_THRESH_FLT ? 1 : ( ( st->core != ACELP_CORE ) || ( st->coder_type == UNVOICED ) ) );
}
mvr2r( synth_buf, synth2, L_frame );
tmp = synth2[-1];
- deemph( synth2, st->preemph_fac, L_frame, &tmp );
+ deemph( synth2, st->preemph_fac_float, L_frame, &tmp );
}
else
{
@@ -157,17 +157,17 @@ void post_decoder(
if ( st->bwidth >= WB )
{
st->hPFstat->on = 1;
- formant_post_filt( st->hPFstat, synth, st->mem_Aq, synth2, L_frame, L_SUBFR, st->lp_noise, brate, 0 );
+ formant_post_filt( st->hPFstat, synth, st->mem_Aq_float, synth2, L_frame, L_SUBFR, st->lp_noise_float, brate, 0 );
}
else
{
st->hPFstat->on = 0;
- formant_post_filt( st->hPFstat, synth, st->mem_Aq, synth2, L_frame, L_SUBFR, st->lp_noise, brate, 1 );
+ formant_post_filt( st->hPFstat, synth, st->mem_Aq_float, synth2, L_frame, L_SUBFR, st->lp_noise_float, brate, 1 );
}
}
/*Bass Post-filter */
- bass_pf_1sf_delay( synth2, pitch, pit_gain, L_frame, L_SUBFR, bpf_noise_buf, pitch_gain_adjust, ( st->lp_noise > LP_NOISE_THRESH_FLT && st->narrowBand ) ? 1 : 0, &( st->hBPF->pst_mem_deemp_err ), &( st->hBPF->pst_lp_ener ) );
+ bass_pf_1sf_delay( synth2, pitch, pit_gain, L_frame, L_SUBFR, bpf_noise_buf, pitch_gain_adjust, ( st->lp_noise_float > LP_NOISE_THRESH_FLT && st->narrowBand ) ? 1 : 0, &( st->hBPF->pst_mem_deemp_err ), &( st->hBPF->pst_lp_ener ) );
}
/* Output */
@@ -409,9 +409,9 @@ void cldfb_synth_set_bandsToZero(
thr_bwddwc = ( nrg_bwddec / 512.0f );
- st->avg_nrg_LT = 0.98999f * st->avg_nrg_LT + 0.009979f * thr_bwddwc;
+ st->avg_nrg_LT_float = 0.98999f * st->avg_nrg_LT_float + 0.009979f * thr_bwddwc;
update_perc = 1;
- if ( st->ini_frame >= 25 && thr_bwddwc < st->avg_nrg_LT * 0.005f )
+ if ( st->ini_frame >= 25 && thr_bwddwc < st->avg_nrg_LT_float * 0.005f )
{
update_perc = 0;
}
@@ -431,11 +431,11 @@ void cldfb_synth_set_bandsToZero(
/*long term percentage*/
if ( update_perc == 1 )
{
- st->perc_bwddec += ( flag - st->perc_bwddec ) / st->active_frame_cnt_bwddec;
+ st->perc_bwddec_float += ( flag - st->perc_bwddec_float ) / st->active_frame_cnt_bwddec;
}
if ( ( st->total_frame_cnt_bwddec > offset ) && ( st->active_frame_cnt_bwddec > 50 ) )
{
- if ( ( st->perc_bwddec >= perc_detect || ( st->perc_bwddec >= perc_miss && st->last_flag_filter_NB ) ) && ( sum_s( st->flag_buffer, WBcnt ) != 0 ) ) /* decision hysterysis */
+ if ( ( st->perc_bwddec_float >= perc_detect || ( st->perc_bwddec_float >= perc_miss && st->last_flag_filter_NB ) ) && ( sum_s( st->flag_buffer, WBcnt ) != 0 ) ) /* decision hysterysis */
{
st->cldfbSyn->bandsToZero = ( st->cldfbSyn->no_channels - 10 );
st->last_flag_filter_NB = 1; /* VAD processing must be dependent on hysterysis, as if hysterysis fails, but threshold passes, we dont want next VAD frames to have NB only */
@@ -451,7 +451,7 @@ void cldfb_synth_set_bandsToZero(
}
if ( sum_s( st->flag_buffer, WBcnt ) == 0 )
{
- st->perc_bwddec = 0.0f;
+ st->perc_bwddec_float = 0.0f;
st->active_frame_cnt_bwddec = 0;
st->total_frame_cnt_bwddec = 0;
st->last_flag_filter_NB = 0;
diff --git a/lib_dec/pvq_core_dec.c b/lib_dec/pvq_core_dec.c
index 677b80f5c09b8aa6d4a72a7720f1e14d1880d319..8bdbe6811ee9d9396acb4e31c9eae3a837ad4ec7 100644
--- a/lib_dec/pvq_core_dec.c
+++ b/lib_dec/pvq_core_dec.c
@@ -117,7 +117,7 @@ static void pvq_decode_band(
for ( j = 0; j < Np; j++ )
{
js = idx_sort[Np - 1 - j];
- pool_part = shrtCDivSignedApprox( pool_tot, Np - j );
+ pool_part = shrtCDivSignedApprox_flt( pool_tot, Np - j );
bits_part[js] = max( 0, min( bits_part[js] + pool_part, 256 ) );
conservativeL1Norm( dim_part[js], bits_part[js], strict_bits, *bits_left, pool_tot, *npulses, /* inputs */
@@ -401,7 +401,7 @@ static void densitySymbolIndexDecode(
return;
}
#define WMC_TOOL_SKIP
- angle = atan2_fx( SQRT_DIM_fx[r_dim], SQRT_DIM_fx[l_dim] );
+ angle = atan2_fx_flt( SQRT_DIM_fx[r_dim], SQRT_DIM_fx[l_dim] );
#ifndef BASOP_NOGLOB
angle = shl( angle, 1 );
#else /* BASOP_NOGLOB */
diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h
index 7beabf0f7410d3c3f8e52af58e79586206eea271..d31b3049baaa4fd1313c29bde6712a1c8dd78202 100644
--- a/lib_dec/stat_dec.h
+++ b/lib_dec/stat_dec.h
@@ -648,7 +648,6 @@ typedef struct gsc_dec_structure
int16_t last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */
Word16 last_bitallocation_band_fx[6]; /* AC mode (GSC) - previous bit allocation of each band */
- //fixed
} GSC_DEC_DATA, *GSC_DEC_HANDLE;
@@ -665,7 +664,7 @@ typedef struct WI_dec_structure
float old_syn2[L_EXC_MEM]; /* FEC - old syn speech used in fast recovery */
Word16 old_syn2_fx[L_EXC_MEM]; /* FEC - old syn speech used in fast recovery */
- //fixed
+
} WI_DEC_DATA, *WI_DEC_HANDLE;
@@ -749,7 +748,7 @@ typedef struct bass_postfilt_structure
float mem_mean_pit[L_TRACK_HIST]; /* Bass post-filter - average pitch memory */
Word16 mem_mean_pit_fx[L_TRACK_HIST]; /* Bass post-filter - average pitch memory */
- //fixed
+
} BPF_DEC_DATA, *BPF_DEC_HANDLE;
@@ -862,7 +861,7 @@ typedef struct td_cng_dec_structure
Word16 last_cng_type_fx; /* DTX/CNG - flag indicating last frame LP or CLDFB based SID/CNG */
- //fixed
+
} TD_CNG_DEC_DATA, *TD_CNG_DEC_HANDLE;
@@ -936,7 +935,7 @@ typedef struct sc_vbr_dec_structure
Word16 nelp_dec_seed_fx; /* Q0*/
Word16 FadeScale_fx; /*Q15*/
- //fixed
+
} SC_VBR_DEC_DATA, *SC_VBR_DEC_HANDLE;
@@ -1009,7 +1008,6 @@ typedef struct hq_nbfec_structure
float prev_oldauOut[L_FRAME8k];
Word16 prev_oldauOut_fx[L_FRAME8k];
- //fixed
} HQ_NBFEC_DATA, *HQ_NBFEC_HANDLE;
@@ -1196,7 +1194,7 @@ typedef struct hq_dec_structure
int16_t ber_occured_in_pvq; /* flag for BER detection from PVQ routines */
- //fixed
+
} HQ_DEC_DATA, *HQ_DEC_HANDLE;
@@ -1225,7 +1223,6 @@ typedef struct zero_bwe_dec_structure
float mem_hp_interp[INTERP_3_1_MEM_LEN]; /* HF (6-7 kHz) BWE - interp. memory */
Word16 mem_hp_interp_fx[INTERP_3_1_MEM_LEN]; /* HF (6-7 kHz) BWE - interp. memory */
- //fixed
} ZERO_BWE_DEC_DATA, *ZERO_BWE_DEC_HANDLE;
@@ -1532,7 +1529,7 @@ typedef struct hr_swb_bwe_dec_structure
Word16 mem_EnergyLT_fx_exp;
- //fixed
+
} HR_BWE_DEC_DATA, *HR_BWE_DEC_HANDLE;
@@ -1619,7 +1616,7 @@ typedef struct amrwb_io_dec_structure
float lt_voice_fac; /* average voice factor over 4 sub-frames */
Word16 lt_voice_fac_fx; /* average voice factor over 4 sub-frames */
- //fixed
+
} AMRWB_IO_DEC_DATA, *AMRWB_IO_DEC_HANDLE;
@@ -1652,136 +1649,335 @@ typedef struct Decoder_State
int16_t last_codec_mode; /* last used codec mode */
uint16_t *bit_stream; /* pointer to bitstream buffer */
- int16_t next_bit_pos; /* position of the next bit to be read from the bitstream */
- int16_t BER_detect; /* flag to signal detected bit error in the bitstream */
- int32_t output_Fs; /* output sampling rate */
- int32_t total_brate; /* total bitrate in kbps of the codec */
- int32_t last_total_brate; /* last total bitrate in kbps of the codec */
+ UWord16 *bit_stream_fx;
+
+ int16_t next_bit_pos; /* position of the next bit to be read from the bitstream */
+ Word16 next_bit_pos_fx; /* position of the next bit to be read from the bitstream */
+
+ Word16 bitstreamformat; /* Bitstream format flag (G.192/MIME/VOIP_G192_RTP/VOIP_RTPDUMP) */
+ Word16 sdp_hf_only; /* RTP payload format parameter: only Header-Full format without zero padding for size collision avoidance */
+ Word16 amrwb_rfc4867_flag; /* MIME from rfc4867 is used */
+ Word16 total_num_bits; /* == st->total_brate / 50 */
+
+ int16_t BER_detect; /* flag to signal detected bit error in the bitstream */
+
+ int32_t output_Fs; /* output sampling rate */
+ Word32 output_Fs_fx; /* output sampling rate Q0*/
+
+ Word16 output_frame_fx; /* Output frame length Q0*/
+
+ int32_t total_brate; /* total bitrate in kbps of the codec */
+ Word32 total_brate_fx; /* total bitrate in kbps of the codec Q0*/
+
+ int32_t last_total_brate; /* last total bitrate in kbps of the codec */
+ Word32 last_total_brate_fx; /* last total bitrate in kbps of the codec Q0*/
+
int32_t last_total_brate_ber; /* last total bitrate in kbps of the codec - used only when first frame is lost and BER is detected afterwards */
- int16_t bits_frame_nominal; /* avg bits per frame on active frame */
+ Word32 last_total_brate_ber_fx; /* last total bitrate in kbps of the codec - used only when first frame is lost and BER is detected afterwards */
+
+ int16_t bits_frame_nominal; /* avg bits per frame on active frame */
int32_t last_bits_frame_nominal; /* last avg bits per frame on active frame */
int16_t flag_ACELP16k; /* flag indicating use of ACELP core at 16kHz internal sampling rate */
int16_t bits_frame_channel; /* bits frame channel */
int16_t side_bits_frame_channel; /* bits frame channel */
- int16_t core; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */
- int16_t coder_type; /* coder type */
+
+ int16_t core; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */
+ Word16 core_fx; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */
+
+ int16_t coder_type; /* coder type */
int16_t transform_type[2]; /* TCX20/10/5 mode in each subframe */
- int32_t core_brate; /* core bitrate */
- int32_t last_core_brate; /* previous frame core bitrate */
- int16_t extl; /* extension layer */
- int16_t extl_orig; /* extension layer */
- int16_t last_extl; /* previous extension layer */
- int32_t extl_brate; /* extension layer bitrate */
- int32_t extl_brate_orig; /* extension layer bitrate */
- int16_t L_frame; /* ACELP core internal frame length */
- int16_t bwidth; /* encoded signal bandwidth */
- int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */
- int16_t ini_frame; /* initialization frames counter */
- int16_t prev_coder_type; /* coding type of last frame */
+
+ int32_t core_brate; /* core bitrate */
+ Word32 core_brate_fx; /* core bitrate */
+
+ int32_t last_core_brate; /* previous frame core bitrate */
+ Word32 last_core_brate_fx; /* previous frame core bitrate Q0*/
+
+ int16_t extl; /* extension layer */
+ Word16 extl_fx; /* extension layer Q0*/
+
+ int16_t extl_orig; /* extension layer */
+
+ int16_t last_extl; /* previous extension layer */
+ Word16 last_extl_fx; /* previous extension layer Q0*/
+
+ int32_t extl_brate; /* extension layer bitrate */
+ Word32 extl_brate_fx; /* extension layer bitrate */
+
+ int32_t extl_brate_orig; /* extension layer bitrate */
+
+ int16_t L_frame; /* ACELP core internal frame length */
+ Word16 L_frame_fx; /* ACELP core internal frame length */
+
+ int16_t bwidth; /* encoded signal bandwidth */
+ Word16 bwidth_fx; /* encoded signal bandwidth */
+
+ int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */
+ Word16 Opt_AMR_WB_fx; /* flag indicating AMR-WB IO mode Q0*/
+
+ Word16 Opt_VOIP_fx; /* flag indicating VOIP mode with JBM */
+
+ int16_t ini_frame; /* initialization frames counter */
+ Word16 ini_frame_fx; /* initialization frames counter */
+
+ int16_t prev_coder_type; /* coding type of last frame */
int16_t low_rate_mode; /* low-rate mode flag */
int16_t last_low_rate_mode; /* previous frame low-rate mode flag */
int16_t inactive_coder_type_flag; /* inactive coder type flag (0 = AVQ / 1 = GSC) */
+ Word16 CNG_fx; /* RXDTX handler: CNG=1, nonCNG=0 */
+ Word16 prev_ft_speech_fx; /* RXDTX handler: previous frametype flag for G.192 format AMRWB SID_FIRST detection */
+
+
+ //note_ : produces failures if added below their float parts
+ Word16 old_exc_fx[L_EXC_MEM_DEC]; /* old excitation Q_exc*/
+ Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame Q2.56*/
+ Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame Q15*/
+
/*----------------------------------------------------------------------------------*
* ACELP core parameters
*----------------------------------------------------------------------------------*/
+
float old_exc[L_EXC_MEM_DEC]; /* old excitation */
- float lsp_old[M]; /* old LSP vector at the end of the frame */
- float lsf_old[M]; /* old LSF vector at the end of the frame */
- float tilt_code; /* tilt of code */
- float mem_syn1[M]; /* synthesis filter memory (for core switching and FD BWE) */
- float mem_syn2[M]; /* synthesis filter memory */
- float mem_syn3[M];
- float mem_deemph; /* deemphasis filter memory */
- float mem_AR[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) */
- float mem_MA[M]; /* MA memory of LSF quantizer (past quantized residual) */
- float stab_fac; /* LSF stability factor */
- float stab_fac_smooth; /* low-pass filtered stability factor */
- int16_t last_coder_type; /* previous coder type */
- float agc_mem2[2]; /* memory of AGC for saturation control */
- int16_t mid_lsf_int;
- int16_t safety_net;
- float stab_fac_smooth_lt;
+ float lsp_old[M]; /* old LSP vector at the end of the frame */
+ float lsf_old[M]; /* old LSF vector at the end of the frame */
+
+
+ float tilt_code; /* tilt of code */
+ Word16 tilt_code_fx; /* tilt of code Q15*/
+
+ float mem_syn1[M]; /* synthesis filter memory (for core switching and FD BWE) */
+ Word16 mem_syn1_fx[M]; /* synthesis filter memory (for core switching and FD BWE) */
+
+ float mem_syn2[M]; /* synthesis filter memory */
+ Word16 mem_syn2_fx[M]; /* synthesis filter memory Q_syn*/
+
+ float mem_syn3[M];
+ Word16 mem_syn3_fx[M];
+
+ float mem_deemph; /* deemphasis filter memory */
+ Word16 mem_deemph_fx; /* deemphasis filter memory Q_syn*/
+
+ float mem_AR[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) */
+ Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean)(Qx2.56) */
+
+ float mem_MA[M]; /* MA memory of LSF quantizer (past quantized residual) */
+ Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual)(Qx2.56)*/
+
+ float stab_fac; /* LSF stability factor */
+ Word16 stab_fac_fx; /* LSF stability factor Q15*/
+
+ float stab_fac_smooth; /* low-pass filtered stability factor */
+ Word16 stab_fac_smooth_fx; /* low-pass filtered stability factor Q15*/
+
+ int16_t last_coder_type; /* previous coder type */
+ Word16 last_coder_type_fx; /* previous coder type Q0*/
+
+ float agc_mem2[2]; /* memory of AGC for saturation control */
+ Word16 agc_mem_fx[2]; /* memory of AGC for saturation control Q0*/
+
+ int16_t mid_lsf_int;
+ Word16 mid_lsf_int_fx;
+
+ int16_t safety_net;
+ Word16 safety_net_fx;
+
+ float stab_fac_smooth_lt;
float log_energy_old;
float log_energy_diff_lt;
+ Word32 offset_scale1_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 1st 8-dim subvector*/
+ Word32 offset_scale2_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 2nd 8-dim subvector*/
+ Word32 offset_scale1_p_fx[MAX_NO_MODES_p + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure, pred. case, 1st 8-dim subvector*/
+ Word32 offset_scale2_p_fx[MAX_NO_MODES_p + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure, pred. case, 2nd 8-dim subvector*/
+ Word16 no_scales_fx[MAX_NO_MODES][2]; /* LSF LVQ structure Q0*/
+ Word16 no_scales_p_fx[MAX_NO_MODES_p][2]; /* LSF LVQ structure Q0*/
+ Word32 L_mem_hp_out_fx[5]; /* hp filter memory for synthesis */
+
+
int16_t GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */
- int16_t GSC_IVAS_mode; /* AC mode (GSC) - GSC IVAS mode */
- int16_t Last_GSC_noisy_speech_flag; /* AC mode (GSC) - mem of the past flag to indicate GSC osn SWB noisy speech */
- GSC_DEC_HANDLE hGSCDec;
+ Word16 GSC_noisy_speech_fx; /* AC mode (GSC) - flag to indicate GSC osn SWB noisy speech */
+
+ int16_t GSC_IVAS_mode; /* AC mode (GSC) - GSC IVAS mode */
+
+ int16_t Last_GSC_noisy_speech_flag; /* AC mode (GSC) - mem of the past flag to indicate GSC osn SWB noisy speech */
+ Word16 Last_GSC_noisy_speech_flag_fx; /* AC mode (GSC) - mem of the past flag to indicate GSC osn SWB noisy speech */
+
+ GSC_DEC_HANDLE hGSCDec;
- float gc_threshold; /* Noise enhancer - threshold for gain_code */
- float dispMem[8]; /* Noise enhancer - phase dispersion algorithm memory */
+
+ float gc_threshold; /* Noise enhancer - threshold for gain_code */
+ Word32 gc_threshold_fx; /* Noise enhancer - threshold for gain_code Q16*/
+
+ float dispMem[8]; /* Noise enhancer - phase dispersion algorithm memory */
+ struct dispMem_fx dm_fx; /* Noise enhancer - phase dispersion algorithm memory */
ZERO_BWE_DEC_HANDLE hBWE_zero; /* HF (6-7kHz) BWE */
int16_t unv_cnt; /* Stationary noise UV modification - unvoiced frame counter */
- int16_t uv_count; /* Stationary noise UV modification - unvoiced counter */
- int16_t act_count; /* Stationary noise UV modification - activation counter */
- float ge_sm; /* Stationary noise UV modification - smoothed excitation gain */
- float lspold_s[M]; /* Stationary noise UV modification - old LSP vector */
- int16_t noimix_seed; /* Stationary noise UV modification - mixture seed */
- float min_alpha; /* Stationary noise UV modification - minimum alpha */
- float exc_pe; /* Stationary noise UV modification - memory of the preemphasis filter */
+ Word16 unv_cnt_fx; /* Stationary noise UV modification - unvoiced frame counter Q0*/
+
+ int16_t uv_count; /* Stationary noise UV modification - unvoiced counter */
+ Word16 uv_count_fx; /* Stationary noise UV modification - unvoiced counter Q0*/
+
+ int16_t act_count; /* Stationary noise UV modification - activation counter */
+ Word16 act_count_fx; /* Stationary noise UV modification - activation counter Q0*/
+
+ float ge_sm; /* Stationary noise UV modification - smoothed excitation gain */
+ Word32 ge_sm_fx; /* Stationary noise UV modification - smoothed excitation gain Q(GE_SHIFT)*/
+
+ float lspold_s[M]; /* Stationary noise UV modification - old LSP vector */
+ Word16 lspold_s_fx[M]; /* Stationary noise UV modification - old LSP vector Q15*/
+
+ int16_t noimix_seed; /* Stationary noise UV modification - mixture seed */
+ Word16 noimix_seed_fx; /* Stationary noise UV modification - mixture seed Q0*/
+
+ float min_alpha; /* Stationary noise UV modification - minimum alpha */
+ Word16 min_alpha_fx; /* Stationary noise UV modification - minimum alpha Q15*/
+
+ Word16 Q_stat_noise; /* Q of Exc_pe */
+
+ float exc_pe; /* Stationary noise UV modification - memory of the preemphasis filter */
+ Word16 exc_pe_fx; /* Stationary noise UV modification - scale (Q_stat_noise) */
+
+ Word16 Q_stat_noise_ge; /* Q of ge_sm_fx */
+
int16_t bfi; /* FEC - bad frame indicator */
- int16_t prev_bfi; /* FEC - previous bad frame indicator */
- int16_t prev_old_bfi; /* FEC - previous old bad frame indicator */
- int16_t seed; /* FEC - seed for random generator for excitation */
- float lp_ener_bfi; /* FEC - long-term active-signal average energy */
- int16_t last_good; /* FEC - clas of last good received */
- float lp_gainp; /* FEC - low-pass filtered pitch gain */
- float lp_gainc; /* FEC - low-pass filtered code gain */
- float lp_ener; /* FEC - low-pass filtered energy */
- float enr_old; /* FEC - energy of the concealed frame */
- float bfi_pitch; /* FEC - pitch for FEC */
- int16_t bfi_pitch_frame; /* FEC - frame length when pitch for FEC is saved */
- float old_pitch_buf[2 * NB_SUBFR16k + 2]; /* FEC - buffer of old subframe pitch values */
- int16_t upd_cnt; /* FEC - counter of frames since last update */
- int16_t scaling_flag; /* FEC - flag to indicate energy control of syn */
- float lp_ener_FEC_av; /* FEC - averaged voiced signal energy */
- float lp_ener_FEC_max; /* FEC - averaged voiced signal energy */
- float old_enr_LP; /* FEC - LP filter gain */
- int16_t prev_nbLostCmpt; /* FEC - compt for number of consecutive lost frame at the previous frame*/
- int16_t mode_lvq; /* FEC - index for LSF mean vector */
- float lsfoldbfi0[M]; /* FEC - LSF vector of the previous frame */
- float lsfoldbfi1[M]; /* FEC - LSF vector of the past previous frame */
- float lsf_adaptive_mean[M]; /* FEC - adaptive mean LSF vector for FEC */
- int16_t decision_hyst; /* FEC - hysteresis of the music/speech decision */
- WI_DEC_HANDLE hWIDec;
- int16_t relax_prev_lsf_interp;
- float mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM]; /* FEC - memory of the synthesis signal for frame class estimation */
+ Word16 bfi_fx; /* FEC - bad frame indicator */
+
+ int16_t prev_bfi; /* FEC - previous bad frame indicator */
+ Word16 prev_bfi_fx; /* FEC - previous bad frame indicator Q0*/
+
+ int16_t prev_old_bfi; /* FEC - previous old bad frame indicator */
+
+ int16_t seed; /* FEC - seed for random generator for excitation */
+ Word16 seed_fx; /* FEC - seed for random generator for excitation Q0*/
+
+ float lp_ener_bfi; /* FEC - long-term active-signal average energy */
+
+ int16_t last_good; /* FEC - clas of last good received */
+
+ float lp_gainp; /* FEC - low-pass filtered pitch gain */
+ Word16 lp_gainp_fx; /* FEC - low-pass filtered pitch gain Q14 */
+
+ float lp_gainc; /* FEC - low-pass filtered code gain */
+ Word16 lp_gainc_fx; /* FEC - low-pass filtered code gain Q3*/
+
+ float lp_ener; /* FEC - low-pass filtered energy */
+ Word32 lp_ener_fx; /* FEC - low-pass filtered energy Q6*/
+
+ float enr_old; /* FEC - energy of the concealed frame */
+ Word32 enr_old_fx; /* FEC - energy of the concealed frame Q0*/
+
+ float bfi_pitch; /* FEC - pitch for FEC */
+ Word16 bfi_pitch_fx; /* 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*/
+
+ float old_pitch_buf[2 * NB_SUBFR16k + 2]; /* FEC - buffer of old subframe pitch values */
+ Word32 old_pitch_buf_fx[2 * NB_SUBFR16k + 2]; /* FEC - buffer of old subframe pitch values 15Q16 */
+
+ int16_t upd_cnt; /* FEC - counter of frames since last update */
+ Word16 upd_cnt_fx; /* FEC - counter of frames since last update Q0*/
+
+ int16_t scaling_flag; /* FEC - flag to indicate energy control of syn */
+
+ float lp_ener_FEC_av_float; /* FEC - averaged voiced signal energy */
+ Word32 lp_ener_FEC_av; /* FEC - averaged voiced signal energy Q0 */
+
+ float lp_ener_FEC_max_float; /* FEC - averaged voiced signal energy */
+ Word32 lp_ener_FEC_max; /* FEC - averaged voiced signal energy Q0 */
+
+ float old_enr_LP_float; /* FEC - LP filter gain */
+ Word16 old_enr_LP; /* FEC - LP filter gain Q5*/
+
+ int16_t prev_nbLostCmpt; /* FEC - compt for number of consecutive lost frame at the previous frame*/
+ int16_t mode_lvq; /* FEC - index for LSF mean vector*/
+
+ float lsfoldbfi0[M]; /* FEC - LSF vector of the previous frame */
+ Word16 lsfoldbfi0_fx[M]; /* FEC - LSF vector of the previous frame (Qx2.56)*/
+
+ float lsfoldbfi1[M]; /* FEC - LSF vector of the past previous frame */
+ Word16 lsfoldbfi1_fx[M]; /* FEC - LSF vector of the past previous frame (Qx2.56) */
+
+ float lsf_adaptive_mean[M]; /* FEC - adaptive mean LSF vector for FEC */
+ Word16 lsf_adaptive_mean_fx[M]; /* FEC - adaptive mean LSF vector for FEC (Qx2.56)*/
+
+ int16_t decision_hyst; /* FEC - hysteresis of the music/speech decision */
+ Word16 decision_hyst_fx; /* FEC - hysteresis of the music/speech decision Q0*/
+
+ Word16 last_good_fx; /* FEC - clas of last good received Q0*/
+ Word16 lp_ener_FER_fx; /* FEC - long-term active-signal average energy Q8*/
+
+
+ WI_DEC_HANDLE hWIDec;
+
+ int16_t relax_prev_lsf_interp;
+ Word16 relax_prev_lsf_interp_fx;
+
+ float mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM]; /* FEC - memory of the synthesis signal for frame class estimation */
+ Word16 mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM]; /* FEC - memory of the synthesis signal for frame class estimation */
int16_t bpf_off; /* Bass post-filter - do not use BPF when this flag is set to 1 */
- BPF_DEC_HANDLE hBPF; /* Bass post-filter handle */
+ Word16 bpf_off_fx; /* Bass post-filter - do not use BPF when this flag is set to 1 Q0*/
+
+ BPF_DEC_HANDLE hBPF; /* Bass post-filter handle */
HANDLE_CLDFB_FILTER_BANK cldfbAna; /* main analysis filter bank handle */
- HANDLE_CLDFB_FILTER_BANK cldfbBPF; /* BPF analysis filter bank handle */
- HANDLE_CLDFB_FILTER_BANK cldfbSyn; /* main synthesis filter bank handle */
- HANDLE_CLDFB_FILTER_BANK cldfbSynHB; /* high band synthesis filter bank needed in SBA2Stereo DTX handling */
+ HANDLE_CLDFB_FILTER_BANK cldfbAna_fx; /* main analysis filter bank handle */
+
+ HANDLE_CLDFB_FILTER_BANK cldfbBPF; /* BPF analysis filter bank handle */
+ HANDLE_CLDFB_FILTER_BANK cldfbBPF_fx; /* BPF analysis filter bank handle */
+
+ HANDLE_CLDFB_FILTER_BANK cldfbSyn; /* main synthesis filter bank handle */
+ HANDLE_CLDFB_FILTER_BANK cldfbSyn_fx; /* main synthesis filter bank handle */
+
+ HANDLE_CLDFB_FILTER_BANK cldfbSynHB; /* high band synthesis filter bank needed in SBA2Stereo DTX handling */
+
int16_t last_active_bandsToZero_bwdec;
int16_t last_flag_filter_NB;
- float perc_bwddec;
- int16_t active_frame_cnt_bwddec;
+
+ float perc_bwddec_float;
+ Word16 perc_bwddec; /*Q14*/
+
+ int16_t active_frame_cnt_bwddec;
int16_t flag_buffer[20];
int16_t total_frame_cnt_bwddec;
- float avg_nrg_LT;
- float ng_ener_ST; /* Noise gate - short-term energy */
+
+ float avg_nrg_LT_float;
+ Word32 avg_nrg_LT;
+
+ float ng_ener_ST; /* Noise gate - short-term energy */
+ Word16 Ng_ener_ST_fx; /* Noise gate - short-term energy Q8*/
int16_t last_L_frame; /* ACELP@16kHz - last value of st->L_frame */
- float mem_preemp_preQ; /* ACELP@16kHz - prequantizer preemhasis memory */
- int16_t last_nq_preQ; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */
- int16_t last_code_preq; /* ACELP@16kHz - last coefficient of the pre-quantizer contribution */
- int16_t use_acelp_preq; /* ACELP@16kHz - flag of prequantizer usage */
+ Word16 last_L_frame_fx; /* ACELP@16kHz - last value of st->L_frame */
+
+ float mem_preemp_preQ; /* ACELP@16kHz - prequantizer preemhasis memory */
+ Word16 mem_preemp_preQ_fx; /* ACELP@16kHz - prequantizer preemhasis memory */
+
+ int16_t last_nq_preQ; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */
+ Word16 last_nq_preQ_fx; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */
+
+ int16_t last_code_preq; /* ACELP@16kHz - last coefficient of the pre-quantizer contribution */
+
+ int16_t use_acelp_preq; /* ACELP@16kHz - flag of prequantizer usage */
+
/* NB and formant post-filter */
PFSTAT_HANDLE hPFstat; /* NB and formant post-filter states */
- float psf_lp_noise; /* NB post-filter - long-term noise */
+
+ float psf_lp_noise; /* NB post-filter - long-term noise */
+ Word16 psf_lp_noise_fx;
float last_voice_factor;
- float prev_synth_buffer[NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS )];
+ Word16 last_voice_factor_fx; /* Q6*/
+
+ float prev_synth_buffer[NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS )];
int16_t old_bfi_cnt; /* HQ core - # of bfi until previous frame(for FEC) */
@@ -1790,15 +1986,26 @@ typedef struct Decoder_State
*----------------------------------------------------------------------------------*/
int16_t first_CNG; /* DTX/CNG - first CNG frame flag */
- int16_t cng_type; /* DTX/CNG - flag indicating LP or CLDFB based SID/CNG */
- int16_t last_vad;
- int32_t last_active_brate; /* DTX/CNG - last active frame bitrate used for CNG_mode control */
- int16_t last_CNG_L_frame; /* DTX/CNG - last CNG frame length */
-
- int16_t active_cnt;
+ Word16 first_CNG_fx; /* CNG and DTX - first CNG frame flag Q0*/
+
+ int16_t cng_type; /* DTX/CNG - flag indicating LP or CLDFB based SID/CNG */
+ Word16 cng_type_fx; /* DTX/CNG - flag indicating LP or CLDFB based SID/CNG */
+
+ int16_t last_vad;
+
+ int32_t last_active_brate; /* DTX/CNG - last active frame bitrate used for CNG_mode control */
+ Word32 last_active_brate_fx; /* DTX/CNG - last active frame bitrate used for CNG_mode control */
+
+ int16_t last_CNG_L_frame; /* DTX/CNG - last CNG frame length */
+ Word16 last_CNG_L_frame_fx; /* DTX/CNG - last CNG frame length */
int16_t CNG_mode; /* DTX/CNG - mode for DTX configuration */
- float lspCNG[M]; /* DTX/CNG - LP filtered ISPs */
+ Word16 CNG_mode_fx; /* DTX/CNG - mode for DTX configuration */
+
+ float lspCNG[M]; /* DTX/CNG - LP filtered ISPs */
+ Word16 lspCNG_fx[M]; /* CNG and DTX - LP filtered ISPs Q15*/
+
+ int16_t active_cnt;
TD_CNG_DEC_HANDLE hTdCngDec;
int16_t masa_sid_format;
@@ -1816,19 +2023,35 @@ typedef struct Decoder_State
SC_VBR_DEC_HANDLE hSC_VBR;
int16_t last_ppp_mode_dec;
- int16_t ppp_mode_dec;
- int16_t last_nelp_mode_dec;
- int16_t nelp_mode_dec;
- float prev_gain_pit_dec;
- float prev_tilt_code_dec;
- int16_t vbr_hw_BWE_disable_dec;
- int16_t last_vbr_hw_BWE_disable_dec;
+ Word16 last_ppp_mode_dec_fx; /*Q0*/
+
+ int16_t ppp_mode_dec;
+ Word16 ppp_mode_dec_fx; /*Q0*/
+
+ int16_t last_nelp_mode_dec;
+ Word16 last_nelp_mode_dec_fx;
+
+ int16_t nelp_mode_dec;
+ Word16 nelp_mode_dec_fx; /* Q0 */
+
+ float prev_gain_pit_dec;
+ Word16 prev_gain_pit_dec_fx; /*Q14*/
+
+ float prev_tilt_code_dec;
+ Word16 prev_tilt_code_dec_fx; /*Q15*/
+
+ int16_t vbr_hw_BWE_disable_dec;
+ Word16 vbr_hw_BWE_disable_dec_fx;
+
+ int16_t last_vbr_hw_BWE_disable_dec;
+ Word16 last_vbr_hw_BWE_disable_dec_fx;
/*----------------------------------------------------------------------------------*
* channel-aware mode
*----------------------------------------------------------------------------------*/
float tilt_code_dec[NB_SUBFR16k];
+ Word16 tilt_code_dec_fx[NB_SUBFR16k];
int16_t rf_frame_type;
int16_t use_partial_copy;
@@ -1851,6 +2074,7 @@ typedef struct Decoder_State
*----------------------------------------------------------------------------------*/
HR_BWE_DEC_HANDLE hBWE_FD_HR;
+ Word16 Qprev_synth_buffer_fx;
/*----------------------------------------------------------------------------------*
* HQ core parameters
@@ -1859,17 +2083,33 @@ typedef struct Decoder_State
HQ_DEC_HANDLE hHQ_core;
int16_t last_core;
- int16_t last_core_from_bs; /* last frame core as coded in TCX bitstream */
+ Word16 last_core_fx; /*Q0*/
+
+ int16_t last_core_from_bs; /* last frame core as coded in TCX bitstream */
+ Word16 last_core_bs_fx;
int16_t last_L_frame_ori;
- float previoussynth[L_FRAME48k]; /* note: only 60+111 out of 960 samples are needed in IVAS (for ACELP->TCX switching */
- float old_synth_sw[NS2SA( 48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS )]; /* note: buffer used only in EVS mono */
- float delay_buf_out[HQ_DELTA_MAX * HQ_DELAY_COMP];
+ Word16 last_L_frame_ori_fx;
+
+ float previoussynth[L_FRAME48k]; /* note: only 60+111 out of 960 samples are needed in IVAS (for ACELP->TCX switching */
+ Word16 previoussynth_fx[L_FRAME48k];
+
+ float old_synth_sw[NS2SA( 48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS )]; /* note: buffer used only in EVS mono */
+ Word16 old_synth_sw_fx[NS2SA(48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS)];
+
+ float delay_buf_out[HQ_DELTA_MAX * HQ_DELAY_COMP];
+ Word16 delay_buf_out_fx[HQ_DELTA_MAX * HQ_DELAY_COMP]; /*Q0*/
float old_Aq_12_8[M + 1]; /* old Aq[] for core switching */
- float old_Es_pred; /* old Es_pred for core switching */
+ Word16 old_Aq_12_8_fx[M + 1]; /* Q12 old Aq[] for core switching */
+
+ float old_Es_pred; /* old Es_pred for core switching */
+ Word16 old_Es_pred_fx; /* old Es_pred for core switching */
- HQ_NBFEC_HANDLE hHQ_nbfec;
+ Word16 old_bfi_cnt_fx; /* HQ core - # of bfi until previous frame(for FEC) */
+ Word16 prev_old_bfi_fx;
+
+ HQ_NBFEC_HANDLE hHQ_nbfec;
/*----------------------------------------------------------------------------------*
* TBE parameters
@@ -1878,30 +2118,110 @@ typedef struct Decoder_State
TD_BWE_DEC_HANDLE hBWE_TD;
int16_t old_bwe_delay;
- float hb_prev_synth_buffer[NS2SA( 48000, DELAY_BWE_TOTAL_NS )];
-
- /* WB/SWB bandwidth switching */
+ Word16 old_bwe_delay_fx; /*Q0*/
+
+ float hb_prev_synth_buffer[NS2SA( 48000, DELAY_BWE_TOTAL_NS )];
+ Word16 hb_prev_synth_buffer_fx[NS2SA(48000, DELAY_BWE_TOTAL_NS)];
+
+ /* WB/SWB bandwidth switching */
float tilt_wb;
- float tilt_swb;
- float prev_ener_shb;
- float enerLH;
- float prev_enerLH;
+ Word16 tilt_wb_fx;
+
+ float tilt_swb;
+ Word16 tilt_swb_fx;
+
+ float prev_ener_shb;
+ Word16 prev_ener_shb_fx;
+
+ float enerLH;
+ Word32 enerLH_fx;
+
+ float prev_enerLH;
+ Word32 prev_enerLH_fx;
+
float enerLL;
- float prev_enerLL;
- int16_t prev_fractive;
- int16_t prev_bws_cnt;
- int16_t bws_cnt;
- int16_t bws_cnt1;
- float attenu1;
- int16_t last_inner_frame;
- int16_t last_bwidth;
- float t_audio_q[L_FRAME];
+ Word32 enerLL_fx;
+
+ float prev_enerLL;
+ Word32 prev_enerLL_fx;
+
+ int16_t prev_fractive;
+ Word16 prev_fractive_fx;
+
+ int16_t prev_bws_cnt;
+ Word16 prev_bws_cnt_fx;
+
+ int16_t bws_cnt;
+ Word16 bws_cnt_fx;
+
+ int16_t bws_cnt1;
+ Word16 bws_cnt1_fx;
+
+ float attenu1;
+ Word16 attenu_fx;
+
+ int16_t last_inner_frame;
+ Word16 last_inner_frame_fx; /* (HQ_CORE) DCT length */
+
+ int16_t last_bwidth;
+ Word16 last_bwidth_fx;
+
+ float t_audio_q[L_FRAME];
+ Word16 t_audio_q_fx[L_FRAME];
+
+ Word16 interpol_3_2_cng_dec_fx[INTERP_3_2_MEM_LEN];
+
+ /*----------------------------------------------------------------------------------*
+ * Fixed point only
+ *----------------------------------------------------------------------------------*/
+ Word16 Q_exc;
+ Word16 prev_Q_exc;
+ Word16 Q_subfr[L_Q_MEM];
+
+ Word16 prev_Q_bwe_syn;
+ Word16 prev_Q_bwe_syn2;
+
+ Word16 prev_Q_bwe_exc_fb;
+ Word16 prev_Qx;
+ Word16 prev_Q_bwe_exc;
+ Word16 prev_Q_synth;
+ Word16 prev_SWB_fenv_fx[SWB_FENV];
+
+ Word16 Q_syn2;
+ Word16 Q_syn;
+ Word16 prev_Q_syn;
+ Word16 prev_frame_pow_exp;
+ Word16 prev_ener_fx_Q;
+ Word16 last_wb_bwe_ener_fx;
+ Word16 prev_fb_ener_adjust_fx;
+
+ Word16 prev_synth_buffer_fx[NS2SA(48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS)];
+ Word16 GainShape_Delay[NUM_SHB_SUBFR / 2];
+ Word16 prev_lpc_wb_fx[LPC_SHB_ORDER_WB];
/*----------------------------------------------------------------------------------*
* SWB BWE structure
*----------------------------------------------------------------------------------*/
FD_BWE_DEC_HANDLE hBWE_FD;
+ Word16 prev_coder_type_fx;
+
+ /*----------------------------------------------------------------------------------*
+ * SWB DTX/CNG parameters
+ *----------------------------------------------------------------------------------*/
+
+ Word16 shb_cng_ener_fx;
+ Word16 wb_cng_ener_fx;
+ Word16 last_wb_cng_ener_fx;
+ Word16 last_shb_cng_ener_fx;
+ Word16 swb_cng_seed_fx;
+ Word16 lsp_shb_prev_prev_fx[LPC_SHB_ORDER];
+ Word16 lsp_shb_prev_fx[LPC_SHB_ORDER];
+ Word16 shb_dtx_count_fx;
+ Word16 last_vad_fx;
+ Word16 trans_cnt_fx;
+ //Word16 burst_cnt_fx;
+ Word16 last_shb_ener_fx;
/*----------------------------------------------------------------------------------*
* LD music post-filter
@@ -1920,6 +2240,9 @@ typedef struct Decoder_State
TCX_DEC_HANDLE hTcxDec;
+ Word32 lp_error_ener;
+ Word32 mem_error;
+
/*----------------------------------------------------------------------------------*
* Mode 2
*----------------------------------------------------------------------------------*/
@@ -1934,32 +2257,70 @@ typedef struct Decoder_State
int16_t bits_frame_core; /* bit per frame for the core */
int16_t narrowBand;
+ Word16 bits_common; /* read bits from header and LPC*/
+
int16_t last_is_cng;
float *acelp_zir;
- float syn[M + 1];
+
+ float syn_float[M + 1];
+ Word16 syn[M + 1];
int16_t bpf_gain_param; /* bass post-filter gain factor parameter (0->noBpf)*/
int16_t L_frame_past;
int16_t L_frameTCX_past;
- float lsfold_uw[M]; /* old lsf (unweighted) */
- float lspold_uw[M]; /* old lsp (unweighted) */
- int16_t seed_tcx_plc; /* seed memory (for random function in TCX PLC) */
- float past_gpit; /* past gain of pitch (for frame recovery) */
- float past_gcode; /* past energy (!) of code (for frame recovery) */
- float lsf_cng[M]; /* lsf coefficients used for CNG generation (long term) */
- float lspold_cng[M]; /* lsp coefficients used for CNG generation (long term) */
- float lsp_q_cng[M]; /* lsp coefficients used for CNG generation (short term interpolated) */
- float old_lsp_q_cng[M]; /* lsp coefficients used for CNG generation (short term interpolated) */
- float lsf_q_cng[M]; /* lsf coefficients used for CNG generation (short term interpolated) */
- float old_lsf_q_cng[M]; /* lsf: old quantized lsfs for background noise */
- float Aq_cng[( NB_SUBFR16k + 1 ) * ( M + 1 )]; /* LPC coefficients derived from CNG estimate */
- float mem_syn_unv_back[M]; /* filter memory for unvoiced synth */
- int16_t plcBackgroundNoiseUpdated; /* flag: Is background noise estimate updated? */
- float last_gain_syn_deemph;
- float last_concealed_gain_syn_deemph;
+ float lsfold_uw_float[M]; /* old lsf (unweighted) */
+ Word16 lsfold_uw[M]; /* old lsf (unweighted) */
+
+ float lspold_uw_float[M]; /* old lsp (unweighted) */
+ Word16 lspold_uw[M]; /* old lsp (unweighted) */
+
+ int16_t seed_tcx_plc; /* seed memory (for random function in TCX PLC) */
+
+ float past_gpit_float; /* past gain of pitch (for frame recovery) */
+ Word16 past_gpit; /* past gain of pitch (for frame recovery) */
+
+ float past_gcode_float; /* past energy (!) of code (for frame recovery) */
+ Word32 past_gcode; /* past energy (!) of code (for frame recovery) */ /*15Q16*/
+
+ float lsf_cng_float[M]; /* lsf coefficients used for CNG generation (long term) */
+ Word16 lsf_cng[M]; /* xSF coefficients used for CNG generation (long term) */
+
+ float lspold_cng_float[M]; /* lsp coefficients used for CNG generation (long term) */
+ Word16 lspold_cng[M]; /* xSP coefficients used for CNG generation (long term) */
+
+ float lsp_q_cng_float[M]; /* lsp coefficients used for CNG generation (short term interpolated) */
+ Word16 lsp_q_cng[M]; /* xSP coefficients used for CNG generation (short term interpolated) */
+
+ float old_lsp_q_cng_float[M]; /* lsp coefficients used for CNG generation (short term interpolated) */
+ Word16 old_lsp_q_cng[M]; /* xSP coefficients used for CNG generation (short term interpolated) */
+
+ float lsf_q_cng_float[M]; /* lsf coefficients used for CNG generation (short term interpolated) */
+ Word16 lsf_q_cng[M]; /* xSF coefficients used for CNG generation (short term interpolated) */
+
+ float old_lsf_q_cng_float[M]; /* lsf: old quantized lsfs for background noise */
+ Word16 old_lsf_q_cng[M]; /* xSF: old quantized lsfs for background noise */
+
+ float Aq_cng_float[( NB_SUBFR16k + 1 ) * ( M + 1 )]; /* LPC coefficients derived from CNG estimate */
+ Word16 Aq_cng[(NB_SUBFR16k + 1)*(M + 1)]; /* LPC coefficients derived from CNG estimate */
+
+ float mem_syn_unv_back_float[M]; /* filter memory for unvoiced synth */
+ Word16 mem_syn_unv_back[M]; /* filter memory for unvoiced synth */
+
+ int16_t plcBackgroundNoiseUpdated; /* flag: Is background noise estimate updated? */
+
+ float last_gain_syn_deemph_float;
+ Word16 last_gain_syn_deemph; /*Q15*/
+
+ Word16 last_gain_syn_deemph_e;
+
+ float last_concealed_gain_syn_deemph_float;
+ Word16 last_concealed_gain_syn_deemph; /*Q15*/
+
+ Word16 last_concealed_gain_syn_deemph_e;
+
/* variables for framing */
int16_t nb_subfr;
@@ -1977,40 +2338,73 @@ typedef struct Decoder_State
int16_t pit_res_max_past;
/*Preemphasis factor*/
- float preemph_fac;
- float gamma;
+ float preemph_fac_float;
+ Word16 preemph_fac; /*0Q15*/
+
+ float gamma_float;
+ Word16 gamma;
+
+ Word16 inv_gamma;
/*for AMR-WB like 6.4 to 7 kHz upsampling and noise filling*/
- float mem_Aq[NB_SUBFR16k * ( M + 1 )];
+ float mem_Aq_float[NB_SUBFR16k * ( M + 1 )];
+ Word16 mem_Aq[(NB_SUBFR16k)*(M + 1)]; /* Q12 */
/* Error concealment */
int16_t last_core_bfi; /* PLC - mode in previous frame */
int16_t nbLostCmpt; /* PLC - compt for number of consecutive lost frame */
- float old_fpitch; /* PLC - last pitch of previous frame (as transmitted) */
- float old_fpitchFB; /* PLC - last pitch of previous FB frame (depends on output sr) */
- int16_t clas_dec; /* PLC - frame class at the decoder */
- float mem_pitch_gain[2 * NB_SUBFR16k + 2]; /* PLC - Pitch gain memory */
- int16_t plc_use_future_lag; /* PLC - flag indicating if info (pitch lag / pitch gain) about future frame is usable */
+ float old_fpitch_float; /* PLC - last pitch of previous frame (as transmitted) */
+ Word32 old_fpitch; /* last pitch of previous frame */ /*15Q16*/
+
+ float old_fpitchFB_float; /* PLC - last pitch of previous FB frame (depends on output sr) */
+ Word32 old_fpitchFB; /* PLC - last pitch of previous FB frame (depends on output sr) */ /*15Q16*/
+
+ int16_t clas_dec; /* PLC - frame class at the decoder */
+
+ float mem_pitch_gain_float[2 * NB_SUBFR16k + 2]; /* PLC - Pitch gain memory */
+ Word16 mem_pitch_gain[2 * NB_SUBFR16k + 2]; /* Pitch gain memory Q14 */
+
+ int16_t plc_use_future_lag; /* PLC - flag indicating if info (pitch lag / pitch gain) about future frame is usable */
+
+ Word32 Mode2_lp_gainc; /* 15Q16 low passed code gain used for concealment*/
+ Word32 Mode2_lp_gainp; /* 15Q16 low passed pitch gain used for concealment*/
+
+
+ float cummulative_damping_float;
+ Word16 cummulative_damping; /*Q15*/
+
+ float cngTDLevel_float;
+ Word16 cngTDLevel;
+
+ Word16 cngTDLevel_e;
+
+ Word16 prev_widow_left_rect;
+
+ int16_t reset_mem_AR;
+
+ Word16 classifier_Q_mem_syn; /*scalingfactor of mem_syn_clas_estim_fx in MODE2 */
- float cummulative_damping;
- float cngTDLevel;
- int16_t reset_mem_AR;
int16_t rate_switching_init;
+
/* LPC quantization */
int16_t lpcQuantization;
int16_t numlpc;
/* Bandwidth */
- float TcxBandwidth;
+ float TcxBandwidth_float;
+ Word16 TcxBandwidth;
- float voice_fac;
+ float voice_fac_float;
+ Word16 voice_fac;
int16_t tcxonly;
int16_t last_ctx_hm_enabled;
+ struct tonalmdctconceal tonalMDCTconceal;
+
TonalMDCTConcealPtr hTonalMDCTConc;
int16_t tonal_mdct_plc_active;
int16_t last_tns_active;
@@ -2018,11 +2412,16 @@ typedef struct Decoder_State
int16_t second_last_core;
/* parameters for switching */
- float mem_syn_r[L_SYN_MEM]; /*LPC synthesis memory needed for rate switching*/
- int16_t rate_switching_reset;
+ float mem_syn_r_float[L_SYN_MEM]; /*LPC synthesis memory needed for rate switching*/
+ Word16 mem_syn_r[L_SYN_MEM]; /*LPC synthesis memory needed for rate switching*/
+
+ int16_t rate_switching_reset;
- float bpf_noise_buf[L_FRAME16k];
- float *p_bpf_noise_buf;
+ float bpf_noise_buf_float[L_FRAME16k];
+ Word16 bpf_noise_buf[L_FRAME_16k];
+
+ float *p_bpf_noise_buf_float;
+ Word16 *p_bpf_noise_buf;
int16_t enableGplc;
int16_t flagGuidedAcelp;
@@ -2032,14 +2431,16 @@ typedef struct Decoder_State
int16_t enablePlcWaveadjust;
int16_t tonality_flag;
T_PLCInfo_HANDLE hPlcInfo;
+ T_PLCInfo plcInfo;
int16_t VAD;
int16_t flag_cna;
int16_t last_flag_cna;
- float lp_noise;
-
- int16_t seed_acelp;
+ float lp_noise_float;
+ Word32 lp_noise;
+
+ int16_t seed_acelp;
int16_t core_ext_mode; /*GC,VC,UC,TC: core extended mode used for PLC or Acelp-external modules.*/
int16_t dec_glr;
@@ -2050,9 +2451,14 @@ typedef struct Decoder_State
uint8_t m_old_frame_type; /*ZERO_FRAME/SID_FRAME/ACTIVE_FRAME*/
int16_t old_ppp_mode;
+ Word16 old_ppp_mode_fx;
+
int16_t con_tcx;
int16_t last_con_tcx;
+ Word16 prev_Q_exc_fr;
+ Word16 prev_Q_syn_fr;
+
int16_t writeFECoffset;
/*----------------------------------------------------------------------------------*
@@ -2060,6 +2466,7 @@ typedef struct Decoder_State
*----------------------------------------------------------------------------------*/
HANDLE_FD_CNG_DEC hFdCngDec;
+ HANDLE_FD_CNG_DEC hFdCngDec_fx;
/*----------------------------------------------------------------------------------*
* IGF
@@ -2067,7 +2474,9 @@ typedef struct Decoder_State
IGF_DEC_INSTANCE_HANDLE hIGFDec;
int16_t igf;
+ CLDFB_SCALE_FACTOR scaleFactor;
+ TEMPORAL_ENVELOPE_CODING_DECODER_FX tecDec_fx;
/*----------------------------------------------------------------------------------*
* TEC
*----------------------------------------------------------------------------------*/
@@ -2086,523 +2495,19 @@ typedef struct Decoder_State
int16_t cng_sba_flag; /* CNG in SBA flag */
/* MCT Channel mode indication: LFE, ignore channel? */
+ //note_ : one extra value in evs ivas macro code
MCT_CHAN_MODE mct_chan_mode;
int16_t cng_ism_flag; /* CNG in ISM format flag */
int16_t is_ism_format; /* Indication whether the codec operates in ISM format */
-} Decoder_State, *DEC_CORE_HANDLE_FLOAT;
-
-typedef struct Decoder_State_fx
-{
-
- /*----------------------------------------------------------------------------------*
- * Common parameters
- *----------------------------------------------------------------------------------*/
- Word16 codec_mode; /* MODE1 or MODE2 */
- Word16 mdct_sw_enable; /* MDCT switching enable flag */
- Word16 mdct_sw; /* MDCT switching indicator */
- Word16 last_codec_mode; /* last used codec mode*/
- UWord16 *bit_stream_fx;
- Word16 next_bit_pos_fx; /* position of the next bit to be read from the bitstream */
- Word16 bitstreamformat; /* Bitstream format flag (G.192/MIME/VOIP_G192_RTP/VOIP_RTPDUMP) */
- Word16 sdp_hf_only; /* RTP payload format parameter: only Header-Full format without zero padding for size collision avoidance */
- Word16 amrwb_rfc4867_flag; /* MIME from rfc4867 is used */
- Word16 total_num_bits; /* == st->total_brate / 50 */
- Word16 BER_detect; /* flag to signal detected bit error in the bitstream */
-
- Word32 output_Fs_fx; /* output sampling rate Q0*/
- Word16 output_frame_fx; /* Output frame length Q0*/
- Word32 total_brate_fx; /* total bitrate in kbps of the codec Q0*/
- Word32 last_total_brate_fx; /* last total bitrate in kbps of the codec Q0*/
- Word32 last_total_brate_ber_fx; /* last total bitrate in kbps of the codec - used only when first frame is lost and BER is detected afterwards */
- Word16 core_fx; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */
- Word32 core_brate_fx; /* core bitrate */
- Word32 last_core_brate_fx; /* previous frame core bitrate Q0*/
- Word16 extl_fx; /* extension layer Q0*/
- Word16 last_extl_fx; /* previous extension layer Q0*/
- Word32 extl_brate_fx; /* extension layer bitrate */
- Word16 L_frame_fx; /* ACELP core internal frame length */
- Word16 bwidth_fx; /* encoded signal bandwidth */
- Word16 Opt_AMR_WB_fx; /* flag indicating AMR-WB IO mode Q0*/
- Word16 Opt_VOIP_fx; /* flag indicating VOIP mode with JBM */
- Word16 ini_frame_fx; /* initialization frames counter */
- Word16 CNG_fx; /* RXDTX handler: CNG=1, nonCNG=0 */
- Word16 prev_ft_speech_fx; /* RXDTX handler: previous frametype flag for G.192 format AMRWB SID_FIRST detection */
-
- /*----------------------------------------------------------------------------------*
- * ACELP core parameters
- *----------------------------------------------------------------------------------*/
-
- Word16 old_exc_fx[L_EXC_MEM_DEC]; /* old excitation Q_exc*/
- Word16 lsp_old_fx[M]; /* old LSP vector at the end of the frame Q15*/
- Word16 lsf_old_fx[M]; /* old LSF vector at the end of the frame Q2.56*/
- Word32 offset_scale1_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 1st 8-dim subvector*/
- Word32 offset_scale2_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 2nd 8-dim subvector*/
- Word32 offset_scale1_p_fx[MAX_NO_MODES_p + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure, pred. case, 1st 8-dim subvector*/
- Word32 offset_scale2_p_fx[MAX_NO_MODES_p + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure, pred. case, 2nd 8-dim subvector*/
- Word16 no_scales_fx[MAX_NO_MODES][2]; /* LSF LVQ structure Q0*/
- Word16 no_scales_p_fx[MAX_NO_MODES_p][2]; /* LSF LVQ structure Q0*/
- Word16 tilt_code_fx; /* tilt of code Q15*/
- Word16 mem_syn2_fx[M]; /* synthesis filter memory Q_syn*/
- Word16 mem_syn1_fx[M]; /* synthesis filter memory (for core switching and FD BWE) */
- Word16 mem_syn3_fx[M];
- Word16 mem_deemph_fx; /* deemphasis filter memory Q_syn*/
- Word32 L_mem_hp_out_fx[5]; /* hp filter memory for synthesis */
- Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual)(Qx2.56)*/
- Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean)(Qx2.56) */
- Word16 stab_fac_fx; /* LSF stability factor Q15*/
- Word16 stab_fac_smooth_fx; /* low-pass filtered stability factor Q15*/
- Word16 last_coder_type_fx; /* previous coder type Q0*/
- Word16 agc_mem_fx[2]; /* memory of AGC for saturation control Q0*/
- Word16 mid_lsf_int_fx;
- Word16 safety_net_fx;
-
- GSC_DEC_HANDLE hGSCDec;
- Word16 GSC_IVAS_mode; /* AC mode (GSC) - GSC IVAS mode */
-
- Word16 Last_GSC_noisy_speech_flag_fx; /* AC mode (GSC) - mem of the past flag to indicate GSC osn SWB noisy speech */
- Word16 GSC_noisy_speech_fx; /* AC mode (GSC) - flag to indicate GSC osn SWB noisy speech */
-
- Word32 gc_threshold_fx; /* Noise enhancer - threshold for gain_code Q16*/
- struct dispMem_fx dm_fx; /* Noise enhancer - phase dispersion algorithm memory */
-
- ZERO_BWE_DEC_HANDLE hBWE_zero; /* HF (6-7kHz) BWE */
-
- Word16 unv_cnt_fx; /* Stationary noise UV modification - unvoiced frame counter Q0*/
- Word16 uv_count_fx; /* Stationary noise UV modification - unvoiced counter Q0*/
- Word16 act_count_fx; /* Stationary noise UV modification - activation counter Q0*/
- Word32 ge_sm_fx; /* Stationary noise UV modification - smoothed excitation gain Q(GE_SHIFT)*/
- Word16 lspold_s_fx[M]; /* Stationary noise UV modification - old LSP vector Q15*/
- Word16 noimix_seed_fx; /* Stationary noise UV modification - mixture seed Q0*/
- Word16 min_alpha_fx; /* Stationary noise UV modification - minimum alpha Q15*/
- Word16 Q_stat_noise; /* Q of Exc_pe */
- Word16 exc_pe_fx; /* Stationary noise UV modification - scale (Q_stat_noise) */
- Word16 Q_stat_noise_ge; /* Q of ge_sm_fx */
-
- Word16 bfi_fx; /* FEC - bad frame indicator */
- Word16 prev_bfi_fx; /* FEC - previous bad frame indicator Q0*/
- Word16 seed_fx; /* FEC - seed for random generator for excitation Q0*/
- Word16 lp_ener_FER_fx; /* FEC - long-term active-signal average energy Q8*/
- Word16 last_good_fx; /* FEC - clas of last good received Q0*/
- Word16 lp_gainc_fx; /* FEC - low-pass filtered code gain Q3*/
- Word16 lp_gainp_fx; /* FEC - low-pass filtered pitch gain Q14 */
- Word32 lp_ener_fx; /* FEC - low-pass filtered energy Q6*/
- Word32 enr_old_fx; /* FEC - energy of the concealed frame Q0*/
- Word16 bfi_pitch_fx; /* FEC - pitch for FEC */
- Word16 bfi_pitch_frame_fx; /*FEC - frame length when pitch for FEC is saved Q0*/
- Word32 old_pitch_buf_fx[2 * NB_SUBFR16k + 2]; /* FEC - buffer of old subframe pitch values 15Q16 */
- Word16 upd_cnt_fx; /* FEC - counter of frames since last update Q0*/
- Word16 scaling_flag; /* FEC - flag to indicate energy control of syn */
- Word32 lp_ener_FEC_av; /* FEC - averaged voiced signal energy Q0 */
- Word32 lp_ener_FEC_max; /* FEC - averaged voiced signal energy Q0 */
- Word16 old_enr_LP; /* FEC - LP filter gain Q5*/
- Word16 lsfoldbfi0_fx[M]; /* FEC - LSF vector of the previous frame (Qx2.56)*/
- Word16 lsfoldbfi1_fx[M]; /* FEC - LSF vector of the past previous frame (Qx2.56) */
- Word16 lsf_adaptive_mean_fx[M]; /* FEC - adaptive mean LSF vector for FEC (Qx2.56)*/
- Word16 decision_hyst_fx; /* FEC - hysteresis of the music/speech decision Q0*/
-
- WI_DEC_HANDLE hWIDec;
- Word16 relax_prev_lsf_interp_fx;
- Word16 mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM]; /* FEC - memory of the synthesis signal for frame class estimation */
- /*----------------------------------------------------------------------------------*
- * DTX and TD CNG parameters
- *----------------------------------------------------------------------------------*/
- Word16 first_CNG_fx; /* CNG and DTX - first CNG frame flag Q0*/
- Word16 cng_type_fx; /* DTX/CNG - flag indicating LP or CLDFB based SID/CNG */
- Word16 last_CNG_L_frame_fx; /* DTX/CNG - last CNG frame length */
- Word32 last_active_brate_fx; /* DTX/CNG - last active frame bitrate used for CNG_mode control */
- Word16 CNG_mode_fx; /* DTX/CNG - mode for DTX configuration */
- Word16 lspCNG_fx[M]; /* CNG and DTX - LP filtered ISPs Q15*/
- Word16 active_cnt;
-
- TD_CNG_DEC_HANDLE hTdCngDec;
- Word16 bpf_off_fx; /* Bass post-filter - do not use BPF when this flag is set to 1 Q0*/
- BPF_DEC_HANDLE hBPF; /* Bass post-filter handle */
- Word16 Ng_ener_ST_fx; /* Noise gate - short-term energy Q8*/
-
- Word16 last_L_frame_fx; /* ACELP@16kHz - last value of st->L_frame */
- Word16 mem_preemp_preQ_fx; /* ACELP@16kHz - prequantizer preemhasis memory */
- Word16 last_nq_preQ_fx; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */
- Word16 use_acelp_preq; /* ACELP@16kHz - flag of prequantizer usage */
-
- AMRWB_IO_DEC_HANDLE hAmrwb_IO;
-
- SC_VBR_DEC_HANDLE hSC_VBR;
- /*----------------------------------------------------------------------------------*
- * SC-VBR
- *----------------------------------------------------------------------------------*/
- Word16 last_ppp_mode_dec_fx; /*Q0*/
- Word16 ppp_mode_dec_fx; /*Q0*/
- Word16 last_nelp_mode_dec_fx;
- Word16 nelp_mode_dec_fx; /* Q0 */
- Word16 prev_gain_pit_dec_fx; /*Q14*/
- Word16 prev_tilt_code_dec_fx; /*Q15*/
- Word16 vbr_hw_BWE_disable_dec_fx;
- Word16 last_vbr_hw_BWE_disable_dec_fx;
-
- /*----------------------------------------------------------------------------------*
- * channel-aware mode
- *----------------------------------------------------------------------------------*/
-
- Word16 tilt_code_dec_fx[NB_SUBFR16k];
- Word16 rf_frame_type;
- Word16 use_partial_copy;
- Word16 prev_use_partial_copy;
- Word16 rf_flag;
- Word16 rf_flag_last;
-
- Word16 rf_fec_offset;
- Word16 next_coder_type;
- Word16 prev_rf_frame_type;
- Word16 rf_target_bits;
-
- Word16 rf_indx_nelp_fid;
- Word16 rf_indx_nelp_iG1;
- Word16 rf_indx_nelp_iG2[2];
- Word16 rf_indx_tbeGainFr;
-
- /*----------------------------------------------------------------------------------*
- * HR SWB BWE parameters
- *----------------------------------------------------------------------------------*/
- HR_BWE_DEC_HANDLE hBWE_FD_HR;
- Word16 Qprev_synth_buffer_fx;
-
- /*----------------------------------------------------------------------------------*
- * HQ core parameters
- *----------------------------------------------------------------------------------*/
- Word16 last_core_fx; /*Q0*/
- Word16 last_core_bs_fx;
- Word16 last_L_frame_ori_fx;
- Word16 previoussynth_fx[L_FRAME48k];
- Word16 old_synth_sw_fx[NS2SA(48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS)];
- Word16 delay_buf_out_fx[HQ_DELTA_MAX * HQ_DELAY_COMP]; /*Q0*/
- Word16 old_Aq_12_8_fx[M + 1]; /* Q12 old Aq[] for core switching */
- Word16 old_Es_pred_fx; /* old Es_pred for core switching */
-
- HQ_DEC_HANDLE hHQ_core;
-
- /*----------------------------------------------------------------------------------*
- * HQ FEC
- *----------------------------------------------------------------------------------*/
-
- Word16 old_bfi_cnt_fx; /* HQ core - # of bfi until previous frame(for FEC) */
- Word16 prev_old_bfi_fx;
- HQ_NBFEC_HANDLE hHQ_nbfec;
-
- /*----------------------------------------------------------------------------------*
- * TBE parameters
- *----------------------------------------------------------------------------------*/
- TD_BWE_DEC_HANDLE hBWE_TD;
- Word16 hb_prev_synth_buffer_fx[NS2SA(48000, DELAY_BWE_TOTAL_NS)];
- Word16 old_bwe_delay_fx; /*Q0*/
-
- /* WB/SWB bandwidth switching */
- Word16 tilt_wb_fx;
- Word16 tilt_swb_fx;
- Word16 prev_ener_shb_fx;
- Word32 enerLH_fx;
- Word32 prev_enerLH_fx;
- Word32 enerLL_fx;
- Word32 prev_enerLL_fx;
-
- Word16 prev_fractive_fx;
- Word16 prev_bws_cnt_fx;
- Word16 bws_cnt_fx;
- Word16 bws_cnt1_fx;
- Word16 attenu_fx;
- Word16 last_inner_frame_fx; /* (HQ_CORE) DCT length */
- Word16 last_bwidth_fx;
- Word16 t_audio_q_fx[L_FRAME];
-
-
- Word16 interpol_3_2_cng_dec_fx[INTERP_3_2_MEM_LEN];
-
- /*----------------------------------------------------------------------------------*
- * SWB BWE parameters
- *----------------------------------------------------------------------------------*/
- FD_BWE_DEC_HANDLE hBWE_FD;
- Word16 prev_coder_type_fx;
- /*----------------------------------------------------------------------------------*
- * SWB DTX/CNG parameters
- *----------------------------------------------------------------------------------*/
-
- Word16 shb_cng_ener_fx;
- Word16 wb_cng_ener_fx;
- Word16 last_wb_cng_ener_fx;
- Word16 last_shb_cng_ener_fx;
- Word16 swb_cng_seed_fx;
- Word16 lsp_shb_prev_prev_fx[LPC_SHB_ORDER];
- Word16 lsp_shb_prev_fx[LPC_SHB_ORDER];
- Word16 shb_dtx_count_fx;
- Word16 last_vad_fx;
- Word16 trans_cnt_fx;
- //Word16 burst_cnt_fx;
- Word16 last_shb_ener_fx;
-
-
- /*----------------------------------------------------------------------------------*
- * LD music post-filter
- *----------------------------------------------------------------------------------*/
- MUSIC_POSTFILT_HANDLE hMusicPF;
-
- /*----------------------------------------------------------------------------------*
- * Fixed point only
- *----------------------------------------------------------------------------------*/
- Word16 Q_exc;
- Word16 prev_Q_exc;
- Word16 Q_subfr[L_Q_MEM];
-
- Word16 prev_Q_bwe_syn;
- Word16 prev_Q_bwe_syn2;
-
- Word16 prev_Q_bwe_exc_fb;
- Word16 prev_Qx;
- Word16 prev_Q_bwe_exc;
- Word16 prev_Q_synth;
- Word16 prev_SWB_fenv_fx[SWB_FENV];
-
- Word16 Q_syn2;
- Word16 Q_syn;
- Word16 prev_Q_syn;
- Word16 prev_frame_pow_exp;
- Word16 prev_ener_fx_Q;
- Word16 last_wb_bwe_ener_fx;
- Word16 prev_fb_ener_adjust_fx;
-
- Word16 prev_synth_buffer_fx[NS2SA(48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS)];
- Word16 prev_lpc_wb_fx[LPC_SHB_ORDER_WB];
- Word16 GainShape_Delay[NUM_SHB_SUBFR / 2];
-
- HANDLE_CLDFB_FILTER_BANK cldfbAna_fx; /* main analysis filter bank handle */
- HANDLE_CLDFB_FILTER_BANK cldfbBPF_fx; /* BPF analysis filter bank handle */
- HANDLE_CLDFB_FILTER_BANK cldfbSyn_fx; /* main synthesis filter bank handle */
-
- Word16 last_active_bandsToZero_bwdec;
- Word16 last_flag_filter_NB;
- Word16 perc_bwddec; /*Q14*/
- Word16 active_frame_cnt_bwddec;
- Word16 flag_buffer[20];
- Word16 total_frame_cnt_bwddec;
- Word32 avg_nrg_LT;
- /*Frequency-domain-based CNG*/
- HANDLE_FD_CNG_DEC hFdCngDec_fx;
-
- /*ACELP config*/
- Word16 force_lpd_reset;
- ACELP_config acelp_cfg; /*configuration set for each frame*/
-
- ACELP_config acelp_cfg_rf; /* configuration for RF frame */
-
- TCX_CONFIG_HANDLE hTcxCfg; /* TCX config */
-
- /* evs decoder */
- Word16 m_decodeMode;
- Word16 m_frame_type; /*ZERO_FRAME/SID_FRAME/ACTIVE_FRAME*/
- Word16 m_old_frame_type; /*ZERO_FRAME/SID_FRAME/ACTIVE_FRAME*/
-
-
- /*dec_prm.c*/
- Word16 bits_frame; /* bit per frame overall included */
- Word16 bits_frame_core; /* bit per frame for the core */
- Word8 narrowBand;
- Word16 bits_common; /* read bits from header and LPC*/
-
- Word8 last_is_cng;
-
-
- Word16 syn[M + 1];
-
- /* bass_pf.c */
- Word16 bpf_gain_param; /*int*/ /* bass post-filter gain factor parameter (0->noBpf)*/
-
- Word16 L_frame_past;
- Word16 L_frameTCX_past;
-
- Word16 lsfold_uw[M]; /* old lsf (unweighted) */
- Word16 lspold_uw[M]; /* old lsp (unweighted) */
- Word16 seed_tcx_plc; /* seed memory (for random function in TCX PLC) */
- Word16 past_gpit; /* past gain of pitch (for frame recovery) */
- Word32 past_gcode; /* past energy (!) of code (for frame recovery) */ /*15Q16*/
- Word16 lsf_cng[M]; /* xSF coefficients used for CNG generation (long term) */
- Word16 lspold_cng[M]; /* xSP coefficients used for CNG generation (long term) */
- Word8 plcBackgroundNoiseUpdated; /* flag: Is background noise estimate updated? */
- Word16 lsp_q_cng[M]; /* xSP coefficients used for CNG generation (short term interpolated) */
- Word16 old_lsp_q_cng[M]; /* xSP coefficients used for CNG generation (short term interpolated) */
- Word16 lsf_q_cng[M]; /* xSF coefficients used for CNG generation (short term interpolated) */
- Word16 old_lsf_q_cng[M]; /* xSF: old quantized lsfs for background noise */
- Word16 Aq_cng[(NB_SUBFR16k + 1)*(M + 1)]; /* LPC coefficients derived from CNG estimate */
- Word16 mem_syn_unv_back[M]; /* filter memory for unvoiced synth */
- Word16 last_gain_syn_deemph; /*Q15*/
- Word16 last_gain_syn_deemph_e;
- Word16 last_concealed_gain_syn_deemph; /*Q15*/
- Word16 last_concealed_gain_syn_deemph_e;
-
- /* variables for framing */
- Word16 nb_subfr;
-
- Word16 fscale;
- Word16 fscale_old;
- Word32 sr_core; /*Q0*/
-
- Word16 pit_min; /*int*/
- Word16 pit_fr1;
- Word16 pit_fr1b;
- Word16 pit_fr2;
- Word16 pit_max; /*int Q0*/
- Word16 pit_res_max;
- Word16 pit_res_max_past;
-
-
- /*Preemphasis factor*/
- Word16 preemph_fac; /*0Q15*/
- Word16 gamma;
- Word16 inv_gamma;
-
- /*for AMR-WB like 6.4 to 7 kHz upsampling and noise filling*/
- Word16 mem_Aq[(NB_SUBFR16k)*(M + 1)]; /* Q12 */
-
- /* Error concealment */
- Word16 last_core_bfi;
- Word16 nbLostCmpt; /* compt for number of consecutive lost frame*/
- Word16 prev_nbLostCmpt; /* compt for number of consecutive lost frame at the previous frame*/
- Word16 mode_lvq; /* index for LSF mean vector */
- Word32 old_fpitch; /* last pitch of previous frame */ /*15Q16*/
- Word32 old_fpitchFB; /* PLC - last pitch of previous FB frame (depends on output sr) */ /*15Q16*/
- Word16 clas_dec;
- Word16 mem_pitch_gain[2 * NB_SUBFR16k + 2]; /* Pitch gain memory Q14 */
- Word8 plc_use_future_lag;
- Word32 Mode2_lp_gainc; /* 15Q16 low passed code gain used for concealment*/
- Word32 Mode2_lp_gainp; /* 15Q16 low passed pitch gain used for concealment*/
-
- Word16 cummulative_damping; /*Q15*/
- Word16 cngTDLevel;
- Word16 cngTDLevel_e;
-
- Word16 prev_widow_left_rect;
-
-
-
- Word16 reset_mem_AR;
-
-
- Word16 classifier_Q_mem_syn; /*scalingfactor of mem_syn_clas_estim_fx in MODE2 */
-
- Word16 rate_switching_init;
-
- /* LPC quantization */
- Word16 lpcQuantization;
- Word16 numlpc;
-
- /* Bandwidth */
- Word16 TcxBandwidth;
-
- /* For NB and formant post-filter */
- PFSTAT_HANDLE hPFstat; /* NB and formant post-filter states */
- Word16 psf_lp_noise_fx;
- Word16 last_voice_factor_fx; /* Q6*/
-
- /* For adaptive tilt_code */
- Word16 voice_fac;
-
- Word16 tcxonly;
-
-
- Word16 last_ctx_hm_enabled;
-
-
- /*----------------------------------------------------------------------------------*
- * TCX LTP decoder handle
- *----------------------------------------------------------------------------------*/
- TCX_LTP_DEC_HANDLE hTcxLtpDec;
- struct tonalmdctconceal tonalMDCTconceal;
- Word8 tonal_mdct_plc_active;
- Word8 last_tns_active;
- Word8 second_last_tns_active;
- Word16 second_last_core;
- /*----------------------------------------------------------------------------------*
- * TCX core decoder handle
- *----------------------------------------------------------------------------------*/
-
- TCX_DEC_HANDLE hTcxDec;
-
- /* parameters for switching */
- Word16 mem_syn_r[L_SYN_MEM]; /*LPC synthesis memory needed for rate switching*/
- Word16 rate_switching_reset;
-
- Word32 lp_error_ener;
- Word32 mem_error;
- Word16 bpf_noise_buf[L_FRAME_16k];
- Word16 *p_bpf_noise_buf;
-
- Word8 enableGplc;
- Word16 flagGuidedAcelp; /*int*/
- Word16 T0_4th;/*int*/
- Word16 guidedT0; /*int*/
-
- Word16 enablePlcWaveadjust;
- Word16 tonality_flag;
- T_PLCInfo plcInfo;
-
- Word8 VAD;
- Word8 flag_cna;
- Word8 last_flag_cna;
-
- Word32 lp_noise;
-
- Word16 seed_acelp;
-
- Word16 core_ext_mode; /*GC,VC,UC,TC: core extended mode used for PLC or Acelp-external modules.*/
-
- Word8 dec_glr;
- Word16 dec_glr_idx;
-
-
- Word16 igf;
- IGF_DEC_INSTANCE_HANDLE hIGFDec;
- CLDFB_SCALE_FACTOR scaleFactor;
-
- Word16 tec_tfa;
- Word16 tec_flag;
- Word16 tfa_flag;
- TEMPORAL_ENVELOPE_CODING_DECODER_FX tecDec_fx;
-
- Word16 con_tcx;
- Word16 last_con_tcx;
- Word16 old_ppp_mode_fx;
-
- Word16 prev_Q_exc_fr;
- Word16 prev_Q_syn_fr;
-
- Word16 writeFECoffset;
-
- /*----------------------------------------------------------------------------------*
- * Stereo/IVAS parameters
- *----------------------------------------------------------------------------------*/
- Word16 bits_frame_nominal; /* avg bits per frame on active frame */
- Word16 last_bits_frame_nominal; /* last avg bits per frame on active frame */
- Word16 flag_ACELP16k; /* flag indicating use of ACELP core at 16kHz internal sampling rate */
-
- Word16 tdm_LRTD_flag; /* LRTD stereo mode flag */
- Word16 cna_dirac_flag; /* CNA in DirAC flag */
- Word16 cng_sba_flag; /* CNG in SBA flag */
- Word16 idchan; /* channel ID (audio channel number) */
- Word16 element_mode; /* element mode */
Word16 last_element_mode; /* element mode */
- Word16 low_rate_mode; /* low-rate mode flag */
- Word16 last_low_rate_mode; /* previous low-rate mode flag */
Word16 coder_type_fx; /* low-rate mode flag */
- Word16 mct_chan_mode;
- Word16 cng_ism_flag; /* CNG in ISM format flag */
- Word16 is_ism_format; /* Indication whether the codec operates in ISM format */
#ifdef DEBUGGING
Word16 id_element; /* element ID */
#endif
- Word32 element_brate; /* element bitrate */
- Word16 extl_orig; /* extension layer */
- Word32 extl_brate_orig; /* extension layer bitrate */
-} Decoder_State_fx, *DEC_CORE_HANDLE;
+} Decoder_State, *DEC_CORE_HANDLE;
#endif
diff --git a/lib_dec/swb_bwe_dec.c b/lib_dec/swb_bwe_dec.c
index 23c59cf5c9e232420f168c78fb11f9dcd98e5876..cc835d7d684cf2f56e74fdaddc9ed5df9f158bd5 100644
--- a/lib_dec/swb_bwe_dec.c
+++ b/lib_dec/swb_bwe_dec.c
@@ -266,7 +266,7 @@ void wb_bwe_dec(
{
/* IVAS_fmToDo: wtda() does not support L_FRAME length; thus temporarily resample the signal */
/* IVAS_fmToDo: delay output[] by 1.25ms ? */
- lerp( output, ysynth, L_FRAME16k, st->L_frame );
+ lerp_flt( output, ysynth, L_FRAME16k, st->L_frame );
wtda( ysynth, wtda_synth, hBWE_FD->old_wtda_swb, ALDO_WINDOW, ALDO_WINDOW, /*st->L_frame*/ L_FRAME16k );
direct_transform( wtda_synth, ysynth, 0, /*st->L_frame*/ L_FRAME16k, st->element_mode );
@@ -585,7 +585,7 @@ void swb_bwe_dec(
{
/* todo - wtda() does not support L_FRAME length; thus temporarily resample the signal */
/* todo - delay output[] by 1.25ms ? */
- lerp( output, ysynth, L_FRAME16k, st->L_frame );
+ lerp_flt( output, ysynth, L_FRAME16k, st->L_frame );
/* windowing of the ACELP core synthesis */
wtda( ysynth, wtda_synth, hBWE_FD->old_wtda_swb, ALDO_WINDOW, ALDO_WINDOW, /*st->L_frame*/ L_FRAME16k );
diff --git a/lib_dec/swb_tbe_dec.c b/lib_dec/swb_tbe_dec.c
index 2bc59695caacb223a2720d4d5722fcfbc037a232..b3efdd7f0ba0947f12f1e4810afd77080086971d 100644
--- a/lib_dec/swb_tbe_dec.c
+++ b/lib_dec/swb_tbe_dec.c
@@ -800,7 +800,7 @@ void swb_tbe_dec(
{
for ( j = 0; j < 4; j++ )
{
- GainShape[i * 4 + j] = st->cummulative_damping * hBWE_TD->GainShape_Delay[4 + i];
+ GainShape[i * 4 + j] = st->cummulative_damping_float * hBWE_TD->GainShape_Delay[4 + i];
}
}
@@ -808,15 +808,15 @@ void swb_tbe_dec(
{
if ( st->nbLostCmpt == 1 )
{
- GainFrame = (float) ( 0.6 * st->cummulative_damping * hBWE_TD->GainFrame_prevfrm );
+ GainFrame = (float) ( 0.6 * st->cummulative_damping_float * hBWE_TD->GainFrame_prevfrm );
}
else if ( st->nbLostCmpt == 2 )
{
- GainFrame = (float) ( 0.35 * st->cummulative_damping * hBWE_TD->GainFrame_prevfrm );
+ GainFrame = (float) ( 0.35 * st->cummulative_damping_float * hBWE_TD->GainFrame_prevfrm );
}
else
{
- GainFrame = (float) ( 0.2 * st->cummulative_damping * hBWE_TD->GainFrame_prevfrm );
+ GainFrame = (float) ( 0.2 * st->cummulative_damping_float * hBWE_TD->GainFrame_prevfrm );
}
}
else
@@ -849,11 +849,11 @@ void swb_tbe_dec(
{
if ( hBWE_TD->prev2_shb_ener_sf > 2.0f * hBWE_TD->prev1_shb_ener_sf || hBWE_TD->prev3_shb_ener_sf > 2.0f * hBWE_TD->prev2_shb_ener_sf )
{
- shb_ener_sf = 0.5f * st->cummulative_damping * hBWE_TD->prev1_shb_ener_sf;
+ shb_ener_sf = 0.5f * st->cummulative_damping_float * hBWE_TD->prev1_shb_ener_sf;
}
else
{
- shb_ener_sf = st->cummulative_damping * hBWE_TD->prev1_shb_ener_sf;
+ shb_ener_sf = st->cummulative_damping_float * hBWE_TD->prev1_shb_ener_sf;
}
}
}
diff --git a/lib_dec/tcq_core_dec.c b/lib_dec/tcq_core_dec.c
index c9dcb27d1a35f43c05fc1bd7eff85c83b14778af..6e0e649839816497b5e1a7e8f4142af2c4ee214a 100644
--- a/lib_dec/tcq_core_dec.c
+++ b/lib_dec/tcq_core_dec.c
@@ -206,7 +206,7 @@ void tcq_core_LR_dec(
{
surplus_fx = -131072;
- bit_allocation_second_fx( Rk_fx, Rk_sort_fx, BANDS, band_width, k_sort, k_num, p2a_flags, p2a_bands, last_bitalloc, input_frame );
+ bit_allocation_second_fx2( Rk_fx, Rk_sort_fx, BANDS, band_width, k_sort, k_num, p2a_flags, p2a_bands, last_bitalloc, input_frame );
nzbands = 0;
for ( j = 0; j < BANDS; j++ )
diff --git a/lib_dec/tcx_utils_dec.c b/lib_dec/tcx_utils_dec.c
index e2dc05a8a2c7185d67905e3e7198c1a8128f5b1a..01bbb3858985038119e63aa783137198415ad67c 100644
--- a/lib_dec/tcx_utils_dec.c
+++ b/lib_dec/tcx_utils_dec.c
@@ -59,7 +59,7 @@ void tcx_decoder_memory_update(
float tmp;
float *synth;
float buf[1 + M + L_FRAME_PLUS];
- float preemph_f = st->preemph_fac;
+ float preemph_f = st->preemph_fac_float;
L_frame_glob = st->L_frame;
@@ -71,16 +71,16 @@ void tcx_decoder_memory_update(
/* Update synth */
synth = buf + 1 + M;
- mvr2r( st->syn, buf, 1 + M );
+ mvr2r( st->syn_float, buf, 1 + M );
mvr2r( xn_buf, synth, L_frame_glob );
- mvr2r( synth + L_frame_glob - M - 1, st->syn, 1 + M );
+ mvr2r( synth + L_frame_glob - M - 1, st->syn_float, 1 + M );
/* Emphasis of synth -> synth_pe */
tmp = synth[-M - 1];
preemph( synth - M, preemph_f, M + L_frame_glob, &tmp );
mvr2r( synth + L_frame_glob - M, st->mem_syn2, M );
- mvr2r( synth + L_frame_glob - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM );
+ mvr2r( synth + L_frame_glob - L_SYN_MEM, st->mem_syn_r_float, L_SYN_MEM );
if ( st->element_mode != IVAS_CPE_MDCT )
{
diff --git a/lib_dec/transition_dec.c b/lib_dec/transition_dec.c
index a7fa472b55ab9dc84ddd8af32d129a3dbd170e58..b25c7d201c6f2f6d64e61fee8288cb7f664c8f23 100644
--- a/lib_dec/transition_dec.c
+++ b/lib_dec/transition_dec.c
@@ -217,7 +217,7 @@ void transition_dec(
/* Find the adaptive codebook vector - ACELP long-term prediction */
pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, inter4_2, L_INTERPOL2, PIT_UP_SAMP );
- offset = tbe_celp_exc_offset( *T0, *T0_frac );
+ offset = tbe_celp_exc_offset_flt( *T0, *T0_frac );
for ( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ )
{
bwe_exc[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc[i + i_subfr * HIBND_ACB_L_FAC - offset];
@@ -243,7 +243,7 @@ void transition_dec(
/* Find the adaptive codebook vector. ACELP long-term prediction */
pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, inter4_2, L_INTERPOL2, PIT_UP_SAMP );
- offset = tbe_celp_exc_offset( *T0, *T0_frac );
+ offset = tbe_celp_exc_offset_flt( *T0, *T0_frac );
for ( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ )
{
bwe_exc[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc[i + i_subfr * HIBND_ACB_L_FAC - offset];
@@ -299,7 +299,7 @@ void transition_dec(
/* Find the adaptive codebook vector. ACELP long-term prediction */
pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, inter4_2, L_INTERPOL2, PIT_UP_SAMP );
- offset = tbe_celp_exc_offset( *T0, *T0_frac );
+ offset = tbe_celp_exc_offset_flt( *T0, *T0_frac );
for ( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ )
{
bwe_exc[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc[i + i_subfr * HIBND_ACB_L_FAC - offset];
@@ -319,7 +319,7 @@ void transition_dec(
/* Find the adaptive codebook vector. ACELP long-term prediction */
pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, inter4_2, L_INTERPOL2, PIT_UP_SAMP );
- offset = tbe_celp_exc_offset( *T0, *T0_frac );
+ offset = tbe_celp_exc_offset_flt( *T0, *T0_frac );
for ( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ )
{
bwe_exc[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc[i + i_subfr * HIBND_ACB_L_FAC - offset];
@@ -339,7 +339,7 @@ void transition_dec(
/* Find the adaptive codebook vector */
pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, inter4_2, L_INTERPOL2, PIT_UP_SAMP );
- offset = tbe_celp_exc_offset( *T0, *T0_frac );
+ offset = tbe_celp_exc_offset_flt( *T0, *T0_frac );
for ( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ )
{
bwe_exc[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc[i + i_subfr * HIBND_ACB_L_FAC - offset];
diff --git a/lib_dec/updt_dec.c b/lib_dec/updt_dec.c
index c6c348333a17b6e70b290d2bc0a68f666710ca8f..2e75f82b03db2b2232372267bef3565dee7c8dec 100644
--- a/lib_dec/updt_dec.c
+++ b/lib_dec/updt_dec.c
@@ -144,22 +144,22 @@ void updt_dec(
mvr2r( &st->old_pitch_buf[st->L_frame / L_SUBFR], st->old_pitch_buf, st->L_frame / L_SUBFR );
mvr2r( pitch_buf, &st->old_pitch_buf[st->L_frame / L_SUBFR], st->L_frame / L_SUBFR );
- mvr2r( &st->mem_pitch_gain[2], &st->mem_pitch_gain[st->L_frame / L_SUBFR + 2], st->L_frame / L_SUBFR );
+ mvr2r( &st->mem_pitch_gain_float[2], &st->mem_pitch_gain_float[st->L_frame / L_SUBFR + 2], st->L_frame / L_SUBFR );
if ( st->L_frame == L_FRAME )
{
- st->mem_pitch_gain[2] = gain_buf[3];
- st->mem_pitch_gain[3] = gain_buf[2];
- st->mem_pitch_gain[4] = gain_buf[1];
- st->mem_pitch_gain[5] = gain_buf[0];
+ st->mem_pitch_gain_float[2] = gain_buf[3];
+ st->mem_pitch_gain_float[3] = gain_buf[2];
+ st->mem_pitch_gain_float[4] = gain_buf[1];
+ st->mem_pitch_gain_float[5] = gain_buf[0];
}
else
{
- st->mem_pitch_gain[2] = gain_buf[4];
- st->mem_pitch_gain[3] = gain_buf[3];
- st->mem_pitch_gain[4] = gain_buf[2];
- st->mem_pitch_gain[5] = gain_buf[1];
- st->mem_pitch_gain[6] = gain_buf[0];
+ st->mem_pitch_gain_float[2] = gain_buf[4];
+ st->mem_pitch_gain_float[3] = gain_buf[3];
+ st->mem_pitch_gain_float[4] = gain_buf[2];
+ st->mem_pitch_gain_float[5] = gain_buf[1];
+ st->mem_pitch_gain_float[6] = gain_buf[0];
}
/* FEC - update adaptive LSF mean vector */
@@ -283,7 +283,7 @@ void updt_IO_switch_dec(
st->cldfbSyn->bandsToZero = 0;
}
st->last_active_bandsToZero_bwdec = 0;
- st->perc_bwddec = 0.0f;
+ st->perc_bwddec_float = 0.0f;
st->last_flag_filter_NB = 0;
st->active_frame_cnt_bwddec = 0;
set_s( st->flag_buffer, 0, 20 );
@@ -315,7 +315,7 @@ void updt_IO_switch_dec(
/* reset the unvoiced/audio signal improvement memories */
st->hGSCDec->seed_tcx = 15687;
- st->psf_lp_noise = st->lp_noise;
+ st->psf_lp_noise = st->lp_noise_float;
/* AMR-WB IO init */
mvr2r( st->hAmrwb_IO->lt_diff_etot, tmpF, MAX_LT );
@@ -695,9 +695,9 @@ void update_decoder_LPD_cng(
mvr2r( timeDomainBuffer, buf_synth + hTcxDec->old_synth_len, st->L_frame );
/* Update synth memory */
- mvr2r( st->syn, synth_buf, 1 + M );
+ mvr2r( st->syn_float, synth_buf, 1 + M );
mvr2r( timeDomainBuffer, synth, st->L_frame );
- mvr2r( synth + st->L_frame - ( 1 + M ), st->syn, 1 + M );
+ mvr2r( synth + st->L_frame - ( 1 + M ), st->syn_float, 1 + M );
mvr2r( hTcxDec->old_synth_float + st->L_frame, hTcxDec->old_synth_float, hTcxDec->old_synth_len - st->L_frame );
mvr2r( synth, hTcxDec->old_synth_float + hTcxDec->old_synth_len - st->L_frame, st->L_frame );
@@ -708,9 +708,9 @@ void update_decoder_LPD_cng(
/* Update pre-synth memory */
tmp = synth[-( 1 + M )];
- preemph( synth - M, st->preemph_fac, M + st->L_frame, &tmp );
+ preemph( synth - M, st->preemph_fac_float, M + st->L_frame, &tmp );
mvr2r( synth + st->L_frame - M, st->mem_syn2, M );
- mvr2r( synth + st->L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM );
+ mvr2r( synth + st->L_frame - L_SYN_MEM, st->mem_syn_r_float, L_SYN_MEM );
/* Update excitation memory */
assert( st->L_frame < L_EXC_MEM_DEC );
@@ -720,8 +720,8 @@ void update_decoder_LPD_cng(
/* Update LPC-related memories */
mvr2r( lsp, st->lsp_old, M );
mvr2r( lsf, st->lsf_old, M );
- mvr2r( lsp, st->lspold_uw, M );
- mvr2r( lsf, st->lsfold_uw, M );
+ mvr2r( lsp, st->lspold_uw_float, M );
+ mvr2r( lsf, st->lsfold_uw_float, M );
hTcxDec->envWeighted = 0;
mvr2r( A, st->old_Aq_12_8, M + 1 );
@@ -743,13 +743,13 @@ void update_decoder_LPD_cng(
}
/* For BWE and Postfilter */
- mvr2r( A, &( st->mem_Aq[0] ), M + 1 );
- mvr2r( A, &( st->mem_Aq[( M + 1 )] ), M + 1 );
- mvr2r( A, &( st->mem_Aq[2 * ( M + 1 )] ), M + 1 );
- mvr2r( A, &( st->mem_Aq[3 * ( M + 1 )] ), M + 1 );
+ mvr2r( A, &( st->mem_Aq_float[0] ), M + 1 );
+ mvr2r( A, &( st->mem_Aq_float[( M + 1 )] ), M + 1 );
+ mvr2r( A, &( st->mem_Aq_float[2 * ( M + 1 )] ), M + 1 );
+ mvr2r( A, &( st->mem_Aq_float[3 * ( M + 1 )] ), M + 1 );
if ( st->L_frame == L_FRAME16k )
{
- mvr2r( A, &( st->mem_Aq[4 * ( M + 1 )] ), M + 1 );
+ mvr2r( A, &( st->mem_Aq_float[4 * ( M + 1 )] ), M + 1 );
}
/* Update for concealment */
@@ -765,7 +765,7 @@ void update_decoder_LPD_cng(
set_f( pitch, (float) L_SUBFR, NB_SUBFR16k );
- FEC_clas_estim( synth, pitch, st->L_frame, UNVOICED, st->codec_mode, st->mem_syn_clas_estim, &( st->clas_dec ), &st->lp_ener_bfi, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1.0f, st->narrowBand, CLASSIFIER_ACELP, 0, st->preemph_fac, st->tcxonly, st->last_core_brate, -1 );
+ FEC_clas_estim( synth, pitch, st->L_frame, UNVOICED, st->codec_mode, st->mem_syn_clas_estim, &( st->clas_dec ), &st->lp_ener_bfi, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1.0f, st->narrowBand, CLASSIFIER_ACELP, 0, st->preemph_fac_float, st->tcxonly, st->last_core_brate, -1 );
/* Postfiltering */
pf_pitch[0] = pf_pitch[1] = pf_pitch[2] = pf_pitch[3] = pf_pitch[4] = L_SUBFR;
diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c
index 280c752d1260513f7dfd6e8d0c7b91ce5780a0ae..1f71ccd66e839231e7a1474ae4738d532bbf6d4b 100644
--- a/lib_enc/acelp_core_enc.c
+++ b/lib_enc/acelp_core_enc.c
@@ -261,7 +261,7 @@ ivas_error acelp_core_enc(
set_zero( st->mem_MA, M );
/* update synthesis filter memories */
- synth_mem_updt2( st->L_frame, st->last_L_frame, hLPDmem->old_exc_flt, hLPDmem->mem_syn_r_flt, hLPDmem->mem_syn2_flt, hLPDmem->mem_syn_flt, ENC );
+ synth_mem_updt2_flt( st->L_frame, st->last_L_frame, hLPDmem->old_exc_flt, hLPDmem->mem_syn_r_flt, hLPDmem->mem_syn2_flt, hLPDmem->mem_syn_flt, ENC );
mvr2r( hLPDmem->old_exc_flt, old_exc_flt, L_EXC_MEM );
mvr2r( hLPDmem->mem_syn2_flt, hLPDmem->mem_syn1_flt, M );
mvr2r( hLPDmem->mem_syn2_flt, hLPDmem->mem_syn3_flt, M );
@@ -456,11 +456,11 @@ ivas_error acelp_core_enc(
/* Prepare ACB memory of old_bwe_exc */
if ( st->L_frame == L_FRAME )
{
- lerp( old_exc_flt, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC );
+ lerp_flt( old_exc_flt, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC );
}
else
{
- lerp( old_exc_flt, old_bwe_exc, L_EXC_MEM_DEC * 2, L_EXC_MEM_DEC );
+ lerp_flt( old_exc_flt, old_bwe_exc, L_EXC_MEM_DEC * 2, L_EXC_MEM_DEC );
}
}
diff --git a/lib_enc/amr_wb_enc.c b/lib_enc/amr_wb_enc.c
index 43406ac39a5bab874506c8496b59de9f95b83d72..89591879288fa4d6348c150d5cd32f11d16a6d94 100644
--- a/lib_enc/amr_wb_enc.c
+++ b/lib_enc/amr_wb_enc.c
@@ -205,7 +205,7 @@ void amr_wb_enc(
set_zero( st->mem_MA, M );
/* update synthesis filter memories */
- synth_mem_updt2( L_FRAME, st->last_L_frame, hLPDmem->old_exc_flt, hLPDmem->mem_syn_r_flt, hLPDmem->mem_syn1_flt, hLPDmem->mem_syn_flt, ENC );
+ synth_mem_updt2_flt( L_FRAME, st->last_L_frame, hLPDmem->old_exc_flt, hLPDmem->mem_syn_r_flt, hLPDmem->mem_syn1_flt, hLPDmem->mem_syn_flt, ENC );
mvr2r( hLPDmem->old_exc_flt, old_exc_flt, L_EXC_MEM );
mvr2r( hLPDmem->mem_syn1_flt, hLPDmem->mem_syn2_flt, M );
mvr2r( hLPDmem->mem_syn2_flt, hLPDmem->mem_syn3_flt, M );
diff --git a/lib_enc/analy_lp.c b/lib_enc/analy_lp.c
index 536d1e13afe4015e2a17312ab69e8b3c67027be1..8e4d6c6ee9fbebc445bfeddbf0ed2a70c30cf31e 100644
--- a/lib_enc/analy_lp.c
+++ b/lib_enc/analy_lp.c
@@ -96,7 +96,7 @@ void analy_lp(
autocorr( pt, r, M, wind_length, wind, 0, 0, 0 );
/* Lag windowing */
- adapt_lag_wind( r, M, Top[half_frame_idx], Tnc[half_frame_idx], sr_core );
+ adapt_lag_wind_fx( r, M, Top[half_frame_idx], Tnc[half_frame_idx], sr_core );
++half_frame_idx;
/* Levinson-Durbin */
@@ -163,7 +163,7 @@ void analy_lp_AMR_WB(
autocorr( speech - L_SUBFR, r, M, wind_length, wind, 0, 0, 0 );
/* Lag windowing */
- adapt_lag_wind( r, M, Top, Tnc, 12800 );
+ adapt_lag_wind_fx( r, M, Top, Tnc, 12800 );
/* Levinson-Durbin */
lev_dur( A, r, M, epsP );
diff --git a/lib_enc/analy_sp.c b/lib_enc/analy_sp.c
index c03ec0c90aa98ded2ebad22d62cba59b8b53724d..5ad93a5e4f401e59f5707c2b2615feda6f1596c6 100644
--- a/lib_enc/analy_sp.c
+++ b/lib_enc/analy_sp.c
@@ -393,7 +393,7 @@ static void find_enr_dft(
/* Last value of Bin_E is handled outside this function*/
assert( bin_cnt == ( STEREO_DFT_N_12k8_ENC / 2 - 1 ) );
BinE[STEREO_DFT_N_12k8_ENC / 2 - 1] = BinE[STEREO_DFT_N_12k8_ENC / 2 - 2];
- lerp( BinE, Bin_E, L_FFT / 2, STEREO_DFT_N_12k8_ENC / 2 );
+ lerp_flt( BinE, Bin_E, L_FFT / 2, STEREO_DFT_N_12k8_ENC / 2 );
mvr2r( Bin_E, ptE, VOIC_BINS );
diff --git a/lib_enc/cod_ace.c b/lib_enc/cod_ace.c
index 867a96e471d3835211ca515ef721caa28ed23d86..fda2e140bee5a4f49495b0c81a5093c537da84c5 100644
--- a/lib_enc/cod_ace.c
+++ b/lib_enc/cod_ace.c
@@ -267,7 +267,7 @@ void coder_acelp(
if ( st->igf )
{
- tbe_celp_exc( st->element_mode, st->idchan, bwe_exc, st->L_frame, L_SUBFR, i_subfr, T0, T0_frac, &error, 0 );
+ tbe_celp_exc_flt( st->element_mode, st->idchan, bwe_exc, st->L_frame, L_SUBFR, i_subfr, T0, T0_frac, &error, 0 );
}
pitch_buf[i_subfr / L_SUBFR] = (float) T0 + (float) T0_frac / (float) T0_res;
diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c
index d19224d73bbe5b9fd2f98daaf503058d360213e0..d41dc89474ea12994f8798a895d743d0e2cb5858 100644
--- a/lib_enc/core_enc_init.c
+++ b/lib_enc/core_enc_init.c
@@ -350,7 +350,7 @@ static void init_sig_buffers(
else if ( st->L_frame != L_frame_old && !( ( total_brate >= ACELP_16k40 && total_brate <= ACELP_24k40 ) &&
( total_brate == last_total_brate ) && ( st->last_bwidth == st->bwidth ) ) )
{
- lerp( st->buf_speech_enc_flt, st->buf_speech_enc_flt, st->L_frame, L_frame_old );
+ lerp_flt( st->buf_speech_enc_flt, st->buf_speech_enc_flt, st->L_frame, L_frame_old );
if ( ( st->last_core != TCX_20_CORE ) && ( st->last_core != TCX_10_CORE ) )
{
@@ -366,7 +366,7 @@ static void init_sig_buffers(
}
else if ( st->L_frame == L_FRAME16k && !st->tcxonly )
{
- lerp( st->buf_wspeech_enc_flt + st->L_frame + L_SUBFR - L_WSP_MEM, st->buf_wspeech_enc_flt + st->L_frame + L_SUBFR - 310, 310, L_WSP_MEM );
+ lerp_flt( st->buf_wspeech_enc_flt + st->L_frame + L_SUBFR - L_WSP_MEM, st->buf_wspeech_enc_flt + st->L_frame + L_SUBFR - 310, 310, L_WSP_MEM );
mvr2r( st->old_inp_16k, st->buf_speech_enc_pe_flt + st->L_frame - L_INP_MEM, L_INP_MEM );
}
@@ -380,7 +380,7 @@ static void init_sig_buffers(
/*Resamp buffers needed only for ACELP*/
if ( st->L_frame == L_FRAME16k )
{
- lerp( st->buf_wspeech_enc_flt + st->L_frame + L_SUBFR - L_WSP_MEM, st->buf_wspeech_enc_flt + st->L_frame + L_SUBFR - 310, 310, L_WSP_MEM );
+ lerp_flt( st->buf_wspeech_enc_flt + st->L_frame + L_SUBFR - L_WSP_MEM, st->buf_wspeech_enc_flt + st->L_frame + L_SUBFR - 310, 310, L_WSP_MEM );
}
st->hLPDmem->mem_w0_flt = 0;
st->mem_wsp_enc_flt = st->buf_wspeech_enc_flt[st->L_frame + L_SUBFR - 1];
@@ -523,11 +523,11 @@ static void init_acelp(
{
if ( st->last_core == ACELP_CORE )
{
- lerp( st->hTcxEnc->Txnq_flt, st->hTcxEnc->Txnq_flt, st->L_frame / 2, L_frame_old / 2 );
+ lerp_flt( st->hTcxEnc->Txnq_flt, st->hTcxEnc->Txnq_flt, st->L_frame / 2, L_frame_old / 2 );
}
else
{
- lerp( st->hTcxEnc->Txnq_flt, st->hTcxEnc->Txnq_flt, st->hTcxCfg->tcx_mdct_window_length, st->hTcxCfg->tcx_mdct_window_length_old );
+ lerp_flt( st->hTcxEnc->Txnq_flt, st->hTcxEnc->Txnq_flt, st->hTcxCfg->tcx_mdct_window_length, st->hTcxCfg->tcx_mdct_window_length_old );
}
st->hTcxEnc->acelp_zir_flt = st->hTcxEnc->Txnq_flt + ( st->L_frame / 2 );
}
@@ -610,7 +610,7 @@ static void init_acelp(
/* Update wsyn */
if ( hLPDmem != NULL )
{
- synth_mem_updt2( st->L_frame, st->last_L_frame, hLPDmem->old_exc_flt, hLPDmem->mem_syn_r_flt, hLPDmem->mem_syn2_flt, hLPDmem->mem_syn_flt, ENC );
+ synth_mem_updt2_flt( st->L_frame, st->last_L_frame, hLPDmem->old_exc_flt, hLPDmem->mem_syn_r_flt, hLPDmem->mem_syn2_flt, hLPDmem->mem_syn_flt, ENC );
lsp2a_stab( st->lsp_old, A, M );
weight_a( A, Ap, GAMMA1_FLT, M );
tmp = 0.f;
@@ -637,7 +637,7 @@ static void init_acelp(
/*Size of LPC syn memory*/
mem_syn_r_size_old = (int16_t) ( 1.25 * L_frame_old / 20.f );
mem_syn_r_size_new = (int16_t) ( 1.25 * st->L_frame / 20.f );
- lerp( hLPDmem->mem_syn_r_flt + L_SYN_MEM - mem_syn_r_size_old, hLPDmem->mem_syn_r_flt + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
+ lerp_flt( hLPDmem->mem_syn_r_flt + L_SYN_MEM - mem_syn_r_size_old, hLPDmem->mem_syn_r_flt + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
mvr2r( hLPDmem->mem_syn_r_flt + L_SYN_MEM - M, hLPDmem->mem_syn_flt, M );
mvr2r( hLPDmem->mem_syn_flt, hLPDmem->mem_syn2_flt, M );
diff --git a/lib_enc/core_enc_ol.c b/lib_enc/core_enc_ol.c
index 051d99f6747bc777fc1d08199a23f33b9c99d3f6..4d9de5fa62cafbe0fd1a4452725acc2de2d8bd67 100644
--- a/lib_enc/core_enc_ol.c
+++ b/lib_enc/core_enc_ol.c
@@ -432,7 +432,7 @@ void core_encode_openloop(
tmp = st->synth_flt[L_FRAME - L_LP - 1];
preemph( buf, st->preemph_fac_flt, L_LP, &tmp );
autocorr( buf, r, M, L_LP, LP_assym_window, 0, 0, 0 );
- lag_wind( r, M, INT_FS_12k8, LAGW_WEAK );
+ lag_wind_flt( r, M, INT_FS_12k8, LAGW_WEAK );
lev_dur( A, r, M, NULL );
a2lsp_stab( A, lsptmp, lsp_new );
diff --git a/lib_enc/enc_gen_voic.c b/lib_enc/enc_gen_voic.c
index 4c0c4e15da5d419947a952c32543414400126f00..ed4c56face6cdab05526a2b5fda5f9f6b140b058 100644
--- a/lib_enc/enc_gen_voic.c
+++ b/lib_enc/enc_gen_voic.c
@@ -165,7 +165,7 @@ void encod_gen_voic(
*pt_pitch = pit_encode( hBstr, st->acelp_cfg.pitch_bits, st->core_brate, 0, L_frame, st->coder_type, &pitch_limit_flag, i_subfr, exc, L_SUBFR, st->pitch, &T0_min, &T0_max, &T0, &T0_frac, h1, xn, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf );
- tbe_celp_exc( st->element_mode, st->idchan, bwe_exc, L_frame, L_SUBFR, i_subfr, T0, T0_frac, &error, st->tdm_LRTD_flag );
+ tbe_celp_exc_flt( st->element_mode, st->idchan, bwe_exc, L_frame, L_SUBFR, i_subfr, T0, T0_frac, &error, st->tdm_LRTD_flag );
/*-----------------------------------------------------------------*
* Find adaptive exitation
diff --git a/lib_enc/ext_sig_ana.c b/lib_enc/ext_sig_ana.c
index 74b09d323dbdef94eb85ff58ae540125656fd54b..4812ec243bc4ebe286973372ad10fade46176ef0 100644
--- a/lib_enc/ext_sig_ana.c
+++ b/lib_enc/ext_sig_ana.c
@@ -426,7 +426,7 @@ void core_signal_analysis_high_bitrate(
{
HBAutocorrelation( st->hTcxCfg, overlap_mode[frameno] == ALDO_WINDOW ? FULL_OVERLAP : overlap_mode[frameno], overlap_mode[frameno + 1] == ALDO_WINDOW ? FULL_OVERLAP : overlap_mode[frameno + 1], &st->speech_enc_pe_flt[frameno * tcx10Size], L_frame / nSubframes, r );
- adapt_lag_wind( r, M, alw_pitch_lag_12k8[frameno], alw_voicing[frameno], st->sr_core );
+ adapt_lag_wind_fx( r, M, alw_pitch_lag_12k8[frameno], alw_voicing[frameno], st->sr_core );
lev_dur( A, r, M, NULL );
diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c
index 95c5cd00748e8c51eb007e2614ffdb471ba26a25..3e4b75a8cac6a96eb8cfa22541a0a793dbab8bac 100644
--- a/lib_enc/ivas_core_pre_proc.c
+++ b/lib_enc/ivas_core_pre_proc.c
@@ -790,7 +790,7 @@ ivas_error ivas_compute_core_buffers(
}
else if ( input_Fs > 8000 )
{
- lerp( st->old_inp_12k8 + L_INP_MEM - L_INP_MEM * 4 / 5, st->old_inp_16k, L_INP_MEM, L_INP_MEM * 4 / 5 );
+ lerp_flt( st->old_inp_12k8 + L_INP_MEM - L_INP_MEM * 4 / 5, st->old_inp_16k, L_INP_MEM, L_INP_MEM * 4 / 5 );
}
if ( inp16k_out != NULL )
diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c
index 2b6b96cedf2ab04a3e46344a00d498acfaee5ce5..9d5d7abde116c8500a272531593ae3fcd6e43450 100644
--- a/lib_enc/ivas_stereo_switching_enc.c
+++ b/lib_enc/ivas_stereo_switching_enc.c
@@ -674,7 +674,7 @@ void stereo_switching_enc(
}
/* update DFT synthesis overlap memory @16kHz, primary channel only */
- lerp( hCPE->hStereoDft->output_mem_dmx, hCPE->hStereoDft->output_mem_dmx_16k, STEREO_DFT_OVL_16k, dft_ovl );
+ lerp_flt( hCPE->hStereoDft->output_mem_dmx, hCPE->hStereoDft->output_mem_dmx_16k, STEREO_DFT_OVL_16k, dft_ovl );
/* reset DFT synthesis overlap memory @8kHz, secondary channel */
set_f( hCPE->hStereoDft->output_mem_res_8k, 0, STEREO_DFT_OVL_8k );
diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c
index 7d318909c2b777807a89e82218ac9ee081d46dd8..325e20b76155e5ec824ac567d0b1f769f9c694da 100644
--- a/lib_enc/ivas_tcx_core_enc.c
+++ b/lib_enc/ivas_tcx_core_enc.c
@@ -457,7 +457,7 @@ void stereo_tcx_core_enc(
tmp = st->synth_flt[L_FRAME - L_LP - 1];
preemph( buf, st->preemph_fac_flt, L_LP, &tmp );
autocorr( buf, r, M, L_LP, LP_assym_window, 0, 0, 0 );
- lag_wind( r, M, INT_FS_12k8, LAGW_WEAK );
+ lag_wind_flt( r, M, INT_FS_12k8, LAGW_WEAK );
lev_dur( A, r, M, NULL );
a2lsp_stab( A, lsptmp, lsp_new );
diff --git a/lib_enc/ivas_td_low_rate_enc.c b/lib_enc/ivas_td_low_rate_enc.c
index a2563e2097f45bfe1c0493afc90762e73babd031..825e01a254d1f62796f5ebc1a2617efb8c2c25b8 100644
--- a/lib_enc/ivas_td_low_rate_enc.c
+++ b/lib_enc/ivas_td_low_rate_enc.c
@@ -246,7 +246,7 @@ void encod_gen_2sbfr(
*pt_pitch = pit_encode( st->hBstr, st->acelp_cfg.pitch_bits, st->core_brate, 0, L_frame, coder_type, &pitch_limit_flag, i_subfr, exc, 2 * L_SUBFR, st->pitch, &T0_min, &T0_max, &T0, &T0_frac, h1, xn, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf );
- tbe_celp_exc( st->element_mode, st->idchan, bwe_exc, L_frame, 2 * L_SUBFR, i_subfr, T0, T0_frac, &error, st->tdm_LRTD_flag );
+ tbe_celp_exc_flt( st->element_mode, st->idchan, bwe_exc, L_frame, 2 * L_SUBFR, i_subfr, T0, T0_frac, &error, st->tdm_LRTD_flag );
/*-----------------------------------------------------------------*
* Find adaptive exitation
diff --git a/lib_enc/pre_proc.c b/lib_enc/pre_proc.c
index 904fdcc4b0c1f764cc53e273a3384f60dd12f8ae..838d3e9f284b14be8f2ec7b6b7c44be60fdc6df4 100644
--- a/lib_enc/pre_proc.c
+++ b/lib_enc/pre_proc.c
@@ -916,7 +916,7 @@ void pre_proc(
}
else if ( st->input_Fs > 8000 )
{
- lerp( st->old_inp_12k8 + L_INP_MEM - L_INP_MEM * 4 / 5, st->old_inp_16k, L_INP_MEM, L_INP_MEM * 4 / 5 );
+ lerp_flt( st->old_inp_12k8 + L_INP_MEM - L_INP_MEM * 4 / 5, st->old_inp_16k, L_INP_MEM, L_INP_MEM * 4 / 5 );
}
if ( sr_core_tmp == INT_FS_16k && st->tcxonly && st->codec_mode == MODE2 )
diff --git a/lib_enc/pvq_core_enc.c b/lib_enc/pvq_core_enc.c
index 0a8b7954d5faaf616735199718ab0f8b196ddd5e..61f5a10ee742d6f81234a02b0226f9b83177e05b 100644
--- a/lib_enc/pvq_core_enc.c
+++ b/lib_enc/pvq_core_enc.c
@@ -131,7 +131,7 @@ static void pvq_encode_band(
js = idx_sort[Np - 1 - j];
- pool_part = shrtCDivSignedApprox( pool_tot, Np - j );
+ pool_part = shrtCDivSignedApprox_flt( pool_tot, Np - j );
bits_part[js] = max( 0, min( bits_part[js] + pool_part, 256 ) );
conservativeL1Norm( dim_part[js], bits_part[js], strict_bits, *bits_left, pool_tot, *npulses, /* inputs */
@@ -421,7 +421,7 @@ static void densityIndexSymbolEncode(
if ( ( 0xFFFE & density ) != 0 ) /* even */
{
- angle = atan2_fx( SQRT_DIM_fx[opp_sz], SQRT_DIM_fx[near_sz] );
+ angle = atan2_fx_flt( SQRT_DIM_fx[opp_sz], SQRT_DIM_fx[near_sz] );
#ifndef BASOP_NOGLOB
angle = shl( angle, 1 );
#else /* BASOP_NOGLOB */
diff --git a/lib_enc/swb_pre_proc.c b/lib_enc/swb_pre_proc.c
index 5bbc461cd154cc355a2141171883e3b93dd17416..7038d964df7d77c0f96dd1f9109083c80f52741a 100644
--- a/lib_enc/swb_pre_proc.c
+++ b/lib_enc/swb_pre_proc.c
@@ -418,7 +418,7 @@ void swb_pre_proc(
{
if ( st->bwidth == SWB )
{
- lerp( st->input - hCPE->hStereoDft->dft_ovl, spchTmp, dft_ovl32k - Sample_Delay_SWB_BWE32k, hCPE->hStereoDft->dft_ovl - Sample_Delay_SWB_BWE );
+ lerp_flt( st->input - hCPE->hStereoDft->dft_ovl, spchTmp, dft_ovl32k - Sample_Delay_SWB_BWE32k, hCPE->hStereoDft->dft_ovl - Sample_Delay_SWB_BWE );
mvr2r( spchTmp, hBWE_FD->old_wtda_swb + L_FRAME32k - ( dft_ovl32k - Sample_Delay_SWB_BWE32k ), dft_ovl32k - Sample_Delay_SWB_BWE32k );
}
@@ -456,7 +456,7 @@ void swb_pre_proc(
}
else
{
- lerp( hBWE_FD->old_fdbwe_speech, new_swb_speech, inner_frame, L_FRAME48k );
+ lerp_flt( hBWE_FD->old_fdbwe_speech, new_swb_speech, inner_frame, L_FRAME48k );
}
if ( st->element_mode == IVAS_CPE_DFT && st->idchan == 0 )
@@ -690,7 +690,7 @@ void swb_pre_proc(
}
/* Dirty downsampling to match Nyquist to upper frequency limit of target */
- lerp( st->input, new_swb_speech, L_resamp, (int16_t) ( input_Fs / 50 ) );
+ lerp_flt( st->input, new_swb_speech, L_resamp, (int16_t) ( input_Fs / 50 ) );
/* flip the spectrum */
mvr2r( new_swb_speech, spchTmp, L_resamp );
@@ -700,7 +700,7 @@ void swb_pre_proc(
}
/* Dirty upsampling to match Nyquist/2 to lower frequency limit of target (reversed spectrum)*/
- lerp( spchTmp, spchTmp2, L_FRAME32k, L_resamp );
+ lerp_flt( spchTmp, spchTmp2, L_FRAME32k, L_resamp );
mvr2r( spchTmp2, spchTmp, L_FRAME32k );
}
else
diff --git a/lib_enc/tcq_core_enc.c b/lib_enc/tcq_core_enc.c
index 03164a3237475fa11cc0f8b7a67610cfe0a5d085..be8325bf24b63e13fb477d0cea83e3a641ee6b0c 100644
--- a/lib_enc/tcq_core_enc.c
+++ b/lib_enc/tcq_core_enc.c
@@ -213,7 +213,7 @@ ivas_error tcq_core_LR_enc(
if ( input_frame <= L_FRAME16k && adjustFlag == 0 && is_transient == 0 )
{
surplus_fx = -131072;
- bit_allocation_second_fx( Rk_fx, Rk_sort_fx, BANDS, sfmsize, k_sort, k_num, p2a_flags, p2a_bands, last_bitalloc, input_frame );
+ bit_allocation_second_fx2( Rk_fx, Rk_sort_fx, BANDS, sfmsize, k_sort, k_num, p2a_flags, p2a_bands, last_bitalloc, input_frame );
nzbands = 0;
for ( j = 0; j < BANDS; j++ )
diff --git a/lib_enc/transition_enc.c b/lib_enc/transition_enc.c
index f879066b1362744218302b725c53b9ea5466ad2f..c02e94047802c3fe6a040505c00cce4d591bffc1 100644
--- a/lib_enc/transition_enc.c
+++ b/lib_enc/transition_enc.c
@@ -243,7 +243,7 @@ void transition_enc(
/* Find the closed loop pitch period */
*T0 = pitch_fr4( &exc[i_subfr], xn, h1, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, pit_start, pit_limit, L_FRAME, L_SUBFR );
- offset = tbe_celp_exc_offset( *T0, *T0_frac );
+ offset = tbe_celp_exc_offset_flt( *T0, *T0_frac );
for ( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ )
{
bwe_exc[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc[i + i_subfr * HIBND_ACB_L_FAC - offset];
@@ -329,7 +329,7 @@ void transition_enc(
/* Find the adaptive codebook vector - ACELP long-term prediction */
pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, inter4_2, L_INTERPOL2, PIT_UP_SAMP );
- offset = tbe_celp_exc_offset( *T0, *T0_frac );
+ offset = tbe_celp_exc_offset_flt( *T0, *T0_frac );
for ( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ )
{
bwe_exc[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc[i + i_subfr * HIBND_ACB_L_FAC - offset];
@@ -369,7 +369,7 @@ void transition_enc(
/* Find the adaptive codebook vector - ACELP long-term prediction */
pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, inter4_2, L_INTERPOL2, PIT_UP_SAMP );
- offset = tbe_celp_exc_offset( *T0, *T0_frac );
+ offset = tbe_celp_exc_offset_flt( *T0, *T0_frac );
for ( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ )
{
bwe_exc[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc[i + i_subfr * HIBND_ACB_L_FAC - offset];
@@ -425,7 +425,7 @@ void transition_enc(
/* Find the adaptive codebook vector - ACELP long-term prediction */
pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, inter4_2, L_INTERPOL2, PIT_UP_SAMP );
- offset = tbe_celp_exc_offset( *T0, *T0_frac );
+ offset = tbe_celp_exc_offset_flt( *T0, *T0_frac );
for ( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ )
{
bwe_exc[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc[i + i_subfr * HIBND_ACB_L_FAC - offset];
@@ -446,7 +446,7 @@ void transition_enc(
/* Find the adaptive codebook vector - ACELP long-term prediction */
pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, inter4_2, L_INTERPOL2, PIT_UP_SAMP );
- offset = tbe_celp_exc_offset( *T0, *T0_frac );
+ offset = tbe_celp_exc_offset_flt( *T0, *T0_frac );
for ( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ )
{
bwe_exc[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc[i + i_subfr * HIBND_ACB_L_FAC - offset];
@@ -476,7 +476,7 @@ void transition_enc(
/* Find the adaptive codebook vector - ACELP long-term prediction */
pred_lt4( &exc[i_subfr], &exc[i_subfr], *T0, *T0_frac, L_SUBFR + 1, inter4_2, L_INTERPOL2, PIT_UP_SAMP );
- offset = tbe_celp_exc_offset( *T0, *T0_frac );
+ offset = tbe_celp_exc_offset_flt( *T0, *T0_frac );
for ( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ )
{
bwe_exc[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc[i + i_subfr * HIBND_ACB_L_FAC - offset];