2010-08-09 13:28:56 +00:00
|
|
|
#ifdef SYSTEM_CPP
|
|
|
|
|
|
|
|
Audio audio;
|
|
|
|
|
|
|
|
void Audio::coprocessor_enable(bool state) {
|
|
|
|
coprocessor = state;
|
2011-08-20 14:40:44 +00:00
|
|
|
dspaudio.clear();
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
dsp_rdoffset = cop_rdoffset = 0;
|
|
|
|
dsp_wroffset = cop_wroffset = 0;
|
|
|
|
dsp_length = cop_length = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Audio::coprocessor_frequency(double input_frequency) {
|
2011-08-20 14:40:44 +00:00
|
|
|
dspaudio.setFrequency(input_frequency);
|
2011-09-24 09:51:08 +00:00
|
|
|
dspaudio.setResampler(nall::DSP::ResampleEngine::Sinc);
|
2011-08-20 14:40:44 +00:00
|
|
|
dspaudio.setResamplerFrequency(system.apu_frequency() / 768.0);
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2011-09-27 11:55:02 +00:00
|
|
|
void Audio::sample(int16 lsample, int16 rsample) {
|
|
|
|
if(coprocessor == false) return interface->audioSample(lsample, rsample);
|
|
|
|
|
|
|
|
dsp_buffer[dsp_wroffset] = ((uint16)lsample << 0) + ((uint16)rsample << 16);
|
|
|
|
dsp_wroffset = (dsp_wroffset + 1) & buffer_mask;
|
|
|
|
dsp_length = (dsp_length + 1) & buffer_mask;
|
|
|
|
flush();
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2011-09-16 11:44:07 +00:00
|
|
|
void Audio::coprocessor_sample(int16 lsample, int16 rsample) {
|
|
|
|
signed samples[] = { lsample, rsample };
|
|
|
|
dspaudio.sample(samples);
|
2011-08-20 14:40:44 +00:00
|
|
|
while(dspaudio.pending()) {
|
2011-09-16 11:44:07 +00:00
|
|
|
dspaudio.read(samples);
|
2011-08-20 14:40:44 +00:00
|
|
|
|
2011-09-16 11:44:07 +00:00
|
|
|
cop_buffer[cop_wroffset] = ((uint16)samples[0] << 0) + ((uint16)samples[1] << 16);
|
2011-08-20 14:40:44 +00:00
|
|
|
cop_wroffset = (cop_wroffset + 1) & buffer_mask;
|
|
|
|
cop_length = (cop_length + 1) & buffer_mask;
|
|
|
|
flush();
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Audio::init() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void Audio::flush() {
|
|
|
|
while(dsp_length > 0 && cop_length > 0) {
|
|
|
|
uint32 dsp_sample = dsp_buffer[dsp_rdoffset];
|
|
|
|
uint32 cop_sample = cop_buffer[cop_rdoffset];
|
|
|
|
|
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
|
|
|
dsp_rdoffset = (dsp_rdoffset + 1) & buffer_mask;
|
|
|
|
cop_rdoffset = (cop_rdoffset + 1) & buffer_mask;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
dsp_length--;
|
|
|
|
cop_length--;
|
|
|
|
|
2011-09-27 11:55:02 +00:00
|
|
|
signed dsp_left = (int16)(dsp_sample >> 0);
|
|
|
|
signed dsp_right = (int16)(dsp_sample >> 16);
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2011-09-27 11:55:02 +00:00
|
|
|
signed cop_left = (int16)(cop_sample >> 0);
|
|
|
|
signed cop_right = (int16)(cop_sample >> 16);
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2011-09-15 12:41:49 +00:00
|
|
|
interface->audioSample(
|
2010-08-09 13:28:56 +00:00
|
|
|
sclamp<16>((dsp_left + cop_left ) / 2),
|
|
|
|
sclamp<16>((dsp_right + cop_right) / 2)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|