From 803b85343a0e705bc2fbde85335028a3114cafde Mon Sep 17 00:00:00 2001 From: Christian Speckner Date: Sat, 3 Feb 2018 01:23:19 +0100 Subject: [PATCH] Tuning. --- src/common/SoundSDL2.cxx | 12 ++++++++++++ src/common/SoundSDL2.hxx | 4 ++++ src/emucore/Console.cxx | 5 +++-- src/emucore/OSystem.cxx | 2 +- src/emucore/Sound.hxx | 10 ++++++++++ 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/common/SoundSDL2.cxx b/src/common/SoundSDL2.cxx index cefcdfa67..1116d6b48 100644 --- a/src/common/SoundSDL2.cxx +++ b/src/common/SoundSDL2.cxx @@ -219,6 +219,18 @@ void SoundSDL2::adjustVolume(Int8 direction) myOSystem.frameBuffer().showMessage(message); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +uInt32 SoundSDL2::getFragmentSize() const +{ + return myHardwareSpec.size; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +uInt32 SoundSDL2::getSampleRate() const +{ + return myHardwareSpec.freq; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void SoundSDL2::processFragment(Int16* stream, uInt32 length) { diff --git a/src/common/SoundSDL2.hxx b/src/common/SoundSDL2.hxx index 49217a0ed..873ab6032 100644 --- a/src/common/SoundSDL2.hxx +++ b/src/common/SoundSDL2.hxx @@ -96,6 +96,10 @@ class SoundSDL2 : public Sound */ void adjustVolume(Int8 direction) override; + uInt32 getFragmentSize() const override; + + uInt32 getSampleRate() const override; + protected: /** Invoked by the sound callback to process the next sound fragment. diff --git a/src/emucore/Console.cxx b/src/emucore/Console.cxx index b8306b54b..bece24a71 100644 --- a/src/emucore/Console.cxx +++ b/src/emucore/Console.cxx @@ -72,7 +72,6 @@ namespace { constexpr uInt8 YSTART_EXTRA = 2; - constexpr uInt8 AUDIO_QUEUE_CAPACITY_FRAGMENTS = 30; constexpr uInt8 AUDIO_QUEUE_HALF_FRAMES_PER_FRAGMENT = 1; } @@ -722,9 +721,11 @@ void Console::createAudioQueue() throw runtime_error("invalid console timing"); } + uInt32 queueSize = (2 * myOSystem.sound().getFragmentSize() * sampleRate) / (myOSystem.sound().getSampleRate() * fragmentSize); + myAudioQueue = make_shared( fragmentSize, - AUDIO_QUEUE_CAPACITY_FRAGMENTS, + queueSize > 0 ? queueSize : 1, myProperties.get(Cartridge_Sound) == "STEREO", sampleRate ); diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index 26ba9ed9d..93d21928e 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -600,7 +600,7 @@ void OSystem::mainLoop() virtualTime += duration_cast(timeslice); time_point now = high_resolution_clock::now(); - if (duration_cast>(now - virtualTime).count() > 0.5) + if (duration_cast>(now - virtualTime).count() > 0) virtualTime = now; else if (virtualTime > now) { if (busyWait && cycles >= 0) { diff --git a/src/emucore/Sound.hxx b/src/emucore/Sound.hxx index 67b3de1af..a8c895f64 100644 --- a/src/emucore/Sound.hxx +++ b/src/emucore/Sound.hxx @@ -66,6 +66,16 @@ class Sound */ virtual void mute(bool state) = 0; + /** + Get the fragment size. + */ + virtual uInt32 getFragmentSize() const = 0; + + /** + Get the sample rate. + */ + virtual uInt32 getSampleRate() const = 0; + /** Reset the sound device. */