Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libsnes/bsnes/snes/alt/dsp/dsp.cpp
2 views
1
#include <snes/snes.hpp>
2
3
#define DSP_CPP
4
namespace SNES {
5
6
DSP dsp;
7
8
#include "serialization.cpp"
9
#include "SPC_DSP.cpp"
10
11
void DSP::step(unsigned clocks) {
12
clock += clocks;
13
}
14
15
void DSP::synchronize_smp() {
16
if(SMP::Threaded == true) {
17
if(clock >= 0 && scheduler.sync != Scheduler::SynchronizeMode::All) co_switch(smp.thread);
18
} else {
19
while(clock >= 0) smp.enter();
20
}
21
}
22
23
void DSP::enter() {
24
spc_dsp.run(1);
25
step(24);
26
27
signed count = spc_dsp.sample_count();
28
if(count > 0) {
29
for(unsigned n = 0; n < count; n += 2) audio.sample(samplebuffer[n + 0], samplebuffer[n + 1]);
30
spc_dsp.set_output(samplebuffer, 8192);
31
}
32
}
33
34
uint8 DSP::read(uint8 addr) {
35
return spc_dsp.read(addr);
36
}
37
38
void DSP::write(uint8 addr, uint8 data) {
39
spc_dsp.write(addr, data);
40
}
41
42
void DSP::power() {
43
spc_dsp.init(smp.apuram);
44
spc_dsp.reset();
45
spc_dsp.set_output(samplebuffer, 8192);
46
}
47
48
void DSP::reset() {
49
spc_dsp.soft_reset();
50
spc_dsp.set_output(samplebuffer, 8192);
51
}
52
53
void DSP::channel_enable(unsigned channel, bool enable) {
54
channel_enabled[channel & 7] = enable;
55
unsigned mask = 0;
56
for(unsigned i = 0; i < 8; i++) {
57
if(channel_enabled[i] == false) mask |= 1 << i;
58
}
59
spc_dsp.mute_voices(mask);
60
}
61
62
DSP::DSP() {
63
for(unsigned i = 0; i < 8; i++) channel_enabled[i] = true;
64
}
65
66
}
67
68