From 52cfa69a6e34d4a2d604999366273f87331c36c5 Mon Sep 17 00:00:00 2001 From: maelstrom Date: Tue, 12 Aug 2025 01:05:33 +0200 Subject: [PATCH] fix(editor): replaced QSoundEffect with Miniaudio --- core/deps.cmake | 2 ++ editor/CMakeLists.txt | 2 +- editor/main.cpp | 10 ++++++++++ editor/mainglwidget.cpp | 10 ++++------ editor/mainwindow.cpp | 9 +++------ 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/core/deps.cmake b/core/deps.cmake index 207588f..46d0823 100644 --- a/core/deps.cmake +++ b/core/deps.cmake @@ -27,4 +27,6 @@ CPMAddPackage("gh:nothings/stb#8cfb1605c02aee9fb6eb5d8ea559017745bd9a16") # 2.14 CPMAddPackage("gh:WohlSoft/LuaJIT#a5da8f4a31972b74254f00969111b8b7a07cf584") # v2.1 set(LUAJIT_INCLUDE_DIRS ${LuaJIT_SOURCE_DIR}/src) +CPMAddPackage("gh:mackron/miniaudio#0.11.22") + set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PREV_BIN_PATH}) \ No newline at end of file diff --git a/editor/CMakeLists.txt b/editor/CMakeLists.txt index 145445a..4e5e078 100644 --- a/editor/CMakeLists.txt +++ b/editor/CMakeLists.txt @@ -37,7 +37,7 @@ set(PROJECT_SOURCES qt_add_executable(editor MANUAL_FINALIZATION ${PROJECT_SOURCES}) target_include_directories(editor PRIVATE .) -target_link_libraries(editor PRIVATE openblocks Qt6::Widgets Qt6::OpenGLWidgets ${QSCINTILLA_LIBRARY}) +target_link_libraries(editor PRIVATE openblocks Qt6::Widgets Qt6::OpenGLWidgets ${QSCINTILLA_LIBRARY} miniaudio) set_target_properties(editor PROPERTIES WIN32_EXECUTABLE ON diff --git a/editor/main.cpp b/editor/main.cpp index 2097afa..8b94731 100644 --- a/editor/main.cpp +++ b/editor/main.cpp @@ -9,6 +9,9 @@ #include #include #include +#include + +ma_engine miniaudio; int main(int argc, char *argv[]) { @@ -23,10 +26,17 @@ int main(int argc, char *argv[]) Logger::init(); + ma_result res = ma_engine_init(NULL, &miniaudio); + if (res != MA_SUCCESS) { + Logger::fatalErrorf("Failed to initialize Miniaudio withe error [%d]", res); + panic(); + } + MainWindow w; w.show(); int result = a.exec(); + ma_engine_uninit(&miniaudio); Logger::finish(); return result; } diff --git a/editor/mainglwidget.cpp b/editor/mainglwidget.cpp index b9b8c4f..740f708 100755 --- a/editor/mainglwidget.cpp +++ b/editor/mainglwidget.cpp @@ -2,8 +2,8 @@ #include #include #include +#include #include -#include #include #include "./ui_mainwindow.h" #include "mainglwidget.h" @@ -45,12 +45,10 @@ void MainGLWidget::initializeGL() { renderInit(width(), height()); } +extern ma_engine miniaudio; inline void playSound(QString path) { - return; // TODO: Fix pulseaudio bug causing stutters - QSoundEffect *sound = new QSoundEffect; - sound->setSource(QUrl::fromLocalFile(path)); - sound->play(); - sound->connect(sound, &QSoundEffect::playingChanged, [=]() { /* Thank you QSound source code! */ sound->deleteLater(); return false; }); + ma_engine_stop(&miniaudio); + ma_engine_play_sound(&miniaudio, path.toStdString().c_str(), NULL); } extern int vpx, vpy; diff --git a/editor/mainwindow.cpp b/editor/mainwindow.cpp index 9de8b47..61513e6 100644 --- a/editor/mainwindow.cpp +++ b/editor/mainwindow.cpp @@ -20,13 +20,13 @@ #include #include #include -#include #include #include #include #include #include #include +#include #include #ifdef _NDEBUG @@ -58,12 +58,9 @@ void logQtMessage(QtMsgType type, const QMessageLogContext &context, const QStri // if (defaultMessageHandler) defaultMessageHandler(type, context, msg); } +extern ma_engine miniaudio; inline void playSound(QString path) { - return; // TODO: Fix pulseaudio bug causing stutters - QSoundEffect *sound = new QSoundEffect; - sound->setSource(QUrl::fromLocalFile(path)); - sound->play(); - sound->connect(sound, &QSoundEffect::playingChanged, [=]() { /* Thank you QSound source code! */ sound->deleteLater(); return false; }); + ma_engine_play_sound(&miniaudio, path.toStdString().c_str(), NULL); } MainWindow::MainWindow(QWidget *parent)