GTK: Audio tweaks:

Be more intelligent about usleep times.
Use ALSA's blocking mode to wait.
This commit is contained in:
Brandon Wright 2019-02-12 12:00:03 -06:00
parent 4aa65d1df6
commit be52994d01
4 changed files with 20 additions and 17 deletions

View File

@ -192,19 +192,14 @@ void S9xAlsaSoundDriver::samples_available()
if (Settings.SoundSync && !Settings.TurboMode && !Settings.Mute) if (Settings.SoundSync && !Settings.TurboMode && !Settings.Mute)
{ {
while (frames < snes_frames_available) snd_pcm_nonblock(pcm, 0);
{ frames = snes_frames_available;
usleep(100); }
frames = snd_pcm_avail(pcm); else
if (frames < 0) {
{ snd_pcm_nonblock(pcm, 1);
frames = snd_pcm_recover(pcm, frames, 1); frames = MIN(frames, snes_frames_available);
return;
}
}
} }
frames = MIN(frames, snes_frames_available);
bytes = snd_pcm_frames_to_bytes(pcm, frames); bytes = snd_pcm_frames_to_bytes(pcm, frames);
if (bytes <= 0) if (bytes <= 0)

View File

@ -183,12 +183,16 @@ void S9xOSSSoundDriver::samples_available()
{ {
while (info.bytes >> 1 < samples_to_write) while (info.bytes >> 1 < samples_to_write)
{ {
usleep(100); int usec_to_sleep = ((samples_to_write >> 1) - (info.bytes >> 2)) * 10000 /
(Settings.SoundPlaybackRate / 100);
usleep(usec_to_sleep > 0 ? usec_to_sleep : 0);
ioctl(filedes, SNDCTL_DSP_GETOSPACE, &info); ioctl(filedes, SNDCTL_DSP_GETOSPACE, &info);
} }
} }
else
samples_to_write = MIN(info.bytes >> 1, samples_to_write) & ~1; {
samples_to_write = MIN(info.bytes >> 1, samples_to_write) & ~1;
}
if (samples_to_write < 0) if (samples_to_write < 0)
return; return;

View File

@ -205,7 +205,9 @@ void S9xPortAudioSoundDriver::samples_available()
{ {
while (frames < snes_frames_available) while (frames < snes_frames_available)
{ {
usleep(100); int usec_to_sleep = (snes_frames_available - frames) * 10000 /
(Settings.SoundPlaybackRate / 100);
usleep(usec_to_sleep > 0 ? usec_to_sleep : 0);
frames = Pa_GetStreamWriteAvailable(audio_stream); frames = Pa_GetStreamWriteAvailable(audio_stream);
} }
} }

View File

@ -241,7 +241,9 @@ void S9xPulseSoundDriver::samples_available()
{ {
while ((int)bytes < samples * 2) while ((int)bytes < samples * 2)
{ {
usleep(100); int usec_to_sleep = ((samples >> 1) - (bytes >> 2)) * 10000 /
(Settings.SoundPlaybackRate / 100);
usleep(usec_to_sleep > 0 ? usec_to_sleep : 0);
lock(); lock();
bytes = pa_stream_writable_size(stream); bytes = pa_stream_writable_size(stream);
unlock(); unlock();