diff options
-rw-r--r-- | sbc/sbcdec.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/sbc/sbcdec.c b/sbc/sbcdec.c index 0617fe04..3435e8f8 100644 --- a/sbc/sbcdec.c +++ b/sbc/sbcdec.c @@ -46,7 +46,7 @@ static void decode(char *filename, char *audiodevice, int tofile) struct stat st; off_t filesize; sbc_t sbc; - int fd, ad, pos, streamlen, framelen, count, format = AFMT_S16_BE; + int fd, ad, pos, streamlen, framelen, count, format = AFMT_S16_BE, written; if (stat(filename, &st) < 0) { fprintf(stderr, "Can't get size of file %s: %s\n", @@ -121,8 +121,8 @@ static void decode(char *filename, char *audiodevice, int tofile) if (count + sbc.len > BUF_SIZE) { // buffer is too full to stuff decoded audio in // so it must be written to the device - write(ad, buf, count); - count = 0; + written = write(ad, buf, count); + if(written > 0) count -= written; } // sanity check @@ -141,8 +141,10 @@ static void decode(char *filename, char *audiodevice, int tofile) framelen = sbc_decode(&sbc, stream + pos, streamlen - pos); } - if (count > 0) - write(ad, buf, count); + if (count > 0) { + written = write(ad, buf, count); + if(written > 0) count -= written; + } close: sbc_finish(&sbc); |