diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 92e765d697a6dc5083975d49371aba5be405f172..bd43fdb84abf1d299cbd7d86625b10de5417be0d 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -636,8 +636,8 @@ typedef enum #define SBA_DIRAC_NRG_SMOOTH_LONG 10 #define SBA_DIRAC_NRG_SMOOTH_SHORT 3 -#define SBA_DIRAC_NRG_SMOOTH_SHORT_BY_LONG_FX ((Word16)0x2666) -#define SBA_DIRAC_NRG_SMOOTH_LONG_BY_LONG_SHORT_FX ((Word32)0x0000B6D8) +#define SBA_DIRAC_NRG_SMOOTH_SHORT_BY_LONG_FX ((Word16)0x2667) +#define SBA_DIRAC_NRG_SMOOTH_LONG_BY_LONG_SHORT_FX ((Word32)0x5B6DB6DB) /* PLC for DFT Stereo residual */ #define STEREO_DFT_RES_N_PEAKS_MAX 15 /*Maximum number of peaks within residual signal in each frame (res_cod_band_max == 6 in 48kHz)*/ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index fd8692341c714a84d02be1a165f1b25ae0e0566e..9e27b3612a4bc2590adb754ae27469a1b330a9cc 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -475,7 +475,8 @@ void filter_with_allpass_fx( const Word32 *sig, /* i : allpass input signal */ Word32 *out, /* o : filtered output */ const int16_t len, /* i : length of input */ - basic_allpass_t *ap /* i/o: basic allpass structure */ + basic_allpass_t *ap, /* i/o: basic allpass structure */ + Word16 q_shift ); Word32 stereo_dft_dmx_swb_nrg_fx( @@ -1524,7 +1525,7 @@ void ivas_hq_pred_hb_bws_fx( ); void synchro_synthesis_fixed_clean( - const Word16 ivas_total_brate, /* i : IVAS total bitrate */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 *output_fx[CPE_CHANNELS], /* i/o: output synthesis signal */ const Word16 output_frame, /* i : Number of samples */ diff --git a/lib_com/lerp.c b/lib_com/lerp.c index a9abd3401dfd2f87065384c148c7df68cd0be0ab..453c686630a33388e7e77d4863e84cd181a705a1 100644 --- a/lib_com/lerp.c +++ b/lib_com/lerp.c @@ -383,6 +383,102 @@ static void lerp_proc(Word16 *f, Word16 *f_out, Word16 bufferNewSize, Word16 buf } + +static void lerp_proc32(Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 bufferOldSize) +{ + + Word16 i, idx, n; + Word16 diff; + Word32 pos, shift; + Word32 buf[2 * L_FRAME_MAX]; + Word32 *ptr; + + ptr = f_out; + test(); + test(); + test(); + IF (((f <= f_out) && (f + bufferOldSize >= f_out)) || ((f_out <= f) && (f_out + bufferNewSize >= f))) + { + ptr = buf; + move16(); + } + + IF(EQ_16(bufferNewSize, bufferOldSize)) + { + Copy32(f, f_out, bufferNewSize); + return; + } + + shift = L_shl(L_deposit_l(div_s(bufferOldSize, shl(bufferNewSize, 4))), 4 - shift_e + 16); + + pos = L_sub(L_shr(shift, 1), 32768l/*1.0f Q15*/); + + /* Adjust interpolation shift to avoid accessing beyond end of input buffer. */ + if (LT_32(shift, 19661l/*0.3f Q16*/)) + { + pos = L_sub(pos, 8520l/*0.13f Q16*/); + } + + assert(pos_e == shift_e); + + /* first point of interpolation */ + IF(pos < 0) + { + + diff = shr(extract_l(pos), 1); + /*buf[0]=f[0]+pos*(f[1]-f[0]);*/ + move16(); + *ptr++ = L_add_sat(f[0], Mpy_32_16_1(L_sub(f[1], f[0]), diff)); + } + ELSE + { + + idx = extract_h(pos); + diff = lshr(extract_l(pos), 1); + move16(); + *ptr++ = L_add_sat(f[idx], Mpy_32_16_1(L_sub(f[idx + 1], f[idx]), diff)); + } + + pos = L_add(pos, shift); + idx = s_max(0, extract_h(pos)); + + n = sub(bufferNewSize, 1); + FOR(i = 1; i < n; i++) + { + diff = lshr(extract_l(pos), 1); + IF (LT_32(pos , 0)) + { + diff = sub(16384/*0.5f Q15*/, diff); + } + move16(); + *ptr++ = L_add_sat(f[idx], Mpy_32_16_1(L_sub(f[idx + 1], f[idx]), diff)); + pos = L_add(pos, shift); + idx = extract_h(pos); + } + + /* last point */ + + IF (GT_32(pos, L_deposit_h(sub(bufferOldSize, 1)))) + { + idx = sub(bufferOldSize, 2); + } + assert(idx <= 2 * L_FRAME_MAX); + + /* diff = t - point;*/ + diff = lshr(extract_l(L_shr(L_sub(pos, L_deposit_h(idx)), 1)), 1); + + move16(); + *ptr++ = L_add_sat(f[idx], L_shl_sat(Mpy_32_16_1(L_sub(f[idx + 1], f[idx]), diff), 1)); + test(); + test(); + test(); + IF(((f <= f_out) && (f + bufferOldSize >= f_out)) || ((f_out <= f) && (f_out + bufferNewSize >= f))) + { + Copy32(buf, f_out, bufferNewSize); + } + +} + #ifdef IVAS_FLOAT_FIXED static void L_lerp_proc_fx( const Word32 *f_fx, Word32 *f_out_fx, const Word16 bufferNewSize, const Word16 bufferOldSize ); @@ -397,10 +493,12 @@ void L_lerp_fx( Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 bufferOld { Word16 tmpNewSize; Word16 guard_bits = s_max(find_guarded_bits_fx(bufferNewSize / bufferOldSize), find_guarded_bits_fx(bufferOldSize / bufferNewSize)) + 1; - q -= guard_bits; - - FOR(Word16 ind = 0; ind < bufferNewSize; ind++) f[ind] = L_shr(f[ind], guard_bits); - FOR(Word16 ind = 0; ind < bufferNewSize; ind++) f_out[ind] = L_shr(f_out[ind], guard_bits); + IF (getScaleFactor32(f, bufferOldSize) < guard_bits) + { + *q -= guard_bits; + FOR(Word16 ind = 0; ind < bufferNewSize; ind++) f[ind] = L_shr(f[ind], guard_bits); + FOR(Word16 ind = 0; ind < bufferNewSize; ind++) f_out[ind] = L_shr(f_out[ind], guard_bits); + } IF ( 128 * bufferNewSize > bufferOldSize * 507 ) { @@ -457,7 +555,7 @@ void L_lerp_fx_q11( Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 buffe tmpNewSize = bufferNewSize; } - L_lerp_proc_fx( f, f_out, tmpNewSize, bufferOldSize ); + lerp_proc32( f, f_out, tmpNewSize, bufferOldSize ); f = f_out; bufferOldSize = tmpNewSize; @@ -474,7 +572,7 @@ void L_lerp_fx_q11( Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 buffe tmpNewSize = bufferNewSize; } - L_lerp_proc_fx( f, f_out, tmpNewSize, bufferOldSize ); + lerp_proc32( f, f_out, tmpNewSize, bufferOldSize ); f = f_out; bufferOldSize = tmpNewSize; @@ -483,7 +581,7 @@ void L_lerp_fx_q11( Word32 *f, Word32 *f_out, Word16 bufferNewSize, Word16 buffe } ELSE { - L_lerp_proc_fx( f, f_out, bufferNewSize, bufferOldSize ); + lerp_proc32(f, f_out, bufferNewSize, bufferOldSize); } return; diff --git a/lib_com/prot.h b/lib_com/prot.h index dbad1b746986655850da8ffcec07fd3fc902b2f0..6f30a3b8ca0321c9cbf6ded1d717554166a82618 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -500,6 +500,14 @@ void delay_signal_fx( Word32 mem[], /* i/o: synchronization memory */ const int16_t delay /* i : delay in samples */ ); +void delay_signal_q_adj_fx( + Word32 x[], /* i/o: signal to be delayed */ + const int16_t len, /* i : length of the input signal */ + Word32 mem[], /* i/o: synchronization memory */ + const int16_t delay, /* i : delay in samples */ + const Word16 q_x, + const Word16 q_mem +); #endif ivas_error push_indice( diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h index f8167bd317bd60d4a75da44786ed02b273c5bf41..51e625fb70b7fa81e0e5a08fab500ef7b881289e 100644 --- a/lib_com/prot_fx2.h +++ b/lib_com/prot_fx2.h @@ -2400,7 +2400,7 @@ void calc_normal_length_fx( Word16 Q_syn ); -Word32 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ +Word16 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ const Word32 *sp, /* i : i signal */ const Word16 exp_sp, /* i : Exp of inp signal */ const Word16 N /* i : signal length */ diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index 808dbfef79f044e1d89bf959aefe55f25ecbd71e..0f10a3afdc8e05229caf26cd8622259d545564a9 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -717,7 +717,7 @@ Word32 calc_tilt_bwe_fx( /* o : Tilt in Q24 */ return L_temp; } #ifdef IVAS_FLOAT_FIXED -Word32 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ +Word16 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ const Word32 *sp, /* i : input signal */ const Word16 exp_sp, /* i : Exp of inp signal */ const Word16 N /* i : signal length */ @@ -726,6 +726,7 @@ Word32 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ Word16 i, j; Word32 L_ener, L_ener_tot, L_temp; Word32 tmp1, tmp2; + Word16 sign = 0; const Word32 *ptr; Word16 exp2, tmp_exp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL @@ -747,61 +748,33 @@ Word32 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ /* Divide Frame Length by 32 */ FOR(j = shr(N, 5); j > 0; j--) { -#ifdef BASOP_NOGLOB /* Critical Overflow and all those below*/ - Word16 tmp = mult_ro( (Word16) *ptr++, 8192, &Overflow ); /* Divide by 4 */ -#else - tmp1 = mult_r(*ptr++, 8192); /* Divide by 4 */ -#endif - L_ener = L_mult0( tmp, tmp ); + Word32 tmp = *ptr++; /* Divide by 4 */ + L_ener = Mpy_32_32( tmp, tmp ); /* With the shift by 4 and the L_mult0, no overflow possible for 32 samples */ FOR(i = 1; i < 32; i++) { - tmp1 = L_mls_o(*ptr++, 8192, &Overflow); /* Divide by 4 */ + tmp1 = *ptr++; /* Divide by 4 */ L_ener = Madd_32_32(L_ener, tmp1, tmp1); } -#ifdef BASOP_NOGLOB /* Critical Overflow */ - L_ener = L_shr_o(L_ener, exp2, &Overflow); - L_temp = L_add_o(L_ener_tot, L_ener, &Overflow); -#else - L_ener = L_shr(L_ener, exp2); L_temp = L_add(L_ener_tot, L_ener); -#endif - IF(Overflow != 0) - { - L_ener_tot = L_shr(L_ener_tot, 1); - L_ener = L_shr(L_ener, 1); - exp2 = add(exp2, 1); - /* this is required, do not remove */ - Overflow = 0; - move16(); - } -#ifdef BASOP_NOGLOB /* Critical Overflow */ - L_ener_tot = L_add_o(L_ener_tot, L_ener, &Overflow); -#else + L_ener_tot = L_add(L_ener_tot, L_ener); -#endif } -#ifdef BASOP_NOGLOB - L_ener = (L_abs(L_sub_o(sp[1], sp[0], &Overflow))); -#else - L_ener = L_deposit_l(abs_s(sub(sp[1], sp[0]))); -#endif + L_ener = L_abs(L_sub(sp[1], sp[0])); + FOR(i = 2; i < N; i++) { /* Eq to (sp[i] - sp[i-1]) * (sp[i-1] - sp[i-2]) < 0 */ -#ifdef BASOP_NOGLOB - tmp1 = L_sub_o(sp[i], sp[i - 1], &Overflow); - tmp2 = L_sub_o(sp[i - 1], sp[i - 2], &Overflow); -#else - tmp1 = sub(sp[i], sp[i - 1]); - tmp2 = sub(sp[i - 1], sp[i - 2]); -#endif - tmp2 = mult(tmp1, tmp2); - tmp1 = abs_s(tmp1); + tmp1 = L_sub(sp[i], sp[i - 1]); + tmp2 = L_sub(sp[i - 1], sp[i - 2]); + + tmp2 = Mpy_32_32(tmp1, tmp2); + tmp1 = L_abs(tmp1); /* to Get either 0 or -1 in 'tmp2' */ - tmp2 = shr(tmp2, 15); + tmp2 = L_shr(tmp2, 31); + sign = extract_l(L_shl(tmp2, Q15)); /* this allows this code */ - L_ener = L_msu0(L_ener, tmp2, tmp1); + L_ener = Msub_32_16(L_ener, tmp1, sign); /* instead of this one */ /* test(); */ /* if (tmp2 < 0) */ @@ -811,23 +784,24 @@ Word32 ivas_calc_tilt_bwe_fx( /* o : Tilt in Q24 */ /* it saves one op */ } - tmp_exp = norm_l(L_ener_tot); - L_temp = L_shl(L_ener_tot, tmp_exp); - tmp1 = sub(add(31 + 4, exp2), add(tmp_exp, shl(exp_sp, 1))); - L_temp = Isqrt_lc(L_temp, &tmp_exp); + L_temp = L_ener_tot; + tmp_exp = sub(Q31, sub(shl(exp_sp, 1), Q31)); + L_temp = Sqrt32(L_temp, &tmp_exp); + L_temp = L_shl(L_temp, sub(exp_sp, sub(Q31, tmp_exp))); /* *tilt_flt = (float)(r1/sqrt(r0)); */ - exp2 = norm_l(L_ener); - L_temp = Mult_32_16(L_temp, round_fx(L_shl(L_ener, exp2))); - exp2 = sub(exp2, tmp_exp); - exp2 = add(exp2, exp_sp); - - /* Put in Q24 */ - L_temp = L_shr(L_temp, sub(exp2, 24)); - + L_temp = L_deposit_l(BASOP_Util_Divide3232_Scale(L_ener, L_temp, &exp2)); + IF (GT_16(sub(exp2, 4) , norm_l(L_temp))) + { + L_temp = MAX_16; + } + ELSE + { + L_temp = L_shl(L_temp, sub(exp2, 4)); // Output is expected in Q11 + } BASOP_SATURATE_WARNING_ON_EVS - return L_temp; + return extract_l(L_temp); } #endif diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index 9aa17c37de3e5b97ffec51e24fec1a03842a776a..cfcfe43be847c8026c85e3b0736f39728e145860 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -3571,6 +3571,35 @@ void delay_signal_fx( return; } +void delay_signal_q_adj_fx( + Word32 x[], /* i/o: signal to be delayed */ + const int16_t len, /* i : length of the input signal */ + Word32 mem[], /* i/o: synchronization memory */ + const int16_t delay, /* i : delay in samples */ + const Word16 q_x, + const Word16 q_mem +) +{ + + Word32 tmp_buffer[L_FRAME48k]; + + Copy32( mem, tmp_buffer, delay ); + Copy32( x + len - delay, mem, delay ); + Copy32( x, x + delay, len - delay ); + + + IF (EQ_16(q_x, q_mem)) + { + Copy32( tmp_buffer, x, delay ); + } + ELSE + { + v_shr( tmp_buffer, sub(q_mem, q_x), x, delay ); + } + + return; +} + void v_add_fx( const Word32 x1[], /* i : Input vector 1 */ const Word32 x2[], /* i : Input vector 2 */ diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index d43aad4792a3b363d1e09e6574e64163bbfbcaad..edc91154f29e20a332636086b5a2fd0a8e193af9 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -1532,6 +1532,7 @@ ivas_error ivas_core_dec( { hCPE->hStereoDft->ap_delay_mem_fx[ind] = (Word32) ( hCPE->hStereoDft->ap_delay_mem[ind] * ( 1 << 11 ) ); } + hCPE->hStereoDft->q_ap_delay_mem_fx = 11; FOR( int ind = 0; ind < NS2SA( 16000, STEREO_DFT32MS_OVL_NS ); ind++ ) { hCPE->hStereoDft->buff_LBTCX_mem_fx[ind] = (Word32) ( hCPE->hStereoDft->buff_LBTCX_mem[ind] * ( 1 << 11 ) ); diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index 1d8b37bd2da74ea717a4720780cecd7b377a582b..b33b8453e00d8b344af43f63e77d5998bb34c630 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -732,7 +732,15 @@ ivas_error ivas_cpe_dec_fx( { hCPE->hStereoDft->q_dft = Q15; } + ELSE IF(hCPE->hStereoDft->q_dft < 0) + { + hCPE->hStereoDft->q_dft = 0; + } hCPE->hStereoDft->q_dft = s_min(hCPE->hStereoDft->q_dft, sts[0]->hFdCngDec->q_smoothed_psd); + IF (hCPE->hStereoDft->q_dft < 0) + { + hCPE->hStereoDft->q_dft = 0; + } IF (EQ_16(hCPE->hStereoDft->first_frame, 1)) { hCPE->hStereoDft->q_smoothed_nrg = hCPE->hStereoDft->q_dft; @@ -914,7 +922,161 @@ ivas_error ivas_cpe_dec_fx( IF( !st_ivas->sba_dirac_stereo_flag ) { + // Delete below + Word16 output_q = OUTPUT_Q; + FOR( Word32 n = 0; n < CPE_CHANNELS; n++ ) + { + IF( hCPE->hStereoDft != NULL ) + { + IF( hCPE->hStereoDft->hTcxLtpDec != NULL ) + { + FOR( Word32 p = 0; p < L_FRAME48k; p++ ) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] * ( 1u << output_q ) ); + } + FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << output_q ) ); + } + hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15 ); + hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain = (Word16) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); + } + } + IF( hCPE->hCoreCoder[n] != NULL ) + { + IF( hCPE->hCoreCoder[n]->hTcxLtpDec != NULL ) + { + FOR( Word32 p = 0; p < L_FRAME48k; p++ ) + { + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] * ( 1u << output_q ) ); + } + FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) + { + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << output_q ) ); + } + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15 ); + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain = (Word16) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); + } + + FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); k++ ) + { + hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[k] = (Word32) ( hCPE->hCoreCoder[n]->prev_synth_buffer[k] * ( 1 << output_q ) ); + } + FOR( Word32 k = 0; k < HQ_DELTA_MAX * HQ_DELAY_COMP; k++ ) + { + hCPE->hCoreCoder[n]->delay_buf_out32_fx[k] = (Word32) ( hCPE->hCoreCoder[n]->delay_buf_out[k] * ( 1 << output_q ) ); + } + IF( hCPE->hCoreCoder[n]->hTcxDec != NULL ) + { + FOR( Word32 k = 0; k < 111; k++ ) + { + hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] = (Word32) ( hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] * ( 1 << output_q ) ); + } + } + } + + IF( hCPE->output_mem[n] != NULL ) + { + FOR( Word32 k = 0; k < NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ); k++ ) + { + hCPE->output_mem_fx[n][k] = (Word32) ( hCPE->output_mem[n][k] * ( 1 << output_q ) ); + } + } + IF( hCPE->input_mem[n] != NULL ) + { + FOR( Word32 ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) + { + hCPE->input_mem_LB_fx[n][ind] = (Word32) ( hCPE->input_mem_LB[n][ind] * ( 1 << output_q ) ); + } + } + + FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) + { + hCPE->prev_hb_synth_fx[n][k] = (Word32) ( hCPE->prev_hb_synth[n][k] * ( 1 << output_q ) ); + } + FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) + { + hCPE->prev_synth_fx[n][k] = (Word32) ( hCPE->prev_synth[n][k] * ( 1 << output_q ) ); + } + } + //till here + synchro_synthesis_fixed_clean( ivas_total_brate, hCPE, output, output_frame, 0 ); + + // delete the below + IF( hCPE->hStereoDft != NULL ) + { + IF( hCPE->hStereoDft->hTcxLtpDec != NULL ) + { + FOR( Word32 p = 0; p < L_FRAME48k; p++ ) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << output_q ); + } + FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << output_q ); + } + hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; + hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; + } + } + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + IF( hCPE->output_mem[n] != NULL ) + { + FOR( Word32 k = 0; k < NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ); k++ ) + { + hCPE->output_mem[n][k] = (float) hCPE->output_mem_fx[n][k] / ( 1u << 11 ); + } + } + IF( hCPE->hCoreCoder[n] != NULL ) + { + IF( hCPE->hCoreCoder[n]->hTcxLtpDec != NULL ) + { + FOR( Word32 p = 0; p < L_FRAME48k; p++ ) + { + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << output_q ); + } + FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) + { + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << output_q ); + } + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; + } + FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); k++ ) + { + hCPE->hCoreCoder[n]->prev_synth_buffer[k] = (float) hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[k] / ( 1 << output_q ); + } + FOR( Word32 k = 0; k < HQ_DELTA_MAX * HQ_DELAY_COMP; k++ ) + { + hCPE->hCoreCoder[n]->delay_buf_out[k] = (float) hCPE->hCoreCoder[n]->delay_buf_out32_fx[k] / ( 1 << output_q ); + } + IF( hCPE->hCoreCoder[n]->hTcxDec != NULL ) + { + FOR( Word32 k = 0; k < 111; k++ ) + { + hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] = (float) hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] / ( 1 << output_q ); + } + } + } + IF( hCPE->input_mem[n] != NULL ) + { + FOR( Word32 ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) + { + hCPE->input_mem_LB[n][ind] = ( (float) hCPE->input_mem_LB_fx[n][ind] / ( 1 << output_q ) ); + } + } + FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) + { + hCPE->prev_hb_synth[n][k] = (float) hCPE->prev_hb_synth_fx[n][k] / ( 1 << output_q ); + } + FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) + { + hCPE->prev_synth[n][k] = (float) hCPE->prev_synth_fx[n][k] / ( 1 << output_q ); + } + } + // till here } IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->nchan_out, 1 ) && ( EQ_16( is_DTXrate( ivas_total_brate ), 0 ) || ( EQ_16( is_DTXrate( ivas_total_brate ), 1 ) && EQ_16( is_DTXrate( st_ivas->hDecoderConfig->last_ivas_total_brate ), 0 ) ) ) ) diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 868cd529c89378c1255575dc1cab712c3b543d26..14451534701684773febcdbda528115692583c18 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -812,10 +812,11 @@ ivas_error ivas_jbm_dec_tc( ivas_spar_dec_gen_umx_mat( st_ivas->hSpar->hMdDec, st_ivas->nchan_transport, IVAS_MAX_NUM_BANDS, st_ivas->bfi, ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, ivas_total_brate, st_ivas->last_active_ivas_total_brate ) ); } -#ifndef IVAS_FLOAT_FIXED_ +#ifndef IVAS_FLOAT_FIXED ivas_sba_dirac_stereo_dec( st_ivas, p_output, output_frame, st_ivas->ivas_format == MC_FORMAT ); #else { + Word16 q; float l_hb_nrg = 0.0, l_hb_nrg_subr = 0.0; static int frame_counter = 0; if ( frame_counter >= 200 ) @@ -842,23 +843,33 @@ ivas_error ivas_jbm_dec_tc( } } } - i_max_val_op = (int) max_val; - hCPE->hStereoDft->q_dft = norm_l( i_max_val_op ) - Q10; - st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->q_smoothed_psd = norm_l( i_max_val_psd ) - Q9; - IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) ) + i_max_val_op = (int)max_val; + hCPE->hStereoDft->q_dft = norm_l(i_max_val_op) - Q11; + IF(hCPE->hStereoDft->q_dft < 0) + { + hCPE->hStereoDft->q_dft = 0; + } + ELSE IF (hCPE->hStereoDft->q_dft > Q11) + { + hCPE->hStereoDft->q_dft = Q11; + } + st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->q_smoothed_psd = norm_l(i_max_val_psd) - Q9; + IF (EQ_16(hCPE->hStereoDft->first_frame, 1)) { - hCPE->hStereoDft->q_smoothed_nrg = hCPE->hStereoDft->q_dft; - hCPE->hStereoDft->first_frame = 0; + hCPE->q_prev_synth_fx = hCPE->hStereoDft->q_dft; + hCPE->hStereoDft->q_smoothed_nrg = Q6;//hCPE->hStereoDft->q_dft; + hCPE->hStereoDft->q_ap_delay_mem_fx = hCPE->hStereoDft->q_dft; } - st_ivas->hCPE[0]->hCoreCoder[0]->stab_fac_fx = (Word16) floatToFixed( st_ivas->hCPE[0]->hCoreCoder[0]->stab_fac, 15 ); - st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact_fx = (Word16) floatToFixed( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact, 15 ); - st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_act_fact_fx = (Word16) floatToFixed( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_act_fact, 15 ); - floatToFixed_arrL( &hCPE->hStereoDft->res_gains_ind[0][0], &hCPE->hStereoDft->res_gains_ind_fx[0][0], Q26, sizeof( hCPE->hStereoDft->res_gains_ind_fx ) / sizeof( hCPE->hStereoDft->res_gains_ind_fx[0][0] ) ); - floatToFixed_arrL( &hCPE->hStereoDft->res_pred_gain[0], &hCPE->hStereoDft->res_pred_gain_fx[0], Q31, sizeof( hCPE->hStereoDft->res_pred_gain_fx ) / sizeof( hCPE->hStereoDft->res_pred_gain_fx[0] ) ); - floatToFixed_arrL( &hCPE->hStereoDft->itd[0], &hCPE->hStereoDft->itd_fx[0], Q1, sizeof( hCPE->hStereoDft->itd_fx ) / sizeof( hCPE->hStereoDft->itd_fx[0] ) ); - floatToFixed_arrL( &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd_fx[0], st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->q_smoothed_psd, sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd_fx ) / sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd_fx[0] ) ); - for ( int ii = 0; ii < sizeof( hCPE->hStereoDft->hb_nrg_subr_fx ) / sizeof( hCPE->hStereoDft->hb_nrg_subr_fx[0] ); ii++ ) + st_ivas->hCPE[0]->hCoreCoder[0]->stab_fac_fx = (Word16)floatToFixed(st_ivas->hCPE[0]->hCoreCoder[0]->stab_fac, 15); + st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact_fx = (Word16)floatToFixed(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact, 15); + st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_act_fact_fx = (Word16)floatToFixed(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_act_fact, 15); + floatToFixed_arrL(&hCPE->hStereoDft->res_gains_ind[0][0], &hCPE->hStereoDft->res_gains_ind_fx[0][0], Q26, sizeof(hCPE->hStereoDft->res_gains_ind_fx) / sizeof(hCPE->hStereoDft->res_gains_ind_fx[0][0])); + floatToFixed_arrL(&hCPE->hStereoDft->res_pred_gain[0], &hCPE->hStereoDft->res_pred_gain_fx[0], Q31, sizeof(hCPE->hStereoDft->res_pred_gain_fx)/ sizeof(hCPE->hStereoDft->res_pred_gain_fx[0])); + floatToFixed_arrL(&hCPE->hStereoDft->itd[0], &hCPE->hStereoDft->itd_fx[0], Q1, sizeof(hCPE->hStereoDft->itd_fx) / sizeof(hCPE->hStereoDft->itd_fx[0])); + floatToFixed_arrL(&st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd_fx[0], st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->q_smoothed_psd, sizeof(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd_fx) / sizeof(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd_fx[0])); + floatToFixed_arrL(&hCPE->prev_hb_synth[0][0], &hCPE->prev_hb_synth_fx[0][0], hCPE->hStereoDft->q_dft, sizeof(hCPE->prev_hb_synth_fx) / sizeof(hCPE->prev_hb_synth_fx[0][0])); + for (int ii = 0; ii < sizeof(hCPE->hStereoDft->hb_nrg_subr_fx) / sizeof(hCPE->hStereoDft->hb_nrg_subr_fx[0]); ii++) { if ( l_hb_nrg_subr < hCPE->hStereoDft->hb_nrg_subr[ii] ) { @@ -890,7 +901,7 @@ ivas_error ivas_jbm_dec_tc( } for ( int ii = 0; ii < sizeof( hCPE->hStereoDft->hb_nrg_fx ) / sizeof( hCPE->hStereoDft->hb_nrg_fx[0] ); ii++ ) { - hCPE->hStereoDft->hb_nrg_fx[ii] = (Word32) ( hCPE->hStereoDft->hb_nrg[ii] / ( (float) ( 1 << hCPE->hStereoDft->q_hb_nrg ) ) ); + hCPE->hStereoDft->hb_nrg_fx[ii] = (Word32)(hCPE->hStereoDft->hb_nrg[ii] * ((float)(1 << hCPE->hStereoDft->q_hb_nrg))); } floatToFixed_arrL( &hCPE->hStereoDft->side_gain[0], &hCPE->hStereoDft->side_gain_fx[0], Q31, sizeof( hCPE->hStereoDft->side_gain_fx ) / sizeof( hCPE->hStereoDft->side_gain_fx[0] ) ); @@ -906,25 +917,51 @@ ivas_error ivas_jbm_dec_tc( { floatToFixed_arrL( &p_output[ii][0], &p_output_fix[ii][0], hCPE->hStereoDft->q_dft, ( 48000 / FRAMES_PER_SEC ) ); } - - Word16 q = 11; - IF( hCPE->hCoreCoder[0] != NULL ) - floatToFixed_arrL( &hCPE->hCoreCoder[0]->hHQ_core->old_outLB[0], &hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx[0], q, L_FRAME32k ); - IF( ( hCPE->hCoreCoder[0] != NULL ) && ( hCPE->hCoreCoder[0]->p_bpf_noise_buf_32 != NULL ) ) - floatToFixed_arrL( &hCPE->hCoreCoder[0]->p_bpf_noise_buf_float[0], &hCPE->hCoreCoder[0]->p_bpf_noise_buf_32[0], q, L_FRAME16k ); - floatToFixed_arrL( &hCPE->input_mem_BPF[0][0], &hCPE->input_mem_BPF_fx[0][0], q, STEREO_DFT32MS_OVL_16k ); - floatToFixed_arrL( &hCPE->input_mem[0][0], &hCPE->input_mem_fx[0][0], q, NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ) ); - floatToFixed_arrL( &hCPE->input_mem_LB[0][0], &hCPE->input_mem_LB_fx[0][0], q, STEREO_DFT32MS_OVL_16k ); - floatToFixed_arrL( &hCPE->input_mem[1][0], &hCPE->input_mem_fx[1][0], q, NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ) ); - floatToFixed_arrL( &hCPE->input_mem_LB[1][0], &hCPE->input_mem_LB_fx[1][0], q, STEREO_DFT32MS_OVL_16k ); - IF( hCPE->hStereoDft != NULL ) - floatToFixed_arrL( &hCPE->hStereoDft->ap_delay_mem[0], &hCPE->hStereoDft->ap_delay_mem_fx[0], q, NS2SA( 16000, DELAY_BWE_TOTAL_NS ) ); - floatToFixed_arrL( &hSCE->save_synth[0], &hSCE->save_synth_fx[0], q, (Word16) ( hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC ) ); - floatToFixed_arrL( &hSCE->save_hb_synth[0], &hSCE->save_hb_synth_fx[0], q, (Word16) ( hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC ) ); + q = hCPE->hStereoDft->q_dft; + floatToFixed_arrL(&hCPE->input_mem_BPF[0][0], &hCPE->input_mem_BPF_fx[0][0], q, STEREO_DFT32MS_OVL_16k); + floatToFixed_arrL(&hCPE->input_mem[0][0], &hCPE->input_mem_fx[0][0], q, NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS )); + floatToFixed_arrL(&hCPE->input_mem_LB[0][0], &hCPE->input_mem_LB_fx[0][0], q, STEREO_DFT32MS_OVL_16k); + floatToFixed_arrL(&hCPE->input_mem[1][0], &hCPE->input_mem_fx[1][0], q, NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS )); + floatToFixed_arrL(&hCPE->input_mem_LB[1][0], &hCPE->input_mem_LB_fx[1][0], q, STEREO_DFT32MS_OVL_16k); + if (hSCE != NULL) + { + floatToFixed_arrL(&hSCE->prev_hb_synth[0], &hSCE->prev_hb_synth_fx[0], hCPE->hStereoDft->q_dft, sizeof(hSCE->prev_hb_synth_fx) / sizeof(hSCE->prev_hb_synth_fx[0])); + floatToFixed_arrL(&hSCE->save_hb_synth[0], &hSCE->save_hb_synth_fx[0], q, (Word16)(hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC)); + floatToFixed_arrL(&hSCE->save_synth[0], &hSCE->save_synth_fx[0], q, (Word16)(hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC)); + } IF( hCPE->hCoreCoder[0] != NULL ) - floatToFixed_arrL( &hCPE->hCoreCoder[0]->hHQ_core->old_out[0], &hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx[0], q, L_FRAME48k ); + { + floatToFixed_arrL(&hCPE->hCoreCoder[0]->hHQ_core->old_outLB[0], &hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx[0], q, L_FRAME32k); + floatToFixed_arrL(&hCPE->hCoreCoder[0]->hHQ_core->old_out[0], &hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx[0], q, L_FRAME48k); + IF( (hCPE->hCoreCoder[0] != NULL) && (hCPE->hCoreCoder[0]->p_bpf_noise_buf_32 != NULL) ) + floatToFixed_arrL(&hCPE->hCoreCoder[0]->p_bpf_noise_buf_float[0], &hCPE->hCoreCoder[0]->p_bpf_noise_buf_32[0], q, L_FRAME16k); + } IF( hCPE->hStereoDft != NULL ) - floatToFixed_arrL( &hCPE->hStereoDft->buff_LBTCX_mem[0], &hCPE->hStereoDft->buff_LBTCX_mem_fx[0], q, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ) ); + { + floatToFixed_arrL(&hCPE->hStereoDft->ap_delay_mem[0], &hCPE->hStereoDft->ap_delay_mem_fx[0], q, NS2SA( 16000, DELAY_BWE_TOTAL_NS )); + floatToFixed_arrL(&hCPE->hStereoDft->buff_LBTCX_mem[0], &hCPE->hStereoDft->buff_LBTCX_mem_fx[0], q, NS2SA( 16000, STEREO_DFT32MS_OVL_NS )); + floatToFixed_arr(&hCPE->hStereoDft->smooth_fac[0][0], &hCPE->hStereoDft->smooth_fac_fx[0][0], Q15, sizeof(hCPE->hStereoDft->smooth_fac_fx) / sizeof(hCPE->hStereoDft->smooth_fac_fx[0][0])); + hCPE->hStereoDft->q_smooth_buf_fx = Q7; + floatToFixed_arrL(&hCPE->hStereoDft->smooth_buf[0][0], &hCPE->hStereoDft->smooth_buf_fx[0][0], hCPE->hStereoDft->q_smooth_buf_fx, sizeof(hCPE->hStereoDft->smooth_buf_fx) / sizeof(hCPE->hStereoDft->smooth_buf_fx[0][0])); + floatToFixed_arrL(&hCPE->hStereoDft->mixer_mat_smooth[0][0][0], &hCPE->hStereoDft->mixer_mat_smooth_fx[0][0][0], Q31, sizeof(hCPE->hStereoDft->mixer_mat_smooth_fx) / sizeof(hCPE->hStereoDft->mixer_mat_smooth_fx[0][0][0])); + floatToFixed_arrL(&st_ivas->hSpar->hMdDec->mixer_mat_prev[0][0][0][0], &st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0], Q31, sizeof(st_ivas->hSpar->hMdDec->mixer_mat_prev_fx) / sizeof(st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0])); + } + for (int ii = 0; ii < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; ii++) + { + for (int jj = 0; jj < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; jj++) + { + floatToFixed_arrL(&st_ivas->hSpar->hMdDec->mixer_mat[ii][jj][0], + &st_ivas->hSpar->hMdDec->mixer_mat_fx[ii][jj][0], + Q31, + st_ivas->hSpar->hMdDec->mix_mat_dim_2); + } + } + hCPE->lt_es_em_fx = floatToFixed(hCPE->lt_es_em, Q15); + for (int ii = 0; ii < CPE_CHANNELS; ii++) + { + hCPE->q_output_mem_fx[ii] = hCPE->hStereoDft->q_dft; + floatToFixed_arrL(&hCPE->output_mem[ii][0], &hCPE->output_mem_fx[ii][0], hCPE->hStereoDft->q_dft, NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS )); + } ivas_sba_dirac_stereo_dec_fx( st_ivas, p_output_fix, output_frame, st_ivas->ivas_format == MC_FORMAT ); @@ -936,17 +973,18 @@ ivas_error ivas_jbm_dec_tc( fixedToFloat_arrL( &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd_fx[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd[0], st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->q_smoothed_psd, sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd_fx ) / sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->smoothed_psd_fx[0] ) ); for ( int ii = 0; ii < sizeof( hCPE->hStereoDft->hb_nrg_subr_fx ) / sizeof( hCPE->hStereoDft->hb_nrg_subr_fx[0] ); ii++ ) { - hCPE->hStereoDft->hb_nrg_subr[0] = ( (float) hCPE->hStereoDft->hb_nrg_subr_fx[0] * ( (float) ( 1 << hCPE->hStereoDft->q_hb_nrg_subr ) ) ); + hCPE->hStereoDft->hb_nrg_subr[0] = ((float)hCPE->hStereoDft->hb_nrg_subr_fx[0] / ((float)(1 << hCPE->hStereoDft->q_hb_nrg_subr))); } for ( int ii = 0; ii < sizeof( hCPE->hStereoDft->hb_nrg_fx ) / sizeof( hCPE->hStereoDft->hb_nrg_fx[0] ); ii++ ) { hCPE->hStereoDft->hb_nrg[ii] = ( (float) hCPE->hStereoDft->hb_nrg_fx[ii] * ( (float) ( 1 << hCPE->hStereoDft->q_hb_nrg ) ) ); } - fixedToFloat_arrL( &hCPE->hStereoDft->side_gain_fx[0], &hCPE->hStereoDft->side_gain[0], Q31, sizeof( hCPE->hStereoDft->side_gain_fx ) / sizeof( hCPE->hStereoDft->side_gain_fx[0] ) ); - fixedToFloat_arrL( &hCPE->hStereoDft->gipd_fx[0], &hCPE->hStereoDft->gipd[0], Q13, sizeof( hCPE->hStereoDft->gipd_fx ) / sizeof( hCPE->hStereoDft->gipd_fx[0] ) ); - fixedToFloat_arr( &hCPE->hStereoDft->g_state_fx[0], &hCPE->hStereoDft->g_state[0], Q15, sizeof( hCPE->hStereoDft->g_state_fx ) / sizeof( hCPE->hStereoDft->g_state_fx[0] ) ); - fixedToFloat_arr( &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm[0], Q15, sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx ) / sizeof( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx[0] ) ); - IF( hCPE->hStereoCng != NULL ) + fixedToFloat_arrL(&hCPE->hStereoDft->side_gain_fx[0], &hCPE->hStereoDft->side_gain[0], Q31,sizeof(hCPE->hStereoDft->side_gain_fx) / sizeof(hCPE->hStereoDft->side_gain_fx[0])); + fixedToFloat_arrL(&hCPE->hStereoDft->gipd_fx[0], &hCPE->hStereoDft->gipd[0], Q13, sizeof(hCPE->hStereoDft->gipd_fx) / sizeof(hCPE->hStereoDft->gipd_fx[0])); + fixedToFloat_arr(&hCPE->hStereoDft->g_state_fx[0], &hCPE->hStereoDft->g_state[0], Q15, sizeof(hCPE->hStereoDft->g_state_fx) / sizeof(hCPE->hStereoDft->g_state_fx[0])); + fixedToFloat_arr(&st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx[0], &st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm[0], Q15, sizeof(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx) / sizeof(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_cm_fx[0])); + fixedToFloat_arrL(&hCPE->prev_hb_synth_fx[0][0], &hCPE->prev_hb_synth[0][0], hCPE->hStereoDft->q_dft, sizeof(hCPE->prev_hb_synth_fx) / sizeof(hCPE->prev_hb_synth_fx[0][0])); + IF (hCPE->hStereoCng != NULL) { fixedToFloat_arr( &hCPE->hStereoCng->cm_fx[0], &hCPE->hStereoCng->cm[0], Q15, sizeof( hCPE->hStereoCng->cm_fx ) / sizeof( hCPE->hStereoCng->cm_fx[0] ) ); } @@ -956,23 +994,48 @@ ivas_error ivas_jbm_dec_tc( { fixedToFloat_arrL( &p_output_fix[ii][0], &p_output[ii][0], hCPE->hStereoDft->q_dft, ( 48000 / FRAMES_PER_SEC ) ); } + fixedToFloat_arrL(&hCPE->input_mem_BPF_fx[0][0], &hCPE->input_mem_BPF[0][0], q, STEREO_DFT32MS_OVL_16k); + fixedToFloat_arrL(&hCPE->input_mem_fx[0][0], &hCPE->input_mem[0][0], q, NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS )); + fixedToFloat_arrL(&hCPE->input_mem_LB_fx[0][0], &hCPE->input_mem_LB[0][0], q, STEREO_DFT32MS_OVL_16k); + fixedToFloat_arrL(&hCPE->input_mem_fx[1][0], &hCPE->input_mem[1][0], q, NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS )); + fixedToFloat_arrL(&hCPE->input_mem_LB_fx[1][0], &hCPE->input_mem_LB[1][0], q, STEREO_DFT32MS_OVL_16k); + if (hSCE != NULL) + { + fixedToFloat_arrL(&hSCE->prev_hb_synth_fx[0], &hSCE->prev_hb_synth[0], hCPE->hStereoDft->q_dft, sizeof(hSCE->prev_hb_synth_fx) / sizeof(hSCE->prev_hb_synth_fx[0])); + fixedToFloat_arrL(&hSCE->save_synth_fx[0], &hSCE->save_synth[0], q, (Word16)(hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC)); + fixedToFloat_arrL(&hSCE->save_hb_synth_fx[0], &hSCE->save_hb_synth[0], q, (Word16)(hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC)); + } IF( hCPE->hCoreCoder[0] != NULL ) - fixedToFloat_arrL( &hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx[0], &hCPE->hCoreCoder[0]->hHQ_core->old_outLB[0], q, L_FRAME32k ); - IF( ( hCPE->hCoreCoder[0] != NULL ) && ( hCPE->hCoreCoder[0]->p_bpf_noise_buf_32 != NULL ) ) - fixedToFloat_arrL( &hCPE->hCoreCoder[0]->p_bpf_noise_buf_32[0], &hCPE->hCoreCoder[0]->p_bpf_noise_buf_float[0], q, L_FRAME16k ); - fixedToFloat_arrL( &hCPE->input_mem_BPF_fx[0][0], &hCPE->input_mem_BPF[0][0], q, STEREO_DFT32MS_OVL_16k ); - fixedToFloat_arrL( &hCPE->input_mem_fx[0][0], &hCPE->input_mem[0][0], q, NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ) ); - fixedToFloat_arrL( &hCPE->input_mem_LB_fx[0][0], &hCPE->input_mem_LB[0][0], q, STEREO_DFT32MS_OVL_16k ); - fixedToFloat_arrL( &hCPE->input_mem_fx[1][0], &hCPE->input_mem[1][0], q, NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ) ); - fixedToFloat_arrL( &hCPE->input_mem_LB_fx[1][0], &hCPE->input_mem_LB[1][0], q, STEREO_DFT32MS_OVL_16k ); - IF( hCPE->hStereoDft != NULL ) - fixedToFloat_arrL( &hCPE->hStereoDft->ap_delay_mem_fx[0], &hCPE->hStereoDft->ap_delay_mem[0], q, NS2SA( 16000, DELAY_BWE_TOTAL_NS ) ); - fixedToFloat_arrL( &hSCE->save_synth_fx[0], &hSCE->save_synth[0], q, (Word16) ( hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC ) ); - fixedToFloat_arrL( &hSCE->save_hb_synth_fx[0], &hSCE->save_hb_synth[0], q, (Word16) ( hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC ) ); - IF( hCPE->hCoreCoder[0] != NULL ) - fixedToFloat_arrL( &hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx[0], &hCPE->hCoreCoder[0]->hHQ_core->old_out[0], q, L_FRAME48k ); + { + fixedToFloat_arrL(&hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx[0], &hCPE->hCoreCoder[0]->hHQ_core->old_outLB[0], q, L_FRAME32k); + fixedToFloat_arrL(&hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx[0], &hCPE->hCoreCoder[0]->hHQ_core->old_out[0], q, L_FRAME48k); + IF( hCPE->hCoreCoder[0]->p_bpf_noise_buf_32 != NULL ) + fixedToFloat_arrL(&hCPE->hCoreCoder[0]->p_bpf_noise_buf_32[0], &hCPE->hCoreCoder[0]->p_bpf_noise_buf_float[0], q, L_FRAME16k); + } IF( hCPE->hStereoDft != NULL ) - fixedToFloat_arrL( &hCPE->hStereoDft->buff_LBTCX_mem_fx[0], &hCPE->hStereoDft->buff_LBTCX_mem[0], q, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ) ); + { + fixedToFloat_arrL(&hCPE->hStereoDft->ap_delay_mem_fx[0], &hCPE->hStereoDft->ap_delay_mem[0], q, NS2SA( 16000, DELAY_BWE_TOTAL_NS )); + fixedToFloat_arrL(&hCPE->hStereoDft->buff_LBTCX_mem_fx[0], &hCPE->hStereoDft->buff_LBTCX_mem[0], q, NS2SA( 16000, STEREO_DFT32MS_OVL_NS )); + fixedToFloat_arrL(&hCPE->hStereoDft->mixer_mat_smooth_fx[0][0][0], &hCPE->hStereoDft->mixer_mat_smooth[0][0][0], Q31, sizeof(hCPE->hStereoDft->mixer_mat_smooth_fx) / sizeof(hCPE->hStereoDft->mixer_mat_smooth_fx[0][0][0])); + fixedToFloat_arrL(&st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0], &st_ivas->hSpar->hMdDec->mixer_mat_prev[0][0][0][0], Q31, sizeof(st_ivas->hSpar->hMdDec->mixer_mat_prev_fx) / sizeof(st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0])); + fixedToFloat_arrL(&hCPE->hStereoDft->smooth_buf_fx[0][0], &hCPE->hStereoDft->smooth_buf[0][0], hCPE->hStereoDft->q_smooth_buf_fx, sizeof(hCPE->hStereoDft->smooth_buf_fx) / sizeof(hCPE->hStereoDft->smooth_buf_fx[0][0])); + fixedToFloat_arr(&hCPE->hStereoDft->smooth_fac_fx[0][0], &hCPE->hStereoDft->smooth_fac[0][0], Q15, sizeof(hCPE->hStereoDft->smooth_fac_fx) / sizeof(hCPE->hStereoDft->smooth_fac_fx[0][0])); + } + for (int ii = 0; ii < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; ii++) + { + for (int jj = 0; jj < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; jj++) + { + fixedToFloat_arrL(&st_ivas->hSpar->hMdDec->mixer_mat_fx[ii][jj][0], + &st_ivas->hSpar->hMdDec->mixer_mat[ii][jj][0], + Q31, + st_ivas->hSpar->hMdDec->mix_mat_dim_2); + } + } + for (int ii = 0; ii < CPE_CHANNELS; ii++) + { + fixedToFloat_arrL(&hCPE->output_mem_fx[ii][0], &hCPE->output_mem[ii][0], hCPE->hStereoDft->q_dft, NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS )); + } + hCPE->lt_es_em = fixedToFloat(hCPE->lt_es_em_fx, Q15); } #endif } @@ -6184,4 +6247,4 @@ void ivas_jbm_masa_sf_to_sf_map( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ivas_mdct_core_dec.c b/lib_dec/ivas_mdct_core_dec.c index fc43c4f2221ca69fb1b8320512dc323c1c0737c7..1a7d43e84f371625a598d912c3f2cf30043ef515 100644 --- a/lib_dec/ivas_mdct_core_dec.c +++ b/lib_dec/ivas_mdct_core_dec.c @@ -2454,6 +2454,7 @@ void ivas_mdct_core_tns_ns_fx( Word16 L_frame_global[CPE_CHANNELS], L_frameTCX_glob[CPE_CHANNELS]; /* TCX */ +#ifdef IVAS_FLOAT_FIXED Word32 xn_buf_fx[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX]; Word16 tcx_offset[CPE_CHANNELS]; Word16 tcx_offsetFB[CPE_CHANNELS]; @@ -2461,6 +2462,7 @@ void ivas_mdct_core_tns_ns_fx( Word16 L_spec[CPE_CHANNELS]; Word32 sns_int_scf_fx[FDNS_NPTS]; Word16 exp; +#endif // IVAS_FLOAT_FIXED /* Initializations */ sts = hCPE->hCoreCoder; @@ -2502,41 +2504,53 @@ void ivas_mdct_core_tns_ns_fx( init_tcx_info_fx( st, L_frame_global[ch], L_frameTCX_glob[ch], k, bfi, &tcx_offset[ch], &tcx_offsetFB[ch], &L_frame[ch], &L_frameTCX[ch], &left_rect[ch], &L_spec[ch] ); + Word16 q_x; + q_x = sub(31 , x_e[ch][k]); IF ( EQ_16(bfi, 0) ) { +#ifdef IVAS_FLOAT_FIXED sns_interpolate_scalefactors_fx( sns_int_scf_fx, &Aq_fx[ch][k * M], DEC ); +#else + sns_interpolate_scalefactors( &sns_int_scf[0], &Aq[ch][k * M], DEC ); +#endif // IVAS_FLOAT_FIXED IF ( NE_16(MCT_flag, 0) && st->hTonalMDCTConc != NULL && EQ_16( add( k, 1 ), nSubframes[ch] ) ) { +#ifdef IVAS_FLOAT_FIXED Word16 scf_fx[FDNS_NPTS], scf_e[FDNS_NPTS]; Word16 q_shift; FOR(Word16 ind = 0; ind < st->hTonalMDCTConc->nScaleFactors; ind++) { q_shift = norm_l(sns_int_scf_fx[ind]); scf_fx[ind] = extract_h(L_shl(sns_int_scf_fx[ind], q_shift)); - scf_e[ind] = 15 - q_shift; + scf_e[ind] = sub(15 , q_shift); } TonalMDCTConceal_SaveFreqSignal_ivas_fx( st->hTonalMDCTConc, x_fx[ch][k], x_e[ch][k], L_frameTCX[ch], L_frame[ch], &scf_fx[0], scf_e, 0, get_igf_startline( st, L_frame[ch], L_frameTCX[ch] ) ); +#else + TonalMDCTConceal_SaveFreqSignal_ivas( st->hTonalMDCTConc, x[ch][k], L_frameTCX[ch], L_frame[ch], &sns_int_scf[0], get_igf_startline_flt( st, L_frame[ch], L_frameTCX[ch] ) ); +#endif } } ELSE { + // st->hTonalMDCTConc->scf_fadeout; IF ( st->hTonalMDCTConc != NULL ) { IF ( EQ_16(MCT_flag, 0) && LT_16(st->hTcxDec->cummulative_damping_tcx, 32440) ) //if ( !MCT_flag && st->hTcxDec->cummulative_damping_tcx_float != 1.f ) { - Word16 *scf_last_m, *scf_bg, *scf_last_e; + Word16 *scf_last_m, *scf_last_e; + Word32 *scf_bg; Word16 fade_in, fade_out; scf_last_m = &st->hTonalMDCTConc->lastBlockData.scaleFactors[0]; scf_last_e = &st->hTonalMDCTConc->lastBlockData.scaleFactors_exp[0]; - scf_bg = &st->hTonalMDCTConc->scaleFactorsBackground[0]; + scf_bg = &st->hTonalMDCTConc->scaleFactorsBackground_fx[0]; st->hTonalMDCTConc->scf_fadeout = mult(st->hTonalMDCTConc->scf_fadeout, 31130); // 0.95 in Q15 = 31130 fade_out = st->hTonalMDCTConc->scf_fadeout; - fade_in = 32767 - fade_out; + fade_in = sub(32767 , fade_out); FOR ( Word16 i = 0; i < st->hTonalMDCTConc->nScaleFactors; i++ ) { @@ -2553,18 +2567,107 @@ void ivas_mdct_core_tns_ns_fx( } } } - Word16 q_x = 15 - x_e[ch][k]; +#ifdef IVAS_FLOAT_FIXED + Word16 norm_x; + q_x = sub(q_x,5); + Scale_sig32( &x_fx[ch][k][0], L_spec[ch], -5 ); decoder_tcx_tns_fx( st, L_frame_global[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], x_fx[ch][k], fUseTns[ch][k], &tnsData[ch][k], bfi, k, 1 ); - sns_shape_spectrum_fx( x_fx[ch][k], &q_x, st->hTcxCfg->psychParamsCurrent, sns_int_scf_fx, 16, st->hTcxCfg->psychParamsCurrent->nBins ); - x_e[ch][k] = 15 - q_x; + norm_x = getScaleFactor32( &x_fx[ch][k][0], L_spec[ch] ); + Scale_sig32( &x_fx[ch][k][0], L_spec[ch], norm_x ); + q_x = add(q_x,norm_x); + x_e[ch][k] = sub(31 , q_x); +#else + decoder_tcx_tns( st, L_frame_global[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], &x[ch][k][0], fUseTns[ch][k], &tnsData[ch][k], bfi, k, 1 ); +#endif +#ifdef IVAS_FLOAT_FIXED + Word16 q_sns_int_scf; + Word16 q_2; + q_sns_int_scf = add(16 - 1 , getScaleFactor32( sns_int_scf_fx, FDNS_NPTS )); + // q_sns_int_scf -= 1; + FOR( Word16 c = 0; c < FDNS_NPTS; c++ ) + { + sns_int_scf_fx[c] = L_shl( sns_int_scf_fx[c], q_sns_int_scf - 16 ); + } + q_2 = q_x; + sns_shape_spectrum_fx( x_fx[ch][k], &q_x, st->hTcxCfg->psychParamsCurrent, sns_int_scf_fx, q_sns_int_scf, st->hTcxCfg->psychParamsCurrent->nBins ); + IF ( LT_16(q_2 , add( q_x , 1 )) ) /*scaling to q_2*/ + { + Scale_sig32( &x_fx[ch][k][0],st->hTcxCfg->psychParamsCurrent->nBins, q_2 - q_x - 1 ); + q_x = q_2; + } + ELSE /*scaling to q_x+1*/ + { + Scale_sig32( &x_fx[ch][k][0] + st->hTcxCfg->psychParamsCurrent->nBins, L_spec[ch] - st->hTcxCfg->psychParamsCurrent->nBins, q_x + 1 - q_2 ); + q_x = add(q_x , 1); + } + x_e[ch][k] = sub(31 , q_x); +#else + sns_shape_spectrum( x[ch][k], st->hTcxCfg->psychParamsCurrent, &sns_int_scf[0], st->hTcxCfg->psychParamsCurrent->nBins ); +#endif // IVAS_FLOAT_FIXEDs +#ifdef IVAS_FLOAT_FIXED v_multc_fixed( x_fx[ch][k] + st->hTcxCfg->psychParamsCurrent->nBins, sns_int_scf_fx[FDNS_NPTS - 1], x_fx[ch][k] + st->hTcxCfg->psychParamsCurrent->nBins, L_spec[ch] - st->hTcxCfg->psychParamsCurrent->nBins ); + q_2 = sub(add(q_x , q_sns_int_scf) , 31); + Scale_sig32( &x_fx[ch][k][0], st->hTcxCfg->psychParamsCurrent->nBins, q_2 - q_x ); + q_x = q_2; + x_e[ch][k] = sub(31 , q_x); +#else + v_multc( x[ch][k] + st->hTcxCfg->psychParamsCurrent->nBins, sns_int_scf[FDNS_NPTS - 1], x[ch][k] + st->hTcxCfg->psychParamsCurrent->nBins, L_spec[ch] - st->hTcxCfg->psychParamsCurrent->nBins ); +#endif // IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED + q_x = sub(q_x,5); + Scale_sig32( &x_fx[ch][k][0], L_spec[ch], -5 ); decoder_tcx_tns_fx( st, L_frame_global[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], &x_fx[ch][k][0], fUseTns[ch][k], &tnsData[ch][k], bfi, k, 0 ); + norm_x = getScaleFactor32( &x_fx[ch][k][0], L_spec[ch] ); + Scale_sig32( &x_fx[ch][k][0], L_spec[ch], norm_x ); + q_x = add(q_x,norm_x); + x_e[ch][k] = sub(31 , q_x); +#else + decoder_tcx_tns( st, L_frame_global[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], &x[ch][k][0], fUseTns[ch][k], &tnsData[ch][k], bfi, k, 0 ); +#endif // IVAS_FLOAT_FIXED } IF ( NE_16(bfi, 0) && NE_16(st->tonal_mdct_plc_active, 0) ) { - TonalMDCTConceal_Apply( st->hTonalMDCTConc, x_fx[ch][0], &x_e[ch][0] ); +#ifdef IVAS_FLOAT_FIXED + Word16 q_x, q_x_old; + FOR( Word16 i = 0; i < FDNS_NPTS; i++ ) + { + st->hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e = s_max( st->hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e, st->hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i] ); + } + q_x_old = sub(31 , x_e[ch][0]); + TonalMDCTConceal_Apply_ivas_fx( st->hTonalMDCTConc, x_fx[ch][0], &x_e[ch][0], st->hTcxCfg->psychParamsCurrent ); + q_x = sub(31 , x_e[ch][0]); + // Fix to float + IF( LT_16(q_x_old , q_x) ) + { + x_e[ch][0] = sub(31 , q_x_old); + FOR( Word16 i = 0; i < st->hTonalMDCTConc->pTCI_float->numIndexes; i++ ) + { + FOR( Word16 l = st->hTonalMDCTConc->pTCI_float->lowerIndex[i]; l <= st->hTonalMDCTConc->pTCI_float->upperIndex[i]; l++ ) + { + x_fx[ch][0][l] = L_shr( x_fx[ch][0][l], q_x - q_x_old ); + } + } + } + ELSE + { + x_e[ch][0] = sub(31 , q_x); + FOR( Word16 i = 0; i < st->hTonalMDCTConc->pTCI_float->numIndexes; i++ ) + { + FOR( Word16 l = 0; l < st->hTonalMDCTConc->pTCI_float->lowerIndex[i]; l++ ) + { + x_fx[ch][0][l] = L_shr( x_fx[ch][0][l], sub(q_x_old , q_x) ); + } + FOR( Word16 l = st->hTonalMDCTConc->pTCI_float->upperIndex[i] + 1; l < L_spec[ch]; l++ ) + { + x_fx[ch][0][l] = L_shr( x_fx[ch][0][l], sub(q_x_old , q_x) ); + } + } + } +#else + TonalMDCTConceal_Apply_ivas( st->hTonalMDCTConc, x[ch][0], st->hTcxCfg->psychParamsCurrent ); +#endif } IF ( ( bfi || MCT_flag ) && st->hTonalMDCTConc != NULL ) diff --git a/lib_dec/ivas_post_proc.c b/lib_dec/ivas_post_proc.c index ef2e1f5a28f3222bc5f5580442acc23cf88bf371..177f86ceba22ef94782aad5760980a63b0445342 100644 --- a/lib_dec/ivas_post_proc.c +++ b/lib_dec/ivas_post_proc.c @@ -638,7 +638,7 @@ void stereo_dft_dec_core_switching_fx( /* apply predelay to have same overall filter delay FOR all cases */ - delay_signal_fx( pAp_input_fx, st->L_frame, hCPE->hStereoDft->ap_delay_mem_fx, predelay ); + delay_signal_q_adj_fx( pAp_input_fx, st->L_frame, hCPE->hStereoDft->ap_delay_mem_fx, predelay, *q, hCPE->hStereoDft->q_ap_delay_mem_fx); /* input zeroes FOR transient frames */ IF( hCPE->hStereoDft->attackPresent ) @@ -669,13 +669,13 @@ void stereo_dft_dec_core_switching_fx( } /* apply 5-stage allpass, each stage consisting of a nested allpass pair */ - - filter_with_allpass_fx( pAp_input_fx, pAp_input_fx, st->L_frame, &hCPE->hStereoDft->ap1 ); - filter_with_allpass_fx( pAp_input_fx, pAp_input_fx, st->L_frame, &hCPE->hStereoDft->ap2 ); - filter_with_allpass_fx( pAp_input_fx, pAp_input_fx, st->L_frame, &hCPE->hStereoDft->ap3 ); + filter_with_allpass_fx( pAp_input_fx, pAp_input_fx, st->L_frame, &hCPE->hStereoDft->ap1, sub(hCPE->hStereoDft->q_ap_delay_mem_fx , *q) ); + filter_with_allpass_fx( pAp_input_fx, pAp_input_fx, st->L_frame, &hCPE->hStereoDft->ap2, sub(hCPE->hStereoDft->q_ap_delay_mem_fx , *q) ); + filter_with_allpass_fx( pAp_input_fx, pAp_input_fx, st->L_frame, &hCPE->hStereoDft->ap3, sub(hCPE->hStereoDft->q_ap_delay_mem_fx , *q) ); /* apply DFT to allpass-filtered signal */ stereo_dft_dec_analyze_fx( hCPE, pAp_input_fx, DFT_fx, 1, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_FB, 0, 0, q, q_DFT ); + hCPE->hStereoDft->q_ap_delay_mem_fx = *q; } IF( st->core == ACELP_CORE ) diff --git a/lib_dec/ivas_rom_dec.c b/lib_dec/ivas_rom_dec.c index 01f446dfba8236263a61ad43fbb318bfb5084c2a..bf3c5dcf408017f5c28d1671a13c0581594d0d9a 100644 --- a/lib_dec/ivas_rom_dec.c +++ b/lib_dec/ivas_rom_dec.c @@ -400,7 +400,7 @@ const Word16 max_smooth_gains1_fx[SBA_DIRAC_STEREO_NUM_BANDS] = const Word16 min_smooth_gains1_fx[SBA_DIRAC_STEREO_NUM_BANDS] = { - (Word16)(0x0000), (Word16)(0x0000), (Word16)(0x6000), (Word16)(0x6000), + (Word16)(0x0000), (Word16)(0x0000), (Word16)(0x0000), (Word16)(0x0000), (Word16)(0x0000), (Word16)(0x0000), (Word16)(0x0000), (Word16)(0x0000), (Word16)(0x0000), (Word16)(0x0000), (Word16)(0x0000), (Word16)(0x0000) }; diff --git a/lib_dec/ivas_sba_dirac_stereo_dec_fx.c b/lib_dec/ivas_sba_dirac_stereo_dec_fx.c index 9489f54ceda899e49ca315cd50391c517e445e82..c8dc5069938ebd80619e05c688ce5e4c92e5f074 100644 --- a/lib_dec/ivas_sba_dirac_stereo_dec_fx.c +++ b/lib_dec/ivas_sba_dirac_stereo_dec_fx.c @@ -186,7 +186,7 @@ static Word16 ivas_sba_dirac_stereo_band_config( assert(0); } - bins_per_cldfb_band = (NFFT / ( 2 * num_cldfb_bands )); + bins_per_cldfb_band = idiv1616(NFFT , shl( num_cldfb_bands, 1 )); move16(); band_limits[0] = 1; move16(); @@ -336,8 +336,7 @@ static void map_params_dirac_to_stereo( Word32 DFT[STEREO_DFT_BUF_MAX], /* i/o: DFT buffer */ const UWord8 b_wide_panning, /* i : flag indicating wider panning */ const Word16 L_frame, /* i : core signal length */ - const Word16 mcmasa, /* i : McMASA flag */ - Word16 q_dft + const Word16 mcmasa /* i : McMASA flag */ ) { Word16 i, b, k; @@ -375,68 +374,88 @@ static void map_params_dirac_to_stereo( /* gain smoothing factor */ pDFT = DFT; - q_nrg = q_dft; + q_nrg = hStereoDft->q_dft; move16(); FOR ( k = 0; k < NB_DIV; k++ ) { FOR ( b = 0; b < hStereoDft->nbands; b++ ) { + Word64 tmp64 = 0; /* calculate band-wise subframe energies */ subframe_band_nrg[k][b] = 0; move32(); FOR ( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) { - subframe_band_nrg[k][b] = L_add(subframe_band_nrg[k][b], - Madd_32_32(Mpy_32_32(pDFT[2 * i], pDFT[2 * i]), - pDFT[2 * i + 1], pDFT[2 * i + 1])); + tmp64 = W_add(tmp64, W_add(W_mult0_32_32(pDFT[2 * i], pDFT[2 * i]), + W_mult0_32_32(pDFT[2 * i + 1], pDFT[2 * i + 1]))); move32(); } + subframe_band_nrg[k][b] = W_extract_h(W_shl(tmp64, 1)); + q_nrg = sub(Q31, sub(shl(hStereoDft->q_dft, 1) , Q31)); subframe_band_nrg[k][b] = Sqrt32( subframe_band_nrg[k][b], &q_nrg ); move32(); + IF (NE_16(q_nrg , sub(Q31, hStereoDft->q_smooth_buf_fx))) + { + subframe_band_nrg[k][b] = L_shl(subframe_band_nrg[k][b], sub(q_nrg, sub(Q31, hStereoDft->q_smooth_buf_fx))); + } hStereoDft->smooth_buf_fx[b][NB_DIV - 1 - k] = subframe_band_nrg[k][b]; move32(); /* calculate short and long energy averages */ smooth_short_avg[k][b] = EPSILON_FIX; move32(); + smooth_long_avg[k][b] = 0; + move32(); + /* Multiplying and adding avoids overflow */ FOR ( i = sub(NB_DIV - 1, k); i < add(SBA_DIRAC_NRG_SMOOTH_SHORT + NB_DIV - 1, k); i++ ) { - smooth_short_avg[k][b] = L_add(smooth_short_avg[k][b], hStereoDft->smooth_buf_fx[b][i]); + smooth_short_avg[k][b] = Madd_32_16(smooth_short_avg[k][b], hStereoDft->smooth_buf_fx[b][i], (Word16)0x2AAB); /* 1/ 3 in Q15*/ + move32(); + smooth_long_avg[k][b] = Madd_32_16(smooth_long_avg[k][b], hStereoDft->smooth_buf_fx[b][i], (Word16)0x0CCD); /* 1/ 10 in Q15*/ move32(); } - smooth_long_avg[k][b] = smooth_short_avg[k][b]; - move32(); FOR ( i = sub(NB_DIV - 1 + SBA_DIRAC_NRG_SMOOTH_SHORT, k) ; i < sub(SBA_DIRAC_NRG_SMOOTH_LONG + NB_DIV - 1, k); i++ ) { - smooth_long_avg[k][b] = L_add(smooth_long_avg[k][b], hStereoDft->smooth_buf_fx[b][i]); + smooth_long_avg[k][b] = Madd_32_16(smooth_long_avg[k][b], hStereoDft->smooth_buf_fx[b][i], (Word16)0x0CCD); move32(); } - smooth_short_avg[k][b] = Mpy_32_16_1(smooth_short_avg[k][b], (Word16)0x2AAB); /* 1/ 3 in Q15*/ - move32(); - smooth_long_avg[k][b] = Mpy_32_16_1(smooth_long_avg[k][b], (Word16)0x0CCD); /* 1/ 10 in Q15*/ - move32(); /* calculate smoothing factor based on energy averages */ /* reduce factor for higher short-term energy */ - hStereoDft->smooth_fac_fx[k][b] = extract_l(s_min( MAX_16, BASOP_Util_Divide3232_Scale(smooth_long_avg[k][b] , smooth_short_avg[k][b], &q_div) )); - move32(); - IF (GT_16(q_div, 0)) + IF (NE_32(smooth_long_avg[k][b], 0)) { - assert(0); + hStereoDft->smooth_fac_fx[k][b] = extract_l(s_min( MAX_16, BASOP_Util_Divide3232_Scale(smooth_long_avg[k][b] , smooth_short_avg[k][b], &q_div) )); + move32(); + IF (GT_16(q_div , norm_s(hStereoDft->smooth_fac_fx[k][b]))) + { + hStereoDft->smooth_fac_fx[k][b] = MAX_16; + move32(); + } + ELSE + { + hStereoDft->smooth_fac_fx[k][b] = shl(hStereoDft->smooth_fac_fx[k][b], q_div); + move32(); + q_div = 0; + move16(); + } } ELSE { - hStereoDft->smooth_fac_fx[k][b] = shl(hStereoDft->smooth_fac_fx[k][b], q_div); - q_div = 0; + hStereoDft->smooth_fac_fx[k][b] = 0; + move32(); } + /* map factor to range [0;1] */ - hStereoDft->smooth_fac_fx[k][b] = extract_l(Mpy_32_16_1(SBA_DIRAC_NRG_SMOOTH_LONG_BY_LONG_SHORT_FX, s_max( 0, sub(hStereoDft->smooth_fac_fx[k][b] , SBA_DIRAC_NRG_SMOOTH_SHORT_BY_LONG_FX)))); + hStereoDft->smooth_fac_fx[k][b] = s_max( 0, extract_l(L_shr(Mpy_32_16_1(SBA_DIRAC_NRG_SMOOTH_LONG_BY_LONG_SHORT_FX, sub(hStereoDft->smooth_fac_fx[k][b] , SBA_DIRAC_NRG_SMOOTH_SHORT_BY_LONG_FX)), Q15))); move16(); /* compress factor (higher compression in lowest bands) */ + q_sqrt = 0; + move16(); IF ( LT_16(b, 2) ) { - hStereoDft->smooth_fac_fx[k][b] = Sqrt16(Sqrt16( hStereoDft->smooth_fac_fx[k][b], &q_sqrt), &q_sqrt); + Word16 tmp_val = Sqrt16( hStereoDft->smooth_fac_fx[k][b], &q_sqrt); + hStereoDft->smooth_fac_fx[k][b] = Sqrt16(tmp_val, &q_sqrt); move16(); } ELSE @@ -444,6 +463,8 @@ static void map_params_dirac_to_stereo( hStereoDft->smooth_fac_fx[k][b] = Sqrt16( hStereoDft->smooth_fac_fx[k][b], &q_sqrt ); move16(); } + hStereoDft->smooth_fac_fx[k][b] = shl(hStereoDft->smooth_fac_fx[k][b], q_sqrt); + move16(); /* apply upper bounds depending on band */ hStereoDft->smooth_fac_fx[0][b] = s_max( hStereoDft->min_smooth_gains_fx[b], s_min( hStereoDft->max_smooth_gains_fx[b], hStereoDft->smooth_fac_fx[0][b] ) ); @@ -458,17 +479,24 @@ static void map_params_dirac_to_stereo( { /* calculate block energies for side gain weighting (combine angles of 2 DirAC blocks to side gain for 1 DFT Stereo subframe; 4 blocks and 2 subframes overall) */ pSynth = synth; - block_len = L_frame / nBlocks; + block_len = idiv1616(L_frame , nBlocks); FOR ( block = 0; block < nBlocks; block++ ) { block_nrg[block] = 0; + move32(); FOR ( i = 0; i < block_len; i++ ) { block_nrg[block] = Madd_32_32(block_nrg[block], pSynth[i] , pSynth[i]); move32(); } - block_nrg[block] = Sqrt32( block_nrg[block], 0); + q_nrg = sub(Q31, sub(shl(hStereoDft->q_dft, 1) , Q31)); + block_nrg[block] = Sqrt32( block_nrg[block], &q_nrg); move32(); + IF (NE_16(q_nrg , sub(Q31, hStereoDft->q_dft))) + { + block_nrg[block] = L_shl(block_nrg[block], sub(q_nrg, sub(Q31, hStereoDft->q_dft))); + move32(); + } pSynth += block_len; } nrg_norm1 = L_deposit_l(BASOP_Util_Divide3232_Scale(MAX_32, L_add(block_nrg[0] , L_add(block_nrg[1] , EPSILON_FIX) ), &q_div)); @@ -530,7 +558,7 @@ static void map_params_dirac_to_stereo( /* combine angles of first 2 blocks to side gain of first subframe */ side_gain[b] = 0; move32(); - FOR ( block = 0; block < nBlocks / 2; block++ ) + FOR ( block = 0; block < shr(nBlocks , 1); block++ ) { IF ( EQ_16(b_wide_panning, 1) ) { @@ -548,7 +576,7 @@ static void map_params_dirac_to_stereo( /* combine angles of last 2 blocks to side gain of second subframe */ side_gain[b + STEREO_DFT_BAND_MAX] = 0; move32(); - FOR ( block = nBlocks / 2; block < nBlocks; block++ ) + FOR ( block = shr(nBlocks , 1); block < nBlocks; block++ ) { IF ( EQ_16(b_wide_panning, 1) ) { @@ -563,17 +591,17 @@ static void map_params_dirac_to_stereo( } } - side_gain[b] = Mpy_32_32(side_gain[b], Sqrt32(L_sub((Word32)0x7FFFFFFF, diffuseness[b]), &q_sqrt)); + side_gain[b] = Mpy_32_32(side_gain[b], Sqrt32(L_sub(MAX_32, diffuseness[b]), &q_sqrt)); move32(); IF (NE_16(q_sqrt, 0)) { - assert(0); + side_gain[b] = L_shl(side_gain[b], q_sqrt); } side_gain[b + STEREO_DFT_BAND_MAX] = Mpy_32_32(side_gain[b + STEREO_DFT_BAND_MAX], Sqrt32(L_sub((Word32)0x7FFFFFFF, diffuseness[b]), &q_sqrt)); move32(); IF (NE_16(q_sqrt, 0)) { - assert(0); + side_gain[b + STEREO_DFT_BAND_MAX] = L_shl(side_gain[b], q_sqrt); } res_pred_gain[b] = Mpy_32_32(diffuseness[b], L_sub((Word32)0x7FFFFFFF, surrCoh[b] )); move32(); @@ -643,10 +671,6 @@ static void ivas_sba_dirac_stereo_compute_td_stefi_nrgs( move32(); hStereoDft->hb_nrg_subr_fx[1] = (hStereoDft->hb_nrg_subr_fx[1] * shr(hStereoDft->NFFT, 1)); move32(); - IF (LE_32(hStereoDft->hb_nrg_subr_fx[0] , 0) || LE_32(hStereoDft->hb_nrg_subr_fx[1] , 0)) - { - assert(0); - } hStereoDft->hb_nrg_fx[0] = hb_nrg; move32(); hStereoDft->td_gain_fx[0] = 0; @@ -702,90 +726,99 @@ static void ivas_sba_dirac_stereo_upmix_hb( { Word16 i; Word32 gp, gm; - Word32 gain_fac; + Word16 gain_fac; IF ( EQ_16(mcmasa, 0) ) { - gain_fac = ( bwidth == FB ) ? (Word32)0x20000000 : (Word32)0x2A3D70A4; /* last matrix element not used for SWB, divide by 3 instead of 4*/ + gain_fac = ( bwidth == FB ) ? (Word32)0x2000 : (Word32)0x2A3D; /* last matrix element not used for SWB, divide by 3 instead of 4*/ + move16(); IF ( sba_mono_flag ) { - gp = L_add(hStereoDft->mixer_mat_smooth_fx[0][0][8], - L_add(hStereoDft->mixer_mat_smooth_fx[0][0][9], - hStereoDft->mixer_mat_smooth_fx[0][0][10])); + gp = L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][8], gain_fac), + Madd_32_16(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][9], gain_fac), + hStereoDft->mixer_mat_smooth_fx[0][0][10], gain_fac)); IF ( EQ_16(bwidth, FB) ) { - gp = L_add(gp, hStereoDft->mixer_mat_smooth_fx[0][0][11]); + gp = Madd_32_16(gp, hStereoDft->mixer_mat_smooth_fx[0][0][11], gain_fac); } FOR ( i = 0; i < shr(output_frame, 1); i++ ) { - hb_stereo_synth[0][i] = Mpy_32_32(hb_synth[i] , Mpy_32_32( gain_fac , gp)); + hb_stereo_synth[0][i] = Mpy_32_32(hb_synth[i] , gp); move32(); } - gp = L_add(hStereoDft->mixer_mat_smooth_fx[0][0][8 + IVAS_MAX_NUM_BANDS], - L_add(hStereoDft->mixer_mat_smooth_fx[0][0][9 + IVAS_MAX_NUM_BANDS], - hStereoDft->mixer_mat_smooth_fx[0][0][10 + IVAS_MAX_NUM_BANDS])); + gp = L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][8 + IVAS_MAX_NUM_BANDS], gain_fac), + Madd_32_16(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][9 + IVAS_MAX_NUM_BANDS], gain_fac), + hStereoDft->mixer_mat_smooth_fx[0][0][10 + IVAS_MAX_NUM_BANDS], gain_fac)); IF ( EQ_16(bwidth, FB) ) { - gp = L_add(gp, hStereoDft->mixer_mat_smooth_fx[0][0][11 + IVAS_MAX_NUM_BANDS]); + gp = Madd_32_16(gp, hStereoDft->mixer_mat_smooth_fx[0][0][11 + IVAS_MAX_NUM_BANDS], gain_fac); } FOR ( i = shr(output_frame , 1); i < output_frame; i++ ) { - hb_stereo_synth[0][i] = Mpy_32_32(Mpy_32_32(hb_synth[i] , gain_fac), gp); + hb_stereo_synth[0][i] = Mpy_32_32(hb_synth[i], gp); + move32(); } } ELSE { - gp = L_add(hStereoDft->mixer_mat_smooth_fx[0][0][8] , - L_add(hStereoDft->mixer_mat_smooth_fx[1][0][8] , - L_add(hStereoDft->mixer_mat_smooth_fx[0][0][9] , - L_add(hStereoDft->mixer_mat_smooth_fx[1][0][9] , - L_add(hStereoDft->mixer_mat_smooth_fx[0][0][10] , - hStereoDft->mixer_mat_smooth_fx[1][0][10]))))); + /* Accounting for the 0.5 multiplication */ + gain_fac = shr(gain_fac, 1); + gp = L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][8], gain_fac) , + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][0][8], gain_fac) , + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][9], gain_fac) , + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][0][9], gain_fac) , + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][10], gain_fac) , + Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][0][10], gain_fac)))))); IF ( EQ_32(bwidth , FB) ) { - gp = L_add(gp, L_add(hStereoDft->mixer_mat_smooth_fx[0][0][11] , hStereoDft->mixer_mat_smooth_fx[1][0][11])); + gp = L_add(gp, Madd_32_16(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][11] , gain_fac), + hStereoDft->mixer_mat_smooth_fx[1][0][11], gain_fac)); } - gm = L_add(L_sub(hStereoDft->mixer_mat_smooth_fx[0][0][8] , hStereoDft->mixer_mat_smooth_fx[1][0][8]) , - L_add(L_sub(hStereoDft->mixer_mat_smooth_fx[0][0][9] , hStereoDft->mixer_mat_smooth_fx[1][0][9]) , - L_sub(hStereoDft->mixer_mat_smooth_fx[0][0][10] , hStereoDft->mixer_mat_smooth_fx[1][0][10]))); + gm = L_add(Msub_32_16(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][8], gain_fac) , + hStereoDft->mixer_mat_smooth_fx[1][0][8], gain_fac) , + L_add(Msub_32_16(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][9], gain_fac) , + hStereoDft->mixer_mat_smooth_fx[1][0][9], gain_fac) , + Msub_32_16(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][10], gain_fac) , + hStereoDft->mixer_mat_smooth_fx[1][0][10], gain_fac))); IF ( EQ_32(bwidth , FB) ) { - gm = L_add(gm, L_sub(hStereoDft->mixer_mat_smooth_fx[0][0][11] , hStereoDft->mixer_mat_smooth_fx[1][0][11])); + gm = L_add(gm, Msub_32_16(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][11], gain_fac) , + hStereoDft->mixer_mat_smooth_fx[1][0][11], gain_fac)); } - FOR ( i = 0; i < output_frame / 2; i++ ) + FOR ( i = 0; i < shr(output_frame , 1); i++ ) { - hb_stereo_synth[0][i] = L_shr(Mpy_32_32(Mpy_32_32(hb_synth[i] , gain_fac) , gp), 1); + hb_stereo_synth[0][i] = Mpy_32_32(hb_synth[i] , gp); move32(); - hb_stereo_synth[1][i] = L_shr(Mpy_32_32(Mpy_32_32(hb_synth[i] , gain_fac) , gm), 1); + hb_stereo_synth[1][i] = Mpy_32_32(hb_synth[i] , gm); move32(); } - gp = L_add(hStereoDft->mixer_mat_smooth_fx[0][0][8 + IVAS_MAX_NUM_BANDS], - L_add(hStereoDft->mixer_mat_smooth_fx[1][0][8 + IVAS_MAX_NUM_BANDS], - L_add(hStereoDft->mixer_mat_smooth_fx[0][0][9 + IVAS_MAX_NUM_BANDS], - L_add(hStereoDft->mixer_mat_smooth_fx[1][0][9 + IVAS_MAX_NUM_BANDS], - L_add(hStereoDft->mixer_mat_smooth_fx[0][0][10 + IVAS_MAX_NUM_BANDS], - hStereoDft->mixer_mat_smooth_fx[1][0][10 + IVAS_MAX_NUM_BANDS]))))); + gp = L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][8 + IVAS_MAX_NUM_BANDS], gain_fac), + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][0][8 + IVAS_MAX_NUM_BANDS], gain_fac), + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][9 + IVAS_MAX_NUM_BANDS], gain_fac), + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][0][9 + IVAS_MAX_NUM_BANDS], gain_fac), + Madd_32_16(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][10 + IVAS_MAX_NUM_BANDS], gain_fac), + hStereoDft->mixer_mat_smooth_fx[1][0][10 + IVAS_MAX_NUM_BANDS], gain_fac))))); IF ( EQ_32(bwidth , FB) ) { - gp = L_add(gp, L_add(hStereoDft->mixer_mat_smooth_fx[0][0][11 + IVAS_MAX_NUM_BANDS] , hStereoDft->mixer_mat_smooth_fx[1][0][11 + IVAS_MAX_NUM_BANDS])); + gp = L_add(gp, Madd_32_16(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][11 + IVAS_MAX_NUM_BANDS], gain_fac) , hStereoDft->mixer_mat_smooth_fx[1][0][11 + IVAS_MAX_NUM_BANDS], gain_fac)); } - gm = L_add(L_sub(hStereoDft->mixer_mat_smooth_fx[0][0][8 + IVAS_MAX_NUM_BANDS] , hStereoDft->mixer_mat_smooth_fx[1][0][8 + IVAS_MAX_NUM_BANDS]), - L_add(L_sub(hStereoDft->mixer_mat_smooth_fx[0][0][9 + IVAS_MAX_NUM_BANDS] , hStereoDft->mixer_mat_smooth_fx[1][0][9 + IVAS_MAX_NUM_BANDS]), - L_sub(hStereoDft->mixer_mat_smooth_fx[0][0][10 + IVAS_MAX_NUM_BANDS] , hStereoDft->mixer_mat_smooth_fx[1][0][10 + IVAS_MAX_NUM_BANDS]))); + gm = L_add(Msub_32_16(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][8 + IVAS_MAX_NUM_BANDS], gain_fac) , hStereoDft->mixer_mat_smooth_fx[1][0][8 + IVAS_MAX_NUM_BANDS], gain_fac), + L_add(Msub_32_16(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][9 + IVAS_MAX_NUM_BANDS], gain_fac) , hStereoDft->mixer_mat_smooth_fx[1][0][9 + IVAS_MAX_NUM_BANDS], gain_fac), + Msub_32_16(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][10 + IVAS_MAX_NUM_BANDS], gain_fac) , hStereoDft->mixer_mat_smooth_fx[1][0][10 + IVAS_MAX_NUM_BANDS], gain_fac))); IF ( EQ_32(bwidth , FB) ) { - gm = L_add(gm, L_sub(hStereoDft->mixer_mat_smooth_fx[0][0][11 + IVAS_MAX_NUM_BANDS] , hStereoDft->mixer_mat_smooth_fx[1][0][11 + IVAS_MAX_NUM_BANDS])); + gm = L_add(gm, Msub_32_16(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][0][11 + IVAS_MAX_NUM_BANDS], gain_fac) , hStereoDft->mixer_mat_smooth_fx[1][0][11 + IVAS_MAX_NUM_BANDS], gain_fac)); } FOR ( i = shr(output_frame , 1); i < output_frame; i++ ) { - hb_stereo_synth[0][i] = L_shr(Mpy_32_32(hb_synth[i] , Mpy_32_32(gain_fac , gp)), 1); + hb_stereo_synth[0][i] = Mpy_32_32(hb_synth[i] , gp); move32(); - hb_stereo_synth[1][i] = L_shr(Mpy_32_32(hb_synth[i] , Mpy_32_32(gain_fac , gm)), 1); + hb_stereo_synth[1][i] = Mpy_32_32(hb_synth[i] , gm); move32(); } } @@ -842,52 +875,52 @@ static void ivas_sba_dirac_stereo_apply_td_stefi( Word32 g_L, g_R; Word32 stefi_L, stefi_R; - g_W_1 = L_add(hStereoDft->mixer_mat_smooth_fx[0][1][8], - L_add(hStereoDft->mixer_mat_smooth_fx[0][2][8] , - L_add(hStereoDft->mixer_mat_smooth_fx[0][3][8] , - L_add(hStereoDft->mixer_mat_smooth_fx[0][1][9] , - L_add(hStereoDft->mixer_mat_smooth_fx[0][2][9], - L_add(hStereoDft->mixer_mat_smooth_fx[0][3][9], - L_add( hStereoDft->mixer_mat_smooth_fx[0][1][10], - L_add(hStereoDft->mixer_mat_smooth_fx[0][2][10], - hStereoDft->mixer_mat_smooth_fx[0][3][10]) + g_W_1 = L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][1][8], 0x147B), + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][2][8], 0x147B) , + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][3][8], 0x147B) , + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][1][9], 0x147B) , + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][2][9], 0x147B), + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][3][9], 0x147B), + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][1][10], 0x147B), + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][2][10], 0x147B), + Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][3][10], 0x147B)) ))))))); - g_Y_1 = L_add( hStereoDft->mixer_mat_smooth_fx[1][1][8], - L_add(hStereoDft->mixer_mat_smooth_fx[1][2][8], - L_add(hStereoDft->mixer_mat_smooth_fx[1][3][8], - L_add( hStereoDft->mixer_mat_smooth_fx[1][1][9], - L_add(hStereoDft->mixer_mat_smooth_fx[1][2][9], - L_add(hStereoDft->mixer_mat_smooth_fx[1][3][9], - L_add(hStereoDft->mixer_mat_smooth_fx[1][1][10], - L_add(hStereoDft->mixer_mat_smooth_fx[1][2][10], - hStereoDft->mixer_mat_smooth_fx[1][3][10]) + g_Y_1 = L_add( Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][1][8], 0x147B), + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][2][8], 0x147B), + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][3][8], 0x147B), + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][1][9], 0x147B), + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][2][9], 0x147B), + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][3][9], 0x147B), + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][1][10], 0x147B), + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][2][10], 0x147B), + Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][3][10], 0x147B)) ))))))); - g_W_2 = L_add(hStereoDft->mixer_mat_smooth_fx[0][1][8 + IVAS_MAX_NUM_BANDS], - L_add(hStereoDft->mixer_mat_smooth_fx[0][2][8 + IVAS_MAX_NUM_BANDS], - L_add(hStereoDft->mixer_mat_smooth_fx[0][3][8 + IVAS_MAX_NUM_BANDS], - L_add(hStereoDft->mixer_mat_smooth_fx[0][1][9 + IVAS_MAX_NUM_BANDS], - L_add(hStereoDft->mixer_mat_smooth_fx[0][2][9 + IVAS_MAX_NUM_BANDS], - L_add(hStereoDft->mixer_mat_smooth_fx[0][3][9 + IVAS_MAX_NUM_BANDS], - L_add(hStereoDft->mixer_mat_smooth_fx[0][1][10 + IVAS_MAX_NUM_BANDS], - L_add(hStereoDft->mixer_mat_smooth_fx[0][2][10 + IVAS_MAX_NUM_BANDS], - hStereoDft->mixer_mat_smooth_fx[0][3][10 + IVAS_MAX_NUM_BANDS]) + g_W_2 = L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][1][8 + IVAS_MAX_NUM_BANDS], 0x147B), + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][2][8 + IVAS_MAX_NUM_BANDS], 0x147B), + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][3][8 + IVAS_MAX_NUM_BANDS], 0x147B), + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][1][9 + IVAS_MAX_NUM_BANDS], 0x147B), + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][2][9 + IVAS_MAX_NUM_BANDS], 0x147B), + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][3][9 + IVAS_MAX_NUM_BANDS], 0x147B), + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][1][10 + IVAS_MAX_NUM_BANDS], 0x147B), + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][2][10 + IVAS_MAX_NUM_BANDS], 0x147B), + Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[0][3][10 + IVAS_MAX_NUM_BANDS], 0x147B)) ))))))); - g_Y_2 = L_add(hStereoDft->mixer_mat_smooth_fx[1][1][8 + IVAS_MAX_NUM_BANDS], - L_add(hStereoDft->mixer_mat_smooth_fx[1][2][8 + IVAS_MAX_NUM_BANDS], - L_add(hStereoDft->mixer_mat_smooth_fx[1][3][8 + IVAS_MAX_NUM_BANDS], - L_add(hStereoDft->mixer_mat_smooth_fx[1][1][9 + IVAS_MAX_NUM_BANDS], - L_add(hStereoDft->mixer_mat_smooth_fx[1][2][9 + IVAS_MAX_NUM_BANDS], - L_add(hStereoDft->mixer_mat_smooth_fx[1][3][9 + IVAS_MAX_NUM_BANDS], - L_add(hStereoDft->mixer_mat_smooth_fx[1][1][10 + IVAS_MAX_NUM_BANDS], - L_add(hStereoDft->mixer_mat_smooth_fx[1][2][10 + IVAS_MAX_NUM_BANDS], - hStereoDft->mixer_mat_smooth_fx[1][3][10 + IVAS_MAX_NUM_BANDS]) + g_Y_2 = L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][1][8 + IVAS_MAX_NUM_BANDS], 0x147B), + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][2][8 + IVAS_MAX_NUM_BANDS], 0x147B), + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][3][8 + IVAS_MAX_NUM_BANDS], 0x147B), + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][1][9 + IVAS_MAX_NUM_BANDS], 0x147B), + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][2][9 + IVAS_MAX_NUM_BANDS], 0x147B), + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][3][9 + IVAS_MAX_NUM_BANDS], 0x147B), + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][1][10 + IVAS_MAX_NUM_BANDS], 0x147B), + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][2][10 + IVAS_MAX_NUM_BANDS], 0x147B), + Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[1][3][10 + IVAS_MAX_NUM_BANDS], 0x147B)) ))))))); - g_L = Mpy_32_16_1(L_sub( L_add(g_W_1 , g_W_2) , L_add(g_Y_1 , g_Y_2) ), 0x147B); /* 0x147B = 0.16 in Q15 */ - g_R = Mpy_32_16_1(L_add( L_add(g_W_1 , g_W_2) , L_add(g_Y_1 , g_Y_2) ), 0x147B); /* 0x147B = 0.16 in Q15 */ + g_L = L_sub( L_add(g_W_1 , g_W_2) , L_add(g_Y_1 , g_Y_2) ); /* 0x147B = 0.16 in Q15 */ + g_R = L_add( L_add(g_W_1 , g_W_2) , L_add(g_Y_1 , g_Y_2) ); /* 0x147B = 0.16 in Q15 */ FOR ( i = 0; i < dftOvlLen; i++ ) { @@ -1016,9 +1049,13 @@ void ivas_sba_dirac_stereo_smooth_parameters_fx( Word16 md_sf; xfade_start_ns = W_sub(W_mult_32_32((Word32)cross_fade_start_offset, 1000000000), W_mult_32_32(IVAS_FB_ENC_DELAY_NS, output_Fs)); - xfade_delay_subframes = (Word16) ( xfade_start_ns / W_mult_32_32(( FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ), output_Fs) ); + /* + 64-bit container is needed for storing the result in the previous step. + ToDo: Replace the 64-bit division below with appropriate BASOP + */ + xfade_delay_subframes = (Word16)( xfade_start_ns / W_mult_32_32(( FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ), output_Fs)); move16(); - i_hist = 4 - xfade_delay_subframes; + i_hist = sub((Word16)4 , xfade_delay_subframes); move16(); FOR ( k = 0; k < 2; k++ ) { @@ -1111,7 +1148,7 @@ void ivas_sba_dirac_stereo_dec_fx( Word32 hb_gain[NB_DIV]; Word32 hb_synth_stereo[CPE_CHANNELS][L_FRAME48k]; Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX]; - Word16 q_dft = 0; + Word16 q_dft[2] = {0, 0}; Word16 q = 0; SCE_DEC_HANDLE hSCE; CPE_DEC_HANDLE hCPE; @@ -1121,6 +1158,8 @@ void ivas_sba_dirac_stereo_dec_fx( hCPE = st_ivas->hCPE[0]; hStereoDft = hCPE->hStereoDft; q = hCPE->hStereoDft->q_dft; + q_dft[0] = hCPE->hStereoDft->q_dft; + q_dft[1] = hCPE->hStereoDft->q_dft; IF ( GT_16(st_ivas->nchan_transport, 1) && EQ_16(mcmasa, 0) ) { @@ -1143,8 +1182,8 @@ void ivas_sba_dirac_stereo_dec_fx( stereo_dft_dec_update_fx( hStereoDft, output_frame, 1 /*st_ivas->sba_dirac_stereo_flag*/ ); IF ( GT_16(st_ivas->nchan_transport, 1) ) { - stereo_dft_dec_analyze_fx( hCPE, output[0], DFT, 0, output_frame, output_frame, DFT_STEREO_DEC_ANA_FB, 0, 0, &q, &q_dft ); - stereo_dft_dec_analyze_fx( hCPE, output[1], DFT, 1, output_frame, output_frame, DFT_STEREO_DEC_ANA_FB, 0, 0, &q, &q_dft ); + stereo_dft_dec_analyze_fx( hCPE, output[0], DFT, 0, output_frame, output_frame, DFT_STEREO_DEC_ANA_FB, 0, 0, &q, &q_dft[0] ); + stereo_dft_dec_analyze_fx( hCPE, output[1], DFT, 1, output_frame, output_frame, DFT_STEREO_DEC_ANA_FB, 0, 0, &q, &q_dft[0] ); hStereoDft->core_hist[0] = hCPE->hCoreCoder[0]->core; move16(); } @@ -1155,7 +1194,7 @@ void ivas_sba_dirac_stereo_dec_fx( /* do DFT Stereo core switching (including DFT analysis) here as CPE element was not available in SCE decoder */ Copy32( hSCE->save_synth_fx, tmp_synth, hSCE->hCoreCoder[0]->L_frame ); - stereo_dft_dec_core_switching_fx( hCPE, output[0] /*hSCE->save_output*/, hSCE->save_synth_fx, hSCE->save_hb_synth_fx, DFT, output_frame, 0, dtx_flag, &q, &q_dft ); + stereo_dft_dec_core_switching_fx( hCPE, output[0] /*hSCE->save_output*/, hSCE->save_synth_fx, hSCE->save_hb_synth_fx, DFT, output_frame, 0, dtx_flag, &q, &q_dft[0] ); /* do updates here after skipping this in SCE decoder (needs to be done after core switching) */ ivas_updt_dec_common_fx( hSCE->hCoreCoder[0], NORMAL_HQ_CORE, -1, hSCE->save_synth_fx, q); @@ -1164,7 +1203,7 @@ void ivas_sba_dirac_stereo_dec_fx( /* mapping of DirAC parameters (azimuth, elevation, diffuseness) to DFT Stereo parameters (side gain, prediction gain) */ map_params_dirac_to_stereo( hStereoDft, st_ivas->hQMetaData, tmp_synth, DFT[0], st_ivas->ivas_format == MC_FORMAT, ( ( st_ivas->ivas_format != SBA_FORMAT && st_ivas->ivas_format != SBA_ISM_FORMAT ) || mcmasa ) ? hSCE->hCoreCoder[0]->L_frame : output_frame, - ( ( st_ivas->ivas_format != SBA_FORMAT && st_ivas->ivas_format != SBA_ISM_FORMAT ) || mcmasa ), q_dft ); + ( ( st_ivas->ivas_format != SBA_FORMAT && st_ivas->ivas_format != SBA_ISM_FORMAT ) || mcmasa )); IF ( (EQ_32( st_ivas->ivas_format , SBA_FORMAT) || EQ_32(st_ivas->ivas_format , SBA_ISM_FORMAT) ) && !mcmasa ) { @@ -1226,4 +1265,4 @@ void ivas_sba_dirac_stereo_dec_fx( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index ee8d7d19ac4a168991ee85659cf2e53b7efa38a3..9f33c23b4ae88a3341effa093ea9cbe44ea2d248 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -151,6 +151,8 @@ ivas_error ivas_spar_md_dec_matrix_open( } } } + hMdDec->mix_mat_dim_0_1 = num_channels; + hMdDec->mix_mat_dim_2 = num_md_sub_frames * IVAS_MAX_NUM_BANDS; #endif #ifdef IVAS_FLOAT_FIXED if ( ( hMdDec->spar_coeffs.C_re_fx = (Word32 ***) malloc( num_channels * sizeof(Word32 ** ) ) ) == NULL ) diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index a748116f40df8a2700448e72ea2d8ee092ff141b..19a7404063b8461fa7e7bc4c464a2edccd7d97ca 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -213,6 +213,7 @@ typedef struct stereo_dft_dec_data_struct Word16 bpf_error_ratio_mem_fx; Word16 q_dft; Word16 q_ip_mem; + Word16 q_ap_delay_mem_fx; Word16 q_smoothed_nrg; Word16 q_DFT_past_DMX_fx[STEREO_DFT_PAST_MAX]; Word32 res_global_gain_fx; @@ -307,6 +308,7 @@ typedef struct stereo_dft_dec_data_struct Word32 past_dmx_nrg_fx; Word32 smooth_buf_fx[SBA_DIRAC_STEREO_NUM_BANDS][SBA_DIRAC_NRG_SMOOTH_LONG + 1]; Word16 smooth_fac_fx[NB_DIV][SBA_DIRAC_STEREO_NUM_BANDS]; + Word16 q_smooth_buf_fx; Word16 q_hb_nrg; Word16 q_hb_nrg_subr; #endif @@ -839,6 +841,8 @@ typedef struct ivas_spar_md_dec_state_t #ifdef IVAS_FLOAT_FIXED Word32 ***mixer_mat_fx; Word32 mixer_mat_prev_fx[MAX_PARAM_SPATIAL_SUBFRAMES + 1][IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH][IVAS_MAX_NUM_BANDS]; + Word16 mix_mat_dim_0_1; + Word16 mix_mat_dim_2; #endif } ivas_spar_md_dec_state_t; @@ -984,6 +988,7 @@ typedef struct cpe_dec_data_structure Word32 prev_hb_synth_fx[CPE_CHANNELS][NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS )]; Word32 prev_synth_fx[CPE_CHANNELS][NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS )]; + Word32 q_prev_synth_fx; Word32 *input_mem_fx[CPE_CHANNELS]; Word32 *input_mem_LB_fx[CPE_CHANNELS]; diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index e5e3ea8ef1797e80c165685894087b9804981d34..6f812b4428ffc0bedcedfc068bceda23c45b470b 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -620,7 +620,7 @@ void stereo_dft_dec_synthesize_fx( Word16 ovl2, flat_portion_end; Word32 ola_buff[STEREO_DFT32MS_OVL2_MAX]; Word16 moffset; - //Word16 scale_dft; + Word16 scale_dft; push_wmops( "DFT_synthesis" ); /*-----------------------------------------------------------------* @@ -2298,11 +2298,13 @@ void stereo_dft_generate_res_pred_fx( rev_nrg = L_shr(rev_nrg, shl(sub(hStereoDft->q_dft, hStereoDft->q_smoothed_nrg), 1)); dmx_nrg = L_shr(dmx_nrg, shl(sub(hStereoDft->q_dft, hStereoDft->q_smoothed_nrg), 1)); } +#if 1 ELSE IF (GT_16(hStereoDft->q_smoothed_nrg , hStereoDft->q_dft)) { hStereoDft->smooth_res_nrg_fx[b] = L_shr(hStereoDft->smooth_res_nrg_fx[b], shl(sub(hStereoDft->q_smoothed_nrg, hStereoDft->q_dft), 1)); hStereoDft->smooth_dmx_nrg_fx[b] = L_shr(hStereoDft->smooth_dmx_nrg_fx[b], shl(sub(hStereoDft->q_smoothed_nrg, hStereoDft->q_dft), 1)); } +#endif /* smoothing */ hStereoDft->smooth_res_nrg_fx[b] = Madd_32_16(Mpy_32_16_1(hStereoDft->smooth_res_nrg_fx[b], alpha), rev_nrg, sub( (Word16)(0x7FFF), alpha )) ; move32(); @@ -2365,10 +2367,12 @@ void stereo_dft_generate_res_pred_fx( move32(); } } +#if 1 IF (GT_16(hStereoDft->q_smoothed_nrg , hStereoDft->q_dft)) { hStereoDft->q_smoothed_nrg = hStereoDft->q_dft; } +#endif } ELSE IF ( EQ_16(hStereoDft->res_pred_mode[k + STEREO_DFT_OFFSET], STEREO_DFT_RESPRED_STEFI) ) { @@ -2529,12 +2533,17 @@ void stereo_dft_generate_res_pred_fx( d_short_ind = add( d_short_ind , add(hStereoDft->past_DMX_pos , 1) ) & (STEREO_DFT_PAST_MAX - 1); /* calculate high band energy of past dmx */ - past_dmx_nrg = EPSILON_FIX; + //past_dmx_nrg = EPSILON_FIX; + past_dmx_nrg = 0; FOR ( i = bin0; i < s_min( shr(hStereoDft->NFFT , 1), STEREO_DFT32MS_N_32k / 2 ); i++ ) { past_dmx_nrg = L_add(past_dmx_nrg, Madd_32_32(Mpy_32_32(hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i] , hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i]) , hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i + 1] , hStereoDft->DFT_past_DMX_fx[d_short_ind][2 * i + 1])); } past_dmx_nrg = L_shl(past_dmx_nrg, shl(sub(hStereoDft->q_dft, hStereoDft->q_DFT_past_DMX_fx[d_short_ind]), 1)); + IF (EQ_32(past_dmx_nrg, 0)) + { + past_dmx_nrg = EPSILON_FX; + } FOR ( b = band0; b < nbands_respred; b++ ) { diff --git a/lib_dec/ivas_stereo_esf_dec.c b/lib_dec/ivas_stereo_esf_dec.c index 7b47b6f2ce7af4892f05a2ef8c695fd32ee88150..fee9f26f434899797aa10fce4429068490de1e6f 100644 --- a/lib_dec/ivas_stereo_esf_dec.c +++ b/lib_dec/ivas_stereo_esf_dec.c @@ -139,7 +139,8 @@ void filter_with_allpass_fx( const Word32 *sig, Word32 *out, const Word16 len, - basic_allpass_t *ap) + basic_allpass_t *ap, + Word16 q_shift) { Word16 k; Word16 pos, mask; @@ -164,6 +165,16 @@ void filter_with_allpass_fx( D2_fx = ap->buffer_fx[1]; D3_fx = ap->buffer_fx[2]; + IF (NE_16(q_shift, 0)) + { + FOR (k = 0; k < sizeof(ap->buffer_fx[0]) / sizeof(ap->buffer_fx[0][0]); k++) + { + D1_fx[k] = L_shr(D1_fx[k], q_shift); + D2_fx[k] = L_shr(D2_fx[k], q_shift); + D3_fx[k] = L_shr(D3_fx[k], q_shift); + } + } + Word32 D1_upd = pos + d1, D2_upd = pos + d2, D3_upd = pos + d3; FOR( k = 0; k <= mask; k++ ) diff --git a/lib_dec/ivas_stereo_mdct_core_dec_fx.c b/lib_dec/ivas_stereo_mdct_core_dec_fx.c index 9ee0c65ba1480b4f4958daaad0b9205efa46098f..791c9099694be65790c0bebc1c3a4ba82d8c67cf 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec_fx.c +++ b/lib_dec/ivas_stereo_mdct_core_dec_fx.c @@ -594,9 +594,101 @@ void stereo_mdct_core_dec_fx( { stereo_decoder_tcx( hCPE->hStereoMdct, ms_mask, x_0[1], x[0], x[1], &hCPE->hStereoMdct->mdct_stereo_mode[0], sts[0]->core, sts[1]->core, sts[0]->igf, L_frameTCX[0], L_frameTCX[1], 0, sts[0]->last_core, sts[1]->last_core, 0 ); } - - ivas_mdct_core_tns_ns( hCPE, fUseTns, tnsData, x, Aq, 0 ); - + { +#ifdef IVAS_FLOAT_FIXED +#if 1 /*Float to fixed conversion*/ + Word32 Aq_fx[2][102]; + Word16 x_e[2][2]; + Word32 *x_fx[CPE_CHANNELS][NB_DIV]; + FOR( Word16 ind = 0; ind < 2; ind++ ) + { + FOR( Word16 ind2 = 0; ind2 < 102; ind2++ ) + { + Aq_fx[ind][ind2] = (Word32) ( Aq[ind][ind2] * ( ONE_IN_Q16 ) ); + } + FOR( Word16 ind2 = 0; ind2 < NB_DIV; ind2++ ) + { + x_fx[ind][ind2] = (Word32 *) malloc( sizeof( Word32 ) * N_MAX ); + } + f2me_buf( x[ind][0], x_fx[ind][0], &x_e[ind][0], 1200 ); + f2me_buf( x[ind][1], x_fx[ind][1], &x_e[ind][1], 600 ); + } + for ( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + st = sts[ch]; + st->hTcxDec->cummulative_damping_tcx = (Word16) ( st->hTcxDec->cummulative_damping_tcx_float * ( ONE_IN_Q15 ) ); + IF( st->hTonalMDCTConc ) + { + FOR( Word16 ind = 0; ind < st->hTonalMDCTConc->nScaleFactors; ind++ ) + { + f2me_16( st->hTonalMDCTConc->lastBlockData.scaleFactors_float[ind], &st->hTonalMDCTConc->lastBlockData.scaleFactors[ind], &st->hTonalMDCTConc->lastBlockData.scaleFactors_exp[ind] ); + } + FOR( Word16 i = 0; i < st->hTonalMDCTConc->nScaleFactors; i++ ) + { + st->hTonalMDCTConc->scaleFactorsBackground_fx[i] = float_to_fix( st->hTonalMDCTConc->scaleFactorsBackground_flt[i], 15 ); + } + st->hTonalMDCTConc->scf_fadeout = float_to_fix16( st->hTonalMDCTConc->scf_fadeout_flt, 15 ); + st->hTonalMDCTConc->lastPitchLag = float_to_fix( st->hTonalMDCTConc->lastPitchLag_float, Q16 ); + if ( sts[0]->bfi && st->tonal_mdct_plc_active ) + { + FOR( Word16 i = 0; i < FDNS_NPTS; i++ ) + { + f2me_16( st->hTonalMDCTConc->secondLastBlockData.scaleFactors_float[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i] ); + } + FOR( Word16 i = 0; i < st->hTonalMDCTConc->pTCI_float->numIndexes; i++ ) + { + float pd = st->hTonalMDCTConc->pTCI_float->phaseDiff_float[i]; + if ( pd >= PI2 ) + pd = fmodf( pd, PI2 ) - PI2; + st->hTonalMDCTConc->pTCI_fix->phaseDiff[i] = float_to_fix16( pd, Q12 ); + } + FOR( Word16 i = 0; i < MAX_NUMBER_OF_IDX * GROUP_LENGTH; i++ ) + { + float pd = st->hTonalMDCTConc->pTCI_float->phase_currentFramePredicted_float[i]; + pd = fmodf( pd, PI2 ); + st->hTonalMDCTConc->pTCI_fix->phase_currentFramePredicted[i] = (Word16) ( pd * ( 1u << Q13 ) ); + } + //st->hTonalMDCTConc->nFramesLost = float_to_fix16( st->hTonalMDCTConc->nFramesLost, Q1 ); + } + f2me( st->hTonalMDCTConc->last_block_nrg_flt, &st->hTonalMDCTConc->last_block_nrg, &st->hTonalMDCTConc->last_block_nrg_exp ); + } + st->old_fpitch = float_to_fix( st->old_fpitch_float, 16 ); + st->hTcxDec->tcxltp_last_gain_unmodified = float_to_fix16( st->hTcxDec->tcxltp_last_gain_unmodified_float, 15 ); + } +#endif // IVAS_FLOAT_FIXED + ivas_mdct_core_tns_ns_fx( hCPE, fUseTns, tnsData, x_fx, Aq_fx, 0, x_e ); +#if 1 /*Fixed to float conversions*/ + FOR( Word16 ind = 0; ind < 2; ind++ ) + { + me2f_buf( x_fx[ind][0], x_e[ind][0], x[ind][0], 1200 ); + me2f_buf( x_fx[ind][1], x_e[ind][1], x[ind][1], 600 ); + } + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + st = sts[ch]; + IF( st->hTonalMDCTConc != NULL ) + { + st->hTonalMDCTConc->scf_fadeout_flt = fixedToFloat( st->hTonalMDCTConc->scf_fadeout, 15 ); + st->hTonalMDCTConc->last_block_nrg_flt = me2f( st->hTonalMDCTConc->last_block_nrg, st->hTonalMDCTConc->last_block_nrg_exp ); + st->hTonalMDCTConc->lastPitchLag_float = fixedToFloat( st->hTonalMDCTConc->lastPitchLag, Q16 ); + if ( sts[0]->bfi && st->tonal_mdct_plc_active ) + { + st->hTonalMDCTConc->nFramesLost_float = fix16_to_float( st->hTonalMDCTConc->nFramesLost, Q1 ); + } + } + } + FOR( Word16 i = 0; i < CPE_CHANNELS; i++ ) + { + FOR( Word16 j = 0; j < NB_DIV; j++ ) + { + free( x_fx[i][j] ); + } + } +#endif +#else + ivas_mdct_core_tns_ns( hCPE, fUseTns, tnsData, x, Aq, 0 ); +#endif + } if ( st_ivas->renderer_type == RENDERER_MC_PARAMMC && ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO ) ) { ivas_ls_setup_conversion_process_mdct_param_mc( st_ivas, x ); diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index 3f840e6a70bde0aeb4b3a4d2a5f88b24e99b80e8..aa0fc5fb08df86320db5937730c84f5e17568c95 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -2626,6 +2626,7 @@ void synchro_synthesis_fixed( Word32 *output_fx[2]; Word32 op[2][L_FRAME48k]; + Word16 output_q = OUTPUT_Q; output_fx[0] = op[0]; output_fx[1] = op[1]; @@ -2633,7 +2634,7 @@ void synchro_synthesis_fixed( { FOR( Word32 k = 0; k < L_FRAME48k; k++ ) { - output_fx[n][k] = (Word32) ( output[n][k] * ( 1 << OUTPUT_Q ) ); + output_fx[n][k] = (Word32) ( output[n][k] * ( 1 << output_q ) ); } IF( hCPE->hStereoDft != NULL ) { @@ -2641,11 +2642,11 @@ void synchro_synthesis_fixed( { FOR( Word32 p = 0; p < L_FRAME48k; p++ ) { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] * ( 1u << OUTPUT_Q ) ); + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] * ( 1u << output_q ) ); } FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << OUTPUT_Q ) ); + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << output_q ) ); } hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15 ); hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain = (Word16) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); @@ -2657,11 +2658,11 @@ void synchro_synthesis_fixed( { FOR( Word32 p = 0; p < L_FRAME48k; p++ ) { - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] * ( 1u << OUTPUT_Q ) ); + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] * ( 1u << output_q ) ); } FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) { - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << OUTPUT_Q ) ); + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << output_q ) ); } hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15 ); hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain = (Word16) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); @@ -2669,17 +2670,17 @@ void synchro_synthesis_fixed( FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); k++ ) { - hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[k] = (Word32) ( hCPE->hCoreCoder[n]->prev_synth_buffer[k] * ( 1 << OUTPUT_Q ) ); + hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[k] = (Word32) ( hCPE->hCoreCoder[n]->prev_synth_buffer[k] * ( 1 << output_q ) ); } FOR( Word32 k = 0; k < HQ_DELTA_MAX * HQ_DELAY_COMP; k++ ) { - hCPE->hCoreCoder[n]->delay_buf_out32_fx[k] = (Word32) ( hCPE->hCoreCoder[n]->delay_buf_out[k] * ( 1 << OUTPUT_Q ) ); + hCPE->hCoreCoder[n]->delay_buf_out32_fx[k] = (Word32) ( hCPE->hCoreCoder[n]->delay_buf_out[k] * ( 1 << output_q ) ); } IF( hCPE->hCoreCoder[n]->hTcxDec != NULL ) { FOR( Word32 k = 0; k < 111; k++ ) { - hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] = (Word32) ( hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] * ( 1 << OUTPUT_Q ) ); + hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] = (Word32) ( hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] * ( 1 << output_q ) ); } } } @@ -2688,24 +2689,24 @@ void synchro_synthesis_fixed( { FOR( Word32 k = 0; k < NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ); k++ ) { - hCPE->output_mem_fx[n][k] = (Word32) ( hCPE->output_mem[n][k] * ( 1 << OUTPUT_Q ) ); + hCPE->output_mem_fx[n][k] = (Word32) ( hCPE->output_mem[n][k] * ( 1 << output_q ) ); } } IF( hCPE->input_mem[n] != NULL ) { FOR( Word32 ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) { - hCPE->input_mem_LB_fx[n][ind] = (Word32) ( hCPE->input_mem_LB[n][ind] * ( 1 << OUTPUT_Q ) ); + hCPE->input_mem_LB_fx[n][ind] = (Word32) ( hCPE->input_mem_LB[n][ind] * ( 1 << output_q ) ); } } FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) { - hCPE->prev_hb_synth_fx[n][k] = (Word32) ( hCPE->prev_hb_synth[n][k] * ( 1 << OUTPUT_Q ) ); + hCPE->prev_hb_synth_fx[n][k] = (Word32) ( hCPE->prev_hb_synth[n][k] * ( 1 << output_q ) ); } FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) { - hCPE->prev_synth_fx[n][k] = (Word32) ( hCPE->prev_synth[n][k] * ( 1 << OUTPUT_Q ) ); + hCPE->prev_synth_fx[n][k] = (Word32) ( hCPE->prev_synth[n][k] * ( 1 << output_q ) ); } } @@ -2933,11 +2934,11 @@ void synchro_synthesis_fixed( { FOR( Word32 p = 0; p < L_FRAME48k; p++ ) { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << OUTPUT_Q ); + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << output_q ); } FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << OUTPUT_Q ); + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << output_q ); } hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; @@ -2962,28 +2963,28 @@ void synchro_synthesis_fixed( { FOR( Word32 p = 0; p < L_FRAME48k; p++ ) { - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << OUTPUT_Q ); + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << output_q ); } FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) { - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << OUTPUT_Q ); + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << output_q ); } hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; } FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); k++ ) { - hCPE->hCoreCoder[n]->prev_synth_buffer[k] = (float) hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[k] / ( 1 << OUTPUT_Q ); + hCPE->hCoreCoder[n]->prev_synth_buffer[k] = (float) hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[k] / ( 1 << output_q ); } FOR( Word32 k = 0; k < HQ_DELTA_MAX * HQ_DELAY_COMP; k++ ) { - hCPE->hCoreCoder[n]->delay_buf_out[k] = (float) hCPE->hCoreCoder[n]->delay_buf_out32_fx[k] / ( 1 << OUTPUT_Q ); + hCPE->hCoreCoder[n]->delay_buf_out[k] = (float) hCPE->hCoreCoder[n]->delay_buf_out32_fx[k] / ( 1 << output_q ); } IF( hCPE->hCoreCoder[n]->hTcxDec != NULL ) { FOR( Word32 k = 0; k < 111; k++ ) { - hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] = (float) hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] / ( 1 << OUTPUT_Q ); + hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] = (float) hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] / ( 1 << output_q ); } } } @@ -2991,16 +2992,16 @@ void synchro_synthesis_fixed( { FOR( Word32 ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) { - hCPE->input_mem_LB[n][ind] = ( (float) hCPE->input_mem_LB_fx[n][ind] / ( 1 << OUTPUT_Q ) ); + hCPE->input_mem_LB[n][ind] = ( (float) hCPE->input_mem_LB_fx[n][ind] / ( 1 << output_q ) ); } } FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) { - hCPE->prev_hb_synth[n][k] = (float) hCPE->prev_hb_synth_fx[n][k] / ( 1 << OUTPUT_Q ); + hCPE->prev_hb_synth[n][k] = (float) hCPE->prev_hb_synth_fx[n][k] / ( 1 << output_q ); } FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) { - hCPE->prev_synth[n][k] = (float) hCPE->prev_synth_fx[n][k] / ( 1 << OUTPUT_Q ); + hCPE->prev_synth[n][k] = (float) hCPE->prev_synth_fx[n][k] / ( 1 << output_q ); } } #endif @@ -3262,11 +3263,11 @@ void synchro_synthesis_fixed( { FOR( Word32 p = 0; p < L_FRAME48k; p++ ) { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << OUTPUT_Q ); + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << output_q ); } FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << OUTPUT_Q ); + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << output_q ); } hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; @@ -3291,28 +3292,28 @@ void synchro_synthesis_fixed( { FOR( Word32 p = 0; p < L_FRAME48k; p++ ) { - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << OUTPUT_Q ); + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << output_q ); } FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) { - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << OUTPUT_Q ); + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << output_q ); } hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; } FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); k++ ) { - hCPE->hCoreCoder[n]->prev_synth_buffer[k] = (float) hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[k] / ( 1 << OUTPUT_Q ); + hCPE->hCoreCoder[n]->prev_synth_buffer[k] = (float) hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[k] / ( 1 << output_q ); } FOR( Word32 k = 0; k < HQ_DELTA_MAX * HQ_DELAY_COMP; k++ ) { - hCPE->hCoreCoder[n]->delay_buf_out[k] = (float) hCPE->hCoreCoder[n]->delay_buf_out32_fx[k] / ( 1 << OUTPUT_Q ); + hCPE->hCoreCoder[n]->delay_buf_out[k] = (float) hCPE->hCoreCoder[n]->delay_buf_out32_fx[k] / ( 1 << output_q ); } IF( hCPE->hCoreCoder[n]->hTcxDec != NULL ) { FOR( Word32 k = 0; k < 111; k++ ) { - hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] = (float) hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] / ( 1 << OUTPUT_Q ); + hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] = (float) hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] / ( 1 << output_q ); } } } @@ -3320,16 +3321,16 @@ void synchro_synthesis_fixed( { FOR( Word32 ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) { - hCPE->input_mem_LB[n][ind] = ( (float) hCPE->input_mem_LB_fx[n][ind] / ( 1 << OUTPUT_Q ) ); + hCPE->input_mem_LB[n][ind] = ( (float) hCPE->input_mem_LB_fx[n][ind] / ( 1 << output_q ) ); } } FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) { - hCPE->prev_hb_synth[n][k] = (float) hCPE->prev_hb_synth_fx[n][k] / ( 1 << OUTPUT_Q ); + hCPE->prev_hb_synth[n][k] = (float) hCPE->prev_hb_synth_fx[n][k] / ( 1 << output_q ); } FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) { - hCPE->prev_synth[n][k] = (float) hCPE->prev_synth_fx[n][k] / ( 1 << OUTPUT_Q ); + hCPE->prev_synth[n][k] = (float) hCPE->prev_synth_fx[n][k] / ( 1 << output_q ); } } @@ -3338,91 +3339,19 @@ void synchro_synthesis_fixed( } void synchro_synthesis_fixed_clean( - const Word16 ivas_total_brate, /* i : IVAS total bitrate */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 *output_fx[CPE_CHANNELS], /* i/o: output synthesis signal */ const Word16 output_frame, /* i : Number of samples */ const Word16 sba_dirac_stereo_flag /* i : signal stereo output FOR SBA DirAC */ ) { - - // Delete below - FOR( Word32 n = 0; n < CPE_CHANNELS; n++ ) + + Word16 output_q = OUTPUT_Q; + IF (hCPE->hStereoDft != NULL) { - IF( hCPE->hStereoDft != NULL ) - { - IF( hCPE->hStereoDft->hTcxLtpDec != NULL ) - { - FOR( Word32 p = 0; p < L_FRAME48k; p++ ) - { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] * ( 1u << OUTPUT_Q ) ); - } - FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) - { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << OUTPUT_Q ) ); - } - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15 ); - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain = (Word16) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); - } - } - IF( hCPE->hCoreCoder[n] != NULL ) - { - IF( hCPE->hCoreCoder[n]->hTcxLtpDec != NULL ) - { - FOR( Word32 p = 0; p < L_FRAME48k; p++ ) - { - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] * ( 1u << OUTPUT_Q ) ); - } - FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) - { - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << OUTPUT_Q ) ); - } - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15 ); - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain = (Word16) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); - } - - FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); k++ ) - { - hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[k] = (Word32) ( hCPE->hCoreCoder[n]->prev_synth_buffer[k] * ( 1 << OUTPUT_Q ) ); - } - FOR( Word32 k = 0; k < HQ_DELTA_MAX * HQ_DELAY_COMP; k++ ) - { - hCPE->hCoreCoder[n]->delay_buf_out32_fx[k] = (Word32) ( hCPE->hCoreCoder[n]->delay_buf_out[k] * ( 1 << OUTPUT_Q ) ); - } - IF( hCPE->hCoreCoder[n]->hTcxDec != NULL ) - { - FOR( Word32 k = 0; k < 111; k++ ) - { - hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] = (Word32) ( hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] * ( 1 << OUTPUT_Q ) ); - } - } - } - - IF( hCPE->output_mem[n] != NULL ) - { - FOR( Word32 k = 0; k < NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ); k++ ) - { - hCPE->output_mem_fx[n][k] = (Word32) ( hCPE->output_mem[n][k] * ( 1 << OUTPUT_Q ) ); - } - } - IF( hCPE->input_mem[n] != NULL ) - { - FOR( Word32 ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) - { - hCPE->input_mem_LB_fx[n][ind] = (Word32) ( hCPE->input_mem_LB[n][ind] * ( 1 << OUTPUT_Q ) ); - } - } - - FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) - { - hCPE->prev_hb_synth_fx[n][k] = (Word32) ( hCPE->prev_hb_synth[n][k] * ( 1 << OUTPUT_Q ) ); - } - FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) - { - hCPE->prev_synth_fx[n][k] = (Word32) ( hCPE->prev_synth[n][k] * ( 1 << OUTPUT_Q ) ); - } + output_q = hCPE->hStereoDft->q_dft; } - // till here Word16 n, delay_comp_TD, delay_comp_DFT; Word32 output_Fs; @@ -3534,13 +3463,14 @@ void synchro_synthesis_fixed_clean( { IF( sba_dirac_stereo_flag ) { - delay_signal_fx( output_fx[n], output_frame, hCPE->prev_synth_fx[n], delay_comp_DFT ); + delay_signal_q_adj_fx( output_fx[n], output_frame, hCPE->prev_synth_fx[n], delay_comp_DFT, hCPE->hStereoDft->q_dft, hCPE->q_prev_synth_fx ); } ELSE { delay_signal_fx( output_fx[n], output_frame, sts[n]->prev_synth_buffer32_fx, delay_comp_DFT ); } } + hCPE->q_prev_synth_fx = hCPE->hStereoDft->q_dft; IF( use_cldfb_for_last_dft ) { Copy32( hCPE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_32, sts[0]->prev_synth_buffer32_fx + delay_comp_DFT, delay_diff ); @@ -3640,83 +3570,6 @@ void synchro_synthesis_fixed_clean( IF( sba_dirac_stereo_flag ) { - // delete the below -#if 1 - IF( hCPE->hStereoDft != NULL ) - { - IF( hCPE->hStereoDft->hTcxLtpDec != NULL ) - { - FOR( Word32 p = 0; p < L_FRAME48k; p++ ) - { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << OUTPUT_Q ); - } - FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) - { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << OUTPUT_Q ); - } - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; - } - } - FOR( n = 0; n < CPE_CHANNELS; n++ ) - { - IF( hCPE->output_mem[n] != NULL ) - { - FOR( Word32 k = 0; k < NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ); k++ ) - { - hCPE->output_mem[n][k] = (float) hCPE->output_mem_fx[n][k] / ( 1u << 11 ); - } - } - IF( hCPE->hCoreCoder[n] != NULL ) - { - IF( hCPE->hCoreCoder[n]->hTcxLtpDec != NULL ) - { - FOR( Word32 p = 0; p < L_FRAME48k; p++ ) - { - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << OUTPUT_Q ); - } - FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) - { - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << OUTPUT_Q ); - } - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; - } - FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); k++ ) - { - hCPE->hCoreCoder[n]->prev_synth_buffer[k] = (float) hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[k] / ( 1 << OUTPUT_Q ); - } - FOR( Word32 k = 0; k < HQ_DELTA_MAX * HQ_DELAY_COMP; k++ ) - { - hCPE->hCoreCoder[n]->delay_buf_out[k] = (float) hCPE->hCoreCoder[n]->delay_buf_out32_fx[k] / ( 1 << OUTPUT_Q ); - } - IF( hCPE->hCoreCoder[n]->hTcxDec != NULL ) - { - FOR( Word32 k = 0; k < 111; k++ ) - { - hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] = (float) hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] / ( 1 << OUTPUT_Q ); - } - } - } - IF( hCPE->input_mem[n] != NULL ) - { - FOR( Word32 ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) - { - hCPE->input_mem_LB[n][ind] = ( (float) hCPE->input_mem_LB_fx[n][ind] / ( 1 << OUTPUT_Q ) ); - } - } - FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) - { - hCPE->prev_hb_synth[n][k] = (float) hCPE->prev_hb_synth_fx[n][k] / ( 1 << OUTPUT_Q ); - } - FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) - { - hCPE->prev_synth[n][k] = (float) hCPE->prev_synth_fx[n][k] / ( 1 << OUTPUT_Q ); - } - } -#endif - - // keep return return; } @@ -3973,11 +3826,11 @@ void synchro_synthesis_fixed_clean( { FOR( Word32 p = 0; p < L_FRAME48k; p++ ) { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << OUTPUT_Q ); + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << output_q ); } FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << OUTPUT_Q ); + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << output_q ); } hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; @@ -3998,28 +3851,28 @@ void synchro_synthesis_fixed_clean( { FOR( Word32 p = 0; p < L_FRAME48k; p++ ) { - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << OUTPUT_Q ); + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << output_q ); } FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) { - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << OUTPUT_Q ); + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << output_q ); } hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; } FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); k++ ) { - hCPE->hCoreCoder[n]->prev_synth_buffer[k] = (float) hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[k] / ( 1 << OUTPUT_Q ); + hCPE->hCoreCoder[n]->prev_synth_buffer[k] = (float) hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[k] / ( 1 << output_q ); } FOR( Word32 k = 0; k < HQ_DELTA_MAX * HQ_DELAY_COMP; k++ ) { - hCPE->hCoreCoder[n]->delay_buf_out[k] = (float) hCPE->hCoreCoder[n]->delay_buf_out32_fx[k] / ( 1 << OUTPUT_Q ); + hCPE->hCoreCoder[n]->delay_buf_out[k] = (float) hCPE->hCoreCoder[n]->delay_buf_out32_fx[k] / ( 1 << output_q ); } IF( hCPE->hCoreCoder[n]->hTcxDec != NULL ) { FOR( Word32 k = 0; k < 111; k++ ) { - hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] = (float) hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] / ( 1 << OUTPUT_Q ); + hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] = (float) hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] / ( 1 << output_q ); } } } @@ -4027,16 +3880,16 @@ void synchro_synthesis_fixed_clean( { FOR( Word32 ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) { - hCPE->input_mem_LB[n][ind] = ( (float) hCPE->input_mem_LB_fx[n][ind] / ( 1 << OUTPUT_Q ) ); + hCPE->input_mem_LB[n][ind] = ( (float) hCPE->input_mem_LB_fx[n][ind] / ( 1 << output_q ) ); } } FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) { - hCPE->prev_hb_synth[n][k] = (float) hCPE->prev_hb_synth_fx[n][k] / ( 1 << OUTPUT_Q ); + hCPE->prev_hb_synth[n][k] = (float) hCPE->prev_hb_synth_fx[n][k] / ( 1 << output_q ); } FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) { - hCPE->prev_synth[n][k] = (float) hCPE->prev_synth_fx[n][k] / ( 1 << OUTPUT_Q ); + hCPE->prev_synth[n][k] = (float) hCPE->prev_synth_fx[n][k] / ( 1 << output_q ); } } diff --git a/lib_dec/updt_dec_fx.c b/lib_dec/updt_dec_fx.c index 2c52affbd7d9709a3499c419b55d847bbbe39dd8..27c4f551c8a772057a56455bc5cede3d82a92cd0 100644 --- a/lib_dec/updt_dec_fx.c +++ b/lib_dec/updt_dec_fx.c @@ -753,7 +753,7 @@ static void ivas_updt_bw_switching_fx( IF(st_fx->output_Fs == 32000 && st_fx->bwidth == SWB) { #ifdef BASOP_NOGLOB - st_fx->tilt_swb_fx = round_fx_sat(L_shl_sat(ivas_calc_tilt_bwe_fx(synth, Qpost, L_FRAME32k), 3)); + st_fx->tilt_swb_fx = ivas_calc_tilt_bwe_fx(synth, Qpost, L_FRAME32k); #else st_fx->tilt_swb_fx = round_fx(L_shl(calc_tilt_bwe_fx(synth, Qpost, L_FRAME32k), 3)); #endif