Skip to content

Commit

Permalink
CDROM: Defer init completion until after seek
Browse files Browse the repository at this point in the history
Reduces leaky reverb in some games.
  • Loading branch information
stenzek committed Aug 9, 2024
1 parent 5368a1d commit 55d0951
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/core/cdrom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ static_assert(sizeof(XA_ADPCMBlockHeader) == 1, "XA-ADPCM block header is one by

} // namespace

static void SoftReset(TickCount ticks_late);
static TickCount SoftReset(TickCount ticks_late);

static bool IsDriveIdle();
static bool IsMotorOn();
Expand Down Expand Up @@ -583,7 +583,7 @@ void CDROM::Reset()
SetHoldPosition(0, true);
}

void CDROM::SoftReset(TickCount ticks_late)
TickCount CDROM::SoftReset(TickCount ticks_late)
{
const bool was_double_speed = s_mode.double_speed;

Expand Down Expand Up @@ -612,6 +612,7 @@ void CDROM::SoftReset(TickCount ticks_late)

UpdateStatusRegister();

TickCount total_ticks;
if (HasMedia())
{
if (IsSeeking())
Expand All @@ -621,7 +622,7 @@ void CDROM::SoftReset(TickCount ticks_late)

const TickCount speed_change_ticks = was_double_speed ? GetTicksForSpeedChange() : 0;
const TickCount seek_ticks = (s_current_lba != 0) ? GetTicksForSeek(0) : 0;
const TickCount total_ticks = std::max<TickCount>(speed_change_ticks + seek_ticks, INIT_TICKS) - ticks_late;
total_ticks = std::max<TickCount>(speed_change_ticks + seek_ticks, INIT_TICKS) - ticks_late;
DEV_LOG("CDROM init total disc ticks = {} (speed change = {}, seek = {})", total_ticks, speed_change_ticks,
seek_ticks);

Expand All @@ -640,6 +641,12 @@ void CDROM::SoftReset(TickCount ticks_late)
s_drive_event.Schedule(total_ticks);
}
}
else
{
total_ticks = INIT_TICKS - ticks_late;
}

return total_ticks;
}

bool CDROM::DoState(StateWrapper& sw)
Expand Down Expand Up @@ -1504,8 +1511,8 @@ TickCount CDROM::GetTicksForStop(bool motor_was_on)

TickCount CDROM::GetTicksForSpeedChange()
{
static constexpr u32 ticks_single_to_double = static_cast<u32>(0.7 * static_cast<double>(System::MASTER_CLOCK));
static constexpr u32 ticks_double_to_single = static_cast<u32>(0.8 * static_cast<double>(System::MASTER_CLOCK));
static constexpr u32 ticks_single_to_double = static_cast<u32>(0.6 * static_cast<double>(System::MASTER_CLOCK));
static constexpr u32 ticks_double_to_single = static_cast<u32>(0.7 * static_cast<double>(System::MASTER_CLOCK));
return System::ScaleTicksToOverclock(s_mode.double_speed ? ticks_single_to_double : ticks_double_to_single);
}

Expand Down Expand Up @@ -1981,9 +1988,8 @@ void CDROM::ExecuteCommand(void*, TickCount ticks, TickCount ticks_late)

SendACKAndStat();

SoftReset(ticks_late);

QueueCommandSecondResponse(Command::Init, INIT_TICKS);
const TickCount reset_ticks = SoftReset(ticks_late);
QueueCommandSecondResponse(Command::Init, reset_ticks);
EndCommand();
return;
}
Expand Down

0 comments on commit 55d0951

Please sign in to comment.