mirror of https://github.com/snes9xgit/snes9x.git
Update input rate at right locations.
This commit is contained in:
parent
ec8bdaa6eb
commit
12e7f0d21f
|
@ -93,13 +93,13 @@ class Resampler
|
||||||
|
|
||||||
inline void dump(unsigned int num_samples)
|
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;
|
start = (start + num_samples) % buffer_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void add_silence(unsigned int num_samples)
|
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;
|
int new_end = (end + num_samples) % buffer_size;
|
||||||
|
|
||||||
|
|
|
@ -161,7 +161,7 @@ std::pair<int, int> S9xOSSSoundDriver::buffer_level()
|
||||||
return { space_free(), output_buffer_size_bytes / 2};
|
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;
|
audio_buf_info info;
|
||||||
int bytes_to_write;
|
int bytes_to_write;
|
||||||
|
@ -173,7 +173,7 @@ void S9xOSSSoundDriver::write_samples(int16_t *data, int samples)
|
||||||
samples = info.bytes / 2;
|
samples = info.bytes / 2;
|
||||||
|
|
||||||
if (samples == 0)
|
if (samples == 0)
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
bytes_written = 0;
|
bytes_written = 0;
|
||||||
bytes_to_write = samples * 2;
|
bytes_to_write = samples * 2;
|
||||||
|
@ -191,4 +191,6 @@ void S9xOSSSoundDriver::write_samples(int16_t *data, int samples)
|
||||||
|
|
||||||
bytes_written += result;
|
bytes_written += result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ class S9xOSSSoundDriver : public S9xSoundDriver
|
||||||
bool open_device(int playback_rate, int buffer_size_ms) override;
|
bool open_device(int playback_rate, int buffer_size_ms) override;
|
||||||
void start() override;
|
void start() override;
|
||||||
void stop() 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;
|
int space_free() override;
|
||||||
std::pair<int, int> buffer_level() override;
|
std::pair<int, int> buffer_level() override;
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 4e2fdb25671c742a9fbe93a6034eb1542244c7e1
|
Subproject commit 197a273fd494321157f40a962c51b5fa8c9c3581
|
|
@ -6,6 +6,7 @@
|
||||||
#include "common/audio/s9x_sound_driver_pulse.hpp"
|
#include "common/audio/s9x_sound_driver_pulse.hpp"
|
||||||
#endif
|
#endif
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QScreen>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
|
@ -138,7 +139,7 @@ void EmuApplication::startGame()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
core->updateSettings(config.get());
|
updateSettings();
|
||||||
updateBindings();
|
updateBindings();
|
||||||
|
|
||||||
startIdleLoop();
|
startIdleLoop();
|
||||||
|
@ -333,6 +334,20 @@ bool EmuApplication::isBound(EmuBinding b)
|
||||||
|
|
||||||
void EmuApplication::updateSettings()
|
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());
|
core->updateSettings(config.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#include "SoundPanel.hpp"
|
#include "SoundPanel.hpp"
|
||||||
#include <QScreen>
|
|
||||||
|
|
||||||
static const int playback_rates[] = { 96000, 48000, 44100 };
|
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) {
|
connect(checkBox_adjust_input_rate, &QCheckBox::clicked, [&](bool checked) {
|
||||||
app->config->adjust_input_rate_automatically = checked;
|
app->config->adjust_input_rate_automatically = checked;
|
||||||
|
app->updateSettings();
|
||||||
|
updateInputRate();
|
||||||
|
|
||||||
if (checked)
|
if (checked)
|
||||||
{
|
{
|
||||||
int calculated = screen()->refreshRate() / 60.09881 * 32040;
|
horizontalSlider_input_rate->setValue(app->config->input_rate);
|
||||||
horizontalSlider_input_rate->setValue(calculated);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
horizontalSlider_input_rate->setDisabled(checked);
|
|
||||||
app->updateSettings();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(horizontalSlider_input_rate, &QSlider::valueChanged, [&](int value) {
|
connect(horizontalSlider_input_rate, &QSlider::valueChanged, [&](int value) {
|
||||||
app->config->input_rate = value;
|
app->config->input_rate = value;
|
||||||
setInputRateText(value);
|
|
||||||
app->updateSettings();
|
app->updateSettings();
|
||||||
|
updateInputRate();
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(checkBox_dynamic_rate_control, &QCheckBox::clicked, [&](bool checked) {
|
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;
|
constexpr double ir_ratio = 60.098813 / 32040.0;
|
||||||
label_input_rate->setText(QString("%1\n%2 Hz").arg(value).arg(hz, 6, 'g', 6));
|
|
||||||
|
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)
|
void SoundPanel::showEvent(QShowEvent *event)
|
||||||
|
@ -126,7 +133,8 @@ void SoundPanel::showEvent(QShowEvent *event)
|
||||||
spinBox_buffer_size->setValue(config->audio_buffer_size_ms);
|
spinBox_buffer_size->setValue(config->audio_buffer_size_ms);
|
||||||
|
|
||||||
checkBox_adjust_input_rate->setChecked(config->adjust_input_rate_automatically);
|
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);
|
checkBox_dynamic_rate_control->setChecked(config->dynamic_rate_control);
|
||||||
doubleSpinBox_dynamic_rate_limit->setValue(config->dynamic_rate_limit);
|
doubleSpinBox_dynamic_rate_limit->setValue(config->dynamic_rate_limit);
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ class SoundPanel :
|
||||||
~SoundPanel();
|
~SoundPanel();
|
||||||
EmuApplication *app;
|
EmuApplication *app;
|
||||||
void showEvent(QShowEvent *event) override;
|
void showEvent(QShowEvent *event) override;
|
||||||
void setInputRateText(int value);
|
void updateInputRate();
|
||||||
|
|
||||||
std::vector<std::string> driver_list;
|
std::vector<std::string> driver_list;
|
||||||
};
|
};
|
Loading…
Reference in New Issue