# HG changeset patch # User Joris van Rantwijk # Date 1245039004 18000 # Node ID b009fad90e9262681e8a29100994ff99d45ade38 # Parent 19e3ec80dac9bb5f416cea248a8a634f66d2b7c5 alsa-ng: buffer timing cleanups diff -r 19e3ec80dac9 -r b009fad90e92 src/alsa-ng/alsa-core.c --- a/src/alsa-ng/alsa-core.c Fri Jun 12 17:15:10 2009 -0400 +++ b/src/alsa-ng/alsa-core.c Sun Jun 14 23:10:04 2009 -0500 @@ -315,7 +315,10 @@ bitwidth = snd_pcm_format_physical_width(afmt); bps = (rate * bitwidth * nch) >> 3; ringbuf_size = aud_cfg->output_buffer_size * bps / 1000; - alsaplug_ringbuffer_init(&pcm_ringbuf, ringbuf_size); + if (alsaplug_ringbuffer_init(&pcm_ringbuf, ringbuf_size) == -1) { + _ERROR("alsaplug_ringbuffer_init failed"); + return -1; + } pcm_going = TRUE; flush_request = -1; @@ -371,14 +374,15 @@ if (pcm_going && pcm_handle != NULL) { + guint d = alsaplug_ringbuffer_used(&pcm_ringbuf); + if (!snd_pcm_delay(pcm_handle, &delay)) - { - guint d = snd_pcm_frames_to_bytes(pcm_handle, delay); - if (bytes < d) - bytes = 0; - else - bytes -= d; - } + d += snd_pcm_frames_to_bytes(pcm_handle, delay); + + if (bytes < d) + bytes = 0; + else + bytes -= d; ret = bytes * (long long) 1000 / bps; }