From f652720d0dc24a1951e66e28486e856b424d68df Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 9 Aug 2008 04:33:55 +0000 Subject: Fix bugs. Tighten up code. Crank up warnings to absurdly strict and pedantic level in order to figure out WTF is going on with audio. git-svn-id: http://svn.drobilla.net/lad/mda-lv2@1328 a436a847-0d15-0410-975c-d299462d15a1 --- Makefile | 2 +- lvz/audioeffectx.h | 43 ++++++++++++++++++++-------------------- lvz/gendata.cpp | 14 ++++++------- lvz/wrapper.cpp | 57 +++++++++++++++++++++++++++++++++-------------------- src/mdaDX10.cpp | 6 +++--- src/mdaJX10.cpp | 6 +++--- src/mdaTestTone.cpp | 4 ++-- 7 files changed, 73 insertions(+), 59 deletions(-) diff --git a/Makefile b/Makefile index 5575b0a..d09bd3d 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -CFLAGS = -O0 -g -Wall -fPIC -Ilvz -I. -DPLUGIN_URI_PREFIX=\"http://drobilla.net/ns/dev/mda-lv2/\" +CFLAGS = -O0 -g -Wall -Wextra -Wshadow -Wno-unused -ansi -pedantic -fPIC -DPIC -Ilvz -I. -DPLUGIN_URI_PREFIX=\"http://drobilla.net/ns/dev/mda-lv2/\" # Change this to wherever you want system-wide bundles installed LV2_INSTALL_DIR = /usr/local/lib/lv2 diff --git a/lvz/audioeffectx.h b/lvz/audioeffectx.h index 025c0cc..ecacfcd 100644 --- a/lvz/audioeffectx.h +++ b/lvz/audioeffectx.h @@ -37,7 +37,6 @@ struct LvzPinProperties { LvzPinProperties() : label(NULL), flags(0) {} char* label; int flags; - }; enum LvzEventTypes { @@ -61,11 +60,13 @@ struct LvzEvents { #define DECLARE_LVZ_DEPRECATED(x) x class AudioEffect { +public: + virtual ~AudioEffect() {} }; class AudioEffectX : public AudioEffect { public: - AudioEffectX(audioMasterCallback audioMaster, int progs, int params) + AudioEffectX(audioMasterCallback audioMaster, LvzInt32 progs, LvzInt32 params) : uniqueID("NIL") , URI("NIL") , curProgram(0) @@ -76,27 +77,27 @@ public: , sampleRate(44100) { } - - virtual const char* getURI() { return URI; } - virtual const char* getUniqueID() { return uniqueID; } - virtual float getSampleRate() { return sampleRate; } - virtual uint32_t getNumInputs() { return numInputs; } - virtual uint32_t getNumOutputs() { return numOutputs; } - virtual uint32_t getNumParameters() { return numParams; } + + virtual const char* getURI() const { return URI; } + virtual const char* getUniqueID() const { return uniqueID; } + virtual float getSampleRate() const { return sampleRate; } + virtual LvzInt32 getNumInputs() const { return numInputs; } + virtual LvzInt32 getNumOutputs() const { return numOutputs; } + virtual LvzInt32 getNumParameters() const { return numParams; } virtual float getParameter(LvzInt32 index) = 0; virtual void getParameterName(LvzInt32 index, char *label) = 0; virtual bool getProductString(char* text) = 0; - virtual void suspend() {}; + virtual void suspend() {} virtual void canMono() {} virtual void canProcessReplacing() {} virtual void isSynth() {} - virtual void process(float **inputs, float **outputs, uint32_t nframes) {} - virtual void setBlockSize(uint32_t blockSize) {} - virtual void setNumInputs(uint32_t num) { numInputs = num; } - virtual void setNumOutputs(uint32_t num) { numOutputs = num;} - virtual void setParameter(uint32_t index, float value) {} + virtual void process(float **inputs, float **outputs, LvzInt32 nframes) = 0; + virtual void setBlockSize(LvzInt32 blockSize) {} + virtual void setNumInputs(LvzInt32 num) { numInputs = num; } + virtual void setNumOutputs(LvzInt32 num) { numOutputs = num; } + virtual void setParameter(LvzInt32 index, float value) = 0; virtual void setSampleRate(float rate) { sampleRate = rate; } virtual void setUniqueID(const char* id) { uniqueID = id; } virtual void setURI(const char* uri) { URI = uri; } @@ -105,12 +106,12 @@ public: protected: const char* uniqueID; const char* URI; - uint32_t curProgram; - uint32_t numPrograms; - uint32_t numParams; - uint32_t numInputs; - uint32_t numOutputs; - float sampleRate; + LvzInt32 curProgram; + LvzInt32 numPrograms; + LvzInt32 numParams; + LvzInt32 numInputs; + LvzInt32 numOutputs; + float sampleRate; AEffGUIEditor* editor; }; diff --git a/lvz/gendata.cpp b/lvz/gendata.cpp index 7efd739..7f1d501 100644 --- a/lvz/gendata.cpp +++ b/lvz/gendata.cpp @@ -30,7 +30,7 @@ using namespace std; // VST is so incredibly awful. Just.. wow. #define MAX_NAME_LENGTH 1024 -char name[MAX_NAME_LENGTH]; +char name_buf[MAX_NAME_LENGTH]; struct Record { @@ -89,13 +89,13 @@ write_plugin(AudioEffectX* effect, const string& lib_file_name) string data_file_name = base_name + ".ttl"; fstream os(data_file_name.c_str(), ios::out); - effect->getProductString(name); + effect->getProductString(name_buf); os << "@prefix : ." << endl; os << "@prefix doap: ." << endl << endl; os << "<" << effect->getURI() << ">" << endl; os << "\t:symbol \"" << effect->getUniqueID() << "\" ;" << endl; - os << "\tdoap:name \"" << name << "\" ;" << endl; + os << "\tdoap:name \"" << name_buf << "\" ;" << endl; os << "\tdoap:license ;" << endl; os << "\t:pluginProperty :hardRtCapable"; @@ -112,11 +112,11 @@ write_plugin(AudioEffectX* effect, const string& lib_file_name) uint32_t idx = 0; for (uint32_t i = idx; i < num_params; ++i, ++idx) { - effect->getParameterName(i, name); + effect->getParameterName(i, name_buf); os << "\t\ta :InputPort, :ControlPort ;" << endl; os << "\t\t:index" << " " << idx << " ;" << endl; - os << "\t\t:name \"" << name << "\" ;" << endl; - os << "\t\t:symbol \"" << symbolify(name) << "\" ;" << endl; + os << "\t\t:name \"" << name_buf << "\" ;" << endl; + os << "\t\t:symbol \"" << symbolify(name_buf) << "\" ;" << endl; os << "\t\t:default " << effect->getParameter(i) << " ;" << endl; os << "\t\t:minimum 0.0 ;" << endl; os << "\t\t:maximum 1.0 ;" << endl; @@ -124,7 +124,6 @@ write_plugin(AudioEffectX* effect, const string& lib_file_name) } for (uint32_t i = 0; i < num_audio_ins; ++i, ++idx) { - snprintf(name, MAX_NAME_LENGTH, "\"in%d\"", i); os << "\t\ta :InputPort, :AudioPort ;" << endl; os << "\t\t:index" << " " << idx << " ;" << endl; os << "\t\t:symbol \"in" << i+1 << "\" ;" << endl; @@ -133,7 +132,6 @@ write_plugin(AudioEffectX* effect, const string& lib_file_name) } for (uint32_t i = 0; i < num_audio_outs; ++i, ++idx) { - snprintf(name, MAX_NAME_LENGTH, "\"out%d\"", i); os << "\t\ta :OutputPort, :AudioPort ;" << endl; os << "\t\t:index " << idx << " ;" << endl; os << "\t\t:symbol \"out" << i+1 << "\" ;" << endl; diff --git a/lvz/wrapper.cpp b/lvz/wrapper.cpp index 0877053..a7fbc7c 100644 --- a/lvz/wrapper.cpp +++ b/lvz/wrapper.cpp @@ -37,24 +37,37 @@ extern "C" { typedef struct { PLUGIN_CLASS* effect; - float** buffers; float* controls; + float** control_buffers; + float** inputs; + float** outputs; } MDAPlugin; -static void mda_cleanup(LV2_Handle instance) +static void +mda_cleanup(LV2_Handle instance) { free(instance); } -static void mda_connect_port(LV2_Handle instance, uint32_t port, void* data) +static void +mda_connect_port(LV2_Handle instance, uint32_t port, void* data) { MDAPlugin* plugin = (MDAPlugin*)instance; - plugin->buffers[port] = (float*)data; + + uint32_t num_params = plugin->effect->getNumParameters(); + uint32_t num_inputs = plugin->effect->getNumInputs(); - if (data != NULL && port < plugin->effect->getNumParameters()) - plugin->controls[port] = *(float*)data; + if (port < num_params) { + plugin->control_buffers[port] = (float*)data; + if (data != NULL) + plugin->controls[port] = *(float*)data; + } else if (port < num_params + num_inputs) { + plugin->inputs[port - num_params] = (float*)data; + } else { + plugin->outputs[port - num_params - num_inputs] = (float*)data; + } } @@ -71,14 +84,21 @@ mda_instantiate(const LV2_Descriptor* descriptor, MDAPlugin* plugin = (MDAPlugin*)malloc(sizeof(MDAPlugin)); plugin->effect = effect; - uint32_t num_ports = effect->getNumParameters() - + effect->getNumInputs() - + effect->getNumOutputs(); - - plugin->buffers = (float**)malloc(sizeof(float*) * num_ports); plugin->controls = (float*)malloc(sizeof(float) * effect->getNumParameters()); - memset(plugin->controls, '\0', sizeof(float) * effect->getNumParameters()); + plugin->control_buffers = (float**)malloc(sizeof(float*) * effect->getNumParameters()); + for (int32_t i = 0; i < effect->getNumParameters(); ++i) { + plugin->controls[i] = effect->getParameter(i); + plugin->control_buffers[i] = NULL; + } + plugin->inputs = (float**)malloc(sizeof(float*) * effect->getNumInputs()); + for (int32_t i = 0; i < effect->getNumInputs(); ++i) + plugin->inputs[i] = NULL; + + plugin->outputs = (float**)malloc(sizeof(float*) * effect->getNumOutputs()); + for (int32_t i = 0; i < effect->getNumOutputs(); ++i) + plugin->outputs[i] = NULL; + return (LV2_Handle)plugin; } @@ -88,20 +108,15 @@ mda_run(LV2_Handle instance, uint32_t sample_count) { MDAPlugin* plugin = (MDAPlugin*)instance; - uint32_t num_params = plugin->effect->getNumParameters(); - uint32_t num_inputs = plugin->effect->getNumInputs(); - - for (uint32_t i = 0; i < num_params; ++i) { - float val = plugin->buffers[i][0]; + for (int32_t i = 0; i < plugin->effect->getNumParameters(); ++i) { + float val = plugin->control_buffers[i][0]; if (val != plugin->controls[i]) { plugin->effect->setParameter(i, val); plugin->controls[i] = val; } } - - plugin->effect->process(plugin->buffers + num_params, - plugin->buffers + num_params + num_inputs, - sample_count); + + plugin->effect->process(plugin->inputs, plugin->outputs, sample_count); } diff --git a/src/mdaDX10.cpp b/src/mdaDX10.cpp index 7623e9b..df88605 100644 --- a/src/mdaDX10.cpp +++ b/src/mdaDX10.cpp @@ -131,10 +131,10 @@ void mdaDX10::update() //parameter change //if multitimbral would have to move } -void mdaDX10::setSampleRate(float sampleRate) +void mdaDX10::setSampleRate(float rate) { - AudioEffectX::setSampleRate(sampleRate); - Fs = sampleRate; + AudioEffectX::setSampleRate(rate); + Fs = rate; } diff --git a/src/mdaJX10.cpp b/src/mdaJX10.cpp index 74f0340..4ded18e 100644 --- a/src/mdaJX10.cpp +++ b/src/mdaJX10.cpp @@ -204,10 +204,10 @@ void mdaJX10::update() //parameter change } -void mdaJX10::setSampleRate(float sampleRate) +void mdaJX10::setSampleRate(float rate) { - AudioEffectX::setSampleRate(sampleRate); - Fs = sampleRate; + AudioEffectX::setSampleRate(rate); + Fs = rate; dlfo = lfoHz * (float)(TWOPI * KMAX) / Fs; } diff --git a/src/mdaTestTone.cpp b/src/mdaTestTone.cpp index 3748109..f74139e 100644 --- a/src/mdaTestTone.cpp +++ b/src/mdaTestTone.cpp @@ -75,11 +75,11 @@ void mdaTestTone::setParameter(LvzInt32 index, float value) //just update display text... - int mode = int(8.9 * fParam0); + int this_mode = int(8.9 * fParam0); float f, df=0.0f; if(fParam4>0.6) df = 1.25f*fParam4 - 0.75f; if(fParam4<0.4) df = 1.25f*fParam4 - 0.50f; - switch(mode) + switch(this_mode) { case 0: //MIDI note f = (float)floor(128.f*fParam3); -- cgit v1.2.1