From 0f24f49a44a12d139692d0846b2722de2213f1a8 Mon Sep 17 00:00:00 2001
From: Chris Robinson <chris.kcat@gmail.com>
Date: Thu, 8 Sep 2016 12:05:08 -0700
Subject: Allow specifying the device to open for the examples

---
 examples/alhrtf.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

(limited to 'examples/alhrtf.c')

diff --git a/examples/alhrtf.c b/examples/alhrtf.c
index 23d60a74..3964a7c6 100644
--- a/examples/alhrtf.c
+++ b/examples/alhrtf.c
@@ -122,28 +122,18 @@ int main(int argc, char **argv)
     ALdouble angle;
     ALenum state;
 
-    /* Print out usage if no file was specified */
-    if(argc < 2 || (strcmp(argv[1], "-hrtf") == 0 && argc < 4))
+    /* Print out usage if no arguments were specified */
+    if(argc < 2)
     {
-        fprintf(stderr, "Usage: %s [-hrtf <name>] <soundfile>\n", argv[0]);
+        fprintf(stderr, "Usage: %s [-device <name>] [-hrtf <name>] <soundfile>\n", argv[0]);
         return 1;
     }
 
-    /* Initialize OpenAL with the default device, and check for HRTF support. */
-    if(InitAL() != 0)
+    /* Initialize OpenAL, and check for HRTF support. */
+    argv++; argc--;
+    if(InitAL(&argv, &argc) != 0)
         return 1;
 
-    if(strcmp(argv[1], "-hrtf") == 0)
-    {
-        hrtfname = argv[2];
-        soundname = argv[3];
-    }
-    else
-    {
-        hrtfname = NULL;
-        soundname = argv[1];
-    }
-
     device = alcGetContextsDevice(alcGetCurrentContext());
     if(!alcIsExtensionPresent(device, "ALC_SOFT_HRTF"))
     {
@@ -164,6 +154,18 @@ int main(int argc, char **argv)
     has_angle_ext = alIsExtensionPresent("AL_EXT_STEREO_ANGLES");
     printf("AL_EXT_STEREO_ANGLES%s found\n", has_angle_ext?"":" not");
 
+    /* Check for user-preferred HRTF */
+    if(strcmp(argv[0], "-hrtf") == 0)
+    {
+        hrtfname = argv[1];
+        soundname = argv[2];
+    }
+    else
+    {
+        hrtfname = NULL;
+        soundname = argv[0];
+    }
+
     /* Enumerate available HRTFs, and reset the device using one. */
     alcGetIntegerv(device, ALC_NUM_HRTF_SPECIFIERS_SOFT, 1, &num_hrtf);
     if(!num_hrtf)
-- 
cgit v1.2.3