4 #include "ardour/interpolation.h"
6 using namespace ARDOUR;
10 LinearInterpolation::interpolate (int channel, nframes_t nframes, Sample *input, Sample *output)
12 // index in the input buffers
16 double distance = 0.0;
18 if (_speed != _target_speed) {
19 acceleration = _target_speed - _speed;
24 distance = phase[channel];
25 for (nframes_t outsample = 0; outsample < nframes; ++outsample) {
27 Sample fractional_phase_part = distance - i;
28 if (fractional_phase_part >= 1.0) {
29 fractional_phase_part -= 1.0;
33 if (input && output) {
34 // Linearly interpolate into the output buffer
36 input[i] * (1.0f - fractional_phase_part) +
37 input[i+1] * fractional_phase_part;
39 distance += _speed + acceleration;
43 phase[channel] = distance - floor(distance);
49 CubicInterpolation::interpolate (int channel, nframes_t nframes, Sample *input, Sample *output)
51 // index in the input buffers
55 double distance = 0.0;
57 if (_speed != _target_speed) {
58 acceleration = _target_speed - _speed;
63 distance = phase[channel];
64 for (nframes_t outsample = 0; outsample < nframes; ++outsample) {
66 Sample fractional_phase_part = distance - i;
67 if (fractional_phase_part >= 1.0) {
68 fractional_phase_part -= 1.0;
72 if (input && output) {
73 // Cubically interpolate into the output buffer
74 output[outsample] = cube_interp(fractional_phase_part, input[i-1], input[i], input[i+1], input[i+2]);
76 distance += _speed + acceleration;
80 phase[channel] = distance - floor(distance);