diff --git a/Assets/dll/libgambatte.dll b/Assets/dll/libgambatte.dll index b567791816..61d08c5d09 100644 Binary files a/Assets/dll/libgambatte.dll and b/Assets/dll/libgambatte.dll differ diff --git a/Assets/dll/libgambatte.so b/Assets/dll/libgambatte.so index aeb5785bc7..a5ec2966fd 100644 Binary files a/Assets/dll/libgambatte.so and b/Assets/dll/libgambatte.so differ diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IEmulator.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IEmulator.cs index c682106145..4810f4abc4 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IEmulator.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IEmulator.cs @@ -124,9 +124,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy if (IsSgb) { - ProcessSgbSound((int)samplesEmittedInFrame, (rendersound && !Muted)); + ProcessSgbSound((int)samplesEmittedInFrame, rendersound && !Muted); } + ProcessMbcSound(rendersound && !Muted); + if (rendersound && !Muted) { ProcessSoundEnd(); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.ISoundProvider.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.ISoundProvider.cs index 5b29b38f60..2e677d0899 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.ISoundProvider.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.ISoundProvider.cs @@ -39,6 +39,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy // sample pairs before resampling private readonly short[] _soundbuff = new short[(35112 + 2064) * 2]; private readonly short[] _sgbsoundbuff = new short[2048 * 2]; + private readonly short[] _mbcsoundbuff = new short[(35112 + 2064) * 2]; private int _soundoutbuffcontains = 0; @@ -50,6 +51,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy private int _sgbLatchL = 0; private int _sgbLatchR = 0; + private int _mbcLatchL = 0; + private int _mbcLatchR = 0; + private BlipBuffer _blipL, _blipR; private uint _blipAccumulate; @@ -104,6 +108,31 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy } } + private void ProcessMbcSound(bool processSound) + { + int nsamp = LibGambatte.gambatte_generatembcsamples(GambatteState, _mbcsoundbuff); + if (nsamp == 0) + { + return; + } + + for (uint i = 0; i < nsamp; i++) + { + int ls = _mbcsoundbuff[i * 2] - _mbcLatchL; + int rs = _mbcsoundbuff[(i * 2) + 1] - _mbcLatchR; + if (ls != 0 && processSound) + { + _blipL.AddDelta(i, ls); + } + if (rs != 0 && processSound) + { + _blipR.AddDelta(i, rs); + } + _mbcLatchL = _mbcsoundbuff[i * 2]; + _mbcLatchR = _mbcsoundbuff[(i * 2) + 1]; + } + } + private void ProcessSoundEnd() { _blipL.EndFrame(_blipAccumulate); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/LibGambatte.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/LibGambatte.cs index 2f17030c35..561da8e066 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/LibGambatte.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/LibGambatte.cs @@ -100,6 +100,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy [DllImport("libgambatte", CallingConvention = CallingConvention.Cdecl)] public static extern int gambatte_generatesgbsamples(IntPtr core, short[] soundbuf, out uint samples); + [DllImport("libgambatte", CallingConvention = CallingConvention.Cdecl)] + public static extern int gambatte_generatembcsamples(IntPtr core, short[] soundbuf); + /// /// Reset to initial state. /// Equivalent to reloading a ROM image, or turning a Game Boy Color off and on again. diff --git a/submodules/gambatte b/submodules/gambatte index 098d085fc4..a89db5c3e6 160000 --- a/submodules/gambatte +++ b/submodules/gambatte @@ -1 +1 @@ -Subproject commit 098d085fc432de2f88846398c6a2771283f25b34 +Subproject commit a89db5c3e68aed4a79645a12f9ae9b1fc1e9d980