Gameboy - fixed frame timing but broke sound
This commit is contained in:
parent
9d7c92fb6e
commit
fea60dfbbe
|
@ -221,8 +221,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
|
||||||
endofframecallback(LibGambatte.gambatte_cpuread(GambatteState, 0xff40));
|
endofframecallback(LibGambatte.gambatte_cpuread(GambatteState, 0xff40));
|
||||||
}
|
}
|
||||||
|
|
||||||
ulong _cycleCount = 0;
|
private ulong _cycleCount = 0;
|
||||||
uint _nextRunAdjust = 0;
|
private uint frameOverflow = 0;
|
||||||
|
private const uint TICKSINFRAME = 35112;
|
||||||
|
|
||||||
public ulong CycleCount { get { return _cycleCount; } }
|
public ulong CycleCount { get { return _cycleCount; } }
|
||||||
|
|
||||||
|
@ -230,18 +231,17 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
|
||||||
{
|
{
|
||||||
FrameAdvancePrep();
|
FrameAdvancePrep();
|
||||||
|
|
||||||
uint nsamp = 35112 + _nextRunAdjust; // according to gambatte docs, this is the nominal length of a frame in 2mhz clocks
|
while (true)
|
||||||
|
{
|
||||||
|
uint samplesEmitted = TICKSINFRAME - frameOverflow; // according to gambatte docs, this is the nominal length of a frame in 2mhz clocks
|
||||||
|
LibGambatte.gambatte_runfor(GambatteState, VideoBuffer, 160, soundbuff, ref samplesEmitted);
|
||||||
|
|
||||||
// Gambatte is going to run whatever it feels like, and report what it ran into nsamp
|
_cycleCount += (ulong)samplesEmitted;
|
||||||
// Therefore we should track it and factor this in next frame, to keep a consistent definition of 1 frame = 35112 cycles
|
frameOverflow += samplesEmitted;
|
||||||
LibGambatte.gambatte_runfor(GambatteState, VideoBuffer, 160, soundbuff, ref nsamp);
|
|
||||||
|
|
||||||
_cycleCount += (ulong)nsamp;
|
|
||||||
_nextRunAdjust = 35112 - nsamp;
|
|
||||||
|
|
||||||
if (rendersound)
|
if (rendersound)
|
||||||
{
|
{
|
||||||
soundbuffcontains = (int)nsamp;
|
soundbuffcontains = (int)samplesEmitted;
|
||||||
ProcessSound();
|
ProcessSound();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -249,6 +249,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
|
||||||
soundbuffcontains = 0;
|
soundbuffcontains = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (frameOverflow >= TICKSINFRAME)
|
||||||
|
{
|
||||||
|
frameOverflow -= TICKSINFRAME;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FrameAdvancePost();
|
FrameAdvancePost();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -853,7 +860,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
|
||||||
|
|
||||||
BlipBuffer blipL, blipR;
|
BlipBuffer blipL, blipR;
|
||||||
|
|
||||||
void ProcessSound()
|
private void ProcessSound()
|
||||||
{
|
{
|
||||||
for (uint i = 0; i < soundbuffcontains; i++)
|
for (uint i = 0; i < soundbuffcontains; i++)
|
||||||
{
|
{
|
||||||
|
@ -874,6 +881,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
|
||||||
blipR.AddDelta(i, diff);
|
blipR.AddDelta(i, diff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
blipL.EndFrame((uint)soundbuffcontains);
|
blipL.EndFrame((uint)soundbuffcontains);
|
||||||
blipR.EndFrame((uint)soundbuffcontains);
|
blipR.EndFrame((uint)soundbuffcontains);
|
||||||
|
|
||||||
|
@ -919,8 +927,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
|
||||||
samples = soundoutbuff;
|
samples = soundoutbuff;
|
||||||
nsamp = soundoutbuffcontains;
|
nsamp = soundoutbuffcontains;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Settings
|
||||||
|
|
||||||
GambatteSettings Settings;
|
GambatteSettings Settings;
|
||||||
GambatteSyncSettings SyncSettings;
|
GambatteSyncSettings SyncSettings;
|
||||||
|
|
||||||
|
@ -1002,5 +1013,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
|
||||||
return (GambatteSyncSettings)MemberwiseClone();
|
return (GambatteSyncSettings)MemberwiseClone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue