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

Build for PS2 #5238

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
13 changes: 13 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ jobs:
- run: cmake -S. -Bbuild -DM68K_CPU=68040 -DM68K_FPU=hard -DM68K_COMMON="-s -fbbb=- -ffast-math -O2"
- run: cd build && make -j2
- store_artifacts: {path: ./build/devilutionx, destination: devilutionx_m68k}
ps2:
docker:
- image: ps2dev/ps2dev:latest
working_directory: ~/repo
steps:
- checkout
- run: apk --no-cache add git cmake make gmp mpc1 mpfr
- run: git clone https://github.com/fjtrujy/ps2_drivers
- run: cd ps2_drivers && make clean all install
- run: cmake -S. -Bbuild -DCMAKE_TOOLCHAIN_FILE=/usr/local/ps2dev/ps2sdk/ps2dev.cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo
- run: cmake --build build -j 2
- store_artifacts: {path: ./build/devilutionx.elf, destination: devilutionx.elf}
vita:
docker:
- image: vitasdk/vitasdk
Expand All @@ -74,4 +86,5 @@ workflows:
- switch
- 3ds
- amigaos-m68k
- ps2
- vita
4 changes: 4 additions & 0 deletions CMake/Platforms.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ if(VITA)
include(platforms/vita)
endif()

if(PS2)
include(platforms/ps2)
endif()

if(PS4)
include(platforms/ps4)
endif()
Expand Down
22 changes: 22 additions & 0 deletions CMake/platforms/ps2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
set(NONET ON)
set(DISABLE_DEMOMODE ON)
set(ASAN OFF)
set(UBSAN OFF)
set(BUILD_TESTING OFF)

set(DEVILUTIONX_SYSTEM_SDL2 OFF)
set(DEVILUTIONX_SYSTEM_BZIP2 OFF)
set(DEVILUTIONX_SYSTEM_LIBFMT OFF)
set(PREFILL_PLAYER_NAME ON)
set(NOEXIT ON)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/threads-stub")

set(BUILD_ASSETS_MPQ OFF)
set(UNPACKED_MPQS ON)

# -fmerge-all-constants saves ~4 KiB
set(_extra_flags "-fmerge-all-constants -fipa-pta")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_extra_flags}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_extra_flags}")

2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ include(Dependencies)
add_subdirectory(Source)

set(BIN_TARGET devilutionx)
if(NINTENDO_3DS)
if(NINTENDO_3DS OR PS2)
set(BIN_TARGET ${BIN_TARGET}.elf)
endif()

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ If you want to help test the latest development stage of the next version (make
[![Original Xbox](https://github.com/diasurgical/devilutionX/actions/workflows/xbox_nxdk.yml/badge.svg)](https://github.com/diasurgical/devilutionX/actions/workflows/xbox_nxdk.yml?query=branch%3Amaster)
[![Xbox One/Series](https://github.com/diasurgical/devilutionX/actions/workflows/xbox_one.yml/badge.svg)](https://github.com/diasurgical/devilutionX/actions/workflows/xbox_one.yml?query=branch%3Amaster)

Linux x86-64, Switch, Vita, 3DS, Amiga, [![CircleCI](https://circleci.com/gh/diasurgical/devilutionX.svg?style=shield)](https://app.circleci.com/pipelines/github/diasurgical/devilutionX?branch=master)
Linux x86-64, Switch, PS2, Vita, 3DS, Amiga, [![CircleCI](https://circleci.com/gh/diasurgical/devilutionX.svg?style=shield)](https://app.circleci.com/pipelines/github/diasurgical/devilutionX?branch=master)

# Building from Source

Expand Down
10 changes: 8 additions & 2 deletions Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,10 @@ else()
list(APPEND libdevilutionx_SRCS
effects.cpp
engine/sound.cpp
utils/push_aulib_decoder.cpp
utils/soundsample.cpp)
if(NOT PS2)
list(APPEND libdevilutionx_SRCS utils/push_aulib_decoder.cpp)
endif()
endif()

if(NOT NONET)
Expand Down Expand Up @@ -279,7 +281,11 @@ if(NOT NONET)
endif()

if(NOT NOSOUND)
target_link_libraries(libdevilutionx PUBLIC SDL_audiolib::SDL_audiolib)
if(PS2)
target_link_libraries(libdevilutionx PUBLIC audsrv ps2snd)
else()
target_link_libraries(libdevilutionx PUBLIC SDL_audiolib::SDL_audiolib)
endif()
endif()

if(NOT NONET AND NOT DISABLE_ZERO_TIER)
Expand Down
86 changes: 43 additions & 43 deletions Source/effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,46 +737,46 @@ TSFX sgSFX[] = {
/*PS_WARR12*/ { sfx_STREAM | sfx_WARRIOR, "sfx\\warrior\\warior12.wav", nullptr },
/*PS_WARR13*/ { sfx_WARRIOR, "sfx\\warrior\\warior13.wav", nullptr },
/*PS_WARR14*/ { sfx_WARRIOR, "sfx\\warrior\\warior14.wav", nullptr },
/*PS_WARR14B*/ { sfx_WARRIOR, "sfx\\warrior\\wario14b.wav", nullptr },
/*PS_WARR14C*/ { sfx_WARRIOR, "sfx\\warrior\\wario14c.wav", nullptr },
/*PS_WARR14B*/ { sfx_STREAM, "sfx\\warrior\\wario14b.wav", nullptr },
/*PS_WARR14C*/ { sfx_STREAM, "sfx\\warrior\\wario14c.wav", nullptr },
/*PS_WARR15*/ { sfx_WARRIOR, "sfx\\warrior\\warior15.wav", nullptr },
/*PS_WARR15B*/ { sfx_WARRIOR, "sfx\\warrior\\wario15b.wav", nullptr },
/*PS_WARR15C*/ { sfx_WARRIOR, "sfx\\warrior\\wario15c.wav", nullptr },
/*PS_WARR15B*/ { sfx_STREAM, "sfx\\warrior\\wario15b.wav", nullptr },
/*PS_WARR15C*/ { sfx_STREAM, "sfx\\warrior\\wario15c.wav", nullptr },
/*PS_WARR16*/ { sfx_WARRIOR, "sfx\\warrior\\warior16.wav", nullptr },
/*PS_WARR16B*/ { sfx_WARRIOR, "sfx\\warrior\\wario16b.wav", nullptr },
/*PS_WARR16C*/ { sfx_WARRIOR, "sfx\\warrior\\wario16c.wav", nullptr },
/*PS_WARR17*/ { sfx_WARRIOR, "sfx\\warrior\\warior17.wav", nullptr },
/*PS_WARR18*/ { sfx_WARRIOR, "sfx\\warrior\\warior18.wav", nullptr },
/*PS_WARR19*/ { sfx_WARRIOR, "sfx\\warrior\\warior19.wav", nullptr },
/*PS_WARR20*/ { sfx_WARRIOR, "sfx\\warrior\\warior20.wav", nullptr },
/*PS_WARR21*/ { sfx_WARRIOR, "sfx\\warrior\\warior21.wav", nullptr },
/*PS_WARR22*/ { sfx_WARRIOR, "sfx\\warrior\\warior22.wav", nullptr },
/*PS_WARR23*/ { sfx_WARRIOR, "sfx\\warrior\\warior23.wav", nullptr },
/*PS_WARR16B*/ { sfx_STREAM, "sfx\\warrior\\wario16b.wav", nullptr },
/*PS_WARR16C*/ { sfx_STREAM, "sfx\\warrior\\wario16c.wav", nullptr },
/*PS_WARR17*/ { sfx_STREAM, "sfx\\warrior\\warior17.wav", nullptr },
/*PS_WARR18*/ { sfx_STREAM, "sfx\\warrior\\warior18.wav", nullptr },
Copy link
Collaborator

@glebm glebm Sep 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct.
This file is "Not a chance" and it is actually used (HeroSpeech::NotAChance)

/*PS_WARR19*/ { sfx_STREAM, "sfx\\warrior\\warior19.wav", nullptr },
/*PS_WARR20*/ { sfx_STREAM, "sfx\\warrior\\warior20.wav", nullptr },
/*PS_WARR21*/ { sfx_STREAM, "sfx\\warrior\\warior21.wav", nullptr },
/*PS_WARR22*/ { sfx_STREAM, "sfx\\warrior\\warior22.wav", nullptr },
/*PS_WARR23*/ { sfx_STREAM, "sfx\\warrior\\warior23.wav", nullptr },
/*PS_WARR24*/ { sfx_WARRIOR, "sfx\\warrior\\warior24.wav", nullptr },
/*PS_WARR25*/ { sfx_WARRIOR, "sfx\\warrior\\warior25.wav", nullptr },
/*PS_WARR26*/ { sfx_WARRIOR, "sfx\\warrior\\warior26.wav", nullptr },
/*PS_WARR25*/ { sfx_STREAM, "sfx\\warrior\\warior25.wav", nullptr },
/*PS_WARR26*/ { sfx_STREAM, "sfx\\warrior\\warior26.wav", nullptr },
/*PS_WARR27*/ { sfx_WARRIOR, "sfx\\warrior\\warior27.wav", nullptr },
/*PS_WARR28*/ { sfx_WARRIOR, "sfx\\warrior\\warior28.wav", nullptr },
/*PS_WARR28*/ { sfx_STREAM, "sfx\\warrior\\warior28.wav", nullptr },
/*PS_WARR29*/ { sfx_WARRIOR, "sfx\\warrior\\warior29.wav", nullptr },
/*PS_WARR30*/ { sfx_WARRIOR, "sfx\\warrior\\warior30.wav", nullptr },
/*PS_WARR31*/ { sfx_WARRIOR, "sfx\\warrior\\warior31.wav", nullptr },
/*PS_WARR32*/ { sfx_WARRIOR, "sfx\\warrior\\warior32.wav", nullptr },
/*PS_WARR33*/ { sfx_WARRIOR, "sfx\\warrior\\warior33.wav", nullptr },
/*PS_WARR30*/ { sfx_STREAM, "sfx\\warrior\\warior30.wav", nullptr },
/*PS_WARR31*/ { sfx_STREAM, "sfx\\warrior\\warior31.wav", nullptr },
/*PS_WARR32*/ { sfx_STREAM, "sfx\\warrior\\warior32.wav", nullptr },
/*PS_WARR33*/ { sfx_STREAM, "sfx\\warrior\\warior33.wav", nullptr },
/*PS_WARR34*/ { sfx_WARRIOR, "sfx\\warrior\\warior34.wav", nullptr },
/*PS_WARR35*/ { sfx_WARRIOR, "sfx\\warrior\\warior35.wav", nullptr },
/*PS_WARR36*/ { sfx_WARRIOR, "sfx\\warrior\\warior36.wav", nullptr },
/*PS_WARR37*/ { sfx_WARRIOR, "sfx\\warrior\\warior37.wav", nullptr },
/*PS_WARR38*/ { sfx_WARRIOR, "sfx\\warrior\\warior38.wav", nullptr },
/*PS_WARR39*/ { sfx_WARRIOR, "sfx\\warrior\\warior39.wav", nullptr },
/*PS_WARR40*/ { sfx_WARRIOR, "sfx\\warrior\\warior40.wav", nullptr },
/*PS_WARR41*/ { sfx_WARRIOR, "sfx\\warrior\\warior41.wav", nullptr },
/*PS_WARR42*/ { sfx_WARRIOR, "sfx\\warrior\\warior42.wav", nullptr },
/*PS_WARR36*/ { sfx_STREAM, "sfx\\warrior\\warior36.wav", nullptr },
/*PS_WARR37*/ { sfx_STREAM, "sfx\\warrior\\warior37.wav", nullptr },
/*PS_WARR38*/ { sfx_STREAM, "sfx\\warrior\\warior38.wav", nullptr },
/*PS_WARR39*/ { sfx_STREAM, "sfx\\warrior\\warior39.wav", nullptr },
/*PS_WARR40*/ { sfx_STREAM, "sfx\\warrior\\warior40.wav", nullptr },
/*PS_WARR41*/ { sfx_STREAM, "sfx\\warrior\\warior41.wav", nullptr },
/*PS_WARR42*/ { sfx_STREAM, "sfx\\warrior\\warior42.wav", nullptr },
/*PS_WARR43*/ { sfx_WARRIOR, "sfx\\warrior\\warior43.wav", nullptr },
/*PS_WARR44*/ { sfx_WARRIOR, "sfx\\warrior\\warior44.wav", nullptr },
/*PS_WARR45*/ { sfx_WARRIOR, "sfx\\warrior\\warior45.wav", nullptr },
/*PS_WARR44*/ { sfx_STREAM, "sfx\\warrior\\warior44.wav", nullptr },
/*PS_WARR45*/ { sfx_STREAM, "sfx\\warrior\\warior45.wav", nullptr },
/*PS_WARR46*/ { sfx_WARRIOR, "sfx\\warrior\\warior46.wav", nullptr },
/*PS_WARR47*/ { sfx_WARRIOR, "sfx\\warrior\\warior47.wav", nullptr },
/*PS_WARR48*/ { sfx_WARRIOR, "sfx\\warrior\\warior48.wav", nullptr },
/*PS_WARR47*/ { sfx_STREAM, "sfx\\warrior\\warior47.wav", nullptr },
/*PS_WARR48*/ { sfx_STREAM, "sfx\\warrior\\warior48.wav", nullptr },
/*PS_WARR49*/ { sfx_WARRIOR, "sfx\\warrior\\warior49.wav", nullptr },
/*PS_WARR50*/ { sfx_WARRIOR, "sfx\\warrior\\warior50.wav", nullptr },
/*PS_WARR51*/ { sfx_STREAM | sfx_WARRIOR, "sfx\\warrior\\warior51.wav", nullptr },
Expand All @@ -785,29 +785,29 @@ TSFX sgSFX[] = {
/*PS_WARR54*/ { sfx_STREAM | sfx_WARRIOR, "sfx\\warrior\\warior54.wav", nullptr },
/*PS_WARR55*/ { sfx_STREAM | sfx_WARRIOR, "sfx\\warrior\\warior55.wav", nullptr },
/*PS_WARR56*/ { sfx_STREAM | sfx_WARRIOR, "sfx\\warrior\\warior56.wav", nullptr },
/*PS_WARR57*/ { sfx_WARRIOR, "sfx\\warrior\\warior57.wav", nullptr },
/*PS_WARR57*/ { sfx_STREAM, "sfx\\warrior\\warior57.wav", nullptr },
/*PS_WARR58*/ { sfx_STREAM | sfx_WARRIOR, "sfx\\warrior\\warior58.wav", nullptr },
/*PS_WARR59*/ { sfx_STREAM | sfx_WARRIOR, "sfx\\warrior\\warior59.wav", nullptr },
/*PS_WARR60*/ { sfx_STREAM | sfx_WARRIOR, "sfx\\warrior\\warior60.wav", nullptr },
/*PS_WARR61*/ { sfx_STREAM | sfx_WARRIOR, "sfx\\warrior\\warior61.wav", nullptr },
/*PS_WARR62*/ { sfx_STREAM | sfx_WARRIOR, "sfx\\warrior\\warior62.wav", nullptr },
/*PS_WARR63*/ { sfx_STREAM | sfx_WARRIOR, "sfx\\warrior\\warior63.wav", nullptr },
/*PS_WARR64*/ { sfx_WARRIOR, "sfx\\warrior\\warior64.wav", nullptr },
/*PS_WARR65*/ { sfx_WARRIOR, "sfx\\warrior\\warior65.wav", nullptr },
/*PS_WARR66*/ { sfx_WARRIOR, "sfx\\warrior\\warior66.wav", nullptr },
/*PS_WARR67*/ { sfx_WARRIOR, "sfx\\warrior\\warior67.wav", nullptr },
/*PS_WARR64*/ { sfx_STREAM, "sfx\\warrior\\warior64.wav", nullptr },
/*PS_WARR65*/ { sfx_STREAM, "sfx\\warrior\\warior65.wav", nullptr },
/*PS_WARR66*/ { sfx_STREAM, "sfx\\warrior\\warior66.wav", nullptr },
/*PS_WARR67*/ { sfx_STREAM, "sfx\\warrior\\warior67.wav", nullptr },
/*PS_WARR68*/ { sfx_WARRIOR, "sfx\\warrior\\warior68.wav", nullptr },
/*PS_WARR69*/ { sfx_WARRIOR, "sfx\\warrior\\warior69.wav", nullptr },
/*PS_WARR69B*/ { sfx_WARRIOR, "sfx\\warrior\\wario69b.wav", nullptr },
/*PS_WARR70*/ { sfx_WARRIOR, "sfx\\warrior\\warior70.wav", nullptr },
/*PS_WARR71*/ { sfx_WARRIOR, "sfx\\warrior\\warior71.wav", nullptr },
/*PS_WARR72*/ { sfx_WARRIOR, "sfx\\warrior\\warior72.wav", nullptr },
/*PS_WARR73*/ { sfx_WARRIOR, "sfx\\warrior\\warior73.wav", nullptr },
/*PS_WARR74*/ { sfx_WARRIOR, "sfx\\warrior\\warior74.wav", nullptr },
/*PS_WARR75*/ { sfx_WARRIOR, "sfx\\warrior\\warior75.wav", nullptr },
/*PS_WARR76*/ { sfx_WARRIOR, "sfx\\warrior\\warior76.wav", nullptr },
/*PS_WARR77*/ { sfx_WARRIOR, "sfx\\warrior\\warior77.wav", nullptr },
/*PS_WARR78*/ { sfx_WARRIOR, "sfx\\warrior\\warior78.wav", nullptr },
/*PS_WARR72*/ { sfx_STREAM, "sfx\\warrior\\warior72.wav", nullptr },
/*PS_WARR73*/ { sfx_STREAM, "sfx\\warrior\\warior73.wav", nullptr },
/*PS_WARR74*/ { sfx_STREAM, "sfx\\warrior\\warior74.wav", nullptr },
/*PS_WARR75*/ { sfx_STREAM, "sfx\\warrior\\warior75.wav", nullptr },
/*PS_WARR76*/ { sfx_STREAM, "sfx\\warrior\\warior76.wav", nullptr },
/*PS_WARR77*/ { sfx_STREAM, "sfx\\warrior\\warior77.wav", nullptr },
/*PS_WARR78*/ { sfx_STREAM, "sfx\\warrior\\warior78.wav", nullptr },
/*PS_WARR79*/ { sfx_WARRIOR, "sfx\\warrior\\warior79.wav", nullptr },
/*PS_WARR80*/ { sfx_STREAM | sfx_WARRIOR, "sfx\\warrior\\warior80.wav", nullptr },
/*PS_WARR81*/ { sfx_STREAM | sfx_WARRIOR, "sfx\\warrior\\warior81.wav", nullptr },
Expand Down
15 changes: 8 additions & 7 deletions Source/engine/load_cl2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ OwnedClxSpriteListOrSheet LoadCl2ListOrSheet(const char *pszName, PointerOrValue
template <size_t MaxCount>
OwnedClxSpriteSheet LoadMultipleCl2Sheet(tl::function_ref<const char *(size_t)> filenames, size_t count, uint16_t width)
{
StaticVector<AssetHandle, MaxCount> files;
StaticVector<AssetRef, MaxCount> files;
StaticVector<size_t, MaxCount> fileSizes;
const size_t sheetHeaderSize = 4 * count;
size_t totalSize = sheetHeaderSize;
for (size_t i = 0; i < count; ++i) {
const char *filename = filenames(i);
size_t size;
files.emplace_back(OpenAsset(filename, size));
if (!files.back().ok()) {
app_fatal(StrCat("Failed to open file:\n", filename, "\n\n", files.back().error()));
AssetRef file = FindAsset(filename);
if (!file.ok()) {
app_fatal(StrCat("Failed to open file:\n", filename, "\n\n", file.error()));
}
size_t size = file.size();
fileSizes.emplace_back(size);
totalSize += size;
}
Expand All @@ -47,8 +47,9 @@ OwnedClxSpriteSheet LoadMultipleCl2Sheet(tl::function_ref<const char *(size_t)>
size_t accumulatedSize = sheetHeaderSize;
for (size_t i = 0; i < count; ++i) {
const size_t size = fileSizes[i];
if (!files[i].read(&data[accumulatedSize], size))
app_fatal(StrCat("Read failed:\n", files[i].error()));
AssetHandle file = OpenAsset(filenames(i));
if (!file.read(&data[accumulatedSize], size))
app_fatal(StrCat("Read failed:\n", file.error()));
WriteLE32(&data[i * 4], accumulatedSize);
#ifndef UNPACKED_MPQS
[[maybe_unused]] const uint16_t numLists = Cl2ToClx(&data[accumulatedSize], size, frameWidth);
Expand Down
63 changes: 60 additions & 3 deletions Source/engine/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
#include <memory>
#include <mutex>

#ifdef PS2
#include <loadfile.h>
#include <ps2snd.h>
#endif

#include <SDL.h>

#include "engine/assets.hpp"
Expand Down Expand Up @@ -38,22 +43,41 @@ namespace {

SoundSample music;

#ifndef PS2
std::string GetMp3Path(const char *path)
{
std::string mp3Path = path;
const std::string::size_type dot = mp3Path.find_last_of('.');
mp3Path.replace(dot + 1, mp3Path.size() - (dot + 1), "mp3");
return mp3Path;
}
#else
std::string GetAdpPath(const char *path)
{
std::string adpPath = path;
const std::string::size_type dot = adpPath.find_last_of('.');
adpPath.replace(dot + 1, adpPath.size() - (dot + 1), "adp");
return adpPath;
}
#endif

bool LoadAudioFile(const char *path, bool stream, bool errorDialog, SoundSample &result)
{
std::string filePath;
#ifndef PS2
bool isMp3 = true;
AssetRef ref = FindAsset(GetMp3Path(path).c_str());
filePath = GetMp3Path(path);
AssetRef ref = FindAsset(filePath.c_str());
if (!ref.ok()) {
ref = FindAsset(path);
filePath = path;
ref = FindAsset(filePath.c_str());
isMp3 = false;
}
#else
bool isMp3 = false;
filePath = GetAdpPath(path);
AssetRef ref = FindAsset(filePath.c_str());
#endif
if (!ref.ok())
ErrDlg("Audio file not found", StrCat(path, "\n", SDL_GetError(), "\n"), __FILE__, __LINE__);

Expand All @@ -70,7 +94,7 @@ bool LoadAudioFile(const char *path, bool stream, bool errorDialog, SoundSample
#endif

if (stream) {
if (result.SetChunkStream(path, isMp3, /*logErrors=*/true) != 0) {
if (result.SetChunkStream(filePath, isMp3, /*logErrors=*/true) != 0) {
if (errorDialog) {
ErrDlg("Failed to load audio file", StrCat(path, "\n", SDL_GetError(), "\n"), __FILE__, __LINE__);
}
Expand Down Expand Up @@ -118,10 +142,12 @@ SoundSample *DuplicateSound(const SoundSample &sound)
it = duplicateSounds.end();
--it;
}
#ifndef PS2
result->SetFinishCallback([it]([[maybe_unused]] Aulib::Stream &stream) {
const std::lock_guard<SdlMutex> lock(*duplicateSoundsMutex);
duplicateSounds.erase(it);
});
#endif
return result;
}

Expand Down Expand Up @@ -209,6 +235,7 @@ void snd_init()
sgOptions.Audio.musicVolume.SetValue(CapVolume(*sgOptions.Audio.musicVolume));
gbMusicOn = *sgOptions.Audio.musicVolume > VOLUME_MIN;

#ifndef PS2
// Initialize the SDL_audiolib library. Set the output sample rate to
// 22kHz, the audio format to 16-bit signed, use 2 output channels
// (stereo), and a 2KiB output buffer.
Expand All @@ -220,14 +247,44 @@ void snd_init()
Aulib::sampleRate(), Aulib::channelCount(), Aulib::frameSize(), Aulib::sampleFormat());

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;
}

void snd_deinit()
{
if (gbSndInited) {
#ifndef PS2
Aulib::quit();
duplicateSoundsMutex = std::nullopt;
#endif
}

gbSndInited = false;
Expand Down
Loading