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
27 for(i=1; i<argc; i++) {
\r
28 if(argv[i][0] == '-') {
\r
29 if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) {
\r
30 print_usage(argv[0]);
\r
33 fprintf(stderr, "invalid option: %s\n", argv[i]);
\r
44 static unsigned char *dbg_samples;
\r
45 static int dbg_cur_offs;
\r
47 static int play_file(const char *fname)
\r
53 if(!(au = au_open(fname))) {
\r
57 audio_set_callback(cbfunc, au);
\r
60 if(!(dbg_samples = malloc(au->size))) {
\r
61 perror("failed to preload samples into memory");
\r
65 if(au_read(au, dbg_samples, au->size) < au->size) {
\r
66 perror("failed to preload samples into memory");
\r
71 audio_play(au->rate, au->bits, au->chan);
\r
72 while(audio_isplaying()) {
\r
94 if(vol > 255) vol = 255;
\r
96 printf("volume: %d%%\n", 101 * vol / 256);
\r
101 if(vol < 0) vol = 0;
\r
103 printf("volume: %d%%\n", 101 * vol / 256);
\r
112 if(dbg_cur_offs != prev) {
\r
113 prev = dbg_cur_offs;
\r
116 printf("%3d%% - offs: %lu/%lu\n", 100 * prev / au->size, prev, au->size);
\r
132 static int cbfunc(void *buf, int size, void *cls)
\r
134 struct au_file *au = cls;
\r
136 if(dbg_cur_offs + size > au->size) {
\r
137 size = au->size - dbg_cur_offs;
\r
139 if(size <= 0) return 0;
\r
141 memcpy(buf, dbg_samples + dbg_cur_offs, size);
\r
142 dbg_cur_offs += size;
\r
146 static int cbfunc(void *buf, int size, void *cls)
\r
150 if((rd = au_read(cls, buf, size)) <= 0) {
\r
157 static void print_usage(const char *argv0)
\r
159 printf("Usage: %s [options] <file1> <file2> ... <filen>\n", argv0);
\r
160 printf("options:\n");
\r
161 printf(" -h,-help: print usage and exit\n");
\r