diff --git a/BizHawk.Emulation.Common/Sound/Utilities/SpeexResampler.cs b/BizHawk.Emulation.Common/Sound/Utilities/SpeexResampler.cs index 9788538812..35d48c9880 100644 --- a/BizHawk.Emulation.Common/Sound/Utilities/SpeexResampler.cs +++ b/BizHawk.Emulation.Common/Sound/Utilities/SpeexResampler.cs @@ -19,14 +19,20 @@ namespace BizHawk.Emulation.Common // TODO: this size is roughly based on how big you can make the buffer before the snes resampling (32040.5 -> 44100) gets screwed up private readonly short[] _inbuf = new short[512]; // [8192]; // [512]; + /// + /// quality of the resampler. values other than those listed are valid, provided they are between MIN and MAX + /// + public enum Quality : int + { + QUALITY_MAX = 10, + QUALITY_MIN = 0, + QUALITY_DEFAULT = 4, + QUALITY_VOIP = 3, + QUALITY_DESKTOP = 5, + } + private static class LibSpeexDSP { - public const int QUALITY_MAX = 10; - public const int QUALITY_MIN = 0; - public const int QUALITY_DEFAULT = 4; - public const int QUALITY_VOIP = 3; - public const int QUALITY_DESKTOP = 5; - public enum RESAMPLER_ERR { SUCCESS = 0, @@ -47,7 +53,7 @@ namespace BizHawk.Emulation.Common /// The error state /// Newly created resampler state [DllImport("libspeexdsp.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr speex_resampler_init(uint nb_channels, uint in_rate, uint out_rate, int quality, ref RESAMPLER_ERR err); + public static extern IntPtr speex_resampler_init(uint nb_channels, uint in_rate, uint out_rate, Quality quality, ref RESAMPLER_ERR err); /// /// Create a new resampler with fractional input/output rates. The sampling @@ -63,7 +69,7 @@ namespace BizHawk.Emulation.Common /// The error state /// Newly created resampler state [DllImport("libspeexdsp.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr speex_resampler_init_frac(uint nb_channels, uint ratio_num, uint ratio_den, uint in_rate, uint out_rate, int quality, ref RESAMPLER_ERR err); + public static extern IntPtr speex_resampler_init_frac(uint nb_channels, uint ratio_num, uint ratio_den, uint in_rate, uint out_rate, Quality quality, ref RESAMPLER_ERR err); /// /// Destroy a resampler state. @@ -162,7 +168,7 @@ namespace BizHawk.Emulation.Common /// Resampler state /// Resampling quality between 0 and 10, where 0 has poor quality and 10 has very high quality. [DllImport("libspeexdsp.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern RESAMPLER_ERR speex_resampler_set_quality(IntPtr st, int quality); + public static extern RESAMPLER_ERR speex_resampler_set_quality(IntPtr st, Quality quality); /// /// Get the conversion quality. @@ -170,7 +176,7 @@ namespace BizHawk.Emulation.Common /// Resampler state /// Resampling quality between 0 and 10, where 0 has poor quality and 10 has very high quality. [DllImport("libspeexdsp.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern void speex_resampler_get_quality(IntPtr st, ref int quality); + public static extern void speex_resampler_get_quality(IntPtr st, ref Quality quality); /// /// Set (change) the input stride. @@ -294,7 +300,7 @@ namespace BizHawk.Emulation.Common /// sampling rate out, rounded to nearest hz /// function which accepts output as produced. if null, act as an /// source to take input from when output is requested. if null, no auto-fetching - public SpeexResampler(int quality, uint rationum, uint ratioden, uint sratein, uint srateout, Action drainer = null, ISoundProvider input = null) + public SpeexResampler(Quality quality, uint rationum, uint ratioden, uint sratein, uint srateout, Action drainer = null, ISoundProvider input = null) { if (drainer != null && input != null) { diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/7800/Atari7800.cs b/BizHawk.Emulation.Cores/Consoles/Atari/7800/Atari7800.cs index 3fb84cf2f8..549a0ec63d 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/7800/Atari7800.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/7800/Atari7800.cs @@ -232,7 +232,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari7800 // really shouldn't happen (after init), but if it does, we're ready if (resampler != null) resampler.Dispose(); - resampler = new SpeexResampler(3, newsamplerate, 44100, newsamplerate, 44100, null, null); + resampler = new SpeexResampler((SpeexResampler.Quality)3, newsamplerate, 44100, newsamplerate, 44100, null, null); samplerate = newsamplerate; dcfilter = new DCFilter(256); } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64Audio.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64Audio.cs index 8bb58fe039..2e71ffec95 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64Audio.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64Audio.cs @@ -48,7 +48,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 this.api = new mupen64plusAudioApi(core); _samplingRate = api.GetSamplingRate(); - Resampler = new SpeexResampler(6, SamplingRate, 44100, + Resampler = new SpeexResampler((SpeexResampler.Quality)6, SamplingRate, 44100, SamplingRate, 44100); coreAPI = core; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs index 924973f3d8..435059f28b 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs @@ -546,7 +546,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES private void InitAudio() { - _resampler = new SpeexResampler(6, 64081, 88200, 32041, 44100); + _resampler = new SpeexResampler((SpeexResampler.Quality)6, 64081, 88200, 32041, 44100); } private void snes_audio_sample(ushort left, ushort right) diff --git a/BizHawk.Emulation.Cores/Libretro/LibretroCore.cs b/BizHawk.Emulation.Cores/Libretro/LibretroCore.cs index 9c5c911102..e1c208f315 100644 --- a/BizHawk.Emulation.Cores/Libretro/LibretroCore.cs +++ b/BizHawk.Emulation.Cores/Libretro/LibretroCore.cs @@ -233,7 +233,7 @@ namespace BizHawk.Emulation.Cores.Libretro uint spsnum = (uint)sps * 1000; uint spsden = (uint)1000; - resampler = new SpeexResampler(5, 44100 * spsden, spsnum, (uint)sps, 44100, null, null); + resampler = new SpeexResampler(SpeexResampler.Quality.QUALITY_DESKTOP, 44100 * spsden, spsnum, (uint)sps, 44100, null, null); } //TODO: handle these in c++ (queue there and blast after frameadvance to c#)