breaks up into 4.3ms blocks correctly

This commit is contained in:
Gordon JC Pearce 2024-10-13 21:07:01 +01:00
parent c758a0a493
commit 0fe57ff017
5 changed files with 63 additions and 26 deletions

View File

@ -48,7 +48,7 @@ void Assigner::handleMidi(const MidiEvent *ev) {
noteOn(ev->data[1]); noteOn(ev->data[1]);
break; break;
default: default:
printf("handle event, status %02x value %02x\n", ev->data[0], ev->data[1]); d_debug("unhandled MIDI event, status %02x value %02x\n", ev->data[0], ev->data[1]);
break; break;
} }
} }

View File

@ -18,23 +18,21 @@
#include "ic29.hpp" #include "ic29.hpp"
Synth s; Synth s;
Synth::Synth() { Synth::Synth() {
printf("initialising synth\n"); d_debug("initialising synth\n");
envAtk = 0x007f; envAtk = 0x007f;
envDcy = envRls = 0xfe90; envDcy = envRls = 0xfe90;
envStn = 0x1fff; envStn = 0x1fff;
} }
void Synth::run() { void Synth::run() {
//printf("called synth::run()\n"); // handle a "loop" worth of envelopes, pitch calculations, etc
//printf("%d\n", voices[0].env.phase); // callled once every 4.3ms block of samples
for (uint8_t i=0; i<NUM_VOICES; i++) {
s.voices[i].env.run();
for (uint8_t i = 0; i < NUM_VOICES; i++) {
s.voices[i].env.run();
} }
} }
@ -42,6 +40,9 @@ void Synth::voiceOn(uint8_t voice, uint8_t note) {
// enable synth voice, start it all running // enable synth voice, start it all running
voice &= 0x7f; voice &= 0x7f;
s.voices[voice].env.on(); s.voices[voice].env.on();
// FIXME determine if we need to reset the counter
s.voices[voice].note = note;
} }
void Synth::voiceOff(uint8_t voice) { void Synth::voiceOff(uint8_t voice) {

View File

@ -20,8 +20,6 @@
#include "peacock.hpp" #include "peacock.hpp"
class Envelope { class Envelope {
public: public:
Envelope(); Envelope();

View File

@ -17,6 +17,7 @@
*/ */
#include "peacock.hpp" #include "peacock.hpp"
#include "ic1.hpp" #include "ic1.hpp"
#include "ic29.hpp" #include "ic29.hpp"
@ -28,20 +29,56 @@ Peacock::Peacock() : Plugin(paramCount, 0, 0), sampleRate(getSampleRate()) {
s.run(); s.run();
} }
void Peacock::runMidi(const MidiEvent *ev, uint32_t count, uint32_t timeLimit) {
// handle MIDI events, starting at lastEvent and continuing until timeLimit
if (count == 0) return; // no events to do, at all
for (uint32_t i = lastEvent; i < count; i++) {
if (ev[i].frame > timeLimit) break; // exceeded the time limit
ic1.handleMidi((const MidiEvent *)&ev[i]);
}
}
void Peacock::run(const float **, float **outputs, uint32_t frames, const MidiEvent *midiEvents, uint32_t midiEventCount) { void Peacock::run(const float **, float **outputs, uint32_t frames, const MidiEvent *midiEvents, uint32_t midiEventCount) {
// no content yet // no content yet
// dispose of parameters // dispose of parameters
(void)outputs; (void)outputs;
(void)frames;
//printf("got %d MIDI events\n", midiEventCount); // calculate an entire jack period's worth of samples
for(uint32_t i=0; i<midiEventCount; i++) { // harder than it sounds because for short jack periods there may be many
ic1.handleMidi((const MidiEvent *) &midiEvents[i]); // such calls between 4.3ms control updates, or there may be many updates
// within a single update
uint32_t framePos = 0; // sample position within current frame
// blockLeft is how many samples are left within this 4.3ms block
// framesleft is how many samples are left within this jack period
// the names are awful, I should FIXME this for legibility
uint32_t sizeThisTime = (framesLeft < blockLeft) ? framesLeft : blockLeft;
framesLeft = frames; // number of frames left to calculate
// now we'll handle MIDI events up to however long is left in this block
lastEvent = 0;
runMidi(midiEvents, midiEventCount, blockLeft);
while (framePos < frames) {
if (blockLeft == 0) {
blockLeft = (int)(getSampleRate() * 0.0043); // how many samples per 4.3ms block?
// handle all MIDI events for this block, up to the end of the block and frame
runMidi(midiEvents, midiEventCount, framePos + blockLeft);
s.run();
}
sizeThisTime = (framesLeft < blockLeft) ? framesLeft : blockLeft;
// run every synth voice into the buffer here FIXME
framePos += sizeThisTime; // move along the frame
framesLeft -= sizeThisTime;
blockLeft -= sizeThisTime;
} }
s.run();
} }
Plugin *createPlugin() { return new Peacock(); } Plugin *createPlugin() { return new Peacock(); }

View File

@ -25,7 +25,6 @@
START_NAMESPACE_DISTRHO START_NAMESPACE_DISTRHO
class Peacock : public Plugin { class Peacock : public Plugin {
public: public:
enum Parameters { enum Parameters {
@ -35,7 +34,6 @@ class Peacock : public Plugin {
Peacock(); Peacock();
protected: protected:
float sampleRate; float sampleRate;
const char *getLabel() const override { return "peacock-8"; } const char *getLabel() const override { return "peacock-8"; }
@ -48,22 +46,25 @@ class Peacock : public Plugin {
int64_t getUniqueId() const override { return d_cconst('P', 'f', 'a', 'u'); } int64_t getUniqueId() const override { return d_cconst('P', 'f', 'a', 'u'); }
// Initialisation // Initialisation
//void initAudioPort(bool input, uint32_t index, AudioPort &port) override; // void initAudioPort(bool input, uint32_t index, AudioPort &port) override;
//void initParameter(uint32_t index, Parameter &parameter) override; // void initParameter(uint32_t index, Parameter &parameter) override;
//void setParameterValue(uint32_t index, float value) override; // void setParameterValue(uint32_t index, float value) override;
//float getParameterValue(uint32_t index) const override; // float getParameterValue(uint32_t index) const override;
// Processing // Processing
//void activate() override; // void activate() override;
//void deactivate() override; // void deactivate() override;
void run(const float **, float **outputs, uint32_t frames, const MidiEvent *midiEvents, uint32_t midiEventCount) override; void run(const float **, float **outputs, uint32_t frames, const MidiEvent *midiEvents, uint32_t midiEventCount) override;
private: private:
uint32_t framesLeft = 0;
uint32_t blockLeft = 0;
uint32_t lastEvent = 0;
void runMidi(const MidiEvent *ev, uint32_t count, uint32_t timeLimit);
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Peacock); DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Peacock);
}; };
END_NAMESPACE_DISTRHO END_NAMESPACE_DISTRHO