From 9994023f09e29f1d73504ebd0620c27885169eb7 Mon Sep 17 00:00:00 2001 From: Brandon Wright Date: Tue, 5 Feb 2019 19:56:59 -0600 Subject: [PATCH] Allow use of Snes9x-side buffer if needed. --- apu/apu.cpp | 12 ++++++++---- gtk/src/gtk_sound.cpp | 5 ++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/apu/apu.cpp b/apu/apu.cpp index d0c0c049..65d6d2c5 100644 --- a/apu/apu.cpp +++ b/apu/apu.cpp @@ -224,24 +224,28 @@ static void UpdatePlaybackRate(void) } } -bool8 S9xInitSound(int unused, int unused2) +bool8 S9xInitSound(int buffer_ms, int unused2) { // The resampler and spc unit use samples (16-bit short) as arguments. + int buffer_size_samples = MAX_SAMPLE_FRAMES * 2; + if (buffer_ms > 0) + buffer_size_samples = Settings.SoundPlaybackRate * buffer_ms * 2 / 1000; + if (!spc::resampler) { - spc::resampler = new HermiteResampler(MAX_SAMPLE_FRAMES * 2); + spc::resampler = new HermiteResampler(buffer_size_samples); if (!spc::resampler) return (FALSE); } if (!msu::resampler) { - msu::resampler = new HermiteResampler(msu::buffer_size); + msu::resampler = new HermiteResampler(buffer_size_samples * 3 / 2); if (!msu::resampler) return (FALSE); } else - msu::resampler->resize(msu::buffer_size); + msu::resampler->resize(buffer_size_samples * 3 / 2); reset_dsp_output(); diff --git a/gtk/src/gtk_sound.cpp b/gtk/src/gtk_sound.cpp index eeaeab23..ac85728b 100644 --- a/gtk/src/gtk_sound.cpp +++ b/gtk/src/gtk_sound.cpp @@ -144,7 +144,10 @@ S9xPortSoundInit () Settings.SoundPlaybackRate = playback_rates[gui_config->sound_playback_rate]; - S9xInitSound (gui_config->sound_buffer_size, 0); + if (gui_config->sound_driver == sdl_driver) + S9xInitSound(gui_config->sound_buffer_size, 0); + else + S9xInitSound(0, 0); S9xSetSoundMute (false); }