diff --git a/config.yml b/config.yml index 05d52cf1..e0ba12b5 100644 --- a/config.yml +++ b/config.yml @@ -20,21 +20,21 @@ f7475fb11e7e6830f82883412638e8390791ab87: - include/sf64event.h - include/sf64player.h -d064229a32cc05ab85e2381ce07744eb3ffaf530: - name: Star Fox 64 (JP) (V1.0) - path: assets/yaml/jp/rev0 - config: - gbi: F3DEX - sort: OFFSET - output: - binary: starship.otr - code: src/assets - headers: include/assets - modding: src/assets - enums: - - include/sf64object.h - - include/sf64level.h - - include/sf64mesg.h - - include/sf64audio_external.h - - include/sf64event.h - - include/sf64player.h \ No newline at end of file +# d064229a32cc05ab85e2381ce07744eb3ffaf530: +# name: Star Fox 64 (JP) (V1.0) +# path: assets/yaml/jp/rev0 +# config: +# gbi: F3DEX +# sort: OFFSET +# output: +# binary: starship.otr +# code: src/assets +# headers: include/assets +# modding: src/assets +# enums: +# - include/sf64object.h +# - include/sf64level.h +# - include/sf64mesg.h +# - include/sf64audio_external.h +# - include/sf64event.h +# - include/sf64player.h \ No newline at end of file diff --git a/include/macros.h b/include/macros.h index f92ceb4f..ac923cfc 100644 --- a/include/macros.h +++ b/include/macros.h @@ -9,6 +9,10 @@ #define TIME_IN_SECONDS(x) (x * 30); +#define CLAMP(x, min, max) ((x) < (min) ? (min) : (x) > (max) ? (max) : (x)) +#define CLAMP_MAX(x, max) ((x) > (max) ? (max) : (x)) +#define CLAMP_MIN(x, min) ((x) < (min) ? (min) : (x)) + #define RAND_FLOAT(max) (Rand_ZeroOne()*(max)) #define RAND_INT(max) ((s32)(Rand_ZeroOne()*(max))) #define RAND_FLOAT_CENTERED(width) ((Rand_ZeroOne()-0.5f)*(width)) diff --git a/include/prevent_context_reordering.h b/include/prevent_context_reordering.h index 2d25120c..cc009271 100644 --- a/include/prevent_context_reordering.h +++ b/include/prevent_context_reordering.h @@ -1,7 +1,7 @@ #ifndef PREVENT_CONTEXT_REORDERING_H #define PREVENT_CONTEXT_REORDERING_H -// extern int Dummyhalf; +extern int Dummyhalf; // struct Dummy0 {int x;}; // struct Dummy1 {int x;}; // struct Dummy2 {int x;}; @@ -17,8 +17,8 @@ // struct Dummy12 {int x;}; // struct Dummy13 {int x;}; // struct Dummy14 {int x;}; -struct Dummy15 {int x;}; -struct Dummy16 {int x;}; +// struct Dummy15 {int x;}; +// struct Dummy16 {int x;}; struct Dummy17 {int x;}; struct Dummy18 {int x;}; struct Dummy19 {int x;}; diff --git a/include/sf64audio_provisional.h b/include/sf64audio_provisional.h index 9b952524..c9885b23 100644 --- a/include/sf64audio_provisional.h +++ b/include/sf64audio_provisional.h @@ -1021,14 +1021,14 @@ typedef struct { // audio_synthesis void func_80008780(f32*, s32, f32*); -Acmd* func_80009B64(Acmd* aList, s32* cmdCount, s16* aiBufStart, s32 aiBufLen); +Acmd* AudioSynth_Update(Acmd* aList, s32* cmdCount, s16* aiBufStart, s32 aiBufLen); // audio_effects -void func_800135A8(SequencePlayer* seqplayer); -void func_80013A18(Note* note); -void func_80013A84(Note* note); -void func_80013B6C(AdsrState* adsr, EnvelopePoint* envelope, s16* arg2); -f32 func_80013B90(AdsrState* adsr); +void Audio_SequencePlayerProcessSound(SequencePlayer* seqplayer); +void Audio_NoteVibratoUpdate(Note* note); +void Audio_NoteVibratoInit(Note* note); +void Audio_AdsrInit(AdsrState* adsr, EnvelopePoint* envelope, s16* arg2); +f32 Audio_AdsrUpdate(AdsrState* adsr); // audio_heap void AudioHeap_DiscardFont(s32 fontId); @@ -1058,29 +1058,29 @@ void AudioLoad_DiscardSeqFonts(s32 seqId); s32 AudioLoad_SlowLoadSample(s32 fontId, u8 instId, s8* status); // audio_playback -TunedSample* func_80011D10(Instrument* instrument, s32 arg1); +TunedSample* Audio_GetInstrumentTunedSample(Instrument* instrument, s32 semitone); Instrument* Audio_GetInstrument(s32, s32); Drum* Audio_GetDrum(s32, s32); -void func_80011F4C(Note* note); -void func_80011FA8(void); -void func_8001266C(SequenceLayer* layer); -void func_800127B0(Note* note, SequenceLayer* layer); -void func_80012864(NotePool* pool); -void func_800128B4(void); -void func_80012964(NotePool* pool); -void func_80012AC4(NotePool* pool, s32); -void func_80012C40(Note* note); -Note* func_8001301C(SequenceLayer* layer); -void func_800132E8(void); +void Audio_NoteDisable(Note* note); +void Audio_ProcessNotes(void); +void Audio_SeqLayerNoteDecay(SequenceLayer* layer); +void Audio_InitSyntheticWave(Note* note, SequenceLayer* layer); +void Audio_InitNoteLists(NotePool* pool); +void Audio_InitNoteFreeList(void); +void Audio_NotePoolClear(NotePool* pool); +void Audio_NotePoolFill(NotePool* pool, s32); +void Audio_AudioListRemove(Note* note); +Note* Audio_AllocNote(SequenceLayer* layer); +void Audio_NoteInitAll(void); // audio_seqplayer -void func_8001415C(SequenceChannel* channel); -void func_800144E4(SequencePlayer* seqPlayer); -void func_800145BC(AudioListItem* list, AudioListItem* item); -void* func_800145FC(AudioListItem* list); -void func_8001678C(s32 arg0); -void func_80016804(s32 arg0); -void func_800168BC(void); +void AudioSeq_SequenceChannelDisable(SequenceChannel* channel); +void AudioSeq_SequencePlayerDisable(SequencePlayer* seqPlayer); +void AudioSeq_AudioListPushBack(AudioListItem* list, AudioListItem* item); +void* AudioSeq_AudioListPopBack(AudioListItem* list); +void AudioSeq_ProcessSequences(s32 arg0); +void AudioSeq_ResetSequencePlayer(s32 arg0); +void AudioSeq_InitSequencePlayers(void); // audio_thread void AudioThread_ScheduleProcessCmds(void); diff --git a/include/sf64object.h b/include/sf64object.h index a1baf573..179163f6 100644 --- a/include/sf64object.h +++ b/include/sf64object.h @@ -8,6 +8,16 @@ #define HITBOX_SHADOW 300000.0f #define HITBOX_WHOOSH 400000.0f +#define TEAM_FACE (14) + +typedef enum ActorCSTeamFace { + /* 0 */ FACE_NONE, + /* 1 */ FACE_FOX, + /* 2 */ FACE_FALCO, + /* 3 */ FACE_SLIPPY, + /* 4 */ FACE_PEPPY +} ActorCSTeamFace; + typedef struct { /* 0x0 */ f32 offset; /* 0x4 */ f32 size; diff --git a/linker_scripts/jp/rev0/symbol_addrs.txt b/linker_scripts/jp/rev0/symbol_addrs.txt index 36576d4f..a9c0360a 100644 --- a/linker_scripts/jp/rev0/symbol_addrs.txt +++ b/linker_scripts/jp/rev0/symbol_addrs.txt @@ -1603,8 +1603,8 @@ func_800C01D4 = 0x800C01D4; func_800C02E4 = 0x800C02E4; D_800C0760 = 0x800C0760; D_800C07B0 = 0x800C07B0; -D_800C0BE0 = 0x800C0BE0; -D_800C0E00 = 0x800C0E00; +gSoundFontTableInit = 0x800C0BE0; +gSeqFontTableInit = 0x800C0E00; D_800C1720 = 0x800C1720; D_800C1730 = 0x800C1730; D_800C1770 = 0x800C1770; diff --git a/linker_scripts/us/rev1/symbol_addrs_audio.txt b/linker_scripts/us/rev1/symbol_addrs_audio.txt index ecbc8fc2..022b5de0 100644 --- a/linker_scripts/us/rev1/symbol_addrs_audio.txt +++ b/linker_scripts/us/rev1/symbol_addrs_audio.txt @@ -233,15 +233,15 @@ func_800098DC = 0x800098DC; func_80009984 = 0x80009984; func_80009A2C = 0x80009A2C; func_80009AAC = 0x80009AAC; -func_80009B64 = 0x80009B64; +AudioSynth_Update = 0x80009B64; func_80009D78 = 0x80009D78; func_8000A128 = 0x8000A128; func_8000A25C = 0x8000A25C; -func_8000A700 = 0x8000A700; -func_8000B3F0 = 0x8000B3F0; +AudioSynth_ProcessNote = 0x8000A700; +AudioSynth_LoadWaveSamples = 0x8000B3F0; func_8000B480 = 0x8000B480; func_8000B51C = 0x8000B51C; -func_8000B98C = 0x8000B98C; +AudioSynth_ApplyHaasEffect = 0x8000B98C; @@ -332,72 +332,72 @@ AudioLoad_GetSamplesForFont = 0x80011758; -func_80011890 = 0x80011890; -func_80011C58 = 0x80011C58; -func_80011D10 = 0x80011D10; +Audio_InitNoteSub = 0x80011890; +Audio_NoteSetResamplingRate = 0x80011C58; +Audio_GetInstrumentTunedSample = 0x80011D10; Audio_GetInstrument = 0x80011D4C; Audio_GetDrum = 0x80011DFC; -func_80011EB8 = 0x80011EB8; -func_80011F4C = 0x80011F4C; -func_80011FA8 = 0x80011FA8; -func_80012438 = 0x80012438; -func_8001266C = 0x8001266C; -func_8001268C = 0x8001268C; -func_800126AC = 0x800126AC; -func_800127B0 = 0x800127B0; -func_80012854 = 0x80012854; -func_80012864 = 0x80012864; -func_800128B4 = 0x800128B4; -func_80012964 = 0x80012964; -func_80012AC4 = 0x80012AC4; -func_80012C00 = 0x80012C00; -func_80012C40 = 0x80012C40; -func_80012C6C = 0x80012C6C; -func_80012CEC = 0x80012CEC; +Audio_NoteInit = 0x80011EB8; +Audio_NoteDisable = 0x80011F4C; +Audio_ProcessNotes = 0x80011FA8; +Audio_SeqLayerDecayRelease = 0x80012438; +Audio_SeqLayerNoteDecay = 0x8001266C; +Audio_SeqLayerNoteRelease = 0x8001268C; +Audio_BuildSyntheticWave = 0x800126AC; +Audio_InitSyntheticWave = 0x800127B0; +Audio_InitNoteList = 0x80012854; +Audio_InitNoteLists = 0x80012864; +Audio_InitNoteFreeList = 0x800128B4; +Audio_NotePoolClear = 0x80012964; +Audio_NotePoolFill = 0x80012AC4; +Audio_AudioListPushFront = 0x80012C00; +Audio_AudioListRemove = 0x80012C40; +Audio_FindNodeWithPrioLessThan = 0x80012C6C; +Audio_NoteInitForLayer = 0x80012CEC; func_80012E28 = 0x80012E28; -func_80012E5C = 0x80012E5C; -func_80012E88 = 0x80012E88; -func_80012ED4 = 0x80012ED4; -func_80012F24 = 0x80012F24; -func_8001301C = 0x8001301C; -func_800132E8 = 0x800132E8; +Audio_NoteReleaseAndTakeOwnership = 0x80012E5C; +Audio_AllocNoteFromDisabled = 0x80012E88; +Audio_AllocNoteFromDecaying = 0x80012ED4; +Audio_AllocNoteFromActive = 0x80012F24; +Audio_AllocNote = 0x8001301C; +Audio_NoteInitAll = 0x800132E8; func_80013400 = 0x80013400; -func_800135A8 = 0x800135A8; -func_80013708 = 0x80013708; +Audio_SequencePlayerProcessSound = 0x800135A8; +Audio_GetPortamentoFreqScale = 0x80013708; func_800137DC = 0x800137DC; -func_80013820 = 0x80013820; -func_80013A18 = 0x80013A18; -func_80013A84 = 0x80013A84; -func_80013B6C = 0x80013B6C; -func_80013B90 = 0x80013B90; - - - -func_80013EA0 = 0x80013EA0; -func_80013FC4 = 0x80013FC4; -func_800140D0 = 0x800140D0; -func_8001410C = 0x8001410C; -func_8001415C = 0x8001415C; -func_800141C8 = 0x800141C8; -func_80014244 = 0x80014244; -func_80014370 = 0x80014370; -func_80014440 = 0x80014440; -func_800144E4 = 0x800144E4; -func_800145BC = 0x800145BC; -func_800145FC = 0x800145FC; -func_8001463C = 0x8001463C; -func_800146C0 = 0x800146C0; -func_800146D4 = 0x800146D4; -func_80014704 = 0x80014704; -func_80014748 = 0x80014748; -func_800152C0 = 0x800152C0; -func_80015330 = 0x80015330; -func_800153C4 = 0x800153C4; -func_800153E8 = 0x800153E8; -func_80015FD4 = 0x80015FD4; -func_8001678C = 0x8001678C; -func_80016804 = 0x80016804; -func_800168BC = 0x800168BC; +Audio_GetVibratoFreqScale = 0x80013820; +Audio_NoteVibratoUpdate = 0x80013A18; +Audio_NoteVibratoInit = 0x80013A84; +Audio_AdsrInit = 0x80013B6C; +Audio_AdsrUpdate = 0x80013B90; + + + +AudioSeq_InitSequenceChannel = 0x80013EA0; +AudioSeq_SeqChannelSetLayer = 0x80013FC4; +AudioSeq_SeqLayerDisable = 0x800140D0; +AudioSeq_SeqLayerFree = 0x8001410C; +AudioSeq_SequenceChannelDisable = 0x8001415C; +AudioSeq_RequestFreeSeqChannel = 0x800141C8; +AudioSeq_SequencePlayerSetupChannels = 0x80014244; +AudioSeq_SequencePlayerDisableChannels = 0x80014370; +AudioSeq_SequenceChannelEnable = 0x80014440; +AudioSeq_SequencePlayerDisable = 0x800144E4; +AudioSeq_AudioListPushBack = 0x800145BC; +AudioSeq_AudioListPopBack = 0x800145FC; +AudioSeq_InitLayerFreelist = 0x8001463C; +AudioSeq_ScriptReadU8 = 0x800146C0; +AudioSeq_ScriptReadS16 = 0x800146D4; +AudioSeq_ScriptReadCompressedU16 = 0x80014704; +AudioSeq_SeqLayerProcessScript = 0x80014748; +AudioSeq_GetInstrument = 0x800152C0; +AudioSeq_SetInstrument = 0x80015330; +AudioSeq_SequenceChannelSetVolume = 0x800153C4; +AudioSeq_SequenceChannelProcessScript = 0x800153E8; +AudioSeq_SequencePlayerProcessSequence = 0x80015FD4; +AudioSeq_ProcessSequences = 0x8001678C; +AudioSeq_ResetSequencePlayer = 0x80016804; +AudioSeq_InitSequencePlayers = 0x800168BC; diff --git a/src/audio/audio_effects.c b/src/audio/audio_effects.c index 61d2ccaa..f78b78ed 100644 --- a/src/audio/audio_effects.c +++ b/src/audio/audio_effects.c @@ -42,7 +42,7 @@ void func_80013400(SequenceChannel* channel, s32 updateVolume) { channel->changes.asByte = 0; } -void func_800135A8(SequencePlayer* seqplayer) { +void Audio_SequencePlayerProcessSound(SequencePlayer* seqplayer) { s32 i; if (seqplayer->fadeTimer != 0) { @@ -56,14 +56,14 @@ void func_800135A8(SequencePlayer* seqplayer) { } seqplayer->fadeTimer--; if ((seqplayer->fadeTimer == 0) && (seqplayer->state == 2)) { - func_800144E4(seqplayer); + AudioSeq_SequencePlayerDisable(seqplayer); return; } } if (seqplayer->recalculateVolume) { seqplayer->appliedFadeVolume = seqplayer->fadeVolume * seqplayer->fadeVolumeMod; } - for (i = 0; i < 16; i++) { + for (i = 0; i < SEQ_NUM_CHANNELS; i++) { if ((IS_SEQUENCE_CHANNEL_VALID(seqplayer->channels[i]) == 1) && (seqplayer->channels[i]->enabled == 1)) { func_80013400(seqplayer->channels[i], seqplayer->recalculateVolume); } @@ -71,7 +71,7 @@ void func_800135A8(SequencePlayer* seqplayer) { seqplayer->recalculateVolume = false; } -f32 func_80013708(Portamento* portamento) { +f32 Audio_GetPortamentoFreqScale(Portamento* portamento) { u32 temp; f32 temp2; @@ -92,7 +92,7 @@ s16 func_800137DC(VibratoState* vibrato) { return vibrato->curve[index] >> 8; } -f32 func_80013820(VibratoState* vibrato) { +f32 Audio_GetVibratoFreqScale(VibratoState* vibrato) { s32 ret; f32 temp; f32 temp2; @@ -136,16 +136,16 @@ f32 func_80013820(VibratoState* vibrato) { return temp2; } -void func_80013A18(Note* note) { +void Audio_NoteVibratoUpdate(Note* note) { if (note->playbackState.portamento.mode != 0) { - note->playbackState.portamentoFreqMod = func_80013708(¬e->playbackState.portamento); + note->playbackState.portamentoFreqMod = Audio_GetPortamentoFreqScale(¬e->playbackState.portamento); } if ((note->playbackState.vibratoState.active != 0) && (note->playbackState.parentLayer != NO_LAYER)) { - note->playbackState.vibratoFreqMod = func_80013820(¬e->playbackState.vibratoState); + note->playbackState.vibratoFreqMod = Audio_GetVibratoFreqScale(¬e->playbackState.vibratoState); } } -void func_80013A84(Note* note) { +void Audio_NoteVibratoInit(Note* note) { NotePlaybackState* noteState = ¬e->playbackState; VibratoState* vibrato = ¬eState->vibratoState; @@ -173,7 +173,7 @@ void func_80013A84(Note* note) { noteState->portamento = noteState->parentLayer->portamento; } -void func_80013B6C(AdsrState* adsr, EnvelopePoint* envelope, s16* arg2) { +void Audio_AdsrInit(AdsrState* adsr, EnvelopePoint* envelope, s16* arg2) { adsr->action.asByte = 0; adsr->state = 0; adsr->delay = 0; @@ -182,7 +182,7 @@ void func_80013B6C(AdsrState* adsr, EnvelopePoint* envelope, s16* arg2) { adsr->current = 0.0f; } -f32 func_80013B90(AdsrState* adsr) { +f32 Audio_AdsrUpdate(AdsrState* adsr) { u8 action = adsr->action.asByte; u8 state = adsr->state; diff --git a/src/audio/audio_heap.c b/src/audio/audio_heap.c index 9d6ca238..72edb0a7 100644 --- a/src/audio/audio_heap.c +++ b/src/audio/audio_heap.c @@ -99,9 +99,9 @@ void AudioHeap_DiscardFont(s32 fontId) { note->playbackState.parentLayer->enabled = false; note->playbackState.parentLayer->finished = true; } - func_80011F4C(note); - func_80012C40(note); - func_800145BC(&gNoteFreeLists.disabled, ¬e->listItem); + Audio_NoteDisable(note); + Audio_AudioListRemove(note); + AudioSeq_AudioListPushBack(&gNoteFreeLists.disabled, ¬e->listItem); } } } @@ -111,7 +111,7 @@ void AudioHeap_DiscardSequence(s32 seqId) { for (i = 0; i < ARRAY_COUNT(gSeqPlayers); i++) { if (gSeqPlayers[i].enabled && gSeqPlayers[i].seqId == seqId) { - func_800144E4(&gSeqPlayers[i]); + AudioSeq_SequencePlayerDisable(&gSeqPlayers[i]); } } } @@ -571,7 +571,7 @@ s32 AudioHeap_ResetStep(void) { switch (gAudioResetStep) { case 5: for (i = 0; i < ARRAY_COUNT(gSeqPlayers); i++) { - func_800144E4(&gSeqPlayers[i]); + AudioSeq_SequencePlayerDisable(&gSeqPlayers[i]); } gResetFadeoutFramesLeft = 4 / sp24; gAudioResetStep--; @@ -696,8 +696,8 @@ void AudioHeap_Init(void) { AudioHeap_InitSampleCaches(spec->persistentSampleCacheSize, spec->temporarySampleCacheSize); AudioHeap_ResetLoadStatus(); gNotes = AudioHeap_AllocZeroed(&gMiscPool, gNumNotes * sizeof(Note)); - func_800132E8(); - func_800128B4(); + Audio_NoteInitAll(); + Audio_InitNoteFreeList(); gNoteSubsEu = AudioHeap_AllocZeroed(&gMiscPool, gAudioBufferParams.ticksPerUpdate * gNumNotes * sizeof(NoteSubEu)); for (i = 0; i != 2; i++) { gAbiCmdBuffs[i] = AudioHeap_AllocZeroed(&gMiscPool, gMaxAudioCmds * 8); diff --git a/src/audio/audio_load.c b/src/audio/audio_load.c index af1d06cf..60093820 100644 --- a/src/audio/audio_load.c +++ b/src/audio/audio_load.c @@ -383,7 +383,7 @@ void AudioLoad_SyncInitSeqPlayerInternal(s32 playerIdx, s32 seqId, s32 arg2) { seqId = AudioLoad_GetLoadTableIndex(SEQUENCE_TABLE, seqId); - func_800144E4(&gSeqPlayers[playerIdx]); + AudioSeq_SequencePlayerDisable(&gSeqPlayers[playerIdx]); index = *((u16*) gSeqFontTable + seqId); numFonts = gSeqFontTable[index++]; @@ -396,7 +396,7 @@ void AudioLoad_SyncInitSeqPlayerInternal(s32 playerIdx, s32 seqId, s32 arg2) { seqData = AudioLoad_SyncLoadSeq(seqId); - func_80016804(playerIdx); + AudioSeq_ResetSequencePlayer(playerIdx); gSeqPlayers[playerIdx].seqId = seqId; gSeqPlayers[playerIdx].defaultFont = fontId; @@ -978,7 +978,7 @@ void AudioLoad_Init(void) { } AudioHeap_InitPool(&gPermanentPool.pool, ramAddr, gPermanentPoolSize); - func_800168BC(); + AudioSeq_InitSequencePlayers(); } static const char devstr38[] = "Entry--- %d %d\n"; diff --git a/src/audio/audio_playback.c b/src/audio/audio_playback.c index a4b2ae46..b97a0b8b 100644 --- a/src/audio/audio_playback.c +++ b/src/audio/audio_playback.c @@ -33,13 +33,13 @@ static const char devstr25[] = "Intterupt UseStop %d (Kill %d)\n"; static const char devstr26[] = "Intterupt RelWait %d (Kill %d)\n"; static const char devstr27[] = "Drop Voice (Prio %x)\n"; -void func_80011C58(Note* note, f32); -void func_8001268C(SequenceLayer* layer); -void func_80012C00(AudioListItem* item1, AudioListItem* item2); -void func_80012C40(Note* note); -void func_80012CEC(Note* note, SequenceLayer* layer); +void Audio_NoteSetResamplingRate(Note* note, f32); +void Audio_SeqLayerNoteRelease(SequenceLayer* layer); +void Audio_AudioListPushFront(AudioListItem* list, AudioListItem* item); +void Audio_AudioListRemove(Note* note); +void Audio_NoteInitForLayer(Note* note, SequenceLayer* layer); -void func_80011890(Note* note, NoteAttributes* noteAttr) { +void Audio_InitNoteSub(Note* note, NoteAttributes* noteAttr) { NoteSubEu* noteSub; f32 panVolumeLeft; f32 pamVolumeRight; @@ -52,7 +52,7 @@ void func_80011890(Note* note, NoteAttributes* noteAttr) { u8 reverb; Stereo stereo; - func_80011C58(note, noteAttr->freqMod); + Audio_NoteSetResamplingRate(note, noteAttr->freqMod); noteSub = ¬e->noteSubEu; velocity = noteAttr->velocity; pan = noteAttr->pan; @@ -130,34 +130,30 @@ void func_80011890(Note* note, NoteAttributes* noteAttr) { } } -void func_80011C58(Note* note, f32 arg1) { +void Audio_NoteSetResamplingRate(Note* note, f32 resamplingRateInput) { NoteSubEu* noteSub = ¬e->noteSubEu; - f32 var_fv0; + f32 resamplingRate; - if (arg1 < 2.0f) { - noteSub->bitField1.hasTwoParts = 0; - if (arg1 > 1.99998f) { - var_fv0 = 1.99998f; - } else { - var_fv0 = arg1; - } + if (resamplingRateInput < 2.0f) { + noteSub->bitField1.hasTwoParts = false; + resamplingRate = CLAMP_MAX(resamplingRateInput, 1.99998f); } else { - noteSub->bitField1.hasTwoParts = 1; - if (arg1 > 3.99996f) { - var_fv0 = 1.99998f; + noteSub->bitField1.hasTwoParts = true; + if (resamplingRateInput > 3.99996f) { + resamplingRate = 1.99998f; } else { - var_fv0 = arg1 * 0.5f; + resamplingRate = resamplingRateInput * 0.5f; } } - note->noteSubEu.resampleRate = (s32) (var_fv0 * 32768.0f); + note->noteSubEu.resampleRate = (s32) (resamplingRate * 32768.0f); } -TunedSample* func_80011D10(Instrument* instrument, s32 arg1) { +TunedSample* Audio_GetInstrumentTunedSample(Instrument* instrument, s32 semitone) { TunedSample* sample; - if (arg1 < instrument->normalRangeLo) { + if (semitone < instrument->normalRangeLo) { sample = &instrument->lowPitchTunedSample; - } else if (arg1 <= instrument->normalRangeHi) { + } else if (semitone <= instrument->normalRangeHi) { sample = &instrument->normalPitchTunedSample; } else { sample = &instrument->highPitchTunedSample; @@ -205,33 +201,33 @@ Drum* Audio_GetDrum(s32 fontId, s32 drumId) { return drum; } -void func_80011EB8(Note* note) { +void Audio_NoteInit(Note* note) { if (note->playbackState.parentLayer->adsr.decayIndex == 0) { - func_80013B6C(¬e->playbackState.adsr, note->playbackState.parentLayer->channel->adsr.envelope, - ¬e->playbackState.adsrVolModUnused); + Audio_AdsrInit(¬e->playbackState.adsr, note->playbackState.parentLayer->channel->adsr.envelope, + ¬e->playbackState.adsrVolModUnused); } else { - func_80013B6C(¬e->playbackState.adsr, note->playbackState.parentLayer->adsr.envelope, - ¬e->playbackState.adsrVolModUnused); + Audio_AdsrInit(¬e->playbackState.adsr, note->playbackState.parentLayer->adsr.envelope, + ¬e->playbackState.adsrVolModUnused); } - note->playbackState.adsr.state = 1; + note->playbackState.adsr.state = ADSR_STATE_INITIAL; note->noteSubEu = gDefaultNoteSub; } -void func_80011F4C(Note* note) { - if (note->noteSubEu.bitField0.needsInit == 1) { - note->noteSubEu.bitField0.needsInit = 0; +void Audio_NoteDisable(Note* note) { + if (note->noteSubEu.bitField0.needsInit == true) { + note->noteSubEu.bitField0.needsInit = false; } note->playbackState.priority = 0; + note->noteSubEu.bitField0.enabled = false; note->playbackState.unk_04 = 0; - note->noteSubEu.bitField0.enabled = 0; note->playbackState.parentLayer = NO_LAYER; note->playbackState.prevParentLayer = NO_LAYER; note->noteSubEu.bitField0.finished = 0; - note->playbackState.adsr.state = 0; + note->playbackState.adsr.state = ADSR_STATE_DISABLED; note->playbackState.adsr.current = 0.0f; } -void func_80011FA8(void) { +void Audio_ProcessNotes(void) { s32 pad2; s32 pad; Note* note; @@ -241,7 +237,7 @@ void func_80011FA8(void) { s32 i; NoteAttributes sp70; u8 bookOffset; - f32 temp_fs0; + f32 scale; for (i = 0; i < gNumNotes; i++) { note = &gNotes[i]; @@ -257,31 +253,31 @@ void func_80011FA8(void) { playbackState->adsr.fadeOutVel = gAudioBufferParams.ticksPerUpdateInv; playbackState->priority = 1; playbackState->unk_04 = 2; - goto block_21; + goto out; } else { if ((playbackState->parentLayer->enabled) || (playbackState->unk_04 != 0) || (playbackState->priority <= 0)) { if (playbackState->parentLayer->channel->seqPlayer == NULL) { - func_8001415C(playbackState->parentLayer->channel); + AudioSeq_SequenceChannelDisable(playbackState->parentLayer->channel); playbackState->priority = 1; playbackState->unk_04 = 1; continue; } if (!(playbackState->parentLayer->channel->seqPlayer->muted && - (playbackState->parentLayer->channel->muteBehavior & 0x40))) { - goto block_21; + (playbackState->parentLayer->channel->muteBehavior & MUTE_BEHAVIOR_STOP_NOTES))) { + goto out; } } - func_8001268C(playbackState->parentLayer); - func_80012C40(note); - func_80012C00(¬e->listItem.pool->decaying, ¬e->listItem); + Audio_SeqLayerNoteRelease(playbackState->parentLayer); + Audio_AudioListRemove(note); + Audio_AudioListPushFront(¬e->listItem.pool->decaying, ¬e->listItem); playbackState->priority = 1; playbackState->unk_04 = 2; } } else if ((playbackState->unk_04 == 0) && (playbackState->priority > 0)) { continue; } - block_21: + out: if (playbackState->priority != 0) { if (1) {} @@ -289,36 +285,36 @@ void func_80011FA8(void) { if ((playbackState->unk_04 > 0) || noteSub->bitField0.finished) { if ((playbackState->adsr.state == 0) || noteSub->bitField0.finished) { if (playbackState->wantedParentLayer != NO_LAYER) { - func_80011F4C(note); + Audio_NoteDisable(note); if (playbackState->wantedParentLayer->channel != NULL) { - func_80012CEC(note, playbackState->wantedParentLayer); - func_80013A84(note); - func_80012C40(note); - func_800145BC(¬e->listItem.pool->active, ¬e->listItem); + Audio_NoteInitForLayer(note, playbackState->wantedParentLayer); + Audio_NoteVibratoInit(note); + Audio_AudioListRemove(note); + AudioSeq_AudioListPushBack(¬e->listItem.pool->active, ¬e->listItem); playbackState->wantedParentLayer = NO_LAYER; } else { - func_80011F4C(note); - func_80012C40(note); - func_800145BC(¬e->listItem.pool->disabled, ¬e->listItem); + Audio_NoteDisable(note); + Audio_AudioListRemove(note); + AudioSeq_AudioListPushBack(¬e->listItem.pool->disabled, ¬e->listItem); playbackState->wantedParentLayer = NO_LAYER; goto next; } } else { - func_80011F4C(note); - func_80012C40(note); - func_800145BC(¬e->listItem.pool->disabled, ¬e->listItem); + Audio_NoteDisable(note); + Audio_AudioListRemove(note); + AudioSeq_AudioListPushBack(¬e->listItem.pool->disabled, ¬e->listItem); goto next; } } } else if (playbackState->adsr.state == 0) { - func_80011F4C(note); - func_80012C40(note); - func_800145BC(¬e->listItem.pool->disabled, ¬e->listItem); + Audio_NoteDisable(note); + Audio_AudioListRemove(note); + AudioSeq_AudioListPushBack(¬e->listItem.pool->disabled, ¬e->listItem); goto next; } - temp_fs0 = func_80013B90(&playbackState->adsr); - func_80013A18(note); + scale = Audio_AdsrUpdate(&playbackState->adsr); + Audio_NoteVibratoUpdate(note); attr = &playbackState->attributes; if ((playbackState->unk_04 == 1) || (playbackState->unk_04 == 2)) { sp70.freqMod = attr->freqMod; @@ -345,15 +341,15 @@ void func_80011FA8(void) { } sp70.freqMod *= playbackState->vibratoFreqMod * playbackState->portamentoFreqMod; sp70.freqMod *= gAudioBufferParams.resampleRate; - sp70.velocity *= temp_fs0; - func_80011890(note, &sp70); + sp70.velocity *= scale; + Audio_InitNoteSub(note, &sp70); noteSub->bitField1.bookOffset = bookOffset; next:; } } } -void func_80012438(SequenceLayer* layer, s32 arg1) { +void Audio_SeqLayerDecayRelease(SequenceLayer* layer, s32 arg1) { Note* note; NoteAttributes* noteAttr; @@ -413,21 +409,21 @@ void func_80012438(SequenceLayer* layer, s32 arg1) { } } if (arg1 == 6) { - func_80012C40(note); - func_80012C00(¬e->listItem.pool->decaying, ¬e->listItem); + Audio_AudioListRemove(note); + Audio_AudioListPushFront(¬e->listItem.pool->decaying, ¬e->listItem); } } } -void func_8001266C(SequenceLayer* layer) { - func_80012438(layer, 6); +void Audio_SeqLayerNoteDecay(SequenceLayer* layer) { + Audio_SeqLayerDecayRelease(layer, ADSR_STATE_DECAY); } -void func_8001268C(SequenceLayer* layer) { - func_80012438(layer, 7); +void Audio_SeqLayerNoteRelease(SequenceLayer* layer) { + Audio_SeqLayerDecayRelease(layer, ADSR_STATE_RELEASE); } -s32 func_800126AC(Note* note, SequenceLayer* layer, s32 waveId) { +s32 Audio_BuildSyntheticWave(Note* note, SequenceLayer* layer, s32 waveId) { f32 freqMod; u8 harmonicIndex = 0; @@ -458,7 +454,7 @@ s32 func_800126AC(Note* note, SequenceLayer* layer, s32 waveId) { return harmonicIndex; } -void func_800127B0(Note* note, SequenceLayer* layer) { +void Audio_InitSyntheticWave(Note* note, SequenceLayer* layer) { s32 harmonicIndex; s32 waveId; @@ -468,39 +464,39 @@ void func_800127B0(Note* note, SequenceLayer* layer) { } harmonicIndex = note->playbackState.harmonicIndex; note->synthesisState.samplePosInt = - (note->synthesisState.samplePosInt * sSamplesPerWavePeriod[func_800126AC(note, layer, waveId)]) / + (note->synthesisState.samplePosInt * sSamplesPerWavePeriod[Audio_BuildSyntheticWave(note, layer, waveId)]) / sSamplesPerWavePeriod[harmonicIndex]; } -void func_80012854(AudioListItem* item) { +void Audio_InitNoteList(AudioListItem* item) { item->prev = item; item->next = item; item->u.value = NULL; } -void func_80012864(NotePool* pool) { - func_80012854(&pool->disabled); - func_80012854(&pool->decaying); - func_80012854(&pool->releasing); - func_80012854(&pool->active); +void Audio_InitNoteLists(NotePool* pool) { + Audio_InitNoteList(&pool->disabled); + Audio_InitNoteList(&pool->decaying); + Audio_InitNoteList(&pool->releasing); + Audio_InitNoteList(&pool->active); pool->disabled.pool = pool; pool->decaying.pool = pool; pool->releasing.pool = pool; pool->active.pool = pool; } -void func_800128B4(void) { +void Audio_InitNoteFreeList(void) { s32 i; - func_80012864(&gNoteFreeLists); + Audio_InitNoteLists(&gNoteFreeLists); for (i = 0; i < gNumNotes; i++) { gNotes[i].listItem.u.value = &gNotes[i]; gNotes[i].listItem.prev = NULL; - func_800145BC(&gNoteFreeLists.disabled, &gNotes[i].listItem); + AudioSeq_AudioListPushBack(&gNoteFreeLists.disabled, &gNotes[i].listItem); } } -void func_80012964(NotePool* pool) { +void Audio_NotePoolClear(NotePool* pool) { s32 poolType; AudioListItem* poolItem; AudioListItem* nextPoolItem; @@ -531,23 +527,22 @@ void func_80012964(NotePool* pool) { if ((nextPoolItem == poolItem) || (nextPoolItem == NULL)) { break; } - func_80012C40((Note*) nextPoolItem); - func_800145BC(freeList, nextPoolItem); + Audio_AudioListRemove((Note*) nextPoolItem); + AudioSeq_AudioListPushBack(freeList, nextPoolItem); } } } -void func_80012AC4(NotePool* pool, s32 arg1) { - s32 var_s0; +void Audio_NotePoolFill(NotePool* pool, s32 count) { + s32 j; s32 poolType; AudioListItem* note; AudioListItem* freeList; AudioListItem* poolList; - func_80012964(pool); - poolType = 0; - var_s0 = 0; - while (var_s0 < arg1) { + Audio_NotePoolClear(pool); + + for (poolType = 0, j = 0; j < count; poolType++) { if (poolType == 4) { return; } @@ -569,30 +564,31 @@ void func_80012AC4(NotePool* pool, s32 arg1) { poolList = &pool->active; break; } - while (var_s0 < arg1) { - note = func_800145FC(freeList); + while (j < count) { + note = AudioSeq_AudioListPopBack(freeList); if (note == NULL) { break; } - func_800145BC(poolList, note); - var_s0++; + AudioSeq_AudioListPushBack(poolList, note); + j++; } - poolType++; } } -void func_80012C00(AudioListItem* item1, AudioListItem* item2) { - if (item2->prev == NULL) { - item2->prev = item1; - item2->next = item1->next; - item1->next->prev = item2; - item1->next = item2; - item1->u.count++; - item2->pool = item1->pool; +void Audio_AudioListPushFront(AudioListItem* list, AudioListItem* item) { + // add 'item' to the front of the list given by 'list', if it's not in any list + if (item->prev == NULL) { + item->prev = list; + item->next = list->next; + list->next->prev = item; + list->next = item; + list->u.count++; + item->pool = list->pool; } } -void func_80012C40(Note* note) { +void Audio_AudioListRemove(Note* note) { + // remove 'item' from the list it's in, if any if (note->listItem.prev != NULL) { note->listItem.prev->next = note->listItem.next; note->listItem.next->prev = note->listItem.prev; @@ -600,7 +596,7 @@ void func_80012C40(Note* note) { } } -Note* func_80012C6C(AudioListItem* item, s32 priority) { +Note* Audio_FindNodeWithPrioLessThan(AudioListItem* item, s32 priority) { AudioListItem* priorityItem; AudioListItem* nextItem = item->next; @@ -625,7 +621,7 @@ Note* func_80012C6C(AudioListItem* item, s32 priority) { return (Note*) priorityItem->u.value; } -void func_80012CEC(Note* note, SequenceLayer* layer) { +void Audio_NoteInitForLayer(Note* note, SequenceLayer* layer) { s32 pad[4]; s32 var_a2; NoteSubEu* noteSub; @@ -639,7 +635,7 @@ void func_80012CEC(Note* note, SequenceLayer* layer) { layer->channel->noteUnused = note; layer->channel->layerUnused = layer; layer->noteVelocity = 0.0f; - func_80011EB8(note); + Audio_NoteInit(note); var_a2 = layer->instOrWave; noteSub = ¬e->noteSubEu; if (var_a2 == 0xFF) { @@ -652,7 +648,7 @@ void func_80012CEC(Note* note, SequenceLayer* layer) { noteSub->bitField1.isSyntheticWave = false; } if (noteSub->bitField1.isSyntheticWave) { - func_800126AC(note, layer, var_a2); + Audio_BuildSyntheticWave(note, layer, var_a2); } note->playbackState.fontId = layer->channel->fontId; noteSub->bitField0.stereoHeadsetEffects = layer->channel->stereoHeadsetEffects; @@ -660,122 +656,126 @@ void func_80012CEC(Note* note, SequenceLayer* layer) { } void func_80012E28(Note* note, SequenceLayer* layer) { - func_8001268C(note->playbackState.parentLayer); + Audio_SeqLayerNoteRelease(note->playbackState.parentLayer); note->playbackState.wantedParentLayer = layer; } -void func_80012E5C(Note* note, SequenceLayer* layer) { +void Audio_NoteReleaseAndTakeOwnership(Note* note, SequenceLayer* layer) { note->playbackState.wantedParentLayer = layer; note->playbackState.priority = layer->channel->notePriority; note->playbackState.adsr.fadeOutVel = gAudioBufferParams.ticksPerUpdateInv; note->playbackState.adsr.action.asByte |= 0x10; } -Note* func_80012E88(NotePool* pool, SequenceLayer* layer) { - Note* note = func_800145FC(&pool->disabled); +Note* Audio_AllocNoteFromDisabled(NotePool* pool, SequenceLayer* layer) { + Note* note = AudioSeq_AudioListPopBack(&pool->disabled); if (note != NULL) { - func_80012CEC(note, layer); - func_80012C00(&pool->active, ¬e->listItem); + Audio_NoteInitForLayer(note, layer); + Audio_AudioListPushFront(&pool->active, ¬e->listItem); } return note; } -Note* func_80012ED4(NotePool* pool, SequenceLayer* layer) { - Note* note = func_800145FC(&pool->decaying); +Note* Audio_AllocNoteFromDecaying(NotePool* pool, SequenceLayer* layer) { + Note* note = AudioSeq_AudioListPopBack(&pool->decaying); if (note != NULL) { - func_80012E5C(note, layer); - func_800145BC(&pool->releasing, ¬e->listItem); + Audio_NoteReleaseAndTakeOwnership(note, layer); + AudioSeq_AudioListPushBack(&pool->releasing, ¬e->listItem); } return note; } -Note* func_80012F24(NotePool* pool, SequenceLayer* layer) { - Note* sp34; - Note* sp30; - s32 sp2C; - s32 sp28; +Note* Audio_AllocNoteFromActive(NotePool* pool, SequenceLayer* layer) { + Note* rNote; + Note* aNote; + s32 rPriority; + s32 aPriority; - sp2C = sp28 = 0x10; - sp34 = func_80012C6C(&pool->releasing, layer->channel->notePriority); - if (sp34 != NULL) { - sp2C = sp34->playbackState.priority; + rPriority = aPriority = 0x10; + rNote = Audio_FindNodeWithPrioLessThan(&pool->releasing, layer->channel->notePriority); + + if (rNote != NULL) { + rPriority = rNote->playbackState.priority; } - sp30 = func_80012C6C(&pool->active, layer->channel->notePriority); - if (sp30 != NULL) { - sp28 = sp30->playbackState.priority; + + aNote = Audio_FindNodeWithPrioLessThan(&pool->active, layer->channel->notePriority); + + if (aNote != NULL) { + aPriority = aNote->playbackState.priority; } - if ((sp34 == NULL) && (sp30 == NULL)) { + + if (rNote == NULL && aNote == NULL) { return NULL; } - if (sp28 < sp2C) { - func_80012C40(sp30); - func_80012E28(sp30, layer); - func_800145BC(&pool->releasing, &sp30->listItem); - sp30->playbackState.priority = layer->channel->notePriority; - return sp30; - } else { - sp34->playbackState.wantedParentLayer = layer; - sp34->playbackState.priority = layer->channel->notePriority; - return sp34; + + if (aPriority < rPriority) { + Audio_AudioListRemove(aNote); + func_80012E28(aNote, layer); + AudioSeq_AudioListPushBack(&pool->releasing, &aNote->listItem); + aNote->playbackState.priority = layer->channel->notePriority; + return aNote; } + rNote->playbackState.wantedParentLayer = layer; + rNote->playbackState.priority = layer->channel->notePriority; + return rNote; } -Note* func_8001301C(SequenceLayer* layer) { - Note* sp24; +Note* Audio_AllocNote(SequenceLayer* layer) { + Note* note; if (layer->channel->noteAllocPolicy & 1) { - sp24 = layer->note; - if ((sp24 != NULL) && (layer == sp24->playbackState.prevParentLayer) && - (sp24->playbackState.wantedParentLayer == NO_LAYER)) { - - func_80012E5C(sp24, layer); - func_80012C40(sp24); - func_800145BC(&sp24->listItem.pool->releasing, &sp24->listItem); - return sp24; + note = layer->note; + if ((note != NULL) && (layer == note->playbackState.prevParentLayer) && + (note->playbackState.wantedParentLayer == NO_LAYER)) { + + Audio_NoteReleaseAndTakeOwnership(note, layer); + Audio_AudioListRemove(note); + AudioSeq_AudioListPushBack(¬e->listItem.pool->releasing, ¬e->listItem); + return note; } } if (layer->channel->noteAllocPolicy & 2) { - if (((sp24 = func_80012E88(&layer->channel->notePool, layer)) != NULL) || - ((sp24 = func_80012ED4(&layer->channel->notePool, layer)) != NULL) || - ((sp24 = func_80012F24(&layer->channel->notePool, layer)) != NULL)) { - return sp24; + if (((note = Audio_AllocNoteFromDisabled(&layer->channel->notePool, layer)) != NULL) || + ((note = Audio_AllocNoteFromDecaying(&layer->channel->notePool, layer)) != NULL) || + ((note = Audio_AllocNoteFromActive(&layer->channel->notePool, layer)) != NULL)) { + return note; } } else if (layer->channel->noteAllocPolicy & 4) { - if (((sp24 = func_80012E88(&layer->channel->notePool, layer)) != NULL) || - ((sp24 = func_80012E88(&layer->channel->seqPlayer->notePool, layer)) != NULL) || - ((sp24 = func_80012ED4(&layer->channel->notePool, layer)) != NULL) || - ((sp24 = func_80012ED4(&layer->channel->seqPlayer->notePool, layer)) != NULL) || - ((sp24 = func_80012F24(&layer->channel->notePool, layer)) != NULL) || - ((sp24 = func_80012F24(&layer->channel->seqPlayer->notePool, layer)) != NULL)) { - return sp24; + if (((note = Audio_AllocNoteFromDisabled(&layer->channel->notePool, layer)) != NULL) || + ((note = Audio_AllocNoteFromDisabled(&layer->channel->seqPlayer->notePool, layer)) != NULL) || + ((note = Audio_AllocNoteFromDecaying(&layer->channel->notePool, layer)) != NULL) || + ((note = Audio_AllocNoteFromDecaying(&layer->channel->seqPlayer->notePool, layer)) != NULL) || + ((note = Audio_AllocNoteFromActive(&layer->channel->notePool, layer)) != NULL) || + ((note = Audio_AllocNoteFromActive(&layer->channel->seqPlayer->notePool, layer)) != NULL)) { + return note; } } else if (layer->channel->noteAllocPolicy & 8) { - if (((sp24 = func_80012E88(&gNoteFreeLists, layer)) != NULL) || - ((sp24 = func_80012ED4(&gNoteFreeLists, layer)) != NULL) || - ((sp24 = func_80012F24(&gNoteFreeLists, layer)) != NULL)) { - return sp24; + if (((note = Audio_AllocNoteFromDisabled(&gNoteFreeLists, layer)) != NULL) || + ((note = Audio_AllocNoteFromDecaying(&gNoteFreeLists, layer)) != NULL) || + ((note = Audio_AllocNoteFromActive(&gNoteFreeLists, layer)) != NULL)) { + return note; } } else { - if (((sp24 = func_80012E88(&layer->channel->notePool, layer)) != NULL) || - ((sp24 = func_80012E88(&layer->channel->seqPlayer->notePool, layer)) != NULL) || - ((sp24 = func_80012E88(&gNoteFreeLists, layer)) != NULL) || - ((sp24 = func_80012ED4(&layer->channel->notePool, layer)) != NULL) || - ((sp24 = func_80012ED4(&layer->channel->seqPlayer->notePool, layer)) != NULL) || - ((sp24 = func_80012ED4(&gNoteFreeLists, layer)) != NULL) || - ((sp24 = func_80012F24(&layer->channel->notePool, layer)) != NULL) || - ((sp24 = func_80012F24(&layer->channel->seqPlayer->notePool, layer)) != NULL) || - ((sp24 = func_80012F24(&gNoteFreeLists, layer)) != NULL)) { - return sp24; + if (((note = Audio_AllocNoteFromDisabled(&layer->channel->notePool, layer)) != NULL) || + ((note = Audio_AllocNoteFromDisabled(&layer->channel->seqPlayer->notePool, layer)) != NULL) || + ((note = Audio_AllocNoteFromDisabled(&gNoteFreeLists, layer)) != NULL) || + ((note = Audio_AllocNoteFromDecaying(&layer->channel->notePool, layer)) != NULL) || + ((note = Audio_AllocNoteFromDecaying(&layer->channel->seqPlayer->notePool, layer)) != NULL) || + ((note = Audio_AllocNoteFromDecaying(&gNoteFreeLists, layer)) != NULL) || + ((note = Audio_AllocNoteFromActive(&layer->channel->notePool, layer)) != NULL) || + ((note = Audio_AllocNoteFromActive(&layer->channel->seqPlayer->notePool, layer)) != NULL) || + ((note = Audio_AllocNoteFromActive(&gNoteFreeLists, layer)) != NULL)) { + return note; } } layer->unk_3 = 0; return NULL; } -void func_800132E8(void) { +void Audio_NoteInitAll(void) { s32 i; Note* note; diff --git a/src/audio/audio_seqplayer.c b/src/audio/audio_seqplayer.c index 8f0bd778..cfb77e2c 100644 --- a/src/audio/audio_seqplayer.c +++ b/src/audio/audio_seqplayer.c @@ -1,6 +1,18 @@ #include "sys.h" #include "sf64audio_provisional.h" +#define PORTAMENTO_IS_SPECIAL(x) ((x).mode & 0x80) +#define PORTAMENTO_MODE(x) ((x).mode & ~0x80) + +typedef enum { + /* 0 */ PORTAMENTO_MODE_OFF, + /* 1 */ PORTAMENTO_MODE_1, + /* 2 */ PORTAMENTO_MODE_2, + /* 3 */ PORTAMENTO_MODE_3, + /* 4 */ PORTAMENTO_MODE_4, + /* 5 */ PORTAMENTO_MODE_5 +} PortamentoMode; + static const char devstr00[] = "Audio:Track:Warning: No Free Notetrack\n"; static const char devstr01[] = "SUBTRACK DIM\n"; static const char devstr02[] = "Audio:Track: Warning :SUBTRACK had been stolen by other Group.\n"; @@ -33,21 +45,21 @@ static const char devstr28[] = "Macro Level Over Error!\n"; static const char devstr29[] = "Group:Undefine upper C0h command (%x)\n"; static const char devstr30[] = "Group:Undefined Command\n"; -void func_800145BC(AudioListItem* list, AudioListItem* item); -void* func_800145FC(AudioListItem* list); -u8 func_800152C0(SequenceChannel* channel, u8 arg1, Instrument** instrument, AdsrSettings* adsrSettings); +void AudioSeq_AudioListPushBack(AudioListItem* list, AudioListItem* item); +void* AudioSeq_AudioListPopBack(AudioListItem* list); +u8 AudioSeq_GetInstrument(SequenceChannel* channel, u8 instId, Instrument** instrumentOut, AdsrSettings* adsrSettings); -void func_80013EA0(SequenceChannel* channel) { +void AudioSeq_InitSequenceChannel(SequenceChannel* channel) { s32 i; - channel->enabled = 0; - channel->finished = 0; - channel->stopScript = 0; - channel->muted = 0; + channel->enabled = false; + channel->finished = false; + channel->stopScript = false; + channel->muted = false; channel->hasInstrument = false; - channel->stereoHeadsetEffects = 0; + channel->stereoHeadsetEffects = false; channel->transposition = 0; - channel->largeNotes = 0; + channel->largeNotes = false; channel->bookOffset = 0; channel->changes.asByte = 0xFF; channel->scriptState.depth = 0; @@ -76,83 +88,84 @@ void func_80013EA0(SequenceChannel* channel) { channel->seqScriptIO[i] = -1; } channel->unused = 0; - func_80012864(&channel->notePool); + Audio_InitNoteLists(&channel->notePool); } -s32 func_80013FC4(SequenceChannel* channel, s32 arg1) { - SequenceLayer* temp_v0; - SequenceLayer* temp; +s32 AudioSeq_SeqChannelSetLayer(SequenceChannel* channel, s32 layerIndex) { + SequenceLayer* layer; + s32 pad; - if (channel->layers[arg1] == NULL) { - temp_v0 = func_800145FC(&gLayerFreeList); - channel->layers[arg1] = temp_v0; - if (temp_v0 == NULL) { - channel->layers[arg1] = NULL; + if (channel->layers[layerIndex] == NULL) { + layer = AudioSeq_AudioListPopBack(&gLayerFreeList); + channel->layers[layerIndex] = layer; + if (layer == NULL) { + channel->layers[layerIndex] = NULL; return -1; } } else { - func_8001266C(channel->layers[arg1]); + Audio_SeqLayerNoteDecay(channel->layers[layerIndex]); } - temp = channel->layers[arg1]; - temp->channel = channel; - temp->adsr = channel->adsr; - temp->enabled = 1; - temp->muted = 0; - temp->continuousNotes = 0; - temp->finished = 0; - temp->adsr.decayIndex = 0; - temp->bit1 = 0; - temp->stereo.asByte = 0x40; - temp->portamento.mode = 0; - temp->state.depth = 0; - temp->unk_3 = 0; - temp->gateTime = 0x80; - temp->pan = 0x40; - temp->transposition = 0; - temp->delay = 0; - temp->gateDelay = 0; - temp->delay2 = 0; - temp->note = NULL; - temp->instrument = NULL; - temp->instOrWave = 0xFF; - temp->freqMod = 1.0f; - temp->velocitySquare = 0.0f; + + layer = channel->layers[layerIndex]; + + layer->channel = channel; + layer->adsr = channel->adsr; + layer->enabled = true; + layer->muted = false; + layer->continuousNotes = false; + layer->finished = false; + layer->adsr.decayIndex = 0; + layer->bit1 = false; + layer->stereo.asByte = 0x40; + layer->portamento.mode = PORTAMENTO_MODE_OFF; + layer->state.depth = 0; + layer->unk_3 = 0; + layer->gateTime = 0x80; + layer->pan = 0x40; + layer->transposition = 0; + layer->delay = 0; + layer->gateDelay = 0; + layer->delay2 = 0; + layer->note = NULL; + layer->instrument = NULL; + layer->instOrWave = 0xFF; + layer->freqMod = 1.0f; + layer->velocitySquare = 0.0f; return 0; } -void func_800140D0(SequenceLayer* layer) { +void AudioSeq_SeqLayerDisable(SequenceLayer* layer) { if (layer != NULL) { - func_8001266C(layer); + Audio_SeqLayerNoteDecay(layer); layer->enabled = 0; layer->finished = 1; } } -void func_8001410C(SequenceChannel* channel, s32 arg1) { - SequenceLayer* temp_a2 = channel->layers[arg1]; +void AudioSeq_SeqLayerFree(SequenceChannel* channel, s32 layerIndex) { + SequenceLayer* layer = channel->layers[layerIndex]; - if (temp_a2 != NULL) { - func_800145BC(&gLayerFreeList, &temp_a2->listItem); - func_800140D0(temp_a2); - channel->layers[arg1] = NULL; + if (layer != NULL) { + AudioSeq_AudioListPushBack(&gLayerFreeList, &layer->listItem); + AudioSeq_SeqLayerDisable(layer); + channel->layers[layerIndex] = NULL; } } -void func_8001415C(SequenceChannel* channel) { - s32 var_s0; +void AudioSeq_SequenceChannelDisable(SequenceChannel* channel) { + s32 i; - for (var_s0 = 0; var_s0 < ARRAY_COUNT(channel->layers); var_s0++) { - func_8001410C(channel, var_s0); + for (i = 0; i < ARRAY_COUNT(channel->layers); i++) { + AudioSeq_SeqLayerFree(channel, i); } - func_80012964(&channel->notePool); - channel->enabled = 0; - channel->finished = 1; + Audio_NotePoolClear(&channel->notePool); + channel->enabled = false; + channel->finished = true; } -SequenceChannel* func_800141C8(void) { +SequenceChannel* AudioSeq_RequestFreeSeqChannel(void) { s32 i; - SequenceChannel* var_v1; for (i = 0; i < 48; i++) { if (gSeqChannels[i].seqPlayer == NULL) { @@ -162,83 +175,82 @@ SequenceChannel* func_800141C8(void) { return &gSeqChannelNone; } -void func_80014244(SequencePlayer* seqPlayer, u16 arg1) { - SequenceChannel* temp_s0; - SequenceChannel* temp_v0; +void AudioSeq_SequencePlayerSetupChannels(SequencePlayer* seqPlayer, u16 channelBits) { + SequenceChannel* channel; s32 i; - for (i = 0; i < 16; i++) { - if (arg1 & 1) { - temp_s0 = seqPlayer->channels[i]; - if ((IS_SEQUENCE_CHANNEL_VALID(temp_s0) == 1) && (seqPlayer == temp_s0->seqPlayer)) { - func_8001415C(temp_s0); - temp_s0->seqPlayer = NULL; + for (i = 0; i < SEQ_NUM_CHANNELS; i++) { + if (channelBits & 1) { + channel = seqPlayer->channels[i]; + if ((IS_SEQUENCE_CHANNEL_VALID(channel) == 1) && (seqPlayer == channel->seqPlayer)) { + AudioSeq_SequenceChannelDisable(channel); + channel->seqPlayer = NULL; } - temp_v0 = func_800141C8(); - if (IS_SEQUENCE_CHANNEL_VALID(temp_v0) == 0) { + channel = AudioSeq_RequestFreeSeqChannel(); + if (IS_SEQUENCE_CHANNEL_VALID(channel) == 0) { D_80155D88 = i + 0x10000; - seqPlayer->channels[i] = temp_v0; + seqPlayer->channels[i] = channel; } else { - func_80013EA0(temp_v0); - seqPlayer->channels[i] = temp_v0; - temp_v0->seqPlayer = seqPlayer; - temp_v0->fontId = seqPlayer->defaultFont; - temp_v0->muteBehavior = seqPlayer->muteBehavior; - temp_v0->noteAllocPolicy = seqPlayer->noteAllocPolicy; + AudioSeq_InitSequenceChannel(channel); + seqPlayer->channels[i] = channel; + channel->seqPlayer = seqPlayer; + channel->fontId = seqPlayer->defaultFont; + channel->muteBehavior = seqPlayer->muteBehavior; + channel->noteAllocPolicy = seqPlayer->noteAllocPolicy; } } - arg1 = arg1 >> 1; + channelBits = channelBits >> 1; } } -void func_80014370(SequencePlayer* seqPlayer, u16 arg1) { +void AudioSeq_SequencePlayerDisableChannels(SequencePlayer* seqPlayer, u16 channelBitsUnused) { s32 i; - for (i = 0; i < 16; i++) { - if (arg1 & 1) { - SequenceChannel* temp_s0 = seqPlayer->channels[i]; + for (i = 0; i < SEQ_NUM_CHANNELS; i++) { + if (channelBitsUnused & 1) { + SequenceChannel* channel = seqPlayer->channels[i]; - if (IS_SEQUENCE_CHANNEL_VALID(temp_s0) == 1) { - if (seqPlayer == temp_s0->seqPlayer) { - func_8001415C(temp_s0); + if (IS_SEQUENCE_CHANNEL_VALID(channel) == 1) { + if (seqPlayer == channel->seqPlayer) { + AudioSeq_SequenceChannelDisable(channel); if (0) {} - temp_s0->seqPlayer = NULL; + channel->seqPlayer = NULL; } seqPlayer->channels[i] = &gSeqChannelNone; } } - arg1 = arg1 >> 1; + channelBitsUnused = channelBitsUnused >> 1; } } -void func_80014440(SequencePlayer* seqPlayer, u8 arg1, u8* arg2) { - SequenceChannel* channel = seqPlayer->channels[arg1]; +void AudioSeq_SequenceChannelEnable(SequencePlayer* seqPlayer, u8 channelIndex, void* script) { + SequenceChannel* channel = seqPlayer->channels[channelIndex]; s32 i; if (IS_SEQUENCE_CHANNEL_VALID(channel) != 0) { channel->scriptState.depth = 0; - channel->scriptState.pc = arg2; + channel->scriptState.pc = script; channel->enabled = 1; channel->finished = 0; channel->delay = 0; for (i = 0; i < ARRAY_COUNT(channel->layers); i++) { if (channel->layers[i] != NULL) { - func_8001410C(channel, i); + AudioSeq_SeqLayerFree(channel, i); } } } } -void func_800144E4(SequencePlayer* seqPlayer) { - func_80014370(seqPlayer, 0xFFFF); - func_80012964(&seqPlayer->notePool); - seqPlayer->finished = 1; - seqPlayer->enabled = 0; +void AudioSeq_SequencePlayerDisable(SequencePlayer* seqPlayer) { + AudioSeq_SequencePlayerDisableChannels(seqPlayer, 0xFFFF); + Audio_NotePoolClear(&seqPlayer->notePool); + seqPlayer->finished = true; + seqPlayer->enabled = false; if ((gSeqLoadStatus[seqPlayer->seqId] >= 2) && (gSeqLoadStatus[seqPlayer->seqId] != 5)) { - gSeqLoadStatus[seqPlayer->seqId] = 3; + gSeqLoadStatus[seqPlayer->seqId] = LOAD_STATUS_DISCARDABLE; } if ((gFontLoadStatus[seqPlayer->defaultFont] >= 2) && (gFontLoadStatus[seqPlayer->defaultFont] != 5)) { - gFontLoadStatus[seqPlayer->defaultFont] = 4; + gFontLoadStatus[seqPlayer->defaultFont] = LOAD_STATUS_MAYBE_DISCARDABLE; } if (seqPlayer->defaultFont == gFontCache.temporary.entries[0].id) { gFontCache.temporary.nextSide = 1; @@ -247,7 +259,7 @@ void func_800144E4(SequencePlayer* seqPlayer) { } } -void func_800145BC(AudioListItem* list, AudioListItem* item) { +void AudioSeq_AudioListPushBack(AudioListItem* list, AudioListItem* item) { if (item->prev == NULL) { list->prev->next = item; item->prev = list->prev; @@ -258,7 +270,7 @@ void func_800145BC(AudioListItem* list, AudioListItem* item) { } } -void* func_800145FC(AudioListItem* list) { +void* AudioSeq_AudioListPopBack(AudioListItem* list) { AudioListItem* item = list->prev; if (item == list) { @@ -271,7 +283,7 @@ void* func_800145FC(AudioListItem* list) { return item->u.value; } -void func_8001463C(void) { +void AudioSeq_InitLayerFreelist(void) { s32 i; gLayerFreeList.prev = &gLayerFreeList; @@ -279,25 +291,25 @@ void func_8001463C(void) { gLayerFreeList.u.value = NULL; gLayerFreeList.pool = NULL; - for (i = 0; i < 64; i++) { + for (i = 0; i < ARRAY_COUNT(gSeqLayers); i++) { gSeqLayers[i].listItem.u.value = &gSeqLayers[i]; gSeqLayers[i].listItem.prev = NULL; - func_800145BC(&gLayerFreeList, &gSeqLayers[i].listItem); + AudioSeq_AudioListPushBack(&gLayerFreeList, &gSeqLayers[i].listItem); } } -u8 func_800146C0(SeqScriptState* state) { +u8 AudioSeq_ScriptReadU8(SeqScriptState* state) { return *(state->pc++); } -s16 func_800146D4(SeqScriptState* state) { +s16 AudioSeq_ScriptReadS16(SeqScriptState* state) { s16 ret = *(state->pc++) << 8; ret = *(state->pc++) | ret; return ret; } -u16 func_80014704(SeqScriptState* state) { +u16 AudioSeq_ScriptReadCompressedU16(SeqScriptState* state) { u16 ret = *(state->pc++); if (ret & 0x80) { @@ -307,7 +319,7 @@ u16 func_80014704(SeqScriptState* state) { return ret; } -void func_80014748(SequenceLayer* layer) { +void AudioSeq_SeqLayerProcessScript(SequenceLayer* layer) { SequencePlayer* seqPlayer; SequenceChannel* channel; // sp60 SeqScriptState* state; @@ -317,56 +329,66 @@ void func_80014748(SequenceLayer* layer) { TunedSample* sample; Portamento* portamento; s16 var_s2; - u16 sp44; // sp44 + u16 cmdArg16; s32 sp40 = true; // sp40 if (!layer->enabled) { return; } + if (layer->delay >= 2) { layer->delay--; if (!layer->muted && (layer->gateDelay >= layer->delay)) { - func_8001266C(layer); - layer->muted = 1; + Audio_SeqLayerNoteDecay(layer); + layer->muted = true; } return; } + if (!layer->continuousNotes) { - func_8001266C(layer); + Audio_SeqLayerNoteDecay(layer); } else if ((layer->note != NULL) && (layer == layer->note->playbackState.wantedParentLayer)) { - func_8001266C(layer); + Audio_SeqLayerNoteDecay(layer); } - if (((layer->portamento.mode & ~0x80) == 1) || ((layer->portamento.mode & ~0x80) == 2)) { - layer->portamento.mode = 0; + + if ((PORTAMENTO_MODE(layer->portamento) == PORTAMENTO_MODE_1) || + (PORTAMENTO_MODE(layer->portamento) == PORTAMENTO_MODE_2)) { + layer->portamento.mode = PORTAMENTO_MODE_OFF; } + channel = layer->channel; state = &layer->state; seqPlayer = channel->seqPlayer; layer->ignoreDrumPan = 1; + while (true) { - cmd = func_800146C0(state); + cmd = AudioSeq_ScriptReadU8(state); if (cmd <= 0xC0) { break; } - switch (cmd) { /* switch 5; irregular */ + + switch (cmd) { case 0xFF: if (state->depth == 0) { - func_800140D0(layer); + AudioSeq_SeqLayerDisable(layer); return; } state->pc = state->stack[--state->depth]; break; + case 0xFC: - sp44 = func_800146D4(state); + cmdArg16 = AudioSeq_ScriptReadS16(state); state->stack[state->depth] = state->pc; state->depth++; - state->pc = &seqPlayer->seqData[sp44]; + state->pc = &seqPlayer->seqData[cmdArg16]; break; + case 0xF8: - state->remLoopIters[state->depth] = func_800146C0(state); + state->remLoopIters[state->depth] = AudioSeq_ScriptReadU8(state); state->stack[state->depth] = state->pc; state->depth++; break; + case 0xF7: state->remLoopIters[state->depth - 1]--; if (state->remLoopIters[state->depth - 1] != 0) { @@ -375,15 +397,18 @@ void func_80014748(SequenceLayer* layer) { state->depth--; } break; + case 0xFB: - sp44 = func_800146D4(state); - state->pc = &seqPlayer->seqData[sp44]; + cmdArg16 = AudioSeq_ScriptReadS16(state); + state->pc = &seqPlayer->seqData[cmdArg16]; break; + case 0xF4: - state->pc += (s8) func_800146C0(state); + state->pc += (s8) AudioSeq_ScriptReadU8(state); break; - case 0xC1: - case 0xCA: + + case 0xC1: // layer_setshortnotevelocity + case 0xCA: // layer_setpan var_s2 = *state->pc++; if (cmd == 0xC1) { layer->velocitySquare = (f32) (var_s2 * var_s2) / 16129.0f; @@ -391,8 +416,9 @@ void func_80014748(SequenceLayer* layer) { layer->pan = var_s2; } break; - case 0xC2: - case 0xC9: + + case 0xC2: // layer_setshortnotegatetime + case 0xC9: // layer_transpose; set transposition in semitones var_s2 = *state->pc++; if (cmd == 0xC9) { layer->gateTime = var_s2; @@ -400,90 +426,109 @@ void func_80014748(SequenceLayer* layer) { layer->transposition = var_s2; } break; - case 0xC4: - case 0xC5: + + case 0xC4: // layer_continuousnoteson + case 0xC5: // layer_continuousnotesoff if (cmd == 0xC4) { - layer->continuousNotes = 1; + layer->continuousNotes = true; } else { - layer->continuousNotes = 0; + layer->continuousNotes = false; } - func_8001266C(layer); + Audio_SeqLayerNoteDecay(layer); break; - case 0xC3: - sp44 = func_80014704(state); - layer->shortNoteDefaultDelay = sp44; + + case 0xC3: // layer_setshortnotedefaultdelay + cmdArg16 = AudioSeq_ScriptReadCompressedU16(state); + layer->shortNoteDefaultDelay = cmdArg16; break; - case 0xC6: - cmd = func_800146C0(state); - if (cmd >= 127) { - if (cmd == 127) { + + case 0xC6: // layer_setinstr + cmd = AudioSeq_ScriptReadU8(state); + if (cmd >= 0x7F) { + if (cmd == 0x7F) { + // Drums layer->instOrWave = 0; } else { + // Synthetic Wave layer->instOrWave = cmd; layer->instrument = NULL; } - if (cmd == 255) { + if (cmd == 0xFF) { layer->adsr.decayIndex = 0; } } else { - // cmd = func_800152C0(channel, cmd, &layer->instrument, &layer->adsr); - // layer->instOrWave = cmd; - if ((layer->instOrWave = func_800152C0(channel, cmd, &layer->instrument, &layer->adsr)) == 0) { + // Instrument + if ((layer->instOrWave = AudioSeq_GetInstrument(channel, cmd, &layer->instrument, &layer->adsr)) == + 0) { layer->instOrWave = 0xFF; } } break; - case 0xC7: - layer->portamento.mode = func_800146C0(state); - cmd = func_800146C0(state) + channel->transposition + layer->transposition + seqPlayer->transposition; - if (cmd > 127) { + + case 0xC7: // layer_portamento + layer->portamento.mode = AudioSeq_ScriptReadU8(state); + + cmd = AudioSeq_ScriptReadU8(state); + cmd += channel->transposition; + cmd += layer->transposition; + cmd += seqPlayer->transposition; + + if (cmd >= 0x80) { cmd = 0; } + layer->portamentoTargetNote = cmd; - if (layer->portamento.mode & 0x80) { - layer->portamentoTime = *state->pc++; + + // If special, the next param is u8 instead of var + if (PORTAMENTO_IS_SPECIAL(layer->portamento)) { + layer->portamentoTime = *(state->pc++); } else { - sp44 = func_80014704(state); - layer->portamentoTime = sp44; + cmdArg16 = AudioSeq_ScriptReadCompressedU16(state); + layer->portamentoTime = cmdArg16; } break; - case 0xC8: - layer->portamento.mode = 0; + + case 0xC8: // layer_disableportamento + layer->portamento.mode = PORTAMENTO_MODE_OFF; break; + case 0xCB: - sp44 = func_800146D4(state); - layer->adsr.envelope = (EnvelopePoint*) &seqPlayer->seqData[sp44]; - layer->adsr.decayIndex = func_800146C0(state); + cmdArg16 = AudioSeq_ScriptReadS16(state); + layer->adsr.envelope = (EnvelopePoint*) &seqPlayer->seqData[cmdArg16]; + layer->adsr.decayIndex = AudioSeq_ScriptReadU8(state); break; + case 0xCC: - layer->bit1 = 1; + layer->bit1 = true; break; + case 0xCD: - layer->stereo.asByte = func_800146C0(state); + layer->stereo.asByte = AudioSeq_ScriptReadU8(state); break; + default: - switch (cmd & 0xF0) { /* switch 6; irregular */ - case 0xD0: - sp44 = (u16) seqPlayer->shortNoteVelocityTable[cmd & 0xF]; - layer->velocitySquare = (f32) (sp44 * sp44) / 16129.0f; + switch (cmd & 0xF0) { + case 0xD0: // layer_setshortnotevelocityfromtable + cmdArg16 = (u16) seqPlayer->shortNoteVelocityTable[cmd & 0xF]; + layer->velocitySquare = (f32) (cmdArg16 * cmdArg16) / 16129.0f; break; - case 0xE0: + + case 0xE0: // layer_setshortnotegatetimefromtable layer->gateTime = seqPlayer->shortNoteGateTimeTable[cmd & 0xF]; break; - default: - break; } break; } } + if (cmd == 0xC0) { - layer->delay = func_80014704(state); + layer->delay = AudioSeq_ScriptReadCompressedU16(state); layer->muted = true; } else { f32 tuning; f32 freqMod; u32 instOrWave; - s32 vel; // sp30 + s32 vel; f32 temp_fa1; f32 temp_fv1; f32 var_v0_2; @@ -493,46 +538,53 @@ void func_80014748(SequenceLayer* layer) { if (channel->largeNotes == 1) { switch (cmd & 0xC0) { case 0x00: - sp44 = func_80014704(state); + cmdArg16 = AudioSeq_ScriptReadCompressedU16(state); vel = *state->pc++; - layer->gateTime = *state->pc++; - layer->lastDelay = sp44; + layer->gateTime = *(state->pc++); + layer->lastDelay = cmdArg16; break; + case 0x40: - sp44 = func_80014704(state); + cmdArg16 = AudioSeq_ScriptReadCompressedU16(state); vel = *state->pc++; layer->gateTime = 0; - layer->lastDelay = sp44; + layer->lastDelay = cmdArg16; break; + case 0x80: - sp44 = layer->lastDelay; + cmdArg16 = layer->lastDelay; vel = *state->pc++; - layer->gateTime = *state->pc++; - + layer->gateTime = *(state->pc)++; break; } + if ((vel > 127) || (vel < 0)) { vel = 127; } + layer->velocitySquare = SQ((f32) vel) / 16129.0f; cmd -= (cmd & 0xC0); } else { - switch (cmd & 0xC0) { /* switch 4; irregular */ + switch (cmd & 0xC0) { case 0x0: - sp44 = func_80014704(state); - layer->lastDelay = sp44; + cmdArg16 = AudioSeq_ScriptReadCompressedU16(state); + layer->lastDelay = cmdArg16; break; + case 0x40: - sp44 = layer->shortNoteDefaultDelay; + cmdArg16 = layer->shortNoteDefaultDelay; break; + case 0x80: - sp44 = layer->lastDelay; + cmdArg16 = layer->lastDelay; break; } cmd -= (cmd & 0xC0); } - layer->delay = sp44; - layer->gateDelay = (layer->gateTime * sp44) >> 8; + + layer->delay = cmdArg16; + layer->gateDelay = (layer->gateTime * cmdArg16) >> 8; + if ((seqPlayer->muted && (channel->muteBehavior & 0x50)) || (channel->muted)) { layer->muted = 1; } else { @@ -544,13 +596,16 @@ void func_80014748(SequenceLayer* layer) { instOrWave = channel->instOrWave; } if (instOrWave == 0) { - cmd = cmd + channel->transposition + layer->transposition; + cmd += channel->transposition; + cmd += layer->transposition; + drum = Audio_GetDrum(channel->fontId, cmd); if (drum == NULL) { layer->muted = true; layer->delay2 = layer->delay; return; } + layer->adsr.envelope = drum->envelope; layer->adsr.decayIndex = drum->adsrDecayIndex; if (!layer->bit1) { @@ -559,7 +614,7 @@ void func_80014748(SequenceLayer* layer) { layer->tunedSample = &drum->tunedSample; layer->freqMod = layer->tunedSample->tuning; } else { - cmd = cmd + seqPlayer->transposition + channel->transposition + layer->transposition; + cmd += seqPlayer->transposition + channel->transposition + layer->transposition; if (cmd >= 0x80) { layer->muted = 1; } else { @@ -568,15 +623,16 @@ void func_80014748(SequenceLayer* layer) { } else { instrument = layer->instrument; } - if (layer->portamento.mode != 0) { + if (layer->portamento.mode != PORTAMENTO_MODE_OFF) { if (layer->portamentoTargetNote < cmd) { temp2 = cmd; } else { temp2 = layer->portamentoTargetNote; } + if (instrument != NULL) { - sample = func_80011D10(instrument, temp2); + sample = Audio_GetInstrumentTunedSample(instrument, temp2); sp40 = (sample == layer->tunedSample); layer->tunedSample = sample; tuning = sample->tuning; @@ -584,21 +640,26 @@ void func_80014748(SequenceLayer* layer) { tuning = 1.0f; layer->tunedSample = NULL; } + temp_fv1 = gPitchFrequencies[cmd] * tuning; temp_fa1 = gPitchFrequencies[layer->portamentoTargetNote] * tuning; + portamento = &layer->portamento; - switch (portamento->mode & ~0x80) { - case 1: - case 3: - case 5: + + switch (PORTAMENTO_MODE(*portamento)) { + case PORTAMENTO_MODE_1: + case PORTAMENTO_MODE_3: + case PORTAMENTO_MODE_5: var_v0_2 = temp_fv1; freqMod = temp_fa1; break; - case 2: - case 4: + + case PORTAMENTO_MODE_2: + case PORTAMENTO_MODE_4: freqMod = temp_fv1; var_v0_2 = temp_fa1; break; + default: freqMod = temp_fv1; var_v0_2 = temp_fv1; @@ -613,12 +674,13 @@ void func_80014748(SequenceLayer* layer) { portamento->speed = 127.0f / (s32) layer->portamentoTime; } portamento->cur = 0.0f; + layer->freqMod = freqMod; if ((layer->portamento.mode & ~0x80) == 5) { layer->portamentoTargetNote = cmd; } } else if (instrument != NULL) { - sample = func_80011D10(instrument, cmd); + sample = Audio_GetInstrumentTunedSample(instrument, cmd); sp40 = (sample == layer->tunedSample); layer->tunedSample = sample; layer->freqMod = gPitchFrequencies[cmd] * sample->tuning; @@ -631,13 +693,14 @@ void func_80014748(SequenceLayer* layer) { layer->delay2 = layer->delay; } } - if ((layer->muted == 0) && (layer->tunedSample != NULL) && (layer->tunedSample->sample->codec == 2) && + + if ((layer->muted == false) && (layer->tunedSample != NULL) && (layer->tunedSample->sample->codec == 2) && (layer->tunedSample->sample->medium != 0)) { layer->muted = 1; } - if (layer->muted == 1) { + if (layer->muted == true) { if ((layer->note != NULL) || (layer->continuousNotes)) { - func_8001266C(layer); + Audio_SeqLayerNoteDecay(layer); } } else { cmd = 0; @@ -646,48 +709,53 @@ void func_80014748(SequenceLayer* layer) { } else if ((layer->note == NULL) || ((u8) layer->unk_3 == 0)) { cmd = 1; } else if (sp40 == 0) { - func_8001266C(layer); + Audio_SeqLayerNoteDecay(layer); cmd = 1; } else if (layer != layer->note->playbackState.parentLayer) { cmd = 1; } else if (layer->tunedSample == NULL) { - func_800127B0(layer->note, layer); + Audio_InitSyntheticWave(layer->note, layer); } if (cmd != 0) { - layer->note = func_8001301C(layer); + layer->note = Audio_AllocNote(layer); } if ((layer->note != NULL) && (layer == layer->note->playbackState.parentLayer)) { - func_80013A84(layer->note); + Audio_NoteVibratoInit(layer->note); } } if (!channel) {} } -u8 func_800152C0(SequenceChannel* channel, u8 arg1, Instrument** instrument, AdsrSettings* adsrSettings) { - Instrument* temp_v0; +u8 AudioSeq_GetInstrument(SequenceChannel* channel, u8 instId, Instrument** instrumentOut, AdsrSettings* adsrSettings) { + Instrument* instrument; - temp_v0 = Audio_GetInstrument(channel->fontId, arg1); - if (temp_v0 == NULL) { - *instrument = NULL; + instrument = Audio_GetInstrument(channel->fontId, instId); + if (instrument == NULL) { + *instrumentOut = NULL; return 0; } - adsrSettings->envelope = temp_v0->envelope; - adsrSettings->decayIndex = temp_v0->adsrDecayIndex; - *instrument = temp_v0; - arg1++; - return arg1; + adsrSettings->envelope = instrument->envelope; + adsrSettings->decayIndex = instrument->adsrDecayIndex; + *instrumentOut = instrument; + instId++; + + return instId; } -void func_80015330(SequenceChannel* channel, u8 arg1) { - if (arg1 >= 0x80) { - channel->instOrWave = arg1; +void AudioSeq_SetInstrument(SequenceChannel* channel, u8 instId) { + if (instId >= 0x80) { + // Synthetic Waves + channel->instOrWave = instId; channel->instrument = NULL; - } else if (arg1 == 0x7F) { + } else if (instId == 0x7F) { + // Drums channel->instOrWave = 0; - channel->instrument = (Instrument*) 1; + channel->instrument = (Instrument*) 1; // invalid pointer, never dereferenced } else { - if ((channel->instOrWave = func_800152C0(channel, arg1, &channel->instrument, &channel->adsr)) == 0) { + // Instruments + if ((channel->instOrWave = AudioSeq_GetInstrument(channel, instId, &channel->instrument, &channel->adsr)) == + 0) { channel->hasInstrument = false; return; } @@ -695,11 +763,11 @@ void func_80015330(SequenceChannel* channel, u8 arg1) { channel->hasInstrument = true; } -void func_800153C4(SequenceChannel* channel, u8 arg1) { - channel->volume = (s32) arg1 / 127.0f; +void AudioSeq_SequenceChannelSetVolume(SequenceChannel* channel, u8 volume) { + channel->volume = (s32) volume / 127.0f; } -void func_800153E8(SequenceChannel* channel) { +void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) { s32 i; SequencePlayer* seqPlayer; u8 cmd; @@ -717,7 +785,7 @@ void func_800153E8(SequenceChannel* channel) { if (channel->stopScript) { for (i = 0; i < ARRAY_COUNT(channel->layers); i++) { if (channel->layers[i] != NULL) { - func_80014748(channel->layers[i]); + AudioSeq_SeqLayerProcessScript(channel->layers[i]); } } return; @@ -735,42 +803,46 @@ void func_800153E8(SequenceChannel* channel) { while (true) { state = &channel->scriptState; - cmd = func_800146C0(state); + cmd = AudioSeq_ScriptReadU8(state); + if (cmd > 0xC0) { switch (cmd) { case 0xD5: case 0xD6: break; + case 0xFF: if (state->depth == 0) { - func_8001415C(channel); + AudioSeq_SequenceChannelDisable(channel); goto end_loop; } state->pc = state->stack[--state->depth]; break; + case 0xFE: goto end_loop; + case 0xFD: - channel->delay = func_80014704(state); + channel->delay = AudioSeq_ScriptReadCompressedU16(state); goto end_loop; + case 0xEA: channel->stopScript = 1; goto end_loop; + case 0xFC: - // if (0 && state->depth >= 4) { - // } - sp52 = func_800146D4(state); + sp52 = AudioSeq_ScriptReadS16(state); state->stack[state->depth] = state->pc; state->depth++; state->pc = &seqPlayer->seqData[sp52]; break; + case 0xF8: - // if (0 && state->depth >= 4) { - // } - state->remLoopIters[state->depth] = func_800146C0(state); + state->remLoopIters[state->depth] = AudioSeq_ScriptReadU8(state); state->stack[state->depth] = state->pc; state->depth++; break; + case 0xF7: state->remLoopIters[state->depth - 1]--; if (state->remLoopIters[state->depth - 1] != 0) { @@ -779,40 +851,47 @@ void func_800153E8(SequenceChannel* channel) { state->depth--; } break; + case 0xF6: state->depth--; break; + case 0xF5: case 0xF9: case 0xFA: case 0xFB: - sp52 = func_800146D4(state); + sp52 = AudioSeq_ScriptReadS16(state); if (((cmd == 0xFA) && (sp4B != 0)) || ((cmd == 0xF9) && (sp4B >= 0)) || ((cmd == 0xF5) && (sp4B < 0))) { break; } state->pc = &seqPlayer->seqData[sp52]; break; + case 0xF2: case 0xF3: case 0xF4: - temps8 = func_800146C0(state); + temps8 = AudioSeq_ScriptReadU8(state); if (((cmd == 0xF3) && (sp4B != 0)) || ((cmd == 0xF2) && (sp4B >= 0))) { break; } state->pc = &state->pc[temps8]; break; + case 0xF1: - func_80012964(&channel->notePool); - func_80012AC4(&channel->notePool, func_800146C0(state)); + Audio_NotePoolClear(&channel->notePool); + Audio_NotePoolFill(&channel->notePool, AudioSeq_ScriptReadU8(state)); break; + case 0xF0: - func_80012964(&channel->notePool); + Audio_NotePoolClear(&channel->notePool); break; + case 0xC2: - sp52 = func_800146D4(state); + sp52 = AudioSeq_ScriptReadS16(state); channel->dynTable = (u8(*)[2]) & seqPlayer->seqData[sp52]; break; + case 0xC5: if (sp4B != -1) { seqData = channel->dynTable[sp4B]; @@ -820,8 +899,9 @@ void func_800153E8(SequenceChannel* channel) { channel->dynTable = (u8(*)[2]) & seqPlayer->seqData[sp52]; } break; + case 0xEB: - cmd = func_800146C0(state); + cmd = AudioSeq_ScriptReadU8(state); sp52 = ((u16*) gSeqFontTable)[seqPlayer->seqId]; loBits = gSeqFontTable[sp52]; cmd = gSeqFontTable[sp52 + loBits - cmd]; @@ -830,85 +910,104 @@ void func_800153E8(SequenceChannel* channel) { } /* fallthrough */ case 0xC1: - cmd = func_800146C0(state); - func_80015330(channel, cmd); + cmd = AudioSeq_ScriptReadU8(state); + AudioSeq_SetInstrument(channel, cmd); break; + case 0xC3: channel->largeNotes = false; break; + case 0xC4: channel->largeNotes = true; break; + case 0xDF: - cmd = func_800146C0(state); - func_800153C4(channel, cmd); + cmd = AudioSeq_ScriptReadU8(state); + AudioSeq_SequenceChannelSetVolume(channel, cmd); channel->changes.s.volume = 1; break; + case 0xE0: - channel->volumeMod = (s32) func_800146C0(state) / 128.0f; + channel->volumeMod = (s32) AudioSeq_ScriptReadU8(state) / 128.0f; channel->changes.s.volume = 1; break; + case 0xDE: - sp52 = func_800146D4(state); + sp52 = AudioSeq_ScriptReadS16(state); channel->freqMod = (s32) sp52 / 32768.0f; channel->changes.s.freqMod = 1; break; + case 0xD3: - cmd = func_800146C0(state) + 0x80; + cmd = AudioSeq_ScriptReadU8(state) + 0x80; channel->freqMod = gBendPitchOneOctaveFrequencies[cmd]; channel->changes.s.freqMod = 1; break; + case 0xEE: - cmd = func_800146C0(state) + 0x80; + cmd = AudioSeq_ScriptReadU8(state) + 0x80; channel->freqMod = gBendPitchTwoSemitonesFrequencies[cmd]; channel->changes.s.freqMod = 1; break; + case 0xDD: - channel->newPan = func_800146C0(state); + channel->newPan = AudioSeq_ScriptReadU8(state); channel->changes.s.pan = 1; break; + case 0xDC: - channel->panChannelWeight = func_800146C0(state); + channel->panChannelWeight = AudioSeq_ScriptReadU8(state); channel->changes.s.pan = 1; break; + case 0xDB: temps8 = *(state->pc++); channel->transposition = temps8; break; + case 0xDA: - sp52 = func_800146D4(state); + sp52 = AudioSeq_ScriptReadS16(state); channel->adsr.envelope = (EnvelopePoint*) &seqPlayer->seqData[sp52]; break; + case 0xD9: - channel->adsr.decayIndex = func_800146C0(state); + channel->adsr.decayIndex = AudioSeq_ScriptReadU8(state); break; + case 0xD8: - channel->vibratoDepthTarget = func_800146C0(state) * 8; + channel->vibratoDepthTarget = AudioSeq_ScriptReadU8(state) * 8; channel->vibratoDepthStart = 0; channel->vibratoDepthChangeDelay = 0; break; + case 0xD7: - channel->vibratoRateStart = channel->vibratoRateTarget = func_800146C0(state) * 32; + channel->vibratoRateStart = channel->vibratoRateTarget = AudioSeq_ScriptReadU8(state) * 32; channel->vibratoRateChangeDelay = 0; break; + case 0xE2: - channel->vibratoDepthStart = func_800146C0(state) * 8; - channel->vibratoDepthTarget = func_800146C0(state) * 8; - channel->vibratoDepthChangeDelay = func_800146C0(state) * 0x10; + channel->vibratoDepthStart = AudioSeq_ScriptReadU8(state) * 8; + channel->vibratoDepthTarget = AudioSeq_ScriptReadU8(state) * 8; + channel->vibratoDepthChangeDelay = AudioSeq_ScriptReadU8(state) * 0x10; break; + case 0xE1: - channel->vibratoRateStart = func_800146C0(state) * 32; - channel->vibratoRateTarget = func_800146C0(state) * 32; - channel->vibratoRateChangeDelay = func_800146C0(state) * 0x10; + channel->vibratoRateStart = AudioSeq_ScriptReadU8(state) * 32; + channel->vibratoRateTarget = AudioSeq_ScriptReadU8(state) * 32; + channel->vibratoRateChangeDelay = AudioSeq_ScriptReadU8(state) * 0x10; break; + case 0xE3: - channel->vibratoDelay = func_800146C0(state) * 0x10; + channel->vibratoDelay = AudioSeq_ScriptReadU8(state) * 0x10; break; + case 0xD4: - channel->targetReverbVol = func_800146C0(state); + channel->targetReverbVol = AudioSeq_ScriptReadU8(state); break; + case 0xC6: - cmd = func_800146C0(state); + cmd = AudioSeq_ScriptReadU8(state); sp52 = ((u16*) gSeqFontTable)[seqPlayer->seqId]; loBits = gSeqFontTable[sp52]; cmd = gSeqFontTable[sp52 + loBits - cmd]; @@ -916,16 +1015,18 @@ void func_800153E8(SequenceChannel* channel) { channel->fontId = cmd; } break; + case 0xC7: - cmd = func_800146C0(state); - sp52 = func_800146D4(state); + cmd = AudioSeq_ScriptReadU8(state); + sp52 = AudioSeq_ScriptReadS16(state); seqData = &seqPlayer->seqData[sp52]; *seqData = (u8) sp4B + cmd; break; + case 0xC8: case 0xC9: case 0xCC: - temps8 = func_800146C0(state); + temps8 = AudioSeq_ScriptReadU8(state); if (cmd == 0xC8) { sp4B -= temps8; } else if (cmd == 0xCC) { @@ -934,39 +1035,48 @@ void func_800153E8(SequenceChannel* channel) { sp4B &= temps8; } break; + case 0xCD: - func_8001415C(seqPlayer->channels[func_800146C0(state)]); + AudioSeq_SequenceChannelDisable(seqPlayer->channels[AudioSeq_ScriptReadU8(state)]); break; + case 0xCA: - channel->muteBehavior = func_800146C0(state); + channel->muteBehavior = AudioSeq_ScriptReadU8(state); break; + case 0xCB: - sp52 = func_800146D4(state); + sp52 = AudioSeq_ScriptReadS16(state); pad = sp52 + sp4B; - // seqData =&seqPlayer->seqData[sp4B]; sp4B = seqPlayer->seqData[pad]; break; + case 0xCE: - channel->unkC4 = func_800146D4(state); + channel->unkC4 = AudioSeq_ScriptReadS16(state); break; + case 0xCF: - sp52 = func_800146D4(state); + sp52 = AudioSeq_ScriptReadS16(state); seqData = &seqPlayer->seqData[sp52]; seqData[0] = (channel->unkC4 >> 8) & 0xFF; seqData[1] = channel->unkC4 & 0xFF; break; + case 0xD0: - channel->stereoHeadsetEffects = func_800146C0(state); + channel->stereoHeadsetEffects = AudioSeq_ScriptReadU8(state); break; + case 0xD1: - channel->noteAllocPolicy = func_800146C0(state); + channel->noteAllocPolicy = AudioSeq_ScriptReadU8(state); break; + case 0xD2: - channel->adsr.sustain = func_800146C0(state); + channel->adsr.sustain = AudioSeq_ScriptReadU8(state); break; + case 0xE5: - channel->someOtherPriority = func_800146C0(state); + channel->someOtherPriority = AudioSeq_ScriptReadU8(state); break; + case 0xE4: if (sp4B != -1) { if (state->depth >= 4) { @@ -982,11 +1092,13 @@ void func_800153E8(SequenceChannel* channel) { // } } break; + case 0xE6: - channel->bookOffset = func_800146C0(state); + channel->bookOffset = AudioSeq_ScriptReadU8(state); break; + case 0xE7: - sp52 = func_800146D4(state); + sp52 = AudioSeq_ScriptReadS16(state); seqData = &seqPlayer->seqData[sp52]; channel->muteBehavior = *seqData++; channel->noteAllocPolicy = *seqData++; @@ -998,17 +1110,19 @@ void func_800153E8(SequenceChannel* channel) { channel->someOtherPriority = *seqData++; channel->changes.s.pan = 1; break; + case 0xE8: - channel->muteBehavior = func_800146C0(state); - channel->noteAllocPolicy = func_800146C0(state); - channel->notePriority = func_800146C0(state); - channel->transposition = (s8) func_800146C0(state); - channel->newPan = func_800146C0(state); - channel->panChannelWeight = func_800146C0(state); - channel->targetReverbVol = func_800146C0(state); - channel->someOtherPriority = func_800146C0(state); + channel->muteBehavior = AudioSeq_ScriptReadU8(state); + channel->noteAllocPolicy = AudioSeq_ScriptReadU8(state); + channel->notePriority = AudioSeq_ScriptReadU8(state); + channel->transposition = (s8) AudioSeq_ScriptReadU8(state); + channel->newPan = AudioSeq_ScriptReadU8(state); + channel->panChannelWeight = AudioSeq_ScriptReadU8(state); + channel->targetReverbVol = AudioSeq_ScriptReadU8(state); + channel->someOtherPriority = AudioSeq_ScriptReadU8(state); channel->changes.s.pan = 1; break; + case 0xEC: channel->vibratoDepthTarget = 0; channel->vibratoDepthStart = 0; @@ -1018,16 +1132,18 @@ void func_800153E8(SequenceChannel* channel) { channel->vibratoRateChangeDelay = 0; channel->freqMod = 1.0f; break; + case 0xE9: - channel->notePriority = func_800146C0(state); + channel->notePriority = AudioSeq_ScriptReadU8(state); break; + case 0xED: - // cmd = - channel->reverbIndex = func_800146C0(state); + channel->reverbIndex = AudioSeq_ScriptReadU8(state); break; + case 0xEF: - func_800146D4(state); - func_800146C0(state); + AudioSeq_ScriptReadS16(state); + AudioSeq_ScriptReadU8(state); break; } } else { @@ -1040,52 +1156,62 @@ void func_800153E8(SequenceChannel* channel) { sp4B = -1; } break; + case 0x10: channel->seqScriptIO[loBits] = -1; if (AudioLoad_SlowLoadSample(channel->fontId, sp4B, &channel->seqScriptIO[loBits]) == -1) {} break; + case 0x70: channel->seqScriptIO[loBits] = sp4B; break; + case 0x80: sp4B = channel->seqScriptIO[loBits]; if (loBits < 4) { channel->seqScriptIO[loBits] = -1; } break; + case 0x50: sp4B -= channel->seqScriptIO[loBits]; break; + case 0x60: channel->delay = loBits; goto end_loop; + case 0x90: - sp52 = func_800146D4(state); - if (func_80013FC4(channel, loBits) == 0) { - // if(1) {} + sp52 = AudioSeq_ScriptReadS16(state); + if (AudioSeq_SeqChannelSetLayer(channel, loBits) == 0) { channel->layers[loBits]->state.pc = &seqPlayer->seqData[sp52]; } break; + case 0xA0: - func_8001410C(channel, loBits); + AudioSeq_SeqLayerFree(channel, loBits); break; + case 0xB0: - if ((sp4B != -1) && (func_80013FC4(channel, loBits) != -1)) { + if ((sp4B != -1) && (AudioSeq_SeqChannelSetLayer(channel, loBits) != -1)) { seqData = channel->dynTable[sp4B]; sp52 = (seqData[0] << 8) + seqData[1]; channel->layers[loBits]->state.pc = &seqPlayer->seqData[sp52]; } break; + case 0x20: - sp52 = func_800146D4(state); - func_80014440(seqPlayer, loBits, &seqPlayer->seqData[sp52]); + sp52 = AudioSeq_ScriptReadS16(state); + AudioSeq_SequenceChannelEnable(seqPlayer, loBits, &seqPlayer->seqData[sp52]); break; + case 0x30: - cmd = func_800146C0(state); + cmd = AudioSeq_ScriptReadU8(state); seqPlayer->channels[loBits]->seqScriptIO[cmd] = sp4B; break; + case 0x40: - cmd = func_800146C0(state); + cmd = AudioSeq_ScriptReadU8(state); sp4B = seqPlayer->channels[loBits]->seqScriptIO[cmd]; break; } @@ -1093,14 +1219,15 @@ void func_800153E8(SequenceChannel* channel) { } } end_loop:; + for (i = 0; i < ARRAY_COUNT(channel->layers); i++) { if (channel->layers[i] != NULL) { - func_80014748(channel->layers[i]); + AudioSeq_SeqLayerProcessScript(channel->layers[i]); } } } -void func_80015FD4(SequencePlayer* seqPlayer) { +void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) { u8 temp_s2; u8 temp_v0_8; u16 temp_v0_7; @@ -1115,42 +1242,49 @@ void func_80015FD4(SequencePlayer* seqPlayer) { if (!seqPlayer->enabled) { return; } + if (((gSeqLoadStatus[seqPlayer->seqId] < 2) != 0) || ((seqPlayer->defaultFont != 0xFF) && ((gFontLoadStatus[seqPlayer->defaultFont] < 2) != 0))) { - func_800144E4(seqPlayer); + AudioSeq_SequencePlayerDisable(seqPlayer); return; } - if (gSeqLoadStatus[seqPlayer->seqId] != 5) { - gSeqLoadStatus[seqPlayer->seqId] = 2; + + if (gSeqLoadStatus[seqPlayer->seqId] != LOAD_STATUS_PERMANENTLY_LOADED) { + gSeqLoadStatus[seqPlayer->seqId] = LOAD_STATUS_COMPLETE; } - if (gFontLoadStatus[seqPlayer->defaultFont] != 5) { - gFontLoadStatus[seqPlayer->defaultFont] = 2; + + if (gFontLoadStatus[seqPlayer->defaultFont] != LOAD_STATUS_PERMANENTLY_LOADED) { + gFontLoadStatus[seqPlayer->defaultFont] = LOAD_STATUS_COMPLETE; } - if (seqPlayer->muted && (seqPlayer->muteBehavior & 0x80)) { + + if (seqPlayer->muted && (seqPlayer->muteBehavior & MUTE_BEHAVIOR_STOP_SCRIPT)) { return; } + seqPlayer->tempoAcc += seqPlayer->tempo; seqPlayer->tempoAcc = seqPlayer->tempoAcc + (s16) seqPlayer->tempoChange; if (seqPlayer->tempoAcc < gMaxTempo) { return; } + seqPlayer->tempoAcc = (seqPlayer->tempoAcc - gMaxTempo) & 0xFFFF; // fake? + if (seqPlayer->delay > 1) { seqPlayer->delay--; } else { temp_s0 = &seqPlayer->scriptState; seqPlayer->recalculateVolume = true; while (true) { - temp_s2 = func_800146C0(temp_s0); + temp_s2 = AudioSeq_ScriptReadU8(temp_s0); if (temp_s2 == 0xFF) { if (temp_s0->depth == 0) { - func_800144E4(seqPlayer); + AudioSeq_SequencePlayerDisable(seqPlayer); break; } temp_s0->pc = temp_s0->stack[--temp_s0->depth]; } if (temp_s2 == 0xFD) { - seqPlayer->delay = func_80014704(temp_s0); + seqPlayer->delay = AudioSeq_ScriptReadCompressedU16(temp_s0); break; } if (temp_s2 == 0xFE) { @@ -1161,18 +1295,21 @@ void func_80015FD4(SequencePlayer* seqPlayer) { switch (temp_s2) { case 0xFF: break; + case 0xFC: - temp_v0_7 = func_800146D4(temp_s0); + temp_v0_7 = AudioSeq_ScriptReadS16(temp_s0); temp_s0->stack[temp_s0->depth] = temp_s0->pc; temp_s0->depth++; temp_s0->pc = &seqPlayer->seqData[temp_v0_7]; break; + case 0xF8: - temp_s0->remLoopIters[temp_s0->depth] = func_800146C0(temp_s0); + temp_s0->remLoopIters[temp_s0->depth] = AudioSeq_ScriptReadU8(temp_s0); temp_s0->stack[temp_s0->depth] = temp_s0->pc; temp_s0->depth++; break; + case 0xF7: temp_s0->remLoopIters[temp_s0->depth - 1]--; if (temp_s0->remLoopIters[temp_s0->depth - 1] != 0) { @@ -1181,39 +1318,45 @@ void func_80015FD4(SequencePlayer* seqPlayer) { temp_s0->depth--; } break; + case 0xF5: case 0xF9: case 0xFA: case 0xFB: - temp_v0_7 = func_800146D4(temp_s0); + temp_v0_7 = AudioSeq_ScriptReadS16(temp_s0); if (((temp_s2 != 0xFA) || (sp50 == 0)) && ((temp_s2 != 0xF9) || (sp50 < 0)) && ((temp_s2 != 0xF5) || (sp50 >= 0))) { temp_s0->pc = &seqPlayer->seqData[temp_v0_7]; } break; + case 0xF2: case 0xF3: case 0xF4: - pad = func_800146C0(temp_s0); + pad = AudioSeq_ScriptReadU8(temp_s0); if (((temp_s2 != 0xF3) || (sp50 == 0)) && ((temp_s2 != 0xF2) || (sp50 < 0))) { temp_s0->pc = &temp_s0->pc[pad]; } break; + case 0xF1: - func_80012964(&seqPlayer->notePool); - func_80012AC4(&seqPlayer->notePool, func_800146C0(temp_s0)); + Audio_NotePoolClear(&seqPlayer->notePool); + Audio_NotePoolFill(&seqPlayer->notePool, AudioSeq_ScriptReadU8(temp_s0)); break; + case 0xF0: - func_80012964(&seqPlayer->notePool); + Audio_NotePoolClear(&seqPlayer->notePool); break; + case 0xDF: seqPlayer->transposition = 0; /* fallthrough */ case 0xDE: - seqPlayer->transposition += (s8) func_800146C0(temp_s0); + seqPlayer->transposition += (s8) AudioSeq_ScriptReadU8(temp_s0); break; + case 0xDD: - seqPlayer->tempo = func_800146C0(temp_s0) * 0x30; + seqPlayer->tempo = AudioSeq_ScriptReadU8(temp_s0) * 0x30; if (seqPlayer->tempo > gMaxTempo) { seqPlayer->tempo = gMaxTempo; } @@ -1221,12 +1364,14 @@ void func_80015FD4(SequencePlayer* seqPlayer) { seqPlayer->tempo = 1; } break; + case 0xDC: - seqPlayer->tempoChange = (s8) func_800146C0(temp_s0) * 0x30; + seqPlayer->tempoChange = (s8) AudioSeq_ScriptReadU8(temp_s0) * 0x30; break; + case 0xDA: - temp_s2 = func_800146C0(temp_s0); - temp_v0_7 = func_800146D4(temp_s0); + temp_s2 = AudioSeq_ScriptReadU8(temp_s0); + temp_v0_7 = AudioSeq_ScriptReadS16(temp_s0); switch (temp_s2) { case 0: case 1: @@ -1242,11 +1387,13 @@ void func_80015FD4(SequencePlayer* seqPlayer) { break; } break; + case 0xDB: - temp_v0_8 = func_800146C0(temp_s0); + temp_v0_8 = AudioSeq_ScriptReadU8(temp_s0); switch (seqPlayer->state) { case 2: break; + case 1: seqPlayer->state = 0; seqPlayer->fadeVolume = 0.0f; @@ -1262,27 +1409,34 @@ void func_80015FD4(SequencePlayer* seqPlayer) { break; } break; + case 0xD9: - seqPlayer->fadeVolumeMod = (s8) func_800146C0(temp_s0) / 127.0f; + seqPlayer->fadeVolumeMod = (s8) AudioSeq_ScriptReadU8(temp_s0) / 127.0f; break; + case 0xD7: - func_80014244(seqPlayer, func_800146D4(temp_s0)); + AudioSeq_SequencePlayerSetupChannels(seqPlayer, AudioSeq_ScriptReadS16(temp_s0)); break; + case 0xD6: - func_80014370(seqPlayer, func_800146D4(temp_s0)); + AudioSeq_SequencePlayerDisableChannels(seqPlayer, AudioSeq_ScriptReadS16(temp_s0)); break; + case 0xD5: - seqPlayer->muteVolumeMod = (s8) func_800146C0(temp_s0) / 127.0f; + seqPlayer->muteVolumeMod = (s8) AudioSeq_ScriptReadU8(temp_s0) / 127.0f; break; + case 0xD4: seqPlayer->muted = 1; break; + case 0xD3: - seqPlayer->muteBehavior = func_800146C0(temp_s0); + seqPlayer->muteBehavior = AudioSeq_ScriptReadU8(temp_s0); break; + case 0xD1: case 0xD2: - temp_v0_7 = func_800146D4(temp_s0); + temp_v0_7 = AudioSeq_ScriptReadS16(temp_s0); temp_v1_7 = &seqPlayer->seqData[(temp_v0_7)]; if (temp_s2 == 0xD2) { seqPlayer->shortNoteVelocityTable = temp_v1_7; @@ -1290,21 +1444,26 @@ void func_80015FD4(SequencePlayer* seqPlayer) { seqPlayer->shortNoteGateTimeTable = temp_v1_7; } break; + case 0xD0: - seqPlayer->noteAllocPolicy = func_800146C0(temp_s0); + seqPlayer->noteAllocPolicy = AudioSeq_ScriptReadU8(temp_s0); break; + case 0xCC: - sp50 = func_800146C0(temp_s0); + sp50 = AudioSeq_ScriptReadU8(temp_s0); break; + case 0xC9: - sp50 &= func_800146C0(temp_s0); + sp50 &= AudioSeq_ScriptReadU8(temp_s0); break; + case 0xC8: - sp50 -= func_800146C0(temp_s0); + sp50 -= AudioSeq_ScriptReadU8(temp_s0); break; + case 0xC7: - temp_s2 = func_800146C0(temp_s0); - temp_v0_7 = func_800146D4(temp_s0); + temp_s2 = AudioSeq_ScriptReadU8(temp_s0); + temp_v0_7 = AudioSeq_ScriptReadS16(temp_s0); temp_v1_7 = &seqPlayer->seqData[temp_v0_7]; temp_v0_8 = sp50; *temp_v1_7 = temp_v0_8 + temp_s2; @@ -1315,19 +1474,24 @@ void func_80015FD4(SequencePlayer* seqPlayer) { case 0x0: sp50 = seqPlayer->channels[(u8) (temp_s2 & 0xF)]->finished; break; + case 0x50: sp50 -= seqPlayer->unk_07[0]; break; + case 0x70: seqPlayer->unk_07[0] = sp50; break; + case 0x80: sp50 = seqPlayer->unk_07[0]; break; + case 0x90: - temp_v0_7 = func_800146D4(temp_s0); - func_80014440(seqPlayer, temp_s2 & 0xF, &seqPlayer->seqData[temp_v0_7]); + temp_v0_7 = AudioSeq_ScriptReadS16(temp_s0); + AudioSeq_SequenceChannelEnable(seqPlayer, temp_s2 & 0xF, &seqPlayer->seqData[temp_v0_7]); break; + case 0x10: break; case 0x20: @@ -1342,35 +1506,36 @@ void func_80015FD4(SequencePlayer* seqPlayer) { } } } - for (i = 0; i < 0x10; i++) { + + for (i = 0; i < SEQ_NUM_CHANNELS; i++) { if (IS_SEQUENCE_CHANNEL_VALID(seqPlayer->channels[i]) == 1) { - func_800153E8(seqPlayer->channels[i]); + AudioSeq_SequenceChannelProcessScript(seqPlayer->channels[i]); } } } -void func_8001678C(s32 arg0) { +void AudioSeq_ProcessSequences(s32 arg0) { s32 i; for (i = 0; i < ARRAY_COUNT(gSeqPlayers); i++) { - if (gSeqPlayers[i].enabled == 1) { - func_80015FD4(&gSeqPlayers[i]); - func_800135A8(&gSeqPlayers[i]); + if (gSeqPlayers[i].enabled == true) { + AudioSeq_SequencePlayerProcessSequence(&gSeqPlayers[i]); + Audio_SequencePlayerProcessSound(&gSeqPlayers[i]); } } - func_80011FA8(); + Audio_ProcessNotes(); } -void func_80016804(s32 arg0) { +void AudioSeq_ResetSequencePlayer(s32 arg0) { SequencePlayer* seqPlayer = &gSeqPlayers[arg0]; - func_800144E4(seqPlayer); + AudioSeq_SequencePlayerDisable(seqPlayer); seqPlayer->delay = 0; seqPlayer->state = 1; seqPlayer->fadeTimer = 0; seqPlayer->fadeTimerUnkEu = 0; seqPlayer->tempoAcc = 0; - seqPlayer->tempo = 0x1680; + seqPlayer->tempo = 120 * SEQTICKS_PER_BEAT; // 120 BPM seqPlayer->tempoChange = 0; seqPlayer->transposition = 0; seqPlayer->noteAllocPolicy = 0; @@ -1383,7 +1548,7 @@ void func_80016804(s32 arg0) { seqPlayer->muteVolumeMod = 0.5f; } -void func_800168BC(void) { +void AudioSeq_InitSequencePlayers(void) { s32 i; s32 j; @@ -1400,7 +1565,7 @@ void func_800168BC(void) { } } - func_8001463C(); + AudioSeq_InitLayerFreelist(); for (i = 0; i < ARRAY_COUNT(gSeqLayers); i++) { gSeqLayers[i].channel = NULL; @@ -1417,7 +1582,7 @@ void func_800168BC(void) { gSeqPlayers[i].muted = false; gSeqPlayers[i].fontDmaInProgress = false; gSeqPlayers[i].seqDmaInProgress = false; - func_80012864(&gSeqPlayers[i].notePool); - func_80016804(i); + Audio_InitNoteLists(&gSeqPlayers[i].notePool); + AudioSeq_ResetSequencePlayer(i); } } diff --git a/src/audio/audio_synthesis.c b/src/audio/audio_synthesis.c index 609fdfc2..3404b6c2 100644 --- a/src/audio/audio_synthesis.c +++ b/src/audio/audio_synthesis.c @@ -1,6 +1,19 @@ #include "sys.h" #include "sf64audio_provisional.h" +#define DMEM_LEFT_CH 0x990 +#define DMEM_RIGHT_CH 0xB10 +#define DMEM_HAAS_TEMP 0x650 +#define DMEM_TEMP 0x450 +#define DMEM_UNCOMPRESSED_NOTE 0x5F0 +#define SAMPLE_SIZE sizeof(s16) + +typedef enum { + /* 0 */ HAAS_EFFECT_DELAY_NONE, + /* 1 */ HAAS_EFFECT_DELAY_LEFT, // Delay left channel so that right channel is heard first + /* 2 */ HAAS_EFFECT_DELAY_RIGHT // Delay right channel so that left channel is heard first +} HaasEffectDelaySide; + s32 D_80145D40; // unused // all of these are part of the DFT-related function @@ -29,19 +42,19 @@ static const char devstr9[] = "S-Resample Pitch %x (old %d -> delay %d)\n"; void func_80009A2C(s32 updateIndex, s32 noteIndex); void func_80009AAC(s32 updateIndex); -Acmd* func_8000A700(s32 noteIndex, NoteSubEu* noteSub, NoteSynthesisState* synthState, s16* aiBuf, s32 aiBufLen, - Acmd* aList, s32 updateIndex); +Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSub, NoteSynthesisState* synthState, s16* aiBuf, + s32 aiBufLen, Acmd* aList, s32 updateIndex); Acmd* func_8000A25C(s16* aiBuf, s32 aiBufLen, Acmd* aList, s32 updateIndex); Acmd* func_800098DC(Acmd* aList, u16 dmem, u16 startPos, s32 size, s32 reverbIndex); Acmd* func_80009984(Acmd* aList, u16 dmem, u16 startPos, s32 size, s32 reverbIndex); Acmd* func_80009D78(Acmd* aList, s32 aiBufLen, s16 reverbIndex, s16 updateIndex); Acmd* func_8000A128(Acmd* aList, s16 reverbIndex, s16 updateIndex); -Acmd* func_8000B3F0(Acmd* aList, NoteSubEu* noteSub, NoteSynthesisState* synthState, s32 numSamplesToLoad); +Acmd* AudioSynth_LoadWaveSamples(Acmd* aList, NoteSubEu* noteSub, NoteSynthesisState* synthState, s32 numSamplesToLoad); Acmd* func_8000B480(Acmd* aList, NoteSynthesisState* synthState, s32 size, u16 pitch, u16 inpDmem, u32 resampleFlags); Acmd* func_8000B51C(Acmd* aList, NoteSubEu* noteSub, NoteSynthesisState* synthState, s32 aiBufLen, u16 dmemSrc, s32 delaySide, s32 flags); -Acmd* func_8000B98C(Acmd* aList, NoteSubEu* noteSub, NoteSynthesisState* synthState, s32 size, s32 flags, - s32 delaySide); +Acmd* AudioSynth_ApplyHaasEffect(Acmd* aList, NoteSubEu* noteSub, NoteSynthesisState* synthState, s32 size, s32 flags, + s32 delaySide); void func_800080C0(s32 sampleCount, s32 itemIndex, s32 reverbIndex) { ReverbRingBufferItem* ringItem; @@ -631,7 +644,7 @@ void func_80009AAC(s32 updateIndex) { } } -Acmd* func_80009B64(Acmd* aList, s32* cmdCount, s16* aiBufStart, s32 aiBufLen) { +Acmd* AudioSynth_Update(Acmd* aList, s32* cmdCount, s16* aiBufStart, s32 aiBufLen) { Acmd* aCmdPtr; s32* aiBufPtr; s32 chunkLen; @@ -640,7 +653,7 @@ Acmd* func_80009B64(Acmd* aList, s32* cmdCount, s16* aiBufStart, s32 aiBufLen) { aCmdPtr = aList; for (i = gAudioBufferParams.ticksPerUpdate; i > 0; i--) { - func_8001678C(i - 1); + AudioSeq_ProcessSequences(i - 1); func_80009AAC(gAudioBufferParams.ticksPerUpdate - i); } @@ -787,8 +800,8 @@ Acmd* func_8000A25C(s16* aiBuf, s32 aiBufLen, Acmd* aList, s32 updateIndex) { if (i != gNoteSubsEu[updateIndex * gNumNotes + sp84[j]].bitField1.reverbIndex) { break; } - aList = func_8000A700(sp84[j], &gNoteSubsEu[updateIndex * gNumNotes + sp84[j]], - &gNotes[sp84[j]].synthesisState, aiBuf, aiBufLen, aList, updateIndex); + aList = AudioSynth_ProcessNote(sp84[j], &gNoteSubsEu[updateIndex * gNumNotes + sp84[j]], + &gNotes[sp84[j]].synthesisState, aiBuf, aiBufLen, aList, updateIndex); j++; } if (gSynthReverbs[i].useReverb) { @@ -797,8 +810,8 @@ Acmd* func_8000A25C(s16* aiBuf, s32 aiBufLen, Acmd* aList, s32 updateIndex) { } while (j < var_s2) { - aList = func_8000A700(sp84[j], &gNoteSubsEu[updateIndex * gNumNotes + sp84[j]], &gNotes[sp84[j]].synthesisState, - aiBuf, aiBufLen, aList, updateIndex); + aList = AudioSynth_ProcessNote(sp84[j], &gNoteSubsEu[updateIndex * gNumNotes + sp84[j]], + &gNotes[sp84[j]].synthesisState, aiBuf, aiBufLen, aList, updateIndex); j++; } @@ -810,81 +823,83 @@ Acmd* func_8000A25C(s16* aiBuf, s32 aiBufLen, Acmd* aList, s32 updateIndex) { return aList; } -// https://decomp.me/scratch/RgX4r -#ifdef NON_MATCHING -Acmd* func_8000A700(s32 noteIndex, NoteSubEu* noteSub, NoteSynthesisState* synthState, s16* aiBuf, s32 aiBufLen, - Acmd* aList, s32 updateIndex) { +Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSub, NoteSynthesisState* synthState, s16* aiBuf, + s32 aiBufLen, Acmd* aList, s32 updateIndex) { s32 pad11C; s32 pad118; s32 pad114; - Sample* bookSample; // sp110 - AdpcmLoop* loopInfo; // sp10C - void* currentBook; // sp108 + Sample* bookSample; + AdpcmLoop* loopInfo; + void* currentBook; s32 pad104; s32 pad100; - s32 noteFinished; // spFC - u32 restart; // spF8 - s32 flags; // spF4 - u16 resampleRateFixedPoint; // spF2 - s32 nSamplesToLoad; // spEC + s32 sampleFinished; + u32 loopToPoint; + s32 flags; + u16 resampleRateFixedPoint; + s32 numSamplesToLoad; s32 padE8; s32 padE4; s32 padE0; - s32 skipBytes; // spDC + s32 skipBytes; s32 padD8; s32 padD4; s32 padD0; - u32 sampleAddr; // spCC + u32 sampleAddr; s32 padC8; - s32 samplesLenAdjusted; // spC4 - s32 nAdpcmSamplesProcessed; // spC0 - u32 endPos; // spBC - s32 nSamplesToProcess; // spB8 + s32 numSamplesToLoadAdj; + s32 numSamplesProcessed; + u32 endPos; + s32 nSamplesToProcess; s32 padB4; s32 padB0; s32 padAC; - s32 padA8; s32 padA4; - s32 nTrailingSamplesToIgnore; // spA0 + s32 padA8; + s32 numTrailingSamplesToIgnore; s32 pad9C; s32 pad98; s32 pad94; - s32 frameSize; // sp90 + s32 frameSize; s32 pad8C; - s32 skipInitialSamples; // sp88 - s32 sampleDmaStart; // sp84 + s32 skipInitialSamples; + s32 sampleDmaStart; s32 pad80; - s32 nParts; // sp7C - s32 curPart; // sp78 - s32 nSamplesInThisIteration; - s32 sampleDataStartPad; - s32 resampledTempLen; // sp6C - u16 noteSamplesDmemAddrBeforeResampling; // sp6A - s32 samplesRemaining; + s32 numParts; + s32 curPart; + s32 numSamplesInThisIteration; + s32 sampleDataChunkAlignPad; + s32 resampledTempLen; + u16 noteSamplesDmemAddrBeforeResampling; + s32 pasdasd; s32 frameIndex; s32 sampleDataOffset; - Note* note; // sp58 - u16 sp56; // sp56 - - s32 nSamplesInFirstFrame; + Note* note; + u16 sp56; + s32 numSamplesInFirstFrame; s32 delaySide; - s32 nSamplesToDecode; + s32 padasdsa; s32 nFramesToDecode; s32 nFirstFrameSamplesToIgnore; - s32 s5; + s32 dmemUncompressedAddrOffset1; u32 sampleslenFixedPoint; - u8* sampleData; + u8* samplesToLoadAddr; s32 temp; s32 temp2; + unsigned int new_var2; u32 nEntries; s32 aligned; s32 align2; - u16 addr; + s16 addr; + u8* new_var; + s32 samplesRemaining; + s32 numSamplesToDecode; currentBook = NULL; note = &gNotes[noteIndex]; flags = 0; - if (noteSub->bitField0.needsInit == 1) { + + if (new_var2 = noteSub->bitField0.needsInit == 1) { // FAKE flags = 1; synthState->restart = 0; synthState->samplePosInt = 0; @@ -896,221 +911,253 @@ Acmd* func_8000A700(s32 noteIndex, NoteSubEu* noteSub, NoteSynthesisState* synth synthState->numParts = 0; note->noteSubEu.bitField0.finished = 0; } + resampleRateFixedPoint = noteSub->resampleRate; - nParts = noteSub->bitField1.hasTwoParts + 1; - sampleslenFixedPoint = (resampleRateFixedPoint * aiBufLen * 2) + synthState->samplePosFrac; - nSamplesToLoad = (sampleslenFixedPoint) >> 0x10; + numParts = noteSub->bitField1.hasTwoParts + 1; + sampleslenFixedPoint = ((resampleRateFixedPoint * aiBufLen) * 2) + synthState->samplePosFrac; + numSamplesToLoad = sampleslenFixedPoint >> 0x10; synthState->samplePosFrac = sampleslenFixedPoint & 0xFFFF; - if ((synthState->numParts == 1) && (nParts == 2)) { - nSamplesToLoad += 2; + + if ((synthState->numParts == 1) && (numParts == 2)) { + numSamplesToLoad += 2; sp56 = 2; - } else if ((synthState->numParts == 2) && (nParts == 1)) { - nSamplesToLoad -= 4; + } else if ((synthState->numParts == 2) && (numParts == 1)) { + numSamplesToLoad -= 4; sp56 = 4; } else { sp56 = 0; } - synthState->numParts = nParts; + + synthState->numParts = numParts; + if (noteSub->bitField1.isSyntheticWave) { - aList = func_8000B3F0(aList, noteSub, synthState, nSamplesToLoad); - noteSamplesDmemAddrBeforeResampling = (synthState->samplePosInt * 2) + 0x5F0; - synthState->samplePosInt += nSamplesToLoad; + aList = AudioSynth_LoadWaveSamples(aList, noteSub, synthState, numSamplesToLoad); + noteSamplesDmemAddrBeforeResampling = (synthState->samplePosInt * ((char) 2)) + 0x5F0; + synthState->samplePosInt += numSamplesToLoad; } else { - bookSample = *(Sample**) noteSub->waveSampleAddr; + bookSample = *((Sample**) noteSub->waveSampleAddr); loopInfo = bookSample->loop; + endPos = loopInfo->end; sampleAddr = bookSample->sampleAddr; resampledTempLen = 0; - for (curPart = 0; curPart < nParts; curPart++) { - nAdpcmSamplesProcessed = 0; - s5 = 0; - if (nParts == 1) { - samplesLenAdjusted = nSamplesToLoad; - } else if (nSamplesToLoad & 1) { - samplesLenAdjusted = (nSamplesToLoad & ~1) + (curPart * 2); + for (curPart = 0; curPart < numParts; curPart++) { + numSamplesProcessed = 0; + dmemUncompressedAddrOffset1 = 0; + if (numParts == 1) { + numSamplesToLoadAdj = numSamplesToLoad; + } else if (numSamplesToLoad & 1) { + numSamplesToLoadAdj = (numSamplesToLoad & (~1)) + (curPart * 2); } else { - samplesLenAdjusted = nSamplesToLoad; + numSamplesToLoadAdj = numSamplesToLoad; } + if ((bookSample->codec == 0) && (currentBook != bookSample->book->book)) { switch (noteSub->bitField1.bookOffset) { case 1: currentBook = &gD_800DD200[1]; break; + case 2: currentBook = &gD_800DD200[2]; break; + default: + case 3: currentBook = bookSample->book->book; break; } - nEntries = 16 * bookSample->book->order * bookSample->book->numPredictors; + nEntries = (16 * bookSample->book->order) * bookSample->book->numPredictors; aLoadADPCM(aList++, nEntries, OS_K0_TO_PHYSICAL(currentBook)); } - while (nAdpcmSamplesProcessed != samplesLenAdjusted) { - restart = 0; - noteFinished = 0; - samplesRemaining = endPos - synthState->samplePosInt; - nSamplesToProcess = samplesLenAdjusted - nAdpcmSamplesProcessed; + while (numSamplesProcessed != numSamplesToLoadAdj) { + sampleFinished = 0; + loopToPoint = 0; + samplesRemaining = endPos - synthState->samplePosInt; + nSamplesToProcess = numSamplesToLoadAdj - numSamplesProcessed; nFirstFrameSamplesToIgnore = synthState->samplePosInt & 0xF; - - if ((nFirstFrameSamplesToIgnore == 0) && !synthState->restart) { + if ((nFirstFrameSamplesToIgnore == 0) && (!synthState->restart)) { nFirstFrameSamplesToIgnore = 0x10; } - - nSamplesInFirstFrame = 0x10 - nFirstFrameSamplesToIgnore; + numSamplesInFirstFrame = 0x10 - nFirstFrameSamplesToIgnore; if (nSamplesToProcess < samplesRemaining) { - nFramesToDecode = (nSamplesToProcess - nSamplesInFirstFrame + 0xF) / 16; - nSamplesToDecode = nFramesToDecode * 0x10; - // if(1) {} - nTrailingSamplesToIgnore = (nSamplesInFirstFrame + nSamplesToDecode) - nSamplesToProcess; + nFramesToDecode = ((nSamplesToProcess - numSamplesInFirstFrame) + 0xF) / 16; + numSamplesToDecode = nFramesToDecode * 0x10; + numTrailingSamplesToIgnore = (numSamplesInFirstFrame + numSamplesToDecode) - nSamplesToProcess; } else { - nSamplesToDecode = samplesRemaining - nSamplesInFirstFrame; - nTrailingSamplesToIgnore = 0; - if (nSamplesToDecode <= 0) { - nSamplesToDecode = 0; - nSamplesInFirstFrame = samplesRemaining; + numSamplesToDecode = samplesRemaining - numSamplesInFirstFrame; + numTrailingSamplesToIgnore = 0; + if (numSamplesToDecode <= 0) { + numSamplesToDecode = 0; + numSamplesInFirstFrame = samplesRemaining; } - nFramesToDecode = (nSamplesToDecode + 0xF) / 16; + nFramesToDecode = (numSamplesToDecode + 0xF) / 16; if (loopInfo->count != 0) { - restart = 1; + loopToPoint = 1; } else { - noteFinished = 1; + sampleFinished = 1; } } + switch (bookSample->codec) { case 0: frameSize = 9; skipInitialSamples = 0x10; sampleDmaStart = 0; break; + case 1: frameSize = 0x10; skipInitialSamples = 0x10; sampleDmaStart = 0; break; + case 2: - temp = - func_800097A8(bookSample, samplesLenAdjusted, flags, &synthState->synthesisBuffers->unk_40); - aLoadBuffer(aList++, OS_K0_TO_PHYSICAL(temp), 0x5F0, (samplesLenAdjusted + 0x10) * 2); - s5 = samplesLenAdjusted; - nAdpcmSamplesProcessed = samplesLenAdjusted; + temp = func_800097A8(bookSample, numSamplesToLoadAdj, flags, + &synthState->synthesisBuffers->unk_40); + if (0) {} + aLoadBuffer(aList++, OS_K0_TO_PHYSICAL(temp), 0x5F0, (numSamplesToLoadAdj + 0x10) * 2); + flags = 0; skipBytes = 0; + numSamplesProcessed = numSamplesToLoadAdj; + dmemUncompressedAddrOffset1 = numSamplesToLoadAdj; goto skip; } - aligned = ALIGN16(nFramesToDecode * frameSize + 0x10); + + aligned = ALIGN16((nFramesToDecode * frameSize) + 0x10); addr = 0x990 - aligned; + if (nFramesToDecode != 0) { + if (1) {} frameIndex = (synthState->samplePosInt + skipInitialSamples - nFirstFrameSamplesToIgnore) / 16; sampleDataOffset = frameIndex * frameSize; if (bookSample->medium == 0) { - sampleData = sampleDmaStart + sampleDataOffset + sampleAddr; + samplesToLoadAddr = (u8*) (sampleDmaStart + sampleDataOffset + sampleAddr); } else { - sampleData = AudioLoad_DmaSampleData(sampleDmaStart + sampleDataOffset + sampleAddr, aligned, - flags, &synthState->sampleDmaIndex, bookSample->medium); + samplesToLoadAddr = + AudioLoad_DmaSampleData(sampleDmaStart + sampleDataOffset + sampleAddr, aligned, flags, + &synthState->sampleDmaIndex, bookSample->medium); } - // if (1){} - sampleDataStartPad = (u32) sampleData & 0xF; - aLoadBuffer(aList++, OS_K0_TO_PHYSICAL(sampleData - sampleDataStartPad), addr, aligned); + sampleDataChunkAlignPad = ((u32) samplesToLoadAddr) % 16; + + aLoadBuffer(aList++, OS_K0_TO_PHYSICAL(samplesToLoadAddr - sampleDataChunkAlignPad), addr, aligned); } else { - nSamplesToDecode = 0; - sampleDataStartPad = 0; + numSamplesToDecode = 0; + sampleDataChunkAlignPad = 0; } + if (synthState->restart) { aSetLoop(aList++, OS_K0_TO_PHYSICAL(bookSample->loop->predictorState)); flags = 2; synthState->restart = 0; } - nSamplesInThisIteration = nSamplesToDecode + nSamplesInFirstFrame - nTrailingSamplesToIgnore; - if (nAdpcmSamplesProcessed == 0) { + numSamplesInThisIteration = (numSamplesToDecode + numSamplesInFirstFrame) - numTrailingSamplesToIgnore; + + if (numSamplesProcessed == 0) { + switch (bookSample->codec) { case 0: - aSetBuffer(aList++, 0, addr + sampleDataStartPad, 0x5F0, nSamplesToDecode * 2); + + aSetBuffer(aList++, 0, addr + sampleDataChunkAlignPad, 0x5F0, numSamplesToDecode * 2); + aADPCMdec(aList++, flags, OS_K0_TO_PHYSICAL(synthState->synthesisBuffers)); break; + case 1: - aSetBuffer(aList++, 0, addr + sampleDataStartPad, 0x5F0, nSamplesToDecode * 2); + aSetBuffer(aList++, 0, addr + sampleDataChunkAlignPad, 0x5F0, numSamplesToDecode * 2); aS8Dec(aList++, flags, OS_K0_TO_PHYSICAL(synthState->synthesisBuffers)); break; } skipBytes = nFirstFrameSamplesToIgnore * 2; } else { - // if (1) {} - align2 = ALIGN16(s5 + 0x10); + align2 = ALIGN16(dmemUncompressedAddrOffset1 + 0x10); switch (bookSample->codec) { case 0: - aSetBuffer(aList++, 0, addr + sampleDataStartPad, align2 + 0x5F0, nSamplesToDecode * 2); + aSetBuffer(aList++, 0, addr + sampleDataChunkAlignPad, align2 + 0x5F0, + numSamplesToDecode * 2); aADPCMdec(aList++, flags, OS_K0_TO_PHYSICAL(synthState->synthesisBuffers)); break; + case 1: - aSetBuffer(aList++, 0, addr + sampleDataStartPad, align2 + 0x5F0, nSamplesToDecode * 2); + aSetBuffer(aList++, 0, addr + sampleDataChunkAlignPad, align2 + 0x5F0, + numSamplesToDecode * 2); aS8Dec(aList++, flags, OS_K0_TO_PHYSICAL(synthState->synthesisBuffers)); break; } - aDMEMMove(aList++, (align2 + (nFirstFrameSamplesToIgnore * 2) + 0x5F0), s5 + 0x5F0, - nSamplesInThisIteration * 2); + + aDMEMMove(aList++, 0x5F0 + align2 + (nFirstFrameSamplesToIgnore * 2), + 0x5F0 + dmemUncompressedAddrOffset1, numSamplesInThisIteration * 2); } - nAdpcmSamplesProcessed += nSamplesInThisIteration; + + numSamplesProcessed += numSamplesInThisIteration; + switch (flags) { case 1: skipBytes = 0x20; - s5 = (nSamplesToDecode + 0x10) * 2; + dmemUncompressedAddrOffset1 = (numSamplesToDecode + 0x10) * 2; break; + case 2: - // if(1) {} - s5 = nSamplesInThisIteration * 2 + s5; + dmemUncompressedAddrOffset1 = (numSamplesInThisIteration * 2) + dmemUncompressedAddrOffset1; break; + default: - if (s5 != 0) { - s5 = nSamplesInThisIteration * 2 + s5; + if (dmemUncompressedAddrOffset1 != 0) { + dmemUncompressedAddrOffset1 = (numSamplesInThisIteration * 2) + dmemUncompressedAddrOffset1; } else { - // if (1) { } - s5 = (nFirstFrameSamplesToIgnore + nSamplesInThisIteration) * 2; + dmemUncompressedAddrOffset1 = (nFirstFrameSamplesToIgnore + numSamplesInThisIteration) * 2; } break; } + skip: flags = 0; - // goto dummy_label_147574; dummy_label_147574: ; - if (noteFinished) { - aClearBuffer(aList++, s5 + 0x5F0, (samplesLenAdjusted - nAdpcmSamplesProcessed) * 2); + + if (sampleFinished) { + aClearBuffer(aList++, dmemUncompressedAddrOffset1 + 0x5F0, + (numSamplesToLoadAdj - numSamplesProcessed) * 2); noteSub->bitField0.finished = 1; note->noteSubEu.bitField0.finished = 1; func_80009A2C(updateIndex, noteIndex); break; } - if (restart) { + if (loopToPoint != 0) { synthState->restart = 1; synthState->samplePosInt = loopInfo->start; } else { synthState->samplePosInt += nSamplesToProcess; } } - switch (nParts) { + + switch (numParts) { case 1: noteSamplesDmemAddrBeforeResampling = skipBytes + 0x5F0; break; + case 2: switch (curPart) { case 0: - aInterl(aList++, skipBytes + 0x5F0, 0x470, ALIGN8(samplesLenAdjusted / 2)); - resampledTempLen = samplesLenAdjusted; + aInterl(aList++, skipBytes + 0x5F0, 0x470, ALIGN8(numSamplesToLoadAdj / 2)); + resampledTempLen = numSamplesToLoadAdj; noteSamplesDmemAddrBeforeResampling = 0x470; if (noteSub->bitField0.finished) { aClearBuffer(aList++, resampledTempLen + noteSamplesDmemAddrBeforeResampling, - samplesLenAdjusted + 0x10); + numSamplesToLoadAdj + 0x10); } break; + case 1: aInterl(aList++, skipBytes + 0x5F0, resampledTempLen + 0x470, - ALIGN8(samplesLenAdjusted / 2)); + ALIGN8(numSamplesToLoadAdj / 2)); break; } + break; } @@ -1125,12 +1172,15 @@ Acmd* func_8000A700(s32 noteIndex, NoteSubEu* noteSub, NoteSynthesisState* synth flags = 1; noteSub->bitField0.needsInit = 0; } + flags = sp56 | flags; aList = func_8000B480(aList, synthState, aiBufLen * 2, resampleRateFixedPoint, noteSamplesDmemAddrBeforeResampling, flags); + if (flags & 1) { flags = 1; } + if (noteSub->bitField1.bookOffset == 3) { aUnkCmd19(aList++, 0, aiBufLen * 2, 0x450, 0x450); } @@ -1142,6 +1192,7 @@ Acmd* func_8000A700(s32 noteIndex, NoteSubEu* noteSub, NoteSynthesisState* synth } aHiLoGain(aList++, temp2, (aiBufLen + 0x10) * 2, 0x450, 0); } + if ((noteSub->leftDelaySize != 0) || (synthState->prevHaasEffectLeftDelaySize != 0)) { delaySide = 1; } else if ((noteSub->rightDelaySize != 0) || (synthState->prevHaasEffectRightDelaySize != 0)) { @@ -1151,29 +1202,37 @@ Acmd* func_8000A700(s32 noteIndex, NoteSubEu* noteSub, NoteSynthesisState* synth } aList = func_8000B51C(aList, noteSub, synthState, aiBufLen, 0x450, delaySide, flags); - // if(restart) {} if (noteSub->bitField0.usesHeadsetPanEffects) { if (!(flags & 1)) { flags = 0; } - aList = func_8000B98C(aList, noteSub, synthState, aiBufLen * 2, flags, delaySide); + aList = AudioSynth_ApplyHaasEffect(aList, noteSub, synthState, aiBufLen * 2, flags, delaySide); } return aList; } -#else -#pragma GLOBAL_ASM("asm/us/rev1/nonmatchings/audio/audio_synthesis/func_8000A700.s") -#endif -Acmd* func_8000B3F0(Acmd* aList, NoteSubEu* noteSub, NoteSynthesisState* synthState, s32 numSamplesToLoad) { - s32 temp_v1; - - aLoadBuffer(aList++, OS_K0_TO_PHYSICAL(noteSub->waveSampleAddr), 0x5F0, 0x80); - synthState->samplePosInt &= 0x3F; - temp_v1 = 0x40 - synthState->samplePosInt; - if (temp_v1 < numSamplesToLoad) { - if ((((numSamplesToLoad - temp_v1) + 0x3F) / 64) != 0) { - aDuplicate(aList++, ((numSamplesToLoad - temp_v1) + 0x3F) / 64, 0x5F0, 0x670); +Acmd* AudioSynth_LoadWaveSamples(Acmd* aList, NoteSubEu* noteSub, NoteSynthesisState* synthState, + s32 numSamplesToLoad) { + s32 numSamplesAvail; + s32 numDuplicates; + + aLoadBuffer(aList++, OS_K0_TO_PHYSICAL(noteSub->waveSampleAddr), DMEM_UNCOMPRESSED_NOTE, + WAVE_SAMPLE_COUNT * SAMPLE_SIZE); + + // Offset in the WAVE_SAMPLE_COUNT samples of gWaveSamples to start processing the wave for continuity + synthState->samplePosInt = (u32) synthState->samplePosInt % WAVE_SAMPLE_COUNT; + // Number of samples in the initial WAVE_SAMPLE_COUNT samples available to be used to process + numSamplesAvail = WAVE_SAMPLE_COUNT - synthState->samplePosInt; + + if (numSamplesToLoad > numSamplesAvail) { + // Duplicate (copy) the WAVE_SAMPLE_COUNT samples as many times as needed to reach numSamplesToLoad. + // (numSamplesToLoad - numSamplesAvail) is the number of samples missing. + // Divide by WAVE_SAMPLE_COUNT, rounding up, to get the amount of duplicates + numDuplicates = ((numSamplesToLoad - numSamplesAvail + WAVE_SAMPLE_COUNT - 1) / WAVE_SAMPLE_COUNT); + if (numDuplicates != 0) { + aDuplicate(aList++, numDuplicates, DMEM_UNCOMPRESSED_NOTE, + DMEM_UNCOMPRESSED_NOTE + (WAVE_SAMPLE_COUNT * SAMPLE_SIZE)); } } return aList; @@ -1263,60 +1322,67 @@ Acmd* func_8000B51C(Acmd* aList, NoteSubEu* noteSub, NoteSynthesisState* synthSt return aList; } -Acmd* func_8000B98C(Acmd* aList, NoteSubEu* noteSub, NoteSynthesisState* synthState, s32 size, s32 flags, - s32 delaySide) { - u16 var_t0; - u8 var_a1; - u8 var_v1; - u16 temp; +/** + * The Haas Effect gives directionality to sound by applying a small (< 35ms) delay to either the left or right channel. + * The delay is small enough that the sound is still perceived as one sound, but the channel that is not delayed will + * reach our ear first and give a sense of directionality. The sound is directed towards the opposite side of the delay. + */ +Acmd* AudioSynth_ApplyHaasEffect(Acmd* aList, NoteSubEu* noteSub, NoteSynthesisState* synthState, s32 size, s32 flags, + s32 delaySide) { + u16 dmemDest; + u8 haasEffectDelaySize; + u8 prevHaasEffectDelaySize; + u16 pitch; switch (delaySide) { - case 1: - var_t0 = 0x990; - var_a1 = noteSub->leftDelaySize; + case HAAS_EFFECT_DELAY_LEFT: + dmemDest = DMEM_LEFT_CH; + haasEffectDelaySize = noteSub->leftDelaySize; + prevHaasEffectDelaySize = synthState->prevHaasEffectLeftDelaySize; synthState->prevHaasEffectRightDelaySize = 0; - var_v1 = synthState->prevHaasEffectLeftDelaySize; - synthState->prevHaasEffectLeftDelaySize = var_a1; + synthState->prevHaasEffectLeftDelaySize = haasEffectDelaySize; break; - case 2: - var_t0 = 0xB10; - var_a1 = noteSub->rightDelaySize; + case HAAS_EFFECT_DELAY_RIGHT: + dmemDest = DMEM_RIGHT_CH; + haasEffectDelaySize = noteSub->rightDelaySize; + prevHaasEffectDelaySize = synthState->prevHaasEffectRightDelaySize; + synthState->prevHaasEffectRightDelaySize = haasEffectDelaySize; synthState->prevHaasEffectLeftDelaySize = 0; - var_v1 = synthState->prevHaasEffectRightDelaySize; - synthState->prevHaasEffectRightDelaySize = var_a1; break; - default: + default: // HAAS_EFFECT_DELAY_NONE return aList; } - if (flags != 1) { - if (var_a1 != var_v1) { - temp = (((size << 0xF) / 2) - 1) / ((size + var_a1 - var_v1 - 2) / 2); - aSetBuffer(aList++, 0, 0x650, 0x450, size + var_a1 - var_v1); - aResampleZoh(aList++, temp, 0); + if (flags != A_INIT) { + if (haasEffectDelaySize != prevHaasEffectDelaySize) { + pitch = (((size << 0xF) / 2) - 1) / ((size + haasEffectDelaySize - prevHaasEffectDelaySize - 2) / 2); + aSetBuffer(aList++, 0, DMEM_HAAS_TEMP, DMEM_TEMP, size + haasEffectDelaySize - prevHaasEffectDelaySize); + aResampleZoh(aList++, pitch, 0); } else { - aDMEMMove(aList++, 0x650, 0x450, size); + aDMEMMove(aList++, DMEM_HAAS_TEMP, DMEM_TEMP, size); } - if (var_v1 != 0) { + if (prevHaasEffectDelaySize != 0) { aLoadBuffer(aList++, OS_K0_TO_PHYSICAL(synthState->synthesisBuffers->panSamplesBuffer), 0x650, - ALIGN16(var_v1)); - aDMEMMove(aList++, 0x450, var_v1 + 0x650, size + var_a1 - var_v1); + ALIGN16(prevHaasEffectDelaySize)); + aDMEMMove(aList++, DMEM_TEMP, prevHaasEffectDelaySize + DMEM_HAAS_TEMP, + size + haasEffectDelaySize - prevHaasEffectDelaySize); } else { - aDMEMMove(aList++, 0x450, 0x650, size + var_a1); + aDMEMMove(aList++, DMEM_TEMP, DMEM_HAAS_TEMP, size + haasEffectDelaySize); } } else { - aDMEMMove(aList++, 0x650, 0x450, size); - aClearBuffer(aList++, 0x650, var_a1); - aDMEMMove(aList++, 0x450, var_a1 + 0x650, size); + aDMEMMove(aList++, DMEM_HAAS_TEMP, DMEM_TEMP, size); + aClearBuffer(aList++, DMEM_HAAS_TEMP, haasEffectDelaySize); + aDMEMMove(aList++, DMEM_TEMP, haasEffectDelaySize + DMEM_HAAS_TEMP, size); } - if (var_a1) { - aSaveBuffer(aList++, size + 0x650, OS_K0_TO_PHYSICAL(synthState->synthesisBuffers->panSamplesBuffer), - ALIGN16(var_a1)); + + if (haasEffectDelaySize) { + aSaveBuffer(aList++, size + DMEM_HAAS_TEMP, OS_K0_TO_PHYSICAL(synthState->synthesisBuffers->panSamplesBuffer), + ALIGN16(haasEffectDelaySize)); } - aAddMixer(aList++, ALIGN64(size), 0x650, var_t0, 0x7FFF); + aAddMixer(aList++, ALIGN64(size), DMEM_HAAS_TEMP, dmemDest, 0x7FFF); return aList; } diff --git a/src/audio/audio_tables.c b/src/audio/audio_tables.c index 2bfea4c3..6247628d 100644 --- a/src/audio/audio_tables.c +++ b/src/audio/audio_tables.c @@ -112,7 +112,7 @@ u8 gSeqFontTableInit[283] = { AS_BYTES(277), AS_BYTES(279), AS_BYTES(281), // sound font for SFX sequence - 1, 0, + 1, 0, // sound fonts voice sequence 20, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 1, 2, // sound fonts for BGM sequences. Each sequence has a single sound font. diff --git a/src/audio/audio_thread.c b/src/audio/audio_thread.c index 14e07fd2..ea9ec343 100644 --- a/src/audio/audio_thread.c +++ b/src/audio/audio_thread.c @@ -114,7 +114,7 @@ SPTask* AudioThread_CreateTask(void) { while (MQ_GET_MESG(gThreadCmdProcQueue, &msg)) { AudioThread_ProcessCmds(msg); } - gCurAbiCmdBuffer = func_80009B64(gCurAbiCmdBuffer, &abiCmdCount, aiBuffer, gAiBuffLengths[aiBuffIndex]); + gCurAbiCmdBuffer = AudioSynth_Update(gCurAbiCmdBuffer, &abiCmdCount, aiBuffer, gAiBuffLengths[aiBuffIndex]); gAudioRandom = osGetCount() * (gAudioRandom + gAudioTaskCountQ); gAudioRandom = gAiBuffers[aiBuffIndex][gAudioTaskCountQ & 0xFF] + gAudioRandom; @@ -174,7 +174,7 @@ void AudioThread_ProcessGlobalCmd(AudioCmd* cmd) { case AUDIOCMD_OP_GLOBAL_DISABLE_SEQPLAYER: if (gSeqPlayers[cmd->arg0].enabled) { if (cmd->asInt == 0) { - func_800144E4(&gSeqPlayers[cmd->arg0]); + AudioSeq_SequencePlayerDisable(&gSeqPlayers[cmd->arg0]); } else { AudioThread_SetFadeOutTimer(cmd->arg0, cmd->asInt); } diff --git a/src/engine/fox_beam.c b/src/engine/fox_beam.c index 13d743aa..ddb3b0b8 100644 --- a/src/engine/fox_beam.c +++ b/src/engine/fox_beam.c @@ -1872,7 +1872,7 @@ void PlayerShot_ApplyExplosionDamage(PlayerShot* shot, s32 damage) { Player* player; f32 radius = shot->scale * 60.0f; - scenery = gScenery; + scenery = &gScenery[0]; for (i = 0; i < ARRAY_COUNT(gScenery); i++, scenery++) { if ((scenery->obj.status == OBJ_ACTIVE) && (scenery->obj.id == OBJ_SCENERY_CO_DOORS)) { dx = scenery->obj.pos.x - shot->obj.pos.x; @@ -1884,7 +1884,8 @@ void PlayerShot_ApplyExplosionDamage(PlayerShot* shot, s32 damage) { scenery->dmgPart = 0; } } - sprite = gSprites; + + sprite = &gSprites[0]; for (i = 0; i < ARRAY_COUNT(gSprites); i++, sprite++) { if ((sprite->obj.status == OBJ_ACTIVE) && ((sprite->obj.id == OBJ_SPRITE_FO_POLE) || (sprite->obj.id == OBJ_SPRITE_TI_CACTUS) || @@ -1897,6 +1898,7 @@ void PlayerShot_ApplyExplosionDamage(PlayerShot* shot, s32 damage) { } } } + actor = &gActors[0]; for (i = 0; i < ARRAY_COUNT(gActors); i++, actor++) { if ((actor->obj.status == OBJ_ACTIVE) && (actor->timer_0C2 == 0) && @@ -1910,9 +1912,11 @@ void PlayerShot_ApplyExplosionDamage(PlayerShot* shot, s32 damage) { if ((gLevelMode == LEVELMODE_ON_RAILS) && (dz < 0.0f)) { dz *= 0.6f; } + actor->hitPos.x = shot->obj.pos.x; actor->hitPos.y = shot->obj.pos.y; actor->hitPos.z = shot->obj.pos.z; + if (sqrtf(SQ(dx) + SQ(dy) + SQ(dz)) < radius) { if ((actor->obj.id == OBJ_ACTOR_CO_RADAR) || (actor->obj.id == OBJ_ACTOR_ME_LASER_CANNON_1) || (actor->obj.id == OBJ_ACTOR_MISSILE_SEEK_TEAM) || (actor->obj.id == OBJ_ACTOR_ME_HOPBOT) || @@ -1953,6 +1957,7 @@ void PlayerShot_ApplyExplosionDamage(PlayerShot* shot, s32 damage) { } } } + if (gCurrentLevel == LEVEL_MACBETH) { Macbeth_801AD144(shot); } else if (gCurrentLevel == LEVEL_VENOM_1) { @@ -1960,7 +1965,8 @@ void PlayerShot_ApplyExplosionDamage(PlayerShot* shot, s32 damage) { } else { PlayerShot_CheckBossHitbox(shot); } - effect = gEffects; + + effect = &gEffects[0]; for (i = 0; i < ARRAY_COUNT(gEffects); i++, effect++) { if (effect->obj.status == OBJ_ACTIVE) { dx = effect->obj.pos.x - shot->obj.pos.x; @@ -1987,6 +1993,7 @@ void PlayerShot_ApplyExplosionDamage(PlayerShot* shot, s32 damage) { } } } + if (gVersusMode) { player = gPlayer; for (i = 0; i < gCamCount; i++, player++) { @@ -2023,14 +2030,17 @@ void PlayerShot_UpdateBomb(PlayerShot* shot) { PlayerShot_ExplodeBomb(shot); break; } + if ((shot->obj.pos.y < gGroundHeight) && (gGroundType != 4)) { PlayerShot_ExplodeBomb(shot); break; } + if ((gPlayer[shot->sourceId].form == FORM_LANDMASTER) || (gPlayer[shot->sourceId].form == FORM_ON_FOOT)) { shot->vel.y -= 1.0f; Math_SmoothStepToF(&shot->obj.rot.x, -90.0f, 0.05f, 1.0f, 0.0f); } + if (shot->timer < 25) { if (gVersusMode) { if (gControllerPress[shot->sourceId].button & gBombButton[shot->sourceId]) { @@ -2044,16 +2054,19 @@ void PlayerShot_UpdateBomb(PlayerShot* shot) { } } } + if (!((gCurrentLevel == LEVEL_VENOM_ANDROSS) && (gBosses[0].obj.status == OBJ_ACTIVE) && (gBosses[0].state == 17))) { PlayerShot_CollisionCheck(shot); } PlayerShot_SetBombLight(shot); break; + case 1: gGroundClipMode = 2; shot->obj.rot.y += 1.0f; Math_SmoothStepToF(&shot->scale, shot->unk_48, 0.05f, 1.5f, 0.001f); + if ((shot->timer > 0) && (shot->timer < 30)) { if (!gVersusMode && ((gPlayer[0].state == PLAYERSTATE_ACTIVE) || (gPlayer[0].state == PLAYERSTATE_U_TURN))) { @@ -2069,6 +2082,7 @@ void PlayerShot_UpdateBomb(PlayerShot* shot) { } PlayerShot_SetBombLight(shot); } + if (shot->timer == 0) { shot->unk_58 -= 8; if (shot->unk_58 < 0) { @@ -2120,7 +2134,8 @@ void PlayerShot_UpdateLockOnShot(PlayerShot* shot) { sLockOnPos.y += actor->info.targetOffset; } } - for (i = 0, player = gPlayer; i < gCamCount; i++, player++) { + + for (i = 0, player = &gPlayer[0]; i < gCamCount; i++, player++) { if (((player->state == PLAYERSTATE_ACTIVE) || (player->state == PLAYERSTATE_U_TURN)) && (gVsLockOnTimers[i][shot->sourceId] != 0)) { var_a3 = 1; @@ -2134,6 +2149,7 @@ void PlayerShot_UpdateLockOnShot(PlayerShot* shot) { sLockOnPos.z = player->trueZpos; } } + if (var_a3 != 0) { sp6C = shot->obj.pos.x - sLockOnPos.x; sp68 = shot->obj.pos.y - sLockOnPos.y; @@ -2159,12 +2175,14 @@ void PlayerShot_UpdateLockOnShot(PlayerShot* shot) { shot->unk_60 = 1; } } + Math_SmoothStepToF(&shot->unk_50, 360.0f, 1.0f, 3.0f, 0.f); if (shot->unk_60 != 0) { Math_SmoothStepToF(&shot->unk_54, 169.0f, 1.0f, 13.0f, 0.f); } else { Math_SmoothStepToF(&shot->unk_54, 91.0f, 1.0f, 7.7999997f, 0.f); } + if (!((gPlayer[shot->sourceId].form == FORM_LANDMASTER) && (shot->unk_60 != 0))) { Vec3f sp44; Vec3f sp38; @@ -2180,6 +2198,7 @@ void PlayerShot_UpdateLockOnShot(PlayerShot* shot) { shot->vel.y = sp38.y; shot->vel.z = sp38.z; } + PlayerShot_CollisionCheck(shot); gLight3x = shot->obj.pos.x; gLight3y = shot->obj.pos.y; @@ -2198,6 +2217,7 @@ void PlayerShot_UpdateShot(PlayerShot* shot, s32 index) { shot->obj.pos.x += shot->vel.x; shot->obj.pos.y += shot->vel.y; shot->obj.pos.z += shot->vel.z; + switch (shot->obj.id) { case PLAYERSHOT_SINGLE_LASER: PlayerShot_UpdateBeam(shot, index); diff --git a/src/engine/fox_edisplay.c b/src/engine/fox_edisplay.c index ee6a7c96..bc318abf 100644 --- a/src/engine/fox_edisplay.c +++ b/src/engine/fox_edisplay.c @@ -588,7 +588,7 @@ void ActorTeamArwing_Draw(ActorTeamArwing* this) { gActorTeamArwing.laserGunsYpos = gActorTeamArwing.laserGunsXpos = gActorTeamArwing.wingsXrot = gActorTeamArwing.wingsYrot = gActorTeamArwing.cockpitGlassXrot = gActorTeamArwing.wingsZrot = 0.0f; gActorTeamArwing.unk_28 = this->fwork[17]; - gActorTeamArwing.drawFace = this->iwork[14]; + gActorTeamArwing.drawFace = this->iwork[TEAM_FACE]; gActorTeamArwing.teamFaceXrot = this->fwork[20]; gActorTeamArwing.teamFaceYrot = this->fwork[19]; diff --git a/src/engine/fox_hud.c b/src/engine/fox_hud.c index 31907b25..d9d9d14c 100644 --- a/src/engine/fox_hud.c +++ b/src/engine/fox_hud.c @@ -5584,7 +5584,7 @@ void Aquas_AqCoralReef2_Setup(ActorCutscene* this, s32 posIdx) { this->obj.id = OBJ_ACTOR_CUTSCENE; this->obj.pos = sAqCoralReef2Pos[posIdx]; this->obj.pos.z -= gPathProgress; - this->animFrame = 46; + this->animFrame = ACTOR_CS_AQ_CORAL_REEF_2; Object_SetInfo(&this->info, this->obj.id); } @@ -5599,7 +5599,7 @@ void Aquas_AqRock_Setup(ActorCutscene* this, s32 posIdx) { this->obj.id = OBJ_ACTOR_CUTSCENE; this->obj.pos = sAqRockPos[posIdx]; this->obj.pos.z -= gPathProgress; - this->animFrame = 47; + this->animFrame = ACTOR_CS_AQ_ROCK; Object_SetInfo(&this->info, this->obj.id); } diff --git a/src/overlays/ovl_i1/fox_co.c b/src/overlays/ovl_i1/fox_co.c index 5fa54e1f..926dd59b 100644 --- a/src/overlays/ovl_i1/fox_co.c +++ b/src/overlays/ovl_i1/fox_co.c @@ -2972,9 +2972,9 @@ void Corneria_LevelStart(Player* player) { Corneria_CsTeamSetup(slippy, 1); Corneria_CsTeamSetup(peppy, 2); - falco->iwork[14] = 2; - slippy->iwork[14] = 3; - peppy->iwork[14] = 4; + falco->iwork[TEAM_FACE] = FACE_FALCO; + slippy->iwork[TEAM_FACE] = FACE_SLIPPY; + peppy->iwork[TEAM_FACE] = FACE_PEPPY; player->cam.eye.x = gCsCamEyeX = player->pos.x - 400.0f; gPlayer[0].cam.eye.y = gCsCamEyeY = player->pos.y + 600.0f; diff --git a/src/overlays/ovl_i2/fox_me.c b/src/overlays/ovl_i2/fox_me.c index a8147d1c..6df45e0e 100644 --- a/src/overlays/ovl_i2/fox_me.c +++ b/src/overlays/ovl_i2/fox_me.c @@ -1791,7 +1791,7 @@ void Meteo_LevelStart_SetupTeam(ActorCutscene* this, s32 teamIdx) { Object_SetInfo(&this->info, this->obj.id); this->info.cullDistance = 200.0f; - if (this->animFrame == 0) { + if (this->animFrame == ACTOR_CS_TEAM_ARWING) { this->iwork[11] = 1; AUDIO_PLAY_SFX(NA_SE_ARWING_ENGINE_FG, this->sfxSource, 4); return; diff --git a/src/overlays/ovl_i2/fox_sx.c b/src/overlays/ovl_i2/fox_sx.c index 029902ea..e40495ee 100644 --- a/src/overlays/ovl_i2/fox_sx.c +++ b/src/overlays/ovl_i2/fox_sx.c @@ -114,7 +114,7 @@ void SectorX_SxSlippy_Update(SxSlippy* this) { gPlayer[0].state = PLAYERSTATE_STANDBY; this->timer_0BC = 200; - this->iwork[14] = 3; + this->iwork[TEAM_FACE] = FACE_SLIPPY; this->fwork[0] = 0.0f; this->fwork[1] = 0.0f; @@ -1343,13 +1343,13 @@ void SectorX_SxSpyborg_PostLimbDraw(s32 limbIndex, Vec3f* rot, void* thisx) { } } -Vec3f D_i2_801956B0[5] = { { 0.0f, 2300.0f, -5000.0f }, - { -600.0f, 2200.0f, -5000.0f }, - { -300.0f, 2270.0f, -5000.0f }, - { 300.0f, 2270.0f, -5000.0f }, - { 600.0f, 2200.0f, -5000.0f } }; +Vec3f sSxCsCommanderPos[5] = { { 0.0f, 2300.0f, -5000.0f }, + { -600.0f, 2200.0f, -5000.0f }, + { -300.0f, 2270.0f, -5000.0f }, + { 300.0f, 2270.0f, -5000.0f }, + { 600.0f, 2200.0f, -5000.0f } }; -Vec3f D_i2_801956EC[3] = { +Vec3f sLevelStartTeamSetupPos[3] = { { 150.0f, 250.0f, 50.0f }, { -150.0f, -50.0f, 50.0f }, { 150.0f, -50.0f, 50.0f }, @@ -1362,7 +1362,7 @@ f32 D_i2_80195740[4] = { -150.0f, 150.0f, 0.0f, 0.0f }; f32 D_i2_80195750[4] = { 20.0f, 0.0f, -70.0f, 0.0f }; f32 D_i2_80195760[4] = { -250.0f, -200.0f, -400.0f, -8000.0f }; f32 D_i2_80195770[3] = { 120.0f, 180.0f, -150.0f }; -s16 D_i2_8019577C[3] = { 2, 3, 4 }; +s16 sSxTeamFaces[3] = { FACE_FALCO, FACE_SLIPPY, FACE_PEPPY }; void SectorX_SxSpyborg_Draw(SxSpyborg* this) { f32 fwork; @@ -1435,32 +1435,32 @@ void SectorX_SxSpyborg_Draw(SxSpyborg* this) { } } -void SectorX_80193800(ActorCutscene* this, s32 index) { +void SectorX_CsCommander_Setup(ActorCutscene* this, s32 index) { Actor_Initialize(this); this->obj.status = OBJ_ACTIVE; this->obj.id = OBJ_ACTOR_CUTSCENE; - this->obj.pos.x = D_i2_801956B0[index].x; - this->obj.pos.y = D_i2_801956B0[index].y; - this->obj.pos.z = D_i2_801956B0[index].z; + this->obj.pos.x = sSxCsCommanderPos[index].x; + this->obj.pos.y = sSxCsCommanderPos[index].y; + this->obj.pos.z = sSxCsCommanderPos[index].z; this->vel.z = 30.0f; this->vel.y = -16.0f; - this->animFrame = 20; + this->animFrame = ACTOR_CS_COMMANDER; this->obj.rot.x = 15.0f; Object_SetInfo(&this->info, this->obj.id); AUDIO_PLAY_SFX(NA_SE_EN_ENGINE_01, this->sfxSource, 4); } -void SectorX_801938D8(ActorCutscene* this, s32 index) { +void SectorX_LevelStart_SetupTeam(ActorCutscene* this, s32 teamIdx) { Actor_Initialize(this); this->obj.status = OBJ_ACTIVE; this->obj.id = OBJ_ACTOR_CUTSCENE; - this->obj.pos.x = gPlayer[0].cam.eye.x + D_i2_801956EC[index].x; - this->obj.pos.y = gPlayer[0].cam.eye.y + D_i2_801956EC[index].y; - this->obj.pos.z = gPlayer[0].cam.eye.z + D_i2_801956EC[index].z; + this->obj.pos.x = gPlayer[0].cam.eye.x + sLevelStartTeamSetupPos[teamIdx].x; + this->obj.pos.y = gPlayer[0].cam.eye.y + sLevelStartTeamSetupPos[teamIdx].y; + this->obj.pos.z = gPlayer[0].cam.eye.z + sLevelStartTeamSetupPos[teamIdx].z; this->state = 1; this->iwork[11] = 1; @@ -1469,7 +1469,7 @@ void SectorX_801938D8(ActorCutscene* this, s32 index) { this->obj.rot.y = 180.0f; this->obj.rot.x = 10.0f; - if (index == 2) { + if (teamIdx == 2) { this->obj.rot.z = -20.0f; } @@ -1492,7 +1492,7 @@ void SectorX_LevelStart(Player* player) { case 0: gCsFrameCount = 0; for (i = 0; i < 5; i++) { - SectorX_80193800(&gActors[5 + i], i); + SectorX_CsCommander_Setup(&gActors[5 + i], i); } player->csState = 1; player->cam.eye.x = gCsCamEyeX = 100.0f; @@ -1582,17 +1582,17 @@ void SectorX_LevelStart(Player* player) { switch (gCsFrameCount) { case 195: if (gTeamShields[TEAM_ID_FALCO] > 0) { - SectorX_801938D8(&gActors[0], 0); + SectorX_LevelStart_SetupTeam(&gActors[0], 0); } break; case 213: if (gTeamShields[TEAM_ID_SLIPPY] > 0) { - SectorX_801938D8(&gActors[1], 1); + SectorX_LevelStart_SetupTeam(&gActors[1], 1); } break; case 229: if (gTeamShields[TEAM_ID_PEPPY] > 0) { - SectorX_801938D8(&gActors[2], 2); + SectorX_LevelStart_SetupTeam(&gActors[2], 2); } break; } @@ -1664,7 +1664,7 @@ void SectorX_LevelStart(Player* player) { player->trueZpos = player->pos.z + player->camDist; } -void SectorX_801944D4(ActorCutscene* this, s32 index) { +void SectorX_LevelComplete_SetupTeam(ActorCutscene* this, s32 teamIdx) { Vec3f srcA; Vec3f destA; Vec3f srcB; @@ -1672,12 +1672,14 @@ void SectorX_801944D4(ActorCutscene* this, s32 index) { Player* player = &gPlayer[0]; Matrix_RotateY(gCalcMatrix, player->rot.y * M_DTOR, MTXF_NEW); - srcA.x = D_i2_80195710[index]; - srcA.y = D_i2_80195720[index]; - srcA.z = D_i2_80195730[index]; - srcB.x = D_i2_80195740[index]; - srcB.y = D_i2_80195750[index]; - srcB.z = D_i2_80195760[index]; + + srcA.x = D_i2_80195710[teamIdx]; + srcA.y = D_i2_80195720[teamIdx]; + srcA.z = D_i2_80195730[teamIdx]; + srcB.x = D_i2_80195740[teamIdx]; + srcB.y = D_i2_80195750[teamIdx]; + srcB.z = D_i2_80195760[teamIdx]; + Matrix_MultVec3fNoTranslate(gCalcMatrix, &srcA, &destA); Matrix_MultVec3fNoTranslate(gCalcMatrix, &srcB, &destB); @@ -1698,16 +1700,16 @@ void SectorX_801944D4(ActorCutscene* this, s32 index) { Object_SetInfo(&this->info, this->obj.id); - if (index == 3) { + if (teamIdx == 3) { this->animFrame = ACTOR_CS_GREAT_FOX; this->state = 20; this->obj.rot.x = -player->rot.x - 10.0f; this->obj.rot.y = (player->rot.y + 180.0f) - 10.0f; this->fwork[9] = 10.0f; } else { - this->obj.rot.z = D_i2_80195770[index]; + this->obj.rot.z = D_i2_80195770[teamIdx]; this->iwork[11] = 1; - this->iwork[14] = D_i2_8019577C[index]; + this->iwork[TEAM_FACE] = sSxTeamFaces[teamIdx]; AUDIO_PLAY_SFX(NA_SE_ARWING_ENGINE_FG, this->sfxSource, 4); } } @@ -1815,13 +1817,13 @@ void SectorX_LevelComplete(Player* player) { case 100: if (gTeamShields[TEAM_ID_FALCO] > 0) { - SectorX_801944D4(&gActors[1], 0); + SectorX_LevelComplete_SetupTeam(&gActors[1], 0); } if (gTeamShields[TEAM_ID_SLIPPY] > 0) { - SectorX_801944D4(&gActors[2], 1); + SectorX_LevelComplete_SetupTeam(&gActors[2], 1); } if (gTeamShields[TEAM_ID_PEPPY] > 0) { - SectorX_801944D4(&gActors[3], 2); + SectorX_LevelComplete_SetupTeam(&gActors[3], 2); } break; @@ -1838,8 +1840,8 @@ void SectorX_LevelComplete(Player* player) { break; case 920: - gActors[1].iwork[14] = gActors[2].iwork[14] = gActors[3].iwork[14] = 0; - SectorX_801944D4(&gActors[0], 3); + gActors[1].iwork[TEAM_FACE] = gActors[2].iwork[TEAM_FACE] = gActors[3].iwork[TEAM_FACE] = FACE_NONE; + SectorX_LevelComplete_SetupTeam(&gActors[0], 3); AUDIO_PLAY_SFX(NA_SE_GREATFOX_ENGINE, gActors[0].sfxSource, 0); break; diff --git a/src/overlays/ovl_i3/fox_a6.c b/src/overlays/ovl_i3/fox_a6.c index e406b971..9a757608 100644 --- a/src/overlays/ovl_i3/fox_a6.c +++ b/src/overlays/ovl_i3/fox_a6.c @@ -2635,7 +2635,7 @@ void Area6_8018EC38(ActorCutscene* this, s32 teamIdx) { // Peppy is omitted, probably because it's outside of the camera view. if (teamIdx + 1 != 3) { - this->iwork[14] = teamIdx + 2; + this->iwork[TEAM_FACE] = teamIdx + 2; } Object_SetInfo(&this->info, this->obj.id); diff --git a/src/overlays/ovl_i3/fox_aq.c b/src/overlays/ovl_i3/fox_aq.c index ba4d54cc..e9f5b8b7 100644 --- a/src/overlays/ovl_i3/fox_aq.c +++ b/src/overlays/ovl_i3/fox_aq.c @@ -6555,7 +6555,7 @@ void Aquas_801BDF14(void) { actor->obj.pos.y = D_i3_801C0504[i].y; actor->obj.pos.z = D_i3_801C0504[i].z; actor->rot_0F4.y = D_i3_801C075C[i]; - actor->animFrame = 41; + actor->animFrame = ACTOR_CS_AQ_FISHGROUP; actor->iwork[0] = RAND_INT(20.0f); actor->iwork[2] = i; actor->timer_0BC = 231; diff --git a/src/overlays/ovl_i4/fox_fo.c b/src/overlays/ovl_i4/fox_fo.c index 28a27131..20b0087d 100644 --- a/src/overlays/ovl_i4/fox_fo.c +++ b/src/overlays/ovl_i4/fox_fo.c @@ -884,9 +884,9 @@ void Fortuna_LevelComplete(Player* player) { D_ctx_80177A48[1] = 0.0f; D_ctx_80177A48[2] = -400.0f; D_ctx_80177A48[3] = 0.0f; - falco->iwork[14] = 2; - slippy->iwork[14] = 3; - peppy->iwork[14] = 4; + falco->iwork[TEAM_FACE] = FACE_FALCO; + slippy->iwork[TEAM_FACE] = FACE_SLIPPY; + peppy->iwork[TEAM_FACE] = FACE_PEPPY; } if (gCsFrameCount == 200) { diff --git a/src/overlays/ovl_i6/fox_andross.c b/src/overlays/ovl_i6/fox_andross.c index 3a870aeb..b140092b 100644 --- a/src/overlays/ovl_i6/fox_andross.c +++ b/src/overlays/ovl_i6/fox_andross.c @@ -329,7 +329,7 @@ void Andross_80188468(void) { actor->obj.pos.y = 300.0f; actor->obj.pos.z = -11959.0f; actor->iwork[11] = 1; - actor->iwork[14] = 1; + actor->iwork[TEAM_FACE] = FACE_FOX; actor->obj.id = OBJ_ACTOR_TEAM_ARWING; Object_SetInfo(&actor->info, actor->obj.id); AUDIO_PLAY_SFX(NA_SE_ARWING_ENGINE_FG, actor->sfxSource, 4); @@ -3787,7 +3787,7 @@ void Andross_801939A0(s32 actorIdx) { actor->fwork[1] = 6.5f; if (actorIdx == 10) { - actor->iwork[14] = 1; + actor->iwork[TEAM_FACE] = FACE_FOX; } if (actorIdx == 1) { actor->state = 1; diff --git a/srcjp/audio/audio_tables.c b/srcjp/audio/audio_tables.c index 0da7d3a4..67aa78c0 100644 --- a/srcjp/audio/audio_tables.c +++ b/srcjp/audio/audio_tables.c @@ -57,104 +57,281 @@ AudioTable D_800C07B0 = { (((numInst) &0xFF) << 8) | ((numDrums) &0xFF) \ } -// AudioTable gSoundFontTableInit -s32 D_800C0BE0[] = { - 0x00210000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00002F00, 0x020000FF, 0x7F000000, 0x00002F00, - 0x00000820, 0x020101FF, 0x7F000000, 0x00003720, 0x000006E0, 0x020002FF, 0x7F000000, 0x00003E00, 0x000015E0, - 0x020002FF, 0x7F000000, 0x000053E0, 0x00000C20, 0x020002FF, 0x7F000000, 0x00006000, 0x00000FE0, 0x020002FF, - 0x7F000000, 0x00006FE0, 0x00001360, 0x020002FF, 0x7F000000, 0x00008340, 0x00001120, 0x020002FF, 0x7F000000, - 0x00009460, 0x00000EA0, 0x020002FF, 0x7F000000, 0x0000A300, 0x00000CE0, 0x020002FF, 0x7F000000, 0x0000AFE0, - 0x00001BA0, 0x020002FF, 0x7F000000, 0x0000CB80, 0x00000AC0, 0x020002FF, 0x7F000000, 0x0000D640, 0x00000AC0, - 0x020002FF, 0x7F000000, 0x0000E100, 0x00000EE0, 0x020002FF, 0x7F000000, 0x0000EFE0, 0x00000C00, 0x020002FF, - 0x7F000000, 0x0000FBE0, 0x000010A0, 0x020002FF, 0x7F000000, 0x00010C80, 0x00000F80, 0x020002FF, 0x7F000000, - 0x00011C00, 0x000010C0, 0x020002FF, 0x7F000000, 0x00012CC0, 0x00001380, 0x020002FF, 0x7F000000, 0x00014040, - 0x00002B20, 0x020002FF, 0x7F000000, 0x00016B60, 0x000009A0, 0x020002FF, 0x7F000000, 0x00017500, 0x00001220, - 0x020303FF, 0x10400000, 0x00018720, 0x00000180, 0x020303FF, 0x03000000, 0x000188A0, 0x000011C0, 0x020303FF, - 0x10400000, 0x00019A60, 0x00000940, 0x020303FF, 0x0A400000, 0x0001A3A0, 0x000009E0, 0x020303FF, 0x0A400000, - 0x0001AD80, 0x00000920, 0x020303FF, 0x0A400000, 0x0001B6A0, 0x000009E0, 0x020303FF, 0x0A400000, 0x0001C080, - 0x000009E0, 0x020303FF, 0x0A400000, 0x0001CA60, 0x00000A10, 0x020303FF, 0x0A400000, 0x0001D470, 0x000009E0, - 0x020303FF, 0x0A400000, 0x0001DE50, 0x00000A00, 0x020303FF, 0x0A400000, 0x0001E850, 0x000008D0, 0x020303FF, - 0x0A400000, -}; -/* AudioTable gSoundFontTableInit = { { 33, 0, 0 }, { - SOUNDFONT_ENTRY(0x00000, 0x2F00, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_SFX, SAMPLES_NONE, 127, 0), - SOUNDFONT_ENTRY(0x02F00, 0x0FE0, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_MAP, SAMPLES_NONE, 127, 0), - SOUNDFONT_ENTRY(0x03EE0, 0x0640, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), - SOUNDFONT_ENTRY(0x04520, 0x1560, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), - SOUNDFONT_ENTRY(0x05A80, 0x0C00, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), - SOUNDFONT_ENTRY(0x06680, 0x0DE0, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), - SOUNDFONT_ENTRY(0x07460, 0x1200, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), - SOUNDFONT_ENTRY(0x08660, 0x1040, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), - SOUNDFONT_ENTRY(0x096A0, 0x0E40, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), - SOUNDFONT_ENTRY(0x0A4E0, 0x0C20, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), - SOUNDFONT_ENTRY(0x0B100, 0x1920, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), - SOUNDFONT_ENTRY(0x0CA20, 0x0A20, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), - SOUNDFONT_ENTRY(0x0D440, 0x0A00, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), - SOUNDFONT_ENTRY(0x0DE40, 0x0D60, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), - SOUNDFONT_ENTRY(0x0EBA0, 0x0C20, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), - SOUNDFONT_ENTRY(0x0F7C0, 0x0F00, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), - SOUNDFONT_ENTRY(0x106C0, 0x0F20, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), - SOUNDFONT_ENTRY(0x115E0, 0x0E20, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), - SOUNDFONT_ENTRY(0x12400, 0x10A0, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), - SOUNDFONT_ENTRY(0x134A0, 0x2580, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), - SOUNDFONT_ENTRY(0x15A20, 0x09E0, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), - SOUNDFONT_ENTRY(0x16400, 0x1220, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 16, 64), - SOUNDFONT_ENTRY(0x17620, 0x0180, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 3, 0), - SOUNDFONT_ENTRY(0x177A0, 0x11C0, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 16, 64), - SOUNDFONT_ENTRY(0x18960, 0x0940, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 10, 64), - SOUNDFONT_ENTRY(0x192A0, 0x09E0, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 10, 64), - SOUNDFONT_ENTRY(0x19C80, 0x0920, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 10, 64), - SOUNDFONT_ENTRY(0x1A5A0, 0x09E0, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 10, 64), - SOUNDFONT_ENTRY(0x1AF80, 0x09E0, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 10, 64), - SOUNDFONT_ENTRY(0x1B960, 0x0A10, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 10, 64), - SOUNDFONT_ENTRY(0x1C370, 0x09E0, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 10, 64), - SOUNDFONT_ENTRY(0x1CD50, 0x0A00, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 10, 64), - SOUNDFONT_ENTRY(0x1D750, 0x08D0, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 10, 64), - }, + SOUNDFONT_ENTRY(0x0, 0x2f00, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_SFX, SAMPLES_NONE, 127, 0), + SOUNDFONT_ENTRY(0x2f00, 0x820, MEDIUM_CART, CACHEPOLICY_1, SAMPLES_MAP, SAMPLES_NONE, 127, 0), + SOUNDFONT_ENTRY(0x3720, 0x6e0, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), + SOUNDFONT_ENTRY(0x3e00, 0x15e0, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), + SOUNDFONT_ENTRY(0x53e0, 0xc20, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), + SOUNDFONT_ENTRY(0x6000, 0xfe0, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), + SOUNDFONT_ENTRY(0x6fe0, 0x1360, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), + SOUNDFONT_ENTRY(0x8340, 0x1120, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), + SOUNDFONT_ENTRY(0x9460, 0xea0, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), + SOUNDFONT_ENTRY(0xa300, 0xce0, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), + SOUNDFONT_ENTRY(0xafe0, 0x1ba0, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), + SOUNDFONT_ENTRY(0xcb80, 0xac0, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), + SOUNDFONT_ENTRY(0xd640, 0xac0, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), + SOUNDFONT_ENTRY(0xe100, 0xee0, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), + SOUNDFONT_ENTRY(0xefe0, 0xc00, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), + SOUNDFONT_ENTRY(0xfbe0, 0x10a0, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), + SOUNDFONT_ENTRY(0x10c80, 0xf80, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), + SOUNDFONT_ENTRY(0x11c00, 0x10c0, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), + SOUNDFONT_ENTRY(0x12cc0, 0x1380, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), + SOUNDFONT_ENTRY(0x14040, 0x2b20, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), + SOUNDFONT_ENTRY(0x16b60, 0x9a0, MEDIUM_CART, CACHEPOLICY_0, SAMPLES_VOICE, SAMPLES_NONE, 127, 0), + SOUNDFONT_ENTRY(0x17500, 0x1220, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 16, 64), + SOUNDFONT_ENTRY(0x18720, 0x180, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 3, 0), + SOUNDFONT_ENTRY(0x188a0, 0x11c0, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 16, 64), + SOUNDFONT_ENTRY(0x19a60, 0x940, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 10, 64), + SOUNDFONT_ENTRY(0x1a3a0, 0x9e0, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 10, 64), + SOUNDFONT_ENTRY(0x1ad80, 0x920, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 10, 64), + SOUNDFONT_ENTRY(0x1b6a0, 0x9e0, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 10, 64), + SOUNDFONT_ENTRY(0x1c080, 0x9e0, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 10, 64), + SOUNDFONT_ENTRY(0x1ca60, 0xa10, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 10, 64), + SOUNDFONT_ENTRY(0x1d470, 0x9e0, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 10, 64), + SOUNDFONT_ENTRY(0x1de50, 0xa00, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 10, 64), + SOUNDFONT_ENTRY(0x1e850, 0x8d0, MEDIUM_CART, CACHEPOLICY_3, SAMPLES_INST, SAMPLES_NONE, 10, 64), + } }; -*/ #define AS_BYTES(x) (((x) >> 8) & 0xFF), ((x) &0xFF) -// u8 gSeqFontTableInit[283] -s32 D_800C0E00[] = { - 0x00840086, 0x009B009D, 0x009F00A1, 0x00A300A5, 0x00A700A9, 0x00AB00AD, 0x00AF00B1, 0x00B300B5, 0x00B700B9, - 0x00BB00BD, 0x00BF00C1, 0x00C300C5, 0x00C700C9, 0x00CB00CD, 0x00CF00D1, 0x00D300D5, 0x00D700D9, 0x00DB00DD, - 0x00DF00E1, 0x00E300E5, 0x00E700E9, 0x00EB00ED, 0x00EF00F1, 0x00F300F5, 0x00F700F9, 0x00FB00FD, 0x00FF0101, - 0x01030105, 0x01070109, 0x010B010D, 0x010F0111, 0x01130115, 0x01170119, 0x01001414, 0x13121110, 0x0F0E0D0C, - 0x0B0A0908, 0x07060504, 0x03010201, 0x18011D01, 0x19011A01, 0x1C011901, 0x19011D01, 0x18011D01, 0x1C011901, - 0x1E011801, 0x19011C01, 0x1C011F01, 0x1F011C01, 0x1C011F01, 0x1F011F01, 0x1C011F01, 0x1F011F01, 0x1F011F01, - 0x1F012001, 0x15011501, 0x16011501, 0x15011501, 0x15011501, 0x17011901, 0x15011501, 0x1D011901, 0x1F011501, - 0x15011501, 0x15011501, 0x15011501, 0x15011501, 0x1B011901, 0x15011901, 0x19011901, 0x15011F00, 0x00000000, -}; - -// clang-format off -/* -u8 gSeqFontTableInit[283] = { - // Offset into this table for sequence sound font list - AS_BYTES(132), AS_BYTES(134), AS_BYTES(155), AS_BYTES(157), AS_BYTES(159), AS_BYTES(161), AS_BYTES(163), - AS_BYTES(165), AS_BYTES(167), AS_BYTES(169), AS_BYTES(171), AS_BYTES(173), AS_BYTES(175), AS_BYTES(177), - AS_BYTES(179), AS_BYTES(181), AS_BYTES(183), AS_BYTES(185), AS_BYTES(187), AS_BYTES(189), AS_BYTES(191), - AS_BYTES(193), AS_BYTES(195), AS_BYTES(197), AS_BYTES(199), AS_BYTES(201), AS_BYTES(203), AS_BYTES(205), - AS_BYTES(207), AS_BYTES(209), AS_BYTES(211), AS_BYTES(213), AS_BYTES(215), AS_BYTES(217), AS_BYTES(219), - AS_BYTES(221), AS_BYTES(223), AS_BYTES(225), AS_BYTES(227), AS_BYTES(229), AS_BYTES(231), AS_BYTES(233), - AS_BYTES(235), AS_BYTES(237), AS_BYTES(239), AS_BYTES(241), AS_BYTES(243), AS_BYTES(245), AS_BYTES(247), - AS_BYTES(249), AS_BYTES(251), AS_BYTES(253), AS_BYTES(255), AS_BYTES(257), AS_BYTES(259), AS_BYTES(261), - AS_BYTES(263), AS_BYTES(265), AS_BYTES(267), AS_BYTES(269), AS_BYTES(271), AS_BYTES(273), AS_BYTES(275), - AS_BYTES(277), AS_BYTES(279), AS_BYTES(281), - - // sound font for SFX sequence - 1, 0, - // sound fonts voice sequence - 20, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 1, 2, - // sound fonts for BGM sequences. Each sequence has a single sound font. - 1, 24, 1, 29, 1, 25, 1, 26, 1, 28, 1, 25, 1, 25, 1, 29, 1, 24, 1, 29, 1, 28, 1, 25, 1, 30, 1, 24, 1, 25, 1, 28, - 1, 28, 1, 31, 1, 31, 1, 28, 1, 28, 1, 31, 1, 31, 1, 31, 1, 28, 1, 31, 1, 31, 1, 31, 1, 31, 1, 31, 1, 31, 1, 32, - 1, 21, 1, 21, 1, 22, 1, 21, 1, 21, 1, 21, 1, 21, 1, 21, 1, 23, 1, 25, 1, 21, 1, 21, 1, 29, 1, 25, 1, 31, 1, 21, - 1, 21, 1, 21, 1, 21, 1, 21, 1, 21, 1, 21, 1, 21, 1, 21, 1, 27, 1, 25, 1, 21, 1, 25, 1, 25, 1, 25, 1, 21, 1, 31 +u8 gSeqFontTableInit[288] = { + AS_BYTES(132), + AS_BYTES(134), + AS_BYTES(155), + AS_BYTES(157), + AS_BYTES(159), + AS_BYTES(161), + AS_BYTES(163), + AS_BYTES(165), + AS_BYTES(167), + AS_BYTES(169), + AS_BYTES(171), + AS_BYTES(173), + AS_BYTES(175), + AS_BYTES(177), + AS_BYTES(179), + AS_BYTES(181), + AS_BYTES(183), + AS_BYTES(185), + AS_BYTES(187), + AS_BYTES(189), + AS_BYTES(191), + AS_BYTES(193), + AS_BYTES(195), + AS_BYTES(197), + AS_BYTES(199), + AS_BYTES(201), + AS_BYTES(203), + AS_BYTES(205), + AS_BYTES(207), + AS_BYTES(209), + AS_BYTES(211), + AS_BYTES(213), + AS_BYTES(215), + AS_BYTES(217), + AS_BYTES(219), + AS_BYTES(221), + AS_BYTES(223), + AS_BYTES(225), + AS_BYTES(227), + AS_BYTES(229), + AS_BYTES(231), + AS_BYTES(233), + AS_BYTES(235), + AS_BYTES(237), + AS_BYTES(239), + AS_BYTES(241), + AS_BYTES(243), + AS_BYTES(245), + AS_BYTES(247), + AS_BYTES(249), + AS_BYTES(251), + AS_BYTES(253), + AS_BYTES(255), + 1, + 1, + 1, + 3, + 1, + 5, + 1, + 7, + 1, + 9, + 1, + 11, + 1, + 13, + 1, + 15, + 1, + 17, + 1, + 19, + 1, + 21, + 1, + 23, + 1, + 25, + 1, + 0, + 20, + 20, + 19, + 18, + 17, + 16, + 15, + 14, + 13, + 12, + 11, + 10, + 9, + 8, + 7, + 6, + 5, + 4, + 3, + 1, + 2, + 1, + 24, + 1, + 29, + 1, + 25, + 1, + 26, + 1, + 28, + 1, + 25, + 1, + 25, + 1, + 29, + 1, + 24, + 1, + 29, + 1, + 28, + 1, + 25, + 1, + 30, + 1, + 24, + 1, + 25, + 1, + 28, + 1, + 28, + 1, + 31, + 1, + 31, + 1, + 28, + 1, + 28, + 1, + 31, + 1, + 31, + 1, + 31, + 1, + 28, + 1, + 31, + 1, + 31, + 1, + 31, + 1, + 31, + 1, + 31, + 1, + 31, + 1, + 32, + 1, + 21, + 1, + 21, + 1, + 22, + 1, + 21, + 1, + 21, + 1, + 21, + 1, + 21, + 1, + 21, + 1, + 23, + 1, + 25, + 1, + 21, + 1, + 21, + 1, + 29, + 1, + 25, + 1, + 31, + 1, + 21, + 1, + 21, + 1, + 21, + 1, + 21, + 1, + 21, + 1, + 21, + 1, + 21, + 1, + 21, + 1, + 21, + 1, + 27, + 1, + 25, + 1, + 21, + 1, + 25, + 1, + 25, + 1, + 25, + 1, + 21, + 1, + 31, + 0, + 0, + 0, + 0, + 0, }; -*/ -// clang-format on