Browse Source

Audio: Fix hrtfStatus() and isHrtfEnabled() and move them to Context.

Since `ALC_HRTF_SOFT` is a ALC extension, we need to use `alcGetIntegerv()`
instead of `alGetIntegerv()` which requires access to the OpenAL device
stored in `Audio::Context` and therefore the aforementioned methods have
been moved there.

Signed-off-by: Squareys <Squareys@googlemail.com>
pull/121/head
Squareys 11 years ago
parent
commit
9d53f7cb2b
  1. 15
      src/Magnum/Audio/Context.cpp
  2. 85
      src/Magnum/Audio/Context.h
  3. 15
      src/Magnum/Audio/Renderer.cpp
  4. 81
      src/Magnum/Audio/Renderer.h
  5. 18
      src/Magnum/Audio/Test/ContextTest.cpp
  6. 18
      src/Magnum/Audio/Test/RendererTest.cpp

15
src/Magnum/Audio/Context.cpp

@ -53,6 +53,21 @@ const std::vector<Extension>& Extension::extensions() {
return extensions;
}
Debug& operator<<(Debug& debug, const Context::HrtfStatus value) {
switch(value) {
#define _c(value) case Context::HrtfStatus::value: return debug << "Audio::Context::HrtfStatus::" #value;
_c(Disabled)
_c(Enabled)
_c(Denied)
_c(Required)
_c(Detected)
_c(UnsupportedFormat)
#undef _c
}
return debug << "Audio::Context::HrtfStatus::(invalid)";
}
Context* Context::_current = nullptr;
Context::Context(): Context{Configuration{}} {}

85
src/Magnum/Audio/Context.h

@ -40,6 +40,7 @@
#include "Magnum/Audio/Audio.h"
#include "Magnum/Audio/Buffer.h"
#include "Magnum/Audio/Extensions.h"
#include "Magnum/Audio/visibility.h"
#ifndef DOXYGEN_GENERATING_OUTPUT
@ -82,6 +83,50 @@ class MAGNUM_AUDIO_EXPORT Extension {
*/
class MAGNUM_AUDIO_EXPORT Context {
public:
/**
* @brief HRTF status
*
* @see @ref hrtfStatus(), @ref isHrtfEnabled()
* @requires_al_extension Extension @alc_extension{SOFTX,HRTF} or
* @alc_extension{SOFT,HRTF}
*/
enum class HrtfStatus: ALenum {
Disabled = ALC_HRTF_DISABLED_SOFT, /**< HRTF is disabled */
Enabled = ALC_HRTF_ENABLED_SOFT, /**< HRTF is enabled */
/**
* HRTF is disabled because it is not allowed on the device. This
* may be caused by invalid resource permissions, or an other user
* configuration that disallows HRTF.
* @requires_al_extension Extension @alc_extension{SOFT,HRTF}
*/
Denied = ALC_HRTF_DENIED_SOFT,
/**
* HRTF is enabled because it must be used on the device. This may
* be caused by a device that can only use HRTF, or other user
* configuration that forces HRTF to be used.
* @requires_al_extension Extension @alc_extension{SOFT,HRTF}
*/
Required = ALC_HRTF_REQUIRED_SOFT,
/**
* HRTF is enabled automatically because the device reported
* headphones.
* @requires_al_extension Extension @alc_extension{SOFT,HRTF}
*/
Detected = ALC_HRTF_HEADPHONES_DETECTED_SOFT,
/**
* The device does not support HRTF with the current format.
* Typically this is caused by non-stereo output or an incompatible
* output frequency.
* @requires_al_extension Extension @alc_extension{SOFT,HRTF}
*/
UnsupportedFormat = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT
};
/** @brief Current context */
static Context* current() { return _current; }
@ -106,6 +151,28 @@ class MAGNUM_AUDIO_EXPORT Context {
*/
~Context();
/**
* @brief Whether HRTFs (Head Related Transfer Functions) are enabled
*
* HRFTs may not be enabled/disabled in a running context. Instead
* create a new @ref Context with HRFTs enabled or disabled.
* @see @ref hrtfStatus(), @ref Audio::Context::Configuration::setHrtf(),
* @fn_alc{GetIntegerv} with @def_alc{HRTF_SOFT}
* @requires_al_extension Extension @alc_extension{SOFTX,HRTF} or
* @alc_extension{SOFT,HRTF}
*/
bool isHrtfEnabled() const;
/**
* @brief HRTF status
*
* @see @ref isHrtfEnabled(), @fn_alc{GetIntegerv} with
* @def_alc{HRTF_STATUS_SOFT}
* @requires_al_extension Extension @alc_extension{SOFTX,HRTF} or
* @alc_extension{SOFT,HRTF}
*/
HrtfStatus hrtfStatus() const;
/**
* @brief Vendor string
*
@ -340,6 +407,24 @@ MAGNUM_ASSERT_AUDIO_EXTENSION_SUPPORTED(Extensions::ALC::SOFTX::HRTF);
} while(0)
#endif
/** @debugoperatorclassenum{Magnum::Audio::Context,Magnum::Audio::Context::HrtfStatus} */
MAGNUM_AUDIO_EXPORT Debug& operator<<(Debug& debug, Context::HrtfStatus value);
inline bool Context::isHrtfEnabled() const {
Int enabled;
alcGetIntegerv(_device, ALC_HRTF_SOFT, 1, &enabled);
return enabled == ALC_TRUE;
}
inline Context::HrtfStatus Context::hrtfStatus() const {
if(!Context::current()->isExtensionSupported<Extensions::ALC::SOFT::HRTF>())
return isHrtfEnabled() ? HrtfStatus::Enabled : HrtfStatus::Disabled;
Int status;
alcGetIntegerv(_device, ALC_HRTF_STATUS_SOFT, 1, &status);
return Context::HrtfStatus(status);
}
}}
#endif

15
src/Magnum/Audio/Renderer.cpp

@ -60,19 +60,4 @@ Debug& operator<<(Debug& debug, const Renderer::DistanceModel value) {
return debug << "Audio::Renderer::DistanceModel::(invalid)";
}
Debug& operator<<(Debug& debug, const Renderer::HrtfStatus value) {
switch(value) {
#define _c(value) case Renderer::HrtfStatus::value: return debug << "Audio::Renderer::HrtfStatus::" #value;
_c(Disabled)
_c(Enabled)
_c(Denied)
_c(Required)
_c(Detected)
_c(UnsupportedFormat)
#undef _c
}
return debug << "Audio::Renderer::HrtfStatus::(invalid)";
}
}}

81
src/Magnum/Audio/Renderer.h

@ -32,11 +32,9 @@
#include <array>
#include <al.h>
#include <alc.h>
#include "Magnum/Magnum.h"
#include "Magnum/Audio/Context.h"
#include "Magnum/Audio/Extensions.h"
#include "Magnum/Audio/visibility.h"
#include "Magnum/Math/Vector3.h"
@ -61,85 +59,9 @@ class Renderer {
OutOfMemory = AL_OUT_OF_MEMORY /**< Unable to allocate memory */
};
/**
* @brief HRTF status
*
* @see @ref hrtfStatus(), @ref isHrtfEnabled()
* @requires_al_extension Extension @alc_extension{SOFTX,HRTF} or
* @alc_extension{SOFT,HRTF}
*/
enum class HrtfStatus: ALenum {
Disabled = ALC_HRTF_DISABLED_SOFT, /**< HRTF is disabled */
Enabled = ALC_HRTF_ENABLED_SOFT, /**< HRTF is enabled */
/**
* HRTF is disabled because it is not allowed on the device. This
* may be caused by invalid resource permissions, or an other user
* configuration that disallows HRTF.
* @requires_al_extension Extension @alc_extension{SOFT,HRTF}
*/
Denied = ALC_HRTF_DENIED_SOFT,
/**
* HRTF is enabled because it must be used on the device. This may
* be caused by a device that can only use HRTF, or other user
* configuration that forces HRTF to be used.
* @requires_al_extension Extension @alc_extension{SOFT,HRTF}
*/
Required = ALC_HRTF_REQUIRED_SOFT,
/**
* HRTF is enabled automatically because the device reported
* headphones.
* @requires_al_extension Extension @alc_extension{SOFT,HRTF}
*/
Detected = ALC_HRTF_HEADPHONES_DETECTED_SOFT,
/**
* The device does not support HRTF with the current format.
* Typically this is caused by non-stereo output or an incompatible
* output frequency.
* @requires_al_extension Extension @alc_extension{SOFT,HRTF}
*/
UnsupportedFormat = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT
};
/** @brief Error status */
static Error error() { return Error(alGetError()); }
/**
* @brief Whether HRTFs (Head Related Transfer Functions) are enabled
*
* HRFTs may not be enabled/disabled in a running context. Instead
* create a new @ref Context with HRFTs enabled or disabled.
* @see @ref hrtfStatus(), @ref Audio::Context::Configuration::setHrtf(),
* @fn_al{GetIntegerv} with @def_alc{HRTF_SOFT}
* @requires_al_extension Extension @alc_extension{SOFTX,HRTF} or
* @alc_extension{SOFT,HRTF}
*/
static bool isHrtfEnabled() {
Int enabled = ALC_FALSE;
alGetIntegerv(ALC_HRTF_SOFT, &enabled);
return enabled == ALC_TRUE;
}
/**
* @brief HRTF status
*
* @see @ref isHrtfEnabled(), @fn_al{GetIntegerv} with
* @def_alc{HRTF_STATUS_SOFT}
* @requires_al_extension Extension @alc_extension{SOFTX,HRTF} or
* @alc_extension{SOFT,HRTF}
*/
static HrtfStatus hrtfStatus() {
if(!Context::current()->isExtensionSupported<Extensions::ALC::SOFT::HRTF>())
return isHrtfEnabled() ? HrtfStatus::Enabled : HrtfStatus::Disabled;
Int status = ALC_HRTF_DISABLED_SOFT;
alGetIntegerv(ALC_HRTF_STATUS_SOFT, &status);
return HrtfStatus(status);
}
/** @{ @name Listener positioning */
/**
@ -344,9 +266,6 @@ MAGNUM_AUDIO_EXPORT Debug& operator<<(Debug& debug, Renderer::Error value);
/** @debugoperatorclassenum{Magnum::Audio::Renderer,Magnum::Audio::Renderer::DistanceModel} */
MAGNUM_AUDIO_EXPORT Debug& operator<<(Debug& debug, Renderer::DistanceModel value);
/** @debugoperatorclassenum{Magnum::Audio::Renderer,Magnum::Audio::Renderer::HrtfStatus} */
MAGNUM_AUDIO_EXPORT Debug& operator<<(Debug& debug, Renderer::HrtfStatus value);
}}
#endif

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

@ -37,13 +37,17 @@ struct ContextTest: TestSuite::Tester {
void extensionsString();
void isExtensionEnabled();
void hrtfStatus();
void hrtfs();
Context _context;
};
ContextTest::ContextTest() {
addTests({&ContextTest::extensionsString,
&ContextTest::isExtensionEnabled});
&ContextTest::isExtensionEnabled,
&ContextTest::hrtfStatus,
&ContextTest::hrtfs});
}
void ContextTest::extensionsString() {
@ -56,6 +60,18 @@ void ContextTest::isExtensionEnabled() {
CORRADE_VERIFY(Context::current()->isExtensionSupported<Extensions::ALC::EXT::ENUMERATION>());
}
void ContextTest::hrtfStatus() {
std::ostringstream out;
Debug(&out) << Context::HrtfStatus::Denied;
CORRADE_COMPARE(out.str(), "Audio::Context::HrtfStatus::Denied\n");
}
void ContextTest::hrtfs() {
/* At least test that the hrtf status is `Disabled` */
CORRADE_VERIFY(!_context.isHrtfEnabled());
CORRADE_COMPARE(_context.hrtfStatus(), Context::HrtfStatus::Disabled);
}
}}}
CORRADE_TEST_MAIN(Magnum::Audio::Test::ContextTest)

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

@ -37,7 +37,6 @@ struct RendererTest: TestSuite::Tester {
void debugError();
void debugDistanceModel();
void hrtfStatus();
void listenerOrientation();
void listenerPosition();
void listenerVelocity();
@ -45,7 +44,6 @@ struct RendererTest: TestSuite::Tester {
void speedOfSound();
void dopplerFactor();
void distanceModel();
void hrtfs();
Context _context;
};
@ -53,15 +51,13 @@ struct RendererTest: TestSuite::Tester {
RendererTest::RendererTest() {
addTests({&RendererTest::debugError,
&RendererTest::debugDistanceModel,
&RendererTest::hrtfStatus,
&RendererTest::listenerOrientation,
&RendererTest::listenerPosition,
&RendererTest::listenerVelocity,
&RendererTest::listenerGain,
&RendererTest::speedOfSound,
&RendererTest::dopplerFactor,
&RendererTest::distanceModel,
&RendererTest::hrtfs});
&RendererTest::distanceModel});
}
void RendererTest::debugError() {
@ -76,12 +72,6 @@ void RendererTest::debugDistanceModel() {
CORRADE_COMPARE(out.str(), "Audio::Renderer::DistanceModel::Inverse\n");
}
void RendererTest::hrtfStatus() {
std::ostringstream out;
Debug(&out) << Renderer::HrtfStatus::Denied;
CORRADE_COMPARE(out.str(), "Audio::Renderer::HrtfStatus::Denied\n");
}
void RendererTest::listenerOrientation() {
constexpr Vector3 up{1.0f, 2.0f, 3.0f}, fwd{3.0f, 2.0f, 1.0f};
Renderer::setListenerOrientation(fwd, up);
@ -133,12 +123,6 @@ void RendererTest::distanceModel() {
CORRADE_COMPARE(Renderer::distanceModel(), model);
}
void RendererTest::hrtfs() {
/* At least test that the hrtf status is `Disabled` */
CORRADE_VERIFY(!Renderer::isHrtfEnabled());
CORRADE_COMPARE(Renderer::hrtfStatus(), Renderer::HrtfStatus::Disabled);
}
}}}
CORRADE_TEST_MAIN(Magnum::Audio::Test::RendererTest)

Loading…
Cancel
Save