mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-21 13:08:08 +00:00
fix equalizer un-precision, and allow band width setting per frequency.
git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@549 3f6dc0c8-ddfe-455d-9043-3cd528dc4637
This commit is contained in:
parent
21b39dee97
commit
552f55f00a
3 changed files with 16 additions and 24 deletions
|
|
@ -1480,17 +1480,15 @@ static void parametrize_equalizer(LinphoneCore *lc, AudioStream *st){
|
|||
if (st->equalizer){
|
||||
MSFilter *f=st->equalizer;
|
||||
int enabled=lp_config_get_int(lc->config,"sound","eq_active",0);
|
||||
float width=lp_config_get_float(lc->config,"sound","eq_width_factor",-1);
|
||||
const char *gains=lp_config_get_string(lc->config,"sound","eq_gains",NULL);
|
||||
ms_filter_call_method(f,MS_EQUALIZER_SET_ACTIVE,&enabled);
|
||||
if (enabled){
|
||||
if (width!=-1) ms_filter_call_method(f,MS_EQUALIZER_SET_ACTIVE,&width);
|
||||
if (gains){
|
||||
do{
|
||||
int bytes;
|
||||
MSEqualizerGain g;
|
||||
if (sscanf(gains,"%f:%f %n",&g.frequency,&g.gain,&bytes)==2){
|
||||
ms_message("Read equalizer gains: %f --> %f",g.frequency,g.gain);
|
||||
if (sscanf(gains,"%f:%f:%f %n",&g.frequency,&g.gain,&g.width,&bytes)==2){
|
||||
ms_message("Read equalizer gains: %f(~%f) --> %f",g.frequency,g.width,g.gain);
|
||||
ms_filter_call_method(f,MS_EQUALIZER_SET_GAIN,&g);
|
||||
gains+=bytes;
|
||||
}else break;
|
||||
|
|
|
|||
|
|
@ -25,17 +25,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
typedef struct _MSEqualizerGain{
|
||||
float frequency; ///< In hz
|
||||
float gain; ///< between 0-1.2
|
||||
float width; ///< frequency band width around mid frequency for which the gain is applied, in Hz. Use 0 for the lowest frequency resolution.
|
||||
}MSEqualizerGain;
|
||||
|
||||
#define MS_EQUALIZER_SET_GAIN MS_FILTER_METHOD(MS_EQUALIZER_ID,0,MSEqualizerGain)
|
||||
#define MS_EQUALIZER_GET_GAIN MS_FILTER_METHOD(MS_EQUALIZER_ID,1,MSEqualizerGain)
|
||||
#define MS_EQUALIZER_SET_ACTIVE MS_FILTER_METHOD(MS_EQUALIZER_ID,2,int)
|
||||
/**
|
||||
* Sets the coeficient for computing how large is the frequency band around a gain setting.
|
||||
* For example, setting this value to 0.4 will result in a frequency range of 800-1200 when setting
|
||||
* a gain for frequency 1000 Hz.
|
||||
**/
|
||||
#define MS_EQUALIZER_SET_FREQ_WIDTH_COEF MS_FILTER_METHOD(MS_EQUALIZER_ID,3,float)
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ static void equalizer_state_destroy(EqualizerState *s){
|
|||
|
||||
static int equalizer_state_hz_to_index(EqualizerState *s, int hz){
|
||||
int ret;
|
||||
int bandres=s->rate/s->nfft;
|
||||
if (hz<0){
|
||||
ms_error("Bad frequency value %i",hz);
|
||||
return -1;
|
||||
|
|
@ -84,7 +85,7 @@ static int equalizer_state_hz_to_index(EqualizerState *s, int hz){
|
|||
hz=(s->rate/2);
|
||||
}
|
||||
/*round to nearest integer*/
|
||||
ret=((hz*s->nfft)+(hz/2))/s->rate;
|
||||
ret=((hz+(bandres/2))*s->nfft)/s->rate;
|
||||
if (ret==s->nfft/2) ret=(s->nfft/2)-1;
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -106,19 +107,19 @@ static float equalizer_state_get(EqualizerState *s, int freqhz){
|
|||
}
|
||||
|
||||
/* return the frequency band width we want to control around hz*/
|
||||
static void equalizer_state_get_band(EqualizerState *s, int hz, int *low_index, int *high_index){
|
||||
int half_band=(int)((float)hz*s->width_coef*0.5);
|
||||
static void equalizer_state_get_band(EqualizerState *s, int hz, int freq_width,int *low_index, int *high_index){
|
||||
int half_band=freq_width/2;
|
||||
*low_index=equalizer_state_hz_to_index(s,hz-half_band);
|
||||
*high_index=equalizer_state_hz_to_index(s,hz+half_band);
|
||||
}
|
||||
|
||||
static void equalizer_state_set(EqualizerState *s, int freqhz, float gain){
|
||||
static void equalizer_state_set(EqualizerState *s, int freqhz, float gain, int freq_width){
|
||||
int low,high;
|
||||
int i;
|
||||
equalizer_state_get_band(s,freqhz,&low,&high);
|
||||
equalizer_state_get_band(s,freqhz,freq_width,&low,&high);
|
||||
for(i=low;i<=high;++i){
|
||||
ms_message("Setting gain %f for freq_index %i (freqhz=%i)",gain,i,freqhz);
|
||||
s->fft_cpx[1+(i*2)]=gain_int16(gain)/s->nfft;
|
||||
s->fft_cpx[1+((i-1)*2)]=gain_int16(gain)/s->nfft;
|
||||
}
|
||||
s->needs_update=TRUE;
|
||||
}
|
||||
|
|
@ -169,11 +170,15 @@ static void equalizer_state_compute_impulse_response(EqualizerState *s){
|
|||
dump_table(s->fft_cpx,s->nfft);
|
||||
ms_ifft(fft_handle,s->fft_cpx,s->fir);
|
||||
ms_fft_destroy(fft_handle);
|
||||
/*
|
||||
ms_message("Inverse fft result:");
|
||||
dump_table(s->fir,s->fir_len);
|
||||
*/
|
||||
time_shift(s->fir,s->fir_len);
|
||||
/*
|
||||
ms_message("Time shifted:");
|
||||
dump_table(s->fir,s->fir_len);
|
||||
*/
|
||||
norm_and_apodize(s->fir,s->fir_len);
|
||||
ms_message("Apodized impulse response:");
|
||||
dump_table(s->fir,s->fir_len);
|
||||
|
|
@ -236,7 +241,7 @@ void equalizer_process(MSFilter *f){
|
|||
int equalizer_set_gain(MSFilter *f, void *data){
|
||||
EqualizerState *s=(EqualizerState*)f->data;
|
||||
MSEqualizerGain *d=(MSEqualizerGain*)data;
|
||||
equalizer_state_set(s,d->frequency,d->gain);
|
||||
equalizer_state_set(s,d->frequency,d->gain,d->width);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -244,6 +249,7 @@ int equalizer_get_gain(MSFilter *f, void *data){
|
|||
EqualizerState *s=(EqualizerState*)f->data;
|
||||
MSEqualizerGain *d=(MSEqualizerGain*)data;
|
||||
d->gain=equalizer_state_get(s,d->frequency);
|
||||
d->width=0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -259,18 +265,11 @@ int equalizer_set_active(MSFilter *f, void *data){
|
|||
return 0;
|
||||
}
|
||||
|
||||
int equalizer_set_freq_width_coef(MSFilter *f, void *data){
|
||||
EqualizerState *s=(EqualizerState*)f->data;
|
||||
s->width_coef=*(float*)data;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static MSFilterMethod equalizer_methods[]={
|
||||
{ MS_EQUALIZER_SET_GAIN , equalizer_set_gain },
|
||||
{ MS_EQUALIZER_GET_GAIN , equalizer_get_gain },
|
||||
{ MS_EQUALIZER_SET_ACTIVE , equalizer_set_active },
|
||||
{ MS_FILTER_SET_SAMPLE_RATE , equalizer_set_rate },
|
||||
{ MS_EQUALIZER_SET_FREQ_WIDTH_COEF, equalizer_set_freq_width_coef},
|
||||
{ 0 , NULL }
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue