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];
int latchaudio = 0;
int latchL = 0;
int latchR = 0;
BlipBuffer blip;
BlipBuffer blipL, blipR;
void ProcessSound()
{
@ -848,37 +849,53 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
{
int curr = soundbuff[i * 2];
if (curr != latchaudio)
if (curr != latchL)
{
int diff = latchaudio - curr;
latchaudio = curr;
blip.AddDelta(i, diff);
int diff = latchL - curr;
latchL = curr;
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);
for (int i = 0; i < soundoutbuffcontains * 2; i += 2)
soundoutbuff[i + 1] = soundoutbuff[i];
blipL.ReadSamplesLeft(soundoutbuff, soundoutbuffcontains);
blipR.ReadSamplesRight(soundoutbuff, soundoutbuffcontains);
soundbuffcontains = 0;
}
void InitSound()
{
blip = new BlipBuffer(1024);
blip.SetRates(2097152, 44100);
blipL = new BlipBuffer(1024);
blipL.SetRates(2097152, 44100);
blipR = new BlipBuffer(1024);
blipR.SetRates(2097152, 44100);
}
void DisposeSound()
{
if (blip != null)
if (blipL != null)
{
blip.Dispose();
blip = null;
blipL.Dispose();
blipL = null;
}
if (blipR != null)
{
blipR.Dispose();
blipR = null;
}
}