diff options
| author | robojumper <robojumper@gmail.com> | 2025-05-24 21:53:14 +0200 |
|---|---|---|
| committer | robojumper <robojumper@gmail.com> | 2025-05-25 08:52:12 +0200 |
| commit | 04d5527ebab1a17348c5030dc21df481ed49b1c6 (patch) | |
| tree | de2e15924ef2ca447b0739e826ac142fb73e8d4b /src/nw4r/snd/snd_SoundSystem.cpp | |
| parent | 4c62e0102547907becb945138356f401b150120e (diff) | |
Initial import of nw4r::snd from https://github.com/muff1n1634/nw4r_snd_mid2010
Co-authored-by: muff1nOS <19197077+muff1n1634@users.noreply.github.com>
Diffstat (limited to 'src/nw4r/snd/snd_SoundSystem.cpp')
| -rw-r--r-- | src/nw4r/snd/snd_SoundSystem.cpp | 222 |
1 files changed, 221 insertions, 1 deletions
diff --git a/src/nw4r/snd/snd_SoundSystem.cpp b/src/nw4r/snd/snd_SoundSystem.cpp index 6510587b..9a6d592a 100644 --- a/src/nw4r/snd/snd_SoundSystem.cpp +++ b/src/nw4r/snd/snd_SoundSystem.cpp @@ -1 +1,221 @@ -#include "nw4r/snd/snd_SoundSystem.h" +#include "nw4r/snd/SoundSystem.h" + +/* Original source: + * kiwi515/ogws + * src/nw4r/snd/snd_SoundSystem.cpp + */ + +/******************************************************************************* + * headers + */ + +#include <decomp.h> +#include <macros.h> // STR +#include <types.h> + +#include "nw4r/snd/AxVoiceManager.h" +#include "nw4r/snd/AxManager.h" +#include "nw4r/snd/Channel.h" // ChannelManager +#include "nw4r/snd/global.h" +#include "nw4r/snd/SeqPlayer.h" +#include "nw4r/snd/SoundThread.h" +#include "nw4r/snd/TaskManager.h" +#include "nw4r/snd/TaskThread.h" +#include "nw4r/snd/VoiceManager.h" + +#if 0 +#include <revolution/OS/OS.h> // OSRegisterVersion +#include <revolution/AX/AXVPB.h> // AXGetMaxVoices +#include <revolution/SC/scsystem.h> +#include <revolution/SC/scapi.h> +#else +#include <context_rvl.h> +#endif + +#include "nw4r/NW4RAssert.hpp" + +/******************************************************************************* + * macros + */ + +#define BUILDSTAMP_LIB_GROUP_NAME "NW4R " +#define BUILDSTAMP_LIB_NAME "SND" + +// You probably want to change these +#define BUILDSTAMP_BUILD_TYPE "release" +#define BUILDSTAMP_DATE __DATE__ +#define BUILDSTAMP_TIME __TIME__ +#define BUILDSTAMP_CW_MAJOR_REV STR(__CWCC__) +#define BUILDSTAMP_CW_MINOR_REV STR(__CWBUILD__) + +#define BUILDSTAMP_STRING \ + "<< " \ + BUILDSTAMP_LIB_GROUP_NAME " - " BUILDSTAMP_LIB_NAME " \t" \ + BUILDSTAMP_BUILD_TYPE " build: " \ + BUILDSTAMP_DATE " " BUILDSTAMP_TIME \ + " (" BUILDSTAMP_CW_MAJOR_REV "_" BUILDSTAMP_CW_MINOR_REV ")" \ + " >>" + +/******************************************************************************* + * variables + */ + +namespace nw4r { namespace snd +{ + // .data, .sdata + extern "C" char const *NW4R_SND_Version_ = BUILDSTAMP_STRING; + + // .bss + detail::TaskThread SoundSystem::sTaskThread; + + // .sbss + namespace + { + bool sInitialized; + } // unnamed namespace + + int SoundSystem::sMaxVoices; +}} // namespace nw4r::snd + +/******************************************************************************* + * functions + */ + +namespace nw4r { namespace snd { + +u32 SoundSystem::GetRequiredMemSize(SoundSystemParam const ¶m) +{ + // could have just used align assert? idk + NW4RAssert_Line(106, param.soundThreadStackSize % 8 == 0); + NW4RAssert_Line(107, param.dvdThreadStackSize % 8 == 0); + + int maxVoices = AXGetMaxVoices(); + + return param.soundThreadStackSize + param.dvdThreadStackSize + + detail::AxVoiceManager::GetInstance().GetRequiredMemSize(maxVoices) + + detail::VoiceManager::GetInstance().GetRequiredMemSize(maxVoices) + + detail::ChannelManager::GetInstance().GetRequiredMemSize(maxVoices); +} + +void SoundSystem::InitSoundSystem(SoundSystemParam const ¶m, void *workMem, + u32 workMemSize) +{ + bool result; // presumably up here + + NW4RAssertAligned_Line(144, workMem, 32); + NW4RAssert_Line(145, workMemSize >= GetRequiredMemSize( param )); + + if (sInitialized) + return; + + sInitialized = true; + + OSRegisterVersion(NW4R_SND_Version_); + + detail::AxManager::GetInstance().Init(); + + SCInit(); + + SCStatus initStatus; + do + initStatus = SCCheckStatus(); + while (initStatus == SC_STATUS_BUSY); + + NW4RAssert_Line(171, initStatus == SC_STATUS_OK); + + SCSoundMode soundMode = SCGetSoundMode(); + switch (soundMode) + { + case SC_SND_MONO: + detail::AxManager::GetInstance().SetOutputMode(OUTPUT_MODE_MONO); + break; + + case SC_SND_STEREO: + detail::AxManager::GetInstance().SetOutputMode(OUTPUT_MODE_STEREO); + break; + + case SC_SND_SURROUND: + detail::AxManager::GetInstance().SetOutputMode(OUTPUT_MODE_DPL2); + break; + + default: + detail::AxManager::GetInstance().SetOutputMode(OUTPUT_MODE_STEREO); + break; + } + + byte_t *ptr = static_cast<byte_t *>(workMem); + + void *dvdThreadStack = ptr; + ptr += param.dvdThreadStackSize; + + void *soundThreadStack = ptr; + ptr += param.soundThreadStackSize; + + sMaxVoices = AXGetMaxVoices(); + + void *axVoiceWork = ptr; + ptr += detail::AxVoiceManager::GetInstance().GetRequiredMemSize( + sMaxVoices); + + detail::AxVoiceManager::GetInstance().Setup( + axVoiceWork, + detail::AxVoiceManager::GetInstance().GetRequiredMemSize( + sMaxVoices)); + + void *voiceWork = ptr; + ptr += detail::VoiceManager::GetInstance().GetRequiredMemSize(sMaxVoices); + + detail::VoiceManager::GetInstance().Setup( + voiceWork, + detail::VoiceManager::GetInstance().GetRequiredMemSize(sMaxVoices)); + + void *channelWork = ptr; + ptr += detail::ChannelManager::GetInstance().GetRequiredMemSize( + sMaxVoices); + + detail::ChannelManager::GetInstance().Setup( + channelWork, + detail::ChannelManager::GetInstance().GetRequiredMemSize( + sMaxVoices)); + + detail::SeqPlayer::InitSeqPlayer(); + + result = sTaskThread.Create(param.dvdThreadPriority, dvdThreadStack, + param.dvdThreadStackSize); + NW4RAssert_Line(247, result); + + result = detail::SoundThread::GetInstance().Create( + param.soundThreadPriority, soundThreadStack, + param.soundThreadStackSize); + NW4RAssert_Line(255, result); + + NW4RAssert_Line(257, ptr <= reinterpret_cast<u8*>( workMem ) + workMemSize); +} + +void SoundSystem::ShutdownSoundSystem() +{ + if (!sInitialized) + return; + + detail::SoundThread::GetInstance().Shutdown(); + + detail::TaskManager::GetInstance().CancelAllTask(); + sTaskThread.Destroy(); + + detail::ChannelManager::GetInstance().Shutdown(); + detail::VoiceManager::GetInstance().Shutdown(); + detail::AxVoiceManager::GetInstance().Shutdown(); + detail::AxManager::GetInstance().Shutdown(); + + sInitialized = false; +} + +bool SoundSystem::IsInitializedSoundSystem() +{ + return sInitialized; +} + +// SoundSystem::WaitForResetReady ([R89JEL]:/bin/RVL/Debug/mainD.MAP:14493) +DECOMP_FORCE("SoundSystem::WaitForResetReady is TIME OUT.\n"); + +}} // namespace nw4r::snd |
