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
This commit is contained in:
Stephen Anthony 2018-08-29 09:10:55 -02:30
parent dc4fc5c8d2
commit fb07d250d9
5 changed files with 42 additions and 48 deletions

View File

@ -42,17 +42,11 @@ namespace {
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AudioSettings::AudioSettings() AudioSettings::AudioSettings(Settings& settings)
: mySettings(),
myIsPersistent(false)
{}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AudioSettings::AudioSettings(Settings* settings)
: mySettings(settings), : mySettings(settings),
myIsPersistent(true) 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() uInt32 AudioSettings::sampleRate()
{ {
updatePresetFromSettings(); 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() uInt32 AudioSettings::fragmentSize()
{ {
updatePresetFromSettings(); 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(); updatePresetFromSettings();
// 0 is a valid value -> keep it // 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(); updatePresetFromSettings();
// 0 is a valid value -> keep it // 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() AudioSettings::ResamplingQuality AudioSettings::resamplingQuality()
{ {
updatePresetFromSettings(); updatePresetFromSettings();
return customSettings() ? normalizeResamplingQuality(mySettings->getInt(SETTING_RESAMPLING_QUALITY)) : myPresetResamplingQuality; return customSettings() ? normalizeResamplingQuality(mySettings.getInt(SETTING_RESAMPLING_QUALITY)) : myPresetResamplingQuality;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string AudioSettings::stereo() const string AudioSettings::stereo() const
{ {
// 0 is a valid value -> keep it // 0 is a valid value -> keep it
return mySettings->getString(SETTING_STEREO); return mySettings.getString(SETTING_STEREO);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 AudioSettings::volume() const uInt32 AudioSettings::volume() const
{ {
// 0 is a valid value -> keep it // 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 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"); throw runtime_error("invalid preset");
} }
if (myIsPersistent) mySettings->setValue(SETTING_PRESET, static_cast<int>(myPreset)); if (myIsPersistent) mySettings.setValue(SETTING_PRESET, static_cast<int>(myPreset));
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -220,8 +214,8 @@ void AudioSettings::setSampleRate(uInt32 sampleRate)
{ {
if (!myIsPersistent) return; if (!myIsPersistent) return;
mySettings->setValue(SETTING_SAMPLE_RATE, sampleRate); mySettings.setValue(SETTING_SAMPLE_RATE, sampleRate);
normalize(*mySettings); normalize(mySettings);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -229,8 +223,8 @@ void AudioSettings::setFragmentSize(uInt32 fragmentSize)
{ {
if (!myIsPersistent) return; if (!myIsPersistent) return;
mySettings->setValue(SETTING_FRAGMENT_SIZE, fragmentSize); mySettings.setValue(SETTING_FRAGMENT_SIZE, fragmentSize);
normalize(*mySettings); normalize(mySettings);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -238,8 +232,8 @@ void AudioSettings::setBufferSize(uInt32 bufferSize)
{ {
if (!myIsPersistent) return; if (!myIsPersistent) return;
mySettings->setValue(SETTING_BUFFER_SIZE, bufferSize); mySettings.setValue(SETTING_BUFFER_SIZE, bufferSize);
normalize(*mySettings); normalize(mySettings);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -247,8 +241,8 @@ void AudioSettings::setHeadroom(uInt32 headroom)
{ {
if (!myIsPersistent) return; if (!myIsPersistent) return;
mySettings->setValue(SETTING_HEADROOM, headroom); mySettings.setValue(SETTING_HEADROOM, headroom);
normalize(*mySettings); normalize(mySettings);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -256,8 +250,8 @@ void AudioSettings::setResamplingQuality(AudioSettings::ResamplingQuality resamp
{ {
if (!myIsPersistent) return; if (!myIsPersistent) return;
mySettings->setValue(SETTING_RESAMPLING_QUALITY, static_cast<int>(resamplingQuality)); mySettings.setValue(SETTING_RESAMPLING_QUALITY, static_cast<int>(resamplingQuality));
normalize(*mySettings); normalize(mySettings);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -265,7 +259,7 @@ void AudioSettings::setStereo(const string& mode)
{ {
if(!myIsPersistent) return; 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; if (!myIsPersistent) return;
mySettings->setValue(SETTING_VOLUME, volume); mySettings.setValue(SETTING_VOLUME, volume);
normalize(*mySettings); normalize(mySettings);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -282,7 +276,7 @@ void AudioSettings::setEnabled(bool isEnabled)
{ {
if (!myIsPersistent) return; if (!myIsPersistent) return;
mySettings->setValue(SETTING_ENABLED, isEnabled); mySettings.setValue(SETTING_ENABLED, isEnabled);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -302,5 +296,5 @@ void AudioSettings::updatePresetFromSettings()
{ {
if (!myIsPersistent) return; if (!myIsPersistent) return;
setPreset(normalizedPreset(mySettings->getInt(SETTING_PRESET))); setPreset(normalizedPreset(mySettings.getInt(SETTING_PRESET)));
} }

View File

@ -65,9 +65,7 @@ class AudioSettings
public: public:
AudioSettings(); explicit AudioSettings(Settings& mySettings);
explicit AudioSettings(Settings* mySettings);
static void normalize(Settings& settings); static void normalize(Settings& settings);
@ -117,7 +115,7 @@ class AudioSettings
private: private:
Settings* mySettings; Settings& mySettings;
Preset myPreset; Preset myPreset;

View File

@ -55,6 +55,7 @@
#include "TIA.hxx" #include "TIA.hxx"
#include "DispatchResult.hxx" #include "DispatchResult.hxx"
#include "EmulationWorker.hxx" #include "EmulationWorker.hxx"
#include "AudioSettings.hxx"
#include "OSystem.hxx" #include "OSystem.hxx"
@ -95,7 +96,6 @@ OSystem::OSystem()
myBuildInfo = info.str(); myBuildInfo = info.str();
mySettings = MediaFactory::createSettings(*this); mySettings = MediaFactory::createSettings(*this);
myAudioSettings = AudioSettings(mySettings.get());
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -148,6 +148,7 @@ bool OSystem::create()
myLauncher = make_unique<Launcher>(*this); myLauncher = make_unique<Launcher>(*this);
myStateManager = make_unique<StateManager>(*this); myStateManager = make_unique<StateManager>(*this);
myTimerManager = make_unique<TimerManager>(); myTimerManager = make_unique<TimerManager>();
myAudioSettings = make_unique<AudioSettings>(*mySettings);
// Create the sound object; the sound subsystem isn't actually // Create the sound object; the sound subsystem isn't actually
// opened until needed, so this is non-blocking (on those systems // opened until needed, so this is non-blocking (on those systems
@ -277,9 +278,9 @@ FBInitStatus OSystem::createFrameBuffer()
void OSystem::createSound() void OSystem::createSound()
{ {
if(!mySound) if(!mySound)
mySound = MediaFactory::createAudio(*this, myAudioSettings); mySound = MediaFactory::createAudio(*this, *myAudioSettings);
#ifndef SOUND_SUPPORT #ifndef SOUND_SUPPORT
myAudioSettings.setEnabled(false); myAudioSettings->setEnabled(false);
#endif #endif
} }
@ -505,7 +506,7 @@ unique_ptr<Console> OSystem::openConsole(const FilesystemNode& romfile, string&
// Finally, create the cart with the correct properties // Finally, create the cart with the correct properties
if(cart) if(cart)
console = make_unique<Console>(*this, cart, props, myAudioSettings); console = make_unique<Console>(*this, cart, props, *myAudioSettings);
} }
return console; return console;

View File

@ -40,6 +40,7 @@ class StateManager;
class TimerManager; class TimerManager;
class VideoDialog; class VideoDialog;
class EmulationWorker; class EmulationWorker;
class AudioSettings;
#include <chrono> #include <chrono>
@ -48,7 +49,6 @@ class EmulationWorker;
#include "EventHandlerConstants.hxx" #include "EventHandlerConstants.hxx"
#include "FpsMeter.hxx" #include "FpsMeter.hxx"
#include "bspf.hxx" #include "bspf.hxx"
#include "AudioSettings.hxx"
/** /**
This class provides an interface for accessing operating system specific This class provides an interface for accessing operating system specific
@ -125,9 +125,11 @@ class OSystem
bool hasConsole() const; bool hasConsole() const;
/** /**
Get the audio settings ovject. Get the audio settings object of the system.
@return The audio settings object
*/ */
AudioSettings& audioSettings() { return myAudioSettings; } AudioSettings& audioSettings() { return *myAudioSettings; }
/** /**
Get the serial port of the system. Get the serial port of the system.
@ -445,6 +447,9 @@ class OSystem
// Pointer to the (currently defined) Console object // Pointer to the (currently defined) Console object
unique_ptr<Console> myConsole; unique_ptr<Console> myConsole;
// Pointer to audio settings object
unique_ptr<AudioSettings> myAudioSettings;
// Pointer to the serial port object // Pointer to the serial port object
unique_ptr<SerialPort> mySerialPort; unique_ptr<SerialPort> mySerialPort;
@ -486,9 +491,6 @@ class OSystem
// Indicates whether to stop the main loop // Indicates whether to stop the main loop
bool myQuitLoop; bool myQuitLoop;
// Audio settings
AudioSettings myAudioSettings;
private: private:
string myBaseDir; string myBaseDir;
string myStateDir; string myStateDir;

View File

@ -214,7 +214,6 @@ void AudioDialog::saveConfig()
// Stereo // Stereo
audioSettings.setStereo(myStereoSoundPopup->getSelectedTag().toString()); audioSettings.setStereo(myStereoSoundPopup->getSelectedTag().toString());
//TODO: instance().sound().setStereo(myStereoSoundPopup->getSelectedTag().toString());
AudioSettings::Preset preset = static_cast<AudioSettings::Preset>(myModePopup->getSelectedTag().toInt()); AudioSettings::Preset preset = static_cast<AudioSettings::Preset>(myModePopup->getSelectedTag().toInt());
audioSettings.setPreset(preset); audioSettings.setPreset(preset);