diff --git a/es-app/src/FileData.cpp b/es-app/src/FileData.cpp index 9fa60a343..05f994e06 100644 --- a/es-app/src/FileData.cpp +++ b/es-app/src/FileData.cpp @@ -268,7 +268,6 @@ void FileData::launchGame(Window* window) window->init(); VolumeControl::getInstance()->init(); - AudioManager::getInstance()->init(); window->normalizeNextUpdate(); //update number of times the game has been launched @@ -343,4 +342,4 @@ FileData::SortType getSortTypeFromString(std::string desc) { } // if not found default to name, ascending return FileSorts::SortTypes.at(0); -} \ No newline at end of file +} diff --git a/es-app/src/components/TextListComponent.h b/es-app/src/components/TextListComponent.h index 0aa078ac2..336cbac50 100644 --- a/es-app/src/components/TextListComponent.h +++ b/es-app/src/components/TextListComponent.h @@ -76,13 +76,11 @@ public: inline void setSelectorOffsetY(float selectorOffsetY) { mSelectorOffsetY = selectorOffsetY; } inline void setSelectorColor(unsigned int color) { mSelectorColor = color; } inline void setSelectedColor(unsigned int color) { mSelectedColor = color; } - inline void setScrollSound(const std::shared_ptr& sound) { mScrollSound = sound; } inline void setColor(unsigned int id, unsigned int color) { mColors[id] = color; } - inline void setSound(const std::shared_ptr& sound) { mScrollSound = sound; } inline void setLineSpacing(float lineSpacing) { mLineSpacing = lineSpacing; } protected: - virtual void onScroll(int amt) { if(mScrollSound) mScrollSound->play(); } + virtual void onScroll(int amt) { if(!mScrollSound.empty()) Sound::get(mScrollSound)->play(); } virtual void onCursorChanged(const CursorState& state); private: @@ -105,7 +103,7 @@ private: float mSelectorOffsetY; unsigned int mSelectorColor; unsigned int mSelectedColor; - std::shared_ptr mScrollSound; + std::string mScrollSound; static const unsigned int COLOR_ID_COUNT = 2; unsigned int mColors[COLOR_ID_COUNT]; @@ -354,7 +352,7 @@ void TextListComponent::applyTheme(const std::shared_ptr& theme, c setSelectorHeight(selectorHeight); if(properties & SOUND && elem->has("scrollSound")) - setSound(Sound::get(elem->get("scrollSound"))); + mScrollSound = elem->get("scrollSound"); if(properties & ALIGNMENT) { diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index 9a0b79739..69a542514 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -120,7 +120,16 @@ void GuiMenu::openSoundSettings() auto sounds_enabled = std::make_shared(mWindow); sounds_enabled->setState(Settings::getInstance()->getBool("EnableSounds")); s->addWithLabel("ENABLE NAVIGATION SOUNDS", sounds_enabled); - s->addSaveFunc([sounds_enabled] { Settings::getInstance()->setBool("EnableSounds", sounds_enabled->getState()); }); + s->addSaveFunc([sounds_enabled] { + if (sounds_enabled->getState() + && !Settings::getInstance()->getBool("EnableSounds") + && PowerSaver::getMode() == PowerSaver::INSTANT) + { + Settings::getInstance()->setString("PowerSaverMode", "default"); + PowerSaver::init(); + } + Settings::getInstance()->setBool("EnableSounds", sounds_enabled->getState()); + }); auto video_audio = std::make_shared(mWindow); video_audio->setState(Settings::getInstance()->getBool("VideoAudio")); @@ -316,6 +325,7 @@ void GuiMenu::openOtherSettings() if (Settings::getInstance()->getString("PowerSaverMode") != "instant" && power_saver->getSelected() == "instant") { Settings::getInstance()->setString("TransitionStyle", "instant"); Settings::getInstance()->setBool("MoveCarousel", false); + Settings::getInstance()->setBool("EnableSounds", false); } Settings::getInstance()->setString("PowerSaverMode", power_saver->getSelected()); PowerSaver::init(); diff --git a/es-core/src/AudioManager.cpp b/es-core/src/AudioManager.cpp index cbc0821ed..735099bc8 100644 --- a/es-core/src/AudioManager.cpp +++ b/es-core/src/AudioManager.cpp @@ -1,4 +1,5 @@ #include "AudioManager.h" +#include "Settings.h" #include #include "Log.h" @@ -62,7 +63,7 @@ AudioManager::~AudioManager() std::shared_ptr & AudioManager::getInstance() { //check if an AudioManager instance is already created, if not create one - if (sInstance == nullptr) { + if (sInstance == nullptr && Settings::getInstance()->getBool("EnableSounds")) { sInstance = std::shared_ptr(new AudioManager); } return sInstance; @@ -106,6 +107,7 @@ void AudioManager::deinit() //completely tear down SDL audio. else SDL hogs audio resources and emulators might fail to start... SDL_CloseAudio(); SDL_QuitSubSystem(SDL_INIT_AUDIO); + sInstance = NULL; } void AudioManager::registerSound(std::shared_ptr & sound) diff --git a/es-core/src/PowerSaver.cpp b/es-core/src/PowerSaver.cpp index cfa648856..a7805ca71 100644 --- a/es-core/src/PowerSaver.cpp +++ b/es-core/src/PowerSaver.cpp @@ -1,4 +1,5 @@ #include "PowerSaver.h" +#include "AudioManager.h" #include "Settings.h" #include @@ -17,6 +18,9 @@ void PowerSaver::init() int PowerSaver::getTimeout() { + if (SDL_GetAudioStatus() == SDL_AUDIO_PAUSED) + AudioManager::getInstance()->deinit(); + // Used only for SDL_WaitEventTimeout. Use `getMode()` for modes. return mRunningScreenSaver ? mWakeupTimeout : mScreenSaverTimeout; } diff --git a/es-core/src/Sound.cpp b/es-core/src/Sound.cpp index c915ea544..22d17b959 100644 --- a/es-core/src/Sound.cpp +++ b/es-core/src/Sound.cpp @@ -114,6 +114,8 @@ void Sound::play() if(!Settings::getInstance()->getBool("EnableSounds")) return; + AudioManager::getInstance(); + SDL_LockAudio(); if (playing) { diff --git a/es-core/src/components/VideoPlayerComponent.cpp b/es-core/src/components/VideoPlayerComponent.cpp index df7914991..5d309dfa3 100644 --- a/es-core/src/components/VideoPlayerComponent.cpp +++ b/es-core/src/components/VideoPlayerComponent.cpp @@ -191,11 +191,6 @@ void VideoPlayerComponent::stopVideo() int status; kill(mPlayerPid, SIGKILL); waitpid(mPlayerPid, &status, WNOHANG); - // Restart AudioManager - if (boost::starts_with(Settings::getInstance()->getString("OMXAudioDev").c_str(), "alsa")) - { - AudioManager::getInstance()->init(); - } mPlayerPid = -1; } }