GTK: SoundSync is now handled in the drivers.

This commit is contained in:
Brandon Wright 2019-02-09 18:48:17 -06:00
parent b1039e7c65
commit 2ba6553c14
6 changed files with 61 additions and 57 deletions

View File

@ -327,23 +327,6 @@ event_hw_accel_changed (GtkComboBox *widget, gpointer data)
}
}
static void
event_frameskip_combo_changed (GtkComboBox *widget, gpointer user_data)
{
Snes9xPreferences *window = (Snes9xPreferences *) user_data;
if (window->get_combo ("frameskip_combo") == THROTTLE_SOUND_SYNC)
{
window->set_check ("dynamic_rate_control", 0);
window->enable_widget ("dynamic_rate_control", 0);
}
else
{
window->enable_widget ("dynamic_rate_control", 1);
}
}
static void
event_scale_method_changed (GtkComboBox *widget, gpointer user_data)
{
@ -532,7 +515,6 @@ Snes9xPreferences::Snes9xPreferences (Snes9xConfig *config) :
{ "game_data_clear", G_CALLBACK (event_game_data_clear) },
{ "about_clicked", G_CALLBACK (event_about_clicked) },
{ "auto_input_rate_toggled", G_CALLBACK (event_auto_input_rate_toggled) },
{ "frameskip_combo_changed", G_CALLBACK (event_frameskip_combo_changed) },
{ "calibrate", G_CALLBACK (event_calibrate) },
{ NULL, NULL }
};
@ -650,8 +632,6 @@ Snes9xPreferences::move_settings_to_dialog ()
config->auto_input_rate ? false : true);
set_spin ("sound_buffer_size", config->sound_buffer_size);
if (Settings.SkipFrames == THROTTLE_SOUND_SYNC)
Settings.DynamicRateControl = 0;
set_check ("dynamic_rate_control", Settings.DynamicRateControl);
set_spin ("dynamic_rate_limit", Settings.DynamicRateLimit / 1000.0);
set_spin ("rewind_buffer_size", config->rewind_buffer_size);
@ -701,7 +681,6 @@ Snes9xPreferences::move_settings_to_dialog ()
set_combo ("scanline_filter_intensity", config->scanline_filter_intensity);
set_combo ("frameskip_combo", Settings.SkipFrames);
enable_widget ("dynamic_rate_control", Settings.SkipFrames != THROTTLE_SOUND_SYNC);
set_check ("bilinear_filter", Settings.BilinearFilter);
#ifdef USE_OPENGL

View File

@ -501,28 +501,11 @@ static void S9xThrottle ()
frame_clock = now;
}
if (Settings.SkipFrames == THROTTLE_SOUND_SYNC &&
!Settings.DynamicRateControl)
if (Settings.SkipFrames == THROTTLE_SOUND_SYNC ||
Settings.SkipFrames == THROTTLE_NONE)
{
while (!S9xSyncSound())
{
usleep (100);
/* If we can't sync sound within a half-second, we're probably deadlocked */
if (g_get_monotonic_time() - now > 500000)
{
S9xClearSamples();
}
}
frame_clock = now;
IPPU.SkippedFrames = 0;
return;
}
else if (Settings.SkipFrames == THROTTLE_NONE)
{
frame_clock = now;
}
else // THROTTLE_TIMER or THROTTLE_TIMER_FRAMESKIP
{

View File

@ -164,39 +164,51 @@ void S9xAlsaSoundDriver::samples_available()
frames = snd_pcm_avail(pcm);
if (Settings.DynamicRateControl)
{
S9xUpdateDynamicRate(snd_pcm_frames_to_bytes(pcm, frames),
output_buffer_size);
}
if (frames < 0)
{
frames = snd_pcm_recover(pcm, frames, 1);
return;
}
S9xFinalizeSamples();
if (Settings.DynamicRateControl)
{
S9xUpdateDynamicRate(snd_pcm_frames_to_bytes(pcm, frames),
output_buffer_size);
}
S9xFinalizeSamples();
int snes_frames_available = S9xGetSampleCount() >> 1;
if (Settings.DynamicRateControl && !Settings.SoundSync)
{
// Using rate control, we should always keep the emulator's sound buffers empty to
// maintain an accurate measurement.
if (frames < (S9xGetSampleCount() >> 1))
if (frames < snes_frames_available)
{
S9xClearSamples();
return;
}
}
frames = MIN(frames, S9xGetSampleCount() >> 1);
if (Settings.SoundSync && !Settings.TurboMode && !Settings.Mute)
{
while (frames < snes_frames_available)
{
usleep(100);
frames = snd_pcm_avail(pcm);
if (frames < 0)
{
frames = snd_pcm_recover(pcm, frames, 1);
return;
}
}
}
frames = MIN(frames, snes_frames_available);
bytes = snd_pcm_frames_to_bytes(pcm, frames);
if (bytes <= 0)
{
return;
}
if (sound_buffer_size < bytes || sound_buffer == NULL)
{

View File

@ -168,7 +168,7 @@ void S9xOSSSoundDriver::samples_available()
samples_to_write = S9xGetSampleCount();
if (Settings.DynamicRateControl)
if (Settings.DynamicRateControl && !Settings.SoundSync)
{
// Using rate control, we should always keep the emulator's sound buffers empty to
// maintain an accurate measurement.
@ -179,6 +179,15 @@ void S9xOSSSoundDriver::samples_available()
}
}
if (Settings.SoundSync && !Settings.TurboMode && !Settings.Mute)
{
while (info.bytes >> 1 < samples_to_write)
{
usleep(100);
ioctl(filedes, SNDCTL_DSP_GETOSPACE, &info);
}
}
samples_to_write = MIN(info.bytes >> 1, samples_to_write) & ~1;
if (samples_to_write < 0)

View File

@ -188,8 +188,9 @@ void S9xPortAudioSoundDriver::samples_available()
}
S9xFinalizeSamples();
int snes_frames_available = S9xGetSampleCount() >> 1;
if (Settings.DynamicRateControl)
if (Settings.DynamicRateControl && !Settings.SoundSync)
{
// Using rate control, we should always keep the emulator's sound buffers empty to
// maintain an accurate measurement.
@ -200,7 +201,16 @@ void S9xPortAudioSoundDriver::samples_available()
}
}
frames = MIN(frames, S9xGetSampleCount() >> 1);
if (Settings.SoundSync && !Settings.TurboMode && !Settings.Mute)
{
while (frames < snes_frames_available)
{
usleep(100);
frames = Pa_GetStreamWriteAvailable(audio_stream);
}
}
frames = MIN(frames, snes_frames_available);
bytes = frames_to_bytes(frames);
if (sound_buffer_size < bytes || sound_buffer == NULL)

View File

@ -228,7 +228,7 @@ void S9xPulseSoundDriver::samples_available()
samples = S9xGetSampleCount();
if (Settings.DynamicRateControl)
if (Settings.DynamicRateControl && !Settings.SoundSync)
{
if ((int)bytes < (samples * 2))
{
@ -237,6 +237,17 @@ void S9xPulseSoundDriver::samples_available()
}
}
if (Settings.SoundSync && !Settings.TurboMode && !Settings.Mute)
{
while ((int)bytes < samples * 2)
{
usleep(100);
lock();
bytes = pa_stream_writable_size(stream);
unlock();
}
}
bytes = MIN((int)bytes, samples * 2) & ~1;
if (!bytes)