From ec2802210cd0d62514f4cb9bc4db2f7df1259ad4 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin <jmvalin@jmvalin.ca> Date: Thu, 1 Sep 2011 21:47:38 -0400 Subject: [PATCH] Removes code that became useless with the Opus-level highpass --- silk/silk_HP_variable_cutoff.c | 105 +++++++++------------------------ silk/silk_control.h | 3 - silk/silk_enc_API.c | 7 +-- silk/silk_structs.h | 1 - src/opus_encoder.c | 3 - 5 files changed, 29 insertions(+), 90 deletions(-) diff --git a/silk/silk_HP_variable_cutoff.c b/silk/silk_HP_variable_cutoff.c index 9bcd27ef8..f76767cfd 100644 --- a/silk/silk_HP_variable_cutoff.c +++ b/silk/silk_HP_variable_cutoff.c @@ -41,87 +41,38 @@ void silk_HP_variable_cutoff( const opus_int nChannels /* I Number of channels */ ) { - opus_int quality_Q15, cutoff_Hz; - opus_int32 B_Q28[ 3 ], A_Q28[ 2 ]; - opus_int32 Fc_Q19, r_Q28, r_Q22; - opus_int32 pitch_freq_Hz_Q16, pitch_freq_log_Q7, delta_freq_Q7; - silk_encoder_state *psEncC1 = &state_Fxx[ 0 ].sCmn; + opus_int quality_Q15; + opus_int32 pitch_freq_Hz_Q16, pitch_freq_log_Q7, delta_freq_Q7; + silk_encoder_state *psEncC1 = &state_Fxx[ 0 ].sCmn; - if( psEncC1->HP_cutoff_Hz == 0 ) { - /* Adaptive cutoff frequency: estimate low end of pitch frequency range */ - if( psEncC1->prevSignalType == TYPE_VOICED ) { - /* difference, in log domain */ - pitch_freq_Hz_Q16 = SKP_DIV32_16( SKP_LSHIFT( SKP_MUL( psEncC1->fs_kHz, 1000 ), 16 ), psEncC1->prevLag ); - pitch_freq_log_Q7 = silk_lin2log( pitch_freq_Hz_Q16 ) - ( 16 << 7 ); + /* Adaptive cutoff frequency: estimate low end of pitch frequency range */ + if( psEncC1->prevSignalType == TYPE_VOICED ) { + /* difference, in log domain */ + pitch_freq_Hz_Q16 = SKP_DIV32_16( SKP_LSHIFT( SKP_MUL( psEncC1->fs_kHz, 1000 ), 16 ), psEncC1->prevLag ); + pitch_freq_log_Q7 = silk_lin2log( pitch_freq_Hz_Q16 ) - ( 16 << 7 ); - /* adjustment based on quality */ - quality_Q15 = psEncC1->input_quality_bands_Q15[ 0 ]; - pitch_freq_log_Q7 = SKP_SMLAWB( pitch_freq_log_Q7, SKP_SMULWB( SKP_LSHIFT( -quality_Q15, 2 ), quality_Q15 ), - pitch_freq_log_Q7 - ( silk_lin2log( SILK_FIX_CONST( VARIABLE_HP_MIN_CUTOFF_HZ, 16 ) ) - ( 16 << 7 ) ) ); + /* adjustment based on quality */ + quality_Q15 = psEncC1->input_quality_bands_Q15[ 0 ]; + pitch_freq_log_Q7 = SKP_SMLAWB( pitch_freq_log_Q7, SKP_SMULWB( SKP_LSHIFT( -quality_Q15, 2 ), quality_Q15 ), + pitch_freq_log_Q7 - ( silk_lin2log( SILK_FIX_CONST( VARIABLE_HP_MIN_CUTOFF_HZ, 16 ) ) - ( 16 << 7 ) ) ); - /* delta_freq = pitch_freq_log - psEnc->variable_HP_smth1; */ - delta_freq_Q7 = pitch_freq_log_Q7 - SKP_RSHIFT( psEncC1->variable_HP_smth1_Q15, 8 ); - if( delta_freq_Q7 < 0 ) { - /* less smoothing for decreasing pitch frequency, to track something close to the minimum */ - delta_freq_Q7 = SKP_MUL( delta_freq_Q7, 3 ); - } + /* delta_freq = pitch_freq_log - psEnc->variable_HP_smth1; */ + delta_freq_Q7 = pitch_freq_log_Q7 - SKP_RSHIFT( psEncC1->variable_HP_smth1_Q15, 8 ); + if( delta_freq_Q7 < 0 ) { + /* less smoothing for decreasing pitch frequency, to track something close to the minimum */ + delta_freq_Q7 = SKP_MUL( delta_freq_Q7, 3 ); + } - /* limit delta, to reduce impact of outliers in pitch estimation */ - delta_freq_Q7 = SKP_LIMIT_32( delta_freq_Q7, -SILK_FIX_CONST( VARIABLE_HP_MAX_DELTA_FREQ, 7 ), SILK_FIX_CONST( VARIABLE_HP_MAX_DELTA_FREQ, 7 ) ); + /* limit delta, to reduce impact of outliers in pitch estimation */ + delta_freq_Q7 = SKP_LIMIT_32( delta_freq_Q7, -SILK_FIX_CONST( VARIABLE_HP_MAX_DELTA_FREQ, 7 ), SILK_FIX_CONST( VARIABLE_HP_MAX_DELTA_FREQ, 7 ) ); - /* update smoother */ - psEncC1->variable_HP_smth1_Q15 = SKP_SMLAWB( psEncC1->variable_HP_smth1_Q15, - SKP_SMULBB( psEncC1->speech_activity_Q8, delta_freq_Q7 ), SILK_FIX_CONST( VARIABLE_HP_SMTH_COEF1, 16 ) ); + /* update smoother */ + psEncC1->variable_HP_smth1_Q15 = SKP_SMLAWB( psEncC1->variable_HP_smth1_Q15, + SKP_SMULBB( psEncC1->speech_activity_Q8, delta_freq_Q7 ), SILK_FIX_CONST( VARIABLE_HP_SMTH_COEF1, 16 ) ); - /* limit frequency range */ - psEncC1->variable_HP_smth1_Q15 = SKP_LIMIT_32( psEncC1->variable_HP_smth1_Q15, - SKP_LSHIFT( silk_lin2log( VARIABLE_HP_MIN_CUTOFF_HZ ), 8 ), - SKP_LSHIFT( silk_lin2log( VARIABLE_HP_MAX_CUTOFF_HZ ), 8 ) ); - } - } else { - /* Externally-controlled cutoff frequency */ - cutoff_Hz = SKP_LIMIT( psEncC1->HP_cutoff_Hz, 10, 500 ); - psEncC1->variable_HP_smth1_Q15 = SKP_LSHIFT( silk_lin2log( cutoff_Hz ), 8 ); - } - -#if 0 - /* second smoother */ - psEncC1->variable_HP_smth2_Q15 = SKP_SMLAWB( psEncC1->variable_HP_smth2_Q15, - psEncC1->variable_HP_smth1_Q15 - psEncC1->variable_HP_smth2_Q15, SILK_FIX_CONST( VARIABLE_HP_SMTH_COEF2, 16 ) ); - - /* convert from log scale to Hertz */ - cutoff_Hz = silk_log2lin( SKP_RSHIFT( psEncC1->variable_HP_smth2_Q15, 8 ) ); - - /********************************/ - /* Compute Filter Coefficients */ - /********************************/ - /* compute cut-off frequency, in radians */ - /* Fc_num = 1.5 * 3.14159 * cutoff_Hz */ - /* Fc_denom = 1e3f * psEncC1->fs_kHz */ - SKP_assert( cutoff_Hz <= SKP_int32_MAX / SILK_FIX_CONST( 1.5 * 3.14159 / 1000, 19 ) ); - Fc_Q19 = SKP_DIV32_16( SKP_SMULBB( SILK_FIX_CONST( 1.5 * 3.14159 / 1000, 19 ), cutoff_Hz ), psEncC1->fs_kHz ); - SKP_assert( Fc_Q19 > 0 && Fc_Q19 < 32768 ); - - r_Q28 = SILK_FIX_CONST( 1.0, 28 ) - SKP_MUL( SILK_FIX_CONST( 0.92, 9 ), Fc_Q19 ); - - /* b = r * [ 1; -2; 1 ]; */ - /* a = [ 1; -2 * r * ( 1 - 0.5 * Fc^2 ); r^2 ]; */ - B_Q28[ 0 ] = r_Q28; - B_Q28[ 1 ] = SKP_LSHIFT( -r_Q28, 1 ); - B_Q28[ 2 ] = r_Q28; - - /* -r * ( 2 - Fc * Fc ); */ - r_Q22 = SKP_RSHIFT( r_Q28, 6 ); - A_Q28[ 0 ] = SKP_SMULWW( r_Q22, SKP_SMULWW( Fc_Q19, Fc_Q19 ) - SILK_FIX_CONST( 2.0, 22 ) ); - A_Q28[ 1 ] = SKP_SMULWW( r_Q22, r_Q22 ); - - /********************************/ - /* High-Pass Filter */ - /********************************/ - silk_biquad_alt( psEncC1->inputBuf, B_Q28, A_Q28, psEncC1->In_HP_State, psEncC1->inputBuf, psEncC1->frame_length, 1 ); - if( nChannels == 2 ) { - silk_biquad_alt( state_Fxx[ 1 ].sCmn.inputBuf, B_Q28, A_Q28, state_Fxx[ 1 ].sCmn.In_HP_State, - state_Fxx[ 1 ].sCmn.inputBuf, state_Fxx[ 1 ].sCmn.frame_length, 1 ); - } -#endif + /* limit frequency range */ + psEncC1->variable_HP_smth1_Q15 = SKP_LIMIT_32( psEncC1->variable_HP_smth1_Q15, + SKP_LSHIFT( silk_lin2log( VARIABLE_HP_MIN_CUTOFF_HZ ), 8 ), + SKP_LSHIFT( silk_lin2log( VARIABLE_HP_MAX_CUTOFF_HZ ), 8 ) ); + } } diff --git a/silk/silk_control.h b/silk/silk_control.h index 58f8a7ae2..0ebf5a330 100644 --- a/silk/silk_control.h +++ b/silk/silk_control.h @@ -83,9 +83,6 @@ typedef struct { /* I: Flag to use constant bitrate */ opus_int useCBR; - /* I: Cutoff frequency of input HP filter (of zero: adaptive) */ - opus_int HP_cutoff_Hz; - /* O: Internal sampling rate used, in Hertz; 8000/12000/16000 */ opus_int32 internalSampleRate; diff --git a/silk/silk_enc_API.c b/silk/silk_enc_API.c index 8e0315b81..bc65caa8b 100644 --- a/silk/silk_enc_API.c +++ b/silk/silk_enc_API.c @@ -112,7 +112,6 @@ opus_int silk_QueryEncoder( encStatus->useInBandFEC = state_Fxx[ 0 ].sCmn.useInBandFEC; encStatus->useDTX = state_Fxx[ 0 ].sCmn.useDTX; encStatus->useCBR = state_Fxx[ 0 ].sCmn.useCBR; - encStatus->HP_cutoff_Hz = state_Fxx[ 0 ].sCmn.HP_cutoff_Hz; encStatus->internalSampleRate = SKP_SMULBB( state_Fxx[ 0 ].sCmn.fs_kHz, 1000 ); encStatus->allowBandwidthSwitch = state_Fxx[ 0 ].sCmn.allow_bandwidth_switch; encStatus->inWBmodeWithoutVariableLP = state_Fxx[ 0 ].sCmn.fs_kHz == 16 && state_Fxx[ 0 ].sCmn.sLP.mode == 0; @@ -302,11 +301,7 @@ opus_int silk_Encode( } } - /* High-pass filter, deactivated if less than zero */ - if(encControl->HP_cutoff_Hz>=0) { - psEnc->state_Fxx[ 0 ].sCmn.HP_cutoff_Hz = encControl->HP_cutoff_Hz; - silk_HP_variable_cutoff( psEnc->state_Fxx, psEnc->nChannelsInternal ); - } + silk_HP_variable_cutoff( psEnc->state_Fxx, psEnc->nChannelsInternal ); /* Total target bits for packet */ nBits = SKP_DIV32_16( SKP_MUL( encControl->bitRate, encControl->payloadSize_ms ), 1000 ); diff --git a/silk/silk_structs.h b/silk/silk_structs.h index 341a2a96b..3044a02fc 100644 --- a/silk/silk_structs.h +++ b/silk/silk_structs.h @@ -132,7 +132,6 @@ typedef struct { opus_int32 In_HP_State[ 2 ]; /* High pass filter state */ opus_int32 variable_HP_smth1_Q15; /* State of first smoother */ opus_int32 variable_HP_smth2_Q15; /* State of second smoother */ - opus_int HP_cutoff_Hz; /* Fixed cutoff frequency (if zero: adaptive) */ silk_LP_state sLP; /* Low pass filter state */ silk_VAD_state sVAD; /* Voice activity detector state */ silk_nsq_state sNSQ; /* Noise Shape Quantizer State */ diff --git a/src/opus_encoder.c b/src/opus_encoder.c index f8c83d1ef..02c3ef721 100644 --- a/src/opus_encoder.c +++ b/src/opus_encoder.c @@ -159,7 +159,6 @@ int opus_encoder_init(OpusEncoder* st, int Fs, int channels, int application) st->silk_mode.useInBandFEC = 0; st->silk_mode.useDTX = 0; st->silk_mode.useCBR = 0; - st->silk_mode.HP_cutoff_Hz = 0; /* Create CELT encoder */ /* Initialize CELT encoder */ @@ -425,7 +424,6 @@ int opus_encode_float(OpusEncoder *st, const opus_val16 *pcm, int frame_size, opus_int32 threshold; threshold = 20000; /* OPUS_APPLICATION_VOIP default to auto high-pass */ - st->silk_mode.HP_cutoff_Hz=0; /* Hysteresis */ if (st->prev_mode == MODE_CELT_ONLY) threshold -= 4000; @@ -442,7 +440,6 @@ int opus_encode_float(OpusEncoder *st, const opus_val16 *pcm, int frame_size, /* SILK/CELT threshold is higher for voice than for music */ threshold = 36000; /* OPUS_APPLICATION_AUDIO disables the high-pass */ - st->silk_mode.HP_cutoff_Hz=-1; if (st->signal_type == OPUS_SIGNAL_MUSIC) threshold -= 20000; else if (st->signal_type == OPUS_SIGNAL_VOICE) -- GitLab