From fa305942395b066ea7e6266d39772d44fe998e12 Mon Sep 17 00:00:00 2001 From: Gordon JC Pearce Date: Thu, 5 Sep 2024 10:01:22 +0100 Subject: [PATCH] can calculate frame/block size correctly for at least 512 and 128 frames per chunk --- plugin/chassis.cpp | 44 ++++++++++++++++++++++---------------------- plugin/voice.hpp | 4 ++-- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/plugin/chassis.cpp b/plugin/chassis.cpp index 637396f..125ecd8 100644 --- a/plugin/chassis.cpp +++ b/plugin/chassis.cpp @@ -97,9 +97,6 @@ void Chassis::loadProgram(uint32_t index) { void Chassis::activate() { // calculate filter coefficients and stuff printf("called activate()\n"); - s.updateLength = sampleRate / 238; // update rate in Hz; - printf("update length is %d for %dHz sample rate\n", s.updateLength, (int)sampleRate); - //s.samplesLeft = s.updateLength; } void Chassis::deactivate() { @@ -139,29 +136,31 @@ void Chassis::noteOff(uint8_t note) { void Chassis::run(const float **, float **outputs, uint32_t frames, const MidiEvent *MidiEvents, uint32_t midiEventCount) { // if (midiEventCount > 0) printf("\n--------------------\n"); - //uint32_t framesDone = 0; -/* - if (s.samplesLeft == 0) { - printf("resetting s.samplesLeft to %d\n", frames); - s.samplesLeft = frames; - }*/ + + if (s.framesLeft == 0) s.framesLeft = frames; + + while ( s.framesLeft != 0) { + uint32_t sizeThisTime = (frames <= s.blockLeft)?frames:s.blockLeft; + + printf("sL = %d bL = %d, calculating %d frames\n", s.framesLeft, s.blockLeft, sizeThisTime); - printf("in run(%d), samplesLeft = %d\n", frames, s.samplesLeft); - s.samplesLeft = frames; + s.framesLeft -= sizeThisTime; + s.blockLeft -= sizeThisTime; + if (s.blockLeft == 0) { + s.blockLeft = 48000/238; + printf("compute params and reset block size\n"); + } + if (s.framesLeft <= s.blockLeft) { + s.blockLeft -= s.framesLeft; + printf("ended with %d frames, %d left in block\n", s.framesLeft, s.blockLeft); + s.framesLeft = 0; + } + }; - do { - printf("doing %d frames %d\n", s.updateLength, s.samplesLeft); - s.samplesLeft -= s.updateLength; - - } while (s.samplesLeft > s.updateLength); - printf("doing %d frames %d\n", s.samplesLeft, s.samplesLeft); - s.samplesLeft = s.updateLength - s.samplesLeft; - - - - printf("done with all that, %d\n", s.samplesLeft); + //printf("done with all that, %d\n", s.samplesLeft); + printf("and now run the rest of the process for %d frames\n\n", frames); for (uint32_t i = 0; i < midiEventCount; i++) { if (MidiEvents[i].data[0] == 0x90) { @@ -180,6 +179,7 @@ void Chassis::run(const float **, float **outputs, uint32_t frames, const MidiEv s.lastpw = s.lfo; // copy left to right memmove(outputs[1], outputs[0], sizeof(float) * frames); + } // create the plugin diff --git a/plugin/voice.hpp b/plugin/voice.hpp index a1d70a3..6ad6e3e 100644 --- a/plugin/voice.hpp +++ b/plugin/voice.hpp @@ -59,6 +59,6 @@ class Synth { Voice voice[8]; float lfo = 0, lfosw = 0.01; float lastpw = 0; - uint32_t updateLength; - uint32_t samplesLeft = 0; + uint32_t blockLeft; + uint32_t framesLeft = 0; };