Browse Source

Audio: implemented ALC_ENUMERATION_EXT.

pull/176/head
Vladimír Vondruš 10 years ago
parent
commit
238d2db591
  1. 2
      doc/openal-support.dox
  2. 32
      src/Magnum/Audio/Context.cpp
  3. 43
      src/Magnum/Audio/Context.h
  4. 4
      src/Magnum/Audio/magnum-al-info.cpp

2
doc/openal-support.dox

@ -38,7 +38,7 @@ functions and enum values are exposed through the API.
Extension | Status Extension | Status
------------------------------------------- | ------ ------------------------------------------- | ------
@alc_extension{ENUMERATION,EXT} | | @alc_extension{ENUMERATION,EXT} | done
@al_extension{EXT,double} | done @al_extension{EXT,double} | done
@al_extension{EXT,float32} | done @al_extension{EXT,float32} | done
@al_extension{EXT,ALAW} | done @al_extension{EXT,ALAW} | done

32
src/Magnum/Audio/Context.cpp

@ -30,6 +30,7 @@
#include <al.h> #include <al.h>
#include <alc.h> #include <alc.h>
#include <cstring>
#include <Corrade/Utility/Assert.h> #include <Corrade/Utility/Assert.h>
#include <Corrade/Utility/Debug.h> #include <Corrade/Utility/Debug.h>
@ -75,6 +76,15 @@ Debug& operator<<(Debug& debug, const Context::HrtfStatus value) {
Context* Context::_current = nullptr; Context* Context::_current = nullptr;
std::vector<std::string> Context::deviceSpecifierStrings() {
std::vector<std::string> list;
const char* const devices = alcGetString(nullptr, ALC_DEVICE_SPECIFIER);
for(const char* device = devices; *device; device += std::strlen(device) + 1)
list.push_back(device);
return list;
}
bool Context::hasCurrent() { return _current; } bool Context::hasCurrent() { return _current; }
Context& Context::current() { Context& Context::current() {
@ -87,11 +97,10 @@ Context::Context(): Context{Configuration{}} {}
Context::Context(const Configuration& config) { Context::Context(const Configuration& config) {
CORRADE_ASSERT(!_current, "Audio::Context: context already created", ); CORRADE_ASSERT(!_current, "Audio::Context: context already created", );
/* Open default device */ /* Open the device */
const ALCchar* const defaultDevice = alcGetString(nullptr, ALC_DEFAULT_DEVICE_SPECIFIER); const ALCchar* const deviceSpecifier = config.deviceSpecifier().empty() ? alcGetString(nullptr, ALC_DEFAULT_DEVICE_SPECIFIER) : config.deviceSpecifier().data();
_device = alcOpenDevice(defaultDevice); if(!(_device = alcOpenDevice(deviceSpecifier))) {
if(!_device) { Error() << "Audio::Context: cannot open sound device" << deviceSpecifier;
Error() << "Audio::Context: cannot open sound device" << defaultDevice;
std::exit(1); std::exit(1);
} }
@ -189,4 +198,17 @@ bool Context::tryCreateContext(const Configuration& config) {
return !!_context; return !!_context;
} }
Context::Configuration::Configuration() = default;
Context::Configuration::~Configuration() = default;
Context::Configuration& Context::Configuration::setDeviceSpecifier(const std::string& specifier) {
_deviceSpecifier = specifier;
return *this;
}
Context::Configuration& Context::Configuration::setDeviceSpecifier(std::string&& specifier) {
_deviceSpecifier = std::move(specifier);
return *this;
}
}} }}

43
src/Magnum/Audio/Context.h

@ -83,7 +83,6 @@ class MAGNUM_AUDIO_EXPORT Extension {
*/ */
class MAGNUM_AUDIO_EXPORT Context { class MAGNUM_AUDIO_EXPORT Context {
public: public:
/** /**
* @brief HRTF status * @brief HRTF status
* *
@ -127,6 +126,14 @@ class MAGNUM_AUDIO_EXPORT Context {
UnsupportedFormat = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT UnsupportedFormat = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT
}; };
/**
* @brief All device specifier strings
*
* @see @ref deviceSpecifierString(), @ref Configuration::setDeviceSpecifier()
* @fn_al{GetString} with @def_alc{DEVICE_SPECIFIER}
*/
static std::vector<std::string> deviceSpecifierStrings();
/** /**
* @brief Whether there is any current context * @brief Whether there is any current context
* *
@ -202,17 +209,27 @@ class MAGNUM_AUDIO_EXPORT Context {
return alcGetString(_device, ALC_HRTF_SPECIFIER_SOFT); return alcGetString(_device, ALC_HRTF_SPECIFIER_SOFT);
} }
/**
* @brief Device specifier string
*
* @see @ref deviceSpecifierStrings(), @ref vendorString(), @ref rendererString(),
* @fn_al{GetString} with @def_alc{DEVICE_SPECIFIER}
*/
std::string deviceSpecifierString() const { return alcGetString(_device, ALC_DEVICE_SPECIFIER); }
/** /**
* @brief Vendor string * @brief Vendor string
* *
* @see @ref rendererString(), @fn_al{GetString} with @def_al{VENDOR} * @see @ref deviceSpecifierString(), @ref rendererString(),
* @fn_al{GetString} with @def_al{VENDOR}
*/ */
std::string vendorString() const { return alGetString(AL_VENDOR); } std::string vendorString() const { return alGetString(AL_VENDOR); }
/** /**
* @brief Renderer string * @brief Renderer string
* *
* @see @ref vendorString(), @fn_al{GetString} with @def_al{RENDERER} * @see @ref deviceSpecifierString(), @ref vendorString(),
* @fn_al{GetString} with @def_al{RENDERER}
*/ */
std::string rendererString() const { return alGetString(AL_RENDERER); } std::string rendererString() const { return alGetString(AL_RENDERER); }
@ -314,8 +331,22 @@ class MAGNUM_AUDIO_EXPORT Context::Configuration {
Disabled = 2 /**< Disabled */ Disabled = 2 /**< Disabled */
}; };
/** @brief Constructor */ explicit Configuration();
explicit Configuration() {} ~Configuration();
/** @brief Device specifier */
const std::string& deviceSpecifier() const { return _deviceSpecifier; }
/**
* @brief Set device specifier
* @return Reference to self (for method chaining)
*
* If set to empty string (the default), default device specifier is
* used.
* @see @ref Context::deviceSpecifierStrings()
*/
Configuration& setDeviceSpecifier(const std::string& specifier);
Configuration& setDeviceSpecifier(std::string&& specifier); /**< @overload */
/** @brief Sampling rate in Hz */ /** @brief Sampling rate in Hz */
Int frequency() const { return _frequency; } Int frequency() const { return _frequency; }
@ -392,6 +423,8 @@ class MAGNUM_AUDIO_EXPORT Context::Configuration {
} }
private: private:
std::string _deviceSpecifier;
Int _frequency{-1}; Int _frequency{-1};
Hrtf _hrtf{}; Hrtf _hrtf{};

4
src/Magnum/Audio/magnum-al-info.cpp

@ -88,6 +88,10 @@ int main(const int argc, const char** const argv) {
Debug() << ""; Debug() << "";
Audio::Context c; Audio::Context c;
Debug() << "Available devices:";
for(const auto& device: Audio::Context::deviceSpecifierStrings())
Debug() << " " << device;
Debug() << "Current device:" << c.deviceSpecifierString();
if(args.isSet("extension-strings")) { if(args.isSet("extension-strings")) {
Debug() << "Extension strings:" << Debug::newline Debug() << "Extension strings:" << Debug::newline

Loading…
Cancel
Save