1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-06-08 09:31:52 +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;

View file

@ -543,11 +543,11 @@ u8 gDefaultShortNoteGateTimeTable[] = {
229, 203, 177, 151, 139, 126, 113, 100, 87, 74, 61, 48, 36, 23, 10, 0,
};
AdsrEnvelope gDefaultEnvelope[] = {
EnvelopePoint gDefaultEnvelope[] = {
{ 1, 32000 },
{ 1000, 32000 },
{ -1, 0 },
{ 0, 0 },
{ ADSR_HANG, 0 },
{ ADSR_DISABLE, 0 },
};
NoteSubEu gZeroNoteSub = { 0 };

View file

@ -215,7 +215,7 @@ void Audio_NotePortamentoInit(Note* note) {
note->playbackState.portamento = note->playbackState.parentLayer->portamento;
}
void Audio_AdsrInit(AdsrState* adsr, AdsrEnvelope* envelope, s16* volOut) {
void Audio_AdsrInit(AdsrState* adsr, EnvelopePoint* envelope, s16* volOut) {
adsr->action.asByte = 0;
adsr->delay = 0;
adsr->envelope = envelope;

View file

@ -5,7 +5,7 @@ void AudioHeap_InitSampleCaches(u32 persistentSampleCacheSize, u32 temporarySamp
SampleCacheEntry* AudioHeap_AllocTemporarySampleCacheEntry(u32 size);
SampleCacheEntry* AudioHeap_AllocPersistentSampleCacheEntry(u32 size);
void AudioHeap_DiscardSampleCacheEntry(SampleCacheEntry* entry);
void AudioHeap_UnapplySampleCache(SampleCacheEntry* entry, SoundFontSample* sample);
void AudioHeap_UnapplySampleCache(SampleCacheEntry* entry, Sample* sample);
void AudioHeap_DiscardSampleCaches(void);
void AudioHeap_DiscardSampleBank(s32 sampleBankId);
void AudioHeap_DiscardSampleBanks(void);
@ -1004,9 +1004,9 @@ void AudioHeap_Init(void) {
reverb->bufSizePerChan = reverb->windowSize;
reverb->framesToIgnore = 2;
reverb->resampleFlags = 1;
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;
@ -1233,35 +1233,35 @@ SampleCacheEntry* AudioHeap_AllocTemporarySampleCacheEntry(u32 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 = Audio_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 = Audio_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 = Audio_GetSfx(fontId, sfxId);
if (sfx != NULL) {
AudioHeap_UnapplySampleCache(entry, sfx->sample);
for (sfxId = 0; sfxId < gAudioContext.soundFontList[fontId].numSfx; sfxId++) {
soundEffect = Audio_GetSoundEffect(fontId, sfxId);
if (soundEffect != NULL) {
AudioHeap_UnapplySampleCache(entry, soundEffect->tunedSample.sample);
}
}
}
@ -1274,8 +1274,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) {
if (AudioHeap_SearchCaches(FONT_TABLE, CACHE_EITHER, fontId) != NULL) {
@ -1287,7 +1287,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;
@ -1331,8 +1331,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;
}
@ -1359,7 +1359,7 @@ typedef struct {
u8 newMedium;
} StorageChange;
void AudioHeap_ChangeStorage(StorageChange* change, SoundFontSample* sample) {
void AudioHeap_ChangeStorage(StorageChange* change, Sample* sample) {
if (sample != NULL) {
u32 startAddr = change->oldAddr;
u32 endAddr = change->oldAddr + change->size;
@ -1394,7 +1394,7 @@ void AudioHeap_ApplySampleBankCacheInternal(s32 apply, s32 sampleBankId) {
s32 fontId;
Drum* drum;
Instrument* inst;
SoundFontSound* sfx;
SoundEffect* soundEffect;
u32* fakematch;
s32 pad[4];
@ -1425,8 +1425,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) {
@ -1439,30 +1439,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 = Audio_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 = Audio_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 = Audio_GetSfx(fontId, sfxId);
if (sfx != NULL) {
AudioHeap_ChangeStorage(&change, sfx->sample);
for (sfxId = 0; sfxId < gAudioContext.soundFontList[fontId].numSfx; sfxId++) {
soundEffect = Audio_GetSoundEffect(fontId, sfxId);
if (soundEffect != NULL) {
AudioHeap_ChangeStorage(&change, soundEffect->tunedSample.sample);
}
}
}

View file

@ -18,12 +18,12 @@ const s16 D_8014A6C0[] = {
// Sizes of everything on the init pool
#define AI_BUFFERS_SIZE (AIBUF_LEN * sizeof(s16) * ARRAY_COUNT(gAudioContext.aiBuffers))
#define SOUNDFONT_INFO_SIZE (NUM_SOUNDFONTS * sizeof(SoundFont))
#define SOUNDFONT_LIST_SIZE (NUM_SOUNDFONTS * sizeof(SoundFont))
#define PERMANENT_POOL_SIZE (SFX_SEQ_SIZE + SFX_SOUNDFONT_1_SIZE + SFX_SOUNDFONT_2_SIZE)
const AudioHeapInitSizes gAudioHeapInitSizes = {
ALIGN16(sizeof(gAudioHeap) - 0x100), // audio heap size
ALIGN16(PERMANENT_POOL_SIZE + AI_BUFFERS_SIZE + SOUNDFONT_INFO_SIZE), // init pool size
ALIGN16(PERMANENT_POOL_SIZE + AI_BUFFERS_SIZE + SOUNDFONT_LIST_SIZE), // init pool size
ALIGN16(PERMANENT_POOL_SIZE), // permanent pool size
};

View file

@ -29,13 +29,13 @@ typedef void SoundFontData;
/* forward declarations */
s32 AudioLoad_SyncInitSeqPlayerInternal(s32 playerIdx, s32 seqId, s32 skipTicks);
SoundFontData* AudioLoad_SyncLoadFont(u32 fontId);
SoundFontSample* AudioLoad_GetFontSample(s32 fontId, s32 instId);
Sample* AudioLoad_GetFontSample(s32 fontId, s32 instId);
void AudioLoad_ProcessAsyncLoads(s32 resetStatus);
void AudioLoad_ProcessAsyncLoadUnkMedium(AudioAsyncLoad* asyncLoad, s32 resetStatus);
void AudioLoad_ProcessAsyncLoad(AudioAsyncLoad* asyncLoad, s32 resetStatus);
void AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, SoundFontData* fontData, SampleBankRelocInfo* sampleBankReloc,
s32 async);
void AudioLoad_RelocateSample(SoundFontSound* sound, SoundFontData* fontData, SampleBankRelocInfo* sampleBankReloc);
void AudioLoad_RelocateSample(TunedSample* tunedSample, SoundFontData* fontData, SampleBankRelocInfo* sampleBankReloc);
void AudioLoad_DiscardFont(s32 fontId);
u32 AudioLoad_TrySyncLoadSampleBank(u32 sampleBankId, u32* outMedium, s32 noLoad);
void* AudioLoad_SyncLoad(u32 tableType, u32 tableId, s32* didAllocate);
@ -395,7 +395,7 @@ void AudioLoad_SyncLoadSeqParts(s32 seqId, s32 arg1) {
}
}
s32 AudioLoad_SyncLoadSample(SoundFontSample* sample, s32 fontId) {
s32 AudioLoad_SyncLoadSample(Sample* sample, s32 fontId) {
void* sampleAddr;
if (sample->isRelocated == true) {
@ -426,11 +426,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);
}
} else if (instId == 0x7F) {
Drum* drum = Audio_GetDrum(fontId, drumId);
@ -438,7 +438,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;
}
}
@ -630,8 +630,8 @@ SoundFontData* AudioLoad_SyncLoadFont(u32 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;
sampleBankReloc.sampleBankId1 = sampleBankId1;
sampleBankReloc.sampleBankId2 = sampleBankId2;
@ -800,15 +800,15 @@ AudioTable* AudioLoad_GetLoadTable(s32 tableType) {
* @param sampleBankReloc information on the sampleBank containing raw audio samples
*/
void AudioLoad_RelocateFont(s32 fontId, SoundFontData* fontDataStartAddr, SampleBankRelocInfo* sampleBankReloc) {
u32 soundOffset; // Relative offset from the beginning of fontData directly to the sound/envelope
u32 soundOffset; // Relative offset from the beginning of fontData directly to the tunedSample/envelope
u32 soundListOffset; // Relative offset from the beginning of fontData to the list of soundOffsets/sfxs
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;
s32 numDrums = gAudioContext.soundFontList[fontId].numDrums;
s32 numInstruments = gAudioContext.soundFontList[fontId].numInstruments;
s32 numSfx = gAudioContext.soundFontList[fontId].numSfx;
u32* fontData = (u32*)fontDataStartAddr;
// Relocate an offset (relative to the start of the font data) to a pointer (a ram address)
@ -837,10 +837,10 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* fontDataStartAddr, Sample
// The drum may be in the list multiple times and already relocated
if (!drum->isRelocated) {
AudioLoad_RelocateSample(&drum->sound, fontDataStartAddr, sampleBankReloc);
AudioLoad_RelocateSample(&drum->tunedSample, fontDataStartAddr, sampleBankReloc);
soundOffset = (u32)drum->envelope;
drum->envelope = (AdsrEnvelope*)RELOC_TO_RAM(soundOffset);
drum->envelope = (EnvelopePoint*)RELOC_TO_RAM(soundOffset);
drum->isRelocated = true;
}
@ -862,12 +862,12 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* fontDataStartAddr, Sample
// Loop through the sound effects
for (i = 0; i < numSfx; i++) {
// Get a pointer to the i'th sound effect
soundOffset = (u32)(((SoundFontSound*)fontData[1]) + i);
sfx = (SoundFontSound*)soundOffset;
soundOffset = (u32)(((SoundEffect*)fontData[1]) + i);
soundEffect = (SoundEffect*)soundOffset;
// Check for NULL (note: the pointer is guaranteed to be in fontData and can never be NULL)
if ((sfx != NULL) && ((u32)sfx->sample != 0)) {
AudioLoad_RelocateSample(sfx, fontDataStartAddr, sampleBankReloc);
if ((soundEffect != NULL) && ((u32)soundEffect->tunedSample.sample != 0)) {
AudioLoad_RelocateSample(&soundEffect->tunedSample, fontDataStartAddr, sampleBankReloc);
}
}
}
@ -892,19 +892,19 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* fontDataStartAddr, Sample
if (!inst->isRelocated) {
// Some instruments have a different sample for low pitches
if (inst->normalRangeLo != 0) {
AudioLoad_RelocateSample(&inst->lowNotesSound, fontDataStartAddr, sampleBankReloc);
AudioLoad_RelocateSample(&inst->lowPitchTunedSample, fontDataStartAddr, sampleBankReloc);
}
// Every instrument has a sample for the default range
AudioLoad_RelocateSample(&inst->normalNotesSound, fontDataStartAddr, sampleBankReloc);
AudioLoad_RelocateSample(&inst->normalPitchTunedSample, fontDataStartAddr, sampleBankReloc);
// Some instruments have a different sample for high pitches
if (inst->normalRangeHi != 0x7F) {
AudioLoad_RelocateSample(&inst->highNotesSound, fontDataStartAddr, sampleBankReloc);
AudioLoad_RelocateSample(&inst->highPitchTunedSample, fontDataStartAddr, sampleBankReloc);
}
soundOffset = (u32)inst->envelope;
inst->envelope = (AdsrEnvelope*)RELOC_TO_RAM(soundOffset);
inst->envelope = (EnvelopePoint*)RELOC_TO_RAM(soundOffset);
inst->isRelocated = true;
}
@ -913,10 +913,10 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* fontDataStartAddr, Sample
#undef FONT_DATA_RELOC
// Store the relocated pointers to the sound lists in the soundFonts meta-data struct
gAudioContext.soundFonts[fontId].drums = (Drum**)fontData[0];
gAudioContext.soundFonts[fontId].soundEffects = (SoundFontSound*)fontData[1];
gAudioContext.soundFonts[fontId].instruments = (Instrument**)(fontData + 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(u32 devAddr, u8* ramAddr, u32 size, s32 medium) {
@ -1112,8 +1112,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;
@ -1222,10 +1222,10 @@ void AudioLoad_Init(void* heap, u32 heapSize) {
AudioLoad_InitTable(gAudioContext.soundFontTable, (u32)_AudiobankSegmentRomStart, 0);
AudioLoad_InitTable(gAudioContext.sampleBankTable, (u32)_AudiotableSegmentRomStart, 0);
numFonts = gAudioContext.soundFontTable->numEntries;
gAudioContext.soundFonts = AudioHeap_Alloc(&gAudioContext.initPool, numFonts * sizeof(SoundFont));
gAudioContext.soundFontList = AudioHeap_Alloc(&gAudioContext.initPool, numFonts * sizeof(SoundFont));
for (i = 0; i < numFonts; i++) {
AudioLoad_InitSoundFontMeta(i);
AudioLoad_InitSoundFont(i);
}
ramAddr = AudioHeap_Alloc(&gAudioContext.initPool, gAudioHeapInitSizes.permanentPoolSize);
@ -1245,7 +1245,7 @@ void AudioLoad_InitSlowLoads(void) {
}
s32 AudioLoad_SlowLoadSample(s32 fontId, s32 instId, s8* status) {
SoundFontSample* sample;
Sample* sample;
AudioSlowLoad* slowLoad;
sample = AudioLoad_GetFontSample(fontId, instId);
@ -1294,8 +1294,8 @@ s32 AudioLoad_SlowLoadSample(s32 fontId, s32 instId, s8* status) {
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 = Audio_GetInstrumentInner(fontId, instId);
@ -1303,21 +1303,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 = Audio_GetDrum(fontId, instId - 0x80);
if (drum == NULL) {
return NULL;
}
sample = drum->sound.sample;
sample = drum->tunedSample.sample;
} else {
SoundFontSound* sound = Audio_GetSfx(fontId, instId - 0x100);
SoundEffect* soundEffect = Audio_GetSoundEffect(fontId, instId - 0x100);
if (sound == NULL) {
if (soundEffect == NULL) {
return NULL;
}
sample = sound->sample;
sample = soundEffect->tunedSample.sample;
}
return sample;
}
@ -1326,7 +1326,7 @@ void AudioLoad_Unused2(void) {
}
void AudioLoad_FinishSlowLoad(AudioSlowLoad* slowLoad) {
SoundFontSample* sample;
Sample* sample;
if (slowLoad->sample.sampleAddr == NULL) {
return;
@ -1561,8 +1561,8 @@ void AudioLoad_FinishAsyncLoad(AudioAsyncLoad* asyncLoad) {
case FONT_TABLE:
fontId = ASYNC_ID(retMsg);
sampleBankId1 = gAudioContext.soundFonts[fontId].sampleBankId1;
sampleBankId2 = gAudioContext.soundFonts[fontId].sampleBankId2;
sampleBankId1 = gAudioContext.soundFontList[fontId].sampleBankId1;
sampleBankId2 = gAudioContext.soundFontList[fontId].sampleBankId2;
sampleBankReloc.sampleBankId1 = sampleBankId1;
sampleBankReloc.sampleBankId2 = sampleBankId2;
sampleBankReloc.baseAddr1 =
@ -1640,26 +1640,26 @@ void AudioLoad_AsyncDmaUnkMedium(u32 devAddr, void* ramAddr, u32 size, s16 arg3)
}
/**
* Read and extract information from SoundFontSound and its SoundFontSample
* Read and extract information from TunedSample and its Sample
* contained in the soundFont binary loaded into ram
* SoundFontSound contains metadata on a sample used by a particular instrument/drum/sfx
* Also relocate offsets into pointers within this loaded SoundFontSound
* 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(SoundFontSound* sound, SoundFontData* fontData, SampleBankRelocInfo* sampleBankReloc) {
SoundFontSample* sample;
void AudioLoad_RelocateSample(TunedSample* tunedSample, SoundFontData* fontData, SampleBankRelocInfo* sampleBankReloc) {
Sample* sample;
void* reloc;
// Relocate an offset (relative to data loaded in ram at `base`) to a pointer (a ram address)
#define AUDIO_RELOC(offset, base) (reloc = (void*)((u32)(offset) + (u32)(base)))
// If this has not already been relocated
if ((u32)sound->sample <= AUDIO_RELOCATED_ADDRESS_START) {
if ((u32)tunedSample->sample <= AUDIO_RELOCATED_ADDRESS_START) {
sample = sound->sample = AUDIO_RELOC(sound->sample, fontData);
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
@ -1710,7 +1710,7 @@ void AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, SoundFontData* fontData
s32 isAsync) {
AudioPreloadReq* preload;
AudioPreloadReq* topPreload;
SoundFontSample* sample;
Sample* sample;
s32 size;
s32 nChunks;
u8* sampleRamAddr;
@ -1809,7 +1809,7 @@ void AudioLoad_RelocateFontAndPreloadSamples(s32 fontId, SoundFontData* fontData
}
s32 AudioLoad_ProcessSamplePreloads(s32 resetStatus) {
SoundFontSample* sample;
Sample* sample;
AudioPreloadReq* preload;
u32 preloadIndex;
u32 key;
@ -1870,7 +1870,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++) {
@ -1887,18 +1887,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 = Audio_GetDrum(fontId, i);
if (1) {}
if (drum != NULL) {
numSamples = AudioLoad_AddToSampleSet(drum->sound.sample, numSamples, sampleSet);
numSamples = AudioLoad_AddToSampleSet(drum->tunedSample.sample, numSamples, sampleSet);
}
}
@ -1907,12 +1907,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);
}
}
@ -1920,8 +1920,8 @@ 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;
@ -1934,13 +1934,13 @@ void AudioLoad_PreloadSamplesForFont(s32 fontId, s32 async, SampleBankRelocInfo*
s32 numSfx;
Drum* drum;
Instrument* instrument;
SoundFontSound* sound;
SoundEffect* soundEffect;
AudioPreloadReq* preload;
AudioPreloadReq* topPreload;
u8* addr;
s32 size;
s32 i;
SoundFontSample* sample;
Sample* sample;
s32 preloadInProgress;
s32 nChunks;
@ -1951,34 +1951,34 @@ void AudioLoad_PreloadSamplesForFont(s32 fontId, s32 async, SampleBankRelocInfo*
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 = Audio_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 = Audio_GetDrum(fontId, i);
if (drum != NULL) {
AudioLoad_AddUsedSample(&drum->sound);
AudioLoad_AddUsedSample(&drum->tunedSample);
}
}
for (i = 0; i < numSfx; i++) {
sound = Audio_GetSfx(fontId, i);
if (sound != NULL) {
AudioLoad_AddUsedSample(sound);
soundEffect = Audio_GetSoundEffect(fontId, i);
if (soundEffect != NULL) {
AudioLoad_AddUsedSample(&soundEffect->tunedSample);
}
}
@ -2076,8 +2076,8 @@ void AudioLoad_LoadPermanentSamples(void) {
if (gAudioContext.permanentCache[i].tableType == FONT_TABLE) {
fontId = AudioLoad_GetRealTableIndex(FONT_TABLE, gAudioContext.permanentCache[i].id);
sampleBankReloc.sampleBankId1 = gAudioContext.soundFonts[fontId].sampleBankId1;
sampleBankReloc.sampleBankId2 = gAudioContext.soundFonts[fontId].sampleBankId2;
sampleBankReloc.sampleBankId1 = gAudioContext.soundFontList[fontId].sampleBankId1;
sampleBankReloc.sampleBankId2 = gAudioContext.soundFontList[fontId].sampleBankId2;
if (sampleBankReloc.sampleBankId1 != 0xFF) {
sampleBankReloc.sampleBankId1 =

View file

@ -19,7 +19,7 @@ void Audio_InitNoteSub(Note* note, NoteSubEu* sub, NoteSubAttributes* attrs) {
sub->bitField0 = note->noteSubEu.bitField0;
sub->bitField1 = note->noteSubEu.bitField1;
sub->sound.samples = note->noteSubEu.sound.samples;
sub->samples = note->noteSubEu.samples;
sub->unk_06 = note->noteSubEu.unk_06;
Audio_NoteSetResamplingRate(sub, attrs->frequency);
@ -293,17 +293,17 @@ void Audio_ProcessNotes(void) {
}
}
SoundFontSound* Audio_InstrumentGetSound(Instrument* instrument, s32 semitone) {
SoundFontSound* sound;
TunedSample* Audio_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* Audio_GetInstrumentInner(s32 fontId, s32 instId) {
@ -318,12 +318,12 @@ Instrument* Audio_GetInstrumentInner(s32 fontId, s32 instId) {
return NULL;
}
if (instId >= gAudioContext.soundFonts[fontId].numInstruments) {
if (instId >= gAudioContext.soundFontList[fontId].numInstruments) {
gAudioContext.audioErrorFlags = ((fontId << 8) + instId) + 0x3000000;
return NULL;
}
inst = gAudioContext.soundFonts[fontId].instruments[instId];
inst = gAudioContext.soundFontList[fontId].instruments[instId];
if (inst == NULL) {
gAudioContext.audioErrorFlags = ((fontId << 8) + instId) + 0x1000000;
return inst;
@ -344,14 +344,14 @@ Drum* Audio_GetDrum(s32 fontId, s32 drumId) {
return NULL;
}
if (drumId >= gAudioContext.soundFonts[fontId].numDrums) {
if (drumId >= gAudioContext.soundFontList[fontId].numDrums) {
gAudioContext.audioErrorFlags = ((fontId << 8) + drumId) + 0x4000000;
return NULL;
}
if ((u32)gAudioContext.soundFonts[fontId].drums < AUDIO_RELOCATED_ADDRESS_START) {
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;
@ -360,8 +360,8 @@ Drum* Audio_GetDrum(s32 fontId, s32 drumId) {
return drum;
}
SoundFontSound* Audio_GetSfx(s32 fontId, s32 sfxId) {
SoundFontSound* sfx;
SoundEffect* Audio_GetSoundEffect(s32 fontId, s32 sfxId) {
SoundEffect* soundEffect;
if (fontId == 0xFF) {
return NULL;
@ -372,26 +372,26 @@ SoundFontSound* Audio_GetSfx(s32 fontId, s32 sfxId) {
return NULL;
}
if (sfxId >= gAudioContext.soundFonts[fontId].numSfx) {
if (sfxId >= gAudioContext.soundFontList[fontId].numSfx) {
gAudioContext.audioErrorFlags = ((fontId << 8) + sfxId) + 0x4000000;
return NULL;
}
if ((u32)gAudioContext.soundFonts[fontId].soundEffects < AUDIO_RELOCATED_ADDRESS_START) {
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) {
if (soundEffect == NULL) {
gAudioContext.audioErrorFlags = ((fontId << 8) + sfxId) + 0x5000000;
}
if (sfx->sample == NULL) {
if (soundEffect->tunedSample.sample == NULL) {
return NULL;
}
return sfx;
return soundEffect;
}
s32 Audio_SetFontInstrument(s32 instrumentType, s32 fontId, s32 index, void* value) {
@ -405,24 +405,24 @@ s32 Audio_SetFontInstrument(s32 instrumentType, s32 fontId, s32 index, void* val
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;
}
@ -559,7 +559,7 @@ s32 Audio_BuildSyntheticWave(Note* note, SequenceLayer* layer, s32 waveId) {
note->playbackState.waveId = waveId;
note->playbackState.sampleCountIndex = sampleCountIndex;
note->noteSubEu.sound.samples = &gWaveSamples[waveId - 128][sampleCountIndex * 64];
note->noteSubEu.samples = &gWaveSamples[waveId - 128][sampleCountIndex * 64];
return sampleCountIndex;
}
@ -763,7 +763,7 @@ void Audio_NoteInitForLayer(Note* note, SequenceLayer* layer) {
if (instId == 0xFF) {
instId = layer->channel->instOrWave;
}
sub->sound.soundFontSound = layer->sound;
sub->tunedSample = layer->tunedSample;
if (instId >= 0x80 && instId < 0xC0) {
sub->bitField1.isSyntheticWave = true;

View file

@ -488,7 +488,7 @@ void AudioSeq_SeqLayerProcessScriptStep1(SequenceLayer* layer);
s32 AudioSeq_SeqLayerProcessScriptStep2(SequenceLayer* layer);
s32 AudioSeq_SeqLayerProcessScriptStep3(SequenceLayer* layer, s32 cmd);
s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd);
s32 AudioSeq_SeqLayerProcessScriptStep5(SequenceLayer* layer, s32 sameSound);
s32 AudioSeq_SeqLayerProcessScriptStep5(SequenceLayer* layer, s32 sameTunedSample);
void AudioSeq_SeqLayerProcessScript(SequenceLayer* layer) {
s32 val;
@ -541,9 +541,9 @@ void AudioSeq_SeqLayerProcessScriptStep1(SequenceLayer* layer) {
layer->notePropertiesNeedInit = true;
}
s32 AudioSeq_SeqLayerProcessScriptStep5(SequenceLayer* layer, s32 sameSound) {
if (!layer->stopSomething && layer->sound != NULL && layer->sound->sample->codec == CODEC_S16_INMEMORY &&
layer->sound->sample->medium != MEDIUM_RAM) {
s32 AudioSeq_SeqLayerProcessScriptStep5(SequenceLayer* layer, s32 sameTunedSample) {
if (!layer->stopSomething && layer->tunedSample != NULL &&
layer->tunedSample->sample->codec == CODEC_S16_INMEMORY && layer->tunedSample->sample->medium != MEDIUM_RAM) {
layer->stopSomething = true;
return -1;
}
@ -552,13 +552,13 @@ s32 AudioSeq_SeqLayerProcessScriptStep5(SequenceLayer* layer, s32 sameSound) {
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) {
Audio_InitSyntheticWave(layer->note, layer);
}
} else {
if (sameSound == false) {
if (!sameTunedSample) {
Audio_SeqLayerNoteDecay(layer);
}
layer->note = Audio_AllocNote(layer);
@ -692,7 +692,7 @@ s32 AudioSeq_SeqLayerProcessScriptStep2(SequenceLayer* layer) {
case 0xCB:
sp3A = AudioSeq_ScriptReadS16(state);
layer->adsr.envelope = (AdsrEnvelope*)(seqPlayer->seqData + sp3A);
layer->adsr.envelope = (EnvelopePoint*)(seqPlayer->seqData + sp3A);
FALLTHROUGH;
case 0xCF:
layer->adsr.decayIndex = AudioSeq_ScriptReadU8(state);
@ -727,7 +727,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;
@ -735,10 +735,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;
@ -769,27 +769,28 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) {
layer->delay2 = layer->delay;
return -1;
}
sound = &drum->sound;
layer->adsr.envelope = (AdsrEnvelope*)drum->envelope;
tunedSample = &drum->tunedSample;
layer->adsr.envelope = (EnvelopePoint*)drum->envelope;
layer->adsr.decayIndex = (u8)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:
layer->semitone = semitone;
sfxId = (layer->transposition << 6) + semitone;
sound = Audio_GetSfx(channel->fontId, sfxId);
if (sound == NULL) {
soundEffect = Audio_GetSoundEffect(channel->fontId, sfxId);
if (soundEffect == NULL) {
layer->stopSomething = true;
layer->delay2 = layer->delay + 1;
return -1;
}
layer->sound = sound;
layer->freqScale = sound->tuning;
tunedSample = &soundEffect->tunedSample;
layer->tunedSample = tunedSample;
layer->freqScale = tunedSample->tuning;
break;
default:
@ -811,15 +812,15 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) {
vel = (semitone > layer->portamentoTargetNote) ? semitone : layer->portamentoTargetNote;
if (instrument != NULL) {
sound = Audio_InstrumentGetSound(instrument, vel);
sameSound = (layer->sound == sound);
layer->sound = sound;
tuning = sound->tuning;
tunedSample = Audio_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;
}
}
@ -873,15 +874,15 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) {
}
if (instrument != NULL) {
sound = Audio_InstrumentGetSound(instrument, semitone);
sameSound = (sound == layer->sound);
layer->sound = sound;
layer->freqScale = gPitchFrequencies[semitone2] * sound->tuning;
tunedSample = Audio_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;
@ -890,8 +891,8 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) {
layer->delay2 = layer->delay;
layer->freqScale *= layer->bend;
if (layer->delay == 0) {
if (layer->sound != NULL) {
time = (f32)layer->sound->sample->loop->end;
if (layer->tunedSample != NULL) {
time = (f32)layer->tunedSample->sample->loop->end;
} else {
time = 0.0f;
}
@ -920,7 +921,7 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) {
}
}
}
return sameSound;
return sameTunedSample;
}
s32 AudioSeq_SeqLayerProcessScriptStep3(SequenceLayer* layer, s32 cmd) {
@ -1241,7 +1242,7 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) {
case 0xDA:
offset = (u16)cmdArgs[0];
channel->adsr.envelope = (AdsrEnvelope*)&seqPlayer->seqData[offset];
channel->adsr.envelope = (EnvelopePoint*)&seqPlayer->seqData[offset];
break;
case 0xD9:

View file

@ -687,7 +687,7 @@ Acmd* AudioSynth_DoOneAudioUpdate(s16* aiBuf, s32 aiBufLen, Acmd* cmd, s32 updat
Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisState* synthState, s16* aiBuf,
s32 aiBufLen, Acmd* cmd, s32 updateIndex) {
s32 pad1[3];
SoundFontSample* sample;
Sample* sample;
AdpcmLoop* loopInfo;
s32 nSamplesUntilLoopEnd;
s32 nSamplesInThisIteration;
@ -778,7 +778,7 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
noteSamplesDmemAddrBeforeResampling = DMEM_UNCOMPRESSED_NOTE + (synthState->samplePosInt * 2);
synthState->samplePosInt += nSamplesToLoad;
} else {
sample = noteSubEu->sound.soundFontSound->sample;
sample = noteSubEu->tunedSample->sample;
loopInfo = sample->loop;
loopEndPos = loopInfo->end;
sampleAddr = (u32)sample->sampleAddr;
@ -812,7 +812,7 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
if (1) {}
if (1) {}
if (1) {}
nEntries = 16 * sample->book->order * sample->book->npredictors;
nEntries = 16 * sample->book->order * sample->book->numPredictors;
aLoadADPCM(cmd++, nEntries, gAudioContext.curLoadedBook);
}
}
@ -917,7 +917,7 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
}
if (synthState->restart) {
aSetLoop(cmd++, sample->loop->state);
aSetLoop(cmd++, sample->loop->predictorState);
flags = A_LOOP;
synthState->restart = false;
}
@ -1195,7 +1195,7 @@ Acmd* AudioSynth_LoadWaveSamples(Acmd* cmd, NoteSubEu* noteSubEu, NoteSynthesisS
gWaveSamples[8] += nSamplesToLoad * 2;
return cmd;
} else {
aLoadBuffer(cmd++, noteSubEu->sound.samples, DMEM_UNCOMPRESSED_NOTE, 0x80);
aLoadBuffer(cmd++, noteSubEu->samples, DMEM_UNCOMPRESSED_NOTE, 0x80);
if (unk6 != 0) {
samplePosInt = (samplePosInt * D_801304C0[unk6 >> 2]) / D_801304C0[unk6 & 3];
}

View file

@ -517,9 +517,9 @@ u8* func_800E5E84(s32 arg0, u32* arg1) {
return AudioLoad_GetFontsForSequence(arg0, arg1);
}
void func_800E5EA4(s32 arg0, u32* arg1, u32* arg2) {
*arg1 = gAudioContext.soundFonts[arg0].sampleBankId1;
*arg2 = gAudioContext.soundFonts[arg0].sampleBankId2;
void Audio_GetSampleBankIdsOfFont(s32 fontId, u32* sampleBankId1, u32* sampleBankId2) {
*sampleBankId1 = gAudioContext.soundFontList[fontId].sampleBankId1;
*sampleBankId2 = gAudioContext.soundFontList[fontId].sampleBankId2;
}
s32 func_800E5EDC(void) {
@ -784,7 +784,7 @@ s32 func_800E6590(s32 playerIdx, s32 arg1, s32 arg2) {
SequencePlayer* seqPlayer;
SequenceLayer* layer;
Note* note;
SoundFontSound* sound;
TunedSample* tunedSample;
s32 loopEnd;
s32 samplePos;
@ -806,11 +806,11 @@ s32 func_800E6590(s32 playerIdx, s32 arg1, s32 arg2) {
note = layer->note;
if (layer == note->playbackState.parentLayer) {
sound = note->noteSubEu.sound.soundFontSound;
if (sound == NULL) {
tunedSample = note->noteSubEu.tunedSample;
if (tunedSample == NULL) {
return 0;
}
loopEnd = sound->sample->loop->end;
loopEnd = tunedSample->sample->loop->end;
samplePos = note->synthesisState.samplePosInt;
return loopEnd - samplePos;
}
@ -834,7 +834,7 @@ s32 func_800E66C0(s32 arg0) {
NoteSubEu* temp_a3;
s32 i;
Note* note;
SoundFontSound* sound;
TunedSample* tunedSample;
phi_v1 = 0;
for (i = 0; i < gAudioContext.numNotes; i++) {
@ -844,11 +844,11 @@ s32 func_800E66C0(s32 arg0) {
temp_a3 = &note->noteSubEu;
if (temp_a2->adsr.action.s.state != 0) {
if (arg0 >= 2) {
sound = temp_a3->sound.soundFontSound;
if (sound == NULL || temp_a3->bitField1.isSyntheticWave) {
tunedSample = temp_a3->tunedSample;
if (tunedSample == NULL || temp_a3->bitField1.isSyntheticWave) {
continue;
}
if (sound->sample->medium == MEDIUM_RAM) {
if (tunedSample->sample->medium == MEDIUM_RAM) {
continue;
}
}