2 Copyright (C) 1999-2010 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <samplerate.h>
23 #include "ardour/libardour_visibility.h"
24 #include "ardour/types.h"
26 #ifndef __interpolation_h__
27 #define __interpolation_h__
31 class LIBARDOUR_API Interpolation {
36 // the idea is that when the speed is not 1.0, we have to
37 // interpolate between samples and then we have to store where we thought we were.
38 // rather than being at sample N or N+1, we were at N+0.8792922
39 std::vector<double> phase;
42 Interpolation () { _speed = 1.0; _target_speed = 1.0; }
43 virtual ~Interpolation() {}
45 void set_speed (double new_speed) { _speed = new_speed; _target_speed = new_speed; }
46 void set_target_speed (double new_speed) { _target_speed = new_speed; }
48 double target_speed() const { return _target_speed; }
49 double speed() const { return _speed; }
51 void add_channel () { phase.push_back (0.0); }
52 void remove_channel () { phase.pop_back (); }
54 virtual void reset () {
55 for (size_t i = 0; i < phase.size(); i++) {
61 class LIBARDOUR_API CubicInterpolation : public Interpolation {
63 CubicInterpolation ();
64 samplecnt_t interpolate (int channel, samplecnt_t input_samples, Sample* input, samplecnt_t & output_samples, Sample* output);
65 samplecnt_t distance (samplecnt_t nframes);
72 bool is_valid (int n) const { return valid_z_bits & (1<<n); }
73 bool invalid (int n) const { return !is_valid (n); }
74 void validate (int n) { valid_z_bits |= (1<<n); }
75 void invalidate (int n) { valid_z_bits &= (1<<n); }