X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dos_auplay;a=blobdiff_plain;f=src%2Fmain.c;h=c88aa3b39bfabd7f80f3ea86a2325abc92804ad7;hp=2015a10661b8b5290ec58c020ba821667aee27ba;hb=6e29178202fe1876a0fb0231e71fa0e75a7b6460;hpb=87ef5613bb9baae3903237321c15133066139f7c diff --git a/src/main.c b/src/main.c index 2015a10..c88aa3b 100644 --- a/src/main.c +++ b/src/main.c @@ -1,15 +1,29 @@ #include +#include #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); +static int vol = 220; +static int quit; + int main(int argc, char **argv) { int i; - play_file("namarie.wav"); /* TODO remove */ + if(audio_init() == -1) { + return 1; + } + audio_setvolume(AUDIO_MASTER, 255); + audio_setvolume(AUDIO_PCM, 255); 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()) { + if(kbhit()) { + int c = getch(); + switch(c) { + case 27: + audio_stop(); + quit = 1; + goto end; + + case ' ': + paused = !paused; + if(paused) { + audio_pause(); + printf("pause\n"); + } else { + audio_resume(); + printf("resume\n"); + } + break; + + case '=': + vol += 32; + if(vol > 255) vol = 255; + audio_setvolume(AUDIO_DEFAULT, vol); + printf("volume: %d%%\n", 101 * vol / 256); + break; + + case '-': + vol -= 32; + if(vol < 0) vol = 0; + audio_setvolume(AUDIO_DEFAULT, vol); + printf("volume: %d%%\n", 101 * vol / 256); + break; + + case 'm': + muted = !muted; + if(muted) { + audio_setvolume(AUDIO_DEFAULT, 0); + } else { + audio_setvolume(AUDIO_DEFAULT, vol); + } + break; + + default: + break; + } + } + + _disable(); + if(dbg_cur_offs != prev) { + prev = dbg_cur_offs; + _enable(); + + printf("%3d%% - offs: %lu/%lu\n", 100 * prev / au->size, prev, au->size); + } else { + _enable(); + } + + } + +end: 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);