blob: 9a45d560c0b0ef5813dba8bd3e0f79a50816ff23 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
#include <stdint.h>
#include <cstdio>
#include "ardour/interpolation.h"
using namespace ARDOUR;
nframes_t
LinearInterpolation::interpolate (int channel, nframes_t nframes, Sample *input, Sample *output)
{
// index in the input buffers
nframes_t i = 0;
double acceleration;
double distance = 0.0;
if (_speed != _target_speed) {
acceleration = _target_speed - _speed;
} else {
acceleration = 0.0;
}
distance = phase[channel];
for (nframes_t outsample = 0; outsample < nframes; ++outsample) {
i = floor(distance);
Sample fractional_phase_part = distance - i;
if (fractional_phase_part >= 1.0) {
fractional_phase_part -= 1.0;
i++;
}
if (input && output) {
// Linearly interpolate into the output buffer
output[outsample] =
input[i] * (1.0f - fractional_phase_part) +
input[i+1] * fractional_phase_part;
}
distance += _speed + acceleration;
}
i = floor(distance);
phase[channel] = distance - floor(distance);
return i;
}
nframes_t
CubicInterpolation::interpolate (int channel, nframes_t nframes, Sample *input, Sample *output)
{
// index in the input buffers
nframes_t i = 0;
double acceleration;
double distance = 0.0;
if (_speed != _target_speed) {
acceleration = _target_speed - _speed;
} else {
acceleration = 0.0;
}
distance = phase[channel];
for (nframes_t outsample = 0; outsample < nframes; ++outsample) {
i = floor(distance);
Sample fractional_phase_part = distance - i;
if (fractional_phase_part >= 1.0) {
fractional_phase_part -= 1.0;
i++;
}
if (input && output) {
// Cubically interpolate into the output buffer
output[outsample] = cube_interp(fractional_phase_part, input[i-1], input[i], input[i+1], input[i+2]);
}
distance += _speed + acceleration;
}
i = floor(distance);
phase[channel] = distance - floor(distance);
return i;
}
|