diff --git a/Workspace_msvc/lib_com.vcxproj b/Workspace_msvc/lib_com.vcxproj
index de047134c3691533f63be592a615a3c50981544c..e1fbbd2ec18fe79d2130fcffaa5065431c6cdd3a 100644
--- a/Workspace_msvc/lib_com.vcxproj
+++ b/Workspace_msvc/lib_com.vcxproj
@@ -297,6 +297,7 @@
+
diff --git a/Workspace_msvc/lib_com.vcxproj.filters b/Workspace_msvc/lib_com.vcxproj.filters
index b39c6d3cc532e0e3e8944a8ac4e08beaa1de1f75..b1857db14a628abed083afe6d38a62d5caa97ec7 100644
--- a/Workspace_msvc/lib_com.vcxproj.filters
+++ b/Workspace_msvc/lib_com.vcxproj.filters
@@ -346,6 +346,7 @@
common_ivas_c
+
diff --git a/lib_com/ari_hm_fx.c b/lib_com/ari_hm_fx.c
index 6d2f725f98ef0c7e4b58f488b46e6d636543b1f0..10dce353a6ebe1c56e54c117aa709b74b87a28c3 100644
--- a/lib_com/ari_hm_fx.c
+++ b/lib_com/ari_hm_fx.c
@@ -14,10 +14,10 @@
#define GET_ADJ2(T,L,F) (((L) << (F)) - (T))
void UnmapIndex(
- Word16 PeriodicityIndex,
- Word16 Bandwidth,
- Word16 LtpPitchLag,
- Word8 SmallerLags,
+ const Word16 PeriodicityIndex,
+ const Word16 Bandwidth,
+ const Word16 LtpPitchLag,
+ const Word16 SmallerLags,
Word16 *FractionalResolution,
Word32 *Lag
)
@@ -79,10 +79,10 @@ void UnmapIndex(
void ConfigureContextHm(
- Word16 NumCoeffs, /* (I) Number of coefficients */
- Word16 TargetBits, /* (I) Target bit budget (excl. Done flag) */
- Word16 PeriodicityIndex, /* (I) Pitch related index */
- Word16 LtpPitchLag, /* (I) TCX-LTP pitch in F.D. */
+ const Word16 NumCoeffs, /* (I) Number of coefficients */
+ const Word16 TargetBits, /* (I) Target bit budget (excl. Done flag) */
+ const Word16 PeriodicityIndex, /* (I) Pitch related index */
+ const Word16 LtpPitchLag, /* (I) TCX-LTP pitch in F.D. */
CONTEXT_HM_CONFIG *hm_cfg /* (O) Context-based harmonic model configuration */
)
{
@@ -94,7 +94,7 @@ void ConfigureContextHm(
Bandwidth = 0;
move16();
- if (GE_16(NumCoeffs, 256))
+ IF (GE_16(NumCoeffs, 256))
{
Bandwidth = 1;
move16();
@@ -103,7 +103,7 @@ void ConfigureContextHm(
SmallerLags = 0;
move16();
test();
- if ((LE_16(TargetBits, kSmallerLagsTargetBitsThreshold))||(Bandwidth==0))
+ IF ((LE_16(TargetBits, kSmallerLagsTargetBitsThreshold))||(Bandwidth==0))
{
SmallerLags = 1;
move16();
diff --git a/lib_com/bitstream_fx.c b/lib_com/bitstream_fx.c
index eed1ede3887cf460f9c38d9483d6df81cab14989..d1f766ff2cc3a1d44c8055770f827695bb8c6f74 100644
--- a/lib_com/bitstream_fx.c
+++ b/lib_com/bitstream_fx.c
@@ -505,8 +505,10 @@ UWord16 get_indice_1_fx( /* o : value of the indice */
Word16 pos /* i : absolute position in the bitstream (update after the read) */
)
{
+ Word16 nbits_total;
+ nbits_total = (Word16)(st_fx->total_brate / FRAMES_PER_SEC);
/* detect corrupted bitstream */
- IF(GT_16(add(pos, 1), st_fx->total_num_bits))
+ IF(GT_16(add(pos, 1), nbits_total))
{
st_fx->BER_detect = 1;
move16();
diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h
index 15c95e49ffe4b3190470c44e2c3fdee115a688fc..b91f439e89b55ae856724ccf12d0ecb04f326469 100644
--- a/lib_com/ivas_prot.h
+++ b/lib_com/ivas_prot.h
@@ -1738,6 +1738,11 @@ void rc_uni_dec_init(
uint16_t *bit_buffer, /* i : Bit buffer */
const int16_t max_available_bits /* i : Total maximum bits available */
);
+void rc_uni_dec_init_fx(
+ RangeUniDecState *rc_st_dec, /* i/o: RC state handle */
+ UWord16 *bit_buffer, /* i : Bit buffer */
+ const Word16 max_available_bits /* i : Total maximum bits available */
+);
/*! r: Read symbol */
uint16_t rc_uni_dec_read_symbol_fastS(
@@ -1747,6 +1752,14 @@ uint16_t rc_uni_dec_read_symbol_fastS(
const uint16_t alphabet_size, /* i : Number of symbols in the alphabet */
const uint16_t tot_shift /* i : Total frequency as a power of 2 */
);
+/*! r: Read symbol */
+UWord16 rc_uni_dec_read_symbol_fastS_fx(
+ RangeUniDecState *rc_st_dec, /* i/o: Decoder State */
+ const UWord16 cum_freq_table[], /* i : Cumulative frequency up to symbol */
+ const UWord16 sym_freq_table[], /* i : Symbol frequency */
+ const UWord16 alphabet_size, /* i : Number of symbols in the alphabet */
+ const UWord16 tot_shift /* i : Total frequency as a power of 2 */
+);
/*! r: Read bit */
uint16_t rc_uni_dec_read_bit(
@@ -1771,6 +1784,9 @@ int16_t rc_uni_dec_virtual_finish(
RangeUniDecState *rc_st_dec /* i/o: RC state handle */
);
+Word16 rc_uni_dec_virtual_finish_fx(
+ RangeUniDecState *rc_st_dec /* i/o: RC state handle */
+);
/*! r: Total number of bits consumed */
int16_t rc_uni_dec_finish(
RangeUniDecState *rc_st_dec /* i/o: RC state handle */
diff --git a/lib_com/parameter_bitmaping_fx.c b/lib_com/parameter_bitmaping_fx.c
new file mode 100644
index 0000000000000000000000000000000000000000..bedb40394e4e24fe6d0e75e948b13adbdee763d2
--- /dev/null
+++ b/lib_com/parameter_bitmaping_fx.c
@@ -0,0 +1,76 @@
+#include
+#include
+#include "options.h"
+#include "stat_com.h"
+#include "prot_fx2.h"
+#include "wmc_auto.h"
+
+/** Get nBits long value from bitstream into *pStream. */
+static Word16 GetFromBitstream(
+ Decoder_State *st,
+ TDecodeValue DecodeValue,
+ UWord16 index,
+ Word16 nFixedBits,
+ Word16 **pStream )
+{
+ Word16 value = 0;
+ move16();
+ move16();
+ value = 0;
+ IF( DecodeValue != NULL )
+ {
+ DecodeValue( st, index, &value );
+ }
+ ELSE
+ {
+ // value = get_next_indice_fx(st, nFixedBits);
+ value = get_next_indice_fx( st, nFixedBits );
+ }
+ move16();
+ *( *pStream )++ = value;
+
+ return value;
+}
+
+void ReadFromBitstream_fx(
+ ParamsBitMap const *paramsBitMap,
+ const Word16 nArrayLength,
+ Decoder_State *st,
+ Word16 **pStream,
+ Word16 *pnSize )
+{
+ Word16 index;
+ Word16 iParam, nParams;
+ Word16 fShiftValue;
+ Word16 value;
+
+ assert( ( paramsBitMap != NULL ) && GT_16( nArrayLength, 0 ) && ( pStream != NULL ) && ( pnSize != NULL ) && ( st != NULL ) );
+ move16();
+ nParams = paramsBitMap->nParams;
+ FOR( index = 0; index < nArrayLength; index++ )
+ {
+ FOR( iParam = 0; iParam < nParams; iParam++ )
+ {
+ ParamBitMap const *param;
+ /* If a function for encoding/decoding value is defined than it should take care of 0 */
+ move16();
+ param = ¶msBitMap->params[iParam];
+ test();
+ test();
+ fShiftValue = s_and( (Word16)EQ_16( param->fZeroAllowed, 0 ), param->EncodeValue == NULL );
+ value = GetFromBitstream( st, param->DecodeValue, index, param->nBits, pStream );
+ IF( fShiftValue )
+ {
+ move16();
+ value = add( value, 1 );
+ }
+
+ IF( ( param->pSubParamBitMap != NULL ) && GT_16( value, 0 ) )
+ {
+ ReadFromBitstream_fx( param->pSubParamBitMap, value, st, pStream, pnSize );
+ }
+ }
+ }
+ move16();
+ *pnSize = add( *pnSize, i_mult( nParams, nArrayLength ) );
+}
\ No newline at end of file
diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h
index d5952d04a5b7fc27c8e7f23e12f9cc2dbea5f716..04abf4fab707e89734aad4c6cf84bc8af787ae99 100644
--- a/lib_com/prot_fx2.h
+++ b/lib_com/prot_fx2.h
@@ -82,7 +82,7 @@ Word16 Q_factor_arrL(float* x, Word16 l);
Word32 floatToFixed(const float f, Word16 Q);
float fixedToFloat(const Word32 i, Word16 Q);
-Word32 Mult_32_16(
+ Word32 Mult_32_16(
Word32 a,
Word16 b);
@@ -696,6 +696,11 @@ void v_sort(Word16 *r, const Word16 lo, const Word16 up);
void compute_poly_product_fx(Word16 *coef, Word32 *p, Word16 order);
+void dec_prm_hm(
+ Decoder_State *st,
+ Word16 *prm_hm,
+ const Word16 L_frame
+);
void msvq_dec
(
const Word16 *const*cb, /* i : Codebook (indexed cb[*stages][levels][p]) (0Q15) */
@@ -984,6 +989,9 @@ void push_next_bits_fx(
UWord16 get_next_indice_1( /* o : value of the indice */
Decoder_State *st_fx /* i/o: decoder state structure */
);
+UWord16 get_next_indice_1_fx( /* o : value of the indice */
+ Decoder_State *st_fx /* i/o: decoder state structure */
+);
UWord16 get_next_indice_1_fx( /* o : value of the indice */
Decoder_State *st_fx /* i/o: decoder state structure */
@@ -3597,8 +3605,8 @@ void SetAllowTnsOnWhite(
void SetTnsConfig(
TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */
- Word8 isTCX20,
- Word8 isAfterACELP
+ const Word16 isTCX20,
+ const Word16 isAfterACELP
);
void tcx_get_gain(Word32 *x, /* i: spectrum 1 */
@@ -4764,11 +4772,11 @@ Word16 tcx_ltp_decode_params(Word16 *ltp_param,
Word16 *pitch_int,
Word16 *pitch_fr,
Word16 *gain,
- Word16 pitmin,
- Word16 pitfr1,
- Word16 pitfr2,
- Word16 pitmax,
- Word16 pitres
+ const Word16 pitmin,
+ const Word16 pitfr1,
+ const Word16 pitfr2,
+ const Word16 pitmax,
+ const Word16 pitres
);
void tcx_ltp_post(
@@ -7147,7 +7155,7 @@ void init_tcx_cfg_fx(
Word16
DecodeIndex_fx(
Decoder_State *st,
- Word16 Bandwidth,
+ const Word16 Bandwidth,
Word16 *PeriodicityIndex);
void tcx_hm_decode(
const Word16 L_frame, /* i : number of spectral lines */
@@ -7258,6 +7266,18 @@ Word16 ari_decode_14bits_pow(Word16 *ptr, Word16 bp, Word16 bits, Word16 *res, T
Word16 ari_decode_14bits_sign(Word16 *ptr, Word16 bp, Word16 bits, Word16 *res, Tastat *s);
//dec_prm_fx.c
+void getTCXparam(
+ Decoder_State *st, /* i/o: Decoder State handle */
+ Decoder_State *st0, /* i : bitstream */
+ CONTEXT_HM_CONFIG hm_cfg, /* i/o: HM config */
+ Word16 param[], /* o : decoded parameters */
+ const Word16 bits_common, /* i : number of common bits */
+ const Word16 start_bit_pos, /* i : position of the start bit */
+ const Word16 *no_param_tns, /* i : number of TNS parameters per subframe */
+ Word16 p_param[2], /* o : pointer to parameters for next round of bs reading*/
+ Word16 nTnsBitsTCX10[2],
+ const Word16 pre_past_flag
+);
void dec_prm(
Word16 *coder_type,
Word16 param[], /* (o) : decoded parameters */
@@ -7278,18 +7298,18 @@ void getLPCparam(
//ari_hm_fx.c
void UnmapIndex(
- Word16 PeriodicityIndex,
- Word16 Bandwidth,
- Word16 LtpPitchLag,
- Word8 SmallerLags,
+ const Word16 PeriodicityIndex,
+ const Word16 Bandwidth,
+ const Word16 LtpPitchLag,
+ const Word16 SmallerLags,
Word16 *FractionalResolution,
Word32 *Lag);
void ConfigureContextHm(
- Word16 NumCoeffs, /* (I) Number of coefficients */
- Word16 TargetBits, /* (I) Target bit budget (excl. Done flag) */
- Word16 PeriodicityIndex, /* (I) Pitch related index */
- Word16 LtpPitchLag, /* (I) TCX-LTP pitch in F.D. */
+ const Word16 NumCoeffs, /* (I) Number of coefficients */
+ const Word16 TargetBits, /* (I) Target bit budget (excl. Done flag) */
+ const Word16 PeriodicityIndex, /* (I) Pitch related index */
+ const Word16 LtpPitchLag, /* (I) TCX-LTP pitch in F.D. */
CONTEXT_HM_CONFIG *hm_cfg /* (O) Context-based harmonic model configuration */
);
@@ -7313,6 +7333,7 @@ void tcx_hm_modify_envelope(
);
//tns_base_dec_fx.c
+#define IVAS_CODE
#ifdef IVAS_CODE
void
#else
@@ -7323,6 +7344,7 @@ ReadTnsData(STnsConfig const * pTnsConfig,
Word16 * pnBits,
Word16 * stream,
Word16 * pnSize);
+#undef IVAS_CODE
Word16 DecodeTnsData(STnsConfig const * pTnsConfig,
Word16 const * stream,
@@ -7373,6 +7395,13 @@ void ReadFromBitstream(
int16_t **pStream,
int16_t *pnSize);
+void ReadFromBitstream_fx(
+ ParamsBitMap const *paramsBitMap,
+ const Word16 nArrayLength,
+ Decoder_State *st,
+ Word16 **pStream,
+ Word16 *pnSize
+);
//igf_dec_fx.c
void IGFDecReadData(const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Deccoder */
Decoder_State *st, /**< in: | decoder state */
@@ -7530,6 +7559,14 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC(
Word16 resQMaxBits, /* i: residual coding maximum bits*/
CONTEXT_HM_CONFIG *hm_cfg /* i: context-based harmonic model configuration */
);
+Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx(
+ Decoder_State *st, /* i/o: decoder state */
+ Word16 *x, /* o : decoded spectrum */
+ const Word16 nt, /* i : size of spectrum */
+ const Word16 nbbits, /* i : bit budget */
+ const Word16 resQMaxBits, /* i : residual coding maximum bits */
+ CONTEXT_HM_CONFIG *hm_cfg /* i : context-based harmonic model configuration*/
+);
//core_dec_reconf_fx.c
void reconfig_decoder_LPD(Decoder_State *st, Word16 bits_frame, Word16 bandwidth_mode, Word32 bitrate, Word16 L_frame_old);
diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h
index 52241e19482120aafe633ea343bd77759b759653..5030f387f95768963f9a4b913b27637c3efbee97 100644
--- a/lib_com/stat_com.h
+++ b/lib_com/stat_com.h
@@ -341,6 +341,12 @@ typedef struct
uint32_t value;
int32_t bits_to_follow;
} Tastat;
+#ifdef IVAS_FLOAT_FIXED
+typedef struct
+{
+ Word32 low, high, value;
+} TastatDec;
+#endif // IVAS_FLOAT_FIXED
/*---------------------------------------------------------------*
* FD CNG common structure *
@@ -535,7 +541,7 @@ typedef int16_t ( *TEncodeValue )( int16_t value, int16_t index );
* @param pValue A pointer where the decoded value should be stored.
* @return Number of bits read from the bitstream.
*/
-typedef int16_t ( *TDecodeValue )( struct Decoder_State *st, int16_t index, int16_t *pValue );
+typedef Word16 ( *TDecodeValue )( struct Decoder_State *st, Word16 index, Word16 *pValue );
/** Linear prediction analysis/synthesis filter definition.
* @param order filter order.
diff --git a/lib_com/tcx_ltp_fx.c b/lib_com/tcx_ltp_fx.c
index 2ffe0d99c07db518a1bcb359d20138840641005e..6a77d13278e2e9c90388d736eb70bfebf44aa7f7 100644
--- a/lib_com/tcx_ltp_fx.c
+++ b/lib_com/tcx_ltp_fx.c
@@ -384,11 +384,11 @@ Word16 tcx_ltp_decode_params(
Word16 *pitch_int,
Word16 *pitch_fr,
Word16 *gain,
- Word16 pitmin,
- Word16 pitfr1,
- Word16 pitfr2,
- Word16 pitmax,
- Word16 pitres
+ const Word16 pitmin,
+ const Word16 pitfr1,
+ const Word16 pitfr2,
+ const Word16 pitmax,
+ const Word16 pitres
)
{
Word16 tmp, tmp2;
@@ -407,21 +407,21 @@ Word16 tcx_ltp_decode_params(
*pitch_int = add(pitmin, tmp2);
move16();
+ tmp2 = sub( *pitch_int, pitmin );
*pitch_fr = sub(ltp_param[1], imult1616(tmp2, pitres));
move16();
}
ELSE
{
- pitres = shr(pitres, 1);
- tmp2 = imult1616(sub(pitfr1, pitfr2), pitres);
+ tmp2 = imult1616(sub(pitfr1, pitfr2),shr( pitres, 1 ));
IF ( LT_16(ltp_param[1], add(tmp, tmp2)))
{
- tmp2 = idiv1616U(sub(ltp_param[1], tmp), pitres);
+ tmp2 = idiv1616U(sub(ltp_param[1], tmp),shr( pitres,1));
*pitch_int = add(pitfr2, tmp2);
move16();
- *pitch_fr = shl( sub(sub(ltp_param[1], tmp), imult1616(tmp2, pitres)), 1 );
+ *pitch_fr = shl( sub(sub(ltp_param[1], tmp), imult1616(tmp2,shr( pitres,1 ))), 1 );
move16();
}
ELSE
diff --git a/lib_com/tcx_utils_fx.c b/lib_com/tcx_utils_fx.c
index 4af5315b36641c20ab0d15c7bd367b56fab8bdd5..0ff6259ee7b64ff910e9a9f42eda1fcb6ff079ca 100644
--- a/lib_com/tcx_utils_fx.c
+++ b/lib_com/tcx_utils_fx.c
@@ -1732,8 +1732,8 @@ void InitTnsConfigs(
void SetTnsConfig(
TCX_CONFIG_HANDLE hTcxCfg, /* i : configuration of TCX */
- Word8 isTCX20,
- Word8 isAfterACELP
+ const Word16 isTCX20,
+ const Word16 isAfterACELP
)
{
move16();
diff --git a/lib_dec/ACcontextMapping_dec_fx.c b/lib_dec/ACcontextMapping_dec_fx.c
index 5fcc16b2e0d835f2deb2b8c5bdd6139fd700de04..51f778c255e085897e7ed43817f2b81a0d29f0e7 100644
--- a/lib_dec/ACcontextMapping_dec_fx.c
+++ b/lib_dec/ACcontextMapping_dec_fx.c
@@ -12,6 +12,8 @@
#include "prot_fx1.h"
#include "prot_fx2.h"
+#include "ivas_prot.h"
+#include "ivas_rom_com.h"
/*-------------------------------------------------------------------*
* ACcontextMapping_decode2_no_mem_s17_LC()
*
@@ -29,10 +31,12 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC(
{
Tastat as;
Word16 start_bit_pos, lsbs_bit_pos, overflow_bit_pos;
- Word16 a, b, t, a1, b1, a1_i, b1_i, k, L;
+ Word16 a, b, a1, b1, a1_i, b1_i, k, L;
+ UWord16 t;
Word16 lev, pki, esc_nb;
Word16 rateFlag;
- Word16 r, lastnz, n;
+ Word16 lastnz, n;
+ UWord16 r;
Word16 resQBits;
Word16 rest_bits, rest_bits_overflow;
Word16 tmp=0; /* initialize just to avoid compiler warning */
@@ -53,7 +57,7 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC(
/* Rate flag */
rateFlag = 0;
move16();
- if (GT_16(nbbits, 400))
+ IF (GT_16(nbbits, 400))
{
rateFlag = 2 << NBITS_CONTEXT;
move16();
@@ -68,7 +72,7 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC(
move16();
L = sub(14, norm_s(negate(nt)));
- n = add(get_next_indice(st, L), 1);
+ n = add(get_next_indice_fx(st, L), 1);
/* Init */
nt_half = shr(nt, 1);
@@ -107,6 +111,7 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC(
move16();
ii[1] = 0;
move16();
+ p1 = p2 = 0; /* to avoid compilation warnings */
get_next_coeff = get_next_coeff_mapped;
move16();
@@ -149,13 +154,14 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC(
move16();
t = add(*ctx, rateFlag);
- if (GT_16(idx, nt_half))
+ IF (GT_16(idx, nt_half))
{
t = add(t, 1 << NBITS_CONTEXT);
}
test();
- IF (t < 0 || lsbs_bit_pos <= 0)
+ /* BER detection: Check max value of context t leading to out-of-bound access to ari_lookup_s17_LC[]*/
+ IF( GE_16(t , ( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ) ) || LE_16( lsbs_bit_pos, 0 ) )
{
st->BER_detect = 1;
move16();
@@ -208,11 +214,11 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC(
/*lsbs bits sign bits*/
rest_bits = add(rest_bits, shl(lev, 1));
- if (a > 0)
+ IF (a > 0)
{
rest_bits = add(rest_bits, 1);
}
- if (b > 0)
+ IF (b > 0)
{
rest_bits = add(rest_bits, 1);
}
@@ -243,12 +249,12 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC(
move16();
/* Update context for next 2-tuple */
- IF (EQ_16(p1, p2)) /* peak-peak or hole-hole context */
+ IF (EQ_32(p1, p2)) /* peak-peak or hole-hole context */
{
lev = sub(esc_nb, 1);
- if (lev > 0) t = add(12, lev);
- if (lev <= 0) t = add(a1, b1);
- if (lev == 0) t = add(t, t);
+ IF (lev > 0) t = add(12, lev);
+ IF (lev <= 0) t = add(a1, b1);
+ IF (lev == 0) t = add(t, t);
*ctx = add(shl(s_and(*ctx, 0xf), 4), add(t, 1));
move16();
@@ -281,12 +287,12 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC(
}
/*Decode signs*/
- if (hm_cfg)
+ IF (hm_cfg)
{
tmp = nt;
move16();
}
- if (!hm_cfg)
+ IF (!hm_cfg)
{
tmp = lastnz;
move16();
@@ -295,7 +301,7 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC(
{
IF (x[k] > 0)
{
- if (get_next_indice_1(st) != 0)
+ IF (get_next_indice_1_fx(st) != 0)
{
x[k] = negate(x[k]);
move16();
@@ -317,6 +323,7 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC(
return resQBits;
}
+#define IVAS_CONTEXT_MAPPING
#ifdef IVAS_CONTEXT_MAPPING
/*-------------------------------------------------------------------*
@@ -326,73 +333,73 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC(
*-------------------------------------------------------------------*/
/*! r: resQBits */
-int16_t RCcontextMapping_decode2_no_mem_s17_LCS(
+Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx(
Decoder_State* st, /* i/o: decoder state */
- int16_t* x, /* o : decoded spectrum */
- const int16_t nt, /* i : size of spectrum */
- const int16_t nbbits, /* i : bit budget */
- const int16_t resQMaxBits, /* i : residual coding maximum bits */
+ Word16* x, /* o : decoded spectrum */
+ const Word16 nt, /* i : size of spectrum */
+ const Word16 nbbits, /* i : bit budget */
+ const Word16 resQMaxBits, /* i : residual coding maximum bits */
CONTEXT_HM_CONFIG* hm_cfg /* i : context-based harmonic model configuration*/
)
{
RangeUniDecState rc_st_dec; /* State of the range decoder */
- int16_t start_bit_pos, lsbs_bit_pos;
- int16_t a, b, a1, b1, k;
- uint16_t t;
- int16_t lev, pki, esc_nb;
- int16_t rateFlag;
- int16_t lastnz, n;
- uint16_t r;
- int16_t resQBits;
- int16_t rest_bits;
- int16_t nt_half;
- int16_t nbbits_m2;
- int16_t bits_tups; /* No. of bits for coding the no. of tuples */
-
- set_s(x, 0, nt);
+ Word16 start_bit_pos, lsbs_bit_pos;
+ Word16 a, b, a1, b1, k;
+ UWord16 t;
+ Word16 lev, pki, esc_nb;
+ Word16 rateFlag;
+ Word16 lastnz, n;
+ UWord16 r;
+ Word16 resQBits;
+ Word16 rest_bits;
+ Word16 nt_half;
+ Word16 nbbits_m2;
+ Word16 bits_tups; /* No. of bits for coding the no. of tuples */
+
+ set16_fx(x, 0, nt);
/*Decode number of ntuples*/
start_bit_pos = st->next_bit_pos;
- lsbs_bit_pos = start_bit_pos + nbbits - 1;
+ lsbs_bit_pos = add( start_bit_pos, sub( nbbits, 1 ) );
n = 0;
k = 1;
- nt_half = nt >> 1;
+ nt_half = shr( nt, 1 );
- while (k < nt_half)
+ WHILE( LT_16( k, nt_half ) )
{
- ++n;
- k = k << 1;
+ n = add( n, 1 );
+ k = shl( k, 1 );
}
bits_tups = n;
- n = get_next_indice(st, n) + 1;
+ n = get_next_indice_fx( st, n ) + 1;
t = 0;
- lastnz = n << 1;
+ lastnz = shl( n, 1 );
- if (lastnz > nt)
+ IF( GT_16( lastnz, nt ) )
{
st->BER_detect = 1;
return 0;
}
- if (hm_cfg)
+ IF( hm_cfg )
{
- int16_t a1_i, b1_i;
- int32_t c[2], * ctx;
- int32_t p1, p2;
- int16_t ii[2];
- int16_t idx1, idx2, idx;
- int16_t numPeakIndicesOrig, numHoleIndices;
+ Word16 a1_i, b1_i;
+ Word16 c[2], * ctx;
+ Word16 p1, p2;
+ Word16 ii[2];
+ Word16 idx1, idx2, idx;
+ Word16 numPeakIndicesOrig, numHoleIndices;
/* Rate flag */
- if (nbbits > 400)
+ IF( GT_16( nbbits, 400 ) )
{
rateFlag = 2 << NBITS_CONTEXT;
}
- else
+ ELSE
{
rateFlag = 0;
}
@@ -402,13 +409,13 @@ int16_t RCcontextMapping_decode2_no_mem_s17_LCS(
/* mapped domain */
numPeakIndicesOrig = hm_cfg->numPeakIndices;
- hm_cfg->numPeakIndices = min(hm_cfg->numPeakIndices, lastnz);
- numHoleIndices = lastnz - hm_cfg->numPeakIndices;
+ hm_cfg->numPeakIndices = s_min(hm_cfg->numPeakIndices, lastnz);
+ numHoleIndices = sub( lastnz, hm_cfg->numPeakIndices);
/* Mark hole indices beyond lastnz as pruned */
- for (k = numHoleIndices; k < hm_cfg->numHoleIndices; ++k)
+ FOR(k = numHoleIndices; k < hm_cfg->numHoleIndices; ++k)
{
- hm_cfg->holeIndices[k] = hm_cfg->holeIndices[k] + nt;
+ hm_cfg->holeIndices[k] = add( hm_cfg->holeIndices[k], nt);
}
ii[0] = numPeakIndicesOrig;
@@ -418,29 +425,32 @@ int16_t RCcontextMapping_decode2_no_mem_s17_LCS(
/* Start Decoding */
/* Initialize range decoder */
- rc_uni_dec_init(&rc_st_dec, &st->bit_stream[st->next_bit_pos], nbbits); /* (nbbits + 30) entries are read by the decoder */
+ rc_uni_dec_init_fx(&rc_st_dec, &st->bit_stream[st->next_bit_pos], nbbits); /* (nbbits + 30) entries are read by the decoder */
nbbits_m2 = nbbits;
- rest_bits = -nbbits_m2;
+ rest_bits = negate(nbbits_m2);
/* Main Loop through the 2-tuples */
- for (k = 0; k < lastnz; k += 2)
+ FOR(k = 0; k < lastnz; k += 2)
{
a1_i = get_next_coeff_mapped(ii, &p1, &idx1, hm_cfg);
b1_i = get_next_coeff_mapped(ii, &p2, &idx2, hm_cfg);
- idx = min(idx1, idx2);
+ idx = s_min(idx1, idx2);
/* Get context */
- ctx = &c[p1 | p2];
+ ctx = &c[s_or(p1, p2)];
- t = (uint16_t)(*ctx + rateFlag);
- t += (nt_half >= idx) ? 0 : (1 << NBITS_CONTEXT);
+ t = add(*ctx, rateFlag);
+ IF(LT_16( nt_half, idx))
+ {
+ t = add(t, 1 << NBITS_CONTEXT);
+ }
esc_nb = 0;
r = 0;
/* BER detection: Check max value of context t leading to out-of-bound access to ari_lookup_s17_LC[]*/
- if ((t >= (1 << (NBITS_CONTEXT + NBITS_RATEQ))) || lsbs_bit_pos <= 0)
+ IF((GE_16(t , (1 << (NBITS_CONTEXT + NBITS_RATEQ)))) || lsbs_bit_pos <= 0)
{
st->BER_detect = 1;
return 0;
@@ -449,24 +459,24 @@ int16_t RCcontextMapping_decode2_no_mem_s17_LCS(
a = b = 0;
/* MSBs decoding */
- for (lev = 0; lev < 15 && lsbs_bit_pos > 0; ++lev)
+ FOR(lev = 0; lev < 15 && lsbs_bit_pos > 0; ++lev)
{
- esc_nb = min(lev, 3);
- pki = ari_lookup_s17_LC[t + (esc_nb << (NBITS_CONTEXT + NBITS_RATEQ))];
- r = rc_uni_dec_read_symbol_fastS(&rc_st_dec, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 17, 14); /*Alphabet size = 17 (2^4 = 16 MSB symbols + 1 ESC symbol) */
- /* r is the symbol read, the possible values are {0,1,....alphabet_size - 1} */
+ esc_nb = s_min(lev, 3);
+ pki = ari_lookup_s17_LC[add(t, Tab_esc_nb[esc_nb])];
+ r = rc_uni_dec_read_symbol_fastS_fx(&rc_st_dec, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 17, 14); /*Alphabet size = 17 (2^4 = 16 MSB symbols + 1 ESC symbol) */
+ /* r is the symbol read, the possible values are {0,1,....alphabet_size - 1} */
- if (r < VAL_ESC) /* If symbol read corresponds to MSB */
+ IF (LT_16(r, VAL_ESC)) /* If symbol read corresponds to MSB */
{
- break;
+ BREAK;
}
/* LSBs decoding */
- a += get_indice_1(st, lsbs_bit_pos--) << lev;
- b += get_indice_1(st, lsbs_bit_pos--) << lev;
+ a = add( a, shl( get_indice_1_fx(st, lsbs_bit_pos--) , lev));
+ b = add( b, shl( get_indice_1_fx(st, lsbs_bit_pos--) , lev));
}
- if ((lsbs_bit_pos < -1 && r >= VAL_ESC) || (lev > 14))
+ IF ((LT_16(lsbs_bit_pos , -1 ) && GE_16( r , VAL_ESC)) || GT_16(lev, 14))
{
x[a1_i] = 0;
x[b1_i] = 0;
@@ -475,19 +485,19 @@ int16_t RCcontextMapping_decode2_no_mem_s17_LCS(
}
/* MSBs contributions */
- b1 = r >> 2;
- a1 = r & 0x3;
- a += a1 << lev;
- b += b1 << lev;
+ b1 = shr( r, 2 );
+ a1 = s_and( r, 0x3 );
+ a = add( a, shl( a1, lev));
+ b = add( b, shl( b1, lev));
/* Add 2 LSB bits per bit-plane */
- rest_bits += 2 * lev;
+ rest_bits = add( rest_bits, shl( lev, 1 ) );
/* Sign bits */
- rest_bits += min(a, 1);
- rest_bits += min(b, 1);
+ rest_bits = add( rest_bits, s_min( a, 1 ) );
+ rest_bits = add( rest_bits, s_min( b, 1 ) );
/* Update bitstream pointer */
- st->next_bit_pos = start_bit_pos + bits_tups + rc_uni_dec_virtual_finish(&rc_st_dec);
+ st->next_bit_pos = add( start_bit_pos, add( bits_tups, rc_uni_dec_virtual_finish_fx( &rc_st_dec ) ) );
/* Confirm that there is no overflow */
#ifdef DEBUGGING
@@ -499,33 +509,33 @@ int16_t RCcontextMapping_decode2_no_mem_s17_LCS(
x[b1_i] = b;
/* Update context for next 2-tuple */
- if (p1 == p2)
+ IF( EQ_32( p1, p2 ) )
{
/* peak-peak or hole-hole context */
- lev = esc_nb - 1;
+ lev = sub( esc_nb, 1 );
- if (lev <= 0)
+ IF( LE_16( lev, 0 ) )
{
- t = 1 + (a1 + b1) * (lev + 2);
+ t = add( 1, imult1616( add( a1, b1 ), add( lev, 2 ) ) );
}
- else
+ ELSE
{
- t = 13 + lev;
+ t = add( 13, lev );
}
- *ctx = (*ctx & 0xf) * 16 + t;
+ *ctx = add( shl( s_and( *ctx, 0xf ), 4 ), t );
}
- else
+ ELSE
{
/* mixed context */
- if (idx1 & 1)
+ IF( s_and( idx1, 1 ) )
{
/* update first context */
c[p1] = update_mixed_context(c[p1], a);
}
- if (idx2 & 1)
+ IF( idx2 & 1 )
{
/* update second context */
c[p2] = update_mixed_context(c[p2], b);
@@ -547,38 +557,38 @@ int16_t RCcontextMapping_decode2_no_mem_s17_LCS(
/* Decode signs */
n = nt;
}
- else /* if(!hm_cfg) */
+ ELSE /* if(!hm_cfg) */
{
- int16_t c, rateQ;
- uint16_t s;
+ Word16 c, rateQ;
+ UWord16 s;
/* Rate flag */
- if (nbbits > 400)
+ IF( GT_16( nbbits, 400 ) )
{
rateFlag = 2;
}
- else
+ ELSE
{
rateFlag = 0;
}
/* Start Decoding */
/* Initialize range decoder */
- rc_uni_dec_init(&rc_st_dec, &st->bit_stream[st->next_bit_pos], nbbits); /* (nbbits + 30) entries are read by the decoder */
+ rc_uni_dec_init_fx( &rc_st_dec, &st->bit_stream[st->next_bit_pos], nbbits ); /* (nbbits + 30) entries are read by the decoder */
nbbits_m2 = nbbits;
- rest_bits = -nbbits_m2;
+ rest_bits = negate( nbbits_m2 );
t = 0;
s = 0;
/* Main Loop through the 2-tuples */
- for (k = 0; k < lastnz; k += 2)
+ FOR( k = 0; k < lastnz; k += 2 )
{
- rateQ = rateFlag + (k > (nt_half));
+ rateQ = add( rateFlag, GT_16( k, ( nt_half ) ) );
/* BER detection: Check max value of context t leading to out-of-bound access to ari_lookup_s17_LC[]*/
- if ((t >= (1 << (NBITS_CONTEXT))) || lsbs_bit_pos <= 0)
+ IF( ( GE_16( t, ( 1 << ( NBITS_CONTEXT ) ) ) ) || lsbs_bit_pos <= 0 )
{
st->BER_detect = 1;
return 0;
@@ -589,24 +599,24 @@ int16_t RCcontextMapping_decode2_no_mem_s17_LCS(
r = 0;
/* MSBs decoding */
- for (lev = 0; lev < 15 && lsbs_bit_pos > 0; ++lev)
+ FOR( lev = 0; lev < 15 && lsbs_bit_pos > 0; ++lev )
{
- esc_nb = min(lev, 3);
- pki = ari_lookup_s17_LC[t + ((rateQ) << NBITS_CONTEXT) + (esc_nb << (NBITS_CONTEXT + NBITS_RATEQ))];
- r = rc_uni_dec_read_symbol_fastS(&rc_st_dec, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 17, 14); /*Alphabet size = 17 (2^4 = 16 MSB symbols + 1 ESC symbol) */
- /* r is the symbol read, the possible values are {0,1,....alphabet_size - 1} */
+ esc_nb = s_min( lev, 3 );
+ pki = ari_lookup_s17_LC[add( t, add( shl( ( rateQ ), NBITS_CONTEXT ), Tab_esc_nb[esc_nb] ) )];
+ r = rc_uni_dec_read_symbol_fastS_fx( &rc_st_dec, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 17, 14 ); /*Alphabet size = 17 (2^4 = 16 MSB symbols + 1 ESC symbol) */
+ /* r is the symbol read, the possible values are {0,1,....alphabet_size - 1} */
- if (r < VAL_ESC) /* If symbol read corresponds to MSB */
+ IF( LT_16( r, VAL_ESC ) ) /* If symbol read corresponds to MSB */
{
- break;
+ BREAK;
}
/* LSBs decoding */
- a += get_indice_1(st, lsbs_bit_pos--) << lev;
- b += get_indice_1(st, lsbs_bit_pos--) << lev;
+ a = add( a, shl( get_indice_1_fx( st, lsbs_bit_pos-- ), lev ) );
+ b = add( b, shl( get_indice_1_fx( st, lsbs_bit_pos-- ), lev ) );
}
- if ((lsbs_bit_pos < -1 && r >= VAL_ESC) || (lev > 14))
+ IF( ( LT_16( lsbs_bit_pos, -1 ) && GE_16( r, VAL_ESC ) ) || GT_16( lev, 14 ) )
{
x[k + 0] = 0;
x[k + 1] = 0;
@@ -615,19 +625,19 @@ int16_t RCcontextMapping_decode2_no_mem_s17_LCS(
}
/* MSBs contributions */
- b1 = r >> 2;
- a1 = r & 0x3;
- a += a1 << lev;
- b += b1 << lev;
+ b1 = shr( r, 2 );
+ a1 = s_and( r, 0x3 );
+ a = add( a, shl( a1, lev ) );
+ b = add( b, shl( b1, lev ) );
/* Add 2 LSB bits per bit-plane */
- rest_bits += 2 * lev;
+ rest_bits = add( rest_bits, shl( lev, 1 ) );
/* Sign bits */
- rest_bits += min(a, 1);
- rest_bits += min(b, 1);
+ rest_bits = add( rest_bits, s_min( a, 1 ) );
+ rest_bits = add( rest_bits, s_min( b, 1 ) );
/* Update bitstream pointer */
- st->next_bit_pos = start_bit_pos + bits_tups + rc_uni_dec_virtual_finish(&rc_st_dec);
+ st->next_bit_pos = add( start_bit_pos, add( bits_tups, rc_uni_dec_virtual_finish_fx( &rc_st_dec ) ) );
/* Confirm that there is no overflow */
#ifdef DEBUGGING
@@ -639,44 +649,45 @@ int16_t RCcontextMapping_decode2_no_mem_s17_LCS(
x[k + 1] = b;
/* Update context for next 2-tuple */
- if (esc_nb < 2)
+ IF( LT_16( esc_nb, 2 ) )
{
- c = 1 + ((a1 + b1) * (esc_nb + 1));
+ c = add( 1, imult1616( add( a1, b1 ), add( esc_nb, 1 ) ) );
}
- else
+ ELSE
{
- c = 12 + esc_nb;
+ c = add( 12, esc_nb );
}
- s = s << 4; /*Shift old 4 bits*/
- s = s + c; /*replace last 4 bits*/
- t = s & 0xFF;
+ s = (UWord16)L_shl( s, 4 ); /*Shift old 4 bits*/
+ s = add( s, c ); /*replace last 4 bits*/
+ t = s_and( s, 0xFF );
}
/* Decode signs */
n = lastnz;
} /* end of if(hm_cfg) */
- for (k = 0; k < n; k++)
+ FOR( k = 0; k < n; k++ )
{
- if (x[k] > 0)
+ IF( x[k] > 0 )
{
- x[k] *= 1 - 2 * get_next_indice_1(st);
+ x[k] = imult1616( x[k], sub( 1, shl( get_next_indice_1_fx( st ), 1 ) ) );
}
}
/* Decode Residual Q */
- resQBits = min(resQMaxBits, lsbs_bit_pos + 1 - st->next_bit_pos);
+ resQBits = s_min( resQMaxBits, sub( add( lsbs_bit_pos, 1 ), st->next_bit_pos ) );
- for (k = 0; k < resQBits; ++k)
+ FOR( k = 0; k < resQBits; ++k )
{
- x[nt + k] = get_indice_1(st, lsbs_bit_pos - k);
+ x[nt + k] = get_indice_1_fx( st, sub( lsbs_bit_pos, k ) );
}
/* Set bitstream pointer to end of buffer */
- get_next_indice_tmp(st, (start_bit_pos + nbbits) - st->next_bit_pos);
+ get_next_indice_tmp_fx( st, sub( add( start_bit_pos, nbbits ), st->next_bit_pos ) );
return resQBits;
}
#endif
+#undef IVAS_CONTEXT_MAPPING
\ No newline at end of file
diff --git a/lib_dec/ari_hm_dec.c b/lib_dec/ari_hm_dec.c
index 1c6373e3fe545b55e8eeecde2fc371ab59a194f9..fa6745deaa742235b4c26a37f9af0bf9f77bd229 100644
--- a/lib_dec/ari_hm_dec.c
+++ b/lib_dec/ari_hm_dec.c
@@ -80,7 +80,7 @@ int16_t DecodeIndex(
Word16
DecodeIndex_fx(
Decoder_State *st,
- Word16 Bandwidth,
+ const Word16 Bandwidth,
Word16 *PeriodicityIndex)
{
TCX_LTP_DEC_HANDLE hTcxLtpDec;
diff --git a/lib_dec/dec_prm_fx.c b/lib_dec/dec_prm_fx.c
index 0c5d65554ccb7608fb7e11ccc50bf7228d5e9748..1c2b5eba1479ad4d2f7fae1b8324e9cf9471adec 100644
--- a/lib_dec/dec_prm_fx.c
+++ b/lib_dec/dec_prm_fx.c
@@ -93,10 +93,10 @@ void getLPCparam(
return;
}
-static void dec_prm_hm(
+void dec_prm_hm(
Decoder_State *st,
Word16 *prm_hm,
- Word16 L_frame
+ const Word16 L_frame
)
{
Word16 tmp;
@@ -117,7 +117,7 @@ static void dec_prm_hm(
move16();
/* Flag */
- prm_hm[0] = get_next_indice(st, 1);
+ prm_hm[0] = get_next_indice_fx(st, 1);
move16();
IF (prm_hm[0] != 0)
@@ -135,12 +135,323 @@ static void dec_prm_hm(
/* Gain index */
IF (EQ_16(st->hTcxCfg->coder_type, VOICED))
{
- prm_hm[2] = get_next_indice(st, kTcxHmNumGainBits);
+ prm_hm[2] = get_next_indice_fx(st, kTcxHmNumGainBits);
move16();
}
}
}
+/*-------------------------------------------------------------------*
+ * getTCXparam()
+ *
+ * get TCX core parameters
+ *-------------------------------------------------------------------*/
+
+void getTCXparam(
+ Decoder_State *st, /* i/o: Decoder State handle */
+ Decoder_State *st0, /* i : bitstream */
+ CONTEXT_HM_CONFIG hm_cfg, /* i/o: HM config */
+ Word16 param[], /* o : decoded parameters */
+ const Word16 bits_common, /* i : number of common bits */
+ const Word16 start_bit_pos, /* i : position of the start bit */
+ const Word16 *no_param_tns, /* i : number of TNS parameters per subframe */
+ Word16 p_param[2], /* o : pointer to parameters for next round of bs reading*/
+ Word16 nTnsBitsTCX10[2],
+ const Word16 pre_past_flag )
+{
+ Word16 ix, j, k, core, last_core, nSubframes;
+ Word16 lg, lgFB, flag_ctx_hm, hm_size;
+ Word16 PeriodicityIndex, useHarmonicModel;
+ Word16 tcxltp_prm_0, tcxltp_prm_1, tcxltp_prm_2, nbits_igf, nbits_tcx;
+ Word16 *prm, *prms;
+ Word16 nTnsParams, nTnsBits;
+ Word16 pre_part, post_part;
+ TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec;
+ TCX_DEC_HANDLE hTcxDec = st->hTcxDec;
+
+
+ IF( EQ_16( pre_past_flag, 0 ) )
+ {
+ pre_part = 1;
+ post_part = 0;
+ }
+ ELSE IF( EQ_16( pre_past_flag, 1 ) )
+ {
+ pre_part = 0;
+ post_part = 1;
+ }
+ ELSE
+ {
+ pre_part = 1;
+ post_part = 1;
+ }
+
+ /* initialization */
+ tcxltp_prm_0 = 0;
+ tcxltp_prm_1 = 0;
+ tcxltp_prm_2 = 0;
+ nbits_igf = 0;
+
+ PeriodicityIndex = 0;
+ useHarmonicModel = 0;
+
+ core = st->core;
+ last_core = st->last_core;
+
+ nSubframes = 1;
+ IF( EQ_16( core, TCX_10_CORE ) )
+ {
+ nSubframes = 2;
+ }
+
+ IF( LT_16( st->element_mode, IVAS_CPE_MDCT ) && st->igf && EQ_16( core, TCX_10_CORE ) )
+ {
+ /* get IGF */
+ FOR( k = 0; k < nSubframes; k++ )
+ {
+ ix = st->next_bit_pos;
+ IGFDecReadLevel( st->hIGFDec, st0, IGF_GRID_LB_SHORT, 1 - k );
+ IGFDecReadData( st->hIGFDec, st0, IGF_GRID_LB_SHORT, 1 - k );
+ IGFDecStoreTCX10SubFrameData( st->hIGFDec, k );
+
+ nbits_igf = add( nbits_igf, sub( st0->next_bit_pos, ix ) );
+ }
+ }
+ /* loop over subframes */
+ FOR( k = 0; k < nSubframes; k++ )
+ {
+ flag_ctx_hm = 0;
+
+ prm = param + imult1616( k, DEC_NPRM_DIV );
+ j = 0;
+
+ nbits_tcx = sub( st0->next_bit_pos, start_bit_pos );
+
+ IF( pre_part && st->enablePlcWaveadjust && EQ_16( k, ( nSubframes - 1 ) ) )
+ {
+ st->tonality_flag = get_next_indice_fx( st0, 1 );
+ }
+
+ IF( post_part )
+ {
+ /* TCX Gain */
+ prm[j++] = get_next_indice_fx( st0, NBITS_TCX_GAIN );
+
+ /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */
+ prm[j++] = get_next_indice_fx( st0, NBITS_NOISE_FILL_LEVEL );
+ }
+ ELSE
+ {
+ j = add( j, 1 + NOISE_FILL_RANGES );
+ }
+
+ /* LTP data */
+ IF( pre_part )
+ {
+ IF( EQ_16( k, 0 ) && ( hTcxLtpDec->tcxltp || GT_32( st->sr_core, 25600 ) ) ) /* PLC pitch info for HB */
+ {
+ prm[j] = get_next_indice_fx( st0, 1 );
+ IF( prm[j] )
+ {
+ prm[j + 1] = get_next_indice_fx( st0, 9 );
+ prm[j + 2] = get_next_indice_fx( st0, 2 );
+ tcxltp_prm_0 = prm[j];
+ tcxltp_prm_1 = prm[j + 1];
+ tcxltp_prm_2 = prm[j + 2];
+ }
+ st->BER_detect = st->BER_detect | tcx_ltp_decode_params( &prm[j], &( hTcxLtpDec->tcxltp_pitch_int ), &( hTcxLtpDec->tcxltp_pitch_fr ), &( hTcxLtpDec->tcxltp_gain ), st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max );
+ hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain;
+
+ IF( EQ_16( core, TCX_20_CORE ) && !st->tcxonly && LT_16( hTcxLtpDec->tcxltp_pitch_int, st->L_frame ) )
+ {
+ // To be done at the end
+ Word32 tmp32 = L_shl( L_mult0( st->L_frame, st->pit_res_max ), 1 + kLtpHmFractionalResolution + 1 );
+ Word16 tmp1 = add( imult1616( hTcxLtpDec->tcxltp_pitch_int, st->pit_res_max ), hTcxLtpDec->tcxltp_pitch_fr );
+ hTcxDec->tcx_hm_LtpPitchLag = div_l( tmp32, tmp1 );
+ }
+ ELSE
+ {
+ hTcxDec->tcx_hm_LtpPitchLag = -1;
+ }
+ j = add( j, 3 );
+ }
+ ELSE
+ {
+ prm[j++] = tcxltp_prm_0;
+ prm[j++] = tcxltp_prm_1;
+ prm[j++] = tcxltp_prm_2;
+ }
+ }
+
+ /* TCX spectral data */
+ lg = shr( st->L_frame, sub( nSubframes, 1 ) );
+ lgFB = shr( st->hTcxCfg->tcx_coded_lines, sub( nSubframes, 1 ) );
+
+ IF( post_part && EQ_16( k, 0 ) && EQ_16( st->last_core_from_bs, ACELP_CORE ) )
+ {
+ /* ACE->TCX transition */
+ lg = add( lg, st->hTcxCfg->tcx_offset );
+ lgFB = add( lgFB, shr( lgFB, sub( 3, nSubframes ) ) );
+
+ IF( LT_16( st->hTcxCfg->lfacNext, 0 ) )
+ {
+ lg = sub( lg, st->hTcxCfg->lfacNext );
+ }
+ }
+
+ IF( pre_part )
+ {
+ /* TNS data */
+ nTnsParams = 0;
+ nTnsBits = 0;
+
+ IF( st->hTcxCfg->fIsTNSAllowed )
+ {
+ IF( EQ_16( core, TCX_10_CORE ) && EQ_16( last_core, ACELP_CORE ) && EQ_16( k, 0 ) )
+ {
+ st0->BER_detect = 1;
+ last_core = TCX_20_CORE;
+ }
+
+ SetTnsConfig( st->hTcxCfg, EQ_16( core, TCX_20_CORE ), EQ_16( st->last_core_from_bs, ACELP_CORE ) && ( k == 0 ) );
+
+ ix = 0;
+ IF( no_param_tns )
+ {
+ ix = get_next_indice_fx( st0, 1 ); /* common_tns_data[] for subframe k */
+ }
+ IF( ix )
+ {
+ prm[j] = imult1616( no_param_tns[k], -1 ); /* - signals common TNS and its size */
+ nTnsParams = no_param_tns[k];
+ }
+ ELSE
+ {
+ ReadTnsData( st->hTcxCfg->pCurrentTnsConfig, st0, &nTnsBits, prm + j, &nTnsParams );
+ }
+ hTcxDec->tnsActive[k] = 0;
+ IF( prm[j] != 0 )
+ {
+ hTcxDec->tnsActive[k] = nTnsParams;
+ }
+ IF( nTnsBitsTCX10 != NULL )
+ {
+ nTnsBitsTCX10[k] = add( nTnsBits, ( no_param_tns ? 1 : 0 ) );
+ }
+
+ j = add( j, nTnsParams );
+ }
+
+ IF( post_part )
+ {
+ IF( EQ_16( core, TCX_20_CORE ) )
+ {
+ // Q-factor of TcxBandwidth is 15 : derived from getTcxBandwidth function
+ st->TcxBandwidth = (Word16)floatToFixed( st->TcxBandwidth_float, 15 );
+ hm_size = mult( st->TcxBandwidth, shl( lg, 1 ) );
+
+ IF( hTcxDec->tcx_lpc_shaped_ari && NE_16( st->last_core_from_bs, ACELP_CORE ) )
+ {
+ dec_prm_hm( st0, &prm[j], hm_size );
+ }
+
+ nbits_tcx = sub( st->bits_frame_core, sub( st0->next_bit_pos, start_bit_pos ) );
+ }
+ ELSE
+ {
+ st->TcxBandwidth = (Word16)floatToFixed( st->TcxBandwidth_float, 15 );
+ hm_size = mult( st->TcxBandwidth, shl( lgFB, 1 ) );
+ nbits_tcx = sub( shr( sub( add( sub( sub( st->bits_frame_core, bits_common ), nbits_igf ), 1 ), k ), 1 ), sub( sub( st0->next_bit_pos, start_bit_pos ), nbits_tcx ) );
+ }
+
+ /*Context HM flag*/
+ IF( st->hTcxCfg->ctx_hm && !( EQ_16( st->last_core_from_bs, ACELP_CORE ) && EQ_16( k, 0 ) ) )
+ {
+ useHarmonicModel = get_next_indice_fx( st0, 1 );
+ prm[j] = useHarmonicModel;
+ nbits_tcx = sub( nbits_tcx, 1 );
+
+ IF( useHarmonicModel )
+ {
+ ix = DecodeIndex_fx( st0, GE_16( hm_size, 256 ), prm + add( j, 1 ) );
+ flag_ctx_hm = 1;
+
+ PeriodicityIndex = *( prm + add( j, 1 ) );
+ IF( EQ_16( st->element_mode, EVS_MONO ) )
+ {
+ ConfigureContextHm( lgFB, nbits_tcx, PeriodicityIndex, hTcxDec->tcx_hm_LtpPitchLag, &hm_cfg );
+ }
+ nbits_tcx = sub( nbits_tcx, ix );
+ }
+ }
+ }
+ j = add( j, NPRM_CTX_HM );
+
+ /* read IGF payload */
+ IF( post_part && EQ_16( core, TCX_20_CORE ) )
+ {
+ IF( st->igf )
+ {
+ ix = st->next_bit_pos;
+ IGFDecReadLevel( st->hIGFDec, st0, ( st->last_core_from_bs == ACELP_CORE ) ? IGF_GRID_LB_TRAN : IGF_GRID_LB_NORM, 1 );
+ IGFDecReadData( st->hIGFDec, st0, ( st->last_core_from_bs == ACELP_CORE ) ? IGF_GRID_LB_TRAN : IGF_GRID_LB_NORM, 1 );
+
+ nbits_tcx = sub( nbits_tcx, sub( st0->next_bit_pos, ix ) );
+ }
+ nbits_tcx = sub( st->bits_frame_core, sub( st0->next_bit_pos, start_bit_pos ) );
+ }
+ ELSE IF( p_param != NULL )
+ {
+ p_param[k] = j;
+ }
+ }
+ ELSE
+ {
+ j = p_param[k];
+
+ nbits_tcx = st->bits_frame_channel;
+ IF( EQ_16( st->core, TCX_10_CORE ) )
+ {
+ nbits_tcx = sub( nTnsBitsTCX10[k], NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL );
+ }
+ }
+
+ IF( post_part )
+ {
+ IF( hTcxDec->tcx_lpc_shaped_ari && EQ_16( core, TCX_20_CORE ) )
+ {
+ prm[j++] = nbits_tcx; /* store length of buffer */
+ prms = &prm[j];
+ FOR( ix = 0; ix < nbits_tcx; ix++ )
+ {
+ prms[ix] = get_next_indice_1_fx( st0 );
+ }
+ FOR( ix = 0; ix < 32; ix++ )
+ {
+ prms[ix + nbits_tcx] = 1;
+ }
+ j = add( j, nbits_tcx );
+ }
+ ELSE
+ {
+ IF( GT_16( st->element_mode, EVS_MONO ) )
+ {
+ IF( useHarmonicModel )
+ {
+ ConfigureContextHm( lgFB, nbits_tcx, PeriodicityIndex, hTcxDec->tcx_hm_LtpPitchLag, &hm_cfg );
+ }
+ hTcxDec->resQBits[k] = RCcontextMapping_decode2_no_mem_s17_LCS_fx( st0, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), flag_ctx_hm ? &hm_cfg : NULL );
+ }
+ ELSE
+ {
+ hTcxDec->resQBits[k] = ACcontextMapping_decode2_no_mem_s17_LC( st0, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), flag_ctx_hm ? &hm_cfg : NULL );
+ }
+ }
+ }
+ }
+
+ return;
+}
/*-----------------------------------------------------------------*
* Funtion dec_prm() *
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
@@ -1219,14 +1530,14 @@ void dec_prm(
test();
IF ( st->hTcxCfg->ctx_hm && !(st->last_core_bs_fx == ACELP_CORE && k == 0) )
{
- prm[j] = get_next_indice(st, 1);
+ prm[j] = get_next_indice_fx(st, 1);
move16();
nbits_tcx = sub(nbits_tcx, 1);
move16();
IF (prm[j]) /* Read PeriodicityIndex */
{
- Word16 NumIndexBits = DecodeIndex_fx(st,hm_size >= 256,prm+j+1);
+ Word16 NumIndexBits = DecodeIndex_fx(st,GE_16(hm_size , 256),prm+j+1);
flag_ctx_hm = 1;
move16();
diff --git a/lib_dec/ivas_range_uni_dec.c b/lib_dec/ivas_range_uni_dec.c
index addccb979ad85db82dc3be677c9fbd654eae2e7b..c6b9425dbf9a3fda7e173c7a91f9bf03fa0747e8 100644
--- a/lib_dec/ivas_range_uni_dec.c
+++ b/lib_dec/ivas_range_uni_dec.c
@@ -58,8 +58,10 @@
*-------------------------------------------------------------------*/
static int16_t rc_uni_dec_read( RangeUniDecState *rc_st_dec );
+static Word16 rc_uni_dec_read_fx( RangeUniDecState *rc_st_dec );
static void rc_uni_dec_update( RangeUniDecState *rc_st_dec, const uint16_t cum_freq, const uint16_t sym_freq );
+static void rc_uni_dec_update_fx( RangeUniDecState *rc_st_dec, const UWord16 cum_freq, const UWord16 sym_freq );
/*-------------------------------------------------------------------*
@@ -93,6 +95,32 @@ void rc_uni_dec_init(
return;
}
+void rc_uni_dec_init_fx(
+ RangeUniDecState *rc_st_dec, /* i/o: RC state handle */
+ UWord16 *bit_buffer, /* i : Bit buffer */
+ const Word16 max_available_bits /* i : Total maximum bits available */
+)
+{
+ Word16 i;
+
+ rc_st_dec->rc_low = 0;
+ rc_st_dec->rc_range = 0xFFFFFFFF;
+
+ rc_st_dec->bit_buffer = bit_buffer;
+ rc_st_dec->bit_count = 0;
+ /* the renormalization procedure reads at most 32 - 2 extra bits than available */
+ rc_st_dec->max_allowable_bit_count = add( max_available_bits, 30 );
+
+ rc_st_dec->bit_error_detected = 0;
+
+ FOR ( i = 0; i < 4; i++ )
+ {
+ // Not adding basops becuase the resultant value greater than Word32
+ rc_st_dec->rc_low = (rc_st_dec->rc_low << 8) + rc_uni_dec_read_fx(rc_st_dec);
+ }
+
+ return;
+}
/*-------------------------------------------------------------------*
* rc_uni_dec_read_symbol_fastS()
@@ -174,6 +202,79 @@ uint16_t rc_uni_dec_read_symbol_fastS(
return sym_begin;
}
+UWord16 rc_uni_dec_read_symbol_fastS_fx(
+ RangeUniDecState *rc_st_dec, /* i/o: Decoder State */
+ const UWord16 cum_freq_table[], /* i : Cumulative frequency up to symbol */
+ const UWord16 sym_freq_table[], /* i : Symbol frequency */
+ const UWord16 alphabet_size, /* i : Number of symbols in the alphabet */
+ const UWord16 tot_shift /* i : Total frequency as a power of 2 */
+)
+{
+ UWord16 sym_begin;
+ UWord16 sym_end;
+ UWord16 sym_middle;
+ UWord32 low; /* local copy (2 to 1 + ceil(log2(alphabet_size)) uses) */
+ UWord32 range; /* local copy (3 to 2 + ceil(log2(alphabet_size)) uses) */
+ UWord16 ceil_log2_alphabet_size; /* ceil(log2(alphabet_size)) */
+ UWord16 step;
+ UWord32 reversed_low;
+
+ low = rc_st_dec->rc_low;
+ range = rc_st_dec->rc_range;
+ // Not converted , to be rechecked(Value of range exceeds Word32)
+ range >>= tot_shift;
+
+ /* the cumulative value is val = low / range */
+ /* the condition val >= level is equivalent with low >= range * level */
+
+ /* in case of bitstream errors it is possible that val >= (1 << tot_shift) */
+ IF ( low >= ( range << tot_shift ) )
+ {
+ rc_st_dec->bit_error_detected = 1;
+
+ /* for valid bitstreams, always low < range, therefore setting low = range */
+ /* will always reach the bitstream error condition branch on the next call */
+ rc_st_dec->rc_range = 0xFFFFFFFF;
+ rc_st_dec->rc_low = rc_st_dec->rc_range;
+
+ /* the current value and all the following values are very likely incorrect */
+ return 0; /* return the minimum valid value for the output */
+ }
+
+ /* do a binary search to find the symbol read */
+ sym_begin = 0;
+ sym_end = alphabet_size; /* the possible values are {sym_begin, .., sym_end - 1} */
+
+ /* ceil(log2(x)) = 1 + floor(log2(x - 1)), for any x >= 2 */
+ /* floor(log2(y)) = 31 - norm_ul_float(y) = 30 - norm_l(y), for any 1 <= y <= 2 ^ 31 - 1 */
+ ceil_log2_alphabet_size = sub(31 , norm_l( alphabet_size - 1 ));
+ /* completely equivalent with 32 - norm_ul_float(alphabet_size - 1), but norm_l is faster */
+ reversed_low = ( range << tot_shift ) - low;
+
+ /* at most ceil_log2_alphabet_size steps are needed so that sym_end - sym_begin == 1 */
+ FOR ( step = 0; step < ceil_log2_alphabet_size; step++ )
+ {
+ sym_middle = shr(add( sym_begin , sym_end ) , 1);
+ /* completely equvalent with low >= range * ((1 << tot_shift) - table[sym_middle]) */
+ IF ( range * sub( shl( 1 , tot_shift ) , cum_freq_table[sym_middle] ) >= reversed_low )
+ {
+ sym_begin = sym_middle;
+ }
+ ELSE
+ {
+ sym_end = sym_middle;
+ }
+ }
+
+ /* sym_begin contains the symbol read */
+
+ /* low was not modified */
+ rc_st_dec->rc_range = range;
+
+ rc_uni_dec_update_fx( rc_st_dec, cum_freq_table[sym_begin], sym_freq_table[sym_begin] );
+
+ return sym_begin;
+}
/*-------------------------------------------------------------------*
@@ -206,6 +307,30 @@ static void rc_uni_dec_update(
return;
}
+static void rc_uni_dec_update_fx(
+ RangeUniDecState *rc_st_dec, /* i/o: RC State handle */
+ const UWord16 cum_freq, /* i : Cumulative frequency */
+ const UWord16 sym_freq /* i : Symbol frequency */
+)
+{
+ // Not adding basop because the value of rc_st_dec->rc_range exceeds Word32
+ rc_st_dec->rc_low -= cum_freq * rc_st_dec->rc_range;
+ rc_st_dec->rc_range *= sym_freq;
+
+ /* rc_range was shifted right by up to 16, so at most two renormalizations are needed */
+ IF ( rc_st_dec->rc_range < 0x01000000 )
+ {
+ rc_st_dec->rc_low = ( rc_st_dec->rc_low << 8 ) + rc_uni_dec_read_fx( rc_st_dec );
+ rc_st_dec->rc_range <<= 8;
+ IF ( rc_st_dec->rc_range < 0x01000000 )
+ {
+ rc_st_dec->rc_low = ( rc_st_dec->rc_low << 8 ) + rc_uni_dec_read_fx( rc_st_dec );
+ rc_st_dec->rc_range <<= 8;
+ }
+ }
+
+ return;
+}
/*-------------------------------------------------------------------*
* rc_uni_dec_read_bit()
*
@@ -430,6 +555,14 @@ int16_t rc_uni_dec_virtual_finish(
/* the function is completely equivalent with rc_uni_dec_finish */
return rc_st_dec->bit_count + norm_l( rc_st_dec->rc_range >> 24 ) - 53;
}
+Word16 rc_uni_dec_virtual_finish_fx(
+ RangeUniDecState *rc_st_dec /* i : RC state handle */
+)
+{
+ /* the function is completely equivalent with rc_uni_dec_finish */
+ // Not adding basop because value of rc_st_dec->rc_range exceeds Word32
+ return add( rc_st_dec->bit_count , sub( norm_l( rc_st_dec->rc_range >> 24 ), 53 ) );
+}
/*-------------------------------------------------------------------*
@@ -475,3 +608,40 @@ static int16_t rc_uni_dec_read(
return byte_read;
}
+
+static Word16 rc_uni_dec_read_fx(
+ RangeUniDecState *rc_st_dec /* i/o: RC State handle */
+)
+{
+ Word16 byte_read;
+ UWord16 *shifted_bit_buffer;
+
+ shifted_bit_buffer = rc_st_dec->bit_buffer + rc_st_dec->bit_count;
+ rc_st_dec->bit_count = add( rc_st_dec->bit_count, 8 );
+
+ /*
+ * In case of bitstream errors the number the bits read may be larger than the total
+ * number of bits that have been read from the bitstream and have meaningful values
+ * plus the extra 30 padding bits that must be appended to the buffer by the caller.
+ */
+ IF( GT_16( rc_st_dec->bit_count, rc_st_dec->max_allowable_bit_count ) )
+ {
+ rc_st_dec->bit_error_detected = 1;
+
+ /* for valid bitstreams, always low < range, therefore setting low = range */
+ /* will always reach the bitstream error condition branch on the next call */
+ rc_st_dec->rc_range = 0xFFFFFFFF;
+ rc_st_dec->rc_low = rc_st_dec->rc_range;
+
+ return 0; /* reading the 8 bits would trigger an out-of-bounds array access */
+ }
+
+
+ /* pack the first 8 bits from shifted_bit_buffer, first bit is most significant */
+ byte_read = s_or( shl( shifted_bit_buffer[0], 7 ), s_or( shl( shifted_bit_buffer[1], 6 ),
+ s_or( shl( shifted_bit_buffer[2], 5 ), s_or( shl( shifted_bit_buffer[3], 4 ),
+ s_or( shl( shifted_bit_buffer[4], 3 ), s_or( shl( shifted_bit_buffer[5], 2 ),
+ s_or( shl( shifted_bit_buffer[6], 1 ), shifted_bit_buffer[7] ) ) ) ) ) ) ) ;
+
+ return byte_read;
+}
diff --git a/lib_dec/ivas_tcx_core_dec.c b/lib_dec/ivas_tcx_core_dec.c
index e856f14f30893cf00f82f715114688417bdfacf7..796b38176845596761aeeea1bc5c178851389ce4 100644
--- a/lib_dec/ivas_tcx_core_dec.c
+++ b/lib_dec/ivas_tcx_core_dec.c
@@ -890,7 +890,12 @@ static void dec_prm_tcx(
if ( st->use_partial_copy == 0 )
{
- getTCXparam_ivas( st, st, hm_cfg, param, bits_common, start_bit_pos, NULL, NULL, NULL, -1 );
+ getTCXparam( st, st, hm_cfg, param, bits_common, start_bit_pos, NULL, NULL, NULL, -1 );
+ // Q-factor for hTcxLtpDec->tcxltp_gain is 15
+ // To be removed later
+ st->hTcxLtpDec->tcxltp_gain_float = fixedToFloat( st->hTcxLtpDec->tcxltp_gain, 15 );
+ st->hTcxDec->tcxltp_last_gain_unmodified_float = st->hTcxLtpDec->tcxltp_gain_float;
+ //
}
if ( !st->use_partial_copy )
diff --git a/lib_dec/tns_base_dec_fx.c b/lib_dec/tns_base_dec_fx.c
index 2839b9b72b650afb381ef023256d368e8fd6f297..6ca2e775282cff66185cc8e91cdc87649f2e8223 100644
--- a/lib_dec/tns_base_dec_fx.c
+++ b/lib_dec/tns_base_dec_fx.c
@@ -28,6 +28,7 @@ typedef Word32 (* TLinearPredictionFilter)(Word16 order, Word16 const parCoeff[]
*
*---------------------------------------------------------------------*/
+#define IVAS_CODE
#ifdef IVAS_CODE
void
#else
@@ -54,11 +55,11 @@ Word16
{
IF(LT_16(pTnsConfig->iFilterBorders[0], 512))
{
- ReadFromBitstream(&tnsEnabledOnWhiteSWBTCX10BitMap, 1, st, &stream, pnSize);
+ ReadFromBitstream_fx(&tnsEnabledOnWhiteSWBTCX10BitMap, 1, st, &stream, pnSize);
}
ELSE
{
- ReadFromBitstream(&tnsEnabledOnWhiteSWBTCX20BitMap, 1, st, &stream, pnSize);
+ ReadFromBitstream_fx(&tnsEnabledOnWhiteSWBTCX20BitMap, 1, st, &stream, pnSize);
}
}
ELSE
@@ -67,17 +68,17 @@ Word16
IF(LT_16(pTnsConfig->iFilterBorders[0], 512))
{
- ReadFromBitstream(&tnsEnabledSWBTCX10BitMap, 1, st, &stream, pnSize);
+ ReadFromBitstream_fx(&tnsEnabledSWBTCX10BitMap, 1, st, &stream, pnSize);
}
ELSE
{
- ReadFromBitstream(&tnsEnabledSWBTCX20BitMap, 1, st, &stream, pnSize);
+ ReadFromBitstream_fx(&tnsEnabledSWBTCX20BitMap, 1, st, &stream, pnSize);
}
}
}
ELSE
{
- ReadFromBitstream(&tnsEnabledWBTCX20BitMap, 1, st, &stream, pnSize);
+ ReadFromBitstream_fx(&tnsEnabledWBTCX20BitMap, 1, st, &stream, pnSize);
}
move16();
@@ -90,6 +91,7 @@ Word16
return TNS_NO_ERROR;
#endif
}
+#undef IVAS_CODE
/*---------------------------------------------------------------------*
* DecodeTnsData()
*