From 8b186f6fa4d58f0d37187d3fd5c1ca6509e1e8f3 Mon Sep 17 00:00:00 2001 From: goyuken Date: Wed, 11 Dec 2013 04:01:33 +0000 Subject: [PATCH] a bit of cleanup in speex resampler and yabooze core --- .../Sound/Utilities/SpeexResampler.cs | 6 +++--- .../Consoles/Sega/Saturn/FilePiping.cs | 16 +++++++-------- .../Consoles/Sega/Saturn/Yabause.cs | 20 +++++-------------- 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/BizHawk.Emulation.Common/Sound/Utilities/SpeexResampler.cs b/BizHawk.Emulation.Common/Sound/Utilities/SpeexResampler.cs index 127c98caf2..7dd47c42b3 100644 --- a/BizHawk.Emulation.Common/Sound/Utilities/SpeexResampler.cs +++ b/BizHawk.Emulation.Common/Sound/Utilities/SpeexResampler.cs @@ -311,6 +311,9 @@ namespace BizHawk.Emulation.Common /// source to take input from when output is requested. if null, no autofetching public SpeexResampler(int quality, uint rationum, uint ratioden, uint sratein, uint srateout, Action drainer = null, ISyncSoundProvider input = null) { + if (drainer != null && input != null) + throw new ArgumentException("Can't autofetch without being an ISyncSoundProvider?"); + LibSpeexDSP.RESAMPLER_ERR err = LibSpeexDSP.RESAMPLER_ERR.SUCCESS; st = LibSpeexDSP.speex_resampler_init_frac(2, rationum, ratioden, sratein, srateout, quality, ref err); @@ -319,9 +322,6 @@ namespace BizHawk.Emulation.Common CheckError(err); - if (drainer != null && input != null) - throw new ArgumentException("Can't autofetch without being an ISyncSoundProvider?"); - this.drainer = drainer ?? InternalDrain; this.input = input; diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/Saturn/FilePiping.cs b/BizHawk.Emulation.Cores/Consoles/Sega/Saturn/FilePiping.cs index e70af62716..7412d3207d 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/Saturn/FilePiping.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/Saturn/FilePiping.cs @@ -41,9 +41,9 @@ namespace BizHawk.Emulation.Cores.Sega.Saturn public void Get(Stream s) { if (thr != null) - throw new Exception("Can only serve one thing at a time!"); + throw new InvalidOperationException("Can only serve one thing at a time!"); if (e != null) - throw new Exception("Previous attempt failed!", e); + throw new InvalidOperationException("Previous attempt failed!", e); if (!s.CanWrite) throw new ArgumentException("Stream must be readable!"); @@ -74,9 +74,9 @@ namespace BizHawk.Emulation.Cores.Sega.Saturn public void Offer(Stream s) { if (thr != null) - throw new Exception("Can only serve one thing at a time!"); + throw new InvalidOperationException("Can only serve one thing at a time!"); if (e != null) - throw new Exception("Previous attempt failed!", e); + throw new InvalidOperationException("Previous attempt failed!", e); if (!s.CanRead) throw new ArgumentException("Stream must be readable!"); @@ -104,15 +104,15 @@ namespace BizHawk.Emulation.Cores.Sega.Saturn } } - public Exception GetResults() + public void Finish() { if (thr == null) - throw new Exception("No pending!"); + throw new InvalidOperationException("No pending!"); thr.Join(); thr = null; Exception ret = e; - e = null; - return ret; + if (ret != null) + throw ret; } } } diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/Saturn/Yabause.cs b/BizHawk.Emulation.Cores/Consoles/Sega/Saturn/Yabause.cs index 41d1135b8b..37bef201ad 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/Saturn/Yabause.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/Saturn/Yabause.cs @@ -79,9 +79,7 @@ namespace BizHawk.Emulation.Cores.Sega.Saturn if (!LibYabause.libyabause_init(ref CDInt, BiosPipe, GL)) throw new Exception("libyabause_init() failed!"); - var e = fp.GetResults(); - if (e != null) - throw e; + fp.Finish(); LibYabause.libyabause_setvidbuff(VideoHandle.AddrOfPinnedObject()); LibYabause.libyabause_setsndbuff(SoundHandle.AddrOfPinnedObject()); @@ -250,9 +248,7 @@ namespace BizHawk.Emulation.Cores.Sega.Saturn var fp = new FilePiping(); fp.Get(ms); bool success = LibYabause.libyabause_savesaveram(fp.GetPipeNameNative()); - var e = fp.GetResults(); - if (e != null) - throw e; + fp.Finish(); if (!success) throw new Exception("libyabause_savesaveram() failed!"); var ret = ms.ToArray(); @@ -273,9 +269,7 @@ namespace BizHawk.Emulation.Cores.Sega.Saturn var fp = new FilePiping(); fp.Offer(data); bool success = LibYabause.libyabause_loadsaveram(fp.GetPipeNameNative()); - var e = fp.GetResults(); - if (e != null) - throw e; + fp.Finish(); if (!success) throw new Exception("libyabause_loadsaveram() failed!"); } @@ -321,9 +315,7 @@ namespace BizHawk.Emulation.Cores.Sega.Saturn var fp = new FilePiping(); fp.Offer(data); bool succeed = LibYabause.libyabause_loadstate(fp.GetPipeNameNative()); - var e = fp.GetResults(); - if (e != null) - throw e; + fp.Finish(); if (!succeed) throw new Exception("libyabause_loadstate() failed"); } @@ -334,9 +326,7 @@ namespace BizHawk.Emulation.Cores.Sega.Saturn var fp = new FilePiping(); fp.Get(ms); bool succeed = LibYabause.libyabause_savestate(fp.GetPipeNameNative()); - var e = fp.GetResults(); - if (e != null) - throw e; + fp.Finish(); var ret = ms.ToArray(); ms.Close(); if (!succeed)