diff options
author | Robin Gareus <robin@gareus.org> | 2015-03-10 22:05:21 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2015-03-10 22:15:44 +0100 |
commit | 7619946b4b804416a08b11d168e5e71f77d0c1ac (patch) | |
tree | 8b920a3336cf9a6db960625f6ab385834eba8a24 /libs/ardour/interpolation.cc | |
parent | 3139b7e9804496395beb787622d5de90266b8e4a (diff) |
MIDI vari-speed playback
Diffstat (limited to 'libs/ardour/interpolation.cc')
-rw-r--r-- | libs/ardour/interpolation.cc | 36 |
1 files changed, 36 insertions, 0 deletions
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 <cstdio> #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; +} |