sad

simple audio daemon
git clone git://git.2f30.org/sad
Log | Files | Refs | LICENSE

commit 36abc4aa8310ef4a6dcaef1cc94d516e6b86ee74
parent 34af9f2c786920782753b967dcdea7ef2729dbae
Author: sin <sin@2f30.org>
Date:   Fri, 26 Dec 2014 11:25:23 +0000

Simplify decode()

Diffstat:
Msad.c | 6+++++-
Msad.h | 2+-
Mwav.c | 10++--------
3 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/sad.c b/sad.c @@ -63,6 +63,8 @@ static void doaudio(void) { Song *s; + short buf[2048]; + int nbytes; s = getcursong(); if (!s) @@ -77,9 +79,11 @@ doaudio(void) s->state = PLAYING; break; case PLAYING: - if (decoder->decode() <= 0) { + if ((nbytes = decoder->decode(buf, sizeof(buf))) <= 0) { decoder->close(); s->state = NONE; + } else { + output->play(buf, nbytes); } break; } diff --git a/sad.h b/sad.h @@ -28,7 +28,7 @@ typedef struct { typedef struct { int (*init)(void); int (*open)(const char *); - int (*decode)(void); + int (*decode)(void *, int); int (*close)(void); void (*exit)(void); } Decoder; diff --git a/wav.c b/wav.c @@ -61,15 +61,9 @@ err0: } static int -wavdecode(void) +wavdecode(void *buf, int nbytes) { - sf_count_t n; - short buf[2048]; - - n = sf_read_short(sf, buf, 2048); - if (n > 0) - output->play(buf, n * sizeof(short)); - return n * sizeof(short); + return sf_read_short(sf, buf, nbytes / sizeof(short)) * sizeof(short); } static int