From 9392c19a709fe1f60ae57ad1cd3970387f5ffb28 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 17 Jul 2024 18:15:54 +1000 Subject: [PATCH] CDROM: Handle audio sectors in 2X mode Fixes menu background in 360 Three Sixty. --- src/core/cdrom.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/core/cdrom.cpp b/src/core/cdrom.cpp index 4e028156b..4e240b408 100644 --- a/src/core/cdrom.cpp +++ b/src/core/cdrom.cpp @@ -3302,8 +3302,10 @@ ALWAYS_INLINE_RELEASE void CDROM::ProcessCDDASector(const u8* raw_sector, const SPU::GeneratePendingSamples(); - constexpr bool is_stereo = true; - constexpr u32 num_samples = CDImage::RAW_SECTOR_SIZE / sizeof(s16) / (is_stereo ? 2 : 1); + // 2 samples per channel, always stereo. + // Apparently in 2X mode, only half the samples in a sector get processed. + // Test cast: Menu background sound in 360 Three Sixty. + const u32 num_samples = (CDImage::RAW_SECTOR_SIZE / sizeof(s16)) / (s_mode.double_speed ? 4 : 2); const u32 remaining_space = s_audio_fifo.GetSpace(); if (remaining_space < num_samples) { @@ -3312,12 +3314,13 @@ ALWAYS_INLINE_RELEASE void CDROM::ProcessCDDASector(const u8* raw_sector, const } const u8* sector_ptr = raw_sector; + const size_t step = s_mode.double_speed ? (sizeof(s16) * 4) : (sizeof(s16) * 2); for (u32 i = 0; i < num_samples; i++) { s16 samp_left, samp_right; std::memcpy(&samp_left, sector_ptr, sizeof(samp_left)); std::memcpy(&samp_right, sector_ptr + sizeof(s16), sizeof(samp_right)); - sector_ptr += sizeof(s16) * 2; + sector_ptr += step; AddCDAudioFrame(samp_left, samp_right); } }