d_snd_bgm_sound_battle OK

This commit is contained in:
robojumper
2025-07-09 00:30:48 +02:00
parent bb3f0562bd
commit 4f9d63d357
11 changed files with 115 additions and 50 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
#include "d/snd/d_snd_bgm_mgr.h"
#include "common.h"
#include "d/snd/d_snd_bgm_sound battle.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_player_mgr.h"
+10 -14
View File
@@ -1,9 +1,9 @@
#include "d/snd/d_snd_bgm_mml_parsers.h"
#include "common.h"
#include "d/snd/d_snd_mgr.h"
#include "d/snd/d_snd_bgm_sound_harp_mgr.h"
#include "d/snd/d_snd_bgm_seq_data_mgr.h"
#include "d/snd/d_snd_bgm_sound_harp_mgr.h"
#include "d/snd/d_snd_mgr.h"
#include "d/snd/d_snd_player_mgr.h"
#include "nw4r/snd/snd_SoundArchive.h"
#include "sized_string.h"
@@ -23,7 +23,8 @@ bool dSndBgmMmlParserHarp_c::parseData(const char *soundLabel, u32 baseSoundId,
SizedString<64> dataLabel;
dataLabel.sprintf("%s%s", dSndBgmSeqDataMgr_c::getDataPrefix(), soundLabel);
u32 dataId = dSndPlayerMgr_c::GetInstance()->convertLabelStringToSoundId(dataLabel);
if (dataId != -1 && dSndMgr_c::GetInstance()->getArchive()->GetSoundType(dataId) == nw4r::snd::SoundArchive::SOUND_TYPE_SEQ) {
if (dataId != -1 &&
dSndMgr_c::GetInstance()->getArchive()->GetSoundType(dataId) == nw4r::snd::SoundArchive::SOUND_TYPE_SEQ) {
ok = loadAndParse(dataId, trackMask, true);
if (ok) {
field_0x294->setSoundId(baseSoundId);
@@ -53,22 +54,17 @@ void dSndBgmMmlParserHarp_c::CommandProc(u32 trackNo, int wait, u32 command, s32
}
break;
default:
if (command == MML_SET_TEMPO) {
field_0x294->setTempo(commandArg1);
}
break;
if (command == MML_SET_TEMPO) {
field_0x294->setTempo(commandArg1);
}
break;
}
}
void dSndBgmMmlParserHarp_c::NoteOnCommandProc(u32 trackNo, int wait, int key, int velocity, s32 length) const {
// TODO type
switch ((s32)trackNo) {
case 15:
field_0x298->addVar(wait, key, velocity);
break;
default:
break;
case 15: field_0x298->addVar(wait, key, velocity); break;
default: break;
}
}
+21 -17
View File
@@ -29,8 +29,8 @@ dSndBgmSound_c::dSndBgmSound_c()
mSeqTempo(-1),
mBgmFlags(0),
mDidRewindPlaySamplePosition(false),
field_0x114(-1),
field_0x118(0x180),
mBgmVar3(-1),
mSeqTimebase(0x180),
mPlaySamplePosition(0),
mpHarpMgr(&mHarpMgr),
mpSeqConfig(nullptr),
@@ -71,9 +71,9 @@ void dSndBgmSound_c::cancel() {
mpSeqConfig = nullptr;
mPlaySamplePosition = 0;
mSeqPlaySamplePosition = -1;
field_0x114 = -1;
mBgmVar3 = -1;
mSeqTempo = -1;
field_0x118 = 0x180;
mSeqTimebase = 0x180;
mHarpMgr.reset();
for (int i = 0; i < 2; i++) {
field_0x14C[i] = 0;
@@ -239,7 +239,7 @@ void dSndBgmSound_c::loadSeqConfig(u32 soundId) {
if (dSndMgr_c::GetInstance()->getArchive()->GetSoundType(soundId) == nw4r::snd::SoundArchive::SOUND_TYPE_SEQ) {
mpSeqConfig = dSndBgmSeqConfig::getConfig(soundId, 1);
if (mpSeqConfig != nullptr) {
field_0x118 = mpSeqConfig->field_0x08;
mSeqTimebase = mpSeqConfig->mTimebase;
}
}
}
@@ -415,27 +415,31 @@ void dSndBgmSound_c::calcSeqPlaySamplePosition() {
nw4r::snd::SeqSoundHandle handle(this);
s32 tick = handle.GetTick();
field_0x114 = readSeqTrackVariable(3);
if (field_0x114 >= 0) {
mSeqPlaySamplePosition = tick % field_0x118;
mBgmVar3 = readSeqTrackVariable(3);
if (mBgmVar3 >= 0) {
// Var >= 0 - seq itself controls play position
mSeqPlaySamplePosition = tick % mSeqTimebase;
if (mSeqPlaySamplePosition == 0) {
field_0x114++;
if (mpSeqConfig != nullptr && field_0x114 > mpSeqConfig->field_0x0E) {
field_0x114 = mpSeqConfig->field_0x0C;
mBgmVar3++;
if (mpSeqConfig != nullptr && mBgmVar3 > mpSeqConfig->mLoopEnd) {
mBgmVar3 = mpSeqConfig->mLoopStart;
}
}
mSeqPlaySamplePosition += field_0x118 * field_0x114;
mSeqPlaySamplePosition += mSeqTimebase * mBgmVar3;
} else if (mpSeqConfig != nullptr) {
if (tick < (mpSeqConfig->field_0x0E + 1) * field_0x118) {
if (tick < (mpSeqConfig->mLoopEnd + 1) * mSeqTimebase) {
// not looped yet, no adjustment needed
mSeqPlaySamplePosition = tick;
return;
}
s32 offset = mpSeqConfig->field_0x0C * field_0x118;
s32 startOffset = mpSeqConfig->mLoopStart * mSeqTimebase;
tick -= offset;
tick = tick % (field_0x118 * (mpSeqConfig->field_0x0E - mpSeqConfig->field_0x0C));
mSeqPlaySamplePosition = tick + offset;
// wrap around loop, making sure to account for start offset
tick -= startOffset;
tick = tick % (mSeqTimebase * (mpSeqConfig->mLoopEnd - mpSeqConfig->mLoopStart));
mSeqPlaySamplePosition = tick + startOffset;
} else {
// Fallback, not controlled by seq no config override
mSeqPlaySamplePosition = tick;
}
}
+55 -3
View File
@@ -5,14 +5,15 @@
#include "d/snd/d_snd_bgm_sound.h"
#include "d/snd/d_snd_mgr.h"
#include "d/snd/d_snd_wzsound.h"
#include "nw4r/snd/snd_SeqSoundHandle.h"
dSndBgmBattleSound_c::dSndBgmBattleSound_c()
: mpBgmBattleConfig(nullptr), mMuteApplyStateMask(0), mTickRelated(0), field_0x190(0), field_0x191(1) {}
: mpBgmBattleConfig(nullptr), mMuteGroupActiveMask(0), mPrevTick(0), field_0x190(0), field_0x191(1) {}
void dSndBgmBattleSound_c::cancel() {
dSndBgmSound_c::cancel();
mMuteApplyStateMask = 0;
mTickRelated = 0;
mMuteGroupActiveMask = 0;
mPrevTick = 0;
field_0x190 = 0;
field_0x191 = 1;
}
@@ -44,3 +45,54 @@ void dSndBgmBattleSound_c::fadeIn(u32 id, s32 fadeFrames) {
field_0x191 = 0;
}
}
void dSndBgmBattleSound_c::setTrackGroupMuted(u32 groupId) {
mMuteGroupActiveMask |= (1 << groupId);
}
void dSndBgmBattleSound_c::setTrackGroupUnmuted(u32 groupId) {
mMuteGroupActiveMask &= ~(1 << groupId);
}
bool dSndBgmBattleSound_c::startMainBattleLoop() {
if (isPlaying() && readSeqTrackVariable(0) != 1) {
// This seq variable allows the seq sound to jump from intro to main loop
writeSeqTrackVariable(0, 1);
mpSeqConfig = dSndBgmSeqConfig::getConfig(GetId(), 1);
return true;
}
return false;
}
void dSndBgmBattleSound_c::calcSeqPlaySamplePosition() {
if (!isSeqSound()) {
return;
}
nw4r::snd::SeqSoundHandle handle(this);
s32 tick = handle.GetTick();
s32 tickDiff = tick - mPrevTick;
if (tickDiff <= 0) {
return;
}
mPrevTick = tick;
s32 timeBase = mpSeqConfig != nullptr ? mpSeqConfig->mTimebase : 0x180;
mBgmVar3 = readSeqTrackVariable(3);
if (mBgmVar3 >= 0) {
// Var >= 0 - seq itself controls play position
mSeqPlaySamplePosition = tick % mSeqTimebase;
mSeqPlaySamplePosition += mSeqTimebase * mBgmVar3;
} else if (mpSeqConfig != nullptr) {
mSeqPlaySamplePosition += tickDiff;
if (mSeqPlaySamplePosition < (mpSeqConfig->mLoopEnd + 1) * timeBase) {
// not looped yet, no adjustment needed
return;
}
// looped, simple adjustment - simplified compared to dSndBgmSound_c which always calculates
// mSeqPlaySamplePosition freshly. This function instead uses the difference
mSeqPlaySamplePosition -= (timeBase * (mpSeqConfig->mLoopEnd - mpSeqConfig->mLoopStart));
}
}