enum filter types, alternate Q calculation
This commit is contained in:
parent
a97baa7779
commit
3efe119c57
5 changed files with 40 additions and 36 deletions
|
@ -126,7 +126,7 @@ adjust(personal *data, ulong fs) {
|
|||
c->up[i] = 0;
|
||||
for (int i = 0; i < DOWN; i++)
|
||||
c->down[i] = 0;
|
||||
c->filter = biquad_gen(0, 16630, 10, 1, fs*oversample);
|
||||
c->filter = biquad_gen(FILT_PEAKING, 16630, 10, 1, fs*oversample);
|
||||
biquad_init(&c->filter);
|
||||
}
|
||||
}
|
||||
|
|
8
crap_eq.h
Executable file → Normal file
8
crap_eq.h
Executable file → Normal file
|
@ -79,8 +79,8 @@ construct_params(param *params) {
|
|||
param_reset(¶ms[1]);
|
||||
|
||||
sprintf(params[2].name, "Band %i Bandwidth", i + 1);
|
||||
params[2].min = 0.0625;
|
||||
params[2].max = 8;
|
||||
params[2].min = 0.0625; // 2^-4 could probably be 2^-3
|
||||
params[2].max = 8; // 2^3 could probably be 2^2
|
||||
params[2].scale = SCALE_FLOAT;
|
||||
params[2].def = DEFAULT_1;
|
||||
param_reset(¶ms[2]);
|
||||
|
@ -102,7 +102,7 @@ adjust(personal *data, param *params, unsigned long fs) {
|
|||
data->fs = fs;
|
||||
biquad *filters = data->filters[0];
|
||||
for (int i = 0; i < BANDS; i++) {
|
||||
filters[i] = biquad_gen(0,
|
||||
filters[i] = biquad_gen(FILT_PEAKING,
|
||||
params[0].value, params[1].value, params[2].value, fs);
|
||||
params += 3;
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ static void
|
|||
adjust_one(personal *data, param *params, unsigned int index) {
|
||||
float fs = data->fs;
|
||||
params += index/3*3;
|
||||
data->filters[0][index/3] = biquad_gen(0,
|
||||
data->filters[0][index/3] = biquad_gen(FILT_PEAKING,
|
||||
params[0].value, params[1].value, params[2].value, fs);
|
||||
resume(data);
|
||||
}
|
||||
|
|
|
@ -69,8 +69,8 @@ pause(personal *data) {
|
|||
static void
|
||||
adjust(personal *data, unsigned long fs) {
|
||||
biquad *filters = data->filters[0];
|
||||
filters[0] = biquad_gen(0, 34.34, +4.6, 1.21, fs);
|
||||
filters[1] = biquad_gen(0, 85.74, -1.2, 1.31, fs);
|
||||
filters[2] = biquad_gen(2, 862.2, -5.5, 1.00, fs);
|
||||
filters[3] = biquad_gen(0, 7496., +3.3, 1.10, fs);
|
||||
filters[0] = biquad_gen(FILT_PEAKING, 34.34, +4.6, 1.21, fs);
|
||||
filters[1] = biquad_gen(FILT_PEAKING, 85.74, -1.2, 1.31, fs);
|
||||
filters[2] = biquad_gen(FILT_HIGHSHELF, 862.2, -5.5, 1.00, fs);
|
||||
filters[3] = biquad_gen(FILT_PEAKING, 7496., +3.3, 1.10, fs);
|
||||
}
|
||||
|
|
27
crap_util.h
27
crap_util.h
|
@ -29,20 +29,21 @@ whitenoise();
|
|||
static void
|
||||
biquad_init(biquad *bq);
|
||||
|
||||
/* types: TODO: enum
|
||||
0: peaking
|
||||
1: lowshelf
|
||||
2: highshelf
|
||||
3: lowpass
|
||||
4: highpass
|
||||
5: allpass
|
||||
6: bandpass 1
|
||||
7: bandpass 2
|
||||
8: notch
|
||||
9: gain
|
||||
*/
|
||||
typedef enum {
|
||||
FILT_PEAKING,
|
||||
FILT_LOWSHELF,
|
||||
FILT_HIGHSHELF,
|
||||
FILT_LOWPASS,
|
||||
FILT_HIGHPASS,
|
||||
FILT_ALLPASS,
|
||||
FILT_BANDPASS,
|
||||
FILT_BANDPASS_2,
|
||||
FILT_NOTCH,
|
||||
FILT_GAIN
|
||||
} filter_t;
|
||||
|
||||
static biquad
|
||||
biquad_gen(int type, double fc, double gain, double bw, double fs);
|
||||
biquad_gen(filter_t type, double fc, double gain, double bw, double fs);
|
||||
|
||||
/* s-plane to z-plane */
|
||||
static biquad_interim
|
||||
|
|
|
@ -38,29 +38,32 @@ design(double cw, double sw,
|
|||
}
|
||||
|
||||
static biquad
|
||||
biquad_gen(int type, double fc, double gain, double bw, double fs) {
|
||||
biquad_gen(filter_t type, double fc, double gain, double bw, double fs) {
|
||||
double w0, cw, sw, A, As, Q;
|
||||
w0 = ANGULAR_LIM(fc, fs);
|
||||
cw = cos(w0);
|
||||
sw = sin(w0);
|
||||
A = DB2LIN(gain/2);
|
||||
As = sqrt(A);
|
||||
Q = 1/(4*sinh(M_LN2/2*bw*w0/sw));
|
||||
//Q = M_SQRT1_2*(1 - SQR(w0/M_PI))/bw;
|
||||
Q = M_SQRT1_2*(1 - (w0/M_PI)*(w0/M_PI))/bw;
|
||||
/* skip = (fabs(A - 1) <= TINY); */
|
||||
|
||||
/* TODO: use enum for type instead of just int */
|
||||
biquad_interim bqi;
|
||||
if (type == 0) bqi = design(cw,sw, 1, A/Q, 1, 1, 1/A/Q, 1);
|
||||
if (type == 1) bqi = design(cw,sw, 1, As/Q, A, 1, 1/As/Q, 1/A);
|
||||
if (type == 2) bqi = design(cw,sw, A, As/Q, 1, 1/A, 1/As/Q, 1);
|
||||
if (type == 3) bqi = design(cw,sw, 0, 0, 1, 1, 1/Q, 1);
|
||||
if (type == 4) bqi = design(cw,sw, 1, 0, 0, 1, 1/Q, 1);
|
||||
if (type == 5) bqi = design(cw,sw, 1, -1/Q, 1, 1, 1/Q, 1);
|
||||
if (type == 6) bqi = design(cw,sw, 0, 1, 0, 1, 1/Q, 1);
|
||||
if (type == 7) bqi = design(cw,sw, 0, 1/Q, 0, 1, 1/Q, 1);
|
||||
if (type == 8) bqi = design(cw,sw, 1, 0, 1, 1, 1/Q, 1);
|
||||
if (type == 9) bqi = design(cw,sw, A, A, A, 1/A, 1/A, 1/A);
|
||||
|
||||
#define d(n0,n1,n2,d0,d1,d2) bqi = design(cw,sw,n0,n1,n2,d0,d1,d2)
|
||||
switch (type) {
|
||||
case FILT_PEAKING: d(1, A/Q, 1, 1, 1/A/Q, 1); break;
|
||||
case FILT_LOWSHELF: d(1, As/Q, A, 1, 1/As/Q, 1/A); break;
|
||||
case FILT_HIGHSHELF: d(A, As/Q, 1, 1/A, 1/As/Q, 1); break;
|
||||
case FILT_LOWPASS: d(0, 0, 1, 1, 1/Q, 1); break;
|
||||
case FILT_HIGHPASS: d(1, 0, 0, 1, 1/Q, 1); break;
|
||||
case FILT_ALLPASS: d(1, -1/Q, 1, 1, 1/Q, 1); break;
|
||||
case FILT_BANDPASS: d(0, 1, 0, 1, 1/Q, 1); break;
|
||||
case FILT_BANDPASS_2: d(0, 1/Q, 0, 1, 1/Q, 1); break;
|
||||
case FILT_NOTCH: d(1, 0, 1, 1, 1/Q, 1); break;
|
||||
case FILT_GAIN: d(A, A, A, 1/A, 1/A, 1/A); break;
|
||||
}
|
||||
#undef d
|
||||
|
||||
double a0r = 1/bqi.a0;
|
||||
|
||||
|
|
Loading…
Reference in a new issue