Audio: Add an option to directly link OpenAL
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
#include <Nazara/Audio/Config.hpp>
|
||||
#include <Nazara/Audio/DummyAudioDevice.hpp>
|
||||
#include <Nazara/Audio/Enums.hpp>
|
||||
#include <Nazara/Audio/OpenALLibrary.hpp>
|
||||
#include <Nazara/Audio/OpenALDevice.hpp>
|
||||
#include <Nazara/Audio/Formats/drwavLoader.hpp>
|
||||
#include <Nazara/Audio/Formats/libflacLoader.hpp>
|
||||
#include <Nazara/Audio/Formats/libvorbisLoader.hpp>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Audio/OpenALLibrary.hpp>
|
||||
#include <Nazara/Audio/OpenALDevice.hpp>
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
@@ -23,6 +24,16 @@ namespace Nz
|
||||
|
||||
CallOnExit unloadOnFailure([this] { Unload(); });
|
||||
|
||||
auto PostLoad = [&]
|
||||
{
|
||||
m_hasCaptureSupport = alcIsExtensionPresent(nullptr, "ALC_EXT_CAPTURE");
|
||||
m_isLoaded = true;
|
||||
|
||||
unloadOnFailure.Reset();
|
||||
};
|
||||
|
||||
#ifndef NAZARA_AUDIO_OPENAL_LINK
|
||||
// Dynamically load OpenAL
|
||||
#if defined(NAZARA_PLATFORM_WINDOWS)
|
||||
std::array libs{
|
||||
"soft_oal.dll",
|
||||
@@ -74,15 +85,32 @@ namespace Nz
|
||||
continue;
|
||||
}
|
||||
|
||||
m_hasCaptureSupport = alcIsExtensionPresent(nullptr, "ALC_EXT_CAPTURE");
|
||||
|
||||
unloadOnFailure.Reset();
|
||||
PostLoad();
|
||||
return true;
|
||||
}
|
||||
|
||||
NazaraError("failed to load OpenAL library");
|
||||
return false;
|
||||
}
|
||||
|
||||
#else
|
||||
// OpenAL is linked to the executable
|
||||
|
||||
// Load core
|
||||
#define NAZARA_AUDIO_AL_ALC_FUNCTION(name) name = &::name;
|
||||
#define NAZARA_AUDIO_AL_EXT_FUNCTION(name)
|
||||
#include <Nazara/Audio/OpenALFunctions.hpp>
|
||||
|
||||
// Load ext
|
||||
#define NAZARA_AUDIO_AL_ALC_FUNCTION(name)
|
||||
#define NAZARA_AUDIO_AL_EXT_BEGIN(ext) if (alIsExtensionPresent(#ext)) {
|
||||
#define NAZARA_AUDIO_AL_EXT_END() }
|
||||
#define NAZARA_AUDIO_AL_FUNCTION_EXT(name) name = reinterpret_cast<decltype(name)>(alGetProcAddress(#name));
|
||||
#include <Nazara/Audio/OpenALFunctions.hpp>
|
||||
|
||||
PostLoad();
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
std::vector<std::string> OpenALLibrary::QueryInputDevices()
|
||||
{
|
||||
@@ -111,10 +139,8 @@ namespace Nz
|
||||
if (!m_library.IsLoaded())
|
||||
return;
|
||||
|
||||
#define NAZARA_AUDIO_FUNC(name, sig) name = nullptr;
|
||||
NAZARA_AUDIO_FOREACH_AL_FUNC(NAZARA_AUDIO_FUNC, NAZARA_AUDIO_FUNC)
|
||||
NAZARA_AUDIO_FOREACH_ALC_FUNC(NAZARA_AUDIO_FUNC, NAZARA_AUDIO_FUNC)
|
||||
#undef NAZARA_AUDIO_FUNC
|
||||
#define NAZARA_AUDIO_AL_ALC_FUNCTION(name) name = nullptr;
|
||||
#include <Nazara/Audio/OpenALFunctions.hpp>
|
||||
|
||||
m_library.Unload();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <Nazara/Audio/OpenALSource.hpp>
|
||||
#include <Nazara/Audio/OpenALBuffer.hpp>
|
||||
#include <Nazara/Audio/OpenALDevice.hpp>
|
||||
#include <Nazara/Audio/OpenALLibrary.hpp>
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
@@ -84,6 +85,7 @@ namespace Nz
|
||||
auto OpenALSource::GetSampleOffsetAndLatency() const -> OffsetWithLatency
|
||||
{
|
||||
OffsetWithLatency offsetWithLatency;
|
||||
#ifdef AL_SOFT_source_latency
|
||||
if (GetDevice().IsExtensionSupported(OpenALExtension::SourceLatency))
|
||||
{
|
||||
GetDevice().MakeContextCurrent();
|
||||
@@ -96,6 +98,7 @@ namespace Nz
|
||||
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
offsetWithLatency.sampleOffset = GetSampleOffset() * 1'000;
|
||||
offsetWithLatency.sourceLatency = 0;
|
||||
|
||||
Reference in New Issue
Block a user