summaryrefslogtreecommitdiff
path: root/src/Z2AudioLib/Z2SoundInfo.cpp
blob: 67b957282b914c0491a501a614332d43f6d34f57 (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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
//
// Generated By: dol2asm
// Translation Unit: Z2SoundInfo
//

#include "Z2AudioLib/Z2SoundInfo.h"
#include "JSystem/JAudio2/JAISeq.h"
#include "JSystem/JAudio2/JAISe.h"
#include "JSystem/JAudio2/JAUSoundTable.h"
#include "JSystem/JUtility/JUTAssert.h"
#include "Z2AudioLib/Z2Calc.h"
#include "dol2asm.h"
#include "dolphin/dvd.h"

//
// Types:
//

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

//
// Forward References:
//

extern "C" void getBgmSeqResourceID__11Z2SoundInfoCF10JAISoundID();
extern "C" void getSoundType__11Z2SoundInfoCF10JAISoundID();
extern "C" void getCategory__11Z2SoundInfoCF10JAISoundID();
extern "C" void getPriority__11Z2SoundInfoCF10JAISoundID();
extern "C" void getAudibleSwFull__11Z2SoundInfoF10JAISoundID();
extern "C" void getAudibleSw__11Z2SoundInfoCF10JAISoundID();
extern "C" void getSeInfo__11Z2SoundInfoCF10JAISoundIDP5JAISe();
extern "C" void getSeqInfo__11Z2SoundInfoCF10JAISoundIDP6JAISeq();
extern "C" void getStreamInfo__11Z2SoundInfoCF10JAISoundIDP9JAIStream();
extern "C" void getStreamFilePath__11Z2SoundInfoF10JAISoundID();
extern "C" void getStreamFileEntry__11Z2SoundInfoF10JAISoundID();
extern "C" void getSwBit__11Z2SoundInfoCF10JAISoundID();
extern "C" void getSoundInfo___11Z2SoundInfoCF10JAISoundIDP8JAISound();
extern "C" void __dt__11Z2SoundInfoFv();
extern "C" static void func_802BBCBC();
extern "C" static void func_802BBCC4();
extern "C" static void func_802BBCCC();
extern "C" static void func_802BBCD4();
extern "C" u32 STRM_CH_SHIFT__20JAUStdSoundTableType;

//
// External References:
//

extern "C" void __dt__12JAISoundInfoFv();
extern "C" void __dt__16JAIStreamDataMgrFv();
extern "C" void getTypeID__13JAUSoundTableCF10JAISoundID();
extern "C" void getData__13JAUSoundTableCF10JAISoundID();
extern "C" void linearTransform__6Z2CalcFfffffb();
extern "C" void getRandom_0_1__6Z2CalcFv();
extern "C" void __dl__FPv();
extern "C" void _savegpr_26();
extern "C" void _savegpr_27();
extern "C" void _savegpr_28();
extern "C" void _savegpr_29();
extern "C" void _restgpr_26();
extern "C" void _restgpr_27();
extern "C" void _restgpr_28();
extern "C" void _restgpr_29();
extern "C" extern void* __vt__12JAUSoundInfo[4 + 1 /* padding */];
extern "C" extern u8 data_80450B58[4];
extern "C" extern u8 __OSReport_disable;

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

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

/* 802BB090-802BB0D8 2B59D0 0048+00 1/0 0/0 0/0 .text getSoundType__11Z2SoundInfoCF10JAISoundID */
int Z2SoundInfo::getSoundType(JAISoundID param_0) const {
    switch (param_0.mId.mBytes.b0) {
    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 param_0) const {
    return param_0.mId.mBytes.b1;
}

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

    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 param_0) {
    JAUAudibleParam local_28;
    JUT_ASSERT(82, isValid());
    switch (JASGlobalInstance<JAUSoundTable>::getInstance()->getTypeID(param_0)) {
    case 81:
        local_28.field_0x0.bytes.b0_0 = (u32)getSwBit(param_0) >> 8;
        if ((getSwBit(param_0) & 1) != 0) {
            local_28.field_0x0.bytes.b0_4 = 0;
        } else {
            local_28.field_0x0.bytes.b0_4 = 1;
        }
        if ((getSwBit(param_0) & 2) != 0) {
            local_28.field_0x0.bytes.b0_5 = 0;
        } else {
            local_28.field_0x0.bytes.b0_5 = 1;
        }
        if ((getSwBit(param_0) & 4) != 0) {
            local_28.field_0x0.bytes.b0_6 = 0;
        } else {
            local_28.field_0x0.bytes.b0_6 = 1;
        }
        if ((getSwBit(param_0) & 0x800000) != 0) {
            local_28.field_0x0.bytes.b0_7 = 1;
        } else {
            local_28.field_0x0.bytes.b0_7 = 0;
        }
        if ((getSwBit(param_0) & 0x1000) != 0) {
            local_28.field_0x0.bytes.b1_0 = 0;
        } else {
            local_28.field_0x0.bytes.b1_0 = 1;
        }
        if ((getSwBit(param_0) & 0x2000) != 0) {
            local_28.field_0x0.bytes.b1_1 = 0;
        } else {
            local_28.field_0x0.bytes.b1_1 = 1;
        }

        int iVar1;
        int uVar7 = 0;
        if ((getSwBit(param_0) & 0x80000) != 0) {
            uVar7 = 8;
        }

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

/* 802BB448-802BB6DC 2B5D88 0294+00 2/1 0/0 0/0 .text getAudibleSw__11Z2SoundInfoCF10JAISoundID */
u16 Z2SoundInfo::getAudibleSw(JAISoundID param_0) const {
    JAUAudibleParam local_28;
    JUT_ASSERT(184, isValid());
    switch (JASGlobalInstance<JAUSoundTable>::getInstance()->getTypeID(param_0)) {
    case 81:
        local_28.field_0x0.bytes.b0_0 = (u32)getSwBit(param_0) >> 8;
        if ((getSwBit(param_0) & 1) != 0) {
            local_28.field_0x0.bytes.b0_4 = 0;
        } else {
            local_28.field_0x0.bytes.b0_4 = 1;
        }
        if ((getSwBit(param_0) & 2) != 0) {
            local_28.field_0x0.bytes.b0_5 = 0;
        } else {
            local_28.field_0x0.bytes.b0_5 = 1;
        }
        if ((getSwBit(param_0) & 4) != 0) {
            local_28.field_0x0.bytes.b0_6 = 0;
        } else {
            local_28.field_0x0.bytes.b0_6 = 1;
        }
        if ((getSwBit(param_0) & 0x800000) != 0) {
            local_28.field_0x0.bytes.b0_7 = 1;
        } else {
            local_28.field_0x0.bytes.b0_7 = 0;
        }
        if ((getSwBit(param_0) & 0x1000) != 0) {
            local_28.field_0x0.bytes.b1_0 = 0;
        } else {
            local_28.field_0x0.bytes.b1_0 = 1;
        }
        if ((getSwBit(param_0) & 0x2000) != 0) {
            local_28.field_0x0.bytes.b1_1 = 0;
        } else {
            local_28.field_0x0.bytes.b1_1 = 1;
        }

        int iVar1;
        int uVar7 = 0;
        if ((getSwBit(param_0) & 0x80000) != 0) {
            uVar7 = 8;
        }

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

/* ############################################################################################## */
/* 80455A68-80455A6C 004068 0004+00 1/1 0/0 0/0 .sdata2          @963 */
SECTION_SDATA2 static f32 lit_963 = 8.0f;

/* 80455A6C-80455A70 00406C 0004+00 1/1 0/0 0/0 .sdata2          @964 */
SECTION_SDATA2 static f32 lit_964 = 15.0f;

/* 80455A70-80455A74 004070 0004+00 1/1 0/0 0/0 .sdata2          @965 */
SECTION_SDATA2 static f32 lit_965 = 16.0f;

/* 80455A74-80455A78 004074 0004+00 1/1 0/0 0/0 .sdata2          @966 */
SECTION_SDATA2 static f32 lit_966 = 24.0f;

/* 80455A78-80455A7C 004078 0004+00 1/1 0/0 0/0 .sdata2          @967 */
SECTION_SDATA2 static f32 lit_967 = 48.0f;

/* 80455A7C-80455A80 00407C 0004+00 2/2 0/0 0/0 .sdata2          @968 */
SECTION_SDATA2 static u8 lit_968[4] = {
    0x00,
    0x00,
    0x00,
    0x00,
};

/* 80455A80-80455A88 004080 0004+04 2/2 0/0 0/0 .sdata2          @969 */
SECTION_SDATA2 static f32 lit_969[1 + 1 /* padding */] = {
    1.0f,
    /* padding */
    0.0f,
};

/* 80455A88-80455A90 004088 0008+00 2/2 0/0 0/0 .sdata2          @973 */
SECTION_SDATA2 static f64 lit_973 = 4503599627370496.0 /* cast u32 to float */;

/* 802BB6DC-802BB8B4 2B601C 01D8+00 1/0 0/0 0/0 .text
 * getSeInfo__11Z2SoundInfoCF10JAISoundIDP5JAISe                */
void Z2SoundInfo::getSeInfo(JAISoundID param_1, JAISe* param_2) const {
    getSoundInfo_(param_1, param_2);
    JUT_ASSERT(292, isValid());
    JAUSoundTableItem* data = JASGlobalInstance<JAUSoundTable>::getInstance()->getData(param_1);
    u8 typeID = JASGlobalInstance<JAUSoundTable>::getInstance()->getTypeID(param_1);
    if (data == NULL) {
        return;
    }
    switch(typeID) {
    case 81:
        param_2->getProperty().field_0x8 *= data->field_0x8;
        u32 uStack_6c = (getSwBit(param_1) & 0xf0) >> 4;
        if (uStack_6c > 8) {
            f32 dVar18 = Z2Calc::getRandom_0_1();
            f32 dVar19 = Z2Calc::linearTransform(uStack_6c, 8.0f, 15.0f, 16.0f, 24.0f, true);
            dVar19 = dVar19 / 48.0f * dVar18;
            param_2->getProperty().field_0x8 += dVar19;
        } else {
            f32 dVar18 = Z2Calc::getRandom_0_1();
            dVar18 = (uStack_6c / 48.0f) * dVar18;
            param_2->getProperty().field_0x8 += dVar18;
        }
        u32 uVar1 = (u32)getSwBit(param_1) >> 0x1c;
        if (uVar1 != 0) {
            f32 dVar18 = (uVar1 / 15.0f) * Z2Calc::getRandom_0_1();
            param_2->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 param_0, JAISeq* param_1) const {
    getSoundInfo_(param_0, param_1);
}

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

/* 80455A94-80455A98 004094 0004+00 1/1 0/0 0/0 .sdata2          @1010 */
SECTION_SDATA2 static f32 lit_1010 = 0.5f;

/* 802BB8E0-802BBA10 2B6220 0130+00 1/0 0/0 0/0 .text
 * getStreamInfo__11Z2SoundInfoCF10JAISoundIDP9JAIStream        */
// regalloc
#ifdef NONMATCHING
void Z2SoundInfo::getStreamInfo(JAISoundID param_1, JAIStream* param_2) const {
    int numChild;
    JAUSoundTableItem* data;
    getSoundInfo_(param_1, param_2);
    JUT_ASSERT(349, isValid());
    switch (JASGlobalInstance<JAUSoundTable>::getInstance()->getTypeID(param_1) & 0xf0) {
    case 0x70:
        int chShift;
        u32 uVar1;
        s32 iVar4;
        u16 uVar3;
        data = JASGlobalInstance<JAUSoundTable>::getInstance()->getData(param_1);
        JUT_ASSERT(356, data);
        uVar1 = data->mResourceId;
        numChild = param_2->getNumChild();
        iVar4 = 0;
        chShift = JAUStdSoundTableType::STRM_CH_SHIFT;
        for (uVar3 = uVar1; iVar4 < numChild && uVar3 != 0; uVar3 >>= chShift, iVar4++) {
            u32 uVar2 = uVar3 & 3;
            if (uVar2 != 0) {
                JAISoundChild* child = param_2->getChild(iVar4);
                if (child != NULL) {
                    switch (uVar2) {
                    case 1:
                        child->mMove.mParams.mPan = 0.5f;
                        break;
                    case 2:
                        child->mMove.mParams.mPan = 0.0f;
                        break;
                    case 3:
                        child->mMove.mParams.mPan = 1.0f;
                        break;
                    }
                }
            }
        }
    }
}
#else
void Z2SoundInfo::getStreamInfo(JAISoundID param_0, JAIStream* param_1) const {
    // NONMATCHING
}
#endif

/* 802BBA10-802BBA88 2B6350 0078+00 1/1 0/0 0/0 .text
 * getStreamFilePath__11Z2SoundInfoF10JAISoundID                */
const char* Z2SoundInfo::getStreamFilePath(JAISoundID param_1) {
    JUT_ASSERT(387, isValid());
    switch (JASGlobalInstance<JAUSoundTable>::getInstance()->getTypeID(param_1) & 0xf0) {
    case 0x70:
        JAUSoundTableItem* data = JASGlobalInstance<JAUSoundTable>::getInstance()->getData(param_1);
        JUT_ASSERT(394, data);
        const void* resource = JASGlobalInstance<JAUSoundTable>::getInstance()->getResource();
        JUT_ASSERT(398, resource);
        return JAUStdSoundTableType::StringOffset::getString(resource, data->field_0x4);
    default:
        return NULL;
        break;
    }
}

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

/* 802BBAC8-802BBB48 2B6408 0080+00 3/3 4/4 0/0 .text getSwBit__11Z2SoundInfoCF10JAISoundID */
int Z2SoundInfo::getSwBit(JAISoundID param_1) const {
    JUT_ASSERT(418, isValid());
    JAUSoundTableItem* data = JASGlobalInstance<JAUSoundTable>::getInstance()->getData(param_1);
    u8 typeID = JASGlobalInstance<JAUSoundTable>::getInstance()->getTypeID(param_1);
    if (data != NULL) {
        switch(typeID) {
        case 81:
            return data->field_0x4;
        }
    }
    return 0xffffffff;
}

/* ############################################################################################## */
/* 80455A98-80455AA0 004098 0004+04 1/1 0/0 0/0 .sdata2          @1070 */
SECTION_SDATA2 static f32 lit_1070[1 + 1 /* padding */] = {
    1.0f / 127.0f,
    /* padding */
    0.0f,
};

/* 802BBB48-802BBBE0 2B6488 0098+00 3/3 0/0 0/0 .text
 * getSoundInfo___11Z2SoundInfoCF10JAISoundIDP8JAISound         */
void Z2SoundInfo::getSoundInfo_(JAISoundID param_1, JAISound* param_2) const {
    JUT_ASSERT(440, isValid());
    JAUSoundTableItem* data = JASGlobalInstance<JAUSoundTable>::getInstance()->getData(param_1);
    u8 typeID = JASGlobalInstance<JAUSoundTable>::getInstance()->getTypeID(param_1);
    if (data != NULL && (typeID & 0x40) != 0) {
        param_2->getProperty().field_0x0 = (1.0f / 127.0f) * data->field_0x1;
    }
}


/* 802BBBE0-802BBCBC 2B6520 00DC+00 2/1 0/0 0/0 .text            __dt__11Z2SoundInfoFv */
// Z2SoundInfo::~Z2SoundInfo() {}

/* 802BBCBC-802BBCC4 2B65FC 0008+00 1/0 0/0 0/0 .text
 * @4@getBgmSeqResourceID__11Z2SoundInfoCF10JAISoundID          */
static void func_802BBCBC() {
    // NONMATCHING
}

/* 802BBCC4-802BBCCC 2B6604 0008+00 1/0 0/0 0/0 .text @4@getAudibleSw__11Z2SoundInfoCF10JAISoundID
 */
static void func_802BBCC4() {
    // NONMATCHING
}

/* 802BBCCC-802BBCD4 2B660C 0008+00 1/0 0/0 0/0 .text            @8@__dt__11Z2SoundInfoFv */
static void func_802BBCCC() {
    // NONMATCHING
}

/* 802BBCD4-802BBCDC 2B6614 0008+00 1/0 0/0 0/0 .text
 * @8@getStreamFileEntry__11Z2SoundInfoF10JAISoundID            */
static void func_802BBCD4() {
    // NONMATCHING
}