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, 255);
\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], "-h") == 0 || strcmp(argv[i], "-help") == 0) {
\r
31 print_usage(argv[0]);
\r
34 fprintf(stderr, "invalid option: %s\n", argv[i]);
\r
45 static unsigned char *dbg_samples;
\r
46 static int dbg_cur_offs;
\r
48 static int play_file(const char *fname)
\r
51 int paused = 0, muted = 0;
\r
54 if(!(au = au_open(fname))) {
\r
58 audio_set_callback(cbfunc, au);
\r
61 if(!(dbg_samples = malloc(au->size))) {
\r
62 perror("failed to preload samples into memory");
\r
66 if(au_read(au, dbg_samples, au->size) < au->size) {
\r
67 perror("failed to preload samples into memory");
\r
72 audio_play(au->rate, au->bits, au->chan);
\r
73 while(audio_isplaying()) {
\r
95 if(vol > 255) vol = 255;
\r
96 audio_setvolume(AUDIO_DEFAULT, vol);
\r
97 printf("volume: %d%%\n", 101 * vol / 256);
\r
102 if(vol < 0) vol = 0;
\r
103 audio_setvolume(AUDIO_DEFAULT, vol);
\r
104 printf("volume: %d%%\n", 101 * vol / 256);
\r
110 audio_setvolume(AUDIO_DEFAULT, 0);
\r
112 audio_setvolume(AUDIO_DEFAULT, vol);
\r
122 if(dbg_cur_offs != prev) {
\r
123 prev = dbg_cur_offs;
\r
126 printf("%3d%% - offs: %lu/%lu\n", 100 * prev / au->size, prev, au->size);
\r
142 static int cbfunc(void *buf, int size, void *cls)
\r
144 struct au_file *au = cls;
\r
146 if(dbg_cur_offs + size > au->size) {
\r
147 size = au->size - dbg_cur_offs;
\r
149 if(size <= 0) return 0;
\r
151 memcpy(buf, dbg_samples + dbg_cur_offs, size);
\r
152 dbg_cur_offs += size;
\r
156 static int cbfunc(void *buf, int size, void *cls)
\r
160 if((rd = au_read(cls, buf, size)) <= 0) {
\r
167 static void print_usage(const char *argv0)
\r
169 printf("Usage: %s [options] <file1> <file2> ... <filen>\n", argv0);
\r
170 printf("options:\n");
\r
171 printf(" -h,-help: print usage and exit\n");
\r