11 static int play_file(const char *fname);
\r
12 static int cbfunc(void *buf, int size, void *cls);
\r
13 static void print_usage(const char *argv0);
\r
15 static int vol = 220;
\r
18 int main(int argc, char **argv)
\r
22 if(audio_init() == -1) {
\r
25 audio_setvolume(AUDIO_MASTER, vol);
\r
26 audio_setvolume(AUDIO_PCM, 255);
\r
28 for(i=1; i<argc; i++) {
\r
29 if(argv[i][0] == '-') {
\r
30 if(strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "-volume") == 0) {
\r
31 if(!argv[++i] || (vol = atoi(argv[i])) <= 0 || vol > 100) {
\r
32 fprintf(stderr, "%s must be followed by a number 1-100\n", argv[-1]);
\r
35 audio_setvolume(AUDIO_DEFAULT, vol * 255 / 100);
\r
37 } else if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) {
\r
38 print_usage(argv[0]);
\r
41 fprintf(stderr, "invalid option: %s\n", argv[i]);
\r
52 static unsigned char *dbg_samples;
\r
53 static int dbg_cur_offs;
\r
55 static int play_file(const char *fname)
\r
58 int paused = 0, muted = 0;
\r
61 if(!(au = au_open(fname))) {
\r
65 audio_set_callback(cbfunc, au);
\r
68 if(!(dbg_samples = malloc(au->size))) {
\r
69 perror("failed to preload samples into memory");
\r
73 if(au_read(au, dbg_samples, au->size) < au->size) {
\r
74 perror("failed to preload samples into memory");
\r
79 audio_play(au->rate, au->bits, au->chan);
\r
80 while(audio_isplaying()) {
\r
102 if(vol > 255) vol = 255;
\r
103 audio_setvolume(AUDIO_DEFAULT, vol);
\r
104 printf("volume: %d%%\n", 101 * vol / 256);
\r
109 if(vol < 0) vol = 0;
\r
110 audio_setvolume(AUDIO_DEFAULT, vol);
\r
111 printf("volume: %d%%\n", 101 * vol / 256);
\r
117 audio_setvolume(AUDIO_DEFAULT, 0);
\r
119 audio_setvolume(AUDIO_DEFAULT, vol);
\r
129 if(dbg_cur_offs != prev) {
\r
130 prev = dbg_cur_offs;
\r
133 printf("%3d%% - offs: %lu/%lu\n", 100 * prev / au->size, prev, au->size);
\r
149 static int cbfunc(void *buf, int size, void *cls)
\r
151 struct au_file *au = cls;
\r
153 if(dbg_cur_offs + size > au->size) {
\r
154 size = au->size - dbg_cur_offs;
\r
156 if(size <= 0) return 0;
\r
158 memcpy(buf, dbg_samples + dbg_cur_offs, size);
\r
159 dbg_cur_offs += size;
\r
163 static int cbfunc(void *buf, int size, void *cls)
\r
167 if((rd = au_read(cls, buf, size)) <= 0) {
\r
174 static void print_usage(const char *argv0)
\r
176 printf("Usage: %s [options] <file1> <file2> ... <filen>\n", argv0);
\r
177 printf("options:\n");
\r
178 printf(" -v,-volume <percent>: set audio volume (1-100)\n");
\r
179 printf(" -h,-help: print usage and exit\n");
\r