From 89d07d7a5aa11aa9ea64f868f3c17537c147c82d Mon Sep 17 00:00:00 2001 From: Paul Reioux Date: Tue, 28 May 2024 16:12:02 -0700 Subject: [PATCH 1/4] ES: EnableSounds: Unify all different toggles for audio under EnableSounds main: Unify all sound controls under 1 setting Signed-off-by: Paul Reioux --- es-app/src/ApiSystem.cpp | 9 ++++--- es-app/src/SystemScreenSaver.cpp | 7 +++--- es-app/src/components/CarouselComponent.cpp | 3 ++- .../src/guis/GuiGeneralScreensaverOptions.cpp | 22 ++++++++--------- es-app/src/guis/GuiMenu.cpp | 21 ++++++++++------ es-app/src/main.cpp | 18 +++++++------- es-app/src/views/SystemView.cpp | 3 ++- .../views/gamelist/ISimpleGameListView.cpp | 24 ++++++++++++------- es-core/src/Settings.cpp | 8 +++---- es-core/src/components/VideoVlcComponent.cpp | 6 ++--- 10 files changed, 71 insertions(+), 50 deletions(-) diff --git a/es-app/src/ApiSystem.cpp b/es-app/src/ApiSystem.cpp index 5af9ac2c0..5990bf734 100644 --- a/es-app/src/ApiSystem.cpp +++ b/es-app/src/ApiSystem.cpp @@ -695,7 +695,8 @@ bool ApiSystem::setAudioOutputDevice(std::string selected) oss << "set-audio set" << " '" << selected << "'"; int exitcode = system(oss.str().c_str()); - Sound::get("/usr/share/emulationstation/resources/checksound.ogg")->play(); + if (Settings::getInstance()->getBool("EnableSounds")) + Sound::get("/usr/share/emulationstation/resources/checksound.ogg")->play(); return exitcode == 0; } @@ -746,7 +747,8 @@ bool ApiSystem::setAudioOutputPath(std::string selected) oss << "set-audio esset" << " '" << selected << "'"; int exitcode = system(oss.str().c_str()); - Sound::get("/usr/share/emulationstation/resources/checksound.ogg")->play(); + if (Settings::getInstance()->getBool("EnableSounds")) + Sound::get("/usr/share/emulationstation/resources/checksound.ogg")->play(); return exitcode == 0; } @@ -797,7 +799,8 @@ bool ApiSystem::setAudioOutputProfile(std::string selected) oss << "batocera-audio set-profile" << " '" << selected << "'"; int exitcode = system(oss.str().c_str()); - Sound::get("/usr/share/emulationstation/resources/checksound.ogg")->play(); + if (Settings::getInstance()->getBool("EnableSounds")) + Sound::get("/usr/share/emulationstation/resources/checksound.ogg")->play(); return exitcode == 0; } diff --git a/es-app/src/SystemScreenSaver.cpp b/es-app/src/SystemScreenSaver.cpp index dbea48b69..38bfec47e 100644 --- a/es-app/src/SystemScreenSaver.cpp +++ b/es-app/src/SystemScreenSaver.cpp @@ -84,7 +84,7 @@ void SystemScreenSaver::startScreenSaver() stopScreenSaver(); - if (!loadingNext && Settings::getInstance()->getBool("StopMusicOnScreenSaver")) //(Settings::getInstance()->getBool("VideoAudio") && !Settings::getInstance()->getBool("ScreenSaverVideoMute"))) + if (!loadingNext && !Settings::getInstance()->getBool("EnableSounds")) //(Settings::getInstance()->getBool("VideoAudio") && !Settings::getInstance()->getBool("ScreenSaverVideoMute"))) AudioManager::getInstance()->deinit(); std::string screensaver_behavior = Settings::getInstance()->getString("ScreenSaverBehavior"); @@ -180,9 +180,10 @@ void SystemScreenSaver::startScreenSaver() } } - // No videos. Just use a standard screensaver + // No videos. Just use a standard screensaver (black screen) mState = STATE_SCREENSAVER_ACTIVE; mCurrentGame = NULL; + } void SystemScreenSaver::stopScreenSaver() @@ -214,7 +215,7 @@ void SystemScreenSaver::stopScreenSaver() PowerSaver::runningScreenSaver(false); // Exiting screen saver -> Restore sound - if (isExitingScreenSaver && Settings::getInstance()->getBool("StopMusicOnScreenSaver")) //isVideoScreenSaver && Settings::getInstance()->getBool("VideoAudio") && !Settings::getInstance()->getBool("ScreenSaverVideoMute")) + if (isExitingScreenSaver && Settings::getInstance()->getBool("EnableSounds")) //isVideoScreenSaver && Settings::getInstance()->getBool("VideoAudio") && !Settings::getInstance()->getBool("ScreenSaverVideoMute")) { AudioManager::getInstance()->init(); diff --git a/es-app/src/components/CarouselComponent.cpp b/es-app/src/components/CarouselComponent.cpp index cffcdf741..3b91a4f21 100644 --- a/es-app/src/components/CarouselComponent.cpp +++ b/es-app/src/components/CarouselComponent.cpp @@ -199,7 +199,8 @@ void CarouselComponent::onCursorChanged(const CursorState& state) return; if (!mScrollSound.empty()) - Sound::get(mScrollSound)->play(); + if (Settings::getInstance()->getBool("EnableSounds")) + Sound::get(mScrollSound)->play(); int oldCursor = mLastCursor; diff --git a/es-app/src/guis/GuiGeneralScreensaverOptions.cpp b/es-app/src/guis/GuiGeneralScreensaverOptions.cpp index 67c44790f..c6fe71634 100644 --- a/es-app/src/guis/GuiGeneralScreensaverOptions.cpp +++ b/es-app/src/guis/GuiGeneralScreensaverOptions.cpp @@ -57,13 +57,13 @@ GuiGeneralScreensaverOptions::GuiGeneralScreensaverOptions(Window* window, int s }); // Screensaver stops music - if (Settings::getInstance()->getBool("audio.bgmusic")) - { - auto ctlStopMusic = std::make_shared(mWindow); - ctlStopMusic->setState(Settings::getInstance()->getBool("StopMusicOnScreenSaver")); - addWithLabel(_("STOP MUSIC ON SCREENSAVER"), ctlStopMusic); - addSaveFunc([ctlStopMusic] { Settings::getInstance()->setBool("StopMusicOnScreenSaver", ctlStopMusic->getState()); }); - } +// if (Settings::getInstance()->getBool("audio.bgmusic")) +// { +// auto ctlStopMusic = std::make_shared(mWindow); +// ctlStopMusic->setState(Settings::getInstance()->getBool("EnableSounds")); +// addWithLabel(_("STOP MUSIC ON SCREENSAVER"), ctlStopMusic); +// addSaveFunc([ctlStopMusic] { Settings::getInstance()->setBool("EnableSounds", ctlStopMusic->getState()); }); +// } if (ssBehavior == "random video") addVideoScreensaverOptions(selectItem); @@ -143,10 +143,10 @@ void GuiGeneralScreensaverOptions::addVideoScreensaverOptions(int selectItem) addWithLabel(_("STRETCH VIDEOS"), stretch_screensaver); addSaveFunc([stretch_screensaver] { Settings::getInstance()->setBool("StretchVideoOnScreenSaver", stretch_screensaver->getState()); }); - auto ss_video_mute = std::make_shared(mWindow); - ss_video_mute->setState(Settings::getInstance()->getBool("ScreenSaverVideoMute")); - addWithLabel(_("MUTE VIDEO AUDIO"), ss_video_mute); - addSaveFunc([ss_video_mute] { Settings::getInstance()->setBool("ScreenSaverVideoMute", ss_video_mute->getState()); }); + //auto ss_video_mute = std::make_shared(mWindow); + //ss_video_mute->setState(Settings::getInstance()->getBool("ScreenSaverVideoMute")); + //addWithLabel(_("MUTE VIDEO AUDIO"), ss_video_mute); + //addSaveFunc([ss_video_mute] { Settings::getInstance()->setBool("ScreenSaverVideoMute", ss_video_mute->getState()); }); // Allow ScreenSaver Controls - ScreenSaverControls auto controls = std::make_shared(mWindow); diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index 0fb90bd16..a967c4146 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -3797,7 +3797,7 @@ void GuiMenu::openSoundSettings() // disable sounds auto sounds_enabled = std::make_shared(mWindow); sounds_enabled->setState(Settings::getInstance()->getBool("EnableSounds")); - s->addWithLabel(_("ENABLE NAVIGATION SOUNDS"), sounds_enabled); + s->addWithLabel(_("ENABLE SYSTEM SOUNDS"), sounds_enabled); s->addSaveFunc([sounds_enabled] { if (sounds_enabled->getState() && !Settings::getInstance()->getBool("EnableSounds") && PowerSaver::getMode() == PowerSaver::INSTANT) @@ -3805,7 +3805,16 @@ void GuiMenu::openSoundSettings() Settings::getInstance()->setPowerSaverMode("default"); PowerSaver::init(); } + + if (sounds_enabled->getState()) + /* user has toggled the sound option to on, so make sure audioManager is alive */ + AudioManager::getInstance()->init(); + else + /* user has toggled the sound option to off, so make sure audioManager is torn down */ + AudioManager::getInstance()->deinit(); + Settings::getInstance()->setBool("EnableSounds", sounds_enabled->getState()); + Settings::getInstance()->saveFile(); }); auto batteryWarning = std::make_shared(mWindow); @@ -3817,12 +3826,10 @@ void GuiMenu::openSoundSettings() SystemConf::getInstance()->set("system.battery.warning", batteryWarningEnabled ? "1" : "0"); }); - auto video_audio = std::make_shared(mWindow); - video_audio->setState(Settings::getInstance()->getBool("VideoAudio")); - s->addWithLabel(_("ENABLE VIDEO PREVIEW AUDIO"), video_audio); - s->addSaveFunc([video_audio] { Settings::getInstance()->setBool("VideoAudio", video_audio->getState()); }); - - +// auto video_audio = std::make_shared(mWindow); +// video_audio->setState(Settings::getInstance()->getBool("VideoAudio")); +// s->addWithLabel(_("ENABLE VIDEO PREVIEW AUDIO"), video_audio); +// s->addSaveFunc([video_audio] { Settings::getInstance()->setBool("VideoAudio", video_audio->getState()); }); mWindow->pushGui(s); } diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index f4e3fe0fc..e445720fb 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -331,8 +331,6 @@ void playVideo() return; } - Settings::getInstance()->setBool("VideoAudio", true); - bool exitLoop = false; VideoVlcComponent vid(&window); @@ -513,14 +511,16 @@ int main(int argc, char* argv[]) // Create a flag in temporary directory to signal READY state ApiSystem::getInstance()->setReadyFlag(); - // Play music - AudioManager::getInstance()->init(); - - if (ViewController::get()->getState().viewing == ViewController::GAME_LIST || ViewController::get()->getState().viewing == ViewController::SYSTEM_SELECT) - AudioManager::getInstance()->changePlaylist(ViewController::get()->getState().getSystem()->getTheme()); - else - AudioManager::getInstance()->playRandomMusic(); + // Play music (as part of ES startup) + if (Settings::getInstance()->getBool("EnableSounds")) + { + AudioManager::getInstance()->init(); + if (ViewController::get()->getState().viewing == ViewController::GAME_LIST || ViewController::get()->getState().viewing == ViewController::SYSTEM_SELECT) + AudioManager::getInstance()->changePlaylist(ViewController::get()->getState().getSystem()->getTheme()); + else + AudioManager::getInstance()->playRandomMusic(); + } int lastTime = SDL_GetTicks(); int ps_time = SDL_GetTicks(); diff --git a/es-app/src/views/SystemView.cpp b/es-app/src/views/SystemView.cpp index a501d2d43..a6ca169be 100644 --- a/es-app/src/views/SystemView.cpp +++ b/es-app/src/views/SystemView.cpp @@ -835,7 +835,8 @@ void SystemView::onCursorChanged(const CursorState& state) TextToSpeech::getInstance()->say(getSelected()->getFullName()); if (!mCarousel.scrollSound.empty()) - Sound::get(mCarousel.scrollSound)->play(); + if (Settings::getInstance()->getBool("EnableSounds")) + Sound::get(mCarousel.scrollSound)->play(); int oldCursor = mLastCursor; mLastCursor = mCursor; diff --git a/es-app/src/views/gamelist/ISimpleGameListView.cpp b/es-app/src/views/gamelist/ISimpleGameListView.cpp index ba44afd88..cc5e73b3e 100644 --- a/es-app/src/views/gamelist/ISimpleGameListView.cpp +++ b/es-app/src/views/gamelist/ISimpleGameListView.cpp @@ -234,7 +234,8 @@ bool ISimpleGameListView::input(InputConfig* config, Input input) if (idx != nullptr && idx->hasRelevency()) return true; - Sound::getFromTheme(mTheme, getName(), "menuOpen")->play(); + if (Settings::getInstance()->getBool("EnableSounds")) + Sound::getFromTheme(mTheme, getName(), "menuOpen")->play(); mWindow->pushGui(new GuiGamelistOptions(mWindow, this, this->mRoot->getSystem())); return true; } @@ -267,7 +268,8 @@ bool ISimpleGameListView::input(InputConfig* config, Input input) populateList(folder->getChildrenListToDisplay()); setCursor(top); - Sound::getFromTheme(getTheme(), getName(), "back")->play(); + if (Settings::getInstance()->getBool("EnableSounds")) + Sound::getFromTheme(getTheme(), getName(), "back")->play(); } else if (mPopupSelfReference) { @@ -320,7 +322,8 @@ void ISimpleGameListView::showSelectedGameOptions() if (cursor == nullptr) return; - Sound::getFromTheme(mTheme, getName(), "menuOpen")->play(); + if (Settings::getInstance()->getBool("EnableSounds")) + Sound::getFromTheme(mTheme, getName(), "menuOpen")->play(); mWindow->pushGui(new GuiGameOptions(mWindow, cursor)); } @@ -341,11 +344,13 @@ void ISimpleGameListView::showSelectedGameSaveSnapshots() if (SaveStateRepository::isEnabled(cursor)) { - Sound::getFromTheme(mTheme, getName(), "menuOpen")->play(); + if (Settings::getInstance()->getBool("EnableSounds")) + Sound::getFromTheme(mTheme, getName(), "menuOpen")->play(); mWindow->pushGui(new GuiSaveState(mWindow, cursor, [this, cursor](SaveState state) { - Sound::getFromTheme(getTheme(), getName(), "launch")->play(); + if (Settings::getInstance()->getBool("EnableSounds")) + Sound::getFromTheme(getTheme(), getName(), "launch")->play(); LaunchGameOptions options; options.saveStateInfo = state; @@ -375,7 +380,8 @@ void ISimpleGameListView::launchSelectedGame() populateList(folder->getChildrenListToDisplay()); setCursor(top); - Sound::getFromTheme(getTheme(), getName(), "back")->play(); + if (Settings::getInstance()->getBool("EnableSounds")) + Sound::getFromTheme(getTheme(), getName(), "back")->play(); } else { @@ -386,7 +392,8 @@ void ISimpleGameListView::launchSelectedGame() { mWindow->pushGui(new GuiSaveState(mWindow, cursor, [this, cursor](SaveState state) { - Sound::getFromTheme(getTheme(), getName(), "launch")->play(); + if (Settings::getInstance()->getBool("EnableSounds")) + Sound::getFromTheme(getTheme(), getName(), "launch")->play(); LaunchGameOptions options; options.saveStateInfo = state; @@ -396,7 +403,8 @@ void ISimpleGameListView::launchSelectedGame() } else { - Sound::getFromTheme(getTheme(), getName(), "launch")->play(); + if (Settings::getInstance()->getBool("EnableSounds")) + Sound::getFromTheme(getTheme(), getName(), "launch")->play(); launch(cursor); } } diff --git a/es-core/src/Settings.cpp b/es-core/src/Settings.cpp index fcf29536e..3be1dfa48 100644 --- a/es-core/src/Settings.cpp +++ b/es-core/src/Settings.cpp @@ -109,7 +109,7 @@ void Settings::setDefaults() mBoolMap["FirstJoystickOnly"] = false; #ifdef _ENABLEEMUELEC - mBoolMap["EnableSounds"] = true; + mBoolMap["EnableSounds"] = false; #else mBoolMap["EnableSounds"] = false; #endif @@ -171,7 +171,7 @@ void Settings::setDefaults() mBoolMap["StretchVideoOnScreenSaver"] = false; mStringMap["PowerSaverMode"] = "default"; // batocera - mBoolMap["StopMusicOnScreenSaver"] = false; + //mBoolMap["StopMusicOnScreenSaver"] = false; mBoolMap["RetroachievementsMenuitem"] = true; mIntMap["ScreenSaverSwapImageTimeout"] = 10000; @@ -214,8 +214,8 @@ void Settings::setDefaults() mIntMap["ScreenSaverSwapVideoTimeout"] = 30000; mBoolMap["EnableVideoPreviews"] = true; - mBoolMap["VideoAudio"] = true; - mBoolMap["ScreenSaverVideoMute"] = false; +// mBoolMap["VideoAudio"] = true; + //mBoolMap["ScreenSaverVideoMute"] = false; mBoolMap["VideoLowersMusic"] = true; mBoolMap["VolumePopup"] = true; diff --git a/es-core/src/components/VideoVlcComponent.cpp b/es-core/src/components/VideoVlcComponent.cpp index 844573cfd..3be1cdef9 100644 --- a/es-core/src/components/VideoVlcComponent.cpp +++ b/es-core/src/components/VideoVlcComponent.cpp @@ -498,7 +498,7 @@ void VideoVlcComponent::handleLooping() } } - if (!getPlayAudio() || (!mScreensaverMode && Settings::getInstance()->getBool("VideoAudio") == false) || (Settings::getInstance()->getBool("ScreenSaverVideoMute") == true && mScreensaverMode)) + if (!getPlayAudio() || (!mScreensaverMode && Settings::getInstance()->getBool("EnableSounds") == false) ) { libvlc_audio_set_mute(mMediaPlayer, 1); } else { @@ -545,7 +545,7 @@ void VideoVlcComponent::startVideo() mMedia = libvlc_media_new_path(mVLC, path.c_str()); if (mMedia) { - // use : vlc –long-help + // use : vlc �long-help // WIN32 ? libvlc_media_add_option(mMedia, ":avcodec-hw=dxva2"); // RPI/OMX ? libvlc_media_add_option(mMedia, ":codec=mediacodec,iomx,all"); . @@ -620,7 +620,7 @@ void VideoVlcComponent::startVideo() if (hasAudioTrack) { - if (!getPlayAudio() || (!mScreensaverMode && Settings::getInstance()->getBool("VideoAudio") == false) || (Settings::getInstance()->getBool("ScreenSaverVideoMute") == true && mScreensaverMode)) + if (!getPlayAudio() || (!mScreensaverMode && Settings::getInstance()->getBool("EnableSounds") == false)) libvlc_audio_set_mute(mMediaPlayer, 1); else libvlc_audio_set_mute(mMediaPlayer, 0); From 388cd3947422f8615c743cabc25bb1b45c87f554 Mon Sep 17 00:00:00 2001 From: Paul Reioux Date: Tue, 28 May 2024 16:20:59 -0700 Subject: [PATCH 2/4] ES: Sound: add a proper callback and clean up --- es-core/src/Sound.cpp | 26 ++++++++++++++++++++------ es-core/src/Sound.h | 3 +++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/es-core/src/Sound.cpp b/es-core/src/Sound.cpp index 5fcdb5b36..f3444659d 100644 --- a/es-core/src/Sound.cpp +++ b/es-core/src/Sound.cpp @@ -10,8 +10,9 @@ std::map< std::string, std::shared_ptr > Sound::sMap; std::shared_ptr Sound::get(const std::string& path) { auto it = sMap.find(path); - if (it != sMap.cend()) + if (it != sMap.cend()) { return it->second; + } std::shared_ptr sound = std::shared_ptr(new Sound(path)); @@ -59,13 +60,16 @@ void Sound::init() deinit(); if (!AudioManager::isInitialized()) + { + LOG(LogError) << "Sound::init: AM not initialized"; return; + } if (mPath.empty() || !Utils::FileSystem::exists(mPath)) + { + LOG(LogError) << "Sound::init: Empty path"; return; - - if (!Settings::getInstance()->getBool("EnableSounds")) - return; + } //load wav file via SDL mSampleData = Mix_LoadWAV(mPath.c_str()); @@ -83,22 +87,32 @@ void Sound::deinit() stop(); Mix_FreeChunk(mSampleData); - mSampleData = nullptr; + mSampleData = nullptr; +} + +void Sound::mixEnd_callback(int channel) +{ + //halt all channels + Mix_HaltChannel(-1); } void Sound::play() { if (mSampleData == nullptr) + { + LOG(LogError) << "Sound::play(): nullptr"; return; + } if (!Settings::getInstance()->getBool("EnableSounds")) return; mPlayingChannel = Mix_PlayChannel(-1, mSampleData, 0); + Mix_ChannelFinished(mixEnd_callback); } bool Sound::isPlaying() const -{ +{ return (mPlayingChannel >= 0); } diff --git a/es-core/src/Sound.h b/es-core/src/Sound.h index 58462fa8e..178f2f6a9 100644 --- a/es-core/src/Sound.h +++ b/es-core/src/Sound.h @@ -30,9 +30,12 @@ class Sound bool isPlaying() const; void stop(); + static void mixEnd_callback(int channel); + private: Sound(const std::string & path = ""); static std::map< std::string, std::shared_ptr > sMap; + }; #endif // ES_CORE_SOUND_H From c6107dc8b8b9bfb8a1232506da0cde927ec8c371 Mon Sep 17 00:00:00 2001 From: Paul Reioux Date: Tue, 28 May 2024 16:28:54 -0700 Subject: [PATCH 3/4] ES: AudioManager: clean up code and remove unused legacy code --- es-core/src/AudioManager.cpp | 54 ++++++++++++++++++++++++++---------- es-core/src/AudioManager.h | 8 ++++-- 2 files changed, 46 insertions(+), 16 deletions(-) diff --git a/es-core/src/AudioManager.cpp b/es-core/src/AudioManager.cpp index a472dc066..7969cc926 100644 --- a/es-core/src/AudioManager.cpp +++ b/es-core/src/AudioManager.cpp @@ -51,6 +51,16 @@ bool AudioManager::isInitialized() return sInstance->mInitialized; } +int AudioManager::openMixerDevice() +{ + return Mix_OpenAudio(48000, MIX_DEFAULT_FORMAT, 2, 4096); +} + +void AudioManager::closeMixerDevice() +{ + Mix_CloseAudio(); +} + void AudioManager::init() { if (mInitialized) @@ -66,9 +76,12 @@ void AudioManager::init() return; } + int mixerOpened; // Open the audio device and pause - if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 4096) < 0) + if (mixerOpened = openMixerDevice() < 0) + { LOG(LogError) << "MUSIC Error - Unable to open SDLMixer audio: " << SDL_GetError() << std::endl; + } else { LOG(LogInfo) << "SDL AUDIO Initialized"; @@ -76,32 +89,48 @@ void AudioManager::init() // Reload known sounds for (unsigned int i = 0; i < sSoundVector.size(); i++) + { sSoundVector[i]->init(); + } + Mix_HaltChannel(-1); } } +void AudioManager::freeSounds() +{ + // Free known sounds from memory + for (unsigned int i = 0; i < sSoundVector.size(); i++) + sSoundVector[i]->deinit(); +} + void AudioManager::deinit() +{ + LOG(LogDebug) << "AudioManager::deinit"; + + freeSounds(); + tearDown(); + + LOG(LogInfo) << "SDL AUDIO Deinitialized"; +} + +void AudioManager::tearDown() { if (!mInitialized) return; - LOG(LogDebug) << "AudioManager::deinit"; + LOG(LogDebug) << "AudioManager::tearDown"; mInitialized = false; //stop all playback - stop(); + stopSound(); stopMusic(); - // Free known sounds from memory - for (unsigned int i = 0; i < sSoundVector.size(); i++) - sSoundVector[i]->deinit(); - Mix_HookMusicFinished(nullptr); Mix_HaltMusic(); //completely tear down SDL audio. else SDL hogs audio resources and emulators might fail to start... - Mix_CloseAudio(); + closeMixerDevice(); SDL_QuitSubSystem(SDL_INIT_AUDIO); LOG(LogInfo) << "SDL AUDIO Deinitialized"; @@ -128,17 +157,14 @@ void AudioManager::unregisterSound(std::shared_ptr & sound) LOG(LogWarning) << "AudioManager Error - tried to unregister a sound that wasn't registered!"; } -void AudioManager::play() -{ - getInstance(); -} - -void AudioManager::stop() +void AudioManager::stopSound() { // Stop playing all Sounds for (unsigned int i = 0; i < sSoundVector.size(); i++) + { if (sSoundVector.at(i)->isPlaying()) sSoundVector[i]->stop(); + } } // batocera diff --git a/es-core/src/AudioManager.h b/es-core/src/AudioManager.h index fa1803940..d856281f5 100644 --- a/es-core/src/AudioManager.h +++ b/es-core/src/AudioManager.h @@ -39,12 +39,15 @@ class AudioManager void init(); void deinit(); + void tearDown(); + + int openMixerDevice(); + void closeMixerDevice(); void registerSound(std::shared_ptr & sound); void unregisterSound(std::shared_ptr & sound); - void play(); - void stop(); + void stopSound(); // batocera void playRandomMusic(bool continueIfPlaying = true); @@ -74,6 +77,7 @@ class AudioManager void setSongName(const std::string& song); bool mSongNameChanged; + void freeSounds(); }; #endif // ES_CORE_AUDIO_MANAGER_H From 2744923c830816b7dfa36a22a79d4c5aa6622d1b Mon Sep 17 00:00:00 2001 From: Paul Reioux Date: Tue, 28 May 2024 18:07:36 -0700 Subject: [PATCH 4/4] ES: GuiMenu: add mono/stereo driver menu to support virtual audio device --- es-app/src/guis/GuiMenu.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index a967c4146..0fb0ef912 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -3831,6 +3831,26 @@ void GuiMenu::openSoundSettings() // s->addWithLabel(_("ENABLE VIDEO PREVIEW AUDIO"), video_audio); // s->addSaveFunc([video_audio] { Settings::getInstance()->setBool("VideoAudio", video_audio->getState()); }); + const std::string audioVDriverScript = "/usr/bin/audio_vdriver.sh"; + if (Utils::FileSystem::exists(audioVDriverScript)) { + auto optionsVAudioDriver = std::make_shared >(mWindow, _("AUDIO PLAYBACK DRIVER"), false); + std::string selectedVAudioDriver = std::string(getShOutput(R"(/usr/bin/audio_vdriver.sh)")); + + std::string a; + for(std::stringstream ss(getShOutput(R"(/usr/bin/audio_vdriver.sh --options)")); getline(ss, a, ' '); ) { + optionsVAudioDriver->add(a, a, a == selectedVAudioDriver); + } + + s->addWithLabel(_("AUDIO PLAYBACK DRIVER"), optionsVAudioDriver); + + Window *window = mWindow; + s->addSaveFunc([this, window, audioVDriverScript, optionsVAudioDriver, selectedVAudioDriver] { + if (optionsVAudioDriver->changed()) { + runSystemCommand(audioVDriverScript + " " + optionsVAudioDriver->getSelected(), "", nullptr); + } + }); + } + mWindow->pushGui(s); }