summaryrefslogtreecommitdiff
path: root/include/nw4r/snd/snd_AnimSoundReader.h
blob: 43e9adf14ef37a950bbf5580779a08e33aae85cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "nw4r/snd/snd_Util.h"
#include "nw4r/ut/ut_binaryFileFormat.h"

namespace nw4r {
namespace snd {
namespace detail {

// Type and name revealed by BBA
struct AnimEventFrameInfo {
    int field_0x00; // at 0x00
    int field_0x04; // at 0x04
    u8 flags;       // at 0x08
    s8 field_0x09;  // at 0x09
    u8 field_0x0A;  // at 0x0A
};

struct AnimEvent {
    u32 flags;                                       // 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 & 1;
    }

    const char *GetSoundLabel() const {
        return Util::GetDataRefAddress0(soundLabelRef, this);
    }

    bool GetVarNo(u32 *var) const {
        if (flags & 2) {
            *var = varNo;
            return true;
        }
        return false;
    }

    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;
    }
};

// Name from Inazuma, BBA
struct AnimEventRef {
    AnimEventFrameInfo mInfo;       // at 0x00
    Util::DataRef<AnimEvent> event; // at 0x0C
};

// Names unknown
struct AnimSoundFile {
    static u32 const SIGNATURE_FILE = NW4R_FOUR_BYTE('R', 'A', 'S', 'D');
    static int const FILE_VERSION = NW4R_FILE_VERSION(1, 0);

    struct Header {
        ut::BinaryFileHeader fileHeader; // size 0x10, offset 0x00
        u32 blockOffset;                 // at 0x10
    };

    struct EventTable {
        Util::Table<AnimEventRef> eventRef; // at 0x00
    };

    struct Block {
        ut::BinaryBlockHeader blockHeader;    // at 0x00
        u32 duration;                         // at 0x08
        Util::DataRef<EventTable> eventTable; // at 0x0C
    };
};

// Name from Inazuma
class AnimSoundFileReader {
public:
    AnimSoundFileReader();
    bool Setup(const void *buf);
    void Shutdown();
    u32 GetEventCount() const;

    const AnimSoundFile::EventTable *GetEventTable() const;
    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
};

} // namespace detail
} // namespace snd
} // namespace nw4r