2011-02-02 10:37:31 +00:00
|
|
|
#ifdef APU_CPP
|
|
|
|
|
|
|
|
void APU::Master::run() {
|
Update to v075r06 release.
byuu says:
Removed the floating-point volume adjustments from the wave channel and
the left/right speaker mixers. Also, against my better judgment I'm
backing out of left/right computation when they are both turned off.
This basically makes non-stereo games run faster, but will make stereo
games appear to run slower. I don't like it when end-users experience
mystery slowdowns.
Anyway, it appears that the audio calculation is really fucking
demanding. Knocks FPS from 800 down to 300. I thought it might be libco,
so I took it out and it only went up to 305fps o.O
There is also some sort of problem with bsnes/Super Game Boy audio. The
latency is really great when you first start, but it seems to drift
apart over time until it is well over 500ms, and then it either pops or
fades back to very low, sub-50ms latency again. The way I handle mixing
is that the coprocessor audio samples go into a resampler to the native
SNES rate, and fed to an output buffer. SNES audio samples go there
untouched. When there is a sample in each, I add them together and
average the result (I still don't understand why we divide by two since
these are signed integers), and output it immediately. It's just-in-time
sampling, so as long as DSP v Coprocessor do not drift very far, it
should have very low latency. And I make the CPU sync DSP and
Coprocessor once per scanline, which is something like 15 samples or so.
2011-02-03 11:17:35 +00:00
|
|
|
if(enable == false) {
|
|
|
|
center = 0;
|
|
|
|
left = 0;
|
|
|
|
right = 0;
|
2013-12-11 11:19:17 +00:00
|
|
|
|
|
|
|
center_bias = left_bias = right_bias = 0;
|
Update to v075r06 release.
byuu says:
Removed the floating-point volume adjustments from the wave channel and
the left/right speaker mixers. Also, against my better judgment I'm
backing out of left/right computation when they are both turned off.
This basically makes non-stereo games run faster, but will make stereo
games appear to run slower. I don't like it when end-users experience
mystery slowdowns.
Anyway, it appears that the audio calculation is really fucking
demanding. Knocks FPS from 800 down to 300. I thought it might be libco,
so I took it out and it only went up to 305fps o.O
There is also some sort of problem with bsnes/Super Game Boy audio. The
latency is really great when you first start, but it seems to drift
apart over time until it is well over 500ms, and then it either pops or
fades back to very low, sub-50ms latency again. The way I handle mixing
is that the coprocessor audio samples go into a resampler to the native
SNES rate, and fed to an output buffer. SNES audio samples go there
untouched. When there is a sample in each, I add them together and
average the result (I still don't understand why we divide by two since
these are signed integers), and output it immediately. It's just-in-time
sampling, so as long as DSP v Coprocessor do not drift very far, it
should have very low latency. And I make the CPU sync DSP and
Coprocessor once per scanline, which is something like 15 samples or so.
2011-02-03 11:17:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-28 09:51:43 +00:00
|
|
|
signed sample = 0;
|
Update to v075r05 release.
byuu says:
Added Game Boy sound emulation, all four channels.
It's really, really, really bad. Plenty of bugs, I don't even know what
the fuck a high-pass filter is so that isn't there. Hermite resampling
from 4MHz down to 44KHz. But it's tolerable.
I don't understand what sweep is for at all, and I'm sure I have that
insane recursive reload behavior wrong.
This is pretty much my own design. I referenced blargg's gb snd emu,
blargg's older gb apu ref, Cydrak's APU core, that lousy gbdev wiki
article, the completely and utterly worthless pandocs, and received
nothing but bad and wrong information that just wasted my time from
But I managed to pull it off. It's also painfully slow, like 250fps on
my machine slow. Countless optimizations are possible.
2011-02-02 10:38:28 +00:00
|
|
|
sample += apu.square1.output;
|
|
|
|
sample += apu.square2.output;
|
|
|
|
sample += apu.wave.output;
|
|
|
|
sample += apu.noise.output;
|
2011-10-28 09:51:43 +00:00
|
|
|
center = (sample * 512) - 16384;
|
Update to v075r06 release.
byuu says:
Removed the floating-point volume adjustments from the wave channel and
the left/right speaker mixers. Also, against my better judgment I'm
backing out of left/right computation when they are both turned off.
This basically makes non-stereo games run faster, but will make stereo
games appear to run slower. I don't like it when end-users experience
mystery slowdowns.
Anyway, it appears that the audio calculation is really fucking
demanding. Knocks FPS from 800 down to 300. I thought it might be libco,
so I took it out and it only went up to 305fps o.O
There is also some sort of problem with bsnes/Super Game Boy audio. The
latency is really great when you first start, but it seems to drift
apart over time until it is well over 500ms, and then it either pops or
fades back to very low, sub-50ms latency again. The way I handle mixing
is that the coprocessor audio samples go into a resampler to the native
SNES rate, and fed to an output buffer. SNES audio samples go there
untouched. When there is a sample in each, I add them together and
average the result (I still don't understand why we divide by two since
these are signed integers), and output it immediately. It's just-in-time
sampling, so as long as DSP v Coprocessor do not drift very far, it
should have very low latency. And I make the CPU sync DSP and
Coprocessor once per scanline, which is something like 15 samples or so.
2011-02-03 11:17:35 +00:00
|
|
|
|
Update to v075r05 release.
byuu says:
Added Game Boy sound emulation, all four channels.
It's really, really, really bad. Plenty of bugs, I don't even know what
the fuck a high-pass filter is so that isn't there. Hermite resampling
from 4MHz down to 44KHz. But it's tolerable.
I don't understand what sweep is for at all, and I'm sure I have that
insane recursive reload behavior wrong.
This is pretty much my own design. I referenced blargg's gb snd emu,
blargg's older gb apu ref, Cydrak's APU core, that lousy gbdev wiki
article, the completely and utterly worthless pandocs, and received
nothing but bad and wrong information that just wasted my time from
But I managed to pull it off. It's also painfully slow, like 250fps on
my machine slow. Countless optimizations are possible.
2011-02-02 10:38:28 +00:00
|
|
|
sample = 0;
|
2011-10-28 09:51:43 +00:00
|
|
|
if(channel1_left_enable) sample += apu.square1.output;
|
|
|
|
if(channel2_left_enable) sample += apu.square2.output;
|
|
|
|
if(channel3_left_enable) sample += apu.wave.output;
|
|
|
|
if(channel4_left_enable) sample += apu.noise.output;
|
2012-04-07 08:17:49 +00:00
|
|
|
sample = (sample * 512) - 16384;
|
2013-12-10 12:12:54 +00:00
|
|
|
sample = (sample * (left_volume + 1)) / 8;
|
|
|
|
left = sample;
|
2011-02-02 10:37:31 +00:00
|
|
|
|
Update to v075r05 release.
byuu says:
Added Game Boy sound emulation, all four channels.
It's really, really, really bad. Plenty of bugs, I don't even know what
the fuck a high-pass filter is so that isn't there. Hermite resampling
from 4MHz down to 44KHz. But it's tolerable.
I don't understand what sweep is for at all, and I'm sure I have that
insane recursive reload behavior wrong.
This is pretty much my own design. I referenced blargg's gb snd emu,
blargg's older gb apu ref, Cydrak's APU core, that lousy gbdev wiki
article, the completely and utterly worthless pandocs, and received
nothing but bad and wrong information that just wasted my time from
But I managed to pull it off. It's also painfully slow, like 250fps on
my machine slow. Countless optimizations are possible.
2011-02-02 10:38:28 +00:00
|
|
|
sample = 0;
|
2011-10-28 09:51:43 +00:00
|
|
|
if(channel1_right_enable) sample += apu.square1.output;
|
|
|
|
if(channel2_right_enable) sample += apu.square2.output;
|
|
|
|
if(channel3_right_enable) sample += apu.wave.output;
|
|
|
|
if(channel4_right_enable) sample += apu.noise.output;
|
2012-04-07 08:17:49 +00:00
|
|
|
sample = (sample * 512) - 16384;
|
|
|
|
sample = (sample * (right_volume + 1)) / 8;
|
|
|
|
right = sample;
|
2013-12-10 12:12:54 +00:00
|
|
|
|
|
|
|
//reduce audio volume
|
|
|
|
center >>= 1;
|
|
|
|
left >>= 1;
|
|
|
|
right >>= 1;
|
2011-02-02 10:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void APU::Master::write(unsigned r, uint8 data) {
|
2011-09-05 03:48:23 +00:00
|
|
|
if(r == 0) { //$ff24 NR50
|
|
|
|
left_in_enable = data & 0x80;
|
|
|
|
left_volume = (data >> 4) & 7;
|
|
|
|
right_in_enable = data & 0x08;
|
|
|
|
right_volume = (data >> 0) & 7;
|
2011-02-02 10:37:31 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 03:48:23 +00:00
|
|
|
if(r == 1) { //$ff25 NR51
|
Update to v075r05 release.
byuu says:
Added Game Boy sound emulation, all four channels.
It's really, really, really bad. Plenty of bugs, I don't even know what
the fuck a high-pass filter is so that isn't there. Hermite resampling
from 4MHz down to 44KHz. But it's tolerable.
I don't understand what sweep is for at all, and I'm sure I have that
insane recursive reload behavior wrong.
This is pretty much my own design. I referenced blargg's gb snd emu,
blargg's older gb apu ref, Cydrak's APU core, that lousy gbdev wiki
article, the completely and utterly worthless pandocs, and received
nothing but bad and wrong information that just wasted my time from
But I managed to pull it off. It's also painfully slow, like 250fps on
my machine slow. Countless optimizations are possible.
2011-02-02 10:38:28 +00:00
|
|
|
channel4_left_enable = data & 0x80;
|
|
|
|
channel3_left_enable = data & 0x40;
|
|
|
|
channel2_left_enable = data & 0x20;
|
|
|
|
channel1_left_enable = data & 0x10;
|
|
|
|
channel4_right_enable = data & 0x08;
|
|
|
|
channel3_right_enable = data & 0x04;
|
|
|
|
channel2_right_enable = data & 0x02;
|
|
|
|
channel1_right_enable = data & 0x01;
|
2011-02-02 10:37:31 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 03:48:23 +00:00
|
|
|
if(r == 2) { //$ff26 NR52
|
2011-02-02 10:37:31 +00:00
|
|
|
enable = data & 0x80;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void APU::Master::power() {
|
2011-09-05 03:48:23 +00:00
|
|
|
left_in_enable = 0;
|
Update to v075r05 release.
byuu says:
Added Game Boy sound emulation, all four channels.
It's really, really, really bad. Plenty of bugs, I don't even know what
the fuck a high-pass filter is so that isn't there. Hermite resampling
from 4MHz down to 44KHz. But it's tolerable.
I don't understand what sweep is for at all, and I'm sure I have that
insane recursive reload behavior wrong.
This is pretty much my own design. I referenced blargg's gb snd emu,
blargg's older gb apu ref, Cydrak's APU core, that lousy gbdev wiki
article, the completely and utterly worthless pandocs, and received
nothing but bad and wrong information that just wasted my time from
But I managed to pull it off. It's also painfully slow, like 250fps on
my machine slow. Countless optimizations are possible.
2011-02-02 10:38:28 +00:00
|
|
|
left_volume = 0;
|
2011-09-05 03:48:23 +00:00
|
|
|
right_in_enable = 0;
|
Update to v075r05 release.
byuu says:
Added Game Boy sound emulation, all four channels.
It's really, really, really bad. Plenty of bugs, I don't even know what
the fuck a high-pass filter is so that isn't there. Hermite resampling
from 4MHz down to 44KHz. But it's tolerable.
I don't understand what sweep is for at all, and I'm sure I have that
insane recursive reload behavior wrong.
This is pretty much my own design. I referenced blargg's gb snd emu,
blargg's older gb apu ref, Cydrak's APU core, that lousy gbdev wiki
article, the completely and utterly worthless pandocs, and received
nothing but bad and wrong information that just wasted my time from
But I managed to pull it off. It's also painfully slow, like 250fps on
my machine slow. Countless optimizations are possible.
2011-02-02 10:38:28 +00:00
|
|
|
right_volume = 0;
|
|
|
|
channel4_left_enable = 0;
|
|
|
|
channel3_left_enable = 0;
|
|
|
|
channel2_left_enable = 0;
|
|
|
|
channel1_left_enable = 0;
|
|
|
|
channel4_right_enable = 0;
|
|
|
|
channel3_right_enable = 0;
|
|
|
|
channel2_right_enable = 0;
|
|
|
|
channel1_right_enable = 0;
|
2011-02-02 10:37:31 +00:00
|
|
|
enable = 0;
|
Update to v075r05 release.
byuu says:
Added Game Boy sound emulation, all four channels.
It's really, really, really bad. Plenty of bugs, I don't even know what
the fuck a high-pass filter is so that isn't there. Hermite resampling
from 4MHz down to 44KHz. But it's tolerable.
I don't understand what sweep is for at all, and I'm sure I have that
insane recursive reload behavior wrong.
This is pretty much my own design. I referenced blargg's gb snd emu,
blargg's older gb apu ref, Cydrak's APU core, that lousy gbdev wiki
article, the completely and utterly worthless pandocs, and received
nothing but bad and wrong information that just wasted my time from
But I managed to pull it off. It's also painfully slow, like 250fps on
my machine slow. Countless optimizations are possible.
2011-02-02 10:38:28 +00:00
|
|
|
|
|
|
|
center = 0;
|
|
|
|
left = 0;
|
|
|
|
right = 0;
|
2013-12-11 11:19:17 +00:00
|
|
|
|
|
|
|
center_bias = 0;
|
|
|
|
left_bias = 0;
|
|
|
|
right_bias = 0;
|
2011-02-02 10:37:31 +00:00
|
|
|
}
|
|
|
|
|
2013-05-05 09:21:30 +00:00
|
|
|
void APU::Master::serialize(serializer& s) {
|
2011-09-05 03:48:23 +00:00
|
|
|
s.integer(left_in_enable);
|
Update to v075r05 release.
byuu says:
Added Game Boy sound emulation, all four channels.
It's really, really, really bad. Plenty of bugs, I don't even know what
the fuck a high-pass filter is so that isn't there. Hermite resampling
from 4MHz down to 44KHz. But it's tolerable.
I don't understand what sweep is for at all, and I'm sure I have that
insane recursive reload behavior wrong.
This is pretty much my own design. I referenced blargg's gb snd emu,
blargg's older gb apu ref, Cydrak's APU core, that lousy gbdev wiki
article, the completely and utterly worthless pandocs, and received
nothing but bad and wrong information that just wasted my time from
But I managed to pull it off. It's also painfully slow, like 250fps on
my machine slow. Countless optimizations are possible.
2011-02-02 10:38:28 +00:00
|
|
|
s.integer(left_volume);
|
2011-09-05 03:48:23 +00:00
|
|
|
s.integer(right_in_enable);
|
Update to v075r05 release.
byuu says:
Added Game Boy sound emulation, all four channels.
It's really, really, really bad. Plenty of bugs, I don't even know what
the fuck a high-pass filter is so that isn't there. Hermite resampling
from 4MHz down to 44KHz. But it's tolerable.
I don't understand what sweep is for at all, and I'm sure I have that
insane recursive reload behavior wrong.
This is pretty much my own design. I referenced blargg's gb snd emu,
blargg's older gb apu ref, Cydrak's APU core, that lousy gbdev wiki
article, the completely and utterly worthless pandocs, and received
nothing but bad and wrong information that just wasted my time from
But I managed to pull it off. It's also painfully slow, like 250fps on
my machine slow. Countless optimizations are possible.
2011-02-02 10:38:28 +00:00
|
|
|
s.integer(right_volume);
|
|
|
|
s.integer(channel4_left_enable);
|
|
|
|
s.integer(channel3_left_enable);
|
|
|
|
s.integer(channel2_left_enable);
|
|
|
|
s.integer(channel1_left_enable);
|
|
|
|
s.integer(channel4_right_enable);
|
|
|
|
s.integer(channel3_right_enable);
|
|
|
|
s.integer(channel2_right_enable);
|
|
|
|
s.integer(channel1_right_enable);
|
2011-02-02 10:37:31 +00:00
|
|
|
s.integer(enable);
|
Update to v075r05 release.
byuu says:
Added Game Boy sound emulation, all four channels.
It's really, really, really bad. Plenty of bugs, I don't even know what
the fuck a high-pass filter is so that isn't there. Hermite resampling
from 4MHz down to 44KHz. But it's tolerable.
I don't understand what sweep is for at all, and I'm sure I have that
insane recursive reload behavior wrong.
This is pretty much my own design. I referenced blargg's gb snd emu,
blargg's older gb apu ref, Cydrak's APU core, that lousy gbdev wiki
article, the completely and utterly worthless pandocs, and received
nothing but bad and wrong information that just wasted my time from
But I managed to pull it off. It's also painfully slow, like 250fps on
my machine slow. Countless optimizations are possible.
2011-02-02 10:38:28 +00:00
|
|
|
|
|
|
|
s.integer(center);
|
|
|
|
s.integer(left);
|
|
|
|
s.integer(right);
|
2013-12-11 11:19:17 +00:00
|
|
|
|
|
|
|
s.integer(center_bias);
|
|
|
|
s.integer(left_bias);
|
|
|
|
s.integer(right_bias);
|
2011-02-02 10:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|