using System; using System.Runtime.InteropServices; namespace BizHawk.Emulation.Cores.Nintendo.N64.NativeApi { class mupen64plusAudioApi { /// /// Handle to native audio plugin /// private IntPtr AudDll; /// /// Gets the size of the mupen64plus audio buffer /// /// The size of the mupen64plus audio buffer [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate int GetBufferSize(); GetBufferSize dllGetBufferSize; /// /// Gets the audio buffer from mupen64plus, and then clears it /// /// The buffer to fill with samples [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void ReadAudioBuffer(short[] dest); ReadAudioBuffer dllReadAudioBuffer; /// /// Gets the current audio rate from mupen64plus /// /// The current audio rate [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate int GetAudioRate(); GetAudioRate dllGetAudioRate; /// /// Loads native functions and attaches itself to the core /// /// Core with loaded core api public mupen64plusAudioApi(mupen64plusApi core) { T GetAudioDelegate(string proc) where T : Delegate => mupen64plusApi.GetTypedDelegate(AudDll, proc); AudDll = core.AttachPlugin(mupen64plusApi.m64p_plugin_type.M64PLUGIN_AUDIO, "mupen64plus-audio-bkm.dll"); // Connect dll functions dllGetBufferSize = GetAudioDelegate("GetBufferSize"); dllReadAudioBuffer = GetAudioDelegate("ReadAudioBuffer"); dllGetAudioRate = GetAudioDelegate("GetAudioRate"); } /// /// Returns currently used sampling rate /// public uint GetSamplingRate() { return (uint)dllGetAudioRate(); } /// /// Returns size of bytes currently in the audio buffer /// public int GetAudioBufferSize() { return dllGetBufferSize(); } /// /// Returns bytes currently in the audiobuffer /// Afterwards audio buffer is cleared /// buffer.Length must be greater than GetAudioBufferSize() /// public void GetAudioBuffer(short[] buffer) { dllReadAudioBuffer(buffer); } } }