diff options
| author | Tharo <17233964+Thar0@users.noreply.github.com> | 2024-08-28 02:09:48 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-27 18:09:48 -0700 |
| commit | 7210cfac2f6e5ca538d412c3811e4e2c11780db8 (patch) | |
| tree | 85f70d58ebdda8f6541b71b4cfc0ee80b40f2134 /src | |
| parent | 98d9571f51aa85279ae501707793848b1c3f6256 (diff) | |
[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
Diffstat (limited to 'src')
| -rw-r--r-- | src/audio/lib/heap.c | 6 | ||||
| -rw-r--r-- | src/audio/lib/load.c | 2 | ||||
| -rw-r--r-- | src/audio/lib/playback.c | 4 | ||||
| -rw-r--r-- | src/audio/lib/seqplayer.c | 2 | ||||
| -rw-r--r-- | src/audio/lib/synthesis.c | 14 | ||||
| -rw-r--r-- | src/audio/lib/thread.c | 2 | ||||
| -rw-r--r-- | src/audio/tables/soundfont_table.c | 50 | ||||
| -rw-r--r-- | src/code/z_player_call.c | 1 |
8 files changed, 65 insertions, 16 deletions
diff --git a/src/audio/lib/heap.c b/src/audio/lib/heap.c index 7ce5db79d..0ebd3b0c8 100644 --- a/src/audio/lib/heap.c +++ b/src/audio/lib/heap.c @@ -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, diff --git a/src/audio/lib/load.c b/src/audio/lib/load.c index 8c8439520..c5bc817ab 100644 --- a/src/audio/lib/load.c +++ b/src/audio/lib/load.c @@ -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; diff --git a/src/audio/lib/playback.c b/src/audio/lib/playback.c index ed478ff5c..a59dea519 100644 --- a/src/audio/lib/playback.c +++ b/src/audio/lib/playback.c @@ -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; } } diff --git a/src/audio/lib/seqplayer.c b/src/audio/lib/seqplayer.c index d6ae5d5d6..2fcd451d0 100644 --- a/src/audio/lib/seqplayer.c +++ b/src/audio/lib/seqplayer.c @@ -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; } diff --git a/src/audio/lib/synthesis.c b/src/audio/lib/synthesis.c index 7793cce33..129b43c6b 100644 --- a/src/audio/lib/synthesis.c +++ b/src/audio/lib/synthesis.c @@ -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; } diff --git a/src/audio/lib/thread.c b/src/audio/lib/thread.c index c1c232d82..38f0ca8d7 100644 --- a/src/audio/lib/thread.c +++ b/src/audio/lib/thread.c @@ -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; } diff --git a/src/audio/tables/soundfont_table.c b/src/audio/tables/soundfont_table.c new file mode 100644 index 000000000..85c58094e --- /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" + +#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 +}; diff --git a/src/code/z_player_call.c b/src/code/z_player_call.c index fdfe4c7dc..51a4a6d48 100644 --- a/src/code/z_player_call.c +++ b/src/code/z_player_call.c @@ -1,4 +1,3 @@ -#include "prevent_bss_reordering.h" #include "global.h" #include "z64pause_menu.h" |
