diff --git a/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs b/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs
index 595a260b7b..07585fe52b 100644
--- a/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs
+++ b/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs
@@ -68,19 +68,14 @@ namespace BizHawk.Emulation.Consoles.GB
- uint[] videoscratch = new uint[160 * 144];
public void FrameAdvance(bool render)
{
uint nsamp = 35112;
- LibGambatte.gambatte_runfor(GambatteState, videoscratch, 160, soundbuff, ref nsamp);
+ LibGambatte.gambatte_runfor(GambatteState, VideoBuffer, 160, soundbuff, ref nsamp);
soundbuffcontains = (int)nsamp;
- // can't convert uint[] to int[], so we do this instead
- // TODO: lie in the p/invoke layer and claim unsigned* is really int*
-
- Buffer.BlockCopy(videoscratch, 0, VideoBuffer, 0, VideoBuffer.Length * sizeof(int));
}
public int Frame
@@ -173,6 +168,7 @@ namespace BizHawk.Emulation.Consoles.GB
{
LibGambatte.gambatte_destroy(GambatteState);
GambatteState = IntPtr.Zero;
+ DisposeSound();
}
#region IVideoProvider
@@ -230,15 +226,15 @@ namespace BizHawk.Emulation.Consoles.GB
resampler = new Sound.Utilities.SpeexResampler(2, 2097152, 44100, 2097152, 44100, metaspu.buffer.enqueue_samples);
}
+ void DisposeSound()
+ {
+ resampler.Dispose();
+ resampler = null;
+ }
+
public void GetSamples(short[] samples)
{
resampler.EnqueueSamples(soundbuff, soundbuffcontains);
- //for (int i = 0; soundbuffcontains >= 0; soundbuffcontains--)
- //{
- // resampler.EnqueueSample(soundbuff[i], soundbuff[i + 1]);
- // i += 2;
- //}
-
soundbuffcontains = 0;
resampler.Flush();
metaspu.GetSamples(samples);
diff --git a/BizHawk.Emulation/Consoles/Nintendo/Gameboy/LibGambatte.cs b/BizHawk.Emulation/Consoles/Nintendo/Gameboy/LibGambatte.cs
index 5737e73626..b2f5822a67 100644
--- a/BizHawk.Emulation/Consoles/Nintendo/Gameboy/LibGambatte.cs
+++ b/BizHawk.Emulation/Consoles/Nintendo/Gameboy/LibGambatte.cs
@@ -67,7 +67,7 @@ namespace BizHawk.Emulation.Consoles.GB
/// in: number of stereo samples to produce, out: actual number of samples produced
/// sample number at which the video frame was produced. -1 means no frame was produced.
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
- public static extern int gambatte_runfor(IntPtr core, uint[] videobuf, int pitch, short[] soundbuf, ref uint samples);
+ public static extern int gambatte_runfor(IntPtr core, int[] videobuf, int pitch, short[] soundbuf, ref uint samples);
///
/// Reset to initial state.
@@ -162,7 +162,7 @@ namespace BizHawk.Emulation.Consoles.GB
/// distance in number of pixels (not bytes) from the start of one line to the next in videoBuf.
///
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
- public static extern bool gambatte_savestate(IntPtr core, uint[] videobuf, int pitch);
+ public static extern bool gambatte_savestate(IntPtr core, int[] videobuf, int pitch);
///
/// Loads emulator state from the state slot selected with selectState().
@@ -181,7 +181,7 @@ namespace BizHawk.Emulation.Consoles.GB
///
/// success
[DllImport("libgambatte.dll", CallingConvention = CallingConvention.Cdecl)]
- public static extern bool gambatte_savestate_file(IntPtr core, uint[] videobuf, int pitch, string filepath);
+ public static extern bool gambatte_savestate_file(IntPtr core, int[] videobuf, int pitch, string filepath);
///
/// Loads emulator state from the file given by 'filepath'.