summaryrefslogtreecommitdiff
path: root/src/Z2AudioLib/Z2SoundInfo.cpp
blob: eba28a7d0807d11de5528e599ec73d1a887f672f (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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#include "Z2AudioLib/Z2SoundInfo.h"
#include "JSystem/JAudio2/JAISeq.h"
#include "JSystem/JAudio2/JAISe.h"
#include "JSystem/JAudio2/JAISoundChild.h"
#include "JSystem/JAudio2/JAIStream.h"
#include "JSystem/JAudio2/JAUSoundTable.h"
#include "JSystem/JUtility/JUTAssert.h"
#include "Z2AudioLib/Z2Calc.h"

struct JAUStdSoundTableType {
    static const u32 STRM_CH_SHIFT;
    struct StringOffset {
        static inline const char* getString(const void* addr, u32 offset) {
            return (const char*)addr + offset;
        }
    };
};

/* 802BB00C-802BB090 2B594C 0084+00 2/1 0/0 0/0 .text
 * getBgmSeqResourceID__11Z2SoundInfoCF10JAISoundID             */
u16 Z2SoundInfo::getBgmSeqResourceID(JAISoundID soundID) const {
    JUT_ASSERT(20, isValid());
    JAUSoundTableItem* data = JASGlobalInstance<JAUSoundTable>::getInstance()->getData(soundID);
    u8 typeID = JASGlobalInstance<JAUSoundTable>::getInstance()->getTypeID(soundID);

    if (data != NULL) {
        switch ((typeID & 0xf0)) {
        case 0x60:
            return (u16)data->mResourceId;
        }
    }

    return 0xffff;
}

/* 802BB090-802BB0D8 2B59D0 0048+00 1/0 0/0 0/0 .text getSoundType__11Z2SoundInfoCF10JAISoundID */
int Z2SoundInfo::getSoundType(JAISoundID soundID) const {
    switch (soundID.id_.info.type.parts.sectionID) {
    case 0:
        return 0;
    case 1:
        return 1;
    case 2:
        return 2;
    }

    return -1;
}

/* 802BB0D8-802BB0E0 2B5A18 0008+00 1/0 0/0 0/0 .text getCategory__11Z2SoundInfoCF10JAISoundID */
int Z2SoundInfo::getCategory(JAISoundID soundID) const {
    return soundID.id_.info.type.parts.groupID;
}

/* 802BB0E0-802BB158 2B5A20 0078+00 1/0 0/0 0/0 .text getPriority__11Z2SoundInfoCF10JAISoundID */
u32 Z2SoundInfo::getPriority(JAISoundID soundID) const {
    JUT_ASSERT(63, isValid());
    JAUSoundTableItem* data = JASGlobalInstance<JAUSoundTable>::getInstance()->getData(soundID);
    u8 typeID = JASGlobalInstance<JAUSoundTable>::getInstance()->getTypeID(soundID);

    if (data != NULL && (typeID & 0x40) != 0) {
        return data->mPriority;
    }

    return 0;
}

/* 802BB158-802BB448 2B5A98 02F0+00 0/0 1/1 0/0 .text getAudibleSwFull__11Z2SoundInfoF10JAISoundID
 */
JAUAudibleParam Z2SoundInfo::getAudibleSwFull(JAISoundID soundID) {
    JAUAudibleParam audibleParam;
    JUT_ASSERT(82, isValid());
    int iVar1, uVar7;

    u8 typeID = JASGlobalInstance<JAUSoundTable>::getInstance()->getTypeID(soundID);
    switch (typeID) {
    case 81:
        audibleParam.field_0x0.bytes.b0_0 = (u32)getSwBit(soundID) >> 8;
        if ((getSwBit(soundID) & 1) != 0) {
            audibleParam.field_0x0.bytes.b0_4 = 0;
        } else {
            audibleParam.field_0x0.bytes.b0_4 = 1;
        }

        if ((getSwBit(soundID) & 2) != 0) {
            audibleParam.field_0x0.bytes.b0_5 = 0;
        } else {
            audibleParam.field_0x0.bytes.b0_5 = 1;
        }

        if ((getSwBit(soundID) & 4) != 0) {
            audibleParam.field_0x0.bytes.b0_6 = 0;
        } else {
            audibleParam.field_0x0.bytes.b0_6 = 1;
        }

        if ((getSwBit(soundID) & 0x800000) != 0) {
            audibleParam.field_0x0.bytes.b0_7 = 1;
        } else {
            audibleParam.field_0x0.bytes.b0_7 = 0;
        }

        if ((getSwBit(soundID) & 0x1000) != 0) {
            audibleParam.field_0x0.bytes.b1_0 = 0;
        } else {
            audibleParam.field_0x0.bytes.b1_0 = 1;
        }

        if ((getSwBit(soundID) & 0x2000) != 0) {
            audibleParam.field_0x0.bytes.b1_1 = 0;
        } else {
            audibleParam.field_0x0.bytes.b1_1 = 1;
        }

        uVar7 = 0;
        if ((getSwBit(soundID) & 0x80000) != 0) {
            uVar7 = 8;
        }

        iVar1 = (getSwBit(soundID) >> 16) & 0x7;
        iVar1 += (getSwBit(soundID) >> 16) & 0x70;
        iVar1 += (getSwBit(soundID) >> 16) & 0xf00;
        audibleParam.field_0x0.bytes.b1_2_7 = uVar7;
        audibleParam.field_0x0.half.f1 = iVar1;
        break;
    default:
        audibleParam.field_0x0.bytes.b0_0 = 0;
        audibleParam.field_0x0.bytes.b0_4 = 1;
        audibleParam.field_0x0.bytes.b0_5 = 1;
        audibleParam.field_0x0.bytes.b0_6 = 1;
        audibleParam.field_0x0.bytes.b0_7 = 0;
        audibleParam.field_0x0.bytes.b1_0 = 1;
        audibleParam.field_0x0.bytes.b1_1 = 1;
        audibleParam.field_0x0.bytes.b1_2_7 = 0;
        audibleParam.field_0x0.half.f1 = 0;
        break;
    }

    return audibleParam;
}

/* 802BB448-802BB6DC 2B5D88 0294+00 2/1 0/0 0/0 .text getAudibleSw__11Z2SoundInfoCF10JAISoundID */
u16 Z2SoundInfo::getAudibleSw(JAISoundID soundID) const {
    JAUAudibleParam audibleParam;
    JUT_ASSERT(184, isValid());
    int iVar1, uVar7;

    u8 typeID = JASGlobalInstance<JAUSoundTable>::getInstance()->getTypeID(soundID);
    switch (typeID) {
    case 81:
        audibleParam.field_0x0.bytes.b0_0 = (u32)getSwBit(soundID) >> 8;
        if ((getSwBit(soundID) & 1) != 0) {
            audibleParam.field_0x0.bytes.b0_4 = 0;
        } else {
            audibleParam.field_0x0.bytes.b0_4 = 1;
        }

        if ((getSwBit(soundID) & 2) != 0) {
            audibleParam.field_0x0.bytes.b0_5 = 0;
        } else {
            audibleParam.field_0x0.bytes.b0_5 = 1;
        }

        if ((getSwBit(soundID) & 4) != 0) {
            audibleParam.field_0x0.bytes.b0_6 = 0;
        } else {
            audibleParam.field_0x0.bytes.b0_6 = 1;
        }

        if ((getSwBit(soundID) & 0x800000) != 0) {
            audibleParam.field_0x0.bytes.b0_7 = 1;
        } else {
            audibleParam.field_0x0.bytes.b0_7 = 0;
        }

        if ((getSwBit(soundID) & 0x1000) != 0) {
            audibleParam.field_0x0.bytes.b1_0 = 0;
        } else {
            audibleParam.field_0x0.bytes.b1_0 = 1;
        }

        if ((getSwBit(soundID) & 0x2000) != 0) {
            audibleParam.field_0x0.bytes.b1_1 = 0;
        } else {
            audibleParam.field_0x0.bytes.b1_1 = 1;
        }

        uVar7 = 0;
        if ((getSwBit(soundID) & 0x80000) != 0) {
            uVar7 = 8;
        }

        iVar1 = (getSwBit(soundID) >> 16) & 0x7;
        iVar1 += (getSwBit(soundID) >> 16) & 0x70;
        iVar1 += (getSwBit(soundID) >> 16) & 0xf00;
        audibleParam.field_0x0.bytes.b1_2_7 = uVar7;
        audibleParam.field_0x0.half.f1 = iVar1;
        break;
    default:
        audibleParam.field_0x0.half.f0 = 0xffff;
        audibleParam.field_0x0.half.f1 = 0xffff;
        break;
    }

    return audibleParam.field_0x0.half.f0;
}

/* 802BB6DC-802BB8B4 2B601C 01D8+00 1/0 0/0 0/0 .text
 * getSeInfo__11Z2SoundInfoCF10JAISoundIDP5JAISe                */
void Z2SoundInfo::getSeInfo(JAISoundID soundID, JAISe* sePtr) const {
    getSoundInfo_(soundID, sePtr);
    JUT_ASSERT(292, isValid());

    JAUSoundTableItem* data = JASGlobalInstance<JAUSoundTable>::getInstance()->getData(soundID);
    u8 typeID = JASGlobalInstance<JAUSoundTable>::getInstance()->getTypeID(soundID);
    if (data == NULL) {
        return;
    }

    switch(typeID) {
    case 81:
        sePtr->getProperty().field_0x8 *= data->field_0x8;
        u32 uStack_6c = (getSwBit(soundID) & 0xf0) >> 4;
        if (uStack_6c > 8) {
            sePtr->getProperty().field_0x8 += Z2Calc::linearTransform(uStack_6c, 8.0f, 15.0f, 16.0f, 24.0f, true) / 48.0f * Z2Calc::getRandom_0_1();
        } else {
            sePtr->getProperty().field_0x8 += (uStack_6c / 48.0f) * Z2Calc::getRandom_0_1();
        }

        u32 uVar1 = (u32)getSwBit(soundID) >> 0x1c;
        if (uVar1 != 0) {
            f32 dVar18 = (uVar1 / 15.0f) * Z2Calc::getRandom_0_1();
            sePtr->getProperty().field_0x0 -= dVar18 < 0.0f ? 0.0f : (dVar18 > 1.0f ? 1.0f : dVar18);
        }
        break;
    }
}

/* 802BB8B4-802BB8E0 2B61F4 002C+00 1/0 0/0 0/0 .text
 * getSeqInfo__11Z2SoundInfoCF10JAISoundIDP6JAISeq              */
void Z2SoundInfo::getSeqInfo(JAISoundID soundID, JAISeq* seqPtr) const {
    getSoundInfo_(soundID, seqPtr);
}

/* 80455A90-80455A94 004090 0004+00 1/1 0/0 0/0 .sdata2 STRM_CH_SHIFT__20JAUStdSoundTableType */
const u32 JAUStdSoundTableType::STRM_CH_SHIFT = 2;

/* 802BB8E0-802BBA10 2B6220 0130+00 1/0 0/0 0/0 .text
 * getStreamInfo__11Z2SoundInfoCF10JAISoundIDP9JAIStream        */
void Z2SoundInfo::getStreamInfo(JAISoundID soundID, JAIStream* streamPtr) const {
    int numChild;
    JAUSoundTableItem* data;
    getSoundInfo_(soundID, streamPtr);
    JUT_ASSERT(349, isValid());

    u8 typeID = JASGlobalInstance<JAUSoundTable>::getInstance()->getTypeID(soundID);
    switch (typeID & 0xf0) {
    case 0x70:
        u16 uVar1;
        s32 iVar4;
        data = JASGlobalInstance<JAUSoundTable>::getInstance()->getData(soundID);
        JUT_ASSERT(356, data);

        uVar1 = data->mResourceId;
        numChild = streamPtr->getNumChild();
        iVar4 = 0;
        for (; iVar4 < numChild && uVar1 != 0; uVar1 >>= JAUStdSoundTableType::STRM_CH_SHIFT, iVar4++) {
            u32 uVar2 = uVar1 & 3;
            if (uVar2 != 0) {
                JAISoundChild* child = streamPtr->getChild(iVar4);
                if (child != NULL) {
                    switch (uVar2) {
                    case 1:
                        child->mMove.params_.mPan = 0.5f;
                        break;
                    case 2:
                        child->mMove.params_.mPan = 0.0f;
                        break;
                    case 3:
                        child->mMove.params_.mPan = 1.0f;
                        break;
                    }
                }
            }
        }
    }
}

/* 802BBA10-802BBA88 2B6350 0078+00 1/1 0/0 0/0 .text
 * getStreamFilePath__11Z2SoundInfoF10JAISoundID                */
const char* Z2SoundInfo::getStreamFilePath(JAISoundID soundID) {
    JUT_ASSERT(387, isValid());
    JAUSoundTableItem* data;
    const void* resource;

    switch (JASGlobalInstance<JAUSoundTable>::getInstance()->getTypeID(soundID) & 0xf0) {
    case 0x70:
        data = JASGlobalInstance<JAUSoundTable>::getInstance()->getData(soundID);
        JUT_ASSERT(394, data);
        resource = JASGlobalInstance<JAUSoundTable>::getInstance()->getResource();
        JUT_ASSERT(398, resource);
        return JAUStdSoundTableType::StringOffset::getString(resource, data->field_0x4);
    default:
        return NULL;
    }
}

/* 802BBA88-802BBAC8 2B63C8 0040+00 2/1 0/0 0/0 .text
 * getStreamFileEntry__11Z2SoundInfoF10JAISoundID               */
s32 Z2SoundInfo::getStreamFileEntry(JAISoundID soundID) {
    const char* path = getStreamFilePath(soundID);
    return !path ? -1 : DVDConvertPathToEntrynum(path);
}

/* 802BBAC8-802BBB48 2B6408 0080+00 3/3 4/4 0/0 .text getSwBit__11Z2SoundInfoCF10JAISoundID */
int Z2SoundInfo::getSwBit(JAISoundID soundID) const {
    JUT_ASSERT(418, isValid());
    JAUSoundTableItem* data = JASGlobalInstance<JAUSoundTable>::getInstance()->getData(soundID);

    u8 typeID = JASGlobalInstance<JAUSoundTable>::getInstance()->getTypeID(soundID);
    if (data != NULL) {
        switch(typeID) {
        case 81:
            return data->field_0x4;
        }
    }

    return 0xFFFFFFFF;
}

/* 802BBB48-802BBBE0 2B6488 0098+00 3/3 0/0 0/0 .text
 * getSoundInfo___11Z2SoundInfoCF10JAISoundIDP8JAISound         */
void Z2SoundInfo::getSoundInfo_(JAISoundID soundID, JAISound* soundPtr) const {
    JUT_ASSERT(440, isValid());
    JAUSoundTableItem* data = JASGlobalInstance<JAUSoundTable>::getInstance()->getData(soundID);

    u8 typeID = JASGlobalInstance<JAUSoundTable>::getInstance()->getTypeID(soundID);
    if (data != NULL && (typeID & 0x40) != 0) {
        soundPtr->getProperty().field_0x0 = (1.0f / 127.0f) * data->field_0x1;
    }
}