summaryrefslogtreecommitdiff
path: root/include/JSystem/JAudio2/JAUSoundTable.h
blob: 7b508b97569d1e9c08b6d039b4fa7fde639ad776 (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#ifndef JAUSOUNDTABLE_H
#define JAUSOUNDTABLE_H

#include "JSystem/JAudio2/JAISound.h"
#include "JSystem/JAudio2/JASGadget.h"

/**
 * @ingroup jsystem-jaudio
 * 
 */
struct JAUSoundTableItem {
    u8 mPriority;
    u8 field_0x1;
    u16 mResourceId;
    u32 field_0x4;
    f32 field_0x8;
};

/**
 * @ingroup jsystem-jaudio
 * 
 */
template<typename Root, typename Section, typename Group, typename Typename_0>
struct JAUSoundTable_ {
    JAUSoundTable_() {
        field_0x0 = NULL;
        field_0x4 = 0;
    }

    void reset() {
        field_0x0 = NULL;
        field_0x4 = NULL;
    }

    void init(const void* param_0) {
        field_0x0 = param_0;
        // magic number is not in debug rom. I'm not sure what this comparison is (maybe some sort of '' number?)
        // I also do not know how it is different between JAUSoundTable and JAUSoundNameTable
        if (*(u32*)field_0x0 + 0xbdad0000 != Root::magicNumber()) {
            field_0x0 = NULL;
        } else {
            field_0x4 = (Root*)((u8*)field_0x0 + *((u32*)field_0x0 + 3));
        }
    }

    Section* getSection(int index) const {
        if (index < 0) {
            return NULL;
        }
        if ((u32)index >= field_0x4->mSectionNumber) {
            return NULL;
        }
        u32 offset = field_0x4->mSectionOffsets[index];
        if (offset == 0) {
            return NULL;
        } 
        return (Section*)((u8*)field_0x0 + offset);
    }

    Group* getGroup(Section* param_1, int index) const {
        int iVar1;

        if (index < 0) {
            return NULL;
        } 
        if ((u32)index >= param_1->mNumGroups) {
            return NULL;
        }
        u32 offset = param_1->getGroupOffset(index);
        if (offset == 0) {
            return NULL;
        } 
        return (Group*)((u8*)field_0x0 + offset);
    }

    const void* field_0x0;
    Root* field_0x4;
    u32 field_0x8;
    u32 field_0xc;
};

/**
 * @ingroup jsystem-jaudio
 * 
 */
struct JAUSoundTableRoot {
    static inline u32 magicNumber() { return 0x5420; }
    u32 mSectionNumber;
    u32 mSectionOffsets[0];
};

/**
 * @ingroup jsystem-jaudio
 * 
 */
struct JAUSoundTableSection {
    int getGroupOffset(int index) const {
        if (index < 0) {
            return 0;
        }
        if (index >= mNumGroups) {
            return 0;
        }
        return mGroupOffsets[index];
    }

    u32 mNumGroups;
    u32 mGroupOffsets[0];
};

/**
 * @ingroup jsystem-jaudio
 * 
 */
struct JAUSoundTableGroup {
    u8 getTypeID(int index) const {
        if (index < 0) {
            return 0;
        }
        if (index >= mNumItems) {
            return 0xff;
        }
        return mTypeIds[index * 4];
    }

    u32 getItemOffset(int index) const {
        if (index < 0) {
            return 0;
        }
        if (index >= mNumItems) {
            return 0;
        }
        return *(u32*)(mTypeIds + index * 4) & 0xffffff;
    }

    u32 mNumItems;
    u32 field_0x4;
    u8 mTypeIds[0];
};

/**
 * @ingroup jsystem-jaudio
 * 
 */
struct JAUSoundTable : public JASGlobalInstance<JAUSoundTable> {
    JAUSoundTable(bool param_0) : JASGlobalInstance<JAUSoundTable>(param_0) {
    }
    ~JAUSoundTable() {}
    
    /* 802A7114 */ void init(void const*);
    /* 802A7160 */ u8 getTypeID(JAISoundID) const;
    /* 802A728C */ JAUSoundTableItem* getData(JAISoundID) const;

    JAUSoundTableItem* getItem(JAUSoundTableGroup* group, int index) const {
        u32 offset = group->getItemOffset(index);
        if (offset == 0) {
            return NULL;
        }
        return (JAUSoundTableItem*)((u8*)field_0x0.field_0x0 + offset);
    }

    const void* getResource() { return field_0x0.field_0x0; }

    JAUSoundTable_<JAUSoundTableRoot,JAUSoundTableSection,JAUSoundTableGroup,void> field_0x0;
};

/**
 * @ingroup jsystem-jaudio
 * 
 */
struct JAUSoundNameTableRoot {
    static inline u32 magicNumber() { return 0x544e; }
    u32 mSectionNumber;
    u32 mSectionOffsets[0];
};
/**
 * @ingroup jsystem-jaudio
 * 
 */
struct JAUSoundNameTableSection {};

/**
 * @ingroup jsystem-jaudio
 * 
 */
struct JAUSoundNameTableGroup {};

/**
 * @ingroup jsystem-jaudio
 * 
 */
struct JAUSoundNameTable : public JASGlobalInstance<JAUSoundNameTable> {
    JAUSoundNameTable(bool param_0) : JASGlobalInstance<JAUSoundNameTable>(param_0) {
    }
    ~JAUSoundNameTable() {}
    /* 802A73D4 */ void init(void const*);

    JAUSoundTable_<JAUSoundNameTableRoot,JAUSoundNameTableSection,JAUSoundNameTableGroup,void> field_0x0;
};

#endif /* JAUSOUNDTABLE_H */