From ce9b832f68db78fd6a4e3ac748ff82c19f46d3ec Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Wed, 5 Sep 2018 14:05:56 -0230 Subject: [PATCH] Improvements to logging for sound settings. - Now shows all settings from AudioSettings (preset, resampler, etc) - Only logs sound info when the settings have actually changed (similar to Framebuffer info) --- src/common/SoundNull.hxx | 5 +++ src/common/SoundSDL2.cxx | 73 +++++++++++++++++++++++++++------------- src/common/SoundSDL2.hxx | 7 ++++ src/emucore/OSystem.cxx | 2 +- src/emucore/Sound.hxx | 5 +++ 5 files changed, 68 insertions(+), 24 deletions(-) diff --git a/src/common/SoundNull.hxx b/src/common/SoundNull.hxx index 1ebc4426a..f487eb983 100644 --- a/src/common/SoundNull.hxx +++ b/src/common/SoundNull.hxx @@ -93,6 +93,11 @@ class SoundNull : public Sound */ void adjustVolume(Int8 direction) override { } + /** + This method is called to provide information about the sound device. + */ + string about() const override { return "Sound disabled"; } + private: // Following constructors and assignment operators not supported SoundNull() = delete; diff --git a/src/common/SoundSDL2.cxx b/src/common/SoundSDL2.cxx index cc9c08c41..86ee5be31 100644 --- a/src/common/SoundSDL2.cxx +++ b/src/common/SoundSDL2.cxx @@ -118,6 +118,8 @@ void SoundSDL2::setEnabled(bool state) void SoundSDL2::open(shared_ptr audioQueue, EmulationTiming* emulationTiming) { + string pre_about = myAboutString; + // Do we need to re-open the sound device? // Only do this when absolutely necessary if(myAudioSettings.sampleRate() != uInt32(myHardwareSpec.freq) || @@ -146,28 +148,9 @@ void SoundSDL2::open(shared_ptr audioQueue, initResampler(); // Show some info - ostringstream buf; - buf << "Sound enabled:" << endl - << " Volume: " << myVolume << endl - << " Frag size: " << uInt32(myHardwareSpec.samples) << endl - << " Frequency: " << uInt32(myHardwareSpec.freq) << endl - << " Channels: " << uInt32(myHardwareSpec.channels) << endl - << " Resampling: "; - switch (myAudioSettings.resamplingQuality()) { - case AudioSettings::ResamplingQuality::nearestNeightbour: - buf << "quality 1, nearest neighbor" << endl; - break; - case AudioSettings::ResamplingQuality::lanczos_2: - buf << "quality 2, nearest Lanczos (a = 2)" << endl; - break; - case AudioSettings::ResamplingQuality::lanczos_3: - buf << "quality 3, nearest Lanczos (a = 3)" << endl; - break; - default: - buf << "unknown resampler" << endl; - break; - } - myOSystem.logMessage(buf.str(), 1); + myAboutString = about(); + if(myAboutString != pre_about) + myOSystem.logMessage(myAboutString, 1); // And start the SDL sound subsystem ... mute(false); @@ -239,6 +222,51 @@ void SoundSDL2::adjustVolume(Int8 direction) myOSystem.frameBuffer().showMessage(message); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +string SoundSDL2::about() const +{ + ostringstream buf; + buf << "Sound enabled:" << endl + << " Volume: " << myVolume << endl + << " Channels: " << uInt32(myHardwareSpec.channels) << endl + << " Preset: "; + switch (myAudioSettings.preset()) { + case AudioSettings::Preset::custom: + buf << "Custom" << endl; + break; + case AudioSettings::Preset::lowQualityMediumLag: + buf << "Low quality, medium lag" << endl; + break; + case AudioSettings::Preset::highQualityMediumLag: + buf << "High quality, medium lag" << endl; + break; + case AudioSettings::Preset::highQualityLowLag: + buf << "High quality, low lag" << endl; + break; + case AudioSettings::Preset::veryHighQualityVeryLowLag: + buf << "Very high quality, very low lag" << endl; + break; + } + buf << " Sample rate: " << uInt32(myHardwareSpec.freq) << endl + << " Frag size: " << uInt32(myHardwareSpec.samples) << endl + << " Buffer size: " << myAudioSettings.bufferSize() << endl + << " Head room: " << myAudioSettings.headroom() << endl + << " Resampling: "; + switch (myAudioSettings.resamplingQuality()) { + case AudioSettings::ResamplingQuality::nearestNeightbour: + buf << "quality 1, nearest neighbor" << endl; + break; + case AudioSettings::ResamplingQuality::lanczos_2: + buf << "quality 2, Lanczos (a = 2)" << endl; + break; + case AudioSettings::ResamplingQuality::lanczos_3: + buf << "quality 3, Lanczos (a = 3)" << endl; + break; + } + + return buf.str(); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void SoundSDL2::processFragment(float* stream, uInt32 length) { @@ -270,7 +298,6 @@ void SoundSDL2::initResampler() Resampler::Format formatTo = Resampler::Format(myHardwareSpec.freq, myHardwareSpec.samples, myHardwareSpec.channels > 1); - switch (myAudioSettings.resamplingQuality()) { case AudioSettings::ResamplingQuality::nearestNeightbour: myResampler = make_unique(formatFrom, formatTo, nextFragmentCallback); diff --git a/src/common/SoundSDL2.hxx b/src/common/SoundSDL2.hxx index 46c9f685e..0c3fae7e0 100644 --- a/src/common/SoundSDL2.hxx +++ b/src/common/SoundSDL2.hxx @@ -96,6 +96,11 @@ class SoundSDL2 : public Sound */ void adjustVolume(Int8 direction) override; + /** + This method is called to provide information about the sound device. + */ + string about() const override; + protected: /** Invoked by the sound callback to process the next sound fragment. @@ -141,6 +146,8 @@ class SoundSDL2 : public Sound AudioSettings& myAudioSettings; + string myAboutString; + private: // Callback function invoked by the SDL Audio library when it needs data static void callback(void* udata, uInt8* stream, int len); diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index 7fce086db..273264aca 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -351,7 +351,7 @@ string OSystem::createConsole(const FilesystemNode& rom, const string& md5sum, } buf << "Game console created:" << endl << " ROM file: " << myRomFile.getShortPath() << endl << endl - << getROMInfo(*myConsole) << endl; + << getROMInfo(*myConsole); logMessage(buf.str(), 1); myFrameBuffer->setCursorState(); diff --git a/src/emucore/Sound.hxx b/src/emucore/Sound.hxx index 24a42e832..426521901 100644 --- a/src/emucore/Sound.hxx +++ b/src/emucore/Sound.hxx @@ -86,6 +86,11 @@ class Sound */ virtual void adjustVolume(Int8 direction) = 0; + /** + This method is called to provide information about the sound device. + */ + virtual string about() const = 0; + protected: // The OSystem for this sound object OSystem& myOSystem;