diff --git a/crap/eq_const_T420.hpp b/crap/eq_const_T420.hpp index 0f7bc51..75796c7 100644 --- a/crap/eq_const_T420.hpp +++ b/crap/eq_const_T420.hpp @@ -1,103 +1,81 @@ -#define ID (0x0DEFACED+420) -#define LABEL "crap_eq_const_T420" -#define NAME "crap T420 Speaker Compensation" -#define AUTHOR "Connor Olding" -#define COPYRIGHT "MIT" -#define PARAMETERS 0 - #define BLOCK_SIZE 256 #include #include "util.hpp" +#include "Param.hpp" +#include "Crap.hpp" +#include "Buffer2.hpp" #include "biquad.hpp" -#define BANDS 16 -typedef struct { - biquad filters[2][BANDS]; -} personal; +struct Crap_eq_const_T420 +:public AdjustAll> { + static constexpr ulong id = 0x0DEFACED; + static constexpr char label[] = "crap_eq_const"; + static constexpr char name[] = "crap Constant Equalizer"; + static constexpr char author[] = "Connor Olding"; + static constexpr char copyright[] = "MIT"; -TEMPLATE static void -process(personal *data, - T *in_L, T *in_R, - T *out_L, T *out_R, - ulong count) -{ - disable_denormals(); + static constexpr ulong bands = 16; + static constexpr ulong parameters = 0; - v2df buf[BLOCK_SIZE]; + biquad filters_L[bands]; + biquad filters_R[bands]; - 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++) { + inline void + process2(v2df *buf, ulong rem) + { + biquad *f0, *f1; + f0 = filters_L; + f1 = filters_R; + 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; } -} -INNER void -construct(personal *data) -{} + inline void + pause() + {} -INNER void -destruct(personal *data) -{} + inline void + resume() + { + for (int i = 0; i < bands; i++) { + biquad_init(&filters_L[i]); + biquad_init(&filters_R[i]); + } + } -INNER void -resume(personal *data) -{ - 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 inline void + construct_params(Param *params) + {} -INNER void -pause(personal *data) -{} + virtual void + adjust_all(Param *params) + { + biquad *f = filters_L; + f[ 0] = biquad_gen(FILT_PEAKING, 180., 11., 1.40, fs); + f[ 1] = biquad_gen(FILT_PEAKING, 740., 5.5, 0.70, fs); + f[ 2] = biquad_gen(FILT_PEAKING, 1220, -12., 0.70, fs); + f[ 3] = biquad_gen(FILT_PEAKING, 1580, 7.0, 0.25, fs); + f[ 4] = biquad_gen(FILT_PEAKING, 2080, -2.5, 0.30, fs); + f[ 5] = biquad_gen(FILT_PEAKING, 2270, 6.0, 0.20, fs); + f[ 6] = biquad_gen(FILT_PEAKING, 2470, -2.0, 0.18, fs); + f[ 7] = biquad_gen(FILT_PEAKING, 3700, -5.0, 0.32, fs); + f[ 8] = biquad_gen(FILT_PEAKING, 6200, -3.5, 0.25, fs); + f[ 9] = biquad_gen(FILT_PEAKING, 6000, -11., 3.66, fs); + f[10] = biquad_gen(FILT_HIGHSHELF, 11500, 4.0, 0.40, fs); + f[11] = biquad_gen(FILT_HIGHPASS, 150, 0.0, 1.00, fs); + f[12] = biquad_gen(FILT_PEAKING, 1775, -2.0, 0.18, fs); + f[13] = biquad_gen(FILT_PEAKING, 490, -1.5, 0.23, fs); + f[14] = biquad_gen(FILT_PEAKING, 3100, 5.0, 0.33, fs); + f[15] = biquad_gen(FILT_LOWPASS, 14000, 0.0, 0.40, fs); + } +}; -INNER void -adjust(personal *data, ulong fs) -{ - biquad *filters = data->filters[0]; - filters[ 0] = biquad_gen(FILT_PEAKING, 180., 11., 1.40, fs); - filters[ 1] = biquad_gen(FILT_PEAKING, 740., 5.5, 0.70, fs); - filters[ 2] = biquad_gen(FILT_PEAKING, 1220, -12., 0.70, fs); - filters[ 3] = biquad_gen(FILT_PEAKING, 1580, 7.0, 0.25, fs); - filters[ 4] = biquad_gen(FILT_PEAKING, 2080, -2.5, 0.30, fs); - filters[ 5] = biquad_gen(FILT_PEAKING, 2270, 6.0, 0.20, fs); - filters[ 6] = biquad_gen(FILT_PEAKING, 2470, -2.0, 0.18, fs); - filters[ 7] = biquad_gen(FILT_PEAKING, 3700, -5.0, 0.32, fs); - filters[ 8] = biquad_gen(FILT_PEAKING, 6200, -3.5, 0.25, fs); - filters[ 9] = biquad_gen(FILT_PEAKING, 6000, -11., 3.66, fs); - filters[10] = biquad_gen(FILT_HIGHSHELF, 11500, 4.0, 0.40, fs); - filters[11] = biquad_gen(FILT_HIGHPASS, 150, 0.0, 1.00, fs); - filters[12] = biquad_gen(FILT_PEAKING, 1775, -2.0, 0.18, fs); - filters[13] = biquad_gen(FILT_PEAKING, 490, -1.5, 0.23, fs); - filters[14] = biquad_gen(FILT_PEAKING, 3100, 5.0, 0.33, fs); - filters[15] = biquad_gen(FILT_LOWPASS, 14000, 0.0, 0.40, fs); -} +constexpr char Crap_eq_const_T420::label[]; +constexpr char Crap_eq_const_T420::name[]; +constexpr char Crap_eq_const_T420::author[]; +constexpr char Crap_eq_const_T420::copyright[]; diff --git a/crap/eq_const_T420_svf.hpp b/crap/eq_const_T420_svf.hpp index 80afd43..62ef5aa 100644 --- a/crap/eq_const_T420_svf.hpp +++ b/crap/eq_const_T420_svf.hpp @@ -1,10 +1,3 @@ -#define ID (0x0DEFACED+420+1337) -#define LABEL "crap_eq_const_T420_svf" -#define NAME "crap T420 Speaker Compensation (SVF)" -#define AUTHOR "Connor Olding" -#define COPYRIGHT "MIT" -#define PARAMETERS 0 - #define BLOCK_SIZE 256 #include @@ -12,104 +5,84 @@ #include #include "util.hpp" +#include "Param.hpp" +#include "Crap.hpp" #include "svf.hpp" +#include "Buffer4.hpp" -#define BANDS 16 -typedef struct { - svf_matrix filters[2][BANDS]; -} personal; +struct Crap_eq_const_T420_svf +:public AdjustAll> { + static constexpr ulong id = 0x0DEFACED + 420 + 1337; + static constexpr char label[] = "crap_eq_const"; + static constexpr char name[] = "crap T420 Speaker Compensation (SVF)"; + static constexpr char author[] = "Connor Olding"; + static constexpr char copyright[] = "MIT"; -TEMPLATE static void -process(personal *data, - T *in_L, T *in_R, - T *out_L, T *out_R, - unsigned long count) -{ - disable_denormals(); + static constexpr ulong bands = 16; + static constexpr ulong parameters = 0; - assert(count % 2 == 0); + svf_matrix filters_L[bands]; + svf_matrix filters_R[bands]; - v4sf buf_L[BLOCK_SIZE/2]; - v4sf buf_R[BLOCK_SIZE/2]; + virtual inline void + process2(v4sf *buf_L, v4sf *buf_R, ulong rem) + { + svf_matrix *f0, *f1; + f0 = filters_L; + f1 = filters_R; - svf_matrix *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, j = 0; i < rem; i += 2, j++) { - buf_L[j][0] = in_L[i+0]; - buf_L[j][1] = in_L[i+1]; - buf_R[j][0] = in_R[i+0]; - buf_R[j][1] = in_R[i+1]; - } - - f0 = data->filters[0]; - for (ulong i = 0; i < BANDS; i++) { + for (ulong i = 0; i < bands; i++) { svf_run_block_mat(f0, buf_L, rem); f0++; } - f1 = data->filters[1]; - for (ulong i = 0; i < BANDS; i++) { + for (ulong i = 0; i < bands; i++) { svf_run_block_mat(f1, buf_R, rem); f1++; } - - for (ulong i = 0, j = 0; i < rem; i += 2, j++) { - out_L[i+0] = buf_L[j][0]; - out_L[i+1] = buf_L[j][1]; - out_R[i+0] = buf_R[j][0]; - out_R[i+1] = buf_R[j][1]; - } - - in_L += BLOCK_SIZE; - in_R += BLOCK_SIZE; - out_L += BLOCK_SIZE; - out_R += BLOCK_SIZE; } -} -INNER void -construct(personal *data) -{} + inline void + pause() + {} -INNER void -destruct(personal *data) -{} + inline void + resume() + { + svf_matrix *filters = filters_L; + for (int i = 0; i < bands; i++) + filters[i].memory = v4sf(0); + memcpy(filters_R, filters, bands*sizeof(svf_matrix)); + } -INNER void -resume(personal *data) -{ - svf_matrix *filters = data->filters[0]; - for (int i = 0; i < BANDS; i++) - filters[i].memory = v4sf(0); - memcpy(data->filters[1], filters, BANDS*sizeof(svf_matrix)); -} + static inline void + construct_params(Param *params) + {} -INNER void -pause(personal *data) -{} + inline void + adjust_all(Param *params) + { + svf_matrix *f = filters_L; + #define gen(a, b, c, d, e) svf_gen_matrix(svf_gen(a, b, c, d, e)) + f[ 0] = gen(FILT_PEAKING, 180., 11., 1.40, fs); + f[ 1] = gen(FILT_PEAKING, 740., 5.5, 0.70, fs); + f[ 2] = gen(FILT_PEAKING, 1220, -12., 0.70, fs); + f[ 3] = gen(FILT_PEAKING, 1580, 7.0, 0.25, fs); + f[ 4] = gen(FILT_PEAKING, 2080, -2.5, 0.30, fs); + f[ 5] = gen(FILT_PEAKING, 2270, 6.0, 0.20, fs); + f[ 6] = gen(FILT_PEAKING, 2470, -2.0, 0.18, fs); + f[ 7] = gen(FILT_PEAKING, 3700, -5.0, 0.32, fs); + f[ 8] = gen(FILT_PEAKING, 6200, -3.5, 0.25, fs); + f[ 9] = gen(FILT_PEAKING, 6000, -11., 3.66, fs); + f[10] = gen(FILT_HIGHSHELF, 11500, 4.0, 0.40, fs); + f[11] = gen(FILT_HIGHPASS, 150, 0.0, 1.00, fs); + f[12] = gen(FILT_PEAKING, 1775, -2.0, 0.18, fs); + f[13] = gen(FILT_PEAKING, 490, -1.5, 0.23, fs); + f[14] = gen(FILT_PEAKING, 3100, 5.0, 0.33, fs); + f[15] = gen(FILT_LOWPASS, 14000, 0.0, 0.40, fs); + } +}; -INNER void -adjust(personal *data, ulong fs) -{ - svf_matrix *filters = data->filters[0]; - filters[ 0] = svf_gen_matrix(svf_gen(FILT_PEAKING, 180., 11., 1.40, fs)); - filters[ 1] = svf_gen_matrix(svf_gen(FILT_PEAKING, 740., 5.5, 0.70, fs)); - filters[ 2] = svf_gen_matrix(svf_gen(FILT_PEAKING, 1220, -12., 0.70, fs)); - filters[ 3] = svf_gen_matrix(svf_gen(FILT_PEAKING, 1580, 7.0, 0.25, fs)); - filters[ 4] = svf_gen_matrix(svf_gen(FILT_PEAKING, 2080, -2.5, 0.30, fs)); - filters[ 5] = svf_gen_matrix(svf_gen(FILT_PEAKING, 2270, 6.0, 0.20, fs)); - filters[ 6] = svf_gen_matrix(svf_gen(FILT_PEAKING, 2470, -2.0, 0.18, fs)); - filters[ 7] = svf_gen_matrix(svf_gen(FILT_PEAKING, 3700, -5.0, 0.32, fs)); - filters[ 8] = svf_gen_matrix(svf_gen(FILT_PEAKING, 6200, -3.5, 0.25, fs)); - filters[ 9] = svf_gen_matrix(svf_gen(FILT_PEAKING, 6000, -11., 3.66, fs)); - filters[10] = svf_gen_matrix(svf_gen(FILT_HIGHSHELF, 11500, 4.0, 0.40, fs)); - filters[11] = svf_gen_matrix(svf_gen(FILT_HIGHPASS, 150, 0.0, 1.00, fs)); - filters[12] = svf_gen_matrix(svf_gen(FILT_PEAKING, 1775, -2.0, 0.18, fs)); - filters[13] = svf_gen_matrix(svf_gen(FILT_PEAKING, 490, -1.5, 0.23, fs)); - filters[14] = svf_gen_matrix(svf_gen(FILT_PEAKING, 3100, 5.0, 0.33, fs)); - filters[15] = svf_gen_matrix(svf_gen(FILT_LOWPASS, 14000, 0.0, 0.40, fs)); -} +constexpr char Crap_eq_const_T420_svf::label[]; +constexpr char Crap_eq_const_T420_svf::name[]; +constexpr char Crap_eq_const_T420_svf::author[]; +constexpr char Crap_eq_const_T420_svf::copyright[]; diff --git a/include/Buffer4.hpp b/include/Buffer4.hpp new file mode 100644 index 0000000..67a93c8 --- /dev/null +++ b/include/Buffer4.hpp @@ -0,0 +1,61 @@ +template +struct Buffer4 : public virtual Mixin { + virtual inline void + process2(v4sf *buf_L, v4sf *buf_R, ulong rem) = 0; + + TEMPLATE void + _process(T *in_L, T *in_R, T *out_L, T *out_R, ulong count) + { + disable_denormals(); + + assert(count % 2 == 0); + + v4sf buf_L[BLOCK_SIZE/2]; + v4sf buf_R[BLOCK_SIZE/2]; + + 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, j = 0; i < rem; i += 2, j++) { + buf_L[j][0] = in_L[i+0]; + buf_L[j][1] = in_L[i+1]; + buf_R[j][0] = in_R[i+0]; + buf_R[j][1] = in_R[i+1]; + } + + process2(buf_L, buf_R, rem); + + for (ulong i = 0, j = 0; i < rem; i += 2, j++) { + out_L[i+0] = buf_L[j][0]; + out_L[i+1] = buf_L[j][1]; + out_R[i+0] = buf_R[j][0]; + out_R[i+1] = buf_R[j][1]; + } + + in_L += BLOCK_SIZE; + in_R += BLOCK_SIZE; + out_L += BLOCK_SIZE; + out_R += BLOCK_SIZE; + } + } + + void + process( + double *in_L, double *in_R, + double *out_L, double *out_R, + ulong count) + { + _process(in_L, in_R, out_L, out_R, count); + } + + void + process( + float *in_L, float *in_R, + float *out_L, float *out_R, + ulong count) + { + _process(in_L, in_R, out_L, out_R, count); + } +};