2 #include "ardour/interpolation.h"
5 LinearInterpolation::interpolate (nframes_t nframes, Sample *input, Sample *output)
7 // the idea behind phase is that when the speed is not 1.0, we have to
8 // interpolate between samples and then we have to store where we thought we were.
9 // rather than being at sample N or N+1, we were at N+0.8792922
10 // so the "phase" element, if you want to think about this way,
11 // varies from 0 to 1, representing the "offset" between samples
12 uint64_t phase = last_phase;
17 // phi = fixed point speed
18 if (phi != target_phi) {
19 phi_delta = ((int64_t)(target_phi - phi)) / nframes;
24 // index in the input buffers
27 for (nframes_t outsample = 0; outsample < nframes; ++outsample) {
29 Sample fractional_phase_part = (phase & fractional_part_mask) / binary_scaling_factor;
31 // Linearly interpolate into the output buffer
32 // using fixed point math
34 input[i] * (1.0f - fractional_phase_part) +
35 input[i+1] * fractional_phase_part;
36 phase += phi + phi_delta;
39 last_phase = (phase & fractional_part_mask);