aboutsummaryrefslogtreecommitdiffstats
path: root/examples/common/alhelpers.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2016-09-08 12:05:08 -0700
committerChris Robinson <[email protected]>2016-09-08 12:14:28 -0700
commit0f24f49a44a12d139692d0846b2722de2213f1a8 (patch)
treeed7a9c9954e56082a27bebfa07fc4c6fbce18c43 /examples/common/alhelpers.c
parentb21e481827b660e7439fcebb505cdb0349517a54 (diff)
Allow specifying the device to open for the examples
Diffstat (limited to 'examples/common/alhelpers.c')
-rw-r--r--examples/common/alhelpers.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/examples/common/alhelpers.c b/examples/common/alhelpers.c
index 4582321c..43548b5c 100644
--- a/examples/common/alhelpers.c
+++ b/examples/common/alhelpers.c
@@ -29,6 +29,7 @@
* channel configs and sample types. */
#include <stdio.h>
+#include <string.h>
#include "AL/al.h"
#include "AL/alc.h"
@@ -37,15 +38,26 @@
#include "alhelpers.h"
-/* InitAL opens the default device and sets up a context using default
- * attributes, making the program ready to call OpenAL functions. */
-int InitAL(void)
+/* InitAL opens a device and sets up a context using default attributes, making
+ * the program ready to call OpenAL functions. */
+int InitAL(char ***argv, int *argc)
{
+ const ALCchar *name;
ALCdevice *device;
ALCcontext *ctx;
- /* Open and initialize a device with default settings */
- device = alcOpenDevice(NULL);
+ /* Open and initialize a device */
+ device = NULL;
+ if(argc && argv && *argc > 1 && strcmp((*argv)[0], "-device") == 0)
+ {
+ device = alcOpenDevice((*argv)[1]);
+ if(!device)
+ fprintf(stderr, "Failed to open \"%s\", trying default\n", (*argv)[1]);
+ (*argv) += 2;
+ (*argc) -= 2;
+ }
+ if(!device)
+ device = alcOpenDevice(NULL);
if(!device)
{
fprintf(stderr, "Could not open a device!\n");
@@ -62,7 +74,13 @@ int InitAL(void)
return 1;
}
- printf("Opened \"%s\"\n", alcGetString(device, ALC_DEVICE_SPECIFIER));
+ name = NULL;
+ if(alcIsExtensionPresent(device, "ALC_ENUMERATE_ALL_EXT"))
+ name = alcGetString(device, ALC_ALL_DEVICES_SPECIFIER);
+ if(!name || alcGetError(device) != AL_NO_ERROR)
+ name = alcGetString(device, ALC_DEVICE_SPECIFIER);
+ printf("Opened \"%s\"\n", name);
+
return 0;
}