snd_AnimSound OK

This commit is contained in:
robojumper
2025-05-29 15:10:23 +02:00
parent 79b2018642
commit 8894f73305
16 changed files with 733 additions and 47 deletions
+4 -2
View File
@@ -5,6 +5,8 @@
#include "nw4r/types_nw4r.h" // IWYU pragma: export
#include "rvl/OS.h" // IWYU pragma: export
#include <cmath>
#define NW4R_MATH_QNAN (-(0.0f / 0.0f))
#define NW4R_MATH_FLT_MAX 3.402823466e+38f
@@ -30,7 +32,7 @@ inline f32 FAbs(register f32 x) {
}
inline f32 FCeil(f32 x) {
return ceilf(x);
return std::ceilf(x);
}
inline f32 FExp(f32 x) {
@@ -38,7 +40,7 @@ inline f32 FExp(f32 x) {
}
inline f32 FFloor(f32 x) {
return floorf(x);
return std::floorf(x);
}
inline f32 FInv(register f32 x) {
+137
View File
@@ -1 +1,138 @@
/* Only implemented to the extent necessary to match data sections. */
#include "nw4r/snd/snd_AnimSoundReader.h"
#include "nw4r/snd/snd_BasicSound.h"
#include "nw4r/snd/snd_SoundHandle.h"
#include "nw4r/snd/snd_SoundStartable.h"
// Class and non-inline function names from InazumaWii, everything else made up
namespace nw4r {
namespace snd {
namespace detail {
class AnimEventPlayer {
public:
AnimEventPlayer();
~AnimEventPlayer();
SoundHandle *GetHandle() {
return &mHandle;
}
bool IsAttachedSound() const {
return mHandle.IsAttachedSound();
}
bool IsCurrentEvent(const AnimEvent *event) const {
return event == mpEvent;
}
int GetPriority() const {
if (!IsAttachedSound()) {
return 0;
}
return mHandle.detail_GetAttachedSound()->GetPriority();
}
bool IsRunning() const {
return mIsRunning;
}
void SetRunning(bool running) {
mIsRunning = running;
}
void UpdateFrame() {
if (!mHandle.IsAttachedSound()) {
mpEvent = 0;
}
}
void Stop() {
if (IsAttachedSound()) {
mHandle.detail_GetAttachedSound()->Stop(0);
}
mpEvent = 0;
}
void StopEvent(const AnimEvent *event) {
if (mpEvent == event) {
Stop();
}
}
void SetVolume(f32 volume) {
if (IsAttachedSound()) {
mHandle.detail_GetAttachedSound()->SetVolume(volume, 0);
}
}
void SetPitch(f32 pitch) {
if (IsAttachedSound()) {
mHandle.detail_GetAttachedSound()->SetPitch(pitch);
}
}
bool StartSound(const AnimEvent *event, SoundStartable *startable, bool b);
bool HoldSound(const AnimEvent *event, SoundStartable *startable, bool b);
void SetVolumePitch(const AnimEvent *event, bool b);
void SetVariable(const AnimEvent *event, u32 varNo, f32 f);
private:
SoundHandle mHandle; // at 0x00
const AnimEvent *mpEvent; // at 0x04
bool mIsRunning; // at 0x08
};
class AnimSoundImpl {
public:
enum PlayDirection {
FORWARD,
BACKWARD,
};
AnimSoundImpl(SoundStartable &startable, AnimEventPlayer *player, int);
~AnimSoundImpl();
bool Setup(const void *data);
void Shutdown();
void ResetFrame(f32, int);
void UpdateFrame(f32 frame, PlayDirection dir);
void UpdateForward(f32 frame);
void UpdateBackward(f32 frame);
void UpdateTrigger(const AnimEventRef *, s32, PlayDirection);
void UpdateForwardRange(const AnimEventRef *, s32);
void UpdateBackwardRange(const AnimEventRef *, s32);
void StartEvent(const AnimEvent *, bool);
void HoldEvent(const AnimEvent *, bool);
// StartEvent is not inlined, but there seems to be
// a corresponding StopEvent function that got inlined
void StopEvent(const AnimEvent *);
// Made up inlines
bool ShouldPlayEvent(const AnimEventRef *ref) const;
void UpdateEvents(s32 duration, PlayDirection direction);
typedef void (*Callback)(int, s32, const char *, UNKWORD, UNKWORD);
private:
/* 0x00 */ SoundStartable &mStartable;
/* 0x04 */ AnimSoundFileReader mReader;
/* 0x0C */ f32 field_0x0C;
/* 0x10 */ AnimEventPlayer *mpSounds;
/* 0x14 */ int mNumSounds;
/* 0x18 */ bool mIsActive;
/* 0x19 */ u8 field_0x19;
/* 0x1A */ u8 field_0x1A;
/* 0x1C */ UNKWORD field_0x1C;
/* 0x20 */ Callback mCallback;
/* 0x24 */ UNKWORD field_0x24;
/* 0x28 */ f32 field_0x28;
/* 0x2C */ f32 mVariableValue;
};
} // namespace detail
} // namespace snd
} // namespace nw4r
+58 -4
View File
@@ -5,11 +5,54 @@ namespace nw4r {
namespace snd {
namespace detail {
struct AnimEvent {};
struct AnimEvent {
u32 flags_0x00; // at 0x00
u32 soundId; // at 0x04
detail::Util::DataRef<const char> soundLabelRef; // at 0x08
u8 volume; // at 0x10
u8 field_0x11; // at 0x11
u8 varNo; // at 0x12
f32 pitch; // at 0x14
UNKWORD field_0x18; // at 0x18
UNKWORD field_0x1C; // at 0x1C
bool ShouldPreventStart() const {
return flags_0x00 & 1;
}
const char *GetSoundLabel() const {
return Util::GetDataRefAddress0(soundLabelRef, this);
}
bool GetVarNo(u32 *var) const {
if (ShouldSetVariable()) {
*var = varNo;
return true;
}
return false;
}
bool ShouldSetVariable() const {
return flags_0x00 & 2;
}
bool MatchesDirection(int playDirection) const {
bool ret = 0;
u32 config = field_0x11;
if ((config == 0 || (playDirection == 0 && config == 1) || (playDirection == 1 && config == 2))) {
ret = true;
}
return ret;
}
};
struct AnimEventRef {
u8 _0x00[0xC];
Util::DataRef<AnimEvent> event; // at 0x08
int field_0x00; // at 0x08
int field_0x04; // at 0x04
u8 flags_0x08; // at 0x08
s8 field_0x09; // at 0x09
u8 field_0x0A; // at 0x0A
Util::DataRef<AnimEvent> event; // at 0x0C
};
struct AnimSoundFile {
@@ -27,7 +70,7 @@ struct AnimSoundFile {
struct Block {
ut::BinaryBlockHeader blockHeader; // at 0x00
UNKWORD _0x08; // at 0x08
u32 duration; // at 0x08
Util::DataRef<EventTable> eventTable; // at 0x0C
};
};
@@ -43,6 +86,17 @@ public:
const AnimEventRef *GetEventRef(u32 id) const;
const AnimEvent *GetEvent(const AnimEventRef *ref) const;
bool IsValid() const {
return mpHeader != NULL;
}
u32 GetAnimDuration() const {
if (!IsValid()) {
return 0;
}
return mpBlock->duration;
}
private:
const AnimSoundFile::Header *mpHeader; // at 0x00
const AnimSoundFile::Block *mpBlock; // at 0x04
+1
View File
@@ -260,6 +260,7 @@ namespace nw4r { namespace snd { namespace detail
PlayerHeap *GetPlayerHeap() { return mPlayerHeap; }
SoundPlayer *GetSoundPlayer() { return mSoundPlayer; }
int GetVoiceOutCount() const;
int GetPriority() const { return mPriority; }
void SetPlayerPriority(int priority);
void SetInitialVolume(f32 volume);
+3 -2
View File
@@ -21,8 +21,9 @@ public:
private:
static const int SPEAKER_ALARM_HZ = 150;
static const int SPEAKER_ALARM_PERIOD_NSEC = static_cast<int>(1.0f / SPEAKER_ALARM_HZ * 1000 * 1000 * 1000);
// commented out since it causes compiler warnings
// static const int SPEAKER_ALARM_PERIOD_NSEC = static_cast<int>(1.0f / SPEAKER_ALARM_HZ * 1000 * 1000 * 1000);
static const int SPEAKER_ALARM_PERIOD_NSEC = 6666667;
private:
RemoteSpeakerManager();
+6
View File
@@ -7,6 +7,7 @@
#include "common.h" // nullptr
#include "nw4r/snd/snd_SeqSound.h"
#include "nw4r/ut/ut_NonCopyable.h" // ut::NonCopyable
/*******************************************************************************
@@ -33,6 +34,11 @@ namespace nw4r { namespace snd
void DetachSound();
void WriteVariable(int varNo, s16 value) {
if (IsAttachedSound())
mSound->WriteVariable(varNo, value);
}
// members
private:
/* base ut::NonCopyable */ // size 0x00, offset 0x00
+6
View File
@@ -31,8 +31,14 @@ namespace nw4r { namespace snd
void detail_AttachSound(detail::BasicSound *sound);
bool IsAttachedSound() const { return mSound != nullptr; }
detail::BasicSound *detail_GetAttachedSound() { return mSound; }
const detail::BasicSound *detail_GetAttachedSound() const { return mSound; }
void DetachSound();
void Stop() {
if (IsAttachedSound())
mSound->Stop(0);
}
u32 GetId() const
{
if (IsAttachedSound())
+15 -10
View File
@@ -144,35 +144,40 @@ namespace nw4r { namespace snd
const StartInfo *pStartInfo
);
// TODO: Fix after removal of above functions
bool StartSound(SoundHandle *pHandle, u32 id) {
return detail_StartSound(pHandle, id, NULL, NULL, NULL) == START_SUCCESS;
return detail_StartSound(pHandle, id, NULL) == START_SUCCESS;
}
bool StartSound(SoundHandle *pHandle, const char *label) {
return detail_StartSound(pHandle, label, NULL) == START_SUCCESS;
}
bool StartSound(SoundHandle *pHandle, unsigned int id) {
return detail_StartSound(pHandle, id, NULL, NULL, NULL) == START_SUCCESS;
return detail_StartSound(pHandle, id, NULL) == START_SUCCESS;
}
bool StartSound(SoundHandle *pHandle, int id) {
return detail_StartSound(pHandle, id, NULL, NULL, NULL) == START_SUCCESS;
return detail_StartSound(pHandle, id, NULL) == START_SUCCESS;
}
bool HoldSound(SoundHandle *pHandle, u32 id) {
return detail_HoldSound(pHandle, id, NULL, NULL, NULL) == START_SUCCESS;
return detail_HoldSound(pHandle, id, NULL) == START_SUCCESS;
}
bool HoldSound(SoundHandle *pHandle, const char *label) {
return detail_HoldSound(pHandle, label, NULL) == START_SUCCESS;
}
bool HoldSound(SoundHandle *pHandle, unsigned int id) {
return detail_HoldSound(pHandle, id, NULL, NULL, NULL) == START_SUCCESS;
return detail_HoldSound(pHandle, id, NULL) == START_SUCCESS;
}
bool HoldSound(SoundHandle *pHandle, int id) {
return detail_HoldSound(pHandle, id, NULL, NULL, NULL) == START_SUCCESS;
return detail_HoldSound(pHandle, id, NULL) == START_SUCCESS;
}
bool PrepareSound(SoundHandle *pHandle, u32 id) {
return detail_PrepareSound(pHandle, id, NULL, NULL, NULL) == START_SUCCESS;
return detail_PrepareSound(pHandle, id, NULL) == START_SUCCESS;
}
bool PrepareSound(SoundHandle *pHandle, unsigned int id) {
return detail_PrepareSound(pHandle, id, NULL, NULL, NULL) == START_SUCCESS;
return detail_PrepareSound(pHandle, id, NULL) == START_SUCCESS;
}
bool PrepareSound(SoundHandle *pHandle, int id) {
return detail_PrepareSound(pHandle, id, NULL, NULL, NULL) == START_SUCCESS;
return detail_PrepareSound(pHandle, id, NULL) == START_SUCCESS;
}
// members