-void
-Interpolation::add_channel_to (int input_buffer_size, int output_buffer_size)
-{
- SRC_DATA newdata;
-
- /* Set up sample rate converter info. */
- newdata.end_of_input = 0 ;
-
- newdata.input_frames = input_buffer_size;
- newdata.output_frames = output_buffer_size;
-
- newdata.input_frames_used = 0 ;
- newdata.output_frames_gen = 0 ;
-
- newdata.src_ratio = 1.0/_speed;
-
- data.push_back (newdata);
-
- reset_state ();
+ if (nframes < 3) {
+ /* no interpolation possible */
+
+ if (input && output) {
+ for (i = 0; i < nframes; ++i) {
+ output[i] = input[i];
+ }
+ }
+
+ phase[channel] = 0;
+ return nframes;
+ }
+
+ /* keep this condition out of the inner loop */
+
+ if (input && output) {
+ /* best guess for the fake point we have to add to be able to interpolate at i == 0:
+ * .... maintain slope of first actual segment ...
+ */
+ Sample inm1 = input[i] - (input[i+1] - input[i]);
+
+ for (framecnt_t outsample = 0; outsample < nframes; ++outsample) {
+ /* get the index into the input we should start with */
+ i = floor (distance);
+ float fractional_phase_part = fmod (distance, 1.0);
+
+ // Cubically interpolate into the output buffer: keep this inlined for speed and rely on compiler
+ // optimization to take care of the rest
+ // shamelessly ripped from Steve Harris' swh-plugins (ladspa-util.h)
+
+ output[outsample] = input[i] + 0.5f * fractional_phase_part * (input[i+1] - inm1 +
+ fractional_phase_part * (4.0f * input[i+1] + 2.0f * inm1 - 5.0f * input[i] - input[i+2] +
+ fractional_phase_part * (3.0f * (input[i] - input[i+1]) - inm1 + input[i+2])));
+
+ distance += _speed + acceleration;
+ inm1 = input[i];
+ }
+
+ i = floor (distance);
+ phase[channel] = fmod (distance, 1.0);
+
+ } else {
+ /* used to calculate play-distance with acceleration (silent roll)
+ * (use same algorithm as real playback for identical rounding/floor'ing)
+ */
+ for (framecnt_t outsample = 0; outsample < nframes; ++outsample) {
+ distance += _speed + acceleration;
+ }
+ i = floor (distance);
+ phase[channel] = fmod (distance, 1.0);
+ }
+
+ return i;