From 0710e3b6d384526ed939f742f8f657623bb354bb Mon Sep 17 00:00:00 2001
From: Connor McLaughlin <stenzek@gmail.com>
Date: Wed, 1 Jul 2020 21:43:24 +1000
Subject: [PATCH] CDROM: Ignore sectors with channel number=255

Some games (Taxi 2 and Blues Blues) have junk audio sectors with a channel number of 255.
We need to skip them otherwise it ends up playing the incorrect file.

TODO: Verify with a hardware test.
---
 src/core/cdrom.cpp | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/core/cdrom.cpp b/src/core/cdrom.cpp
index e9a934713..f1de8d280 100644
--- a/src/core/cdrom.cpp
+++ b/src/core/cdrom.cpp
@@ -2137,6 +2137,17 @@ void CDROM::ProcessXAADPCMSector(const u8* raw_sector, const CDImage::SubChannel
   // is read. Fixes audio in Tomb Raider III menu.
   if (!m_xa_current_set)
   {
+    // Some games (Taxi 2 and Blues Blues) have junk audio sectors with a channel number of 255.
+    // We need to skip them otherwise it ends up playing the incorrect file.
+    // TODO: Verify with a hardware test.
+    if (m_last_sector_subheader.channel_number == 255 && (!m_mode.xa_filter || m_xa_filter_channel_number != 255))
+    {
+      Log_WarningPrintf("Skipping XA file with file number %u and channel number %u (submode 0x%02X coding 0x%02X)",
+                        m_last_sector_subheader.file_number, m_last_sector_subheader.channel_number,
+                        m_last_sector_subheader.submode.bits, m_last_sector_subheader.codinginfo.bits);
+      return;
+    }
+
     m_xa_current_file_number = m_last_sector_subheader.file_number;
     m_xa_current_channel_number = m_last_sector_subheader.channel_number;
     m_xa_current_set = true;