From b97b3483dc1f584e53661dba2bbb2b6551fee7ce Mon Sep 17 00:00:00 2001 From: Jeod <47716344+JeodC@users.noreply.github.com> Date: Mon, 3 Aug 2026 17:46:38 -0400 Subject: [PATCH] DECOMP: Documenting music related code https://gitlab.com/banjo.decomp/banjo-kazooie/-/commit/c845029ac185fd569348306a94da6535118ec342 --- include/core1/core1.h | 10 +- include/core1/music.h | 87 ++ include/core1/musicplayer.h | 53 ++ include/enums.h | 3 +- include/functions.h | 39 +- include/music.h | 35 - include/structs.h | 23 +- lib/ultralib/audio/csp_chanmode.c | 12 +- lib/ultralib/audio/csp_controlchange.c | 4 +- lib/ultralib/audio/csp_getchanstate.c | 3 +- src/MMM/minigame_organ.c | 8 +- src/TTC/ch/treasurehunt.c | 8 +- src/core1/audio_ambience.c | 64 +- src/core1/audio_instruments.c | 1006 ++++++++++++------------ src/core1/audio_manager.c | 6 +- src/core1/audio_soundplayer.c | 8 +- src/core1/graphics_thread.c | 7 +- src/core1/musicplayer.c | 707 +++++++++-------- src/core1/musicplayer.h | 7 - src/core1/n_audio/n_csplayer.c | 4 +- src/core2/anim/anim_bonetransform.c | 16 +- src/core2/ba/marker.c | 6 +- src/core2/ch/snacker.c | 2 +- src/core2/frame/rendermem.c | 2 +- src/core2/gc/zoombox.c | 6 +- src/core2/map/cutscene_skip.c | 4 +- src/core2/map/cutscene_triggers.c | 7 +- src/core2/map/exit.c | 2 +- src/core2/map/gsworld.c | 4 +- src/core2/quiz/game.c | 2 +- src/core2/sfx/instruments.c | 88 +-- src/core2/sfx/source.c | 20 +- src/core2/sfx/trackmanager.c | 4 +- src/core2/spline_pathfollow.c | 6 +- src/lair/ff_manager.c | 6 +- 35 files changed, 1183 insertions(+), 1086 deletions(-) create mode 100644 include/core1/music.h create mode 100644 include/core1/musicplayer.h delete mode 100644 include/music.h delete mode 100644 src/core1/musicplayer.h diff --git a/include/core1/core1.h b/include/core1/core1.h index bf301700d..cefee692d 100644 --- a/include/core1/core1.h +++ b/include/core1/core1.h @@ -15,6 +15,8 @@ #include "core1/mem.h" #include "core1/ml.h" #include "core1/mlmtx.h" +#include "core1/music.h" +#include "core1/musicplayer.h" #include "core1/pfsmanager.h" #include "core1/rarezip.h" #include "core1/sns.h" @@ -34,14 +36,10 @@ void* malloc(size_t size); void glcrc_calc_checksum(void *start, void *end, u32 checksum[2]); -void func_80250530(s32 arg0, u16 chan_mask, f32 arg2); - void func_8025A104(enum comusic_e arg0, s32 arg1); void func_8025A55C(s32 arg0, s32 arg1, s32 arg2); s32 func_8025A864(enum comusic_e track_id); -void func_8025ABB8(enum comusic_e comusic_id, s32 arg1, s32 arg2, s32 arg3); -int func_8025AD7C(enum comusic_e arg0); -int func_8025ADBC(enum comusic_e arg0); +void func_8025ABB8(enum comusic_e track_id, s32 arg1, s32 arg2, s32 arg3); void piMgr_read(void *vaddr, s32 devaddr, s32 size); @@ -120,7 +118,7 @@ void core1_7090_freeSfxSource(int idx); /* src/core1/code_CE60.c */ void core1_ce60_setChanMask(s32 chan_mask); -void core1_ce60_setChanMaskWithValue(s32 chan_mask, f32 arg1); +void core1_ce60_setChanMaskWithTransitionSpeed(s32 chan_mask, f32 transition_speed); bool core1_ce60_isPlayerInRange(s32 x, s32 z, s32 distance); f32 core1_ce60_getPlayerDistance(f32 x, f32 z); bool core1_ce60_isPlayerInsideBoundingBox(s32 box_idx); diff --git a/include/core1/music.h b/include/core1/music.h new file mode 100644 index 000000000..d4cd03283 --- /dev/null +++ b/include/core1/music.h @@ -0,0 +1,87 @@ +#ifndef MUSIC_H +#define MUSIC_H + +#include +#include "bool.h" +#include "enums.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#include // [port] inside extern "C" so n_audio decls keep C linkage in C++ TUs + +#define NUM_CHANNEL_TEMPO_STATES 32 + +typedef struct chan_tempo_state_s { + s32 slot_id; + s32 chan; + f32 tempo; + f32 change_step; + f32 target_tempo; +} ChanTempoState; + +typedef struct midi_bin_s { + u8 pad[1]; // Fake struct, contains compressed MIDI data of arbitrary size +} MidiBin; + +typedef struct music_slot_s { + s16 volume; + u8 unk2; + u8 unk3; + ALCSeq cseq; + ALCSPlayer cseqp; + s16 track_id; // enum comusic_e + s16 index_cpy; + f32 unk17C; + f32 unk180; + u8 unk184[14]; + u8 unk192[14]; +} MusicSlot; + +typedef struct music_track_meta_s { + char *name; + u16 volume; +} MusicTrackMeta; + +void musicInstruments_init(void); +ALBank *musicInstruments_getSoundBank(void); +void musicTrack_load(enum comusic_e track_id); +void musicTrack_release(enum comusic_e track_id); +void musicTrack_releaseAll(void); +void musicSlot_loadTrack(u8 index, enum comusic_e track_id); +enum comusic_e musicSlot_getTrack(u8 index); +void musicSlot_func_8024FA98(u8 index, enum comusic_e track_id); +s32 musicSlot_getSlotSeqpState(u8 index); +void musicSlot_stopAll(void); +void musicSlot_func_8024FC1C(u8 index, enum comusic_e track_id); +void musicSlot_func_8024FC6C(u8 index); +void musicSlot_func_8024FCE0(u8 index, s16 volume); +void musicSlot_setVolume(u8 index, s16 volume); +void musicSlot_setTempo(u8 index, s32 tempo); +void musicSlot_func_8024FE44(u8 index, f32 arg1, f32 arg2); +s32 musicSlot_getCSeqTicks(u8 index); +void func_8024FF34(void); +s32 gcMusic_getDefaultVolumeForTrack(enum comusic_e track_id); +void gcMusic_setDefaultVolumeForTrack(enum comusic_e track_id, u16 volume); +char *gcMusic_getNameForTrack(enum comusic_e track_id); +bool musicSlot_hasStopped(u8 index); +s32 gcMusic_getAssetCount(void); +N_ALCSPlayer *musicSlot_getCSeqp(s32 index); +void musicSlot_func_802500F4(s32 index); +void musicSlot_func_802500FC(s32 index); +void musicSlot_func_80250104(ALCSeq *cseq, s32 arg1, s32 chan); +void musicSlot_func_80250170(u8 index, s32 arg1, s32 arg2); +s32 musicSlot_func_802501A0(u8 index, s32 arg1, s32 *chan); +void musicSlot_setChannelTempoChange(s32 index, s16 chan, s16 target_tempo, f32 transition_speed); +void musicSlot_setTempoChange(s32 index, s32 target_tempo, f32 transition_speed); +u16 musicSlot_func_80250474(s32 index); +void musicSlot_stepToChannelMask(s32 index, u16 chan_mask, f32 transition_speed); +void musicSlot_stepToTempo(s32 index, s32 target_tempo, f32 transition_speed); +void func_80250650(void); // n_audio ?? + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/core1/musicplayer.h b/include/core1/musicplayer.h new file mode 100644 index 000000000..241d8b42f --- /dev/null +++ b/include/core1/musicplayer.h @@ -0,0 +1,53 @@ +#ifndef BANJO_KAZOOIE_CORE1_MUSICPLAYER_H +#define BANJO_KAZOOIE_CORE1_MUSICPLAYER_H + +#include +#include "bool.h" +#include "enums.h" +#include "core2/fla.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define NUM_MUSIC_SLOTS 6 + + + +typedef struct struct_12_s{ + s32 volume_1; // volume 1 + s32 volume_2; // volume 2 +} struct12s; + +typedef struct comusic_s { + f32 volume_change_wait_timer; + f32 unk4; + s32 volume; + s32 destination_volume; + s16 track_id; //trackId + s16 volume_change; + u8 unk14; + u8 unk15; + u8 pad16[0x2]; + FREE_LIST(struct12s) *unk18; + s32 unk1C[0xE]; +} CoMusic; + +CoMusic *comusic_findTrack(enum comusic_e track_id); + +void coMusicPlayer_init(void); +void coMusicPlayer_free(void); +s32 coMusicPlayer_getTrackCount(void); +void coMusicPlayer_update(void); + + +bool comusic_isTrackQueued(enum comusic_e track_id); +bool comusic_isPrimaryTrack(enum comusic_e track_id); +s32 comusic_getTrackPosition(enum comusic_e track_id); +void comusic_defrag(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/enums.h b/include/enums.h index 02b9f532a..af2cd130e 100644 --- a/include/enums.h +++ b/include/enums.h @@ -870,7 +870,8 @@ enum comusic_e COMUSIC_A9_TOOTY = 0xA9, COMUSIC_AA_BEACH = 0xAA, JINGLE_JINJOATOR_FINAL_HIT, - COMUSIC_AC_GOOD_ENDING = 0xAC + COMUSIC_AC_GOOD_ENDING = 0xAC, + COMUSIC_NUM_TRACKS }; // SFXR_ = Repeating SFX diff --git a/include/functions.h b/include/functions.h index 531d6728e..e4a00360e 100644 --- a/include/functions.h +++ b/include/functions.h @@ -622,7 +622,7 @@ void func_80353580(ActorMarker *marker); void func_8025A58C(u32 arg0, u32 arg1); void func_8025AABC(enum comusic_e track_id); void func_8025AEA0(enum comusic_e track_id, s32 arg1); -void comusic_8025AB44(enum comusic_e comusic_id, s32 arg1, s32 arg2); +void comusic_8025AB44(enum comusic_e track_id, s32 arg1, s32 arg2); void comusic_playTrack(enum comusic_e); void coMusicPlayer_playMusic(enum comusic_e, s32); @@ -962,26 +962,11 @@ void maCastle_release(void); void maCastle_update(void); // --- core1/audio_instruments.c --- -s32 gcMusic_getDefaultVolumeForTrack(s32 track_id); -s32 func_802501A0(u8 arg0, s32 arg1, s32 *arg2); -void func_8024F764(s32 arg0); -void func_8024F7C4(s32 arg0); -void func_8024F83C(void); -void func_8024FB8C(void); -s32 func_8024FEEC(u8 arg0); -void func_8024FF34(void); -void func_80250170(u8 arg0, s32 arg1, s32 arg2); -void func_80250650(void); -void musicInstruments_init(void); +// (see include/core1/music.h) // --- core1/musicplayer.c --- int func_8025AEEC(void); -s32 coMusicPlayer_getTrackCount(void); -s32 func_8025ADD4(enum comusic_e id); -void coMusicPlayer_free(void); -void coMusicPlayer_init(void); -void comusic_defrag(void); -void func_8025A23C(s32 arg0); +void func_8025A23C(enum comusic_e track_id); void func_8025A2B0(void); void func_8025A2D8(void); void func_8025A2FC(s32 arg0, s32 arg1); @@ -1250,7 +1235,7 @@ void assetCache_init(void); void assetcache_update_ptr(void * arg0, void* arg1); void func_8033B5FC(void); void func_8033B61C(void); -void func_8033B788(void); +void assetcache_func_8033B788(void); void func_8033BD6C(void); bool func_8033BD8C(void* arg0); @@ -1296,12 +1281,12 @@ void anSeq_update(void **ppAnSeq, AnimCtrl *pAnCtl); // --- core2/sfx/instruments.c --- bool func_803354EC(enum sfx_e sfx_id); -bool func_80335520(s32 arg0); -intptr_t func_8033531C(enum sfx_e uid, struct46s *arg1); -intptr_t func_80335354(int uid, struct46s *arg1); -void func_803353BC(intptr_t arg0, u16 arg1); -void func_803353F4(intptr_t arg0, s32 arg1); -void func_80335418(intptr_t arg0, s32 arg1); +bool func_80335520(enum sfx_e sfx_id); +intptr_t sfxInstruments_func_8033531C(enum sfx_e sfx_id, struct46s *arg1); +intptr_t sfxInstruments_func_80335354(enum sfx_e sfx_id, struct46s *arg1); +void sfxInstruments_func_803353BC(intptr_t arg0, u16 arg1); +void sfxInstruments_func_803353F4(intptr_t arg0, s32 arg1); +void sfxInstruments_func_80335418(intptr_t arg0, s32 arg1); void sfxInstruments_init(void); // --- core2/ba/anim.c --- @@ -1795,7 +1780,7 @@ void ncCamera_update(void); // --- core2/sfx/trackmanager.c --- int func_80322914(void); -s32 func_803226E8(enum map_e map_id); +s32 core2_9B650_getMusicTrackFromMap(enum map_e map_id); s32 func_8032274C(void); s32 func_80322758(void); void func_80322764(void); @@ -3118,7 +3103,7 @@ void func_8029BC60(enum asset_e *anim_id, f32 *anim_duration); s32 func_802E4AD4(s32 arg0); // --- core2/sfx/instruments.c --- -void func_8033543C(Struct81s *arg0); +void sfxInstruments_func_8033543C(Struct81s *arg0); // --- core2/fx/projectile_system.c --- void func_8033F7F0(u8 indx, Gfx **gfx, Mtx **mtx, Vtx **vtx); diff --git a/include/music.h b/include/music.h deleted file mode 100644 index 15cd76970..000000000 --- a/include/music.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef MUSIC_H -#define MUSIC_H -#include -#include "structs.h" -#include - -typedef struct struct_B_s{ - s32 unk0; - s32 chan; - f32 unk8; - f32 unkC; - f32 unk10; -} structBs; - -typedef struct music_track_s{ - s16 unk0; - u8 unk2; - u8 unk3; - ALCSeq cseq; - ALCSPlayer cseqp; - s16 index; - s16 index_cpy; - f32 unk17C; - f32 unk180; - u8 unk184[0xE]; - u8 unk192[0xE]; -} MusicTrack; - -typedef struct music_track_meta_s{ - char *name; - u16 volume; - // u8 pad6[2]; -}MusicTrackMeta; - -#endif diff --git a/include/structs.h b/include/structs.h index ce50d76ab..cb62f6802 100644 --- a/include/structs.h +++ b/include/structs.h @@ -240,25 +240,6 @@ typedef struct struct_8_s{ f32 unk60; }struct8s; -typedef struct struct_11_s{ - f32 unk0; - f32 unk4; - s32 volume; - s32 unkC; - s16 track_id; //trackId - s16 unk12; - u8 unk14; - u8 unk15; - u8 pad16[0x2]; - FREE_LIST(struct12s) *unk18; - s32 unk1C[0xE]; -} CoMusic; - -typedef struct struct_12_s{ - s32 unk0; - s32 unk1; -} struct12s; - typedef struct dialog_s { s32 cmd; u8* str; @@ -795,8 +776,8 @@ typedef struct{ typedef struct { s32 unk0; //sound state cnt s32 unk4; - s32 unk8; //maxSounds - struct ALHeap *unkC; //heap + s32 max_sounds; + struct ALHeap *heap; u16 unk10; }Struct87s; #ifdef __cplusplus diff --git a/lib/ultralib/audio/csp_chanmode.c b/lib/ultralib/audio/csp_chanmode.c index 7bd9f82d6..8acd90cd3 100644 --- a/lib/ultralib/audio/csp_chanmode.c +++ b/lib/ultralib/audio/csp_chanmode.c @@ -1,24 +1,24 @@ #include #include "n_synth.h" -void func_8025F5C0(N_ALSeqPlayer *arg0, u8 arg1){ +void func_8025F5C0(N_ALCSPlayer *seqp, u8 chan) { ALEvent evt; evt.type = AL_SEQP_MIDI_EVT; evt.msg.midi.ticks = 0; evt.msg.midi.status = AL_MIDI_ChannelModeSelect; evt.msg.midi.byte1 = 0x7E; - evt.msg.midi.byte2 = arg1; - alEvtqPostEvent(&arg0->evtq, &evt, 0); + evt.msg.midi.byte2 = chan; + alEvtqPostEvent(&seqp->evtq, &evt, 0); } -void func_8025F570(N_ALSeqPlayer *arg0, u8 arg1){ +void func_8025F570(N_ALCSPlayer *seqp, u8 chan) { ALEvent evt; evt.type = AL_SEQP_MIDI_EVT; evt.msg.midi.ticks = 0; evt.msg.midi.status = AL_MIDI_ChannelModeSelect; evt.msg.midi.byte1 = 0x7F; - evt.msg.midi.byte2 = arg1; - alEvtqPostEvent(&arg0->evtq, &evt, 0); + evt.msg.midi.byte2 = chan; + alEvtqPostEvent(&seqp->evtq, &evt, 0); } \ No newline at end of file diff --git a/lib/ultralib/audio/csp_controlchange.c b/lib/ultralib/audio/csp_controlchange.c index 72621d94c..beeac18ce 100644 --- a/lib/ultralib/audio/csp_controlchange.c +++ b/lib/ultralib/audio/csp_controlchange.c @@ -3,7 +3,7 @@ #include "variables.h" #include // [port] N64 SDK audio library - stubbed for PC port -void func_8025F510(ALCSPlayer *seqp, u8 chan, u8 arg2) +void func_8025F510(ALCSPlayer *seqp, u8 chan, u8 tempo) { ALEvent evt; @@ -11,7 +11,7 @@ void func_8025F510(ALCSPlayer *seqp, u8 chan, u8 arg2) evt.msg.midi.ticks = 0; evt.msg.midi.status = AL_MIDI_ControlChange | chan; evt.msg.midi.byte1 = 0x7D; - evt.msg.midi.byte2 = arg2; + evt.msg.midi.byte2 = tempo; alEvtqPostEvent(&seqp->evtq, &evt, 0); } \ No newline at end of file diff --git a/lib/ultralib/audio/csp_getchanstate.c b/lib/ultralib/audio/csp_getchanstate.c index 1a6806ce7..6c7495914 100644 --- a/lib/ultralib/audio/csp_getchanstate.c +++ b/lib/ultralib/audio/csp_getchanstate.c @@ -3,7 +3,6 @@ #include "variables.h" #include "n_synth.h" -u8 func_8025F4A0(N_ALCSPlayer *seqp, u8 chan) -{ +u8 func_8025F4A0(N_ALCSPlayer *seqp, u8 chan) { return seqp->chanState[chan].unkA; } \ No newline at end of file diff --git a/src/MMM/minigame_organ.c b/src/MMM/minigame_organ.c index 7333e0340..fdd745bb9 100644 --- a/src/MMM/minigame_organ.c +++ b/src/MMM/minigame_organ.c @@ -317,7 +317,7 @@ void code3420_handleOrganGame(s32 arg0, s32 arg1) { bool is_black_key; Me.unk8 = D_8038BF20; - func_80250170(0, 0x6A, 0); + musicSlot_func_80250170(0, 0x6A, 0); Me.state = 0; if ((gsworld_getMap() == MAP_1C_MMM_CHURCH) && (arg1 == 2)) { @@ -358,7 +358,7 @@ void code3420_handleOrganGame(s32 arg0, s32 arg1) { void maOrgan_update(void){ - UNK_TYPE(u32) sp4C; + s32 chan; f32 motzhand_dist; Actor *motzhand; f32 sp38[3]; @@ -369,8 +369,8 @@ void maOrgan_update(void){ return; } - if(func_802501A0(0, 0x6A, &sp4C)){ - func_80250170(0, 0x6A, 0); + if(musicSlot_func_802501A0(0, 0x6A, &chan)){ + musicSlot_func_80250170(0, 0x6A, 0); Me.unk8++; if(Me.unk8->unk4 == -1){ Me.unk8 = &D_8038BF20[10]; diff --git a/src/TTC/ch/treasurehunt.c b/src/TTC/ch/treasurehunt.c index ca861780c..f74edd024 100644 --- a/src/TTC/ch/treasurehunt.c +++ b/src/TTC/ch/treasurehunt.c @@ -76,17 +76,17 @@ ParticleSettingsVelocityPosition CH_TREASUREHUNT_VELOCITY_RANGES = { /* .code */ static bool __chTreasurehunt_isActiveHitboxBeakBusterHitbox(void) { - enum comusic_e comusic_id; + enum comusic_e track_id; s32 music_volume; if (player_getActiveHitbox(0) == HITBOX_1_BEAK_BUSTER) { - comusic_id = COMUSIC_2B_DING_B; + track_id = COMUSIC_2B_DING_B; music_volume = 28000; if (chtreasureHunt_puzzleCurrentStep == 5) { - comusic_id = COMUSIC_2D_PUZZLE_SOLVED_FANFARE; + track_id = COMUSIC_2D_PUZZLE_SOLVED_FANFARE; music_volume = 0x7FFF; } - coMusicPlayer_playMusic(comusic_id, music_volume); + coMusicPlayer_playMusic(track_id, music_volume); return true; } return false; diff --git a/src/core1/audio_ambience.c b/src/core1/audio_ambience.c index 4e1ae3956..278b2d4cb 100644 --- a/src/core1/audio_ambience.c +++ b/src/core1/audio_ambience.c @@ -30,14 +30,14 @@ static BoundingBox sBoundingBoxes[] = { static s32 sUnusedCounter; // is only incremented and decremented, but not used static bool D_802806F4; static s32 sPlayerPosition[4]; -static enum comusic_e sTrackId[4]; +static enum comusic_e sTrackId[4]; // 0 - enum comusic_e, 1 - enum comusic_e, 2 - s32 volume for [0], 3 - s32 volume for [1] void core1_ce60_setChanMask(s32 chan_mask) { - func_80250530(0, chan_mask, 3.0f); + musicSlot_stepToChannelMask(0, chan_mask, 3.0f); } -void core1_ce60_setChanMaskWithValue(s32 chan_mask, f32 value) { - func_80250530(0, chan_mask, value); +void core1_ce60_setChanMaskWithTransitionSpeed(s32 chan_mask, f32 transition_speed) { + musicSlot_stepToChannelMask(0, chan_mask, transition_speed); } bool core1_ce60_isPlayerInRange(s32 x, s32 z, s32 distance) { @@ -56,13 +56,13 @@ bool core1_ce60_isPlayerInsideBoundingBox(s32 box_idx) { } void core1_ce60_func_8024A9EC(s32 arg0) { - if (!func_8025ADBC(sTrackId[0]) && sTrackId[2]) { + if (!comusic_isPrimaryTrack(sTrackId[0]) && sTrackId[2]) { func_8025A104(sTrackId[0], 0); } func_8025A55C(sTrackId[2], arg0 ? arg0 : 0x1f4, 4); - if (func_8025AD7C(sTrackId[1]) || sTrackId[3]) { + if (comusic_isTrackQueued(sTrackId[1]) || sTrackId[3]) { func_8025ABB8(sTrackId[1], sTrackId[3], arg0 ? arg0 : 0x1f4, 4 ); } @@ -78,7 +78,7 @@ void core1_ce60_func_8024AAB0(void) { sTrackId[0] = func_8032274C(); sTrackId[1] = func_80322758(); - sTrackId[2] = sTrackId[3] = COMUSIC_0_DING_A; + sTrackId[2] = sTrackId[3] = 0; if (0 <= sTrackId[0]) sTrackId[2] = gcMusic_getDefaultVolumeForTrack(sTrackId[0]); @@ -100,17 +100,17 @@ void core1_ce60_func_8024AAB0(void) { case MAP_1_SM_SPIRAL_MOUNTAIN: if (core1_ce60_isPlayerInsideBoundingBox(4)) { - sTrackId[2] = COMUSIC_0_DING_A; + sTrackId[2] = 0; } else { - sTrackId[3] = COMUSIC_0_DING_A; + sTrackId[3] = 0; } break; case MAP_1B_MMM_MAD_MONSTER_MANSION: if (func_80309D58(player_position, 1)) { - sTrackId[2] = COMUSIC_0_DING_A; + sTrackId[2] = 0; } else { - sTrackId[3] = COMUSIC_0_DING_A; + sTrackId[3] = 0; } break; @@ -118,34 +118,34 @@ void core1_ce60_func_8024AAB0(void) { if (jiggyscore_isCollected(JIGGY_2E_FP_PRESENTS) || (levelSpecificFlags_get(LEVEL_FLAG_11_FP_UNKNOWN) && levelSpecificFlags_get(LEVEL_FLAG_12_FP_UNKNOWN) && levelSpecificFlags_get(LEVEL_FLAG_13_FP_UNKNOWN))) { - sTrackId[2] = COMUSIC_0_DING_A; + sTrackId[2] = 0; } else { - sTrackId[3] = COMUSIC_0_DING_A; + sTrackId[3] = 0; } break; case MAP_1D_MMM_CELLAR: if (sns_get_item_state(SNS_ITEM_EGG_CYAN, 1) && sPlayerPosition[0] >= 0x23A) { - sTrackId[2] = COMUSIC_0_DING_A; + sTrackId[2] = 0; } else { - sTrackId[3] = COMUSIC_0_DING_A; + sTrackId[3] = 0; } break; case MAP_7F_FP_WOZZAS_CAVE: if (sns_get_item_state(SNS_ITEM_ICE_KEY, 1) && core1_ce60_isPlayerInRange(0x619, 0x97a, 0x69a)) { - sTrackId[2] = COMUSIC_0_DING_A; + sTrackId[2] = 0; } else { - sTrackId[3] = COMUSIC_0_DING_A; + sTrackId[3] = 0; } break; case MAP_45_CCW_AUTUMN: case MAP_46_CCW_WINTER: if (core1_ce60_isPlayerInsideBoundingBox(5)) { - sTrackId[2] = COMUSIC_0_DING_A; + sTrackId[2] = 0; } else { - sTrackId[3] = COMUSIC_0_DING_A; + sTrackId[3] = 0; } break; } @@ -237,9 +237,9 @@ void core1_ce60_func_8024AF48(void) { if (player_getWaterState() == BSWATERGROUP_2_UNDERWATER) { if(!(sPlayerPosition[1] < 651)) { - core1_ce60_setChanMaskWithValue(0x8180, 5.0f); + core1_ce60_setChanMaskWithTransitionSpeed(0x8180, 5.0f); } else { - core1_ce60_setChanMaskWithValue(0x3e00, 5.0f); + core1_ce60_setChanMaskWithTransitionSpeed(0x3e00, 5.0f); } } else { core1_ce60_setChanMask(0x407f); @@ -296,7 +296,7 @@ void core1_ce60_func_8024AF48(void) { break; case MAP_1B_MMM_MAD_MONSTER_MANSION: - if (!mapSpecificFlags_get(1) && !func_8025AD7C(COMUSIC_4_MMM_CLOCK_VERSION) && !func_8025AD7C(COMUSIC_3C_MINIGAME_LOSS)) { + if (!mapSpecificFlags_get(1) && !comusic_isTrackQueued(COMUSIC_4_MMM_CLOCK_VERSION) && !comusic_isTrackQueued(COMUSIC_3C_MINIGAME_LOSS)) { core1_ce60_func_8024A9EC(0); } @@ -305,9 +305,9 @@ void core1_ce60_func_8024AF48(void) { case MAP_D_BGS_BUBBLEGLOOP_SWAMP: if (core1_ce60_isPlayerInRange(1890, -1346, 1400) || core1_ce60_isPlayerInRange(-133, 2008, 900) || core1_ce60_isPlayerInRange(-3629, -535, 1400)) { - core1_ce60_setChanMaskWithValue(0x2f4f, 2.0f); + core1_ce60_setChanMaskWithTransitionSpeed(0x2f4f, 2.0f); } else { - core1_ce60_setChanMaskWithValue(0x6f4f, 2.0f); + core1_ce60_setChanMaskWithTransitionSpeed(0x6f4f, 2.0f); } break; @@ -329,15 +329,15 @@ void core1_ce60_func_8024AF48(void) { case MAP_40_CCW_HUB: if (core1_ce60_isPlayerInRange(0, 0, 2050)) { - core1_ce60_setChanMaskWithValue(7, 2.0f); + core1_ce60_setChanMaskWithTransitionSpeed(7, 2.0f); } else if (1450 <= sPlayerPosition[2]){ - core1_ce60_setChanMaskWithValue(0x407, 2.0f); + core1_ce60_setChanMaskWithTransitionSpeed(0x407, 2.0f); } else if (sPlayerPosition[0] < -1449) { - core1_ce60_setChanMaskWithValue(0x707, 2.0f); + core1_ce60_setChanMaskWithTransitionSpeed(0x707, 2.0f); } else if (sPlayerPosition[2] < -1449) { - core1_ce60_setChanMaskWithValue(0x1067, 2.0f); + core1_ce60_setChanMaskWithTransitionSpeed(0x1067, 2.0f); } else if (1450 <= sPlayerPosition[0]) { - core1_ce60_setChanMaskWithValue(0x7007, 2.0f); + core1_ce60_setChanMaskWithTransitionSpeed(0x7007, 2.0f); } break; @@ -590,14 +590,14 @@ void core1_ce60_func_8024AF48(void) { case MAP_91_FILE_SELECT: if (!gameSelect_getGameNumber()) { - core1_ce60_setChanMaskWithValue(0x200, 0.5f); + core1_ce60_setChanMaskWithTransitionSpeed(0x200, 0.5f); } else { - core1_ce60_setChanMaskWithValue(0x1ff, 0.5f); + core1_ce60_setChanMaskWithTransitionSpeed(0x1ff, 0.5f); } break; case MAP_8C_SM_BANJOS_HOUSE: - core1_ce60_setChanMaskWithValue(0x1ff, 0.5f); + core1_ce60_setChanMaskWithTransitionSpeed(0x1ff, 0.5f); break; case MAP_1D_MMM_CELLAR: diff --git a/src/core1/audio_instruments.c b/src/core1/audio_instruments.c index b7830b253..13998f6fe 100644 --- a/src/core1/audio_instruments.c +++ b/src/core1/audio_instruments.c @@ -1,704 +1,702 @@ // BanjoDecomp: code_11AC0.c #include +#include #include "core1/core1.h" +#include "core1/music.h" #include "functions.h" #include "variables.h" #include "port/ShipUtils.h" // gPortResetPending - -#include "music.h" -#include - #include "version.h" #include #include "port/Patches/Patches.h" -extern void func_8025F570(ALCSPlayer *, u8); -extern void func_8025F510(ALCSPlayer *, u8, u8); -extern void func_8025F5C0(ALCSPlayer *, u8); +#if VERSION == VERSION_USA_1_0 +#define MUSIC_TRACK_ASSET_BASE_ID 0x1516 +#elif VERSION == VERSION_PAL +#define MUSIC_TRACK_ASSET_BASE_ID 0xD74 +#else +#define MUSIC_TRACK_ASSET_BASE_ID 0 +#endif + +u8 func_8025F4A0(N_ALCSPlayer *seqp, u8 chan); // n_audio, get channel tempo +void func_8025F5C0(N_ALCSPlayer *seqp, u8 chan); // n_audio +void func_8025F570(N_ALCSPlayer *seqp, u8 chan); // n_audio +void func_8025F3F0(ALCSPlayer *, f32, f32); // audio +void func_8025F510(ALCSPlayer *seqp, u8 chan, u8 tempo); // audio, alCSPSetTempo for channel extern u8 *soundfont2ctl_ROM_START; extern u8 *soundfont2ctl_ROM_END; extern u8 *soundfont2tbl_ROM_START; -/* dependent functions */ -void func_8024FA98(u8, s32); -void musicTrack_setVolume(u8, s16); -int func_80250074(u8); -u8 func_8025F4A0(ALCSPlayer *, u8); - -void func_8025F3F0(ALCSPlayer *, f32, f32); -u16 func_80250474(s32 arg0); -void func_8024FB8C(void); - -/* .data */ -MusicTrackMeta D_80275D40[0xB0] = { - {"Blank", 15000}, - {"Scrap", 15000}, - {"Jungle 2", 20000}, - {"Snow 2", 20000}, - {"Bells", 21000}, - {"Beach", 20000}, - {"Swamp", 15000}, - {"Crab Cave", 20000}, - {"Title", 15000}, - {"Notes", 15000}, - {"Jinjo", 15000}, - {"Feather", 15000}, - {"Egg", 15000}, - {"Jigpiece", 28000}, - {"Sky", 0x7FFF}, - {"Spooky", 21000}, - {"Training", 15000}, - {"Lighthouse", 24000}, - {"Crab", 15000}, - {"Shell", 0x7FFF}, - {"Feather Inv", 15000}, - {"Extra life", 15000}, - {"Honeycomb", 15000}, - {"Empty honey piece", 15000}, - {"Extra honey", 15000}, - {"Mystery", 15000}, - {"You lose", 20000}, - {"Termite nest", 0x7FFF}, - {"Outside whale", 15000}, - {"Spell", 15000}, - {"Witch House", 23000}, - {"In whale", 0x4650}, - {"Desert", 20000}, - {"In spooky", 0x4650}, - {"Grave", 24000}, - {"Church", 28000}, - {"Sphinx", 20000}, - {"Invulnerabilty", 28000}, - {"Collapse", 15000}, - {"Snake", 15000}, - {"Sandcastle", 15000}, - {"Summer", 20000}, - {"Winter", 0x6978}, - {"Right", 28000}, - {"Wrong", 0x7D00}, - {"Achieve", 0x7D00}, - {"Autumn", 0x55F0}, - {"Default forest", 0x7530}, - {"5 Jinjos", 15000}, - {"Game over", 15000}, - {"Nintendo", 15000}, - {"Ship", 24000}, - {"Shark", 15000}, - {"Ship inside", 24000}, - {"100 Notes", 15000}, - {"Door Open", 15000}, - {"Organ sequence", 0x4650}, - {"Advent", 15000}, - {"Slalom", 15000}, - {"Race win", 15000}, - {"Race lose", 15000}, - {"Jigsaw magic", 15000}, - {"Oh dear", 15000}, - {"Up", 15000}, - {"Down", 15000}, - {"Shamen Hut", 0x4A38}, - {"Jig 10", 0x61A8}, - {"Carpet", 15000}, - {"Squirrel", 15000}, - {"Hornet", 15000}, - {"Treetop", 0x7D00}, - {"Turtle Shell", 0x61A8}, - {"House Summer", 15000}, - {"House Autumn", 15000}, - {"Out Buildings", 15000}, - {"Hornet 2", 15000}, - {"Cabins", 15000}, - {"Rain", 15000}, - {"Jigsaw Open", 15000}, - {"Jigsaw Close", 15000}, - {"Witch 1", 23000}, - {"Witch 2", 23000}, - {"Witch 3", 23000}, - {"Witch 4", 23000}, - {"Witch 5", 23000}, - {"Mr Vile", 15000}, - {"Bridge", 0x55F0}, - {"Turbo Talon Trot", 28000}, - {"Long legs", 28000}, - {"Witch 6", 23000}, - {"Boggy sad", 15000}, - {"Boggy happy", 15000}, - {"Quit", 15000}, - {"Witch 7", 23000}, - {"Witch 8", 23000}, - {"Spring", 0x4650}, - {"Squirrel attic", 0x6590}, - {"Lights", 15000}, - {"Box", 0x4268}, - {"Witch 9", 23000}, - {"Open up", 15000}, - {"Puzzle complete", 0x61A8}, - {"Xmas tree", 15000}, - {"Puzzle in", 15000}, - {"Lite tune", 15000}, - {"Open extra", 15000}, - {"Ouija", 0x7148}, - {"Wozza", 15000}, - {"Intro", 20000}, - {"Gnawty", 15000}, - {"Banjo's Pad", 15000}, - {"Pause", 15000}, - {"Cesspit", 0x61A8}, - {"Quiz", 15000}, - {"Frog", 20000}, - {"GameBoy", 15000}, - {"Lair", 15000}, - {"Red Extra", 0x7D00}, - {"Gold Extra", 0x7D00}, - {"Egg Extra", 0x7D00}, - {"Note door", 15000}, - {"Cheaty", 15000}, - {"Fairy", 20000}, - {"Skull", 0x61A8}, - {"Square Grunty", 0x61A8}, - {"Square Banjo", 0x61A8}, - {"Square Joker", 0x7530}, - {"Square Music", 0x61A8}, - {"Lab", 20000}, - {"Fade Up", 0x61A8}, - {"Puzzle Out", 15000}, - {"Secret Gobi", 20000}, - {"Secret Beach", 20000}, - {"Secret Ice", 20000}, - {"Secret Spooky", 20000}, - {"Secret Squirrel", 20000}, - {"Secret Egg", 20000}, - {"Jinjup", 0x7D00}, - {"Turbo Talon Trot short", 28000}, - {"Fade Down", 0x61A8}, - {"Big Jinjo", 0x7D00}, - {"T1000", 15000}, - {"Credits", 15000}, - {"T1000x", 20000}, - {"Big Door", 20000}, - {"Descent", 20000}, - {"Wind up", 20000}, - {"Air", 20000}, - {"Do jig", 20000}, - {"Picture", 28000}, - {"Piece up", 20000}, - {"Piece down", 20000}, - {"Spin", 20000}, - {"BarBQ", 15000}, - {"Chord1", 20000}, - {"Chord2", 20000}, - {"Chord3", 20000}, - {"Chord4", 20000}, - {"Chord5", 20000}, - {"Chord6", 20000}, - {"Chord7", 20000}, - {"Chord8", 20000}, - {"Chord9", 20000}, - {"Chord10", 20000}, - {"Shock1", 20000}, - {"Shock2", 20000}, - {"Shock3", 20000}, - {"Shock4", 20000}, - {"Sad grunt", 20000}, - {"Podium", 20000}, - {"Endbit", 20000}, - {"Rock", 20000}, - {"Last Bit", 20000}, - {"Unnamed piece", 15000}, - {"Unnamed piece", 15000}, +MusicTrackMeta musicTrackInfo[176] = { + { "Blank", 15000 }, + { "Scrap", 15000 }, + { "Jungle 2", 20000 }, + { "Snow 2", 20000 }, + { "Bells", 21000 }, + { "Beach", 20000 }, + { "Swamp", 15000 }, + { "Crab Cave", 20000 }, + { "Title", 15000 }, + { "Notes", 15000 }, + { "Jinjo", 15000 }, + { "Feather", 15000 }, + { "Egg", 15000 }, + { "Jigpiece", 28000 }, + { "Sky", 32767 }, + { "Spooky", 21000 }, + { "Training", 15000 }, + { "Lighthouse", 24000 }, + { "Crab", 15000 }, + { "Shell", 32767 }, + { "Feather Inv", 15000 }, + { "Extra life", 15000 }, + { "Honeycomb", 15000 }, + { "Empty honey piece", 15000 }, + { "Extra honey", 15000 }, + { "Mystery", 15000 }, + { "You lose", 20000 }, + { "Termite nest", 32767 }, + { "Outside whale", 15000 }, + { "Spell", 15000 }, + { "Witch House", 23000 }, + { "In whale", 18000 }, + { "Desert", 20000 }, + { "In spooky", 18000 }, + { "Grave", 24000 }, + { "Church", 28000 }, + { "Sphinx", 20000 }, + { "Invulnerabilty", 28000 }, + { "Collapse", 15000 }, + { "Snake", 15000 }, + { "Sandcastle", 15000 }, + { "Summer", 20000 }, + { "Winter", 27000 }, + { "Right", 28000 }, + { "Wrong", 32000 }, + { "Achieve", 32000 }, + { "Autumn", 22000 }, + { "Default forest", 30000 }, + { "5 Jinjos", 15000 }, + { "Game over", 15000 }, + { "Nintendo", 15000 }, + { "Ship", 24000 }, + { "Shark", 15000 }, + { "Ship inside", 24000 }, + { "100 Notes", 15000 }, + { "Door Open", 15000 }, + { "Organ sequence", 18000 }, + { "Advent", 15000 }, + { "Slalom", 15000 }, + { "Race win", 15000 }, + { "Race lose", 15000 }, + { "Jigsaw magic", 15000 }, + { "Oh dear", 15000 }, + { "Up", 15000 }, + { "Down", 15000 }, + { "Shamen Hut", 19000 }, + { "Jig 10", 25000 }, + { "Carpet", 15000 }, + { "Squirrel", 15000 }, + { "Hornet", 15000 }, + { "Treetop", 32000 }, + { "Turtle Shell", 25000 }, + { "House Summer", 15000 }, + { "House Autumn", 15000 }, + { "Out Buildings", 15000 }, + { "Hornet 2", 15000 }, + { "Cabins", 15000 }, + { "Rain", 15000 }, + { "Jigsaw Open", 15000 }, + { "Jigsaw Close", 15000 }, + { "Witch 1", 23000 }, + { "Witch 2", 23000 }, + { "Witch 3", 23000 }, + { "Witch 4", 23000 }, + { "Witch 5", 23000 }, + { "Mr Vile", 15000 }, + { "Bridge", 22000 }, + { "Turbo Talon Trot", 28000 }, + { "Long legs", 28000 }, + { "Witch 6", 23000 }, + { "Boggy sad", 15000 }, + { "Boggy happy", 15000 }, + { "Quit", 15000 }, + { "Witch 7", 23000 }, + { "Witch 8", 23000 }, + { "Spring", 18000 }, + { "Squirrel attic", 26000 }, + { "Lights", 15000 }, + { "Box", 17000 }, + { "Witch 9", 23000 }, + { "Open up", 15000 }, + { "Puzzle complete", 25000 }, + { "Xmas tree", 15000 }, + { "Puzzle in", 15000 }, + { "Lite tune", 15000 }, + { "Open extra", 15000 }, + { "Ouija", 29000 }, + { "Wozza", 15000 }, + { "Intro", 20000 }, + { "Gnawty", 15000 }, + { "Banjo's Pad", 15000 }, + { "Pause", 15000 }, + { "Cesspit", 25000 }, + { "Quiz", 15000 }, + { "Frog", 20000 }, + { "GameBoy", 15000 }, + { "Lair", 15000 }, + { "Red Extra", 32000 }, + { "Gold Extra", 32000 }, + { "Egg Extra", 32000 }, + { "Note door", 15000 }, + { "Cheaty", 15000 }, + { "Fairy", 20000 }, + { "Skull", 25000 }, + { "Square Grunty", 25000 }, + { "Square Banjo", 25000 }, + { "Square Joker", 30000 }, + { "Square Music", 25000 }, + { "Lab", 20000 }, + { "Fade Up", 25000 }, + { "Puzzle Out", 15000 }, + { "Secret Gobi", 20000 }, + { "Secret Beach", 20000 }, + { "Secret Ice", 20000 }, + { "Secret Spooky", 20000 }, + { "Secret Squirrel", 20000 }, + { "Secret Egg", 20000 }, + { "Jinjup", 32000 }, + { "Turbo Talon Trot short", 28000 }, + { "Fade Down", 25000 }, + { "Big Jinjo", 32000 }, + { "T1000", 15000 }, + { "Credits", 15000 }, + { "T1000x", 20000 }, + { "Big Door", 20000 }, + { "Descent", 20000 }, + { "Wind up", 20000 }, + { "Air", 20000 }, + { "Do jig", 20000 }, + { "Picture", 28000 }, + { "Piece up", 20000 }, + { "Piece down", 20000 }, + { "Spin", 20000 }, + { "BarBQ", 15000 }, + { "Chord1", 20000 }, + { "Chord2", 20000 }, + { "Chord3", 20000 }, + { "Chord4", 20000 }, + { "Chord5", 20000 }, + { "Chord6", 20000 }, + { "Chord7", 20000 }, + { "Chord8", 20000 }, + { "Chord9", 20000 }, + { "Chord10", 20000 }, + { "Shock1", 20000 }, + { "Shock2", 20000 }, + { "Shock3", 20000 }, + { "Shock4", 20000 }, + { "Sad grunt", 20000 }, + { "Podium", 20000 }, + { "Endbit", 20000 }, + { "Rock", 20000 }, + { "Last Bit", 20000 }, + { "Unnamed piece", 15000 }, + { "Unnamed piece", 15000 }, 0 }; + s32 D_802762C0 = 0; s32 D_802762C4 = 0; -/* .bss */ -MusicTrack D_80281720[6]; -MusicTrack **D_802820E0; -ALSeqpConfig D_802820E8; -u16 D_80282104; //called as u16 someplaces and s16 others -ALBank * D_80282108; -structBs D_80282110[0x20]; - -/* .code */ -void musicInstruments_init(void){ - s32 i; - - D_80282104 = 0xAD; - D_802820E0 = (MusicTrack **) bk_malloc(D_80282104 * sizeof(MusicTrack *)); - for(i = 0; i < D_80282104; i++){ - D_802820E0[i] = NULL; +MusicSlot sMusicSlots[NUM_MUSIC_SLOTS]; +MidiBin **sMIDIAssets; +ALSeqpConfig sMusicInstrumentsSeqConfig; +u16 sNumMIDIAssets; +ALBank *sMusicSoundBank; +ChanTempoState sChanTempoStates[NUM_CHANNEL_TEMPO_STATES]; + +void musicInstruments_init(void) { + ALBankFile *bnk_f; + u32 size; + int i; + + sNumMIDIAssets = COMUSIC_NUM_TRACKS; + sMIDIAssets = (MidiBin **) bk_malloc(sNumMIDIAssets * sizeof(MidiBin *)); + for (i = 0; i < sNumMIDIAssets; i++) { + sMIDIAssets[i] = NULL; } - for(i = 0; i < 6; i++){ - D_80281720[i].index = -1; - D_80281720[i].unk2 = 0; - D_80281720[i].unk3 = 0; - D_80281720[i].index_cpy = 0; - D_80281720[i].unk17C = 0.0f; - D_80281720[i].unk180 = 1.0f; - D_80281720[i].cseqp.state = AL_STOPPED; + for (i = 0; i < NUM_MUSIC_SLOTS; i++) { + sMusicSlots[i].track_id = -1; + sMusicSlots[i].unk2 = FALSE; + sMusicSlots[i].unk3 = FALSE; + sMusicSlots[i].index_cpy = 0; + sMusicSlots[i].unk17C = 0.0f; + sMusicSlots[i].unk180 = 1.0f; + sMusicSlots[i].cseqp.state = AL_STOPPED; } - ALBankFile * bnk_f; - f32 tmpf1; - s32 size; - // [port] Parse N64 big-endian ctl binary into native 64-bit structs extern ALBankFile *port_alBnkfNew(u8 *ctlData, s32 ctlSize, u8 *tblData); size = soundfont2ctl_ROM_END - soundfont2ctl_ROM_START; bnk_f = port_alBnkfNew(soundfont2ctl_ROM_START, size, soundfont2tbl_ROM_START); - D_802820E8.maxVoices = 0x18; - D_802820E8.maxEvents = 0x55; - D_802820E8.maxChannels = 0x10; - D_802820E8.heap = audioManager_getALHeapInfo(); - D_802820E8.initOsc = NULL; - D_802820E8.updateOsc = NULL; - D_802820E8.stopOsc = NULL; - audioManager_setupSeqp(&D_802820E8); - for(i = 0; i < 6; i++){ - n_alCSPNew((N_ALCSPlayer *)&D_80281720[i].cseqp, &D_802820E8); + sMusicInstrumentsSeqConfig.maxVoices = 24; + sMusicInstrumentsSeqConfig.maxEvents = 85; + sMusicInstrumentsSeqConfig.maxChannels = 16; + sMusicInstrumentsSeqConfig.heap = audioManager_getALHeapInfo(); + sMusicInstrumentsSeqConfig.initOsc = NULL; + sMusicInstrumentsSeqConfig.updateOsc = NULL; + sMusicInstrumentsSeqConfig.stopOsc = NULL; + audioManager_setupSeqp(&sMusicInstrumentsSeqConfig); + + for (i = 0; i < NUM_MUSIC_SLOTS; i++) { + n_alCSPNew((N_ALCSPlayer *) &sMusicSlots[i].cseqp, &sMusicInstrumentsSeqConfig); } - D_80282108 = bnk_f->bankArray[0]; - for(i = 0; i < 6; i++){ - alCSPSetBank(&D_80281720[i].cseqp, D_80282108); + sMusicSoundBank = bnk_f->bankArray[0]; + for (i = 0; i < NUM_MUSIC_SLOTS; i++) { + alCSPSetBank(&sMusicSlots[i].cseqp, sMusicSoundBank); } - func_8024FB8C(); + musicSlot_stopAll(); } -ALBank *music_get_sound_bank(void){ - return D_80282108; +ALBank *musicInstruments_getSoundBank(void) { + return sMusicSoundBank; } -void func_8024F764(s32 arg0){//music track load - if(D_802820E0[arg0] == NULL){ - func_8033B788(); -#if VERSION == VERSION_USA_1_0 - D_802820E0[arg0] = assetcache_get(arg0 + 0x1516); -#elif VERSION == VERSION_PAL - D_802820E0[arg0] = assetcache_get(arg0 + 0xd74); -#endif - } +void musicTrack_load(enum comusic_e track_id) { + if (sMIDIAssets[track_id] == NULL) { + assetcache_func_8033B788(); + sMIDIAssets[track_id] = assetcache_get(MUSIC_TRACK_ASSET_BASE_ID + track_id); + } } -void func_8024F7C4(s32 arg0){ - s32 i; +void musicTrack_release(enum comusic_e track_id) { + int i; + port_lockAudio(); - if(D_802820E0[arg0] != NULL){ - i = 0; - for(i = 0; i != 6; i++){ - if(D_80281720[i].index == arg0){ + if (sMIDIAssets[track_id] != NULL) { + for (i = 0; i < NUM_MUSIC_SLOTS; i++) { + if (sMusicSlots[i].track_id == track_id) { port_unlockAudio(); return; } } - assetcache_release(D_802820E0[arg0]); - D_802820E0[arg0] = 0; + assetcache_release(sMIDIAssets[track_id]); + sMIDIAssets[track_id] = NULL; } port_unlockAudio(); } -void func_8024F83C(void){ - s32 i; - for(i = 0; i < D_80282104; i++){ - func_8024F7C4(i); +void musicTrack_releaseAll(void) { + int i; + + for (i = 0; i < sNumMIDIAssets; i++) { + musicTrack_release(i); } } -void func_8024F890(u8 arg0, s32 arg1){ - s32 i; +void musicSlot_loadTrack(u8 index, enum comusic_e track_id) { + int i; + // [port] This function directly mutates the sequence player's target (n_alCSeqNew) and // chanMask while the free-running audio worker reads them in n_alAudioFrame. Unlike // the rest of the audio code, it has no osSetIntMask bracket. Guard it with the audio lock. port_lockAudio(); - if(arg1 == -1){ - if(arg1 != D_80281720[arg0].index) { - alCSPStop(&D_80281720[arg0].cseqp); + if (track_id == -1) { + if (track_id != sMusicSlots[index].track_id) { + alCSPStop((ALCSPlayer *) &sMusicSlots[index].cseqp); } - D_80281720[arg0].index = arg1; - } - else{ - if(-1 != D_80281720[arg0].index){ - func_8024F890(arg0, -1); - } - D_80281720[arg0].unk2 = 0; - D_80281720[arg0].unk3 = 0; - D_80281720[arg0].index = arg1; - for(i = 0; i < 0xe; i++){ - D_80281720[arg0].unk184[i] = 0; - D_80281720[arg0].unk192[i] = 0; + sMusicSlots[index].track_id = track_id; + } else { + if (sMusicSlots[index].track_id != -1) { + musicSlot_loadTrack(index, -1); } - func_8024F764(D_80281720[arg0].index); - if (arg1 >= 0 && arg1 < 0xB0 && D_802820E0 != NULL) { - n_alCSeqNew(&D_80281720[arg0].cseq, (u8 *)D_802820E0[arg1]); + sMusicSlots[index].unk2 = FALSE; + sMusicSlots[index].unk3 = FALSE; + sMusicSlots[index].track_id = track_id; + for (i = 0; i < 14; i++) { + sMusicSlots[index].unk184[i] = 0; + sMusicSlots[index].unk192[i] = 0; } - D_80281720[arg0].cseqp.chanMask = func_80250474(arg0); - alCSPSetSeq(&D_80281720[arg0].cseqp, &D_80281720[arg0].cseq); - alCSPPlay(&D_80281720[arg0].cseqp); - alCSPSetVol(&D_80281720[arg0].cseqp, D_80281720[arg0].unk0); - if(player_is_present() && player_getWaterState() == BSWATERGROUP_2_UNDERWATER){ - func_8025F3F0(&D_80281720[arg0].cseqp, 0.0f, 1.0f); + musicTrack_load(sMusicSlots[index].track_id); + if (track_id >= 0 && track_id < COMUSIC_NUM_TRACKS && sMIDIAssets != NULL) { // [port] bounds guard + n_alCSeqNew(&sMusicSlots[index].cseq, (u8 *) sMIDIAssets[sMusicSlots[index].track_id]); } - else{ - func_8025F3F0(&D_80281720[arg0].cseqp, D_80281720[arg0].unk17C, D_80281720[arg0].unk180); + sMusicSlots[index].cseqp.chanMask = musicSlot_func_80250474(index); + alCSPSetSeq(&sMusicSlots[index].cseqp, &sMusicSlots[index].cseq); + alCSPPlay(&sMusicSlots[index].cseqp); + alCSPSetVol(&sMusicSlots[index].cseqp, sMusicSlots[index].volume); + + if (player_is_present() && (player_getWaterState() == BSWATERGROUP_2_UNDERWATER)) { + func_8025F3F0(&sMusicSlots[index].cseqp, 0.0f, 1.0f); + } else { + func_8025F3F0(&sMusicSlots[index].cseqp, sMusicSlots[index].unk17C, sMusicSlots[index].unk180); } } port_unlockAudio(); } -s32 func_8024FA6C(u8 arg0){ - return D_80281720[arg0].index; +enum comusic_e musicSlot_getTrack(u8 index) { + return sMusicSlots[index].track_id; } -void func_8024FA98(u8 arg0, s32 arg1){ - s32 sp2C; - s32 sp24; - volatile s64 sp20; +void musicSlot_func_8024FA98(u8 index, enum comusic_e track_id) { + s32 current_track_id; + volatile OSTime time; - sp2C = D_80281720[arg0].index; - if(arg1 == sp2C || sp2C == -1){ - func_8024F890(arg0, arg1); - }else{ - func_8024F890(arg0, -1); - sp20 = osGetTime(); - while(D_80281720[arg0].cseqp.state != AL_STOPPED){ - if(gPortResetPending) break; // [port] avoid deadlock during reset + current_track_id = sMusicSlots[index].track_id; + if ((current_track_id == track_id) || (current_track_id == -1)) { + musicSlot_loadTrack(index, track_id); + } else { + musicSlot_loadTrack(index, -1); + time = osGetTime(); + while (sMusicSlots[index].cseqp.state != AL_STOPPED) { + if (gPortResetPending) break; // [port] avoid deadlock during reset osGetTime(); }; - func_8024F7C4(sp2C); - func_8024F890(arg0, arg1); + musicTrack_release(current_track_id); + musicSlot_loadTrack(index, track_id); } } -s32 func_8024FB60(u8 arg0){ - return D_80281720[arg0].cseqp.state; +s32 musicSlot_getSlotSeqpState(u8 index) { + return sMusicSlots[index].cseqp.state; } -void func_8024FB8C(void){ - s32 i, allStopped; - volatile s64 sp2C; +void musicSlot_stopAll(void) { + int i; + bool still_running; + volatile OSTime time; - for(i = 0; i < 6; i++){ - func_8024F890(i,-1); + for (i = 0; i < NUM_MUSIC_SLOTS; i++) { + musicSlot_loadTrack(i, -1); } - sp2C = osGetTime(); - do{ + time = osGetTime(); + + do { // [port] During reset, audio callback may not run to clear player states - if(gPortResetPending) break; - allStopped = 0; - for(i = 0; i < 6; i++){ - if(func_8024FB60(i) != AL_STOPPED) - allStopped++; + if (gPortResetPending) break; + still_running = FALSE; + for (i = 0; i < NUM_MUSIC_SLOTS; i++) { + if (musicSlot_getSlotSeqpState(i) != AL_STOPPED) + still_running++; } osGetTime(); - }while(allStopped); + } while(still_running); } -void func_8024FC1C(u8 arg0, s32 arg1){ - D_80281720[arg0].index_cpy = arg1; - D_80281720[arg0].unk2 = 1; - D_80281720[arg0].unk3 = 0; - if (arg1 >= 0 && arg1 < 0xB0) { - D_80281720[arg0].unk0 = D_80275D40[arg1].volume; +void musicSlot_func_8024FC1C(u8 index, enum comusic_e track_id) { + sMusicSlots[index].index_cpy = track_id; + sMusicSlots[index].unk2 = TRUE; + sMusicSlots[index].unk3 = FALSE; + if (track_id >= 0 && track_id < 176) { // [port] bounds guard + sMusicSlots[index].volume = musicTrackInfo[track_id].volume; } else { - D_80281720[arg0].unk0 = 0; + sMusicSlots[index].volume = 0; } } -void func_8024FC6C(u8 arg0){ - s32 indx; - indx = D_80281720[arg0].index; - if(indx == 0x2D || indx == 0x3D){ - D_80281720[arg0].unk2 = 1; - D_80281720[arg0].unk3 = 0; - D_80281720[arg0].index_cpy = D_80281720[arg0].index; - }else{ - D_80281720[arg0].index_cpy = -1; - D_80281720[arg0].unk3 = 1; - D_80281720[arg0].unk2 = 1; - D_80281720[arg0].unk0 = 0; +void musicSlot_func_8024FC6C(u8 index) { + enum comusic_e track_id = sMusicSlots[index].track_id; + + if ((track_id == COMUSIC_2D_PUZZLE_SOLVED_FANFARE) || (track_id == COMUSIC_3D_JIGGY_SPAWN)) { + sMusicSlots[index].unk2 = TRUE; + sMusicSlots[index].unk3 = FALSE; + sMusicSlots[index].index_cpy = sMusicSlots[index].track_id; + } else { + sMusicSlots[index].index_cpy = -1; + sMusicSlots[index].unk3 = TRUE; + sMusicSlots[index].unk2 = TRUE; + sMusicSlots[index].volume = 0; } } -void func_8024FCE0(u8 arg0, s16 arg1){ - D_80281720[arg0].unk3 = 1; - D_80281720[arg0].unk2 = 1; - D_80281720[arg0].unk0 = arg1; - D_80281720[arg0].index_cpy = D_80281720[arg0].index; +void musicSlot_func_8024FCE0(u8 index, s16 volume) { + sMusicSlots[index].unk3 = TRUE; + sMusicSlots[index].unk2 = TRUE; + sMusicSlots[index].volume = volume; + sMusicSlots[index].index_cpy = sMusicSlots[index].track_id; } -//musicTrack_setVolume -void musicTrack_setVolume(u8 arg0, s16 arg1){ - D_80281720[arg0].unk0 = arg1; - alCSPSetVol(&D_80281720[arg0].cseqp, arg1); - if(D_80281720[arg0].unk3 && arg1){ - func_8024FCE0(arg0, arg1); - } - else if(!D_80281720[arg0].unk3 && arg1 == 0){ - if(func_80250074(arg0) == 0) - func_8024FC6C(arg0); +void musicSlot_setVolume(u8 index, s16 volume) { + sMusicSlots[index].volume = volume; + alCSPSetVol(&sMusicSlots[index].cseqp, volume); + + if (sMusicSlots[index].unk3 && volume) { + musicSlot_func_8024FCE0(index, volume); + } else if (!sMusicSlots[index].unk3 && (volume == 0)) { + if (!musicSlot_hasStopped(index)) { + musicSlot_func_8024FC6C(index); + } } } -//musicTrack_setTempo -void func_8024FDDC(u8 arg0, s32 tempo){ - if(func_80250074(arg0) == 0){ - if(!D_80281720[arg0].unk2){ - alCSPSetTempo(&D_80281720[arg0].cseqp, tempo); +void musicSlot_setTempo(u8 index, s32 tempo) { + if (!musicSlot_hasStopped(index)) { + if (!sMusicSlots[index].unk2) { + alCSPSetTempo(&sMusicSlots[index].cseqp, tempo); } } } -void func_8024FE44(u8 arg0, f32 arg1, f32 arg2){ - D_80281720[arg0].unk17C = arg1; - D_80281720[arg0].unk180 = arg2; - if(func_80250074(arg0) == 0){ +void musicSlot_func_8024FE44(u8 index, f32 arg1, f32 arg2) { + sMusicSlots[index].unk17C = arg1; + sMusicSlots[index].unk180 = arg2; + if (!musicSlot_hasStopped(index)) { if(player_getWaterState() == BSWATERGROUP_2_UNDERWATER){ - func_8025F3F0(&D_80281720[arg0].cseqp, 0.0f, 1.0f); + func_8025F3F0(&sMusicSlots[index].cseqp, 0.0f, 1.0f); }else{ - func_8025F3F0(&D_80281720[arg0].cseqp, arg1, arg2); + func_8025F3F0(&sMusicSlots[index].cseqp, arg1, arg2); } } } -s32 func_8024FEEC(u8 arg0) -{ - return alCSeqGetTicks(&D_80281720[arg0].cseq); +s32 musicSlot_getCSeqTicks(u8 index) { + return alCSeqGetTicks(&sMusicSlots[index].cseq); } -void func_8024FF34(void){ +void func_8024FF34(void) { s32 i; - for(i = 0; i < 6 ; i++){ - switch(D_80281720[i].cseqp.state){ - case AL_PLAYING://L8024FF94 - if(D_80281720[i].unk2){ - alCSPStop(&(D_80281720[i].cseqp)); + for (i = 0; i < NUM_MUSIC_SLOTS; i++) { + switch (sMusicSlots[i].cseqp.state) { + case AL_PLAYING: + if (sMusicSlots[i].unk2) { + alCSPStop(&sMusicSlots[i].cseqp); - if(D_80281720[i].unk3) - D_80281720[i].unk2 = 0; + if (sMusicSlots[i].unk3) { + sMusicSlots[i].unk2 = FALSE; + } } break; - - case AL_STOPPED: //L8024FFBC - if(D_80281720[i].unk2){ - if(D_80281720[i].unk3){ - alCSPPlay(&D_80281720[i].cseqp); - } else{ - func_8024FA98(i, D_80281720[i].index_cpy); + + case AL_STOPPED: + if (sMusicSlots[i].unk2) { + if (sMusicSlots[i].unk3) { + alCSPPlay(&sMusicSlots[i].cseqp); + } else { + musicSlot_func_8024FA98(i, sMusicSlots[i].index_cpy); } - D_80281720[i].unk3 = 0; - D_80281720[i].unk2 = 0; - musicTrack_setVolume(i, D_80281720[i].unk0); + sMusicSlots[i].unk3 = FALSE; + sMusicSlots[i].unk2 = FALSE; + musicSlot_setVolume(i, sMusicSlots[i].volume); } break; - case AL_STOPPING: //L80250008 + + case AL_STOPPING: break; } } } -s32 gcMusic_getDefaultVolumeForTrack(s32 track_id){ - if (track_id >= 0 && track_id < 0xB0) { - return D_80275D40[track_id].volume; +s32 gcMusic_getDefaultVolumeForTrack(enum comusic_e track_id) { + if (track_id >= 0 && track_id < 176) { // [port] bounds guard + return musicTrackInfo[track_id].volume; } return 0; } -void gcMusic_setDefaultVolumeForTrack(s32 track_id, u16 arg1){ - if (track_id >= 0 && track_id < 0xB0) { - D_80275D40[track_id].volume = arg1; +void gcMusic_setDefaultVolumeForTrack(enum comusic_e track_id, u16 volume) { + if (track_id >= 0 && track_id < 176) { // [port] bounds guard + musicTrackInfo[track_id].volume = volume; } } -//song_getName -char *gcMusic_getNameForTrack(s32 track_id){ - if (track_id >= 0 && track_id < 0xB0) { - return D_80275D40[track_id].name; +char *gcMusic_getNameForTrack(enum comusic_e track_id) { + if (track_id >= 0 && track_id < 176) { // [port] bounds guard + return musicTrackInfo[track_id].name; } return NULL; } -int func_80250074(u8 arg0){ - return (D_80281720[arg0].cseqp.state == AL_STOPPED && D_80281720[arg0].unk3 == 0); +bool musicSlot_hasStopped(u8 index) { + return (sMusicSlots[index].cseqp.state == AL_STOPPED && !sMusicSlots[index].unk3); } -s32 func_802500C0(void){ - return *(s16 *)&D_80282104; +s32 gcMusic_getAssetCount(void) { + return (s16) sNumMIDIAssets; } -N_ALCSPlayer *func_802500CC(s32 arg0){ - return (N_ALCSPlayer *)&D_80281720[arg0].cseqp; +N_ALCSPlayer *musicSlot_getCSeqp(s32 index) { + return (N_ALCSPlayer *) &sMusicSlots[index].cseqp; } -void func_802500F4(s32 arg0){} +void musicSlot_func_802500F4(s32 index) {} -void func_802500FC(s32 arg0){} +void musicSlot_func_802500FC(s32 index) {} -void func_80250104(ALCSeq *arg0, s32 arg1, s32 arg2){ +void musicSlot_func_80250104(ALCSeq *cseq, s32 arg1, s32 chan) { u8 i; - for(i = 0; i < 6; i++){ - if(arg0 == &D_80281720[i].cseq){ - D_80281720[i].unk184[arg1 - 0x6A] = 1; - D_80281720[i].unk192[arg1 - 0x6A] = arg2; + + for (i = 0; i < NUM_MUSIC_SLOTS; i++) { + if (cseq == &sMusicSlots[i].cseq) { + sMusicSlots[i].unk184[arg1 - 0x6A] = 1; + sMusicSlots[i].unk192[arg1 - 0x6A] = chan; return; } } } -void func_80250170(u8 arg0, s32 arg1, s32 arg2){ - D_80281720[arg0].unk184[arg1 - 0x6A] = arg2; +void musicSlot_func_80250170(u8 index, s32 arg1, s32 arg2) { + sMusicSlots[index].unk184[arg1 - 0x6A] = arg2; } -s32 func_802501A0(u8 arg0, s32 arg1, s32 *arg2){ - if(arg2 != 0){ - *arg2 = D_80281720[arg0].unk192[arg1 - 0x6A]; +s32 musicSlot_func_802501A0(u8 index, s32 arg1, s32 *chan) { + if (chan) { + *chan = sMusicSlots[index].unk192[arg1 - 0x6A]; } - return D_80281720[arg0].unk184[arg1 - 0x6A]; + return sMusicSlots[index].unk184[arg1 - 0x6A]; } -void func_80250200(s32 arg0, s16 chan, s16 arg2, f32 arg3){ - s32 i; - ALCSPlayer *sp28; - f32 tmpf; - s32 mask; +void musicSlot_setChannelTempoChange(s32 index, s16 chan, s16 target_tempo, f32 transition_speed) { + int i; + N_ALCSPlayer *csplayer; + f32 tempo; + OSIntMask old_int_mask; - sp28 = (ALCSPlayer *)func_802500CC(arg0); - mask = osSetIntMask(OS_IM_NONE); - tmpf = (!func_80250074(arg0))? func_8025F4A0(sp28, chan) :127.0f; + csplayer = musicSlot_getCSeqp(index); + old_int_mask = osSetIntMask(OS_IM_NONE); + tempo = (!musicSlot_hasStopped(index)) ? func_8025F4A0(csplayer, chan) : 127.0f; - if(arg3 < (2.0f/FRAMERATE)){ - arg3 = (2.0f/FRAMERATE); + if (transition_speed < (2.0f / FRAMERATE)) { + transition_speed = (2.0f / FRAMERATE); } - for(i = 0; i< 0x20; i++){ - if( (D_80282110[i].unk8 == D_80282110[i].unk10) - || (D_80282110[i].unk0 == arg0 && chan ==D_80282110[i].chan) - ){ - D_80282110[i].unk0 = arg0; - D_80282110[i].chan = chan; - D_80282110[i].unk8 = tmpf; - D_80282110[i].unkC = (arg2 - tmpf)/((arg3 * (float)FRAMERATE)/2); - D_80282110[i].unk10 = arg2; - osSetIntMask(mask); + for (i = 0; i < NUM_CHANNEL_TEMPO_STATES; i++) { + if ((sChanTempoStates[i].tempo == sChanTempoStates[i].target_tempo) || ((sChanTempoStates[i].slot_id == index) && (sChanTempoStates[i].chan) == chan)) { + sChanTempoStates[i].slot_id = index; + sChanTempoStates[i].chan = chan; + sChanTempoStates[i].tempo = tempo; + sChanTempoStates[i].change_step = (target_tempo - tempo) / ((transition_speed * (f32) FRAMERATE) / 2); + sChanTempoStates[i].target_tempo = target_tempo; + osSetIntMask(old_int_mask); return; } } - osSetIntMask(mask); + + osSetIntMask(old_int_mask); } -void func_80250360(s32 arg0, s32 arg1, f32 arg2){ - ALCSPlayer * sp24; - s32 i; - s32 sp1C; +void musicSlot_setTempoChange(s32 index, s32 target_tempo, f32 transition_speed) { + N_ALCSPlayer *csplayer; + int i; + OSIntMask old_int_mask; f32 tempo; - sp24 = (ALCSPlayer *)func_802500CC(arg0); - sp1C = osSetIntMask(1); - tempo = alCSPGetTempo(sp24); - if( arg2 < (2.0f/FRAMERATE)){ - arg2 = (2.0f/FRAMERATE); + csplayer = musicSlot_getCSeqp(index); + old_int_mask = osSetIntMask(OS_IM_NONE); + tempo = alCSPGetTempo((ALCSPlayer *) csplayer); + + if (transition_speed < (2.0f / FRAMERATE)) { + transition_speed = (2.0f / FRAMERATE); } - for(i = 0; i < 0x20; i++){ - if(D_80282110[i].unk8 == D_80282110[i].unk10 - || (D_80282110[i].unk0 == arg0 && -1 ==D_80282110[i].chan) - ){ - D_80282110[i].unk0 = arg0; - D_80282110[i].chan = -1; - D_80282110[i].unk8 = tempo; - D_80282110[i].unkC = (arg1 - tempo)/((arg2 * (float)FRAMERATE)/2); - D_80282110[i].unk10 = arg1; - osSetIntMask(sp1C); + + for (i = 0; i < NUM_CHANNEL_TEMPO_STATES; i++) { + if ((sChanTempoStates[i].tempo == sChanTempoStates[i].target_tempo) || ((sChanTempoStates[i].slot_id == index) && (sChanTempoStates[i].chan == -1))) { + sChanTempoStates[i].slot_id = index; + sChanTempoStates[i].chan = -1; + sChanTempoStates[i].tempo = tempo; + sChanTempoStates[i].change_step = (target_tempo - tempo) / ((transition_speed * (f32) FRAMERATE) / 2); + sChanTempoStates[i].target_tempo = target_tempo; + osSetIntMask(old_int_mask); return; } } - osSetIntMask(sp1C); + + osSetIntMask(old_int_mask); } -u16 func_80250474(s32 arg0){ - ALCSPlayer * sp24; - s32 i; - s32 sp1C; - f32 tmpf; - - - if(arg0 != 0) - return ~0; - D_802762C0 = (D_802762C4 = -1); - sp1C = osSetIntMask(1); - for(i = 0; i < 0x20; i++){ - D_80282110[i].unk8 = -1.0f; - D_80282110[i].unk10 = -1.0f; +u16 musicSlot_func_80250474(s32 index) { + int i; + OSIntMask old_int_mask; + + if (index != 0) { + return -1; + } + + D_802762C0 = D_802762C4 = -1; + + old_int_mask = osSetIntMask(OS_IM_NONE); + for (i = 0; i < NUM_CHANNEL_TEMPO_STATES; i++) { + sChanTempoStates[i].tempo = -1.0f; + sChanTempoStates[i].target_tempo = -1.0f; } - osSetIntMask(sp1C); + osSetIntMask(old_int_mask); + core1_ce60_func_8024AF48(); - if(D_802762C0 == -1){ + + if (D_802762C0 == -1) { D_802762C0 = 0xFFFF; } - return D_802762C0; + return D_802762C0; } -void func_80250530(s32 arg0, u16 chan_mask, f32 arg2){ +void musicSlot_stepToChannelMask(s32 index, u16 chan_mask, f32 transition_speed) { s32 chan; - if(D_802762C0 != chan_mask){ - if(D_802762C0 == -1){ - arg2 = 0.0f; + + if (D_802762C0 != chan_mask) { + if (D_802762C0 == -1) { + transition_speed = 0.0f; } D_802762C0 = chan_mask; - for(chan = 0; chan < 16; chan++){ - if(chan_mask & (1 << chan)){ - func_80250200(arg0, chan, 0x7F, arg2); - } - else{ - func_80250200(arg0, chan, 0, arg2); + for (chan = 0; chan < 16; chan++) { + if (chan_mask & (1 << chan)) { + musicSlot_setChannelTempoChange(index, chan, 127, transition_speed); + } else { + musicSlot_setChannelTempoChange(index, chan, 0, transition_speed); } } - }//L802505E4 + } } -void func_80250604(s32 arg0, s32 arg1, f32 arg2){ - if(arg1 != D_802762C4){ - if(D_802762C4 == -1){ - arg2 = 0.0f; +void musicSlot_stepToTempo(s32 index, s32 target_tempo, f32 transition_speed) { + if (target_tempo != D_802762C4) { + if (D_802762C4 == -1) { + transition_speed = 0.0f; } - D_802762C4 = arg1; - func_80250360(arg0, arg1, arg2); + D_802762C4 = target_tempo; + musicSlot_setTempoChange(index, target_tempo, transition_speed); } } +// n_audio ?? void func_80250650(void) { N_ALCSPlayer *csplayer; - s32 i; + int i; s32 channel; - for(i = 0; i < 0x20; i++){ - csplayer = func_802500CC(D_80282110[i].unk0); - if ((D_80282110[i].unk8 != D_80282110[i].unk10) && (func_80250074((u8)D_80282110[i].unk0) == 0)) { - if (D_80282110[i].unkC >= 0.0f) { - D_80282110[i].unk8 = MIN(D_80282110[i].unk8 + D_80282110[i].unkC, D_80282110[i].unk10); + for (i = 0; i < NUM_CHANNEL_TEMPO_STATES; i++) { + csplayer = musicSlot_getCSeqp(sChanTempoStates[i].slot_id); + + if ((sChanTempoStates[i].tempo != sChanTempoStates[i].target_tempo) && !musicSlot_hasStopped(sChanTempoStates[i].slot_id)) { + if (sChanTempoStates[i].change_step >= 0.0f) { + sChanTempoStates[i].tempo = MIN(sChanTempoStates[i].tempo + sChanTempoStates[i].change_step, sChanTempoStates[i].target_tempo); } else { - D_80282110[i].unk8 = MAX(D_80282110[i].unk8 + D_80282110[i].unkC, D_80282110[i].unk10); + sChanTempoStates[i].tempo = MAX(sChanTempoStates[i].tempo + sChanTempoStates[i].change_step, sChanTempoStates[i].target_tempo); } - if (D_80282110[i].chan == -1) { - alCSPSetTempo((ALCSPlayer *)csplayer, (s32) D_80282110[i].unk8); + + if (sChanTempoStates[i].chan == -1) { + alCSPSetTempo((ALCSPlayer *) csplayer, (s32) sChanTempoStates[i].tempo); } else { - func_8025F510((ALCSPlayer *)csplayer,D_80282110[i].chan, D_80282110[i].unk8); - channel = D_80282110[i].chan; + func_8025F510((ALCSPlayer *) csplayer, sChanTempoStates[i].chan, sChanTempoStates[i].tempo); + channel = sChanTempoStates[i].chan; if (((csplayer->chanMask) & (1 << channel))) { - if (D_80282110[i].unk8 == 0.0) { - func_8025F5C0((ALCSPlayer *)csplayer, D_80282110[i].chan); + if (sChanTempoStates[i].tempo == 0.0) { + func_8025F5C0(csplayer, sChanTempoStates[i].chan); } } else { - if (D_80282110[i].unk8 != 0.0f) { - func_8025F570((ALCSPlayer *)csplayer, D_80282110[i].chan); + if (sChanTempoStates[i].tempo != 0.0f) { + func_8025F570(csplayer, sChanTempoStates[i].chan); } } } diff --git a/src/core1/audio_manager.c b/src/core1/audio_manager.c index d6d669dac..8326f8c2a 100644 --- a/src/core1/audio_manager.c +++ b/src/core1/audio_manager.c @@ -332,10 +332,10 @@ void audioManager_create(void) { for (i = 0; i < 89; i++) { alLink(&sDMAStateData[i + 1].link, &sDMAStateData[i].link); - sDMAStateData[i].heap = (uintptr_t)alHeapDBAlloc(0, 0, sn_alConfig.heap, 1, DMA_BLOCK_SIZE); + sDMAStateData[i].heap = (uintptr_t)alHeapAlloc(sn_alConfig.heap, 1, DMA_BLOCK_SIZE); } - sDMAStateData[i].heap = (uintptr_t)alHeapDBAlloc(0, 0, sn_alConfig.heap, 1, DMA_BLOCK_SIZE); + sDMAStateData[i].heap = (uintptr_t)alHeapAlloc(sn_alConfig.heap, 1, DMA_BLOCK_SIZE); for (i = 0; i < 2; i++) { audioManager.ACMDList[i] = bk_malloc(NUM_AUDIO_CMDS_PER_SECOND * sizeof(Acmd) / FRAMERATE); @@ -344,7 +344,7 @@ void audioManager_create(void) { sNumAudioCmdsPerFrame = NUM_AUDIO_CMDS_PER_SECOND / FRAMERATE; for (i = 0; i < 3; i++) { - audioManager.audio_info[i] = alHeapDBAlloc(0, 0, sn_alConfig.heap, 1, sizeof(AudioInfo)); + audioManager.audio_info[i] = alHeapAlloc(sn_alConfig.heap, 1, sizeof(AudioInfo)); audioManager.audio_info[i]->reply_mesg_data.unk0 = 0; audioManager.audio_info[i]->reply_mesg_data.audio_info_ptr = audioManager.audio_info[i]; audioManager.audio_info[i]->data = bk_malloc(4 * sMaxFrameSize); diff --git a/src/core1/audio_soundplayer.c b/src/core1/audio_soundplayer.c index 4bba31210..6b6e32385 100644 --- a/src/core1/audio_soundplayer.c +++ b/src/core1/audio_soundplayer.c @@ -48,18 +48,18 @@ void func_80243070(Struct87s *arg0) { ALEvent sp40; u32 var_s0; - D_802758CC->maxSounds = (s32) arg0->unk8; + D_802758CC->maxSounds = arg0->max_sounds; D_802758CC->target = 0; D_802758CC->frameTime = 33000; - D_802758CC->sndState = alHeapDBAlloc(NULL, 0, (ALHeap *)arg0->unkC, 1, arg0->unk0 * sizeof(N_AL_Struct81s)); - alEvtqNew(&D_802758CC->evtq, alHeapDBAlloc(NULL, 0, (ALHeap *)arg0->unkC, 1, arg0->unk4 * sizeof(ALEventListItem)), arg0->unk4); + D_802758CC->sndState = alHeapAlloc((ALHeap *)arg0->heap, 1, arg0->unk0 * sizeof(N_AL_Struct81s)); + alEvtqNew(&D_802758CC->evtq, alHeapAlloc((ALHeap *)arg0->heap, 1, arg0->unk4 * sizeof(ALEventListItem)), arg0->unk4); D_802758C0.unk8 = D_802758CC->sndState; for(var_s0 = 1; var_s0 < arg0->unk0; var_s0++){ var_v0 = (N_AL_Struct81s *)D_802758CC->sndState; temp_a0 = var_s0 + var_v0; alLink((ALLink *)temp_a0, (ALLink*)(temp_a0 - 1)); } - D_8027EF14 = alHeapDBAlloc(NULL, 0, (ALHeap *)arg0->unkC, 2, (s32) arg0->unk10); + D_8027EF14 = alHeapAlloc((ALHeap *)arg0->heap, 2, (s32) arg0->unk10); for(var_s0 = 0; var_s0 < arg0->unk10; var_s0++){ D_8027EF14[var_s0] = 0x7FFF; } diff --git a/src/core1/graphics_thread.c b/src/core1/graphics_thread.c index 4df502bf2..f7572d8ae 100644 --- a/src/core1/graphics_thread.c +++ b/src/core1/graphics_thread.c @@ -26,11 +26,10 @@ #define UNKFLAG1_TASK_YIELDED 0x20 /* .extern */ -extern u8 n_aspMainTextStart[]; +// n_aspMainTextStart/n_aspMainDataStart come from (via core1/music.h) extern u8 gSPF3DEX_fifoTextStart[]; extern u8 gSPL3DEX_fifoTextStart[]; -extern u8 n_aspMainDataStart[]; extern u8 gSPF3DEX_fifoDataStart[]; extern u8 gSPL3DEX_fifoDataStart[]; @@ -143,8 +142,8 @@ void thread5_insertGfxTaskData(OSMesg arg0) { void thread5_startAudioTask(struct ucode_task_data_s *task_data) { #if 0 // [port] microcode boot pointers, there is no RSP to load them into ucode_getPtrAndSize(&sAudTask.t.ucode_boot, &sAudTask.t.ucode_boot_size); - sAudTask.t.ucode = n_aspMainTextStart; - sAudTask.t.ucode_data = n_aspMainDataStart; + sAudTask.t.ucode = (u64 *) n_aspMainTextStart; + sAudTask.t.ucode_data = (u64 *) n_aspMainDataStart; #endif sAudTask.t.data_ptr = (void*) task_data->data_ptr; sAudTask.t.data_size = ((u8 *)task_data->data_ptr_end - (u8 *)task_data->data_ptr) >> 3 << 3; diff --git a/src/core1/musicplayer.c b/src/core1/musicplayer.c index ba238ec90..1fb9e0dd4 100644 --- a/src/core1/musicplayer.c +++ b/src/core1/musicplayer.c @@ -1,57 +1,45 @@ // BanjoDecomp: musicplayer.c #include -#include "core1/core1.h" #include "functions.h" #include "variables.h" -#include "musicplayer.h" - #include "version.h" -extern void func_8024FDDC(u8, s32); +#include "core1/core1.h" void func_8025AE50(s32, f32); - -bool func_80250074(u8); -void musicTrack_setVolume(u8, s32); -void func_8024FC1C(u8, s32); void func_8025AC20(enum comusic_e, s32, s32, f32, char*, s32); -void func_8025AC7C(enum comusic_e comusic_id, s32 arg1, s32 arg2, f32 arg3, void *arg4, char *arg5, s32 arg6); -void coMusicPlayer_free(void); -void func_8025A55C(s32, s32, s32); +void func_8025AC7C(enum comusic_e, s32, s32, f32, void *, const char *, s32); void func_8025A7DC(enum comusic_e); -void func_8025ABB8(enum comusic_e, s32, s32, s32); /* .bss */ -CoMusic *D_80276E30 = NULL; //active track ptr -int D_80276E34 = 0; +CoMusic *comusicTracks = NULL; // Pointer to the first CoMusic struct. Additional are saved after in memory. The first track is the primary track. +bool sProcessVolumeChange = FALSE; /* .code */ /** * @brief returns a pointer to the CoMusic struct with the corresponding track_id - * if it exists OR the first free CoMusic struct. - * - * @param track_id - * @return CoMusic* + * if it exists OR the first free CoMusic struct. This also skips the first CoMusic in the search. + * + * @param track_id + * @return CoMusic* */ -CoMusic *findTrack(enum comusic_e track_id) { - CoMusic *iMusPtr; - CoMusic *freeSlotPtr; - - freeSlotPtr = NULL; - for(iMusPtr = D_80276E30 + 1; iMusPtr < D_80276E30 + 5; iMusPtr++) { - if (track_id == iMusPtr->track_id) { - return iMusPtr; +CoMusic *comusic_findTrack(enum comusic_e track_id) { + CoMusic *i_ptr, *first_free = NULL; + + for (i_ptr = &comusicTracks[1]; i_ptr < &comusicTracks[NUM_MUSIC_SLOTS - 1]; i_ptr++) { + if (i_ptr->track_id == track_id) { + return i_ptr; } - if (freeSlotPtr == 0) { - if ((s32) iMusPtr->track_id < 0) { - freeSlotPtr = iMusPtr; - } + + if ((first_free == NULL) && (i_ptr->track_id < 0)) { + first_free = i_ptr; } } - return freeSlotPtr; + + return first_free; } -void func_80259914(CoMusic *this, s32 arg1, s32 arg2){ +void comusic_func_80259914(CoMusic *this, s32 arg1, s32 arg2) { s32 sp2C; s32 i; struct12s *tmp; @@ -60,128 +48,159 @@ void func_80259914(CoMusic *this, s32 arg1, s32 arg2){ for(i = 0; i < 0xE; i++){ this->unk1C[i] = 0; } - tmp = (struct12s *)freelist_next(&this->unk18, &sp2C); - tmp->unk0 = arg1; - tmp->unk1 = arg2; + + tmp = (struct12s *)freelist_next(&this->unk18, &sp2C); + tmp->volume_1 = arg1; + tmp->volume_2 = arg2; } -void func_80259994(CoMusic *this, s32 arg1){ - func_80259914(this, arg1, arg1); +void comusic_func_80259994(CoMusic *this, s32 volume) { + comusic_func_80259914(this, volume, volume); } -void func_802599B4(CoMusic *this){ - func_80259994(this, gcMusic_getDefaultVolumeForTrack(this->track_id)); +void comusic_func_802599B4(CoMusic *this) { + comusic_func_80259994(this, gcMusic_getDefaultVolumeForTrack(this->track_id)); + this->track_id = -1; this->unk14 = 0; - this->unk15 = 0; - func_8024FC1C(this - D_80276E30, -1); + this->unk15 = FALSE; + + musicSlot_func_8024FC1C(this - comusicTracks, -1); } -void coMusicPlayer_init(void){ - CoMusic * iPtr; - s32 i; - - if(D_80276E30 != NULL) +void coMusicPlayer_init(void) { + CoMusic *i_ptr; + int i; + + if (comusicTracks != NULL) { coMusicPlayer_free(); + } + + comusicTracks = (CoMusic *) bk_malloc(NUM_MUSIC_SLOTS * sizeof(CoMusic)); - D_80276E30 = (CoMusic *) bk_malloc(6*sizeof(CoMusic)); - for(iPtr = D_80276E30; iPtr < D_80276E30 + 6; iPtr++){ - iPtr->track_id = -1; - iPtr->volume = 0; - iPtr->unk12 = 0; - iPtr->unkC = 0; - iPtr->unk4 = 0.0f; - iPtr->unk14 = 0; - iPtr->unk15 = 0; - iPtr->unk0 = 0.0f; - iPtr->unk18 = (FREE_LIST(struct12s) *)freelist_new(sizeof(struct12s),4); - for(i = 0; i < 0xE; i++){ - iPtr->unk1C[i] = 0; + for (i_ptr = &comusicTracks[0]; i_ptr < &comusicTracks[NUM_MUSIC_SLOTS]; i_ptr++) { + i_ptr->track_id = -1; + i_ptr->volume = 0; + i_ptr->volume_change = 0; + i_ptr->destination_volume = 0; + i_ptr->unk4 = 0.0f; + i_ptr->unk14 = 0; + i_ptr->unk15 = FALSE; + i_ptr->volume_change_wait_timer = 0.0f; + i_ptr->unk18 = (FREE_LIST(struct12s) *) freelist_new(sizeof(struct12s), 4); + + for (i = 0; i < 0xE; i++) { + i_ptr->unk1C[i] = 0; } } } -//comusic_freeAll -void coMusicPlayer_free(void){ - CoMusic *iPtr; - func_8024FB8C(); - func_8024F83C(); +void coMusicPlayer_free(void) { + CoMusic *i_ptr; + + musicSlot_stopAll(); + musicTrack_releaseAll(); - for(iPtr = D_80276E30; iPtr < D_80276E30 + 6; iPtr++){ - freelist_free(iPtr->unk18); + for (i_ptr = &comusicTracks[0]; i_ptr < &comusicTracks[NUM_MUSIC_SLOTS]; i_ptr++) { + freelist_free(i_ptr->unk18); } - bk_free(D_80276E30); - D_80276E30 = NULL; + + bk_free(comusicTracks); + comusicTracks = NULL; } -s32 coMusicPlayer_getTrackCount(void){ - CoMusic * iPtr; - s32 cnt = 0; - for(iPtr = D_80276E30; iPtr < D_80276E30 + 6; iPtr++){ - if(iPtr->track_id >= 0) - cnt++; +s32 coMusicPlayer_getTrackCount(void) { + CoMusic *i_ptr; + s32 count = 0; + + for (i_ptr = &comusicTracks[0]; i_ptr < &comusicTracks[NUM_MUSIC_SLOTS]; i_ptr++) { + if (i_ptr->track_id >= 0) { + count++; + } } - return cnt; + + return count; } void coMusicPlayer_update(void) { - s32 temp_lo; - CoMusic *var_s0; + s32 music_slot; + CoMusic *i_ptr; f32 dt; - dt = time_getDelta(); - for(var_s0 = D_80276E30; var_s0 < &D_80276E30[6]; var_s0++){ - if (var_s0->track_id >= 0) { - temp_lo = var_s0 - D_80276E30; - var_s0->unk4 = ml_min_f(var_s0->unk4 + dt, 600.0f); - if ((var_s0->unk4 > 1.0f) && func_80250074(temp_lo)) { - func_8025A7DC(var_s0->track_id); + + for (i_ptr = &comusicTracks[0]; i_ptr < &comusicTracks[NUM_MUSIC_SLOTS]; i_ptr++) { + if (i_ptr->track_id >= 0) { + music_slot = i_ptr - comusicTracks; + i_ptr->unk4 = ml_min_f(i_ptr->unk4 + dt, 600.0f); + + if ((i_ptr->unk4 > 1.0f) && musicSlot_hasStopped(music_slot)) { + func_8025A7DC(i_ptr->track_id); } } } + func_8024FF34(); - if (!D_80276E34) + + if (!sProcessVolumeChange) { return; + } - D_80276E34 = false; - for(var_s0 = D_80276E30; var_s0 < &D_80276E30[6]; var_s0++){ - if (var_s0->track_id >= 0) { - if (var_s0->unk12 != 0) { - temp_lo = var_s0 - D_80276E30; - if (var_s0->unk0 > 0.0f) { - var_s0->unk0 -= time_getDelta(); - D_80276E34 = true; - } else if (var_s0->unk12 < 0) { - var_s0->volume += var_s0->unk12; - if (var_s0->unk15 && (var_s0->unkC == 0) && (var_s0->volume <= 0)) { - func_802599B4(var_s0); - continue; - } else { - if (var_s0->unkC >= var_s0->volume) { - var_s0->volume = var_s0->unkC; - var_s0->unk12 = 0; - } else { - D_80276E34 = true; - } - musicTrack_setVolume(temp_lo, (s16)var_s0->volume); - } - } else if (var_s0->volume < var_s0->unkC) { - if (var_s0->volume == 0) { - var_s0->unk4 = 0.0f; - } - var_s0->volume += var_s0->unk12; - if (var_s0->volume >= var_s0->unkC) { - var_s0->volume = var_s0->unkC; - var_s0->unk12 = 0; + sProcessVolumeChange = FALSE; + + for (i_ptr = &comusicTracks[0]; i_ptr < &comusicTracks[NUM_MUSIC_SLOTS]; i_ptr++) { + if (i_ptr->track_id < 0) { + continue; + } + + if (i_ptr->volume_change != 0) { + music_slot = i_ptr - comusicTracks; + + // The volume change begins only after the wait timer expires + if (i_ptr->volume_change_wait_timer > 0.0f) { + i_ptr->volume_change_wait_timer -= time_getDelta(); + sProcessVolumeChange = TRUE; + continue; + } + + // Process volume decrease + if (i_ptr->volume_change < 0) { + i_ptr->volume += i_ptr->volume_change; + + if (i_ptr->unk15 && (i_ptr->destination_volume == 0) && (i_ptr->volume <= 0)) { + comusic_func_802599B4(i_ptr); + continue; + } else { + if (i_ptr->volume <= i_ptr->destination_volume) { + i_ptr->volume = i_ptr->destination_volume; + i_ptr->volume_change = 0; } else { - D_80276E34 = true; + sProcessVolumeChange = TRUE; } - musicTrack_setVolume(temp_lo, (s16)var_s0->volume); + musicSlot_setVolume(music_slot, i_ptr->volume); + } + + continue; + } + + // Process volume increase + if (i_ptr->volume < i_ptr->destination_volume) { + if (i_ptr->volume == 0) { + i_ptr->unk4 = 0.0f; + } + i_ptr->volume += i_ptr->volume_change; + if (i_ptr->volume >= i_ptr->destination_volume) { + i_ptr->volume = i_ptr->destination_volume; + i_ptr->volume_change = 0; } else { - var_s0->unk12 = 0; + sProcessVolumeChange = TRUE; } + musicSlot_setVolume(music_slot, i_ptr->volume); + + continue; } + + i_ptr->volume_change = 0; } } } @@ -194,11 +213,12 @@ void func_80259EA8(CoMusic *this, s32 *arg1, s32 *arg2){ struct12s *tmp_ptr; for(i = 1; i < cnt; i++){ - if(freelist_elementIsAlive(this->unk18, i)){ + if (freelist_elementIsAlive(this->unk18, i)) { tmp_ptr = (struct12s*)freelist_at(this->unk18, i); - if(tmp_ptr->unk0 < tmp_s1 || (tmp_s1 == tmp_ptr->unk0 && tmp_ptr->unk1 < tmp_s2)){ - tmp_s1 = tmp_ptr->unk0; - tmp_s2 = tmp_ptr->unk1; + + if (tmp_ptr->volume_1 < tmp_s1 || (tmp_s1 == tmp_ptr->volume_1 && tmp_ptr->volume_2 < tmp_s2)) { + tmp_s1 = tmp_ptr->volume_1; + tmp_s2 = tmp_ptr->volume_2; }//L80259F40 } } @@ -220,15 +240,15 @@ void func_80259F7C(CoMusic *self, s32 *arg1, s32 *arg2, s32 *arg3) { if (var_s2 < 0) { temp_v0 = (struct12s *)freelist_at(self->unk18, 1); - if (temp_v0->unk0 < gcMusic_getDefaultVolumeForTrack(self->track_id)) { + if (temp_v0->volume_1 < gcMusic_getDefaultVolumeForTrack(self->track_id)) { var_s2 = gcMusic_getDefaultVolumeForTrack(self->track_id); + } else { + var_s2 = temp_v0->volume_1; } - else{ - var_s2 = temp_v0->unk0; - } + if (*arg3 != 0) { temp_v0 = (struct12s *)freelist_at(self->unk18, *arg3); - *arg2 = temp_v0->unk1; + *arg2 = temp_v0->volume_2; freelist_freeElement(self->unk18, *arg3); *arg3 = 0; func_80259EA8(self, arg1, &sp34); @@ -238,79 +258,87 @@ void func_80259F7C(CoMusic *self, s32 *arg1, s32 *arg2, s32 *arg3) { if (*arg3 == 0) { temp_v0 = (struct12s *)freelist_at(self->unk18, 1); - if ((temp_v0->unk0 < var_s2) || ((var_s2 == temp_v0->unk0) && (sp34 >= temp_v0->unk1))) { - func_80259914(self, var_s2, sp34); + if ((temp_v0->volume_1 < var_s2) || ((var_s2 == temp_v0->volume_1) && (sp34 >= temp_v0->volume_2))) { + comusic_func_80259914(self, var_s2, sp34); } else { freelist_next(&self->unk18, arg3); } } + if (*arg3 != 0) { temp_v0 = (struct12s *)freelist_at(self->unk18, *arg3); - temp_v0->unk0 = var_s2; - temp_v0->unk1 = sp34; + temp_v0->volume_1 = var_s2; + temp_v0->volume_2 = sp34; } + func_80259EA8(self, arg1, arg2); } -void func_8025A104(enum comusic_e arg0, s32 arg1){ - if (arg0 != D_80276E30[0].track_id){ - func_8024FC1C(0, arg0); +void func_8025A104(enum comusic_e track_id, s32 volume) { + if (track_id != comusicTracks[0].track_id) { + musicSlot_func_8024FC1C(0, track_id); } - musicTrack_setVolume(0, (s16)arg1); - D_80276E30[0].track_id = (s16) arg0; - D_80276E30[0].volume = arg1; - D_80276E30[0].unk0 = 0.0f; - D_80276E30[0].unk12 = 0; - D_80276E30[0].unk4 = 0.0f; - D_80276E30[0].unk15 = 0; - func_80259994(&D_80276E30[0], arg1); -} -void func_8025A1A8(enum comusic_e arg0){ + musicSlot_setVolume(0, volume); + comusicTracks[0].track_id = (s16) track_id; + comusicTracks[0].volume = volume; + comusicTracks[0].volume_change_wait_timer = 0.0f; + comusicTracks[0].volume_change = 0; + comusicTracks[0].unk4 = 0.0f; + comusicTracks[0].unk15 = FALSE; + comusic_func_80259994(&comusicTracks[0], volume); +} - if (arg0 != D_80276E30[0].track_id){ - func_8024FC1C(0, arg0); - D_80276E30[0].track_id = (s16) arg0; - D_80276E30[0].volume = gcMusic_getDefaultVolumeForTrack(arg0); - D_80276E30[0].unk0 = 0.0f; - D_80276E30[0].unk12 = 0; - D_80276E30[0].unk4 = 0.0f; - D_80276E30[0].unk15 = 0; - func_80259994(&D_80276E30[0], D_80276E30[0].volume); +void func_8025A1A8(enum comusic_e arg0){ + if (arg0 == comusicTracks[0].track_id) { + return; } + + musicSlot_func_8024FC1C(0, arg0); + + comusicTracks[0].track_id = (s16) arg0; + comusicTracks[0].volume = gcMusic_getDefaultVolumeForTrack(arg0); + comusicTracks[0].volume_change_wait_timer = 0.0f; + comusicTracks[0].volume_change = 0; + comusicTracks[0].unk4 = 0.0f; + comusicTracks[0].unk15 = FALSE; + + comusic_func_80259994(&comusicTracks[0], comusicTracks[0].volume); } -void func_8025A23C(s32 arg0){ - CoMusic *music = &D_80276E30[5]; - s32 temp_v0; +void func_8025A23C(enum comusic_e track_id) { + CoMusic *last_music_track = &comusicTracks[NUM_MUSIC_SLOTS - 1]; + s32 volume; - if (arg0 != music->track_id){ - func_8024FC1C(5, arg0); - music->track_id = (s16) arg0; - temp_v0 = gcMusic_getDefaultVolumeForTrack(arg0); - music->volume = temp_v0; - music->unk12 = 0; - music->unk15 = 0; - music->unk0 = 0.0f; - music->unk4 = 0.0f; - func_80259994(music, temp_v0); + if (track_id == last_music_track->track_id){ + return; } + + musicSlot_func_8024FC1C(NUM_MUSIC_SLOTS - 1, track_id); + last_music_track->track_id = (s16) track_id; + volume = gcMusic_getDefaultVolumeForTrack(track_id); + last_music_track->volume = volume; + last_music_track->volume_change = 0; + last_music_track->unk15 = FALSE; + last_music_track->volume_change_wait_timer = 0.0f; + last_music_track->unk4 = 0.0f; + comusic_func_80259994(last_music_track, volume); } -void func_8025A2B0(void){ - func_802599B4(&D_80276E30[5]); +void func_8025A2B0(void) { + comusic_func_802599B4(&comusicTracks[NUM_MUSIC_SLOTS - 1]); } -void func_8025A2D8(void){ - func_802599B4(&D_80276E30[0]); +void func_8025A2D8(void) { + comusic_func_802599B4(&comusicTracks[0]); } void func_8025A2FC(s32 arg0, s32 arg1){ s32 i; func_8025A55C(arg0, arg1, 1); - for (i = 1; i < 5; i++){ - s16 val = D_80276E30[i].track_id; + for (i = 1; i < NUM_MUSIC_SLOTS - 1; i++){ + s16 val = comusicTracks[i].track_id; if (val >= 0){ func_8025ABB8(val, arg0, arg1, 1); } @@ -320,12 +348,13 @@ void func_8025A2FC(s32 arg0, s32 arg1){ void func_8025A388(s32 arg0, s32 arg1) { s32 i; - if (D_80276E30[0].unk14 == 0){ + if (comusicTracks->unk14 == 0){ func_8025A55C(arg0, arg1, 1); } - for (i = 1; i < 5; i++){ - if (D_80276E30[i].track_id >= 0 && D_80276E30[i].unk14 == 0){ - func_8025ABB8(D_80276E30[i].track_id, arg0, arg1, 1); + + for (i = 1; i < NUM_MUSIC_SLOTS - 1; i++) { + if (comusicTracks[i].track_id >= 0 && comusicTracks[i].unk14 == 0) { + func_8025ABB8(comusicTracks[i].track_id, arg0, arg1, 1); } } } @@ -334,238 +363,263 @@ void func_8025A430(s32 arg0, s32 arg1, s32 arg2){ s32 i; func_8025A55C(arg0, arg1, arg2); - for (i = 1; i < 5; i++){ - s16 val = D_80276E30[i].track_id; - if (val >= 0){ + + for (i = 1; i < NUM_MUSIC_SLOTS - 1; i++) { + s16 val = comusicTracks[i].track_id; + + if (val >= 0) { func_8025ABB8(val, arg0, arg1, arg2); } } } -void func_8025A4C4(s32 arg0, s32 arg1, s32 *arg2){ - if(D_80276E30[0].track_id >= 0){ - func_80259F7C(&D_80276E30[0], &arg0, &arg1, arg2); - if(arg0 != D_80276E30[0].volume){ - if(D_80276E30[0].volume < arg0){ - D_80276E30[0].unk12 = arg1; - } - else{ - D_80276E30[0].unk12 = -arg1; - } - D_80276E30[0].unkC = arg0; - D_80276E34 = 1; +void func_8025A4C4(s32 arg0, s32 arg1, s32 *arg2) { + if (comusicTracks[0].track_id < 0) { + return; + } + + func_80259F7C(&comusicTracks[0], &arg0, &arg1, arg2); + + if (arg0 != comusicTracks[0].volume) { + if (comusicTracks[0].volume < arg0) { + comusicTracks[0].volume_change = arg1; + } else { + comusicTracks[0].volume_change = -arg1; } + + comusicTracks[0].destination_volume = arg0; + sProcessVolumeChange = TRUE; } } -void func_8025A55C(s32 arg0, s32 arg1, s32 arg2){ - func_8025A4C4(arg0, arg1, &D_80276E30->unk1C[arg2]); +void func_8025A55C(s32 arg0, s32 arg1, s32 arg2) { + func_8025A4C4(arg0, arg1, &comusicTracks->unk1C[arg2]); } -void func_8025A58C(u32 arg0, u32 arg1){ +void func_8025A58C(u32 arg0, u32 arg1) { func_8025A55C(arg0, arg1, 0); } +void comusic_playMusic(enum comusic_e track_id, s32 volume, bool force_reinit) { + CoMusic *track; + s32 index; -void playMusic(enum comusic_e comusic_id, s32 volume, s32 arg2){ - CoMusic *tmp_a2; - s32 sp20; - - if(volume == -1){ - volume = gcMusic_getDefaultVolumeForTrack(comusic_id); + if (volume == -1) { + volume = gcMusic_getDefaultVolumeForTrack(track_id); } - tmp_a2 = findTrack(comusic_id); - if(tmp_a2 == NULL) + track = comusic_findTrack(track_id); + + if (track == NULL) { return; + } + + index = track - comusicTracks; - sp20 = (tmp_a2 - D_80276E30); - if(tmp_a2->track_id < 0 || arg2){ - switch(comusic_id){ + // Initialize the track if comusic_findTrack returned an empty + if (track->track_id < 0 || force_reinit) { + switch (track_id) { case COMUSIC_15_EXTRA_LIFE_COLLECTED: - if(gsworld_getMap() == MAP_10_BGS_MR_VILE){ + if (gsworld_getMap() == MAP_10_BGS_MR_VILE) { break; } case COMUSIC_3B_MINIGAME_VICTORY: case COMUSIC_3C_MINIGAME_LOSS: func_8025AE50(4000, 2.0f); } - tmp_a2->track_id = comusic_id; - tmp_a2->unk12 = 0; - tmp_a2->unk15 = 0; - tmp_a2->unk4 = 0.0f; - func_80259994(tmp_a2, volume); - func_8024FC1C(sp20, comusic_id); + + track->track_id = track_id; + track->volume_change = 0; + track->unk15 = FALSE; + track->unk4 = 0.0f; + comusic_func_80259994(track, volume); + musicSlot_func_8024FC1C(index, track_id); } - musicTrack_setVolume(sp20, (s16) volume); - tmp_a2->volume = volume; + musicSlot_setVolume(index, volume); + track->volume = volume; } -void coMusicPlayer_playMusicWeak(enum comusic_e track_id, s32 volume){ - playMusic(track_id, volume, 0); +// If comusic_findTrack returns the track, then do not re-initialize; just adust the volume +void coMusicPlayer_playMusicWeak(enum comusic_e track_id, s32 volume) { + comusic_playMusic(track_id, volume, FALSE); } -void coMusicPlayer_playMusic(enum comusic_e track_id, s32 volume){ - playMusic(track_id, volume, 1); +// Plays the track and reinitializes it +void coMusicPlayer_playMusic(enum comusic_e track_id, s32 volume) { + comusic_playMusic(track_id, volume, TRUE); } //comusic_queueTrack -void comusic_playTrack(enum comusic_e track_id){ +void comusic_playTrack(enum comusic_e track_id) { CoMusic *trackPtr; s32 indx; - trackPtr = findTrack(track_id); - if(trackPtr == NULL) + trackPtr = comusic_findTrack(track_id); + + if (trackPtr == NULL) { return; - - indx = trackPtr - D_80276E30; - if(trackPtr->track_id < 0){ + } + + indx = trackPtr - comusicTracks; + + if (trackPtr->track_id < 0) { trackPtr->track_id = track_id; - trackPtr->unk12 = 0; + trackPtr->volume_change = 0; trackPtr->unk4 = 0.0f; - func_8024FC1C( indx, track_id); - func_80259994(trackPtr, trackPtr->volume = gcMusic_getDefaultVolumeForTrack(track_id)); + musicSlot_func_8024FC1C( indx, track_id); + comusic_func_80259994(trackPtr, trackPtr->volume = gcMusic_getDefaultVolumeForTrack(track_id)); } - } -void func_8025A788(enum comusic_e comusic_id, f32 delay1, f32 delay2){ - timedFunc_set_1(delay1, (GenFunction_1) comusic_playTrack, comusic_id); - timedFunc_set_1(delay1 + delay2, (GenFunction_1) func_8025A7DC, comusic_id); +void func_8025A788(enum comusic_e track_id, f32 delay1, f32 delay2) { + timedFunc_set_1(delay1, (GenFunction_1) comusic_playTrack, track_id); + timedFunc_set_1(delay1 + delay2, (GenFunction_1) func_8025A7DC, track_id); } -void func_8025A7DC(enum comusic_e track_id){ +void func_8025A7DC(enum comusic_e track_id) { CoMusic *trackPtr; - trackPtr = findTrack(track_id); + trackPtr = comusic_findTrack(track_id); + if (trackPtr != NULL && trackPtr->track_id >= 0){ - func_802599B4(trackPtr); + comusic_func_802599B4(trackPtr); } } -s32 func_8025A818(void){ - if (D_80276E30[0].unkC == 0 && D_80276E30[0].volume <= 0){ - func_802599B4(&D_80276E30[0]); +s32 func_8025A818(void) { + if (comusicTracks[0].destination_volume == 0 && comusicTracks[0].volume <= 0){ + comusic_func_802599B4(&comusicTracks[0]); return 1; } + return 0; } s32 func_8025A864(enum comusic_e track_id){ CoMusic *trackPtr; - trackPtr = findTrack(track_id); - if (trackPtr != NULL && trackPtr->unkC == 0 && trackPtr->volume <= 0){ - func_802599B4(trackPtr); + trackPtr = comusic_findTrack(track_id); + + if (trackPtr != NULL && trackPtr->destination_volume == 0 && trackPtr->volume <= 0){ + comusic_func_802599B4(trackPtr); return 1; } + return 0; } void func_8025A8B8(enum comusic_e track_id, s32 arg1){ - CoMusic *trackPtr; + CoMusic *trackPtr = comusic_findTrack(track_id); - trackPtr = findTrack(track_id); if (trackPtr != NULL){ trackPtr->unk14 = arg1; } } void func_8025A8E4(s32 arg0) { - if (D_80276E30[0].track_id >= 0) { - D_80276E30[0].unk14 = arg0; + if (comusicTracks[0].track_id < 0) { + return; } + + comusicTracks[0].unk14 = arg0; } void func_8025A904(void){ - CoMusic *trackPtr = &D_80276E30[0]; + CoMusic *i_ptr; - while (trackPtr < &D_80276E30[6]){ - if (trackPtr->track_id >= 0){ - func_802599B4(trackPtr); + for (i_ptr = &comusicTracks[0]; i_ptr < &comusicTracks[NUM_MUSIC_SLOTS]; i_ptr++) { + if (i_ptr->track_id >= 0) { + comusic_func_802599B4(i_ptr); } - trackPtr++; } } //dequeue_allTracks void func_8025A96C(void){ - CoMusic *iPtr; + CoMusic *i_ptr; - for(iPtr = &D_80276E30[1]; iPtr < &D_80276E30[6]; iPtr++){ - if(iPtr->track_id >= 0){ - func_802599B4(iPtr); + for (i_ptr = &comusicTracks[1]; i_ptr < &comusicTracks[NUM_MUSIC_SLOTS]; i_ptr++) { + if (i_ptr->track_id >= 0) { + comusic_func_802599B4(i_ptr); } } } //dequeue_allTracks void func_8025A9D4(void){ - CoMusic *iPtr; + CoMusic *i_ptr; - for(iPtr = &D_80276E30[0]; iPtr < &D_80276E30[6]; iPtr++){ - if(iPtr->track_id >= 0 && !iPtr->unk14){ - func_802599B4(iPtr); + for (i_ptr = &comusicTracks[0]; i_ptr < &comusicTracks[NUM_MUSIC_SLOTS]; i_ptr++) { + if (i_ptr->track_id >= 0 && !i_ptr->unk14) { + comusic_func_802599B4(i_ptr); } } } //dequeue_nonmainTracks void func_8025AA48(void){ - CoMusic *iPtr; + CoMusic *i_ptr; - for(iPtr = &D_80276E30[1]; iPtr < &D_80276E30[6]; iPtr++){ - if(iPtr->track_id >= 0 && !iPtr->unk14){ - func_802599B4(iPtr); + for (i_ptr = &comusicTracks[1]; i_ptr < &comusicTracks[NUM_MUSIC_SLOTS]; i_ptr++) { + if (i_ptr->track_id >= 0 && !i_ptr->unk14) { + comusic_func_802599B4(i_ptr); } } } //dequeue_track? -void func_8025AABC(enum comusic_e track_id){ +void func_8025AABC(enum comusic_e track_id) { CoMusic *trackPtr; - - if(trackPtr = findTrack(track_id)){ - trackPtr->unk15 = 1; - if(!trackPtr->volume) - func_802599B4(trackPtr); + + trackPtr = comusic_findTrack(track_id); + + if (!trackPtr) { + return; } -} -void func_8025AB00(void){ - D_80276E30[0].unk15 = 1; - if (!D_80276E30[0].volume){ - func_802599B4(&D_80276E30[0]); + trackPtr->unk15 = TRUE; + + if (!trackPtr->volume) { + comusic_func_802599B4(trackPtr); } } -void comusic_8025AB44(enum comusic_e comusic_id, s32 arg1, s32 arg2){ - func_8025AC20(comusic_id, arg1, arg2, 0.0f, "comusic.c", VER_SELECT(0x39e, 0x39f, 0, 0)); +void func_8025AB00(void) { + comusicTracks[0].unk15 = TRUE; + + if (comusicTracks[0].volume){ + return; + } + comusic_func_802599B4(&comusicTracks[0]); } -void comusic_8025AB78(enum comusic_e comusic_id, s32 arg1, s32 arg2, s32 arg3){ - CoMusic *track = findTrack(comusic_id); +void comusic_8025AB44(enum comusic_e track_id, s32 arg1, s32 arg2) { + func_8025AC20(track_id, arg1, arg2, 0.0f, "comusic.c", VER_SELECT(926, 927, 0, 0)); +} + +void comusic_8025AB78(enum comusic_e track_id, s32 arg1, s32 arg2, s32 arg3) { + CoMusic *track = comusic_findTrack(track_id); // [port] null check if (!track) return; - func_8025AC7C(comusic_id, arg1, arg2, 0.0f, &track->unk1C[arg3], "comusic.c", VER_SELECT(0x3a3, 0x3a4, 0, 0)); + func_8025AC7C(track_id, arg1, arg2, 0.0f, &track->unk1C[arg3], "comusic.c", VER_SELECT(931, 932, 0, 0)); } -void func_8025ABB8(enum comusic_e comusic_id, s32 arg1, s32 arg2, s32 arg3){ - func_8025AC7C(comusic_id, arg1, arg2, 0.0f, &(findTrack(comusic_id)->unk1C[arg3]), "comusic.c", VER_SELECT(0x3aa, 0x3ab,0,0)); +void func_8025ABB8(enum comusic_e track_id, s32 arg1, s32 arg2, s32 arg3) { + func_8025AC7C(track_id, arg1, arg2, 0.0f, &(comusic_findTrack(track_id)->unk1C[arg3]), "comusic.c", VER_SELECT(938, 939, 0, 0)); } -void func_8025AC20(enum comusic_e comusic_id, s32 arg1, s32 arg2, f32 arg3, char* arg4, s32 char5){ - func_8025AC7C(comusic_id, arg1, arg2, 0.0f, findTrack(comusic_id)->unk1C, "comusic.c", VER_SELECT(0x3b1, 0x3b2,0,0)); +void func_8025AC20(enum comusic_e track_id, s32 arg1, s32 arg2, f32 arg3, char* arg4, s32 char5) { + func_8025AC7C(track_id, arg1, arg2, 0.0f, comusic_findTrack(track_id)->unk1C, "comusic.c", VER_SELECT(945, 946, 0, 0)); } -void func_8025AC7C(enum comusic_e comusic_id, s32 arg1, s32 arg2, f32 arg3, void *arg4, char* arg5, s32 arg6){ +void func_8025AC7C(enum comusic_e track_id, s32 arg1, s32 arg2, f32 arg3, void *arg4, const char *filename, s32 arg6){ CoMusic *trackPtr; u32 slot_index; - s32 *fadeSlot = (s32 *)arg4; + s32 *fadeSlot = (s32 *)arg4; // [port] passed as void* for 64-bit pointer safety //get track location - trackPtr = findTrack(comusic_id); + trackPtr = comusic_findTrack(track_id); if(trackPtr == NULL) return; @@ -573,69 +627,76 @@ void func_8025AC7C(enum comusic_e comusic_id, s32 arg1, s32 arg2, f32 arg3, void if(trackPtr->track_id < 0){ //Track not loaded if(arg1 == 0) return; - slot_index = (trackPtr - D_80276E30); - func_8024FC1C(slot_index, comusic_id); - trackPtr->track_id = comusic_id; + slot_index = (trackPtr - comusicTracks); + musicSlot_func_8024FC1C(slot_index, track_id); + trackPtr->track_id = track_id; trackPtr->volume = 0; - trackPtr->unk15 = 0; + trackPtr->unk15 = FALSE; trackPtr->unk4 = 0.0f; - func_80259994(trackPtr, 0); - musicTrack_setVolume(slot_index, 0); + comusic_func_80259994(trackPtr, 0); + musicSlot_setVolume(slot_index, 0); } func_80259F7C(trackPtr,&arg1, &arg2, fadeSlot); - trackPtr->unk0 = arg3; - trackPtr->unk12 = (trackPtr->volume < arg1)? arg2: -arg2; - trackPtr->unkC = arg1; - D_80276E34 = 1; + trackPtr->volume_change_wait_timer = arg3; + trackPtr->volume_change = (trackPtr->volume < arg1)? arg2: -arg2; + trackPtr->destination_volume = arg1; + sProcessVolumeChange = TRUE; } -//comusic_trackQueued -int func_8025AD7C(enum comusic_e arg0){ - CoMusic * trackPtr = findTrack(arg0); - return (trackPtr == NULL || trackPtr->track_id == -1)? 0 : 1; +bool comusic_isTrackQueued(enum comusic_e track_id) { + CoMusic *track = comusic_findTrack(track_id); + return ((track == NULL) || (track->track_id == -1)) ? FALSE : TRUE; } -//comusic_isPrimaryTrack -int func_8025ADBC(enum comusic_e arg0){ - return D_80276E30[0].track_id == arg0; +bool comusic_isPrimaryTrack(enum comusic_e track_id) { + return comusicTracks[0].track_id == track_id; } -s32 func_8025ADD4(enum comusic_e id){ - CoMusic * ptr = findTrack(id); - return ptr - D_80276E30; +s32 comusic_getTrackPosition(enum comusic_e track_id) { + CoMusic *track = comusic_findTrack(track_id); + return track - comusicTracks; } -void func_8025AE0C(s32 arg0, f32 arg1){ +void func_8025AE0C(s32 arg0, f32 time) { func_8025A58C(0, arg0); - timedFunc_set_2(arg1, (GenFunction_2)func_8025A58C, -1, arg0); + timedFunc_set_2(time, (GenFunction_2)func_8025A58C, -1, arg0); } -void func_8025AE50(s32 arg0, f32 arg1){ +void func_8025AE50(s32 arg0, f32 time) { func_8025A430(0, arg0, 6); - timedFunc_set_3(arg1, (GenFunction_3)func_8025A430, -1, arg0, 6); + timedFunc_set_3(time, (GenFunction_3)func_8025A430, -1, arg0, 6); } -void func_8025AEA0(enum comusic_e track_id, s32 arg1){ - CoMusic *ptr = findTrack(track_id); - - if(!ptr) return; - func_8024FDDC(ptr - D_80276E30, arg1); +void func_8025AEA0(enum comusic_e track_id, s32 arg1) { + CoMusic *track = comusic_findTrack(track_id); + + if (!track) { + return; + } + + musicSlot_setTempo(track - comusicTracks, arg1); } -int func_8025AEEC(void){ - s32 out = func_802501A0(0, 0x6A, 0); - if(out) - func_80250170(0, 0x6A, 0); +int func_8025AEEC(void) { + s32 out = musicSlot_func_802501A0(0, 0x6A, NULL); + + if (out) { + musicSlot_func_80250170(0, 0x6A, 0); + } + return out; } -void comusic_defrag(void){ - CoMusic *iPtr; +void comusic_defrag(void) { + CoMusic *i_ptr; - if(!D_80276E30) return; + if (!comusicTracks) { + return; + } - for(iPtr = &D_80276E30[0]; iPtr < &D_80276E30[6]; iPtr++){ - iPtr->unk18 = (FREE_LIST(struct12s) *)freelist_defrag(iPtr->unk18); + for (i_ptr = &comusicTracks[0]; i_ptr < &comusicTracks[NUM_MUSIC_SLOTS]; i_ptr++) { + i_ptr->unk18 = (FREE_LIST(struct12s) *) freelist_defrag(i_ptr->unk18); } - D_80276E30 = (CoMusic *)defrag(D_80276E30); + + comusicTracks = (CoMusic *) defrag(comusicTracks); } diff --git a/src/core1/musicplayer.h b/src/core1/musicplayer.h deleted file mode 100644 index 1fd913058..000000000 --- a/src/core1/musicplayer.h +++ /dev/null @@ -1,7 +0,0 @@ -// BanjoDecomp: core1/musicplayer.h -#ifndef BANJO_KAZOOIE_MUSICPLAYER_H -#define BANJO_KAZOOIE_MUSICPLAYER_H - -#define MAX_MUSIC_STRUCT_COUNT 6 - -#endif // BANJO_KAZOOIE_MUSICPLAYER_H diff --git a/src/core1/n_audio/n_csplayer.c b/src/core1/n_audio/n_csplayer.c index a92c0852d..722cad573 100644 --- a/src/core1/n_audio/n_csplayer.c +++ b/src/core1/n_audio/n_csplayer.c @@ -17,7 +17,7 @@ ALVoiceState *__n_mapVoice(ALSeqPlayer *, u8, u8, u8); ALSound *__n_lookupSoundQuick(ALSeqPlayer *, u8, u8, u8); void __n_seqpReleaseVoice(ALSeqPlayer *seqp, ALVoice *voice, ALMicroTime deltaTime); char __alCSeqNextDelta(ALCSeq *seq, s32 *pDeltaTicks); -void func_80250104(ALCSeq *arg0, s32 arg1, s32 arg2); +void musicSlot_func_80250104(ALCSeq *cseq, s32 arg1, s32 chan); /*==================================================================== * csplayer.c @@ -746,7 +746,7 @@ static void __n_CSPHandleMIDIMsg(N_ALCSPlayer *seqp, ALEvent *event) case 0x75: /* switch 2 */ case 0x76: /* switch 2 */ case 0x77: /* switch 2 */ - func_80250104(seqp->target, byte1, chan); + musicSlot_func_80250104(seqp->target, byte1, chan); break; /* case (AL_MIDI_FX_CTRL_0): case (AL_MIDI_FX_CTRL_1): diff --git a/src/core2/anim/anim_bonetransform.c b/src/core2/anim/anim_bonetransform.c index f9a2d5f62..db1ec7674 100644 --- a/src/core2/anim/anim_bonetransform.c +++ b/src/core2/anim/anim_bonetransform.c @@ -17,7 +17,7 @@ f32 D_803709E0[] = { s32 assetCacheCurrentSize = 0; u8 assetCacheLength = 0; //assetCache_size; u8 assetCacheCurrentIndex = 0; - u8 D_80370A1C = 0; + u8 D_80370A1C = FALSE; /* .bss */ @@ -390,8 +390,8 @@ BKSprite *codeB3A80_getSprite(enum asset_e sprite_id, BKSpriteDisplayData **arg1 return s0; } -void func_8033B788(void ){ - D_80370A1C = 1; +void assetcache_func_8033B788(void) { + D_80370A1C = TRUE; } void *assetcache_get(enum asset_e assetId) { @@ -424,10 +424,10 @@ void *assetcache_reload(enum asset_e assetId) { void *uncompressed_file;//sp34 u8 sp33; //sp33 void *compressed_file;//sp2C - s32 sp28;//sp28 + bool sp28; - sp28 = (s32 )D_80370A1C; - D_80370A1C = (u8)0U; + sp28 = D_80370A1C; + D_80370A1C = FALSE; for(i = 0; i < assetCacheLength && assetId != assetCacheAssetIdList[i]; i++); assetCacheCurrentIndex = i; if(i == 0x96) @@ -457,7 +457,7 @@ void *assetcache_reload(enum asset_e assetId) { compressed_file = (void *)((s32) uncompressed_file + uncomp_size); } else { sp33 = 2; - if (sp28 != 0) { + if (sp28) { func_80254C98(); } uncompressed_file = bk_malloc(uncomp_size); @@ -500,7 +500,7 @@ void assetCache_resizeAsset(void *assetPtr, s32 size){ void assetCache_init(void){ // Lighthouse TODO assets - D_80370A1C = 0; + D_80370A1C = FALSE; func_8033B180(); assetCachePtrList = (void **)bk_malloc(150*sizeof(void*)); // Lighthouse [port] Changed from 600 to sizeof diff --git a/src/core2/ba/marker.c b/src/core2/ba/marker.c index 82519a10e..1f232124e 100644 --- a/src/core2/ba/marker.c +++ b/src/core2/ba/marker.c @@ -585,7 +585,7 @@ void __baMarker_resolveCollision(Prop *other_prop){ __baMarker_8028B848(); } - if (func_8025AD7C(COMUSIC_30_5TH_JINJO_COLLECTED) && EventSystem_Should(VB_PLAY_JIGGY_DANCE, true)) { + if (comusic_isTrackQueued(COMUSIC_30_5TH_JINJO_COLLECTED) && EventSystem_Should(VB_PLAY_JIGGY_DANCE, true)) { __baMarker_8028B8DC(); } __spawnQueue_add_4((GenFunction_4)__baMarker_8028B904, reinterpret_cast(u32, other_prop->actorProp.x), reinterpret_cast(u32, other_prop->actorProp.y), reinterpret_cast(u32, other_prop->actorProp.z), jiggy_id); @@ -942,8 +942,8 @@ void baMarker_update(void){ Prop *other_prop; if ((D_8037BF88 != 0)){ - temp_s0 = func_8024FEEC(func_8025ADD4(COMUSIC_30_5TH_JINJO_COLLECTED) & 0xFF); - if((coMusicPlayer_getTrackCount() < 4 && temp_s0 >= 0xBB9) || !func_8025AD7C(COMUSIC_30_5TH_JINJO_COLLECTED)){ + temp_s0 = musicSlot_getCSeqTicks(comusic_getTrackPosition(COMUSIC_30_5TH_JINJO_COLLECTED)); + if((coMusicPlayer_getTrackCount() < 4 && temp_s0 >= 0xBB9) || !comusic_isTrackQueued(COMUSIC_30_5TH_JINJO_COLLECTED)){ func_8028F918(0); D_8037BF88 = 0; } diff --git a/src/core2/ch/snacker.c b/src/core2/ch/snacker.c index 63d518b95..4ad8c74e3 100644 --- a/src/core2/ch/snacker.c +++ b/src/core2/ch/snacker.c @@ -137,7 +137,7 @@ static void __chsnacker_die(ActorMarker *marker, ActorMarker *other){ void func_802E0FC4(Actor *this){ s_chSnacker_marker = NULL; D_8037E630 = this->unk166; - if(func_8025AD7C(COMUSIC_34_SNACKER_DANGER)){ + if(comusic_isTrackQueued(COMUSIC_34_SNACKER_DANGER)){ func_8025AABC(COMUSIC_34_SNACKER_DANGER); func_8025A7DC(COMUSIC_34_SNACKER_DANGER); } diff --git a/src/core2/frame/rendermem.c b/src/core2/frame/rendermem.c index 865009e91..bda7df47c 100644 --- a/src/core2/frame/rendermem.c +++ b/src/core2/frame/rendermem.c @@ -85,7 +85,7 @@ void func_802E3460(s32 arg0) { } else if (D_8037E8C0.unk14 == 1) { D_8037E8C0.unk4 = 0.0f; - if (func_8025AD7C(COMUSIC_31_GAME_OVER)) { + if (comusic_isTrackQueued(COMUSIC_31_GAME_OVER)) { comusic_8025AB44(COMUSIC_31_GAME_OVER, 0, 200); } func_802F1934(D_8037E8C0.unk10, getActiveFramebuffer()); diff --git a/src/core2/gc/zoombox.c b/src/core2/gc/zoombox.c index 6a59d9769..1324910f7 100644 --- a/src/core2/gc/zoombox.c +++ b/src/core2/gc/zoombox.c @@ -437,7 +437,7 @@ void func_803382FC(s32); void func_80315200(GcZoombox *this){ s32 s1 = 0; if(-1.0f == this->unk110[0]){ - if(func_8025AD7C(this->unk108[0])){ + if(comusic_isTrackQueued(this->unk108[0])){ func_8025A7DC(this->unk108[0]); } }else{ @@ -546,7 +546,7 @@ void func_803155C8(GcZoombox *this){ this->unk1A4_26 = 0; this->unk1A4_31 = 0; if(-1.0f == this->unk110[0]){ - if(func_8025AD7C(this->unk108[0])){ + if(comusic_isTrackQueued(this->unk108[0])){ func_8025A7DC(this->unk108[0]); } }else{ @@ -716,7 +716,7 @@ void func_80315C90(GcZoombox *this, s32 arg1) { } if (this->unk110[0] == -1.0f) { - if (func_8025AD7C(this->unk108[0]) == 0) { + if (comusic_isTrackQueued(this->unk108[0]) == 0) { comusic_playTrack(this->unk108[0]); } } else { diff --git a/src/core2/map/cutscene_skip.c b/src/core2/map/cutscene_skip.c index 18155463f..d552cace1 100644 --- a/src/core2/map/cutscene_skip.c +++ b/src/core2/map/cutscene_skip.c @@ -135,8 +135,8 @@ void func_8031CB50(enum map_e map_id, s32 exit_id, s32 arg2) { s32 sp1C; if ((D_80383190 == 0) && (getGameMode() != GAME_MODE_8_BOTTLES_BONUS) && (getGameMode() != GAME_MODE_7_ATTRACT_DEMO)) { - sp1C = func_803226E8(gsworld_getMap()); - if ((func_803226E8(map_id) != sp1C) && (func_80322914() == 0)) { + sp1C = core2_9B650_getMusicTrackFromMap(gsworld_getMap()); + if ((core2_9B650_getMusicTrackFromMap(map_id) != sp1C) && (func_80322914() == 0)) { func_8025A388(0, 0x4E2); func_8025AB00(); core1_ce60_incOrDecCounter(false); diff --git a/src/core2/map/cutscene_triggers.c b/src/core2/map/cutscene_triggers.c index b734f1179..9a736fff2 100644 --- a/src/core2/map/cutscene_triggers.c +++ b/src/core2/map/cutscene_triggers.c @@ -17,7 +17,6 @@ typedef struct struct_core2_9B180_s{ void (*unk10)(struct struct_core2_9B180_s *); }Struct_core2_9B180_0; -extern void func_8024FE44(u8, f32, f32); extern void func_8030EDAC(f32, f32); void func_80322298(Struct_core2_9B180_0 *); @@ -70,7 +69,7 @@ void func_80322130(Struct_core2_9B180_0 *arg0) { void func_803221C4(Struct_core2_9B180_0 * arg0){ - func_8024FE44(0, 0.2f, 1.25f); + musicSlot_func_8024FE44(0, 0.2f, 1.25f); } void func_803221F4(Struct_core2_9B180_0 * arg0){ @@ -82,7 +81,7 @@ void func_8032222C(Struct_core2_9B180_0 * arg0) { s32 phi_s0; for(phi_s0 = 1; phi_s0 < 5; phi_s0++){ - func_8024FE44(phi_s0, 0.2f, 1.25f); + musicSlot_func_8024FE44(phi_s0, 0.2f, 1.25f); } } @@ -181,7 +180,7 @@ void func_803224FC(void) { func_8030EDAC(0.0f, 1.0f); func_80244A98(1); for(i = 0; i < 5; i++){ - func_8024FE44(i, 0.0f, 1.0f); + musicSlot_func_8024FE44(i, 0.0f, 1.0f); } } diff --git a/src/core2/map/exit.c b/src/core2/map/exit.c index 565369751..24b2b7216 100644 --- a/src/core2/map/exit.c +++ b/src/core2/map/exit.c @@ -258,7 +258,7 @@ void func_8034BA20(void) { func_802E412C(1, 5); func_802E40A8(MAP_97_CS_END_BEACH_2, 0); func_802E40C4(1); - if (func_8025AD7C(5)) { + if (comusic_isTrackQueued(5)) { func_8025A7DC(5); } D_80386110 = 0; diff --git a/src/core2/map/gsworld.c b/src/core2/map/gsworld.c index 8426ecdcf..25f597866 100644 --- a/src/core2/map/gsworld.c +++ b/src/core2/map/gsworld.c @@ -218,7 +218,7 @@ void gsworld_free(void) { dialogBin_terminate(); playerModel_free(); if (!func_80322914()) { - func_8024F7C4(func_803226E8(sGsWorldData.map)); + musicTrack_release(core2_9B650_getMusicTrackFromMap(sGsWorldData.map)); } core1_7090_release(); AnimTextureListCache_free(); @@ -245,7 +245,7 @@ void gsworld_set(enum map_e arg0, s32 arg1, s32 arg2) { func_8038E7C4(); } if (func_80322914() == 0) { - func_8024F764(func_803226E8(sGsWorldData.map)); + musicTrack_load(core2_9B650_getMusicTrackFromMap(sGsWorldData.map)); } func_80320B84(); AnimTextureListCache_init(); diff --git a/src/core2/quiz/game.c b/src/core2/quiz/game.c index a058abd6e..d7d8ceca8 100644 --- a/src/core2/quiz/game.c +++ b/src/core2/quiz/game.c @@ -1332,7 +1332,7 @@ void func_802D6114(void){ func_802E4A70(); }//L802D6194 volatileFlag_set(VOLATILE_FLAG_21, 1); - if(sp24 != 0x1C || !func_8025ADBC(COMUSIC_23_MMM_INSIDE_CHURCH)){ + if(sp24 != 0x1C || !comusic_isPrimaryTrack(COMUSIC_23_MMM_INSIDE_CHURCH)){ musicKeepsPlaying(); } transitionToMap(sp24, sp20, 0); diff --git a/src/core2/sfx/instruments.c b/src/core2/sfx/instruments.c index 410004a40..68f44805f 100644 --- a/src/core2/sfx/instruments.c +++ b/src/core2/sfx/instruments.c @@ -4,113 +4,91 @@ #include "variables.h" #include -extern ALBank *music_get_sound_bank(void); -extern void func_80243070(void *arg0); +extern void func_80243070(Struct87s *arg0); extern u8 *soundfont1ctl_ROM_START; extern u8 *soundfont1ctl_ROM_END; extern u8 *soundfont1tbl_ROM_START; -struct { - s32 unk0; //sound state cnt - s32 unk4; - s32 unk8; //maxSounds - ALHeap *unkC; //heap - s16 unk10; -} D_803835F0; -ALBank * sfx_sound_bank; - -/* .code */ -void sfxInstruments_init(void){ +Struct87s D_803835F0; +ALBank *sSfxSoundBank; + +void sfxInstruments_init(void) { ALBank *bnk; s32 size; ALInstrument *inst; - ALBankFile * bnkf; - + ALBankFile *bnk_f; // [port] parse BE ctl binary into native 64-bit structs extern ALBankFile *port_alBnkfNew(u8 *ctlData, s32 ctlSize, u8 *tblData); size = soundfont1ctl_ROM_END - soundfont1ctl_ROM_START; - bnkf = port_alBnkfNew(soundfont1ctl_ROM_START, size, soundfont1tbl_ROM_START); - bnk = bnkf->bankArray[0]; + bnk_f = port_alBnkfNew(soundfont1ctl_ROM_START, size, soundfont1tbl_ROM_START); + + bnk = bnk_f->bankArray[0]; inst = bnk->instArray[0]; + D_803835F0.unk0 = inst->soundCount; D_803835F0.unk4 = 0x100; D_803835F0.unk10 = 0x40; - D_803835F0.unk8 = 0x18; - D_803835F0.unkC = audioManager_getALHeapInfo(); + D_803835F0.max_sounds = 24; + D_803835F0.heap = audioManager_getALHeapInfo(); func_80243070(&D_803835F0); - sfx_sound_bank = bnk; + + sSfxSoundBank = bnk; } -intptr_t func_8033531C(enum sfx_e uid, struct46s *arg1) -{ - intptr_t result = (intptr_t)func_80244608(sfx_sound_bank, (s16) (uid + 1), arg1); - return result; +intptr_t sfxInstruments_func_8033531C(enum sfx_e sfx_id, struct46s *arg1) { + return (intptr_t) func_80244608(sSfxSoundBank, (s16) (sfx_id + 1), arg1); } -intptr_t func_80335354(int uid, struct46s *arg1) -{ - ALBank *bank = music_get_sound_bank(); - return (intptr_t)func_80244608(bank, (s16) (uid + 1), arg1); +intptr_t sfxInstruments_func_80335354(enum sfx_e sfx_id, struct46s *arg1) { + return (intptr_t) func_80244608(musicInstruments_getSoundBank(), (s16) (sfx_id + 1), arg1); } -void func_80335394(intptr_t arg0, f32 arg1) -{ +void sfxInstruments_func_80335394(intptr_t arg0, f32 arg1) { func_80244978(arg0, AL_SEQP_STOP_EVT, reinterpret_cast(s32, arg1)); } -void func_803353BC(intptr_t arg0, u16 arg1) -{ +void sfxInstruments_func_803353BC(intptr_t arg0, u16 arg1) { if(arg1 > 0x7fff) arg1 = 0x7fff; func_80244978(arg0, AL_SEQP_PROG_EVT, arg1); } -void func_803353F4(intptr_t arg0, s32 arg1) -{ +void sfxInstruments_func_803353F4(intptr_t arg0, s32 arg1) { func_80244978(arg0, 0x100, arg1); } -void func_80335418(intptr_t arg0, s32 arg1) -{ +void sfxInstruments_func_80335418(intptr_t arg0, s32 arg1) { func_80244978(arg0, AL_SEQ_END_EVT, arg1); } -void func_8033543C(Struct81s *arg0){ +void sfxInstruments_func_8033543C(Struct81s *arg0) { if(arg0 != NULL && func_802445AC(arg0) != 0){ func_80244814(arg0); } } -bool func_80335470(Struct81s *arg0) -{ +bool sfxInstruments_func_80335470(Struct81s *arg0) { return func_802445AC(arg0) != 0; } -u32 func_80335494(Struct81s *arg0) -{ +u32 sfxInstruments_func_80335494(Struct81s *arg0) { return func_802445AC(arg0); } -s32 func_803354B4(void) -{ - return sfx_sound_bank->instArray[0]->soundCount; +s32 sfxInstruments_getSoundCount(void) { + return sSfxSoundBank->instArray[0]->soundCount; } -s32 func_803354C8(void) -{ - ALBank *bank = music_get_sound_bank(); - return bank->instArray[0]->soundCount; +s32 sfxInstruments_getMusicSoundBankSoundCount(void) { + return musicInstruments_getSoundBank()->instArray[0]->soundCount; } -bool func_803354EC(enum sfx_e sfx_id) -{ - return func_802445C4(sfx_sound_bank, (s16)(sfx_id + 1)); +bool func_803354EC(enum sfx_e sfx_id) { + return func_802445C4(sSfxSoundBank, (s16) (sfx_id + 1)); } -bool func_80335520(s32 arg0) -{ - ALBank *bank = music_get_sound_bank(); - return func_802445C4(bank, (s16)(arg0 + 1)); +bool func_80335520(enum sfx_e sfx_id) { + return func_802445C4(musicInstruments_getSoundBank(), (s16) (sfx_id + 1)); } diff --git a/src/core2/sfx/source.c b/src/core2/sfx/source.c index 3cd50ef42..e8afe1509 100644 --- a/src/core2/sfx/source.c +++ b/src/core2/sfx/source.c @@ -6,7 +6,7 @@ #include "port/ShipUtils.h" // gPortResetPending #include -extern void func_80335394(intptr_t, f32); +extern void sfxInstruments_func_80335394(intptr_t, f32); extern f32 sfx_randf2(f32, f32); #define SFX_SRC_FLAG_0_UNKOWN (1 << 0) @@ -177,10 +177,10 @@ void func_8030CBD0(SfxSource *arg0){ sfxsource_setFlag(arg0, SFX_SRC_FLAG_3_UNKOWN); sfxsource_setFlag(arg0, SFX_SRC_FLAG_4_UNKOWN); if(arg0->sfx_uid > 0x3e8){ - func_80335354(arg0->sfx_uid - 0x3e9, func_8030C8DC(arg0->unk40)); + sfxInstruments_func_80335354(arg0->sfx_uid - 0x3e9, func_8030C8DC(arg0->unk40)); } else{ - func_8033531C(arg0->sfx_uid, func_8030C8DC(arg0->unk40)); + sfxInstruments_func_8033531C(arg0->sfx_uid, func_8030C8DC(arg0->unk40)); } }//L8030CC7C } @@ -190,7 +190,7 @@ void func_8030CC90(SfxSource *arg0){ sfxsource_clearFlag(arg0, SFX_SRC_FLAG_5_UNKOWN); func_8030C7F8(arg0, 2); if(arg0->unk40){ - func_8033543C((Struct81s *)func_8030C8F4(arg0->unk40)); + sfxInstruments_func_8033543C((Struct81s *)func_8030C8F4(arg0->unk40)); } } } @@ -245,25 +245,25 @@ s32 func_8030CDE4(SfxSource *arg0){ void func_8030CF68(s32 arg0, s32 arg1){ if(arg0){ - func_803353F4((intptr_t)func_8030C8F4(arg0), arg1); + sfxInstruments_func_803353F4((intptr_t)func_8030C8F4(arg0), arg1); } } void func_8030CF9C(s32 arg0, s32 arg1){ if(arg0){ - func_80335418((intptr_t)func_8030C8F4(arg0), arg1); + sfxInstruments_func_80335418((intptr_t)func_8030C8F4(arg0), arg1); } } void func_8030CFD0(s32 arg0, f32 arg1){ if(arg0){ - func_80335394((intptr_t)func_8030C8F4(arg0), arg1); + sfxInstruments_func_80335394((intptr_t)func_8030C8F4(arg0), arg1); } } void func_8030D004(s32 arg0, s32 arg1){ if(arg0){ - func_803353BC((intptr_t)func_8030C8F4(arg0), (u16) arg1); + sfxInstruments_func_803353BC((intptr_t)func_8030C8F4(arg0), (u16) arg1); } } @@ -474,8 +474,8 @@ void func_8030D8A8(s32 arg0, s32 arg){ } void func_8030D8B4(void){ - func_8024FB8C(); - func_8024F83C(); + musicSlot_stopAll(); + musicTrack_releaseAll(); } void func_8030D8DC(void){ diff --git a/src/core2/sfx/trackmanager.c b/src/core2/sfx/trackmanager.c index e65939774..7d6c98493 100644 --- a/src/core2/sfx/trackmanager.c +++ b/src/core2/sfx/trackmanager.c @@ -194,7 +194,7 @@ s32 func_803226BC(enum map_e map_id){ return D_8036DE80[func_803225E0(map_id)].unk6; } -s32 func_803226E8(enum map_e map_id){ +s32 core2_9B650_getMusicTrackFromMap(enum map_e map_id){ int t1, t2; if (port_getRomhackMusic(map_id, &t1, &t2)) { return t1; @@ -232,7 +232,7 @@ void func_8032278C(s32 arg0, s32 arg1) { static s32 D_8036E2B4 = 1; D_80383340.unk4 = func_803226BC(gsworld_getMap()); - D_80383340.unk0 = func_803226E8(gsworld_getMap()); + D_80383340.unk0 = core2_9B650_getMusicTrackFromMap(gsworld_getMap()); D_80383340.unk2 = func_80322714(gsworld_getMap()); if (arg1 == 3) { D_8036E2B4 = 1; diff --git a/src/core2/spline_pathfollow.c b/src/core2/spline_pathfollow.c index 271422d9c..f208f76af 100644 --- a/src/core2/spline_pathfollow.c +++ b/src/core2/spline_pathfollow.c @@ -953,7 +953,7 @@ s32 func_803422D4(Actor *arg0, Union_glspline *arg1, SplineList *arg2){ switch (arg1->t0.unk4.common.bit3) { case 1: - func_80250530(0, arg1->t0.unk4.common.bit31, 3.0f); + musicSlot_stepToChannelMask(0, arg1->t0.unk4.common.bit31, 3.0f); break; case 2: @@ -1399,8 +1399,8 @@ s32 func_803438E0(Actor *actor, s32 arg1, s32 arg2, s32 arg3) { } } - if ((actor->unk138_3 != 0) && func_802501A0(0, actor->unk138_3 + 0x69, 0)) { - func_80250170(0, actor->unk138_3 + 0x69, 0); + if ((actor->unk138_3 != 0) && musicSlot_func_802501A0(0, actor->unk138_3 + 0x69, NULL)) { + musicSlot_func_80250170(0, actor->unk138_3 + 0x69, 0); actor->unk138_3 = 0; } } diff --git a/src/lair/ff_manager.c b/src/lair/ff_manager.c index fb12c5fd2..b849c2253 100644 --- a/src/lair/ff_manager.c +++ b/src/lair/ff_manager.c @@ -699,7 +699,7 @@ void func_8038D16C(s32 a0, u16 a1) { coMusicPlayer_playMusic(a0, 0); comusic_8025AB44(a0, 28000, 500); - func_80250530(func_8025ADD4(a0), a1, 0); + musicSlot_stepToChannelMask(comusic_getTrackPosition(a0), a1, 0); } void func_8038D1BC(void) @@ -914,7 +914,7 @@ void ff_setState(enum FF_Action next_state) { timedFunc_set_0(1.5f, func_8038D1BC); break; case 1: //L8038D870 - if (func_8025AD7C(D_80394354[ffStorage->questionTypeTableIndex].unk2)) { + if (comusic_isTrackQueued(D_80394354[ffStorage->questionTypeTableIndex].unk2)) { comusic_8025AB44(D_80394354[ffStorage->questionTypeTableIndex].unk2, 0, 0x1F4); timedFunc_set_0(1.5f, func_8038D1BC); } else { @@ -1304,7 +1304,7 @@ void lair_func_8038E0B0(void) { break; case 9://L8038E738 - if (!func_8025AD7C(0x78)) { + if (!comusic_isTrackQueued(0x78)) { mapSpecificFlags_set(6, true); ff_setState(0); }