Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
28910_len_5090.c
Go to the documentation of this file.
1#include "audio.h"
2
4
6extern u8 BgmDivisors[8];
7extern u8 D_80078558[40];
8
9extern void (*SefCmdHandlers[])(SoundManager*, SoundPlayer*);
10extern void (*SeqCmdHandlers[])(BGMPlayer*, BGMPlayerTrack*);
11extern u8 SeqCmdArgCounts[];
12
13static void au_bgm_stop_player(BGMPlayer* player);
14
15static s32 snd_bpm_to_tempo(BGMPlayer* player, u32 tempo);
16
17static u8 au_bgm_get_random_pan(BGMPlayer* player, u8 arg1, u8 arg2);
18static s16 au_bgm_get_random_pitch(s32 arg0, s32 arg1, u8 arg2);
19static u8 au_bgm_get_random_vol(s32 arg0, u8 volume, u8 arg2);
20static u8 au_bgm_get_random_reverb(s32 arg0, u8 arg1, u8 arg2);
21
23 BGMHeader* bgmFile;
24 BGMFileInfo* bgmData;
25 s32 unkType;
26 u32 segmentID;
27 s32 segmentOffset;
28 u32 value;
29 s32 delta;
30 u8 var_a1;
31 u8 pos;
32 u32 i;
33
34 segmentID = 0;
35 unkType = -1;
36 player->updateCounter++;
37
38 if (player->unk_258 != 0) {
39 if (player->unk_258 < ARRAY_COUNT(player->unk_238)) {
40 pos = player->unk_259;
41 for (var_a1 = 0; var_a1 < player->unk_258; var_a1++) {
42 value = player->unk_238[pos];
43 if (value != 0) {
44 if (value < 16) {
45 unkType = value & 3;
46 segmentID = value >> 2;
47 }
48 pos++;
49 if (pos >= ARRAY_COUNT(player->unk_238)) {
50 pos = 0;
51 }
52 }
53 }
54 delta = player->unk_25A - player->unk_259;
55 if (delta < 0) {
56 delta += ARRAY_COUNT(player->unk_238);
57 }
58 player->unk_258 -= delta;
59 player->unk_259 = player->unk_25A;
60 } else {
61 player->unk_258 = 0;
62 }
63 if (unkType != -1) {
64 if (unkType != 0) {
65 if (unkType != player->unk_58) {
66 player->unk_58 = unkType & 0xFF;
67 player->unk_5A = unkType & 0xFF;
70 if (unkType == 2) {
71 bgmFile = player->globals->dataBGM[1];
72 } else {
73 bgmFile = player->globals->dataBGM[0];
74 }
75 player->bgmFile = bgmFile;
76 bgmData = &bgmFile->info;
77 func_8004E880(player, BGM_SAMPLE_RATE, BgmDivisors[((u8*)player->unk_74)[0] & 7]); //TODO revise unk_74 typing
78
79 segmentOffset = bgmData->segments[segmentID];
80 if (segmentOffset == 0) {
81 segmentOffset = bgmData->segments[0];
82 }
83 player->segmentStartPos = AU_FILE_RELATIVE(bgmFile, segmentOffset << 2);
84 player->segmentReadPos = AU_FILE_RELATIVE(bgmFile, segmentOffset << 2);
85
86 if (bgmData->drums != 0) {
87 player->drumsInfo = AU_FILE_RELATIVE(player->bgmFile, bgmData->drums << 2);
88 player->bgmDrumCount = bgmData->drumCount;
89 for (i = 0; i < player->bgmDrumCount; i++) {
90 BGMDrumInfo* drum = &player->drumsInfo[i];
91 player->drums[i] = drum;
92 }
93 for (; i < ARRAY_COUNT(player->drums); i++) {
94 player->drums[i] = player->drums[0];
95 }
96 } else {
97 player->drumsInfo = NULL;
98 player->bgmDrumCount = 0;
99 }
100
101 if (bgmData->instruments != 0) {
102 player->instrumentsInfo = AU_FILE_RELATIVE(player->bgmFile, bgmData->instruments << 2);
103 player->bgmInstrumentCount = bgmData->instrumentCount;
104 return;
105 }
106 player->instrumentsInfo = NULL;
107 player->bgmInstrumentCount = 0;
108 }
109 } else {
110 if (player->unk_58 != 0) {
112 player->nextUpdateCounter = 1;
113 player->nextUpdateStep = 1;
114 } else {
115 au_bgm_stop_player(player);
116 }
117 }
118 }
119 }
120}
121
123 if (songString != gBGMPlayerA->globals->dataBGM[0]->name) {
124 if (songString == gBGMPlayerA->globals->dataBGM[1]->name) {
125 return gBGMPlayerB;
126 }
127 } else {
128 return gBGMPlayerA;
129 }
130 return NULL;
131}
132
134 BGMPlayer* player;
135 BGMFileInfo* fileInfo;
136 s32 songName;
137 s32 variation;
138 s32 duration;
139 s32 volume0;
140 s32 volume1;
141 AuResult status;
142 u32 i;
143
144 status = AU_RESULT_OK;
145 songName = event->songName;
146 variation = event->variation;
147 if (songName != 0) {
148 player = au_bgm_get_player_with_song_name(songName);
149 if (player != NULL) {
150 fileInfo = &player->bgmFile->info;
151 duration = event->duration;
152 if (duration != 0) {
153 if (duration > SND_MAX_DURATION) {
154 duration = SND_MAX_DURATION;
155 } else if (duration < SND_MIN_DURATION) {
156 duration = SND_MIN_DURATION;
157 }
158 }
159 volume0 = event->startVolume;
160 if (volume0 > 0x7F) {
161 volume0 = 0x7F;
162 }
163 if (volume0 != 0) {
164 volume0 = (volume0 << 8) | 0xFF;
165 }
166 volume1 = event->finalVolume;
167 if (volume1 > 0x7F) {
168 volume1 = 0x7F;
169 }
170 if (volume1 != 0) {
171 volume1 = (volume1 << 8) | 0xFF;
172 } else {
173 volume1 = 0x7FFF;
174 }
175
176 au_fade_init(&player->fadeInfo, duration, volume0, volume1);
177 player->fadeInfo.targetVolScale = 0x7FFF;
178 player->fadeInfo.volScaleTime = 1;
179 func_8004E880(player, BGM_SAMPLE_RATE, BgmDivisors[fileInfo->numSegments & 7]);
180
181 if (variation < 0 || variation >= 4 || fileInfo->segments[variation] == 0) {
182 variation = 0;
183 }
184 player->curSegmentID = variation;
185
186 player->segmentStartPos = AU_FILE_RELATIVE(player->bgmFile, fileInfo->segments[variation] << 2);
187 player->segmentReadPos = player->segmentStartPos;
188
189 if (fileInfo->drums != 0) {
190 player->drumsInfo = AU_FILE_RELATIVE(player->bgmFile, fileInfo->drums << 2);
191 player->bgmDrumCount = fileInfo->drumCount;
192
193 for (i = 0; i < player->bgmDrumCount; i++) {
194 BGMDrumInfo* drum = &player->drumsInfo[i];
195 player->drums[i] = drum;
196 }
197 for (; i < ARRAY_COUNT(player->drums); i++) {
198 player->drums[i] = player->drums[0];
199 }
200 } else {
201 player->drumsInfo = NULL;
202 player->bgmDrumCount = 0;
203 }
204 if (fileInfo->instruments != 0) {
205 player->instrumentsInfo = AU_FILE_RELATIVE(player->bgmFile, fileInfo->instruments << 2);
206 player->bgmInstrumentCount = fileInfo->instrumentCount;
207 } else {
208 player->instrumentsInfo = NULL;
209 player->bgmInstrumentCount = 0;
210 }
211 player->songName = songName;
213 } else {
215 }
216 } else {
218 }
219 return status;
220}
221
223 BGMPlayer* player;
224 AuResult status = AU_RESULT_OK;
225
226 if (songName != 0) {
227 player = au_bgm_get_player_with_song_name(songName);
228 if (player != NULL) {
229 if (songName == player->songName) {
230 au_bgm_stop_player(player);
231 }
232 } else {
234 }
235 } else {
237 }
238
239 return status;
240}
241
242void au_bgm_stop_all(void) {
243 au_bgm_stop_player(gBGMPlayerA);
244 au_bgm_stop_player(gBGMPlayerB);
245}
246
247static void au_bgm_stop_player(BGMPlayer* player) {
248 if (player->masterState != BGM_PLAY_STATE_IDLE) {
250 player->nextUpdateCounter = 1;
251 player->nextUpdateStep = 1;
252 au_fade_clear(&player->fadeInfo);
253 }
254}
255
257 BGMPlayer* player;
258 AuResult result = AU_RESULT_OK;
259
260 if (songName != 0) {
261 player = au_bgm_get_player_with_song_name(songName);
262 if (player != NULL) {
263 result = (songName == player->songName);
264 } else {
266 }
267 } else {
269 }
270
271 return result;
272}
273
275 if (player->songName != NULL && player->masterState != 0) {
276 return 1;
277 } else {
278 return 0;
279 }
280}
281
283 AuResult status;
284 BGMPlayer* player;
285 u32 songName = s->songName;
286 u32 duration = s->duration;
287 s16 volume = s->finalVolume;
288
289 status = AU_RESULT_OK;
290 if (songName != 0) {
291 if (duration >= SND_MIN_DURATION && duration <= SND_MAX_DURATION) {
292 player = au_bgm_get_player_with_song_name(songName);
293 if (player != NULL) {
294 if (player->songName == songName) {
295 if (player->masterState != BGM_PLAY_STATE_IDLE) {
296 if (player->unk_220 == 0) {
297 player->fadeInfo.targetVolume = volume;
298 player->fadeInfo.fadeTime = (duration * 1000) / AU_5750;
299 player->fadeInfo.fadeStep = ((volume << 0x10) - player->fadeInfo.curVolume.s32) / player->fadeInfo.fadeTime;
300 player->fadeInfo.variation = s->variation;
301 if (s->unk14 == 1) {
302 player->fadeSongName = songName;
303 }
304 }
305 }
306 }
307 } else {
309 }
310 } else {
312 }
313 } else {
315 }
316 return status;
317}
318
319AuResult func_8004DC80(s32 songName) {
321
322 s.songName = songName;
323 s.duration = 0;
324 s.startVolume = 0;
325 s.finalVolume = 0;
326 s.variation = 0;
327 s.unk14 = 0;
328 return func_8004DCB8(&s, 0);
329}
330
332 AuResult status;
333 BGMPlayer* playerA;
334 BGMPlayer* playerB;
335 s32 songName;
336 s32 variation;
337 u32 i;
338 u32 j;
339
340 songName = update->songName;
341 variation = update->variation;
342 status = AU_RESULT_OK;
343
344 if (songName != 0) {
345 playerA = au_bgm_get_player_with_song_name(songName);
346 if (playerA != NULL) {
347 if (update->unk14 == 0) {
348 playerB = func_80053F64(variation);
349 if (playerB != NULL) {
350 if (songName == playerA->songName) {
351 if (!clearChanged) {
352 for (i = 0; i < ARRAY_COUNT(playerA->tracks); i++) {
353 BGMPlayerTrack* track = &playerA->tracks[i];
354 if (track->bgmReadPos != 0) {
355 for (j = track->unk_52; j < track->unk_53; j++) {
356 track->changed.all = 0;
357 }
358 }
359 }
360 }
361 playerA->globals->unk_globals_6C[variation].unk_5 = playerA->priority;
362 playerA->globals->unk_globals_6C[variation].unk_4 = 1;
363 playerA->fadeSongName = 0;
364 au_copy_words(playerA, playerB, sizeof(*playerA));
365 if (clearChanged == 0) {
366 au_bgm_stop_player(playerA);
367 }
368 }
369 } else {
371 }
372 } else {
373 if (songName == playerA->songName) {
374 if (playerA->masterState != BGM_PLAY_STATE_IDLE) {
375 playerA->unk_220 = 1;
376 func_80050900(playerA);
377 }
378 }
379 }
380 } else {
382 }
383 } else {
385 }
386 return status;
387}
388
390 AuResult status;
391 BGMPlayer* playerA;
392 BGMPlayer* playerB;
393 s32 variation;
394 s32 songName;
395 s32 volume0;
396 s32 volume1;
397 s32 duration;
398
399 songName = update->songName;
400 variation = update->variation;
401 status = AU_RESULT_OK;
402
403 if (songName != 0) {
404 if (update->unk14 == 0) {
405 playerA = func_80053F64(variation);
406 if (playerA != NULL && playerA->globals->unk_globals_6C[variation].unk_4 == 1) {
407 playerB = func_80054248(playerA->globals->unk_globals_6C[variation].unk_5);
408 if (playerB != NULL) {
409 if (func_8004DB28(playerB) == 0) {
410 status = func_80053E58(playerA->songID, playerA->bgmFile);
411 duration = update->duration;
412 if (duration != 0) {
413 if (duration > SND_MAX_DURATION) {
414 duration = SND_MAX_DURATION;
415 } else if (duration < SND_MIN_DURATION) {
416 duration = SND_MIN_DURATION;
417 }
418 }
419 volume0 = update->startVolume;
420 if (volume0 > BGM_MAX_VOLUME) {
421 volume0 = BGM_MAX_VOLUME;
422 }
423 if (volume0 != 0) {
424 volume0 = (volume0 << 8) | 0xFF;
425 }
426 volume1 = update->finalVolume;
427 if (volume1 > BGM_MAX_VOLUME) {
428 volume1 = BGM_MAX_VOLUME;
429 }
430 if (volume1 != 0) {
431 volume1 = (volume1 << 8) | 0xFF;
432 } else {
433 volume1 = 0x7FFF;
434 }
435 playerB->globals->unk_74 = playerB;
436 playerB->globals->unk_78 = playerA;
437 playerB->globals->unkSongName = songName;
438 playerB->globals->unkFadeTime = duration;
439 playerB->globals->unkFadeStart = volume0;
440 playerB->globals->unkFadeEnd = volume1;
441 playerB->globals->unk_80 = 1;
442 } else {
443 status = AU_ERROR_7;
444 }
445 } else {
446 status = AU_ERROR_6;
447 }
448 } else {
450 }
451 } else {
452 playerB = au_bgm_get_player_with_song_name(songName);
453 if (playerB != NULL) {
454 if (songName == playerB->songName) {
455 if (playerB->unk_220 != 0) {
456 playerB->unk_220 = 0;
457 }
458 }
459 }
460 }
461 } else {
463 }
464 return status;
465}
466
467void func_8004DFD4(AuGlobals* globals) {
468 BGMPlayer* player;
469 BGMPlayerTrack* track;
470 SeqNote* note;
471 u32 i;
472 u32 j;
473 s32 k;
474
475 player = globals->unk_74;
476 au_copy_words(globals->unk_78, globals->unk_74, sizeof(*player));
477 if (globals->unkSongName == player->songName) {
478 for (i = 0; i < ARRAY_COUNT(player->tracks); i++) {
479 track = &player->tracks[i];
480 if (track->bgmReadPos != NULL) {
481 for (j = track->unk_52; j < track->unk_53; j++) {
482 note = &player->notes[j];
483 note->noteLength = 0;
484 }
485 }
486 }
487 for (k = 0; k < ARRAY_COUNT(player->effectIndices); k++) {
488 if (player->effectIndices[k] != 0xFF) {
489 player->seqCmdArgs.MasterEffect.index = player->effectIndices[k];
490 player->seqCmdArgs.MasterEffect.value = player->effectValues[k];
491 au_BGMCmd_E6_MasterEffect(player, track);
492 }
493 }
494 au_fade_init(&player->fadeInfo, globals->unkFadeTime, globals->unkFadeStart, globals->unkFadeEnd);
495 }
496 globals->unk_80 = 0;
497}
498
500 BGMPlayer* player;
501 AuResult status = AU_RESULT_OK;
502
503 if (update->songName != 0) {
504 player = au_bgm_get_player_with_song_name(update->songName);
505 if (player != NULL) {
506 func_80053B04(&player->fadeInfo, update->duration, update->finalVolume);
507 }
508 else {
510 }
511 } else {
513 }
514 return status;
515}
516
517void au_bgm_player_init(BGMPlayer* player, s32 priority, s32 busId, AuGlobals* globals) {
518 s16 i;
519
520 player->globals = globals;
521 func_8004E880(player, BGM_SAMPLE_RATE, 48);
522 player->busVolume = 0x8000;
524 player->masterVolume = 0x7F000000;
525 player->updateCounter = 0;
526 player->songPlayingCounter = 0;
527 player->songName = 0;
528 player->fadeSongName = 0;
529 player->unk_58 = 0;
530 player->unk_5A = 0;
531 player->segmentReadPos = NULL;
532 player->segmentStartPos = NULL;
533 player->subSegmentStartPos = 0;
534 player->masterTempoTime = 0;
535 player->masterTempoTarget = 0;
536 player->masterTempoStep = 0;
537 player->masterVolumeTime = 0;
538 player->masterVolumeTarget = 0;
539 player->masterVolumeStep = 0;
540 player->masterPitchShift = 0;
541 player->detune = 0;
542 player->unk_220 = 0;
543 player->trackVolsConfig = NULL;
544 player->bFadeConfigSetsVolume = FALSE;
546 player->priority = priority;
547 player->busId = busId;
548 *(s32*)player->segLoopCounters = 0;
549 player->unk_222 = 0;
550 player->unk_223 = 0;
551 player->playbackRate = 1.0f;
552 player->unk_22A[0] = 0;
553 player->unk_22A[1] = 1;
554 player->unk_22A[2] = 0;
555 player->unk_22A[3] = 0;
556 player->unk_22A[4] = 0;
557 player->unk_22A[5] = 2;
558 player->unk_22A[6] = 3;
559 player->unk_22A[7] = 4;
560
561 for (i = 0; i < ARRAY_COUNT(player->tracks); i++) {
562 BGMPlayerTrack* temp = &player->tracks[i];
563
564 temp->subTrackVolume = 0;
565 temp->delayTime = 0;
566 temp->subTrackCoarseTune = 0;
567 temp->subTrackFineTune = 0;
568 temp->subTrackPan = 0;
569 temp->subTrackReverb = 0;
570 temp->patch = 0;
571 temp->isDrumTrack = FALSE;
572 temp->segTrackVolume = 0x7F;
573 temp->unk_4C = 0;
574
575 if (i < ARRAY_COUNT(player->unk_238)) {
576 player->unk_238[i] = 0;
577 }
578 }
579
580 for (i = 0; i < ARRAY_COUNT(player->notes); i++) {
581 SeqNote* note = &player->notes[i];
582
583 note->volume = 0;
584 note->adjustedPitch = 0;
585 note->noteLength = 0;
586 note->unk_14 = 0;
587 note->noteVelocity = 0;
588 note->unk_note_17 = 0;
589 }
590
591 au_fade_set_vol_scale(&player->fadeInfo, 0x7FFF);
592 func_80055110(player);
593}
594
595void au_bgm_set_effect_indices(BGMPlayer* player, u8* list) {
596 s32 i;
597 s32 remaining;
598
599 for (i = 0; i < ARRAY_COUNT(player->effectIndices); i++) {
600 s8 idx = *list++;
601
602 if (idx < 0) {
603 break;
604 }
605 player->effectIndices[i] = idx;
606 }
607
608 remaining = ARRAY_COUNT(player->effectIndices) - i;
609 if (remaining > 0) {
610 while (remaining-- != 0) {
611 player->effectIndices[i++] = -1;
612 }
613 }
614}
615
617 player->fadeInfo.fadeTime--;
618
619 if (player->fadeInfo.fadeTime != 0) {
620 player->fadeInfo.curVolume.s32 += player->fadeInfo.fadeStep;
621 } else {
622 player->fadeInfo.curVolume.s32 = player->fadeInfo.targetVolume << 16;
623
624 if (player->fadeInfo.onCompleteCallback != NULL) {
625 player->fadeInfo.onCompleteCallback();
626 }
627
628 if (player->fadeSongName != 0) {
630 } else if (player->fadeInfo.curVolume.s32 == 0) {
631 au_bgm_stop_player(player);
632 }
633 }
634 func_8004E444(player);
635}
636
638 u16 mult = (arg0->fadeInfo.curVolume.u16 * arg0->fadeInfo.volScale.u16) >> 15;
639 s32 i;
640
641 for (i = 0; i < ARRAY_COUNT(arg0->effectIndices); i++) {
642 s8 busId = arg0->effectIndices[i];
643
644 if (busId < 0) {
645 return;
646 }
647 au_fade_set_volume(busId, mult, arg0->busVolume);
648 }
649}
650
652 u16 hasMore = TRUE;
653 s32 retVal = FALSE;
654
655 // update pseudorandom numbers with fast 'good enough' method
656 player->randomValue1 = (u16)player->randomValue1 + (u16)player->songPlayingCounter + (u16)player->updateCounter;
657 player->randomValue2 = (u16)player->randomValue2 + ((player->songPlayingCounter << 4) & 0xFFFF) + ((player->updateCounter >> 4) & 0xFFFF);
658 do {
659 switch (player->masterState) {
661 hasMore = FALSE;
662 break;
664 if (player->unk_220 == 0) {
666 if (player->masterState == BGM_STATE_PLAY_SUBSEG) {
667 hasMore = FALSE;
668 }
669 } else {
670 hasMore = FALSE;
671 }
672 break;
675 break;
678 hasMore = FALSE;
679 break;
682 break;
683 default:
684 retVal = TRUE;
685 hasMore = FALSE;
686 break;
687 }
688 } while (hasMore);
689 return retVal;
690}
691
693 s32* buf;
694 s32 cmd;
695 s32 keepReading;
696 s32 i;
697
698 for (i = 0; i < ARRAY_COUNT(player->tracks); i++) {
699 BGMPlayerTrack* track = &player->tracks[i];
700 track->instrument = NO_INSTRUMENT;
701 track->subTrackVolume = 0x7FFF0000;
702 track->subTrackPan = 0x40;
703 track->subTrackReverb = 0;
704 track->patch = 0;
705 track->subTrackCoarseTune = 0;
706 track->subTrackFineTune = 0;
707 track->segTrackVolume = 0x7F;
708 track->unk_4C = 0;
709 track->unkVolume = 0x7FFF0000;
710 track->savedPos = NULL;
711 track->prevReadPos = NULL;
712 track->detourLength = 0;
713 track->segTrackTune = 0;
714 track->trackTremoloTime = 0;
715 track->trackTremoloAmount = 0;
716 track->trackTremoloSpeed = 0;
717 track->subTrackVolumeStep = 0;
718 track->subTrackVolumeTarget = 0;
719 track->subTrackVolumeTime = 0;
720 track->unkVolumeStep = 0;
721 track->unkVolumeTarget = 0;
722 track->unkVolumeTime = 0;
723 track->unk_4D = 0;
724 track->unk_4E = 0;
725 track->unk_4F = 0;
726 track->unk_50 = 0;
727 track->unk_51 = 0;
728 track->polyphonicIdx = 0;
729 track->unk_57 = 0;
730 track->isDrumTrack = FALSE;
731 track->parentTrackIdx = 0;
732 track->unk_5A = 0;
733 track->subtrackBusId = player->busId;
734 track->index = i;
735 }
736
737 for (i = 0; i < ARRAY_COUNT(player->notes); i++) {
738 SeqNote* note = &player->notes[i];
739 note->ins = NO_INSTRUMENT;
740 note->pitchRatio = 2.0f;
741 note->unk_14 = 0;
742 note->noteVelocity = 0;
743 note->noteLength = 0;
744 note->tremoloTime = 0;
745 }
746
747 func_80050900(player);
748 player->playbackRate = 128.0f; // set to 1.0 later om...
750 player->masterTempoBPM = BGM_DEFAULT_TEMPO / 100;
751 player->unk_21E = 0x80;
752 player->masterVolume = 0x7F000000;
753 player->fadeSongName = 0;
754 player->unk_74 = 0;
755 player->masterTempoTarget = 0;
756 player->masterPitchShift = 0;
757 player->detune = 0;
758 player->masterVolumeTime = 0;
759 player->masterVolumeTarget = 0;
760 player->masterVolumeStep = 0;
761 player->proxMixValue = 0;
762 player->proxMixID = 0;
763 player->proxMixVolume = 0;
764 player->segActiveLoopEndPos[3] = NULL;
765 player->segActiveLoopEndPos[2] = NULL;
766 player->segActiveLoopEndPos[1] = NULL;
767 player->segActiveLoopEndPos[0] = NULL;
768 *(s32*)player->segLoopCounters = 0;
769 player->segLoopDepth = 0;
770 player->unk_222 = 0;
771 player->unk_223 = 0;
772 player->trackVolsConfig = NULL;
773 player->bFadeConfigSetsVolume = FALSE;
774 player->unk_233 = 1;
775 player->unk_211 = 0;
776 player->playbackRate = 1.0f;
777
778 for (i = 0; i < ARRAY_COUNT(player->unk_212); i++) {
779 func_8004E844(player, i);
780 }
781
782 for (i = 0; i < ARRAY_COUNT(player->effectValues); i++) {
783 player->effectValues[i] = 0;
784 }
785
786 player->unk_220 = 0;
787 player->songPlayingCounter = 0;
788 for (i = 0; i < ARRAY_COUNT(player->segLoopStartLabels); i++) {
789 player->segLoopStartLabels[i] = player->segmentReadPos;
790 }
791
792 // find labels
793 buf = player->segmentReadPos;
794 keepReading = TRUE;
795 while (keepReading) {
796 cmd = *buf++;
797 if (cmd == 0) {
798 keepReading = FALSE;
799 } else if ((cmd & 0xF0000000) == BGM_SEGMENT_LABEL << 28) {
800 player->segLoopStartLabels[cmd & 0x1F] = buf;
801 }
802 }
803
805}
806
807void func_8004E844(BGMPlayer* player, s32 arg1) {
808 s32 i;
809 u16* temp = player->unk_174[arg1];
810 player->unk_212[arg1] = 0;
811
812 for (i = 0; i < 9; i++) {
813 *temp++ = 0xFF00;
814 }
815}
816
817// divisor is number of ticks per beat?
818void func_8004E880(BGMPlayer* player, s32 sampleRate, s32 divisor) {
819 u32 A;
820
821 A = 10434782 / (u32)divisor;
822
823 if (A > 500000) {
824 A = 500000;
825 } else if (A < 80000) {
826 A = 80000;
827 }
828 if (A < sampleRate) {
829 sampleRate = A;
830 }
831 player->nextUpdateStep = sampleRate;
832 player->nextUpdateInterval = A;
833 player->nextUpdateCounter = A;
834 player->maxTempo = A / 1000;
835}
836
837// runs whenever a new segment begins playing
839 u16 continueReading = TRUE;
840 u32 cmd;
841
842 player->masterTempoStep = 0;
843 player->masterTempoTime = 0;
844 while (continueReading) {
845 cmd = *player->segmentReadPos++;
846 if (cmd == BGM_SEGMENT_END) {
848 continueReading = FALSE;
849 } else {
850 switch (cmd >> 12) {
851 case BGM_SEGMENT_SUBSEG << 16:
852 au_bgm_load_subsegment(player, cmd);
854 continueReading = FALSE;
855 break;
856 case BGM_SEGMENT_START_LOOP << 16:
857 break;
858 case BGM_SEGMENT_WAIT << 16:
859 continueReading = FALSE;
860 break;
861 case BGM_SEGMENT_END_LOOP << 16:
862 au_bgm_end_segment_loop(player, cmd);
863 break;
864 case BGM_SEGMENT_6 << 16:
865 if (!(player->unk_223 & 1)) {
866 au_bgm_end_segment_loop(player, cmd);
867 }
868 break;
869 case BGM_SEGMENT_7 << 16:
870 if (player->unk_223 & 1) {
871 au_bgm_end_segment_loop(player, cmd);
872 }
873 break;
874 default:
875 continueReading = FALSE;
876 break;
877 }
878 }
879 }
880}
881
882void au_bgm_end_segment_loop(BGMPlayer* player, u32 cmd) {
883 s32 labelIndex = cmd & 0x1F; // 01F (bits 0-4)
884 s32 iterCount = (cmd >> 5) & 0x7F; // FE0 (bits 5-11)
885 u32 depth;
886
887 depth = player->segLoopDepth;
888 if (player->segActiveLoopEndPos[depth] != NULL) {
889 if (player->segActiveLoopEndPos[depth] == player->segmentReadPos) {
890 if (player->segLoopCounters[depth] != 0) {
891 player->segLoopCounters[depth]--;
892 if ((player->segLoopCounters[depth]) == 0) {
893 player->segActiveLoopEndPos[depth] = NULL;
894 if (depth > 0) {
895 depth--;
896 }
897 } else {
898 player->segmentReadPos = player->segLoopStartLabels[labelIndex];
899 }
900 } else {
901 player->segmentReadPos = player->segLoopStartLabels[labelIndex];
902 }
903 } else if (depth < 4) {
904 depth++;
905 player->segActiveLoopEndPos[depth] = player->segmentReadPos;
906 player->segLoopCounters[depth] = iterCount;
907 player->segmentReadPos = player->segLoopStartLabels[labelIndex];
908 }
909 } else {
910 player->segActiveLoopEndPos[depth] = player->segmentReadPos;
911 player->segLoopCounters[depth] = iterCount;
912 player->segmentReadPos = player->segLoopStartLabels[labelIndex];
913 }
914 player->segLoopDepth = depth;
915}
916
917void au_bgm_load_subsegment(BGMPlayer* player, u32 cmd) {
918 BGMPlayerTrack* track;
919 u32 trackInfo;
920 s32* trackList;
921 u32 parentIdx;
922 s32 count;
923 s32 nextRelativePos;
924 s32 bUsesPolyphony;
925 s32 i;
926
927 nextRelativePos = 0;
928 bUsesPolyphony = FALSE;
929 player->subSegmentStartPos = AU_FILE_RELATIVE(player->segmentStartPos, (cmd & 0xFFFF) << 2);
930 trackList = player->subSegmentStartPos;
931 for (i = 0; i < ARRAY_COUNT(player->tracks); i++) {
932 track = &player->tracks[i];
933 trackInfo = *trackList++;
934 track->bgmReadPos = (AuFilePos) (trackInfo >> 0x10);
935 if (track->bgmReadPos != NULL) {
936 if ((trackInfo & 0x100) == 0) {
937 track->polyphonicIdx = (trackInfo & (0x7 << 0xD)) >> 0xD;
938 track->isDrumTrack = (trackInfo >> 7) & 1;
939 parentIdx = (trackInfo & (0xF << 9)) >> 9;
940 track->parentTrackIdx = 0;
941 if (parentIdx != 0) {
942 BGMPlayerTrack* parentTrack = &player->tracks[parentIdx - 1];
943 if ((parentIdx - 1) < i) {
944 track->unk_51 = parentTrack->unk_51;
945 track->unk_52 = parentTrack->unk_52;
946 track->unk_53 = parentTrack->unk_53;
947
948 track->bgmReadPos = (track->bgmReadPos + (s32)player->subSegmentStartPos);
949 track->delayTime = 1;
950
951 track->parentTrackIdx = parentIdx;
952 if (player->unk_233 != 0) {
953 track->unk_5A = 1;
954 }
955 bUsesPolyphony = TRUE;
956 } else {
957 track->bgmReadPos = NULL;
958 }
959 } else {
960 count = player->unk_22A[track->polyphonicIdx];
961 track->unk_51 = count;
962 track->unk_52 = nextRelativePos;
963 nextRelativePos += count;
964 track->unk_53 = nextRelativePos;
965
966 track->bgmReadPos = (track->bgmReadPos + (s32)player->subSegmentStartPos);
967 track->delayTime = 1;
968 }
969 } else {
970 track->bgmReadPos = NULL;
971 }
972 }
973 }
974 player->unk_21B = nextRelativePos; // last Voice?
975 if (bUsesPolyphony) {
976 player->unk_233 = 0;
977 }
978}
979
981 s32 i;
982
983 player->unk_220 = 0;
984 player->songName = 0;
985 player->fadeSongName = 0;
986 player->unk_58 = 0;
987 player->unk_5A = 0;
988 for (i = 0; i < ARRAY_COUNT(player->tracks); i++) {
989 player->tracks[i].bgmReadPos = NULL;
990 }
991 func_80050900(player);
994}
995
996#define POST_BGM_READ() \
997if (track->detourLength != 0) {\
998 track->detourLength--;\
999 if (track->detourLength == 0) {\
1000 track->bgmReadPos = track->savedPos;\
1001 }\
1002}
1003
1005 s32 bVolumeFading;
1006 u8 sp1F;
1007 s16 notePitch;
1008 u8 bFinished;
1009
1010 AuVoice* voice;
1011 BGMDrumInfo* drumInfo;
1012 BGMPlayerTrack* track;
1013 SeqNote* note;
1014 s32 var_a0;
1015 s32 temp;
1016 s32 var_a1_5;
1017 s32 bAcquiredVoiceIdx;
1018 u8 opcode;
1019 u8 noteVelocity;
1020 s32 noteLength;
1021 u32 i;
1022 u8 voiceIdx;
1023 s32 temp2;
1024 bVolumeFading = FALSE;
1025 bFinished = FALSE;
1026
1027 if (player->masterTempoTime != 0) {
1028 player->masterTempoTime--;
1029 if (player->masterTempoTime == 0) {
1030 player->masterTempo = player->masterTempoTarget;
1031 player->masterTempoTarget = 0;
1032 player->masterTempoStep = 0;
1033 } else {
1034 player->masterTempo += player->masterTempoStep;
1035 }
1036 player->nextUpdateStep = player->masterTempo * 10;
1037 }
1038 if (player->masterVolumeTime != 0) {
1039 player->masterVolumeTime--;
1040 if (player->masterVolumeTime == 0) {
1041 player->masterVolume = player->masterVolumeTarget;
1042 player->masterVolumeTarget = 0;
1043 player->masterVolumeStep = 0;
1044 } else {
1045 player->masterVolume += player->masterVolumeStep;
1046 }
1047 bVolumeFading = TRUE;
1048 }
1049 player->volumeChanged = FALSE;
1050 if (player->trackVolsConfig != NULL) {
1051 if (player->bFadeConfigSetsVolume) {
1052 // setting track volumes
1053 s32 lenLimit = 16;
1054 while (lenLimit-- != 0) {
1055 i = *player->trackVolsConfig++;
1056 if (i == 0) {
1057 break;
1058 }
1059 track = &player->tracks[i - 1];
1060 player->seqCmdArgs.TrackVolumeFade.time = 48;
1061 player->seqCmdArgs.TrackVolumeFade.value = *(player->trackVolsConfig++);
1062 if (track->bgmReadPos != 0) {
1063 au_BGMCmd_F6_TrackVolumeFade(player, track);
1064 }
1065 }
1066 }
1067 else {
1068 // clearing track volumes
1069 s32 lenLimit = 16;
1070 while (lenLimit-- != 0) {
1071 i = *player->trackVolsConfig++;
1072 if (i == 0) {
1073 break;
1074 }
1075 track = &player->tracks[i - 1];
1076 player->seqCmdArgs.TrackVolumeFade.time = 48;
1077 player->trackVolsConfig++; // ignore arg
1078 player->seqCmdArgs.TrackVolumeFade.value = 0;
1079 if (track->bgmReadPos != 0) {
1080 au_BGMCmd_F6_TrackVolumeFade(player, track);
1081 }
1082 }
1083 }
1084 player->trackVolsConfig = NULL;
1085 player->bFadeConfigSetsVolume = FALSE;
1086 }
1087 for (i = 0; i < ARRAY_COUNT(player->tracks); i++) {
1088 track = &player->tracks[i];
1089 if (track->bgmReadPos != NULL) {
1090 track->changed.all = 0;
1091 if (bVolumeFading || player->volumeChanged) {
1092 track->changed.volume = 1;
1093 } else {
1094 track->changed.volume = 0;
1095 }
1096 if (track->subTrackVolumeTime != 0) {
1097 track->subTrackVolumeTime--;
1098 if (track->subTrackVolumeTime == 0) {
1099 track->subTrackVolume = track->subTrackVolumeTarget;
1100 } else {
1101 track->subTrackVolume += track->subTrackVolumeStep;
1102 }
1103 track->changed.volume = 1;
1104 }
1105 if (track->unkVolumeTime != 0) {
1106 track->unkVolumeTime--;
1107 if (track->unkVolumeTime == 0) {
1108 track->unkVolume = track->unkVolumeTarget << 0x10;
1109 } else {
1110 track->unkVolume += track->unkVolumeStep;
1111 }
1112 track->changed.volume = 1;
1113 }
1114 track->delayTime--;
1115 if (track->delayTime <= 0) {
1116 sp1F = track->unk_52;
1117 while (track->delayTime == 0) {
1118 opcode = *(track->bgmReadPos++);
1119 POST_BGM_READ();
1120
1121 if (opcode < 0x80) {
1122 if (opcode == 0) {
1123 if (track->prevReadPos != 0) {
1124 track->bgmReadPos = track->prevReadPos;
1125 track->prevReadPos = 0;
1126 } else {
1127 bFinished = TRUE;
1128 break;
1129 }
1130 } else {
1131 if (opcode >= 0x78) {
1132 // long delay
1133 track->delayTime = (((opcode & 7) << 8) + *(track->bgmReadPos++)) + 0x78;
1134 POST_BGM_READ();
1135
1136 } else {
1137 // delay
1138 track->delayTime = opcode;
1139 }
1140 }
1141 } else {
1142 // note
1143 if (opcode < 0xD4) {
1144 notePitch = (opcode & 0x7F);
1145 noteVelocity = *(track->bgmReadPos++);
1146 POST_BGM_READ();
1147 noteLength = *(track->bgmReadPos++);
1148 POST_BGM_READ();
1149 if (!(noteLength < 0xC0)) {
1150 noteLength = (((u8)noteLength & ~0xC0) << 8) + *(track->bgmReadPos++) + 0xC0;
1151 POST_BGM_READ();
1152 }
1153 bAcquiredVoiceIdx = FALSE;
1154 if (track->unk_5A == 0) {
1155 // find first free voice
1156 for (voiceIdx = sp1F; voiceIdx < track->unk_53; voiceIdx++) {
1157 voice = &player->globals->voices[voiceIdx];
1158 sp1F++;
1159 if (voice->priority == AU_PRIORITY_FREE) {
1160 bAcquiredVoiceIdx = TRUE;
1161 break;
1162 }
1163 }
1164
1165 if (!bAcquiredVoiceIdx) {
1166 if (track->polyphonicIdx >= 5) { // 5 = AL_DEFAULT_PRIORITY?
1167 // try stealing a voice with lower priority
1168 for (voiceIdx = track->unk_52; voiceIdx < track->unk_53; voiceIdx++) {
1169 voice = &player->globals->voices[voiceIdx];
1170 if (voice->priority < player->priority) {
1171 au_reset_voice(voice, voiceIdx);
1172 bAcquiredVoiceIdx = TRUE;
1173 break;
1174 }
1175 }
1176 // try stealing a voice with equal priority and zero note length
1177 if (!bAcquiredVoiceIdx) {
1178 for (voiceIdx = track->unk_52; voiceIdx < track->unk_53; voiceIdx++) {
1179 voice = &player->globals->voices[voiceIdx];
1180 if (voice->priority == player->priority) {
1181 note = &player->notes[voiceIdx];
1182 if (note->noteLength == 0) {
1183 au_reset_voice(voice, voiceIdx);
1184 bAcquiredVoiceIdx = TRUE;
1185 break;
1186 }
1187 }
1188 }
1189 }
1190 // try stealing a voice with equal priority and lowest note length
1191 if (!bAcquiredVoiceIdx) {
1192 s32 shortestLength = 0xFFFF;
1193 u8 voice_it;
1194 AuVoice* curVoice;
1195 SeqNote* curNote;
1196 for (voice_it = track->unk_52; voice_it < track->unk_53; voice_it++) {
1197 curVoice = &player->globals->voices[voice_it];
1198 if (curVoice->priority == player->priority) {
1199 curNote = &player->notes[voice_it];
1200 if (curNote->unk_note_17 == 0 && curNote->noteLength < shortestLength) {
1201 shortestLength = curNote->noteLength;
1202 voice = curVoice;
1203 note = curNote;
1204 voiceIdx = voice_it;
1205 bAcquiredVoiceIdx = TRUE;
1206 }
1207 }
1208 }
1209 if (bAcquiredVoiceIdx) {
1210 note->noteLength = 0;
1211 au_reset_voice(voice, voiceIdx);
1212 }
1213 }
1214
1215 } else {
1216 voiceIdx = track->unk_52;
1217 voice = &player->globals->voices[voiceIdx];
1218 note = &player->notes[voiceIdx];
1219 note->noteLength = 0;
1220 if (voice->priority <= player->priority) {
1221 au_reset_voice(voice, voiceIdx);
1222 bAcquiredVoiceIdx = TRUE;
1223 }
1224 }
1225 }
1226 }
1227 if (bAcquiredVoiceIdx) {
1228 note = &player->notes[voiceIdx];
1229 note->tremoloTime = 0;
1230 if (noteVelocity > 0) {
1231 note->noteVelocity = noteVelocity + 1;
1232 } else {
1233 note->noteVelocity = 0;
1234 }
1235 note->noteLength = noteLength;
1236 if (track->isDrumTrack) {
1237 if (notePitch < 72) { // = 6 * 12
1238 drumInfo = &player->globals->dataPER->drums[notePitch];
1239 } else {
1240 drumInfo = player->drums[notePitch - 72]; // = 6 * 12
1241 }
1242 note->ins = au_get_instrument(player->globals, (u16)drumInfo->bankPatch >> 8, (u16)drumInfo->bankPatch & 0xFF, &voice->envelope);
1243 if (drumInfo->randVolume != 0) {
1244 note->volume = note->noteVelocity * au_bgm_get_random_vol(player->randomValue1, drumInfo->volume, drumInfo->randVolume);
1245 } else {
1246 note->volume = note->noteVelocity * drumInfo->volume;
1247 }
1248 voice->clientVolume = ((
1249 ((player->masterVolume >> 0x15) * (track->subTrackVolume >> 0x15) * (track->unkVolume >> 0x15)) >> 0x14)
1250 * (track->segTrackVolume * note->volume)) >> 0x10;
1251 note->adjustedPitch =
1252 drumInfo->keyBase
1253 + track->subTrackCoarseTune
1254 + track->subTrackFineTune
1255 - note->ins->keyBase;
1256 temp = (note->adjustedPitch + track->segTrackTune) + player->detune;
1257 if (drumInfo->randTune != 0) {
1258 note->unk_14 = au_bgm_get_random_pitch(player->randomValue1, temp, drumInfo->randTune);
1259 temp = note->unk_14;
1260 }
1261 note->pitchRatio = au_compute_pitch_ratio(temp) * note->ins->pitchRatio;
1262 if (drumInfo->randPan != 0) {
1263 voice->pan = au_bgm_get_random_pan(player, drumInfo->pan, drumInfo->randPan);
1264 } else {
1265 voice->pan = drumInfo->pan;
1266 }
1267 if (drumInfo->randReverb != 0) {
1268 voice->reverb = au_bgm_get_random_reverb(player->randomValue1, drumInfo->reverb, drumInfo->randReverb);
1269 } else {
1270 voice->reverb = drumInfo->reverb;
1271 }
1272 } else {
1273 note->volume = ((
1274 ((player->masterVolume >> 0x15) * (track->subTrackVolume >> 0x15) * (track->unkVolume >> 0x15)) >> 0x14)
1275 * (track->segTrackVolume * note->noteVelocity)) >> 9;
1276 voice->clientVolume = note->volume;
1277 note->ins = track->instrument;
1278 note->adjustedPitch =
1279 (notePitch * 100)
1280 + track->subTrackCoarseTune
1281 + player->masterPitchShift
1282 + track->subTrackFineTune
1283 - note->ins->keyBase;
1285 note->adjustedPitch
1286 + track->segTrackTune
1287 + player->detune)
1288 * track->instrument->pitchRatio;
1289
1290 if (track->unk_57 != 0) {
1291 voice->pan = au_bgm_get_random_pan(player, track->subTrackPan, track->unk_57);
1292 } else {
1293 voice->pan = track->subTrackPan;
1294 }
1295 voice->reverb = track->subTrackReverb;
1296
1297 if (track->unk_4C != 0) {
1298 voice->envelope.cmdListPress = (u8*) player->unk_174[track->unk_4C - 1]; //TODO ???
1299 } else {
1301 }
1303 }
1304 voice->instrument = note->ins;
1305 voice->pitchRatio = note->pitchRatio;
1306 voice->busId = track->subtrackBusId;
1307 if (note->noteLength >= 2) {
1308 note->unk_note_17 = 1;
1309 note->tremoloTime = track->trackTremoloTime;
1310 note->unk_13 = 0;
1311 note->tremoloAmount = track->trackTremoloAmount;
1313 voice->priority = player->priority;
1314 voice->clientPriority = voice->priority;
1315 }
1316 }
1317 } else {
1318 //TODO variable is nargs, but reusing temp is required to match
1319 temp = SeqCmdArgCounts[opcode - 0xE0];
1320 if (temp != 0) {
1321 player->seqCmdArgs.raw[0] = *(track->bgmReadPos++);
1322 POST_BGM_READ();
1323 } else {
1324 goto bgm_args_done;
1325 }
1326 if (temp > 1) {
1327 player->seqCmdArgs.raw[1] = *(track->bgmReadPos++);
1328 POST_BGM_READ();
1329 } else {
1330 goto bgm_args_done;
1331 }
1332 if (temp > 2) {
1333 player->seqCmdArgs.raw[2] = *(track->bgmReadPos++);
1334 POST_BGM_READ();
1335 } else {
1336 goto bgm_args_done;
1337 }
1338 if (temp > 3) {
1339 player->seqCmdArgs.raw[3] = *(track->bgmReadPos++);
1340 POST_BGM_READ();
1341 }
1342 bgm_args_done:
1343 CurrentSeqCmdHandler = SeqCmdHandlers[opcode - 0xE0];
1344 CurrentSeqCmdHandler(player, track);
1345 }
1346 }
1347 } // end while
1348 }
1349
1350 for (voiceIdx = track->unk_52; voiceIdx < track->unk_53; voiceIdx++) {
1351 if (track->unk_5A == 0) {
1352 voice = &player->globals->voices[voiceIdx];
1353 if (voice->priority == player->priority) {
1354 note = &player->notes[voiceIdx];
1355 if (note->unk_note_17 == 0) {
1356 if (note->noteLength > 0) {
1357 note->noteLength--;
1358 if (note->noteLength == 0) {
1360 }
1361 }
1362 if (track->isDrumTrack) {
1363 if (track->changed.tune || (player->detune != 0)) {
1364 note->pitchRatio = au_compute_pitch_ratio(((note->adjustedPitch + note->unk_14) + track->segTrackTune) + player->detune) * note->ins->pitchRatio;
1365 if (voice->pitchRatio != note->pitchRatio) {
1366 voice->pitchRatio = note->pitchRatio;
1368 }
1369 }
1370 if (track->changed.volume) {
1371 voice->clientVolume = (
1372 ((((player->masterVolume >> 0x15)
1373 * (track->subTrackVolume >> 0x15))
1374 * (track->unkVolume >> 0x15)) >> 0x14)
1375 * (track->segTrackVolume * note->volume)) >> 0x10;
1377 }
1378 } else {
1379 if (note->tremoloTime != 0) {
1380 if (note->tremoloAmount != 0) {
1381 note->tremoloAmount--;
1382 } else {
1383 u8 temp_a0_6;
1384 u8 temp_a2_4;
1385 note->unk_13 += track->trackTremoloSpeed;
1386 opcode = (note->unk_13 << 2) + 3;
1387 temp_a2_4 = note->unk_13 >> 6;
1388
1389 if ((temp_a2_4 == 1) || (temp_a2_4 == 3)) {
1390 u8 temp2 = ~opcode;
1391 var_a1_5 = temp2 + 1;
1392 } else {
1393 var_a1_5 = opcode;
1394 }
1395
1396 var_a1_5 = (var_a1_5 * track->trackTremoloTime) >> 8;
1397
1398 if ((temp_a2_4 == 2) || (temp_a2_4 == 3)) {
1399 var_a1_5 = -var_a1_5;
1400 }
1401
1402 note->pitchRatio = au_compute_pitch_ratio(var_a1_5 + ((note->adjustedPitch + track->segTrackTune) + player->detune)) * note->ins->pitchRatio;
1403 if (voice->pitchRatio != note->pitchRatio) {
1404 voice->pitchRatio = note->pitchRatio;
1406 }
1407 }
1408 } else if (track->changed.tune || (player->detune != 0)) {
1409
1410 note->pitchRatio = au_compute_pitch_ratio((note->adjustedPitch + track->segTrackTune) + player->detune) * note->ins->pitchRatio;
1411 if (voice->pitchRatio != note->pitchRatio) {
1412 voice->pitchRatio = note->pitchRatio;
1414 }
1415 }
1416 if (track->changed.volume) {
1417 s32 tempVolume = ((player->masterVolume >> 0x15) * (track->subTrackVolume >> 0x15) * (track->unkVolume >> 0x15)) >> 0x14;
1418 note->volume = (tempVolume * (track->segTrackVolume * note->noteVelocity)) >> 9;
1419 voice->clientVolume = note->volume;
1421 voice->pan = track->subTrackPan;
1422 voice->reverb = track->subTrackReverb;
1423 } else if (track->changed.pan || track->changed.reverb) {
1424 voice->pan = track->subTrackPan;
1425 voice->reverb = track->subTrackReverb;
1427 }
1428 }
1429 }
1430 note->unk_note_17 = 0;
1431 }
1432 }
1433 }
1434 }
1435 }
1436
1437 if (bFinished) {
1439 }
1440}
1441
1442static const f32 padding[] = {0.0f}; // at least after func_8004E4B8
1443
1445 u32 bpm = player->seqCmdArgs.MasterTempo.value;
1446 s32 tempo;
1447
1448 player->masterTempoBPM = bpm;
1449 tempo = snd_bpm_to_tempo(player, bpm);
1450 player->masterTempo = tempo;
1451 player->nextUpdateStep = tempo * 10;
1452 player->masterTempoTime = 0;
1453 player->masterTempoTarget = 0;
1454 player->masterTempoStep = 0;
1455}
1456
1457static s32 snd_bpm_to_tempo(BGMPlayer* player, u32 tempo) {
1458 u32 maxTempo = player->maxTempo;
1459 u32 ret = tempo;
1460
1461 ret *= player->playbackRate;
1462
1463 if (maxTempo < ret) {
1464 ret = maxTempo;
1465 } else if (ret == 0) {
1466 ret = 1;
1467 }
1468
1469 return ret * 100;
1470}
1471
1473 s32 volume = player->seqCmdArgs.MasterVolume.value & 0x7F;
1474
1475 if (volume != 0) {
1476 volume = volume << 0x18;
1477 }
1478
1479 player->masterVolume = volume;
1480 player->masterVolumeTime = 0;
1481 player->masterVolumeTarget = 0;
1482 player->masterVolumeStep = 0;
1483 player->volumeChanged = TRUE;
1484 track->changed.volume = TRUE;
1485}
1486
1488 player->masterPitchShift = (s8)player->seqCmdArgs.MasterPitchShift.cent * 100;
1489}
1490
1492 player->globals->effectChanges[player->busId].type = player->seqCmdArgs.UnkCmdE3.effectType;
1493 player->globals->effectChanges[player->busId].changed = TRUE;
1494}
1495
1497 u8 index = player->seqCmdArgs.MasterEffect.index;
1498 u32 busId = player->effectIndices[index];
1499
1500 if ((index < 4) && (busId < 0x80)) {
1501 if (player->globals->effectChanges[busId].type != player->seqCmdArgs.MasterEffect.value) {
1502 player->globals->effectChanges[busId].type = player->seqCmdArgs.MasterEffect.value;
1503 player->globals->effectChanges[busId].changed = TRUE;
1504 }
1505 player->effectValues[index] = player->seqCmdArgs.MasterEffect.value;
1506 }
1507}
1508
1510 s32 time = player->seqCmdArgs.MasterTempoFade.time;
1511 s32 tempo = snd_bpm_to_tempo(player, player->seqCmdArgs.MasterTempoFade.value);
1512
1513 if (time <= 0) {
1514 time = 1;
1515 }
1516
1517 player->masterTempoTime = time;
1518 player->masterTempoTarget = tempo;
1519 player->masterTempoStep = (tempo - player->masterTempo) / time;
1520}
1521
1523 s32 time = player->seqCmdArgs.MasterVolumeFade.time;
1524 s32 volume = player->seqCmdArgs.MasterVolumeFade.value & 0x7F;
1525
1526 if (volume != 0) {
1527 volume = volume << 0x18;
1528 }
1529
1530 if (time <= 0) {
1531 time = 1;
1532 }
1533
1534 player->masterVolumeTime = time;
1535 player->masterVolumeTarget = volume;
1536 player->masterVolumeStep = (volume - player->masterVolume) / time;
1537}
1538
1540 track->patch = player->seqCmdArgs.TrackOverridePatch.patch;
1541 track->instrument = au_get_instrument(player->globals, player->seqCmdArgs.TrackOverridePatch.bank, track->patch, &track->envelope);
1542}
1543
1545 u32 volume = arg0->seqCmdArgs.SubTrackVolume.value & 0x7F;
1546
1547 if (volume != 0) {
1548 volume = volume << 0x18;
1549 }
1550
1551 track->subTrackVolume = volume;
1552 track->changed.volume = TRUE;
1553}
1554
1556 s32 time = player->seqCmdArgs.TrackVolumeFade.time;
1557 s32 volume = player->seqCmdArgs.TrackVolumeFade.value & 0x7F;
1558
1559 if (volume != 0) {
1560 volume = volume << 0x18;
1561 }
1562
1563 if (volume != track->subTrackVolume) {
1564 if (time <= 0) {
1565 time = 1;
1566 }
1567
1568 track->subTrackVolumeTime = time;
1569 track->subTrackVolumeTarget = volume;
1570 track->subTrackVolumeStep = (volume - track->subTrackVolume) / time;
1571 }
1572}
1573
1575 track->subTrackPan = player->seqCmdArgs.SubTrackPan.value & 0x7F;
1576 track->unk_57 = 0;
1577 track->changed.pan = TRUE;
1578}
1579
1581 track->subTrackReverb = player->seqCmdArgs.SubTrackReverb.value & 0x7F;
1582 track->changed.reverb = TRUE;
1583}
1584
1586 track->segTrackVolume = player->seqCmdArgs.SegTrackVolume.value & 0x7F;
1587 track->changed.volume = TRUE;
1588}
1589
1591 track->subTrackCoarseTune = (s8)player->seqCmdArgs.SubTrackCoarseTune.cent * 100;
1592}
1593
1597
1599 track->segTrackTune = player->seqCmdArgs.SegTrackTune.value;
1600 track->changed.tune = TRUE;
1601}
1602
1604 track->trackTremoloAmount = player->seqCmdArgs.TrackTremolo.amount;
1605 track->trackTremoloSpeed = player->seqCmdArgs.TrackTremolo.speed;
1606 track->trackTremoloTime = player->seqCmdArgs.TrackTremolo.time;
1607}
1608
1612
1616
1618 track->trackTremoloTime = 0;
1619}
1620
1622 track->subTrackPan = player->seqCmdArgs.UnkCmdF4.pan0 & 0x7F;
1623 track->unk_57 = player->seqCmdArgs.UnkCmdF4.pan1 & 0x7F;
1624}
1625
1627 BGMInstrumentInfo* instrument;
1628 s32 volume;
1629 u32 voiceIndex;
1630 u32 patch;
1631 u32 bank;
1632
1633 voiceIndex = player->seqCmdArgs.SetTrackVoice.index;
1634 if (voiceIndex < 0x80) {
1635 if (voiceIndex < player->bgmInstrumentCount) {
1636 instrument = &player->instrumentsInfo[voiceIndex];
1637 } else {
1638 instrument = &player->globals->defaultPRGEntry;
1639 }
1640 } else {
1641 voiceIndex -= 0x80;
1642 if (voiceIndex < 0x40) {
1643 instrument = &player->globals->dataPRG[voiceIndex];
1644 } else {
1645 instrument = &player->globals->defaultPRGEntry;
1646 }
1647 }
1648 bank = instrument->bankPatch >> 8;
1649 patch = (u8)instrument->bankPatch;
1650 volume = instrument->volume & 0x7F;
1651 track->patch = patch;
1652 track->instrument = au_get_instrument(player->globals, bank, patch, &track->envelope);
1653 if (volume != 0) {
1654 volume <<= 0x18;
1655 }
1656 track->subTrackVolume = volume;
1657 track->subTrackPan = instrument->pan & 0x7F;
1658 track->subTrackReverb = instrument->reverb & 0x7F;
1659 track->subTrackCoarseTune = instrument->coarseTune * 100;
1660 track->subTrackFineTune = instrument->fineTune;
1661 track->changed.all |= 0x10101;
1662}
1663
1665 u8 index = player->seqCmdArgs.SubTrackReverbType.index;
1666 s8 busId = player->effectIndices[index];
1667
1668 if ((index < 4) && (busId >= 0)) {
1669 track->subtrackBusId = busId;
1670 } else {
1671 track->subtrackBusId = player->busId;
1672 }
1673}
1674
1676 bgm_trigger_music_event(player->priority, track->index, player->seqCmdArgs.EventTrigger.eventInfo >> 8);
1677}
1678
1679// jump to another part of the track and return after a specified read length
1681 AuFilePos readPos = AU_FILE_RELATIVE(player->bgmFile, player->seqCmdArgs.Detour.offset);
1682
1683 track->detourLength = player->seqCmdArgs.Detour.length;
1684 track->savedPos = track->bgmReadPos;
1685 track->bgmReadPos = readPos;
1686}
1687
1688// jump to another part of the track, switched by player->proxMixID
1690 AuFilePos args;
1691 u32 i;
1692
1693 // get jump table
1694 args = AU_FILE_RELATIVE(player->bgmFile, player->seqCmdArgs.Jump.unk_00);
1695 if (player->proxMixID < player->seqCmdArgs.Jump.unk_02) {
1696 args += player->proxMixID * 3;
1697 }
1698 // read new position from jump table
1699 track->prevReadPos = track->bgmReadPos;
1700 track->bgmReadPos = AU_FILE_RELATIVE(player->bgmFile, (args[0] << 8) + args[1]);
1701 track->isDrumTrack = args[2];
1702
1703 if (track->unk_4D != 0) {
1704 track->unk_4D = 0;
1705 track->unkVolume = 0;
1706 for (i = track->unk_52; i < track->unk_53; i++) {
1707 AuVoice* voice = &player->globals->voices[i];
1708 if ((voice->priority == player->priority) && (voice->cmdPtr != NULL)) {
1709 au_reset_voice(voice, i);
1710 }
1711 }
1712 }
1713 if (track->unk_4E != 0) {
1714 track->unk_4E = 0;
1715 func_80050888(player, track, player->proxMixVolume, 144);
1716 }
1717 track->subTrackCoarseTune = 0;
1718 track->subTrackFineTune = 0;
1719 track->unk_4C = 0;
1720 track->segTrackTune = 0;
1721 track->trackTremoloTime = 0;
1722 track->subTrackVolumeTime = 0;
1723 track->unk_57 = 0;
1724 track->subtrackBusId = player->busId;
1725}
1726
1728 u32 i;
1729 u32 j;
1730 u8 temp_a1;
1731 u8 temp_a3;
1732
1733 u32 arg0 = player->seqCmdArgs.UnkCmdFF.unk_00;
1734 u32 arg1 = player->seqCmdArgs.UnkCmdFF.unk_01;
1735 u32 arg2 = player->seqCmdArgs.UnkCmdFF.unk_02;
1736
1737 switch (arg0) {
1738 case 1:
1739 if ((arg1 < ARRAY_COUNT(player->effectIndices)) && ((s8)player->effectIndices[arg1] >= 0)) {
1740 player->globals->channelDelayBusId = player->effectIndices[arg1];
1741 if (arg2 != 0) {
1742 temp_a3 = arg2 & 0xF;
1743 temp_a1 = ((arg2 >> 4) & 1) + 1;
1744 if ((player->globals->channelDelayTime != temp_a3) || (player->globals->channelDelaySide != temp_a1)) {
1745 player->globals->channelDelayTime = temp_a3;
1746 player->globals->channelDelaySide = temp_a1;
1747 player->globals->channelDelayPending = 1;
1748 }
1749 } else {
1750 if (player->globals->channelDelaySide != 0) {
1751 player->globals->channelDelaySide = 0;
1752 player->globals->channelDelayPending = 1;
1753 }
1754 }
1755 }
1756 break;
1757 case 2:
1758 if (arg1 - 1 < 8) {
1759 player->unk_211 = arg1;
1760 func_8004E844(player, arg1 - 1);
1761 } else {
1762 player->unk_211 = 0;
1763 }
1764 break;
1765 case 3:
1766 i = player->unk_211;
1767 if (i - 1 < 8) {
1768 i = i - 1; // needed to match
1769 j = player->unk_212[i];
1770 if (j < 8) {
1771 if (arg1 >= 40) {
1772 player->unk_174[i][j] = (arg1 << 8) + arg2;
1773 } else {
1774 player->unk_174[i][j] = (D_80078558[arg1] << 8) + arg2;
1775 }
1776 player->unk_212[i] = j + 1;
1777 }
1778 }
1779 break;
1780 case 4:
1781 if (arg1 < 9) {
1782 track->unk_4C = arg1;
1783 } else {
1784 track->unk_4C = 0;
1785 }
1786 break;
1787 case 5:
1788 if (player->soundManager != NULL) {
1789 for (i = 0; i < ARRAY_COUNT(player->soundManager->bgmSounds); i++) {
1790 if ((player->soundManager->bgmSounds[i].unk_0) == 0) {
1791 player->soundManager->bgmSounds[i].unk_0 = arg1;
1792 player->soundManager->bgmSounds[i].volume = ((player->fadeInfo.curVolume.u16 * player->fadeInfo.volScale.u16) + 0x7FFF) >> 0x17;
1793 break;
1794 }
1795 }
1796 }
1797 break;
1798 case 6:
1799 if (arg1 == 0) {
1800 if (track->unk_4E != 0) {
1801 track->unk_4E = 0;
1802 for (i = 0; i < ARRAY_COUNT(player->tracks); i++) {
1803 BGMPlayerTrack* otherTrack = &player->tracks[i];
1804 if (player->proxMixVolume == 0x7F) {
1805 if (otherTrack->unk_4F != 0) {
1806 otherTrack->unk_4E = 0;
1807 func_80050888(player, otherTrack, otherTrack->unk_4F, 72);
1808 }
1809 } else {
1810 if (otherTrack->unk_50 != 0) {
1811 otherTrack->unk_4E = 0;
1812 func_80050888(player, otherTrack, otherTrack->unk_50, 72);
1813 }
1814 }
1815 }
1816 }
1817 } else {
1818 track->unk_4F = arg1;
1819 track->unk_50 = arg2;
1820 }
1821 break;
1822 }
1823}
1824
1826}
1827
1828/*
1829Uses bit masks:
18303F00 = 0011 1111 0000 0000 -> 0011 1111
1831000C = 0000 0000 0000 1100 -> 1100 0000
1832*/
1833static u8 au_bgm_get_random_pan(BGMPlayer* player, u8 pan, u8 amplitude) {
1834 s32 seed = player->randomValue1;
1835 s32 tap7 = seed >> 7;
1836 s32 tap2 = seed >> 2;
1837 s32 parity = (tap7 + tap2) & 1;
1838 s32 lo = (seed >> 8) & 0x3F; // bitmask 0x3F00
1839 s32 hi = (seed << 4) & 0xC0; // bitmask 0x000C
1840 s32 random = lo + hi;
1841 s32 base = pan;
1842 s32 retPan;
1843
1844 if (parity) {
1845 retPan = base + ((amplitude * random) >> 8);
1846 } else {
1847 retPan = base - ((amplitude * random) >> 8);
1848 }
1849 if (retPan < 0) {
1850 retPan = 0;
1851 } else if (retPan >= 0x80) {
1852 retPan = 0x7F;
1853 }
1854 return retPan;
1855}
1856
1857/*
1858Uses bit masks:
18593C0 = 0000 0011 1100 0000 -> 0001 1111
186003C = 0000 0000 0011 1100 -> 1110 0000
1861*/
1862static s16 au_bgm_get_random_pitch(s32 seed, s32 pitch, u8 amplitude) {
1863 s32 tap4 = seed >> 4;
1864 s32 tap1 = seed >> 1;
1865 s32 parity = (tap4 + tap1) & 1;
1866 s32 lo = (seed >> 6) & 0xF; // bitmask 0x3C0
1867 s32 hi = (seed << 2) & 0xF0; // bitmask 0x03C
1868 s32 random = lo + hi;
1869 s32 retVal;
1870
1871 if (parity) {
1872 retVal = pitch + ((amplitude * 5 * random) >> 8);
1873 } else {
1874 retVal = pitch - ((amplitude * 5 * random) >> 8);
1875 }
1876 return retVal;
1877}
1878
1879/*
1880Uses bit masks:
18811F00 = 0001 1111 0000 0000 -> 0001 1111
188200E0 = 0000 0000 1110 0000 -> 1110 0000
1883*/
1884static u8 au_bgm_get_random_vol(s32 seed, u8 volume, u8 amplitude) {
1885 s32 lo = (seed >> 8) & 0x1F; // bitmask 0x1F00
1886 s32 hi = seed & 0xE0;
1887 s32 random = lo + hi;
1888
1889 return volume * (0x8000 - amplitude * random);
1890}
1891
1892/*
1893Uses bit masks:
18940380 = 0000 0011 1000 0000 -> 0000 0111
1895001F = 0000 0000 0001 1111 -> 1111 1000
1896*/
1897static u8 au_bgm_get_random_reverb(s32 seed, u8 reverb, u8 amplitude) {
1898 s32 lo = (seed >> 7) & 7; // bitmask 0x380
1899 s32 hi = (seed << 3) & 0xF8; // bitmask 0x01F
1900 s32 random = lo + hi;
1901
1902 return reverb * (0x8000 - (amplitude * random));
1903}
1904
1905void au_bgm_set_proximity_mix(s32 songName, u32 mix) {
1906 BGMPlayer* player;
1907 BGMPlayerTrack* track;
1908 s32 changed = FALSE;
1909 u8 mixID = mix & 0xFF;
1910 s32 i;
1911
1912 if (songName != 0) {
1913 player = au_bgm_get_player_with_song_name(songName);
1914 if ((player != NULL) && (player->proxMixValue != mix)) {
1915 player->proxMixValue = mix;
1916 if (player->proxMixID != mixID) {
1917 player->proxMixID = mixID;
1918 changed = TRUE;
1919 }
1920 player->proxMixVolume = (mix >> 0x18) & 0x7F;
1921 for (i = 0; i < ARRAY_COUNT(player->tracks); i++) {
1922 track = &player->tracks[i];
1923 if (changed) {
1924 track->unk_4D = 1;
1925 }
1926 track->unk_4E = 1;
1927 }
1928 }
1929 }
1930}
1931
1932void au_bgm_set_playback_rate(BGMPlayer* player, f32 rate) {
1933 if (rate > 2.0) {
1934 rate = 2.0f;
1935 } else if (rate < 0.25) {
1936 rate = 0.25f;
1937 }
1938
1939 player->playbackRate = rate;
1940 player->masterTempo = snd_bpm_to_tempo(player, player->masterTempoBPM);
1941 player->nextUpdateStep = player->masterTempo * 10;
1942 player->masterTempoTime = 0;
1943 player->masterTempoTarget = 0;
1944 player->masterTempoStep = 0;
1945}
1946
1947void au_bgm_player_set_detune(BGMPlayer* player, s32 detune) {
1948 if (detune > 1200) {
1949 detune = 1200;
1950 } else if (detune < -2400) {
1951 detune = -2400;
1952 }
1953
1954 player->detune = detune;
1955}
1956
1957void au_bgm_change_track_volume(BGMPlayer* player, s32 trackIdx, s16 time, u8 volume) {
1958 BGMPlayerTrack* track = &player->tracks[trackIdx];
1959
1960 if (track->bgmReadPos != 0) {
1961 player->seqCmdArgs.TrackVolumeFade.time = time;
1962 player->seqCmdArgs.TrackVolumeFade.value = volume;
1963 au_BGMCmd_F6_TrackVolumeFade(player, track);
1964 }
1965}
1966
1967void au_bgm_set_track_volumes(BGMPlayer* player, u8* trackVols, s32 mode) {
1968 player->trackVolsConfig = trackVols;
1969 player->bFadeConfigSetsVolume = mode;
1970}
1971
1972void func_80050888(BGMPlayer* player, BGMPlayerTrack* track, s32 target, s32 duration) {
1973 if (target != 0) {
1974 target = (target << 8) | 0xFF;
1975 }
1976 if (duration <= 0) {
1977 duration = 1;
1978 } else if (duration > 1000) {
1979 duration = 1000;
1980 }
1981 if (target == track->unkVolume) {
1982 track->unkVolumeTime = 0;
1983 return;
1984 }
1985 track->unkVolumeTime = duration;
1986 track->unkVolumeTarget = target;
1987 track->unkVolumeStep = ((target << 0x10) - track->unkVolume) / duration;
1988}
1989
1991 u8 i;
1992
1993 for (i = 0; i < ARRAY_COUNT(player->globals->voices); i++) {
1994 AuVoice* voice = &player->globals->voices[i];
1995 if (voice->priority == player->priority) {
1996 au_reset_voice(voice, i);
1997 }
1998 }
1999}
2000
2002 BGMPlayer* player;
2003 BGMPlayerTrack* track;
2004 BGMPlayerTrack* parentTrack;
2005 AuVoice* voice;
2006 s32 i;
2007 s32 j;
2008 s8 oldVolume;
2009
2010 s32 songName = update->songName;
2011 s32 variation = update->variation;
2012 AuResult status = AU_RESULT_OK;
2013
2014 if (songName != 0) {
2015 player = au_bgm_get_player_with_song_name(songName);
2016 if (player != NULL) {
2017 for (i = 0; i < ARRAY_COUNT(player->tracks); i++) {
2018 track = &player->tracks[i];
2019 if (track->bgmReadPos != NULL) {
2020 if (track->parentTrackIdx != 0) {
2021 parentTrack = &player->tracks[track->parentTrackIdx - 1];
2022 if (variation != 0) {
2023 if (track->unk_5A != 0) {
2024 track->unk_5A = 0;
2025 parentTrack->unk_5A = 1;
2026 for (j = parentTrack->unk_52; j < parentTrack->unk_53; j++) {
2027 voice = &player->globals->voices[j];
2028 if (voice->priority == player->priority) {
2031 }
2032 }
2033 oldVolume = track->subTrackVolume >> 24;
2034 au_BGMCmd_E9_SubTrackVolume(player, track);
2035 player->seqCmdArgs.raw[0] = 0;
2036 player->seqCmdArgs.TrackVolumeFade.time = 96;
2037 player->seqCmdArgs.TrackVolumeFade.value = oldVolume;
2038 au_BGMCmd_F6_TrackVolumeFade(player, track);
2039 }
2040 } else {
2041 if (track->unk_5A == 0) {
2042 track->unk_5A = 1;
2043 parentTrack->unk_5A = 0;
2044 for (j = track->unk_52; j < track->unk_53; j++) {
2045 voice = &player->globals->voices[j];
2046 if (voice->priority == player->priority) {
2049 }
2050 }
2051 oldVolume = parentTrack->subTrackVolume >> 24;
2052 au_BGMCmd_E9_SubTrackVolume(player, parentTrack);
2053 player->seqCmdArgs.raw[0] = 0;
2054 player->seqCmdArgs.TrackVolumeFade.time = 96;
2055 player->seqCmdArgs.TrackVolumeFade.value = oldVolume;
2056 au_BGMCmd_F6_TrackVolumeFade(player, parentTrack);
2057 }
2058 }
2059 }
2060 }
2061 }
2062 } else {
2064 }
2065 } else {
2066 status = AU_ERROR_NULL_SONG_NAME;
2067 }
2068
2069 return status;
2070}
void au_BGMCmd_EB_SubTrackReverb(BGMPlayer *player, BGMPlayerTrack *track)
void func_8004E880(BGMPlayer *player, s32 sampleRate, s32 divisor)
void au_BGMCmd_F6_TrackVolumeFade(BGMPlayer *player, BGMPlayerTrack *track)
void au_bgm_player_update_stop(BGMPlayer *player)
void au_BGMCmd_F4(BGMPlayer *player, BGMPlayerTrack *track)
void au_bgm_set_proximity_mix(s32 songName, u32 mix)
AuResult au_bgm_dispatch_player_event(SongUpdateEvent *event)
void au_BGMCmd_FD_EventTrigger(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_F7_SubTrackReverbType(BGMPlayer *player, BGMPlayerTrack *track)
void func_80050900(BGMPlayer *player)
void au_BGMCmd_FC_Jump(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_EE_SubTrackFineTune(BGMPlayer *player, BGMPlayerTrack *track)
BGMPlayer * au_bgm_get_player_with_song_name(s32 songString)
AuResult au_bgm_is_song_playing(s32 songName)
void au_BGMCmd_FE_Detour(BGMPlayer *player, BGMPlayerTrack *track)
AuResult func_8004DC80(s32 songName)
void(* SefCmdHandlers[])(SoundManager *, SoundPlayer *)
Definition sfx_player.c:192
void au_BGMCmd_E3(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_EA_SubTrackPan(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_F2_TrackTremoloTime(BGMPlayer *player, BGMPlayerTrack *track)
u8 BgmDivisors[8]
Definition sfx_player.c:271
u8 EnvelopeReleaseDefaultFast[]
Definition sfx_player.c:309
void au_bgm_load_subsegment(BGMPlayer *player, u32 cmd)
void func_8004DFD4(AuGlobals *globals)
void au_bgm_update_main(BGMPlayer *player)
void au_BGMCmd_E5_MasterVolumeFade(BGMPlayer *player, BGMPlayerTrack *track)
void func_8004E844(BGMPlayer *player, s32 arg1)
void au_bgm_change_track_volume(BGMPlayer *player, s32 trackIdx, s16 time, u8 volume)
u8 SeqCmdArgCounts[]
Definition sfx_player.c:264
void func_8004E444(BGMPlayer *arg0)
AuResult func_8004DCB8(SongUpdateEvent *update, s32 clearChanged)
AuResult func_8004E0F4(SongUpdateEvent *update)
void au_bgm_player_read_segment(BGMPlayer *player)
void au_bgm_player_update_playing(BGMPlayer *player)
void au_bgm_set_track_volumes(BGMPlayer *player, u8 *trackVols, s32 mode)
#define POST_BGM_READ()
void au_BGMCmd_F1_TrackTremoloSpeed(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_E0_MasterTempo(BGMPlayer *player, BGMPlayerTrack *track)
BSS void(* CurrentSeqCmdHandler)(BGMPlayer *, BGMPlayerTrack *)
void au_bgm_set_effect_indices(BGMPlayer *player, u8 *list)
AuResult au_bgm_stop_song(s32 songName)
void au_bgm_update_fade(BGMPlayer *player)
u8 D_80078558[40]
Definition sfx_player.c:317
void au_BGMCmd_E8_TrackOverridePatch(BGMPlayer *player, BGMPlayerTrack *track)
void au_bgm_player_initialize(BGMPlayer *player)
void au_BGMCmd_F0_TrackTremolo(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_EC_SegTrackVolume(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_E9_SubTrackVolume(BGMPlayer *arg0, BGMPlayerTrack *track)
void au_BGMCmd_NOP(BGMPlayer *player, BGMPlayerTrack *track)
AuResult func_8004DB4C(SongUpdateEvent *s)
AuResult func_8004DE2C(SongUpdateEvent *update)
void au_bgm_stop_all(void)
void au_BGMCmd_E2_MasterPitchShift(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_F5_TrackVoice(BGMPlayer *player, BGMPlayerTrack *track)
void au_bgm_end_segment_loop(BGMPlayer *player, u32 cmd)
void au_BGMCmd_E6_MasterEffect(BGMPlayer *player, BGMPlayerTrack *track)
AuResult func_80050970(SongUpdateEvent *update)
void au_BGMCmd_FF(BGMPlayer *player, BGMPlayerTrack *track)
s32 func_8004DB28(BGMPlayer *player)
void au_bgm_set_playback_rate(BGMPlayer *player, f32 rate)
s32 au_bgm_player_update_main(BGMPlayer *player)
void(* SeqCmdHandlers[])(BGMPlayer *, BGMPlayerTrack *)
Definition sfx_player.c:229
void au_BGMCmd_ED_SubTrackCoarseTune(BGMPlayer *player, BGMPlayerTrack *track)
void func_80050888(BGMPlayer *player, BGMPlayerTrack *track, s32 target, s32 duration)
void au_bgm_player_set_detune(BGMPlayer *player, s32 detune)
void au_bgm_player_init(BGMPlayer *player, s32 priority, s32 busId, AuGlobals *globals)
void au_BGMCmd_E1_MasterVolume(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_F3_TrackTremoloStop(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_E4_MasterTempoFade(BGMPlayer *player, BGMPlayerTrack *track)
void au_BGMCmd_EF_SegTrackTune(BGMPlayer *player, BGMPlayerTrack *track)
void au_reset_voice(AuVoice *voice, u8 voiceIdx)
Instrument * au_get_instrument(AuGlobals *globals, u32 bank, u32 patch, EnvelopeData *envData)
void func_80053B04(Fade *fade, u32 arg1, s32 target)
AuResult func_80053E58(s32 songID, BGMHeader *bgmFile)
void au_fade_set_volume(u8 busId, u16 volume, s32 busVolume)
f32 au_compute_pitch_ratio(s32 pitch)
BGMPlayer * func_80053F64(s32 arg0)
BGMPlayer * func_80054248(u8 arg0)
void au_fade_init(Fade *fade, s32 time, s32 startValue, s32 endValue)
void au_copy_words(void *src, void *dst, s32 size)
void au_fade_clear(Fade *fade)
void au_fade_set_vol_scale(Fade *fade, s16 value)
void func_80055110(BGMPlayer *player)
Definition 30450.c:133
void bgm_trigger_music_event(s32 playerID, s32 trackIndex, s32 eventInfo)
Definition 30450.c:812
s32 randomValue2
Definition audio.h:1018
u16 drumCount
Definition audio.h:750
s32 unkFadeTime
Definition audio.h:917
s8 subtrackBusId
Definition audio.h:983
u8 unk_212[8]
Definition audio.h:1057
struct SeqArgs::@80 SubTrackReverbType
u8 channelDelayPending
Definition audio.h:904
BGMInstrumentInfo * instrumentsInfo
Definition audio.h:1030
struct BGMHeader * bgmFile
Definition audio.h:1024
#define BGM_SAMPLE_RATE
Definition audio.h:52
struct SeqArgs::@64 MasterVolumeFade
s32 fadeStep
Definition audio.h:367
u8 * cmdListPress
Definition audio.h:533
u8 busId
Definition audio.h:1074
s8 volumeChanged
Definition audio.h:1058
VolumeField curVolume
Definition audio.h:366
u8 randVolume
Definition audio.h:770
SoundManager * soundManager
Definition audio.h:1004
s8 segTrackVolume
Definition audio.h:965
struct SeqArgs::@82 EventTrigger
AuVoice voices[24]
Definition audio.h:938
BGMPlayer * gBGMPlayerB
u16 unk_58
Definition audio.h:1019
s32 songPlayingCounter
Definition audio.h:1009
struct SeqArgs::@61 MasterPitchShift
u8 segLoopDepth
Definition audio.h:1055
SoundPlayChange changed
Definition audio.h:961
struct SeqArgs::@66 TrackOverridePatch
struct SeqArgs::@74 TrackTremolo
u8 * cmdListRelease
Definition audio.h:534
EnvelopeData envelope
Definition audio.h:721
s32 s32
Definition audio.h:361
u8 unk_211
Definition audio.h:1056
u16 instrumentCount
Definition audio.h:752
u8 tremoloTime
Definition audio.h:995
u8 unk_25A
Definition audio.h:1079
s32 songName
Definition audio.h:1010
u8 unk_258
Definition audio.h:1077
#define BGM_DEFAULT_TEMPO
Definition audio.h:53
s32 unkSongName
Definition audio.h:915
struct SeqArgs::@68 SubTrackPan
struct SeqArgs::@75 TrackTremoloSpeed
@ BGM_SEGMENT_START_LOOP
Definition audio.h:111
@ BGM_SEGMENT_6
Definition audio.h:114
@ BGM_SEGMENT_END_LOOP
Definition audio.h:113
@ BGM_SEGMENT_SUBSEG
Definition audio.h:110
@ BGM_SEGMENT_END
Definition audio.h:109
@ BGM_SEGMENT_7
Definition audio.h:115
@ BGM_SEGMENT_WAIT
Definition audio.h:112
s16 keyBase
Definition audio.h:765
struct SeqArgs::@71 SubTrackCoarseTune
#define NO_INSTRUMENT
Definition audio.h:17
BGMDrumInfo * drumsInfo
Definition audio.h:1029
struct SeqArgs::@70 SegTrackVolume
s32 nextUpdateInterval
Definition audio.h:1006
s32 songID
Definition audio.h:1013
AuGlobals * globals
Definition audio.h:1003
SoundManager90 bgmSounds[4]
Definition audio.h:676
u8 raw[4]
Definition audio.h:263
s32 unkVolumeStep
Definition audio.h:954
u8 proxMixID
Definition audio.h:1046
s32 randomValue1
Definition audio.h:1017
u8 unk_21E
Definition audio.h:1062
s32 unk_74
Definition audio.h:1028
s32 masterVolumeTarget
Definition audio.h:1038
struct SeqArgs::@73 SegTrackTune
u8 bgmDrumCount
Definition audio.h:1060
s32 nextUpdateCounter
Definition audio.h:1007
struct SeqArgs::@59 MasterTempo
u8 trackTremoloTime
Definition audio.h:978
u16 masterTempoBPM
Definition audio.h:1051
s32 masterTempo
Definition audio.h:1032
VolumeField volScale
Definition audio.h:375
#define AU_FILE_RELATIVE(base, offset)
Definition audio.h:40
SegData * subSegmentStartPos
Definition audio.h:1027
s16 unk_5A
Definition audio.h:1020
SeqNote notes[24]
Definition audio.h:1082
u8 unk_259
Definition audio.h:1078
s32 masterTempoStep
Definition audio.h:1033
BGMDrumInfo drums[12]
Definition audio.h:831
f32 pitchRatio
Definition audio.h:714
s16 volScaleTime
Definition audio.h:378
u8 effectIndices[4]
Definition audio.h:1016
s32 masterTempoTarget
Definition audio.h:1034
BGMInstrumentInfo * dataPRG
Definition audio.h:909
struct BGMPlayer * unk_74
Definition audio.h:913
struct SeqArgs::@69 SubTrackReverb
SeqArgs seqCmdArgs
Definition audio.h:1041
s32 unkFadeEnd
Definition audio.h:919
u8 polyphonicIdx
Definition audio.h:976
s32 subTrackVolumeStep
Definition audio.h:948
s16 unk_174[8][9]
Definition audio.h:1049
BGMFileInfo info
Definition audio.h:760
u16 drums
Definition audio.h:749
@ AU_VOICE_SYNC_FLAG_PAN_FXMIX
Definition audio.h:83
@ AU_VOICE_SYNC_FLAG_PITCH
Definition audio.h:82
@ AU_VOICE_SYNC_FLAG_ALL
Definition audio.h:80
u8 trackTremoloSpeed
Definition audio.h:977
u8 unk_222
Definition audio.h:1066
u16 segments[4]
Definition audio.h:748
s16 trackTremoloAmount
Definition audio.h:958
u8 randPan
Definition audio.h:771
BGMDrumInfo * drums[12]
Definition audio.h:1031
s32 subTrackVolume
Definition audio.h:947
u16 maxTempo
Definition audio.h:1052
s32 name
Definition audio.h:758
s16 bankPatch
Definition audio.h:764
@ BGM_PLAY_STATE_IDLE
Definition audio.h:101
@ BGM_PLAY_STATE_STOP
Definition audio.h:105
@ BGM_PLAY_STATE_NEXT_SUBSEG
Definition audio.h:103
@ BGM_STATE_PLAY_SUBSEG
Definition audio.h:102
@ BGM_PLAY_STATE_INIT
Definition audio.h:104
u8 * trackVolsConfig
Definition audio.h:1050
u16 subTrackCoarseTune
Definition audio.h:963
s32 masterTempoTime
Definition audio.h:1035
u8 unk_223
Definition audio.h:1067
u8 numSegments
Definition audio.h:746
s16 unkVolumeTime
Definition audio.h:956
s8 clientPriority
Definition audio.h:740
#define BGM_MAX_VOLUME
Definition audio.h:58
s32 nextUpdateStep
Definition audio.h:1005
s16 clientVolume
Definition audio.h:737
s32 unk_80
Definition audio.h:916
u8 unk_13
Definition audio.h:996
s16 fadeTime
Definition audio.h:369
u8 bgmInstrumentCount
Definition audio.h:1061
u8 unk_note_17
Definition audio.h:999
u8 noteVelocity
Definition audio.h:998
s16 detourLength
Definition audio.h:960
u8 pan
Definition audio.h:717
s32 delayTime
Definition audio.h:951
SegData * segmentReadPos
Definition audio.h:1025
u8 effectValues[4]
Definition audio.h:1068
s16 targetVolScale
Definition audio.h:377
s16 volume
Definition audio.h:991
u16 masterPitchShift
Definition audio.h:1053
u16 instruments
Definition audio.h:751
s32 subTrackVolumeTime
Definition audio.h:950
u8 unk_21B
Definition audio.h:1059
BGMPlayer * gBGMPlayerA
s32 masterVolume
Definition audio.h:1036
s16 adjustedPitch
Definition audio.h:992
struct SeqArgs::@67 SubTrackVolume
s32 masterVolumeTime
Definition audio.h:1039
u8 volume
Definition audio.h:766
u8 syncFlags
Definition audio.h:739
struct SeqArgs::@79 TrackVolumeFade
u16 u16
Definition audio.h:360
s32 busVolume
Definition audio.h:1015
#define SND_MIN_DURATION
Definition audio.h:55
#define BGM_SEGMENT_LABEL
Definition audio.h:60
u16 tremoloAmount
Definition audio.h:994
Fade fadeInfo
Definition audio.h:1014
u8 bFadeConfigSetsVolume
Definition audio.h:1071
s16 unkVolumeTarget
Definition audio.h:955
struct SeqArgs::@83 Detour
s32 updateCounter
Definition audio.h:1008
u8 channelDelayBusId
Definition audio.h:905
struct SeqArgs::@84 UnkCmdFF
AuFilePos savedPos
Definition audio.h:943
u8 channelDelaySide
Definition audio.h:907
s32 unkFadeStart
Definition audio.h:918
u8 parentTrackIdx
Definition audio.h:981
Instrument * instrument
Definition audio.h:713
s32 unk_238[8]
Definition audio.h:1076
struct BGMHeader * dataBGM[2]
Definition audio.h:910
s32 fadeSongName
Definition audio.h:1011
PEREntry * dataPER
Definition audio.h:908
u8 envelopeFlags
Definition audio.h:734
u8 unk_233
Definition audio.h:1072
BGMInstrumentInfo defaultPRGEntry
Definition audio.h:893
u8 unk_22A[8]
Definition audio.h:1070
struct BGMPlayer * unk_78
Definition audio.h:914
struct SeqArgs::@77 UnkCmdF4
s8 reverb
Definition audio.h:768
struct SeqArgs::@65 MasterEffect
s32 noteLength
Definition audio.h:993
u8 priority
Definition audio.h:1073
struct SeqArgs::@62 UnkCmdE3
#define SND_MAX_DURATION
Definition audio.h:56
s32 unkVolume
Definition audio.h:953
u8 reverb
Definition audio.h:718
s32 subTrackVolumeTarget
Definition audio.h:949
SegData * segActiveLoopEndPos[4]
Definition audio.h:1043
u16 keyBase
Definition audio.h:558
s32 masterVolumeStep
Definition audio.h:1037
EnvelopeData envelope
Definition audio.h:946
BGMPlayerTrack tracks[16]
Definition audio.h:1081
AuFilePos bgmReadPos
Definition audio.h:942
struct SeqArgs::@76 TrackTremoloTime
u8 segLoopCounters[4]
Definition audio.h:1044
#define AU_5750
Definition audio.h:22
SegData * segmentStartPos
Definition audio.h:1026
u8 randReverb
Definition audio.h:772
@ AU_PRIORITY_FREE
Definition audio.h:65
s16 segTrackTune
Definition audio.h:957
f32 pitchRatio
Definition audio.h:990
SndGlobalsSub6C unk_globals_6C[1]
Definition audio.h:912
u8 randTune
Definition audio.h:769
AuFilePos prevReadPos
Definition audio.h:944
AuEffectChange effectChanges[4]
Definition audio.h:903
u8 masterState
Definition audio.h:1065
s8 subTrackFineTune
Definition audio.h:964
f32 playbackRate
Definition audio.h:1040
u8 * AuFilePos
Definition audio.h:14
u8 busId
Definition audio.h:719
Instrument * ins
Definition audio.h:989
struct SeqArgs::@60 MasterVolume
@ AU_VOICE_ENV_FLAG_KEY_RELEASED
Definition audio.h:75
@ AU_VOICE_ENV_FLAG_VOL_CHANGED
Definition audio.h:76
SegData * segLoopStartLabels[32]
Definition audio.h:1042
s16 unk_14
Definition audio.h:997
u8 unk_220
Definition audio.h:1064
Instrument * instrument
Definition audio.h:945
struct SeqArgs::@81 Jump
u8 priority
Definition audio.h:741
u32 curSegmentID
Definition audio.h:1023
struct SeqArgs::@78 SetTrackVoice
u8 * cmdPtr
Definition audio.h:722
s16 targetVolume
Definition audio.h:368
s16 detune
Definition audio.h:1054
struct SeqArgs::@63 MasterTempoFade
u8 subTrackReverb
Definition audio.h:967
u8 channelDelayTime
Definition audio.h:906
struct SeqArgs::@72 SubTrackFineTune
s32 proxMixValue
Definition audio.h:1045
u8 proxMixVolume
Definition audio.h:1047
void N update(void)
Definition 07.c:80
Vec3s pos
Definition demo_api.c:17
AuResult
Definition enums.h:1755
@ AU_ERROR_NULL_SONG_NAME
Definition enums.h:1761
@ AU_ERROR_7
Definition enums.h:1765
@ AU_RESULT_OK
Definition enums.h:1756
@ AU_ERROR_6
Definition enums.h:1764
@ AU_ERROR_SONG_NOT_PLAYING
Definition enums.h:1759
@ AU_ERROR_INVALID_SONG_DURATION
Definition enums.h:1763
#define BSS
Definition macros.h:7
#define ARRAY_COUNT(arr)
Definition macros.h:40
#define A(sym)
Definition macros.h:36