crap/crap_eq.h

125 lines
2.6 KiB
C
Raw Normal View History

2014-01-29 17:55:11 -08:00
#include <stdio.h>
#include <string.h>
#include "crap_util.h"
#include "param.h"
#define BANDS 4
#define ID 0x000CAFED
#define LABEL "crap_eq"
#define NAME "crap Parametric Equalizer"
#define AUTHOR "Connor Olding"
#define COPYRIGHT "MIT"
#define PARAMETERS (BANDS*3)
typedef struct {
biquad filters[2][BANDS];
float fs;
} personal;
2014-02-05 23:32:24 -08:00
static double
process_one(biquad *filters, double samp)
2014-01-29 17:55:11 -08:00
{
for (int i = 0; i < BANDS; i++)
samp = biquad_run(&filters[i], samp);
return samp;
}
static void
process(personal *data,
float *in_L, float *in_R,
float *out_L, float *out_R,
2014-02-05 23:47:16 -08:00
unsigned long count)
{
2014-01-29 17:55:11 -08:00
for (unsigned long pos = 0; pos < count; pos++) {
out_L[pos] = process_one(data->filters[0], in_L[pos]);
out_R[pos] = process_one(data->filters[1], in_R[pos]);
}
}
static void
process_double(personal *data,
double *in_L, double *in_R,
double *out_L, double *out_R,
2014-02-05 23:47:16 -08:00
unsigned long count)
{
2014-01-29 17:55:11 -08:00
for (unsigned long pos = 0; pos < count; pos++) {
out_L[pos] = process_one(data->filters[0], in_L[pos]);
out_R[pos] = process_one(data->filters[1], in_R[pos]);
}
}
static void
2014-02-05 23:47:16 -08:00
resume(personal *data)
{
2014-01-29 17:55:11 -08:00
biquad *filters = data->filters[0];
for (int i = 0; i < BANDS; i++)
biquad_init(&filters[i]);
memcpy(data->filters[1], filters, BANDS*sizeof(biquad));
}
static void
2014-02-05 23:47:16 -08:00
pause(personal *data)
{}
2014-01-29 17:55:11 -08:00
static void
2014-02-05 23:47:16 -08:00
construct_params(param *params)
{
2014-01-29 17:55:11 -08:00
for (int i = 0; i < BANDS; i++) {
sprintf(params[0].name, "Band %i Frequency", i + 1);
params[0].min = 20;
params[0].max = 20000;
params[0].scale = SCALE_HZ;
params[0].def = DEFAULT_440;
param_reset(&params[0]);
sprintf(params[1].name, "Band %i Gain", i + 1);
params[1].min = -18;
params[1].max = 18;
params[1].scale = SCALE_DB;
params[1].def = DEFAULT_0;
param_reset(&params[1]);
sprintf(params[2].name, "Band %i Bandwidth", i + 1);
params[2].min = 0.0625; // 2^-4 could probably be 2^-3
params[2].max = 8; // 2^3 could probably be 2^2
2014-01-29 17:55:11 -08:00
params[2].scale = SCALE_FLOAT;
params[2].def = DEFAULT_1;
param_reset(&params[2]);
params += 3;
}
}
2014-01-29 19:36:08 -08:00
static void
2014-02-05 23:47:16 -08:00
construct(personal *data)
{}
2014-01-29 19:36:08 -08:00
2014-01-29 17:55:11 -08:00
static void
2014-02-05 23:47:16 -08:00
destruct(personal *data)
{}
2014-01-29 17:55:11 -08:00
static void
2014-02-05 23:47:16 -08:00
adjust(personal *data, param *params, unsigned long fs)
{
2014-01-29 17:55:11 -08:00
data->fs = fs;
biquad *filters = data->filters[0];
for (int i = 0; i < BANDS; i++) {
filters[i] = biquad_gen(FILT_PEAKING,
2014-01-29 17:55:11 -08:00
params[0].value, params[1].value, params[2].value, fs);
params += 3;
}
resume(data);
}
static void
2014-02-05 23:47:16 -08:00
adjust_one(personal *data, param *params, unsigned int index)
{
2014-01-29 17:55:11 -08:00
float fs = data->fs;
params += index/3*3;
data->filters[0][index/3] = biquad_gen(FILT_PEAKING,
2014-01-29 17:55:11 -08:00
params[0].value, params[1].value, params[2].value, fs);
resume(data);
}