globals for samplerate and buffersize

This commit is contained in:
Gordon JC Pearce 2025-12-21 21:00:53 +00:00
parent 8f604d10c2
commit 23d99e92f2
7 changed files with 39 additions and 32 deletions

View File

@ -23,12 +23,7 @@
#include <cstdio>
//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;

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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(); }

View File

@ -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;

View File

@ -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 <stdint.h>