diff options
author | Themaister <maister@archlinux.us> | 2010-05-12 13:44:26 +0200 |
---|---|---|
committer | Alexey Yakovenko <wakeroid@gmail.com> | 2010-05-12 21:28:22 +0200 |
commit | 599a24ec50818e0a389c4fe73758acddcd048865 (patch) | |
tree | 03ee3d601aefec29be0ffad64bf0add4345a9c8e /plugins/oss | |
parent | f9367cdd7fe79619630193357967ed41200f6f8b (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/oss')
-rw-r--r-- | plugins/oss/oss.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/plugins/oss/oss.c b/plugins/oss/oss.c index 53ba8575..c98a9f83 100644 --- a/plugins/oss/oss.c +++ b/plugins/oss/oss.c @@ -53,7 +53,7 @@ static uintptr_t mutex; static void oss_thread (void *context); -static void +static int oss_callback (char *stream, int len); static int @@ -244,13 +244,17 @@ oss_thread (void *context) { usleep (10000); continue; } + + int res = 0; char buf[BLOCKSIZE]; - oss_callback (buf, sizeof (buf)); + int write_size = oss_callback (buf, sizeof (buf)); deadbeef->mutex_lock (mutex); - int res = write (fd, buf, sizeof (buf)); + if ( write_size > 0 ) + res = write (fd, buf, write_size); + deadbeef->mutex_unlock (mutex); - if (res != sizeof (buf)) { + if (res != write_size) { perror ("oss write"); fprintf (stderr, "oss: failed to write buffer\n"); } @@ -258,7 +262,7 @@ oss_thread (void *context) { } } -static void +static int oss_callback (char *stream, int len) { int bytesread = deadbeef->streamer_read (stream, len); int16_t ivolume = deadbeef->volume_get_amp () * 1000; @@ -266,9 +270,7 @@ oss_callback (char *stream, int len) { ((int16_t*)stream)[i] = (int16_t)(((int32_t)(((int16_t*)stream)[i])) * ivolume / 1000); } - if (bytesread < len) { - memset (stream + bytesread, 0, len-bytesread); - } + return bytesread; } static int |