From 4acc13fb36523ba270b3b921ffd1328610e0a58c Mon Sep 17 00:00:00 2001 From: KiritoDv Date: Mon, 4 Nov 2024 01:02:27 -0600 Subject: [PATCH] Doing some more fixes --- include/sf64audio_provisional.h | 6 +++--- src/audio/audio_context.c | 6 +++--- src/audio/audio_load.c | 4 ++-- src/audio/audio_synthesis.c | 23 +++++++++++------------ src/audio/audio_thread.c | 2 +- src/audio/mixer.c | 14 +++++++++++--- src/audio/mixer.h | 2 +- 7 files changed, 32 insertions(+), 25 deletions(-) diff --git a/include/sf64audio_provisional.h b/include/sf64audio_provisional.h index 63bb5c3e..bb1214a9 100644 --- a/include/sf64audio_provisional.h +++ b/include/sf64audio_provisional.h @@ -1139,9 +1139,9 @@ extern AudioCommonPoolSplit gPersistentCommonPoolSplit; // 0x4 extern AudioCommonPoolSplit gTemporaryCommonPoolSplit; // 0x4 -extern u8 gSampleFontLoadStatus[64]; -extern u8 gFontLoadStatus[64]; -extern u8 gSeqLoadStatus[256]; +extern u8 gSampleFontLoadStatus[2048]; +extern u8 gFontLoadStatus[2048]; +extern u8 gSeqLoadStatus[2048]; extern volatile u8 gAudioResetStep; extern u8 gAudioSpecId; extern s32 gResetFadeoutFramesLeft; diff --git a/src/audio/audio_context.c b/src/audio/audio_context.c index 59f7a18c..8f33028c 100644 --- a/src/audio/audio_context.c +++ b/src/audio/audio_context.c @@ -31,9 +31,9 @@ AudioCommonPoolSplit gPersistentCommonPoolSplit; // 0x4 AudioCommonPoolSplit gTemporaryCommonPoolSplit; // 0x4 -u8 gSampleFontLoadStatus[64]; -u8 gFontLoadStatus[64]; -u8 gSeqLoadStatus[256]; +u8 gSampleFontLoadStatus[2048]; +u8 gFontLoadStatus[2048]; +u8 gSeqLoadStatus[2048]; volatile u8 gAudioResetStep; u8 gAudioSpecId; s32 gResetFadeoutFramesLeft; diff --git a/src/audio/audio_load.c b/src/audio/audio_load.c index 860ccfd9..ae690892 100644 --- a/src/audio/audio_load.c +++ b/src/audio/audio_load.c @@ -791,8 +791,8 @@ void* AudioLoad_AsyncLoadInner(s32 tableType, s32 id, s32 nChunks, s32 retData, void AudioLoad_ProcessLoads(s32 resetStatus) { AudioLoad_ProcessSlowLoads(resetStatus); - AudioLoad_ProcessSamplePreloads(resetStatus); - AudioLoad_ProcessAsyncLoads(resetStatus); + // AudioLoad_ProcessSamplePreloads(resetStatus); + // AudioLoad_ProcessAsyncLoads(resetStatus); } static const char devstr27[] = "Clear Workarea %x -%x size %x \n"; diff --git a/src/audio/audio_synthesis.c b/src/audio/audio_synthesis.c index e9a7d99d..f446bcc4 100644 --- a/src/audio/audio_synthesis.c +++ b/src/audio/audio_synthesis.c @@ -690,7 +690,7 @@ Acmd* func_80009D78(Acmd* aList, s32 aiBufLen, s16 reverbIndex, s16 updateIndex) if (sp64->lengthB != 0) { aList = func_800098DC(aList, sp64->lengthA + 0xC90, 0, sp64->lengthB, reverbIndex); } - aAddMixer(aList++, 0x300, 0xC90, 0x990, 0x7FFF); + aAddMixer(aList++, 0x300, 0xC90, 0x990); aMix(aList++, 0x30, gSynthReverbs[reverbIndex].decayRatio + 0x8000, 0xC90, 0xC90); } else { sp62 = (sp64->startPos & 7) * 2; @@ -705,7 +705,7 @@ Acmd* func_80009D78(Acmd* aList, s32 aiBufLen, s16 reverbIndex, s16 updateIndex) aSetBuffer(aList++, 0, sp62 + 0x5F0, 0xE10, aiBufLen * 2); aResample(aList++, gSynthReverbs[reverbIndex].resampleFlags, gSynthReverbs[reverbIndex].unk_0A, OS_K0_TO_PHYSICAL(gSynthReverbs[reverbIndex].unk_34)); - aAddMixer(aList++, 0x300, 0xC90, 0x990, 0x7FFF); + aAddMixer(aList++, 0x300, 0xC90, 0x990); aMix(aList++, 0x30, gSynthReverbs[reverbIndex].decayRatio + 0x8000, 0xC90, 0xC90); } @@ -837,7 +837,7 @@ Acmd* func_8000A700(s32 noteIndex, NoteSubEu* noteSub, NoteSynthesisState* synth s32 padC8; s32 samplesLenAdjusted; // spC4 s32 nAdpcmSamplesProcessed; // spC0 - u32 endPos; // spBC + uintptr_t endPos; // spBC s32 nSamplesToProcess; // spB8 s32 padB4; s32 padB0; @@ -856,12 +856,12 @@ Acmd* func_8000A700(s32 noteIndex, NoteSubEu* noteSub, NoteSynthesisState* synth s32 nParts; // sp7C s32 curPart; // sp78 s32 nSamplesInThisIteration; - s32 sampleDataStartPad; + uintptr_t sampleDataStartPad; s32 resampledTempLen; // sp6C u16 noteSamplesDmemAddrBeforeResampling; // sp6A s32 samplesRemaining; s32 frameIndex; - s32 sampleDataOffset; + uintptr_t sampleDataOffset; Note* note; // sp58 u16 sp56; // sp56 @@ -878,7 +878,7 @@ Acmd* func_8000A700(s32 noteIndex, NoteSubEu* noteSub, NoteSynthesisState* synth u32 nEntries; s32 aligned; s32 align2; - u16 addr; + uintptr_t addr; currentBook = NULL; note = &gNotes[noteIndex]; @@ -1000,19 +1000,18 @@ Acmd* func_8000A700(s32 noteIndex, NoteSubEu* noteSub, NoteSynthesisState* synth skipBytes = 0; goto skip; } - aligned = ALIGN16(nFramesToDecode * frameSize + 0x10); + aligned = ALIGN16(nFramesToDecode * frameSize + SAMPLES_PER_FRAME); addr = 0x990 - aligned; if (nFramesToDecode != 0) { // LTODO: Validate this // bookSample->medium = 0; - frameIndex = (synthState->samplePosInt + skipInitialSamples - nFirstFrameSamplesToIgnore) / 16; + frameIndex = (synthState->samplePosInt + skipInitialSamples - nFirstFrameSamplesToIgnore) / SAMPLES_PER_FRAME; sampleDataOffset = frameIndex * frameSize; if (bookSample->medium == 0) { - sampleData = sampleDmaStart + sampleDataOffset + sampleAddr; + sampleData = sampleDataOffset + sampleAddr; } else { - sampleData = AudioLoad_DmaSampleData(sampleDmaStart + sampleDataOffset + sampleAddr, aligned, - flags, &synthState->sampleDmaIndex, bookSample->medium); + sampleData = sampleDataOffset + sampleAddr; } // if (1){} sampleDataStartPad = (uintptr_t) sampleData & 0xF; @@ -1318,7 +1317,7 @@ Acmd* func_8000B98C(Acmd* aList, NoteSubEu* noteSub, NoteSynthesisState* synthSt ALIGN16(var_a1)); } - aAddMixer(aList++, ALIGN64(size), 0x650, var_t0, 0x7FFF); + aAddMixer(aList++, ALIGN64(size), 0x650, var_t0); return aList; } diff --git a/src/audio/audio_thread.c b/src/audio/audio_thread.c index 406f3fb6..0ccbba46 100644 --- a/src/audio/audio_thread.c +++ b/src/audio/audio_thread.c @@ -48,7 +48,7 @@ void AudioThread_CreateNextAudioBuffer(s16 *samples, u32 num_samples) { gCurAudioFrameDmaCount = 0; AudioLoad_DecreaseSampleDmaTtls(); - AudioLoad_ProcessLoads(gAudioResetStep); + // AudioLoad_ProcessLoads(gAudioResetStep); if (MQ_GET_MESG(gAudioSpecQueue, &specId)) { if (gAudioResetStep == 0) { diff --git a/src/audio/mixer.c b/src/audio/mixer.c index 8606cc12..1ff6768c 100644 --- a/src/audio/mixer.c +++ b/src/audio/mixer.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "mixer.h" @@ -14,9 +15,10 @@ #define ROUND_UP_8(v) (((v) + 7) & ~7) #define ROUND_DOWN_16(v) ((v) & ~0xf) -#define DMEM_BUF_SIZE (0x1000 - 0x3C0 - 0x40) -#define BUF_U8(a) (rspa.buf.as_u8 + ((a) - 0x3C0)) -#define BUF_S16(a) (rspa.buf.as_s16 + ((a) - 0x3C0) / sizeof(int16_t)) +//#define DMEM_BUF_SIZE (0x1000 - 0x0330 - 0x10 - 0x40) +#define DMEM_BUF_SIZE 0xC80 +#define BUF_U8(a) (rspa.buf.as_u8 + ((a)-0x0330)) +#define BUF_S16(a) (rspa.buf.as_s16 + ((a)-0x0330) / sizeof(int16_t)) static struct { uint16_t in; @@ -100,7 +102,13 @@ void aClearBufferImpl(uint16_t addr, int nbytes) { } void aLoadBufferImpl(const void *source_addr, uint16_t dest_addr, uint16_t nbytes) { +#if __SANITIZE_ADDRESS__ + for (size_t i = 0; i < ROUND_DOWN_16(nbytes); i++) { + BUF_U8(dest_addr)[i] = ((const unsigned char*)source_addr)[i]; + } +#else memcpy(BUF_U8(dest_addr), source_addr, ROUND_DOWN_16(nbytes)); +#endif } void aSaveBufferImpl(uint16_t source_addr, int16_t *dest_addr, uint16_t nbytes) { diff --git a/src/audio/mixer.h b/src/audio/mixer.h index 674c9589..0eaf0830 100644 --- a/src/audio/mixer.h +++ b/src/audio/mixer.h @@ -77,7 +77,7 @@ void aUnkCmd19Impl(uint8_t f, uint16_t count, uint16_t out_addr, uint16_t in_add aEnvMixerImpl(inBuf, nSamples, swapReverb, negLeft, negRight, dryLeft, dryRight, wetLeft, wetRight) #define aMix(pkt, c, g, i, o) aMixImpl(c, g, i, o) #define aS8Dec(pkt, f, s) aS8DecImpl(f, s) -#define aAddMixer(pkt, s, d, c, x) aAddMixerImpl(s, d, c) +#define aAddMixer(pkt, s, d, c) aAddMixerImpl(s, d, c) #define aDuplicate(pkt, s, d, c) aDuplicateImpl(s, d, c) #define aDMEMMove2(pkt, t, i, o, c) aDMEMMove2Impl(t, i, o, c) #define aResampleZoh(pkt, pitch, startFract) aResampleZohImpl(pitch, startFract)