Browse Source

Remove rate limiting from CV-MIDI, WIP.

tags/v2.0.0
Andrew Belt 4 years ago
parent
commit
7aa8f896a3
2 changed files with 12 additions and 9 deletions
  1. +10
    -9
      src/core/CV_MIDI.cpp
  2. +2
    -0
      src/engine/Engine.cpp

+ 10
- 9
src/core/CV_MIDI.cpp View File

@@ -44,7 +44,7 @@ struct CV_MIDI : Module {
};

MidiOutput midiOutput;
float rateLimiterPhase = 0.f;
dsp::Timer rateLimiterTimer;

CV_MIDI() {
config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
@@ -68,14 +68,15 @@ struct CV_MIDI : Module {
}

void process(const ProcessArgs& args) override {
const float rateLimiterPeriod = 0.005f;
rateLimiterPhase += args.sampleTime / rateLimiterPeriod;
if (rateLimiterPhase >= 1.f) {
rateLimiterPhase -= 1.f;
}
else {
return;
}
// MIDI baud rate is 31250 b/s, or 3125 B/s.
// CC messages are 3 bytes, so we can send a maximum of 1041 CC messages per second.
// Since multiple CCs can be generated, play it safe and limit the CC rate to 200 Hz.
const float rateLimiterPeriod = 1 / 200.f;
bool rateLimiterTriggered = (rateLimiterTimer.process(args.sampleTime) >= rateLimiterPeriod);
if (rateLimiterTriggered)
rateLimiterTimer.time -= rateLimiterPeriod;

midiOutput.setTimestamp(APP->engine->getFrameTime());

for (int c = 0; c < inputs[PITCH_INPUT].getChannels(); c++) {
int vel = (int) std::round(inputs[VEL_INPUT].getNormalPolyVoltage(10.f * 100 / 127, c) / 10.f * 127);


+ 2
- 0
src/engine/Engine.cpp View File

@@ -560,8 +560,10 @@ void Engine::step(int frames) {
random::init();

internal->stepFrame = internal->frame;
int64_t oldStepTime = internal->stepTime;
internal->stepTime = system::getNanoseconds();
internal->stepFrames = frames;
DEBUG("time %ld", internal->stepTime - oldStepTime);

// Set sample rate
if (internal->sampleRate != settings::sampleRate) {


Loading…
Cancel
Save