From 3035d3c09667ac9d4b36b68e289ed333cc6f022a Mon Sep 17 00:00:00 2001 From: Ryan Myers Date: Fri, 17 Sep 2021 21:48:28 -0400 Subject: [PATCH] Fix previous commit --- include/PR/libaudio.h | 47 +++++++++++++++++++++++++++++++++++-------- src/audio.c | 4 ++-- src/audio.h | 2 +- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/include/PR/libaudio.h b/include/PR/libaudio.h index 153d3eb9..fde5d00a 100644 --- a/include/PR/libaudio.h +++ b/include/PR/libaudio.h @@ -673,7 +673,9 @@ typedef ALMicroTime (*ALOscInit)(void **oscState,f32 *initVal, u8 oscType, typedef ALMicroTime (*ALOscUpdate)(void *oscState, f32 *updateVal); typedef void (*ALOscStop)(void *oscState); -/* Size: 0x8C bytes */ +/** + * Has an extra two bytes for the voice limit not found in standard implementations + * Size: 0x92 */ typedef struct { /* 0x00 */ ALPlayer node; /* note: must be first in structure */ /* 0x14 */ ALSynth *drvr; /* reference to the client driver */ @@ -696,8 +698,7 @@ typedef struct { /* 0x6C */ ALVoiceState *vFreeList; /* list of free voice state structs */ /* 0x70 */ u8 voiceLimit; /* 0x71 */ u8 mappedVoices; - /* 0x72 */ u8 unk72; // Might just be padding? - /* 0x73 */ u8 unk73; // Might just be padding? + /* 0x72 */ u16 unk72; /* Might just be padding? */ /* 0x74 */ ALOscInit initOsc; /* 0x78 */ ALOscUpdate updateOsc; /* 0x7C */ ALOscStop stopOsc; @@ -706,7 +707,39 @@ typedef struct { /* 0x88 */ s32 loopCount; /* -1 = loop forever, 0 = no loop */ } ALSeqPlayer; -/* Size: 0x80 bytes */ +/** + * This has an extra padded 4 bytes at the end for some reason. + * Size: 0x80 bytes */ +typedef struct { + ALPlayer node; /* note: must be first in structure */ + ALSynth *drvr; /* reference to the client driver */ + ALCSeq *target; /* current sequence */ + ALMicroTime curTime; + ALBank *bank; /* current ALBank */ + s32 uspt; /* microseconds per tick */ + s32 nextDelta; /* microseconds to next callback */ + s32 state; + u16 chanMask; /* active channels */ + s16 vol; /* overall sequence volume */ + u8 maxChannels; /* number of MIDI channels */ + u8 debugFlags; /* control which error get reported */ + ALEvent nextEvent; + ALEventQueue evtq; + ALMicroTime frameTime; + ALChanState *chanState; /* 16 channels for MIDI */ + ALVoiceState *vAllocHead; /* list head for allocated voices */ + ALVoiceState *vAllocTail; /* list tail for allocated voices */ + ALVoiceState *vFreeList; /* list of free voice state structs */ + ALOscInit initOsc; + ALOscUpdate updateOsc; + ALOscStop stopOsc; + s32 unk7C; /* Padded to match ALCSPlayer_Custom */ +} ALCSPlayer; + +/** + * This custom struct has a unk36 byte that is set to 0x7F in func_80002224. + * It is otherwise identical to the ALCSPlayer above, but we need to pad it's size to match + * Size: 0x80 bytes */ typedef struct { /* 0x00 */ ALPlayer node; /* note: must be first in structure */ /* 0x14 */ ALSynth *drvr; /* reference to the client driver */ @@ -721,9 +754,7 @@ typedef struct { /* 0x34 */ u8 maxChannels; /* number of MIDI channels */ /* 0x35 */ u8 debugFlags; /* control which error get reported */ /* 0x36 */ u8 unk36; - /* 0x37 */ u8 unk37; - /* 0x38 */ u8 unk38; // Might just be padding? - /* 0x39 */ u8 unk39; // Might just be padding? + /* 0x37 */ u8 unk37[3]; /* Padded to match ALCSPlayer */ /* 0x40 */ ALEvent nextEvent; /* 0x4C */ ALEventQueue evtq; /* 0x60 */ ALMicroTime frameTime; @@ -734,7 +765,7 @@ typedef struct { /* 0x74 */ ALOscInit initOsc; /* 0x78 */ ALOscUpdate updateOsc; /* 0x7C */ ALOscStop stopOsc; -} ALCSPlayer; +} ALCSPlayer_Custom; /* Maintain backwards compatibility with old routine names. */ #define alSeqpSetProgram alSeqpSetChlProgram diff --git a/src/audio.c b/src/audio.c index 571280a4..b59c2a67 100644 --- a/src/audio.c +++ b/src/audio.c @@ -744,7 +744,7 @@ u8 ALBankFile_80115D14_GetSoundDecayTime(u16 sndIndx) { } ALSeqPlayer *func_80002224(s32 _max_voices, s32 _max_events) { - ALCSPlayer *cseqp; + ALCSPlayer_Custom *cseqp; ALSeqpConfig config; config.maxVoices = _max_voices; @@ -756,7 +756,7 @@ ALSeqPlayer *func_80002224(s32 _max_voices, s32 _max_events) { config.updateOsc = NULL; config.stopOsc = NULL; - cseqp = (ALCSPlayer *) alHeapDBAlloc(NULL, 0, &gALHeap, 1, sizeof(ALCSPlayer)); + cseqp = (ALCSPlayer_Custom *) alHeapDBAlloc(NULL, 0, &gALHeap, 1, sizeof(ALCSPlayer_Custom)); alCSPNew(cseqp, &config); alCSPSetBank(cseqp, ALBankFile_80115D10->bankArray[0]); cseqp->unk36 = 0x7F; diff --git a/src/audio.h b/src/audio.h index 4dd272ce..32fda725 100644 --- a/src/audio.h +++ b/src/audio.h @@ -46,7 +46,7 @@ typedef struct unk80115D48 { void alCSPNew(ALCSPlayer *seqp, ALSeqpConfig *config); //lib/src/al/csplayer.c void alCSPSetBank(ALCSPlayer *seqp, ALBank *b); //lib/src/unknown_0C8660.c -void set_voice_limit(ALCSPlayer *seqp, u8 voiceLimit); //lib/src/mips1/alseqplayer.c +void set_voice_limit(ALSeqPlayer *seqp, u8 voiceLimit); //lib/src/mips1/alseqplayer.c void *alHeapDBAlloc(u8 *file, s32 line, ALHeap *hp, s32 num, s32 size); //lib/src/al/alHeapDBAlloc.c s32 alCSPSetChlPan(ALCSPlayer *seqp, u8 chan, ALPan pan); //lib/src/unknown_0C84E0.c void alCSPSetChlVol(ALCSPlayer *, u8 chan, u8 vol); //lib/src/unknown_0C84E0.c