ao: add option parsing

This commit is contained in:
James Laird
2013-04-01 21:44:30 +11:00
parent f39ff3a44e
commit efe7d2c63c
+36 -5
View File
@@ -16,8 +16,42 @@ static void help(void) {
}
static int init(int argc, char **argv) {
printf("ao: init\n");
ao_initialize();
int driver = ao_default_driver_id();
ao_option *ao_opts = NULL;
optind = 0;
// some platforms apparently require optreset = 1; - which?
char opt, *mid;
while ((opt = getopt(argc, argv, "d:i:n:o:")) > 0) {
switch (opt) {
case 'd':
driver = ao_driver_id(optarg);
if (!driver)
die("could not find ao driver %s\n", optarg);
break;
case 'i':
ao_append_option(&ao_opts, "id", optarg);
break;
case 'n':
ao_append_option(&ao_opts, "dev", optarg);
// Old libao versions (for example, 0.8.8) only support
// "dsp" instead of "dev".
ao_append_option(&ao_opts, "dsp", optarg);
break;
case 'o':
mid = strchr(optarg, '=');
if (!mid)
die("Expected an = in audio option %s\n", optarg);
*mid = 0;
ao_append_option(&ao_opts, optarg, mid+1);
break;
default:
help();
die("Invalid audio option -%c specified\n", opt);
}
}
ao_sample_format fmt;
memset(&fmt, 0, sizeof(fmt));
@@ -26,8 +60,6 @@ static int init(int argc, char **argv) {
fmt.channels = 2;
fmt.byte_format = AO_FMT_NATIVE;
int driver = ao_default_driver_id();
dev = ao_open_live(driver, &fmt, NULL);
return dev ? 0 : 1;
@@ -39,9 +71,8 @@ static void deinit(void) {
}
static void start(int sample_rate) {
printf("ao: start\n");
if (sample_rate != 44100)
die("unexpceted sample rate!\n");
die("unexpected sample rate!\n");
}
static void play(short buf[], int samples) {