|
|
703c576 |
diff -Nur audacious-plugins-fedora-2.1-orig/src/alsa-ng/alsa-core.c audacious-plugins-fedora-2.1/src/alsa-ng/alsa-core.c
|
|
|
703c576 |
--- audacious-plugins-fedora-2.1-orig/src/alsa-ng/alsa-core.c 2009-10-21 13:18:35.825170784 +0200
|
|
|
63cefb0 |
+++ audacious-plugins-fedora-2.1/src/alsa-ng/alsa-core.c 2009-10-26 12:19:30.561386114 +0100
|
|
|
2dc41f8 |
@@ -27,6 +27,10 @@
|
|
|
2dc41f8 |
static gboolean pcm_going = FALSE;
|
|
|
2dc41f8 |
static GThread *audio_thread = NULL;
|
|
|
2dc41f8 |
static gint bps;
|
|
|
2dc41f8 |
+static gint loopbufsize = 384000;
|
|
|
2dc41f8 |
+static gint looppostsize = 2048;
|
|
|
2dc41f8 |
+static gint looppresize;
|
|
|
2dc41f8 |
+static gboolean prefill = TRUE;
|
|
|
2dc41f8 |
|
|
|
2dc41f8 |
static gsize wr_total = 0;
|
|
|
2dc41f8 |
static gsize wr_hwframes = 0;
|
|
|
2dc41f8 |
@@ -221,6 +225,9 @@
|
|
|
2dc41f8 |
}
|
|
|
2dc41f8 |
else
|
|
|
2dc41f8 |
{
|
|
|
2dc41f8 |
+ if (wr_frames == -EPIPE) {
|
|
|
2dc41f8 |
+ prefill = TRUE;
|
|
|
2dc41f8 |
+ }
|
|
|
2dc41f8 |
gint err = snd_pcm_recover(pcm_handle, wr_frames, 1);
|
|
|
2dc41f8 |
|
|
|
2dc41f8 |
_DEBUG ("snd_pcm_writei error: %s", snd_strerror (wr_frames));
|
|
|
2dc41f8 |
@@ -237,7 +244,7 @@
|
|
|
2dc41f8 |
static gpointer
|
|
|
2dc41f8 |
alsaplug_loop(gpointer unused)
|
|
|
2dc41f8 |
{
|
|
|
2dc41f8 |
- guchar buf[2048];
|
|
|
2dc41f8 |
+ guchar buf[loopbufsize];
|
|
|
2dc41f8 |
int size;
|
|
|
2dc41f8 |
|
|
|
2dc41f8 |
while (pcm_going)
|
|
|
2dc41f8 |
@@ -247,6 +254,7 @@
|
|
|
2dc41f8 |
if (flush_request != -1)
|
|
|
2dc41f8 |
{
|
|
|
2dc41f8 |
alsaplug_ringbuffer_reset (& pcm_ringbuf);
|
|
|
2dc41f8 |
+ prefill = TRUE;
|
|
|
2dc41f8 |
snd_pcm_drop(pcm_handle);
|
|
|
2dc41f8 |
snd_pcm_prepare(pcm_handle);
|
|
|
2dc41f8 |
wr_total = flush_request * (long long) bps / 1000;
|
|
|
703c576 |
@@ -264,12 +272,25 @@
|
|
|
2dc41f8 |
continue;
|
|
|
2dc41f8 |
}
|
|
|
2dc41f8 |
|
|
|
2dc41f8 |
- if (size > sizeof buf)
|
|
|
2dc41f8 |
- size = sizeof buf;
|
|
|
2dc41f8 |
+ if (prefill) {
|
|
|
2dc41f8 |
+ if (size > loopbufsize)
|
|
|
2dc41f8 |
+ size = loopbufsize;
|
|
|
2dc41f8 |
+
|
|
|
2dc41f8 |
+ if (size >= looppresize) {
|
|
|
2dc41f8 |
+ alsaplug_ringbuffer_read (& pcm_ringbuf, buf, size);
|
|
|
2dc41f8 |
+ prefill = FALSE;
|
|
|
2dc41f8 |
+ }
|
|
|
2dc41f8 |
+ }
|
|
|
2dc41f8 |
+ else {
|
|
|
2dc41f8 |
+ if (size > looppostsize)
|
|
|
2dc41f8 |
+ size = looppostsize;
|
|
|
2dc41f8 |
|
|
|
703c576 |
- alsaplug_ringbuffer_read (& pcm_ringbuf, buf, size);
|
|
|
2dc41f8 |
+ alsaplug_ringbuffer_read (& pcm_ringbuf, buf, size);
|
|
|
2dc41f8 |
+ }
|
|
|
2dc41f8 |
g_mutex_unlock (pcm_state_mutex);
|
|
|
2dc41f8 |
- alsaplug_write_buffer (buf, size);
|
|
|
2dc41f8 |
+ if (!prefill) {
|
|
|
2dc41f8 |
+ alsaplug_write_buffer (buf, size);
|
|
|
2dc41f8 |
+ }
|
|
|
2dc41f8 |
}
|
|
|
2dc41f8 |
|
|
|
2dc41f8 |
snd_pcm_drain(pcm_handle);
|
|
|
63cefb0 |
@@ -336,9 +357,10 @@
|
|
|
63cefb0 |
static gint
|
|
|
63cefb0 |
alsaplug_open_audio(AFormat fmt, gint rate, gint nch)
|
|
|
63cefb0 |
{
|
|
|
63cefb0 |
- gint err, bitwidth, ringbuf_size, buf_size;
|
|
|
63cefb0 |
+ gint err, bitwidth, ringbuf_size, buf_size, buf_size_norm;
|
|
|
703c576 |
snd_pcm_format_t afmt;
|
|
|
703c576 |
snd_pcm_hw_params_t *hwparams = NULL;
|
|
|
63cefb0 |
+ guint buf_time_min;
|
|
|
703c576 |
|
|
|
703c576 |
afmt = alsaplug_format_convert(fmt);
|
|
|
703c576 |
if (afmt == SND_PCM_FORMAT_UNKNOWN)
|
|
|
63cefb0 |
@@ -354,6 +376,10 @@
|
|
|
63cefb0 |
return -1;
|
|
|
63cefb0 |
}
|
|
|
63cefb0 |
|
|
|
63cefb0 |
+ buf_size = MAX(aud_cfg->output_buffer_size, 100);
|
|
|
63cefb0 |
+ buf_size_norm = MAX(buf_size-400, 100);
|
|
|
63cefb0 |
+ buf_time_min = buf_size_norm * 1000;
|
|
|
63cefb0 |
+
|
|
|
63cefb0 |
snd_pcm_hw_params_alloca(&hwparams);
|
|
|
63cefb0 |
snd_pcm_hw_params_any(pcm_handle, hwparams);
|
|
|
63cefb0 |
|
|
|
63cefb0 |
@@ -365,18 +391,25 @@
|
|
|
703c576 |
"snd_pcm_hw_params_set_channels");
|
|
|
703c576 |
CHECK_FAIL (snd_pcm_hw_params_set_rate (pcm_handle, hwparams, rate, 0),
|
|
|
703c576 |
"snd_pcm_hw_params_set_rate");
|
|
|
63cefb0 |
+ snd_pcm_hw_params_set_buffer_time_min (pcm_handle, hwparams, &buf_time_min, 0);
|
|
|
703c576 |
CHECK_FAIL (snd_pcm_hw_params (pcm_handle, hwparams), "snd_pcm_hw_params");
|
|
|
703c576 |
|
|
|
703c576 |
bitwidth = snd_pcm_format_physical_width(afmt);
|
|
|
63cefb0 |
bps = (rate * bitwidth * nch) >> 3;
|
|
|
63cefb0 |
|
|
|
63cefb0 |
- buf_size = MAX(aud_cfg->output_buffer_size, 100);
|
|
|
63cefb0 |
ringbuf_size = buf_size * bps / 1000;
|
|
|
63cefb0 |
|
|
|
63cefb0 |
if (alsaplug_ringbuffer_init(&pcm_ringbuf, ringbuf_size) == -1) {
|
|
|
2dc41f8 |
_ERROR("alsaplug_ringbuffer_init failed");
|
|
|
2dc41f8 |
return -1;
|
|
|
2dc41f8 |
}
|
|
|
2dc41f8 |
+ if (loopbufsize >= ringbuf_size) {
|
|
|
2dc41f8 |
+ looppresize = ringbuf_size/2;
|
|
|
2dc41f8 |
+ }
|
|
|
2dc41f8 |
+ else {
|
|
|
2dc41f8 |
+ looppresize = loopbufsize;
|
|
|
2dc41f8 |
+ }
|
|
|
2dc41f8 |
+ prefill = TRUE;
|
|
|
2dc41f8 |
|
|
|
2dc41f8 |
pcm_going = TRUE;
|
|
|
2dc41f8 |
flush_request = -1;
|
|
|
63cefb0 |
@@ -511,6 +544,7 @@
|
|
|
2dc41f8 |
{
|
|
|
2dc41f8 |
g_mutex_lock (pcm_state_mutex);
|
|
|
2dc41f8 |
paused = p;
|
|
|
2dc41f8 |
+ prefill = !paused;
|
|
|
2dc41f8 |
g_cond_broadcast (pcm_state_cond);
|
|
|
2dc41f8 |
g_mutex_unlock (pcm_state_mutex);
|
|
|
2dc41f8 |
}
|