Skip to content

Commit

Permalink
Fix vanilla audio cache coherency issues reported by ares (#133)
Browse files Browse the repository at this point in the history
* Write back the data cache line for filters

 * Write back the data cache after clearing AI sample buffers
  • Loading branch information
Thar0 authored Jun 9, 2024
1 parent 3251456 commit 5c65081
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/audio/lib/heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,9 @@ void AudioHeap_LoadHighPassFilter(s16* filter, s32 cutoff) {
void AudioHeap_LoadFilter(s16* filter, s32 lowPassCutoff, s32 highPassCutoff) {
s32 i;

// Filters should always be data cache aligned
assert(((uintptr_t)filter & DCACHE_LINEMASK) == 0);

if (lowPassCutoff == 0 && highPassCutoff == 0) {
// Identity filter
AudioHeap_LoadLowPassFilter(filter, 0);
Expand All @@ -725,6 +728,13 @@ void AudioHeap_LoadFilter(s16* filter, s32 lowPassCutoff, s32 highPassCutoff) {
filter[i] = (ptr1[i] + ptr2[i]) / 2;
}
}

// Write back the cache line for this filter
#if defined(CONSOLE_WIIVC) || defined(CONSOLE_GC)
osWritebackDCache(filter, 8 * sizeof(s16));
#else
asm("cache %0, (%1)" ::"i"(CACH_PD | C_HWBINV), "r"(filter));
#endif
}

void AudioHeap_UpdateReverb(SynthesisReverb* reverb) {
Expand Down Expand Up @@ -757,9 +767,8 @@ void AudioHeap_ClearCurrentAiBuffer(void) {

gAudioCtx.aiBufLengths[curAiBufferIndex] = gAudioCtx.audioBufferParameters.minAiBufferLength;

for (i = 0; i < AIBUF_LEN; i++) {
gAudioCtx.aiBuffers[curAiBufferIndex][i] = 0;
}
bzero(gAudioCtx.aiBuffers[curAiBufferIndex], AIBUF_LEN * sizeof(s16));
osWritebackDCache(gAudioCtx.aiBuffers[curAiBufferIndex], AIBUF_LEN * sizeof(s16));
}

s32 AudioHeap_ResetStep(void) {
Expand Down Expand Up @@ -826,9 +835,8 @@ s32 AudioHeap_ResetStep(void) {
gAudioCtx.resetStatus = 0;
for (i = 0; i < 3; i++) {
gAudioCtx.aiBufLengths[i] = gAudioCtx.audioBufferParameters.maxAiBufferLength;
for (j = 0; j < AIBUF_LEN; j++) {
gAudioCtx.aiBuffers[i][j] = 0;
}
bzero(gAudioCtx.aiBuffers[i], AIBUF_LEN * sizeof(s16));
osWritebackDCache(gAudioCtx.aiBuffers[i], AIBUF_LEN * sizeof(s16));
}
break;
}
Expand Down

0 comments on commit 5c65081

Please sign in to comment.