From efe7d2c63c851df4a13641eab6e0eba45b1174eb Mon Sep 17 00:00:00 2001 From: James Laird Date: Mon, 1 Apr 2013 21:44:30 +1100 Subject: [PATCH] ao: add option parsing --- audio_ao.c | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/audio_ao.c b/audio_ao.c index b762bdc0..72556a4a 100644 --- a/audio_ao.c +++ b/audio_ao.c @@ -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) {