diff --git a/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs b/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs index 9c87cf4988..f9d2b72b07 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs @@ -19,7 +19,7 @@ namespace BizHawk.Emulation.Cores.Sony.PSX isPorted: true, isReleased: false )] - public unsafe class Octoshock : IEmulator, IVideoProvider, ISoundProvider + public unsafe class Octoshock : IEmulator, IVideoProvider, ISyncSoundProvider { public string SystemId { get { return "NULL"; } } @@ -54,10 +54,6 @@ namespace BizHawk.Emulation.Cores.Sony.PSX private Random rand = new Random(); public CoreComm CoreComm { get; private set; } public IVideoProvider VideoProvider { get { return this; } } - public ISoundProvider SoundProvider { get { return this; } } - public ISyncSoundProvider SyncSoundProvider { get { return new FakeSyncSound(this, 735); } } - public bool StartAsyncSound() { return true; } - public void EndAsyncSound() { } //we can only have one active core at a time, due to the lib being so static. //so we'll track the current one here and detach the previous one whenever a new one is booted up. @@ -315,6 +311,13 @@ namespace BizHawk.Emulation.Cores.Sony.PSX OctoshockDll.shock_GetFramebuffer(psx, ref fb); //alpha channel is added in c++, right now. wish we didnt have to do it at all } + + fixed (short* samples = sbuff) + { + sbuffcontains = OctoshockDll.shock_GetSamples(null); + if (sbuffcontains * 2 > sbuff.Length) throw new InvalidOperationException("shock_GetSamples returned too many samples: " + sbuffcontains); + OctoshockDll.shock_GetSamples(samples); + } } public ControllerDefinition ControllerDefinition { get { return DualShockController; } } @@ -338,8 +341,29 @@ namespace BizHawk.Emulation.Cores.Sony.PSX public int BufferWidth { get; private set; } public int BufferHeight { get; private set; } public int BackgroundColor { get { return 0; } } - public void GetSamples(short[] samples) { } - public void DiscardSamples() { } - public int MaxVolume { get; set; } + + #region ISoundProvider + + private short[] sbuff = new short[1454*2]; //this is the most ive ever seen.. dont know why + private int sbuffcontains = 0; + + public ISoundProvider SoundProvider { get { throw new InvalidOperationException(); } } + public ISyncSoundProvider SyncSoundProvider { get { return this; } } + public bool StartAsyncSound() { return false; } + public void EndAsyncSound() { } + + public void GetSamples(out short[] samples, out int nsamp) + { + samples = sbuff; + nsamp = sbuffcontains; + } + + public void DiscardSamples() + { + sbuffcontains = 0; + } + + #endregion + } } diff --git a/BizHawk.Emulation.Cores/Consoles/Sony/PSX/OctoshockDll.cs b/BizHawk.Emulation.Cores/Consoles/Sony/PSX/OctoshockDll.cs index f31b9935db..120b9db35d 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sony/PSX/OctoshockDll.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sony/PSX/OctoshockDll.cs @@ -124,4 +124,7 @@ public unsafe static class OctoshockDll [DllImport("octoshock.dll")] public static extern int shock_GetFramebuffer(IntPtr psx, ref ShockFramebufferInfo fb); + + [DllImport("octoshock.dll")] + public static extern int shock_GetSamples(void* buffer); } diff --git a/output/dll/octoshock.dll b/output/dll/octoshock.dll index 5fe5439298..61a314da37 100644 Binary files a/output/dll/octoshock.dll and b/output/dll/octoshock.dll differ diff --git a/psx/octoshock/psx/psx.cpp b/psx/octoshock/psx/psx.cpp index 4abe1f7ecb..8ee22716c7 100644 --- a/psx/octoshock/psx/psx.cpp +++ b/psx/octoshock/psx/psx.cpp @@ -1741,6 +1741,17 @@ void NormalizeFramebuffer() s_FramebufferCurrent = curr; } +EW_EXPORT s32 shock_GetSamples(void* buffer) +{ + //if buffer is NULL, user just wants to know how many samples, so dont do any copying + if(buffer != NULL) + { + memcpy(buffer,espec.SoundBuf,espec.SoundBufSize*4); + } + + return espec.SoundBufSize; +} + EW_EXPORT s32 shock_GetFramebuffer(void* psx, ShockFramebufferInfo* fb) { //if user requires normalization, do it now diff --git a/psx/octoshock/psx/psx.h b/psx/octoshock/psx/psx.h index 8f1a9de946..6dabcf981f 100644 --- a/psx/octoshock/psx/psx.h +++ b/psx/octoshock/psx/psx.h @@ -279,5 +279,8 @@ EW_EXPORT s32 shock_Step(void* psx, eShockStep step); //Fetches the framebuffer. Can retrieve parameters (set the job ptr to NULL) or fill the provided job ptr with the framebuffer (make sure its big enough). //This helps us copy fewer times. -//TODO - support pitch and color format conversion if needed -EW_EXPORT s32 shock_GetFramebuffer(void* psx, ShockFramebufferInfo* fb); \ No newline at end of file +EW_EXPORT s32 shock_GetFramebuffer(void* psx, ShockFramebufferInfo* fb); + +//Returns the queued SPU output (usually ~737 samples per frame) as the normal 16bit interleaved stereo format +//The size of the queue will be returned. Make sure your buffer can handle it. Pass NULL just to get the required size. +EW_EXPORT s32 shock_GetSamples(void* buffer); \ No newline at end of file