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