remove unnecessary extra video buffer in gambatte wrapper, and dispose of resampler properly

This commit is contained in:
goyuken 2012-09-09 13:35:58 +00:00
parent 2628e500d7
commit 3acc87c013
2 changed files with 11 additions and 15 deletions

View File

@ -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);

View File

@ -67,7 +67,7 @@ namespace BizHawk.Emulation.Consoles.GB
/// <param name="samples">in: number of stereo samples to produce, out: actual number of samples produced</param>
/// <returns>sample number at which the video frame was produced. -1 means no frame was produced.</returns>
[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);
/// <summary>
/// Reset to initial state.
@ -162,7 +162,7 @@ namespace BizHawk.Emulation.Consoles.GB
/// <param name="pitch">distance in number of pixels (not bytes) from the start of one line to the next in videoBuf.</param>
/// <returns></returns>
[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);
/// <summary>
/// Loads emulator state from the state slot selected with selectState().
@ -181,7 +181,7 @@ namespace BizHawk.Emulation.Consoles.GB
/// <param name="filepath"></param>
/// <returns>success</returns>
[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);
/// <summary>
/// Loads emulator state from the file given by 'filepath'.