i did not know that the gameboy had stereo audio

This commit is contained in:
goyuken 2014-03-05 05:03:13 +00:00
parent b2eef124e2
commit dbe0106814
1 changed files with 34 additions and 17 deletions

View File

@ -838,9 +838,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
short[] soundoutbuff = new short[2048]; short[] soundoutbuff = new short[2048];
int latchaudio = 0; int latchL = 0;
int latchR = 0;
BlipBuffer blip; BlipBuffer blipL, blipR;
void ProcessSound() void ProcessSound()
{ {
@ -848,37 +849,53 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
{ {
int curr = soundbuff[i * 2]; int curr = soundbuff[i * 2];
if (curr != latchaudio) if (curr != latchL)
{ {
int diff = latchaudio - curr; int diff = latchL - curr;
latchaudio = curr; latchL = curr;
blip.AddDelta(i, diff); blipL.AddDelta(i, diff);
}
curr = soundbuff[i * 2 + 1];
if (curr != latchR)
{
int diff = latchR - curr;
latchR = curr;
blipR.AddDelta(i, diff);
} }
} }
blip.EndFrame((uint)soundbuffcontains); blipL.EndFrame((uint)soundbuffcontains);
blipR.EndFrame((uint)soundbuffcontains);
soundoutbuffcontains = blip.SamplesAvailable(); soundoutbuffcontains = blipL.SamplesAvailable();
if (soundoutbuffcontains != blipR.SamplesAvailable())
throw new Exception("Audio processing error");
blip.ReadSamples(soundoutbuff, soundoutbuffcontains, true); blipL.ReadSamplesLeft(soundoutbuff, soundoutbuffcontains);
for (int i = 0; i < soundoutbuffcontains * 2; i += 2) blipR.ReadSamplesRight(soundoutbuff, soundoutbuffcontains);
soundoutbuff[i + 1] = soundoutbuff[i];
soundbuffcontains = 0; soundbuffcontains = 0;
} }
void InitSound() void InitSound()
{ {
blip = new BlipBuffer(1024); blipL = new BlipBuffer(1024);
blip.SetRates(2097152, 44100); blipL.SetRates(2097152, 44100);
blipR = new BlipBuffer(1024);
blipR.SetRates(2097152, 44100);
} }
void DisposeSound() void DisposeSound()
{ {
if (blip != null) if (blipL != null)
{ {
blip.Dispose(); blipL.Dispose();
blip = null; blipL = null;
}
if (blipR != null)
{
blipR.Dispose();
blipR = null;
} }
} }