X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dos_auplay;a=blobdiff_plain;f=src%2Fmain.c;h=4395af6db91028fd42e2f4e31540a7b6df86a15a;hp=9a1b262e7236a75a24924e69657f7f116f279a07;hb=49ef4e243def029b7e68bf92141acbeac600e1e8;hpb=869f6c1ab78d6e2888bb008b3bd8604714f5151a diff --git a/src/main.c b/src/main.c index 9a1b262..4395af6 100644 --- a/src/main.c +++ b/src/main.c @@ -1,16 +1,22 @@ #include +#include #include #include "aufile.h" #include "audio.h" +#define DBG_PRELOAD + static int play_file(const char *fname); +static int cbfunc(void *buf, int size, void *cls); static void print_usage(const char *argv0); int main(int argc, char **argv) { int i; - play_file("namarie.wav"); /* TODO remove */ + if(audio_init() == -1) { + return 1; + } for(i=1; isize))) { + perror("failed to preload samples into memory"); + return -1; + } + dbg_cur_offs = 0; + if(au_read(au, dbg_samples, au->size) < au->size) { + perror("failed to preload samples into memory"); + return -1; + } +#endif + audio_play(au->rate, au->bits, au->chan); while(audio_isplaying()); au_close(au); +#ifdef DBG_PRELOAD + free(dbg_samples); +#endif return 0; } +#ifdef DBG_PRELOAD +static int cbfunc(void *buf, int size, void *cls) +{ + struct au_file *au = cls; + + if(dbg_cur_offs + size > au->size) { + size = au->size - dbg_cur_offs; + } + if(size <= 0) return 0; + + memcpy(buf, dbg_samples + dbg_cur_offs, size); + dbg_cur_offs += size; + return size; +} +#else +static int cbfunc(void *buf, int size, void *cls) +{ + int rd; + + if((rd = au_read(cls, buf, size)) <= 0) { + return 0; + } + return rd; +} +#endif + static void print_usage(const char *argv0) { printf("Usage: %s [options] ... \n", argv0);