From: ehofman Date: Sat, 28 Nov 2009 13:31:04 +0000 (+0000) Subject: Add a function to retreive all available playback devices. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=a0aaa23904a25b99eeae4911e3b9b77ed9d37845;p=simgear.git Add a function to retreive all available playback devices. --- diff --git a/simgear/sound/soundmgr_openal.cxx b/simgear/sound/soundmgr_openal.cxx index 692c7868..2ccbcf55 100644 --- a/simgear/sound/soundmgr_openal.cxx +++ b/simgear/sound/soundmgr_openal.cxx @@ -562,6 +562,32 @@ bool SGSoundMgr::load(string &samplepath, void **dbuf, int *fmt, return true; } +vector SGSoundMgr::get_available_devices() +{ + vector 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) { diff --git a/simgear/sound/soundmgr_openal.hxx b/simgear/sound/soundmgr_openal.hxx index f1f9bd17..2aa78bc5 100644 --- a/simgear/sound/soundmgr_openal.hxx +++ b/simgear/sound/soundmgr_openal.hxx @@ -59,6 +59,10 @@ # include #endif +#ifndef ALC_ALL_DEVICES_SPECIFIER +# define ALC_ALL_DEVICES_SPECIFIER 0x1013 +#endif + #include #include #include @@ -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 get_available_devices(); + private: static int _alut_init;