2 #include <samplerate.h>
4 #include "ardour/types.h"
6 #ifndef __interpolation_h__
7 #define __interpolation_h__
13 double _speed, _target_speed;
16 Interpolation () { _speed = 1.0; }
18 void set_speed (double new_speed) { _speed = new_speed; }
19 void set_target_speed (double new_speed) { _target_speed = new_speed; }
21 double target_speed() const { return _target_speed; }
22 double speed() const { return _speed; }
24 void add_channel_to (int input_buffer_size, int output_buffer_size) {}
25 void remove_channel_from () {}
30 // 40.24 fixpoint math
31 #define FIXPOINT_ONE 0x1000000
33 class FixedPointLinearInterpolation : public Interpolation {
35 /// speed in fixed point math
38 /// target speed in fixed point math
41 std::vector<uint64_t> last_phase;
43 // Fixed point is just an integer with an implied scaling factor.
44 // In 40.24 the scaling factor is 2^24 = 16777216,
45 // so a value of 10*2^24 (in integer space) is equivalent to 10.0.
47 // The advantage is that addition and modulus [like x = (x + y) % 2^40]
48 // have no rounding errors and no drift, and just require a single integer add.
51 static const int64_t fractional_part_mask = 0xFFFFFF;
52 static const Sample binary_scaling_factor = 16777216.0f;
55 FixedPointLinearInterpolation () : phi (FIXPOINT_ONE), target_phi (FIXPOINT_ONE) {}
57 void set_speed (double new_speed) {
58 target_phi = (uint64_t) (FIXPOINT_ONE * fabs(new_speed));
62 void add_channel_to (int input_buffer_size, int output_buffer_size);
63 void remove_channel_from ();
65 nframes_t interpolate (int channel, nframes_t nframes, Sample* input, Sample* output);
69 class LinearInterpolation : public Interpolation {
71 // the idea is that when the speed is not 1.0, we have to
72 // interpolate between samples and then we have to store where we thought we were.
73 // rather than being at sample N or N+1, we were at N+0.8792922
74 std::vector<double> phase;
77 void add_channel_to (int input_buffer_size, int output_buffer_size);
78 void remove_channel_from ();
80 nframes_t interpolate (int channel, nframes_t nframes, Sample* input, Sample* output);
84 class LibSamplerateInterpolation : public Interpolation {
86 std::vector<SRC_STATE*> state;
87 std::vector<SRC_DATA*> data;
94 LibSamplerateInterpolation ();
95 ~LibSamplerateInterpolation ();
97 void set_speed (double new_speed);
98 void set_target_speed (double new_speed) {}
99 double speed () const { return _speed; }
101 void add_channel_to (int input_buffer_size, int output_buffer_size);
102 void remove_channel_from ();
104 nframes_t interpolate (int channel, nframes_t nframes, Sample* input, Sample* output);
105 void reset() { reset_state (); }
108 } // namespace ARDOUR