From 8ba93b36a03fb57b7b68a5274a643bd8865b203c Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Mon, 5 Oct 2020 00:05:14 +1000 Subject: [PATCH] CDROM: Add option to speed up double speed reads --- src/core/cdrom.cpp | 4 + src/core/host_interface.cpp | 1 + src/core/settings.cpp | 2 + src/core/settings.h | 1 + .../libretro_host_interface.cpp | 17 ++++- src/duckstation-qt/consolesettingswidget.cpp | 14 ++++ src/duckstation-qt/consolesettingswidget.h | 1 + src/duckstation-qt/consolesettingswidget.ui | 73 +++++++++++++++++-- 8 files changed, 106 insertions(+), 7 deletions(-) diff --git a/src/core/cdrom.cpp b/src/core/cdrom.cpp index 2dfc0f751..52e132023 100644 --- a/src/core/cdrom.cpp +++ b/src/core/cdrom.cpp @@ -620,6 +620,10 @@ TickCount CDROM::GetAckDelayForCommand(Command command) TickCount CDROM::GetTicksForRead() { const TickCount tps = System::GetTicksPerSecond(); + + if (g_settings.cdrom_read_speedup > 1 && !m_mode.cdda && !m_mode.xa_enable && m_mode.double_speed) + return tps / (150 * g_settings.cdrom_read_speedup); + return m_mode.double_speed ? (tps / 150) : (tps / 75); } diff --git a/src/core/host_interface.cpp b/src/core/host_interface.cpp index a576ae150..8ced54443 100644 --- a/src/core/host_interface.cpp +++ b/src/core/host_interface.cpp @@ -457,6 +457,7 @@ void HostInterface::SetDefaultSettings(SettingsInterface& si) si.SetBoolValue("CDROM", "RegionCheck", true); si.SetBoolValue("CDROM", "LoadImageToRAM", false); si.SetBoolValue("CDROM", "MuteCDAudio", false); + si.SetIntValue("CDROM", "ReadSpeedup", 1); si.SetStringValue("Audio", "Backend", Settings::GetAudioBackendName(Settings::DEFAULT_AUDIO_BACKEND)); si.SetIntValue("Audio", "OutputVolume", 100); diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 54782c2e4..b840d2803 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -176,6 +176,7 @@ void Settings::Load(SettingsInterface& si) cdrom_region_check = si.GetBoolValue("CDROM", "RegionCheck", true); cdrom_load_image_to_ram = si.GetBoolValue("CDROM", "LoadImageToRAM", false); cdrom_mute_cd_audio = si.GetBoolValue("CDROM", "MuteCDAudio", false); + cdrom_read_speedup = si.GetIntValue("CDROM", "ReadSpeedup", 1); audio_backend = ParseAudioBackend(si.GetStringValue("Audio", "Backend", GetAudioBackendName(DEFAULT_AUDIO_BACKEND)).c_str()) @@ -296,6 +297,7 @@ void Settings::Save(SettingsInterface& si) const si.SetBoolValue("CDROM", "RegionCheck", cdrom_region_check); si.SetBoolValue("CDROM", "LoadImageToRAM", cdrom_load_image_to_ram); si.SetBoolValue("CDROM", "MuteCDAudio", cdrom_mute_cd_audio); + si.SetIntValue("CDROM", "ReadSpeedup", cdrom_read_speedup); si.SetStringValue("Audio", "Backend", GetAudioBackendName(audio_backend)); si.SetIntValue("Audio", "OutputVolume", audio_output_volume); diff --git a/src/core/settings.h b/src/core/settings.h index 8738ee452..01a5a37cc 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -123,6 +123,7 @@ struct Settings bool cdrom_region_check = true; bool cdrom_load_image_to_ram = false; bool cdrom_mute_cd_audio = false; + u32 cdrom_read_speedup = 1; AudioBackend audio_backend = AudioBackend::Cubeb; s32 audio_output_volume = 100; diff --git a/src/duckstation-libretro/libretro_host_interface.cpp b/src/duckstation-libretro/libretro_host_interface.cpp index 0e2cdfcb0..8a88f56cd 100644 --- a/src/duckstation-libretro/libretro_host_interface.cpp +++ b/src/duckstation-libretro/libretro_host_interface.cpp @@ -445,7 +445,7 @@ void LibretroHostInterface::OnSystemDestroyed() m_using_hardware_renderer = false; } -static std::array s_option_definitions = {{ +static std::array s_option_definitions = {{ {"duckstation_Console.Region", "Console Region", "Determines which region/hardware to emulate. Auto-Detect will use the region of the disc inserted.", @@ -481,6 +481,21 @@ static std::array s_option_definitions = {{ "Forcibly mutes both CD-DA and XA audio from the CD-ROM. Can be used to disable background music in some games.", {{"true", "Enabled"}, {"false", "Disabled"}}, "false"}, + {"duckstation_CDROM.ReadSpeedup", + "Mute CD Audio", + "Speeds up CD-ROM reads by the specified factor. Only applies to double-speed reads, and is ignored when audio " + "is playing. May improve loading speeds in some games, at the cost of breaking others.", + {{"1", "None (Double Speed)"}, + {"2", "2x (Quad Speed)"}, + {"3", "3x (6x Speed)"}, + {"4", "4x (8x Speed)"}, + {"5", "5x (10x Speed)"}, + {"6", "6x (12x Speed)"}, + {"7", "7x (14x Speed)"}, + {"8", "8x (16x Speed)"}, + {"9", "9x (18x Speed)"}, + {"10", "10x (20x Speed)"}}, + "1"}, {"duckstation_CPU.ExecutionMode", "CPU Execution Mode", "Which mode to use for CPU emulation. Recompiler provides the best performance.", diff --git a/src/duckstation-qt/consolesettingswidget.cpp b/src/duckstation-qt/consolesettingswidget.cpp index f8cde51e3..2923e447f 100644 --- a/src/duckstation-qt/consolesettingswidget.cpp +++ b/src/duckstation-qt/consolesettingswidget.cpp @@ -39,11 +39,19 @@ ConsoleSettingsWidget::ConsoleSettingsWidget(QtHostInterface* host_interface, QW m_ui.cdromLoadImageToRAM, tr("Preload Image to RAM"), tr("Unchecked"), tr("Loads the game image into RAM. Useful for network paths that may become unreliable during gameplay. In some " "cases also eliminates stutter when games initiate audio track playback.")); + dialog->registerWidgetHelp( + m_ui.cdromReadSpeedup, tr("CDROM Read Speedup"), tr("None (Double Speed"), + tr("Speeds up CD-ROM reads by the specified factor. Only applies to double-speed reads, and is ignored when audio " + "is playing. May improve loading speeds in some games, at the cost of breaking others.")); m_ui.cpuClockSpeed->setEnabled(m_ui.enableCPUClockSpeedControl->checkState() == Qt::Checked); + m_ui.cdromReadSpeedup->setCurrentIndex(m_host_interface->GetIntSettingValue("CDROM", "ReadSpeedup", 1) - 1); + connect(m_ui.enableCPUClockSpeedControl, &QCheckBox::stateChanged, this, &ConsoleSettingsWidget::onEnableCPUClockSpeedControlChecked); connect(m_ui.cpuClockSpeed, &QSlider::valueChanged, this, &ConsoleSettingsWidget::onCPUClockSpeedValueChanged); + connect(m_ui.cdromReadSpeedup, QOverload::of(&QComboBox::currentIndexChanged), this, + &ConsoleSettingsWidget::onCDROMReadSpeedupValueChanged); calculateCPUClockValue(); } @@ -95,6 +103,12 @@ void ConsoleSettingsWidget::updateCPUClockSpeedLabel() m_ui.cpuClockSpeedLabel->setText(tr("%1% (%2MHz)").arg(percent).arg(frequency / 1000000.0, 0, 'f', 2)); } +void ConsoleSettingsWidget::onCDROMReadSpeedupValueChanged(int value) +{ + m_host_interface->SetIntSettingValue("CDROM", "ReadSpeedup", value + 1); + m_host_interface->applySettings(); +} + void ConsoleSettingsWidget::calculateCPUClockValue() { const u32 numerator = static_cast(m_host_interface->GetIntSettingValue("CPU", "OverclockNumerator", 1)); diff --git a/src/duckstation-qt/consolesettingswidget.h b/src/duckstation-qt/consolesettingswidget.h index 9f339f8c1..3d9248928 100644 --- a/src/duckstation-qt/consolesettingswidget.h +++ b/src/duckstation-qt/consolesettingswidget.h @@ -19,6 +19,7 @@ private Q_SLOTS: void onEnableCPUClockSpeedControlChecked(int state); void onCPUClockSpeedValueChanged(int value); void updateCPUClockSpeedLabel(); + void onCDROMReadSpeedupValueChanged(int value); private: void calculateCPUClockValue(); diff --git a/src/duckstation-qt/consolesettingswidget.ui b/src/duckstation-qt/consolesettingswidget.ui index ab570636d..cb70f6ac8 100644 --- a/src/duckstation-qt/consolesettingswidget.ui +++ b/src/duckstation-qt/consolesettingswidget.ui @@ -6,8 +6,8 @@ 0 0 - 541 - 351 + 648 + 401 @@ -132,30 +132,91 @@ - CDROM Emulation + CD-ROM Emulation - + Use Read Thread (Asynchronous) - + Enable Region Check - + Preload Image To RAM + + + + Read Speedup: + + + + + + + + None (Double Speed) + + + + + 2x (Quad Speed) + + + + + 3x (6x Speed) + + + + + 4x (8x Speed) + + + + + 5x (10x Speed) + + + + + 6x (12x Speed) + + + + + 7x (14x Speed) + + + + + 8x (16x Speed) + + + + + 9x (18x Speed) + + + + + 10x (20x Speed) + + + +