2016-01-07 08:14:33 +00:00
|
|
|
#pragma once
|
2011-08-20 14:40:44 +00:00
|
|
|
|
2011-09-23 11:13:57 +00:00
|
|
|
struct ResampleHermite : Resampler {
|
2013-05-02 11:25:45 +00:00
|
|
|
ResampleHermite(DSP& dsp) : Resampler(dsp) {}
|
2011-09-23 11:13:57 +00:00
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
inline auto setFrequency() -> void;
|
|
|
|
inline auto clear() -> void;
|
|
|
|
inline auto sample() -> void;
|
|
|
|
|
|
|
|
private:
|
|
|
|
double fraction;
|
|
|
|
double step;
|
2011-09-23 11:13:57 +00:00
|
|
|
};
|
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
auto ResampleHermite::setFrequency() -> void {
|
2011-09-23 11:13:57 +00:00
|
|
|
fraction = 0.0;
|
|
|
|
step = dsp.settings.frequency / frequency;
|
|
|
|
}
|
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
auto ResampleHermite::clear() -> void {
|
2011-09-23 11:13:57 +00:00
|
|
|
fraction = 0.0;
|
|
|
|
}
|
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
auto ResampleHermite::sample() -> void {
|
2011-09-23 11:13:57 +00:00
|
|
|
while(fraction <= 1.0) {
|
2015-11-21 07:36:48 +00:00
|
|
|
double channel[dsp.settings.channels];
|
2011-08-20 14:40:44 +00:00
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
for(auto n : range(dsp.settings.channels)) {
|
|
|
|
double a = dsp.buffer.read(n, -3);
|
|
|
|
double b = dsp.buffer.read(n, -2);
|
|
|
|
double c = dsp.buffer.read(n, -1);
|
|
|
|
double d = dsp.buffer.read(n, -0);
|
2011-08-20 14:40:44 +00:00
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
const double tension = 0.0; //-1 = low, 0 = normal, +1 = high
|
|
|
|
const double bias = 0.0; //-1 = left, 0 = even, +1 = right
|
2011-08-20 14:40:44 +00:00
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
double mu1, mu2, mu3, m0, m1, a0, a1, a2, a3;
|
2011-08-20 14:40:44 +00:00
|
|
|
|
2011-09-23 11:13:57 +00:00
|
|
|
mu1 = fraction;
|
2011-08-20 14:40:44 +00:00
|
|
|
mu2 = mu1 * mu1;
|
|
|
|
mu3 = mu2 * mu1;
|
|
|
|
|
|
|
|
m0 = (b - a) * (1.0 + bias) * (1.0 - tension) / 2.0;
|
|
|
|
m0 += (c - b) * (1.0 - bias) * (1.0 - tension) / 2.0;
|
|
|
|
m1 = (c - b) * (1.0 + bias) * (1.0 - tension) / 2.0;
|
|
|
|
m1 += (d - c) * (1.0 - bias) * (1.0 - tension) / 2.0;
|
|
|
|
|
|
|
|
a0 = +2 * mu3 - 3 * mu2 + 1;
|
|
|
|
a1 = mu3 - 2 * mu2 + mu1;
|
|
|
|
a2 = mu3 - mu2;
|
|
|
|
a3 = -2 * mu3 + 3 * mu2;
|
|
|
|
|
|
|
|
channel[n] = (a0 * b) + (a1 * m0) + (a2 * m1) + (a3 * c);
|
|
|
|
}
|
|
|
|
|
2011-09-23 11:13:57 +00:00
|
|
|
dsp.write(channel);
|
|
|
|
fraction += step;
|
2011-08-20 14:40:44 +00:00
|
|
|
}
|
|
|
|
|
2011-09-23 11:13:57 +00:00
|
|
|
dsp.buffer.rdoffset++;
|
|
|
|
fraction -= 1.0;
|
2011-08-20 14:40:44 +00:00
|
|
|
}
|