can calculate frame/block size correctly for at least 512 and 128 frames per chunk

This commit is contained in:
Gordon JC Pearce 2024-09-05 10:01:22 +01:00
parent 98ab957faf
commit fa30594239
2 changed files with 24 additions and 24 deletions

View File

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

View File

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