summaryrefslogtreecommitdiff
path: root/src/JSystem/JAudio/JAIStreamMgr.cpp
blob: 9912019be158646fea23ce07882fae929d831a04 (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
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
//
// Generated by dtk
// Translation Unit: JAIStreamMgr.cpp
//

#include "JSystem/JAudio/JAIStreamMgr.h"
#include "JSystem/JAudio/JAIBasic.h"
#include "JSystem/JAudio/JAIGlobalParameter.h"
#include "JSystem/JAudio/JASCallback.h"
#include "JSystem/JAudio/JASDSPChannel.h"
#include "JSystem/JAudio/JASDSPInterface.h"
#include "JSystem/JAudio/JASDvdThread.h"
#include "JSystem/JAudio/JASSystemHeap.h"
#include "JSystem/JKernel/JKRSolidHeap.h"
#include "string.h"
#include "dolphin/os/OS.h"

const u32 sChannelMax = 2;

#define JUT_ASSERT_3(LINE, COND)                                                                   \
    if (!(COND)) {                                                                                 \
        if (!(COND)) {                                                                             \
            JUTAssertion::showAssert(3, __FILE__, LINE, #COND);                                    \
            OSPanic(__FILE__, LINE, "Halt");                                                       \
        }                                                                                          \
    }

s16 JAInter::StreamLib::filter_table[32] = {
    0x0000, 0x0000, 0x0800, 0x0000, 0x0000, 0x0800, 0x0400, 0x0400,
    0x1000, -0x800, 0x0E00, -0x600, 0x0C00, -0x400, 0x1200, -0xA00,
    0x1068, -0x8C8, 0x12C0, -0x8FC, 0x1400, -0xC00, 0x0800, -0x800,
    0x0400, -0x400, -0x400, 0x0400, -0x400, 0x0000, -0x800, 0x0000,
};
s16 JAInter::StreamLib::table4[] = {
    0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
    -0x008, -0x007, -0x006, -0x005, -0x004, -0x003, -0x002, -0x001,

};
JAInter::LinkSound JAInter::StreamMgr::streamControl;
DVDFileInfo JAInter::StreamLib::finfo;
JAInter::StreamLib::StreamHeader JAInter::StreamLib::header;
char JAInter::StreamLib::Filename[100];
JASystem::Kernel::TSolidHeap JAInter::StreamLib::streamHeap;
u32 JAInter::StreamLib::LOOP_BLOCKS = 12;
int JAInter::StreamLib::LOOP_SAMPLESIZE = 0xF000;
int JAInter::StreamLib::outputmode = 1;
JAInter::StreamMgr::flags_t JAInter::StreamMgr::flags;
JAInter::streamUpdate_t* JAInter::StreamMgr::streamUpdate;
JAInter::streamList_t* JAInter::StreamMgr::streamList;
JAInter::streamList_t* JAInter::StreamMgr::initOnCodeStrm;
u32 JAInter::StreamLib::adpcm_remain;
u32 JAInter::StreamLib::adpcm_loadpoint;
u32 JAInter::StreamLib::loadsize;
s16* JAInter::StreamLib::adpcm_buffer;
s16*** JAInter::StreamLib::loop_buffer;
void** JAInter::StreamLib::store_buffer;
JASystem::TDSPChannel* JAInter::StreamLib::assign_ch[2];
u32 JAInter::StreamLib::playside;
int JAInter::StreamLib::playback_samples;
int JAInter::StreamLib::loadup_samples;
u32 JAInter::StreamLib::adpcmbuf_state;
u32 JAInter::StreamLib::movieframe;
bool JAInter::StreamLib::stopflag;
bool JAInter::StreamLib::stopflag2;
u8 JAInter::StreamLib::playflag;
u8 JAInter::StreamLib::playflag2;
u8 JAInter::StreamLib::prepareflag;
u8 JAInter::StreamLib::dspch_deallockflag;
f32 JAInter::StreamLib::outvolume;
f32 JAInter::StreamLib::outpitch;
f32 JAInter::StreamLib::outpan;
f32 JAInter::StreamLib::stackvolume;
f32 JAInter::StreamLib::stackpitch;
f32 JAInter::StreamLib::stackpan;
u8 JAInter::StreamLib::outflag_volume;
bool JAInter::StreamLib::outflag_pan;
bool JAInter::StreamLib::outflag_pitch;
int JAInter::StreamLib::loop_start_flag;
int JAInter::StreamLib::outpause;
int JAInter::StreamLib::playmode;
int JAInter::StreamLib::shift_sample;
int JAInter::StreamLib::extra_sample;
int JAInter::StreamLib::DvdLoadFlag;
u32 JAInter::StreamLib::startInitFlag;
int JAInter::StreamLib::Mode;
int JAInter::StreamLib::sFillBlockSize;
void* JAInter::StreamLib::Head;
bool JAInter::StreamLib::bufferMode;
u8 JAInter::StreamLib::allocFlag;
u8 JAInter::StreamLib::dspFinishFlag;
void (*JAInter::StreamLib::allocCallback)();
void (*JAInter::StreamLib::deallocCallback)();

/* 8029B9A4-8029BEB4       .text init__Q27JAInter9StreamMgrFv */
void JAInter::StreamMgr::init() {
    flags.flag1 = false;
    flags.flag2 = false;
    flags.flag3 = false;
    JAISound* soundObjects = JAIBasic::getInterface()->makeSound(JAIGlobalParameter::getParamStreamControlBufferMax());
    JUT_ASSERT_MSG(46, soundObjects, "JAIStreamMgr::initHeap Cannot Alloc Heap!!\n");
    streamControl.init(soundObjects, JAIGlobalParameter::getParamStreamControlBufferMax());
    for (int i = 0; i < JAIGlobalParameter::getParamStreamParameterBufferMax(); i++) {
        StreamParameter* _para = new (JAIBasic::getCurrentJAIHeap(), 32) StreamParameter();
        JUT_ASSERT_MSG(52, _para, "JAIStreamMgr::initHeap Cannot Alloc Heap!!\n");
        _para->pan = new (JAIBasic::getCurrentJAIHeap(), 32) MoveParaSet[JAIGlobalParameter::getParamStreamParameterLines()];
        JUT_ASSERT_MSG(54, _para->pan, "JAIStreamMgr::initHeap Cannot Alloc Heap!!\n");
        _para->pitch = new (JAIBasic::getCurrentJAIHeap(), 32) MoveParaSet[JAIGlobalParameter::getParamStreamParameterLines()];
        JUT_ASSERT_MSG(56, _para->pitch, "JAIStreamMgr::initHeap Cannot Alloc Heap!!\n");
        streamControl.Buffer[i].field_0x3c = _para;
    }
    streamUpdate = new (JAIBasic::getCurrentJAIHeap(), 32) streamUpdate_t();
    JUT_ASSERT_MSG(61, streamUpdate, "JAIStreamMgr::initHeap Cannot Alloc Heap!!\n");
    streamUpdate_t* tmp = streamUpdate;
    tmp->field_0x0 = 0;
    tmp->field_0x1 = 0;
    tmp->field_0x4 = 1.0f;
    tmp->field_0x8 = 1.0f;
    tmp->field_0xc = 0.5f;
    tmp->mActiveTrackFlag = SOUNDACTIVE_Unk0;
    tmp->mpSound = NULL;
}

/* 8029BEB4-8029C04C       .text storeStreamBuffer__Q27JAInter9StreamMgrFPP8JAISoundPQ27JAInter5ActorUlUlUcPv */
void JAInter::StreamMgr::storeStreamBuffer(JAISound** param_1, JAInter::Actor* param_2, u32 param_3, u32 param_4, u8 param_5, void* param_6) {
    /* Nonmatching */
    if (param_1 && param_1[0] && param_1[0]->checkSoundHandle(param_3, param_6)) {
        return;
    }
    if (streamControl.field_0x4) {
        releaseStreamBuffer(streamControl.field_0x4, 0);
    }
    JAISound* sound = streamControl.getSound();
    StreamParameter* para = sound->getStreamParameter();
    para->mPauseMode = 0;
    para->field_0x4 = 0;
    para->mVolumeFlags = 0;
    para->mPitchFlags = 0;
    para->mPanFlags = 0;
    for (u32 i = 0; i < 20; i++) {
        MoveParaSet* movePara = &para->mVolumes[i];
        movePara->init(1.0f);
    }
    for (u32 i = 0; i < JAIGlobalParameter::getParamStreamParameterLines(); i++) {
        para->pitch[i].init(1.0f);
        para->pan[i].init(0.5f);
    }
    sound->mState = SOUNDSTATE_Stored;
    sound->field_0x6 = 10;
    streamUpdate->field_0x2 = 0;
    sound->initParameter(param_1, param_2, param_3, param_4, param_5, param_6);
}

/* 8029C04C-8029C0F0       .text releaseStreamBuffer__Q27JAInter9StreamMgrFP8JAISoundUl */
void JAInter::StreamMgr::releaseStreamBuffer(JAISound* param_1, u32 param_2) {
    if (param_2 == 0 || param_1->mState < SOUNDSTATE_Playing) {
        StreamLib::stop();
        param_1->mState = SOUNDSTATE_Inactive;
        streamUpdate->mpSound = NULL;
        param_1->clearMainSoundPPointer();
        streamControl.releaseSound(param_1);
        JASystem::Dvd::unpauseDvdT();
    } else {
        if (param_1->getStreamParameter()->mUpdateData) {
            param_1->getStreamParameter()->mUpdateData->mActiveTrackFlag |= SOUNDACTIVE_DoFadeout;
            param_1->mFadeCounter = param_2;
        }
    }
}

/* 8029C0F0-8029C128       .text processGFrameStream__Q27JAInter9StreamMgrFv */
void JAInter::StreamMgr::processGFrameStream() {
    if (!flags.flag2) {
        checkPlayingStream();
        checkRequestStream();
        checkWaitStream();
        checkEntriedStream();
    }
}

/* 8029C128-8029C1D8       .text checkEntriedStream__Q27JAInter9StreamMgrFv */
void JAInter::StreamMgr::checkEntriedStream() {
    for (JAISound* sound = streamControl.field_0x4; sound; sound = sound->field_0x34) {
        if (sound->mState != SOUNDSTATE_Stored || StreamLib::getPlayingFlag() == 1) {
            continue;
        }
        sound->mState = SOUNDSTATE_Loaded;
        sound->getStreamParameter()->mUpdateData = streamUpdate;
        streamUpdate_t* tmp = streamUpdate;
        tmp->field_0x0 = 0;
        tmp->field_0x1 = 0;
        tmp->field_0x4 = 1.0f;
        tmp->field_0x8 = 1.0f;
        tmp->field_0xc = 0.5f;
        tmp->mActiveTrackFlag = SOUNDACTIVE_Unk0;
        tmp->mpSound = NULL;
        streamUpdate->mpSound = sound;
    }
}

/* 8029C1D8-8029C2AC       .text checkWaitStream__Q27JAInter9StreamMgrFv */
void JAInter::StreamMgr::checkWaitStream() {
    JAISound* sound = streamUpdate->mpSound;
    if (!sound) {
        return;
    }
    if (sound->mState != SOUNDSTATE_Loaded) {
        return;
    }
    char buffer[64];
    strcpy(buffer, JAIGlobalParameter::getParamStreamPath());
    strcat(buffer, streamList[JAIBasic::getInterface()->getSoundOffsetNumberFromID(sound->getID())].field_0x10);
    JAIBasic::getInterface()->setSeExtParameter(sound);
    sound->mState = SOUNDSTATE_Ready;
    checkPlayingStream();
    StreamLib::start(buffer, sound->getStreamParameter()->field_0x4, streamList[sound->getID() & 0x3FF].field_0x20);
    StreamLib::setPrepareFlag(1);
}

/* 8029C2AC-8029C344       .text checkRequestStream__Q27JAInter9StreamMgrFv */
void JAInter::StreamMgr::checkRequestStream() {
    JAISound* sound = streamUpdate->mpSound;
    if (!sound) {
        return;
    }
    if (sound->mState != SOUNDSTATE_Ready) {
        return;
    }
    if (streamUpdate->field_0x2) {
        return;
    }
    sound->mState = SOUNDSTATE_Playing;
    if (sound->mFadeCounter > 1) {
        sound->setStreamInterVolume(SOUNDPARAM_Fadeout, 0.0, 0);
        sound->setStreamInterVolume(SOUNDPARAM_Fadeout, 1.0, sound->mFadeCounter);
        StreamLib::setVolume(0.0);
    }
    StreamLib::setPrepareFlag(0);
}

/* 8029C344-8029C730       .text checkPlayingStream__Q27JAInter9StreamMgrFv */
void JAInter::StreamMgr::checkPlayingStream() {
    JAISound* streamSound = getUpdateInfo()->mpSound;
    if (streamSound == NULL) {
        return;
    }

    streamUpdate_t* data = getUpdateInfo();
    if (streamSound->mState >= SOUNDSTATE_Playing) {
        streamSound->getStreamParameter();
        if (StreamLib::getPlayingFlag() == 2) {
            streamSound->mState = SOUNDSTATE_Inactive;
            if (streamSound->getStreamParameter()->mUpdateData) {
                streamSound->getStreamParameter()->mUpdateData->mpSound = NULL;
            }
            streamSound->clearMainSoundPPointer();
            streamControl.releaseSound(streamSound);
            return;
        }

        if (streamSound->field_0x6 != 0) {
            streamSound->field_0x6--;
        }

        if ((data->mActiveTrackFlag & SOUNDACTIVE_DoFadeout) != 0) {
            streamSound->setStreamInterVolume(SOUNDPARAM_Fadeout, 0.0f, streamSound->mFadeCounter);
            streamSound->mState = SOUNDSTATE_Fadeout;
            data->mActiveTrackFlag ^= SOUNDACTIVE_DoFadeout;
        }
        
        if (streamSound->mState == SOUNDSTATE_Fadeout &&
            (streamSound->getStreamInterVolume(SOUNDPARAM_Fadeout) == 0.0f || streamSound->mFadeCounter == 0) &&
            streamSound->field_0x6 == 0
        ) {
            StreamLib::stop();
            streamSound->mState = SOUNDSTATE_Inactive;
            if (streamSound->getStreamParameter()->mUpdateData != NULL) {
                streamSound->getStreamParameter()->mUpdateData->mpSound = NULL;
            }
            streamSound->clearMainSoundPPointer();
            streamControl.releaseSound(streamSound);
        }
    }
    if (streamSound->mState < SOUNDSTATE_Ready) {
        return;
    }

    StreamParameter* param = streamSound->getStreamParameter();
    if (data->mActiveTrackFlag & SOUNDACTIVE_Volume) {
        f32 volFactor = 1.0f;
        for (u8 i = 0; i < 20; i++) {
            MoveParaSet* vol = &param->mVolumes[i];
            if (param->mVolumeFlags & (1 << i)) {
                if (vol->move() == FALSE) {
                    param->mVolumeFlags ^= (1 << i);
                }
            }

            volFactor *= vol->mCurrentValue;
        }

        if (streamUpdate->field_0x4 != volFactor) {
            StreamLib::setVolume(volFactor);
            streamUpdate->field_0x4 = volFactor;
        }

        if (param->mVolumeFlags == 0) {
            data->mActiveTrackFlag ^= SOUNDACTIVE_Volume;
        }
    }

    if (data->mActiveTrackFlag & SOUNDACTIVE_Pitch) {
        f32 pitchFactor = 1.0f;
        for (u8 i = 0; i < 7; i++) {
            MoveParaSet* pitch = &param->pitch[i];
            if (param->mPitchFlags & (1 << i)) {
                if (pitch->move() == FALSE) {
                    param->mPitchFlags ^= (1 << i);
                }
            }

            pitchFactor *= pitch->mCurrentValue;
        }

        if (streamUpdate->field_0x8 != pitchFactor) {
            StreamLib::setPitch(pitchFactor);
            streamUpdate->field_0x8 = pitchFactor;
        }

        if (param->mPitchFlags == 0) {
            data->mActiveTrackFlag ^= SOUNDACTIVE_Pitch;
        }
    }

    if (data->mActiveTrackFlag & SOUNDACTIVE_Pan) {
        f32 panFactor = 0.0f;
        for (u8 i = 0; i < 7; i++) {
            MoveParaSet* pan = &param->pan[i];
            if (param->mPanFlags & (1 << i)) {
                if (pan->move() == FALSE) {
                    param->mPanFlags ^= (1 << i);
                }
            }

            panFactor += (pan->mCurrentValue - 0.5f);
        }

        panFactor += 0.5f;
        if (panFactor > 1.0f) {
            panFactor = 1.0f;
        } else if (panFactor < 0.0f) {
            panFactor = 0.0f;
        }

        if (streamUpdate->field_0xc != panFactor) {
            StreamLib::setPan(panFactor);
            getUpdateInfo()->field_0xc = panFactor;
        }

        if (param->mPanFlags == 0) {
            data->mActiveTrackFlag ^= SOUNDACTIVE_Pan;
        }
    }

    streamSound->field_0x18++;
}

/* 8029C730-8029C858       .text Play_DirectPCM__Q27JAInter9StreamLibFPQ28JASystem11TDSPChannelPsUsUlsUs */
void JAInter::StreamLib::Play_DirectPCM(JASystem::TDSPChannel* param_1, s16* param_2, u16 param_3, u32 param_4, s16 param_5, u16 param_6) {
    JASystem::DSPInterface::DSPBuffer* buffer = JASystem::DSPInterface::getDSPHandle(param_1->mNumber);
    buffer->field_0x118 = (u32)param_2;
    buffer->field_0x102 = 0;
    buffer->field_0x100 = 33;
    if (JAInter::StreamLib::header.field_0x10 != 0) {
        buffer->field_0x74 = -1;
    } else {
        buffer->field_0x74 = param_4;
    }
    buffer->field_0x110 = (u32)param_2;
    buffer->field_0x114 = param_3 << 16;
    JASystem::DSPInterface::getDSPHandle(param_1->mNumber)->setMixerInitDelayMax(0);
    for (u8 i = 0; i < 6; i++) {
        if (i < 2) {
            JASystem::DSPInterface::getDSPHandle(param_1->mNumber)->setMixerInitVolume(i, param_5, 0);
        } else {
            JASystem::DSPInterface::getDSPHandle(param_1->mNumber)->setMixerInitVolume(i, 0, 0);
        }
        JASystem::DSPInterface::getDSPHandle(param_1->mNumber)->setBusConnect(i, i + 1);
    }
    JASystem::DSPInterface::getDSPHandle(param_1->mNumber)->setPitch(param_6);
    param_1->play();
}

/* 8029C858-8029C864       .text Get_DirectPCM_LoopRemain__Q27JAInter9StreamLibFPQ38JASystem12DSPInterface9DSPBuffer */
int JAInter::StreamLib::Get_DirectPCM_LoopRemain(JASystem::DSPInterface::DSPBuffer* dspBuffer) {
    return dspBuffer->field_0x6c >> 0x10;
}

/* 8029C864-8029C86C       .text Get_DirectPCM_Remain__Q27JAInter9StreamLibFPQ38JASystem12DSPInterface9DSPBuffer */
int JAInter::StreamLib::Get_DirectPCM_Remain(JASystem::DSPInterface::DSPBuffer* dspBuffer) {
    return dspBuffer->field_0x74;
}

/* 8029C86C-8029C8BC       .text init__Q27JAInter9StreamLibFb */
void JAInter::StreamLib::init(bool param_1) {
    bufferMode = param_1;
    if (!param_1) {
        u32 size = getNeedBufferSize();
        allocBuffer(JASDram->alloc(size, 0), size);
    }
}

/* 8029C8BC-8029CBF0       .text allocBuffer__Q27JAInter9StreamLibFPvl */
void JAInter::StreamLib::allocBuffer(void* param_1, s32 param_2) {
    if (allocFlag) {
        return;
    }
    streamHeap.init((u8*)param_1, param_2);
    loop_buffer = (s16***)streamHeap.alloc(8);
    JUT_ASSERT_3(555, loop_buffer);
    for (u32 i = 0; i < 2; i++) {
        loop_buffer[i] = (s16**)streamHeap.alloc(LOOP_BLOCKS << 2);
        JUT_ASSERT_3(559, loop_buffer[i]);
        for (int j = 0; j < LOOP_BLOCKS; j++) {
            loop_buffer[i][j] = (s16*)streamHeap.alloc(0x2800);
            JUT_ASSERT_3(563, loop_buffer[i][j]);
        }
    };
    store_buffer = (void**)streamHeap.alloc(8);
    JUT_ASSERT_3(568, store_buffer);
    for (u32 i = 0; i < 2; i++) {
        store_buffer[i] = streamHeap.alloc(0x5000);
        JUT_ASSERT_3(572, store_buffer[i]);
    }
    JUT_ASSERT_3(575, loop_buffer);
    adpcm_buffer = (s16*)streamHeap.alloc(0x5000);
    JUT_ASSERT_3(577, adpcm_buffer);
    allocFlag = true;
}

/* 8029CBF0-8029CC50       .text deallocBuffer__Q27JAInter9StreamLibFv */
bool JAInter::StreamLib::deallocBuffer() {
    if (bufferMode && allocFlag && playflag2 != 1) {
        streamHeap.freeAll();
        allocFlag = 0;
        return true;
    }
    return false;
}

/* 8029CC50-8029CCA4       .text getNeedBufferSize__Q27JAInter9StreamLibFv */
u32 JAInter::StreamLib::getNeedBufferSize() {
    /* Nonmatching - regalloc */
    u32 i = 0;
    u32 size;
    u32 r0 = ((LOOP_BLOCKS << 2) & ~0x1F) + 0x20;
    for (size = 0x20; i < 2; i++) {
        size += r0;
        for (u32 j = 0; j < LOOP_BLOCKS; j++) {
            size += 0x2820;
        }
    }
    size += 0x20;
    for (u32 i = 0; i < 2; i++) {
        size += 0x5020;
    }
    size += 0x5020;
    return size;
}

/* 8029CCA4-8029CCAC       .text setAllocBufferCallback__Q27JAInter9StreamLibFPFv_v */
void JAInter::StreamLib::setAllocBufferCallback(void (*param_1)(void)) {
    allocCallback = param_1;
}

/* 8029CCAC-8029CCB4       .text setDeallocBufferCallback__Q27JAInter9StreamLibFPFv_v */
void JAInter::StreamLib::setDeallocBufferCallback(void (*param_1)(void)) {
    deallocCallback = param_1;
}

/* 8029CCB4-8029CCD0       .text sync__Q27JAInter9StreamLibFl */
void JAInter::StreamLib::sync(s32 param_1) {
    static s32 before = param_1;
    before = param_1;
}

/* 8029CCD0-8029CD8C       .text __DecodePCM__Q27JAInter9StreamLibFv */
void JAInter::StreamLib::__DecodePCM() {
    /* Nonmatching */
    int i;
    s16* dst1 = loop_buffer[0][playside];
    s16* dst2 = loop_buffer[1][playside];
    s16* src = adpcm_buffer;
    for (i = 0; i < loadsize >> 2; dst2++, i++, dst1++, src += 2) {
        dst1[0] = src[0];
        dst2[0] = src[1];
    }
    loadup_samples += loadsize >> 2;
    DCStoreRange(loop_buffer[0][playside], loadsize >> 1);
    DCStoreRange(loop_buffer[1][playside], loadsize >> 1);
}

/* 8029CD8C-8029D134       .text __DecodeADPCM__Q27JAInter9StreamLibFv */
void JAInter::StreamLib::__DecodeADPCM() {
    /* Nonmatching */
}

/* 8029D134-8029D1C8       .text __Decode__Q27JAInter9StreamLibFv */
void JAInter::StreamLib::__Decode() {
    switch (header.field_0xa) {
    case 2:
        __DecodePCM();
        return;
    case 4:
        __DecodeADPCM();
        return;
    }
    JUT_ASSERT_3(948, 0);
}

/* 8029D1C8-8029D1E8       .text __LoadFin__Q27JAInter9StreamLibFlP11DVDFileInfo */
void JAInter::StreamLib::__LoadFin(s32, DVDFileInfo*) {
    DvdLoadFlag = 0;
    if (adpcmbuf_state == 3) {
        return;
    }
    adpcmbuf_state = 2;
}

/* 8029D1E8-8029D328       .text LoadADPCM__Q27JAInter9StreamLibFv */
void JAInter::StreamLib::LoadADPCM() {
    /* Nonmatching */
}

/* 8029D328-8029D338       .text setVolume__Q27JAInter9StreamLibFf */
void JAInter::StreamLib::setVolume(f32 param_1) {
    stackvolume = param_1;
    outflag_volume = true;
}

/* 8029D338-8029D348       .text setPitch__Q27JAInter9StreamLibFf */
void JAInter::StreamLib::setPitch(f32 param_1) {
    stackpitch = param_1;
    outflag_pitch = true;
}

/* 8029D348-8029D358       .text setPan__Q27JAInter9StreamLibFf */
void JAInter::StreamLib::setPan(f32 param_1) {
    stackpan = param_1;
    outflag_pan = true;
}

/* 8029D358-8029D368       .text stop__Q27JAInter9StreamLibFv */
void JAInter::StreamLib::stop() {
    stopflag = true;
    stopflag2 = true;
}

/* 8029D368-8029D384       .text setPauseFlag__Q27JAInter9StreamLibFUc */
void JAInter::StreamLib::setPauseFlag(u8 param_1) {
    outpause |= param_1;
    outpause |= 0x80;
}

/* 8029D384-8029D3A4       .text clearPauseFlag__Q27JAInter9StreamLibFUc */
void JAInter::StreamLib::clearPauseFlag(u8 param_1) {
    outpause &= (param_1 ^ 0xff);
    outpause |= 0x80;
}

/* 8029D3A4-8029D3AC       .text setPrepareFlag__Q27JAInter9StreamLibFUc */
void JAInter::StreamLib::setPrepareFlag(u8 param_1) {
    prepareflag = param_1;
}

/* 8029D3AC-8029D3B4       .text setOutputMode__Q27JAInter9StreamLibFUl */
void JAInter::StreamLib::setOutputMode(u32 param_1) {
    outputmode = param_1;
}

/* 8029D3B4-8029D3BC       .text getPlayingFlag__Q27JAInter9StreamLibFv */
u8 JAInter::StreamLib::getPlayingFlag() {
    return playflag2;
}

/* 8029D3BC-8029D424       .text setDecodedBufferBlocks__Q27JAInter9StreamLibFUl */
void JAInter::StreamLib::setDecodedBufferBlocks(u32 param_1) {
    /* Nonmatching */
    if (param_1 < 3) {
        OSReport("setDecodedBufferBlocks : 3ブロック以上必要ですので、使用ブロックを%dから3に変更します。\n");
        param_1 = 3;
    } else if (param_1 > 12) {
        OSReport("setDecodedBufferBlocks : 13ブロック以上は設定できませんので、使用ブロックを%dから12に変更しま す。\n");
        param_1 = 12;
    }
    LOOP_BLOCKS = param_1;
}

/* 8029D424-8029D464       .text LoopInit__Q27JAInter9StreamLibFv */
void JAInter::StreamLib::LoopInit() {
    loop_start_flag = true;
    u32 var1 = (header.field_0x14 - (header.field_0x14 & 0x7F) >> 4) * 18 + 32;
    adpcm_loadpoint = var1;
    var1 -= 32;
    adpcm_remain = header.field_0x0 - var1;
}

/* 8029D464-8029D4C0       .text directPlayWait__Q27JAInter9StreamLibFPv */
s32 JAInter::StreamLib::directPlayWait(void*) {
    if (getPlayingFlag() != 1) {
        startInitFlag++;
        prepareflag = 0;
        JASystem::Kernel::registerDspCallback(callBack, NULL);
        return -1;
    }
    return 0;
}

/* 8029D4C0-8029D560       .text start__Q27JAInter9StreamLibFPcUlPv */
void JAInter::StreamLib::start(char* param_1, u32 param_2, void* param_3) {
    /* Nonmatching */
    if (!startInitFlag) {
        strcpy(Filename, param_1);
        Mode = param_2;
        Head = param_3;
        if (!param_3) {
            stop();
            JASystem::Kernel::registerDspCallback(directPlayWait, NULL);
        } else {
            startInitFlag++;
            prepareflag = 0;
            JASystem::Kernel::registerDspCallback(callBack, NULL);
        }
    }

}

/* 8029D560-8029D7C0       .text __start__Q27JAInter9StreamLibFv */
void JAInter::StreamLib::__start() {
    /* Nonmatching */
}

/* 8029D7C0-8029E14C       .text callBack__Q27JAInter9StreamLibFPv */
s32 JAInter::StreamLib::callBack(void*) {
    /* Nonmatching */
}