Loading lib_enc/analy_sp_fx.c +244 −6 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ *-------------------------------------------------------------------*/ static void find_enr( Word16 data[], Word32 band[], Word32 *ptE, Word32 *LEtot, const Word16 min_band, const Word16 max_band, const Word16 Q_new2, const Word32 e_min, Word32 *Bin_E, Word16 BIN_FREQ_FX, Word32 *band_energies ); #ifdef IVAS_FLOAT_FIXED1 #ifdef IVAS_FLOAT_FIXED static void ivas_find_enr( Word16 data[], Word32 band[], Word32 *ptE, Word32 *LEtot, const Word16 min_band, const Word16 max_band, const Word16 Q_new2, const Word32 e_min, Word32 *Bin_E, Word16 BIN_FREQ_FX, Word32 *band_energies ); #endif #ifdef IVAS_CODE_CPE Loading Loading @@ -508,7 +508,7 @@ void ivas_analy_sp_fx( 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, ivas_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; Loading Loading @@ -653,7 +653,7 @@ void ivas_analy_sp_fx_front( 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, ivas_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; Loading Loading @@ -737,7 +737,7 @@ void ivas_analy_sp_fx_front( * The energy is normalized by the number of frequency bins in a channel *------------------------------------------------------------------------*/ static void find_enr( static void ivas_find_enr( Word16 data[], /* i : fft result */ Word32 band[], /* o : per band energy Q_new + QSCALE */ Word32 *ptE, /* o : per bin energy for low frequencies Q_new + QSCALE-2 */ Loading Loading @@ -979,6 +979,244 @@ static void find_enr( return; } static void find_enr( Word16 data[], /* i : fft result */ Word32 band[], /* o : per band energy Q_new + QSCALE */ Word32 *ptE, /* o : per bin energy for low frequencies Q_new + QSCALE-2 */ Word32 *LEtot, /* o : total energy Q_new + QSCALE */ const Word16 min_band, /* i : minimum critical band Q0 */ const Word16 max_band, /* i : maximum critical band Q0 */ const Word16 Q_new2, /* i : scaling factor Q0 */ const Word32 e_min, /* i : minimum energy scaled Q_new + QSCALE */ Word32 *Bin_E, /* o : Per bin energy Q_new + QSCALE-2 */ Word16 BIN_FREQ_FX, /* i : Number of frequency bins */ Word32 *band_energies /* o : per band energy without MODE2_E_MIN */ ) { Word16 i, cnt, shift_to_norm; Word16 freq, wtmp; Word16 *ptR, *ptI, diff_scaleP1, diff_scaleM2; Word16 exp_band; Word32 Ltmp, Ltmp1; Word16 voic_band; Word32 etot; Word16 exp_etot; Word32 *tmpptr; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); #endif ptR = &data[1]; /* first real */ ptI = &data[L_FFT - 1]; /* first imaginary */ /*-----------------------------------------------------------------------------------* * Scaling needed by band and ptE output * Wants all energies scaled by Q_new + QSCALE to maintain maximum * precision on bckr noise in clean speech * First shift left by Q_new + QSCALE than shift right by 2*Q_new-1 * shift left (Q_new + QSCALE - (2*Q_new -1)) * shift left (QSCALE - Q_new + 1) == shift left by (QSCALE+1) - Q_new *-----------------------------------------------------------------------------------*/ diff_scaleP1 = sub( QSCALE + 1 + 1, Q_new2 ); diff_scaleM2 = sub( QSCALE + 1 - 2, Q_new2 ); voic_band = VOIC_BAND_8k; move16(); assert( VOIC_BAND == VOIC_BAND_8k ); etot = L_deposit_l( 0 ); exp_etot = 0; move16(); /*-----------------------------------------------------------------* * For low frequency bins, save per bin energy for the use * in NS and find_tilt() *-----------------------------------------------------------------*/ freq = BIN_FREQ_FX; move16(); FOR( i = 0; i < voic_band; i++ ) /* up to maximum allowed voiced critical band */ { tmpptr = Bin_E; move16(); Ltmp1 = L_deposit_l( 0 ); 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 ); /* *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) */ #ifdef BASOP_NOGLOB *ptE = L_shl_o( Ltmp, diff_scaleM2, &Overflow ); #else /* BASOP_NOGLOB */ *ptE = L_shl( Ltmp, diff_scaleM2 ); #endif /* BASOP_NOGLOB */ move32(); /* scaled by Q_new + QSCALE - 2 */ BASOP_SATURATE_WARNING_ON_EVS; /*band[i] += *ptE++;*/ *Bin_E = *ptE; move32(); Bin_E++; Ltmp1 = L_add( Ltmp1, Ltmp ); ptE++; ptR++; ptI--; } exp_band = sub( norm_l( Ltmp1 ), 1 ); /* divide by 2 to ensure band < cnt */ wtmp = round_fx( L_shl( Ltmp1, exp_band ) ); /* band[i] /= cnt */ /* normalization per frequency bin */ cnt = (Word16) ( Bin_E - tmpptr ); shift_to_norm = norm_s( cnt ); wtmp = div_s( wtmp, shl( cnt, shift_to_norm ) ); Ltmp1 = L_deposit_l( wtmp ); exp_band = sub( exp_band, shift_to_norm ); exp_band = sub( diff_scaleP1, exp_band ); BASOP_SATURATE_WARNING_OFF_EVS; /* saturation seems to have no effect (tested by simulation) */ #ifdef BASOP_NOGLOB band[i] = L_shl_o( Ltmp1, exp_band, &Overflow ); #else /* BASOP_NOGLOB */ band[i] = L_shl( Ltmp1, exp_band ); #endif /* BASOP_NOGLOB */ move32(); /* band scaled by Q_new + QSCALE */ BASOP_SATURATE_WARNING_ON_EVS; test(); IF( GE_16( i, min_band ) && LE_16( i, max_band ) ) { IF( LT_32( band[i], e_min ) ) { Ltmp1 = L_shl( e_min, 0 ); exp_band = 0; move16(); } wtmp = sub( exp_band, exp_etot ); if ( wtmp > 0 ) { etot = L_shr( etot, wtmp ); } exp_etot = s_max( exp_etot, exp_band ); etot = L_add( etot, L_shl( Ltmp1, sub( exp_band, exp_etot ) ) ); } band_energies[i] = band[i]; move32(); band[i] = L_max( band[i], e_min ); move32(); } IF( EQ_16( BIN_FREQ_FX, 50 ) ) { /*-----------------------------------------------------------------* * Continue compute the E per critical band for high frequencies *-----------------------------------------------------------------*/ FOR( i = voic_band; i < NB_BANDS; i++ ) { tmpptr = Bin_E; move16(); Ltmp1 = L_deposit_l( 0 ); 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 ); /* *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) */ #ifdef BASOP_NOGLOB *Bin_E = L_shl_o( Ltmp, diff_scaleM2, &Overflow ); #else /* BASOP_NOGLOB */ *Bin_E = L_shl( Ltmp, diff_scaleM2 ); #endif /* BASOP_NOGLOB */ move32(); /* scaled by Q_new + QSCALE - 2 */ BASOP_SATURATE_WARNING_ON_EVS; Bin_E++; Ltmp1 = L_add( Ltmp1, Ltmp ); ptR++; ptI--; } exp_band = sub( norm_l( Ltmp1 ), 1 ); /* divide by 2 to ensure band < cnt */ wtmp = round_fx( L_shl( Ltmp1, exp_band ) ); /* band[i] /= cnt */ /* normalization per frequency bin */ cnt = (Word16) ( Bin_E - tmpptr ); shift_to_norm = norm_s( cnt ); wtmp = div_s( wtmp, shl( cnt, shift_to_norm ) ); Ltmp1 = L_deposit_l( wtmp ); exp_band = sub( exp_band, shift_to_norm ); exp_band = sub( diff_scaleP1, exp_band ); BASOP_SATURATE_WARNING_OFF_EVS; /* saturation seems to have no effect (tested by simulation) */ #ifdef BASOP_NOGLOB band[i] = L_shl_o( Ltmp1, exp_band, &Overflow ); #else /* BASOP_NOGLOB */ band[i] = L_shl( Ltmp1, exp_band ); #endif move32(); /* band scaled by Q_new + QSCALE */ BASOP_SATURATE_WARNING_ON_EVS; test(); IF( GE_16( i, min_band ) && LE_16( i, max_band ) ) { IF( LT_32( band[i], e_min ) ) { Ltmp1 = L_shl( e_min, 0 ); exp_band = 0; move16(); } wtmp = sub( exp_band, exp_etot ); if ( wtmp > 0 ) { etot = L_shr( etot, wtmp ); } exp_etot = s_max( exp_etot, exp_band ); etot = L_add( etot, L_shl( Ltmp1, sub( exp_band, exp_etot ) ) ); } band_energies[i] = band[i]; move32(); band[i] = L_max( band[i], e_min ); move32(); } } /*-----------------------------------------------------------------* * Find the total energy over the input bandwidth *-----------------------------------------------------------------*/ #ifdef BASOP_NOGLOB etot = L_add_sat( *LEtot, L_shl_sat( etot, sub( exp_etot, 4 ) ) ); #else etot = L_add( *LEtot, L_shl( etot, sub( exp_etot, 4 ) ) ); #endif *LEtot = etot; move32(); return; } #ifdef IVAS_FLOAT_FIXED1 /*------------------------------------------------------------------------* * ivas_find_enr() Loading Loading
lib_enc/analy_sp_fx.c +244 −6 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ *-------------------------------------------------------------------*/ static void find_enr( Word16 data[], Word32 band[], Word32 *ptE, Word32 *LEtot, const Word16 min_band, const Word16 max_band, const Word16 Q_new2, const Word32 e_min, Word32 *Bin_E, Word16 BIN_FREQ_FX, Word32 *band_energies ); #ifdef IVAS_FLOAT_FIXED1 #ifdef IVAS_FLOAT_FIXED static void ivas_find_enr( Word16 data[], Word32 band[], Word32 *ptE, Word32 *LEtot, const Word16 min_band, const Word16 max_band, const Word16 Q_new2, const Word32 e_min, Word32 *Bin_E, Word16 BIN_FREQ_FX, Word32 *band_energies ); #endif #ifdef IVAS_CODE_CPE Loading Loading @@ -508,7 +508,7 @@ void ivas_analy_sp_fx( 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, ivas_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; Loading Loading @@ -653,7 +653,7 @@ void ivas_analy_sp_fx_front( 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, ivas_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; Loading Loading @@ -737,7 +737,7 @@ void ivas_analy_sp_fx_front( * The energy is normalized by the number of frequency bins in a channel *------------------------------------------------------------------------*/ static void find_enr( static void ivas_find_enr( Word16 data[], /* i : fft result */ Word32 band[], /* o : per band energy Q_new + QSCALE */ Word32 *ptE, /* o : per bin energy for low frequencies Q_new + QSCALE-2 */ Loading Loading @@ -979,6 +979,244 @@ static void find_enr( return; } static void find_enr( Word16 data[], /* i : fft result */ Word32 band[], /* o : per band energy Q_new + QSCALE */ Word32 *ptE, /* o : per bin energy for low frequencies Q_new + QSCALE-2 */ Word32 *LEtot, /* o : total energy Q_new + QSCALE */ const Word16 min_band, /* i : minimum critical band Q0 */ const Word16 max_band, /* i : maximum critical band Q0 */ const Word16 Q_new2, /* i : scaling factor Q0 */ const Word32 e_min, /* i : minimum energy scaled Q_new + QSCALE */ Word32 *Bin_E, /* o : Per bin energy Q_new + QSCALE-2 */ Word16 BIN_FREQ_FX, /* i : Number of frequency bins */ Word32 *band_energies /* o : per band energy without MODE2_E_MIN */ ) { Word16 i, cnt, shift_to_norm; Word16 freq, wtmp; Word16 *ptR, *ptI, diff_scaleP1, diff_scaleM2; Word16 exp_band; Word32 Ltmp, Ltmp1; Word16 voic_band; Word32 etot; Word16 exp_etot; Word32 *tmpptr; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); #endif ptR = &data[1]; /* first real */ ptI = &data[L_FFT - 1]; /* first imaginary */ /*-----------------------------------------------------------------------------------* * Scaling needed by band and ptE output * Wants all energies scaled by Q_new + QSCALE to maintain maximum * precision on bckr noise in clean speech * First shift left by Q_new + QSCALE than shift right by 2*Q_new-1 * shift left (Q_new + QSCALE - (2*Q_new -1)) * shift left (QSCALE - Q_new + 1) == shift left by (QSCALE+1) - Q_new *-----------------------------------------------------------------------------------*/ diff_scaleP1 = sub( QSCALE + 1 + 1, Q_new2 ); diff_scaleM2 = sub( QSCALE + 1 - 2, Q_new2 ); voic_band = VOIC_BAND_8k; move16(); assert( VOIC_BAND == VOIC_BAND_8k ); etot = L_deposit_l( 0 ); exp_etot = 0; move16(); /*-----------------------------------------------------------------* * For low frequency bins, save per bin energy for the use * in NS and find_tilt() *-----------------------------------------------------------------*/ freq = BIN_FREQ_FX; move16(); FOR( i = 0; i < voic_band; i++ ) /* up to maximum allowed voiced critical band */ { tmpptr = Bin_E; move16(); Ltmp1 = L_deposit_l( 0 ); 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 ); /* *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) */ #ifdef BASOP_NOGLOB *ptE = L_shl_o( Ltmp, diff_scaleM2, &Overflow ); #else /* BASOP_NOGLOB */ *ptE = L_shl( Ltmp, diff_scaleM2 ); #endif /* BASOP_NOGLOB */ move32(); /* scaled by Q_new + QSCALE - 2 */ BASOP_SATURATE_WARNING_ON_EVS; /*band[i] += *ptE++;*/ *Bin_E = *ptE; move32(); Bin_E++; Ltmp1 = L_add( Ltmp1, Ltmp ); ptE++; ptR++; ptI--; } exp_band = sub( norm_l( Ltmp1 ), 1 ); /* divide by 2 to ensure band < cnt */ wtmp = round_fx( L_shl( Ltmp1, exp_band ) ); /* band[i] /= cnt */ /* normalization per frequency bin */ cnt = (Word16) ( Bin_E - tmpptr ); shift_to_norm = norm_s( cnt ); wtmp = div_s( wtmp, shl( cnt, shift_to_norm ) ); Ltmp1 = L_deposit_l( wtmp ); exp_band = sub( exp_band, shift_to_norm ); exp_band = sub( diff_scaleP1, exp_band ); BASOP_SATURATE_WARNING_OFF_EVS; /* saturation seems to have no effect (tested by simulation) */ #ifdef BASOP_NOGLOB band[i] = L_shl_o( Ltmp1, exp_band, &Overflow ); #else /* BASOP_NOGLOB */ band[i] = L_shl( Ltmp1, exp_band ); #endif /* BASOP_NOGLOB */ move32(); /* band scaled by Q_new + QSCALE */ BASOP_SATURATE_WARNING_ON_EVS; test(); IF( GE_16( i, min_band ) && LE_16( i, max_band ) ) { IF( LT_32( band[i], e_min ) ) { Ltmp1 = L_shl( e_min, 0 ); exp_band = 0; move16(); } wtmp = sub( exp_band, exp_etot ); if ( wtmp > 0 ) { etot = L_shr( etot, wtmp ); } exp_etot = s_max( exp_etot, exp_band ); etot = L_add( etot, L_shl( Ltmp1, sub( exp_band, exp_etot ) ) ); } band_energies[i] = band[i]; move32(); band[i] = L_max( band[i], e_min ); move32(); } IF( EQ_16( BIN_FREQ_FX, 50 ) ) { /*-----------------------------------------------------------------* * Continue compute the E per critical band for high frequencies *-----------------------------------------------------------------*/ FOR( i = voic_band; i < NB_BANDS; i++ ) { tmpptr = Bin_E; move16(); Ltmp1 = L_deposit_l( 0 ); 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 ); /* *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) */ #ifdef BASOP_NOGLOB *Bin_E = L_shl_o( Ltmp, diff_scaleM2, &Overflow ); #else /* BASOP_NOGLOB */ *Bin_E = L_shl( Ltmp, diff_scaleM2 ); #endif /* BASOP_NOGLOB */ move32(); /* scaled by Q_new + QSCALE - 2 */ BASOP_SATURATE_WARNING_ON_EVS; Bin_E++; Ltmp1 = L_add( Ltmp1, Ltmp ); ptR++; ptI--; } exp_band = sub( norm_l( Ltmp1 ), 1 ); /* divide by 2 to ensure band < cnt */ wtmp = round_fx( L_shl( Ltmp1, exp_band ) ); /* band[i] /= cnt */ /* normalization per frequency bin */ cnt = (Word16) ( Bin_E - tmpptr ); shift_to_norm = norm_s( cnt ); wtmp = div_s( wtmp, shl( cnt, shift_to_norm ) ); Ltmp1 = L_deposit_l( wtmp ); exp_band = sub( exp_band, shift_to_norm ); exp_band = sub( diff_scaleP1, exp_band ); BASOP_SATURATE_WARNING_OFF_EVS; /* saturation seems to have no effect (tested by simulation) */ #ifdef BASOP_NOGLOB band[i] = L_shl_o( Ltmp1, exp_band, &Overflow ); #else /* BASOP_NOGLOB */ band[i] = L_shl( Ltmp1, exp_band ); #endif move32(); /* band scaled by Q_new + QSCALE */ BASOP_SATURATE_WARNING_ON_EVS; test(); IF( GE_16( i, min_band ) && LE_16( i, max_band ) ) { IF( LT_32( band[i], e_min ) ) { Ltmp1 = L_shl( e_min, 0 ); exp_band = 0; move16(); } wtmp = sub( exp_band, exp_etot ); if ( wtmp > 0 ) { etot = L_shr( etot, wtmp ); } exp_etot = s_max( exp_etot, exp_band ); etot = L_add( etot, L_shl( Ltmp1, sub( exp_band, exp_etot ) ) ); } band_energies[i] = band[i]; move32(); band[i] = L_max( band[i], e_min ); move32(); } } /*-----------------------------------------------------------------* * Find the total energy over the input bandwidth *-----------------------------------------------------------------*/ #ifdef BASOP_NOGLOB etot = L_add_sat( *LEtot, L_shl_sat( etot, sub( exp_etot, 4 ) ) ); #else etot = L_add( *LEtot, L_shl( etot, sub( exp_etot, 4 ) ) ); #endif *LEtot = etot; move32(); return; } #ifdef IVAS_FLOAT_FIXED1 /*------------------------------------------------------------------------* * ivas_find_enr() Loading