From e48bd2958444d365577b4f7af4ecdbac1268c917 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Fri, 19 Apr 2024 03:13:46 +0200 Subject: [PATCH] Qt: try to fix sound effects Don't re-use sound effect objects. Allow 3 sounds simultaneously. --- rpcs3/rpcs3qt/gui_application.cpp | 18 +++++++++++++----- rpcs3/rpcs3qt/gui_application.h | 3 ++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/rpcs3/rpcs3qt/gui_application.cpp b/rpcs3/rpcs3qt/gui_application.cpp index 0304630815..ee4bb469e7 100644 --- a/rpcs3/rpcs3qt/gui_application.cpp +++ b/rpcs3/rpcs3qt/gui_application.cpp @@ -606,11 +606,19 @@ void gui_application::InitializeCallbacks() { if (fs::is_file(path)) { - m_sound_effect.stop(); - m_sound_effect.setSource(QUrl::fromLocalFile(qstr(path))); - m_sound_effect.setVolume(g_cfg.audio.volume * 0.01f); - m_sound_effect.setLoopCount(1); - m_sound_effect.play(); + // Allow to play 3 sound effects at the same time + while (m_sound_effects.size() >= 3) + { + m_sound_effects.pop_front(); + } + + // Create a new sound effect. Re-using the same object seems to be broken for some users starting with Qt 6.6.3. + std::unique_ptr sound_effect = std::make_unique(); + sound_effect->setSource(QUrl::fromLocalFile(qstr(path))); + sound_effect->setVolume(g_cfg.audio.volume * 0.01f); + sound_effect->play(); + + m_sound_effects.push_back(std::move(sound_effect)); } }); }; diff --git a/rpcs3/rpcs3qt/gui_application.h b/rpcs3/rpcs3qt/gui_application.h index 3ced20951b..6a0be442c8 100644 --- a/rpcs3/rpcs3qt/gui_application.h +++ b/rpcs3/rpcs3qt/gui_application.h @@ -16,6 +16,7 @@ #include #include +#include class gs_frame; class main_window; @@ -96,7 +97,7 @@ private: QTimer m_timer; QElapsedTimer m_timer_playtime; - QSoundEffect m_sound_effect{}; + std::deque> m_sound_effects{}; std::shared_ptr m_emu_settings; std::shared_ptr m_gui_settings;