d_snd_bgm_mml_parsers OK

This commit is contained in:
robojumper
2025-07-20 13:14:48 +02:00
parent af75869621
commit 339ee576b5
7 changed files with 262 additions and 22 deletions
+75 -2
View File
@@ -1,11 +1,14 @@
#include "d/snd/d_snd_bgm_mgr.h"
#include "common.h"
#include "d/flag/storyflag_manager.h"
#include "d/snd/d_snd_bgm_sound_battle.h"
#include "d/snd/d_snd_bgm_sound.h"
#include "d/snd/d_snd_mgr.h"
#include "d/snd/d_snd_bgm_mml_parsers.h"
#include "d/snd/d_snd_player_mgr.h"
#include "d/snd/d_snd_sound.h"
#include "d/snd/d_snd_state_mgr.h"
#include "d/snd/d_snd_util.h"
#include "d/snd/d_snd_wzsound.h"
#include "nw4r/snd/snd_SoundArchive.h"
@@ -59,8 +62,8 @@ dSndBgmMgr_c::dSndBgmMgr_c()
mBgmSounds[i]->init(mSoundActor, i);
}
field_0x270 = new dSndBgmSound_c();
field_0x270->init(dSndMgr_c::GetInstance()->getPlayer(), 8);
mpBgmMuteSound = new dSndBgmSound_c();
mpBgmMuteSound->init(dSndMgr_c::GetInstance()->getPlayer(), 8);
for (int i = 0; i < 3; i++) {
mFanSounds[i] = new dSndSound_c();
@@ -116,6 +119,72 @@ void dSndBgmMgr_c::calcLists() {
}
}
void dSndBgmMgr_c::loadStageSound() {
for (int i = 0; i < 3; i++) {
field_0x30C[i] = nullptr;
field_0x318[i] = 0;
field_0x324[i] = 0;
field_0x330[i] = 0;
}
if (dSndStateMgr_c::GetInstance()->isInDemo()) {
return;
}
if (dSndStateMgr_c::isInStage("F103")) {
// Flooded Faron Woods
if (!StoryflagManager::sInstance->getFlag(18)) {
bool ok = true;
if (!dSndPlayerMgr_c::GetInstance()->isLoadedFileForSound(TAG_BGM_EVENT_COMP_NOTE)) {
ok = dSndPlayerMgr_c::GetInstance()->loadFileForSound(TAG_BGM_EVENT_COMP_NOTE);
}
if (ok) {
dSndBgmMmlParserTagCompNote_c parser;
parser.parseData(&field_0x30C[0]);
field_0x324[0] = field_0x30C[0]->data[0];
}
}
} else if (dSndStateMgr_c::isInStage("F403") && dSndStateMgr_c::GetInstance()->getLayer() == 1) {
bool ok = true;
if (!dSndPlayerMgr_c::GetInstance()->isLoadedFileForSound(TAG_BGM_BATTLE_CROWD)) {
ok = dSndPlayerMgr_c::GetInstance()->loadFileForSound(TAG_BGM_BATTLE_CROWD);
}
if (ok) {
dSndBgmMmlParserTagBattle_c parser;
parser.parseData(TAG_BGM_BATTLE_CROWD, &field_0x30C[0]);
field_0x324[0] = field_0x30C[0]->data[0];
}
} else {
if (dSndPlayerMgr_c::GetInstance()->isLoadedFileForSound(TAG_BGM_BOSS_A)) {
bool ok = true;
// I am REALLY not sure how TAG_BGM_BOSS_A could spontaneously unload here but better
// double check I guess
if (!dSndPlayerMgr_c::GetInstance()->isLoadedFileForSound(TAG_BGM_BOSS_A)) {
// TODO types
ok = dSndMgr_c::GetInstance()->loadGroup((unsigned int)GRP_BGM_BOSS_A, nullptr, 0);
}
if (ok) {
dSndBgmMmlParserTagBgmBoss_c parser1;
parser1.parseData(&field_0x30C[0], &field_0x30C[1]);
}
if (ok) {
dSndBgmMmlParserTagBattle_c parser;
parser.parseData(TAG_BGM_BOSS_A_CHANCE, &field_0x30C[2]);
}
}
}
}
void dSndBgmMgr_c::startBgmMuteSound() {
if (mpBgmMuteSound != nullptr) {
mpBgmMuteSound->stop(0);
mpBgmMuteSound->startBgmSound(BGM_MUTE, 0, 0);
}
}
bool dSndBgmMgr_c::prepareBgm(u32 soundId, u32 startOffset) {
if (isPlayingBgmSoundId(soundId)) {
return false;
@@ -147,6 +216,10 @@ bool dSndBgmMgr_c::stopBgmSound(dSndBgmSound_c *sound, s32 fadeFrames) {
return false;
}
void dSndBgmMgr_c::endBgmMuteSound() {
mpBgmMuteSound->stop(0);
}
void dSndBgmMgr_c::checkForPrepareStoppedBgmSound(u32 stoppedSoundId) {
// TODO ???
u32 id = stoppedSoundId == BGM_SKYFIELD ? BGM_SKYFIELD : -1;
+117
View File
@@ -6,6 +6,7 @@
#include "d/snd/d_snd_harp_song_data.h"
#include "d/snd/d_snd_mgr.h"
#include "d/snd/d_snd_player_mgr.h"
#include "d/snd/d_snd_wzsound.h"
#include "nw4r/snd/snd_SoundArchive.h"
#include "sized_string.h"
@@ -106,3 +107,119 @@ void dSndBgmMmlParserHarpSong_c::NoteOnCommandProc(u32 trackNo, int wait, int ke
}
}
}
dSndBgmMmlParserTagBattle_c::dSndBgmMmlParserTagBattle_c()
: dSndBgmMmlParser_c(&dSndMgr_c::GetInstance()->getPlayer(), dSndMgr_c::GetInstance()->getArchive()),
mpBuf(nullptr),
mBufSize(0) {}
bool dSndBgmMmlParserTagBattle_c::parseData(u32 soundId, dSndTagData **pOutData) {
if (soundId == -1) {
return false;
}
// First pass, check how much memory we need
loadAndParse(soundId, (1 << 0), true);
// alloc memory
mpBuf = reinterpret_cast<dSndTagData *>(
dSndMgr_c::GetInstance()->getSoundHeap()->Alloc(sizeof(dSndTagData) + mBufSize * sizeof(u32))
);
mpBuf->size = mBufSize;
// second pass, actually parse
mBufSize = 0;
bool ok = loadAndParse(soundId, (1 << 0), true);
*pOutData = mpBuf;
return ok;
}
void dSndBgmMmlParserTagBattle_c::NoteOnCommandProc(u32 trackNo, int wait, int key, int velocity, s32 length) const {
if (key < 0x3C) {
return;
}
if (mpBuf != nullptr) {
mpBuf->data[mBufSize] = wait;
}
mBufSize++;
}
dSndBgmMmlParserTagBgmBoss_c::dSndBgmMmlParserTagBgmBoss_c()
: dSndBgmMmlParser_c(&dSndMgr_c::GetInstance()->getPlayer(), dSndMgr_c::GetInstance()->getArchive()),
mpBuf1(nullptr),
mpBuf2(nullptr),
mBufSize1(0),
mBufSize2(0) {}
void dSndBgmMmlParserTagBgmBoss_c::parseData(dSndTagData **pOutData1, dSndTagData **pOutData2) {
// First pass, check how much memory we need
loadAndParse(TAG_BGM_BOSS_A, (1 << 0), true);
// alloc memory
mpBuf1 = reinterpret_cast<dSndTagData *>(
dSndMgr_c::GetInstance()->getSoundHeap()->Alloc(sizeof(dSndTagData) + mBufSize1 * sizeof(u32))
);
mpBuf2 = reinterpret_cast<dSndTagData *>(
dSndMgr_c::GetInstance()->getSoundHeap()->Alloc(sizeof(dSndTagData) + mBufSize2 * sizeof(u32))
);
mpBuf1->size = mBufSize1;
mpBuf2->size = mBufSize2;
// second pass, actually parse
mBufSize1 = 0;
mBufSize2 = 0;
loadAndParse(TAG_BGM_BOSS_A, (1 << 0), true);
*pOutData1 = mpBuf1;
*pOutData2 = mpBuf2;
}
void dSndBgmMmlParserTagBgmBoss_c::NoteOnCommandProc(u32 trackNo, int wait, int key, int velocity, s32 length) const {
switch (key) {
case 0x3C: {
if (mpBuf1 != nullptr) {
mpBuf1->data[mBufSize1] = wait;
}
mBufSize1++;
break;
}
case 0x48: {
if (mpBuf2 != nullptr) {
mpBuf2->data[mBufSize2] = wait;
}
mBufSize2++;
break;
}
}
}
dSndBgmMmlParserTagCompNote_c::dSndBgmMmlParserTagCompNote_c()
: dSndBgmMmlParser_c(&dSndMgr_c::GetInstance()->getPlayer(), dSndMgr_c::GetInstance()->getArchive()),
mpBuf(nullptr),
mBufSize(0) {}
void dSndBgmMmlParserTagCompNote_c::parseData(dSndTagData **pOutData) {
// First pass, check how much memory we need
loadAndParse(TAG_BGM_EVENT_COMP_NOTE, (1 << 0), true);
// alloc memory
mpBuf = reinterpret_cast<dSndTagData *>(
dSndMgr_c::GetInstance()->getSoundHeap()->Alloc(sizeof(dSndTagData) + mBufSize * sizeof(u32))
);
mpBuf->size = mBufSize;
// second pass, actually parse
mBufSize = 0;
loadAndParse(TAG_BGM_EVENT_COMP_NOTE, (1 << 0), true);
*pOutData = mpBuf;
}
void dSndBgmMmlParserTagCompNote_c::NoteOnCommandProc(u32 trackNo, int wait, int key, int velocity, s32 length) const {
if (key < 0x3C) {
return;
}
// TODO - signed/unsigned
u32 w = wait;
if (mpBuf != nullptr) {
if (w != 0) {
w = w < 0xC80 ? 0 : w - 0xC80;
}
mpBuf->data[mBufSize] = w;
}
mBufSize++;
}