diff options
Diffstat (limited to 'al/filter.cpp')
-rw-r--r-- | al/filter.cpp | 528 |
1 files changed, 300 insertions, 228 deletions
diff --git a/al/filter.cpp b/al/filter.cpp index 33887254..73efa01f 100644 --- a/al/filter.cpp +++ b/al/filter.cpp @@ -23,7 +23,9 @@ #include "filter.h" #include <algorithm> +#include <cstdarg> #include <cstdint> +#include <cstdio> #include <iterator> #include <memory> #include <mutex> @@ -34,206 +36,253 @@ #include "AL/alc.h" #include "AL/efx.h" -#include "alcmain.h" -#include "alcontext.h" -#include "alexcpt.h" +#include "albit.h" +#include "alc/context.h" +#include "alc/device.h" #include "almalloc.h" #include "alnumeric.h" +#include "core/except.h" #include "opthelpers.h" #include "vector.h" namespace { -#define FILTER_MIN_GAIN 0.0f -#define FILTER_MAX_GAIN 4.0f /* +12dB */ +class filter_exception final : public al::base_exception { + ALenum mErrorCode; -void ALlowpass_setParami(ALfilter*, ALCcontext *context, ALenum param, ALint) -{ context->setError(AL_INVALID_ENUM, "Invalid low-pass integer property 0x%04x", param); } -void ALlowpass_setParamiv(ALfilter*, ALCcontext *context, ALenum param, const ALint*) -{ context->setError(AL_INVALID_ENUM, "Invalid low-pass integer-vector property 0x%04x", param); } -void ALlowpass_setParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat val) +public: +#ifdef __USE_MINGW_ANSI_STDIO + [[gnu::format(gnu_printf, 3, 4)]] +#else + [[gnu::format(printf, 3, 4)]] +#endif + filter_exception(ALenum code, const char *msg, ...); + ~filter_exception() override; + + ALenum errorCode() const noexcept { return mErrorCode; } +}; + +filter_exception::filter_exception(ALenum code, const char* msg, ...) : mErrorCode{code} { - switch(param) - { - case AL_LOWPASS_GAIN: - if(!(val >= FILTER_MIN_GAIN && val <= FILTER_MAX_GAIN)) - SETERR_RETURN(context, AL_INVALID_VALUE,, "Low-pass gain %f out of range", val); - filter->Gain = val; - break; + std::va_list args; + va_start(args, msg); + setMessage(msg, args); + va_end(args); +} +filter_exception::~filter_exception() = default; + - case AL_LOWPASS_GAINHF: - if(!(val >= AL_LOWPASS_MIN_GAINHF && val <= AL_LOWPASS_MAX_GAINHF)) - SETERR_RETURN(context, AL_INVALID_VALUE,, "Low-pass gainhf %f out of range", val); - filter->GainHF = val; - break; +#define DEFINE_ALFILTER_VTABLE(T) \ +const ALfilter::Vtable T##_vtable = { \ + T##_setParami, T##_setParamiv, T##_setParamf, T##_setParamfv, \ + T##_getParami, T##_getParamiv, T##_getParamf, T##_getParamfv, \ +} - default: - context->setError(AL_INVALID_ENUM, "Invalid low-pass float property 0x%04x", param); +void ALlowpass_setParami(ALfilter*, ALenum param, int) +{ throw filter_exception{AL_INVALID_ENUM, "Invalid low-pass integer property 0x%04x", param}; } +void ALlowpass_setParamiv(ALfilter*, ALenum param, const int*) +{ + throw filter_exception{AL_INVALID_ENUM, "Invalid low-pass integer-vector property 0x%04x", + param}; +} +void ALlowpass_setParamf(ALfilter *filter, ALenum param, float val) +{ + switch(param) + { + case AL_LOWPASS_GAIN: + if(!(val >= AL_LOWPASS_MIN_GAIN && val <= AL_LOWPASS_MAX_GAIN)) + throw filter_exception{AL_INVALID_VALUE, "Low-pass gain %f out of range", val}; + filter->Gain = val; + break; + + case AL_LOWPASS_GAINHF: + if(!(val >= AL_LOWPASS_MIN_GAINHF && val <= AL_LOWPASS_MAX_GAINHF)) + throw filter_exception{AL_INVALID_VALUE, "Low-pass gainhf %f out of range", val}; + filter->GainHF = val; + break; + + default: + throw filter_exception{AL_INVALID_ENUM, "Invalid low-pass float property 0x%04x", param}; } } -void ALlowpass_setParamfv(ALfilter *filter, ALCcontext *context, ALenum param, const ALfloat *vals) -{ ALlowpass_setParamf(filter, context, param, vals[0]); } - -void ALlowpass_getParami(ALfilter*, ALCcontext *context, ALenum param, ALint*) -{ context->setError(AL_INVALID_ENUM, "Invalid low-pass integer property 0x%04x", param); } -void ALlowpass_getParamiv(ALfilter*, ALCcontext *context, ALenum param, ALint*) -{ context->setError(AL_INVALID_ENUM, "Invalid low-pass integer-vector property 0x%04x", param); } -void ALlowpass_getParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *val) +void ALlowpass_setParamfv(ALfilter *filter, ALenum param, const float *vals) +{ ALlowpass_setParamf(filter, param, vals[0]); } + +void ALlowpass_getParami(const ALfilter*, ALenum param, int*) +{ throw filter_exception{AL_INVALID_ENUM, "Invalid low-pass integer property 0x%04x", param}; } +void ALlowpass_getParamiv(const ALfilter*, ALenum param, int*) +{ + throw filter_exception{AL_INVALID_ENUM, "Invalid low-pass integer-vector property 0x%04x", + param}; +} +void ALlowpass_getParamf(const ALfilter *filter, ALenum param, float *val) { switch(param) { - case AL_LOWPASS_GAIN: - *val = filter->Gain; - break; + case AL_LOWPASS_GAIN: + *val = filter->Gain; + break; - case AL_LOWPASS_GAINHF: - *val = filter->GainHF; - break; + case AL_LOWPASS_GAINHF: + *val = filter->GainHF; + break; - default: - context->setError(AL_INVALID_ENUM, "Invalid low-pass float property 0x%04x", param); + default: + throw filter_exception{AL_INVALID_ENUM, "Invalid low-pass float property 0x%04x", param}; } } -void ALlowpass_getParamfv(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *vals) -{ ALlowpass_getParamf(filter, context, param, vals); } +void ALlowpass_getParamfv(const ALfilter *filter, ALenum param, float *vals) +{ ALlowpass_getParamf(filter, param, vals); } DEFINE_ALFILTER_VTABLE(ALlowpass); -void ALhighpass_setParami(ALfilter*, ALCcontext *context, ALenum param, ALint) -{ context->setError(AL_INVALID_ENUM, "Invalid high-pass integer property 0x%04x", param); } -void ALhighpass_setParamiv(ALfilter*, ALCcontext *context, ALenum param, const ALint*) -{ context->setError(AL_INVALID_ENUM, "Invalid high-pass integer-vector property 0x%04x", param); } -void ALhighpass_setParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat val) +void ALhighpass_setParami(ALfilter*, ALenum param, int) +{ throw filter_exception{AL_INVALID_ENUM, "Invalid high-pass integer property 0x%04x", param}; } +void ALhighpass_setParamiv(ALfilter*, ALenum param, const int*) +{ + throw filter_exception{AL_INVALID_ENUM, "Invalid high-pass integer-vector property 0x%04x", + param}; +} +void ALhighpass_setParamf(ALfilter *filter, ALenum param, float val) { switch(param) { - case AL_HIGHPASS_GAIN: - if(!(val >= FILTER_MIN_GAIN && val <= FILTER_MAX_GAIN)) - SETERR_RETURN(context, AL_INVALID_VALUE,, "High-pass gain out of range"); - filter->Gain = val; - break; - - case AL_HIGHPASS_GAINLF: - if(!(val >= AL_HIGHPASS_MIN_GAINLF && val <= AL_HIGHPASS_MAX_GAINLF)) - SETERR_RETURN(context, AL_INVALID_VALUE,, "High-pass gainlf out of range"); - filter->GainLF = val; - break; - - default: - context->setError(AL_INVALID_ENUM, "Invalid high-pass float property 0x%04x", param); + case AL_HIGHPASS_GAIN: + if(!(val >= AL_HIGHPASS_MIN_GAIN && val <= AL_HIGHPASS_MAX_GAIN)) + throw filter_exception{AL_INVALID_VALUE, "High-pass gain %f out of range", val}; + filter->Gain = val; + break; + + case AL_HIGHPASS_GAINLF: + if(!(val >= AL_HIGHPASS_MIN_GAINLF && val <= AL_HIGHPASS_MAX_GAINLF)) + throw filter_exception{AL_INVALID_VALUE, "High-pass gainlf %f out of range", val}; + filter->GainLF = val; + break; + + default: + throw filter_exception{AL_INVALID_ENUM, "Invalid high-pass float property 0x%04x", param}; } } -void ALhighpass_setParamfv(ALfilter *filter, ALCcontext *context, ALenum param, const ALfloat *vals) -{ ALhighpass_setParamf(filter, context, param, vals[0]); } - -void ALhighpass_getParami(ALfilter*, ALCcontext *context, ALenum param, ALint*) -{ context->setError(AL_INVALID_ENUM, "Invalid high-pass integer property 0x%04x", param); } -void ALhighpass_getParamiv(ALfilter*, ALCcontext *context, ALenum param, ALint*) -{ context->setError(AL_INVALID_ENUM, "Invalid high-pass integer-vector property 0x%04x", param); } -void ALhighpass_getParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *val) +void ALhighpass_setParamfv(ALfilter *filter, ALenum param, const float *vals) +{ ALhighpass_setParamf(filter, param, vals[0]); } + +void ALhighpass_getParami(const ALfilter*, ALenum param, int*) +{ throw filter_exception{AL_INVALID_ENUM, "Invalid high-pass integer property 0x%04x", param}; } +void ALhighpass_getParamiv(const ALfilter*, ALenum param, int*) +{ + throw filter_exception{AL_INVALID_ENUM, "Invalid high-pass integer-vector property 0x%04x", + param}; +} +void ALhighpass_getParamf(const ALfilter *filter, ALenum param, float *val) { switch(param) { - case AL_HIGHPASS_GAIN: - *val = filter->Gain; - break; + case AL_HIGHPASS_GAIN: + *val = filter->Gain; + break; - case AL_HIGHPASS_GAINLF: - *val = filter->GainLF; - break; + case AL_HIGHPASS_GAINLF: + *val = filter->GainLF; + break; - default: - context->setError(AL_INVALID_ENUM, "Invalid high-pass float property 0x%04x", param); + default: + throw filter_exception{AL_INVALID_ENUM, "Invalid high-pass float property 0x%04x", param}; } } -void ALhighpass_getParamfv(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *vals) -{ ALhighpass_getParamf(filter, context, param, vals); } +void ALhighpass_getParamfv(const ALfilter *filter, ALenum param, float *vals) +{ ALhighpass_getParamf(filter, param, vals); } DEFINE_ALFILTER_VTABLE(ALhighpass); -void ALbandpass_setParami(ALfilter*, ALCcontext *context, ALenum param, ALint) -{ context->setError(AL_INVALID_ENUM, "Invalid band-pass integer property 0x%04x", param); } -void ALbandpass_setParamiv(ALfilter*, ALCcontext *context, ALenum param, const ALint*) -{ context->setError(AL_INVALID_ENUM, "Invalid band-pass integer-vector property 0x%04x", param); } -void ALbandpass_setParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat val) +void ALbandpass_setParami(ALfilter*, ALenum param, int) +{ throw filter_exception{AL_INVALID_ENUM, "Invalid band-pass integer property 0x%04x", param}; } +void ALbandpass_setParamiv(ALfilter*, ALenum param, const int*) +{ + throw filter_exception{AL_INVALID_ENUM, "Invalid band-pass integer-vector property 0x%04x", + param}; +} +void ALbandpass_setParamf(ALfilter *filter, ALenum param, float val) { switch(param) { - case AL_BANDPASS_GAIN: - if(!(val >= FILTER_MIN_GAIN && val <= FILTER_MAX_GAIN)) - SETERR_RETURN(context, AL_INVALID_VALUE,, "Band-pass gain out of range"); - filter->Gain = val; - break; - - case AL_BANDPASS_GAINHF: - if(!(val >= AL_BANDPASS_MIN_GAINHF && val <= AL_BANDPASS_MAX_GAINHF)) - SETERR_RETURN(context, AL_INVALID_VALUE,, "Band-pass gainhf out of range"); - filter->GainHF = val; - break; - - case AL_BANDPASS_GAINLF: - if(!(val >= AL_BANDPASS_MIN_GAINLF && val <= AL_BANDPASS_MAX_GAINLF)) - SETERR_RETURN(context, AL_INVALID_VALUE,, "Band-pass gainlf out of range"); - filter->GainLF = val; - break; - - default: - context->setError(AL_INVALID_ENUM, "Invalid band-pass float property 0x%04x", param); + case AL_BANDPASS_GAIN: + if(!(val >= AL_BANDPASS_MIN_GAIN && val <= AL_BANDPASS_MAX_GAIN)) + throw filter_exception{AL_INVALID_VALUE, "Band-pass gain %f out of range", val}; + filter->Gain = val; + break; + + case AL_BANDPASS_GAINHF: + if(!(val >= AL_BANDPASS_MIN_GAINHF && val <= AL_BANDPASS_MAX_GAINHF)) + throw filter_exception{AL_INVALID_VALUE, "Band-pass gainhf %f out of range", val}; + filter->GainHF = val; + break; + + case AL_BANDPASS_GAINLF: + if(!(val >= AL_BANDPASS_MIN_GAINLF && val <= AL_BANDPASS_MAX_GAINLF)) + throw filter_exception{AL_INVALID_VALUE, "Band-pass gainlf %f out of range", val}; + filter->GainLF = val; + break; + + default: + throw filter_exception{AL_INVALID_ENUM, "Invalid band-pass float property 0x%04x", param}; } } -void ALbandpass_setParamfv(ALfilter *filter, ALCcontext *context, ALenum param, const ALfloat *vals) -{ ALbandpass_setParamf(filter, context, param, vals[0]); } - -void ALbandpass_getParami(ALfilter*, ALCcontext *context, ALenum param, ALint*) -{ context->setError(AL_INVALID_ENUM, "Invalid band-pass integer property 0x%04x", param); } -void ALbandpass_getParamiv(ALfilter*, ALCcontext *context, ALenum param, ALint*) -{ context->setError(AL_INVALID_ENUM, "Invalid band-pass integer-vector property 0x%04x", param); } -void ALbandpass_getParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *val) +void ALbandpass_setParamfv(ALfilter *filter, ALenum param, const float *vals) +{ ALbandpass_setParamf(filter, param, vals[0]); } + +void ALbandpass_getParami(const ALfilter*, ALenum param, int*) +{ throw filter_exception{AL_INVALID_ENUM, "Invalid band-pass integer property 0x%04x", param}; } +void ALbandpass_getParamiv(const ALfilter*, ALenum param, int*) +{ + throw filter_exception{AL_INVALID_ENUM, "Invalid band-pass integer-vector property 0x%04x", + param}; +} +void ALbandpass_getParamf(const ALfilter *filter, ALenum param, float *val) { switch(param) { - case AL_BANDPASS_GAIN: - *val = filter->Gain; - break; + case AL_BANDPASS_GAIN: + *val = filter->Gain; + break; - case AL_BANDPASS_GAINHF: - *val = filter->GainHF; - break; + case AL_BANDPASS_GAINHF: + *val = filter->GainHF; + break; - case AL_BANDPASS_GAINLF: - *val = filter->GainLF; - break; + case AL_BANDPASS_GAINLF: + *val = filter->GainLF; + break; - default: - context->setError(AL_INVALID_ENUM, "Invalid band-pass float property 0x%04x", param); + default: + throw filter_exception{AL_INVALID_ENUM, "Invalid band-pass float property 0x%04x", param}; } } -void ALbandpass_getParamfv(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *vals) -{ ALbandpass_getParamf(filter, context, param, vals); } +void ALbandpass_getParamfv(const ALfilter *filter, ALenum param, float *vals) +{ ALbandpass_getParamf(filter, param, vals); } DEFINE_ALFILTER_VTABLE(ALbandpass); -void ALnullfilter_setParami(ALfilter*, ALCcontext *context, ALenum param, ALint) -{ context->setError(AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); } -void ALnullfilter_setParamiv(ALfilter*, ALCcontext *context, ALenum param, const ALint*) -{ context->setError(AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); } -void ALnullfilter_setParamf(ALfilter*, ALCcontext *context, ALenum param, ALfloat) -{ context->setError(AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); } -void ALnullfilter_setParamfv(ALfilter*, ALCcontext *context, ALenum param, const ALfloat*) -{ context->setError(AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); } - -void ALnullfilter_getParami(ALfilter*, ALCcontext *context, ALenum param, ALint*) -{ context->setError(AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); } -void ALnullfilter_getParamiv(ALfilter*, ALCcontext *context, ALenum param, ALint*) -{ context->setError(AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); } -void ALnullfilter_getParamf(ALfilter*, ALCcontext *context, ALenum param, ALfloat*) -{ context->setError(AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); } -void ALnullfilter_getParamfv(ALfilter*, ALCcontext *context, ALenum param, ALfloat*) -{ context->setError(AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); } +void ALnullfilter_setParami(ALfilter*, ALenum param, int) +{ throw filter_exception{AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param}; } +void ALnullfilter_setParamiv(ALfilter*, ALenum param, const int*) +{ throw filter_exception{AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param}; } +void ALnullfilter_setParamf(ALfilter*, ALenum param, float) +{ throw filter_exception{AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param}; } +void ALnullfilter_setParamfv(ALfilter*, ALenum param, const float*) +{ throw filter_exception{AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param}; } + +void ALnullfilter_getParami(const ALfilter*, ALenum param, int*) +{ throw filter_exception{AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param}; } +void ALnullfilter_getParamiv(const ALfilter*, ALenum param, int*) +{ throw filter_exception{AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param}; } +void ALnullfilter_getParamf(const ALfilter*, ALenum param, float*) +{ throw filter_exception{AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param}; } +void ALnullfilter_getParamfv(const ALfilter*, ALenum param, float*) +{ throw filter_exception{AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param}; } DEFINE_ALFILTER_VTABLE(ALnullfilter); @@ -283,19 +332,18 @@ bool EnsureFilters(ALCdevice *device, size_t needed) { size_t count{std::accumulate(device->FilterList.cbegin(), device->FilterList.cend(), size_t{0}, [](size_t cur, const FilterSubList &sublist) noexcept -> size_t - { return cur + static_cast<ALuint>(POPCNT64(sublist.FreeMask)); } - )}; + { return cur + static_cast<ALuint>(al::popcount(sublist.FreeMask)); })}; while(needed > count) { - if UNLIKELY(device->FilterList.size() >= 1<<25) + if(device->FilterList.size() >= 1<<25) UNLIKELY return false; device->FilterList.emplace_back(); auto sublist = device->FilterList.end() - 1; sublist->FreeMask = ~0_u64; sublist->Filters = static_cast<ALfilter*>(al_calloc(alignof(ALfilter), sizeof(ALfilter)*64)); - if UNLIKELY(!sublist->Filters) + if(!sublist->Filters) UNLIKELY { device->FilterList.pop_back(); return false; @@ -310,12 +358,12 @@ ALfilter *AllocFilter(ALCdevice *device) { auto sublist = std::find_if(device->FilterList.begin(), device->FilterList.end(), [](const FilterSubList &entry) noexcept -> bool - { return entry.FreeMask != 0; } - ); + { return entry.FreeMask != 0; }); auto lidx = static_cast<ALuint>(std::distance(device->FilterList.begin(), sublist)); - auto slidx = static_cast<ALuint>(CTZ64(sublist->FreeMask)); + auto slidx = static_cast<ALuint>(al::countr_zero(sublist->FreeMask)); + ASSUME(slidx < 64); - ALfilter *filter{::new (sublist->Filters + slidx) ALfilter{}}; + ALfilter *filter{al::construct_at(sublist->Filters + slidx)}; InitFilterParams(filter, AL_FILTER_NULL); /* Add 1 to avoid filter ID 0. */ @@ -343,35 +391,35 @@ inline ALfilter *LookupFilter(ALCdevice *device, ALuint id) const size_t lidx{(id-1) >> 6}; const ALuint slidx{(id-1) & 0x3f}; - if UNLIKELY(lidx >= device->FilterList.size()) + if(lidx >= device->FilterList.size()) UNLIKELY return nullptr; FilterSubList &sublist = device->FilterList[lidx]; - if UNLIKELY(sublist.FreeMask & (1_u64 << slidx)) + if(sublist.FreeMask & (1_u64 << slidx)) UNLIKELY return nullptr; return sublist.Filters + slidx; } } // namespace -AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters) +AL_API void AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters) START_API_FUNC { ContextRef context{GetContextRef()}; - if UNLIKELY(!context) return; + if(!context) UNLIKELY return; - if UNLIKELY(n < 0) + if(n < 0) UNLIKELY context->setError(AL_INVALID_VALUE, "Generating %d filters", n); - if UNLIKELY(n <= 0) return; + if(n <= 0) UNLIKELY return; - ALCdevice *device{context->mDevice.get()}; - std::lock_guard<std::mutex> _{device->EffectLock}; + ALCdevice *device{context->mALDevice.get()}; + std::lock_guard<std::mutex> _{device->FilterLock}; if(!EnsureFilters(device, static_cast<ALuint>(n))) { context->setError(AL_OUT_OF_MEMORY, "Failed to allocate %d filter%s", n, (n==1)?"":"s"); return; } - if LIKELY(n == 1) + if(n == 1) LIKELY { /* Special handling for the easy and normal case. */ ALfilter *filter{AllocFilter(device)}; @@ -393,17 +441,17 @@ START_API_FUNC } END_API_FUNC -AL_API ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, const ALuint *filters) +AL_API void AL_APIENTRY alDeleteFilters(ALsizei n, const ALuint *filters) START_API_FUNC { ContextRef context{GetContextRef()}; - if UNLIKELY(!context) return; + if(!context) UNLIKELY return; - if UNLIKELY(n < 0) + if(n < 0) UNLIKELY context->setError(AL_INVALID_VALUE, "Deleting %d filters", n); - if UNLIKELY(n <= 0) return; + if(n <= 0) UNLIKELY return; - ALCdevice *device{context->mDevice.get()}; + ALCdevice *device{context->mALDevice.get()}; std::lock_guard<std::mutex> _{device->FilterLock}; /* First try to find any filters that are invalid. */ @@ -412,7 +460,7 @@ START_API_FUNC const ALuint *filters_end = filters + n; auto invflt = std::find_if_not(filters, filters_end, validate_filter); - if UNLIKELY(invflt != filters_end) + if(invflt != filters_end) UNLIKELY { context->setError(AL_INVALID_NAME, "Invalid filter ID %u", *invflt); return; @@ -432,9 +480,9 @@ AL_API ALboolean AL_APIENTRY alIsFilter(ALuint filter) START_API_FUNC { ContextRef context{GetContextRef()}; - if LIKELY(context) + if(context) LIKELY { - ALCdevice *device{context->mDevice.get()}; + ALCdevice *device{context->mALDevice.get()}; std::lock_guard<std::mutex> _{device->FilterLock}; if(!filter || LookupFilter(device, filter)) return AL_TRUE; @@ -444,192 +492,216 @@ START_API_FUNC END_API_FUNC -AL_API ALvoid AL_APIENTRY alFilteri(ALuint filter, ALenum param, ALint value) +AL_API void AL_APIENTRY alFilteri(ALuint filter, ALenum param, ALint value) START_API_FUNC { ContextRef context{GetContextRef()}; - if UNLIKELY(!context) return; + if(!context) UNLIKELY return; - ALCdevice *device{context->mDevice.get()}; + ALCdevice *device{context->mALDevice.get()}; std::lock_guard<std::mutex> _{device->FilterLock}; ALfilter *alfilt{LookupFilter(device, filter)}; - if UNLIKELY(!alfilt) + if(!alfilt) UNLIKELY context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); else { if(param == AL_FILTER_TYPE) { - if(value == AL_FILTER_NULL || value == AL_FILTER_LOWPASS || - value == AL_FILTER_HIGHPASS || value == AL_FILTER_BANDPASS) + if(value == AL_FILTER_NULL || value == AL_FILTER_LOWPASS + || value == AL_FILTER_HIGHPASS || value == AL_FILTER_BANDPASS) InitFilterParams(alfilt, value); else context->setError(AL_INVALID_VALUE, "Invalid filter type 0x%04x", value); } - else + else try { /* Call the appropriate handler */ - ALfilter_setParami(alfilt, context.get(), param, value); + alfilt->setParami(param, value); + } + catch(filter_exception &e) { + context->setError(e.errorCode(), "%s", e.what()); } } } END_API_FUNC -AL_API ALvoid AL_APIENTRY alFilteriv(ALuint filter, ALenum param, const ALint *values) +AL_API void AL_APIENTRY alFilteriv(ALuint filter, ALenum param, const ALint *values) START_API_FUNC { switch(param) { - case AL_FILTER_TYPE: - alFilteri(filter, param, values[0]); - return; + case AL_FILTER_TYPE: + alFilteri(filter, param, values[0]); + return; } ContextRef context{GetContextRef()}; - if UNLIKELY(!context) return; + if(!context) UNLIKELY return; - ALCdevice *device{context->mDevice.get()}; + ALCdevice *device{context->mALDevice.get()}; std::lock_guard<std::mutex> _{device->FilterLock}; ALfilter *alfilt{LookupFilter(device, filter)}; - if UNLIKELY(!alfilt) + if(!alfilt) UNLIKELY context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); - else + else try { /* Call the appropriate handler */ - ALfilter_setParamiv(alfilt, context.get(), param, values); + alfilt->setParamiv(param, values); + } + catch(filter_exception &e) { + context->setError(e.errorCode(), "%s", e.what()); } } END_API_FUNC -AL_API ALvoid AL_APIENTRY alFilterf(ALuint filter, ALenum param, ALfloat value) +AL_API void AL_APIENTRY alFilterf(ALuint filter, ALenum param, ALfloat value) START_API_FUNC { ContextRef context{GetContextRef()}; - if UNLIKELY(!context) return; + if(!context) UNLIKELY return; - ALCdevice *device{context->mDevice.get()}; + ALCdevice *device{context->mALDevice.get()}; std::lock_guard<std::mutex> _{device->FilterLock}; ALfilter *alfilt{LookupFilter(device, filter)}; - if UNLIKELY(!alfilt) + if(!alfilt) UNLIKELY context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); - else + else try { /* Call the appropriate handler */ - ALfilter_setParamf(alfilt, context.get(), param, value); + alfilt->setParamf(param, value); + } + catch(filter_exception &e) { + context->setError(e.errorCode(), "%s", e.what()); } } END_API_FUNC -AL_API ALvoid AL_APIENTRY alFilterfv(ALuint filter, ALenum param, const ALfloat *values) +AL_API void AL_APIENTRY alFilterfv(ALuint filter, ALenum param, const ALfloat *values) START_API_FUNC { ContextRef context{GetContextRef()}; - if UNLIKELY(!context) return; + if(!context) UNLIKELY return; - ALCdevice *device{context->mDevice.get()}; + ALCdevice *device{context->mALDevice.get()}; std::lock_guard<std::mutex> _{device->FilterLock}; ALfilter *alfilt{LookupFilter(device, filter)}; - if UNLIKELY(!alfilt) + if(!alfilt) UNLIKELY context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); - else + else try { /* Call the appropriate handler */ - ALfilter_setParamfv(alfilt, context.get(), param, values); + alfilt->setParamfv(param, values); + } + catch(filter_exception &e) { + context->setError(e.errorCode(), "%s", e.what()); } } END_API_FUNC -AL_API ALvoid AL_APIENTRY alGetFilteri(ALuint filter, ALenum param, ALint *value) +AL_API void AL_APIENTRY alGetFilteri(ALuint filter, ALenum param, ALint *value) START_API_FUNC { ContextRef context{GetContextRef()}; - if UNLIKELY(!context) return; + if(!context) UNLIKELY return; - ALCdevice *device{context->mDevice.get()}; + ALCdevice *device{context->mALDevice.get()}; std::lock_guard<std::mutex> _{device->FilterLock}; - ALfilter *alfilt{LookupFilter(device, filter)}; - if UNLIKELY(!alfilt) + const ALfilter *alfilt{LookupFilter(device, filter)}; + if(!alfilt) UNLIKELY context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); else { if(param == AL_FILTER_TYPE) *value = alfilt->type; - else + else try { /* Call the appropriate handler */ - ALfilter_getParami(alfilt, context.get(), param, value); + alfilt->getParami(param, value); + } + catch(filter_exception &e) { + context->setError(e.errorCode(), "%s", e.what()); } } } END_API_FUNC -AL_API ALvoid AL_APIENTRY alGetFilteriv(ALuint filter, ALenum param, ALint *values) +AL_API void AL_APIENTRY alGetFilteriv(ALuint filter, ALenum param, ALint *values) START_API_FUNC { switch(param) { - case AL_FILTER_TYPE: - alGetFilteri(filter, param, values); - return; + case AL_FILTER_TYPE: + alGetFilteri(filter, param, values); + return; } ContextRef context{GetContextRef()}; - if UNLIKELY(!context) return; + if(!context) UNLIKELY return; - ALCdevice *device{context->mDevice.get()}; + ALCdevice *device{context->mALDevice.get()}; std::lock_guard<std::mutex> _{device->FilterLock}; - ALfilter *alfilt{LookupFilter(device, filter)}; - if UNLIKELY(!alfilt) + const ALfilter *alfilt{LookupFilter(device, filter)}; + if(!alfilt) UNLIKELY context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); - else + else try { /* Call the appropriate handler */ - ALfilter_getParamiv(alfilt, context.get(), param, values); + alfilt->getParamiv(param, values); + } + catch(filter_exception &e) { + context->setError(e.errorCode(), "%s", e.what()); } } END_API_FUNC -AL_API ALvoid AL_APIENTRY alGetFilterf(ALuint filter, ALenum param, ALfloat *value) +AL_API void AL_APIENTRY alGetFilterf(ALuint filter, ALenum param, ALfloat *value) START_API_FUNC { ContextRef context{GetContextRef()}; - if UNLIKELY(!context) return; + if(!context) UNLIKELY return; - ALCdevice *device{context->mDevice.get()}; + ALCdevice *device{context->mALDevice.get()}; std::lock_guard<std::mutex> _{device->FilterLock}; - ALfilter *alfilt{LookupFilter(device, filter)}; - if UNLIKELY(!alfilt) + const ALfilter *alfilt{LookupFilter(device, filter)}; + if(!alfilt) UNLIKELY context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); - else + else try { /* Call the appropriate handler */ - ALfilter_getParamf(alfilt, context.get(), param, value); + alfilt->getParamf(param, value); + } + catch(filter_exception &e) { + context->setError(e.errorCode(), "%s", e.what()); } } END_API_FUNC -AL_API ALvoid AL_APIENTRY alGetFilterfv(ALuint filter, ALenum param, ALfloat *values) +AL_API void AL_APIENTRY alGetFilterfv(ALuint filter, ALenum param, ALfloat *values) START_API_FUNC { ContextRef context{GetContextRef()}; - if UNLIKELY(!context) return; + if(!context) UNLIKELY return; - ALCdevice *device{context->mDevice.get()}; + ALCdevice *device{context->mALDevice.get()}; std::lock_guard<std::mutex> _{device->FilterLock}; - ALfilter *alfilt{LookupFilter(device, filter)}; - if UNLIKELY(!alfilt) + const ALfilter *alfilt{LookupFilter(device, filter)}; + if(!alfilt) UNLIKELY context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); - else + else try { /* Call the appropriate handler */ - ALfilter_getParamfv(alfilt, context.get(), param, values); + alfilt->getParamfv(param, values); + } + catch(filter_exception &e) { + context->setError(e.errorCode(), "%s", e.what()); } } END_API_FUNC @@ -640,7 +712,7 @@ FilterSubList::~FilterSubList() uint64_t usemask{~FreeMask}; while(usemask) { - ALsizei idx = CTZ64(usemask); + const int idx{al::countr_zero(usemask)}; al::destroy_at(Filters+idx); usemask &= ~(1_u64 << idx); } |