]> git.mxchange.org Git - simgear.git/commitdiff
Add a function to retreive all available playback devices.
authorehofman <ehofman>
Sat, 28 Nov 2009 13:31:04 +0000 (13:31 +0000)
committerTim Moore <timoore@redhat.com>
Sun, 29 Nov 2009 12:04:39 +0000 (13:04 +0100)
simgear/sound/soundmgr_openal.cxx
simgear/sound/soundmgr_openal.hxx

index 692c78688c8f9a92d626ae484c21858644e0d15e..2ccbcf5543141ac381550d1adef0214fc33e27d5 100644 (file)
@@ -562,6 +562,32 @@ bool SGSoundMgr::load(string &samplepath, void **dbuf, int *fmt,
     return true;
 }
 
+vector<const char*> SGSoundMgr::get_available_devices()
+{
+    vector<const char*> devices;
+    const ALCchar *s;
+
+    if (alcIsExtensionPresent(NULL, "ALC_enumerate_all_EXT") == AL_TRUE) {
+        s = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
+    } else {
+        s = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
+    }
+
+    if (s) {
+        ALCchar *nptr, *ptr = (ALCchar *)s;
+
+        nptr = ptr;
+        while (*(nptr += strlen(ptr)+1) != 0)
+        {
+            devices.push_back(ptr);
+            ptr = nptr;
+        }
+        devices.push_back(ptr);
+    }
+
+    return devices;
+}
+
 
 bool SGSoundMgr::testForError(void *p, string s)
 {
index f1f9bd17a178d5feb8d518a030f40a7c0312e73d..2aa78bc518c3b8c8f63d7a83d84f677884208d66 100644 (file)
 # include <AL/alut.h>
 #endif
 
+#ifndef ALC_ALL_DEVICES_SPECIFIER
+# define ALC_ALL_DEVICES_SPECIFIER     0x1013
+#endif
+
 #include <simgear/compiler.h>
 #include <simgear/structure/subsystem_mgr.hxx>
 #include <simgear/math/SGMathFwd.hxx>
@@ -280,6 +284,11 @@ public:
     bool load(string &samplepath, void **data, int *format,
                                          size_t *size, int *freq );
 
+    /**
+     * Get a list of available playback devices.
+     */
+    vector<const char*> get_available_devices();
+
 private:
     static int _alut_init;