diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index 872c180b56e4807da3521a9b68f021b01e256dc6..2079257245fac4fa09babd2a22c751b868d0c2c7 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -120,6 +120,8 @@ void ivas_initFdCngCom_fx( HANDLE_FD_CNG_COM hFdCngCom, Word16 scale ) move16(); hFdCngCom->CngBitrate = -1; move16(); + hFdCngCom->olapBufferSynth_exp = 0; + move16(); /* Initialize noise estimation algorithm */ set32_fx( hFdCngCom->periodog, 0, PERIODOGLEN ); @@ -2653,9 +2655,10 @@ void SynthesisSTFT_ivas_fx( const Word16 nchan_out /* i : number of output channels */ ) { - Word16 i, len, scale, tmp; + Word16 i, len, scale, tmp, sft, exp, tmp1; Word16 len2, len3, len4; Word16 buf[M + 1 + L_FRAME16k]; + Word32 L_olapBuffer[FFTLEN]; /* Perform IFFT */ @@ -2666,6 +2669,12 @@ void SynthesisSTFT_ivas_fx( hFdCngCom->fftBuffer_exp = fftBufferExp; move16(); + sft = getScaleFactor32( fftBuffer, hFdCngCom->fftlen ); + scale_sig32( fftBuffer, hFdCngCom->fftlen, sft ); + fftBufferExp = sub( fftBufferExp, sft ); + hFdCngCom->fftBuffer_exp = fftBufferExp; + move16(); + fftBufferExp = add( fftBufferExp, hFdCngCom->fftlenShift ); /* Perform overlap-add */ @@ -2679,48 +2688,58 @@ void SynthesisSTFT_ivas_fx( } ELSE { - Copy( olapBuffer + hFdCngCom->frameSize, olapBuffer, hFdCngCom->frameSize ); + Copy_Scale_sig_16_32_no_sat( olapBuffer + hFdCngCom->frameSize, L_olapBuffer, hFdCngCom->frameSize, add( sub( hFdCngCom->olapBufferSynth_exp, sub( 15, hFdCngCom->fftlenShift ) ), 16 ) ); /* exp: hFdCngCom->olapBufferSynth_exp -> (15 - fftlenShift) */ set16_fx( olapBuffer + hFdCngCom->frameSize, 0, hFdCngCom->frameSize ); } len2 = shr( hFdCngCom->fftlen, 2 ); len4 = shr( hFdCngCom->fftlen, 3 ); len3 = add( len2, len4 ); len = add( hFdCngCom->frameSize, len4 ); + tmp1 = sub( fftBufferExp, 15 ); IF( tcx_transition ) { FOR( i = 0; i < len; i++ ) { - olapBuffer[i] = round_fx_sat( L_shl_sat( fftBuffer[i], fftBufferExp - 15 ) ); // Q(15 - fftBufferExp) - move16(); + L_olapBuffer[i] = L_shl_sat( fftBuffer[i], tmp1 ); /* Q(31 - (15 - fftlenShift) ) */ + move32(); } } ELSE { FOR( i = 0; i < len4; i++ ) { - olapBuffer[i + 1 * len4] = add_sat( olapBuffer[i + 1 * len4], mult_r( round_fx_sat( L_shl_sat( fftBuffer[i + 1 * len4], fftBufferExp - 15 ) ), olapWin[i].v.im ) ); - move16(); - olapBuffer[i + 2 * len4] = add_sat( olapBuffer[i + 2 * len4], mult_r( round_fx_sat( L_shl_sat( fftBuffer[i + 2 * len4], fftBufferExp - 15 ) ), olapWin[len4 - 1 - i].v.re ) ); - move16(); + L_olapBuffer[i + 1 * len4] = Madd_32_16( L_olapBuffer[i + 1 * len4], L_shl_sat( fftBuffer[i + 1 * len4], tmp1 ), olapWin[i].v.im ); /* Q(31 - (15 - fftlenShift) ) */ + move32(); + L_olapBuffer[i + 2 * len4] = Madd_32_16( L_olapBuffer[i + 2 * len4], L_shl_sat( fftBuffer[i + 2 * len4], tmp1 ), olapWin[len4 - 1 - i].v.re ); /* Q(31 - (15 - fftlenShift) ) */ + move32(); } FOR( i = len3; i < len; i++ ) { - olapBuffer[i] = round_fx_sat( L_shl_sat( fftBuffer[i], fftBufferExp - 15 ) ); + L_olapBuffer[i] = L_shl_sat( fftBuffer[i], tmp1 ); /* Q(31 - (15 - fftlenShift) ) */ + move32(); } } FOR( i = 0; i < len4; i++ ) { - olapBuffer[i + 5 * len4] = mult_r( round_fx_sat( L_shl_sat( fftBuffer[i + 5 * len4], fftBufferExp - 15 ) ), olapWin[i].v.re ); - move16(); - olapBuffer[i + 6 * len4] = mult_r( round_fx_sat( L_shl_sat( fftBuffer[i + 6 * len4], fftBufferExp - 15 ) ), olapWin[len4 - 1 - i].v.im ); - move16(); + L_olapBuffer[i + 5 * len4] = Mpy_32_16_1( L_shl_sat( fftBuffer[i + 5 * len4], tmp1 ), olapWin[i].v.re ); /* Q(31 - (15 - fftlenShift) ) */ + move32(); + L_olapBuffer[i + 6 * len4] = Mpy_32_16_1( L_shl_sat( fftBuffer[i + 6 * len4], tmp1 ), olapWin[len4 - 1 - i].v.im ); /* Q(31 - (15 - fftlenShift) ) */ + move32(); } len = add( len, len2 ); FOR( i = len; i < hFdCngCom->fftlen; i++ ) { - olapBuffer[i] = 0; + L_olapBuffer[i] = 0; + move32(); + } + + sft = L_norm_arr( L_olapBuffer, hFdCngCom->fftlen ); + IF( NE_16( sft, 31 ) ) + { + Copy_Scale_sig32_16( L_olapBuffer, olapBuffer, hFdCngCom->fftlen, sft ); + hFdCngCom->olapBufferSynth_exp = sub( sub( 15, hFdCngCom->fftlenShift ), sft ); move16(); } @@ -2737,24 +2756,23 @@ void SynthesisSTFT_ivas_fx( buf[i] = mult_r( olapBuffer[i + len4 - M - 1], hFdCngCom->fftlenFac ); move16(); } + exp = add( hFdCngCom->olapBufferSynth_exp, hFdCngCom->fftlenShift ); tmp = buf[0]; } IF( EQ_16( gen_exc, 1 ) ) { - Word16 s = getScaleFactor16( buf + 1, M + hFdCngCom->frameSize ); - if ( GT_16( *Q_new, s ) ) - { - *Q_new = s; - move16(); - } - - E_UTIL_f_preemph2( *Q_new - 1, buf + 1, PREEMPH_FAC, M + hFdCngCom->frameSize, &tmp ); - Residu3_fx( hFdCngCom->A_cng, buf + 1 + M, hFdCngCom->exc_cng, hFdCngCom->frameSize, 1 ); + E_UTIL_f_preemph2( 0, buf + 1, PREEMPH_FAC, add( M, hFdCngCom->frameSize ), &tmp ); + Residu3_fx( hFdCngCom->A_cng, buf + 1 + M, hFdCngCom->exc_cng, hFdCngCom->frameSize, 0 ); + *Q_new = sub( 15, exp ); + move16(); } IF( EQ_16( gen_exc, 2 ) ) { - *Q_new = E_UTIL_f_preemph3( buf + 1, PREEMPH_FAC, M + hFdCngCom->frameSize, &tmp, 1 ); - Residu3_fx( hFdCngCom->A_cng, buf + 1 + M, hFdCngCom->exc_cng, hFdCngCom->frameSize, 1 ); + *Q_new = E_UTIL_f_preemph3( buf + 1, PREEMPH_FAC, add( M, hFdCngCom->frameSize ), &tmp, 0 ); + move16(); + Residu3_fx( hFdCngCom->A_cng, buf + 1 + M, hFdCngCom->exc_cng, hFdCngCom->frameSize, negate( *Q_new ) ); + *Q_new = sub( 15, exp ); + move16(); } } diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 044a06b5bae06c1ebe365b05b639173e0d85176f..9a2597db69d46f43d1380eaba5c48a52bc4cccca 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -6512,6 +6512,18 @@ void hf_synth_fx( const Word16 Q_syn2 /* i : synthesis scaling */ ); +void hf_synth_ivas_fx( + ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 *Aq, /* i : quantized Az Q12*/ + const Word16 *exc, /* i : excitation at 12.8 kHz Q_exc*/ + Word16 *synth, /* i : 12.8kHz synthesis signal Q_syn2*/ + Word16 *synth16k, /* o : 16kHz synthesis signal Q_syn2*/ + const Word16 Q_exc, /* i : excitation scaling */ + const Word16 Q_syn2 /* i : synthesis scaling */ +); + void hf_synth_amr_wb_init_fx( AMRWB_IO_DEC_HANDLE hAmrwb_IO /* i/o: AMR-WB IO data handle */ ); @@ -10139,6 +10151,12 @@ void hp400_12k8_fx( Word16 mem[] /* i/o: filter memory [6] */ ); +void hp400_12k8_ivas_fx( + Word16 signal[], /* i/o: input signal / output is divided by 16 */ + const Word16 lg, /* i : lenght of signal */ + Word16 mem[] /* i/o: filter memory [6] */ +); + Word16 dot_prod_satcontr( const Word16 *x, const Word16 *y, Word16 qx, Word16 qy, Word16 *qo, Word16 len ); void E_UTIL_f_convolve( const Word16 x[], const Word16 h[], Word16 y[], const Word16 size ); diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index f99d498027a98db71cfbed521e46712659506917..80822f59e999002977b27fcd97ab7095a469e10b 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -377,7 +377,8 @@ typedef struct Word16 *olapBufferAna; /* q_olapBufferAna */ /* points to FD_CNG_DEC->olapBufferAna[FFTLEN] in case of decoder */ Word16 olapBufferAna_fx[FFTLEN]; /* q_olapBufferAna_fx */ /* points to FD_CNG_DEC->olapBufferAna[FFTLEN] in case of decoder */ Word16 olapBufferSynth[FFTLEN]; /* q_olapBuffer */ - Word16 *olapBufferSynth2; /*Q_syn*/ /* points to FD_CNG_DEC->olapBufferSynth2[FFTLEN] in case of decoder */ + Word16 olapBufferSynth_exp; + Word16 *olapBufferSynth2; /*Q_syn*/ /* points to FD_CNG_DEC->olapBufferSynth2[FFTLEN] in case of decoder */ const PWord16 *olapWinAna; const PWord16 *olapWinSyn; diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index 77e779efdcb1844eb7e56cee51b25079083aca26..b3471e50c383e782a70bc6f743573912a313d30b 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -3864,6 +3864,58 @@ void hp400_12k8_fx( return; } +void hp400_12k8_ivas_fx( + Word16 signal[], /* i/o: input signal / output is divided by 16 */ + const Word16 lg, /* i : lenght of signal */ + Word16 mem[] /* i/o: filter memory [6] */ +) +{ + Word16 i; + Word16 x0, x1, x2; + Word32 L_tmp, yy1, y2; + + yy1 = L_Comp( mem[2], mem[3] ); /* Q_syn + 13 */ + y2 = L_Comp( mem[0], mem[1] ); /* Q_syn + 13 */ + x0 = mem[4]; /* Q_syn */ + move16(); + x1 = mem[5]; /* Q_syn */ + move16(); + + FOR( i = 0; i < lg; i++ ) + { + x2 = x1; /* Q_syn */ + move16(); + x1 = x0; /* Q_syn */ + move16(); + x0 = signal[i]; /* Q_syn */ + move16(); + + L_tmp = Mpy_32_16_1( yy1, a_hp400_ivas_fx[1] ); /*yy1 * a_hp400[1]*/ /* Qx(Q_of_yy1) + 10 ---->( (Q_syn+13) + 12 - 15)*/ + L_tmp = Madd_32_16( L_tmp, y2, a_hp400_ivas_fx[2] ); /*y2 * a_hp400[2]*/ /* Qx + 10 ---->( (Q_syn+13) + 12 - 15)*/ + L_tmp = L_shl( L_tmp, 3 ); /* shifting by 3 to maintain same Q (Q_syn+13) */ + + L_tmp = L_mac( L_tmp, x0, b_hp400_fx[0] ); /* Q_syn + 13 */ + L_tmp = L_mac( L_tmp, x1, b_hp400_fx[1] ); /* Q_syn + 13 */ + L_tmp = L_mac( L_tmp, x2, b_hp400_fx[2] ); /* Q_syn + 13 */ + + y2 = yy1; /* Q_syn + 13 */ + move32(); + yy1 = L_tmp; /* Q_syn + 13 */ + move32(); + + signal[i] = round_fx( L_tmp ); /* Q_syn - 3 */ + move16(); + } + + L_Extract( yy1, &mem[2], &mem[3] ); + L_Extract( y2, &mem[0], &mem[1] ); + mem[4] = x0; /* Q_syn */ + mem[5] = x1; /* Q_syn */ + move16(); + move16(); + return; +} + Word16 dot_prod_satcontr( const Word16 *x, const Word16 *y, Word16 qx, Word16 qy, Word16 *qo, Word16 len ) { Word16 tmp_tab_x[L_FRAME16k]; diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index 2fff712f931c660f6a6c0724fd164b92bc8ac994..fd0c8ce2d12688e55ecfdf169e8d9e1699e9cf84 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -2289,7 +2289,7 @@ ivas_error acelp_core_dec_fx( ELSE { Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); // Q0 - hf_synth_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc2_fx, psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2 ); + hf_synth_ivas_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc2_fx, psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2 ); Copy_Scale_sig_16_32_DEPREC( synth_fx16, synth_fx, output_frame, 0 ); } } diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index cc83eeca320bd3c993587d97b9320ebfc768e0c4..99d202870cbccbacc182b78771e2a9547455ba02 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -2968,7 +2968,9 @@ void generate_comfort_noise_dec_ivas_fx( Word32 tmp1, tmp2; Word16 scaleCldfb; Word32 *fftBuffer = hFdCngCom->fftBuffer; /*hFdCngCom->fftBuffer_exp*/ - Word16 fftBuffer_exp = hFdCngCom->fftBuffer_exp; + Word16 fftBuffer_exp, fftBuffer_exp2; + fftBuffer_exp = hFdCngCom->fftBuffer_exp; + move16(); Word16 fftBuffer_temp_exp[FFTLEN]; Word16 *timeDomainOutput = hFdCngCom->timeDomainBuffer; Word16 temp; @@ -3001,6 +3003,8 @@ void generate_comfort_noise_dec_ivas_fx( hFdCngCom->fftBuffer_exp = fftBuffer_exp; move16(); set16_fx( fftBuffer_temp_exp, fftBuffer_exp, FFTLEN ); + fftBuffer_exp2 = fftBuffer_exp; + move16(); fftBuffer_exp = 0; move16(); @@ -3158,9 +3162,16 @@ void generate_comfort_noise_dec_ivas_fx( /* Perform STFT synthesis */ SynthesisSTFT_ivas_fx( fftBuffer, fftBuffer_exp, timeDomainOutput, hFdCngCom->olapBufferSynth, hFdCngCom->olapWinSyn, - tcx_transition, hFdCngCom, gen_exc, Q_new, st->element_mode, nchan_out ); - scale_sig32( fftBuffer + hFdCngCom->fftlen, sub( FFTLEN, hFdCngCom->fftlen ), sub( fftBuffer_exp, hFdCngCom->fftBuffer_exp ) ); /*Q31 - fftBuffer_exp*/ - + tcx_transition, hFdCngCom, gen_exc, Q_new, st->element_mode, nchan_out ); /* fftBuffer in hfDCngCom->fftBuffer_exp */ + /* fftBuffer now in different Qs [0 to fftlen - 1] = hfDCngCom->fftBuffer_exp and [fftlen to FFTLEN(640)] = fftBuffer_exp2, bringing it in common exponent */ + Word16 shift1 = L_norm_arr( fftBuffer, hFdCngCom->fftlen ); + Word16 shift2 = L_norm_arr( fftBuffer + hFdCngCom->fftlen, sub( FFTLEN, hFdCngCom->fftlen ) ); + Word16 shift = s_max( sub( hFdCngCom->fftBuffer_exp, shift1 ), sub( fftBuffer_exp2, shift2 ) ); + + scale_sig32( fftBuffer, hFdCngCom->fftlen, sub( hFdCngCom->fftBuffer_exp, shift ) ); + scale_sig32( fftBuffer + hFdCngCom->fftlen, sub( FFTLEN, hFdCngCom->fftlen ), sub( fftBuffer_exp2, shift ) ); + hFdCngCom->fftBuffer_exp = shift; + move16(); { Word32 Lener, att; Word16 exp; diff --git a/lib_dec/hf_synth_fx.c b/lib_dec/hf_synth_fx.c index 65c2e9290ab40cbdfd90c6883b33adaaac01d0ec..27d768f631bb7b007adeeae34f78ffe698833ad7 100644 --- a/lib_dec/hf_synth_fx.c +++ b/lib_dec/hf_synth_fx.c @@ -21,6 +21,7 @@ static void filt_6k_7k_scale_fx( Word16 signal[], Word16 lg, Word16 mem[], Word16 fact, Word16 exp ); static void hf_synthesis_fx( ZERO_BWE_DEC_HANDLE hBWE_zero, const Word32 core_brate, const Word16 output_subfr, const Word16 Aq[], const Word16 exc[], const Word16 Q_exc, Word16 synth[], Word16 synth16k[], const Word16 Q_syn ); +static void hf_synthesis_ivas_fx( ZERO_BWE_DEC_HANDLE hBWE_zero, const Word32 core_brate, const Word16 output_subfr, const Word16 Aq[], const Word16 exc[], const Word16 Q_exc, Word16 synth[], Word16 synth16k[], const Word16 Q_syn ); static void hf_synthesis_amr_wb_fx( const Word32 core_brate, const Word16 output_subfr, const Word16 Ap[], Word16 exc16k[], Word16 synth_out[], Word16 *mem_syn_hf, Word16 *delay_syn_hf, Word16 *mem_hp_interp, Word16 p_r, Word16 HF_corr_gain, Word16 til, Word16 voice_factors, const Word16 exc[], const Word16 Q_exc, const Word16 Q_out, Word16 qhf ); static void envelope_fx( AMRWB_IO_DEC_HANDLE hAmrwb_IO, const Word32 core_brate, const Word16 Aq[], Word16 Ap[], Word16 *r, Word16 tilt0, Word16 tilt, Word16 voice_factor ); static void AdaptiveStartBand_fx( Word16 *start_band, const Word32 rate, const Word16 *lsf, const Word16 voicing_fac, const Word16 clas, Word16 *voicing_flag, Word16 *start_band_old, Word32 *OptCrit_old ); @@ -291,7 +292,213 @@ static void hf_synthesis_fx( { Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); /* Q_syn */ } + Vr_add( synth16k, upsampled_HF_syn, synth16k, output_subfr ); + + return; +} + +void hf_synth_ivas_fx( + ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 *Aq, /* i : quantized Az Q12*/ + const Word16 *exc, /* i : excitation at 12.8 kHz Q_exc*/ + Word16 *synth, /* i : 12.8kHz synthesis signal Q_syn2*/ + Word16 *synth16k, /* o : 16kHz synthesis signal Q_syn2*/ + const Word16 Q_exc, /* i : excitation scaling */ + const Word16 Q_syn2 /* i : synthesis scaling */ +) +{ + const Word16 *p_Aq; + Word16 i_subfr, output_subfr; + + output_subfr = shr( output_frame, 2 ); + + p_Aq = Aq; /* Q12 */ + FOR( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR ) + { + hf_synthesis_ivas_fx( hBWE_zero, core_brate, output_subfr, p_Aq, &exc[i_subfr], Q_exc, &synth[i_subfr], &synth16k[i_subfr * output_subfr / L_SUBFR], Q_syn2 ); + + p_Aq += ( M + 1 ); /* Q12 */ + } + + return; +} + +static void hf_synthesis_ivas_fx( + ZERO_BWE_DEC_HANDLE hBWE_zero, + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 output_subfr, /* i : output sub-frame length Q0*/ + const Word16 Aq[], /* i : quantized Az Q12*/ + const Word16 exc[], /* i : excitation at 12.8 kHz Q_exc*/ + const Word16 Q_exc, /* i : excitation scaling */ + Word16 synth[], /* i : 12.8kHz synthesis signal Q_syn*/ + Word16 synth16k[], /* i/o: 16kHz synthesis signal Q_syn*/ + const Word16 Q_syn /* i : synthesis scaling */ +) +{ + Word16 i, s; + Word16 HF_syn[L_SUBFR16k], upsampled_HF_syn[L_FRAME48k / NB_SUBFR]; + Word16 HF_exc[L_SUBFR16k]; + Word16 exp1, exp2, scale, tmp, ener, Q_tmp, Q_ener, sft; + Word32 L_tmp, ONE, P_ONE; + Word16 Ap[M16k + 1]; + Word64 prod; + + /*-----------------------------------------------------------------* + * generate white noise vector + *-----------------------------------------------------------------*/ + + Random_Fill( &hBWE_zero->seed2, L_SUBFR16k, HF_exc, 3 ); /* 3 = Shift Right by 3 */ + + /* o: HF_exc in Q(-3) */ + + /*-----------------------------------------------------------------* + * calculate energy scaling factor so that white noise would have the + * same energy as exc12k8 + *-----------------------------------------------------------------*/ + + /*ener = sum2_f( exc, L_SUBFR ) + 0.01f*/ + ener = extract_h( Dot_product12( exc, exc, L_SUBFR, &exp2 ) ); + exp2 = sub( exp2, add( Q_exc, Q_exc ) ); // ener exponent + + /*tmp = round_fx(Dot_product12(HF_exc, HF_exc, output_subfr, &exp1)); */ + L_tmp = Dot_product12( HF_exc, HF_exc, L_SUBFR16k, &exp1 ); + tmp = round_fx( L_tmp ); + exp1 = add( exp1, 6 ); /* tmp exponent */ + + ener = shr( ener, 1 ); /* to avoid the assertion in div_s() further*/ + exp2 = add( exp2, 1 ); + + tmp = div_s( ener, tmp ); + exp1 = sub( exp2, exp1 ); + + scale = Sqrt16( tmp, &exp1 ); /* scale exponent = exp1 */ + + /*-----------------------------------------------------------------* + * calculate energy scaling factor to respect tilt of synth12k8 + * (tilt: 1=voiced, -1=unvoiced) + *-----------------------------------------------------------------*/ + + hp400_12k8_ivas_fx( synth, L_SUBFR, hBWE_zero->mem_hp400_fx ); + + /* i: mem_hp400 in Q_syn */ + /* i: synth in Q_syn */ + /* o: synth in Q_syn-3 */ + prod = W_mac0_16_16( 1L, synth[0], synth[0] ); /* 2*(Q_syn-3) */ + FOR( i = 1; i < L_SUBFR; i++ ) + { + prod = W_mac0_16_16( prod, synth[i], synth[i] ); /* 2*(Q_syn-3) */ + } + sft = W_norm( prod ); + ener = extract_h( W_extract_h( W_shl( prod, sft ) ) ); + Q_ener = sub( add( shl( sub( Q_syn, 3 ), 1 ), sft ), 48 ); + + prod = W_mac0_16_16( 1L, synth[1], synth[0] ); /* 2*(Q_syn-3) */ + FOR( i = 2; i < L_SUBFR; i++ ) + { + prod = W_mac0_16_16( prod, synth[i], synth[i - 1] ); /* 2*(Q_syn-3) */ + } + sft = sub( W_norm( prod ), 1 ); + tmp = extract_h( W_extract_h( W_shl( prod, sft ) ) ); + Q_tmp = sub( add( shl( sub( Q_syn, 3 ), 1 ), sft ), 48 ); + tmp = s_max( 0, tmp ); + IF( tmp > 0 ) + { + tmp = div_s( tmp, ener ); + Q_tmp = add( 15, sub( Q_tmp, Q_ener ) ); + } + + /*-----------------------------------------------------------------* + * modify energy of white noise according to synthesis tilt + *-----------------------------------------------------------------*/ + /* tmp = 1.0 - fac */ + ONE = L_shl( 1, Q_tmp ); + P_ONE = L_shl( 3277 /* 0.1 in Q15 */, sub( Q_tmp, 15 ) ); + L_tmp = L_msu0( ONE, tmp, 1 ); + test(); + if ( core_brate == FRAME_NO_DATA || EQ_32( core_brate, SID_2k40 ) ) + { + /* emphasize HF noise in CNG */ + /*fac *= 2.0f;*/ + L_tmp = L_add( L_tmp, L_tmp ); + } + L_tmp = L_max( L_tmp, P_ONE ); + L_tmp = L_min( L_tmp, ONE ); + + sft = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, sft ); + + tmp = round_fx( L_tmp ); + Q_tmp = sub( add( Q_tmp, sft ), 16 ); + + /*scale *= fac;*/ + tmp = mult_r( scale, tmp ); /* Q = (15 - exp1) + Q_tmp - 15 */ + Q_tmp = sub( Q_tmp, exp1 ); + /*-----------------------------------------------------------------* + * modify HF excitation according to both calculated scaling factors + * high pass filtering (0.94ms of delay) + *-----------------------------------------------------------------*/ + + exp2 = sub( hBWE_zero->memExp1, exp1 ); + hBWE_zero->memExp1 = exp1; + move16(); + + filt_6k_7k_scale_fx( HF_exc, L_SUBFR16k, hBWE_zero->mem_hf_fx, tmp, exp2 ); + /* i: HF_exc in Q(-3) */ + /* o: HF_exc in ((-3) + Q_tmp - 17) */ + /* o: hBWE_zero->mem_hf_fx in Q(HF_exc)-2 */ + + /*-----------------------------------------------------------------* + * synthesis of noise: 4.8kHz..5.6kHz --> 6kHz..7kHz + *-----------------------------------------------------------------*/ + + /*weight_a( Aq, Ap, 0.6f, M );*/ + weight_a_lc_fx( Aq, Ap, Gamma_19661_Tbl_fx, M ); + /* o: Ap in Q14 */ + + Syn_filt_s( 0, Ap, M, HF_exc, HF_syn, L_SUBFR16k, hBWE_zero->mem_syn_hf_fx, 1 ); + /* o: HF_syn in same Q as HF_exc */ + /* o: mem_syn_hf_fx same Q as HF_syn */ + + Scale_sig( HF_syn, L_SUBFR16k, ( add( Q_syn, exp1 ) ) ); /* bring HF_syn to (Q_syn+exp1) */ + + /*-----------------------------------------------------------------* + * add filtered HF noise to speech synthesis + *-----------------------------------------------------------------*/ + + /* delay by 5 samples @16kHz to compensate CLDFB resampling delay (20samples) and HP filtering delay (roughly 15 samples) */ + delay_signal_fx( HF_syn, L_SUBFR16k, hBWE_zero->delay_syn_hf_fx, NS2SA_FX2( 16000, DELAY_CLDFB_NS ) - 15 ); + + /* interpolate the HF synthesis */ + IF( EQ_16( output_subfr, L_SUBFR48k ) ) /* 48kHz sampled output */ + { + s = s_max( s_min( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( hBWE_zero->mem_hp_interp_fx, INTERP_3_1_MEM_LEN - 3 ) ), 3 ), + sub( Find_Max_Norm16( hBWE_zero->mem_hp_interp_fx + INTERP_3_1_MEM_LEN - 3, 3 ), 1 ) ), + 0 ); + Scale_sig( HF_syn, L_SUBFR16k, s ); /* Q_syn+exp1+s */ + Scale_sig( hBWE_zero->mem_hp_interp_fx, INTERP_3_1_MEM_LEN, s ); /* Qx + s */ + interpolate_3_over_1_allpass_fx( HF_syn, L_SUBFR16k, upsampled_HF_syn, hBWE_zero->mem_hp_interp_fx ); + Scale_sig( upsampled_HF_syn, 3 * L_SUBFR16k, -s ); /* Q_syn + exp1 + s */ + Scale_sig( hBWE_zero->mem_hp_interp_fx, INTERP_3_1_MEM_LEN, -s ); /* Qx */ + Scale_sig( HF_syn, L_SUBFR16k, -s ); /* Q_syn+exp1 */ + Scale_sig( upsampled_HF_syn, L_SUBFR48k, -1 ); + } + ELSE IF( EQ_16( output_subfr, L_SUBFR32k ) ) /* 32kHz sampled output */ + { + s = s_max( sub( s_min( Find_Max_Norm16( HF_syn, L_SUBFR16k ), Find_Max_Norm16( hBWE_zero->mem_hp_interp_fx, 2 * ALLPASSSECTIONS_STEEP ) ), 2 ), 0 ); + Scale_sig( HF_syn, L_SUBFR16k, s ); /* Q_syn+exp1+s */ + Scale_sig( hBWE_zero->mem_hp_interp_fx, 2 * ALLPASSSECTIONS_STEEP, s ); /* Qx + s */ + Interpolate_allpass_steep_fx( HF_syn, hBWE_zero->mem_hp_interp_fx, L_SUBFR16k, upsampled_HF_syn ); + Scale_sig( upsampled_HF_syn, 2 * L_SUBFR16k, -s ); /* Q_syn + exp1 */ + Scale_sig( hBWE_zero->mem_hp_interp_fx, 2 * ALLPASSSECTIONS_STEEP, -s ); /* Qx */ + Scale_sig( HF_syn, L_SUBFR16k, -s ); /* Q_syn+exp1 */ + } + ELSE /* 16kHz sampled output */ + { + Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); /* Q_syn */ + } Vr_add( synth16k, upsampled_HF_syn, synth16k, output_subfr ); return; diff --git a/lib_dec/ivas_ism_dtx_dec_fx.c b/lib_dec/ivas_ism_dtx_dec_fx.c index 73ea5cd1f27289546002cddce0f3de1f71654c66..d5943a90cf19cc9744f181178dca2ae722ff154e 100644 --- a/lib_dec/ivas_ism_dtx_dec_fx.c +++ b/lib_dec/ivas_ism_dtx_dec_fx.c @@ -161,7 +161,7 @@ void ivas_ism_dtx_limit_noise_energy_for_near_silence_fx( ) { Word32 fac_fx, cng_noise_nrg_obj_fx, cng_noise_nrg_dominant_fx; - Word16 ch, cng_noise_level_len, Q_cng_noise_nrg_dominant, Q_fac; + Word16 ch, cng_noise_level_len, Q_cng_noise_nrg_dominant, exp; HANDLE_FD_CNG_COM hFdCngCom; hFdCngCom = hSCE[sce_id_dtx]->hCoreCoder[0]->hFdCngDec->hFdCngCom; cng_noise_level_len = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); @@ -193,10 +193,10 @@ void ivas_ism_dtx_limit_noise_energy_for_near_silence_fx( Q_temp = sub( Q_temp, 1 ); temp = L_shr( temp, 1 ); } - fac_fx = getSqrtWord32( temp ); /*Resultant Q=Q_temp/2*/ - Q_fac = shr( Q_temp, 1 ); + exp = sub( 31, Q_temp ); + fac_fx = Sqrt32( temp, &exp ); v_multc_fixed( hFdCngCom->cngNoiseLevel, fac_fx, hFdCngCom->cngNoiseLevel, cng_noise_level_len ); /*Resultant Q of cngNoiseLevel is Q_cngNoiseLevel for ch*/ - scale_sig32( hFdCngCom->cngNoiseLevel, cng_noise_level_len, negate( sub( 31, Q_fac ) ) ); /*Restoring Q of hFdCngCom->cngNoiseLevel to Q_cngNoiseLevel */ + scale_sig32( hFdCngCom->cngNoiseLevel, cng_noise_level_len, exp ); /*Restoring Q of hFdCngCom->cngNoiseLevel to Q_cngNoiseLevel */ } } }