Path: blob/master/libsnes/bsnes/nall/dsp/resample/cubic.hpp
2 views
#ifdef NALL_DSP_INTERNAL_HPP12struct ResampleCubic : Resampler {3inline void setFrequency();4inline void clear();5inline void sample();6ResampleCubic(DSP &dsp) : Resampler(dsp) {}78real fraction;9real step;10};1112void ResampleCubic::setFrequency() {13fraction = 0.0;14step = dsp.settings.frequency / frequency;15}1617void ResampleCubic::clear() {18fraction = 0.0;19}2021void ResampleCubic::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, -3);27real b = dsp.buffer.read(n, -2);28real c = dsp.buffer.read(n, -1);29real d = dsp.buffer.read(n, -0);3031real mu = fraction;3233real A = d - c - a + b;34real B = a - b - A;35real C = c - a;36real D = b;3738channel[n] = A * (mu * 3) + B * (mu * 2) + C * mu + D;39}4041dsp.write(channel);42fraction += step;43}4445dsp.buffer.rdoffset++;46fraction -= 1.0;47}4849#endif505152