Browse Source

Audio: Add Error and Context::Error enums, debug operator and test

Signed-off-by: Squareys <squareys@googlemail.com>
pull/216/head
Squareys 9 years ago
parent
commit
eedd1b20d2
  1. 38
      src/Magnum/Audio/Context.cpp
  2. 52
      src/Magnum/Audio/Context.h
  3. 18
      src/Magnum/Audio/Test/ContextTest.cpp

38
src/Magnum/Audio/Context.cpp

@ -74,6 +74,40 @@ Debug& operator<<(Debug& debug, const Context::HrtfStatus value) {
return debug << "Audio::Context::HrtfStatus(" << Debug::nospace << reinterpret_cast<void*>(ALenum(value)) << Debug::nospace << ")"; return debug << "Audio::Context::HrtfStatus(" << Debug::nospace << reinterpret_cast<void*>(ALenum(value)) << Debug::nospace << ")";
} }
Debug& operator<<(Debug& debug, const Error value) {
switch(value) {
/* LCOV_EXCL_START */
#define _c(value) case Error::value: return debug << "Audio::Error::" #value;
_c(None)
_c(InvalidName)
_c(InvalidEnum)
_c(InvalidValue)
_c(InvalidOperation)
_c(OutOfMemory)
#undef _c
/* LCOV_EXCL_STOP */
}
return debug << "Audio::Error(" << Debug::nospace << reinterpret_cast<void*>(ALenum(value)) << Debug::nospace << ")";
}
Debug& operator<<(Debug& debug, const Context::Error value) {
switch(value) {
/* LCOV_EXCL_START */
#define _c(value) case Context::Error::value: return debug << "Audio::Context::Error::" #value;
_c(None)
_c(InvalidDevice)
_c(InvalidContext)
_c(InvalidEnum)
_c(InvalidValue)
_c(OutOfMemory)
#undef _c
/* LCOV_EXCL_STOP */
}
return debug << "Audio::Context::Error(" << Debug::nospace << reinterpret_cast<void*>(ALenum(value)) << Debug::nospace << ")";
}
Context* Context::_current = nullptr; Context* Context::_current = nullptr;
std::vector<std::string> Context::deviceSpecifierStrings() { std::vector<std::string> Context::deviceSpecifierStrings() {
@ -100,12 +134,12 @@ Context::Context(const Configuration& config) {
/* Open the device */ /* Open the device */
const ALCchar* const deviceSpecifier = config.deviceSpecifier().empty() ? alcGetString(nullptr, ALC_DEFAULT_DEVICE_SPECIFIER) : config.deviceSpecifier().data(); const ALCchar* const deviceSpecifier = config.deviceSpecifier().empty() ? alcGetString(nullptr, ALC_DEFAULT_DEVICE_SPECIFIER) : config.deviceSpecifier().data();
if(!(_device = alcOpenDevice(deviceSpecifier))) { if(!(_device = alcOpenDevice(deviceSpecifier))) {
Error() << "Audio::Context: cannot open sound device" << deviceSpecifier; Magnum::Error() << "Audio::Context: cannot open sound device" << deviceSpecifier;
std::exit(1); std::exit(1);
} }
if(!tryCreateContext(config)) { if(!tryCreateContext(config)) {
Error() << "Audio::Context: cannot create context:" << alcGetError(_device); Magnum::Error() << "Audio::Context: cannot create context:" << Audio::Context::Error(alcGetError(_device));
std::exit(1); std::exit(1);
} }

52
src/Magnum/Audio/Context.h

@ -50,6 +50,29 @@ typedef struct ALCcontext_struct ALCcontext;
namespace Magnum { namespace Audio { namespace Magnum { namespace Audio {
/**
* @brief OpenAL error
*/
enum class Error: ALenum {
/** No error */
None = AL_NO_ERROR,
/** Invalid name parameter passed to AL call. */
InvalidName = AL_INVALID_NAME,
/** Invalid enum parameter passed to AL call. */
InvalidEnum = AL_INVALID_ENUM,
/** Invalid value parameter passed to AL call. */
InvalidValue = AL_INVALID_VALUE,
/** Illegal AL call. */
InvalidOperation = AL_INVALID_OPERATION,
/** Out of memory. */
OutOfMemory = AL_OUT_OF_MEMORY
};
/** /**
@brief Run-time information about OpenAL extension @brief Run-time information about OpenAL extension
@ -126,6 +149,29 @@ class MAGNUM_AUDIO_EXPORT Context {
UnsupportedFormat = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT UnsupportedFormat = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT
}; };
/**
* @brief OpenAL context error
*/
enum class Error: ALenum {
/** No error. */
None = ALC_NO_ERROR,
/** Invalid device handle. */
InvalidDevice = ALC_INVALID_DEVICE,
/** Invalid context handle. */
InvalidContext = ALC_INVALID_CONTEXT,
/** Invalid enum parameter passed to an ALC call. */
InvalidEnum = ALC_INVALID_ENUM,
/** Invalid value parameter passed to an ALC call. */
InvalidValue = ALC_INVALID_VALUE,
/** Out of memory. */
OutOfMemory = ALC_OUT_OF_MEMORY
};
/** /**
* @brief All device specifier strings * @brief All device specifier strings
* *
@ -467,6 +513,12 @@ MAGNUM_ASSERT_AUDIO_EXTENSION_SUPPORTED(Extensions::ALC::SOFTX::HRTF);
/** @debugoperatorclassenum{Magnum::Audio::Context,Magnum::Audio::Context::HrtfStatus} */ /** @debugoperatorclassenum{Magnum::Audio::Context,Magnum::Audio::Context::HrtfStatus} */
MAGNUM_AUDIO_EXPORT Debug& operator<<(Debug& debug, Context::HrtfStatus value); MAGNUM_AUDIO_EXPORT Debug& operator<<(Debug& debug, Context::HrtfStatus value);
/** @debugoperatorclassenum{Magnum::Audio::Context,Magnum::Audio::Error} */
MAGNUM_AUDIO_EXPORT Debug& operator<<(Debug& debug, Error value);
/** @debugoperatorclassenum{Magnum::Audio::Context,Magnum::Audio::Context::Error} */
MAGNUM_AUDIO_EXPORT Debug& operator<<(Debug& debug, Context::Error value);
inline bool Context::isHrtfEnabled() const { inline bool Context::isHrtfEnabled() const {
Int enabled; Int enabled;
alcGetIntegerv(_device, ALC_HRTF_SOFT, 1, &enabled); alcGetIntegerv(_device, ALC_HRTF_SOFT, 1, &enabled);

18
src/Magnum/Audio/Test/ContextTest.cpp

@ -35,10 +35,14 @@ struct ContextTest: TestSuite::Tester {
explicit ContextTest(); explicit ContextTest();
void debugHrtfStatus(); void debugHrtfStatus();
void debugError();
void debugContextError();
}; };
ContextTest::ContextTest() { ContextTest::ContextTest() {
addTests({&ContextTest::debugHrtfStatus}); addTests({&ContextTest::debugHrtfStatus,
&ContextTest::debugError,
&ContextTest::debugContextError});
} }
void ContextTest::debugHrtfStatus() { void ContextTest::debugHrtfStatus() {
@ -47,6 +51,18 @@ void ContextTest::debugHrtfStatus() {
CORRADE_COMPARE(out.str(), "Audio::Context::HrtfStatus::Denied Audio::Context::HrtfStatus(0xdead)\n"); CORRADE_COMPARE(out.str(), "Audio::Context::HrtfStatus::Denied Audio::Context::HrtfStatus(0xdead)\n");
} }
void ContextTest::debugError() {
std::ostringstream out;
Debug(&out) << Error::None << Error(0xdead);
CORRADE_COMPARE(out.str(), "Audio::Error::None Audio::Error(0xdead)\n");
}
void ContextTest::debugContextError() {
std::ostringstream out;
Debug(&out) << Context::Error::None << Context::Error(0xdead);
CORRADE_COMPARE(out.str(), "Audio::Context::Error::None Audio::Context::Error(0xdead)\n");
}
}}} }}}
CORRADE_TEST_MAIN(Magnum::Audio::Test::ContextTest) CORRADE_TEST_MAIN(Magnum::Audio::Test::ContextTest)

Loading…
Cancel
Save