Loading lib_com/ivas_fb_mixer.c +2 −0 Original line number Diff line number Diff line Loading @@ -383,6 +383,8 @@ ivas_error ivas_FB_mixer_open_fx( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); } set32_fx( hFbMixer->ppFilterbank_prior_input_fx[i], 0, fb_cfg->prior_input_length ); hFbMixer->q_ppFilterbank_prior_input_fx[i] = Q31; move16(); } test(); Loading lib_com/lerp.c +18 −3 Original line number Diff line number Diff line Loading @@ -617,6 +617,7 @@ static void L_lerp_proc_fx( Word32 pos_fx, shift_fx, diff_fx; Word32 buf_fx[2 * L_FRAME_MAX]; Word16 tmp; Word32 ffxsub; IF( EQ_16( bufferNewSize, bufferOldSize ) ) { Loading Loading @@ -644,8 +645,15 @@ static void L_lerp_proc_fx( ELSE { idx = extract_l( L_shr( pos_fx, 21 ) ); diff_fx = L_sub( pos_fx, L_shl( idx, 21 ) ); /*Q21*/ buf_fx[0] = L_add( f_fx[idx], L_shl( Mpy_32_32( diff_fx, L_sub( f_fx[( idx + 1 )], f_fx[idx] ) ), 31 - 21 ) ); /*Qx*/ diff_fx = L_sub( pos_fx, L_shl( idx, 21 ) ); ffxsub = L_sub( f_fx[idx + 1], f_fx[idx] ); Word64 f_fx64 = W_shl( f_fx[idx], 21 ); Word64 mult64 = W_mult0_32_32( diff_fx, ffxsub ); Word64 add64 = W_add( f_fx64, mult64 ); buf_fx[0] = W_extract_l( W_shr( add64, 21 ) ); move32(); } Loading @@ -656,8 +664,15 @@ static void L_lerp_proc_fx( idx = extract_l( L_shr( pos_fx, 21 ) ); diff_fx = L_sub( pos_fx, L_shl( idx, 21 ) ); /*Q21*/ buf_fx[i] = L_add( f_fx[idx], L_shl( Mpy_32_32( diff_fx, L_sub( f_fx[idx + 1], f_fx[idx] ) ), 31 - 21 ) ); /*Qx*/ ffxsub = L_sub( f_fx[idx + 1], f_fx[idx] ); Word64 f_fx64 = W_shl( f_fx[idx], 21 ); Word64 mult64 = W_mult0_32_32( diff_fx, ffxsub ); Word64 add64 = W_add( f_fx64, mult64 ); buf_fx[i] = W_extract_l( W_shr( add64, 21 ) ); move32(); pos_fx = L_add( pos_fx, shift_fx ); /*Q21*/ } Loading lib_com/prot.h +12 −16 Original line number Diff line number Diff line Loading @@ -2391,25 +2391,21 @@ ivas_error acelp_core_enc( ivas_error acelp_core_enc( Encoder_State *st, /* i/o: encoder state structure */ /*const*/ float inp[], /* i : input signal of the current frame */ // const float ener, /* i : residual energy from Levinson-Durbin */ float A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes */ float Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes */ const float epsP[M + 1], /* i : LP prediction errors */ float lsp_new[M], /* i : LSPs at the end of the frame */ float lsp_mid[M], /* i : LSPs in the middle of the frame */ const int16_t vad_hover_flag, /* i : VAD hangover flag */ const int16_t attack_flag, /* i : attack flag (GSC or TC) */ Word16 A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes */ Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes */ const Word32 epsP[M + 1], /* i : LP prediction errors */ Word16 lsp_new[M], /* i : LSPs at the end of the frame */ Word16 lsp_mid[M], /* i : LSPs in the middle of the frame */ const Word16 vad_hover_flag, /* i : VAD hangover flag */ const Word16 attack_flag, /* i : attack flag (GSC or TC) */ Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation 2*Q_new */ #ifndef IVAS_FLOAT_FIXED float *voice_factors, /* o : voicing factors */ #else Word16 *voice_factors_fx, /* o : voicing factors Q15 */ #endif float old_syn_12k8_16k[], /* o : ACELP core synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ float pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */ int16_t *unbits, /* o : number of unused bits */ Word16 old_syn_12k8_16k[], /* o : ACELP core synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ Word16 *q_old_syn_12k8_16, Word16 pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */ Word16 *unbits, /* o : number of unused bits */ STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ float tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ Word16 Q_new ); #endif Loading lib_enc/acelp_core_enc.c +82 −310 File changed.Preview size limit exceeded, changes collapsed. Show changes lib_enc/analy_sp_fx.c +198 −16 Original line number Diff line number Diff line Loading @@ -291,15 +291,23 @@ static void find_enr_dft_fx( c_fx = L_shr( c_fx, guarded_bits ); WHILE( LE_32( freq, crit_bands_fx[i] ) ) { BinE_fx[bin_cnt] = W_extract_l( W_shr( W_add( W_mult0_32_32( *ptR_fx, *ptR_fx ), W_mult0_32_32( *ptI_fx, *ptI_fx ) ), 31 ) ); // /* energy */ Word64 te = ( W_add( W_mult0_32_32( *ptR_fx, *ptR_fx ), W_mult0_32_32( *ptI_fx, *ptI_fx ) ) ); Word16 te_exp = W_norm( te ); te = W_shl( te, te_exp ); // 2 * Q_inp_dmx + te_exp BinE_fx[bin_cnt] = W_extract_h( te ); // 2 * Q_inp_dmx + te_exp - 32 move32(); g_fx = L_sub( L_shr( g_1_fx, guarded_bits ), Mpy_32_32( g_2_fx, c_fx ) ); tmp_fx = L_sub( Mpy_32_32( c_fx, c_1_fx ), Mpy_32_32( s_fx, s_1_fx ) ); s_fx = L_add( Mpy_32_32( s_fx, c_1_fx ), Mpy_32_32( c_fx, s_1_fx ) ); c_fx = tmp_fx; move32(); BinE_fx[bin_cnt] = Mpy_32_32( Mpy_32_32( BinE_fx[bin_cnt], norm_val_fx ), g_fx ); /* normalization - corresponds to FFT normalization by 2/L_FFT */ Word64 ngmult = W_mult0_32_32( norm_val_fx, g_fx ); // Q31 + Q31 - gaurded_bits Word16 ngmult_exp = W_norm( ngmult ); ngmult = W_shl( ngmult, ngmult_exp ); // Q31 + Q31 - gaurded_bits + ngmult_exp BinE_fx[bin_cnt] = Mpy_32_32( W_extract_h( ngmult ), BinE_fx[bin_cnt] ); //(Q31 + Q31 - gaurded_bits + ngmult_exp) - Q32 + (2 * Q_inp_dmx + te_exp - 32) - 31 move32(); BinE_fx[bin_cnt] = L_shl( BinE_fx[bin_cnt], guarded_bits ); // 2 * Q_inp_dmx - 32 - 1 BinE_fx[bin_cnt] = L_shl( BinE_fx[bin_cnt], sub( Qout, sub( sub( add( add( shl( Q_inp_dmx, 1 ), te_exp ), ngmult_exp ), 34 ), guarded_bits ) ) ); move32(); band_fx[i] = L_add( BinE_fx[bin_cnt], band_fx[i] ); move32(); Loading @@ -313,8 +321,6 @@ static void find_enr_dft_fx( c_fx = L_shl( c_fx, guarded_bits ); band_fx[i] = Mpy_32_16_r( band_fx[i], inv_tbl_fx[cnt] ); /* normalization per frequency bin */ move32(); band_fx[i] = L_shl( band_fx[i], sub( Qout, sub( shl( Q_inp_dmx, 1 ), 32 ) ) ); move32(); band_ener_fx[i] = band_fx[i]; /* per band energy without E_MIN */ move32(); if ( LT_32( band_fx[i], L_shl( E_MIN_Q11_FX, sub( Qout, Q11 ) ) ) ) Loading Loading @@ -351,12 +357,19 @@ static void find_enr_dft_fx( c_fx = L_shr( c_fx, guarded_bits ); WHILE( LT_32( freq, 6399 ) ) { BinE_fx[bin_cnt] = W_extract_l( W_shr( W_add( W_mult0_32_32( *ptR_fx, *ptR_fx ), W_mult0_32_32( *ptI_fx, *ptI_fx ) ), 31 ) ); Word64 te = ( W_add( W_mult0_32_32( *ptR_fx, *ptR_fx ), W_mult0_32_32( *ptI_fx, *ptI_fx ) ) ); Word16 te_exp = W_norm( te ); te = W_shl( te, te_exp ); // 2 * Q_inp_dmx + te_exp BinE_fx[bin_cnt] = W_extract_h( te ); // 2 * Q_inp_dmx + te_exp - 32 move32(); g_fx = L_sub( L_shr( g_1_fx, guarded_bits ), Mpy_32_32( g_2_fx, c_fx ) ); BinE_fx[bin_cnt] = Mpy_32_32( Mpy_32_32( BinE_fx[bin_cnt], norm_val_fx ), g_fx ); Word64 ngmult = W_mult0_32_32( norm_val_fx, g_fx ); // Q31 + Q31 - gaurded_bits Word16 ngmult_exp = W_norm( ngmult ); ngmult = W_shl( ngmult, ngmult_exp ); // Q31 + Q31 - gaurded_bits + ngmult_exp BinE_fx[bin_cnt] = Mpy_32_32( W_extract_h( ngmult ), BinE_fx[bin_cnt] ); //(Q31 + Q31 - gaurded_bits + ngmult_exp) - Q32 + (2 * Q_inp_dmx + te_exp - 32) - 31 move32(); BinE_fx[bin_cnt] = L_shl( BinE_fx[bin_cnt], guarded_bits ); // Q11 BinE_fx[bin_cnt] = L_shl( BinE_fx[bin_cnt], sub( Qout, sub( sub( add( add( shl( Q_inp_dmx, 1 ), te_exp ), ngmult_exp ), 34 ), guarded_bits ) ) ); move32(); band_fx[i] = L_add( BinE_fx[bin_cnt], band_fx[i] ); move32(); Loading @@ -368,7 +381,7 @@ static void find_enr_dft_fx( } c_fx = L_shl( c_fx, guarded_bits ); band_fx[i] = Mpy_32_16_r( band_fx[i], inv_tbl_fx[cnt] ); band_fx[i] = L_shl( band_fx[i], sub( Qout, sub( shl( Q_inp_dmx, 1 ), 32 ) ) ); move32(); band_ener_fx[i] = band_fx[i]; move32(); if ( LT_32( band_fx[i], L_shl( E_MIN_Q11_FX, sub( Qout, Q11 ) ) ) ) Loading @@ -381,13 +394,11 @@ static void find_enr_dft_fx( /* put bin energies from BinE into Bin_E[L_FFT/2-1] (interpolate 40 Hz bin values to fit into 50 Hz bins) */ /* Last value of Bin_E is handled outside this function*/ assert( bin_cnt == ( STEREO_DFT_N_12k8_ENC / 2 - 1 ) ); Scale_sig32( BinE_fx, 256, sub( Qout, sub( shl( Q_inp_dmx, 1 ), 32 ) ) ); BinE_fx[STEREO_DFT_N_12k8_ENC / 2 - 1] = BinE_fx[STEREO_DFT_N_12k8_ENC / 2 - 2]; move32(); L_lerp_fx( BinE_fx, Bin_E_fx, L_FFT / 2, STEREO_DFT_N_12k8_ENC / 2, &Qout ); MVR2R_WORD32( Bin_E_fx, ptE_fx, VOIC_BINS ); // Qout /* find the total log energy */ tmp_fx = *Etot_fx; move32(); Loading @@ -396,6 +407,9 @@ static void find_enr_dft_fx( tmp_fx = L_add( tmp_fx, band_fx[i] ); // Qout } *Etot_fx = tmp_fx; scale_sig32( band_fx, NB_BANDS, 2 ); scale_sig32( band_ener_fx, NB_BANDS, 2 ); move32(); return; } Loading Loading @@ -550,6 +564,168 @@ void ivas_analy_sp_fx( } return; } void ivas_analy_sp_fx_front( const Word16 element_mode, /* i : element mode */ CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ const Word32 input_Fs, /* i : input sampling rate */ Word16 *speech, /* i : speech buffer Q_new - preemph_bits */ const Word16 Q_new, /* i : current scaling exp Q0 */ Word32 *fr_bands, /* o : energy in critical frequency bands Q_new + QSCALE */ Word32 *lf_E, /* o : per bin E for first... Q_new + QSCALE - 2*/ Word16 *Etot, /* o : total input energy Q8 */ const Word16 min_band, /* i : minimum critical band Q0 */ const Word16 max_band, /* i : maximum critical band Q0 */ const Word32 e_min_scaled, /* i : minimum energy scaled Q_new + QSCALE */ Word16 Scale_fac[2], /* o : FFT scales factors (2 values by frame) Q0 */ Word32 *Bin_E, /* o : per-bin energy spectrum Q7 */ Word32 *Bin_E_old, /* o : per-bin energy spectrum of the previous frame Q7 */ Word32 *PS, /* o : per-bin energy spectrum Q_new + QSCALE */ Word16 *EspecdB, /* o : per-bin log energy spectrum (with f=0) Q7 */ Word32 *band_energies, /* o : energy in critical frequency bands without minimum noise floor MODE2_E_MIN (Q_new + QSCALE + 2)*/ Word16 *fft_buff /* o : FFT coefficients (Q_new + QSCALE + 2) */ ) { Word16 *pt; Word16 i_subfr, i; Word32 *pt_bands; Word32 Ltmp, LEtot; Word16 *pt_fft; Word16 Min_val, Max_val; Word16 Scale_fac2; Word16 fft_temp[L_FFT]; /*-----------------------------------------------------------------* * Compute spectrum * find energy per critical frequency band and total energy in dB *-----------------------------------------------------------------*/ pt_bands = fr_bands; pt_fft = fft_buff; LEtot = L_deposit_l( 0 ); IF( NE_16( element_mode, IVAS_CPE_DFT ) ) { FOR( i_subfr = 0; i_subfr <= 1; i_subfr++ ) { pt = speech + 3 * ( L_SUBFR / 2 ) - L_FFT / 2; IF( i_subfr != 0 ) { pt = speech + 7 * ( L_SUBFR / 2 ) - L_FFT / 2; } /* Clear 1st value of 1st part, copy 1st value of 2nd part */ fft_temp[0] = 0; move16(); fft_temp[L_FFT / 2] = pt[L_FFT / 2]; move16(); Max_val = s_max( fft_temp[0], fft_temp[L_FFT / 2] ); Min_val = s_min( fft_temp[0], fft_temp[L_FFT / 2] ); FOR( i = 1; i < L_FFT / 2; i++ ) { /* 1st windowed part */ fft_temp[i] = mult_r( pt[i], sqrt_han_window_fx[i] ); move16(); if ( fft_temp[i] > 0 ) Max_val = s_max( Max_val, fft_temp[i] ); if ( fft_temp[i] < 0 ) Min_val = s_min( Min_val, fft_temp[i] ); /* 2nd windowed part */ fft_temp[L_FFT - i] = mult_r( pt[L_FFT - i], sqrt_han_window_fx[i] ); move16(); if ( fft_temp[L_FFT - i] > 0 ) Max_val = s_max( Max_val, fft_temp[L_FFT - i] ); if ( fft_temp[L_FFT - i] < 0 ) Min_val = s_min( Min_val, fft_temp[L_FFT - i] ); } /* Combine -Min_val and Max_val into one */ Max_val = s_max( negate( Min_val ), Max_val ); Scale_fac[i_subfr] = s_min( sub( norm_s( Max_val ), 1 ), 6 ); move16(); Scale_fac2 = shl( Scale_fac[i_subfr], 1 ); Scale_sig( fft_temp, L_FRAME_12k8, Scale_fac[i_subfr] ); r_fft_fx_lc( FFT_W128, SIZE_256, SIZE2_256, NUM_STAGE_256, fft_temp, pt_fft, 1 ); Scale_sig( pt_fft, L_FFT, -1 ); // Q(-1) /*e_min_scaled = Q_new + QSCALE + 2*/ find_enr( pt_fft, pt_bands, lf_E + i_subfr * VOIC_BINS, &LEtot, min_band, max_band, add( Q_new, Scale_fac2 ), e_min_scaled, &Bin_E[i_subfr * L_FFT / 2], BIN, band_energies + i_subfr * NB_BANDS ); pt_bands += NB_BANDS; pt_fft += L_FFT; } LEtot = L_shl_sat( LEtot, 2 ); // Q_new + Q_SCALE - 2 } ELSE { Word16 Q_inp_dmx = Q_factor_arrL( hCPE->hStereoDft->DFT[0], STEREO_DFT_N_MAX_ENC ); floatToFixed_arrL( hCPE->hStereoDft->DFT[0], hCPE->hStereoDft->DFT_fx[0], Q_inp_dmx, STEREO_DFT_N_MAX_ENC ); Word16 Qout = add( Q_new, QSCALE - 2 ); find_enr_dft_fx( hCPE, input_Fs, hCPE->hStereoDft->DFT_fx[0], pt_bands, lf_E, &LEtot, min_band, max_band, Bin_E, band_energies, Q_inp_dmx, Qout ); MVR2R_WORD32( lf_E, lf_E + VOIC_BINS, VOIC_BINS ); MVR2R_WORD32( Bin_E, Bin_E + ( L_FFT / 2 ), L_FFT / 2 ); MVR2R_WORD32( band_energies, band_energies + NB_BANDS, NB_BANDS ); MVR2R_WORD32( pt_bands, pt_bands + NB_BANDS, NB_BANDS ); LEtot = L_shl( LEtot, 1 ); } Word32 temp32_log; temp32_log = L_add( BASOP_Util_Log2( L_shr( LEtot, 1 ) ), L_shl( sub( Q31, add( Q_new, QSCALE - Q2 - 1 ) ), Q25 ) ); temp32_log = Mpy_32_32( temp32_log, 1616142483 ); // log10(x) = log2(x)/log2(10) /* 10.0 * log10( (float) tmp )*/ /* 10.0/log2(10) in Q29 = 1616142483*/ *Etot = extract_l( L_shr( temp32_log, 23 - 8 ) ); // Q8 Bin_E[L_FFT / 2 - 1] = Bin_E[L_FFT / 2 - 2]; move32(); Bin_E[L_FFT - 1] = Bin_E[L_FFT - 2]; move32(); /* Per-bin log-energy spectrum */ FOR( i = 0; i < L_FFT / 2; i++ ) { Bin_E_old[i] = Bin_E[i]; move32(); /* tmp = (input[i] + input[i+Len]+0.001f)/2.0f */ // Ltmp = L_max( L_shr( 21474, sub( Q31, add( Q_new, QSCALE ) ) ), L_add( L_shr( Bin_E[i], 1 ), L_shr( Bin_E[i + L_FFT / 2], 1 ) ) ); Ltmp = L_shr( L_add( Bin_E[i], Bin_E[i + L_FFT / 2] ), 1 ); // average if ( Ltmp == 0 ) { // Ltmp = L_min( L_shr( 21474, sub( Q31, add( Q_new, QSCALE - 2 ) ) ), 1 ); Ltmp = L_max( L_shr( 21474, sub( Q31, add( Q_new, QSCALE - 2 ) ) ), 1 ); if ( EspecdB != NULL ) { // temp32_log = L_add( BASOP_Util_Log2( Ltmp ), L_shl( sub( Q31, Q_new + QSCALE ), Q25 ) ); // EspecdB[i] = -1474; /* log(1e-5) in Q7 */ EspecdB[i] = -14736; /* log(1e-5) in Q7 */ move16(); } } else { if ( EspecdB != NULL ) { temp32_log = L_add( BASOP_Util_Log2( Ltmp ), L_shl( sub( Q31, Q_new + QSCALE - 2 - 1 ), Q25 ) ); EspecdB[i] = extract_l( L_shr( Mpy_32_32( temp32_log, 1860652798 ), Q22 - Q7 ) ); /*log(x) = log2(x)*logf(2)*/ /* 10.0*log((float)tmp) */ /* 10.0*logf(2) in Q28 = 1860652798 */ move16(); } } if ( PS != NULL ) { PS[i] = Ltmp; move32(); } } return; } #endif Loading Loading @@ -629,9 +805,12 @@ static void find_enr( FOR( ; freq <= crit_bands[i]; freq += BIN_FREQ_FX ) { /*ptE = *ptR * *ptR + *ptI * *ptI */ /* energy */ Ltmp = L_mult( *ptI, *ptI ); Ltmp = L_mac( Ltmp, *ptR, *ptR ); Word64 te = ( W_add( W_mult0_32_32( *ptR, *ptR ), W_mult0_32_32( *ptI, *ptI ) ) ); // 2 * Qfft Word16 te_exp = W_norm( te ); te = W_shl( te, te_exp ); // 2 * Qfft + te_exp Ltmp = W_extract_h( te ); // 2 * Qfft + te_exp - 32 Ltmp = L_shr( Ltmp, sub( te_exp, 32 ) ); /* *ptE *= 4.0 / (L_FFT*L_FFT) */ /* normalization - corresponds to FFT normalization by 2/L_FFT */ BASOP_SATURATE_WARNING_OFF_EVS; /* saturation seems to have no effect (tested by simulation) */ Loading Loading @@ -714,8 +893,11 @@ static void find_enr( FOR( ; freq <= crit_bands[i]; freq += BIN_FREQ_FX ) { /* *ptE = *ptR * *ptR + *ptI * *ptI */ Ltmp = L_mult( *ptI, *ptI ); Ltmp = L_mac( Ltmp, *ptR, *ptR ); Word64 te = ( W_add( W_mult0_32_32( *ptR, *ptR ), W_mult0_32_32( *ptI, *ptI ) ) ); Word16 te_exp = W_norm( te ); te = W_shl( te, te_exp ); Ltmp = W_extract_h( te ); Ltmp = L_shr( Ltmp, sub( te_exp, 32 ) ); /* *ptE *= 4.0 / (L_FFT*L_FFT) */ /* normalization - corresponds to FFT normalization by 2/L_FFT */ Loading Loading
lib_com/ivas_fb_mixer.c +2 −0 Original line number Diff line number Diff line Loading @@ -383,6 +383,8 @@ ivas_error ivas_FB_mixer_open_fx( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); } set32_fx( hFbMixer->ppFilterbank_prior_input_fx[i], 0, fb_cfg->prior_input_length ); hFbMixer->q_ppFilterbank_prior_input_fx[i] = Q31; move16(); } test(); Loading
lib_com/lerp.c +18 −3 Original line number Diff line number Diff line Loading @@ -617,6 +617,7 @@ static void L_lerp_proc_fx( Word32 pos_fx, shift_fx, diff_fx; Word32 buf_fx[2 * L_FRAME_MAX]; Word16 tmp; Word32 ffxsub; IF( EQ_16( bufferNewSize, bufferOldSize ) ) { Loading Loading @@ -644,8 +645,15 @@ static void L_lerp_proc_fx( ELSE { idx = extract_l( L_shr( pos_fx, 21 ) ); diff_fx = L_sub( pos_fx, L_shl( idx, 21 ) ); /*Q21*/ buf_fx[0] = L_add( f_fx[idx], L_shl( Mpy_32_32( diff_fx, L_sub( f_fx[( idx + 1 )], f_fx[idx] ) ), 31 - 21 ) ); /*Qx*/ diff_fx = L_sub( pos_fx, L_shl( idx, 21 ) ); ffxsub = L_sub( f_fx[idx + 1], f_fx[idx] ); Word64 f_fx64 = W_shl( f_fx[idx], 21 ); Word64 mult64 = W_mult0_32_32( diff_fx, ffxsub ); Word64 add64 = W_add( f_fx64, mult64 ); buf_fx[0] = W_extract_l( W_shr( add64, 21 ) ); move32(); } Loading @@ -656,8 +664,15 @@ static void L_lerp_proc_fx( idx = extract_l( L_shr( pos_fx, 21 ) ); diff_fx = L_sub( pos_fx, L_shl( idx, 21 ) ); /*Q21*/ buf_fx[i] = L_add( f_fx[idx], L_shl( Mpy_32_32( diff_fx, L_sub( f_fx[idx + 1], f_fx[idx] ) ), 31 - 21 ) ); /*Qx*/ ffxsub = L_sub( f_fx[idx + 1], f_fx[idx] ); Word64 f_fx64 = W_shl( f_fx[idx], 21 ); Word64 mult64 = W_mult0_32_32( diff_fx, ffxsub ); Word64 add64 = W_add( f_fx64, mult64 ); buf_fx[i] = W_extract_l( W_shr( add64, 21 ) ); move32(); pos_fx = L_add( pos_fx, shift_fx ); /*Q21*/ } Loading
lib_com/prot.h +12 −16 Original line number Diff line number Diff line Loading @@ -2391,25 +2391,21 @@ ivas_error acelp_core_enc( ivas_error acelp_core_enc( Encoder_State *st, /* i/o: encoder state structure */ /*const*/ float inp[], /* i : input signal of the current frame */ // const float ener, /* i : residual energy from Levinson-Durbin */ float A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes */ float Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes */ const float epsP[M + 1], /* i : LP prediction errors */ float lsp_new[M], /* i : LSPs at the end of the frame */ float lsp_mid[M], /* i : LSPs in the middle of the frame */ const int16_t vad_hover_flag, /* i : VAD hangover flag */ const int16_t attack_flag, /* i : attack flag (GSC or TC) */ Word16 A[NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes */ Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes */ const Word32 epsP[M + 1], /* i : LP prediction errors */ Word16 lsp_new[M], /* i : LSPs at the end of the frame */ Word16 lsp_mid[M], /* i : LSPs in the middle of the frame */ const Word16 vad_hover_flag, /* i : VAD hangover flag */ const Word16 attack_flag, /* i : attack flag (GSC or TC) */ Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation 2*Q_new */ #ifndef IVAS_FLOAT_FIXED float *voice_factors, /* o : voicing factors */ #else Word16 *voice_factors_fx, /* o : voicing factors Q15 */ #endif float old_syn_12k8_16k[], /* o : ACELP core synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ float pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */ int16_t *unbits, /* o : number of unused bits */ Word16 old_syn_12k8_16k[], /* o : ACELP core synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ Word16 *q_old_syn_12k8_16, Word16 pitch_buf[NB_SUBFR16k], /* o : floating pitch for each subframe */ Word16 *unbits, /* o : number of unused bits */ STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ float tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ Word16 Q_new ); #endif Loading
lib_enc/acelp_core_enc.c +82 −310 File changed.Preview size limit exceeded, changes collapsed. Show changes
lib_enc/analy_sp_fx.c +198 −16 Original line number Diff line number Diff line Loading @@ -291,15 +291,23 @@ static void find_enr_dft_fx( c_fx = L_shr( c_fx, guarded_bits ); WHILE( LE_32( freq, crit_bands_fx[i] ) ) { BinE_fx[bin_cnt] = W_extract_l( W_shr( W_add( W_mult0_32_32( *ptR_fx, *ptR_fx ), W_mult0_32_32( *ptI_fx, *ptI_fx ) ), 31 ) ); // /* energy */ Word64 te = ( W_add( W_mult0_32_32( *ptR_fx, *ptR_fx ), W_mult0_32_32( *ptI_fx, *ptI_fx ) ) ); Word16 te_exp = W_norm( te ); te = W_shl( te, te_exp ); // 2 * Q_inp_dmx + te_exp BinE_fx[bin_cnt] = W_extract_h( te ); // 2 * Q_inp_dmx + te_exp - 32 move32(); g_fx = L_sub( L_shr( g_1_fx, guarded_bits ), Mpy_32_32( g_2_fx, c_fx ) ); tmp_fx = L_sub( Mpy_32_32( c_fx, c_1_fx ), Mpy_32_32( s_fx, s_1_fx ) ); s_fx = L_add( Mpy_32_32( s_fx, c_1_fx ), Mpy_32_32( c_fx, s_1_fx ) ); c_fx = tmp_fx; move32(); BinE_fx[bin_cnt] = Mpy_32_32( Mpy_32_32( BinE_fx[bin_cnt], norm_val_fx ), g_fx ); /* normalization - corresponds to FFT normalization by 2/L_FFT */ Word64 ngmult = W_mult0_32_32( norm_val_fx, g_fx ); // Q31 + Q31 - gaurded_bits Word16 ngmult_exp = W_norm( ngmult ); ngmult = W_shl( ngmult, ngmult_exp ); // Q31 + Q31 - gaurded_bits + ngmult_exp BinE_fx[bin_cnt] = Mpy_32_32( W_extract_h( ngmult ), BinE_fx[bin_cnt] ); //(Q31 + Q31 - gaurded_bits + ngmult_exp) - Q32 + (2 * Q_inp_dmx + te_exp - 32) - 31 move32(); BinE_fx[bin_cnt] = L_shl( BinE_fx[bin_cnt], guarded_bits ); // 2 * Q_inp_dmx - 32 - 1 BinE_fx[bin_cnt] = L_shl( BinE_fx[bin_cnt], sub( Qout, sub( sub( add( add( shl( Q_inp_dmx, 1 ), te_exp ), ngmult_exp ), 34 ), guarded_bits ) ) ); move32(); band_fx[i] = L_add( BinE_fx[bin_cnt], band_fx[i] ); move32(); Loading @@ -313,8 +321,6 @@ static void find_enr_dft_fx( c_fx = L_shl( c_fx, guarded_bits ); band_fx[i] = Mpy_32_16_r( band_fx[i], inv_tbl_fx[cnt] ); /* normalization per frequency bin */ move32(); band_fx[i] = L_shl( band_fx[i], sub( Qout, sub( shl( Q_inp_dmx, 1 ), 32 ) ) ); move32(); band_ener_fx[i] = band_fx[i]; /* per band energy without E_MIN */ move32(); if ( LT_32( band_fx[i], L_shl( E_MIN_Q11_FX, sub( Qout, Q11 ) ) ) ) Loading Loading @@ -351,12 +357,19 @@ static void find_enr_dft_fx( c_fx = L_shr( c_fx, guarded_bits ); WHILE( LT_32( freq, 6399 ) ) { BinE_fx[bin_cnt] = W_extract_l( W_shr( W_add( W_mult0_32_32( *ptR_fx, *ptR_fx ), W_mult0_32_32( *ptI_fx, *ptI_fx ) ), 31 ) ); Word64 te = ( W_add( W_mult0_32_32( *ptR_fx, *ptR_fx ), W_mult0_32_32( *ptI_fx, *ptI_fx ) ) ); Word16 te_exp = W_norm( te ); te = W_shl( te, te_exp ); // 2 * Q_inp_dmx + te_exp BinE_fx[bin_cnt] = W_extract_h( te ); // 2 * Q_inp_dmx + te_exp - 32 move32(); g_fx = L_sub( L_shr( g_1_fx, guarded_bits ), Mpy_32_32( g_2_fx, c_fx ) ); BinE_fx[bin_cnt] = Mpy_32_32( Mpy_32_32( BinE_fx[bin_cnt], norm_val_fx ), g_fx ); Word64 ngmult = W_mult0_32_32( norm_val_fx, g_fx ); // Q31 + Q31 - gaurded_bits Word16 ngmult_exp = W_norm( ngmult ); ngmult = W_shl( ngmult, ngmult_exp ); // Q31 + Q31 - gaurded_bits + ngmult_exp BinE_fx[bin_cnt] = Mpy_32_32( W_extract_h( ngmult ), BinE_fx[bin_cnt] ); //(Q31 + Q31 - gaurded_bits + ngmult_exp) - Q32 + (2 * Q_inp_dmx + te_exp - 32) - 31 move32(); BinE_fx[bin_cnt] = L_shl( BinE_fx[bin_cnt], guarded_bits ); // Q11 BinE_fx[bin_cnt] = L_shl( BinE_fx[bin_cnt], sub( Qout, sub( sub( add( add( shl( Q_inp_dmx, 1 ), te_exp ), ngmult_exp ), 34 ), guarded_bits ) ) ); move32(); band_fx[i] = L_add( BinE_fx[bin_cnt], band_fx[i] ); move32(); Loading @@ -368,7 +381,7 @@ static void find_enr_dft_fx( } c_fx = L_shl( c_fx, guarded_bits ); band_fx[i] = Mpy_32_16_r( band_fx[i], inv_tbl_fx[cnt] ); band_fx[i] = L_shl( band_fx[i], sub( Qout, sub( shl( Q_inp_dmx, 1 ), 32 ) ) ); move32(); band_ener_fx[i] = band_fx[i]; move32(); if ( LT_32( band_fx[i], L_shl( E_MIN_Q11_FX, sub( Qout, Q11 ) ) ) ) Loading @@ -381,13 +394,11 @@ static void find_enr_dft_fx( /* put bin energies from BinE into Bin_E[L_FFT/2-1] (interpolate 40 Hz bin values to fit into 50 Hz bins) */ /* Last value of Bin_E is handled outside this function*/ assert( bin_cnt == ( STEREO_DFT_N_12k8_ENC / 2 - 1 ) ); Scale_sig32( BinE_fx, 256, sub( Qout, sub( shl( Q_inp_dmx, 1 ), 32 ) ) ); BinE_fx[STEREO_DFT_N_12k8_ENC / 2 - 1] = BinE_fx[STEREO_DFT_N_12k8_ENC / 2 - 2]; move32(); L_lerp_fx( BinE_fx, Bin_E_fx, L_FFT / 2, STEREO_DFT_N_12k8_ENC / 2, &Qout ); MVR2R_WORD32( Bin_E_fx, ptE_fx, VOIC_BINS ); // Qout /* find the total log energy */ tmp_fx = *Etot_fx; move32(); Loading @@ -396,6 +407,9 @@ static void find_enr_dft_fx( tmp_fx = L_add( tmp_fx, band_fx[i] ); // Qout } *Etot_fx = tmp_fx; scale_sig32( band_fx, NB_BANDS, 2 ); scale_sig32( band_ener_fx, NB_BANDS, 2 ); move32(); return; } Loading Loading @@ -550,6 +564,168 @@ void ivas_analy_sp_fx( } return; } void ivas_analy_sp_fx_front( const Word16 element_mode, /* i : element mode */ CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ const Word32 input_Fs, /* i : input sampling rate */ Word16 *speech, /* i : speech buffer Q_new - preemph_bits */ const Word16 Q_new, /* i : current scaling exp Q0 */ Word32 *fr_bands, /* o : energy in critical frequency bands Q_new + QSCALE */ Word32 *lf_E, /* o : per bin E for first... Q_new + QSCALE - 2*/ Word16 *Etot, /* o : total input energy Q8 */ const Word16 min_band, /* i : minimum critical band Q0 */ const Word16 max_band, /* i : maximum critical band Q0 */ const Word32 e_min_scaled, /* i : minimum energy scaled Q_new + QSCALE */ Word16 Scale_fac[2], /* o : FFT scales factors (2 values by frame) Q0 */ Word32 *Bin_E, /* o : per-bin energy spectrum Q7 */ Word32 *Bin_E_old, /* o : per-bin energy spectrum of the previous frame Q7 */ Word32 *PS, /* o : per-bin energy spectrum Q_new + QSCALE */ Word16 *EspecdB, /* o : per-bin log energy spectrum (with f=0) Q7 */ Word32 *band_energies, /* o : energy in critical frequency bands without minimum noise floor MODE2_E_MIN (Q_new + QSCALE + 2)*/ Word16 *fft_buff /* o : FFT coefficients (Q_new + QSCALE + 2) */ ) { Word16 *pt; Word16 i_subfr, i; Word32 *pt_bands; Word32 Ltmp, LEtot; Word16 *pt_fft; Word16 Min_val, Max_val; Word16 Scale_fac2; Word16 fft_temp[L_FFT]; /*-----------------------------------------------------------------* * Compute spectrum * find energy per critical frequency band and total energy in dB *-----------------------------------------------------------------*/ pt_bands = fr_bands; pt_fft = fft_buff; LEtot = L_deposit_l( 0 ); IF( NE_16( element_mode, IVAS_CPE_DFT ) ) { FOR( i_subfr = 0; i_subfr <= 1; i_subfr++ ) { pt = speech + 3 * ( L_SUBFR / 2 ) - L_FFT / 2; IF( i_subfr != 0 ) { pt = speech + 7 * ( L_SUBFR / 2 ) - L_FFT / 2; } /* Clear 1st value of 1st part, copy 1st value of 2nd part */ fft_temp[0] = 0; move16(); fft_temp[L_FFT / 2] = pt[L_FFT / 2]; move16(); Max_val = s_max( fft_temp[0], fft_temp[L_FFT / 2] ); Min_val = s_min( fft_temp[0], fft_temp[L_FFT / 2] ); FOR( i = 1; i < L_FFT / 2; i++ ) { /* 1st windowed part */ fft_temp[i] = mult_r( pt[i], sqrt_han_window_fx[i] ); move16(); if ( fft_temp[i] > 0 ) Max_val = s_max( Max_val, fft_temp[i] ); if ( fft_temp[i] < 0 ) Min_val = s_min( Min_val, fft_temp[i] ); /* 2nd windowed part */ fft_temp[L_FFT - i] = mult_r( pt[L_FFT - i], sqrt_han_window_fx[i] ); move16(); if ( fft_temp[L_FFT - i] > 0 ) Max_val = s_max( Max_val, fft_temp[L_FFT - i] ); if ( fft_temp[L_FFT - i] < 0 ) Min_val = s_min( Min_val, fft_temp[L_FFT - i] ); } /* Combine -Min_val and Max_val into one */ Max_val = s_max( negate( Min_val ), Max_val ); Scale_fac[i_subfr] = s_min( sub( norm_s( Max_val ), 1 ), 6 ); move16(); Scale_fac2 = shl( Scale_fac[i_subfr], 1 ); Scale_sig( fft_temp, L_FRAME_12k8, Scale_fac[i_subfr] ); r_fft_fx_lc( FFT_W128, SIZE_256, SIZE2_256, NUM_STAGE_256, fft_temp, pt_fft, 1 ); Scale_sig( pt_fft, L_FFT, -1 ); // Q(-1) /*e_min_scaled = Q_new + QSCALE + 2*/ find_enr( pt_fft, pt_bands, lf_E + i_subfr * VOIC_BINS, &LEtot, min_band, max_band, add( Q_new, Scale_fac2 ), e_min_scaled, &Bin_E[i_subfr * L_FFT / 2], BIN, band_energies + i_subfr * NB_BANDS ); pt_bands += NB_BANDS; pt_fft += L_FFT; } LEtot = L_shl_sat( LEtot, 2 ); // Q_new + Q_SCALE - 2 } ELSE { Word16 Q_inp_dmx = Q_factor_arrL( hCPE->hStereoDft->DFT[0], STEREO_DFT_N_MAX_ENC ); floatToFixed_arrL( hCPE->hStereoDft->DFT[0], hCPE->hStereoDft->DFT_fx[0], Q_inp_dmx, STEREO_DFT_N_MAX_ENC ); Word16 Qout = add( Q_new, QSCALE - 2 ); find_enr_dft_fx( hCPE, input_Fs, hCPE->hStereoDft->DFT_fx[0], pt_bands, lf_E, &LEtot, min_band, max_band, Bin_E, band_energies, Q_inp_dmx, Qout ); MVR2R_WORD32( lf_E, lf_E + VOIC_BINS, VOIC_BINS ); MVR2R_WORD32( Bin_E, Bin_E + ( L_FFT / 2 ), L_FFT / 2 ); MVR2R_WORD32( band_energies, band_energies + NB_BANDS, NB_BANDS ); MVR2R_WORD32( pt_bands, pt_bands + NB_BANDS, NB_BANDS ); LEtot = L_shl( LEtot, 1 ); } Word32 temp32_log; temp32_log = L_add( BASOP_Util_Log2( L_shr( LEtot, 1 ) ), L_shl( sub( Q31, add( Q_new, QSCALE - Q2 - 1 ) ), Q25 ) ); temp32_log = Mpy_32_32( temp32_log, 1616142483 ); // log10(x) = log2(x)/log2(10) /* 10.0 * log10( (float) tmp )*/ /* 10.0/log2(10) in Q29 = 1616142483*/ *Etot = extract_l( L_shr( temp32_log, 23 - 8 ) ); // Q8 Bin_E[L_FFT / 2 - 1] = Bin_E[L_FFT / 2 - 2]; move32(); Bin_E[L_FFT - 1] = Bin_E[L_FFT - 2]; move32(); /* Per-bin log-energy spectrum */ FOR( i = 0; i < L_FFT / 2; i++ ) { Bin_E_old[i] = Bin_E[i]; move32(); /* tmp = (input[i] + input[i+Len]+0.001f)/2.0f */ // Ltmp = L_max( L_shr( 21474, sub( Q31, add( Q_new, QSCALE ) ) ), L_add( L_shr( Bin_E[i], 1 ), L_shr( Bin_E[i + L_FFT / 2], 1 ) ) ); Ltmp = L_shr( L_add( Bin_E[i], Bin_E[i + L_FFT / 2] ), 1 ); // average if ( Ltmp == 0 ) { // Ltmp = L_min( L_shr( 21474, sub( Q31, add( Q_new, QSCALE - 2 ) ) ), 1 ); Ltmp = L_max( L_shr( 21474, sub( Q31, add( Q_new, QSCALE - 2 ) ) ), 1 ); if ( EspecdB != NULL ) { // temp32_log = L_add( BASOP_Util_Log2( Ltmp ), L_shl( sub( Q31, Q_new + QSCALE ), Q25 ) ); // EspecdB[i] = -1474; /* log(1e-5) in Q7 */ EspecdB[i] = -14736; /* log(1e-5) in Q7 */ move16(); } } else { if ( EspecdB != NULL ) { temp32_log = L_add( BASOP_Util_Log2( Ltmp ), L_shl( sub( Q31, Q_new + QSCALE - 2 - 1 ), Q25 ) ); EspecdB[i] = extract_l( L_shr( Mpy_32_32( temp32_log, 1860652798 ), Q22 - Q7 ) ); /*log(x) = log2(x)*logf(2)*/ /* 10.0*log((float)tmp) */ /* 10.0*logf(2) in Q28 = 1860652798 */ move16(); } } if ( PS != NULL ) { PS[i] = Ltmp; move32(); } } return; } #endif Loading Loading @@ -629,9 +805,12 @@ static void find_enr( FOR( ; freq <= crit_bands[i]; freq += BIN_FREQ_FX ) { /*ptE = *ptR * *ptR + *ptI * *ptI */ /* energy */ Ltmp = L_mult( *ptI, *ptI ); Ltmp = L_mac( Ltmp, *ptR, *ptR ); Word64 te = ( W_add( W_mult0_32_32( *ptR, *ptR ), W_mult0_32_32( *ptI, *ptI ) ) ); // 2 * Qfft Word16 te_exp = W_norm( te ); te = W_shl( te, te_exp ); // 2 * Qfft + te_exp Ltmp = W_extract_h( te ); // 2 * Qfft + te_exp - 32 Ltmp = L_shr( Ltmp, sub( te_exp, 32 ) ); /* *ptE *= 4.0 / (L_FFT*L_FFT) */ /* normalization - corresponds to FFT normalization by 2/L_FFT */ BASOP_SATURATE_WARNING_OFF_EVS; /* saturation seems to have no effect (tested by simulation) */ Loading Loading @@ -714,8 +893,11 @@ static void find_enr( FOR( ; freq <= crit_bands[i]; freq += BIN_FREQ_FX ) { /* *ptE = *ptR * *ptR + *ptI * *ptI */ Ltmp = L_mult( *ptI, *ptI ); Ltmp = L_mac( Ltmp, *ptR, *ptR ); Word64 te = ( W_add( W_mult0_32_32( *ptR, *ptR ), W_mult0_32_32( *ptI, *ptI ) ) ); Word16 te_exp = W_norm( te ); te = W_shl( te, te_exp ); Ltmp = W_extract_h( te ); Ltmp = L_shr( Ltmp, sub( te_exp, 32 ) ); /* *ptE *= 4.0 / (L_FFT*L_FFT) */ /* normalization - corresponds to FFT normalization by 2/L_FFT */ Loading