Files
jak-project/game/overlord/sbank.cpp
T
Ziemas 766b328c97 Overlord sound player (#1239)
* Accept player RPC commands in overlord

* Remove the .projectile file

I use emacs for everything so I don't want it to only look at the goal code.

* Fill out most of the unique player structs

* Decompile most of ssound.c

* Silence some spam

* Comment out WaitSema instance

* Add a file with definitions for snd_ functions

Makes it compile without commenting them out.

Maybe it'd be nice to maintain the original API usage in overlord for
similarity and shim them to whatever API the player uses.

* Make SoundBank statically sized again.

Didn't realise this was used in an array. MSVC should be happy again.

Not sure what the actual size of these should be.

* Fix logic issue

* Finish RPC Loader

* More RPC_Player

* Play RPC command

* All the RPC commands added

* Call Music/Bank loaders

* audio: add almost all `.MUS` and `.SBK` files to build process

* Include TWEAKVAL in build output

* Load banks and music tweaks

* Comment out spam

* Sound struct unk -> is music

* Also test if empty1.sbk was found

For the sake of tests.

* Get rid of PC_DEBUG_SOUND_ENABLE

Co-authored-by: Tyler Wilding <xtvaser@gmail.com>
2022-03-22 18:53:36 -04:00

99 lines
2.1 KiB
C++

#include <cstring>
#include "sbank.h"
#include "soundcommon.h"
constexpr int N_BANKS = 3;
SoundBank* gBanks[N_BANKS];
SoundBank gCommonBank;
SoundBank gLevelBank[2];
void sbank_init_globals() {
gBanks[0] = &gCommonBank;
gBanks[1] = &gLevelBank[0];
gBanks[2] = &gLevelBank[1];
memset((void*)&gCommonBank, 0, sizeof(gCommonBank));
memset((void*)&gLevelBank, 0, sizeof(gLevelBank));
}
void InitBanks() {
for (auto& gBank : gBanks) {
gBank->bank_handle = 0;
gBank->sound_count = 0;
strcpy(gBank->name, "<unused>");
}
}
SoundBank* AllocateBank() {
int idx = 0;
// find a bank with unk1 = 0, or return nullptr if none exists
while (true) {
if (idx >= N_BANKS) {
return nullptr;
}
if (gBanks[idx]->bank_handle == 0) {
break;
}
idx++;
}
// Funny hack: The loader will read this out of the destination buffer in order to determine how
// many sectors of sound name mapping it needs to read.
if (idx == 0) {
gBanks[0]->sound_count = 0x3fe;
} else {
gBanks[idx]->sound_count = 0x65;
}
return gBanks[idx];
}
s32 LookupSoundIndex(const char* name, SoundBank** bank_out) {
int idx = 0;
while (true) {
if (idx > N_BANKS - 1) {
return -1;
}
auto& bank = gBanks[idx];
if (bank->bank_handle == 0) {
break;
}
for (int i = 0; i < bank->sound_count; i++) {
if (memcmp(bank->name, name, 16) == 0) {
*bank_out = bank;
return i;
}
}
idx++;
}
return -1;
}
// name should be a 16-byte "sound name"
SoundBank* LookupBank(const char* name) {
int idx = N_BANKS - 1;
while (true) {
if (idx < 0) {
return nullptr; // not found.
}
auto& bank = gBanks[idx];
// they had some weird stuff here that took advantage of the fact that this region was
// 16-byte aligned, so it probably wasn't a memcmp, but this is easier.
if (memcmp(bank->name, name, 16) == 0) {
return bank;
}
idx--;
}
}
void ReloadBankInfo() {
for (auto& b : gBanks) {
if (b->bank_handle) {
ReadBankSoundInfo(b, b, 1);
}
}
}