From df37350fb4f57da37c621c04c0b385bc5fe7539e Mon Sep 17 00:00:00 2001 From: Gordon JC Pearce Date: Tue, 3 Sep 2024 15:22:56 +0100 Subject: [PATCH] saw, envelope, decoupled voice code but doesn't compile --- plugin/Makefile | 10 ++++++---- plugin/chassis.cpp | 14 +++++++------- plugin/chassis.hpp | 6 +++--- plugin/voice.cpp | 32 ++++++++++++++++++++++++++++++++ plugin/voice.hpp | 29 ++++------------------------- 5 files changed, 52 insertions(+), 39 deletions(-) diff --git a/plugin/Makefile b/plugin/Makefile index c676d85..742693b 100644 --- a/plugin/Makefile +++ b/plugin/Makefile @@ -1,7 +1,7 @@ ############################### # -# Makefile for BarrVerb -# based on the work of falkTX +# Makefile for BarrChassis +# based on the work of falkTX, in the DPF example plugins # # for full licence, see LICENCE in the root of the project # @@ -9,10 +9,12 @@ NAME = chassis -FILES_DSP = chassis.cpp +FILES_DSP = \ + chassis.cpp + include ../dpf/Makefile.plugins.mk -TARGETS += vst2 vst3 jack lv2_dsp +TARGETS += jack all: $(TARGETS) diff --git a/plugin/chassis.cpp b/plugin/chassis.cpp index 23b1a63..437b352 100644 --- a/plugin/chassis.cpp +++ b/plugin/chassis.cpp @@ -25,16 +25,17 @@ Chassis::Chassis() : Plugin(kParameterCount, 0, 0) { // one parameter, no progr // Initialisation functions -void Chassis::initParameter(uint32_t index, Parameter ¶meter) { -} +//void Chassis::initParameter(uint32_t index, Parameter ¶meter) { +//} +/* void Chassis::setParameterValue(uint32_t index, float value) { } float Chassis::getParameterValue(uint32_t index) const { return 0; } - +*/ void Chassis::initAudioPort(bool input, uint32_t index, AudioPort &port) { port.groupId = kPortGroupStereo; Plugin::initAudioPort(input, index, port); @@ -72,22 +73,21 @@ void Chassis::noteOn(uint8_t note) { if (vPtr == NUM_VOICES) vPtr = 0; if (voice[vPtr].isFree()) { // if it's an existing note don't reset - voice[vPtr].voiceOn(note, voice[i].note != note); + voice[vPtr].on(note, voice[i].note != note); break; } } if (i == NUM_VOICES) { // didn't find a free voice vPtr++; if (vPtr == NUM_VOICES) vPtr = 0; - voice[vPtr].voiceOn(note, true); + voice[vPtr].on(note, true); } } void Chassis::noteOff(uint8_t note) { - uint32_t v; for (uint32_t i = 0; i < NUM_VOICES; i++) { if (voice[i].note == note && !voice[i].isFree()) { - voice[i].voiceOff(); + voice[i].off(); break; } } diff --git a/plugin/chassis.hpp b/plugin/chassis.hpp index 982437c..68ff29b 100644 --- a/plugin/chassis.hpp +++ b/plugin/chassis.hpp @@ -46,10 +46,10 @@ class Chassis : public Plugin { // Initialisation void initAudioPort(bool input, uint32_t index, AudioPort &port) override; - void initParameter(uint32_t index, Parameter ¶meter) override; + //void initParameter(uint32_t index, Parameter ¶meter) override; - void setParameterValue(uint32_t index, float value) override; - float getParameterValue(uint32_t index) const override; + //void setParameterValue(uint32_t index, float value) override; + //float getParameterValue(uint32_t index) const override; // void initProgramName(uint32_t index, String &programName) override; // void loadProgram(uint32_t index) override; diff --git a/plugin/voice.cpp b/plugin/voice.cpp index b574b87..046c6c3 100644 --- a/plugin/voice.cpp +++ b/plugin/voice.cpp @@ -15,3 +15,35 @@ OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ + +#include + +#include "voice.hpp" + +inline bool Voice::isFree() { + return keyState == K_OFF; +} + +void Voice::on(uint32_t key, bool reset = 0) { + keyState = K_ON; + envState = ATTACK; + note = key; + if (reset) env = 0; + omega = (261.63 * powf(2, (note - 60) / 12.0f)) / 48000.0f; + target = 1; +} + +void Voice::off() { + keyState = K_OFF; + envState = RELEASE; + target = 0; +} + +void Voice::run(float *buffer, uint32_t samples) { + env = ((target - env) * 0.01) + env; + for (uint32_t i = 0; i < samples; i++) { + phase += omega; + if (phase > 1) phase -= 1; + buffer[i] += (0.5 - phase) * env; + } +} diff --git a/plugin/voice.hpp b/plugin/voice.hpp index 664be31..69e9532 100644 --- a/plugin/voice.hpp +++ b/plugin/voice.hpp @@ -25,34 +25,13 @@ class Voice { public: uint8_t note; - void voiceOn(uint32_t key, bool reset = 0) { - keyState = K_ON; - envState = ATTACK; - note = key; - if (reset) env = 0; - omega = (261.63 * powf(2, (note - 60)/12.0f))/48000.0f; - target = 1; - } + void on(uint32_t key, bool reset); - void voiceOff() { - keyState = K_OFF; - envState = RELEASE; - target = 0; - } + void off(); - inline bool isFree() { - return keyState == K_OFF; - } + inline bool isFree(); - void run(float *buffer, uint32_t samples) { - - env = ((target - env)*0.01) + env; - for (uint32_t i = 0; i < samples; i++) { - phase += omega; - if (phase > 1) phase -= 1; - buffer[i] += (0.5-phase) * env; - } - } + void run(float *buffer, uint32_t samples); private: enum { ATTACK,