2 //#include "ardour/types.h"
5 #define nframes_t uint32_t
8 #define FIXPOINT_ONE 0x1000000
12 /// speed in fixed point math
15 /// target speed in fixed point math
20 // Fixed point is just an integer with an implied scaling factor.
21 // In 40.24 the scaling factor is 2^24 = 16777216,
22 // so a value of 10*2^24 (in integer space) is equivalent to 10.0.
24 // The advantage is that addition and modulus [like x = (x + y) % 2^40]
25 // have no rounding errors and no drift, and just require a single integer add.
28 static const int64_t fractional_part_mask = 0xFFFFFF;
29 static const Sample binary_scaling_factor = 16777216.0f;
32 Interpolation () : phi (FIXPOINT_ONE), target_phi (FIXPOINT_ONE), last_phase (0) {}
34 void set_speed (double new_speed) {
35 target_phi = (uint64_t) (FIXPOINT_ONE * fabs(new_speed));
39 uint64_t get_phi () const { return phi; }
40 uint64_t get_target_phi () const { return target_phi; }
41 uint64_t get_last_phase () const { return last_phase; }
43 virtual nframes_t interpolate (nframes_t nframes, Sample* input, Sample* output) = 0;
46 class LinearInterpolation : public Interpolation {
48 nframes_t interpolate (nframes_t nframes, Sample* input, Sample* output);