123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893 |
- /**
- * OpenAL cross platform audio library
- * Copyright (C) 1999-2000 by authors.
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- * Or go to http://www.gnu.org/copyleft/lgpl.html
- */
- #include "config.h"
- #include "version.h"
- #include <atomic>
- #include <cmath>
- #include <cstdlib>
- #include <cstring>
- #include <mutex>
- #include "AL/al.h"
- #include "AL/alc.h"
- #include "AL/alext.h"
- #include "alcontext.h"
- #include "almalloc.h"
- #include "alnumeric.h"
- #include "alspan.h"
- #include "alu.h"
- #include "atomic.h"
- #include "core/except.h"
- #include "event.h"
- #include "inprogext.h"
- #include "opthelpers.h"
- #include "strutils.h"
- #include "voice.h"
- namespace {
- constexpr ALchar alVendor[] = "OpenAL Community";
- constexpr ALchar alVersion[] = "1.1 ALSOFT " ALSOFT_VERSION;
- constexpr ALchar alRenderer[] = "OpenAL Soft";
- // Error Messages
- constexpr ALchar alNoError[] = "No Error";
- constexpr ALchar alErrInvalidName[] = "Invalid Name";
- constexpr ALchar alErrInvalidEnum[] = "Invalid Enum";
- constexpr ALchar alErrInvalidValue[] = "Invalid Value";
- constexpr ALchar alErrInvalidOp[] = "Invalid Operation";
- constexpr ALchar alErrOutOfMemory[] = "Out of Memory";
- /* Resampler strings */
- template<Resampler rtype> struct ResamplerName { };
- template<> struct ResamplerName<Resampler::Point>
- { static constexpr const ALchar *Get() noexcept { return "Nearest"; } };
- template<> struct ResamplerName<Resampler::Linear>
- { static constexpr const ALchar *Get() noexcept { return "Linear"; } };
- template<> struct ResamplerName<Resampler::Cubic>
- { static constexpr const ALchar *Get() noexcept { return "Cubic"; } };
- template<> struct ResamplerName<Resampler::FastBSinc12>
- { static constexpr const ALchar *Get() noexcept { return "11th order Sinc (fast)"; } };
- template<> struct ResamplerName<Resampler::BSinc12>
- { static constexpr const ALchar *Get() noexcept { return "11th order Sinc"; } };
- template<> struct ResamplerName<Resampler::FastBSinc24>
- { static constexpr const ALchar *Get() noexcept { return "23rd order Sinc (fast)"; } };
- template<> struct ResamplerName<Resampler::BSinc24>
- { static constexpr const ALchar *Get() noexcept { return "23rd order Sinc"; } };
- const ALchar *GetResamplerName(const Resampler rtype)
- {
- #define HANDLE_RESAMPLER(r) case r: return ResamplerName<r>::Get()
- switch(rtype)
- {
- HANDLE_RESAMPLER(Resampler::Point);
- HANDLE_RESAMPLER(Resampler::Linear);
- HANDLE_RESAMPLER(Resampler::Cubic);
- HANDLE_RESAMPLER(Resampler::FastBSinc12);
- HANDLE_RESAMPLER(Resampler::BSinc12);
- HANDLE_RESAMPLER(Resampler::FastBSinc24);
- HANDLE_RESAMPLER(Resampler::BSinc24);
- }
- #undef HANDLE_RESAMPLER
- /* Should never get here. */
- throw std::runtime_error{"Unexpected resampler index"};
- }
- al::optional<DistanceModel> DistanceModelFromALenum(ALenum model)
- {
- switch(model)
- {
- case AL_NONE: return al::make_optional(DistanceModel::Disable);
- case AL_INVERSE_DISTANCE: return al::make_optional(DistanceModel::Inverse);
- case AL_INVERSE_DISTANCE_CLAMPED: return al::make_optional(DistanceModel::InverseClamped);
- case AL_LINEAR_DISTANCE: return al::make_optional(DistanceModel::Linear);
- case AL_LINEAR_DISTANCE_CLAMPED: return al::make_optional(DistanceModel::LinearClamped);
- case AL_EXPONENT_DISTANCE: return al::make_optional(DistanceModel::Exponent);
- case AL_EXPONENT_DISTANCE_CLAMPED: return al::make_optional(DistanceModel::ExponentClamped);
- }
- return al::nullopt;
- }
- ALenum ALenumFromDistanceModel(DistanceModel model)
- {
- switch(model)
- {
- case DistanceModel::Disable: return AL_NONE;
- case DistanceModel::Inverse: return AL_INVERSE_DISTANCE;
- case DistanceModel::InverseClamped: return AL_INVERSE_DISTANCE_CLAMPED;
- case DistanceModel::Linear: return AL_LINEAR_DISTANCE;
- case DistanceModel::LinearClamped: return AL_LINEAR_DISTANCE_CLAMPED;
- case DistanceModel::Exponent: return AL_EXPONENT_DISTANCE;
- case DistanceModel::ExponentClamped: return AL_EXPONENT_DISTANCE_CLAMPED;
- }
- throw std::runtime_error{"Unexpected distance model "+std::to_string(static_cast<int>(model))};
- }
- } // namespace
- /* WARNING: Non-standard export! Not part of any extension, or exposed in the
- * alcFunctions list.
- */
- extern "C" AL_API const ALchar* AL_APIENTRY alsoft_get_version(void)
- START_API_FUNC
- {
- static const auto spoof = al::getenv("ALSOFT_SPOOF_VERSION");
- if(spoof) return spoof->c_str();
- return ALSOFT_VERSION;
- }
- END_API_FUNC
- #define DO_UPDATEPROPS() do { \
- if(!context->mDeferUpdates.load(std::memory_order_acquire)) \
- UpdateContextProps(context.get()); \
- else \
- context->mPropsClean.clear(std::memory_order_release); \
- } while(0)
- AL_API void AL_APIENTRY alEnable(ALenum capability)
- START_API_FUNC
- {
- ContextRef context{GetContextRef()};
- if UNLIKELY(!context) return;
- std::lock_guard<std::mutex> _{context->mPropLock};
- switch(capability)
- {
- case AL_SOURCE_DISTANCE_MODEL:
- context->mSourceDistanceModel = true;
- DO_UPDATEPROPS();
- break;
- default:
- context->setError(AL_INVALID_VALUE, "Invalid enable property 0x%04x", capability);
- }
- }
- END_API_FUNC
- AL_API void AL_APIENTRY alDisable(ALenum capability)
- START_API_FUNC
- {
- ContextRef context{GetContextRef()};
- if UNLIKELY(!context) return;
- std::lock_guard<std::mutex> _{context->mPropLock};
- switch(capability)
- {
- case AL_SOURCE_DISTANCE_MODEL:
- context->mSourceDistanceModel = false;
- DO_UPDATEPROPS();
- break;
- default:
- context->setError(AL_INVALID_VALUE, "Invalid disable property 0x%04x", capability);
- }
- }
- END_API_FUNC
- AL_API ALboolean AL_APIENTRY alIsEnabled(ALenum capability)
- START_API_FUNC
- {
- ContextRef context{GetContextRef()};
- if UNLIKELY(!context) return AL_FALSE;
- std::lock_guard<std::mutex> _{context->mPropLock};
- ALboolean value{AL_FALSE};
- switch(capability)
- {
- case AL_SOURCE_DISTANCE_MODEL:
- value = context->mSourceDistanceModel ? AL_TRUE : AL_FALSE;
- break;
- default:
- context->setError(AL_INVALID_VALUE, "Invalid is enabled property 0x%04x", capability);
- }
- return value;
- }
- END_API_FUNC
- AL_API ALboolean AL_APIENTRY alGetBoolean(ALenum pname)
- START_API_FUNC
- {
- ContextRef context{GetContextRef()};
- if UNLIKELY(!context) return AL_FALSE;
- std::lock_guard<std::mutex> _{context->mPropLock};
- ALboolean value{AL_FALSE};
- switch(pname)
- {
- case AL_DOPPLER_FACTOR:
- if(context->mDopplerFactor != 0.0f)
- value = AL_TRUE;
- break;
- case AL_DOPPLER_VELOCITY:
- if(context->mDopplerVelocity != 0.0f)
- value = AL_TRUE;
- break;
- case AL_DISTANCE_MODEL:
- if(context->mDistanceModel == DistanceModel::Default)
- value = AL_TRUE;
- break;
- case AL_SPEED_OF_SOUND:
- if(context->mSpeedOfSound != 0.0f)
- value = AL_TRUE;
- break;
- case AL_DEFERRED_UPDATES_SOFT:
- if(context->mDeferUpdates.load(std::memory_order_acquire))
- value = AL_TRUE;
- break;
- case AL_GAIN_LIMIT_SOFT:
- if(GainMixMax/context->mGainBoost != 0.0f)
- value = AL_TRUE;
- break;
- case AL_NUM_RESAMPLERS_SOFT:
- /* Always non-0. */
- value = AL_TRUE;
- break;
- case AL_DEFAULT_RESAMPLER_SOFT:
- value = static_cast<int>(ResamplerDefault) ? AL_TRUE : AL_FALSE;
- break;
- default:
- context->setError(AL_INVALID_VALUE, "Invalid boolean property 0x%04x", pname);
- }
- return value;
- }
- END_API_FUNC
- AL_API ALdouble AL_APIENTRY alGetDouble(ALenum pname)
- START_API_FUNC
- {
- ContextRef context{GetContextRef()};
- if UNLIKELY(!context) return 0.0;
- std::lock_guard<std::mutex> _{context->mPropLock};
- ALdouble value{0.0};
- switch(pname)
- {
- case AL_DOPPLER_FACTOR:
- value = context->mDopplerFactor;
- break;
- case AL_DOPPLER_VELOCITY:
- value = context->mDopplerVelocity;
- break;
- case AL_DISTANCE_MODEL:
- value = static_cast<ALdouble>(ALenumFromDistanceModel(context->mDistanceModel));
- break;
- case AL_SPEED_OF_SOUND:
- value = context->mSpeedOfSound;
- break;
- case AL_DEFERRED_UPDATES_SOFT:
- if(context->mDeferUpdates.load(std::memory_order_acquire))
- value = static_cast<ALdouble>(AL_TRUE);
- break;
- case AL_GAIN_LIMIT_SOFT:
- value = ALdouble{GainMixMax}/context->mGainBoost;
- break;
- case AL_NUM_RESAMPLERS_SOFT:
- value = static_cast<ALdouble>(Resampler::Max) + 1.0;
- break;
- case AL_DEFAULT_RESAMPLER_SOFT:
- value = static_cast<ALdouble>(ResamplerDefault);
- break;
- default:
- context->setError(AL_INVALID_VALUE, "Invalid double property 0x%04x", pname);
- }
- return value;
- }
- END_API_FUNC
- AL_API ALfloat AL_APIENTRY alGetFloat(ALenum pname)
- START_API_FUNC
- {
- ContextRef context{GetContextRef()};
- if UNLIKELY(!context) return 0.0f;
- std::lock_guard<std::mutex> _{context->mPropLock};
- ALfloat value{0.0f};
- switch(pname)
- {
- case AL_DOPPLER_FACTOR:
- value = context->mDopplerFactor;
- break;
- case AL_DOPPLER_VELOCITY:
- value = context->mDopplerVelocity;
- break;
- case AL_DISTANCE_MODEL:
- value = static_cast<ALfloat>(ALenumFromDistanceModel(context->mDistanceModel));
- break;
- case AL_SPEED_OF_SOUND:
- value = context->mSpeedOfSound;
- break;
- case AL_DEFERRED_UPDATES_SOFT:
- if(context->mDeferUpdates.load(std::memory_order_acquire))
- value = static_cast<ALfloat>(AL_TRUE);
- break;
- case AL_GAIN_LIMIT_SOFT:
- value = GainMixMax/context->mGainBoost;
- break;
- case AL_NUM_RESAMPLERS_SOFT:
- value = static_cast<ALfloat>(Resampler::Max) + 1.0f;
- break;
- case AL_DEFAULT_RESAMPLER_SOFT:
- value = static_cast<ALfloat>(ResamplerDefault);
- break;
- default:
- context->setError(AL_INVALID_VALUE, "Invalid float property 0x%04x", pname);
- }
- return value;
- }
- END_API_FUNC
- AL_API ALint AL_APIENTRY alGetInteger(ALenum pname)
- START_API_FUNC
- {
- ContextRef context{GetContextRef()};
- if UNLIKELY(!context) return 0;
- std::lock_guard<std::mutex> _{context->mPropLock};
- ALint value{0};
- switch(pname)
- {
- case AL_DOPPLER_FACTOR:
- value = static_cast<ALint>(context->mDopplerFactor);
- break;
- case AL_DOPPLER_VELOCITY:
- value = static_cast<ALint>(context->mDopplerVelocity);
- break;
- case AL_DISTANCE_MODEL:
- value = ALenumFromDistanceModel(context->mDistanceModel);
- break;
- case AL_SPEED_OF_SOUND:
- value = static_cast<ALint>(context->mSpeedOfSound);
- break;
- case AL_DEFERRED_UPDATES_SOFT:
- if(context->mDeferUpdates.load(std::memory_order_acquire))
- value = AL_TRUE;
- break;
- case AL_GAIN_LIMIT_SOFT:
- value = static_cast<ALint>(GainMixMax/context->mGainBoost);
- break;
- case AL_NUM_RESAMPLERS_SOFT:
- value = static_cast<int>(Resampler::Max) + 1;
- break;
- case AL_DEFAULT_RESAMPLER_SOFT:
- value = static_cast<int>(ResamplerDefault);
- break;
- default:
- context->setError(AL_INVALID_VALUE, "Invalid integer property 0x%04x", pname);
- }
- return value;
- }
- END_API_FUNC
- extern "C" AL_API ALint64SOFT AL_APIENTRY alGetInteger64SOFT(ALenum pname)
- START_API_FUNC
- {
- ContextRef context{GetContextRef()};
- if UNLIKELY(!context) return 0_i64;
- std::lock_guard<std::mutex> _{context->mPropLock};
- ALint64SOFT value{0};
- switch(pname)
- {
- case AL_DOPPLER_FACTOR:
- value = static_cast<ALint64SOFT>(context->mDopplerFactor);
- break;
- case AL_DOPPLER_VELOCITY:
- value = static_cast<ALint64SOFT>(context->mDopplerVelocity);
- break;
- case AL_DISTANCE_MODEL:
- value = ALenumFromDistanceModel(context->mDistanceModel);
- break;
- case AL_SPEED_OF_SOUND:
- value = static_cast<ALint64SOFT>(context->mSpeedOfSound);
- break;
- case AL_DEFERRED_UPDATES_SOFT:
- if(context->mDeferUpdates.load(std::memory_order_acquire))
- value = AL_TRUE;
- break;
- case AL_GAIN_LIMIT_SOFT:
- value = static_cast<ALint64SOFT>(GainMixMax/context->mGainBoost);
- break;
- case AL_NUM_RESAMPLERS_SOFT:
- value = static_cast<ALint64SOFT>(Resampler::Max) + 1;
- break;
- case AL_DEFAULT_RESAMPLER_SOFT:
- value = static_cast<ALint64SOFT>(ResamplerDefault);
- break;
- default:
- context->setError(AL_INVALID_VALUE, "Invalid integer64 property 0x%04x", pname);
- }
- return value;
- }
- END_API_FUNC
- AL_API ALvoid* AL_APIENTRY alGetPointerSOFT(ALenum pname)
- START_API_FUNC
- {
- ContextRef context{GetContextRef()};
- if UNLIKELY(!context) return nullptr;
- std::lock_guard<std::mutex> _{context->mPropLock};
- void *value{nullptr};
- switch(pname)
- {
- case AL_EVENT_CALLBACK_FUNCTION_SOFT:
- value = reinterpret_cast<void*>(context->mEventCb);
- break;
- case AL_EVENT_CALLBACK_USER_PARAM_SOFT:
- value = context->mEventParam;
- break;
- default:
- context->setError(AL_INVALID_VALUE, "Invalid pointer property 0x%04x", pname);
- }
- return value;
- }
- END_API_FUNC
- AL_API void AL_APIENTRY alGetBooleanv(ALenum pname, ALboolean *values)
- START_API_FUNC
- {
- if(values)
- {
- switch(pname)
- {
- case AL_DOPPLER_FACTOR:
- case AL_DOPPLER_VELOCITY:
- case AL_DISTANCE_MODEL:
- case AL_SPEED_OF_SOUND:
- case AL_DEFERRED_UPDATES_SOFT:
- case AL_GAIN_LIMIT_SOFT:
- case AL_NUM_RESAMPLERS_SOFT:
- case AL_DEFAULT_RESAMPLER_SOFT:
- values[0] = alGetBoolean(pname);
- return;
- }
- }
- ContextRef context{GetContextRef()};
- if UNLIKELY(!context) return;
- if(!values)
- context->setError(AL_INVALID_VALUE, "NULL pointer");
- else switch(pname)
- {
- default:
- context->setError(AL_INVALID_VALUE, "Invalid boolean-vector property 0x%04x", pname);
- }
- }
- END_API_FUNC
- AL_API void AL_APIENTRY alGetDoublev(ALenum pname, ALdouble *values)
- START_API_FUNC
- {
- if(values)
- {
- switch(pname)
- {
- case AL_DOPPLER_FACTOR:
- case AL_DOPPLER_VELOCITY:
- case AL_DISTANCE_MODEL:
- case AL_SPEED_OF_SOUND:
- case AL_DEFERRED_UPDATES_SOFT:
- case AL_GAIN_LIMIT_SOFT:
- case AL_NUM_RESAMPLERS_SOFT:
- case AL_DEFAULT_RESAMPLER_SOFT:
- values[0] = alGetDouble(pname);
- return;
- }
- }
- ContextRef context{GetContextRef()};
- if UNLIKELY(!context) return;
- if(!values)
- context->setError(AL_INVALID_VALUE, "NULL pointer");
- else switch(pname)
- {
- default:
- context->setError(AL_INVALID_VALUE, "Invalid double-vector property 0x%04x", pname);
- }
- }
- END_API_FUNC
- AL_API void AL_APIENTRY alGetFloatv(ALenum pname, ALfloat *values)
- START_API_FUNC
- {
- if(values)
- {
- switch(pname)
- {
- case AL_DOPPLER_FACTOR:
- case AL_DOPPLER_VELOCITY:
- case AL_DISTANCE_MODEL:
- case AL_SPEED_OF_SOUND:
- case AL_DEFERRED_UPDATES_SOFT:
- case AL_GAIN_LIMIT_SOFT:
- case AL_NUM_RESAMPLERS_SOFT:
- case AL_DEFAULT_RESAMPLER_SOFT:
- values[0] = alGetFloat(pname);
- return;
- }
- }
- ContextRef context{GetContextRef()};
- if UNLIKELY(!context) return;
- if(!values)
- context->setError(AL_INVALID_VALUE, "NULL pointer");
- else switch(pname)
- {
- default:
- context->setError(AL_INVALID_VALUE, "Invalid float-vector property 0x%04x", pname);
- }
- }
- END_API_FUNC
- AL_API void AL_APIENTRY alGetIntegerv(ALenum pname, ALint *values)
- START_API_FUNC
- {
- if(values)
- {
- switch(pname)
- {
- case AL_DOPPLER_FACTOR:
- case AL_DOPPLER_VELOCITY:
- case AL_DISTANCE_MODEL:
- case AL_SPEED_OF_SOUND:
- case AL_DEFERRED_UPDATES_SOFT:
- case AL_GAIN_LIMIT_SOFT:
- case AL_NUM_RESAMPLERS_SOFT:
- case AL_DEFAULT_RESAMPLER_SOFT:
- values[0] = alGetInteger(pname);
- return;
- }
- }
- ContextRef context{GetContextRef()};
- if UNLIKELY(!context) return;
- if(!values)
- context->setError(AL_INVALID_VALUE, "NULL pointer");
- else switch(pname)
- {
- default:
- context->setError(AL_INVALID_VALUE, "Invalid integer-vector property 0x%04x", pname);
- }
- }
- END_API_FUNC
- extern "C" AL_API void AL_APIENTRY alGetInteger64vSOFT(ALenum pname, ALint64SOFT *values)
- START_API_FUNC
- {
- if(values)
- {
- switch(pname)
- {
- case AL_DOPPLER_FACTOR:
- case AL_DOPPLER_VELOCITY:
- case AL_DISTANCE_MODEL:
- case AL_SPEED_OF_SOUND:
- case AL_DEFERRED_UPDATES_SOFT:
- case AL_GAIN_LIMIT_SOFT:
- case AL_NUM_RESAMPLERS_SOFT:
- case AL_DEFAULT_RESAMPLER_SOFT:
- values[0] = alGetInteger64SOFT(pname);
- return;
- }
- }
- ContextRef context{GetContextRef()};
- if UNLIKELY(!context) return;
- if(!values)
- context->setError(AL_INVALID_VALUE, "NULL pointer");
- else switch(pname)
- {
- default:
- context->setError(AL_INVALID_VALUE, "Invalid integer64-vector property 0x%04x", pname);
- }
- }
- END_API_FUNC
- AL_API void AL_APIENTRY alGetPointervSOFT(ALenum pname, ALvoid **values)
- START_API_FUNC
- {
- if(values)
- {
- switch(pname)
- {
- case AL_EVENT_CALLBACK_FUNCTION_SOFT:
- case AL_EVENT_CALLBACK_USER_PARAM_SOFT:
- values[0] = alGetPointerSOFT(pname);
- return;
- }
- }
- ContextRef context{GetContextRef()};
- if UNLIKELY(!context) return;
- if(!values)
- context->setError(AL_INVALID_VALUE, "NULL pointer");
- else switch(pname)
- {
- default:
- context->setError(AL_INVALID_VALUE, "Invalid pointer-vector property 0x%04x", pname);
- }
- }
- END_API_FUNC
- AL_API const ALchar* AL_APIENTRY alGetString(ALenum pname)
- START_API_FUNC
- {
- ContextRef context{GetContextRef()};
- if UNLIKELY(!context) return nullptr;
- const ALchar *value{nullptr};
- switch(pname)
- {
- case AL_VENDOR:
- value = alVendor;
- break;
- case AL_VERSION:
- value = alVersion;
- break;
- case AL_RENDERER:
- value = alRenderer;
- break;
- case AL_EXTENSIONS:
- value = context->mExtensionList;
- break;
- case AL_NO_ERROR:
- value = alNoError;
- break;
- case AL_INVALID_NAME:
- value = alErrInvalidName;
- break;
- case AL_INVALID_ENUM:
- value = alErrInvalidEnum;
- break;
- case AL_INVALID_VALUE:
- value = alErrInvalidValue;
- break;
- case AL_INVALID_OPERATION:
- value = alErrInvalidOp;
- break;
- case AL_OUT_OF_MEMORY:
- value = alErrOutOfMemory;
- break;
- default:
- context->setError(AL_INVALID_VALUE, "Invalid string property 0x%04x", pname);
- }
- return value;
- }
- END_API_FUNC
- AL_API void AL_APIENTRY alDopplerFactor(ALfloat value)
- START_API_FUNC
- {
- ContextRef context{GetContextRef()};
- if UNLIKELY(!context) return;
- if(!(value >= 0.0f && std::isfinite(value)))
- context->setError(AL_INVALID_VALUE, "Doppler factor %f out of range", value);
- else
- {
- std::lock_guard<std::mutex> _{context->mPropLock};
- context->mDopplerFactor = value;
- DO_UPDATEPROPS();
- }
- }
- END_API_FUNC
- AL_API void AL_APIENTRY alDopplerVelocity(ALfloat value)
- START_API_FUNC
- {
- ContextRef context{GetContextRef()};
- if UNLIKELY(!context) return;
- if(!(value >= 0.0f && std::isfinite(value)))
- context->setError(AL_INVALID_VALUE, "Doppler velocity %f out of range", value);
- else
- {
- std::lock_guard<std::mutex> _{context->mPropLock};
- context->mDopplerVelocity = value;
- DO_UPDATEPROPS();
- }
- }
- END_API_FUNC
- AL_API void AL_APIENTRY alSpeedOfSound(ALfloat value)
- START_API_FUNC
- {
- ContextRef context{GetContextRef()};
- if UNLIKELY(!context) return;
- if(!(value > 0.0f && std::isfinite(value)))
- context->setError(AL_INVALID_VALUE, "Speed of sound %f out of range", value);
- else
- {
- std::lock_guard<std::mutex> _{context->mPropLock};
- context->mSpeedOfSound = value;
- DO_UPDATEPROPS();
- }
- }
- END_API_FUNC
- AL_API void AL_APIENTRY alDistanceModel(ALenum value)
- START_API_FUNC
- {
- ContextRef context{GetContextRef()};
- if UNLIKELY(!context) return;
- if(auto model = DistanceModelFromALenum(value))
- {
- std::lock_guard<std::mutex> _{context->mPropLock};
- context->mDistanceModel = *model;
- if(!context->mSourceDistanceModel)
- DO_UPDATEPROPS();
- }
- else
- context->setError(AL_INVALID_VALUE, "Distance model 0x%04x out of range", value);
- }
- END_API_FUNC
- AL_API void AL_APIENTRY alDeferUpdatesSOFT(void)
- START_API_FUNC
- {
- ContextRef context{GetContextRef()};
- if UNLIKELY(!context) return;
- context->deferUpdates();
- }
- END_API_FUNC
- AL_API void AL_APIENTRY alProcessUpdatesSOFT(void)
- START_API_FUNC
- {
- ContextRef context{GetContextRef()};
- if UNLIKELY(!context) return;
- context->processUpdates();
- }
- END_API_FUNC
- AL_API const ALchar* AL_APIENTRY alGetStringiSOFT(ALenum pname, ALsizei index)
- START_API_FUNC
- {
- ContextRef context{GetContextRef()};
- if UNLIKELY(!context) return nullptr;
- const ALchar *value{nullptr};
- switch(pname)
- {
- case AL_RESAMPLER_NAME_SOFT:
- if(index < 0 || index > static_cast<ALint>(Resampler::Max))
- context->setError(AL_INVALID_VALUE, "Resampler name index %d out of range", index);
- else
- value = GetResamplerName(static_cast<Resampler>(index));
- break;
- default:
- context->setError(AL_INVALID_VALUE, "Invalid string indexed property");
- }
- return value;
- }
- END_API_FUNC
- void UpdateContextProps(ALCcontext *context)
- {
- /* Get an unused proprty container, or allocate a new one as needed. */
- ContextProps *props{context->mFreeContextProps.load(std::memory_order_acquire)};
- if(!props)
- props = new ContextProps{};
- else
- {
- ContextProps *next;
- do {
- next = props->next.load(std::memory_order_relaxed);
- } while(context->mFreeContextProps.compare_exchange_weak(props, next,
- std::memory_order_seq_cst, std::memory_order_acquire) == 0);
- }
- /* Copy in current property values. */
- props->DopplerFactor = context->mDopplerFactor;
- props->DopplerVelocity = context->mDopplerVelocity;
- props->SpeedOfSound = context->mSpeedOfSound;
- props->SourceDistanceModel = context->mSourceDistanceModel;
- props->mDistanceModel = context->mDistanceModel;
- /* Set the new container for updating internal parameters. */
- props = context->mParams.ContextUpdate.exchange(props, std::memory_order_acq_rel);
- if(props)
- {
- /* If there was an unused update container, put it back in the
- * freelist.
- */
- AtomicReplaceHead(context->mFreeContextProps, props);
- }
- }
|