summaryrefslogtreecommitdiff
path: root/src/audio
diff options
context:
space:
mode:
authorTharo <17233964+Thar0@users.noreply.github.com>2024-08-28 02:09:59 +0100
committerGitHub <noreply@github.com>2024-08-27 21:09:59 -0400
commitaa97586659dbd24174258e0437ab9411a9747d3d (patch)
tree1927736915f7b6707bacdd70527b19899c05f637 /src/audio
parent17debe86206e8194b36cb5838cf6e9dc7f3a968b (diff)
[Audio 6/?] Build Soundfonts and the Soundfont Table (#2056)
* [Audio 6/?] Build Soundfonts and the Soundfont Table * Improve lots of error messages * First suggested changes * Make audio build debugging more friendly Co-authored-by: Dragorn421 <Dragorn421@users.noreply.github.com> * Some fixes from MM review * 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 --------- Co-authored-by: Dragorn421 <Dragorn421@users.noreply.github.com>
Diffstat (limited to 'src/audio')
-rw-r--r--src/audio/lib/heap.c6
-rw-r--r--src/audio/lib/load.c2
-rw-r--r--src/audio/lib/seqplayer.c2
-rw-r--r--src/audio/lib/synthesis.c8
-rw-r--r--src/audio/lib/thread.c2
-rw-r--r--src/audio/tables/soundfont_table.c50
6 files changed, 60 insertions, 10 deletions
diff --git a/src/audio/lib/heap.c b/src/audio/lib/heap.c
index e68ef6eec..a29e0d9c9 100644
--- a/src/audio/lib/heap.c
+++ b/src/audio/lib/heap.c
@@ -1002,9 +1002,9 @@ void AudioHeap_Init(void) {
reverb->sample.medium = MEDIUM_RAM;
reverb->sample.size = reverb->windowSize * SAMPLE_SIZE;
reverb->sample.sampleAddr = (u8*)reverb->leftRingBuf;
- reverb->loop.start = 0;
- reverb->loop.count = 1;
- reverb->loop.end = reverb->windowSize;
+ reverb->loop.header.start = 0;
+ reverb->loop.header.count = 1;
+ reverb->loop.header.end = reverb->windowSize;
if (reverb->downsampleRate != 1) {
reverb->unk_0E = 0x8000 / reverb->downsampleRate;
diff --git a/src/audio/lib/load.c b/src/audio/lib/load.c
index 807bab317..be87f5c45 100644
--- a/src/audio/lib/load.c
+++ b/src/audio/lib/load.c
@@ -1214,7 +1214,7 @@ void AudioLoad_Init(void* heap, u32 heapSize) {
// Set audio tables pointers
gAudioCtx.sequenceTable = (AudioTable*)gSequenceTable;
- gAudioCtx.soundFontTable = (AudioTable*)gSoundFontTable;
+ gAudioCtx.soundFontTable = &gSoundFontTable;
gAudioCtx.sampleBankTable = &gSampleBankTable;
gAudioCtx.sequenceFontTable = gSequenceFontTable;
diff --git a/src/audio/lib/seqplayer.c b/src/audio/lib/seqplayer.c
index 4caddea4e..11866bf61 100644
--- a/src/audio/lib/seqplayer.c
+++ b/src/audio/lib/seqplayer.c
@@ -946,7 +946,7 @@ s32 AudioSeq_SeqLayerProcessScriptStep4(SequenceLayer* layer, s32 cmd) {
if (layer->delay == 0) {
if (layer->tunedSample != NULL) {
- time = layer->tunedSample->sample->loop->end;
+ time = layer->tunedSample->sample->loop->header.end;
} else {
time = 0.0f;
}
diff --git a/src/audio/lib/synthesis.c b/src/audio/lib/synthesis.c
index b93494de4..2a84f0cde 100644
--- a/src/audio/lib/synthesis.c
+++ b/src/audio/lib/synthesis.c
@@ -796,7 +796,7 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
} else {
sample = noteSubEu->tunedSample->sample;
loopInfo = sample->loop;
- loopEndPos = loopInfo->end;
+ loopEndPos = loopInfo->header.end;
sampleAddr = (u32)sample->sampleAddr;
resampledTempLen = 0;
@@ -829,7 +829,7 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
if (1) {}
if (1) {}
if (1) {}
- nEntries = SAMPLES_PER_FRAME * sample->book->order * sample->book->numPredictors;
+ nEntries = SAMPLES_PER_FRAME * sample->book->header.order * sample->book->header.numPredictors;
aLoadADPCM(cmd++, nEntries, gAudioCtx.curLoadedBook);
}
}
@@ -861,7 +861,7 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
nSamplesInFirstFrame = nSamplesUntilLoopEnd;
}
nFramesToDecode = (nSamplesToDecode + SAMPLES_PER_FRAME - 1) / SAMPLES_PER_FRAME;
- if (loopInfo->count != 0) {
+ if (loopInfo->header.count != 0) {
// Loop around and restart
restart = true;
} else {
@@ -1019,7 +1019,7 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS
} else {
if (restart) {
synthState->restart = true;
- synthState->samplePosInt = loopInfo->start;
+ synthState->samplePosInt = loopInfo->header.start;
} else {
synthState->samplePosInt += nSamplesToProcess;
}
diff --git a/src/audio/lib/thread.c b/src/audio/lib/thread.c
index 22afc33fd..d1809c2d0 100644
--- a/src/audio/lib/thread.c
+++ b/src/audio/lib/thread.c
@@ -795,7 +795,7 @@ s32 func_800E6590(s32 seqPlayerIndex, s32 channelIndex, s32 layerIndex) {
if (tunedSample == NULL) {
return 0;
}
- loopEnd = tunedSample->sample->loop->end;
+ loopEnd = tunedSample->sample->loop->header.end;
samplePos = note->synthesisState.samplePosInt;
return loopEnd - samplePos;
}
diff --git a/src/audio/tables/soundfont_table.c b/src/audio/tables/soundfont_table.c
new file mode 100644
index 000000000..65d1fc9a5
--- /dev/null
+++ b/src/audio/tables/soundfont_table.c
@@ -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"
+ 0,
+
+#undef DEFINE_SOUNDFONT
+
+ 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
+};