From eb577e29e4ca049fc225314ef2b7e438879eb06a Mon Sep 17 00:00:00 2001 From: engineer124 <47598039+engineer124@users.noreply.github.com> Date: Fri, 9 Feb 2024 04:36:11 +1100 Subject: [PATCH] Introduce More Audio Headers (#1515) * 4 audio headers * local first * PR Review, more cleanup * more cleanup * fix bss * PR Review * PR Suggestions --- include/audio/heap.h | 22 +- include/audio/list.h | 43 ++++ include/audio/load.h | 32 ++- include/audio/playback.h | 139 +++++++++++ include/audio/reverb.h | 8 +- include/audio/seqplayer.h | 245 +++++++++++++++++++ include/audio/synthesis.h | 54 +++++ include/functions.h | 31 --- include/variables.h | 4 - include/z64audio.h | 428 +-------------------------------- src/audio/lib/heap.c | 7 +- src/audio/lib/load.c | 1 + src/audio/lib/playback.c | 101 ++++---- src/audio/lib/seqplayer.c | 31 +-- src/audio/lib/synthesis.c | 1 + tools/disasm/functions.txt | 20 +- tools/sizes/code_functions.csv | 20 +- 17 files changed, 622 insertions(+), 565 deletions(-) create mode 100644 include/audio/list.h create mode 100644 include/audio/playback.h create mode 100644 include/audio/seqplayer.h create mode 100644 include/audio/synthesis.h diff --git a/include/audio/heap.h b/include/audio/heap.h index 33f3dfcd94..2c4147dbc6 100644 --- a/include/audio/heap.h +++ b/include/audio/heap.h @@ -5,7 +5,7 @@ #include "libc/stddef.h" #include "unk.h" -typedef struct { +typedef struct AudioHeapInitSizes { /* 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 initPoolSize; // The entire audio heap is split into two pools. /* 0x8 */ size_t permanentPoolSize; @@ -14,7 +14,7 @@ typedef struct { /** * Meta-data associated with a pool (contain withing the Audio Heap) */ -typedef struct { +typedef struct AudioAllocPool { /* 0x0 */ u8* startAddr; // start addr of the pool /* 0x4 */ u8* curAddr; // address of the next available memory for allocation /* 0x8 */ size_t size; // size of the pool @@ -24,7 +24,7 @@ typedef struct { /** * Audio cache entry data to store a single entry containing either a sequence, soundfont, or entire sample banks */ -typedef struct { +typedef struct AudioCacheEntry { /* 0x0 */ u8* addr; /* 0x4 */ size_t size; /* 0x8 */ s16 tableType; @@ -34,7 +34,7 @@ typedef struct { /** * Audio cache entry data to store a single entry containing an individual sample */ -typedef struct { +typedef struct SampleCacheEntry { /* 0x00 */ s8 inUse; /* 0x01 */ s8 origMedium; /* 0x02 */ u8 sampleBankId; @@ -47,42 +47,42 @@ typedef struct { /** * Audio cache entry data to store individual samples */ -typedef struct { +typedef struct AudioSampleCache { /* 0x000 */ AudioAllocPool pool; /* 0x010 */ SampleCacheEntry entries[128]; /* 0xA10 */ s32 numEntries; } AudioSampleCache; // size = 0xA14 -typedef struct { +typedef struct AudioPersistentCache { /* 0x00 */ u32 numEntries; /* 0x04 */ AudioAllocPool pool; /* 0x14 */ AudioCacheEntry entries[16]; } AudioPersistentCache; // size = 0xD4 -typedef struct { +typedef struct AudioTemporaryCache { /* 0x00 */ u32 nextSide; /* 0x04 */ AudioAllocPool pool; /* 0x14 */ AudioCacheEntry entries[2]; } AudioTemporaryCache; // size = 0x3C -typedef struct { +typedef struct AudioCache { /* 0x000 */ AudioPersistentCache persistent; /* 0x0D4 */ AudioTemporaryCache temporary; /* 0x100 */ UNK_TYPE1 pad100[0x10]; } AudioCache; // size = 0x110 -typedef struct { +typedef struct AudioCachePoolSplit { /* 0x0 */ size_t persistentCommonPoolSize; /* 0x4 */ size_t temporaryCommonPoolSize; } AudioCachePoolSplit; // size = 0x8 -typedef struct { +typedef struct AudioCommonPoolSplit { /* 0x0 */ size_t seqCacheSize; /* 0x4 */ size_t fontCacheSize; /* 0x8 */ size_t sampleBankCacheSize; } AudioCommonPoolSplit; // size = 0xC -typedef struct { +typedef struct AudioSessionPoolSplit { /* 0x0 */ size_t miscPoolSize; /* 0x4 */ size_t unusedSizes[2]; /* 0xC */ size_t cachePoolSize; diff --git a/include/audio/list.h b/include/audio/list.h new file mode 100644 index 0000000000..0f05d86341 --- /dev/null +++ b/include/audio/list.h @@ -0,0 +1,43 @@ +#ifndef AUDIO_LIST_H +#define AUDIO_LIST_H + +#include "PR/ultratypes.h" + +// A node in a circularly linked list. Each node is either a head or an item: +// - Items can be either detached (prev = NULL), or attached to a list. +// 'value' points to something of interest. +// - List heads are always attached; if a list is empty, its head points +// to itself. 'count' contains the size of the list. +// If the list holds notes, 'pool' points back to the pool where it lives. +// Otherwise, that member is NULL. +typedef struct AudioListItem { + /* 0x0 */ struct AudioListItem* prev; + /* 0x4 */ struct AudioListItem* next; + union { + /* 0x8 */ void* value; // either Note* or SequenceLayer* + /* 0x8 */ s32 count; + } u; + /* 0xC */ struct NotePool* pool; +} AudioListItem; // size = 0x10 + +typedef struct NotePool { + /* 0x00 */ AudioListItem disabled; + /* 0x10 */ AudioListItem decaying; + /* 0x20 */ AudioListItem releasing; + /* 0x30 */ AudioListItem active; +} NotePool; // size = 0x40 + +// playback.c functions + +void AudioList_InitNoteLists(NotePool* pool); +void AudioList_InitNoteFreeList(void); +void AudioList_ClearNotePool(NotePool* pool); +void AudioList_FillNotePool(NotePool* pool, s32 count); +void AudioList_Remove(AudioListItem* item); + +// seqplayer.c functions + +void AudioList_PushBack(AudioListItem* list, AudioListItem* item); +void* AudioList_PopBack(AudioListItem* list); + +#endif diff --git a/include/audio/load.h b/include/audio/load.h index eccdc2db29..2952dee010 100644 --- a/include/audio/load.h +++ b/include/audio/load.h @@ -1,25 +1,23 @@ #ifndef AUDIO_LOAD_H #define AUDIO_LOAD_H -#include "audio/soundfont.h" +#include "soundfont.h" +#include "PR/os.h" +#include "PR/os_message.h" #include "PR/ultratypes.h" #include "libc/stddef.h" #include "libc/stdint.h" -#include "PR/os_message.h" #include "unk.h" -#include "PR/os.h" - -struct Sample; typedef s32 (*DmaHandler)(OSPiHandle* handle, OSIoMesg* mb, s32 direction); -typedef enum { +typedef enum SampleBankTableType { /* 0 */ SEQUENCE_TABLE, /* 1 */ FONT_TABLE, /* 2 */ SAMPLE_TABLE } SampleBankTableType; -typedef struct { +typedef struct AudioTableEntry { /* 0x0 */ uintptr_t romAddr; /* 0x4 */ size_t size; /* 0x8 */ s8 medium; @@ -29,7 +27,7 @@ typedef struct { /* 0xE */ s16 shortData3; } AudioTableEntry; // size = 0x10 -typedef struct { +typedef struct AudioTable { /* 0x00 */ s16 numEntries; /* 0x02 */ s16 unkMediumParam; /* 0x04 */ uintptr_t romAddr; @@ -37,7 +35,7 @@ typedef struct { /* 0x10 */ AudioTableEntry entries[1]; // (dynamic size) } AudioTable; // size >= 0x20 -typedef enum { +typedef enum AudioLoadStatus { /* 0 */ LOAD_STATUS_NOT_LOADED, /* 1 */ LOAD_STATUS_IN_PROGRESS, /* 2 */ LOAD_STATUS_COMPLETE, @@ -46,14 +44,14 @@ typedef enum { /* 5 */ LOAD_STATUS_PERMANENT } AudioLoadStatus; -typedef enum { +typedef enum AudioCacheType { /* 0 */ CACHE_TEMPORARY, /* 1 */ CACHE_PERSISTENT, /* 2 */ CACHE_EITHER, /* 3 */ CACHE_PERMANENT } AudioCacheType; -typedef enum { +typedef enum AudioCacheLoadType { /* 0 */ CACHE_LOAD_PERMANENT, /* 1 */ CACHE_LOAD_PERSISTENT, /* 2 */ CACHE_LOAD_TEMPORARY, @@ -61,7 +59,7 @@ typedef enum { /* 4 */ CACHE_LOAD_EITHER_NOSYNC } AudioCacheLoadType; -typedef struct { +typedef struct AudioAsyncLoad { /* 0x00 */ s8 status; /* 0x01 */ s8 delay; /* 0x02 */ s8 medium; @@ -78,7 +76,7 @@ typedef struct { /* 0x40 */ OSIoMesg ioMesg; } AudioAsyncLoad; // size = 0x58 -typedef struct { +typedef struct AudioSlowLoad { /* 0x00 */ u8 medium; /* 0x01 */ u8 seqOrFontId; /* 0x02 */ u16 instId; @@ -89,13 +87,13 @@ 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 */ struct Sample sample; + /* 0x20 */ Sample sample; /* 0x30 */ OSMesgQueue msgqueue; /* 0x48 */ OSMesg msg; /* 0x4C */ OSIoMesg ioMesg; } AudioSlowLoad; // size = 0x64 -typedef struct { +typedef struct SampleDma { /* 0x0 */ u8* ramAddr; /* 0x4 */ uintptr_t devAddr; /* 0x8 */ u16 sizeUnused; @@ -105,9 +103,9 @@ typedef struct { /* 0xE */ u8 ttl; // Time To Live: duration after which the DMA can be discarded } SampleDma; // size = 0x10 -typedef struct { +typedef struct AudioPreloadReq { /* 0x00 */ u32 endAndMediumKey; - /* 0x04 */ struct Sample* sample; + /* 0x04 */ Sample* sample; /* 0x08 */ u8* ramAddr; /* 0x0C */ u32 encodedInfo; /* 0x10 */ s32 isFree; diff --git a/include/audio/playback.h b/include/audio/playback.h new file mode 100644 index 0000000000..cd01bc61dc --- /dev/null +++ b/include/audio/playback.h @@ -0,0 +1,139 @@ +#ifndef AUDIO_PLAYBACK_H +#define AUDIO_PLAYBACK_H + +#include "synthesis.h" +#include "effects.h" +#include "list.h" +#include "PR/ultratypes.h" +#include "unk.h" + +struct SequenceLayer; +struct Instrument; +struct TunedSample; +struct Drum; +struct SoundEffect; + +#define AUDIO_ERROR(fontId, id, err) (((fontId << 8) + id) + (err << 24)) + +typedef enum AudioError { + /* 0x01 */ AUDIO_ERROR_NO_INST = 1, + /* 0x03 */ AUDIO_ERROR_INVALID_INST_ID = 3, + /* 0x04 */ AUDIO_ERROR_INVALID_DRUM_SFX_ID, + /* 0x05 */ AUDIO_ERROR_NO_DRUM_SFX, + /* 0x10 */ AUDIO_ERROR_FONT_NOT_LOADED = 0x10 +} AudioError; + +typedef union { + struct { + /* 0x0 */ u8 unused : 2; + /* 0x0 */ u8 type : 2; + /* 0x0 */ u8 strongRight : 1; + /* 0x0 */ u8 strongLeft : 1; + /* 0x0 */ u8 strongReverbRight : 1; + /* 0x0 */ u8 strongReverbLeft : 1; + }; + /* 0x0 */ u8 asByte; +} StereoData; // size = 0x1 + +typedef struct NoteAttributes { + /* 0x00 */ u8 targetReverbVol; + /* 0x01 */ u8 gain; // Increases volume by a multiplicative scaling factor. Represented as a UQ4.4 number + /* 0x02 */ u8 pan; + /* 0x03 */ u8 surroundEffectIndex; + /* 0x04 */ StereoData stereoData; + /* 0x05 */ u8 combFilterSize; + /* 0x06 */ u16 combFilterGain; + /* 0x08 */ f32 freqScale; + /* 0x0C */ f32 velocity; + /* 0x10 */ s16* filter; + /* 0x14 */ s16* filterBuf; +} NoteAttributes; // size = 0x18 + +typedef enum NotePlaybackStatus { + /* 0 */ PLAYBACK_STATUS_0, + /* 1 */ PLAYBACK_STATUS_1, + /* 2 */ PLAYBACK_STATUS_2 +} NotePlaybackStatus; + +typedef struct NotePlaybackState { + /* 0x00 */ u8 priority; + /* 0x01 */ u8 waveId; + /* 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 status; + /* 0x05 */ u8 stereoHeadsetEffects; + /* 0x06 */ s16 adsrVolScaleUnused; + /* 0x08 */ f32 portamentoFreqScale; + /* 0x0C */ f32 vibratoFreqScale; + /* 0x18 */ struct SequenceLayer* wantedParentLayer; + /* 0x14 */ struct SequenceLayer* parentLayer; + /* 0x10 */ struct SequenceLayer* prevParentLayer; + /* 0x1C */ NoteAttributes attributes; + /* 0x34 */ AdsrState adsr; + /* 0x54 */ Portamento portamento; + /* 0x60 */ VibratoState vibratoState; + /* 0x7C */ UNK_TYPE1 pad7C[0x4]; + /* 0x80 */ u8 unk_80; + /* 0x84 */ u32 startSamplePos; + /* 0x88 */ UNK_TYPE1 unk_BC[0x1C]; +} NotePlaybackState; // size = 0xA4 + +typedef struct NoteSampleState { + struct { + /* 0x00 */ vu8 enabled : 1; + /* 0x00 */ u8 needsInit : 1; + /* 0x00 */ u8 finished : 1; + /* 0x00 */ u8 unused : 1; + /* 0x00 */ u8 strongRight : 1; + /* 0x00 */ u8 strongLeft : 1; + /* 0x00 */ u8 strongReverbRight : 1; + /* 0x00 */ u8 strongReverbLeft : 1; + } bitField0; + struct { + /* 0x01 */ u8 reverbIndex : 3; + /* 0x01 */ u8 bookOffset : 2; + /* 0x01 */ u8 isSyntheticWave : 1; + /* 0x01 */ u8 hasTwoParts : 1; + /* 0x01 */ u8 useHaasEffect : 1; + } bitField1; + /* 0x02 */ u8 gain; // Increases volume by a multiplicative scaling factor. Represented as a UQ4.4 number + /* 0x03 */ u8 haasEffectLeftDelaySize; + /* 0x04 */ u8 haasEffectRightDelaySize; + /* 0x05 */ u8 targetReverbVol; + /* 0x06 */ u8 harmonicIndexCurAndPrev; // bits 3..2 store curHarmonicIndex, bits 1..0 store prevHarmonicIndex + /* 0x07 */ u8 combFilterSize; + /* 0x08 */ u16 targetVolLeft; + /* 0x0A */ u16 targetVolRight; + /* 0x0C */ u16 frequencyFixedPoint; + /* 0x0E */ u16 combFilterGain; + union { + /* 0x10 */ TunedSample* tunedSample; + /* 0x10 */ s16* waveSampleAddr; // used for synthetic waves + }; + /* 0x14 */ s16* filter; + /* 0x18 */ UNK_TYPE1 unk_18; + /* 0x19 */ u8 surroundEffectIndex; + /* 0x1A */ UNK_TYPE1 unk_1A[0x6]; +} NoteSampleState; // size = 0x20 + +typedef struct Note { + /* 0x00 */ AudioListItem listItem; + /* 0x10 */ NoteSynthesisState synthesisState; + /* 0x34 */ NotePlaybackState playbackState; + /* 0xD8 */ NoteSampleState sampleState; +} Note; // size = 0xF8 + +void AudioPlayback_NoteDisable(Note* note); +void AudioPlayback_ProcessNotes(void); +struct TunedSample* AudioPlayback_GetInstrumentTunedSample(struct Instrument* instrument, s32 semitone); +struct Instrument* AudioPlayback_GetInstrumentInner(s32 fontId, s32 instId); +struct Drum* AudioPlayback_GetDrum(s32 fontId, s32 drumId); +struct SoundEffect* AudioPlayback_GetSoundEffect(s32 fontId, s32 sfxId); +s32 AudioPlayback_SetFontInstrument(s32 instrumentType, s32 fontId, s32 index, void* value); +void AudioPlayback_SeqLayerNoteDecay(struct SequenceLayer* layer); +void AudioPlayback_SeqLayerNoteRelease(struct SequenceLayer* layer); +void AudioPlayback_InitSyntheticWave(Note* note, struct SequenceLayer* layer); +Note* AudioPlayback_AllocNote(struct SequenceLayer* layer); +void AudioPlayback_NoteInitAll(void); + +#endif diff --git a/include/audio/reverb.h b/include/audio/reverb.h index 83df3eed9f..6d10fc59a4 100644 --- a/include/audio/reverb.h +++ b/include/audio/reverb.h @@ -1,8 +1,8 @@ #ifndef AUDIO_REVERB_H #define AUDIO_REVERB_H +#include "soundfont.h" #include "PR/ultratypes.h" -#include "audio/soundfont.h" #define REVERB_INDEX_NONE -1 @@ -19,7 +19,7 @@ typedef enum ReverbDataType { /* 9 */ REVERB_DATA_TYPE_9 // Reverb Unk } ReverbDataType; -typedef struct { +typedef struct ReverbSettings { /* 0x00 */ u8 downsampleRate; /* 0x02 */ u16 delayNumSamples; /* 0x04 */ u16 decayRatio; // determines how fast reverb dissipates @@ -39,7 +39,7 @@ typedef struct { * By storing the sample in a ring buffer, the time it takes to loop * around back to the same sample acts as a delay, leading to an echo effect. */ -typedef struct { +typedef struct ReverbBufferEntry { /* 0x00 */ s16 numSamplesAfterDownsampling; // never read /* 0x02 */ s16 numSamples; // never read /* 0x04 */ s16* toDownsampleLeft; @@ -52,7 +52,7 @@ typedef struct { /* 0x18 */ u16 saveResampleNumSamples; } ReverbBufferEntry; // size = 0x1C -typedef struct { +typedef struct SynthesisReverb { /* 0x000 */ u8 resampleFlags; /* 0x001 */ u8 useReverb; /* 0x002 */ u8 framesToIgnore; diff --git a/include/audio/seqplayer.h b/include/audio/seqplayer.h new file mode 100644 index 0000000000..6e656f5cf6 --- /dev/null +++ b/include/audio/seqplayer.h @@ -0,0 +1,245 @@ +#ifndef AUDIO_SEQPLAYER_H +#define AUDIO_SEQPLAYER_H + +#include "effects.h" +#include "list.h" +#include "playback.h" +#include "PR/ultratypes.h" +#include "PR/abi.h" +#include "unk.h" + +struct Sample; +struct Instrument; +struct TunedSample; + +#define SEQ_NUM_CHANNELS 16 + +#define NO_LAYER ((SequenceLayer*)(-1)) + +#define TATUMS_PER_BEAT 48 + +#define IS_SEQUENCE_CHANNEL_VALID(ptr) ((uintptr_t)(ptr) != (uintptr_t)&gAudioCtx.sequenceChannelNone) +#define SEQ_IO_VAL_NONE -1 + +#define MUTE_FLAGS_STOP_SAMPLES (1 << 3) // prevent further noteSubEus from playing +#define MUTE_FLAGS_STOP_LAYER (1 << 4) // stop something in seqLayer scripts +#define MUTE_FLAGS_SOFTEN (1 << 5) // lower volume, by default to half +#define MUTE_FLAGS_STOP_NOTES (1 << 6) // prevent further notes from playing +#define MUTE_FLAGS_STOP_SCRIPT (1 << 7) // stop processing sequence/channel scripts + +typedef struct SeqScriptState { + /* 0x00 */ u8* pc; // program counter + /* 0x04 */ u8* stack[4]; + /* 0x14 */ u8 remLoopIters[4]; // remaining loop iterations + /* 0x18 */ u8 depth; + /* 0x19 */ s8 value; +} SeqScriptState; // size = 0x1C + +typedef enum SeqPlayerState { + /* 0 */ SEQPLAYER_STATE_0, + /* 1 */ SEQPLAYER_STATE_FADE_IN, + /* 2 */ SEQPLAYER_STATE_FADE_OUT +} SeqPlayerState; + +// Also known as a Group, according to debug strings. +typedef struct SequencePlayer { + /* 0x000 */ u8 enabled : 1; + /* 0x000 */ u8 finished : 1; + /* 0x000 */ u8 muted : 1; + /* 0x000 */ u8 seqDmaInProgress : 1; + /* 0x000 */ u8 fontDmaInProgress : 1; + /* 0x000 */ u8 recalculateVolume : 1; + /* 0x000 */ u8 stopScript : 1; + /* 0x000 */ u8 applyBend : 1; + /* 0x001 */ u8 state; + /* 0x002 */ u8 noteAllocPolicy; + /* 0x003 */ u8 muteFlags; + /* 0x004 */ u8 seqId; + /* 0x005 */ u8 defaultFont; + /* 0x006 */ u8 unk_06[1]; + /* 0x007 */ s8 playerIndex; + /* 0x008 */ u16 tempo; // tatums per minute + /* 0x00A */ u16 tempoAcc; + /* 0x00C */ s16 tempoChange; + /* 0x00E */ s16 transposition; + /* 0x010 */ u16 delay; + /* 0x012 */ u16 fadeTimer; + /* 0x014 */ u16 storedFadeTimer; + /* 0x016 */ u16 unk_16; + /* 0x018 */ u8* seqData; + /* 0x01C */ f32 fadeVolume; + /* 0x020 */ f32 fadeVelocity; + /* 0x024 */ f32 volume; + /* 0x028 */ f32 muteVolumeScale; + /* 0x02C */ f32 fadeVolumeScale; + /* 0x030 */ f32 appliedFadeVolume; + /* 0x034 */ f32 bend; + /* 0x038 */ struct SequenceChannel* channels[16]; + /* 0x078 */ SeqScriptState scriptState; + /* 0x094 */ u8* shortNoteVelocityTable; + /* 0x098 */ u8* shortNoteGateTimeTable; + /* 0x09C */ NotePool notePool; + /* 0x0DC */ s32 skipTicks; + /* 0x0E0 */ u32 scriptCounter; + /* 0x0E4 */ UNK_TYPE1 unk_E4[0x74]; // unused struct members for sequence/sound font dma management, according to sm64 decomp + /* 0x158 */ s8 seqScriptIO[8]; +} SequencePlayer; // size = 0x160 + +// Also known as a SubTrack, according to sm64 debug strings. +typedef struct SequenceChannel { + /* 0x00 */ u8 enabled : 1; + /* 0x00 */ u8 finished : 1; + /* 0x00 */ u8 stopScript : 1; + /* 0x00 */ u8 muted : 1; // sets SequenceLayer.muted + /* 0x00 */ u8 hasInstrument : 1; + /* 0x00 */ u8 stereoHeadsetEffects : 1; + /* 0x00 */ u8 largeNotes : 1; // notes specify duration and velocity + /* 0x00 */ u8 unused : 1; + union { + struct { + /* 0x01 */ u8 freqScale : 1; + /* 0x01 */ u8 volume : 1; + /* 0x01 */ u8 pan : 1; + } s; + /* 0x01 */ u8 asByte; + } changes; + /* 0x02 */ u8 noteAllocPolicy; + /* 0x03 */ u8 muteFlags; + /* 0x04 */ u8 targetReverbVol; // or dry/wet mix + /* 0x05 */ u8 notePriority; // 0-3 + /* 0x06 */ u8 someOtherPriority; + /* 0x07 */ u8 fontId; + /* 0x08 */ u8 reverbIndex; + /* 0x09 */ u8 bookOffset; + /* 0x0A */ u8 newPan; + /* 0x0B */ u8 panChannelWeight; // proportion of pan that comes from the channel (0..128) + /* 0x0C */ u8 gain; // Increases volume by a multiplicative scaling factor. Represented as a UQ4.4 number + /* 0x0D */ u8 velocityRandomVariance; + /* 0x0E */ u8 gateTimeRandomVariance; + /* 0x0F */ u8 combFilterSize; + /* 0x10 */ u8 surroundEffectIndex; + /* 0x11 */ u8 channelIndex; + /* 0x12 */ VibratoSubStruct vibrato; + /* 0x20 */ u16 delay; + /* 0x22 */ u16 combFilterGain; + /* 0x24 */ u16 unk_22; // Used for indexing data + /* 0x26 */ s16 instOrWave; // either 0 (none), instrument index + 1, or + // 0x80..0x83 for sawtooth/triangle/sine/square waves. + /* 0x28 */ s16 transposition; + /* 0x2C */ f32 volumeScale; + /* 0x30 */ f32 volume; + /* 0x34 */ s32 pan; + /* 0x38 */ f32 appliedVolume; + /* 0x3C */ f32 freqScale; + /* 0x40 */ u8 (*dynTable)[][2]; + /* 0x44 */ Note* noteUnused; + /* 0x48 */ struct SequenceLayer* layerUnused; + /* 0x4C */ struct Instrument* instrument; + /* 0x50 */ SequencePlayer* seqPlayer; + /* 0x54 */ struct SequenceLayer* layers[4]; + /* 0x64 */ SeqScriptState scriptState; + /* 0x80 */ AdsrSettings adsr; + /* 0x88 */ NotePool notePool; + /* 0xC8 */ s8 seqScriptIO[8]; // bridge between sound script and audio lib, "io ports" + /* 0xD0 */ u8* sfxState; // SfxChannelState + /* 0xD4 */ s16* filter; + /* 0xD8 */ StereoData stereoData; + /* 0xDC */ s32 startSamplePos; + /* 0xE0 */ s32 unk_E0; +} SequenceChannel; // size = 0xE4 + +// Might also be known as a Track, according to sm64 debug strings (?). +typedef struct SequenceLayer { + /* 0x00 */ u8 enabled : 1; + /* 0x00 */ u8 finished : 1; + /* 0x00 */ u8 muted : 1; + /* 0x00 */ u8 continuousNotes : 1; // keep the same note for consecutive notes with the same sound + /* 0x00 */ u8 bit3 : 1; // "loaded"? + /* 0x00 */ u8 ignoreDrumPan : 1; + /* 0x00 */ u8 bit1 : 1; // "has initialized continuous notes"? + /* 0x00 */ u8 notePropertiesNeedInit : 1; + /* 0x01 */ StereoData stereoData; + /* 0x02 */ u8 instOrWave; + /* 0x03 */ u8 gateTime; + /* 0x04 */ u8 semitone; + /* 0x05 */ u8 portamentoTargetNote; + /* 0x06 */ u8 pan; // 0..128 + /* 0x07 */ u8 notePan; + /* 0x08 */ u8 surroundEffectIndex; + /* 0x09 */ u8 targetReverbVol; + union { + struct { + /* 0x0A */ u16 bit_0 : 1; + /* 0x0A */ u16 bit_1 : 1; + /* 0x0A */ u16 bit_2 : 1; + /* 0x0A */ u16 useVibrato : 1; + /* 0x0A */ u16 bit_4 : 1; + /* 0x0A */ u16 bit_5 : 1; + /* 0x0A */ u16 bit_6 : 1; + /* 0x0A */ u16 bit_7 : 1; + /* 0x0A */ u16 bit_8 : 1; + /* 0x0A */ u16 bit_9 : 1; + /* 0x0A */ u16 bit_A : 1; + /* 0x0A */ u16 bit_B : 1; + /* 0x0A */ u16 bit_C : 1; + /* 0x0A */ u16 bit_D : 1; + /* 0x0A */ u16 bit_E : 1; + /* 0x0A */ u16 bit_F : 1; + } s; + /* 0x0A */ u16 asByte; + } unk_0A; + /* 0x0C */ VibratoSubStruct vibrato; + /* 0x1A */ s16 delay; + /* 0x1C */ s16 gateDelay; + /* 0x1E */ s16 delay2; + /* 0x20 */ u16 portamentoTime; + /* 0x22 */ s16 transposition; // #semitones added to play commands + // (seq instruction encoding only allows referring to the limited range + // 0..0x3F; this makes 0x40..0x7F accessible as well) + /* 0x24 */ s16 shortNoteDefaultDelay; + /* 0x26 */ s16 lastDelay; + /* 0x28 */ AdsrSettings adsr; + /* 0x30 */ Portamento portamento; + /* 0x3C */ Note* note; + /* 0x40 */ f32 freqScale; + /* 0x44 */ f32 bend; + /* 0x48 */ f32 velocitySquare2; + /* 0x4C */ f32 velocitySquare; // not sure which one of those corresponds to the sm64 original + /* 0x50 */ f32 noteVelocity; + /* 0x54 */ f32 noteFreqScale; + /* 0x58 */ struct Instrument* instrument; + /* 0x5C */ struct TunedSample* tunedSample; + /* 0x60 */ SequenceChannel* channel; + /* 0x64 */ SeqScriptState scriptState; + /* 0x80 */ AudioListItem listItem; +} SequenceLayer; // size = 0x90 + +void AudioScript_SequenceChannelDisable(SequenceChannel* channel); +void AudioScript_SequencePlayerDisableAsFinished(SequencePlayer* seqPlayer); +void AudioScript_SequencePlayerDisable(SequencePlayer* seqPlayer); +void AudioScript_ProcessSequences(s32 arg0); +void AudioScript_SkipForwardSequence(SequencePlayer* seqPlayer); +void AudioScript_ResetSequencePlayer(SequencePlayer* seqPlayer); +void AudioScript_InitSequencePlayerChannels(s32 seqPlayerIndex); +void AudioScript_InitSequencePlayers(void); + +typedef enum AudioCustomFunctions { + /* 0x00 */ AUDIO_CUSTOM_FUNCTION_SEQ_0, + /* 0x01 */ AUDIO_CUSTOM_FUNCTION_SEQ_1, + /* 0x02 */ AUDIO_CUSTOM_FUNCTION_SEQ_2, + /* 0x03 */ AUDIO_CUSTOM_FUNCTION_SEQ_3, + /* 0xFE */ AUDIO_CUSTOM_FUNCTION_SYNTH = 0xFE, + /* 0xFF */ AUDIO_CUSTOM_FUNCTION_REVERB +} AudioCustomFunctions; + +typedef void (*AudioCustomUpdateFunction)(void); +typedef u32 (*AudioCustomSeqFunction)(s8 value, SequenceChannel* channel); +typedef void* (*AudioCustomReverbFunction)(struct Sample*, s32, s8, s32); +typedef Acmd* (*AudioCustomSynthFunction)(Acmd*, s32, s32); + +extern AudioCustomUpdateFunction gAudioCustomUpdateFunction; +extern AudioCustomSeqFunction gAudioCustomSeqFunction; +extern AudioCustomReverbFunction gAudioCustomReverbFunction; +extern AudioCustomSynthFunction gAudioCustomSynthFunction; + +#endif diff --git a/include/audio/synthesis.h b/include/audio/synthesis.h new file mode 100644 index 0000000000..194bb7a5cc --- /dev/null +++ b/include/audio/synthesis.h @@ -0,0 +1,54 @@ +#ifndef AUDIO_SYNTHESIS_H +#define AUDIO_SYNTHESIS_H + +#include "PR/ultratypes.h" +#include "PR/abi.h" +#include "unk.h" + +// size of a single sample point +#define SAMPLE_SIZE sizeof(s16) + +// Samples are processed in groups of 16 called a "frame" +#define SAMPLES_PER_FRAME ADPCMFSIZE + +// The length of one left/right channel is 13 frames +#define DMEM_1CH_SIZE (13 * SAMPLES_PER_FRAME * SAMPLE_SIZE) +// Both left and right channels +#define DMEM_2CH_SIZE (2 * DMEM_1CH_SIZE) + +// Must be the same amount of samples as copied by aDuplicate() (audio microcode) +#define WAVE_SAMPLE_COUNT 64 + +typedef struct NoteSynthesisBuffers { + /* 0x000 */ s16 adpcmState[16]; + /* 0x020 */ s16 finalResampleState[16]; + /* 0x040 */ s16 filterState[32]; + /* 0x080 */ s16 unusedState[16]; + /* 0x0A0 */ s16 haasEffectDelayState[32]; + /* 0x0E0 */ s16 combFilterState[128]; + /* 0x1E0 */ s16 surroundEffectState[128]; +} NoteSynthesisBuffers; // size = 0x2E0 + +typedef struct NoteSynthesisState { + /* 0x00 */ u8 atLoopPoint : 1; + /* 0x00 */ u8 stopLoop : 1; + /* 0x01 */ u8 sampleDmaIndex; + /* 0x02 */ u8 prevHaasEffectLeftDelaySize; + /* 0x03 */ u8 prevHaasEffectRightDelaySize; + /* 0x04 */ u8 curReverbVol; + /* 0x05 */ u8 numParts; + /* 0x06 */ u16 samplePosFrac; // Fractional part of the sample position + /* 0x08 */ u16 surroundEffectGain; + /* 0x0C */ s32 samplePosInt; // Integer part of the sample position + /* 0x10 */ NoteSynthesisBuffers* synthesisBuffers; + /* 0x14 */ s16 curVolLeft; + /* 0x16 */ s16 curVolRight; + /* 0x18 */ UNK_TYPE1 unk_18[0x6]; + /* 0x1E */ u8 combFilterNeedsInit; + /* 0x1F */ u8 unk_1F; + /* 0x20 */ UNK_TYPE1 unk_20[0x4]; +} NoteSynthesisState; // size = 0x24 + +Acmd* AudioSynth_Update(Acmd* abiCmdStart, s32* numAbiCmds, s16* aiBufStart, s32 numSamplesPerFrame); + +#endif diff --git a/include/functions.h b/include/functions.h index 9310b8c83b..fdd61205e1 100644 --- a/include/functions.h +++ b/include/functions.h @@ -762,8 +762,6 @@ s32 SysFlashrom_IsBusy(void); s32 SysFlashrom_AwaitResult(void); void SysFlashrom_WriteDataSync(void* addr, u32 pageNum, u32 pageCount); -Acmd* AudioSynth_Update(Acmd* abiCmdStart, s32* numAbiCmds, s16* aiBufStart, s32 numSamplesPerFrame); - AudioTask* AudioThread_Update(void); void AudioThread_QueueCmdF32(u32 opArgs, f32 data); void AudioThread_QueueCmdS32(u32 opArgs, s32 data); @@ -782,35 +780,6 @@ void AudioThread_InitMesgQueues(void); void Audio_InvalDCache(void* buf, size_t size); void Audio_WritebackDCache(void* buf, size_t size); -void AudioPlayback_NoteDisable(Note* note); -void AudioPlayback_ProcessNotes(void); -TunedSample* AudioPlayback_GetInstrumentTunedSample(Instrument* instrument, s32 semitone); -Instrument* AudioPlayback_GetInstrumentInner(s32 fontId, s32 instId); -Drum* AudioPlayback_GetDrum(s32 fontId, s32 drumId); -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); -void AudioPlayback_InitSyntheticWave(Note* note, SequenceLayer* layer); -void AudioPlayback_InitNoteLists(NotePool* pool); -void AudioPlayback_InitNoteFreeList(void); -void AudioPlayback_NotePoolClear(NotePool* pool); -void AudioPlayback_NotePoolFill(NotePool* pool, s32 count); -void AudioPlayback_AudioListRemove(AudioListItem* item); -Note* AudioPlayback_AllocNote(SequenceLayer* layer); -void AudioPlayback_NoteInitAll(void); - -void AudioScript_SequenceChannelDisable(SequenceChannel* channel); -void AudioScript_SequencePlayerDisableAsFinished(SequencePlayer* seqPlayer); -void AudioScript_SequencePlayerDisable(SequencePlayer* seqPlayer); -void AudioScript_AudioListPushBack(AudioListItem* list, AudioListItem* item); -void* AudioScript_AudioListPopBack(AudioListItem* list); -void AudioScript_ProcessSequences(s32 arg0); -void AudioScript_SkipForwardSequence(SequencePlayer* seqPlayer); -void AudioScript_ResetSequencePlayer(SequencePlayer* seqPlayer); -void AudioScript_InitSequencePlayerChannels(s32 seqPlayerIndex); -void AudioScript_InitSequencePlayers(void); - void func_8019AE40(s32 param_1, s32 param_2, u32 param_3, s32 param_4); void func_8019AEC0(UNK_PTR param_1, UNK_PTR param_2); diff --git a/include/variables.h b/include/variables.h index 3b12d539e8..7692a1b6fe 100644 --- a/include/variables.h +++ b/include/variables.h @@ -98,10 +98,6 @@ extern u8 sResetAudioHeapTimer; extern u16 sResetAudioHeapFadeReverbVolume; extern u16 sResetAudioHeapFadeReverbVolumeStep; extern AudioContext gAudioCtx; // at 0x80200C70 -extern AudioCustomUpdateFunction gAudioCustomUpdateFunction; -extern AudioCustomSeqFunction gAudioCustomSeqFunction; -extern AudioCustomReverbFunction gAudioCustomReverbFunction; -extern AudioCustomSynthFunction gAudioCustomSynthFunction; // other segments extern Mtx D_01000000; diff --git a/include/z64audio.h b/include/z64audio.h index 3a9915e77e..d7bbb53df7 100644 --- a/include/z64audio.h +++ b/include/z64audio.h @@ -6,22 +6,18 @@ #include "audiothread_cmd.h" #include "libc/stddef.h" #include "unk.h" -#include "audiothread_cmd.h" -#include "audio/effects.h" #include "audio/heap.h" +#include "audio/list.h" #include "audio/load.h" #include "audio/reverb.h" -#include "audio/soundfont.h" +#include "audio/seqplayer.h" #include "sequence.h" -#define NO_LAYER ((SequenceLayer*)(-1)) - -#define TATUMS_PER_BEAT 48 - -#define IS_SEQUENCE_CHANNEL_VALID(ptr) ((uintptr_t)(ptr) != (uintptr_t)&gAudioCtx.sequenceChannelNone) -#define SEQ_NUM_CHANNELS 16 -#define SEQ_IO_VAL_NONE -1 +struct Note; +struct NoteSampleState; +struct SoundFont; +struct Sample; typedef enum { /* 0 */ AUDIO_HEAP_RESET_STATE_NONE, @@ -29,42 +25,10 @@ typedef enum { /* 2 */ AUDIO_HEAP_RESET_STATE_RESETTING_ALT // Never set to } AudioHeapResetState; -typedef enum { - /* 0x00 */ AUDIO_CUSTOM_FUNCTION_SEQ_0, - /* 0x01 */ AUDIO_CUSTOM_FUNCTION_SEQ_1, - /* 0x02 */ AUDIO_CUSTOM_FUNCTION_SEQ_2, - /* 0x03 */ AUDIO_CUSTOM_FUNCTION_SEQ_3, - /* 0xFE */ AUDIO_CUSTOM_FUNCTION_SYNTH = 0xFE, - /* 0xFF */ AUDIO_CUSTOM_FUNCTION_REVERB -} AudioCustomFunctions; - -typedef enum { - /* 0 */ SEQPLAYER_STATE_0, - /* 1 */ SEQPLAYER_STATE_FADE_IN, - /* 2 */ SEQPLAYER_STATE_FADE_OUT -} SeqPlayerState; - #define MAX_CHANNELS_PER_BANK 3 -#define MUTE_FLAGS_STOP_SAMPLES (1 << 3) // prevent further noteSubEus from playing -#define MUTE_FLAGS_STOP_LAYER (1 << 4) // stop something in seqLayer scripts -#define MUTE_FLAGS_SOFTEN (1 << 5) // lower volume, by default to half -#define MUTE_FLAGS_STOP_NOTES (1 << 6) // prevent further notes from playing -#define MUTE_FLAGS_STOP_SCRIPT (1 << 7) // stop processing sequence/channel scripts - #define AUDIO_LERPIMP(v0, v1, t) (v0 + ((v1 - v0) * t)) -// size of a single sample point -#define SAMPLE_SIZE sizeof(s16) - -// Samples are processed in groups of 16 called a "frame" -#define SAMPLES_PER_FRAME ADPCMFSIZE - -// The length of one left/right channel is 13 frames -#define DMEM_1CH_SIZE (13 * SAMPLES_PER_FRAME * SAMPLE_SIZE) -// Both left and right channels -#define DMEM_2CH_SIZE (2 * DMEM_1CH_SIZE) - #define AIBUF_LEN (88 * SAMPLES_PER_FRAME) // number of samples #define AIBUF_SIZE (AIBUF_LEN * SAMPLE_SIZE) // number of bytes @@ -73,24 +37,13 @@ typedef enum { #define FILTER_BUF_PART1 (8 * SAMPLE_SIZE) #define FILTER_BUF_PART2 (8 * SAMPLE_SIZE) -// Must be the same amount of samples as copied by aDuplicate() (audio microcode) -#define WAVE_SAMPLE_COUNT 64 - #define AUDIO_RELOCATED_ADDRESS_START K0BASE // To be used with AudioThread_CountAndReleaseNotes() #define AUDIO_NOTE_RELEASE (1 << 0) #define AUDIO_NOTE_SAMPLE_NOTES (1 << 1) -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, @@ -100,346 +53,6 @@ typedef enum { /* 4 */ SOUNDMODE_SURROUND } SoundMode; -struct Note; -struct NotePool; -struct SequenceChannel; -struct SequenceLayer; - -// A node in a circularly linked list. Each node is either a head or an item: -// - Items can be either detached (prev = NULL), or attached to a list. -// 'value' points to something of interest. -// - List heads are always attached; if a list is empty, its head points -// to itself. 'count' contains the size of the list. -// If the list holds notes, 'pool' points back to the pool where it lives. -// Otherwise, that member is NULL. -typedef struct AudioListItem { - /* 0x00 */ struct AudioListItem* prev; - /* 0x04 */ struct AudioListItem* next; - union { - /* 0x08 */ void* value; // either Note* or SequenceLayer* - /* 0x08 */ s32 count; - } u; - /* 0x0C */ struct NotePool* pool; -} AudioListItem; // size = 0x10 - -typedef struct NotePool { - /* 0x00 */ AudioListItem disabled; - /* 0x10 */ AudioListItem decaying; - /* 0x20 */ AudioListItem releasing; - /* 0x30 */ AudioListItem active; -} NotePool; // size = 0x40 - -typedef struct { - /* 0x00 */ u8* pc; // program counter - /* 0x04 */ u8* stack[4]; - /* 0x14 */ u8 remLoopIters[4]; // remaining loop iterations - /* 0x18 */ u8 depth; - /* 0x19 */ s8 value; -} SeqScriptState; // size = 0x1C - -// Also known as a Group, according to debug strings. -typedef struct SequencePlayer { - /* 0x000 */ u8 enabled : 1; - /* 0x000 */ u8 finished : 1; - /* 0x000 */ u8 muted : 1; - /* 0x000 */ u8 seqDmaInProgress : 1; - /* 0x000 */ u8 fontDmaInProgress : 1; - /* 0x000 */ u8 recalculateVolume : 1; - /* 0x000 */ u8 stopScript : 1; - /* 0x000 */ u8 applyBend : 1; - /* 0x001 */ u8 state; - /* 0x002 */ u8 noteAllocPolicy; - /* 0x003 */ u8 muteFlags; - /* 0x004 */ u8 seqId; - /* 0x005 */ u8 defaultFont; - /* 0x006 */ u8 unk_06[1]; - /* 0x007 */ s8 playerIndex; - /* 0x008 */ u16 tempo; // tatums per minute - /* 0x00A */ u16 tempoAcc; - /* 0x00C */ s16 tempoChange; - /* 0x00E */ s16 transposition; - /* 0x010 */ u16 delay; - /* 0x012 */ u16 fadeTimer; - /* 0x014 */ u16 storedFadeTimer; - /* 0x016 */ u16 unk_16; - /* 0x018 */ u8* seqData; - /* 0x01C */ f32 fadeVolume; - /* 0x020 */ f32 fadeVelocity; - /* 0x024 */ f32 volume; - /* 0x028 */ f32 muteVolumeScale; - /* 0x02C */ f32 fadeVolumeScale; - /* 0x030 */ f32 appliedFadeVolume; - /* 0x034 */ f32 bend; - /* 0x038 */ struct SequenceChannel* channels[16]; - /* 0x078 */ SeqScriptState scriptState; - /* 0x094 */ u8* shortNoteVelocityTable; - /* 0x098 */ u8* shortNoteGateTimeTable; - /* 0x09C */ NotePool notePool; - /* 0x0DC */ s32 skipTicks; - /* 0x0E0 */ u32 scriptCounter; - /* 0x0E4 */ UNK_TYPE1 unk_E4[0x74]; // unused struct members for sequence/sound font dma management, according to sm64 decomp - /* 0x158 */ s8 seqScriptIO[8]; -} SequencePlayer; // size = 0x160 - -typedef union { - struct { - /* 0x0 */ u8 unused : 2; - /* 0x0 */ u8 type : 2; - /* 0x0 */ u8 strongRight : 1; - /* 0x0 */ u8 strongLeft : 1; - /* 0x0 */ u8 strongReverbRight : 1; - /* 0x0 */ u8 strongReverbLeft : 1; - }; - /* 0x0 */ u8 asByte; -} StereoData; // size = 0x1 - -typedef struct { - /* 0x00 */ u8 targetReverbVol; - /* 0x01 */ u8 gain; // Increases volume by a multiplicative scaling factor. Represented as a UQ4.4 number - /* 0x02 */ u8 pan; - /* 0x03 */ u8 surroundEffectIndex; - /* 0x04 */ StereoData stereoData; - /* 0x05 */ u8 combFilterSize; - /* 0x06 */ u16 combFilterGain; - /* 0x08 */ f32 freqScale; - /* 0x0C */ f32 velocity; - /* 0x10 */ s16* filter; - /* 0x14 */ s16* filterBuf; -} NoteAttributes; // size = 0x18 - -// Also known as a SubTrack, according to sm64 debug strings. -typedef struct SequenceChannel { - /* 0x00 */ u8 enabled : 1; - /* 0x00 */ u8 finished : 1; - /* 0x00 */ u8 stopScript : 1; - /* 0x00 */ u8 muted : 1; // sets SequenceLayer.muted - /* 0x00 */ u8 hasInstrument : 1; - /* 0x00 */ u8 stereoHeadsetEffects : 1; - /* 0x00 */ u8 largeNotes : 1; // notes specify duration and velocity - /* 0x00 */ u8 unused : 1; - union { - struct { - /* 0x01 */ u8 freqScale : 1; - /* 0x01 */ u8 volume : 1; - /* 0x01 */ u8 pan : 1; - } s; - /* 0x01 */ u8 asByte; - } changes; - /* 0x02 */ u8 noteAllocPolicy; - /* 0x03 */ u8 muteFlags; - /* 0x04 */ u8 targetReverbVol; // or dry/wet mix - /* 0x05 */ u8 notePriority; // 0-3 - /* 0x06 */ u8 someOtherPriority; - /* 0x07 */ u8 fontId; - /* 0x08 */ u8 reverbIndex; - /* 0x09 */ u8 bookOffset; - /* 0x0A */ u8 newPan; - /* 0x0B */ u8 panChannelWeight; // proportion of pan that comes from the channel (0..128) - /* 0x0C */ u8 gain; // Increases volume by a multiplicative scaling factor. Represented as a UQ4.4 number - /* 0x0D */ u8 velocityRandomVariance; - /* 0x0E */ u8 gateTimeRandomVariance; - /* 0x0F */ u8 combFilterSize; - /* 0x10 */ u8 surroundEffectIndex; - /* 0x11 */ u8 channelIndex; - /* 0x12 */ VibratoSubStruct vibrato; - /* 0x20 */ u16 delay; - /* 0x22 */ u16 combFilterGain; - /* 0x24 */ u16 unk_22; // Used for indexing data - /* 0x26 */ s16 instOrWave; // either 0 (none), instrument index + 1, or - // 0x80..0x83 for sawtooth/triangle/sine/square waves. - /* 0x28 */ s16 transposition; - /* 0x2C */ f32 volumeScale; - /* 0x30 */ f32 volume; - /* 0x34 */ s32 pan; - /* 0x38 */ f32 appliedVolume; - /* 0x3C */ f32 freqScale; - /* 0x40 */ u8 (*dynTable)[][2]; - /* 0x44 */ struct Note* noteUnused; - /* 0x48 */ struct SequenceLayer* layerUnused; - /* 0x4C */ Instrument* instrument; - /* 0x50 */ SequencePlayer* seqPlayer; - /* 0x54 */ struct SequenceLayer* layers[4]; - /* 0x64 */ SeqScriptState scriptState; - /* 0x80 */ AdsrSettings adsr; - /* 0x88 */ NotePool notePool; - /* 0xC8 */ s8 seqScriptIO[8]; // bridge between sound script and audio lib, "io ports" - /* 0xD0 */ u8* sfxState; // SfxChannelState - /* 0xD4 */ s16* filter; - /* 0xD8 */ StereoData stereoData; - /* 0xDC */ s32 startSamplePos; - /* 0xE0 */ s32 unk_E0; -} SequenceChannel; // size = 0xE4 - -// Might also be known as a Track, according to sm64 debug strings (?). -typedef struct SequenceLayer { - /* 0x00 */ u8 enabled : 1; - /* 0x00 */ u8 finished : 1; - /* 0x00 */ u8 muted : 1; - /* 0x00 */ u8 continuousNotes : 1; // keep the same note for consecutive notes with the same sound - /* 0x00 */ u8 bit3 : 1; // "loaded"? - /* 0x00 */ u8 ignoreDrumPan : 1; - /* 0x00 */ u8 bit1 : 1; // "has initialized continuous notes"? - /* 0x00 */ u8 notePropertiesNeedInit : 1; - /* 0x01 */ StereoData stereoData; - /* 0x02 */ u8 instOrWave; - /* 0x03 */ u8 gateTime; - /* 0x04 */ u8 semitone; - /* 0x05 */ u8 portamentoTargetNote; - /* 0x06 */ u8 pan; // 0..128 - /* 0x07 */ u8 notePan; - /* 0x08 */ u8 surroundEffectIndex; - /* 0x09 */ u8 targetReverbVol; - union { - struct { - /* 0x0A */ u16 bit_0 : 1; - /* 0x0A */ u16 bit_1 : 1; - /* 0x0A */ u16 bit_2 : 1; - /* 0x0A */ u16 useVibrato : 1; - /* 0x0A */ u16 bit_4 : 1; - /* 0x0A */ u16 bit_5 : 1; - /* 0x0A */ u16 bit_6 : 1; - /* 0x0A */ u16 bit_7 : 1; - /* 0x0A */ u16 bit_8 : 1; - /* 0x0A */ u16 bit_9 : 1; - /* 0x0A */ u16 bit_A : 1; - /* 0x0A */ u16 bit_B : 1; - /* 0x0A */ u16 bit_C : 1; - /* 0x0A */ u16 bit_D : 1; - /* 0x0A */ u16 bit_E : 1; - /* 0x0A */ u16 bit_F : 1; - } s; - /* 0x0A */ u16 asByte; - } unk_0A; - /* 0x0C */ VibratoSubStruct vibrato; - /* 0x1A */ s16 delay; - /* 0x1C */ s16 gateDelay; - /* 0x1E */ s16 delay2; - /* 0x20 */ u16 portamentoTime; - /* 0x22 */ s16 transposition; // #semitones added to play commands - // (seq instruction encoding only allows referring to the limited range - // 0..0x3F; this makes 0x40..0x7F accessible as well) - /* 0x24 */ s16 shortNoteDefaultDelay; - /* 0x26 */ s16 lastDelay; - /* 0x28 */ AdsrSettings adsr; - /* 0x30 */ Portamento portamento; - /* 0x3C */ struct Note* note; - /* 0x40 */ f32 freqScale; - /* 0x44 */ f32 bend; - /* 0x48 */ f32 velocitySquare2; - /* 0x4C */ f32 velocitySquare; // not sure which one of those corresponds to the sm64 original - /* 0x50 */ f32 noteVelocity; - /* 0x54 */ f32 noteFreqScale; - /* 0x58 */ Instrument* instrument; - /* 0x5C */ TunedSample* tunedSample; - /* 0x60 */ SequenceChannel* channel; // Not SequenceChannel? - /* 0x64 */ SeqScriptState scriptState; - /* 0x80 */ AudioListItem listItem; -} SequenceLayer; // size = 0x90 - -typedef struct { - /* 0x000 */ s16 adpcmState[16]; - /* 0x020 */ s16 finalResampleState[16]; - /* 0x040 */ s16 filterState[32]; - /* 0x080 */ s16 unusedState[16]; - /* 0x0A0 */ s16 haasEffectDelayState[32]; - /* 0x0E0 */ s16 combFilterState[128]; - /* 0x1E0 */ s16 surroundEffectState[128]; -} NoteSynthesisBuffers; // size = 0x2E0 - -typedef struct { - /* 0x00 */ u8 atLoopPoint : 1; - /* 0x00 */ u8 stopLoop : 1; - /* 0x01 */ u8 sampleDmaIndex; - /* 0x02 */ u8 prevHaasEffectLeftDelaySize; - /* 0x03 */ u8 prevHaasEffectRightDelaySize; - /* 0x04 */ u8 curReverbVol; - /* 0x05 */ u8 numParts; - /* 0x06 */ u16 samplePosFrac; // Fractional part of the sample position - /* 0x08 */ u16 surroundEffectGain; - /* 0x0C */ s32 samplePosInt; // Integer part of the sample position - /* 0x10 */ NoteSynthesisBuffers* synthesisBuffers; - /* 0x14 */ s16 curVolLeft; - /* 0x16 */ s16 curVolRight; - /* 0x18 */ UNK_TYPE1 unk_14[0x6]; - /* 0x1E */ u8 combFilterNeedsInit; - /* 0x1F */ u8 unk_1F; - /* 0x20 */ UNK_TYPE1 unk_20[0x4]; -} NoteSynthesisState; // size = 0x24 - -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 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 status; - /* 0x05 */ u8 stereoHeadsetEffects; - /* 0x06 */ s16 adsrVolScaleUnused; - /* 0x08 */ f32 portamentoFreqScale; - /* 0x0C */ f32 vibratoFreqScale; - /* 0x18 */ SequenceLayer* wantedParentLayer; - /* 0x14 */ SequenceLayer* parentLayer; - /* 0x10 */ SequenceLayer* prevParentLayer; - /* 0x1C */ NoteAttributes attributes; - /* 0x34 */ AdsrState adsr; - /* 0x54 */ Portamento portamento; - /* 0x60 */ VibratoState vibratoState; - /* 0x7C */ UNK_TYPE1 pad7C[0x4]; - /* 0x80 */ u8 unk_80; - /* 0x84 */ u32 startSamplePos; - /* 0x88 */ UNK_TYPE1 unk_BC[0x1C]; -} NotePlaybackState; // size = 0xA4 - -typedef struct { - struct { - /* 0x00 */ volatile u8 enabled : 1; - /* 0x00 */ u8 needsInit : 1; - /* 0x00 */ u8 finished : 1; - /* 0x00 */ u8 unused : 1; - /* 0x00 */ u8 strongRight : 1; - /* 0x00 */ u8 strongLeft : 1; - /* 0x00 */ u8 strongReverbRight : 1; - /* 0x00 */ u8 strongReverbLeft : 1; - } bitField0; - struct { - /* 0x01 */ u8 reverbIndex : 3; - /* 0x01 */ u8 bookOffset : 2; - /* 0x01 */ u8 isSyntheticWave : 1; - /* 0x01 */ u8 hasTwoParts : 1; - /* 0x01 */ u8 useHaasEffect : 1; - } bitField1; - /* 0x02 */ u8 gain; // Increases volume by a multiplicative scaling factor. Represented as a UQ4.4 number - /* 0x03 */ u8 haasEffectLeftDelaySize; - /* 0x04 */ u8 haasEffectRightDelaySize; - /* 0x05 */ u8 targetReverbVol; - /* 0x06 */ u8 harmonicIndexCurAndPrev; // bits 3..2 store curHarmonicIndex, bits 1..0 store prevHarmonicIndex - /* 0x07 */ u8 combFilterSize; - /* 0x08 */ u16 targetVolLeft; - /* 0x0A */ u16 targetVolRight; - /* 0x0C */ u16 frequencyFixedPoint; - /* 0x0E */ u16 combFilterGain; - union { - /* 0x10 */ TunedSample* tunedSample; - /* 0x10 */ s16* waveSampleAddr; // used for synthetic waves - }; - /* 0x14 */ s16* filter; - /* 0x18 */ UNK_TYPE1 unk_18; - /* 0x19 */ u8 surroundEffectIndex; - /* 0x1A */ UNK_TYPE1 unk_1A[0x6]; -} NoteSampleState; // size = 0x20 - -typedef struct Note { - /* 0x00 */ AudioListItem listItem; - /* 0x10 */ NoteSynthesisState synthesisState; - /* 0x34 */ NotePlaybackState playbackState; - /* 0xD8 */ NoteSampleState sampleState; -} Note; // size = 0xF8 - /** * 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. @@ -526,10 +139,10 @@ typedef struct { /* 0x0004 */ u16 unk_4; /* 0x0006 */ char unk_0006[0xA]; /* 0x0010 */ s16* adpcmCodeBook; - /* 0x0014 */ NoteSampleState* sampleStateList; + /* 0x0014 */ struct NoteSampleState* sampleStateList; /* 0x0018 */ SynthesisReverb synthesisReverbs[4]; /* 0x0B58 */ char unk_0B58[0x30]; - /* 0x0B88 */ Sample* usedSamples[128]; + /* 0x0B88 */ struct Sample* usedSamples[128]; /* 0x0D88 */ AudioPreloadReq preloadSampleStack[128]; /* 0x1788 */ s32 numUsedSamples; /* 0x178C */ s32 preloadSampleStackTop; @@ -567,7 +180,7 @@ typedef struct { /* 0x285C */ char unk_285C[0x4]; /* 0x2860 */ u8* sequenceFontTable; /* 0x2864 */ u16 numSequences; - /* 0x2868 */ SoundFont* soundFontList; + /* 0x2868 */ struct SoundFont* soundFontList; /* 0x286C */ AudioBufferParameters audioBufferParameters; /* 0x2994 */ f32 unk_2870; /* 0x2898 */ s32 sampleDmaBufSize1; @@ -618,13 +231,13 @@ typedef struct { /* 0x4368 */ u8 sampleFontLoadStatus[0x30]; /* 0x4398 */ u8 fontLoadStatus[0x30]; /* 0x43C8 */ u8 seqLoadStatus[0x80]; - /* 0x4448 */ volatile u8 resetStatus; + /* 0x4448 */ vu8 resetStatus; /* 0x4449 */ u8 specId; /* 0x444C */ s32 audioResetFadeOutFramesLeft; /* 0x4450 */ f32* adsrDecayTable; // A table on the audio heap that stores decay rates used for ADSR /* 0x4454 */ u8* audioHeap; /* 0x4458 */ size_t audioHeapSize; - /* 0x445C */ Note* notes; + /* 0x445C */ struct Note* notes; // dynamically sized based on gAudioCtx.numNotes /* 0x4460 */ SequencePlayer seqPlayers[5]; /* 0x4B40 */ SequenceLayer sequenceLayers[80]; /* 0x7840 */ SequenceChannel sequenceChannelNone; @@ -648,23 +261,4 @@ typedef struct { /* 0x81F4 */ UNK_TYPE1 unk_81F4[4]; } AudioContext; // size = 0x81F8 -typedef struct { - /* 0x00 */ u8 targetReverbVol; - /* 0x01 */ u8 gain; // Increases volume by a multiplicative scaling factor. Represented as a UQ4.4 number - /* 0x02 */ u8 pan; - /* 0x03 */ u8 surroundEffectIndex; - /* 0x04 */ StereoData stereoData; - /* 0x08 */ f32 frequency; - /* 0x0C */ f32 velocity; - /* 0x10 */ char unk_0C[0x4]; - /* 0x14 */ s16* filter; - /* 0x18 */ u8 combFilterSize; - /* 0x1A */ u16 combFilterGain; -} NoteSubAttributes; // size = 0x1A - -typedef void (*AudioCustomUpdateFunction)(void); -typedef u32 (*AudioCustomSeqFunction)(s8 value, SequenceChannel* channel); -typedef void* (*AudioCustomReverbFunction)(Sample*, s32, s8, s32); -typedef Acmd* (*AudioCustomSynthFunction)(Acmd*, s32, s32); - #endif diff --git a/src/audio/lib/heap.c b/src/audio/lib/heap.c index 4101ab7b72..0d11acfed0 100644 --- a/src/audio/lib/heap.c +++ b/src/audio/lib/heap.c @@ -1,5 +1,6 @@ #include "global.h" #include "audio/effects.h" +#include "audio/heap.h" void* AudioHeap_SearchRegularCaches(s32 tableType, s32 cache, s32 id); void AudioHeap_InitSampleCaches(size_t persistentSampleCacheSize, size_t temporarySampleCacheSize); @@ -86,8 +87,8 @@ void AudioHeap_DiscardFont(s32 fontId) { } AudioPlayback_NoteDisable(note); - AudioPlayback_AudioListRemove(¬e->listItem); - AudioScript_AudioListPushBack(&gAudioCtx.noteFreeLists.disabled, ¬e->listItem); + AudioList_Remove(¬e->listItem); + AudioList_PushBack(&gAudioCtx.noteFreeLists.disabled, ¬e->listItem); } } } @@ -1034,7 +1035,7 @@ void AudioHeap_Init(void) { // Initialize notes gAudioCtx.notes = AudioHeap_AllocZeroed(&gAudioCtx.miscPool, gAudioCtx.numNotes * sizeof(Note)); AudioPlayback_NoteInitAll(); - AudioPlayback_InitNoteFreeList(); + AudioList_InitNoteFreeList(); gAudioCtx.sampleStateList = AudioHeap_AllocZeroed(&gAudioCtx.miscPool, gAudioCtx.audioBufferParameters.updatesPerFrame * gAudioCtx.numNotes * sizeof(NoteSampleState)); diff --git a/src/audio/lib/load.c b/src/audio/lib/load.c index c3a101102a..adc6769994 100644 --- a/src/audio/lib/load.c +++ b/src/audio/lib/load.c @@ -11,6 +11,7 @@ */ #include "global.h" +#include "audio/load.h" #include "buffers.h" /** diff --git a/src/audio/lib/playback.c b/src/audio/lib/playback.c index 6bc5e3943c..db59eaec5a 100644 --- a/src/audio/lib/playback.c +++ b/src/audio/lib/playback.c @@ -1,10 +1,25 @@ #include "global.h" #include "audio/effects.h" +#include "audio/playback.h" void AudioPlayback_NoteSetResamplingRate(NoteSampleState* sampleState, f32 resamplingRateInput); -void AudioPlayback_AudioListPushFront(AudioListItem* list, AudioListItem* item); +void AudioList_PushFront(AudioListItem* list, AudioListItem* item); void AudioPlayback_NoteInitForLayer(Note* note, SequenceLayer* layer); +typedef struct { + /* 0x00 */ u8 targetReverbVol; + /* 0x01 */ u8 gain; // Increases volume by a multiplicative scaling factor. Represented as a UQ4.4 number + /* 0x02 */ u8 pan; + /* 0x03 */ u8 surroundEffectIndex; + /* 0x04 */ StereoData stereoData; + /* 0x08 */ f32 frequency; + /* 0x0C */ f32 velocity; + /* 0x10 */ UNK_TYPE1 unk_10[0x4]; + /* 0x14 */ s16* filter; + /* 0x18 */ u8 combFilterSize; + /* 0x1A */ u16 combFilterGain; +} NoteSubAttributes; // size = 0x1A + void AudioPlayback_InitSampleState(Note* note, NoteSampleState* sampleState, NoteSubAttributes* subAttrs) { f32 volLeft; f32 volRight; @@ -205,8 +220,8 @@ void AudioPlayback_ProcessNotes(void) { } AudioPlayback_SeqLayerNoteRelease(playbackState->parentLayer); - AudioPlayback_AudioListRemove(¬e->listItem); - AudioPlayback_AudioListPushFront(¬e->listItem.pool->decaying, ¬e->listItem); + AudioList_Remove(¬e->listItem); + AudioList_PushFront(¬e->listItem.pool->decaying, ¬e->listItem); playbackState->priority = 1; playbackState->status = PLAYBACK_STATUS_2; } else if ((playbackState->status == PLAYBACK_STATUS_0) && (playbackState->priority >= 1)) { @@ -227,14 +242,14 @@ void AudioPlayback_ProcessNotes(void) { AudioPlayback_NoteInitForLayer(note, playbackState->wantedParentLayer); AudioEffects_InitVibrato(note); AudioEffects_InitPortamento(note); - AudioPlayback_AudioListRemove(¬e->listItem); - AudioScript_AudioListPushBack(¬e->listItem.pool->active, ¬e->listItem); + AudioList_Remove(¬e->listItem); + AudioList_PushBack(¬e->listItem.pool->active, ¬e->listItem); playbackState->wantedParentLayer = NO_LAYER; // don't skip } else { AudioPlayback_NoteDisable(note); - AudioPlayback_AudioListRemove(¬e->listItem); - AudioScript_AudioListPushBack(¬e->listItem.pool->disabled, ¬e->listItem); + AudioList_Remove(¬e->listItem); + AudioList_PushBack(¬e->listItem.pool->disabled, ¬e->listItem); playbackState->wantedParentLayer = NO_LAYER; goto skip; } @@ -243,8 +258,8 @@ void AudioPlayback_ProcessNotes(void) { playbackState->parentLayer->bit1 = true; } AudioPlayback_NoteDisable(note); - AudioPlayback_AudioListRemove(¬e->listItem); - AudioScript_AudioListPushBack(¬e->listItem.pool->disabled, ¬e->listItem); + AudioList_Remove(¬e->listItem); + AudioList_PushBack(¬e->listItem.pool->disabled, ¬e->listItem); continue; } } @@ -253,8 +268,8 @@ void AudioPlayback_ProcessNotes(void) { playbackState->parentLayer->bit1 = true; } AudioPlayback_NoteDisable(note); - AudioPlayback_AudioListRemove(¬e->listItem); - AudioScript_AudioListPushBack(¬e->listItem.pool->disabled, ¬e->listItem); + AudioList_Remove(¬e->listItem); + AudioList_PushBack(¬e->listItem.pool->disabled, ¬e->listItem); continue; } @@ -570,8 +585,8 @@ void AudioPlayback_SeqLayerDecayRelease(SequenceLayer* layer, s32 target) { } if (target == ADSR_STATUS_DECAY) { - AudioPlayback_AudioListRemove(¬e->listItem); - AudioPlayback_AudioListPushFront(¬e->listItem.pool->decaying, ¬e->listItem); + AudioList_Remove(¬e->listItem); + AudioList_PushFront(¬e->listItem.pool->decaying, ¬e->listItem); } } @@ -649,35 +664,35 @@ void AudioPlayback_InitSyntheticWave(Note* note, SequenceLayer* layer) { } } -void AudioPlayback_InitNoteList(AudioListItem* list) { +void AudioList_InitNoteList(AudioListItem* list) { list->prev = list; list->next = list; list->u.count = 0; } -void AudioPlayback_InitNoteLists(NotePool* pool) { - AudioPlayback_InitNoteList(&pool->disabled); - AudioPlayback_InitNoteList(&pool->decaying); - AudioPlayback_InitNoteList(&pool->releasing); - AudioPlayback_InitNoteList(&pool->active); +void AudioList_InitNoteLists(NotePool* pool) { + AudioList_InitNoteList(&pool->disabled); + AudioList_InitNoteList(&pool->decaying); + AudioList_InitNoteList(&pool->releasing); + AudioList_InitNoteList(&pool->active); pool->disabled.pool = pool; pool->decaying.pool = pool; pool->releasing.pool = pool; pool->active.pool = pool; } -void AudioPlayback_InitNoteFreeList(void) { +void AudioList_InitNoteFreeList(void) { s32 i; - AudioPlayback_InitNoteLists(&gAudioCtx.noteFreeLists); + AudioList_InitNoteLists(&gAudioCtx.noteFreeLists); for (i = 0; i < gAudioCtx.numNotes; i++) { gAudioCtx.notes[i].listItem.u.value = &gAudioCtx.notes[i]; gAudioCtx.notes[i].listItem.prev = NULL; - AudioScript_AudioListPushBack(&gAudioCtx.noteFreeLists.disabled, &gAudioCtx.notes[i].listItem); + AudioList_PushBack(&gAudioCtx.noteFreeLists.disabled, &gAudioCtx.notes[i].listItem); } } -void AudioPlayback_NotePoolClear(NotePool* pool) { +void AudioList_ClearNotePool(NotePool* pool) { s32 i; AudioListItem* source; AudioListItem* cur; @@ -711,20 +726,20 @@ void AudioPlayback_NotePoolClear(NotePool* pool) { if (cur == source || cur == NULL) { break; } - AudioPlayback_AudioListRemove(cur); - AudioScript_AudioListPushBack(dest, cur); + AudioList_Remove(cur); + AudioList_PushBack(dest, cur); } } } -void AudioPlayback_NotePoolFill(NotePool* pool, s32 count) { +void AudioList_FillNotePool(NotePool* pool, s32 count) { s32 i; s32 j; Note* note; AudioListItem* source; AudioListItem* dest; - AudioPlayback_NotePoolClear(pool); + AudioList_ClearNotePool(pool); for (i = 0, j = 0; j < count; i++) { if (i == 4) { @@ -754,17 +769,17 @@ void AudioPlayback_NotePoolFill(NotePool* pool, s32 count) { } while (j < count) { - note = AudioScript_AudioListPopBack(source); + note = AudioList_PopBack(source); if (note == NULL) { break; } - AudioScript_AudioListPushBack(dest, ¬e->listItem); + AudioList_PushBack(dest, ¬e->listItem); j++; } } } -void AudioPlayback_AudioListPushFront(AudioListItem* list, AudioListItem* item) { +void AudioList_PushFront(AudioListItem* list, AudioListItem* item) { // add 'item' to the front of the list given by 'list', if it's not in any list if (item->prev == NULL) { item->prev = list; @@ -776,7 +791,7 @@ void AudioPlayback_AudioListPushFront(AudioListItem* list, AudioListItem* item) } } -void AudioPlayback_AudioListRemove(AudioListItem* item) { +void AudioList_Remove(AudioListItem* item) { // remove 'item' from the list it's in, if any if (item->prev != NULL) { item->prev->next = item->next; @@ -785,7 +800,7 @@ void AudioPlayback_AudioListRemove(AudioListItem* item) { } } -Note* AudioPlayback_FindNodeWithPrioLessThan(AudioListItem* list, s32 limit) { +Note* AudioList_FindNodeWithPrioLessThan(AudioListItem* list, s32 limit) { AudioListItem* cur = list->next; AudioListItem* best; @@ -871,22 +886,22 @@ void AudioPlayback_NoteReleaseAndTakeOwnership(Note* note, SequenceLayer* layer) } Note* AudioPlayback_AllocNoteFromDisabled(NotePool* pool, SequenceLayer* layer) { - Note* note = AudioScript_AudioListPopBack(&pool->disabled); + Note* note = AudioList_PopBack(&pool->disabled); if (note != NULL) { AudioPlayback_NoteInitForLayer(note, layer); - AudioPlayback_AudioListPushFront(&pool->active, ¬e->listItem); + AudioList_PushFront(&pool->active, ¬e->listItem); } return note; } Note* AudioPlayback_AllocNoteFromDecaying(NotePool* pool, SequenceLayer* layer) { - Note* note = AudioPlayback_FindNodeWithPrioLessThan(&pool->decaying, layer->channel->notePriority); + Note* note = AudioList_FindNodeWithPrioLessThan(&pool->decaying, layer->channel->notePriority); if (note != NULL) { AudioPlayback_NoteReleaseAndTakeOwnership(note, layer); - AudioPlayback_AudioListRemove(¬e->listItem); - AudioScript_AudioListPushBack(&pool->releasing, ¬e->listItem); + AudioList_Remove(¬e->listItem); + AudioList_PushBack(&pool->releasing, ¬e->listItem); } return note; } @@ -898,13 +913,13 @@ Note* AudioPlayback_AllocNoteFromActive(NotePool* pool, SequenceLayer* layer) { s32 aPriority; rPriority = aPriority = 0x10; - rNote = AudioPlayback_FindNodeWithPrioLessThan(&pool->releasing, layer->channel->notePriority); + rNote = AudioList_FindNodeWithPrioLessThan(&pool->releasing, layer->channel->notePriority); if (rNote != NULL) { rPriority = rNote->playbackState.priority; } - aNote = AudioPlayback_FindNodeWithPrioLessThan(&pool->active, layer->channel->notePriority); + aNote = AudioList_FindNodeWithPrioLessThan(&pool->active, layer->channel->notePriority); if (aNote != NULL) { aPriority = aNote->playbackState.priority; @@ -915,9 +930,9 @@ Note* AudioPlayback_AllocNoteFromActive(NotePool* pool, SequenceLayer* layer) { } if (aPriority < rPriority) { - AudioPlayback_AudioListRemove(&aNote->listItem); + AudioList_Remove(&aNote->listItem); func_801963E8(aNote, layer); - AudioScript_AudioListPushBack(&pool->releasing, &aNote->listItem); + AudioList_PushBack(&pool->releasing, &aNote->listItem); aNote->playbackState.priority = layer->channel->notePriority; return aNote; } @@ -935,8 +950,8 @@ Note* AudioPlayback_AllocNote(SequenceLayer* layer) { if ((note != NULL) && (note->playbackState.prevParentLayer == layer) && (note->playbackState.wantedParentLayer == NO_LAYER)) { AudioPlayback_NoteReleaseAndTakeOwnership(note, layer); - AudioPlayback_AudioListRemove(¬e->listItem); - AudioScript_AudioListPushBack(¬e->listItem.pool->releasing, ¬e->listItem); + AudioList_Remove(¬e->listItem); + AudioList_PushBack(¬e->listItem.pool->releasing, ¬e->listItem); return note; } } diff --git a/src/audio/lib/seqplayer.c b/src/audio/lib/seqplayer.c index 34ec93a7b4..7fc88f6e67 100644 --- a/src/audio/lib/seqplayer.c +++ b/src/audio/lib/seqplayer.c @@ -14,6 +14,7 @@ * Otherwise, each set of instructions has its own command interpreter */ #include "global.h" +#include "audio/seqplayer.h" #define PROCESS_SCRIPT_END -1 @@ -307,7 +308,7 @@ void AudioScript_InitSequenceChannel(SequenceChannel* channel) { } channel->unused = false; - AudioPlayback_InitNoteLists(&channel->notePool); + AudioList_InitNoteLists(&channel->notePool); channel->startSamplePos = 0; channel->unk_E0 = 0; channel->sfxState = NULL; @@ -318,7 +319,7 @@ s32 AudioScript_SeqChannelSetLayer(SequenceChannel* channel, s32 layerIndex) { s32 pad; if (channel->layers[layerIndex] == NULL) { - layer = AudioScript_AudioListPopBack(&gAudioCtx.layerFreeList); + layer = AudioList_PopBack(&gAudioCtx.layerFreeList); channel->layers[layerIndex] = layer; if (layer == NULL) { channel->layers[layerIndex] = NULL; @@ -386,7 +387,7 @@ void AudioScript_SeqLayerFree(SequenceChannel* channel, s32 layerIndex) { SequenceLayer* layer = channel->layers[layerIndex]; if (layer != NULL) { - AudioScript_AudioListPushBack(&gAudioCtx.layerFreeList, &layer->listItem); + AudioList_PushBack(&gAudioCtx.layerFreeList, &layer->listItem); AudioScript_SeqLayerDisable(layer); channel->layers[layerIndex] = NULL; } @@ -401,7 +402,7 @@ void AudioScript_SequenceChannelDisable(SequenceChannel* channel) { AudioScript_SeqLayerFree(channel, i); } - AudioPlayback_NotePoolClear(&channel->notePool); + AudioList_ClearNotePool(&channel->notePool); channel->enabled = false; } @@ -456,7 +457,7 @@ void AudioScript_SequencePlayerDisableAsFinished(SequencePlayer* seqPlayer) { void AudioScript_SequencePlayerDisable(SequencePlayer* seqPlayer) { AudioScript_SequencePlayerDisableChannels(seqPlayer, 0xFFFF); - AudioPlayback_NotePoolClear(&seqPlayer->notePool); + AudioList_ClearNotePool(&seqPlayer->notePool); if (!seqPlayer->enabled) { return; } @@ -479,7 +480,7 @@ void AudioScript_SequencePlayerDisable(SequencePlayer* seqPlayer) { } } -void AudioScript_AudioListPushBack(AudioListItem* list, AudioListItem* item) { +void AudioList_PushBack(AudioListItem* list, AudioListItem* item) { if (item->prev == NULL) { list->prev->next = item; item->prev = list->prev; @@ -490,7 +491,7 @@ void AudioScript_AudioListPushBack(AudioListItem* list, AudioListItem* item) { } } -void* AudioScript_AudioListPopBack(AudioListItem* list) { +void* AudioList_PopBack(AudioListItem* list) { AudioListItem* item = list->prev; if (item == list) { @@ -516,7 +517,7 @@ void AudioScript_InitLayerFreelist(void) { for (i = 0; i < ARRAY_COUNT(gAudioCtx.sequenceLayers); i++) { gAudioCtx.sequenceLayers[i].listItem.u.value = &gAudioCtx.sequenceLayers[i]; gAudioCtx.sequenceLayers[i].listItem.prev = NULL; - AudioScript_AudioListPushBack(&gAudioCtx.layerFreeList, &gAudioCtx.sequenceLayers[i].listItem); + AudioList_PushBack(&gAudioCtx.layerFreeList, &gAudioCtx.sequenceLayers[i].listItem); } } @@ -1259,13 +1260,13 @@ void AudioScript_SequenceChannelProcessScript(SequenceChannel* channel) { goto exit_loop; case 0xF1: // channel: reserve notes - AudioPlayback_NotePoolClear(&channel->notePool); + AudioList_ClearNotePool(&channel->notePool); cmd = (u8)cmdArgs[0]; - AudioPlayback_NotePoolFill(&channel->notePool, cmd); + AudioList_FillNotePool(&channel->notePool, cmd); break; case 0xF0: // channel: unreserve notes - AudioPlayback_NotePoolClear(&channel->notePool); + AudioList_ClearNotePool(&channel->notePool); break; case 0xC2: // channel: set dyntable @@ -1913,13 +1914,13 @@ void AudioScript_SequencePlayerProcessSequence(SequencePlayer* seqPlayer) { if (cmd >= 0xC0) { switch (cmd) { case 0xF1: // seqPlayer: reserve notes - AudioPlayback_NotePoolClear(&seqPlayer->notePool); + AudioList_ClearNotePool(&seqPlayer->notePool); cmd = AudioScript_ScriptReadU8(seqScript); - AudioPlayback_NotePoolFill(&seqPlayer->notePool, cmd); + AudioList_FillNotePool(&seqPlayer->notePool, cmd); break; case 0xF0: // seqPlayer: unreserve notes - AudioPlayback_NotePoolClear(&seqPlayer->notePool); + AudioList_ClearNotePool(&seqPlayer->notePool); break; case 0xDF: // seqPlayer: transpose @@ -2281,7 +2282,7 @@ void AudioScript_InitSequencePlayer(SequencePlayer* seqPlayer) { seqPlayer->fadeVolumeScale = 1.0f; seqPlayer->bend = 1.0f; - AudioPlayback_InitNoteLists(&seqPlayer->notePool); + AudioList_InitNoteLists(&seqPlayer->notePool); AudioScript_ResetSequencePlayer(seqPlayer); } diff --git a/src/audio/lib/synthesis.c b/src/audio/lib/synthesis.c index 0e95b4a99d..7793cce331 100644 --- a/src/audio/lib/synthesis.c +++ b/src/audio/lib/synthesis.c @@ -1,4 +1,5 @@ #include "global.h" +#include "audio/synthesis.h" // DMEM Addresses for the RSP #define DMEM_TEMP 0x3B0 diff --git a/tools/disasm/functions.txt b/tools/disasm/functions.txt index a10a842f0b..a68c73984f 100644 --- a/tools/disasm/functions.txt +++ b/tools/disasm/functions.txt @@ -3741,14 +3741,14 @@ 0x80195C60:("AudioPlayback_SeqLayerNoteRelease",), 0x80195C80:("AudioPlayback_BuildSyntheticWave",), 0x80195D84:("AudioPlayback_InitSyntheticWave",), - 0x80195DDC:("AudioPlayback_InitNoteList",), - 0x80195DEC:("AudioPlayback_InitNoteLists",), - 0x80195E3C:("AudioPlayback_InitNoteFreeList",), - 0x80195EE0:("AudioPlayback_NotePoolClear",), - 0x80196040:("AudioPlayback_NotePoolFill",), - 0x8019617C:("AudioPlayback_AudioListPushFront",), - 0x801961BC:("AudioPlayback_AudioListRemove",), - 0x801961E8:("AudioPlayback_FindNodeWithPrioLessThan",), + 0x80195DDC:("AudioList_InitNoteList",), + 0x80195DEC:("AudioList_InitNoteLists",), + 0x80195E3C:("AudioList_InitNoteFreeList",), + 0x80195EE0:("AudioList_ClearNotePool",), + 0x80196040:("AudioList_FillNotePool",), + 0x8019617C:("AudioList_PushFront",), + 0x801961BC:("AudioList_Remove",), + 0x801961E8:("AudioList_FindNodeWithPrioLessThan",), 0x80196268:("AudioPlayback_NoteInitForLayer",), 0x801963E8:("func_801963E8",), 0x8019641C:("AudioPlayback_NoteReleaseAndTakeOwnership",), @@ -3779,8 +3779,8 @@ 0x80197C8C:("AudioScript_SequenceChannelEnable",), 0x80197D24:("AudioScript_SequencePlayerDisableAsFinished",), 0x80197D4C:("AudioScript_SequencePlayerDisable",), - 0x80197E08:("AudioScript_AudioListPushBack",), - 0x80197E48:("AudioScript_AudioListPopBack",), + 0x80197E08:("AudioList_PushBack",), + 0x80197E48:("AudioList_PopBack",), 0x80197E88:("AudioScript_InitLayerFreelist",), 0x80197F28:("AudioScript_ScriptReadU8",), 0x80197F3C:("AudioScript_ScriptReadS16",), diff --git a/tools/sizes/code_functions.csv b/tools/sizes/code_functions.csv index a28e015725..3fc575e9c9 100644 --- a/tools/sizes/code_functions.csv +++ b/tools/sizes/code_functions.csv @@ -3258,14 +3258,14 @@ asm/non_matchings/code/audio_playback/AudioPlayback_SeqLayerNoteDecay.s,AudioPla asm/non_matchings/code/audio_playback/AudioPlayback_SeqLayerNoteRelease.s,AudioPlayback_SeqLayerNoteRelease,0x80195C60,0x8 asm/non_matchings/code/audio_playback/AudioPlayback_BuildSyntheticWave.s,AudioPlayback_BuildSyntheticWave,0x80195C80,0x41 asm/non_matchings/code/audio_playback/AudioPlayback_InitSyntheticWave.s,AudioPlayback_InitSyntheticWave,0x80195D84,0x16 -asm/non_matchings/code/audio_playback/AudioPlayback_InitNoteList.s,AudioPlayback_InitNoteList,0x80195DDC,0x4 -asm/non_matchings/code/audio_playback/AudioPlayback_InitNoteLists.s,AudioPlayback_InitNoteLists,0x80195DEC,0x14 -asm/non_matchings/code/audio_playback/AudioPlayback_InitNoteFreeList.s,AudioPlayback_InitNoteFreeList,0x80195E3C,0x29 -asm/non_matchings/code/audio_playback/AudioPlayback_NotePoolClear.s,AudioPlayback_NotePoolClear,0x80195EE0,0x58 -asm/non_matchings/code/audio_playback/AudioPlayback_NotePoolFill.s,AudioPlayback_NotePoolFill,0x80196040,0x4F -asm/non_matchings/code/audio_playback/AudioPlayback_AudioListPushFront.s,AudioPlayback_AudioListPushFront,0x8019617C,0x10 -asm/non_matchings/code/audio_playback/AudioPlayback_AudioListRemove.s,AudioPlayback_AudioListRemove,0x801961BC,0xB -asm/non_matchings/code/audio_playback/AudioPlayback_FindNodeWithPrioLessThan.s,AudioPlayback_FindNodeWithPrioLessThan,0x801961E8,0x20 +asm/non_matchings/code/audio_playback/AudioList_InitNoteList.s,AudioList_InitNoteList,0x80195DDC,0x4 +asm/non_matchings/code/audio_playback/AudioList_InitNoteLists.s,AudioList_InitNoteLists,0x80195DEC,0x14 +asm/non_matchings/code/audio_playback/AudioList_InitNoteFreeList.s,AudioList_InitNoteFreeList,0x80195E3C,0x29 +asm/non_matchings/code/audio_playback/AudioList_ClearNotePool.s,AudioList_ClearNotePool,0x80195EE0,0x58 +asm/non_matchings/code/audio_playback/AudioList_FillNotePool.s,AudioList_FillNotePool,0x80196040,0x4F +asm/non_matchings/code/audio_playback/AudioList_PushFront.s,AudioList_PushFront,0x8019617C,0x10 +asm/non_matchings/code/audio_playback/AudioList_Remove.s,AudioList_Remove,0x801961BC,0xB +asm/non_matchings/code/audio_playback/AudioList_FindNodeWithPrioLessThan.s,AudioList_FindNodeWithPrioLessThan,0x801961E8,0x20 asm/non_matchings/code/audio_playback/AudioPlayback_NoteInitForLayer.s,AudioPlayback_NoteInitForLayer,0x80196268,0x60 asm/non_matchings/code/audio_playback/func_801963E8.s,func_801963E8,0x801963E8,0xD asm/non_matchings/code/audio_playback/AudioPlayback_NoteReleaseAndTakeOwnership.s,AudioPlayback_NoteReleaseAndTakeOwnership,0x8019641C,0xB @@ -3296,8 +3296,8 @@ asm/non_matchings/code/audio_seqplayer/AudioScript_SequencePlayerDisableChannels asm/non_matchings/code/audio_seqplayer/AudioScript_SequenceChannelEnable.s,AudioScript_SequenceChannelEnable,0x80197C8C,0x26 asm/non_matchings/code/audio_seqplayer/AudioScript_SequencePlayerDisableAsFinished.s,AudioScript_SequencePlayerDisableAsFinished,0x80197D24,0xA asm/non_matchings/code/audio_seqplayer/AudioScript_SequencePlayerDisable.s,AudioScript_SequencePlayerDisable,0x80197D4C,0x2F -asm/non_matchings/code/audio_seqplayer/AudioScript_AudioListPushBack.s,AudioScript_AudioListPushBack,0x80197E08,0x10 -asm/non_matchings/code/audio_seqplayer/AudioScript_AudioListPopBack.s,AudioScript_AudioListPopBack,0x80197E48,0x10 +asm/non_matchings/code/audio_seqplayer/AudioList_PushBack.s,AudioList_PushBack,0x80197E08,0x10 +asm/non_matchings/code/audio_seqplayer/AudioList_PopBack.s,AudioList_PopBack,0x80197E48,0x10 asm/non_matchings/code/audio_seqplayer/AudioScript_InitLayerFreelist.s,AudioScript_InitLayerFreelist,0x80197E88,0x28 asm/non_matchings/code/audio_seqplayer/AudioScript_ScriptReadU8.s,AudioScript_ScriptReadU8,0x80197F28,0x5 asm/non_matchings/code/audio_seqplayer/AudioScript_ScriptReadS16.s,AudioScript_ScriptReadS16,0x80197F3C,0xE