X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dos_auplay;a=blobdiff_plain;f=src%2Fmain.c;h=107cd11ec2d460be71a7c871893e45649dd0c6cc;hp=4395af6db91028fd42e2f4e31540a7b6df86a15a;hb=9a54081e387f5c08e1d1a6077283528c62509956;hpb=49ef4e243def029b7e68bf92141acbeac600e1e8 diff --git a/src/main.c b/src/main.c index 4395af6..107cd11 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include "aufile.h" #include "audio.h" @@ -10,17 +12,29 @@ 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; + int i, vol; if(audio_init() == -1) { return 1; } + audio_setvolume(AUDIO_MASTER, 255); + audio_setvolume(AUDIO_PCM, 255); for(i=1; i 100) { + fprintf(stderr, "%s must be followed by a number 1-100\n", argv[-1]); + return 1; + } + audio_setvolume(AUDIO_MASTER, vol * 255 / 100); + + } else if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) { print_usage(argv[0]); return 0; } else { @@ -29,6 +43,7 @@ int main(int argc, char **argv) } } else { play_file(argv[i]); + if(quit) break; } } return 0; @@ -40,6 +55,8 @@ static int dbg_cur_offs; static int play_file(const char *fname) { struct au_file *au; + int paused = 0, muted = 0; + unsigned long prev; if(!(au = au_open(fname))) { return -1; @@ -60,8 +77,67 @@ static int play_file(const char *fname) #endif audio_play(au->rate, au->bits, au->chan); - while(audio_isplaying()); + 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); @@ -99,5 +175,6 @@ static void print_usage(const char *argv0) { printf("Usage: %s [options] ... \n", argv0); printf("options:\n"); + printf(" -v,-volume : set audio volume (1-100)\n"); printf(" -h,-help: print usage and exit\n"); }