2011-08-20 14:40:44 +00:00
|
|
|
#ifdef NALL_DSP_INTERNAL_HPP
|
|
|
|
|
2011-09-23 11:13:57 +00:00
|
|
|
struct ResampleLinear : Resampler {
|
|
|
|
inline void setFrequency();
|
|
|
|
inline void clear();
|
|
|
|
inline void sample();
|
2013-05-02 11:25:45 +00:00
|
|
|
ResampleLinear(DSP& dsp) : Resampler(dsp) {}
|
2011-08-20 14:40:44 +00:00
|
|
|
|
2011-09-23 11:13:57 +00:00
|
|
|
real fraction;
|
|
|
|
real step;
|
|
|
|
};
|
2011-08-20 14:40:44 +00:00
|
|
|
|
2011-09-23 11:13:57 +00:00
|
|
|
void ResampleLinear::setFrequency() {
|
|
|
|
fraction = 0.0;
|
|
|
|
step = dsp.settings.frequency / frequency;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResampleLinear::clear() {
|
|
|
|
fraction = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResampleLinear::sample() {
|
|
|
|
while(fraction <= 1.0) {
|
|
|
|
real channel[dsp.settings.channels];
|
|
|
|
|
|
|
|
for(unsigned n = 0; n < dsp.settings.channels; n++) {
|
|
|
|
real a = dsp.buffer.read(n, -1);
|
|
|
|
real b = dsp.buffer.read(n, -0);
|
|
|
|
|
|
|
|
real mu = fraction;
|
2011-08-20 14:40:44 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|