aboutsummaryrefslogtreecommitdiff
path: root/plugins/dfsound/alsa.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/dfsound/alsa.c')
-rw-r--r--plugins/dfsound/alsa.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/plugins/dfsound/alsa.c b/plugins/dfsound/alsa.c
index 6b9f83e..9873655 100644
--- a/plugins/dfsound/alsa.c
+++ b/plugins/dfsound/alsa.c
@@ -166,20 +166,22 @@ static void alsa_finish(void)
}
}
-// GET BYTES BUFFERED
-static int alsa_busy(void)
-{
+static float alsa_capacity(void) {
int l;
- if (handle == NULL) // failed to open?
- return 1;
+ if (handle == NULL) return 0;
+ if (buffer_size == 0) return 0;
+
l = snd_pcm_avail(handle);
if (l < 0) return 0;
- if (l < buffer_size / 2) // can we write in at least the half of fragments?
- l = 1; // -> no? wait
- else l = 0; // -> else go on
- return l;
+ return (float)l / buffer_size;
+}
+
+// GET BYTES BUFFERED
+static int alsa_busy(void)
+{
+ return alsa_capacity() < 0.5;
}
// FEED SOUND DATA
@@ -219,4 +221,5 @@ void out_register_alsa(struct out_driver *drv)
drv->finish = alsa_finish;
drv->busy = alsa_busy;
drv->feed = alsa_feed;
+ drv->capacity = alsa_capacity;
}