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 ResampleCosine : Resampler {
|
2013-05-02 11:25:45 +00:00
|
|
|
ResampleCosine(DSP& dsp) : Resampler(dsp) {}
|
2011-08-20 14:40:44 +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
|
|
|
};
|
2011-08-20 14:40:44 +00:00
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
auto ResampleCosine::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 ResampleCosine::clear() -> void {
|
2011-09-23 11:13:57 +00:00
|
|
|
fraction = 0.0;
|
|
|
|
}
|
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
auto ResampleCosine::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-09-23 11:13:57 +00:00
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
for(auto n : range(dsp.settings.channels)) {
|
|
|
|
double a = dsp.buffer.read(n, -1);
|
|
|
|
double b = dsp.buffer.read(n, -0);
|
2011-09-23 11:13:57 +00:00
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
double mu = fraction;
|
2011-08-20 14:40:44 +00:00
|
|
|
mu = (1.0 - cos(mu * 3.14159265)) / 2.0;
|
|
|
|
|
|
|
|
channel[n] = a * (1.0 - mu) + b * mu;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|