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

proper 3-soundbank fixes #32

Merged
merged 2 commits into from
Sep 12, 2022
Merged
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
101 changes: 101 additions & 0 deletions data/game/overlord/sbank.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#include "sbank.h"

#include <cstring>

#include "soundcommon.h"

constexpr int N_BANKS = 4;
SoundBank* gBanks[N_BANKS];
SoundBank gCommonBank;
SoundBank gLevelBank[3];

void sbank_init_globals() {
gBanks[0] = &gCommonBank;
gBanks[1] = &gLevelBank[0];
gBanks[2] = &gLevelBank[1];
gBanks[3] = &gLevelBank[2];
Comment on lines +7 to +16
Copy link
Contributor Author

@dallmeyer dallmeyer Sep 12, 2022

Choose a reason for hiding this comment

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

all the c++ changes are in these lines

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 < (int)bank->sound_count; i++) {
if (memcmp(bank->sound[i].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);
}
}
}
199 changes: 85 additions & 114 deletions data/goal_src/jak1/engine/level/level.gc
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,7 @@
(sb2 #f)
(sb3 #f)
)
;; loop through active levels and figure out which soundbanks we need
(dotimes (s4-0 (-> *level* length))
(let ((v1-5 (-> *level* level s4-0)))
(when (= (-> v1-5 status) 'active)
Expand All @@ -1593,7 +1594,7 @@
(set! sb2 t0-0)
)
((not sb3)
(set! sb2 t0-0)
(set! sb3 t0-0)
)
(else
(format
Expand All @@ -1613,119 +1614,89 @@
)
)
)
(when (and sb1 (!= sb1 *sound-bank-1*) (!= sb1 *sound-bank-2*) (!= sb1 *sound-bank-3*))
(when (not *sound-bank-1*)
(format 0 "Load soundbank ~A~%" sb1)
(sound-bank-load (string->sound-name (symbol->string sb1)))
(set! *sound-bank-1* sb1)
(return 0)
)
(when (not *sound-bank-2*)
(format 0 "Load soundbank ~A~%" sb1)
(sound-bank-load (string->sound-name (symbol->string sb1)))
(set! *sound-bank-2* sb1)
(return 0)
)
(when (not *sound-bank-3*)
(format 0 "Load soundbank ~A~%" sb1)
(sound-bank-load (string->sound-name (symbol->string sb1)))
(set! *sound-bank-3* sb1)
(return 0)
)
(when (and (!= *sound-bank-1* sb2) (!= *sound-bank-1* sb3))
(format 0 "Unload soundbank ~A~%" *sound-bank-1*)
(sound-bank-unload (string->sound-name (symbol->string *sound-bank-1*)))
(set! *sound-bank-1* #f)
(return 0)
)
(when (and (!= *sound-bank-2* sb2) (!= *sound-bank-2* sb3))
(format 0 "Unload soundbank ~A~%" *sound-bank-2*)
(sound-bank-unload (string->sound-name (symbol->string *sound-bank-2*)))
(set! *sound-bank-2* #f)
(return 0)
)
(when (and (!= *sound-bank-3* sb2) (!= *sound-bank-3* sb3))
(format 0 "Unload soundbank ~A~%" *sound-bank-3*)
(sound-bank-unload (string->sound-name (symbol->string *sound-bank-3*)))
(set! *sound-bank-3* #f)
(return 0)
)
)
(when (and sb2 (!= sb2 *sound-bank-1*) (!= sb2 *sound-bank-2*) (!= sb2 *sound-bank-3*))
(when (not *sound-bank-1*)
(format 0 "Load soundbank ~A~%" sb2)
(sound-bank-load (string->sound-name (symbol->string sb2)))
(set! *sound-bank-1* sb2)
(return 0)
)
(when (not *sound-bank-2*)
(format 0 "Load soundbank ~A~%" sb2)
(sound-bank-load (string->sound-name (symbol->string sb2)))
(set! *sound-bank-2* sb2)
(return 0)
)
(when (not *sound-bank-3*)
(format 0 "Load soundbank ~A~%" sb2)
(sound-bank-load (string->sound-name (symbol->string sb2)))
(set! *sound-bank-3* sb2)
(return 0)
)
(when (and (!= *sound-bank-1* sb1) (!= *sound-bank-1* sb3))
(format 0 "Unload soundbank ~A~%" *sound-bank-1*)
(sound-bank-unload (string->sound-name (symbol->string *sound-bank-1*)))
(set! *sound-bank-1* #f)
(return 0)
)
(when (and (!= *sound-bank-2* sb1) (!= *sound-bank-2* sb3))
(format 0 "Unload soundbank ~A~%" *sound-bank-2*)
(sound-bank-unload (string->sound-name (symbol->string *sound-bank-2*)))
(set! *sound-bank-2* #f)
(return 0)
)
(when (and (!= *sound-bank-3* sb1) (!= *sound-bank-3* sb3))
(format 0 "Unload soundbank ~A~%" *sound-bank-3*)
(sound-bank-unload (string->sound-name (symbol->string *sound-bank-2*)))
(set! *sound-bank-3* #f)
(return 0)
)
)
(when (and sb2 (!= sb2 *sound-bank-1*) (!= sb2 *sound-bank-2*) (!= sb2 *sound-bank-3*))
(when (not *sound-bank-1*)
(format 0 "Load soundbank ~A~%" sb2)
(sound-bank-load (string->sound-name (symbol->string sb2)))
(set! *sound-bank-1* sb2)
(return 0)
)
(when (not *sound-bank-2*)
(format 0 "Load soundbank ~A~%" sb2)
(sound-bank-load (string->sound-name (symbol->string sb2)))
(set! *sound-bank-2* sb2)
(return 0)
)
(when (not *sound-bank-3*)
(format 0 "Load soundbank ~A~%" sb2)
(sound-bank-load (string->sound-name (symbol->string sb2)))
(set! *sound-bank-3* sb2)
(return 0)
)
(when (and (!= *sound-bank-1* sb1) (!= *sound-bank-1* sb2))
(format 0 "Unload soundbank ~A~%" *sound-bank-1*)
(sound-bank-unload (string->sound-name (symbol->string *sound-bank-1*)))
(set! *sound-bank-1* #f)
(return 0)
)
(when (and (!= *sound-bank-2* sb1) (!= *sound-bank-2* sb2))
(format 0 "Unload soundbank ~A~%" *sound-bank-2*)
(sound-bank-unload (string->sound-name (symbol->string *sound-bank-2*)))
(set! *sound-bank-2* #f)
(return 0)
)
(when (and (!= *sound-bank-3* sb1) (!= *sound-bank-3* sb2))
(format 0 "Unload soundbank ~A~%" *sound-bank-3*)
(sound-bank-unload (string->sound-name (symbol->string *sound-bank-2*)))
(set! *sound-bank-3* #f)
(return 0)
)
(when (or sb1 sb2 sb3)
;; unload any soundbanks that are loaded and not already set to sb1/sb2/sb3
(when (and *sound-bank-1* (!= *sound-bank-1* sb1) (!= *sound-bank-1* sb2) (!= *sound-bank-1* sb3))
(format 0 "Unload soundbank ~A~%" *sound-bank-1*)
(sound-bank-unload (string->sound-name (symbol->string *sound-bank-1*)))
(set! *sound-bank-1* #f)
(return 0)
)
(when (and *sound-bank-2* (!= *sound-bank-2* sb1) (!= *sound-bank-2* sb2) (!= *sound-bank-2* sb3))
(format 0 "Unload soundbank ~A~%" *sound-bank-2*)
(sound-bank-unload (string->sound-name (symbol->string *sound-bank-2*)))
(set! *sound-bank-2* #f)
(return 0)
)
(when (and *sound-bank-3* (!= *sound-bank-3* sb1) (!= *sound-bank-3* sb2) (!= *sound-bank-3* sb3))
(format 0 "Unload soundbank ~A~%" *sound-bank-3*)
(sound-bank-unload (string->sound-name (symbol->string *sound-bank-3*)))
(set! *sound-bank-3* #f)
(return 0)
)
;; load sb1 into some soundbank if needed
(when (and sb1 (!= sb1 *sound-bank-1*) (!= sb1 *sound-bank-2*) (!= sb1 *sound-bank-3*))
(when (not *sound-bank-1*)
(format 0 "Load soundbank ~A~%" sb1)
(sound-bank-load (string->sound-name (symbol->string sb1)))
(set! *sound-bank-1* sb1)
(return 0)
)
(when (not *sound-bank-2*)
(format 0 "Load soundbank ~A~%" sb1)
(sound-bank-load (string->sound-name (symbol->string sb1)))
(set! *sound-bank-2* sb1)
(return 0)
)
(when (not *sound-bank-3*)
(format 0 "Load soundbank ~A~%" sb1)
(sound-bank-load (string->sound-name (symbol->string sb1)))
(set! *sound-bank-3* sb1)
(return 0)
)
)
;; load sb2 into some soundbank if needed
(when (and sb2 (!= sb2 *sound-bank-1*) (!= sb2 *sound-bank-2*) (!= sb2 *sound-bank-3*))
(when (not *sound-bank-1*)
(format 0 "Load soundbank ~A~%" sb2)
(sound-bank-load (string->sound-name (symbol->string sb2)))
(set! *sound-bank-1* sb2)
(return 0)
)
(when (not *sound-bank-2*)
(format 0 "Load soundbank ~A~%" sb2)
(sound-bank-load (string->sound-name (symbol->string sb2)))
(set! *sound-bank-2* sb2)
(return 0)
)
(when (not *sound-bank-3*)
(format 0 "Load soundbank ~A~%" sb2)
(sound-bank-load (string->sound-name (symbol->string sb2)))
(set! *sound-bank-3* sb2)
(return 0)
)
)
;; load sb3 into some soundbank if needed
(when (and sb3 (!= sb3 *sound-bank-1*) (!= sb3 *sound-bank-2*) (!= sb3 *sound-bank-3*))
(when (not *sound-bank-1*)
(format 0 "Load soundbank ~A~%" sb3)
(sound-bank-load (string->sound-name (symbol->string sb3)))
(set! *sound-bank-1* sb3)
(return 0)
)
(when (not *sound-bank-2*)
(format 0 "Load soundbank ~A~%" sb3)
(sound-bank-load (string->sound-name (symbol->string sb3)))
(set! *sound-bank-2* sb3)
(return 0)
)
(when (not *sound-bank-3*)
(format 0 "Load soundbank ~A~%" sb3)
(sound-bank-load (string->sound-name (symbol->string sb3)))
(set! *sound-bank-3* sb3)
(return 0)
)
)
)
)
0
Expand Down
Binary file modified extractor.exe
Binary file not shown.
Binary file modified gk.exe
Binary file not shown.
Binary file modified goalc.exe
Binary file not shown.