From ae0aa50b6f4df9df525dd3b65e3e70f5346b8a18 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sun, 15 May 2022 18:55:17 +0200 Subject: [PATCH] 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. --- libs/ardour/delayline.cc | 26 ++++++++++++-------------- libs/ardour/fixed_delay.cc | 11 +++++++++-- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/libs/ardour/delayline.cc b/libs/ardour/delayline.cc index d3f4982f79..19ac357db3 100644 --- a/libs/ardour/delayline.cc +++ b/libs/ardour/delayline.cc @@ -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; } } diff --git a/libs/ardour/fixed_delay.cc b/libs/ardour/fixed_delay.cc index 6606197047..75586ef13b 100644 --- a/libs/ardour/fixed_delay.cc +++ b/libs/ardour/fixed_delay.cc @@ -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; }