From e0d49d2350c3b4e260a96f0590899b143375af96 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Sat, 16 Mar 2024 23:23:53 +0530 Subject: [PATCH] Fixed point sub-functions integration - 2 [x] ivas_core_dec fixed point updates. [x] acelp core: integration of updt_dec function [x] ivas_stereo_td_bit_alloc updates [x] acelp core: cng_params_upd integration. --- lib_com/cng_exc_fx.c | 87 +++++----- lib_com/fd_cng_com_fx.c | 55 +++++-- lib_com/ivas_prot.h | 12 +- lib_com/ivas_rom_com.c | 131 ++++++--------- lib_com/ivas_rom_com.h | 34 ++-- lib_com/ivas_rom_com_fx.c | 6 + lib_com/ivas_rom_com_fx.h | 4 +- lib_com/ivas_stereo_td_bit_alloc.c | 248 +++++++++-------------------- lib_com/prot.h | 6 +- lib_com/prot_fx2.h | 43 ++--- lib_dec/acelp_core_dec.c | 182 ++++++++++++++++++++- lib_dec/ivas_core_dec.c | 210 ++++++++++++++++++------ lib_dec/lsf_dec.c | 18 +++ lib_dec/stat_dec.h | 3 + lib_enc/acelp_core_enc.c | 26 ++- lib_enc/lsf_enc.c | 17 ++ 16 files changed, 680 insertions(+), 402 deletions(-) diff --git a/lib_com/cng_exc_fx.c b/lib_com/cng_exc_fx.c index c6ff88ef0..3873a8eb5 100644 --- a/lib_com/cng_exc_fx.c +++ b/lib_com/cng_exc_fx.c @@ -7,6 +7,7 @@ #include "prot_fx1.h" /* Function prototypes */ #include "prot_fx2.h" /* Function prototypes */ #include "rom_com.h" +#include "ivas_rom_com_fx.h" /*---------------------------------------------------------------------* * Local constants @@ -964,22 +965,22 @@ void cng_params_upd_fx( #ifdef IVAS_FLOAT_FIXED void cng_params_upd_ivas_fx( - const Word16 lsp_new[], /* i : LSP aprameters Q15 */ - const Word16 exc2[], /* i : current enhanced excitation Q_exc */ - const Word16 L_frame, /* i : frame length Q0 */ - Word16 *ho_circ_ptr, /* i/o: pointer for CNG averaging buffers Q0 */ - Word32 ho_ener_circ[], /* o : energy buffer for CNG averaging Q6 */ - Word16 *ho_circ_size, /* i/o: size of DTX hangover history buffer for averaging Q0 */ - Word16 ho_lsp_circ[], /* o : old LSP buffer for CNG averaging Q15 */ - const Word16 Q_exc, /* i : Q value of excitation */ - const Word16 enc_dec_flag, /* i : Flag indicating encoder or decoder (ENC,DEC) */ - Word32 ho_env_circ[], /* i/o: Envelope buffer */ - Word16 *cng_buf_cnt, /* i/o: Counter of postponed FFT-processing instances */ - Word16 cng_exc2_buf[], /* i/o: Excitation buffer Q_exc */ - Word16 cng_Qexc_buf[], /* i/o: Q_exc buffer Q0 */ - Word32 cng_brate_buf[], /* i/o: last_active_brate buffer Q0 */ - const Word32 last_active_brate,/* i : Last active bit rate Q0 */ - const Word16 element_mode, /* i : Element mode */ + const Word16 lsp_new[], /* i : LSP aprameters Q15 */ + const Word16 exc2[], /* i : current enhanced excitation Q_exc */ + const Word16 L_frame, /* i : frame length Q0 */ + Word16 *ho_circ_ptr, /* i/o: pointer for CNG averaging buffers Q0 */ + Word32 ho_ener_circ[], /* o : energy buffer for CNG averaging Q6 */ + Word16 *ho_circ_size, /* i/o: size of DTX hangover history buffer for averaging Q0 */ + Word16 ho_lsp_circ[], /* o : old LSP buffer for CNG averaging Q15 */ + const Word16 Q_exc, /* i : Q value of excitation */ + const Word16 enc_dec_flag,/* i : Flag indicating encoder or decoder (ENC,DEC) */ + Word32 ho_env_circ[], /* i/o: Envelope buffer */ + Word16 *cng_buf_cnt, /* i/o: Counter of postponed FFT-processing instances */ + Word16 cng_exc2_buf[], /* i/o: Excitation buffer Q_exc */ + Word16 cng_Qexc_buf[], /* i/o: Q_exc buffer Q0 */ + Word32 cng_brate_buf[], /* i/o: last_active_brate buffer Q0 */ + const Word32 last_active_brate /* i : Last active bit rate Q0 */ + , const Word16 element_mode, /* i : Element mode */ const Word16 bwidth /* i : Audio bandwidth */ ) { @@ -993,10 +994,9 @@ void cng_params_upd_ivas_fx( Word32 env[NUM_ENV_CNG]; Word16 exp1; Word16 CNG_mode; - Word16 tmp; + Word16 tmp = 0; Word16 temp_lo_fx, temp_hi_fx; Word16 exp_pow; - Word32 att; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif @@ -1120,47 +1120,50 @@ void cng_params_upd_ivas_fx( tmp = add( add( Q_exc, Q_exc ), 1 ); sp[i] = L_shr( L_tmp, sub( tmp, 6 ) ); move32(); /* Q6 */ - ptR++; ptI--; } - Copy32( sp, env, NUM_ENV_CNG ); - IF( element_mode == IVAS_SCE || element_mode == IVAS_CPE_DFT ) + + Copy32(sp,env,NUM_ENV_CNG); + Word16 shift = 0; + if (element_mode == IVAS_SCE || element_mode == IVAS_CPE_DFT) { - Word16 index; - att = 0; - index = apply_scale_ind( &att, bwidth, last_active_brate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO ); - // att = powf(10, att / 10.0f); - tmp = att_pow_tbl[index]; // Q15 + Word32 att_fx = 0; + Word16 index = 0; + apply_scale_ivas_fx(&att_fx, bwidth, last_active_brate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO, &index); + att_fx = pow_10_q23[index];//Q23 + tmp = extract_h(att_fx);//Q7 + shift = 8; } - ELSE + else { - CNG_mode = get_cng_mode( last_active_brate ); + CNG_mode = get_cng_mode(last_active_brate); /* att = 1/pow(2,ENR_ATT_fx[CNG_mode]); */ - L_tmp = L_shl( L_deposit_l( ENR_ATT_fx[CNG_mode] ), 8 ); /* 16 */ - temp_lo_fx = L_Extract_lc( L_tmp, &temp_hi_fx ); - - exp_pow = sub( 14, temp_hi_fx ); - L_tmp = Pow2( 14, temp_lo_fx ); /* Qexp_pow */ - L_tmp = L_shl( L_tmp, sub( 13, exp_pow ) ); /* Q13 */ - tmp = extract_l( L_tmp ); /* Q13 */ - - exp1 = norm_s( tmp ); - tmp = shl( tmp, exp1 ); /*Q(exp1+13) */ - tmp = div_s( 16384, tmp ); /*Q(15+14-exp1-13) */ - tmp = shr( tmp, sub( 1, exp1 ) ); /* Q15 */ + L_tmp = L_shl(L_deposit_l(ENR_ATT_fx[CNG_mode]), 8);/* 16 */ + temp_lo_fx = L_Extract_lc(L_tmp, &temp_hi_fx); + + exp_pow = sub(14, temp_hi_fx); + L_tmp = Pow2(14, temp_lo_fx); /* Qexp_pow */ + L_tmp = L_shl(L_tmp, sub(13, exp_pow)); /* Q13 */ + tmp = extract_l(L_tmp);/* Q13 */ + + exp1 = norm_s(tmp); + tmp = shl(tmp, exp1);/*Q(exp1+13) */ + tmp = div_s(16384, tmp); /*Q(15+14-exp1-13) */ + tmp = shr(tmp, sub(1, exp1));/* Q15 */ } - FOR( i = 0; i < NUM_ENV_CNG; i++ ) + FOR(i = 0; i < NUM_ENV_CNG; i++) { - env[i] = Mult_32_16( env[i], tmp ); + env[i] = Mult_32_16(env[i],tmp); move32(); } /* update the circular buffer of old residual envelope */ /* Copy32( env, &(ho_env_circ[add(shl(*ho_circ_ptr,4),shl(*ho_circ_ptr,2))]), NUM_ENV_CNG ); */ Copy32( env, &( ho_env_circ[( *ho_circ_ptr ) * NUM_ENV_CNG] ), NUM_ENV_CNG ); + scale_sig32(&(ho_env_circ[(*ho_circ_ptr)*NUM_ENV_CNG]), NUM_ENV_CNG, shift); } *ho_circ_size = add( *ho_circ_size, 1 ); if ( GT_16( *ho_circ_size, HO_HIST_SIZE ) ) diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index dc928860c..583286007 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -1821,34 +1821,63 @@ void apply_scale( * Apply bitrate-dependent scale * returns index of scaleTable *-------------------------------------------------------------------*/ -Word16 apply_scale_ind( - Word32 *scale, /* o : scalefactor */ - const Word16 bwmode, /* i : audio bandwidth */ - const Word32 bitrate, /* i : Bit rate */ - const SCALE_SETUP *scaleTable, /* i : Scale table */ - const Word16 scaleTableSize /* i : Size of scale table */ -) + Word16 apply_scale_ind( + Word32 *scale, /* o : scalefactor */ + const Word16 bwmode, /* i : audio bandwidth */ + const Word32 bitrate, /* i : Bit rate */ + const SCALE_SETUP *scaleTable, /* i : Scale table */ + const Word16 scaleTableSize /* i : Size of scale table */ + ) { Word16 i; // PMT("Verifiy if the basop ued are ok for stereo too") - FOR( i = 0; i < scaleTableSize; i++ ) + FOR(i = 0; i < scaleTableSize; i++) { cast16(); - IF( s_and( (Word16) EQ_16( bwmode, (Word16) scaleTable[i].bwmode ), - s_and( L_sub( bitrate, scaleTable[i].bitrateFrom ) >= 0, - L_sub( bitrate, scaleTable[i].bitrateTo ) < 0 ) ) ) + IF(s_and((Word16)EQ_16(bwmode, (Word16)scaleTable[i].bwmode), + s_and(L_sub(bitrate, scaleTable[i].bitrateFrom) >= 0, + L_sub(bitrate, scaleTable[i].bitrateTo) < 0))) { BREAK; } + } { - *scale = L_add( *scale, L_deposit_h( scaleTable[i].scale ) ); + *scale = L_add(*scale, L_deposit_h(scaleTable[i].scale)); } return i; } -#endif // IVAS_FLOAT_FIXED +void apply_scale_ivas_fx( + Word32 *scale, /* o : scalefactor */ + const Word16 bwmode, /* i : audio bandwidth */ + const Word32 bitrate, /* i : Bit rate */ + const SCALE_SETUP* scaleTable, /* i : Scale table */ + const Word16 scaleTableSize, /* i : Size of scale table */ + Word16 *index +) +{ + Word16 i; + //PMT("Verifiy if the basop ued are ok for stereo too") + FOR(i = 0; i < scaleTableSize; i++) + { + cast16(); + IF(s_and((Word16)EQ_16(bwmode, (Word16)scaleTable[i].bwmode), + s_and(L_sub(bitrate, scaleTable[i].bitrateFrom) >= 0, + L_sub(bitrate, scaleTable[i].bitrateTo) < 0)) + ) + { + BREAK; + } + } + assert(i < scaleTableSize); + + *scale = L_add(*scale, L_deposit_h(scaleTable[i].scale)); + *index = i; + +} +#endif // IVAS_FLOAT_FIXED /*------------------------------------------------------------------- * bandcombinepow() * diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 2190b6b1e..c4b7a10dd 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -2371,8 +2371,8 @@ void tdm_low_rate_dec( #ifdef IVAS_FLOAT_FIXED void tdm_SCh_LSF_intra_pred_fx( const Word32 element_brate, /* i : element bitrate */ - const Word32 *tdm_lsfQ_PCh_fx, /* i : primary channel LSFs */ - Word32 *pred_lsf_SCh_fx /* o : predicted secondary channel LSFs */ + const Word16 *tdm_lsfQ_PCh_fx, /* i : primary channel LSFs */ + Word16 *pred_lsf_SCh_fx /* o : predicted secondary channel LSFs */ ); #endif @@ -2386,12 +2386,10 @@ void tdm_SCh_LSF_intra_pred( void tdm_SCh_lsf_reuse_fx( const Word16 enc_dec, /* i : encoder/decoder flag */ const Word32 element_brate, /* i : element bitrate */ - Word32 lsf_new_fx[M], /* i/o: LSFs at the end of the frame */ - Word16 lsf_new_q_fx, /* i/o: LSFs at the end of the frame */ + Word16 lsf_new_fx[M], /* i/o: LSFs at the end of the frame */ Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame */ - Word16 lsp_new_q_fx, /* i/o: LSPs at the end of the frame */ - const Word32 tdm_lsfQ_PCh_fx[M], /* i : primary channel LSFs */ - const Word32 lsf_wgts_fx[M], /* i : LSF weights */ + const Word16 tdm_lsfQ_PCh_fx[M], /* i : primary channel LSFs */ + const Word16 lsf_wgts_fx[M], /* i : LSF weights */ Word16 *beta_index /* i/o: quantization index */ ); #endif diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index a125144c1..1f262adf7 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -685,84 +685,57 @@ const int16_t tdm_bit_allc_tbl[5][6] = }; #ifdef IVAS_FLOAT_FIXED /* LSFs Intra-frame prediction tables */ -//Q18 -const Word32 tdm_LSF_MEAN_RE_USE_OUT_fx[M] = -{ - 78981888, 136655664, 228279712, 351345824, 448816480, 548262656, 652351360, 744776256, 837960320, 941893888, 1037661888, 1125471744, 1234781824, 1341864320, 1454050176, 1551520000, -}; -//Q18 -const Word32 tdm_LSF_MEAN_RE_USE_IN_fx[M] = -{ - 75081712, 136935120, 232599584, 353359904, 452356736, 551120000, 658427840, 747921216, 841828032, 946883008, 1040944704, 1134499968, 1240576256, 1351348096, 1460888960, 1563513856, -}; -//Q18 -const Word32 tdm_LSF_MEAN_RE_USE_fx[M] = -{ - 69608200, 140188480, 241060944, 353105792, 460584864, 556547904, 670261760, 767422464, - 864841216, 966328064, 1057613056, 1151813248, 1253489536, 1351602432, 1452951424, 1553826432 -}; - -const Word32 tdm_Beta_Q1bit_re_use_13k2_fx[2] = { 2083059138, 1610612736 };//Q31 -const Word32 tdm_Beta_Q1bit_re_use_16k4_fx[2] = { 2040109465, 1524713390 };//Q31 -const Word32 tdm_Beta_Q1bit_re_use_24k4_32k_fx[2] = { 1997159792, 1567663063 };//Q31 -const Word32 tdm_Beta_Q1bit_re_use_48k_fx[2] = { 2083059138, 1653562408 };//Q31 -//Q31 -const Word32 tdm_RE_USE_adaptive_beta_prd_diag_3_fx[15 + 16 + 15] = -{ - 1902455808, 442381632, - 125627792, 1770600320, 492632736, - 78383152, 1755567872, 364213216, - -12884902, 1821710336, 442596384, - 142378160, 1929084544, 291413536, - 142592912, 1707464192, 415323328, - 200789728, 1706819968, 361851008, - 238155936, 1709396992, 392560000, - 230424992, 1682553472, 387406048, - 317612832, 1580977408, 425631264, - 286689056, 1636597248, 408021888, - 408666144, 1582480640, 368293440, - 383325824, 1549194752, 353475808, - 422410048, 1479831040, 263925744, - 438730912, 1356565376, 116608360, - 379460352, 1158782208, -}; -//Q18 -const Word32 tdm_LSF_MEAN_PRED_QNT_fx[M] = -{ - 102580472, 159515808, 253756928, 355005792, 448190432, 545390272, 642420608, 733207808, - 837863616, 931704576, 1026299968, 1122975360, 1234068608, 1339500800, 1448725504, 1547547776 -}; -//Q18 -const Word32 tdm_LSF_MEAN_PRED_QNT_IN_fx[M] = -{ - 75639032, 140369984, 235860912, 351879296, 453702048, 552355776, 653120000, 749686720, 849157568, 950448448, 1046620416, 1142095360, 1245801600, 1351007616, 1459383680, 1565687296, -}; -//Q18 -const Word32 tdm_LSF_MEAN_PRED_QNT_OUT_fx[M] = -{ - 75081712, 136935120, 232599584, 353359904, 452356736, 551120000, 658427840, 747921216, 841828032, 946883008, 1040944704, 1134499968, 1240576256, 1351348096, 1460888960, 1563513856, -}; -//Q31 -const Word32 tdm_PRED_QNT_fixed_beta_prd_diag_3_fx[15 + 16 + 15] = -{ - 1511828480, 258342288, - -240303424, 1576253056, 387191296, - 54331336, 1439243520, 408236640, - -396640224, 1694794112, 646392576, - -89764816, 1871746688, 394492736, - 7086696, 1484984960, 514107584, - 45741400, 1444827008, 524200768, - 151397600, 1621135360, 425846016, - 161490768, 1535880320, 466648192, - 190267056, 1323494144, 658633216, - 46600396, 1743971456, 434006432, - 340161408, 1570025344, 374950656, - 258557024, 1566804096, 424772256, - 264355232, 1611042176, 264999488, - 367004960, 1368376576, 227633264, - 256194800, 1411755776, -}; -#else +//2.56 +const Word16 tdm_LSF_MEAN_RE_USE_OUT_fx[M] = +{ + 771, 1335, 2229, 3431, 4383, 5354, 6371, 7273, 8183, 9198, 10133, 10991, 12058, 13104, 14200, 15152 +}; +//2.56 +const Word16 tdm_LSF_MEAN_RE_USE_IN_fx[M] = +{ + 733, 1337, 2271, 3451, 4418, 5382, 6430, 7304, 8221, 9247, 10165, 11079, 12115, 13197, 14266, 15269, +}; +//2.56 +const Word16 tdm_LSF_MEAN_RE_USE_fx[M] = +{ + 680, 1369, 2354, 3448, 4498, 5435, 6546, 7494, 8446, 9437, 10328, 11248, 12241, 13199, 14189, 15174 +}; + +const Word16 tdm_Beta_Q1bit_re_use_13k2_fx[2] = { 31784, 24576 };//Q15 +const Word16 tdm_Beta_Q1bit_re_use_16k4_fx[2] = { 31129, 23265 };//Q15 +const Word16 tdm_Beta_Q1bit_re_use_24k4_32k_fx[2] = { 30474, 23920 };//Q15 +const Word16 tdm_Beta_Q1bit_re_use_48k_fx[2] = { 31784, 25231 };//Q15 + +//Q15 +const Word16 tdm_RE_USE_adaptive_beta_prd_diag_3_fx[15 + 16 + 15] = +{ + 29028, 6750, 1916, 27016, 7516, 1195, 26787, 5557, -196, 27796, 6753, 2172, 29434, 4446, 2175, 26053, 6337, 3063, 26043, 5521, 3633, 26082, + 5989, 3515, 25672, 5911, 4846, 24123, 6494, 4374, 24971, 6225, 6235, 24146, 5619, 5848, 23638, 5393, 6445, 22579, 4027, 6694, 20698, 1779, + 5789, 17681 +}; +//2.56 +const Word16 tdm_LSF_MEAN_PRED_QNT_fx[M] = +{ + 1002, 1558, 2478, 3467, 4377, 5326, 6274, 7160, 8182, 9099, 10022, 10967, 12051, 13081, 14148, 15113 +}; +//2.56 +const Word16 tdm_LSF_MEAN_PRED_QNT_IN_fx[M] = +{ + 739, 1371, 2303, 3436, 4431, 5394, 6378, 7321, 8293, 9282, 10221, 11153, 12166, 13193, 14252, 15290 +}; +//2.56 +const Word16 tdm_LSF_MEAN_PRED_QNT_OUT_fx[M] = +{ + 733, 1337, 2271, 3451, 4418, 5382, 6430, 7304, 8221, 9247, 10165, 11079, 12115, 13197, 14266, 15269 +}; +//Q15 +const Word16 tdm_PRED_QNT_fixed_beta_prd_diag_3_fx[15 + 16 + 15] = +{ + 23067, 3941, -3666, 24050, 5907, 829, 21960, 6229, -6052, 25859, 9862, -1369, 28559, 6019, 108, 22658, 7844, 697, 22045, 7998, 2310, 24735, + 6497, 2464, 23434, 7120, 2903, 20194, 10049, 711, 26610, 6622, 5190, 23955, 5721, 3945, 23906, 6481, 4033, 24581, 4043, 5599, 20879, 3473, + 3909, 21541 +}; +#endif /* LSFs Intra-frame prediction tables */ const float tdm_LSF_MEAN_RE_USE_OUT[M] = { @@ -839,7 +812,7 @@ const float tdm_PRED_QNT_fixed_beta_prd_diag_3[15 + 16 + 15] = 0.1709f, 0.6372f, 0.1060f, 0.1193f, 0.6574f, }; -#endif + const int16_t fast_FCB_bits_2sfr[] = {8, 14, 18, 20, 24, 128/*stop value*/}; const int16_t fast_FCB_rates_2sfr[] = {/*16*50,*/ (8+14)*50, 28*50, 32*50, 34*50, 36*50, 38*50, 40*50, 42*50, 44*50, 48*50}; diff --git a/lib_com/ivas_rom_com.h b/lib_com/ivas_rom_com.h index e2bc05fa6..05539e1d7 100644 --- a/lib_com/ivas_rom_com.h +++ b/lib_com/ivas_rom_com.h @@ -112,22 +112,22 @@ extern const int16_t tdm_bit_allc_tbl[5][6]; /* LSFs Intra-frame prediction tables */ #ifdef IVAS_FLOAT_FIXED -extern const Word32 tdm_LSF_MEAN_RE_USE_OUT_fx[M]; -extern const Word32 tdm_LSF_MEAN_RE_USE_IN_fx[M]; -extern const Word32 tdm_LSF_MEAN_RE_USE_fx[M]; - -extern const Word32 tdm_Beta_Q1bit_re_use_13k2_fx[2]; -extern const Word32 tdm_Beta_Q1bit_re_use_16k4_fx[2]; -extern const Word32 tdm_Beta_Q1bit_re_use_24k4_32k_fx[2]; -extern const Word32 tdm_Beta_Q1bit_re_use_48k_fx[2]; - -extern const Word32 tdm_RE_USE_adaptive_beta_prd_diag_3_fx[15 + 16 + 15]; - -extern const Word32 tdm_LSF_MEAN_PRED_QNT_OUT_fx[M]; -extern const Word32 tdm_LSF_MEAN_PRED_QNT_IN_fx[M]; -extern const Word32 tdm_LSF_MEAN_PRED_QNT_fx[M]; -extern const Word32 tdm_PRED_QNT_fixed_beta_prd_diag_3_fx[15 + 16 + 15]; -#else +extern const Word16 tdm_LSF_MEAN_RE_USE_OUT_fx[M]; +extern const Word16 tdm_LSF_MEAN_RE_USE_IN_fx[M]; +extern const Word16 tdm_LSF_MEAN_RE_USE_fx[M]; + +extern const Word16 tdm_Beta_Q1bit_re_use_13k2_fx[2]; +extern const Word16 tdm_Beta_Q1bit_re_use_16k4_fx[2]; +extern const Word16 tdm_Beta_Q1bit_re_use_24k4_32k_fx[2]; +extern const Word16 tdm_Beta_Q1bit_re_use_48k_fx[2]; + +extern const Word16 tdm_RE_USE_adaptive_beta_prd_diag_3_fx[15 + 16 + 15]; + +extern const Word16 tdm_LSF_MEAN_PRED_QNT_OUT_fx[M]; +extern const Word16 tdm_LSF_MEAN_PRED_QNT_IN_fx[M]; +extern const Word16 tdm_LSF_MEAN_PRED_QNT_fx[M]; +extern const Word16 tdm_PRED_QNT_fixed_beta_prd_diag_3_fx[15 + 16 + 15]; +#endif extern const float tdm_LSF_MEAN_RE_USE_OUT[M]; extern const float tdm_LSF_MEAN_RE_USE_IN[M]; extern const float tdm_LSF_MEAN_RE_USE[M]; @@ -143,7 +143,7 @@ extern const float tdm_LSF_MEAN_PRED_QNT_OUT[M]; extern const float tdm_LSF_MEAN_PRED_QNT_IN[M]; extern const float tdm_LSF_MEAN_PRED_QNT[M]; extern const float tdm_PRED_QNT_fixed_beta_prd_diag_3[15 + 16 + 15]; -#endif + extern const int16_t fast_FCB_bits_2sfr[]; extern const int16_t fast_FCB_rates_2sfr[]; diff --git a/lib_com/ivas_rom_com_fx.c b/lib_com/ivas_rom_com_fx.c index ffdeb37be..ec6735a07 100644 --- a/lib_com/ivas_rom_com_fx.c +++ b/lib_com/ivas_rom_com_fx.c @@ -548,6 +548,12 @@ const Word16 pow_10_q11[128] = { 13540, 13786, 14036, 14291, 14550, 14815, 15084, 15357, 15636, 15920, 16209, 16503, 16803, 17108, 17418, 17734, 18056, 18384, 18718, 19058, 19404, 19756, 20114 }; +#ifdef IVAS_FLOAT_FIXED +const Word32 pow_10_q23[14] = { + 2364231, 2652711, 3339565, 4204263, 5803499, 8011059, 8388608, 6818517, 7222539, 5292854, 4204263, 6977341, 7919357, 8388608 +}; +#endif + /* clang-format on */ const Word16 ivas_tan_panning_gain_dirac_tbl_fx[601] = { SHC( 0x8000 ), SHC( 0x8001 ), SHC( 0x8002 ), SHC( 0x8003 ), SHC( 0x8005 ), SHC( 0x8007 ), SHC( 0x800a ), SHC( 0x800e ), diff --git a/lib_com/ivas_rom_com_fx.h b/lib_com/ivas_rom_com_fx.h index b441430a5..b12c4ab05 100644 --- a/lib_com/ivas_rom_com_fx.h +++ b/lib_com/ivas_rom_com_fx.h @@ -81,7 +81,9 @@ extern const Word32 ls_elevation_CICP16_fx[9]; extern const Word32 ls_azimuth_CICP19_fx[11]; extern const Word32 ls_elevation_CICP19_fx[11]; extern const Word16 pow_10_q11[128]; - +#ifdef IVAS_FLOAT_FIXED +extern const Word32 pow_10_q23[14]; +#endif extern const Word16 ivas_sin_az_fx[ 361 ]; extern const Word16 ivas_sine_panning_tbl_fx[601]; extern const Word16 ivas_tan_panning_gain_dirac_tbl_fx[601]; diff --git a/lib_com/ivas_stereo_td_bit_alloc.c b/lib_com/ivas_stereo_td_bit_alloc.c index 51903044e..2cbc2e108 100644 --- a/lib_com/ivas_stereo_td_bit_alloc.c +++ b/lib_com/ivas_stereo_td_bit_alloc.c @@ -559,22 +559,22 @@ void td_stereo_param_updt_fx( *-------------------------------------------------------------------*/ static void tdm_SCh_LSF_intra_pred_zero_bits_fx( - const Word32 *tdm_lsfQ_PCh_fx, /* i : primary channel LSFs */ - Word32 *pred_lsf_SCh_fx, /* o : predicted secondary channel LSFs */ - const Word32 *lsf_mean_fx, /* i : secondary channel mean LSFs */ - const Word32 beta_fx /* i : pull to average beta factor */ + const Word16 *tdm_lsfQ_PCh_fx, /* i : primary channel LSFs */ + Word16 *pred_lsf_SCh_fx, /* o : predicted secondary channel LSFs */ + const Word16 *lsf_mean_fx, /* i : secondary channel mean LSFs */ + const Word16 beta_fx /* i : pull to average beta factor */ ) { Word16 i; /* pulling the LSFs closer to the average */ FOR( i = 0; i < M; i++ ) { - pred_lsf_SCh_fx[i] = L_add( Mpy_32_32( beta_fx, tdm_lsfQ_PCh_fx[i] ), Mpy_32_32( L_sub( ONE_IN_Q31, beta_fx ), lsf_mean_fx[i] ) ); + pred_lsf_SCh_fx[i] = add( mult_r( beta_fx, tdm_lsfQ_PCh_fx[i] ), mult_r( sub( 32767, beta_fx ), lsf_mean_fx[i] ) ); } return; } -#else +#endif /*-------------------------------------------------------------------* * tdm_SCh_LSF_intra_pred_zero_bits() * @@ -598,7 +598,7 @@ static void tdm_SCh_LSF_intra_pred_zero_bits( return; } -#endif + #ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * tdm_SCh_LSF_intra_pred_tri_diag_mat_fx() @@ -607,51 +607,53 @@ static void tdm_SCh_LSF_intra_pred_zero_bits( *-------------------------------------------------------------------*/ static void tdm_SCh_LSF_intra_pred_tri_diag_mat_fx( - Word32 *lsf_SCh_fx, /* i/o: secondary channel LSFs */ - const Word32 *lsf_mean_in_fx, /* i : secondary channel mean LSFs (in) */ - const Word32 *lsf_mean_out_fx, /* i : secondary channel mean LSFs (out) */ - const Word32 *prd_diag_3_fx /* i : secondary channel mean LSFs */ + Word16 *lsf_SCh_fx, /* i/o: secondary channel LSFs */ + const Word16 *lsf_mean_in_fx, /* i : secondary channel mean LSFs (in) */ + const Word16 *lsf_mean_out_fx, /* i : secondary channel mean LSFs (out) */ + const Word16 *prd_diag_3_fx /* i : secondary channel mean LSFs */ ) { Word16 i; - Word32 lsf_tmp_fx[M]; - const Word32 *prd_ptr_fx; - Word32 *lsf_tmp_ptr1_fx; - Word32 *lsf_tmp_ptr2_fx; - Word32 *lsf_SCh_ptr_fx; + Word16 lsf_tmp_fx[M]; + const Word16 *prd_ptr_fx; + Word16 *lsf_tmp_ptr1_fx; + Word16 *lsf_tmp_ptr2_fx; + Word16 *lsf_SCh_ptr_fx; prd_ptr_fx = prd_diag_3_fx; - v_sub_32( lsf_SCh_fx, lsf_mean_in_fx, lsf_tmp_fx, M ); + v_sub_16( lsf_SCh_fx, lsf_mean_in_fx, lsf_tmp_fx, M ); lsf_tmp_ptr1_fx = lsf_tmp_fx; lsf_SCh_ptr_fx = lsf_SCh_fx; lsf_tmp_ptr2_fx = lsf_tmp_ptr1_fx; - *lsf_SCh_ptr_fx = Mpy_32_32( *lsf_tmp_ptr1_fx++, *prd_ptr_fx++ ); - *lsf_SCh_ptr_fx = L_add( *lsf_SCh_ptr_fx, Mpy_32_32( *lsf_tmp_ptr1_fx++, *prd_ptr_fx++ ) ); + *lsf_SCh_ptr_fx = mult_r( *lsf_tmp_ptr1_fx++, *prd_ptr_fx++ ); //Q2.56 + 15 -15 + *lsf_SCh_ptr_fx = add( *lsf_SCh_ptr_fx, mult_r( *lsf_tmp_ptr1_fx, *prd_ptr_fx++ ) );//Q2.56 + 15 -15 lsf_SCh_ptr_fx++; FOR( i = 1; i < M - 1; i++ ) { - lsf_tmp_ptr1_fx = lsf_tmp_ptr2_fx; - *lsf_SCh_ptr_fx = Mpy_32_32( *lsf_tmp_ptr1_fx++, *prd_ptr_fx++ ); + lsf_tmp_ptr1_fx = lsf_tmp_ptr2_fx;//Q2.56 + *lsf_SCh_ptr_fx = mult_r( *lsf_tmp_ptr1_fx++, *prd_ptr_fx++ );//Q2.56 + 15 -15 lsf_tmp_ptr2_fx = lsf_tmp_ptr1_fx; - *lsf_SCh_ptr_fx = L_add( *lsf_SCh_ptr_fx, Mpy_32_32( ( *lsf_tmp_ptr1_fx++ ), ( *prd_ptr_fx++ ) ) ); - ( *lsf_SCh_ptr_fx ) = L_add( *lsf_SCh_ptr_fx, Mpy_32_32( ( *lsf_tmp_ptr1_fx ), ( *prd_ptr_fx++ ) ) ); + *lsf_SCh_ptr_fx = add( *lsf_SCh_ptr_fx, mult_r( ( *lsf_tmp_ptr1_fx++ ), ( *prd_ptr_fx++ ) ) ); + ( *lsf_SCh_ptr_fx ) = add( *lsf_SCh_ptr_fx, mult_r( ( *lsf_tmp_ptr1_fx ), ( *prd_ptr_fx++ ) ) ); lsf_SCh_ptr_fx++; } lsf_tmp_ptr1_fx = lsf_tmp_ptr2_fx; + *lsf_SCh_ptr_fx = mult_r((*lsf_tmp_ptr1_fx), (*prd_ptr_fx)); + *lsf_tmp_ptr1_fx++; + *prd_ptr_fx++; + *lsf_SCh_ptr_fx = add( mult_r( ( *lsf_tmp_ptr1_fx), ( *prd_ptr_fx) ), *lsf_SCh_ptr_fx); - *lsf_SCh_ptr_fx = L_add( Mpy_32_32( ( *lsf_tmp_ptr1_fx++ ), ( *prd_ptr_fx++ ) ), Mpy_32_32( ( *lsf_tmp_ptr1_fx ), ( *prd_ptr_fx ) ) ); - - v_add_32( lsf_SCh_fx, lsf_mean_out_fx, lsf_SCh_fx, M ); + v_add_16( lsf_SCh_fx, lsf_mean_out_fx, lsf_SCh_fx, M ); return; } -#else +#endif /*-------------------------------------------------------------------* * tdm_SCh_LSF_intra_pred_tri_diag_mat() * @@ -700,7 +702,7 @@ static void tdm_SCh_LSF_intra_pred_tri_diag_mat( return; } -#endif + #ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * tdm_SCh_LSF_intra_pred_fx() @@ -710,31 +712,31 @@ static void tdm_SCh_LSF_intra_pred_tri_diag_mat( void tdm_SCh_LSF_intra_pred_fx( const Word32 element_brate, /* i : element bitrate */ - const Word32 *tdm_lsfQ_PCh_fx, /* i : primary channel LSFs */ - Word32 *pred_lsf_SCh_fx /* o : predicted secondary channel LSFs */ + const Word16 *tdm_lsfQ_PCh_fx, /* i : primary channel LSFs */ + Word16 *pred_lsf_SCh_fx /* o : predicted secondary channel LSFs */ ) { - Word32 fixed_beta; + Word16 fixed_beta; IF( element_brate <= IVAS_13k2 ) { - fixed_beta = 1868310773; // 0.87f in Q31 + fixed_beta = 28508; // 0.87f in Q15 } ELSE IF( element_brate <= IVAS_16k4 ) { - fixed_beta = 2018634629; // 0.94f in Q31 + fixed_beta = 30801; // 0.94f in Q15 } ELSE IF( element_brate <= IVAS_24k4 ) { - fixed_beta = 1954210119; // 0.91f in Q31 + fixed_beta = 29818; // 0.91f in Q15 } ELSE IF( element_brate <= IVAS_32k ) { - fixed_beta = 1975684956; // 0.92f in Q31 + fixed_beta = 30146; // 0.92f in Q15 } ELSE { - fixed_beta = 1954210119; // 0.91f in Q31 + fixed_beta = 29818; // 0.91f in Q15 } tdm_SCh_LSF_intra_pred_zero_bits_fx( tdm_lsfQ_PCh_fx, pred_lsf_SCh_fx, tdm_LSF_MEAN_PRED_QNT_fx, fixed_beta ); @@ -757,47 +759,6 @@ void tdm_SCh_LSF_intra_pred( float *pred_lsf_SCh /* o : predicted secondary channel LSFs */ ) { -#ifdef IVAS_FLOAT_FIXED - Word32 fixed_beta; - - IF( element_brate <= IVAS_13k2 ) - { - fixed_beta = 1868310773; // 0.87f in Q31 - } - ELSE IF( element_brate <= IVAS_16k4 ) - { - fixed_beta = 2018634629; // 0.94f in Q31 - } - ELSE IF( element_brate <= IVAS_24k4 ) - { - fixed_beta = 1954210119; // 0.91f in Q31 - } - ELSE IF( element_brate <= IVAS_32k ) - { - fixed_beta = 1975684956; // 0.92f in Q31 - } - ELSE - { - fixed_beta = 1954210119; // 0.91f in Q31 - } - - Word32 pred_lsf_SCh_fx[M]; - Word32 tdm_lsfQ_PCh_fx[M]; - - FOR( Word16 i = 0; i < M; i++ ) - { - tdm_lsfQ_PCh_fx[i] = (Word32) ( tdm_lsfQ_PCh[i] * ( 1 << 18 ) ); - } - - tdm_SCh_LSF_intra_pred_zero_bits_fx( tdm_lsfQ_PCh_fx, pred_lsf_SCh_fx, tdm_LSF_MEAN_PRED_QNT_fx, fixed_beta ); - - tdm_SCh_LSF_intra_pred_tri_diag_mat_fx( pred_lsf_SCh_fx, tdm_LSF_MEAN_PRED_QNT_IN_fx, tdm_LSF_MEAN_PRED_QNT_OUT_fx, tdm_PRED_QNT_fixed_beta_prd_diag_3_fx ); - - FOR( Word16 i = 0; i < M; i++ ) - { - pred_lsf_SCh[i] = (float) pred_lsf_SCh_fx[i] / ( 1 << 18 ); - } -#else float fixed_beta; if ( element_brate <= IVAS_13k2 ) @@ -824,7 +785,7 @@ void tdm_SCh_LSF_intra_pred( tdm_SCh_LSF_intra_pred_zero_bits( tdm_lsfQ_PCh, pred_lsf_SCh, tdm_LSF_MEAN_PRED_QNT, fixed_beta ); tdm_SCh_LSF_intra_pred_tri_diag_mat( pred_lsf_SCh, tdm_LSF_MEAN_PRED_QNT_IN, tdm_LSF_MEAN_PRED_QNT_OUT, tdm_PRED_QNT_fixed_beta_prd_diag_3 ); -#endif + return; } @@ -836,27 +797,27 @@ void tdm_SCh_LSF_intra_pred( *-------------------------------------------------------------------*/ static void tdm_SCh_LSF_intra_pred_one_bit_dec_fx( - const Word32 *tdm_lsfQ_PCh_fx, /* i : primary channel LSFs */ - Word32 *pred_lsf_SCh_fx, /* o : predicted secondary channel LSFs */ - const Word32 *lsf_mean_fx, /* i : secondary channel mean LSFs */ - const Word32 *Beta_Q_x_fx, /* i : beta quantization values */ + const Word16 *tdm_lsfQ_PCh_fx, /* i : primary channel LSFs */ + Word16 *pred_lsf_SCh_fx, /* o : predicted secondary channel LSFs */ + const Word16 *lsf_mean_fx, /* i : secondary channel mean LSFs */ + const Word16 *Beta_Q_x_fx, /* i : beta quantization values */ const Word16 beta_index_fx /* i : the quantization bits for beta (-1 if beta fixed)*/ ) { Word16 i; - Word32 beta_fx; + Word16 beta_fx; - beta_fx = Beta_Q_x_fx[beta_index_fx]; // Q31 + beta_fx = Beta_Q_x_fx[beta_index_fx]; // Q15 /* pulling the LSFs closer to the avergae */ - for ( i = 0; i < M; i++ ) + FOR ( i = 0; i < M; i++ ) { - pred_lsf_SCh_fx[i] = Madd_32_32( Mpy_32_32( beta_fx, tdm_lsfQ_PCh_fx[i] ), L_sub( ONE_IN_Q31, beta_fx ), lsf_mean_fx[i] ); + pred_lsf_SCh_fx[i] = add( mult_r( beta_fx, tdm_lsfQ_PCh_fx[i] ), mult_r(sub( 32767, beta_fx ), lsf_mean_fx[i] )); } return; } -#else +#endif /*-------------------------------------------------------------------* * tdm_SCh_LSF_intra_pred_one_bit_dec() * @@ -884,7 +845,7 @@ static void tdm_SCh_LSF_intra_pred_one_bit_dec( return; } -#endif + #ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * tdm_SCh_LSF_intra_pred_one_bit_enc_fx() @@ -893,31 +854,37 @@ static void tdm_SCh_LSF_intra_pred_one_bit_dec( *-------------------------------------------------------------------*/ static void tdm_SCh_LSF_intra_pred_one_bit_enc_fx( - const Word32 *lsf_SCh_fx, /* i : secondary channel LSFs */ - const Word32 *tdm_lsfQ_PCh_fx, /* i : primary channel LSFs */ - Word32 *pred_lsf_SCh_fx, /* o : predicted secondary channel LSFs */ - const Word32 *lsf_mean_fx, /* i : secondary channel mean LSFs */ - const Word32 *lsf_wgts_new_fx, /* i : Improved wgts for LSFs */ - const Word32 *Beta_Q_x_fx, /* i : beta quantization values */ + const Word16 *lsf_SCh_fx, /* i : secondary channel LSFs */ + const Word16 *tdm_lsfQ_PCh_fx, /* i : primary channel LSFs */ + Word16 *pred_lsf_SCh_fx, /* o : predicted secondary channel LSFs */ + const Word16 *lsf_mean_fx, /* i : secondary channel mean LSFs */ + const Word16 *lsf_wgts_new_fx, /* i : Improved wgts for LSFs */ + const Word16 *Beta_Q_x_fx, /* i : beta quantization values */ Word16 *beta_index /* o : the quantization bits for beta (-1 if beta fixed) */ ) { Word16 i; - Word32 A_temp_fx[M]; - Word32 B_temp_fx[M]; + Word16 A_temp_fx[M]; + Word16 B_temp_fx[M]; Word32 WD_fx[2] = { 0 }; FOR( i = 0; i < M; i++ ) { - A_temp_fx[i] = L_sub( lsf_SCh_fx[i], lsf_mean_fx[i] ); - B_temp_fx[i] = L_sub( lsf_mean_fx[i], tdm_lsfQ_PCh_fx[i] ); + A_temp_fx[i] = sub( lsf_SCh_fx[i], lsf_mean_fx[i] ); + B_temp_fx[i] = sub( lsf_mean_fx[i], tdm_lsfQ_PCh_fx[i] ); } FOR( i = 0; i < M; i++ ) { - WD_fx[0] += Mpy_32_32( lsf_wgts_new_fx[i], Mpy_32_32( A_temp_fx[i], A_temp_fx[i] ) ) + 2 * Mpy_32_32( Beta_Q_x_fx[0], Mpy_32_32( lsf_wgts_new_fx[i], Mpy_32_32( A_temp_fx[i], B_temp_fx[i] ) ) ) + Mpy_32_32( lsf_wgts_new_fx[i], Mpy_32_32( Mpy_32_32( Beta_Q_x_fx[0], Beta_Q_x_fx[0] ), Mpy_32_32( B_temp_fx[i], B_temp_fx[i] ) ) ); - WD_fx[1] += Mpy_32_32( lsf_wgts_new_fx[i], Mpy_32_32( A_temp_fx[i], A_temp_fx[i] ) ) + 2 * Mpy_32_32( Beta_Q_x_fx[1], Mpy_32_32( lsf_wgts_new_fx[i], Mpy_32_32( A_temp_fx[i], B_temp_fx[i] ) ) ) + Mpy_32_32( lsf_wgts_new_fx[i], Mpy_32_32( Mpy_32_32( Beta_Q_x_fx[1], Beta_Q_x_fx[1] ), Mpy_32_32( B_temp_fx[i], B_temp_fx[i] ) ) ); + Word32 wgt_A_temp = Mpy_32_16_1(L_mult(A_temp_fx[i], A_temp_fx[i]), lsf_wgts_new_fx[i]);// + Word32 wgt_B_temp = Mpy_32_16_1(L_mult(B_temp_fx[i], B_temp_fx[i]), lsf_wgts_new_fx[i]); + Word32 wgt_AB_temp = Mpy_32_16_1(L_mult(A_temp_fx[i], B_temp_fx[i]), lsf_wgts_new_fx[i]); + Word32 Beta_Q_x0 = L_mult(Beta_Q_x_fx[0], Beta_Q_x_fx[0]);//Q31 + Word32 Beta_Q_x1 = L_mult(Beta_Q_x_fx[1], Beta_Q_x_fx[1]);//Q31 + + WD_fx[0] = L_add(WD_fx[0], L_add(L_add(wgt_A_temp, Mpy_32_16_1(L_shl(wgt_AB_temp, 1), Beta_Q_x_fx[0])), Mpy_32_32(wgt_B_temp, Beta_Q_x0))); + WD_fx[1] = L_add(WD_fx[1], L_add(L_add(wgt_A_temp, Mpy_32_16_1(L_shl(wgt_AB_temp, 1), Beta_Q_x_fx[1])), Mpy_32_32(wgt_B_temp, Beta_Q_x1))); } IF( WD_fx[0] < WD_fx[1] ) @@ -933,7 +900,7 @@ static void tdm_SCh_LSF_intra_pred_one_bit_enc_fx( return; } -#else +#endif /*-------------------------------------------------------------------* * tdm_SCh_LSF_intra_pred_one_bit_enc() * @@ -982,7 +949,7 @@ static void tdm_SCh_LSF_intra_pred_one_bit_enc( return; } -#endif + #ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * tdm_SCh_lsf_reuse_fx() @@ -993,26 +960,24 @@ static void tdm_SCh_LSF_intra_pred_one_bit_enc( void tdm_SCh_lsf_reuse_fx( const Word16 enc_dec, /* i : encoder/decoder flag */ const Word32 element_brate, /* i : element bitrate */ - Word32 lsf_new_fx[M], /* i/o: LSFs at the end of the frame */ - Word16 lsf_new_q_fx, + Word16 lsf_new_fx[M], /* i/o: LSFs at the end of the frame */ Word16 lsp_new_fx[M], /* i/o: LSPs at the end of the frame */ - Word16 lsp_new_q_fx, - const Word32 tdm_lsfQ_PCh_fx[M], /* i : primary channel LSFs */ - const Word32 lsf_wgts_fx[M], /* i : LSF weights */ + const Word16 tdm_lsfQ_PCh_fx[M], /* i : primary channel LSFs */ + const Word16 lsf_wgts_fx[M], /* i : LSF weights */ Word16 *beta_index /* i/o: quantization index */ ) { - const Word32 *Beta_Q1bit_re_use_fx; + const Word16 *Beta_Q1bit_re_use_fx; - IF( element_brate <= IVAS_13k2 ) + IF( LE_32(element_brate, IVAS_13k2 )) { Beta_Q1bit_re_use_fx = tdm_Beta_Q1bit_re_use_13k2_fx; } - ELSE IF( element_brate <= IVAS_16k4 ) + ELSE IF(LE_32(element_brate, IVAS_16k4 )) { Beta_Q1bit_re_use_fx = tdm_Beta_Q1bit_re_use_16k4_fx; } - ELSE IF( element_brate <= IVAS_32k ) + ELSE IF(LE_32(element_brate, IVAS_32k )) { Beta_Q1bit_re_use_fx = tdm_Beta_Q1bit_re_use_24k4_32k_fx; } @@ -1021,7 +986,7 @@ void tdm_SCh_lsf_reuse_fx( Beta_Q1bit_re_use_fx = tdm_Beta_Q1bit_re_use_48k_fx; } - IF( enc_dec == ENC ) + IF( EQ_16(enc_dec, ENC )) { tdm_SCh_LSF_intra_pred_one_bit_enc_fx( lsf_new_fx, tdm_lsfQ_PCh_fx, lsf_new_fx, tdm_LSF_MEAN_RE_USE_fx, lsf_wgts_fx, Beta_Q1bit_re_use_fx, beta_index ); } @@ -1032,7 +997,7 @@ void tdm_SCh_lsf_reuse_fx( tdm_SCh_LSF_intra_pred_tri_diag_mat_fx( lsf_new_fx, tdm_LSF_MEAN_RE_USE_IN_fx, tdm_LSF_MEAN_RE_USE_OUT_fx, tdm_RE_USE_adaptive_beta_prd_diag_3_fx ); - lsf2lsp_32_fx( lsf_new_fx, lsf_new_q_fx, lsp_new_fx, &lsp_new_q_fx, M, INT_FS_12k8 ); + lsf2lsp_fx( lsf_new_fx, lsp_new_fx, M, INT_FS_12k8 ); return; } @@ -1054,61 +1019,6 @@ void tdm_SCh_lsf_reuse( int16_t *beta_index /* i/o: quantization index */ ) { -#ifdef IVAS_FLOAT_FIXED - ////////// to be removed //////////////// - Word32 lsf_new_fx[M]; - Word32 tdm_lsfQ_PCh_fx[M]; - Word32 lsf_wgts_fx[M]; - Word16 lsp_new_fx[M]; - Word16 lsf_new_q_fx = 18; - Word16 lsp_new_q_fx; - FOR( Word16 i = 0; i < M; i++ ) - { - lsf_new_fx[i] = (Word32) ( lsf_new[i] * ( 1 << lsf_new_q_fx ) ); - tdm_lsfQ_PCh_fx[i] = (Word32) ( tdm_lsfQ_PCh[i] * ( 1 << 18 ) ); - IF( enc_dec == ENC ) - { - lsf_wgts_fx[i] = (Word32) ( lsf_wgts[i] * ( 1 << 26 ) ); - } - } - ///////////////////////////////////////// - const Word32 *Beta_Q1bit_re_use_fx; - IF( element_brate <= IVAS_13k2 ) - { - Beta_Q1bit_re_use_fx = tdm_Beta_Q1bit_re_use_13k2_fx; - } - ELSE IF( element_brate <= IVAS_16k4 ) - { - Beta_Q1bit_re_use_fx = tdm_Beta_Q1bit_re_use_16k4_fx; - } - ELSE IF( element_brate <= IVAS_32k ) - { - Beta_Q1bit_re_use_fx = tdm_Beta_Q1bit_re_use_24k4_32k_fx; - } - ELSE - { - Beta_Q1bit_re_use_fx = tdm_Beta_Q1bit_re_use_48k_fx; - } - - IF( enc_dec == ENC ) - { - tdm_SCh_LSF_intra_pred_one_bit_enc_fx( lsf_new_fx, tdm_lsfQ_PCh_fx, lsf_new_fx, tdm_LSF_MEAN_RE_USE_fx, lsf_wgts_fx, Beta_Q1bit_re_use_fx, beta_index ); - } - ELSE /* DEC */ - { - tdm_SCh_LSF_intra_pred_one_bit_dec_fx( tdm_lsfQ_PCh_fx, lsf_new_fx, tdm_LSF_MEAN_RE_USE_fx, Beta_Q1bit_re_use_fx, *beta_index ); - } - - tdm_SCh_LSF_intra_pred_tri_diag_mat_fx( lsf_new_fx, tdm_LSF_MEAN_RE_USE_IN_fx, tdm_LSF_MEAN_RE_USE_OUT_fx, tdm_RE_USE_adaptive_beta_prd_diag_3_fx ); - - lsf2lsp_32_fx( lsf_new_fx, lsf_new_q_fx, lsp_new_fx, &lsp_new_q_fx, M, INT_FS_12k8 ); - - FOR( Word16 i = 0; i < M; i++ ) - { - lsf_new[i] = (float) lsf_new_fx[i] / ( 1 << lsf_new_q_fx ); - lsp_new[i] = (float) lsp_new_fx[i] / ( 1 << lsp_new_q_fx ); - } -#else const float *Beta_Q1bit_re_use; if ( element_brate <= IVAS_13k2 ) @@ -1140,6 +1050,6 @@ void tdm_SCh_lsf_reuse( tdm_SCh_LSF_intra_pred_tri_diag_mat( lsf_new, tdm_LSF_MEAN_RE_USE_IN, tdm_LSF_MEAN_RE_USE_OUT, tdm_RE_USE_adaptive_beta_prd_diag_3 ); lsf2lsp( lsf_new, lsp_new, M, INT_FS_12k8 ); -#endif + return; } diff --git a/lib_com/prot.h b/lib_com/prot.h index 8f204a011..f6ef4d6e9 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -2378,7 +2378,7 @@ ivas_error acelp_core_enc( float pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */ int16_t *unbits, /* o : number of unused bits */ STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ - const float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ + float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ ); ivas_error acelp_core_switch_dec_bfi( @@ -4589,8 +4589,8 @@ ivas_error acelp_core_dec( int16_t *unbits, /* o : number of unused bits */ int16_t *sid_bw, /* o : 0-NB/WB, 1-SWB SID */ STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ - const float tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */ - const float tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ + float tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */ + float tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ const int16_t use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ const int16_t last_element_mode, /* i : last element mode */ const int32_t last_element_brate, /* i : last element bitrate */ diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h index b466a7679..9b194e890 100644 --- a/lib_com/prot_fx2.h +++ b/lib_com/prot_fx2.h @@ -3569,25 +3569,24 @@ void cng_params_upd_fx( ); void cng_params_upd_ivas_fx( - const Word16 lsp_new[], /* i : LSP aprameters Q15 */ - const Word16 exc2[], /* i : current enhanced excitation Q_exc */ - const Word16 L_frame, /* i : frame length Q0 */ - Word16 *ho_circ_ptr, /* i/o: pointer for CNG averaging buffers Q0 */ - Word32 ho_ener_circ[], /* o : energy buffer for CNG averaging Q6 */ - Word16 *ho_circ_size, /* i/o: size of DTX hangover history buffer for averaging Q0 */ - Word16 ho_lsp_circ[], /* o : old LSP buffer for CNG averaging Q15 */ - const Word16 Q_exc, /* i : Q value of excitation */ - const Word16 enc_dec_flag, /* i : Flag indicating encoder or decoder (ENC,DEC) */ - Word32 ho_env_circ[], /* i/o: Envelope buffer */ - Word16 *cng_buf_cnt, /* i/o: Counter of postponed FFT-processing instances */ - Word16 cng_exc2_buf[], /* i/o: Excitation buffer Q_exc */ - Word16 cng_Qexc_buf[], /* i/o: Q_exc buffer Q0 */ - Word32 cng_brate_buf[], /* i/o: last_active_brate buffer Q0 */ - const Word32 last_active_brate, /* i : Last active bit rate Q0 */ - const Word16 element_mode, /* i : Element mode */ - const Word16 bwidth /* i : Audio bandwidth */ + const Word16 lsp_new[], /* i : LSP aprameters Q15 */ + const Word16 exc2[], /* i : current enhanced excitation Q_exc */ + const Word16 L_frame, /* i : frame length Q0 */ + Word16 *ho_circ_ptr, /* i/o: pointer for CNG averaging buffers Q0 */ + Word32 ho_ener_circ[], /* o : energy buffer for CNG averaging Q6 */ + Word16 *ho_circ_size, /* i/o: size of DTX hangover history buffer for averaging Q0 */ + Word16 ho_lsp_circ[], /* o : old LSP buffer for CNG averaging Q15 */ + const Word16 Q_exc, /* i : Q value of excitation */ + const Word16 enc_dec_flag,/* i : Flag indicating encoder or decoder (ENC,DEC) */ + Word32 ho_env_circ[], /* i/o: Envelope buffer */ + Word16 *cng_buf_cnt, /* i/o: Counter of postponed FFT-processing instances */ + Word16 cng_exc2_buf[], /* i/o: Excitation buffer Q_exc */ + Word16 cng_Qexc_buf[], /* i/o: Q_exc buffer Q0 */ + Word32 cng_brate_buf[], /* i/o: last_active_brate buffer Q0 */ + const Word32 last_active_brate /* i : Last active bit rate Q0 */ + , const Word16 element_mode, /* i : Element mode */ + const Word16 bwidth /* i : Audio bandwidth */ ); - int16_t get_cng_mode( const int32_t last_active_brate /* i : last active bitrate */ ); @@ -4771,6 +4770,14 @@ Word16 apply_scale_ind( const SCALE_SETUP *scaleTable, /* i : Scale table */ const Word16 scaleTableSize /* i : Size of scale table */ ); +void apply_scale_ivas_fx( + Word32 *scale, /* o : scalefactor */ + const Word16 bwmode, /* i : audio bandwidth */ + const Word32 bitrate, /* i : Bit rate */ + const SCALE_SETUP* scaleTable, /* i : Scale table */ + const Word16 scaleTableSize, /* i : Size of scale table */ + Word16 *index +); /* Compute the power for each partition */ void bandcombinepow( diff --git a/lib_dec/acelp_core_dec.c b/lib_dec/acelp_core_dec.c index 661041919..c7786ea44 100644 --- a/lib_dec/acelp_core_dec.c +++ b/lib_dec/acelp_core_dec.c @@ -68,8 +68,8 @@ ivas_error acelp_core_dec( int16_t *unbits, /* o : number of unused bits */ int16_t *sid_bw, /* o : 0-NB/WB, 1-SWB SID */ STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ - const float tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */ - const float tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ + float tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */ + float tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ const int16_t use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ const int16_t last_element_mode, /* i : last element mode */ const int32_t last_element_brate, /* i : last element bitrate */ @@ -780,7 +780,27 @@ ivas_error acelp_core_dec( int16_t beta_index; beta_index = get_next_indice( st, TDM_IC_LSF_PRED_BITS ); +#ifdef IVAS_FLOAT_FIXED + Word16 lsf_new_fx[M]; + Word16 lsp_new_fx[M]; + Word16 tdm_lsfQ_PCh_fx[M]; + for (int i = 0; i < M; i++) + { + lsf_new_fx[i] = (lsf_new[i]) * 2.56; + tdm_lsfQ_PCh_fx[i] = (tdm_lsfQ_PCh[i]) * 2.56; + } + floatToFixed_arr(lsp_new, lsp_new_fx, 15, M); + + tdm_SCh_lsf_reuse_fx(DEC, st->element_brate, lsf_new_fx, lsp_new_fx, tdm_lsfQ_PCh_fx, NULL, &beta_index); + + for (int i = 0; i < M; i++) + { + lsf_new[i] = (lsf_new_fx[i]) / 2.56; + } + fixedToFloat_arr(lsp_new_fx, lsp_new, 15, M); +#else tdm_SCh_lsf_reuse( DEC, st->element_brate, lsf_new, lsp_new, tdm_lsfQ_PCh, NULL, &beta_index ); +#endif } else { @@ -2363,7 +2383,7 @@ ivas_error acelp_core_dec( float max_real = 0.f, max_imag = 0.f; for (i = 0; i < CLDFB_NO_COL_MAX; i++) { - for (j = 0; j < CLDFB_NO_CHANNELS_MAX; j++) { + for ( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++) { max_real = (float)max(max_real , fabs(realBuffer[i][j])); max_imag = (float)max(max_imag, fabs(imagBuffer[i][j])); } @@ -2664,16 +2684,166 @@ ivas_error acelp_core_dec( * Updates *----------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED + ////////////////////////////////////// Float to fix starts here //////////////////////////////////////////////// + Word16 tmp_Q_exc = 0; + Word16 tmp_old_exc_fx[L_EXC_DEC]; // Q_exc + Word16 tmp_old_bwe_exc_fx[((PIT16k_MAX + (L_FRAME16k + 1) + L_SUBFR16k) * 2)]; // Q_exc + Word16 tmp_pitch_buf_fx[NB_SUBFR16k]; // Q6 + Word16 tmp_Es_pred_fx; // Q8 + Word16 tmp_Aq_fx[NB_SUBFR16k * (M + 1)]; // Q12 + Word16 tmp_lsf_new_fx[M]; // Qx2.56 + Word16 tmp_lsp_new_fx[M]; // Q15 + Word16 tmp_voice_factors_fx[NB_SUBFR16k]; // Q15 + Word16 tmp_gain_buf_fx[NB_SUBFR16k]; // Q14 + + floatToFixed_arr(old_exc, tmp_old_exc_fx, tmp_Q_exc, L_EXC_DEC); + floatToFixed_arr(old_bwe_exc, tmp_old_bwe_exc_fx, tmp_Q_exc, ((PIT16k_MAX + (L_FRAME16k + 1) + L_SUBFR16k) * 2)); + floatToFixed_arr(pitch_buf, tmp_pitch_buf_fx, Q6, NB_SUBFR16k); + tmp_Es_pred_fx = float_to_fix16(Es_pred, Q8); + floatToFixed_arr(Aq, tmp_Aq_fx, Q12, NB_SUBFR16k * (M + 1)); + for (i = 0; i < M; i++) + { + tmp_lsf_new_fx[i] = (Word16)(lsf_new[i] * 2.56f); + } + floatToFixed_arr(lsp_new, tmp_lsp_new_fx, Q15, M); + floatToFixed_arr(voice_factors, tmp_voice_factors_fx, Q15, NB_SUBFR16k); + floatToFixed_arr(gain_buf, tmp_voice_factors_fx, Q14, NB_SUBFR16k); + st->Last_GSC_noisy_speech_flag_fx = st->Last_GSC_noisy_speech_flag; + st->coder_type_fx = st->coder_type; + if (st->hGSCDec != NULL) + { + st->hGSCDec->Last_GSC_pit_band_idx_fx = st->hGSCDec->Last_GSC_pit_band_idx; + st->hGSCDec->seed_tcx_fx = st->hGSCDec->seed_tcx; + } + st->GSC_noisy_speech_fx = st->GSC_noisy_speech; + st->last_ppp_mode_dec_fx = st->last_ppp_mode_dec; + st->ppp_mode_dec_fx = st->ppp_mode_dec; + st->nelp_mode_dec_fx = st->nelp_mode_dec; + st->vbr_hw_BWE_disable_dec_fx = st->vbr_hw_BWE_disable_dec; + // just outputs: + if (st->hGSCDec != NULL) + { + st->hGSCDec->noise_lev_fx = st->hGSCDec->noise_lev; + floatToFixed_arr(st->hGSCDec->old_y_gain, st->hGSCDec->old_y_gain_fx, Q12, MBANDS_GN); + floatToFixed_arr(st->hGSCDec->Last_GSC_spectrum, st->hGSCDec->Last_GSC_spectrum_fx, Q10, M); + } + st->last_coder_type_fx = st->last_coder_type; + st->Last_GSC_noisy_speech_flag_fx = st->Last_GSC_noisy_speech_flag; + if (st->hHQ_core != NULL) + st->hHQ_core->HqVoicing_fx = st->hHQ_core->HqVoicing; + st->old_ppp_mode_fx = st->old_ppp_mode; + st->last_ppp_mode_dec_fx = st->last_ppp_mode_dec; + st->last_nelp_mode_dec_fx = st->last_nelp_mode_dec; + st->last_vbr_hw_BWE_disable_dec_fx = st->last_vbr_hw_BWE_disable_dec; + floatToFixed_arr(st->old_exc, st->old_exc_fx, tmp_Q_exc, L_EXC_MEM_DEC); + for (i = 0; i < M; i++) + { + st->lsf_old_fx[i] = (Word16)(st->lsf_old[i] * 2.56f); + } + floatToFixed_arr(st->lsp_old, st->lsp_old_fx, Q15, M); + st->last_voice_factor_fx = float_to_fix16(st->last_voice_factor, Q15); + floatToFixed_arrL(st->old_pitch_buf, st->old_pitch_buf_fx, Q16, 2 * NB_SUBFR16k + 2); + floatToFixed_arr(st->mem_pitch_gain_float, st->mem_pitch_gain, Q14, 2 * NB_SUBFR16k + 2); + for (i = 0; i < M; i++) + { + st->lsfoldbfi1[i] = (Word16)(st->lsfoldbfi1_fx[i] * 2.56f); + st->lsfoldbfi0[i] = (Word16)(st->lsfoldbfi0_fx[i] * 2.56f); + } + floatToFixed_arr(st->old_Aq_12_8, st->old_Aq_12_8_fx, Q12, M + 1); + st->old_Es_pred_fx = float_to_fix16(st->old_Es_pred, Q8); + ////////////////////////////////////// Float to fix ends here //////////////////////////////////////////////// + + updt_dec_fx( st, tmp_old_exc_fx, tmp_pitch_buf_fx, tmp_Es_pred_fx, tmp_Aq_fx, tmp_lsf_new_fx, tmp_lsp_new_fx, tmp_voice_factors_fx, tmp_old_bwe_exc_fx, tmp_gain_buf_fx ); + + ////////////////////////////////////// Fixed to float starts here //////////////////////////////////////////// + st->last_coder_type = st->last_coder_type_fx; + if (st->hGSCDec != NULL) + { + st->hGSCDec->noise_lev = st->hGSCDec->noise_lev_fx; + st->hGSCDec->Last_GSC_pit_band_idx = st->hGSCDec->Last_GSC_pit_band_idx_fx; + } + st->Last_GSC_noisy_speech_flag = st->Last_GSC_noisy_speech_flag_fx; + if (st->hHQ_core != NULL) + st->hHQ_core->HqVoicing = st->hHQ_core->HqVoicing_fx; + st->old_ppp_mode = st->old_ppp_mode_fx; + st->last_ppp_mode_dec = st->last_ppp_mode_dec_fx; + st->last_nelp_mode_dec = st->last_nelp_mode_dec_fx; + st->last_vbr_hw_BWE_disable_dec = st->last_vbr_hw_BWE_disable_dec_fx; + fixedToFloat_arr(st->old_exc_fx, st->old_exc, tmp_Q_exc, L_EXC_MEM_DEC); + IF(!st->Opt_AMR_WB && st->hBWE_TD != NULL) + fixedToFloat_arr(st->hBWE_TD->old_bwe_exc_fx, st->hBWE_TD->old_bwe_exc, tmp_Q_exc, PIT16k_MAX * 2); + for (i = 0; i < M; i++) + { + st->lsf_old[i] = st->lsf_old_fx[i] / 2.56f; + } + fixedToFloat_arr(st->lsp_old_fx, st->lsp_old, Q15, M); + st->last_voice_factor = fix16_to_float(st->last_voice_factor_fx, Q15); + if (st->hGSCDec != NULL) + { + fixedToFloat_arr(st->hGSCDec->Last_GSC_spectrum_fx, st->hGSCDec->Last_GSC_spectrum, Q10, M); + fixedToFloat_arr(st->hGSCDec->old_y_gain_fx, st->hGSCDec->old_y_gain, Q12, MBANDS_GN); + } + fixedToFloat_arrL(st->old_pitch_buf_fx, st->old_pitch_buf, Q16, 2 * NB_SUBFR16k + 2); + fixedToFloat_arr(st->mem_pitch_gain, st->mem_pitch_gain_float, Q14, 2 * NB_SUBFR16k + 2); + for (i = 0; i < M; i++) + { + st->lsfoldbfi1[i] = st->lsfoldbfi1_fx[i] / 2.56f; + st->lsfoldbfi0[i] = st->lsfoldbfi0_fx[i] / 2.56f; + } + fixedToFloat_arr(st->old_Aq_12_8_fx, st->old_Aq_12_8, Q12, M+1); + st->old_Es_pred = fix16_to_float(st->old_Es_pred_fx, Q8); + ////////////////////////////////////// Fixed to float ends here ////////////////////////////////////////////// +#else updt_dec( st, old_exc, pitch_buf, Es_pred, Aq, lsf_new, lsp_new, voice_factors, old_bwe_exc, gain_buf ); +#endif - if ( st->core_brate > SID_2k40 && st->hTdCngDec != NULL && st->hFdCngDec != NULL ) +#ifdef IVAS_FLOAT_FIXED + IF( GT_32( st->core_brate, SID_2k40 ) && st->hTdCngDec != NULL && st->hFdCngDec != NULL ) { /* update CNG parameters in active frames */ - cng_params_upd( lsp_new, exc, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ, DEC, st->hTdCngDec->ho_env_circ, NULL, NULL, NULL, st->last_active_brate, st->element_mode, st->hFdCngDec->hFdCngCom->CngBandwidth ); + Word16 lsp_new_fx[M]; + Word16 exc_fx[L_EXC_DEC], Q_exc, exp_exc; + f2me_buf_16( exc, exc_fx, &exp_exc, st->L_frame ); + Q_exc = 15 - exp_exc; + floatToFixed_arr( lsp_new, lsp_new_fx, Q15, M ); + floatToFixed_arr( exc, exc_fx, Q_exc, st->L_frame ); + floatToFixed_arrL( st->hTdCngDec->ho_ener_circ, st->hTdCngDec->ho_ener_circ_fx, Q6, HO_HIST_SIZE ); + st->hTdCngDec->ho_circ_size_fx = st->hTdCngDec->ho_circ_size; + st->hTdCngDec->ho_circ_ptr_fx = st->hTdCngDec->ho_circ_ptr; + floatToFixed_arr( st->hTdCngDec->ho_lsp_circ, st->hTdCngDec->ho_lsp_circ_fx, Q15, HO_HIST_SIZE * M ); + floatToFixed_arrL( st->hTdCngDec->ho_env_circ, st->hTdCngDec->ho_env_circ_fx, Q6, HO_HIST_SIZE * NUM_ENV_CNG ); + + cng_params_upd_ivas_fx( lsp_new_fx, exc_fx, st->L_frame, &st->hTdCngDec->ho_circ_ptr_fx, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size_fx, + st->hTdCngDec->ho_lsp_circ_fx, Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode, + st->hFdCngDec->hFdCngCom->CngBandwidth ); + + fixedToFloat_arr( lsp_new_fx, lsp_new, Q15, M ); + fixedToFloat_arr( exc_fx, exc, Q_exc, st->L_frame ); + fixedToFloat_arrL( st->hTdCngDec->ho_ener_circ_fx, st->hTdCngDec->ho_ener_circ, Q6, HO_HIST_SIZE ); + st->hTdCngDec->ho_circ_size = st->hTdCngDec->ho_circ_size_fx; + st->hTdCngDec->ho_circ_ptr = st->hTdCngDec->ho_circ_ptr_fx; + fixedToFloat_arr( st->hTdCngDec->ho_lsp_circ_fx, st->hTdCngDec->ho_lsp_circ, Q15, HO_HIST_SIZE * M ); + fixedToFloat_arrL( st->hTdCngDec->ho_env_circ_fx, st->hTdCngDec->ho_env_circ, Q6, HO_HIST_SIZE * NUM_ENV_CNG ); /* Set 16k LSP flag for CNG buffer */ - st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = ( st->L_frame == L_FRAME ? 0 : 1 ); + st->hTdCngDec->ho_16k_lsp_fx[st->hTdCngDec->ho_circ_ptr_fx] = 0; + move16(); + IF( NE_16( st->L_frame, L_FRAME ) ) + { + st->hTdCngDec->ho_16k_lsp_fx[st->hTdCngDec->ho_circ_ptr_fx] = 1; + move16(); + } + } +#else + if (st->core_brate > SID_2k40 && st->hTdCngDec != NULL && st->hFdCngDec != NULL) + { + /* update CNG parameters in active frames */ + cng_params_upd(lsp_new, exc, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ, DEC, st->hTdCngDec->ho_env_circ, NULL, NULL, NULL, st->last_active_brate, st->element_mode, st->hFdCngDec->hFdCngCom->CngBandwidth); + /* Set 16k LSP flag for CNG buffer */ + st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = (st->L_frame == L_FRAME ? 0 : 1); } +#endif pop_wmops(); return error; diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index e412b00ae..dd5f0b88b 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -47,6 +47,20 @@ #include "ivas_prot_fx.h" #endif +int16_t dbgwrite2_txt( + const float *buffer, /* i : Write buffer */ + const int16_t count, /* i : Number of elements */ + const char *const filename ) +{ + FILE *fp = fopen( filename, "a" ); + for ( int i = 0; i < count; i++ ) + { + fprintf( fp, "%f\n", buffer[i] ); + } + fclose( fp ); + return 0; +} + /*-------------------------------------------------------------------* * ivas_core_dec() @@ -79,6 +93,9 @@ ivas_error ivas_core_dec( int16_t tmps, incr; float bwe_exc_extended[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; float voice_factors[CPE_CHANNELS][NB_SUBFR16k]; +#ifdef IVAS_FLOAT_FIXED + Word16 voice_factors_fx[CPE_CHANNELS][NB_SUBFR16k]; +#endif int16_t core_switching_flag[CPE_CHANNELS]; float old_syn_12k8_16k[CPE_CHANNELS][L_FRAME16k]; float tmp; @@ -106,6 +123,13 @@ ivas_error ivas_core_dec( int16_t nchan_out; float *save_hb_synth; ivas_error error; + Word16 tmp1, tmp2; + Word32 L_tmp; + +#ifdef IVAS_FLOAT_FIXED + Word16 hb_synth_fx[6][L_FRAME48k]; /*not sure about number of channels so kept it as 6 will change it later*/ + Word32 hb_synth_32[6][L_FRAME48k]; +#endif error = IVAS_ERR_OK; push_wmops( "ivas_core_dec" ); @@ -114,11 +138,55 @@ ivas_error ivas_core_dec( * General initialization *-----------------------------------------------------------------*/ +#ifndef TO_BE_REMOVED_CONVERSION + Word16 k; + + if ( hSCE != NULL ) + { + sts = hSCE->hCoreCoder; + } + else + { + sts = hCPE->hCoreCoder; + } + + //core_coding_part will go in this loop, once the things are done + for ( k = 0; k < n_channels; k++ ) + { + if ( sts[k]->hTcxDec != NULL ) + { + floatToFixed_arr( sts[k]->hHQ_core->old_out, sts[k]->hHQ_core->old_out_fx, 0, L_FRAME48k ); + floatToFixed_arr( sts[k]->hHQ_core->old_outLB, sts[k]->hHQ_core->old_out_LB_fx, 0, L_FRAME32k ); + floatToFixed_arrL( sts[k]->hHQ_core->old_outLB, sts[k]->hHQ_core->old_outLB_fx, 11, L_FRAME32k ); + sts[k]->hTcxDec->conceal_eof_gain32 = floatToFixed( sts[k]->hTcxDec->conceal_eof_gain_float, 15 ); + f2me_16( sts[k]->last_concealed_gain_syn_deemph_float, &sts[k]->last_concealed_gain_syn_deemph, &sts[k]->last_concealed_gain_syn_deemph_e ); + } + } + + if ( hCPE != NULL && hCPE->last_element_mode == IVAS_CPE_MDCT && hCPE->element_mode == IVAS_CPE_DFT ) + { + floatToFixed_arrL( hCPE->input_mem_LB[0], hCPE->input_mem_LB_fx[0], 11, STEREO_DFT32MS_OVL_16k ); + // fixedToFloat_arrL(hCPE->old_outLB_mdct_fx, hCPE->old_outLB_mdct, 11, STEREO_MDCT2DFT_FADE_LEN_48k); + } + + IF( sts[0]->element_mode == IVAS_CPE_MDCT && sts[0]->total_brate == SID_2k40 ) + { + FOR( Word16 ch = 0; ch < CPE_CHANNELS; ++ch ) + { + f2me_buf( sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst_flt, sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst, &sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEstExp, sts[ch]->hFdCngDec->hFdCngCom->npart ); + f2me_buf( sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevel_flt, sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevel, &sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, sts[ch]->hFdCngDec->hFdCngCom->stopBand - sts[ch]->hFdCngDec->hFdCngCom->startBand ); + hCPE->hCoreCoder[ch]->preemph_fac = float_to_fix16( hCPE->hCoreCoder[ch]->preemph_fac_float, Q15 ); + floatToFixed_arr( sts[ch]->hFdCngDec->hFdCngCom->A_cng_flt, sts[ch]->hFdCngDec->hFdCngCom->A_cng, Q14, M + 1 ); + } + } + +#endif + use_cldfb_for_dft = 0; tdm_LRTD_flag = -1; read_sid_info = 1; /* read SID by default */ - if ( hSCE != NULL ) + IF( hSCE != NULL ) { sts = hSCE->hCoreCoder; hStereoICBWE = NULL; @@ -128,15 +196,15 @@ ivas_error ivas_core_dec( hStereoTD = NULL; p_output_mem = NULL; nchan_out = 1; - if ( st_ivas != NULL && st_ivas->ivas_format == ISM_FORMAT ) + IF( st_ivas != NULL && st_ivas->ivas_format == ISM_FORMAT ) { - if ( st_ivas->hISMDTX.sce_id_dtx != hSCE->sce_id ) + IF( st_ivas->hISMDTX.sce_id_dtx != hSCE->sce_id ) { read_sid_info = 0; } } } - else + ELSE { sts = hCPE->hCoreCoder; element_brate = hCPE->element_brate; @@ -147,21 +215,22 @@ ivas_error ivas_core_dec( p_output_mem = hCPE->output_mem[1]; nchan_out = hCPE->nchan_out; - if ( hCPE->hStereoTD != NULL ) + IF( hCPE->hStereoTD != NULL ) { tdm_LRTD_flag = hCPE->hCoreCoder[0]->tdm_LRTD_flag; } - if ( sts[0]->element_mode == IVAS_CPE_DFT ) + IF( sts[0]->element_mode == IVAS_CPE_DFT ) { use_cldfb_for_dft = ( hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) ? 1 : 0; } } output_Fs = sts[0]->output_Fs; - output_frame = (int16_t) ( output_Fs / FRAMES_PER_SEC ); + // output_frame = (int16_t) ( output_Fs / FRAMES_PER_SEC ); + output_frame = extract_l( Mpy_32_16_1( output_Fs, INV_FRAME_PER_SEC_Q15 ) ); - for ( n = 0; n < n_channels; n++ ) + FOR( n = 0; n < n_channels; n++ ) { st = sts[n]; @@ -185,14 +254,14 @@ ivas_error ivas_core_dec( st->rf_flag = 0; st->rf_frame_type = RF_NO_DATA; - if ( st->bfi == 1 ) + IF( st->bfi == 1 ) { frameMode[n] = FRAMEMODE_MISSING; st->coder_type = st->last_coder_type; } - else + ELSE { - if ( !( st->element_mode == IVAS_CPE_TD && n == 1 ) ) /* coder_type for SCh in TD stereo is already read in tdm_configure_dec() */ + IF( !( st->element_mode == IVAS_CPE_TD && n == 1 ) ) /* coder_type for SCh in TD stereo is already read in tdm_configure_dec() */ { st->coder_type = INACTIVE; } @@ -200,20 +269,45 @@ ivas_error ivas_core_dec( st->flagGuidedAcelp = 0; } - if ( !st->bfi && st->prev_bfi && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) && st->hTcxDec != NULL ) + IF( !st->bfi && st->prev_bfi && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) && st->hTcxDec != NULL ) { +#ifdef IVAS_FLOAT_FIXED + + FOR( i = 0; i < st->hTcxDec->L_frameTCX; i++ ) + { + L_tmp = Mpy_32_16_1( st->hTcxDec->conceal_eof_gain32, st->hHQ_core->old_out_fx[i] ); + L_tmp = Mpy_32_16_1( L_tmp, st->last_concealed_gain_syn_deemph ); + L_tmp = L_shl( L_tmp, st->last_concealed_gain_syn_deemph_e ); + st->hHQ_core->old_out_fx[i] = extract_l( L_tmp ); // Q0 + } + + FOR( i = 0; i < st->L_frame; i++ ) + { + L_tmp = Mpy_32_16_1( st->hTcxDec->conceal_eof_gain32, st->hHQ_core->old_out_LB_fx[i] ); + L_tmp = Mpy_32_16_1( L_tmp, st->last_concealed_gain_syn_deemph ); + L_tmp = L_shl( L_tmp, st->last_concealed_gain_syn_deemph_e ); + st->hHQ_core->old_out_LB_fx[i] = extract_l( L_tmp ); // Q0 + } + Copy_Scale_sig_16_32( st->hHQ_core->old_out_LB_fx, st->hHQ_core->old_outLB_fx, st->L_frame, 11 ); +#else 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 ); +#endif } +#ifdef IVAS_FLOAT_FIXED + set16_fx( voice_factors_fx[n], 0, NB_SUBFR16k ); + set16_fx( hb_synth_fx[n], 0, L_FRAME48k ); +#else set_f( voice_factors[n], 0.f, NB_SUBFR16k ); set_f( hb_synth[n], 0.0f, L_FRAME48k ); +#endif /*------------------------------------------------------------------* * Decision matrix (selection of technologies) *-----------------------------------------------------------------*/ - if ( st->bfi != 1 ) + IF( st->bfi != 1 ) { #ifdef IVAS_FLOAT_FIXED ivas_decision_matrix_dec_fx( st, &sharpFlag[n], &core_switching_flag[n], element_brate, nchan_out ); @@ -226,55 +320,64 @@ ivas_error ivas_core_dec( synchonize_channels_mdct_sid( sts, n ); #endif - if ( st->bfi != 1 ) /* note: st->bfi can be changed from 0 to 1 in ivas_decision_matrix_dec() when BER is detected */ + IF( st->bfi != 1 ) /* note: st->bfi can be changed from 0 to 1 in ivas_decision_matrix_dec() when BER is detected */ { st->sr_core = st->L_frame * FRAMES_PER_SEC; st->fscale_old = st->fscale; st->fscale = sr2fscale( st->sr_core ); } - else + ELSE { frameMode[n] = FRAMEMODE_MISSING; } } - else if ( st->element_mode >= IVAS_SCE && st->prev_bfi == 1 && st->last_con_tcx == 1 ) + ELSE IF( st->element_mode >= IVAS_SCE && st->prev_bfi == 1 && st->last_con_tcx == 1 ) { st->core = TCX_20_CORE; } } /* n_channels loop */ /* MDCT stereo -> DFT stereo switching */ - if ( hCPE != NULL && hCPE->last_element_mode == IVAS_CPE_MDCT && hCPE->element_mode == IVAS_CPE_DFT ) + IF( hCPE != NULL && hCPE->last_element_mode == IVAS_CPE_MDCT && hCPE->element_mode == IVAS_CPE_DFT ) { - int16_t ovl, fade_len; - if ( sts[0]->L_frame != sts[0]->last_L_frame ) + Word16 ovl, fade_len; + IF( 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 ); +#ifdef IVAS_FLOAT_FIXED L_lerp_fx_q11( sts[0]->hHQ_core->old_outLB_fx, sts[0]->hHQ_core->old_outLB_fx, sts[0]->L_frame, sts[0]->last_L_frame ); + Copy_Scale_sig_32_16( sts[0]->hHQ_core->old_outLB_fx, sts[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, -11 ); +#else + lerp_flt( sts[0]->hHQ_core->old_outLB, sts[0]->hHQ_core->old_outLB, sts[0]->L_frame, sts[0]->last_L_frame ); +#endif } - if ( sts[0]->L_frame != L_FRAME16k ) + IF( sts[0]->L_frame != L_FRAME16k ) { - ovl = (int16_t) ( STEREO_DFT32MS_OVL_16k * ( (float) sts[0]->L_frame / L_FRAME16k ) ); - lerp_flt( hCPE->input_mem_LB[0], hCPE->input_mem_LB[0], ovl, STEREO_DFT32MS_OVL_16k ); + ovl = mult( sts[0]->L_frame, 5120 ); /*STEREO_DFT32MS_OVL_16k/L_FRAME16k = 5/32 = 5120 (Q15)*/ +#ifdef IVAS_FLOAT_FIXED L_lerp_fx_q11( hCPE->input_mem_LB_fx[0], hCPE->input_mem_LB_fx[0], ovl, STEREO_DFT32MS_OVL_16k ); +#else + lerp_flt( hCPE->input_mem_LB[0], hCPE->input_mem_LB[0], ovl, STEREO_DFT32MS_OVL_16k ); +#endif - - fade_len = (int16_t) ( STEREO_MDCT2DFT_FADE_LEN_48k * ( (float) sts[0]->L_frame / L_FRAME16k ) ); - lerp_flt( hCPE->old_outLB_mdct, hCPE->old_outLB_mdct, fade_len, STEREO_MDCT2DFT_FADE_LEN_48k ); + fade_len = mult( sts[0]->L_frame, 12288 ); /* STEREO_MDCT2DFT_FADE_LEN_48k/L_FRAME16k = 3/8 = 12288 (Q15)*/ +#ifdef IVAS_FLOAT_FIXED L_lerp_fx_q11( hCPE->old_outLB_mdct_fx, hCPE->old_outLB_mdct_fx, fade_len, STEREO_MDCT2DFT_FADE_LEN_48k ); +#else + lerp_flt( hCPE->old_outLB_mdct, hCPE->old_outLB_mdct, fade_len, STEREO_MDCT2DFT_FADE_LEN_48k ); +#endif } } - if ( hCPE != NULL && hCPE->hStereoCng != NULL ) + IF( hCPE != NULL && hCPE->hStereoCng != NULL ) { hCPE->hStereoCng->flag_cna_fade = 0; } - if ( sba_dirac_stereo_flag && hSCE && sts[0]->total_brate <= SID_2k40 && sts[0]->cng_type == FD_CNG ) + IF( sba_dirac_stereo_flag && hSCE && sts[0]->total_brate <= SID_2k40 && sts[0]->cng_type == FD_CNG ) { save_hb_synth = hSCE->save_hb_synth; } - else + ELSE { save_hb_synth = NULL; } @@ -283,16 +386,10 @@ ivas_error ivas_core_dec( * Decode SID for MDCT-Stereo DTX mode *-----------------------------------------------------------------*/ - if ( sts[0]->element_mode == IVAS_CPE_MDCT && sts[0]->total_brate == SID_2k40 ) + IF( sts[0]->element_mode == IVAS_CPE_MDCT && sts[0]->total_brate == SID_2k40 ) { #ifdef IVAS_FLOAT_FIXED - FOR( Word16 ch = 0; ch < CPE_CHANNELS; ++ch ) - { - f2me_buf( sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst_flt, sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst, &sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEstExp, sts[ch]->hFdCngDec->hFdCngCom->npart ); - f2me_buf( sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevel_flt, sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevel, &sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, sts[ch]->hFdCngDec->hFdCngCom->stopBand - sts[ch]->hFdCngDec->hFdCngCom->startBand ); - hCPE->hCoreCoder[ch]->preemph_fac = float_to_fix16( hCPE->hCoreCoder[ch]->preemph_fac_float, Q15 ); - floatToFixed_arr( sts[ch]->hFdCngDec->hFdCngCom->A_cng_flt, sts[ch]->hFdCngDec->hFdCngCom->A_cng, Q14, M + 1 ); - } + IF( sts[0]->cng_sba_flag ) { @@ -302,13 +399,6 @@ ivas_error ivas_core_dec( { FdCngDecodeMDCTStereoSID_fx( hCPE ); } - - FOR( Word16 ch = 0; ch < CPE_CHANNELS; ++ch ) - { - me2f_buf( sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst, sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEstExp, sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst_flt, sts[ch]->hFdCngDec->hFdCngCom->npart ); - me2f_buf( sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevel, sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevel_flt, sts[ch]->hFdCngDec->hFdCngCom->stopBand - sts[ch]->hFdCngDec->hFdCngCom->startBand ); - fixedToFloat_arr( sts[ch]->hFdCngDec->hFdCngCom->A_cng, sts[ch]->hFdCngDec->hFdCngCom->A_cng_flt, Q14, M + 1 ); - } #else if ( sts[0]->cng_sba_flag ) { @@ -325,11 +415,41 @@ ivas_error ivas_core_dec( * Sanity check in combined format coding *-----------------------------------------------------------------*/ - if ( hCPE != NULL && hCPE->element_mode == IVAS_CPE_DFT && hCPE->brate_surplus > 0 ) + IF( hCPE != NULL && hCPE->element_mode == IVAS_CPE_DFT && hCPE->brate_surplus > 0 ) { ivas_combined_format_brate_sanity( hCPE->element_brate, sts[0]->core, sts[0]->total_brate, &( sts[0]->core_brate ), &( sts[0]->inactive_coder_type_flag ), &tmps ); } +#ifndef TO_BE_REMOVED_CONVERSION + if ( hCPE != NULL && hCPE->last_element_mode == IVAS_CPE_MDCT && hCPE->element_mode == IVAS_CPE_DFT ) + { + fixedToFloat_arrL( hCPE->input_mem_LB_fx[0], hCPE->input_mem_LB[0], 11, STEREO_DFT32MS_OVL_16k ); + fixedToFloat_arrL( hCPE->old_outLB_mdct_fx, hCPE->old_outLB_mdct, 11, STEREO_MDCT2DFT_FADE_LEN_48k ); + } + // n_channels loop + // sts is initialized here + for ( k = 0; k < n_channels; k++ ) + { + if ( sts[k]->hTcxDec != NULL ) + { + fixedToFloat_arr( sts[k]->hHQ_core->old_out_fx, sts[k]->hHQ_core->old_out, 0, L_FRAME48k ); + fixedToFloat_arr( sts[k]->hHQ_core->old_out_LB_fx, sts[k]->hHQ_core->old_outLB, 0, L_FRAME32k ); + } + fixedToFloat_arr( voice_factors_fx[k], voice_factors[k], 15, NB_SUBFR16k ); + fixedToFloat_arr( hb_synth_fx[k], hb_synth[k], 0, L_FRAME48k ); // 0 is assumed as original values are set to 0 + } + IF( sts[0]->element_mode == IVAS_CPE_MDCT && sts[0]->total_brate == SID_2k40 ) + { + FOR( Word16 ch = 0; ch < CPE_CHANNELS; ++ch ) + { + me2f_buf( sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst, sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEstExp, sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst_flt, sts[ch]->hFdCngDec->hFdCngCom->npart ); + me2f_buf( sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevel, sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevel_flt, sts[ch]->hFdCngDec->hFdCngCom->stopBand - sts[ch]->hFdCngDec->hFdCngCom->startBand ); + fixedToFloat_arr( sts[ch]->hFdCngDec->hFdCngCom->A_cng, sts[ch]->hFdCngDec->hFdCngCom->A_cng_flt, Q14, M + 1 ); + } + } + +#endif + /*------------------------------------------------------------------* * Core Decoding *-----------------------------------------------------------------*/ diff --git a/lib_dec/lsf_dec.c b/lib_dec/lsf_dec.c index cea3d80a6..a5b791a27 100644 --- a/lib_dec/lsf_dec.c +++ b/lib_dec/lsf_dec.c @@ -39,6 +39,7 @@ #include "cnst.h" #include "rom_com.h" #include "prot.h" +#include "prot_fx2.h" #include "basop_proto_func.h" #include "ivas_prot.h" #include "ivas_rom_com.h" @@ -514,7 +515,24 @@ void lsf_end_dec( /* TD stereo SCh: perform intra-frame prediction with pulling-to-mean */ if ( st->tdm_LRTD_flag == 0 && st->idchan == 1 && tdm_lsfQ_PCh != NULL ) { +#ifdef IVAS_FLOAT_FIXED + Word16 tdm_lsfQ_PCh_fx[M]; + Word16 pred3_fx[M]; + for (int i = 0; i < M; i++) + { + tdm_lsfQ_PCh_fx[i] = (tdm_lsfQ_PCh[i]) * 2.56; + pred3_fx[i] = (pred3[i]) * 2.56; + } + + tdm_SCh_LSF_intra_pred_fx(st->element_brate, tdm_lsfQ_PCh_fx, pred3_fx); + + for (int i = 0; i < M; i++) + { + pred3[i] = (pred3_fx[i]) / 2.56; + } +#else tdm_SCh_LSF_intra_pred( st->element_brate, tdm_lsfQ_PCh, pred3 ); +#endif } if ( safety_net ) diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index d1c1acd7f..5d8f83466 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -671,6 +671,9 @@ typedef struct tcx_dec_structure float conceal_eof_gain_float; Word16 conceal_eof_gain; /*Q14*/ +#ifdef IVAS_FLOAT_FIXED + Word32 conceal_eof_gain32; /*have been created for further calculation */ +#endif float damping_float; Word16 damping; /* 1Q14 */ diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index 4cda9e89e..258add9ae 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -43,6 +43,7 @@ #include "prot.h" #include "ivas_cnst.h" #include "ivas_prot.h" +#include "prot_fx2.h" #include "ivas_rom_com.h" #include "wmc_auto.h" @@ -69,7 +70,7 @@ ivas_error acelp_core_enc( float pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */ int16_t *unbits, /* o : number of unused bits */ STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ - const float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ + float tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ ) { int16_t i, nBits; /* reserved bits */ @@ -416,9 +417,30 @@ ivas_error acelp_core_enc( lsp2lsf( lsp_new, lsf_new, M, 12800 ); Unified_weighting( &st->Bin_E[L_FFT / 2], lsf_new, lsf_wgts, st->bwidth == NB, st->coder_type == UNVOICED, st->sr_core, M ); +#ifdef IVAS_FLOAT_FIXED + Word16 lsf_new_fx[M]; + Word16 lsp_new_fx[M]; + Word16 tdm_lsfQ_PCh_fx[M]; + Word16 lsf_wgts_fx[M]; + for (int i = 0; i < M; i++) + { + lsf_new_fx[i] = (lsf_new[i]) * 2.56; + tdm_lsfQ_PCh_fx[i] = (tdm_lsfQ_PCh[i]) * 2.56; + lsf_wgts_fx[i] = (lsf_wgts[i]) * 2.56; + } + floatToFixed_arr(lsp_new, lsp_new_fx, 15, M); - tdm_SCh_lsf_reuse( ENC, st->element_brate, lsf_new, lsp_new, tdm_lsfQ_PCh, lsf_wgts, &beta_index ); + tdm_SCh_lsf_reuse_fx(ENC, st->element_brate, lsf_new_fx, lsp_new_fx, tdm_lsfQ_PCh_fx, lsf_wgts_fx, &beta_index); + for (int i = 0; i < M; i++) + { + lsf_new[i] = (lsf_new_fx[i]) / 2.56; + lsf_wgts[i] = (lsf_wgts_fx[i]) / 2.56; + } + fixedToFloat_arr(lsp_new_fx, lsp_new, 15, M); +#else + tdm_SCh_lsf_reuse( ENC, st->element_brate, lsf_new, lsp_new, tdm_lsfQ_PCh, lsf_wgts, &beta_index ); +#endif push_indice( hBstr, IND_IC_LSF_PRED, beta_index, TDM_IC_LSF_PRED_BITS ); } diff --git a/lib_enc/lsf_enc.c b/lib_enc/lsf_enc.c index 7ba256905..128e7fb3e 100644 --- a/lib_enc/lsf_enc.c +++ b/lib_enc/lsf_enc.c @@ -40,6 +40,7 @@ #include "rom_enc.h" #include "rom_com.h" #include "prot.h" +#include "prot_fx2.h" #include "basop_proto_func.h" #include "ivas_prot.h" #include "ivas_rom_com.h" @@ -553,8 +554,24 @@ void lsf_end_enc( { /* if secondary channel predmode is set to be > 2 */ predmode += 3; +#ifdef IVAS_FLOAT_FIXED + Word16 tdm_lsfQ_PCh_fx[M]; + Word16 pred3_fx[M]; + for (int i = 0; i < M; i++) + { + tdm_lsfQ_PCh_fx[i] = (tdm_lsfQ_PCh[i]) * 2.56; + pred3_fx[i] = (pred3[i]) * 2.56; + } + + tdm_SCh_LSF_intra_pred_fx(st->element_brate, tdm_lsfQ_PCh_fx, pred3_fx); + for (int i = 0; i < M; i++) + { + pred3[i] = (pred3_fx[i]) / 2.56; + } +#else tdm_SCh_LSF_intra_pred( st->element_brate, tdm_lsfQ_PCh, pred3 ); +#endif } if ( predmode == 0 ) /* Safety-net only */ -- GitLab