From c741ef87f33039705dec762e063e44171ca44acb Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sun, 15 Sep 2013 20:02:11 -0700 Subject: [PATCH] const highly essential 0day fix in readme as well --- Makefile | 2 +- README.md | 4 +- crap_eq_const.c | 140 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 143 insertions(+), 3 deletions(-) create mode 100755 crap_eq_const.c diff --git a/Makefile b/Makefile index b59d67a..adad318 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ DISTNAME = crap VERSION = git EXE = design -SHOBJ = crap_eq.so +SHOBJ = crap_eq.so crap_eq_const.so MID = crap_util.o HEADERS = crap_util.h ladspa.h diff --git a/README.md b/README.md index c1052dc..57acfe8 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ connor's rancid audio plugins. LADSPA. -alternatively, crazy-revealing androgynous panties. +alternatively, chocolate recipes are powerful. ### crap_eq @@ -10,4 +10,4 @@ multiband parametric EQ. try redefining BANDS. ### crap_eq_const -workinonit... +simplified code for a response defined at compile-time. diff --git a/crap_eq_const.c b/crap_eq_const.c new file mode 100755 index 0000000..1c33279 --- /dev/null +++ b/crap_eq_const.c @@ -0,0 +1,140 @@ +#include +#include + +#include "ladspa.h" +#include "crap_util.h" + +typedef unsigned long ulong; + +#define REALBANDS 4 +#define EQ_INPUT 0 +#define EQ_OUTPUT 1 +#define PCOUNT 2 + +const LADSPA_PortDescriptor p_discs[PCOUNT] = { + LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO, + LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO +}; +const LADSPA_PortRangeHint p_hints[PCOUNT] = { + {.HintDescriptor = 0}, + {.HintDescriptor = 0} +}; +const char *p_names[PCOUNT] = {"Input", "Output"}; + +typedef struct { + LADSPA_Data *input; + LADSPA_Data *output; + + biquad filters[REALBANDS]; + LADSPA_Data fs; + + LADSPA_Data run_adding_gain; +} eq_t; + +static void +activate_eq(LADSPA_Handle instance) { + eq_t *eq = (eq_t *)instance; + biquad *filters = eq->filters; + + for (int i = 0; i < REALBANDS; i++) + biquad_init(&filters[i]); +} + +static void +cleanup_eq(LADSPA_Handle instance) { + free(instance); +} + +static void +connect_port_eq(LADSPA_Handle instance, ulong port, LADSPA_Data *data) { + eq_t *eq = (eq_t *)instance; + if (port == EQ_INPUT) + eq->input = data; + else if (port == EQ_OUTPUT) + eq->output = data; +} + +static LADSPA_Handle +instantiate_eq(const LADSPA_Descriptor *descriptor, ulong s_rate) { + eq_t *eq = (eq_t *) calloc(1, sizeof(eq_t)); + biquad *filters = eq->filters; + LADSPA_Data fs = s_rate; + + eq->fs = fs; + eq->run_adding_gain = 1; + + filters[0] = biquad_gen(4, 10, 0.0, 1.00, fs); + filters[1] = biquad_gen(0, 36, 4.3, 1.25, fs); + filters[2] = biquad_gen(2, 1400, -7.0, 1.20, fs); + filters[3] = biquad_gen(0, 7000, 3.3, 1.25, fs); + + return (LADSPA_Handle) eq; +} + +static void +run_eq_for_real(LADSPA_Handle instance, ulong sample_count, const int running) { + eq_t *eq = (eq_t *) instance; + + biquad *filters = eq->filters; + + const LADSPA_Data *input = eq->input; + LADSPA_Data *output = eq->output; + + for (ulong pos = 0; pos < sample_count; pos++) { + LADSPA_Data samp = input[pos]; + for (int i = 0; i < REALBANDS; i++) + samp = biquad_run(&filters[i], samp); + if (running) + output[pos] += eq->run_adding_gain * samp; + else + output[pos] = samp; + } +} + +static void +run_eq(LADSPA_Handle instance, ulong sample_count) { + run_eq_for_real(instance, sample_count, 0); +} + +static void +run_adding_eq(LADSPA_Handle instance, ulong sample_count) { + run_eq_for_real(instance, sample_count, 1); +} + +void +set_run_adding_gain(LADSPA_Handle instance, LADSPA_Data gain) { + eq_t *eq = (eq_t *) instance; + eq->run_adding_gain = gain; +} + +void _init() {} +void _fini() {} + +static const LADSPA_Descriptor eqDescriptor = { + .UniqueID = 0xDEFACED, + .Label = "crap_eq_const", + .Properties = 0, + .Name = "crap const Equalizer", + .Maker = "Connor Olding", + .Copyright = "MIT", + .PortCount = PCOUNT, + .PortDescriptors = p_discs, + .PortRangeHints = p_hints, + .PortNames = p_names, + + .activate = activate_eq, + .cleanup = cleanup_eq, + .connect_port = connect_port_eq, + .deactivate = NULL, + .instantiate = instantiate_eq, + .run = run_eq, + .run_adding = run_adding_eq, + .set_run_adding_gain = set_run_adding_gain +}; + +const LADSPA_Descriptor * +ladspa_descriptor(ulong index) { + if (index != 0) + return NULL; + return &eqDescriptor; +}