diff --git a/apu/resampler.h b/apu/resampler.h index d144bb3b..b4c83949 100644 --- a/apu/resampler.h +++ b/apu/resampler.h @@ -93,13 +93,13 @@ class Resampler inline void dump(unsigned int num_samples) { - if (space_filled() >= num_samples) + if ((unsigned int)space_filled() >= num_samples) start = (start + num_samples) % buffer_size; } inline void add_silence(unsigned int num_samples) { - if (space_empty() <= num_samples) + if ((unsigned int)space_empty() <= num_samples) { int new_end = (end + num_samples) % buffer_size; diff --git a/common/audio/s9x_sound_driver_oss.cpp b/common/audio/s9x_sound_driver_oss.cpp index 9d9c3c3e..279a6982 100644 --- a/common/audio/s9x_sound_driver_oss.cpp +++ b/common/audio/s9x_sound_driver_oss.cpp @@ -161,7 +161,7 @@ std::pair S9xOSSSoundDriver::buffer_level() return { space_free(), output_buffer_size_bytes / 2}; } -void S9xOSSSoundDriver::write_samples(int16_t *data, int samples) +bool S9xOSSSoundDriver::write_samples(int16_t *data, int samples) { audio_buf_info info; int bytes_to_write; @@ -173,7 +173,7 @@ void S9xOSSSoundDriver::write_samples(int16_t *data, int samples) samples = info.bytes / 2; if (samples == 0) - return; + return false; bytes_written = 0; bytes_to_write = samples * 2; @@ -191,4 +191,6 @@ void S9xOSSSoundDriver::write_samples(int16_t *data, int samples) bytes_written += result; } + + return true; } diff --git a/common/audio/s9x_sound_driver_oss.hpp b/common/audio/s9x_sound_driver_oss.hpp index 4d7aa99f..b17be48f 100644 --- a/common/audio/s9x_sound_driver_oss.hpp +++ b/common/audio/s9x_sound_driver_oss.hpp @@ -18,7 +18,7 @@ class S9xOSSSoundDriver : public S9xSoundDriver bool open_device(int playback_rate, int buffer_size_ms) override; void start() override; void stop() override; - void write_samples(int16_t *data, int samples) override; + bool write_samples(int16_t *data, int samples) override; int space_free() override; std::pair buffer_level() override; diff --git a/external/SPIRV-Cross b/external/SPIRV-Cross index 4e2fdb25..197a273f 160000 --- a/external/SPIRV-Cross +++ b/external/SPIRV-Cross @@ -1 +1 @@ -Subproject commit 4e2fdb25671c742a9fbe93a6034eb1542244c7e1 +Subproject commit 197a273fd494321157f40a962c51b5fa8c9c3581 diff --git a/qt/src/EmuApplication.cpp b/qt/src/EmuApplication.cpp index 4f5748ed..e203c16a 100644 --- a/qt/src/EmuApplication.cpp +++ b/qt/src/EmuApplication.cpp @@ -6,6 +6,7 @@ #include "common/audio/s9x_sound_driver_pulse.hpp" #endif #include +#include #include #include using namespace std::chrono_literals; @@ -138,7 +139,7 @@ void EmuApplication::startGame() } }; - core->updateSettings(config.get()); + updateSettings(); updateBindings(); startIdleLoop(); @@ -333,6 +334,20 @@ bool EmuApplication::isBound(EmuBinding b) void EmuApplication::updateSettings() { + if (config->adjust_input_rate_automatically) + { + constexpr double ir_ratio = 60.098813 / 32040.0; + + auto refresh = window->screen()->refreshRate(); + config->input_rate = refresh / ir_ratio; + if (refresh > 119 && refresh < 121) + config->input_rate /= 2; + else if (refresh > 179 && refresh < 181) + config->input_rate /= 3; + else if (refresh > 239 && refresh < 241) + config->input_rate /= 4; + } + core->updateSettings(config.get()); } diff --git a/qt/src/SoundPanel.cpp b/qt/src/SoundPanel.cpp index 0b47f2fd..9c147a71 100644 --- a/qt/src/SoundPanel.cpp +++ b/qt/src/SoundPanel.cpp @@ -1,5 +1,4 @@ #include "SoundPanel.hpp" -#include static const int playback_rates[] = { 96000, 48000, 44100 }; @@ -39,20 +38,19 @@ SoundPanel::SoundPanel(EmuApplication *app_) connect(checkBox_adjust_input_rate, &QCheckBox::clicked, [&](bool checked) { app->config->adjust_input_rate_automatically = checked; + app->updateSettings(); + updateInputRate(); + if (checked) { - int calculated = screen()->refreshRate() / 60.09881 * 32040; - horizontalSlider_input_rate->setValue(calculated); + horizontalSlider_input_rate->setValue(app->config->input_rate); } - - horizontalSlider_input_rate->setDisabled(checked); - app->updateSettings(); }); connect(horizontalSlider_input_rate, &QSlider::valueChanged, [&](int value) { app->config->input_rate = value; - setInputRateText(value); app->updateSettings(); + updateInputRate(); }); connect(checkBox_dynamic_rate_control, &QCheckBox::clicked, [&](bool checked) { @@ -78,10 +76,19 @@ SoundPanel::~SoundPanel() { } -void SoundPanel::setInputRateText(int value) +void SoundPanel::updateInputRate() { - double hz = value / 32040.0 * 60.09881; - label_input_rate->setText(QString("%1\n%2 Hz").arg(value).arg(hz, 6, 'g', 6)); + constexpr double ir_ratio = 60.098813 / 32040.0; + + app->updateSettings(); + if (app->config->adjust_input_rate_automatically) + horizontalSlider_input_rate->setEnabled(false); + else + horizontalSlider_input_rate->setEnabled(true); + + double hz = app->config->input_rate * ir_ratio; + + label_input_rate->setText(QString("%1\n%2 Hz").arg(app->config->input_rate).arg(hz, 6, 'g', 6)); } void SoundPanel::showEvent(QShowEvent *event) @@ -126,7 +133,8 @@ void SoundPanel::showEvent(QShowEvent *event) spinBox_buffer_size->setValue(config->audio_buffer_size_ms); checkBox_adjust_input_rate->setChecked(config->adjust_input_rate_automatically); - setInputRateText(config->input_rate); + updateInputRate(); + horizontalSlider_input_rate->setValue(config->input_rate); checkBox_dynamic_rate_control->setChecked(config->dynamic_rate_control); doubleSpinBox_dynamic_rate_limit->setValue(config->dynamic_rate_limit); diff --git a/qt/src/SoundPanel.hpp b/qt/src/SoundPanel.hpp index 8dc3633a..4ff7e701 100644 --- a/qt/src/SoundPanel.hpp +++ b/qt/src/SoundPanel.hpp @@ -12,7 +12,7 @@ class SoundPanel : ~SoundPanel(); EmuApplication *app; void showEvent(QShowEvent *event) override; - void setInputRateText(int value); + void updateInputRate(); std::vector driver_list; }; \ No newline at end of file