summaryrefslogtreecommitdiff
path: root/plugins/alsa
diff options
context:
space:
mode:
authorGravatar Themaister <maister@archlinux.us>2010-05-12 13:44:26 +0200
committerGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-05-12 21:28:22 +0200
commit599a24ec50818e0a389c4fe73758acddcd048865 (patch)
tree03ee3d601aefec29be0ffad64bf0add4345a9c8e /plugins/alsa
parentf9367cdd7fe79619630193357967ed41200f6f8b (diff)
Fix audio stuttering at start of audio stream.
Reading from the audio stream at the start of a stream may cause it to return 0, where the callback simply wrote 0s rather than wait for the stream to write audio back to it.
Diffstat (limited to 'plugins/alsa')
-rw-r--r--plugins/alsa/alsa.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/plugins/alsa/alsa.c b/plugins/alsa/alsa.c
index edc6d63a..bf51d9e2 100644
--- a/plugins/alsa/alsa.c
+++ b/plugins/alsa/alsa.c
@@ -58,7 +58,7 @@ static char conf_alsa_soundcard[100] = "default";
//static snd_async_handler_t *pcm_callback;
-static void
+static int
palsa_callback (char *stream, int len);
#if 0
@@ -497,9 +497,13 @@ palsa_thread (void *context) {
int written = 0;
snd_pcm_sframes_t frames_to_deliver = snd_pcm_avail_update (audio);
while (frames_to_deliver >= period_size) {
+ err = 0;
char buf[period_size * 4];
- palsa_callback (buf, period_size * 4);
- err = snd_pcm_writei (audio, buf, period_size);
+ int bytes_to_write = palsa_callback (buf, period_size * 4);
+
+ if ( bytes_to_write >= 4 )
+ err = snd_pcm_writei (audio, buf, snd_pcm_bytes_to_frames(audio, bytes_to_write));
+
if (err < 0) {
if (err == -ESTRPIPE) {
fprintf (stderr, "alsa: trying to recover from suspend... (error=%d, %s)\n", err, snd_strerror (err));
@@ -523,7 +527,7 @@ palsa_thread (void *context) {
}
}
-static void
+static int
palsa_callback (char *stream, int len) {
int bytesread = deadbeef->streamer_read (stream, len);
@@ -564,9 +568,7 @@ palsa_callback (char *stream, int len) {
((int16_t*)stream)[i] = (int16_t)(((int32_t)(((int16_t*)stream)[i])) * ivolume / 1000);
}
#endif
- if (bytesread < len) {
- memset (stream + bytesread, 0, len-bytesread);
- }
+ return bytesread;
}
static int