diff options
-rw-r--r-- | al/auxeffectslot.cpp | 10 | ||||
-rw-r--r-- | al/buffer.cpp | 4 | ||||
-rw-r--r-- | al/effect.cpp | 4 | ||||
-rw-r--r-- | al/effects/reverb.cpp | 24 | ||||
-rw-r--r-- | al/event.cpp | 2 | ||||
-rw-r--r-- | al/filter.cpp | 4 | ||||
-rw-r--r-- | al/source.cpp | 8 | ||||
-rw-r--r-- | alc/backends/pipewire.cpp | 12 | ||||
-rw-r--r-- | common/almalloc.h | 71 | ||||
-rw-r--r-- | common/alnumeric.h | 6 | ||||
-rw-r--r-- | core/context.cpp | 6 | ||||
-rw-r--r-- | core/mastering.cpp | 4 | ||||
-rw-r--r-- | utils/uhjencoder.cpp | 6 |
13 files changed, 44 insertions, 117 deletions
diff --git a/al/auxeffectslot.cpp b/al/auxeffectslot.cpp index 571eb717..c69990fe 100644 --- a/al/auxeffectslot.cpp +++ b/al/auxeffectslot.cpp @@ -165,7 +165,7 @@ void AddActiveEffectSlots(const al::span<ALeffectslot*> auxslots, ALCcontext *co curarray = context->mActiveAuxSlots.exchange(newarray, std::memory_order_acq_rel); context->mDevice->waitForMix(); - al::destroy_n(curarray->end(), curarray->size()); + std::destroy_n(curarray->end(), curarray->size()); delete curarray; } @@ -204,7 +204,7 @@ void RemoveActiveEffectSlots(const al::span<ALeffectslot*> auxslots, ALCcontext curarray = context->mActiveAuxSlots.exchange(newarray, std::memory_order_acq_rel); context->mDevice->waitForMix(); - al::destroy_n(curarray->end(), curarray->size()); + std::destroy_n(curarray->end(), curarray->size()); delete curarray; } @@ -289,7 +289,7 @@ void FreeEffectSlot(ALCcontext *context, ALeffectslot *slot) const size_t lidx{id >> 6}; const ALuint slidx{id & 0x3f}; - al::destroy_at(slot); + std::destroy_at(slot); context->mEffectSlotList[lidx].FreeMask |= 1_u64 << slidx; context->mNumEffectSlots--; @@ -1030,7 +1030,7 @@ EffectSlotSubList::~EffectSlotSubList() while(usemask) { const int idx{al::countr_zero(usemask)}; - al::destroy_at(EffectSlots+idx); + std::destroy_at(EffectSlots+idx); usemask &= ~(1_u64 << idx); } FreeMask = ~usemask; @@ -1275,7 +1275,7 @@ void ALeffectslot::eax_fx_slot_load_effect(int version, ALenum altype) void ALeffectslot::eax_fx_slot_set_volume() { - const auto volume = clamp(eax_.lVolume, EAXFXSLOT_MINVOLUME, EAXFXSLOT_MAXVOLUME); + const auto volume = std::clamp(eax_.lVolume, EAXFXSLOT_MINVOLUME, EAXFXSLOT_MAXVOLUME); const auto gain = level_mb_to_gain(static_cast<float>(volume)); eax_set_efx_slot_gain(gain); } diff --git a/al/buffer.cpp b/al/buffer.cpp index 1a042f46..371e586c 100644 --- a/al/buffer.cpp +++ b/al/buffer.cpp @@ -222,7 +222,7 @@ void FreeBuffer(ALCdevice *device, ALbuffer *buffer) const size_t lidx{id >> 6}; const ALuint slidx{id & 0x3f}; - al::destroy_at(buffer); + std::destroy_at(buffer); device->BufferList[lidx].FreeMask |= 1_u64 << slidx; } @@ -1533,7 +1533,7 @@ BufferSubList::~BufferSubList() while(usemask) { const int idx{al::countr_zero(usemask)}; - al::destroy_at(Buffers+idx); + std::destroy_at(Buffers+idx); usemask &= ~(1_u64 << idx); } FreeMask = ~usemask; diff --git a/al/effect.cpp b/al/effect.cpp index 28f5e967..3d91139a 100644 --- a/al/effect.cpp +++ b/al/effect.cpp @@ -210,7 +210,7 @@ void FreeEffect(ALCdevice *device, ALeffect *effect) const size_t lidx{id >> 6}; const ALuint slidx{id & 0x3f}; - al::destroy_at(effect); + std::destroy_at(effect); device->EffectList[lidx].FreeMask |= 1_u64 << slidx; } @@ -555,7 +555,7 @@ EffectSubList::~EffectSubList() while(usemask) { const int idx{al::countr_zero(usemask)}; - al::destroy_at(Effects+idx); + std::destroy_at(Effects+idx); usemask &= ~(1_u64 << idx); } FreeMask = ~usemask; diff --git a/al/effects/reverb.cpp b/al/effects/reverb.cpp index 440d7b4e..d93602cd 100644 --- a/al/effects/reverb.cpp +++ b/al/effects/reverb.cpp @@ -945,7 +945,7 @@ struct EnvironmentSizeDeferrer2 { if ((props.dwFlags & EAX2LISTENERFLAGS_DECAYTIMESCALE) != 0) { - props.flDecayTime = clamp( + props.flDecayTime = std::clamp( props.flDecayTime * scale, EAXREVERB_MINDECAYTIME, EAXREVERB_MAXDECAYTIME); @@ -954,7 +954,7 @@ struct EnvironmentSizeDeferrer2 { if ((props.dwFlags & EAX2LISTENERFLAGS_REFLECTIONSSCALE) != 0 && (props.dwFlags & EAX2LISTENERFLAGS_REFLECTIONSDELAYSCALE) != 0) { - props.lReflections = clamp( + props.lReflections = std::clamp( props.lReflections - static_cast<long>(gain_to_level_mb(scale)), EAXREVERB_MINREFLECTIONS, EAXREVERB_MAXREFLECTIONS); @@ -962,7 +962,7 @@ struct EnvironmentSizeDeferrer2 { if ((props.dwFlags & EAX2LISTENERFLAGS_REFLECTIONSDELAYSCALE) != 0) { - props.flReflectionsDelay = clamp( + props.flReflectionsDelay = std::clamp( props.flReflectionsDelay * scale, EAXREVERB_MINREFLECTIONSDELAY, EAXREVERB_MAXREFLECTIONSDELAY); @@ -972,7 +972,7 @@ struct EnvironmentSizeDeferrer2 { { const auto log_scalar = ((props.dwFlags & EAXREVERBFLAGS_DECAYTIMESCALE) != 0) ? 2'000.0F : 3'000.0F; - props.lReverb = clamp( + props.lReverb = std::clamp( props.lReverb - static_cast<long>(std::log10(scale) * log_scalar), EAXREVERB_MINREVERB, EAXREVERB_MAXREVERB); @@ -980,7 +980,7 @@ struct EnvironmentSizeDeferrer2 { if ((props.dwFlags & EAX2LISTENERFLAGS_REVERBDELAYSCALE) != 0) { - props.flReverbDelay = clamp( + props.flReverbDelay = std::clamp( props.flReverbDelay * scale, EAXREVERB_MINREVERBDELAY, EAXREVERB_MAXREVERBDELAY); @@ -1015,7 +1015,7 @@ struct EnvironmentSizeDeferrer3 { if ((props.ulFlags & EAXREVERBFLAGS_DECAYTIMESCALE) != 0) { - props.flDecayTime = clamp( + props.flDecayTime = std::clamp( props.flDecayTime * scale, EAXREVERB_MINDECAYTIME, EAXREVERB_MAXDECAYTIME); @@ -1024,7 +1024,7 @@ struct EnvironmentSizeDeferrer3 { if ((props.ulFlags & EAXREVERBFLAGS_REFLECTIONSSCALE) != 0 && (props.ulFlags & EAXREVERBFLAGS_REFLECTIONSDELAYSCALE) != 0) { - props.lReflections = clamp( + props.lReflections = std::clamp( props.lReflections - static_cast<long>(gain_to_level_mb(scale)), EAXREVERB_MINREFLECTIONS, EAXREVERB_MAXREFLECTIONS); @@ -1032,7 +1032,7 @@ struct EnvironmentSizeDeferrer3 { if ((props.ulFlags & EAXREVERBFLAGS_REFLECTIONSDELAYSCALE) != 0) { - props.flReflectionsDelay = clamp( + props.flReflectionsDelay = std::clamp( props.flReflectionsDelay * scale, EAXREVERB_MINREFLECTIONSDELAY, EAXREVERB_MAXREFLECTIONSDELAY); @@ -1041,7 +1041,7 @@ struct EnvironmentSizeDeferrer3 { if ((props.ulFlags & EAXREVERBFLAGS_REVERBSCALE) != 0) { const auto log_scalar = ((props.ulFlags & EAXREVERBFLAGS_DECAYTIMESCALE) != 0) ? 2'000.0F : 3'000.0F; - props.lReverb = clamp( + props.lReverb = std::clamp( props.lReverb - static_cast<long>(std::log10(scale) * log_scalar), EAXREVERB_MINREVERB, EAXREVERB_MAXREVERB); @@ -1049,7 +1049,7 @@ struct EnvironmentSizeDeferrer3 { if ((props.ulFlags & EAXREVERBFLAGS_REVERBDELAYSCALE) != 0) { - props.flReverbDelay = clamp( + props.flReverbDelay = std::clamp( props.flReverbDelay * scale, EAXREVERB_MINREVERBDELAY, EAXREVERB_MAXREVERBDELAY); @@ -1057,7 +1057,7 @@ struct EnvironmentSizeDeferrer3 { if ((props.ulFlags & EAXREVERBFLAGS_ECHOTIMESCALE) != 0) { - props.flEchoTime = clamp( + props.flEchoTime = std::clamp( props.flEchoTime * scale, EAXREVERB_MINECHOTIME, EAXREVERB_MAXECHOTIME); @@ -1065,7 +1065,7 @@ struct EnvironmentSizeDeferrer3 { if ((props.ulFlags & EAXREVERBFLAGS_MODULATIONTIMESCALE) != 0) { - props.flModulationTime = clamp( + props.flModulationTime = std::clamp( props.flModulationTime * scale, EAXREVERB_MINMODULATIONTIME, EAXREVERB_MAXMODULATIONTIME); diff --git a/al/event.cpp b/al/event.cpp index acb4958a..33e28412 100644 --- a/al/event.cpp +++ b/al/event.cpp @@ -50,7 +50,7 @@ static int EventThread(ALCcontext *context) evt_data.len -= 1; AsyncEvent evt{*evt_ptr}; - al::destroy_at(evt_ptr); + std::destroy_at(evt_ptr); ring->readAdvance(1); quitnow = evt.EnumType == AsyncEvent::KillThread; diff --git a/al/filter.cpp b/al/filter.cpp index c5d1b2a1..0fd8eaa8 100644 --- a/al/filter.cpp +++ b/al/filter.cpp @@ -380,7 +380,7 @@ void FreeFilter(ALCdevice *device, ALfilter *filter) const size_t lidx{id >> 6}; const ALuint slidx{id & 0x3f}; - al::destroy_at(filter); + std::destroy_at(filter); device->FilterList[lidx].FreeMask |= 1_u64 << slidx; } @@ -716,7 +716,7 @@ FilterSubList::~FilterSubList() while(usemask) { const int idx{al::countr_zero(usemask)}; - al::destroy_at(Filters+idx); + std::destroy_at(Filters+idx); usemask &= ~(1_u64 << idx); } FreeMask = ~usemask; diff --git a/al/source.cpp b/al/source.cpp index 2b0540b4..b8feb0c3 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -738,7 +738,7 @@ void FreeSource(ALCcontext *context, ALsource *source) SendVoiceChanges(context, vchg); } - al::destroy_at(source); + std::destroy_at(source); context->mSourceList[lidx].FreeMask |= 1_u64 << slidx; context->mNumSources--; @@ -4041,7 +4041,7 @@ SourceSubList::~SourceSubList() { const int idx{al::countr_zero(usemask)}; usemask &= ~(1_u64 << idx); - al::destroy_at(Sources+idx); + std::destroy_at(Sources+idx); } FreeMask = ~usemask; al_free(Sources); @@ -4257,7 +4257,7 @@ void ALsource::eax1_translate(const Eax1Props& src, Eax5Props& dst) noexcept else { dst.source.ulFlags &= ~EAXSOURCEFLAGS_ROOMAUTO; - dst.sends[0].lSend = clamp(static_cast<long>(gain_to_level_mb(src.fMix)), + dst.sends[0].lSend = std::clamp(static_cast<long>(gain_to_level_mb(src.fMix)), EAXSOURCE_MINSEND, EAXSOURCE_MAXSEND); } } @@ -4492,7 +4492,7 @@ void ALsource::eax_update_room_filters() void ALsource::eax_set_efx_outer_gain_hf() { - OuterGainHF = clamp( + OuterGainHF = std::clamp( level_mb_to_gain(static_cast<float>(mEax.source.lOutsideVolumeHF)), AL_MIN_CONE_OUTER_GAINHF, AL_MAX_CONE_OUTER_GAINHF); diff --git a/alc/backends/pipewire.cpp b/alc/backends/pipewire.cpp index dc52a44d..bb7fc2f2 100644 --- a/alc/backends/pipewire.cpp +++ b/alc/backends/pipewire.cpp @@ -1085,9 +1085,9 @@ EventManager::~EventManager() if(mLoop) mLoop.stop(); for(NodeProxy *node : mNodeList) - al::destroy_at(node); + std::destroy_at(node); if(mDefaultMetadata) - al::destroy_at(mDefaultMetadata); + std::destroy_at(mDefaultMetadata); } void EventManager::kill() @@ -1095,10 +1095,10 @@ void EventManager::kill() if(mLoop) mLoop.stop(); for(NodeProxy *node : mNodeList) - al::destroy_at(node); + std::destroy_at(node); mNodeList.clear(); if(mDefaultMetadata) - al::destroy_at(mDefaultMetadata); + std::destroy_at(mDefaultMetadata); mDefaultMetadata = nullptr; mRegistry = nullptr; @@ -1191,7 +1191,7 @@ void EventManager::removeCallback(uint32_t id) { if(node->mId != id) return false; - al::destroy_at(node); + std::destroy_at(node); return true; }; auto node_end = std::remove_if(mNodeList.begin(), mNodeList.end(), clear_node); @@ -1199,7 +1199,7 @@ void EventManager::removeCallback(uint32_t id) if(mDefaultMetadata && mDefaultMetadata->mId == id) { - al::destroy_at(mDefaultMetadata); + std::destroy_at(mDefaultMetadata); mDefaultMetadata = nullptr; } } diff --git a/common/almalloc.h b/common/almalloc.h index a795fc3b..bd2e085b 100644 --- a/common/almalloc.h +++ b/common/almalloc.h @@ -125,71 +125,6 @@ constexpr T* construct_at(T *ptr, Args&& ...args) noexcept(std::is_nothrow_constructible<T, Args...>::value) { return ::new(static_cast<void*>(ptr)) T{std::forward<Args>(args)...}; } -/* At least VS 2015 complains that 'ptr' is unused when the given type's - * destructor is trivial (a no-op). So disable that warning for this call. - */ -DIAGNOSTIC_PUSH -msc_pragma(warning(disable : 4100)) -template<typename T> -constexpr std::enable_if_t<!std::is_array<T>::value> -destroy_at(T *ptr) noexcept(std::is_nothrow_destructible<T>::value) -{ ptr->~T(); } -DIAGNOSTIC_POP -template<typename T> -constexpr std::enable_if_t<std::is_array<T>::value> -destroy_at(T *ptr) noexcept(std::is_nothrow_destructible<std::remove_all_extents_t<T>>::value) -{ - for(auto &elem : *ptr) - al::destroy_at(std::addressof(elem)); -} - -template<typename T> -constexpr void destroy(T first, T end) noexcept(noexcept(al::destroy_at(std::addressof(*first)))) -{ - while(first != end) - { - al::destroy_at(std::addressof(*first)); - ++first; - } -} - -template<typename T, typename N> -constexpr std::enable_if_t<std::is_integral<N>::value,T> -destroy_n(T first, N count) noexcept(noexcept(al::destroy_at(std::addressof(*first)))) -{ - if(count != 0) - { - do { - al::destroy_at(std::addressof(*first)); - ++first; - } while(--count); - } - return first; -} - - -template<typename T, typename N> -inline std::enable_if_t<std::is_integral<N>::value, -T> uninitialized_default_construct_n(T first, N count) -{ - using ValueT = typename std::iterator_traits<T>::value_type; - T current{first}; - if(count != 0) - { - try { - do { - ::new(static_cast<void*>(std::addressof(*current))) ValueT; - ++current; - } while(--count); - } - catch(...) { - al::destroy(first, current); - throw; - } - } - return current; -} - /* Storage for flexible array data. This is trivially destructible if type T is * trivially destructible. @@ -209,7 +144,7 @@ struct FlexArrayStorage { } FlexArrayStorage(size_t size) : mSize{size} - { al::uninitialized_default_construct_n(mArray, mSize); } + { std::uninitialized_default_construct_n(mArray, mSize); } ~FlexArrayStorage() = default; FlexArrayStorage(const FlexArrayStorage&) = delete; @@ -231,8 +166,8 @@ struct FlexArrayStorage<T,alignment,false> { } FlexArrayStorage(size_t size) : mSize{size} - { al::uninitialized_default_construct_n(mArray, mSize); } - ~FlexArrayStorage() { al::destroy_n(mArray, mSize); } + { std::uninitialized_default_construct_n(mArray, mSize); } + ~FlexArrayStorage() { std::destroy_n(mArray, mSize); } FlexArrayStorage(const FlexArrayStorage&) = delete; FlexArrayStorage& operator=(const FlexArrayStorage&) = delete; diff --git a/common/alnumeric.h b/common/alnumeric.h index d6919e40..8220d3e5 100644 --- a/common/alnumeric.h +++ b/common/alnumeric.h @@ -283,12 +283,6 @@ inline float fast_roundf(float f) noexcept } -template<typename T> -constexpr const T& clamp(const T& value, const T& min_value, const T& max_value) noexcept -{ - return std::min(std::max(value, min_value), max_value); -} - // Converts level (mB) to gain. inline float level_mb_to_gain(float x) { diff --git a/core/context.cpp b/core/context.cpp index d68d8327..d94daf16 100644 --- a/core/context.cpp +++ b/core/context.cpp @@ -51,7 +51,7 @@ ContextBase::~ContextBase() if(EffectSlotArray *curarray{mActiveAuxSlots.exchange(nullptr, std::memory_order_relaxed)}) { - al::destroy_n(curarray->end(), curarray->size()); + std::destroy_n(curarray->end(), curarray->size()); delete curarray; } @@ -63,12 +63,12 @@ ContextBase::~ContextBase() auto evt_vec = mAsyncEvents->getReadVector(); if(evt_vec.first.len > 0) { - al::destroy_n(reinterpret_cast<AsyncEvent*>(evt_vec.first.buf), evt_vec.first.len); + std::destroy_n(reinterpret_cast<AsyncEvent*>(evt_vec.first.buf), evt_vec.first.len); count += evt_vec.first.len; } if(evt_vec.second.len > 0) { - al::destroy_n(reinterpret_cast<AsyncEvent*>(evt_vec.second.buf), evt_vec.second.len); + std::destroy_n(reinterpret_cast<AsyncEvent*>(evt_vec.second.buf), evt_vec.second.len); count += evt_vec.second.len; } if(count > 0) diff --git a/core/mastering.cpp b/core/mastering.cpp index 97a4008e..4445719b 100644 --- a/core/mastering.cpp +++ b/core/mastering.cpp @@ -382,10 +382,10 @@ std::unique_ptr<Compressor> Compressor::Create(const size_t NumChans, const floa Compressor::~Compressor() { if(mHold) - al::destroy_at(mHold); + std::destroy_at(mHold); mHold = nullptr; if(mDelay) - al::destroy_n(mDelay, mNumChans); + std::destroy_n(mDelay, mNumChans); mDelay = nullptr; } diff --git a/utils/uhjencoder.cpp b/utils/uhjencoder.cpp index 34698993..c381d1b9 100644 --- a/utils/uhjencoder.cpp +++ b/utils/uhjencoder.cpp @@ -502,11 +502,9 @@ int main(int argc, char **argv) got -= LeadIn; for(size_t c{0};c < uhjchans;++c) { - constexpr float max_val{8388607.0f / 8388608.0f}; - auto clamp = [](float v, float mn, float mx) noexcept - { return std::min(std::max(v, mn), mx); }; + static constexpr float max_val{8388607.0f / 8388608.0f}; for(size_t i{0};i < got;++i) - outmem[i*uhjchans + c] = clamp(encmem[c][LeadIn+i], -1.0f, max_val); + outmem[i*uhjchans + c] = std::clamp(encmem[c][LeadIn+i], -1.0f, max_val); } LeadIn = 0; |