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) <noreply@anthropic.com>
This commit is contained in:
Henrik RydgårdandClaude Opus 5 committed 2026-09-17 10:33:08 -06:00
1 parent 45727ef2be
commit b561de3ff1
2 files changed
+13 -10

No files matched your search

+8 -6
View File
@@ -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:
+5 -4
View File
@@ -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