13static void au_bgm_stop_player(
BGMPlayer* player);
15static s32 snd_bpm_to_tempo(
BGMPlayer* player, u32 tempo);
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);
41 for (var_a1 = 0; var_a1 < player->
unk_258; var_a1++) {
46 segmentID = value >> 2;
65 if (unkType != player->
unk_58) {
66 player->
unk_58 = unkType & 0xFF;
67 player->
unk_5A = unkType & 0xFF;
76 bgmData = &bgmFile->
info;
79 segmentOffset = bgmData->
segments[segmentID];
80 if (segmentOffset == 0) {
81 segmentOffset = bgmData->
segments[0];
86 if (bgmData->
drums != 0) {
91 player->
drums[i] = drum;
110 if (player->
unk_58 != 0) {
115 au_bgm_stop_player(player);
145 songName =
event->songName;
146 variation =
event->variation;
149 if (player != NULL) {
151 duration =
event->duration;
159 volume0 =
event->startVolume;
160 if (volume0 > 0x7F) {
164 volume0 = (volume0 << 8) | 0xFF;
166 volume1 =
event->finalVolume;
167 if (volume1 > 0x7F) {
171 volume1 = (volume1 << 8) | 0xFF;
181 if (variation < 0 || variation >= 4 || fileInfo->
segments[variation] == 0) {
189 if (fileInfo->
drums != 0) {
195 player->
drums[i] = drum;
228 if (player != NULL) {
230 au_bgm_stop_player(player);
247static void au_bgm_stop_player(
BGMPlayer* player) {
262 if (player != NULL) {
263 result = (songName == player->
songName);
293 if (player != NULL) {
341 variation =
update->variation;
346 if (playerA != NULL) {
349 if (playerB != NULL) {
350 if (songName == playerA->
songName) {
365 if (clearChanged == 0) {
366 au_bgm_stop_player(playerA);
373 if (songName == playerA->
songName) {
400 variation =
update->variation;
408 if (playerB != NULL) {
411 duration =
update->duration;
419 volume0 =
update->startVolume;
424 volume0 = (volume0 << 8) | 0xFF;
426 volume1 =
update->finalVolume;
431 volume1 = (volume1 << 8) | 0xFF;
453 if (playerB != NULL) {
454 if (songName == playerB->
songName) {
479 track = &player->
tracks[i];
482 note = &player->
notes[j];
503 if (
update->songName != 0) {
505 if (player != NULL) {
547 player->
busId = busId;
610 while (remaining-- != 0) {
624 if (player->
fadeInfo.onCompleteCallback != NULL) {
625 player->
fadeInfo.onCompleteCallback();
631 au_bgm_stop_player(player);
795 while (keepReading) {
809 u16* temp = player->
unk_174[arg1];
812 for (i = 0; i < 9; i++) {
821 A = 10434782 / (u32)divisor;
825 }
else if (
A < 80000) {
828 if (
A < sampleRate) {
839 u16 continueReading = TRUE;
844 while (continueReading) {
848 continueReading = FALSE;
854 continueReading = FALSE;
859 continueReading = FALSE;
875 continueReading = FALSE;
883 s32 labelIndex = cmd & 0x1F;
884 s32 iterCount = (cmd >> 5) & 0x7F;
903 }
else if (depth < 4) {
928 bUsesPolyphony = FALSE;
932 track = &player->
tracks[i];
933 trackInfo = *trackList++;
936 if ((trackInfo & 0x100) == 0) {
939 parentIdx = (trackInfo & (0xF << 9)) >> 9;
941 if (parentIdx != 0) {
943 if ((parentIdx - 1) < i) {
955 bUsesPolyphony = TRUE;
962 track->
unk_52 = nextRelativePos;
963 nextRelativePos += count;
964 track->
unk_53 = nextRelativePos;
974 player->
unk_21B = nextRelativePos;
975 if (bUsesPolyphony) {
996#define POST_BGM_READ() \
997if (track->detourLength != 0) {\
998 track->detourLength--;\
999 if (track->detourLength == 0) {\
1000 track->bgmReadPos = track->savedPos;\
1017 s32 bAcquiredVoiceIdx;
1024 bVolumeFading = FALSE;
1047 bVolumeFading = TRUE;
1054 while (lenLimit-- != 0) {
1059 track = &player->
tracks[i - 1];
1070 while (lenLimit-- != 0) {
1075 track = &player->
tracks[i - 1];
1088 track = &player->
tracks[i];
1121 if (opcode < 0x80) {
1131 if (opcode >= 0x78) {
1143 if (opcode < 0xD4) {
1144 notePitch = (opcode & 0x7F);
1149 if (!(noteLength < 0xC0)) {
1150 noteLength = (((u8)noteLength & ~0xC0) << 8) + *(track->
bgmReadPos++) + 0xC0;
1153 bAcquiredVoiceIdx = FALSE;
1154 if (track->
unk_5A == 0) {
1156 for (voiceIdx = sp1F; voiceIdx < track->
unk_53; voiceIdx++) {
1160 bAcquiredVoiceIdx = TRUE;
1165 if (!bAcquiredVoiceIdx) {
1168 for (voiceIdx = track->
unk_52; voiceIdx < track->
unk_53; voiceIdx++) {
1172 bAcquiredVoiceIdx = TRUE;
1177 if (!bAcquiredVoiceIdx) {
1178 for (voiceIdx = track->
unk_52; voiceIdx < track->
unk_53; voiceIdx++) {
1181 note = &player->
notes[voiceIdx];
1184 bAcquiredVoiceIdx = TRUE;
1191 if (!bAcquiredVoiceIdx) {
1192 s32 shortestLength = 0xFFFF;
1196 for (voice_it = track->
unk_52; voice_it < track->
unk_53; voice_it++) {
1199 curNote = &player->
notes[voice_it];
1204 voiceIdx = voice_it;
1205 bAcquiredVoiceIdx = TRUE;
1209 if (bAcquiredVoiceIdx) {
1216 voiceIdx = track->
unk_52;
1218 note = &player->
notes[voiceIdx];
1222 bAcquiredVoiceIdx = TRUE;
1227 if (bAcquiredVoiceIdx) {
1228 note = &player->
notes[voiceIdx];
1230 if (noteVelocity > 0) {
1237 if (notePitch < 72) {
1240 drumInfo = player->
drums[notePitch - 72];
1263 voice->
pan = au_bgm_get_random_pan(player, drumInfo->
pan, drumInfo->
randPan);
1265 voice->
pan = drumInfo->
pan;
1290 if (track->
unk_57 != 0) {
1297 if (track->
unk_4C != 0) {
1350 for (voiceIdx = track->
unk_52; voiceIdx < track->
unk_53; voiceIdx++) {
1351 if (track->
unk_5A == 0) {
1354 note = &player->
notes[voiceIdx];
1386 opcode = (note->
unk_13 << 2) + 3;
1387 temp_a2_4 = note->
unk_13 >> 6;
1389 if ((temp_a2_4 == 1) || (temp_a2_4 == 3)) {
1391 var_a1_5 = temp2 + 1;
1398 if ((temp_a2_4 == 2) || (temp_a2_4 == 3)) {
1399 var_a1_5 = -var_a1_5;
1442static const f32 padding[] = {0.0f};
1449 tempo = snd_bpm_to_tempo(player, bpm);
1457static s32 snd_bpm_to_tempo(
BGMPlayer* player, u32 tempo) {
1463 if (maxTempo < ret) {
1465 }
else if (ret == 0) {
1476 volume = volume << 0x18;
1500 if ((index < 4) && (busId < 0x80)) {
1527 volume = volume << 0x18;
1548 volume = volume << 0x18;
1560 volume = volume << 0x18;
1634 if (voiceIndex < 0x80) {
1635 if (voiceIndex < player->bgmInstrumentCount) {
1642 if (voiceIndex < 0x40) {
1650 volume = instrument->
volume & 0x7F;
1651 track->
patch = patch;
1661 track->
changed.all |= 0x10101;
1668 if ((index < 4) && (busId >= 0)) {
1703 if (track->
unk_4D != 0) {
1713 if (track->
unk_4E != 0) {
1742 temp_a3 = arg2 & 0xF;
1743 temp_a1 = ((arg2 >> 4) & 1) + 1;
1772 player->
unk_174[i][j] = (arg1 << 8) + arg2;
1800 if (track->
unk_4E != 0) {
1805 if (otherTrack->
unk_4F != 0) {
1810 if (otherTrack->
unk_50 != 0) {
1833static u8 au_bgm_get_random_pan(
BGMPlayer* player, u8 pan, u8 amplitude) {
1835 s32 tap7 = seed >> 7;
1836 s32 tap2 = seed >> 2;
1837 s32 parity = (tap7 + tap2) & 1;
1838 s32 lo = (seed >> 8) & 0x3F;
1839 s32 hi = (seed << 4) & 0xC0;
1840 s32 random = lo + hi;
1845 retPan = base + ((amplitude * random) >> 8);
1847 retPan = base - ((amplitude * random) >> 8);
1851 }
else if (retPan >= 0x80) {
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;
1867 s32 hi = (seed << 2) & 0xF0;
1868 s32 random = lo + hi;
1872 retVal = pitch + ((amplitude * 5 * random) >> 8);
1874 retVal = pitch - ((amplitude * 5 * random) >> 8);
1884static u8 au_bgm_get_random_vol(s32 seed, u8 volume, u8 amplitude) {
1885 s32 lo = (seed >> 8) & 0x1F;
1886 s32 hi = seed & 0xE0;
1887 s32 random = lo + hi;
1889 return volume * (0x8000 - amplitude * random);
1897static u8 au_bgm_get_random_reverb(s32 seed, u8 reverb, u8 amplitude) {
1898 s32 lo = (seed >> 7) & 7;
1899 s32 hi = (seed << 3) & 0xF8;
1900 s32 random = lo + hi;
1902 return reverb * (0x8000 - (amplitude * random));
1908 s32 changed = FALSE;
1909 u8 mixID = mix & 0xFF;
1912 if (songName != 0) {
1914 if ((player != NULL) && (player->
proxMixValue != mix)) {
1922 track = &player->
tracks[i];
1935 }
else if (rate < 0.25) {
1948 if (detune > 1200) {
1950 }
else if (detune < -2400) {
1974 target = (target << 8) | 0xFF;
1976 if (duration <= 0) {
1978 }
else if (duration > 1000) {
2010 s32 songName =
update->songName;
2011 s32 variation =
update->variation;
2014 if (songName != 0) {
2016 if (player != NULL) {
2018 track = &player->
tracks[i];
2022 if (variation != 0) {
2023 if (track->
unk_5A != 0) {
2026 for (j = parentTrack->
unk_52; j < parentTrack->
unk_53; j++) {
2041 if (track->
unk_5A == 0) {
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 *)
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 EnvelopeReleaseDefaultFast[]
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)
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)
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)
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 *)
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)
void bgm_trigger_music_event(s32 playerID, s32 trackIndex, s32 eventInfo)
struct SeqArgs::@80 SubTrackReverbType
BGMInstrumentInfo * instrumentsInfo
struct BGMHeader * bgmFile
struct SeqArgs::@64 MasterVolumeFade
SoundManager * soundManager
struct SeqArgs::@82 EventTrigger
struct SeqArgs::@61 MasterPitchShift
struct SeqArgs::@66 TrackOverridePatch
struct SeqArgs::@74 TrackTremolo
#define BGM_DEFAULT_TEMPO
struct SeqArgs::@68 SubTrackPan
struct SeqArgs::@75 TrackTremoloSpeed
struct SeqArgs::@71 SubTrackCoarseTune
struct SeqArgs::@70 SegTrackVolume
SoundManager90 bgmSounds[4]
struct SeqArgs::@73 SegTrackTune
struct SeqArgs::@59 MasterTempo
#define AU_FILE_RELATIVE(base, offset)
SegData * subSegmentStartPos
BGMInstrumentInfo * dataPRG
struct BGMPlayer * unk_74
struct SeqArgs::@69 SubTrackReverb
@ AU_VOICE_SYNC_FLAG_PAN_FXMIX
@ AU_VOICE_SYNC_FLAG_PITCH
@ BGM_PLAY_STATE_NEXT_SUBSEG
struct SeqArgs::@67 SubTrackVolume
struct SeqArgs::@79 TrackVolumeFade
#define BGM_SEGMENT_LABEL
struct SeqArgs::@83 Detour
struct SeqArgs::@84 UnkCmdFF
struct BGMHeader * dataBGM[2]
BGMInstrumentInfo defaultPRGEntry
struct BGMPlayer * unk_78
struct SeqArgs::@77 UnkCmdF4
struct SeqArgs::@65 MasterEffect
struct SeqArgs::@62 UnkCmdE3
SegData * segActiveLoopEndPos[4]
BGMPlayerTrack tracks[16]
struct SeqArgs::@76 TrackTremoloTime
SegData * segmentStartPos
SndGlobalsSub6C unk_globals_6C[1]
AuEffectChange effectChanges[4]
struct SeqArgs::@60 MasterVolume
@ AU_VOICE_ENV_FLAG_KEY_RELEASED
@ AU_VOICE_ENV_FLAG_VOL_CHANGED
SegData * segLoopStartLabels[32]
struct SeqArgs::@78 SetTrackVoice
struct SeqArgs::@63 MasterTempoFade
struct SeqArgs::@72 SubTrackFineTune
@ AU_ERROR_NULL_SONG_NAME
@ AU_ERROR_SONG_NOT_PLAYING
@ AU_ERROR_INVALID_SONG_DURATION