Atrac3: Set up the decoder the way libatrac3plus does

libatrac3plus picks the codec parameter from the frame size and the
header's joint stereo flag, and the channel count plays no part. We
guessed joint stereo from the frame size and channel count instead, so
LocoRoco 2's MuiMui house music never started: the game writes a 2-channel
normal-stereo header for every track it streams, and that 0xC0 track holds
one mono sound unit per frame. Taken as joint stereo, its first frame failed
during setup, and the game retried forever.

Now the joint stereo flag comes from the track header, and the decoder's
channel count from the parameter it maps to, so that track decodes as mono
into both output channels, as on hardware. Low-level decoding, which has
no header, still goes by the frame size. Atrac2 saves the flag; older
states fall back to the guess.

Fixes #8647.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Henrik RydgårdandClaude Opus 5.5 committed 2026-09-29 17:14:00 -06:00
1 parent ae460c9e1a
commit b9ea98d2c5
6 files changed
+47 -17

No files matched your search

+13 -4
View File
@@ -337,7 +337,7 @@ void Atrac2::DumpBufferToFile() {
}
void Atrac2::DoState(PointerWrap &p) {
auto s = p.Section("Atrac2", 1, 3);
auto s = p.Section("Atrac2", 1, 4);
if (!s)
return;
@@ -362,8 +362,14 @@ void Atrac2::DoState(PointerWrap &p) {
}
const SceAtracIdInfo &info = context_->info;
if (s >= 4) {
Do(p, jointStereo_);
} else if (p.mode == p.MODE_READ) {
jointStereo_ = IsAtrac3StreamJointStereo(info.codec, info.sampleSize, info.numChan);
}
if (p.mode == p.MODE_READ && info.state != ATRAC_STATUS_NO_DATA) {
CreateDecoder(info.codec, info.sampleSize, info.numChan);
CreateDecoder(info.codec, info.sampleSize, info.numChan, jointStereo_);
}
}
@@ -1004,7 +1010,8 @@ int Atrac2::SetData(const Track &track, u32 bufferAddr, u32 readSize, u32 buffer
SceAtracIdInfo &info = context_->info;
CreateDecoder(info.codec, info.sampleSize, info.numChan);
jointStereo_ = track.jointStereo != 0;
CreateDecoder(info.codec, info.sampleSize, info.numChan, jointStereo_);
outputChannels_ = outputChannels;
@@ -1140,7 +1147,9 @@ void Atrac2::InitLowLevel(const Atrac3LowLevelParams &params, int codecType) {
info.dataOff = 0;
info.decodePos = 0;
info.state = ATRAC_STATUS_LOW_LEVEL;
CreateDecoder(codecType, info.sampleSize, info.numChan);
// There's no track header here, so go by the bitrate.
jointStereo_ = IsAtrac3StreamJointStereo(codecType, info.sampleSize, info.numChan);
CreateDecoder(codecType, info.sampleSize, info.numChan, jointStereo_);
}
int Atrac2::DecodeLowLevel(const u8 *srcData, int *bytesConsumed, s16 *dstData, int *bytesWritten) {