1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-07-17 21:35:11 +00:00

Restructuring SoundFont Structs (#1277)

* Document fontData relocation

* Fix

* More cleanup

* typo

* sample -> sampleHeader

* Revert name

* Just a little more

* Another comment change

* Fix Drum

* fix

* K0BASE

* Update relocs

* consistency

* clearer phrasing

* Fix

* PR/Discord Suggestions

* typo

* Revert Sound Font Sample Struct for another PR

* Missed a function

* Organize structs, tuned samples

* New sound effects struct

* fix func name

* wave samples

* consistency

* Fix

* More suggestions

* PR Suggestions

* sample bank reloc

* Revert header description

* better text

* SoundFount Relocation: some cleanup (#6)

* `fontDataStartAddr` for relocation, `fontData` for reading data (`AudioLoad_RelocateFont`)

* Comment "cleanup" in `AudioLoad_RelocateFont`

* Comment "cleanup" in `AudioLoad_RelocateSample`

* Cleanup cast and compares to 0 (offsets) / NULL (pointers)

* Cleanup

* soundFont info

* Revert waveSamples

* cleanup

* Plural

* PR suggestions

* A few name changes and suggestions

* small changes

* Drop Info on SoundFont

* Missed some

* One more function change

Co-authored-by: Dragorn421 <Dragorn421@users.noreply.github.com>
This commit is contained in:
engineer124 2022-06-19 07:31:08 -07:00 committed by GitHub
parent 849fdbf9ea
commit 38de9405e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 254 additions and 246 deletions

View file

@ -1847,10 +1847,10 @@ void Audio_NoteSetResamplingRate(NoteSubEu* noteSubEu, f32 resamplingRateInput);
void Audio_NoteInit(Note* note);
void Audio_NoteDisable(Note* note);
void Audio_ProcessNotes(void);
SoundFontSound* Audio_InstrumentGetSound(Instrument* instrument, s32 semitone);
TunedSample* Audio_GetInstrumentTunedSample(Instrument* instrument, s32 semitone);
Instrument* Audio_GetInstrumentInner(s32 fontId, s32 instId);
Drum* Audio_GetDrum(s32 fontId, s32 drumId);
SoundFontSound* Audio_GetSfx(s32 fontId, s32 sfxId);
SoundEffect* Audio_GetSoundEffect(s32 fontId, s32 sfxId);
s32 Audio_SetFontInstrument(s32 instrumentType, s32 fontId, s32 index, void* value);
void Audio_SeqLayerDecayRelease(SequenceLayer* layer, s32 target);
void Audio_SeqLayerNoteDecay(SequenceLayer* layer);
@ -1881,7 +1881,7 @@ f32 Audio_GetVibratoFreqScale(VibratoState* vib);
void Audio_NoteVibratoUpdate(Note* note);
void Audio_NoteVibratoInit(Note* note);
void Audio_NotePortamentoInit(Note* note);
void Audio_AdsrInit(AdsrState* adsr, AdsrEnvelope* envelope, s16* volOut);
void Audio_AdsrInit(AdsrState* adsr, EnvelopePoint* envelope, s16* volOut);
f32 Audio_AdsrUpdate(AdsrState* adsr);
void AudioSeq_SequenceChannelDisable(SequenceChannel* channel);
void AudioSeq_SequencePlayerDisableAsFinished(SequencePlayer* seqPlayer);

View file

@ -118,7 +118,7 @@ extern f32 gBendPitchTwoSemitonesFrequencies[256];
extern f32 gPitchFrequencies[];
extern u8 gDefaultShortNoteVelocityTable[16];
extern u8 gDefaultShortNoteGateTimeTable[16];
extern AdsrEnvelope gDefaultEnvelope[4];
extern EnvelopePoint gDefaultEnvelope[4];
extern NoteSubEu gZeroNoteSub;
extern NoteSubEu gDefaultNoteSub;
extern u16 gHeadsetPanQuantization[64];

View file

@ -115,20 +115,20 @@ typedef struct {
typedef struct {
/* 0x0 */ s16 delay;
/* 0x2 */ s16 arg;
} AdsrEnvelope; // size = 0x4
} EnvelopePoint; // size = 0x4
typedef struct {
/* 0x00 */ u32 start;
/* 0x04 */ u32 end;
/* 0x08 */ u32 count;
/* 0x0C */ char unk_0C[0x4];
/* 0x10 */ s16 state[16]; // only exists if count != 0. 8-byte aligned
/* 0x10 */ s16 predictorState[16]; // only exists if count != 0. 8-byte aligned
} AdpcmLoop; // size = 0x30 (or 0x10)
typedef struct {
/* 0x00 */ s32 order;
/* 0x04 */ s32 npredictors;
/* 0x08 */ s16 book[1]; // size 8 * order * npredictors. 8-byte aligned
/* 0x04 */ s32 numPredictors;
/* 0x08 */ s16 book[1]; // size 8 * order * numPredictors. 8-byte aligned
} AdpcmBook; // size >= 0x8
typedef struct {
@ -140,12 +140,49 @@ typedef struct {
/* 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
} SoundFontSample; // size = 0x10
} 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 */ 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 */ 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 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
/**
* Stores parsed information from soundfont data
*/
typedef struct {
/* 0x00 */ u8 numInstruments;
/* 0x01 */ u8 numDrums;
/* 0x02 */ u8 sampleBankId1;
/* 0x03 */ u8 sampleBankId2;
/* 0x04 */ u16 numSfx;
/* 0x08 */ Instrument** instruments;
/* 0x0C */ Drum** drums;
/* 0x10 */ SoundEffect* soundEffects;
} SoundFont; // size = 0x14
typedef struct {
/* 0x00 */ s16 numSamplesAfterDownsampling; // never read
@ -195,41 +232,11 @@ typedef struct {
/* 0x274 */ s16* filterRight;
/* 0x278 */ s16* filterLeftState;
/* 0x27C */ s16* filterRightState;
/* 0x280 */ SoundFontSound sound;
/* 0x288 */ SoundFontSample sample;
/* 0x280 */ TunedSample tunedSample;
/* 0x288 */ Sample sample;
/* 0x298 */ AdpcmLoop loop;
} SynthesisReverb; // size = 0x2C8
typedef struct {
/* 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 */ AdsrEnvelope* envelope;
/* 0x08 */ SoundFontSound lowNotesSound;
/* 0x10 */ SoundFontSound normalNotesSound;
/* 0x18 */ SoundFontSound highNotesSound;
} Instrument; // size = 0x20
typedef struct {
/* 0x00 */ u8 adsrDecayIndex; // index used to obtain adsr decay rate from adsrDecayTable
/* 0x01 */ u8 pan;
/* 0x02 */ u8 isRelocated; // have sound.sample and envelope been relocated (offsets to pointers)
/* 0x04 */ SoundFontSound sound;
/* 0x0C */ AdsrEnvelope* envelope;
} Drum; // size = 0x10
typedef struct {
/* 0x00 */ u8 numInstruments;
/* 0x01 */ u8 numDrums;
/* 0x02 */ u8 sampleBankId1;
/* 0x03 */ u8 sampleBankId2;
/* 0x04 */ u16 numSfx;
/* 0x08 */ Instrument** instruments;
/* 0x0C */ Drum** drums;
/* 0x10 */ SoundFontSound* soundEffects;
} SoundFont; // size = 0x14
typedef struct {
/* 0x00 */ u8* pc; // program counter
/* 0x04 */ u8* stack[4];
@ -284,7 +291,7 @@ typedef struct {
typedef struct {
/* 0x0 */ u8 decayIndex; // index used to obtain adsr decay rate from adsrDecayTable
/* 0x1 */ u8 sustain;
/* 0x4 */ AdsrEnvelope* envelope;
/* 0x4 */ EnvelopePoint* envelope;
} AdsrSettings; // size = 0x8
typedef struct {
@ -306,7 +313,7 @@ typedef struct {
/* 0x10 */ f32 current;
/* 0x14 */ f32 target;
/* 0x18 */ char unk_18[4];
/* 0x1C */ AdsrEnvelope* envelope;
/* 0x1C */ EnvelopePoint* envelope;
} AdsrState; // size = 0x20
typedef struct {
@ -436,7 +443,7 @@ typedef struct SequenceLayer {
/* 0x40 */ f32 noteVelocity;
/* 0x44 */ f32 noteFreqScale;
/* 0x48 */ Instrument* instrument;
/* 0x4C */ SoundFontSound* sound;
/* 0x4C */ TunedSample* tunedSample;
/* 0x50 */ SequenceChannel* channel;
/* 0x54 */ SeqScriptState scriptState;
/* 0x70 */ AudioListItem listItem;
@ -531,9 +538,9 @@ typedef struct {
/* 0x0C */ u16 resamplingRateFixedPoint;
/* 0x0E */ u16 unk_0E;
/* 0x10 */ union {
SoundFontSound* soundFontSound;
TunedSample* tunedSample;
s16* samples; // used for synthetic waves
} sound;
};
/* 0x14 */ s16* filter;
/* 0x18 */ char pad_18[0x8];
} NoteSubEu; // size = 0x20
@ -690,7 +697,7 @@ typedef struct {
typedef struct {
/* 0x00 */ u32 endAndMediumKey;
/* 0x04 */ SoundFontSample* sample;
/* 0x04 */ Sample* sample;
/* 0x08 */ u8* ramAddr;
/* 0x0C */ u32 encodedInfo;
/* 0x10 */ s32 isFree;
@ -748,7 +755,7 @@ typedef struct {
/* 0x14 */ s32 state;
/* 0x18 */ s32 bytesRemaining;
/* 0x1C */ s8* status; // write-only
/* 0x20 */ SoundFontSample sample;
/* 0x20 */ Sample sample;
/* 0x30 */ OSMesgQueue msgQueue;
/* 0x48 */ OSMesg msg;
/* 0x4C */ OSIoMesg ioMesg;
@ -799,7 +806,7 @@ typedef struct {
/* 0x0014 */ NoteSubEu* noteSubsEu;
/* 0x0018 */ SynthesisReverb synthesisReverbs[4];
/* 0x0B38 */ char unk_0B38[0x30];
/* 0x0B68 */ SoundFontSample* usedSamples[128];
/* 0x0B68 */ Sample* usedSamples[128];
/* 0x0D68 */ AudioPreloadReq preloadSampleStack[128];
/* 0x1768 */ s32 numUsedSamples;
/* 0x176C */ s32 preloadSampleStackTop;
@ -836,7 +843,7 @@ typedef struct {
/* 0x2838 */ AudioTable* sampleBankTable;
/* 0x283C */ u8* sequenceFontTable;
/* 0x2840 */ u16 numSequences;
/* 0x2844 */ SoundFont* soundFonts;
/* 0x2844 */ SoundFont* soundFontList;
/* 0x2848 */ AudioBufferParameters audioBufferParameters;
/* 0x2870 */ f32 unk_2870;
/* 0x2874 */ s32 sampleDmaBufSize1;