Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libsnes/bsnes/nall/dsp/resample/nearest.hpp
2 views
1
#ifdef NALL_DSP_INTERNAL_HPP
2
3
struct ResampleNearest : Resampler {
4
inline void setFrequency();
5
inline void clear();
6
inline void sample();
7
ResampleNearest(DSP &dsp) : Resampler(dsp) {}
8
9
real fraction;
10
real step;
11
};
12
13
void ResampleNearest::setFrequency() {
14
fraction = 0.0;
15
step = dsp.settings.frequency / frequency;
16
}
17
18
void ResampleNearest::clear() {
19
fraction = 0.0;
20
}
21
22
void ResampleNearest::sample() {
23
while(fraction <= 1.0) {
24
real *channel = (real*)alloca(dsp.settings.channels * sizeof(real));
25
26
for(unsigned n = 0; n < dsp.settings.channels; n++) {
27
real a = dsp.buffer.read(n, -1);
28
real b = dsp.buffer.read(n, -0);
29
30
real mu = fraction;
31
32
channel[n] = mu < 0.5 ? a : b;
33
}
34
35
dsp.write(channel);
36
fraction += step;
37
}
38
39
dsp.buffer.rdoffset++;
40
fraction -= 1.0;
41
}
42
43
#endif
44
45