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 ~Interpolation () { phase.clear(); }
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_to (int /*input_buffer_size*/, int /*output_buffer_size*/) { phase.push_back (0.0); }
52 void remove_channel_from () { phase.pop_back (); }
55 for (size_t i = 0; i < phase.size(); i++) {
61 class LIBARDOUR_API LinearInterpolation : public Interpolation {
63 framecnt_t interpolate (int channel, framecnt_t nframes, Sample* input, Sample* output);
66 class LIBARDOUR_API CubicInterpolation : public Interpolation {
68 framecnt_t interpolate (int channel, framecnt_t nframes, Sample* input, Sample* output);
73 class LIBARDOUR_API CubicMidiInterpolation : public Interpolation {
75 framecnt_t distance (framecnt_t nframes, bool roll = true);