mirror of https://github.com/snes9xgit/snes9x.git
GTK: Audio tweaks:
Be more intelligent about usleep times. Use ALSA's blocking mode to wait.
This commit is contained in:
parent
4aa65d1df6
commit
be52994d01
|
@ -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)
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
|
Loading…
Reference in New Issue