From 7619946b4b804416a08b11d168e5e71f77d0c1ac Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 10 Mar 2015 22:05:21 +0100 Subject: MIDI vari-speed playback --- libs/ardour/interpolation.cc | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'libs/ardour/interpolation.cc') diff --git a/libs/ardour/interpolation.cc b/libs/ardour/interpolation.cc index bccaa45553..79b43bc58e 100644 --- a/libs/ardour/interpolation.cc +++ b/libs/ardour/interpolation.cc @@ -21,6 +21,7 @@ #include #include "ardour/interpolation.h" +#include "ardour/midi_buffer.h" using namespace ARDOUR; @@ -150,3 +151,38 @@ CubicInterpolation::interpolate (int channel, framecnt_t nframes, Sample *input, return i; } + +framecnt_t +CubicMidiInterpolation::distance (framecnt_t nframes, bool roll) +{ + assert(phase.size() == 1); + + framecnt_t i = 0; + + double acceleration; + double distance = 0.0; + + if (nframes < 3) { + return nframes; + } + + if (_speed != _target_speed) { + acceleration = _target_speed - _speed; + } else { + acceleration = 0.0; + } + + distance = phase[0]; + + for (framecnt_t outsample = 0; outsample < nframes; ++outsample) { + distance += _speed + acceleration; + } + + if (roll) { + phase[0] = distance - floor(distance); + } + + i = floor(distance); + + return i; +} -- cgit v1.2.3