Mercurial > SDL_sound_CoreAudio
comparison playsound/playsound.c @ 187:bfe5031726e8
printf() fix (extra comma was in there), and --decodebuf/--audiobuf
functionality was added.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Thu, 27 Dec 2001 23:07:26 +0000 |
parents | 47cc2de2ae36 |
children | 9d436dbb1666 |
comparison
equal
deleted
inserted
replaced
186:70561bf8d5fd | 187:bfe5031726e8 |
---|---|
30 #include <assert.h> | 30 #include <assert.h> |
31 #include <signal.h> | 31 #include <signal.h> |
32 #include "SDL.h" | 32 #include "SDL.h" |
33 #include "SDL_sound.h" | 33 #include "SDL_sound.h" |
34 | 34 |
35 #define DEFAULT_DECODEBUF 16384 | |
36 #define DEFAULT_AUDIOBUF 4096 | |
37 | |
35 #define PLAYSOUND_VER_MAJOR 0 | 38 #define PLAYSOUND_VER_MAJOR 0 |
36 #define PLAYSOUND_VER_MINOR 1 | 39 #define PLAYSOUND_VER_MINOR 1 |
37 #define PLAYSOUND_VER_PATCH 3 | 40 #define PLAYSOUND_VER_PATCH 3 |
38 | |
39 | 41 |
40 static void output_versions(const char *argv0) | 42 static void output_versions(const char *argv0) |
41 { | 43 { |
42 Sound_Version compiled; | 44 Sound_Version compiled; |
43 Sound_Version linked; | 45 Sound_Version linked; |
94 | 96 |
95 | 97 |
96 static void output_usage(const char *argv0) | 98 static void output_usage(const char *argv0) |
97 { | 99 { |
98 fprintf(stderr, | 100 fprintf(stderr, |
99 "USAGE: %s [...options...] [soundFile1] ... [soundFileN]\n" | 101 "USAGE: %s [...options...] [soundFile1] ... [soundFileN]\n" |
100 "\n" | 102 "\n" |
101 " Options:\n" | 103 " Options:\n" |
102 " --rate x Playback at sample rate of x HZ.\n" | 104 " --rate n Playback at sample rate of n HZ.\n" |
103 " --format fmt Playback in fmt format (see below).\n" | 105 " --format fmt Playback in fmt format (see below).\n" |
104 " --channels n Playback on n channels (1 or 2).\n" | 106 " --channels n Playback on n channels (1 or 2).\n" |
105 " --version Display version information and exit.\n" | 107 " --decodebuf n Buffer n decoded bytes at a time (default %d).\n" |
106 " --decoders List supported sound formats and exit.\n" | 108 " --audiobuf n Buffer n samples to audio device (default %d).\n" |
107 " --predecode Decode entire sample before playback.\n" | 109 " --version Display version information and exit.\n" |
108 " --credits Shameless promotion.\n" | 110 " --decoders List supported data formats and exit.\n" |
109 " --help Display this information and exit.\n" | 111 " --predecode Decode entire sample before playback.\n" |
110 "\n" | 112 " --credits Shameless promotion.\n" |
111 " Valid arguments to the --format option are:\n" | 113 " --help Display this information and exit.\n" |
112 " U8 Unsigned 8-bit.\n" | 114 "\n" |
113 " S8 Signed 8-bit.\n" | 115 " Valid arguments to the --format option are:\n" |
114 " U16LSB Unsigned 16-bit (least significant byte first).\n" | 116 " U8 Unsigned 8-bit.\n" |
115 " U16MSB Unsigned 16-bit (most significant byte first).\n" | 117 " S8 Signed 8-bit.\n" |
116 " S16LSB Signed 16-bit (least significant byte first).\n" | 118 " U16LSB Unsigned 16-bit (least significant byte first).\n" |
117 " S16MSB Signed 16-bit (most significant byte first).\n" | 119 " U16MSB Unsigned 16-bit (most significant byte first).\n" |
118 "\n", | 120 " S16LSB Signed 16-bit (least significant byte first).\n" |
119 argv0); | 121 " S16MSB Signed 16-bit (most significant byte first).\n" |
122 "\n", | |
123 argv0, DEFAULT_DECODEBUF, DEFAULT_AUDIOBUF); | |
120 } /* output_usage */ | 124 } /* output_usage */ |
121 | 125 |
122 | 126 |
123 static void output_credits(void) | 127 static void output_credits(void) |
124 { | 128 { |
226 | 230 |
227 | 231 |
228 int main(int argc, char **argv) | 232 int main(int argc, char **argv) |
229 { | 233 { |
230 Sound_AudioInfo sound_desired; | 234 Sound_AudioInfo sound_desired; |
235 Uint32 audio_buffersize = DEFAULT_AUDIOBUF; | |
236 Uint32 decode_buffersize = DEFAULT_DECODEBUF; | |
231 SDL_AudioSpec sdl_desired; | 237 SDL_AudioSpec sdl_desired; |
232 SDL_AudioSpec sdl_actual; | 238 SDL_AudioSpec sdl_actual; |
233 Sound_Sample *sample; | 239 Sound_Sample *sample; |
234 int predecode = 0; | 240 int predecode = 0; |
235 int use_specific_audiofmt = 0; | 241 int use_specific_audiofmt = 0; |
302 fprintf(stderr, | 308 fprintf(stderr, |
303 "Bad argument to --channels! Try 1 (mono) or 2 " | 309 "Bad argument to --channels! Try 1 (mono) or 2 " |
304 "(stereo).\n"); | 310 "(stereo).\n"); |
305 return(42); | 311 return(42); |
306 } | 312 } |
313 } /* else if */ | |
314 | |
315 else if (strcmp(argv[i], "--audiobuf") == 0 && argc > i + 1) | |
316 { | |
317 audio_buffersize = atoi(argv[++i]); | |
318 } /* else if */ | |
319 | |
320 else if (strcmp(argv[i], "--decodebuf") == 0 && argc > i + 1) | |
321 { | |
322 decode_buffersize = atoi(argv[++i]); | |
307 } /* else if */ | 323 } /* else if */ |
308 | 324 |
309 else if (strcmp(argv[i], "--decoders") == 0) | 325 else if (strcmp(argv[i], "--decoders") == 0) |
310 { | 326 { |
311 if (!Sound_Init()) | 327 if (!Sound_Init()) |
364 for (i = 1; i < argc; i++) | 380 for (i = 1; i < argc; i++) |
365 { | 381 { |
366 /* !!! FIXME: This is ugly! */ | 382 /* !!! FIXME: This is ugly! */ |
367 if ( (strcmp(argv[i], "--rate") == 0) || | 383 if ( (strcmp(argv[i], "--rate") == 0) || |
368 (strcmp(argv[i], "--format") == 0) || | 384 (strcmp(argv[i], "--format") == 0) || |
369 (strcmp(argv[i], "--channels") == 0) ) | 385 (strcmp(argv[i], "--channels") == 0) || |
386 (strcmp(argv[i], "--audiobuf") == 0) || | |
387 (strcmp(argv[i], "--decodebuf") == 0) ) | |
370 { | 388 { |
371 i++; | 389 i++; |
372 continue; | 390 continue; |
373 } /* if */ | 391 } /* if */ |
374 | 392 |
375 if (strncmp(argv[i], "--", 2) == 0) | 393 if (strncmp(argv[i], "--", 2) == 0) |
376 continue; | 394 continue; |
377 | 395 |
378 sample = Sound_NewSampleFromFile(argv[i], | 396 sample = Sound_NewSampleFromFile(argv[i], |
379 use_specific_audiofmt ? &sound_desired : NULL, 4096 * 4); | 397 use_specific_audiofmt ? &sound_desired : NULL, |
398 decode_buffersize); | |
380 | 399 |
381 if (!sample) | 400 if (!sample) |
382 { | 401 { |
383 fprintf(stderr, "Couldn't load \"%s\"!\n" | 402 fprintf(stderr, "Couldn't load \"%s\"!\n" |
384 " reason: [%s].\n", argv[i], Sound_GetError()); | 403 " reason: [%s].\n", argv[i], Sound_GetError()); |
400 sdl_desired.freq = sample->actual.rate; | 419 sdl_desired.freq = sample->actual.rate; |
401 sdl_desired.format = sample->actual.format; | 420 sdl_desired.format = sample->actual.format; |
402 sdl_desired.channels = sample->actual.channels; | 421 sdl_desired.channels = sample->actual.channels; |
403 } /* else */ | 422 } /* else */ |
404 | 423 |
405 sdl_desired.samples = 4096; | 424 sdl_desired.samples = audio_buffersize; |
406 sdl_desired.callback = audio_callback; | 425 sdl_desired.callback = audio_callback; |
407 sdl_desired.userdata = sample; | 426 sdl_desired.userdata = sample; |
408 | 427 |
409 if (SDL_OpenAudio(&sdl_desired, NULL) < 0) | 428 if (SDL_OpenAudio(&sdl_desired, NULL) < 0) |
410 { | 429 { |
424 decoded_ptr = sample->buffer; | 443 decoded_ptr = sample->buffer; |
425 if (sample->flags & SOUND_SAMPLEFLAG_ERROR) | 444 if (sample->flags & SOUND_SAMPLEFLAG_ERROR) |
426 { | 445 { |
427 fprintf(stderr, | 446 fprintf(stderr, |
428 "Couldn't fully decode \"%s\"!\n" | 447 "Couldn't fully decode \"%s\"!\n" |
429 " reason: [%s].\n", | 448 " reason: [%s].\n" |
430 " (playing first %lu bytes of decoded data...)\n", | 449 " (playing first %lu bytes of decoded data...)\n", |
431 argv[i], Sound_GetError(), decoded_bytes); | 450 argv[i], Sound_GetError(), decoded_bytes); |
432 } /* if */ | 451 } /* if */ |
433 else | 452 else |
434 { | 453 { |