make brace style consistent

This commit is contained in:
Connor Olding 2014-02-05 23:47:16 -08:00
parent 153331f5f7
commit 6d6c64c1b0
11 changed files with 132 additions and 86 deletions

View file

@ -55,10 +55,9 @@ remember to export `VST_SDK_DIR` to the path of your `vstsdk2.4/`
## TODO ## TODO
* rename plugins (fix capitalization consistency and such) * rename plugins (fix capitalization consistency and such)
* make code style consistent
* remove crap\_ prefixes? * remove crap\_ prefixes?
* move to subdirs? * move to subdirs?
* reduce input/output buffers on biquads (shared) * reduce input/output buffers on biquads (shared)
* ease up on the preprocessor ifs * ease up on the preprocessor ifs
* polish parameter support * polish parameter support
* make code style consistent

View file

@ -16,13 +16,15 @@ static float *audio_buffer;
static int audio_count = 0; static int audio_count = 0;
static void static void
cleanup() { cleanup()
{
dlclose(plug); dlclose(plug);
if (audio_count) free(audio_buffer); if (audio_count) free(audio_buffer);
} }
static const LADSPA_Descriptor* static const LADSPA_Descriptor*
load_ladspa(char *path) { load_ladspa(char *path)
{
plug = dlopen(path, RTLD_NOW); plug = dlopen(path, RTLD_NOW);
assert(plug); assert(plug);
atexit(cleanup); atexit(cleanup);
@ -37,7 +39,8 @@ load_ladspa(char *path) {
} }
int int
main(int argc, char **argv) { main(int argc, char **argv)
{
assert(argc > 1); assert(argc > 1);
const LADSPA_Descriptor *d = load_ladspa(argv[1]); const LADSPA_Descriptor *d = load_ladspa(argv[1]);

View file

@ -84,7 +84,8 @@ static void
process(personal *data, process(personal *data,
float *in_L, float *in_R, float *in_L, float *in_R,
float *out_L, float *out_R, float *out_L, float *out_R,
ulong count) { ulong count)
{
for (ulong pos = 0; pos < count; pos++) { for (ulong pos = 0; pos < count; pos++) {
out_L[pos] = process_one(&data->c[0], in_L[pos]); out_L[pos] = process_one(&data->c[0], in_L[pos]);
out_R[pos] = process_one(&data->c[1], in_R[pos]); out_R[pos] = process_one(&data->c[1], in_R[pos]);
@ -95,7 +96,8 @@ static void
process_double(personal *data, process_double(personal *data,
double *in_L, double *in_R, double *in_L, double *in_R,
double *out_L, double *out_R, double *out_L, double *out_R,
ulong count) { ulong count)
{
for (ulong pos = 0; pos < count; pos++) { for (ulong pos = 0; pos < count; pos++) {
out_L[pos] = process_one(&data->c[0], in_L[pos]); out_L[pos] = process_one(&data->c[0], in_L[pos]);
out_R[pos] = process_one(&data->c[1], in_R[pos]); out_R[pos] = process_one(&data->c[1], in_R[pos]);
@ -103,30 +105,32 @@ process_double(personal *data,
} }
static void static void
construct(personal *data) { construct(personal *data)
} {}
static void static void
destruct(personal *data) { destruct(personal *data)
} {}
static void static void
resume(personal *data) { resume(personal *data)
} {}
static void static void
pause(personal *data) { pause(personal *data)
} {}
static void static void
adjust(personal *data, ulong fs) { adjust(personal *data, ulong fs)
{
for (int k = 0; k < 2; k++) { for (int k = 0; k < 2; k++) {
channel *c = &data->c[k]; channel *c = &data->c[k];
for (int i = 0; i < UP; i++) for (int i = 0; i < UP; i++)
c->up[i] = 0; c->up[i] = 0;
for (int i = 0; i < DOWN; i++) for (int i = 0; i < DOWN; i++)
c->down[i] = 0; c->down[i] = 0;
c->filter = biquad_gen(FILT_PEAKING, 16630, 10, 1, fs*oversample); c->filter = biquad_gen(FILT_PEAKING,
16630, 10, 1, fs*oversample);
biquad_init(&c->filter); biquad_init(&c->filter);
} }
} }

View file

@ -30,7 +30,8 @@ static void
process(personal *data, process(personal *data,
float *in_L, float *in_R, float *in_L, float *in_R,
float *out_L, float *out_R, float *out_L, float *out_R,
unsigned long count) { unsigned long count)
{
for (unsigned long pos = 0; pos < count; pos++) { for (unsigned long pos = 0; pos < count; pos++) {
out_L[pos] = process_one(data->filters[0], in_L[pos]); out_L[pos] = process_one(data->filters[0], in_L[pos]);
out_R[pos] = process_one(data->filters[1], in_R[pos]); out_R[pos] = process_one(data->filters[1], in_R[pos]);
@ -41,7 +42,8 @@ static void
process_double(personal *data, process_double(personal *data,
double *in_L, double *in_R, double *in_L, double *in_R,
double *out_L, double *out_R, double *out_L, double *out_R,
unsigned long count) { unsigned long count)
{
for (unsigned long pos = 0; pos < count; pos++) { for (unsigned long pos = 0; pos < count; pos++) {
out_L[pos] = process_one(data->filters[0], in_L[pos]); out_L[pos] = process_one(data->filters[0], in_L[pos]);
out_R[pos] = process_one(data->filters[1], in_R[pos]); out_R[pos] = process_one(data->filters[1], in_R[pos]);
@ -49,7 +51,8 @@ process_double(personal *data,
} }
static void static void
resume(personal *data) { resume(personal *data)
{
biquad *filters = data->filters[0]; biquad *filters = data->filters[0];
for (int i = 0; i < BANDS; i++) for (int i = 0; i < BANDS; i++)
biquad_init(&filters[i]); biquad_init(&filters[i]);
@ -57,11 +60,12 @@ resume(personal *data) {
} }
static void static void
pause(personal *data) { pause(personal *data)
} {}
static void static void
construct_params(param *params) { construct_params(param *params)
{
for (int i = 0; i < BANDS; i++) { for (int i = 0; i < BANDS; i++) {
sprintf(params[0].name, "Band %i Frequency", i + 1); sprintf(params[0].name, "Band %i Frequency", i + 1);
params[0].min = 20; params[0].min = 20;
@ -89,15 +93,16 @@ construct_params(param *params) {
} }
static void static void
construct(personal *data) { construct(personal *data)
} {}
static void static void
destruct(personal *data) { destruct(personal *data)
} {}
static void static void
adjust(personal *data, param *params, unsigned long fs) { adjust(personal *data, param *params, unsigned long fs)
{
data->fs = fs; data->fs = fs;
biquad *filters = data->filters[0]; biquad *filters = data->filters[0];
for (int i = 0; i < BANDS; i++) { for (int i = 0; i < BANDS; i++) {
@ -109,7 +114,8 @@ adjust(personal *data, param *params, unsigned long fs) {
} }
static void static void
adjust_one(personal *data, param *params, unsigned int index) { adjust_one(personal *data, param *params, unsigned int index)
{
float fs = data->fs; float fs = data->fs;
params += index/3*3; params += index/3*3;
data->filters[0][index/3] = biquad_gen(FILT_PEAKING, data->filters[0][index/3] = biquad_gen(FILT_PEAKING,

View file

@ -26,7 +26,8 @@ static void
process(personal *data, process(personal *data,
float *in_L, float *in_R, float *in_L, float *in_R,
float *out_L, float *out_R, float *out_L, float *out_R,
unsigned long count) { unsigned long count)
{
for (unsigned long pos = 0; pos < count; pos++) { for (unsigned long pos = 0; pos < count; pos++) {
out_L[pos] = process_one(data->filters[0], in_L[pos]); out_L[pos] = process_one(data->filters[0], in_L[pos]);
out_R[pos] = process_one(data->filters[1], in_R[pos]); out_R[pos] = process_one(data->filters[1], in_R[pos]);
@ -37,8 +38,8 @@ static void
process_double(personal *data, process_double(personal *data,
double *in_L, double *in_R, double *in_L, double *in_R,
double *out_L, double *out_R, double *out_L, double *out_R,
unsigned long count) { unsigned long count)
// TODO: test which hosts use this {
for (unsigned long pos = 0; pos < count; pos++) { for (unsigned long pos = 0; pos < count; pos++) {
out_L[pos] = process_one(data->filters[0], in_L[pos]); out_L[pos] = process_one(data->filters[0], in_L[pos]);
out_R[pos] = process_one(data->filters[1], in_R[pos]); out_R[pos] = process_one(data->filters[1], in_R[pos]);
@ -46,15 +47,16 @@ process_double(personal *data,
} }
static void static void
construct(personal *data) { construct(personal *data)
} {}
static void static void
destruct(personal *data) { destruct(personal *data)
} {}
static void static void
resume(personal *data) { resume(personal *data)
{
biquad *filters = data->filters[0]; biquad *filters = data->filters[0];
for (int i = 0; i < BANDS; i++) for (int i = 0; i < BANDS; i++)
biquad_init(&filters[i]); biquad_init(&filters[i]);
@ -62,11 +64,12 @@ resume(personal *data) {
} }
static void static void
pause(personal *data) { pause(personal *data)
} {}
static void static void
adjust(personal *data, unsigned long fs) { adjust(personal *data, unsigned long fs)
{
biquad *filters = data->filters[0]; biquad *filters = data->filters[0];
filters[0] = biquad_gen(FILT_PEAKING, 34.34, +4.6, 1.21, fs); filters[0] = biquad_gen(FILT_PEAKING, 34.34, +4.6, 1.21, fs);
filters[1] = biquad_gen(FILT_PEAKING, 85.74, -1.2, 1.31, fs); filters[1] = biquad_gen(FILT_PEAKING, 85.74, -1.2, 1.31, fs);

View file

@ -14,7 +14,8 @@ static void
process(personal *data, process(personal *data,
float *in_L, float *in_R, float *in_L, float *in_R,
float *out_L, float *out_R, float *out_L, float *out_R,
unsigned long count) { unsigned long count)
{
// TODO: separate and preserve mirand for each channel // TODO: separate and preserve mirand for each channel
for (unsigned long pos = 0; pos < count; pos++) for (unsigned long pos = 0; pos < count; pos++)
out_L[pos] = whitenoise(); out_L[pos] = whitenoise();
@ -26,7 +27,8 @@ static void
process_double(personal *data, process_double(personal *data,
double *in_L, double *in_R, double *in_L, double *in_R,
double *out_L, double *out_R, double *out_L, double *out_R,
unsigned long count) { unsigned long count)
{
for (unsigned long pos = 0; pos < count; pos++) for (unsigned long pos = 0; pos < count; pos++)
out_L[pos] = whitenoise(); out_L[pos] = whitenoise();
for (unsigned long pos = 0; pos < count; pos++) for (unsigned long pos = 0; pos < count; pos++)
@ -34,22 +36,21 @@ process_double(personal *data,
} }
static void static void
construct(personal *data) { construct(personal *data)
} {}
static void static void
destruct(personal *data) { destruct(personal *data)
} {}
static void static void
resume(personal *data) { resume(personal *data)
} {}
static void static void
pause(personal *data) { pause(personal *data)
} {}
static void static void
adjust(personal *data, unsigned long fs) { adjust(personal *data, unsigned long fs)
} {}

View file

@ -97,7 +97,8 @@ static void
process(personal *data, process(personal *data,
float *in_L, float *in_R, float *in_L, float *in_R,
float *out_L, float *out_R, float *out_L, float *out_R,
unsigned long count) { unsigned long count)
{
disable_denormals(); disable_denormals();
for (unsigned long pos = 0; pos < count; pos++) { for (unsigned long pos = 0; pos < count; pos++) {
out_L[pos] = process_one(data->history_L, in_L[pos]); out_L[pos] = process_one(data->history_L, in_L[pos]);
@ -109,7 +110,8 @@ static void
process_double(personal *data, process_double(personal *data,
double *in_L, double *in_R, double *in_L, double *in_R,
double *out_L, double *out_R, double *out_L, double *out_R,
unsigned long count) { unsigned long count)
{
disable_denormals(); disable_denormals();
for (unsigned long pos = 0; pos < count; pos++) { for (unsigned long pos = 0; pos < count; pos++) {
out_L[pos] = process_one(data->history_L, in_L[pos]); out_L[pos] = process_one(data->history_L, in_L[pos]);
@ -118,24 +120,27 @@ process_double(personal *data,
} }
static void static void
resume(personal *data) { resume(personal *data)
{
memset(data->history_L, 0, HIST_SIZE*sizeof(double)); memset(data->history_L, 0, HIST_SIZE*sizeof(double));
memset(data->history_R, 0, HIST_SIZE*sizeof(double)); memset(data->history_R, 0, HIST_SIZE*sizeof(double));
} }
static void static void
pause(personal *data) { pause(personal *data)
} {}
static void static void
construct(personal *data) { construct(personal *data)
{
resume(data); resume(data);
} }
static void static void
destruct(personal *data) { destruct(personal *data)
} {}
static void static void
adjust(personal *data, unsigned long fs) { adjust(personal *data, unsigned long fs)
{
resume(data); resume(data);
} }

View file

@ -6,7 +6,8 @@
static unsigned int mirand = 1; static unsigned int mirand = 1;
static float static float
whitenoise() { whitenoise()
{
union either { union either {
float f; float f;
unsigned int i; unsigned int i;
@ -19,14 +20,16 @@ whitenoise() {
/* used to resemble https://github.com/swh/ladspa/blob/master/util/biquad.h */ /* used to resemble https://github.com/swh/ladspa/blob/master/util/biquad.h */
static void static void
biquad_init(biquad *bq) { biquad_init(biquad *bq)
{
bq->x1 = bq->x2 = bq->y1 = bq->y2 = 0; bq->x1 = bq->x2 = bq->y1 = bq->y2 = 0;
} }
static biquad_interim static biquad_interim
design(double cw, double sw, design(double cw, double sw,
double num0, double num1, double num2, double num0, double num1, double num2,
double den0, double den1, double den2) { double den0, double den1, double den2)
{
return (biquad_interim) { return (biquad_interim) {
.b0 = num0* (1 + cw) + num1*sw + num2* (1 - cw), .b0 = num0* (1 + cw) + num1*sw + num2* (1 - cw),
.b1 = num0*-2*(1 + cw) + num2*2*(1 - cw), .b1 = num0*-2*(1 + cw) + num2*2*(1 - cw),
@ -38,7 +41,8 @@ design(double cw, double sw,
} }
static biquad static biquad
biquad_gen(filter_t type, double fc, double gain, double bw, double fs) { biquad_gen(filter_t type, double fc, double gain, double bw, double fs)
{
double w0, cw, sw, A, As, Q; double w0, cw, sw, A, As, Q;
w0 = ANGULAR_LIM(fc, fs); w0 = ANGULAR_LIM(fc, fs);
cw = cos(w0); cw = cos(w0);
@ -77,7 +81,8 @@ biquad_gen(filter_t type, double fc, double gain, double bw, double fs) {
} }
static double static double
biquad_run(biquad *bq, double x) { biquad_run(biquad *bq, double x)
{
double y; double y;
y = bq->b0*x + bq->b1*bq->x1 + bq->b2*bq->x2 y = bq->b0*x + bq->b1*bq->x1 + bq->b2*bq->x2

View file

@ -6,13 +6,15 @@
#include "crap_util.h" #include "crap_util.h"
void void
usage() { usage()
{
fputs("usage: design SAMPLERATE TYPE CENTERFREQ GAIN BANDWIDTH\n", stderr); fputs("usage: design SAMPLERATE TYPE CENTERFREQ GAIN BANDWIDTH\n", stderr);
exit(1); exit(1);
} }
int int
main(int argc, char **argv) { main(int argc, char **argv)
{
if (argc != 6) usage(); if (argc != 6) usage();
double tv[5]; double tv[5];
for (int i = 1; i <= 5; i++) { for (int i = 1; i <= 5; i++) {

View file

@ -41,7 +41,8 @@ typedef struct {
} plug_t; } plug_t;
static void static void
plug_connect(LADSPA_Handle instance, unsigned long port, LADSPA_Data *data) { plug_connect(LADSPA_Handle instance, unsigned long port, LADSPA_Data *data)
{
plug_t *plug = (plug_t *)instance; plug_t *plug = (plug_t *)instance;
if (port == PLUG_INPUT_L) if (port == PLUG_INPUT_L)
plug->input_L = data; plug->input_L = data;
@ -58,19 +59,22 @@ plug_connect(LADSPA_Handle instance, unsigned long port, LADSPA_Data *data) {
} }
static void 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); resume(&plug->data);
} }
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); pause(&plug->data);
} }
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); construct(&plug->data);
#if (PARAMETERS > 0) #if (PARAMETERS > 0)
@ -83,14 +87,16 @@ plug_construct(const LADSPA_Descriptor *descriptor, unsigned long fs) {
} }
static void 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); destruct(&plug->data);
free(plug); free(plug);
} }
static void static void
plug_process(LADSPA_Handle instance, unsigned long count) { plug_process(LADSPA_Handle instance, unsigned long count)
{
plug_t *plug = (plug_t *)instance; plug_t *plug = (plug_t *)instance;
#if (PARAMETERS > 0) #if (PARAMETERS > 0)
for (int i = 0; i < PARAMETERS; i++) { for (int i = 0; i < PARAMETERS; i++) {
@ -129,14 +135,16 @@ static const LADSPA_Descriptor plug_desc = {
}; };
const LADSPA_Descriptor * const LADSPA_Descriptor *
ladspa_descriptor(unsigned long index) { ladspa_descriptor(unsigned long index)
{
if (index != 0) if (index != 0)
return NULL; return NULL;
return &plug_desc; return &plug_desc;
} }
static void static void
plug_init() { plug_init()
{
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
p_names[i] = p_default_strings[i]; p_names[i] = p_default_strings[i];
p_descs[i] = LADSPA_PORT_AUDIO; p_descs[i] = LADSPA_PORT_AUDIO;

View file

@ -48,7 +48,8 @@ private:
}; };
AudioEffect * AudioEffect *
createEffectInstance(audioMasterCallback audioMaster) { createEffectInstance(audioMasterCallback audioMaster)
{
return new plugin(audioMaster); return new plugin(audioMaster);
} }
@ -73,19 +74,23 @@ plugin::~plugin()
} }
void void
plugin::resume() { plugin::resume()
{
::resume(&data); ::resume(&data);
AudioEffectX::resume(); AudioEffectX::resume();
} }
void void
plugin::suspend() { plugin::suspend()
{
AudioEffectX::suspend(); AudioEffectX::suspend();
::pause(&data); ::pause(&data);
} }
void void
plugin::processReplacing(float **inputs, float **outputs, VstInt32 count) { plugin::processReplacing(
float **inputs, float **outputs, VstInt32 count)
{
::process(&data, ::process(&data,
inputs[0], inputs[1], inputs[0], inputs[1],
outputs[0], outputs[1], outputs[0], outputs[1],
@ -93,7 +98,9 @@ plugin::processReplacing(float **inputs, float **outputs, VstInt32 count) {
} }
void void
plugin::processDoubleReplacing(double **inputs, double **outputs, VstInt32 count) { plugin::processDoubleReplacing(
double **inputs, double **outputs, VstInt32 count)
{
::process_double(&data, ::process_double(&data,
inputs[0], inputs[1], inputs[0], inputs[1],
outputs[0], outputs[1], outputs[0], outputs[1],
@ -101,12 +108,14 @@ plugin::processDoubleReplacing(double **inputs, double **outputs, VstInt32 count
} }
bool bool
plugin::setProcessPrecision(VstInt32 precision) { plugin::setProcessPrecision(VstInt32 precision)
{
return true; return true;
} }
void void
plugin::setSampleRate(float fs) { plugin::setSampleRate(float fs)
{
AudioEffectX::setSampleRate(fs); AudioEffectX::setSampleRate(fs);
#if (PARAMETERS > 0) #if (PARAMETERS > 0)
::adjust(&data, params, (unsigned long) fs); ::adjust(&data, params, (unsigned long) fs);
@ -119,7 +128,8 @@ plugin::setSampleRate(float fs) {
} }
bool bool
plugin::getEffectName(char *name) { plugin::getEffectName(char *name)
{
vst_strncpy(name, LABEL, kVstMaxEffectNameLen); vst_strncpy(name, LABEL, kVstMaxEffectNameLen);
return true; return true;
} }