begin work on class-based plugins

ladspa/crap_eq is working, seemingly.
This commit is contained in:
Connor Olding 2015-06-07 13:18:59 -07:00
parent 79ffa24c08
commit dfd81b055b
6 changed files with 213 additions and 108 deletions

View File

@ -10,7 +10,7 @@ LADSPA = $(BOTH)
VST = $(BOTH) delay_test VST = $(BOTH) delay_test
UTILS = design bench UTILS = design bench
INCLUDES = util biquad svf param os6iir os2piir INCLUDES = util Crap biquad svf param os6iir os2piir
BENCH_AGAINST = eq_const BENCH_AGAINST = eq_const

View File

@ -42,3 +42,4 @@ other targets:
* rename plugins (fix capitalization consistency and such) * rename plugins (fix capitalization consistency and such)
* scrap overly-complex makefile for a shell script * scrap overly-complex makefile for a shell script
* support for CPUs without SSE/NEON * support for CPUs without SSE/NEON
* don't mix CamelCase with underscores (only done for legacy reasons)

View File

@ -13,124 +13,136 @@
#include "util.hpp" #include "util.hpp"
#include "param.hpp" #include "param.hpp"
#include "Crap.hpp"
#include "biquad.hpp" #include "biquad.hpp"
typedef struct { template<class Mixin>
biquad filters[2][BANDS]; struct Buffer2 : public virtual Mixin {
float fs; virtual inline void
} personal; process2(v2df *buf, ulong rem) = 0;
TEMPLATE static void TEMPLATE void
process(personal *data, _process(T *in_L, T *in_R, T *out_L, T *out_R, ulong count)
T *in_L, T *in_R, {
T *out_L, T *out_R, disable_denormals();
unsigned long count)
{
disable_denormals();
v2df buf[BLOCK_SIZE]; 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 pos = 0; pos < count; pos += BLOCK_SIZE) { for (ulong i = 0; i < rem; i++) {
ulong rem = BLOCK_SIZE; buf[i][0] = in_L[i];
if (pos + BLOCK_SIZE > count) buf[i][1] = in_R[i];
rem = count - pos; }
for (ulong i = 0; i < rem; i++) { process2(buf, rem);
buf[i][0] = in_L[i];
buf[i][1] = in_R[i]; 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;
} }
}
f0 = data->filters[0]; void
f1 = data->filters[1]; 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);
}
};
struct Crap_eq
:public Unconstructive<
AdjustAll<
Buffer2<Crap>
>
> {
biquad filters_L[BANDS];
biquad filters_R[BANDS];
inline void
process2(v2df *buf, ulong rem)
{
biquad *f0, *f1;
f0 = filters_L;
f1 = filters_R;
for (ulong i = 0; i < BANDS; i++) { for (ulong i = 0; i < BANDS; i++) {
biquad_run_block_stereo(f0, f1, buf, rem); biquad_run_block_stereo(f0, f1, buf, rem);
f0++; f0++;
f1++; f1++;
} }
}
for (ulong i = 0; i < rem; i++) { inline void
out_L[i] = buf[i][0]; pause()
out_R[i] = buf[i][1]; {}
inline void
resume()
{
for (int i = 0; i < BANDS; i++) {
biquad_init(&filters_L[i]);
biquad_init(&filters_R[i]);
} }
in_L += BLOCK_SIZE;
in_R += BLOCK_SIZE;
out_L += BLOCK_SIZE;
out_R += BLOCK_SIZE;
} }
}
INNER void static inline void
resume(personal *data) construct_params(param *params)
{ {
biquad *filters = data->filters[0]; for (int i = 0; i < BANDS; i++) {
for (int i = 0; i < BANDS; i++) sprintf(params[0].name, "Band %i Frequency", i + 1);
biquad_init(&filters[i]); params[0].min = 20;
memcpy(data->filters[1], filters, BANDS*sizeof(biquad)); params[0].max = 20000;
} params[0].scale = SCALE_HZ;
params[0].def = DEFAULT_440;
param_reset(&params[0]);
INNER void sprintf(params[1].name, "Band %i Gain", i + 1);
pause(personal *data) params[1].min = -18;
{} params[1].max = 18;
params[1].scale = SCALE_DB;
params[1].def = DEFAULT_0;
param_reset(&params[1]);
INNER void sprintf(params[2].name, "Band %i Bandwidth", i + 1);
construct_params(param *params) params[2].min = 0.0625; // 2^-4 could probably be 2^-3
{ params[2].max = 8; // 2^3 could probably be 2^2
for (int i = 0; i < BANDS; i++) { params[2].scale = SCALE_FLOAT;
sprintf(params[0].name, "Band %i Frequency", i + 1); params[2].def = DEFAULT_1;
params[0].min = 20; param_reset(&params[2]);
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 += 3;
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
params[2].scale = SCALE_FLOAT;
params[2].def = DEFAULT_1;
param_reset(&params[2]);
params += 3;
} }
}
INNER void inline void
construct(personal *data) adjust_all(param *params)
{} {
for (int i = 0; i < BANDS; i++) {
INNER void filters_L[i] = biquad_gen(FILT_PEAKING,
destruct(personal *data) params[0].value, params[1].value, params[2].value, (double) fs);
{} params += 3;
filters_R[i] = filters_L[i];
INNER void }
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(FILT_PEAKING,
params[0].value, params[1].value, params[2].value, fs);
params += 3;
} }
resume(data); };
}
INNER 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(FILT_PEAKING,
params[0].value, params[1].value, params[2].value, fs);
resume(data);
}

85
include/Crap.hpp Normal file
View File

@ -0,0 +1,85 @@
struct Crap {
virtual inline
~Crap() {}
virtual inline void
construct() = 0;
virtual inline void
destruct() = 0;
virtual void
pause() = 0;
virtual void
resume() = 0;
virtual void
process(
double *in_L, double *in_R,
double *out_L, double *out_R,
ulong count) = 0;
virtual void
process(
float *in_L, float *in_R,
float *out_L, float *out_R,
ulong count) = 0;
//void
//construct_params(param *params) = 0;
virtual void
adjust(param *params, ulong fs) = 0;
virtual void
adjust_one(param *params, int i) = 0;
};
template<class Mixin>
struct AdjustAll : public virtual Mixin {
ulong fs;
virtual void
adjust_all(param *params) = 0;
inline void
adjust(param *params, ulong fs_new)
{
fs = fs_new;
adjust_all(params);
}
inline void
adjust_one(param *params, int i)
{
adjust_all(params);
}
};
template<class Mixin>
struct Unconstructive : public virtual Mixin {
inline void
construct()
{};
inline void
destruct()
{};
};
template<class Mixin>
struct NoParams : public virtual Mixin {
// etc
//void
//construct_params(param *params) = 0;
void
adjust(param *params, ulong fs)
{}
void
adjust_one(param *params, int i)
{}
};

View File

@ -2,6 +2,7 @@
#include "ladspa.hpp" #include "ladspa.hpp"
//#INCLUDE //#INCLUDE
//#REDEFINE
#ifndef PARAM_NAME_LEN #ifndef PARAM_NAME_LEN
#define PARAM_NAME_LEN 24 #define PARAM_NAME_LEN 24
@ -33,7 +34,7 @@ typedef struct {
LADSPA_Data *output_L; LADSPA_Data *output_L;
LADSPA_Data *output_R; LADSPA_Data *output_R;
personal data; Crap *crap;
#if (PARAMETERS > 0) #if (PARAMETERS > 0)
LADSPA_Data *values[PARAMETERS]; LADSPA_Data *values[PARAMETERS];
param params[PARAMETERS]; param params[PARAMETERS];
@ -62,26 +63,27 @@ static void
plug_resume(LADSPA_Handle instance) plug_resume(LADSPA_Handle instance)
{ {
plug_t *plug = (plug_t *)instance; plug_t *plug = (plug_t *)instance;
resume(&plug->data); plug->crap->resume();
} }
static void static void
plug_pause(LADSPA_Handle instance) plug_pause(LADSPA_Handle instance)
{ {
plug_t *plug = (plug_t *)instance; plug_t *plug = (plug_t *)instance;
pause(&plug->data); plug->crap->pause();
} }
static LADSPA_Handle static LADSPA_Handle
plug_construct(const LADSPA_Descriptor *descriptor, unsigned long fs) plug_construct(const LADSPA_Descriptor *descriptor, unsigned long fs)
{ {
plug_t *plug = (plug_t *) calloc(1, sizeof(plug_t)); plug_t *plug = (plug_t *) calloc(1, sizeof(plug_t));
construct(&plug->data); plug->crap = new CrapPlug();
plug->crap->construct();
#if (PARAMETERS > 0) #if (PARAMETERS > 0)
memcpy(plug->params, global_params, sizeof(param)*PARAMETERS); memcpy(plug->params, global_params, sizeof(param)*PARAMETERS);
adjust(&plug->data, plug->params, fs); plug->crap->adjust(plug->params, fs);
#else #else
adjust(&plug->data, fs); plug->crap->adjust(NULL, fs);
#endif #endif
return (LADSPA_Handle) plug; return (LADSPA_Handle) plug;
} }
@ -90,7 +92,8 @@ static void
plug_destruct(LADSPA_Handle instance) plug_destruct(LADSPA_Handle instance)
{ {
plug_t *plug = (plug_t *)instance; plug_t *plug = (plug_t *)instance;
destruct(&plug->data); plug->crap->destruct();
delete plug->crap;
free(plug); free(plug);
} }
@ -104,11 +107,11 @@ plug_process(LADSPA_Handle instance, unsigned long count)
continue; continue;
if (*plug->values[i] != plug->params[i].value) { if (*plug->values[i] != plug->params[i].value) {
plug->params[i].value = *plug->values[i]; plug->params[i].value = *plug->values[i];
adjust_one(&plug->data, plug->params, i); plug->crap->adjust_one(plug->params, i);
} }
} }
#endif #endif
process(&plug->data, plug->crap->process(
plug->input_L, plug->input_R, plug->input_L, plug->input_R,
plug->output_L, plug->output_R, plug->output_L, plug->output_R,
count); count);
@ -155,7 +158,7 @@ plug_init()
} }
#if (PARAMETERS > 0) #if (PARAMETERS > 0)
construct_params(global_params); CrapPlug::construct_params(global_params);
for (int i = 0; i < PARAMETERS; i++) { for (int i = 0; i < PARAMETERS; i++) {
int j = i + 4; int j = i + 4;
param *p = &global_params[i]; param *p = &global_params[i];

View File

@ -2,7 +2,10 @@
set -e set -e
set -u set -u
pp_class="${1%*.hpp}"
pp_class="${pp_class#crap/*}"
pp_include="#include \"$1\"" pp_include="#include \"$1\""
pp_redefine="#define CrapPlug Crap_$pp_class"
out="$2" out="$2"
template="$3" template="$3"
@ -10,6 +13,7 @@ template="$3"
case "$REPLY" in case "$REPLY" in
'//#INCLUDE') echo "$pp_include" ;; '//#INCLUDE') echo "$pp_include" ;;
'//#REDEFINE') echo "$pp_redefine" ;;
*) echo -E "$REPLY" ;; *) echo -E "$REPLY" ;;
esac esac