Path: blob/master/libsnes/bsnes/nall/dsp/resample/nearest.hpp
2 views
#ifdef NALL_DSP_INTERNAL_HPP12struct ResampleNearest : Resampler {3inline void setFrequency();4inline void clear();5inline void sample();6ResampleNearest(DSP &dsp) : Resampler(dsp) {}78real fraction;9real step;10};1112void ResampleNearest::setFrequency() {13fraction = 0.0;14step = dsp.settings.frequency / frequency;15}1617void ResampleNearest::clear() {18fraction = 0.0;19}2021void ResampleNearest::sample() {22while(fraction <= 1.0) {23real *channel = (real*)alloca(dsp.settings.channels * sizeof(real));2425for(unsigned n = 0; n < dsp.settings.channels; n++) {26real a = dsp.buffer.read(n, -1);27real b = dsp.buffer.read(n, -0);2829real mu = fraction;3031channel[n] = mu < 0.5 ? a : b;32}3334dsp.write(channel);35fraction += step;36}3738dsp.buffer.rdoffset++;39fraction -= 1.0;40}4142#endif434445