From f73707df4f1aab0e59eae9de2f8e1d69764e8ca4 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sat, 11 Feb 2023 17:10:37 +0100 Subject: [PATCH] Implement streaming --- Source/CMakeLists.txt | 2 +- Source/engine/sound.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 7e1498feb..caf13c7b1 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -282,7 +282,7 @@ endif() if(NOT NOSOUND) if(PS2) - target_link_libraries(libdevilutionx PUBLIC audsrv) + target_link_libraries(libdevilutionx PUBLIC audsrv ps2snd) else() target_link_libraries(libdevilutionx PUBLIC SDL_audiolib::SDL_audiolib) endif() diff --git a/Source/engine/sound.cpp b/Source/engine/sound.cpp index 25bc67da3..4f00debe8 100644 --- a/Source/engine/sound.cpp +++ b/Source/engine/sound.cpp @@ -10,6 +10,11 @@ #include #include +#ifdef PS2 +#include +#include +#endif + #include #include "engine/assets.hpp" @@ -244,6 +249,31 @@ void snd_init() duplicateSoundsMutex.emplace(); #else audsrv_set_volume(MAX_VOLUME); + + if (SifLoadModule("host:ps2snd.irx", 0, NULL) < 0) { + LogError(LogCategory::Audio, "Failed to initialize audio: ps2snd"); + } + + if (sceSdInit(0) < 0) { + LogError(LogCategory::Audio, "Failed to initialize audio: sceSdInit"); + } + + ///* Setup master volumes for both cores */ + sceSdSetParam(0 | SD_PARAM_MVOLL, 0x3fff); + sceSdSetParam(0 | SD_PARAM_MVOLR, 0x3fff); + sceSdSetParam(1 | SD_PARAM_MVOLL, 0x3fff); + sceSdSetParam(1 | SD_PARAM_MVOLR, 0x3fff); + + if (sndStreamOpen("host:spawn/music/slvla.adp", SD_VOICE(0,22) | (SD_VOICE(0,23)<<16), STREAM_END_CLOSE, 2097152-1024*32, 1024)<0) + { + LogError(LogCategory::Audio, "Failed to open stream"); + } + + if (sndStreamPlay()<0) + { + LogError(LogCategory::Audio, "Failed to play stream"); + } + #endif gbSndInited = true; }