From b561de3ff1031814f702f5bd9a02f859c75eb8d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 17 Sep 2026 10:25:57 -0600 Subject: [PATCH] sceAudiocodec: size the AAC input frame like the firmware The AAC decode path read the frame size from srcBytesRead, which is an output field the decoder writes - it's 0 on the first call, so the decoder was handed 0 readable bytes and audio never started. avcodec.prx's decodeUtility sizes the AAC input from the byte at 0x2c instead: 0x609 when nonzero, 0x600 when zero. Investigated after report by sum2012 in #16238. Not actually tested yet. Co-Authored-By: Claude Opus 5 (1M context) --- Core/HLE/sceAudiocodec.cpp | 14 ++++++++------ Core/HLE/sceAudiocodec.h | 9 +++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Core/HLE/sceAudiocodec.cpp b/Core/HLE/sceAudiocodec.cpp index 5306340605..1e7809f4e3 100644 --- a/Core/HLE/sceAudiocodec.cpp +++ b/Core/HLE/sceAudiocodec.cpp @@ -96,11 +96,9 @@ static_assert(offsetof(SceAudiocodecCodec, allocMem) == 0x68); // AAC (0x1003) // ------------------------------------------------ -// Sample rate is at offset 0x28. -// srcBytesConsumed can be very small the first frames. -// 0x1000 is always the frame size. -// The firmware sizes AAC from the bytes at 0x2c and 0x2d rather than from 0x28: input is -// 0x600 or 0x609, output 0x1000 or 0x2000, depending on those two. Consistent with the above. +// Sample rate is at offset 0x28. The input frame size is 0x609 when the byte at 0x2c is nonzero +// and 0x600 when it is zero (avcodec.prx decodeUtility, case 0x1003); the output size comes from +// the byte at 0x2d and is 0x1000 or 0x2000. // MP3 (0x1002) // ------------------------------------------------ @@ -342,7 +340,11 @@ static int sceAudiocodecDecode(u32 ctxPtr, int codec) { sampleRate = Mp3SampleRateFromContext(ctx); break; case PSP_CODEC_AAC: - bytesPerFrame = ctx->srcBytesRead; + // avcodec.prx sizes the AAC input frame from the byte at 0x2c: 0x609 when it is nonzero, + // 0x600 when it is zero (decodeUtility, case 0x1003). srcBytesRead, which this used to read, + // is an output field and is 0 on the first call, so the decoder got nothing to read and + // audio never started (seen in Meururu no Atelier Plus running the real mpeg.prx). + bytesPerFrame = ctx->fmt.aac.unk2c ? 0x609 : 0x600; sampleRate = ctx->fmt.aac.sampleRate; break; case PSP_CODEC_AT3: diff --git a/Core/HLE/sceAudiocodec.h b/Core/HLE/sceAudiocodec.h index 1da7067f31..e298cba0b7 100644 --- a/Core/HLE/sceAudiocodec.h +++ b/Core/HLE/sceAudiocodec.h @@ -100,12 +100,13 @@ struct SceAudiocodecCodec { s32 unk64; // 0x64 } mp3; - // AAC. The hardware sizes its input from the byte at 0x2c and its output from the byte - // at 0x2d; the sample rate at 0x28 is our own observation from games. + // AAC. The input frame size is 0x609 when unk2c is nonzero and 0x600 when it is zero, and + // the output size comes from unk2d (avcodec.prx decodeUtility); the sample rate at 0x28 is + // our own observation from games. struct { u32 sampleRate; // 0x28 - u8 unk2c; // 0x2c - u8 unk2d; // 0x2d + u8 unk2c; // 0x2c selects the input frame size (see above) + u8 unk2d; // 0x2d selects the output size u8 unk2e; // 0x2e u8 unk2f; // 0x2f s32 unk30[14]; // 0x30..0x67