No-op: reformat and add GPL boilerplate.
[ardour.git] / libs / ardour / ardour / interpolation.h
1 /*
2     Copyright (C) 1999-2010 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
20 #include <math.h>
21 #include <samplerate.h>
22
23 #include "ardour/types.h"
24
25 #ifndef __interpolation_h__
26 #define __interpolation_h__
27
28 namespace ARDOUR {
29
30 class Interpolation {
31 protected:
32         double _speed;
33         double _target_speed;
34
35         // the idea is that when the speed is not 1.0, we have to
36         // interpolate between samples and then we have to store where we thought we were.
37         // rather than being at sample N or N+1, we were at N+0.8792922
38         std::vector<double> phase;
39
40 public:
41         Interpolation ()  { _speed = 1.0; _target_speed = 1.0; }
42         ~Interpolation () { phase.clear(); }
43
44         void set_speed (double new_speed)          { _speed = new_speed; _target_speed = new_speed; }
45         void set_target_speed (double new_speed)   { _target_speed = new_speed; }
46         
47         double target_speed()          const { return _target_speed; }
48         double speed()                 const { return _speed; }
49         
50         void add_channel_to (int /*input_buffer_size*/, int /*output_buffer_size*/) { phase.push_back (0.0); }
51         void remove_channel_from () { phase.pop_back (); }
52         
53         void reset () {
54                 for (size_t i = 0; i < phase.size(); i++) {
55                         phase[i] = 0.0;
56                 }
57         }
58 };
59
60 class LinearInterpolation : public Interpolation {
61 public:
62         framecnt_t interpolate (int channel, framecnt_t nframes, Sample* input, Sample* output);
63 };
64
65 class CubicInterpolation : public Interpolation {
66 public:
67         framecnt_t interpolate (int channel, framecnt_t nframes, Sample* input, Sample* output);
68 };
69
70 } // namespace ARDOUR
71
72 #endif