13
0

Fix MIDI delay-line (amend 25098ed)

Events in the delay-buffer must be shifted back every cycle.
Also in case of fixed-delay-lines events may not be in sequence
since events are only sorted at backend port-level.
This commit is contained in:
Robin Gareus 2022-05-15 18:55:17 +02:00
parent 576f10b6f1
commit ae0aa50b6f
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 21 additions and 16 deletions

View File

@ -231,20 +231,18 @@ DelayLine::run (BufferSet& bufs, samplepos_t /* start_sample */, samplepos_t /*
dly->silence (n_samples);
}
if (delay_diff != 0) {
/* If the delay time changes, iterate over all events in the dly-buffer
* and adjust the time in-place. <= 0 becomes 0.
*
* iterate over all events in dly-buffer and subtract one cycle
* (n_samples) from the timestamp, bringing them closer to de-queue.
*/
for (MidiBuffer::iterator m = dly->begin (); m != dly->end (); ++m) {
MidiBuffer::TimeType *t = m.timeptr ();
if (*t > n_samples + delay_diff) {
*t -= n_samples + delay_diff;
} else {
*t = 0;
}
/* If the delay time changes, iterate over all events in the dly-buffer
* and adjust the time in-place. <= 0 becomes 0.
*
* iterate over all events in dly-buffer and subtract one cycle
* (n_samples) from the timestamp, bringing them closer to de-queue.
*/
for (MidiBuffer::iterator m = dly->begin (); m != dly->end (); ++m) {
MidiBuffer::TimeType *t = m.timeptr ();
if (*t > n_samples + delay_diff) {
*t -= n_samples + delay_diff;
} else {
*t = 0;
}
}

View File

@ -148,7 +148,7 @@ FixedDelay::delay (
if (ev.time () < n_samples) {
mout->push_back (ev);
} else {
mdly->push_back (ev);
mdly->insert_event (ev);
}
}
@ -158,9 +158,16 @@ FixedDelay::delay (
if (ev.time () >= n_samples) {
break;
}
mout->push_back (ev);
mout->insert_event (ev);
m = mdly->erase (m);
}
/* prepare for next cycle */
for (MidiBuffer::iterator m = mdly->begin (); m != mdly->end (); ++m) {
MidiBuffer::TimeType *t = m.timeptr ();
assert (*t >= n_samples);
*t -= n_samples;
}
return;
}