Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qt: try to fix sound effects #15482

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions rpcs3/rpcs3qt/gui_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QSoundEffect> sound_effect = std::make_unique<QSoundEffect>();
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));
}
});
};
Expand Down
3 changes: 2 additions & 1 deletion rpcs3/rpcs3qt/gui_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <memory>
#include <functional>
#include <deque>

class gs_frame;
class main_window;
Expand Down Expand Up @@ -96,7 +97,7 @@ class gui_application : public QApplication, public main_application
QTimer m_timer;
QElapsedTimer m_timer_playtime;

QSoundEffect m_sound_effect{};
std::deque<std::unique_ptr<QSoundEffect>> m_sound_effects{};

std::shared_ptr<emu_settings> m_emu_settings;
std::shared_ptr<gui_settings> m_gui_settings;
Expand Down