From fb07d250d9151f466b15d4aff7516248bc44fccc Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Wed, 29 Aug 2018 09:10:55 -0230 Subject: [PATCH] Simplify AudioSettings class a little. - Use only one c'tor, which fixes some warnings from Coverity - Fix large compile times when AudioSettings class is changed --- src/common/AudioSettings.cxx | 58 ++++++++++++++++-------------------- src/common/AudioSettings.hxx | 6 ++-- src/emucore/OSystem.cxx | 9 +++--- src/emucore/OSystem.hxx | 16 +++++----- src/gui/AudioDialog.cxx | 1 - 5 files changed, 42 insertions(+), 48 deletions(-) diff --git a/src/common/AudioSettings.cxx b/src/common/AudioSettings.cxx index 599b56849..7e81ebb91 100644 --- a/src/common/AudioSettings.cxx +++ b/src/common/AudioSettings.cxx @@ -42,17 +42,11 @@ namespace { } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -AudioSettings::AudioSettings() - : mySettings(), - myIsPersistent(false) -{} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -AudioSettings::AudioSettings(Settings* settings) +AudioSettings::AudioSettings(Settings& settings) : mySettings(settings), myIsPersistent(true) { - setPreset(normalizedPreset(mySettings->getInt(SETTING_PRESET))); + setPreset(normalizedPreset(mySettings.getInt(SETTING_PRESET))); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -113,14 +107,14 @@ AudioSettings::Preset AudioSettings::preset() uInt32 AudioSettings::sampleRate() { updatePresetFromSettings(); - return customSettings() ? convertInt(mySettings->getInt(SETTING_SAMPLE_RATE), DEFAULT_SAMPLE_RATE) : myPresetSampleRate; + return customSettings() ? convertInt(mySettings.getInt(SETTING_SAMPLE_RATE), DEFAULT_SAMPLE_RATE) : myPresetSampleRate; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt32 AudioSettings::fragmentSize() { updatePresetFromSettings(); - return customSettings() ? convertInt(mySettings->getInt(SETTING_FRAGMENT_SIZE), DEFAULT_FRAGMENT_SIZE) : myPresetFragmentSize; + return customSettings() ? convertInt(mySettings.getInt(SETTING_FRAGMENT_SIZE), DEFAULT_FRAGMENT_SIZE) : myPresetFragmentSize; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -128,7 +122,7 @@ uInt32 AudioSettings::bufferSize() { updatePresetFromSettings(); // 0 is a valid value -> keep it - return customSettings() ? convertInt(mySettings->getInt(SETTING_BUFFER_SIZE), 0) : myPresetBufferSize; + return customSettings() ? convertInt(mySettings.getInt(SETTING_BUFFER_SIZE), 0) : myPresetBufferSize; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -136,34 +130,34 @@ uInt32 AudioSettings::headroom() { updatePresetFromSettings(); // 0 is a valid value -> keep it - return customSettings() ? convertInt(mySettings->getInt(SETTING_HEADROOM), 0) : myPresetHeadroom; + return customSettings() ? convertInt(mySettings.getInt(SETTING_HEADROOM), 0) : myPresetHeadroom; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - AudioSettings::ResamplingQuality AudioSettings::resamplingQuality() { updatePresetFromSettings(); - return customSettings() ? normalizeResamplingQuality(mySettings->getInt(SETTING_RESAMPLING_QUALITY)) : myPresetResamplingQuality; + return customSettings() ? normalizeResamplingQuality(mySettings.getInt(SETTING_RESAMPLING_QUALITY)) : myPresetResamplingQuality; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string AudioSettings::stereo() const { // 0 is a valid value -> keep it - return mySettings->getString(SETTING_STEREO); + return mySettings.getString(SETTING_STEREO); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt32 AudioSettings::volume() const { // 0 is a valid value -> keep it - return convertInt(mySettings->getInt(SETTING_VOLUME), 0); + return convertInt(mySettings.getInt(SETTING_VOLUME), 0); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool AudioSettings::enabled() const { - return mySettings->getBool(SETTING_ENABLED); + return mySettings.getBool(SETTING_ENABLED); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -212,7 +206,7 @@ void AudioSettings::setPreset(AudioSettings::Preset preset) throw runtime_error("invalid preset"); } - if (myIsPersistent) mySettings->setValue(SETTING_PRESET, static_cast(myPreset)); + if (myIsPersistent) mySettings.setValue(SETTING_PRESET, static_cast(myPreset)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -220,8 +214,8 @@ void AudioSettings::setSampleRate(uInt32 sampleRate) { if (!myIsPersistent) return; - mySettings->setValue(SETTING_SAMPLE_RATE, sampleRate); - normalize(*mySettings); + mySettings.setValue(SETTING_SAMPLE_RATE, sampleRate); + normalize(mySettings); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -229,8 +223,8 @@ void AudioSettings::setFragmentSize(uInt32 fragmentSize) { if (!myIsPersistent) return; - mySettings->setValue(SETTING_FRAGMENT_SIZE, fragmentSize); - normalize(*mySettings); + mySettings.setValue(SETTING_FRAGMENT_SIZE, fragmentSize); + normalize(mySettings); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -238,8 +232,8 @@ void AudioSettings::setBufferSize(uInt32 bufferSize) { if (!myIsPersistent) return; - mySettings->setValue(SETTING_BUFFER_SIZE, bufferSize); - normalize(*mySettings); + mySettings.setValue(SETTING_BUFFER_SIZE, bufferSize); + normalize(mySettings); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -247,8 +241,8 @@ void AudioSettings::setHeadroom(uInt32 headroom) { if (!myIsPersistent) return; - mySettings->setValue(SETTING_HEADROOM, headroom); - normalize(*mySettings); + mySettings.setValue(SETTING_HEADROOM, headroom); + normalize(mySettings); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -256,8 +250,8 @@ void AudioSettings::setResamplingQuality(AudioSettings::ResamplingQuality resamp { if (!myIsPersistent) return; - mySettings->setValue(SETTING_RESAMPLING_QUALITY, static_cast(resamplingQuality)); - normalize(*mySettings); + mySettings.setValue(SETTING_RESAMPLING_QUALITY, static_cast(resamplingQuality)); + normalize(mySettings); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -265,7 +259,7 @@ void AudioSettings::setStereo(const string& mode) { if(!myIsPersistent) return; - mySettings->setValue(SETTING_STEREO, mode); + mySettings.setValue(SETTING_STEREO, mode); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -273,8 +267,8 @@ void AudioSettings::setVolume(uInt32 volume) { if (!myIsPersistent) return; - mySettings->setValue(SETTING_VOLUME, volume); - normalize(*mySettings); + mySettings.setValue(SETTING_VOLUME, volume); + normalize(mySettings); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -282,7 +276,7 @@ void AudioSettings::setEnabled(bool isEnabled) { if (!myIsPersistent) return; - mySettings->setValue(SETTING_ENABLED, isEnabled); + mySettings.setValue(SETTING_ENABLED, isEnabled); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -302,5 +296,5 @@ void AudioSettings::updatePresetFromSettings() { if (!myIsPersistent) return; - setPreset(normalizedPreset(mySettings->getInt(SETTING_PRESET))); + setPreset(normalizedPreset(mySettings.getInt(SETTING_PRESET))); } diff --git a/src/common/AudioSettings.hxx b/src/common/AudioSettings.hxx index f529d7512..c9efaa8fc 100644 --- a/src/common/AudioSettings.hxx +++ b/src/common/AudioSettings.hxx @@ -65,9 +65,7 @@ class AudioSettings public: - AudioSettings(); - - explicit AudioSettings(Settings* mySettings); + explicit AudioSettings(Settings& mySettings); static void normalize(Settings& settings); @@ -117,7 +115,7 @@ class AudioSettings private: - Settings* mySettings; + Settings& mySettings; Preset myPreset; diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index 5324d1f2c..418c55e7e 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -55,6 +55,7 @@ #include "TIA.hxx" #include "DispatchResult.hxx" #include "EmulationWorker.hxx" +#include "AudioSettings.hxx" #include "OSystem.hxx" @@ -95,7 +96,6 @@ OSystem::OSystem() myBuildInfo = info.str(); mySettings = MediaFactory::createSettings(*this); - myAudioSettings = AudioSettings(mySettings.get()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -148,6 +148,7 @@ bool OSystem::create() myLauncher = make_unique(*this); myStateManager = make_unique(*this); myTimerManager = make_unique(); + myAudioSettings = make_unique(*mySettings); // Create the sound object; the sound subsystem isn't actually // opened until needed, so this is non-blocking (on those systems @@ -277,9 +278,9 @@ FBInitStatus OSystem::createFrameBuffer() void OSystem::createSound() { if(!mySound) - mySound = MediaFactory::createAudio(*this, myAudioSettings); + mySound = MediaFactory::createAudio(*this, *myAudioSettings); #ifndef SOUND_SUPPORT - myAudioSettings.setEnabled(false); + myAudioSettings->setEnabled(false); #endif } @@ -505,7 +506,7 @@ unique_ptr OSystem::openConsole(const FilesystemNode& romfile, string& // Finally, create the cart with the correct properties if(cart) - console = make_unique(*this, cart, props, myAudioSettings); + console = make_unique(*this, cart, props, *myAudioSettings); } return console; diff --git a/src/emucore/OSystem.hxx b/src/emucore/OSystem.hxx index 1f7a6fac6..21be6e145 100644 --- a/src/emucore/OSystem.hxx +++ b/src/emucore/OSystem.hxx @@ -40,6 +40,7 @@ class StateManager; class TimerManager; class VideoDialog; class EmulationWorker; +class AudioSettings; #include @@ -48,7 +49,6 @@ class EmulationWorker; #include "EventHandlerConstants.hxx" #include "FpsMeter.hxx" #include "bspf.hxx" -#include "AudioSettings.hxx" /** This class provides an interface for accessing operating system specific @@ -125,9 +125,11 @@ class OSystem bool hasConsole() const; /** - Get the audio settings ovject. - */ - AudioSettings& audioSettings() { return myAudioSettings; } + Get the audio settings object of the system. + + @return The audio settings object + */ + AudioSettings& audioSettings() { return *myAudioSettings; } /** Get the serial port of the system. @@ -445,6 +447,9 @@ class OSystem // Pointer to the (currently defined) Console object unique_ptr myConsole; + // Pointer to audio settings object + unique_ptr myAudioSettings; + // Pointer to the serial port object unique_ptr mySerialPort; @@ -486,9 +491,6 @@ class OSystem // Indicates whether to stop the main loop bool myQuitLoop; - // Audio settings - AudioSettings myAudioSettings; - private: string myBaseDir; string myStateDir; diff --git a/src/gui/AudioDialog.cxx b/src/gui/AudioDialog.cxx index 0993423ad..d89a696d3 100644 --- a/src/gui/AudioDialog.cxx +++ b/src/gui/AudioDialog.cxx @@ -214,7 +214,6 @@ void AudioDialog::saveConfig() // Stereo audioSettings.setStereo(myStereoSoundPopup->getSelectedTag().toString()); - //TODO: instance().sound().setStereo(myStereoSoundPopup->getSelectedTag().toString()); AudioSettings::Preset preset = static_cast(myModePopup->getSelectedTag().toInt()); audioSettings.setPreset(preset);