diff --git a/CHANGES b/CHANGES index e92048cc9..03646c26f 100644 --- a/CHANGES +++ b/CHANGES @@ -50,6 +50,7 @@ Bugfixes: - Core: Fix ordering events when scheduling during events - GBA: Reset WAITCNT properly - GBA Serialize: Fix loading states in Hblank + - PSP2: Fix more issues causing poor audio Misc: - GBA Timer: Use global cycles for timers - GBA: Extend oddly-sized ROMs to full address space (fixes mgba.io/i/722) diff --git a/src/platform/psp2/psp2-context.c b/src/platform/psp2/psp2-context.c index 93d0d98e3..4ee45f59c 100644 --- a/src/platform/psp2/psp2-context.c +++ b/src/platform/psp2/psp2-context.c @@ -234,8 +234,7 @@ static void _requestImage(struct mImageSource* source, const void** buffer, size static void _postAudioBuffer(struct mAVStream* stream, blip_t* left, blip_t* right) { UNUSED(stream); MutexLock(&audioContext.mutex); - struct GBAStereoSample* samples = &audioContext.buffer[audioContext.writeOffset]; - while (audioContext.samples == PSP2_AUDIO_BUFFER_SIZE) { + while (audioContext.samples + PSP2_SAMPLES >= PSP2_AUDIO_BUFFER_SIZE) { if (!frameLimiter) { blip_clear(left); blip_clear(right); @@ -244,6 +243,7 @@ static void _postAudioBuffer(struct mAVStream* stream, blip_t* left, blip_t* rig } ConditionWait(&audioContext.cond, &audioContext.mutex); } + struct GBAStereoSample* samples = &audioContext.buffer[audioContext.writeOffset]; blip_read_samples(left, &samples[0].left, PSP2_SAMPLES, true); blip_read_samples(right, &samples[0].right, PSP2_SAMPLES, true); audioContext.samples += PSP2_SAMPLES; @@ -403,6 +403,8 @@ void mPSP2UnloadROM(struct mGUIRunner* runner) { default: break; } + audioContext.running = false; + ThreadJoin(audioThread); } void mPSP2Paused(struct mGUIRunner* runner) {