diff --git a/include/functions.h b/include/functions.h index 4b116af1f1..bfcb5f5624 100644 --- a/include/functions.h +++ b/include/functions.h @@ -3037,8 +3037,8 @@ void* AudioHeap_AllocAttemptExternal(AudioAllocPool* pool, size_t size); void* AudioHeap_AllocDmaMemory(AudioAllocPool* pool, size_t size); void* AudioHeap_AllocZeroed(AudioAllocPool* pool, size_t size); void* AudioHeap_Alloc(AudioAllocPool* pool, size_t size); -void AudioHeap_AllocPoolInit(AudioAllocPool* pool, void* addr, size_t size); -void AudioHeap_PopCache(s32 tableType); +void AudioHeap_InitPool(AudioAllocPool* pool, void* addr, size_t size); +void AudioHeap_PopPersistentCache(s32 tableType); void AudioHeap_InitMainPool(size_t initPoolSize); void* AudioHeap_AllocCached(s32 tableType, size_t size, s32 cache, s32 id); void* AudioHeap_SearchCaches(s32 tableType, s32 cache, s32 id); @@ -3123,10 +3123,10 @@ s32 osAiSetNextBuffer(void* buf, u32 size); void AudioPlayback_NoteDisable(Note* note); void AudioPlayback_ProcessNotes(void); -SoundFontSound* AudioPlayback_InstrumentGetSound(Instrument* instrument, s32 semitone); +TunedSample* AudioPlayback_GetInstrumentTunedSample(Instrument* instrument, s32 semitone); Instrument* AudioPlayback_GetInstrumentInner(s32 fontId, s32 instId); Drum* AudioPlayback_GetDrum(s32 fontId, s32 drumId); -SoundFontSound* AudioPlayback_GetSfx(s32 fontId, s32 sfxId); +SoundEffect* AudioPlayback_GetSoundEffect(s32 fontId, s32 sfxId); s32 AudioPlayback_SetFontInstrument(s32 instrumentType, s32 fontId, s32 index, void* value); void AudioPlayback_SeqLayerNoteDecay(SequenceLayer* layer); void AudioPlayback_SeqLayerNoteRelease(SequenceLayer* layer); diff --git a/include/variables.h b/include/variables.h index 36ad5440ae..54248860f1 100644 --- a/include/variables.h +++ b/include/variables.h @@ -2968,7 +2968,7 @@ extern f64 D_801E0EB0; // extern UNK_TYPE4 D_801E1068; extern UNK_PTR D_801E10B0; extern const s16 gAudioTatumInit[]; -extern const AudioContextInitSizes gAudioContextInitSizes; +extern const AudioHeapInitSizes gAudioHeapInitSizes; // extern UNK_TYPE4 D_801E1108; // extern UNK_TYPE4 D_801E110C; extern u8 gSoundFontTable[]; @@ -3489,7 +3489,7 @@ extern ActiveSfx gActiveSfx[7][3]; extern AudioContext gAudioContext; // at 0x80200C70 extern void (*D_80208E68)(void); extern u32 (*D_80208E6C)(s8 value, SequenceChannel* channel); -extern s32 (*D_80208E70)(SoundFontSample*, s32, s8, s32); +extern s32 (*D_80208E70)(Sample*, s32, s8, s32); extern Acmd* (*D_80208E74)(Acmd*, s32, s32); // post-code buffers diff --git a/include/z64audio.h b/include/z64audio.h index 4095251ca6..fc9bf9f4c9 100644 --- a/include/z64audio.h +++ b/include/z64audio.h @@ -10,6 +10,12 @@ #define IS_SEQUENCE_CHANNEL_VALID(ptr) ((uintptr_t)(ptr) != (uintptr_t)&gAudioContext.sequenceChannelNone) #define SEQ_NUM_CHANNELS 16 +typedef enum { + /* 0 */ SEQPLAYER_STATE_0, + /* 1 */ SEQPLAYER_STATE_1, // Fading in + /* 2 */ SEQPLAYER_STATE_2 // Fading out +} SeqPlayerState; + #define MAX_CHANNELS_PER_BANK 3 #define MUTE_FLAGS_3 (1 << 3) // prevent further noteSubEus from playing @@ -27,6 +33,21 @@ #define AIBUF_LEN 0x580 +// Must be the same amount of samples as copied by aDuplicate() (audio microcode) +#define WAVE_SAMPLE_COUNT 64 + +#define AUDIO_RELOCATED_ADDRESS_START K0BASE + +typedef enum { + /* 0x1 */ AUDIO_ERROR_NO_INST = 1, + /* 0x3 */ AUDIO_ERROR_INVALID_INST_ID = 3, + /* 0x4 */ AUDIO_ERROR_INVALID_DRUM_SFX_ID, + /* 0x5 */ AUDIO_ERROR_NO_DRUM_SFX, + /* 0x10 */ AUDIO_ERROR_FONT_NOT_LOADED = 0x10 +} AudioError; + +#define AUDIO_ERROR(fontId, id, err) (((fontId << 8) + id) + (err << 24)) + typedef enum { /* 0 */ SOUNDMODE_STEREO, /* 1 */ SOUNDMODE_HEADSET, @@ -157,20 +178,20 @@ typedef struct { typedef struct { /* 0x00 */ u32 unk_0 : 1; - /* 0x00 */ u32 codec : 3; - /* 0x00 */ u32 medium : 2; - /* 0x00 */ u32 unk_bit26 : 1; - /* 0x00 */ u32 unk_bit25 : 1; - /* 0x01 */ u32 size : 24; - /* 0x04 */ u8* sampleAddr; - /* 0x08 */ AdpcmLoop* loop; - /* 0x0C */ AdpcmBook* book; -} SoundFontSample; // size = 0x10 + /* 0x00 */ u32 codec : 3; // The state of compression or decompression + /* 0x00 */ u32 medium : 2; // Medium where sample is currently stored + /* 0x00 */ u32 unk_bit26 : 1; // Has the sample header been relocated (offsets to pointers) + /* 0x00 */ u32 isRelocated : 1; // Size of the sample + /* 0x01 */ u32 size : 24; // Size of the sample + /* 0x04 */ u8* sampleAddr; // Raw sample data. Offset from the start of the sample bank or absolute address to either rom or ram + /* 0x08 */ AdpcmLoop* loop; // Adpcm loop parameters used by the sample. Offset from the start of the sound font / pointer to ram + /* 0x0C */ AdpcmBook* book; // Adpcm book parameters used by the sample. Offset from the start of the sound font / pointer to ram +} Sample; // size = 0x10 typedef struct { - /* 0x00 */ SoundFontSample* sample; + /* 0x00 */ Sample* sample; /* 0x04 */ f32 tuning; // frequency scale factor -} SoundFontSound; // size = 0x8 +} TunedSample; // size = 0x8 typedef struct { /* 0x00 */ s16 numSamplesAfterDownsampling; // never read @@ -222,29 +243,33 @@ typedef struct { /* 0x27C */ s16* unk_27C; /* 0x280 */ s16* filterLeftState; /* 0x284 */ s16* filterRightState; - /* 0x288 */ SoundFontSound sound; - /* 0x290 */ SoundFontSample sample; + /* 0x288 */ TunedSample tunedSample; + /* 0x290 */ Sample sample; /* 0x2A0 */ AdpcmLoop loop; } SynthesisReverb; // size = 0x2D0 typedef struct { - /* 0x00 */ u8 loaded; + /* 0x00 */ u8 isRelocated; // have the envelope and all samples been relocated (offsets to pointers) /* 0x01 */ u8 normalRangeLo; /* 0x02 */ u8 normalRangeHi; /* 0x03 */ u8 adsrDecayIndex; // index used to obtain adsr decay rate from adsrDecayTable /* 0x04 */ EnvelopePoint* envelope; - /* 0x08 */ SoundFontSound lowNotesSound; - /* 0x10 */ SoundFontSound normalNotesSound; - /* 0x18 */ SoundFontSound highNotesSound; + /* 0x08 */ TunedSample lowPitchTunedSample; + /* 0x10 */ TunedSample normalPitchTunedSample; + /* 0x18 */ TunedSample highPitchTunedSample; } Instrument; // size = 0x20 typedef struct { /* 0x00 */ u8 adsrDecayIndex; // index used to obtain adsr decay rate from adsrDecayTable /* 0x01 */ u8 pan; - /* 0x02 */ u8 loaded; - /* 0x04 */ SoundFontSound sound; - /* 0x14 */ EnvelopePoint* envelope; -} Drum; // size = 0x18 + /* 0x02 */ u8 isRelocated; // have tunedSample.sample and envelope been relocated (offsets to pointers) + /* 0x04 */ TunedSample tunedSample; + /* 0x0C */ EnvelopePoint* envelope; +} Drum; // size = 0x10 + +typedef struct { + /* 0x00 */ TunedSample tunedSample; +} SoundEffect; // size = 0x08 typedef struct { /* 0x00 */ u8 numInstruments; @@ -254,7 +279,7 @@ typedef struct { /* 0x04 */ u16 numSfx; /* 0x08 */ Instrument** instruments; /* 0x0C */ Drum** drums; - /* 0x10 */ SoundFontSound* soundEffects; + /* 0x10 */ SoundEffect* soundEffects; } SoundFont; // size = 0x14 typedef struct { @@ -290,10 +315,7 @@ typedef struct { /* 0x012 */ u16 fadeTimer; /* 0x014 */ u16 fadeTimerUnkEu; /* 0x016 */ u16 unk_16; - union { - /* 0x018 */ u8* seqData; - /* 0x018 */ u16* seqData16; - }; + /* 0x018 */ u8* seqData; /* 0x01C */ f32 fadeVolume; /* 0x020 */ f32 fadeVelocity; /* 0x024 */ f32 volume; @@ -437,7 +459,7 @@ typedef struct SequenceChannel { /* 0xD0 */ u8* sfxState; // SfxChannelState /* 0xD4 */ s16* filter; /* 0xD8 */ Stereo stereo; - /* 0xDC */ s32 unk_DC; + /* 0xDC */ s32 startSamplePos; /* 0xE0 */ s32 unk_E0; } SequenceChannel; // size = 0xE4 @@ -501,7 +523,7 @@ typedef struct SequenceLayer { /* 0x50 */ f32 noteVelocity; /* 0x54 */ f32 noteFreqScale; /* 0x58 */ Instrument* instrument; - /* 0x5C */ SoundFontSound* sound; + /* 0x5C */ TunedSample* tunedSample; /* 0x60 */ SequenceChannel* channel; // Not SequenceChannel? /* 0x64 */ SeqScriptState scriptState; /* 0x80 */ AudioListItem listItem; @@ -557,12 +579,18 @@ typedef struct { /* 0x1A */ u16 delay; } VibratoState; // size = 0x1C +typedef enum { + /* 0 */ PLAYBACK_STATUS_0, + /* 1 */ PLAYBACK_STATUS_1, + /* 2 */ PLAYBACK_STATUS_2 +} NotePlaybackStatus; + typedef struct { /* 0x00 */ u8 priority; /* 0x01 */ u8 waveId; - /* 0x02 */ u8 sampleCountIndex; + /* 0x02 */ u8 harmonicIndex; // the harmonic index for the synthetic wave contained in gWaveSamples (also matches the base 2 logarithm of the harmonic order) /* 0x03 */ u8 fontId; - /* 0x04 */ u8 unk_04; + /* 0x04 */ u8 status; /* 0x05 */ u8 stereoHeadsetEffects; /* 0x06 */ s16 adsrVolScaleUnused; /* 0x08 */ f32 portamentoFreqScale; @@ -575,7 +603,7 @@ typedef struct { /* 0x54 */ Portamento portamento; /* 0x60 */ VibratoState vibratoState; /* 0x7C */ char unk_7C[0x8]; - /* 0x84 */ u32 unk_84; + /* 0x84 */ u32 startSamplePos; } NotePlaybackState; // size = 0x88 typedef struct { @@ -600,16 +628,16 @@ typedef struct { /* 0x03 */ u8 headsetPanRight; /* 0x04 */ u8 headsetPanLeft; /* 0x05 */ u8 reverbVol; - /* 0x06 */ u8 unk_06; + /* 0x06 */ u8 harmonicIndexCurAndPrev; // bits 3..2 store curHarmonicIndex, bits 1..0 store prevHarmonicIndex /* 0x07 */ u8 unk_07; /* 0x08 */ u16 targetVolLeft; /* 0x0A */ u16 targetVolRight; /* 0x0C */ u16 resamplingRateFixedPoint; /* 0x0E */ u16 unk_0E; - union { - /* 0x10 */ SoundFontSound* soundFontSound; - /* 0x10 */ s16* samples; // used for synthetic waves - } sound; + union { + /* 0x10 */ TunedSample* tunedSample; + /* 0x10 */ s16* waveSampleAddr; // used for synthetic waves + }; /* 0x14 */ s16* filter; /* 0x18 */ u8 unk_18; /* 0x19 */ u8 unk_19; @@ -640,7 +668,7 @@ typedef struct { } ReverbSettings; // size = 0x18 /** - * The high-level audio specifications requested when initializing or resetting the audio heap. + * The high-level audio specifications requested when initializing or resetting the audio pool. * Most often resets during scene transitions, but will highly depend on game play. */ typedef struct { @@ -648,7 +676,8 @@ typedef struct { /* 0x04 */ u8 unk_04; /* 0x05 */ u8 numNotes; /* 0x06 */ u8 numSequencePlayers; - /* 0x07 */ u8 unk_07[0x2]; // unused, set to zero + /* 0x07 */ u8 unk_07; // unused, set to zero + /* 0x08 */ u8 unk_08; // unused, set to zero /* 0x09 */ u8 numReverbs; /* 0x0C */ ReverbSettings* reverbSettings; /* 0x10 */ u16 sampleDmaBufSize1; @@ -675,17 +704,17 @@ typedef struct { /* 0x02 */ u16 samplingFreq; // Target sampling rate in Hz /* 0x04 */ u16 aiSamplingFreq; // True sampling rate set to the audio interface (AI) for the audio digital-analog converter (DAC) /* 0x06 */ s16 samplesPerFrameTarget; - /* 0x08 */ s16 maxAiBufferLength; - /* 0x0A */ s16 minAiBufferLength; - /* 0x0C */ s16 updatesPerFrame; + /* 0x08 */ s16 maxAiBufNumSamples; + /* 0x0A */ s16 minAiBufNumSamples; + /* 0x0C */ s16 updatesPerFrame; // for each frame of the audio thread (default 60 fps), number of updates to process audio /* 0x0E */ s16 samplesPerUpdate; /* 0x10 */ s16 samplesPerUpdateMax; /* 0x12 */ s16 samplesPerUpdateMin; /* 0x14 */ s16 numSequencePlayers; /* 0x18 */ f32 resampleRate; - /* 0x1C */ f32 updatesPerFrameInv; - /* 0x20 */ f32 unkUpdatesPerFrameScaled; - /* 0x24 */ f32 unk_24; + /* 0x1C */ f32 updatesPerFrameInv; // inverse (reciprocal) of updatesPerFrame + /* 0x20 */ f32 updatesPerFrameInvScaled; // updatesPerFrameInv scaled down by a factor of 256 + /* 0x24 */ f32 updatesPerFrameScaled; // updatesPerFrame scaled down by a factor of 4 } AudioBufferParameters; // size = 0x28 /** @@ -767,7 +796,7 @@ typedef struct { typedef struct { /* 0x00 */ u32 endAndMediumKey; - /* 0x04 */ SoundFontSample* sample; + /* 0x04 */ Sample* sample; /* 0x08 */ u8* ramAddr; /* 0x0C */ u32 encodedInfo; /* 0x10 */ s32 isFree; @@ -822,7 +851,7 @@ typedef struct { /* 0x14 */ s32 status; /* 0x18 */ size_t bytesRemaining; /* 0x1C */ s8* isDone; // TODO: rename in OoT and sync up here. This is an external status while (s32 status) is an internal status - /* 0x20 */ SoundFontSample sample; + /* 0x20 */ Sample sample; /* 0x30 */ OSMesgQueue msgqueue; /* 0x48 */ OSMesg msg; /* 0x4C */ OSIoMesg ioMesg; @@ -873,7 +902,7 @@ typedef struct { /* 0x0014 */ NoteSubEu* noteSubsEu; /* 0x0018 */ SynthesisReverb synthesisReverbs[4]; /* 0x0B58 */ char unk_0B58[0x30]; - /* 0x0B88 */ SoundFontSample* usedSamples[128]; + /* 0x0B88 */ Sample* usedSamples[128]; /* 0x0D88 */ AudioPreloadReq preloadSampleStack[128]; /* 0x1788 */ s32 numUsedSamples; /* 0x178C */ s32 preloadSampleStackTop; @@ -889,7 +918,7 @@ typedef struct { /* 0x1E58 */ OSMesg externalLoadMesgBuf[0x10]; /* 0x1E98 */ OSMesgQueue preloadSampleQueue; /* 0x1EB0 */ OSMesg preloadSampleMesgBuf[0x10]; - /* 0x1EF0 */ OSMesgQueue currAudioFrameDmaQueue; + /* 0x1EF0 */ OSMesgQueue curAudioFrameDmaQueue; /* 0x1F08 */ OSMesg currAudioFrameDmaMesgBuf[0x40]; /* 0x2008 */ OSIoMesg currAudioFrameDmaIoMesgBuf[0x40]; /* 0x2608 */ OSMesgQueue syncDmaQueue; @@ -911,7 +940,7 @@ typedef struct { /* 0x285C */ char unk_285C[0x4]; /* 0x2860 */ u8* sequenceFontTable; /* 0x2864 */ u16 numSequences; - /* 0x2868 */ SoundFont* soundFonts; + /* 0x2868 */ SoundFont* soundFontList; /* 0x286C */ AudioBufferParameters audioBufferParameters; /* 0x2994 */ f32 unk_2870; /* 0x2898 */ s32 sampleDmaBufSize1; @@ -925,7 +954,7 @@ typedef struct { /* 0x28C0 */ s32 totalTaskCount; // The total number of times the top-level function on the audio thread is run since the last audio reset /* 0x28C4 */ s32 curAudioFrameDmaCount; /* 0x28C8 */ s32 rspTaskIndex; - /* 0x28CC */ s32 curAiBuffferIndex; + /* 0x28CC */ s32 curAiBufferIndex; /* 0x28AC */ Acmd* abiCmdBufs[2]; // Pointer to audio heap where the audio binary interface command lists are stored. Two lists that alternative every frame /* 0x28B4 */ Acmd* curAbiCmdBuf; /* 0x28DC */ AudioTask* curTask; @@ -933,16 +962,16 @@ typedef struct { /* 0x2980 */ f32 unk_2960; /* 0x2984*/ s32 refreshRate; /* 0x2988 */ s16* aiBuffers[3]; // Pointers to the audio buffer allocated on the initPool contained in the audio heap. Stores fully processed digital audio before transferring to the audio interface (AI) - /* 0x2994 */ s16 aiBufLengths[3]; // Number of bytes to transfer to the audio interface buffer + /* 0x2994 */ s16 aiBufNumSamples[3]; // Number of samples to transfer to the audio interface buffer /* 0x299C */ u32 audioRandom; /* 0x29A0 */ s32 audioErrorFlags; /* 0x29A4 */ volatile u32 resetTimer; /* 0x29A8 */ u32 (*unk_29A8[4])(s8 value, SequenceChannel* channel); /* 0x29B8 */ s8 unk_29B8; /* 0x29BC */ s32 unk_29BC; // sMaxAbiCmdCnt - /* 0x29C0 */ AudioAllocPool audioSessionPool; // A sub-pool to main pool, contains all sub-pools and data that changes every audio reset + /* 0x29C0 */ AudioAllocPool sessionPool; // A sub-pool to main pool, contains all sub-pools and data that changes every audio reset /* 0x29D0 */ AudioAllocPool externalPool; // pool allocated on an external device. Never used in game - /* 0x29E0 */ AudioAllocPool audioInitPool; // A sub-pool to the main pool, contains all sub-pools and data that persists every audio reset + /* 0x29E0 */ AudioAllocPool initPool; // A sub-pool to the main pool, contains all sub-pools and data that persists every audio reset /* 0x29F0 */ AudioAllocPool miscPool; // A sub-pool to the session pool, /* 0x2A00 */ char unk_29D0[0x20]; // probably two unused pools /* 0x2A20 */ AudioAllocPool cachePool; // The common pool for all cache entries @@ -978,7 +1007,7 @@ typedef struct { /* 0x7978 */ u8 cmdWritePos; /* 0x7979 */ u8 cmdReadPos; /* 0x797A */ u8 cmdQueueFinished; - /* 0x797C */ u16 activeChannelsFlags[5]; // bitwise flag for 16 channels. Only channels with bit turned on will be processed + /* 0x797C */ u16 activeChannelsFlags[5]; // bit-packed for 16 channels. Only channels with bit turned on will be processed /* 0x7988 */ OSMesgQueue* audioResetQueueP; /* 0x798C */ OSMesgQueue* taskStartQueueP; /* 0x7990 */ OSMesgQueue* cmdProcQueueP; @@ -1008,9 +1037,9 @@ typedef struct { typedef struct { /* 0x0 */ size_t heapSize; // total number of bytes allocated to the audio heap. Must be <= the size of `gAudioHeap` (ideally about the same size) - /* 0x4 */ size_t mainPoolSplitSize; // The entire audio heap is split into two pools. + /* 0x4 */ size_t initPoolSize; // The entire audio heap is split into two pools. /* 0x8 */ size_t permanentPoolSize; -} AudioContextInitSizes; // size = 0xC +} AudioHeapInitSizes; // size = 0xC typedef struct { /* 0x00 */ f32 unk_00; diff --git a/src/code/audio/audio_effects.c b/src/code/audio/audio_effects.c index ab9228bbf6..bc27a6e227 100644 --- a/src/code/audio/audio_effects.c +++ b/src/code/audio/audio_effects.c @@ -63,7 +63,7 @@ void AudioEffects_SequencePlayerProcessSound(SequencePlayer* seqPlayer) { } seqPlayer->fadeTimer--; - if (seqPlayer->fadeTimer == 0 && seqPlayer->state == 2) { + if ((seqPlayer->fadeTimer == 0) && (seqPlayer->state == SEQPLAYER_STATE_2)) { AudioSeq_SequencePlayerDisable(seqPlayer); return; } @@ -243,12 +243,10 @@ f32 AudioEffects_AdsrUpdate(AdsrState* adsr) { break; } // fallthrough - case ADSR_STATE_START_LOOP: adsr->envIndex = 0; adsr->action.s.state = ADSR_STATE_LOOP; // fallthrough - retry: case ADSR_STATE_LOOP: adsr->delay = adsr->envelope[adsr->envIndex].delay; @@ -256,18 +254,21 @@ f32 AudioEffects_AdsrUpdate(AdsrState* adsr) { case ADSR_DISABLE: adsr->action.s.state = ADSR_STATE_DISABLED; break; + case ADSR_HANG: adsr->action.s.state = ADSR_STATE_HANG; break; + case ADSR_GOTO: adsr->envIndex = adsr->envelope[adsr->envIndex].arg; goto retry; + case ADSR_RESTART: adsr->action.s.state = ADSR_STATE_INITIAL; break; default: - adsr->delay *= gAudioContext.audioBufferParameters.unk_24; + adsr->delay *= gAudioContext.audioBufferParameters.updatesPerFrameScaled; if (adsr->delay == 0) { adsr->delay = 1; } @@ -282,14 +283,13 @@ f32 AudioEffects_AdsrUpdate(AdsrState* adsr) { break; } // fallthrough - case ADSR_STATE_FADE: adsr->current += adsr->velocity; - if (--adsr->delay <= 0) { + adsr->delay--; + if (adsr->delay <= 0) { adsr->action.s.state = ADSR_STATE_LOOP; } // fallthrough - case ADSR_STATE_HANG: break; diff --git a/src/code/audio/audio_heap.c b/src/code/audio/audio_heap.c index 7d3ea8ba66..667cd1c400 100644 --- a/src/code/audio/audio_heap.c +++ b/src/code/audio/audio_heap.c @@ -4,7 +4,7 @@ void* AudioHeap_SearchRegularCaches(s32 tableType, s32 cache, s32 id); void AudioHeap_InitSampleCaches(size_t persistentSampleCacheSize, size_t temporarySampleCacheSize); SampleCacheEntry* AudioHeap_AllocTemporarySampleCacheEntry(size_t size); void AudioHeap_DiscardSampleCacheEntry(SampleCacheEntry* entry); -void AudioHeap_UnapplySampleCache(SampleCacheEntry* entry, SoundFontSample* sample); +void AudioHeap_UnapplySampleCache(SampleCacheEntry* entry, Sample* sample); SampleCacheEntry* AudioHeap_AllocPersistentSampleCacheEntry(size_t size); void AudioHeap_DiscardSampleCaches(void); void AudioHeap_DiscardSampleBank(s32 sampleBankId); @@ -14,29 +14,37 @@ void AudioHeap_InitReverb(s32 reverbIndex, ReverbSettings* settings, s32 flags); #define gTatumsPerBeat (gAudioTatumInit[1]) -f32 func_8018B0F0(f32 arg0) { - return 256.0f * gAudioContext.audioBufferParameters.unkUpdatesPerFrameScaled / arg0; +/** + * Effectively scales `updatesPerFrameInv` by the reciprocal of `scaleInv` + * `updatesPerFrameInvScaled` is just `updatesPerFrameInv` scaled down by a factor of 256.0f + * i.e. (256.0f * `updatesPerFrameInvScaled`) is just `updatesPerFrameInv` + */ +f32 AudioHeap_CalculateAdsrDecay(f32 scaleInv) { + return 256.0f * gAudioContext.audioBufferParameters.updatesPerFrameInvScaled / scaleInv; } -void func_8018B10C(void) { +/** + * Initialize the decay rate table used for decaying notes as part of adsr + */ +void AudioHeap_InitAdsrDecayTable(void) { s32 i; - gAudioContext.adsrDecayTable[255] = func_8018B0F0(0.25f); - gAudioContext.adsrDecayTable[254] = func_8018B0F0(0.33f); - gAudioContext.adsrDecayTable[253] = func_8018B0F0(0.5f); - gAudioContext.adsrDecayTable[252] = func_8018B0F0(0.66f); - gAudioContext.adsrDecayTable[251] = func_8018B0F0(0.75f); + gAudioContext.adsrDecayTable[255] = AudioHeap_CalculateAdsrDecay(0.25f); + gAudioContext.adsrDecayTable[254] = AudioHeap_CalculateAdsrDecay(0.33f); + gAudioContext.adsrDecayTable[253] = AudioHeap_CalculateAdsrDecay(0.5f); + gAudioContext.adsrDecayTable[252] = AudioHeap_CalculateAdsrDecay(0.66f); + gAudioContext.adsrDecayTable[251] = AudioHeap_CalculateAdsrDecay(0.75f); for (i = 128; i < 251; i++) { - gAudioContext.adsrDecayTable[i] = func_8018B0F0(251 - i); + gAudioContext.adsrDecayTable[i] = AudioHeap_CalculateAdsrDecay(251 - i); } for (i = 16; i < 128; i++) { - gAudioContext.adsrDecayTable[i] = func_8018B0F0(4 * (143 - i)); + gAudioContext.adsrDecayTable[i] = AudioHeap_CalculateAdsrDecay(4 * (143 - i)); } for (i = 1; i < 16; i++) { - gAudioContext.adsrDecayTable[i] = func_8018B0F0(60 * (23 - i)); + gAudioContext.adsrDecayTable[i] = AudioHeap_CalculateAdsrDecay(60 * (23 - i)); } gAudioContext.adsrDecayTable[0] = 0.0f; @@ -71,7 +79,7 @@ void AudioHeap_DiscardFont(s32 fontId) { Note* note = &gAudioContext.notes[i]; if (note->playbackState.fontId == fontId) { - if ((note->playbackState.unk_04 == 0) && (note->playbackState.priority != 0)) { + if ((note->playbackState.status == PLAYBACK_STATUS_0) && (note->playbackState.priority != 0)) { note->playbackState.parentLayer->enabled = false; note->playbackState.parentLayer->finished = true; } @@ -233,19 +241,19 @@ void* AudioHeap_Alloc(AudioAllocPool* pool, size_t size) { * Initialize a pool at the requested address with the requested size. * Store the metadata of this pool in AudioAllocPool* pool */ -void AudioHeap_AllocPoolInit(AudioAllocPool* pool, void* addr, size_t size) { +void AudioHeap_InitPool(AudioAllocPool* pool, void* addr, size_t size) { pool->curAddr = pool->startAddr = (u8*)ALIGN16((uintptr_t)addr); pool->size = size - ((uintptr_t)addr & 0xF); pool->count = 0; } -void AudioHeap_ClearPersistentCache(AudioPersistentCache* persistent) { +void AudioHeap_InitPersistentCache(AudioPersistentCache* persistent) { persistent->pool.count = 0; persistent->numEntries = 0; persistent->pool.curAddr = persistent->pool.startAddr; } -void AudioHeap_ClearTemporaryCache(AudioTemporaryCache* temporary) { +void AudioHeap_InitTemporaryCache(AudioTemporaryCache* temporary) { temporary->pool.count = 0; temporary->pool.curAddr = temporary->pool.startAddr; temporary->nextSide = 0; @@ -260,7 +268,7 @@ void AudioHeap_ResetPool(AudioAllocPool* pool) { pool->curAddr = pool->startAddr; } -void AudioHeap_PopCache(s32 tableType) { +void AudioHeap_PopPersistentCache(s32 tableType) { AudioCache* loadedCache; AudioAllocPool* persistentHeap; AudioPersistentCache* persistent; @@ -306,69 +314,65 @@ void AudioHeap_PopCache(s32 tableType) { persistent->numEntries--; } -void AudioHeap_InitMainPool(size_t mainPoolSplitSize) { - AudioHeap_AllocPoolInit(&gAudioContext.audioInitPool, gAudioContext.audioHeap, mainPoolSplitSize); - AudioHeap_AllocPoolInit(&gAudioContext.audioSessionPool, gAudioContext.audioHeap + mainPoolSplitSize, - gAudioContext.audioHeapSize - mainPoolSplitSize); +void AudioHeap_InitMainPool(size_t initPoolSize) { + AudioHeap_InitPool(&gAudioContext.initPool, gAudioContext.audioHeap, initPoolSize); + AudioHeap_InitPool(&gAudioContext.sessionPool, gAudioContext.audioHeap + initPoolSize, + gAudioContext.audioHeapSize - initPoolSize); gAudioContext.externalPool.startAddr = NULL; } void AudioHeap_InitSessionPool(AudioSessionPoolSplit* split) { - gAudioContext.audioSessionPool.curAddr = gAudioContext.audioSessionPool.startAddr; + gAudioContext.sessionPool.curAddr = gAudioContext.sessionPool.startAddr; - AudioHeap_AllocPoolInit(&gAudioContext.miscPool, - AudioHeap_Alloc(&gAudioContext.audioSessionPool, split->miscPoolSize), split->miscPoolSize); - AudioHeap_AllocPoolInit(&gAudioContext.cachePool, - AudioHeap_Alloc(&gAudioContext.audioSessionPool, split->cachePoolSize), - split->cachePoolSize); + AudioHeap_InitPool(&gAudioContext.miscPool, AudioHeap_Alloc(&gAudioContext.sessionPool, split->miscPoolSize), + split->miscPoolSize); + AudioHeap_InitPool(&gAudioContext.cachePool, AudioHeap_Alloc(&gAudioContext.sessionPool, split->cachePoolSize), + split->cachePoolSize); } void AudioHeap_InitCachePool(AudioCachePoolSplit* split) { gAudioContext.cachePool.curAddr = gAudioContext.cachePool.startAddr; - AudioHeap_AllocPoolInit(&gAudioContext.persistentCommonPool, - AudioHeap_Alloc(&gAudioContext.cachePool, split->persistentCommonPoolSize), - split->persistentCommonPoolSize); - AudioHeap_AllocPoolInit(&gAudioContext.temporaryCommonPool, - AudioHeap_Alloc(&gAudioContext.cachePool, split->temporaryCommonPoolSize), - split->temporaryCommonPoolSize); + AudioHeap_InitPool(&gAudioContext.persistentCommonPool, + AudioHeap_Alloc(&gAudioContext.cachePool, split->persistentCommonPoolSize), + split->persistentCommonPoolSize); + AudioHeap_InitPool(&gAudioContext.temporaryCommonPool, + AudioHeap_Alloc(&gAudioContext.cachePool, split->temporaryCommonPoolSize), + split->temporaryCommonPoolSize); } -void AudioHeap_InitPersistentCache(AudioCommonPoolSplit* split) { +void AudioHeap_InitPersistentPoolsAndCaches(AudioCommonPoolSplit* split) { gAudioContext.persistentCommonPool.curAddr = gAudioContext.persistentCommonPool.startAddr; - AudioHeap_AllocPoolInit(&gAudioContext.seqCache.persistent.pool, - AudioHeap_Alloc(&gAudioContext.persistentCommonPool, split->seqCacheSize), - split->seqCacheSize); - AudioHeap_AllocPoolInit(&gAudioContext.fontCache.persistent.pool, - AudioHeap_Alloc(&gAudioContext.persistentCommonPool, split->fontCacheSize), - split->fontCacheSize); - AudioHeap_AllocPoolInit(&gAudioContext.sampleBankCache.persistent.pool, - AudioHeap_Alloc(&gAudioContext.persistentCommonPool, split->sampleBankCacheSize), - split->sampleBankCacheSize); + AudioHeap_InitPool(&gAudioContext.seqCache.persistent.pool, + AudioHeap_Alloc(&gAudioContext.persistentCommonPool, split->seqCacheSize), split->seqCacheSize); + AudioHeap_InitPool(&gAudioContext.fontCache.persistent.pool, + AudioHeap_Alloc(&gAudioContext.persistentCommonPool, split->fontCacheSize), + split->fontCacheSize); + AudioHeap_InitPool(&gAudioContext.sampleBankCache.persistent.pool, + AudioHeap_Alloc(&gAudioContext.persistentCommonPool, split->sampleBankCacheSize), + split->sampleBankCacheSize); - AudioHeap_ClearPersistentCache(&gAudioContext.seqCache.persistent); - AudioHeap_ClearPersistentCache(&gAudioContext.fontCache.persistent); - AudioHeap_ClearPersistentCache(&gAudioContext.sampleBankCache.persistent); + AudioHeap_InitPersistentCache(&gAudioContext.seqCache.persistent); + AudioHeap_InitPersistentCache(&gAudioContext.fontCache.persistent); + AudioHeap_InitPersistentCache(&gAudioContext.sampleBankCache.persistent); } -void AudioHeap_InitTemporaryCache(AudioCommonPoolSplit* split) { +void AudioHeap_InitTemporaryPoolsAndCaches(AudioCommonPoolSplit* split) { gAudioContext.temporaryCommonPool.curAddr = gAudioContext.temporaryCommonPool.startAddr; - AudioHeap_AllocPoolInit(&gAudioContext.seqCache.temporary.pool, - AudioHeap_Alloc(&gAudioContext.temporaryCommonPool, split->seqCacheSize), - split->seqCacheSize); - AudioHeap_AllocPoolInit(&gAudioContext.fontCache.temporary.pool, - AudioHeap_Alloc(&gAudioContext.temporaryCommonPool, split->fontCacheSize), - split->fontCacheSize); - AudioHeap_AllocPoolInit(&gAudioContext.sampleBankCache.temporary.pool, - AudioHeap_Alloc(&gAudioContext.temporaryCommonPool, split->sampleBankCacheSize), - split->sampleBankCacheSize); + AudioHeap_InitPool(&gAudioContext.seqCache.temporary.pool, + AudioHeap_Alloc(&gAudioContext.temporaryCommonPool, split->seqCacheSize), split->seqCacheSize); + AudioHeap_InitPool(&gAudioContext.fontCache.temporary.pool, + AudioHeap_Alloc(&gAudioContext.temporaryCommonPool, split->fontCacheSize), split->fontCacheSize); + AudioHeap_InitPool(&gAudioContext.sampleBankCache.temporary.pool, + AudioHeap_Alloc(&gAudioContext.temporaryCommonPool, split->sampleBankCacheSize), + split->sampleBankCacheSize); - AudioHeap_ClearTemporaryCache(&gAudioContext.seqCache.temporary); - AudioHeap_ClearTemporaryCache(&gAudioContext.fontCache.temporary); - AudioHeap_ClearTemporaryCache(&gAudioContext.sampleBankCache.temporary); + AudioHeap_InitTemporaryCache(&gAudioContext.seqCache.temporary); + AudioHeap_InitTemporaryCache(&gAudioContext.fontCache.temporary); + AudioHeap_InitTemporaryCache(&gAudioContext.sampleBankCache.temporary); } void* AudioHeap_AllocCached(s32 tableType, size_t size, s32 cache, s32 id) { @@ -764,7 +768,7 @@ void AudioHeap_LoadFilter(s16* filter, s32 lowPassCutoff, s32 highPassCutoff) { s32 cutOff; //! @bug filter is never set if (lowPassCutoff == highPassCutoff) and does not equal 0 - if (lowPassCutoff == 0 && highPassCutoff == 0) { + if ((lowPassCutoff == 0) && (highPassCutoff == 0)) { // Identity filter AudioHeap_LoadLowPassFilter(filter, 0); } else if (highPassCutoff == 0) { @@ -830,13 +834,13 @@ void AudioHeap_UpdateReverbs(void) { * Clear the Audio Interface Buffers */ void AudioHeap_ClearAiBuffers(void) { - s32 curAiBuffferIndex = gAudioContext.curAiBuffferIndex; + s32 curAiBufferIndex = gAudioContext.curAiBufferIndex; s32 i; - gAudioContext.aiBufLengths[curAiBuffferIndex] = gAudioContext.audioBufferParameters.minAiBufferLength; + gAudioContext.aiBufNumSamples[curAiBufferIndex] = gAudioContext.audioBufferParameters.minAiBufNumSamples; for (i = 0; i < AIBUF_LEN; i++) { - gAudioContext.aiBuffers[curAiBuffferIndex][i] = 0; + gAudioContext.aiBuffers[curAiBufferIndex][i] = 0; } } @@ -902,8 +906,8 @@ s32 AudioHeap_ResetStep(void) { case 1: AudioHeap_Init(); gAudioContext.resetStatus = 0; - for (i = 0; i < ARRAY_COUNT(gAudioContext.aiBufLengths); i++) { - gAudioContext.aiBufLengths[i] = gAudioContext.audioBufferParameters.maxAiBufferLength; + for (i = 0; i < ARRAY_COUNT(gAudioContext.aiBufNumSamples); i++) { + gAudioContext.aiBufNumSamples[i] = gAudioContext.audioBufferParameters.maxAiBufNumSamples; for (j = 0; j < AIBUF_LEN; j++) { gAudioContext.aiBuffers[i][j] = 0; } @@ -940,9 +944,9 @@ void AudioHeap_Init(void) { gAudioContext.audioBufferParameters.samplesPerFrameTarget = ALIGN16(gAudioContext.audioBufferParameters.samplingFreq / gAudioContext.refreshRate); - gAudioContext.audioBufferParameters.minAiBufferLength = + gAudioContext.audioBufferParameters.minAiBufNumSamples = gAudioContext.audioBufferParameters.samplesPerFrameTarget - 0x10; - gAudioContext.audioBufferParameters.maxAiBufferLength = + gAudioContext.audioBufferParameters.maxAiBufNumSamples = gAudioContext.audioBufferParameters.samplesPerFrameTarget + 0x10; gAudioContext.audioBufferParameters.updatesPerFrame = ((gAudioContext.audioBufferParameters.samplesPerFrameTarget + 0x10) / 0xD0) + 1; @@ -952,9 +956,10 @@ void AudioHeap_Init(void) { gAudioContext.audioBufferParameters.samplesPerUpdateMax = gAudioContext.audioBufferParameters.samplesPerUpdate + 8; gAudioContext.audioBufferParameters.samplesPerUpdateMin = gAudioContext.audioBufferParameters.samplesPerUpdate - 8; gAudioContext.audioBufferParameters.resampleRate = 32000.0f / (s32)gAudioContext.audioBufferParameters.samplingFreq; - gAudioContext.audioBufferParameters.unkUpdatesPerFrameScaled = + gAudioContext.audioBufferParameters.updatesPerFrameInvScaled = (1.0f / 256.0f) / gAudioContext.audioBufferParameters.updatesPerFrame; - gAudioContext.audioBufferParameters.unk_24 = gAudioContext.audioBufferParameters.updatesPerFrame * 0.25f; + gAudioContext.audioBufferParameters.updatesPerFrameScaled = + gAudioContext.audioBufferParameters.updatesPerFrame / 4.0f; gAudioContext.audioBufferParameters.updatesPerFrameInv = 1.0f / gAudioContext.audioBufferParameters.updatesPerFrame; // sample dma size @@ -980,12 +985,12 @@ void AudioHeap_Init(void) { gAudioContext.audioBufferParameters.specUnk4 = spec->unk_04; gAudioContext.audioBufferParameters.samplesPerFrameTarget *= gAudioContext.audioBufferParameters.specUnk4; - gAudioContext.audioBufferParameters.maxAiBufferLength *= gAudioContext.audioBufferParameters.specUnk4; - gAudioContext.audioBufferParameters.minAiBufferLength *= gAudioContext.audioBufferParameters.specUnk4; + gAudioContext.audioBufferParameters.maxAiBufNumSamples *= gAudioContext.audioBufferParameters.specUnk4; + gAudioContext.audioBufferParameters.minAiBufNumSamples *= gAudioContext.audioBufferParameters.specUnk4; gAudioContext.audioBufferParameters.updatesPerFrame *= gAudioContext.audioBufferParameters.specUnk4; if (gAudioContext.audioBufferParameters.specUnk4 >= 2) { - gAudioContext.audioBufferParameters.maxAiBufferLength -= 0x10; + gAudioContext.audioBufferParameters.maxAiBufNumSamples -= 0x10; } // Determine the maximum allowable number of audio command list entries for the rsp microcode @@ -998,7 +1003,7 @@ void AudioHeap_Init(void) { temporarySize = spec->temporarySeqCacheSize + spec->temporaryFontCacheSize + spec->temporarySampleBankCacheSize + 0x10; cachePoolSize = persistentSize + temporarySize; - miscPoolSize = gAudioContext.audioSessionPool.size - cachePoolSize - 0x100; + miscPoolSize = gAudioContext.sessionPool.size - cachePoolSize - 0x100; if (gAudioContext.externalPool.startAddr != NULL) { gAudioContext.externalPool.curAddr = gAudioContext.externalPool.startAddr; @@ -1018,13 +1023,13 @@ void AudioHeap_Init(void) { gAudioContext.persistentCommonPoolSplit.seqCacheSize = spec->persistentSeqCacheSize; gAudioContext.persistentCommonPoolSplit.fontCacheSize = spec->persistentFontCacheSize; gAudioContext.persistentCommonPoolSplit.sampleBankCacheSize = spec->persistentSampleBankCacheSize; - AudioHeap_InitPersistentCache(&gAudioContext.persistentCommonPoolSplit); + AudioHeap_InitPersistentPoolsAndCaches(&gAudioContext.persistentCommonPoolSplit); // Temporary Pool Split (Split into Sequences, SoundFonts, Samples) gAudioContext.temporaryCommonPoolSplit.seqCacheSize = spec->temporarySeqCacheSize; gAudioContext.temporaryCommonPoolSplit.fontCacheSize = spec->temporaryFontCacheSize; gAudioContext.temporaryCommonPoolSplit.sampleBankCacheSize = spec->temporarySampleBankCacheSize; - AudioHeap_InitTemporaryCache(&gAudioContext.temporaryCommonPoolSplit); + AudioHeap_InitTemporaryPoolsAndCaches(&gAudioContext.temporaryCommonPoolSplit); AudioHeap_ResetLoadStatus(); @@ -1039,12 +1044,12 @@ void AudioHeap_Init(void) { // Initialize audio binary interface command list buffer for (j = 0; j < ARRAY_COUNT(gAudioContext.abiCmdBufs); j++) { gAudioContext.abiCmdBufs[j] = - AudioHeap_AllocDmaMemoryZeroed(&gAudioContext.miscPool, gAudioContext.maxAudioCmds * sizeof(u64)); + AudioHeap_AllocDmaMemoryZeroed(&gAudioContext.miscPool, gAudioContext.maxAudioCmds * sizeof(Acmd)); } - // Initialize adsrDecayTable (fadeOutVelocities for ADSR) + // Initialize the decay rate table for ADSR gAudioContext.adsrDecayTable = AudioHeap_Alloc(&gAudioContext.miscPool, 0x100 * sizeof(f32)); - func_8018B10C(); + AudioHeap_InitAdsrDecayTable(); // Initialize reverbs for (i = 0; i < ARRAY_COUNT(gAudioContext.synthesisReverbs); i++) { @@ -1139,14 +1144,14 @@ void AudioHeap_InitSampleCaches(size_t persistentSampleCacheSize, size_t tempora if (addr == NULL) { gAudioContext.persistentSampleCache.pool.size = 0; } else { - AudioHeap_AllocPoolInit(&gAudioContext.persistentSampleCache.pool, addr, persistentSampleCacheSize); + AudioHeap_InitPool(&gAudioContext.persistentSampleCache.pool, addr, persistentSampleCacheSize); } addr = AudioHeap_AllocAttemptExternal(&gAudioContext.miscPool, temporarySampleCacheSize); if (addr == NULL) { gAudioContext.temporarySampleCache.pool.size = 0; } else { - AudioHeap_AllocPoolInit(&gAudioContext.temporarySampleCache.pool, addr, temporarySampleCacheSize); + AudioHeap_InitPool(&gAudioContext.temporarySampleCache.pool, addr, temporarySampleCacheSize); } gAudioContext.persistentSampleCache.numEntries = 0; @@ -1257,35 +1262,35 @@ SampleCacheEntry* AudioHeap_AllocTemporarySampleCacheEntry(size_t size) { void AudioHeap_UnapplySampleCacheForFont(SampleCacheEntry* entry, s32 fontId) { Drum* drum; Instrument* inst; - SoundFontSound* sfx; + SoundEffect* soundEffect; s32 instId; s32 drumId; s32 sfxId; - for (instId = 0; instId < gAudioContext.soundFonts[fontId].numInstruments; instId++) { + for (instId = 0; instId < gAudioContext.soundFontList[fontId].numInstruments; instId++) { inst = AudioPlayback_GetInstrumentInner(fontId, instId); if (inst != NULL) { if (inst->normalRangeLo != 0) { - AudioHeap_UnapplySampleCache(entry, inst->lowNotesSound.sample); + AudioHeap_UnapplySampleCache(entry, inst->lowPitchTunedSample.sample); } if (inst->normalRangeHi != 0x7F) { - AudioHeap_UnapplySampleCache(entry, inst->highNotesSound.sample); + AudioHeap_UnapplySampleCache(entry, inst->highPitchTunedSample.sample); } - AudioHeap_UnapplySampleCache(entry, inst->normalNotesSound.sample); + AudioHeap_UnapplySampleCache(entry, inst->normalPitchTunedSample.sample); } } - for (drumId = 0; drumId < gAudioContext.soundFonts[fontId].numDrums; drumId++) { + for (drumId = 0; drumId < gAudioContext.soundFontList[fontId].numDrums; drumId++) { drum = AudioPlayback_GetDrum(fontId, drumId); if (drum != NULL) { - AudioHeap_UnapplySampleCache(entry, drum->sound.sample); + AudioHeap_UnapplySampleCache(entry, drum->tunedSample.sample); } } - for (sfxId = 0; sfxId < gAudioContext.soundFonts[fontId].numSfx; sfxId++) { - sfx = AudioPlayback_GetSfx(fontId, sfxId); - if (sfx != NULL) { - AudioHeap_UnapplySampleCache(entry, sfx->sample); + for (sfxId = 0; sfxId < gAudioContext.soundFontList[fontId].numSfx; sfxId++) { + soundEffect = AudioPlayback_GetSoundEffect(fontId, sfxId); + if (soundEffect != NULL) { + AudioHeap_UnapplySampleCache(entry, soundEffect->tunedSample.sample); } } } @@ -1298,8 +1303,8 @@ void AudioHeap_DiscardSampleCacheEntry(SampleCacheEntry* entry) { numFonts = gAudioContext.soundFontTable->numEntries; for (fontId = 0; fontId < numFonts; fontId++) { - sampleBankId1 = gAudioContext.soundFonts[fontId].sampleBankId1; - sampleBankId2 = gAudioContext.soundFonts[fontId].sampleBankId2; + sampleBankId1 = gAudioContext.soundFontList[fontId].sampleBankId1; + sampleBankId2 = gAudioContext.soundFontList[fontId].sampleBankId2; if (((sampleBankId1 != 0xFF) && (entry->sampleBankId == sampleBankId1)) || ((sampleBankId2 != 0xFF) && (entry->sampleBankId == sampleBankId2)) || entry->sampleBankId == 0 || entry->sampleBankId == 0xFE) { @@ -1313,7 +1318,7 @@ void AudioHeap_DiscardSampleCacheEntry(SampleCacheEntry* entry) { } } -void AudioHeap_UnapplySampleCache(SampleCacheEntry* entry, SoundFontSample* sample) { +void AudioHeap_UnapplySampleCache(SampleCacheEntry* entry, Sample* sample) { if (sample != NULL) { if (sample->sampleAddr == entry->allocatedAddr) { sample->sampleAddr = entry->sampleAddr; @@ -1362,8 +1367,8 @@ void AudioHeap_DiscardSampleCaches(void) { numFonts = gAudioContext.soundFontTable->numEntries; for (fontId = 0; fontId < numFonts; fontId++) { - sampleBankId1 = gAudioContext.soundFonts[fontId].sampleBankId1; - sampleBankId2 = gAudioContext.soundFonts[fontId].sampleBankId2; + sampleBankId1 = gAudioContext.soundFontList[fontId].sampleBankId1; + sampleBankId2 = gAudioContext.soundFontList[fontId].sampleBankId2; if ((sampleBankId1 == 0xFF) && (sampleBankId2 == 0xFF)) { continue; } @@ -1390,7 +1395,7 @@ typedef struct { u8 newMedium; } StorageChange; -void AudioHeap_ChangeStorage(StorageChange* change, SoundFontSample* sample) { +void AudioHeap_ChangeStorage(StorageChange* change, Sample* sample) { if (sample != NULL && ((sample->medium == change->newMedium) || (D_801FD120 != 1)) && ((sample->medium == MEDIUM_RAM) || (D_801FD120 != 0))) { uintptr_t startAddr = change->oldAddr; @@ -1430,7 +1435,7 @@ void AudioHeap_ApplySampleBankCacheInternal(s32 apply, s32 sampleBankId) { s32 fontId; Drum* drum; Instrument* inst; - SoundFontSound* sfx; + SoundEffect* soundEffect; uintptr_t* newAddr; s32 pad[4]; @@ -1457,8 +1462,8 @@ void AudioHeap_ApplySampleBankCacheInternal(s32 apply, s32 sampleBankId) { } for (fontId = 0; fontId < numFonts; fontId++) { - sampleBankId1 = gAudioContext.soundFonts[fontId].sampleBankId1; - sampleBankId2 = gAudioContext.soundFonts[fontId].sampleBankId2; + sampleBankId1 = gAudioContext.soundFontList[fontId].sampleBankId1; + sampleBankId2 = gAudioContext.soundFontList[fontId].sampleBankId2; if ((sampleBankId1 != 0xFF) || (sampleBankId2 != 0xFF)) { if (!AudioLoad_IsFontLoadComplete(fontId) || AudioHeap_SearchCaches(FONT_TABLE, CACHE_EITHER, fontId) == NULL) { @@ -1471,30 +1476,30 @@ void AudioHeap_ApplySampleBankCacheInternal(s32 apply, s32 sampleBankId) { continue; } - for (instId = 0; instId < gAudioContext.soundFonts[fontId].numInstruments; instId++) { + for (instId = 0; instId < gAudioContext.soundFontList[fontId].numInstruments; instId++) { inst = AudioPlayback_GetInstrumentInner(fontId, instId); if (inst != NULL) { if (inst->normalRangeLo != 0) { - AudioHeap_ChangeStorage(&change, inst->lowNotesSound.sample); + AudioHeap_ChangeStorage(&change, inst->lowPitchTunedSample.sample); } if (inst->normalRangeHi != 0x7F) { - AudioHeap_ChangeStorage(&change, inst->highNotesSound.sample); + AudioHeap_ChangeStorage(&change, inst->highPitchTunedSample.sample); } - AudioHeap_ChangeStorage(&change, inst->normalNotesSound.sample); + AudioHeap_ChangeStorage(&change, inst->normalPitchTunedSample.sample); } } - for (drumId = 0; drumId < gAudioContext.soundFonts[fontId].numDrums; drumId++) { + for (drumId = 0; drumId < gAudioContext.soundFontList[fontId].numDrums; drumId++) { drum = AudioPlayback_GetDrum(fontId, drumId); if (drum != NULL) { - AudioHeap_ChangeStorage(&change, drum->sound.sample); + AudioHeap_ChangeStorage(&change, drum->tunedSample.sample); } } - for (sfxId = 0; sfxId < gAudioContext.soundFonts[fontId].numSfx; sfxId++) { - sfx = AudioPlayback_GetSfx(fontId, sfxId); - if (sfx != NULL) { - AudioHeap_ChangeStorage(&change, sfx->sample); + for (sfxId = 0; sfxId < gAudioContext.soundFontList[fontId].numSfx; sfxId++) { + soundEffect = AudioPlayback_GetSoundEffect(fontId, sfxId); + if (soundEffect != NULL) { + AudioHeap_ChangeStorage(&change, soundEffect->tunedSample.sample); } } } @@ -1671,9 +1676,9 @@ void AudioHeap_InitReverb(s32 reverbIndex, ReverbSettings* settings, s32 flags) reverb->framesToIgnore = 2; } - reverb->sound.sample = &reverb->sample; + reverb->tunedSample.sample = &reverb->sample; reverb->sample.loop = &reverb->loop; - reverb->sound.tuning = 1.0f; + reverb->tunedSample.tuning = 1.0f; reverb->sample.codec = CODEC_REVERB; reverb->sample.medium = MEDIUM_RAM; reverb->sample.size = reverb->windowSize * 2; diff --git a/src/code/audio/audio_init_params.c b/src/code/audio/audio_init_params.c index b407ef7c98..81c49b30ca 100644 --- a/src/code/audio/audio_init_params.c +++ b/src/code/audio/audio_init_params.c @@ -5,8 +5,8 @@ const s16 gAudioTatumInit[] = { 0x30, // gTatumsPerBeat }; -const AudioContextInitSizes gAudioContextInitSizes = { +const AudioHeapInitSizes gAudioHeapInitSizes = { 0x137F00, // heapSize - 0x1C480, // mainPoolSplitSize + 0x1C480, // initPoolSize 0x1A000, // permanentPoolSize }; diff --git a/src/code/audio/audio_load.c b/src/code/audio/audio_load.c index 9ebdd1d857..c8e5ac5d1b 100644 --- a/src/code/audio/audio_load.c +++ b/src/code/audio/audio_load.c @@ -16,7 +16,7 @@ * SoundFont Notes: * */ -// opaque type for unpatched sound font data (should maybe get rid of this?) +// opaque type for soundfont data loaded into ram (should maybe get rid of this?) typedef void SoundFontData; typedef struct { @@ -26,7 +26,7 @@ typedef struct { /* 0x0C */ uintptr_t baseAddr2; /* 0x10 */ u32 medium1; /* 0x14 */ u32 medium2; -} AudioRelocInfo; // size = 0x18 +} SampleBankRelocInfo; // size = 0x18 void AudioLoad_DiscardFont(s32 fontId); s32 AudioLoad_SyncInitSeqPlayerInternal(s32 playerIndex, s32 seqId, s32 arg2); @@ -42,7 +42,7 @@ void AudioLoad_SyncDmaUnkMedium(uintptr_t devAddr, u8* addr, size_t size, s32 un s32 AudioLoad_Dma(OSIoMesg* mesg, u32 priority, s32 direction, uintptr_t devAddr, void* ramAddr, size_t size, OSMesgQueue* reqQueue, s32 medium, const char* dmaFuncType); void* AudioLoad_AsyncLoadInner(s32 tableType, s32 id, s32 nChunks, s32 retData, OSMesgQueue* retQueue); -SoundFontSample* AudioLoad_GetFontSample(s32 fontId, s32 instId); +Sample* AudioLoad_GetFontSample(s32 fontId, s32 instId); void AudioLoad_ProcessSlowLoads(s32 resetStatus); void AudioLoad_DmaSlowCopy(AudioSlowLoad* slowLoad, size_t size); void AudioLoad_DmaSlowCopyUnkMedium(intptr_t devAddr, intptr_t ramAddr, size_t size, s32 arg3); @@ -56,8 +56,9 @@ void AudioLoad_ProcessAsyncLoad(AudioAsyncLoad* asyncLoad, s32 resetStatus); void AudioLoad_AsyncDma(AudioAsyncLoad* asyncLoad, size_t size); void AudioLoad_AsyncDmaRamUnloaded(AudioAsyncLoad* asyncLoad, size_t size); void AudioLoad_AsyncDmaUnkMedium(uintptr_t devAddr, void* ramAddr, size_t size, s16 arg3); -void AudioLoad_RelocateSample(SoundFontSound* sound, SoundFontData* fontData, AudioRelocInfo* relocInfo); -void AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, SoundFontData* fontData, AudioRelocInfo* relocInfo, s32 async); +void AudioLoad_RelocateSample(TunedSample* tunedSample, SoundFontData* fontData, SampleBankRelocInfo* sampleBankReloc); +void AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, SoundFontData* fontData, SampleBankRelocInfo* sampleBankReloc, + s32 isAsync); s32 AudioLoad_ProcessSamplePreloads(s32 resetStatus); #define MK_ASYNC_MSG(retData, tableType, id, loadStatus) \ @@ -217,7 +218,7 @@ void* AudioLoad_DmaSampleData(uintptr_t devAddr, size_t size, s32 arg2, u8* dmaI dma->devAddr = dmaDevAddr; dma->sizeUnused = transfer; AudioLoad_Dma(&gAudioContext.currAudioFrameDmaIoMesgBuf[gAudioContext.curAudioFrameDmaCount++], OS_MESG_PRI_NORMAL, - OS_READ, dmaDevAddr, dma->ramAddr, transfer, &gAudioContext.currAudioFrameDmaQueue, medium, + OS_READ, dmaDevAddr, dma->ramAddr, transfer, &gAudioContext.curAudioFrameDmaQueue, medium, "SUPERDMA"); *dmaIndexRef = dmaIndex; return (devAddr - dmaDevAddr) + dma->ramAddr; @@ -423,10 +424,10 @@ void AudioLoad_SyncLoadSeqParts(s32 seqId, s32 arg1, s32 arg2, OSMesgQueue* arg3 } } -s32 AudioLoad_SyncLoadSample(SoundFontSample* sample, s32 fontId) { +s32 AudioLoad_SyncLoadSample(Sample* sample, s32 fontId) { void* sampleAddr; - if (sample->unk_bit25 == true) { + if (sample->isRelocated == true) { if (sample->medium != MEDIUM_RAM) { sampleAddr = AudioHeap_AllocSampleCache(sample->size, fontId, (void*)sample->sampleAddr, sample->medium, CACHE_PERSISTENT); @@ -454,11 +455,11 @@ s32 AudioLoad_SyncLoadInstrument(s32 fontId, s32 instId, s32 drumId) { return -1; } if (instrument->normalRangeLo != 0) { - AudioLoad_SyncLoadSample(instrument->lowNotesSound.sample, fontId); + AudioLoad_SyncLoadSample(instrument->lowPitchTunedSample.sample, fontId); } - AudioLoad_SyncLoadSample(instrument->normalNotesSound.sample, fontId); + AudioLoad_SyncLoadSample(instrument->normalPitchTunedSample.sample, fontId); if (instrument->normalRangeHi != 0x7F) { - return AudioLoad_SyncLoadSample(instrument->highNotesSound.sample, fontId); + return AudioLoad_SyncLoadSample(instrument->highPitchTunedSample.sample, fontId); } // TODO: is this missing return UB? } else if (instId == 0x7F) { @@ -467,7 +468,7 @@ s32 AudioLoad_SyncLoadInstrument(s32 fontId, s32 instId, s32 drumId) { if (drum == NULL) { return -1; } - AudioLoad_SyncLoadSample(drum->sound.sample, fontId); + AudioLoad_SyncLoadSample(drum->tunedSample.sample, fontId); return 0; } // TODO: is this missing return UB? @@ -680,28 +681,29 @@ SoundFontData* AudioLoad_SyncLoadFont(u32 fontId) { s32 sampleBankId1; s32 sampleBankId2; s32 didAllocate; - AudioRelocInfo relocInfo; + SampleBankRelocInfo sampleBankReloc; s32 realFontId = AudioLoad_GetRealTableIndex(FONT_TABLE, fontId); if (gAudioContext.fontLoadStatus[realFontId] == LOAD_STATUS_IN_PROGRESS) { return NULL; } - sampleBankId1 = gAudioContext.soundFonts[realFontId].sampleBankId1; - sampleBankId2 = gAudioContext.soundFonts[realFontId].sampleBankId2; + sampleBankId1 = gAudioContext.soundFontList[realFontId].sampleBankId1; + sampleBankId2 = gAudioContext.soundFontList[realFontId].sampleBankId2; - relocInfo.sampleBankId1 = sampleBankId1; - relocInfo.sampleBankId2 = sampleBankId2; - if (relocInfo.sampleBankId1 != 0xFF) { - relocInfo.baseAddr1 = AudioLoad_TrySyncLoadSampleBank(relocInfo.sampleBankId1, &relocInfo.medium1, false); + sampleBankReloc.sampleBankId1 = sampleBankId1; + sampleBankReloc.sampleBankId2 = sampleBankId2; + if (sampleBankReloc.sampleBankId1 != 0xFF) { + sampleBankReloc.baseAddr1 = + AudioLoad_TrySyncLoadSampleBank(sampleBankReloc.sampleBankId1, &sampleBankReloc.medium1, false); } else { - relocInfo.baseAddr1 = 0; + sampleBankReloc.baseAddr1 = 0; } if (sampleBankId2 != 0xFF) { - relocInfo.baseAddr2 = AudioLoad_TrySyncLoadSampleBank(sampleBankId2, &relocInfo.medium2, false); + sampleBankReloc.baseAddr2 = AudioLoad_TrySyncLoadSampleBank(sampleBankId2, &sampleBankReloc.medium2, false); } else { - relocInfo.baseAddr2 = 0; + sampleBankReloc.baseAddr2 = 0; } fontData = AudioLoad_SyncLoad(FONT_TABLE, fontId, &didAllocate); @@ -709,7 +711,7 @@ SoundFontData* AudioLoad_SyncLoadFont(u32 fontId) { return NULL; } if (didAllocate == true) { - AudioLoad_RelocateFontAndPreloadSamples(realFontId, fontData, &relocInfo, false); + AudioLoad_RelocateFontAndPreloadSamples(realFontId, fontData, &sampleBankReloc, false); } return fontData; @@ -778,7 +780,7 @@ void* AudioLoad_SyncLoad(s32 tableType, u32 id, s32* didAllocate) { } if (tableType == FONT_TABLE) { - SoundFont* soundFont = &gAudioContext.soundFonts[realId]; + SoundFont* soundFont = &gAudioContext.soundFontList[realId]; soundFont->numInstruments = ((UnloadedFonts*)romAddr)->numInstruments; soundFont->numDrums = ((UnloadedFonts*)romAddr)->numDrums; @@ -861,89 +863,131 @@ AudioTable* AudioLoad_GetLoadTable(s32 tableType) { } /** + * Read and extract information from soundFont binary loaded into ram. + * Also relocate offsets into pointers within this loaded soundFont * - * SoundFontData* mem -> the address of the soundFont as stored in memory + * @param fontId index of font being processed + * @param fontDataStartAddr ram address of raw soundfont binary loaded into cache + * @param sampleBankReloc information on the sampleBank containing raw audio samples */ -void AudioLoad_RelocateFont(s32 fontId, SoundFontData* fontData, AudioRelocInfo* relocInfo) { - uintptr_t reloc; - uintptr_t reloc2; +void AudioLoad_RelocateFont(s32 fontId, SoundFontData* fontDataStartAddr, SampleBankRelocInfo* sampleBankReloc) { + uintptr_t soundOffset; + uintptr_t soundListOffset; Instrument* inst; Drum* drum; - SoundFontSound* sfx; + SoundEffect* soundEffect; s32 i; - s32 numDrums = gAudioContext.soundFonts[fontId].numDrums; - s32 numInstruments = gAudioContext.soundFonts[fontId].numInstruments; - s32 numSfx = gAudioContext.soundFonts[fontId].numSfx; - void** ptrs = (void**)fontData; + s32 numDrums = gAudioContext.soundFontList[fontId].numDrums; + s32 numInstruments = gAudioContext.soundFontList[fontId].numInstruments; + s32 numSfx = gAudioContext.soundFontList[fontId].numSfx; + u32* fontData = (u32*)fontDataStartAddr; -#define BASE_OFFSET(x) (void*)((uintptr_t)(x) + (uintptr_t)(fontData)) + // Relocate an offset (relative to the start of the font data) to a pointer (a ram address) +#define RELOC_TO_RAM(x) (void*)((uintptr_t)(x) + (uintptr_t)(fontDataStartAddr)) - // relocate drums - reloc2 = ptrs[0]; + // Drums relocation + + // The first u32 in fontData is an offset to a list of offsets to the drums + soundListOffset = fontData[0]; if (1) {} - if ((reloc2 != 0) && (numDrums != 0)) { - ptrs[0] = BASE_OFFSET(reloc2); + + // If the soundFont has drums + if ((soundListOffset != 0) && (numDrums != 0)) { + + fontData[0] = RELOC_TO_RAM(soundListOffset); + + // Loop through the drum offsets for (i = 0; i < numDrums; i++) { - reloc = ((Drum**)ptrs[0])[i]; - if (reloc != 0) { - reloc = BASE_OFFSET(reloc); - ((Drum**)ptrs[0])[i] = drum = reloc; - if (!drum->loaded) { - AudioLoad_RelocateSample(&drum->sound, fontData, relocInfo); - reloc = drum->envelope; - drum->envelope = BASE_OFFSET(reloc); - drum->loaded = true; + // Get the i'th drum offset + soundOffset = ((Drum**)fontData[0])[i]; + + // Some drum data entries are empty, represented by an offset of 0 in the list of drum offsets + if (soundOffset != 0) { + soundOffset = RELOC_TO_RAM(soundOffset); + ((Drum**)fontData[0])[i] = drum = soundOffset; + + // The drum may be in the list multiple times and already relocated + if (!drum->isRelocated) { + AudioLoad_RelocateSample(&drum->tunedSample, fontDataStartAddr, sampleBankReloc); + + soundOffset = drum->envelope; + drum->envelope = RELOC_TO_RAM(soundOffset); + + drum->isRelocated = true; } } } } - // relocate sfxs - reloc2 = ptrs[1]; + // Sound effects relocation + + // The second u32 in fontData is an offset to the first sound effect entry + soundListOffset = fontData[1]; if (1) {} - if ((reloc2 != 0) && (numSfx != 0)) { - ptrs[1] = BASE_OFFSET(reloc2); + + // If the soundFont has sound effects + if ((soundListOffset != 0) && (numSfx != 0)) { + + fontData[1] = RELOC_TO_RAM(soundListOffset); + + // Loop through the sound effects for (i = 0; i < numSfx; i++) { - reloc = (SoundFontSound*)ptrs[1] + i; - if (reloc != 0) { - sfx = reloc; - if (sfx->sample != NULL) { - AudioLoad_RelocateSample(sfx, fontData, relocInfo); - } + // Get a pointer to the i'th sound effect + soundOffset = (TunedSample*)fontData[1] + i; + soundEffect = (SoundEffect*)soundOffset; + + // Check for NULL (note: the pointer is guaranteed to be in fontData and can never be NULL) + if ((soundEffect != NULL) && (soundEffect->tunedSample.sample != NULL)) { + AudioLoad_RelocateSample(&soundEffect->tunedSample, fontDataStartAddr, sampleBankReloc); } } } - if (numInstruments > 0x7E) { - numInstruments = 0x7E; + // Instruments relocation + + // Instrument Id 126 and above is reserved. + // There can only be 126 instruments, indexed from 0 to 125 + if (numInstruments > 126) { + numInstruments = 126; } - // relocate instruments + // Starting from the 3rd u32 in fontData is the list of offsets to the instruments + // Loop through the instruments for (i = 2; i <= 2 + numInstruments - 1; i++) { - if (ptrs[i] != NULL) { - ptrs[i] = BASE_OFFSET(ptrs[i]); - inst = ptrs[i]; - if (!inst->loaded) { + // Some instrument data entries are empty, represented by an offset of 0 in the list of instrument offsets + if (fontData[i] != 0) { + fontData[i] = RELOC_TO_RAM(fontData[i]); + inst = (Instrument*)fontData[i]; + + // The instrument may be in the list multiple times and already relocated + if (!inst->isRelocated) { + // Some instruments have a different sample for low pitches if (inst->normalRangeLo != 0) { - AudioLoad_RelocateSample(&inst->lowNotesSound, fontData, relocInfo); - } - AudioLoad_RelocateSample(&inst->normalNotesSound, fontData, relocInfo); - if (inst->normalRangeHi != 0x7F) { - AudioLoad_RelocateSample(&inst->highNotesSound, fontData, relocInfo); + AudioLoad_RelocateSample(&inst->lowPitchTunedSample, fontDataStartAddr, sampleBankReloc); } - reloc = inst->envelope; - inst->envelope = BASE_OFFSET(reloc); - inst->loaded = true; + // Every instrument has a sample for the default range + AudioLoad_RelocateSample(&inst->normalPitchTunedSample, fontDataStartAddr, sampleBankReloc); + + // Some instruments have a different sample for high pitches + if (inst->normalRangeHi != 0x7F) { + AudioLoad_RelocateSample(&inst->highPitchTunedSample, fontDataStartAddr, sampleBankReloc); + } + + soundOffset = inst->envelope; + inst->envelope = (EnvelopePoint*)RELOC_TO_RAM(soundOffset); + + inst->isRelocated = true; } } } -#undef BASE_OFFSET +#undef RELOC_TO_RAM - gAudioContext.soundFonts[fontId].drums = ptrs[0]; - gAudioContext.soundFonts[fontId].soundEffects = ptrs[1]; - gAudioContext.soundFonts[fontId].instruments = (Instrument**)(&ptrs[2]); + // Store the relocated pointers + gAudioContext.soundFontList[fontId].drums = (Drum**)fontData[0]; + gAudioContext.soundFontList[fontId].soundEffects = (SoundEffect*)fontData[1]; + gAudioContext.soundFontList[fontId].instruments = (Instrument**)(&fontData[2]); } void AudioLoad_SyncDma(uintptr_t devAddr, u8* ramAddr, size_t size, s32 medium) { @@ -1102,7 +1146,7 @@ void* AudioLoad_AsyncLoadInner(s32 tableType, s32 id, s32 nChunks, s32 retData, } if (tableType == FONT_TABLE) { - soundFont = &gAudioContext.soundFonts[realId]; + soundFont = &gAudioContext.soundFontList[realId]; soundFont->numInstruments = ((UnloadedFonts*)romAddr)->numInstruments; soundFont->numDrums = ((UnloadedFonts*)romAddr)->numDrums; @@ -1154,8 +1198,8 @@ void AudioLoad_SetUnusedHandler(void* callback) { sUnusedHandler = callback; } -void AudioLoad_InitSoundFontMeta(s32 fontId) { - SoundFont* font = &gAudioContext.soundFonts[fontId]; +void AudioLoad_InitSoundFont(s32 fontId) { + SoundFont* font = &gAudioContext.soundFontList[fontId]; AudioTableEntry* entry = &gAudioContext.soundFontTable->entries[fontId]; font->sampleBankId1 = (entry->shortData1 >> 8) & 0xFF; @@ -1210,20 +1254,20 @@ void AudioLoad_Init(void* heap, size_t heapSize) { AudioThread_InitMesgQueues(); - for (i = 0; i < ARRAY_COUNT(gAudioContext.aiBufLengths); i++) { - gAudioContext.aiBufLengths[i] = 0xA0; + for (i = 0; i < ARRAY_COUNT(gAudioContext.aiBufNumSamples); i++) { + gAudioContext.aiBufNumSamples[i] = 0xA0; } gAudioContext.totalTaskCount = 0; gAudioContext.rspTaskIndex = 0; - gAudioContext.curAiBuffferIndex = 0; + gAudioContext.curAiBufferIndex = 0; gAudioContext.soundMode = SOUNDMODE_STEREO; gAudioContext.curTask = NULL; gAudioContext.rspTask[0].task.t.dataSize = 0; gAudioContext.rspTask[1].task.t.dataSize = 0; osCreateMesgQueue(&gAudioContext.syncDmaQueue, &gAudioContext.syncDmaMesg, 1); - osCreateMesgQueue(&gAudioContext.currAudioFrameDmaQueue, gAudioContext.currAudioFrameDmaMesgBuf, + osCreateMesgQueue(&gAudioContext.curAudioFrameDmaQueue, gAudioContext.currAudioFrameDmaMesgBuf, ARRAY_COUNT(gAudioContext.currAudioFrameDmaMesgBuf)); osCreateMesgQueue(&gAudioContext.externalLoadQueue, gAudioContext.externalLoadMesgBuf, ARRAY_COUNT(gAudioContext.externalLoadMesgBuf)); @@ -1235,23 +1279,24 @@ void AudioLoad_Init(void* heap, size_t heapSize) { if (heap == NULL) { gAudioContext.audioHeap = gAudioHeap; - gAudioContext.audioHeapSize = gAudioContextInitSizes.heapSize; + gAudioContext.audioHeapSize = gAudioHeapInitSizes.heapSize; } else { void** hp = &heap; + gAudioContext.audioHeap = *hp; gAudioContext.audioHeapSize = heapSize; } - for (i = 0; i < (s32)gAudioContext.audioHeapSize / 8; i++) { + for (i = 0; i < ((s32)gAudioContext.audioHeapSize / (s32)sizeof(u64)); i++) { ((u64*)gAudioContext.audioHeap)[i] = 0; } // Main Pool Split (split entirety of audio heap into initPool and sessionPool) - AudioHeap_InitMainPool(gAudioContextInitSizes.mainPoolSplitSize); + AudioHeap_InitMainPool(gAudioHeapInitSizes.initPoolSize); - // Initialize the audio interface buffer + // Initialize the audio interface buffers for (i = 0; i < ARRAY_COUNT(gAudioContext.aiBuffers); i++) { - gAudioContext.aiBuffers[i] = AudioHeap_AllocZeroed(&gAudioContext.audioInitPool, AIBUF_LEN * sizeof(s16)); + gAudioContext.aiBuffers[i] = AudioHeap_AllocZeroed(&gAudioContext.initPool, AIBUF_LEN * sizeof(s16)); } // Connect audio tables to their tables in memory @@ -1272,18 +1317,18 @@ void AudioLoad_Init(void* heap, size_t heapSize) { AudioLoad_InitTable(gAudioContext.sampleBankTable, SEGMENT_ROM_START(Audiotable), 0); numFonts = gAudioContext.soundFontTable->numEntries; - gAudioContext.soundFonts = AudioHeap_Alloc(&gAudioContext.audioInitPool, numFonts * sizeof(SoundFont)); + gAudioContext.soundFontList = AudioHeap_Alloc(&gAudioContext.initPool, numFonts * sizeof(SoundFont)); for (i = 0; i < numFonts; i++) { - AudioLoad_InitSoundFontMeta(i); + AudioLoad_InitSoundFont(i); } - if (addr = AudioHeap_Alloc(&gAudioContext.audioInitPool, gAudioContextInitSizes.permanentPoolSize), addr == NULL) { - // cast away const from D_8014A6C4 - *((u32*)&gAudioContextInitSizes.permanentPoolSize) = 0; + if (addr = AudioHeap_Alloc(&gAudioContext.initPool, gAudioHeapInitSizes.permanentPoolSize), addr == NULL) { + // cast away const from gAudioHeapInitSizes + *((u32*)&gAudioHeapInitSizes.permanentPoolSize) = 0; } - AudioHeap_AllocPoolInit(&gAudioContext.permanentPool, addr, gAudioContextInitSizes.permanentPoolSize); + AudioHeap_InitPool(&gAudioContext.permanentPool, addr, gAudioHeapInitSizes.permanentPoolSize); gAudioContextInitalized = true; osSendMesg(gAudioContext.taskStartQueueP, (void*)gAudioContext.totalTaskCount, OS_MESG_NOBLOCK); } @@ -1294,7 +1339,7 @@ void AudioLoad_InitSlowLoads(void) { } s32 AudioLoad_SlowLoadSample(s32 fontId, s32 instId, s8* isDone) { - SoundFontSample* sample; + Sample* sample; AudioSlowLoad* slowLoad; sample = AudioLoad_GetFontSample(fontId, instId); @@ -1344,8 +1389,8 @@ s32 AudioLoad_SlowLoadSample(s32 fontId, s32 instId, s8* isDone) { return 0; } -SoundFontSample* AudioLoad_GetFontSample(s32 fontId, s32 instId) { - SoundFontSample* sample; +Sample* AudioLoad_GetFontSample(s32 fontId, s32 instId) { + Sample* sample; if (instId < 0x80) { Instrument* instrument = AudioPlayback_GetInstrumentInner(fontId, instId); @@ -1353,21 +1398,21 @@ SoundFontSample* AudioLoad_GetFontSample(s32 fontId, s32 instId) { if (instrument == NULL) { return NULL; } - sample = instrument->normalNotesSound.sample; + sample = instrument->normalPitchTunedSample.sample; } else if (instId < 0x100) { Drum* drum = AudioPlayback_GetDrum(fontId, instId - 0x80); if (drum == NULL) { return NULL; } - sample = drum->sound.sample; + sample = drum->tunedSample.sample; } else { - SoundFontSound* sound = AudioPlayback_GetSfx(fontId, instId - 0x100); + SoundEffect* soundEffect = AudioPlayback_GetSoundEffect(fontId, instId - 0x100); - if (sound == NULL) { + if (soundEffect == NULL) { return NULL; } - sample = sound->sample; + sample = soundEffect->tunedSample.sample; } return sample; @@ -1377,7 +1422,7 @@ void AudioLoad_Unused2(void) { } void AudioLoad_FinishSlowLoad(AudioSlowLoad* slowLoad) { - SoundFontSample* sample; + Sample* sample; if (slowLoad->sample.sampleAddr == NULL) { return; @@ -1596,7 +1641,7 @@ void AudioLoad_FinishAsyncLoad(AudioAsyncLoad* asyncLoad) { OSMesg doneMsg; u32 sampleBankId1; u32 sampleBankId2; - AudioRelocInfo relocInfo; + SampleBankRelocInfo sampleBankReloc; if (1) {} switch (ASYNC_TBLTYPE(retMsg)) { @@ -1608,16 +1653,16 @@ void AudioLoad_FinishAsyncLoad(AudioAsyncLoad* asyncLoad) { break; case FONT_TABLE: fontId = ASYNC_ID(retMsg); - sampleBankId1 = gAudioContext.soundFonts[fontId].sampleBankId1; - sampleBankId2 = gAudioContext.soundFonts[fontId].sampleBankId2; - relocInfo.sampleBankId1 = sampleBankId1; - relocInfo.sampleBankId2 = sampleBankId2; - relocInfo.baseAddr1 = - sampleBankId1 != 0xFF ? AudioLoad_GetSampleBank(sampleBankId1, &relocInfo.medium1) : 0; - relocInfo.baseAddr2 = - sampleBankId2 != 0xFF ? AudioLoad_GetSampleBank(sampleBankId2, &relocInfo.medium2) : 0; + sampleBankId1 = gAudioContext.soundFontList[fontId].sampleBankId1; + sampleBankId2 = gAudioContext.soundFontList[fontId].sampleBankId2; + sampleBankReloc.sampleBankId1 = sampleBankId1; + sampleBankReloc.sampleBankId2 = sampleBankId2; + sampleBankReloc.baseAddr1 = + (sampleBankId1 != 0xFF) ? AudioLoad_GetSampleBank(sampleBankId1, &sampleBankReloc.medium1) : 0; + sampleBankReloc.baseAddr2 = + (sampleBankId2 != 0xFF) ? AudioLoad_GetSampleBank(sampleBankId2, &sampleBankReloc.medium2) : 0; AudioLoad_SetFontLoadStatus(fontId, ASYNC_STATUS(retMsg)); - AudioLoad_RelocateFontAndPreloadSamples(fontId, asyncLoad->ramAddr, &relocInfo, true); + AudioLoad_RelocateFontAndPreloadSamples(fontId, asyncLoad->ramAddr, &sampleBankReloc, true); break; } @@ -1700,28 +1745,48 @@ void AudioLoad_AsyncDmaRamUnloaded(AudioAsyncLoad* asyncLoad, size_t size) { void AudioLoad_AsyncDmaUnkMedium(uintptr_t devAddr, void* ramAddr, size_t size, s16 arg3) { } -#define RELOC(v, base) (reloc = (void*)((uintptr_t)(v) + (uintptr_t)(base))) - -void AudioLoad_RelocateSample(SoundFontSound* sound, SoundFontData* mem, AudioRelocInfo* relocInfo) { - SoundFontSample* sample; +/** + * Read and extract information from TunedSample and its Sample + * contained in the soundFont binary loaded into ram + * TunedSample contains metadata on a sample used by a particular instrument/drum/sfx + * Also relocate offsets into pointers within this loaded TunedSample + * + * @param fontId index of font being processed + * @param fontData ram address of raw soundfont binary loaded into cache + * @param sampleBankReloc information on the sampleBank containing raw audio samples + */ +void AudioLoad_RelocateSample(TunedSample* tunedSample, SoundFontData* fontData, SampleBankRelocInfo* sampleBankReloc) { + Sample* sample; void* reloc; - if ((uintptr_t)sound->sample <= 0x80000000) { - sample = sound->sample = RELOC(sound->sample, mem); - if (sample->size != 0 && sample->unk_bit25 != true) { - sample->loop = RELOC(sample->loop, mem); - sample->book = RELOC(sample->book, mem); + // Relocate an offset (relative to data loaded in ram at `base`) to a pointer (a ram address) +#define AUDIO_RELOC(v, base) (reloc = (void*)((uintptr_t)(v) + (uintptr_t)(base))) - // Resolve the sample medium 2-bit bitfield into a real value based on relocInfo. + if ((uintptr_t)tunedSample->sample <= AUDIO_RELOCATED_ADDRESS_START) { + + sample = tunedSample->sample = AUDIO_RELOC(tunedSample->sample, fontData); + + // If the sample exists and has not already been relocated + // Note: this is important, as the same sample can be used by different drums, sound effects, instruments + if ((sample->size != 0) && (sample->isRelocated != true)) { + sample->loop = AUDIO_RELOC(sample->loop, fontData); + sample->book = AUDIO_RELOC(sample->book, fontData); + + // Resolve the sample medium 2-bit bitfield into a real value based on sampleBankReloc. + // Then relocate the offset sample within the sampleBank (not the fontData) into absolute address. + // sampleAddr can be either rom or ram depending on sampleBank cache policy + // in practice, this is always in rom switch (sample->medium) { case 0: - sample->sampleAddr = RELOC(sample->sampleAddr, relocInfo->baseAddr1); - sample->medium = relocInfo->medium1; + sample->sampleAddr = AUDIO_RELOC(sample->sampleAddr, sampleBankReloc->baseAddr1); + sample->medium = sampleBankReloc->medium1; break; + case 1: - sample->sampleAddr = RELOC(sample->sampleAddr, relocInfo->baseAddr2); - sample->medium = relocInfo->medium2; + sample->sampleAddr = AUDIO_RELOC(sample->sampleAddr, sampleBankReloc->baseAddr2); + sample->medium = sampleBankReloc->medium2; break; + case 2: case 3: // Invalid? This leaves sample->medium as MEDIUM_CART and MEDIUM_DISK_DRIVE @@ -1729,7 +1794,8 @@ void AudioLoad_RelocateSample(SoundFontSound* sound, SoundFontData* mem, AudioRe break; } - sample->unk_bit25 = true; + sample->isRelocated = true; + if (sample->unk_bit26 && (sample->medium != MEDIUM_RAM)) { gAudioContext.usedSamples[gAudioContext.numUsedSamples++] = sample; } @@ -1737,12 +1803,19 @@ void AudioLoad_RelocateSample(SoundFontSound* sound, SoundFontData* mem, AudioRe } } -#undef RELOC +#undef AUDIO_RELOC -void AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, SoundFontData* mem, AudioRelocInfo* relocInfo, s32 async) { +/** + * @param fontId index of font being processed + * @param fontData ram address of raw soundfont binary loaded into cache + * @param sampleBankReloc information on the sampleBank containing raw audio samples + * @param isAsync bool for whether this is an asynchronous load or not + */ +void AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, SoundFontData* fontData, SampleBankRelocInfo* sampleBankReloc, + s32 isAsync) { AudioPreloadReq* preload; AudioPreloadReq* topPreload; - SoundFontSample* sample; + Sample* sample; size_t size; s32 nChunks; u8* sampleRamAddr; @@ -1757,7 +1830,7 @@ void AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, SoundFontData* mem, Aud } gAudioContext.numUsedSamples = 0; - AudioLoad_RelocateFont(fontId, mem, relocInfo); + AudioLoad_RelocateFont(fontId, fontData, sampleBankReloc); size = 0; for (i = 0; i < gAudioContext.numUsedSamples; i++) { @@ -1772,13 +1845,13 @@ void AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, SoundFontData* mem, Aud sample = gAudioContext.usedSamples[i]; sampleRamAddr = NULL; - switch (async) { + switch (isAsync) { case false: - if (sample->medium == relocInfo->medium1) { - sampleRamAddr = AudioHeap_AllocSampleCache(sample->size, relocInfo->sampleBankId1, + if (sample->medium == sampleBankReloc->medium1) { + sampleRamAddr = AudioHeap_AllocSampleCache(sample->size, sampleBankReloc->sampleBankId1, sample->sampleAddr, sample->medium, CACHE_PERSISTENT); - } else if (sample->medium == relocInfo->medium2) { - sampleRamAddr = AudioHeap_AllocSampleCache(sample->size, relocInfo->sampleBankId2, + } else if (sample->medium == sampleBankReloc->medium2) { + sampleRamAddr = AudioHeap_AllocSampleCache(sample->size, sampleBankReloc->sampleBankId2, sample->sampleAddr, sample->medium, CACHE_PERSISTENT); } else if (sample->medium == MEDIUM_DISK_DRIVE) { sampleRamAddr = AudioHeap_AllocSampleCache(sample->size, 0xFE, sample->sampleAddr, sample->medium, @@ -1787,23 +1860,26 @@ void AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, SoundFontData* mem, Aud break; case true: - if (sample->medium == relocInfo->medium1) { - sampleRamAddr = AudioHeap_AllocSampleCache(sample->size, relocInfo->sampleBankId1, + if (sample->medium == sampleBankReloc->medium1) { + sampleRamAddr = AudioHeap_AllocSampleCache(sample->size, sampleBankReloc->sampleBankId1, sample->sampleAddr, sample->medium, CACHE_TEMPORARY); - } else if (sample->medium == relocInfo->medium2) { - sampleRamAddr = AudioHeap_AllocSampleCache(sample->size, relocInfo->sampleBankId2, + } else if (sample->medium == sampleBankReloc->medium2) { + sampleRamAddr = AudioHeap_AllocSampleCache(sample->size, sampleBankReloc->sampleBankId2, sample->sampleAddr, sample->medium, CACHE_TEMPORARY); } else if (sample->medium == MEDIUM_DISK_DRIVE) { sampleRamAddr = AudioHeap_AllocSampleCache(sample->size, 0xFE, sample->sampleAddr, sample->medium, CACHE_TEMPORARY); } break; + + default: + break; } if (sampleRamAddr == NULL) { continue; } - switch (async) { + switch (isAsync) { case false: if (sample->medium == MEDIUM_UNK) { AudioLoad_SyncDmaUnkMedium((uintptr_t)sample->sampleAddr, sampleRamAddr, sample->size, @@ -1827,6 +1903,9 @@ void AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, SoundFontData* mem, Aud preload->endAndMediumKey = (uintptr_t)sample->sampleAddr + sample->size + sample->medium; gAudioContext.preloadSampleStackTop++; break; + + default: + break; } } gAudioContext.numUsedSamples = 0; @@ -1841,7 +1920,7 @@ void AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, SoundFontData* mem, Aud } s32 AudioLoad_ProcessSamplePreloads(s32 resetStatus) { - SoundFontSample* sample; + Sample* sample; AudioPreloadReq* preload; u32 preloadIndex; u32 key; @@ -1902,7 +1981,7 @@ s32 AudioLoad_ProcessSamplePreloads(s32 resetStatus) { return true; } -s32 AudioLoad_AddToSampleSet(SoundFontSample* sample, s32 numSamples, SoundFontSample** sampleSet) { +s32 AudioLoad_AddToSampleSet(Sample* sample, s32 numSamples, Sample** sampleSet) { s32 i; for (i = 0; i < numSamples; i++) { @@ -1919,18 +1998,18 @@ s32 AudioLoad_AddToSampleSet(SoundFontSample* sample, s32 numSamples, SoundFontS return numSamples; } -s32 AudioLoad_GetSamplesForFont(s32 fontId, SoundFontSample** sampleSet) { +s32 AudioLoad_GetSamplesForFont(s32 fontId, Sample** sampleSet) { s32 i; s32 numSamples = 0; - s32 numDrums = gAudioContext.soundFonts[fontId].numDrums; - s32 numInstruments = gAudioContext.soundFonts[fontId].numInstruments; + s32 numDrums = gAudioContext.soundFontList[fontId].numDrums; + s32 numInstruments = gAudioContext.soundFontList[fontId].numInstruments; for (i = 0; i < numDrums; i++) { Drum* drum = AudioPlayback_GetDrum(fontId, i); if (1) {} if (drum != NULL) { - numSamples = AudioLoad_AddToSampleSet(drum->sound.sample, numSamples, sampleSet); + numSamples = AudioLoad_AddToSampleSet(drum->tunedSample.sample, numSamples, sampleSet); } } @@ -1939,12 +2018,12 @@ s32 AudioLoad_GetSamplesForFont(s32 fontId, SoundFontSample** sampleSet) { if (instrument != NULL) { if (instrument->normalRangeLo != 0) { - numSamples = AudioLoad_AddToSampleSet(instrument->lowNotesSound.sample, numSamples, sampleSet); + numSamples = AudioLoad_AddToSampleSet(instrument->lowPitchTunedSample.sample, numSamples, sampleSet); } if (instrument->normalRangeHi != 0x7F) { - numSamples = AudioLoad_AddToSampleSet(instrument->highNotesSound.sample, numSamples, sampleSet); + numSamples = AudioLoad_AddToSampleSet(instrument->highPitchTunedSample.sample, numSamples, sampleSet); } - numSamples = AudioLoad_AddToSampleSet(instrument->normalNotesSound.sample, numSamples, sampleSet); + numSamples = AudioLoad_AddToSampleSet(instrument->normalPitchTunedSample.sample, numSamples, sampleSet); } } @@ -1952,27 +2031,27 @@ s32 AudioLoad_GetSamplesForFont(s32 fontId, SoundFontSample** sampleSet) { return numSamples; } -void AudioLoad_AddUsedSample(SoundFontSound* sound) { - SoundFontSample* sample = sound->sample; +void AudioLoad_AddUsedSample(TunedSample* tunedSample) { + Sample* sample = tunedSample->sample; if ((sample->size != 0) && (sample->unk_bit26) && (sample->medium != MEDIUM_RAM)) { gAudioContext.usedSamples[gAudioContext.numUsedSamples++] = sample; } } -void AudioLoad_PreloadSamplesForFont(s32 fontId, s32 async, AudioRelocInfo* relocInfo) { +void AudioLoad_PreloadSamplesForFont(s32 fontId, s32 async, SampleBankRelocInfo* sampleBankReloc) { s32 numDrums; s32 numInstruments; s32 numSfx; Drum* drum; Instrument* instrument; - SoundFontSound* sound; + SoundEffect* soundEffect; AudioPreloadReq* preload; AudioPreloadReq* topPreload; u8* addr; size_t size; s32 i; - SoundFontSample* sample; + Sample* sample; s32 preloadInProgress; s32 nChunks; @@ -1983,34 +2062,34 @@ void AudioLoad_PreloadSamplesForFont(s32 fontId, s32 async, AudioRelocInfo* relo gAudioContext.numUsedSamples = 0; - numDrums = gAudioContext.soundFonts[fontId].numDrums; - numInstruments = gAudioContext.soundFonts[fontId].numInstruments; - numSfx = gAudioContext.soundFonts[fontId].numSfx; + numDrums = gAudioContext.soundFontList[fontId].numDrums; + numInstruments = gAudioContext.soundFontList[fontId].numInstruments; + numSfx = gAudioContext.soundFontList[fontId].numSfx; for (i = 0; i < numInstruments; i++) { instrument = AudioPlayback_GetInstrumentInner(fontId, i); if (instrument != NULL) { if (instrument->normalRangeLo != 0) { - AudioLoad_AddUsedSample(&instrument->lowNotesSound); + AudioLoad_AddUsedSample(&instrument->lowPitchTunedSample); } if (instrument->normalRangeHi != 0x7F) { - AudioLoad_AddUsedSample(&instrument->highNotesSound); + AudioLoad_AddUsedSample(&instrument->highPitchTunedSample); } - AudioLoad_AddUsedSample(&instrument->normalNotesSound); + AudioLoad_AddUsedSample(&instrument->normalPitchTunedSample); } } for (i = 0; i < numDrums; i++) { drum = AudioPlayback_GetDrum(fontId, i); if (drum != NULL) { - AudioLoad_AddUsedSample(&drum->sound); + AudioLoad_AddUsedSample(&drum->tunedSample); } } for (i = 0; i < numSfx; i++) { - sound = AudioPlayback_GetSfx(fontId, i); - if (sound != NULL) { - AudioLoad_AddUsedSample(sound); + soundEffect = AudioPlayback_GetSoundEffect(fontId, i); + if (soundEffect != NULL) { + AudioLoad_AddUsedSample(&soundEffect->tunedSample); } } @@ -2036,21 +2115,21 @@ void AudioLoad_PreloadSamplesForFont(s32 fontId, s32 async, AudioRelocInfo* relo switch (async) { case false: - if (sample->medium == relocInfo->medium1) { - addr = AudioHeap_AllocSampleCache(sample->size, relocInfo->sampleBankId1, sample->sampleAddr, + if (sample->medium == sampleBankReloc->medium1) { + addr = AudioHeap_AllocSampleCache(sample->size, sampleBankReloc->sampleBankId1, sample->sampleAddr, sample->medium, CACHE_PERSISTENT); - } else if (sample->medium == relocInfo->medium2) { - addr = AudioHeap_AllocSampleCache(sample->size, relocInfo->sampleBankId2, sample->sampleAddr, + } else if (sample->medium == sampleBankReloc->medium2) { + addr = AudioHeap_AllocSampleCache(sample->size, sampleBankReloc->sampleBankId2, sample->sampleAddr, sample->medium, CACHE_PERSISTENT); } break; case true: - if (sample->medium == relocInfo->medium1) { - addr = AudioHeap_AllocSampleCache(sample->size, relocInfo->sampleBankId1, sample->sampleAddr, + if (sample->medium == sampleBankReloc->medium1) { + addr = AudioHeap_AllocSampleCache(sample->size, sampleBankReloc->sampleBankId1, sample->sampleAddr, sample->medium, CACHE_TEMPORARY); - } else if (sample->medium == relocInfo->medium2) { - addr = AudioHeap_AllocSampleCache(sample->size, relocInfo->sampleBankId2, sample->sampleAddr, + } else if (sample->medium == sampleBankReloc->medium2) { + addr = AudioHeap_AllocSampleCache(sample->size, sampleBankReloc->sampleBankId2, sample->sampleAddr, sample->medium, CACHE_TEMPORARY); } break; @@ -2104,23 +2183,25 @@ void AudioLoad_LoadPermanentSamples(void) { sampleBankTable = AudioLoad_GetLoadTable(SAMPLE_TABLE); for (i = 0; i < gAudioContext.permanentPool.count; i++) { - AudioRelocInfo relocInfo; + SampleBankRelocInfo sampleBankReloc; if (gAudioContext.permanentEntries[i].tableType == FONT_TABLE) { fontId = AudioLoad_GetRealTableIndex(FONT_TABLE, gAudioContext.permanentEntries[i].id); - relocInfo.sampleBankId1 = gAudioContext.soundFonts[fontId].sampleBankId1; - relocInfo.sampleBankId2 = gAudioContext.soundFonts[fontId].sampleBankId2; + sampleBankReloc.sampleBankId1 = gAudioContext.soundFontList[fontId].sampleBankId1; + sampleBankReloc.sampleBankId2 = gAudioContext.soundFontList[fontId].sampleBankId2; - if (relocInfo.sampleBankId1 != 0xFF) { - relocInfo.sampleBankId1 = AudioLoad_GetRealTableIndex(SAMPLE_TABLE, relocInfo.sampleBankId1); - relocInfo.medium1 = sampleBankTable->entries[relocInfo.sampleBankId1].medium; + if (sampleBankReloc.sampleBankId1 != 0xFF) { + sampleBankReloc.sampleBankId1 = + AudioLoad_GetRealTableIndex(SAMPLE_TABLE, sampleBankReloc.sampleBankId1); + sampleBankReloc.medium1 = sampleBankTable->entries[sampleBankReloc.sampleBankId1].medium; } - if (relocInfo.sampleBankId2 != 0xFF) { - relocInfo.sampleBankId2 = AudioLoad_GetRealTableIndex(SAMPLE_TABLE, relocInfo.sampleBankId2); - relocInfo.medium2 = sampleBankTable->entries[relocInfo.sampleBankId2].medium; + if (sampleBankReloc.sampleBankId2 != 0xFF) { + sampleBankReloc.sampleBankId2 = + AudioLoad_GetRealTableIndex(SAMPLE_TABLE, sampleBankReloc.sampleBankId2); + sampleBankReloc.medium2 = sampleBankTable->entries[sampleBankReloc.sampleBankId2].medium; } - AudioLoad_PreloadSamplesForFont(fontId, false, &relocInfo); + AudioLoad_PreloadSamplesForFont(fontId, false, &sampleBankReloc); } } } diff --git a/src/code/audio/audio_playback.c b/src/code/audio/audio_playback.c index e7f5153ac2..e1a42b1eda 100644 --- a/src/code/audio/audio_playback.c +++ b/src/code/audio/audio_playback.c @@ -4,9 +4,10 @@ void AudioPlayback_NoteSetResamplingRate(NoteSubEu* noteSubEu, f32 resamplingRat void AudioPlayback_AudioListPushFront(AudioListItem* list, AudioListItem* item); void AudioPlayback_NoteInitForLayer(Note* note, SequenceLayer* layer); -void AudioPlayback_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* attrs) { - f32 volRight, volLeft; - s32 smallPanIndex; +void AudioPlayback_InitNoteSub(Note* note, NoteSubEu* noteSubEu, NoteSubAttributes* subAttrs) { + f32 volLeft; + f32 volRight; + s32 halfPanIndex; u64 pad; u8 strongLeft; u8 strongRight; @@ -16,41 +17,41 @@ void AudioPlayback_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* at StereoData stereoData; s32 stereoHeadsetEffects = note->playbackState.stereoHeadsetEffects; - vel = attrs->velocity; - pan = attrs->pan; - reverbVol = attrs->reverbVol; - stereoData = attrs->stereo.s; + vel = subAttrs->velocity; + pan = subAttrs->pan; + reverbVol = subAttrs->reverbVol; + stereoData = subAttrs->stereo.s; - sub->bitField0 = note->noteSubEu.bitField0; - sub->bitField1 = note->noteSubEu.bitField1; - sub->sound.samples = note->noteSubEu.sound.samples; - sub->unk_06 = note->noteSubEu.unk_06; + noteSubEu->bitField0 = note->noteSubEu.bitField0; + noteSubEu->bitField1 = note->noteSubEu.bitField1; + noteSubEu->waveSampleAddr = note->noteSubEu.waveSampleAddr; + noteSubEu->harmonicIndexCurAndPrev = note->noteSubEu.harmonicIndexCurAndPrev; - AudioPlayback_NoteSetResamplingRate(sub, attrs->frequency); + AudioPlayback_NoteSetResamplingRate(noteSubEu, subAttrs->frequency); pan &= 0x7F; - sub->bitField0.stereoStrongRight = false; - sub->bitField0.stereoStrongLeft = false; - sub->bitField0.stereoHeadsetEffects = stereoData.stereoHeadsetEffects; - sub->bitField0.usesHeadsetPanEffects = stereoData.usesHeadsetPanEffects; - if (stereoHeadsetEffects && gAudioContext.soundMode == SOUNDMODE_HEADSET) { - smallPanIndex = pan >> 1; - if (smallPanIndex > 0x3F) { - smallPanIndex = 0x3F; + noteSubEu->bitField0.stereoStrongRight = false; + noteSubEu->bitField0.stereoStrongLeft = false; + noteSubEu->bitField0.stereoHeadsetEffects = stereoData.stereoHeadsetEffects; + noteSubEu->bitField0.usesHeadsetPanEffects = stereoData.usesHeadsetPanEffects; + if (stereoHeadsetEffects && (gAudioContext.soundMode == SOUNDMODE_HEADSET)) { + halfPanIndex = pan >> 1; + if (halfPanIndex > 0x3F) { + halfPanIndex = 0x3F; } - sub->headsetPanLeft = gHeadsetPanQuantization[smallPanIndex]; - sub->headsetPanRight = gHeadsetPanQuantization[0x3F - smallPanIndex]; - sub->bitField1.usesHeadsetPanEffects2 = true; + noteSubEu->headsetPanLeft = gHeadsetPanQuantization[halfPanIndex]; + noteSubEu->headsetPanRight = gHeadsetPanQuantization[0x3F - halfPanIndex]; + noteSubEu->bitField1.usesHeadsetPanEffects2 = true; volLeft = gHeadsetPanVolume[pan]; volRight = gHeadsetPanVolume[0x7F - pan]; - } else if (stereoHeadsetEffects && gAudioContext.soundMode == SOUNDMODE_STEREO) { + } else if (stereoHeadsetEffects && (gAudioContext.soundMode == SOUNDMODE_STEREO)) { strongLeft = strongRight = false; - sub->headsetPanRight = 0; - sub->headsetPanLeft = 0; - sub->bitField1.usesHeadsetPanEffects2 = false; + noteSubEu->headsetPanRight = 0; + noteSubEu->headsetPanLeft = 0; + noteSubEu->bitField1.usesHeadsetPanEffects2 = false; volLeft = gStereoPanVolume[pan]; volRight = gStereoPanVolume[0x7F - pan]; @@ -60,34 +61,38 @@ void AudioPlayback_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* at strongRight = true; } - sub->bitField0.stereoStrongRight = strongRight; - sub->bitField0.stereoStrongLeft = strongLeft; + // case 0: + noteSubEu->bitField0.stereoStrongRight = strongRight; + noteSubEu->bitField0.stereoStrongLeft = strongLeft; switch (stereoData.bit2) { case 0: break; + case 1: - sub->bitField0.stereoStrongRight = stereoData.strongRight; - sub->bitField0.stereoStrongLeft = stereoData.strongLeft; + noteSubEu->bitField0.stereoStrongRight = stereoData.strongRight; + noteSubEu->bitField0.stereoStrongLeft = stereoData.strongLeft; break; + case 2: - sub->bitField0.stereoStrongRight = stereoData.strongRight | strongRight; - sub->bitField0.stereoStrongLeft = stereoData.strongLeft | strongLeft; + noteSubEu->bitField0.stereoStrongRight = stereoData.strongRight | strongRight; + noteSubEu->bitField0.stereoStrongLeft = stereoData.strongLeft | strongLeft; break; + case 3: - sub->bitField0.stereoStrongRight = stereoData.strongRight ^ strongRight; - sub->bitField0.stereoStrongLeft = stereoData.strongLeft ^ strongLeft; + noteSubEu->bitField0.stereoStrongRight = stereoData.strongRight ^ strongRight; + noteSubEu->bitField0.stereoStrongLeft = stereoData.strongLeft ^ strongLeft; break; } } else if (gAudioContext.soundMode == SOUNDMODE_MONO) { - sub->bitField0.stereoHeadsetEffects = false; - sub->bitField0.usesHeadsetPanEffects = false; + noteSubEu->bitField0.stereoHeadsetEffects = false; + noteSubEu->bitField0.usesHeadsetPanEffects = false; volLeft = 0.707f; // approx 1/sqrt(2) volRight = 0.707f; } else { - sub->bitField0.stereoStrongRight = stereoData.strongRight; - sub->bitField0.stereoStrongLeft = stereoData.strongLeft; + noteSubEu->bitField0.stereoStrongRight = stereoData.strongRight; + noteSubEu->bitField0.stereoStrongLeft = stereoData.strongLeft; volLeft = gDefaultPanVolume[pan]; volRight = gDefaultPanVolume[0x7F - pan]; } @@ -95,15 +100,15 @@ void AudioPlayback_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* at vel = 0.0f > vel ? 0.0f : vel; vel = 1.0f < vel ? 1.0f : vel; - sub->targetVolLeft = (s32)((vel * volLeft) * (0x1000 - 0.001f)); - sub->targetVolRight = (s32)((vel * volRight) * (0x1000 - 0.001f)); + noteSubEu->targetVolLeft = (s32)((vel * volLeft) * (0x1000 - 0.001f)); + noteSubEu->targetVolRight = (s32)((vel * volRight) * (0x1000 - 0.001f)); - sub->gain = attrs->gain; - sub->filter = attrs->filter; - sub->unk_07 = attrs->unk_14; - sub->unk_0E = attrs->unk_16; - sub->reverbVol = reverbVol; - sub->unk_19 = attrs->unk_3; + noteSubEu->gain = subAttrs->gain; + noteSubEu->filter = subAttrs->filter; + noteSubEu->unk_07 = subAttrs->unk_14; + noteSubEu->unk_0E = subAttrs->unk_16; + noteSubEu->reverbVol = reverbVol; + noteSubEu->unk_19 = subAttrs->unk_3; } void AudioPlayback_NoteSetResamplingRate(NoteSubEu* noteSubEu, f32 resamplingRateInput) { @@ -133,7 +138,7 @@ void AudioPlayback_NoteInit(Note* note) { ¬e->playbackState.adsrVolScaleUnused); } - note->playbackState.unk_04 = 0; + note->playbackState.status = PLAYBACK_STATUS_0; note->playbackState.adsr.action.s.state = ADSR_STATE_INITIAL; note->noteSubEu = gDefaultNoteSub; } @@ -144,7 +149,7 @@ void AudioPlayback_NoteDisable(Note* note) { } note->playbackState.priority = 0; note->noteSubEu.bitField0.enabled = false; - note->playbackState.unk_04 = 0; + note->playbackState.status = PLAYBACK_STATUS_0; note->noteSubEu.bitField0.finished = false; note->playbackState.parentLayer = NO_LAYER; note->playbackState.prevParentLayer = NO_LAYER; @@ -154,7 +159,7 @@ void AudioPlayback_NoteDisable(Note* note) { void AudioPlayback_ProcessNotes(void) { s32 pad; - s32 unk_04; + s32 playbackStatus; NoteAttributes* attrs; NoteSubEu* noteSubEu2; NoteSubEu* noteSubEu; @@ -174,19 +179,19 @@ void AudioPlayback_ProcessNotes(void) { continue; } - if (note != playbackState->parentLayer->note && playbackState->unk_04 == 0) { + if ((note != playbackState->parentLayer->note) && (playbackState->status == PLAYBACK_STATUS_0)) { playbackState->adsr.action.s.release = true; playbackState->adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; playbackState->priority = 1; - playbackState->unk_04 = 2; + playbackState->status = PLAYBACK_STATUS_2; goto out; - } else if (!playbackState->parentLayer->enabled && playbackState->unk_04 == 0 && - playbackState->priority >= 1) { + } else if (!playbackState->parentLayer->enabled && (playbackState->status == PLAYBACK_STATUS_0) && + (playbackState->priority >= 1)) { // do nothing } else if (playbackState->parentLayer->channel->seqPlayer == NULL) { AudioSeq_SequenceChannelDisable(playbackState->parentLayer->channel); playbackState->priority = 1; - playbackState->unk_04 = 1; + playbackState->status = PLAYBACK_STATUS_1; continue; } else if (playbackState->parentLayer->channel->seqPlayer->muted && (playbackState->parentLayer->channel->muteFlags & MUTE_FLAGS_STOP_NOTES)) { @@ -199,8 +204,8 @@ void AudioPlayback_ProcessNotes(void) { AudioPlayback_AudioListRemove(¬e->listItem); AudioPlayback_AudioListPushFront(¬e->listItem.pool->decaying, ¬e->listItem); playbackState->priority = 1; - playbackState->unk_04 = 2; - } else if (playbackState->unk_04 == 0 && playbackState->priority >= 1) { + playbackState->status = PLAYBACK_STATUS_2; + } else if ((playbackState->status == PLAYBACK_STATUS_0) && (playbackState->priority >= 1)) { continue; } @@ -208,8 +213,8 @@ void AudioPlayback_ProcessNotes(void) { if (playbackState->priority != 0) { if (1) {} noteSubEu = ¬e->noteSubEu; - if (playbackState->unk_04 >= 1 || noteSubEu->bitField0.finished) { - if (playbackState->adsr.action.s.state == ADSR_STATE_DISABLED || noteSubEu->bitField0.finished) { + if ((playbackState->status >= 1) || noteSubEu->bitField0.finished) { + if ((playbackState->adsr.action.s.state == ADSR_STATE_DISABLED) || noteSubEu->bitField0.finished) { if (playbackState->wantedParentLayer != NO_LAYER) { AudioPlayback_NoteDisable(note); if (playbackState->wantedParentLayer->channel != NULL) { @@ -249,9 +254,9 @@ void AudioPlayback_ProcessNotes(void) { scale = AudioEffects_AdsrUpdate(&playbackState->adsr); AudioEffects_NoteVibratoUpdate(note); - unk_04 = playbackState->unk_04; + playbackStatus = playbackState->status; attrs = &playbackState->attributes; - if (unk_04 == 1 || unk_04 == 2) { + if ((playbackStatus == PLAYBACK_STATUS_1) || (playbackStatus == PLAYBACK_STATUS_2)) { subAttrs.frequency = attrs->freqScale; subAttrs.velocity = attrs->velocity; subAttrs.pan = attrs->pan; @@ -317,17 +322,18 @@ void AudioPlayback_ProcessNotes(void) { } } -SoundFontSound* AudioPlayback_InstrumentGetSound(Instrument* instrument, s32 semitone) { - SoundFontSound* sound; +TunedSample* AudioPlayback_GetInstrumentTunedSample(Instrument* instrument, s32 semitone) { + TunedSample* tunedSample; if (semitone < instrument->normalRangeLo) { - sound = &instrument->lowNotesSound; + tunedSample = &instrument->lowPitchTunedSample; } else if (semitone <= instrument->normalRangeHi) { - sound = &instrument->normalNotesSound; + tunedSample = &instrument->normalPitchTunedSample; } else { - sound = &instrument->highNotesSound; + tunedSample = &instrument->highPitchTunedSample; } - return sound; + + return tunedSample; } Instrument* AudioPlayback_GetInstrumentInner(s32 fontId, s32 instId) { @@ -338,18 +344,18 @@ Instrument* AudioPlayback_GetInstrumentInner(s32 fontId, s32 instId) { } if (!AudioLoad_IsFontLoadComplete(fontId)) { - gAudioContext.audioErrorFlags = fontId + 0x10000000; + gAudioContext.audioErrorFlags = AUDIO_ERROR(0, fontId, AUDIO_ERROR_FONT_NOT_LOADED); return NULL; } - if (instId >= gAudioContext.soundFonts[fontId].numInstruments) { - gAudioContext.audioErrorFlags = ((fontId << 8) + instId) + 0x3000000; + if (instId >= gAudioContext.soundFontList[fontId].numInstruments) { + gAudioContext.audioErrorFlags = AUDIO_ERROR(fontId, instId, AUDIO_ERROR_INVALID_INST_ID); return NULL; } - inst = gAudioContext.soundFonts[fontId].instruments[instId]; + inst = gAudioContext.soundFontList[fontId].instruments[instId]; if (inst == NULL) { - gAudioContext.audioErrorFlags = ((fontId << 8) + instId) + 0x1000000; + gAudioContext.audioErrorFlags = AUDIO_ERROR(fontId, instId, AUDIO_ERROR_NO_INST); return inst; } @@ -364,58 +370,58 @@ Drum* AudioPlayback_GetDrum(s32 fontId, s32 drumId) { } if (!AudioLoad_IsFontLoadComplete(fontId)) { - gAudioContext.audioErrorFlags = fontId + 0x10000000; + gAudioContext.audioErrorFlags = AUDIO_ERROR(0, fontId, AUDIO_ERROR_FONT_NOT_LOADED); return NULL; } - if (drumId >= gAudioContext.soundFonts[fontId].numDrums) { - gAudioContext.audioErrorFlags = ((fontId << 8) + drumId) + 0x4000000; + if (drumId >= gAudioContext.soundFontList[fontId].numDrums) { + gAudioContext.audioErrorFlags = AUDIO_ERROR(fontId, drumId, AUDIO_ERROR_INVALID_DRUM_SFX_ID); return NULL; } - if ((u32)gAudioContext.soundFonts[fontId].drums < 0x80000000) { + if ((u32)gAudioContext.soundFontList[fontId].drums < AUDIO_RELOCATED_ADDRESS_START) { return NULL; } - drum = gAudioContext.soundFonts[fontId].drums[drumId]; + drum = gAudioContext.soundFontList[fontId].drums[drumId]; if (drum == NULL) { - gAudioContext.audioErrorFlags = ((fontId << 8) + drumId) + 0x5000000; + gAudioContext.audioErrorFlags = AUDIO_ERROR(fontId, drumId, AUDIO_ERROR_NO_DRUM_SFX); } return drum; } -SoundFontSound* AudioPlayback_GetSfx(s32 fontId, s32 sfxId) { - SoundFontSound* sfx; +SoundEffect* AudioPlayback_GetSoundEffect(s32 fontId, s32 sfxId) { + SoundEffect* soundEffect; if (fontId == 0xFF) { return NULL; } if (!AudioLoad_IsFontLoadComplete(fontId)) { - gAudioContext.audioErrorFlags = fontId + 0x10000000; + gAudioContext.audioErrorFlags = AUDIO_ERROR(0, fontId, AUDIO_ERROR_FONT_NOT_LOADED); return NULL; } - if (sfxId >= gAudioContext.soundFonts[fontId].numSfx) { - gAudioContext.audioErrorFlags = ((fontId << 8) + sfxId) + 0x4000000; + if (sfxId >= gAudioContext.soundFontList[fontId].numSfx) { + gAudioContext.audioErrorFlags = AUDIO_ERROR(fontId, sfxId, AUDIO_ERROR_INVALID_DRUM_SFX_ID); return NULL; } - if ((u32)gAudioContext.soundFonts[fontId].soundEffects < 0x80000000) { + if ((u32)gAudioContext.soundFontList[fontId].soundEffects < AUDIO_RELOCATED_ADDRESS_START) { return NULL; } - sfx = &gAudioContext.soundFonts[fontId].soundEffects[sfxId]; + soundEffect = &gAudioContext.soundFontList[fontId].soundEffects[sfxId]; - if (sfx == NULL) { - gAudioContext.audioErrorFlags = ((fontId << 8) + sfxId) + 0x5000000; + if (soundEffect == NULL) { + gAudioContext.audioErrorFlags = AUDIO_ERROR(fontId, sfxId, AUDIO_ERROR_NO_DRUM_SFX); } - if (sfx->sample == NULL) { + if (soundEffect->tunedSample.sample == NULL) { return NULL; } - return sfx; + return soundEffect; } s32 AudioPlayback_SetFontInstrument(s32 instrumentType, s32 fontId, s32 index, void* value) { @@ -429,24 +435,24 @@ s32 AudioPlayback_SetFontInstrument(s32 instrumentType, s32 fontId, s32 index, v switch (instrumentType) { case 0: - if (index >= gAudioContext.soundFonts[fontId].numDrums) { + if (index >= gAudioContext.soundFontList[fontId].numDrums) { return -3; } - gAudioContext.soundFonts[fontId].drums[index] = value; + gAudioContext.soundFontList[fontId].drums[index] = value; break; case 1: - if (index >= gAudioContext.soundFonts[fontId].numSfx) { + if (index >= gAudioContext.soundFontList[fontId].numSfx) { return -3; } - gAudioContext.soundFonts[fontId].soundEffects[index] = *(SoundFontSound*)value; + gAudioContext.soundFontList[fontId].soundEffects[index] = *(SoundEffect*)value; break; default: - if (index >= gAudioContext.soundFonts[fontId].numInstruments) { + if (index >= gAudioContext.soundFontList[fontId].numInstruments) { return -3; } - gAudioContext.soundFonts[fontId].instruments[index] = value; + gAudioContext.soundFontList[fontId].instruments[index] = value; break; } @@ -456,7 +462,7 @@ s32 AudioPlayback_SetFontInstrument(s32 instrumentType, s32 fontId, s32 index, v void AudioPlayback_SeqLayerDecayRelease(SequenceLayer* layer, s32 target) { Note* note; NoteAttributes* attrs; - SequenceChannel* chan; + SequenceChannel* channel; s32 i; if (layer == NO_LAYER) { @@ -491,27 +497,27 @@ void AudioPlayback_SeqLayerDecayRelease(SequenceLayer* layer, s32 target) { attrs->pan = layer->notePan; if (layer->channel != NULL) { - chan = layer->channel; + channel = layer->channel; if (layer->unk_0A.s.bit_2 == 1) { - attrs->reverb = chan->reverb; + attrs->reverb = channel->reverb; } else { attrs->reverb = layer->unk_09; } if (layer->unk_08 == 0x80) { - attrs->unk_3 = chan->unk_10; + attrs->unk_3 = channel->unk_10; } else { attrs->unk_3 = layer->unk_08; } if (layer->unk_0A.s.bit_9 == 1) { - attrs->gain = chan->gain; + attrs->gain = channel->gain; } else { attrs->gain = 0; } - attrs->filter = chan->filter; + attrs->filter = channel->filter; if (attrs->filter != NULL) { for (i = 0; i < 8; i++) { @@ -520,18 +526,18 @@ void AudioPlayback_SeqLayerDecayRelease(SequenceLayer* layer, s32 target) { attrs->filter = attrs->filterBuf; } - attrs->unk_6 = chan->unk_20; - attrs->unk_4 = chan->unk_0F; - if (chan->seqPlayer->muted && (chan->muteFlags & MUTE_FLAGS_3)) { + attrs->unk_6 = channel->unk_20; + attrs->unk_4 = channel->unk_0F; + if (channel->seqPlayer->muted && (channel->muteFlags & MUTE_FLAGS_3)) { note->noteSubEu.bitField0.finished = true; } if (layer->stereo.asByte == 0) { - attrs->stereo = chan->stereo; + attrs->stereo = channel->stereo; } else { attrs->stereo = layer->stereo; } - note->playbackState.priority = chan->someOtherPriority; + note->playbackState.priority = channel->someOtherPriority; } else { attrs->stereo = layer->stereo; note->playbackState.priority = 1; @@ -542,9 +548,9 @@ void AudioPlayback_SeqLayerDecayRelease(SequenceLayer* layer, s32 target) { if (target == ADSR_STATE_RELEASE) { note->playbackState.adsr.fadeOutVel = gAudioContext.audioBufferParameters.updatesPerFrameInv; note->playbackState.adsr.action.s.release = true; - note->playbackState.unk_04 = 2; + note->playbackState.status = PLAYBACK_STATUS_2; } else { - note->playbackState.unk_04 = 1; + note->playbackState.status = PLAYBACK_STATUS_1; note->playbackState.adsr.action.s.decay = true; if (layer->adsr.decayIndex == 0) { note->playbackState.adsr.fadeOutVel = gAudioContext.adsrDecayTable[layer->channel->adsr.decayIndex]; @@ -570,10 +576,18 @@ void AudioPlayback_SeqLayerNoteRelease(SequenceLayer* layer) { AudioPlayback_SeqLayerDecayRelease(layer, ADSR_STATE_RELEASE); } +/** + * Extract the synthetic wave to use from gWaveSamples and update corresponding frequencies + * + * @param note + * @param layer + * @param waveId the index of the type of synthetic wave to use, offset by 128 + * @return harmonicIndex, the index of the harmonic for the synthetic wave contained in gWaveSamples + */ s32 AudioPlayback_BuildSyntheticWave(Note* note, SequenceLayer* layer, s32 waveId) { f32 freqScale; - f32 ratio; - u8 sampleCountIndex; + f32 freqRatio; + u8 harmonicIndex; if (waveId < 128) { waveId = 128; @@ -583,42 +597,48 @@ s32 AudioPlayback_BuildSyntheticWave(Note* note, SequenceLayer* layer, s32 waveI if (layer->portamento.mode != 0 && 0.0f < layer->portamento.extent) { freqScale *= (layer->portamento.extent + 1.0f); } + + // Map frequency to the harmonic to use from gWaveSamples if (freqScale < 0.99999f) { - sampleCountIndex = 0; - ratio = 1.0465f; + harmonicIndex = 0; + freqRatio = 1.0465f; } else if (freqScale < 1.99999f) { - sampleCountIndex = 1; - ratio = 0.52325f; + harmonicIndex = 1; + freqRatio = 1.0465f / 2; } else if (freqScale < 3.99999f) { - sampleCountIndex = 2; - ratio = 0.26263f; + harmonicIndex = 2; + freqRatio = 1.0465f / 4 + 1.005E-3; } else { - sampleCountIndex = 3; - ratio = 0.13081f; + harmonicIndex = 3; + freqRatio = 1.0465f / 8 - 2.5E-6; } - layer->freqScale *= ratio; + + // Update results + layer->freqScale *= freqRatio; note->playbackState.waveId = waveId; - note->playbackState.sampleCountIndex = sampleCountIndex; + note->playbackState.harmonicIndex = harmonicIndex; - note->noteSubEu.sound.samples = &gWaveSamples[waveId - 128][sampleCountIndex * 64]; + // Save the pointer to the synthethic wave + // waveId index starts at 128, there are WAVE_SAMPLE_COUNT samples to read from + note->noteSubEu.waveSampleAddr = &gWaveSamples[waveId - 128][harmonicIndex * WAVE_SAMPLE_COUNT]; - return sampleCountIndex; + return harmonicIndex; } void AudioPlayback_InitSyntheticWave(Note* note, SequenceLayer* layer) { - s32 sampleCountIndex; - s32 waveSampleCountIndex; + s32 prevHarmonicIndex; + s32 curHarmonicIndex; s32 waveId = layer->instOrWave; if (waveId == 0xFF) { waveId = layer->channel->instOrWave; } - sampleCountIndex = note->playbackState.sampleCountIndex; - waveSampleCountIndex = AudioPlayback_BuildSyntheticWave(note, layer, waveId); + prevHarmonicIndex = note->playbackState.harmonicIndex; + curHarmonicIndex = AudioPlayback_BuildSyntheticWave(note, layer, waveId); - if (waveSampleCountIndex != sampleCountIndex) { - note->noteSubEu.unk_06 = waveSampleCountIndex * 4 + sampleCountIndex; + if (curHarmonicIndex != prevHarmonicIndex) { + note->noteSubEu.harmonicIndexCurAndPrev = (curHarmonicIndex << 2) + prevHarmonicIndex; } } @@ -805,7 +825,7 @@ void AudioPlayback_NoteInitForLayer(Note* note, SequenceLayer* layer) { if (instId == 0xFF) { instId = channel->instOrWave; } - noteSubEu->sound.soundFontSound = layer->sound; + noteSubEu->tunedSample = layer->tunedSample; if (instId >= 0x80 && instId < 0xC0) { noteSubEu->bitField1.isSyntheticWave = true; @@ -815,12 +835,12 @@ void AudioPlayback_NoteInitForLayer(Note* note, SequenceLayer* layer) { if (noteSubEu->bitField1.isSyntheticWave) { AudioPlayback_BuildSyntheticWave(note, layer, instId); - } else if (channel->unk_DC == 1) { - playbackState->unk_84 = noteSubEu->sound.soundFontSound->sample->loop->start; + } else if (channel->startSamplePos == 1) { + playbackState->startSamplePos = noteSubEu->tunedSample->sample->loop->start; } else { - playbackState->unk_84 = channel->unk_DC; - if (playbackState->unk_84 >= noteSubEu->sound.soundFontSound->sample->loop->end) { - playbackState->unk_84 = 0; + playbackState->startSamplePos = channel->startSamplePos; + if (playbackState->startSamplePos >= noteSubEu->tunedSample->sample->loop->end) { + playbackState->startSamplePos = 0; } } @@ -969,7 +989,7 @@ void AudioPlayback_NoteInitAll(void) { note = &gAudioContext.notes[i]; note->noteSubEu = gZeroNoteSub; note->playbackState.priority = 0; - note->playbackState.unk_04 = 0; + note->playbackState.status = PLAYBACK_STATUS_0; note->playbackState.parentLayer = NO_LAYER; note->playbackState.wantedParentLayer = NO_LAYER; note->playbackState.prevParentLayer = NO_LAYER; @@ -981,7 +1001,7 @@ void AudioPlayback_NoteInitAll(void) { note->playbackState.portamento.cur = 0; note->playbackState.portamento.speed = 0; note->playbackState.stereoHeadsetEffects = false; - note->playbackState.unk_84 = 0; + note->playbackState.startSamplePos = 0; note->synthesisState.synthesisBuffers = AudioHeap_AllocDmaMemory(&gAudioContext.miscPool, 0x2E0); note->playbackState.attributes.filterBuf = AudioHeap_AllocDmaMemory(&gAudioContext.miscPool, 0x10); } diff --git a/src/code/audio/audio_seqplayer.c b/src/code/audio/audio_seqplayer.c index ebcc9a8d1c..ea5c5ed5e4 100644 --- a/src/code/audio/audio_seqplayer.c +++ b/src/code/audio/audio_seqplayer.c @@ -33,7 +33,7 @@ u8 AudioSeq_ScriptReadU8(SeqScriptState* state); s16 AudioSeq_ScriptReadS16(SeqScriptState* state); u16 AudioSeq_ScriptReadCompressedU16(SeqScriptState* state); void AudioSeq_SeqLayerProcessScriptStep1(SequenceLayer* layer); -s32 AudioSeq_SeqLayerProcessScriptStep5(SequenceLayer* layer, s32 sameSound); +s32 AudioSeq_SeqLayerProcessScriptStep5(SequenceLayer* layer, s32 sameTunedSample); s32 AudioSeq_SeqLayerProcessScriptStep2(SequenceLayer* layer); s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd); s32 AudioSeq_SeqLayerProcessScriptStep3(SequenceLayer* layer, s32 cmd); @@ -320,7 +320,7 @@ void AudioSeq_InitSequenceChannel(SequenceChannel* channel) { channel->unused = false; AudioPlayback_InitNoteLists(&channel->notePool); - channel->unk_DC = 0; + channel->startSamplePos = 0; channel->unk_E0 = 0; channel->sfxState = NULL; } @@ -582,7 +582,7 @@ void AudioSeq_SeqLayerProcessScript(SequenceLayer* layer) { } while ((cmd == -1) && (layer->delay == 0)); if (cmd != PROCESS_SCRIPT_END) { - // returns `sameSound` instead of a command + // returns `sameTunedSample` instead of a command cmd = AudioSeq_SeqLayerProcessScriptStep4(layer, cmd); } @@ -611,20 +611,20 @@ void AudioSeq_SeqLayerProcessScriptStep1(SequenceLayer* layer) { layer->notePropertiesNeedInit = true; } -s32 AudioSeq_SeqLayerProcessScriptStep5(SequenceLayer* layer, s32 sameSound) { +s32 AudioSeq_SeqLayerProcessScriptStep5(SequenceLayer* layer, s32 sameTunedSample) { Note* note; if ((layer->continuousNotes == true) && (layer->bit1 == true)) { return 0; } - if ((layer->continuousNotes == true) && (layer->note != NULL) && layer->bit3 && (sameSound == true) && + if ((layer->continuousNotes == true) && (layer->note != NULL) && layer->bit3 && (sameTunedSample == true) && (layer->note->playbackState.parentLayer == layer)) { - if (layer->sound == NULL) { + if (layer->tunedSample == NULL) { AudioPlayback_InitSyntheticWave(layer->note, layer); } } else { - if (!sameSound) { + if (!sameTunedSample) { AudioPlayback_SeqLayerNoteDecay(layer); } @@ -815,7 +815,7 @@ s32 AudioSeq_SeqLayerProcessScriptStep2(SequenceLayer* layer) { } s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) { - s32 sameSound = true; + s32 sameTunedSample = true; s32 instOrWave; s32 speed; f32 temp_f14; @@ -823,10 +823,10 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) { Portamento* portamento; f32 freqScale; f32 freqScale2; - SoundFontSound* sound; + TunedSample* tunedSample; Instrument* instrument; Drum* drum; - s32 pad; + SoundEffect* soundEffect; SequenceChannel* channel; SequencePlayer* seqPlayer; u8 semitone = cmd; @@ -861,15 +861,15 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) { return PROCESS_SCRIPT_END; } - sound = &drum->sound; + tunedSample = &drum->tunedSample; layer->adsr.envelope = drum->envelope; layer->adsr.decayIndex = drum->adsrDecayIndex; if (!layer->ignoreDrumPan) { layer->pan = drum->pan; } - layer->sound = sound; - layer->freqScale = sound->tuning; + layer->tunedSample = tunedSample; + layer->freqScale = tunedSample->tuning; break; case 1: @@ -877,15 +877,16 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) { layer->semitone = semitone; sfxId = (layer->transposition << 6) + semitone; - sound = AudioPlayback_GetSfx(channel->fontId, sfxId); - if (sound == NULL) { + soundEffect = AudioPlayback_GetSoundEffect(channel->fontId, sfxId); + if (soundEffect == NULL) { layer->stopSomething = true; layer->delay2 = layer->delay + 1; return PROCESS_SCRIPT_END; } - layer->sound = sound; - layer->freqScale = sound->tuning; + tunedSample = &soundEffect->tunedSample; + layer->tunedSample = tunedSample; + layer->freqScale = tunedSample->tuning; break; default: @@ -909,15 +910,15 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) { vel = (semitone > layer->portamentoTargetNote) ? semitone : layer->portamentoTargetNote; if (instrument != NULL) { - sound = AudioPlayback_InstrumentGetSound(instrument, vel); - sameSound = (layer->sound == sound); - layer->sound = sound; - tuning = sound->tuning; + tunedSample = AudioPlayback_GetInstrumentTunedSample(instrument, vel); + sameTunedSample = (layer->tunedSample == tunedSample); + layer->tunedSample = tunedSample; + tuning = tunedSample->tuning; } else { - layer->sound = NULL; + layer->tunedSample = NULL; tuning = 1.0f; if (instOrWave >= 0xC0) { - layer->sound = &gAudioContext.synthesisReverbs[instOrWave - 0xC0].sound; + layer->tunedSample = &gAudioContext.synthesisReverbs[instOrWave - 0xC0].tunedSample; } } @@ -971,15 +972,15 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) { } if (instrument != NULL) { - sound = AudioPlayback_InstrumentGetSound(instrument, semitone); - sameSound = (sound == layer->sound); - layer->sound = sound; - layer->freqScale = gPitchFrequencies[semitone2] * sound->tuning; + tunedSample = AudioPlayback_GetInstrumentTunedSample(instrument, semitone); + sameTunedSample = (tunedSample == layer->tunedSample); + layer->tunedSample = tunedSample; + layer->freqScale = gPitchFrequencies[semitone2] * tunedSample->tuning; } else { - layer->sound = NULL; + layer->tunedSample = NULL; layer->freqScale = gPitchFrequencies[semitone2]; if (instOrWave >= 0xC0) { - layer->sound = &gAudioContext.synthesisReverbs[instOrWave - 0xC0].sound; + layer->tunedSample = &gAudioContext.synthesisReverbs[instOrWave - 0xC0].tunedSample; } } break; @@ -989,8 +990,8 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) { layer->freqScale *= layer->bend; if (layer->delay == 0) { - if (layer->sound != NULL) { - time = layer->sound->sample->loop->end; + if (layer->tunedSample != NULL) { + time = layer->tunedSample->sample->loop->end; } else { time = 0.0f; } @@ -1020,7 +1021,7 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) { } } } - return sameSound; + return sameTunedSample; } s32 AudioSeq_SeqLayerProcessScriptStep3(SequenceLayer* layer, s32 cmd) { @@ -1571,7 +1572,7 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) { channel->unk_0F = 0; channel->unk_20 = 0; channel->bookOffset = 0; - channel->unk_DC = 0; + channel->startSamplePos = 0; channel->unk_E0 = 0; channel->freqScale = 1.0f; break; @@ -1659,7 +1660,7 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) { break; case 0xBD: // channel: - channel->unk_DC = cmdArgs[0]; + channel->startSamplePos = cmdArgs[0]; break; case 0xBE: // channel: @@ -1672,10 +1673,10 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) { } break; - case 0xA0: // channel: - case 0xA1: // channel: - case 0xA2: // channel: - case 0xA3: // channel: + case 0xA0: // channel: read from SfxChannelState using arg + case 0xA1: // channel: read from SfxChannelState using unk_22 + case 0xA2: // channel: write to SfxChannelState using arg + case 0xA3: // channel: write to SfxChannelState using unk_22 if ((cmd == 0xA0) || (cmd == 0xA2)) { cmdArgU16 = (u16)cmdArgs[0]; } else { @@ -1958,15 +1959,15 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) { cmd = AudioSeq_ScriptReadU8(seqScript); temp = AudioSeq_ScriptReadS16(seqScript); switch (cmd) { - case 0: - case 1: - if (seqPlayer->state != 2) { + case SEQPLAYER_STATE_0: + case SEQPLAYER_STATE_1: + if (seqPlayer->state != SEQPLAYER_STATE_2) { seqPlayer->fadeTimerUnkEu = temp; seqPlayer->state = cmd; } break; - case 2: + case SEQPLAYER_STATE_2: seqPlayer->fadeTimer = temp; seqPlayer->state = cmd; seqPlayer->fadeVelocity = (0.0f - seqPlayer->fadeVolume) / (s32)seqPlayer->fadeTimer; @@ -1977,11 +1978,11 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) { case 0xDB: // seqPlayer: set volume value = AudioSeq_ScriptReadU8(seqScript); switch (seqPlayer->state) { - case 1: - seqPlayer->state = 0; + case SEQPLAYER_STATE_1: + seqPlayer->state = SEQPLAYER_STATE_0; seqPlayer->fadeVolume = 0.0f; // fallthrough - case 0: + case SEQPLAYER_STATE_0: seqPlayer->fadeTimer = seqPlayer->fadeTimerUnkEu; if (seqPlayer->fadeTimerUnkEu != 0) { seqPlayer->fadeVelocity = @@ -1991,7 +1992,7 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) { } break; - case 2: + case SEQPLAYER_STATE_2: break; } break; @@ -2102,7 +2103,7 @@ void AudioSeq_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) { cmd = AudioSeq_ScriptReadU8(seqScript); if (cmd == 0xFF) { cmd = seqPlayer->playerIndex; - if (seqPlayer->state == 2) { + if (seqPlayer->state == SEQPLAYER_STATE_2) { break; } } @@ -2224,7 +2225,7 @@ void AudioSeq_ResetSequencePlayer(SequencePlayer* seqPlayer) { AudioSeq_SequencePlayerDisable(seqPlayer); seqPlayer->stopScript = false; seqPlayer->delay = 0; - seqPlayer->state = 1; + seqPlayer->state = SEQPLAYER_STATE_1; seqPlayer->fadeTimer = 0; seqPlayer->fadeTimerUnkEu = 0; seqPlayer->tempoAcc = 0; diff --git a/src/overlays/actors/ovl_Boss_03/z_boss_03.c b/src/overlays/actors/ovl_Boss_03/z_boss_03.c index 380ef6f0b4..1c14d63bb1 100644 --- a/src/overlays/actors/ovl_Boss_03/z_boss_03.c +++ b/src/overlays/actors/ovl_Boss_03/z_boss_03.c @@ -53,6 +53,7 @@ * - Seaweed */ +#include "prevent_bss_reordering.h" #include "z_boss_03.h" #include "overlays/actors/ovl_Door_Warp1/z_door_warp1.h" #include "overlays/actors/ovl_En_Water_Effect/z_en_water_effect.h" diff --git a/src/overlays/actors/ovl_Obj_Flowerpot/z_obj_flowerpot.c b/src/overlays/actors/ovl_Obj_Flowerpot/z_obj_flowerpot.c index 73c5e32c6e..b699cd9afd 100644 --- a/src/overlays/actors/ovl_Obj_Flowerpot/z_obj_flowerpot.c +++ b/src/overlays/actors/ovl_Obj_Flowerpot/z_obj_flowerpot.c @@ -4,7 +4,6 @@ * Description: Breakable Pot With Grass */ -#include "prevent_bss_reordering.h" #include "z_obj_flowerpot.h" #include "objects/object_flowerpot/object_flowerpot.h" diff --git a/tools/disasm/functions.txt b/tools/disasm/functions.txt index 3699d01005..37515bb054 100644 --- a/tools/disasm/functions.txt +++ b/tools/disasm/functions.txt @@ -3546,8 +3546,8 @@ 0x8018A808:("func_8018A808",), 0x8018ACC4:("func_8018ACC4",), 0x8018AE34:("func_8018AE34",), - 0x8018B0F0:("func_8018B0F0",), - 0x8018B10C:("func_8018B10C",), + 0x8018B0F0:("AudioHeap_CalculateAdsrDecay",), + 0x8018B10C:("AudioHeap_InitAdsrDecayTable",), 0x8018B250:("AudioHeap_ResetLoadStatus",), 0x8018B318:("AudioHeap_DiscardFont",), 0x8018B3FC:("AudioHeap_ReleaseNotesForFont",), @@ -3560,16 +3560,16 @@ 0x8018B640:("AudioHeap_AllocZeroed",), 0x8018B69C:("AudioHeap_TestAlloc",), 0x8018B6E8:("AudioHeap_Alloc",), - 0x8018B740:("AudioHeap_AllocPoolInit",), - 0x8018B768:("AudioHeap_ClearPersistentCache",), - 0x8018B77C:("AudioHeap_ClearTemporaryCache",), + 0x8018B740:("AudioHeap_InitPool",), + 0x8018B768:("AudioHeap_InitPersistentCache",), + 0x8018B77C:("AudioHeap_InitTemporaryCache",), 0x8018B7AC:("AudioHeap_ResetPool",), - 0x8018B7BC:("AudioHeap_PopCache",), + 0x8018B7BC:("AudioHeap_PopPersistentCache",), 0x8018B8FC:("AudioHeap_InitMainPool",), 0x8018B95C:("AudioHeap_InitSessionPool",), 0x8018B9E0:("AudioHeap_InitCachePool",), - 0x8018BA64:("AudioHeap_InitPersistentCache",), - 0x8018BB28:("AudioHeap_InitTemporaryCache",), + 0x8018BA64:("AudioHeap_InitPersistentPoolsAndCaches",), + 0x8018BB28:("AudioHeap_InitTemporaryPoolsAndCaches",), 0x8018BBEC:("AudioHeap_AllocCached",), 0x8018C380:("AudioHeap_SearchCaches",), 0x8018C3D8:("AudioHeap_SearchRegularCaches",), @@ -3645,7 +3645,7 @@ 0x80190B08:("AudioLoad_ProcessLoads",), 0x80190B38:("AudioLoad_SetDmaHandler",), 0x80190B44:("AudioLoad_SetUnusedHandler",), - 0x80190B50:("AudioLoad_InitSoundFontMeta",), + 0x80190B50:("AudioLoad_InitSoundFont",), 0x80190BB0:("AudioLoad_Init",), 0x80190F50:("AudioLoad_InitSlowLoads",), 0x80190F64:("AudioLoad_SlowLoadSample",), @@ -3731,10 +3731,10 @@ 0x80194E60:("AudioPlayback_NoteInit",), 0x80194F20:("AudioPlayback_NoteDisable",), 0x80194F84:("AudioPlayback_ProcessNotes",), - 0x801954CC:("AudioPlayback_InstrumentGetSound",), + 0x801954CC:("AudioPlayback_GetInstrumentTunedSample",), 0x80195508:("AudioPlayback_GetInstrumentInner",), 0x801955DC:("AudioPlayback_GetDrum",), - 0x801956C0:("AudioPlayback_GetSfx",), + 0x801956C0:("AudioPlayback_GetSoundEffect",), 0x801957B4:("AudioPlayback_SetFontInstrument",), 0x801958F8:("AudioPlayback_SeqLayerDecayRelease",), 0x80195C40:("AudioPlayback_SeqLayerNoteDecay",), diff --git a/tools/disasm/variables.txt b/tools/disasm/variables.txt index dffd1bd190..86ab55c724 100644 --- a/tools/disasm/variables.txt +++ b/tools/disasm/variables.txt @@ -3814,7 +3814,7 @@ 0x801E10B0:("jtbl_801E10B0","UNK_PTR","",0x4), 0x801E10C4:("jtbl_801E10C4","UNK_PTR","",0x4), 0x801E1100:("gAudioTatumInit","s16","[2]",0x4), - 0x801E1104:("gAudioContextInitSizes","AudioContextInitSizes","",0xC), + 0x801E1104:("gAudioHeapInitSizes","AudioHeapInitSizes","",0xC), 0x801E1110:("sGameOverTimer","UNK_TYPE2","",0x2), 0x801E1120:("jtbl_801E1120","UNK_PTR","",0x4), 0x801E1180:("gSoundFontTable","UNK_TYPE2","",0x2), diff --git a/tools/sizes/code_functions.csv b/tools/sizes/code_functions.csv index 991b30fdfb..db8f76ef72 100644 --- a/tools/sizes/code_functions.csv +++ b/tools/sizes/code_functions.csv @@ -3076,16 +3076,16 @@ asm/non_matchings/code/audio_heap/AudioHeap_AllocDmaMemoryZeroed.s,AudioHeap_All asm/non_matchings/code/audio_heap/AudioHeap_AllocZeroed.s,AudioHeap_AllocZeroed,0x8018B640,0x17 asm/non_matchings/code/audio_heap/AudioHeap_TestAlloc.s,AudioHeap_TestAlloc,0x8018B69C,0x13 asm/non_matchings/code/audio_heap/Audio_Alloc.s,Audio_Alloc,0x8018B6E8,0x16 -asm/non_matchings/code/audio_heap/AudioHeap_AllocPoolInit.s,AudioHeap_AllocPoolInit,0x8018B740,0xA -asm/non_matchings/code/audio_heap/AudioHeap_ClearPersistentCache.s,AudioHeap_ClearPersistentCache,0x8018B768,0x5 -asm/non_matchings/code/audio_heap/AudioHeap_ClearTemporaryCache.s,AudioHeap_ClearTemporaryCache,0x8018B77C,0xC +asm/non_matchings/code/audio_heap/AudioHeap_InitPool.s,AudioHeap_InitPool,0x8018B740,0xA +asm/non_matchings/code/audio_heap/AudioHeap_InitPersistentCache.s,AudioHeap_InitPersistentCache,0x8018B768,0x5 +asm/non_matchings/code/audio_heap/AudioHeap_InitTemporaryCache.s,AudioHeap_InitTemporaryCache,0x8018B77C,0xC asm/non_matchings/code/audio_heap/AudioHeap_ResetPool.s,AudioHeap_ResetPool,0x8018B7AC,0x4 -asm/non_matchings/code/audio_heap/AudioHeap_PopCache.s,AudioHeap_PopCache,0x8018B7BC,0x50 +asm/non_matchings/code/audio_heap/AudioHeap_PopPersistentCache.s,AudioHeap_PopPersistentCache,0x8018B7BC,0x50 asm/non_matchings/code/audio_heap/AudioHeap_InitMainPool.s,AudioHeap_InitMainPool,0x8018B8FC,0x18 asm/non_matchings/code/audio_heap/AudioHeap_InitSessionPool.s,AudioHeap_InitSessionPool,0x8018B95C,0x21 asm/non_matchings/code/audio_heap/AudioHeap_InitCachePool.s,AudioHeap_InitCachePool,0x8018B9E0,0x21 -asm/non_matchings/code/audio_heap/AudioHeap_InitPersistentCache.s,AudioHeap_InitPersistentCache,0x8018BA64,0x31 -asm/non_matchings/code/audio_heap/AudioHeap_InitTemporaryCache.s,AudioHeap_InitTemporaryCache,0x8018BB28,0x31 +asm/non_matchings/code/audio_heap/AudioHeap_InitPersistentPoolsAndCaches.s,AudioHeap_InitPersistentPoolsAndCaches,0x8018BA64,0x31 +asm/non_matchings/code/audio_heap/AudioHeap_InitTemporaryPoolsAndCaches.s,AudioHeap_InitTemporaryPoolsAndCaches,0x8018BB28,0x31 asm/non_matchings/code/audio_heap/AudioHeap_AllocCached.s,AudioHeap_AllocCached,0x8018BBEC,0x1E5 asm/non_matchings/code/audio_heap/AudioHeap_SearchCaches.s,AudioHeap_SearchCaches,0x8018C380,0x16 asm/non_matchings/code/audio_heap/AudioHeap_SearchRegularCaches.s,AudioHeap_SearchRegularCaches,0x8018C3D8,0x43 @@ -3161,7 +3161,7 @@ asm/non_matchings/code/audio_load/AudioLoad_AsyncLoadInner.s,AudioLoad_AsyncLoad asm/non_matchings/code/audio_load/AudioLoad_ProcessLoads.s,AudioLoad_ProcessLoads,0x80190B08,0xC asm/non_matchings/code/audio_load/AudioLoad_SetDmaHandler.s,AudioLoad_SetDmaHandler,0x80190B38,0x3 asm/non_matchings/code/audio_load/AudioLoad_SetUnusedHandler.s,AudioLoad_SetUnusedHandler,0x80190B44,0x3 -asm/non_matchings/code/audio_load/AudioLoad_InitSoundFontMeta.s,AudioLoad_InitSoundFontMeta,0x80190B50,0x18 +asm/non_matchings/code/audio_load/AudioLoad_InitSoundFont.s,AudioLoad_InitSoundFont,0x80190B50,0x18 asm/non_matchings/code/audio_load/AudioLoad_Init.s,AudioLoad_Init,0x80190BB0,0xE8 asm/non_matchings/code/audio_load/AudioLoad_InitSlowLoads.s,AudioLoad_InitSlowLoads,0x80190F50,0x5 asm/non_matchings/code/audio_load/AudioLoad_SlowLoadSample.s,AudioLoad_SlowLoadSample,0x80190F64,0x74 @@ -3247,10 +3247,10 @@ asm/non_matchings/code/audio_playback/AudioPlayback_NoteSetResamplingRate.s,Audi asm/non_matchings/code/audio_playback/AudioPlayback_NoteInit.s,AudioPlayback_NoteInit,0x80194E60,0x30 asm/non_matchings/code/audio_playback/AudioPlayback_NoteDisable.s,AudioPlayback_NoteDisable,0x80194F20,0x19 asm/non_matchings/code/audio_playback/AudioPlayback_ProcessNotes.s,AudioPlayback_ProcessNotes,0x80194F84,0x152 -asm/non_matchings/code/audio_playback/AudioPlayback_InstrumentGetSound.s,AudioPlayback_InstrumentGetSound,0x801954CC,0xF +asm/non_matchings/code/audio_playback/AudioPlayback_GetInstrumentTunedSample.s,AudioPlayback_GetInstrumentTunedSample,0x801954CC,0xF asm/non_matchings/code/audio_playback/AudioPlayback_GetInstrumentInner.s,AudioPlayback_GetInstrumentInner,0x80195508,0x35 asm/non_matchings/code/audio_playback/AudioPlayback_GetDrum.s,AudioPlayback_GetDrum,0x801955DC,0x39 -asm/non_matchings/code/audio_playback/AudioPlayback_GetSfx.s,AudioPlayback_GetSfx,0x801956C0,0x3D +asm/non_matchings/code/audio_playback/AudioPlayback_GetSoundEffect.s,AudioPlayback_GetSoundEffect,0x801956C0,0x3D asm/non_matchings/code/audio_playback/AudioPlayback_SetFontInstrument.s,AudioPlayback_SetFontInstrument,0x801957B4,0x51 asm/non_matchings/code/audio_playback/AudioPlayback_SeqLayerDecayRelease.s,AudioPlayback_SeqLayerDecayRelease,0x801958F8,0xD2 asm/non_matchings/code/audio_playback/AudioPlayback_SeqLayerNoteDecay.s,AudioPlayback_SeqLayerNoteDecay,0x80195C40,0x8