[Audio 6/?] Build Soundfonts and the Soundfont Table (#1675)

* [Audio 6/?] Build Soundfonts and the Soundfont Table

* Fix bss

* Maybe fix warnings

* Improve lots of error messages

* Suggested changes from OoT PR

* Suggested changes

* Make soundfont_table.h generation depend on the samplebank xmls since they are read, report from which soundfont the invalid pointer indirect warning originates from
This commit is contained in:
Tharo
2024-08-28 02:09:48 +01:00
committed by GitHub
parent 98d9571f51
commit 7210cfac2f
28 changed files with 2776 additions and 50 deletions
+3 -3
View File
@@ -1694,9 +1694,9 @@ void AudioHeap_InitReverb(s32 reverbIndex, ReverbSettings* settings, s32 isFirst
reverb->sample.medium = MEDIUM_RAM;
reverb->sample.size = reverb->delayNumSamples * SAMPLE_SIZE;
reverb->sample.sampleAddr = (u8*)reverb->leftReverbBuf;
reverb->loop.start = 0;
reverb->loop.count = 1;
reverb->loop.loopEnd = reverb->delayNumSamples;
reverb->loop.header.start = 0;
reverb->loop.header.count = 1;
reverb->loop.header.loopEnd = reverb->delayNumSamples;
AudioHeap_SetReverbData(reverbIndex, REVERB_DATA_TYPE_FILTER_LEFT, settings->lowPassFilterCutoffLeft, isFirstInit);
AudioHeap_SetReverbData(reverbIndex, REVERB_DATA_TYPE_FILTER_RIGHT, settings->lowPassFilterCutoffRight,
+1 -1
View File
@@ -1302,7 +1302,7 @@ void AudioLoad_Init(void* heap, size_t heapSize) {
// Connect audio tables to their tables in memory
gAudioCtx.sequenceTable = (AudioTable*)gSequenceTable;
gAudioCtx.soundFontTable = (AudioTable*)gSoundFontTable;
gAudioCtx.soundFontTable = &gSoundFontTable;
gAudioCtx.sampleBankTable = &gSampleBankTable;
gAudioCtx.sequenceFontTable = gSequenceFontTable;
+2 -2
View File
@@ -861,10 +861,10 @@ void AudioPlayback_NoteInitForLayer(Note* note, SequenceLayer* layer) {
if (noteSampleState->bitField1.isSyntheticWave) {
AudioPlayback_BuildSyntheticWave(note, layer, instId);
} else if (channel->startSamplePos == 1) {
playbackState->startSamplePos = noteSampleState->tunedSample->sample->loop->start;
playbackState->startSamplePos = noteSampleState->tunedSample->sample->loop->header.start;
} else {
playbackState->startSamplePos = channel->startSamplePos;
if (playbackState->startSamplePos >= noteSampleState->tunedSample->sample->loop->loopEnd) {
if (playbackState->startSamplePos >= noteSampleState->tunedSample->sample->loop->header.loopEnd) {
playbackState->startSamplePos = 0;
}
}
+1 -1
View File
@@ -980,7 +980,7 @@ s32 AudioScript_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) {
if (layer->delay == 0) {
if (layer->tunedSample != NULL) {
time = layer->tunedSample->sample->loop->loopEnd;
time = layer->tunedSample->sample->loop->header.loopEnd;
} else {
time = 0.0f;
}
+7 -7
View File
@@ -985,10 +985,10 @@ Acmd* AudioSynth_ProcessSample(s32 noteIndex, NoteSampleState* sampleState, Note
synthState->stopLoop = true;
}
if ((loopInfo->count == 2) && synthState->stopLoop) {
sampleEndPos = loopInfo->sampleEnd;
if ((loopInfo->header.count == 2) && synthState->stopLoop) {
sampleEndPos = loopInfo->header.sampleEnd;
} else {
sampleEndPos = loopInfo->loopEnd;
sampleEndPos = loopInfo->header.loopEnd;
}
sampleAddr = sample->sampleAddr;
@@ -1028,7 +1028,7 @@ Acmd* AudioSynth_ProcessSample(s32 noteIndex, NoteSampleState* sampleState, Note
break;
}
numEntries = SAMPLES_PER_FRAME * sample->book->order * sample->book->numPredictors;
numEntries = SAMPLES_PER_FRAME * sample->book->header.order * sample->book->header.numPredictors;
aLoadADPCM(cmd++, numEntries, gAudioCtx.adpcmCodeBook);
}
}
@@ -1066,8 +1066,8 @@ Acmd* AudioSynth_ProcessSample(s32 noteIndex, NoteSampleState* sampleState, Note
numSamplesInFirstFrame = numSamplesUntilEnd;
}
numFramesToDecode = (numSamplesToDecode + SAMPLES_PER_FRAME - 1) / SAMPLES_PER_FRAME;
if (loopInfo->count != 0) {
if ((loopInfo->count == 2) && synthState->stopLoop) {
if (loopInfo->header.count != 0) {
if ((loopInfo->header.count == 2) && synthState->stopLoop) {
sampleFinished = true;
} else {
// Loop around and restart
@@ -1293,7 +1293,7 @@ Acmd* AudioSynth_ProcessSample(s32 noteIndex, NoteSampleState* sampleState, Note
break; // break out of the for-loop
} else if (loopToPoint) {
synthState->atLoopPoint = true;
synthState->samplePosInt = loopInfo->start;
synthState->samplePosInt = loopInfo->header.start;
} else {
synthState->samplePosInt += numSamplesToProcess;
}
+1 -1
View File
@@ -903,7 +903,7 @@ s32 AudioThread_GetSamplePos(s32 seqPlayerIndex, s32 channelIndex, s32 layerInde
if (tunedSample == NULL) {
return false;
}
*loopEnd = tunedSample->sample->loop->loopEnd;
*loopEnd = tunedSample->sample->loop->header.loopEnd;
*samplePosInt = note->synthesisState.samplePosInt;
return true;
}
+50
View File
@@ -0,0 +1,50 @@
#include "attributes.h"
#include "z64audio.h"
// Symbol definition
extern AudioTable gSoundFontTable;
#pragma weak gSoundFontTable = sSoundFontTableHeader
// Externs for table
#define DEFINE_SOUNDFONT(name, medium, cachePolicy, sampleBankNormal, sampleBankDD, nInstruments, nDrums, nSfx) \
extern u8 name##_Start[]; \
extern u8 name##_Size[];
#include "assets/audio/soundfont_table.h"
#undef DEFINE_SOUNDFONT
// Table header
NO_REORDER AudioTableHeader sSoundFontTableHeader = {
// The table contains the number of soundfonts, count them with the preprocessor
#define DEFINE_SOUNDFONT(name, medium, cachePolicy, sampleBankNormal, sampleBankDD, nInstruments, nDrums, nSfx) 1 +
#include "assets/audio/soundfont_table.h"
#undef DEFINE_SOUNDFONT
0,
0,
0x00000000,
{ 0, 0, 0, 0, 0, 0, 0, 0 },
};
// Table body
NO_REORDER AudioTableEntry sSoundFontTableEntries[] = {
#define DEFINE_SOUNDFONT(name, medium, cachePolicy, sampleBankNormal, sampleBankDD, nInstruments, nDrums, nSfx) \
{ (u32)name##_Start, \
(u32)name##_Size, \
(medium), \
(cachePolicy), \
((sampleBankNormal) << 8) | (sampleBankDD), \
((nInstruments) << 8) | (nDrums), \
(nSfx) },
#include "assets/audio/soundfont_table.h"
#undef DEFINE_SOUNDFONT
};
-1
View File
@@ -1,4 +1,3 @@
#include "prevent_bss_reordering.h"
#include "global.h"
#include "z64pause_menu.h"