From 47bbdb679eca04298b99c4df9847a27aa238620f Mon Sep 17 00:00:00 2001 From: Christian Speckner Date: Sun, 24 Jun 2018 22:48:28 +0200 Subject: [PATCH] Remove unnecessary code, don't spam if audio is disabled. --- src/common/AudioQueue.cxx | 17 ++++++++--------- src/common/AudioQueue.hxx | 18 +++++++++--------- src/common/SoundSDL2.cxx | 4 +++- src/emucore/Console.cxx | 3 +-- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/common/AudioQueue.cxx b/src/common/AudioQueue.cxx index 845c63032..251796a9c 100644 --- a/src/common/AudioQueue.cxx +++ b/src/common/AudioQueue.cxx @@ -21,10 +21,9 @@ using std::mutex; using std::lock_guard; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -AudioQueue::AudioQueue(uInt32 fragmentSize, uInt32 capacity, bool isStereo, uInt16 sampleRate) +AudioQueue::AudioQueue(uInt32 fragmentSize, uInt32 capacity, bool isStereo) : myFragmentSize(fragmentSize), myIsStereo(isStereo), - mySampleRate(sampleRate), myFragmentQueue(capacity), myAllFragments(capacity + 2), mySize(0), @@ -70,12 +69,6 @@ uInt32 AudioQueue::fragmentSize() const return myFragmentSize; } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 AudioQueue::sampleRate() const -{ - return mySampleRate; -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Int16* AudioQueue::enqueue(Int16* fragment) { @@ -101,7 +94,7 @@ Int16* AudioQueue::enqueue(Int16* fragment) if (mySize < capacity) mySize++; else { myNextFragment = (myNextFragment + 1) % capacity; - (cerr << "audio buffer overflow\n").flush(); + if (!myIgnoreOverflows) (cerr << "audio buffer overflow\n").flush(); } return newFragment; @@ -141,3 +134,9 @@ void AudioQueue::closeSink(Int16* fragment) if (!myFirstFragmentForDequeue) myFirstFragmentForDequeue = fragment; } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void AudioQueue::ignoreOverflows(bool shouldIgnoreOverflows) +{ + myIgnoreOverflows = shouldIgnoreOverflows; +} diff --git a/src/common/AudioQueue.hxx b/src/common/AudioQueue.hxx index e0d7c4868..af714a925 100644 --- a/src/common/AudioQueue.hxx +++ b/src/common/AudioQueue.hxx @@ -45,7 +45,7 @@ class AudioQueue @param isStereo Whether samples are stereo or mono. @param sampleRate The sample rate. This is not used, but can be queried. */ - AudioQueue(uInt32 fragmentSize, uInt32 capacity, bool isStereo, uInt16 sampleRate); + AudioQueue(uInt32 fragmentSize, uInt32 capacity, bool isStereo); /** Capacity getter. @@ -67,11 +67,6 @@ class AudioQueue */ uInt32 fragmentSize() const; - /** - Sample rate getter. - */ - uInt16 sampleRate() const; - /** Enqueue a new fragment and get a new fragmen to fill. @@ -96,6 +91,11 @@ class AudioQueue */ void closeSink(Int16* fragment); + /** + Should we ignore overflows? + */ + void ignoreOverflows(bool shouldIgnoreOverflows); + private: // The size of an individual fragment (in stereo / mono samples) @@ -104,9 +104,6 @@ class AudioQueue // Are we using stereo samples? bool myIsStereo; - // The sample rate - uInt16 mySampleRate; - // The fragment queue vector myFragmentQueue; @@ -130,6 +127,9 @@ class AudioQueue // The first (empty) dequeue call replaces the returned fragment with this fragment. Int16* myFirstFragmentForDequeue; + // Log overflows? + bool myIgnoreOverflows; + private: AudioQueue() = delete; diff --git a/src/common/SoundSDL2.cxx b/src/common/SoundSDL2.cxx index fd27d432e..298d31a12 100644 --- a/src/common/SoundSDL2.cxx +++ b/src/common/SoundSDL2.cxx @@ -98,6 +98,7 @@ SoundSDL2::~SoundSDL2() void SoundSDL2::setEnabled(bool state) { myAudioSettings.setEnabled(state); + if (myAudioQueue) myAudioQueue->ignoreOverflows(!state); myOSystem.logMessage(state ? "SoundSDL2::setEnabled(true)" : "SoundSDL2::setEnabled(false)", 2); @@ -112,6 +113,7 @@ void SoundSDL2::open(shared_ptr audioQueue, myOSystem.logMessage("SoundSDL2::open started ...", 2); mute(true); + audioQueue->ignoreOverflows(!myAudioSettings.enabled()); if(!myAudioSettings.enabled()) { myOSystem.logMessage("Sound disabled\n", 1); @@ -251,7 +253,7 @@ void SoundSDL2::initResampler() }; Resampler::Format formatFrom = - Resampler::Format(myAudioQueue->sampleRate(), myAudioQueue->fragmentSize(), myAudioQueue->isStereo()); + Resampler::Format(myEmulationTiming->audioSampleRate(), myAudioQueue->fragmentSize(), myAudioQueue->isStereo()); Resampler::Format formatTo = Resampler::Format(myHardwareSpec.freq, myHardwareSpec.samples, myHardwareSpec.channels > 1); diff --git a/src/emucore/Console.cxx b/src/emucore/Console.cxx index 532f9f9e5..3cbfeffa7 100644 --- a/src/emucore/Console.cxx +++ b/src/emucore/Console.cxx @@ -725,8 +725,7 @@ void Console::createAudioQueue() myAudioQueue = make_shared( myEmulationTiming.audioFragmentSize(), myEmulationTiming.audioQueueCapacity(), - myProperties.get(Cartridge_Sound) == "STEREO", - myEmulationTiming.audioSampleRate() + myProperties.get(Cartridge_Sound) == "STEREO" ); }