eqfil

Files: eqfil.h, eqfil.c

2nd order tunable equalization filter
This provides a peak/notch filter for building parametric/graphic equalizers. With gain above 1, there will be a peak at the center frequency with a width dependent on bw. If gain is less than 1, a notch is formed around the center frequency (freq).

Functions

sp_eqfil_create(sp_eqfil **eqfil)
sp_eqfil_init(sp_data *sp, sp_eqfil *eqfil)
sp_eqfil_compute(sp_data *sp, sp_eqfil *eqfil, SPFLOAT *input, SPFLOAT *output)
sp_eqfil_destroy(sp_eqfil **eqfil)

Optional Parameters

freq: The center frequency of the filter
(Default value: 1000)
bw: The peak/notch bandwidth in Hertz
(Default value: 125)
gain: The peak/notch gain
(Default value: 2)

Inputs

input: Signal input.

Outputs

output: Signal output.

Example Code

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include "soundpipe.h"

typedef struct {
    sp_noise *ns;
    sp_eqfil *eqfil;
    int counter;
} UserData;

void write_noise(sp_data *data, void *ud) {
    UserData *udata = ud;
    SPFLOAT in = 0;
    SPFLOAT out = 0;
    if(udata->counter == 0) {
        udata->eqfil->freq = 500 + rand() % 4000;
        udata->eqfil->bw = fabs(udata->eqfil->freq * 0.5);
    }
    sp_noise_compute(data, udata->ns, NULL, &in);
    sp_eqfil_compute(data, udata->eqfil, &in, &data->out[0]); 
    udata->counter = (udata->counter + 1) % 5000;
}
int main() {
    srand(time(NULL));
    UserData ud;
    ud.counter = 0;
    sp_data *sp;
    sp_create(&sp);
    sp_noise_create(&ud.ns);
    sp_eqfil_create(&ud.eqfil);
    sp_noise_init(sp, ud.ns);
    sp_eqfil_init(sp, ud.eqfil);
    sp->len = 44100 * 5;
    sp_process(sp, &ud, write_noise);
    sp_noise_destroy(&ud.ns);
    sp_eqfil_destroy(&ud.eqfil);
    sp_destroy(&sp);
    return 0;
}