diff --git a/crap_eq.c b/crap_eq.c index e63a349..f8eb9d7 100644 --- a/crap_eq.c +++ b/crap_eq.c @@ -29,25 +29,17 @@ typedef unsigned long ulong; #define BW_MAX 8 void __attribute__ ((constructor)) eq_init(); -void __attribute__ ((destructor)) eq_fini(); +static const char *gain_desc = "Band %i Gain [dB]"; +static const char *freq_desc = "Band %i Freq [Hz]"; +static const char *band_desc = "Band %i Bandwidth [octaves]"; + +#define NAME_SIZE 32 LADSPA_PortDescriptor p_discs[PCOUNT]; LADSPA_PortRangeHint p_hints[PCOUNT]; +char name_buffer[PCOUNT*NAME_SIZE]; char *p_names[PCOUNT]; -static LADSPA_Descriptor eqDescriptor = { - .UniqueID = 0xCAFED, - .Label = "crap_eq", - .Properties = 0, - .Name = "crap Parametric Equalizer", - .Maker = "Connor Olding", - .Copyright = "MIT", - .PortCount = PCOUNT, - .PortDescriptors = p_discs, - .PortRangeHints = p_hints, - .PortNames = p_names -}; - typedef struct { LADSPA_Data *chg[BANDS]; LADSPA_Data *chf[BANDS]; @@ -62,13 +54,6 @@ typedef struct { LADSPA_Data fs; } eq_t; -const LADSPA_Descriptor * -ladspa_descriptor(ulong index) { - if (index != 0) - return NULL; - return &eqDescriptor; -} - static void activate_eq(LADSPA_Handle instance) { eq_t *eq = (eq_t *)instance; @@ -159,14 +144,41 @@ run_eq(LADSPA_Handle instance, ulong sample_count) { } } -static const char *gain_desc = "Band %i Gain [dB]"; -static const char *freq_desc = "Band %i Freq [Hz]"; -static const char *band_desc = "Band %i Bandwidth [octaves]"; +static LADSPA_Descriptor eqDescriptor = { + .UniqueID = 0xCAFED, + .Label = "crap_eq", + .Properties = 0, + .Name = "crap Parametric 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 = NULL, + .set_run_adding_gain = NULL +}; + +const LADSPA_Descriptor * +ladspa_descriptor(ulong index) { + if (index != 0) + return NULL; + return &eqDescriptor; +} void eq_init() { #define INCTRL (LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL) #define BOUNDED (LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE) + for (int i = 0; i < PCOUNT; i++) + p_names[i] = &name_buffer[i*NAME_SIZE]; for (int i = 0; i < BANDS; i++) { const int gi = i; const int fi = i + BANDS; @@ -176,9 +188,6 @@ eq_init() { p_discs[fi] = INCTRL; p_discs[bi] = INCTRL; - p_names[gi] = calloc(strlen(gain_desc), sizeof(char)); - p_names[fi] = calloc(strlen(freq_desc), sizeof(char)); - p_names[bi] = calloc(strlen(band_desc), sizeof(char)); sprintf(p_names[gi], gain_desc, i); sprintf(p_names[fi], freq_desc, i); sprintf(p_names[bi], band_desc, i); @@ -200,32 +209,10 @@ eq_init() { } p_discs[EQ_INPUT] = LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO; - p_names[EQ_INPUT] = "Input"; + strcpy(p_names[EQ_INPUT], "Input"); p_hints[EQ_INPUT].HintDescriptor = 0; p_discs[EQ_OUTPUT] = LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO; - p_names[EQ_OUTPUT] = "Output"; + strcpy(p_names[EQ_OUTPUT], "Output"); p_hints[EQ_OUTPUT].HintDescriptor = 0; - - eqDescriptor.activate = activate_eq; - eqDescriptor.cleanup = cleanup_eq; - eqDescriptor.connect_port = connect_port_eq; - eqDescriptor.deactivate = NULL; - eqDescriptor.instantiate = instantiate_eq; - eqDescriptor.run = run_eq; - eqDescriptor.run_adding = NULL; - eqDescriptor.set_run_adding_gain = NULL; -} - -void -eq_fini() { - for (int i = 0; i < BANDS; i++) { - const int gi = i; - const int fi = i + BANDS; - const int bi = i + BANDS*2; - - free(p_names[gi]); - free(p_names[fi]); - free(p_names[bi]); - } }