diff --git a/soh/soh/mixer.c b/soh/soh/mixer.c index a03db828..16e74dcf 100644 --- a/soh/soh/mixer.c +++ b/soh/soh/mixer.c @@ -99,14 +99,14 @@ void aClearBufferImpl(uint16_t addr, int nbytes) { memset(BUF_U8(addr), 0, nbytes); } -void aFillBufferImpl(uint16_t dest_addr, uint16_t samples) { - memset(BUF_U8(dest_addr), 0, samples); -} - void aLoadBufferImpl(const void *source_addr, uint16_t dest_addr, uint16_t nbytes) { memcpy(BUF_U8(dest_addr), source_addr, ROUND_DOWN_16(nbytes)); } +void aLoadBufferNoRoundImpl(const void *source_addr, uint16_t dest_addr, uint16_t nbytes) { + memcpy(BUF_U8(dest_addr), source_addr, nbytes); +} + void aSaveBufferImpl(uint16_t source_addr, int16_t *dest_addr, uint16_t nbytes) { memcpy(dest_addr, BUF_S16(source_addr), ROUND_DOWN_16(nbytes)); } diff --git a/soh/soh/mixer.h b/soh/soh/mixer.h index 7ec95884..7e77b0c3 100644 --- a/soh/soh/mixer.h +++ b/soh/soh/mixer.h @@ -33,8 +33,8 @@ #undef aUnkCmd19 void aClearBufferImpl(uint16_t addr, int nbytes); -void aFillBufferImpl(const void* dest_addr, uint16_t nbytes); void aLoadBufferImpl(const void* source_addr, uint16_t dest_addr, uint16_t nbytes); +void aLoadBufferNoRoundImpl(const void* source_addr, uint16_t dest_addr, uint16_t nbytes); void aSaveBufferImpl(uint16_t source_addr, int16_t* dest_addr, uint16_t nbytes); void aLoadADPCMImpl(int num_entries_times_16, const int16_t* book_source_addr); void aSetBufferImpl(uint8_t flags, uint16_t in, uint16_t out, uint16_t nbytes); @@ -62,8 +62,8 @@ void aUnkCmd19Impl(uint8_t f, uint16_t count, uint16_t out_addr, uint16_t in_add do { \ } while (0) #define aClearBuffer(pkt, d, c) aClearBufferImpl(d, c) -#define aFillBuffer(pkt, d, c) aFillBufferImpl(d, c) #define aLoadBuffer(pkt, s, d, c) aLoadBufferImpl(s, d, c) +#define aLoadBufferNoRound(pkt, s, d, c) aLoadBufferNoRoundImpl(s, d, c) #define aSaveBuffer(pkt, s, d, c) aSaveBufferImpl(s, d, c) #define aLoadADPCM(pkt, c, d) aLoadADPCMImpl(c, d) #define aSetBuffer(pkt, f, i, o, c) aSetBufferImpl(f, i, o, c) diff --git a/soh/src/code/audio_synthesis.c b/soh/src/code/audio_synthesis.c index 81566001..29e11b17 100644 --- a/soh/src/code/audio_synthesis.c +++ b/soh/src/code/audio_synthesis.c @@ -871,14 +871,14 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS s5 = samplesLenAdjusted; goto skip; case CODEC_REVERB: + goto skip; break; } if (nFramesToDecode != 0) { frameIndex = (synthState->samplePosInt + skipInitialSamples - nFirstFrameSamplesToIgnore) / 16; sampleDataOffset = frameIndex * frameSize; - if (audioFontSample->medium == MEDIUM_RAM) - { + if (audioFontSample->medium == MEDIUM_RAM) { sampleData = (u8*)(sampleDataStart + sampleDataOffset + sampleAddr); } else if (audioFontSample->medium == MEDIUM_UNK) { return cmd; @@ -892,25 +892,17 @@ Acmd* AudioSynth_ProcessNote(s32 noteIndex, NoteSubEu* noteSubEu, NoteSynthesisS return cmd; } - sampleDataStartPad = (uintptr_t)sampleData & 0xF; aligned = ALIGN16((nFramesToDecode * frameSize) + 16); - addr = DMEM_COMPRESSED_ADPCM_DATA - aligned; // Note: This must maintain full aligned width for playback + addr = DMEM_COMPRESSED_ADPCM_DATA - aligned; - // Cap ALIGN16 window to actual size of sample to avoid access violations - alignDiff = 0; - if ((sampleDataOffset + aligned) > audioFontSample->size + 16) { - int32_t capped = (audioFontSample->size + 16) - sampleDataOffset; - alignDiff = aligned - capped; - aligned = capped; + if (audioFontSample->medium != MEDIUM_RAM) { + aLoadBuffer(cmd++, sampleData - sampleDataStartPad, addr, aligned); + // RAM samples do not need rounded alignment value for src bytes otherwise access violations ahoy! + } else { + aLoadBufferNoRound(cmd++, sampleData - sampleDataStartPad, addr, (nFramesToDecode * frameSize + 16)); } - aLoadBuffer(cmd++, sampleData - sampleDataStartPad, addr, aligned); - - // Fill gap with zeros so we don't play any junk left behind - if (alignDiff > 0) { - aFillBuffer(cmd++, addr + aligned, alignDiff); - } } else { nSamplesToDecode = 0; sampleDataStartPad = 0;