Path: blob/master/libsnes/bsnes/nall/dsp/resample/hermite.hpp
2 views
#ifdef NALL_DSP_INTERNAL_HPP12struct ResampleHermite : Resampler {3inline void setFrequency();4inline void clear();5inline void sample();6ResampleHermite(DSP &dsp) : Resampler(dsp) {}78real fraction;9real step;10};1112void ResampleHermite::setFrequency() {13fraction = 0.0;14step = dsp.settings.frequency / frequency;15}1617void ResampleHermite::clear() {18fraction = 0.0;19}2021void ResampleHermite::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);3031const real tension = 0.0; //-1 = low, 0 = normal, +1 = high32const real bias = 0.0; //-1 = left, 0 = even, +1 = right3334real mu1, mu2, mu3, m0, m1, a0, a1, a2, a3;3536mu1 = fraction;37mu2 = mu1 * mu1;38mu3 = mu2 * mu1;3940m0 = (b - a) * (1.0 + bias) * (1.0 - tension) / 2.0;41m0 += (c - b) * (1.0 - bias) * (1.0 - tension) / 2.0;42m1 = (c - b) * (1.0 + bias) * (1.0 - tension) / 2.0;43m1 += (d - c) * (1.0 - bias) * (1.0 - tension) / 2.0;4445a0 = +2 * mu3 - 3 * mu2 + 1;46a1 = mu3 - 2 * mu2 + mu1;47a2 = mu3 - mu2;48a3 = -2 * mu3 + 3 * mu2;4950channel[n] = (a0 * b) + (a1 * m0) + (a2 * m1) + (a3 * c);51}5253dsp.write(channel);54fraction += step;55}5657dsp.buffer.rdoffset++;58fraction -= 1.0;59}6061#endif626364