From 7b0fd2a0e24f7b2e21a8a1d1e0a5fddd83c760ed Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Sun, 11 Feb 2024 11:18:56 +0530 Subject: [PATCH] Functions in ivas_omasa_dec.c converted to fixed point. [x] Ported ivas_omasa_data_open, ivas_omasa_data_close, ivas_dirac_dec_binaural_internal(partial), generate_masking_noise_dirac, ivas_combined_orientation_update_index, resampleCldfb_ivas, rand_gauss, v_multc_32_16_fixed, generate_masking_noise_dirac functions --- lib_com/cldfb.c | 432 +++++++++++++++---- lib_com/fd_cng_com.c | 18 + lib_com/ivas_rom_com_fx.c | 8 + lib_com/ivas_rom_com_fx.h | 1 + lib_com/prot_fx2.h | 51 ++- lib_com/rom_com.c | 34 +- lib_com/stat_com.h | 5 +- lib_dec/fd_cng_dec.c | 120 ++++++ lib_dec/ivas_omasa_dec.c | 146 ++++++- lib_dec/ivas_spar_decoder.c | 10 +- lib_dec/ivas_stat_dec.h | 5 + lib_rend/ivas_dirac_dec_binaural_functions.c | 361 +++++++++++++++- lib_rend/ivas_prot_rend.h | 7 + lib_rend/ivas_rotation.c | 32 ++ 14 files changed, 1106 insertions(+), 124 deletions(-) diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index e35a5cbfe..c8ac7e4a2 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -689,11 +689,12 @@ void cldfbAnalysis_ts_ivas( #ifdef IVAS_FLOAT_FIXED void cldfbAnalysis_ts_fx( - const Word32 *timeIn_fx, /* i : time buffer */ // q = 27 - Word32 realBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : real value buffer */ // q = 23 - Word32 imagBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : imag value buffer */ // q = 23 + const Word32 *timeIn_fx, /* i : time buffer */ // q + Word32 realBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : real value buffer */ // q - 5 + Word32 imagBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : imag value buffer */ // q - 5 const Word16 samplesToProcess, /* i : samples to process */ - HANDLE_CLDFB_FILTER_BANK h_cldfb /* i : filterbank state */ + HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i : filterbank state */ + Word16* q_cldfb ) { Word16 i, k; @@ -760,115 +761,358 @@ void cldfbAnalysis_ts_fx( for ( k = 0; k < M4; k++ ) { /* prototype filter */ - r1_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )])); // q = 27 - r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )])); // q = 27 - r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )])); // q = 27 - r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )])); // q = 27 - r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )])); // q = 27 - - r2_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 0 * L2 )])); // q = 27 - r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 1 * L2 )])); // q = 27 - r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 2 * L2 )])); // q = 27 - r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 3 * L2 )])); // q = 27 - r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 4 * L2 )])); // q = 27 - - i1_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )])); // q = 27 - i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )])); // q = 27 - i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )])); // q = 27 - i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )])); // q = 27 - i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )])); // q = 27 - - i2_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2 )])); // q = 27 - i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2 )])); // q = 27 - i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2 )])); // q = 27 - i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2 )])); // q = 27 - i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2 )])); // q = 27 + r1_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )])); // q + r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )])); // q + r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )])); // q + r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )])); // q + r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )])); // q + + r2_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 0 * L2 )])); // q + r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 1 * L2 )])); // q + r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 2 * L2 )])); // q + r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 3 * L2 )])); // q + r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 4 * L2 )])); // q + + i1_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )])); // q + i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )])); // q + i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )])); // q + i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )])); // q + i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )])); // q + + i2_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2 )])); // q + i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2 )])); // q + i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2 )])); // q + i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2 )])); // q + i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2 )])); // q - r1_fx = Mpy_32_16_1(r1_fx, ptr_pf_sf); - r2_fx = Mpy_32_16_1(r2_fx, ptr_pf_sf); - i1_fx = Mpy_32_16_1(i1_fx, ptr_pf_sf); - i2_fx = Mpy_32_16_1(i2_fx, ptr_pf_sf); + r1_fx = Mpy_32_16_1(r1_fx, ptr_pf_sf); // q - 1 + r2_fx = Mpy_32_16_1(r2_fx, ptr_pf_sf); // q - 1 + i1_fx = Mpy_32_16_1(i1_fx, ptr_pf_sf); // q - 1 + i2_fx = Mpy_32_16_1(i2_fx, ptr_pf_sf); // q - 1 /* folding + pre modulation of DST IV */ - rr12_fx = L_sub( r1_fx, r2_fx ); // q = 27 - ri12_fx = L_negate( L_add( i1_fx, i2_fx ) ); // q = 27 + rr12_fx = L_sub( r1_fx, r2_fx ); // q -1 + ri12_fx = L_negate( L_add( i1_fx, i2_fx ) ); // q - 1 /*cplxMult(&rBuffer[2*k],&rBuffer[2*k+1],rr12,ri12,rot_vctr_re[k],rot_vctr_im[k]);*/ - rBuffer_fx[2 * k] = L_sub(Mpy_32_32(rr12_fx, rot_vctr_re_fx[k]), Mpy_32_32(ri12_fx, rot_vctr_im_fx[k])); // q = 25 - rBuffer_fx[2 * k + 1] = L_add(Mpy_32_32(rr12_fx, rot_vctr_im_fx[k]), Mpy_32_32(ri12_fx, rot_vctr_re_fx[k])); // q = 25 + rBuffer_fx[2 * k] = L_sub(Mpy_32_32(rr12_fx, rot_vctr_re_fx[k]), Mpy_32_32(ri12_fx, rot_vctr_im_fx[k])); // q - 3 + rBuffer_fx[2 * k + 1] = L_add(Mpy_32_32(rr12_fx, rot_vctr_im_fx[k]), Mpy_32_32(ri12_fx, rot_vctr_re_fx[k])); // q - 3 ///* folding + pre modulation of DCT IV */ - ir12_fx = L_add(r1_fx, r2_fx); // q = 27 - ii12_fx = L_sub(i1_fx, i2_fx); // q = 27 + ir12_fx = L_add(r1_fx, r2_fx); // q - 1 + ii12_fx = L_sub(i1_fx, i2_fx); // q - 1 /*cplxMult(&iBuffer[2*k],&iBuffer[2*k+1],ir12,ii12,rot_vctr_re[k],rot_vctr_im[k]);*/ - iBuffer_fx[2 * k] = L_sub(Mpy_32_32(ir12_fx, rot_vctr_re_fx[k]), Mpy_32_32(ii12_fx, rot_vctr_im_fx[k])); // q = 25 - iBuffer_fx[2 * k + 1] = L_add(Mpy_32_32(ir12_fx, rot_vctr_im_fx[k]), Mpy_32_32(ii12_fx, rot_vctr_re_fx[k])); // q = 25 + iBuffer_fx[2 * k] = L_sub(Mpy_32_32(ir12_fx, rot_vctr_re_fx[k]), Mpy_32_32(ii12_fx, rot_vctr_im_fx[k])); // q - 3 + iBuffer_fx[2 * k + 1] = L_add(Mpy_32_32(ir12_fx, rot_vctr_im_fx[k]), Mpy_32_32(ii12_fx, rot_vctr_re_fx[k])); // q - 3 } for ( k = M4; k < M2; k++ ) { /* prototype filter */ - r1_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )])); // q = 27 - r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )])); // q = 27 - r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )])); // q = 27 - r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )])); // q = 27 - r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )])); // q = 27 - - r2_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 0 * L2 )])); // q = 27 - r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 1 * L2 )])); // q = 27 - r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 2 * L2 )])); // q = 27 - r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 3 * L2 )])); // q = 27 - r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 4 * L2 )])); // q = 27 - - i1_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )])); // q = 27 - i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )])); // q = 27 - i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )])); // q = 27 - i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )])); // q = 27 - i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )])); // q = 27 - - i2_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )])); // q = 27 - i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )])); // q = 27 - i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )])); // q = 27 - i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )])); // q = 27 - i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )])); // q = 27 - - r1_fx = Mpy_32_16_1(r1_fx, ptr_pf_sf); - r2_fx = Mpy_32_16_1(r2_fx, ptr_pf_sf); - i1_fx = Mpy_32_16_1(i1_fx, ptr_pf_sf); - i2_fx = Mpy_32_16_1(i2_fx, ptr_pf_sf); + r1_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )])); // q + r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )])); // q + r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )])); // q + r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )])); // q + r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )])); // q + + r2_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 0 * L2 )])); // q + r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 1 * L2 )])); // q + r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 2 * L2 )])); // q + r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 3 * L2 )])); // q + r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 4 * L2 )])); // q + + i1_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )])); // q + i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )])); // q + i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )])); // q + i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )])); // q + i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )])); // q + + i2_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )])); // q + i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )])); // q + i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )])); // q + i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )])); // q + i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )])); // q + + r1_fx = Mpy_32_16_1(r1_fx, ptr_pf_sf); // q - 1 + r2_fx = Mpy_32_16_1(r2_fx, ptr_pf_sf); // q - 1 + i1_fx = Mpy_32_16_1(i1_fx, ptr_pf_sf); // q - 1 + i2_fx = Mpy_32_16_1(i2_fx, ptr_pf_sf); // q - 1 /* folding + pre modulation of DST IV */ - rr12_fx = L_add(r1_fx, r2_fx); // q = 27 - ri12_fx = L_sub(i1_fx, i2_fx); // q = 27 + rr12_fx = L_add(r1_fx, r2_fx); // q - 1 + ri12_fx = L_sub(i1_fx, i2_fx); // q - 1 /*cplxMult(&rBuffer[2*k],&rBuffer[2*k+1],rr12,ri12,rot_vctr_re[k],rot_vctr_im[k]);*/ - rBuffer_fx[2 * k] = L_sub(Mpy_32_32(rr12_fx, rot_vctr_re_fx[k]), Mpy_32_32(ri12_fx, rot_vctr_im_fx[k])); // q = 25 - rBuffer_fx[2 * k + 1] = L_add(Mpy_32_32(rr12_fx, rot_vctr_im_fx[k]), Mpy_32_32(ri12_fx, rot_vctr_re_fx[k])); // q = 25 + rBuffer_fx[2 * k] = L_sub(Mpy_32_32(rr12_fx, rot_vctr_re_fx[k]), Mpy_32_32(ri12_fx, rot_vctr_im_fx[k])); // q - 3 + rBuffer_fx[2 * k + 1] = L_add(Mpy_32_32(rr12_fx, rot_vctr_im_fx[k]), Mpy_32_32(ri12_fx, rot_vctr_re_fx[k])); // q - 3 /* folding + pre modulation of DCT IV */ - ir12_fx = L_sub(r1_fx, r2_fx); // q = 27 - ii12_fx = L_add(i1_fx, i2_fx); // q = 27 + ir12_fx = L_sub(r1_fx, r2_fx); // q - 1 + ii12_fx = L_add(i1_fx, i2_fx); // q - 1 /*cplxMult(&iBuffer[2*k],&iBuffer[2*k+1],ir12,ii12,rot_vctr_re[k],rot_vctr_im[k]);*/ - iBuffer_fx[2 * k] = L_sub(Mpy_32_32(ir12_fx, rot_vctr_re_fx[k]), Mpy_32_32(ii12_fx, rot_vctr_im_fx[k])); // q = 25 - iBuffer_fx[2 * k + 1] = L_add(Mpy_32_32(ir12_fx, rot_vctr_im_fx[k]), Mpy_32_32(ii12_fx, rot_vctr_re_fx[k])); // q = 25 + iBuffer_fx[2 * k] = L_sub(Mpy_32_32(ir12_fx, rot_vctr_re_fx[k]), Mpy_32_32(ii12_fx, rot_vctr_im_fx[k])); // q - 3 + iBuffer_fx[2 * k + 1] = L_add(Mpy_32_32(ir12_fx, rot_vctr_im_fx[k]), Mpy_32_32(ii12_fx, rot_vctr_re_fx[k])); // q - 3 } + + *q_cldfb = sub(*q_cldfb, 3); /* FFT of DST IV */ Word16 q_shift; - q_shift = L_norm_arr(rBuffer_fx, 2 * CLDFB_NO_CHANNELS_MAX) - find_guarded_bits_fx(M2); + q_shift = sub(s_min(getScaleFactor32(rBuffer_fx, 2 * CLDFB_NO_CHANNELS_MAX), getScaleFactor32(iBuffer_fx, 2 * CLDFB_NO_CHANNELS_MAX)), find_guarded_bits_fx(M2)); + *q_cldfb = add(*q_cldfb, q_shift); for (Word16 ind = 0; ind < 2 * CLDFB_NO_CHANNELS_MAX; ind++) { rBuffer_fx[ind] = L_shl(rBuffer_fx[ind], q_shift); } + for (Word16 ind = 0; ind < 2 * CLDFB_NO_CHANNELS_MAX; ind++) { + iBuffer_fx[ind] = L_shl(iBuffer_fx[ind], q_shift); + } fft_cldfb_fx( rBuffer_fx, M2 ); + + /* post modulation of DST IV */ + for ( k = 0; k < M2; k++ ) + { + /*cplxMult(&realBuffer[M1-1-(2*k)],&realBuffer[2*k],rBuffer[2*k],rBuffer[2*k+1],rot_vctr_re[k],rot_vctr_im[k]);*/ + realBuffer_fx[M1 - 1 - ( 2 * k )] = L_sub(Mpy_32_32(rBuffer_fx[2 * k], rot_vctr_re_fx[k]), Mpy_32_32(rBuffer_fx[2 * k + 1], rot_vctr_im_fx[k])); // q - 5 + realBuffer_fx[2 * k] = L_add(Mpy_32_32(rBuffer_fx[2 * k], rot_vctr_im_fx[k]), Mpy_32_32(rBuffer_fx[2 * k + 1], rot_vctr_re_fx[k])); // q - 5 + } + *q_cldfb = sub(*q_cldfb, 2); + + /* FFT of DCT IV */ + fft_cldfb_fx( iBuffer_fx, M2 ); + + q_shift = s_min(getScaleFactor32(rBuffer_fx, 2 * CLDFB_NO_CHANNELS_MAX), getScaleFactor32(iBuffer_fx, 2 * CLDFB_NO_CHANNELS_MAX)); + *q_cldfb = add(*q_cldfb, q_shift); + for (Word16 ind = 0; ind < 2 * CLDFB_NO_CHANNELS_MAX; ind++) { + rBuffer_fx[ind] = L_shl(rBuffer_fx[ind], q_shift); + } for (Word16 ind = 0; ind < 2 * CLDFB_NO_CHANNELS_MAX; ind++) { - rBuffer_fx[ind] = L_shr(rBuffer_fx[ind], q_shift); + iBuffer_fx[ind] = L_shl(iBuffer_fx[ind], q_shift); + } + + /* post modulation of DCT IV */ + for ( k = 0; k < M2; k++ ) + { + /* do it inplace */ + /*cplxMult(&imagBuffer[2*k],&imagBuffer[M1-1-(2*k)],iBuffer[2*k],iBuffer[2*k+1],rot_vctr_re[k],rot_vctr_im[k]);*/ + imagBuffer_fx[2 * k] = L_sub(Mpy_32_32(iBuffer_fx[2 * k], rot_vctr_re_fx[k]), Mpy_32_32(iBuffer_fx[2 * k + 1], rot_vctr_im_fx[k])); // q - 5 + imagBuffer_fx[M1 - 1 - ( 2 * k )] = L_add(Mpy_32_32(iBuffer_fx[2 * k], rot_vctr_im_fx[k]), Mpy_32_32(iBuffer_fx[2 * k + 1], rot_vctr_re_fx[k])); // q - 5 + } + + if ( h_cldfb->prototype == CLDFB_PROTOTYPE_5_00MS ) + { + /* rotation due to delay*/ + /*if(h_cldfb->da != M1)*/ + if ( rot_vctr_delay_re_fx != NULL ) + { + for ( k = 0; k < M1; k++ ) + { + Word32 cplx_aux_fx; + /* delay */ + /*cplxMult(&rBuffer[k], &iBuffer[k], realBuffer[i][k], imagBuffer[i][k], cos((EVS_PI/M1)*(k+0.5)*((h_cldfb->da-M1)*0.5)), + sin((EVS_PI/M1)*(k+0.5)*((h_cldfb->da-M1)*0.5)));*/ + /*cplxMult(&rBuffer[k], &iBuffer[k], realBuffer[k], imagBuffer[k], rot_vctr_delay_re[k], rot_vctr_delay_im[k]);*/ + /*cplxMult(&realBuffer[k], &imagBuffer[k], realBuffer[k], imagBuffer[k], rot_vctr_delay_re[k], rot_vctr_delay_im[k]);*/ + /*realBuffer[k] = rBuffer[k]; + imagBuffer[k] = iBuffer[k];*/ + cplx_aux_fx = L_sub(Mpy_32_32(realBuffer_fx[k], rot_vctr_delay_re_fx[k]), Mpy_32_32(imagBuffer_fx[k], rot_vctr_delay_im_fx[k])); // q - 5 + imagBuffer_fx[k] = L_add(Mpy_32_32(realBuffer_fx[k], rot_vctr_delay_im_fx[k]), Mpy_32_32(imagBuffer_fx[k], rot_vctr_delay_re_fx[k])); // q - 5 + realBuffer_fx[k] = cplx_aux_fx; + } + } + } + + timeBuffer_fx += L2 * 5; + timeBuffer_fx += h_cldfb->no_channels - h_cldfb->p_filter_length; + } + + /* update memory */ + if ( samplesToProcess > -1 ) + { + Copy32( buffer_fx + samplesToProcess, h_cldfb->cldfb_state_fx, offset ); + } + else + { + Copy32( buffer_fx + frameSize, h_cldfb->cldfb_state_fx, offset ); + } + + return; +} + +void cldfbAnalysis_ts_fx_fixed_q( + const Word32 *timeIn_fx, /* i : time buffer */ // q + Word32 realBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : real value buffer */ // q - 5 + Word32 imagBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : imag value buffer */ // q - 5 + const Word16 samplesToProcess, /* i : samples to process */ + HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i : filterbank state */ + Word16* q_cldfb +) +{ + Word16 i, k; + Word16 L2, M1, M2, M4; + Word16 no_col = h_cldfb->no_col; + + Word32 r1_fx, r2_fx, rr12_fx, ir12_fx; + Word32 i1_fx, i2_fx, ri12_fx, ii12_fx; + Word32 rBuffer_fx[2 * CLDFB_NO_CHANNELS_MAX]; + Word32 iBuffer_fx[2 * CLDFB_NO_CHANNELS_MAX]; + const Word32 *rot_vctr_re_fx; + const Word32 *rot_vctr_im_fx; + const Word32 *rot_vctr_delay_re_fx; + const Word32 *rot_vctr_delay_im_fx; + const Word16 *ptr_pf_fx; + Word16 ptr_pf_sf; + Word32 *timeBuffer_fx, buffer_fx[( CLDFB_NO_CHANNELS_MAX * CLDFB_NO_COL_MAX ) + ( 9 * CLDFB_NO_CHANNELS_MAX )]; + Word16 offset, frameSize; + + offset = h_cldfb->p_filter_length - h_cldfb->no_channels; + frameSize = h_cldfb->no_channels * h_cldfb->no_col; + + /* prepare input buffer */ + timeBuffer_fx = buffer_fx; + Copy32( h_cldfb->cldfb_state_fx, timeBuffer_fx, offset ); + + if ( samplesToProcess > -1 ) + { + Copy32( timeIn_fx, timeBuffer_fx + offset, samplesToProcess ); + set32_fx( timeBuffer_fx + offset + samplesToProcess, 0, ( frameSize - samplesToProcess ) ); + } + else + { + Copy32( timeIn_fx, timeBuffer_fx + offset, frameSize ); + } + + /* only process needed cols */ + if ( samplesToProcess > -1 ) + { + no_col = min( no_col, ( samplesToProcess + h_cldfb->no_channels - 1 ) / h_cldfb->no_channels ); + assert( no_col == 1 ); + } + + M1 = h_cldfb->no_channels; + M2 = M1 >> 1; + M4 = M1 >> 2; + L2 = M1 << 1; + + if ( M2 & 1 ) + { + M4 += 1; + } + + rot_vctr_re_fx = h_cldfb->rot_vec_ana_re_fx; // q = 29 + rot_vctr_im_fx = h_cldfb->rot_vec_ana_im_fx; // q = 29 + rot_vctr_delay_re_fx = h_cldfb->rot_vec_ana_delay_re_fx; // q = 31 + rot_vctr_delay_im_fx = h_cldfb->rot_vec_ana_delay_im_fx; // q = 31 + + ptr_pf_fx = h_cldfb->p_filter; + ptr_pf_sf = h_cldfb->p_filter_sf; + + for ( i = 0; i < no_col; i++ ) + { + for ( k = 0; k < M4; k++ ) + { + /* prototype filter */ + r1_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )])); // q + r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )])); // q + r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )])); // q + r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )])); // q + r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )])); // q + + r2_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 0 * L2 )])); // q + r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 1 * L2 )])); // q + r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 2 * L2 )])); // q + r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 3 * L2 )])); // q + r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 4 * L2 )])); // q + + i1_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )])); // q + i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )])); // q + i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )])); // q + i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )])); // q + i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )])); // q + + i2_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2 )])); // q + i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2 )])); // q + i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2 )])); // q + i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2 )])); // q + i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2 )])); // q + + r1_fx = Mpy_32_16_1(r1_fx, ptr_pf_sf); // q - 1 + r2_fx = Mpy_32_16_1(r2_fx, ptr_pf_sf); // q - 1 + i1_fx = Mpy_32_16_1(i1_fx, ptr_pf_sf); // q - 1 + i2_fx = Mpy_32_16_1(i2_fx, ptr_pf_sf); // q - 1 + + /* folding + pre modulation of DST IV */ + rr12_fx = L_sub( r1_fx, r2_fx ); // q -1 + ri12_fx = L_negate( L_add( i1_fx, i2_fx ) ); // q - 1 + /*cplxMult(&rBuffer[2*k],&rBuffer[2*k+1],rr12,ri12,rot_vctr_re[k],rot_vctr_im[k]);*/ + rBuffer_fx[2 * k] = L_sub(Mpy_32_32(rr12_fx, rot_vctr_re_fx[k]), Mpy_32_32(ri12_fx, rot_vctr_im_fx[k])); // q - 3 + rBuffer_fx[2 * k + 1] = L_add(Mpy_32_32(rr12_fx, rot_vctr_im_fx[k]), Mpy_32_32(ri12_fx, rot_vctr_re_fx[k])); // q - 3 + + ///* folding + pre modulation of DCT IV */ + ir12_fx = L_add(r1_fx, r2_fx); // q - 1 + ii12_fx = L_sub(i1_fx, i2_fx); // q - 1 + /*cplxMult(&iBuffer[2*k],&iBuffer[2*k+1],ir12,ii12,rot_vctr_re[k],rot_vctr_im[k]);*/ + iBuffer_fx[2 * k] = L_sub(Mpy_32_32(ir12_fx, rot_vctr_re_fx[k]), Mpy_32_32(ii12_fx, rot_vctr_im_fx[k])); // q - 3 + iBuffer_fx[2 * k + 1] = L_add(Mpy_32_32(ir12_fx, rot_vctr_im_fx[k]), Mpy_32_32(ii12_fx, rot_vctr_re_fx[k])); // q - 3 + } + + for ( k = M4; k < M2; k++ ) + { + /* prototype filter */ + r1_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )])); // q + r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )])); // q + r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )])); // q + r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )])); // q + r1_fx = L_sub(r1_fx, Mpy_32_16_1(timeBuffer_fx[L2 - M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )])); // q + + r2_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 0 * L2 )])); // q + r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 1 * L2 )])); // q + r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 2 * L2 )])); // q + r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 3 * L2 )])); // q + r2_fx = L_sub(r2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 5 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 4 * L2 )])); // q + + i1_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )])); // q + i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )])); // q + i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )])); // q + i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )])); // q + i1_fx = L_sub(i1_fx, Mpy_32_16_1(timeBuffer_fx[L2 + M2 - 1 - ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )])); // q + + i2_fx = L_sub(0, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 0 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )])); // q + i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 1 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )])); // q + i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 2 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )])); // q + i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 3 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )])); // q + i2_fx = L_sub(i2_fx, Mpy_32_16_1(timeBuffer_fx[L2 - 3 * M2 + ( 2 * k ) + 4 * L2], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )])); // q + + r1_fx = Mpy_32_16_1(r1_fx, ptr_pf_sf); // q - 1 + r2_fx = Mpy_32_16_1(r2_fx, ptr_pf_sf); // q - 1 + i1_fx = Mpy_32_16_1(i1_fx, ptr_pf_sf); // q - 1 + i2_fx = Mpy_32_16_1(i2_fx, ptr_pf_sf); // q - 1 + + /* folding + pre modulation of DST IV */ + rr12_fx = L_add(r1_fx, r2_fx); // q - 1 + ri12_fx = L_sub(i1_fx, i2_fx); // q - 1 + /*cplxMult(&rBuffer[2*k],&rBuffer[2*k+1],rr12,ri12,rot_vctr_re[k],rot_vctr_im[k]);*/ + rBuffer_fx[2 * k] = L_sub(Mpy_32_32(rr12_fx, rot_vctr_re_fx[k]), Mpy_32_32(ri12_fx, rot_vctr_im_fx[k])); // q - 3 + rBuffer_fx[2 * k + 1] = L_add(Mpy_32_32(rr12_fx, rot_vctr_im_fx[k]), Mpy_32_32(ri12_fx, rot_vctr_re_fx[k])); // q - 3 + + /* folding + pre modulation of DCT IV */ + ir12_fx = L_sub(r1_fx, r2_fx); // q - 1 + ii12_fx = L_add(i1_fx, i2_fx); // q - 1 + /*cplxMult(&iBuffer[2*k],&iBuffer[2*k+1],ir12,ii12,rot_vctr_re[k],rot_vctr_im[k]);*/ + iBuffer_fx[2 * k] = L_sub(Mpy_32_32(ir12_fx, rot_vctr_re_fx[k]), Mpy_32_32(ii12_fx, rot_vctr_im_fx[k])); // q - 3 + iBuffer_fx[2 * k + 1] = L_add(Mpy_32_32(ir12_fx, rot_vctr_im_fx[k]), Mpy_32_32(ii12_fx, rot_vctr_re_fx[k])); // q - 3 } + *q_cldfb = sub(*q_cldfb, 3); + + /* FFT of DST IV */ + fft_cldfb_fx( rBuffer_fx, M2 ); + /* post modulation of DST IV */ for ( k = 0; k < M2; k++ ) { /*cplxMult(&realBuffer[M1-1-(2*k)],&realBuffer[2*k],rBuffer[2*k],rBuffer[2*k+1],rot_vctr_re[k],rot_vctr_im[k]);*/ - realBuffer_fx[M1 - 1 - ( 2 * k )] = L_sub(Mpy_32_32(rBuffer_fx[2 * k], rot_vctr_re_fx[k]), Mpy_32_32(rBuffer_fx[2 * k + 1], rot_vctr_im_fx[k])); // q = 23 - realBuffer_fx[2 * k] = L_add(Mpy_32_32(rBuffer_fx[2 * k], rot_vctr_im_fx[k]), Mpy_32_32(rBuffer_fx[2 * k + 1], rot_vctr_re_fx[k])); // q = 23 + realBuffer_fx[M1 - 1 - ( 2 * k )] = L_sub(Mpy_32_32(rBuffer_fx[2 * k], rot_vctr_re_fx[k]), Mpy_32_32(rBuffer_fx[2 * k + 1], rot_vctr_im_fx[k])); // q - 5 + realBuffer_fx[2 * k] = L_add(Mpy_32_32(rBuffer_fx[2 * k], rot_vctr_im_fx[k]), Mpy_32_32(rBuffer_fx[2 * k + 1], rot_vctr_re_fx[k])); // q - 5 } + *q_cldfb = sub(*q_cldfb, 2); /* FFT of DCT IV */ fft_cldfb_fx( iBuffer_fx, M2 ); @@ -878,8 +1122,8 @@ void cldfbAnalysis_ts_fx( { /* do it inplace */ /*cplxMult(&imagBuffer[2*k],&imagBuffer[M1-1-(2*k)],iBuffer[2*k],iBuffer[2*k+1],rot_vctr_re[k],rot_vctr_im[k]);*/ - imagBuffer_fx[2 * k] = L_sub(Mpy_32_32(iBuffer_fx[2 * k], rot_vctr_re_fx[k]), Mpy_32_32(iBuffer_fx[2 * k + 1], rot_vctr_im_fx[k])); // q = 23 - imagBuffer_fx[M1 - 1 - ( 2 * k )] = L_add(Mpy_32_32(iBuffer_fx[2 * k], rot_vctr_im_fx[k]), Mpy_32_32(iBuffer_fx[2 * k + 1], rot_vctr_re_fx[k])); // q = 23 + imagBuffer_fx[2 * k] = L_sub(Mpy_32_32(iBuffer_fx[2 * k], rot_vctr_re_fx[k]), Mpy_32_32(iBuffer_fx[2 * k + 1], rot_vctr_im_fx[k])); // q - 5 + imagBuffer_fx[M1 - 1 - ( 2 * k )] = L_add(Mpy_32_32(iBuffer_fx[2 * k], rot_vctr_im_fx[k]), Mpy_32_32(iBuffer_fx[2 * k + 1], rot_vctr_re_fx[k])); // q - 5 } if ( h_cldfb->prototype == CLDFB_PROTOTYPE_5_00MS ) @@ -898,8 +1142,8 @@ void cldfbAnalysis_ts_fx( /*cplxMult(&realBuffer[k], &imagBuffer[k], realBuffer[k], imagBuffer[k], rot_vctr_delay_re[k], rot_vctr_delay_im[k]);*/ /*realBuffer[k] = rBuffer[k]; imagBuffer[k] = iBuffer[k];*/ - cplx_aux_fx = L_sub(Mpy_32_32(realBuffer_fx[k], rot_vctr_delay_re_fx[k]), Mpy_32_32(imagBuffer_fx[k], rot_vctr_delay_im_fx[k])); // q = 23 - imagBuffer_fx[k] = L_add(Mpy_32_32(realBuffer_fx[k], rot_vctr_delay_im_fx[k]), Mpy_32_32(imagBuffer_fx[k], rot_vctr_delay_re_fx[k])); // q = 23 + cplx_aux_fx = L_sub(Mpy_32_32(realBuffer_fx[k], rot_vctr_delay_re_fx[k]), Mpy_32_32(imagBuffer_fx[k], rot_vctr_delay_im_fx[k])); // q - 5 + imagBuffer_fx[k] = L_add(Mpy_32_32(realBuffer_fx[k], rot_vctr_delay_im_fx[k]), Mpy_32_32(imagBuffer_fx[k], rot_vctr_delay_re_fx[k])); // q - 5 realBuffer_fx[k] = cplx_aux_fx; } } @@ -1509,6 +1753,28 @@ void resampleCldfb_ivas( return; } +#ifdef IVAS_FLOAT_FIXED +void resampleCldfb_ivas_fx( + HANDLE_CLDFB_FILTER_BANK hs, /* i/o: filter bank handle */ + const Word32 newSamplerate +) +{ + Word16 timeOffset; + + /* keep old parameters before switching*/ + Word16 timeOffsetold = sub(hs->p_filter_length, hs->no_channels); + + /* new settings */ + configureCldfb_ivas_fx( hs, newSamplerate ); + + timeOffset = sub(hs->p_filter_length, hs->no_channels); + + /*low complexity-resampling only stored previous samples that are needed for next frame modulation */ + L_lerp_fx_q11( hs->cldfb_state_fx, hs->cldfb_state_fx, timeOffset, timeOffsetold ); + + return; +} +#endif /*-------------------------------------------------------------------* * analysisCLDFBEncoder() diff --git a/lib_com/fd_cng_com.c b/lib_com/fd_cng_com.c index 0a9867fb8..61738d940 100644 --- a/lib_com/fd_cng_com.c +++ b/lib_com/fd_cng_com.c @@ -1072,7 +1072,25 @@ float rand_gauss_flt( return temp; } +#ifdef IVAS_FLOAT_FIXED +Word32 rand_gauss_fx( + Word32 *x, + Word16 *seed, + Word16 q +) +{ + Word32 temp; + temp = own_random( seed ); + temp = L_add(temp, own_random( seed )); + temp = L_add(temp, own_random( seed )); + temp = L_shr(temp, 15 - q); + + *x = temp; + + return temp; +} +#endif /*------------------------------------------------------------------- * lpc_from_spectrum_flt() diff --git a/lib_com/ivas_rom_com_fx.c b/lib_com/ivas_rom_com_fx.c index a90f830d2..0c79ed33d 100644 --- a/lib_com/ivas_rom_com_fx.c +++ b/lib_com/ivas_rom_com_fx.c @@ -364,4 +364,12 @@ const Word32 ls_elevation_CICP16_fx[9] = { 0, 0, 0, 0, 0, 146800640, 146800640, const Word32 ls_azimuth_CICP19_fx[11] = { 125829120, -125829120, 0, 566231040, -566231040, 377487360, -377487360, 125829120, -125829120, 566231040, -566231040 }; const Word32 ls_elevation_CICP19_fx[11] = { 0, 0, 0, 0, 0, 0, 0, 146800640, 146800640, 146800640, 146800640 }; +const Word16 pow_10_q11[128] = { + 2048, 2085, 2123, 2161, 2200, 2240, 2281, 2322, 2364, 2407, 2451, 2496, 2541, 2587, 2634, 2682, 2731, 2780, 2831, 2882, 2934, 2988, 3042, 3097, 3153, 3211, 3269, + 3328, 3389, 3450, 3513, 3576, 3641, 3708, 3775, 3843, 3913, 3984, 4056, 4130, 4205, 4281, 4359, 4438, 4519, 4601, 4684, 4769, 4856, 4944, 5034, 5125, 5218, 5313, + 5410, 5508, 5608, 5710, 5813, 5919, 6026, 6136, 6247, 6360, 6476, 6593, 6713, 6835, 6959, 7085, 7214, 7345, 7478, 7614, 7752, 7893, 8036, 8182, 8331, 8482, 8636, + 8793, 8952, 9115, 9280, 9449, 9620, 9795, 9973, 10154, 10338, 10526, 10717, 10911, 11109, 11311, 11516, 11725, 11938, 12155, 12375, 12600, 12829, 13062, 13299, + 13540, 13786, 14036, 14291, 14550, 14815, 15084, 15357, 15636, 15920, 16209, 16503, 16803, 17108, 17418, 17734, 18056, 18384, 18718, 19058, 19404, 19756, 20114 +}; + /* clang-format on */ diff --git a/lib_com/ivas_rom_com_fx.h b/lib_com/ivas_rom_com_fx.h index f10915790..2f849ca3b 100644 --- a/lib_com/ivas_rom_com_fx.h +++ b/lib_com/ivas_rom_com_fx.h @@ -75,5 +75,6 @@ extern const Word32 ls_azimuth_CICP16_fx[9]; extern const Word32 ls_elevation_CICP16_fx[9]; extern const Word32 ls_azimuth_CICP19_fx[11]; extern const Word32 ls_elevation_CICP19_fx[11]; +extern const Word16 pow_10_q11[128]; #endif \ No newline at end of file diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h index f071999ec..5e5d17d62 100644 --- a/lib_com/prot_fx2.h +++ b/lib_com/prot_fx2.h @@ -5167,6 +5167,13 @@ void v_add_w64( const Word16 hdrm /* i : headroom for when subtraction result > 1 or < -1 */ ); +void v_multc_32_16_fixed( + const Word32 x[], /* i : Input vector */ + const Word16 c, /* i : Constant */ + Word32 y[], /* o : Output vector that contains c*x */ + const Word16 N /* i : Vector length */ +); + void v_sub_fixed( const Word32 x1[], /* i : Input vector 1 */ const Word32 x2[], /* i : Input vector 2 */ @@ -8186,12 +8193,23 @@ void v_add_fx( ); void cldfbAnalysis_ts_fx( - const Word32 *timeIn_fx, /* i : time buffer */ // q = 31 - Word32 realBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : real value buffer */ // q = 29 - Word32 imagBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : imag value buffer */ // q = 29 + const Word32 *timeIn_fx, /* i : time buffer */ + Word32 realBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : real value buffer */ + Word32 imagBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : imag value buffer */ + const Word16 samplesToProcess, /* i : samples to process */ + HANDLE_CLDFB_FILTER_BANK h_cldfb , + Word16* q_cldfb +); + +void cldfbAnalysis_ts_fx_fixed_q( + const Word32 *timeIn_fx, /* i : time buffer */ // q + Word32 realBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : real value buffer */ // q - 5 + Word32 imagBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* o : imag value buffer */ // q - 5 const Word16 samplesToProcess, /* i : samples to process */ - HANDLE_CLDFB_FILTER_BANK h_cldfb + HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i : filterbank state */ + Word16* q_cldfb ); + // dec4t64.c void dec_acelp_fast_fx( Decoder_State *st, /* i/o: decoder state structure */ @@ -8292,4 +8310,29 @@ ivas_error openCldfb_ivas_fx( const Word32 sampling_rate, /* i : sampling rate */ CLDFB_PROTOTYPE prototype /* i : CLDFB version (1.25ms/5ms delay) */ ); + +Word32 rand_gauss_fx( + Word32 *x, + Word16 *seed, + Word16 q +); + +void resampleCldfb_ivas_fx( + HANDLE_CLDFB_FILTER_BANK hs, /* i/o: filter bank handle */ + const Word32 newSamplerate +); + +void generate_masking_noise_dirac_fx( + HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ + HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i : filterbank state */ + Word32 *tdBuffer_fx, /* i/o: time-domain signal, if NULL no LB-CNA */ + Word32 *Cldfb_RealBuffer_fx, /* o : CLDFD real buffer */ + Word32 *Cldfb_ImagBuffer_fx, /* o : CLDFD imaginary buffer */ + const Word16 slot_index, /* i : CLDFB slot index */ + const Word16 cna_flag, /* i : CNA flag for LB and HB */ + const Word16 fd_cng_flag, /* i : FD-CNG flag for HB */ + Word16 q_input, + Word16 *q_cldfb +); + #endif diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c index a2434cd9c..9dc82a9c3 100644 --- a/lib_com/rom_com.c +++ b/lib_com/rom_com.c @@ -10709,23 +10709,23 @@ const SCALE_SETUP scaleTable_cn_only[SIZE_SCALE_TABLE_CN] = #endif const SCALE_SETUP scaleTable_cn_dirac[15] = { - { 0, 0, 13200, -3.0f, 16306/*0.9952622652 Q14*/ /*-3.0f*/ }, - { 0, 13200, 16400, -2.5f, 12751/*0.7782794237 Q14*/ /*-2.5f*/ }, - { 0, 16400, 24400, -2.0f, 9583/*0.5848932266 Q14*/ /*-2.0f*/ }, - { 0, 24400, 32000, -1.5f, 6759/*0.4125375748 Q14*/ /*-1.5f*/ }, - { 0, 32000,512001, 0.0f, 0/*0.0000000000 Q14*/ /* 0.0f*/ }, - - { 1, 0, 13200, -3.0f, 16306/*0.9952622652 Q14*/ /*-3.0f*/ }, - { 1, 13200, 16400, -2.5f, 12751/*0.7782794237 Q14*/ /*-2.5f*/ }, - { 1, 16400, 24400, -2.0f, 9583/*0.5848932266 Q14*/ /*-2.0f*/ }, - { 1, 24400, 32000, -1.5f, 6759/*0.4125375748 Q14*/ /*-1.5f*/ }, - { 1, 32000,512001, 0.0f, 0/*0.0000000000 Q14*/ /* 0.0f*/ }, - - { 2, 0, 13200, -3.0f, 16306/*0.9952622652 Q14*/ /*-3.0f*/ }, - { 2, 13200, 16400, -2.5f, 12751/*0.7782794237 Q14*/ /*-2.5f*/ }, - { 2, 16400, 24400, -2.0f, 9583/*0.5848932266 Q14*/ /*-2.0f*/ }, - { 2, 24400, 32000, -1.5f, 6759/*0.4125375748 Q14*/ /*-1.5f*/ }, - { 2, 32000,512001, 0.0f, 0/*0.0000000000 Q14*/ /* 0.0f*/ } + { 0, 0, 13200, -3.0f, 16306/*0.9952622652 Q14*/ /*-3.0f*/, -24576 }, + { 0, 13200, 16400, -2.5f, 12751/*0.7782794237 Q14*/ /*-2.5f*/, -20480 }, + { 0, 16400, 24400, -2.0f, 9583/*0.5848932266 Q14*/ /*-2.0f*/, -16384 }, + { 0, 24400, 32000, -1.5f, 6759/*0.4125375748 Q14*/ /*-1.5f*/, -12288 }, + { 0, 32000,512001, 0.0f, 0/*0.0000000000 Q14*/ /* 0.0f*/, 0 }, + + { 1, 0, 13200, -3.0f, 16306/*0.9952622652 Q14*/ /*-3.0f*/, -24576 }, + { 1, 13200, 16400, -2.5f, 12751/*0.7782794237 Q14*/ /*-2.5f*/, -20480 }, + { 1, 16400, 24400, -2.0f, 9583/*0.5848932266 Q14*/ /*-2.0f*/, -16384 }, + { 1, 24400, 32000, -1.5f, 6759/*0.4125375748 Q14*/ /*-1.5f*/, -12288 }, + { 1, 32000,512001, 0.0f, 0/*0.0000000000 Q14*/ /* 0.0f*/, 0 }, + + { 2, 0, 13200, -3.0f, 16306/*0.9952622652 Q14*/ /*-3.0f*/, -24576 }, + { 2, 13200, 16400, -2.5f, 12751/*0.7782794237 Q14*/ /*-2.5f*/, -20480 }, + { 2, 16400, 24400, -2.0f, 9583/*0.5848932266 Q14*/ /*-2.0f*/, -16384 }, + { 2, 24400, 32000, -1.5f, 6759/*0.4125375748 Q14*/ /*-1.5f*/, -12288 }, + { 2, 32000,512001, 0.0f, 0/*0.0000000000 Q14*/ /* 0.0f*/, 0 } }; const float scaleTable_cn_only_amrwbio_flt[SIZE_SCALE_TABLE_CN_AMRWB][2] = { diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index 49e7f4a1e..521ac037c 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -372,7 +372,8 @@ typedef struct int32_t bitrateTo; float scale_flt; - Word16 scale; + Word16 scale; /* EVS implementation */ + Word16 scale_ivas; /* IVAS implementation */ } SCALE_SETUP; @@ -445,6 +446,7 @@ typedef struct Word16 exp_cldfb_periodog; Word32 cngNoiseLevel[FFTCLDFBLEN]; /* Noise level applied for the CNG in each (sub)band */ + Word16 q_cngNoiseLevel; Word16 cngNoiseLevelExp; int16_t seed; /* Seed memory (for random function) */ @@ -753,6 +755,7 @@ typedef struct cldfb_filter_bank_struct float scale_flt; /* scaling of frequency domain */ Word16 scale; + Word16 q_scale; } CLDFB_FILTER_BANK, *HANDLE_CLDFB_FILTER_BANK; diff --git a/lib_dec/fd_cng_dec.c b/lib_dec/fd_cng_dec.c index 8dc34d6c8..69b2204a2 100644 --- a/lib_dec/fd_cng_dec.c +++ b/lib_dec/fd_cng_dec.c @@ -44,6 +44,7 @@ #include "wmc_auto.h" #include "ivas_prot.h" #include "ivas_rom_dec.h" +#include "ivas_rom_com_fx.h" #include "prot_fx2.h" #include "ivas_prot_fx.h" @@ -2037,6 +2038,125 @@ void generate_masking_noise_dirac( return; } +#ifdef IVAS_FLOAT_FIXED +void generate_masking_noise_dirac_fx( + HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ + HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i : filterbank state */ + Word32 *tdBuffer_fx, /* i/o: time-domain signal, if NULL no LB-CNA */ + Word32 *Cldfb_RealBuffer_fx, /* o : CLDFD real buffer */ + Word32 *Cldfb_ImagBuffer_fx, /* o : CLDFD imaginary buffer */ + const Word16 slot_index, /* i : CLDFB slot index */ + const Word16 cna_flag, /* i : CNA flag for LB and HB */ + const Word16 fd_cng_flag, /* i : FD-CNG flag for HB */ + Word16 q_input, + Word16 *q_cldfb +) +{ + Word16 i; + Word32 *ptr_level_fx; + Word16 *seed = &( hFdCngCom->seed ); + Word32 scale_fx; + Word16 q_scale, q_shift, q_ptr_level; + + push_wmops( "fd_cng_dirac" ); + + /* Init */ + scale_fx = 0; + move32(); + + /* Resample CLDFB memories if necessary*/ + IF ( NE_16( i_mult( h_cldfb->no_channels, h_cldfb->no_col ), hFdCngCom->frameSize ) ) + { + resampleCldfb_ivas_fx( h_cldfb, hFdCngCom->frameSize * FRAMES_PER_SEC ); + } + + set32_fx( Cldfb_RealBuffer_fx, 0, CLDFB_NO_CHANNELS_MAX ); + set32_fx( Cldfb_ImagBuffer_fx, 0, CLDFB_NO_CHANNELS_MAX ); + + /*LB CLDFB - CNA from STFT*/ + IF ( NE_16(cna_flag, 0) ) + { + /* skip noise generating if level is very low, to avoid problems with possibly running into denormals */ + IF ( GT_16(hFdCngCom->likelihood_noisy_speech, 0) ) + { + /* Compute additional CN level */ + FOR ( i = 0; i < 15; i++ ) + { + IF ( ( EQ_16(hFdCngCom->CngBandwidth, scaleTable_cn_dirac[i].bwmode) ) && + ( GE_32(hFdCngCom->CngBitrate, scaleTable_cn_dirac[i].bitrateFrom) ) && + ( LT_32(hFdCngCom->CngBitrate, scaleTable_cn_dirac[i].bitrateTo) ) ) + { + BREAK; + } + } + + scale_fx = L_sub(pow_10_q11[shr(negate(scaleTable_cn_dirac[i].scale_ivas) / 10, 13 - 7)], 2048); // Q11 + scale_fx = Mpy_32_16_1(scale_fx, hFdCngCom->likelihood_noisy_speech); + } + } + /* LB CLDFB - CNA from STFT: CNA applied only in channel 0*/ + IF ( cna_flag && tdBuffer_fx != NULL ) + { + *q_cldfb = q_input; + IF ( scale_fx != 0 ) + { + /* LF CLDFB*/ + cldfbAnalysis_ts_fx_fixed_q( &( tdBuffer_fx[hFdCngCom->numCoreBands * slot_index] ), Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hFdCngCom->numCoreBands, h_cldfb, q_cldfb ); + } + ELSE + { + /* LB ana CLDFB*/ + cldfbAnalysis_ts_fx_fixed_q( &( tdBuffer_fx[hFdCngCom->numCoreBands * slot_index] ), Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hFdCngCom->numCoreBands, h_cldfb, q_cldfb ); + } + } + + /*HF CLDFB - CNA and/or FD-CNG*/ + IF ( fd_cng_flag ) + { + scale_fx += 2048; // 1 in Q11 + move16(); + } + IF ( scale_fx != 0 ) + { + q_scale = 11; + move16(); + q_shift = norm_l(scale_fx); + scale_fx = L_shl(scale_fx, q_shift); + q_scale = add(q_scale, q_shift); + scale_fx = Mpy_32_32(scale_fx, Mpy_32_16_1(L_mult(h_cldfb->scale, h_cldfb->scale), CLDFB_SCALING)); //Q = q_scale + 2q -34 + q_scale = sub(add(q_scale, i_mult(2, h_cldfb->q_scale)), 34); + ptr_level_fx = hFdCngCom->cngNoiseLevel + hFdCngCom->stopFFTbin - hFdCngCom->startBand; + q_ptr_level = hFdCngCom->q_cngNoiseLevel; + move16(); + + FOR ( i = hFdCngCom->numCoreBands; i < hFdCngCom->regularStopBand; i++ ) + { + Word32 num; + Word16 exp, q_num; + q_shift = norm_l(scale_fx); + scale_fx = L_shl(scale_fx, q_shift); + q_scale = add(q_scale, q_shift); + num = Mpy_32_32(scale_fx, *ptr_level_fx); + q_num = sub(add(q_scale, q_ptr_level), 30); + exp = sub(31, q_num); + num = Sqrt32(num, &exp); + /* Real part in CLDFB band */ + rand_gauss_fx( &Cldfb_RealBuffer_fx[i], seed, *q_cldfb ); + Cldfb_RealBuffer_fx[i] = L_shl(Mpy_32_32(Cldfb_RealBuffer_fx[i], num), exp); + /* Imaginary part in CLDFB band */ + rand_gauss_fx( &Cldfb_ImagBuffer_fx[i], seed, *q_cldfb ); + Cldfb_ImagBuffer_fx[i] = L_shl(Mpy_32_32(Cldfb_ImagBuffer_fx[i], num), exp); + + ptr_level_fx++; + } + } + + pop_wmops(); + + return; +} +#endif + /*------------------------------------------------------------------- * FdCngDecodeMDCTStereoSID() diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 527e68f9f..a8a584233 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -55,6 +55,7 @@ * Allocate and initialize MASA_ISM rendering handle *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_omasa_data_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ ) @@ -113,6 +114,86 @@ ivas_error ivas_omasa_data_open( return IVAS_ERR_OK; } +#else +ivas_error ivas_omasa_data_open( + Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ +) +{ + MASA_ISM_DATA_HANDLE hMasaIsmData; + int16_t ch, bin; + int16_t sf, obj_idx; + + IF ( ( hMasaIsmData = (MASA_ISM_DATA_HANDLE) malloc( sizeof( MASA_ISM_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA ISM data\n" ) ); + } + + FOR ( bin = 0; bin < CLDFB_NO_CHANNELS_MAX; bin++ ) + { + FOR ( ch = 0; ch < 2; ch++ ) + { + hMasaIsmData->ismPreprocMatrix_fx[ch][ch][bin] = 32767; + hMasaIsmData->ismPreprocMatrix_fx[1 - ch][ch][bin] = 0; + hMasaIsmData->eneMoveIIR_fx[ch][bin] = 0; + hMasaIsmData->enePreserveIIR_fx[ch][bin] = 0; + } + hMasaIsmData->preprocEneTarget_fx[bin] = 0; + hMasaIsmData->preprocEneRealized_fx[bin] = 0; + } + + hMasaIsmData->objectsMoved = 0; + hMasaIsmData->delayBuffer_fx = NULL; + + for ( ch = 0; ch < MAX_NUM_OBJECTS; ch++ ) + { + hMasaIsmData->ism_is_edited[ch] = 0; + hMasaIsmData->q_elevation_old_fx[ch] = 0; + hMasaIsmData->q_azimuth_old_fx[ch] = 0; + } + + for ( obj_idx = 0; obj_idx < MAX_NUM_OBJECTS; obj_idx++ ) + { + set_s( hMasaIsmData->azimuth_ism[obj_idx], 0, MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR ); + set_s( hMasaIsmData->elevation_ism[obj_idx], 0, MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR ); + for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR; sf++ ) + { + // To be removed later ///////////////////////////////////////////////////////////////////////// + set_zero( hMasaIsmData->energy_ratio_ism[obj_idx][sf], CLDFB_NO_CHANNELS_MAX ); + ///////////////////////////////////////////////////////////////////////////////////////////////// + set32_fx( hMasaIsmData->energy_ratio_ism_fx[obj_idx][sf], 0, CLDFB_NO_CHANNELS_MAX ); + } + } + set_s( hMasaIsmData->azimuth_separated_ism, 0, MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR ); + set_s( hMasaIsmData->elevation_separated_ism, 0, MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR ); + + // to be removed later //////////////////////////////////////////////////////////////////////////////////// + FOR ( bin = 0; bin < CLDFB_NO_CHANNELS_MAX; bin++ ) + { + FOR ( ch = 0; ch < 2; ch++ ) + { + hMasaIsmData->ismPreprocMatrix[ch][ch][bin] = 1.0f; + hMasaIsmData->ismPreprocMatrix[1 - ch][ch][bin] = 0.0f; + hMasaIsmData->eneMoveIIR[ch][bin] = 0.0f; + hMasaIsmData->enePreserveIIR[ch][bin] = 0.0f; + } + hMasaIsmData->preprocEneTarget[bin] = 0.0f; + hMasaIsmData->preprocEneRealized[bin] = 0.0f; + } + + hMasaIsmData->delayBuffer = NULL; + + for ( ch = 0; ch < MAX_NUM_OBJECTS; ch++ ) + { + hMasaIsmData->q_elevation_old[ch] = 0.0f; + hMasaIsmData->q_azimuth_old[ch] = 0.0f; + } + ///////////////////////////////////////////////////////////////////////////////////////////////////////////// + + st_ivas->hMasaIsmData = hMasaIsmData; + + return IVAS_ERR_OK; +} +#endif /*-------------------------------------------------------------------* @@ -121,6 +202,7 @@ ivas_error ivas_omasa_data_open( * Deallocate MASA_ISM rendering handle *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_omasa_data_close( MASA_ISM_DATA_HANDLE *hMasaIsmData /* i/o: MASA_ISM rendering handle */ ) @@ -159,6 +241,46 @@ void ivas_omasa_data_close( return; } +#else +void ivas_omasa_data_close( + MASA_ISM_DATA_HANDLE *hMasaIsmData /* i/o: MASA_ISM rendering handle */ +) +{ + Word16 i; + + IF ( hMasaIsmData == NULL || *hMasaIsmData == NULL ) + { + return; + } + + // To be removed later ///////////////////////////////////////////////// + IF ( ( *hMasaIsmData )->delayBuffer != NULL ) + { + FOR ( i = 0; i < ( *hMasaIsmData )->delayBuffer_nchan; i++ ) + { + free( ( *hMasaIsmData )->delayBuffer[i] ); + } + free( ( *hMasaIsmData )->delayBuffer ); + ( *hMasaIsmData )->delayBuffer = NULL; + } + ///////////////////////////////////////////////////////////////////////// + + IF ( ( *hMasaIsmData )->delayBuffer_fx != NULL ) + { + FOR ( i = 0; i < ( *hMasaIsmData )->delayBuffer_nchan; i++ ) + { + free( ( *hMasaIsmData )->delayBuffer_fx[i] ); + } + free( ( *hMasaIsmData )->delayBuffer_fx ); + ( *hMasaIsmData )->delayBuffer_fx = NULL; + } + + free( *hMasaIsmData ); + *hMasaIsmData = NULL; + + return; +} +#endif /*--------------------------------------------------------------------------* @@ -645,7 +767,7 @@ void ivas_omasa_dirac_rend_jbm( } } - q_output -= 1; // guard bit + q_output -= 2; // guard bit FOR(Word16 ind = 0; ind < MAX_NUM_OBJECTS; ind++) { FOR(Word16 ind2 = 0; ind2 < nSamplesAsked; ind2++) @@ -656,8 +778,8 @@ void ivas_omasa_dirac_rend_jbm( output_fx = (Word32**)malloc(sizeof(Word32*) * (st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe)); FOR(Word16 ind = 0; ind < st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; ind++) { - output_fx[ind] = (Word32*)malloc(sizeof(Word32) * nSamplesAsked); - FOR(Word16 ind2 = 0; ind2 < nSamplesAsked; ind2++) + output_fx[ind] = (Word32*)malloc(sizeof(Word32) * 960); + FOR(Word16 ind2 = 0; ind2 < 960; ind2++) { output_fx[ind][ind2] =(Word32)(output_f[ind][ind2] * (1<hDecoderConfig->Opt_tsm; ind1++) + FOR(Word16 ind1 = 0; ind1 < st_ivas->nchan_ism; ind1++) { - FOR(Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++) + FOR(Word16 ind2 = 0; ind2 < 960; ind2++) { st_ivas->hTcBuffer->tc_fx[ind1][ind2] = (Word32)(st_ivas->hTcBuffer->tc[ind1][ind2] * (1 << q_output)); } @@ -753,12 +875,12 @@ void ivas_omasa_dirac_rend_jbm( } } - //ivas_omasa_separate_object_render_jbm_fx( st_ivas, *nSamplesRendered, data_separated_objects_fx, output_fx, subframes_rendered, slots_rendered ); - ivas_omasa_separate_object_render_jbm( st_ivas, *nSamplesRendered, data_separated_objects, output_f, subframes_rendered, slots_rendered ); + ivas_omasa_separate_object_render_jbm_fx( st_ivas, *nSamplesRendered, data_separated_objects_fx, output_fx, subframes_rendered, slots_rendered ); + //ivas_omasa_separate_object_render_jbm( st_ivas, *nSamplesRendered, data_separated_objects, output_f, subframes_rendered, slots_rendered ); - /*FOR(Word16 ind = 0; ind < st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; ind++) + FOR(Word16 ind = 0; ind < st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; ind++) { - FOR(Word16 ind2 = 0; ind2 < nSamplesAsked; ind2++) + FOR(Word16 ind2 = 0; ind2 < 960; ind2++) { output_f[ind][ind2] =(float)(output_fx[ind][ind2]) / (float)(1<hIsmRendererData->prev_gains[ind1][ind2] = (float)(st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2]) / (float)(1 << 29); } } - FOR(Word16 ind1 = 0; ind1 < st_ivas->hDecoderConfig->Opt_tsm; ind1++) + FOR(Word16 ind1 = 0; ind1 < st_ivas->nchan_ism; ind1++) { - FOR(Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++) + FOR(Word16 ind2 = 0; ind2 < 960; ind2++) { st_ivas->hTcBuffer->tc[ind1][ind2] = (float)(st_ivas->hTcBuffer->tc_fx[ind1][ind2]) / (float)(1 << q_output); } @@ -789,7 +911,7 @@ void ivas_omasa_dirac_rend_jbm( FOR ( Word16 k = 0; k < st_ivas->hIsmRendererData->interpolator_length; k++ ) { st_ivas->hIsmRendererData->interpolator[k] = (float)st_ivas->hIsmRendererData->interpolator_fx[k] / (float)(1<<15); - }*/ + } #else ivas_omasa_separate_object_render_jbm( st_ivas, *nSamplesRendered, data_separated_objects, output_f, subframes_rendered, slots_rendered ); #endif diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 82fa3edea..17b883148 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -796,19 +796,17 @@ void ivas_spar_get_cldfb_gains( #ifdef IVAS_FLOAT_FIXED Word32 ts_inout_fx[CLDFB_NO_CHANNELS_MAX], ts_re_fx[CLDFB_NO_CHANNELS_MAX], ts_im_fx[CLDFB_NO_CHANNELS_MAX]; + Word16 q_cldfb = 27; for (Word16 i = 0; i < CLDFB_NO_CHANNELS_MAX; i++) { ts_inout_fx[i] = (Word32)(ts_inout[i] * (1LL << (31-4))); - ts_im_fx[i] = (Word32)(ts_im[i] * (1LL << (29-4))); - ts_re_fx[i] = (Word32)(ts_re[i] * (1LL << (29-4))); } for (Word16 i = 0; i < cldfbAnaDec0->p_filter_length - cldfbAnaDec0->no_channels; i++) { cldfbAnaDec0->cldfb_state_fx[i] = (Word32)(cldfbAnaDec0->cldfb_state[i] * (1LL << (31-4))); } - cldfbAnalysis_ts_fx( ts_inout_fx, ts_re_fx, ts_im_fx, num_cldfb_bands, cldfbAnaDec0 ); + cldfbAnalysis_ts_fx( ts_inout_fx, ts_re_fx, ts_im_fx, num_cldfb_bands, cldfbAnaDec0, &q_cldfb ); for (Word16 i = 0; i < CLDFB_NO_CHANNELS_MAX; i++) { - ts_inout[i] = (float)(ts_inout_fx[i]) / (float)(1LL << (31-4)); - ts_im[i] = (float)(ts_im_fx[i]) / (float)(1LL << (29-4)); - ts_re[i] = (float)(ts_re_fx[i]) / (float)(1LL << (29-4)); + ts_im[i] = (float)(ts_im_fx[i]) / (float)(1LL << q_cldfb); + ts_re[i] = (float)(ts_re_fx[i]) / (float)(1LL << q_cldfb); } for (Word16 i = 0; i < cldfbAnaDec0->p_filter_length - cldfbAnaDec0->no_channels; i++) { cldfbAnaDec0->cldfb_state_fx[i] = (Word32)(cldfbAnaDec0->cldfb_state[i] * (1LL << (31-4))); diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 5d86991b4..b39b9abeb 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1011,6 +1011,11 @@ typedef struct ivas_masa_ism_data_structure float **delayBuffer; #ifdef IVAS_FLOAT_FIXED Word32 **delayBuffer_fx; + Word16 ismPreprocMatrix_fx[2][2][CLDFB_NO_CHANNELS_MAX]; + Word16 eneMoveIIR_fx[2][CLDFB_NO_CHANNELS_MAX]; + Word16 enePreserveIIR_fx[2][CLDFB_NO_CHANNELS_MAX]; + Word16 preprocEneTarget_fx[CLDFB_NO_CHANNELS_MAX]; + Word16 preprocEneRealized_fx[CLDFB_NO_CHANNELS_MAX]; #endif int16_t delayBuffer_size; diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 500b97308..3097ce03a 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -506,7 +506,7 @@ void ivas_dirac_dec_binaural_sba_gain( /*------------------------------------------------------------------------- * Local functions *------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static void ivas_dirac_dec_binaural_internal( Decoder_Struct *st_ivas, COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, @@ -520,6 +520,12 @@ static void ivas_dirac_dec_binaural_internal( int16_t slot, ch, numInChannels; float Cldfb_RealBuffer_in[6][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; float Cldfb_ImagBuffer_in[6][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + for (int i = 0; i < 6; i++) { + for (int j = 0; j < 4; j++) { + set_zero(Cldfb_RealBuffer_in[i][j], 60); + set_zero(Cldfb_ImagBuffer_in[i][j], 60); + } + } int16_t nchanSeparateChannels; float Rmat[3][3]; int16_t max_band_decorr; @@ -742,7 +748,360 @@ static void ivas_dirac_dec_binaural_internal( return; } +#else +static void ivas_dirac_dec_binaural_internal( + Decoder_Struct *st_ivas, + COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, + float *output_f[], + const int16_t nchan_transport, + const int16_t subframe ) +{ + //////////////////////////////////////////////////////////////////////////// + double maxim = 0; + Word16 q_input = 11; + IF(st_ivas->hTcBuffer->tc[nchan_transport]) + FOR(Word16 ind = 0; ind < st_ivas->cldfbAnaDec[1]->no_channels * st_ivas->cldfbAnaDec[1]->no_col; ind++) + { + st_ivas->hTcBuffer->tc_fx[nchan_transport][ind] = (Word32)(st_ivas->hTcBuffer->tc[nchan_transport][ind] * (1 << q_input)); + } + FOR(Word16 cha = 0; cha < 3 + max(1, st_ivas->nchan_ism); cha++) { + FOR(Word16 ind = 0; ind < st_ivas->hTcBuffer->n_samples_available; ind++) IF(st_ivas->hTcBuffer->tc[cha]) + { + st_ivas->hTcBuffer->tc_fx[cha][ind] = (Word32)(st_ivas->hTcBuffer->tc[cha][ind] * (1 << q_input)); + } + } + + FOR(Word16 cha = 0; cha < 3 + max(1, st_ivas->nchan_ism); cha++) { + IF(st_ivas->cldfbAnaDec[cha] && st_ivas->cldfbAnaDec[cha]->cldfb_state) + FOR(Word16 ind = 0; ind < st_ivas->cldfbAnaDec[cha]->cldfb_state_length; ind++) + { + st_ivas->cldfbAnaDec[cha]->cldfb_state_fx[ind] = (Word32)(st_ivas->cldfbAnaDec[cha]->cldfb_state[ind] * (1 << q_input)); + } + } + IF(st_ivas->hSCE[0] && st_ivas->hSCE[0]->hCoreCoder[0] && st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt >= (1 << 0)) assert(0); + IF(st_ivas->hSCE[0] && st_ivas->hSCE[0]->hCoreCoder[0]) st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->likelihood_noisy_speech = (Word16)(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt * (32767)); + st_ivas->cldfbAnaDec[1]->q_scale = 15; + IF(abs_s((Word16)st_ivas->cldfbAnaDec[1]->scale_flt) != 0) + st_ivas->cldfbAnaDec[1]->q_scale = norm_s((Word16)st_ivas->cldfbAnaDec[1]->scale_flt); + st_ivas->cldfbAnaDec[1]->scale = (Word16)(st_ivas->cldfbAnaDec[1]->scale_flt * (1 << st_ivas->cldfbAnaDec[1]->q_scale)); + maxim = 0; + IF(st_ivas->hSCE[0] && st_ivas->hSCE[0]->hCoreCoder[0]) + FOR(Word16 ind = 0; ind < FFTCLDFBLEN; ind++) + { + maxim = fmax(maxim, fabs(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[ind])); + } + IF(st_ivas->hSCE[0] && st_ivas->hSCE[0]->hCoreCoder[0]) + st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->q_cngNoiseLevel = 31; + IF(st_ivas->hSCE[0] && st_ivas->hSCE[0]->hCoreCoder[0] && L_abs((Word32)maxim)!=0) st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->q_cngNoiseLevel = norm_l((Word32)maxim); + IF(st_ivas->hSCE[0] && st_ivas->hSCE[0]->hCoreCoder[0]) + FOR(Word16 ind = 0; ind < FFTCLDFBLEN; ind++) + { + st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel[ind] = (Word32)(st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[ind] * (1<hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->q_cngNoiseLevel)); + } + Word16 q_cldfb[6][CLDFB_SLOTS_PER_SUBFRAME]; + FOR(Word16 ind = 0; ind < 6; ind++) + { + FOR(Word16 ind2 = 0; ind2 < 4; ind2++) + { + q_cldfb[ind][ind2] = q_input; + } + } + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + DIRAC_DEC_BIN_HANDLE hDiracDecBin; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; + PARAMBIN_REND_CONFIG config_data; + Word16 slot, ch, numInChannels; + float Cldfb_RealBuffer_in[6][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + Word32 Cldfb_RealBuffer_in_fx[6][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + Word32 Cldfb_ImagBuffer_in_fx[6][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + float Cldfb_ImagBuffer_in[6][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + for (int i = 0; i < 6; i++) { + for (int j = 0; j < 4; j++) { + set_zero(Cldfb_RealBuffer_in[i][j], 60); + set_zero(Cldfb_ImagBuffer_in[i][j], 60); + set32_fx(Cldfb_RealBuffer_in_fx[i][j], 0, 60); + set32_fx(Cldfb_ImagBuffer_in_fx[i][j], 0, 60); + } + } + Word16 nchanSeparateChannels; + Word32 Rmat_fx[3][3]; + float Rmat[3][3]; + Word16 max_band_decorr; + DIFFUSE_DISTRIBUTION_DATA diffuseDistData; + Word16 nBins, offsetSamples; + Word16 i, j; + hDiracDecBin = st_ivas->hDiracDecBin; + assert( hDiracDecBin ); + hSpatParamRendCom = st_ivas->hSpatParamRendCom; + nBins = hSpatParamRendCom->num_freq_bands; + offsetSamples = hSpatParamRendCom->slots_rendered * nBins; + + /* Setup internal config */ + config_data.separateCenterChannelRendering = st_ivas->hOutSetup.separateChannelEnabled; + move16(); + config_data.ivas_format = st_ivas->ivas_format; + config_data.mc_mode = st_ivas->mc_mode; + config_data.ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + move32(); + config_data.nchan_transport = st_ivas->nchan_transport; + move16(); + config_data.qualityBasedSmFactor = st_ivas->hMasa != NULL ? st_ivas->hMasa->data.dir_decode_quality : 1.0f; + config_data.processReverb = st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ? 1 : 0; + move16(); + IF ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + config_data.ism_mode = st_ivas->ism_mode; + } + ELSE + { + config_data.ism_mode = ISM_MODE_NONE; + } + + /* The input channel number at this processing function (not nchan_transport) */ + numInChannels = BINAURAL_CHANNELS; + IF ( config_data.separateCenterChannelRendering || ( st_ivas->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) ) ) + { + numInChannels = add(numInChannels, 1); + } + ELSE IF ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC && ( st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) + { + numInChannels = add(numInChannels, st_ivas->nchan_ism); + } + + Rmat_fx[0][0] = 32768; // 1 in Q15 + move32(); + Rmat_fx[0][1] = 0; + move32(); + Rmat_fx[0][2] = 0; + move32(); + + Rmat_fx[1][0] = 0; + move32(); + Rmat_fx[1][1] = 32768; // 1 in Q15 + move32(); + Rmat_fx[1][2] = 0; + move32(); + + Rmat_fx[2][0] = 0; + move32(); + Rmat_fx[2][1] = 0; + move32(); + Rmat_fx[2][2] = 32768; // 1 in Q15 + move32(); + + + Rmat[0][0] = 1.0f; + Rmat[0][1] = 0.0f; + Rmat[0][2] = 0.0f; + + Rmat[1][0] = 0.0f; + Rmat[1][1] = 1.0f; + Rmat[1][2] = 0.0f; + + Rmat[2][0] = 0.0f; + Rmat[2][1] = 0.0f; + Rmat[2][2] = 1.0f; + + /* CLDFB Analysis of input */ + FOR ( slot = 0; slot < hSpatParamRendCom->subframe_nbslots[subframe]; slot++ ) + { + FOR ( ch = 0; ch < numInChannels; ch++ ) + { + IF ( ch == 0 || nchan_transport == 2 ) + { + q_cldfb[ch][slot] = q_input; + move16(); + cldfbAnalysis_ts_fx_fixed_q( + &( st_ivas->hTcBuffer->tc_fx[ch][nBins * slot + offsetSamples] ), + Cldfb_RealBuffer_in_fx[ch][slot], + Cldfb_ImagBuffer_in_fx[ch][slot], + nBins, st_ivas->cldfbAnaDec[ch], &q_cldfb[ch][slot] ); + } + ELSE IF ( config_data.nchan_transport == 2 ) /* Stereo signal transmitted as mono with DFT stereo */ + { + /* At mono input duplicate the channel to dual-mono */ + mvl2l( Cldfb_RealBuffer_in_fx[0][slot], Cldfb_RealBuffer_in_fx[1][slot], nBins ); + mvl2l( Cldfb_ImagBuffer_in_fx[0][slot], Cldfb_ImagBuffer_in_fx[1][slot], nBins ); + q_cldfb[1][slot] = q_cldfb[0][slot]; + move16(); + } + ELSE /* when nchan_transport == 1 and ch == 1 */ + { + /* CNA and HB FD-CNG*/ + IF ( st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag ) + { + Word16 numCoreBands, b; + Word16 slotInFrame; + + numCoreBands = st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->numCoreBands; + move16(); + slotInFrame = add(hSpatParamRendCom->slots_rendered, slot); + + generate_masking_noise_dirac_fx( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom, + st_ivas->cldfbAnaDec[1], + st_ivas->hTcBuffer->tc_fx[nchan_transport], + Cldfb_RealBuffer_in_fx[2][slot], Cldfb_ImagBuffer_in_fx[2][slot], + slotInFrame, + st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && st_ivas->hSCE[0]->hCoreCoder[0]->flag_cna, + ( st_ivas->hSCE[0]->hCoreCoder[0]->core_brate == FRAME_NO_DATA || st_ivas->hSCE[0]->hCoreCoder[0]->core_brate == SID_2k40 ) && ( st_ivas->hSCE[0]->hCoreCoder[0]->cng_type == FD_CNG ) && st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag, + 11, &q_cldfb[2][slot] ); + + generate_masking_noise_dirac_fx( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom, + st_ivas->cldfbAnaDec[1], /*nothing will be analyzed, just get cnst*/ + NULL, + Cldfb_RealBuffer_in_fx[1][slot], Cldfb_ImagBuffer_in_fx[1][slot], + slotInFrame, + st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && st_ivas->hSCE[0]->hCoreCoder[0]->flag_cna, + ( st_ivas->hSCE[0]->hCoreCoder[0]->core_brate == FRAME_NO_DATA || st_ivas->hSCE[0]->hCoreCoder[0]->core_brate == SID_2k40 ) && ( st_ivas->hSCE[0]->hCoreCoder[0]->cng_type == FD_CNG ) && st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag, + 0, &q_cldfb[1][slot] ); + + /* LB: Copy first channel + LB-CNG to first and second channels with same scaling (dual-mono)*/ + FOR ( b = 0; b < numCoreBands; b++ ) + { + Cldfb_RealBuffer_in_fx[0][slot][b] = Mpy_32_16_1( L_add(L_shr(Cldfb_RealBuffer_in_fx[0][slot][b], q_cldfb[0][slot] - q_input + 5), L_shr(Cldfb_RealBuffer_in_fx[2][slot][b], q_cldfb[2][slot] - q_input + 5)), 23170/* INV_SQRT2 in Q15*/ ); + Cldfb_RealBuffer_in_fx[1][slot][b] = Cldfb_RealBuffer_in_fx[0][slot][b]; + move32(); + Cldfb_ImagBuffer_in_fx[0][slot][b] = Mpy_32_16_1( L_add(L_shr(Cldfb_ImagBuffer_in_fx[0][slot][b], q_cldfb[0][slot] - q_input + 5), L_shr(Cldfb_ImagBuffer_in_fx[2][slot][b], q_cldfb[2][slot] - q_input + 5)), 23170 ); + Cldfb_ImagBuffer_in_fx[1][slot][b] = Cldfb_ImagBuffer_in_fx[0][slot][b]; + move32(); + } + q_cldfb[1][slot] = q_input - 5; + q_cldfb[0][slot] = q_input - 5; + /* HB: Copy first channel to second channel and add HB-CNGs with different scalings*/ + FOR ( ; b < nBins; b++ ) + { + Cldfb_RealBuffer_in_fx[0][slot][b] = Mpy_32_16_1(Cldfb_RealBuffer_in_fx[0][slot][b], 23170); + Cldfb_RealBuffer_in_fx[1][slot][b] = L_add(L_add(Cldfb_RealBuffer_in_fx[0][slot][b], L_shr(Cldfb_RealBuffer_in_fx[1][slot][b], 1)), Cldfb_RealBuffer_in_fx[0][slot][b]); + Cldfb_RealBuffer_in_fx[0][slot][b] = L_add(Cldfb_RealBuffer_in_fx[0][slot][b], L_shr(Cldfb_RealBuffer_in_fx[2][slot][b], 1)); + + Cldfb_ImagBuffer_in_fx[0][slot][b] = Mpy_32_16_1(Cldfb_ImagBuffer_in_fx[0][slot][b], 23170); + Cldfb_ImagBuffer_in_fx[1][slot][b] = L_add(Cldfb_ImagBuffer_in_fx[0][slot][b], L_shr(Cldfb_ImagBuffer_in_fx[1][slot][b], 1)); + Cldfb_ImagBuffer_in_fx[0][slot][b] = L_add(Cldfb_ImagBuffer_in_fx[0][slot][b], L_shr(Cldfb_ImagBuffer_in_fx[2][slot][b], 1)); + } + } + ELSE + { + /* At mono input duplicate the channel to dual-mono, and apply gain + correction to ensure same overall level as in stereo mode */ + v_multc_fixed_16( Cldfb_RealBuffer_in_fx[0][slot], 23170, Cldfb_RealBuffer_in_fx[0][slot], nBins ); + v_multc_fixed_16( Cldfb_ImagBuffer_in_fx[0][slot], 23170, Cldfb_ImagBuffer_in_fx[0][slot], nBins ); + + mvl2l( Cldfb_RealBuffer_in_fx[0][slot], Cldfb_RealBuffer_in_fx[1][slot], nBins ); + mvl2l( Cldfb_ImagBuffer_in_fx[0][slot], Cldfb_ImagBuffer_in_fx[1][slot], nBins ); + q_cldfb[1][slot] = q_cldfb[0][slot]; + move16(); + } + } + } + + IF ( hDiracDecBin->useTdDecorr ) + { + FOR ( ch = BINAURAL_CHANNELS; ch < ( 2 * BINAURAL_CHANNELS ); ch++ ) + { + q_cldfb[ch][slot] = q_input; + cldfbAnalysis_ts_fx_fixed_q( + &( st_ivas->hTcBuffer->tc_fx[ch][nBins * slot + offsetSamples] ), + Cldfb_RealBuffer_in_fx[ch][slot], + Cldfb_ImagBuffer_in_fx[ch][slot], + nBins, st_ivas->cldfbAnaDec[ch], &q_cldfb[ch][slot] ); + IF ( config_data.nchan_transport == 1 && + ( config_data.ivas_format == SBA_FORMAT || config_data.ivas_format == SBA_ISM_FORMAT ) ) + { + v_multc_fixed_16( Cldfb_RealBuffer_in_fx[ch][slot], 23170, Cldfb_RealBuffer_in_fx[ch][slot], nBins ); + v_multc_fixed_16( Cldfb_ImagBuffer_in_fx[ch][slot], 23170, Cldfb_ImagBuffer_in_fx[ch][slot], nBins ); + } + } + } + } + + ////////////////////////////////////////////////////////////////////////////////////////////// + FOR(Word16 cha = 0; cha < 3 + max(1, st_ivas->nchan_ism); cha++) IF(st_ivas->cldfbAnaDec[cha] && st_ivas->cldfbAnaDec[cha]->cldfb_state) + FOR(Word16 ind = 0; ind < st_ivas->cldfbAnaDec[cha]->cldfb_state_length; ind++) + { + st_ivas->cldfbAnaDec[cha]->cldfb_state[ind] = (float)(st_ivas->cldfbAnaDec[cha]->cldfb_state_fx[ind]) / (float)(1 << q_input); + } + FOR(Word16 cha = 0; cha < 6; cha++) FOR(slot = 0; slot < 4; slot++) + FOR(Word16 ind = 0; ind < 60; ind++) + { + Cldfb_RealBuffer_in[cha][slot][ind] = (float)Cldfb_RealBuffer_in_fx[cha][slot][ind] / (float)(1 << (q_cldfb[cha][slot])); + Cldfb_ImagBuffer_in[cha][slot][ind] = (float)Cldfb_ImagBuffer_in_fx[cha][slot][ind] / (float)(1 << (q_cldfb[cha][slot])); + } + + ////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + if ( config_data.ivas_format == SBA_FORMAT || config_data.ivas_format == SBA_ISM_FORMAT ) + { + hDiracDecBin->hDiffuseDist = &diffuseDistData; + + ivas_spar_param_to_masa_param_mapping( st_ivas, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, subframe ); + ivas_sba_prototype_renderer( st_ivas, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, subframe ); + } + + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && nchan_transport == 2 && st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) + { + ivas_omasa_preProcessStereoTransportsForMovedObjects( st_ivas, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, nBins, subframe ); + } + + if ( hCombinedOrientationData ) + { + for ( i = 0; i < 3; i++ ) + { + for ( j = 0; j < 3; j++ ) + { + Rmat[i][j] = hCombinedOrientationData->Rmat[hCombinedOrientationData->subframe_idx][i][j]; + } + } + + if ( nchan_transport == 2 ) + { + adaptTransportSignalsHeadtracked( hCombinedOrientationData, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, nBins, hSpatParamRendCom->subframe_nbslots[subframe], Rmat ); + + ivas_dirac_dec_binaural_check_and_switch_transports_headtracked( hCombinedOrientationData, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, nBins, hSpatParamRendCom->subframe_nbslots[subframe], Rmat ); + } + } + + ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matrices( hDiracDecBin, hSpatParamRendCom, &config_data, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, Rmat, subframe, + hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, st_ivas->hMasaIsmData ); + + if ( config_data.ivas_format == ISM_FORMAT ) + { + max_band_decorr = 0; + } + else if ( hDiracDecBin->useTdDecorr ) + { + max_band_decorr = CLDFB_NO_CHANNELS_MAX; + } + else + { + max_band_decorr = hDiracDecBin->h_freq_domain_decorr_ap_params->max_band_decorr; + } + + + + nchanSeparateChannels = 0; + if ( config_data.separateCenterChannelRendering || ( st_ivas->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) ) ) + { + nchanSeparateChannels = 1; + } + else if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC && ( st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) + { + nchanSeparateChannels = (uint8_t) st_ivas->nchan_ism; + } + + ivas_dirac_dec_binaural_determine_processing_matrices( hDiracDecBin, hSpatParamRendCom, &config_data, max_band_decorr, Rmat, subframe, + hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, nchanSeparateChannels, st_ivas->hMasaIsmData ); + + ivas_dirac_dec_binaural_process_output( hDiracDecBin, hSpatParamRendCom, st_ivas->cldfbSynDec, output_f, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, max_band_decorr, numInChannels, config_data.processReverb, subframe ); + + hDiracDecBin->hDiffuseDist = NULL; + + hSpatParamRendCom->slots_rendered += hSpatParamRendCom->subframe_nbslots[subframe]; + hSpatParamRendCom->subframes_rendered++; + + return; +} +#endif static void ivas_dirac_dec_decorrelate_slot( DIRAC_DEC_BIN_HANDLE hDiracDecBin, diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index d3a8e5543..79eafa714 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -1626,10 +1626,17 @@ void rotateFrame_sd( const int16_t subframe_idx /* i : subframe index */ ); #endif +#ifdef IVAS_FLOAT_FIXED +void ivas_combined_orientation_update_index( + COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i/o: combined orientation handle */ + const Word16 samples_rendered /* i : samples rendered since the last call */ +); +#else void ivas_combined_orientation_update_index( COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i/o: combined orientation handle */ const int16_t samples_rendered /* i : samples rendered since the last call */ ); +#endif #ifdef IVAS_FLOAT_FIXED void ivas_combined_orientation_update_start_index( COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i/o: combined orientation handle */ diff --git a/lib_rend/ivas_rotation.c b/lib_rend/ivas_rotation.c index 611701a0b..2fcc1860f 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -2496,6 +2496,7 @@ void SHrotmatgen( * update read index based on the number of rendered samples *------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_combined_orientation_update_index( COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i/o: combined orientation handle */ const int16_t samples_rendered /* i : samples rendered since the last call */ @@ -2519,6 +2520,37 @@ void ivas_combined_orientation_update_index( return; } +#else +void ivas_combined_orientation_update_index( + COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i/o: combined orientation handle */ + const Word16 samples_rendered /* i : samples rendered since the last call */ +) +{ + Word16 exp, div_result; + IF ( hCombinedOrientationData != NULL ) + { + IF ( EQ_16(hCombinedOrientationData->num_subframes, 1) ) + { + /* only one orientation available anyway or split rendering with low resolution*/ + hCombinedOrientationData->subframe_idx = 0; + move16(); + } + ELSE + { + hCombinedOrientationData->cur_subframe_samples_rendered = add(hCombinedOrientationData->cur_subframe_samples_rendered, samples_rendered); + div_result = BASOP_Util_Divide3216_Scale(hCombinedOrientationData->cur_subframe_samples_rendered, hCombinedOrientationData->subframe_size, &exp); + hCombinedOrientationData->subframe_idx = add(hCombinedOrientationData->subframe_idx, shl(div_result, exp + 1)); + hCombinedOrientationData->cur_subframe_samples_rendered = hCombinedOrientationData->cur_subframe_samples_rendered % hCombinedOrientationData->subframe_size; + move16(); + hCombinedOrientationData->subframe_idx = s_min( hCombinedOrientationData->subframe_idx, hCombinedOrientationData->num_subframes - 1 ); + } + } + + return; +} +#endif + + #ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- -- GitLab