1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-05-12 20:13:47 +00:00

Document parts of audio (#1000)

* Minor labelling

* progress

* play percentage -> delay

* duration -> gatetime

* more

* more

* more

* seqIdx -> playerIdx

* more

* more

* more

* more

* format

* fix comment

* filters

* more

* media

* confusion

* Sync load is actually slow load

* AudioHeap prefix

* more

* more

* reformat

* more

* more

* AudioLoad

* more

* more

* seq banks

* more consistent

* more

* name last function in audio_load

* More audio_synthesis

* clean up audio tables

* minor

* slow/fast load ramAddr

* format

* remove unused

* Remove union

* remove padding

* audio bank -> sound font

* seqLayer -> layer

* stuff

* seqChannel -> channel

* ChannelLayer -> Layer

* remove define, add bug comment

* format

* more

* cache enum

* more

* AudioSeq function prefix

* naming

* bankIdx -> bankId

* more

* format

* review

* more

* fixes

* avoid hardcoded sfxid's

* SE -> Sfx

Co-authored-by: zelda2774 <zelda2774@invalid>
This commit is contained in:
zelda2774 2021-11-07 17:58:50 +01:00 committed by GitHub
parent 823a3c0754
commit 5ad7cf9dbb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
50 changed files with 3493 additions and 3508 deletions

View file

@ -59,7 +59,7 @@ glabel gNoteFrequencies
glabel gDefaultShortNoteVelocityTable glabel gDefaultShortNoteVelocityTable
.incbin "baserom.z64", 0xBA6C54, 0x10 .incbin "baserom.z64", 0xBA6C54, 0x10
glabel gDefaultShortNoteDurationTable glabel gDefaultShortNoteGateTimeTable
.incbin "baserom.z64", 0xBA6C64, 0x10 .incbin "baserom.z64", 0xBA6C64, 0x10
glabel gDefaultEnvelope glabel gDefaultEnvelope
@ -95,10 +95,10 @@ glabel gDefaultPanVolume
glabel D_80130224 glabel D_80130224
.incbin "baserom.z64", 0xBA73C4, 0x4 .incbin "baserom.z64", 0xBA73C4, 0x4
glabel D_80130228 glabel sLowPassFilterData
.incbin "baserom.z64", 0xBA73C8, 0x100 .incbin "baserom.z64", 0xBA73C8, 0x100
glabel D_80130328 glabel sHighPassFilterData
.incbin "baserom.z64", 0xBA74C8, 0x148 .incbin "baserom.z64", 0xBA74C8, 0x148
glabel D_80130470 glabel D_80130470

View file

@ -33,34 +33,34 @@ glabel D_8016C8B0
glabel sSoundRequests glabel sSoundRequests
.space 0x1800 .space 0x1800
glabel D_8016E1A0 glabel sSoundBankListEnd
.space 0x8 .space 0x8
glabel D_8016E1A8 glabel sSoundBankFreeListStart
.space 0x8 .space 0x8
glabel D_8016E1B0 glabel sSoundBankUnused
.space 0x8 .space 0x8
glabel D_8016E1B8 glabel gActiveSounds
.space 0xA8 .space 0xA8
glabel D_8016E260 glabel sCurSfxPlayerChannelIdx
.space 0x4 .space 0x4
glabel gSoundBankMuted glabel gSoundBankMuted
.space 0xC .space 0xC
glabel D_8016E270 glabel sUnusedBankLerp
.space 0x70 .space 0x70
glabel gAudioSEFlagSwapSource glabel gAudioSfxSwapSource
.space 0x18 .space 0x18
glabel gAudioSEFlagSwapTarget glabel gAudioSfxSwapTarget
.space 0x18 .space 0x18
glabel gAudioSEFlagSwapMode glabel gAudioSfxSwapMode
.space 0x10 .space 0x10
glabel D_8016E320 glabel D_8016E320

View file

@ -9,16 +9,16 @@
.balign 16 .balign 16
glabel gAudioBankTable glabel gSoundFontTable
.incbin "baserom.z64", 0xBCC270, 0x270 .incbin "baserom.z64", 0xBCC270, 0x270
glabel D_80155340 glabel gSequenceFontTable
.incbin "baserom.z64", 0xBCC4E0, 0x1C0 .incbin "baserom.z64", 0xBCC4E0, 0x1C0
glabel gSequenceTable glabel gSequenceTable
.incbin "baserom.z64", 0xBCC6A0, 0x6F0 .incbin "baserom.z64", 0xBCC6A0, 0x6F0
glabel gAudioTable glabel gSampleBankTable
.incbin "baserom.z64", 0xBCCD90, 0x80 .incbin "baserom.z64", 0xBCCD90, 0x80
glabel rspAspMainDataStart glabel rspAspMainDataStart

View file

@ -17,9 +17,8 @@ void Idle_ThreadEntry(void* arg);
void ViConfig_UpdateVi(u32 mode); void ViConfig_UpdateVi(u32 mode);
void ViConfig_UpdateBlack(void); void ViConfig_UpdateBlack(void);
s32 DmaMgr_CompareName(const char* name1, const char* name2); s32 DmaMgr_CompareName(const char* name1, const char* name2);
s32 DmaMgr_DMARomToRam(u32 rom, u32 ram, u32 size); s32 DmaMgr_DmaRomToRam(u32 rom, u32 ram, u32 size);
s32 DmaMgr_DmaCallback0(OSPiHandle* pihandle, OSIoMesg* mb, s32 direction); s32 DmaMgr_DmaHandler(OSPiHandle* pihandle, OSIoMesg* mb, s32 direction);
void DmaMgr_DmaCallback1(u32 ram, u32 rom, u32 size);
void DmaMgr_Error(DmaRequest* req, const char* file, const char* errorName, const char* errorDesc); void DmaMgr_Error(DmaRequest* req, const char* file, const char* errorName, const char* errorDesc);
const char* DmaMgr_GetFileNameImpl(u32 vrom); const char* DmaMgr_GetFileNameImpl(u32 vrom);
const char* DmaMgr_GetFileName(u32 vrom); const char* DmaMgr_GetFileName(u32 vrom);
@ -1891,76 +1890,57 @@ void UCodeDisas_Destroy(UCodeDisas*);
void UCodeDisas_RegisterUCode(UCodeDisas*, s32, UCodeInfo*); void UCodeDisas_RegisterUCode(UCodeDisas*, s32, UCodeInfo*);
void UCodeDisas_SetCurUCode(UCodeDisas*, void*); void UCodeDisas_SetCurUCode(UCodeDisas*, void*);
Acmd* AudioSynth_Update(Acmd* cmdStart, s32* cmdCnt, s16* aiStart, s32 aiBufLen); Acmd* AudioSynth_Update(Acmd* cmdStart, s32* cmdCnt, s16* aiStart, s32 aiBufLen);
void Audio_DiscardBank(s32 bankId); void AudioHeap_DiscardFont(s32 fontId);
void Audio_DiscardSequence(s32 seqId); void AudioHeap_DiscardSequence(s32 seqId);
void func_800DE238(void* mem, u32 size); void AudioHeap_WritebackDCache(void* mem, u32 size);
void* func_800DE258(SoundAllocPool* pool, u32 size); void* AudioHeap_AllocZeroedAttemptExternal(AudioAllocPool* pool, u32 size);
void* func_800DE2B0(SoundAllocPool* pool, u32 size); void* AudioHeap_AllocAttemptExternal(AudioAllocPool* pool, u32 size);
void* Audio_AllocDmaMemory(SoundAllocPool* pool, u32 size); void* AudioHeap_AllocDmaMemory(AudioAllocPool* pool, u32 size);
void* Audio_AllocDmaMemoryZeroed(SoundAllocPool* pool, u32 size); void* AudioHeap_AllocDmaMemoryZeroed(AudioAllocPool* pool, u32 size);
void* Audio_AllocZeroed(SoundAllocPool* pool, u32 size); void* AudioHeap_AllocZeroed(AudioAllocPool* pool, u32 size);
void* Audio_Alloc(SoundAllocPool* pool, u32 size); void* AudioHeap_Alloc(AudioAllocPool* pool, u32 size);
void Audio_SoundAllocPoolInit(SoundAllocPool* pool, void* memAddr, u32 size); void AudioHeap_AllocPoolInit(AudioAllocPool* pool, void* mem, u32 size);
void Audio_PersistentPoolClear(PersistentPool* persistent); void AudioHeap_PersistentCacheClear(AudioPersistentCache* persistent);
void Audio_TemporaryPoolClear(TemporaryPool* temporary); void AudioHeap_TemporaryCacheClear(AudioTemporaryCache* temporary);
void func_800DE4B0(s32 poolIdx); void AudioHeap_PopCache(s32 tableType);
void Audio_InitMainPools(s32 sizeForAudioInitPool); void AudioHeap_InitMainPools(s32 sizeForAudioInitPool);
void Audio_SessionPoolsInit(AudioPoolSplit4* split); void* AudioHeap_AllocCached(s32 tableType, s32 size, s32 cache, s32 id);
void Audio_SeqAndBankPoolInit(AudioPoolSplit2* split); void* AudioHeap_SearchCaches(s32 tableType, s32 arg1, s32 id);
void Audio_PersistentPoolsInit(AudioPoolSplit3* split); void* AudioHeap_SearchRegularCaches(s32 tableType, s32 cache, s32 id);
void Audio_TemporaryPoolsInit(AudioPoolSplit3* split); void AudioHeap_LoadFilter(s16* filter, s32 filter1, s32 filter2);
void* Audio_AllocBankOrSeq(s32 poolIdx, s32 size, s32 arg2, s32 id); s32 AudioHeap_ResetStep(void);
void* func_800DF074(s32 poolIdx, s32 arg1, s32 id); void AudioHeap_Init(void);
void* func_800DF0CC(s32 poolIdx, s32 arg1, s32 id); void* AudioHeap_SearchPermanentCache(s32 tableType, s32 id);
void func_800DF5DC(s16* arg0, s32 arg1); void* AudioHeap_AllocPermanent(s32 tableType, s32 id, u32 size);
void func_800DF630(s16* arg0, s32 arg1); void* AudioHeap_AllocSampleCache(u32 size, s32 fontId, void* sampleAddr, s8 medium, s32 cache);
void func_800DF688(s16* arg0, s32 arg1, s32 arg2); void AudioHeap_ApplySampleBankCache(s32 sampleBankId);
void func_800DF7C4(void); void AudioLoad_DecreaseSampleDmaTtls(void);
void func_800DF888(void); void* AudioLoad_DmaSampleData(u32 devAddr, u32 size, s32 arg2, u8* dmaIndexRef, s32 medium);
s32 Audio_ResetStep(void); void AudioLoad_InitSampleDmaBuffers(s32 arg0);
void Audio_InitHeap(void); s32 AudioLoad_IsFontLoadComplete(s32 fontId);
void* func_800E04E8(s32 poolIdx, s32 id); s32 AudioLoad_IsSeqLoadComplete(s32 seqId);
void* func_800E0540(s32 poolIdx, s32 id, u32 size); void AudioLoad_SetFontLoadStatus(s32 fontId, s32 status);
void* func_800E05C4(u32 size, s32 arg1, void* arg2, s8 arg3, s32 arg4); void AudioLoad_SetSeqLoadStatus(s32 seqId, s32 status);
void func_800E0634(u32 arg0, u32 arg1); void AudioLoad_SyncLoadSeqParts(s32 seqId, s32 arg1);
UnkHeapEntry* func_800E06CC(u32 size); s32 AudioLoad_SyncLoadInstrument(s32 fontId, s32 instId, s32 drumId);
void func_800E0964(UnkHeapEntry* entry, s32 bankId); void AudioLoad_AsyncLoadSeq(s32 seqId, s32 arg1, s32 retData, OSMesgQueue* retQueue);
void func_800E0AD8(UnkHeapEntry* entry); void AudioLoad_AsyncLoadSampleBank(s32 sampleBankId, s32 arg1, s32 retData, OSMesgQueue* retQueue);
void func_800E0BB4(UnkHeapEntry* entry, AudioBankSample* sample); void AudioLoad_AsyncLoadFont(s32 fontId, s32 arg1, s32 retData, OSMesgQueue* retQueue);
UnkHeapEntry* func_800E0BF8(u32 size); u8* AudioLoad_GetFontsForSequence(s32 seqId, u32* arg1);
// ? func_800E0C80(?); void AudioLoad_DiscardSeqFonts(s32 seqId);
void func_800E0CBC(void); s32 AudioLoad_SyncInitSeqPlayer(s32 playerIdx, s32 seqId, s32 arg2);
void func_800E0E6C(s32 id); s32 AudioLoad_SyncInitSeqPlayerSkipTicks(s32 playerIdx, s32 seqId, s32 arg2);
void func_800E0E90(s32 id); void AudioLoad_ProcessLoads(s32 resetStatus);
void func_800E0EB4(s32 arg0, s32 id); void AudioLoad_SetDmaHandler(DmaHandler callback);
void func_800E1148(void); void AudioLoad_Init(void* heap, u32 heapSize);
void func_800E11F0(void); void AudioLoad_InitSlowLoads(void);
void* Audio_DmaSampleData(u32 devAddr, u32 size, s32 arg2, u8* dmaIndexRef, s32 medium); s32 AudioLoad_SlowLoadSample(s32 arg0, s32 arg1, s8* arg2);
void func_800E1618(s32 arg0); s32 AudioLoad_SlowLoadSeq(s32 playerIdx, u8* ramAddr, s8* arg2);
s32 Audio_IsBankLoadComplete(s32 bankId); void AudioLoad_InitAsyncLoads(void);
s32 Audio_IsSeqLoadComplete(s32 seqId); void AudioLoad_LoadPermanentSamples(void);
void Audio_SetBankLoadStatus(s32 bankId, s32 status); void AudioLoad_ScriptLoad(s32 tableType, s32 arg1, s8* arg2);
void Audio_SetSeqLoadStatus(s32 seqId, s32 status); void AudioLoad_ProcessScriptLoads(void);
void func_800E1C18(s32 channelIdx, s32 arg1); void AudioLoad_InitScriptLoads(void);
s32 func_800E1D64(s32 arg0, s32 arg1, s32 arg2);
void Audio_AudioSeqAsyncLoad(s32 arg0, s32 arg1, s32 arg2, OSMesgQueue* arg3);
void Audio_AudioTableAsyncLoad(s32 arg0, s32 arg1, s32 arg2, OSMesgQueue* arg3);
void Audio_AudioBankAsyncLoad(s32 arg0, s32 arg1, s32 arg2, OSMesgQueue* arg3);
u8* func_800E1F38(s32 arg0, u32* arg1);
void func_800E1F7C(s32 arg0);
s32 func_800E20D4(s32 playerIndex, s32 seqId, s32 arg2);
s32 func_800E2124(s32 playerIndex, s32 seqId, s32 arg2);
void Audio_ProcessLoads(s32 resetStatus);
void func_800E301C(void* callback);
void Audio_ContextInit(void* heap, u32 heapSize);
void Audio_SyncLoadsInit(void);
s32 Audio_SyncLoadSample(s32 arg0, s32 arg1, s8* arg2);
s32 Audio_SyncLoadSeq(s32 seqIdx, u8* ramAddr, s8* arg2);
void Audio_AsyncLoadReqInit(void);
void func_800E4D94(void);
void func_800E4EEC(s32 tableType, s32 arg1, s8* arg2);
void func_800E4F58(void);
void func_800E4FB0(void);
AudioTask* func_800E4FE0(void); AudioTask* func_800E4FE0(void);
void Audio_QueueCmdF32(u32 arg0, f32 arg1); void Audio_QueueCmdF32(u32 arg0, f32 arg1);
void Audio_QueueCmdS32(u32 arg0, s32 arg1); void Audio_QueueCmdS32(u32 arg0, s32 arg1);
@ -1983,16 +1963,16 @@ void Audio_NoteSetResamplingRate(NoteSubEu* noteSubEu, f32 resamplingRateInput);
void Audio_NoteInit(Note* note); void Audio_NoteInit(Note* note);
void Audio_NoteDisable(Note* note); void Audio_NoteDisable(Note* note);
void Audio_ProcessNotes(void); void Audio_ProcessNotes(void);
AudioBankSound* Audio_InstrumentGetAudioBankSound(Instrument* instrument, s32 semitone); SoundFontSound* Audio_InstrumentGetSound(Instrument* instrument, s32 semitone);
Instrument* Audio_GetInstrumentInner(s32 bankId, s32 instId); Instrument* Audio_GetInstrumentInner(s32 fontId, s32 instId);
Drum* Audio_GetDrum(s32 bankId, s32 drumId); Drum* Audio_GetDrum(s32 fontId, s32 drumId);
AudioBankSound* Audio_GetSfx(s32 bankId, s32 sfxId); SoundFontSound* Audio_GetSfx(s32 fontId, s32 sfxId);
s32 func_800E7744(s32 instrument, s32 bankId, s32 instId, void* arg3); s32 Audio_SetFontInstrument(s32 instrumentType, s32 fontId, s32 index, void* value);
void Audio_SeqChanLayerDecayRelease(SequenceChannelLayer* seqLayer, s32 target); void Audio_SeqLayerDecayRelease(SequenceLayer* layer, s32 target);
void Audio_SeqChanLayerNoteDecay(SequenceChannelLayer* seqLayer); void Audio_SeqLayerNoteDecay(SequenceLayer* layer);
void Audio_SeqChanLayerNoteRelease(SequenceChannelLayer* seqLayer); void Audio_SeqLayerNoteRelease(SequenceLayer* layer);
s32 Audio_BuildSyntheticWave(Note* note, SequenceChannelLayer* seqLayer, s32 waveId); s32 Audio_BuildSyntheticWave(Note* note, SequenceLayer* layer, s32 waveId);
void Audio_InitSyntheticWave(Note* note, SequenceChannelLayer* seqLayer); void Audio_InitSyntheticWave(Note* note, SequenceLayer* layer);
void Audio_InitNoteList(AudioListItem* list); void Audio_InitNoteList(AudioListItem* list);
void Audio_InitNoteLists(NotePool* pool); void Audio_InitNoteLists(NotePool* pool);
void Audio_InitNoteFreeList(void); void Audio_InitNoteFreeList(void);
@ -2000,16 +1980,16 @@ void Audio_NotePoolClear(NotePool* pool);
void Audio_NotePoolFill(NotePool* pool, s32 count); void Audio_NotePoolFill(NotePool* pool, s32 count);
void Audio_AudioListPushFront(AudioListItem* list, AudioListItem* item); void Audio_AudioListPushFront(AudioListItem* list, AudioListItem* item);
void Audio_AudioListRemove(AudioListItem* item); void Audio_AudioListRemove(AudioListItem* item);
Note* Audio_PopNodeWithValueLessEqual(AudioListItem* list, s32 limit); Note* Audio_FindNodeWithPrioLessThan(AudioListItem* list, s32 limit);
void Audio_NoteInitForLayer(Note* note, SequenceChannelLayer* seqLayer); void Audio_NoteInitForLayer(Note* note, SequenceLayer* layer);
void func_800E82C0(Note* note, SequenceChannelLayer* seqLayer); void func_800E82C0(Note* note, SequenceLayer* layer);
void Audio_NoteReleaseAndTakeOwnership(Note* note, SequenceChannelLayer* seqLayer); void Audio_NoteReleaseAndTakeOwnership(Note* note, SequenceLayer* layer);
Note* Audio_AllocNoteFromDisabled(NotePool* pool, SequenceChannelLayer* seqLayer); Note* Audio_AllocNoteFromDisabled(NotePool* pool, SequenceLayer* layer);
Note* Audio_AllocNoteFromDecaying(NotePool* pool, SequenceChannelLayer* seqLayer); Note* Audio_AllocNoteFromDecaying(NotePool* pool, SequenceLayer* layer);
Note* Audio_AllocNoteFromActive(NotePool* pool, SequenceChannelLayer* seqLayer); Note* Audio_AllocNoteFromActive(NotePool* pool, SequenceLayer* layer);
Note* Audio_AllocNote(SequenceChannelLayer* seqLayer); Note* Audio_AllocNote(SequenceLayer* layer);
void Audio_NoteInitAll(void); void Audio_NoteInitAll(void);
void Audio_SequenceChannelProcessSound(SequenceChannel* seqChannel, s32 recalculateVolume, s32 b); void Audio_SequenceChannelProcessSound(SequenceChannel* channel, s32 recalculateVolume, s32 b);
void Audio_SequencePlayerProcessSound(SequencePlayer* seqPlayer); void Audio_SequencePlayerProcessSound(SequencePlayer* seqPlayer);
f32 Audio_GetPortamentoFreqScale(Portamento* p); f32 Audio_GetPortamentoFreqScale(Portamento* p);
s16 Audio_GetVibratoPitchChange(VibratoState* vib); s16 Audio_GetVibratoPitchChange(VibratoState* vib);
@ -2019,16 +1999,16 @@ void Audio_NoteVibratoInit(Note* note);
void Audio_NotePortamentoInit(Note* note); void Audio_NotePortamentoInit(Note* note);
void Audio_AdsrInit(AdsrState* adsr, AdsrEnvelope* envelope, s16* volOut); void Audio_AdsrInit(AdsrState* adsr, AdsrEnvelope* envelope, s16* volOut);
f32 Audio_AdsrUpdate(AdsrState* adsr); f32 Audio_AdsrUpdate(AdsrState* adsr);
void Audio_SequenceChannelDisable(SequenceChannel* seqChannel); void AudioSeq_SequenceChannelDisable(SequenceChannel* channel);
void Audio_SequencePlayerDisableAsFinished(SequencePlayer* seqPlayer); void AudioSeq_SequencePlayerDisableAsFinished(SequencePlayer* seqPlayer);
void Audio_SequencePlayerDisable(SequencePlayer* seqPlayer); void AudioSeq_SequencePlayerDisable(SequencePlayer* seqPlayer);
void Audio_AudioListPushBack(AudioListItem* list, AudioListItem* item); void AudioSeq_AudioListPushBack(AudioListItem* list, AudioListItem* item);
void* Audio_AudioListPopBack(AudioListItem* list); void* AudioSeq_AudioListPopBack(AudioListItem* list);
void Audio_ProcessSequences(s32 arg0); void AudioSeq_ProcessSequences(s32 arg0);
void Audio_ProcessSequence(SequencePlayer* seqPlayer); void AudioSeq_SkipForwardSequence(SequencePlayer* seqPlayer);
void Audio_ResetSequencePlayer(SequencePlayer* seqPlayer); void AudioSeq_ResetSequencePlayer(SequencePlayer* seqPlayer);
void func_800EC734(s32 seqPlayerIdx); void AudioSeq_InitSequencePlayerChannels(s32 playerIdx);
void Audio_InitSequencePlayers(void); void AudioSeq_InitSequencePlayers(void);
void func_800ECC04(u16); void func_800ECC04(u16);
void func_800ED858(u8); void func_800ED858(u8);
void func_800ED93C(s8 songIdx, s8 arg1); void func_800ED93C(s8 songIdx, s8 arg1);
@ -2042,7 +2022,7 @@ void func_800EE824(void);
void AudioDebug_Draw(GfxPrint* printer); void AudioDebug_Draw(GfxPrint* printer);
void AudioDebug_ScrPrt(const s8* str, u16 num); void AudioDebug_ScrPrt(const s8* str, u16 num);
void func_800F3054(void); void func_800F3054(void);
void Audio_SetSoundProperties(u8 bankIdx, u8 entryIdx, u8 channelIdx); void Audio_SetSoundProperties(u8 bankId, u8 entryIdx, u8 channelIdx);
void func_800F3F3C(u8); void func_800F3F3C(u8);
void func_800F4010(Vec3f* pos, u16 sfxId, f32); void func_800F4010(Vec3f* pos, u16 sfxId, f32);
void Audio_PlaySoundRandom(Vec3f* pos, u16 baseSfxId, u8 randLim); void Audio_PlaySoundRandom(Vec3f* pos, u16 baseSfxId, u8 randLim);
@ -2084,7 +2064,7 @@ void func_800F5B58(void);
void func_800F5BF0(u8 arg0); void func_800F5BF0(u8 arg0);
void func_800F5C64(u16); void func_800F5C64(u16);
void func_800F5C2C(void); void func_800F5C2C(void);
void func_800F5E18(u8 seqIdx, u16 seqId, u8 fadeTimer, s8 arg3, s8 arg4); void func_800F5E18(u8 playerIdx, u16 seqId, u8 fadeTimer, s8 arg3, s8 arg4);
void func_800F5E90(u8); void func_800F5E90(u8);
void func_800F6114(f32 dist); void func_800F6114(f32 dist);
void func_800F6268(f32 dist, u16); void func_800F6268(f32 dist, u16);
@ -2093,8 +2073,8 @@ void func_800F6584(u8 arg0);
void Audio_SetEnvReverb(s8 reverb); void Audio_SetEnvReverb(s8 reverb);
void Audio_SetCodeReverb(s8 reverb); void Audio_SetCodeReverb(s8 reverb);
void func_800F6700(s8 outputMode); void func_800F6700(s8 outputMode);
void func_800F67A0(u8); void Audio_SetBaseFilter(u8);
void func_800F6828(u8); void Audio_SetExtraFilter(u8);
void Audio_SetCutsceneFlag(s8 flag); void Audio_SetCutsceneFlag(s8 flag);
void Audio_PlaySoundIfNotInCutscene(u16 sfxId); void Audio_PlaySoundIfNotInCutscene(u16 sfxId);
void func_800F6964(u16); void func_800F6964(u16);
@ -2106,33 +2086,30 @@ void Audio_PreNMI();
void func_800F6D58(u8, u8, u8); void func_800F6D58(u8, u8, u8);
// ? func_800F6E7C(?); // ? func_800F6E7C(?);
void func_800F6FB4(u8); void func_800F6FB4(u8);
void func_800F70F8(); void Audio_Init();
void func_800F711C(); void Audio_InitSound();
void func_800F7170(void); void func_800F7170(void);
void func_800F71BC(s32 arg0); void func_800F71BC(s32 arg0);
void Audio_SetSoundBanksMute(u16 muteMask); void Audio_SetSoundBanksMute(u16 muteMask);
void Audio_QueueSeqCmdMute(u8); void Audio_QueueSeqCmdMute(u8 channelIdx);
void Audio_ClearBGMMute(u8); void Audio_ClearBGMMute(u8 channelIdx);
void Audio_PlaySoundGeneral(u16 sfxId, Vec3f* pos, u8 a2, f32* freqScale, f32* a4, s8* reverbAdd); void Audio_PlaySoundGeneral(u16 sfxId, Vec3f* pos, u8 token, f32* freqScale, f32* a4, s8* reverbAdd);
void Audio_ProcessSoundRequest(void); void Audio_ProcessSoundRequest(void);
void func_800F7B54(u8, u8); void Audio_ChooseActiveSounds(u8 bankId);
void func_800F7CEC(u8); void Audio_PlayActiveSounds(u8 bankId);
void func_800F8480(u8); void Audio_StopSfxByBank(u8 bankId);
void func_800F87A0(u8);
void func_800F8884(u8, Vec3f*); void func_800F8884(u8, Vec3f*);
void func_800F89A0(u8, Vec3f*); void Audio_StopSfxByPosAndBank(u8, Vec3f*);
void func_800F89E8(Vec3f*); void Audio_StopSfxByPos(Vec3f*);
void func_800F9280(u8 seqIdx, u8 seqId, u8 arg2, u16 fadeTimer); void func_800F9280(u8 playerIdx, u8 seqId, u8 arg2, u16 fadeTimer);
void Audio_QueueSeqCmd(u32 bgmID); void Audio_QueueSeqCmd(u32 bgmID);
void func_800F8A44(Vec3f* pos, u16 sfxId); void Audio_StopSfxByPosAndId(Vec3f* pos, u16 sfxId);
void func_800F8BA0(u8, u16); void Audio_StopSfxByTokenAndId(u8, u16);
void Audio_StopSfx(u32 sfxId); void Audio_StopSfxById(u32 sfxId);
void Audio_ProcessSoundRequests(void); void Audio_ProcessSoundRequests(void);
void func_800F8EA0(u8, u8, u16);
void func_800F8F34(u8);
void func_800F8F88(void); void func_800F8F88(void);
u8 Audio_IsSfxPlaying(u32 sfxId); u8 Audio_IsSfxPlaying(u32 sfxId);
void func_800F905C(void); void Audio_ResetSounds(void);
void func_800F9474(u8, u16); void func_800F9474(u8, u16);
void func_800F94FC(u32); void func_800F94FC(u32);
void Audio_ProcessSeqCmd(u32); void Audio_ProcessSeqCmd(u32);
@ -2141,7 +2118,7 @@ u16 func_800FA0B4(u8 a0);
s32 func_800FA11C(u32 arg0, u32 arg1); s32 func_800FA11C(u32 arg0, u32 arg1);
void func_800FA174(u8); void func_800FA174(u8);
void func_800FA18C(u8, u8); void func_800FA18C(u8, u8);
void Audio_SetVolScale(u8 seqIdx, u8 scaleIdx, u8 targetVol, u8 volFadeTimer); void Audio_SetVolScale(u8 playerIdx, u8 scaleIdx, u8 targetVol, u8 volFadeTimer);
void func_800FA3DC(void); void func_800FA3DC(void);
u8 func_800FAD34(void); u8 func_800FAD34(void);
void func_800FADF8(void); void func_800FADF8(void);

View file

@ -331,7 +331,7 @@ extern f32 gPitchBendFrequencyScale[256];
extern f32 D_8012F4B4[256]; extern f32 D_8012F4B4[256];
extern f32 gNoteFrequencies[]; extern f32 gNoteFrequencies[];
extern u8 gDefaultShortNoteVelocityTable[16]; extern u8 gDefaultShortNoteVelocityTable[16];
extern u8 gDefaultShortNoteDurationTable[16]; extern u8 gDefaultShortNoteGateTimeTable[16];
extern AdsrEnvelope gDefaultEnvelope[3]; extern AdsrEnvelope gDefaultEnvelope[3];
extern NoteSubEu gZeroNoteSub; extern NoteSubEu gZeroNoteSub;
extern NoteSubEu gDefaultNoteSub; extern NoteSubEu gDefaultNoteSub;
@ -339,14 +339,14 @@ extern u16 gHeadsetPanQuantization[0x10];
extern f32 gHeadsetPanVolume[128]; extern f32 gHeadsetPanVolume[128];
extern f32 gStereoPanVolume[128]; extern f32 gStereoPanVolume[128];
extern f32 gDefaultPanVolume[128]; extern f32 gDefaultPanVolume[128];
extern s16 D_80130228[]; extern s16 sLowPassFilterData[16*8];
extern s16 D_80130328[]; extern s16 sHighPassFilterData[15*8];
extern s32 gAudioContextInitalized; extern s32 gAudioContextInitalized;
extern f32 D_80130510; extern f32 D_80130510;
extern s32 D_80130514; extern s32 D_80130514;
extern u8 D_80130570[7]; extern u8 gIsLargeSoundBank[7];
extern u8 D_80130578[4][7]; extern u8 gChannelsPerBank[4][7];
extern u8 D_80130594[4][7]; extern u8 gUsedChannelsPerBank[4][7];
extern u8 gMorphaTransposeTable[16]; extern u8 gMorphaTransposeTable[16];
extern u8* gFrogsSongPtr; extern u8* gFrogsSongPtr;
extern OcarinaNote* gScarecrowCustomSongPtr; extern OcarinaNote* gScarecrowCustomSongPtr;
@ -357,13 +357,13 @@ extern char D_80133390[];
extern char D_80133398[]; extern char D_80133398[];
extern SoundBankEntry* gSoundBanks[7]; extern SoundBankEntry* gSoundBanks[7];
extern u8 sBankSizes[7]; extern u8 sBankSizes[7];
extern u8 D_801333CC; extern u8 gSfxChannelLayout;
extern u16 D_801333D0; extern u16 D_801333D0;
extern Vec3f D_801333D4; extern Vec3f D_801333D4;
extern f32 D_801333E0; extern f32 D_801333E0;
extern s8 D_801333E8; extern s8 D_801333E8;
extern u8 D_801333F0; extern u8 D_801333F0;
extern u8 gAudioSEFlagSwapOff; extern u8 gAudioSfxSwapOff;
extern u8 D_801333F8; extern u8 D_801333F8;
//extern ? sSeqCmdWrPos; //extern ? sSeqCmdWrPos;
//extern ? sSeqCmdRdPos; //extern ? sSeqCmdRdPos;
@ -2818,10 +2818,10 @@ extern s16 D_80153960[];
//extern ? D_80154AE8; //extern ? D_80154AE8;
//extern ? D_80154AFC; //extern ? D_80154AFC;
//extern ? D_80154B00; //extern ? D_80154B00;
extern u8 gAudioBankTable[]; extern u8 gSoundFontTable[];
extern u8 D_80155340[]; extern u8 gSequenceFontTable[];
extern u8 gSequenceTable[]; extern u8 gSequenceTable[];
extern u8 gAudioTable[]; extern u8 gSampleBankTable[];
extern u8 D_80155F50[]; extern u8 D_80155F50[];
extern u8 D_80157580[]; extern u8 D_80157580[];
extern u8 D_801579A0[]; extern u8 D_801579A0[];
@ -3038,60 +3038,11 @@ extern SpeedMeterTimeEntry* gSpeedMeterTimeEntryPtr;
//extern ? D_8016A794; //extern ? D_8016A794;
//extern ? D_8016A7AC; //extern ? D_8016A7AC;
extern FaultThreadStruct gFaultStruct; extern FaultThreadStruct gFaultStruct;
//extern ? D_8016B5F6; extern ActiveSound gActiveSounds[7][MAX_CHANNELS_PER_BANK]; // total size = 0xA8
//extern ? D_8016B684;
//extern ? D_8016B690;
//extern ? D_8016B692;
//extern ? D_8016B6A0;
//extern ? D_8016B6B5;
//extern ? D_8016B6B8;
extern OSMesgQueue D_8016B6E0;
//extern ? D_8016B7A8;
//extern ? D_8016B7AC;
//extern ? D_8016B7B0;
//extern ? D_8016B7D8;
//extern ? D_8016B7DC;
//extern ? D_8016B7E0;
//extern ? D_8016B8B0;
//extern ? D_8016B8B1;
//extern ? D_8016B8B2;
//extern ? D_8016B8B3;
//extern ? D_8016B8B8;
//extern ? D_8016B9B8;
//extern ? D_8016B9D8;
//extern ? D_8016B9F2;
//extern ? D_8016B9F3;
//extern ? D_8016B9F4;
//extern ? D_8016B9F6;
//extern ? D_8016B9F8;
//extern ? D_8016B9F9;
//extern ? D_8016BA00;
//extern ? D_8016BA04;
//extern ? D_8016BA08;
//extern ? D_8016BA09;
//extern ? D_8016BA10;
//extern ? D_8016BA18;
//extern ? D_8016BA2E;
//extern ? D_8016BA50;
//extern ? D_8016BA70;
//extern ? D_8016BAA0;
extern SoundBankEntry D_8016BAD0[9];
extern SoundBankEntry D_8016BC80[12];
extern SoundBankEntry D_8016BEC0[22];
extern SoundBankEntry D_8016C2E0[20];
extern SoundBankEntry D_8016C6A0[8];
extern SoundBankEntry D_8016C820[3];
extern SoundBankEntry D_8016C8B0[5];
extern u8 D_8016E1A0[7];
extern u8 D_8016E1A8[7];
extern u8 D_8016E1B0[7];
extern Struct_800F7CEC D_8016E1B8[7][3]; // total size = 0xA8
extern u8 D_8016E260;
extern u8 gSoundBankMuted[]; extern u8 gSoundBankMuted[];
//extern ? D_8016E270; extern u16 gAudioSfxSwapSource[10];
extern u16 gAudioSEFlagSwapSource[10]; extern u16 gAudioSfxSwapTarget[10];
extern u16 gAudioSEFlagSwapTarget[10]; extern u8 gAudioSfxSwapMode[10];
extern u8 gAudioSEFlagSwapMode[10];
//extern ? D_8016E320; //extern ? D_8016E320;
//extern ? D_8016E348; //extern ? D_8016E348;
extern unk_D_8016E750 D_8016E750[4]; extern unk_D_8016E750 D_8016E750[4];

View file

@ -3,42 +3,68 @@
#define MK_CMD(b0,b1,b2,b3) ((((b0) & 0xFF) << 0x18) | (((b1) & 0xFF) << 0x10) | (((b2) & 0xFF) << 0x8) | (((b3) & 0xFF) << 0)) #define MK_CMD(b0,b1,b2,b3) ((((b0) & 0xFF) << 0x18) | (((b1) & 0xFF) << 0x10) | (((b2) & 0xFF) << 0x8) | (((b3) & 0xFF) << 0))
/** #define NO_LAYER ((SequenceLayer*)(-1))
* Structs in this repository have primarily been imported from the SM64 Decompilation.
* Some struct members may be wrong; the symbol '?' next to an offset means the member is a guess.
*/
#define NO_LAYER ((SequenceChannelLayer*)(-1))
#define NO_CHANNEL ((SequenceChannel*)(-1))
#define TATUMS_PER_BEAT 48 #define TATUMS_PER_BEAT 48
#define IS_SEQUENCE_CHANNEL_VALID(ptr) ((u32)(ptr) != (u32)&gAudioContext.sequenceChannelNone) #define IS_SEQUENCE_CHANNEL_VALID(ptr) ((u32)(ptr) != (u32)&gAudioContext.sequenceChannelNone)
#define ADSR_STATE_DISABLED 0 #define MAX_CHANNELS_PER_BANK 3
#define ADSR_STATE_INITIAL 1
#define ADSR_STATE_START_LOOP 2
#define ADSR_STATE_LOOP 3
#define ADSR_STATE_FADE 4
#define ADSR_STATE_HANG 5
#define ADSR_STATE_DECAY 6
#define ADSR_STATE_RELEASE 7
#define ADSR_STATE_SUSTAIN 8
#define ADSR_DISABLE 0 #define ADSR_DISABLE 0
#define ADSR_HANG -1 #define ADSR_HANG -1
#define ADSR_GOTO -2 #define ADSR_GOTO -2
#define ADSR_RESTART -3 #define ADSR_RESTART -3
#define AIBUF_LEN 0xB00 #define AIBUF_LEN 0x580
#define CODEC_ADPCM 0 typedef enum {
#define CODEC_S8 1 /* 0 */ ADSR_STATE_DISABLED,
/* 1 */ ADSR_STATE_INITIAL,
/* 2 */ ADSR_STATE_START_LOOP,
/* 3 */ ADSR_STATE_LOOP,
/* 4 */ ADSR_STATE_FADE,
/* 5 */ ADSR_STATE_HANG,
/* 6 */ ADSR_STATE_DECAY,
/* 7 */ ADSR_STATE_RELEASE,
/* 8 */ ADSR_STATE_SUSTAIN
} AdsrStatus;
typedef enum {
/* 0 */ MEDIUM_RAM,
/* 1 */ MEDIUM_UNK,
/* 2 */ MEDIUM_CART,
/* 3 */ MEDIUM_DISK_DRIVE
} SampleMedium;
typedef enum {
/* 0 */ CODEC_ADPCM,
/* 1 */ CODEC_S8,
/* 2 */ CODEC_S16_INMEMORY,
/* 3 */ CODEC_SMALL_ADPCM,
/* 4 */ CODEC_REVERB,
/* 5 */ CODEC_S16
} SampleCodec;
typedef enum {
/* 0 */ SEQUENCE_TABLE,
/* 1 */ FONT_TABLE,
/* 2 */ SAMPLE_TABLE
} SampleBankTableType;
typedef enum {
/* 0 */ CACHE_TEMPORARY,
/* 1 */ CACHE_PERSISTENT,
/* 2 */ CACHE_EITHER,
/* 3 */ CACHE_PERMANENT
} AudioCacheType;
typedef s32 (*DmaHandler)(OSPiHandle* handle, OSIoMesg* mb, s32 direction);
struct Note; struct Note;
struct NotePool; struct NotePool;
struct SequenceChannel; struct SequenceChannel;
struct SequenceChannelLayer; struct SequenceLayer;
typedef struct AudioListItem { typedef struct AudioListItem {
// A node in a circularly linked list. Each node is either a head or an item: // A node in a circularly linked list. Each node is either a head or an item:
@ -51,7 +77,7 @@ typedef struct AudioListItem {
/* 0x00 */ struct AudioListItem* prev; /* 0x00 */ struct AudioListItem* prev;
/* 0x04 */ struct AudioListItem* next; /* 0x04 */ struct AudioListItem* next;
/* 0x08 */ union { /* 0x08 */ union {
void* value; // either Note* or SequenceChannelLayer* void* value; // either Note* or SequenceLayer*
s32 count; s32 count;
} u; } u;
/* 0x0C */ struct NotePool* pool; /* 0x0C */ struct NotePool* pool;
@ -97,18 +123,18 @@ typedef struct {
typedef struct { typedef struct {
/* 0x00 */ u32 codec : 4; /* 0x00 */ u32 codec : 4;
/* 0x00 */ u32 medium : 2; /* 0x00 */ u32 medium : 2;
/* 0x00 */ u32 unk_bits26 : 1; /* 0x00 */ u32 unk_bit26 : 1;
/* 0x00 */ u32 unk_bits25 : 1; /* 0x00 */ u32 unk_bit25 : 1;
/* 0x01 */ u32 size : 24; /* 0x01 */ u32 size : 24;
/* 0x04 */ u8* sampleAddr; /* 0x04 */ u8* sampleAddr;
/* 0x08 */ AdpcmLoop* loop; /* 0x08 */ AdpcmLoop* loop;
/* 0x0C */ AdpcmBook* book; /* 0x0C */ AdpcmBook* book;
} AudioBankSample; // size = 0x10 } SoundFontSample; // size = 0x10
typedef struct { typedef struct {
/* 0x00 */ AudioBankSample* sample; /* 0x00 */ SoundFontSample* sample;
/* 0x04 */ f32 tuning; // frequency scale factor /* 0x04 */ f32 tuning; // frequency scale factor
} AudioBankSound; // size = 0x8 } SoundFontSound; // size = 0x8
typedef struct { typedef struct {
/* 0x00 */ s16 numSamplesAfterDownsampling; // never read /* 0x00 */ s16 numSamplesAfterDownsampling; // never read
@ -158,8 +184,8 @@ typedef struct {
/* 0x274 */ s16* filterRight; /* 0x274 */ s16* filterRight;
/* 0x278 */ s16* filterLeftState; /* 0x278 */ s16* filterLeftState;
/* 0x27C */ s16* filterRightState; /* 0x27C */ s16* filterRightState;
/* 0x280 */ AudioBankSound sound; /* 0x280 */ SoundFontSound sound;
/* 0x288 */ AudioBankSample sample; /* 0x288 */ SoundFontSample sample;
/* 0x298 */ AdpcmLoop loop; /* 0x298 */ AdpcmLoop loop;
} SynthesisReverb; // size = 0x2C8 } SynthesisReverb; // size = 0x2C8
@ -169,29 +195,29 @@ typedef struct {
/* 0x02 */ u8 normalRangeHi; /* 0x02 */ u8 normalRangeHi;
/* 0x03 */ u8 releaseRate; /* 0x03 */ u8 releaseRate;
/* 0x04 */ AdsrEnvelope* envelope; /* 0x04 */ AdsrEnvelope* envelope;
/* 0x08 */ AudioBankSound lowNotesSound; /* 0x08 */ SoundFontSound lowNotesSound;
/* 0x10 */ AudioBankSound normalNotesSound; /* 0x10 */ SoundFontSound normalNotesSound;
/* 0x18 */ AudioBankSound highNotesSound; /* 0x18 */ SoundFontSound highNotesSound;
} Instrument; // size = 0x20 } Instrument; // size = 0x20
typedef struct { typedef struct {
/* 0x00 */ u8 releaseRate; /* 0x00 */ u8 releaseRate;
/* 0x01 */ u8 pan; /* 0x01 */ u8 pan;
/* 0x02 */ u8 loaded; /* 0x02 */ u8 loaded;
/* 0x04 */ AudioBankSound sound; /* 0x04 */ SoundFontSound sound;
/* 0x14 */ AdsrEnvelope* envelope; /* 0x14 */ AdsrEnvelope* envelope;
} Drum; // size = 0x14 } Drum; // size = 0x14
typedef struct { typedef struct {
/* 0x00 */ u8 numInstruments; /* 0x00 */ u8 numInstruments;
/* 0x01 */ u8 numDrums; /* 0x01 */ u8 numDrums;
/* 0x02 */ u8 unk_02; /* 0x02 */ u8 sampleBankId1;
/* 0x03 */ u8 unk_03; /* 0x03 */ u8 sampleBankId2;
/* 0x04 */ u16 numSfx; /* 0x04 */ u16 numSfx;
/* 0x08 */ Instrument** instruments; /* 0x08 */ Instrument** instruments;
/* 0x0C */ Drum** drums; /* 0x0C */ Drum** drums;
/* 0x10 */ AudioBankSound* soundEffects; /* 0x10 */ SoundFontSound* soundEffects;
} CtlEntry; // size = 0x14 } SoundFont; // size = 0x14
typedef struct { typedef struct {
/* 0x00 */ u8* pc; /* 0x00 */ u8* pc;
@ -199,7 +225,7 @@ typedef struct {
/* 0x14 */ u8 remLoopIters[4]; /* 0x14 */ u8 remLoopIters[4];
/* 0x18 */ u8 depth; /* 0x18 */ u8 depth;
/* 0x19 */ s8 value; /* 0x19 */ s8 value;
} M64ScriptState; // size = 0x1C } SeqScriptState; // size = 0x1C
// Also known as a Group, according to debug strings. // Also known as a Group, according to debug strings.
typedef struct { typedef struct {
@ -207,17 +233,17 @@ typedef struct {
/* 0x000 */ u8 finished : 1; /* 0x000 */ u8 finished : 1;
/* 0x000 */ u8 muted : 1; /* 0x000 */ u8 muted : 1;
/* 0x000 */ u8 seqDmaInProgress : 1; /* 0x000 */ u8 seqDmaInProgress : 1;
/* 0x000 */ u8 bankDmaInProgress : 1; /* 0x000 */ u8 fontDmaInProgress : 1;
/*?0x000 */ u8 recalculateVolume : 1; /* 0x000 */ u8 recalculateVolume : 1;
/* 0x000 */ u8 unk_0b2 : 1; /* 0x000 */ u8 stopScript : 1;
/* 0x000 */ u8 unk_0b1 : 1; /* 0x000 */ u8 unk_0b1 : 1;
/* 0x001 */ u8 state; /* 0x001 */ u8 state;
/* 0x002 */ u8 noteAllocPolicy; /* 0x002 */ u8 noteAllocPolicy;
/* 0x003 */ u8 muteBehavior; /* 0x003 */ u8 muteBehavior;
/* 0x004 */ u8 seqId; /* 0x004 */ u8 seqId;
/* 0x005 */ u8 defaultBank; /* 0x005 */ u8 defaultFont;
/* 0x006 */ u8 unk_06[1]; /* 0x006 */ u8 unk_06[1];
/* 0x007 */ s8 playerIndex; /* 0x007 */ s8 playerIdx;
/* 0x008 */ u16 tempo; // tatums per minute /* 0x008 */ u16 tempo; // tatums per minute
/* 0x00A */ u16 tempoAcc; /* 0x00A */ u16 tempoAcc;
/* 0x00C */ u16 unk_0C; /* 0x00C */ u16 unk_0C;
@ -234,23 +260,14 @@ typedef struct {
/* 0x030 */ f32 appliedFadeVolume; /* 0x030 */ f32 appliedFadeVolume;
/* 0x034 */ f32 unk_34; /* 0x034 */ f32 unk_34;
/* 0x038 */ struct SequenceChannel* channels[16]; /* 0x038 */ struct SequenceChannel* channels[16];
/* 0x078 */ M64ScriptState scriptState; /* 0x078 */ SeqScriptState scriptState;
/* 0x094 */ u8* shortNoteVelocityTable; /* 0x094 */ u8* shortNoteVelocityTable;
/* 0x098 */ u8* shortNoteDurationTable; /* 0x098 */ u8* shortNoteGateTimeTable;
/* 0x09C */ NotePool notePool; /* 0x09C */ NotePool notePool;
/* 0x0DC */ s32 unk_DC; /* 0x0DC */ s32 skipTicks;
/* 0x0E0 */ u32 unk_E0; /* 0x0E0 */ u32 scriptCounter;
/* 0x0E4 */ u8 pad_E4[0x10]; // OSMesgQueue seqDmaMesgQueue; /* 0x0E4 */ char unk_E4[0x74]; // unused struct members for sequence/sound font dma management, according to sm64 decomp
/*?0x0F4 */ OSMesg seqDmaMesg; /* 0x158 */ s8 soundScriptIO[8];
/*?0x0F8 */ OSIoMesg seqDmaIoMesg;
/*?0x110 */ OSMesgQueue bankDmaMesgQueue;
/*?0x128 */ OSMesg bankDmaMesg;
/*?0x12C */ OSIoMesg bankDmaIoMesg;
/*?0x144 */ u8* bankDmaCurrMemAddr;
/*?0x148 */ u32 bankDmaCurrDevAddr;
/*?0x14C */ s32 bankDmaRemaining;
/* */ u8 pad_150[8];
/* 0x158 */ s8 unk_158[8]; // "port" according to debug strings. seqVariationEu? soundScriptIO?
} SequencePlayer; // size = 0x160 } SequencePlayer; // size = 0x160
typedef struct { typedef struct {
@ -282,8 +299,7 @@ typedef struct {
} AdsrState; } AdsrState;
typedef struct { typedef struct {
/* 0x00 */ u8 bit0 : 1; // unused? /* 0x00 */ u8 unused : 2;
/* 0x00 */ u8 bit1 : 1; // unused?
/* 0x00 */ u8 bit2 : 2; /* 0x00 */ u8 bit2 : 2;
/* 0x00 */ u8 strongRight : 1; /* 0x00 */ u8 strongRight : 1;
/* 0x00 */ u8 strongLeft : 1; /* 0x00 */ u8 strongLeft : 1;
@ -309,13 +325,12 @@ typedef struct {
/* 0x14 */ s16 filterBuf[8]; /* 0x14 */ s16 filterBuf[8];
} NoteAttributes; // size = 0x24 } NoteAttributes; // size = 0x24
// Also known as a SubTrack, according to debug strings. // Also known as a SubTrack, according to sm64 debug strings.
// Confusingly, a SubTrack is a container of Tracks.
typedef struct SequenceChannel { typedef struct SequenceChannel {
/* 0x00 */ u8 enabled : 1; /* 0x00 */ u8 enabled : 1;
/* 0x00 */ u8 finished : 1; /* 0x00 */ u8 finished : 1;
/* 0x00 */ u8 stopScript : 1; /* 0x00 */ u8 stopScript : 1;
/* 0x00 */ u8 stopSomething2 : 1; // sets SequenceChannelLayer.stopSomething /* 0x00 */ u8 stopSomething2 : 1; // sets SequenceLayer.stopSomething
/* 0x00 */ u8 hasInstrument : 1; /* 0x00 */ u8 hasInstrument : 1;
/* 0x00 */ u8 stereoHeadsetEffects : 1; /* 0x00 */ u8 stereoHeadsetEffects : 1;
/* 0x00 */ u8 largeNotes : 1; // notes specify duration and velocity /* 0x00 */ u8 largeNotes : 1; // notes specify duration and velocity
@ -333,14 +348,14 @@ typedef struct SequenceChannel {
/* 0x04 */ u8 reverb; // or dry/wet mix /* 0x04 */ u8 reverb; // or dry/wet mix
/* 0x05 */ u8 notePriority; // 0-3 /* 0x05 */ u8 notePriority; // 0-3
/* 0x06 */ u8 someOtherPriority; /* 0x06 */ u8 someOtherPriority;
/* 0x07 */ u8 bankId; /* 0x07 */ u8 fontId;
/* 0x08 */ u8 reverbIndex; /* 0x08 */ u8 reverbIndex;
/* 0x09 */ u8 bookOffset; /* 0x09 */ u8 bookOffset;
/* 0x0A */ u8 newPan; /* 0x0A */ u8 newPan;
/* 0x0B */ u8 panChannelWeight; // proportion of pan that comes from the channel (0..128) /* 0x0B */ u8 panChannelWeight; // proportion of pan that comes from the channel (0..128)
/* 0x0C */ u8 unk_0C; /* 0x0C */ u8 unk_0C;
/* 0x0D */ u8 velocityRandomVariance; /* 0x0D */ u8 velocityRandomVariance;
/* 0x0E */ u8 durationRandomVariance; /* 0x0E */ u8 gateTimeRandomVariance;
/* 0x0F */ u8 unk_0F; /* 0x0F */ u8 unk_0F;
/* 0x10 */ u16 vibratoRateStart; /* 0x10 */ u16 vibratoRateStart;
/* 0x12 */ u16 vibratoExtentStart; /* 0x12 */ u16 vibratoExtentStart;
@ -362,20 +377,20 @@ typedef struct SequenceChannel {
/* 0x38 */ f32 freqScale; /* 0x38 */ f32 freqScale;
/* 0x3C */ u8 (*dynTable)[][2]; /* 0x3C */ u8 (*dynTable)[][2];
/* 0x40 */ struct Note* noteUnused; /* 0x40 */ struct Note* noteUnused;
/* 0x44 */ struct SequenceChannelLayer* layerUnused; /* 0x44 */ struct SequenceLayer* layerUnused;
/* 0x48 */ Instrument* instrument; /* 0x48 */ Instrument* instrument;
/* 0x4C */ SequencePlayer* seqPlayer; /* 0x4C */ SequencePlayer* seqPlayer;
/* 0x50 */ struct SequenceChannelLayer* layers[4]; /* 0x50 */ struct SequenceLayer* layers[4];
/* 0x60 */ M64ScriptState scriptState; /* 0x60 */ SeqScriptState scriptState;
/* 0x7C */ AdsrSettings adsr; /* 0x7C */ AdsrSettings adsr;
/* 0x84 */ NotePool notePool; /* 0x84 */ NotePool notePool;
/* 0xC4 */ s8 soundScriptIO[8]; // bridge between sound script and audio lib /* 0xC4 */ s8 soundScriptIO[8]; // bridge between sound script and audio lib, "io ports"
/* 0xCC */ s16* filter; /* 0xCC */ s16* filter;
/* 0xD0 */ Stereo stereo; /* 0xD0 */ Stereo stereo;
} SequenceChannel; // size = 0xD4 } SequenceChannel; // size = 0xD4
// Also known as a Track, according to debug strings. // Might also be known as a Track, according to sm64 debug strings (?).
typedef struct SequenceChannelLayer { typedef struct SequenceLayer {
/* 0x00 */ u8 enabled : 1; /* 0x00 */ u8 enabled : 1;
/* 0x00 */ u8 finished : 1; /* 0x00 */ u8 finished : 1;
/* 0x00 */ u8 stopSomething : 1; /* 0x00 */ u8 stopSomething : 1;
@ -386,20 +401,20 @@ typedef struct SequenceChannelLayer {
/* 0x00 */ u8 notePropertiesNeedInit : 1; /* 0x00 */ u8 notePropertiesNeedInit : 1;
/* 0x01 */ Stereo stereo; /* 0x01 */ Stereo stereo;
/* 0x02 */ u8 instOrWave; /* 0x02 */ u8 instOrWave;
/* 0x03 */ u8 noteDuration; /* 0x03 */ u8 gateTime;
/* 0x04 */ u8 semitone; /* 0x04 */ u8 semitone;
/* 0x05 */ u8 portamentoTargetNote; /* 0x05 */ u8 portamentoTargetNote;
/* 0x06 */ u8 pan; // 0..128 /* 0x06 */ u8 pan; // 0..128
/* 0x07 */ u8 notePan; /* 0x07 */ u8 notePan;
/* 0x08 */ s16 delay; /* 0x08 */ s16 delay;
/* 0x0A */ s16 duration; /* 0x0A */ s16 gateDelay;
/* 0x0C */ s16 delay2; /* 0x0C */ s16 delay2;
/* 0x0E */ u16 portamentoTime; /* 0x0E */ u16 portamentoTime;
/* 0x10 */ s16 transposition; // #semitones added to play commands /* 0x10 */ s16 transposition; // #semitones added to play commands
// (m64 instruction encoding only allows referring to the limited range // (seq instruction encoding only allows referring to the limited range
// 0..0x3F; this makes 0x40..0x7F accessible as well) // 0..0x3F; this makes 0x40..0x7F accessible as well)
/* 0x12 */ s16 shortNoteDefaultPlayPercentage; /* 0x12 */ s16 shortNoteDefaultDelay;
/* 0x14 */ s16 playPercentage; /* 0x14 */ s16 lastDelay;
/* 0x18 */ AdsrSettings adsr; /* 0x18 */ AdsrSettings adsr;
/* 0x20 */ Portamento portamento; /* 0x20 */ Portamento portamento;
/* 0x2C */ struct Note* note; /* 0x2C */ struct Note* note;
@ -410,11 +425,11 @@ typedef struct SequenceChannelLayer {
/* 0x40 */ f32 noteVelocity; /* 0x40 */ f32 noteVelocity;
/* 0x44 */ f32 noteFreqScale; /* 0x44 */ f32 noteFreqScale;
/* 0x48 */ Instrument* instrument; /* 0x48 */ Instrument* instrument;
/* 0x4C */ AudioBankSound* sound; /* 0x4C */ SoundFontSound* sound;
/* 0x50 */ SequenceChannel* seqChannel; /* 0x50 */ SequenceChannel* channel;
/* 0x54 */ M64ScriptState scriptState; /* 0x54 */ SeqScriptState scriptState;
/* 0x70 */ AudioListItem listItem; /* 0x70 */ AudioListItem listItem;
} SequenceChannelLayer; // size = 0x80 } SequenceLayer; // size = 0x80
typedef struct { typedef struct {
/* 0x0000 */ s16 adpcmdecState[0x10]; /* 0x0000 */ s16 adpcmdecState[0x10];
@ -431,7 +446,7 @@ typedef struct {
/* 0x02 */ u8 prevHeadsetPanRight; /* 0x02 */ u8 prevHeadsetPanRight;
/* 0x03 */ u8 prevHeadsetPanLeft; /* 0x03 */ u8 prevHeadsetPanLeft;
/* 0x04 */ u8 reverbVol; /* 0x04 */ u8 reverbVol;
/* 0x05 */ u8 numAdpcmParts; /* 0x05 */ u8 numParts;
/* 0x06 */ u16 samplePosFrac; /* 0x06 */ u16 samplePosFrac;
/* 0x08 */ s32 samplePosInt; /* 0x08 */ s32 samplePosInt;
/* 0x0C */ NoteSynthesisBuffers* synthesisBuffers; /* 0x0C */ NoteSynthesisBuffers* synthesisBuffers;
@ -446,7 +461,7 @@ typedef struct {
} NoteSynthesisState; // size = 0x20 } NoteSynthesisState; // size = 0x20
typedef struct { typedef struct {
/* 0x00 */ struct SequenceChannel* seqChannel; /* 0x00 */ struct SequenceChannel* channel;
/* 0x04 */ u32 time; /* 0x04 */ u32 time;
/* 0x08 */ s16* curve; /* 0x08 */ s16* curve;
/* 0x0C */ f32 extent; /* 0x0C */ f32 extent;
@ -461,44 +476,37 @@ typedef struct {
/* 0x00 */ u8 priority; /* 0x00 */ u8 priority;
/* 0x01 */ u8 waveId; /* 0x01 */ u8 waveId;
/* 0x02 */ u8 sampleCountIndex; /* 0x02 */ u8 sampleCountIndex;
/* 0x03 */ u8 bankId; /* 0x03 */ u8 fontId;
/* 0x04 */ u8 unk_04; /* 0x04 */ u8 unk_04;
/* 0x05 */ u8 stereoHeadsetEffects; /* 0x05 */ u8 stereoHeadsetEffects;
/* 0x06 */ s16 adsrVolScale; // unused? /* 0x06 */ s16 adsrVolScaleUnused;
/* 0x08 */ f32 portamentoFreqScale; /* 0x08 */ f32 portamentoFreqScale;
/* 0x0C */ f32 vibratoFreqScale; /* 0x0C */ f32 vibratoFreqScale;
/* 0x10 */ SequenceChannelLayer* prevParentLayer; /* 0x10 */ SequenceLayer* prevParentLayer;
/* 0x14 */ SequenceChannelLayer* parentLayer; /* 0x14 */ SequenceLayer* parentLayer;
/* 0x18 */ SequenceChannelLayer* wantedParentLayer; /* 0x18 */ SequenceLayer* wantedParentLayer;
/* 0x1C */ NoteAttributes attributes; /* 0x1C */ NoteAttributes attributes;
/* 0x40 */ AdsrState adsr; /* 0x40 */ AdsrState adsr;
// may contain portamento, vibratoState, if those are not part of Note itself // may contain portamento, vibratoState, if those are not part of Note itself
} NotePlaybackState; } NotePlaybackState;
typedef struct { typedef struct {
// these bitfields should perhaps be merged into a single struct
union {
struct { struct {
/* 0x00 */ vu8 enabled : 1; /* 0x00 */ volatile u8 enabled : 1;
/* 0x00 */ u8 needsInit : 1; /* 0x00 */ u8 needsInit : 1;
/*?0x00 */ u8 finished : 1; /* 0x00 */ u8 finished : 1; // ?
/* 0x00 */ u8 unused : 1; /* 0x00 */ u8 unused : 1;
/* 0x00 */ u8 stereoStrongRight : 1; /* 0x00 */ u8 stereoStrongRight : 1;
/* 0x00 */ u8 stereoStrongLeft : 1; /* 0x00 */ u8 stereoStrongLeft : 1;
/* 0x00 */ u8 stereoHeadsetEffects : 1; /* 0x00 */ u8 stereoHeadsetEffects : 1;
/*?0x00 */ u8 usesHeadsetPanEffects : 1; /* 0x00 */ u8 usesHeadsetPanEffects : 1; // ?
} s;
/* 0x00 */ u8 asByte; // likely does not exist
} bitField0; } bitField0;
union {
struct { struct {
/* 0x01 */ u8 reverbIndex : 3; /* 0x01 */ u8 reverbIndex : 3;
/* 0x01 */ u8 bookOffset : 2; /* 0x01 */ u8 bookOffset : 2;
/* 0x01 */ u8 isSyntheticWave : 1; /* 0x01 */ u8 isSyntheticWave : 1;
/* 0x01 */ u8 hasTwoAdpcmParts : 1; /* 0x01 */ u8 hasTwoParts : 1;
/* 0x01 */ u8 usesHeadsetPanEffects2 : 1; /* 0x01 */ u8 usesHeadsetPanEffects2 : 1;
} s;
/* 0x01 */ u8 asByte; // likely does not exist
} bitField1; } bitField1;
/* 0x02 */ u8 unk_2; /* 0x02 */ u8 unk_2;
/* 0x03 */ u8 headsetPanRight; /* 0x03 */ u8 headsetPanRight;
@ -511,7 +519,7 @@ typedef struct {
/* 0x0C */ u16 resamplingRateFixedPoint; /* 0x0C */ u16 resamplingRateFixedPoint;
/* 0x0E */ u16 unk_0E; /* 0x0E */ u16 unk_0E;
/* 0x10 */ union { /* 0x10 */ union {
AudioBankSound* audioBankSound; SoundFontSound* soundFontSound;
s16* samples; // used for synthetic waves s16* samples; // used for synthetic waves
} sound; } sound;
/* 0x14 */ s16* filter; /* 0x14 */ s16* filter;
@ -540,30 +548,30 @@ typedef struct {
/* 0x0E */ u16 leakLtr; /* 0x0E */ u16 leakLtr;
/* 0x10 */ s8 unk_10; /* 0x10 */ s8 unk_10;
/* 0x12 */ u16 unk_12; /* 0x12 */ u16 unk_12;
/* 0x14 */ s16 unk_14; /* 0x14 */ s16 lowPassFilterCutoffLeft;
/* 0x16 */ s16 unk_16; /* 0x16 */ s16 lowPassFilterCutoffRight;
} ReverbSettings; // size = 0x18 } ReverbSettings; // size = 0x18
typedef struct { typedef struct {
/* 0x00 */ u32 frequency; /* 0x00 */ u32 frequency;
/* 0x04 */ u8 unk_04; /* 0x04 */ u8 unk_04;
/* 0x05 */ u8 maxSimultaneousNotes; /* 0x05 */ u8 numNotes;
/* 0x06 */ u8 numSequencePlayers; /* 0x06 */ u8 numSequencePlayers;
/* 0x07 */ u8 unk_07[0x2]; /* 0x07 */ u8 unk_07; // unused, set to zero
/* 0x08 */ u8 unk_08; // unused, set to zero
/* 0x09 */ u8 numReverbs; /* 0x09 */ u8 numReverbs;
/* 0x0A */ u8 unk_0A[0x2];
/* 0x0C */ ReverbSettings* reverbSettings; /* 0x0C */ ReverbSettings* reverbSettings;
/* 0x10 */ u16 unk_10; /* 0x10 */ u16 sampleDmaBufSize1;
/* 0x12 */ u16 unk_12; /* 0x12 */ u16 sampleDmaBufSize2;
/* 0x14 */ u16 unk_14; /* 0x14 */ u16 unk_14;
/* 0x18 */ u32 persistentSeqMem; /* 0x18 */ u32 persistentSeqMem;
/* 0x1C */ u32 persistentBankMem; /* 0x1C */ u32 persistentFontMem;
/* 0x20 */ u32 persistentUnusedMem; /* 0x20 */ u32 persistentSampleMem;
/* 0x24 */ u32 temporarySeqMem; /* 0x24 */ u32 temporarySeqMem;
/* 0x28 */ u32 temporaryBankMem; /* 0x28 */ u32 temporaryFontMem;
/* 0x2C */ u32 temporaryUnusedMem; /* 0x2C */ u32 temporarySampleMem;
/* 0x30 */ s32 unk_30; /* 0x30 */ s32 persistentSampleCacheMem;
/* 0x34 */ s32 unk_34; /* 0x34 */ s32 temporarySampleCacheMem;
} AudioSpec; // size = 0x38 } AudioSpec; // size = 0x38
typedef struct { typedef struct {
@ -588,52 +596,49 @@ typedef struct {
/* 0x0 */ u8* start; /* 0x0 */ u8* start;
/* 0x4 */ u8* cur; /* 0x4 */ u8* cur;
/* 0x8 */ s32 size; /* 0x8 */ s32 size;
/* 0xC */ s32 unused; // set to 0, never read /* 0xC */ s32 count;
} SoundAllocPool; // size = 0x10 } AudioAllocPool; // size = 0x10
typedef struct { typedef struct {
/* 0x0 */ u8* ptr; /* 0x0 */ u8* ptr;
/* 0x4 */ u32 size; /* 0x4 */ u32 size;
/* 0x8 */ s16 poolIndex; /* 0x8 */ s16 tableType;
/* 0xA */ s16 id; // seqId or bankId /* 0xA */ s16 id;
} SeqOrBankEntry; // size = 0xC } AudioCacheEntry; // size = 0xC
typedef struct { typedef struct {
/* 0x00 */ s8 unk_00; /* 0x00 */ s8 inUse;
/* 0x01 */ s8 unk_01; /* 0x01 */ s8 origMedium;
/* 0x02 */ s8 unk_02; /* 0x02 */ s8 sampleBankId;
/* 0x03 */ char unk_03[0x5]; /* 0x03 */ char unk_03[0x5];
/* 0x08 */ u8* unk_08; /* 0x08 */ u8* allocatedAddr;
/* 0x0C */ void* unk_0C; /* 0x0C */ void* sampleAddr;
/* 0x10 */ u32 size; /* 0x10 */ u32 size;
} UnkHeapEntry; // size = 0x14 } SampleCacheEntry; // size = 0x14
typedef struct { typedef struct {
/* 0x000 */ SoundAllocPool pool; /* 0x000 */ AudioAllocPool pool;
/* 0x010 */ UnkHeapEntry entries[32]; /* 0x010 */ SampleCacheEntry entries[32];
/* 0x290 */ s32 size; /* 0x290 */ s32 size;
} UnkPool; // size = 0x294 } AudioSampleCache; // size = 0x294
typedef struct typedef struct {
{
/* 0x00*/ u32 numEntries; /* 0x00*/ u32 numEntries;
/* 0x04*/ SoundAllocPool pool; /* 0x04*/ AudioAllocPool pool;
/* 0x14*/ SeqOrBankEntry entries[16]; /* 0x14*/ AudioCacheEntry entries[16];
} PersistentPool; // size = 0xD4 } AudioPersistentCache; // size = 0xD4
typedef struct typedef struct {
{
/* 0x00*/ u32 nextSide; /* 0x00*/ u32 nextSide;
/* 0x04*/ SoundAllocPool pool; /* 0x04*/ AudioAllocPool pool;
/* 0x14*/ SeqOrBankEntry entries[2]; /* 0x14*/ AudioCacheEntry entries[2];
} TemporaryPool; // size = 0x3C } AudioTemporaryCache; // size = 0x3C
typedef struct typedef struct {
{ /* 0x000*/ AudioPersistentCache persistent;
/* 0x000*/ PersistentPool persistent; /* 0x0D4*/ AudioTemporaryCache temporary;
/* 0x0D4*/ TemporaryPool temporary;
/* 0x100*/ u8 unk_100[0x10]; /* 0x100*/ u8 unk_100[0x10];
} SoundMultiPool; // size = 0x110 } AudioCache; // size = 0x110
typedef struct { typedef struct {
u32 wantPersistent; u32 wantPersistent;
@ -642,40 +647,24 @@ typedef struct {
typedef struct { typedef struct {
u32 wantSeq; u32 wantSeq;
u32 wantBank; u32 wantFont;
u32 wantUnused; u32 wantSample;
} AudioPoolSplit3; // size = 0xC } AudioPoolSplit3; // size = 0xC
typedef struct { typedef struct {
u32 wantSeq; u32 wantSeq;
u32 wantBank; u32 wantFont;
u32 wantUnused; u32 wantSample;
u32 wantCustom; u32 wantCustom;
} AudioPoolSplit4; // size = 0x10 } AudioPoolSplit4; // size = 0x10
typedef struct {
u8* unk_0;
u8* unk_4;
u32 unk_8;
s8 unk_C;
s8 unk_D;
s16 unk_E;
} Struct_800E0E0C_2;
typedef struct {
char unk_00[0x2];
s16 unk_02;
char unk_04[0x8];
Struct_800E0E0C_2 unk_C[1]; // unknown size
} ManyStruct_800E0E0C_2;
typedef struct { typedef struct {
/* 0x00 */ u32 endAndMediumKey; /* 0x00 */ u32 endAndMediumKey;
/* 0x04 */ AudioBankSample* sample; /* 0x04 */ SoundFontSample* sample;
/* 0x08 */ u8* ramAddr; /* 0x08 */ u8* ramAddr;
/* 0x0C */ u32 encodedInfo; /* 0x0C */ u32 encodedInfo;
/* 0x10 */ s32 isFree; /* 0x10 */ s32 isFree;
} AudioStruct0D68; // size = 0x14 } AudioPreloadReq; // size = 0x14
typedef struct { typedef struct {
union{ union{
@ -698,111 +687,56 @@ typedef struct {
}; };
} AudioCmd; } AudioCmd;
typedef struct {
union{
struct {
s16 unk_00;
u16 unk_02;
};
u32 unk_00w;
};
u32 unk_04;
s8 unk_08;
char unk_09[0x7];
} unk_dma_s;
#define MK_ASYNC_MSG(b0,b1,b2,b3)(((b0) << 0x18) | ((b1) << 0x10) | ((b2) << 0x08) | ((b3) << 0x00))
#define ASYNC_TBLTYPE(v)((u8)(v >> 0x10))
#define ASYNC_B2(v)((u8)(v >> 0x08))
#define ASYNC_B3(v)((u8)(v >> 0x00))
#define AYSNC_B0(v)(((u8)(v >> 0x18))
typedef struct { typedef struct {
/* 0x00 */ s8 status; /* 0x00 */ s8 status;
/* 0x01 */ s8 unk_01; /* 0x01 */ s8 delay;
/* 0x02 */ s8 unk_02; // type? /* 0x02 */ s8 medium;
/* 0x03 */ char unk_03[0x1]; /* 0x04 */ u8* ramAddr;
/* 0x04 */ u32 unk_04; /* 0x08 */ u32 curDevAddr;
/* 0x08 */ u32 devAddr; /* 0x0C */ u8* curRamAddr;
/* 0x0C */ u8* ramAddr;
/* 0x10 */ u32 bytesRemaining; /* 0x10 */ u32 bytesRemaining;
/* 0x14 */ u32 chunkSize; /* 0x14 */ u32 chunkSize;
/* 0x18 */ s32 unk_18; /* 0x18 */ s32 unkMediumParam;
/* 0x1C */ u32 retMsg; /* 0x1C */ u32 retMsg;
/* 0x20 */ OSMesgQueue* retQueue; /* 0x20 */ OSMesgQueue* retQueue;
/* 0x24 */ OSMesgQueue msgQueue; /* 0x24 */ OSMesgQueue msgQueue;
/* 0x3C */ OSMesg msg; /* 0x3C */ OSMesg msg;
/* 0x40 */ OSIoMesg ioMesg; /* 0x40 */ OSIoMesg ioMesg;
} AsyncLoadReq; // size = 0x58 } AudioAsyncLoad; // size = 0x58
typedef struct { typedef struct {
/* 0x00 */ u8 unk_00; /* 0x00 */ u8 medium;
/* 0x01 */ u8 unk_01; /* 0x01 */ u8 seqOrFontId;
/* 0x02 */ u16 unk_02; /* 0x02 */ u16 instId;
/* 0x04 */ s32 unk_04; /* 0x04 */ s32 unkMediumParam;
/* 0x08 */ s32 devAddr; /* 0x08 */ s32 curDevAddr;
/* 0x0C */ u8* ramAddr; /* 0x0C */ u8* curRamAddr;
/* 0x10 */ u8* unk_10; /* 0x10 */ u8* ramAddr;
/* 0x14 */ s32 status; /* 0x14 */ s32 status;
/* 0x18 */ s32 size; /* 0x18 */ s32 bytesRemaining;
/* 0x1C */ s8* isDone; /* 0x1C */ s8* isDone;
/* 0x20 */ AudioBankSample sample; /* 0x20 */ SoundFontSample sample;
/* 0x30 */ OSMesgQueue msgqueue; /* 0x30 */ OSMesgQueue msgqueue;
/* 0x48 */ OSMesg msg; /* 0x48 */ OSMesg msg;
/* 0x4C */ OSIoMesg ioMesg; /* 0x4C */ OSIoMesg ioMesg;
} AudioSyncLoad; // size = 0x64 } AudioSlowLoad; // size = 0x64
typedef struct {
u16 offsets[18];
char data[1];
} unk_283C;
typedef struct {
/* 0x00 */ s16 entryCnt;
/* 0x02 */ s16 unk_02;
/* 0x04 */ u32 romAddr;
/* 0x08 */ char pad[0x8];
} AudioTableHeader; // size = 0x10
typedef struct { typedef struct {
/* 0x00 */ u32 romAddr; /* 0x00 */ u32 romAddr;
/* 0x04 */ u32 size; /* 0x04 */ u32 size;
/* 0x08 */ s8 unk_08; /* 0x08 */ s8 medium;
/* 0x09 */ s8 type; /* 0x09 */ s8 cachePolicy;
/* 0x0A */ char pad[6]; /* 0x0A */ s16 shortData1;
} SequenceTableEntry; // size = 0x10 /* 0x0C */ s16 shortData2;
/* 0x0E */ s16 shortData3;
typedef struct {
/* 0x00 */ u32 romAddr;
/* 0x04 */ u32 size;
/* 0x08 */ u8 unk_08;
/* 0x09 */ u8 unk_09;
/* 0x0A */ s16 unk_0A;
/* 0x0C */ s16 unk_0C;
/* 0x0E */ s16 unk_0E;
} AudioBankTableEntry; // size = 0x10
typedef struct {
/* 0x00 */ u32 romAddr;
/* 0x04 */ u32 size;
/* 0x08 */ s8 unk_08;
/* 0x09 */ s8 unk_09;
/* 0x0A */ char pad[6];
} AudioTableEntry; // size = 0x10 } AudioTableEntry; // size = 0x10
typedef struct { typedef struct {
/* 0x00 */ AudioTableHeader header; /* 0x00 */ s16 numEntries;
/* 0x10 */ SequenceTableEntry entries[1]; /* 0x02 */ s16 unkMediumParam;
} SequenceTable; // size >= 0x20 /* 0x04 */ u32 romAddr;
/* 0x08 */ char pad[0x8];
typedef struct { /* 0x10 */ AudioTableEntry entries[1]; // (dynamic size)
/* 0x00 */ AudioTableHeader header;
/* 0x10 */ AudioBankTableEntry entries[1];
} AudioBankTable; // size >= 0x20
typedef struct {
/* 0x00 */ AudioTableHeader header;
/* 0x10 */ AudioTableEntry entries[1];
} AudioTable; // size >= 0x20 } AudioTable; // size >= 0x20
typedef struct { typedef struct {
@ -820,22 +754,7 @@ typedef struct {
/* 0x0C */ u8 unused; /* 0x0C */ u8 unused;
/* 0x0D */ u8 reuseIndex; // position in sSampleDmaReuseQueue1/2, if ttl == 0 /* 0x0D */ u8 reuseIndex; // position in sSampleDmaReuseQueue1/2, if ttl == 0
/* 0x0E */ u8 ttl; // duration after which the DMA can be discarded /* 0x0E */ u8 ttl; // duration after which the DMA can be discarded
} SampleDmaReq; // size = 0x10 } SampleDma; // size = 0x10
typedef struct {
/* 0x00 */ s32 index1;
/* 0x04 */ s32 index2;
/* 0x08 */ s32 baseAddr1;
/* 0x0C */ s32 baseAddr2;
/* 0x10 */ u32 medium1;
/* 0x14 */ u32 medium2;
} RelocInfo; // size = 0x18
typedef enum {
/* 0 */ SEQUENCE_TABLE,
/* 1 */ BANK_TABLE,
/* 2 */ AUDIO_TABLE
} AudioTableType;
typedef struct { typedef struct {
/* 0x0000 */ char unk_0000; /* 0x0000 */ char unk_0000;
@ -847,56 +766,52 @@ typedef struct {
/* 0x0014 */ NoteSubEu* noteSubsEu; /* 0x0014 */ NoteSubEu* noteSubsEu;
/* 0x0018 */ SynthesisReverb synthesisReverbs[4]; /* 0x0018 */ SynthesisReverb synthesisReverbs[4];
/* 0x0B38 */ char unk_0B38[0x30]; /* 0x0B38 */ char unk_0B38[0x30];
/* 0x0B68 */ AudioBankSample* unk_0B68[128]; /* 0x0B68 */ SoundFontSample* usedSamples[128];
/* 0x0D68 */ AudioStruct0D68 unk_0D68[128]; /* 0x0D68 */ AudioPreloadReq preloadSampleStack[128];
/* 0x1768 */ s32 unk_1768; /* 0x1768 */ s32 numUsedSamples;
/* 0x176C */ s32 unk_176C; /* 0x176C */ s32 preloadSampleStackTop;
/* 0x1770 */ AsyncLoadReq asyncReqs[0x10]; /* 0x1770 */ AudioAsyncLoad asyncLoads[0x10];
/* 0x1CF0 */ OSMesgQueue asyncLoadQueue; /* 0x1CF0 */ OSMesgQueue asyncLoadUnkMediumQueue;
/* 0x1D08 */ char unk_1D08[0x40]; /* 0x1D08 */ char unk_1D08[0x40];
/* 0x1D48 */ AsyncLoadReq* curAsyncReq; /* 0x1D48 */ AudioAsyncLoad* curUnkMediumLoad;
/* 0x1D4C */ u32 syncLoadPos; /* 0x1D4C */ u32 slowLoadPos;
/* 0x1D50 */ AudioSyncLoad syncLoads[2]; /* 0x1D50 */ AudioSlowLoad slowLoads[2];
/* 0x1E18 */ OSPiHandle* cartHandle; /* 0x1E18 */ OSPiHandle* cartHandle;
/* probably an unused PI handle for n64 disk drive */ /* 0x1E1C */ OSPiHandle* driveHandle;
/* 0x1E1C */ OSPiHandle* unk_1E1C; /* 0x1E20 */ OSMesgQueue externalLoadQueue;
/* 0x1E20 */ OSMesgQueue unk_1E20; /* 0x1E38 */ OSMesg externalLoadMesgBuf[0x10];
/* 0x1E38 */ OSMesg unk_1E38[0x10]; /* 0x1E78 */ OSMesgQueue preloadSampleQueue;
/* 0x1E78 */ OSMesgQueue unk_1E78; /* 0x1E90 */ OSMesg preloadSampleMesgBuf[0x10];
/* 0x1E90 */ OSMesg unk_1E90[0x10];
/* 0x1ED0 */ OSMesgQueue currAudioFrameDmaQueue; /* 0x1ED0 */ OSMesgQueue currAudioFrameDmaQueue;
/* 0x1EE8 */ OSMesg currAudioFrameDmaMesgBufs[0x40]; /* 0x1EE8 */ OSMesg currAudioFrameDmaMesgBuf[0x40];
/* 0x1FE8 */ OSIoMesg currAudioFrameDmaIoMesgBufs[0x40]; /* 0x1FE8 */ OSIoMesg currAudioFrameDmaIoMesgBuf[0x40];
/* 0x25E8 */ OSMesgQueue unk_25E8; /* 0x25E8 */ OSMesgQueue syncDmaQueue;
/* 0x2600 */ OSMesg unk_2600; /* 0x2600 */ OSMesg syncDmaMesg;
/* 0x2604 */ OSIoMesg unk_2604; /* 0x2604 */ OSIoMesg syncDmaIoMesg;
/* 0x261C */ SampleDmaReq* sampleDmaReqs; /* 0x261C */ SampleDma* sampleDmas;
/* 0x2620 */ u32 sampleDmaReqCnt; /* 0x2620 */ u32 sampleDmaCount;
/* 0x2624 */ u32 sampleDmaListSize1; /* 0x2624 */ u32 sampleDmaListSize1;
/* 0x2628 */ s32 unk_2628; /* 0x2628 */ s32 unused2628;
/* 0x262C */ u8 sampleDmaReuseQueue1[0x100]; // read pos <= write pos, wrapping mod 256 /* 0x262C */ u8 sampleDmaReuseQueue1[0x100]; // read pos <= write pos, wrapping mod 256
/* 0x272C */ u8 sampleDmaReuseQueue2[0x100]; /* 0x272C */ u8 sampleDmaReuseQueue2[0x100];
/* 0x282C */ u8 sampleDmaReuseQueue1RdPos; /* 0x282C */ u8 sampleDmaReuseQueue1RdPos;
/* 0x282D */ u8 sampleDmaReuseQueue2RdPos; /* 0x282D */ u8 sampleDmaReuseQueue2RdPos;
/* 0x282E */ u8 sampleDmaReuseQueue1WrPos; /* 0x282E */ u8 sampleDmaReuseQueue1WrPos;
/* 0x282F */ u8 sampleDmaReuseQueue2WrPos; /* 0x282F */ u8 sampleDmaReuseQueue2WrPos;
/* 0x2830 */ SequenceTable* sequenceTable; /* 0x2830 */ AudioTable* sequenceTable;
/* 0x2834 */ AudioBankTable* audioBankTable; /* 0x2834 */ AudioTable* soundFontTable;
/* 0x2838 */ AudioTable* audioTable; /* 0x2838 */ AudioTable* sampleBankTable;
union { /* 0x283C */ u8* sequenceFontTable;
/* 0x283C */ u16* unk_283C; /* 0x2840 */ u16 numSequences;
/* 0x283C */ u8* unk_283Cb; /* 0x2844 */ SoundFont* soundFonts;
};
/* 0x2840 */ u16 seqTabEntCnt; // channels used?
/* 0x2844 */ CtlEntry* ctlEntries;
/* 0x2848 */ AudioBufferParameters audioBufferParameters; /* 0x2848 */ AudioBufferParameters audioBufferParameters;
/* 0x2870 */ f32 unk_2870; /* 0x2870 */ f32 unk_2870;
/* 0x2874 */ s32 unk_2874; /* 0x2874 */ s32 sampleDmaBufSize1;
/* 0x2874 */ s32 unk_2878; /* 0x2874 */ s32 sampleDmaBufSize2;
/* 0x287C */ char unk_287C[0x10]; /* 0x287C */ char unk_287C[0x10];
/* 0x288C */ s32 unk_288C; /* 0x288C */ s32 sampleDmaBufSize;
/* 0x2890 */ s32 maxAudioCmds; /* 0x2890 */ s32 maxAudioCmds;
/* 0x2894 */ s32 maxSimultaneousNotes; // (bad name) /* 0x2894 */ s32 numNotes;
/* 0x2898 */ s16 tempoInternalToExternal; /* 0x2898 */ s16 tempoInternalToExternal;
/* 0x289A */ s8 soundMode; /* 0x289A */ s8 soundMode;
/* 0x289C */ s32 totalTaskCnt; /* 0x289C */ s32 totalTaskCnt;
@ -916,27 +831,27 @@ typedef struct {
/* 0x2980 */ s32 audioErrorFlags; /* 0x2980 */ s32 audioErrorFlags;
/* 0x2984 */ volatile u32 resetTimer; /* 0x2984 */ volatile u32 resetTimer;
/* 0x2988 */ char unk_2988[0x8]; /* 0x2988 */ char unk_2988[0x8];
/* 0x2990 */ SoundAllocPool audioSessionPool; /* 0x2990 */ AudioAllocPool audioSessionPool;
/* 0x29A0 */ SoundAllocPool unkPool; /* 0x29A0 */ AudioAllocPool externalPool;
/* 0x29B0 */ SoundAllocPool audioInitPool; /* 0x29B0 */ AudioAllocPool audioInitPool;
/* 0x29C0 */ SoundAllocPool notesAndBuffersPool; /* 0x29C0 */ AudioAllocPool notesAndBuffersPool;
/* 0x29D0 */ char unk_29D0[0x20]; // probably two unused pools /* 0x29D0 */ char unk_29D0[0x20]; // probably two unused pools
/* 0x29F0 */ SoundAllocPool seqAndBankPool; /* 0x29F0 */ AudioAllocPool cachePool;
/* 0x2A00 */ SoundAllocPool persistentCommonPool; /* 0x2A00 */ AudioAllocPool persistentCommonPool;
/* 0x2A10 */ SoundAllocPool temporaryCommonPool; /* 0x2A10 */ AudioAllocPool temporaryCommonPool;
/* 0x2A20 */ SoundMultiPool seqLoadedPool; /* 0x2A20 */ AudioCache seqCache;
/* 0x2B30 */ SoundMultiPool bankLoadedPool; /* 0x2B30 */ AudioCache fontCache;
/* 0x2C40 */ SoundMultiPool unusedLoadedPool; // rename after we figure out what this is /* 0x2C40 */ AudioCache sampleBankCache;
/* 0x2D50 */ SoundAllocPool unk_2D50; /* 0x2D50 */ AudioAllocPool permanentPool;
/* 0x2D60 */ SeqOrBankEntry unk_2D60[32]; /* 0x2D60 */ AudioCacheEntry permanentCache[32];
/* 0x2EE0 */ UnkPool unk_2EE0; /* 0x2EE0 */ AudioSampleCache persistentSampleCache;
/* 0x3174 */ UnkPool unk_3174; /* 0x3174 */ AudioSampleCache temporarySampleCache;
/* 0x3408 */ AudioPoolSplit4 sessionPoolSplit; /* 0x3408 */ AudioPoolSplit4 sessionPoolSplit;
/* 0x3418 */ AudioPoolSplit2 seqAndBankPoolSplit; /* 0x3418 */ AudioPoolSplit2 cachePoolSplit;
/* 0x3420 */ AudioPoolSplit3 persistentCommonPoolSplit; /* 0x3420 */ AudioPoolSplit3 persistentCommonPoolSplit;
/* 0x342C */ AudioPoolSplit3 temporaryCommonPoolSplit; /* 0x342C */ AudioPoolSplit3 temporaryCommonPoolSplit;
/* 0x3438 */ u8 audioTableLoadStatus[0x30]; /* 0x3438 */ u8 sampleFontLoadStatus[0x30];
/* 0x3468 */ u8 bankLoadStatus[0x30]; /* 0x3468 */ u8 fontLoadStatus[0x30];
/* 0x3498 */ u8 seqLoadStatus[0x80]; /* 0x3498 */ u8 seqLoadStatus[0x80];
/* 0x3518 */ volatile u8 resetStatus; /* 0x3518 */ volatile u8 resetStatus;
/* 0x3519 */ u8 audioResetSpecIdToLoad; /* 0x3519 */ u8 audioResetSpecIdToLoad;
@ -946,7 +861,7 @@ typedef struct {
/* 0x3528 */ u32 audioHeapSize; /* 0x3528 */ u32 audioHeapSize;
/* 0x352C */ Note* notes; /* 0x352C */ Note* notes;
/* 0x3530 */ SequencePlayer seqPlayers[4]; /* 0x3530 */ SequencePlayer seqPlayers[4];
/* 0x3AB0 */ SequenceChannelLayer sequenceLayers[64]; /* 0x3AB0 */ SequenceLayer sequenceLayers[64];
/* 0x5AB0 */ SequenceChannel sequenceChannelNone; /* 0x5AB0 */ SequenceChannel sequenceChannelNone;
/* 0x5B84 */ s32 noteSubEuOffset; /* 0x5B84 */ s32 noteSubEuOffset;
/* 0x5B88 */ AudioListItem layerFreeList; /* 0x5B88 */ AudioListItem layerFreeList;
@ -954,7 +869,6 @@ typedef struct {
/* 0x5BD8 */ u8 cmdWrPos; /* 0x5BD8 */ u8 cmdWrPos;
/* 0x5BD9 */ u8 cmdRdPos; /* 0x5BD9 */ u8 cmdRdPos;
/* 0x5BDA */ u8 cmdQueueFinished; /* 0x5BDA */ u8 cmdQueueFinished;
/* 0x5BDB */ char unk_5BDB[0x1];
/* 0x5BDC */ u16 unk_5BDC[4]; /* 0x5BDC */ u16 unk_5BDC[4];
/* 0x5BE4 */ OSMesgQueue* audioResetQueueP; /* 0x5BE4 */ OSMesgQueue* audioResetQueueP;
/* 0x5BE8 */ OSMesgQueue* taskStartQueueP; /* 0x5BE8 */ OSMesgQueue* taskStartQueueP;
@ -982,9 +896,9 @@ typedef struct {
} NoteSubAttributes; // size = 0x18 } NoteSubAttributes; // size = 0x18
typedef struct { typedef struct {
/* 0x00 */ u32 heap; /* 0x00 */ u32 heapSize;
/* 0x04 */ u32 mainPool; /* 0x04 */ u32 initPoolSize;
/* 0x08 */ u32 initPool; /* 0x08 */ u32 permanentPoolSize;
} AudioContextInitSizes; // size = 0xC } AudioContextInitSizes; // size = 0xC
typedef struct { typedef struct {
@ -1012,22 +926,18 @@ typedef struct {
/* 0x020 */ f32 unk_20; /* 0x020 */ f32 unk_20;
/* 0x024 */ f32 unk_24; /* 0x024 */ f32 unk_24;
/* 0x028 */ u16 unk_28; /* 0x028 */ u16 unk_28;
/* 0x02A */ char unk_2A[0x2];
/* 0x02C */ u32 unk_2C[8]; /* 0x02C */ u32 unk_2C[8];
/* 0x04C */ u8 unk_4C; /* 0x04C */ u8 unk_4C;
/* 0x04D */ u8 unk_4D; /* 0x04D */ u8 unk_4D;
/* 0x04E */ u8 unk_4E; /* 0x04E */ u8 unk_4E;
/* 0x04F */ char unk_4F;
/* 0x050 */ unk_50_s unk_50[0x10]; /* 0x050 */ unk_50_s unk_50[0x10];
/* 0x250 */ u16 unk_250; /* 0x250 */ u16 unk_250;
/* 0x252 */ u16 unk_252; /* 0x252 */ u16 unk_252;
/* 0x254 */ u16 unk_254; /* 0x254 */ u16 unk_254;
/* 0x256 */ u16 unk_256; /* 0x256 */ u16 unk_256;
/* 0x258 */ u16 unk_258; /* 0x258 */ u16 unk_258;
/* 0x25A */ char unk_25A[0x2];
/* 0x25C */ u32 unk_25C; /* 0x25C */ u32 unk_25C;
/* 0x260 */ u8 unk_260; /* 0x260 */ u8 unk_260;
/* 0x261 */ char unk_261[0x3];
} unk_D_8016E750; // size = 0x264 } unk_D_8016E750; // size = 0x264
typedef enum { typedef enum {
@ -1040,24 +950,33 @@ typedef enum {
/* 6 */ BANK_VOICE /* 6 */ BANK_VOICE
} SoundBankTypes; } SoundBankTypes;
typedef enum {
/* 0 */ SFX_STATE_EMPTY,
/* 1 */ SFX_STATE_QUEUED,
/* 2 */ SFX_STATE_READY,
/* 3 */ SFX_STATE_PLAYING_REFRESH,
/* 4 */ SFX_STATE_PLAYING_1,
/* 5 */ SFX_STATE_PLAYING_2
} SfxState;
typedef struct { typedef struct {
/* 0x00 */ f32* posX; /* 0x00 */ f32* posX;
/* 0x04 */ f32* posY; /* 0x04 */ f32* posY;
/* 0x08 */ f32* posZ; /* 0x08 */ f32* posZ;
/* 0x0C */ u8 unk_C; /* 0x0C */ u8 token;
/* 0x10 */ f32* freqScale; /* 0x10 */ f32* freqScale;
/* 0x14 */ f32* unk_14; /* 0x14 */ f32* vol;
/* 0x18 */ s8* reverbAdd; /* 0x18 */ s8* reverbAdd;
/* 0x1C */ f32 dist; /* 0x1C */ f32 dist;
/* 0x20 */ u32 priority; // lower is more prioritized /* 0x20 */ u32 priority; // lower is more prioritized
/* 0x24 */ u8 sfxImportance; /* 0x24 */ u8 sfxImportance;
/* 0x26 */ u16 sfxParams; /* 0x26 */ u16 sfxParams;
/* 0x28 */ u16 sfxId; /* 0x28 */ u16 sfxId;
/* 0x2A */ u8 unk_2A; /* 0x2A */ u8 state; // uses SfxState enum
/* 0x2B */ u8 unk_2B; /* 0x2B */ u8 freshness;
/* 0x2C */ u8 prev; /* 0x2C */ u8 prev;
/* 0x2D */ u8 next; /* 0x2D */ u8 next;
/* 0x2E */ u8 unk_2E; /* 0x2E */ u8 channelIdx;
/* 0x2F */ u8 unk_2F; /* 0x2F */ u8 unk_2F;
} SoundBankEntry; // size = 0x30 } SoundBankEntry; // size = 0x30
@ -1084,8 +1003,8 @@ typedef struct {
typedef struct { typedef struct {
u32 priority; // lower is more prioritized u32 priority; // lower is more prioritized
u8 unk_4; u8 entryIndex;
} Struct_800F7CEC; } ActiveSound;
typedef struct { typedef struct {
u8 importance; u8 importance;

2
spec
View file

@ -418,7 +418,7 @@ beginseg
include "build/data/code_800F7260.bss.o" include "build/data/code_800F7260.bss.o"
include "build/src/code/code_800F9280.o" include "build/src/code/code_800F9280.o"
include "build/data/code_800F9280.data.o" include "build/data/code_800F9280.data.o"
include "build/src/code/audio_rodata.o" include "build/src/code/audio_init_params.o"
include "build/src/code/logseverity.o" include "build/src/code/logseverity.o"
include "build/src/code/gfxprint.o" include "build/src/code/gfxprint.o"
include "build/src/code/code_800FBCE0.o" include "build/src/code/code_800FBCE0.o"

View file

@ -17,7 +17,7 @@ void* Yaz0_FirstDMA(void) {
curSize = sYaz0CurDataEnd - (u32)sYaz0DataBuffer; curSize = sYaz0CurDataEnd - (u32)sYaz0DataBuffer;
dmaSize = (curSize > sYaz0CurSize) ? sYaz0CurSize : curSize; dmaSize = (curSize > sYaz0CurSize) ? sYaz0CurSize : curSize;
DmaMgr_DMARomToRam(sYaz0CurRomStart, sYaz0DataBuffer, dmaSize); DmaMgr_DmaRomToRam(sYaz0CurRomStart, sYaz0DataBuffer, dmaSize);
sYaz0CurRomStart += dmaSize; sYaz0CurRomStart += dmaSize;
sYaz0CurSize -= dmaSize; sYaz0CurSize -= dmaSize;
return sYaz0DataBuffer; return sYaz0DataBuffer;
@ -38,7 +38,7 @@ void* Yaz0_NextDMA(void* curSrcPos) {
} }
if (dmaSize != 0) { if (dmaSize != 0) {
DmaMgr_DMARomToRam(sYaz0CurRomStart, (u32)dst + restSize, dmaSize); DmaMgr_DmaRomToRam(sYaz0CurRomStart, (u32)dst + restSize, dmaSize);
sYaz0CurRomStart += dmaSize; sYaz0CurRomStart += dmaSize;
sYaz0CurSize -= dmaSize; sYaz0CurSize -= dmaSize;
if (!sYaz0CurSize) { if (!sYaz0CurSize) {

View file

@ -1569,7 +1569,7 @@ s32 DmaMgr_CompareName(const char* name1, const char* name2) {
return 0; return 0;
} }
s32 DmaMgr_DMARomToRam(u32 rom, u32 ram, u32 size) { s32 DmaMgr_DmaRomToRam(u32 rom, u32 ram, u32 size) {
OSIoMesg ioMsg; OSIoMesg ioMsg;
OSMesgQueue queue; OSMesgQueue queue;
OSMesg msg; OSMesg msg;
@ -1601,14 +1601,14 @@ s32 DmaMgr_DMARomToRam(u32 rom, u32 ram, u32 size) {
ret = osEPiStartDma(gCartHandle, &ioMsg, OS_READ); ret = osEPiStartDma(gCartHandle, &ioMsg, OS_READ);
if (ret) { if (ret) {
goto DmaMgr_DMARomToRam_end; goto end;
} }
if (D_80009460 == 10) { if (D_80009460 == 10) {
osSyncPrintf("%10lld ノーマルDMA START (%d)\n", OS_CYCLES_TO_USEC(osGetTime()), gPiMgrCmdQ.validCount); osSyncPrintf("%10lld ノーマルDMA START (%d)\n", OS_CYCLES_TO_USEC(osGetTime()), gPiMgrCmdQ.validCount);
} }
osRecvMesg(&queue, NULL, 1); osRecvMesg(&queue, NULL, OS_MESG_BLOCK);
if (D_80009460 == 10) { if (D_80009460 == 10) {
osSyncPrintf("%10lld ノーマルDMA END (%d)\n", OS_CYCLES_TO_USEC(osGetTime()), gPiMgrCmdQ.validCount); osSyncPrintf("%10lld ノーマルDMA END (%d)\n", OS_CYCLES_TO_USEC(osGetTime()), gPiMgrCmdQ.validCount);
} }
@ -1633,22 +1633,22 @@ s32 DmaMgr_DMARomToRam(u32 rom, u32 ram, u32 size) {
ret = osEPiStartDma(gCartHandle, &ioMsg, OS_READ); ret = osEPiStartDma(gCartHandle, &ioMsg, OS_READ);
if (ret) { if (ret) {
goto DmaMgr_DMARomToRam_end; goto end;
} }
osRecvMesg(&queue, NULL, 1); osRecvMesg(&queue, NULL, OS_MESG_BLOCK);
if (D_80009460 == 10) { if (D_80009460 == 10) {
osSyncPrintf("%10lld ノーマルDMA END (%d)\n", OS_CYCLES_TO_USEC(osGetTime()), gPiMgrCmdQ.validCount); osSyncPrintf("%10lld ノーマルDMA END (%d)\n", OS_CYCLES_TO_USEC(osGetTime()), gPiMgrCmdQ.validCount);
} }
DmaMgr_DMARomToRam_end: end:
osInvalICache((void*)ram, size); osInvalICache((void*)ram, size);
osInvalDCache((void*)ram, size); osInvalDCache((void*)ram, size);
return ret; return ret;
} }
s32 DmaMgr_DmaCallback0(OSPiHandle* pihandle, OSIoMesg* mb, s32 direction) { s32 DmaMgr_DmaHandler(OSPiHandle* pihandle, OSIoMesg* mb, s32 direction) {
s32 ret; s32 ret;
ASSERT(pihandle == gCartHandle, "pihandle == carthandle", "../z_std_dma.c", 530); ASSERT(pihandle == gCartHandle, "pihandle == carthandle", "../z_std_dma.c", 530);
@ -1667,7 +1667,7 @@ s32 DmaMgr_DmaCallback0(OSPiHandle* pihandle, OSIoMesg* mb, s32 direction) {
return ret; return ret;
} }
void DmaMgr_DmaCallback1(u32 ram, u32 rom, u32 size) { void DmaMgr_DmaFromDriveRom(u32 ram, u32 rom, u32 size) {
OSPiHandle* handle = osDriveRomInit(); OSPiHandle* handle = osDriveRomInit();
OSMesgQueue queue; OSMesgQueue queue;
OSMesg msg; OSMesg msg;
@ -1684,7 +1684,7 @@ void DmaMgr_DmaCallback1(u32 ram, u32 rom, u32 size) {
ioMsg.size = size; ioMsg.size = size;
handle->transferInfo.cmdType = 2; handle->transferInfo.cmdType = 2;
osEPiStartDma(handle, &ioMsg, 0); osEPiStartDma(handle, &ioMsg, OS_READ);
osRecvMesg(&queue, NULL, OS_MESG_BLOCK); osRecvMesg(&queue, NULL, OS_MESG_BLOCK);
return; return;
} }
@ -1783,7 +1783,7 @@ void DmaMgr_ProcessMsg(DmaRequest* req) {
"セグメント境界をまたがってDMA転送することはできません"); "セグメント境界をまたがってDMA転送することはできません");
} }
DmaMgr_DMARomToRam(iter->romStart + (vrom - iter->vromStart), (u32)ram, size); DmaMgr_DmaRomToRam(iter->romStart + (vrom - iter->vromStart), (u32)ram, size);
found = true; found = true;
if (0) { if (0) {
@ -1823,7 +1823,7 @@ void DmaMgr_ProcessMsg(DmaRequest* req) {
return; return;
} }
DmaMgr_DMARomToRam(vrom, (u32)ram, size); DmaMgr_DmaRomToRam(vrom, (u32)ram, size);
if (0) { if (0) {
osSyncPrintf("No Press ROM:%08X RAM:%08X SIZE:%08X (非公式)\n", vrom, ram, size); osSyncPrintf("No Press ROM:%08X RAM:%08X SIZE:%08X (非公式)\n", vrom, ram, size);
@ -1837,7 +1837,7 @@ void DmaMgr_ThreadEntry(void* arg0) {
osSyncPrintf("DMAマネージャスレッド実行開始\n"); osSyncPrintf("DMAマネージャスレッド実行開始\n");
while (true) { while (true) {
osRecvMesg(&sDmaMgrMsgQueue, &msg, 1); osRecvMesg(&sDmaMgrMsgQueue, &msg, OS_MESG_BLOCK);
req = (DmaRequest*)msg; req = (DmaRequest*)msg;
if (req == NULL) { if (req == NULL) {
break; break;
@ -1861,8 +1861,8 @@ void DmaMgr_ThreadEntry(void* arg0) {
s32 DmaMgr_SendRequestImpl(DmaRequest* req, u32 ram, u32 vrom, u32 size, u32 unk, OSMesgQueue* queue, OSMesg msg) { s32 DmaMgr_SendRequestImpl(DmaRequest* req, u32 ram, u32 vrom, u32 size, u32 unk, OSMesgQueue* queue, OSMesg msg) {
static s32 sDmaMgrQueueFullLogged = 0; static s32 sDmaMgrQueueFullLogged = 0;
if ((1 && (ram == 0)) || (osMemSize < ram + size + 0x80000000) || (vrom & 1) || (vrom > 0x4000000) || if ((1 && (ram == 0)) || (osMemSize < ram + size + 0x80000000) || (vrom & 1) || (vrom > 0x4000000) || (size == 0) ||
(size == 0) || (size & 1)) { (size & 1)) {
DmaMgr_Error(req, NULL, "ILLIGAL DMA-FUNCTION CALL", "パラメータ異常です"); DmaMgr_Error(req, NULL, "ILLIGAL DMA-FUNCTION CALL", "パラメータ異常です");
} }
@ -1910,7 +1910,7 @@ void DmaMgr_Init(void) {
s32 idx; s32 idx;
DmaEntry* iter; DmaEntry* iter;
DmaMgr_DMARomToRam((u32)_dmadataSegmentRomStart, (u32)_dmadataSegmentStart, DmaMgr_DmaRomToRam((u32)_dmadataSegmentRomStart, (u32)_dmadataSegmentStart,
(u32)(_dmadataSegmentRomEnd - _dmadataSegmentRomStart)); (u32)(_dmadataSegmentRomEnd - _dmadataSegmentRomStart));
osSyncPrintf("dma_rom_ad[]\n"); osSyncPrintf("dma_rom_ad[]\n");
@ -1972,6 +1972,6 @@ s32 DmaMgr_SendRequest1(void* ram0, u32 vrom, u32 size, const char* file, s32 li
return ret; return ret;
} }
osRecvMesg(&queue, NULL, 1); osRecvMesg(&queue, NULL, OS_MESG_BLOCK);
return 0; return 0;
} }

View file

@ -55,9 +55,9 @@ void AudioMgr_ThreadEntry(void* arg0) {
s16* msg = NULL; s16* msg = NULL;
osSyncPrintf("オーディオマネージャスレッド実行開始\n"); // "Start running audio manager thread" osSyncPrintf("オーディオマネージャスレッド実行開始\n"); // "Start running audio manager thread"
func_800F70F8(); Audio_Init();
func_800E301C(DmaMgr_DmaCallback0); AudioLoad_SetDmaHandler(DmaMgr_DmaHandler);
func_800F711C(); Audio_InitSound();
osSendMesg(&audioMgr->unk_C8, NULL, OS_MESG_BLOCK); osSendMesg(&audioMgr->unk_C8, NULL, OS_MESG_BLOCK);
IrqMgr_AddClient(audioMgr->irqMgr, &irqClient, &audioMgr->unk_74); IrqMgr_AddClient(audioMgr->irqMgr, &irqClient, &audioMgr->unk_74);

View file

@ -1,51 +1,51 @@
#include "ultra64.h" #include "ultra64.h"
#include "global.h" #include "global.h"
void Audio_SequenceChannelProcessSound(SequenceChannel* seqChannel, s32 recalculateVolume, s32 b) { void Audio_SequenceChannelProcessSound(SequenceChannel* channel, s32 recalculateVolume, s32 b) {
f32 channelVolume; f32 channelVolume;
f32 chanFreqScale; f32 chanFreqScale;
s32 i; s32 i;
if (seqChannel->changes.s.volume || recalculateVolume) { if (channel->changes.s.volume || recalculateVolume) {
channelVolume = seqChannel->volume * seqChannel->volumeScale * seqChannel->seqPlayer->appliedFadeVolume; channelVolume = channel->volume * channel->volumeScale * channel->seqPlayer->appliedFadeVolume;
if (seqChannel->seqPlayer->muted && (seqChannel->muteBehavior & 0x20)) { if (channel->seqPlayer->muted && (channel->muteBehavior & 0x20)) {
channelVolume = seqChannel->seqPlayer->muteVolumeScale * channelVolume; channelVolume = channel->seqPlayer->muteVolumeScale * channelVolume;
} }
seqChannel->appliedVolume = channelVolume * channelVolume; channel->appliedVolume = channelVolume * channelVolume;
} }
if (seqChannel->changes.s.pan) { if (channel->changes.s.pan) {
seqChannel->pan = seqChannel->newPan * seqChannel->panChannelWeight; channel->pan = channel->newPan * channel->panChannelWeight;
} }
chanFreqScale = seqChannel->freqScale; chanFreqScale = channel->freqScale;
if (b != 0) { if (b != 0) {
chanFreqScale *= seqChannel->seqPlayer->unk_34; chanFreqScale *= channel->seqPlayer->unk_34;
seqChannel->changes.s.freqScale = true; channel->changes.s.freqScale = true;
} }
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
SequenceChannelLayer* layer = seqChannel->layers[i]; SequenceLayer* layer = channel->layers[i];
if (layer != NULL && layer->enabled && layer->note != NULL) { if (layer != NULL && layer->enabled && layer->note != NULL) {
if (layer->notePropertiesNeedInit) { if (layer->notePropertiesNeedInit) {
layer->noteFreqScale = layer->freqScale * chanFreqScale; layer->noteFreqScale = layer->freqScale * chanFreqScale;
layer->noteVelocity = layer->velocitySquare2 * seqChannel->appliedVolume; layer->noteVelocity = layer->velocitySquare2 * channel->appliedVolume;
layer->notePan = (seqChannel->pan + layer->pan * (0x80 - seqChannel->panChannelWeight)) >> 7; layer->notePan = (channel->pan + layer->pan * (0x80 - channel->panChannelWeight)) >> 7;
layer->notePropertiesNeedInit = false; layer->notePropertiesNeedInit = false;
} else { } else {
if (seqChannel->changes.s.freqScale) { if (channel->changes.s.freqScale) {
layer->noteFreqScale = layer->freqScale * chanFreqScale; layer->noteFreqScale = layer->freqScale * chanFreqScale;
} }
if (seqChannel->changes.s.volume || recalculateVolume) { if (channel->changes.s.volume || recalculateVolume) {
layer->noteVelocity = layer->velocitySquare2 * seqChannel->appliedVolume; layer->noteVelocity = layer->velocitySquare2 * channel->appliedVolume;
} }
if (seqChannel->changes.s.pan) { if (channel->changes.s.pan) {
layer->notePan = (seqChannel->pan + layer->pan * (0x80 - seqChannel->panChannelWeight)) >> 7; layer->notePan = (channel->pan + layer->pan * (0x80 - channel->panChannelWeight)) >> 7;
} }
} }
} }
} }
seqChannel->changes.asByte = 0; channel->changes.asByte = 0;
} }
void Audio_SequencePlayerProcessSound(SequencePlayer* seqPlayer) { void Audio_SequencePlayerProcessSound(SequencePlayer* seqPlayer) {
@ -63,7 +63,7 @@ void Audio_SequencePlayerProcessSound(SequencePlayer* seqPlayer) {
} }
if (--seqPlayer->fadeTimer == 0 && seqPlayer->state == 2) { if (--seqPlayer->fadeTimer == 0 && seqPlayer->state == 2) {
Audio_SequencePlayerDisable(seqPlayer); AudioSeq_SequencePlayerDisable(seqPlayer);
return; return;
} }
} }
@ -112,14 +112,16 @@ f32 Audio_GetVibratoFreqScale(VibratoState* vib) {
f32 temp; f32 temp;
f32 twoToThe16th = 65536.0f; f32 twoToThe16th = 65536.0f;
s32 one = 1; s32 one = 1;
SequenceChannel* channel = vib->seqChannel; SequenceChannel* channel = vib->channel;
if (vib->delay != 0) { if (vib->delay != 0) {
vib->delay--; vib->delay--;
return 1; return 1;
} }
if (channel != NO_CHANNEL) { //! @bug this probably meant to compare with gAudioContext.sequenceChannelNone.
//! -1 isn't used as a channel pointer anywhere else.
if (channel != ((SequenceChannel*)(-1))) {
if (vib->extentChangeTimer) { if (vib->extentChangeTimer) {
if (vib->extentChangeTimer == 1) { if (vib->extentChangeTimer == 1) {
vib->extent = (s32)channel->vibratoExtentTarget; vib->extent = (s32)channel->vibratoExtentTarget;
@ -179,7 +181,7 @@ void Audio_NoteVibratoUpdate(Note* note) {
void Audio_NoteVibratoInit(Note* note) { void Audio_NoteVibratoInit(Note* note) {
VibratoState* vib; VibratoState* vib;
SequenceChannel* seqChannel; SequenceChannel* channel;
note->playbackState.vibratoFreqScale = 1.0f; note->playbackState.vibratoFreqScale = 1.0f;
@ -189,20 +191,20 @@ void Audio_NoteVibratoInit(Note* note) {
vib->time = 0; vib->time = 0;
vib->curve = gWaveSamples[2]; vib->curve = gWaveSamples[2];
vib->seqChannel = note->playbackState.parentLayer->seqChannel; vib->channel = note->playbackState.parentLayer->channel;
seqChannel = vib->seqChannel; channel = vib->channel;
if ((vib->extentChangeTimer = seqChannel->vibratoExtentChangeDelay) == 0) { if ((vib->extentChangeTimer = channel->vibratoExtentChangeDelay) == 0) {
vib->extent = (s32)seqChannel->vibratoExtentTarget; vib->extent = (s32)channel->vibratoExtentTarget;
} else { } else {
vib->extent = (s32)seqChannel->vibratoExtentStart; vib->extent = (s32)channel->vibratoExtentStart;
} }
if ((vib->rateChangeTimer = seqChannel->vibratoRateChangeDelay) == 0) { if ((vib->rateChangeTimer = channel->vibratoRateChangeDelay) == 0) {
vib->rate = (s32)seqChannel->vibratoRateTarget; vib->rate = (s32)channel->vibratoRateTarget;
} else { } else {
vib->rate = (s32)seqChannel->vibratoRateStart; vib->rate = (s32)channel->vibratoRateStart;
} }
vib->delay = seqChannel->vibratoDelay; vib->delay = channel->vibratoDelay;
} }
void Audio_NotePortamentoInit(Note* note) { void Audio_NotePortamentoInit(Note* note) {

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,7 @@
#include "global.h" #include "global.h"
const s16 D_8014A6C0[] = { const s16 D_8014A6C0[] = {
0x1C00, 0x1C00, // unused
0x0030, 0x0030, // gTatumsPerBeat
}; };
const AudioContextInitSizes D_8014A6C4 = { 0x37F00, 0xE0E0, 0xBCE0 }; const AudioContextInitSizes D_8014A6C4 = { 0x37F00, 0xE0E0, 0xBCE0 };

File diff suppressed because it is too large Load diff

View file

@ -17,8 +17,8 @@ void Audio_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* attrs) {
reverbVol = attrs->reverbVol; reverbVol = attrs->reverbVol;
sp24 = attrs->stereo.s; sp24 = attrs->stereo.s;
sub->bitField0.s = note->noteSubEu.bitField0.s; sub->bitField0 = note->noteSubEu.bitField0;
sub->bitField1.s = note->noteSubEu.bitField1.s; sub->bitField1 = note->noteSubEu.bitField1;
sub->sound.samples = note->noteSubEu.sound.samples; sub->sound.samples = note->noteSubEu.sound.samples;
sub->unk_06 = note->noteSubEu.unk_06; sub->unk_06 = note->noteSubEu.unk_06;
@ -26,10 +26,10 @@ void Audio_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* attrs) {
pan &= 0x7F; pan &= 0x7F;
sub->bitField0.s.stereoStrongRight = false; sub->bitField0.stereoStrongRight = false;
sub->bitField0.s.stereoStrongLeft = false; sub->bitField0.stereoStrongLeft = false;
sub->bitField0.s.stereoHeadsetEffects = sp24.stereoHeadsetEffects; sub->bitField0.stereoHeadsetEffects = sp24.stereoHeadsetEffects;
sub->bitField0.s.usesHeadsetPanEffects = sp24.usesHeadsetPanEffects; sub->bitField0.usesHeadsetPanEffects = sp24.usesHeadsetPanEffects;
if (stereoHeadsetEffects && gAudioContext.soundMode == 1) { if (stereoHeadsetEffects && gAudioContext.soundMode == 1) {
smallPanIndex = pan >> 1; smallPanIndex = pan >> 1;
if (smallPanIndex > 0x3F) { if (smallPanIndex > 0x3F) {
@ -38,7 +38,7 @@ void Audio_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* attrs) {
sub->headsetPanLeft = gHeadsetPanQuantization[smallPanIndex]; sub->headsetPanLeft = gHeadsetPanQuantization[smallPanIndex];
sub->headsetPanRight = gHeadsetPanQuantization[0x3F - smallPanIndex]; sub->headsetPanRight = gHeadsetPanQuantization[0x3F - smallPanIndex];
sub->bitField1.s.usesHeadsetPanEffects2 = true; sub->bitField1.usesHeadsetPanEffects2 = true;
volLeft = gHeadsetPanVolume[pan]; volLeft = gHeadsetPanVolume[pan];
volRight = gHeadsetPanVolume[0x7F - pan]; volRight = gHeadsetPanVolume[0x7F - pan];
@ -46,7 +46,7 @@ void Audio_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* attrs) {
strongLeft = strongRight = 0; strongLeft = strongRight = 0;
sub->headsetPanRight = 0; sub->headsetPanRight = 0;
sub->headsetPanLeft = 0; sub->headsetPanLeft = 0;
sub->bitField1.s.usesHeadsetPanEffects2 = false; sub->bitField1.usesHeadsetPanEffects2 = false;
volLeft = gStereoPanVolume[pan]; volLeft = gStereoPanVolume[pan];
volRight = gStereoPanVolume[0x7F - pan]; volRight = gStereoPanVolume[0x7F - pan];
@ -56,34 +56,34 @@ void Audio_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* attrs) {
strongRight = 1; strongRight = 1;
} }
sub->bitField0.s.stereoStrongRight = strongRight; sub->bitField0.stereoStrongRight = strongRight;
sub->bitField0.s.stereoStrongLeft = strongLeft; sub->bitField0.stereoStrongLeft = strongLeft;
switch (sp24.bit2) { switch (sp24.bit2) {
case 0: case 0:
break; break;
case 1: case 1:
sub->bitField0.s.stereoStrongRight = sp24.strongRight; sub->bitField0.stereoStrongRight = sp24.strongRight;
sub->bitField0.s.stereoStrongLeft = sp24.strongLeft; sub->bitField0.stereoStrongLeft = sp24.strongLeft;
break; break;
case 2: case 2:
sub->bitField0.s.stereoStrongRight = sp24.strongRight | strongRight; sub->bitField0.stereoStrongRight = sp24.strongRight | strongRight;
sub->bitField0.s.stereoStrongLeft = sp24.strongLeft | strongLeft; sub->bitField0.stereoStrongLeft = sp24.strongLeft | strongLeft;
break; break;
case 3: case 3:
sub->bitField0.s.stereoStrongRight = sp24.strongRight ^ strongRight; sub->bitField0.stereoStrongRight = sp24.strongRight ^ strongRight;
sub->bitField0.s.stereoStrongLeft = sp24.strongLeft ^ strongLeft; sub->bitField0.stereoStrongLeft = sp24.strongLeft ^ strongLeft;
break; break;
} }
} else if (gAudioContext.soundMode == 3) { } else if (gAudioContext.soundMode == 3) {
sub->bitField0.s.stereoHeadsetEffects = false; sub->bitField0.stereoHeadsetEffects = false;
sub->bitField0.s.usesHeadsetPanEffects = false; sub->bitField0.usesHeadsetPanEffects = false;
volLeft = 0.707f; // approx 1/sqrt(2) volLeft = 0.707f; // approx 1/sqrt(2)
volRight = 0.707f; volRight = 0.707f;
} else { } else {
sub->bitField0.s.stereoStrongRight = sp24.strongRight; sub->bitField0.stereoStrongRight = sp24.strongRight;
sub->bitField0.s.stereoStrongLeft = sp24.strongLeft; sub->bitField0.stereoStrongLeft = sp24.strongLeft;
volLeft = gDefaultPanVolume[pan]; volLeft = gDefaultPanVolume[pan];
volRight = gDefaultPanVolume[0x7F - pan]; volRight = gDefaultPanVolume[0x7F - pan];
} }
@ -105,7 +105,7 @@ void Audio_NoteSetResamplingRate(NoteSubEu* noteSubEu, f32 resamplingRateInput)
f32 resamplingRate = 0.0f; f32 resamplingRate = 0.0f;
if (resamplingRateInput < 2.0f) { if (resamplingRateInput < 2.0f) {
noteSubEu->bitField1.s.hasTwoAdpcmParts = false; noteSubEu->bitField1.hasTwoParts = false;
if (1.99998f < resamplingRateInput) { if (1.99998f < resamplingRateInput) {
resamplingRate = 1.99998f; resamplingRate = 1.99998f;
@ -114,7 +114,7 @@ void Audio_NoteSetResamplingRate(NoteSubEu* noteSubEu, f32 resamplingRateInput)
} }
} else { } else {
noteSubEu->bitField1.s.hasTwoAdpcmParts = true; noteSubEu->bitField1.hasTwoParts = true;
if (3.99996f < resamplingRateInput) { if (3.99996f < resamplingRateInput) {
resamplingRate = 1.99998f; resamplingRate = 1.99998f;
} else { } else {
@ -126,11 +126,11 @@ void Audio_NoteSetResamplingRate(NoteSubEu* noteSubEu, f32 resamplingRateInput)
void Audio_NoteInit(Note* note) { void Audio_NoteInit(Note* note) {
if (note->playbackState.parentLayer->adsr.releaseRate == 0) { if (note->playbackState.parentLayer->adsr.releaseRate == 0) {
Audio_AdsrInit(&note->playbackState.adsr, note->playbackState.parentLayer->seqChannel->adsr.envelope, Audio_AdsrInit(&note->playbackState.adsr, note->playbackState.parentLayer->channel->adsr.envelope,
&note->playbackState.adsrVolScale); &note->playbackState.adsrVolScaleUnused);
} else { } else {
Audio_AdsrInit(&note->playbackState.adsr, note->playbackState.parentLayer->adsr.envelope, Audio_AdsrInit(&note->playbackState.adsr, note->playbackState.parentLayer->adsr.envelope,
&note->playbackState.adsrVolScale); &note->playbackState.adsrVolScaleUnused);
} }
note->playbackState.unk_04 = 0; note->playbackState.unk_04 = 0;
@ -139,13 +139,13 @@ void Audio_NoteInit(Note* note) {
} }
void Audio_NoteDisable(Note* note) { void Audio_NoteDisable(Note* note) {
if (note->noteSubEu.bitField0.s.needsInit == true) { if (note->noteSubEu.bitField0.needsInit == true) {
note->noteSubEu.bitField0.s.needsInit = false; note->noteSubEu.bitField0.needsInit = false;
} }
note->playbackState.priority = 0; note->playbackState.priority = 0;
note->noteSubEu.bitField0.s.enabled = false; note->noteSubEu.bitField0.enabled = false;
note->playbackState.unk_04 = 0; note->playbackState.unk_04 = 0;
note->noteSubEu.bitField0.s.finished = false; note->noteSubEu.bitField0.finished = false;
note->playbackState.parentLayer = NO_LAYER; note->playbackState.parentLayer = NO_LAYER;
note->playbackState.prevParentLayer = NO_LAYER; note->playbackState.prevParentLayer = NO_LAYER;
note->playbackState.adsr.action.s.state = ADSR_STATE_DISABLED; note->playbackState.adsr.action.s.state = ADSR_STATE_DISABLED;
@ -164,7 +164,7 @@ void Audio_ProcessNotes(void) {
f32 scale; f32 scale;
s32 i; s32 i;
for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) { for (i = 0; i < gAudioContext.numNotes; i++) {
note = &gAudioContext.notes[i]; note = &gAudioContext.notes[i];
noteSubEu2 = &gAudioContext.noteSubsEu[gAudioContext.noteSubEuOffset + i]; noteSubEu2 = &gAudioContext.noteSubsEu[gAudioContext.noteSubEuOffset + i];
playbackState = &note->playbackState; playbackState = &note->playbackState;
@ -182,19 +182,19 @@ void Audio_ProcessNotes(void) {
} else if (!playbackState->parentLayer->enabled && playbackState->unk_04 == 0 && } else if (!playbackState->parentLayer->enabled && playbackState->unk_04 == 0 &&
playbackState->priority >= 1) { playbackState->priority >= 1) {
// do nothing // do nothing
} else if (playbackState->parentLayer->seqChannel->seqPlayer == NULL) { } else if (playbackState->parentLayer->channel->seqPlayer == NULL) {
Audio_SequenceChannelDisable(playbackState->parentLayer->seqChannel); AudioSeq_SequenceChannelDisable(playbackState->parentLayer->channel);
playbackState->priority = 1; playbackState->priority = 1;
playbackState->unk_04 = 1; playbackState->unk_04 = 1;
continue; continue;
} else if (playbackState->parentLayer->seqChannel->seqPlayer->muted && } else if (playbackState->parentLayer->channel->seqPlayer->muted &&
(playbackState->parentLayer->seqChannel->muteBehavior & 0x40)) { (playbackState->parentLayer->channel->muteBehavior & 0x40)) {
// do nothing // do nothing
} else { } else {
goto out; goto out;
} }
Audio_SeqChanLayerNoteRelease(playbackState->parentLayer); Audio_SeqLayerNoteRelease(playbackState->parentLayer);
Audio_AudioListRemove(&note->listItem); Audio_AudioListRemove(&note->listItem);
Audio_AudioListPushFront(&note->listItem.pool->decaying, &note->listItem); Audio_AudioListPushFront(&note->listItem.pool->decaying, &note->listItem);
playbackState->priority = 1; playbackState->priority = 1;
@ -207,22 +207,22 @@ void Audio_ProcessNotes(void) {
if (playbackState->priority != 0) { if (playbackState->priority != 0) {
if (1) {} if (1) {}
noteSubEu = &note->noteSubEu; noteSubEu = &note->noteSubEu;
if (playbackState->unk_04 >= 1 || noteSubEu->bitField0.s.finished) { if (playbackState->unk_04 >= 1 || noteSubEu->bitField0.finished) {
if (playbackState->adsr.action.s.state == ADSR_STATE_DISABLED || noteSubEu->bitField0.s.finished) { if (playbackState->adsr.action.s.state == ADSR_STATE_DISABLED || noteSubEu->bitField0.finished) {
if (playbackState->wantedParentLayer != NO_LAYER) { if (playbackState->wantedParentLayer != NO_LAYER) {
Audio_NoteDisable(note); Audio_NoteDisable(note);
if (playbackState->wantedParentLayer->seqChannel != NULL) { if (playbackState->wantedParentLayer->channel != NULL) {
Audio_NoteInitForLayer(note, playbackState->wantedParentLayer); Audio_NoteInitForLayer(note, playbackState->wantedParentLayer);
Audio_NoteVibratoInit(note); Audio_NoteVibratoInit(note);
Audio_NotePortamentoInit(note); Audio_NotePortamentoInit(note);
Audio_AudioListRemove(&note->listItem); Audio_AudioListRemove(&note->listItem);
Audio_AudioListPushBack(&note->listItem.pool->active, &note->listItem); AudioSeq_AudioListPushBack(&note->listItem.pool->active, &note->listItem);
playbackState->wantedParentLayer = NO_LAYER; playbackState->wantedParentLayer = NO_LAYER;
// don't skip // don't skip
} else { } else {
Audio_NoteDisable(note); Audio_NoteDisable(note);
Audio_AudioListRemove(&note->listItem); Audio_AudioListRemove(&note->listItem);
Audio_AudioListPushBack(&note->listItem.pool->disabled, &note->listItem); AudioSeq_AudioListPushBack(&note->listItem.pool->disabled, &note->listItem);
playbackState->wantedParentLayer = NO_LAYER; playbackState->wantedParentLayer = NO_LAYER;
goto skip; goto skip;
} }
@ -232,7 +232,7 @@ void Audio_ProcessNotes(void) {
} }
Audio_NoteDisable(note); Audio_NoteDisable(note);
Audio_AudioListRemove(&note->listItem); Audio_AudioListRemove(&note->listItem);
Audio_AudioListPushBack(&note->listItem.pool->disabled, &note->listItem); AudioSeq_AudioListPushBack(&note->listItem.pool->disabled, &note->listItem);
continue; continue;
} }
} }
@ -242,7 +242,7 @@ void Audio_ProcessNotes(void) {
} }
Audio_NoteDisable(note); Audio_NoteDisable(note);
Audio_AudioListRemove(&note->listItem); Audio_AudioListRemove(&note->listItem);
Audio_AudioListPushBack(&note->listItem.pool->disabled, &note->listItem); AudioSeq_AudioListPushBack(&note->listItem.pool->disabled, &note->listItem);
continue; continue;
} }
@ -259,10 +259,10 @@ void Audio_ProcessNotes(void) {
subAttrs.filter = attrs->filter; subAttrs.filter = attrs->filter;
subAttrs.unk_14 = attrs->unk_4; subAttrs.unk_14 = attrs->unk_4;
subAttrs.unk_16 = attrs->unk_6; subAttrs.unk_16 = attrs->unk_6;
bookOffset = noteSubEu->bitField1.s.bookOffset; bookOffset = noteSubEu->bitField1.bookOffset;
} else { } else {
SequenceChannelLayer* layer = playbackState->parentLayer; SequenceLayer* layer = playbackState->parentLayer;
SequenceChannel* channel = layer->seqChannel; SequenceChannel* channel = layer->channel;
subAttrs.frequency = layer->noteFreqScale; subAttrs.frequency = layer->noteFreqScale;
subAttrs.velocity = layer->noteVelocity; subAttrs.velocity = layer->noteVelocity;
@ -289,14 +289,14 @@ void Audio_ProcessNotes(void) {
subAttrs.frequency *= gAudioContext.audioBufferParameters.resampleRate; subAttrs.frequency *= gAudioContext.audioBufferParameters.resampleRate;
subAttrs.velocity *= scale; subAttrs.velocity *= scale;
Audio_InitNoteSub(note, noteSubEu2, &subAttrs); Audio_InitNoteSub(note, noteSubEu2, &subAttrs);
noteSubEu->bitField1.s.bookOffset = bookOffset; noteSubEu->bitField1.bookOffset = bookOffset;
skip:; skip:;
} }
} }
} }
AudioBankSound* Audio_InstrumentGetAudioBankSound(Instrument* instrument, s32 semitone) { SoundFontSound* Audio_InstrumentGetSound(Instrument* instrument, s32 semitone) {
AudioBankSound* sound; SoundFontSound* sound;
if (semitone < instrument->normalRangeLo) { if (semitone < instrument->normalRangeLo) {
sound = &instrument->lowNotesSound; sound = &instrument->lowNotesSound;
} else if (semitone <= instrument->normalRangeHi) { } else if (semitone <= instrument->normalRangeHi) {
@ -307,85 +307,85 @@ AudioBankSound* Audio_InstrumentGetAudioBankSound(Instrument* instrument, s32 se
return sound; return sound;
} }
Instrument* Audio_GetInstrumentInner(s32 bankId, s32 instId) { Instrument* Audio_GetInstrumentInner(s32 fontId, s32 instId) {
Instrument* inst; Instrument* inst;
if (bankId == 0xFF) { if (fontId == 0xFF) {
return NULL; return NULL;
} }
if (!Audio_IsBankLoadComplete(bankId)) { if (!AudioLoad_IsFontLoadComplete(fontId)) {
gAudioContext.audioErrorFlags = bankId + 0x10000000; gAudioContext.audioErrorFlags = fontId + 0x10000000;
return NULL; return NULL;
} }
if (instId >= gAudioContext.ctlEntries[bankId].numInstruments) { if (instId >= gAudioContext.soundFonts[fontId].numInstruments) {
gAudioContext.audioErrorFlags = ((bankId << 8) + instId) + 0x3000000; gAudioContext.audioErrorFlags = ((fontId << 8) + instId) + 0x3000000;
return NULL; return NULL;
} }
inst = gAudioContext.ctlEntries[bankId].instruments[instId]; inst = gAudioContext.soundFonts[fontId].instruments[instId];
if (inst == NULL) { if (inst == NULL) {
gAudioContext.audioErrorFlags = ((bankId << 8) + instId) + 0x1000000; gAudioContext.audioErrorFlags = ((fontId << 8) + instId) + 0x1000000;
return inst; return inst;
} }
return inst; return inst;
} }
Drum* Audio_GetDrum(s32 bankId, s32 drumId) { Drum* Audio_GetDrum(s32 fontId, s32 drumId) {
Drum* drum; Drum* drum;
if (bankId == 0xFF) { if (fontId == 0xFF) {
return NULL; return NULL;
} }
if (!Audio_IsBankLoadComplete(bankId)) { if (!AudioLoad_IsFontLoadComplete(fontId)) {
gAudioContext.audioErrorFlags = bankId + 0x10000000; gAudioContext.audioErrorFlags = fontId + 0x10000000;
return NULL; return NULL;
} }
if (drumId >= gAudioContext.ctlEntries[bankId].numDrums) { if (drumId >= gAudioContext.soundFonts[fontId].numDrums) {
gAudioContext.audioErrorFlags = ((bankId << 8) + drumId) + 0x4000000; gAudioContext.audioErrorFlags = ((fontId << 8) + drumId) + 0x4000000;
return NULL; return NULL;
} }
if ((u32)gAudioContext.ctlEntries[bankId].drums < 0x80000000) { if ((u32)gAudioContext.soundFonts[fontId].drums < 0x80000000) {
return NULL; return NULL;
} }
drum = gAudioContext.ctlEntries[bankId].drums[drumId]; drum = gAudioContext.soundFonts[fontId].drums[drumId];
if (drum == NULL) { if (drum == NULL) {
gAudioContext.audioErrorFlags = ((bankId << 8) + drumId) + 0x5000000; gAudioContext.audioErrorFlags = ((fontId << 8) + drumId) + 0x5000000;
} }
return drum; return drum;
} }
AudioBankSound* Audio_GetSfx(s32 bankId, s32 sfxId) { SoundFontSound* Audio_GetSfx(s32 fontId, s32 sfxId) {
AudioBankSound* sfx; SoundFontSound* sfx;
if (bankId == 0xFF) { if (fontId == 0xFF) {
return NULL; return NULL;
} }
if (!Audio_IsBankLoadComplete(bankId)) { if (!AudioLoad_IsFontLoadComplete(fontId)) {
gAudioContext.audioErrorFlags = bankId + 0x10000000; gAudioContext.audioErrorFlags = fontId + 0x10000000;
return NULL; return NULL;
} }
if (sfxId >= gAudioContext.ctlEntries[bankId].numSfx) { if (sfxId >= gAudioContext.soundFonts[fontId].numSfx) {
gAudioContext.audioErrorFlags = ((bankId << 8) + sfxId) + 0x4000000; gAudioContext.audioErrorFlags = ((fontId << 8) + sfxId) + 0x4000000;
return NULL; return NULL;
} }
if ((u32)gAudioContext.ctlEntries[bankId].soundEffects < 0x80000000) { if ((u32)gAudioContext.soundFonts[fontId].soundEffects < 0x80000000) {
return NULL; return NULL;
} }
sfx = &gAudioContext.ctlEntries[bankId].soundEffects[sfxId]; sfx = &gAudioContext.soundFonts[fontId].soundEffects[sfxId];
if (sfx == NULL) { if (sfx == NULL) {
gAudioContext.audioErrorFlags = ((bankId << 8) + sfxId) + 0x5000000; gAudioContext.audioErrorFlags = ((fontId << 8) + sfxId) + 0x5000000;
} }
if (sfx->sample == NULL) { if (sfx->sample == NULL) {
@ -395,67 +395,67 @@ AudioBankSound* Audio_GetSfx(s32 bankId, s32 sfxId) {
return sfx; return sfx;
} }
s32 func_800E7744(s32 instrument, s32 bankId, s32 instId, void* arg3) { s32 Audio_SetFontInstrument(s32 instrumentType, s32 fontId, s32 index, void* value) {
if (bankId == 0xFF) { if (fontId == 0xFF) {
return -1; return -1;
} }
if (!Audio_IsBankLoadComplete(bankId)) { if (!AudioLoad_IsFontLoadComplete(fontId)) {
return -2; return -2;
} }
switch (instrument) { switch (instrumentType) {
case 0: case 0:
if (instId >= gAudioContext.ctlEntries[bankId].numDrums) { if (index >= gAudioContext.soundFonts[fontId].numDrums) {
return -3; return -3;
} }
gAudioContext.ctlEntries[bankId].drums[instId] = arg3; gAudioContext.soundFonts[fontId].drums[index] = value;
break; break;
case 1: case 1:
if (instId >= gAudioContext.ctlEntries[bankId].numSfx) { if (index >= gAudioContext.soundFonts[fontId].numSfx) {
return -3; return -3;
} }
gAudioContext.ctlEntries[bankId].soundEffects[instId] = *(AudioBankSound*)arg3; gAudioContext.soundFonts[fontId].soundEffects[index] = *(SoundFontSound*)value;
break; break;
default: default:
if (instId >= gAudioContext.ctlEntries[bankId].numInstruments) { if (index >= gAudioContext.soundFonts[fontId].numInstruments) {
return -3; return -3;
} }
gAudioContext.ctlEntries[bankId].instruments[instId] = arg3; gAudioContext.soundFonts[fontId].instruments[index] = value;
break; break;
} }
return 0; return 0;
} }
void Audio_SeqChanLayerDecayRelease(SequenceChannelLayer* seqLayer, s32 target) { void Audio_SeqLayerDecayRelease(SequenceLayer* layer, s32 target) {
Note* note; Note* note;
NoteAttributes* attrs; NoteAttributes* attrs;
SequenceChannel* chan; SequenceChannel* chan;
s32 i; s32 i;
if (seqLayer == NO_LAYER) { if (layer == NO_LAYER) {
return; return;
} }
seqLayer->bit3 = false; layer->bit3 = false;
if (seqLayer->note == NULL) { if (layer->note == NULL) {
return; return;
} }
note = seqLayer->note; note = layer->note;
attrs = &note->playbackState.attributes; attrs = &note->playbackState.attributes;
if (note->playbackState.wantedParentLayer == seqLayer) { if (note->playbackState.wantedParentLayer == layer) {
note->playbackState.wantedParentLayer = NO_LAYER; note->playbackState.wantedParentLayer = NO_LAYER;
} }
if (note->playbackState.parentLayer != seqLayer) { if (note->playbackState.parentLayer != layer) {
if (note->playbackState.parentLayer == NO_LAYER && note->playbackState.wantedParentLayer == NO_LAYER && if (note->playbackState.parentLayer == NO_LAYER && note->playbackState.wantedParentLayer == NO_LAYER &&
note->playbackState.prevParentLayer == seqLayer && target != ADSR_STATE_DECAY) { note->playbackState.prevParentLayer == layer && target != ADSR_STATE_DECAY) {
note->playbackState.adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; note->playbackState.adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv;
note->playbackState.adsr.action.s.release = true; note->playbackState.adsr.action.s.release = true;
} }
@ -463,12 +463,12 @@ void Audio_SeqChanLayerDecayRelease(SequenceChannelLayer* seqLayer, s32 target)
} }
if (note->playbackState.adsr.action.s.state != ADSR_STATE_DECAY) { if (note->playbackState.adsr.action.s.state != ADSR_STATE_DECAY) {
attrs->freqScale = seqLayer->noteFreqScale; attrs->freqScale = layer->noteFreqScale;
attrs->velocity = seqLayer->noteVelocity; attrs->velocity = layer->noteVelocity;
attrs->pan = seqLayer->notePan; attrs->pan = layer->notePan;
if (seqLayer->seqChannel != NULL) { if (layer->channel != NULL) {
chan = seqLayer->seqChannel; chan = layer->channel;
attrs->reverb = chan->reverb; attrs->reverb = chan->reverb;
attrs->unk_1 = chan->unk_0C; attrs->unk_1 = chan->unk_0C;
attrs->filter = chan->filter; attrs->filter = chan->filter;
@ -483,17 +483,17 @@ void Audio_SeqChanLayerDecayRelease(SequenceChannelLayer* seqLayer, s32 target)
attrs->unk_6 = chan->unk_20; attrs->unk_6 = chan->unk_20;
attrs->unk_4 = chan->unk_0F; attrs->unk_4 = chan->unk_0F;
if (chan->seqPlayer->muted && (chan->muteBehavior & 8)) { if (chan->seqPlayer->muted && (chan->muteBehavior & 8)) {
note->noteSubEu.bitField0.s.finished = true; note->noteSubEu.bitField0.finished = true;
} }
if (seqLayer->stereo.asByte == 0) { if (layer->stereo.asByte == 0) {
attrs->stereo = chan->stereo; attrs->stereo = chan->stereo;
} else { } else {
attrs->stereo = seqLayer->stereo; attrs->stereo = layer->stereo;
} }
note->playbackState.priority = chan->someOtherPriority; note->playbackState.priority = chan->someOtherPriority;
} else { } else {
attrs->stereo = seqLayer->stereo; attrs->stereo = layer->stereo;
note->playbackState.priority = 1; note->playbackState.priority = 1;
} }
@ -506,13 +506,13 @@ void Audio_SeqChanLayerDecayRelease(SequenceChannelLayer* seqLayer, s32 target)
} else { } else {
note->playbackState.unk_04 = 1; note->playbackState.unk_04 = 1;
note->playbackState.adsr.action.s.decay = true; note->playbackState.adsr.action.s.decay = true;
if (seqLayer->adsr.releaseRate == 0) { if (layer->adsr.releaseRate == 0) {
note->playbackState.adsr.fadeOutVel = gAudioContext.unk_3520[seqLayer->seqChannel->adsr.releaseRate]; note->playbackState.adsr.fadeOutVel = gAudioContext.unk_3520[layer->channel->adsr.releaseRate];
} else { } else {
note->playbackState.adsr.fadeOutVel = gAudioContext.unk_3520[seqLayer->adsr.releaseRate]; note->playbackState.adsr.fadeOutVel = gAudioContext.unk_3520[layer->adsr.releaseRate];
} }
note->playbackState.adsr.sustain = note->playbackState.adsr.sustain =
((f32)(s32)(seqLayer->seqChannel->adsr.sustain) * note->playbackState.adsr.current) / 256.0f; ((f32)(s32)(layer->channel->adsr.sustain) * note->playbackState.adsr.current) / 256.0f;
} }
} }
@ -522,15 +522,15 @@ void Audio_SeqChanLayerDecayRelease(SequenceChannelLayer* seqLayer, s32 target)
} }
} }
void Audio_SeqChanLayerNoteDecay(SequenceChannelLayer* seqLayer) { void Audio_SeqLayerNoteDecay(SequenceLayer* layer) {
Audio_SeqChanLayerDecayRelease(seqLayer, ADSR_STATE_DECAY); Audio_SeqLayerDecayRelease(layer, ADSR_STATE_DECAY);
} }
void Audio_SeqChanLayerNoteRelease(SequenceChannelLayer* seqLayer) { void Audio_SeqLayerNoteRelease(SequenceLayer* layer) {
Audio_SeqChanLayerDecayRelease(seqLayer, ADSR_STATE_RELEASE); Audio_SeqLayerDecayRelease(layer, ADSR_STATE_RELEASE);
} }
s32 Audio_BuildSyntheticWave(Note* note, SequenceChannelLayer* seqLayer, s32 waveId) { s32 Audio_BuildSyntheticWave(Note* note, SequenceLayer* layer, s32 waveId) {
f32 freqScale; f32 freqScale;
f32 ratio; f32 ratio;
u8 sampleCountIndex; u8 sampleCountIndex;
@ -539,9 +539,9 @@ s32 Audio_BuildSyntheticWave(Note* note, SequenceChannelLayer* seqLayer, s32 wav
waveId = 128; waveId = 128;
} }
freqScale = seqLayer->freqScale; freqScale = layer->freqScale;
if (seqLayer->portamento.mode != 0 && 0.0f < seqLayer->portamento.extent) { if (layer->portamento.mode != 0 && 0.0f < layer->portamento.extent) {
freqScale *= (seqLayer->portamento.extent + 1.0f); freqScale *= (layer->portamento.extent + 1.0f);
} }
if (freqScale < 0.99999f) { if (freqScale < 0.99999f) {
sampleCountIndex = 0; sampleCountIndex = 0;
@ -556,7 +556,7 @@ s32 Audio_BuildSyntheticWave(Note* note, SequenceChannelLayer* seqLayer, s32 wav
sampleCountIndex = 3; sampleCountIndex = 3;
ratio = 0.13081f; ratio = 0.13081f;
} }
seqLayer->freqScale *= ratio; layer->freqScale *= ratio;
note->playbackState.waveId = waveId; note->playbackState.waveId = waveId;
note->playbackState.sampleCountIndex = sampleCountIndex; note->playbackState.sampleCountIndex = sampleCountIndex;
@ -565,17 +565,17 @@ s32 Audio_BuildSyntheticWave(Note* note, SequenceChannelLayer* seqLayer, s32 wav
return sampleCountIndex; return sampleCountIndex;
} }
void Audio_InitSyntheticWave(Note* note, SequenceChannelLayer* seqLayer) { void Audio_InitSyntheticWave(Note* note, SequenceLayer* layer) {
s32 sampleCountIndex; s32 sampleCountIndex;
s32 waveSampleCountIndex; s32 waveSampleCountIndex;
s32 waveId = seqLayer->instOrWave; s32 waveId = layer->instOrWave;
if (waveId == 0xFF) { if (waveId == 0xFF) {
waveId = seqLayer->seqChannel->instOrWave; waveId = layer->channel->instOrWave;
} }
sampleCountIndex = note->playbackState.sampleCountIndex; sampleCountIndex = note->playbackState.sampleCountIndex;
waveSampleCountIndex = Audio_BuildSyntheticWave(note, seqLayer, waveId); waveSampleCountIndex = Audio_BuildSyntheticWave(note, layer, waveId);
if (waveSampleCountIndex != sampleCountIndex) { if (waveSampleCountIndex != sampleCountIndex) {
note->noteSubEu.unk_06 = waveSampleCountIndex * 4 + sampleCountIndex; note->noteSubEu.unk_06 = waveSampleCountIndex * 4 + sampleCountIndex;
@ -603,10 +603,10 @@ void Audio_InitNoteFreeList(void) {
s32 i; s32 i;
Audio_InitNoteLists(&gAudioContext.noteFreeLists); Audio_InitNoteLists(&gAudioContext.noteFreeLists);
for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) { for (i = 0; i < gAudioContext.numNotes; i++) {
gAudioContext.notes[i].listItem.u.value = &gAudioContext.notes[i]; gAudioContext.notes[i].listItem.u.value = &gAudioContext.notes[i];
gAudioContext.notes[i].listItem.prev = NULL; gAudioContext.notes[i].listItem.prev = NULL;
Audio_AudioListPushBack(&gAudioContext.noteFreeLists.disabled, &gAudioContext.notes[i].listItem); AudioSeq_AudioListPushBack(&gAudioContext.noteFreeLists.disabled, &gAudioContext.notes[i].listItem);
} }
} }
@ -645,7 +645,7 @@ void Audio_NotePoolClear(NotePool* pool) {
break; break;
} }
Audio_AudioListRemove(cur); Audio_AudioListRemove(cur);
Audio_AudioListPushBack(dest, cur); AudioSeq_AudioListPushBack(dest, cur);
} }
} }
} }
@ -687,11 +687,11 @@ void Audio_NotePoolFill(NotePool* pool, s32 count) {
} }
while (j < count) { while (j < count) {
note = Audio_AudioListPopBack(source); note = AudioSeq_AudioListPopBack(source);
if (note == NULL) { if (note == NULL) {
break; break;
} }
Audio_AudioListPushBack(dest, &note->listItem); AudioSeq_AudioListPushBack(dest, &note->listItem);
j++; j++;
} }
} }
@ -718,7 +718,7 @@ void Audio_AudioListRemove(AudioListItem* item) {
} }
} }
Note* Audio_PopNodeWithValueLessEqual(AudioListItem* list, s32 limit) { Note* Audio_FindNodeWithPrioLessThan(AudioListItem* list, s32 limit) {
AudioListItem* cur = list->next; AudioListItem* cur = list->next;
AudioListItem* best; AudioListItem* best;
@ -743,89 +743,90 @@ Note* Audio_PopNodeWithValueLessEqual(AudioListItem* list, s32 limit) {
return best->u.value; return best->u.value;
} }
void Audio_NoteInitForLayer(Note* note, SequenceChannelLayer* seqLayer) { void Audio_NoteInitForLayer(Note* note, SequenceLayer* layer) {
s32 pad[3]; s32 pad[3];
s16 instId; s16 instId;
NotePlaybackState* playback = &note->playbackState; NotePlaybackState* playback = &note->playbackState;
NoteSubEu* sub = &note->noteSubEu; NoteSubEu* sub = &note->noteSubEu;
note->playbackState.prevParentLayer = NO_LAYER; note->playbackState.prevParentLayer = NO_LAYER;
note->playbackState.parentLayer = seqLayer; note->playbackState.parentLayer = layer;
playback->priority = seqLayer->seqChannel->notePriority; playback->priority = layer->channel->notePriority;
seqLayer->notePropertiesNeedInit = true; layer->notePropertiesNeedInit = true;
seqLayer->bit3 = true; layer->bit3 = true;
seqLayer->note = note; layer->note = note;
seqLayer->seqChannel->noteUnused = note; layer->channel->noteUnused = note;
seqLayer->seqChannel->layerUnused = seqLayer; layer->channel->layerUnused = layer;
seqLayer->noteVelocity = 0.0f; layer->noteVelocity = 0.0f;
Audio_NoteInit(note); Audio_NoteInit(note);
instId = seqLayer->instOrWave; instId = layer->instOrWave;
if (instId == 0xFF) { if (instId == 0xFF) {
instId = seqLayer->seqChannel->instOrWave; instId = layer->channel->instOrWave;
} }
sub->sound.audioBankSound = seqLayer->sound; sub->sound.soundFontSound = layer->sound;
if (instId >= 0x80 && instId < 0xC0) { if (instId >= 0x80 && instId < 0xC0) {
sub->bitField1.s.isSyntheticWave = true; sub->bitField1.isSyntheticWave = true;
} else { } else {
sub->bitField1.s.isSyntheticWave = false; sub->bitField1.isSyntheticWave = false;
} }
if (sub->bitField1.s.isSyntheticWave) { if (sub->bitField1.isSyntheticWave) {
Audio_BuildSyntheticWave(note, seqLayer, instId); Audio_BuildSyntheticWave(note, layer, instId);
} }
playback->bankId = seqLayer->seqChannel->bankId; playback->fontId = layer->channel->fontId;
playback->stereoHeadsetEffects = seqLayer->seqChannel->stereoHeadsetEffects; playback->stereoHeadsetEffects = layer->channel->stereoHeadsetEffects;
sub->bitField1.s.reverbIndex = seqLayer->seqChannel->reverbIndex & 3; sub->bitField1.reverbIndex = layer->channel->reverbIndex & 3;
} }
void func_800E82C0(Note* note, SequenceChannelLayer* seqLayer) { void func_800E82C0(Note* note, SequenceLayer* layer) {
Audio_SeqChanLayerNoteRelease(note->playbackState.parentLayer); // similar to Audio_NoteReleaseAndTakeOwnership, hard to say what the difference is
note->playbackState.wantedParentLayer = seqLayer; Audio_SeqLayerNoteRelease(note->playbackState.parentLayer);
note->playbackState.wantedParentLayer = layer;
} }
void Audio_NoteReleaseAndTakeOwnership(Note* note, SequenceChannelLayer* seqLayer) { void Audio_NoteReleaseAndTakeOwnership(Note* note, SequenceLayer* layer) {
note->playbackState.wantedParentLayer = seqLayer; note->playbackState.wantedParentLayer = layer;
note->playbackState.priority = seqLayer->seqChannel->notePriority; note->playbackState.priority = layer->channel->notePriority;
note->playbackState.adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; note->playbackState.adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv;
note->playbackState.adsr.action.s.release = true; note->playbackState.adsr.action.s.release = true;
} }
Note* Audio_AllocNoteFromDisabled(NotePool* pool, SequenceChannelLayer* seqLayer) { Note* Audio_AllocNoteFromDisabled(NotePool* pool, SequenceLayer* layer) {
Note* note = Audio_AudioListPopBack(&pool->disabled); Note* note = AudioSeq_AudioListPopBack(&pool->disabled);
if (note != NULL) { if (note != NULL) {
Audio_NoteInitForLayer(note, seqLayer); Audio_NoteInitForLayer(note, layer);
Audio_AudioListPushFront(&pool->active, &note->listItem); Audio_AudioListPushFront(&pool->active, &note->listItem);
} }
return note; return note;
} }
Note* Audio_AllocNoteFromDecaying(NotePool* pool, SequenceChannelLayer* seqLayer) { Note* Audio_AllocNoteFromDecaying(NotePool* pool, SequenceLayer* layer) {
Note* note = Audio_AudioListPopBack(&pool->decaying); Note* note = AudioSeq_AudioListPopBack(&pool->decaying);
if (note != NULL) { if (note != NULL) {
Audio_NoteReleaseAndTakeOwnership(note, seqLayer); Audio_NoteReleaseAndTakeOwnership(note, layer);
Audio_AudioListPushBack(&pool->releasing, &note->listItem); AudioSeq_AudioListPushBack(&pool->releasing, &note->listItem);
} }
return note; return note;
} }
Note* Audio_AllocNoteFromActive(NotePool* pool, SequenceChannelLayer* seqLayer) { Note* Audio_AllocNoteFromActive(NotePool* pool, SequenceLayer* layer) {
Note* rNote; Note* rNote;
Note* aNote; Note* aNote;
s32 rPriority; s32 rPriority;
s32 aPriority; s32 aPriority;
rPriority = aPriority = 0x10; rPriority = aPriority = 0x10;
rNote = Audio_PopNodeWithValueLessEqual(&pool->releasing, seqLayer->seqChannel->notePriority); rNote = Audio_FindNodeWithPrioLessThan(&pool->releasing, layer->channel->notePriority);
if (rNote != NULL) { if (rNote != NULL) {
rPriority = rNote->playbackState.priority; rPriority = rNote->playbackState.priority;
} }
aNote = Audio_PopNodeWithValueLessEqual(&pool->active, seqLayer->seqChannel->notePriority); aNote = Audio_FindNodeWithPrioLessThan(&pool->active, layer->channel->notePriority);
if (aNote != NULL) { if (aNote != NULL) {
aPriority = aNote->playbackState.priority; aPriority = aNote->playbackState.priority;
@ -837,76 +838,76 @@ Note* Audio_AllocNoteFromActive(NotePool* pool, SequenceChannelLayer* seqLayer)
if (aPriority < rPriority) { if (aPriority < rPriority) {
Audio_AudioListRemove(&aNote->listItem); Audio_AudioListRemove(&aNote->listItem);
func_800E82C0(aNote, seqLayer); func_800E82C0(aNote, layer);
Audio_AudioListPushBack(&pool->releasing, &aNote->listItem); AudioSeq_AudioListPushBack(&pool->releasing, &aNote->listItem);
aNote->playbackState.priority = seqLayer->seqChannel->notePriority; aNote->playbackState.priority = layer->channel->notePriority;
return aNote; return aNote;
} }
rNote->playbackState.wantedParentLayer = seqLayer; rNote->playbackState.wantedParentLayer = layer;
rNote->playbackState.priority = seqLayer->seqChannel->notePriority; rNote->playbackState.priority = layer->channel->notePriority;
return rNote; return rNote;
} }
Note* Audio_AllocNote(SequenceChannelLayer* seqLayer) { Note* Audio_AllocNote(SequenceLayer* layer) {
Note* ret; Note* ret;
u32 policy = seqLayer->seqChannel->noteAllocPolicy; u32 policy = layer->channel->noteAllocPolicy;
if (policy & 1) { if (policy & 1) {
ret = seqLayer->note; ret = layer->note;
if (ret != NULL && ret->playbackState.prevParentLayer == seqLayer && if (ret != NULL && ret->playbackState.prevParentLayer == layer &&
ret->playbackState.wantedParentLayer == NO_LAYER) { ret->playbackState.wantedParentLayer == NO_LAYER) {
Audio_NoteReleaseAndTakeOwnership(ret, seqLayer); Audio_NoteReleaseAndTakeOwnership(ret, layer);
Audio_AudioListRemove(&ret->listItem); Audio_AudioListRemove(&ret->listItem);
Audio_AudioListPushBack(&ret->listItem.pool->releasing, &ret->listItem); AudioSeq_AudioListPushBack(&ret->listItem.pool->releasing, &ret->listItem);
return ret; return ret;
} }
} }
if (policy & 2) { if (policy & 2) {
if (!(ret = Audio_AllocNoteFromDisabled(&seqLayer->seqChannel->notePool, seqLayer)) && if (!(ret = Audio_AllocNoteFromDisabled(&layer->channel->notePool, layer)) &&
!(ret = Audio_AllocNoteFromDecaying(&seqLayer->seqChannel->notePool, seqLayer)) && !(ret = Audio_AllocNoteFromDecaying(&layer->channel->notePool, layer)) &&
!(ret = Audio_AllocNoteFromActive(&seqLayer->seqChannel->notePool, seqLayer))) { !(ret = Audio_AllocNoteFromActive(&layer->channel->notePool, layer))) {
goto null_return; goto null_return;
} }
return ret; return ret;
} }
if (policy & 4) { if (policy & 4) {
if (!(ret = Audio_AllocNoteFromDisabled(&seqLayer->seqChannel->notePool, seqLayer)) && if (!(ret = Audio_AllocNoteFromDisabled(&layer->channel->notePool, layer)) &&
!(ret = Audio_AllocNoteFromDisabled(&seqLayer->seqChannel->seqPlayer->notePool, seqLayer)) && !(ret = Audio_AllocNoteFromDisabled(&layer->channel->seqPlayer->notePool, layer)) &&
!(ret = Audio_AllocNoteFromDecaying(&seqLayer->seqChannel->notePool, seqLayer)) && !(ret = Audio_AllocNoteFromDecaying(&layer->channel->notePool, layer)) &&
!(ret = Audio_AllocNoteFromDecaying(&seqLayer->seqChannel->seqPlayer->notePool, seqLayer)) && !(ret = Audio_AllocNoteFromDecaying(&layer->channel->seqPlayer->notePool, layer)) &&
!(ret = Audio_AllocNoteFromActive(&seqLayer->seqChannel->notePool, seqLayer)) && !(ret = Audio_AllocNoteFromActive(&layer->channel->notePool, layer)) &&
!(ret = Audio_AllocNoteFromActive(&seqLayer->seqChannel->seqPlayer->notePool, seqLayer))) { !(ret = Audio_AllocNoteFromActive(&layer->channel->seqPlayer->notePool, layer))) {
goto null_return; goto null_return;
} }
return ret; return ret;
} }
if (policy & 8) { if (policy & 8) {
if (!(ret = Audio_AllocNoteFromDisabled(&gAudioContext.noteFreeLists, seqLayer)) && if (!(ret = Audio_AllocNoteFromDisabled(&gAudioContext.noteFreeLists, layer)) &&
!(ret = Audio_AllocNoteFromDecaying(&gAudioContext.noteFreeLists, seqLayer)) && !(ret = Audio_AllocNoteFromDecaying(&gAudioContext.noteFreeLists, layer)) &&
!(ret = Audio_AllocNoteFromActive(&gAudioContext.noteFreeLists, seqLayer))) { !(ret = Audio_AllocNoteFromActive(&gAudioContext.noteFreeLists, layer))) {
goto null_return; goto null_return;
} }
return ret; return ret;
} }
if (!(ret = Audio_AllocNoteFromDisabled(&seqLayer->seqChannel->notePool, seqLayer)) && if (!(ret = Audio_AllocNoteFromDisabled(&layer->channel->notePool, layer)) &&
!(ret = Audio_AllocNoteFromDisabled(&seqLayer->seqChannel->seqPlayer->notePool, seqLayer)) && !(ret = Audio_AllocNoteFromDisabled(&layer->channel->seqPlayer->notePool, layer)) &&
!(ret = Audio_AllocNoteFromDisabled(&gAudioContext.noteFreeLists, seqLayer)) && !(ret = Audio_AllocNoteFromDisabled(&gAudioContext.noteFreeLists, layer)) &&
!(ret = Audio_AllocNoteFromDecaying(&seqLayer->seqChannel->notePool, seqLayer)) && !(ret = Audio_AllocNoteFromDecaying(&layer->channel->notePool, layer)) &&
!(ret = Audio_AllocNoteFromDecaying(&seqLayer->seqChannel->seqPlayer->notePool, seqLayer)) && !(ret = Audio_AllocNoteFromDecaying(&layer->channel->seqPlayer->notePool, layer)) &&
!(ret = Audio_AllocNoteFromDecaying(&gAudioContext.noteFreeLists, seqLayer)) && !(ret = Audio_AllocNoteFromDecaying(&gAudioContext.noteFreeLists, layer)) &&
!(ret = Audio_AllocNoteFromActive(&seqLayer->seqChannel->notePool, seqLayer)) && !(ret = Audio_AllocNoteFromActive(&layer->channel->notePool, layer)) &&
!(ret = Audio_AllocNoteFromActive(&seqLayer->seqChannel->seqPlayer->notePool, seqLayer)) && !(ret = Audio_AllocNoteFromActive(&layer->channel->seqPlayer->notePool, layer)) &&
!(ret = Audio_AllocNoteFromActive(&gAudioContext.noteFreeLists, seqLayer))) { !(ret = Audio_AllocNoteFromActive(&gAudioContext.noteFreeLists, layer))) {
goto null_return; goto null_return;
} }
return ret; return ret;
null_return: null_return:
seqLayer->bit3 = true; layer->bit3 = true;
return NULL; return NULL;
} }
@ -914,7 +915,7 @@ void Audio_NoteInitAll(void) {
Note* note; Note* note;
s32 i; s32 i;
for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) { for (i = 0; i < gAudioContext.numNotes; i++) {
note = &gAudioContext.notes[i]; note = &gAudioContext.notes[i];
note->noteSubEu = gZeroNoteSub; note->noteSubEu = gZeroNoteSub;
note->playbackState.priority = 0; note->playbackState.priority = 0;
@ -924,13 +925,13 @@ void Audio_NoteInitAll(void) {
note->playbackState.prevParentLayer = NO_LAYER; note->playbackState.prevParentLayer = NO_LAYER;
note->playbackState.waveId = 0; note->playbackState.waveId = 0;
note->playbackState.attributes.velocity = 0.0f; note->playbackState.attributes.velocity = 0.0f;
note->playbackState.adsrVolScale = 0; note->playbackState.adsrVolScaleUnused = 0;
note->playbackState.adsr.action.asByte = 0; note->playbackState.adsr.action.asByte = 0;
note->vibratoState.active = 0; note->vibratoState.active = 0;
note->portamento.cur = 0; note->portamento.cur = 0;
note->portamento.speed = 0; note->portamento.speed = 0;
note->playbackState.stereoHeadsetEffects = false; note->playbackState.stereoHeadsetEffects = false;
note->unk_BC = 0; note->unk_BC = 0;
note->synthesisState.synthesisBuffers = Audio_AllocDmaMemory(&gAudioContext.notesAndBuffersPool, 0x1E0); note->synthesisState.synthesisBuffers = AudioHeap_AllocDmaMemory(&gAudioContext.notesAndBuffersPool, 0x1E0);
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -112,14 +112,14 @@ void func_800DB03C(s32 arg0) {
s32 baseIndex; s32 baseIndex;
s32 i; s32 i;
baseIndex = gAudioContext.maxSimultaneousNotes * arg0; baseIndex = gAudioContext.numNotes * arg0;
for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) { for (i = 0; i < gAudioContext.numNotes; i++) {
subEu = &gAudioContext.notes[i].noteSubEu; subEu = &gAudioContext.notes[i].noteSubEu;
subEu2 = &gAudioContext.noteSubsEu[baseIndex + i]; subEu2 = &gAudioContext.noteSubsEu[baseIndex + i];
if (subEu->bitField0.s.enabled) { if (subEu->bitField0.enabled) {
subEu->bitField0.s.needsInit = false; subEu->bitField0.needsInit = false;
} else { } else {
subEu2->bitField0.s.enabled = false; subEu2->bitField0.enabled = false;
} }
subEu->unk_06 = 0; subEu->unk_06 = 0;
@ -136,7 +136,7 @@ Acmd* AudioSynth_Update(Acmd* cmdStart, s32* cmdCnt, s16* aiStart, s32 aiBufLen)
cmdP = cmdStart; cmdP = cmdStart;
for (i = gAudioContext.audioBufferParameters.updatesPerFrame; i > 0; i--) { for (i = gAudioContext.audioBufferParameters.updatesPerFrame; i > 0; i--) {
Audio_ProcessSequences(i - 1); AudioSeq_ProcessSequences(i - 1);
func_800DB03C(gAudioContext.audioBufferParameters.updatesPerFrame - i); func_800DB03C(gAudioContext.audioBufferParameters.updatesPerFrame - i);
} }
@ -181,9 +181,9 @@ void func_800DB2C0(s32 updateIndexStart, s32 noteIndex) {
s32 i; s32 i;
for (i = updateIndexStart + 1; i < gAudioContext.audioBufferParameters.updatesPerFrame; i++) { for (i = updateIndexStart + 1; i < gAudioContext.audioBufferParameters.updatesPerFrame; i++) {
temp_v1 = &gAudioContext.noteSubsEu[(gAudioContext.maxSimultaneousNotes * i) + noteIndex]; temp_v1 = &gAudioContext.noteSubsEu[(gAudioContext.numNotes * i) + noteIndex];
if (!temp_v1->bitField0.s.needsInit) { if (!temp_v1->bitField0.needsInit) {
temp_v1->bitField0.s.enabled = 0; temp_v1->bitField0.enabled = 0;
} else { } else {
break; break;
} }
@ -442,11 +442,11 @@ void func_800DBE64(void) {
void func_800DBE6C(void) { void func_800DBE6C(void) {
} }
void AudioSynth_SetFilter(Acmd* cmd, s32 flags, s32 countOrBuf, s32 addr) { void AudioSynth_LoadFilter(Acmd* cmd, s32 flags, s32 countOrBuf, s32 addr) {
aFilter(cmd, flags, countOrBuf, addr); aFilter(cmd, flags, countOrBuf, addr);
} }
void AudioSynth_SetFilterCount(Acmd* cmd, s32 count, s32 addr) { void AudioSynth_LoadFilterCount(Acmd* cmd, s32 count, s32 addr) {
aFilter(cmd, 2, count, addr); aFilter(cmd, 2, count, addr);
} }
@ -563,28 +563,27 @@ Acmd* AudioSynth_DoOneAudioUpdate(s16* aiBuf, s32 aiBufLen, Acmd* cmd, s32 updat
NoteSubEu* noteSubEu2; NoteSubEu* noteSubEu2;
s32 unk14; s32 unk14;
t = gAudioContext.maxSimultaneousNotes * updateIndex; t = gAudioContext.numNotes * updateIndex;
count = 0; count = 0;
if (gAudioContext.numSynthesisReverbs == 0) { if (gAudioContext.numSynthesisReverbs == 0) {
for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) { for (i = 0; i < gAudioContext.numNotes; i++) {
if (gAudioContext.noteSubsEu[t + i].bitField0.s.enabled) { if (gAudioContext.noteSubsEu[t + i].bitField0.enabled) {
noteIndices[count++] = i; noteIndices[count++] = i;
} }
} }
} else { } else {
for (reverbIndex = 0; reverbIndex < gAudioContext.numSynthesisReverbs; reverbIndex++) { for (reverbIndex = 0; reverbIndex < gAudioContext.numSynthesisReverbs; reverbIndex++) {
for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) { for (i = 0; i < gAudioContext.numNotes; i++) {
noteSubEu = &gAudioContext.noteSubsEu[t + i]; noteSubEu = &gAudioContext.noteSubsEu[t + i];
if (noteSubEu->bitField0.s.enabled && noteSubEu->bitField1.s.reverbIndex == reverbIndex) { if (noteSubEu->bitField0.enabled && noteSubEu->bitField1.reverbIndex == reverbIndex) {
noteIndices[count++] = i; noteIndices[count++] = i;
} }
} }
} }
for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) { for (i = 0; i < gAudioContext.numNotes; i++) {
noteSubEu = &gAudioContext.noteSubsEu[t + i]; noteSubEu = &gAudioContext.noteSubsEu[t + i];
if (noteSubEu->bitField0.s.enabled && if (noteSubEu->bitField0.enabled && noteSubEu->bitField1.reverbIndex >= gAudioContext.numSynthesisReverbs) {
noteSubEu->bitField1.s.reverbIndex >= gAudioContext.numSynthesisReverbs) {
noteIndices[count++] = i; noteIndices[count++] = i;
} }
} }
@ -620,7 +619,7 @@ Acmd* AudioSynth_DoOneAudioUpdate(s16* aiBuf, s32 aiBufLen, Acmd* cmd, s32 updat
while (i < count) { while (i < count) {
noteSubEu2 = &gAudioContext.noteSubsEu[noteIndices[i] + t]; noteSubEu2 = &gAudioContext.noteSubsEu[noteIndices[i] + t];
if (noteSubEu2->bitField1.s.reverbIndex == reverbIndex) { if (noteSubEu2->bitField1.reverbIndex == reverbIndex) {
cmd = AudioSynth_ProcessNote(noteIndices[i], noteSubEu2, cmd = AudioSynth_ProcessNote(noteIndices[i], noteSubEu2,
&gAudioContext.notes[noteIndices[i]].synthesisState, aiBuf, aiBufLen, cmd, &gAudioContext.notes[noteIndices[i]].synthesisState, aiBuf, aiBufLen, cmd,
updateIndex); updateIndex);
@ -662,43 +661,43 @@ Acmd* AudioSynth_DoOneAudioUpdate(s16* aiBuf, s32 aiBufLen, Acmd* cmd, s32 updat
Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisState* synthState, s16* aiBuf, Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisState* synthState, s16* aiBuf,
s32 aiBufLen, Acmd* cmd, s32 updateIndex) { s32 aiBufLen, Acmd* cmd, s32 updateIndex) {
s32 pad1[3]; s32 pad1[3];
AudioBankSample* audioBankSample; SoundFontSample* audioFontSample;
AdpcmLoop* loopInfo; AdpcmLoop* loopInfo;
s32 samplesRemaining; s32 nSamplesUntilLoopEnd;
s32 nSamplesInThisIteration; s32 nSamplesInThisIteration;
s32 noteFinished; s32 noteFinished;
s32 restart; s32 restart;
s32 flags; s32 flags;
u16 resamplingRateFixedPoint; u16 resamplingRateFixedPoint;
s32 phi_s6; s32 nSamplesInFirstFrame;
s32 phi_s7; s32 nTrailingSamplesToIgnore;
s32 phi_a1_2; s32 phi_a1_2;
s32 temp_v1_5; s32 frameIndex;
s32 sp120; s32 skipBytes;
s32 temp_v1_6; s32 temp_v1_6;
void* buf; void* buf;
s32 phi_s0; s32 nSamplesToDecode;
s32 sampleAddr; u32 sampleAddr;
u32 samplesLenFixedPoint; u32 samplesLenFixedPoint;
s32 samplesLenAdjusted; s32 samplesLenAdjusted;
s32 nAdpcmSamplesProcessed; s32 nSamplesProcessed;
s32 endPos; s32 loopEndPos;
s32 nSamplesToProcess; s32 nSamplesToProcess;
s32 phi_s4; s32 phi_s4;
s32 phi_s3; s32 nFirstFrameSamplesToIgnore;
s32 pad2[7]; s32 pad2[7];
s32 spD4; s32 frameSize;
s32 phi_s1; s32 nFramesToDecode;
s32 spCC; s32 skipInitialSamples;
s32 spC8; s32 sampleDataStart;
u8* phi_a1; u8* sampleData;
s32 nParts; s32 nParts;
s32 curPart; s32 curPart;
s32 phi_t0; s32 sampleDataStartPad;
s32 side; s32 side;
s32 resampledTempLen; s32 resampledTempLen;
u16 noteSamplesDmemAddrBeforeResampling; u16 noteSamplesDmemAddrBeforeResampling;
s32 temp_mult; s32 sampleDataOffset;
s32 thing; s32 thing;
s32 s5; s32 s5;
Note* note; Note* note;
@ -712,12 +711,12 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
s16 addr; s16 addr;
u16 unused; u16 unused;
bookOffset = noteSubEu->bitField1.s.bookOffset; bookOffset = noteSubEu->bitField1.bookOffset;
finished = noteSubEu->bitField0.s.finished; finished = noteSubEu->bitField0.finished;
note = &gAudioContext.notes[noteIndex]; note = &gAudioContext.notes[noteIndex];
flags = A_CONTINUE; flags = A_CONTINUE;
if (noteSubEu->bitField0.s.needsInit == true) { if (noteSubEu->bitField0.needsInit == true) {
flags = A_INIT; flags = A_INIT;
synthState->restart = 0; synthState->restart = 0;
synthState->samplePosInt = note->unk_BC; synthState->samplePosInt = note->unk_BC;
@ -727,42 +726,40 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
synthState->prevHeadsetPanRight = 0; synthState->prevHeadsetPanRight = 0;
synthState->prevHeadsetPanLeft = 0; synthState->prevHeadsetPanLeft = 0;
synthState->reverbVol = noteSubEu->reverbVol; synthState->reverbVol = noteSubEu->reverbVol;
synthState->numAdpcmParts = 0; synthState->numParts = 0;
synthState->unk_1A = 1; synthState->unk_1A = 1;
note->noteSubEu.bitField0.s.finished = false; note->noteSubEu.bitField0.finished = false;
finished = false; finished = false;
} }
resamplingRateFixedPoint = noteSubEu->resamplingRateFixedPoint; resamplingRateFixedPoint = noteSubEu->resamplingRateFixedPoint;
nParts = noteSubEu->bitField1.s.hasTwoAdpcmParts + 1; nParts = noteSubEu->bitField1.hasTwoParts + 1;
samplesLenFixedPoint = (resamplingRateFixedPoint * aiBufLen * 2) + synthState->samplePosFrac; samplesLenFixedPoint = (resamplingRateFixedPoint * aiBufLen * 2) + synthState->samplePosFrac;
nSamplesToLoad = samplesLenFixedPoint >> 16; nSamplesToLoad = samplesLenFixedPoint >> 16;
synthState->samplePosFrac = samplesLenFixedPoint & 0xFFFF; synthState->samplePosFrac = samplesLenFixedPoint & 0xFFFF;
// Partially-optimized out no-op ifs required for matching. SM64 decomp // Partially-optimized out no-op ifs required for matching. SM64 decomp
// makes it clear that this is how it should look. // makes it clear that this is how it should look.
if (synthState->numAdpcmParts == 1 && nParts == 2) { if (synthState->numParts == 1 && nParts == 2) {
} else if (synthState->numAdpcmParts == 2 && nParts == 1) { } else if (synthState->numParts == 2 && nParts == 1) {
} else { } else {
} }
synthState->numAdpcmParts = nParts; synthState->numParts = nParts;
if (noteSubEu->bitField1.s.isSyntheticWave) { if (noteSubEu->bitField1.isSyntheticWave) {
cmd = AudioSynth_LoadWaveSamples(cmd, noteSubEu, synthState, nSamplesToLoad); cmd = AudioSynth_LoadWaveSamples(cmd, noteSubEu, synthState, nSamplesToLoad);
noteSamplesDmemAddrBeforeResampling = DMEM_UNCOMPRESSED_NOTE + (synthState->samplePosInt * 2); noteSamplesDmemAddrBeforeResampling = DMEM_UNCOMPRESSED_NOTE + (synthState->samplePosInt * 2);
synthState->samplePosInt += nSamplesToLoad; synthState->samplePosInt += nSamplesToLoad;
} else { } else {
// ADPCM note audioFontSample = noteSubEu->sound.soundFontSound->sample;
audioBankSample = noteSubEu->sound.audioBankSound->sample; loopInfo = audioFontSample->loop;
loopInfo = audioBankSample->loop; loopEndPos = loopInfo->end;
endPos = loopInfo->end; sampleAddr = audioFontSample->sampleAddr;
sampleAddr = audioBankSample->sampleAddr;
resampledTempLen = 0; resampledTempLen = 0;
for (curPart = 0; curPart < nParts; curPart++) { for (curPart = 0; curPart < nParts; curPart++) {
// reordering in the loop prelude nSamplesProcessed = 0;
nAdpcmSamplesProcessed = 0;
s5 = 0; s5 = 0;
if (nParts == 1) { if (nParts == 1) {
@ -773,8 +770,8 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
samplesLenAdjusted = nSamplesToLoad; samplesLenAdjusted = nSamplesToLoad;
} }
if (audioBankSample->codec == 0 || audioBankSample->codec == 3) { if (audioFontSample->codec == CODEC_ADPCM || audioFontSample->codec == CODEC_SMALL_ADPCM) {
if (gAudioContext.curLoadedBook != (*audioBankSample->book).book) { if (gAudioContext.curLoadedBook != audioFontSample->book->book) {
u32 nEntries; u32 nEntries;
switch (bookOffset) { switch (bookOffset) {
case 1: case 1:
@ -783,43 +780,43 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
case 2: case 2:
case 3: case 3:
default: default:
gAudioContext.curLoadedBook = (*audioBankSample->book).book; gAudioContext.curLoadedBook = audioFontSample->book->book;
break; break;
} }
if (1) {} if (1) {}
if (1) {} if (1) {}
if (1) {} if (1) {}
nEntries = 16 * audioBankSample->book->order * audioBankSample->book->npredictors; nEntries = 16 * audioFontSample->book->order * audioFontSample->book->npredictors;
aLoadADPCM(cmd++, nEntries, gAudioContext.curLoadedBook); aLoadADPCM(cmd++, nEntries, gAudioContext.curLoadedBook);
} }
} }
while (nAdpcmSamplesProcessed != samplesLenAdjusted) { while (nSamplesProcessed != samplesLenAdjusted) {
noteFinished = false; noteFinished = false;
restart = false; restart = false;
phi_s4 = 0; phi_s4 = 0;
phi_s3 = synthState->samplePosInt & 0xF; nFirstFrameSamplesToIgnore = synthState->samplePosInt & 0xF;
samplesRemaining = endPos - synthState->samplePosInt; nSamplesUntilLoopEnd = loopEndPos - synthState->samplePosInt;
nSamplesToProcess = samplesLenAdjusted - nAdpcmSamplesProcessed; nSamplesToProcess = samplesLenAdjusted - nSamplesProcessed;
if (phi_s3 == 0 && synthState->restart == false) { if (nFirstFrameSamplesToIgnore == 0 && !synthState->restart) {
phi_s3 = 16; nFirstFrameSamplesToIgnore = 16;
} }
phi_s6 = 16 - phi_s3; nSamplesInFirstFrame = 16 - nFirstFrameSamplesToIgnore;
if (nSamplesToProcess < samplesRemaining) { if (nSamplesToProcess < nSamplesUntilLoopEnd) {
phi_s1 = (s32)(nSamplesToProcess - phi_s6 + 15) / 16; nFramesToDecode = (s32)(nSamplesToProcess - nSamplesInFirstFrame + 15) / 16;
phi_s0 = phi_s1 * 16; nSamplesToDecode = nFramesToDecode * 16;
phi_s7 = phi_s6 + phi_s0 - nSamplesToProcess; nTrailingSamplesToIgnore = nSamplesInFirstFrame + nSamplesToDecode - nSamplesToProcess;
} else { } else {
phi_s0 = samplesRemaining - phi_s6; nSamplesToDecode = nSamplesUntilLoopEnd - nSamplesInFirstFrame;
phi_s7 = 0; nTrailingSamplesToIgnore = 0;
if (phi_s0 <= 0) { if (nSamplesToDecode <= 0) {
phi_s0 = 0; nSamplesToDecode = 0;
phi_s6 = samplesRemaining; nSamplesInFirstFrame = nSamplesUntilLoopEnd;
} }
phi_s1 = (phi_s0 + 15) / 16; nFramesToDecode = (nSamplesToDecode + 15) / 16;
if (loopInfo->count != 0) { if (loopInfo->count != 0) {
// Loop around and restart // Loop around and restart
restart = true; restart = true;
@ -828,111 +825,114 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
} }
} }
switch (audioBankSample->codec) { switch (audioFontSample->codec) {
case CODEC_ADPCM: case CODEC_ADPCM:
spD4 = 9; frameSize = 9;
spCC = 0x10; skipInitialSamples = 16;
spC8 = 0; sampleDataStart = 0;
break; break;
case 3: case CODEC_SMALL_ADPCM:
spD4 = 5; frameSize = 5;
spCC = 0x10; skipInitialSamples = 16;
spC8 = 0; sampleDataStart = 0;
break; break;
case CODEC_S8: case CODEC_S8:
spD4 = 0x10; frameSize = 16;
spCC = 0x10; skipInitialSamples = 16;
spC8 = 0; sampleDataStart = 0;
break; break;
case 2: case CODEC_S16_INMEMORY:
AudioSynth_ClearBuffer(cmd++, DMEM_UNCOMPRESSED_NOTE, (samplesLenAdjusted * 2) + 0x20); AudioSynth_ClearBuffer(cmd++, DMEM_UNCOMPRESSED_NOTE, (samplesLenAdjusted * 2) + 0x20);
flags = A_CONTINUE; flags = A_CONTINUE;
sp120 = 0; skipBytes = 0;
nAdpcmSamplesProcessed = samplesLenAdjusted; nSamplesProcessed = samplesLenAdjusted;
s5 = samplesLenAdjusted; s5 = samplesLenAdjusted;
goto skip; goto skip;
case 5: case CODEC_S16:
AudioSynth_ClearBuffer(cmd++, DMEM_UNCOMPRESSED_NOTE, (samplesLenAdjusted * 2) + 0x20); AudioSynth_ClearBuffer(cmd++, DMEM_UNCOMPRESSED_NOTE, (samplesLenAdjusted * 2) + 0x20);
flags = A_CONTINUE; flags = A_CONTINUE;
sp120 = 0; skipBytes = 0;
nAdpcmSamplesProcessed = samplesLenAdjusted; nSamplesProcessed = samplesLenAdjusted;
s5 = samplesLenAdjusted; s5 = samplesLenAdjusted;
goto skip; goto skip;
case 4: case CODEC_REVERB:
break; break;
} }
if (phi_s1 != 0) { if (nFramesToDecode != 0) {
temp_v1_5 = (synthState->samplePosInt + spCC - phi_s3) / 16; frameIndex = (synthState->samplePosInt + skipInitialSamples - nFirstFrameSamplesToIgnore) / 16;
temp_mult = (temp_v1_5 * spD4); sampleDataOffset = frameIndex * frameSize;
if (audioBankSample->medium == 0) { if (audioFontSample->medium == MEDIUM_RAM) {
phi_a1 = spC8 + temp_mult + sampleAddr; sampleData = (u8*)(sampleDataStart + sampleDataOffset + sampleAddr);
} else if (audioBankSample->medium == 1) { } else if (audioFontSample->medium == MEDIUM_UNK) {
return cmd; return cmd;
} else { } else {
phi_a1 = sampleData = AudioLoad_DmaSampleData(sampleDataStart + sampleDataOffset + sampleAddr,
Audio_DmaSampleData((u32)(spC8 + temp_mult + sampleAddr), ALIGN16((phi_s1 * spD4) + 0x10), ALIGN16((nFramesToDecode * frameSize) + 0x10), flags,
flags, &synthState->sampleDmaIndex, audioBankSample->medium); &synthState->sampleDmaIndex, audioFontSample->medium);
} }
if (phi_a1 == NULL) { if (sampleData == NULL) {
return cmd; return cmd;
} }
phi_t0 = (u32)phi_a1 & 0xF; sampleDataStartPad = (u32)sampleData & 0xF;
aligned = ALIGN16((phi_s1 * spD4) + 16); aligned = ALIGN16((nFramesToDecode * frameSize) + 16);
addr = DMEM_COMPRESSED_ADPCM_DATA - aligned; addr = DMEM_COMPRESSED_ADPCM_DATA - aligned;
aLoadBuffer(cmd++, phi_a1 - phi_t0, addr, aligned); aLoadBuffer(cmd++, sampleData - sampleDataStartPad, addr, aligned);
} else { } else {
phi_s0 = 0; nSamplesToDecode = 0;
phi_t0 = 0; sampleDataStartPad = 0;
} }
if (synthState->restart) { if (synthState->restart) {
aSetLoop(cmd++, audioBankSample->loop->state); aSetLoop(cmd++, audioFontSample->loop->state);
flags = A_LOOP; flags = A_LOOP;
synthState->restart = false; synthState->restart = false;
} }
nSamplesInThisIteration = phi_s0 + phi_s6 - phi_s7; nSamplesInThisIteration = nSamplesToDecode + nSamplesInFirstFrame - nTrailingSamplesToIgnore;
if (nAdpcmSamplesProcessed == 0) { if (nSamplesProcessed == 0) {
if (1) {} if (1) {}
sp120 = phi_s3 * 2; skipBytes = nFirstFrameSamplesToIgnore * 2;
} else { } else {
phi_s4 = ALIGN16(s5 + 16); phi_s4 = ALIGN16(s5 + 16);
} }
switch (audioBankSample->codec) { switch (audioFontSample->codec) {
case CODEC_ADPCM: case CODEC_ADPCM:
aligned = ALIGN16((phi_s1 * spD4) + 0x10); aligned = ALIGN16((nFramesToDecode * frameSize) + 0x10);
addr = DMEM_COMPRESSED_ADPCM_DATA - aligned; addr = DMEM_COMPRESSED_ADPCM_DATA - aligned;
aSetBuffer(cmd++, 0, addr + phi_t0, DMEM_UNCOMPRESSED_NOTE + phi_s4, phi_s0 * 2); aSetBuffer(cmd++, 0, addr + sampleDataStartPad, DMEM_UNCOMPRESSED_NOTE + phi_s4,
nSamplesToDecode * 2);
aADPCMdec(cmd++, flags, synthState->synthesisBuffers->adpcmdecState); aADPCMdec(cmd++, flags, synthState->synthesisBuffers->adpcmdecState);
break; break;
case 3: case CODEC_SMALL_ADPCM:
aligned = ALIGN16((phi_s1 * spD4) + 0x10); aligned = ALIGN16((nFramesToDecode * frameSize) + 0x10);
addr = DMEM_COMPRESSED_ADPCM_DATA - aligned; addr = DMEM_COMPRESSED_ADPCM_DATA - aligned;
aSetBuffer(cmd++, 0, addr + phi_t0, DMEM_UNCOMPRESSED_NOTE + phi_s4, phi_s0 * 2); aSetBuffer(cmd++, 0, addr + sampleDataStartPad, DMEM_UNCOMPRESSED_NOTE + phi_s4,
nSamplesToDecode * 2);
aADPCMdec(cmd++, flags | 4, synthState->synthesisBuffers->adpcmdecState); aADPCMdec(cmd++, flags | 4, synthState->synthesisBuffers->adpcmdecState);
break; break;
case CODEC_S8: case CODEC_S8:
aligned = ALIGN16((phi_s1 * spD4) + 0x10); aligned = ALIGN16((nFramesToDecode * frameSize) + 0x10);
addr = DMEM_COMPRESSED_ADPCM_DATA - aligned; addr = DMEM_COMPRESSED_ADPCM_DATA - aligned;
AudioSynth_SetBuffer(cmd++, 0, addr + phi_t0, DMEM_UNCOMPRESSED_NOTE + phi_s4, phi_s0 * 2); AudioSynth_SetBuffer(cmd++, 0, addr + sampleDataStartPad, DMEM_UNCOMPRESSED_NOTE + phi_s4,
nSamplesToDecode * 2);
AudioSynth_S8Dec(cmd++, flags, synthState->synthesisBuffers->adpcmdecState); AudioSynth_S8Dec(cmd++, flags, synthState->synthesisBuffers->adpcmdecState);
break; break;
} }
if (nAdpcmSamplesProcessed != 0) { if (nSamplesProcessed != 0) {
aDMEMMove(cmd++, DMEM_UNCOMPRESSED_NOTE + phi_s4 + (phi_s3 * 2), DMEM_UNCOMPRESSED_NOTE + s5, aDMEMMove(cmd++, DMEM_UNCOMPRESSED_NOTE + phi_s4 + (nFirstFrameSamplesToIgnore * 2),
nSamplesInThisIteration * 2); DMEM_UNCOMPRESSED_NOTE + s5, nSamplesInThisIteration * 2);
} }
nAdpcmSamplesProcessed += nSamplesInThisIteration; nSamplesProcessed += nSamplesInThisIteration;
switch (flags) { switch (flags) {
case A_INIT: case A_INIT:
sp120 = 0x20; skipBytes = 0x20;
s5 = (phi_s0 + 0x10) * 2; s5 = (nSamplesToDecode + 0x10) * 2;
break; break;
case A_LOOP: case A_LOOP:
s5 = nSamplesInThisIteration * 2 + s5; s5 = nSamplesInThisIteration * 2 + s5;
@ -941,7 +941,7 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
if (s5 != 0) { if (s5 != 0) {
s5 = nSamplesInThisIteration * 2 + s5; s5 = nSamplesInThisIteration * 2 + s5;
} else { } else {
s5 = (phi_s3 + nSamplesInThisIteration) * 2; s5 = (nFirstFrameSamplesToIgnore + nSamplesInThisIteration) * 2;
} }
break; break;
} }
@ -951,9 +951,9 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
skip: skip:
if (noteFinished) { if (noteFinished) {
AudioSynth_ClearBuffer(cmd++, DMEM_UNCOMPRESSED_NOTE + s5, AudioSynth_ClearBuffer(cmd++, DMEM_UNCOMPRESSED_NOTE + s5,
(samplesLenAdjusted - nAdpcmSamplesProcessed) * 2); (samplesLenAdjusted - nSamplesProcessed) * 2);
finished = true; finished = true;
note->noteSubEu.bitField0.s.finished = true; note->noteSubEu.bitField0.finished = true;
func_800DB2C0(updateIndex, noteIndex); func_800DB2C0(updateIndex, noteIndex);
break; break;
} else { } else {
@ -968,12 +968,12 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
switch (nParts) { switch (nParts) {
case 1: case 1:
noteSamplesDmemAddrBeforeResampling = DMEM_UNCOMPRESSED_NOTE + sp120; noteSamplesDmemAddrBeforeResampling = DMEM_UNCOMPRESSED_NOTE + skipBytes;
break; break;
case 2: case 2:
switch (curPart) { switch (curPart) {
case 0: case 0:
AudioSynth_InterL(cmd++, DMEM_UNCOMPRESSED_NOTE + sp120, DMEM_TEMP + 0x20, AudioSynth_InterL(cmd++, DMEM_UNCOMPRESSED_NOTE + skipBytes, DMEM_TEMP + 0x20,
((samplesLenAdjusted / 2) + 7) & ~7); ((samplesLenAdjusted / 2) + 7) & ~7);
resampledTempLen = samplesLenAdjusted; resampledTempLen = samplesLenAdjusted;
noteSamplesDmemAddrBeforeResampling = DMEM_TEMP + 0x20; noteSamplesDmemAddrBeforeResampling = DMEM_TEMP + 0x20;
@ -983,7 +983,7 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
} }
break; break;
case 1: case 1:
AudioSynth_InterL(cmd++, DMEM_UNCOMPRESSED_NOTE + sp120, AudioSynth_InterL(cmd++, DMEM_UNCOMPRESSED_NOTE + skipBytes,
DMEM_TEMP + 0x20 + resampledTempLen, ((samplesLenAdjusted / 2) + 7) & ~7); DMEM_TEMP + 0x20 + resampledTempLen, ((samplesLenAdjusted / 2) + 7) & ~7);
break; break;
} }
@ -995,8 +995,8 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
} }
flags = A_CONTINUE; flags = A_CONTINUE;
if (noteSubEu->bitField0.s.needsInit == true) { if (noteSubEu->bitField0.needsInit == true) {
noteSubEu->bitField0.s.needsInit = false; noteSubEu->bitField0.needsInit = false;
flags = A_INIT; flags = A_INIT;
} }
@ -1020,8 +1020,8 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
filter = noteSubEu->filter; filter = noteSubEu->filter;
if (filter != 0) { if (filter != 0) {
AudioSynth_SetFilterCount(cmd++, aiBufLen * 2, filter); AudioSynth_LoadFilterCount(cmd++, aiBufLen * 2, filter);
AudioSynth_SetFilter(cmd++, flags, DMEM_TEMP, synthState->synthesisBuffers->mixEnvelopeState); AudioSynth_LoadFilter(cmd++, flags, DMEM_TEMP, synthState->synthesisBuffers->mixEnvelopeState);
} }
unk7 = noteSubEu->unk_07; unk7 = noteSubEu->unk_07;
@ -1051,7 +1051,7 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
side = 0; side = 0;
} }
cmd = AudioSynth_ProcessEnvelope(cmd, noteSubEu, synthState, aiBufLen, DMEM_TEMP, side, flags); cmd = AudioSynth_ProcessEnvelope(cmd, noteSubEu, synthState, aiBufLen, DMEM_TEMP, side, flags);
if (noteSubEu->bitField1.s.usesHeadsetPanEffects2) { if (noteSubEu->bitField1.usesHeadsetPanEffects2) {
if (!(flags & A_INIT)) { if (!(flags & A_INIT)) {
flags = A_CONTINUE; flags = A_CONTINUE;
} }
@ -1118,7 +1118,7 @@ Acmd* AudioSynth_ProcessEnvelope(Acmd* cmd, NoteSubEu* noteSubEu, NoteSynthesisS
synthState->curVolLeft = curVolLeft + (rampLeft * (aiBufLen >> 3)); synthState->curVolLeft = curVolLeft + (rampLeft * (aiBufLen >> 3));
synthState->curVolRight = curVolRight + (rampRight * (aiBufLen >> 3)); synthState->curVolRight = curVolRight + (rampRight * (aiBufLen >> 3));
if (noteSubEu->bitField1.s.usesHeadsetPanEffects2) { if (noteSubEu->bitField1.usesHeadsetPanEffects2) {
AudioSynth_ClearBuffer(cmd++, DMEM_NOTE_PAN_TEMP, DEFAULT_LEN_1CH); AudioSynth_ClearBuffer(cmd++, DMEM_NOTE_PAN_TEMP, DEFAULT_LEN_1CH);
AudioSynth_EnvSetup1(cmd++, phi_t1 * 2, rampReverb, rampLeft, rampRight); AudioSynth_EnvSetup1(cmd++, phi_t1 * 2, rampReverb, rampLeft, rampRight);
AudioSynth_EnvSetup2(cmd++, curVolLeft, curVolRight); AudioSynth_EnvSetup2(cmd++, curVolLeft, curVolRight);
@ -1139,9 +1139,9 @@ Acmd* AudioSynth_ProcessEnvelope(Acmd* cmd, NoteSubEu* noteSubEu, NoteSynthesisS
phi_a1 = D_801304AC; phi_a1 = D_801304AC;
} }
aEnvMixer(cmd++, inBuf, aiBufLen, (sourceReverbVol & 0x80) >> 7, noteSubEu->bitField0.s.stereoHeadsetEffects, aEnvMixer(cmd++, inBuf, aiBufLen, (sourceReverbVol & 0x80) >> 7, noteSubEu->bitField0.stereoHeadsetEffects,
noteSubEu->bitField0.s.usesHeadsetPanEffects, noteSubEu->bitField0.s.stereoStrongRight, noteSubEu->bitField0.usesHeadsetPanEffects, noteSubEu->bitField0.stereoStrongRight,
noteSubEu->bitField0.s.stereoStrongLeft, phi_a1, D_801304A0); noteSubEu->bitField0.stereoStrongLeft, phi_a1, D_801304A0);
return cmd; return cmd;
} }
@ -1151,7 +1151,7 @@ Acmd* AudioSynth_LoadWaveSamples(Acmd* cmd, NoteSubEu* noteSubEu, NoteSynthesisS
s32 samplePosInt = synthState->samplePosInt; s32 samplePosInt = synthState->samplePosInt;
s32 repeats; s32 repeats;
if (noteSubEu->bitField1.s.bookOffset != 0) { if (noteSubEu->bitField1.bookOffset != 0) {
AudioSynth_LoadBuffer(cmd++, DMEM_UNCOMPRESSED_NOTE, ALIGN16(nSamplesToLoad * 2), gWaveSamples[8]); AudioSynth_LoadBuffer(cmd++, DMEM_UNCOMPRESSED_NOTE, ALIGN16(nSamplesToLoad * 2), gWaveSamples[8]);
gWaveSamples[8] += nSamplesToLoad * 2; gWaveSamples[8] += nSamplesToLoad * 2;
return cmd; return cmd;

View file

@ -16,7 +16,7 @@ void func_8006BA30(GlobalContext* globalCtx) {
for (i = 0; i < ARRAY_COUNT(globalCtx->soundSources); i++) { for (i = 0; i < ARRAY_COUNT(globalCtx->soundSources); i++) {
if (source->countdown != 0) { if (source->countdown != 0) {
if (DECR(source->countdown) == 0) { if (DECR(source->countdown) == 0) {
func_800F89E8(&source->relativePos); Audio_StopSfxByPos(&source->relativePos);
} else { } else {
SkinMatrix_Vec3fMtxFMultXYZ(&globalCtx->mf_11D60, &source->originPos, &source->relativePos); SkinMatrix_Vec3fMtxFMultXYZ(&globalCtx->mf_11D60, &source->originPos, &source->relativePos);
} }
@ -49,7 +49,7 @@ void Audio_PlaySoundAtPosition(GlobalContext* globalCtx, Vec3f* pos, s32 duratio
if (i >= ARRAY_COUNT(globalCtx->soundSources)) { if (i >= ARRAY_COUNT(globalCtx->soundSources)) {
source = backupSource; source = backupSource;
func_800F89E8(&source->relativePos); Audio_StopSfxByPos(&source->relativePos);
} }
source->originPos = *pos; source->originPos = *pos;

View file

@ -8,6 +8,6 @@ void func_800C3C20(void) {
s32 i; s32 i;
for (i = 0; (i < ARRAY_COUNT(D_8012D200)) & 0xFFFFFFFF; i++) { for (i = 0; (i < ARRAY_COUNT(D_8012D200)) & 0xFFFFFFFF; i++) {
func_800F87A0(D_8012D200[i]); Audio_StopSfxByBank(D_8012D200[i]);
} }
} }

View file

@ -107,12 +107,12 @@ AudioTask* func_800E5000(void) {
} }
gAudioContext.curAudioFrameDmaCount = 0; gAudioContext.curAudioFrameDmaCount = 0;
func_800E11F0(); AudioLoad_DecreaseSampleDmaTtls();
Audio_ProcessLoads(gAudioContext.resetStatus); AudioLoad_ProcessLoads(gAudioContext.resetStatus);
func_800E4F58(); AudioLoad_ProcessScriptLoads();
if (gAudioContext.resetStatus != 0) { if (gAudioContext.resetStatus != 0) {
if (Audio_ResetStep() == 0) { if (AudioHeap_ResetStep() == 0) {
if (gAudioContext.resetStatus == 0) { if (gAudioContext.resetStatus == 0) {
osSendMesg(gAudioContext.audioResetQueueP, gAudioContext.audioResetSpecIdToLoad, OS_MESG_NOBLOCK); osSendMesg(gAudioContext.audioResetQueueP, gAudioContext.audioResetSpecIdToLoad, OS_MESG_NOBLOCK);
} }
@ -217,19 +217,19 @@ void func_800E5584(AudioCmd* cmd) {
switch (cmd->op) { switch (cmd->op) {
case 0x81: case 0x81:
func_800E1C18(cmd->arg1, cmd->arg2); AudioLoad_SyncLoadSeqParts(cmd->arg1, cmd->arg2);
return; return;
case 0x82: case 0x82:
func_800E20D4(cmd->arg0, cmd->arg1, cmd->arg2); AudioLoad_SyncInitSeqPlayer(cmd->arg0, cmd->arg1, cmd->arg2);
func_800E59AC(cmd->arg0, cmd->data); func_800E59AC(cmd->arg0, cmd->data);
return; return;
case 0x85: case 0x85:
func_800E2124(cmd->arg0, cmd->arg1, cmd->data); AudioLoad_SyncInitSeqPlayerSkipTicks(cmd->arg0, cmd->arg1, cmd->data);
return; return;
case 0x83: case 0x83:
if (gAudioContext.seqPlayers[cmd->arg0].enabled) { if (gAudioContext.seqPlayers[cmd->arg0].enabled) {
if (cmd->asInt == 0) { if (cmd->asInt == 0) {
Audio_SequencePlayerDisableAsFinished(&gAudioContext.seqPlayers[cmd->arg0]); AudioSeq_SequencePlayerDisableAsFinished(&gAudioContext.seqPlayers[cmd->arg0]);
} else { } else {
func_800E5958(cmd->arg0, cmd->asInt); func_800E5958(cmd->arg0, cmd->asInt);
} }
@ -247,12 +247,12 @@ void func_800E5584(AudioCmd* cmd) {
return; return;
case 0xF2: case 0xF2:
if (cmd->asUInt == 1) { if (cmd->asUInt == 1) {
for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) { for (i = 0; i < gAudioContext.numNotes; i++) {
Note* note = &gAudioContext.notes[i]; Note* note = &gAudioContext.notes[i];
NoteSubEu* subEu = &note->noteSubEu; NoteSubEu* subEu = &note->noteSubEu;
if (subEu->bitField0.s.enabled && note->playbackState.unk_04 == 0) { if (subEu->bitField0.enabled && note->playbackState.unk_04 == 0) {
if (note->playbackState.parentLayer->seqChannel->muteBehavior & 8) { if (note->playbackState.parentLayer->channel->muteBehavior & 8) {
subEu->bitField0.s.finished = 1; subEu->bitField0.finished = 1;
} }
} }
} }
@ -266,19 +266,19 @@ void func_800E5584(AudioCmd* cmd) {
return; return;
case 0xF3: case 0xF3:
func_800E1D64(cmd->arg0, cmd->arg1, cmd->arg2); AudioLoad_SyncLoadInstrument(cmd->arg0, cmd->arg1, cmd->arg2);
return; return;
case 0xF4: case 0xF4:
Audio_AudioTableAsyncLoad(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioContext.unk_1E20); AudioLoad_AsyncLoadSampleBank(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioContext.externalLoadQueue);
return; return;
case 0xF5: case 0xF5:
Audio_AudioBankAsyncLoad(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioContext.unk_1E20); AudioLoad_AsyncLoadFont(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioContext.externalLoadQueue);
return; return;
case 0xFC: case 0xFC:
Audio_AudioSeqAsyncLoad(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioContext.unk_1E20); AudioLoad_AsyncLoadSeq(cmd->arg0, cmd->arg1, cmd->arg2, &gAudioContext.externalLoadQueue);
return; return;
case 0xF6: case 0xF6:
func_800E1F7C(cmd->arg1); AudioLoad_DiscardSeqFonts(cmd->arg1);
return; return;
case 0x90: case 0x90:
gAudioContext.unk_5BDC[cmd->arg0] = cmd->asUShort; gAudioContext.unk_5BDC[cmd->arg0] = cmd->asUShort;
@ -293,7 +293,7 @@ void func_800E5584(AudioCmd* cmd) {
case 0xE0: case 0xE0:
case 0xE1: case 0xE1:
case 0xE2: case 0xE2:
func_800E7744(cmd->op - 0xE0, cmd->arg0, cmd->arg1, cmd->data); Audio_SetFontInstrument(cmd->op - 0xE0, cmd->arg0, cmd->arg1, cmd->data);
return; return;
case 0xFE: case 0xFE:
temp_t7 = cmd->asUInt; temp_t7 = cmd->asUInt;
@ -301,14 +301,14 @@ void func_800E5584(AudioCmd* cmd) {
for (i = 0; i < gAudioContext.audioBufferParameters.numSequencePlayers; i++) { for (i = 0; i < gAudioContext.audioBufferParameters.numSequencePlayers; i++) {
SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[i]; SequencePlayer* seqPlayer = &gAudioContext.seqPlayers[i];
if (seqPlayer->enabled) { if (seqPlayer->enabled) {
Audio_SequencePlayerDisableAsFinished(seqPlayer); AudioSeq_SequencePlayerDisableAsFinished(seqPlayer);
} }
} }
} }
func_800E66C0(temp_t7); func_800E66C0(temp_t7);
return; return;
case 0xE3: case 0xE3:
func_800DE4B0(cmd->asInt); AudioHeap_PopCache(cmd->asInt);
return; return;
default: default:
return; return;
@ -478,24 +478,24 @@ void Audio_ProcessCmds(u32 msg) {
} }
} }
u32 func_800E5E20(u32* arg0) { u32 func_800E5E20(u32* out) {
u32 sp1C; u32 sp1C;
if (osRecvMesg(&gAudioContext.unk_1E20, (OSMesg*)&sp1C, OS_MESG_NOBLOCK) == -1) { if (osRecvMesg(&gAudioContext.externalLoadQueue, (OSMesg*)&sp1C, OS_MESG_NOBLOCK) == -1) {
*arg0 = 0; *out = 0;
return 0; return 0;
} }
*arg0 = sp1C & 0xFFFFFF; *out = sp1C & 0xFFFFFF;
return sp1C >> 0x18; return sp1C >> 0x18;
} }
u8* func_800E5E84(s32 arg0, u32* arg1) { u8* func_800E5E84(s32 arg0, u32* arg1) {
return func_800E1F38(arg0, arg1); return AudioLoad_GetFontsForSequence(arg0, arg1);
} }
void func_800E5EA4(s32 arg0, u32* arg1, u32* arg2) { void func_800E5EA4(s32 arg0, u32* arg1, u32* arg2) {
*arg1 = gAudioContext.ctlEntries[arg0].unk_02; *arg1 = gAudioContext.soundFonts[arg0].sampleBankId1;
*arg2 = gAudioContext.ctlEntries[arg0].unk_03; *arg2 = gAudioContext.soundFonts[arg0].sampleBankId2;
} }
s32 func_800E5EDC(void) { s32 func_800E5EDC(void) {
@ -563,15 +563,15 @@ s8 func_800E6070(s32 playerIdx, s32 channelIdx, s32 scriptIdx) {
} }
s8 func_800E60C4(s32 arg0, s32 arg1) { s8 func_800E60C4(s32 arg0, s32 arg1) {
return gAudioContext.seqPlayers[arg0].unk_158[arg1]; return gAudioContext.seqPlayers[arg0].soundScriptIO[arg1];
} }
void func_800E60EC(void* memAddr, u32 size) { void Audio_InitExternalPool(void* mem, u32 size) {
Audio_SoundAllocPoolInit(&gAudioContext.unkPool, memAddr, size); AudioHeap_AllocPoolInit(&gAudioContext.externalPool, mem, size);
} }
void func_800E611C(void) { void Audio_DestroyExternalPool(void) {
gAudioContext.unkPool.start = NULL; gAudioContext.externalPool.start = NULL;
} }
void func_800E6128(SequencePlayer* seqPlayer, AudioCmd* cmd) { void func_800E6128(SequencePlayer* seqPlayer, AudioCmd* cmd) {
@ -596,7 +596,7 @@ void func_800E6128(SequencePlayer* seqPlayer, AudioCmd* cmd) {
seqPlayer->transposition = cmd->asSbyte; seqPlayer->transposition = cmd->asSbyte;
return; return;
case 0x46: case 0x46:
seqPlayer->unk_158[cmd->arg2] = cmd->asSbyte; seqPlayer->soundScriptIO[cmd->arg2] = cmd->asSbyte;
return; return;
case 0x4A: case 0x4A:
fadeVolume = (s32)cmd->arg1 / 127.0f; fadeVolume = (s32)cmd->arg1 / 127.0f;
@ -725,9 +725,9 @@ void Audio_WaitForAudioTask(void) {
s32 func_800E6590(s32 arg0, s32 arg1, s32 arg2) { s32 func_800E6590(s32 arg0, s32 arg1, s32 arg2) {
SequencePlayer* seqPlayer; SequencePlayer* seqPlayer;
SequenceChannelLayer* layer; SequenceLayer* layer;
Note* note; Note* note;
AudioBankSound* sound; SoundFontSound* sound;
s32 loopEnd; s32 loopEnd;
s32 samplePos; s32 samplePos;
@ -749,7 +749,7 @@ s32 func_800E6590(s32 arg0, s32 arg1, s32 arg2) {
note = layer->note; note = layer->note;
if (layer == note->playbackState.parentLayer) { if (layer == note->playbackState.parentLayer) {
sound = note->noteSubEu.sound.audioBankSound; sound = note->noteSubEu.sound.soundFontSound;
if (sound == NULL) { if (sound == NULL) {
return 0; return 0;
} }
@ -777,21 +777,21 @@ s32 func_800E66C0(s32 arg0) {
NoteSubEu* temp_a3; NoteSubEu* temp_a3;
s32 i; s32 i;
Note* note; Note* note;
AudioBankSound* sound; SoundFontSound* sound;
phi_v1 = 0; phi_v1 = 0;
for (i = 0; i < gAudioContext.maxSimultaneousNotes; i++) { for (i = 0; i < gAudioContext.numNotes; i++) {
note = &gAudioContext.notes[i]; note = &gAudioContext.notes[i];
temp_a2 = &note->playbackState; temp_a2 = &note->playbackState;
if (note->noteSubEu.bitField0.s.enabled) { if (note->noteSubEu.bitField0.enabled) {
temp_a3 = &note->noteSubEu; temp_a3 = &note->noteSubEu;
if (temp_a2->adsr.action.s.state != 0) { if (temp_a2->adsr.action.s.state != 0) {
if (arg0 >= 2) { if (arg0 >= 2) {
sound = temp_a3->sound.audioBankSound; sound = temp_a3->sound.soundFontSound;
if (sound == NULL || temp_a3->bitField1.s.isSyntheticWave) { if (sound == NULL || temp_a3->bitField1.isSyntheticWave) {
continue; continue;
} }
if (sound->sample->medium == 0) { if (sound->sample->medium == MEDIUM_RAM) {
continue; continue;
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -5,24 +5,24 @@
typedef struct { typedef struct {
/* 0x00 */ u16 sfxId; /* 0x00 */ u16 sfxId;
/* 0x04 */ Vec3f* pos; /* 0x04 */ Vec3f* pos;
/* 0x08 */ u8 unk_8; /* 0x08 */ u8 token;
/* 0x0C */ f32* freqScale; /* 0x0C */ f32* freqScale;
/* 0x10 */ f32* unk_10; /* 0x10 */ f32* vol;
/* 0x14 */ s8* reverbAdd; /* 0x14 */ s8* reverbAdd;
} SoundRequest; // size = 0x18 } SoundRequest; // size = 0x18
typedef struct { typedef struct {
/* 0x00 */ f32 unk_0; /* 0x00 */ f32 value;
/* 0x04 */ f32 unk_4; /* 0x04 */ f32 target;
/* 0x08 */ f32 unk_8; /* 0x08 */ f32 step;
/* 0x0C */ u16 unk_C; /* 0x0C */ u16 remainingFrames;
} Struct_800F8EA0; // size = 0x10 } UnusedBankLerp; // size = 0x10
// rodata for Audio_ProcessSoundRequest (this file) // rodata for Audio_ProcessSoundRequest (this file)
// (probably moved to .data due to -use_readwrite_const) // (probably moved to .data due to -use_readwrite_const)
char D_80133340[] = "SE"; char D_80133340[] = "SE";
// rodata for func_800F7CEC (this file) // rodata for Audio_ChooseActiveSounds (this file)
char D_80133344[] = VT_COL(RED, WHITE) "<INAGAKI CHECK> dist over! flag:%04X ptr:%08X pos:%f-%f-%f" VT_RST "\n"; char D_80133344[] = VT_COL(RED, WHITE) "<INAGAKI CHECK> dist over! flag:%04X ptr:%08X pos:%f-%f-%f" VT_RST "\n";
// file padding // file padding
@ -32,6 +32,21 @@ s32 D_8013338C = 0;
char D_80133390[] = "SEQ H"; char D_80133390[] = "SEQ H";
char D_80133398[] = " L"; char D_80133398[] = " L";
// bss
extern SoundRequest sSoundRequests[0x100];
extern SoundBankEntry D_8016BAD0[9];
extern SoundBankEntry D_8016BC80[12];
extern SoundBankEntry D_8016BEC0[22];
extern SoundBankEntry D_8016C2E0[20];
extern SoundBankEntry D_8016C6A0[8];
extern SoundBankEntry D_8016C820[3];
extern SoundBankEntry D_8016C8B0[5];
extern u8 sSoundBankListEnd[7];
extern u8 sSoundBankFreeListStart[7];
extern u8 sSoundBankUnused[7];
extern u8 sCurSfxPlayerChannelIdx;
extern UnusedBankLerp sUnusedBankLerp[7];
// data // data
// sSoundRequests ring buffer endpoints. read index <= write index, wrapping around mod 256. // sSoundRequests ring buffer endpoints. read index <= write index, wrapping around mod 256.
@ -58,7 +73,7 @@ u8 sBankSizes[ARRAY_COUNT(gSoundBanks)] = {
ARRAY_COUNT(D_8016C6A0), ARRAY_COUNT(D_8016C820), ARRAY_COUNT(D_8016C8B0), ARRAY_COUNT(D_8016C6A0), ARRAY_COUNT(D_8016C820), ARRAY_COUNT(D_8016C8B0),
}; };
u8 D_801333CC = 0; u8 gSfxChannelLayout = 0;
u16 D_801333D0 = 0; u16 D_801333D0 = 0;
@ -74,13 +89,10 @@ s32 D_801333EC = 0; // unused
u8 D_801333F0 = 0; u8 D_801333F0 = 0;
u8 gAudioSEFlagSwapOff = 0; u8 gAudioSfxSwapOff = 0;
u8 D_801333F8 = 0; u8 D_801333F8 = 0;
extern SoundRequest sSoundRequests[0x100];
extern Struct_800F8EA0 D_8016E270[7];
void Audio_SetSoundBanksMute(u16 muteMask) { void Audio_SetSoundBanksMute(u16 muteMask) {
u8 bankId; u8 bankId;
@ -94,38 +106,37 @@ void Audio_SetSoundBanksMute(u16 muteMask) {
} }
} }
void Audio_QueueSeqCmdMute(u8 arg0) { void Audio_QueueSeqCmdMute(u8 channelIdx) {
D_801333D0 |= (1 << arg0); D_801333D0 |= (1 << channelIdx);
Audio_SetVolScale(0, 2, 0x40, 0xF); Audio_SetVolScale(0, 2, 0x40, 0xF);
Audio_SetVolScale(3, 2, 0x40, 0xF); Audio_SetVolScale(3, 2, 0x40, 0xF);
} }
void Audio_ClearBGMMute(u8 arg0) { void Audio_ClearBGMMute(u8 channelIdx) {
D_801333D0 &= ((1 << arg0) ^ 0xFFFF); D_801333D0 &= ((1 << channelIdx) ^ 0xFFFF);
if (D_801333D0 == 0) { if (D_801333D0 == 0) {
Audio_SetVolScale(0, 2, 0x7F, 0xF); Audio_SetVolScale(0, 2, 0x7F, 0xF);
Audio_SetVolScale(3, 2, 0x7F, 0xF); Audio_SetVolScale(3, 2, 0x7F, 0xF);
} }
} }
// a4 is often the same as freqScale. (u8)(*a4 * 127.0f) is sent to script on IO port 2 void Audio_PlaySoundGeneral(u16 sfxId, Vec3f* pos, u8 token, f32* freqScale, f32* vol, s8* reverbAdd) {
void Audio_PlaySoundGeneral(u16 sfxId, Vec3f* pos, u8 a2, f32* freqScale, f32* a4, s8* reverbAdd) {
u8 i; u8 i;
SoundRequest* req; SoundRequest* req;
if (!gSoundBankMuted[SFX_BANK_SHIFT(sfxId)]) { if (!gSoundBankMuted[SFX_BANK_SHIFT(sfxId)]) {
req = &sSoundRequests[sSoundRequestWriteIndex]; req = &sSoundRequests[sSoundRequestWriteIndex];
if (!gAudioSEFlagSwapOff) { if (!gAudioSfxSwapOff) {
for (i = 0; i < 10; i++) { for (i = 0; i < 10; i++) {
if (sfxId == gAudioSEFlagSwapSource[i]) { if (sfxId == gAudioSfxSwapSource[i]) {
if (gAudioSEFlagSwapMode[i] == 0) { // "SWAP" if (gAudioSfxSwapMode[i] == 0) { // "SWAP"
sfxId = gAudioSEFlagSwapTarget[i]; sfxId = gAudioSfxSwapTarget[i];
} else { // "ADD" } else { // "ADD"
req->sfxId = gAudioSEFlagSwapTarget[i]; req->sfxId = gAudioSfxSwapTarget[i];
req->pos = pos; req->pos = pos;
req->unk_8 = a2; req->token = token;
req->freqScale = freqScale; req->freqScale = freqScale;
req->unk_10 = a4; req->vol = vol;
req->reverbAdd = reverbAdd; req->reverbAdd = reverbAdd;
sSoundRequestWriteIndex++; sSoundRequestWriteIndex++;
req = &sSoundRequests[sSoundRequestWriteIndex]; req = &sSoundRequests[sSoundRequestWriteIndex];
@ -136,9 +147,9 @@ void Audio_PlaySoundGeneral(u16 sfxId, Vec3f* pos, u8 a2, f32* freqScale, f32* a
} }
req->sfxId = sfxId; req->sfxId = sfxId;
req->pos = pos; req->pos = pos;
req->unk_8 = a2; req->token = token;
req->freqScale = freqScale; req->freqScale = freqScale;
req->unk_10 = a4; req->vol = vol;
req->reverbAdd = reverbAdd; req->reverbAdd = reverbAdd;
sSoundRequestWriteIndex++; sSoundRequestWriteIndex++;
} }
@ -174,7 +185,7 @@ void Audio_RemoveMatchingSoundRequests(u8 aspect, SoundBankEntry* cmp) {
} }
break; break;
case 4: case 4:
if (req->unk_8 == cmp->unk_C && req->sfxId == cmp->sfxId) { if (req->token == cmp->token && req->sfxId == cmp->sfxId) {
remove = true; remove = true;
} }
break; break;
@ -221,7 +232,7 @@ void Audio_ProcessSoundRequest(void) {
return; return;
} }
if (gSoundBanks[bankId][index].sfxId == req->sfxId) { if (gSoundBanks[bankId][index].sfxId == req->sfxId) {
count = D_80130594[D_801333CC][bankId]; count = gUsedChannelsPerBank[gSfxChannelLayout][bankId];
} else { } else {
if (count == 0) { if (count == 0) {
evictIndex = index; evictIndex = index;
@ -233,7 +244,7 @@ void Audio_ProcessSoundRequest(void) {
evictImportance = gSoundParams[SFX_BANK_SHIFT(sfxId)][SFX_INDEX(sfxId)].importance; evictImportance = gSoundParams[SFX_BANK_SHIFT(sfxId)][SFX_INDEX(sfxId)].importance;
} }
count++; count++;
if (count == D_80130594[D_801333CC][bankId]) { if (count == gUsedChannelsPerBank[gSfxChannelLayout][bankId]) {
if (gSoundParams[SFX_BANK_SHIFT(req->sfxId)][SFX_INDEX(req->sfxId)].importance >= evictImportance) { if (gSoundParams[SFX_BANK_SHIFT(req->sfxId)][SFX_INDEX(req->sfxId)].importance >= evictImportance) {
index = evictIndex; index = evictIndex;
} else { } else {
@ -241,23 +252,24 @@ void Audio_ProcessSoundRequest(void) {
} }
} }
} }
if (count == D_80130594[D_801333CC][bankId]) { if (count == gUsedChannelsPerBank[gSfxChannelLayout][bankId]) {
soundParams = &gSoundParams[SFX_BANK_SHIFT(req->sfxId)][SFX_INDEX(req->sfxId)]; soundParams = &gSoundParams[SFX_BANK_SHIFT(req->sfxId)][SFX_INDEX(req->sfxId)];
if ((req->sfxId & 0xC00) || (soundParams->params & 4) || (index == evictIndex)) { if ((req->sfxId & 0xC00) || (soundParams->params & 4) || (index == evictIndex)) {
if ((gSoundBanks[bankId][index].sfxParams & 8) && gSoundBanks[bankId][index].unk_2A != 1) { if ((gSoundBanks[bankId][index].sfxParams & 8) &&
Audio_ClearBGMMute(gSoundBanks[bankId][index].unk_2E); gSoundBanks[bankId][index].state != SFX_STATE_QUEUED) {
Audio_ClearBGMMute(gSoundBanks[bankId][index].channelIdx);
} }
gSoundBanks[bankId][index].unk_C = req->unk_8; gSoundBanks[bankId][index].token = req->token;
gSoundBanks[bankId][index].sfxId = req->sfxId; gSoundBanks[bankId][index].sfxId = req->sfxId;
gSoundBanks[bankId][index].unk_2A = 1; gSoundBanks[bankId][index].state = SFX_STATE_QUEUED;
gSoundBanks[bankId][index].unk_2B = 2; gSoundBanks[bankId][index].freshness = 2;
gSoundBanks[bankId][index].freqScale = req->freqScale; gSoundBanks[bankId][index].freqScale = req->freqScale;
gSoundBanks[bankId][index].unk_14 = req->unk_10; gSoundBanks[bankId][index].vol = req->vol;
gSoundBanks[bankId][index].reverbAdd = req->reverbAdd; gSoundBanks[bankId][index].reverbAdd = req->reverbAdd;
gSoundBanks[bankId][index].sfxParams = soundParams->params; gSoundBanks[bankId][index].sfxParams = soundParams->params;
gSoundBanks[bankId][index].sfxImportance = soundParams->importance; gSoundBanks[bankId][index].sfxImportance = soundParams->importance;
} else if (gSoundBanks[bankId][index].unk_2A == 5) { } else if (gSoundBanks[bankId][index].state == SFX_STATE_PLAYING_2) {
gSoundBanks[bankId][index].unk_2A = 4; gSoundBanks[bankId][index].state = SFX_STATE_PLAYING_1;
} }
index = 0; index = 0;
} }
@ -266,93 +278,95 @@ void Audio_ProcessSoundRequest(void) {
index = gSoundBanks[bankId][index].next; index = gSoundBanks[bankId][index].next;
} }
} }
if (gSoundBanks[bankId][D_8016E1A8[bankId]].next != 0xFF && index != 0) { if (gSoundBanks[bankId][sSoundBankFreeListStart[bankId]].next != 0xFF && index != 0) {
index = D_8016E1A8[bankId]; index = sSoundBankFreeListStart[bankId];
entry = &gSoundBanks[bankId][index]; entry = &gSoundBanks[bankId][index];
entry->posX = &req->pos->x; entry->posX = &req->pos->x;
entry->posY = &req->pos->y; entry->posY = &req->pos->y;
entry->posZ = &req->pos->z; entry->posZ = &req->pos->z;
entry->unk_C = req->unk_8; entry->token = req->token;
entry->freqScale = req->freqScale; entry->freqScale = req->freqScale;
entry->unk_14 = req->unk_10; entry->vol = req->vol;
entry->reverbAdd = req->reverbAdd; entry->reverbAdd = req->reverbAdd;
soundParams = &gSoundParams[SFX_BANK_SHIFT(req->sfxId)][SFX_INDEX(req->sfxId)]; soundParams = &gSoundParams[SFX_BANK_SHIFT(req->sfxId)][SFX_INDEX(req->sfxId)];
entry->sfxParams = soundParams->params; entry->sfxParams = soundParams->params;
entry->sfxImportance = soundParams->importance; entry->sfxImportance = soundParams->importance;
entry->sfxId = req->sfxId; entry->sfxId = req->sfxId;
entry->unk_2A = 1; entry->state = SFX_STATE_QUEUED;
entry->unk_2B = 2; entry->freshness = 2;
entry->prev = D_8016E1A0[bankId]; entry->prev = sSoundBankListEnd[bankId];
gSoundBanks[bankId][D_8016E1A0[bankId]].next = D_8016E1A8[bankId]; gSoundBanks[bankId][sSoundBankListEnd[bankId]].next = sSoundBankFreeListStart[bankId];
D_8016E1A0[bankId] = D_8016E1A8[bankId]; sSoundBankListEnd[bankId] = sSoundBankFreeListStart[bankId];
D_8016E1A8[bankId] = gSoundBanks[bankId][D_8016E1A8[bankId]].next; sSoundBankFreeListStart[bankId] = gSoundBanks[bankId][sSoundBankFreeListStart[bankId]].next;
gSoundBanks[bankId][D_8016E1A8[bankId]].prev = 0xFF; gSoundBanks[bankId][sSoundBankFreeListStart[bankId]].prev = 0xFF;
entry->next = 0xFF; entry->next = 0xFF;
} }
} }
void func_800F7B54(u8 bankId, u8 bankIndex) { void Audio_RemoveSoundBankEntry(u8 bankId, u8 entryIndex) {
SoundBankEntry* entry = &gSoundBanks[bankId][bankIndex]; SoundBankEntry* entry = &gSoundBanks[bankId][entryIndex];
u8 i; u8 i;
if (entry->sfxParams & 8) { if (entry->sfxParams & 8) {
Audio_ClearBGMMute(entry->unk_2E); Audio_ClearBGMMute(entry->channelIdx);
} }
if (bankIndex == D_8016E1A0[bankId]) { if (entryIndex == sSoundBankListEnd[bankId]) {
D_8016E1A0[bankId] = entry->prev; sSoundBankListEnd[bankId] = entry->prev;
} else { } else {
gSoundBanks[bankId][entry->next].prev = entry->prev; gSoundBanks[bankId][entry->next].prev = entry->prev;
} }
gSoundBanks[bankId][entry->prev].next = entry->next; gSoundBanks[bankId][entry->prev].next = entry->next;
entry->next = D_8016E1A8[bankId]; entry->next = sSoundBankFreeListStart[bankId];
entry->prev = 0xFF; entry->prev = 0xFF;
gSoundBanks[bankId][D_8016E1A8[bankId]].prev = bankIndex; gSoundBanks[bankId][sSoundBankFreeListStart[bankId]].prev = entryIndex;
D_8016E1A8[bankId] = bankIndex; sSoundBankFreeListStart[bankId] = entryIndex;
entry->unk_2A = 0; entry->state = SFX_STATE_EMPTY;
for (i = 0; i < D_80130578[D_801333CC][bankId]; i++) { for (i = 0; i < gChannelsPerBank[gSfxChannelLayout][bankId]; i++) {
if (D_8016E1B8[bankId][i].unk_4 == bankIndex) { if (gActiveSounds[bankId][i].entryIndex == entryIndex) {
D_8016E1B8[bankId][i].unk_4 = 0xFF; gActiveSounds[bankId][i].entryIndex = 0xFF;
i = D_80130578[D_801333CC][bankId]; i = gChannelsPerBank[gSfxChannelLayout][bankId];
} }
} }
} }
void func_800F7CEC(u8 arg0) { void Audio_ChooseActiveSounds(u8 bankId) {
u8 phi_s3; u8 numChosenSounds;
u8 spAE; u8 numChannels;
u8 phi_s4; u8 entryIndex;
u8 i; u8 i;
u8 j; u8 j;
u8 phi_s0; u8 k;
u8 sfxImportance; u8 sfxImportance;
u8 phi_v1_5; u8 needNewSound;
u8 temp2; u8 chosenEntryIndex;
u16 temp3; u16 temp3;
f32 tempf1; f32 tempf1;
SoundBankEntry* entry; SoundBankEntry* entry;
Struct_800F7CEC sp84[3]; ActiveSound chosenSounds[MAX_CHANNELS_PER_BANK];
Struct_800F7CEC* temp_s4_3; ActiveSound* activeSound;
s32 pad; s32 pad;
phi_s3 = 0; numChosenSounds = 0;
for (i = 0; i < 3; i++) { for (i = 0; i < MAX_CHANNELS_PER_BANK; i++) {
sp84[i].priority = 0x7FFFFFFF; chosenSounds[i].priority = 0x7FFFFFFF;
sp84[i].unk_4 = 0xFF; chosenSounds[i].entryIndex = 0xFF;
} }
phi_s4 = gSoundBanks[arg0][0].next; entryIndex = gSoundBanks[bankId][0].next;
phi_s0 = 0; k = 0;
while (phi_s4 != 0xFF) { while (entryIndex != 0xFF) {
if ((1 == gSoundBanks[arg0][phi_s4].unk_2A) && (gSoundBanks[arg0][phi_s4].sfxId & 0xC00)) { if ((gSoundBanks[bankId][entryIndex].state == SFX_STATE_QUEUED) &&
gSoundBanks[arg0][phi_s4].unk_2B--; (gSoundBanks[bankId][entryIndex].sfxId & 0xC00)) {
} else if (!(gSoundBanks[arg0][phi_s4].sfxId & 0xC00) && (gSoundBanks[arg0][phi_s4].unk_2A == 5)) { gSoundBanks[bankId][entryIndex].freshness--;
Audio_QueueCmdS8((gSoundBanks[arg0][phi_s4].unk_2E << 8) | 0x6020000, 0); } else if (!(gSoundBanks[bankId][entryIndex].sfxId & 0xC00) &&
func_800F7B54(arg0, phi_s4); (gSoundBanks[bankId][entryIndex].state == SFX_STATE_PLAYING_2)) {
Audio_QueueCmdS8((gSoundBanks[bankId][entryIndex].channelIdx << 8) | 0x6020000, 0);
Audio_RemoveSoundBankEntry(bankId, entryIndex);
} }
if (gSoundBanks[arg0][phi_s4].unk_2B == 0) { if (gSoundBanks[bankId][entryIndex].freshness == 0) {
func_800F7B54(arg0, phi_s4); Audio_RemoveSoundBankEntry(bankId, entryIndex);
} else if (gSoundBanks[arg0][phi_s4].unk_2A != 0) { } else if (gSoundBanks[bankId][entryIndex].state != SFX_STATE_EMPTY) {
entry = &gSoundBanks[arg0][phi_s4]; entry = &gSoundBanks[bankId][entryIndex];
if (&D_801333D4.x == entry[0].posX) { if (&D_801333D4.x == entry[0].posX) {
entry->dist = 0.0f; entry->dist = 0.0f;
@ -369,122 +383,124 @@ void func_800F7CEC(u8 arg0) {
osSyncPrintf(D_80133344, entry->sfxId, entry->posX, entry->posZ, *entry->posX, *entry->posY, osSyncPrintf(D_80133344, entry->sfxId, entry->posX, entry->posZ, *entry->posX, *entry->posY,
*entry->posZ); *entry->posZ);
} }
temp3 = entry->sfxId; temp3 = entry->sfxId; // fake
entry->priority = (u32)entry->dist + (SQ(0xFF - sfxImportance) * SQ(76)) + temp3 - temp3; entry->priority = (u32)entry->dist + (SQ(0xFF - sfxImportance) * SQ(76)) + temp3 - temp3;
if (*entry->posZ < 0.0f) { if (*entry->posZ < 0.0f) {
entry->priority += (s32)(-*entry->posZ * 6.0f); entry->priority += (s32)(-*entry->posZ * 6.0f);
} }
} }
if (entry->dist > SQ(1e5f)) { if (entry->dist > SQ(1e5f)) {
if (entry->unk_2A == 4) { if (entry->state == SFX_STATE_PLAYING_1) {
Audio_QueueCmdS8((entry->unk_2E << 8) | 0x6020000, 0); Audio_QueueCmdS8((entry->channelIdx << 8) | 0x6020000, 0);
if (entry->sfxId & 0xC00) { if (entry->sfxId & 0xC00) {
func_800F7B54(arg0, phi_s4); Audio_RemoveSoundBankEntry(bankId, entryIndex);
phi_s4 = phi_s0; entryIndex = k;
} }
} }
} else { } else {
spAE = D_80130578[D_801333CC][arg0]; numChannels = gChannelsPerBank[gSfxChannelLayout][bankId];
for (i = 0; i < spAE; i++) { for (i = 0; i < numChannels; i++) {
if (sp84[i].priority >= entry->priority) { if (chosenSounds[i].priority >= entry->priority) {
if (phi_s3 < D_80130578[D_801333CC][arg0]) { if (numChosenSounds < gChannelsPerBank[gSfxChannelLayout][bankId]) {
phi_s3++; numChosenSounds++;
} }
for (j = spAE - 1; j > i; j--) { for (j = numChannels - 1; j > i; j--) {
sp84[j].priority = sp84[j - 1].priority; chosenSounds[j].priority = chosenSounds[j - 1].priority;
sp84[j].unk_4 = sp84[j - 1].unk_4; chosenSounds[j].entryIndex = chosenSounds[j - 1].entryIndex;
} }
sp84[i].priority = entry->priority; chosenSounds[i].priority = entry->priority;
sp84[i].unk_4 = phi_s4; chosenSounds[i].entryIndex = entryIndex;
i = spAE; // "break;" i = numChannels; // "break;"
} }
} }
} }
phi_s0 = phi_s4; k = entryIndex;
} }
phi_s4 = gSoundBanks[arg0][phi_s0].next; entryIndex = gSoundBanks[bankId][k].next;
} }
for (i = 0; i < phi_s3; i++) { for (i = 0; i < numChosenSounds; i++) {
entry = &gSoundBanks[arg0][sp84[i].unk_4]; entry = &gSoundBanks[bankId][chosenSounds[i].entryIndex];
if (entry->unk_2A == 1) { if (entry->state == SFX_STATE_QUEUED) {
entry->unk_2A = 2; entry->state = SFX_STATE_READY;
} else if (entry->unk_2A == 4) { } else if (entry->state == SFX_STATE_PLAYING_1) {
entry->unk_2A = 3; entry->state = SFX_STATE_PLAYING_REFRESH;
} }
} }
spAE = D_80130578[D_801333CC][arg0]; // Pick something to play for all channels.
for (i = 0; i < spAE; i++) { numChannels = gChannelsPerBank[gSfxChannelLayout][bankId];
phi_v1_5 = 0; for (i = 0; i < numChannels; i++) {
temp_s4_3 = &D_8016E1B8[arg0][i]; needNewSound = false;
activeSound = &gActiveSounds[bankId][i];
if (temp_s4_3->unk_4 == 0xFF) { if (activeSound->entryIndex == 0xFF) {
phi_v1_5 = 1; needNewSound = true;
} else { } else {
entry = &gSoundBanks[arg0][temp_s4_3[0].unk_4]; entry = &gSoundBanks[bankId][activeSound[0].entryIndex];
if (entry->unk_2A == 4) { if (entry->state == SFX_STATE_PLAYING_1) {
if (entry->sfxId & 0xC00) { if (entry->sfxId & 0xC00) {
func_800F7B54(arg0, temp_s4_3->unk_4); Audio_RemoveSoundBankEntry(bankId, activeSound->entryIndex);
} else { } else {
entry->unk_2A = 1; entry->state = SFX_STATE_QUEUED;
} }
phi_v1_5 = 1; needNewSound = true;
} else if (entry->unk_2A == 0) { } else if (entry->state == SFX_STATE_EMPTY) {
temp_s4_3->unk_4 = 0xFF; activeSound->entryIndex = 0xFF;
phi_v1_5 = 1; needNewSound = true;
} else { } else {
for (j = 0; j < spAE; j++) { // Sound is already playing as it should, nothing to do.
if (temp_s4_3->unk_4 == sp84[j].unk_4) { for (j = 0; j < numChannels; j++) {
sp84[j].unk_4 = 0xFF; if (activeSound->entryIndex == chosenSounds[j].entryIndex) {
j = spAE; chosenSounds[j].entryIndex = 0xFF;
j = numChannels;
} }
} }
phi_s3--; numChosenSounds--;
} }
} }
if (phi_v1_5 == 1) { if (needNewSound == true) {
for (j = 0; j < spAE; j++) { for (j = 0; j < numChannels; j++) {
temp2 = sp84[j].unk_4; chosenEntryIndex = chosenSounds[j].entryIndex;
if ((temp2 != 0xFF) && (gSoundBanks[arg0][temp2].unk_2A != 3)) { if ((chosenEntryIndex != 0xFF) &&
for (phi_s0 = 0; phi_s0 < spAE; phi_s0++) { (gSoundBanks[bankId][chosenEntryIndex].state != SFX_STATE_PLAYING_REFRESH)) {
if (temp2 == D_8016E1B8[arg0][phi_s0].unk_4) { for (k = 0; k < numChannels; k++) {
phi_v1_5 = 0; if (chosenEntryIndex == gActiveSounds[bankId][k].entryIndex) {
phi_s0 = spAE; needNewSound = false;
k = numChannels; // "break;"
} }
} }
if (phi_v1_5 == 1) { if (needNewSound == true) {
temp_s4_3->unk_4 = temp2; activeSound->entryIndex = chosenEntryIndex;
chosenSounds[j].entryIndex = 0xFF;
sp84[j].unk_4 = 0xFF; j = numChannels + 1;
numChosenSounds--;
j = spAE + 1;
phi_s3--;
} }
} }
} }
if (j == spAE) { if (j == numChannels) {
temp_s4_3->unk_4 = 0xFF; // nothing found
activeSound->entryIndex = 0xFF;
} }
} }
} }
} }
void func_800F8480(u8 bankId) { void Audio_PlayActiveSounds(u8 bankId) {
u8 bankIndex; u8 entryIndex;
SequenceChannel* seqChannel; SequenceChannel* channel;
SoundBankEntry* entry; SoundBankEntry* entry;
u8 i; u8 i;
for (i = 0; i < D_80130578[D_801333CC][bankId]; i++) { for (i = 0; i < gChannelsPerBank[gSfxChannelLayout][bankId]; i++) {
bankIndex = D_8016E1B8[bankId][i].unk_4; entryIndex = gActiveSounds[bankId][i].entryIndex;
if (bankIndex != 0xFF) { if (entryIndex != 0xFF) {
entry = &gSoundBanks[bankId][bankIndex]; entry = &gSoundBanks[bankId][entryIndex];
seqChannel = gAudioContext.seqPlayers[2].channels[D_8016E260]; channel = gAudioContext.seqPlayers[2].channels[sCurSfxPlayerChannelIdx];
if (entry->unk_2A == 2) { if (entry->state == SFX_STATE_READY) {
entry->unk_2E = D_8016E260; entry->channelIdx = sCurSfxPlayerChannelIdx;
if (entry->sfxParams & 8) { if (entry->sfxParams & 8) {
Audio_QueueSeqCmdMute(D_8016E260); Audio_QueueSeqCmdMute(sCurSfxPlayerChannelIdx);
} }
if (entry->sfxParams & 0xC0) { if (entry->sfxParams & 0xC0) {
switch (entry->sfxParams & 0xC0) { switch (entry->sfxParams & 0xC0) {
@ -502,47 +518,48 @@ void func_800F8480(u8 bankId) {
break; break;
} }
} }
Audio_SetSoundProperties(bankId, bankIndex, D_8016E260); Audio_SetSoundProperties(bankId, entryIndex, sCurSfxPlayerChannelIdx);
Audio_QueueCmdS8(0x06020000 | ((D_8016E260 & 0xFF) << 8), 1); Audio_QueueCmdS8(0x06020000 | ((sCurSfxPlayerChannelIdx & 0xFF) << 8), 1);
Audio_QueueCmdS8(0x06020000 | ((D_8016E260 & 0xFF) << 8) | 4, entry->sfxId & 0xFF); Audio_QueueCmdS8(0x06020000 | ((sCurSfxPlayerChannelIdx & 0xFF) << 8) | 4, entry->sfxId & 0xFF);
if (D_80130570[bankId] != 0) { if (gIsLargeSoundBank[bankId]) {
Audio_QueueCmdS8(0x06020000 | ((D_8016E260 & 0xFF) << 8) | 5, (entry->sfxId & 0x100) >> 8); Audio_QueueCmdS8(0x06020000 | ((sCurSfxPlayerChannelIdx & 0xFF) << 8) | 5,
(entry->sfxId & 0x100) >> 8);
} }
if (entry->sfxId & 0xC00) { if (entry->sfxId & 0xC00) {
entry->unk_2A = 4; entry->state = SFX_STATE_PLAYING_1;
} else { } else {
entry->unk_2A = 5; entry->state = SFX_STATE_PLAYING_2;
} }
} else if ((u8)seqChannel->soundScriptIO[1] == 0xFF) { } else if ((u8)channel->soundScriptIO[1] == 0xFF) {
func_800F7B54(bankId, bankIndex); Audio_RemoveSoundBankEntry(bankId, entryIndex);
} else if (entry->unk_2A == 3) { } else if (entry->state == SFX_STATE_PLAYING_REFRESH) {
Audio_SetSoundProperties(bankId, bankIndex, D_8016E260); Audio_SetSoundProperties(bankId, entryIndex, sCurSfxPlayerChannelIdx);
if (entry->sfxId & 0xC00) { if (entry->sfxId & 0xC00) {
entry->unk_2A = 4; entry->state = SFX_STATE_PLAYING_1;
} else { } else {
entry->unk_2A = 5; entry->state = SFX_STATE_PLAYING_2;
} }
} }
} }
D_8016E260++; sCurSfxPlayerChannelIdx++;
} }
} }
void func_800F87A0(u8 bankId) { void Audio_StopSfxByBank(u8 bankId) {
SoundBankEntry* entry; SoundBankEntry* entry;
s32 pad; s32 pad;
SoundBankEntry cmp; SoundBankEntry cmp;
u8 bankIndex = gSoundBanks[bankId][0].next; u8 entryIndex = gSoundBanks[bankId][0].next;
while (bankIndex != 0xFF) { while (entryIndex != 0xFF) {
entry = &gSoundBanks[bankId][bankIndex]; entry = &gSoundBanks[bankId][entryIndex];
if (entry->unk_2A >= 3) { if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
Audio_QueueCmdS8(0x06020000 | ((entry->unk_2E & 0xFF) << 8), 0); Audio_QueueCmdS8(0x06020000 | ((entry->channelIdx & 0xFF) << 8), 0);
} }
if (entry->unk_2A != 0) { if (entry->state != SFX_STATE_EMPTY) {
func_800F7B54(bankId, bankIndex); Audio_RemoveSoundBankEntry(bankId, entryIndex);
} }
bankIndex = gSoundBanks[bankId][0].next; entryIndex = gSoundBanks[bankId][0].next;
} }
cmp.sfxId = bankId << 12; cmp.sfxId = bankId << 12;
Audio_RemoveMatchingSoundRequests(0, &cmp); Audio_RemoveMatchingSoundRequests(0, &cmp);
@ -550,26 +567,26 @@ void func_800F87A0(u8 bankId) {
void func_800F8884(u8 bankId, Vec3f* pos) { void func_800F8884(u8 bankId, Vec3f* pos) {
SoundBankEntry* entry; SoundBankEntry* entry;
u8 bankIndex = gSoundBanks[bankId][0].next; u8 entryIndex = gSoundBanks[bankId][0].next;
u8 bankIndex2 = 0; u8 prevEntryIndex = 0;
while (bankIndex != 0xFF) { while (entryIndex != 0xFF) {
entry = &gSoundBanks[bankId][bankIndex]; entry = &gSoundBanks[bankId][entryIndex];
if (entry->posX == &pos->x) { if (entry->posX == &pos->x) {
if (entry->unk_2A >= 3) { if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
Audio_QueueCmdS8(0x06020000 | ((entry->unk_2E & 0xFF) << 8), 0); Audio_QueueCmdS8(0x06020000 | ((entry->channelIdx & 0xFF) << 8), 0);
} }
if (entry->unk_2A != 0) { if (entry->state != SFX_STATE_EMPTY) {
func_800F7B54(bankId, bankIndex); Audio_RemoveSoundBankEntry(bankId, entryIndex);
} }
} else { } else {
bankIndex2 = bankIndex; prevEntryIndex = entryIndex;
} }
bankIndex = gSoundBanks[bankId][bankIndex2].next; entryIndex = gSoundBanks[bankId][prevEntryIndex].next;
} }
} }
void func_800F89A0(u8 bankId, Vec3f* pos) { void Audio_StopSfxByPosAndBank(u8 bankId, Vec3f* pos) {
SoundBankEntry cmp; SoundBankEntry cmp;
func_800F8884(bankId, pos); func_800F8884(bankId, pos);
@ -578,7 +595,7 @@ void func_800F89A0(u8 bankId, Vec3f* pos) {
Audio_RemoveMatchingSoundRequests(1, &cmp); Audio_RemoveMatchingSoundRequests(1, &cmp);
} }
void func_800F89E8(Vec3f* pos) { void Audio_StopSfxByPos(Vec3f* pos) {
u8 i; u8 i;
SoundBankEntry cmp; SoundBankEntry cmp;
@ -589,27 +606,27 @@ void func_800F89E8(Vec3f* pos) {
Audio_RemoveMatchingSoundRequests(2, &cmp); Audio_RemoveMatchingSoundRequests(2, &cmp);
} }
void func_800F8A44(Vec3f* pos, u16 sfxId) { void Audio_StopSfxByPosAndId(Vec3f* pos, u16 sfxId) {
SoundBankEntry* entry; SoundBankEntry* entry;
u8 bankIndex = gSoundBanks[SFX_BANK(sfxId)][0].next; u8 entryIndex = gSoundBanks[SFX_BANK(sfxId)][0].next;
u8 bankIndex2 = 0; u8 prevEntryIndex = 0;
SoundBankEntry cmp; SoundBankEntry cmp;
while (bankIndex != 0xFF) { while (entryIndex != 0xFF) {
entry = &gSoundBanks[SFX_BANK(sfxId)][bankIndex]; entry = &gSoundBanks[SFX_BANK(sfxId)][entryIndex];
if (entry->posX == &pos->x && entry->sfxId == sfxId) { if (entry->posX == &pos->x && entry->sfxId == sfxId) {
if (entry->unk_2A >= 3) { if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
Audio_QueueCmdS8(0x06020000 | ((entry->unk_2E & 0xFF) << 8), 0); Audio_QueueCmdS8(0x06020000 | ((entry->channelIdx & 0xFF) << 8), 0);
} }
if (entry->unk_2A != 0) { if (entry->state != SFX_STATE_EMPTY) {
func_800F7B54(SFX_BANK(sfxId), bankIndex); Audio_RemoveSoundBankEntry(SFX_BANK(sfxId), entryIndex);
} }
bankIndex = 0xFF; entryIndex = 0xFF;
} else { } else {
bankIndex2 = bankIndex; prevEntryIndex = entryIndex;
} }
if (bankIndex != 0xFF) { if (entryIndex != 0xFF) {
bankIndex = gSoundBanks[SFX_BANK(sfxId)][bankIndex2].next; entryIndex = gSoundBanks[SFX_BANK(sfxId)][prevEntryIndex].next;
} }
} }
cmp.posX = &pos->x; cmp.posX = &pos->x;
@ -617,52 +634,52 @@ void func_800F8A44(Vec3f* pos, u16 sfxId) {
Audio_RemoveMatchingSoundRequests(3, &cmp); Audio_RemoveMatchingSoundRequests(3, &cmp);
} }
void func_800F8BA0(u8 arg0, u16 sfxId) { void Audio_StopSfxByTokenAndId(u8 token, u16 sfxId) {
SoundBankEntry* entry; SoundBankEntry* entry;
u8 bankIndex = gSoundBanks[SFX_BANK(sfxId)][0].next; u8 entryIndex = gSoundBanks[SFX_BANK(sfxId)][0].next;
u8 bankIndex2 = 0; u8 prevEntryIndex = 0;
SoundBankEntry cmp; SoundBankEntry cmp;
while (bankIndex != 0xFF) { while (entryIndex != 0xFF) {
entry = &gSoundBanks[SFX_BANK(sfxId)][bankIndex]; entry = &gSoundBanks[SFX_BANK(sfxId)][entryIndex];
if (entry->unk_C == arg0 && entry->sfxId == sfxId) { if (entry->token == token && entry->sfxId == sfxId) {
if (entry->unk_2A >= 3) { if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
Audio_QueueCmdS8(0x06020000 | ((entry->unk_2E & 0xFF) << 8), 0); Audio_QueueCmdS8(0x06020000 | ((entry->channelIdx & 0xFF) << 8), 0);
} }
if (entry->unk_2A != 0) { if (entry->state != SFX_STATE_EMPTY) {
func_800F7B54(SFX_BANK(sfxId), bankIndex); Audio_RemoveSoundBankEntry(SFX_BANK(sfxId), entryIndex);
} }
} else { } else {
bankIndex2 = bankIndex; prevEntryIndex = entryIndex;
} }
if (bankIndex != 0xFF) { if (entryIndex != 0xFF) {
bankIndex = gSoundBanks[SFX_BANK(sfxId)][bankIndex2].next; entryIndex = gSoundBanks[SFX_BANK(sfxId)][prevEntryIndex].next;
} }
} }
cmp.unk_C = arg0; cmp.token = token;
cmp.sfxId = sfxId; cmp.sfxId = sfxId;
Audio_RemoveMatchingSoundRequests(4, &cmp); Audio_RemoveMatchingSoundRequests(4, &cmp);
} }
void Audio_StopSfx(u32 sfxId) { void Audio_StopSfxById(u32 sfxId) {
SoundBankEntry* entry; SoundBankEntry* entry;
u8 bankIndex = gSoundBanks[SFX_BANK(sfxId)][0].next; u8 entryIndex = gSoundBanks[SFX_BANK(sfxId)][0].next;
u8 bankIndex2 = 0; u8 prevEntryIndex = 0;
SoundBankEntry cmp; SoundBankEntry cmp;
while (bankIndex != 0xFF) { while (entryIndex != 0xFF) {
entry = &gSoundBanks[SFX_BANK(sfxId)][bankIndex]; entry = &gSoundBanks[SFX_BANK(sfxId)][entryIndex];
if (entry->sfxId == sfxId) { if (entry->sfxId == sfxId) {
if (entry->unk_2A >= 3) { if (entry->state >= SFX_STATE_PLAYING_REFRESH) {
Audio_QueueCmdS8(0x06020000 | ((entry->unk_2E & 0xFF) << 8), 0); Audio_QueueCmdS8(0x06020000 | ((entry->channelIdx & 0xFF) << 8), 0);
} }
if (entry->unk_2A != 0) { if (entry->state != SFX_STATE_EMPTY) {
func_800F7B54(SFX_BANK(sfxId), bankIndex); Audio_RemoveSoundBankEntry(SFX_BANK(sfxId), entryIndex);
} }
} else { } else {
bankIndex2 = bankIndex; prevEntryIndex = entryIndex;
} }
bankIndex = gSoundBanks[SFX_BANK(sfxId)][bankIndex2].next; entryIndex = gSoundBanks[SFX_BANK(sfxId)][prevEntryIndex].next;
} }
cmp.sfxId = sfxId; cmp.sfxId = sfxId;
Audio_RemoveMatchingSoundRequests(5, &cmp); Audio_RemoveMatchingSoundRequests(5, &cmp);
@ -675,72 +692,72 @@ void Audio_ProcessSoundRequests(void) {
} }
} }
void func_800F8EA0(u8 arg0, u8 arg1, u16 arg2) { void Audio_SetUnusedBankLerp(u8 bankId, u8 target, u16 delay) {
if (arg2 == 0) { if (delay == 0) {
arg2++; delay++;
} }
D_8016E270[arg0].unk_4 = arg1 / 127.0f; sUnusedBankLerp[bankId].target = target / 127.0f;
D_8016E270[arg0].unk_C = arg2; sUnusedBankLerp[bankId].remainingFrames = delay;
D_8016E270[arg0].unk_8 = ((D_8016E270[arg0].unk_0 - D_8016E270[arg0].unk_4) / arg2); sUnusedBankLerp[bankId].step = ((sUnusedBankLerp[bankId].value - sUnusedBankLerp[bankId].target) / delay);
} }
void func_800F8F34(u8 arg0) { void Audio_StepUnusedBankLerp(u8 bankId) {
if (D_8016E270[arg0].unk_C != 0) { if (sUnusedBankLerp[bankId].remainingFrames != 0) {
D_8016E270[arg0].unk_C--; sUnusedBankLerp[bankId].remainingFrames--;
if (D_8016E270[arg0].unk_C != 0) { if (sUnusedBankLerp[bankId].remainingFrames != 0) {
D_8016E270[arg0].unk_0 -= D_8016E270[arg0].unk_8; sUnusedBankLerp[bankId].value -= sUnusedBankLerp[bankId].step;
} else { } else {
D_8016E270[arg0].unk_0 = D_8016E270[arg0].unk_4; sUnusedBankLerp[bankId].value = sUnusedBankLerp[bankId].target;
} }
} }
} }
void func_800F8F88(void) { void func_800F8F88(void) {
u8 i; u8 bankId;
if (IS_SEQUENCE_CHANNEL_VALID(gAudioContext.seqPlayers[2].channels[0])) { if (IS_SEQUENCE_CHANNEL_VALID(gAudioContext.seqPlayers[2].channels[0])) {
D_8016E260 = 0; sCurSfxPlayerChannelIdx = 0;
for (i = 0; i < ARRAY_COUNT(gSoundBanks); i++) { for (bankId = 0; bankId < ARRAY_COUNT(gSoundBanks); bankId++) {
func_800F7CEC(i); Audio_ChooseActiveSounds(bankId);
func_800F8480(i); Audio_PlayActiveSounds(bankId);
func_800F8F34(i); Audio_StepUnusedBankLerp(bankId);
} }
} }
} }
u8 Audio_IsSfxPlaying(u32 sfxId) { u8 Audio_IsSfxPlaying(u32 sfxId) {
SoundBankEntry* entry; SoundBankEntry* entry;
u8 bankIndex = gSoundBanks[SFX_BANK(sfxId)][0].next; u8 entryIndex = gSoundBanks[SFX_BANK(sfxId)][0].next;
while (bankIndex != 0xFF) { while (entryIndex != 0xFF) {
entry = &gSoundBanks[SFX_BANK(sfxId)][bankIndex]; entry = &gSoundBanks[SFX_BANK(sfxId)][entryIndex];
if (entry->sfxId == sfxId) { if (entry->sfxId == sfxId) {
return true; return true;
} }
bankIndex = entry->next; entryIndex = entry->next;
} }
return false; return false;
} }
void func_800F905C(void) { void Audio_ResetSounds(void) {
u8 bankId; u8 bankId;
u8 i; u8 i;
u8 bankIndex; u8 entryIndex;
sSoundRequestWriteIndex = 0; sSoundRequestWriteIndex = 0;
sSoundRequestReadIndex = 0; sSoundRequestReadIndex = 0;
D_801333D0 = 0; D_801333D0 = 0;
for (bankId = 0; bankId < ARRAY_COUNT(gSoundBanks); bankId++) { for (bankId = 0; bankId < ARRAY_COUNT(gSoundBanks); bankId++) {
D_8016E1A0[bankId] = 0; sSoundBankListEnd[bankId] = 0;
D_8016E1A8[bankId] = 1; sSoundBankFreeListStart[bankId] = 1;
D_8016E1B0[bankId] = 0; sSoundBankUnused[bankId] = 0;
gSoundBankMuted[bankId] = false; gSoundBankMuted[bankId] = false;
D_8016E270[bankId].unk_0 = 1.0f; sUnusedBankLerp[bankId].value = 1.0f;
D_8016E270[bankId].unk_C = 0; sUnusedBankLerp[bankId].remainingFrames = 0;
} }
for (bankId = 0; bankId < ARRAY_COUNT(gSoundBanks); bankId++) { for (bankId = 0; bankId < ARRAY_COUNT(gSoundBanks); bankId++) {
for (i = 0; i < 3; i++) { for (i = 0; i < MAX_CHANNELS_PER_BANK; i++) {
D_8016E1B8[bankId][i].unk_4 = 0xFF; gActiveSounds[bankId][i].entryIndex = 0xFF;
} }
} }
for (bankId = 0; bankId < ARRAY_COUNT(gSoundBanks); bankId++) { for (bankId = 0; bankId < ARRAY_COUNT(gSoundBanks); bankId++) {
@ -755,9 +772,9 @@ void func_800F905C(void) {
} }
if (D_801333F8 == 0) { if (D_801333F8 == 0) {
for (bankId = 0; bankId < 10; bankId++) { for (bankId = 0; bankId < 10; bankId++) {
gAudioSEFlagSwapSource[bankId] = 0; gAudioSfxSwapSource[bankId] = 0;
gAudioSEFlagSwapTarget[bankId] = 0; gAudioSfxSwapTarget[bankId] = 0;
gAudioSEFlagSwapMode[bankId] = 0; gAudioSfxSwapMode[bankId] = 0;
} }
D_801333F8++; D_801333F8++;
} }

View file

@ -9,56 +9,55 @@ extern u8 sSeqCmdRdPos;
extern u8 sSeqCmdWrPos; extern u8 sSeqCmdWrPos;
extern u8 D_80133408; extern u8 D_80133408;
extern u8 D_80133418; extern u8 D_80133418;
extern u8 D_801333CC;
extern u8 D_80133410[]; extern u8 D_80133410[];
// TODO: clean up these macros. They are similar to ones in code_800EC960.c but without casts. // TODO: clean up these macros. They are similar to ones in code_800EC960.c but without casts.
#define Audio_StartSeq(seqIdx, fadeTimer, seqId) \ #define Audio_StartSeq(playerIdx, fadeTimer, seqId) \
Audio_QueueSeqCmd(0x00000000 | ((seqIdx) << 24) | ((fadeTimer) << 16) | (seqId)) Audio_QueueSeqCmd(0x00000000 | ((playerIdx) << 24) | ((fadeTimer) << 16) | (seqId))
#define Audio_SeqCmdA(seqIdx, a) Audio_QueueSeqCmd(0xA0000000 | ((seqIdx) << 24) | (a)) #define Audio_SeqCmdA(playerIdx, a) Audio_QueueSeqCmd(0xA0000000 | ((playerIdx) << 24) | (a))
#define Audio_SeqCmdB30(seqIdx, a, b) Audio_QueueSeqCmd(0xB0003000 | ((seqIdx) << 24) | ((a) << 16) | (b)) #define Audio_SeqCmdB30(playerIdx, a, b) Audio_QueueSeqCmd(0xB0003000 | ((playerIdx) << 24) | ((a) << 16) | (b))
#define Audio_SeqCmdB40(seqIdx, a, b) Audio_QueueSeqCmd(0xB0004000 | ((seqIdx) << 24) | ((a) << 16) | (b)) #define Audio_SeqCmdB40(playerIdx, a, b) Audio_QueueSeqCmd(0xB0004000 | ((playerIdx) << 24) | ((a) << 16) | (b))
#define Audio_SeqCmd3(seqIdx, a) Audio_QueueSeqCmd(0x30000000 | ((seqIdx) << 24) | (a)) #define Audio_SeqCmd3(playerIdx, a) Audio_QueueSeqCmd(0x30000000 | ((playerIdx) << 24) | (a))
#define Audio_SeqCmd5(seqIdx, a, b) Audio_QueueSeqCmd(0x50000000 | ((seqIdx) << 24) | ((a) << 16) | (b)) #define Audio_SeqCmd5(playerIdx, a, b) Audio_QueueSeqCmd(0x50000000 | ((playerIdx) << 24) | ((a) << 16) | (b))
#define Audio_SeqCmd4(seqIdx, a, b) Audio_QueueSeqCmd(0x40000000 | ((seqIdx) << 24) | ((a) << 16) | (b)) #define Audio_SeqCmd4(playerIdx, a, b) Audio_QueueSeqCmd(0x40000000 | ((playerIdx) << 24) | ((a) << 16) | (b))
#define Audio_SetVolScaleNow(seqIdx, volFadeTimer, volScale) \ #define Audio_SetVolScaleNow(playerIdx, volFadeTimer, volScale) \
Audio_ProcessSeqCmd(0x40000000 | ((u8)seqIdx << 24) | ((u8)volFadeTimer << 16) | ((u8)(volScale * 127.0f))); Audio_ProcessSeqCmd(0x40000000 | ((u8)playerIdx << 24) | ((u8)volFadeTimer << 16) | ((u8)(volScale * 127.0f)));
void func_800F9280(u8 seqIdx, u8 seqId, u8 arg2, u16 fadeTimer) { void func_800F9280(u8 playerIdx, u8 seqId, u8 arg2, u16 fadeTimer) {
u8 i; u8 i;
u16 dur; u16 dur;
s32 pad; s32 pad;
if (D_80133408 == 0 || seqIdx == 2) { if (D_80133408 == 0 || playerIdx == 2) {
arg2 &= 0x7F; arg2 &= 0x7F;
if (arg2 == 0x7F) { if (arg2 == 0x7F) {
dur = (fadeTimer >> 3) * 60 * gAudioContext.audioBufferParameters.updatesPerFrame; dur = (fadeTimer >> 3) * 60 * gAudioContext.audioBufferParameters.updatesPerFrame;
Audio_QueueCmdS32(0x85000000 | _SHIFTL(seqIdx, 16, 8) | _SHIFTL(seqId, 8, 8), dur); Audio_QueueCmdS32(0x85000000 | _SHIFTL(playerIdx, 16, 8) | _SHIFTL(seqId, 8, 8), dur);
} else { } else {
Audio_QueueCmdS32(0x82000000 | _SHIFTL(seqIdx, 16, 8) | _SHIFTL(seqId, 8, 8), Audio_QueueCmdS32(0x82000000 | _SHIFTL(playerIdx, 16, 8) | _SHIFTL(seqId, 8, 8),
(fadeTimer * (u16)gAudioContext.audioBufferParameters.updatesPerFrame) / 4); (fadeTimer * (u16)gAudioContext.audioBufferParameters.updatesPerFrame) / 4);
} }
D_8016E750[seqIdx].unk_254 = seqId | (arg2 << 8); D_8016E750[playerIdx].unk_254 = seqId | (arg2 << 8);
D_8016E750[seqIdx].unk_256 = seqId | (arg2 << 8); D_8016E750[playerIdx].unk_256 = seqId | (arg2 << 8);
if (D_8016E750[seqIdx].volCur != 1.0f) { if (D_8016E750[playerIdx].volCur != 1.0f) {
Audio_QueueCmdF32(0x41000000 | _SHIFTL(seqIdx, 16, 8), D_8016E750[seqIdx].volCur); Audio_QueueCmdF32(0x41000000 | _SHIFTL(playerIdx, 16, 8), D_8016E750[playerIdx].volCur);
} }
D_8016E750[seqIdx].unk_28 = 0; D_8016E750[playerIdx].unk_28 = 0;
D_8016E750[seqIdx].unk_18 = 0; D_8016E750[playerIdx].unk_18 = 0;
D_8016E750[seqIdx].unk_14 = 0; D_8016E750[playerIdx].unk_14 = 0;
for (i = 0; i < 0x10; i++) { for (i = 0; i < 0x10; i++) {
D_8016E750[seqIdx].unk_50[i].unk_00 = 1.0f; D_8016E750[playerIdx].unk_50[i].unk_00 = 1.0f;
D_8016E750[seqIdx].unk_50[i].unk_0C = 0; D_8016E750[playerIdx].unk_50[i].unk_0C = 0;
D_8016E750[seqIdx].unk_50[i].unk_10 = 1.0f; D_8016E750[playerIdx].unk_50[i].unk_10 = 1.0f;
D_8016E750[seqIdx].unk_50[i].unk_1C = 0; D_8016E750[playerIdx].unk_50[i].unk_1C = 0;
} }
D_8016E750[seqIdx].unk_250 = 0; D_8016E750[playerIdx].unk_250 = 0;
D_8016E750[seqIdx].unk_252 = 0; D_8016E750[playerIdx].unk_252 = 0;
} }
} }
@ -102,7 +101,7 @@ void Audio_ProcessSeqCmd(u32 cmd) {
u8 spec; u8 spec;
u8 op; u8 op;
u8 subOp; u8 subOp;
u8 seqIdx; u8 playerIdx;
u8 seqId; u8 seqId;
u8 seqArgs; u8 seqArgs;
u8 found; u8 found;
@ -119,7 +118,7 @@ void Audio_ProcessSeqCmd(u32 cmd) {
} }
op = cmd >> 28; op = cmd >> 28;
seqIdx = (cmd & 0xF000000) >> 24; playerIdx = (cmd & 0xF000000) >> 24;
switch (op) { switch (op) {
case 0x0: case 0x0:
@ -127,15 +126,15 @@ void Audio_ProcessSeqCmd(u32 cmd) {
seqId = cmd & 0xFF; seqId = cmd & 0xFF;
seqArgs = (cmd & 0xFF00) >> 8; seqArgs = (cmd & 0xFF00) >> 8;
fadeTimer = (cmd & 0xFF0000) >> 13; fadeTimer = (cmd & 0xFF0000) >> 13;
if ((D_8016E750[seqIdx].unk_260 == 0) && (seqArgs < 0x80)) { if ((D_8016E750[playerIdx].unk_260 == 0) && (seqArgs < 0x80)) {
func_800F9280(seqIdx, seqId, seqArgs, fadeTimer); func_800F9280(playerIdx, seqId, seqArgs, fadeTimer);
} }
break; break;
case 0x1: case 0x1:
// disable seq player // disable seq player
fadeTimer = (cmd & 0xFF0000) >> 13; fadeTimer = (cmd & 0xFF0000) >> 13;
func_800F9474(seqIdx, fadeTimer); func_800F9474(playerIdx, fadeTimer);
break; break;
case 0x2: case 0x2:
@ -144,35 +143,35 @@ void Audio_ProcessSeqCmd(u32 cmd) {
seqArgs = (cmd & 0xFF00) >> 8; seqArgs = (cmd & 0xFF00) >> 8;
fadeTimer = (cmd & 0xFF0000) >> 13; fadeTimer = (cmd & 0xFF0000) >> 13;
new_var = seqArgs; new_var = seqArgs;
for (i = 0; i < D_8016E348[seqIdx]; i++) { for (i = 0; i < D_8016E348[playerIdx]; i++) {
if (D_8016E320[seqIdx][i].unk_0 == seqId) { if (D_8016E320[playerIdx][i].unk_0 == seqId) {
if (i == 0) { if (i == 0) {
func_800F9280(seqIdx, seqId, seqArgs, fadeTimer); func_800F9280(playerIdx, seqId, seqArgs, fadeTimer);
} }
return; return;
} }
} }
found = D_8016E348[seqIdx]; found = D_8016E348[playerIdx];
for (i = 0; i < D_8016E348[seqIdx]; i++) { for (i = 0; i < D_8016E348[playerIdx]; i++) {
if (D_8016E320[seqIdx][i].unk_1 <= new_var) { if (D_8016E320[playerIdx][i].unk_1 <= new_var) {
found = i; found = i;
i = D_8016E348[seqIdx]; // "break;" i = D_8016E348[playerIdx]; // "break;"
} }
} }
if (D_8016E348[seqIdx] < 5) { if (D_8016E348[playerIdx] < 5) {
D_8016E348[seqIdx]++; D_8016E348[playerIdx]++;
} }
for (i = D_8016E348[seqIdx] - 1; i != found; i--) { for (i = D_8016E348[playerIdx] - 1; i != found; i--) {
D_8016E320[seqIdx][i].unk_1 = D_8016E320[seqIdx][i - 1].unk_1; D_8016E320[playerIdx][i].unk_1 = D_8016E320[playerIdx][i - 1].unk_1;
D_8016E320[seqIdx][i].unk_0 = D_8016E320[seqIdx][i - 1].unk_0; D_8016E320[playerIdx][i].unk_0 = D_8016E320[playerIdx][i - 1].unk_0;
} }
D_8016E320[seqIdx][found].unk_1 = seqArgs; D_8016E320[playerIdx][found].unk_1 = seqArgs;
D_8016E320[seqIdx][found].unk_0 = seqId; D_8016E320[playerIdx][found].unk_0 = seqId;
if (found == 0) { if (found == 0) {
func_800F9280(seqIdx, seqId, seqArgs, fadeTimer); func_800F9280(playerIdx, seqId, seqArgs, fadeTimer);
} }
break; break;
@ -181,26 +180,26 @@ void Audio_ProcessSeqCmd(u32 cmd) {
seqId = cmd & 0xFF; seqId = cmd & 0xFF;
fadeTimer = (cmd & 0xFF0000) >> 13; fadeTimer = (cmd & 0xFF0000) >> 13;
found = D_8016E348[seqIdx]; found = D_8016E348[playerIdx];
for (i = 0; i < D_8016E348[seqIdx]; i++) { for (i = 0; i < D_8016E348[playerIdx]; i++) {
if (D_8016E320[seqIdx][i].unk_0 == seqId) { if (D_8016E320[playerIdx][i].unk_0 == seqId) {
found = i; found = i;
i = D_8016E348[seqIdx]; // "break;" i = D_8016E348[playerIdx]; // "break;"
} }
} }
if (found != D_8016E348[seqIdx]) { if (found != D_8016E348[playerIdx]) {
for (i = found; i < D_8016E348[seqIdx] - 1; i++) { for (i = found; i < D_8016E348[playerIdx] - 1; i++) {
D_8016E320[seqIdx][i].unk_1 = D_8016E320[seqIdx][i + 1].unk_1; D_8016E320[playerIdx][i].unk_1 = D_8016E320[playerIdx][i + 1].unk_1;
D_8016E320[seqIdx][i].unk_0 = D_8016E320[seqIdx][i + 1].unk_0; D_8016E320[playerIdx][i].unk_0 = D_8016E320[playerIdx][i + 1].unk_0;
} }
D_8016E348[seqIdx]--; D_8016E348[playerIdx]--;
} }
if (found == 0) { if (found == 0) {
func_800F9474(seqIdx, fadeTimer); func_800F9474(playerIdx, fadeTimer);
if (D_8016E348[seqIdx] != 0) { if (D_8016E348[playerIdx] != 0) {
func_800F9280(seqIdx, D_8016E320[seqIdx][0].unk_0, D_8016E320[seqIdx][0].unk_1, fadeTimer); func_800F9280(playerIdx, D_8016E320[playerIdx][0].unk_0, D_8016E320[playerIdx][0].unk_1, fadeTimer);
} }
} }
break; break;
@ -212,10 +211,11 @@ void Audio_ProcessSeqCmd(u32 cmd) {
if (duration == 0) { if (duration == 0) {
duration++; duration++;
} }
D_8016E750[seqIdx].volTarget = (f32)val / 127.0f; D_8016E750[playerIdx].volTarget = (f32)val / 127.0f;
if (D_8016E750[seqIdx].volCur != D_8016E750[seqIdx].volTarget) { if (D_8016E750[playerIdx].volCur != D_8016E750[playerIdx].volTarget) {
D_8016E750[seqIdx].unk_08 = (D_8016E750[seqIdx].volCur - D_8016E750[seqIdx].volTarget) / (f32)duration; D_8016E750[playerIdx].unk_08 =
D_8016E750[seqIdx].unk_0C = duration; (D_8016E750[playerIdx].volCur - D_8016E750[playerIdx].volTarget) / (f32)duration;
D_8016E750[playerIdx].unk_0C = duration;
} }
break; break;
@ -228,11 +228,12 @@ void Audio_ProcessSeqCmd(u32 cmd) {
} }
freqScale = (f32)val / 1000.0f; freqScale = (f32)val / 1000.0f;
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++) {
D_8016E750[seqIdx].unk_50[i].unk_14 = freqScale; D_8016E750[playerIdx].unk_50[i].unk_14 = freqScale;
D_8016E750[seqIdx].unk_50[i].unk_1C = duration; D_8016E750[playerIdx].unk_50[i].unk_1C = duration;
D_8016E750[seqIdx].unk_50[i].unk_18 = (D_8016E750[seqIdx].unk_50[i].unk_10 - freqScale) / (f32)duration; D_8016E750[playerIdx].unk_50[i].unk_18 =
(D_8016E750[playerIdx].unk_50[i].unk_10 - freqScale) / (f32)duration;
} }
D_8016E750[seqIdx].unk_250 = 0xFFFF; D_8016E750[playerIdx].unk_250 = 0xFFFF;
break; break;
case 0xD: case 0xD:
@ -244,11 +245,11 @@ void Audio_ProcessSeqCmd(u32 cmd) {
duration++; duration++;
} }
freqScale = (f32)val / 1000.0f; freqScale = (f32)val / 1000.0f;
D_8016E750[seqIdx].unk_50[chanIdx].unk_14 = freqScale; D_8016E750[playerIdx].unk_50[chanIdx].unk_14 = freqScale;
D_8016E750[seqIdx].unk_50[chanIdx].unk_18 = D_8016E750[playerIdx].unk_50[chanIdx].unk_18 =
(D_8016E750[seqIdx].unk_50[chanIdx].unk_10 - freqScale) / (f32)duration; (D_8016E750[playerIdx].unk_50[chanIdx].unk_10 - freqScale) / (f32)duration;
D_8016E750[seqIdx].unk_50[chanIdx].unk_1C = duration; D_8016E750[playerIdx].unk_50[chanIdx].unk_1C = duration;
D_8016E750[seqIdx].unk_250 |= 1 << chanIdx; D_8016E750[playerIdx].unk_250 |= 1 << chanIdx;
break; break;
case 0x6: case 0x6:
@ -259,13 +260,13 @@ void Audio_ProcessSeqCmd(u32 cmd) {
if (duration == 0) { if (duration == 0) {
duration++; duration++;
} }
D_8016E750[seqIdx].unk_50[chanIdx].unk_04 = (f32)val / 127.0f; D_8016E750[playerIdx].unk_50[chanIdx].unk_04 = (f32)val / 127.0f;
if (D_8016E750[seqIdx].unk_50[chanIdx].unk_00 != D_8016E750[seqIdx].unk_50[chanIdx].unk_04) { if (D_8016E750[playerIdx].unk_50[chanIdx].unk_00 != D_8016E750[playerIdx].unk_50[chanIdx].unk_04) {
D_8016E750[seqIdx].unk_50[chanIdx].unk_08 = D_8016E750[playerIdx].unk_50[chanIdx].unk_08 =
(D_8016E750[seqIdx].unk_50[chanIdx].unk_00 - D_8016E750[seqIdx].unk_50[chanIdx].unk_04) / (D_8016E750[playerIdx].unk_50[chanIdx].unk_00 - D_8016E750[playerIdx].unk_50[chanIdx].unk_04) /
(f32)duration; (f32)duration;
D_8016E750[seqIdx].unk_50[chanIdx].unk_0C = duration; D_8016E750[playerIdx].unk_50[chanIdx].unk_0C = duration;
D_8016E750[seqIdx].unk_252 |= 1 << chanIdx; D_8016E750[playerIdx].unk_252 |= 1 << chanIdx;
} }
break; break;
@ -273,7 +274,7 @@ void Audio_ProcessSeqCmd(u32 cmd) {
// set global io port // set global io port
port = (cmd & 0xFF0000) >> 16; port = (cmd & 0xFF0000) >> 16;
val = cmd & 0xFF; val = cmd & 0xFF;
Audio_QueueCmdS8(0x46000000 | _SHIFTL(seqIdx, 16, 8) | _SHIFTL(port, 0, 8), val); Audio_QueueCmdS8(0x46000000 | _SHIFTL(playerIdx, 16, 8) | _SHIFTL(port, 0, 8), val);
break; break;
case 0x8: case 0x8:
@ -281,15 +282,15 @@ void Audio_ProcessSeqCmd(u32 cmd) {
chanIdx = (cmd & 0xF00) >> 8; chanIdx = (cmd & 0xF00) >> 8;
port = (cmd & 0xFF0000) >> 16; port = (cmd & 0xFF0000) >> 16;
val = cmd & 0xFF; val = cmd & 0xFF;
if ((D_8016E750[seqIdx].unk_258 & (1 << chanIdx)) == 0) { if ((D_8016E750[playerIdx].unk_258 & (1 << chanIdx)) == 0) {
Audio_QueueCmdS8(0x06000000 | _SHIFTL(seqIdx, 16, 8) | _SHIFTL(chanIdx, 8, 8) | _SHIFTL(port, 0, 8), Audio_QueueCmdS8(0x06000000 | _SHIFTL(playerIdx, 16, 8) | _SHIFTL(chanIdx, 8, 8) | _SHIFTL(port, 0, 8),
val); val);
} }
break; break;
case 0x9: case 0x9:
// set channel mask for command 0x8 // set channel mask for command 0x8
D_8016E750[seqIdx].unk_258 = cmd & 0xFFFF; D_8016E750[playerIdx].unk_258 = cmd & 0xFFFF;
break; break;
case 0xA: case 0xA:
@ -297,36 +298,36 @@ void Audio_ProcessSeqCmd(u32 cmd) {
channelMask = cmd & 0xFFFF; channelMask = cmd & 0xFFFF;
if (channelMask != 0) { if (channelMask != 0) {
// with channel mask channelMask... // with channel mask channelMask...
Audio_QueueCmdU16(0x90000000 | _SHIFTL(seqIdx, 16, 8), channelMask); Audio_QueueCmdU16(0x90000000 | _SHIFTL(playerIdx, 16, 8), channelMask);
// stop channels // stop channels
Audio_QueueCmdS8(0x08000000 | _SHIFTL(seqIdx, 16, 8) | 0xFF00, 1); Audio_QueueCmdS8(0x08000000 | _SHIFTL(playerIdx, 16, 8) | 0xFF00, 1);
} }
if ((channelMask ^ 0xFFFF) != 0) { if ((channelMask ^ 0xFFFF) != 0) {
// with channel mask ~channelMask... // with channel mask ~channelMask...
Audio_QueueCmdU16(0x90000000 | _SHIFTL(seqIdx, 16, 8), (channelMask ^ 0xFFFF)); Audio_QueueCmdU16(0x90000000 | _SHIFTL(playerIdx, 16, 8), (channelMask ^ 0xFFFF));
// unstop channels // unstop channels
Audio_QueueCmdS8(0x08000000 | _SHIFTL(seqIdx, 16, 8) | 0xFF00, 0); Audio_QueueCmdS8(0x08000000 | _SHIFTL(playerIdx, 16, 8) | 0xFF00, 0);
} }
break; break;
case 0xB: case 0xB:
// update tempo // update tempo
D_8016E750[seqIdx].unk_14 = cmd; D_8016E750[playerIdx].unk_14 = cmd;
break; break;
case 0xC: case 0xC:
// start sequence with setup commands // start sequence with setup commands
subOp = (cmd & 0xF00000) >> 20; subOp = (cmd & 0xF00000) >> 20;
if (subOp != 0xF) { if (subOp != 0xF) {
if (D_8016E750[seqIdx].unk_4D < 7) { if (D_8016E750[playerIdx].unk_4D < 7) {
found = D_8016E750[seqIdx].unk_4D++; found = D_8016E750[playerIdx].unk_4D++;
if (found < 8) { if (found < 8) {
D_8016E750[seqIdx].unk_2C[found] = cmd; D_8016E750[playerIdx].unk_2C[found] = cmd;
D_8016E750[seqIdx].unk_4C = 2; D_8016E750[playerIdx].unk_4C = 2;
} }
} }
} else { } else {
D_8016E750[seqIdx].unk_4D = 0; D_8016E750[playerIdx].unk_4D = 0;
} }
break; break;
@ -348,7 +349,7 @@ void Audio_ProcessSeqCmd(u32 cmd) {
case 0xF: case 0xF:
// change spec // change spec
spec = cmd & 0xFF; spec = cmd & 0xFF;
D_801333CC = (cmd & 0xFF00) >> 8; gSfxChannelLayout = (cmd & 0xFF00) >> 8;
oldSpec = gAudioSpecId; oldSpec = gAudioSpecId;
gAudioSpecId = spec; gAudioSpecId = spec;
func_800E5F88(spec); func_800E5F88(spec);
@ -403,21 +404,21 @@ void func_800FA18C(u8 arg0, u8 arg1) {
} }
} }
void Audio_SetVolScale(u8 seqIdx, u8 scaleIdx, u8 targetVol, u8 volFadeTimer) { void Audio_SetVolScale(u8 playerIdx, u8 scaleIdx, u8 targetVol, u8 volFadeTimer) {
f32 volScale; f32 volScale;
u8 i; u8 i;
D_8016E750[seqIdx].volScales[scaleIdx] = targetVol & 0x7F; D_8016E750[playerIdx].volScales[scaleIdx] = targetVol & 0x7F;
if (volFadeTimer != 0) { if (volFadeTimer != 0) {
D_8016E750[seqIdx].fadeVolUpdate = 1; D_8016E750[playerIdx].fadeVolUpdate = 1;
D_8016E750[seqIdx].volFadeTimer = volFadeTimer; D_8016E750[playerIdx].volFadeTimer = volFadeTimer;
} else { } else {
for (i = 0, volScale = 1.0f; i < 4; i++) { for (i = 0, volScale = 1.0f; i < 4; i++) {
volScale *= D_8016E750[seqIdx].volScales[i] / 127.0f; volScale *= D_8016E750[playerIdx].volScales[i] / 127.0f;
} }
Audio_SetVolScaleNow(seqIdx, volFadeTimer, volScale); Audio_SetVolScaleNow(playerIdx, volFadeTimer, volScale);
} }
} }
@ -432,7 +433,7 @@ void func_800FA3DC(void) {
u8 temp_s0_3; u8 temp_s0_3;
u8 temp_a3_3; u8 temp_a3_3;
s32 pad[3]; s32 pad[3];
u32 sp70; u32 dummy;
f32 phi_f0; f32 phi_f0;
u8 phi_t0; u8 phi_t0;
u8 i; u8 i;
@ -441,7 +442,7 @@ void func_800FA3DC(void) {
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
if (D_8016E750[i].unk_260 != 0) { if (D_8016E750[i].unk_260 != 0) {
switch (func_800E5E20(&sp70)) { switch (func_800E5E20(&dummy)) {
case 1: case 1:
case 2: case 2:
case 3: case 3:
@ -624,13 +625,13 @@ void func_800FA3DC(void) {
break; break;
case 14: case 14:
if (temp_a3_3 & 1) { if (temp_a3_3 & 1) {
Audio_QueueCmdS32(0xE3000000, 0); Audio_QueueCmdS32(0xE3000000, SEQUENCE_TABLE);
} }
if (temp_a3_3 & 2) { if (temp_a3_3 & 2) {
Audio_QueueCmdS32(0xE3000000, 1); Audio_QueueCmdS32(0xE3000000, FONT_TABLE);
} }
if (temp_a3_3 & 4) { if (temp_a3_3 & 4) {
Audio_QueueCmdS32(0xE3000000, 2); Audio_QueueCmdS32(0xE3000000, SAMPLE_TABLE);
} }
break; break;
case 9: case 9:
@ -653,13 +654,13 @@ u8 func_800FAD34(void) {
if (D_80133418 == 1) { if (D_80133418 == 1) {
if (func_800E5EDC() == 1) { if (func_800E5EDC() == 1) {
D_80133418 = 0; D_80133418 = 0;
Audio_QueueCmdS8(0x46020000, D_801333CC); Audio_QueueCmdS8(0x46020000, gSfxChannelLayout);
func_800F7170(); func_800F7170();
} }
} else if (D_80133418 == 2) { } else if (D_80133418 == 2) {
while (func_800E5EDC() != 1) {} while (func_800E5EDC() != 1) {}
D_80133418 = 0; D_80133418 = 0;
Audio_QueueCmdS8(0x46020000, D_801333CC); Audio_QueueCmdS8(0x46020000, gSfxChannelLayout);
func_800F7170(); func_800F7170();
} }
} }

View file

@ -51,7 +51,7 @@ void Fault_ClientProcessThread(void* arg) {
} }
if (ctx->queue != NULL) { if (ctx->queue != NULL) {
osSendMesg(ctx->queue, ctx->msg, 1); osSendMesg(ctx->queue, ctx->msg, OS_MESG_BLOCK);
} }
} }
@ -81,7 +81,7 @@ void Fault_ProcessClientContext(FaultClientContext* ctx) {
while (true) { while (true) {
osSetTimer(&timer, OS_USEC_TO_CYCLES(1000000), 0, &queue, (OSMesg)timerMsgVal); osSetTimer(&timer, OS_USEC_TO_CYCLES(1000000), 0, &queue, (OSMesg)timerMsgVal);
osRecvMesg(&queue, &recMsg, 1); osRecvMesg(&queue, &recMsg, OS_MESG_BLOCK);
if (recMsg != (OSMesg)666) { if (recMsg != (OSMesg)666) {
break; break;
@ -957,7 +957,7 @@ void Fault_ThreadEntry(void* arg) {
while (true) { while (true) {
do { do {
osRecvMesg(&sFaultStructPtr->queue, &msg, 1); osRecvMesg(&sFaultStructPtr->queue, &msg, OS_MESG_BLOCK);
if (msg == (OSMesg)1) { if (msg == (OSMesg)1) {
sFaultStructPtr->msgId = 1; sFaultStructPtr->msgId = 1;

View file

@ -87,7 +87,7 @@ void Sched_HandleReset(SchedContext* sc) {
if (sc->curRDPTask != NULL) { if (sc->curRDPTask != NULL) {
LOG_TIME("(((u64)(now - rdp_start_time)*(1000000LL/15625LL))/((62500000LL*3/4)/15625LL))", LOG_TIME("(((u64)(now - rdp_start_time)*(1000000LL/15625LL))/((62500000LL*3/4)/15625LL))",
OS_CYCLES_TO_USEC(now - sRDPStartTime), "../sched.c", 431); OS_CYCLES_TO_USEC(now - sRDPStartTime), "../sched.c", 431);
osSendMesg(&sc->interruptQ, RDP_DONE_MSG, 0); osSendMesg(&sc->interruptQ, RDP_DONE_MSG, OS_MESG_NOBLOCK);
} }
} }
} }

View file

@ -2837,7 +2837,7 @@ Actor* Actor_Delete(ActorContext* actorCtx, Actor* actor, GlobalContext* globalC
actorCtx->targetCtx.unk_90 = NULL; actorCtx->targetCtx.unk_90 = NULL;
} }
func_800F89E8(&actor->projectedPos); Audio_StopSfxByPos(&actor->projectedPos);
Actor_Destroy(actor, globalCtx); Actor_Destroy(actor, globalCtx);
newHead = Actor_RemoveFromCategory(globalCtx, actorCtx, actor); newHead = Actor_RemoveFromCategory(globalCtx, actorCtx, actor);

View file

@ -7129,7 +7129,7 @@ s32 Camera_CheckWater(Camera* camera) {
camera->unk_150 = 0x50; camera->unk_150 = 0x50;
} }
func_800F6828(0x20); Audio_SetExtraFilter(0x20);
if (PREG(81)) { if (PREG(81)) {
Quake_RemoveFromIdx(*quakeId); Quake_RemoveFromIdx(*quakeId);
@ -7164,7 +7164,7 @@ s32 Camera_CheckWater(Camera* camera) {
camera->unk_150 = 0; camera->unk_150 = 0;
camera->unk_152 = 0; camera->unk_152 = 0;
} }
func_800F6828(0); Audio_SetExtraFilter(0);
} }
//! @bug: doesn't always return a value, but sometimes does. //! @bug: doesn't always return a value, but sometimes does.
} }

View file

@ -62,11 +62,11 @@ void EffectSs_ClearAll(GlobalContext* globalCtx) {
void EffectSs_Delete(EffectSs* effectSs) { void EffectSs_Delete(EffectSs* effectSs) {
if (effectSs->flags & 2) { if (effectSs->flags & 2) {
func_800F89E8(&effectSs->pos); Audio_StopSfxByPos(&effectSs->pos);
} }
if (effectSs->flags & 4) { if (effectSs->flags & 4) {
func_800F89E8(&effectSs->vec); Audio_StopSfxByPos(&effectSs->vec);
} }
EffectSs_Reset(effectSs); EffectSs_Reset(effectSs);

View file

@ -205,7 +205,7 @@ void Gameplay_Init(GameState* thisx) {
GameState_Realloc(&globalCtx->state, 0x1D4790); GameState_Realloc(&globalCtx->state, 0x1D4790);
KaleidoManager_Init(globalCtx); KaleidoManager_Init(globalCtx);
View_Init(&globalCtx->view, gfxCtx); View_Init(&globalCtx->view, gfxCtx);
func_800F6828(0); Audio_SetExtraFilter(0);
Quake_Init(); Quake_Init();
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
@ -402,7 +402,7 @@ void Gameplay_Init(GameState* thisx) {
if (dREG(95) != 0) { if (dREG(95) != 0) {
D_8012D1F0 = D_801614D0; D_8012D1F0 = D_801614D0;
osSyncPrintf("\nkawauso_data=[%x]", D_8012D1F0); osSyncPrintf("\nkawauso_data=[%x]", D_8012D1F0);
DmaMgr_DMARomToRam(0x03FEB000, (u32)D_8012D1F0, sizeof(D_801614D0)); DmaMgr_DmaRomToRam(0x03FEB000, (u32)D_8012D1F0, sizeof(D_801614D0));
} }
} }

View file

@ -72,7 +72,7 @@ void BgHakaShip_Destroy(Actor* thisx, GlobalContext* globalCtx) {
BgHakaShip* this = THIS; BgHakaShip* this = THIS;
DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId);
func_800F89E8(&this->bellSoundPos); Audio_StopSfxByPos(&this->bellSoundPos);
} }
void BgHakaShip_ChildUpdatePosition(BgHakaShip* this, GlobalContext* globalCtx) { void BgHakaShip_ChildUpdatePosition(BgHakaShip* this, GlobalContext* globalCtx) {

View file

@ -200,7 +200,7 @@ void BgHakaTrap_Destroy(Actor* thisx, GlobalContext* globalCtx) {
Collider_DestroyCylinder(globalCtx, &this->colliderCylinder); Collider_DestroyCylinder(globalCtx, &this->colliderCylinder);
} }
func_800F89E8(&this->unk_16C); Audio_StopSfxByPos(&this->unk_16C);
} }
void func_8087FFC0(BgHakaTrap* this, GlobalContext* globalCtx) { void func_8087FFC0(BgHakaTrap* this, GlobalContext* globalCtx) {

View file

@ -112,7 +112,7 @@ void BgHidanRock_Destroy(Actor* thisx, GlobalContext* globalCtx) {
DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); DynaPoly_DeleteBgActor(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId);
Collider_DestroyCylinder(globalCtx, &this->collider); Collider_DestroyCylinder(globalCtx, &this->collider);
func_800F89E8(&this->unk_170); Audio_StopSfxByPos(&this->unk_170);
} }
void func_8088B24C(BgHidanRock* this) { void func_8088B24C(BgHidanRock* this) {

View file

@ -335,7 +335,7 @@ void BgYdanSp_FloorWebIdle(BgYdanSp* this, GlobalContext* globalCtx) {
if (this->unk16C > 3.0f) { if (this->unk16C > 3.0f) {
Audio_PlayActorSound2(&this->dyna.actor, NA_SE_EV_WEB_VIBRATION); Audio_PlayActorSound2(&this->dyna.actor, NA_SE_EV_WEB_VIBRATION);
} else { } else {
Audio_StopSfx(NA_SE_EV_WEB_VIBRATION); Audio_StopSfxById(NA_SE_EV_WEB_VIBRATION);
} }
} }
BgYdanSp_UpdateFloorWebCollision(this); BgYdanSp_UpdateFloorWebCollision(this);

View file

@ -688,7 +688,7 @@ void BossFd2_Death(BossFd2* this, GlobalContext* globalCtx) {
if ((this->work[FD2_HOLE_COUNTER] == 1) || (this->work[FD2_HOLE_COUNTER] == 40)) { if ((this->work[FD2_HOLE_COUNTER] == 1) || (this->work[FD2_HOLE_COUNTER] == 40)) {
this->work[FD2_SCREAM_TIMER] = 20; this->work[FD2_SCREAM_TIMER] = 20;
if (this->work[FD2_HOLE_COUNTER] == 40) { if (this->work[FD2_HOLE_COUNTER] == 40) {
Audio_StopSfx(NA_SE_EN_VALVAISA_DEAD); Audio_StopSfxById(NA_SE_EN_VALVAISA_DEAD);
} }
Audio_PlayActorSound2(&this->actor, NA_SE_EN_VALVAISA_DAMAGE2); Audio_PlayActorSound2(&this->actor, NA_SE_EN_VALVAISA_DAMAGE2);

View file

@ -1022,11 +1022,11 @@ void func_808FFCFC(BossGanon2* this, GlobalContext* globalCtx) {
ABS((s16)(this->actor.yawTowardsPlayer - this->actor.shape.rot.y)) < 0x2800) { ABS((s16)(this->actor.yawTowardsPlayer - this->actor.shape.rot.y)) < 0x2800) {
this->unk_311 = false; this->unk_311 = false;
func_80900580(this, globalCtx); func_80900580(this, globalCtx);
Audio_StopSfx(NA_SE_EN_MGANON_UNARI); Audio_StopSfxById(NA_SE_EN_MGANON_UNARI);
} else if ((this->actor.bgCheckFlags & 8) && func_808FFA24(this, globalCtx)) { } else if ((this->actor.bgCheckFlags & 8) && func_808FFA24(this, globalCtx)) {
this->unk_311 = false; this->unk_311 = false;
func_80900580(this, globalCtx); func_80900580(this, globalCtx);
Audio_StopSfx(NA_SE_EN_MGANON_UNARI); Audio_StopSfxById(NA_SE_EN_MGANON_UNARI);
} }
} }
@ -1889,12 +1889,12 @@ void func_80902524(BossGanon2* this, GlobalContext* globalCtx) {
func_809000A0(this, globalCtx); func_809000A0(this, globalCtx);
Audio_PlayActorSound2(&this->actor, NA_SE_EN_FANTOM_HIT_THUNDER); Audio_PlayActorSound2(&this->actor, NA_SE_EN_FANTOM_HIT_THUNDER);
Audio_PlayActorSound2(&this->actor, NA_SE_EN_MGANON_DAMAGE); Audio_PlayActorSound2(&this->actor, NA_SE_EN_MGANON_DAMAGE);
Audio_StopSfx(NA_SE_EN_MGANON_UNARI); Audio_StopSfxById(NA_SE_EN_MGANON_UNARI);
} else if ((this->actionFunc == func_80900890) && (acHitInfo->toucher.dmgFlags & 0x9000200)) { } else if ((this->actionFunc == func_80900890) && (acHitInfo->toucher.dmgFlags & 0x9000200)) {
this->unk_316 = 60; this->unk_316 = 60;
this->unk_342 = 5; this->unk_342 = 5;
Audio_PlayActorSound2(&this->actor, NA_SE_EN_MGANON_DAMAGE); Audio_PlayActorSound2(&this->actor, NA_SE_EN_MGANON_DAMAGE);
Audio_StopSfx(NA_SE_EN_MGANON_UNARI); Audio_StopSfxById(NA_SE_EN_MGANON_UNARI);
this->actor.colChkInfo.health -= 2; this->actor.colChkInfo.health -= 2;
temp_v0_4 = this->actor.colChkInfo.health; temp_v0_4 = this->actor.colChkInfo.health;
if (temp_v0_4 < 0x15 && this->unk_334 == 0) { if (temp_v0_4 < 0x15 && this->unk_334 == 0) {
@ -1920,7 +1920,7 @@ void func_80902524(BossGanon2* this, GlobalContext* globalCtx) {
this->unk_344 = 0x32; this->unk_344 = 0x32;
this->unk_342 = 5; this->unk_342 = 5;
Audio_PlayActorSound2(&this->actor, NA_SE_EN_MGANON_DAMAGE); Audio_PlayActorSound2(&this->actor, NA_SE_EN_MGANON_DAMAGE);
Audio_StopSfx(NA_SE_EN_MGANON_UNARI); Audio_StopSfxById(NA_SE_EN_MGANON_UNARI);
phi_v1_2 = 1; phi_v1_2 = 1;
if (acHitInfo->toucher.dmgFlags & 0x9000200) { if (acHitInfo->toucher.dmgFlags & 0x9000200) {
if (acHitInfo->toucher.dmgFlags & 0x8000000) { if (acHitInfo->toucher.dmgFlags & 0x8000000) {

View file

@ -1837,7 +1837,7 @@ void BossGoma_UpdateHit(BossGoma* this, GlobalContext* globalCtx) {
} else if (this->actionFunc != BossGoma_FloorStunned && this->patienceTimer != 0 && } else if (this->actionFunc != BossGoma_FloorStunned && this->patienceTimer != 0 &&
(acHitInfo->toucher.dmgFlags & 0x00000005)) { (acHitInfo->toucher.dmgFlags & 0x00000005)) {
Audio_PlayActorSound2(&this->actor, NA_SE_EN_GOMA_DAM2); Audio_PlayActorSound2(&this->actor, NA_SE_EN_GOMA_DAM2);
Audio_StopSfx(NA_SE_EN_GOMA_CRY1); Audio_StopSfxById(NA_SE_EN_GOMA_CRY1);
this->invincibilityFrames = 10; this->invincibilityFrames = 10;
BossGoma_SetupFloorStunned(this); BossGoma_SetupFloorStunned(this);
this->sfxFaintTimer = 100; this->sfxFaintTimer = 100;

View file

@ -2262,7 +2262,7 @@ void BossMo_UpdateTent(Actor* thisx, GlobalContext* globalCtx) {
this->actor.draw = NULL; this->actor.draw = NULL;
if (this->tent2KillTimer > 20) { if (this->tent2KillTimer > 20) {
Actor_Kill(&this->actor); Actor_Kill(&this->actor);
func_800F89E8(&this->tentTipPos); Audio_StopSfxByPos(&this->tentTipPos);
sMorphaTent2 = NULL; sMorphaTent2 = NULL;
} }
return; return;

View file

@ -342,7 +342,7 @@ void BossSst_Destroy(Actor* thisx, GlobalContext* globalCtx) {
Collider_DestroyJntSph(globalCtx, &this->colliderJntSph); Collider_DestroyJntSph(globalCtx, &this->colliderJntSph);
Collider_DestroyCylinder(globalCtx, &this->colliderCyl); Collider_DestroyCylinder(globalCtx, &this->colliderCyl);
func_800F89E8(&this->center); Audio_StopSfxByPos(&this->center);
} }
void BossSst_HeadSetupLurk(BossSst* this) { void BossSst_HeadSetupLurk(BossSst* this) {

View file

@ -338,7 +338,7 @@ void EnDivingGame_SetupRupeeThrow(EnDivingGame* this, GlobalContext* globalCtx)
void EnDivingGame_RupeeThrow(EnDivingGame* this, GlobalContext* globalCtx) { void EnDivingGame_RupeeThrow(EnDivingGame* this, GlobalContext* globalCtx) {
SkelAnime_Update(&this->skelAnime); SkelAnime_Update(&this->skelAnime);
if (func_800C0DB4(globalCtx, &this->actor.projectedPos)) { if (func_800C0DB4(globalCtx, &this->actor.projectedPos)) {
func_800F6828(0); Audio_SetExtraFilter(0);
} }
if (this->subCamId != 0) { if (this->subCamId != 0) {
Math_ApproachF(&this->camEye.x, this->unk_2D0.x, this->unk_2DC.x, this->unk_2E8.x * this->unk_318); Math_ApproachF(&this->camEye.x, this->unk_2D0.x, this->unk_2DC.x, this->unk_2E8.x * this->unk_318);

View file

@ -244,7 +244,7 @@ void EnDntNomal_TargetWait(EnDntNomal* this, GlobalContext* globalCtx) {
scorePos.y = this->actor.world.pos.y + 20.0f; scorePos.y = this->actor.world.pos.y + 20.0f;
scorePos.z = this->actor.world.pos.z; scorePos.z = this->actor.world.pos.z;
EffectSsExtra_Spawn(globalCtx, &scorePos, &scoreVel, &scoreAccel, 4, 2); EffectSsExtra_Spawn(globalCtx, &scorePos, &scoreVel, &scoreAccel, 4, 2);
Audio_StopSfx(NA_SE_SY_TRE_BOX_APPEAR); Audio_StopSfxById(NA_SE_SY_TRE_BOX_APPEAR);
func_80078884(NA_SE_SY_TRE_BOX_APPEAR); func_80078884(NA_SE_SY_TRE_BOX_APPEAR);
// "Big hit" // "Big hit"
osSyncPrintf(VT_FGCOL(CYAN) "☆☆☆☆☆ 大当り ☆☆☆☆☆ %d\n" VT_RST, this->hitCounter); osSyncPrintf(VT_FGCOL(CYAN) "☆☆☆☆☆ 大当り ☆☆☆☆☆ %d\n" VT_RST, this->hitCounter);

View file

@ -838,7 +838,7 @@ void EnGeldB_SetupSlash(EnGeldB* this) {
this->action = GELDB_SLASH; this->action = GELDB_SLASH;
this->spinAttackState = 0; this->spinAttackState = 0;
this->actor.speedXZ = 0.0f; this->actor.speedXZ = 0.0f;
func_800F8A44(&this->actor.projectedPos, NA_SE_EN_GERUDOFT_BREATH); Audio_StopSfxByPosAndId(&this->actor.projectedPos, NA_SE_EN_GERUDOFT_BREATH);
EnGeldB_SetupAction(this, EnGeldB_Slash); EnGeldB_SetupAction(this, EnGeldB_Slash);
} }
@ -1363,7 +1363,7 @@ void EnGeldB_CollisionCheck(EnGeldB* this, GlobalContext* globalCtx) {
if (this->actor.colChkInfo.damageEffect != GELDB_DMG_UNK_6) { if (this->actor.colChkInfo.damageEffect != GELDB_DMG_UNK_6) {
this->damageEffect = this->actor.colChkInfo.damageEffect; this->damageEffect = this->actor.colChkInfo.damageEffect;
Actor_SetDropFlag(&this->actor, &this->bodyCollider.info, 1); Actor_SetDropFlag(&this->actor, &this->bodyCollider.info, 1);
func_800F8A44(&this->actor.projectedPos, NA_SE_EN_GERUDOFT_BREATH); Audio_StopSfxByPosAndId(&this->actor.projectedPos, NA_SE_EN_GERUDOFT_BREATH);
if ((this->actor.colChkInfo.damageEffect == GELDB_DMG_STUN) || if ((this->actor.colChkInfo.damageEffect == GELDB_DMG_STUN) ||
(this->actor.colChkInfo.damageEffect == GELDB_DMG_FREEZE)) { (this->actor.colChkInfo.damageEffect == GELDB_DMG_FREEZE)) {
if (this->action != GELDB_STUNNED) { if (this->action != GELDB_STUNNED) {

View file

@ -506,12 +506,12 @@ s16 EnGo2_GetStateGoronCityLink(GlobalContext* globalCtx, EnGo2* this) {
if (globalCtx->msgCtx.choiceIndex == 0) { if (globalCtx->msgCtx.choiceIndex == 0) {
this->actor.textId = gSaveContext.infTable[16] & 0x800 ? 0x3033 : 0x3035; this->actor.textId = gSaveContext.infTable[16] & 0x800 ? 0x3033 : 0x3035;
if (this->actor.textId == 0x3035) { if (this->actor.textId == 0x3035) {
Audio_StopSfx(0x39EB); Audio_StopSfxById(NA_SE_EN_GOLON_CRY);
} }
} else { } else {
this->actor.textId = gSaveContext.infTable[16] & 0x800 ? 0x3036 : 0x3033; this->actor.textId = gSaveContext.infTable[16] & 0x800 ? 0x3036 : 0x3033;
if (this->actor.textId == 0x3036) { if (this->actor.textId == 0x3036) {
Audio_StopSfx(0x39EB); Audio_StopSfxById(NA_SE_EN_GOLON_CRY);
} }
} }
func_8010B720(globalCtx, this->actor.textId); func_8010B720(globalCtx, this->actor.textId);

View file

@ -899,7 +899,7 @@ void EnHorse_Destroy(Actor* thisx, GlobalContext* globalCtx) {
EnHorse* this = THIS; EnHorse* this = THIS;
if (this->stateFlags & ENHORSE_DRAW) { if (this->stateFlags & ENHORSE_DRAW) {
func_800F89E8(&this->unk_21C); Audio_StopSfxByPos(&this->unk_21C);
} }
func_800A6888(globalCtx, &this->skin); func_800A6888(globalCtx, &this->skin);
Collider_DestroyCylinder(globalCtx, &this->cyl1); Collider_DestroyCylinder(globalCtx, &this->cyl1);

View file

@ -699,7 +699,7 @@ void EnPoField_SoulInteract(EnPoField* this, GlobalContext* globalCtx) {
} }
if (func_8010BDBC(&globalCtx->msgCtx) == 4) { if (func_8010BDBC(&globalCtx->msgCtx) == 4) {
if (func_80106BC8(globalCtx) != 0) { if (func_80106BC8(globalCtx) != 0) {
func_800F8A44(&this->actor.projectedPos, NA_SE_EN_PO_BIG_CRY - SFX_FLAG); Audio_StopSfxByPosAndId(&this->actor.projectedPos, NA_SE_EN_PO_BIG_CRY - SFX_FLAG);
if (globalCtx->msgCtx.choiceIndex == 0) { if (globalCtx->msgCtx.choiceIndex == 0) {
if (Inventory_HasEmptyBottle()) { if (Inventory_HasEmptyBottle()) {
Audio_PlayActorSound2(&this->actor, NA_SE_EN_PO_BIG_GET); Audio_PlayActorSound2(&this->actor, NA_SE_EN_PO_BIG_GET);

View file

@ -443,7 +443,7 @@ void EnPoh_Talk(EnPoh* this, GlobalContext* globalCtx) {
void func_80ADE950(EnPoh* this, s32 arg1) { void func_80ADE950(EnPoh* this, s32 arg1) {
if (arg1) { if (arg1) {
func_800F8A44(&this->actor.projectedPos, NA_SE_EN_PO_BIG_CRY - SFX_FLAG); Audio_StopSfxByPosAndId(&this->actor.projectedPos, NA_SE_EN_PO_BIG_CRY - SFX_FLAG);
Audio_PlayActorSound2(&this->actor, NA_SE_EN_PO_LAUGH); Audio_PlayActorSound2(&this->actor, NA_SE_EN_PO_LAUGH);
} }
this->actionFunc = func_80AE009C; this->actionFunc = func_80AE009C;
@ -816,7 +816,7 @@ void EnPoh_TalkRegular(EnPoh* this, GlobalContext* globalCtx) {
} }
if (func_8010BDBC(&globalCtx->msgCtx) == 4) { if (func_8010BDBC(&globalCtx->msgCtx) == 4) {
if (func_80106BC8(globalCtx) != 0) { if (func_80106BC8(globalCtx) != 0) {
func_800F8A44(&this->actor.projectedPos, NA_SE_EN_PO_BIG_CRY - SFX_FLAG); Audio_StopSfxByPosAndId(&this->actor.projectedPos, NA_SE_EN_PO_BIG_CRY - SFX_FLAG);
if (globalCtx->msgCtx.choiceIndex == 0) { if (globalCtx->msgCtx.choiceIndex == 0) {
if (Inventory_HasEmptyBottle()) { if (Inventory_HasEmptyBottle()) {
this->actor.textId = 0x5008; this->actor.textId = 0x5008;

View file

@ -894,7 +894,7 @@ void func_80860F84(EnTest* this, GlobalContext* globalCtx) {
void EnTest_SetupSlashDown(EnTest* this) { void EnTest_SetupSlashDown(EnTest* this) {
Animation_PlayOnce(&this->skelAnime, &gStalfosDownSlashAnim); Animation_PlayOnce(&this->skelAnime, &gStalfosDownSlashAnim);
func_800F8A44(&this->actor.projectedPos, NA_SE_EN_STAL_WARAU); Audio_StopSfxByPosAndId(&this->actor.projectedPos, NA_SE_EN_STAL_WARAU);
this->swordCollider.base.atFlags &= ~AT_BOUNCED; this->swordCollider.base.atFlags &= ~AT_BOUNCED;
this->unk_7C8 = 0x10; this->unk_7C8 = 0x10;
this->actor.speedXZ = 0.0f; this->actor.speedXZ = 0.0f;
@ -1076,7 +1076,7 @@ void EnTest_JumpBack(EnTest* this, GlobalContext* globalCtx) {
void EnTest_SetupJumpslash(EnTest* this) { void EnTest_SetupJumpslash(EnTest* this) {
Animation_PlayOnce(&this->skelAnime, &gStalfosJumpAnim); Animation_PlayOnce(&this->skelAnime, &gStalfosJumpAnim);
func_800F8A44(&this->actor.projectedPos, NA_SE_EN_STAL_WARAU); Audio_StopSfxByPosAndId(&this->actor.projectedPos, NA_SE_EN_STAL_WARAU);
this->timer = 0; this->timer = 0;
this->unk_7C8 = 0x17; this->unk_7C8 = 0x17;
this->actor.velocity.y = 10.0f; this->actor.velocity.y = 10.0f;
@ -1669,7 +1669,7 @@ void EnTest_UpdateDamage(EnTest* this, GlobalContext* globalCtx) {
this->unk_7DC = player->unk_845; this->unk_7DC = player->unk_845;
this->actor.world.rot.y = this->actor.yawTowardsPlayer; this->actor.world.rot.y = this->actor.yawTowardsPlayer;
Actor_SetDropFlag(&this->actor, &this->bodyCollider.info, false); Actor_SetDropFlag(&this->actor, &this->bodyCollider.info, false);
func_800F8A44(&this->actor.projectedPos, NA_SE_EN_STAL_WARAU); Audio_StopSfxByPosAndId(&this->actor.projectedPos, NA_SE_EN_STAL_WARAU);
if ((this->actor.colChkInfo.damageEffect == STALFOS_DMGEFF_STUN) || if ((this->actor.colChkInfo.damageEffect == STALFOS_DMGEFF_STUN) ||
(this->actor.colChkInfo.damageEffect == STALFOS_DMGEFF_FREEZE) || (this->actor.colChkInfo.damageEffect == STALFOS_DMGEFF_FREEZE) ||

View file

@ -404,7 +404,7 @@ void EnViewer_UpdateImpl(EnViewer* this, GlobalContext* globalCtx) {
break; break;
} }
} else { } else {
func_800F67A0(0); Audio_SetBaseFilter(0);
switch (this->state) { switch (this->state) {
case 0: case 0:
Animation_PlayLoopSetSpeed(&this->skin.skelAnime, &object_opening_demo1_Anim_00504C, 1.0f); Animation_PlayLoopSetSpeed(&this->skin.skelAnime, &object_opening_demo1_Anim_00504C, 1.0f);

View file

@ -307,7 +307,7 @@ void EnWallmas_WaitToDrop(EnWallmas* this, GlobalContext* globalCtx) {
if ((player->stateFlags1 & 0x100000) || (player->stateFlags1 & 0x8000000) || !(player->actor.bgCheckFlags & 1) || if ((player->stateFlags1 & 0x100000) || (player->stateFlags1 & 0x8000000) || !(player->actor.bgCheckFlags & 1) ||
((this->actor.params == 1) && (320.0f < Math_Vec3f_DistXZ(&this->actor.home.pos, playerPos)))) { ((this->actor.params == 1) && (320.0f < Math_Vec3f_DistXZ(&this->actor.home.pos, playerPos)))) {
Audio_StopSfx(NA_SE_EN_FALL_AIM); Audio_StopSfxById(NA_SE_EN_FALL_AIM);
this->timer = 0x82; this->timer = 0x82;
} }

View file

@ -177,7 +177,7 @@ void func_80B42F74(EnYabusameMark* this, GlobalContext* globalCtx) {
func_800F5C64(NA_BGM_ITEM_GET | 0x900); func_800F5C64(NA_BGM_ITEM_GET | 0x900);
} }
if (scoreIndex == 1) { if (scoreIndex == 1) {
Audio_StopSfx(NA_SE_SY_TRE_BOX_APPEAR); Audio_StopSfxById(NA_SE_SY_TRE_BOX_APPEAR);
func_80078884(NA_SE_SY_TRE_BOX_APPEAR); func_80078884(NA_SE_SY_TRE_BOX_APPEAR);
} }
if (scoreIndex == 0) { if (scoreIndex == 0) {

View file

@ -1292,7 +1292,7 @@ void func_808326F0(Player* this) {
s32 i; s32 i;
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
Audio_StopSfx((u16)(*entry + this->ageProperties->unk_92)); Audio_StopSfxById((u16)(*entry + this->ageProperties->unk_92));
entry++; entry++;
} }
} }
@ -5540,10 +5540,10 @@ void func_8083D36C(GlobalContext* globalCtx, Player* this) {
void func_8083D53C(GlobalContext* globalCtx, Player* this) { void func_8083D53C(GlobalContext* globalCtx, Player* this) {
if (this->actor.yDistToWater < this->ageProperties->unk_2C) { if (this->actor.yDistToWater < this->ageProperties->unk_2C) {
func_800F67A0(0); Audio_SetBaseFilter(0);
this->unk_840 = 0; this->unk_840 = 0;
} else { } else {
func_800F67A0(32); Audio_SetBaseFilter(0x20);
if (this->unk_840 < 300) { if (this->unk_840 < 300) {
this->unk_840++; this->unk_840++;
} }