From 23d99e92f295955bd0ea80c0a3aac72f1c55bddd Mon Sep 17 00:00:00 2001 From: Gordon JC Pearce Date: Sun, 21 Dec 2025 21:00:53 +0000 Subject: [PATCH] globals for samplerate and buffersize --- plugin/chorus.cpp | 12 +++++------- plugin/chorus.hpp | 15 +++++++++------ plugin/module.cpp | 2 +- plugin/module.hpp | 13 +++++++------ plugin/peacock.cpp | 17 +++++++++++------ plugin/peacock.hpp | 8 ++++---- plugin/svf.hpp | 4 ++-- 7 files changed, 39 insertions(+), 32 deletions(-) diff --git a/plugin/chorus.cpp b/plugin/chorus.cpp index 682843d..f1455dc 100644 --- a/plugin/chorus.cpp +++ b/plugin/chorus.cpp @@ -23,12 +23,7 @@ #include -//extern double sampleRate; -//extern uint32_t bufferSize; - -double sampleRate = 48000; -uint32_t bufferSize = 1024; -Chorus::Chorus() { // no parameters, programs, or states +Chorus::Chorus() { lpfOut1 = new float[bufferSize]; lpfOut2 = new float[bufferSize]; @@ -53,6 +48,7 @@ Chorus::Chorus() { // no parameters, programs, or states } Chorus::~Chorus() { + printf("called chorus destructor\n"); delete lpfOut1; delete lpfOut2; delete ram; @@ -62,7 +58,7 @@ Chorus::~Chorus() { delete postFilter2r; } -void Chorus::run(const float *input, float **outputs, uint32_t frames) { +void Chorus::run(const float* input, float** outputs, uint32_t frames) { // actual effects here // now run the DSP @@ -70,6 +66,8 @@ void Chorus::run(const float *input, float **outputs, uint32_t frames) { float lfoMod, dly1, frac; uint16_t tap, delay; + fastOmega = sampleRate*4; + for (uint32_t i = 0; i < frames; i++) { // run a step of LFO fastPhase += fastOmega; diff --git a/plugin/chorus.hpp b/plugin/chorus.hpp index 657de58..e936201 100644 --- a/plugin/chorus.hpp +++ b/plugin/chorus.hpp @@ -16,11 +16,14 @@ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef Chorus_HPP -#define Chorus_HPP +#ifndef __CHORUS_HPP +#define __CHORUS_HPP #include "svf.hpp" +extern uint32_t bufferSize; +extern double sampleRate; + // total size of delay line buffer #define DELAYSIZE 1028 @@ -30,8 +33,8 @@ class Chorus { public: Chorus(); ~Chorus(); - void run(const float *input, float **outputs, uint32_t frames); - + void run(const float* input, float** outputs, uint32_t frames); + private: double fastPhase, fastOmega; double slowPhase, slowOmega; @@ -39,8 +42,8 @@ class Chorus { uint16_t delayptr; - float *ram; - float *lpfIn; + float* ram; + float* lpfIn; float *lpfOut1, *lpfOut2; SVF *postFilter1l, *postFilter2l, *postFilter1r, *postFilter2r; diff --git a/plugin/module.cpp b/plugin/module.cpp index d4d4cf1..3a548f0 100644 --- a/plugin/module.cpp +++ b/plugin/module.cpp @@ -84,7 +84,7 @@ void Module::run(Voice* voice) { px *= (patchRam.switch1 & 0x07); - v->omega = px / 192000.0f; // fixme use proper scaler + v->omega = px / (sampleRate * 4.0f); // fixme use proper scaler // per voice we need to calculate the key follow amount and envelope amount v->vcfCut = (patchRam.vcfFreq << 7) + ((vcf * v->env) >> 16); diff --git a/plugin/module.hpp b/plugin/module.hpp index 2a907c6..9b34419 100644 --- a/plugin/module.hpp +++ b/plugin/module.hpp @@ -23,17 +23,18 @@ #include "DistrhoPluginInfo.h" +extern double sampleRate; + class Voice; class Module { - public: Module(); void run(Voice* voice); - // Voice voices[NUM_VOICES]; + float res = 0; - // precomputed values for all voices + // precomputed values for all voices float pw; //, saw, square, sub; // "internal state" values for patch parameters @@ -49,9 +50,9 @@ class Module { uint8_t vcoLfo = 0x00; uint8_t pwmLfo = 0x60; uint8_t noise = 0x00; - uint8_t vcfFreq = 0x30;//1c; // 0x3f80 + uint8_t vcfFreq = 0x30; // 1c; // 0x3f80 uint8_t vcfReso = 0x00; - uint8_t vcfEnv = 0x40;//4e; + uint8_t vcfEnv = 0x40; // 4e; uint8_t vcfLfo = 0; uint8_t vcfKey = 0x7f; // 47; uint8_t vca = 0x28; @@ -66,11 +67,11 @@ class Module { private: // controls - float subRC = 0, outRC = 0, pwmRC = 0, resRC = 0, noiseRC = 0; }; class Voice { friend Module; + public: Voice(); void on(uint8_t midiNote); diff --git a/plugin/peacock.cpp b/plugin/peacock.cpp index 173ee25..e157b31 100644 --- a/plugin/peacock.cpp +++ b/plugin/peacock.cpp @@ -18,22 +18,27 @@ #include "peacock.hpp" +double sampleRate; +uint32_t bufferSize; + START_NAMESPACE_DISTRHO Peacock::Peacock() : Plugin(parameterCount, 0, 0) { d_debug("peacock constructor\n"); + sampleRate = getSampleRate(); - m = new Module; + bufferSize = getBufferSize(); + m = new Module(); ic1 = new Assigner; ic1->voice = voice; - chorus = new Chorus; + chorus = new Chorus(); + } Peacock::~Peacock() { - free(m); - free(ic1); - free(chorus); + printf("peacock destructor\n"); + } void Peacock::initAudioPort(bool input, uint32_t index, AudioPort& port) { @@ -99,7 +104,7 @@ void Peacock::run(const float**, float** outputs, uint32_t frames, const MidiEve //memcpy(outputs[1], outputs[0], sizeof(float) * frames); chorus->run(outputs[0], outputs, frames); - //outputs[0][0]=1; + // outputs[0][0]=1; } Plugin* createPlugin() { return new Peacock(); } diff --git a/plugin/peacock.hpp b/plugin/peacock.hpp index 72654ed..b391c64 100644 --- a/plugin/peacock.hpp +++ b/plugin/peacock.hpp @@ -21,8 +21,11 @@ #include "DistrhoPlugin.hpp" #include "assigner.hpp" -#include "module.hpp" #include "chorus.hpp" +#include "module.hpp" + +extern double sampleRate; +extern uint32_t bufferSize; START_NAMESPACE_DISTRHO @@ -31,7 +34,6 @@ class Peacock : public Plugin { Peacock(); ~Peacock(); - protected: const char* getLabel() const override { return "peacock-8"; } const char* getDescription() const override { @@ -59,8 +61,6 @@ class Peacock : public Plugin { Module* m; Chorus* chorus; - uint32_t sampleRate; - // variables for breaking up the 4.3 millisecond module board ticks uint32_t lastEvent = 0; // event number of last MIDI event processed in a chunk uint32_t framesLeft = 0, blockLeft = 0; diff --git a/plugin/svf.hpp b/plugin/svf.hpp index cc05f72..8af410f 100644 --- a/plugin/svf.hpp +++ b/plugin/svf.hpp @@ -16,8 +16,8 @@ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef SVF_HPP -#define SVF_HPP +#ifndef __SVF_HPP +#define __SVF_HPP #include