diff --git a/crap/eq.h b/crap/eq.h index 578ca90..244063d 100644 --- a/crap/eq.h +++ b/crap/eq.h @@ -1,9 +1,6 @@ #include #include -#include "util.h" -#include "param.h" - #define BANDS 4 #define ID 0x000CAFED @@ -13,44 +10,29 @@ #define COPYRIGHT "MIT" #define PARAMETERS (BANDS*3) +#define BLOCK_SIZE 256 + +#include "util.h" +#include "param.h" + typedef struct { biquad filters[2][BANDS]; float fs; } personal; -INNER double -process_one(biquad *filters, double samp) -{ - for (int i = 0; i < BANDS; i++) - samp = biquad_run(&filters[i], samp); - return samp; -} - -INNER void -process(personal *data, - float *in_L, float *in_R, - float *out_L, float *out_R, - unsigned long count) -{ - disable_denormals(); - 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]); - } -} - -INNER void +static void process_double(personal *data, double *in_L, double *in_R, double *out_L, double *out_R, unsigned long count) -{ - disable_denormals(); - 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]); - } -} +#include "process_biquads.h" + +static void +process(personal *data, + float *in_L, float *in_R, + float *out_L, float *out_R, + ulong count) +#include "process_biquads.h" INNER void resume(personal *data) diff --git a/crap/eq_const.h b/crap/eq_const.h index 8aa9644..101ea7c 100644 --- a/crap/eq_const.h +++ b/crap/eq_const.h @@ -20,45 +20,15 @@ static void process_double(personal *data, double *in_L, double *in_R, double *out_L, double *out_R, + unsigned long count) +#include "process_biquads.h" + +static void +process(personal *data, + float *in_L, float *in_R, + float *out_L, float *out_R, ulong count) -{ - disable_denormals(); - - v2df buf[BLOCK_SIZE]; - - biquad *f0, *f1; - - for (ulong pos = 0; pos < count; pos += BLOCK_SIZE) { - ulong rem = BLOCK_SIZE; - if (pos + BLOCK_SIZE > count) - rem = count - pos; - - for (ulong i = 0; i < rem; i++) { - buf[i][0] = in_L[i]; - buf[i][1] = in_R[i]; - } - - f0 = data->filters[0]; - f1 = data->filters[1]; - for (ulong i = 0; i < BANDS; i++) { - biquad_run_block_stereo(f0, f1, buf, rem); - f0++; - f1++; - } - - for (ulong i = 0; i < rem; i++) { - out_L[i] = buf[i][0]; - out_R[i] = buf[i][1]; - } - - in_L += BLOCK_SIZE; - in_R += BLOCK_SIZE; - out_L += BLOCK_SIZE; - out_R += BLOCK_SIZE; - } -} - -#include "process.h" +#include "process_biquads.h" INNER void construct(personal *data) diff --git a/include/process_biquads.h b/include/process_biquads.h new file mode 100644 index 0000000..a277a4d --- /dev/null +++ b/include/process_biquads.h @@ -0,0 +1,36 @@ +{ + disable_denormals(); + + v2df buf[BLOCK_SIZE]; + + biquad *f0, *f1; + + for (ulong pos = 0; pos < count; pos += BLOCK_SIZE) { + ulong rem = BLOCK_SIZE; + if (pos + BLOCK_SIZE > count) + rem = count - pos; + + for (ulong i = 0; i < rem; i++) { + buf[i][0] = in_L[i]; + buf[i][1] = in_R[i]; + } + + f0 = data->filters[0]; + f1 = data->filters[1]; + for (ulong i = 0; i < BANDS; i++) { + biquad_run_block_stereo(f0, f1, buf, rem); + f0++; + f1++; + } + + for (ulong i = 0; i < rem; i++) { + out_L[i] = buf[i][0]; + out_R[i] = buf[i][1]; + } + + in_L += BLOCK_SIZE; + in_R += BLOCK_SIZE; + out_L += BLOCK_SIZE; + out_R += BLOCK_SIZE; + } +}