From 4c9e18c5a0c29548eb38db636785aa7064713c5d Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 29 Jul 2019 17:54:07 -0700 Subject: Rename al/* sources to avoid camel-case --- al/source.cpp | 3639 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 3639 insertions(+) create mode 100644 al/source.cpp (limited to 'al/source.cpp') diff --git a/al/source.cpp b/al/source.cpp new file mode 100644 index 00000000..b4582e6b --- /dev/null +++ b/al/source.cpp @@ -0,0 +1,3639 @@ +/** + * OpenAL cross platform audio library + * Copyright (C) 1999-2007 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 "source.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "AL/al.h" +#include "AL/alc.h" +#include "AL/alext.h" +#include "AL/efx.h" + +#include "alcmain.h" +#include "alcontext.h" +#include "alexcpt.h" +#include "almalloc.h" +#include "alnumeric.h" +#include "alu.h" +#include "ambidefs.h" +#include "atomic.h" +#include "auxeffectslot.h" +#include "backends/base.h" +#include "bformatdec.h" +#include "buffer.h" +#include "error.h" +#include "event.h" +#include "filter.h" +#include "filters/nfc.h" +#include "filters/splitter.h" +#include "inprogext.h" +#include "logging.h" +#include "math_defs.h" +#include "opthelpers.h" +#include "ringbuffer.h" +#include "threads.h" + + +namespace { + +using namespace std::placeholders; + +inline ALvoice *GetSourceVoice(ALsource *source, ALCcontext *context) +{ + ALint idx{source->VoiceIdx}; + if(idx >= 0 && static_cast(idx) < context->VoiceCount.load(std::memory_order_relaxed)) + { + ALuint sid{source->id}; + ALvoice &voice = (*context->Voices)[idx]; + if(voice.mSourceID.load(std::memory_order_acquire) == sid) + return &voice; + } + source->VoiceIdx = -1; + return nullptr; +} + +void UpdateSourceProps(const ALsource *source, ALvoice *voice, ALCcontext *context) +{ + /* Get an unused property container, or allocate a new one as needed. */ + ALvoiceProps *props{context->FreeVoiceProps.load(std::memory_order_acquire)}; + if(!props) + props = new ALvoiceProps{}; + else + { + ALvoiceProps *next; + do { + next = props->next.load(std::memory_order_relaxed); + } while(context->FreeVoiceProps.compare_exchange_weak(props, next, + std::memory_order_acq_rel, std::memory_order_acquire) == 0); + } + + /* Copy in current property values. */ + props->Pitch = source->Pitch; + props->Gain = source->Gain; + props->OuterGain = source->OuterGain; + props->MinGain = source->MinGain; + props->MaxGain = source->MaxGain; + props->InnerAngle = source->InnerAngle; + props->OuterAngle = source->OuterAngle; + props->RefDistance = source->RefDistance; + props->MaxDistance = source->MaxDistance; + props->RolloffFactor = source->RolloffFactor; + props->Position = source->Position; + props->Velocity = source->Velocity; + props->Direction = source->Direction; + props->OrientAt = source->OrientAt; + props->OrientUp = source->OrientUp; + props->HeadRelative = source->HeadRelative; + props->mDistanceModel = source->mDistanceModel; + props->mResampler = source->mResampler; + props->DirectChannels = source->DirectChannels; + props->mSpatializeMode = source->mSpatialize; + + props->DryGainHFAuto = source->DryGainHFAuto; + props->WetGainAuto = source->WetGainAuto; + props->WetGainHFAuto = source->WetGainHFAuto; + props->OuterGainHF = source->OuterGainHF; + + props->AirAbsorptionFactor = source->AirAbsorptionFactor; + props->RoomRolloffFactor = source->RoomRolloffFactor; + props->DopplerFactor = source->DopplerFactor; + + props->StereoPan = source->StereoPan; + + props->Radius = source->Radius; + + props->Direct.Gain = source->Direct.Gain; + props->Direct.GainHF = source->Direct.GainHF; + props->Direct.HFReference = source->Direct.HFReference; + props->Direct.GainLF = source->Direct.GainLF; + props->Direct.LFReference = source->Direct.LFReference; + + auto copy_send = [](const ALsource::SendData &srcsend) noexcept -> ALvoicePropsBase::SendData + { + ALvoicePropsBase::SendData ret; + ret.Slot = srcsend.Slot; + ret.Gain = srcsend.Gain; + ret.GainHF = srcsend.GainHF; + ret.HFReference = srcsend.HFReference; + ret.GainLF = srcsend.GainLF; + ret.LFReference = srcsend.LFReference; + return ret; + }; + std::transform(source->Send.cbegin(), source->Send.cend(), props->Send, copy_send); + + /* Set the new container for updating internal parameters. */ + props = voice->mUpdate.exchange(props, std::memory_order_acq_rel); + if(props) + { + /* If there was an unused update container, put it back in the + * freelist. + */ + AtomicReplaceHead(context->FreeVoiceProps, props); + } +} + +/* GetSourceSampleOffset + * + * Gets the current read offset for the given Source, in 32.32 fixed-point + * samples. The offset is relative to the start of the queue (not the start of + * the current buffer). + */ +int64_t GetSourceSampleOffset(ALsource *Source, ALCcontext *context, std::chrono::nanoseconds *clocktime) +{ + ALCdevice *device{context->Device}; + const ALbufferlistitem *Current; + uint64_t readPos; + ALuint refcount; + ALvoice *voice; + + do { + Current = nullptr; + readPos = 0; + while(((refcount=device->MixCount.load(std::memory_order_acquire))&1)) + std::this_thread::yield(); + *clocktime = GetDeviceClockTime(device); + + voice = GetSourceVoice(Source, context); + if(voice) + { + Current = voice->mCurrentBuffer.load(std::memory_order_relaxed); + + readPos = uint64_t{voice->mPosition.load(std::memory_order_relaxed)} << 32; + readPos |= int64_t{voice->mPositionFrac.load(std::memory_order_relaxed)} << + (32-FRACTIONBITS); + } + std::atomic_thread_fence(std::memory_order_acquire); + } while(refcount != device->MixCount.load(std::memory_order_relaxed)); + + if(voice) + { + const ALbufferlistitem *BufferList{Source->queue}; + while(BufferList && BufferList != Current) + { + readPos += int64_t{BufferList->max_samples} << 32; + BufferList = BufferList->next.load(std::memory_order_relaxed); + } + readPos = minu64(readPos, 0x7fffffffffffffff_u64); + } + + return static_cast(readPos); +} + +/* GetSourceSecOffset + * + * Gets the current read offset for the given Source, in seconds. The offset is + * relative to the start of the queue (not the start of the current buffer). + */ +ALdouble GetSourceSecOffset(ALsource *Source, ALCcontext *context, std::chrono::nanoseconds *clocktime) +{ + ALCdevice *device{context->Device}; + const ALbufferlistitem *Current; + uint64_t readPos; + ALuint refcount; + ALvoice *voice; + + do { + Current = nullptr; + readPos = 0; + while(((refcount=device->MixCount.load(std::memory_order_acquire))&1)) + std::this_thread::yield(); + *clocktime = GetDeviceClockTime(device); + + voice = GetSourceVoice(Source, context); + if(voice) + { + Current = voice->mCurrentBuffer.load(std::memory_order_relaxed); + + readPos = uint64_t{voice->mPosition.load(std::memory_order_relaxed)} << FRACTIONBITS; + readPos |= voice->mPositionFrac.load(std::memory_order_relaxed); + } + std::atomic_thread_fence(std::memory_order_acquire); + } while(refcount != device->MixCount.load(std::memory_order_relaxed)); + + ALdouble offset{0.0}; + if(voice) + { + const ALbufferlistitem *BufferList{Source->queue}; + const ALbuffer *BufferFmt{nullptr}; + while(BufferList && BufferList != Current) + { + for(ALsizei i{0};!BufferFmt && i < BufferList->num_buffers;++i) + BufferFmt = BufferList->buffers[i]; + readPos += int64_t{BufferList->max_samples} << FRACTIONBITS; + BufferList = BufferList->next.load(std::memory_order_relaxed); + } + + while(BufferList && !BufferFmt) + { + for(ALsizei i{0};!BufferFmt && i < BufferList->num_buffers;++i) + BufferFmt = BufferList->buffers[i]; + BufferList = BufferList->next.load(std::memory_order_relaxed); + } + assert(BufferFmt != nullptr); + + offset = static_cast(readPos) / static_castFRACTIONONE / + static_cast(BufferFmt->Frequency); + } + + return offset; +} + +/* GetSourceOffset + * + * Gets the current read offset for the given Source, in the appropriate format + * (Bytes, Samples or Seconds). The offset is relative to the start of the + * queue (not the start of the current buffer). + */ +ALdouble GetSourceOffset(ALsource *Source, ALenum name, ALCcontext *context) +{ + ALCdevice *device{context->Device}; + const ALbufferlistitem *Current; + ALuint readPos; + ALsizei readPosFrac; + ALuint refcount; + ALvoice *voice; + + do { + Current = nullptr; + readPos = readPosFrac = 0; + while(((refcount=device->MixCount.load(std::memory_order_acquire))&1)) + std::this_thread::yield(); + voice = GetSourceVoice(Source, context); + if(voice) + { + Current = voice->mCurrentBuffer.load(std::memory_order_relaxed); + + readPos = voice->mPosition.load(std::memory_order_relaxed); + readPosFrac = voice->mPositionFrac.load(std::memory_order_relaxed); + } + std::atomic_thread_fence(std::memory_order_acquire); + } while(refcount != device->MixCount.load(std::memory_order_relaxed)); + + ALdouble offset{0.0}; + if(voice) + { + const ALbufferlistitem *BufferList{Source->queue}; + const ALbuffer *BufferFmt{nullptr}; + ALboolean readFin{AL_FALSE}; + ALuint totalBufferLen{0u}; + + while(BufferList) + { + for(ALsizei i{0};!BufferFmt && i < BufferList->num_buffers;++i) + BufferFmt = BufferList->buffers[i]; + + readFin |= (BufferList == Current); + totalBufferLen += BufferList->max_samples; + if(!readFin) readPos += BufferList->max_samples; + + BufferList = BufferList->next.load(std::memory_order_relaxed); + } + assert(BufferFmt != nullptr); + + if(Source->Looping) + readPos %= totalBufferLen; + else + { + /* Wrap back to 0 */ + if(readPos >= totalBufferLen) + readPos = readPosFrac = 0; + } + + offset = 0.0; + switch(name) + { + case AL_SEC_OFFSET: + offset = (readPos + static_cast(readPosFrac)/FRACTIONONE) / BufferFmt->Frequency; + break; + + case AL_SAMPLE_OFFSET: + offset = readPos + static_cast(readPosFrac)/FRACTIONONE; + break; + + case AL_BYTE_OFFSET: + if(BufferFmt->OriginalType == UserFmtIMA4) + { + ALsizei align = (BufferFmt->OriginalAlign-1)/2 + 4; + ALuint BlockSize = align * ChannelsFromFmt(BufferFmt->mFmtChannels); + ALuint FrameBlockSize = BufferFmt->OriginalAlign; + + /* Round down to nearest ADPCM block */ + offset = static_cast(readPos / FrameBlockSize * BlockSize); + } + else if(BufferFmt->OriginalType == UserFmtMSADPCM) + { + ALsizei align = (BufferFmt->OriginalAlign-2)/2 + 7; + ALuint BlockSize = align * ChannelsFromFmt(BufferFmt->mFmtChannels); + ALuint FrameBlockSize = BufferFmt->OriginalAlign; + + /* Round down to nearest ADPCM block */ + offset = static_cast(readPos / FrameBlockSize * BlockSize); + } + else + { + const ALsizei FrameSize{FrameSizeFromFmt(BufferFmt->mFmtChannels, + BufferFmt->mFmtType)}; + offset = static_cast(readPos * FrameSize); + } + break; + } + } + + return offset; +} + + +/* GetSampleOffset + * + * Retrieves the sample offset into the Source's queue (from the Sample, Byte + * or Second offset supplied by the application). This takes into account the + * fact that the buffer format may have been modifed since. + */ +ALboolean GetSampleOffset(ALsource *Source, ALuint *offset, ALsizei *frac) +{ + const ALbuffer *BufferFmt{nullptr}; + const ALbufferlistitem *BufferList; + + /* Find the first valid Buffer in the Queue */ + BufferList = Source->queue; + while(BufferList) + { + for(ALsizei i{0};i < BufferList->num_buffers && !BufferFmt;i++) + BufferFmt = BufferList->buffers[i]; + if(BufferFmt) break; + BufferList = BufferList->next.load(std::memory_order_relaxed); + } + if(!BufferFmt) + { + Source->OffsetType = AL_NONE; + Source->Offset = 0.0; + return AL_FALSE; + } + + ALdouble dbloff, dblfrac; + switch(Source->OffsetType) + { + case AL_BYTE_OFFSET: + /* Determine the ByteOffset (and ensure it is block aligned) */ + *offset = static_cast(Source->Offset); + if(BufferFmt->OriginalType == UserFmtIMA4) + { + ALsizei align = (BufferFmt->OriginalAlign-1)/2 + 4; + *offset /= align * ChannelsFromFmt(BufferFmt->mFmtChannels); + *offset *= BufferFmt->OriginalAlign; + } + else if(BufferFmt->OriginalType == UserFmtMSADPCM) + { + ALsizei align = (BufferFmt->OriginalAlign-2)/2 + 7; + *offset /= align * ChannelsFromFmt(BufferFmt->mFmtChannels); + *offset *= BufferFmt->OriginalAlign; + } + else + *offset /= FrameSizeFromFmt(BufferFmt->mFmtChannels, BufferFmt->mFmtType); + *frac = 0; + break; + + case AL_SAMPLE_OFFSET: + dblfrac = modf(Source->Offset, &dbloff); + *offset = static_cast(mind(dbloff, std::numeric_limits::max())); + *frac = static_cast(mind(dblfrac*FRACTIONONE, FRACTIONONE-1.0)); + break; + + case AL_SEC_OFFSET: + dblfrac = modf(Source->Offset*BufferFmt->Frequency, &dbloff); + *offset = static_cast(mind(dbloff, std::numeric_limits::max())); + *frac = static_cast(mind(dblfrac*FRACTIONONE, FRACTIONONE-1.0)); + break; + } + Source->OffsetType = AL_NONE; + Source->Offset = 0.0; + + return AL_TRUE; +} + +/* ApplyOffset + * + * Apply the stored playback offset to the Source. This function will update + * the number of buffers "played" given the stored offset. + */ +ALboolean ApplyOffset(ALsource *Source, ALvoice *voice) +{ + /* Get sample frame offset */ + ALuint offset{0u}; + ALsizei frac{0}; + if(!GetSampleOffset(Source, &offset, &frac)) + return AL_FALSE; + + ALuint totalBufferLen{0u}; + ALbufferlistitem *BufferList{Source->queue}; + while(BufferList && totalBufferLen <= offset) + { + if(static_cast(BufferList->max_samples) > offset-totalBufferLen) + { + /* Offset is in this buffer */ + voice->mPosition.store(offset - totalBufferLen, std::memory_order_relaxed); + voice->mPositionFrac.store(frac, std::memory_order_relaxed); + voice->mCurrentBuffer.store(BufferList, std::memory_order_release); + return AL_TRUE; + } + totalBufferLen += BufferList->max_samples; + + BufferList = BufferList->next.load(std::memory_order_relaxed); + } + + /* Offset is out of range of the queue */ + return AL_FALSE; +} + + +ALsource *AllocSource(ALCcontext *context) +{ + ALCdevice *device{context->Device}; + std::lock_guard _{context->SourceLock}; + if(context->NumSources >= device->SourcesMax) + { + alSetError(context, AL_OUT_OF_MEMORY, "Exceeding %u source limit", device->SourcesMax); + return nullptr; + } + auto sublist = std::find_if(context->SourceList.begin(), context->SourceList.end(), + [](const SourceSubList &entry) noexcept -> bool + { return entry.FreeMask != 0; } + ); + auto lidx = static_cast(std::distance(context->SourceList.begin(), sublist)); + ALsource *source; + ALsizei slidx; + if(LIKELY(sublist != context->SourceList.end())) + { + slidx = CTZ64(sublist->FreeMask); + source = sublist->Sources + slidx; + } + else + { + /* Don't allocate so many list entries that the 32-bit ID could + * overflow... + */ + if(UNLIKELY(context->SourceList.size() >= 1<<25)) + { + alSetError(context, AL_OUT_OF_MEMORY, "Too many sources allocated"); + return nullptr; + } + context->SourceList.emplace_back(); + sublist = context->SourceList.end() - 1; + + sublist->FreeMask = ~0_u64; + sublist->Sources = static_cast(al_calloc(16, sizeof(ALsource)*64)); + if(UNLIKELY(!sublist->Sources)) + { + context->SourceList.pop_back(); + alSetError(context, AL_OUT_OF_MEMORY, "Failed to allocate source batch"); + return nullptr; + } + + slidx = 0; + source = sublist->Sources + slidx; + } + + source = new (source) ALsource{device->NumAuxSends}; + + /* Add 1 to avoid source ID 0. */ + source->id = ((lidx<<6) | slidx) + 1; + + context->NumSources += 1; + sublist->FreeMask &= ~(1_u64 << slidx); + + return source; +} + +void FreeSource(ALCcontext *context, ALsource *source) +{ + ALuint id = source->id - 1; + ALsizei lidx = id >> 6; + ALsizei slidx = id & 0x3f; + + ALCdevice *device{context->Device}; + BackendUniqueLock backlock{*device->Backend}; + if(ALvoice *voice{GetSourceVoice(source, context)}) + { + voice->mCurrentBuffer.store(nullptr, std::memory_order_relaxed); + voice->mLoopBuffer.store(nullptr, std::memory_order_relaxed); + voice->mSourceID.store(0u, std::memory_order_relaxed); + std::atomic_thread_fence(std::memory_order_release); + /* Don't set the voice to stopping if it was already stopped or + * stopping. + */ + ALvoice::State oldvstate{ALvoice::Playing}; + voice->mPlayState.compare_exchange_strong(oldvstate, ALvoice::Stopping, + std::memory_order_acq_rel, std::memory_order_acquire); + } + backlock.unlock(); + + al::destroy_at(source); + + context->SourceList[lidx].FreeMask |= 1_u64 << slidx; + context->NumSources--; +} + + +inline ALsource *LookupSource(ALCcontext *context, ALuint id) noexcept +{ + ALuint lidx = (id-1) >> 6; + ALsizei slidx = (id-1) & 0x3f; + + if(UNLIKELY(lidx >= context->SourceList.size())) + return nullptr; + SourceSubList &sublist{context->SourceList[lidx]}; + if(UNLIKELY(sublist.FreeMask & (1_u64 << slidx))) + return nullptr; + return sublist.Sources + slidx; +} + +inline ALbuffer *LookupBuffer(ALCdevice *device, ALuint id) noexcept +{ + ALuint lidx = (id-1) >> 6; + ALsizei slidx = (id-1) & 0x3f; + + if(UNLIKELY(lidx >= device->BufferList.size())) + return nullptr; + BufferSubList &sublist = device->BufferList[lidx]; + if(UNLIKELY(sublist.FreeMask & (1_u64 << slidx))) + return nullptr; + return sublist.Buffers + slidx; +} + +inline ALfilter *LookupFilter(ALCdevice *device, ALuint id) noexcept +{ + ALuint lidx = (id-1) >> 6; + ALsizei slidx = (id-1) & 0x3f; + + if(UNLIKELY(lidx >= device->FilterList.size())) + return nullptr; + FilterSubList &sublist = device->FilterList[lidx]; + if(UNLIKELY(sublist.FreeMask & (1_u64 << slidx))) + return nullptr; + return sublist.Filters + slidx; +} + +inline ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id) noexcept +{ + ALuint lidx = (id-1) >> 6; + ALsizei slidx = (id-1) & 0x3f; + + if(UNLIKELY(lidx >= context->EffectSlotList.size())) + return nullptr; + EffectSlotSubList &sublist{context->EffectSlotList[lidx]}; + if(UNLIKELY(sublist.FreeMask & (1_u64 << slidx))) + return nullptr; + return sublist.EffectSlots + slidx; +} + + +enum SourceProp : ALenum { + srcPitch = AL_PITCH, + srcGain = AL_GAIN, + srcMinGain = AL_MIN_GAIN, + srcMaxGain = AL_MAX_GAIN, + srcMaxDistance = AL_MAX_DISTANCE, + srcRolloffFactor = AL_ROLLOFF_FACTOR, + srcDopplerFactor = AL_DOPPLER_FACTOR, + srcConeOuterGain = AL_CONE_OUTER_GAIN, + srcSecOffset = AL_SEC_OFFSET, + srcSampleOffset = AL_SAMPLE_OFFSET, + srcByteOffset = AL_BYTE_OFFSET, + srcConeInnerAngle = AL_CONE_INNER_ANGLE, + srcConeOuterAngle = AL_CONE_OUTER_ANGLE, + srcRefDistance = AL_REFERENCE_DISTANCE, + + srcPosition = AL_POSITION, + srcVelocity = AL_VELOCITY, + srcDirection = AL_DIRECTION, + + srcSourceRelative = AL_SOURCE_RELATIVE, + srcLooping = AL_LOOPING, + srcBuffer = AL_BUFFER, + srcSourceState = AL_SOURCE_STATE, + srcBuffersQueued = AL_BUFFERS_QUEUED, + srcBuffersProcessed = AL_BUFFERS_PROCESSED, + srcSourceType = AL_SOURCE_TYPE, + + /* ALC_EXT_EFX */ + srcConeOuterGainHF = AL_CONE_OUTER_GAINHF, + srcAirAbsorptionFactor = AL_AIR_ABSORPTION_FACTOR, + srcRoomRolloffFactor = AL_ROOM_ROLLOFF_FACTOR, + srcDirectFilterGainHFAuto = AL_DIRECT_FILTER_GAINHF_AUTO, + srcAuxSendFilterGainAuto = AL_AUXILIARY_SEND_FILTER_GAIN_AUTO, + srcAuxSendFilterGainHFAuto = AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO, + srcDirectFilter = AL_DIRECT_FILTER, + srcAuxSendFilter = AL_AUXILIARY_SEND_FILTER, + + /* AL_SOFT_direct_channels */ + srcDirectChannelsSOFT = AL_DIRECT_CHANNELS_SOFT, + + /* AL_EXT_source_distance_model */ + srcDistanceModel = AL_DISTANCE_MODEL, + + /* AL_SOFT_source_latency */ + srcSampleOffsetLatencySOFT = AL_SAMPLE_OFFSET_LATENCY_SOFT, + srcSecOffsetLatencySOFT = AL_SEC_OFFSET_LATENCY_SOFT, + + /* AL_EXT_STEREO_ANGLES */ + srcAngles = AL_STEREO_ANGLES, + + /* AL_EXT_SOURCE_RADIUS */ + srcRadius = AL_SOURCE_RADIUS, + + /* AL_EXT_BFORMAT */ + srcOrientation = AL_ORIENTATION, + + /* AL_SOFT_source_resampler */ + srcResampler = AL_SOURCE_RESAMPLER_SOFT, + + /* AL_SOFT_source_spatialize */ + srcSpatialize = AL_SOURCE_SPATIALIZE_SOFT, + + /* ALC_SOFT_device_clock */ + srcSampleOffsetClockSOFT = AL_SAMPLE_OFFSET_CLOCK_SOFT, + srcSecOffsetClockSOFT = AL_SEC_OFFSET_CLOCK_SOFT, +}; + +/** + * Returns if the last known state for the source was playing or paused. Does + * not sync with the mixer voice. + */ +inline bool IsPlayingOrPaused(ALsource *source) +{ return source->state == AL_PLAYING || source->state == AL_PAUSED; } + +/** + * Returns an updated source state using the matching voice's status (or lack + * thereof). + */ +inline ALenum GetSourceState(ALsource *source, ALvoice *voice) +{ + if(!voice && source->state == AL_PLAYING) + source->state = AL_STOPPED; + return source->state; +} + +/** + * Returns if the source should specify an update, given the context's + * deferring state and the source's last known state. + */ +inline bool SourceShouldUpdate(ALsource *source, ALCcontext *context) +{ + return !context->DeferUpdates.load(std::memory_order_acquire) && + IsPlayingOrPaused(source); +} + + +/** Can only be called while the mixer is locked! */ +void SendStateChangeEvent(ALCcontext *context, ALuint id, ALenum state) +{ + ALbitfieldSOFT enabledevt{context->EnabledEvts.load(std::memory_order_acquire)}; + if(!(enabledevt&EventType_SourceStateChange)) return; + + /* The mixer may have queued a state change that's not yet been processed, + * and we don't want state change messages to occur out of order, so send + * it through the async queue to ensure proper ordering. + */ + RingBuffer *ring{context->AsyncEvents.get()}; + auto evt_vec = ring->getWriteVector(); + if(evt_vec.first.len < 1) return; + + AsyncEvent *evt{new (evt_vec.first.buf) AsyncEvent{EventType_SourceStateChange}}; + evt->u.srcstate.id = id; + evt->u.srcstate.state = state; + ring->writeAdvance(1); + context->EventSem.post(); +} + + +ALint FloatValsByProp(ALenum prop) +{ + switch(static_cast(prop)) + { + case AL_PITCH: + case AL_GAIN: + case AL_MIN_GAIN: + case AL_MAX_GAIN: + case AL_MAX_DISTANCE: + case AL_ROLLOFF_FACTOR: + case AL_DOPPLER_FACTOR: + case AL_CONE_OUTER_GAIN: + case AL_SEC_OFFSET: + case AL_SAMPLE_OFFSET: + case AL_BYTE_OFFSET: + case AL_CONE_INNER_ANGLE: + case AL_CONE_OUTER_ANGLE: + case AL_REFERENCE_DISTANCE: + case AL_CONE_OUTER_GAINHF: + case AL_AIR_ABSORPTION_FACTOR: + case AL_ROOM_ROLLOFF_FACTOR: + case AL_DIRECT_FILTER_GAINHF_AUTO: + case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: + case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: + case AL_DIRECT_CHANNELS_SOFT: + case AL_DISTANCE_MODEL: + case AL_SOURCE_RELATIVE: + case AL_LOOPING: + case AL_SOURCE_STATE: + case AL_BUFFERS_QUEUED: + case AL_BUFFERS_PROCESSED: + case AL_SOURCE_TYPE: + case AL_SOURCE_RADIUS: + case AL_SOURCE_RESAMPLER_SOFT: + case AL_SOURCE_SPATIALIZE_SOFT: + return 1; + + case AL_STEREO_ANGLES: + return 2; + + case AL_POSITION: + case AL_VELOCITY: + case AL_DIRECTION: + return 3; + + case AL_ORIENTATION: + return 6; + + case AL_SEC_OFFSET_LATENCY_SOFT: + case AL_SEC_OFFSET_CLOCK_SOFT: + break; /* Double only */ + + case AL_BUFFER: + case AL_DIRECT_FILTER: + case AL_AUXILIARY_SEND_FILTER: + break; /* i/i64 only */ + case AL_SAMPLE_OFFSET_LATENCY_SOFT: + case AL_SAMPLE_OFFSET_CLOCK_SOFT: + break; /* i64 only */ + } + return 0; +} +ALint DoubleValsByProp(ALenum prop) +{ + switch(static_cast(prop)) + { + case AL_PITCH: + case AL_GAIN: + case AL_MIN_GAIN: + case AL_MAX_GAIN: + case AL_MAX_DISTANCE: + case AL_ROLLOFF_FACTOR: + case AL_DOPPLER_FACTOR: + case AL_CONE_OUTER_GAIN: + case AL_SEC_OFFSET: + case AL_SAMPLE_OFFSET: + case AL_BYTE_OFFSET: + case AL_CONE_INNER_ANGLE: + case AL_CONE_OUTER_ANGLE: + case AL_REFERENCE_DISTANCE: + case AL_CONE_OUTER_GAINHF: + case AL_AIR_ABSORPTION_FACTOR: + case AL_ROOM_ROLLOFF_FACTOR: + case AL_DIRECT_FILTER_GAINHF_AUTO: + case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: + case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: + case AL_DIRECT_CHANNELS_SOFT: + case AL_DISTANCE_MODEL: + case AL_SOURCE_RELATIVE: + case AL_LOOPING: + case AL_SOURCE_STATE: + case AL_BUFFERS_QUEUED: + case AL_BUFFERS_PROCESSED: + case AL_SOURCE_TYPE: + case AL_SOURCE_RADIUS: + case AL_SOURCE_RESAMPLER_SOFT: + case AL_SOURCE_SPATIALIZE_SOFT: + return 1; + + case AL_SEC_OFFSET_LATENCY_SOFT: + case AL_SEC_OFFSET_CLOCK_SOFT: + case AL_STEREO_ANGLES: + return 2; + + case AL_POSITION: + case AL_VELOCITY: + case AL_DIRECTION: + return 3; + + case AL_ORIENTATION: + return 6; + + case AL_BUFFER: + case AL_DIRECT_FILTER: + case AL_AUXILIARY_SEND_FILTER: + break; /* i/i64 only */ + case AL_SAMPLE_OFFSET_LATENCY_SOFT: + case AL_SAMPLE_OFFSET_CLOCK_SOFT: + break; /* i64 only */ + } + return 0; +} + +ALint IntValsByProp(ALenum prop) +{ + switch(static_cast(prop)) + { + case AL_PITCH: + case AL_GAIN: + case AL_MIN_GAIN: + case AL_MAX_GAIN: + case AL_MAX_DISTANCE: + case AL_ROLLOFF_FACTOR: + case AL_DOPPLER_FACTOR: + case AL_CONE_OUTER_GAIN: + case AL_SEC_OFFSET: + case AL_SAMPLE_OFFSET: + case AL_BYTE_OFFSET: + case AL_CONE_INNER_ANGLE: + case AL_CONE_OUTER_ANGLE: + case AL_REFERENCE_DISTANCE: + case AL_CONE_OUTER_GAINHF: + case AL_AIR_ABSORPTION_FACTOR: + case AL_ROOM_ROLLOFF_FACTOR: + case AL_DIRECT_FILTER_GAINHF_AUTO: + case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: + case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: + case AL_DIRECT_CHANNELS_SOFT: + case AL_DISTANCE_MODEL: + case AL_SOURCE_RELATIVE: + case AL_LOOPING: + case AL_BUFFER: + case AL_SOURCE_STATE: + case AL_BUFFERS_QUEUED: + case AL_BUFFERS_PROCESSED: + case AL_SOURCE_TYPE: + case AL_DIRECT_FILTER: + case AL_SOURCE_RADIUS: + case AL_SOURCE_RESAMPLER_SOFT: + case AL_SOURCE_SPATIALIZE_SOFT: + return 1; + + case AL_POSITION: + case AL_VELOCITY: + case AL_DIRECTION: + case AL_AUXILIARY_SEND_FILTER: + return 3; + + case AL_ORIENTATION: + return 6; + + case AL_SAMPLE_OFFSET_LATENCY_SOFT: + case AL_SAMPLE_OFFSET_CLOCK_SOFT: + break; /* i64 only */ + case AL_SEC_OFFSET_LATENCY_SOFT: + case AL_SEC_OFFSET_CLOCK_SOFT: + break; /* Double only */ + case AL_STEREO_ANGLES: + break; /* Float/double only */ + } + return 0; +} +ALint Int64ValsByProp(ALenum prop) +{ + switch(static_cast(prop)) + { + case AL_PITCH: + case AL_GAIN: + case AL_MIN_GAIN: + case AL_MAX_GAIN: + case AL_MAX_DISTANCE: + case AL_ROLLOFF_FACTOR: + case AL_DOPPLER_FACTOR: + case AL_CONE_OUTER_GAIN: + case AL_SEC_OFFSET: + case AL_SAMPLE_OFFSET: + case AL_BYTE_OFFSET: + case AL_CONE_INNER_ANGLE: + case AL_CONE_OUTER_ANGLE: + case AL_REFERENCE_DISTANCE: + case AL_CONE_OUTER_GAINHF: + case AL_AIR_ABSORPTION_FACTOR: + case AL_ROOM_ROLLOFF_FACTOR: + case AL_DIRECT_FILTER_GAINHF_AUTO: + case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: + case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: + case AL_DIRECT_CHANNELS_SOFT: + case AL_DISTANCE_MODEL: + case AL_SOURCE_RELATIVE: + case AL_LOOPING: + case AL_BUFFER: + case AL_SOURCE_STATE: + case AL_BUFFERS_QUEUED: + case AL_BUFFERS_PROCESSED: + case AL_SOURCE_TYPE: + case AL_DIRECT_FILTER: + case AL_SOURCE_RADIUS: + case AL_SOURCE_RESAMPLER_SOFT: + case AL_SOURCE_SPATIALIZE_SOFT: + return 1; + + case AL_SAMPLE_OFFSET_LATENCY_SOFT: + case AL_SAMPLE_OFFSET_CLOCK_SOFT: + return 2; + + case AL_POSITION: + case AL_VELOCITY: + case AL_DIRECTION: + case AL_AUXILIARY_SEND_FILTER: + return 3; + + case AL_ORIENTATION: + return 6; + + case AL_SEC_OFFSET_LATENCY_SOFT: + case AL_SEC_OFFSET_CLOCK_SOFT: + break; /* Double only */ + case AL_STEREO_ANGLES: + break; /* Float/double only */ + } + return 0; +} + + +ALboolean SetSourcefv(ALsource *Source, ALCcontext *Context, SourceProp prop, const ALfloat *values); +ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const ALint *values); +ALboolean SetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, const ALint64SOFT *values); + +#define CHECKVAL(x) do { \ + if(!(x)) \ + { \ + alSetError(Context, AL_INVALID_VALUE, "Value out of range"); \ + return AL_FALSE; \ + } \ +} while(0) + +void UpdateSourceProps(ALsource *source, ALCcontext *context) +{ + ALvoice *voice; + if(SourceShouldUpdate(source, context) && (voice=GetSourceVoice(source, context)) != nullptr) + UpdateSourceProps(source, voice, context); + else + source->PropsClean.clear(std::memory_order_release); +} + +ALboolean SetSourcefv(ALsource *Source, ALCcontext *Context, SourceProp prop, const ALfloat *values) +{ + ALint ival; + + switch(prop) + { + case AL_SEC_OFFSET_LATENCY_SOFT: + case AL_SEC_OFFSET_CLOCK_SOFT: + /* Query only */ + SETERR_RETURN(Context, AL_INVALID_OPERATION, AL_FALSE, + "Setting read-only source property 0x%04x", prop); + + case AL_PITCH: + CHECKVAL(*values >= 0.0f); + + Source->Pitch = *values; + UpdateSourceProps(Source, Context); + return AL_TRUE; + + case AL_CONE_INNER_ANGLE: + CHECKVAL(*values >= 0.0f && *values <= 360.0f); + + Source->InnerAngle = *values; + UpdateSourceProps(Source, Context); + return AL_TRUE; + + case AL_CONE_OUTER_ANGLE: + CHECKVAL(*values >= 0.0f && *values <= 360.0f); + + Source->OuterAngle = *values; + UpdateSourceProps(Source, Context); + return AL_TRUE; + + case AL_GAIN: + CHECKVAL(*values >= 0.0f); + + Source->Gain = *values; + UpdateSourceProps(Source, Context); + return AL_TRUE; + + case AL_MAX_DISTANCE: + CHECKVAL(*values >= 0.0f); + + Source->MaxDistance = *values; + UpdateSourceProps(Source, Context); + return AL_TRUE; + + case AL_ROLLOFF_FACTOR: + CHECKVAL(*values >= 0.0f); + + Source->RolloffFactor = *values; + UpdateSourceProps(Source, Context); + return AL_TRUE; + + case AL_REFERENCE_DISTANCE: + CHECKVAL(*values >= 0.0f); + + Source->RefDistance = *values; + UpdateSourceProps(Source, Context); + return AL_TRUE; + + case AL_MIN_GAIN: + CHECKVAL(*values >= 0.0f); + + Source->MinGain = *values; + UpdateSourceProps(Source, Context); + return AL_TRUE; + + case AL_MAX_GAIN: + CHECKVAL(*values >= 0.0f); + + Source->MaxGain = *values; + UpdateSourceProps(Source, Context); + return AL_TRUE; + + case AL_CONE_OUTER_GAIN: + CHECKVAL(*values >= 0.0f && *values <= 1.0f); + + Source->OuterGain = *values; + UpdateSourceProps(Source, Context); + return AL_TRUE; + + case AL_CONE_OUTER_GAINHF: + CHECKVAL(*values >= 0.0f && *values <= 1.0f); + + Source->OuterGainHF = *values; + UpdateSourceProps(Source, Context); + return AL_TRUE; + + case AL_AIR_ABSORPTION_FACTOR: + CHECKVAL(*values >= 0.0f && *values <= 10.0f); + + Source->AirAbsorptionFactor = *values; + UpdateSourceProps(Source, Context); + return AL_TRUE; + + case AL_ROOM_ROLLOFF_FACTOR: + CHECKVAL(*values >= 0.0f && *values <= 10.0f); + + Source->RoomRolloffFactor = *values; + UpdateSourceProps(Source, Context); + return AL_TRUE; + + case AL_DOPPLER_FACTOR: + CHECKVAL(*values >= 0.0f && *values <= 1.0f); + + Source->DopplerFactor = *values; + UpdateSourceProps(Source, Context); + return AL_TRUE; + + case AL_SEC_OFFSET: + case AL_SAMPLE_OFFSET: + case AL_BYTE_OFFSET: + CHECKVAL(*values >= 0.0f); + + Source->OffsetType = prop; + Source->Offset = *values; + + if(IsPlayingOrPaused(Source)) + { + ALCdevice *device{Context->Device}; + BackendLockGuard _{*device->Backend}; + /* Double-check that the source is still playing while we have + * the lock. + */ + if(ALvoice *voice{GetSourceVoice(Source, Context)}) + { + if(ApplyOffset(Source, voice) == AL_FALSE) + SETERR_RETURN(Context, AL_INVALID_VALUE, AL_FALSE, "Invalid offset"); + } + } + return AL_TRUE; + + case AL_SOURCE_RADIUS: + CHECKVAL(*values >= 0.0f && std::isfinite(*values)); + + Source->Radius = *values; + UpdateSourceProps(Source, Context); + return AL_TRUE; + + case AL_STEREO_ANGLES: + CHECKVAL(std::isfinite(values[0]) && std::isfinite(values[1])); + + Source->StereoPan[0] = values[0]; + Source->StereoPan[1] = values[1]; + UpdateSourceProps(Source, Context); + return AL_TRUE; + + + case AL_POSITION: + CHECKVAL(std::isfinite(values[0]) && std::isfinite(values[1]) && std::isfinite(values[2])); + + Source->Position[0] = values[0]; + Source->Position[1] = values[1]; + Source->Position[2] = values[2]; + UpdateSourceProps(Source, Context); + return AL_TRUE; + + case AL_VELOCITY: + CHECKVAL(std::isfinite(values[0]) && std::isfinite(values[1]) && std::isfinite(values[2])); + + Source->Velocity[0] = values[0]; + Source->Velocity[1] = values[1]; + Source->Velocity[2] = values[2]; + UpdateSourceProps(Source, Context); + return AL_TRUE; + + case AL_DIRECTION: + CHECKVAL(std::isfinite(values[0]) && std::isfinite(values[1]) && std::isfinite(values[2])); + + Source->Direction[0] = values[0]; + Source->Direction[1] = values[1]; + Source->Direction[2] = values[2]; + UpdateSourceProps(Source, Context); + return AL_TRUE; + + case AL_ORIENTATION: + CHECKVAL(std::isfinite(values[0]) && std::isfinite(values[1]) && std::isfinite(values[2]) && + std::isfinite(values[3]) && std::isfinite(values[4]) && std::isfinite(values[5])); + + Source->OrientAt[0] = values[0]; + Source->OrientAt[1] = values[1]; + Source->OrientAt[2] = values[2]; + Source->OrientUp[0] = values[3]; + Source->OrientUp[1] = values[4]; + Source->OrientUp[2] = values[5]; + UpdateSourceProps(Source, Context); + return AL_TRUE; + + + case AL_SOURCE_RELATIVE: + case AL_LOOPING: + case AL_SOURCE_STATE: + case AL_SOURCE_TYPE: + case AL_DISTANCE_MODEL: + case AL_DIRECT_FILTER_GAINHF_AUTO: + case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: + case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: + case AL_DIRECT_CHANNELS_SOFT: + case AL_SOURCE_RESAMPLER_SOFT: + case AL_SOURCE_SPATIALIZE_SOFT: + ival = static_cast(values[0]); + return SetSourceiv(Source, Context, prop, &ival); + + case AL_BUFFERS_QUEUED: + case AL_BUFFERS_PROCESSED: + ival = static_cast(static_cast(values[0])); + return SetSourceiv(Source, Context, prop, &ival); + + case AL_BUFFER: + case AL_DIRECT_FILTER: + case AL_AUXILIARY_SEND_FILTER: + case AL_SAMPLE_OFFSET_LATENCY_SOFT: + case AL_SAMPLE_OFFSET_CLOCK_SOFT: + break; + } + + ERR("Unexpected property: 0x%04x\n", prop); + SETERR_RETURN(Context, AL_INVALID_ENUM, AL_FALSE, "Invalid source float property 0x%04x", prop); +} + +ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const ALint *values) +{ + ALCdevice *device{Context->Device}; + ALbuffer *buffer{nullptr}; + ALfilter *filter{nullptr}; + ALeffectslot *slot{nullptr}; + ALbufferlistitem *oldlist{nullptr}; + std::unique_lock slotlock; + std::unique_lock filtlock; + std::unique_lock buflock; + ALfloat fvals[6]; + + switch(prop) + { + case AL_SOURCE_STATE: + case AL_SOURCE_TYPE: + case AL_BUFFERS_QUEUED: + case AL_BUFFERS_PROCESSED: + /* Query only */ + SETERR_RETURN(Context, AL_INVALID_OPERATION, AL_FALSE, + "Setting read-only source property 0x%04x", prop); + + case AL_SOURCE_RELATIVE: + CHECKVAL(*values == AL_FALSE || *values == AL_TRUE); + + Source->HeadRelative = static_cast(*values); + UpdateSourceProps(Source, Context); + return AL_TRUE; + + case AL_LOOPING: + CHECKVAL(*values == AL_FALSE || *values == AL_TRUE); + + Source->Looping = static_cast(*values); + if(IsPlayingOrPaused(Source)) + { + ALvoice *voice{GetSourceVoice(Source, Context)}; + if(voice) + { + if(Source->Looping) + voice->mLoopBuffer.store(Source->queue, std::memory_order_release); + else + voice->mLoopBuffer.store(nullptr, std::memory_order_release); + + /* If the source is playing, wait for the current mix to finish + * to ensure it isn't currently looping back or reaching the + * end. + */ + while((device->MixCount.load(std::memory_order_acquire)&1)) + std::this_thread::yield(); + } + } + return AL_TRUE; + + case AL_BUFFER: + buflock = std::unique_lock{device->BufferLock}; + if(!(*values == 0 || (buffer=LookupBuffer(device, *values)) != nullptr)) + SETERR_RETURN(Context, AL_INVALID_VALUE, AL_FALSE, "Invalid buffer ID %u", + *values); + + if(buffer && buffer->MappedAccess != 0 && + !(buffer->MappedAccess&AL_MAP_PERSISTENT_BIT_SOFT)) + SETERR_RETURN(Context, AL_INVALID_OPERATION, AL_FALSE, + "Setting non-persistently mapped buffer %u", buffer->id); + else + { + ALenum state = GetSourceState(Source, GetSourceVoice(Source, Context)); + if(state == AL_PLAYING || state == AL_PAUSED) + SETERR_RETURN(Context, AL_INVALID_OPERATION, AL_FALSE, + "Setting buffer on playing or paused source %u", Source->id); + } + + oldlist = Source->queue; + if(buffer != nullptr) + { + /* Add the selected buffer to a one-item queue */ + auto newlist = static_cast(al_calloc(alignof(void*), + ALbufferlistitem::Sizeof(1u))); + newlist->next.store(nullptr, std::memory_order_relaxed); + newlist->max_samples = buffer->SampleLen; + newlist->num_buffers = 1; + newlist->buffers[0] = buffer; + IncrementRef(&buffer->ref); + + /* Source is now Static */ + Source->SourceType = AL_STATIC; + Source->queue = newlist; + } + else + { + /* Source is now Undetermined */ + Source->SourceType = AL_UNDETERMINED; + Source->queue = nullptr; + } + buflock.unlock(); + + /* Delete all elements in the previous queue */ + while(oldlist != nullptr) + { + ALbufferlistitem *temp{oldlist}; + oldlist = temp->next.load(std::memory_order_relaxed); + + for(ALsizei i{0};i < temp->num_buffers;i++) + { + if(temp->buffers[i]) + DecrementRef(&temp->buffers[i]->ref); + } + al_free(temp); + } + return AL_TRUE; + + case AL_SEC_OFFSET: + case AL_SAMPLE_OFFSET: + case AL_BYTE_OFFSET: + CHECKVAL(*values >= 0); + + Source->OffsetType = prop; + Source->Offset = *values; + + if(IsPlayingOrPaused(Source)) + { + ALCdevice *device{Context->Device}; + BackendLockGuard _{*device->Backend}; + if(ALvoice *voice{GetSourceVoice(Source, Context)}) + { + if(ApplyOffset(Source, voice) == AL_FALSE) + SETERR_RETURN(Context, AL_INVALID_VALUE, AL_FALSE, + "Invalid source offset"); + } + } + return AL_TRUE; + + case AL_DIRECT_FILTER: + filtlock = std::unique_lock{device->FilterLock}; + if(!(*values == 0 || (filter=LookupFilter(device, *values)) != nullptr)) + SETERR_RETURN(Context, AL_INVALID_VALUE, AL_FALSE, "Invalid filter ID %u", + *values); + + if(!filter) + { + Source->Direct.Gain = 1.0f; + Source->Direct.GainHF = 1.0f; + Source->Direct.HFReference = LOWPASSFREQREF; + Source->Direct.GainLF = 1.0f; + Source->Direct.LFReference = HIGHPASSFREQREF; + } + else + { + Source->Direct.Gain = filter->Gain; + Source->Direct.GainHF = filter->GainHF; + Source->Direct.HFReference = filter->HFReference; + Source->Direct.GainLF = filter->GainLF; + Source->Direct.LFReference = filter->LFReference; + } + filtlock.unlock(); + UpdateSourceProps(Source, Context); + return AL_TRUE; + + case AL_DIRECT_FILTER_GAINHF_AUTO: + CHECKVAL(*values == AL_FALSE || *values == AL_TRUE); + + Source->DryGainHFAuto = *values; + UpdateSourceProps(Source, Context); + return AL_TRUE; + + case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: + CHECKVAL(*values == AL_FALSE || *values == AL_TRUE); + + Source->WetGainAuto = *values; + UpdateSourceProps(Source, Context); + return AL_TRUE; + + case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: + CHECKVAL(*values == AL_FALSE || *values == AL_TRUE); + + Source->WetGainHFAuto = *values; + UpdateSourceProps(Source, Context); + return AL_TRUE; + + case AL_DIRECT_CHANNELS_SOFT: + CHECKVAL(*values == AL_FALSE || *values == AL_TRUE); + + Source->DirectChannels = *values; + UpdateSourceProps(Source, Context); + return AL_TRUE; + + case AL_DISTANCE_MODEL: + CHECKVAL(*values == AL_NONE || + *values == AL_INVERSE_DISTANCE || + *values == AL_INVERSE_DISTANCE_CLAMPED || + *values == AL_LINEAR_DISTANCE || + *values == AL_LINEAR_DISTANCE_CLAMPED || + *values == AL_EXPONENT_DISTANCE || + *values == AL_EXPONENT_DISTANCE_CLAMPED); + + Source->mDistanceModel = static_cast(*values); + if(Context->SourceDistanceModel) + UpdateSourceProps(Source, Context); + return AL_TRUE; + + case AL_SOURCE_RESAMPLER_SOFT: + CHECKVAL(*values >= 0 && *values <= ResamplerMax); + + Source->mResampler = static_cast(*values); + UpdateSourceProps(Source, Context); + return AL_TRUE; + + case AL_SOURCE_SPATIALIZE_SOFT: + CHECKVAL(*values >= AL_FALSE && *values <= AL_AUTO_SOFT); + + Source->mSpatialize = static_cast(*values); + UpdateSourceProps(Source, Context); + return AL_TRUE; + + + case AL_AUXILIARY_SEND_FILTER: + slotlock = std::unique_lock{Context->EffectSlotLock}; + if(!(values[0] == 0 || (slot=LookupEffectSlot(Context, values[0])) != nullptr)) + SETERR_RETURN(Context, AL_INVALID_VALUE, AL_FALSE, "Invalid effect ID %u", + values[0]); + if(static_cast(values[1]) >= static_cast(device->NumAuxSends)) + SETERR_RETURN(Context, AL_INVALID_VALUE, AL_FALSE, "Invalid send %u", values[1]); + + filtlock = std::unique_lock{device->FilterLock}; + if(!(values[2] == 0 || (filter=LookupFilter(device, values[2])) != nullptr)) + SETERR_RETURN(Context, AL_INVALID_VALUE, AL_FALSE, "Invalid filter ID %u", + values[2]); + + if(!filter) + { + /* Disable filter */ + Source->Send[values[1]].Gain = 1.0f; + Source->Send[values[1]].GainHF = 1.0f; + Source->Send[values[1]].HFReference = LOWPASSFREQREF; + Source->Send[values[1]].GainLF = 1.0f; + Source->Send[values[1]].LFReference = HIGHPASSFREQREF; + } + else + { + Source->Send[values[1]].Gain = filter->Gain; + Source->Send[values[1]].GainHF = filter->GainHF; + Source->Send[values[1]].HFReference = filter->HFReference; + Source->Send[values[1]].GainLF = filter->GainLF; + Source->Send[values[1]].LFReference = filter->LFReference; + } + filtlock.unlock(); + + if(slot != Source->Send[values[1]].Slot && IsPlayingOrPaused(Source)) + { + /* Add refcount on the new slot, and release the previous slot */ + if(slot) IncrementRef(&slot->ref); + if(Source->Send[values[1]].Slot) + DecrementRef(&Source->Send[values[1]].Slot->ref); + Source->Send[values[1]].Slot = slot; + + /* We must force an update if the auxiliary slot changed on an + * active source, in case the slot is about to be deleted. + */ + ALvoice *voice{GetSourceVoice(Source, Context)}; + if(voice) UpdateSourceProps(Source, voice, Context); + else Source->PropsClean.clear(std::memory_order_release); + } + else + { + if(slot) IncrementRef(&slot->ref); + if(Source->Send[values[1]].Slot) + DecrementRef(&Source->Send[values[1]].Slot->ref); + Source->Send[values[1]].Slot = slot; + UpdateSourceProps(Source, Context); + } + + return AL_TRUE; + + + /* 1x float */ + case AL_CONE_INNER_ANGLE: + case AL_CONE_OUTER_ANGLE: + case AL_PITCH: + case AL_GAIN: + case AL_MIN_GAIN: + case AL_MAX_GAIN: + case AL_REFERENCE_DISTANCE: + case AL_ROLLOFF_FACTOR: + case AL_CONE_OUTER_GAIN: + case AL_MAX_DISTANCE: + case AL_DOPPLER_FACTOR: + case AL_CONE_OUTER_GAINHF: + case AL_AIR_ABSORPTION_FACTOR: + case AL_ROOM_ROLLOFF_FACTOR: + case AL_SOURCE_RADIUS: + fvals[0] = static_cast(*values); + return SetSourcefv(Source, Context, prop, fvals); + + /* 3x float */ + case AL_POSITION: + case AL_VELOCITY: + case AL_DIRECTION: + fvals[0] = static_cast(values[0]); + fvals[1] = static_cast(values[1]); + fvals[2] = static_cast(values[2]); + return SetSourcefv(Source, Context, prop, fvals); + + /* 6x float */ + case AL_ORIENTATION: + fvals[0] = static_cast(values[0]); + fvals[1] = static_cast(values[1]); + fvals[2] = static_cast(values[2]); + fvals[3] = static_cast(values[3]); + fvals[4] = static_cast(values[4]); + fvals[5] = static_cast(values[5]); + return SetSourcefv(Source, Context, prop, fvals); + + case AL_SAMPLE_OFFSET_LATENCY_SOFT: + case AL_SEC_OFFSET_LATENCY_SOFT: + case AL_SEC_OFFSET_CLOCK_SOFT: + case AL_SAMPLE_OFFSET_CLOCK_SOFT: + case AL_STEREO_ANGLES: + break; + } + + ERR("Unexpected property: 0x%04x\n", prop); + SETERR_RETURN(Context, AL_INVALID_ENUM, AL_FALSE, "Invalid source integer property 0x%04x", + prop); +} + +ALboolean SetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, const ALint64SOFT *values) +{ + ALfloat fvals[6]; + ALint ivals[3]; + + switch(prop) + { + case AL_SOURCE_TYPE: + case AL_BUFFERS_QUEUED: + case AL_BUFFERS_PROCESSED: + case AL_SOURCE_STATE: + case AL_SAMPLE_OFFSET_LATENCY_SOFT: + case AL_SAMPLE_OFFSET_CLOCK_SOFT: + /* Query only */ + SETERR_RETURN(Context, AL_INVALID_OPERATION, AL_FALSE, + "Setting read-only source property 0x%04x", prop); + + /* 1x int */ + case AL_SOURCE_RELATIVE: + case AL_LOOPING: + case AL_SEC_OFFSET: + case AL_SAMPLE_OFFSET: + case AL_BYTE_OFFSET: + case AL_DIRECT_FILTER_GAINHF_AUTO: + case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: + case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: + case AL_DIRECT_CHANNELS_SOFT: + case AL_DISTANCE_MODEL: + case AL_SOURCE_RESAMPLER_SOFT: + case AL_SOURCE_SPATIALIZE_SOFT: + CHECKVAL(*values <= INT_MAX && *values >= INT_MIN); + + ivals[0] = static_cast(*values); + return SetSourceiv(Source, Context, prop, ivals); + + /* 1x uint */ + case AL_BUFFER: + case AL_DIRECT_FILTER: + CHECKVAL(*values <= UINT_MAX && *values >= 0); + + ivals[0] = static_cast(*values); + return SetSourceiv(Source, Context, prop, ivals); + + /* 3x uint */ + case AL_AUXILIARY_SEND_FILTER: + CHECKVAL(values[0] <= UINT_MAX && values[0] >= 0 && + values[1] <= UINT_MAX && values[1] >= 0 && + values[2] <= UINT_MAX && values[2] >= 0); + + ivals[0] = static_cast(values[0]); + ivals[1] = static_cast(values[1]); + ivals[2] = static_cast(values[2]); + return SetSourceiv(Source, Context, prop, ivals); + + /* 1x float */ + case AL_CONE_INNER_ANGLE: + case AL_CONE_OUTER_ANGLE: + case AL_PITCH: + case AL_GAIN: + case AL_MIN_GAIN: + case AL_MAX_GAIN: + case AL_REFERENCE_DISTANCE: + case AL_ROLLOFF_FACTOR: + case AL_CONE_OUTER_GAIN: + case AL_MAX_DISTANCE: + case AL_DOPPLER_FACTOR: + case AL_CONE_OUTER_GAINHF: + case AL_AIR_ABSORPTION_FACTOR: + case AL_ROOM_ROLLOFF_FACTOR: + case AL_SOURCE_RADIUS: + fvals[0] = static_cast(*values); + return SetSourcefv(Source, Context, prop, fvals); + + /* 3x float */ + case AL_POSITION: + case AL_VELOCITY: + case AL_DIRECTION: + fvals[0] = static_cast(values[0]); + fvals[1] = static_cast(values[1]); + fvals[2] = static_cast(values[2]); + return SetSourcefv(Source, Context, prop, fvals); + + /* 6x float */ + case AL_ORIENTATION: + fvals[0] = static_cast(values[0]); + fvals[1] = static_cast(values[1]); + fvals[2] = static_cast(values[2]); + fvals[3] = static_cast(values[3]); + fvals[4] = static_cast(values[4]); + fvals[5] = static_cast(values[5]); + return SetSourcefv(Source, Context, prop, fvals); + + case AL_SEC_OFFSET_LATENCY_SOFT: + case AL_SEC_OFFSET_CLOCK_SOFT: + case AL_STEREO_ANGLES: + break; + } + + ERR("Unexpected property: 0x%04x\n", prop); + SETERR_RETURN(Context, AL_INVALID_ENUM, AL_FALSE, "Invalid source integer64 property 0x%04x", + prop); +} + +#undef CHECKVAL + + +ALboolean GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp prop, ALdouble *values); +ALboolean GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, ALint *values); +ALboolean GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, ALint64SOFT *values); + +ALboolean GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp prop, ALdouble *values) +{ + ALCdevice *device{Context->Device}; + ClockLatency clocktime; + std::chrono::nanoseconds srcclock; + ALint ivals[3]; + ALboolean err; + + switch(prop) + { + case AL_GAIN: + *values = Source->Gain; + return AL_TRUE; + + case AL_PITCH: + *values = Source->Pitch; + return AL_TRUE; + + case AL_MAX_DISTANCE: + *values = Source->MaxDistance; + return AL_TRUE; + + case AL_ROLLOFF_FACTOR: + *values = Source->RolloffFactor; + return AL_TRUE; + + case AL_REFERENCE_DISTANCE: + *values = Source->RefDistance; + return AL_TRUE; + + case AL_CONE_INNER_ANGLE: + *values = Source->InnerAngle; + return AL_TRUE; + + case AL_CONE_OUTER_ANGLE: + *values = Source->OuterAngle; + return AL_TRUE; + + case AL_MIN_GAIN: + *values = Source->MinGain; + return AL_TRUE; + + case AL_MAX_GAIN: + *values = Source->MaxGain; + return AL_TRUE; + + case AL_CONE_OUTER_GAIN: + *values = Source->OuterGain; + return AL_TRUE; + + case AL_SEC_OFFSET: + case AL_SAMPLE_OFFSET: + case AL_BYTE_OFFSET: + *values = GetSourceOffset(Source, prop, Context); + return AL_TRUE; + + case AL_CONE_OUTER_GAINHF: + *values = Source->OuterGainHF; + return AL_TRUE; + + case AL_AIR_ABSORPTION_FACTOR: + *values = Source->AirAbsorptionFactor; + return AL_TRUE; + + case AL_ROOM_ROLLOFF_FACTOR: + *values = Source->RoomRolloffFactor; + return AL_TRUE; + + case AL_DOPPLER_FACTOR: + *values = Source->DopplerFactor; + return AL_TRUE; + + case AL_SOURCE_RADIUS: + *values = Source->Radius; + return AL_TRUE; + + case AL_STEREO_ANGLES: + values[0] = Source->StereoPan[0]; + values[1] = Source->StereoPan[1]; + return AL_TRUE; + + case AL_SEC_OFFSET_LATENCY_SOFT: + /* Get the source offset with the clock time first. Then get the + * clock time with the device latency. Order is important. + */ + values[0] = GetSourceSecOffset(Source, Context, &srcclock); + { std::lock_guard _{device->StateLock}; + clocktime = GetClockLatency(device); + } + if(srcclock == clocktime.ClockTime) + values[1] = static_cast(clocktime.Latency.count()) / 1000000000.0; + else + { + /* If the clock time incremented, reduce the latency by that + * much since it's that much closer to the source offset it got + * earlier. + */ + std::chrono::nanoseconds diff = clocktime.ClockTime - srcclock; + values[1] = static_cast((clocktime.Latency - std::min(clocktime.Latency, diff)).count()) / + 1000000000.0; + } + return AL_TRUE; + + case AL_SEC_OFFSET_CLOCK_SOFT: + values[0] = GetSourceSecOffset(Source, Context, &srcclock); + values[1] = srcclock.count() / 1000000000.0; + return AL_TRUE; + + case AL_POSITION: + values[0] = Source->Position[0]; + values[1] = Source->Position[1]; + values[2] = Source->Position[2]; + return AL_TRUE; + + case AL_VELOCITY: + values[0] = Source->Velocity[0]; + values[1] = Source->Velocity[1]; + values[2] = Source->Velocity[2]; + return AL_TRUE; + + case AL_DIRECTION: + values[0] = Source->Direction[0]; + values[1] = Source->Direction[1]; + values[2] = Source->Direction[2]; + return AL_TRUE; + + case AL_ORIENTATION: + values[0] = Source->OrientAt[0]; + values[1] = Source->OrientAt[1]; + values[2] = Source->OrientAt[2]; + values[3] = Source->OrientUp[0]; + values[4] = Source->OrientUp[1]; + values[5] = Source->OrientUp[2]; + return AL_TRUE; + + /* 1x int */ + case AL_SOURCE_RELATIVE: + case AL_LOOPING: + case AL_SOURCE_STATE: + case AL_BUFFERS_QUEUED: + case AL_BUFFERS_PROCESSED: + case AL_SOURCE_TYPE: + case AL_DIRECT_FILTER_GAINHF_AUTO: + case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: + case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: + case AL_DIRECT_CHANNELS_SOFT: + case AL_DISTANCE_MODEL: + case AL_SOURCE_RESAMPLER_SOFT: + case AL_SOURCE_SPATIALIZE_SOFT: + if((err=GetSourceiv(Source, Context, prop, ivals)) != AL_FALSE) + *values = static_cast(ivals[0]); + return err; + + case AL_BUFFER: + case AL_DIRECT_FILTER: + case AL_AUXILIARY_SEND_FILTER: + case AL_SAMPLE_OFFSET_LATENCY_SOFT: + case AL_SAMPLE_OFFSET_CLOCK_SOFT: + break; + } + + ERR("Unexpected property: 0x%04x\n", prop); + SETERR_RETURN(Context, AL_INVALID_ENUM, AL_FALSE, "Invalid source double property 0x%04x", + prop); +} + +ALboolean GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, ALint *values) +{ + ALbufferlistitem *BufferList; + ALdouble dvals[6]; + ALboolean err; + + switch(prop) + { + case AL_SOURCE_RELATIVE: + *values = Source->HeadRelative; + return AL_TRUE; + + case AL_LOOPING: + *values = Source->Looping; + return AL_TRUE; + + case AL_BUFFER: + BufferList = (Source->SourceType == AL_STATIC) ? Source->queue : nullptr; + *values = (BufferList && BufferList->num_buffers >= 1 && BufferList->buffers[0]) ? + BufferList->buffers[0]->id : 0; + return AL_TRUE; + + case AL_SOURCE_STATE: + *values = GetSourceState(Source, GetSourceVoice(Source, Context)); + return AL_TRUE; + + case AL_BUFFERS_QUEUED: + if(!(BufferList=Source->queue)) + *values = 0; + else + { + ALsizei count = 0; + do { + count += BufferList->num_buffers; + BufferList = BufferList->next.load(std::memory_order_relaxed); + } while(BufferList != nullptr); + *values = count; + } + return AL_TRUE; + + case AL_BUFFERS_PROCESSED: + if(Source->Looping || Source->SourceType != AL_STREAMING) + { + /* Buffers on a looping source are in a perpetual state of + * PENDING, so don't report any as PROCESSED */ + *values = 0; + } + else + { + const ALbufferlistitem *BufferList{Source->queue}; + const ALbufferlistitem *Current{nullptr}; + ALsizei played{0}; + + ALvoice *voice{GetSourceVoice(Source, Context)}; + if(voice != nullptr) + Current = voice->mCurrentBuffer.load(std::memory_order_relaxed); + else if(Source->state == AL_INITIAL) + Current = BufferList; + + while(BufferList && BufferList != Current) + { + played += BufferList->num_buffers; + BufferList = BufferList->next.load(std::memory_order_relaxed); + } + *values = played; + } + return AL_TRUE; + + case AL_SOURCE_TYPE: + *values = Source->SourceType; + return AL_TRUE; + + case AL_DIRECT_FILTER_GAINHF_AUTO: + *values = Source->DryGainHFAuto; + return AL_TRUE; + + case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: + *values = Source->WetGainAuto; + return AL_TRUE; + + case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: + *values = Source->WetGainHFAuto; + return AL_TRUE; + + case AL_DIRECT_CHANNELS_SOFT: + *values = Source->DirectChannels; + return AL_TRUE; + + case AL_DISTANCE_MODEL: + *values = static_cast(Source->mDistanceModel); + return AL_TRUE; + + case AL_SOURCE_RESAMPLER_SOFT: + *values = Source->mResampler; + return AL_TRUE; + + case AL_SOURCE_SPATIALIZE_SOFT: + *values = Source->mSpatialize; + return AL_TRUE; + + /* 1x float/double */ + case AL_CONE_INNER_ANGLE: + case AL_CONE_OUTER_ANGLE: + case AL_PITCH: + case AL_GAIN: + case AL_MIN_GAIN: + case AL_MAX_GAIN: + case AL_REFERENCE_DISTANCE: + case AL_ROLLOFF_FACTOR: + case AL_CONE_OUTER_GAIN: + case AL_MAX_DISTANCE: + case AL_SEC_OFFSET: + case AL_SAMPLE_OFFSET: + case AL_BYTE_OFFSET: + case AL_DOPPLER_FACTOR: + case AL_AIR_ABSORPTION_FACTOR: + case AL_ROOM_ROLLOFF_FACTOR: + case AL_CONE_OUTER_GAINHF: + case AL_SOURCE_RADIUS: + if((err=GetSourcedv(Source, Context, prop, dvals)) != AL_FALSE) + *values = static_cast(dvals[0]); + return err; + + /* 3x float/double */ + case AL_POSITION: + case AL_VELOCITY: + case AL_DIRECTION: + if((err=GetSourcedv(Source, Context, prop, dvals)) != AL_FALSE) + { + values[0] = static_cast(dvals[0]); + values[1] = static_cast(dvals[1]); + values[2] = static_cast(dvals[2]); + } + return err; + + /* 6x float/double */ + case AL_ORIENTATION: + if((err=GetSourcedv(Source, Context, prop, dvals)) != AL_FALSE) + { + values[0] = static_cast(dvals[0]); + values[1] = static_cast(dvals[1]); + values[2] = static_cast(dvals[2]); + values[3] = static_cast(dvals[3]); + values[4] = static_cast(dvals[4]); + values[5] = static_cast(dvals[5]); + } + return err; + + case AL_SAMPLE_OFFSET_LATENCY_SOFT: + case AL_SAMPLE_OFFSET_CLOCK_SOFT: + break; /* i64 only */ + case AL_SEC_OFFSET_LATENCY_SOFT: + case AL_SEC_OFFSET_CLOCK_SOFT: + break; /* Double only */ + case AL_STEREO_ANGLES: + break; /* Float/double only */ + + case AL_DIRECT_FILTER: + case AL_AUXILIARY_SEND_FILTER: + break; /* ??? */ + } + + ERR("Unexpected property: 0x%04x\n", prop); + SETERR_RETURN(Context, AL_INVALID_ENUM, AL_FALSE, "Invalid source integer property 0x%04x", + prop); +} + +ALboolean GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, ALint64SOFT *values) +{ + ALCdevice *device = Context->Device; + ClockLatency clocktime; + std::chrono::nanoseconds srcclock; + ALdouble dvals[6]; + ALint ivals[3]; + ALboolean err; + + switch(prop) + { + case AL_SAMPLE_OFFSET_LATENCY_SOFT: + /* Get the source offset with the clock time first. Then get the + * clock time with the device latency. Order is important. + */ + values[0] = GetSourceSampleOffset(Source, Context, &srcclock); + { std::lock_guard _{device->StateLock}; + clocktime = GetClockLatency(device); + } + if(srcclock == clocktime.ClockTime) + values[1] = clocktime.Latency.count(); + else + { + /* If the clock time incremented, reduce the latency by that + * much since it's that much closer to the source offset it got + * earlier. + */ + auto diff = clocktime.ClockTime - srcclock; + values[1] = (clocktime.Latency - std::min(clocktime.Latency, diff)).count(); + } + return AL_TRUE; + + case AL_SAMPLE_OFFSET_CLOCK_SOFT: + values[0] = GetSourceSampleOffset(Source, Context, &srcclock); + values[1] = srcclock.count(); + return AL_TRUE; + + /* 1x float/double */ + case AL_CONE_INNER_ANGLE: + case AL_CONE_OUTER_ANGLE: + case AL_PITCH: + case AL_GAIN: + case AL_MIN_GAIN: + case AL_MAX_GAIN: + case AL_REFERENCE_DISTANCE: + case AL_ROLLOFF_FACTOR: + case AL_CONE_OUTER_GAIN: + case AL_MAX_DISTANCE: + case AL_SEC_OFFSET: + case AL_SAMPLE_OFFSET: + case AL_BYTE_OFFSET: + case AL_DOPPLER_FACTOR: + case AL_AIR_ABSORPTION_FACTOR: + case AL_ROOM_ROLLOFF_FACTOR: + case AL_CONE_OUTER_GAINHF: + case AL_SOURCE_RADIUS: + if((err=GetSourcedv(Source, Context, prop, dvals)) != AL_FALSE) + *values = static_cast(dvals[0]); + return err; + + /* 3x float/double */ + case AL_POSITION: + case AL_VELOCITY: + case AL_DIRECTION: + if((err=GetSourcedv(Source, Context, prop, dvals)) != AL_FALSE) + { + values[0] = static_cast(dvals[0]); + values[1] = static_cast(dvals[1]); + values[2] = static_cast(dvals[2]); + } + return err; + + /* 6x float/double */ + case AL_ORIENTATION: + if((err=GetSourcedv(Source, Context, prop, dvals)) != AL_FALSE) + { + values[0] = static_cast(dvals[0]); + values[1] = static_cast(dvals[1]); + values[2] = static_cast(dvals[2]); + values[3] = static_cast(dvals[3]); + values[4] = static_cast(dvals[4]); + values[5] = static_cast(dvals[5]); + } + return err; + + /* 1x int */ + case AL_SOURCE_RELATIVE: + case AL_LOOPING: + case AL_SOURCE_STATE: + case AL_BUFFERS_QUEUED: + case AL_BUFFERS_PROCESSED: + case AL_SOURCE_TYPE: + case AL_DIRECT_FILTER_GAINHF_AUTO: + case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: + case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: + case AL_DIRECT_CHANNELS_SOFT: + case AL_DISTANCE_MODEL: + case AL_SOURCE_RESAMPLER_SOFT: + case AL_SOURCE_SPATIALIZE_SOFT: + if((err=GetSourceiv(Source, Context, prop, ivals)) != AL_FALSE) + *values = ivals[0]; + return err; + + /* 1x uint */ + case AL_BUFFER: + case AL_DIRECT_FILTER: + if((err=GetSourceiv(Source, Context, prop, ivals)) != AL_FALSE) + *values = static_cast(ivals[0]); + return err; + + /* 3x uint */ + case AL_AUXILIARY_SEND_FILTER: + if((err=GetSourceiv(Source, Context, prop, ivals)) != AL_FALSE) + { + values[0] = static_cast(ivals[0]); + values[1] = static_cast(ivals[1]); + values[2] = static_cast(ivals[2]); + } + return err; + + case AL_SEC_OFFSET_LATENCY_SOFT: + case AL_SEC_OFFSET_CLOCK_SOFT: + break; /* Double only */ + case AL_STEREO_ANGLES: + break; /* Float/double only */ + } + + ERR("Unexpected property: 0x%04x\n", prop); + SETERR_RETURN(Context, AL_INVALID_ENUM, AL_FALSE, "Invalid source integer64 property 0x%04x", + prop); +} + +} // namespace + +AL_API ALvoid AL_APIENTRY alGenSources(ALsizei n, ALuint *sources) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + if(n < 0) + alSetError(context.get(), AL_INVALID_VALUE, "Generating %d sources", n); + else if(n == 1) + { + ALsource *source = AllocSource(context.get()); + if(source) sources[0] = source->id; + } + else + { + al::vector tempids(n); + auto alloc_end = std::find_if_not(tempids.begin(), tempids.end(), + [&context](ALuint &id) -> bool + { + ALsource *source{AllocSource(context.get())}; + if(!source) return false; + id = source->id; + return true; + } + ); + if(alloc_end != tempids.end()) + alDeleteSources(static_cast(std::distance(tempids.begin(), alloc_end)), + tempids.data()); + else + std::copy(tempids.cbegin(), tempids.cend(), sources); + } +} +END_API_FUNC + +AL_API ALvoid AL_APIENTRY alDeleteSources(ALsizei n, const ALuint *sources) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + if(n < 0) + SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Deleting %d sources", n); + + std::lock_guard _{context->SourceLock}; + + /* Check that all Sources are valid */ + const ALuint *sources_end = sources + n; + auto invsrc = std::find_if_not(sources, sources_end, + [&context](ALuint sid) -> bool + { + if(!LookupSource(context.get(), sid)) + { + alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", sid); + return false; + } + return true; + } + ); + if(LIKELY(invsrc == sources_end)) + { + /* All good. Delete source IDs. */ + std::for_each(sources, sources_end, + [&context](ALuint sid) -> void + { + ALsource *src{LookupSource(context.get(), sid)}; + if(src) FreeSource(context.get(), src); + } + ); + } +} +END_API_FUNC + +AL_API ALboolean AL_APIENTRY alIsSource(ALuint source) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(LIKELY(context)) + { + std::lock_guard _{context->SourceLock}; + if(LookupSource(context.get(), source) != nullptr) + return AL_TRUE; + } + return AL_FALSE; +} +END_API_FUNC + + +AL_API ALvoid AL_APIENTRY alSourcef(ALuint source, ALenum param, ALfloat value) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + std::lock_guard _{context->PropLock}; + std::lock_guard __{context->SourceLock}; + ALsource *Source = LookupSource(context.get(), source); + if(UNLIKELY(!Source)) + alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + else if(FloatValsByProp(param) != 1) + alSetError(context.get(), AL_INVALID_ENUM, "Invalid float property 0x%04x", param); + else + SetSourcefv(Source, context.get(), static_cast(param), &value); +} +END_API_FUNC + +AL_API ALvoid AL_APIENTRY alSource3f(ALuint source, ALenum param, ALfloat value1, ALfloat value2, ALfloat value3) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + std::lock_guard _{context->PropLock}; + std::lock_guard __{context->SourceLock}; + ALsource *Source = LookupSource(context.get(), source); + if(UNLIKELY(!Source)) + alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + else if(FloatValsByProp(param) != 3) + alSetError(context.get(), AL_INVALID_ENUM, "Invalid 3-float property 0x%04x", param); + else + { + ALfloat fvals[3] = { value1, value2, value3 }; + SetSourcefv(Source, context.get(), static_cast(param), fvals); + } +} +END_API_FUNC + +AL_API ALvoid AL_APIENTRY alSourcefv(ALuint source, ALenum param, const ALfloat *values) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + std::lock_guard _{context->PropLock}; + std::lock_guard __{context->SourceLock}; + ALsource *Source = LookupSource(context.get(), source); + if(UNLIKELY(!Source)) + alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + else if(!values) + alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + else if(FloatValsByProp(param) < 1) + alSetError(context.get(), AL_INVALID_ENUM, "Invalid float-vector property 0x%04x", param); + else + SetSourcefv(Source, context.get(), static_cast(param), values); +} +END_API_FUNC + + +AL_API ALvoid AL_APIENTRY alSourcedSOFT(ALuint source, ALenum param, ALdouble value) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + std::lock_guard _{context->PropLock}; + std::lock_guard __{context->SourceLock}; + ALsource *Source = LookupSource(context.get(), source); + if(UNLIKELY(!Source)) + alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + else if(DoubleValsByProp(param) != 1) + alSetError(context.get(), AL_INVALID_ENUM, "Invalid double property 0x%04x", param); + else + { + ALfloat fval = static_cast(value); + SetSourcefv(Source, context.get(), static_cast(param), &fval); + } +} +END_API_FUNC + +AL_API ALvoid AL_APIENTRY alSource3dSOFT(ALuint source, ALenum param, ALdouble value1, ALdouble value2, ALdouble value3) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + std::lock_guard _{context->PropLock}; + std::lock_guard __{context->SourceLock}; + ALsource *Source = LookupSource(context.get(), source); + if(UNLIKELY(!Source)) + alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + else if(DoubleValsByProp(param) != 3) + alSetError(context.get(), AL_INVALID_ENUM, "Invalid 3-double property 0x%04x", param); + else { + ALfloat fvals[3] = {static_cast(value1), + static_cast(value2), + static_cast(value3)}; + SetSourcefv(Source, context.get(), static_cast(param), fvals); + } +} +END_API_FUNC + +AL_API ALvoid AL_APIENTRY alSourcedvSOFT(ALuint source, ALenum param, const ALdouble *values) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + std::lock_guard _{context->PropLock}; + std::lock_guard __{context->SourceLock}; + ALsource *Source = LookupSource(context.get(), source); + if(UNLIKELY(!Source)) + alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + else if(!values) + alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + else + { + ALint count{DoubleValsByProp(param)}; + if(count < 1 || count > 6) + alSetError(context.get(), AL_INVALID_ENUM, "Invalid double-vector property 0x%04x", param); + else + { + ALfloat fvals[6]; + ALint i; + + for(i = 0;i < count;i++) + fvals[i] = static_cast(values[i]); + SetSourcefv(Source, context.get(), static_cast(param), fvals); + } + } +} +END_API_FUNC + + +AL_API ALvoid AL_APIENTRY alSourcei(ALuint source, ALenum param, ALint value) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + std::lock_guard _{context->PropLock}; + std::lock_guard __{context->SourceLock}; + ALsource *Source = LookupSource(context.get(), source); + if(UNLIKELY(!Source)) + alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + else if(IntValsByProp(param) != 1) + alSetError(context.get(), AL_INVALID_ENUM, "Invalid integer property 0x%04x", param); + else + SetSourceiv(Source, context.get(), static_cast(param), &value); +} +END_API_FUNC + +AL_API void AL_APIENTRY alSource3i(ALuint source, ALenum param, ALint value1, ALint value2, ALint value3) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + std::lock_guard _{context->PropLock}; + std::lock_guard __{context->SourceLock}; + ALsource *Source = LookupSource(context.get(), source); + if(UNLIKELY(!Source)) + alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + else if(IntValsByProp(param) != 3) + alSetError(context.get(), AL_INVALID_ENUM, "Invalid 3-integer property 0x%04x", param); + else + { + ALint ivals[3] = { value1, value2, value3 }; + SetSourceiv(Source, context.get(), static_cast(param), ivals); + } +} +END_API_FUNC + +AL_API void AL_APIENTRY alSourceiv(ALuint source, ALenum param, const ALint *values) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + std::lock_guard _{context->PropLock}; + std::lock_guard __{context->SourceLock}; + ALsource *Source = LookupSource(context.get(), source); + if(UNLIKELY(!Source)) + alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + else if(!values) + alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + else if(IntValsByProp(param) < 1) + alSetError(context.get(), AL_INVALID_ENUM, "Invalid integer-vector property 0x%04x", param); + else + SetSourceiv(Source, context.get(), static_cast(param), values); +} +END_API_FUNC + + +AL_API ALvoid AL_APIENTRY alSourcei64SOFT(ALuint source, ALenum param, ALint64SOFT value) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + std::lock_guard _{context->PropLock}; + std::lock_guard __{context->SourceLock}; + ALsource *Source{LookupSource(context.get(), source)}; + if(UNLIKELY(!Source)) + alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + else if(Int64ValsByProp(param) != 1) + alSetError(context.get(), AL_INVALID_ENUM, "Invalid integer64 property 0x%04x", param); + else + SetSourcei64v(Source, context.get(), static_cast(param), &value); +} +END_API_FUNC + +AL_API void AL_APIENTRY alSource3i64SOFT(ALuint source, ALenum param, ALint64SOFT value1, ALint64SOFT value2, ALint64SOFT value3) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + std::lock_guard _{context->PropLock}; + std::lock_guard __{context->SourceLock}; + ALsource *Source{LookupSource(context.get(), source)}; + if(UNLIKELY(!Source)) + alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + else if(Int64ValsByProp(param) != 3) + alSetError(context.get(), AL_INVALID_ENUM, "Invalid 3-integer64 property 0x%04x", param); + else + { + ALint64SOFT i64vals[3] = { value1, value2, value3 }; + SetSourcei64v(Source, context.get(), static_cast(param), i64vals); + } +} +END_API_FUNC + +AL_API void AL_APIENTRY alSourcei64vSOFT(ALuint source, ALenum param, const ALint64SOFT *values) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + std::lock_guard _{context->PropLock}; + std::lock_guard __{context->SourceLock}; + ALsource *Source{LookupSource(context.get(), source)}; + if(UNLIKELY(!Source)) + alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + else if(!values) + alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + else if(Int64ValsByProp(param) < 1) + alSetError(context.get(), AL_INVALID_ENUM, "Invalid integer64-vector property 0x%04x", param); + else + SetSourcei64v(Source, context.get(), static_cast(param), values); +} +END_API_FUNC + + +AL_API ALvoid AL_APIENTRY alGetSourcef(ALuint source, ALenum param, ALfloat *value) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + std::lock_guard _{context->SourceLock}; + ALsource *Source{LookupSource(context.get(), source)}; + if(UNLIKELY(!Source)) + alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + else if(!value) + alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + else if(FloatValsByProp(param) != 1) + alSetError(context.get(), AL_INVALID_ENUM, "Invalid float property 0x%04x", param); + else + { + ALdouble dval; + if(GetSourcedv(Source, context.get(), static_cast(param), &dval)) + *value = static_cast(dval); + } +} +END_API_FUNC + +AL_API ALvoid AL_APIENTRY alGetSource3f(ALuint source, ALenum param, ALfloat *value1, ALfloat *value2, ALfloat *value3) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + std::lock_guard _{context->SourceLock}; + ALsource *Source{LookupSource(context.get(), source)}; + if(UNLIKELY(!Source)) + alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + else if(!(value1 && value2 && value3)) + alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + else if(FloatValsByProp(param) != 3) + alSetError(context.get(), AL_INVALID_ENUM, "Invalid 3-float property 0x%04x", param); + else + { + ALdouble dvals[3]; + if(GetSourcedv(Source, context.get(), static_cast(param), dvals)) + { + *value1 = static_cast(dvals[0]); + *value2 = static_cast(dvals[1]); + *value3 = static_cast(dvals[2]); + } + } +} +END_API_FUNC + +AL_API ALvoid AL_APIENTRY alGetSourcefv(ALuint source, ALenum param, ALfloat *values) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + std::lock_guard _{context->SourceLock}; + ALsource *Source{LookupSource(context.get(), source)}; + if(UNLIKELY(!Source)) + alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + else if(!values) + alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + else + { + ALint count{FloatValsByProp(param)}; + if(count < 1 && count > 6) + alSetError(context.get(), AL_INVALID_ENUM, "Invalid float-vector property 0x%04x", param); + else + { + ALdouble dvals[6]; + if(GetSourcedv(Source, context.get(), static_cast(param), dvals)) + { + for(ALint i{0};i < count;i++) + values[i] = static_cast(dvals[i]); + } + } + } +} +END_API_FUNC + + +AL_API void AL_APIENTRY alGetSourcedSOFT(ALuint source, ALenum param, ALdouble *value) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + std::lock_guard _{context->SourceLock}; + ALsource *Source{LookupSource(context.get(), source)}; + if(UNLIKELY(!Source)) + alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + else if(!value) + alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + else if(DoubleValsByProp(param) != 1) + alSetError(context.get(), AL_INVALID_ENUM, "Invalid double property 0x%04x", param); + else + GetSourcedv(Source, context.get(), static_cast(param), value); +} +END_API_FUNC + +AL_API void AL_APIENTRY alGetSource3dSOFT(ALuint source, ALenum param, ALdouble *value1, ALdouble *value2, ALdouble *value3) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + std::lock_guard _{context->SourceLock}; + ALsource *Source{LookupSource(context.get(), source)}; + if(UNLIKELY(!Source)) + alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + else if(!(value1 && value2 && value3)) + alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + else if(DoubleValsByProp(param) != 3) + alSetError(context.get(), AL_INVALID_ENUM, "Invalid 3-double property 0x%04x", param); + else + { + ALdouble dvals[3]; + if(GetSourcedv(Source, context.get(), static_cast(param), dvals)) + { + *value1 = dvals[0]; + *value2 = dvals[1]; + *value3 = dvals[2]; + } + } +} +END_API_FUNC + +AL_API void AL_APIENTRY alGetSourcedvSOFT(ALuint source, ALenum param, ALdouble *values) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + std::lock_guard _{context->SourceLock}; + ALsource *Source{LookupSource(context.get(), source)}; + if(UNLIKELY(!Source)) + alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + else if(!values) + alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + else if(DoubleValsByProp(param) < 1) + alSetError(context.get(), AL_INVALID_ENUM, "Invalid double-vector property 0x%04x", param); + else + GetSourcedv(Source, context.get(), static_cast(param), values); +} +END_API_FUNC + + +AL_API ALvoid AL_APIENTRY alGetSourcei(ALuint source, ALenum param, ALint *value) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + std::lock_guard _{context->SourceLock}; + ALsource *Source{LookupSource(context.get(), source)}; + if(UNLIKELY(!Source)) + alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + else if(!value) + alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + else if(IntValsByProp(param) != 1) + alSetError(context.get(), AL_INVALID_ENUM, "Invalid integer property 0x%04x", param); + else + GetSourceiv(Source, context.get(), static_cast(param), value); +} +END_API_FUNC + +AL_API void AL_APIENTRY alGetSource3i(ALuint source, ALenum param, ALint *value1, ALint *value2, ALint *value3) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + std::lock_guard _{context->SourceLock}; + ALsource *Source{LookupSource(context.get(), source)}; + if(UNLIKELY(!Source)) + alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + else if(!(value1 && value2 && value3)) + alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + else if(IntValsByProp(param) != 3) + alSetError(context.get(), AL_INVALID_ENUM, "Invalid 3-integer property 0x%04x", param); + else + { + ALint ivals[3]; + if(GetSourceiv(Source, context.get(), static_cast(param), ivals)) + { + *value1 = ivals[0]; + *value2 = ivals[1]; + *value3 = ivals[2]; + } + } +} +END_API_FUNC + +AL_API void AL_APIENTRY alGetSourceiv(ALuint source, ALenum param, ALint *values) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + std::lock_guard _{context->SourceLock}; + ALsource *Source{LookupSource(context.get(), source)}; + if(UNLIKELY(!Source)) + alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + else if(!values) + alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + else if(IntValsByProp(param) < 1) + alSetError(context.get(), AL_INVALID_ENUM, "Invalid integer-vector property 0x%04x", param); + else + GetSourceiv(Source, context.get(), static_cast(param), values); +} +END_API_FUNC + + +AL_API void AL_APIENTRY alGetSourcei64SOFT(ALuint source, ALenum param, ALint64SOFT *value) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + std::lock_guard _{context->SourceLock}; + ALsource *Source{LookupSource(context.get(), source)}; + if(UNLIKELY(!Source)) + alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + else if(!value) + alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + else if(Int64ValsByProp(param) != 1) + alSetError(context.get(), AL_INVALID_ENUM, "Invalid integer64 property 0x%04x", param); + else + GetSourcei64v(Source, context.get(), static_cast(param), value); +} +END_API_FUNC + +AL_API void AL_APIENTRY alGetSource3i64SOFT(ALuint source, ALenum param, ALint64SOFT *value1, ALint64SOFT *value2, ALint64SOFT *value3) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + std::lock_guard _{context->SourceLock}; + ALsource *Source{LookupSource(context.get(), source)}; + if(UNLIKELY(!Source)) + alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + else if(!(value1 && value2 && value3)) + alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + else if(Int64ValsByProp(param) != 3) + alSetError(context.get(), AL_INVALID_ENUM, "Invalid 3-integer64 property 0x%04x", param); + else + { + ALint64SOFT i64vals[3]; + if(GetSourcei64v(Source, context.get(), static_cast(param), i64vals)) + { + *value1 = i64vals[0]; + *value2 = i64vals[1]; + *value3 = i64vals[2]; + } + } +} +END_API_FUNC + +AL_API void AL_APIENTRY alGetSourcei64vSOFT(ALuint source, ALenum param, ALint64SOFT *values) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + std::lock_guard _{context->SourceLock}; + ALsource *Source{LookupSource(context.get(), source)}; + if(UNLIKELY(!Source)) + alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + else if(!values) + alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + else if(Int64ValsByProp(param) < 1) + alSetError(context.get(), AL_INVALID_ENUM, "Invalid integer64-vector property 0x%04x", param); + else + GetSourcei64v(Source, context.get(), static_cast(param), values); +} +END_API_FUNC + + +AL_API ALvoid AL_APIENTRY alSourcePlay(ALuint source) +START_API_FUNC +{ alSourcePlayv(1, &source); } +END_API_FUNC + +AL_API ALvoid AL_APIENTRY alSourcePlayv(ALsizei n, const ALuint *sources) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + if(n < 0) + SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Playing %d sources", n); + if(n == 0) return; + + al::vector extra_sources; + std::array source_storage; + ALsource **srchandles{source_storage.data()}; + if(UNLIKELY(static_cast(n) > source_storage.size())) + { + extra_sources.resize(n); + srchandles = extra_sources.data(); + } + + std::lock_guard _{context->SourceLock}; + for(ALsizei i{0};i < n;i++) + { + srchandles[i] = LookupSource(context.get(), sources[i]); + if(!srchandles[i]) + SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid source ID %u", sources[i]); + } + + ALCdevice *device{context->Device}; + BackendLockGuard __{*device->Backend}; + /* If the device is disconnected, go right to stopped. */ + if(UNLIKELY(!device->Connected.load(std::memory_order_acquire))) + { + /* TODO: Send state change event? */ + std::for_each(srchandles, srchandles+n, + [](ALsource *source) -> void + { + source->OffsetType = AL_NONE; + source->Offset = 0.0; + source->state = AL_STOPPED; + } + ); + return; + } + + /* Count the number of reusable voices. */ + auto voices_end = context->Voices->begin() + + context->VoiceCount.load(std::memory_order_relaxed); + auto free_voices = std::accumulate(context->Voices->begin(), voices_end, ALsizei{0}, + [](const ALsizei count, const ALvoice &voice) noexcept -> ALsizei + { + if(voice.mPlayState.load(std::memory_order_acquire) == ALvoice::Stopped && + voice.mSourceID.load(std::memory_order_relaxed) == 0u) + return count + 1; + return count; + } + ); + if(UNLIKELY(n > free_voices)) + { + /* Increment the number of voices to handle the request. */ + const ALuint need_voices{static_cast(n) - free_voices}; + const size_t rem_voices{context->Voices->size() - + context->VoiceCount.load(std::memory_order_relaxed)}; + + if(UNLIKELY(need_voices > rem_voices)) + { + /* Allocate more voices to get enough. */ + const size_t alloc_count{need_voices - rem_voices}; + if(UNLIKELY(context->Voices->size() > std::numeric_limits::max()-alloc_count)) + SETERR_RETURN(context.get(), AL_OUT_OF_MEMORY,, + "Overflow increasing voice count to %zu + %zu", context->Voices->size(), + alloc_count); + + const size_t newcount{context->Voices->size() + alloc_count}; + AllocateVoices(context.get(), newcount); + } + + context->VoiceCount.fetch_add(need_voices, std::memory_order_relaxed); + } + + auto start_source = [&context,device](ALsource *source) -> void + { + /* Check that there is a queue containing at least one valid, non zero + * length buffer. + */ + ALbufferlistitem *BufferList{source->queue}; + while(BufferList && BufferList->max_samples == 0) + BufferList = BufferList->next.load(std::memory_order_relaxed); + + /* If there's nothing to play, go right to stopped. */ + if(UNLIKELY(!BufferList)) + { + /* NOTE: A source without any playable buffers should not have an + * ALvoice since it shouldn't be in a playing or paused state. So + * there's no need to look up its voice and clear the source. + */ + ALenum oldstate{GetSourceState(source, nullptr)}; + source->OffsetType = AL_NONE; + source->Offset = 0.0; + if(oldstate != AL_STOPPED) + { + source->state = AL_STOPPED; + SendStateChangeEvent(context.get(), source->id, AL_STOPPED); + } + return; + } + + ALvoice *voice{GetSourceVoice(source, context.get())}; + switch(GetSourceState(source, voice)) + { + case AL_PLAYING: + assert(voice != nullptr); + /* A source that's already playing is restarted from the beginning. */ + voice->mCurrentBuffer.store(BufferList, std::memory_order_relaxed); + voice->mPosition.store(0u, std::memory_order_relaxed); + voice->mPositionFrac.store(0, std::memory_order_release); + return; + + case AL_PAUSED: + assert(voice != nullptr); + /* A source that's paused simply resumes. */ + voice->mPlayState.store(ALvoice::Playing, std::memory_order_release); + source->state = AL_PLAYING; + SendStateChangeEvent(context.get(), source->id, AL_PLAYING); + return; + + default: + assert(voice == nullptr); + break; + } + + /* Look for an unused voice to play this source with. */ + auto voices_end = context->Voices->begin() + + context->VoiceCount.load(std::memory_order_relaxed); + voice = std::find_if(context->Voices->begin(), voices_end, + [](const ALvoice &voice) noexcept -> bool + { + return voice.mPlayState.load(std::memory_order_acquire) == ALvoice::Stopped && + voice.mSourceID.load(std::memory_order_relaxed) == 0u; + } + ); + assert(voice != voices_end); + auto vidx = static_cast(std::distance(context->Voices->begin(), voice)); + voice->mPlayState.store(ALvoice::Stopped, std::memory_order_release); + + source->PropsClean.test_and_set(std::memory_order_acquire); + UpdateSourceProps(source, voice, context.get()); + + /* A source that's not playing or paused has any offset applied when it + * starts playing. + */ + if(source->Looping) + voice->mLoopBuffer.store(source->queue, std::memory_order_relaxed); + else + voice->mLoopBuffer.store(nullptr, std::memory_order_relaxed); + voice->mCurrentBuffer.store(BufferList, std::memory_order_relaxed); + voice->mPosition.store(0u, std::memory_order_relaxed); + voice->mPositionFrac.store(0, std::memory_order_relaxed); + bool start_fading{false}; + if(ApplyOffset(source, voice) != AL_FALSE) + start_fading = voice->mPosition.load(std::memory_order_relaxed) != 0 || + voice->mPositionFrac.load(std::memory_order_relaxed) != 0 || + voice->mCurrentBuffer.load(std::memory_order_relaxed) != BufferList; + + auto buffers_end = BufferList->buffers + BufferList->num_buffers; + auto buffer = std::find_if(BufferList->buffers, buffers_end, + std::bind(std::not_equal_to{}, _1, nullptr)); + if(buffer != buffers_end) + { + voice->mFrequency = (*buffer)->Frequency; + voice->mFmtChannels = (*buffer)->mFmtChannels; + voice->mNumChannels = ChannelsFromFmt((*buffer)->mFmtChannels); + voice->mSampleSize = BytesFromFmt((*buffer)->mFmtType); + } + + /* Clear the stepping value so the mixer knows not to mix this until + * the update gets applied. + */ + voice->mStep = 0; + + voice->mFlags = start_fading ? VOICE_IS_FADING : 0; + if(source->SourceType == AL_STATIC) voice->mFlags |= VOICE_IS_STATIC; + + /* Don't need to set the VOICE_IS_AMBISONIC flag if the device is + * mixing in first order. No HF scaling is necessary to mix it. + */ + if((voice->mFmtChannels == FmtBFormat2D || voice->mFmtChannels == FmtBFormat3D) && + device->mAmbiOrder > 1) + { + const int *OrderFromChan; + if(voice->mFmtChannels == FmtBFormat2D) + { + static constexpr int Order2DFromChan[MAX_AMBI2D_CHANNELS]{ + 0, 1,1, 2,2, 3,3 + }; + OrderFromChan = Order2DFromChan; + } + else + { + static constexpr int Order3DFromChan[MAX_AMBI_CHANNELS]{ + 0, 1,1,1, 2,2,2,2,2, 3,3,3,3,3,3,3, + }; + OrderFromChan = Order3DFromChan; + } + + BandSplitter splitter{400.0f / static_cast(device->Frequency)}; + + const auto scales = BFormatDec::GetHFOrderScales(1, device->mAmbiOrder); + auto init_ambi = [scales,&OrderFromChan,&splitter](ALvoice::ChannelData &chandata) -> void + { + chandata.mPrevSamples.fill(0.0f); + chandata.mAmbiScale = scales[*(OrderFromChan++)]; + chandata.mAmbiSplitter = splitter; + }; + std::for_each(voice->mChans.begin(), voice->mChans.begin()+voice->mNumChannels, + init_ambi); + + voice->mFlags |= VOICE_IS_AMBISONIC; + } + else + { + /* Clear previous samples. */ + auto clear_prevs = [](ALvoice::ChannelData &chandata) -> void + { chandata.mPrevSamples.fill(0.0f); }; + std::for_each(voice->mChans.begin(), voice->mChans.begin()+voice->mNumChannels, + clear_prevs); + } + + auto clear_params = [device](ALvoice::ChannelData &chandata) -> void + { + chandata.mDryParams = DirectParams{}; + std::fill_n(chandata.mWetParams.begin(), device->NumAuxSends, SendParams{}); + }; + std::for_each(voice->mChans.begin(), voice->mChans.begin()+voice->mNumChannels, + clear_params); + + if(device->AvgSpeakerDist > 0.0f) + { + const ALfloat w1{SPEEDOFSOUNDMETRESPERSEC / + (device->AvgSpeakerDist * device->Frequency)}; + auto init_nfc = [w1](ALvoice::ChannelData &chandata) -> void + { chandata.mDryParams.NFCtrlFilter.init(w1); }; + std::for_each(voice->mChans.begin(), voice->mChans.begin()+voice->mNumChannels, + init_nfc); + } + + voice->mSourceID.store(source->id, std::memory_order_relaxed); + voice->mPlayState.store(ALvoice::Playing, std::memory_order_release); + source->state = AL_PLAYING; + source->VoiceIdx = vidx; + + SendStateChangeEvent(context.get(), source->id, AL_PLAYING); + }; + std::for_each(srchandles, srchandles+n, start_source); +} +END_API_FUNC + + +AL_API ALvoid AL_APIENTRY alSourcePause(ALuint source) +START_API_FUNC +{ alSourcePausev(1, &source); } +END_API_FUNC + +AL_API ALvoid AL_APIENTRY alSourcePausev(ALsizei n, const ALuint *sources) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + if(n < 0) + SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Pausing %d sources", n); + if(n == 0) return; + + al::vector extra_sources; + std::array source_storage; + ALsource **srchandles{source_storage.data()}; + if(UNLIKELY(static_cast(n) > source_storage.size())) + { + extra_sources.resize(n); + srchandles = extra_sources.data(); + } + + std::lock_guard _{context->SourceLock}; + for(ALsizei i{0};i < n;i++) + { + srchandles[i] = LookupSource(context.get(), sources[i]); + if(!srchandles[i]) + SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid source ID %u", sources[i]); + } + + ALCdevice *device{context->Device}; + BackendLockGuard __{*device->Backend}; + auto pause_source = [&context](ALsource *source) -> void + { + ALvoice *voice{GetSourceVoice(source, context.get())}; + if(voice) + { + std::atomic_thread_fence(std::memory_order_release); + ALvoice::State oldvstate{ALvoice::Playing}; + voice->mPlayState.compare_exchange_strong(oldvstate, ALvoice::Stopping, + std::memory_order_acq_rel, std::memory_order_acquire); + } + if(GetSourceState(source, voice) == AL_PLAYING) + { + source->state = AL_PAUSED; + SendStateChangeEvent(context.get(), source->id, AL_PAUSED); + } + }; + std::for_each(srchandles, srchandles+n, pause_source); +} +END_API_FUNC + + +AL_API ALvoid AL_APIENTRY alSourceStop(ALuint source) +START_API_FUNC +{ alSourceStopv(1, &source); } +END_API_FUNC + +AL_API ALvoid AL_APIENTRY alSourceStopv(ALsizei n, const ALuint *sources) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + if(n < 0) + SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Stopping %d sources", n); + if(n == 0) return; + + al::vector extra_sources; + std::array source_storage; + ALsource **srchandles{source_storage.data()}; + if(UNLIKELY(static_cast(n) > source_storage.size())) + { + extra_sources.resize(n); + srchandles = extra_sources.data(); + } + + std::lock_guard _{context->SourceLock}; + for(ALsizei i{0};i < n;i++) + { + srchandles[i] = LookupSource(context.get(), sources[i]); + if(!srchandles[i]) + SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid source ID %u", sources[i]); + } + + ALCdevice *device{context->Device}; + BackendLockGuard __{*device->Backend}; + auto stop_source = [&context](ALsource *source) -> void + { + ALvoice *voice{GetSourceVoice(source, context.get())}; + if(voice != nullptr) + { + voice->mCurrentBuffer.store(nullptr, std::memory_order_relaxed); + voice->mLoopBuffer.store(nullptr, std::memory_order_relaxed); + voice->mSourceID.store(0u, std::memory_order_relaxed); + std::atomic_thread_fence(std::memory_order_release); + ALvoice::State oldvstate{ALvoice::Playing}; + voice->mPlayState.compare_exchange_strong(oldvstate, ALvoice::Stopping, + std::memory_order_acq_rel, std::memory_order_acquire); + voice = nullptr; + } + ALenum oldstate{GetSourceState(source, voice)}; + if(oldstate != AL_INITIAL && oldstate != AL_STOPPED) + { + source->state = AL_STOPPED; + SendStateChangeEvent(context.get(), source->id, AL_STOPPED); + } + source->OffsetType = AL_NONE; + source->Offset = 0.0; + }; + std::for_each(srchandles, srchandles+n, stop_source); +} +END_API_FUNC + + +AL_API ALvoid AL_APIENTRY alSourceRewind(ALuint source) +START_API_FUNC +{ alSourceRewindv(1, &source); } +END_API_FUNC + +AL_API ALvoid AL_APIENTRY alSourceRewindv(ALsizei n, const ALuint *sources) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + if(n < 0) + SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Rewinding %d sources", n); + if(n == 0) return; + + al::vector extra_sources; + std::array source_storage; + ALsource **srchandles{source_storage.data()}; + if(UNLIKELY(static_cast(n) > source_storage.size())) + { + extra_sources.resize(n); + srchandles = extra_sources.data(); + } + + std::lock_guard _{context->SourceLock}; + for(ALsizei i{0};i < n;i++) + { + srchandles[i] = LookupSource(context.get(), sources[i]); + if(!srchandles[i]) + SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid source ID %u", sources[i]); + } + + ALCdevice *device{context->Device}; + BackendLockGuard __{*device->Backend}; + auto rewind_source = [&context](ALsource *source) -> void + { + ALvoice *voice{GetSourceVoice(source, context.get())}; + if(voice != nullptr) + { + voice->mCurrentBuffer.store(nullptr, std::memory_order_relaxed); + voice->mLoopBuffer.store(nullptr, std::memory_order_relaxed); + voice->mSourceID.store(0u, std::memory_order_relaxed); + std::atomic_thread_fence(std::memory_order_release); + ALvoice::State oldvstate{ALvoice::Playing}; + voice->mPlayState.compare_exchange_strong(oldvstate, ALvoice::Stopping, + std::memory_order_acq_rel, std::memory_order_acquire); + voice = nullptr; + } + if(GetSourceState(source, voice) != AL_INITIAL) + { + source->state = AL_INITIAL; + SendStateChangeEvent(context.get(), source->id, AL_INITIAL); + } + source->OffsetType = AL_NONE; + source->Offset = 0.0; + }; + std::for_each(srchandles, srchandles+n, rewind_source); +} +END_API_FUNC + + +AL_API ALvoid AL_APIENTRY alSourceQueueBuffers(ALuint src, ALsizei nb, const ALuint *buffers) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + if(nb < 0) + SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Queueing %d buffers", nb); + if(nb == 0) return; + + std::lock_guard _{context->SourceLock}; + ALsource *source{LookupSource(context.get(),src)}; + if(UNLIKELY(!source)) + SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid source ID %u", src); + + /* Can't queue on a Static Source */ + if(UNLIKELY(source->SourceType == AL_STATIC)) + SETERR_RETURN(context.get(), AL_INVALID_OPERATION,, "Queueing onto static source %u", src); + + /* Check for a valid Buffer, for its frequency and format */ + ALCdevice *device{context->Device}; + ALbuffer *BufferFmt{nullptr}; + ALbufferlistitem *BufferList{source->queue}; + while(BufferList) + { + for(ALsizei i{0};i < BufferList->num_buffers;i++) + { + if((BufferFmt=BufferList->buffers[i]) != nullptr) + break; + } + if(BufferFmt) break; + BufferList = BufferList->next.load(std::memory_order_relaxed); + } + + std::unique_lock buflock{device->BufferLock}; + ALbufferlistitem *BufferListStart{nullptr}; + BufferList = nullptr; + for(ALsizei i{0};i < nb;i++) + { + ALbuffer *buffer{nullptr}; + if(buffers[i] && (buffer=LookupBuffer(device, buffers[i])) == nullptr) + { + alSetError(context.get(), AL_INVALID_NAME, "Queueing invalid buffer ID %u", + buffers[i]); + goto buffer_error; + } + + if(!BufferListStart) + { + BufferListStart = static_cast(al_calloc(alignof(void*), + ALbufferlistitem::Sizeof(1u))); + BufferList = BufferListStart; + } + else + { + auto item = static_cast(al_calloc(alignof(void*), + ALbufferlistitem::Sizeof(1u))); + BufferList->next.store(item, std::memory_order_relaxed); + BufferList = item; + } + BufferList->next.store(nullptr, std::memory_order_relaxed); + BufferList->max_samples = buffer ? buffer->SampleLen : 0; + BufferList->num_buffers = 1; + BufferList->buffers[0] = buffer; + if(!buffer) continue; + + IncrementRef(&buffer->ref); + + if(buffer->MappedAccess != 0 && !(buffer->MappedAccess&AL_MAP_PERSISTENT_BIT_SOFT)) + { + alSetError(context.get(), AL_INVALID_OPERATION, + "Queueing non-persistently mapped buffer %u", buffer->id); + goto buffer_error; + } + + if(BufferFmt == nullptr) + BufferFmt = buffer; + else if(BufferFmt->Frequency != buffer->Frequency || + BufferFmt->mFmtChannels != buffer->mFmtChannels || + BufferFmt->OriginalType != buffer->OriginalType) + { + alSetError(context.get(), AL_INVALID_OPERATION, + "Queueing buffer with mismatched format"); + + buffer_error: + /* A buffer failed (invalid ID or format), so unlock and release + * each buffer we had. */ + while(BufferListStart) + { + ALbufferlistitem *next = BufferListStart->next.load(std::memory_order_relaxed); + for(i = 0;i < BufferListStart->num_buffers;i++) + { + if((buffer=BufferListStart->buffers[i]) != nullptr) + DecrementRef(&buffer->ref); + } + al_free(BufferListStart); + BufferListStart = next; + } + return; + } + } + /* All buffers good. */ + buflock.unlock(); + + /* Source is now streaming */ + source->SourceType = AL_STREAMING; + + if(!(BufferList=source->queue)) + source->queue = BufferListStart; + else + { + ALbufferlistitem *next; + while((next=BufferList->next.load(std::memory_order_relaxed)) != nullptr) + BufferList = next; + BufferList->next.store(BufferListStart, std::memory_order_release); + } +} +END_API_FUNC + +AL_API void AL_APIENTRY alSourceQueueBufferLayersSOFT(ALuint src, ALsizei nb, const ALuint *buffers) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + if(nb < 0) + SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Queueing %d buffer layers", nb); + if(nb == 0) return; + + std::lock_guard _{context->SourceLock}; + ALsource *source{LookupSource(context.get(),src)}; + if(UNLIKELY(!source)) + SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid source ID %u", src); + + /* Can't queue on a Static Source */ + if(UNLIKELY(source->SourceType == AL_STATIC)) + SETERR_RETURN(context.get(), AL_INVALID_OPERATION,, "Queueing onto static source %u", src); + + /* Check for a valid Buffer, for its frequency and format */ + ALCdevice *device{context->Device}; + ALbuffer *BufferFmt{nullptr}; + ALbufferlistitem *BufferList{source->queue}; + while(BufferList) + { + for(ALsizei i{0};i < BufferList->num_buffers;i++) + { + if((BufferFmt=BufferList->buffers[i]) != nullptr) + break; + } + if(BufferFmt) break; + BufferList = BufferList->next.load(std::memory_order_relaxed); + } + + std::unique_lock buflock{device->BufferLock}; + auto BufferListStart = static_cast(al_calloc(alignof(void*), + ALbufferlistitem::Sizeof(nb))); + BufferList = BufferListStart; + BufferList->next.store(nullptr, std::memory_order_relaxed); + BufferList->max_samples = 0; + BufferList->num_buffers = 0; + + for(ALsizei i{0};i < nb;i++) + { + ALbuffer *buffer{nullptr}; + if(buffers[i] && (buffer=LookupBuffer(device, buffers[i])) == nullptr) + { + alSetError(context.get(), AL_INVALID_NAME, "Queueing invalid buffer ID %u", + buffers[i]); + goto buffer_error; + } + + BufferList->buffers[BufferList->num_buffers++] = buffer; + if(!buffer) continue; + + IncrementRef(&buffer->ref); + + BufferList->max_samples = maxi(BufferList->max_samples, buffer->SampleLen); + + if(buffer->MappedAccess != 0 && !(buffer->MappedAccess&AL_MAP_PERSISTENT_BIT_SOFT)) + { + alSetError(context.get(), AL_INVALID_OPERATION, + "Queueing non-persistently mapped buffer %u", buffer->id); + goto buffer_error; + } + + if(BufferFmt == nullptr) + BufferFmt = buffer; + else if(BufferFmt->Frequency != buffer->Frequency || + BufferFmt->mFmtChannels != buffer->mFmtChannels || + BufferFmt->OriginalType != buffer->OriginalType) + { + alSetError(context.get(), AL_INVALID_OPERATION, + "Queueing buffer with mismatched format"); + + buffer_error: + /* A buffer failed (invalid ID or format), so unlock and release + * each buffer we had. */ + while(BufferListStart) + { + ALbufferlistitem *next{BufferListStart->next.load(std::memory_order_relaxed)}; + for(i = 0;i < BufferListStart->num_buffers;i++) + { + if((buffer=BufferListStart->buffers[i]) != nullptr) + DecrementRef(&buffer->ref); + } + al_free(BufferListStart); + BufferListStart = next; + } + return; + } + } + /* All buffers good. */ + buflock.unlock(); + + /* Source is now streaming */ + source->SourceType = AL_STREAMING; + + if(!(BufferList=source->queue)) + source->queue = BufferListStart; + else + { + ALbufferlistitem *next; + while((next=BufferList->next.load(std::memory_order_relaxed)) != nullptr) + BufferList = next; + BufferList->next.store(BufferListStart, std::memory_order_release); + } +} +END_API_FUNC + +AL_API ALvoid AL_APIENTRY alSourceUnqueueBuffers(ALuint src, ALsizei nb, ALuint *buffers) +START_API_FUNC +{ + ContextRef context{GetContextRef()}; + if(UNLIKELY(!context)) return; + + if(nb < 0) + SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Unqueueing %d buffers", nb); + if(nb == 0) return; + + std::lock_guard _{context->SourceLock}; + ALsource *source{LookupSource(context.get(),src)}; + if(UNLIKELY(!source)) + SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid source ID %u", src); + + if(UNLIKELY(source->Looping)) + SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Unqueueing from looping source %u", src); + if(UNLIKELY(source->SourceType != AL_STREAMING)) + SETERR_RETURN(context.get(), AL_INVALID_VALUE,, + "Unqueueing from a non-streaming source %u", src); + + /* Make sure enough buffers have been processed to unqueue. */ + ALbufferlistitem *BufferList{source->queue}; + ALvoice *voice{GetSourceVoice(source, context.get())}; + ALbufferlistitem *Current{nullptr}; + if(voice) + Current = voice->mCurrentBuffer.load(std::memory_order_relaxed); + else if(source->state == AL_INITIAL) + Current = BufferList; + if(UNLIKELY(BufferList == Current)) + SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Unqueueing pending buffers"); + + ALsizei i{BufferList->num_buffers}; + while(i < nb) + { + /* If the next bufferlist to check is NULL or is the current one, it's + * trying to unqueue pending buffers. + */ + ALbufferlistitem *next{BufferList->next.load(std::memory_order_relaxed)}; + if(UNLIKELY(!next) || UNLIKELY(next == Current)) + SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Unqueueing pending buffers"); + BufferList = next; + + i += BufferList->num_buffers; + } + + while(nb > 0) + { + ALbufferlistitem *head{source->queue}; + ALbufferlistitem *next{head->next.load(std::memory_order_relaxed)}; + for(i = 0;i < head->num_buffers && nb > 0;i++,nb--) + { + ALbuffer *buffer{head->buffers[i]}; + if(!buffer) + *(buffers++) = 0; + else + { + *(buffers++) = buffer->id; + DecrementRef(&buffer->ref); + } + } + if(i < head->num_buffers) + { + /* This head has some buffers left over, so move them to the front + * and update the sample and buffer count. + */ + ALsizei max_length{0}; + ALsizei j{0}; + while(i < head->num_buffers) + { + ALbuffer *buffer{head->buffers[i++]}; + if(buffer) max_length = maxi(max_length, buffer->SampleLen); + head->buffers[j++] = buffer; + } + head->max_samples = max_length; + head->num_buffers = j; + break; + } + + /* Otherwise, free this item and set the source queue head to the next + * one. + */ + al_free(head); + source->queue = next; + } +} +END_API_FUNC + + +ALsource::ALsource(ALsizei num_sends) +{ + InnerAngle = 360.0f; + OuterAngle = 360.0f; + Pitch = 1.0f; + Position[0] = 0.0f; + Position[1] = 0.0f; + Position[2] = 0.0f; + Velocity[0] = 0.0f; + Velocity[1] = 0.0f; + Velocity[2] = 0.0f; + Direction[0] = 0.0f; + Direction[1] = 0.0f; + Direction[2] = 0.0f; + OrientAt[0] = 0.0f; + OrientAt[1] = 0.0f; + OrientAt[2] = -1.0f; + OrientUp[0] = 0.0f; + OrientUp[1] = 1.0f; + OrientUp[2] = 0.0f; + RefDistance = 1.0f; + MaxDistance = std::numeric_limits::max(); + RolloffFactor = 1.0f; + Gain = 1.0f; + MinGain = 0.0f; + MaxGain = 1.0f; + OuterGain = 0.0f; + OuterGainHF = 1.0f; + + DryGainHFAuto = AL_TRUE; + WetGainAuto = AL_TRUE; + WetGainHFAuto = AL_TRUE; + AirAbsorptionFactor = 0.0f; + RoomRolloffFactor = 0.0f; + DopplerFactor = 1.0f; + HeadRelative = AL_FALSE; + Looping = AL_FALSE; + mDistanceModel = DistanceModel::Default; + mResampler = ResamplerDefault; + DirectChannels = AL_FALSE; + mSpatialize = SpatializeAuto; + + StereoPan[0] = Deg2Rad( 30.0f); + StereoPan[1] = Deg2Rad(-30.0f); + + Radius = 0.0f; + + Direct.Gain = 1.0f; + Direct.GainHF = 1.0f; + Direct.HFReference = LOWPASSFREQREF; + Direct.GainLF = 1.0f; + Direct.LFReference = HIGHPASSFREQREF; + Send.resize(num_sends); + for(auto &send : Send) + { + send.Slot = nullptr; + send.Gain = 1.0f; + send.GainHF = 1.0f; + send.HFReference = LOWPASSFREQREF; + send.GainLF = 1.0f; + send.LFReference = HIGHPASSFREQREF; + } + + Offset = 0.0; + OffsetType = AL_NONE; + SourceType = AL_UNDETERMINED; + state = AL_INITIAL; + + queue = nullptr; + + PropsClean.test_and_set(std::memory_order_relaxed); + + VoiceIdx = -1; +} + +ALsource::~ALsource() +{ + ALbufferlistitem *BufferList{queue}; + while(BufferList != nullptr) + { + ALbufferlistitem *next{BufferList->next.load(std::memory_order_relaxed)}; + for(ALsizei i{0};i < BufferList->num_buffers;i++) + { + if(BufferList->buffers[i]) + DecrementRef(&BufferList->buffers[i]->ref); + } + al_free(BufferList); + BufferList = next; + } + queue = nullptr; + + std::for_each(Send.begin(), Send.end(), + [](ALsource::SendData &send) -> void + { + if(send.Slot) + DecrementRef(&send.Slot->ref); + send.Slot = nullptr; + } + ); +} + +void UpdateAllSourceProps(ALCcontext *context) +{ + auto voices_end = context->Voices->begin() + + context->VoiceCount.load(std::memory_order_relaxed); + std::for_each(context->Voices->begin(), voices_end, + [context](ALvoice &voice) -> void + { + ALuint sid{voice.mSourceID.load(std::memory_order_acquire)}; + ALsource *source = sid ? LookupSource(context, sid) : nullptr; + if(source && !source->PropsClean.test_and_set(std::memory_order_acq_rel)) + UpdateSourceProps(source, &voice, context); + } + ); +} + +SourceSubList::~SourceSubList() +{ + uint64_t usemask{~FreeMask}; + while(usemask) + { + ALsizei idx{CTZ64(usemask)}; + al::destroy_at(Sources+idx); + usemask &= ~(1_u64 << idx); + } + FreeMask = ~usemask; + al_free(Sources); + Sources = nullptr; +} -- cgit v1.2.3 From ea76e003e7f2063687ed662282d388078ecf385b Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 30 Jul 2019 09:05:54 -0700 Subject: Properly prefix ALCcontext members --- al/auxeffectslot.cpp | 86 +++++++++---------- al/buffer.cpp | 40 ++++----- al/effect.cpp | 22 ++--- al/error.cpp | 16 ++-- al/event.cpp | 50 +++++------ al/extension.cpp | 2 +- al/filter.cpp | 22 ++--- al/listener.cpp | 58 ++++++------- al/source.cpp | 208 ++++++++++++++++++++++----------------------- al/state.cpp | 130 ++++++++++++++-------------- alc/alc.cpp | 158 +++++++++++++++++----------------- alc/alcontext.h | 76 ++++++++--------- alc/alu.cpp | 60 ++++++------- alc/effects/autowah.cpp | 2 +- alc/effects/chorus.cpp | 2 +- alc/effects/distortion.cpp | 2 +- alc/effects/echo.cpp | 2 +- alc/effects/equalizer.cpp | 2 +- alc/effects/fshifter.cpp | 2 +- alc/effects/modulator.cpp | 2 +- alc/effects/reverb.cpp | 4 +- alc/effects/vmorpher.cpp | 2 +- alc/mixvoice.cpp | 14 +-- 23 files changed, 481 insertions(+), 481 deletions(-) (limited to 'al/source.cpp') diff --git a/al/auxeffectslot.cpp b/al/auxeffectslot.cpp index 605923dd..880c970d 100644 --- a/al/auxeffectslot.cpp +++ b/al/auxeffectslot.cpp @@ -54,9 +54,9 @@ inline ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id) noexcept ALuint lidx = (id-1) >> 6; ALsizei slidx = (id-1) & 0x3f; - if(UNLIKELY(lidx >= context->EffectSlotList.size())) + if(UNLIKELY(lidx >= context->mEffectSlotList.size())) return nullptr; - EffectSlotSubList &sublist{context->EffectSlotList[lidx]}; + EffectSlotSubList &sublist{context->mEffectSlotList[lidx]}; if(UNLIKELY(sublist.FreeMask & (1_u64 << slidx))) return nullptr; return sublist.EffectSlots + slidx; @@ -79,7 +79,7 @@ inline ALeffect *LookupEffect(ALCdevice *device, ALuint id) noexcept void AddActiveEffectSlots(const ALuint *slotids, ALsizei count, ALCcontext *context) { if(count < 1) return; - ALeffectslotArray *curarray{context->ActiveAuxSlots.load(std::memory_order_acquire)}; + ALeffectslotArray *curarray{context->mActiveAuxSlots.load(std::memory_order_acquire)}; size_t newcount{curarray->size() + count}; /* Insert the new effect slots into the head of the array, followed by the @@ -114,8 +114,8 @@ void AddActiveEffectSlots(const ALuint *slotids, ALsizei count, ALCcontext *cont curarray = nullptr; } - curarray = context->ActiveAuxSlots.exchange(newarray, std::memory_order_acq_rel); - ALCdevice *device{context->Device}; + curarray = context->mActiveAuxSlots.exchange(newarray, std::memory_order_acq_rel); + ALCdevice *device{context->mDevice}; while((device->MixCount.load(std::memory_order_acquire)&1)) std::this_thread::yield(); delete curarray; @@ -124,7 +124,7 @@ void AddActiveEffectSlots(const ALuint *slotids, ALsizei count, ALCcontext *cont void RemoveActiveEffectSlots(const ALuint *slotids, ALsizei count, ALCcontext *context) { if(count < 1) return; - ALeffectslotArray *curarray{context->ActiveAuxSlots.load(std::memory_order_acquire)}; + ALeffectslotArray *curarray{context->mActiveAuxSlots.load(std::memory_order_acquire)}; /* Don't shrink the allocated array size since we don't know how many (if * any) of the effect slots to remove are in the array. @@ -150,8 +150,8 @@ void RemoveActiveEffectSlots(const ALuint *slotids, ALsizei count, ALCcontext *c curarray = nullptr; } - curarray = context->ActiveAuxSlots.exchange(newarray, std::memory_order_acq_rel); - ALCdevice *device{context->Device}; + curarray = context->mActiveAuxSlots.exchange(newarray, std::memory_order_acq_rel); + ALCdevice *device{context->mDevice}; while((device->MixCount.load(std::memory_order_acquire)&1)) std::this_thread::yield(); delete curarray; @@ -160,22 +160,22 @@ void RemoveActiveEffectSlots(const ALuint *slotids, ALsizei count, ALCcontext *c ALeffectslot *AllocEffectSlot(ALCcontext *context) { - ALCdevice *device{context->Device}; - std::lock_guard _{context->EffectSlotLock}; - if(context->NumEffectSlots >= device->AuxiliaryEffectSlotMax) + ALCdevice *device{context->mDevice}; + std::lock_guard _{context->mEffectSlotLock}; + if(context->mNumEffectSlots >= device->AuxiliaryEffectSlotMax) { alSetError(context, AL_OUT_OF_MEMORY, "Exceeding %u effect slot limit", device->AuxiliaryEffectSlotMax); return nullptr; } - auto sublist = std::find_if(context->EffectSlotList.begin(), context->EffectSlotList.end(), + auto sublist = std::find_if(context->mEffectSlotList.begin(), context->mEffectSlotList.end(), [](const EffectSlotSubList &entry) noexcept -> bool { return entry.FreeMask != 0; } ); - auto lidx = static_cast(std::distance(context->EffectSlotList.begin(), sublist)); + auto lidx = static_cast(std::distance(context->mEffectSlotList.begin(), sublist)); ALeffectslot *slot; ALsizei slidx; - if(LIKELY(sublist != context->EffectSlotList.end())) + if(LIKELY(sublist != context->mEffectSlotList.end())) { slidx = CTZ64(sublist->FreeMask); slot = sublist->EffectSlots + slidx; @@ -185,19 +185,19 @@ ALeffectslot *AllocEffectSlot(ALCcontext *context) /* Don't allocate so many list entries that the 32-bit ID could * overflow... */ - if(UNLIKELY(context->EffectSlotList.size() >= 1<<25)) + if(UNLIKELY(context->mEffectSlotList.size() >= 1<<25)) { alSetError(context, AL_OUT_OF_MEMORY, "Too many effect slots allocated"); return nullptr; } - context->EffectSlotList.emplace_back(); - sublist = context->EffectSlotList.end() - 1; + context->mEffectSlotList.emplace_back(); + sublist = context->mEffectSlotList.end() - 1; sublist->FreeMask = ~0_u64; sublist->EffectSlots = static_cast(al_calloc(16, sizeof(ALeffectslot)*64)); if(UNLIKELY(!sublist->EffectSlots)) { - context->EffectSlotList.pop_back(); + context->mEffectSlotList.pop_back(); alSetError(context, AL_OUT_OF_MEMORY, "Failed to allocate effect slot batch"); return nullptr; } @@ -219,7 +219,7 @@ ALeffectslot *AllocEffectSlot(ALCcontext *context) /* Add 1 to avoid source ID 0. */ slot->id = ((lidx<<6) | slidx) + 1; - context->NumEffectSlots += 1; + context->mNumEffectSlots += 1; sublist->FreeMask &= ~(1_u64 << slidx); return slot; @@ -233,13 +233,13 @@ void FreeEffectSlot(ALCcontext *context, ALeffectslot *slot) al::destroy_at(slot); - context->EffectSlotList[lidx].FreeMask |= 1_u64 << slidx; - context->NumEffectSlots--; + context->mEffectSlotList[lidx].FreeMask |= 1_u64 << slidx; + context->mNumEffectSlots--; } #define DO_UPDATEPROPS() do { \ - if(!context->DeferUpdates.load(std::memory_order_acquire)) \ + if(!context->mDeferUpdates.load(std::memory_order_acquire)) \ UpdateEffectSlotProps(slot, context.get()); \ else \ slot->PropsClean.clear(std::memory_order_release); \ @@ -295,7 +295,7 @@ START_API_FUNC std::copy(tempids.cbegin(), tempids.cend(), effectslots); } - std::unique_lock slotlock{context->EffectSlotLock}; + std::unique_lock slotlock{context->mEffectSlotLock}; AddActiveEffectSlots(effectslots, n, context.get()); } END_API_FUNC @@ -310,7 +310,7 @@ START_API_FUNC SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Deleting %d effect slots", n); if(n == 0) return; - std::lock_guard _{context->EffectSlotLock}; + std::lock_guard _{context->mEffectSlotLock}; auto effectslots_end = effectslots + n; auto bad_slot = std::find_if(effectslots, effectslots_end, [&context](ALuint id) -> bool @@ -350,7 +350,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(LIKELY(context)) { - std::lock_guard _{context->EffectSlotLock}; + std::lock_guard _{context->mEffectSlotLock}; if(LookupEffectSlot(context.get(), effectslot) != nullptr) return AL_TRUE; } @@ -365,8 +365,8 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->PropLock}; - std::lock_guard __{context->EffectSlotLock}; + std::lock_guard _{context->mPropLock}; + std::lock_guard __{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); if(UNLIKELY(!slot)) SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); @@ -377,7 +377,7 @@ START_API_FUNC switch(param) { case AL_EFFECTSLOT_EFFECT: - device = context->Device; + device = context->mDevice; { std::lock_guard ___{device->EffectLock}; ALeffect *effect{value ? LookupEffect(device, value) : nullptr}; @@ -453,7 +453,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->EffectSlotLock}; + std::lock_guard _{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); if(UNLIKELY(!slot)) SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); @@ -473,8 +473,8 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->PropLock}; - std::lock_guard __{context->EffectSlotLock}; + std::lock_guard _{context->mPropLock}; + std::lock_guard __{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); if(UNLIKELY(!slot)) SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); @@ -508,7 +508,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->EffectSlotLock}; + std::lock_guard _{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); if(UNLIKELY(!slot)) SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); @@ -529,7 +529,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->EffectSlotLock}; + std::lock_guard _{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); if(UNLIKELY(!slot)) SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); @@ -566,7 +566,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->EffectSlotLock}; + std::lock_guard _{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); if(UNLIKELY(!slot)) SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); @@ -586,7 +586,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->EffectSlotLock}; + std::lock_guard _{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); if(UNLIKELY(!slot)) SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); @@ -617,7 +617,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->EffectSlotLock}; + std::lock_guard _{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); if(UNLIKELY(!slot)) SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); @@ -647,7 +647,7 @@ ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect if(!State) return AL_OUT_OF_MEMORY; FPUCtl mixer_mode{}; - ALCdevice *Device{Context->Device}; + ALCdevice *Device{Context->mDevice}; std::unique_lock statelock{Device->StateLock}; State->mOutTarget = Device->Dry.Buffer; if(State->deviceUpdate(Device) == AL_FALSE) @@ -677,7 +677,7 @@ ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect EffectSlot->Effect.Props = effect->Props; /* Remove state references from old effect slot property updates. */ - ALeffectslotProps *props{Context->FreeEffectslotProps.load()}; + ALeffectslotProps *props{Context->mFreeEffectslotProps.load()}; while(props) { if(props->State) @@ -739,7 +739,7 @@ ALeffectslot::~ALeffectslot() void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context) { /* Get an unused property container, or allocate a new one as needed. */ - ALeffectslotProps *props{context->FreeEffectslotProps.load(std::memory_order_relaxed)}; + ALeffectslotProps *props{context->mFreeEffectslotProps.load(std::memory_order_relaxed)}; if(!props) props = static_cast(al_calloc(16, sizeof(*props))); else @@ -747,7 +747,7 @@ void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context) ALeffectslotProps *next; do { next = props->next.load(std::memory_order_relaxed); - } while(context->FreeEffectslotProps.compare_exchange_weak(props, next, + } while(context->mFreeEffectslotProps.compare_exchange_weak(props, next, std::memory_order_seq_cst, std::memory_order_acquire) == 0); } @@ -775,7 +775,7 @@ void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context) if(props->State) props->State->DecRef(); props->State = nullptr; - AtomicReplaceHead(context->FreeEffectslotProps, props); + AtomicReplaceHead(context->mFreeEffectslotProps, props); } if(oldstate) @@ -784,8 +784,8 @@ void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context) void UpdateAllEffectSlotProps(ALCcontext *context) { - std::lock_guard _{context->EffectSlotLock}; - ALeffectslotArray *auxslots{context->ActiveAuxSlots.load(std::memory_order_acquire)}; + std::lock_guard _{context->mEffectSlotLock}; + ALeffectslotArray *auxslots{context->mActiveAuxSlots.load(std::memory_order_acquire)}; for(ALeffectslot *slot : *auxslots) { if(!slot->PropsClean.test_and_set(std::memory_order_acq_rel)) diff --git a/al/buffer.cpp b/al/buffer.cpp index 8b9c67e0..d4f2d179 100644 --- a/al/buffer.cpp +++ b/al/buffer.cpp @@ -247,7 +247,7 @@ constexpr ALbitfieldSOFT INVALID_MAP_FLAGS{~unsigned(AL_MAP_READ_BIT_SOFT | AL_M ALbuffer *AllocBuffer(ALCcontext *context) { - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; std::lock_guard _{device->BufferLock}; auto sublist = std::find_if(device->BufferList.begin(), device->BufferList.end(), [](const BufferSubList &entry) noexcept -> bool @@ -657,7 +657,7 @@ START_API_FUNC if(UNLIKELY(n == 0)) return; - ALCdevice *device = context->Device; + ALCdevice *device = context->mDevice; std::lock_guard _{device->BufferLock}; /* First try to find any buffers that are invalid or in-use. */ @@ -700,7 +700,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(LIKELY(context)) { - ALCdevice *device = context->Device; + ALCdevice *device = context->mDevice; std::lock_guard _{device->BufferLock}; if(!buffer || LookupBuffer(device, buffer)) return AL_TRUE; @@ -721,7 +721,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->Device; + ALCdevice *device = context->mDevice; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); @@ -755,7 +755,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return nullptr; - ALCdevice *device = context->Device; + ALCdevice *device = context->mDevice; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); @@ -807,7 +807,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->Device; + ALCdevice *device = context->mDevice; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); @@ -830,7 +830,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->Device; + ALCdevice *device = context->mDevice; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); @@ -862,7 +862,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->Device; + ALCdevice *device = context->mDevice; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); @@ -992,7 +992,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->Device; + ALCdevice *device = context->mDevice; std::lock_guard _{device->BufferLock}; if(UNLIKELY(LookupBuffer(device, buffer) == nullptr)) @@ -1012,7 +1012,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->Device; + ALCdevice *device = context->mDevice; std::lock_guard _{device->BufferLock}; if(UNLIKELY(LookupBuffer(device, buffer) == nullptr)) @@ -1031,7 +1031,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->Device; + ALCdevice *device = context->mDevice; std::lock_guard _{device->BufferLock}; if(UNLIKELY(LookupBuffer(device, buffer) == nullptr)) @@ -1053,7 +1053,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->Device; + ALCdevice *device = context->mDevice; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); @@ -1088,7 +1088,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->Device; + ALCdevice *device = context->mDevice; std::lock_guard _{device->BufferLock}; if(UNLIKELY(LookupBuffer(device, buffer) == nullptr)) @@ -1118,7 +1118,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->Device; + ALCdevice *device = context->mDevice; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); @@ -1156,7 +1156,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->Device; + ALCdevice *device = context->mDevice; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); @@ -1178,7 +1178,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->Device; + ALCdevice *device = context->mDevice; std::lock_guard _{device->BufferLock}; if(UNLIKELY(LookupBuffer(device, buffer) == nullptr)) @@ -1206,7 +1206,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->Device; + ALCdevice *device = context->mDevice; std::lock_guard _{device->BufferLock}; if(UNLIKELY(LookupBuffer(device, buffer) == nullptr)) @@ -1228,7 +1228,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->Device; + ALCdevice *device = context->mDevice; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); if(UNLIKELY(!albuf)) @@ -1273,7 +1273,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->Device; + ALCdevice *device = context->mDevice; std::lock_guard _{device->BufferLock}; if(UNLIKELY(LookupBuffer(device, buffer) == nullptr)) alSetError(context.get(), AL_INVALID_NAME, "Invalid buffer ID %u", buffer); @@ -1308,7 +1308,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->Device; + ALCdevice *device = context->mDevice; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); if(UNLIKELY(!albuf)) diff --git a/al/effect.cpp b/al/effect.cpp index b6cd5463..b6291129 100644 --- a/al/effect.cpp +++ b/al/effect.cpp @@ -139,7 +139,7 @@ void InitEffectParams(ALeffect *effect, ALenum type) ALeffect *AllocEffect(ALCcontext *context) { - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; std::lock_guard _{device->EffectLock}; auto sublist = std::find_if(device->EffectList.begin(), device->EffectList.end(), [](const EffectSubList &entry) noexcept -> bool @@ -270,7 +270,7 @@ START_API_FUNC if(UNLIKELY(n == 0)) return; - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; std::lock_guard _{device->EffectLock}; /* First try to find any effects that are invalid. */ @@ -308,7 +308,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(LIKELY(context)) { - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; std::lock_guard _{device->EffectLock}; if(!effect || LookupEffect(device, effect)) return AL_TRUE; @@ -323,7 +323,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; std::lock_guard _{device->EffectLock}; ALeffect *aleffect{LookupEffect(device, effect)}; @@ -373,7 +373,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; std::lock_guard _{device->EffectLock}; ALeffect *aleffect{LookupEffect(device, effect)}; @@ -393,7 +393,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; std::lock_guard _{device->EffectLock}; ALeffect *aleffect{LookupEffect(device, effect)}; @@ -413,7 +413,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; std::lock_guard _{device->EffectLock}; ALeffect *aleffect{LookupEffect(device, effect)}; @@ -433,7 +433,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; std::lock_guard _{device->EffectLock}; const ALeffect *aleffect{LookupEffect(device, effect)}; @@ -465,7 +465,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; std::lock_guard _{device->EffectLock}; const ALeffect *aleffect{LookupEffect(device, effect)}; @@ -485,7 +485,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; std::lock_guard _{device->EffectLock}; const ALeffect *aleffect{LookupEffect(device, effect)}; @@ -505,7 +505,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; std::lock_guard _{device->EffectLock}; const ALeffect *aleffect{LookupEffect(device, effect)}; diff --git a/al/error.cpp b/al/error.cpp index f5f0801e..f5ec9f52 100644 --- a/al/error.cpp +++ b/al/error.cpp @@ -82,14 +82,14 @@ void alSetError(ALCcontext *context, ALenum errorCode, const char *msg, ...) } ALenum curerr{AL_NO_ERROR}; - context->LastError.compare_exchange_strong(curerr, errorCode); - if((context->EnabledEvts.load(std::memory_order_relaxed)&EventType_Error)) + context->mLastError.compare_exchange_strong(curerr, errorCode); + if((context->mEnabledEvts.load(std::memory_order_relaxed)&EventType_Error)) { - std::lock_guard _{context->EventCbLock}; - ALbitfieldSOFT enabledevts{context->EnabledEvts.load(std::memory_order_relaxed)}; - if((enabledevts&EventType_Error) && context->EventCb) - (*context->EventCb)(AL_EVENT_TYPE_ERROR_SOFT, 0, errorCode, msglen, msg, - context->EventParam); + std::lock_guard _{context->mEventCbLock}; + ALbitfieldSOFT enabledevts{context->mEnabledEvts.load(std::memory_order_relaxed)}; + if((enabledevts&EventType_Error) && context->mEventCb) + (*context->mEventCb)(AL_EVENT_TYPE_ERROR_SOFT, 0, errorCode, msglen, msg, + context->mEventParam); } } @@ -113,6 +113,6 @@ START_API_FUNC return deferror; } - return context->LastError.exchange(AL_NO_ERROR); + return context->mLastError.exchange(AL_NO_ERROR); } END_API_FUNC diff --git a/al/event.cpp b/al/event.cpp index b103d0da..b2710561 100644 --- a/al/event.cpp +++ b/al/event.cpp @@ -31,18 +31,18 @@ static int EventThread(ALCcontext *context) { - RingBuffer *ring{context->AsyncEvents.get()}; + RingBuffer *ring{context->mAsyncEvents.get()}; bool quitnow{false}; while(LIKELY(!quitnow)) { auto evt_data = ring->getReadVector().first; if(evt_data.len == 0) { - context->EventSem.wait(); + context->mEventSem.wait(); continue; } - std::lock_guard _{context->EventCbLock}; + std::lock_guard _{context->mEventCbLock}; do { auto &evt = *reinterpret_cast(evt_data.buf); evt_data.buf += sizeof(AsyncEvent); @@ -69,8 +69,8 @@ static int EventThread(ALCcontext *context) continue; } - ALbitfieldSOFT enabledevts{context->EnabledEvts.load(std::memory_order_acquire)}; - if(!context->EventCb) continue; + ALbitfieldSOFT enabledevts{context->mEnabledEvts.load(std::memory_order_acquire)}; + if(!context->mEventCb) continue; if(evt.EnumType == EventType_SourceStateChange) { @@ -82,9 +82,9 @@ static int EventThread(ALCcontext *context) (evt.u.srcstate.state==AL_PLAYING) ? "AL_PLAYING" : (evt.u.srcstate.state==AL_PAUSED) ? "AL_PAUSED" : (evt.u.srcstate.state==AL_STOPPED) ? "AL_STOPPED" : ""; - context->EventCb(AL_EVENT_TYPE_SOURCE_STATE_CHANGED_SOFT, evt.u.srcstate.id, + context->mEventCb(AL_EVENT_TYPE_SOURCE_STATE_CHANGED_SOFT, evt.u.srcstate.id, evt.u.srcstate.state, static_cast(msg.length()), msg.c_str(), - context->EventParam); + context->mEventParam); } else if(evt.EnumType == EventType_BufferCompleted) { @@ -93,14 +93,14 @@ static int EventThread(ALCcontext *context) std::string msg{std::to_string(evt.u.bufcomp.count)}; if(evt.u.bufcomp.count == 1) msg += " buffer completed"; else msg += " buffers completed"; - context->EventCb(AL_EVENT_TYPE_BUFFER_COMPLETED_SOFT, evt.u.bufcomp.id, + context->mEventCb(AL_EVENT_TYPE_BUFFER_COMPLETED_SOFT, evt.u.bufcomp.id, evt.u.bufcomp.count, static_cast(msg.length()), msg.c_str(), - context->EventParam); + context->mEventParam); } else if((enabledevts&evt.EnumType) == evt.EnumType) - context->EventCb(evt.u.user.type, evt.u.user.id, evt.u.user.param, + context->mEventCb(evt.u.user.type, evt.u.user.id, evt.u.user.param, static_cast(strlen(evt.u.user.msg)), evt.u.user.msg, - context->EventParam); + context->mEventParam); } while(evt_data.len != 0); } return 0; @@ -109,7 +109,7 @@ static int EventThread(ALCcontext *context) void StartEventThrd(ALCcontext *ctx) { try { - ctx->EventThread = std::thread{EventThread, ctx}; + ctx->mEventThread = std::thread{EventThread, ctx}; } catch(std::exception& e) { ERR("Failed to start event thread: %s\n", e.what()); @@ -122,7 +122,7 @@ void StartEventThrd(ALCcontext *ctx) void StopEventThrd(ALCcontext *ctx) { static constexpr AsyncEvent kill_evt{EventType_KillThread}; - RingBuffer *ring{ctx->AsyncEvents.get()}; + RingBuffer *ring{ctx->mAsyncEvents.get()}; auto evt_data = ring->getWriteVector().first; if(evt_data.len == 0) { @@ -134,9 +134,9 @@ void StopEventThrd(ALCcontext *ctx) new (evt_data.buf) AsyncEvent{kill_evt}; ring->writeAdvance(1); - ctx->EventSem.post(); - if(ctx->EventThread.joinable()) - ctx->EventThread.join(); + ctx->mEventSem.post(); + if(ctx->mEventThread.joinable()) + ctx->mEventThread.join(); } AL_API void AL_APIENTRY alEventControlSOFT(ALsizei count, const ALenum *types, ALboolean enable) @@ -176,8 +176,8 @@ START_API_FUNC if(enable) { - ALbitfieldSOFT enabledevts{context->EnabledEvts.load(std::memory_order_relaxed)}; - while(context->EnabledEvts.compare_exchange_weak(enabledevts, enabledevts|flags, + ALbitfieldSOFT enabledevts{context->mEnabledEvts.load(std::memory_order_relaxed)}; + while(context->mEnabledEvts.compare_exchange_weak(enabledevts, enabledevts|flags, std::memory_order_acq_rel, std::memory_order_acquire) == 0) { /* enabledevts is (re-)filled with the current value on failure, so @@ -187,15 +187,15 @@ START_API_FUNC } else { - ALbitfieldSOFT enabledevts{context->EnabledEvts.load(std::memory_order_relaxed)}; - while(context->EnabledEvts.compare_exchange_weak(enabledevts, enabledevts&~flags, + ALbitfieldSOFT enabledevts{context->mEnabledEvts.load(std::memory_order_relaxed)}; + while(context->mEnabledEvts.compare_exchange_weak(enabledevts, enabledevts&~flags, std::memory_order_acq_rel, std::memory_order_acquire) == 0) { } /* Wait to ensure the event handler sees the changed flags before * returning. */ - std::lock_guard{context->EventCbLock}; + std::lock_guard{context->mEventCbLock}; } } END_API_FUNC @@ -206,9 +206,9 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->PropLock}; - std::lock_guard __{context->EventCbLock}; - context->EventCb = callback; - context->EventParam = userParam; + std::lock_guard _{context->mPropLock}; + std::lock_guard __{context->mEventCbLock}; + context->mEventCb = callback; + context->mEventParam = userParam; } END_API_FUNC diff --git a/al/extension.cpp b/al/extension.cpp index e38d4382..c190ad03 100644 --- a/al/extension.cpp +++ b/al/extension.cpp @@ -43,7 +43,7 @@ START_API_FUNC SETERR_RETURN(context.get(), AL_INVALID_VALUE, AL_FALSE, "NULL pointer"); size_t len{strlen(extName)}; - const char *ptr{context->ExtensionList}; + const char *ptr{context->mExtensionList}; while(ptr && *ptr) { if(strncasecmp(ptr, extName, len) == 0 && diff --git a/al/filter.cpp b/al/filter.cpp index 405842f3..d9fce069 100644 --- a/al/filter.cpp +++ b/al/filter.cpp @@ -279,7 +279,7 @@ void InitFilterParams(ALfilter *filter, ALenum type) ALfilter *AllocFilter(ALCcontext *context) { - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; std::lock_guard _{device->FilterLock}; auto sublist = std::find_if(device->FilterList.begin(), device->FilterList.end(), [](const FilterSubList &entry) noexcept -> bool @@ -411,7 +411,7 @@ START_API_FUNC if(UNLIKELY(n == 0)) return; - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; std::lock_guard _{device->FilterLock}; /* First try to find any filters that are invalid. */ @@ -449,7 +449,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(LIKELY(context)) { - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; std::lock_guard _{device->FilterLock}; if(!filter || LookupFilter(device, filter)) return AL_TRUE; @@ -465,7 +465,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; std::lock_guard _{device->FilterLock}; ALfilter *alfilt{LookupFilter(device, filter)}; @@ -503,7 +503,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; std::lock_guard _{device->FilterLock}; ALfilter *alfilt{LookupFilter(device, filter)}; @@ -523,7 +523,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; std::lock_guard _{device->FilterLock}; ALfilter *alfilt{LookupFilter(device, filter)}; @@ -543,7 +543,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; std::lock_guard _{device->FilterLock}; ALfilter *alfilt{LookupFilter(device, filter)}; @@ -563,7 +563,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; std::lock_guard _{device->FilterLock}; ALfilter *alfilt{LookupFilter(device, filter)}; @@ -595,7 +595,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; std::lock_guard _{device->FilterLock}; ALfilter *alfilt{LookupFilter(device, filter)}; @@ -615,7 +615,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; std::lock_guard _{device->FilterLock}; ALfilter *alfilt{LookupFilter(device, filter)}; @@ -635,7 +635,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; std::lock_guard _{device->FilterLock}; ALfilter *alfilt{LookupFilter(device, filter)}; diff --git a/al/listener.cpp b/al/listener.cpp index d67bf072..ba0a7268 100644 --- a/al/listener.cpp +++ b/al/listener.cpp @@ -36,7 +36,7 @@ #define DO_UPDATEPROPS() do { \ - if(!context->DeferUpdates.load(std::memory_order_acquire)) \ + if(!context->mDeferUpdates.load(std::memory_order_acquire)) \ UpdateListenerProps(context.get()); \ else \ listener.PropsClean.clear(std::memory_order_release); \ @@ -49,8 +49,8 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALlistener &listener = context->Listener; - std::lock_guard _{context->PropLock}; + ALlistener &listener = context->mListener; + std::lock_guard _{context->mPropLock}; switch(param) { case AL_GAIN: @@ -64,11 +64,11 @@ START_API_FUNC if(!(value >= AL_MIN_METERS_PER_UNIT && value <= AL_MAX_METERS_PER_UNIT)) SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Listener meters per unit out of range"); - context->MetersPerUnit = value; - if(!context->DeferUpdates.load(std::memory_order_acquire)) + context->mMetersPerUnit = value; + if(!context->mDeferUpdates.load(std::memory_order_acquire)) UpdateContextProps(context.get()); else - context->PropsClean.clear(std::memory_order_release); + context->mPropsClean.clear(std::memory_order_release); break; default: @@ -83,8 +83,8 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALlistener &listener = context->Listener; - std::lock_guard _{context->PropLock}; + ALlistener &listener = context->mListener; + std::lock_guard _{context->mPropLock}; switch(param) { case AL_POSITION: @@ -133,8 +133,8 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALlistener &listener = context->Listener; - std::lock_guard _{context->PropLock}; + ALlistener &listener = context->mListener; + std::lock_guard _{context->mPropLock}; if(!values) SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "NULL pointer"); switch(param) { @@ -165,7 +165,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->PropLock}; + std::lock_guard _{context->mPropLock}; switch(param) { default: @@ -188,7 +188,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->PropLock}; + std::lock_guard _{context->mPropLock}; switch(param) { default: @@ -225,7 +225,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->PropLock}; + std::lock_guard _{context->mPropLock}; if(!values) alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); else switch(param) @@ -243,8 +243,8 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALlistener &listener = context->Listener; - std::lock_guard _{context->PropLock}; + ALlistener &listener = context->mListener; + std::lock_guard _{context->mPropLock}; if(!value) alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); else switch(param) @@ -254,7 +254,7 @@ START_API_FUNC break; case AL_METERS_PER_UNIT: - *value = context->MetersPerUnit; + *value = context->mMetersPerUnit; break; default: @@ -269,8 +269,8 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALlistener &listener = context->Listener; - std::lock_guard _{context->PropLock}; + ALlistener &listener = context->mListener; + std::lock_guard _{context->mPropLock}; if(!value1 || !value2 || !value3) alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); else switch(param) @@ -312,8 +312,8 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALlistener &listener = context->Listener; - std::lock_guard _{context->PropLock}; + ALlistener &listener = context->mListener; + std::lock_guard _{context->mPropLock}; if(!values) alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); else switch(param) @@ -341,7 +341,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->PropLock}; + std::lock_guard _{context->mPropLock}; if(!value) alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); else switch(param) @@ -358,8 +358,8 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALlistener &listener = context->Listener; - std::lock_guard _{context->PropLock}; + ALlistener &listener = context->mListener; + std::lock_guard _{context->mPropLock}; if(!value1 || !value2 || !value3) alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); else switch(param) @@ -396,8 +396,8 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALlistener &listener = context->Listener; - std::lock_guard _{context->PropLock}; + ALlistener &listener = context->mListener; + std::lock_guard _{context->mPropLock}; if(!values) alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); else switch(param) @@ -422,7 +422,7 @@ END_API_FUNC void UpdateListenerProps(ALCcontext *context) { /* Get an unused proprty container, or allocate a new one as needed. */ - ALlistenerProps *props{context->FreeListenerProps.load(std::memory_order_acquire)}; + ALlistenerProps *props{context->mFreeListenerProps.load(std::memory_order_acquire)}; if(!props) props = static_cast(al_calloc(16, sizeof(*props))); else @@ -430,12 +430,12 @@ void UpdateListenerProps(ALCcontext *context) ALlistenerProps *next; do { next = props->next.load(std::memory_order_relaxed); - } while(context->FreeListenerProps.compare_exchange_weak(props, next, + } while(context->mFreeListenerProps.compare_exchange_weak(props, next, std::memory_order_seq_cst, std::memory_order_acquire) == 0); } /* Copy in current property values. */ - ALlistener &listener = context->Listener; + ALlistener &listener = context->mListener; props->Position = listener.Position; props->Velocity = listener.Velocity; props->OrientAt = listener.OrientAt; @@ -449,6 +449,6 @@ void UpdateListenerProps(ALCcontext *context) /* If there was an unused update container, put it back in the * freelist. */ - AtomicReplaceHead(context->FreeListenerProps, props); + AtomicReplaceHead(context->mFreeListenerProps, props); } } diff --git a/al/source.cpp b/al/source.cpp index b4582e6b..39b635a4 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -77,10 +77,10 @@ using namespace std::placeholders; inline ALvoice *GetSourceVoice(ALsource *source, ALCcontext *context) { ALint idx{source->VoiceIdx}; - if(idx >= 0 && static_cast(idx) < context->VoiceCount.load(std::memory_order_relaxed)) + if(idx >= 0 && static_cast(idx) < context->mVoiceCount.load(std::memory_order_relaxed)) { ALuint sid{source->id}; - ALvoice &voice = (*context->Voices)[idx]; + ALvoice &voice = (*context->mVoices)[idx]; if(voice.mSourceID.load(std::memory_order_acquire) == sid) return &voice; } @@ -91,7 +91,7 @@ inline ALvoice *GetSourceVoice(ALsource *source, ALCcontext *context) void UpdateSourceProps(const ALsource *source, ALvoice *voice, ALCcontext *context) { /* Get an unused property container, or allocate a new one as needed. */ - ALvoiceProps *props{context->FreeVoiceProps.load(std::memory_order_acquire)}; + ALvoiceProps *props{context->mFreeVoiceProps.load(std::memory_order_acquire)}; if(!props) props = new ALvoiceProps{}; else @@ -99,7 +99,7 @@ void UpdateSourceProps(const ALsource *source, ALvoice *voice, ALCcontext *conte ALvoiceProps *next; do { next = props->next.load(std::memory_order_relaxed); - } while(context->FreeVoiceProps.compare_exchange_weak(props, next, + } while(context->mFreeVoiceProps.compare_exchange_weak(props, next, std::memory_order_acq_rel, std::memory_order_acquire) == 0); } @@ -164,7 +164,7 @@ void UpdateSourceProps(const ALsource *source, ALvoice *voice, ALCcontext *conte /* If there was an unused update container, put it back in the * freelist. */ - AtomicReplaceHead(context->FreeVoiceProps, props); + AtomicReplaceHead(context->mFreeVoiceProps, props); } } @@ -176,7 +176,7 @@ void UpdateSourceProps(const ALsource *source, ALvoice *voice, ALCcontext *conte */ int64_t GetSourceSampleOffset(ALsource *Source, ALCcontext *context, std::chrono::nanoseconds *clocktime) { - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; const ALbufferlistitem *Current; uint64_t readPos; ALuint refcount; @@ -222,7 +222,7 @@ int64_t GetSourceSampleOffset(ALsource *Source, ALCcontext *context, std::chrono */ ALdouble GetSourceSecOffset(ALsource *Source, ALCcontext *context, std::chrono::nanoseconds *clocktime) { - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; const ALbufferlistitem *Current; uint64_t readPos; ALuint refcount; @@ -282,7 +282,7 @@ ALdouble GetSourceSecOffset(ALsource *Source, ALCcontext *context, std::chrono:: */ ALdouble GetSourceOffset(ALsource *Source, ALenum name, ALCcontext *context) { - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; const ALbufferlistitem *Current; ALuint readPos; ALsizei readPosFrac; @@ -484,21 +484,21 @@ ALboolean ApplyOffset(ALsource *Source, ALvoice *voice) ALsource *AllocSource(ALCcontext *context) { - ALCdevice *device{context->Device}; - std::lock_guard _{context->SourceLock}; - if(context->NumSources >= device->SourcesMax) + ALCdevice *device{context->mDevice}; + std::lock_guard _{context->mSourceLock}; + if(context->mNumSources >= device->SourcesMax) { alSetError(context, AL_OUT_OF_MEMORY, "Exceeding %u source limit", device->SourcesMax); return nullptr; } - auto sublist = std::find_if(context->SourceList.begin(), context->SourceList.end(), + auto sublist = std::find_if(context->mSourceList.begin(), context->mSourceList.end(), [](const SourceSubList &entry) noexcept -> bool { return entry.FreeMask != 0; } ); - auto lidx = static_cast(std::distance(context->SourceList.begin(), sublist)); + auto lidx = static_cast(std::distance(context->mSourceList.begin(), sublist)); ALsource *source; ALsizei slidx; - if(LIKELY(sublist != context->SourceList.end())) + if(LIKELY(sublist != context->mSourceList.end())) { slidx = CTZ64(sublist->FreeMask); source = sublist->Sources + slidx; @@ -508,19 +508,19 @@ ALsource *AllocSource(ALCcontext *context) /* Don't allocate so many list entries that the 32-bit ID could * overflow... */ - if(UNLIKELY(context->SourceList.size() >= 1<<25)) + if(UNLIKELY(context->mSourceList.size() >= 1<<25)) { alSetError(context, AL_OUT_OF_MEMORY, "Too many sources allocated"); return nullptr; } - context->SourceList.emplace_back(); - sublist = context->SourceList.end() - 1; + context->mSourceList.emplace_back(); + sublist = context->mSourceList.end() - 1; sublist->FreeMask = ~0_u64; sublist->Sources = static_cast(al_calloc(16, sizeof(ALsource)*64)); if(UNLIKELY(!sublist->Sources)) { - context->SourceList.pop_back(); + context->mSourceList.pop_back(); alSetError(context, AL_OUT_OF_MEMORY, "Failed to allocate source batch"); return nullptr; } @@ -534,7 +534,7 @@ ALsource *AllocSource(ALCcontext *context) /* Add 1 to avoid source ID 0. */ source->id = ((lidx<<6) | slidx) + 1; - context->NumSources += 1; + context->mNumSources += 1; sublist->FreeMask &= ~(1_u64 << slidx); return source; @@ -546,7 +546,7 @@ void FreeSource(ALCcontext *context, ALsource *source) ALsizei lidx = id >> 6; ALsizei slidx = id & 0x3f; - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; BackendUniqueLock backlock{*device->Backend}; if(ALvoice *voice{GetSourceVoice(source, context)}) { @@ -565,8 +565,8 @@ void FreeSource(ALCcontext *context, ALsource *source) al::destroy_at(source); - context->SourceList[lidx].FreeMask |= 1_u64 << slidx; - context->NumSources--; + context->mSourceList[lidx].FreeMask |= 1_u64 << slidx; + context->mNumSources--; } @@ -575,9 +575,9 @@ inline ALsource *LookupSource(ALCcontext *context, ALuint id) noexcept ALuint lidx = (id-1) >> 6; ALsizei slidx = (id-1) & 0x3f; - if(UNLIKELY(lidx >= context->SourceList.size())) + if(UNLIKELY(lidx >= context->mSourceList.size())) return nullptr; - SourceSubList &sublist{context->SourceList[lidx]}; + SourceSubList &sublist{context->mSourceList[lidx]}; if(UNLIKELY(sublist.FreeMask & (1_u64 << slidx))) return nullptr; return sublist.Sources + slidx; @@ -614,9 +614,9 @@ inline ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id) noexcept ALuint lidx = (id-1) >> 6; ALsizei slidx = (id-1) & 0x3f; - if(UNLIKELY(lidx >= context->EffectSlotList.size())) + if(UNLIKELY(lidx >= context->mEffectSlotList.size())) return nullptr; - EffectSlotSubList &sublist{context->EffectSlotList[lidx]}; + EffectSlotSubList &sublist{context->mEffectSlotList[lidx]}; if(UNLIKELY(sublist.FreeMask & (1_u64 << slidx))) return nullptr; return sublist.EffectSlots + slidx; @@ -715,7 +715,7 @@ inline ALenum GetSourceState(ALsource *source, ALvoice *voice) */ inline bool SourceShouldUpdate(ALsource *source, ALCcontext *context) { - return !context->DeferUpdates.load(std::memory_order_acquire) && + return !context->mDeferUpdates.load(std::memory_order_acquire) && IsPlayingOrPaused(source); } @@ -723,14 +723,14 @@ inline bool SourceShouldUpdate(ALsource *source, ALCcontext *context) /** Can only be called while the mixer is locked! */ void SendStateChangeEvent(ALCcontext *context, ALuint id, ALenum state) { - ALbitfieldSOFT enabledevt{context->EnabledEvts.load(std::memory_order_acquire)}; + ALbitfieldSOFT enabledevt{context->mEnabledEvts.load(std::memory_order_acquire)}; if(!(enabledevt&EventType_SourceStateChange)) return; /* The mixer may have queued a state change that's not yet been processed, * and we don't want state change messages to occur out of order, so send * it through the async queue to ensure proper ordering. */ - RingBuffer *ring{context->AsyncEvents.get()}; + RingBuffer *ring{context->mAsyncEvents.get()}; auto evt_vec = ring->getWriteVector(); if(evt_vec.first.len < 1) return; @@ -738,7 +738,7 @@ void SendStateChangeEvent(ALCcontext *context, ALuint id, ALenum state) evt->u.srcstate.id = id; evt->u.srcstate.state = state; ring->writeAdvance(1); - context->EventSem.post(); + context->mEventSem.post(); } @@ -1127,7 +1127,7 @@ ALboolean SetSourcefv(ALsource *Source, ALCcontext *Context, SourceProp prop, co if(IsPlayingOrPaused(Source)) { - ALCdevice *device{Context->Device}; + ALCdevice *device{Context->mDevice}; BackendLockGuard _{*device->Backend}; /* Double-check that the source is still playing while we have * the lock. @@ -1230,7 +1230,7 @@ ALboolean SetSourcefv(ALsource *Source, ALCcontext *Context, SourceProp prop, co ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const ALint *values) { - ALCdevice *device{Context->Device}; + ALCdevice *device{Context->mDevice}; ALbuffer *buffer{nullptr}; ALfilter *filter{nullptr}; ALeffectslot *slot{nullptr}; @@ -1348,7 +1348,7 @@ ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, co if(IsPlayingOrPaused(Source)) { - ALCdevice *device{Context->Device}; + ALCdevice *device{Context->mDevice}; BackendLockGuard _{*device->Backend}; if(ALvoice *voice{GetSourceVoice(Source, Context)}) { @@ -1423,7 +1423,7 @@ ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, co *values == AL_EXPONENT_DISTANCE_CLAMPED); Source->mDistanceModel = static_cast(*values); - if(Context->SourceDistanceModel) + if(Context->mSourceDistanceModel) UpdateSourceProps(Source, Context); return AL_TRUE; @@ -1443,7 +1443,7 @@ ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, co case AL_AUXILIARY_SEND_FILTER: - slotlock = std::unique_lock{Context->EffectSlotLock}; + slotlock = std::unique_lock{Context->mEffectSlotLock}; if(!(values[0] == 0 || (slot=LookupEffectSlot(Context, values[0])) != nullptr)) SETERR_RETURN(Context, AL_INVALID_VALUE, AL_FALSE, "Invalid effect ID %u", values[0]); @@ -1664,7 +1664,7 @@ ALboolean GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, ALboolean GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp prop, ALdouble *values) { - ALCdevice *device{Context->Device}; + ALCdevice *device{Context->mDevice}; ClockLatency clocktime; std::chrono::nanoseconds srcclock; ALint ivals[3]; @@ -1997,7 +1997,7 @@ ALboolean GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, AL ALboolean GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, ALint64SOFT *values) { - ALCdevice *device = Context->Device; + ALCdevice *device = Context->mDevice; ClockLatency clocktime; std::chrono::nanoseconds srcclock; ALdouble dvals[6]; @@ -2172,7 +2172,7 @@ START_API_FUNC if(n < 0) SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Deleting %d sources", n); - std::lock_guard _{context->SourceLock}; + std::lock_guard _{context->mSourceLock}; /* Check that all Sources are valid */ const ALuint *sources_end = sources + n; @@ -2207,7 +2207,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(LIKELY(context)) { - std::lock_guard _{context->SourceLock}; + std::lock_guard _{context->mSourceLock}; if(LookupSource(context.get(), source) != nullptr) return AL_TRUE; } @@ -2222,8 +2222,8 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->PropLock}; - std::lock_guard __{context->SourceLock}; + std::lock_guard _{context->mPropLock}; + std::lock_guard __{context->mSourceLock}; ALsource *Source = LookupSource(context.get(), source); if(UNLIKELY(!Source)) alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); @@ -2240,8 +2240,8 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->PropLock}; - std::lock_guard __{context->SourceLock}; + std::lock_guard _{context->mPropLock}; + std::lock_guard __{context->mSourceLock}; ALsource *Source = LookupSource(context.get(), source); if(UNLIKELY(!Source)) alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); @@ -2261,8 +2261,8 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->PropLock}; - std::lock_guard __{context->SourceLock}; + std::lock_guard _{context->mPropLock}; + std::lock_guard __{context->mSourceLock}; ALsource *Source = LookupSource(context.get(), source); if(UNLIKELY(!Source)) alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); @@ -2282,8 +2282,8 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->PropLock}; - std::lock_guard __{context->SourceLock}; + std::lock_guard _{context->mPropLock}; + std::lock_guard __{context->mSourceLock}; ALsource *Source = LookupSource(context.get(), source); if(UNLIKELY(!Source)) alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); @@ -2303,8 +2303,8 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->PropLock}; - std::lock_guard __{context->SourceLock}; + std::lock_guard _{context->mPropLock}; + std::lock_guard __{context->mSourceLock}; ALsource *Source = LookupSource(context.get(), source); if(UNLIKELY(!Source)) alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); @@ -2325,8 +2325,8 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->PropLock}; - std::lock_guard __{context->SourceLock}; + std::lock_guard _{context->mPropLock}; + std::lock_guard __{context->mSourceLock}; ALsource *Source = LookupSource(context.get(), source); if(UNLIKELY(!Source)) alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); @@ -2357,8 +2357,8 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->PropLock}; - std::lock_guard __{context->SourceLock}; + std::lock_guard _{context->mPropLock}; + std::lock_guard __{context->mSourceLock}; ALsource *Source = LookupSource(context.get(), source); if(UNLIKELY(!Source)) alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); @@ -2375,8 +2375,8 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->PropLock}; - std::lock_guard __{context->SourceLock}; + std::lock_guard _{context->mPropLock}; + std::lock_guard __{context->mSourceLock}; ALsource *Source = LookupSource(context.get(), source); if(UNLIKELY(!Source)) alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); @@ -2396,8 +2396,8 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->PropLock}; - std::lock_guard __{context->SourceLock}; + std::lock_guard _{context->mPropLock}; + std::lock_guard __{context->mSourceLock}; ALsource *Source = LookupSource(context.get(), source); if(UNLIKELY(!Source)) alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); @@ -2417,8 +2417,8 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->PropLock}; - std::lock_guard __{context->SourceLock}; + std::lock_guard _{context->mPropLock}; + std::lock_guard __{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); @@ -2435,8 +2435,8 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->PropLock}; - std::lock_guard __{context->SourceLock}; + std::lock_guard _{context->mPropLock}; + std::lock_guard __{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); @@ -2456,8 +2456,8 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->PropLock}; - std::lock_guard __{context->SourceLock}; + std::lock_guard _{context->mPropLock}; + std::lock_guard __{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); @@ -2477,7 +2477,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->SourceLock}; + std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); @@ -2500,7 +2500,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->SourceLock}; + std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); @@ -2527,7 +2527,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->SourceLock}; + std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); @@ -2558,7 +2558,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->SourceLock}; + std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); @@ -2577,7 +2577,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->SourceLock}; + std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); @@ -2604,7 +2604,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->SourceLock}; + std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); @@ -2624,7 +2624,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->SourceLock}; + std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); @@ -2643,7 +2643,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->SourceLock}; + std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); @@ -2670,7 +2670,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->SourceLock}; + std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); @@ -2690,7 +2690,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->SourceLock}; + std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); @@ -2709,7 +2709,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->SourceLock}; + std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); @@ -2736,7 +2736,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->SourceLock}; + std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); @@ -2774,7 +2774,7 @@ START_API_FUNC srchandles = extra_sources.data(); } - std::lock_guard _{context->SourceLock}; + std::lock_guard _{context->mSourceLock}; for(ALsizei i{0};i < n;i++) { srchandles[i] = LookupSource(context.get(), sources[i]); @@ -2782,7 +2782,7 @@ START_API_FUNC SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid source ID %u", sources[i]); } - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; BackendLockGuard __{*device->Backend}; /* If the device is disconnected, go right to stopped. */ if(UNLIKELY(!device->Connected.load(std::memory_order_acquire))) @@ -2800,9 +2800,9 @@ START_API_FUNC } /* Count the number of reusable voices. */ - auto voices_end = context->Voices->begin() + - context->VoiceCount.load(std::memory_order_relaxed); - auto free_voices = std::accumulate(context->Voices->begin(), voices_end, ALsizei{0}, + auto voices_end = context->mVoices->begin() + + context->mVoiceCount.load(std::memory_order_relaxed); + auto free_voices = std::accumulate(context->mVoices->begin(), voices_end, ALsizei{0}, [](const ALsizei count, const ALvoice &voice) noexcept -> ALsizei { if(voice.mPlayState.load(std::memory_order_acquire) == ALvoice::Stopped && @@ -2815,23 +2815,23 @@ START_API_FUNC { /* Increment the number of voices to handle the request. */ const ALuint need_voices{static_cast(n) - free_voices}; - const size_t rem_voices{context->Voices->size() - - context->VoiceCount.load(std::memory_order_relaxed)}; + const size_t rem_voices{context->mVoices->size() - + context->mVoiceCount.load(std::memory_order_relaxed)}; if(UNLIKELY(need_voices > rem_voices)) { /* Allocate more voices to get enough. */ const size_t alloc_count{need_voices - rem_voices}; - if(UNLIKELY(context->Voices->size() > std::numeric_limits::max()-alloc_count)) + if(UNLIKELY(context->mVoices->size() > std::numeric_limits::max()-alloc_count)) SETERR_RETURN(context.get(), AL_OUT_OF_MEMORY,, - "Overflow increasing voice count to %zu + %zu", context->Voices->size(), + "Overflow increasing voice count to %zu + %zu", context->mVoices->size(), alloc_count); - const size_t newcount{context->Voices->size() + alloc_count}; + const size_t newcount{context->mVoices->size() + alloc_count}; AllocateVoices(context.get(), newcount); } - context->VoiceCount.fetch_add(need_voices, std::memory_order_relaxed); + context->mVoiceCount.fetch_add(need_voices, std::memory_order_relaxed); } auto start_source = [&context,device](ALsource *source) -> void @@ -2886,9 +2886,9 @@ START_API_FUNC } /* Look for an unused voice to play this source with. */ - auto voices_end = context->Voices->begin() + - context->VoiceCount.load(std::memory_order_relaxed); - voice = std::find_if(context->Voices->begin(), voices_end, + auto voices_end = context->mVoices->begin() + + context->mVoiceCount.load(std::memory_order_relaxed); + voice = std::find_if(context->mVoices->begin(), voices_end, [](const ALvoice &voice) noexcept -> bool { return voice.mPlayState.load(std::memory_order_acquire) == ALvoice::Stopped && @@ -2896,7 +2896,7 @@ START_API_FUNC } ); assert(voice != voices_end); - auto vidx = static_cast(std::distance(context->Voices->begin(), voice)); + auto vidx = static_cast(std::distance(context->mVoices->begin(), voice)); voice->mPlayState.store(ALvoice::Stopped, std::memory_order_release); source->PropsClean.test_and_set(std::memory_order_acquire); @@ -3036,7 +3036,7 @@ START_API_FUNC srchandles = extra_sources.data(); } - std::lock_guard _{context->SourceLock}; + std::lock_guard _{context->mSourceLock}; for(ALsizei i{0};i < n;i++) { srchandles[i] = LookupSource(context.get(), sources[i]); @@ -3044,7 +3044,7 @@ START_API_FUNC SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid source ID %u", sources[i]); } - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; BackendLockGuard __{*device->Backend}; auto pause_source = [&context](ALsource *source) -> void { @@ -3091,7 +3091,7 @@ START_API_FUNC srchandles = extra_sources.data(); } - std::lock_guard _{context->SourceLock}; + std::lock_guard _{context->mSourceLock}; for(ALsizei i{0};i < n;i++) { srchandles[i] = LookupSource(context.get(), sources[i]); @@ -3099,7 +3099,7 @@ START_API_FUNC SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid source ID %u", sources[i]); } - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; BackendLockGuard __{*device->Backend}; auto stop_source = [&context](ALsource *source) -> void { @@ -3153,7 +3153,7 @@ START_API_FUNC srchandles = extra_sources.data(); } - std::lock_guard _{context->SourceLock}; + std::lock_guard _{context->mSourceLock}; for(ALsizei i{0};i < n;i++) { srchandles[i] = LookupSource(context.get(), sources[i]); @@ -3161,7 +3161,7 @@ START_API_FUNC SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid source ID %u", sources[i]); } - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; BackendLockGuard __{*device->Backend}; auto rewind_source = [&context](ALsource *source) -> void { @@ -3200,7 +3200,7 @@ START_API_FUNC SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Queueing %d buffers", nb); if(nb == 0) return; - std::lock_guard _{context->SourceLock}; + std::lock_guard _{context->mSourceLock}; ALsource *source{LookupSource(context.get(),src)}; if(UNLIKELY(!source)) SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid source ID %u", src); @@ -3210,7 +3210,7 @@ START_API_FUNC SETERR_RETURN(context.get(), AL_INVALID_OPERATION,, "Queueing onto static source %u", src); /* Check for a valid Buffer, for its frequency and format */ - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; ALbuffer *BufferFmt{nullptr}; ALbufferlistitem *BufferList{source->queue}; while(BufferList) @@ -3319,7 +3319,7 @@ START_API_FUNC SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Queueing %d buffer layers", nb); if(nb == 0) return; - std::lock_guard _{context->SourceLock}; + std::lock_guard _{context->mSourceLock}; ALsource *source{LookupSource(context.get(),src)}; if(UNLIKELY(!source)) SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid source ID %u", src); @@ -3329,7 +3329,7 @@ START_API_FUNC SETERR_RETURN(context.get(), AL_INVALID_OPERATION,, "Queueing onto static source %u", src); /* Check for a valid Buffer, for its frequency and format */ - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; ALbuffer *BufferFmt{nullptr}; ALbufferlistitem *BufferList{source->queue}; while(BufferList) @@ -3429,7 +3429,7 @@ START_API_FUNC SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Unqueueing %d buffers", nb); if(nb == 0) return; - std::lock_guard _{context->SourceLock}; + std::lock_guard _{context->mSourceLock}; ALsource *source{LookupSource(context.get(),src)}; if(UNLIKELY(!source)) SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid source ID %u", src); @@ -3611,9 +3611,9 @@ ALsource::~ALsource() void UpdateAllSourceProps(ALCcontext *context) { - auto voices_end = context->Voices->begin() + - context->VoiceCount.load(std::memory_order_relaxed); - std::for_each(context->Voices->begin(), voices_end, + auto voices_end = context->mVoices->begin() + + context->mVoiceCount.load(std::memory_order_relaxed); + std::for_each(context->mVoices->begin(), voices_end, [context](ALvoice &voice) -> void { ALuint sid{voice.mSourceID.load(std::memory_order_acquire)}; diff --git a/al/state.cpp b/al/state.cpp index cbb43685..b1885f5c 100644 --- a/al/state.cpp +++ b/al/state.cpp @@ -80,10 +80,10 @@ START_API_FUNC END_API_FUNC #define DO_UPDATEPROPS() do { \ - if(!context->DeferUpdates.load(std::memory_order_acquire)) \ + if(!context->mDeferUpdates.load(std::memory_order_acquire)) \ UpdateContextProps(context.get()); \ else \ - context->PropsClean.clear(std::memory_order_release); \ + context->mPropsClean.clear(std::memory_order_release); \ } while(0) @@ -93,11 +93,11 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->PropLock}; + std::lock_guard _{context->mPropLock}; switch(capability) { case AL_SOURCE_DISTANCE_MODEL: - context->SourceDistanceModel = AL_TRUE; + context->mSourceDistanceModel = AL_TRUE; DO_UPDATEPROPS(); break; @@ -113,11 +113,11 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - std::lock_guard _{context->PropLock}; + std::lock_guard _{context->mPropLock}; switch(capability) { case AL_SOURCE_DISTANCE_MODEL: - context->SourceDistanceModel = AL_FALSE; + context->mSourceDistanceModel = AL_FALSE; DO_UPDATEPROPS(); break; @@ -133,12 +133,12 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return AL_FALSE; - std::lock_guard _{context->PropLock}; + std::lock_guard _{context->mPropLock}; ALboolean value{AL_FALSE}; switch(capability) { case AL_SOURCE_DISTANCE_MODEL: - value = context->SourceDistanceModel; + value = context->mSourceDistanceModel; break; default: @@ -155,17 +155,17 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return AL_FALSE; - std::lock_guard _{context->PropLock}; + std::lock_guard _{context->mPropLock}; ALboolean value{AL_FALSE}; switch(pname) { case AL_DOPPLER_FACTOR: - if(context->DopplerFactor != 0.0f) + if(context->mDopplerFactor != 0.0f) value = AL_TRUE; break; case AL_DOPPLER_VELOCITY: - if(context->DopplerVelocity != 0.0f) + if(context->mDopplerVelocity != 0.0f) value = AL_TRUE; break; @@ -175,17 +175,17 @@ START_API_FUNC break; case AL_SPEED_OF_SOUND: - if(context->SpeedOfSound != 0.0f) + if(context->mSpeedOfSound != 0.0f) value = AL_TRUE; break; case AL_DEFERRED_UPDATES_SOFT: - if(context->DeferUpdates.load(std::memory_order_acquire)) + if(context->mDeferUpdates.load(std::memory_order_acquire)) value = AL_TRUE; break; case AL_GAIN_LIMIT_SOFT: - if(GAIN_MIX_MAX/context->GainBoost != 0.0f) + if(GAIN_MIX_MAX/context->mGainBoost != 0.0f) value = AL_TRUE; break; @@ -212,16 +212,16 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return 0.0; - std::lock_guard _{context->PropLock}; + std::lock_guard _{context->mPropLock}; ALdouble value{0.0}; switch(pname) { case AL_DOPPLER_FACTOR: - value = static_cast(context->DopplerFactor); + value = static_cast(context->mDopplerFactor); break; case AL_DOPPLER_VELOCITY: - value = static_cast(context->DopplerVelocity); + value = static_cast(context->mDopplerVelocity); break; case AL_DISTANCE_MODEL: @@ -229,16 +229,16 @@ START_API_FUNC break; case AL_SPEED_OF_SOUND: - value = static_cast(context->SpeedOfSound); + value = static_cast(context->mSpeedOfSound); break; case AL_DEFERRED_UPDATES_SOFT: - if(context->DeferUpdates.load(std::memory_order_acquire)) + if(context->mDeferUpdates.load(std::memory_order_acquire)) value = static_cast(AL_TRUE); break; case AL_GAIN_LIMIT_SOFT: - value = static_castGAIN_MIX_MAX/context->GainBoost; + value = static_castGAIN_MIX_MAX/context->mGainBoost; break; case AL_NUM_RESAMPLERS_SOFT: @@ -263,16 +263,16 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return 0.0f; - std::lock_guard _{context->PropLock}; + std::lock_guard _{context->mPropLock}; ALfloat value{0.0f}; switch(pname) { case AL_DOPPLER_FACTOR: - value = context->DopplerFactor; + value = context->mDopplerFactor; break; case AL_DOPPLER_VELOCITY: - value = context->DopplerVelocity; + value = context->mDopplerVelocity; break; case AL_DISTANCE_MODEL: @@ -280,16 +280,16 @@ START_API_FUNC break; case AL_SPEED_OF_SOUND: - value = context->SpeedOfSound; + value = context->mSpeedOfSound; break; case AL_DEFERRED_UPDATES_SOFT: - if(context->DeferUpdates.load(std::memory_order_acquire)) + if(context->mDeferUpdates.load(std::memory_order_acquire)) value = static_cast(AL_TRUE); break; case AL_GAIN_LIMIT_SOFT: - value = GAIN_MIX_MAX/context->GainBoost; + value = GAIN_MIX_MAX/context->mGainBoost; break; case AL_NUM_RESAMPLERS_SOFT: @@ -314,16 +314,16 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return 0; - std::lock_guard _{context->PropLock}; + std::lock_guard _{context->mPropLock}; ALint value{0}; switch(pname) { case AL_DOPPLER_FACTOR: - value = static_cast(context->DopplerFactor); + value = static_cast(context->mDopplerFactor); break; case AL_DOPPLER_VELOCITY: - value = static_cast(context->DopplerVelocity); + value = static_cast(context->mDopplerVelocity); break; case AL_DISTANCE_MODEL: @@ -331,16 +331,16 @@ START_API_FUNC break; case AL_SPEED_OF_SOUND: - value = static_cast(context->SpeedOfSound); + value = static_cast(context->mSpeedOfSound); break; case AL_DEFERRED_UPDATES_SOFT: - if(context->DeferUpdates.load(std::memory_order_acquire)) + if(context->mDeferUpdates.load(std::memory_order_acquire)) value = static_cast(AL_TRUE); break; case AL_GAIN_LIMIT_SOFT: - value = static_cast(GAIN_MIX_MAX/context->GainBoost); + value = static_cast(GAIN_MIX_MAX/context->mGainBoost); break; case AL_NUM_RESAMPLERS_SOFT: @@ -365,16 +365,16 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return 0; - std::lock_guard _{context->PropLock}; + std::lock_guard _{context->mPropLock}; ALint64SOFT value{0}; switch(pname) { case AL_DOPPLER_FACTOR: - value = (ALint64SOFT)context->DopplerFactor; + value = (ALint64SOFT)context->mDopplerFactor; break; case AL_DOPPLER_VELOCITY: - value = (ALint64SOFT)context->DopplerVelocity; + value = (ALint64SOFT)context->mDopplerVelocity; break; case AL_DISTANCE_MODEL: @@ -382,16 +382,16 @@ START_API_FUNC break; case AL_SPEED_OF_SOUND: - value = (ALint64SOFT)context->SpeedOfSound; + value = (ALint64SOFT)context->mSpeedOfSound; break; case AL_DEFERRED_UPDATES_SOFT: - if(context->DeferUpdates.load(std::memory_order_acquire)) + if(context->mDeferUpdates.load(std::memory_order_acquire)) value = (ALint64SOFT)AL_TRUE; break; case AL_GAIN_LIMIT_SOFT: - value = (ALint64SOFT)(GAIN_MIX_MAX/context->GainBoost); + value = (ALint64SOFT)(GAIN_MIX_MAX/context->mGainBoost); break; case AL_NUM_RESAMPLERS_SOFT: @@ -416,16 +416,16 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return nullptr; - std::lock_guard _{context->PropLock}; + std::lock_guard _{context->mPropLock}; void *value{nullptr}; switch(pname) { case AL_EVENT_CALLBACK_FUNCTION_SOFT: - value = reinterpret_cast(context->EventCb); + value = reinterpret_cast(context->mEventCb); break; case AL_EVENT_CALLBACK_USER_PARAM_SOFT: - value = context->EventParam; + value = context->mEventParam; break; default: @@ -650,7 +650,7 @@ START_API_FUNC break; case AL_EXTENSIONS: - value = context->ExtensionList; + value = context->mExtensionList; break; case AL_NO_ERROR: @@ -694,8 +694,8 @@ START_API_FUNC alSetError(context.get(), AL_INVALID_VALUE, "Doppler factor %f out of range", value); else { - std::lock_guard _{context->PropLock}; - context->DopplerFactor = value; + std::lock_guard _{context->mPropLock}; + context->mDopplerFactor = value; DO_UPDATEPROPS(); } } @@ -707,24 +707,24 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - if((context->EnabledEvts.load(std::memory_order_relaxed)&EventType_Deprecated)) + if((context->mEnabledEvts.load(std::memory_order_relaxed)&EventType_Deprecated)) { static constexpr ALCchar msg[] = "alDopplerVelocity is deprecated in AL1.1, use alSpeedOfSound"; const ALsizei msglen = static_cast(strlen(msg)); - std::lock_guard _{context->EventCbLock}; - ALbitfieldSOFT enabledevts{context->EnabledEvts.load(std::memory_order_relaxed)}; - if((enabledevts&EventType_Deprecated) && context->EventCb) - (*context->EventCb)(AL_EVENT_TYPE_DEPRECATED_SOFT, 0, 0, msglen, msg, - context->EventParam); + std::lock_guard _{context->mEventCbLock}; + ALbitfieldSOFT enabledevts{context->mEnabledEvts.load(std::memory_order_relaxed)}; + if((enabledevts&EventType_Deprecated) && context->mEventCb) + (*context->mEventCb)(AL_EVENT_TYPE_DEPRECATED_SOFT, 0, 0, msglen, msg, + context->mEventParam); } if(!(value >= 0.0f && std::isfinite(value))) alSetError(context.get(), AL_INVALID_VALUE, "Doppler velocity %f out of range", value); else { - std::lock_guard _{context->PropLock}; - context->DopplerVelocity = value; + std::lock_guard _{context->mPropLock}; + context->mDopplerVelocity = value; DO_UPDATEPROPS(); } } @@ -740,8 +740,8 @@ START_API_FUNC alSetError(context.get(), AL_INVALID_VALUE, "Speed of sound %f out of range", value); else { - std::lock_guard _{context->PropLock}; - context->SpeedOfSound = value; + std::lock_guard _{context->mPropLock}; + context->mSpeedOfSound = value; DO_UPDATEPROPS(); } } @@ -760,9 +760,9 @@ START_API_FUNC alSetError(context.get(), AL_INVALID_VALUE, "Distance model 0x%04x out of range", value); else { - std::lock_guard _{context->PropLock}; + std::lock_guard _{context->mPropLock}; context->mDistanceModel = static_cast(value); - if(!context->SourceDistanceModel) + if(!context->mSourceDistanceModel) DO_UPDATEPROPS(); } } @@ -825,7 +825,7 @@ END_API_FUNC void UpdateContextProps(ALCcontext *context) { /* Get an unused proprty container, or allocate a new one as needed. */ - ALcontextProps *props{context->FreeContextProps.load(std::memory_order_acquire)}; + ALcontextProps *props{context->mFreeContextProps.load(std::memory_order_acquire)}; if(!props) props = static_cast(al_calloc(16, sizeof(*props))); else @@ -833,27 +833,27 @@ void UpdateContextProps(ALCcontext *context) ALcontextProps *next; do { next = props->next.load(std::memory_order_relaxed); - } while(context->FreeContextProps.compare_exchange_weak(props, next, + } while(context->mFreeContextProps.compare_exchange_weak(props, next, std::memory_order_seq_cst, std::memory_order_acquire) == 0); } /* Copy in current property values. */ - props->MetersPerUnit = context->MetersPerUnit; + props->MetersPerUnit = context->mMetersPerUnit; - props->DopplerFactor = context->DopplerFactor; - props->DopplerVelocity = context->DopplerVelocity; - props->SpeedOfSound = context->SpeedOfSound; + props->DopplerFactor = context->mDopplerFactor; + props->DopplerVelocity = context->mDopplerVelocity; + props->SpeedOfSound = context->mSpeedOfSound; - props->SourceDistanceModel = context->SourceDistanceModel; + props->SourceDistanceModel = context->mSourceDistanceModel; props->mDistanceModel = context->mDistanceModel; /* Set the new container for updating internal parameters. */ - props = context->Update.exchange(props, std::memory_order_acq_rel); + props = context->mUpdate.exchange(props, std::memory_order_acq_rel); if(props) { /* If there was an unused update container, put it back in the * freelist. */ - AtomicReplaceHead(context->FreeContextProps, props); + AtomicReplaceHead(context->mFreeContextProps, props); } } diff --git a/alc/alc.cpp b/alc/alc.cpp index 538bea9f..49ecf54b 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -833,7 +833,7 @@ std::atomic LastNullDeviceError{ALC_NO_ERROR}; /* Thread-local current context */ void ReleaseThreadCtx(ALCcontext *context) { - auto ref = DecrementRef(&context->ref); + auto ref = DecrementRef(&context->mRef); TRACEREF("ALCcontext %p decreasing refcount to %u\n", context, ref); ERR("Context %p current for thread being destroyed, possible leak!\n", context); } @@ -1599,7 +1599,7 @@ void SetDefaultChannelOrder(ALCdevice *device) */ void ALCcontext_DeferUpdates(ALCcontext *context) { - context->DeferUpdates.store(true); + context->mDeferUpdates.store(true); } /* ALCcontext_ProcessUpdates @@ -1608,19 +1608,19 @@ void ALCcontext_DeferUpdates(ALCcontext *context) */ void ALCcontext_ProcessUpdates(ALCcontext *context) { - std::lock_guard _{context->PropLock}; - if(context->DeferUpdates.exchange(false)) + std::lock_guard _{context->mPropLock}; + if(context->mDeferUpdates.exchange(false)) { /* Tell the mixer to stop applying updates, then wait for any active * updating to finish, before providing updates. */ - context->HoldUpdates.store(true, std::memory_order_release); - while((context->UpdateCount.load(std::memory_order_acquire)&1) != 0) + context->mHoldUpdates.store(true, std::memory_order_release); + while((context->mUpdateCount.load(std::memory_order_acquire)&1) != 0) std::this_thread::yield(); - if(!context->PropsClean.test_and_set(std::memory_order_acq_rel)) + if(!context->mPropsClean.test_and_set(std::memory_order_acq_rel)) UpdateContextProps(context); - if(!context->Listener.PropsClean.test_and_set(std::memory_order_acq_rel)) + if(!context->mListener.PropsClean.test_and_set(std::memory_order_acq_rel)) UpdateListenerProps(context); UpdateAllEffectSlotProps(context); UpdateAllSourceProps(context); @@ -1628,7 +1628,7 @@ void ALCcontext_ProcessUpdates(ALCcontext *context) /* Now with all updates declared, let the mixer continue applying them * so they all happen at once. */ - context->HoldUpdates.store(false, std::memory_order_release); + context->mHoldUpdates.store(false, std::memory_order_release); } } @@ -2167,9 +2167,9 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) FPUCtl mixer_mode{}; for(ALCcontext *context : *device->mContexts.load()) { - if(context->DefaultSlot) + if(context->mDefaultSlot) { - ALeffectslot *slot = context->DefaultSlot.get(); + ALeffectslot *slot = context->mDefaultSlot.get(); aluInitEffectPanning(slot, device); EffectState *state{slot->Effect.State}; @@ -2180,9 +2180,9 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) UpdateEffectSlotProps(slot, context); } - std::unique_lock proplock{context->PropLock}; - std::unique_lock slotlock{context->EffectSlotLock}; - for(auto &sublist : context->EffectSlotList) + std::unique_lock proplock{context->mPropLock}; + std::unique_lock slotlock{context->mEffectSlotLock}; + for(auto &sublist : context->mEffectSlotList) { uint64_t usemask = ~sublist.FreeMask; while(usemask) @@ -2204,8 +2204,8 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) } slotlock.unlock(); - std::unique_lock srclock{context->SourceLock}; - for(auto &sublist : context->SourceList) + std::unique_lock srclock{context->mSourceLock}; + for(auto &sublist : context->mSourceList) { uint64_t usemask = ~sublist.FreeMask; while(usemask) @@ -2245,7 +2245,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) * auxiliary sends is changing. Active sources will have updates * respecified in UpdateAllSourceProps. */ - ALvoiceProps *vprops{context->FreeVoiceProps.exchange(nullptr, std::memory_order_acq_rel)}; + ALvoiceProps *vprops{context->mFreeVoiceProps.exchange(nullptr, std::memory_order_acq_rel)}; while(vprops) { ALvoiceProps *next = vprops->next.load(std::memory_order_relaxed); @@ -2253,8 +2253,8 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) vprops = next; } - auto voices = context->Voices.get(); - auto voices_end = voices->begin() + context->VoiceCount.load(std::memory_order_relaxed); + auto voices = context->mVoices.get(); + auto voices_end = voices->begin() + context->mVoiceCount.load(std::memory_order_relaxed); if(device->NumAuxSends < old_sends) { const ALsizei num_sends{device->NumAuxSends}; @@ -2300,9 +2300,9 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) ); srclock.unlock(); - context->PropsClean.test_and_set(std::memory_order_release); + context->mPropsClean.test_and_set(std::memory_order_release); UpdateContextProps(context); - context->Listener.PropsClean.test_and_set(std::memory_order_release); + context->mListener.PropsClean.test_and_set(std::memory_order_release); UpdateListenerProps(context); UpdateAllSourceProps(context); } @@ -2383,9 +2383,9 @@ static DeviceRef VerifyDevice(ALCdevice *device) } -ALCcontext::ALCcontext(ALCdevice *device) : Device{device} +ALCcontext::ALCcontext(ALCdevice *device) : mDevice{device} { - PropsClean.test_and_set(std::memory_order_relaxed); + mPropsClean.test_and_set(std::memory_order_relaxed); } /* InitContext @@ -2394,43 +2394,43 @@ ALCcontext::ALCcontext(ALCdevice *device) : Device{device} */ static ALvoid InitContext(ALCcontext *Context) { - ALlistener &listener = Context->Listener; + ALlistener &listener = Context->mListener; ALeffectslotArray *auxslots; //Validate Context - if(!Context->DefaultSlot) + if(!Context->mDefaultSlot) auxslots = ALeffectslot::CreatePtrArray(0); else { auxslots = ALeffectslot::CreatePtrArray(1); - (*auxslots)[0] = Context->DefaultSlot.get(); + (*auxslots)[0] = Context->mDefaultSlot.get(); } - Context->ActiveAuxSlots.store(auxslots, std::memory_order_relaxed); + Context->mActiveAuxSlots.store(auxslots, std::memory_order_relaxed); //Set globals Context->mDistanceModel = DistanceModel::Default; - Context->SourceDistanceModel = AL_FALSE; - Context->DopplerFactor = 1.0f; - Context->DopplerVelocity = 1.0f; - Context->SpeedOfSound = SPEEDOFSOUNDMETRESPERSEC; - Context->MetersPerUnit = AL_DEFAULT_METERS_PER_UNIT; + Context->mSourceDistanceModel = AL_FALSE; + Context->mDopplerFactor = 1.0f; + Context->mDopplerVelocity = 1.0f; + Context->mSpeedOfSound = SPEEDOFSOUNDMETRESPERSEC; + Context->mMetersPerUnit = AL_DEFAULT_METERS_PER_UNIT; - Context->ExtensionList = alExtList; + Context->mExtensionList = alExtList; listener.Params.Matrix = alu::Matrix::Identity(); listener.Params.Velocity = alu::Vector{}; listener.Params.Gain = listener.Gain; - listener.Params.MetersPerUnit = Context->MetersPerUnit; - listener.Params.DopplerFactor = Context->DopplerFactor; - listener.Params.SpeedOfSound = Context->SpeedOfSound * Context->DopplerVelocity; + listener.Params.MetersPerUnit = Context->mMetersPerUnit; + listener.Params.DopplerFactor = Context->mDopplerFactor; + listener.Params.SpeedOfSound = Context->mSpeedOfSound * Context->mDopplerVelocity; listener.Params.ReverbSpeedOfSound = listener.Params.SpeedOfSound * listener.Params.MetersPerUnit; - listener.Params.SourceDistanceModel = Context->SourceDistanceModel; + listener.Params.SourceDistanceModel = Context->mSourceDistanceModel; listener.Params.mDistanceModel = Context->mDistanceModel; - Context->AsyncEvents = CreateRingBuffer(511, sizeof(AsyncEvent), false); + Context->mAsyncEvents = CreateRingBuffer(511, sizeof(AsyncEvent), false); StartEventThrd(Context); } @@ -2444,14 +2444,14 @@ ALCcontext::~ALCcontext() { TRACE("Freeing context %p\n", this); - ALcontextProps *cprops{Update.exchange(nullptr, std::memory_order_relaxed)}; + ALcontextProps *cprops{mUpdate.exchange(nullptr, std::memory_order_relaxed)}; if(cprops) { TRACE("Freed unapplied context update %p\n", cprops); al_free(cprops); } size_t count{0}; - cprops = FreeContextProps.exchange(nullptr, std::memory_order_acquire); + cprops = mFreeContextProps.exchange(nullptr, std::memory_order_acquire); while(cprops) { ALcontextProps *next{cprops->next.load(std::memory_order_relaxed)}; @@ -2461,17 +2461,17 @@ ALCcontext::~ALCcontext() } TRACE("Freed %zu context property object%s\n", count, (count==1)?"":"s"); - count = std::accumulate(SourceList.cbegin(), SourceList.cend(), size_t{0u}, + count = std::accumulate(mSourceList.cbegin(), mSourceList.cend(), size_t{0u}, [](size_t cur, const SourceSubList &sublist) noexcept -> size_t { return cur + POPCNT64(~sublist.FreeMask); } ); if(count > 0) WARN("%zu Source%s not deleted\n", count, (count==1)?"":"s"); - SourceList.clear(); - NumSources = 0; + mSourceList.clear(); + mNumSources = 0; count = 0; - ALeffectslotProps *eprops{FreeEffectslotProps.exchange(nullptr, std::memory_order_acquire)}; + ALeffectslotProps *eprops{mFreeEffectslotProps.exchange(nullptr, std::memory_order_acquire)}; while(eprops) { ALeffectslotProps *next{eprops->next.load(std::memory_order_relaxed)}; @@ -2482,20 +2482,20 @@ ALCcontext::~ALCcontext() } TRACE("Freed %zu AuxiliaryEffectSlot property object%s\n", count, (count==1)?"":"s"); - delete ActiveAuxSlots.exchange(nullptr, std::memory_order_relaxed); - DefaultSlot = nullptr; + delete mActiveAuxSlots.exchange(nullptr, std::memory_order_relaxed); + mDefaultSlot = nullptr; - count = std::accumulate(EffectSlotList.cbegin(), EffectSlotList.cend(), size_t{0u}, + count = std::accumulate(mEffectSlotList.cbegin(), mEffectSlotList.cend(), size_t{0u}, [](size_t cur, const EffectSlotSubList &sublist) noexcept -> size_t { return cur + POPCNT64(~sublist.FreeMask); } ); if(count > 0) WARN("%zu AuxiliaryEffectSlot%s not deleted\n", count, (count==1)?"":"s"); - EffectSlotList.clear(); - NumEffectSlots = 0; + mEffectSlotList.clear(); + mNumEffectSlots = 0; count = 0; - ALvoiceProps *vprops{FreeVoiceProps.exchange(nullptr, std::memory_order_acquire)}; + ALvoiceProps *vprops{mFreeVoiceProps.exchange(nullptr, std::memory_order_acquire)}; while(vprops) { ALvoiceProps *next{vprops->next.load(std::memory_order_relaxed)}; @@ -2505,17 +2505,17 @@ ALCcontext::~ALCcontext() } TRACE("Freed %zu voice property object%s\n", count, (count==1)?"":"s"); - Voices = nullptr; - VoiceCount.store(0, std::memory_order_relaxed); + mVoices = nullptr; + mVoiceCount.store(0, std::memory_order_relaxed); - ALlistenerProps *lprops{Listener.Update.exchange(nullptr, std::memory_order_relaxed)}; + ALlistenerProps *lprops{mListener.Update.exchange(nullptr, std::memory_order_relaxed)}; if(lprops) { TRACE("Freed unapplied listener update %p\n", lprops); al_free(lprops); } count = 0; - lprops = FreeListenerProps.exchange(nullptr, std::memory_order_acquire); + lprops = mFreeListenerProps.exchange(nullptr, std::memory_order_acquire); while(lprops) { ALlistenerProps *next{lprops->next.load(std::memory_order_relaxed)}; @@ -2525,10 +2525,10 @@ ALCcontext::~ALCcontext() } TRACE("Freed %zu listener property object%s\n", count, (count==1)?"":"s"); - if(AsyncEvents) + if(mAsyncEvents) { count = 0; - auto evt_vec = AsyncEvents->getReadVector(); + auto evt_vec = mAsyncEvents->getReadVector(); if(evt_vec.first.len > 0) { al::destroy_n(reinterpret_cast(evt_vec.first.buf), evt_vec.first.len); @@ -2541,10 +2541,10 @@ ALCcontext::~ALCcontext() } if(count > 0) TRACE("Destructed %zu orphaned event%s\n", count, (count==1)?"":"s"); - AsyncEvents->readAdvance(count); + mAsyncEvents->readAdvance(count); } - ALCdevice_DecRef(Device); + ALCdevice_DecRef(mDevice); } /* ReleaseContext @@ -2612,13 +2612,13 @@ static bool ReleaseContext(ALCcontext *context, ALCdevice *device) static void ALCcontext_IncRef(ALCcontext *context) { - auto ref = IncrementRef(&context->ref); + auto ref = IncrementRef(&context->mRef); TRACEREF("ALCcontext %p increasing refcount to %u\n", context, ref); } void ALCcontext_DecRef(ALCcontext *context) { - auto ref = DecrementRef(&context->ref); + auto ref = DecrementRef(&context->mRef); TRACEREF("ALCcontext %p decreasing refcount to %u\n", context, ref); if(UNLIKELY(ref == 0)) delete context; } @@ -2661,10 +2661,10 @@ ContextRef GetContextRef(void) void AllocateVoices(ALCcontext *context, size_t num_voices) { - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; const ALsizei num_sends{device->NumAuxSends}; - if(context->Voices && num_voices == context->Voices->size()) + if(context->mVoices && num_voices == context->mVoices->size()) return; std::unique_ptr> voices; @@ -2673,11 +2673,11 @@ void AllocateVoices(ALCcontext *context, size_t num_voices) voices.reset(new (ptr) al::FlexArray{num_voices}); } - const size_t v_count{minz(context->VoiceCount.load(std::memory_order_relaxed), num_voices)}; - if(context->Voices) + const size_t v_count{minz(context->mVoiceCount.load(std::memory_order_relaxed), num_voices)}; + if(context->mVoices) { /* Copy the old voice data to the new storage. */ - auto viter = std::move(context->Voices->begin(), context->Voices->begin()+v_count, + auto viter = std::move(context->mVoices->begin(), context->mVoices->begin()+v_count, voices->begin()); /* Clear extraneous property set sends. */ @@ -2697,8 +2697,8 @@ void AllocateVoices(ALCcontext *context, size_t num_voices) std::for_each(voices->begin(), viter, clear_sends); } - context->Voices = std::move(voices); - context->VoiceCount.store(static_cast(v_count), std::memory_order_relaxed); + context->mVoices = std::move(voices); + context->mVoiceCount.store(static_cast(v_count), std::memory_order_relaxed); } @@ -3444,7 +3444,7 @@ START_API_FUNC dev->LastError.store(ALC_NO_ERROR); ContextRef context{new ALCcontext{dev.get()}}; - ALCdevice_IncRef(context->Device); + ALCdevice_IncRef(context->mDevice); ALCenum err{UpdateDeviceParams(dev.get(), attrList)}; if(err != ALC_NO_ERROR) @@ -3461,12 +3461,12 @@ START_API_FUNC if(DefaultEffect.type != AL_EFFECT_NULL && dev->Type == Playback) { void *ptr{al_calloc(16, sizeof(ALeffectslot))}; - context->DefaultSlot = std::unique_ptr{new (ptr) ALeffectslot{}}; - if(InitEffectSlot(context->DefaultSlot.get()) == AL_NO_ERROR) - aluInitEffectPanning(context->DefaultSlot.get(), dev.get()); + context->mDefaultSlot = std::unique_ptr{new (ptr) ALeffectslot{}}; + if(InitEffectSlot(context->mDefaultSlot.get()) == AL_NO_ERROR) + aluInitEffectPanning(context->mDefaultSlot.get(), dev.get()); else { - context->DefaultSlot = nullptr; + context->mDefaultSlot = nullptr; ERR("Failed to initialize the default effect slot\n"); } } @@ -3483,8 +3483,8 @@ START_API_FUNC const ALfloat db{clampf(valf, -24.0f, 24.0f)}; if(db != valf) WARN("volume-adjust clamped: %f, range: +/-%f\n", valf, 24.0f); - context->GainBoost = std::pow(10.0f, db/20.0f); - TRACE("volume-adjust gain: %f\n", context->GainBoost); + context->mGainBoost = std::pow(10.0f, db/20.0f); + TRACE("volume-adjust gain: %f\n", context->mGainBoost); } } UpdateListenerProps(context.get()); @@ -3526,10 +3526,10 @@ START_API_FUNC ContextList.insert(iter, ContextRef{context.get()}); } - if(context->DefaultSlot) + if(context->mDefaultSlot) { - if(InitializeEffect(context.get(), context->DefaultSlot.get(), &DefaultEffect) == AL_NO_ERROR) - UpdateEffectSlotProps(context->DefaultSlot.get(), context.get()); + if(InitializeEffect(context.get(), context->mDefaultSlot.get(), &DefaultEffect) == AL_NO_ERROR) + UpdateEffectSlotProps(context->mDefaultSlot.get(), context.get()); else ERR("Failed to initialize the default effect\n"); } @@ -3560,7 +3560,7 @@ START_API_FUNC ContextRef ctx{std::move(*iter)}; ContextList.erase(iter); - ALCdevice *Device{ctx->Device}; + ALCdevice *Device{ctx->mDevice}; std::lock_guard _{Device->StateLock}; if(!ReleaseContext(ctx.get(), Device) && Device->Flags.get()) @@ -3671,7 +3671,7 @@ START_API_FUNC alcSetError(nullptr, ALC_INVALID_CONTEXT); return nullptr; } - return ctx->Device; + return ctx->mDevice; } END_API_FUNC diff --git a/alc/alcontext.h b/alc/alcontext.h index a2da77b0..8156c345 100644 --- a/alc/alcontext.h +++ b/alc/alcontext.h @@ -73,70 +73,70 @@ struct EffectSlotSubList { }; struct ALCcontext { - RefCount ref{1u}; + RefCount mRef{1u}; - al::vector SourceList; - ALuint NumSources{0}; - std::mutex SourceLock; + al::vector mSourceList; + ALuint mNumSources{0}; + std::mutex mSourceLock; - al::vector EffectSlotList; - ALuint NumEffectSlots{0u}; - std::mutex EffectSlotLock; + al::vector mEffectSlotList; + ALuint mNumEffectSlots{0u}; + std::mutex mEffectSlotLock; - std::atomic LastError{AL_NO_ERROR}; + std::atomic mLastError{AL_NO_ERROR}; DistanceModel mDistanceModel{DistanceModel::Default}; - ALboolean SourceDistanceModel{AL_FALSE}; + ALboolean mSourceDistanceModel{AL_FALSE}; - ALfloat DopplerFactor{1.0f}; - ALfloat DopplerVelocity{1.0f}; - ALfloat SpeedOfSound{}; - ALfloat MetersPerUnit{1.0f}; + ALfloat mDopplerFactor{1.0f}; + ALfloat mDopplerVelocity{1.0f}; + ALfloat mSpeedOfSound{}; + ALfloat mMetersPerUnit{1.0f}; - std::atomic_flag PropsClean; - std::atomic DeferUpdates{false}; + std::atomic_flag mPropsClean; + std::atomic mDeferUpdates{false}; - std::mutex PropLock; + std::mutex mPropLock; /* Counter for the pre-mixing updates, in 31.1 fixed point (lowest bit * indicates if updates are currently happening). */ - RefCount UpdateCount{0u}; - std::atomic HoldUpdates{false}; + RefCount mUpdateCount{0u}; + std::atomic mHoldUpdates{false}; - ALfloat GainBoost{1.0f}; + ALfloat mGainBoost{1.0f}; - std::atomic Update{nullptr}; + std::atomic mUpdate{nullptr}; /* Linked lists of unused property containers, free to use for future * updates. */ - std::atomic FreeContextProps{nullptr}; - std::atomic FreeListenerProps{nullptr}; - std::atomic FreeVoiceProps{nullptr}; - std::atomic FreeEffectslotProps{nullptr}; + std::atomic mFreeContextProps{nullptr}; + std::atomic mFreeListenerProps{nullptr}; + std::atomic mFreeVoiceProps{nullptr}; + std::atomic mFreeEffectslotProps{nullptr}; - std::unique_ptr> Voices{nullptr}; - std::atomic VoiceCount{0u}; + std::unique_ptr> mVoices{nullptr}; + std::atomic mVoiceCount{0u}; using ALeffectslotArray = al::FlexArray; - std::atomic ActiveAuxSlots{nullptr}; + std::atomic mActiveAuxSlots{nullptr}; - std::thread EventThread; - al::semaphore EventSem; - std::unique_ptr AsyncEvents; - std::atomic EnabledEvts{0u}; - std::mutex EventCbLock; - ALEVENTPROCSOFT EventCb{}; - void *EventParam{nullptr}; + std::thread mEventThread; + al::semaphore mEventSem; + std::unique_ptr mAsyncEvents; + std::atomic mEnabledEvts{0u}; + std::mutex mEventCbLock; + ALEVENTPROCSOFT mEventCb{}; + void *mEventParam{nullptr}; /* Default effect slot */ - std::unique_ptr DefaultSlot; + std::unique_ptr mDefaultSlot; - ALCdevice *const Device; - const ALCchar *ExtensionList{nullptr}; + ALCdevice *const mDevice; + const ALCchar *mExtensionList{nullptr}; - ALlistener Listener{}; + ALlistener mListener{}; ALCcontext(ALCdevice *device); diff --git a/alc/alu.cpp b/alc/alu.cpp index b2e1effa..2469d08d 100644 --- a/alc/alu.cpp +++ b/alc/alu.cpp @@ -279,10 +279,10 @@ alu::Vector operator*(const alu::Matrix &mtx, const alu::Vector &vec) noexcept bool CalcContextParams(ALCcontext *Context) { - ALcontextProps *props{Context->Update.exchange(nullptr, std::memory_order_acq_rel)}; + ALcontextProps *props{Context->mUpdate.exchange(nullptr, std::memory_order_acq_rel)}; if(!props) return false; - ALlistener &Listener = Context->Listener; + ALlistener &Listener = Context->mListener; Listener.Params.MetersPerUnit = props->MetersPerUnit; Listener.Params.DopplerFactor = props->DopplerFactor; @@ -294,13 +294,13 @@ bool CalcContextParams(ALCcontext *Context) Listener.Params.SourceDistanceModel = props->SourceDistanceModel; Listener.Params.mDistanceModel = props->mDistanceModel; - AtomicReplaceHead(Context->FreeContextProps, props); + AtomicReplaceHead(Context->mFreeContextProps, props); return true; } bool CalcListenerParams(ALCcontext *Context) { - ALlistener &Listener = Context->Listener; + ALlistener &Listener = Context->mListener; ALlistenerProps *props{Listener.Update.exchange(nullptr, std::memory_order_acq_rel)}; if(!props) return false; @@ -328,9 +328,9 @@ bool CalcListenerParams(ALCcontext *Context) const alu::Vector vel{props->Velocity[0], props->Velocity[1], props->Velocity[2], 0.0f}; Listener.Params.Velocity = Listener.Params.Matrix * vel; - Listener.Params.Gain = props->Gain * Context->GainBoost; + Listener.Params.Gain = props->Gain * Context->mGainBoost; - AtomicReplaceHead(Context->FreeListenerProps, props); + AtomicReplaceHead(Context->mFreeListenerProps, props); return true; } @@ -391,14 +391,14 @@ bool CalcEffectSlotParams(ALeffectslot *slot, ALCcontext *context, bool force) /* Otherwise, if it would be deleted, send it off with a release * event. */ - RingBuffer *ring{context->AsyncEvents.get()}; + RingBuffer *ring{context->mAsyncEvents.get()}; auto evt_vec = ring->getWriteVector(); if(LIKELY(evt_vec.first.len > 0)) { AsyncEvent *evt{new (evt_vec.first.buf) AsyncEvent{EventType_ReleaseEffectState}}; evt->u.mEffectState = oldstate; ring->writeAdvance(1); - context->EventSem.post(); + context->mEventSem.post(); } else { @@ -411,7 +411,7 @@ bool CalcEffectSlotParams(ALeffectslot *slot, ALCcontext *context, bool force) } } - AtomicReplaceHead(context->FreeEffectslotProps, props); + AtomicReplaceHead(context->mFreeEffectslotProps, props); } EffectTarget output; @@ -419,7 +419,7 @@ bool CalcEffectSlotParams(ALeffectslot *slot, ALCcontext *context, bool force) output = EffectTarget{&target->Wet, nullptr}; else { - ALCdevice *device{context->Device}; + ALCdevice *device{context->mDevice}; output = EffectTarget{&device->Dry, &device->RealOut}; } state->update(context, slot, &slot->Params.mEffectProps, output); @@ -960,7 +960,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat xpos, const ALfloat ypo void CalcNonAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, const ALCcontext *ALContext) { - const ALCdevice *Device{ALContext->Device}; + const ALCdevice *Device{ALContext->mDevice}; ALeffectslot *SendSlots[MAX_SENDS]; voice->mDirect.Buffer = Device->Dry.Buffer; @@ -968,7 +968,7 @@ void CalcNonAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, cons { SendSlots[i] = props->Send[i].Slot; if(!SendSlots[i] && i == 0) - SendSlots[i] = ALContext->DefaultSlot.get(); + SendSlots[i] = ALContext->mDefaultSlot.get(); if(!SendSlots[i] || SendSlots[i]->Params.EffectType == AL_EFFECT_NULL) { SendSlots[i] = nullptr; @@ -992,7 +992,7 @@ void CalcNonAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, cons voice->mResampler = SelectResampler(props->mResampler); /* Calculate gains */ - const ALlistener &Listener = ALContext->Listener; + const ALlistener &Listener = ALContext->mListener; ALfloat DryGain{clampf(props->Gain, props->MinGain, props->MaxGain)}; DryGain *= props->Direct.Gain * Listener.Params.Gain; DryGain = minf(DryGain, GAIN_MIX_MAX); @@ -1014,9 +1014,9 @@ void CalcNonAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, cons void CalcAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, const ALCcontext *ALContext) { - const ALCdevice *Device{ALContext->Device}; + const ALCdevice *Device{ALContext->mDevice}; const ALsizei NumSends{Device->NumAuxSends}; - const ALlistener &Listener = ALContext->Listener; + const ALlistener &Listener = ALContext->mListener; /* Set mixing buffers and get send parameters. */ voice->mDirect.Buffer = Device->Dry.Buffer; @@ -1029,7 +1029,7 @@ void CalcAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, const A { SendSlots[i] = props->Send[i].Slot; if(!SendSlots[i] && i == 0) - SendSlots[i] = ALContext->DefaultSlot.get(); + SendSlots[i] = ALContext->mDefaultSlot.get(); if(!SendSlots[i] || SendSlots[i]->Params.EffectType == AL_EFFECT_NULL) { SendSlots[i] = nullptr; @@ -1342,7 +1342,7 @@ void CalcSourceParams(ALvoice *voice, ALCcontext *context, bool force) { voice->mProps = *props; - AtomicReplaceHead(context->FreeVoiceProps, props); + AtomicReplaceHead(context->mFreeVoiceProps, props); } if((voice->mProps.mSpatializeMode == SpatializeAuto && voice->mFmtChannels == FmtMono) || @@ -1355,8 +1355,8 @@ void CalcSourceParams(ALvoice *voice, ALCcontext *context, bool force) void ProcessParamUpdates(ALCcontext *ctx, const ALeffectslotArray *slots) { - IncrementRef(&ctx->UpdateCount); - if(LIKELY(!ctx->HoldUpdates.load(std::memory_order_acquire))) + IncrementRef(&ctx->mUpdateCount); + if(LIKELY(!ctx->mHoldUpdates.load(std::memory_order_acquire))) { bool cforce{CalcContextParams(ctx)}; bool force{CalcListenerParams(ctx) || cforce}; @@ -1365,8 +1365,8 @@ void ProcessParamUpdates(ALCcontext *ctx, const ALeffectslotArray *slots) { return CalcEffectSlotParams(slot, ctx, cforce) | force; } ); - std::for_each(ctx->Voices->begin(), - ctx->Voices->begin() + ctx->VoiceCount.load(std::memory_order_acquire), + std::for_each(ctx->mVoices->begin(), + ctx->mVoices->begin() + ctx->mVoiceCount.load(std::memory_order_acquire), [ctx,force](ALvoice &voice) -> void { ALuint sid{voice.mSourceID.load(std::memory_order_acquire)}; @@ -1374,14 +1374,14 @@ void ProcessParamUpdates(ALCcontext *ctx, const ALeffectslotArray *slots) } ); } - IncrementRef(&ctx->UpdateCount); + IncrementRef(&ctx->mUpdateCount); } void ProcessContext(ALCcontext *ctx, const ALsizei SamplesToDo) { ASSUME(SamplesToDo > 0); - const ALeffectslotArray *auxslots{ctx->ActiveAuxSlots.load(std::memory_order_acquire)}; + const ALeffectslotArray *auxslots{ctx->mActiveAuxSlots.load(std::memory_order_acquire)}; /* Process pending propery updates for objects on the context. */ ProcessParamUpdates(ctx, auxslots); @@ -1396,8 +1396,8 @@ void ProcessContext(ALCcontext *ctx, const ALsizei SamplesToDo) ); /* Process voices that have a playing source. */ - std::for_each(ctx->Voices->begin(), - ctx->Voices->begin() + ctx->VoiceCount.load(std::memory_order_acquire), + std::for_each(ctx->mVoices->begin(), + ctx->mVoices->begin() + ctx->mVoiceCount.load(std::memory_order_acquire), [SamplesToDo,ctx](ALvoice &voice) -> void { const ALvoice::State vstate{voice.mPlayState.load(std::memory_order_acquire)}; @@ -1772,16 +1772,16 @@ void aluHandleDisconnect(ALCdevice *device, const char *msg, ...) for(ALCcontext *ctx : *device->mContexts.load()) { - const ALbitfieldSOFT enabledevt{ctx->EnabledEvts.load(std::memory_order_acquire)}; + const ALbitfieldSOFT enabledevt{ctx->mEnabledEvts.load(std::memory_order_acquire)}; if((enabledevt&EventType_Disconnected)) { - RingBuffer *ring{ctx->AsyncEvents.get()}; + RingBuffer *ring{ctx->mAsyncEvents.get()}; auto evt_data = ring->getWriteVector().first; if(evt_data.len > 0) { new (evt_data.buf) AsyncEvent{evt}; ring->writeAdvance(1); - ctx->EventSem.post(); + ctx->mEventSem.post(); } } @@ -1792,8 +1792,8 @@ void aluHandleDisconnect(ALCdevice *device, const char *msg, ...) voice.mSourceID.store(0u, std::memory_order_relaxed); voice.mPlayState.store(ALvoice::Stopped, std::memory_order_release); }; - std::for_each(ctx->Voices->begin(), - ctx->Voices->begin() + ctx->VoiceCount.load(std::memory_order_acquire), + std::for_each(ctx->mVoices->begin(), + ctx->mVoices->begin() + ctx->mVoiceCount.load(std::memory_order_acquire), stop_voice); } } diff --git a/alc/effects/autowah.cpp b/alc/effects/autowah.cpp index 298d5c96..d92e114a 100644 --- a/alc/effects/autowah.cpp +++ b/alc/effects/autowah.cpp @@ -107,7 +107,7 @@ ALboolean ALautowahState::deviceUpdate(const ALCdevice*) void ALautowahState::update(const ALCcontext *context, const ALeffectslot *slot, const EffectProps *props, const EffectTarget target) { - const ALCdevice *device{context->Device}; + const ALCdevice *device{context->mDevice}; const ALfloat ReleaseTime{clampf(props->Autowah.ReleaseTime, 0.001f, 1.0f)}; diff --git a/alc/effects/chorus.cpp b/alc/effects/chorus.cpp index 28514a9b..7a473723 100644 --- a/alc/effects/chorus.cpp +++ b/alc/effects/chorus.cpp @@ -158,7 +158,7 @@ void ChorusState::update(const ALCcontext *Context, const ALeffectslot *Slot, co /* The LFO depth is scaled to be relative to the sample delay. Clamp the * delay and depth to allow enough padding for resampling. */ - const ALCdevice *device{Context->Device}; + const ALCdevice *device{Context->mDevice}; const auto frequency = static_cast(device->Frequency); mDelay = maxi(float2int(props->Chorus.Delay*frequency*FRACTIONONE + 0.5f), mindelay); mDepth = minf(props->Chorus.Depth * mDelay, static_cast(mDelay - mindelay)); diff --git a/alc/effects/distortion.cpp b/alc/effects/distortion.cpp index a74575d4..79278f0d 100644 --- a/alc/effects/distortion.cpp +++ b/alc/effects/distortion.cpp @@ -64,7 +64,7 @@ ALboolean DistortionState::deviceUpdate(const ALCdevice*) void DistortionState::update(const ALCcontext *context, const ALeffectslot *slot, const EffectProps *props, const EffectTarget target) { - const ALCdevice *device{context->Device}; + const ALCdevice *device{context->mDevice}; /* Store waveshaper edge settings. */ const ALfloat edge{ diff --git a/alc/effects/echo.cpp b/alc/effects/echo.cpp index 8e309cbb..9a43c037 100644 --- a/alc/effects/echo.cpp +++ b/alc/effects/echo.cpp @@ -94,7 +94,7 @@ ALboolean EchoState::deviceUpdate(const ALCdevice *Device) void EchoState::update(const ALCcontext *context, const ALeffectslot *slot, const EffectProps *props, const EffectTarget target) { - const ALCdevice *device = context->Device; + const ALCdevice *device = context->mDevice; const auto frequency = static_cast(device->Frequency); mTap[0].delay = maxi(float2int(props->Echo.Delay*frequency + 0.5f), 1); diff --git a/alc/effects/equalizer.cpp b/alc/effects/equalizer.cpp index 0ae3a25f..25ccf264 100644 --- a/alc/effects/equalizer.cpp +++ b/alc/effects/equalizer.cpp @@ -112,7 +112,7 @@ ALboolean EqualizerState::deviceUpdate(const ALCdevice*) void EqualizerState::update(const ALCcontext *context, const ALeffectslot *slot, const EffectProps *props, const EffectTarget target) { - const ALCdevice *device = context->Device; + const ALCdevice *device = context->mDevice; auto frequency = static_cast(device->Frequency); ALfloat gain, f0norm; diff --git a/alc/effects/fshifter.cpp b/alc/effects/fshifter.cpp index b36c53a1..9b204d2e 100644 --- a/alc/effects/fshifter.cpp +++ b/alc/effects/fshifter.cpp @@ -109,7 +109,7 @@ ALboolean FshifterState::deviceUpdate(const ALCdevice*) void FshifterState::update(const ALCcontext *context, const ALeffectslot *slot, const EffectProps *props, const EffectTarget target) { - const ALCdevice *device{context->Device}; + const ALCdevice *device{context->mDevice}; ALfloat step{props->Fshifter.Frequency / static_cast(device->Frequency)}; mPhaseStep = fastf2i(minf(step, 0.5f) * FRACTIONONE); diff --git a/alc/effects/modulator.cpp b/alc/effects/modulator.cpp index 5f28e1da..bd63c56c 100644 --- a/alc/effects/modulator.cpp +++ b/alc/effects/modulator.cpp @@ -110,7 +110,7 @@ ALboolean ModulatorState::deviceUpdate(const ALCdevice*) void ModulatorState::update(const ALCcontext *context, const ALeffectslot *slot, const EffectProps *props, const EffectTarget target) { - const ALCdevice *device{context->Device}; + const ALCdevice *device{context->mDevice}; const float step{props->Modulator.Frequency / static_cast(device->Frequency)}; mStep = fastf2i(clampf(step*WAVEFORM_FRACONE, 0.0f, ALfloat{WAVEFORM_FRACONE-1})); diff --git a/alc/effects/reverb.cpp b/alc/effects/reverb.cpp index 82b04436..bc4995ff 100644 --- a/alc/effects/reverb.cpp +++ b/alc/effects/reverb.cpp @@ -906,8 +906,8 @@ void ReverbState::update3DPanning(const ALfloat *ReflectionsPan, const ALfloat * void ReverbState::update(const ALCcontext *Context, const ALeffectslot *Slot, const EffectProps *props, const EffectTarget target) { - const ALCdevice *Device{Context->Device}; - const ALlistener &Listener = Context->Listener; + const ALCdevice *Device{Context->mDevice}; + const ALlistener &Listener = Context->mListener; const auto frequency = static_cast(Device->Frequency); /* Calculate the master filters */ diff --git a/alc/effects/vmorpher.cpp b/alc/effects/vmorpher.cpp index d1bf8587..ae8c98e1 100644 --- a/alc/effects/vmorpher.cpp +++ b/alc/effects/vmorpher.cpp @@ -210,7 +210,7 @@ ALboolean VmorpherState::deviceUpdate(const ALCdevice* /*device*/) void VmorpherState::update(const ALCcontext *context, const ALeffectslot *slot, const EffectProps *props, const EffectTarget target) { - const ALCdevice *device{context->Device}; + const ALCdevice *device{context->mDevice}; const ALfloat frequency{static_cast(device->Frequency)}; const ALfloat step{props->Vmorpher.Rate / static_cast(device->Frequency)}; mStep = fastf2i(clampf(step*WAVEFORM_FRACONE, 0.0f, ALfloat{WAVEFORM_FRACONE-1})); diff --git a/alc/mixvoice.cpp b/alc/mixvoice.cpp index 0d7b2cee..881759c0 100644 --- a/alc/mixvoice.cpp +++ b/alc/mixvoice.cpp @@ -291,10 +291,10 @@ constexpr ALshort aLawDecompressionTable[256] = { void SendSourceStoppedEvent(ALCcontext *context, ALuint id) { - ALbitfieldSOFT enabledevt{context->EnabledEvts.load(std::memory_order_acquire)}; + ALbitfieldSOFT enabledevt{context->mEnabledEvts.load(std::memory_order_acquire)}; if(!(enabledevt&EventType_SourceStateChange)) return; - RingBuffer *ring{context->AsyncEvents.get()}; + RingBuffer *ring{context->mAsyncEvents.get()}; auto evt_vec = ring->getWriteVector(); if(evt_vec.first.len < 1) return; @@ -303,7 +303,7 @@ void SendSourceStoppedEvent(ALCcontext *context, ALuint id) evt->u.srcstate.state = AL_STOPPED; ring->writeAdvance(1); - context->EventSem.post(); + context->mEventSem.post(); } @@ -544,7 +544,7 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc ASSUME(SampleSize > 0); ASSUME(increment > 0); - ALCdevice *Device{Context->Device}; + ALCdevice *Device{Context->mDevice}; const ALsizei NumSends{Device->NumAuxSends}; const ALsizei IrSize{Device->mHrtf ? Device->mHrtf->irSize : 0}; @@ -929,10 +929,10 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc std::atomic_thread_fence(std::memory_order_release); /* Send any events now, after the position/buffer info was updated. */ - ALbitfieldSOFT enabledevt{Context->EnabledEvts.load(std::memory_order_acquire)}; + ALbitfieldSOFT enabledevt{Context->mEnabledEvts.load(std::memory_order_acquire)}; if(buffers_done > 0 && (enabledevt&EventType_BufferCompleted)) { - RingBuffer *ring{Context->AsyncEvents.get()}; + RingBuffer *ring{Context->mAsyncEvents.get()}; auto evt_vec = ring->getWriteVector(); if(evt_vec.first.len > 0) { @@ -940,7 +940,7 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc evt->u.bufcomp.id = SourceID; evt->u.bufcomp.count = buffers_done; ring->writeAdvance(1); - Context->EventSem.post(); + Context->mEventSem.post(); } } -- cgit v1.2.3 From ac554de67d5eb353283c3359bbac15fb4ddad7d9 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 30 Jul 2019 14:13:05 -0700 Subject: Turn some functions into methods --- al/source.cpp | 2 +- al/state.cpp | 4 +-- alc/alc.cpp | 77 ++++++++++++++++++++++----------------------------------- alc/alcmain.h | 3 --- alc/alcontext.h | 22 ++++++++++++----- 5 files changed, 48 insertions(+), 60 deletions(-) (limited to 'al/source.cpp') diff --git a/al/source.cpp b/al/source.cpp index 39b635a4..35d3bb84 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -2828,7 +2828,7 @@ START_API_FUNC alloc_count); const size_t newcount{context->mVoices->size() + alloc_count}; - AllocateVoices(context.get(), newcount); + context->allocVoices(newcount); } context->mVoiceCount.fetch_add(need_voices, std::memory_order_relaxed); diff --git a/al/state.cpp b/al/state.cpp index b1885f5c..903ab614 100644 --- a/al/state.cpp +++ b/al/state.cpp @@ -775,7 +775,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCcontext_DeferUpdates(context.get()); + context->deferUpdates(); } END_API_FUNC @@ -785,7 +785,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCcontext_ProcessUpdates(context.get()); + context->processUpdates(); } END_API_FUNC diff --git a/alc/alc.cpp b/alc/alc.cpp index 49ecf54b..db5fd094 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -1591,44 +1591,29 @@ void SetDefaultChannelOrder(ALCdevice *device) } -/* ALCcontext_DeferUpdates - * - * Defers/suspends updates for the given context's listener and sources. This - * does *NOT* stop mixing, but rather prevents certain property changes from - * taking effect. - */ -void ALCcontext_DeferUpdates(ALCcontext *context) +void ALCcontext::processUpdates() { - context->mDeferUpdates.store(true); -} - -/* ALCcontext_ProcessUpdates - * - * Resumes update processing after being deferred. - */ -void ALCcontext_ProcessUpdates(ALCcontext *context) -{ - std::lock_guard _{context->mPropLock}; - if(context->mDeferUpdates.exchange(false)) + std::lock_guard _{mPropLock}; + if(mDeferUpdates.exchange(false)) { /* Tell the mixer to stop applying updates, then wait for any active * updating to finish, before providing updates. */ - context->mHoldUpdates.store(true, std::memory_order_release); - while((context->mUpdateCount.load(std::memory_order_acquire)&1) != 0) + mHoldUpdates.store(true, std::memory_order_release); + while((mUpdateCount.load(std::memory_order_acquire)&1) != 0) std::this_thread::yield(); - if(!context->mPropsClean.test_and_set(std::memory_order_acq_rel)) - UpdateContextProps(context); - if(!context->mListener.PropsClean.test_and_set(std::memory_order_acq_rel)) - UpdateListenerProps(context); - UpdateAllEffectSlotProps(context); - UpdateAllSourceProps(context); + if(!mPropsClean.test_and_set(std::memory_order_acq_rel)) + UpdateContextProps(this); + if(!mListener.PropsClean.test_and_set(std::memory_order_acq_rel)) + UpdateListenerProps(this); + UpdateAllEffectSlotProps(this); + UpdateAllSourceProps(this); /* Now with all updates declared, let the mixer continue applying them * so they all happen at once. */ - context->mHoldUpdates.store(false, std::memory_order_release); + mHoldUpdates.store(false, std::memory_order_release); } } @@ -2559,12 +2544,12 @@ static bool ReleaseContext(ALCcontext *context, ALCdevice *device) { WARN("%p released while current on thread\n", context); LocalContext.set(nullptr); - ALCcontext_DecRef(context); + context->decRef(); } ALCcontext *origctx{context}; if(GlobalContext.compare_exchange_strong(origctx, nullptr)) - ALCcontext_DecRef(context); + context->decRef(); bool ret{}; { @@ -2616,11 +2601,11 @@ static void ALCcontext_IncRef(ALCcontext *context) TRACEREF("ALCcontext %p increasing refcount to %u\n", context, ref); } -void ALCcontext_DecRef(ALCcontext *context) +void ALCcontext::decRef() noexcept { - auto ref = DecrementRef(&context->mRef); - TRACEREF("ALCcontext %p decreasing refcount to %u\n", context, ref); - if(UNLIKELY(ref == 0)) delete context; + auto ref = DecrementRef(&mRef); + TRACEREF("ALCcontext %p decreasing refcount to %u\n", this, ref); + if(UNLIKELY(ref == 0)) delete this; } /* VerifyContext @@ -2659,12 +2644,11 @@ ContextRef GetContextRef(void) } -void AllocateVoices(ALCcontext *context, size_t num_voices) +void ALCcontext::allocVoices(size_t num_voices) { - ALCdevice *device{context->mDevice}; - const ALsizei num_sends{device->NumAuxSends}; + const ALsizei num_sends{mDevice->NumAuxSends}; - if(context->mVoices && num_voices == context->mVoices->size()) + if(mVoices && num_voices == mVoices->size()) return; std::unique_ptr> voices; @@ -2673,12 +2657,11 @@ void AllocateVoices(ALCcontext *context, size_t num_voices) voices.reset(new (ptr) al::FlexArray{num_voices}); } - const size_t v_count{minz(context->mVoiceCount.load(std::memory_order_relaxed), num_voices)}; - if(context->mVoices) + const size_t v_count{minz(mVoiceCount.load(std::memory_order_relaxed), num_voices)}; + if(mVoices) { /* Copy the old voice data to the new storage. */ - auto viter = std::move(context->mVoices->begin(), context->mVoices->begin()+v_count, - voices->begin()); + auto viter = std::move(mVoices->begin(), mVoices->begin()+v_count, voices->begin()); /* Clear extraneous property set sends. */ auto clear_sends = [num_sends](ALvoice &voice) -> void @@ -2697,8 +2680,8 @@ void AllocateVoices(ALCcontext *context, size_t num_voices) std::for_each(voices->begin(), viter, clear_sends); } - context->mVoices = std::move(voices); - context->mVoiceCount.store(static_cast(v_count), std::memory_order_relaxed); + mVoices = std::move(voices); + mVoiceCount.store(static_cast(v_count), std::memory_order_relaxed); } @@ -2734,7 +2717,7 @@ START_API_FUNC if(!ctx) alcSetError(nullptr, ALC_INVALID_CONTEXT); else - ALCcontext_DeferUpdates(ctx.get()); + ctx->deferUpdates(); } END_API_FUNC @@ -2752,7 +2735,7 @@ START_API_FUNC if(!ctx) alcSetError(nullptr, ALC_INVALID_CONTEXT); else - ALCcontext_ProcessUpdates(ctx.get()); + ctx->processUpdates(); } END_API_FUNC @@ -3452,11 +3435,9 @@ START_API_FUNC alcSetError(dev.get(), err); if(err == ALC_INVALID_DEVICE) aluHandleDisconnect(dev.get(), "Device update failure"); - statelock.unlock(); - return nullptr; } - AllocateVoices(context.get(), 256); + context->allocVoices(256); if(DefaultEffect.type != AL_EFFECT_NULL && dev->Type == Playback) { diff --git a/alc/alcmain.h b/alc/alcmain.h index 85f37e73..f69dc755 100644 --- a/alc/alcmain.h +++ b/alc/alcmain.h @@ -461,9 +461,6 @@ struct ALCdevice { #define RECORD_THREAD_NAME "alsoft-record" -void AllocateVoices(ALCcontext *context, size_t num_voices); - - extern ALint RTPrioLevel; void SetRTPriority(void); diff --git a/alc/alcontext.h b/alc/alcontext.h index 8156c345..9c2ce4a3 100644 --- a/alc/alcontext.h +++ b/alc/alcontext.h @@ -144,16 +144,26 @@ struct ALCcontext { ALCcontext& operator=(const ALCcontext&) = delete; ~ALCcontext(); + void decRef() noexcept; + + void allocVoices(size_t num_voices); + + /** + * Defers/suspends updates for the given context's listener and sources. + * This does *NOT* stop mixing, but rather prevents certain property + * changes from taking effect. + */ + void deferUpdates() noexcept + { mDeferUpdates.store(true); } + + /** Resumes update processing after being deferred. */ + void processUpdates(); + DEF_NEWDEL(ALCcontext) }; -void ALCcontext_DecRef(ALCcontext *context); - void UpdateContextProps(ALCcontext *context); -void ALCcontext_DeferUpdates(ALCcontext *context); -void ALCcontext_ProcessUpdates(ALCcontext *context); - /* Simple RAII context reference. Takes the reference of the provided * ALCcontext, and decrements it when leaving scope. Movable (transfer @@ -165,7 +175,7 @@ class ContextRef { void reset() noexcept { if(mCtx) - ALCcontext_DecRef(mCtx); + mCtx->decRef(); mCtx = nullptr; } -- cgit v1.2.3 From f286c3fa3857579a6c7cf84f32ff953e498577bf Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 30 Jul 2019 21:32:05 -0700 Subject: Move another function to a ALCcontext method --- CMakeLists.txt | 1 - al/auxeffectslot.cpp | 77 ++++++++------- al/buffer.cpp | 185 ++++++++++++++++++------------------ al/effect.cpp | 29 +++--- al/error.cpp | 19 ++-- al/error.h | 24 ----- al/event.cpp | 7 +- al/extension.cpp | 3 +- al/filter.cpp | 81 ++++++++-------- al/listener.cpp | 52 +++++----- al/source.cpp | 230 ++++++++++++++++++++++----------------------- al/state.cpp | 57 ++++++----- alc/alc.cpp | 1 - alc/alcontext.h | 23 +++-- alc/effects/autowah.cpp | 13 ++- alc/effects/chorus.cpp | 17 ++-- alc/effects/compressor.cpp | 17 ++-- alc/effects/dedicated.cpp | 13 ++- alc/effects/distortion.cpp | 15 ++- alc/effects/echo.cpp | 13 ++- alc/effects/equalizer.cpp | 13 ++- alc/effects/fshifter.cpp | 13 ++- alc/effects/modulator.cpp | 9 +- alc/effects/null.cpp | 10 +- alc/effects/pshifter.cpp | 15 +-- alc/effects/reverb.cpp | 23 ++--- alc/effects/vmorpher.cpp | 17 ++-- 27 files changed, 467 insertions(+), 510 deletions(-) delete mode 100644 al/error.h (limited to 'al/source.cpp') diff --git a/CMakeLists.txt b/CMakeLists.txt index db43215d..e72f2a01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -612,7 +612,6 @@ SET(OPENAL_OBJS al/effect.cpp al/effect.h al/error.cpp - al/error.h al/extension.cpp al/filter.cpp al/filter.h diff --git a/al/auxeffectslot.cpp b/al/auxeffectslot.cpp index 880c970d..2d10efde 100644 --- a/al/auxeffectslot.cpp +++ b/al/auxeffectslot.cpp @@ -40,7 +40,6 @@ #include "alspan.h" #include "alu.h" #include "effect.h" -#include "error.h" #include "fpu_modes.h" #include "inprogext.h" #include "logging.h" @@ -164,7 +163,7 @@ ALeffectslot *AllocEffectSlot(ALCcontext *context) std::lock_guard _{context->mEffectSlotLock}; if(context->mNumEffectSlots >= device->AuxiliaryEffectSlotMax) { - alSetError(context, AL_OUT_OF_MEMORY, "Exceeding %u effect slot limit", + context->setError(AL_OUT_OF_MEMORY, "Exceeding %u effect slot limit", device->AuxiliaryEffectSlotMax); return nullptr; } @@ -187,7 +186,7 @@ ALeffectslot *AllocEffectSlot(ALCcontext *context) */ if(UNLIKELY(context->mEffectSlotList.size() >= 1<<25)) { - alSetError(context, AL_OUT_OF_MEMORY, "Too many effect slots allocated"); + context->setError(AL_OUT_OF_MEMORY, "Too many effect slots allocated"); return nullptr; } context->mEffectSlotList.emplace_back(); @@ -198,7 +197,7 @@ ALeffectslot *AllocEffectSlot(ALCcontext *context) if(UNLIKELY(!sublist->EffectSlots)) { context->mEffectSlotList.pop_back(); - alSetError(context, AL_OUT_OF_MEMORY, "Failed to allocate effect slot batch"); + context->setError(AL_OUT_OF_MEMORY, "Failed to allocate effect slot batch"); return nullptr; } @@ -211,7 +210,7 @@ ALeffectslot *AllocEffectSlot(ALCcontext *context) if(err != AL_NO_ERROR) { al::destroy_at(slot); - alSetError(context, err, "Effect slot object initialization failed"); + context->setError(err, "Effect slot object initialization failed"); return nullptr; } aluInitEffectPanning(slot, device); @@ -264,7 +263,7 @@ START_API_FUNC if(UNLIKELY(!context)) return; if(n < 0) - SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Generating %d effect slots", n); + SETERR_RETURN(context, AL_INVALID_VALUE,, "Generating %d effect slots", n); if(n == 0) return; if(n == 1) @@ -307,7 +306,7 @@ START_API_FUNC if(UNLIKELY(!context)) return; if(n < 0) - SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Deleting %d effect slots", n); + SETERR_RETURN(context, AL_INVALID_VALUE,, "Deleting %d effect slots", n); if(n == 0) return; std::lock_guard _{context->mEffectSlotLock}; @@ -318,12 +317,12 @@ START_API_FUNC ALeffectslot *slot{LookupEffectSlot(context.get(), id)}; if(!slot) { - alSetError(context.get(), AL_INVALID_NAME, "Invalid effect slot ID %u", id); + context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", id); return true; } if(ReadRef(&slot->ref) != 0) { - alSetError(context.get(), AL_INVALID_NAME, "Deleting in-use effect slot %u", id); + context->setError(AL_INVALID_NAME, "Deleting in-use effect slot %u", id); return true; } return false; @@ -369,7 +368,7 @@ START_API_FUNC std::lock_guard __{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); if(UNLIKELY(!slot)) - SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); + SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); ALeffectslot *target{}; ALCdevice *device{}; @@ -382,34 +381,34 @@ START_API_FUNC { std::lock_guard ___{device->EffectLock}; ALeffect *effect{value ? LookupEffect(device, value) : nullptr}; if(!(value == 0 || effect != nullptr)) - SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Invalid effect ID %u", value); + SETERR_RETURN(context, AL_INVALID_VALUE,, "Invalid effect ID %u", value); err = InitializeEffect(context.get(), slot, effect); } if(err != AL_NO_ERROR) { - alSetError(context.get(), err, "Effect initialization failed"); + context->setError(err, "Effect initialization failed"); return; } break; case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO: if(!(value == AL_TRUE || value == AL_FALSE)) - SETERR_RETURN(context.get(), AL_INVALID_VALUE,, - "Effect slot auxiliary send auto out of range"); + SETERR_RETURN(context, AL_INVALID_VALUE,, + "Effect slot auxiliary send auto out of range"); slot->AuxSendAuto = value; break; case AL_EFFECTSLOT_TARGET_SOFT: target = (value ? LookupEffectSlot(context.get(), value) : nullptr); if(value && !target) - SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Invalid effect slot target ID"); + SETERR_RETURN(context, AL_INVALID_VALUE,, "Invalid effect slot target ID"); if(target) { ALeffectslot *checker{target}; while(checker && checker != slot) checker = checker->Target; if(checker) - SETERR_RETURN(context.get(), AL_INVALID_OPERATION,, + SETERR_RETURN(context, AL_INVALID_OPERATION,, "Setting target of effect slot ID %u to %u creates circular chain", slot->id, target->id); } @@ -431,8 +430,8 @@ START_API_FUNC break; default: - SETERR_RETURN(context.get(), AL_INVALID_ENUM,, - "Invalid effect slot integer property 0x%04x", param); + SETERR_RETURN(context, AL_INVALID_ENUM,, "Invalid effect slot integer property 0x%04x", + param); } DO_UPDATEPROPS(); } @@ -456,13 +455,13 @@ START_API_FUNC std::lock_guard _{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); if(UNLIKELY(!slot)) - SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); + SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); switch(param) { default: - SETERR_RETURN(context.get(), AL_INVALID_ENUM,, - "Invalid effect slot integer-vector property 0x%04x", param); + SETERR_RETURN(context, AL_INVALID_ENUM,, + "Invalid effect slot integer-vector property 0x%04x", param); } } END_API_FUNC @@ -477,19 +476,19 @@ START_API_FUNC std::lock_guard __{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); if(UNLIKELY(!slot)) - SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); + SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); switch(param) { case AL_EFFECTSLOT_GAIN: if(!(value >= 0.0f && value <= 1.0f)) - SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Effect slot gain out of range"); + SETERR_RETURN(context, AL_INVALID_VALUE,, "Effect slot gain out of range"); slot->Gain = value; break; default: - SETERR_RETURN(context.get(), AL_INVALID_ENUM,, "Invalid effect slot float property 0x%04x", - param); + SETERR_RETURN(context, AL_INVALID_ENUM,, "Invalid effect slot float property 0x%04x", + param); } DO_UPDATEPROPS(); } @@ -511,13 +510,13 @@ START_API_FUNC std::lock_guard _{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); if(UNLIKELY(!slot)) - SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); + SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); switch(param) { default: - SETERR_RETURN(context.get(), AL_INVALID_ENUM,, - "Invalid effect slot float-vector property 0x%04x", param); + SETERR_RETURN(context, AL_INVALID_ENUM,, + "Invalid effect slot float-vector property 0x%04x", param); } } END_API_FUNC @@ -532,7 +531,7 @@ START_API_FUNC std::lock_guard _{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); if(UNLIKELY(!slot)) - SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); + SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); switch(param) { @@ -545,8 +544,7 @@ START_API_FUNC break; default: - SETERR_RETURN(context.get(), AL_INVALID_ENUM,, - "Invalid effect slot integer property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid effect slot integer property 0x%04x", param); } } END_API_FUNC @@ -569,13 +567,13 @@ START_API_FUNC std::lock_guard _{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); if(UNLIKELY(!slot)) - SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); + SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); switch(param) { default: - SETERR_RETURN(context.get(), AL_INVALID_ENUM,, - "Invalid effect slot integer-vector property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid effect slot integer-vector property 0x%04x", + param); } } END_API_FUNC @@ -589,7 +587,7 @@ START_API_FUNC std::lock_guard _{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); if(UNLIKELY(!slot)) - SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); + SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); switch(param) { @@ -598,8 +596,7 @@ START_API_FUNC break; default: - SETERR_RETURN(context.get(), AL_INVALID_ENUM,, - "Invalid effect slot float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid effect slot float property 0x%04x", param); } } END_API_FUNC @@ -620,13 +617,13 @@ START_API_FUNC std::lock_guard _{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); if(UNLIKELY(!slot)) - SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); + SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); switch(param) { default: - SETERR_RETURN(context.get(), AL_INVALID_ENUM,, - "Invalid effect slot float-vector property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid effect slot float-vector property 0x%04x", + param); } } END_API_FUNC diff --git a/al/buffer.cpp b/al/buffer.cpp index d4f2d179..d6d743d0 100644 --- a/al/buffer.cpp +++ b/al/buffer.cpp @@ -48,7 +48,6 @@ #include "alnumeric.h" #include "aloptional.h" #include "atomic.h" -#include "error.h" #include "inprogext.h" #include "opthelpers.h" @@ -269,7 +268,7 @@ ALbuffer *AllocBuffer(ALCcontext *context) */ if(UNLIKELY(device->BufferList.size() >= 1<<25)) { - alSetError(context, AL_OUT_OF_MEMORY, "Too many buffers allocated"); + context->setError(AL_OUT_OF_MEMORY, "Too many buffers allocated"); return nullptr; } device->BufferList.emplace_back(); @@ -279,7 +278,7 @@ ALbuffer *AllocBuffer(ALCcontext *context) if(UNLIKELY(!sublist->Buffers)) { device->BufferList.pop_back(); - alSetError(context, AL_OUT_OF_MEMORY, "Failed to allocate buffer batch"); + context->setError(AL_OUT_OF_MEMORY, "Failed to allocate buffer batch"); return nullptr; } @@ -611,7 +610,7 @@ START_API_FUNC if(UNLIKELY(n < 0)) { - alSetError(context.get(), AL_INVALID_VALUE, "Generating %d buffers", n); + context->setError(AL_INVALID_VALUE, "Generating %d buffers", n); return; } @@ -651,7 +650,7 @@ START_API_FUNC if(UNLIKELY(n < 0)) { - alSetError(context.get(), AL_INVALID_VALUE, "Deleting %d buffers", n); + context->setError(AL_INVALID_VALUE, "Deleting %d buffers", n); return; } if(UNLIKELY(n == 0)) @@ -669,12 +668,12 @@ START_API_FUNC ALbuffer *ALBuf = LookupBuffer(device, bid); if(UNLIKELY(!ALBuf)) { - alSetError(context.get(), AL_INVALID_NAME, "Invalid buffer ID %u", bid); + context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", bid); return true; } if(UNLIKELY(ReadRef(&ALBuf->ref) != 0)) { - alSetError(context.get(), AL_INVALID_OPERATION, "Deleting in-use buffer %u", bid); + context->setError(AL_INVALID_OPERATION, "Deleting in-use buffer %u", bid); return true; } return false; @@ -726,22 +725,22 @@ START_API_FUNC ALbuffer *albuf = LookupBuffer(device, buffer); if(UNLIKELY(!albuf)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid buffer ID %u", buffer); + context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); else if(UNLIKELY(size < 0)) - alSetError(context.get(), AL_INVALID_VALUE, "Negative storage size %d", size); + context->setError(AL_INVALID_VALUE, "Negative storage size %d", size); else if(UNLIKELY(freq < 1)) - alSetError(context.get(), AL_INVALID_VALUE, "Invalid sample rate %d", freq); + context->setError(AL_INVALID_VALUE, "Invalid sample rate %d", freq); else if(UNLIKELY((flags&INVALID_STORAGE_MASK) != 0)) - alSetError(context.get(), AL_INVALID_VALUE, "Invalid storage flags 0x%x", - flags&INVALID_STORAGE_MASK); + context->setError(AL_INVALID_VALUE, "Invalid storage flags 0x%x", + flags&INVALID_STORAGE_MASK); else if(UNLIKELY((flags&AL_MAP_PERSISTENT_BIT_SOFT) && !(flags&MAP_READ_WRITE_FLAGS))) - alSetError(context.get(), AL_INVALID_VALUE, - "Declaring persistently mapped storage without read or write access"); + context->setError(AL_INVALID_VALUE, + "Declaring persistently mapped storage without read or write access"); else { auto usrfmt = DecomposeUserFormat(format); if(UNLIKELY(!usrfmt)) - alSetError(context.get(), AL_INVALID_ENUM, "Invalid format 0x%04x", format); + context->setError(AL_INVALID_ENUM, "Invalid format 0x%04x", format); else LoadData(context.get(), albuf, freq, size, usrfmt->channels, usrfmt->type, static_cast(data), flags); @@ -760,33 +759,33 @@ START_API_FUNC ALbuffer *albuf = LookupBuffer(device, buffer); if(UNLIKELY(!albuf)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid buffer ID %u", buffer); + context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); else if(UNLIKELY((access&INVALID_MAP_FLAGS) != 0)) - alSetError(context.get(), AL_INVALID_VALUE, "Invalid map flags 0x%x", access&INVALID_MAP_FLAGS); + context->setError(AL_INVALID_VALUE, "Invalid map flags 0x%x", access&INVALID_MAP_FLAGS); else if(UNLIKELY(!(access&MAP_READ_WRITE_FLAGS))) - alSetError(context.get(), AL_INVALID_VALUE, "Mapping buffer %u without read or write access", - buffer); + context->setError(AL_INVALID_VALUE, "Mapping buffer %u without read or write access", + buffer); else { ALbitfieldSOFT unavailable = (albuf->Access^access) & access; if(UNLIKELY(ReadRef(&albuf->ref) != 0 && !(access&AL_MAP_PERSISTENT_BIT_SOFT))) - alSetError(context.get(), AL_INVALID_OPERATION, - "Mapping in-use buffer %u without persistent mapping", buffer); + context->setError(AL_INVALID_OPERATION, + "Mapping in-use buffer %u without persistent mapping", buffer); else if(UNLIKELY(albuf->MappedAccess != 0)) - alSetError(context.get(), AL_INVALID_OPERATION, "Mapping already-mapped buffer %u", buffer); + context->setError(AL_INVALID_OPERATION, "Mapping already-mapped buffer %u", buffer); else if(UNLIKELY((unavailable&AL_MAP_READ_BIT_SOFT))) - alSetError(context.get(), AL_INVALID_VALUE, - "Mapping buffer %u for reading without read access", buffer); + context->setError(AL_INVALID_VALUE, + "Mapping buffer %u for reading without read access", buffer); else if(UNLIKELY((unavailable&AL_MAP_WRITE_BIT_SOFT))) - alSetError(context.get(), AL_INVALID_VALUE, - "Mapping buffer %u for writing without write access", buffer); + context->setError(AL_INVALID_VALUE, + "Mapping buffer %u for writing without write access", buffer); else if(UNLIKELY((unavailable&AL_MAP_PERSISTENT_BIT_SOFT))) - alSetError(context.get(), AL_INVALID_VALUE, - "Mapping buffer %u persistently without persistent access", buffer); + context->setError(AL_INVALID_VALUE, + "Mapping buffer %u persistently without persistent access", buffer); else if(UNLIKELY(offset < 0 || offset >= albuf->OriginalSize || length <= 0 || length > albuf->OriginalSize - offset)) - alSetError(context.get(), AL_INVALID_VALUE, "Mapping invalid range %d+%d for buffer %u", - offset, length, buffer); + context->setError(AL_INVALID_VALUE, "Mapping invalid range %d+%d for buffer %u", + offset, length, buffer); else { void *retval = albuf->mData.data() + offset; @@ -812,9 +811,9 @@ START_API_FUNC ALbuffer *albuf = LookupBuffer(device, buffer); if(UNLIKELY(!albuf)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid buffer ID %u", buffer); + context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); else if(albuf->MappedAccess == 0) - alSetError(context.get(), AL_INVALID_OPERATION, "Unmapping unmapped buffer %u", buffer); + context->setError(AL_INVALID_OPERATION, "Unmapping unmapped buffer %u", buffer); else { albuf->MappedAccess = 0; @@ -835,15 +834,15 @@ START_API_FUNC ALbuffer *albuf = LookupBuffer(device, buffer); if(UNLIKELY(!albuf)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid buffer ID %u", buffer); + context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); else if(UNLIKELY(!(albuf->MappedAccess&AL_MAP_WRITE_BIT_SOFT))) - alSetError(context.get(), AL_INVALID_OPERATION, - "Flushing buffer %u while not mapped for writing", buffer); + context->setError(AL_INVALID_OPERATION, "Flushing buffer %u while not mapped for writing", + buffer); else if(UNLIKELY(offset < albuf->MappedOffset || offset >= albuf->MappedOffset+albuf->MappedSize || length <= 0 || length > albuf->MappedOffset+albuf->MappedSize-offset)) - alSetError(context.get(), AL_INVALID_VALUE, "Flushing invalid range %d+%d on buffer %u", - offset, length, buffer); + context->setError(AL_INVALID_VALUE, "Flushing invalid range %d+%d on buffer %u", offset, + length, buffer); else { /* FIXME: Need to use some method of double-buffering for the mixer and @@ -868,32 +867,30 @@ START_API_FUNC ALbuffer *albuf = LookupBuffer(device, buffer); if(UNLIKELY(!albuf)) { - alSetError(context.get(), AL_INVALID_NAME, "Invalid buffer ID %u", buffer); + context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); return; } auto usrfmt = DecomposeUserFormat(format); if(UNLIKELY(!usrfmt)) { - alSetError(context.get(), AL_INVALID_ENUM, "Invalid format 0x%04x", format); + context->setError(AL_INVALID_ENUM, "Invalid format 0x%04x", format); return; } ALsizei unpack_align{albuf->UnpackAlign.load()}; ALsizei align{SanitizeAlignment(usrfmt->type, unpack_align)}; if(UNLIKELY(align < 1)) - alSetError(context.get(), AL_INVALID_VALUE, "Invalid unpack alignment %d", unpack_align); + context->setError(AL_INVALID_VALUE, "Invalid unpack alignment %d", unpack_align); else if(UNLIKELY(long{usrfmt->channels} != long{albuf->mFmtChannels} || usrfmt->type != albuf->OriginalType)) - alSetError(context.get(), AL_INVALID_ENUM, - "Unpacking data with mismatched format"); + context->setError(AL_INVALID_ENUM, "Unpacking data with mismatched format"); else if(UNLIKELY(align != albuf->OriginalAlign)) - alSetError(context.get(), AL_INVALID_VALUE, - "Unpacking data with alignment %u does not match original alignment %u", - align, albuf->OriginalAlign); + context->setError(AL_INVALID_VALUE, + "Unpacking data with alignment %u does not match original alignment %u", align, + albuf->OriginalAlign); else if(UNLIKELY(albuf->MappedAccess != 0)) - alSetError(context.get(), AL_INVALID_OPERATION, "Unpacking data into mapped buffer %u", - buffer); + context->setError(AL_INVALID_OPERATION, "Unpacking data into mapped buffer %u", buffer); else { ALsizei num_chans{ChannelsFromFmt(albuf->mFmtChannels)}; @@ -906,14 +903,14 @@ START_API_FUNC if(UNLIKELY(offset < 0 || length < 0 || offset > albuf->OriginalSize || length > albuf->OriginalSize-offset)) - alSetError(context.get(), AL_INVALID_VALUE, "Invalid data sub-range %d+%d on buffer %u", - offset, length, buffer); + context->setError(AL_INVALID_VALUE, "Invalid data sub-range %d+%d on buffer %u", + offset, length, buffer); else if(UNLIKELY((offset%byte_align) != 0)) - alSetError(context.get(), AL_INVALID_VALUE, + context->setError(AL_INVALID_VALUE, "Sub-range offset %d is not a multiple of frame size %d (%d unpack alignment)", offset, byte_align, align); else if(UNLIKELY((length%byte_align) != 0)) - alSetError(context.get(), AL_INVALID_VALUE, + context->setError(AL_INVALID_VALUE, "Sub-range length %d is not a multiple of frame size %d (%d unpack alignment)", length, byte_align, align); else @@ -948,7 +945,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - alSetError(context.get(), AL_INVALID_OPERATION, "alBufferSamplesSOFT not supported"); + context->setError(AL_INVALID_OPERATION, "alBufferSamplesSOFT not supported"); } END_API_FUNC @@ -959,7 +956,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - alSetError(context.get(), AL_INVALID_OPERATION, "alBufferSubSamplesSOFT not supported"); + context->setError(AL_INVALID_OPERATION, "alBufferSubSamplesSOFT not supported"); } END_API_FUNC @@ -970,7 +967,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - alSetError(context.get(), AL_INVALID_OPERATION, "alGetBufferSamplesSOFT not supported"); + context->setError(AL_INVALID_OPERATION, "alGetBufferSamplesSOFT not supported"); } END_API_FUNC @@ -980,7 +977,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(!context) return AL_FALSE; - alSetError(context.get(), AL_INVALID_OPERATION, "alIsBufferFormatSupportedSOFT not supported"); + context->setError(AL_INVALID_OPERATION, "alIsBufferFormatSupportedSOFT not supported"); return AL_FALSE; } END_API_FUNC @@ -996,11 +993,11 @@ START_API_FUNC std::lock_guard _{device->BufferLock}; if(UNLIKELY(LookupBuffer(device, buffer) == nullptr)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid buffer ID %u", buffer); + context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); else switch(param) { default: - alSetError(context.get(), AL_INVALID_ENUM, "Invalid buffer float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid buffer float property 0x%04x", param); } } END_API_FUNC @@ -1016,11 +1013,11 @@ START_API_FUNC std::lock_guard _{device->BufferLock}; if(UNLIKELY(LookupBuffer(device, buffer) == nullptr)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid buffer ID %u", buffer); + context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); else switch(param) { default: - alSetError(context.get(), AL_INVALID_ENUM, "Invalid buffer 3-float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid buffer 3-float property 0x%04x", param); } } END_API_FUNC @@ -1035,13 +1032,13 @@ START_API_FUNC std::lock_guard _{device->BufferLock}; if(UNLIKELY(LookupBuffer(device, buffer) == nullptr)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid buffer ID %u", buffer); + context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); else if(UNLIKELY(!values)) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(param) { default: - alSetError(context.get(), AL_INVALID_ENUM, "Invalid buffer float-vector property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid buffer float-vector property 0x%04x", param); } } END_API_FUNC @@ -1058,25 +1055,25 @@ START_API_FUNC ALbuffer *albuf = LookupBuffer(device, buffer); if(UNLIKELY(!albuf)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid buffer ID %u", buffer); + context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); else switch(param) { case AL_UNPACK_BLOCK_ALIGNMENT_SOFT: if(UNLIKELY(value < 0)) - alSetError(context.get(), AL_INVALID_VALUE, "Invalid unpack block alignment %d", value); + context->setError(AL_INVALID_VALUE, "Invalid unpack block alignment %d", value); else albuf->UnpackAlign.store(value); break; case AL_PACK_BLOCK_ALIGNMENT_SOFT: if(UNLIKELY(value < 0)) - alSetError(context.get(), AL_INVALID_VALUE, "Invalid pack block alignment %d", value); + context->setError(AL_INVALID_VALUE, "Invalid pack block alignment %d", value); else albuf->PackAlign.store(value); break; default: - alSetError(context.get(), AL_INVALID_ENUM, "Invalid buffer integer property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid buffer integer property 0x%04x", param); } } END_API_FUNC @@ -1092,11 +1089,11 @@ START_API_FUNC std::lock_guard _{device->BufferLock}; if(UNLIKELY(LookupBuffer(device, buffer) == nullptr)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid buffer ID %u", buffer); + context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); else switch(param) { default: - alSetError(context.get(), AL_INVALID_ENUM, "Invalid buffer 3-integer property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid buffer 3-integer property 0x%04x", param); } } END_API_FUNC @@ -1123,18 +1120,18 @@ START_API_FUNC ALbuffer *albuf = LookupBuffer(device, buffer); if(UNLIKELY(!albuf)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid buffer ID %u", buffer); + context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); else if(UNLIKELY(!values)) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(param) { case AL_LOOP_POINTS_SOFT: if(UNLIKELY(ReadRef(&albuf->ref) != 0)) - alSetError(context.get(), AL_INVALID_OPERATION, "Modifying in-use buffer %u's loop points", - buffer); + context->setError(AL_INVALID_OPERATION, "Modifying in-use buffer %u's loop points", + buffer); else if(UNLIKELY(values[0] >= values[1] || values[0] < 0 || values[1] > albuf->SampleLen)) - alSetError(context.get(), AL_INVALID_VALUE, "Invalid loop point range %d -> %d o buffer %u", - values[0], values[1], buffer); + context->setError(AL_INVALID_VALUE, "Invalid loop point range %d -> %d on buffer %u", + values[0], values[1], buffer); else { albuf->LoopStart = values[0]; @@ -1143,8 +1140,7 @@ START_API_FUNC break; default: - alSetError(context.get(), AL_INVALID_ENUM, "Invalid buffer integer-vector property 0x%04x", - param); + context->setError(AL_INVALID_ENUM, "Invalid buffer integer-vector property 0x%04x", param); } } END_API_FUNC @@ -1161,13 +1157,13 @@ START_API_FUNC ALbuffer *albuf = LookupBuffer(device, buffer); if(UNLIKELY(!albuf)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid buffer ID %u", buffer); + context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); else if(UNLIKELY(!value)) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(param) { default: - alSetError(context.get(), AL_INVALID_ENUM, "Invalid buffer float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid buffer float property 0x%04x", param); } } END_API_FUNC @@ -1182,13 +1178,13 @@ START_API_FUNC std::lock_guard _{device->BufferLock}; if(UNLIKELY(LookupBuffer(device, buffer) == nullptr)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid buffer ID %u", buffer); + context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); else if(UNLIKELY(!value1 || !value2 || !value3)) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(param) { default: - alSetError(context.get(), AL_INVALID_ENUM, "Invalid buffer 3-float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid buffer 3-float property 0x%04x", param); } } END_API_FUNC @@ -1210,13 +1206,13 @@ START_API_FUNC std::lock_guard _{device->BufferLock}; if(UNLIKELY(LookupBuffer(device, buffer) == nullptr)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid buffer ID %u", buffer); + context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); else if(UNLIKELY(!values)) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(param) { default: - alSetError(context.get(), AL_INVALID_ENUM, "Invalid buffer float-vector property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid buffer float-vector property 0x%04x", param); } } END_API_FUNC @@ -1232,9 +1228,9 @@ START_API_FUNC std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); if(UNLIKELY(!albuf)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid buffer ID %u", buffer); + context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); else if(UNLIKELY(!value)) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(param) { case AL_FREQUENCY: @@ -1262,7 +1258,7 @@ START_API_FUNC break; default: - alSetError(context.get(), AL_INVALID_ENUM, "Invalid buffer integer property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid buffer integer property 0x%04x", param); } } END_API_FUNC @@ -1276,13 +1272,13 @@ START_API_FUNC ALCdevice *device = context->mDevice; std::lock_guard _{device->BufferLock}; if(UNLIKELY(LookupBuffer(device, buffer) == nullptr)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid buffer ID %u", buffer); + context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); else if(UNLIKELY(!value1 || !value2 || !value3)) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(param) { default: - alSetError(context.get(), AL_INVALID_ENUM, "Invalid buffer 3-integer property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid buffer 3-integer property 0x%04x", param); } } END_API_FUNC @@ -1312,9 +1308,9 @@ START_API_FUNC std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); if(UNLIKELY(!albuf)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid buffer ID %u", buffer); + context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); else if(UNLIKELY(!values)) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(param) { case AL_LOOP_POINTS_SOFT: @@ -1323,8 +1319,7 @@ START_API_FUNC break; default: - alSetError(context.get(), AL_INVALID_ENUM, "Invalid buffer integer-vector property 0x%04x", - param); + context->setError(AL_INVALID_ENUM, "Invalid buffer integer-vector property 0x%04x", param); } } END_API_FUNC diff --git a/al/effect.cpp b/al/effect.cpp index b6291129..2d72916e 100644 --- a/al/effect.cpp +++ b/al/effect.cpp @@ -43,7 +43,6 @@ #include "almalloc.h" #include "alnumeric.h" #include "effects/base.h" -#include "error.h" #include "logging.h" #include "opthelpers.h" #include "vector.h" @@ -161,7 +160,7 @@ ALeffect *AllocEffect(ALCcontext *context) */ if(UNLIKELY(device->EffectList.size() >= 1<<25)) { - alSetError(context, AL_OUT_OF_MEMORY, "Too many effects allocated"); + context->setError(AL_OUT_OF_MEMORY, "Too many effects allocated"); return nullptr; } device->EffectList.emplace_back(); @@ -171,7 +170,7 @@ ALeffect *AllocEffect(ALCcontext *context) if(UNLIKELY(!sublist->Effects)) { device->EffectList.pop_back(); - alSetError(context, AL_OUT_OF_MEMORY, "Failed to allocate effect batch"); + context->setError(AL_OUT_OF_MEMORY, "Failed to allocate effect batch"); return nullptr; } @@ -224,7 +223,7 @@ START_API_FUNC if(UNLIKELY(n < 0)) { - alSetError(context.get(), AL_INVALID_VALUE, "Generating %d effects", n); + context->setError(AL_INVALID_VALUE, "Generating %d effects", n); return; } @@ -264,7 +263,7 @@ START_API_FUNC if(UNLIKELY(n < 0)) { - alSetError(context.get(), AL_INVALID_VALUE, "Deleting %d effects", n); + context->setError(AL_INVALID_VALUE, "Deleting %d effects", n); return; } if(UNLIKELY(n == 0)) @@ -282,7 +281,7 @@ START_API_FUNC ALeffect *effect{LookupEffect(device, eid)}; if(UNLIKELY(!effect)) { - alSetError(context.get(), AL_INVALID_NAME, "Invalid effect ID %u", eid); + context->setError(AL_INVALID_NAME, "Invalid effect ID %u", eid); return true; } return false; @@ -328,7 +327,7 @@ START_API_FUNC ALeffect *aleffect{LookupEffect(device, effect)}; if(UNLIKELY(!aleffect)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid effect ID %u", effect); + context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect); else { if(param == AL_EFFECT_TYPE) @@ -349,7 +348,7 @@ START_API_FUNC if(isOk) InitEffectParams(aleffect, value); else - alSetError(context.get(), AL_INVALID_VALUE, "Effect type 0x%04x not supported", value); + context->setError(AL_INVALID_VALUE, "Effect type 0x%04x not supported", value); } else { @@ -378,7 +377,7 @@ START_API_FUNC ALeffect *aleffect{LookupEffect(device, effect)}; if(UNLIKELY(!aleffect)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid effect ID %u", effect); + context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect); else { /* Call the appropriate handler */ @@ -398,7 +397,7 @@ START_API_FUNC ALeffect *aleffect{LookupEffect(device, effect)}; if(UNLIKELY(!aleffect)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid effect ID %u", effect); + context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect); else { /* Call the appropriate handler */ @@ -418,7 +417,7 @@ START_API_FUNC ALeffect *aleffect{LookupEffect(device, effect)}; if(UNLIKELY(!aleffect)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid effect ID %u", effect); + context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect); else { /* Call the appropriate handler */ @@ -438,7 +437,7 @@ START_API_FUNC const ALeffect *aleffect{LookupEffect(device, effect)}; if(UNLIKELY(!aleffect)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid effect ID %u", effect); + context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect); else { if(param == AL_EFFECT_TYPE) @@ -470,7 +469,7 @@ START_API_FUNC const ALeffect *aleffect{LookupEffect(device, effect)}; if(UNLIKELY(!aleffect)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid effect ID %u", effect); + context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect); else { /* Call the appropriate handler */ @@ -490,7 +489,7 @@ START_API_FUNC const ALeffect *aleffect{LookupEffect(device, effect)}; if(UNLIKELY(!aleffect)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid effect ID %u", effect); + context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect); else { /* Call the appropriate handler */ @@ -510,7 +509,7 @@ START_API_FUNC const ALeffect *aleffect{LookupEffect(device, effect)}; if(UNLIKELY(!aleffect)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid effect ID %u", effect); + context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect); else { /* Call the appropriate handler */ diff --git a/al/error.cpp b/al/error.cpp index f5ec9f52..8bd78fe2 100644 --- a/al/error.cpp +++ b/al/error.cpp @@ -20,8 +20,6 @@ #include "config.h" -#include "error.h" - #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN #include @@ -49,7 +47,7 @@ bool TrapALError{false}; -void alSetError(ALCcontext *context, ALenum errorCode, const char *msg, ...) +void ALCcontext::setError(ALenum errorCode, const char *msg, ...) { auto message = al::vector(256); @@ -69,7 +67,7 @@ void alSetError(ALCcontext *context, ALenum errorCode, const char *msg, ...) else msg = ""; msglen = static_cast(strlen(msg)); - WARN("Error generated on context %p, code 0x%04x, \"%s\"\n", context, errorCode, msg); + WARN("Error generated on context %p, code 0x%04x, \"%s\"\n", this, errorCode, msg); if(TrapALError) { #ifdef _WIN32 @@ -82,14 +80,13 @@ void alSetError(ALCcontext *context, ALenum errorCode, const char *msg, ...) } ALenum curerr{AL_NO_ERROR}; - context->mLastError.compare_exchange_strong(curerr, errorCode); - if((context->mEnabledEvts.load(std::memory_order_relaxed)&EventType_Error)) + mLastError.compare_exchange_strong(curerr, errorCode); + if((mEnabledEvts.load(std::memory_order_relaxed)&EventType_Error)) { - std::lock_guard _{context->mEventCbLock}; - ALbitfieldSOFT enabledevts{context->mEnabledEvts.load(std::memory_order_relaxed)}; - if((enabledevts&EventType_Error) && context->mEventCb) - (*context->mEventCb)(AL_EVENT_TYPE_ERROR_SOFT, 0, errorCode, msglen, msg, - context->mEventParam); + std::lock_guard _{mEventCbLock}; + ALbitfieldSOFT enabledevts{mEnabledEvts.load(std::memory_order_relaxed)}; + if((enabledevts&EventType_Error) && mEventCb) + (*mEventCb)(AL_EVENT_TYPE_ERROR_SOFT, 0, errorCode, msglen, msg, mEventParam); } } diff --git a/al/error.h b/al/error.h deleted file mode 100644 index 6408b60c..00000000 --- a/al/error.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef AL_ERROR_H -#define AL_ERROR_H - -#include "AL/al.h" -#include "AL/alc.h" - -#include "logging.h" - - -extern bool TrapALError; - -void alSetError(ALCcontext *context, ALenum errorCode, const char *msg, ...) DECL_FORMAT(printf, 3, 4); - -#define SETERR_GOTO(ctx, err, lbl, ...) do { \ - alSetError((ctx), (err), __VA_ARGS__); \ - goto lbl; \ -} while(0) - -#define SETERR_RETURN(ctx, err, retval, ...) do { \ - alSetError((ctx), (err), __VA_ARGS__); \ - return retval; \ -} while(0) - -#endif diff --git a/al/event.cpp b/al/event.cpp index b2710561..0d41e713 100644 --- a/al/event.cpp +++ b/al/event.cpp @@ -21,7 +21,6 @@ #include "alexcpt.h" #include "almalloc.h" #include "effects/base.h" -#include "error.h" #include "inprogext.h" #include "logging.h" #include "opthelpers.h" @@ -145,9 +144,9 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - if(count < 0) SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Controlling %d events", count); + if(count < 0) SETERR_RETURN(context, AL_INVALID_VALUE,, "Controlling %d events", count); if(count == 0) return; - if(!types) SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "NULL pointer"); + if(!types) SETERR_RETURN(context, AL_INVALID_VALUE,, "NULL pointer"); ALbitfieldSOFT flags{0}; const ALenum *types_end = types+count; @@ -172,7 +171,7 @@ START_API_FUNC } ); if(bad_type != types_end) - SETERR_RETURN(context.get(), AL_INVALID_ENUM,, "Invalid event type 0x%04x", *bad_type); + SETERR_RETURN(context, AL_INVALID_ENUM,, "Invalid event type 0x%04x", *bad_type); if(enable) { diff --git a/al/extension.cpp b/al/extension.cpp index c190ad03..1b36e3db 100644 --- a/al/extension.cpp +++ b/al/extension.cpp @@ -29,7 +29,6 @@ #include "alcontext.h" #include "alexcpt.h" -#include "error.h" #include "opthelpers.h" @@ -40,7 +39,7 @@ START_API_FUNC if(UNLIKELY(!context)) return AL_FALSE; if(!extName) - SETERR_RETURN(context.get(), AL_INVALID_VALUE, AL_FALSE, "NULL pointer"); + SETERR_RETURN(context, AL_INVALID_VALUE, AL_FALSE, "NULL pointer"); size_t len{strlen(extName)}; const char *ptr{context->mExtensionList}; diff --git a/al/filter.cpp b/al/filter.cpp index d9fce069..5009daae 100644 --- a/al/filter.cpp +++ b/al/filter.cpp @@ -36,7 +36,6 @@ #include "alexcpt.h" #include "almalloc.h" #include "alnumeric.h" -#include "error.h" #include "opthelpers.h" #include "vector.h" @@ -47,9 +46,9 @@ namespace { #define FILTER_MAX_GAIN 4.0f /* +12dB */ void ALlowpass_setParami(ALfilter*, ALCcontext *context, ALenum param, ALint) -{ alSetError(context, AL_INVALID_ENUM, "Invalid low-pass integer property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid low-pass integer property 0x%04x", param); } void ALlowpass_setParamiv(ALfilter*, ALCcontext *context, ALenum param, const ALint*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid low-pass integer-vector property 0x%04x", param); } +{ 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) { switch(param) @@ -67,16 +66,16 @@ void ALlowpass_setParamf(ALfilter *filter, ALCcontext *context, ALenum param, AL break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid low-pass float property 0x%04x", param); + context->setError(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*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid low-pass integer property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid low-pass integer property 0x%04x", param); } void ALlowpass_getParamiv(ALfilter*, ALCcontext *context, ALenum param, ALint*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid low-pass integer-vector property 0x%04x", param); } +{ 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) { switch(param) @@ -90,7 +89,7 @@ void ALlowpass_getParamf(ALfilter *filter, ALCcontext *context, ALenum param, AL break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid low-pass float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid low-pass float property 0x%04x", param); } } void ALlowpass_getParamfv(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *vals) @@ -100,9 +99,9 @@ DEFINE_ALFILTER_VTABLE(ALlowpass); void ALhighpass_setParami(ALfilter*, ALCcontext *context, ALenum param, ALint) -{ alSetError(context, AL_INVALID_ENUM, "Invalid high-pass integer property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid high-pass integer property 0x%04x", param); } void ALhighpass_setParamiv(ALfilter*, ALCcontext *context, ALenum param, const ALint*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid high-pass integer-vector property 0x%04x", param); } +{ 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) { switch(param) @@ -120,16 +119,16 @@ void ALhighpass_setParamf(ALfilter *filter, ALCcontext *context, ALenum param, A break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid high-pass float property 0x%04x", param); + context->setError(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*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid high-pass integer property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid high-pass integer property 0x%04x", param); } void ALhighpass_getParamiv(ALfilter*, ALCcontext *context, ALenum param, ALint*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid high-pass integer-vector property 0x%04x", param); } +{ 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) { switch(param) @@ -143,7 +142,7 @@ void ALhighpass_getParamf(ALfilter *filter, ALCcontext *context, ALenum param, A break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid high-pass float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid high-pass float property 0x%04x", param); } } void ALhighpass_getParamfv(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *vals) @@ -153,9 +152,9 @@ DEFINE_ALFILTER_VTABLE(ALhighpass); void ALbandpass_setParami(ALfilter*, ALCcontext *context, ALenum param, ALint) -{ alSetError(context, AL_INVALID_ENUM, "Invalid band-pass integer property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid band-pass integer property 0x%04x", param); } void ALbandpass_setParamiv(ALfilter*, ALCcontext *context, ALenum param, const ALint*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid band-pass integer-vector property 0x%04x", param); } +{ 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) { switch(param) @@ -179,16 +178,16 @@ void ALbandpass_setParamf(ALfilter *filter, ALCcontext *context, ALenum param, A break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid band-pass float property 0x%04x", param); + context->setError(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*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid band-pass integer property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid band-pass integer property 0x%04x", param); } void ALbandpass_getParamiv(ALfilter*, ALCcontext *context, ALenum param, ALint*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid band-pass integer-vector property 0x%04x", param); } +{ 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) { switch(param) @@ -206,7 +205,7 @@ void ALbandpass_getParamf(ALfilter *filter, ALCcontext *context, ALenum param, A break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid band-pass float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid band-pass float property 0x%04x", param); } } void ALbandpass_getParamfv(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *vals) @@ -216,22 +215,22 @@ DEFINE_ALFILTER_VTABLE(ALbandpass); void ALnullfilter_setParami(ALfilter*, ALCcontext *context, ALenum param, ALint) -{ alSetError(context, AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); } void ALnullfilter_setParamiv(ALfilter*, ALCcontext *context, ALenum param, const ALint*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); } void ALnullfilter_setParamf(ALfilter*, ALCcontext *context, ALenum param, ALfloat) -{ alSetError(context, AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); } void ALnullfilter_setParamfv(ALfilter*, ALCcontext *context, ALenum param, const ALfloat*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); } void ALnullfilter_getParami(ALfilter*, ALCcontext *context, ALenum param, ALint*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); } void ALnullfilter_getParamiv(ALfilter*, ALCcontext *context, ALenum param, ALint*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); } void ALnullfilter_getParamf(ALfilter*, ALCcontext *context, ALenum param, ALfloat*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); } void ALnullfilter_getParamfv(ALfilter*, ALCcontext *context, ALenum param, ALfloat*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); } DEFINE_ALFILTER_VTABLE(ALnullfilter); @@ -301,7 +300,7 @@ ALfilter *AllocFilter(ALCcontext *context) */ if(UNLIKELY(device->FilterList.size() >= 1<<25)) { - alSetError(context, AL_OUT_OF_MEMORY, "Too many filters allocated"); + context->setError(AL_OUT_OF_MEMORY, "Too many filters allocated"); return nullptr; } device->FilterList.emplace_back(); @@ -311,7 +310,7 @@ ALfilter *AllocFilter(ALCcontext *context) if(UNLIKELY(!sublist->Filters)) { device->FilterList.pop_back(); - alSetError(context, AL_OUT_OF_MEMORY, "Failed to allocate filter batch"); + context->setError(AL_OUT_OF_MEMORY, "Failed to allocate filter batch"); return nullptr; } @@ -365,7 +364,7 @@ START_API_FUNC if(UNLIKELY(n < 0)) { - alSetError(context.get(), AL_INVALID_VALUE, "Generating %d filters", n); + context->setError(AL_INVALID_VALUE, "Generating %d filters", n); return; } @@ -405,7 +404,7 @@ START_API_FUNC if(UNLIKELY(n < 0)) { - alSetError(context.get(), AL_INVALID_VALUE, "Deleting %d filters", n); + context->setError(AL_INVALID_VALUE, "Deleting %d filters", n); return; } if(UNLIKELY(n == 0)) @@ -423,7 +422,7 @@ START_API_FUNC ALfilter *filter{LookupFilter(device, fid)}; if(UNLIKELY(!filter)) { - alSetError(context.get(), AL_INVALID_NAME, "Invalid filter ID %u", fid); + context->setError(AL_INVALID_NAME, "Invalid filter ID %u", fid); return true; } return false; @@ -470,7 +469,7 @@ START_API_FUNC ALfilter *alfilt{LookupFilter(device, filter)}; if(UNLIKELY(!alfilt)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid filter ID %u", filter); + context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); else { if(param == AL_FILTER_TYPE) @@ -479,7 +478,7 @@ START_API_FUNC value == AL_FILTER_HIGHPASS || value == AL_FILTER_BANDPASS) InitFilterParams(alfilt, value); else - alSetError(context.get(), AL_INVALID_VALUE, "Invalid filter type 0x%04x", value); + context->setError(AL_INVALID_VALUE, "Invalid filter type 0x%04x", value); } else { @@ -508,7 +507,7 @@ START_API_FUNC ALfilter *alfilt{LookupFilter(device, filter)}; if(UNLIKELY(!alfilt)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid filter ID %u", filter); + context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); else { /* Call the appropriate handler */ @@ -528,7 +527,7 @@ START_API_FUNC ALfilter *alfilt{LookupFilter(device, filter)}; if(UNLIKELY(!alfilt)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid filter ID %u", filter); + context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); else { /* Call the appropriate handler */ @@ -548,7 +547,7 @@ START_API_FUNC ALfilter *alfilt{LookupFilter(device, filter)}; if(UNLIKELY(!alfilt)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid filter ID %u", filter); + context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); else { /* Call the appropriate handler */ @@ -568,7 +567,7 @@ START_API_FUNC ALfilter *alfilt{LookupFilter(device, filter)}; if(UNLIKELY(!alfilt)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid filter ID %u", filter); + context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); else { if(param == AL_FILTER_TYPE) @@ -600,7 +599,7 @@ START_API_FUNC ALfilter *alfilt{LookupFilter(device, filter)}; if(UNLIKELY(!alfilt)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid filter ID %u", filter); + context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); else { /* Call the appropriate handler */ @@ -620,7 +619,7 @@ START_API_FUNC ALfilter *alfilt{LookupFilter(device, filter)}; if(UNLIKELY(!alfilt)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid filter ID %u", filter); + context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); else { /* Call the appropriate handler */ @@ -640,7 +639,7 @@ START_API_FUNC ALfilter *alfilt{LookupFilter(device, filter)}; if(UNLIKELY(!alfilt)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid filter ID %u", filter); + context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); else { /* Call the appropriate handler */ diff --git a/al/listener.cpp b/al/listener.cpp index ba0a7268..3a1f32a4 100644 --- a/al/listener.cpp +++ b/al/listener.cpp @@ -31,7 +31,6 @@ #include "alexcpt.h" #include "almalloc.h" #include "atomic.h" -#include "error.h" #include "opthelpers.h" @@ -55,15 +54,14 @@ START_API_FUNC { case AL_GAIN: if(!(value >= 0.0f && std::isfinite(value))) - SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Listener gain out of range"); + SETERR_RETURN(context, AL_INVALID_VALUE,, "Listener gain out of range"); listener.Gain = value; DO_UPDATEPROPS(); break; case AL_METERS_PER_UNIT: if(!(value >= AL_MIN_METERS_PER_UNIT && value <= AL_MAX_METERS_PER_UNIT)) - SETERR_RETURN(context.get(), AL_INVALID_VALUE,, - "Listener meters per unit out of range"); + SETERR_RETURN(context, AL_INVALID_VALUE,, "Listener meters per unit out of range"); context->mMetersPerUnit = value; if(!context->mDeferUpdates.load(std::memory_order_acquire)) UpdateContextProps(context.get()); @@ -72,7 +70,7 @@ START_API_FUNC break; default: - alSetError(context.get(), AL_INVALID_ENUM, "Invalid listener float property"); + context->setError(AL_INVALID_ENUM, "Invalid listener float property"); } } END_API_FUNC @@ -89,7 +87,7 @@ START_API_FUNC { case AL_POSITION: if(!(std::isfinite(value1) && std::isfinite(value2) && std::isfinite(value3))) - SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Listener position out of range"); + SETERR_RETURN(context, AL_INVALID_VALUE,, "Listener position out of range"); listener.Position[0] = value1; listener.Position[1] = value2; listener.Position[2] = value3; @@ -98,7 +96,7 @@ START_API_FUNC case AL_VELOCITY: if(!(std::isfinite(value1) && std::isfinite(value2) && std::isfinite(value3))) - SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Listener velocity out of range"); + SETERR_RETURN(context, AL_INVALID_VALUE,, "Listener velocity out of range"); listener.Velocity[0] = value1; listener.Velocity[1] = value2; listener.Velocity[2] = value3; @@ -106,7 +104,7 @@ START_API_FUNC break; default: - alSetError(context.get(), AL_INVALID_ENUM, "Invalid listener 3-float property"); + context->setError(AL_INVALID_ENUM, "Invalid listener 3-float property"); } } END_API_FUNC @@ -135,13 +133,13 @@ START_API_FUNC ALlistener &listener = context->mListener; std::lock_guard _{context->mPropLock}; - if(!values) SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "NULL pointer"); + if(!values) SETERR_RETURN(context, AL_INVALID_VALUE,, "NULL pointer"); switch(param) { case AL_ORIENTATION: if(!(std::isfinite(values[0]) && std::isfinite(values[1]) && std::isfinite(values[2]) && std::isfinite(values[3]) && std::isfinite(values[4]) && std::isfinite(values[5]))) - SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Listener orientation out of range"); + SETERR_RETURN(context, AL_INVALID_VALUE,, "Listener orientation out of range"); /* AT then UP */ listener.OrientAt[0] = values[0]; listener.OrientAt[1] = values[1]; @@ -153,7 +151,7 @@ START_API_FUNC break; default: - alSetError(context.get(), AL_INVALID_ENUM, "Invalid listener float-vector property"); + context->setError(AL_INVALID_ENUM, "Invalid listener float-vector property"); } } END_API_FUNC @@ -169,7 +167,7 @@ START_API_FUNC switch(param) { default: - alSetError(context.get(), AL_INVALID_ENUM, "Invalid listener integer property"); + context->setError(AL_INVALID_ENUM, "Invalid listener integer property"); } } END_API_FUNC @@ -192,7 +190,7 @@ START_API_FUNC switch(param) { default: - alSetError(context.get(), AL_INVALID_ENUM, "Invalid listener 3-integer property"); + context->setError(AL_INVALID_ENUM, "Invalid listener 3-integer property"); } } END_API_FUNC @@ -227,11 +225,11 @@ START_API_FUNC std::lock_guard _{context->mPropLock}; if(!values) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(param) { default: - alSetError(context.get(), AL_INVALID_ENUM, "Invalid listener integer-vector property"); + context->setError(AL_INVALID_ENUM, "Invalid listener integer-vector property"); } } END_API_FUNC @@ -246,7 +244,7 @@ START_API_FUNC ALlistener &listener = context->mListener; std::lock_guard _{context->mPropLock}; if(!value) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(param) { case AL_GAIN: @@ -258,7 +256,7 @@ START_API_FUNC break; default: - alSetError(context.get(), AL_INVALID_ENUM, "Invalid listener float property"); + context->setError(AL_INVALID_ENUM, "Invalid listener float property"); } } END_API_FUNC @@ -272,7 +270,7 @@ START_API_FUNC ALlistener &listener = context->mListener; std::lock_guard _{context->mPropLock}; if(!value1 || !value2 || !value3) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(param) { case AL_POSITION: @@ -288,7 +286,7 @@ START_API_FUNC break; default: - alSetError(context.get(), AL_INVALID_ENUM, "Invalid listener 3-float property"); + context->setError(AL_INVALID_ENUM, "Invalid listener 3-float property"); } } END_API_FUNC @@ -315,7 +313,7 @@ START_API_FUNC ALlistener &listener = context->mListener; std::lock_guard _{context->mPropLock}; if(!values) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(param) { case AL_ORIENTATION: @@ -329,7 +327,7 @@ START_API_FUNC break; default: - alSetError(context.get(), AL_INVALID_ENUM, "Invalid listener float-vector property"); + context->setError(AL_INVALID_ENUM, "Invalid listener float-vector property"); } } END_API_FUNC @@ -343,11 +341,11 @@ START_API_FUNC std::lock_guard _{context->mPropLock}; if(!value) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(param) { default: - alSetError(context.get(), AL_INVALID_ENUM, "Invalid listener integer property"); + context->setError(AL_INVALID_ENUM, "Invalid listener integer property"); } } END_API_FUNC @@ -361,7 +359,7 @@ START_API_FUNC ALlistener &listener = context->mListener; std::lock_guard _{context->mPropLock}; if(!value1 || !value2 || !value3) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(param) { case AL_POSITION: @@ -377,7 +375,7 @@ START_API_FUNC break; default: - alSetError(context.get(), AL_INVALID_ENUM, "Invalid listener 3-integer property"); + context->setError(AL_INVALID_ENUM, "Invalid listener 3-integer property"); } } END_API_FUNC @@ -399,7 +397,7 @@ START_API_FUNC ALlistener &listener = context->mListener; std::lock_guard _{context->mPropLock}; if(!values) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(param) { case AL_ORIENTATION: @@ -413,7 +411,7 @@ START_API_FUNC break; default: - alSetError(context.get(), AL_INVALID_ENUM, "Invalid listener integer-vector property"); + context->setError(AL_INVALID_ENUM, "Invalid listener integer-vector property"); } } END_API_FUNC diff --git a/al/source.cpp b/al/source.cpp index 35d3bb84..ab509804 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -57,7 +57,6 @@ #include "backends/base.h" #include "bformatdec.h" #include "buffer.h" -#include "error.h" #include "event.h" #include "filter.h" #include "filters/nfc.h" @@ -488,7 +487,7 @@ ALsource *AllocSource(ALCcontext *context) std::lock_guard _{context->mSourceLock}; if(context->mNumSources >= device->SourcesMax) { - alSetError(context, AL_OUT_OF_MEMORY, "Exceeding %u source limit", device->SourcesMax); + context->setError(AL_OUT_OF_MEMORY, "Exceeding %u source limit", device->SourcesMax); return nullptr; } auto sublist = std::find_if(context->mSourceList.begin(), context->mSourceList.end(), @@ -510,7 +509,7 @@ ALsource *AllocSource(ALCcontext *context) */ if(UNLIKELY(context->mSourceList.size() >= 1<<25)) { - alSetError(context, AL_OUT_OF_MEMORY, "Too many sources allocated"); + context->setError(AL_OUT_OF_MEMORY, "Too many sources allocated"); return nullptr; } context->mSourceList.emplace_back(); @@ -521,7 +520,7 @@ ALsource *AllocSource(ALCcontext *context) if(UNLIKELY(!sublist->Sources)) { context->mSourceList.pop_back(); - alSetError(context, AL_OUT_OF_MEMORY, "Failed to allocate source batch"); + context->setError(AL_OUT_OF_MEMORY, "Failed to allocate source batch"); return nullptr; } @@ -993,7 +992,7 @@ ALboolean SetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, #define CHECKVAL(x) do { \ if(!(x)) \ { \ - alSetError(Context, AL_INVALID_VALUE, "Value out of range"); \ + Context->setError(AL_INVALID_VALUE, "Value out of range"); \ return AL_FALSE; \ } \ } while(0) @@ -1225,7 +1224,8 @@ ALboolean SetSourcefv(ALsource *Source, ALCcontext *Context, SourceProp prop, co } ERR("Unexpected property: 0x%04x\n", prop); - SETERR_RETURN(Context, AL_INVALID_ENUM, AL_FALSE, "Invalid source float property 0x%04x", prop); + Context->setError(AL_INVALID_ENUM, "Invalid source float property 0x%04x", prop); + return AL_FALSE; } ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const ALint *values) @@ -1548,8 +1548,8 @@ ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, co } ERR("Unexpected property: 0x%04x\n", prop); - SETERR_RETURN(Context, AL_INVALID_ENUM, AL_FALSE, "Invalid source integer property 0x%04x", - prop); + Context->setError(AL_INVALID_ENUM, "Invalid source integer property 0x%04x", prop); + return AL_FALSE; } ALboolean SetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, const ALint64SOFT *values) @@ -1651,8 +1651,8 @@ ALboolean SetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, } ERR("Unexpected property: 0x%04x\n", prop); - SETERR_RETURN(Context, AL_INVALID_ENUM, AL_FALSE, "Invalid source integer64 property 0x%04x", - prop); + Context->setError(AL_INVALID_ENUM, "Invalid source integer64 property 0x%04x", prop); + return AL_FALSE; } #undef CHECKVAL @@ -1824,8 +1824,8 @@ ALboolean GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp prop, AL } ERR("Unexpected property: 0x%04x\n", prop); - SETERR_RETURN(Context, AL_INVALID_ENUM, AL_FALSE, "Invalid source double property 0x%04x", - prop); + Context->setError(AL_INVALID_ENUM, "Invalid source double property 0x%04x", prop); + return AL_FALSE; } ALboolean GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, ALint *values) @@ -1991,8 +1991,8 @@ ALboolean GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, AL } ERR("Unexpected property: 0x%04x\n", prop); - SETERR_RETURN(Context, AL_INVALID_ENUM, AL_FALSE, "Invalid source integer property 0x%04x", - prop); + Context->setError(AL_INVALID_ENUM, "Invalid source integer property 0x%04x", prop); + return AL_FALSE; } ALboolean GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, ALint64SOFT *values) @@ -2123,8 +2123,8 @@ ALboolean GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, } ERR("Unexpected property: 0x%04x\n", prop); - SETERR_RETURN(Context, AL_INVALID_ENUM, AL_FALSE, "Invalid source integer64 property 0x%04x", - prop); + Context->setError(AL_INVALID_ENUM, "Invalid source integer64 property 0x%04x", prop); + return AL_FALSE; } } // namespace @@ -2136,7 +2136,7 @@ START_API_FUNC if(UNLIKELY(!context)) return; if(n < 0) - alSetError(context.get(), AL_INVALID_VALUE, "Generating %d sources", n); + context->setError(AL_INVALID_VALUE, "Generating %d sources", n); else if(n == 1) { ALsource *source = AllocSource(context.get()); @@ -2170,7 +2170,7 @@ START_API_FUNC if(UNLIKELY(!context)) return; if(n < 0) - SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Deleting %d sources", n); + SETERR_RETURN(context, AL_INVALID_VALUE,, "Deleting %d sources", n); std::lock_guard _{context->mSourceLock}; @@ -2181,7 +2181,7 @@ START_API_FUNC { if(!LookupSource(context.get(), sid)) { - alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", sid); + context->setError(AL_INVALID_NAME, "Invalid source ID %u", sid); return false; } return true; @@ -2226,9 +2226,9 @@ START_API_FUNC std::lock_guard __{context->mSourceLock}; ALsource *Source = LookupSource(context.get(), source); if(UNLIKELY(!Source)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(FloatValsByProp(param) != 1) - alSetError(context.get(), AL_INVALID_ENUM, "Invalid float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid float property 0x%04x", param); else SetSourcefv(Source, context.get(), static_cast(param), &value); } @@ -2244,9 +2244,9 @@ START_API_FUNC std::lock_guard __{context->mSourceLock}; ALsource *Source = LookupSource(context.get(), source); if(UNLIKELY(!Source)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(FloatValsByProp(param) != 3) - alSetError(context.get(), AL_INVALID_ENUM, "Invalid 3-float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid 3-float property 0x%04x", param); else { ALfloat fvals[3] = { value1, value2, value3 }; @@ -2265,11 +2265,11 @@ START_API_FUNC std::lock_guard __{context->mSourceLock}; ALsource *Source = LookupSource(context.get(), source); if(UNLIKELY(!Source)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!values) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else if(FloatValsByProp(param) < 1) - alSetError(context.get(), AL_INVALID_ENUM, "Invalid float-vector property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid float-vector property 0x%04x", param); else SetSourcefv(Source, context.get(), static_cast(param), values); } @@ -2286,9 +2286,9 @@ START_API_FUNC std::lock_guard __{context->mSourceLock}; ALsource *Source = LookupSource(context.get(), source); if(UNLIKELY(!Source)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(DoubleValsByProp(param) != 1) - alSetError(context.get(), AL_INVALID_ENUM, "Invalid double property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid double property 0x%04x", param); else { ALfloat fval = static_cast(value); @@ -2307,9 +2307,9 @@ START_API_FUNC std::lock_guard __{context->mSourceLock}; ALsource *Source = LookupSource(context.get(), source); if(UNLIKELY(!Source)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(DoubleValsByProp(param) != 3) - alSetError(context.get(), AL_INVALID_ENUM, "Invalid 3-double property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid 3-double property 0x%04x", param); else { ALfloat fvals[3] = {static_cast(value1), static_cast(value2), @@ -2329,14 +2329,14 @@ START_API_FUNC std::lock_guard __{context->mSourceLock}; ALsource *Source = LookupSource(context.get(), source); if(UNLIKELY(!Source)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!values) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else { ALint count{DoubleValsByProp(param)}; if(count < 1 || count > 6) - alSetError(context.get(), AL_INVALID_ENUM, "Invalid double-vector property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid double-vector property 0x%04x", param); else { ALfloat fvals[6]; @@ -2361,9 +2361,9 @@ START_API_FUNC std::lock_guard __{context->mSourceLock}; ALsource *Source = LookupSource(context.get(), source); if(UNLIKELY(!Source)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(IntValsByProp(param) != 1) - alSetError(context.get(), AL_INVALID_ENUM, "Invalid integer property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid integer property 0x%04x", param); else SetSourceiv(Source, context.get(), static_cast(param), &value); } @@ -2379,9 +2379,9 @@ START_API_FUNC std::lock_guard __{context->mSourceLock}; ALsource *Source = LookupSource(context.get(), source); if(UNLIKELY(!Source)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(IntValsByProp(param) != 3) - alSetError(context.get(), AL_INVALID_ENUM, "Invalid 3-integer property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid 3-integer property 0x%04x", param); else { ALint ivals[3] = { value1, value2, value3 }; @@ -2400,11 +2400,11 @@ START_API_FUNC std::lock_guard __{context->mSourceLock}; ALsource *Source = LookupSource(context.get(), source); if(UNLIKELY(!Source)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!values) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else if(IntValsByProp(param) < 1) - alSetError(context.get(), AL_INVALID_ENUM, "Invalid integer-vector property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid integer-vector property 0x%04x", param); else SetSourceiv(Source, context.get(), static_cast(param), values); } @@ -2421,9 +2421,9 @@ START_API_FUNC std::lock_guard __{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(Int64ValsByProp(param) != 1) - alSetError(context.get(), AL_INVALID_ENUM, "Invalid integer64 property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid integer64 property 0x%04x", param); else SetSourcei64v(Source, context.get(), static_cast(param), &value); } @@ -2439,9 +2439,9 @@ START_API_FUNC std::lock_guard __{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(Int64ValsByProp(param) != 3) - alSetError(context.get(), AL_INVALID_ENUM, "Invalid 3-integer64 property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid 3-integer64 property 0x%04x", param); else { ALint64SOFT i64vals[3] = { value1, value2, value3 }; @@ -2460,11 +2460,11 @@ START_API_FUNC std::lock_guard __{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!values) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else if(Int64ValsByProp(param) < 1) - alSetError(context.get(), AL_INVALID_ENUM, "Invalid integer64-vector property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid integer64-vector property 0x%04x", param); else SetSourcei64v(Source, context.get(), static_cast(param), values); } @@ -2480,11 +2480,11 @@ START_API_FUNC std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!value) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else if(FloatValsByProp(param) != 1) - alSetError(context.get(), AL_INVALID_ENUM, "Invalid float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid float property 0x%04x", param); else { ALdouble dval; @@ -2503,11 +2503,11 @@ START_API_FUNC std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!(value1 && value2 && value3)) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else if(FloatValsByProp(param) != 3) - alSetError(context.get(), AL_INVALID_ENUM, "Invalid 3-float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid 3-float property 0x%04x", param); else { ALdouble dvals[3]; @@ -2530,14 +2530,14 @@ START_API_FUNC std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!values) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else { ALint count{FloatValsByProp(param)}; if(count < 1 && count > 6) - alSetError(context.get(), AL_INVALID_ENUM, "Invalid float-vector property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid float-vector property 0x%04x", param); else { ALdouble dvals[6]; @@ -2561,11 +2561,11 @@ START_API_FUNC std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!value) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else if(DoubleValsByProp(param) != 1) - alSetError(context.get(), AL_INVALID_ENUM, "Invalid double property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid double property 0x%04x", param); else GetSourcedv(Source, context.get(), static_cast(param), value); } @@ -2580,11 +2580,11 @@ START_API_FUNC std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!(value1 && value2 && value3)) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else if(DoubleValsByProp(param) != 3) - alSetError(context.get(), AL_INVALID_ENUM, "Invalid 3-double property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid 3-double property 0x%04x", param); else { ALdouble dvals[3]; @@ -2607,11 +2607,11 @@ START_API_FUNC std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!values) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else if(DoubleValsByProp(param) < 1) - alSetError(context.get(), AL_INVALID_ENUM, "Invalid double-vector property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid double-vector property 0x%04x", param); else GetSourcedv(Source, context.get(), static_cast(param), values); } @@ -2627,11 +2627,11 @@ START_API_FUNC std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!value) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else if(IntValsByProp(param) != 1) - alSetError(context.get(), AL_INVALID_ENUM, "Invalid integer property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid integer property 0x%04x", param); else GetSourceiv(Source, context.get(), static_cast(param), value); } @@ -2646,11 +2646,11 @@ START_API_FUNC std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!(value1 && value2 && value3)) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else if(IntValsByProp(param) != 3) - alSetError(context.get(), AL_INVALID_ENUM, "Invalid 3-integer property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid 3-integer property 0x%04x", param); else { ALint ivals[3]; @@ -2673,11 +2673,11 @@ START_API_FUNC std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!values) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else if(IntValsByProp(param) < 1) - alSetError(context.get(), AL_INVALID_ENUM, "Invalid integer-vector property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid integer-vector property 0x%04x", param); else GetSourceiv(Source, context.get(), static_cast(param), values); } @@ -2693,11 +2693,11 @@ START_API_FUNC std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!value) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else if(Int64ValsByProp(param) != 1) - alSetError(context.get(), AL_INVALID_ENUM, "Invalid integer64 property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid integer64 property 0x%04x", param); else GetSourcei64v(Source, context.get(), static_cast(param), value); } @@ -2712,11 +2712,11 @@ START_API_FUNC std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!(value1 && value2 && value3)) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else if(Int64ValsByProp(param) != 3) - alSetError(context.get(), AL_INVALID_ENUM, "Invalid 3-integer64 property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid 3-integer64 property 0x%04x", param); else { ALint64SOFT i64vals[3]; @@ -2739,11 +2739,11 @@ START_API_FUNC std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) - alSetError(context.get(), AL_INVALID_NAME, "Invalid source ID %u", source); + context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!values) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else if(Int64ValsByProp(param) < 1) - alSetError(context.get(), AL_INVALID_ENUM, "Invalid integer64-vector property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid integer64-vector property 0x%04x", param); else GetSourcei64v(Source, context.get(), static_cast(param), values); } @@ -2762,7 +2762,7 @@ START_API_FUNC if(UNLIKELY(!context)) return; if(n < 0) - SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Playing %d sources", n); + SETERR_RETURN(context, AL_INVALID_VALUE,, "Playing %d sources", n); if(n == 0) return; al::vector extra_sources; @@ -2779,7 +2779,7 @@ START_API_FUNC { srchandles[i] = LookupSource(context.get(), sources[i]); if(!srchandles[i]) - SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid source ID %u", sources[i]); + SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid source ID %u", sources[i]); } ALCdevice *device{context->mDevice}; @@ -2823,7 +2823,7 @@ START_API_FUNC /* Allocate more voices to get enough. */ const size_t alloc_count{need_voices - rem_voices}; if(UNLIKELY(context->mVoices->size() > std::numeric_limits::max()-alloc_count)) - SETERR_RETURN(context.get(), AL_OUT_OF_MEMORY,, + SETERR_RETURN(context, AL_OUT_OF_MEMORY,, "Overflow increasing voice count to %zu + %zu", context->mVoices->size(), alloc_count); @@ -3024,7 +3024,7 @@ START_API_FUNC if(UNLIKELY(!context)) return; if(n < 0) - SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Pausing %d sources", n); + SETERR_RETURN(context, AL_INVALID_VALUE,, "Pausing %d sources", n); if(n == 0) return; al::vector extra_sources; @@ -3041,7 +3041,7 @@ START_API_FUNC { srchandles[i] = LookupSource(context.get(), sources[i]); if(!srchandles[i]) - SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid source ID %u", sources[i]); + SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid source ID %u", sources[i]); } ALCdevice *device{context->mDevice}; @@ -3079,7 +3079,7 @@ START_API_FUNC if(UNLIKELY(!context)) return; if(n < 0) - SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Stopping %d sources", n); + SETERR_RETURN(context, AL_INVALID_VALUE,, "Stopping %d sources", n); if(n == 0) return; al::vector extra_sources; @@ -3096,7 +3096,7 @@ START_API_FUNC { srchandles[i] = LookupSource(context.get(), sources[i]); if(!srchandles[i]) - SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid source ID %u", sources[i]); + SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid source ID %u", sources[i]); } ALCdevice *device{context->mDevice}; @@ -3141,7 +3141,7 @@ START_API_FUNC if(UNLIKELY(!context)) return; if(n < 0) - SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Rewinding %d sources", n); + SETERR_RETURN(context, AL_INVALID_VALUE,, "Rewinding %d sources", n); if(n == 0) return; al::vector extra_sources; @@ -3158,7 +3158,7 @@ START_API_FUNC { srchandles[i] = LookupSource(context.get(), sources[i]); if(!srchandles[i]) - SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid source ID %u", sources[i]); + SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid source ID %u", sources[i]); } ALCdevice *device{context->mDevice}; @@ -3197,17 +3197,17 @@ START_API_FUNC if(UNLIKELY(!context)) return; if(nb < 0) - SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Queueing %d buffers", nb); + SETERR_RETURN(context, AL_INVALID_VALUE,, "Queueing %d buffers", nb); if(nb == 0) return; std::lock_guard _{context->mSourceLock}; ALsource *source{LookupSource(context.get(),src)}; if(UNLIKELY(!source)) - SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid source ID %u", src); + SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid source ID %u", src); /* Can't queue on a Static Source */ if(UNLIKELY(source->SourceType == AL_STATIC)) - SETERR_RETURN(context.get(), AL_INVALID_OPERATION,, "Queueing onto static source %u", src); + SETERR_RETURN(context, AL_INVALID_OPERATION,, "Queueing onto static source %u", src); /* Check for a valid Buffer, for its frequency and format */ ALCdevice *device{context->mDevice}; @@ -3232,8 +3232,7 @@ START_API_FUNC ALbuffer *buffer{nullptr}; if(buffers[i] && (buffer=LookupBuffer(device, buffers[i])) == nullptr) { - alSetError(context.get(), AL_INVALID_NAME, "Queueing invalid buffer ID %u", - buffers[i]); + context->setError(AL_INVALID_NAME, "Queueing invalid buffer ID %u", buffers[i]); goto buffer_error; } @@ -3260,8 +3259,8 @@ START_API_FUNC if(buffer->MappedAccess != 0 && !(buffer->MappedAccess&AL_MAP_PERSISTENT_BIT_SOFT)) { - alSetError(context.get(), AL_INVALID_OPERATION, - "Queueing non-persistently mapped buffer %u", buffer->id); + context->setError(AL_INVALID_OPERATION, "Queueing non-persistently mapped buffer %u", + buffer->id); goto buffer_error; } @@ -3271,8 +3270,7 @@ START_API_FUNC BufferFmt->mFmtChannels != buffer->mFmtChannels || BufferFmt->OriginalType != buffer->OriginalType) { - alSetError(context.get(), AL_INVALID_OPERATION, - "Queueing buffer with mismatched format"); + context->setError(AL_INVALID_OPERATION, "Queueing buffer with mismatched format"); buffer_error: /* A buffer failed (invalid ID or format), so unlock and release @@ -3316,17 +3314,17 @@ START_API_FUNC if(UNLIKELY(!context)) return; if(nb < 0) - SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Queueing %d buffer layers", nb); + SETERR_RETURN(context, AL_INVALID_VALUE,, "Queueing %d buffer layers", nb); if(nb == 0) return; std::lock_guard _{context->mSourceLock}; ALsource *source{LookupSource(context.get(),src)}; if(UNLIKELY(!source)) - SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid source ID %u", src); + SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid source ID %u", src); /* Can't queue on a Static Source */ if(UNLIKELY(source->SourceType == AL_STATIC)) - SETERR_RETURN(context.get(), AL_INVALID_OPERATION,, "Queueing onto static source %u", src); + SETERR_RETURN(context, AL_INVALID_OPERATION,, "Queueing onto static source %u", src); /* Check for a valid Buffer, for its frequency and format */ ALCdevice *device{context->mDevice}; @@ -3356,8 +3354,7 @@ START_API_FUNC ALbuffer *buffer{nullptr}; if(buffers[i] && (buffer=LookupBuffer(device, buffers[i])) == nullptr) { - alSetError(context.get(), AL_INVALID_NAME, "Queueing invalid buffer ID %u", - buffers[i]); + context->setError(AL_INVALID_NAME, "Queueing invalid buffer ID %u", buffers[i]); goto buffer_error; } @@ -3370,8 +3367,8 @@ START_API_FUNC if(buffer->MappedAccess != 0 && !(buffer->MappedAccess&AL_MAP_PERSISTENT_BIT_SOFT)) { - alSetError(context.get(), AL_INVALID_OPERATION, - "Queueing non-persistently mapped buffer %u", buffer->id); + context->setError(AL_INVALID_OPERATION, "Queueing non-persistently mapped buffer %u", + buffer->id); goto buffer_error; } @@ -3381,8 +3378,7 @@ START_API_FUNC BufferFmt->mFmtChannels != buffer->mFmtChannels || BufferFmt->OriginalType != buffer->OriginalType) { - alSetError(context.get(), AL_INVALID_OPERATION, - "Queueing buffer with mismatched format"); + context->setError(AL_INVALID_OPERATION, "Queueing buffer with mismatched format"); buffer_error: /* A buffer failed (invalid ID or format), so unlock and release @@ -3426,19 +3422,19 @@ START_API_FUNC if(UNLIKELY(!context)) return; if(nb < 0) - SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Unqueueing %d buffers", nb); + SETERR_RETURN(context, AL_INVALID_VALUE,, "Unqueueing %d buffers", nb); if(nb == 0) return; std::lock_guard _{context->mSourceLock}; ALsource *source{LookupSource(context.get(),src)}; if(UNLIKELY(!source)) - SETERR_RETURN(context.get(), AL_INVALID_NAME,, "Invalid source ID %u", src); + SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid source ID %u", src); if(UNLIKELY(source->Looping)) - SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Unqueueing from looping source %u", src); + SETERR_RETURN(context, AL_INVALID_VALUE,, "Unqueueing from looping source %u", src); if(UNLIKELY(source->SourceType != AL_STREAMING)) - SETERR_RETURN(context.get(), AL_INVALID_VALUE,, - "Unqueueing from a non-streaming source %u", src); + SETERR_RETURN(context, AL_INVALID_VALUE,, "Unqueueing from a non-streaming source %u", + src); /* Make sure enough buffers have been processed to unqueue. */ ALbufferlistitem *BufferList{source->queue}; @@ -3449,7 +3445,7 @@ START_API_FUNC else if(source->state == AL_INITIAL) Current = BufferList; if(UNLIKELY(BufferList == Current)) - SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Unqueueing pending buffers"); + SETERR_RETURN(context, AL_INVALID_VALUE,, "Unqueueing pending buffers"); ALsizei i{BufferList->num_buffers}; while(i < nb) @@ -3459,7 +3455,7 @@ START_API_FUNC */ ALbufferlistitem *next{BufferList->next.load(std::memory_order_relaxed)}; if(UNLIKELY(!next) || UNLIKELY(next == Current)) - SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Unqueueing pending buffers"); + SETERR_RETURN(context, AL_INVALID_VALUE,, "Unqueueing pending buffers"); BufferList = next; i += BufferList->num_buffers; diff --git a/al/state.cpp b/al/state.cpp index 903ab614..3f2f8b79 100644 --- a/al/state.cpp +++ b/al/state.cpp @@ -102,7 +102,7 @@ START_API_FUNC break; default: - alSetError(context.get(), AL_INVALID_VALUE, "Invalid enable property 0x%04x", capability); + context->setError(AL_INVALID_VALUE, "Invalid enable property 0x%04x", capability); } } END_API_FUNC @@ -122,7 +122,7 @@ START_API_FUNC break; default: - alSetError(context.get(), AL_INVALID_VALUE, "Invalid disable property 0x%04x", capability); + context->setError(AL_INVALID_VALUE, "Invalid disable property 0x%04x", capability); } } END_API_FUNC @@ -142,7 +142,7 @@ START_API_FUNC break; default: - alSetError(context.get(), AL_INVALID_VALUE, "Invalid is enabled property 0x%04x", capability); + context->setError(AL_INVALID_VALUE, "Invalid is enabled property 0x%04x", capability); } return value; @@ -199,7 +199,7 @@ START_API_FUNC break; default: - alSetError(context.get(), AL_INVALID_VALUE, "Invalid boolean property 0x%04x", pname); + context->setError(AL_INVALID_VALUE, "Invalid boolean property 0x%04x", pname); } return value; @@ -250,7 +250,7 @@ START_API_FUNC break; default: - alSetError(context.get(), AL_INVALID_VALUE, "Invalid double property 0x%04x", pname); + context->setError(AL_INVALID_VALUE, "Invalid double property 0x%04x", pname); } return value; @@ -301,7 +301,7 @@ START_API_FUNC break; default: - alSetError(context.get(), AL_INVALID_VALUE, "Invalid float property 0x%04x", pname); + context->setError(AL_INVALID_VALUE, "Invalid float property 0x%04x", pname); } return value; @@ -352,7 +352,7 @@ START_API_FUNC break; default: - alSetError(context.get(), AL_INVALID_VALUE, "Invalid integer property 0x%04x", pname); + context->setError(AL_INVALID_VALUE, "Invalid integer property 0x%04x", pname); } return value; @@ -403,7 +403,7 @@ START_API_FUNC break; default: - alSetError(context.get(), AL_INVALID_VALUE, "Invalid integer64 property 0x%04x", pname); + context->setError(AL_INVALID_VALUE, "Invalid integer64 property 0x%04x", pname); } return value; @@ -429,7 +429,7 @@ START_API_FUNC break; default: - alSetError(context.get(), AL_INVALID_VALUE, "Invalid pointer property 0x%04x", pname); + context->setError(AL_INVALID_VALUE, "Invalid pointer property 0x%04x", pname); } return value; @@ -460,11 +460,11 @@ START_API_FUNC if(UNLIKELY(!context)) return; if(!values) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(pname) { default: - alSetError(context.get(), AL_INVALID_VALUE, "Invalid boolean-vector property 0x%04x", pname); + context->setError(AL_INVALID_VALUE, "Invalid boolean-vector property 0x%04x", pname); } } END_API_FUNC @@ -493,11 +493,11 @@ START_API_FUNC if(UNLIKELY(!context)) return; if(!values) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(pname) { default: - alSetError(context.get(), AL_INVALID_VALUE, "Invalid double-vector property 0x%04x", pname); + context->setError(AL_INVALID_VALUE, "Invalid double-vector property 0x%04x", pname); } } END_API_FUNC @@ -526,11 +526,11 @@ START_API_FUNC if(UNLIKELY(!context)) return; if(!values) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(pname) { default: - alSetError(context.get(), AL_INVALID_VALUE, "Invalid float-vector property 0x%04x", pname); + context->setError(AL_INVALID_VALUE, "Invalid float-vector property 0x%04x", pname); } } END_API_FUNC @@ -559,11 +559,11 @@ START_API_FUNC if(UNLIKELY(!context)) return; if(!values) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(pname) { default: - alSetError(context.get(), AL_INVALID_VALUE, "Invalid integer-vector property 0x%04x", pname); + context->setError(AL_INVALID_VALUE, "Invalid integer-vector property 0x%04x", pname); } } END_API_FUNC @@ -592,11 +592,11 @@ START_API_FUNC if(UNLIKELY(!context)) return; if(!values) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(pname) { default: - alSetError(context.get(), AL_INVALID_VALUE, "Invalid integer64-vector property 0x%04x", pname); + context->setError(AL_INVALID_VALUE, "Invalid integer64-vector property 0x%04x", pname); } } END_API_FUNC @@ -619,11 +619,11 @@ START_API_FUNC if(UNLIKELY(!context)) return; if(!values) - alSetError(context.get(), AL_INVALID_VALUE, "NULL pointer"); + context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(pname) { default: - alSetError(context.get(), AL_INVALID_VALUE, "Invalid pointer-vector property 0x%04x", pname); + context->setError(AL_INVALID_VALUE, "Invalid pointer-vector property 0x%04x", pname); } } END_API_FUNC @@ -678,7 +678,7 @@ START_API_FUNC break; default: - alSetError(context.get(), AL_INVALID_VALUE, "Invalid string property 0x%04x", pname); + context->setError(AL_INVALID_VALUE, "Invalid string property 0x%04x", pname); } return value; } @@ -691,7 +691,7 @@ START_API_FUNC if(UNLIKELY(!context)) return; if(!(value >= 0.0f && std::isfinite(value))) - alSetError(context.get(), AL_INVALID_VALUE, "Doppler factor %f out of range", value); + context->setError(AL_INVALID_VALUE, "Doppler factor %f out of range", value); else { std::lock_guard _{context->mPropLock}; @@ -720,7 +720,7 @@ START_API_FUNC } if(!(value >= 0.0f && std::isfinite(value))) - alSetError(context.get(), AL_INVALID_VALUE, "Doppler velocity %f out of range", value); + context->setError(AL_INVALID_VALUE, "Doppler velocity %f out of range", value); else { std::lock_guard _{context->mPropLock}; @@ -737,7 +737,7 @@ START_API_FUNC if(UNLIKELY(!context)) return; if(!(value > 0.0f && std::isfinite(value))) - alSetError(context.get(), AL_INVALID_VALUE, "Speed of sound %f out of range", value); + context->setError(AL_INVALID_VALUE, "Speed of sound %f out of range", value); else { std::lock_guard _{context->mPropLock}; @@ -757,7 +757,7 @@ START_API_FUNC value == AL_LINEAR_DISTANCE || value == AL_LINEAR_DISTANCE_CLAMPED || value == AL_EXPONENT_DISTANCE || value == AL_EXPONENT_DISTANCE_CLAMPED || value == AL_NONE)) - alSetError(context.get(), AL_INVALID_VALUE, "Distance model 0x%04x out of range", value); + context->setError(AL_INVALID_VALUE, "Distance model 0x%04x out of range", value); else { std::lock_guard _{context->mPropLock}; @@ -808,14 +808,13 @@ START_API_FUNC { case AL_RESAMPLER_NAME_SOFT: if(index < 0 || static_cast(index) >= al::size(ResamplerNames)) - alSetError(context.get(), AL_INVALID_VALUE, "Resampler name index %d out of range", - index); + context->setError(AL_INVALID_VALUE, "Resampler name index %d out of range", index); else value = ResamplerNames[index]; break; default: - alSetError(context.get(), AL_INVALID_VALUE, "Invalid string indexed property"); + context->setError(AL_INVALID_VALUE, "Invalid string indexed property"); } return value; } diff --git a/alc/alc.cpp b/alc/alc.cpp index db5fd094..240aca6d 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -53,7 +53,6 @@ #include "al/auxeffectslot.h" #include "al/effect.h" -#include "al/error.h" #include "al/event.h" #include "al/filter.h" #include "al/listener.h" diff --git a/alc/alcontext.h b/alc/alcontext.h index 9c2ce4a3..833d4c5b 100644 --- a/alc/alcontext.h +++ b/alc/alcontext.h @@ -9,16 +9,16 @@ #include "AL/al.h" #include "AL/alc.h" #include "AL/alext.h" -#include "inprogext.h" -#include "atomic.h" -#include "vector.h" -#include "threads.h" +#include "al/listener.h" #include "almalloc.h" #include "alnumeric.h" - -#include "al/listener.h" #include "alu.h" +#include "atomic.h" +#include "inprogext.h" +#include "logging.h" +#include "threads.h" +#include "vector.h" struct ALsource; @@ -159,9 +159,17 @@ struct ALCcontext { /** Resumes update processing after being deferred. */ void processUpdates(); + void setError(ALenum errorCode, const char *msg, ...) DECL_FORMAT(printf, 3, 4); + DEF_NEWDEL(ALCcontext) }; +#define SETERR_RETURN(ctx, err, retval, ...) do { \ + (ctx)->setError((err), __VA_ARGS__); \ + return retval; \ +} while(0) + + void UpdateContextProps(ALCcontext *context); @@ -224,4 +232,7 @@ struct ALcontextProps { std::atomic next; }; + +extern bool TrapALError; + #endif /* ALCONTEXT_H */ diff --git a/alc/effects/autowah.cpp b/alc/effects/autowah.cpp index d92e114a..1aac749e 100644 --- a/alc/effects/autowah.cpp +++ b/alc/effects/autowah.cpp @@ -26,7 +26,6 @@ #include #include "al/auxeffectslot.h" -#include "al/error.h" #include "alcmain.h" #include "alcontext.h" #include "alu.h" @@ -226,16 +225,16 @@ void ALautowah_setParamf(EffectProps *props, ALCcontext *context, ALenum param, break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid autowah float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid autowah float property 0x%04x", param); } } void ALautowah_setParamfv(EffectProps *props, ALCcontext *context, ALenum param, const ALfloat *vals) { ALautowah_setParamf(props, context, param, vals[0]); } void ALautowah_setParami(EffectProps*, ALCcontext *context, ALenum param, ALint) -{ alSetError(context, AL_INVALID_ENUM, "Invalid autowah integer property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid autowah integer property 0x%04x", param); } void ALautowah_setParamiv(EffectProps*, ALCcontext *context, ALenum param, const ALint*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid autowah integer vector property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid autowah integer vector property 0x%04x", param); } void ALautowah_getParamf(const EffectProps *props, ALCcontext *context, ALenum param, ALfloat *val) { @@ -258,7 +257,7 @@ void ALautowah_getParamf(const EffectProps *props, ALCcontext *context, ALenum p break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid autowah float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid autowah float property 0x%04x", param); } } @@ -266,9 +265,9 @@ void ALautowah_getParamfv(const EffectProps *props, ALCcontext *context, ALenum { ALautowah_getParamf(props, context, param, vals); } void ALautowah_getParami(const EffectProps*, ALCcontext *context, ALenum param, ALint*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid autowah integer property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid autowah integer property 0x%04x", param); } void ALautowah_getParamiv(const EffectProps*, ALCcontext *context, ALenum param, ALint*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid autowah integer vector property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid autowah integer vector property 0x%04x", param); } DEFINE_ALEFFECT_VTABLE(ALautowah); diff --git a/alc/effects/chorus.cpp b/alc/effects/chorus.cpp index 7a473723..31f10c81 100644 --- a/alc/effects/chorus.cpp +++ b/alc/effects/chorus.cpp @@ -31,7 +31,6 @@ #include "AL/efx.h" #include "al/auxeffectslot.h" -#include "al/error.h" #include "alcmain.h" #include "alcontext.h" #include "almalloc.h" @@ -290,7 +289,7 @@ void Chorus_setParami(EffectProps *props, ALCcontext *context, ALenum param, ALi break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid chorus integer property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid chorus integer property 0x%04x", param); } } void Chorus_setParamiv(EffectProps *props, ALCcontext *context, ALenum param, const ALint *vals) @@ -324,7 +323,7 @@ void Chorus_setParamf(EffectProps *props, ALCcontext *context, ALenum param, ALf break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid chorus float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid chorus float property 0x%04x", param); } } void Chorus_setParamfv(EffectProps *props, ALCcontext *context, ALenum param, const ALfloat *vals) @@ -343,7 +342,7 @@ void Chorus_getParami(const EffectProps *props, ALCcontext *context, ALenum para break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid chorus integer property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid chorus integer property 0x%04x", param); } } void Chorus_getParamiv(const EffectProps *props, ALCcontext *context, ALenum param, ALint *vals) @@ -369,7 +368,7 @@ void Chorus_getParamf(const EffectProps *props, ALCcontext *context, ALenum para break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid chorus float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid chorus float property 0x%04x", param); } } void Chorus_getParamfv(const EffectProps *props, ALCcontext *context, ALenum param, ALfloat *vals) @@ -414,7 +413,7 @@ void Flanger_setParami(EffectProps *props, ALCcontext *context, ALenum param, AL break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid flanger integer property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid flanger integer property 0x%04x", param); } } void Flanger_setParamiv(EffectProps *props, ALCcontext *context, ALenum param, const ALint *vals) @@ -448,7 +447,7 @@ void Flanger_setParamf(EffectProps *props, ALCcontext *context, ALenum param, AL break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid flanger float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid flanger float property 0x%04x", param); } } void Flanger_setParamfv(EffectProps *props, ALCcontext *context, ALenum param, const ALfloat *vals) @@ -467,7 +466,7 @@ void Flanger_getParami(const EffectProps *props, ALCcontext *context, ALenum par break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid flanger integer property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid flanger integer property 0x%04x", param); } } void Flanger_getParamiv(const EffectProps *props, ALCcontext *context, ALenum param, ALint *vals) @@ -493,7 +492,7 @@ void Flanger_getParamf(const EffectProps *props, ALCcontext *context, ALenum par break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid flanger float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid flanger float property 0x%04x", param); } } void Flanger_getParamfv(const EffectProps *props, ALCcontext *context, ALenum param, ALfloat *vals) diff --git a/alc/effects/compressor.cpp b/alc/effects/compressor.cpp index 86e2e02b..63867762 100644 --- a/alc/effects/compressor.cpp +++ b/alc/effects/compressor.cpp @@ -23,7 +23,6 @@ #include #include "al/auxeffectslot.h" -#include "al/error.h" #include "alcmain.h" #include "alcontext.h" #include "alu.h" @@ -166,16 +165,16 @@ void Compressor_setParami(EffectProps *props, ALCcontext *context, ALenum param, break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid compressor integer property 0x%04x", - param); + context->setError(AL_INVALID_ENUM, "Invalid compressor integer property 0x%04x", + param); } } void Compressor_setParamiv(EffectProps *props, ALCcontext *context, ALenum param, const ALint *vals) { Compressor_setParami(props, context, param, vals[0]); } void Compressor_setParamf(EffectProps*, ALCcontext *context, ALenum param, ALfloat) -{ alSetError(context, AL_INVALID_ENUM, "Invalid compressor float property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid compressor float property 0x%04x", param); } void Compressor_setParamfv(EffectProps*, ALCcontext *context, ALenum param, const ALfloat*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid compressor float-vector property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid compressor float-vector property 0x%04x", param); } void Compressor_getParami(const EffectProps *props, ALCcontext *context, ALenum param, ALint *val) { @@ -186,16 +185,16 @@ void Compressor_getParami(const EffectProps *props, ALCcontext *context, ALenum break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid compressor integer property 0x%04x", - param); + context->setError(AL_INVALID_ENUM, "Invalid compressor integer property 0x%04x", + param); } } void Compressor_getParamiv(const EffectProps *props, ALCcontext *context, ALenum param, ALint *vals) { Compressor_getParami(props, context, param, vals); } void Compressor_getParamf(const EffectProps*, ALCcontext *context, ALenum param, ALfloat*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid compressor float property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid compressor float property 0x%04x", param); } void Compressor_getParamfv(const EffectProps*, ALCcontext *context, ALenum param, ALfloat*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid compressor float-vector property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid compressor float-vector property 0x%04x", param); } DEFINE_ALEFFECT_VTABLE(Compressor); diff --git a/alc/effects/dedicated.cpp b/alc/effects/dedicated.cpp index c05df772..2e49658f 100644 --- a/alc/effects/dedicated.cpp +++ b/alc/effects/dedicated.cpp @@ -25,7 +25,6 @@ #include #include "al/auxeffectslot.h" -#include "al/error.h" #include "alcmain.h" #include "alcontext.h" #include "alu.h" @@ -95,9 +94,9 @@ void DedicatedState::process(const ALsizei samplesToDo, const FloatBufferLine *R void Dedicated_setParami(EffectProps*, ALCcontext *context, ALenum param, ALint) -{ alSetError(context, AL_INVALID_ENUM, "Invalid dedicated integer property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid dedicated integer property 0x%04x", param); } void Dedicated_setParamiv(EffectProps*, ALCcontext *context, ALenum param, const ALint*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid dedicated integer-vector property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid dedicated integer-vector property 0x%04x", param); } void Dedicated_setParamf(EffectProps *props, ALCcontext *context, ALenum param, ALfloat val) { switch(param) @@ -109,16 +108,16 @@ void Dedicated_setParamf(EffectProps *props, ALCcontext *context, ALenum param, break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid dedicated float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid dedicated float property 0x%04x", param); } } void Dedicated_setParamfv(EffectProps *props, ALCcontext *context, ALenum param, const ALfloat *vals) { Dedicated_setParamf(props, context, param, vals[0]); } void Dedicated_getParami(const EffectProps*, ALCcontext *context, ALenum param, ALint*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid dedicated integer property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid dedicated integer property 0x%04x", param); } void Dedicated_getParamiv(const EffectProps*, ALCcontext *context, ALenum param, ALint*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid dedicated integer-vector property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid dedicated integer-vector property 0x%04x", param); } void Dedicated_getParamf(const EffectProps *props, ALCcontext *context, ALenum param, ALfloat *val) { switch(param) @@ -128,7 +127,7 @@ void Dedicated_getParamf(const EffectProps *props, ALCcontext *context, ALenum p break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid dedicated float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid dedicated float property 0x%04x", param); } } void Dedicated_getParamfv(const EffectProps *props, ALCcontext *context, ALenum param, ALfloat *vals) diff --git a/alc/effects/distortion.cpp b/alc/effects/distortion.cpp index 79278f0d..3fd08229 100644 --- a/alc/effects/distortion.cpp +++ b/alc/effects/distortion.cpp @@ -26,7 +26,6 @@ #include #include "al/auxeffectslot.h" -#include "al/error.h" #include "alcmain.h" #include "alcontext.h" #include "alu.h" @@ -159,9 +158,9 @@ void DistortionState::process(const ALsizei samplesToDo, const FloatBufferLine * void Distortion_setParami(EffectProps*, ALCcontext *context, ALenum param, ALint) -{ alSetError(context, AL_INVALID_ENUM, "Invalid distortion integer property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid distortion integer property 0x%04x", param); } void Distortion_setParamiv(EffectProps*, ALCcontext *context, ALenum param, const ALint*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid distortion integer-vector property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid distortion integer-vector property 0x%04x", param); } void Distortion_setParamf(EffectProps *props, ALCcontext *context, ALenum param, ALfloat val) { switch(param) @@ -197,17 +196,16 @@ void Distortion_setParamf(EffectProps *props, ALCcontext *context, ALenum param, break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid distortion float property 0x%04x", - param); + context->setError(AL_INVALID_ENUM, "Invalid distortion float property 0x%04x", param); } } void Distortion_setParamfv(EffectProps *props, ALCcontext *context, ALenum param, const ALfloat *vals) { Distortion_setParamf(props, context, param, vals[0]); } void Distortion_getParami(const EffectProps*, ALCcontext *context, ALenum param, ALint*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid distortion integer property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid distortion integer property 0x%04x", param); } void Distortion_getParamiv(const EffectProps*, ALCcontext *context, ALenum param, ALint*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid distortion integer-vector property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid distortion integer-vector property 0x%04x", param); } void Distortion_getParamf(const EffectProps *props, ALCcontext *context, ALenum param, ALfloat *val) { switch(param) @@ -233,8 +231,7 @@ void Distortion_getParamf(const EffectProps *props, ALCcontext *context, ALenum break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid distortion float property 0x%04x", - param); + context->setError(AL_INVALID_ENUM, "Invalid distortion float property 0x%04x", param); } } void Distortion_getParamfv(const EffectProps *props, ALCcontext *context, ALenum param, ALfloat *vals) diff --git a/alc/effects/echo.cpp b/alc/effects/echo.cpp index 9a43c037..d14db80c 100644 --- a/alc/effects/echo.cpp +++ b/alc/effects/echo.cpp @@ -26,7 +26,6 @@ #include #include "al/auxeffectslot.h" -#include "al/error.h" #include "al/filter.h" #include "alcmain.h" #include "alcontext.h" @@ -163,9 +162,9 @@ void EchoState::process(const ALsizei samplesToDo, const FloatBufferLine *RESTRI void Echo_setParami(EffectProps*, ALCcontext *context, ALenum param, ALint) -{ alSetError(context, AL_INVALID_ENUM, "Invalid echo integer property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid echo integer property 0x%04x", param); } void Echo_setParamiv(EffectProps*, ALCcontext *context, ALenum param, const ALint*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid echo integer-vector property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid echo integer-vector property 0x%04x", param); } void Echo_setParamf(EffectProps *props, ALCcontext *context, ALenum param, ALfloat val) { switch(param) @@ -201,16 +200,16 @@ void Echo_setParamf(EffectProps *props, ALCcontext *context, ALenum param, ALflo break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid echo float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid echo float property 0x%04x", param); } } void Echo_setParamfv(EffectProps *props, ALCcontext *context, ALenum param, const ALfloat *vals) { Echo_setParamf(props, context, param, vals[0]); } void Echo_getParami(const EffectProps*, ALCcontext *context, ALenum param, ALint*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid echo integer property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid echo integer property 0x%04x", param); } void Echo_getParamiv(const EffectProps*, ALCcontext *context, ALenum param, ALint*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid echo integer-vector property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid echo integer-vector property 0x%04x", param); } void Echo_getParamf(const EffectProps *props, ALCcontext *context, ALenum param, ALfloat *val) { switch(param) @@ -236,7 +235,7 @@ void Echo_getParamf(const EffectProps *props, ALCcontext *context, ALenum param, break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid echo float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid echo float property 0x%04x", param); } } void Echo_getParamfv(const EffectProps *props, ALCcontext *context, ALenum param, ALfloat *vals) diff --git a/alc/effects/equalizer.cpp b/alc/effects/equalizer.cpp index 25ccf264..4b900bcf 100644 --- a/alc/effects/equalizer.cpp +++ b/alc/effects/equalizer.cpp @@ -27,7 +27,6 @@ #include #include "al/auxeffectslot.h" -#include "al/error.h" #include "alcmain.h" #include "alcontext.h" #include "alu.h" @@ -174,9 +173,9 @@ void EqualizerState::process(const ALsizei samplesToDo, const FloatBufferLine *R void Equalizer_setParami(EffectProps*, ALCcontext *context, ALenum param, ALint) -{ alSetError(context, AL_INVALID_ENUM, "Invalid equalizer integer property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid equalizer integer property 0x%04x", param); } void Equalizer_setParamiv(EffectProps*, ALCcontext *context, ALenum param, const ALint*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid equalizer integer-vector property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid equalizer integer-vector property 0x%04x", param); } void Equalizer_setParamf(EffectProps *props, ALCcontext *context, ALenum param, ALfloat val) { switch(param) @@ -242,16 +241,16 @@ void Equalizer_setParamf(EffectProps *props, ALCcontext *context, ALenum param, break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid equalizer float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid equalizer float property 0x%04x", param); } } void Equalizer_setParamfv(EffectProps *props, ALCcontext *context, ALenum param, const ALfloat *vals) { Equalizer_setParamf(props, context, param, vals[0]); } void Equalizer_getParami(const EffectProps*, ALCcontext *context, ALenum param, ALint*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid equalizer integer property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid equalizer integer property 0x%04x", param); } void Equalizer_getParamiv(const EffectProps*, ALCcontext *context, ALenum param, ALint*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid equalizer integer-vector property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid equalizer integer-vector property 0x%04x", param); } void Equalizer_getParamf(const EffectProps *props, ALCcontext *context, ALenum param, ALfloat *val) { switch(param) @@ -297,7 +296,7 @@ void Equalizer_getParamf(const EffectProps *props, ALCcontext *context, ALenum p break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid equalizer float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid equalizer float property 0x%04x", param); } } void Equalizer_getParamfv(const EffectProps *props, ALCcontext *context, ALenum param, ALfloat *vals) diff --git a/alc/effects/fshifter.cpp b/alc/effects/fshifter.cpp index 9b204d2e..bca29bba 100644 --- a/alc/effects/fshifter.cpp +++ b/alc/effects/fshifter.cpp @@ -27,7 +27,6 @@ #include #include "al/auxeffectslot.h" -#include "al/error.h" #include "alcmain.h" #include "alcontext.h" #include "alu.h" @@ -213,7 +212,8 @@ void Fshifter_setParamf(EffectProps *props, ALCcontext *context, ALenum param, A break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid frequency shifter float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid frequency shifter float property 0x%04x", + param); } } void Fshifter_setParamfv(EffectProps *props, ALCcontext *context, ALenum param, const ALfloat *vals) @@ -236,7 +236,8 @@ void Fshifter_setParami(EffectProps *props, ALCcontext *context, ALenum param, A break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid frequency shifter integer property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid frequency shifter integer property 0x%04x", + param); } } void Fshifter_setParamiv(EffectProps *props, ALCcontext *context, ALenum param, const ALint *vals) @@ -253,7 +254,8 @@ void Fshifter_getParami(const EffectProps *props, ALCcontext *context, ALenum pa *val = props->Fshifter.RightDirection; break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid frequency shifter integer property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid frequency shifter integer property 0x%04x", + param); } } void Fshifter_getParamiv(const EffectProps *props, ALCcontext *context, ALenum param, ALint *vals) @@ -268,7 +270,8 @@ void Fshifter_getParamf(const EffectProps *props, ALCcontext *context, ALenum pa break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid frequency shifter float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid frequency shifter float property 0x%04x", + param); } } void Fshifter_getParamfv(const EffectProps *props, ALCcontext *context, ALenum param, ALfloat *vals) diff --git a/alc/effects/modulator.cpp b/alc/effects/modulator.cpp index bd63c56c..d7118285 100644 --- a/alc/effects/modulator.cpp +++ b/alc/effects/modulator.cpp @@ -27,7 +27,6 @@ #include #include "al/auxeffectslot.h" -#include "al/error.h" #include "alcmain.h" #include "alcontext.h" #include "alu.h" @@ -187,7 +186,7 @@ void Modulator_setParamf(EffectProps *props, ALCcontext *context, ALenum param, break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid modulator float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid modulator float property 0x%04x", param); } } void Modulator_setParamfv(EffectProps *props, ALCcontext *context, ALenum param, const ALfloat *vals) @@ -208,7 +207,7 @@ void Modulator_setParami(EffectProps *props, ALCcontext *context, ALenum param, break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid modulator integer property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid modulator integer property 0x%04x", param); } } void Modulator_setParamiv(EffectProps *props, ALCcontext *context, ALenum param, const ALint *vals) @@ -229,7 +228,7 @@ void Modulator_getParami(const EffectProps *props, ALCcontext *context, ALenum p break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid modulator integer property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid modulator integer property 0x%04x", param); } } void Modulator_getParamiv(const EffectProps *props, ALCcontext *context, ALenum param, ALint *vals) @@ -246,7 +245,7 @@ void Modulator_getParamf(const EffectProps *props, ALCcontext *context, ALenum p break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid modulator float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid modulator float property 0x%04x", param); } } void Modulator_getParamfv(const EffectProps *props, ALCcontext *context, ALenum param, ALfloat *vals) diff --git a/alc/effects/null.cpp b/alc/effects/null.cpp index c4eebb3d..245b9b04 100644 --- a/alc/effects/null.cpp +++ b/alc/effects/null.cpp @@ -5,8 +5,8 @@ #include "AL/alc.h" #include "al/auxeffectslot.h" -#include "al/error.h" #include "alcmain.h" +#include "alcontext.h" #include "almalloc.h" #include "alspan.h" #include "effects/base.h" @@ -69,7 +69,7 @@ void NullEffect_setParami(EffectProps* /*props*/, ALCcontext *context, ALenum pa switch(param) { default: - alSetError(context, AL_INVALID_ENUM, "Invalid null effect integer property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid null effect integer property 0x%04x", param); } } void NullEffect_setParamiv(EffectProps *props, ALCcontext *context, ALenum param, const ALint *vals) @@ -85,7 +85,7 @@ void NullEffect_setParamf(EffectProps* /*props*/, ALCcontext *context, ALenum pa switch(param) { default: - alSetError(context, AL_INVALID_ENUM, "Invalid null effect float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid null effect float property 0x%04x", param); } } void NullEffect_setParamfv(EffectProps *props, ALCcontext *context, ALenum param, const ALfloat *vals) @@ -102,7 +102,7 @@ void NullEffect_getParami(const EffectProps* /*props*/, ALCcontext *context, ALe switch(param) { default: - alSetError(context, AL_INVALID_ENUM, "Invalid null effect integer property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid null effect integer property 0x%04x", param); } } void NullEffect_getParamiv(const EffectProps *props, ALCcontext *context, ALenum param, ALint *vals) @@ -118,7 +118,7 @@ void NullEffect_getParamf(const EffectProps* /*props*/, ALCcontext *context, ALe switch(param) { default: - alSetError(context, AL_INVALID_ENUM, "Invalid null effect float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid null effect float property 0x%04x", param); } } void NullEffect_getParamfv(const EffectProps *props, ALCcontext *context, ALenum param, ALfloat *vals) diff --git a/alc/effects/pshifter.cpp b/alc/effects/pshifter.cpp index eac5894b..a08052b9 100644 --- a/alc/effects/pshifter.cpp +++ b/alc/effects/pshifter.cpp @@ -31,7 +31,6 @@ #include #include "al/auxeffectslot.h" -#include "al/error.h" #include "alcmain.h" #include "alcomplex.h" #include "alcontext.h" @@ -325,9 +324,9 @@ void PshifterState::process(const ALsizei samplesToDo, const FloatBufferLine *RE void Pshifter_setParamf(EffectProps*, ALCcontext *context, ALenum param, ALfloat) -{ alSetError(context, AL_INVALID_ENUM, "Invalid pitch shifter float property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid pitch shifter float property 0x%04x", param); } void Pshifter_setParamfv(EffectProps*, ALCcontext *context, ALenum param, const ALfloat*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid pitch shifter float-vector property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid pitch shifter float-vector property 0x%04x", param); } void Pshifter_setParami(EffectProps *props, ALCcontext *context, ALenum param, ALint val) { @@ -346,7 +345,8 @@ void Pshifter_setParami(EffectProps *props, ALCcontext *context, ALenum param, A break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid pitch shifter integer property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid pitch shifter integer property 0x%04x", + param); } } void Pshifter_setParamiv(EffectProps *props, ALCcontext *context, ALenum param, const ALint *vals) @@ -364,16 +364,17 @@ void Pshifter_getParami(const EffectProps *props, ALCcontext *context, ALenum pa break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid pitch shifter integer property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid pitch shifter integer property 0x%04x", + param); } } void Pshifter_getParamiv(const EffectProps *props, ALCcontext *context, ALenum param, ALint *vals) { Pshifter_getParami(props, context, param, vals); } void Pshifter_getParamf(const EffectProps*, ALCcontext *context, ALenum param, ALfloat*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid pitch shifter float property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid pitch shifter float property 0x%04x", param); } void Pshifter_getParamfv(const EffectProps*, ALCcontext *context, ALenum param, ALfloat*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid pitch shifter float vector-property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid pitch shifter float vector-property 0x%04x", param); } DEFINE_ALEFFECT_VTABLE(Pshifter); diff --git a/alc/effects/reverb.cpp b/alc/effects/reverb.cpp index bc4995ff..6e6844e0 100644 --- a/alc/effects/reverb.cpp +++ b/alc/effects/reverb.cpp @@ -30,7 +30,6 @@ #include #include "al/auxeffectslot.h" -#include "al/error.h" #include "al/listener.h" #include "alcmain.h" #include "alcontext.h" @@ -1545,8 +1544,8 @@ void EAXReverb_setParami(EffectProps *props, ALCcontext *context, ALenum param, break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid EAX reverb integer property 0x%04x", - param); + context->setError(AL_INVALID_ENUM, "Invalid EAX reverb integer property 0x%04x", + param); } } void EAXReverb_setParamiv(EffectProps *props, ALCcontext *context, ALenum param, const ALint *vals) @@ -1676,8 +1675,7 @@ void EAXReverb_setParamf(EffectProps *props, ALCcontext *context, ALenum param, break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid EAX reverb float property 0x%04x", - param); + context->setError(AL_INVALID_ENUM, "Invalid EAX reverb float property 0x%04x", param); } } void EAXReverb_setParamfv(EffectProps *props, ALCcontext *context, ALenum param, const ALfloat *vals) @@ -1714,8 +1712,8 @@ void EAXReverb_getParami(const EffectProps *props, ALCcontext *context, ALenum p break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid EAX reverb integer property 0x%04x", - param); + context->setError(AL_INVALID_ENUM, "Invalid EAX reverb integer property 0x%04x", + param); } } void EAXReverb_getParamiv(const EffectProps *props, ALCcontext *context, ALenum param, ALint *vals) @@ -1805,8 +1803,7 @@ void EAXReverb_getParamf(const EffectProps *props, ALCcontext *context, ALenum p break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid EAX reverb float property 0x%04x", - param); + context->setError(AL_INVALID_ENUM, "Invalid EAX reverb float property 0x%04x", param); } } void EAXReverb_getParamfv(const EffectProps *props, ALCcontext *context, ALenum param, ALfloat *vals) @@ -1884,7 +1881,7 @@ void StdReverb_setParami(EffectProps *props, ALCcontext *context, ALenum param, break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid reverb integer property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid reverb integer property 0x%04x", param); } } void StdReverb_setParamiv(EffectProps *props, ALCcontext *context, ALenum param, const ALint *vals) @@ -1966,7 +1963,7 @@ void StdReverb_setParamf(EffectProps *props, ALCcontext *context, ALenum param, break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid reverb float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid reverb float property 0x%04x", param); } } void StdReverb_setParamfv(EffectProps *props, ALCcontext *context, ALenum param, const ALfloat *vals) @@ -1981,7 +1978,7 @@ void StdReverb_getParami(const EffectProps *props, ALCcontext *context, ALenum p break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid reverb integer property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid reverb integer property 0x%04x", param); } } void StdReverb_getParamiv(const EffectProps *props, ALCcontext *context, ALenum param, ALint *vals) @@ -2039,7 +2036,7 @@ void StdReverb_getParamf(const EffectProps *props, ALCcontext *context, ALenum p break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid reverb float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid reverb float property 0x%04x", param); } } void StdReverb_getParamfv(const EffectProps *props, ALCcontext *context, ALenum param, ALfloat *vals) diff --git a/alc/effects/vmorpher.cpp b/alc/effects/vmorpher.cpp index ae8c98e1..95016105 100644 --- a/alc/effects/vmorpher.cpp +++ b/alc/effects/vmorpher.cpp @@ -26,7 +26,6 @@ #include #include "al/auxeffectslot.h" -#include "al/error.h" #include "alcmain.h" #include "alcontext.h" #include "alu.h" @@ -333,11 +332,12 @@ void Vmorpher_setParami(EffectProps* props, ALCcontext *context, ALenum param, A break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid vocal morpher integer property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid vocal morpher integer property 0x%04x", + param); } } void Vmorpher_setParamiv(EffectProps*, ALCcontext *context, ALenum param, const ALint*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid vocal morpher integer-vector property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid vocal morpher integer-vector property 0x%04x", param); } void Vmorpher_setParamf(EffectProps *props, ALCcontext *context, ALenum param, ALfloat val) { switch(param) @@ -349,7 +349,8 @@ void Vmorpher_setParamf(EffectProps *props, ALCcontext *context, ALenum param, A break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid vocal morpher float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid vocal morpher float property 0x%04x", + param); } } void Vmorpher_setParamfv(EffectProps *props, ALCcontext *context, ALenum param, const ALfloat *vals) @@ -380,11 +381,12 @@ void Vmorpher_getParami(const EffectProps* props, ALCcontext *context, ALenum pa break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid vocal morpher integer property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid vocal morpher integer property 0x%04x", + param); } } void Vmorpher_getParamiv(const EffectProps*, ALCcontext *context, ALenum param, ALint*) -{ alSetError(context, AL_INVALID_ENUM, "Invalid vocal morpher integer-vector property 0x%04x", param); } +{ context->setError(AL_INVALID_ENUM, "Invalid vocal morpher integer-vector property 0x%04x", param); } void Vmorpher_getParamf(const EffectProps *props, ALCcontext *context, ALenum param, ALfloat *val) { switch(param) @@ -394,7 +396,8 @@ void Vmorpher_getParamf(const EffectProps *props, ALCcontext *context, ALenum pa break; default: - alSetError(context, AL_INVALID_ENUM, "Invalid vocal morpher float property 0x%04x", param); + context->setError(AL_INVALID_ENUM, "Invalid vocal morpher float property 0x%04x", + param); } } void Vmorpher_getParamfv(const EffectProps *props, ALCcontext *context, ALenum param, ALfloat *vals) -- cgit v1.2.3 From a0aa5bc80a5c38f4ba92e38f924f4141344da819 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 31 Jul 2019 09:20:53 -0700 Subject: Add iterators to ALbufferlistitem And change some types to ALuint --- al/buffer.cpp | 7 ++- al/buffer.h | 6 +- al/source.cpp | 187 +++++++++++++++++++++++++------------------------------ al/source.h | 53 ++++++++++++++-- alc/mixvoice.cpp | 62 +++++++++--------- 5 files changed, 170 insertions(+), 145 deletions(-) (limited to 'al/source.cpp') diff --git a/al/buffer.cpp b/al/buffer.cpp index d6d743d0..4e843e03 100644 --- a/al/buffer.cpp +++ b/al/buffer.cpp @@ -459,14 +459,14 @@ void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALuint freq, ALsizei size, U if(UNLIKELY(size/SrcByteAlign > std::numeric_limits::max()/align)) SETERR_RETURN(context, AL_OUT_OF_MEMORY,, "Buffer size overflow, %d blocks x %d samples per block", size/SrcByteAlign, align); - const ALsizei frames{size / SrcByteAlign * align}; + const auto frames = static_cast(size / SrcByteAlign * align); /* Convert the sample frames to the number of bytes needed for internal * storage. */ ALsizei NumChannels{ChannelsFromFmt(DstChannels)}; ALsizei FrameSize{NumChannels * BytesFromFmt(DstType)}; - if(UNLIKELY(frames > std::numeric_limits::max()/FrameSize)) + if(UNLIKELY(frames > std::numeric_limits::max()/FrameSize)) SETERR_RETURN(context, AL_OUT_OF_MEMORY,, "Buffer size overflow, %d frames x %d bytes per frame", frames, FrameSize); size_t newsize{static_cast(frames) * FrameSize}; @@ -1129,7 +1129,8 @@ START_API_FUNC if(UNLIKELY(ReadRef(&albuf->ref) != 0)) context->setError(AL_INVALID_OPERATION, "Modifying in-use buffer %u's loop points", buffer); - else if(UNLIKELY(values[0] >= values[1] || values[0] < 0 || values[1] > albuf->SampleLen)) + else if(UNLIKELY(values[0] < 0 || values[0] >= values[1] || + static_cast(values[1]) > albuf->SampleLen)) context->setError(AL_INVALID_VALUE, "Invalid loop point range %d -> %d on buffer %u", values[0], values[1], buffer); else diff --git a/al/buffer.h b/al/buffer.h index 1d5873e5..e5149bb1 100644 --- a/al/buffer.h +++ b/al/buffer.h @@ -92,7 +92,7 @@ struct ALbuffer { ALsizei Frequency{0}; ALbitfieldSOFT Access{0u}; - ALsizei SampleLen{0}; + ALuint SampleLen{0u}; FmtChannels mFmtChannels{}; FmtType mFmtType{}; @@ -101,8 +101,8 @@ struct ALbuffer { ALsizei OriginalSize{0}; ALsizei OriginalAlign{0}; - ALsizei LoopStart{0}; - ALsizei LoopEnd{0}; + ALuint LoopStart{0u}; + ALuint LoopEnd{0u}; std::atomic UnpackAlign{0}; std::atomic PackAlign{0}; diff --git a/al/source.cpp b/al/source.cpp index ab509804..6708c970 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -205,8 +205,8 @@ int64_t GetSourceSampleOffset(ALsource *Source, ALCcontext *context, std::chrono const ALbufferlistitem *BufferList{Source->queue}; while(BufferList && BufferList != Current) { - readPos += int64_t{BufferList->max_samples} << 32; - BufferList = BufferList->next.load(std::memory_order_relaxed); + readPos += int64_t{BufferList->mMaxSamples} << 32; + BufferList = BufferList->mNext.load(std::memory_order_relaxed); } readPos = minu64(readPos, 0x7fffffffffffffff_u64); } @@ -252,17 +252,17 @@ ALdouble GetSourceSecOffset(ALsource *Source, ALCcontext *context, std::chrono:: const ALbuffer *BufferFmt{nullptr}; while(BufferList && BufferList != Current) { - for(ALsizei i{0};!BufferFmt && i < BufferList->num_buffers;++i) - BufferFmt = BufferList->buffers[i]; - readPos += int64_t{BufferList->max_samples} << FRACTIONBITS; - BufferList = BufferList->next.load(std::memory_order_relaxed); + for(ALuint i{0};!BufferFmt && i < BufferList->mNumBuffers;++i) + BufferFmt = (*BufferList)[i]; + readPos += int64_t{BufferList->mMaxSamples} << FRACTIONBITS; + BufferList = BufferList->mNext.load(std::memory_order_relaxed); } while(BufferList && !BufferFmt) { - for(ALsizei i{0};!BufferFmt && i < BufferList->num_buffers;++i) - BufferFmt = BufferList->buffers[i]; - BufferList = BufferList->next.load(std::memory_order_relaxed); + for(ALuint i{0};!BufferFmt && i < BufferList->mNumBuffers;++i) + BufferFmt = (*BufferList)[i]; + BufferList = BufferList->mNext.load(std::memory_order_relaxed); } assert(BufferFmt != nullptr); @@ -314,14 +314,14 @@ ALdouble GetSourceOffset(ALsource *Source, ALenum name, ALCcontext *context) while(BufferList) { - for(ALsizei i{0};!BufferFmt && i < BufferList->num_buffers;++i) - BufferFmt = BufferList->buffers[i]; + for(ALuint i{0};!BufferFmt && i < BufferList->mNumBuffers;++i) + BufferFmt = (*BufferList)[i]; readFin |= (BufferList == Current); - totalBufferLen += BufferList->max_samples; - if(!readFin) readPos += BufferList->max_samples; + totalBufferLen += BufferList->mMaxSamples; + if(!readFin) readPos += BufferList->mMaxSamples; - BufferList = BufferList->next.load(std::memory_order_relaxed); + BufferList = BufferList->mNext.load(std::memory_order_relaxed); } assert(BufferFmt != nullptr); @@ -393,10 +393,10 @@ ALboolean GetSampleOffset(ALsource *Source, ALuint *offset, ALsizei *frac) BufferList = Source->queue; while(BufferList) { - for(ALsizei i{0};i < BufferList->num_buffers && !BufferFmt;i++) - BufferFmt = BufferList->buffers[i]; + for(ALuint i{0};!BufferFmt && i < BufferList->mNumBuffers;i++) + BufferFmt = (*BufferList)[i]; if(BufferFmt) break; - BufferList = BufferList->next.load(std::memory_order_relaxed); + BufferList = BufferList->mNext.load(std::memory_order_relaxed); } if(!BufferFmt) { @@ -463,7 +463,7 @@ ALboolean ApplyOffset(ALsource *Source, ALvoice *voice) ALbufferlistitem *BufferList{Source->queue}; while(BufferList && totalBufferLen <= offset) { - if(static_cast(BufferList->max_samples) > offset-totalBufferLen) + if(static_cast(BufferList->mMaxSamples) > offset-totalBufferLen) { /* Offset is in this buffer */ voice->mPosition.store(offset - totalBufferLen, std::memory_order_relaxed); @@ -471,9 +471,9 @@ ALboolean ApplyOffset(ALsource *Source, ALvoice *voice) voice->mCurrentBuffer.store(BufferList, std::memory_order_release); return AL_TRUE; } - totalBufferLen += BufferList->max_samples; + totalBufferLen += BufferList->mMaxSamples; - BufferList = BufferList->next.load(std::memory_order_relaxed); + BufferList = BufferList->mNext.load(std::memory_order_relaxed); } /* Offset is out of range of the queue */ @@ -1305,10 +1305,10 @@ ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, co /* Add the selected buffer to a one-item queue */ auto newlist = static_cast(al_calloc(alignof(void*), ALbufferlistitem::Sizeof(1u))); - newlist->next.store(nullptr, std::memory_order_relaxed); - newlist->max_samples = buffer->SampleLen; - newlist->num_buffers = 1; - newlist->buffers[0] = buffer; + newlist->mNext.store(nullptr, std::memory_order_relaxed); + newlist->mMaxSamples = buffer->SampleLen; + newlist->mNumBuffers = 1; + newlist->mBuffers[0] = buffer; IncrementRef(&buffer->ref); /* Source is now Static */ @@ -1327,13 +1327,11 @@ ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, co while(oldlist != nullptr) { ALbufferlistitem *temp{oldlist}; - oldlist = temp->next.load(std::memory_order_relaxed); + oldlist = temp->mNext.load(std::memory_order_relaxed); - for(ALsizei i{0};i < temp->num_buffers;i++) - { - if(temp->buffers[i]) - DecrementRef(&temp->buffers[i]->ref); - } + std::for_each(temp->begin(), temp->end(), + [](ALbuffer *buffer) -> void + { if(buffer) DecrementRef(&buffer->ref); }); al_free(temp); } return AL_TRUE; @@ -1846,8 +1844,8 @@ ALboolean GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, AL case AL_BUFFER: BufferList = (Source->SourceType == AL_STATIC) ? Source->queue : nullptr; - *values = (BufferList && BufferList->num_buffers >= 1 && BufferList->buffers[0]) ? - BufferList->buffers[0]->id : 0; + *values = (BufferList && BufferList->mNumBuffers >= 1 && BufferList->front()) ? + BufferList->front()->id : 0; return AL_TRUE; case AL_SOURCE_STATE: @@ -1861,8 +1859,8 @@ ALboolean GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, AL { ALsizei count = 0; do { - count += BufferList->num_buffers; - BufferList = BufferList->next.load(std::memory_order_relaxed); + count += BufferList->mNumBuffers; + BufferList = BufferList->mNext.load(std::memory_order_relaxed); } while(BufferList != nullptr); *values = count; } @@ -1889,8 +1887,8 @@ ALboolean GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, AL while(BufferList && BufferList != Current) { - played += BufferList->num_buffers; - BufferList = BufferList->next.load(std::memory_order_relaxed); + played += BufferList->mNumBuffers; + BufferList = BufferList->mNext.load(std::memory_order_relaxed); } *values = played; } @@ -2840,8 +2838,8 @@ START_API_FUNC * length buffer. */ ALbufferlistitem *BufferList{source->queue}; - while(BufferList && BufferList->max_samples == 0) - BufferList = BufferList->next.load(std::memory_order_relaxed); + while(BufferList && BufferList->mMaxSamples == 0) + BufferList = BufferList->mNext.load(std::memory_order_relaxed); /* If there's nothing to play, go right to stopped. */ if(UNLIKELY(!BufferList)) @@ -2918,10 +2916,9 @@ START_API_FUNC voice->mPositionFrac.load(std::memory_order_relaxed) != 0 || voice->mCurrentBuffer.load(std::memory_order_relaxed) != BufferList; - auto buffers_end = BufferList->buffers + BufferList->num_buffers; - auto buffer = std::find_if(BufferList->buffers, buffers_end, + auto buffer = std::find_if(BufferList->cbegin(), BufferList->cend(), std::bind(std::not_equal_to{}, _1, nullptr)); - if(buffer != buffers_end) + if(buffer != BufferList->cend()) { voice->mFrequency = (*buffer)->Frequency; voice->mFmtChannels = (*buffer)->mFmtChannels; @@ -3215,13 +3212,10 @@ START_API_FUNC ALbufferlistitem *BufferList{source->queue}; while(BufferList) { - for(ALsizei i{0};i < BufferList->num_buffers;i++) - { - if((BufferFmt=BufferList->buffers[i]) != nullptr) - break; - } + for(ALuint i{0};!BufferFmt && i < BufferList->mNumBuffers;i++) + BufferFmt = (*BufferList)[i]; if(BufferFmt) break; - BufferList = BufferList->next.load(std::memory_order_relaxed); + BufferList = BufferList->mNext.load(std::memory_order_relaxed); } std::unique_lock buflock{device->BufferLock}; @@ -3246,13 +3240,13 @@ START_API_FUNC { auto item = static_cast(al_calloc(alignof(void*), ALbufferlistitem::Sizeof(1u))); - BufferList->next.store(item, std::memory_order_relaxed); + BufferList->mNext.store(item, std::memory_order_relaxed); BufferList = item; } - BufferList->next.store(nullptr, std::memory_order_relaxed); - BufferList->max_samples = buffer ? buffer->SampleLen : 0; - BufferList->num_buffers = 1; - BufferList->buffers[0] = buffer; + BufferList->mNext.store(nullptr, std::memory_order_relaxed); + BufferList->mMaxSamples = buffer ? buffer->SampleLen : 0; + BufferList->mNumBuffers = 1; + BufferList->mBuffers[0] = buffer; if(!buffer) continue; IncrementRef(&buffer->ref); @@ -3277,12 +3271,10 @@ START_API_FUNC * each buffer we had. */ while(BufferListStart) { - ALbufferlistitem *next = BufferListStart->next.load(std::memory_order_relaxed); - for(i = 0;i < BufferListStart->num_buffers;i++) - { - if((buffer=BufferListStart->buffers[i]) != nullptr) - DecrementRef(&buffer->ref); - } + ALbufferlistitem *next = BufferListStart->mNext.load(std::memory_order_relaxed); + std::for_each(BufferListStart->begin(), BufferListStart->end(), + [](ALbuffer *buffer) -> void + { if(buffer) DecrementRef(&buffer->ref); }); al_free(BufferListStart); BufferListStart = next; } @@ -3300,9 +3292,9 @@ START_API_FUNC else { ALbufferlistitem *next; - while((next=BufferList->next.load(std::memory_order_relaxed)) != nullptr) + while((next=BufferList->mNext.load(std::memory_order_relaxed)) != nullptr) BufferList = next; - BufferList->next.store(BufferListStart, std::memory_order_release); + BufferList->mNext.store(BufferListStart, std::memory_order_release); } } END_API_FUNC @@ -3332,22 +3324,19 @@ START_API_FUNC ALbufferlistitem *BufferList{source->queue}; while(BufferList) { - for(ALsizei i{0};i < BufferList->num_buffers;i++) - { - if((BufferFmt=BufferList->buffers[i]) != nullptr) - break; - } + for(ALuint i{0};!BufferFmt && i < BufferList->mNumBuffers;i++) + BufferFmt = (*BufferList)[i]; if(BufferFmt) break; - BufferList = BufferList->next.load(std::memory_order_relaxed); + BufferList = BufferList->mNext.load(std::memory_order_relaxed); } std::unique_lock buflock{device->BufferLock}; auto BufferListStart = static_cast(al_calloc(alignof(void*), ALbufferlistitem::Sizeof(nb))); BufferList = BufferListStart; - BufferList->next.store(nullptr, std::memory_order_relaxed); - BufferList->max_samples = 0; - BufferList->num_buffers = 0; + BufferList->mNext.store(nullptr, std::memory_order_relaxed); + BufferList->mMaxSamples = 0; + BufferList->mNumBuffers = 0; for(ALsizei i{0};i < nb;i++) { @@ -3358,12 +3347,12 @@ START_API_FUNC goto buffer_error; } - BufferList->buffers[BufferList->num_buffers++] = buffer; + BufferList->mBuffers[BufferList->mNumBuffers++] = buffer; if(!buffer) continue; IncrementRef(&buffer->ref); - BufferList->max_samples = maxi(BufferList->max_samples, buffer->SampleLen); + BufferList->mMaxSamples = maxu(BufferList->mMaxSamples, buffer->SampleLen); if(buffer->MappedAccess != 0 && !(buffer->MappedAccess&AL_MAP_PERSISTENT_BIT_SOFT)) { @@ -3385,12 +3374,10 @@ START_API_FUNC * each buffer we had. */ while(BufferListStart) { - ALbufferlistitem *next{BufferListStart->next.load(std::memory_order_relaxed)}; - for(i = 0;i < BufferListStart->num_buffers;i++) - { - if((buffer=BufferListStart->buffers[i]) != nullptr) - DecrementRef(&buffer->ref); - } + ALbufferlistitem *next{BufferListStart->mNext.load(std::memory_order_relaxed)}; + std::for_each(BufferListStart->begin(), BufferListStart->end(), + [](ALbuffer *buffer) -> void + { if(buffer) DecrementRef(&buffer->ref); }); al_free(BufferListStart); BufferListStart = next; } @@ -3408,9 +3395,9 @@ START_API_FUNC else { ALbufferlistitem *next; - while((next=BufferList->next.load(std::memory_order_relaxed)) != nullptr) + while((next=BufferList->mNext.load(std::memory_order_relaxed)) != nullptr) BufferList = next; - BufferList->next.store(BufferListStart, std::memory_order_release); + BufferList->mNext.store(BufferListStart, std::memory_order_release); } } END_API_FUNC @@ -3447,27 +3434,27 @@ START_API_FUNC if(UNLIKELY(BufferList == Current)) SETERR_RETURN(context, AL_INVALID_VALUE,, "Unqueueing pending buffers"); - ALsizei i{BufferList->num_buffers}; - while(i < nb) + ALuint i{BufferList->mNumBuffers}; + while(i < static_cast(nb)) { /* If the next bufferlist to check is NULL or is the current one, it's * trying to unqueue pending buffers. */ - ALbufferlistitem *next{BufferList->next.load(std::memory_order_relaxed)}; + ALbufferlistitem *next{BufferList->mNext.load(std::memory_order_relaxed)}; if(UNLIKELY(!next) || UNLIKELY(next == Current)) SETERR_RETURN(context, AL_INVALID_VALUE,, "Unqueueing pending buffers"); BufferList = next; - i += BufferList->num_buffers; + i += BufferList->mNumBuffers; } while(nb > 0) { ALbufferlistitem *head{source->queue}; - ALbufferlistitem *next{head->next.load(std::memory_order_relaxed)}; - for(i = 0;i < head->num_buffers && nb > 0;i++,nb--) + ALbufferlistitem *next{head->mNext.load(std::memory_order_relaxed)}; + for(i = 0;i < head->mNumBuffers && nb > 0;i++,nb--) { - ALbuffer *buffer{head->buffers[i]}; + ALbuffer *buffer{(*head)[i]}; if(!buffer) *(buffers++) = 0; else @@ -3476,21 +3463,21 @@ START_API_FUNC DecrementRef(&buffer->ref); } } - if(i < head->num_buffers) + if(i < head->mNumBuffers) { /* This head has some buffers left over, so move them to the front * and update the sample and buffer count. */ - ALsizei max_length{0}; - ALsizei j{0}; - while(i < head->num_buffers) + ALuint max_length{0}; + ALuint j{0}; + while(i < head->mNumBuffers) { - ALbuffer *buffer{head->buffers[i++]}; - if(buffer) max_length = maxi(max_length, buffer->SampleLen); - head->buffers[j++] = buffer; + ALbuffer *buffer{(*head)[i++]}; + if(buffer) max_length = maxu(max_length, buffer->SampleLen); + head->mBuffers[j++] = buffer; } - head->max_samples = max_length; - head->num_buffers = j; + head->mMaxSamples = max_length; + head->mNumBuffers = j; break; } @@ -3584,12 +3571,10 @@ ALsource::~ALsource() ALbufferlistitem *BufferList{queue}; while(BufferList != nullptr) { - ALbufferlistitem *next{BufferList->next.load(std::memory_order_relaxed)}; - for(ALsizei i{0};i < BufferList->num_buffers;i++) - { - if(BufferList->buffers[i]) - DecrementRef(&BufferList->buffers[i]->ref); - } + ALbufferlistitem *next{BufferList->mNext.load(std::memory_order_relaxed)}; + std::for_each(BufferList->begin(), BufferList->end(), + [](ALbuffer *buffer) -> void + { if(buffer) DecrementRef(&buffer->ref); }); al_free(BufferList); BufferList = next; } diff --git a/al/source.h b/al/source.h index c9892398..1aafafab 100644 --- a/al/source.h +++ b/al/source.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "AL/al.h" #include "AL/alc.h" @@ -21,16 +22,58 @@ struct ALeffectslot; struct ALbufferlistitem { - std::atomic next; - ALsizei max_samples; - ALsizei num_buffers; - ALbuffer *buffers[]; + using element_type = ALbuffer*; + using value_type = ALbuffer*; + using index_type = size_t; + using difference_type = ptrdiff_t; + + using pointer = ALbuffer**; + using const_pointer = ALbuffer*const*; + using reference = ALbuffer*&; + using const_reference = ALbuffer*const&; + + using iterator = pointer; + using const_iterator = const_pointer; + using reverse_iterator = std::reverse_iterator; + using const_reverse_iterator = std::reverse_iterator; + + + std::atomic mNext; + ALuint mMaxSamples; + ALuint mNumBuffers; + element_type mBuffers[]; static constexpr size_t Sizeof(size_t num_buffers) noexcept { - return maxz(offsetof(ALbufferlistitem, buffers) + sizeof(ALbuffer*)*num_buffers, + return maxz(offsetof(ALbufferlistitem, mBuffers) + sizeof(element_type)*num_buffers, sizeof(ALbufferlistitem)); } + + reference front() { return mBuffers[0]; } + const_reference front() const { return mBuffers[0]; } + reference back() { return mBuffers[mNumBuffers-1]; } + const_reference back() const { return mBuffers[mNumBuffers-1]; } + reference operator[](index_type idx) { return mBuffers[idx]; } + const_reference operator[](index_type idx) const { return mBuffers[idx]; } + pointer data() noexcept { return mBuffers; } + const_pointer data() const noexcept { return mBuffers; } + + index_type size() const noexcept { return mNumBuffers; } + bool empty() const noexcept { return mNumBuffers == 0; } + + iterator begin() noexcept { return mBuffers; } + iterator end() noexcept { return mBuffers+mNumBuffers; } + const_iterator begin() const noexcept { return mBuffers; } + const_iterator end() const noexcept { return mBuffers+mNumBuffers; } + const_iterator cbegin() const noexcept { return mBuffers; } + const_iterator cend() const noexcept { return mBuffers+mNumBuffers; } + + reverse_iterator rbegin() noexcept { return reverse_iterator{end()}; } + reverse_iterator rend() noexcept { return reverse_iterator{begin()}; } + const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator{end()}; } + const_reverse_iterator rend() const noexcept { return const_reverse_iterator{begin()}; } + const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator{cend()}; } + const_reverse_iterator crend() const noexcept { return const_reverse_iterator{cbegin()}; } }; diff --git a/alc/mixvoice.cpp b/alc/mixvoice.cpp index 881759c0..e2b2bf51 100644 --- a/alc/mixvoice.cpp +++ b/alc/mixvoice.cpp @@ -382,15 +382,15 @@ void LoadSamples(ALfloat *RESTRICT dst, const al::byte *src, ALint srcstep, FmtT } ALfloat *LoadBufferStatic(ALbufferlistitem *BufferListItem, ALbufferlistitem *&BufferLoopItem, - const ALsizei NumChannels, const ALsizei SampleSize, const ALsizei chan, ALsizei DataPosInt, + const ALsizei NumChannels, const ALsizei SampleSize, const ALsizei chan, ALuint DataPosInt, al::span SrcBuffer) { /* TODO: For static sources, loop points are taken from the first buffer * (should be adjusted by any buffer offset, to possibly be added later). */ - const ALbuffer *Buffer0{BufferListItem->buffers[0]}; - const ALsizei LoopStart{Buffer0->LoopStart}; - const ALsizei LoopEnd{Buffer0->LoopEnd}; + const ALbuffer *Buffer0{BufferListItem->front()}; + const ALuint LoopStart{Buffer0->LoopStart}; + const ALuint LoopEnd{Buffer0->LoopEnd}; ASSUME(LoopStart >= 0); ASSUME(LoopEnd > LoopStart); @@ -416,10 +416,9 @@ ALfloat *LoadBufferStatic(ALbufferlistitem *BufferListItem, ALbufferlistitem *&B return CompLen; }; /* It's impossible to have a buffer list item with no entries. */ - ASSUME(BufferListItem->num_buffers > 0); - auto buffers_end = BufferListItem->buffers + BufferListItem->num_buffers; - SrcBuffer = SrcBuffer.subspan(std::accumulate(BufferListItem->buffers, buffers_end, - size_t{0u}, load_buffer)); + ASSUME(BufferListItem->mNumBuffers > 0); + SrcBuffer = SrcBuffer.subspan(std::accumulate(BufferListItem->begin(), + BufferListItem->end(), size_t{0u}, load_buffer)); } else { @@ -442,10 +441,9 @@ ALfloat *LoadBufferStatic(ALbufferlistitem *BufferListItem, ALbufferlistitem *&B LoadSamples(SrcData.data(), Data, NumChannels, buffer->mFmtType, DataSize); return CompLen; }; - ASSUME(BufferListItem->num_buffers > 0); - auto buffers_end = BufferListItem->buffers + BufferListItem->num_buffers; - SrcBuffer = SrcBuffer.subspan(std::accumulate(BufferListItem->buffers, buffers_end, - size_t{0u}, load_buffer)); + ASSUME(BufferListItem->mNumBuffers > 0); + SrcBuffer = SrcBuffer.subspan(std::accumulate(BufferListItem->begin(), + BufferListItem->end(), size_t{0u}, load_buffer)); const auto LoopSize = static_cast(LoopEnd - LoopStart); while(!SrcBuffer.empty()) @@ -468,24 +466,24 @@ ALfloat *LoadBufferStatic(ALbufferlistitem *BufferListItem, ALbufferlistitem *&B LoadSamples(SrcData.data(), Data, NumChannels, buffer->mFmtType, DataSize); return CompLen; }; - SrcBuffer = SrcBuffer.subspan(std::accumulate(BufferListItem->buffers, buffers_end, - size_t{0u}, load_buffer_loop)); + SrcBuffer = SrcBuffer.subspan(std::accumulate(BufferListItem->begin(), + BufferListItem->end(), size_t{0u}, load_buffer_loop)); } } return SrcBuffer.begin(); } ALfloat *LoadBufferQueue(ALbufferlistitem *BufferListItem, ALbufferlistitem *BufferLoopItem, - const ALsizei NumChannels, const ALsizei SampleSize, const ALsizei chan, ALsizei DataPosInt, + const ALsizei NumChannels, const ALsizei SampleSize, const ALsizei chan, ALuint DataPosInt, al::span SrcBuffer) { /* Crawl the buffer queue to fill in the temp buffer */ while(BufferListItem && !SrcBuffer.empty()) { - if(DataPosInt >= BufferListItem->max_samples) + if(DataPosInt >= BufferListItem->mMaxSamples) { - DataPosInt -= BufferListItem->max_samples; - BufferListItem = BufferListItem->next.load(std::memory_order_acquire); + DataPosInt -= BufferListItem->mMaxSamples; + BufferListItem = BufferListItem->mNext.load(std::memory_order_acquire); if(!BufferListItem) BufferListItem = BufferLoopItem; continue; } @@ -505,15 +503,14 @@ ALfloat *LoadBufferQueue(ALbufferlistitem *BufferListItem, ALbufferlistitem *Buf LoadSamples(SrcBuffer.data(), Data, NumChannels, buffer->mFmtType, DataSize); return CompLen; }; - ASSUME(BufferListItem->num_buffers > 0); - auto buffers_end = BufferListItem->buffers + BufferListItem->num_buffers; - SrcBuffer = SrcBuffer.subspan(std::accumulate(BufferListItem->buffers, buffers_end, - size_t{0u}, load_buffer)); + ASSUME(BufferListItem->mNumBuffers > 0); + SrcBuffer = SrcBuffer.subspan(std::accumulate(BufferListItem->begin(), + BufferListItem->end(), size_t{0u}, load_buffer)); if(SrcBuffer.empty()) break; DataPosInt = 0; - BufferListItem = BufferListItem->next.load(std::memory_order_acquire); + BufferListItem = BufferListItem->mNext.load(std::memory_order_acquire); if(!BufferListItem) BufferListItem = BufferLoopItem; } @@ -530,7 +527,7 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc /* Get voice info */ const bool isstatic{(voice->mFlags&VOICE_IS_STATIC) != 0}; - ALsizei DataPosInt{static_cast(voice->mPosition.load(std::memory_order_relaxed))}; + ALuint DataPosInt{voice->mPosition.load(std::memory_order_relaxed)}; ALsizei DataPosFrac{voice->mPositionFrac.load(std::memory_order_relaxed)}; ALbufferlistitem *BufferListItem{voice->mCurrentBuffer.load(std::memory_order_relaxed)}; ALbufferlistitem *BufferLoopItem{voice->mLoopBuffer.load(std::memory_order_relaxed)}; @@ -538,7 +535,6 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc const ALsizei SampleSize{voice->mSampleSize}; const ALint increment{voice->mStep}; - ASSUME(DataPosInt >= 0); ASSUME(DataPosFrac >= 0); ASSUME(NumChannels > 0); ASSUME(SampleSize > 0); @@ -868,9 +864,9 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc if(BufferLoopItem) { /* Handle looping static source */ - const ALbuffer *Buffer{BufferListItem->buffers[0]}; - const ALsizei LoopStart{Buffer->LoopStart}; - const ALsizei LoopEnd{Buffer->LoopEnd}; + const ALbuffer *Buffer{BufferListItem->front()}; + const ALuint LoopStart{Buffer->LoopStart}; + const ALuint LoopEnd{Buffer->LoopEnd}; if(DataPosInt >= LoopEnd) { assert(LoopEnd > LoopStart); @@ -880,7 +876,7 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc else { /* Handle non-looping static source */ - if(DataPosInt >= BufferListItem->max_samples) + if(DataPosInt >= BufferListItem->mMaxSamples) { if(LIKELY(vstate == ALvoice::Playing)) vstate = ALvoice::Stopped; @@ -892,13 +888,13 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc else while(1) { /* Handle streaming source */ - if(BufferListItem->max_samples > DataPosInt) + if(BufferListItem->mMaxSamples > DataPosInt) break; - DataPosInt -= BufferListItem->max_samples; + DataPosInt -= BufferListItem->mMaxSamples; - buffers_done += BufferListItem->num_buffers; - BufferListItem = BufferListItem->next.load(std::memory_order_relaxed); + buffers_done += BufferListItem->mNumBuffers; + BufferListItem = BufferListItem->mNext.load(std::memory_order_relaxed); if(!BufferListItem && !(BufferListItem=BufferLoopItem)) { if(LIKELY(vstate == ALvoice::Playing)) -- cgit v1.2.3 From 65f7fc610e6a6101509906c0c9bbbd794c9a3737 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 1 Aug 2019 13:28:53 -0700 Subject: Add a common base for auto-deleting ref-counted objects Which will also work as the basis for a future intrusive_ptr --- CMakeLists.txt | 1 + al/auxeffectslot.cpp | 44 +++++++++++-------------------- al/buffer.cpp | 8 +++--- al/event.cpp | 2 +- al/source.cpp | 26 +++++++++---------- alc/alc.cpp | 70 +++++++++++++++++--------------------------------- alc/alcmain.h | 5 ++-- alc/alcontext.h | 9 +++---- alc/alu.cpp | 24 +++++------------ alc/backends/base.cpp | 4 +-- alc/effects/base.h | 9 ++----- alc/hrtf.cpp | 8 +++--- common/atomic.h | 16 ++++++------ common/intrusive_ptr.h | 48 ++++++++++++++++++++++++++++++++++ 14 files changed, 133 insertions(+), 141 deletions(-) create mode 100644 common/intrusive_ptr.h (limited to 'al/source.cpp') diff --git a/CMakeLists.txt b/CMakeLists.txt index e72f2a01..5f3f9763 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -598,6 +598,7 @@ SET(COMMON_OBJS common/aloptional.h common/alspan.h common/atomic.h + common/intrusive_ptr.h common/math_defs.h common/opthelpers.h common/threads.cpp diff --git a/al/auxeffectslot.cpp b/al/auxeffectslot.cpp index 2d10efde..b4e93858 100644 --- a/al/auxeffectslot.cpp +++ b/al/auxeffectslot.cpp @@ -320,7 +320,7 @@ START_API_FUNC context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", id); return true; } - if(ReadRef(&slot->ref) != 0) + if(ReadRef(slot->ref) != 0) { context->setError(AL_INVALID_NAME, "Deleting in-use effect slot %u", id); return true; @@ -418,14 +418,14 @@ START_API_FUNC /* We must force an update if there was an existing effect slot * target, in case it's about to be deleted. */ - if(target) IncrementRef(&target->ref); - DecrementRef(&oldtarget->ref); + if(target) IncrementRef(target->ref); + DecrementRef(oldtarget->ref); slot->Target = target; UpdateEffectSlotProps(slot, context.get()); return; } - if(target) IncrementRef(&target->ref); + if(target) IncrementRef(target->ref); slot->Target = target; break; @@ -651,7 +651,7 @@ ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect { statelock.unlock(); mixer_mode.leave(); - State->DecRef(); + State->release(); return AL_OUT_OF_MEMORY; } mixer_mode.leave(); @@ -667,7 +667,7 @@ ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect EffectSlot->Effect.Props = effect->Props; } - EffectSlot->Effect.State->DecRef(); + EffectSlot->Effect.State->release(); EffectSlot->Effect.State = State; } else if(effect) @@ -678,7 +678,7 @@ ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect while(props) { if(props->State) - props->State->DecRef(); + props->State->release(); props->State = nullptr; props = props->next.load(std::memory_order_relaxed); } @@ -687,20 +687,6 @@ ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect } -void EffectState::IncRef() noexcept -{ - auto ref = IncrementRef(&mRef); - TRACEREF("EffectState %p increasing refcount to %u\n", this, ref); -} - -void EffectState::DecRef() noexcept -{ - auto ref = DecrementRef(&mRef); - TRACEREF("EffectState %p decreasing refcount to %u\n", this, ref); - if(ref == 0) delete this; -} - - ALenum InitEffectSlot(ALeffectslot *slot) { EffectStateFactory *factory{getFactoryByType(slot->Effect.Type)}; @@ -708,7 +694,7 @@ ALenum InitEffectSlot(ALeffectslot *slot) slot->Effect.State = factory->create(); if(!slot->Effect.State) return AL_OUT_OF_MEMORY; - slot->Effect.State->IncRef(); + slot->Effect.State->add_ref(); slot->Params.mEffectState = slot->Effect.State; return AL_NO_ERROR; } @@ -716,21 +702,21 @@ ALenum InitEffectSlot(ALeffectslot *slot) ALeffectslot::~ALeffectslot() { if(Target) - DecrementRef(&Target->ref); + DecrementRef(Target->ref); Target = nullptr; ALeffectslotProps *props{Update.load()}; if(props) { - if(props->State) props->State->DecRef(); + if(props->State) props->State->release(); TRACE("Freed unapplied AuxiliaryEffectSlot update %p\n", props); al_free(props); } if(Effect.State) - Effect.State->DecRef(); + Effect.State->release(); if(Params.mEffectState) - Params.mEffectState->DecRef(); + Params.mEffectState->release(); } void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context) @@ -759,7 +745,7 @@ void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context) * delete it. */ EffectState *oldstate{props->State}; - slot->Effect.State->IncRef(); + slot->Effect.State->add_ref(); props->State = slot->Effect.State; /* Set the new container for updating internal parameters. */ @@ -770,13 +756,13 @@ void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context) * freelist. */ if(props->State) - props->State->DecRef(); + props->State->release(); props->State = nullptr; AtomicReplaceHead(context->mFreeEffectslotProps, props); } if(oldstate) - oldstate->DecRef(); + oldstate->release(); } void UpdateAllEffectSlotProps(ALCcontext *context) diff --git a/al/buffer.cpp b/al/buffer.cpp index 4e843e03..173c76bd 100644 --- a/al/buffer.cpp +++ b/al/buffer.cpp @@ -380,7 +380,7 @@ const ALchar *NameFromUserFmtType(UserFmtType type) */ void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALuint freq, ALsizei size, UserFmtChannels SrcChannels, UserFmtType SrcType, const al::byte *SrcData, ALbitfieldSOFT access) { - if(UNLIKELY(ReadRef(&ALBuf->ref) != 0 || ALBuf->MappedAccess != 0)) + if(UNLIKELY(ReadRef(ALBuf->ref) != 0 || ALBuf->MappedAccess != 0)) SETERR_RETURN(context, AL_INVALID_OPERATION,, "Modifying storage for in-use buffer %u", ALBuf->id); @@ -671,7 +671,7 @@ START_API_FUNC context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", bid); return true; } - if(UNLIKELY(ReadRef(&ALBuf->ref) != 0)) + if(UNLIKELY(ReadRef(ALBuf->ref) != 0)) { context->setError(AL_INVALID_OPERATION, "Deleting in-use buffer %u", bid); return true; @@ -768,7 +768,7 @@ START_API_FUNC else { ALbitfieldSOFT unavailable = (albuf->Access^access) & access; - if(UNLIKELY(ReadRef(&albuf->ref) != 0 && !(access&AL_MAP_PERSISTENT_BIT_SOFT))) + if(UNLIKELY(ReadRef(albuf->ref) != 0 && !(access&AL_MAP_PERSISTENT_BIT_SOFT))) context->setError(AL_INVALID_OPERATION, "Mapping in-use buffer %u without persistent mapping", buffer); else if(UNLIKELY(albuf->MappedAccess != 0)) @@ -1126,7 +1126,7 @@ START_API_FUNC else switch(param) { case AL_LOOP_POINTS_SOFT: - if(UNLIKELY(ReadRef(&albuf->ref) != 0)) + if(UNLIKELY(ReadRef(albuf->ref) != 0)) context->setError(AL_INVALID_OPERATION, "Modifying in-use buffer %u's loop points", buffer); else if(UNLIKELY(values[0] < 0 || values[0] >= values[1] || diff --git a/al/event.cpp b/al/event.cpp index 0d41e713..75827b59 100644 --- a/al/event.cpp +++ b/al/event.cpp @@ -64,7 +64,7 @@ static int EventThread(ALCcontext *context) if(evt.EnumType == EventType_ReleaseEffectState) { - evt.u.mEffectState->DecRef(); + evt.u.mEffectState->release(); continue; } diff --git a/al/source.cpp b/al/source.cpp index 6708c970..1e0940de 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -1309,7 +1309,7 @@ ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, co newlist->mMaxSamples = buffer->SampleLen; newlist->mNumBuffers = 1; newlist->mBuffers[0] = buffer; - IncrementRef(&buffer->ref); + IncrementRef(buffer->ref); /* Source is now Static */ Source->SourceType = AL_STATIC; @@ -1331,7 +1331,7 @@ ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, co std::for_each(temp->begin(), temp->end(), [](ALbuffer *buffer) -> void - { if(buffer) DecrementRef(&buffer->ref); }); + { if(buffer) DecrementRef(buffer->ref); }); al_free(temp); } return AL_TRUE; @@ -1475,9 +1475,9 @@ ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, co if(slot != Source->Send[values[1]].Slot && IsPlayingOrPaused(Source)) { /* Add refcount on the new slot, and release the previous slot */ - if(slot) IncrementRef(&slot->ref); + if(slot) IncrementRef(slot->ref); if(Source->Send[values[1]].Slot) - DecrementRef(&Source->Send[values[1]].Slot->ref); + DecrementRef(Source->Send[values[1]].Slot->ref); Source->Send[values[1]].Slot = slot; /* We must force an update if the auxiliary slot changed on an @@ -1489,9 +1489,9 @@ ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, co } else { - if(slot) IncrementRef(&slot->ref); + if(slot) IncrementRef(slot->ref); if(Source->Send[values[1]].Slot) - DecrementRef(&Source->Send[values[1]].Slot->ref); + DecrementRef(Source->Send[values[1]].Slot->ref); Source->Send[values[1]].Slot = slot; UpdateSourceProps(Source, Context); } @@ -3249,7 +3249,7 @@ START_API_FUNC BufferList->mBuffers[0] = buffer; if(!buffer) continue; - IncrementRef(&buffer->ref); + IncrementRef(buffer->ref); if(buffer->MappedAccess != 0 && !(buffer->MappedAccess&AL_MAP_PERSISTENT_BIT_SOFT)) { @@ -3274,7 +3274,7 @@ START_API_FUNC ALbufferlistitem *next = BufferListStart->mNext.load(std::memory_order_relaxed); std::for_each(BufferListStart->begin(), BufferListStart->end(), [](ALbuffer *buffer) -> void - { if(buffer) DecrementRef(&buffer->ref); }); + { if(buffer) DecrementRef(buffer->ref); }); al_free(BufferListStart); BufferListStart = next; } @@ -3350,7 +3350,7 @@ START_API_FUNC BufferList->mBuffers[BufferList->mNumBuffers++] = buffer; if(!buffer) continue; - IncrementRef(&buffer->ref); + IncrementRef(buffer->ref); BufferList->mMaxSamples = maxu(BufferList->mMaxSamples, buffer->SampleLen); @@ -3377,7 +3377,7 @@ START_API_FUNC ALbufferlistitem *next{BufferListStart->mNext.load(std::memory_order_relaxed)}; std::for_each(BufferListStart->begin(), BufferListStart->end(), [](ALbuffer *buffer) -> void - { if(buffer) DecrementRef(&buffer->ref); }); + { if(buffer) DecrementRef(buffer->ref); }); al_free(BufferListStart); BufferListStart = next; } @@ -3460,7 +3460,7 @@ START_API_FUNC else { *(buffers++) = buffer->id; - DecrementRef(&buffer->ref); + DecrementRef(buffer->ref); } } if(i < head->mNumBuffers) @@ -3574,7 +3574,7 @@ ALsource::~ALsource() ALbufferlistitem *next{BufferList->mNext.load(std::memory_order_relaxed)}; std::for_each(BufferList->begin(), BufferList->end(), [](ALbuffer *buffer) -> void - { if(buffer) DecrementRef(&buffer->ref); }); + { if(buffer) DecrementRef(buffer->ref); }); al_free(BufferList); BufferList = next; } @@ -3584,7 +3584,7 @@ ALsource::~ALsource() [](ALsource::SendData &send) -> void { if(send.Slot) - DecrementRef(&send.Slot->ref); + DecrementRef(send.Slot->ref); send.Slot = nullptr; } ); diff --git a/alc/alc.cpp b/alc/alc.cpp index 240aca6d..73723f26 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -79,6 +79,7 @@ #include "fpu_modes.h" #include "hrtf.h" #include "inprogext.h" +#include "intrusive_ptr.h" #include "logging.h" #include "mastering.h" #include "opthelpers.h" @@ -832,9 +833,9 @@ std::atomic LastNullDeviceError{ALC_NO_ERROR}; /* Thread-local current context */ void ReleaseThreadCtx(ALCcontext *context) { - auto ref = DecrementRef(&context->mRef); - TRACEREF("ALCcontext %p decreasing refcount to %u\n", context, ref); - ERR("Context %p current for thread being destroyed, possible leak!\n", context); + const bool result{context->releaseIfNoDelete()}; + ERR("Context %p current for thread being destroyed%s!\n", context, + result ? "" : ", leak detected"); } std::atomic ThreadCtxProc{ReleaseThreadCtx}; @@ -907,19 +908,6 @@ constexpr ALCint alcEFXMinorVersion = 0; al::FlexArray EmptyContextArray{0u}; -void ALCdevice_IncRef(ALCdevice *device) -{ - auto ref = IncrementRef(&device->ref); - TRACEREF("ALCdevice %p increasing refcount to %u\n", device, ref); -} - -void ALCdevice_DecRef(ALCdevice *device) -{ - auto ref = DecrementRef(&device->ref); - TRACEREF("ALCdevice %p decreasing refcount to %u\n", device, ref); - if(UNLIKELY(ref == 0)) delete device; -} - /* Simple RAII device reference. Takes the reference of the provided ALCdevice, * and decrements it when leaving scope. Movable (transfer reference) but not * copyable (no new references). @@ -930,7 +918,7 @@ class DeviceRef { void reset() noexcept { if(mDev) - ALCdevice_DecRef(mDev); + mDev->release(); mDev = nullptr; } @@ -1658,10 +1646,10 @@ static std::unique_ptr CreateDeviceLimiter(const ALCdevice *device, */ static inline void UpdateClockBase(ALCdevice *device) { - IncrementRef(&device->MixCount); + IncrementRef(device->MixCount); device->ClockBase += nanoseconds{seconds{device->SamplesDone}} / device->Frequency; device->SamplesDone = 0; - IncrementRef(&device->MixCount); + IncrementRef(device->MixCount); } /* UpdateDeviceParams @@ -2205,7 +2193,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) for(s = device->NumAuxSends;s < old_sends;s++) { if(source->Send[s].Slot) - DecrementRef(&source->Send[s].Slot->ref); + DecrementRef(source->Send[s].Slot->ref); source->Send[s].Slot = nullptr; } source->Send.resize(device->NumAuxSends); @@ -2360,7 +2348,7 @@ static DeviceRef VerifyDevice(ALCdevice *device) auto iter = std::lower_bound(DeviceList.cbegin(), DeviceList.cend(), device); if(iter != DeviceList.cend() && *iter == device) { - ALCdevice_IncRef(iter->get()); + (*iter)->add_ref(); return DeviceRef{iter->get()}; } return DeviceRef{}; @@ -2459,7 +2447,7 @@ ALCcontext::~ALCcontext() while(eprops) { ALeffectslotProps *next{eprops->next.load(std::memory_order_relaxed)}; - if(eprops->State) eprops->State->DecRef(); + if(eprops->State) eprops->State->release(); al_free(eprops); eprops = next; ++count; @@ -2528,7 +2516,7 @@ ALCcontext::~ALCcontext() mAsyncEvents->readAdvance(count); } - ALCdevice_DecRef(mDevice); + mDevice->release(); } /* ReleaseContext @@ -2543,12 +2531,12 @@ static bool ReleaseContext(ALCcontext *context, ALCdevice *device) { WARN("%p released while current on thread\n", context); LocalContext.set(nullptr); - context->decRef(); + context->release(); } ALCcontext *origctx{context}; if(GlobalContext.compare_exchange_strong(origctx, nullptr)) - context->decRef(); + context->release(); bool ret{}; { @@ -2594,18 +2582,6 @@ static bool ReleaseContext(ALCcontext *context, ALCdevice *device) return ret; } -static void ALCcontext_IncRef(ALCcontext *context) -{ - auto ref = IncrementRef(&context->mRef); - TRACEREF("ALCcontext %p increasing refcount to %u\n", context, ref); -} - -void ALCcontext::decRef() noexcept -{ - auto ref = DecrementRef(&mRef); - TRACEREF("ALCcontext %p decreasing refcount to %u\n", this, ref); - if(UNLIKELY(ref == 0)) delete this; -} /* VerifyContext * @@ -2617,7 +2593,7 @@ static ContextRef VerifyContext(ALCcontext *context) auto iter = std::lower_bound(ContextList.cbegin(), ContextList.cend(), context); if(iter != ContextList.cend() && *iter == context) { - ALCcontext_IncRef(iter->get()); + (*iter)->add_ref(); return ContextRef{iter->get()}; } return ContextRef{}; @@ -2632,12 +2608,12 @@ ContextRef GetContextRef(void) { ALCcontext *context{LocalContext.get()}; if(context) - ALCcontext_IncRef(context); + context->add_ref(); else { std::lock_guard _{ListLock}; context = GlobalContext.load(std::memory_order_acquire); - if(context) ALCcontext_IncRef(context); + if(context) context->add_ref(); } return ContextRef{context}; } @@ -3278,11 +3254,11 @@ START_API_FUNC ALuint samplecount; ALuint refcount; do { - while(((refcount=ReadRef(&dev->MixCount))&1) != 0) + while(((refcount=ReadRef(dev->MixCount))&1) != 0) std::this_thread::yield(); basecount = dev->ClockBase; samplecount = dev->SamplesDone; - } while(refcount != ReadRef(&dev->MixCount)); + } while(refcount != ReadRef(dev->MixCount)); basecount += nanoseconds{seconds{samplecount}} / dev->Frequency; *values = basecount.count(); } @@ -3426,7 +3402,7 @@ START_API_FUNC dev->LastError.store(ALC_NO_ERROR); ContextRef context{new ALCcontext{dev.get()}}; - ALCdevice_IncRef(context->mDevice); + dev->add_ref(); ALCenum err{UpdateDeviceParams(dev.get(), attrList)}; if(err != ALC_NO_ERROR) @@ -3502,7 +3478,7 @@ START_API_FUNC { std::lock_guard _{ListLock}; auto iter = std::lower_bound(ContextList.cbegin(), ContextList.cend(), context.get()); - ALCcontext_IncRef(context.get()); + context->add_ref(); ContextList.insert(iter, ContextRef{context.get()}); } @@ -3850,7 +3826,7 @@ START_API_FUNC { std::lock_guard _{ListLock}; auto iter = std::lower_bound(DeviceList.cbegin(), DeviceList.cend(), device.get()); - ALCdevice_IncRef(device.get()); + device->add_ref(); DeviceList.insert(iter, DeviceRef{device.get()}); } @@ -3976,7 +3952,7 @@ START_API_FUNC { std::lock_guard _{ListLock}; auto iter = std::lower_bound(DeviceList.cbegin(), DeviceList.cend(), device.get()); - ALCdevice_IncRef(device.get()); + device->add_ref(); DeviceList.insert(iter, DeviceRef{device.get()}); } @@ -4145,7 +4121,7 @@ START_API_FUNC { std::lock_guard _{ListLock}; auto iter = std::lower_bound(DeviceList.cbegin(), DeviceList.cend(), device.get()); - ALCdevice_IncRef(device.get()); + device->add_ref(); DeviceList.insert(iter, DeviceRef{device.get()}); } diff --git a/alc/alcmain.h b/alc/alcmain.h index f69dc755..5b4e4a2b 100644 --- a/alc/alcmain.h +++ b/alc/alcmain.h @@ -24,6 +24,7 @@ #include "atomic.h" #include "hrtf.h" #include "inprogext.h" +#include "intrusive_ptr.h" #include "vector.h" class BFormatDec; @@ -310,9 +311,7 @@ enum { DeviceFlagsCount }; -struct ALCdevice { - RefCount ref{1u}; - +struct ALCdevice : public al::intrusive_ref { std::atomic Connected{true}; const DeviceType Type{}; diff --git a/alc/alcontext.h b/alc/alcontext.h index 43b9c08f..53da10dc 100644 --- a/alc/alcontext.h +++ b/alc/alcontext.h @@ -18,6 +18,7 @@ #include "alu.h" #include "atomic.h" #include "inprogext.h" +#include "intrusive_ptr.h" #include "logging.h" #include "threads.h" #include "vector.h" @@ -84,9 +85,7 @@ struct EffectSlotSubList { { std::swap(FreeMask, rhs.FreeMask); std::swap(EffectSlots, rhs.EffectSlots); return *this; } }; -struct ALCcontext { - RefCount mRef{1u}; - +struct ALCcontext : public al::intrusive_ref { al::vector mSourceList; ALuint mNumSources{0}; std::mutex mSourceLock; @@ -156,8 +155,6 @@ struct ALCcontext { ALCcontext& operator=(const ALCcontext&) = delete; ~ALCcontext(); - void decRef() noexcept; - void allocVoices(size_t num_voices); /** @@ -194,7 +191,7 @@ class ContextRef { void reset() noexcept { if(mCtx) - mCtx->decRef(); + mCtx->release(); mCtx = nullptr; } diff --git a/alc/alu.cpp b/alc/alu.cpp index 2469d08d..8d627b97 100644 --- a/alc/alu.cpp +++ b/alc/alu.cpp @@ -373,20 +373,10 @@ bool CalcEffectSlotParams(ALeffectslot *slot, ALCcontext *context, bool force) EffectState *oldstate{slot->Params.mEffectState}; slot->Params.mEffectState = state; - /* Manually decrement the old effect state's refcount if it's greater - * than 1. We need to be a bit clever here to avoid the refcount - * reaching 0 since it can't be deleted in the mixer. + /* Only decrement the old state if it won't get deleted, since we can't + * be deleting/freeing anything in the mixer. */ - ALuint oldval{oldstate->mRef.load(std::memory_order_acquire)}; - while(oldval > 1 && !oldstate->mRef.compare_exchange_weak(oldval, oldval-1, - std::memory_order_acq_rel, std::memory_order_acquire)) - { - /* oldval was updated with the current value on failure, so just - * try again. - */ - } - - if(oldval < 2) + if(!oldstate->releaseIfNoDelete()) { /* Otherwise, if it would be deleted, send it off with a release * event. @@ -1355,7 +1345,7 @@ void CalcSourceParams(ALvoice *voice, ALCcontext *context, bool force) void ProcessParamUpdates(ALCcontext *ctx, const ALeffectslotArray *slots) { - IncrementRef(&ctx->mUpdateCount); + IncrementRef(ctx->mUpdateCount); if(LIKELY(!ctx->mHoldUpdates.load(std::memory_order_acquire))) { bool cforce{CalcContextParams(ctx)}; @@ -1374,7 +1364,7 @@ void ProcessParamUpdates(ALCcontext *ctx, const ALeffectslotArray *slots) } ); } - IncrementRef(&ctx->mUpdateCount); + IncrementRef(ctx->mUpdateCount); } void ProcessContext(ALCcontext *ctx, const ALsizei SamplesToDo) @@ -1676,7 +1666,7 @@ void aluMixData(ALCdevice *device, ALvoid *OutBuffer, ALsizei NumSamples) ); /* Increment the mix count at the start (lsb should now be 1). */ - IncrementRef(&device->MixCount); + IncrementRef(device->MixCount); /* For each context on this device, process and mix its sources and * effects. @@ -1694,7 +1684,7 @@ void aluMixData(ALCdevice *device, ALvoid *OutBuffer, ALsizei NumSamples) device->SamplesDone %= device->Frequency; /* Increment the mix count at the end (lsb should now be 0). */ - IncrementRef(&device->MixCount); + IncrementRef(device->MixCount); /* Apply any needed post-process for finalizing the Dry mix to the * RealOut (Ambisonic decode, UHJ encode, etc). diff --git a/alc/backends/base.cpp b/alc/backends/base.cpp index 78b9196e..095990b7 100644 --- a/alc/backends/base.cpp +++ b/alc/backends/base.cpp @@ -43,11 +43,11 @@ ClockLatency BackendBase::getClockLatency() ALuint refcount; do { - while(((refcount=mDevice->MixCount.load(std::memory_order_acquire))&1)) + while(((refcount=ReadRef(mDevice->MixCount))&1) != 0) std::this_thread::yield(); ret.ClockTime = GetDeviceClockTime(mDevice); std::atomic_thread_fence(std::memory_order_acquire); - } while(refcount != mDevice->MixCount.load(std::memory_order_relaxed)); + } while(refcount != ReadRef(mDevice->MixCount)); /* NOTE: The device will generally have about all but one periods filled at * any given time during playback. Without a more accurate measurement from diff --git a/alc/effects/base.h b/alc/effects/base.h index 4f48de22..89a9e8e4 100644 --- a/alc/effects/base.h +++ b/alc/effects/base.h @@ -5,7 +5,7 @@ #include "almalloc.h" #include "alspan.h" #include "atomic.h" - +#include "intrusive_ptr.h" struct ALeffectslot; @@ -149,9 +149,7 @@ struct EffectTarget { RealMixParams *RealOut; }; -struct EffectState { - RefCount mRef{1u}; - +struct EffectState : public al::intrusive_ref { al::span mOutTarget; @@ -160,9 +158,6 @@ struct EffectState { virtual ALboolean deviceUpdate(const ALCdevice *device) = 0; virtual void update(const ALCcontext *context, const ALeffectslot *slot, const EffectProps *props, const EffectTarget target) = 0; virtual void process(const ALsizei samplesToDo, const FloatBufferLine *RESTRICT samplesIn, const ALsizei numInput, const al::span samplesOut) = 0; - - void IncRef() noexcept; - void DecRef() noexcept; }; diff --git a/alc/hrtf.cpp b/alc/hrtf.cpp index 124707c5..a8b56019 100644 --- a/alc/hrtf.cpp +++ b/alc/hrtf.cpp @@ -484,7 +484,7 @@ std::unique_ptr CreateHrtfStore(ALuint rate, ALsizei irSize, const AL ERR("Out of memory allocating storage for %s.\n", filename); else { - InitRef(&Hrtf->ref, 1u); + InitRef(Hrtf->ref, 1u); Hrtf->sampleRate = rate; Hrtf->irSize = irSize; Hrtf->fdCount = fdCount; @@ -1373,13 +1373,13 @@ HrtfEntry *GetLoadedHrtf(HrtfHandle *handle) void HrtfEntry::IncRef() { - auto ref = IncrementRef(&this->ref); + auto ref = IncrementRef(this->ref); TRACEREF("HrtfEntry %p increasing refcount to %u\n", this, ref); } void HrtfEntry::DecRef() { - auto ref = DecrementRef(&this->ref); + auto ref = DecrementRef(this->ref); TRACEREF("HrtfEntry %p decreasing refcount to %u\n", this, ref); if(ref == 0) { @@ -1389,7 +1389,7 @@ void HrtfEntry::DecRef() auto delete_unused = [](HrtfHandlePtr &handle) -> void { HrtfEntry *entry{handle->entry.get()}; - if(entry && ReadRef(&entry->ref) == 0) + if(entry && ReadRef(entry->ref) == 0) { TRACE("Unloading unused HRTF %s\n", handle->filename.data()); handle->entry = nullptr; diff --git a/common/atomic.h b/common/atomic.h index e34f35bb..5e9b04c6 100644 --- a/common/atomic.h +++ b/common/atomic.h @@ -6,14 +6,14 @@ using RefCount = std::atomic; -inline void InitRef(RefCount *ptr, unsigned int value) -{ ptr->store(value, std::memory_order_relaxed); } -inline unsigned int ReadRef(RefCount *ptr) -{ return ptr->load(std::memory_order_acquire); } -inline unsigned int IncrementRef(RefCount *ptr) -{ return ptr->fetch_add(1u, std::memory_order_acq_rel)+1u; } -inline unsigned int DecrementRef(RefCount *ptr) -{ return ptr->fetch_sub(1u, std::memory_order_acq_rel)-1u; } +inline void InitRef(RefCount &ref, unsigned int value) +{ ref.store(value, std::memory_order_relaxed); } +inline unsigned int ReadRef(RefCount &ref) +{ return ref.load(std::memory_order_acquire); } +inline unsigned int IncrementRef(RefCount &ref) +{ return ref.fetch_add(1u, std::memory_order_acq_rel)+1u; } +inline unsigned int DecrementRef(RefCount &ref) +{ return ref.fetch_sub(1u, std::memory_order_acq_rel)-1u; } /* WARNING: A livelock is theoretically possible if another thread keeps diff --git a/common/intrusive_ptr.h b/common/intrusive_ptr.h new file mode 100644 index 00000000..8f34aeac --- /dev/null +++ b/common/intrusive_ptr.h @@ -0,0 +1,48 @@ +#ifndef INTRUSIVE_PTR_H +#define INTRUSIVE_PTR_H + +#include "atomic.h" +#include "opthelpers.h" + + +namespace al { + +template +class intrusive_ref { + RefCount mRef{1u}; + +public: + unsigned int add_ref() noexcept { return IncrementRef(mRef); } + unsigned int release() noexcept + { + auto ref = DecrementRef(mRef); + if(UNLIKELY(ref == 0)) + delete static_cast(this); + return ref; + } + + /** + * Release only if doing so would not bring the object to 0 references and + * delete it. Returns false if the object could not be released. + * + * NOTE: The caller is responsible for handling a failed release, as it + * means the object has no other references and needs to be be deleted + * somehow. + */ + bool releaseIfNoDelete() noexcept + { + auto val = mRef.load(std::memory_order_acquire); + while(val > 1 && !mRef.compare_exchange_strong(val, val-1, std::memory_order_acq_rel)) + { + /* val was updated with the current value on failure, so just try + * again. + */ + } + + return val >= 2; + } +}; + +} // namespace al + +#endif /* INTRUSIVE_PTR_H */ -- cgit v1.2.3 From 33bcced82a1e97811d4212195b6e6ca9cf2242b1 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 1 Aug 2019 19:44:09 -0700 Subject: Use a smart pointer for holding the context's device --- al/auxeffectslot.cpp | 10 +++++----- al/buffer.cpp | 40 ++++++++++++++++++++-------------------- al/effect.cpp | 22 +++++++++++----------- al/event.cpp | 3 +-- al/filter.cpp | 22 +++++++++++----------- al/source.cpp | 32 ++++++++++++++++---------------- alc/alc.cpp | 13 +++++-------- alc/alcontext.h | 4 ++-- alc/alu.cpp | 6 +++--- alc/effects/autowah.cpp | 2 +- alc/effects/chorus.cpp | 2 +- alc/effects/distortion.cpp | 2 +- alc/effects/echo.cpp | 2 +- alc/effects/equalizer.cpp | 2 +- alc/effects/fshifter.cpp | 2 +- alc/effects/modulator.cpp | 2 +- alc/effects/reverb.cpp | 2 +- alc/effects/vmorpher.cpp | 2 +- alc/mixvoice.cpp | 2 +- 19 files changed, 84 insertions(+), 88 deletions(-) (limited to 'al/source.cpp') diff --git a/al/auxeffectslot.cpp b/al/auxeffectslot.cpp index b4e93858..912765fc 100644 --- a/al/auxeffectslot.cpp +++ b/al/auxeffectslot.cpp @@ -114,7 +114,7 @@ void AddActiveEffectSlots(const ALuint *slotids, ALsizei count, ALCcontext *cont } curarray = context->mActiveAuxSlots.exchange(newarray, std::memory_order_acq_rel); - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; while((device->MixCount.load(std::memory_order_acquire)&1)) std::this_thread::yield(); delete curarray; @@ -150,7 +150,7 @@ void RemoveActiveEffectSlots(const ALuint *slotids, ALsizei count, ALCcontext *c } curarray = context->mActiveAuxSlots.exchange(newarray, std::memory_order_acq_rel); - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; while((device->MixCount.load(std::memory_order_acquire)&1)) std::this_thread::yield(); delete curarray; @@ -159,7 +159,7 @@ void RemoveActiveEffectSlots(const ALuint *slotids, ALsizei count, ALCcontext *c ALeffectslot *AllocEffectSlot(ALCcontext *context) { - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{context->mEffectSlotLock}; if(context->mNumEffectSlots >= device->AuxiliaryEffectSlotMax) { @@ -376,7 +376,7 @@ START_API_FUNC switch(param) { case AL_EFFECTSLOT_EFFECT: - device = context->mDevice; + device = context->mDevice.get(); { std::lock_guard ___{device->EffectLock}; ALeffect *effect{value ? LookupEffect(device, value) : nullptr}; @@ -644,7 +644,7 @@ ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect if(!State) return AL_OUT_OF_MEMORY; FPUCtl mixer_mode{}; - ALCdevice *Device{Context->mDevice}; + ALCdevice *Device{Context->mDevice.get()}; std::unique_lock statelock{Device->StateLock}; State->mOutTarget = Device->Dry.Buffer; if(State->deviceUpdate(Device) == AL_FALSE) diff --git a/al/buffer.cpp b/al/buffer.cpp index 173c76bd..a068399c 100644 --- a/al/buffer.cpp +++ b/al/buffer.cpp @@ -246,7 +246,7 @@ constexpr ALbitfieldSOFT INVALID_MAP_FLAGS{~unsigned(AL_MAP_READ_BIT_SOFT | AL_M ALbuffer *AllocBuffer(ALCcontext *context) { - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; auto sublist = std::find_if(device->BufferList.begin(), device->BufferList.end(), [](const BufferSubList &entry) noexcept -> bool @@ -656,7 +656,7 @@ START_API_FUNC if(UNLIKELY(n == 0)) return; - ALCdevice *device = context->mDevice; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; /* First try to find any buffers that are invalid or in-use. */ @@ -699,7 +699,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(LIKELY(context)) { - ALCdevice *device = context->mDevice; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; if(!buffer || LookupBuffer(device, buffer)) return AL_TRUE; @@ -720,7 +720,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->mDevice; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); @@ -754,7 +754,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return nullptr; - ALCdevice *device = context->mDevice; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); @@ -806,7 +806,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->mDevice; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); @@ -829,7 +829,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->mDevice; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); @@ -861,7 +861,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->mDevice; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); @@ -989,7 +989,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->mDevice; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; if(UNLIKELY(LookupBuffer(device, buffer) == nullptr)) @@ -1009,7 +1009,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->mDevice; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; if(UNLIKELY(LookupBuffer(device, buffer) == nullptr)) @@ -1028,7 +1028,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->mDevice; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; if(UNLIKELY(LookupBuffer(device, buffer) == nullptr)) @@ -1050,7 +1050,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->mDevice; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); @@ -1085,7 +1085,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->mDevice; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; if(UNLIKELY(LookupBuffer(device, buffer) == nullptr)) @@ -1115,7 +1115,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->mDevice; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); @@ -1153,7 +1153,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->mDevice; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); @@ -1175,7 +1175,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->mDevice; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; if(UNLIKELY(LookupBuffer(device, buffer) == nullptr)) @@ -1203,7 +1203,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->mDevice; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; if(UNLIKELY(LookupBuffer(device, buffer) == nullptr)) @@ -1225,7 +1225,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->mDevice; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); if(UNLIKELY(!albuf)) @@ -1270,7 +1270,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->mDevice; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; if(UNLIKELY(LookupBuffer(device, buffer) == nullptr)) context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); @@ -1305,7 +1305,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device = context->mDevice; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); if(UNLIKELY(!albuf)) diff --git a/al/effect.cpp b/al/effect.cpp index 2d72916e..15200a88 100644 --- a/al/effect.cpp +++ b/al/effect.cpp @@ -138,7 +138,7 @@ void InitEffectParams(ALeffect *effect, ALenum type) ALeffect *AllocEffect(ALCcontext *context) { - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->EffectLock}; auto sublist = std::find_if(device->EffectList.begin(), device->EffectList.end(), [](const EffectSubList &entry) noexcept -> bool @@ -269,7 +269,7 @@ START_API_FUNC if(UNLIKELY(n == 0)) return; - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->EffectLock}; /* First try to find any effects that are invalid. */ @@ -307,7 +307,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(LIKELY(context)) { - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->EffectLock}; if(!effect || LookupEffect(device, effect)) return AL_TRUE; @@ -322,7 +322,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->EffectLock}; ALeffect *aleffect{LookupEffect(device, effect)}; @@ -372,7 +372,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->EffectLock}; ALeffect *aleffect{LookupEffect(device, effect)}; @@ -392,7 +392,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->EffectLock}; ALeffect *aleffect{LookupEffect(device, effect)}; @@ -412,7 +412,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->EffectLock}; ALeffect *aleffect{LookupEffect(device, effect)}; @@ -432,7 +432,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->EffectLock}; const ALeffect *aleffect{LookupEffect(device, effect)}; @@ -464,7 +464,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->EffectLock}; const ALeffect *aleffect{LookupEffect(device, effect)}; @@ -484,7 +484,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->EffectLock}; const ALeffect *aleffect{LookupEffect(device, effect)}; @@ -504,7 +504,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->EffectLock}; const ALeffect *aleffect{LookupEffect(device, effect)}; diff --git a/al/event.cpp b/al/event.cpp index 75827b59..06a2e008 100644 --- a/al/event.cpp +++ b/al/event.cpp @@ -120,7 +120,6 @@ void StartEventThrd(ALCcontext *ctx) void StopEventThrd(ALCcontext *ctx) { - static constexpr AsyncEvent kill_evt{EventType_KillThread}; RingBuffer *ring{ctx->mAsyncEvents.get()}; auto evt_data = ring->getWriteVector().first; if(evt_data.len == 0) @@ -130,7 +129,7 @@ void StopEventThrd(ALCcontext *ctx) evt_data = ring->getWriteVector().first; } while(evt_data.len == 0); } - new (evt_data.buf) AsyncEvent{kill_evt}; + new (evt_data.buf) AsyncEvent{EventType_KillThread}; ring->writeAdvance(1); ctx->mEventSem.post(); diff --git a/al/filter.cpp b/al/filter.cpp index 5009daae..b52267f1 100644 --- a/al/filter.cpp +++ b/al/filter.cpp @@ -278,7 +278,7 @@ void InitFilterParams(ALfilter *filter, ALenum type) ALfilter *AllocFilter(ALCcontext *context) { - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->FilterLock}; auto sublist = std::find_if(device->FilterList.begin(), device->FilterList.end(), [](const FilterSubList &entry) noexcept -> bool @@ -410,7 +410,7 @@ START_API_FUNC if(UNLIKELY(n == 0)) return; - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->FilterLock}; /* First try to find any filters that are invalid. */ @@ -448,7 +448,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(LIKELY(context)) { - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->FilterLock}; if(!filter || LookupFilter(device, filter)) return AL_TRUE; @@ -464,7 +464,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->FilterLock}; ALfilter *alfilt{LookupFilter(device, filter)}; @@ -502,7 +502,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->FilterLock}; ALfilter *alfilt{LookupFilter(device, filter)}; @@ -522,7 +522,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->FilterLock}; ALfilter *alfilt{LookupFilter(device, filter)}; @@ -542,7 +542,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->FilterLock}; ALfilter *alfilt{LookupFilter(device, filter)}; @@ -562,7 +562,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->FilterLock}; ALfilter *alfilt{LookupFilter(device, filter)}; @@ -594,7 +594,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->FilterLock}; ALfilter *alfilt{LookupFilter(device, filter)}; @@ -614,7 +614,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->FilterLock}; ALfilter *alfilt{LookupFilter(device, filter)}; @@ -634,7 +634,7 @@ START_API_FUNC ContextRef context{GetContextRef()}; if(UNLIKELY(!context)) return; - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->FilterLock}; ALfilter *alfilt{LookupFilter(device, filter)}; diff --git a/al/source.cpp b/al/source.cpp index 1e0940de..5ba36524 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -175,7 +175,7 @@ void UpdateSourceProps(const ALsource *source, ALvoice *voice, ALCcontext *conte */ int64_t GetSourceSampleOffset(ALsource *Source, ALCcontext *context, std::chrono::nanoseconds *clocktime) { - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; const ALbufferlistitem *Current; uint64_t readPos; ALuint refcount; @@ -221,7 +221,7 @@ int64_t GetSourceSampleOffset(ALsource *Source, ALCcontext *context, std::chrono */ ALdouble GetSourceSecOffset(ALsource *Source, ALCcontext *context, std::chrono::nanoseconds *clocktime) { - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; const ALbufferlistitem *Current; uint64_t readPos; ALuint refcount; @@ -281,7 +281,7 @@ ALdouble GetSourceSecOffset(ALsource *Source, ALCcontext *context, std::chrono:: */ ALdouble GetSourceOffset(ALsource *Source, ALenum name, ALCcontext *context) { - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; const ALbufferlistitem *Current; ALuint readPos; ALsizei readPosFrac; @@ -483,7 +483,7 @@ ALboolean ApplyOffset(ALsource *Source, ALvoice *voice) ALsource *AllocSource(ALCcontext *context) { - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; std::lock_guard _{context->mSourceLock}; if(context->mNumSources >= device->SourcesMax) { @@ -545,7 +545,7 @@ void FreeSource(ALCcontext *context, ALsource *source) ALsizei lidx = id >> 6; ALsizei slidx = id & 0x3f; - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; BackendUniqueLock backlock{*device->Backend}; if(ALvoice *voice{GetSourceVoice(source, context)}) { @@ -1126,7 +1126,7 @@ ALboolean SetSourcefv(ALsource *Source, ALCcontext *Context, SourceProp prop, co if(IsPlayingOrPaused(Source)) { - ALCdevice *device{Context->mDevice}; + ALCdevice *device{Context->mDevice.get()}; BackendLockGuard _{*device->Backend}; /* Double-check that the source is still playing while we have * the lock. @@ -1230,7 +1230,7 @@ ALboolean SetSourcefv(ALsource *Source, ALCcontext *Context, SourceProp prop, co ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const ALint *values) { - ALCdevice *device{Context->mDevice}; + ALCdevice *device{Context->mDevice.get()}; ALbuffer *buffer{nullptr}; ALfilter *filter{nullptr}; ALeffectslot *slot{nullptr}; @@ -1346,7 +1346,7 @@ ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, co if(IsPlayingOrPaused(Source)) { - ALCdevice *device{Context->mDevice}; + ALCdevice *device{Context->mDevice.get()}; BackendLockGuard _{*device->Backend}; if(ALvoice *voice{GetSourceVoice(Source, Context)}) { @@ -1662,7 +1662,7 @@ ALboolean GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, ALboolean GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp prop, ALdouble *values) { - ALCdevice *device{Context->mDevice}; + ALCdevice *device{Context->mDevice.get()}; ClockLatency clocktime; std::chrono::nanoseconds srcclock; ALint ivals[3]; @@ -1995,7 +1995,7 @@ ALboolean GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, AL ALboolean GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, ALint64SOFT *values) { - ALCdevice *device = Context->mDevice; + ALCdevice *device = Context->mDevice.get(); ClockLatency clocktime; std::chrono::nanoseconds srcclock; ALdouble dvals[6]; @@ -2780,7 +2780,7 @@ START_API_FUNC SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid source ID %u", sources[i]); } - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; BackendLockGuard __{*device->Backend}; /* If the device is disconnected, go right to stopped. */ if(UNLIKELY(!device->Connected.load(std::memory_order_acquire))) @@ -3041,7 +3041,7 @@ START_API_FUNC SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid source ID %u", sources[i]); } - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; BackendLockGuard __{*device->Backend}; auto pause_source = [&context](ALsource *source) -> void { @@ -3096,7 +3096,7 @@ START_API_FUNC SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid source ID %u", sources[i]); } - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; BackendLockGuard __{*device->Backend}; auto stop_source = [&context](ALsource *source) -> void { @@ -3158,7 +3158,7 @@ START_API_FUNC SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid source ID %u", sources[i]); } - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; BackendLockGuard __{*device->Backend}; auto rewind_source = [&context](ALsource *source) -> void { @@ -3207,7 +3207,7 @@ START_API_FUNC SETERR_RETURN(context, AL_INVALID_OPERATION,, "Queueing onto static source %u", src); /* Check for a valid Buffer, for its frequency and format */ - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; ALbuffer *BufferFmt{nullptr}; ALbufferlistitem *BufferList{source->queue}; while(BufferList) @@ -3319,7 +3319,7 @@ START_API_FUNC SETERR_RETURN(context, AL_INVALID_OPERATION,, "Queueing onto static source %u", src); /* Check for a valid Buffer, for its frequency and format */ - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; ALbuffer *BufferFmt{nullptr}; ALbufferlistitem *BufferList{source->queue}; while(BufferList) diff --git a/alc/alc.cpp b/alc/alc.cpp index 6837d107..20776fba 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -2304,7 +2304,7 @@ static DeviceRef VerifyDevice(ALCdevice *device) } -ALCcontext::ALCcontext(ALCdevice *device) : mDevice{device} +ALCcontext::ALCcontext(al::intrusive_ptr device) : mDevice{std::move(device)} { mPropsClean.test_and_set(std::memory_order_relaxed); } @@ -2464,8 +2464,6 @@ ALCcontext::~ALCcontext() TRACE("Destructed %zu orphaned event%s\n", count, (count==1)?"":"s"); mAsyncEvents->readAdvance(count); } - - mDevice->release(); } /* ReleaseContext @@ -3346,9 +3344,6 @@ START_API_FUNC dev->LastError.store(ALC_NO_ERROR); - ContextRef context{new ALCcontext{dev.get()}}; - dev->add_ref(); - ALCenum err{UpdateDeviceParams(dev.get(), attrList)}; if(err != ALC_NO_ERROR) { @@ -3357,6 +3352,8 @@ START_API_FUNC aluHandleDisconnect(dev.get(), "Device update failure"); return nullptr; } + + ContextRef context{new ALCcontext{dev}}; context->allocVoices(256); if(DefaultEffect.type != AL_EFFECT_NULL && dev->Type == Playback) @@ -3461,7 +3458,7 @@ START_API_FUNC ContextRef ctx{std::move(*iter)}; ContextList.erase(iter); - ALCdevice *Device{ctx->mDevice}; + ALCdevice *Device{ctx->mDevice.get()}; std::lock_guard _{Device->StateLock}; if(!ReleaseContext(ctx.get(), Device) && Device->Flags.get()) @@ -3572,7 +3569,7 @@ START_API_FUNC alcSetError(nullptr, ALC_INVALID_CONTEXT); return nullptr; } - return ctx->mDevice; + return ctx->mDevice.get(); } END_API_FUNC diff --git a/alc/alcontext.h b/alc/alcontext.h index ebb70a79..c4f23dfb 100644 --- a/alc/alcontext.h +++ b/alc/alcontext.h @@ -144,13 +144,13 @@ struct ALCcontext : public al::intrusive_ref { /* Default effect slot */ std::unique_ptr mDefaultSlot; - ALCdevice *const mDevice; + const al::intrusive_ptr mDevice; const ALCchar *mExtensionList{nullptr}; ALlistener mListener{}; - ALCcontext(ALCdevice *device); + ALCcontext(al::intrusive_ptr device); ALCcontext(const ALCcontext&) = delete; ALCcontext& operator=(const ALCcontext&) = delete; ~ALCcontext(); diff --git a/alc/alu.cpp b/alc/alu.cpp index 8d627b97..7d333fcb 100644 --- a/alc/alu.cpp +++ b/alc/alu.cpp @@ -409,7 +409,7 @@ bool CalcEffectSlotParams(ALeffectslot *slot, ALCcontext *context, bool force) output = EffectTarget{&target->Wet, nullptr}; else { - ALCdevice *device{context->mDevice}; + ALCdevice *device{context->mDevice.get()}; output = EffectTarget{&device->Dry, &device->RealOut}; } state->update(context, slot, &slot->Params.mEffectProps, output); @@ -950,7 +950,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat xpos, const ALfloat ypo void CalcNonAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, const ALCcontext *ALContext) { - const ALCdevice *Device{ALContext->mDevice}; + const ALCdevice *Device{ALContext->mDevice.get()}; ALeffectslot *SendSlots[MAX_SENDS]; voice->mDirect.Buffer = Device->Dry.Buffer; @@ -1004,7 +1004,7 @@ void CalcNonAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, cons void CalcAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, const ALCcontext *ALContext) { - const ALCdevice *Device{ALContext->mDevice}; + const ALCdevice *Device{ALContext->mDevice.get()}; const ALsizei NumSends{Device->NumAuxSends}; const ALlistener &Listener = ALContext->mListener; diff --git a/alc/effects/autowah.cpp b/alc/effects/autowah.cpp index 1aac749e..f16c5ba5 100644 --- a/alc/effects/autowah.cpp +++ b/alc/effects/autowah.cpp @@ -106,7 +106,7 @@ ALboolean ALautowahState::deviceUpdate(const ALCdevice*) void ALautowahState::update(const ALCcontext *context, const ALeffectslot *slot, const EffectProps *props, const EffectTarget target) { - const ALCdevice *device{context->mDevice}; + const ALCdevice *device{context->mDevice.get()}; const ALfloat ReleaseTime{clampf(props->Autowah.ReleaseTime, 0.001f, 1.0f)}; diff --git a/alc/effects/chorus.cpp b/alc/effects/chorus.cpp index 31f10c81..5966d3bd 100644 --- a/alc/effects/chorus.cpp +++ b/alc/effects/chorus.cpp @@ -157,7 +157,7 @@ void ChorusState::update(const ALCcontext *Context, const ALeffectslot *Slot, co /* The LFO depth is scaled to be relative to the sample delay. Clamp the * delay and depth to allow enough padding for resampling. */ - const ALCdevice *device{Context->mDevice}; + const ALCdevice *device{Context->mDevice.get()}; const auto frequency = static_cast(device->Frequency); mDelay = maxi(float2int(props->Chorus.Delay*frequency*FRACTIONONE + 0.5f), mindelay); mDepth = minf(props->Chorus.Depth * mDelay, static_cast(mDelay - mindelay)); diff --git a/alc/effects/distortion.cpp b/alc/effects/distortion.cpp index 3fd08229..ec1550f5 100644 --- a/alc/effects/distortion.cpp +++ b/alc/effects/distortion.cpp @@ -63,7 +63,7 @@ ALboolean DistortionState::deviceUpdate(const ALCdevice*) void DistortionState::update(const ALCcontext *context, const ALeffectslot *slot, const EffectProps *props, const EffectTarget target) { - const ALCdevice *device{context->mDevice}; + const ALCdevice *device{context->mDevice.get()}; /* Store waveshaper edge settings. */ const ALfloat edge{ diff --git a/alc/effects/echo.cpp b/alc/effects/echo.cpp index d14db80c..d41c4f67 100644 --- a/alc/effects/echo.cpp +++ b/alc/effects/echo.cpp @@ -93,7 +93,7 @@ ALboolean EchoState::deviceUpdate(const ALCdevice *Device) void EchoState::update(const ALCcontext *context, const ALeffectslot *slot, const EffectProps *props, const EffectTarget target) { - const ALCdevice *device = context->mDevice; + const ALCdevice *device{context->mDevice.get()}; const auto frequency = static_cast(device->Frequency); mTap[0].delay = maxi(float2int(props->Echo.Delay*frequency + 0.5f), 1); diff --git a/alc/effects/equalizer.cpp b/alc/effects/equalizer.cpp index 4b900bcf..a8e81b37 100644 --- a/alc/effects/equalizer.cpp +++ b/alc/effects/equalizer.cpp @@ -111,7 +111,7 @@ ALboolean EqualizerState::deviceUpdate(const ALCdevice*) void EqualizerState::update(const ALCcontext *context, const ALeffectslot *slot, const EffectProps *props, const EffectTarget target) { - const ALCdevice *device = context->mDevice; + const ALCdevice *device{context->mDevice.get()}; auto frequency = static_cast(device->Frequency); ALfloat gain, f0norm; diff --git a/alc/effects/fshifter.cpp b/alc/effects/fshifter.cpp index bca29bba..a6c2c747 100644 --- a/alc/effects/fshifter.cpp +++ b/alc/effects/fshifter.cpp @@ -108,7 +108,7 @@ ALboolean FshifterState::deviceUpdate(const ALCdevice*) void FshifterState::update(const ALCcontext *context, const ALeffectslot *slot, const EffectProps *props, const EffectTarget target) { - const ALCdevice *device{context->mDevice}; + const ALCdevice *device{context->mDevice.get()}; ALfloat step{props->Fshifter.Frequency / static_cast(device->Frequency)}; mPhaseStep = fastf2i(minf(step, 0.5f) * FRACTIONONE); diff --git a/alc/effects/modulator.cpp b/alc/effects/modulator.cpp index d7118285..8a6378cd 100644 --- a/alc/effects/modulator.cpp +++ b/alc/effects/modulator.cpp @@ -109,7 +109,7 @@ ALboolean ModulatorState::deviceUpdate(const ALCdevice*) void ModulatorState::update(const ALCcontext *context, const ALeffectslot *slot, const EffectProps *props, const EffectTarget target) { - const ALCdevice *device{context->mDevice}; + const ALCdevice *device{context->mDevice.get()}; const float step{props->Modulator.Frequency / static_cast(device->Frequency)}; mStep = fastf2i(clampf(step*WAVEFORM_FRACONE, 0.0f, ALfloat{WAVEFORM_FRACONE-1})); diff --git a/alc/effects/reverb.cpp b/alc/effects/reverb.cpp index 6e6844e0..51a57360 100644 --- a/alc/effects/reverb.cpp +++ b/alc/effects/reverb.cpp @@ -905,7 +905,7 @@ void ReverbState::update3DPanning(const ALfloat *ReflectionsPan, const ALfloat * void ReverbState::update(const ALCcontext *Context, const ALeffectslot *Slot, const EffectProps *props, const EffectTarget target) { - const ALCdevice *Device{Context->mDevice}; + const ALCdevice *Device{Context->mDevice.get()}; const ALlistener &Listener = Context->mListener; const auto frequency = static_cast(Device->Frequency); diff --git a/alc/effects/vmorpher.cpp b/alc/effects/vmorpher.cpp index 95016105..ad0f026b 100644 --- a/alc/effects/vmorpher.cpp +++ b/alc/effects/vmorpher.cpp @@ -209,7 +209,7 @@ ALboolean VmorpherState::deviceUpdate(const ALCdevice* /*device*/) void VmorpherState::update(const ALCcontext *context, const ALeffectslot *slot, const EffectProps *props, const EffectTarget target) { - const ALCdevice *device{context->mDevice}; + const ALCdevice *device{context->mDevice.get()}; const ALfloat frequency{static_cast(device->Frequency)}; const ALfloat step{props->Vmorpher.Rate / static_cast(device->Frequency)}; mStep = fastf2i(clampf(step*WAVEFORM_FRACONE, 0.0f, ALfloat{WAVEFORM_FRACONE-1})); diff --git a/alc/mixvoice.cpp b/alc/mixvoice.cpp index e2b2bf51..b1d7500a 100644 --- a/alc/mixvoice.cpp +++ b/alc/mixvoice.cpp @@ -540,7 +540,7 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc ASSUME(SampleSize > 0); ASSUME(increment > 0); - ALCdevice *Device{Context->mDevice}; + ALCdevice *Device{Context->mDevice.get()}; const ALsizei NumSends{Device->NumAuxSends}; const ALsizei IrSize{Device->mHrtf ? Device->mHrtf->irSize : 0}; -- cgit v1.2.3 From 9f223898f2f460d707d8506e28989d2952a767f9 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 2 Aug 2019 12:38:20 -0700 Subject: Use an unsigned voice index --- al/source.cpp | 17 ++++------------- al/source.h | 15 ++++++++------- 2 files changed, 12 insertions(+), 20 deletions(-) (limited to 'al/source.cpp') diff --git a/al/source.cpp b/al/source.cpp index 5ba36524..a021cd1a 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -75,15 +75,15 @@ using namespace std::placeholders; inline ALvoice *GetSourceVoice(ALsource *source, ALCcontext *context) { - ALint idx{source->VoiceIdx}; - if(idx >= 0 && static_cast(idx) < context->mVoiceCount.load(std::memory_order_relaxed)) + ALuint idx{source->VoiceIdx}; + if(idx < context->mVoiceCount.load(std::memory_order_relaxed)) { ALuint sid{source->id}; ALvoice &voice = (*context->mVoices)[idx]; if(voice.mSourceID.load(std::memory_order_acquire) == sid) return &voice; } - source->VoiceIdx = -1; + source->VoiceIdx = INVALID_VOICE_IDX; return nullptr; } @@ -2894,7 +2894,7 @@ START_API_FUNC } ); assert(voice != voices_end); - auto vidx = static_cast(std::distance(context->mVoices->begin(), voice)); + auto vidx = static_cast(std::distance(context->mVoices->begin(), voice)); voice->mPlayState.store(ALvoice::Stopped, std::memory_order_release); source->PropsClean.test_and_set(std::memory_order_acquire); @@ -3554,16 +3554,7 @@ ALsource::ALsource(ALsizei num_sends) send.LFReference = HIGHPASSFREQREF; } - Offset = 0.0; - OffsetType = AL_NONE; - SourceType = AL_UNDETERMINED; - state = AL_INITIAL; - - queue = nullptr; - PropsClean.test_and_set(std::memory_order_relaxed); - - VoiceIdx = -1; } ALsource::~ALsource() diff --git a/al/source.h b/al/source.h index 1aafafab..a5d10cf9 100644 --- a/al/source.h +++ b/al/source.h @@ -20,6 +20,7 @@ struct ALeffectslot; #define DEFAULT_SENDS 2 +#define INVALID_VOICE_IDX static_cast(-1) struct ALbufferlistitem { using element_type = ALbuffer*; @@ -139,27 +140,27 @@ struct ALsource { * Last user-specified offset, and the offset type (bytes, samples, or * seconds). */ - ALdouble Offset; - ALenum OffsetType; + ALdouble Offset{0.0}; + ALenum OffsetType{AL_NONE}; /** Source type (static, streaming, or undetermined) */ - ALint SourceType; + ALint SourceType{AL_UNDETERMINED}; /** Source state (initial, playing, paused, or stopped) */ - ALenum state; + ALenum state{AL_INITIAL}; /** Source Buffer Queue head. */ - ALbufferlistitem *queue; + ALbufferlistitem *queue{nullptr}; std::atomic_flag PropsClean; /* Index into the context's Voices array. Lazily updated, only checked and * reset when looking up the voice. */ - ALint VoiceIdx; + ALuint VoiceIdx{INVALID_VOICE_IDX}; /** Self ID */ - ALuint id; + ALuint id{0}; ALsource(ALsizei num_sends); -- cgit v1.2.3 From 7baa07e3adb91ce52358ebeb6e8aed51855422ba Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 3 Aug 2019 18:57:38 -0700 Subject: Pass spans to the source set-property methods This avoids an extra property check to get the size since the number of values can be checked when accessed. --- al/source.cpp | 431 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 212 insertions(+), 219 deletions(-) (limited to 'al/source.cpp') diff --git a/al/source.cpp b/al/source.cpp index a021cd1a..043ef940 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -985,28 +985,38 @@ ALint Int64ValsByProp(ALenum prop) } -ALboolean SetSourcefv(ALsource *Source, ALCcontext *Context, SourceProp prop, const ALfloat *values); -ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const ALint *values); -ALboolean SetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, const ALint64SOFT *values); +bool SetSourcefv(ALsource *Source, ALCcontext *Context, SourceProp prop, const al::span values); +bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const al::span values); +bool SetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, const al::span values); +#define CHECKSIZE(v, s) do { \ + if(UNLIKELY((v).size() != INT_MAX && (v).size() != (s))) \ + { \ + Context->setError(AL_INVALID_ENUM, \ + "Property 0x%04x expects %d value(s), got %zu", prop, (s), \ + (v).size()); \ + return false; \ + } \ +} while(0) #define CHECKVAL(x) do { \ - if(!(x)) \ + if(UNLIKELY(!(x))) \ { \ Context->setError(AL_INVALID_VALUE, "Value out of range"); \ - return AL_FALSE; \ + return false; \ } \ } while(0) -void UpdateSourceProps(ALsource *source, ALCcontext *context) +bool UpdateSourceProps(ALsource *source, ALCcontext *context) { ALvoice *voice; if(SourceShouldUpdate(source, context) && (voice=GetSourceVoice(source, context)) != nullptr) UpdateSourceProps(source, voice, context); else source->PropsClean.clear(std::memory_order_release); + return true; } -ALboolean SetSourcefv(ALsource *Source, ALCcontext *Context, SourceProp prop, const ALfloat *values) +bool SetSourcefv(ALsource *Source, ALCcontext *Context, SourceProp prop, const al::span values) { ALint ival; @@ -1015,114 +1025,115 @@ ALboolean SetSourcefv(ALsource *Source, ALCcontext *Context, SourceProp prop, co case AL_SEC_OFFSET_LATENCY_SOFT: case AL_SEC_OFFSET_CLOCK_SOFT: /* Query only */ - SETERR_RETURN(Context, AL_INVALID_OPERATION, AL_FALSE, - "Setting read-only source property 0x%04x", prop); + SETERR_RETURN(Context, AL_INVALID_OPERATION, false, + "Setting read-only source property 0x%04x", prop); case AL_PITCH: - CHECKVAL(*values >= 0.0f); + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f); - Source->Pitch = *values; - UpdateSourceProps(Source, Context); - return AL_TRUE; + Source->Pitch = values[0]; + return UpdateSourceProps(Source, Context); case AL_CONE_INNER_ANGLE: - CHECKVAL(*values >= 0.0f && *values <= 360.0f); + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f && values[0] <= 360.0f); - Source->InnerAngle = *values; - UpdateSourceProps(Source, Context); - return AL_TRUE; + Source->InnerAngle = values[0]; + return UpdateSourceProps(Source, Context); case AL_CONE_OUTER_ANGLE: - CHECKVAL(*values >= 0.0f && *values <= 360.0f); + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f && values[0] <= 360.0f); - Source->OuterAngle = *values; - UpdateSourceProps(Source, Context); - return AL_TRUE; + Source->OuterAngle = values[0]; + return UpdateSourceProps(Source, Context); case AL_GAIN: - CHECKVAL(*values >= 0.0f); + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f); - Source->Gain = *values; - UpdateSourceProps(Source, Context); - return AL_TRUE; + Source->Gain = values[0]; + return UpdateSourceProps(Source, Context); case AL_MAX_DISTANCE: - CHECKVAL(*values >= 0.0f); + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f); - Source->MaxDistance = *values; - UpdateSourceProps(Source, Context); - return AL_TRUE; + Source->MaxDistance = values[0]; + return UpdateSourceProps(Source, Context); case AL_ROLLOFF_FACTOR: - CHECKVAL(*values >= 0.0f); + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f); - Source->RolloffFactor = *values; - UpdateSourceProps(Source, Context); - return AL_TRUE; + Source->RolloffFactor = values[0]; + return UpdateSourceProps(Source, Context); case AL_REFERENCE_DISTANCE: - CHECKVAL(*values >= 0.0f); + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f); - Source->RefDistance = *values; - UpdateSourceProps(Source, Context); - return AL_TRUE; + Source->RefDistance = values[0]; + return UpdateSourceProps(Source, Context); case AL_MIN_GAIN: - CHECKVAL(*values >= 0.0f); + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f); - Source->MinGain = *values; - UpdateSourceProps(Source, Context); - return AL_TRUE; + Source->MinGain = values[0]; + return UpdateSourceProps(Source, Context); case AL_MAX_GAIN: - CHECKVAL(*values >= 0.0f); + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f); - Source->MaxGain = *values; - UpdateSourceProps(Source, Context); - return AL_TRUE; + Source->MaxGain = values[0]; + return UpdateSourceProps(Source, Context); case AL_CONE_OUTER_GAIN: - CHECKVAL(*values >= 0.0f && *values <= 1.0f); + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f && values[0] <= 1.0f); - Source->OuterGain = *values; - UpdateSourceProps(Source, Context); - return AL_TRUE; + Source->OuterGain = values[0]; + return UpdateSourceProps(Source, Context); case AL_CONE_OUTER_GAINHF: - CHECKVAL(*values >= 0.0f && *values <= 1.0f); + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f && values[0] <= 1.0f); - Source->OuterGainHF = *values; - UpdateSourceProps(Source, Context); - return AL_TRUE; + Source->OuterGainHF = values[0]; + return UpdateSourceProps(Source, Context); case AL_AIR_ABSORPTION_FACTOR: - CHECKVAL(*values >= 0.0f && *values <= 10.0f); + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f && values[0] <= 10.0f); - Source->AirAbsorptionFactor = *values; - UpdateSourceProps(Source, Context); - return AL_TRUE; + Source->AirAbsorptionFactor = values[0]; + return UpdateSourceProps(Source, Context); case AL_ROOM_ROLLOFF_FACTOR: - CHECKVAL(*values >= 0.0f && *values <= 10.0f); + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f && values[0] <= 10.0f); - Source->RoomRolloffFactor = *values; - UpdateSourceProps(Source, Context); - return AL_TRUE; + Source->RoomRolloffFactor = values[0]; + return UpdateSourceProps(Source, Context); case AL_DOPPLER_FACTOR: - CHECKVAL(*values >= 0.0f && *values <= 1.0f); + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f && values[0] <= 1.0f); - Source->DopplerFactor = *values; - UpdateSourceProps(Source, Context); - return AL_TRUE; + Source->DopplerFactor = values[0]; + return UpdateSourceProps(Source, Context); case AL_SEC_OFFSET: case AL_SAMPLE_OFFSET: case AL_BYTE_OFFSET: - CHECKVAL(*values >= 0.0f); + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f); Source->OffsetType = prop; - Source->Offset = *values; + Source->Offset = values[0]; if(IsPlayingOrPaused(Source)) { @@ -1134,55 +1145,56 @@ ALboolean SetSourcefv(ALsource *Source, ALCcontext *Context, SourceProp prop, co if(ALvoice *voice{GetSourceVoice(Source, Context)}) { if(ApplyOffset(Source, voice) == AL_FALSE) - SETERR_RETURN(Context, AL_INVALID_VALUE, AL_FALSE, "Invalid offset"); + SETERR_RETURN(Context, AL_INVALID_VALUE, false, "Invalid offset"); } } - return AL_TRUE; + return true; case AL_SOURCE_RADIUS: - CHECKVAL(*values >= 0.0f && std::isfinite(*values)); + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f && std::isfinite(values[0])); - Source->Radius = *values; - UpdateSourceProps(Source, Context); - return AL_TRUE; + Source->Radius = values[0]; + return UpdateSourceProps(Source, Context); case AL_STEREO_ANGLES: + CHECKSIZE(values, 2); CHECKVAL(std::isfinite(values[0]) && std::isfinite(values[1])); Source->StereoPan[0] = values[0]; Source->StereoPan[1] = values[1]; - UpdateSourceProps(Source, Context); - return AL_TRUE; + return UpdateSourceProps(Source, Context); case AL_POSITION: + CHECKSIZE(values, 3); CHECKVAL(std::isfinite(values[0]) && std::isfinite(values[1]) && std::isfinite(values[2])); Source->Position[0] = values[0]; Source->Position[1] = values[1]; Source->Position[2] = values[2]; - UpdateSourceProps(Source, Context); - return AL_TRUE; + return UpdateSourceProps(Source, Context); case AL_VELOCITY: + CHECKSIZE(values, 3); CHECKVAL(std::isfinite(values[0]) && std::isfinite(values[1]) && std::isfinite(values[2])); Source->Velocity[0] = values[0]; Source->Velocity[1] = values[1]; Source->Velocity[2] = values[2]; - UpdateSourceProps(Source, Context); - return AL_TRUE; + return UpdateSourceProps(Source, Context); case AL_DIRECTION: + CHECKSIZE(values, 3); CHECKVAL(std::isfinite(values[0]) && std::isfinite(values[1]) && std::isfinite(values[2])); Source->Direction[0] = values[0]; Source->Direction[1] = values[1]; Source->Direction[2] = values[2]; - UpdateSourceProps(Source, Context); - return AL_TRUE; + return UpdateSourceProps(Source, Context); case AL_ORIENTATION: + CHECKSIZE(values, 6); CHECKVAL(std::isfinite(values[0]) && std::isfinite(values[1]) && std::isfinite(values[2]) && std::isfinite(values[3]) && std::isfinite(values[4]) && std::isfinite(values[5])); @@ -1192,8 +1204,7 @@ ALboolean SetSourcefv(ALsource *Source, ALCcontext *Context, SourceProp prop, co Source->OrientUp[0] = values[3]; Source->OrientUp[1] = values[4]; Source->OrientUp[2] = values[5]; - UpdateSourceProps(Source, Context); - return AL_TRUE; + return UpdateSourceProps(Source, Context); case AL_SOURCE_RELATIVE: @@ -1207,13 +1218,15 @@ ALboolean SetSourcefv(ALsource *Source, ALCcontext *Context, SourceProp prop, co case AL_DIRECT_CHANNELS_SOFT: case AL_SOURCE_RESAMPLER_SOFT: case AL_SOURCE_SPATIALIZE_SOFT: + CHECKSIZE(values, 1); ival = static_cast(values[0]); - return SetSourceiv(Source, Context, prop, &ival); + return SetSourceiv(Source, Context, prop, {&ival, 1u}); case AL_BUFFERS_QUEUED: case AL_BUFFERS_PROCESSED: + CHECKSIZE(values, 1); ival = static_cast(static_cast(values[0])); - return SetSourceiv(Source, Context, prop, &ival); + return SetSourceiv(Source, Context, prop, {&ival, 1u}); case AL_BUFFER: case AL_DIRECT_FILTER: @@ -1225,10 +1238,10 @@ ALboolean SetSourcefv(ALsource *Source, ALCcontext *Context, SourceProp prop, co ERR("Unexpected property: 0x%04x\n", prop); Context->setError(AL_INVALID_ENUM, "Invalid source float property 0x%04x", prop); - return AL_FALSE; + return false; } -ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const ALint *values) +bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const al::span values) { ALCdevice *device{Context->mDevice.get()}; ALbuffer *buffer{nullptr}; @@ -1247,24 +1260,24 @@ ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, co case AL_BUFFERS_QUEUED: case AL_BUFFERS_PROCESSED: /* Query only */ - SETERR_RETURN(Context, AL_INVALID_OPERATION, AL_FALSE, - "Setting read-only source property 0x%04x", prop); + SETERR_RETURN(Context, AL_INVALID_OPERATION, false, + "Setting read-only source property 0x%04x", prop); case AL_SOURCE_RELATIVE: - CHECKVAL(*values == AL_FALSE || *values == AL_TRUE); + CHECKSIZE(values, 1); + CHECKVAL(values[0] == AL_FALSE || values[0] == AL_TRUE); - Source->HeadRelative = static_cast(*values); - UpdateSourceProps(Source, Context); - return AL_TRUE; + Source->HeadRelative = static_cast(values[0]); + return UpdateSourceProps(Source, Context); case AL_LOOPING: - CHECKVAL(*values == AL_FALSE || *values == AL_TRUE); + CHECKSIZE(values, 1); + CHECKVAL(values[0] == AL_FALSE || values[0] == AL_TRUE); - Source->Looping = static_cast(*values); + Source->Looping = static_cast(values[0]); if(IsPlayingOrPaused(Source)) { - ALvoice *voice{GetSourceVoice(Source, Context)}; - if(voice) + if(ALvoice *voice{GetSourceVoice(Source, Context)}) { if(Source->Looping) voice->mLoopBuffer.store(Source->queue, std::memory_order_release); @@ -1279,24 +1292,24 @@ ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, co std::this_thread::yield(); } } - return AL_TRUE; + return true; case AL_BUFFER: + CHECKSIZE(values, 1); buflock = std::unique_lock{device->BufferLock}; - if(!(*values == 0 || (buffer=LookupBuffer(device, *values)) != nullptr)) - SETERR_RETURN(Context, AL_INVALID_VALUE, AL_FALSE, "Invalid buffer ID %u", - *values); + if(!(values[0] == 0 || (buffer=LookupBuffer(device, values[0])) != nullptr)) + SETERR_RETURN(Context, AL_INVALID_VALUE, false, "Invalid buffer ID %u", values[0]); if(buffer && buffer->MappedAccess != 0 && !(buffer->MappedAccess&AL_MAP_PERSISTENT_BIT_SOFT)) - SETERR_RETURN(Context, AL_INVALID_OPERATION, AL_FALSE, - "Setting non-persistently mapped buffer %u", buffer->id); + SETERR_RETURN(Context, AL_INVALID_OPERATION, false, + "Setting non-persistently mapped buffer %u", buffer->id); else { ALenum state = GetSourceState(Source, GetSourceVoice(Source, Context)); if(state == AL_PLAYING || state == AL_PAUSED) - SETERR_RETURN(Context, AL_INVALID_OPERATION, AL_FALSE, - "Setting buffer on playing or paused source %u", Source->id); + SETERR_RETURN(Context, AL_INVALID_OPERATION, false, + "Setting buffer on playing or paused source %u", Source->id); } oldlist = Source->queue; @@ -1334,15 +1347,16 @@ ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, co { if(buffer) DecrementRef(buffer->ref); }); al_free(temp); } - return AL_TRUE; + return true; case AL_SEC_OFFSET: case AL_SAMPLE_OFFSET: case AL_BYTE_OFFSET: - CHECKVAL(*values >= 0); + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0); Source->OffsetType = prop; - Source->Offset = *values; + Source->Offset = values[0]; if(IsPlayingOrPaused(Source)) { @@ -1351,17 +1365,16 @@ ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, co if(ALvoice *voice{GetSourceVoice(Source, Context)}) { if(ApplyOffset(Source, voice) == AL_FALSE) - SETERR_RETURN(Context, AL_INVALID_VALUE, AL_FALSE, - "Invalid source offset"); + SETERR_RETURN(Context, AL_INVALID_VALUE, false, "Invalid source offset"); } } - return AL_TRUE; + return true; case AL_DIRECT_FILTER: + CHECKSIZE(values, 1); filtlock = std::unique_lock{device->FilterLock}; - if(!(*values == 0 || (filter=LookupFilter(device, *values)) != nullptr)) - SETERR_RETURN(Context, AL_INVALID_VALUE, AL_FALSE, "Invalid filter ID %u", - *values); + if(!(values[0] == 0 || (filter=LookupFilter(device, values[0])) != nullptr)) + SETERR_RETURN(Context, AL_INVALID_VALUE, false, "Invalid filter ID %u", values[0]); if(!filter) { @@ -1380,78 +1393,74 @@ ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, co Source->Direct.LFReference = filter->LFReference; } filtlock.unlock(); - UpdateSourceProps(Source, Context); - return AL_TRUE; + return UpdateSourceProps(Source, Context); case AL_DIRECT_FILTER_GAINHF_AUTO: - CHECKVAL(*values == AL_FALSE || *values == AL_TRUE); + CHECKSIZE(values, 1); + CHECKVAL(values[0] == AL_FALSE || values[0] == AL_TRUE); - Source->DryGainHFAuto = *values; - UpdateSourceProps(Source, Context); - return AL_TRUE; + Source->DryGainHFAuto = values[0]; + return UpdateSourceProps(Source, Context); case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: - CHECKVAL(*values == AL_FALSE || *values == AL_TRUE); + CHECKSIZE(values, 1); + CHECKVAL(values[0] == AL_FALSE || values[0] == AL_TRUE); - Source->WetGainAuto = *values; - UpdateSourceProps(Source, Context); - return AL_TRUE; + Source->WetGainAuto = values[0]; + return UpdateSourceProps(Source, Context); case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: - CHECKVAL(*values == AL_FALSE || *values == AL_TRUE); + CHECKSIZE(values, 1); + CHECKVAL(values[0] == AL_FALSE || values[0] == AL_TRUE); - Source->WetGainHFAuto = *values; - UpdateSourceProps(Source, Context); - return AL_TRUE; + Source->WetGainHFAuto = values[0]; + return UpdateSourceProps(Source, Context); case AL_DIRECT_CHANNELS_SOFT: - CHECKVAL(*values == AL_FALSE || *values == AL_TRUE); + CHECKSIZE(values, 1); + CHECKVAL(values[0] == AL_FALSE || values[0] == AL_TRUE); - Source->DirectChannels = *values; - UpdateSourceProps(Source, Context); - return AL_TRUE; + Source->DirectChannels = values[0]; + return UpdateSourceProps(Source, Context); case AL_DISTANCE_MODEL: - CHECKVAL(*values == AL_NONE || - *values == AL_INVERSE_DISTANCE || - *values == AL_INVERSE_DISTANCE_CLAMPED || - *values == AL_LINEAR_DISTANCE || - *values == AL_LINEAR_DISTANCE_CLAMPED || - *values == AL_EXPONENT_DISTANCE || - *values == AL_EXPONENT_DISTANCE_CLAMPED); - - Source->mDistanceModel = static_cast(*values); + CHECKSIZE(values, 1); + CHECKVAL(values[0] == AL_NONE || + values[0] == AL_INVERSE_DISTANCE || values[0] == AL_INVERSE_DISTANCE_CLAMPED || + values[0] == AL_LINEAR_DISTANCE || values[0] == AL_LINEAR_DISTANCE_CLAMPED || + values[0] == AL_EXPONENT_DISTANCE || values[0] == AL_EXPONENT_DISTANCE_CLAMPED); + + Source->mDistanceModel = static_cast(values[0]); if(Context->mSourceDistanceModel) - UpdateSourceProps(Source, Context); - return AL_TRUE; + return UpdateSourceProps(Source, Context); + return true; case AL_SOURCE_RESAMPLER_SOFT: - CHECKVAL(*values >= 0 && *values <= ResamplerMax); + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0 && values[0] <= ResamplerMax); - Source->mResampler = static_cast(*values); - UpdateSourceProps(Source, Context); - return AL_TRUE; + Source->mResampler = static_cast(values[0]); + return UpdateSourceProps(Source, Context); case AL_SOURCE_SPATIALIZE_SOFT: - CHECKVAL(*values >= AL_FALSE && *values <= AL_AUTO_SOFT); + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= AL_FALSE && values[0] <= AL_AUTO_SOFT); - Source->mSpatialize = static_cast(*values); - UpdateSourceProps(Source, Context); - return AL_TRUE; + Source->mSpatialize = static_cast(values[0]); + return UpdateSourceProps(Source, Context); case AL_AUXILIARY_SEND_FILTER: + CHECKSIZE(values, 3); slotlock = std::unique_lock{Context->mEffectSlotLock}; if(!(values[0] == 0 || (slot=LookupEffectSlot(Context, values[0])) != nullptr)) - SETERR_RETURN(Context, AL_INVALID_VALUE, AL_FALSE, "Invalid effect ID %u", - values[0]); + SETERR_RETURN(Context, AL_INVALID_VALUE, false, "Invalid effect ID %u", values[0]); if(static_cast(values[1]) >= static_cast(device->NumAuxSends)) - SETERR_RETURN(Context, AL_INVALID_VALUE, AL_FALSE, "Invalid send %u", values[1]); + SETERR_RETURN(Context, AL_INVALID_VALUE, false, "Invalid send %u", values[1]); filtlock = std::unique_lock{device->FilterLock}; if(!(values[2] == 0 || (filter=LookupFilter(device, values[2])) != nullptr)) - SETERR_RETURN(Context, AL_INVALID_VALUE, AL_FALSE, "Invalid filter ID %u", - values[2]); + SETERR_RETURN(Context, AL_INVALID_VALUE, false, "Invalid filter ID %u", values[2]); if(!filter) { @@ -1495,8 +1504,7 @@ ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, co Source->Send[values[1]].Slot = slot; UpdateSourceProps(Source, Context); } - - return AL_TRUE; + return true; /* 1x float */ @@ -1515,27 +1523,30 @@ ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, co case AL_AIR_ABSORPTION_FACTOR: case AL_ROOM_ROLLOFF_FACTOR: case AL_SOURCE_RADIUS: - fvals[0] = static_cast(*values); - return SetSourcefv(Source, Context, prop, fvals); + CHECKSIZE(values, 1); + fvals[0] = static_cast(values[0]); + return SetSourcefv(Source, Context, prop, {fvals, 1u}); /* 3x float */ case AL_POSITION: case AL_VELOCITY: case AL_DIRECTION: + CHECKSIZE(values, 3); fvals[0] = static_cast(values[0]); fvals[1] = static_cast(values[1]); fvals[2] = static_cast(values[2]); - return SetSourcefv(Source, Context, prop, fvals); + return SetSourcefv(Source, Context, prop, {fvals, 3u}); /* 6x float */ case AL_ORIENTATION: + CHECKSIZE(values, 6); fvals[0] = static_cast(values[0]); fvals[1] = static_cast(values[1]); fvals[2] = static_cast(values[2]); fvals[3] = static_cast(values[3]); fvals[4] = static_cast(values[4]); fvals[5] = static_cast(values[5]); - return SetSourcefv(Source, Context, prop, fvals); + return SetSourcefv(Source, Context, prop, {fvals, 6u}); case AL_SAMPLE_OFFSET_LATENCY_SOFT: case AL_SEC_OFFSET_LATENCY_SOFT: @@ -1547,10 +1558,10 @@ ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, co ERR("Unexpected property: 0x%04x\n", prop); Context->setError(AL_INVALID_ENUM, "Invalid source integer property 0x%04x", prop); - return AL_FALSE; + return false; } -ALboolean SetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, const ALint64SOFT *values) +bool SetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, const al::span values) { ALfloat fvals[6]; ALint ivals[3]; @@ -1564,8 +1575,8 @@ ALboolean SetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, case AL_SAMPLE_OFFSET_LATENCY_SOFT: case AL_SAMPLE_OFFSET_CLOCK_SOFT: /* Query only */ - SETERR_RETURN(Context, AL_INVALID_OPERATION, AL_FALSE, - "Setting read-only source property 0x%04x", prop); + SETERR_RETURN(Context, AL_INVALID_OPERATION, false, + "Setting read-only source property 0x%04x", prop); /* 1x int */ case AL_SOURCE_RELATIVE: @@ -1580,21 +1591,24 @@ ALboolean SetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, case AL_DISTANCE_MODEL: case AL_SOURCE_RESAMPLER_SOFT: case AL_SOURCE_SPATIALIZE_SOFT: - CHECKVAL(*values <= INT_MAX && *values >= INT_MIN); + CHECKSIZE(values, 1); + CHECKVAL(values[0] <= INT_MAX && values[0] >= INT_MIN); - ivals[0] = static_cast(*values); - return SetSourceiv(Source, Context, prop, ivals); + ivals[0] = static_cast(values[0]); + return SetSourceiv(Source, Context, prop, {ivals, 1u}); /* 1x uint */ case AL_BUFFER: case AL_DIRECT_FILTER: - CHECKVAL(*values <= UINT_MAX && *values >= 0); + CHECKSIZE(values, 1); + CHECKVAL(values[0] <= UINT_MAX && values[0] >= 0); - ivals[0] = static_cast(*values); - return SetSourceiv(Source, Context, prop, ivals); + ivals[0] = static_cast(values[0]); + return SetSourceiv(Source, Context, prop, {ivals, 1u}); /* 3x uint */ case AL_AUXILIARY_SEND_FILTER: + CHECKSIZE(values, 3); CHECKVAL(values[0] <= UINT_MAX && values[0] >= 0 && values[1] <= UINT_MAX && values[1] >= 0 && values[2] <= UINT_MAX && values[2] >= 0); @@ -1602,7 +1616,7 @@ ALboolean SetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, ivals[0] = static_cast(values[0]); ivals[1] = static_cast(values[1]); ivals[2] = static_cast(values[2]); - return SetSourceiv(Source, Context, prop, ivals); + return SetSourceiv(Source, Context, prop, {ivals, 3u}); /* 1x float */ case AL_CONE_INNER_ANGLE: @@ -1620,27 +1634,30 @@ ALboolean SetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, case AL_AIR_ABSORPTION_FACTOR: case AL_ROOM_ROLLOFF_FACTOR: case AL_SOURCE_RADIUS: - fvals[0] = static_cast(*values); - return SetSourcefv(Source, Context, prop, fvals); + CHECKSIZE(values, 1); + fvals[0] = static_cast(values[0]); + return SetSourcefv(Source, Context, prop, {fvals, 1u}); /* 3x float */ case AL_POSITION: case AL_VELOCITY: case AL_DIRECTION: + CHECKSIZE(values, 3); fvals[0] = static_cast(values[0]); fvals[1] = static_cast(values[1]); fvals[2] = static_cast(values[2]); - return SetSourcefv(Source, Context, prop, fvals); + return SetSourcefv(Source, Context, prop, {fvals, 3u}); /* 6x float */ case AL_ORIENTATION: + CHECKSIZE(values, 6); fvals[0] = static_cast(values[0]); fvals[1] = static_cast(values[1]); fvals[2] = static_cast(values[2]); fvals[3] = static_cast(values[3]); fvals[4] = static_cast(values[4]); fvals[5] = static_cast(values[5]); - return SetSourcefv(Source, Context, prop, fvals); + return SetSourcefv(Source, Context, prop, {fvals, 6u}); case AL_SEC_OFFSET_LATENCY_SOFT: case AL_SEC_OFFSET_CLOCK_SOFT: @@ -2225,10 +2242,8 @@ START_API_FUNC ALsource *Source = LookupSource(context.get(), source); if(UNLIKELY(!Source)) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); - else if(FloatValsByProp(param) != 1) - context->setError(AL_INVALID_ENUM, "Invalid float property 0x%04x", param); else - SetSourcefv(Source, context.get(), static_cast(param), &value); + SetSourcefv(Source, context.get(), static_cast(param), {&value, 1u}); } END_API_FUNC @@ -2243,11 +2258,9 @@ START_API_FUNC ALsource *Source = LookupSource(context.get(), source); if(UNLIKELY(!Source)) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); - else if(FloatValsByProp(param) != 3) - context->setError(AL_INVALID_ENUM, "Invalid 3-float property 0x%04x", param); else { - ALfloat fvals[3] = { value1, value2, value3 }; + const ALfloat fvals[3]{ value1, value2, value3 }; SetSourcefv(Source, context.get(), static_cast(param), fvals); } } @@ -2266,10 +2279,8 @@ START_API_FUNC context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); - else if(FloatValsByProp(param) < 1) - context->setError(AL_INVALID_ENUM, "Invalid float-vector property 0x%04x", param); else - SetSourcefv(Source, context.get(), static_cast(param), values); + SetSourcefv(Source, context.get(), static_cast(param), {values, INT_MAX}); } END_API_FUNC @@ -2285,12 +2296,10 @@ START_API_FUNC ALsource *Source = LookupSource(context.get(), source); if(UNLIKELY(!Source)) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); - else if(DoubleValsByProp(param) != 1) - context->setError(AL_INVALID_ENUM, "Invalid double property 0x%04x", param); else { - ALfloat fval = static_cast(value); - SetSourcefv(Source, context.get(), static_cast(param), &fval); + const auto fval = static_cast(value); + SetSourcefv(Source, context.get(), static_cast(param), {&fval, 1u}); } } END_API_FUNC @@ -2306,12 +2315,10 @@ START_API_FUNC ALsource *Source = LookupSource(context.get(), source); if(UNLIKELY(!Source)) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); - else if(DoubleValsByProp(param) != 3) - context->setError(AL_INVALID_ENUM, "Invalid 3-double property 0x%04x", param); - else { - ALfloat fvals[3] = {static_cast(value1), - static_cast(value2), - static_cast(value3)}; + else + { + const ALfloat fvals[3]{static_cast(value1), static_cast(value2), + static_cast(value3)}; SetSourcefv(Source, context.get(), static_cast(param), fvals); } } @@ -2332,17 +2339,15 @@ START_API_FUNC context->setError(AL_INVALID_VALUE, "NULL pointer"); else { - ALint count{DoubleValsByProp(param)}; + const ALuint count = DoubleValsByProp(param); if(count < 1 || count > 6) context->setError(AL_INVALID_ENUM, "Invalid double-vector property 0x%04x", param); else { ALfloat fvals[6]; - ALint i; - - for(i = 0;i < count;i++) + for(ALuint i{0};i < count;i++) fvals[i] = static_cast(values[i]); - SetSourcefv(Source, context.get(), static_cast(param), fvals); + SetSourcefv(Source, context.get(), static_cast(param), {fvals, count}); } } } @@ -2360,10 +2365,8 @@ START_API_FUNC ALsource *Source = LookupSource(context.get(), source); if(UNLIKELY(!Source)) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); - else if(IntValsByProp(param) != 1) - context->setError(AL_INVALID_ENUM, "Invalid integer property 0x%04x", param); else - SetSourceiv(Source, context.get(), static_cast(param), &value); + SetSourceiv(Source, context.get(), static_cast(param), {&value, 1u}); } END_API_FUNC @@ -2378,11 +2381,9 @@ START_API_FUNC ALsource *Source = LookupSource(context.get(), source); if(UNLIKELY(!Source)) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); - else if(IntValsByProp(param) != 3) - context->setError(AL_INVALID_ENUM, "Invalid 3-integer property 0x%04x", param); else { - ALint ivals[3] = { value1, value2, value3 }; + const ALint ivals[3]{ value1, value2, value3 }; SetSourceiv(Source, context.get(), static_cast(param), ivals); } } @@ -2401,10 +2402,8 @@ START_API_FUNC context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); - else if(IntValsByProp(param) < 1) - context->setError(AL_INVALID_ENUM, "Invalid integer-vector property 0x%04x", param); else - SetSourceiv(Source, context.get(), static_cast(param), values); + SetSourceiv(Source, context.get(), static_cast(param), {values, INT_MAX}); } END_API_FUNC @@ -2420,10 +2419,8 @@ START_API_FUNC ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); - else if(Int64ValsByProp(param) != 1) - context->setError(AL_INVALID_ENUM, "Invalid integer64 property 0x%04x", param); else - SetSourcei64v(Source, context.get(), static_cast(param), &value); + SetSourcei64v(Source, context.get(), static_cast(param), {&value, 1u}); } END_API_FUNC @@ -2438,11 +2435,9 @@ START_API_FUNC ALsource *Source{LookupSource(context.get(), source)}; if(UNLIKELY(!Source)) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); - else if(Int64ValsByProp(param) != 3) - context->setError(AL_INVALID_ENUM, "Invalid 3-integer64 property 0x%04x", param); else { - ALint64SOFT i64vals[3] = { value1, value2, value3 }; + const ALint64SOFT i64vals[3]{ value1, value2, value3 }; SetSourcei64v(Source, context.get(), static_cast(param), i64vals); } } @@ -2461,10 +2456,8 @@ START_API_FUNC context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); - else if(Int64ValsByProp(param) < 1) - context->setError(AL_INVALID_ENUM, "Invalid integer64-vector property 0x%04x", param); else - SetSourcei64v(Source, context.get(), static_cast(param), values); + SetSourcei64v(Source, context.get(), static_cast(param), {values, INT_MAX}); } END_API_FUNC -- cgit v1.2.3 From 7897de31d0f75f4ac1d91fe8c470953e9f54d151 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 3 Aug 2019 19:36:19 -0700 Subject: Pass spans to the source get-property methods --- al/source.cpp | 433 ++++++++++++++++++++++------------------------------------ 1 file changed, 165 insertions(+), 268 deletions(-) (limited to 'al/source.cpp') diff --git a/al/source.cpp b/al/source.cpp index 043ef940..69bdf6b5 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -741,7 +741,7 @@ void SendStateChangeEvent(ALCcontext *context, ALuint id, ALenum state) } -ALint FloatValsByProp(ALenum prop) +ALuint FloatValsByProp(ALenum prop) { switch(static_cast(prop)) { @@ -803,7 +803,7 @@ ALint FloatValsByProp(ALenum prop) } return 0; } -ALint DoubleValsByProp(ALenum prop) +ALuint DoubleValsByProp(ALenum prop) { switch(static_cast(prop)) { @@ -864,126 +864,6 @@ ALint DoubleValsByProp(ALenum prop) return 0; } -ALint IntValsByProp(ALenum prop) -{ - switch(static_cast(prop)) - { - case AL_PITCH: - case AL_GAIN: - case AL_MIN_GAIN: - case AL_MAX_GAIN: - case AL_MAX_DISTANCE: - case AL_ROLLOFF_FACTOR: - case AL_DOPPLER_FACTOR: - case AL_CONE_OUTER_GAIN: - case AL_SEC_OFFSET: - case AL_SAMPLE_OFFSET: - case AL_BYTE_OFFSET: - case AL_CONE_INNER_ANGLE: - case AL_CONE_OUTER_ANGLE: - case AL_REFERENCE_DISTANCE: - case AL_CONE_OUTER_GAINHF: - case AL_AIR_ABSORPTION_FACTOR: - case AL_ROOM_ROLLOFF_FACTOR: - case AL_DIRECT_FILTER_GAINHF_AUTO: - case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: - case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: - case AL_DIRECT_CHANNELS_SOFT: - case AL_DISTANCE_MODEL: - case AL_SOURCE_RELATIVE: - case AL_LOOPING: - case AL_BUFFER: - case AL_SOURCE_STATE: - case AL_BUFFERS_QUEUED: - case AL_BUFFERS_PROCESSED: - case AL_SOURCE_TYPE: - case AL_DIRECT_FILTER: - case AL_SOURCE_RADIUS: - case AL_SOURCE_RESAMPLER_SOFT: - case AL_SOURCE_SPATIALIZE_SOFT: - return 1; - - case AL_POSITION: - case AL_VELOCITY: - case AL_DIRECTION: - case AL_AUXILIARY_SEND_FILTER: - return 3; - - case AL_ORIENTATION: - return 6; - - case AL_SAMPLE_OFFSET_LATENCY_SOFT: - case AL_SAMPLE_OFFSET_CLOCK_SOFT: - break; /* i64 only */ - case AL_SEC_OFFSET_LATENCY_SOFT: - case AL_SEC_OFFSET_CLOCK_SOFT: - break; /* Double only */ - case AL_STEREO_ANGLES: - break; /* Float/double only */ - } - return 0; -} -ALint Int64ValsByProp(ALenum prop) -{ - switch(static_cast(prop)) - { - case AL_PITCH: - case AL_GAIN: - case AL_MIN_GAIN: - case AL_MAX_GAIN: - case AL_MAX_DISTANCE: - case AL_ROLLOFF_FACTOR: - case AL_DOPPLER_FACTOR: - case AL_CONE_OUTER_GAIN: - case AL_SEC_OFFSET: - case AL_SAMPLE_OFFSET: - case AL_BYTE_OFFSET: - case AL_CONE_INNER_ANGLE: - case AL_CONE_OUTER_ANGLE: - case AL_REFERENCE_DISTANCE: - case AL_CONE_OUTER_GAINHF: - case AL_AIR_ABSORPTION_FACTOR: - case AL_ROOM_ROLLOFF_FACTOR: - case AL_DIRECT_FILTER_GAINHF_AUTO: - case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: - case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: - case AL_DIRECT_CHANNELS_SOFT: - case AL_DISTANCE_MODEL: - case AL_SOURCE_RELATIVE: - case AL_LOOPING: - case AL_BUFFER: - case AL_SOURCE_STATE: - case AL_BUFFERS_QUEUED: - case AL_BUFFERS_PROCESSED: - case AL_SOURCE_TYPE: - case AL_DIRECT_FILTER: - case AL_SOURCE_RADIUS: - case AL_SOURCE_RESAMPLER_SOFT: - case AL_SOURCE_SPATIALIZE_SOFT: - return 1; - - case AL_SAMPLE_OFFSET_LATENCY_SOFT: - case AL_SAMPLE_OFFSET_CLOCK_SOFT: - return 2; - - case AL_POSITION: - case AL_VELOCITY: - case AL_DIRECTION: - case AL_AUXILIARY_SEND_FILTER: - return 3; - - case AL_ORIENTATION: - return 6; - - case AL_SEC_OFFSET_LATENCY_SOFT: - case AL_SEC_OFFSET_CLOCK_SOFT: - break; /* Double only */ - case AL_STEREO_ANGLES: - break; /* Float/double only */ - } - return 0; -} - bool SetSourcefv(ALsource *Source, ALCcontext *Context, SourceProp prop, const al::span values); bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const al::span values); @@ -1667,17 +1547,17 @@ bool SetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, const ERR("Unexpected property: 0x%04x\n", prop); Context->setError(AL_INVALID_ENUM, "Invalid source integer64 property 0x%04x", prop); - return AL_FALSE; + return false; } #undef CHECKVAL -ALboolean GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp prop, ALdouble *values); -ALboolean GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, ALint *values); -ALboolean GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, ALint64SOFT *values); +bool GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp prop, const al::span values); +bool GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const al::span values); +bool GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, const al::span values); -ALboolean GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp prop, ALdouble *values) +bool GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp prop, const al::span values) { ALCdevice *device{Context->mDevice.get()}; ClockLatency clocktime; @@ -1688,77 +1568,95 @@ ALboolean GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp prop, AL switch(prop) { case AL_GAIN: - *values = Source->Gain; - return AL_TRUE; + CHECKSIZE(values, 1); + values[0] = Source->Gain; + return true; case AL_PITCH: - *values = Source->Pitch; - return AL_TRUE; + CHECKSIZE(values, 1); + values[0] = Source->Pitch; + return true; case AL_MAX_DISTANCE: - *values = Source->MaxDistance; - return AL_TRUE; + CHECKSIZE(values, 1); + values[0] = Source->MaxDistance; + return true; case AL_ROLLOFF_FACTOR: - *values = Source->RolloffFactor; - return AL_TRUE; + CHECKSIZE(values, 1); + values[0] = Source->RolloffFactor; + return true; case AL_REFERENCE_DISTANCE: - *values = Source->RefDistance; - return AL_TRUE; + CHECKSIZE(values, 1); + values[0] = Source->RefDistance; + return true; case AL_CONE_INNER_ANGLE: - *values = Source->InnerAngle; - return AL_TRUE; + CHECKSIZE(values, 1); + values[0] = Source->InnerAngle; + return true; case AL_CONE_OUTER_ANGLE: - *values = Source->OuterAngle; - return AL_TRUE; + CHECKSIZE(values, 1); + values[0] = Source->OuterAngle; + return true; case AL_MIN_GAIN: - *values = Source->MinGain; - return AL_TRUE; + CHECKSIZE(values, 1); + values[0] = Source->MinGain; + return true; case AL_MAX_GAIN: - *values = Source->MaxGain; - return AL_TRUE; + CHECKSIZE(values, 1); + values[0] = Source->MaxGain; + return true; case AL_CONE_OUTER_GAIN: - *values = Source->OuterGain; - return AL_TRUE; + CHECKSIZE(values, 1); + values[0] = Source->OuterGain; + return true; case AL_SEC_OFFSET: case AL_SAMPLE_OFFSET: case AL_BYTE_OFFSET: - *values = GetSourceOffset(Source, prop, Context); - return AL_TRUE; + CHECKSIZE(values, 1); + values[0] = GetSourceOffset(Source, prop, Context); + return true; case AL_CONE_OUTER_GAINHF: - *values = Source->OuterGainHF; - return AL_TRUE; + CHECKSIZE(values, 1); + values[0] = Source->OuterGainHF; + return true; case AL_AIR_ABSORPTION_FACTOR: - *values = Source->AirAbsorptionFactor; - return AL_TRUE; + CHECKSIZE(values, 1); + values[0] = Source->AirAbsorptionFactor; + return true; case AL_ROOM_ROLLOFF_FACTOR: - *values = Source->RoomRolloffFactor; - return AL_TRUE; + CHECKSIZE(values, 1); + values[0] = Source->RoomRolloffFactor; + return true; case AL_DOPPLER_FACTOR: - *values = Source->DopplerFactor; - return AL_TRUE; + CHECKSIZE(values, 1); + values[0] = Source->DopplerFactor; + return true; case AL_SOURCE_RADIUS: - *values = Source->Radius; - return AL_TRUE; + CHECKSIZE(values, 1); + values[0] = Source->Radius; + return true; case AL_STEREO_ANGLES: + CHECKSIZE(values, 2); values[0] = Source->StereoPan[0]; values[1] = Source->StereoPan[1]; - return AL_TRUE; + return true; case AL_SEC_OFFSET_LATENCY_SOFT: + CHECKSIZE(values, 2); /* Get the source offset with the clock time first. Then get the * clock time with the device latency. Order is important. */ @@ -1778,39 +1676,44 @@ ALboolean GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp prop, AL values[1] = static_cast((clocktime.Latency - std::min(clocktime.Latency, diff)).count()) / 1000000000.0; } - return AL_TRUE; + return true; case AL_SEC_OFFSET_CLOCK_SOFT: + CHECKSIZE(values, 2); values[0] = GetSourceSecOffset(Source, Context, &srcclock); values[1] = srcclock.count() / 1000000000.0; - return AL_TRUE; + return true; case AL_POSITION: + CHECKSIZE(values, 3); values[0] = Source->Position[0]; values[1] = Source->Position[1]; values[2] = Source->Position[2]; - return AL_TRUE; + return true; case AL_VELOCITY: + CHECKSIZE(values, 3); values[0] = Source->Velocity[0]; values[1] = Source->Velocity[1]; values[2] = Source->Velocity[2]; - return AL_TRUE; + return true; case AL_DIRECTION: + CHECKSIZE(values, 3); values[0] = Source->Direction[0]; values[1] = Source->Direction[1]; values[2] = Source->Direction[2]; - return AL_TRUE; + return true; case AL_ORIENTATION: + CHECKSIZE(values, 6); values[0] = Source->OrientAt[0]; values[1] = Source->OrientAt[1]; values[2] = Source->OrientAt[2]; values[3] = Source->OrientUp[0]; values[4] = Source->OrientUp[1]; values[5] = Source->OrientUp[2]; - return AL_TRUE; + return true; /* 1x int */ case AL_SOURCE_RELATIVE: @@ -1826,8 +1729,9 @@ ALboolean GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp prop, AL case AL_DISTANCE_MODEL: case AL_SOURCE_RESAMPLER_SOFT: case AL_SOURCE_SPATIALIZE_SOFT: - if((err=GetSourceiv(Source, Context, prop, ivals)) != AL_FALSE) - *values = static_cast(ivals[0]); + CHECKSIZE(values, 1); + if((err=GetSourceiv(Source, Context, prop, {ivals, 1u})) != AL_FALSE) + values[0] = static_cast(ivals[0]); return err; case AL_BUFFER: @@ -1840,10 +1744,10 @@ ALboolean GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp prop, AL ERR("Unexpected property: 0x%04x\n", prop); Context->setError(AL_INVALID_ENUM, "Invalid source double property 0x%04x", prop); - return AL_FALSE; + return false; } -ALboolean GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, ALint *values) +bool GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const al::span values) { ALbufferlistitem *BufferList; ALdouble dvals[6]; @@ -1852,43 +1756,49 @@ ALboolean GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, AL switch(prop) { case AL_SOURCE_RELATIVE: - *values = Source->HeadRelative; - return AL_TRUE; + CHECKSIZE(values, 1); + values[0] = Source->HeadRelative; + return true; case AL_LOOPING: - *values = Source->Looping; - return AL_TRUE; + CHECKSIZE(values, 1); + values[0] = Source->Looping; + return true; case AL_BUFFER: + CHECKSIZE(values, 1); BufferList = (Source->SourceType == AL_STATIC) ? Source->queue : nullptr; - *values = (BufferList && BufferList->mNumBuffers >= 1 && BufferList->front()) ? - BufferList->front()->id : 0; - return AL_TRUE; + values[0] = (BufferList && !BufferList->empty() && BufferList->front()) ? + BufferList->front()->id : 0; + return true; case AL_SOURCE_STATE: - *values = GetSourceState(Source, GetSourceVoice(Source, Context)); - return AL_TRUE; + CHECKSIZE(values, 1); + values[0] = GetSourceState(Source, GetSourceVoice(Source, Context)); + return true; case AL_BUFFERS_QUEUED: + CHECKSIZE(values, 1); if(!(BufferList=Source->queue)) - *values = 0; + values[0] = 0; else { - ALsizei count = 0; + ALsizei count{0}; do { count += BufferList->mNumBuffers; BufferList = BufferList->mNext.load(std::memory_order_relaxed); } while(BufferList != nullptr); - *values = count; + values[0] = count; } - return AL_TRUE; + return true; case AL_BUFFERS_PROCESSED: + CHECKSIZE(values, 1); if(Source->Looping || Source->SourceType != AL_STREAMING) { /* Buffers on a looping source are in a perpetual state of * PENDING, so don't report any as PROCESSED */ - *values = 0; + values[0] = 0; } else { @@ -1907,41 +1817,49 @@ ALboolean GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, AL played += BufferList->mNumBuffers; BufferList = BufferList->mNext.load(std::memory_order_relaxed); } - *values = played; + values[0] = played; } - return AL_TRUE; + return true; case AL_SOURCE_TYPE: - *values = Source->SourceType; - return AL_TRUE; + CHECKSIZE(values, 1); + values[0] = Source->SourceType; + return true; case AL_DIRECT_FILTER_GAINHF_AUTO: - *values = Source->DryGainHFAuto; - return AL_TRUE; + CHECKSIZE(values, 1); + values[0] = Source->DryGainHFAuto; + return true; case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: - *values = Source->WetGainAuto; - return AL_TRUE; + CHECKSIZE(values, 1); + values[0] = Source->WetGainAuto; + return true; case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: - *values = Source->WetGainHFAuto; - return AL_TRUE; + CHECKSIZE(values, 1); + values[0] = Source->WetGainHFAuto; + return true; case AL_DIRECT_CHANNELS_SOFT: - *values = Source->DirectChannels; - return AL_TRUE; + CHECKSIZE(values, 1); + values[0] = Source->DirectChannels; + return true; case AL_DISTANCE_MODEL: - *values = static_cast(Source->mDistanceModel); - return AL_TRUE; + CHECKSIZE(values, 1); + values[0] = static_cast(Source->mDistanceModel); + return true; case AL_SOURCE_RESAMPLER_SOFT: - *values = Source->mResampler; - return AL_TRUE; + CHECKSIZE(values, 1); + values[0] = Source->mResampler; + return true; case AL_SOURCE_SPATIALIZE_SOFT: - *values = Source->mSpatialize; - return AL_TRUE; + CHECKSIZE(values, 1); + values[0] = Source->mSpatialize; + return true; /* 1x float/double */ case AL_CONE_INNER_ANGLE: @@ -1962,15 +1880,17 @@ ALboolean GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, AL case AL_ROOM_ROLLOFF_FACTOR: case AL_CONE_OUTER_GAINHF: case AL_SOURCE_RADIUS: - if((err=GetSourcedv(Source, Context, prop, dvals)) != AL_FALSE) - *values = static_cast(dvals[0]); + CHECKSIZE(values, 1); + if((err=GetSourcedv(Source, Context, prop, {dvals, 1u})) != false) + values[0] = static_cast(dvals[0]); return err; /* 3x float/double */ case AL_POSITION: case AL_VELOCITY: case AL_DIRECTION: - if((err=GetSourcedv(Source, Context, prop, dvals)) != AL_FALSE) + CHECKSIZE(values, 3); + if((err=GetSourcedv(Source, Context, prop, {dvals, 3u})) != false) { values[0] = static_cast(dvals[0]); values[1] = static_cast(dvals[1]); @@ -1980,7 +1900,8 @@ ALboolean GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, AL /* 6x float/double */ case AL_ORIENTATION: - if((err=GetSourcedv(Source, Context, prop, dvals)) != AL_FALSE) + CHECKSIZE(values, 6); + if((err=GetSourcedv(Source, Context, prop, {dvals, 6u})) != false) { values[0] = static_cast(dvals[0]); values[1] = static_cast(dvals[1]); @@ -2007,10 +1928,10 @@ ALboolean GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, AL ERR("Unexpected property: 0x%04x\n", prop); Context->setError(AL_INVALID_ENUM, "Invalid source integer property 0x%04x", prop); - return AL_FALSE; + return false; } -ALboolean GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, ALint64SOFT *values) +bool GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, const al::span values) { ALCdevice *device = Context->mDevice.get(); ClockLatency clocktime; @@ -2022,6 +1943,7 @@ ALboolean GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, switch(prop) { case AL_SAMPLE_OFFSET_LATENCY_SOFT: + CHECKSIZE(values, 2); /* Get the source offset with the clock time first. Then get the * clock time with the device latency. Order is important. */ @@ -2040,9 +1962,10 @@ ALboolean GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, auto diff = clocktime.ClockTime - srcclock; values[1] = (clocktime.Latency - std::min(clocktime.Latency, diff)).count(); } - return AL_TRUE; + return true; case AL_SAMPLE_OFFSET_CLOCK_SOFT: + CHECKSIZE(values, 2); values[0] = GetSourceSampleOffset(Source, Context, &srcclock); values[1] = srcclock.count(); return AL_TRUE; @@ -2066,15 +1989,17 @@ ALboolean GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, case AL_ROOM_ROLLOFF_FACTOR: case AL_CONE_OUTER_GAINHF: case AL_SOURCE_RADIUS: - if((err=GetSourcedv(Source, Context, prop, dvals)) != AL_FALSE) - *values = static_cast(dvals[0]); + CHECKSIZE(values, 1); + if((err=GetSourcedv(Source, Context, prop, {dvals, 1u})) != false) + values[0] = static_cast(dvals[0]); return err; /* 3x float/double */ case AL_POSITION: case AL_VELOCITY: case AL_DIRECTION: - if((err=GetSourcedv(Source, Context, prop, dvals)) != AL_FALSE) + CHECKSIZE(values, 3); + if((err=GetSourcedv(Source, Context, prop, {dvals, 3u})) != false) { values[0] = static_cast(dvals[0]); values[1] = static_cast(dvals[1]); @@ -2084,7 +2009,8 @@ ALboolean GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, /* 6x float/double */ case AL_ORIENTATION: - if((err=GetSourcedv(Source, Context, prop, dvals)) != AL_FALSE) + CHECKSIZE(values, 6); + if((err=GetSourcedv(Source, Context, prop, {dvals, 6u})) != false) { values[0] = static_cast(dvals[0]); values[1] = static_cast(dvals[1]); @@ -2109,20 +2035,23 @@ ALboolean GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, case AL_DISTANCE_MODEL: case AL_SOURCE_RESAMPLER_SOFT: case AL_SOURCE_SPATIALIZE_SOFT: - if((err=GetSourceiv(Source, Context, prop, ivals)) != AL_FALSE) - *values = ivals[0]; + CHECKSIZE(values, 1); + if((err=GetSourceiv(Source, Context, prop, {ivals, 1u})) != false) + values[0] = ivals[0]; return err; /* 1x uint */ case AL_BUFFER: case AL_DIRECT_FILTER: - if((err=GetSourceiv(Source, Context, prop, ivals)) != AL_FALSE) - *values = static_cast(ivals[0]); + CHECKSIZE(values, 1); + if((err=GetSourceiv(Source, Context, prop, {ivals, 1u})) != false) + values[0] = static_cast(ivals[0]); return err; /* 3x uint */ case AL_AUXILIARY_SEND_FILTER: - if((err=GetSourceiv(Source, Context, prop, ivals)) != AL_FALSE) + CHECKSIZE(values, 3); + if((err=GetSourceiv(Source, Context, prop, {ivals, 3u})) != false) { values[0] = static_cast(ivals[0]); values[1] = static_cast(ivals[1]); @@ -2139,7 +2068,7 @@ ALboolean GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, ERR("Unexpected property: 0x%04x\n", prop); Context->setError(AL_INVALID_ENUM, "Invalid source integer64 property 0x%04x", prop); - return AL_FALSE; + return false; } } // namespace @@ -2339,16 +2268,11 @@ START_API_FUNC context->setError(AL_INVALID_VALUE, "NULL pointer"); else { - const ALuint count = DoubleValsByProp(param); - if(count < 1 || count > 6) - context->setError(AL_INVALID_ENUM, "Invalid double-vector property 0x%04x", param); - else - { - ALfloat fvals[6]; - for(ALuint i{0};i < count;i++) - fvals[i] = static_cast(values[i]); - SetSourcefv(Source, context.get(), static_cast(param), {fvals, count}); - } + const ALuint count{DoubleValsByProp(param)}; + ALfloat fvals[6]; + for(ALuint i{0};i < count;i++) + fvals[i] = static_cast(values[i]); + SetSourcefv(Source, context.get(), static_cast(param), {fvals, count}); } } END_API_FUNC @@ -2474,12 +2398,10 @@ START_API_FUNC context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!value) context->setError(AL_INVALID_VALUE, "NULL pointer"); - else if(FloatValsByProp(param) != 1) - context->setError(AL_INVALID_ENUM, "Invalid float property 0x%04x", param); else { ALdouble dval; - if(GetSourcedv(Source, context.get(), static_cast(param), &dval)) + if(GetSourcedv(Source, context.get(), static_cast(param), {&dval, 1u})) *value = static_cast(dval); } } @@ -2497,8 +2419,6 @@ START_API_FUNC context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!(value1 && value2 && value3)) context->setError(AL_INVALID_VALUE, "NULL pointer"); - else if(FloatValsByProp(param) != 3) - context->setError(AL_INVALID_ENUM, "Invalid 3-float property 0x%04x", param); else { ALdouble dvals[3]; @@ -2526,17 +2446,12 @@ START_API_FUNC context->setError(AL_INVALID_VALUE, "NULL pointer"); else { - ALint count{FloatValsByProp(param)}; - if(count < 1 && count > 6) - context->setError(AL_INVALID_ENUM, "Invalid float-vector property 0x%04x", param); - else + const ALuint count{FloatValsByProp(param)}; + ALdouble dvals[6]; + if(GetSourcedv(Source, context.get(), static_cast(param), {dvals, count})) { - ALdouble dvals[6]; - if(GetSourcedv(Source, context.get(), static_cast(param), dvals)) - { - for(ALint i{0};i < count;i++) - values[i] = static_cast(dvals[i]); - } + for(ALuint i{0};i < count;i++) + values[i] = static_cast(dvals[i]); } } } @@ -2555,10 +2470,8 @@ START_API_FUNC context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!value) context->setError(AL_INVALID_VALUE, "NULL pointer"); - else if(DoubleValsByProp(param) != 1) - context->setError(AL_INVALID_ENUM, "Invalid double property 0x%04x", param); else - GetSourcedv(Source, context.get(), static_cast(param), value); + GetSourcedv(Source, context.get(), static_cast(param), {value, 1u}); } END_API_FUNC @@ -2574,8 +2487,6 @@ START_API_FUNC context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!(value1 && value2 && value3)) context->setError(AL_INVALID_VALUE, "NULL pointer"); - else if(DoubleValsByProp(param) != 3) - context->setError(AL_INVALID_ENUM, "Invalid 3-double property 0x%04x", param); else { ALdouble dvals[3]; @@ -2601,10 +2512,8 @@ START_API_FUNC context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); - else if(DoubleValsByProp(param) < 1) - context->setError(AL_INVALID_ENUM, "Invalid double-vector property 0x%04x", param); else - GetSourcedv(Source, context.get(), static_cast(param), values); + GetSourcedv(Source, context.get(), static_cast(param), {values, INT_MAX}); } END_API_FUNC @@ -2621,10 +2530,8 @@ START_API_FUNC context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!value) context->setError(AL_INVALID_VALUE, "NULL pointer"); - else if(IntValsByProp(param) != 1) - context->setError(AL_INVALID_ENUM, "Invalid integer property 0x%04x", param); else - GetSourceiv(Source, context.get(), static_cast(param), value); + GetSourceiv(Source, context.get(), static_cast(param), {value, 1u}); } END_API_FUNC @@ -2640,8 +2547,6 @@ START_API_FUNC context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!(value1 && value2 && value3)) context->setError(AL_INVALID_VALUE, "NULL pointer"); - else if(IntValsByProp(param) != 3) - context->setError(AL_INVALID_ENUM, "Invalid 3-integer property 0x%04x", param); else { ALint ivals[3]; @@ -2667,10 +2572,8 @@ START_API_FUNC context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); - else if(IntValsByProp(param) < 1) - context->setError(AL_INVALID_ENUM, "Invalid integer-vector property 0x%04x", param); else - GetSourceiv(Source, context.get(), static_cast(param), values); + GetSourceiv(Source, context.get(), static_cast(param), {values, INT_MAX}); } END_API_FUNC @@ -2687,10 +2590,8 @@ START_API_FUNC context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!value) context->setError(AL_INVALID_VALUE, "NULL pointer"); - else if(Int64ValsByProp(param) != 1) - context->setError(AL_INVALID_ENUM, "Invalid integer64 property 0x%04x", param); else - GetSourcei64v(Source, context.get(), static_cast(param), value); + GetSourcei64v(Source, context.get(), static_cast(param), {value, 1u}); } END_API_FUNC @@ -2706,8 +2607,6 @@ START_API_FUNC context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!(value1 && value2 && value3)) context->setError(AL_INVALID_VALUE, "NULL pointer"); - else if(Int64ValsByProp(param) != 3) - context->setError(AL_INVALID_ENUM, "Invalid 3-integer64 property 0x%04x", param); else { ALint64SOFT i64vals[3]; @@ -2733,10 +2632,8 @@ START_API_FUNC context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else if(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); - else if(Int64ValsByProp(param) < 1) - context->setError(AL_INVALID_ENUM, "Invalid integer64-vector property 0x%04x", param); else - GetSourcei64v(Source, context.get(), static_cast(param), values); + GetSourcei64v(Source, context.get(), static_cast(param), {values, INT_MAX}); } END_API_FUNC -- cgit v1.2.3 From 2fa2c35bdc2a09d5e856bb12ad6dff556bbe65a8 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 4 Aug 2019 11:59:14 -0700 Subject: Modify LIKELY and UNLIKELY to not need extra parenthesis --- al/auxeffectslot.cpp | 56 ++++----- al/buffer.cpp | 224 ++++++++++++++++++------------------ al/effect.cpp | 70 ++++++------ al/error.cpp | 2 +- al/event.cpp | 12 +- al/extension.cpp | 2 +- al/filter.cpp | 70 ++++++------ al/listener.cpp | 24 ++-- al/source.cpp | 268 ++++++++++++++++++++++---------------------- al/state.cpp | 46 ++++---- alc/alc.cpp | 2 +- alc/alu.cpp | 12 +- alc/backends/opensl.cpp | 2 +- alc/backends/pulseaudio.cpp | 22 ++-- alc/bformatdec.cpp | 4 +- alc/effects/pshifter.cpp | 4 +- alc/effects/reverb.cpp | 2 +- alc/helpers.cpp | 2 +- alc/logging.h | 8 +- alc/mastering.cpp | 2 +- alc/mixer/mixer_neon.cpp | 6 +- alc/mixer/mixer_sse.cpp | 6 +- alc/mixvoice.cpp | 16 +-- common/alexcpt.cpp | 2 +- common/alnumeric.h | 6 +- common/intrusive_ptr.h | 2 +- common/opthelpers.h | 4 +- 27 files changed, 428 insertions(+), 448 deletions(-) (limited to 'al/source.cpp') diff --git a/al/auxeffectslot.cpp b/al/auxeffectslot.cpp index 912765fc..e961874d 100644 --- a/al/auxeffectslot.cpp +++ b/al/auxeffectslot.cpp @@ -53,10 +53,10 @@ inline ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id) noexcept ALuint lidx = (id-1) >> 6; ALsizei slidx = (id-1) & 0x3f; - if(UNLIKELY(lidx >= context->mEffectSlotList.size())) + if UNLIKELY(lidx >= context->mEffectSlotList.size()) return nullptr; EffectSlotSubList &sublist{context->mEffectSlotList[lidx]}; - if(UNLIKELY(sublist.FreeMask & (1_u64 << slidx))) + if UNLIKELY(sublist.FreeMask & (1_u64 << slidx)) return nullptr; return sublist.EffectSlots + slidx; } @@ -66,10 +66,10 @@ inline ALeffect *LookupEffect(ALCdevice *device, ALuint id) noexcept ALuint lidx = (id-1) >> 6; ALsizei slidx = (id-1) & 0x3f; - if(UNLIKELY(lidx >= device->EffectList.size())) + if UNLIKELY(lidx >= device->EffectList.size()) return nullptr; EffectSubList &sublist = device->EffectList[lidx]; - if(UNLIKELY(sublist.FreeMask & (1_u64 << slidx))) + if UNLIKELY(sublist.FreeMask & (1_u64 << slidx)) return nullptr; return sublist.Effects + slidx; } @@ -104,7 +104,7 @@ void AddActiveEffectSlots(const ALuint *slotids, ALsizei count, ALCcontext *cont /* Reallocate newarray if the new size ended up smaller from duplicate * removal. */ - if(UNLIKELY(newcount < newarray->size())) + if UNLIKELY(newcount < newarray->size()) { curarray = newarray; newarray = ALeffectslot::CreatePtrArray(newcount); @@ -139,7 +139,7 @@ void RemoveActiveEffectSlots(const ALuint *slotids, ALsizei count, ALCcontext *c /* Reallocate with the new size. */ auto newsize = static_cast(std::distance(newarray->begin(), slotiter)); - if(LIKELY(newsize != newarray->size())) + if LIKELY(newsize != newarray->size()) { curarray = newarray; newarray = ALeffectslot::CreatePtrArray(newsize); @@ -174,7 +174,7 @@ ALeffectslot *AllocEffectSlot(ALCcontext *context) auto lidx = static_cast(std::distance(context->mEffectSlotList.begin(), sublist)); ALeffectslot *slot; ALsizei slidx; - if(LIKELY(sublist != context->mEffectSlotList.end())) + if LIKELY(sublist != context->mEffectSlotList.end()) { slidx = CTZ64(sublist->FreeMask); slot = sublist->EffectSlots + slidx; @@ -184,7 +184,7 @@ ALeffectslot *AllocEffectSlot(ALCcontext *context) /* Don't allocate so many list entries that the 32-bit ID could * overflow... */ - if(UNLIKELY(context->mEffectSlotList.size() >= 1<<25)) + if UNLIKELY(context->mEffectSlotList.size() >= 1<<25) { context->setError(AL_OUT_OF_MEMORY, "Too many effect slots allocated"); return nullptr; @@ -194,7 +194,7 @@ ALeffectslot *AllocEffectSlot(ALCcontext *context) sublist->FreeMask = ~0_u64; sublist->EffectSlots = static_cast(al_calloc(16, sizeof(ALeffectslot)*64)); - if(UNLIKELY(!sublist->EffectSlots)) + if UNLIKELY(!sublist->EffectSlots) { context->mEffectSlotList.pop_back(); context->setError(AL_OUT_OF_MEMORY, "Failed to allocate effect slot batch"); @@ -260,7 +260,7 @@ AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslo START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; if(n < 0) SETERR_RETURN(context, AL_INVALID_VALUE,, "Generating %d effect slots", n); @@ -303,7 +303,7 @@ AL_API ALvoid AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, const ALuint * START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; if(n < 0) SETERR_RETURN(context, AL_INVALID_VALUE,, "Deleting %d effect slots", n); @@ -347,7 +347,7 @@ AL_API ALboolean AL_APIENTRY alIsAuxiliaryEffectSlot(ALuint effectslot) START_API_FUNC { ContextRef context{GetContextRef()}; - if(LIKELY(context)) + if LIKELY(context) { std::lock_guard _{context->mEffectSlotLock}; if(LookupEffectSlot(context.get(), effectslot) != nullptr) @@ -362,12 +362,12 @@ AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSloti(ALuint effectslot, ALenum param START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mPropLock}; std::lock_guard __{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); - if(UNLIKELY(!slot)) + if UNLIKELY(!slot) SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); ALeffectslot *target{}; @@ -450,11 +450,11 @@ START_API_FUNC } ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); - if(UNLIKELY(!slot)) + if UNLIKELY(!slot) SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); switch(param) @@ -470,12 +470,12 @@ AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotf(ALuint effectslot, ALenum param START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mPropLock}; std::lock_guard __{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); - if(UNLIKELY(!slot)) + if UNLIKELY(!slot) SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); switch(param) @@ -505,11 +505,11 @@ START_API_FUNC } ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); - if(UNLIKELY(!slot)) + if UNLIKELY(!slot) SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); switch(param) @@ -526,11 +526,11 @@ AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSloti(ALuint effectslot, ALenum pa START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); - if(UNLIKELY(!slot)) + if UNLIKELY(!slot) SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); switch(param) @@ -562,11 +562,11 @@ START_API_FUNC } ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); - if(UNLIKELY(!slot)) + if UNLIKELY(!slot) SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); switch(param) @@ -582,11 +582,11 @@ AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotf(ALuint effectslot, ALenum pa START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); - if(UNLIKELY(!slot)) + if UNLIKELY(!slot) SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); switch(param) @@ -612,11 +612,11 @@ START_API_FUNC } ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mEffectSlotLock}; ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot); - if(UNLIKELY(!slot)) + if UNLIKELY(!slot) SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot); switch(param) diff --git a/al/buffer.cpp b/al/buffer.cpp index a068399c..df2496cb 100644 --- a/al/buffer.cpp +++ b/al/buffer.cpp @@ -256,7 +256,7 @@ ALbuffer *AllocBuffer(ALCcontext *context) auto lidx = static_cast(std::distance(device->BufferList.begin(), sublist)); ALbuffer *buffer{nullptr}; ALsizei slidx{0}; - if(LIKELY(sublist != device->BufferList.end())) + if LIKELY(sublist != device->BufferList.end()) { slidx = CTZ64(sublist->FreeMask); buffer = sublist->Buffers + slidx; @@ -266,7 +266,7 @@ ALbuffer *AllocBuffer(ALCcontext *context) /* Don't allocate so many list entries that the 32-bit ID could * overflow... */ - if(UNLIKELY(device->BufferList.size() >= 1<<25)) + if UNLIKELY(device->BufferList.size() >= 1<<25) { context->setError(AL_OUT_OF_MEMORY, "Too many buffers allocated"); return nullptr; @@ -275,7 +275,7 @@ ALbuffer *AllocBuffer(ALCcontext *context) sublist = device->BufferList.end() - 1; sublist->FreeMask = ~0_u64; sublist->Buffers = reinterpret_cast(al_calloc(16, sizeof(ALbuffer)*64)); - if(UNLIKELY(!sublist->Buffers)) + if UNLIKELY(!sublist->Buffers) { device->BufferList.pop_back(); context->setError(AL_OUT_OF_MEMORY, "Failed to allocate buffer batch"); @@ -311,10 +311,10 @@ inline ALbuffer *LookupBuffer(ALCdevice *device, ALuint id) ALuint lidx = (id-1) >> 6; ALsizei slidx = (id-1) & 0x3f; - if(UNLIKELY(lidx >= device->BufferList.size())) + if UNLIKELY(lidx >= device->BufferList.size()) return nullptr; BufferSubList &sublist = device->BufferList[lidx]; - if(UNLIKELY(sublist.FreeMask & (1_u64 << slidx))) + if UNLIKELY(sublist.FreeMask & (1_u64 << slidx)) return nullptr; return sublist.Buffers + slidx; } @@ -380,7 +380,7 @@ const ALchar *NameFromUserFmtType(UserFmtType type) */ void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALuint freq, ALsizei size, UserFmtChannels SrcChannels, UserFmtType SrcType, const al::byte *SrcData, ALbitfieldSOFT access) { - if(UNLIKELY(ReadRef(ALBuf->ref) != 0 || ALBuf->MappedAccess != 0)) + if UNLIKELY(ReadRef(ALBuf->ref) != 0 || ALBuf->MappedAccess != 0) SETERR_RETURN(context, AL_INVALID_OPERATION,, "Modifying storage for in-use buffer %u", ALBuf->id); @@ -398,8 +398,7 @@ void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALuint freq, ALsizei size, U case UserFmtBFormat2D: DstChannels = FmtBFormat2D; break; case UserFmtBFormat3D: DstChannels = FmtBFormat3D; break; } - if (UNLIKELY(static_cast(SrcChannels) != - static_cast(DstChannels))) + if UNLIKELY(static_cast(SrcChannels) != static_cast(DstChannels)) SETERR_RETURN(context, AL_INVALID_ENUM, , "Invalid format"); /* IMA4 and MSADPCM convert to 16-bit short. */ @@ -422,24 +421,23 @@ void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALuint freq, ALsizei size, U */ if((access&MAP_READ_WRITE_FLAGS)) { - if (UNLIKELY(static_cast(SrcType) != static_cast(DstType))) - SETERR_RETURN(context, AL_INVALID_VALUE, , - "%s samples cannot be mapped", - NameFromUserFmtType(SrcType)); + if UNLIKELY(static_cast(SrcType) != static_cast(DstType)) + SETERR_RETURN(context, AL_INVALID_VALUE,, "%s samples cannot be mapped", + NameFromUserFmtType(SrcType)); } const ALsizei unpackalign{ALBuf->UnpackAlign.load()}; const ALsizei align{SanitizeAlignment(SrcType, unpackalign)}; - if(UNLIKELY(align < 1)) + if UNLIKELY(align < 1) SETERR_RETURN(context, AL_INVALID_VALUE,, "Invalid unpack alignment %d for %s samples", - unpackalign, NameFromUserFmtType(SrcType)); + unpackalign, NameFromUserFmtType(SrcType)); if((access&AL_PRESERVE_DATA_BIT_SOFT)) { /* Can only preserve data with the same format and alignment. */ - if(UNLIKELY(ALBuf->mFmtChannels != DstChannels || ALBuf->OriginalType != SrcType)) + if UNLIKELY(ALBuf->mFmtChannels != DstChannels || ALBuf->OriginalType != SrcType) SETERR_RETURN(context, AL_INVALID_VALUE,, "Preserving data of mismatched format"); - if(UNLIKELY(ALBuf->OriginalAlign != align)) + if UNLIKELY(ALBuf->OriginalAlign != align) SETERR_RETURN(context, AL_INVALID_VALUE,, "Preserving data of mismatched alignment"); } @@ -451,12 +449,12 @@ void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALuint freq, ALsizei size, U (SrcType == UserFmtMSADPCM) ? ((align-2)/2 + 7) * ChannelsFromUserFmt(SrcChannels) : (align * FrameSizeFromUserFmt(SrcChannels, SrcType)) }; - if(UNLIKELY((size%SrcByteAlign) != 0)) + if UNLIKELY((size%SrcByteAlign) != 0) SETERR_RETURN(context, AL_INVALID_VALUE,, "Data size %d is not a multiple of frame size %d (%d unpack alignment)", size, SrcByteAlign, align); - if(UNLIKELY(size/SrcByteAlign > std::numeric_limits::max()/align)) + if UNLIKELY(size/SrcByteAlign > std::numeric_limits::max()/align) SETERR_RETURN(context, AL_OUT_OF_MEMORY,, "Buffer size overflow, %d blocks x %d samples per block", size/SrcByteAlign, align); const auto frames = static_cast(size / SrcByteAlign * align); @@ -466,7 +464,7 @@ void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALuint freq, ALsizei size, U */ ALsizei NumChannels{ChannelsFromFmt(DstChannels)}; ALsizei FrameSize{NumChannels * BytesFromFmt(DstType)}; - if(UNLIKELY(frames > std::numeric_limits::max()/FrameSize)) + if UNLIKELY(frames > std::numeric_limits::max()/FrameSize) SETERR_RETURN(context, AL_OUT_OF_MEMORY,, "Buffer size overflow, %d frames x %d bytes per frame", frames, FrameSize); size_t newsize{static_cast(frames) * FrameSize}; @@ -606,21 +604,19 @@ AL_API ALvoid AL_APIENTRY alGenBuffers(ALsizei n, ALuint *buffers) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; - if(UNLIKELY(n < 0)) - { + if UNLIKELY(n < 0) context->setError(AL_INVALID_VALUE, "Generating %d buffers", n); - return; - } + if UNLIKELY(n <= 0) return; - if(LIKELY(n == 1)) + if LIKELY(n == 1) { /* Special handling for the easy and normal case. */ ALbuffer *buffer = AllocBuffer(context.get()); if(buffer) buffers[0] = buffer->id; } - else if(n > 1) + else { /* Store the allocated buffer IDs in a separate local list, to avoid * modifying the user storage in case of failure. @@ -646,15 +642,11 @@ AL_API ALvoid AL_APIENTRY alDeleteBuffers(ALsizei n, const ALuint *buffers) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; - if(UNLIKELY(n < 0)) - { + if UNLIKELY(n < 0) context->setError(AL_INVALID_VALUE, "Deleting %d buffers", n); - return; - } - if(UNLIKELY(n == 0)) - return; + if UNLIKELY(n <= 0) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; @@ -666,12 +658,12 @@ START_API_FUNC { if(!bid) return false; ALbuffer *ALBuf = LookupBuffer(device, bid); - if(UNLIKELY(!ALBuf)) + if UNLIKELY(!ALBuf) { context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", bid); return true; } - if(UNLIKELY(ReadRef(ALBuf->ref) != 0)) + if UNLIKELY(ReadRef(ALBuf->ref) != 0) { context->setError(AL_INVALID_OPERATION, "Deleting in-use buffer %u", bid); return true; @@ -679,7 +671,7 @@ START_API_FUNC return false; } ); - if(LIKELY(invbuf == buffers_end)) + if LIKELY(invbuf == buffers_end) { /* All good. Delete non-0 buffer IDs. */ std::for_each(buffers, buffers_end, @@ -697,7 +689,7 @@ AL_API ALboolean AL_APIENTRY alIsBuffer(ALuint buffer) START_API_FUNC { ContextRef context{GetContextRef()}; - if(LIKELY(context)) + if LIKELY(context) { ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; @@ -718,28 +710,28 @@ AL_API void AL_APIENTRY alBufferStorageSOFT(ALuint buffer, ALenum format, const START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); - if(UNLIKELY(!albuf)) + if UNLIKELY(!albuf) context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); - else if(UNLIKELY(size < 0)) + else if UNLIKELY(size < 0) context->setError(AL_INVALID_VALUE, "Negative storage size %d", size); - else if(UNLIKELY(freq < 1)) + else if UNLIKELY(freq < 1) context->setError(AL_INVALID_VALUE, "Invalid sample rate %d", freq); - else if(UNLIKELY((flags&INVALID_STORAGE_MASK) != 0)) + else if UNLIKELY((flags&INVALID_STORAGE_MASK) != 0) context->setError(AL_INVALID_VALUE, "Invalid storage flags 0x%x", flags&INVALID_STORAGE_MASK); - else if(UNLIKELY((flags&AL_MAP_PERSISTENT_BIT_SOFT) && !(flags&MAP_READ_WRITE_FLAGS))) + else if UNLIKELY((flags&AL_MAP_PERSISTENT_BIT_SOFT) && !(flags&MAP_READ_WRITE_FLAGS)) context->setError(AL_INVALID_VALUE, "Declaring persistently mapped storage without read or write access"); else { auto usrfmt = DecomposeUserFormat(format); - if(UNLIKELY(!usrfmt)) + if UNLIKELY(!usrfmt) context->setError(AL_INVALID_ENUM, "Invalid format 0x%04x", format); else LoadData(context.get(), albuf, freq, size, usrfmt->channels, usrfmt->type, @@ -752,38 +744,38 @@ AL_API void* AL_APIENTRY alMapBufferSOFT(ALuint buffer, ALsizei offset, ALsizei START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return nullptr; + if UNLIKELY(!context) return nullptr; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); - if(UNLIKELY(!albuf)) + if UNLIKELY(!albuf) context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); - else if(UNLIKELY((access&INVALID_MAP_FLAGS) != 0)) + else if UNLIKELY((access&INVALID_MAP_FLAGS) != 0) context->setError(AL_INVALID_VALUE, "Invalid map flags 0x%x", access&INVALID_MAP_FLAGS); - else if(UNLIKELY(!(access&MAP_READ_WRITE_FLAGS))) + else if UNLIKELY(!(access&MAP_READ_WRITE_FLAGS)) context->setError(AL_INVALID_VALUE, "Mapping buffer %u without read or write access", buffer); else { ALbitfieldSOFT unavailable = (albuf->Access^access) & access; - if(UNLIKELY(ReadRef(albuf->ref) != 0 && !(access&AL_MAP_PERSISTENT_BIT_SOFT))) + if UNLIKELY(ReadRef(albuf->ref) != 0 && !(access&AL_MAP_PERSISTENT_BIT_SOFT)) context->setError(AL_INVALID_OPERATION, "Mapping in-use buffer %u without persistent mapping", buffer); - else if(UNLIKELY(albuf->MappedAccess != 0)) + else if UNLIKELY(albuf->MappedAccess != 0) context->setError(AL_INVALID_OPERATION, "Mapping already-mapped buffer %u", buffer); - else if(UNLIKELY((unavailable&AL_MAP_READ_BIT_SOFT))) + else if UNLIKELY((unavailable&AL_MAP_READ_BIT_SOFT)) context->setError(AL_INVALID_VALUE, "Mapping buffer %u for reading without read access", buffer); - else if(UNLIKELY((unavailable&AL_MAP_WRITE_BIT_SOFT))) + else if UNLIKELY((unavailable&AL_MAP_WRITE_BIT_SOFT)) context->setError(AL_INVALID_VALUE, "Mapping buffer %u for writing without write access", buffer); - else if(UNLIKELY((unavailable&AL_MAP_PERSISTENT_BIT_SOFT))) + else if UNLIKELY((unavailable&AL_MAP_PERSISTENT_BIT_SOFT)) context->setError(AL_INVALID_VALUE, "Mapping buffer %u persistently without persistent access", buffer); - else if(UNLIKELY(offset < 0 || offset >= albuf->OriginalSize || - length <= 0 || length > albuf->OriginalSize - offset)) + else if UNLIKELY(offset < 0 || offset >= albuf->OriginalSize || + length <= 0 || length > albuf->OriginalSize - offset) context->setError(AL_INVALID_VALUE, "Mapping invalid range %d+%d for buffer %u", offset, length, buffer); else @@ -804,15 +796,15 @@ AL_API void AL_APIENTRY alUnmapBufferSOFT(ALuint buffer) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); - if(UNLIKELY(!albuf)) + if UNLIKELY(!albuf) context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); - else if(albuf->MappedAccess == 0) + else if UNLIKELY(albuf->MappedAccess == 0) context->setError(AL_INVALID_OPERATION, "Unmapping unmapped buffer %u", buffer); else { @@ -827,20 +819,20 @@ AL_API void AL_APIENTRY alFlushMappedBufferSOFT(ALuint buffer, ALsizei offset, A START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); - if(UNLIKELY(!albuf)) + if UNLIKELY(!albuf) context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); - else if(UNLIKELY(!(albuf->MappedAccess&AL_MAP_WRITE_BIT_SOFT))) + else if UNLIKELY(!(albuf->MappedAccess&AL_MAP_WRITE_BIT_SOFT)) context->setError(AL_INVALID_OPERATION, "Flushing buffer %u while not mapped for writing", buffer); - else if(UNLIKELY(offset < albuf->MappedOffset || + else if UNLIKELY(offset < albuf->MappedOffset || offset >= albuf->MappedOffset+albuf->MappedSize || - length <= 0 || length > albuf->MappedOffset+albuf->MappedSize-offset)) + length <= 0 || length > albuf->MappedOffset+albuf->MappedSize-offset) context->setError(AL_INVALID_VALUE, "Flushing invalid range %d+%d on buffer %u", offset, length, buffer); else @@ -859,20 +851,20 @@ AL_API ALvoid AL_APIENTRY alBufferSubDataSOFT(ALuint buffer, ALenum format, cons START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); - if(UNLIKELY(!albuf)) + if UNLIKELY(!albuf) { context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); return; } auto usrfmt = DecomposeUserFormat(format); - if(UNLIKELY(!usrfmt)) + if UNLIKELY(!usrfmt) { context->setError(AL_INVALID_ENUM, "Invalid format 0x%04x", format); return; @@ -880,16 +872,16 @@ START_API_FUNC ALsizei unpack_align{albuf->UnpackAlign.load()}; ALsizei align{SanitizeAlignment(usrfmt->type, unpack_align)}; - if(UNLIKELY(align < 1)) + if UNLIKELY(align < 1) context->setError(AL_INVALID_VALUE, "Invalid unpack alignment %d", unpack_align); - else if(UNLIKELY(long{usrfmt->channels} != long{albuf->mFmtChannels} || - usrfmt->type != albuf->OriginalType)) + else if UNLIKELY(long{usrfmt->channels} != long{albuf->mFmtChannels} || + usrfmt->type != albuf->OriginalType) context->setError(AL_INVALID_ENUM, "Unpacking data with mismatched format"); - else if(UNLIKELY(align != albuf->OriginalAlign)) + else if UNLIKELY(align != albuf->OriginalAlign) context->setError(AL_INVALID_VALUE, "Unpacking data with alignment %u does not match original alignment %u", align, albuf->OriginalAlign); - else if(UNLIKELY(albuf->MappedAccess != 0)) + else if UNLIKELY(albuf->MappedAccess != 0) context->setError(AL_INVALID_OPERATION, "Unpacking data into mapped buffer %u", buffer); else { @@ -901,15 +893,15 @@ START_API_FUNC (align * frame_size) }; - if(UNLIKELY(offset < 0 || length < 0 || offset > albuf->OriginalSize || - length > albuf->OriginalSize-offset)) + if UNLIKELY(offset < 0 || length < 0 || offset > albuf->OriginalSize || + length > albuf->OriginalSize-offset) context->setError(AL_INVALID_VALUE, "Invalid data sub-range %d+%d on buffer %u", offset, length, buffer); - else if(UNLIKELY((offset%byte_align) != 0)) + else if UNLIKELY((offset%byte_align) != 0) context->setError(AL_INVALID_VALUE, "Sub-range offset %d is not a multiple of frame size %d (%d unpack alignment)", offset, byte_align, align); - else if(UNLIKELY((length%byte_align) != 0)) + else if UNLIKELY((length%byte_align) != 0) context->setError(AL_INVALID_VALUE, "Sub-range length %d is not a multiple of frame size %d (%d unpack alignment)", length, byte_align, align); @@ -943,7 +935,7 @@ AL_API void AL_APIENTRY alBufferSamplesSOFT(ALuint /*buffer*/, ALuint /*samplera START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; context->setError(AL_INVALID_OPERATION, "alBufferSamplesSOFT not supported"); } @@ -954,7 +946,7 @@ AL_API void AL_APIENTRY alBufferSubSamplesSOFT(ALuint /*buffer*/, ALsizei /*offs START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; context->setError(AL_INVALID_OPERATION, "alBufferSubSamplesSOFT not supported"); } @@ -965,7 +957,7 @@ AL_API void AL_APIENTRY alGetBufferSamplesSOFT(ALuint /*buffer*/, ALsizei /*offs START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; context->setError(AL_INVALID_OPERATION, "alGetBufferSamplesSOFT not supported"); } @@ -975,7 +967,7 @@ AL_API ALboolean AL_APIENTRY alIsBufferFormatSupportedSOFT(ALenum /*format*/) START_API_FUNC { ContextRef context{GetContextRef()}; - if(!context) return AL_FALSE; + if UNLIKELY(!context) return AL_FALSE; context->setError(AL_INVALID_OPERATION, "alIsBufferFormatSupportedSOFT not supported"); return AL_FALSE; @@ -987,12 +979,12 @@ AL_API void AL_APIENTRY alBufferf(ALuint buffer, ALenum param, ALfloat /*value*/ START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; - if(UNLIKELY(LookupBuffer(device, buffer) == nullptr)) + if UNLIKELY(LookupBuffer(device, buffer) == nullptr) context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); else switch(param) { @@ -1007,12 +999,12 @@ AL_API void AL_APIENTRY alBuffer3f(ALuint buffer, ALenum param, START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; - if(UNLIKELY(LookupBuffer(device, buffer) == nullptr)) + if UNLIKELY(LookupBuffer(device, buffer) == nullptr) context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); else switch(param) { @@ -1026,14 +1018,14 @@ AL_API void AL_APIENTRY alBufferfv(ALuint buffer, ALenum param, const ALfloat *v START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; - if(UNLIKELY(LookupBuffer(device, buffer) == nullptr)) + if UNLIKELY(LookupBuffer(device, buffer) == nullptr) context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); - else if(UNLIKELY(!values)) + else if UNLIKELY(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(param) { @@ -1048,25 +1040,25 @@ AL_API void AL_APIENTRY alBufferi(ALuint buffer, ALenum param, ALint value) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); - if(UNLIKELY(!albuf)) + if UNLIKELY(!albuf) context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); else switch(param) { case AL_UNPACK_BLOCK_ALIGNMENT_SOFT: - if(UNLIKELY(value < 0)) + if UNLIKELY(value < 0) context->setError(AL_INVALID_VALUE, "Invalid unpack block alignment %d", value); else albuf->UnpackAlign.store(value); break; case AL_PACK_BLOCK_ALIGNMENT_SOFT: - if(UNLIKELY(value < 0)) + if UNLIKELY(value < 0) context->setError(AL_INVALID_VALUE, "Invalid pack block alignment %d", value); else albuf->PackAlign.store(value); @@ -1083,12 +1075,12 @@ AL_API void AL_APIENTRY alBuffer3i(ALuint buffer, ALenum param, START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; - if(UNLIKELY(LookupBuffer(device, buffer) == nullptr)) + if UNLIKELY(LookupBuffer(device, buffer) == nullptr) context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); else switch(param) { @@ -1113,24 +1105,24 @@ START_API_FUNC } ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); - if(UNLIKELY(!albuf)) + if UNLIKELY(!albuf) context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); - else if(UNLIKELY(!values)) + else if UNLIKELY(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(param) { case AL_LOOP_POINTS_SOFT: - if(UNLIKELY(ReadRef(albuf->ref) != 0)) + if UNLIKELY(ReadRef(albuf->ref) != 0) context->setError(AL_INVALID_OPERATION, "Modifying in-use buffer %u's loop points", buffer); - else if(UNLIKELY(values[0] < 0 || values[0] >= values[1] || - static_cast(values[1]) > albuf->SampleLen)) + else if UNLIKELY(values[0] < 0 || values[0] >= values[1] || + static_cast(values[1]) > albuf->SampleLen) context->setError(AL_INVALID_VALUE, "Invalid loop point range %d -> %d on buffer %u", values[0], values[1], buffer); else @@ -1151,15 +1143,15 @@ AL_API ALvoid AL_APIENTRY alGetBufferf(ALuint buffer, ALenum param, ALfloat *val START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); - if(UNLIKELY(!albuf)) + if UNLIKELY(!albuf) context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); - else if(UNLIKELY(!value)) + else if UNLIKELY(!value) context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(param) { @@ -1173,14 +1165,14 @@ AL_API void AL_APIENTRY alGetBuffer3f(ALuint buffer, ALenum param, ALfloat *valu START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; - if(UNLIKELY(LookupBuffer(device, buffer) == nullptr)) + if UNLIKELY(LookupBuffer(device, buffer) == nullptr) context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); - else if(UNLIKELY(!value1 || !value2 || !value3)) + else if UNLIKELY(!value1 || !value2 || !value3) context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(param) { @@ -1201,14 +1193,14 @@ START_API_FUNC } ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; - if(UNLIKELY(LookupBuffer(device, buffer) == nullptr)) + if UNLIKELY(LookupBuffer(device, buffer) == nullptr) context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); - else if(UNLIKELY(!values)) + else if UNLIKELY(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(param) { @@ -1223,14 +1215,14 @@ AL_API ALvoid AL_APIENTRY alGetBufferi(ALuint buffer, ALenum param, ALint *value START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); - if(UNLIKELY(!albuf)) + if UNLIKELY(!albuf) context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); - else if(UNLIKELY(!value)) + else if UNLIKELY(!value) context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(param) { @@ -1268,13 +1260,13 @@ AL_API void AL_APIENTRY alGetBuffer3i(ALuint buffer, ALenum param, ALint *value1 START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; - if(UNLIKELY(LookupBuffer(device, buffer) == nullptr)) + if UNLIKELY(LookupBuffer(device, buffer) == nullptr) context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); - else if(UNLIKELY(!value1 || !value2 || !value3)) + else if UNLIKELY(!value1 || !value2 || !value3) context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(param) { @@ -1303,14 +1295,14 @@ START_API_FUNC } ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->BufferLock}; ALbuffer *albuf = LookupBuffer(device, buffer); - if(UNLIKELY(!albuf)) + if UNLIKELY(!albuf) context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", buffer); - else if(UNLIKELY(!values)) + else if UNLIKELY(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); else switch(param) { diff --git a/al/effect.cpp b/al/effect.cpp index 15200a88..e5571be0 100644 --- a/al/effect.cpp +++ b/al/effect.cpp @@ -148,7 +148,7 @@ ALeffect *AllocEffect(ALCcontext *context) auto lidx = static_cast(std::distance(device->EffectList.begin(), sublist)); ALeffect *effect{nullptr}; ALsizei slidx{0}; - if(LIKELY(sublist != device->EffectList.end())) + if LIKELY(sublist != device->EffectList.end()) { slidx = CTZ64(sublist->FreeMask); effect = sublist->Effects + slidx; @@ -158,7 +158,7 @@ ALeffect *AllocEffect(ALCcontext *context) /* Don't allocate so many list entries that the 32-bit ID could * overflow... */ - if(UNLIKELY(device->EffectList.size() >= 1<<25)) + if UNLIKELY(device->EffectList.size() >= 1<<25) { context->setError(AL_OUT_OF_MEMORY, "Too many effects allocated"); return nullptr; @@ -167,7 +167,7 @@ ALeffect *AllocEffect(ALCcontext *context) sublist = device->EffectList.end() - 1; sublist->FreeMask = ~0_u64; sublist->Effects = static_cast(al_calloc(16, sizeof(ALeffect)*64)); - if(UNLIKELY(!sublist->Effects)) + if UNLIKELY(!sublist->Effects) { device->EffectList.pop_back(); context->setError(AL_OUT_OF_MEMORY, "Failed to allocate effect batch"); @@ -205,10 +205,10 @@ inline ALeffect *LookupEffect(ALCdevice *device, ALuint id) ALuint lidx = (id-1) >> 6; ALsizei slidx = (id-1) & 0x3f; - if(UNLIKELY(lidx >= device->EffectList.size())) + if UNLIKELY(lidx >= device->EffectList.size()) return nullptr; EffectSubList &sublist = device->EffectList[lidx]; - if(UNLIKELY(sublist.FreeMask & (1_u64 << slidx))) + if UNLIKELY(sublist.FreeMask & (1_u64 << slidx)) return nullptr; return sublist.Effects + slidx; } @@ -219,21 +219,19 @@ AL_API ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; - if(UNLIKELY(n < 0)) - { + if UNLIKELY(n < 0) context->setError(AL_INVALID_VALUE, "Generating %d effects", n); - return; - } + if UNLIKELY(n <= 0) return; - if(LIKELY(n == 1)) + if LIKELY(n == 1) { /* Special handling for the easy and normal case. */ ALeffect *effect = AllocEffect(context.get()); if(effect) effects[0] = effect->id; } - else if(n > 1) + else { /* Store the allocated buffer IDs in a separate local list, to avoid * modifying the user storage in case of failure. @@ -259,15 +257,11 @@ AL_API ALvoid AL_APIENTRY alDeleteEffects(ALsizei n, const ALuint *effects) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; - if(UNLIKELY(n < 0)) - { + if UNLIKELY(n < 0) context->setError(AL_INVALID_VALUE, "Deleting %d effects", n); - return; - } - if(UNLIKELY(n == 0)) - return; + if UNLIKELY(n <= 0) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->EffectLock}; @@ -279,7 +273,7 @@ START_API_FUNC { if(!eid) return false; ALeffect *effect{LookupEffect(device, eid)}; - if(UNLIKELY(!effect)) + if UNLIKELY(!effect) { context->setError(AL_INVALID_NAME, "Invalid effect ID %u", eid); return true; @@ -287,7 +281,7 @@ START_API_FUNC return false; } ); - if(LIKELY(inveffect == effects_end)) + if LIKELY(inveffect == effects_end) { /* All good. Delete non-0 effect IDs. */ std::for_each(effects, effects_end, @@ -305,7 +299,7 @@ AL_API ALboolean AL_APIENTRY alIsEffect(ALuint effect) START_API_FUNC { ContextRef context{GetContextRef()}; - if(LIKELY(context)) + if LIKELY(context) { ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->EffectLock}; @@ -320,13 +314,13 @@ AL_API ALvoid AL_APIENTRY alEffecti(ALuint effect, ALenum param, ALint value) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->EffectLock}; ALeffect *aleffect{LookupEffect(device, effect)}; - if(UNLIKELY(!aleffect)) + if UNLIKELY(!aleffect) context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect); else { @@ -370,13 +364,13 @@ START_API_FUNC } ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->EffectLock}; ALeffect *aleffect{LookupEffect(device, effect)}; - if(UNLIKELY(!aleffect)) + if UNLIKELY(!aleffect) context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect); else { @@ -390,13 +384,13 @@ AL_API ALvoid AL_APIENTRY alEffectf(ALuint effect, ALenum param, ALfloat value) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->EffectLock}; ALeffect *aleffect{LookupEffect(device, effect)}; - if(UNLIKELY(!aleffect)) + if UNLIKELY(!aleffect) context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect); else { @@ -410,13 +404,13 @@ AL_API ALvoid AL_APIENTRY alEffectfv(ALuint effect, ALenum param, const ALfloat START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->EffectLock}; ALeffect *aleffect{LookupEffect(device, effect)}; - if(UNLIKELY(!aleffect)) + if UNLIKELY(!aleffect) context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect); else { @@ -430,13 +424,13 @@ AL_API ALvoid AL_APIENTRY alGetEffecti(ALuint effect, ALenum param, ALint *value START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->EffectLock}; const ALeffect *aleffect{LookupEffect(device, effect)}; - if(UNLIKELY(!aleffect)) + if UNLIKELY(!aleffect) context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect); else { @@ -462,13 +456,13 @@ START_API_FUNC } ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->EffectLock}; const ALeffect *aleffect{LookupEffect(device, effect)}; - if(UNLIKELY(!aleffect)) + if UNLIKELY(!aleffect) context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect); else { @@ -482,13 +476,13 @@ AL_API ALvoid AL_APIENTRY alGetEffectf(ALuint effect, ALenum param, ALfloat *val START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->EffectLock}; const ALeffect *aleffect{LookupEffect(device, effect)}; - if(UNLIKELY(!aleffect)) + if UNLIKELY(!aleffect) context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect); else { @@ -502,13 +496,13 @@ AL_API ALvoid AL_APIENTRY alGetEffectfv(ALuint effect, ALenum param, ALfloat *va START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->EffectLock}; const ALeffect *aleffect{LookupEffect(device, effect)}; - if(UNLIKELY(!aleffect)) + if UNLIKELY(!aleffect) context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect); else { diff --git a/al/error.cpp b/al/error.cpp index 8bd78fe2..a7080493 100644 --- a/al/error.cpp +++ b/al/error.cpp @@ -94,7 +94,7 @@ AL_API ALenum AL_APIENTRY alGetError(void) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) + if UNLIKELY(!context) { constexpr ALenum deferror{AL_INVALID_OPERATION}; WARN("Querying error state on null context (implicitly 0x%04x)\n", deferror); diff --git a/al/event.cpp b/al/event.cpp index 06a2e008..530f9679 100644 --- a/al/event.cpp +++ b/al/event.cpp @@ -32,7 +32,7 @@ static int EventThread(ALCcontext *context) { RingBuffer *ring{context->mAsyncEvents.get()}; bool quitnow{false}; - while(LIKELY(!quitnow)) + while LIKELY(!quitnow) { auto evt_data = ring->getReadVector().first; if(evt_data.len == 0) @@ -60,7 +60,7 @@ static int EventThread(ALCcontext *context) } _{evt, ring}; quitnow = evt.EnumType == EventType_KillThread; - if(UNLIKELY(quitnow)) break; + if UNLIKELY(quitnow) break; if(evt.EnumType == EventType_ReleaseEffectState) { @@ -141,10 +141,10 @@ AL_API void AL_APIENTRY alEventControlSOFT(ALsizei count, const ALenum *types, A START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; - if(count < 0) SETERR_RETURN(context, AL_INVALID_VALUE,, "Controlling %d events", count); - if(count == 0) return; + if(count < 0) context->setError(AL_INVALID_VALUE, "Controlling %d events", count); + if(count <= 0) return; if(!types) SETERR_RETURN(context, AL_INVALID_VALUE,, "NULL pointer"); ALbitfieldSOFT flags{0}; @@ -202,7 +202,7 @@ AL_API void AL_APIENTRY alEventCallbackSOFT(ALEVENTPROCSOFT callback, void *user START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mPropLock}; std::lock_guard __{context->mEventCbLock}; diff --git a/al/extension.cpp b/al/extension.cpp index 1b36e3db..ab759262 100644 --- a/al/extension.cpp +++ b/al/extension.cpp @@ -36,7 +36,7 @@ AL_API ALboolean AL_APIENTRY alIsExtensionPresent(const ALchar *extName) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return AL_FALSE; + if UNLIKELY(!context) return AL_FALSE; if(!extName) SETERR_RETURN(context, AL_INVALID_VALUE, AL_FALSE, "NULL pointer"); diff --git a/al/filter.cpp b/al/filter.cpp index b52267f1..41a96513 100644 --- a/al/filter.cpp +++ b/al/filter.cpp @@ -288,7 +288,7 @@ ALfilter *AllocFilter(ALCcontext *context) auto lidx = static_cast(std::distance(device->FilterList.begin(), sublist)); ALfilter *filter{nullptr}; ALsizei slidx{0}; - if(LIKELY(sublist != device->FilterList.end())) + if LIKELY(sublist != device->FilterList.end()) { slidx = CTZ64(sublist->FreeMask); filter = sublist->Filters + slidx; @@ -298,7 +298,7 @@ ALfilter *AllocFilter(ALCcontext *context) /* Don't allocate so many list entries that the 32-bit ID could * overflow... */ - if(UNLIKELY(device->FilterList.size() >= 1<<25)) + if UNLIKELY(device->FilterList.size() >= 1<<25) { context->setError(AL_OUT_OF_MEMORY, "Too many filters allocated"); return nullptr; @@ -307,7 +307,7 @@ ALfilter *AllocFilter(ALCcontext *context) sublist = device->FilterList.end() - 1; sublist->FreeMask = ~0_u64; sublist->Filters = static_cast(al_calloc(16, sizeof(ALfilter)*64)); - if(UNLIKELY(!sublist->Filters)) + if UNLIKELY(!sublist->Filters) { device->FilterList.pop_back(); context->setError(AL_OUT_OF_MEMORY, "Failed to allocate filter batch"); @@ -346,10 +346,10 @@ inline ALfilter *LookupFilter(ALCdevice *device, ALuint id) ALuint lidx = (id-1) >> 6; ALsizei slidx = (id-1) & 0x3f; - if(UNLIKELY(lidx >= device->FilterList.size())) + if UNLIKELY(lidx >= device->FilterList.size()) return nullptr; FilterSubList &sublist = device->FilterList[lidx]; - if(UNLIKELY(sublist.FreeMask & (1_u64 << slidx))) + if UNLIKELY(sublist.FreeMask & (1_u64 << slidx)) return nullptr; return sublist.Filters + slidx; } @@ -360,21 +360,19 @@ AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; - if(UNLIKELY(n < 0)) - { + if UNLIKELY(n < 0) context->setError(AL_INVALID_VALUE, "Generating %d filters", n); - return; - } + if UNLIKELY(n <= 0) return; - if(LIKELY(n == 1)) + if LIKELY(n == 1) { /* Special handling for the easy and normal case. */ ALfilter *filter = AllocFilter(context.get()); if(filter) filters[0] = filter->id; } - else if(n > 1) + else { /* Store the allocated buffer IDs in a separate local list, to avoid * modifying the user storage in case of failure. @@ -400,15 +398,11 @@ AL_API ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, const ALuint *filters) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; - if(UNLIKELY(n < 0)) - { + if UNLIKELY(n < 0) context->setError(AL_INVALID_VALUE, "Deleting %d filters", n); - return; - } - if(UNLIKELY(n == 0)) - return; + if UNLIKELY(n <= 0) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->FilterLock}; @@ -420,7 +414,7 @@ START_API_FUNC { if(!fid) return false; ALfilter *filter{LookupFilter(device, fid)}; - if(UNLIKELY(!filter)) + if UNLIKELY(!filter) { context->setError(AL_INVALID_NAME, "Invalid filter ID %u", fid); return true; @@ -428,7 +422,7 @@ START_API_FUNC return false; } ); - if(LIKELY(invflt == filters_end)) + if LIKELY(invflt == filters_end) { /* All good. Delete non-0 filter IDs. */ std::for_each(filters, filters_end, @@ -446,7 +440,7 @@ AL_API ALboolean AL_APIENTRY alIsFilter(ALuint filter) START_API_FUNC { ContextRef context{GetContextRef()}; - if(LIKELY(context)) + if LIKELY(context) { ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->FilterLock}; @@ -462,13 +456,13 @@ AL_API ALvoid AL_APIENTRY alFilteri(ALuint filter, ALenum param, ALint value) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->FilterLock}; ALfilter *alfilt{LookupFilter(device, filter)}; - if(UNLIKELY(!alfilt)) + if UNLIKELY(!alfilt) context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); else { @@ -500,13 +494,13 @@ START_API_FUNC } ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->FilterLock}; ALfilter *alfilt{LookupFilter(device, filter)}; - if(UNLIKELY(!alfilt)) + if UNLIKELY(!alfilt) context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); else { @@ -520,13 +514,13 @@ AL_API ALvoid AL_APIENTRY alFilterf(ALuint filter, ALenum param, ALfloat value) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->FilterLock}; ALfilter *alfilt{LookupFilter(device, filter)}; - if(UNLIKELY(!alfilt)) + if UNLIKELY(!alfilt) context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); else { @@ -540,13 +534,13 @@ AL_API ALvoid AL_APIENTRY alFilterfv(ALuint filter, ALenum param, const ALfloat START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->FilterLock}; ALfilter *alfilt{LookupFilter(device, filter)}; - if(UNLIKELY(!alfilt)) + if UNLIKELY(!alfilt) context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); else { @@ -560,13 +554,13 @@ AL_API ALvoid AL_APIENTRY alGetFilteri(ALuint filter, ALenum param, ALint *value START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->FilterLock}; ALfilter *alfilt{LookupFilter(device, filter)}; - if(UNLIKELY(!alfilt)) + if UNLIKELY(!alfilt) context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); else { @@ -592,13 +586,13 @@ START_API_FUNC } ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->FilterLock}; ALfilter *alfilt{LookupFilter(device, filter)}; - if(UNLIKELY(!alfilt)) + if UNLIKELY(!alfilt) context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); else { @@ -612,13 +606,13 @@ AL_API ALvoid AL_APIENTRY alGetFilterf(ALuint filter, ALenum param, ALfloat *val START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->FilterLock}; ALfilter *alfilt{LookupFilter(device, filter)}; - if(UNLIKELY(!alfilt)) + if UNLIKELY(!alfilt) context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); else { @@ -632,13 +626,13 @@ AL_API ALvoid AL_APIENTRY alGetFilterfv(ALuint filter, ALenum param, ALfloat *va START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALCdevice *device{context->mDevice.get()}; std::lock_guard _{device->FilterLock}; ALfilter *alfilt{LookupFilter(device, filter)}; - if(UNLIKELY(!alfilt)) + if UNLIKELY(!alfilt) context->setError(AL_INVALID_NAME, "Invalid filter ID %u", filter); else { diff --git a/al/listener.cpp b/al/listener.cpp index 3a1f32a4..aebf2aa5 100644 --- a/al/listener.cpp +++ b/al/listener.cpp @@ -46,7 +46,7 @@ AL_API ALvoid AL_APIENTRY alListenerf(ALenum param, ALfloat value) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALlistener &listener = context->mListener; std::lock_guard _{context->mPropLock}; @@ -79,7 +79,7 @@ AL_API ALvoid AL_APIENTRY alListener3f(ALenum param, ALfloat value1, ALfloat val START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALlistener &listener = context->mListener; std::lock_guard _{context->mPropLock}; @@ -129,7 +129,7 @@ START_API_FUNC } ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALlistener &listener = context->mListener; std::lock_guard _{context->mPropLock}; @@ -161,7 +161,7 @@ AL_API ALvoid AL_APIENTRY alListeneri(ALenum param, ALint /*value*/) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mPropLock}; switch(param) @@ -184,7 +184,7 @@ START_API_FUNC } ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mPropLock}; switch(param) @@ -221,7 +221,7 @@ START_API_FUNC } ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mPropLock}; if(!values) @@ -239,7 +239,7 @@ AL_API ALvoid AL_APIENTRY alGetListenerf(ALenum param, ALfloat *value) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALlistener &listener = context->mListener; std::lock_guard _{context->mPropLock}; @@ -265,7 +265,7 @@ AL_API ALvoid AL_APIENTRY alGetListener3f(ALenum param, ALfloat *value1, ALfloat START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALlistener &listener = context->mListener; std::lock_guard _{context->mPropLock}; @@ -308,7 +308,7 @@ START_API_FUNC } ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALlistener &listener = context->mListener; std::lock_guard _{context->mPropLock}; @@ -337,7 +337,7 @@ AL_API ALvoid AL_APIENTRY alGetListeneri(ALenum param, ALint *value) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mPropLock}; if(!value) @@ -354,7 +354,7 @@ AL_API void AL_APIENTRY alGetListener3i(ALenum param, ALint *value1, ALint *valu START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALlistener &listener = context->mListener; std::lock_guard _{context->mPropLock}; @@ -392,7 +392,7 @@ START_API_FUNC } ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; ALlistener &listener = context->mListener; std::lock_guard _{context->mPropLock}; diff --git a/al/source.cpp b/al/source.cpp index 69bdf6b5..9273a7a8 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -497,7 +497,7 @@ ALsource *AllocSource(ALCcontext *context) auto lidx = static_cast(std::distance(context->mSourceList.begin(), sublist)); ALsource *source; ALsizei slidx; - if(LIKELY(sublist != context->mSourceList.end())) + if LIKELY(sublist != context->mSourceList.end()) { slidx = CTZ64(sublist->FreeMask); source = sublist->Sources + slidx; @@ -507,7 +507,7 @@ ALsource *AllocSource(ALCcontext *context) /* Don't allocate so many list entries that the 32-bit ID could * overflow... */ - if(UNLIKELY(context->mSourceList.size() >= 1<<25)) + if UNLIKELY(context->mSourceList.size() >= 1<<25) { context->setError(AL_OUT_OF_MEMORY, "Too many sources allocated"); return nullptr; @@ -517,7 +517,7 @@ ALsource *AllocSource(ALCcontext *context) sublist->FreeMask = ~0_u64; sublist->Sources = static_cast(al_calloc(16, sizeof(ALsource)*64)); - if(UNLIKELY(!sublist->Sources)) + if UNLIKELY(!sublist->Sources) { context->mSourceList.pop_back(); context->setError(AL_OUT_OF_MEMORY, "Failed to allocate source batch"); @@ -574,10 +574,10 @@ inline ALsource *LookupSource(ALCcontext *context, ALuint id) noexcept ALuint lidx = (id-1) >> 6; ALsizei slidx = (id-1) & 0x3f; - if(UNLIKELY(lidx >= context->mSourceList.size())) + if UNLIKELY(lidx >= context->mSourceList.size()) return nullptr; SourceSubList &sublist{context->mSourceList[lidx]}; - if(UNLIKELY(sublist.FreeMask & (1_u64 << slidx))) + if UNLIKELY(sublist.FreeMask & (1_u64 << slidx)) return nullptr; return sublist.Sources + slidx; } @@ -587,10 +587,10 @@ inline ALbuffer *LookupBuffer(ALCdevice *device, ALuint id) noexcept ALuint lidx = (id-1) >> 6; ALsizei slidx = (id-1) & 0x3f; - if(UNLIKELY(lidx >= device->BufferList.size())) + if UNLIKELY(lidx >= device->BufferList.size()) return nullptr; BufferSubList &sublist = device->BufferList[lidx]; - if(UNLIKELY(sublist.FreeMask & (1_u64 << slidx))) + if UNLIKELY(sublist.FreeMask & (1_u64 << slidx)) return nullptr; return sublist.Buffers + slidx; } @@ -600,10 +600,10 @@ inline ALfilter *LookupFilter(ALCdevice *device, ALuint id) noexcept ALuint lidx = (id-1) >> 6; ALsizei slidx = (id-1) & 0x3f; - if(UNLIKELY(lidx >= device->FilterList.size())) + if UNLIKELY(lidx >= device->FilterList.size()) return nullptr; FilterSubList &sublist = device->FilterList[lidx]; - if(UNLIKELY(sublist.FreeMask & (1_u64 << slidx))) + if UNLIKELY(sublist.FreeMask & (1_u64 << slidx)) return nullptr; return sublist.Filters + slidx; } @@ -613,10 +613,10 @@ inline ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id) noexcept ALuint lidx = (id-1) >> 6; ALsizei slidx = (id-1) & 0x3f; - if(UNLIKELY(lidx >= context->mEffectSlotList.size())) + if UNLIKELY(lidx >= context->mEffectSlotList.size()) return nullptr; EffectSlotSubList &sublist{context->mEffectSlotList[lidx]}; - if(UNLIKELY(sublist.FreeMask & (1_u64 << slidx))) + if UNLIKELY(sublist.FreeMask & (1_u64 << slidx)) return nullptr; return sublist.EffectSlots + slidx; } @@ -870,7 +870,7 @@ bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a bool SetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, const al::span values); #define CHECKSIZE(v, s) do { \ - if(UNLIKELY((v).size() != INT_MAX && (v).size() != (s))) \ + if UNLIKELY((v).size() != INT_MAX && (v).size() != (s)) \ { \ Context->setError(AL_INVALID_ENUM, \ "Property 0x%04x expects %d value(s), got %zu", prop, (s), \ @@ -879,7 +879,7 @@ bool SetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, const } \ } while(0) #define CHECKVAL(x) do { \ - if(UNLIKELY(!(x))) \ + if UNLIKELY(!(x)) \ { \ Context->setError(AL_INVALID_VALUE, "Value out of range"); \ return false; \ @@ -2077,9 +2077,9 @@ AL_API ALvoid AL_APIENTRY alGenSources(ALsizei n, ALuint *sources) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; - if(n < 0) + if UNLIKELY(n < 0) context->setError(AL_INVALID_VALUE, "Generating %d sources", n); else if(n == 1) { @@ -2111,9 +2111,9 @@ AL_API ALvoid AL_APIENTRY alDeleteSources(ALsizei n, const ALuint *sources) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; - if(n < 0) + if UNLIKELY(n < 0) SETERR_RETURN(context, AL_INVALID_VALUE,, "Deleting %d sources", n); std::lock_guard _{context->mSourceLock}; @@ -2131,7 +2131,7 @@ START_API_FUNC return true; } ); - if(LIKELY(invsrc == sources_end)) + if LIKELY(invsrc == sources_end) { /* All good. Delete source IDs. */ std::for_each(sources, sources_end, @@ -2149,7 +2149,7 @@ AL_API ALboolean AL_APIENTRY alIsSource(ALuint source) START_API_FUNC { ContextRef context{GetContextRef()}; - if(LIKELY(context)) + if LIKELY(context) { std::lock_guard _{context->mSourceLock}; if(LookupSource(context.get(), source) != nullptr) @@ -2164,12 +2164,12 @@ AL_API ALvoid AL_APIENTRY alSourcef(ALuint source, ALenum param, ALfloat value) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mPropLock}; std::lock_guard __{context->mSourceLock}; ALsource *Source = LookupSource(context.get(), source); - if(UNLIKELY(!Source)) + if UNLIKELY(!Source) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else SetSourcefv(Source, context.get(), static_cast(param), {&value, 1u}); @@ -2180,12 +2180,12 @@ AL_API ALvoid AL_APIENTRY alSource3f(ALuint source, ALenum param, ALfloat value1 START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mPropLock}; std::lock_guard __{context->mSourceLock}; ALsource *Source = LookupSource(context.get(), source); - if(UNLIKELY(!Source)) + if UNLIKELY(!Source) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else { @@ -2199,14 +2199,14 @@ AL_API ALvoid AL_APIENTRY alSourcefv(ALuint source, ALenum param, const ALfloat START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mPropLock}; std::lock_guard __{context->mSourceLock}; ALsource *Source = LookupSource(context.get(), source); - if(UNLIKELY(!Source)) + if UNLIKELY(!Source) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); - else if(!values) + else if UNLIKELY(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); else SetSourcefv(Source, context.get(), static_cast(param), {values, INT_MAX}); @@ -2218,17 +2218,17 @@ AL_API ALvoid AL_APIENTRY alSourcedSOFT(ALuint source, ALenum param, ALdouble va START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mPropLock}; std::lock_guard __{context->mSourceLock}; ALsource *Source = LookupSource(context.get(), source); - if(UNLIKELY(!Source)) + if UNLIKELY(!Source) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else { - const auto fval = static_cast(value); - SetSourcefv(Source, context.get(), static_cast(param), {&fval, 1u}); + const ALfloat fval[1]{static_cast(value)}; + SetSourcefv(Source, context.get(), static_cast(param), fval); } } END_API_FUNC @@ -2237,12 +2237,12 @@ AL_API ALvoid AL_APIENTRY alSource3dSOFT(ALuint source, ALenum param, ALdouble v START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mPropLock}; std::lock_guard __{context->mSourceLock}; ALsource *Source = LookupSource(context.get(), source); - if(UNLIKELY(!Source)) + if UNLIKELY(!Source) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else { @@ -2257,14 +2257,14 @@ AL_API ALvoid AL_APIENTRY alSourcedvSOFT(ALuint source, ALenum param, const ALdo START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mPropLock}; std::lock_guard __{context->mSourceLock}; ALsource *Source = LookupSource(context.get(), source); - if(UNLIKELY(!Source)) + if UNLIKELY(!Source) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); - else if(!values) + else if UNLIKELY(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); else { @@ -2282,12 +2282,12 @@ AL_API ALvoid AL_APIENTRY alSourcei(ALuint source, ALenum param, ALint value) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mPropLock}; std::lock_guard __{context->mSourceLock}; ALsource *Source = LookupSource(context.get(), source); - if(UNLIKELY(!Source)) + if UNLIKELY(!Source) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else SetSourceiv(Source, context.get(), static_cast(param), {&value, 1u}); @@ -2298,12 +2298,12 @@ AL_API void AL_APIENTRY alSource3i(ALuint source, ALenum param, ALint value1, AL START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mPropLock}; std::lock_guard __{context->mSourceLock}; ALsource *Source = LookupSource(context.get(), source); - if(UNLIKELY(!Source)) + if UNLIKELY(!Source) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else { @@ -2317,14 +2317,14 @@ AL_API void AL_APIENTRY alSourceiv(ALuint source, ALenum param, const ALint *val START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mPropLock}; std::lock_guard __{context->mSourceLock}; ALsource *Source = LookupSource(context.get(), source); - if(UNLIKELY(!Source)) + if UNLIKELY(!Source) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); - else if(!values) + else if UNLIKELY(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); else SetSourceiv(Source, context.get(), static_cast(param), {values, INT_MAX}); @@ -2336,12 +2336,12 @@ AL_API ALvoid AL_APIENTRY alSourcei64SOFT(ALuint source, ALenum param, ALint64SO START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mPropLock}; std::lock_guard __{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; - if(UNLIKELY(!Source)) + if UNLIKELY(!Source) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else SetSourcei64v(Source, context.get(), static_cast(param), {&value, 1u}); @@ -2352,12 +2352,12 @@ AL_API void AL_APIENTRY alSource3i64SOFT(ALuint source, ALenum param, ALint64SOF START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mPropLock}; std::lock_guard __{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; - if(UNLIKELY(!Source)) + if UNLIKELY(!Source) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); else { @@ -2371,14 +2371,14 @@ AL_API void AL_APIENTRY alSourcei64vSOFT(ALuint source, ALenum param, const ALin START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mPropLock}; std::lock_guard __{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; - if(UNLIKELY(!Source)) + if UNLIKELY(!Source) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); - else if(!values) + else if UNLIKELY(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); else SetSourcei64v(Source, context.get(), static_cast(param), {values, INT_MAX}); @@ -2390,19 +2390,19 @@ AL_API ALvoid AL_APIENTRY alGetSourcef(ALuint source, ALenum param, ALfloat *val START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; - if(UNLIKELY(!Source)) + if UNLIKELY(!Source) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); - else if(!value) + else if UNLIKELY(!value) context->setError(AL_INVALID_VALUE, "NULL pointer"); else { - ALdouble dval; - if(GetSourcedv(Source, context.get(), static_cast(param), {&dval, 1u})) - *value = static_cast(dval); + ALdouble dval[1]; + if(GetSourcedv(Source, context.get(), static_cast(param), dval)) + *value = static_cast(dval[1]); } } END_API_FUNC @@ -2411,13 +2411,13 @@ AL_API ALvoid AL_APIENTRY alGetSource3f(ALuint source, ALenum param, ALfloat *va START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; - if(UNLIKELY(!Source)) + if UNLIKELY(!Source) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); - else if(!(value1 && value2 && value3)) + else if UNLIKELY(!(value1 && value2 && value3)) context->setError(AL_INVALID_VALUE, "NULL pointer"); else { @@ -2436,13 +2436,13 @@ AL_API ALvoid AL_APIENTRY alGetSourcefv(ALuint source, ALenum param, ALfloat *va START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; - if(UNLIKELY(!Source)) + if UNLIKELY(!Source) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); - else if(!values) + else if UNLIKELY(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); else { @@ -2462,13 +2462,13 @@ AL_API void AL_APIENTRY alGetSourcedSOFT(ALuint source, ALenum param, ALdouble * START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; - if(UNLIKELY(!Source)) + if UNLIKELY(!Source) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); - else if(!value) + else if UNLIKELY(!value) context->setError(AL_INVALID_VALUE, "NULL pointer"); else GetSourcedv(Source, context.get(), static_cast(param), {value, 1u}); @@ -2479,13 +2479,13 @@ AL_API void AL_APIENTRY alGetSource3dSOFT(ALuint source, ALenum param, ALdouble START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; - if(UNLIKELY(!Source)) + if UNLIKELY(!Source) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); - else if(!(value1 && value2 && value3)) + else if UNLIKELY(!(value1 && value2 && value3)) context->setError(AL_INVALID_VALUE, "NULL pointer"); else { @@ -2504,13 +2504,13 @@ AL_API void AL_APIENTRY alGetSourcedvSOFT(ALuint source, ALenum param, ALdouble START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; - if(UNLIKELY(!Source)) + if UNLIKELY(!Source) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); - else if(!values) + else if UNLIKELY(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); else GetSourcedv(Source, context.get(), static_cast(param), {values, INT_MAX}); @@ -2522,13 +2522,13 @@ AL_API ALvoid AL_APIENTRY alGetSourcei(ALuint source, ALenum param, ALint *value START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; - if(UNLIKELY(!Source)) + if UNLIKELY(!Source) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); - else if(!value) + else if UNLIKELY(!value) context->setError(AL_INVALID_VALUE, "NULL pointer"); else GetSourceiv(Source, context.get(), static_cast(param), {value, 1u}); @@ -2539,13 +2539,13 @@ AL_API void AL_APIENTRY alGetSource3i(ALuint source, ALenum param, ALint *value1 START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; - if(UNLIKELY(!Source)) + if UNLIKELY(!Source) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); - else if(!(value1 && value2 && value3)) + else if UNLIKELY(!(value1 && value2 && value3)) context->setError(AL_INVALID_VALUE, "NULL pointer"); else { @@ -2564,13 +2564,13 @@ AL_API void AL_APIENTRY alGetSourceiv(ALuint source, ALenum param, ALint *values START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; - if(UNLIKELY(!Source)) + if UNLIKELY(!Source) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); - else if(!values) + else if UNLIKELY(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); else GetSourceiv(Source, context.get(), static_cast(param), {values, INT_MAX}); @@ -2582,13 +2582,13 @@ AL_API void AL_APIENTRY alGetSourcei64SOFT(ALuint source, ALenum param, ALint64S START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; - if(UNLIKELY(!Source)) + if UNLIKELY(!Source) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); - else if(!value) + else if UNLIKELY(!value) context->setError(AL_INVALID_VALUE, "NULL pointer"); else GetSourcei64v(Source, context.get(), static_cast(param), {value, 1u}); @@ -2599,13 +2599,13 @@ AL_API void AL_APIENTRY alGetSource3i64SOFT(ALuint source, ALenum param, ALint64 START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; - if(UNLIKELY(!Source)) + if UNLIKELY(!Source) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); - else if(!(value1 && value2 && value3)) + else if UNLIKELY(!(value1 && value2 && value3)) context->setError(AL_INVALID_VALUE, "NULL pointer"); else { @@ -2624,13 +2624,13 @@ AL_API void AL_APIENTRY alGetSourcei64vSOFT(ALuint source, ALenum param, ALint64 START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mSourceLock}; ALsource *Source{LookupSource(context.get(), source)}; - if(UNLIKELY(!Source)) + if UNLIKELY(!Source) context->setError(AL_INVALID_NAME, "Invalid source ID %u", source); - else if(!values) + else if UNLIKELY(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); else GetSourcei64v(Source, context.get(), static_cast(param), {values, INT_MAX}); @@ -2647,16 +2647,16 @@ AL_API ALvoid AL_APIENTRY alSourcePlayv(ALsizei n, const ALuint *sources) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; - if(n < 0) - SETERR_RETURN(context, AL_INVALID_VALUE,, "Playing %d sources", n); - if(n == 0) return; + if UNLIKELY(n < 0) + context->setError(AL_INVALID_VALUE, "Playing %d sources", n); + if UNLIKELY(n <= 0) return; al::vector extra_sources; std::array source_storage; ALsource **srchandles{source_storage.data()}; - if(UNLIKELY(static_cast(n) > source_storage.size())) + if UNLIKELY(static_cast(n) > source_storage.size()) { extra_sources.resize(n); srchandles = extra_sources.data(); @@ -2673,7 +2673,7 @@ START_API_FUNC ALCdevice *device{context->mDevice.get()}; BackendLockGuard __{*device->Backend}; /* If the device is disconnected, go right to stopped. */ - if(UNLIKELY(!device->Connected.load(std::memory_order_acquire))) + if UNLIKELY(!device->Connected.load(std::memory_order_acquire)) { /* TODO: Send state change event? */ std::for_each(srchandles, srchandles+n, @@ -2699,18 +2699,18 @@ START_API_FUNC return count; } ); - if(UNLIKELY(n > free_voices)) + if UNLIKELY(n > free_voices) { /* Increment the number of voices to handle the request. */ const ALuint need_voices{static_cast(n) - free_voices}; const size_t rem_voices{context->mVoices->size() - context->mVoiceCount.load(std::memory_order_relaxed)}; - if(UNLIKELY(need_voices > rem_voices)) + if UNLIKELY(need_voices > rem_voices) { /* Allocate more voices to get enough. */ const size_t alloc_count{need_voices - rem_voices}; - if(UNLIKELY(context->mVoices->size() > std::numeric_limits::max()-alloc_count)) + if UNLIKELY(context->mVoices->size() > std::numeric_limits::max()-alloc_count) SETERR_RETURN(context, AL_OUT_OF_MEMORY,, "Overflow increasing voice count to %zu + %zu", context->mVoices->size(), alloc_count); @@ -2732,7 +2732,7 @@ START_API_FUNC BufferList = BufferList->mNext.load(std::memory_order_relaxed); /* If there's nothing to play, go right to stopped. */ - if(UNLIKELY(!BufferList)) + if UNLIKELY(!BufferList) { /* NOTE: A source without any playable buffers should not have an * ALvoice since it shouldn't be in a playing or paused state. So @@ -2908,16 +2908,16 @@ AL_API ALvoid AL_APIENTRY alSourcePausev(ALsizei n, const ALuint *sources) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; - if(n < 0) - SETERR_RETURN(context, AL_INVALID_VALUE,, "Pausing %d sources", n); - if(n == 0) return; + if UNLIKELY(n < 0) + context->setError(AL_INVALID_VALUE, "Pausing %d sources", n); + if UNLIKELY(n <= 0) return; al::vector extra_sources; std::array source_storage; ALsource **srchandles{source_storage.data()}; - if(UNLIKELY(static_cast(n) > source_storage.size())) + if UNLIKELY(static_cast(n) > source_storage.size()) { extra_sources.resize(n); srchandles = extra_sources.data(); @@ -2963,16 +2963,16 @@ AL_API ALvoid AL_APIENTRY alSourceStopv(ALsizei n, const ALuint *sources) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; - if(n < 0) - SETERR_RETURN(context, AL_INVALID_VALUE,, "Stopping %d sources", n); - if(n == 0) return; + if UNLIKELY(n < 0) + context->setError(AL_INVALID_VALUE, "Stopping %d sources", n); + if UNLIKELY(n <= 0) return; al::vector extra_sources; std::array source_storage; ALsource **srchandles{source_storage.data()}; - if(UNLIKELY(static_cast(n) > source_storage.size())) + if UNLIKELY(static_cast(n) > source_storage.size()) { extra_sources.resize(n); srchandles = extra_sources.data(); @@ -3025,16 +3025,16 @@ AL_API ALvoid AL_APIENTRY alSourceRewindv(ALsizei n, const ALuint *sources) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; - if(n < 0) - SETERR_RETURN(context, AL_INVALID_VALUE,, "Rewinding %d sources", n); - if(n == 0) return; + if UNLIKELY(n < 0) + context->setError(AL_INVALID_VALUE, "Rewinding %d sources", n); + if UNLIKELY(n <= 0) return; al::vector extra_sources; std::array source_storage; ALsource **srchandles{source_storage.data()}; - if(UNLIKELY(static_cast(n) > source_storage.size())) + if UNLIKELY(static_cast(n) > source_storage.size()) { extra_sources.resize(n); srchandles = extra_sources.data(); @@ -3081,19 +3081,19 @@ AL_API ALvoid AL_APIENTRY alSourceQueueBuffers(ALuint src, ALsizei nb, const ALu START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; - if(nb < 0) - SETERR_RETURN(context, AL_INVALID_VALUE,, "Queueing %d buffers", nb); - if(nb == 0) return; + if UNLIKELY(nb < 0) + context->setError(AL_INVALID_VALUE, "Queueing %d buffers", nb); + if UNLIKELY(nb <= 0) return; std::lock_guard _{context->mSourceLock}; ALsource *source{LookupSource(context.get(),src)}; - if(UNLIKELY(!source)) + if UNLIKELY(!source) SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid source ID %u", src); /* Can't queue on a Static Source */ - if(UNLIKELY(source->SourceType == AL_STATIC)) + if UNLIKELY(source->SourceType == AL_STATIC) SETERR_RETURN(context, AL_INVALID_OPERATION,, "Queueing onto static source %u", src); /* Check for a valid Buffer, for its frequency and format */ @@ -3193,19 +3193,19 @@ AL_API void AL_APIENTRY alSourceQueueBufferLayersSOFT(ALuint src, ALsizei nb, co START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; - if(nb < 0) - SETERR_RETURN(context, AL_INVALID_VALUE,, "Queueing %d buffer layers", nb); - if(nb == 0) return; + if UNLIKELY(nb < 0) + context->setError(AL_INVALID_VALUE, "Queueing %d buffer layers", nb); + if UNLIKELY(nb <= 0) return; std::lock_guard _{context->mSourceLock}; ALsource *source{LookupSource(context.get(),src)}; - if(UNLIKELY(!source)) + if UNLIKELY(!source) SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid source ID %u", src); /* Can't queue on a Static Source */ - if(UNLIKELY(source->SourceType == AL_STATIC)) + if UNLIKELY(source->SourceType == AL_STATIC) SETERR_RETURN(context, AL_INVALID_OPERATION,, "Queueing onto static source %u", src); /* Check for a valid Buffer, for its frequency and format */ @@ -3296,20 +3296,20 @@ AL_API ALvoid AL_APIENTRY alSourceUnqueueBuffers(ALuint src, ALsizei nb, ALuint START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; - if(nb < 0) - SETERR_RETURN(context, AL_INVALID_VALUE,, "Unqueueing %d buffers", nb); - if(nb == 0) return; + if UNLIKELY(nb < 0) + context->setError(AL_INVALID_VALUE, "Unqueueing %d buffers", nb); + if UNLIKELY(nb <= 0) return; std::lock_guard _{context->mSourceLock}; ALsource *source{LookupSource(context.get(),src)}; - if(UNLIKELY(!source)) + if UNLIKELY(!source) SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid source ID %u", src); - if(UNLIKELY(source->Looping)) + if UNLIKELY(source->Looping) SETERR_RETURN(context, AL_INVALID_VALUE,, "Unqueueing from looping source %u", src); - if(UNLIKELY(source->SourceType != AL_STREAMING)) + if UNLIKELY(source->SourceType != AL_STREAMING) SETERR_RETURN(context, AL_INVALID_VALUE,, "Unqueueing from a non-streaming source %u", src); @@ -3321,7 +3321,7 @@ START_API_FUNC Current = voice->mCurrentBuffer.load(std::memory_order_relaxed); else if(source->state == AL_INITIAL) Current = BufferList; - if(UNLIKELY(BufferList == Current)) + if UNLIKELY(BufferList == Current) SETERR_RETURN(context, AL_INVALID_VALUE,, "Unqueueing pending buffers"); ALuint i{BufferList->mNumBuffers}; @@ -3331,7 +3331,7 @@ START_API_FUNC * trying to unqueue pending buffers. */ ALbufferlistitem *next{BufferList->mNext.load(std::memory_order_relaxed)}; - if(UNLIKELY(!next) || UNLIKELY(next == Current)) + if UNLIKELY(!next || next == Current) SETERR_RETURN(context, AL_INVALID_VALUE,, "Unqueueing pending buffers"); BufferList = next; diff --git a/al/state.cpp b/al/state.cpp index 3e8f4d18..b0338296 100644 --- a/al/state.cpp +++ b/al/state.cpp @@ -90,7 +90,7 @@ AL_API ALvoid AL_APIENTRY alEnable(ALenum capability) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mPropLock}; switch(capability) @@ -110,7 +110,7 @@ AL_API ALvoid AL_APIENTRY alDisable(ALenum capability) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; std::lock_guard _{context->mPropLock}; switch(capability) @@ -130,7 +130,7 @@ AL_API ALboolean AL_APIENTRY alIsEnabled(ALenum capability) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return AL_FALSE; + if UNLIKELY(!context) return AL_FALSE; std::lock_guard _{context->mPropLock}; ALboolean value{AL_FALSE}; @@ -152,7 +152,7 @@ AL_API ALboolean AL_APIENTRY alGetBoolean(ALenum pname) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return AL_FALSE; + if UNLIKELY(!context) return AL_FALSE; std::lock_guard _{context->mPropLock}; ALboolean value{AL_FALSE}; @@ -209,7 +209,7 @@ AL_API ALdouble AL_APIENTRY alGetDouble(ALenum pname) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return 0.0; + if UNLIKELY(!context) return 0.0; std::lock_guard _{context->mPropLock}; ALdouble value{0.0}; @@ -260,7 +260,7 @@ AL_API ALfloat AL_APIENTRY alGetFloat(ALenum pname) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return 0.0f; + if UNLIKELY(!context) return 0.0f; std::lock_guard _{context->mPropLock}; ALfloat value{0.0f}; @@ -311,7 +311,7 @@ AL_API ALint AL_APIENTRY alGetInteger(ALenum pname) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return 0; + if UNLIKELY(!context) return 0; std::lock_guard _{context->mPropLock}; ALint value{0}; @@ -362,7 +362,7 @@ extern "C" AL_API ALint64SOFT AL_APIENTRY alGetInteger64SOFT(ALenum pname) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return 0; + if UNLIKELY(!context) return 0_i64; std::lock_guard _{context->mPropLock}; ALint64SOFT value{0}; @@ -413,7 +413,7 @@ AL_API void* AL_APIENTRY alGetPointerSOFT(ALenum pname) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return nullptr; + if UNLIKELY(!context) return nullptr; std::lock_guard _{context->mPropLock}; void *value{nullptr}; @@ -456,7 +456,7 @@ START_API_FUNC } ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; if(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); @@ -489,7 +489,7 @@ START_API_FUNC } ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; if(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); @@ -522,7 +522,7 @@ START_API_FUNC } ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; if(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); @@ -555,7 +555,7 @@ START_API_FUNC } ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; if(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); @@ -588,7 +588,7 @@ START_API_FUNC } ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; if(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); @@ -615,7 +615,7 @@ START_API_FUNC } ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; if(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); @@ -631,7 +631,7 @@ AL_API const ALchar* AL_APIENTRY alGetString(ALenum pname) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return nullptr; + if UNLIKELY(!context) return nullptr; const ALchar *value{nullptr}; switch(pname) @@ -687,7 +687,7 @@ AL_API ALvoid AL_APIENTRY alDopplerFactor(ALfloat value) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; if(!(value >= 0.0f && std::isfinite(value))) context->setError(AL_INVALID_VALUE, "Doppler factor %f out of range", value); @@ -704,7 +704,7 @@ AL_API ALvoid AL_APIENTRY alDopplerVelocity(ALfloat value) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; if((context->mEnabledEvts.load(std::memory_order_relaxed)&EventType_Deprecated)) { @@ -733,7 +733,7 @@ AL_API ALvoid AL_APIENTRY alSpeedOfSound(ALfloat value) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; if(!(value > 0.0f && std::isfinite(value))) context->setError(AL_INVALID_VALUE, "Speed of sound %f out of range", value); @@ -750,7 +750,7 @@ AL_API ALvoid AL_APIENTRY alDistanceModel(ALenum value) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; if(!(value == AL_INVERSE_DISTANCE || value == AL_INVERSE_DISTANCE_CLAMPED || value == AL_LINEAR_DISTANCE || value == AL_LINEAR_DISTANCE_CLAMPED || @@ -772,7 +772,7 @@ AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; context->deferUpdates(); } @@ -782,7 +782,7 @@ AL_API ALvoid AL_APIENTRY alProcessUpdatesSOFT(void) START_API_FUNC { ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return; + if UNLIKELY(!context) return; context->processUpdates(); } @@ -800,7 +800,7 @@ START_API_FUNC static_assert(al::size(ResamplerNames) == ResamplerMax+1, "Incorrect ResamplerNames list"); ContextRef context{GetContextRef()}; - if(UNLIKELY(!context)) return nullptr; + if UNLIKELY(!context) return nullptr; const ALchar *value{nullptr}; switch(pname) diff --git a/alc/alc.cpp b/alc/alc.cpp index 615fc154..f66654c2 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -4193,7 +4193,7 @@ START_API_FUNC device->Connected.store(true); ALCenum err{UpdateDeviceParams(dev.get(), attribs)}; - if(LIKELY(err == ALC_NO_ERROR)) return ALC_TRUE; + if LIKELY(err == ALC_NO_ERROR) return ALC_TRUE; alcSetError(dev.get(), err); if(err == ALC_INVALID_DEVICE) diff --git a/alc/alu.cpp b/alc/alu.cpp index 253dbe48..412bfffa 100644 --- a/alc/alu.cpp +++ b/alc/alu.cpp @@ -383,7 +383,7 @@ bool CalcEffectSlotParams(ALeffectslot *slot, ALCcontext *context, bool force) */ RingBuffer *ring{context->mAsyncEvents.get()}; auto evt_vec = ring->getWriteVector(); - if(LIKELY(evt_vec.first.len > 0)) + if LIKELY(evt_vec.first.len > 0) { AsyncEvent *evt{new (evt_vec.first.buf) AsyncEvent{EventType_ReleaseEffectState}}; evt->u.mEffectState = oldstate; @@ -1347,7 +1347,7 @@ void ProcessParamUpdates(ALCcontext *ctx, const ALeffectslotArray &slots, const al::span voices) { IncrementRef(ctx->mUpdateCount); - if(LIKELY(!ctx->mHoldUpdates.load(std::memory_order_acquire))) + if LIKELY(!ctx->mHoldUpdates.load(std::memory_order_acquire)) { bool cforce{CalcContextParams(ctx)}; bool force{CalcListenerParams(ctx) || cforce}; @@ -1463,7 +1463,7 @@ void ApplyStablizer(FrontStablizer *Stablizer, const al::span B auto &DelayBuf = Stablizer->DelayBuf[i]; auto buffer_end = Buffer[i].begin() + SamplesToDo; - if(LIKELY(SamplesToDo >= ALsizei{FrontStablizer::DelayLength})) + if LIKELY(SamplesToDo >= ALsizei{FrontStablizer::DelayLength}) { auto delay_end = std::rotate(Buffer[i].begin(), buffer_end - FrontStablizer::DelayLength, buffer_end); @@ -1556,7 +1556,7 @@ void ApplyDistanceComp(const al::span Samples, const ALsizei Sa ALfloat *inout{al::assume_aligned<16>(chanbuffer.data())}; auto inout_end = inout + SamplesToDo; - if(LIKELY(SamplesToDo >= base)) + if LIKELY(SamplesToDo >= base) { auto delay_end = std::rotate(inout, inout_end - base, inout_end); std::swap_ranges(inout, delay_end, distbuf); @@ -1690,7 +1690,7 @@ void aluMixData(ALCdevice *device, ALvoid *OutBuffer, ALsizei NumSamples) /* Apply any needed post-process for finalizing the Dry mix to the * RealOut (Ambisonic decode, UHJ encode, etc). */ - if(LIKELY(device->PostProcess)) + if LIKELY(device->PostProcess) device->PostProcess(device, SamplesToDo); const al::span RealOut{device->RealOut.Buffer}; @@ -1718,7 +1718,7 @@ void aluMixData(ALCdevice *device, ALvoid *OutBuffer, ALsizei NumSamples) if(device->DitherDepth > 0.0f) ApplyDither(RealOut, &device->DitherSeed, device->DitherDepth, SamplesToDo); - if(LIKELY(OutBuffer)) + if LIKELY(OutBuffer) { /* Finally, interleave and convert samples, writing to the device's * output buffer. diff --git a/alc/backends/opensl.cpp b/alc/backends/opensl.cpp index b34dc0cb..d9a7836e 100644 --- a/alc/backends/opensl.cpp +++ b/alc/backends/opensl.cpp @@ -136,7 +136,7 @@ const char *res_str(SLresult result) } #define PRINTERR(x, s) do { \ - if(UNLIKELY((x) != SL_RESULT_SUCCESS)) \ + if UNLIKELY((x) != SL_RESULT_SUCCESS) \ ERR("%s: %s\n", (s), res_str((x))); \ } while(0) diff --git a/alc/backends/pulseaudio.cpp b/alc/backends/pulseaudio.cpp index da209c8d..2ddcc86d 100644 --- a/alc/backends/pulseaudio.cpp +++ b/alc/backends/pulseaudio.cpp @@ -379,7 +379,7 @@ pa_context *connect_context(std::unique_lock &plock) if(!binname.fname.empty()) name = binname.fname.c_str(); - if(UNLIKELY(!pulse_mainloop)) + if UNLIKELY(!pulse_mainloop) { std::thread{pulse_mainloop_thread}.detach(); while(!pulse_mainloop) @@ -744,7 +744,7 @@ void PulsePlayback::streamWriteCallback(pa_stream *stream, size_t nbytes) aluMixData(mDevice, buf, nbytes/mFrameSize); int ret{pa_stream_write(stream, buf, nbytes, pa_xfree, 0, PA_SEEK_RELATIVE)}; - if(UNLIKELY(ret != PA_OK)) + if UNLIKELY(ret != PA_OK) ERR("Failed to write to stream: %d, %s\n", ret, pa_strerror(ret)); } @@ -1064,7 +1064,7 @@ ClockLatency PulsePlayback::getClockLatency() err = pa_stream_get_latency(mStream, &latency, &neg); } - if(UNLIKELY(err != 0)) + if UNLIKELY(err != 0) { /* FIXME: if err = -PA_ERR_NODATA, it means we were called too soon * after starting the stream and no timing info has been received from @@ -1075,7 +1075,7 @@ ClockLatency PulsePlayback::getClockLatency() latency = 0; neg = 0; } - else if(UNLIKELY(neg)) + else if UNLIKELY(neg) latency = 0; ret.Latency = std::chrono::microseconds{latency}; @@ -1328,24 +1328,24 @@ ALCenum PulseCapture::captureSamples(ALCvoid *buffer, ALCuint samples) { if(mCapBuffer.empty()) { - if(UNLIKELY(!mDevice->Connected.load(std::memory_order_acquire))) + if UNLIKELY(!mDevice->Connected.load(std::memory_order_acquire)) break; const pa_stream_state_t state{pa_stream_get_state(mStream)}; - if(UNLIKELY(!PA_STREAM_IS_GOOD(state))) + if UNLIKELY(!PA_STREAM_IS_GOOD(state)) { aluHandleDisconnect(mDevice, "Bad capture state: %u", state); break; } const void *capbuf; size_t caplen; - if(UNLIKELY(pa_stream_peek(mStream, &capbuf, &caplen) < 0)) + if UNLIKELY(pa_stream_peek(mStream, &capbuf, &caplen) < 0) { aluHandleDisconnect(mDevice, "Failed retrieving capture samples: %s", pa_strerror(pa_context_errno(mContext))); break; } if(caplen == 0) break; - if(UNLIKELY(!capbuf)) + if UNLIKELY(!capbuf) mCapLen = -static_cast(caplen); else mCapLen = static_cast(caplen); @@ -1353,7 +1353,7 @@ ALCenum PulseCapture::captureSamples(ALCvoid *buffer, ALCuint samples) } const size_t rem{minz(dstbuf.size(), mCapBuffer.size())}; - if(UNLIKELY(mCapLen < 0)) + if UNLIKELY(mCapLen < 0) std::fill_n(dstbuf.begin(), rem, mSilentVal); else std::copy_n(mCapBuffer.begin(), rem, dstbuf.begin()); @@ -1409,13 +1409,13 @@ ClockLatency PulseCapture::getClockLatency() err = pa_stream_get_latency(mStream, &latency, &neg); } - if(UNLIKELY(err != 0)) + if UNLIKELY(err != 0) { ERR("Failed to get stream latency: 0x%x\n", err); latency = 0; neg = 0; } - else if(UNLIKELY(neg)) + else if UNLIKELY(neg) latency = 0; ret.Latency = std::chrono::microseconds{latency}; diff --git a/alc/bformatdec.cpp b/alc/bformatdec.cpp index 6b20dd84..8319600e 100644 --- a/alc/bformatdec.cpp +++ b/alc/bformatdec.cpp @@ -160,7 +160,7 @@ void BFormatDec::process(const al::span OutBuffer, ALuint enabled{mEnabled}; for(FloatBufferLine &outbuf : OutBuffer) { - if(LIKELY(enabled&1)) + if LIKELY(enabled&1) { MixRowSamples(outbuf, (*mixmtx)[sHFBand], hfsamples, 0, SamplesToDo); MixRowSamples(outbuf, (*mixmtx)[sLFBand], lfsamples, 0, SamplesToDo); @@ -176,7 +176,7 @@ void BFormatDec::process(const al::span OutBuffer, ALuint enabled{mEnabled}; for(FloatBufferLine &outbuf : OutBuffer) { - if(LIKELY(enabled&1)) + if LIKELY(enabled&1) MixRowSamples(outbuf, *mixmtx, insamples, 0, SamplesToDo); ++mixmtx; enabled >>= 1; diff --git a/alc/effects/pshifter.cpp b/alc/effects/pshifter.cpp index a08052b9..819e510c 100644 --- a/alc/effects/pshifter.cpp +++ b/alc/effects/pshifter.cpp @@ -68,11 +68,11 @@ inline int double2int(double d) shift = ((conv.i64>>52)&0x7ff) - (1023+52); /* Over/underflow */ - if(UNLIKELY(shift >= 63 || shift < -52)) + if UNLIKELY(shift >= 63 || shift < -52) return 0; mant = (conv.i64&0xfffffffffffff_i64) | 0x10000000000000_i64; - if(LIKELY(shift < 0)) + if LIKELY(shift < 0) return (int)(mant >> -shift) * sign; return (int)(mant << shift) * sign; diff --git a/alc/effects/reverb.cpp b/alc/effects/reverb.cpp index 51a57360..a8c4523e 100644 --- a/alc/effects/reverb.cpp +++ b/alc/effects/reverb.cpp @@ -1484,7 +1484,7 @@ void ReverbState::process(const ALsizei samplesToDo, const FloatBufferLine *REST mDelay.write(offset, c, afmt[c].data()+base, todo); /* Process the samples for reverb. */ - if(UNLIKELY(fadeCount < FADE_SAMPLES)) + if UNLIKELY(fadeCount < FADE_SAMPLES) { auto fade = static_cast(fadeCount); diff --git a/alc/helpers.cpp b/alc/helpers.cpp index e86af6ce..7a547168 100644 --- a/alc/helpers.cpp +++ b/alc/helpers.cpp @@ -478,7 +478,7 @@ void al_print(FILE *logfile, const char *fmt, ...) va_start(args, fmt); va_copy(args2, args); int msglen{std::vsnprintf(str, sizeof(stcmsg), fmt, args)}; - if(UNLIKELY(msglen >= 0 && static_cast(msglen) >= sizeof(stcmsg))) + if UNLIKELY(msglen >= 0 && static_cast(msglen) >= sizeof(stcmsg)) { dynmsg.resize(static_cast(msglen) + 1u); str = dynmsg.data(); diff --git a/alc/logging.h b/alc/logging.h index 0bb0c87b..8a3e75e6 100644 --- a/alc/logging.h +++ b/alc/logging.h @@ -39,24 +39,24 @@ enum LogLevel { extern LogLevel gLogLevel; #define TRACEREF(...) do { \ - if(UNLIKELY(gLogLevel >= LogRef)) \ + if UNLIKELY(gLogLevel >= LogRef) \ AL_PRINT("(--)", __VA_ARGS__); \ } while(0) #define TRACE(...) do { \ - if(UNLIKELY(gLogLevel >= LogTrace)) \ + if UNLIKELY(gLogLevel >= LogTrace) \ AL_PRINT("(II)", __VA_ARGS__); \ LOG_ANDROID(ANDROID_LOG_DEBUG, __VA_ARGS__); \ } while(0) #define WARN(...) do { \ - if(UNLIKELY(gLogLevel >= LogWarning)) \ + if UNLIKELY(gLogLevel >= LogWarning) \ AL_PRINT("(WW)", __VA_ARGS__); \ LOG_ANDROID(ANDROID_LOG_WARN, __VA_ARGS__); \ } while(0) #define ERR(...) do { \ - if(UNLIKELY(gLogLevel >= LogError)) \ + if UNLIKELY(gLogLevel >= LogError) \ AL_PRINT("(EE)", __VA_ARGS__); \ LOG_ANDROID(ANDROID_LOG_ERROR, __VA_ARGS__); \ } while(0) diff --git a/alc/mastering.cpp b/alc/mastering.cpp index ec40001b..d4d87c25 100644 --- a/alc/mastering.cpp +++ b/alc/mastering.cpp @@ -314,7 +314,7 @@ void SignalDelay(Compressor *Comp, const ALsizei SamplesToDo, FloatBufferLine *O ALfloat *delaybuf{al::assume_aligned<16>(Comp->mDelay[c].data())}; auto inout_end = inout + SamplesToDo; - if(LIKELY(SamplesToDo >= lookAhead)) + if LIKELY(SamplesToDo >= lookAhead) { auto delay_end = std::rotate(inout, inout_end - lookAhead, inout_end); std::swap_ranges(inout, delay_end, delaybuf); diff --git a/alc/mixer/mixer_neon.cpp b/alc/mixer/mixer_neon.cpp index b4ca61d7..f43063ce 100644 --- a/alc/mixer/mixer_neon.cpp +++ b/alc/mixer/mixer_neon.cpp @@ -209,7 +209,7 @@ void Mix_(const ALfloat *data, const al::span OutBuffe const ALfloat step{diff * delta}; ALfloat step_count{0.0f}; /* Mix with applying gain steps in aligned multiples of 4. */ - if(LIKELY(minsize > 3)) + if LIKELY(minsize > 3) { const float32x4_t four4{vdupq_n_f32(4.0f)}; const float32x4_t step4{vdupq_n_f32(step)}; @@ -258,7 +258,7 @@ void Mix_(const ALfloat *data, const al::span OutBuffe if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD)) continue; - if(LIKELY(BufferSize-pos > 3)) + if LIKELY(BufferSize-pos > 3) { ALsizei todo{(BufferSize-pos) >> 2}; const float32x4_t gain4 = vdupq_n_f32(gain); @@ -289,7 +289,7 @@ void MixRow_(FloatBufferLine &OutBuffer, const ALfloat *Gains, continue; ALsizei pos{0}; - if(LIKELY(BufferSize > 3)) + if LIKELY(BufferSize > 3) { ALsizei todo{BufferSize >> 2}; float32x4_t gain4{vdupq_n_f32(gain)}; diff --git a/alc/mixer/mixer_sse.cpp b/alc/mixer/mixer_sse.cpp index b52ef256..cff37d2b 100644 --- a/alc/mixer/mixer_sse.cpp +++ b/alc/mixer/mixer_sse.cpp @@ -165,7 +165,7 @@ void Mix_(const ALfloat *data, const al::span OutBuffer const ALfloat step{diff * delta}; ALfloat step_count{0.0f}; /* Mix with applying gain steps in aligned multiples of 4. */ - if(LIKELY(minsize > 3)) + if LIKELY(minsize > 3) { const __m128 four4{_mm_set1_ps(4.0f)}; const __m128 step4{_mm_set1_ps(step)}; @@ -211,7 +211,7 @@ void Mix_(const ALfloat *data, const al::span OutBuffer if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD)) continue; - if(LIKELY(BufferSize-pos > 3)) + if LIKELY(BufferSize-pos > 3) { ALsizei todo{(BufferSize-pos) >> 2}; const __m128 gain4{_mm_set1_ps(gain)}; @@ -242,7 +242,7 @@ void MixRow_(FloatBufferLine &OutBuffer, const ALfloat *Gains, continue; ALsizei pos{0}; - if(LIKELY(BufferSize > 3)) + if LIKELY(BufferSize > 3) { ALsizei todo{BufferSize >> 2}; const __m128 gain4 = _mm_set1_ps(gain); diff --git a/alc/mixvoice.cpp b/alc/mixvoice.cpp index 06324397..df955719 100644 --- a/alc/mixvoice.cpp +++ b/alc/mixvoice.cpp @@ -635,7 +635,7 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc SrcData.begin()); std::fill(srciter, SrcData.end(), 0.0f); - if(UNLIKELY(!BufferListItem)) + if UNLIKELY(!BufferListItem) srciter = std::copy(chandata.mPrevSamples.begin()+MAX_RESAMPLE_PADDING, chandata.mPrevSamples.end(), srciter); else if(isstatic) @@ -645,7 +645,7 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc srciter = LoadBufferQueue(BufferListItem, BufferLoopItem, NumChannels, SampleSize, chan, DataPosInt, {srciter, SrcData.end()}); - if(UNLIKELY(srciter != SrcData.end())) + if UNLIKELY(srciter != SrcData.end()) { /* If the source buffer wasn't filled, copy the last sample for * the remaining buffer. Ideally it should have ended with @@ -734,7 +734,7 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc * and new target gains given how much of the fade time * this mix handles. */ - if(LIKELY(Counter > fademix)) + if LIKELY(Counter > fademix) { const ALfloat a{static_cast(fademix) / static_cast(Counter)}; @@ -758,7 +758,7 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc parms.Hrtf.Old.Gain = TargetGain; } - if(LIKELY(fademix < DstBufferSize)) + if LIKELY(fademix < DstBufferSize) { const ALsizei todo{DstBufferSize - fademix}; ALfloat gain{TargetGain}; @@ -856,7 +856,7 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc OutPos += DstBufferSize; Counter = maxi(DstBufferSize, Counter) - DstBufferSize; - if(UNLIKELY(!BufferListItem)) + if UNLIKELY(!BufferListItem) { /* Do nothing extra when there's no buffers. */ } @@ -879,7 +879,7 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc /* Handle non-looping static source */ if(DataPosInt >= BufferListItem->mMaxSamples) { - if(LIKELY(vstate == ALvoice::Playing)) + if LIKELY(vstate == ALvoice::Playing) vstate = ALvoice::Stopped; BufferListItem = nullptr; break; @@ -898,7 +898,7 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc BufferListItem = BufferListItem->mNext.load(std::memory_order_relaxed); if(!BufferListItem && !(BufferListItem=BufferLoopItem)) { - if(LIKELY(vstate == ALvoice::Playing)) + if LIKELY(vstate == ALvoice::Playing) vstate = ALvoice::Stopped; break; } @@ -908,7 +908,7 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc voice->mFlags |= VOICE_IS_FADING; /* Don't update positions and buffers if we were stopping. */ - if(UNLIKELY(vstate == ALvoice::Stopping)) + if UNLIKELY(vstate == ALvoice::Stopping) { voice->mPlayState.store(ALvoice::Stopped, std::memory_order_release); return; diff --git a/common/alexcpt.cpp b/common/alexcpt.cpp index 9e04bbaf..5055e34f 100644 --- a/common/alexcpt.cpp +++ b/common/alexcpt.cpp @@ -17,7 +17,7 @@ backend_exception::backend_exception(ALCenum code, const char *msg, ...) : mErro va_start(args, msg); va_copy(args2, args); int msglen{std::vsnprintf(nullptr, 0, msg, args)}; - if(LIKELY(msglen > 0)) + if LIKELY(msglen > 0) { mMessage.resize(static_cast(msglen)+1); std::vsnprintf(&mMessage[0], mMessage.length(), msg, args2); diff --git a/common/alnumeric.h b/common/alnumeric.h index 950eebe1..7035715c 100644 --- a/common/alnumeric.h +++ b/common/alnumeric.h @@ -246,11 +246,11 @@ inline int float2int(float f) noexcept shift = ((conv.i>>23)&0xff) - (127+23); /* Over/underflow */ - if(UNLIKELY(shift >= 31 || shift < -23)) + if UNLIKELY(shift >= 31 || shift < -23) return 0; mant = (conv.i&0x7fffff) | 0x800000; - if(LIKELY(shift < 0)) + if LIKELY(shift < 0) return (mant >> -shift) * sign; return (mant << shift) * sign; @@ -293,7 +293,7 @@ inline float fast_roundf(float f) noexcept sign = (conv.i>>31)&0x01; expo = (conv.i>>23)&0xff; - if(UNLIKELY(expo >= 150/*+23*/)) + if UNLIKELY(expo >= 150/*+23*/) { /* An exponent (base-2) of 23 or higher is incapable of sub-integral * precision, so it's already an integral value. We don't need to worry diff --git a/common/intrusive_ptr.h b/common/intrusive_ptr.h index 831b8302..fa76ad48 100644 --- a/common/intrusive_ptr.h +++ b/common/intrusive_ptr.h @@ -16,7 +16,7 @@ public: unsigned int release() noexcept { auto ref = DecrementRef(mRef); - if(UNLIKELY(ref == 0)) + if UNLIKELY(ref == 0) delete static_cast(this); return ref; } diff --git a/common/opthelpers.h b/common/opthelpers.h index c83229f5..58578c15 100644 --- a/common/opthelpers.h +++ b/common/opthelpers.h @@ -12,9 +12,9 @@ * required to be true, but it can result in more optimal code for the true * path at the expense of a less optimal false path. */ -#define LIKELY(x) __builtin_expect(!!(x), !false) +#define LIKELY(x) (__builtin_expect(!!(x), !false)) /* The opposite of LIKELY, optimizing the case where the condition is false. */ -#define UNLIKELY(x) __builtin_expect(!!(x), false) +#define UNLIKELY(x) (__builtin_expect(!!(x), false)) /* Unlike LIKELY, ASSUME requires the condition to be true or else it invokes * undefined behavior. It's essentially an assert without actually checking the * condition at run-time, allowing for stronger optimizations than LIKELY. -- cgit v1.2.3 From 7c069e29ee721b2d1294dea72aa48d73d45d2009 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 5 Aug 2019 22:40:19 -0700 Subject: Update some more includes --- al/auxeffectslot.cpp | 1 + al/event.cpp | 1 + al/filter.cpp | 2 ++ al/listener.cpp | 2 ++ al/listener.h | 2 +- al/source.cpp | 1 + al/state.cpp | 1 + 7 files changed, 9 insertions(+), 1 deletion(-) (limited to 'al/source.cpp') diff --git a/al/auxeffectslot.cpp b/al/auxeffectslot.cpp index e961874d..a0b8840f 100644 --- a/al/auxeffectslot.cpp +++ b/al/auxeffectslot.cpp @@ -31,6 +31,7 @@ #include "AL/al.h" #include "AL/alc.h" +#include "AL/efx.h" #include "alcmain.h" #include "alcontext.h" diff --git a/al/event.cpp b/al/event.cpp index 530f9679..13b1533f 100644 --- a/al/event.cpp +++ b/al/event.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include "AL/al.h" #include "AL/alc.h" diff --git a/al/filter.cpp b/al/filter.cpp index 41a96513..b1118550 100644 --- a/al/filter.cpp +++ b/al/filter.cpp @@ -29,6 +29,8 @@ #include #include +#include "AL/al.h" +#include "AL/alc.h" #include "AL/efx.h" #include "alcmain.h" diff --git a/al/listener.cpp b/al/listener.cpp index d2fb8807..bcee0b08 100644 --- a/al/listener.cpp +++ b/al/listener.cpp @@ -25,6 +25,8 @@ #include #include +#include "AL/al.h" +#include "AL/alc.h" #include "AL/efx.h" #include "alcontext.h" diff --git a/al/listener.h b/al/listener.h index 094e3067..05d93d19 100644 --- a/al/listener.h +++ b/al/listener.h @@ -6,7 +6,7 @@ #include "AL/al.h" #include "AL/alc.h" -#include "AL/alext.h" +#include "AL/efx.h" #include "vecmat.h" diff --git a/al/source.cpp b/al/source.cpp index 9273a7a8..b5d0b383 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -50,6 +50,7 @@ #include "alexcpt.h" #include "almalloc.h" #include "alnumeric.h" +#include "alspan.h" #include "alu.h" #include "ambidefs.h" #include "atomic.h" diff --git a/al/state.cpp b/al/state.cpp index cbfd12fe..8c95c22f 100644 --- a/al/state.cpp +++ b/al/state.cpp @@ -35,6 +35,7 @@ #include "alcontext.h" #include "alexcpt.h" #include "almalloc.h" +#include "alnumeric.h" #include "alspan.h" #include "alu.h" #include "atomic.h" -- cgit v1.2.3 From dca2365051e4697f5a1692252e9516398f746e0b Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 10 Aug 2019 20:31:08 -0700 Subject: Fix array access index --- al/source.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'al/source.cpp') diff --git a/al/source.cpp b/al/source.cpp index b5d0b383..98c52816 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -2403,7 +2403,7 @@ START_API_FUNC { ALdouble dval[1]; if(GetSourcedv(Source, context.get(), static_cast(param), dval)) - *value = static_cast(dval[1]); + *value = static_cast(dval[0]); } } END_API_FUNC -- cgit v1.2.3 From 7118733458bc388a900677da6e0d4e4244d0f536 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 11 Aug 2019 03:34:35 -0700 Subject: Remove multiple buffers per queue item And simplify related code --- al/source.cpp | 252 +++++++++++-------------------------------------------- al/source.h | 58 ++----------- alc/inprogext.h | 8 -- alc/mixvoice.cpp | 133 +++++++++-------------------- 4 files changed, 96 insertions(+), 355 deletions(-) (limited to 'al/source.cpp') diff --git a/al/source.cpp b/al/source.cpp index 98c52816..4bdf51fe 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -206,7 +206,7 @@ int64_t GetSourceSampleOffset(ALsource *Source, ALCcontext *context, std::chrono const ALbufferlistitem *BufferList{Source->queue}; while(BufferList && BufferList != Current) { - readPos += int64_t{BufferList->mMaxSamples} << 32; + readPos += int64_t{BufferList->mSampleLen} << 32; BufferList = BufferList->mNext.load(std::memory_order_relaxed); } readPos = minu64(readPos, 0x7fffffffffffffff_u64); @@ -253,16 +253,14 @@ ALdouble GetSourceSecOffset(ALsource *Source, ALCcontext *context, std::chrono:: const ALbuffer *BufferFmt{nullptr}; while(BufferList && BufferList != Current) { - for(ALuint i{0};!BufferFmt && i < BufferList->mNumBuffers;++i) - BufferFmt = (*BufferList)[i]; - readPos += int64_t{BufferList->mMaxSamples} << FRACTIONBITS; + if(!BufferFmt) BufferFmt = BufferList->mBuffer; + readPos += int64_t{BufferList->mSampleLen} << FRACTIONBITS; BufferList = BufferList->mNext.load(std::memory_order_relaxed); } while(BufferList && !BufferFmt) { - for(ALuint i{0};!BufferFmt && i < BufferList->mNumBuffers;++i) - BufferFmt = (*BufferList)[i]; + BufferFmt = BufferList->mBuffer; BufferList = BufferList->mNext.load(std::memory_order_relaxed); } assert(BufferFmt != nullptr); @@ -315,12 +313,11 @@ ALdouble GetSourceOffset(ALsource *Source, ALenum name, ALCcontext *context) while(BufferList) { - for(ALuint i{0};!BufferFmt && i < BufferList->mNumBuffers;++i) - BufferFmt = (*BufferList)[i]; + if(!BufferFmt) BufferFmt = BufferList->mBuffer; readFin |= (BufferList == Current); - totalBufferLen += BufferList->mMaxSamples; - if(!readFin) readPos += BufferList->mMaxSamples; + totalBufferLen += BufferList->mSampleLen; + if(!readFin) readPos += BufferList->mSampleLen; BufferList = BufferList->mNext.load(std::memory_order_relaxed); } @@ -392,11 +389,9 @@ ALboolean GetSampleOffset(ALsource *Source, ALuint *offset, ALsizei *frac) /* Find the first valid Buffer in the Queue */ BufferList = Source->queue; - while(BufferList) + while(BufferList && !BufferFmt) { - for(ALuint i{0};!BufferFmt && i < BufferList->mNumBuffers;i++) - BufferFmt = (*BufferList)[i]; - if(BufferFmt) break; + BufferFmt = BufferList->mBuffer; BufferList = BufferList->mNext.load(std::memory_order_relaxed); } if(!BufferFmt) @@ -464,7 +459,7 @@ ALboolean ApplyOffset(ALsource *Source, ALvoice *voice) ALbufferlistitem *BufferList{Source->queue}; while(BufferList && totalBufferLen <= offset) { - if(static_cast(BufferList->mMaxSamples) > offset-totalBufferLen) + if(BufferList->mSampleLen > offset-totalBufferLen) { /* Offset is in this buffer */ voice->mPosition.store(offset - totalBufferLen, std::memory_order_relaxed); @@ -472,7 +467,7 @@ ALboolean ApplyOffset(ALsource *Source, ALvoice *voice) voice->mCurrentBuffer.store(BufferList, std::memory_order_release); return AL_TRUE; } - totalBufferLen += BufferList->mMaxSamples; + totalBufferLen += BufferList->mSampleLen; BufferList = BufferList->mNext.load(std::memory_order_relaxed); } @@ -1197,12 +1192,9 @@ bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a if(buffer != nullptr) { /* Add the selected buffer to a one-item queue */ - auto newlist = static_cast(al_calloc(alignof(void*), - ALbufferlistitem::Sizeof(1u))); - newlist->mNext.store(nullptr, std::memory_order_relaxed); - newlist->mMaxSamples = buffer->SampleLen; - newlist->mNumBuffers = 1; - newlist->mBuffers[0] = buffer; + auto newlist = new ALbufferlistitem{}; + newlist->mSampleLen = buffer->SampleLen; + newlist->mBuffer = buffer; IncrementRef(buffer->ref); /* Source is now Static */ @@ -1220,13 +1212,11 @@ bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a /* Delete all elements in the previous queue */ while(oldlist != nullptr) { - ALbufferlistitem *temp{oldlist}; + std::unique_ptr temp{oldlist}; oldlist = temp->mNext.load(std::memory_order_relaxed); - std::for_each(temp->begin(), temp->end(), - [](ALbuffer *buffer) -> void - { if(buffer) DecrementRef(buffer->ref); }); - al_free(temp); + if(ALbuffer *buffer{temp->mBuffer}) + DecrementRef(buffer->ref); } return true; @@ -1769,8 +1759,7 @@ bool GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a case AL_BUFFER: CHECKSIZE(values, 1); BufferList = (Source->SourceType == AL_STATIC) ? Source->queue : nullptr; - values[0] = (BufferList && !BufferList->empty() && BufferList->front()) ? - BufferList->front()->id : 0; + values[0] = (BufferList && BufferList->mBuffer) ? BufferList->mBuffer->id : 0; return true; case AL_SOURCE_STATE: @@ -1786,7 +1775,7 @@ bool GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a { ALsizei count{0}; do { - count += BufferList->mNumBuffers; + ++count; BufferList = BufferList->mNext.load(std::memory_order_relaxed); } while(BufferList != nullptr); values[0] = count; @@ -1815,7 +1804,7 @@ bool GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a while(BufferList && BufferList != Current) { - played += BufferList->mNumBuffers; + ++played; BufferList = BufferList->mNext.load(std::memory_order_relaxed); } values[0] = played; @@ -2729,7 +2718,7 @@ START_API_FUNC * length buffer. */ ALbufferlistitem *BufferList{source->queue}; - while(BufferList && BufferList->mMaxSamples == 0) + while(BufferList && BufferList->mSampleLen == 0) BufferList = BufferList->mNext.load(std::memory_order_relaxed); /* If there's nothing to play, go right to stopped. */ @@ -2807,15 +2796,11 @@ START_API_FUNC voice->mPositionFrac.load(std::memory_order_relaxed) != 0 || voice->mCurrentBuffer.load(std::memory_order_relaxed) != BufferList; - auto buffer = std::find_if(BufferList->cbegin(), BufferList->cend(), - std::bind(std::not_equal_to{}, _1, nullptr)); - if(buffer != BufferList->cend()) - { - voice->mFrequency = (*buffer)->Frequency; - voice->mFmtChannels = (*buffer)->mFmtChannels; - voice->mNumChannels = ChannelsFromFmt((*buffer)->mFmtChannels); - voice->mSampleSize = BytesFromFmt((*buffer)->mFmtType); - } + ALbuffer *buffer{BufferList->mBuffer}; + voice->mFrequency = buffer->Frequency; + voice->mFmtChannels = buffer->mFmtChannels; + voice->mNumChannels = ChannelsFromFmt(buffer->mFmtChannels); + voice->mSampleSize = BytesFromFmt(buffer->mFmtType); /* Clear the stepping value so the mixer knows not to mix this until * the update gets applied. @@ -3101,11 +3086,9 @@ START_API_FUNC ALCdevice *device{context->mDevice.get()}; ALbuffer *BufferFmt{nullptr}; ALbufferlistitem *BufferList{source->queue}; - while(BufferList) + while(BufferList && !BufferFmt) { - for(ALuint i{0};!BufferFmt && i < BufferList->mNumBuffers;i++) - BufferFmt = (*BufferList)[i]; - if(BufferFmt) break; + BufferFmt = BufferList->mBuffer; BufferList = BufferList->mNext.load(std::memory_order_relaxed); } @@ -3123,128 +3106,22 @@ START_API_FUNC if(!BufferListStart) { - BufferListStart = static_cast(al_calloc(alignof(void*), - ALbufferlistitem::Sizeof(1u))); + BufferListStart = new ALbufferlistitem{}; BufferList = BufferListStart; } else { - auto item = static_cast(al_calloc(alignof(void*), - ALbufferlistitem::Sizeof(1u))); + auto item = new ALbufferlistitem{}; BufferList->mNext.store(item, std::memory_order_relaxed); BufferList = item; } BufferList->mNext.store(nullptr, std::memory_order_relaxed); - BufferList->mMaxSamples = buffer ? buffer->SampleLen : 0; - BufferList->mNumBuffers = 1; - BufferList->mBuffers[0] = buffer; - if(!buffer) continue; - - IncrementRef(buffer->ref); - - if(buffer->MappedAccess != 0 && !(buffer->MappedAccess&AL_MAP_PERSISTENT_BIT_SOFT)) - { - context->setError(AL_INVALID_OPERATION, "Queueing non-persistently mapped buffer %u", - buffer->id); - goto buffer_error; - } - - if(BufferFmt == nullptr) - BufferFmt = buffer; - else if(BufferFmt->Frequency != buffer->Frequency || - BufferFmt->mFmtChannels != buffer->mFmtChannels || - BufferFmt->OriginalType != buffer->OriginalType) - { - context->setError(AL_INVALID_OPERATION, "Queueing buffer with mismatched format"); - - buffer_error: - /* A buffer failed (invalid ID or format), so unlock and release - * each buffer we had. */ - while(BufferListStart) - { - ALbufferlistitem *next = BufferListStart->mNext.load(std::memory_order_relaxed); - std::for_each(BufferListStart->begin(), BufferListStart->end(), - [](ALbuffer *buffer) -> void - { if(buffer) DecrementRef(buffer->ref); }); - al_free(BufferListStart); - BufferListStart = next; - } - return; - } - } - /* All buffers good. */ - buflock.unlock(); - - /* Source is now streaming */ - source->SourceType = AL_STREAMING; - - if(!(BufferList=source->queue)) - source->queue = BufferListStart; - else - { - ALbufferlistitem *next; - while((next=BufferList->mNext.load(std::memory_order_relaxed)) != nullptr) - BufferList = next; - BufferList->mNext.store(BufferListStart, std::memory_order_release); - } -} -END_API_FUNC - -AL_API void AL_APIENTRY alSourceQueueBufferLayersSOFT(ALuint src, ALsizei nb, const ALuint *buffers) -START_API_FUNC -{ - ContextRef context{GetContextRef()}; - if UNLIKELY(!context) return; - - if UNLIKELY(nb < 0) - context->setError(AL_INVALID_VALUE, "Queueing %d buffer layers", nb); - if UNLIKELY(nb <= 0) return; - - std::lock_guard _{context->mSourceLock}; - ALsource *source{LookupSource(context.get(),src)}; - if UNLIKELY(!source) - SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid source ID %u", src); - - /* Can't queue on a Static Source */ - if UNLIKELY(source->SourceType == AL_STATIC) - SETERR_RETURN(context, AL_INVALID_OPERATION,, "Queueing onto static source %u", src); - - /* Check for a valid Buffer, for its frequency and format */ - ALCdevice *device{context->mDevice.get()}; - ALbuffer *BufferFmt{nullptr}; - ALbufferlistitem *BufferList{source->queue}; - while(BufferList) - { - for(ALuint i{0};!BufferFmt && i < BufferList->mNumBuffers;i++) - BufferFmt = (*BufferList)[i]; - if(BufferFmt) break; - BufferList = BufferList->mNext.load(std::memory_order_relaxed); - } - - std::unique_lock buflock{device->BufferLock}; - auto BufferListStart = static_cast(al_calloc(alignof(void*), - ALbufferlistitem::Sizeof(nb))); - BufferList = BufferListStart; - BufferList->mNext.store(nullptr, std::memory_order_relaxed); - BufferList->mMaxSamples = 0; - BufferList->mNumBuffers = 0; - - for(ALsizei i{0};i < nb;i++) - { - ALbuffer *buffer{nullptr}; - if(buffers[i] && (buffer=LookupBuffer(device, buffers[i])) == nullptr) - { - context->setError(AL_INVALID_NAME, "Queueing invalid buffer ID %u", buffers[i]); - goto buffer_error; - } - - BufferList->mBuffers[BufferList->mNumBuffers++] = buffer; + BufferList->mSampleLen = buffer ? buffer->SampleLen : 0; + BufferList->mBuffer = buffer; if(!buffer) continue; IncrementRef(buffer->ref); - BufferList->mMaxSamples = maxu(BufferList->mMaxSamples, buffer->SampleLen); - if(buffer->MappedAccess != 0 && !(buffer->MappedAccess&AL_MAP_PERSISTENT_BIT_SOFT)) { context->setError(AL_INVALID_OPERATION, "Queueing non-persistently mapped buffer %u", @@ -3265,12 +3142,9 @@ START_API_FUNC * each buffer we had. */ while(BufferListStart) { - ALbufferlistitem *next{BufferListStart->mNext.load(std::memory_order_relaxed)}; - std::for_each(BufferListStart->begin(), BufferListStart->end(), - [](ALbuffer *buffer) -> void - { if(buffer) DecrementRef(buffer->ref); }); - al_free(BufferListStart); - BufferListStart = next; + std::unique_ptr head{BufferListStart}; + BufferListStart = head->mNext.load(std::memory_order_relaxed); + if(ALbuffer *buffer{head->mBuffer}) DecrementRef(buffer->ref); } return; } @@ -3325,7 +3199,7 @@ START_API_FUNC if UNLIKELY(BufferList == Current) SETERR_RETURN(context, AL_INVALID_VALUE,, "Unqueueing pending buffers"); - ALuint i{BufferList->mNumBuffers}; + ALuint i{1u}; while(i < static_cast(nb)) { /* If the next bufferlist to check is NULL or is the current one, it's @@ -3336,47 +3210,22 @@ START_API_FUNC SETERR_RETURN(context, AL_INVALID_VALUE,, "Unqueueing pending buffers"); BufferList = next; - i += BufferList->mNumBuffers; + ++i; } while(nb > 0) { - ALbufferlistitem *head{source->queue}; - ALbufferlistitem *next{head->mNext.load(std::memory_order_relaxed)}; - for(i = 0;i < head->mNumBuffers && nb > 0;i++,nb--) - { - ALbuffer *buffer{(*head)[i]}; - if(!buffer) - *(buffers++) = 0; - else - { - *(buffers++) = buffer->id; - DecrementRef(buffer->ref); - } - } - if(i < head->mNumBuffers) + std::unique_ptr head{source->queue}; + source->queue = head->mNext.load(std::memory_order_relaxed); + + if(ALbuffer *buffer{head->mBuffer}) { - /* This head has some buffers left over, so move them to the front - * and update the sample and buffer count. - */ - ALuint max_length{0}; - ALuint j{0}; - while(i < head->mNumBuffers) - { - ALbuffer *buffer{(*head)[i++]}; - if(buffer) max_length = maxu(max_length, buffer->SampleLen); - head->mBuffers[j++] = buffer; - } - head->mMaxSamples = max_length; - head->mNumBuffers = j; - break; + *(buffers++) = buffer->id; + DecrementRef(buffer->ref); } - - /* Otherwise, free this item and set the source queue head to the next - * one. - */ - al_free(head); - source->queue = next; + else + *(buffers++) = 0; + --nb; } } END_API_FUNC @@ -3453,12 +3302,9 @@ ALsource::~ALsource() ALbufferlistitem *BufferList{queue}; while(BufferList != nullptr) { - ALbufferlistitem *next{BufferList->mNext.load(std::memory_order_relaxed)}; - std::for_each(BufferList->begin(), BufferList->end(), - [](ALbuffer *buffer) -> void - { if(buffer) DecrementRef(buffer->ref); }); - al_free(BufferList); - BufferList = next; + std::unique_ptr head{BufferList}; + BufferList = head->mNext.load(std::memory_order_relaxed); + if(ALbuffer *buffer{BufferList->mBuffer}) DecrementRef(buffer->ref); } queue = nullptr; diff --git a/al/source.h b/al/source.h index a5d10cf9..05037fd3 100644 --- a/al/source.h +++ b/al/source.h @@ -10,6 +10,7 @@ #include "AL/alc.h" #include "alcontext.h" +#include "almalloc.h" #include "alnumeric.h" #include "alu.h" #include "vector.h" @@ -23,58 +24,11 @@ struct ALeffectslot; #define INVALID_VOICE_IDX static_cast(-1) struct ALbufferlistitem { - using element_type = ALbuffer*; - using value_type = ALbuffer*; - using index_type = size_t; - using difference_type = ptrdiff_t; - - using pointer = ALbuffer**; - using const_pointer = ALbuffer*const*; - using reference = ALbuffer*&; - using const_reference = ALbuffer*const&; - - using iterator = pointer; - using const_iterator = const_pointer; - using reverse_iterator = std::reverse_iterator; - using const_reverse_iterator = std::reverse_iterator; - - - std::atomic mNext; - ALuint mMaxSamples; - ALuint mNumBuffers; - element_type mBuffers[]; - - static constexpr size_t Sizeof(size_t num_buffers) noexcept - { - return maxz(offsetof(ALbufferlistitem, mBuffers) + sizeof(element_type)*num_buffers, - sizeof(ALbufferlistitem)); - } - - reference front() { return mBuffers[0]; } - const_reference front() const { return mBuffers[0]; } - reference back() { return mBuffers[mNumBuffers-1]; } - const_reference back() const { return mBuffers[mNumBuffers-1]; } - reference operator[](index_type idx) { return mBuffers[idx]; } - const_reference operator[](index_type idx) const { return mBuffers[idx]; } - pointer data() noexcept { return mBuffers; } - const_pointer data() const noexcept { return mBuffers; } - - index_type size() const noexcept { return mNumBuffers; } - bool empty() const noexcept { return mNumBuffers == 0; } - - iterator begin() noexcept { return mBuffers; } - iterator end() noexcept { return mBuffers+mNumBuffers; } - const_iterator begin() const noexcept { return mBuffers; } - const_iterator end() const noexcept { return mBuffers+mNumBuffers; } - const_iterator cbegin() const noexcept { return mBuffers; } - const_iterator cend() const noexcept { return mBuffers+mNumBuffers; } - - reverse_iterator rbegin() noexcept { return reverse_iterator{end()}; } - reverse_iterator rend() noexcept { return reverse_iterator{begin()}; } - const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator{end()}; } - const_reverse_iterator rend() const noexcept { return const_reverse_iterator{begin()}; } - const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator{cend()}; } - const_reverse_iterator crend() const noexcept { return const_reverse_iterator{cbegin()}; } + std::atomic mNext{nullptr}; + ALuint mSampleLen{0u}; + ALbuffer *mBuffer{nullptr}; + + DEF_NEWDEL(ALbufferlistitem) }; diff --git a/alc/inprogext.h b/alc/inprogext.h index 15881b59..ad3ea288 100644 --- a/alc/inprogext.h +++ b/alc/inprogext.h @@ -72,14 +72,6 @@ AL_API void AL_APIENTRY alGetPointervSOFT(ALenum pname, void **values); #endif #endif -#ifndef AL_SOFT_buffer_layers -#define AL_SOFT_buffer_layers -typedef void (AL_APIENTRY*LPALSOURCEQUEUEBUFFERLAYERSSOFT)(ALuint src, ALsizei nb, const ALuint *buffers); -#ifdef AL_ALEXT_PROTOTYPES -AL_API void AL_APIENTRY alSourceQueueBufferLayersSOFT(ALuint src, ALsizei nb, const ALuint *buffers); -#endif -#endif - #ifndef AL_SOFT_effect_chain #define AL_SOFT_effect_chain #define AL_EFFECTSLOT_TARGET_SOFT 0xf000 diff --git a/alc/mixvoice.cpp b/alc/mixvoice.cpp index cf3eeb50..295b1352 100644 --- a/alc/mixvoice.cpp +++ b/alc/mixvoice.cpp @@ -372,7 +372,7 @@ inline void LoadSampleArray(ALfloat *RESTRICT dst, const al::byte *src, ALint sr const SampleType *RESTRICT ssrc{reinterpret_cast(src)}; for(ALsizei i{0};i < samples;i++) - dst[i] += FmtTypeTraits::to_float(ssrc[i*srcstep]); + dst[i] = FmtTypeTraits::to_float(ssrc[i*srcstep]); } void LoadSamples(ALfloat *RESTRICT dst, const al::byte *src, ALint srcstep, FmtType srctype, @@ -395,12 +395,9 @@ ALfloat *LoadBufferStatic(ALbufferlistitem *BufferListItem, ALbufferlistitem *&B const ALsizei NumChannels, const ALsizei SampleSize, const ALsizei chan, ALuint DataPosInt, al::span SrcBuffer) { - /* TODO: For static sources, loop points are taken from the first buffer - * (should be adjusted by any buffer offset, to possibly be added later). - */ - const ALbuffer *Buffer0{BufferListItem->front()}; - const ALuint LoopStart{Buffer0->LoopStart}; - const ALuint LoopEnd{Buffer0->LoopEnd}; + const ALbuffer *Buffer{BufferListItem->mBuffer}; + const ALuint LoopStart{Buffer->LoopStart}; + const ALuint LoopEnd{Buffer->LoopEnd}; ASSUME(LoopStart >= 0); ASSUME(LoopEnd > LoopStart); @@ -409,75 +406,37 @@ ALfloat *LoadBufferStatic(ALbufferlistitem *BufferListItem, ALbufferlistitem *&B { BufferLoopItem = nullptr; - auto load_buffer = [DataPosInt,NumChannels,SampleSize,chan,SrcBuffer](size_t CompLen, const ALbuffer *buffer) -> size_t - { - if(DataPosInt >= buffer->SampleLen) - return CompLen; - - /* Load what's left to play from the buffer */ - const size_t DataSize{std::min(SrcBuffer.size(), - buffer->SampleLen - DataPosInt)}; - CompLen = std::max(CompLen, DataSize); - - const al::byte *Data{buffer->mData.data()}; - Data += (DataPosInt*NumChannels + chan)*SampleSize; - - LoadSamples(SrcBuffer.data(), Data, NumChannels, buffer->mFmtType, DataSize); - return CompLen; - }; - /* It's impossible to have a buffer list item with no entries. */ - ASSUME(BufferListItem->mNumBuffers > 0); - SrcBuffer = SrcBuffer.subspan(std::accumulate(BufferListItem->begin(), - BufferListItem->end(), size_t{0u}, load_buffer)); + /* Load what's left to play from the buffer */ + const size_t DataSize{minz(SrcBuffer.size(), Buffer->SampleLen-DataPosInt)}; + + const al::byte *Data{Buffer->mData.data()}; + Data += (DataPosInt*NumChannels + chan)*SampleSize; + + LoadSamples(SrcBuffer.data(), Data, NumChannels, Buffer->mFmtType, DataSize); + SrcBuffer = SrcBuffer.subspan(DataSize); } else { - const al::span SrcData{SrcBuffer.first( - std::min(SrcBuffer.size(), LoopEnd - DataPosInt))}; + /* Load what's left of this loop iteration */ + const size_t DataSize{minz(SrcBuffer.size(), LoopEnd-DataPosInt)}; - auto load_buffer = [DataPosInt,NumChannels,SampleSize,chan,SrcData](size_t CompLen, const ALbuffer *buffer) -> size_t - { - if(DataPosInt >= buffer->SampleLen) - return CompLen; + const al::byte *Data{Buffer->mData.data()}; + Data += (DataPosInt*NumChannels + chan)*SampleSize; - /* Load what's left of this loop iteration */ - const size_t DataSize{std::min(SrcData.size(), - buffer->SampleLen - DataPosInt)}; - CompLen = std::max(CompLen, DataSize); - - const al::byte *Data{buffer->mData.data()}; - Data += (DataPosInt*NumChannels + chan)*SampleSize; - - LoadSamples(SrcData.data(), Data, NumChannels, buffer->mFmtType, DataSize); - return CompLen; - }; - ASSUME(BufferListItem->mNumBuffers > 0); - SrcBuffer = SrcBuffer.subspan(std::accumulate(BufferListItem->begin(), - BufferListItem->end(), size_t{0u}, load_buffer)); + LoadSamples(SrcBuffer.data(), Data, NumChannels, Buffer->mFmtType, DataSize); + SrcBuffer = SrcBuffer.subspan(DataSize); + /* Load any repeats of the loop we can to fill the buffer. */ const auto LoopSize = static_cast(LoopEnd - LoopStart); while(!SrcBuffer.empty()) { - const al::span SrcData{SrcBuffer.first( - std::min(SrcBuffer.size(), LoopSize))}; - - auto load_buffer_loop = [LoopStart,NumChannels,SampleSize,chan,SrcData](size_t CompLen, const ALbuffer *buffer) -> size_t - { - if(LoopStart >= buffer->SampleLen) - return CompLen; - - const size_t DataSize{std::min(SrcData.size(), - buffer->SampleLen-LoopStart)}; - CompLen = std::max(CompLen, DataSize); + const size_t DataSize{minz(SrcBuffer.size(), LoopSize)}; - const al::byte *Data{buffer->mData.data()}; - Data += (LoopStart*NumChannels + chan)*SampleSize; + const al::byte *Data{Buffer->mData.data()}; + Data += (LoopStart*NumChannels + chan)*SampleSize; - LoadSamples(SrcData.data(), Data, NumChannels, buffer->mFmtType, DataSize); - return CompLen; - }; - SrcBuffer = SrcBuffer.subspan(std::accumulate(BufferListItem->begin(), - BufferListItem->end(), size_t{0u}, load_buffer_loop)); + LoadSamples(SrcBuffer.data(), Data, NumChannels, Buffer->mFmtType, DataSize); + SrcBuffer = SrcBuffer.subspan(DataSize); } } return SrcBuffer.begin(); @@ -490,35 +449,24 @@ ALfloat *LoadBufferQueue(ALbufferlistitem *BufferListItem, ALbufferlistitem *Buf /* Crawl the buffer queue to fill in the temp buffer */ while(BufferListItem && !SrcBuffer.empty()) { - if(DataPosInt >= BufferListItem->mMaxSamples) + ALbuffer *Buffer{BufferListItem->mBuffer}; + if(!(Buffer && DataPosInt < Buffer->SampleLen)) { - DataPosInt -= BufferListItem->mMaxSamples; + if(Buffer) DataPosInt -= Buffer->SampleLen; BufferListItem = BufferListItem->mNext.load(std::memory_order_acquire); if(!BufferListItem) BufferListItem = BufferLoopItem; continue; } - auto load_buffer = [DataPosInt,NumChannels,SampleSize,chan,SrcBuffer](size_t CompLen, const ALbuffer *buffer) -> size_t - { - if(!buffer) return CompLen; - if(DataPosInt >= buffer->SampleLen) - return CompLen; + const size_t DataSize{std::min(SrcBuffer.size(), Buffer->SampleLen-DataPosInt)}; - const size_t DataSize{std::min(SrcBuffer.size(), buffer->SampleLen-DataPosInt)}; - CompLen = std::max(CompLen, DataSize); + const al::byte *Data{Buffer->mData.data()}; + Data += (DataPosInt*NumChannels + chan)*SampleSize; - const al::byte *Data{buffer->mData.data()}; - Data += (DataPosInt*NumChannels + chan)*SampleSize; + LoadSamples(SrcBuffer.data(), Data, NumChannels, Buffer->mFmtType, DataSize); + SrcBuffer = SrcBuffer.subspan(DataSize); + if(SrcBuffer.empty()) break; - LoadSamples(SrcBuffer.data(), Data, NumChannels, buffer->mFmtType, DataSize); - return CompLen; - }; - ASSUME(BufferListItem->mNumBuffers > 0); - SrcBuffer = SrcBuffer.subspan(std::accumulate(BufferListItem->begin(), - BufferListItem->end(), size_t{0u}, load_buffer)); - - if(SrcBuffer.empty()) - break; DataPosInt = 0; BufferListItem = BufferListItem->mNext.load(std::memory_order_acquire); if(!BufferListItem) BufferListItem = BufferLoopItem; @@ -640,10 +588,11 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc ALvoice::ChannelData &chandata = voice->mChans[chan]; const al::span SrcData{Device->SourceData, SrcBufferSize}; - /* Load the previous samples into the source data first, and clear the rest. */ + /* Load the previous samples into the source data first, then load + * what we can from the buffer queue. + */ auto srciter = std::copy_n(chandata.mPrevSamples.begin(), MAX_RESAMPLE_PADDING, SrcData.begin()); - std::fill(srciter, SrcData.end(), 0.0f); if UNLIKELY(!BufferListItem) srciter = std::copy(chandata.mPrevSamples.begin()+MAX_RESAMPLE_PADDING, @@ -875,7 +824,7 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc if(BufferLoopItem) { /* Handle looping static source */ - const ALbuffer *Buffer{BufferListItem->front()}; + const ALbuffer *Buffer{BufferListItem->mBuffer}; const ALuint LoopStart{Buffer->LoopStart}; const ALuint LoopEnd{Buffer->LoopEnd}; if(DataPosInt >= LoopEnd) @@ -887,7 +836,7 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc else { /* Handle non-looping static source */ - if(DataPosInt >= BufferListItem->mMaxSamples) + if(DataPosInt >= BufferListItem->mSampleLen) { if LIKELY(vstate == ALvoice::Playing) vstate = ALvoice::Stopped; @@ -899,12 +848,12 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc else while(1) { /* Handle streaming source */ - if(BufferListItem->mMaxSamples > DataPosInt) + if(BufferListItem->mSampleLen > DataPosInt) break; - DataPosInt -= BufferListItem->mMaxSamples; + DataPosInt -= BufferListItem->mSampleLen; - buffers_done += BufferListItem->mNumBuffers; + ++buffers_done; BufferListItem = BufferListItem->mNext.load(std::memory_order_relaxed); if(!BufferListItem && !(BufferListItem=BufferLoopItem)) { -- cgit v1.2.3 From 50d16d2422febe2f4f56e7f29794778b10606b3a Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 11 Aug 2019 22:48:18 -0700 Subject: Don't use INT_MAX for unknown span lengths 32-bit doesn't like it, for some reason. Use the largest possible length it could be. --- al/source.cpp | 50 ++++++++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 26 deletions(-) (limited to 'al/source.cpp') diff --git a/al/source.cpp b/al/source.cpp index 4bdf51fe..b20f6e81 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -737,6 +737,8 @@ void SendStateChangeEvent(ALCcontext *context, ALuint id, ALenum state) } +constexpr size_t MaxValues{6u}; + ALuint FloatValsByProp(ALenum prop) { switch(static_cast(prop)) @@ -866,20 +868,16 @@ bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a bool SetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, const al::span values); #define CHECKSIZE(v, s) do { \ - if UNLIKELY((v).size() != INT_MAX && (v).size() != (s)) \ - { \ - Context->setError(AL_INVALID_ENUM, \ - "Property 0x%04x expects %d value(s), got %zu", prop, (s), \ - (v).size()); \ - return false; \ - } \ + if LIKELY((v).size() == (s) || (v).size() == MaxValues) break; \ + Context->setError(AL_INVALID_ENUM, \ + "Property 0x%04x expects %d value(s), got %zu", prop, (s), \ + (v).size()); \ + return false; \ } while(0) #define CHECKVAL(x) do { \ - if UNLIKELY(!(x)) \ - { \ - Context->setError(AL_INVALID_VALUE, "Value out of range"); \ - return false; \ - } \ + if LIKELY(x) break; \ + Context->setError(AL_INVALID_VALUE, "Value out of range"); \ + return false; \ } while(0) bool UpdateSourceProps(ALsource *source, ALCcontext *context) @@ -1434,8 +1432,8 @@ bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a bool SetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, const al::span values) { - ALfloat fvals[6]; - ALint ivals[3]; + ALfloat fvals[MaxValues]; + ALint ivals[MaxValues]; switch(prop) { @@ -1553,7 +1551,7 @@ bool GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a ALCdevice *device{Context->mDevice.get()}; ClockLatency clocktime; std::chrono::nanoseconds srcclock; - ALint ivals[3]; + ALint ivals[MaxValues]; ALboolean err; switch(prop) @@ -1741,7 +1739,7 @@ bool GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a bool GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const al::span values) { ALbufferlistitem *BufferList; - ALdouble dvals[6]; + ALdouble dvals[MaxValues]; ALboolean err; switch(prop) @@ -1926,8 +1924,8 @@ bool GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, const ALCdevice *device = Context->mDevice.get(); ClockLatency clocktime; std::chrono::nanoseconds srcclock; - ALdouble dvals[6]; - ALint ivals[3]; + ALdouble dvals[MaxValues]; + ALint ivals[MaxValues]; ALboolean err; switch(prop) @@ -2199,7 +2197,7 @@ START_API_FUNC else if UNLIKELY(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); else - SetSourcefv(Source, context.get(), static_cast(param), {values, INT_MAX}); + SetSourcefv(Source, context.get(), static_cast(param), {values, MaxValues}); } END_API_FUNC @@ -2259,7 +2257,7 @@ START_API_FUNC else { const ALuint count{DoubleValsByProp(param)}; - ALfloat fvals[6]; + ALfloat fvals[MaxValues]; for(ALuint i{0};i < count;i++) fvals[i] = static_cast(values[i]); SetSourcefv(Source, context.get(), static_cast(param), {fvals, count}); @@ -2317,7 +2315,7 @@ START_API_FUNC else if UNLIKELY(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); else - SetSourceiv(Source, context.get(), static_cast(param), {values, INT_MAX}); + SetSourceiv(Source, context.get(), static_cast(param), {values, MaxValues}); } END_API_FUNC @@ -2371,7 +2369,7 @@ START_API_FUNC else if UNLIKELY(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); else - SetSourcei64v(Source, context.get(), static_cast(param), {values, INT_MAX}); + SetSourcei64v(Source, context.get(), static_cast(param), {values, MaxValues}); } END_API_FUNC @@ -2437,7 +2435,7 @@ START_API_FUNC else { const ALuint count{FloatValsByProp(param)}; - ALdouble dvals[6]; + ALdouble dvals[MaxValues]; if(GetSourcedv(Source, context.get(), static_cast(param), {dvals, count})) { for(ALuint i{0};i < count;i++) @@ -2503,7 +2501,7 @@ START_API_FUNC else if UNLIKELY(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); else - GetSourcedv(Source, context.get(), static_cast(param), {values, INT_MAX}); + GetSourcedv(Source, context.get(), static_cast(param), {values, MaxValues}); } END_API_FUNC @@ -2563,7 +2561,7 @@ START_API_FUNC else if UNLIKELY(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); else - GetSourceiv(Source, context.get(), static_cast(param), {values, INT_MAX}); + GetSourceiv(Source, context.get(), static_cast(param), {values, MaxValues}); } END_API_FUNC @@ -2623,7 +2621,7 @@ START_API_FUNC else if UNLIKELY(!values) context->setError(AL_INVALID_VALUE, "NULL pointer"); else - GetSourcei64v(Source, context.get(), static_cast(param), {values, INT_MAX}); + GetSourcei64v(Source, context.get(), static_cast(param), {values, MaxValues}); } END_API_FUNC -- cgit v1.2.3 From 81d17bb80f77cc5d078547b5fb102a2b44fecee0 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 12 Aug 2019 14:30:47 -0700 Subject: Fix some return types --- al/source.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'al/source.cpp') diff --git a/al/source.cpp b/al/source.cpp index b20f6e81..018e49a0 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -1552,7 +1552,7 @@ bool GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a ClockLatency clocktime; std::chrono::nanoseconds srcclock; ALint ivals[MaxValues]; - ALboolean err; + bool err; switch(prop) { @@ -1719,7 +1719,7 @@ bool GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a case AL_SOURCE_RESAMPLER_SOFT: case AL_SOURCE_SPATIALIZE_SOFT: CHECKSIZE(values, 1); - if((err=GetSourceiv(Source, Context, prop, {ivals, 1u})) != AL_FALSE) + if((err=GetSourceiv(Source, Context, prop, {ivals, 1u})) != false) values[0] = static_cast(ivals[0]); return err; @@ -1740,7 +1740,7 @@ bool GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a { ALbufferlistitem *BufferList; ALdouble dvals[MaxValues]; - ALboolean err; + bool err; switch(prop) { @@ -1926,7 +1926,7 @@ bool GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, const std::chrono::nanoseconds srcclock; ALdouble dvals[MaxValues]; ALint ivals[MaxValues]; - ALboolean err; + bool err; switch(prop) { @@ -1956,7 +1956,7 @@ bool GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, const CHECKSIZE(values, 2); values[0] = GetSourceSampleOffset(Source, Context, &srcclock); values[1] = srcclock.count(); - return AL_TRUE; + return true; /* 1x float/double */ case AL_CONE_INNER_ANGLE: -- cgit v1.2.3 From 91ff01d1ad3c2995266902f41454c04e2b6e5d47 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 13 Aug 2019 20:33:26 -0700 Subject: Don't explicitly inline a particular function --- al/source.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'al/source.cpp') diff --git a/al/source.cpp b/al/source.cpp index 018e49a0..95c3305e 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -74,7 +74,7 @@ namespace { using namespace std::placeholders; -inline ALvoice *GetSourceVoice(ALsource *source, ALCcontext *context) +ALvoice *GetSourceVoice(ALsource *source, ALCcontext *context) { ALuint idx{source->VoiceIdx}; if(idx < context->mVoiceCount.load(std::memory_order_relaxed)) -- cgit v1.2.3 From 024d5d900aa7f9e3435459b0a8cfe354dc8e21fd Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 21 Aug 2019 03:00:19 -0700 Subject: Dereference the correct buffer when destructing a source --- al/source.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'al/source.cpp') diff --git a/al/source.cpp b/al/source.cpp index 95c3305e..49f2fb2a 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -3302,7 +3302,7 @@ ALsource::~ALsource() { std::unique_ptr head{BufferList}; BufferList = head->mNext.load(std::memory_order_relaxed); - if(ALbuffer *buffer{BufferList->mBuffer}) DecrementRef(buffer->ref); + if(ALbuffer *buffer{head->mBuffer}) DecrementRef(buffer->ref); } queue = nullptr; -- cgit v1.2.3 From 3973334a64f0aa428c9cbd06c89cfb60951810c8 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 31 Aug 2019 15:49:34 -0700 Subject: Store the voice fraction offset as unsigned --- al/source.cpp | 22 +++++++++++----------- alc/alu.h | 4 ++-- alc/mixer/defs.h | 2 +- alc/mixer/mixer_c.cpp | 27 +++++++++++++-------------- alc/mixer/mixer_neon.cpp | 36 +++++++++++++++++------------------- alc/mixer/mixer_sse.cpp | 9 ++++----- alc/mixer/mixer_sse2.cpp | 9 ++++----- alc/mixer/mixer_sse41.cpp | 9 ++++----- alc/mixvoice.cpp | 3 +-- 9 files changed, 57 insertions(+), 64 deletions(-) (limited to 'al/source.cpp') diff --git a/al/source.cpp b/al/source.cpp index 49f2fb2a..d9a7cb87 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -195,7 +195,7 @@ int64_t GetSourceSampleOffset(ALsource *Source, ALCcontext *context, std::chrono Current = voice->mCurrentBuffer.load(std::memory_order_relaxed); readPos = uint64_t{voice->mPosition.load(std::memory_order_relaxed)} << 32; - readPos |= int64_t{voice->mPositionFrac.load(std::memory_order_relaxed)} << + readPos |= uint64_t{voice->mPositionFrac.load(std::memory_order_relaxed)} << (32-FRACTIONBITS); } std::atomic_thread_fence(std::memory_order_acquire); @@ -206,7 +206,7 @@ int64_t GetSourceSampleOffset(ALsource *Source, ALCcontext *context, std::chrono const ALbufferlistitem *BufferList{Source->queue}; while(BufferList && BufferList != Current) { - readPos += int64_t{BufferList->mSampleLen} << 32; + readPos += uint64_t{BufferList->mSampleLen} << 32; BufferList = BufferList->mNext.load(std::memory_order_relaxed); } readPos = minu64(readPos, 0x7fffffffffffffff_u64); @@ -254,7 +254,7 @@ ALdouble GetSourceSecOffset(ALsource *Source, ALCcontext *context, std::chrono:: while(BufferList && BufferList != Current) { if(!BufferFmt) BufferFmt = BufferList->mBuffer; - readPos += int64_t{BufferList->mSampleLen} << FRACTIONBITS; + readPos += uint64_t{BufferList->mSampleLen} << FRACTIONBITS; BufferList = BufferList->mNext.load(std::memory_order_relaxed); } @@ -265,7 +265,7 @@ ALdouble GetSourceSecOffset(ALsource *Source, ALCcontext *context, std::chrono:: } assert(BufferFmt != nullptr); - offset = static_cast(readPos) / static_castFRACTIONONE / + offset = static_cast(readPos) / ALdouble{FRACTIONONE} / static_cast(BufferFmt->Frequency); } @@ -283,7 +283,7 @@ ALdouble GetSourceOffset(ALsource *Source, ALenum name, ALCcontext *context) ALCdevice *device{context->mDevice.get()}; const ALbufferlistitem *Current; ALuint readPos; - ALsizei readPosFrac; + ALuint readPosFrac; ALuint refcount; ALvoice *voice; @@ -382,7 +382,7 @@ ALdouble GetSourceOffset(ALsource *Source, ALenum name, ALCcontext *context) * or Second offset supplied by the application). This takes into account the * fact that the buffer format may have been modifed since. */ -ALboolean GetSampleOffset(ALsource *Source, ALuint *offset, ALsizei *frac) +ALboolean GetSampleOffset(ALsource *Source, ALuint *offset, ALuint *frac) { const ALbuffer *BufferFmt{nullptr}; const ALbufferlistitem *BufferList; @@ -426,14 +426,14 @@ ALboolean GetSampleOffset(ALsource *Source, ALuint *offset, ALsizei *frac) case AL_SAMPLE_OFFSET: dblfrac = modf(Source->Offset, &dbloff); - *offset = static_cast(mind(dbloff, std::numeric_limits::max())); - *frac = static_cast(mind(dblfrac*FRACTIONONE, FRACTIONONE-1.0)); + *offset = static_cast(mind(dbloff, std::numeric_limits::max())); + *frac = static_cast(mind(dblfrac*FRACTIONONE, FRACTIONONE-1.0)); break; case AL_SEC_OFFSET: dblfrac = modf(Source->Offset*BufferFmt->Frequency, &dbloff); - *offset = static_cast(mind(dbloff, std::numeric_limits::max())); - *frac = static_cast(mind(dblfrac*FRACTIONONE, FRACTIONONE-1.0)); + *offset = static_cast(mind(dbloff, std::numeric_limits::max())); + *frac = static_cast(mind(dblfrac*FRACTIONONE, FRACTIONONE-1.0)); break; } Source->OffsetType = AL_NONE; @@ -451,7 +451,7 @@ ALboolean ApplyOffset(ALsource *Source, ALvoice *voice) { /* Get sample frame offset */ ALuint offset{0u}; - ALsizei frac{0}; + ALuint frac{0u}; if(!GetSampleOffset(Source, &offset, &frac)) return AL_FALSE; diff --git a/alc/alu.h b/alc/alu.h index da6f6a94..51c5f702 100644 --- a/alc/alu.h +++ b/alc/alu.h @@ -81,7 +81,7 @@ union InterpState { }; using ResamplerFunc = const ALfloat*(*)(const InterpState *state, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, const al::span dst); + ALuint frac, ALint increment, const al::span dst); void BsincPrepare(const ALuint increment, BsincState *state, const BSincTable *table); @@ -219,7 +219,7 @@ struct ALvoice { */ std::atomic mPosition; /** Fractional (fixed-point) offset to the next sample. */ - std::atomic mPositionFrac; + std::atomic mPositionFrac; /* Current buffer queue item being played. */ std::atomic mCurrentBuffer; diff --git a/alc/mixer/defs.h b/alc/mixer/defs.h index bb5ca56e..4aa3c6b6 100644 --- a/alc/mixer/defs.h +++ b/alc/mixer/defs.h @@ -27,7 +27,7 @@ enum ResampleType { }; template -const ALfloat *Resample_(const InterpState *state, const ALfloat *RESTRICT src, ALsizei frac, +const ALfloat *Resample_(const InterpState *state, const ALfloat *RESTRICT src, ALuint frac, ALint increment, const al::span dst); template diff --git a/alc/mixer/mixer_c.cpp b/alc/mixer/mixer_c.cpp index dbdbf16d..7a79d1e2 100644 --- a/alc/mixer/mixer_c.cpp +++ b/alc/mixer/mixer_c.cpp @@ -13,23 +13,23 @@ namespace { -inline ALfloat do_point(const InterpState&, const ALfloat *RESTRICT vals, const ALsizei) +inline ALfloat do_point(const InterpState&, const ALfloat *RESTRICT vals, const ALuint) { return vals[0]; } -inline ALfloat do_lerp(const InterpState&, const ALfloat *RESTRICT vals, const ALsizei frac) +inline ALfloat do_lerp(const InterpState&, const ALfloat *RESTRICT vals, const ALuint frac) { return lerp(vals[0], vals[1], frac * (1.0f/FRACTIONONE)); } -inline ALfloat do_cubic(const InterpState&, const ALfloat *RESTRICT vals, const ALsizei frac) +inline ALfloat do_cubic(const InterpState&, const ALfloat *RESTRICT vals, const ALuint frac) { return cubic(vals[0], vals[1], vals[2], vals[3], frac * (1.0f/FRACTIONONE)); } -inline ALfloat do_bsinc(const InterpState &istate, const ALfloat *RESTRICT vals, const ALsizei frac) +inline ALfloat do_bsinc(const InterpState &istate, const ALfloat *RESTRICT vals, const ALuint frac) { ASSUME(istate.bsinc.m > 0); // Calculate the phase index and factor. #define FRAC_PHASE_BITDIFF (FRACTIONBITS-BSINC_PHASE_BITS) - const ALsizei pi{frac >> FRAC_PHASE_BITDIFF}; + const ALuint pi{frac >> FRAC_PHASE_BITDIFF}; const ALfloat pf{(frac & ((1< const ALfloat *DoResample(const InterpState *state, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, const al::span dst) + ALuint frac, ALint increment, const al::span dst) { ASSUME(increment > 0); - ASSUME(frac >= 0); const InterpState istate{*state}; auto proc_sample = [&src,&frac,istate,increment]() -> ALfloat @@ -68,7 +67,7 @@ const ALfloat *DoResample(const InterpState *state, const ALfloat *RESTRICT src, } // namespace template<> -const ALfloat *Resample_(const InterpState*, const ALfloat *RESTRICT src, ALsizei, +const ALfloat *Resample_(const InterpState*, const ALfloat *RESTRICT src, ALuint, ALint, const al::span dst) { #if defined(HAVE_SSE) || defined(HAVE_NEON) @@ -82,22 +81,22 @@ const ALfloat *Resample_(const InterpState*, const ALfloat *RESTRI template<> const ALfloat *Resample_(const InterpState *state, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, const al::span dst) + ALuint frac, ALint increment, const al::span dst) { return DoResample(state, src, frac, increment, dst); } template<> const ALfloat *Resample_(const InterpState *state, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, const al::span dst) + ALuint frac, ALint increment, const al::span dst) { return DoResample(state, src, frac, increment, dst); } template<> const ALfloat *Resample_(const InterpState *state, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, const al::span dst) + ALuint frac, ALint increment, const al::span dst) { return DoResample(state, src-1, frac, increment, dst); } template<> const ALfloat *Resample_(const InterpState *state, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, const al::span dst) + ALuint frac, ALint increment, const al::span dst) { return DoResample(state, src-state->bsinc.l, frac, increment, dst); } diff --git a/alc/mixer/mixer_neon.cpp b/alc/mixer/mixer_neon.cpp index 472eae1b..d3e89aec 100644 --- a/alc/mixer/mixer_neon.cpp +++ b/alc/mixer/mixer_neon.cpp @@ -16,7 +16,7 @@ template<> const ALfloat *Resample_(const InterpState*, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, const al::span dst) + ALuint frac, ALint increment, const al::span dst) { const int32x4_t increment4 = vdupq_n_s32(increment*4); const float32x4_t fracOne4 = vdupq_n_f32(1.0f/FRACTIONONE); @@ -24,7 +24,6 @@ const ALfloat *Resample_(const InterpState*, const ALfloat *RES alignas(16) ALsizei pos_[4], frac_[4]; int32x4_t pos4, frac4; - ASSUME(frac >= 0); ASSUME(increment > 0); InitiatePositionArrays(frac, increment, frac_, pos_, 4); @@ -35,17 +34,17 @@ const ALfloat *Resample_(const InterpState*, const ALfloat *RES const auto aligned_end = (dst.size()&~3) + dst_iter; while(dst_iter != aligned_end) { - const int pos0 = vgetq_lane_s32(pos4, 0); - const int pos1 = vgetq_lane_s32(pos4, 1); - const int pos2 = vgetq_lane_s32(pos4, 2); - const int pos3 = vgetq_lane_s32(pos4, 3); - const float32x4_t val1 = (float32x4_t){src[pos0], src[pos1], src[pos2], src[pos3]}; - const float32x4_t val2 = (float32x4_t){src[pos0+1], src[pos1+1], src[pos2+1], src[pos3+1]}; + const int pos0{vgetq_lane_s32(pos4, 0)}; + const int pos1{vgetq_lane_s32(pos4, 1)}; + const int pos2{vgetq_lane_s32(pos4, 2)}; + const int pos3{vgetq_lane_s32(pos4, 3)}; + const float32x4_t val1{src[pos0], src[pos1], src[pos2], src[pos3]}; + const float32x4_t val2{src[pos0+1], src[pos1+1], src[pos2+1], src[pos3+1]}; /* val1 + (val2-val1)*mu */ - const float32x4_t r0 = vsubq_f32(val2, val1); - const float32x4_t mu = vmulq_f32(vcvtq_f32_s32(frac4), fracOne4); - const float32x4_t out = vmlaq_f32(val1, mu, r0); + const float32x4_t r0{vsubq_f32(val2, val1)}; + const float32x4_t mu{vmulq_f32(vcvtq_f32_s32(frac4), fracOne4)}; + const float32x4_t out{vmlaq_f32(val1, mu, r0)}; vst1q_f32(dst_iter, out); dst_iter += 4; @@ -58,15 +57,15 @@ const ALfloat *Resample_(const InterpState*, const ALfloat *RES /* NOTE: These four elements represent the position *after* the last four * samples, so the lowest element is the next position to resample. */ - ALsizei pos{vgetq_lane_s32(pos4, 0)}; + src += static_cast(vgetq_lane_s32(pos4, 0)); frac = vgetq_lane_s32(frac4, 0); while(dst_iter != dst.end()) { - *(dst_iter++) = lerp(src[pos], src[pos+1], frac * (1.0f/FRACTIONONE)); + *(dst_iter++) = lerp(src[0], src[1], frac * (1.0f/FRACTIONONE)); frac += increment; - pos += frac>>FRACTIONBITS; + src += frac>>FRACTIONBITS; frac &= FRACTIONMASK; } return dst.begin(); @@ -74,22 +73,21 @@ const ALfloat *Resample_(const InterpState*, const ALfloat *RES template<> const ALfloat *Resample_(const InterpState *state, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, const al::span dst) + ALuint frac, ALint increment, const al::span dst) { const ALfloat *const filter{state->bsinc.filter}; const float32x4_t sf4{vdupq_n_f32(state->bsinc.sf)}; - const ALsizei m{state->bsinc.m}; + const ptrdiff_t m{state->bsinc.m}; ASSUME(m > 0); ASSUME(increment > 0); - ASSUME(frac >= 0); src -= state->bsinc.l; for(float &out_sample : dst) { // Calculate the phase index and factor. #define FRAC_PHASE_BITDIFF (FRACTIONBITS-BSINC_PHASE_BITS) - const ALsizei pi{frac >> FRAC_PHASE_BITDIFF}; + const ALuint pi{frac >> FRAC_PHASE_BITDIFF}; const ALfloat pf{(frac & ((1<(const InterpState *state, const ALflo const float *scd{fil + m}; const float *phd{scd + m}; const float *spd{phd + m}; - ALsizei td{m >> 2}; + ptrdiff_t td{m >> 2}; size_t j{0u}; do { diff --git a/alc/mixer/mixer_sse.cpp b/alc/mixer/mixer_sse.cpp index 8d2abc88..05ebe26f 100644 --- a/alc/mixer/mixer_sse.cpp +++ b/alc/mixer/mixer_sse.cpp @@ -15,22 +15,21 @@ template<> const ALfloat *Resample_(const InterpState *state, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, const al::span dst) + ALuint frac, ALint increment, const al::span dst) { const ALfloat *const filter{state->bsinc.filter}; const __m128 sf4{_mm_set1_ps(state->bsinc.sf)}; - const ALsizei m{state->bsinc.m}; + const ptrdiff_t m{state->bsinc.m}; ASSUME(m > 0); ASSUME(increment > 0); - ASSUME(frac >= 0); src -= state->bsinc.l; for(float &out_sample : dst) { // Calculate the phase index and factor. #define FRAC_PHASE_BITDIFF (FRACTIONBITS-BSINC_PHASE_BITS) - const ALsizei pi{frac >> FRAC_PHASE_BITDIFF}; + const ALuint pi{frac >> FRAC_PHASE_BITDIFF}; const ALfloat pf{(frac & ((1<(const InterpState *state, const ALfloa const float *scd{fil + m}; const float *phd{scd + m}; const float *spd{phd + m}; - ALsizei td{m >> 2}; + ptrdiff_t td{m >> 2}; size_t j{0u}; #define MLA4(x, y, z) _mm_add_ps(x, _mm_mul_ps(y, z)) diff --git a/alc/mixer/mixer_sse2.cpp b/alc/mixer/mixer_sse2.cpp index e3443f4e..b126cd25 100644 --- a/alc/mixer/mixer_sse2.cpp +++ b/alc/mixer/mixer_sse2.cpp @@ -29,13 +29,12 @@ template<> const ALfloat *Resample_(const InterpState*, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, const al::span dst) + ALuint frac, ALint increment, const al::span dst) { const __m128i increment4{_mm_set1_epi32(increment*4)}; const __m128 fracOne4{_mm_set1_ps(1.0f/FRACTIONONE)}; const __m128i fracMask4{_mm_set1_epi32(FRACTIONMASK)}; - ASSUME(frac >= 0); ASSUME(increment > 0); alignas(16) ALsizei pos_[4], frac_[4]; @@ -70,15 +69,15 @@ const ALfloat *Resample_(const InterpState*, const ALfloat *RES /* NOTE: These four elements represent the position *after* the last four * samples, so the lowest element is the next position to resample. */ - ALsizei pos{_mm_cvtsi128_si32(pos4)}; + src += static_cast(_mm_cvtsi128_si32(pos4)); frac = _mm_cvtsi128_si32(frac4); while(dst_iter != dst.end()) { - *(dst_iter++) = lerp(src[pos], src[pos+1], frac * (1.0f/FRACTIONONE)); + *(dst_iter++) = lerp(src[0], src[1], frac * (1.0f/FRACTIONONE)); frac += increment; - pos += frac>>FRACTIONBITS; + src += frac>>FRACTIONBITS; frac &= FRACTIONMASK; } return dst.begin(); diff --git a/alc/mixer/mixer_sse41.cpp b/alc/mixer/mixer_sse41.cpp index 424b9b5f..06c51e6a 100644 --- a/alc/mixer/mixer_sse41.cpp +++ b/alc/mixer/mixer_sse41.cpp @@ -30,13 +30,12 @@ template<> const ALfloat *Resample_(const InterpState*, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, const al::span dst) + ALuint frac, ALint increment, const al::span dst) { const __m128i increment4{_mm_set1_epi32(increment*4)}; const __m128 fracOne4{_mm_set1_ps(1.0f/FRACTIONONE)}; const __m128i fracMask4{_mm_set1_epi32(FRACTIONMASK)}; - ASSUME(frac >= 0); ASSUME(increment > 0); alignas(16) ALsizei pos_[4], frac_[4]; @@ -71,15 +70,15 @@ const ALfloat *Resample_(const InterpState*, const ALfloat *RES /* NOTE: These four elements represent the position *after* the last four * samples, so the lowest element is the next position to resample. */ - ALsizei pos{_mm_cvtsi128_si32(pos4)}; + src += static_cast(_mm_cvtsi128_si32(pos4)); frac = _mm_cvtsi128_si32(frac4); while(dst_iter != dst.end()) { - *(dst_iter++) = lerp(src[pos], src[pos+1], frac * (1.0f/FRACTIONONE)); + *(dst_iter++) = lerp(src[0], src[1], frac * (1.0f/FRACTIONONE)); frac += increment; - pos += frac>>FRACTIONBITS; + src += frac>>FRACTIONBITS; frac &= FRACTIONMASK; } return dst.begin(); diff --git a/alc/mixvoice.cpp b/alc/mixvoice.cpp index 97583107..2d1a4655 100644 --- a/alc/mixvoice.cpp +++ b/alc/mixvoice.cpp @@ -482,7 +482,7 @@ void ALvoice::mix(State vstate, ALCcontext *Context, const ALuint SamplesToDo) /* Get voice info */ const bool isstatic{(mFlags&VOICE_IS_STATIC) != 0}; ALuint DataPosInt{mPosition.load(std::memory_order_relaxed)}; - ALsizei DataPosFrac{mPositionFrac.load(std::memory_order_relaxed)}; + ALuint DataPosFrac{mPositionFrac.load(std::memory_order_relaxed)}; ALbufferlistitem *BufferListItem{mCurrentBuffer.load(std::memory_order_relaxed)}; ALbufferlistitem *BufferLoopItem{mLoopBuffer.load(std::memory_order_relaxed)}; const ALsizei NumChannels{mNumChannels}; @@ -490,7 +490,6 @@ void ALvoice::mix(State vstate, ALCcontext *Context, const ALuint SamplesToDo) const ALint increment{mStep}; if(increment < 1) return; - ASSUME(DataPosFrac >= 0); ASSUME(NumChannels > 0); ASSUME(SampleSize > 0); ASSUME(increment > 0); -- cgit v1.2.3 From aee10ef60623e012e5edc6fcf31b2d71b2086bc9 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 1 Sep 2019 00:24:49 -0700 Subject: Hold the source lock in UpdateAllSourceProps --- al/source.cpp | 1 + alc/alc.cpp | 41 ++++++++++++++++++++--------------------- 2 files changed, 21 insertions(+), 21 deletions(-) (limited to 'al/source.cpp') diff --git a/al/source.cpp b/al/source.cpp index d9a7cb87..08e4bff6 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -3318,6 +3318,7 @@ ALsource::~ALsource() void UpdateAllSourceProps(ALCcontext *context) { + std::lock_guard _{context->mSourceLock}; auto voices_end = context->mVoices->begin() + context->mVoiceCount.load(std::memory_order_relaxed); std::for_each(context->mVoices->begin(), voices_end, diff --git a/alc/alc.cpp b/alc/alc.cpp index a69a8e7c..8ee762d5 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -2203,30 +2203,29 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) }; std::for_each(voices->begin(), voices_end, clear_sends); } - std::for_each(voices->begin(), voices_end, - [device](ALvoice &voice) -> void - { - delete voice.mUpdate.exchange(nullptr, std::memory_order_acq_rel); + auto reset_voice = [device](ALvoice &voice) -> void + { + delete voice.mUpdate.exchange(nullptr, std::memory_order_acq_rel); - /* Force the voice to stopped if it was stopping. */ - ALvoice::State vstate{ALvoice::Stopping}; - voice.mPlayState.compare_exchange_strong(vstate, ALvoice::Stopped, - std::memory_order_acquire, std::memory_order_acquire); - if(voice.mSourceID.load(std::memory_order_relaxed) == 0u) - return; + /* Force the voice to stopped if it was stopping. */ + ALvoice::State vstate{ALvoice::Stopping}; + voice.mPlayState.compare_exchange_strong(vstate, ALvoice::Stopped, + std::memory_order_acquire, std::memory_order_acquire); + if(voice.mSourceID.load(std::memory_order_relaxed) == 0u) + return; - if(device->AvgSpeakerDist > 0.0f) - { - /* Reinitialize the NFC filters for new parameters. */ - const ALfloat w1{SPEEDOFSOUNDMETRESPERSEC / - (device->AvgSpeakerDist * device->Frequency)}; - auto init_nfc = [w1](ALvoice::ChannelData &chandata) -> void - { chandata.mDryParams.NFCtrlFilter.init(w1); }; - std::for_each(voice.mChans.begin(), voice.mChans.begin()+voice.mNumChannels, - init_nfc); - } + if(device->AvgSpeakerDist > 0.0f) + { + /* Reinitialize the NFC filters for new parameters. */ + const ALfloat w1{SPEEDOFSOUNDMETRESPERSEC / + (device->AvgSpeakerDist * device->Frequency)}; + auto init_nfc = [w1](ALvoice::ChannelData &chandata) -> void + { chandata.mDryParams.NFCtrlFilter.init(w1); }; + std::for_each(voice.mChans.begin(), voice.mChans.begin()+voice.mNumChannels, + init_nfc); } - ); + }; + std::for_each(voices->begin(), voices_end, reset_voice); srclock.unlock(); context->mPropsClean.test_and_set(std::memory_order_release); -- cgit v1.2.3 From 727217ce0a9765270551ad6e10a25ee0b7fb74e6 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 1 Sep 2019 15:28:33 -0700 Subject: Ensure AL_STOPPED state change events are sent With explicit calls to alSourceStop on a playing or paused source --- al/source.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'al/source.cpp') diff --git a/al/source.cpp b/al/source.cpp index 08e4bff6..010dee1c 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -2974,7 +2974,11 @@ START_API_FUNC BackendLockGuard __{*device->Backend}; auto stop_source = [&context](ALsource *source) -> void { + /* Get the source state before clearing from the voice, so we know what + * state the source+voice was actually in. + */ ALvoice *voice{GetSourceVoice(source, context.get())}; + const ALenum oldstate{GetSourceState(source, voice)}; if(voice != nullptr) { voice->mCurrentBuffer.store(nullptr, std::memory_order_relaxed); @@ -2986,7 +2990,6 @@ START_API_FUNC std::memory_order_acq_rel, std::memory_order_acquire); voice = nullptr; } - ALenum oldstate{GetSourceState(source, voice)}; if(oldstate != AL_INITIAL && oldstate != AL_STOPPED) { source->state = AL_STOPPED; @@ -3048,7 +3051,7 @@ START_API_FUNC std::memory_order_acq_rel, std::memory_order_acquire); voice = nullptr; } - if(GetSourceState(source, voice) != AL_INITIAL) + if(source->state != AL_INITIAL) { source->state = AL_INITIAL; SendStateChangeEvent(context.get(), source->id, AL_INITIAL); -- cgit v1.2.3 From bb35e24c9ba7ec01c05fc1f07ef737c15821283a Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 1 Sep 2019 17:54:17 -0700 Subject: Avoid unnecessary placement new definitions --- al/auxeffectslot.cpp | 7 +------ al/auxeffectslot.h | 2 +- al/source.cpp | 7 +------ alc/alc.cpp | 3 +-- 4 files changed, 4 insertions(+), 15 deletions(-) (limited to 'al/source.cpp') diff --git a/al/auxeffectslot.cpp b/al/auxeffectslot.cpp index b2f2c249..3eb8b80a 100644 --- a/al/auxeffectslot.cpp +++ b/al/auxeffectslot.cpp @@ -173,13 +173,9 @@ ALeffectslot *AllocEffectSlot(ALCcontext *context) { return entry.FreeMask != 0; } ); auto lidx = static_cast(std::distance(context->mEffectSlotList.begin(), sublist)); - ALeffectslot *slot; ALsizei slidx; if LIKELY(sublist != context->mEffectSlotList.end()) - { slidx = CTZ64(sublist->FreeMask); - slot = sublist->EffectSlots + slidx; - } else { /* Don't allocate so many list entries that the 32-bit ID could @@ -203,10 +199,9 @@ ALeffectslot *AllocEffectSlot(ALCcontext *context) } slidx = 0; - slot = sublist->EffectSlots + slidx; } - slot = new (slot) ALeffectslot{}; + ALeffectslot *slot{::new (sublist->EffectSlots + slidx) ALeffectslot{}}; ALenum err{InitEffectSlot(slot)}; if(err != AL_NO_ERROR) { diff --git a/al/auxeffectslot.h b/al/auxeffectslot.h index a6eb94f9..2471447f 100644 --- a/al/auxeffectslot.h +++ b/al/auxeffectslot.h @@ -92,7 +92,7 @@ struct ALeffectslot { static ALeffectslotArray *CreatePtrArray(size_t count) noexcept; - DEF_PLACE_NEWDEL() + DEF_NEWDEL(ALeffectslot) }; ALenum InitEffectSlot(ALeffectslot *slot); diff --git a/al/source.cpp b/al/source.cpp index 010dee1c..86a7d94c 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -491,13 +491,9 @@ ALsource *AllocSource(ALCcontext *context) { return entry.FreeMask != 0; } ); auto lidx = static_cast(std::distance(context->mSourceList.begin(), sublist)); - ALsource *source; ALsizei slidx; if LIKELY(sublist != context->mSourceList.end()) - { slidx = CTZ64(sublist->FreeMask); - source = sublist->Sources + slidx; - } else { /* Don't allocate so many list entries that the 32-bit ID could @@ -521,10 +517,9 @@ ALsource *AllocSource(ALCcontext *context) } slidx = 0; - source = sublist->Sources + slidx; } - source = new (source) ALsource{device->NumAuxSends}; + ALsource *source{::new (sublist->Sources + slidx) ALsource{device->NumAuxSends}}; /* Add 1 to avoid source ID 0. */ source->id = ((lidx<<6) | slidx) + 1; diff --git a/alc/alc.cpp b/alc/alc.cpp index 8ee762d5..7964a2b3 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -2422,8 +2422,7 @@ void ALCcontext::init() { if(DefaultEffect.type != AL_EFFECT_NULL && mDevice->Type == Playback) { - void *ptr{al_calloc(16, sizeof(ALeffectslot))}; - mDefaultSlot = std::unique_ptr{new (ptr) ALeffectslot{}}; + mDefaultSlot = std::unique_ptr{new ALeffectslot{}}; if(InitEffectSlot(mDefaultSlot.get()) == AL_NO_ERROR) aluInitEffectPanning(mDefaultSlot.get(), mDevice.get()); else -- cgit v1.2.3 From ef2769af03825f278b855858681e4cbe55c0734b Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 4 Sep 2019 23:04:55 -0700 Subject: Use a normal vector for the voices array --- al/source.cpp | 55 +++++++++++++++++-------------------------------------- alc/alc.cpp | 50 +++++--------------------------------------------- alc/alcontext.h | 5 +---- alc/alu.cpp | 7 ++----- alc/alu.h | 1 + 5 files changed, 26 insertions(+), 92 deletions(-) (limited to 'al/source.cpp') diff --git a/al/source.cpp b/al/source.cpp index 86a7d94c..be565d58 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -77,10 +77,10 @@ using namespace std::placeholders; ALvoice *GetSourceVoice(ALsource *source, ALCcontext *context) { ALuint idx{source->VoiceIdx}; - if(idx < context->mVoiceCount.load(std::memory_order_relaxed)) + if(idx < context->mVoices.size()) { ALuint sid{source->id}; - ALvoice &voice = (*context->mVoices)[idx]; + ALvoice &voice = context->mVoices[idx]; if(voice.mSourceID.load(std::memory_order_acquire) == sid) return &voice; } @@ -2671,38 +2671,20 @@ START_API_FUNC } /* Count the number of reusable voices. */ - auto voices_end = context->mVoices->begin() + - context->mVoiceCount.load(std::memory_order_relaxed); - auto free_voices = std::accumulate(context->mVoices->begin(), voices_end, ALsizei{0}, - [](const ALsizei count, const ALvoice &voice) noexcept -> ALsizei - { - if(voice.mPlayState.load(std::memory_order_acquire) == ALvoice::Stopped && - voice.mSourceID.load(std::memory_order_relaxed) == 0u) - return count + 1; - return count; - } - ); + auto count_free_voices = [](const ALsizei count, const ALvoice &voice) noexcept -> ALsizei + { + if(voice.mPlayState.load(std::memory_order_acquire) == ALvoice::Stopped && + voice.mSourceID.load(std::memory_order_relaxed) == 0u) + return count + 1; + return count; + }; + auto free_voices = std::accumulate(context->mVoices.begin(), context->mVoices.end(), + ALsizei{0}, count_free_voices); if UNLIKELY(n > free_voices) { - /* Increment the number of voices to handle the request. */ + /* Increase the number of voices to handle the request. */ const ALuint need_voices{static_cast(n) - free_voices}; - const size_t rem_voices{context->mVoices->size() - - context->mVoiceCount.load(std::memory_order_relaxed)}; - - if UNLIKELY(need_voices > rem_voices) - { - /* Allocate more voices to get enough. */ - const size_t alloc_count{need_voices - rem_voices}; - if UNLIKELY(context->mVoices->size() > std::numeric_limits::max()-alloc_count) - SETERR_RETURN(context, AL_OUT_OF_MEMORY,, - "Overflow increasing voice count to %zu + %zu", context->mVoices->size(), - alloc_count); - - const size_t newcount{context->mVoices->size() + alloc_count}; - context->allocVoices(newcount); - } - - context->mVoiceCount.fetch_add(need_voices, std::memory_order_relaxed); + context->mVoices.resize(context->mVoices.size() + need_voices); } auto start_source = [&context,device](ALsource *source) -> void @@ -2757,9 +2739,8 @@ START_API_FUNC } /* Look for an unused voice to play this source with. */ - auto voices_end = context->mVoices->begin() + - context->mVoiceCount.load(std::memory_order_relaxed); - voice = std::find_if(context->mVoices->begin(), voices_end, + auto voices_end = context->mVoices.data() + context->mVoices.size(); + voice = std::find_if(context->mVoices.data(), voices_end, [](const ALvoice &voice) noexcept -> bool { return voice.mPlayState.load(std::memory_order_acquire) == ALvoice::Stopped && @@ -2767,7 +2748,7 @@ START_API_FUNC } ); assert(voice != voices_end); - auto vidx = static_cast(std::distance(context->mVoices->begin(), voice)); + auto vidx = static_cast(std::distance(context->mVoices.data(), voice)); voice->mPlayState.store(ALvoice::Stopped, std::memory_order_release); source->PropsClean.test_and_set(std::memory_order_acquire); @@ -3317,9 +3298,7 @@ ALsource::~ALsource() void UpdateAllSourceProps(ALCcontext *context) { std::lock_guard _{context->mSourceLock}; - auto voices_end = context->mVoices->begin() + - context->mVoiceCount.load(std::memory_order_relaxed); - std::for_each(context->mVoices->begin(), voices_end, + std::for_each(context->mVoices.begin(), context->mVoices.end(), [context](ALvoice &voice) -> void { ALuint sid{voice.mSourceID.load(std::memory_order_acquire)}; diff --git a/alc/alc.cpp b/alc/alc.cpp index 7964a2b3..81afaeb0 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -2182,8 +2182,6 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) vprops = next; } - auto voices = context->mVoices.get(); - auto voices_end = voices->begin() + context->mVoiceCount.load(std::memory_order_relaxed); if(device->NumAuxSends < old_sends) { const ALsizei num_sends{device->NumAuxSends}; @@ -2201,7 +2199,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) }; std::for_each(voice.mChans.begin(), voice.mChans.end(), clear_chan_sends); }; - std::for_each(voices->begin(), voices_end, clear_sends); + std::for_each(context->mVoices.begin(), context->mVoices.end(), clear_sends); } auto reset_voice = [device](ALvoice &voice) -> void { @@ -2225,7 +2223,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) init_nfc); } }; - std::for_each(voices->begin(), voices_end, reset_voice); + std::for_each(context->mVoices.begin(), context->mVoices.end(), reset_voice); srclock.unlock(); context->mPropsClean.test_and_set(std::memory_order_release); @@ -2378,8 +2376,7 @@ ALCcontext::~ALCcontext() } TRACE("Freed %zu voice property object%s\n", count, (count==1)?"":"s"); - mVoices = nullptr; - mVoiceCount.store(0, std::memory_order_relaxed); + mVoices.clear(); ALlistenerProps *lprops{mListener.Params.Update.exchange(nullptr, std::memory_order_relaxed)}; if(lprops) @@ -2459,7 +2456,8 @@ void ALCcontext::init() StartEventThrd(this); - allocVoices(256); + mVoices.reserve(256); + mVoices.resize(64); } bool ALCcontext::deinit() @@ -2548,44 +2546,6 @@ ContextRef GetContextRef(void) } -void ALCcontext::allocVoices(size_t num_voices) -{ - const ALsizei num_sends{mDevice->NumAuxSends}; - - if(mVoices && num_voices == mVoices->size()) - return; - - using ALvoiceArray = al::FlexArray; - std::unique_ptr voices{ALvoiceArray::Create(num_voices)}; - - const size_t v_count{minz(mVoiceCount.load(std::memory_order_relaxed), num_voices)}; - if(mVoices) - { - /* Copy the old voice data to the new storage. */ - auto viter = std::move(mVoices->begin(), mVoices->begin()+v_count, voices->begin()); - - /* Clear extraneous property set sends. */ - auto clear_sends = [num_sends](ALvoice &voice) -> void - { - std::fill(std::begin(voice.mProps.Send)+num_sends, std::end(voice.mProps.Send), - ALvoiceProps::SendData{}); - - std::fill(voice.mSend.begin()+num_sends, voice.mSend.end(), ALvoice::SendData{}); - auto clear_chan_sends = [num_sends](ALvoice::ChannelData &chandata) -> void - { - std::fill(chandata.mWetParams.begin()+num_sends, chandata.mWetParams.end(), - SendParams{}); - }; - std::for_each(voice.mChans.begin(), voice.mChans.end(), clear_chan_sends); - }; - std::for_each(voices->begin(), viter, clear_sends); - } - - mVoices = std::move(voices); - mVoiceCount.store(static_cast(v_count), std::memory_order_relaxed); -} - - /************************************************ * Standard ALC functions ************************************************/ diff --git a/alc/alcontext.h b/alc/alcontext.h index c91d0a21..dd622654 100644 --- a/alc/alcontext.h +++ b/alc/alcontext.h @@ -127,8 +127,7 @@ struct ALCcontext : public al::intrusive_ref { std::atomic mFreeVoiceProps{nullptr}; std::atomic mFreeEffectslotProps{nullptr}; - std::unique_ptr> mVoices{nullptr}; - std::atomic mVoiceCount{0u}; + al::vector mVoices; using ALeffectslotArray = al::FlexArray; std::atomic mActiveAuxSlots{nullptr}; @@ -163,8 +162,6 @@ struct ALCcontext : public al::intrusive_ref { */ bool deinit(); - void allocVoices(size_t num_voices); - /** * Defers/suspends updates for the given context's listener and sources. * This does *NOT* stop mixing, but rather prevents certain property diff --git a/alc/alu.cpp b/alc/alu.cpp index 861929ef..e58ff3b4 100644 --- a/alc/alu.cpp +++ b/alc/alu.cpp @@ -1348,8 +1348,7 @@ void ProcessContext(ALCcontext *ctx, const ALuint SamplesToDo) ASSUME(SamplesToDo > 0); const ALeffectslotArray &auxslots = *ctx->mActiveAuxSlots.load(std::memory_order_acquire); - const al::span voices{ctx->mVoices->data(), - ctx->mVoiceCount.load(std::memory_order_acquire)}; + const al::span voices{ctx->mVoices.data(), ctx->mVoices.size()}; /* Process pending propery updates for objects on the context. */ ProcessParamUpdates(ctx, auxslots, voices); @@ -1755,9 +1754,7 @@ void aluHandleDisconnect(ALCdevice *device, const char *msg, ...) voice.mSourceID.store(0u, std::memory_order_relaxed); voice.mPlayState.store(ALvoice::Stopped, std::memory_order_release); }; - std::for_each(ctx->mVoices->begin(), - ctx->mVoices->begin() + ctx->mVoiceCount.load(std::memory_order_acquire), - stop_voice); + std::for_each(ctx->mVoices.begin(), ctx->mVoices.end(), stop_voice); } IncrementRef(device->MixCount); } diff --git a/alc/alu.h b/alc/alu.h index 51c5f702..3b6045f0 100644 --- a/alc/alu.h +++ b/alc/alu.h @@ -269,6 +269,7 @@ struct ALvoice { ALvoice() = default; ALvoice(const ALvoice&) = delete; + ALvoice(ALvoice&& rhs) noexcept { *this = std::move(rhs); } ~ALvoice() { delete mUpdate.exchange(nullptr, std::memory_order_acq_rel); } ALvoice& operator=(const ALvoice&) = delete; ALvoice& operator=(ALvoice&& rhs) noexcept -- cgit v1.2.3 From 97c043da072470afcb9707eeb81ff52336d63e1e Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 5 Sep 2019 04:00:49 -0700 Subject: Don't set voice properties in ApplyOffset --- al/source.cpp | 65 ++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 23 deletions(-) (limited to 'al/source.cpp') diff --git a/al/source.cpp b/al/source.cpp index be565d58..9bae27a5 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -50,6 +50,7 @@ #include "alexcpt.h" #include "almalloc.h" #include "alnumeric.h" +#include "aloptional.h" #include "alspan.h" #include "alu.h" #include "ambidefs.h" @@ -382,7 +383,7 @@ ALdouble GetSourceOffset(ALsource *Source, ALenum name, ALCcontext *context) * or Second offset supplied by the application). This takes into account the * fact that the buffer format may have been modifed since. */ -ALboolean GetSampleOffset(ALsource *Source, ALuint *offset, ALuint *frac) +bool GetSampleOffset(ALsource *Source, ALuint *offset, ALuint *frac) { const ALbuffer *BufferFmt{nullptr}; const ALbufferlistitem *BufferList; @@ -398,7 +399,7 @@ ALboolean GetSampleOffset(ALsource *Source, ALuint *offset, ALuint *frac) { Source->OffsetType = AL_NONE; Source->Offset = 0.0; - return AL_FALSE; + return false; } ALdouble dbloff, dblfrac; @@ -439,21 +440,30 @@ ALboolean GetSampleOffset(ALsource *Source, ALuint *offset, ALuint *frac) Source->OffsetType = AL_NONE; Source->Offset = 0.0; - return AL_TRUE; + return true; } -/* ApplyOffset + +struct VoicePos { + ALuint pos, frac; + ALbufferlistitem *bufferitem; +}; + +/** + * CalcOffset * - * Apply the stored playback offset to the Source. This function will update - * the number of buffers "played" given the stored offset. + * Calculates the voice position, fixed-point fraction, and bufferlist item + * using the source's stored offset. If the source has no stored offset, or the + * offset is out of range, returns an empty optional. */ -ALboolean ApplyOffset(ALsource *Source, ALvoice *voice) +al::optional CalcOffset(ALsource *Source) { + al::optional ret; + /* Get sample frame offset */ - ALuint offset{0u}; - ALuint frac{0u}; + ALuint offset{0u}, frac{0u}; if(!GetSampleOffset(Source, &offset, &frac)) - return AL_FALSE; + return ret; ALuint totalBufferLen{0u}; ALbufferlistitem *BufferList{Source->queue}; @@ -462,10 +472,8 @@ ALboolean ApplyOffset(ALsource *Source, ALvoice *voice) if(BufferList->mSampleLen > offset-totalBufferLen) { /* Offset is in this buffer */ - voice->mPosition.store(offset - totalBufferLen, std::memory_order_relaxed); - voice->mPositionFrac.store(frac, std::memory_order_relaxed); - voice->mCurrentBuffer.store(BufferList, std::memory_order_release); - return AL_TRUE; + ret = {offset-totalBufferLen, frac, BufferList}; + return ret; } totalBufferLen += BufferList->mSampleLen; @@ -473,7 +481,7 @@ ALboolean ApplyOffset(ALsource *Source, ALvoice *voice) } /* Offset is out of range of the queue */ - return AL_FALSE; + return ret; } @@ -1013,8 +1021,12 @@ bool SetSourcefv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a */ if(ALvoice *voice{GetSourceVoice(Source, Context)}) { - if(ApplyOffset(Source, voice) == AL_FALSE) - SETERR_RETURN(Context, AL_INVALID_VALUE, false, "Invalid offset"); + auto vpos = CalcOffset(Source); + if(!vpos) SETERR_RETURN(Context, AL_INVALID_VALUE, false, "Invalid offset"); + + voice->mPosition.store(vpos->pos, std::memory_order_relaxed); + voice->mPositionFrac.store(vpos->frac, std::memory_order_relaxed); + voice->mCurrentBuffer.store(vpos->bufferitem, std::memory_order_release); } } return true; @@ -1228,8 +1240,12 @@ bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a BackendLockGuard _{*device->Backend}; if(ALvoice *voice{GetSourceVoice(Source, Context)}) { - if(ApplyOffset(Source, voice) == AL_FALSE) - SETERR_RETURN(Context, AL_INVALID_VALUE, false, "Invalid source offset"); + auto vpos = CalcOffset(Source); + if(!vpos) SETERR_RETURN(Context, AL_INVALID_VALUE, false, "Invalid source offset"); + + voice->mPosition.store(vpos->pos, std::memory_order_relaxed); + voice->mPositionFrac.store(vpos->frac, std::memory_order_relaxed); + voice->mCurrentBuffer.store(vpos->bufferitem, std::memory_order_release); } } return true; @@ -2765,10 +2781,13 @@ START_API_FUNC voice->mPosition.store(0u, std::memory_order_relaxed); voice->mPositionFrac.store(0, std::memory_order_relaxed); bool start_fading{false}; - if(ApplyOffset(source, voice) != AL_FALSE) - start_fading = voice->mPosition.load(std::memory_order_relaxed) != 0 || - voice->mPositionFrac.load(std::memory_order_relaxed) != 0 || - voice->mCurrentBuffer.load(std::memory_order_relaxed) != BufferList; + if(auto vpos = CalcOffset(source)) + { + start_fading = vpos->pos != 0 || vpos->frac != 0 || vpos->bufferitem != BufferList; + voice->mPosition.store(vpos->pos, std::memory_order_relaxed); + voice->mPositionFrac.store(vpos->frac, std::memory_order_relaxed); + voice->mCurrentBuffer.store(vpos->bufferitem, std::memory_order_relaxed); + } ALbuffer *buffer{BufferList->mBuffer}; voice->mFrequency = buffer->Frequency; -- cgit v1.2.3 From e5c9643dd55721ce36ea84bf15134127e04aba71 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 5 Sep 2019 15:08:22 -0700 Subject: Combine two functions into one --- al/source.cpp | 97 ++++++++++++++++++++++++----------------------------------- 1 file changed, 40 insertions(+), 57 deletions(-) (limited to 'al/source.cpp') diff --git a/al/source.cpp b/al/source.cpp index 9bae27a5..1b5aa851 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -377,96 +377,79 @@ ALdouble GetSourceOffset(ALsource *Source, ALenum name, ALCcontext *context) } -/* GetSampleOffset +struct VoicePos { + ALuint pos, frac; + ALbufferlistitem *bufferitem; +}; + +/** + * GetSampleOffset * - * Retrieves the sample offset into the Source's queue (from the Sample, Byte - * or Second offset supplied by the application). This takes into account the - * fact that the buffer format may have been modifed since. + * Retrieves the voice position, fixed-point fraction, and bufferlist item + * using the source's stored offset and offset type. If the source has no + * stored offset, or the offset is out of range, returns an empty optional. */ -bool GetSampleOffset(ALsource *Source, ALuint *offset, ALuint *frac) +al::optional GetSampleOffset(ALsource *Source) { - const ALbuffer *BufferFmt{nullptr}; - const ALbufferlistitem *BufferList; - + al::optional ret; + /* Find the first valid Buffer in the Queue */ - BufferList = Source->queue; - while(BufferList && !BufferFmt) + const ALbuffer *BufferFmt{nullptr}; + ALbufferlistitem *BufferList{Source->queue}; + while(BufferList) { - BufferFmt = BufferList->mBuffer; + if((BufferFmt=BufferList->mBuffer) != nullptr) break; BufferList = BufferList->mNext.load(std::memory_order_relaxed); } - if(!BufferFmt) + if(!BufferList) { Source->OffsetType = AL_NONE; Source->Offset = 0.0; - return false; + return ret; } + /* Get sample frame offset */ + ALuint offset{0u}, frac{0u}; ALdouble dbloff, dblfrac; switch(Source->OffsetType) { case AL_BYTE_OFFSET: /* Determine the ByteOffset (and ensure it is block aligned) */ - *offset = static_cast(Source->Offset); + offset = static_cast(Source->Offset); if(BufferFmt->OriginalType == UserFmtIMA4) { - ALsizei align = (BufferFmt->OriginalAlign-1)/2 + 4; - *offset /= align * ChannelsFromFmt(BufferFmt->mFmtChannels); - *offset *= BufferFmt->OriginalAlign; + const ALsizei align{(BufferFmt->OriginalAlign-1)/2 + 4}; + offset /= align * ChannelsFromFmt(BufferFmt->mFmtChannels); + offset *= BufferFmt->OriginalAlign; } else if(BufferFmt->OriginalType == UserFmtMSADPCM) { - ALsizei align = (BufferFmt->OriginalAlign-2)/2 + 7; - *offset /= align * ChannelsFromFmt(BufferFmt->mFmtChannels); - *offset *= BufferFmt->OriginalAlign; + const ALsizei align{(BufferFmt->OriginalAlign-2)/2 + 7}; + offset /= align * ChannelsFromFmt(BufferFmt->mFmtChannels); + offset *= BufferFmt->OriginalAlign; } else - *offset /= FrameSizeFromFmt(BufferFmt->mFmtChannels, BufferFmt->mFmtType); - *frac = 0; + offset /= FrameSizeFromFmt(BufferFmt->mFmtChannels, BufferFmt->mFmtType); + frac = 0; break; case AL_SAMPLE_OFFSET: - dblfrac = modf(Source->Offset, &dbloff); - *offset = static_cast(mind(dbloff, std::numeric_limits::max())); - *frac = static_cast(mind(dblfrac*FRACTIONONE, FRACTIONONE-1.0)); + dblfrac = std::modf(Source->Offset, &dbloff); + offset = static_cast(mind(dbloff, std::numeric_limits::max())); + frac = static_cast(mind(dblfrac*FRACTIONONE, FRACTIONONE-1.0)); break; case AL_SEC_OFFSET: - dblfrac = modf(Source->Offset*BufferFmt->Frequency, &dbloff); - *offset = static_cast(mind(dbloff, std::numeric_limits::max())); - *frac = static_cast(mind(dblfrac*FRACTIONONE, FRACTIONONE-1.0)); + dblfrac = std::modf(Source->Offset*BufferFmt->Frequency, &dbloff); + offset = static_cast(mind(dbloff, std::numeric_limits::max())); + frac = static_cast(mind(dblfrac*FRACTIONONE, FRACTIONONE-1.0)); break; } Source->OffsetType = AL_NONE; Source->Offset = 0.0; - return true; -} - - -struct VoicePos { - ALuint pos, frac; - ALbufferlistitem *bufferitem; -}; - -/** - * CalcOffset - * - * Calculates the voice position, fixed-point fraction, and bufferlist item - * using the source's stored offset. If the source has no stored offset, or the - * offset is out of range, returns an empty optional. - */ -al::optional CalcOffset(ALsource *Source) -{ - al::optional ret; - - /* Get sample frame offset */ - ALuint offset{0u}, frac{0u}; - if(!GetSampleOffset(Source, &offset, &frac)) - return ret; - + /* Find the bufferlist item this offset belongs to. */ ALuint totalBufferLen{0u}; - ALbufferlistitem *BufferList{Source->queue}; while(BufferList && totalBufferLen <= offset) { if(BufferList->mSampleLen > offset-totalBufferLen) @@ -1021,7 +1004,7 @@ bool SetSourcefv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a */ if(ALvoice *voice{GetSourceVoice(Source, Context)}) { - auto vpos = CalcOffset(Source); + auto vpos = GetSampleOffset(Source); if(!vpos) SETERR_RETURN(Context, AL_INVALID_VALUE, false, "Invalid offset"); voice->mPosition.store(vpos->pos, std::memory_order_relaxed); @@ -1240,7 +1223,7 @@ bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a BackendLockGuard _{*device->Backend}; if(ALvoice *voice{GetSourceVoice(Source, Context)}) { - auto vpos = CalcOffset(Source); + auto vpos = GetSampleOffset(Source); if(!vpos) SETERR_RETURN(Context, AL_INVALID_VALUE, false, "Invalid source offset"); voice->mPosition.store(vpos->pos, std::memory_order_relaxed); @@ -2781,7 +2764,7 @@ START_API_FUNC voice->mPosition.store(0u, std::memory_order_relaxed); voice->mPositionFrac.store(0, std::memory_order_relaxed); bool start_fading{false}; - if(auto vpos = CalcOffset(source)) + if(auto vpos = GetSampleOffset(source)) { start_fading = vpos->pos != 0 || vpos->frac != 0 || vpos->bufferitem != BufferList; voice->mPosition.store(vpos->pos, std::memory_order_relaxed); -- cgit v1.2.3 From 987fd13796d5761b7adc5f6e137e7a6149d02f7b Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 6 Sep 2019 21:20:20 -0700 Subject: Use a new voice when restarting a playing source --- al/source.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'al/source.cpp') diff --git a/al/source.cpp b/al/source.cpp index 1b5aa851..44c46d65 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -2716,14 +2716,6 @@ START_API_FUNC ALvoice *voice{GetSourceVoice(source, context.get())}; switch(GetSourceState(source, voice)) { - case AL_PLAYING: - assert(voice != nullptr); - /* A source that's already playing is restarted from the beginning. */ - voice->mCurrentBuffer.store(BufferList, std::memory_order_relaxed); - voice->mPosition.store(0u, std::memory_order_relaxed); - voice->mPositionFrac.store(0, std::memory_order_release); - return; - case AL_PAUSED: assert(voice != nullptr); /* A source that's paused simply resumes. */ @@ -2732,6 +2724,19 @@ START_API_FUNC SendStateChangeEvent(context.get(), source->id, AL_PLAYING); return; + case AL_PLAYING: + assert(voice != nullptr); + /* A source that's already playing is restarted from the beginning. + * Stop the current voice and start a new one so it properly cross- + * fades back to the beginning. + */ + voice->mCurrentBuffer.store(nullptr, std::memory_order_relaxed); + voice->mLoopBuffer.store(nullptr, std::memory_order_relaxed); + voice->mSourceID.store(0u, std::memory_order_release); + voice->mPlayState.store(ALvoice::Stopping, std::memory_order_release); + voice = nullptr; + break; + default: assert(voice == nullptr); break; @@ -2851,10 +2856,13 @@ START_API_FUNC voice->mSourceID.store(source->id, std::memory_order_relaxed); voice->mPlayState.store(ALvoice::Playing, std::memory_order_release); - source->state = AL_PLAYING; source->VoiceIdx = vidx; - SendStateChangeEvent(context.get(), source->id, AL_PLAYING); + if(source->state != AL_PLAYING) + { + source->state = AL_PLAYING; + SendStateChangeEvent(context.get(), source->id, AL_PLAYING); + } }; std::for_each(srchandles, srchandles+n, start_source); } -- cgit v1.2.3 From 07e2aa3bc0c7dde66b332e400f71bfd0d9cb1c5f Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 11 Sep 2019 14:33:26 -0700 Subject: Clean up some more implicit conversions --- al/buffer.cpp | 248 ++++++++++++++++++++++++++++--------------------------- al/buffer.h | 19 ++--- al/event.cpp | 4 +- al/event.h | 2 +- al/source.cpp | 113 ++++++++++++------------- alc/mixvoice.cpp | 28 +++---- 6 files changed, 204 insertions(+), 210 deletions(-) (limited to 'al/source.cpp') diff --git a/al/buffer.cpp b/al/buffer.cpp index 3cf9a60f..1b4f6846 100644 --- a/al/buffer.cpp +++ b/al/buffer.cpp @@ -99,13 +99,13 @@ constexpr int MSADPCMAdaptionCoeff[7][2] = { }; -void DecodeIMA4Block(ALshort *dst, const al::byte *src, ALint numchans, ALsizei align) +void DecodeIMA4Block(ALshort *dst, const al::byte *src, size_t numchans, size_t align) { ALint sample[MAX_INPUT_CHANNELS]{}; ALint index[MAX_INPUT_CHANNELS]{}; ALuint code[MAX_INPUT_CHANNELS]{}; - for(int c{0};c < numchans;c++) + for(size_t c{0};c < numchans;c++) { sample[c] = al::to_integer(src[0]) | (al::to_integer(src[1])<<8); sample[c] = (sample[c]^0x8000) - 32768; @@ -114,14 +114,14 @@ void DecodeIMA4Block(ALshort *dst, const al::byte *src, ALint numchans, ALsizei index[c] = clampi((index[c]^0x8000) - 32768, 0, 88); src += 2; - *(dst++) = sample[c]; + *(dst++) = static_cast(sample[c]); } - for(int i{1};i < align;i++) + for(size_t i{1};i < align;i++) { if((i&7) == 1) { - for(int c{0};c < numchans;c++) + for(size_t c{0};c < numchans;c++) { code[c] = al::to_integer(src[0]) | (al::to_integer(src[1])<< 8) | (al::to_integer(src[2])<<16) | (al::to_integer(src[3])<<24); @@ -129,7 +129,7 @@ void DecodeIMA4Block(ALshort *dst, const al::byte *src, ALint numchans, ALsizei } } - for(int c{0};c < numchans;c++) + for(size_t c{0};c < numchans;c++) { const ALuint nibble{code[c]&0xf}; code[c] >>= 4; @@ -140,51 +140,53 @@ void DecodeIMA4Block(ALshort *dst, const al::byte *src, ALint numchans, ALsizei index[c] += IMA4Index_adjust[nibble]; index[c] = clampi(index[c], 0, 88); - *(dst++) = sample[c]; + *(dst++) = static_cast(sample[c]); } } } -void DecodeMSADPCMBlock(ALshort *dst, const al::byte *src, ALint numchans, ALsizei align) +void DecodeMSADPCMBlock(ALshort *dst, const al::byte *src, size_t numchans, size_t align) { ALubyte blockpred[MAX_INPUT_CHANNELS]{}; ALint delta[MAX_INPUT_CHANNELS]{}; ALshort samples[MAX_INPUT_CHANNELS][2]{}; - for(int c{0};c < numchans;c++) + for(size_t c{0};c < numchans;c++) { - blockpred[c] = minu(al::to_integer(src[0]), 6); + blockpred[c] = std::min(al::to_integer(src[0]), 6); ++src; } - for(int c{0};c < numchans;c++) + for(size_t c{0};c < numchans;c++) { delta[c] = al::to_integer(src[0]) | (al::to_integer(src[1])<<8); delta[c] = (delta[c]^0x8000) - 32768; src += 2; } - for(int c{0};c < numchans;c++) + for(size_t c{0};c < numchans;c++) { - samples[c][0] = al::to_integer(src[0]) | (al::to_integer(src[1])<<8); + samples[c][0] = static_cast(al::to_integer(src[0]) | + (al::to_integer(src[1])<<8)); samples[c][0] = (samples[c][0]^0x8000) - 32768; src += 2; } - for(int c{0};c < numchans;c++) + for(size_t c{0};c < numchans;c++) { - samples[c][1] = al::to_integer(src[0]) | (al::to_integer(src[1])<<8); + samples[c][1] = static_cast(al::to_integer(src[0]) | + (al::to_integer(src[1])<<8)); samples[c][1] = (samples[c][1]^0x8000) - 32768; src += 2; } /* Second sample is written first. */ - for(int c{0};c < numchans;c++) + for(size_t c{0};c < numchans;c++) *(dst++) = samples[c][1]; - for(int c{0};c < numchans;c++) + for(size_t c{0};c < numchans;c++) *(dst++) = samples[c][0]; int num{0}; - for(int i{2};i < align;i++) + for(size_t i{2};i < align;i++) { - for(int c{0};c < numchans;c++) + for(size_t c{0};c < numchans;c++) { /* Read the nibble (first is in the upper bits). */ al::byte nibble; @@ -199,20 +201,20 @@ void DecodeMSADPCMBlock(ALshort *dst, const al::byte *src, ALint numchans, ALsiz pred = clampi(pred, -32768, 32767); samples[c][1] = samples[c][0]; - samples[c][0] = pred; + samples[c][0] = static_cast(pred); delta[c] = (MSADPCMAdaption[al::to_integer(nibble)] * delta[c]) / 256; delta[c] = maxi(16, delta[c]); - *(dst++) = pred; + *(dst++) = static_cast(pred); } } } -void Convert_ALshort_ALima4(ALshort *dst, const al::byte *src, ALsizei numchans, ALsizei len, - ALsizei align) +void Convert_ALshort_ALima4(ALshort *dst, const al::byte *src, size_t numchans, size_t len, + size_t align) { - const ALsizei byte_align{((align-1)/2 + 4) * numchans}; + const size_t byte_align{((align-1)/2 + 4) * numchans}; len /= align; while(len--) @@ -223,10 +225,10 @@ void Convert_ALshort_ALima4(ALshort *dst, const al::byte *src, ALsizei numchans, } } -void Convert_ALshort_ALmsadpcm(ALshort *dst, const al::byte *src, ALsizei numchans, ALsizei len, - ALsizei align) +void Convert_ALshort_ALmsadpcm(ALshort *dst, const al::byte *src, size_t numchans, size_t len, + size_t align) { - const ALsizei byte_align{((align-2)/2 + 7) * numchans}; + const size_t byte_align{((align-2)/2 + 7) * numchans}; len /= align; while(len--) @@ -238,6 +240,41 @@ void Convert_ALshort_ALmsadpcm(ALshort *dst, const al::byte *src, ALsizei numcha } +ALuint BytesFromUserFmt(UserFmtType type) +{ + switch(type) + { + case UserFmtUByte: return sizeof(ALubyte); + case UserFmtShort: return sizeof(ALshort); + case UserFmtFloat: return sizeof(ALfloat); + case UserFmtDouble: return sizeof(ALdouble); + case UserFmtMulaw: return sizeof(ALubyte); + case UserFmtAlaw: return sizeof(ALubyte); + case UserFmtIMA4: break; /* not handled here */ + case UserFmtMSADPCM: break; /* not handled here */ + } + return 0; +} +ALuint ChannelsFromUserFmt(UserFmtChannels chans) +{ + switch(chans) + { + case UserFmtMono: return 1; + case UserFmtStereo: return 2; + case UserFmtRear: return 2; + case UserFmtQuad: return 4; + case UserFmtX51: return 6; + case UserFmtX61: return 7; + case UserFmtX71: return 8; + case UserFmtBFormat2D: return 3; + case UserFmtBFormat3D: return 4; + } + return 0; +} +inline ALuint FrameSizeFromUserFmt(UserFmtChannels chans, UserFmtType type) +{ return ChannelsFromUserFmt(chans) * BytesFromUserFmt(type); } + + constexpr ALbitfieldSOFT INVALID_STORAGE_MASK{~unsigned(AL_MAP_READ_BIT_SOFT | AL_MAP_WRITE_BIT_SOFT | AL_MAP_PERSISTENT_BIT_SOFT | AL_PRESERVE_DATA_BIT_SOFT)}; constexpr ALbitfieldSOFT MAP_READ_WRITE_FLAGS{AL_MAP_READ_BIT_SOFT | AL_MAP_WRITE_BIT_SOFT}; @@ -316,11 +353,8 @@ inline ALbuffer *LookupBuffer(ALCdevice *device, ALuint id) } -ALsizei SanitizeAlignment(UserFmtType type, ALsizei align) +ALuint SanitizeAlignment(UserFmtType type, ALuint align) { - if(align < 0) - return 0; - if(align == 0) { if(type == UserFmtIMA4) @@ -339,17 +373,17 @@ ALsizei SanitizeAlignment(UserFmtType type, ALsizei align) if(type == UserFmtIMA4) { /* IMA4 block alignment must be a multiple of 8, plus 1. */ - if((align&7) == 1) return align; + if((align&7) == 1) return static_cast(align); return 0; } if(type == UserFmtMSADPCM) { /* MSADPCM block alignment must be a multiple of 2. */ - if((align&1) == 0) return align; + if((align&1) == 0) return static_cast(align); return 0; } - return align; + return static_cast(align); } @@ -369,12 +403,10 @@ const ALchar *NameFromUserFmtType(UserFmtType type) return ""; } -/* - * LoadData - * - * Loads the specified data into the buffer, using the specified format. - */ -void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALuint freq, ALsizei size, UserFmtChannels SrcChannels, UserFmtType SrcType, const al::byte *SrcData, ALbitfieldSOFT access) +/** Loads the specified data into the buffer, using the specified format. */ +void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALsizei freq, ALuint size, + UserFmtChannels SrcChannels, UserFmtType SrcType, const al::byte *SrcData, + ALbitfieldSOFT access) { if UNLIKELY(ReadRef(ALBuf->ref) != 0 || ALBuf->MappedAccess != 0) SETERR_RETURN(context, AL_INVALID_OPERATION,, "Modifying storage for in-use buffer %u", @@ -422,10 +454,10 @@ void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALuint freq, ALsizei size, U NameFromUserFmtType(SrcType)); } - const ALsizei unpackalign{ALBuf->UnpackAlign.load()}; - const ALsizei align{SanitizeAlignment(SrcType, unpackalign)}; + const ALuint unpackalign{ALBuf->UnpackAlign}; + const ALuint align{SanitizeAlignment(SrcType, unpackalign)}; if UNLIKELY(align < 1) - SETERR_RETURN(context, AL_INVALID_VALUE,, "Invalid unpack alignment %d for %s samples", + SETERR_RETURN(context, AL_INVALID_VALUE,, "Invalid unpack alignment %u for %s samples", unpackalign, NameFromUserFmtType(SrcType)); if((access&AL_PRESERVE_DATA_BIT_SOFT)) @@ -433,14 +465,14 @@ void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALuint freq, ALsizei size, U /* Can only preserve data with the same format and alignment. */ if UNLIKELY(ALBuf->mFmtChannels != DstChannels || ALBuf->OriginalType != SrcType) SETERR_RETURN(context, AL_INVALID_VALUE,, "Preserving data of mismatched format"); - if UNLIKELY(ALBuf->OriginalAlign != align) + if UNLIKELY(static_cast(ALBuf->OriginalAlign) != align) SETERR_RETURN(context, AL_INVALID_VALUE,, "Preserving data of mismatched alignment"); } /* Convert the input/source size in bytes to sample frames using the unpack * block alignment. */ - const ALsizei SrcByteAlign{ + const ALuint SrcByteAlign{ (SrcType == UserFmtIMA4) ? ((align-1)/2 + 4) * ChannelsFromUserFmt(SrcChannels) : (SrcType == UserFmtMSADPCM) ? ((align-2)/2 + 7) * ChannelsFromUserFmt(SrcChannels) : (align * FrameSizeFromUserFmt(SrcChannels, SrcType)) @@ -453,13 +485,13 @@ void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALuint freq, ALsizei size, U if UNLIKELY(size/SrcByteAlign > std::numeric_limits::max()/align) SETERR_RETURN(context, AL_OUT_OF_MEMORY,, "Buffer size overflow, %d blocks x %d samples per block", size/SrcByteAlign, align); - const auto frames = static_cast(size / SrcByteAlign * align); + const ALuint frames{size / SrcByteAlign * align}; /* Convert the sample frames to the number of bytes needed for internal * storage. */ - ALsizei NumChannels{ChannelsFromFmt(DstChannels)}; - ALsizei FrameSize{NumChannels * BytesFromFmt(DstType)}; + ALuint NumChannels{ChannelsFromFmt(DstChannels)}; + ALuint FrameSize{NumChannels * BytesFromFmt(DstType)}; if UNLIKELY(frames > std::numeric_limits::max()/FrameSize) SETERR_RETURN(context, AL_OUT_OF_MEMORY,, "Buffer size overflow, %d frames x %d bytes per frame", frames, FrameSize); @@ -588,7 +620,7 @@ al::optional DecomposeUserFormat(ALenum format) for(const auto &fmt : UserFmtList) { if(fmt.format == format) - return al::make_optional(DecompResult{fmt.channels, fmt.type}); + return al::make_optional({fmt.channels, fmt.type}); } return al::nullopt; } @@ -607,7 +639,7 @@ START_API_FUNC if UNLIKELY(n <= 0) return; ALCdevice *device{context->mDevice.get()}; - std::unique_lock buflock{device->BufferLock}; + std::lock_guard _{device->BufferLock}; if(!EnsureBuffers(device, static_cast(n))) { context->setError(AL_OUT_OF_MEMORY, "Failed to allocate %d buffer%s", n, (n==1)?"":"s"); @@ -732,8 +764,8 @@ START_API_FUNC if UNLIKELY(!usrfmt) context->setError(AL_INVALID_ENUM, "Invalid format 0x%04x", format); else - LoadData(context.get(), albuf, freq, size, usrfmt->channels, usrfmt->type, - static_cast(data), flags); + LoadData(context.get(), albuf, freq, static_cast(size), usrfmt->channels, + usrfmt->type, static_cast(data), flags); } } END_API_FUNC @@ -772,8 +804,9 @@ START_API_FUNC else if UNLIKELY((unavailable&AL_MAP_PERSISTENT_BIT_SOFT)) context->setError(AL_INVALID_VALUE, "Mapping buffer %u persistently without persistent access", buffer); - else if UNLIKELY(offset < 0 || offset >= albuf->OriginalSize || - length <= 0 || length > albuf->OriginalSize - offset) + else if UNLIKELY(offset < 0 || length <= 0 + || static_cast(offset) >= albuf->OriginalSize + || static_cast(length) > albuf->OriginalSize - static_cast(offset)) context->setError(AL_INVALID_VALUE, "Mapping invalid range %d+%d for buffer %u", offset, length, buffer); else @@ -828,9 +861,9 @@ START_API_FUNC else if UNLIKELY(!(albuf->MappedAccess&AL_MAP_WRITE_BIT_SOFT)) context->setError(AL_INVALID_OPERATION, "Flushing buffer %u while not mapped for writing", buffer); - else if UNLIKELY(offset < albuf->MappedOffset || - offset >= albuf->MappedOffset+albuf->MappedSize || - length <= 0 || length > albuf->MappedOffset+albuf->MappedSize-offset) + else if UNLIKELY(offset < albuf->MappedOffset || length <= 0 + || offset >= albuf->MappedOffset+albuf->MappedSize + || length > albuf->MappedOffset+albuf->MappedSize-offset) context->setError(AL_INVALID_VALUE, "Flushing invalid range %d+%d on buffer %u", offset, length, buffer); else @@ -868,12 +901,12 @@ START_API_FUNC return; } - ALsizei unpack_align{albuf->UnpackAlign.load()}; - ALsizei align{SanitizeAlignment(usrfmt->type, unpack_align)}; + ALuint unpack_align{albuf->UnpackAlign}; + ALuint align{SanitizeAlignment(usrfmt->type, unpack_align)}; if UNLIKELY(align < 1) - context->setError(AL_INVALID_VALUE, "Invalid unpack alignment %d", unpack_align); - else if UNLIKELY(long{usrfmt->channels} != long{albuf->mFmtChannels} || - usrfmt->type != albuf->OriginalType) + context->setError(AL_INVALID_VALUE, "Invalid unpack alignment %u", unpack_align); + else if UNLIKELY(long{usrfmt->channels} != long{albuf->mFmtChannels} + || usrfmt->type != albuf->OriginalType) context->setError(AL_INVALID_ENUM, "Unpacking data with mismatched format"); else if UNLIKELY(align != albuf->OriginalAlign) context->setError(AL_INVALID_VALUE, @@ -883,43 +916,43 @@ START_API_FUNC context->setError(AL_INVALID_OPERATION, "Unpacking data into mapped buffer %u", buffer); else { - ALsizei num_chans{ChannelsFromFmt(albuf->mFmtChannels)}; - ALsizei frame_size{num_chans * BytesFromFmt(albuf->mFmtType)}; - ALsizei byte_align{ + ALuint num_chans{ChannelsFromFmt(albuf->mFmtChannels)}; + ALuint frame_size{num_chans * BytesFromFmt(albuf->mFmtType)}; + ALuint byte_align{ (albuf->OriginalType == UserFmtIMA4) ? ((align-1)/2 + 4) * num_chans : (albuf->OriginalType == UserFmtMSADPCM) ? ((align-2)/2 + 7) * num_chans : (align * frame_size) }; - if UNLIKELY(offset < 0 || length < 0 || offset > albuf->OriginalSize || - length > albuf->OriginalSize-offset) + if UNLIKELY(offset < 0 || length < 0 || static_cast(offset) > albuf->OriginalSize + || static_cast(length) > albuf->OriginalSize-static_cast(offset)) context->setError(AL_INVALID_VALUE, "Invalid data sub-range %d+%d on buffer %u", offset, length, buffer); - else if UNLIKELY((offset%byte_align) != 0) + else if UNLIKELY((static_cast(offset)%byte_align) != 0) context->setError(AL_INVALID_VALUE, "Sub-range offset %d is not a multiple of frame size %d (%d unpack alignment)", offset, byte_align, align); - else if UNLIKELY((length%byte_align) != 0) + else if UNLIKELY((static_cast(length)%byte_align) != 0) context->setError(AL_INVALID_VALUE, "Sub-range length %d is not a multiple of frame size %d (%d unpack alignment)", length, byte_align, align); else { /* offset -> byte offset, length -> sample count */ - offset = offset/byte_align * align * frame_size; - length = length/byte_align * align; + size_t byteoff{static_cast(offset)/byte_align * align * frame_size}; + size_t samplen{static_cast(length)/byte_align * align}; - void *dst = albuf->mData.data() + offset; + void *dst = albuf->mData.data() + byteoff; if(usrfmt->type == UserFmtIMA4 && albuf->mFmtType == FmtShort) Convert_ALshort_ALima4(static_cast(dst), - static_cast(data), num_chans, length, align); + static_cast(data), num_chans, samplen, align); else if(usrfmt->type == UserFmtMSADPCM && albuf->mFmtType == FmtShort) Convert_ALshort_ALmsadpcm(static_cast(dst), - static_cast(data), num_chans, length, align); + static_cast(data), num_chans, samplen, align); else { - assert(long{usrfmt->type} == static_cast(albuf->mFmtType)); - memcpy(dst, data, length * frame_size); + assert(long{usrfmt->type} == long{albuf->mFmtType}); + memcpy(dst, data, size_t{samplen} * frame_size); } } } @@ -1052,14 +1085,14 @@ START_API_FUNC if UNLIKELY(value < 0) context->setError(AL_INVALID_VALUE, "Invalid unpack block alignment %d", value); else - albuf->UnpackAlign.store(value); + albuf->UnpackAlign = static_cast(value); break; case AL_PACK_BLOCK_ALIGNMENT_SOFT: if UNLIKELY(value < 0) context->setError(AL_INVALID_VALUE, "Invalid pack block alignment %d", value); else - albuf->PackAlign.store(value); + albuf->PackAlign = static_cast(value); break; default: @@ -1119,14 +1152,14 @@ START_API_FUNC if UNLIKELY(ReadRef(albuf->ref) != 0) context->setError(AL_INVALID_OPERATION, "Modifying in-use buffer %u's loop points", buffer); - else if UNLIKELY(values[0] < 0 || values[0] >= values[1] || - static_cast(values[1]) > albuf->SampleLen) + else if UNLIKELY(values[0] < 0 || values[0] >= values[1] + || static_cast(values[1]) > albuf->SampleLen) context->setError(AL_INVALID_VALUE, "Invalid loop point range %d -> %d on buffer %u", values[0], values[1], buffer); else { - albuf->LoopStart = values[0]; - albuf->LoopEnd = values[1]; + albuf->LoopStart = static_cast(values[0]); + albuf->LoopEnd = static_cast(values[1]); } break; @@ -1229,23 +1262,24 @@ START_API_FUNC break; case AL_BITS: - *value = BytesFromFmt(albuf->mFmtType) * 8; + *value = static_cast(BytesFromFmt(albuf->mFmtType) * 8); break; case AL_CHANNELS: - *value = ChannelsFromFmt(albuf->mFmtChannels); + *value = static_cast(ChannelsFromFmt(albuf->mFmtChannels)); break; case AL_SIZE: - *value = albuf->SampleLen * FrameSizeFromFmt(albuf->mFmtChannels, albuf->mFmtType); + *value = static_cast(albuf->SampleLen * + FrameSizeFromFmt(albuf->mFmtChannels, albuf->mFmtType)); break; case AL_UNPACK_BLOCK_ALIGNMENT_SOFT: - *value = albuf->UnpackAlign.load(); + *value = static_cast(albuf->UnpackAlign); break; case AL_PACK_BLOCK_ALIGNMENT_SOFT: - *value = albuf->PackAlign.load(); + *value = static_cast(albuf->PackAlign); break; default: @@ -1305,8 +1339,8 @@ START_API_FUNC else switch(param) { case AL_LOOP_POINTS_SOFT: - values[0] = albuf->LoopStart; - values[1] = albuf->LoopEnd; + values[0] = static_cast(albuf->LoopStart); + values[1] = static_cast(albuf->LoopEnd); break; default: @@ -1316,39 +1350,7 @@ START_API_FUNC END_API_FUNC -ALsizei BytesFromUserFmt(UserFmtType type) -{ - switch(type) - { - case UserFmtUByte: return sizeof(ALubyte); - case UserFmtShort: return sizeof(ALshort); - case UserFmtFloat: return sizeof(ALfloat); - case UserFmtDouble: return sizeof(ALdouble); - case UserFmtMulaw: return sizeof(ALubyte); - case UserFmtAlaw: return sizeof(ALubyte); - case UserFmtIMA4: break; /* not handled here */ - case UserFmtMSADPCM: break; /* not handled here */ - } - return 0; -} -ALsizei ChannelsFromUserFmt(UserFmtChannels chans) -{ - switch(chans) - { - case UserFmtMono: return 1; - case UserFmtStereo: return 2; - case UserFmtRear: return 2; - case UserFmtQuad: return 4; - case UserFmtX51: return 6; - case UserFmtX61: return 7; - case UserFmtX71: return 8; - case UserFmtBFormat2D: return 3; - case UserFmtBFormat3D: return 4; - } - return 0; -} - -ALsizei BytesFromFmt(FmtType type) +ALuint BytesFromFmt(FmtType type) { switch(type) { @@ -1361,7 +1363,7 @@ ALsizei BytesFromFmt(FmtType type) } return 0; } -ALsizei ChannelsFromFmt(FmtChannels chans) +ALuint ChannelsFromFmt(FmtChannels chans) { switch(chans) { diff --git a/al/buffer.h b/al/buffer.h index 2c01aae2..70faf56e 100644 --- a/al/buffer.h +++ b/al/buffer.h @@ -35,11 +35,6 @@ enum UserFmtChannels : unsigned char { UserFmtBFormat3D, /* WXYZ */ }; -ALsizei BytesFromUserFmt(UserFmtType type); -ALsizei ChannelsFromUserFmt(UserFmtChannels chans); -inline ALsizei FrameSizeFromUserFmt(UserFmtChannels chans, UserFmtType type) -{ return ChannelsFromUserFmt(chans) * BytesFromUserFmt(type); } - /* Storable formats */ enum FmtType : unsigned char { @@ -64,9 +59,9 @@ enum FmtChannels : unsigned char { #define MAX_INPUT_CHANNELS (8) -ALsizei BytesFromFmt(FmtType type); -ALsizei ChannelsFromFmt(FmtChannels chans); -inline ALsizei FrameSizeFromFmt(FmtChannels chans, FmtType type) +ALuint BytesFromFmt(FmtType type); +ALuint ChannelsFromFmt(FmtChannels chans); +inline ALuint FrameSizeFromFmt(FmtChannels chans, FmtType type) { return ChannelsFromFmt(chans) * BytesFromFmt(type); } @@ -81,14 +76,14 @@ struct ALbuffer { FmtType mFmtType{}; UserFmtType OriginalType{}; - ALsizei OriginalSize{0}; - ALsizei OriginalAlign{0}; + ALuint OriginalSize{0}; + ALuint OriginalAlign{0}; ALuint LoopStart{0u}; ALuint LoopEnd{0u}; - std::atomic UnpackAlign{0}; - std::atomic PackAlign{0}; + ALuint UnpackAlign{0}; + ALuint PackAlign{0}; ALbitfieldSOFT MappedAccess{0u}; ALsizei MappedOffset{0}; diff --git a/al/event.cpp b/al/event.cpp index 13b1533f..2832ace7 100644 --- a/al/event.cpp +++ b/al/event.cpp @@ -83,8 +83,8 @@ static int EventThread(ALCcontext *context) (evt.u.srcstate.state==AL_PAUSED) ? "AL_PAUSED" : (evt.u.srcstate.state==AL_STOPPED) ? "AL_STOPPED" : ""; context->mEventCb(AL_EVENT_TYPE_SOURCE_STATE_CHANGED_SOFT, evt.u.srcstate.id, - evt.u.srcstate.state, static_cast(msg.length()), msg.c_str(), - context->mEventParam); + static_cast(evt.u.srcstate.state), static_cast(msg.length()), + msg.c_str(), context->mEventParam); } else if(evt.EnumType == EventType_BufferCompleted) { diff --git a/al/event.h b/al/event.h index ae1b421b..9056d577 100644 --- a/al/event.h +++ b/al/event.h @@ -33,7 +33,7 @@ struct AsyncEvent { } srcstate; struct { ALuint id; - ALsizei count; + ALuint count; } bufcomp; struct { ALenum type; diff --git a/al/source.cpp b/al/source.cpp index 44c46d65..d368b3f0 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -305,72 +305,69 @@ ALdouble GetSourceOffset(ALsource *Source, ALenum name, ALCcontext *context) } while(refcount != device->MixCount.load(std::memory_order_relaxed)); ALdouble offset{0.0}; - if(voice) - { - const ALbufferlistitem *BufferList{Source->queue}; - const ALbuffer *BufferFmt{nullptr}; - ALboolean readFin{AL_FALSE}; - ALuint totalBufferLen{0u}; + if(!voice) return offset; - while(BufferList) - { - if(!BufferFmt) BufferFmt = BufferList->mBuffer; + const ALbufferlistitem *BufferList{Source->queue}; + const ALbuffer *BufferFmt{nullptr}; + ALboolean readFin{AL_FALSE}; + ALuint totalBufferLen{0u}; - readFin |= (BufferList == Current); - totalBufferLen += BufferList->mSampleLen; - if(!readFin) readPos += BufferList->mSampleLen; + while(BufferList) + { + if(!BufferFmt) BufferFmt = BufferList->mBuffer; - BufferList = BufferList->mNext.load(std::memory_order_relaxed); - } - assert(BufferFmt != nullptr); + readFin |= (BufferList == Current); + totalBufferLen += BufferList->mSampleLen; + if(!readFin) readPos += BufferList->mSampleLen; - if(Source->Looping) - readPos %= totalBufferLen; - else - { - /* Wrap back to 0 */ - if(readPos >= totalBufferLen) - readPos = readPosFrac = 0; - } + BufferList = BufferList->mNext.load(std::memory_order_relaxed); + } + assert(BufferFmt != nullptr); - offset = 0.0; - switch(name) - { - case AL_SEC_OFFSET: - offset = (readPos + static_cast(readPosFrac)/FRACTIONONE) / BufferFmt->Frequency; - break; + if(Source->Looping) + readPos %= totalBufferLen; + else + { + /* Wrap back to 0 */ + if(readPos >= totalBufferLen) + readPos = readPosFrac = 0; + } - case AL_SAMPLE_OFFSET: - offset = readPos + static_cast(readPosFrac)/FRACTIONONE; - break; + switch(name) + { + case AL_SEC_OFFSET: + offset = (readPos + static_cast(readPosFrac)/FRACTIONONE) / BufferFmt->Frequency; + break; - case AL_BYTE_OFFSET: - if(BufferFmt->OriginalType == UserFmtIMA4) - { - ALsizei align = (BufferFmt->OriginalAlign-1)/2 + 4; - ALuint BlockSize = align * ChannelsFromFmt(BufferFmt->mFmtChannels); - ALuint FrameBlockSize = BufferFmt->OriginalAlign; + case AL_SAMPLE_OFFSET: + offset = readPos + static_cast(readPosFrac)/FRACTIONONE; + break; - /* Round down to nearest ADPCM block */ - offset = static_cast(readPos / FrameBlockSize * BlockSize); - } - else if(BufferFmt->OriginalType == UserFmtMSADPCM) - { - ALsizei align = (BufferFmt->OriginalAlign-2)/2 + 7; - ALuint BlockSize = align * ChannelsFromFmt(BufferFmt->mFmtChannels); - ALuint FrameBlockSize = BufferFmt->OriginalAlign; + case AL_BYTE_OFFSET: + if(BufferFmt->OriginalType == UserFmtIMA4) + { + ALuint FrameBlockSize{BufferFmt->OriginalAlign}; + ALuint align{(BufferFmt->OriginalAlign-1)/2 + 4}; + ALuint BlockSize{align * ChannelsFromFmt(BufferFmt->mFmtChannels)}; - /* Round down to nearest ADPCM block */ - offset = static_cast(readPos / FrameBlockSize * BlockSize); - } - else - { - const ALsizei FrameSize{FrameSizeFromFmt(BufferFmt->mFmtChannels, - BufferFmt->mFmtType)}; - offset = static_cast(readPos * FrameSize); - } - break; + /* Round down to nearest ADPCM block */ + offset = static_cast(readPos / FrameBlockSize * BlockSize); } + else if(BufferFmt->OriginalType == UserFmtMSADPCM) + { + ALuint FrameBlockSize{BufferFmt->OriginalAlign}; + ALuint align{(FrameBlockSize-2)/2 + 7}; + ALuint BlockSize{align * ChannelsFromFmt(BufferFmt->mFmtChannels)}; + + /* Round down to nearest ADPCM block */ + offset = static_cast(readPos / FrameBlockSize * BlockSize); + } + else + { + const ALuint FrameSize{FrameSizeFromFmt(BufferFmt->mFmtChannels, BufferFmt->mFmtType)}; + offset = static_cast(readPos * FrameSize); + } + break; } return offset; @@ -418,13 +415,13 @@ al::optional GetSampleOffset(ALsource *Source) offset = static_cast(Source->Offset); if(BufferFmt->OriginalType == UserFmtIMA4) { - const ALsizei align{(BufferFmt->OriginalAlign-1)/2 + 4}; + const ALuint align{(BufferFmt->OriginalAlign-1)/2 + 4}; offset /= align * ChannelsFromFmt(BufferFmt->mFmtChannels); offset *= BufferFmt->OriginalAlign; } else if(BufferFmt->OriginalType == UserFmtMSADPCM) { - const ALsizei align{(BufferFmt->OriginalAlign-2)/2 + 7}; + const ALuint align{(BufferFmt->OriginalAlign-2)/2 + 7}; offset /= align * ChannelsFromFmt(BufferFmt->mFmtChannels); offset *= BufferFmt->OriginalAlign; } diff --git a/alc/mixvoice.cpp b/alc/mixvoice.cpp index 2efc5a24..09b76fb7 100644 --- a/alc/mixvoice.cpp +++ b/alc/mixvoice.cpp @@ -362,7 +362,7 @@ const ALfloat *DoFilters(BiquadFilter *lpfilter, BiquadFilter *hpfilter, ALfloat template -inline void LoadSampleArray(ALfloat *RESTRICT dst, const al::byte *src, ALint srcstep, +inline void LoadSampleArray(ALfloat *RESTRICT dst, const al::byte *src, const size_t srcstep, const size_t samples) { using SampleType = typename FmtTypeTraits::Type; @@ -372,7 +372,7 @@ inline void LoadSampleArray(ALfloat *RESTRICT dst, const al::byte *src, ALint sr dst[i] = FmtTypeTraits::to_float(ssrc[i*srcstep]); } -void LoadSamples(ALfloat *RESTRICT dst, const al::byte *src, ALint srcstep, FmtType srctype, +void LoadSamples(ALfloat *RESTRICT dst, const al::byte *src, const size_t srcstep, FmtType srctype, const size_t samples) { #define HANDLE_FMT(T) case T: LoadSampleArray(dst, src, srcstep, samples); break @@ -389,7 +389,7 @@ void LoadSamples(ALfloat *RESTRICT dst, const al::byte *src, ALint srcstep, FmtT } ALfloat *LoadBufferStatic(ALbufferlistitem *BufferListItem, ALbufferlistitem *&BufferLoopItem, - const ALsizei NumChannels, const ALsizei SampleSize, const ALsizei chan, ALuint DataPosInt, + const size_t NumChannels, const size_t SampleSize, const size_t chan, size_t DataPosInt, al::span SrcBuffer) { const ALbuffer *Buffer{BufferListItem->mBuffer}; @@ -439,7 +439,7 @@ ALfloat *LoadBufferStatic(ALbufferlistitem *BufferListItem, ALbufferlistitem *&B } ALfloat *LoadBufferQueue(ALbufferlistitem *BufferListItem, ALbufferlistitem *BufferLoopItem, - const ALsizei NumChannels, const ALsizei SampleSize, const ALsizei chan, ALuint DataPosInt, + const size_t NumChannels, const size_t SampleSize, const size_t chan, size_t DataPosInt, al::span SrcBuffer) { /* Crawl the buffer queue to fill in the temp buffer */ @@ -485,9 +485,9 @@ void ALvoice::mix(State vstate, ALCcontext *Context, const ALuint SamplesToDo) ALuint DataPosFrac{mPositionFrac.load(std::memory_order_relaxed)}; ALbufferlistitem *BufferListItem{mCurrentBuffer.load(std::memory_order_relaxed)}; ALbufferlistitem *BufferLoopItem{mLoopBuffer.load(std::memory_order_relaxed)}; - const ALsizei NumChannels{mNumChannels}; - const ALsizei SampleSize{mSampleSize}; - const ALint increment{mStep}; + const auto NumChannels = static_cast(mNumChannels); + const auto SampleSize = static_cast(mSampleSize); + const auto increment = static_cast(mStep); if(increment < 1) return; ASSUME(NumChannels > 0); @@ -508,7 +508,7 @@ void ALvoice::mix(State vstate, ALCcontext *Context, const ALuint SamplesToDo) if(!Counter) { /* No fading, just overwrite the old/current params. */ - for(ALsizei chan{0};chan < NumChannels;chan++) + for(ALuint chan{0};chan < NumChannels;chan++) { ChannelData &chandata = mChans[chan]; DirectParams &parms = chandata.mDryParams; @@ -530,7 +530,7 @@ void ALvoice::mix(State vstate, ALCcontext *Context, const ALuint SamplesToDo) } else if((mFlags&VOICE_HAS_HRTF)) { - for(ALsizei chan{0};chan < NumChannels;chan++) + for(ALuint chan{0};chan < NumChannels;chan++) { DirectParams &parms = mChans[chan].mDryParams; if(!(parms.Hrtf.Old.Gain > GAIN_SILENCE_THRESHOLD)) @@ -545,7 +545,7 @@ void ALvoice::mix(State vstate, ALCcontext *Context, const ALuint SamplesToDo) } } - ALsizei buffers_done{0}; + ALuint buffers_done{0u}; ALuint OutPos{0u}; do { /* Figure out how many buffer samples will be needed */ @@ -575,11 +575,11 @@ void ALvoice::mix(State vstate, ALCcontext *Context, const ALuint SamplesToDo) * unless this is the last update. */ if(DstBufferSize < SamplesToDo-OutPos) - DstBufferSize &= ~3; + DstBufferSize &= ~3u; } ASSUME(DstBufferSize > 0); - for(ALsizei chan{0};chan < NumChannels;chan++) + for(ALuint chan{0};chan < NumChannels;chan++) { ChannelData &chandata = mChans[chan]; const al::span SrcData{Device->SourceData, SrcBufferSize}; @@ -616,8 +616,8 @@ void ALvoice::mix(State vstate, ALCcontext *Context, const ALuint SamplesToDo) chandata.mPrevSamples.size(), chandata.mPrevSamples.begin()); /* Resample, then apply ambisonic upsampling as needed. */ - const ALfloat *ResampledData{Resample(&mResampleState, - &SrcData[MAX_RESAMPLE_PADDING], DataPosFrac, increment, + const ALfloat *ResampledData{Resample(&mResampleState, &SrcData[MAX_RESAMPLE_PADDING], + DataPosFrac, static_cast(increment), {Device->ResampledData, DstBufferSize})}; if((mFlags&VOICE_IS_AMBISONIC)) { -- cgit v1.2.3 From 2e010d29cba51aec339179d52d3faddf84faafb0 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 12 Sep 2019 11:33:04 -0700 Subject: Clean up implicit conversions in source.cpp --- al/source.cpp | 2512 +++++++++++++++++++++++++++--------------------------- al/source.h | 16 +- alc/alu.h | 4 +- alc/mixvoice.cpp | 4 +- 4 files changed, 1270 insertions(+), 1266 deletions(-) (limited to 'al/source.cpp') diff --git a/al/source.cpp b/al/source.cpp index d368b3f0..3c22b620 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -74,6 +74,7 @@ namespace { using namespace std::placeholders; +using std::chrono::nanoseconds; ALvoice *GetSourceVoice(ALsource *source, ALCcontext *context) { @@ -175,7 +176,7 @@ void UpdateSourceProps(const ALsource *source, ALvoice *voice, ALCcontext *conte * samples. The offset is relative to the start of the queue (not the start of * the current buffer). */ -int64_t GetSourceSampleOffset(ALsource *Source, ALCcontext *context, std::chrono::nanoseconds *clocktime) +int64_t GetSourceSampleOffset(ALsource *Source, ALCcontext *context, nanoseconds *clocktime) { ALCdevice *device{context->mDevice.get()}; const ALbufferlistitem *Current; @@ -221,7 +222,7 @@ int64_t GetSourceSampleOffset(ALsource *Source, ALCcontext *context, std::chrono * Gets the current read offset for the given Source, in seconds. The offset is * relative to the start of the queue (not the start of the current buffer). */ -ALdouble GetSourceSecOffset(ALsource *Source, ALCcontext *context, std::chrono::nanoseconds *clocktime) +ALdouble GetSourceSecOffset(ALsource *Source, ALCcontext *context, nanoseconds *clocktime) { ALCdevice *device{context->mDevice.get()}; const ALbufferlistitem *Current; @@ -465,49 +466,72 @@ al::optional GetSampleOffset(ALsource *Source) } -ALsource *AllocSource(ALCcontext *context) +/** + * Returns if the last known state for the source was playing or paused. Does + * not sync with the mixer voice. + */ +inline bool IsPlayingOrPaused(ALsource *source) +{ return source->state == AL_PLAYING || source->state == AL_PAUSED; } + +/** + * Returns an updated source state using the matching voice's status (or lack + * thereof). + */ +inline ALenum GetSourceState(ALsource *source, ALvoice *voice) { - ALCdevice *device{context->mDevice.get()}; - std::lock_guard _{context->mSourceLock}; - if(context->mNumSources >= device->SourcesMax) - { - context->setError(AL_OUT_OF_MEMORY, "Exceeding %u source limit", device->SourcesMax); - return nullptr; - } - auto sublist = std::find_if(context->mSourceList.begin(), context->mSourceList.end(), - [](const SourceSubList &entry) noexcept -> bool - { return entry.FreeMask != 0; } - ); - auto lidx = static_cast(std::distance(context->mSourceList.begin(), sublist)); - ALsizei slidx; - if LIKELY(sublist != context->mSourceList.end()) - slidx = CTZ64(sublist->FreeMask); - else + if(!voice && source->state == AL_PLAYING) + source->state = AL_STOPPED; + return source->state; +} + +/** + * Returns if the source should specify an update, given the context's + * deferring state and the source's last known state. + */ +inline bool SourceShouldUpdate(ALsource *source, ALCcontext *context) +{ + return !context->mDeferUpdates.load(std::memory_order_acquire) && + IsPlayingOrPaused(source); +} + + +bool EnsureSources(ALCcontext *context, size_t needed) +{ + size_t count{std::accumulate(context->mSourceList.cbegin(), context->mSourceList.cend(), + size_t{0}, + [](size_t cur, const SourceSubList &sublist) noexcept -> size_t + { return cur + static_cast(POPCNT64(~sublist.FreeMask)); } + )}; + + while(needed > count) { - /* Don't allocate so many list entries that the 32-bit ID could - * overflow... - */ if UNLIKELY(context->mSourceList.size() >= 1<<25) - { - context->setError(AL_OUT_OF_MEMORY, "Too many sources allocated"); - return nullptr; - } - context->mSourceList.emplace_back(); - sublist = context->mSourceList.end() - 1; + return false; + context->mSourceList.emplace_back(); + auto sublist = context->mSourceList.end() - 1; sublist->FreeMask = ~0_u64; - sublist->Sources = static_cast(al_calloc(16, sizeof(ALsource)*64)); + sublist->Sources = static_cast(al_calloc(alignof(ALsource), sizeof(ALsource)*64)); if UNLIKELY(!sublist->Sources) { context->mSourceList.pop_back(); - context->setError(AL_OUT_OF_MEMORY, "Failed to allocate source batch"); - return nullptr; + return false; } - - slidx = 0; + count += 64; } + return true; +} - ALsource *source{::new (sublist->Sources + slidx) ALsource{device->NumAuxSends}}; +ALsource *AllocSource(ALCcontext *context, ALsizei num_sends) +{ + auto sublist = std::find_if(context->mSourceList.begin(), context->mSourceList.end(), + [](const SourceSubList &entry) noexcept -> bool + { return entry.FreeMask != 0; } + ); + auto lidx = static_cast(std::distance(context->mSourceList.begin(), sublist)); + auto slidx = static_cast(CTZ64(sublist->FreeMask)); + + ALsource *source{::new (sublist->Sources + slidx) ALsource{num_sends}}; /* Add 1 to avoid source ID 0. */ source->id = ((lidx<<6) | slidx) + 1; @@ -520,26 +544,28 @@ ALsource *AllocSource(ALCcontext *context) void FreeSource(ALCcontext *context, ALsource *source) { - ALuint id = source->id - 1; - ALsizei lidx = id >> 6; - ALsizei slidx = id & 0x3f; + const ALuint id{source->id - 1}; + const size_t lidx{id >> 6}; + const ALuint slidx{id & 0x3f}; - ALCdevice *device{context->mDevice.get()}; - BackendUniqueLock backlock{*device->Backend}; - if(ALvoice *voice{GetSourceVoice(source, context)}) - { - voice->mCurrentBuffer.store(nullptr, std::memory_order_relaxed); - voice->mLoopBuffer.store(nullptr, std::memory_order_relaxed); - voice->mSourceID.store(0u, std::memory_order_relaxed); - std::atomic_thread_fence(std::memory_order_release); - /* Don't set the voice to stopping if it was already stopped or - * stopping. - */ - ALvoice::State oldvstate{ALvoice::Playing}; - voice->mPlayState.compare_exchange_strong(oldvstate, ALvoice::Stopping, - std::memory_order_acq_rel, std::memory_order_acquire); + if(IsPlayingOrPaused(source)) + { + ALCdevice *device{context->mDevice.get()}; + BackendLockGuard _{*device->Backend}; + if(ALvoice *voice{GetSourceVoice(source, context)}) + { + voice->mCurrentBuffer.store(nullptr, std::memory_order_relaxed); + voice->mLoopBuffer.store(nullptr, std::memory_order_relaxed); + voice->mSourceID.store(0u, std::memory_order_relaxed); + std::atomic_thread_fence(std::memory_order_release); + /* Don't set the voice to stopping if it was already stopped or + * stopping. + */ + ALvoice::State oldvstate{ALvoice::Playing}; + voice->mPlayState.compare_exchange_strong(oldvstate, ALvoice::Stopping, + std::memory_order_acq_rel, std::memory_order_acquire); + } } - backlock.unlock(); al::destroy_at(source); @@ -550,8 +576,8 @@ void FreeSource(ALCcontext *context, ALsource *source) inline ALsource *LookupSource(ALCcontext *context, ALuint id) noexcept { - ALuint lidx = (id-1) >> 6; - ALsizei slidx = (id-1) & 0x3f; + const size_t lidx{(id-1) >> 6}; + const ALuint slidx{(id-1) & 0x3f}; if UNLIKELY(lidx >= context->mSourceList.size()) return nullptr; @@ -563,8 +589,8 @@ inline ALsource *LookupSource(ALCcontext *context, ALuint id) noexcept inline ALbuffer *LookupBuffer(ALCdevice *device, ALuint id) noexcept { - ALuint lidx = (id-1) >> 6; - ALsizei slidx = (id-1) & 0x3f; + const size_t lidx{(id-1) >> 6}; + const ALuint slidx{(id-1) & 0x3f}; if UNLIKELY(lidx >= device->BufferList.size()) return nullptr; @@ -576,8 +602,8 @@ inline ALbuffer *LookupBuffer(ALCdevice *device, ALuint id) noexcept inline ALfilter *LookupFilter(ALCdevice *device, ALuint id) noexcept { - ALuint lidx = (id-1) >> 6; - ALsizei slidx = (id-1) & 0x3f; + const size_t lidx{(id-1) >> 6}; + const ALuint slidx{(id-1) & 0x3f}; if UNLIKELY(lidx >= device->FilterList.size()) return nullptr; @@ -589,8 +615,8 @@ inline ALfilter *LookupFilter(ALCdevice *device, ALuint id) noexcept inline ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id) noexcept { - ALuint lidx = (id-1) >> 6; - ALsizei slidx = (id-1) & 0x3f; + const size_t lidx{(id-1) >> 6}; + const ALuint slidx{(id-1) & 0x3f}; if UNLIKELY(lidx >= context->mEffectSlotList.size()) return nullptr; @@ -669,34 +695,6 @@ enum SourceProp : ALenum { srcSecOffsetClockSOFT = AL_SEC_OFFSET_CLOCK_SOFT, }; -/** - * Returns if the last known state for the source was playing or paused. Does - * not sync with the mixer voice. - */ -inline bool IsPlayingOrPaused(ALsource *source) -{ return source->state == AL_PLAYING || source->state == AL_PAUSED; } - -/** - * Returns an updated source state using the matching voice's status (or lack - * thereof). - */ -inline ALenum GetSourceState(ALsource *source, ALvoice *voice) -{ - if(!voice && source->state == AL_PLAYING) - source->state = AL_STOPPED; - return source->state; -} - -/** - * Returns if the source should specify an update, given the context's - * deferring state and the source's last known state. - */ -inline bool SourceShouldUpdate(ALsource *source, ALCcontext *context) -{ - return !context->mDeferUpdates.load(std::memory_order_acquire) && - IsPlayingOrPaused(source); -} - /** Can only be called while the mixer is locked! */ void SendStateChangeEvent(ALCcontext *context, ALuint id, ALenum state) @@ -712,7 +710,7 @@ void SendStateChangeEvent(ALCcontext *context, ALuint id, ALenum state) auto evt_vec = ring->getWriteVector(); if(evt_vec.first.len < 1) return; - AsyncEvent *evt{new (evt_vec.first.buf) AsyncEvent{EventType_SourceStateChange}}; + AsyncEvent *evt{::new (evt_vec.first.buf) AsyncEvent{EventType_SourceStateChange}}; evt->u.srcstate.id = id; evt->u.srcstate.state = state; ring->writeAdvance(1); @@ -726,61 +724,61 @@ ALuint FloatValsByProp(ALenum prop) { switch(static_cast(prop)) { - case AL_PITCH: - case AL_GAIN: - case AL_MIN_GAIN: - case AL_MAX_GAIN: - case AL_MAX_DISTANCE: - case AL_ROLLOFF_FACTOR: - case AL_DOPPLER_FACTOR: - case AL_CONE_OUTER_GAIN: - case AL_SEC_OFFSET: - case AL_SAMPLE_OFFSET: - case AL_BYTE_OFFSET: - case AL_CONE_INNER_ANGLE: - case AL_CONE_OUTER_ANGLE: - case AL_REFERENCE_DISTANCE: - case AL_CONE_OUTER_GAINHF: - case AL_AIR_ABSORPTION_FACTOR: - case AL_ROOM_ROLLOFF_FACTOR: - case AL_DIRECT_FILTER_GAINHF_AUTO: - case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: - case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: - case AL_DIRECT_CHANNELS_SOFT: - case AL_DISTANCE_MODEL: - case AL_SOURCE_RELATIVE: - case AL_LOOPING: - case AL_SOURCE_STATE: - case AL_BUFFERS_QUEUED: - case AL_BUFFERS_PROCESSED: - case AL_SOURCE_TYPE: - case AL_SOURCE_RADIUS: - case AL_SOURCE_RESAMPLER_SOFT: - case AL_SOURCE_SPATIALIZE_SOFT: - return 1; - - case AL_STEREO_ANGLES: - return 2; - - case AL_POSITION: - case AL_VELOCITY: - case AL_DIRECTION: - return 3; - - case AL_ORIENTATION: - return 6; - - case AL_SEC_OFFSET_LATENCY_SOFT: - case AL_SEC_OFFSET_CLOCK_SOFT: - break; /* Double only */ - - case AL_BUFFER: - case AL_DIRECT_FILTER: - case AL_AUXILIARY_SEND_FILTER: - break; /* i/i64 only */ - case AL_SAMPLE_OFFSET_LATENCY_SOFT: - case AL_SAMPLE_OFFSET_CLOCK_SOFT: - break; /* i64 only */ + case AL_PITCH: + case AL_GAIN: + case AL_MIN_GAIN: + case AL_MAX_GAIN: + case AL_MAX_DISTANCE: + case AL_ROLLOFF_FACTOR: + case AL_DOPPLER_FACTOR: + case AL_CONE_OUTER_GAIN: + case AL_SEC_OFFSET: + case AL_SAMPLE_OFFSET: + case AL_BYTE_OFFSET: + case AL_CONE_INNER_ANGLE: + case AL_CONE_OUTER_ANGLE: + case AL_REFERENCE_DISTANCE: + case AL_CONE_OUTER_GAINHF: + case AL_AIR_ABSORPTION_FACTOR: + case AL_ROOM_ROLLOFF_FACTOR: + case AL_DIRECT_FILTER_GAINHF_AUTO: + case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: + case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: + case AL_DIRECT_CHANNELS_SOFT: + case AL_DISTANCE_MODEL: + case AL_SOURCE_RELATIVE: + case AL_LOOPING: + case AL_SOURCE_STATE: + case AL_BUFFERS_QUEUED: + case AL_BUFFERS_PROCESSED: + case AL_SOURCE_TYPE: + case AL_SOURCE_RADIUS: + case AL_SOURCE_RESAMPLER_SOFT: + case AL_SOURCE_SPATIALIZE_SOFT: + return 1; + + case AL_STEREO_ANGLES: + return 2; + + case AL_POSITION: + case AL_VELOCITY: + case AL_DIRECTION: + return 3; + + case AL_ORIENTATION: + return 6; + + case AL_SEC_OFFSET_LATENCY_SOFT: + case AL_SEC_OFFSET_CLOCK_SOFT: + break; /* Double only */ + + case AL_BUFFER: + case AL_DIRECT_FILTER: + case AL_AUXILIARY_SEND_FILTER: + break; /* i/i64 only */ + case AL_SAMPLE_OFFSET_LATENCY_SOFT: + case AL_SAMPLE_OFFSET_CLOCK_SOFT: + break; /* i64 only */ } return 0; } @@ -788,59 +786,59 @@ ALuint DoubleValsByProp(ALenum prop) { switch(static_cast(prop)) { - case AL_PITCH: - case AL_GAIN: - case AL_MIN_GAIN: - case AL_MAX_GAIN: - case AL_MAX_DISTANCE: - case AL_ROLLOFF_FACTOR: - case AL_DOPPLER_FACTOR: - case AL_CONE_OUTER_GAIN: - case AL_SEC_OFFSET: - case AL_SAMPLE_OFFSET: - case AL_BYTE_OFFSET: - case AL_CONE_INNER_ANGLE: - case AL_CONE_OUTER_ANGLE: - case AL_REFERENCE_DISTANCE: - case AL_CONE_OUTER_GAINHF: - case AL_AIR_ABSORPTION_FACTOR: - case AL_ROOM_ROLLOFF_FACTOR: - case AL_DIRECT_FILTER_GAINHF_AUTO: - case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: - case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: - case AL_DIRECT_CHANNELS_SOFT: - case AL_DISTANCE_MODEL: - case AL_SOURCE_RELATIVE: - case AL_LOOPING: - case AL_SOURCE_STATE: - case AL_BUFFERS_QUEUED: - case AL_BUFFERS_PROCESSED: - case AL_SOURCE_TYPE: - case AL_SOURCE_RADIUS: - case AL_SOURCE_RESAMPLER_SOFT: - case AL_SOURCE_SPATIALIZE_SOFT: - return 1; - - case AL_SEC_OFFSET_LATENCY_SOFT: - case AL_SEC_OFFSET_CLOCK_SOFT: - case AL_STEREO_ANGLES: - return 2; - - case AL_POSITION: - case AL_VELOCITY: - case AL_DIRECTION: - return 3; - - case AL_ORIENTATION: - return 6; - - case AL_BUFFER: - case AL_DIRECT_FILTER: - case AL_AUXILIARY_SEND_FILTER: - break; /* i/i64 only */ - case AL_SAMPLE_OFFSET_LATENCY_SOFT: - case AL_SAMPLE_OFFSET_CLOCK_SOFT: - break; /* i64 only */ + case AL_PITCH: + case AL_GAIN: + case AL_MIN_GAIN: + case AL_MAX_GAIN: + case AL_MAX_DISTANCE: + case AL_ROLLOFF_FACTOR: + case AL_DOPPLER_FACTOR: + case AL_CONE_OUTER_GAIN: + case AL_SEC_OFFSET: + case AL_SAMPLE_OFFSET: + case AL_BYTE_OFFSET: + case AL_CONE_INNER_ANGLE: + case AL_CONE_OUTER_ANGLE: + case AL_REFERENCE_DISTANCE: + case AL_CONE_OUTER_GAINHF: + case AL_AIR_ABSORPTION_FACTOR: + case AL_ROOM_ROLLOFF_FACTOR: + case AL_DIRECT_FILTER_GAINHF_AUTO: + case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: + case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: + case AL_DIRECT_CHANNELS_SOFT: + case AL_DISTANCE_MODEL: + case AL_SOURCE_RELATIVE: + case AL_LOOPING: + case AL_SOURCE_STATE: + case AL_BUFFERS_QUEUED: + case AL_BUFFERS_PROCESSED: + case AL_SOURCE_TYPE: + case AL_SOURCE_RADIUS: + case AL_SOURCE_RESAMPLER_SOFT: + case AL_SOURCE_SPATIALIZE_SOFT: + return 1; + + case AL_SEC_OFFSET_LATENCY_SOFT: + case AL_SEC_OFFSET_CLOCK_SOFT: + case AL_STEREO_ANGLES: + return 2; + + case AL_POSITION: + case AL_VELOCITY: + case AL_DIRECTION: + return 3; + + case AL_ORIENTATION: + return 6; + + case AL_BUFFER: + case AL_DIRECT_FILTER: + case AL_AUXILIARY_SEND_FILTER: + break; /* i/i64 only */ + case AL_SAMPLE_OFFSET_LATENCY_SOFT: + case AL_SAMPLE_OFFSET_CLOCK_SOFT: + break; /* i64 only */ } return 0; } @@ -879,222 +877,222 @@ bool SetSourcefv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a switch(prop) { - case AL_SEC_OFFSET_LATENCY_SOFT: - case AL_SEC_OFFSET_CLOCK_SOFT: - /* Query only */ - SETERR_RETURN(Context, AL_INVALID_OPERATION, false, - "Setting read-only source property 0x%04x", prop); + case AL_SEC_OFFSET_LATENCY_SOFT: + case AL_SEC_OFFSET_CLOCK_SOFT: + /* Query only */ + SETERR_RETURN(Context, AL_INVALID_OPERATION, false, + "Setting read-only source property 0x%04x", prop); - case AL_PITCH: - CHECKSIZE(values, 1); - CHECKVAL(values[0] >= 0.0f); + case AL_PITCH: + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f); - Source->Pitch = values[0]; - return UpdateSourceProps(Source, Context); + Source->Pitch = values[0]; + return UpdateSourceProps(Source, Context); - case AL_CONE_INNER_ANGLE: - CHECKSIZE(values, 1); - CHECKVAL(values[0] >= 0.0f && values[0] <= 360.0f); + case AL_CONE_INNER_ANGLE: + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f && values[0] <= 360.0f); - Source->InnerAngle = values[0]; - return UpdateSourceProps(Source, Context); + Source->InnerAngle = values[0]; + return UpdateSourceProps(Source, Context); - case AL_CONE_OUTER_ANGLE: - CHECKSIZE(values, 1); - CHECKVAL(values[0] >= 0.0f && values[0] <= 360.0f); + case AL_CONE_OUTER_ANGLE: + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f && values[0] <= 360.0f); - Source->OuterAngle = values[0]; - return UpdateSourceProps(Source, Context); + Source->OuterAngle = values[0]; + return UpdateSourceProps(Source, Context); - case AL_GAIN: - CHECKSIZE(values, 1); - CHECKVAL(values[0] >= 0.0f); + case AL_GAIN: + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f); - Source->Gain = values[0]; - return UpdateSourceProps(Source, Context); + Source->Gain = values[0]; + return UpdateSourceProps(Source, Context); - case AL_MAX_DISTANCE: - CHECKSIZE(values, 1); - CHECKVAL(values[0] >= 0.0f); + case AL_MAX_DISTANCE: + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f); - Source->MaxDistance = values[0]; - return UpdateSourceProps(Source, Context); + Source->MaxDistance = values[0]; + return UpdateSourceProps(Source, Context); - case AL_ROLLOFF_FACTOR: - CHECKSIZE(values, 1); - CHECKVAL(values[0] >= 0.0f); + case AL_ROLLOFF_FACTOR: + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f); - Source->RolloffFactor = values[0]; - return UpdateSourceProps(Source, Context); + Source->RolloffFactor = values[0]; + return UpdateSourceProps(Source, Context); - case AL_REFERENCE_DISTANCE: - CHECKSIZE(values, 1); - CHECKVAL(values[0] >= 0.0f); + case AL_REFERENCE_DISTANCE: + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f); - Source->RefDistance = values[0]; - return UpdateSourceProps(Source, Context); + Source->RefDistance = values[0]; + return UpdateSourceProps(Source, Context); - case AL_MIN_GAIN: - CHECKSIZE(values, 1); - CHECKVAL(values[0] >= 0.0f); + case AL_MIN_GAIN: + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f); - Source->MinGain = values[0]; - return UpdateSourceProps(Source, Context); + Source->MinGain = values[0]; + return UpdateSourceProps(Source, Context); - case AL_MAX_GAIN: - CHECKSIZE(values, 1); - CHECKVAL(values[0] >= 0.0f); + case AL_MAX_GAIN: + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f); - Source->MaxGain = values[0]; - return UpdateSourceProps(Source, Context); + Source->MaxGain = values[0]; + return UpdateSourceProps(Source, Context); - case AL_CONE_OUTER_GAIN: - CHECKSIZE(values, 1); - CHECKVAL(values[0] >= 0.0f && values[0] <= 1.0f); + case AL_CONE_OUTER_GAIN: + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f && values[0] <= 1.0f); - Source->OuterGain = values[0]; - return UpdateSourceProps(Source, Context); + Source->OuterGain = values[0]; + return UpdateSourceProps(Source, Context); - case AL_CONE_OUTER_GAINHF: - CHECKSIZE(values, 1); - CHECKVAL(values[0] >= 0.0f && values[0] <= 1.0f); + case AL_CONE_OUTER_GAINHF: + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f && values[0] <= 1.0f); - Source->OuterGainHF = values[0]; - return UpdateSourceProps(Source, Context); + Source->OuterGainHF = values[0]; + return UpdateSourceProps(Source, Context); - case AL_AIR_ABSORPTION_FACTOR: - CHECKSIZE(values, 1); - CHECKVAL(values[0] >= 0.0f && values[0] <= 10.0f); + case AL_AIR_ABSORPTION_FACTOR: + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f && values[0] <= 10.0f); - Source->AirAbsorptionFactor = values[0]; - return UpdateSourceProps(Source, Context); + Source->AirAbsorptionFactor = values[0]; + return UpdateSourceProps(Source, Context); - case AL_ROOM_ROLLOFF_FACTOR: - CHECKSIZE(values, 1); - CHECKVAL(values[0] >= 0.0f && values[0] <= 10.0f); + case AL_ROOM_ROLLOFF_FACTOR: + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f && values[0] <= 10.0f); - Source->RoomRolloffFactor = values[0]; - return UpdateSourceProps(Source, Context); + Source->RoomRolloffFactor = values[0]; + return UpdateSourceProps(Source, Context); - case AL_DOPPLER_FACTOR: - CHECKSIZE(values, 1); - CHECKVAL(values[0] >= 0.0f && values[0] <= 1.0f); + case AL_DOPPLER_FACTOR: + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f && values[0] <= 1.0f); - Source->DopplerFactor = values[0]; - return UpdateSourceProps(Source, Context); + Source->DopplerFactor = values[0]; + return UpdateSourceProps(Source, Context); - case AL_SEC_OFFSET: - case AL_SAMPLE_OFFSET: - case AL_BYTE_OFFSET: - CHECKSIZE(values, 1); - CHECKVAL(values[0] >= 0.0f); + case AL_SEC_OFFSET: + case AL_SAMPLE_OFFSET: + case AL_BYTE_OFFSET: + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f); - Source->OffsetType = prop; - Source->Offset = values[0]; + Source->OffsetType = prop; + Source->Offset = values[0]; - if(IsPlayingOrPaused(Source)) + if(IsPlayingOrPaused(Source)) + { + ALCdevice *device{Context->mDevice.get()}; + BackendLockGuard _{*device->Backend}; + /* Double-check that the source is still playing while we have the + * lock. + */ + if(ALvoice *voice{GetSourceVoice(Source, Context)}) { - ALCdevice *device{Context->mDevice.get()}; - BackendLockGuard _{*device->Backend}; - /* Double-check that the source is still playing while we have - * the lock. - */ - if(ALvoice *voice{GetSourceVoice(Source, Context)}) - { - auto vpos = GetSampleOffset(Source); - if(!vpos) SETERR_RETURN(Context, AL_INVALID_VALUE, false, "Invalid offset"); - - voice->mPosition.store(vpos->pos, std::memory_order_relaxed); - voice->mPositionFrac.store(vpos->frac, std::memory_order_relaxed); - voice->mCurrentBuffer.store(vpos->bufferitem, std::memory_order_release); - } - } - return true; + auto vpos = GetSampleOffset(Source); + if(!vpos) SETERR_RETURN(Context, AL_INVALID_VALUE, false, "Invalid offset"); - case AL_SOURCE_RADIUS: - CHECKSIZE(values, 1); - CHECKVAL(values[0] >= 0.0f && std::isfinite(values[0])); - - Source->Radius = values[0]; - return UpdateSourceProps(Source, Context); - - case AL_STEREO_ANGLES: - CHECKSIZE(values, 2); - CHECKVAL(std::isfinite(values[0]) && std::isfinite(values[1])); - - Source->StereoPan[0] = values[0]; - Source->StereoPan[1] = values[1]; - return UpdateSourceProps(Source, Context); - - - case AL_POSITION: - CHECKSIZE(values, 3); - CHECKVAL(std::isfinite(values[0]) && std::isfinite(values[1]) && std::isfinite(values[2])); - - Source->Position[0] = values[0]; - Source->Position[1] = values[1]; - Source->Position[2] = values[2]; - return UpdateSourceProps(Source, Context); - - case AL_VELOCITY: - CHECKSIZE(values, 3); - CHECKVAL(std::isfinite(values[0]) && std::isfinite(values[1]) && std::isfinite(values[2])); - - Source->Velocity[0] = values[0]; - Source->Velocity[1] = values[1]; - Source->Velocity[2] = values[2]; - return UpdateSourceProps(Source, Context); - - case AL_DIRECTION: - CHECKSIZE(values, 3); - CHECKVAL(std::isfinite(values[0]) && std::isfinite(values[1]) && std::isfinite(values[2])); - - Source->Direction[0] = values[0]; - Source->Direction[1] = values[1]; - Source->Direction[2] = values[2]; - return UpdateSourceProps(Source, Context); - - case AL_ORIENTATION: - CHECKSIZE(values, 6); - CHECKVAL(std::isfinite(values[0]) && std::isfinite(values[1]) && std::isfinite(values[2]) && - std::isfinite(values[3]) && std::isfinite(values[4]) && std::isfinite(values[5])); - - Source->OrientAt[0] = values[0]; - Source->OrientAt[1] = values[1]; - Source->OrientAt[2] = values[2]; - Source->OrientUp[0] = values[3]; - Source->OrientUp[1] = values[4]; - Source->OrientUp[2] = values[5]; - return UpdateSourceProps(Source, Context); - - - case AL_SOURCE_RELATIVE: - case AL_LOOPING: - case AL_SOURCE_STATE: - case AL_SOURCE_TYPE: - case AL_DISTANCE_MODEL: - case AL_DIRECT_FILTER_GAINHF_AUTO: - case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: - case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: - case AL_DIRECT_CHANNELS_SOFT: - case AL_SOURCE_RESAMPLER_SOFT: - case AL_SOURCE_SPATIALIZE_SOFT: - CHECKSIZE(values, 1); - ival = static_cast(values[0]); - return SetSourceiv(Source, Context, prop, {&ival, 1u}); - - case AL_BUFFERS_QUEUED: - case AL_BUFFERS_PROCESSED: - CHECKSIZE(values, 1); - ival = static_cast(static_cast(values[0])); - return SetSourceiv(Source, Context, prop, {&ival, 1u}); - - case AL_BUFFER: - case AL_DIRECT_FILTER: - case AL_AUXILIARY_SEND_FILTER: - case AL_SAMPLE_OFFSET_LATENCY_SOFT: - case AL_SAMPLE_OFFSET_CLOCK_SOFT: - break; + voice->mPosition.store(vpos->pos, std::memory_order_relaxed); + voice->mPositionFrac.store(vpos->frac, std::memory_order_relaxed); + voice->mCurrentBuffer.store(vpos->bufferitem, std::memory_order_release); + } + } + return true; + + case AL_SOURCE_RADIUS: + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0.0f && std::isfinite(values[0])); + + Source->Radius = values[0]; + return UpdateSourceProps(Source, Context); + + case AL_STEREO_ANGLES: + CHECKSIZE(values, 2); + CHECKVAL(std::isfinite(values[0]) && std::isfinite(values[1])); + + Source->StereoPan[0] = values[0]; + Source->StereoPan[1] = values[1]; + return UpdateSourceProps(Source, Context); + + + case AL_POSITION: + CHECKSIZE(values, 3); + CHECKVAL(std::isfinite(values[0]) && std::isfinite(values[1]) && std::isfinite(values[2])); + + Source->Position[0] = values[0]; + Source->Position[1] = values[1]; + Source->Position[2] = values[2]; + return UpdateSourceProps(Source, Context); + + case AL_VELOCITY: + CHECKSIZE(values, 3); + CHECKVAL(std::isfinite(values[0]) && std::isfinite(values[1]) && std::isfinite(values[2])); + + Source->Velocity[0] = values[0]; + Source->Velocity[1] = values[1]; + Source->Velocity[2] = values[2]; + return UpdateSourceProps(Source, Context); + + case AL_DIRECTION: + CHECKSIZE(values, 3); + CHECKVAL(std::isfinite(values[0]) && std::isfinite(values[1]) && std::isfinite(values[2])); + + Source->Direction[0] = values[0]; + Source->Direction[1] = values[1]; + Source->Direction[2] = values[2]; + return UpdateSourceProps(Source, Context); + + case AL_ORIENTATION: + CHECKSIZE(values, 6); + CHECKVAL(std::isfinite(values[0]) && std::isfinite(values[1]) && std::isfinite(values[2]) + && std::isfinite(values[3]) && std::isfinite(values[4]) && std::isfinite(values[5])); + + Source->OrientAt[0] = values[0]; + Source->OrientAt[1] = values[1]; + Source->OrientAt[2] = values[2]; + Source->OrientUp[0] = values[3]; + Source->OrientUp[1] = values[4]; + Source->OrientUp[2] = values[5]; + return UpdateSourceProps(Source, Context); + + + case AL_SOURCE_RELATIVE: + case AL_LOOPING: + case AL_SOURCE_STATE: + case AL_SOURCE_TYPE: + case AL_DISTANCE_MODEL: + case AL_DIRECT_FILTER_GAINHF_AUTO: + case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: + case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: + case AL_DIRECT_CHANNELS_SOFT: + case AL_SOURCE_RESAMPLER_SOFT: + case AL_SOURCE_SPATIALIZE_SOFT: + CHECKSIZE(values, 1); + ival = static_cast(values[0]); + return SetSourceiv(Source, Context, prop, {&ival, 1u}); + + case AL_BUFFERS_QUEUED: + case AL_BUFFERS_PROCESSED: + CHECKSIZE(values, 1); + ival = static_cast(static_cast(values[0])); + return SetSourceiv(Source, Context, prop, {&ival, 1u}); + + case AL_BUFFER: + case AL_DIRECT_FILTER: + case AL_AUXILIARY_SEND_FILTER: + case AL_SAMPLE_OFFSET_LATENCY_SOFT: + case AL_SAMPLE_OFFSET_CLOCK_SOFT: + break; } ERR("Unexpected property: 0x%04x\n", prop); @@ -1116,304 +1114,308 @@ bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a switch(prop) { - case AL_SOURCE_STATE: - case AL_SOURCE_TYPE: - case AL_BUFFERS_QUEUED: - case AL_BUFFERS_PROCESSED: - /* Query only */ - SETERR_RETURN(Context, AL_INVALID_OPERATION, false, - "Setting read-only source property 0x%04x", prop); - - case AL_SOURCE_RELATIVE: - CHECKSIZE(values, 1); - CHECKVAL(values[0] == AL_FALSE || values[0] == AL_TRUE); - - Source->HeadRelative = static_cast(values[0]); - return UpdateSourceProps(Source, Context); - - case AL_LOOPING: - CHECKSIZE(values, 1); - CHECKVAL(values[0] == AL_FALSE || values[0] == AL_TRUE); - - Source->Looping = static_cast(values[0]); - if(IsPlayingOrPaused(Source)) + case AL_SOURCE_STATE: + case AL_SOURCE_TYPE: + case AL_BUFFERS_QUEUED: + case AL_BUFFERS_PROCESSED: + /* Query only */ + SETERR_RETURN(Context, AL_INVALID_OPERATION, false, + "Setting read-only source property 0x%04x", prop); + + case AL_SOURCE_RELATIVE: + CHECKSIZE(values, 1); + CHECKVAL(values[0] == AL_FALSE || values[0] == AL_TRUE); + + Source->HeadRelative = static_cast(values[0]); + return UpdateSourceProps(Source, Context); + + case AL_LOOPING: + CHECKSIZE(values, 1); + CHECKVAL(values[0] == AL_FALSE || values[0] == AL_TRUE); + + Source->Looping = static_cast(values[0]); + if(IsPlayingOrPaused(Source)) + { + if(ALvoice *voice{GetSourceVoice(Source, Context)}) { - if(ALvoice *voice{GetSourceVoice(Source, Context)}) - { - if(Source->Looping) - voice->mLoopBuffer.store(Source->queue, std::memory_order_release); - else - voice->mLoopBuffer.store(nullptr, std::memory_order_release); - - /* If the source is playing, wait for the current mix to finish - * to ensure it isn't currently looping back or reaching the - * end. - */ - while((device->MixCount.load(std::memory_order_acquire)&1)) - std::this_thread::yield(); - } + if(Source->Looping) + voice->mLoopBuffer.store(Source->queue, std::memory_order_release); + else + voice->mLoopBuffer.store(nullptr, std::memory_order_release); + + /* If the source is playing, wait for the current mix to finish + * to ensure it isn't currently looping back or reaching the + * end. + */ + while((device->MixCount.load(std::memory_order_acquire)&1)) + std::this_thread::yield(); } - return true; + } + return true; - case AL_BUFFER: - CHECKSIZE(values, 1); - buflock = std::unique_lock{device->BufferLock}; - if(!(values[0] == 0 || (buffer=LookupBuffer(device, values[0])) != nullptr)) - SETERR_RETURN(Context, AL_INVALID_VALUE, false, "Invalid buffer ID %u", values[0]); + case AL_BUFFER: + CHECKSIZE(values, 1); + buflock = std::unique_lock{device->BufferLock}; + if(values[0] && (buffer=LookupBuffer(device, static_cast(values[0]))) == nullptr) + SETERR_RETURN(Context, AL_INVALID_VALUE, false, "Invalid buffer ID %u", + static_cast(values[0])); - if(buffer && buffer->MappedAccess != 0 && - !(buffer->MappedAccess&AL_MAP_PERSISTENT_BIT_SOFT)) + if(buffer && buffer->MappedAccess != 0 && + !(buffer->MappedAccess&AL_MAP_PERSISTENT_BIT_SOFT)) + SETERR_RETURN(Context, AL_INVALID_OPERATION, false, + "Setting non-persistently mapped buffer %u", buffer->id); + else + { + ALenum state = GetSourceState(Source, GetSourceVoice(Source, Context)); + if(state == AL_PLAYING || state == AL_PAUSED) SETERR_RETURN(Context, AL_INVALID_OPERATION, false, - "Setting non-persistently mapped buffer %u", buffer->id); - else - { - ALenum state = GetSourceState(Source, GetSourceVoice(Source, Context)); - if(state == AL_PLAYING || state == AL_PAUSED) - SETERR_RETURN(Context, AL_INVALID_OPERATION, false, - "Setting buffer on playing or paused source %u", Source->id); - } + "Setting buffer on playing or paused source %u", Source->id); + } - oldlist = Source->queue; - if(buffer != nullptr) - { - /* Add the selected buffer to a one-item queue */ - auto newlist = new ALbufferlistitem{}; - newlist->mSampleLen = buffer->SampleLen; - newlist->mBuffer = buffer; - IncrementRef(buffer->ref); - - /* Source is now Static */ - Source->SourceType = AL_STATIC; - Source->queue = newlist; - } - else - { - /* Source is now Undetermined */ - Source->SourceType = AL_UNDETERMINED; - Source->queue = nullptr; - } - buflock.unlock(); + oldlist = Source->queue; + if(buffer != nullptr) + { + /* Add the selected buffer to a one-item queue */ + auto newlist = new ALbufferlistitem{}; + newlist->mSampleLen = buffer->SampleLen; + newlist->mBuffer = buffer; + IncrementRef(buffer->ref); + + /* Source is now Static */ + Source->SourceType = AL_STATIC; + Source->queue = newlist; + } + else + { + /* Source is now Undetermined */ + Source->SourceType = AL_UNDETERMINED; + Source->queue = nullptr; + } + buflock.unlock(); - /* Delete all elements in the previous queue */ - while(oldlist != nullptr) - { - std::unique_ptr temp{oldlist}; - oldlist = temp->mNext.load(std::memory_order_relaxed); + /* Delete all elements in the previous queue */ + while(oldlist != nullptr) + { + std::unique_ptr temp{oldlist}; + oldlist = temp->mNext.load(std::memory_order_relaxed); - if(ALbuffer *buffer{temp->mBuffer}) - DecrementRef(buffer->ref); - } - return true; + if(ALbuffer *buffer{temp->mBuffer}) + DecrementRef(buffer->ref); + } + return true; - case AL_SEC_OFFSET: - case AL_SAMPLE_OFFSET: - case AL_BYTE_OFFSET: - CHECKSIZE(values, 1); - CHECKVAL(values[0] >= 0); + case AL_SEC_OFFSET: + case AL_SAMPLE_OFFSET: + case AL_BYTE_OFFSET: + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0); - Source->OffsetType = prop; - Source->Offset = values[0]; + Source->OffsetType = prop; + Source->Offset = values[0]; - if(IsPlayingOrPaused(Source)) + if(IsPlayingOrPaused(Source)) + { + ALCdevice *device{Context->mDevice.get()}; + BackendLockGuard _{*device->Backend}; + if(ALvoice *voice{GetSourceVoice(Source, Context)}) { - ALCdevice *device{Context->mDevice.get()}; - BackendLockGuard _{*device->Backend}; - if(ALvoice *voice{GetSourceVoice(Source, Context)}) - { - auto vpos = GetSampleOffset(Source); - if(!vpos) SETERR_RETURN(Context, AL_INVALID_VALUE, false, "Invalid source offset"); - - voice->mPosition.store(vpos->pos, std::memory_order_relaxed); - voice->mPositionFrac.store(vpos->frac, std::memory_order_relaxed); - voice->mCurrentBuffer.store(vpos->bufferitem, std::memory_order_release); - } - } - return true; - - case AL_DIRECT_FILTER: - CHECKSIZE(values, 1); - filtlock = std::unique_lock{device->FilterLock}; - if(!(values[0] == 0 || (filter=LookupFilter(device, values[0])) != nullptr)) - SETERR_RETURN(Context, AL_INVALID_VALUE, false, "Invalid filter ID %u", values[0]); + auto vpos = GetSampleOffset(Source); + if(!vpos) SETERR_RETURN(Context, AL_INVALID_VALUE, false, "Invalid source offset"); - if(!filter) - { - Source->Direct.Gain = 1.0f; - Source->Direct.GainHF = 1.0f; - Source->Direct.HFReference = LOWPASSFREQREF; - Source->Direct.GainLF = 1.0f; - Source->Direct.LFReference = HIGHPASSFREQREF; + voice->mPosition.store(vpos->pos, std::memory_order_relaxed); + voice->mPositionFrac.store(vpos->frac, std::memory_order_relaxed); + voice->mCurrentBuffer.store(vpos->bufferitem, std::memory_order_release); } - else - { - Source->Direct.Gain = filter->Gain; - Source->Direct.GainHF = filter->GainHF; - Source->Direct.HFReference = filter->HFReference; - Source->Direct.GainLF = filter->GainLF; - Source->Direct.LFReference = filter->LFReference; - } - filtlock.unlock(); - return UpdateSourceProps(Source, Context); + } + return true; - case AL_DIRECT_FILTER_GAINHF_AUTO: - CHECKSIZE(values, 1); - CHECKVAL(values[0] == AL_FALSE || values[0] == AL_TRUE); + case AL_DIRECT_FILTER: + CHECKSIZE(values, 1); + filtlock = std::unique_lock{device->FilterLock}; + if(values[0] && (filter=LookupFilter(device, static_cast(values[0]))) == nullptr) + SETERR_RETURN(Context, AL_INVALID_VALUE, false, "Invalid filter ID %u", + static_cast(values[0])); - Source->DryGainHFAuto = values[0]; - return UpdateSourceProps(Source, Context); + if(!filter) + { + Source->Direct.Gain = 1.0f; + Source->Direct.GainHF = 1.0f; + Source->Direct.HFReference = LOWPASSFREQREF; + Source->Direct.GainLF = 1.0f; + Source->Direct.LFReference = HIGHPASSFREQREF; + } + else + { + Source->Direct.Gain = filter->Gain; + Source->Direct.GainHF = filter->GainHF; + Source->Direct.HFReference = filter->HFReference; + Source->Direct.GainLF = filter->GainLF; + Source->Direct.LFReference = filter->LFReference; + } + filtlock.unlock(); + return UpdateSourceProps(Source, Context); - case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: - CHECKSIZE(values, 1); - CHECKVAL(values[0] == AL_FALSE || values[0] == AL_TRUE); + case AL_DIRECT_FILTER_GAINHF_AUTO: + CHECKSIZE(values, 1); + CHECKVAL(values[0] == AL_FALSE || values[0] == AL_TRUE); - Source->WetGainAuto = values[0]; - return UpdateSourceProps(Source, Context); + Source->DryGainHFAuto = values[0]; + return UpdateSourceProps(Source, Context); - case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: - CHECKSIZE(values, 1); - CHECKVAL(values[0] == AL_FALSE || values[0] == AL_TRUE); + case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: + CHECKSIZE(values, 1); + CHECKVAL(values[0] == AL_FALSE || values[0] == AL_TRUE); - Source->WetGainHFAuto = values[0]; - return UpdateSourceProps(Source, Context); + Source->WetGainAuto = values[0]; + return UpdateSourceProps(Source, Context); - case AL_DIRECT_CHANNELS_SOFT: - CHECKSIZE(values, 1); - CHECKVAL(values[0] == AL_FALSE || values[0] == AL_TRUE); + case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: + CHECKSIZE(values, 1); + CHECKVAL(values[0] == AL_FALSE || values[0] == AL_TRUE); - Source->DirectChannels = values[0]; - return UpdateSourceProps(Source, Context); + Source->WetGainHFAuto = values[0]; + return UpdateSourceProps(Source, Context); - case AL_DISTANCE_MODEL: - CHECKSIZE(values, 1); - CHECKVAL(values[0] == AL_NONE || - values[0] == AL_INVERSE_DISTANCE || values[0] == AL_INVERSE_DISTANCE_CLAMPED || - values[0] == AL_LINEAR_DISTANCE || values[0] == AL_LINEAR_DISTANCE_CLAMPED || - values[0] == AL_EXPONENT_DISTANCE || values[0] == AL_EXPONENT_DISTANCE_CLAMPED); + case AL_DIRECT_CHANNELS_SOFT: + CHECKSIZE(values, 1); + CHECKVAL(values[0] == AL_FALSE || values[0] == AL_TRUE); - Source->mDistanceModel = static_cast(values[0]); - if(Context->mSourceDistanceModel) - return UpdateSourceProps(Source, Context); - return true; + Source->DirectChannels = values[0]; + return UpdateSourceProps(Source, Context); - case AL_SOURCE_RESAMPLER_SOFT: - CHECKSIZE(values, 1); - CHECKVAL(values[0] >= 0 && values[0] <= ResamplerMax); + case AL_DISTANCE_MODEL: + CHECKSIZE(values, 1); + CHECKVAL(values[0] == AL_NONE || + values[0] == AL_INVERSE_DISTANCE || values[0] == AL_INVERSE_DISTANCE_CLAMPED || + values[0] == AL_LINEAR_DISTANCE || values[0] == AL_LINEAR_DISTANCE_CLAMPED || + values[0] == AL_EXPONENT_DISTANCE || values[0] == AL_EXPONENT_DISTANCE_CLAMPED); - Source->mResampler = static_cast(values[0]); + Source->mDistanceModel = static_cast(values[0]); + if(Context->mSourceDistanceModel) return UpdateSourceProps(Source, Context); + return true; - case AL_SOURCE_SPATIALIZE_SOFT: - CHECKSIZE(values, 1); - CHECKVAL(values[0] >= AL_FALSE && values[0] <= AL_AUTO_SOFT); + case AL_SOURCE_RESAMPLER_SOFT: + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= 0 && values[0] <= ResamplerMax); - Source->mSpatialize = static_cast(values[0]); - return UpdateSourceProps(Source, Context); + Source->mResampler = static_cast(values[0]); + return UpdateSourceProps(Source, Context); + case AL_SOURCE_SPATIALIZE_SOFT: + CHECKSIZE(values, 1); + CHECKVAL(values[0] >= AL_FALSE && values[0] <= AL_AUTO_SOFT); - case AL_AUXILIARY_SEND_FILTER: - CHECKSIZE(values, 3); - slotlock = std::unique_lock{Context->mEffectSlotLock}; - if(!(values[0] == 0 || (slot=LookupEffectSlot(Context, values[0])) != nullptr)) - SETERR_RETURN(Context, AL_INVALID_VALUE, false, "Invalid effect ID %u", values[0]); - if(static_cast(values[1]) >= static_cast(device->NumAuxSends)) - SETERR_RETURN(Context, AL_INVALID_VALUE, false, "Invalid send %u", values[1]); + Source->mSpatialize = static_cast(values[0]); + return UpdateSourceProps(Source, Context); - filtlock = std::unique_lock{device->FilterLock}; - if(!(values[2] == 0 || (filter=LookupFilter(device, values[2])) != nullptr)) - SETERR_RETURN(Context, AL_INVALID_VALUE, false, "Invalid filter ID %u", values[2]); - if(!filter) - { - /* Disable filter */ - Source->Send[values[1]].Gain = 1.0f; - Source->Send[values[1]].GainHF = 1.0f; - Source->Send[values[1]].HFReference = LOWPASSFREQREF; - Source->Send[values[1]].GainLF = 1.0f; - Source->Send[values[1]].LFReference = HIGHPASSFREQREF; - } - else - { - Source->Send[values[1]].Gain = filter->Gain; - Source->Send[values[1]].GainHF = filter->GainHF; - Source->Send[values[1]].HFReference = filter->HFReference; - Source->Send[values[1]].GainLF = filter->GainLF; - Source->Send[values[1]].LFReference = filter->LFReference; - } - filtlock.unlock(); + case AL_AUXILIARY_SEND_FILTER: + CHECKSIZE(values, 3); + slotlock = std::unique_lock{Context->mEffectSlotLock}; + if(values[0] && (slot=LookupEffectSlot(Context, static_cast(values[0]))) == nullptr) + SETERR_RETURN(Context, AL_INVALID_VALUE, false, "Invalid effect ID %u", values[0]); + if(static_cast(values[1]) >= static_cast(device->NumAuxSends)) + SETERR_RETURN(Context, AL_INVALID_VALUE, false, "Invalid send %u", values[1]); - if(slot != Source->Send[values[1]].Slot && IsPlayingOrPaused(Source)) - { - /* Add refcount on the new slot, and release the previous slot */ - if(slot) IncrementRef(slot->ref); - if(Source->Send[values[1]].Slot) - DecrementRef(Source->Send[values[1]].Slot->ref); - Source->Send[values[1]].Slot = slot; - - /* We must force an update if the auxiliary slot changed on an - * active source, in case the slot is about to be deleted. - */ - ALvoice *voice{GetSourceVoice(Source, Context)}; - if(voice) UpdateSourceProps(Source, voice, Context); - else Source->PropsClean.clear(std::memory_order_release); - } - else - { - if(slot) IncrementRef(slot->ref); - if(Source->Send[values[1]].Slot) - DecrementRef(Source->Send[values[1]].Slot->ref); - Source->Send[values[1]].Slot = slot; - UpdateSourceProps(Source, Context); - } - return true; - - - /* 1x float */ - case AL_CONE_INNER_ANGLE: - case AL_CONE_OUTER_ANGLE: - case AL_PITCH: - case AL_GAIN: - case AL_MIN_GAIN: - case AL_MAX_GAIN: - case AL_REFERENCE_DISTANCE: - case AL_ROLLOFF_FACTOR: - case AL_CONE_OUTER_GAIN: - case AL_MAX_DISTANCE: - case AL_DOPPLER_FACTOR: - case AL_CONE_OUTER_GAINHF: - case AL_AIR_ABSORPTION_FACTOR: - case AL_ROOM_ROLLOFF_FACTOR: - case AL_SOURCE_RADIUS: - CHECKSIZE(values, 1); - fvals[0] = static_cast(values[0]); - return SetSourcefv(Source, Context, prop, {fvals, 1u}); - - /* 3x float */ - case AL_POSITION: - case AL_VELOCITY: - case AL_DIRECTION: - CHECKSIZE(values, 3); - fvals[0] = static_cast(values[0]); - fvals[1] = static_cast(values[1]); - fvals[2] = static_cast(values[2]); - return SetSourcefv(Source, Context, prop, {fvals, 3u}); - - /* 6x float */ - case AL_ORIENTATION: - CHECKSIZE(values, 6); - fvals[0] = static_cast(values[0]); - fvals[1] = static_cast(values[1]); - fvals[2] = static_cast(values[2]); - fvals[3] = static_cast(values[3]); - fvals[4] = static_cast(values[4]); - fvals[5] = static_cast(values[5]); - return SetSourcefv(Source, Context, prop, {fvals, 6u}); - - case AL_SAMPLE_OFFSET_LATENCY_SOFT: - case AL_SEC_OFFSET_LATENCY_SOFT: - case AL_SEC_OFFSET_CLOCK_SOFT: - case AL_SAMPLE_OFFSET_CLOCK_SOFT: - case AL_STEREO_ANGLES: - break; + filtlock = std::unique_lock{device->FilterLock}; + if(values[2] && (filter=LookupFilter(device, static_cast(values[2]))) == nullptr) + SETERR_RETURN(Context, AL_INVALID_VALUE, false, "Invalid filter ID %u", values[2]); + + if(!filter) + { + /* Disable filter */ + auto &send = Source->Send[static_cast(values[1])]; + send.Gain = 1.0f; + send.GainHF = 1.0f; + send.HFReference = LOWPASSFREQREF; + send.GainLF = 1.0f; + send.LFReference = HIGHPASSFREQREF; + } + else + { + auto &send = Source->Send[static_cast(values[1])]; + send.Gain = filter->Gain; + send.GainHF = filter->GainHF; + send.HFReference = filter->HFReference; + send.GainLF = filter->GainLF; + send.LFReference = filter->LFReference; + } + filtlock.unlock(); + + if(slot != Source->Send[static_cast(values[1])].Slot && IsPlayingOrPaused(Source)) + { + /* Add refcount on the new slot, and release the previous slot */ + if(slot) IncrementRef(slot->ref); + if(auto *slot = Source->Send[static_cast(values[1])].Slot) + DecrementRef(slot->ref); + Source->Send[static_cast(values[1])].Slot = slot; + + /* We must force an update if the auxiliary slot changed on an + * active source, in case the slot is about to be deleted. + */ + ALvoice *voice{GetSourceVoice(Source, Context)}; + if(voice) UpdateSourceProps(Source, voice, Context); + else Source->PropsClean.clear(std::memory_order_release); + } + else + { + if(slot) IncrementRef(slot->ref); + if(auto *slot = Source->Send[static_cast(values[1])].Slot) + DecrementRef(slot->ref); + Source->Send[static_cast(values[1])].Slot = slot; + UpdateSourceProps(Source, Context); + } + return true; + + + /* 1x float */ + case AL_CONE_INNER_ANGLE: + case AL_CONE_OUTER_ANGLE: + case AL_PITCH: + case AL_GAIN: + case AL_MIN_GAIN: + case AL_MAX_GAIN: + case AL_REFERENCE_DISTANCE: + case AL_ROLLOFF_FACTOR: + case AL_CONE_OUTER_GAIN: + case AL_MAX_DISTANCE: + case AL_DOPPLER_FACTOR: + case AL_CONE_OUTER_GAINHF: + case AL_AIR_ABSORPTION_FACTOR: + case AL_ROOM_ROLLOFF_FACTOR: + case AL_SOURCE_RADIUS: + CHECKSIZE(values, 1); + fvals[0] = static_cast(values[0]); + return SetSourcefv(Source, Context, prop, {fvals, 1u}); + + /* 3x float */ + case AL_POSITION: + case AL_VELOCITY: + case AL_DIRECTION: + CHECKSIZE(values, 3); + fvals[0] = static_cast(values[0]); + fvals[1] = static_cast(values[1]); + fvals[2] = static_cast(values[2]); + return SetSourcefv(Source, Context, prop, {fvals, 3u}); + + /* 6x float */ + case AL_ORIENTATION: + CHECKSIZE(values, 6); + fvals[0] = static_cast(values[0]); + fvals[1] = static_cast(values[1]); + fvals[2] = static_cast(values[2]); + fvals[3] = static_cast(values[3]); + fvals[4] = static_cast(values[4]); + fvals[5] = static_cast(values[5]); + return SetSourcefv(Source, Context, prop, {fvals, 6u}); + + case AL_SAMPLE_OFFSET_LATENCY_SOFT: + case AL_SEC_OFFSET_LATENCY_SOFT: + case AL_SEC_OFFSET_CLOCK_SOFT: + case AL_SAMPLE_OFFSET_CLOCK_SOFT: + case AL_STEREO_ANGLES: + break; } ERR("Unexpected property: 0x%04x\n", prop); @@ -1428,101 +1430,100 @@ bool SetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, const switch(prop) { - case AL_SOURCE_TYPE: - case AL_BUFFERS_QUEUED: - case AL_BUFFERS_PROCESSED: - case AL_SOURCE_STATE: - case AL_SAMPLE_OFFSET_LATENCY_SOFT: - case AL_SAMPLE_OFFSET_CLOCK_SOFT: - /* Query only */ - SETERR_RETURN(Context, AL_INVALID_OPERATION, false, - "Setting read-only source property 0x%04x", prop); - - /* 1x int */ - case AL_SOURCE_RELATIVE: - case AL_LOOPING: - case AL_SEC_OFFSET: - case AL_SAMPLE_OFFSET: - case AL_BYTE_OFFSET: - case AL_DIRECT_FILTER_GAINHF_AUTO: - case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: - case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: - case AL_DIRECT_CHANNELS_SOFT: - case AL_DISTANCE_MODEL: - case AL_SOURCE_RESAMPLER_SOFT: - case AL_SOURCE_SPATIALIZE_SOFT: - CHECKSIZE(values, 1); - CHECKVAL(values[0] <= INT_MAX && values[0] >= INT_MIN); - - ivals[0] = static_cast(values[0]); - return SetSourceiv(Source, Context, prop, {ivals, 1u}); - - /* 1x uint */ - case AL_BUFFER: - case AL_DIRECT_FILTER: - CHECKSIZE(values, 1); - CHECKVAL(values[0] <= UINT_MAX && values[0] >= 0); - - ivals[0] = static_cast(values[0]); - return SetSourceiv(Source, Context, prop, {ivals, 1u}); - - /* 3x uint */ - case AL_AUXILIARY_SEND_FILTER: - CHECKSIZE(values, 3); - CHECKVAL(values[0] <= UINT_MAX && values[0] >= 0 && - values[1] <= UINT_MAX && values[1] >= 0 && - values[2] <= UINT_MAX && values[2] >= 0); - - ivals[0] = static_cast(values[0]); - ivals[1] = static_cast(values[1]); - ivals[2] = static_cast(values[2]); - return SetSourceiv(Source, Context, prop, {ivals, 3u}); - - /* 1x float */ - case AL_CONE_INNER_ANGLE: - case AL_CONE_OUTER_ANGLE: - case AL_PITCH: - case AL_GAIN: - case AL_MIN_GAIN: - case AL_MAX_GAIN: - case AL_REFERENCE_DISTANCE: - case AL_ROLLOFF_FACTOR: - case AL_CONE_OUTER_GAIN: - case AL_MAX_DISTANCE: - case AL_DOPPLER_FACTOR: - case AL_CONE_OUTER_GAINHF: - case AL_AIR_ABSORPTION_FACTOR: - case AL_ROOM_ROLLOFF_FACTOR: - case AL_SOURCE_RADIUS: - CHECKSIZE(values, 1); - fvals[0] = static_cast(values[0]); - return SetSourcefv(Source, Context, prop, {fvals, 1u}); - - /* 3x float */ - case AL_POSITION: - case AL_VELOCITY: - case AL_DIRECTION: - CHECKSIZE(values, 3); - fvals[0] = static_cast(values[0]); - fvals[1] = static_cast(values[1]); - fvals[2] = static_cast(values[2]); - return SetSourcefv(Source, Context, prop, {fvals, 3u}); - - /* 6x float */ - case AL_ORIENTATION: - CHECKSIZE(values, 6); - fvals[0] = static_cast(values[0]); - fvals[1] = static_cast(values[1]); - fvals[2] = static_cast(values[2]); - fvals[3] = static_cast(values[3]); - fvals[4] = static_cast(values[4]); - fvals[5] = static_cast(values[5]); - return SetSourcefv(Source, Context, prop, {fvals, 6u}); - - case AL_SEC_OFFSET_LATENCY_SOFT: - case AL_SEC_OFFSET_CLOCK_SOFT: - case AL_STEREO_ANGLES: - break; + case AL_SOURCE_TYPE: + case AL_BUFFERS_QUEUED: + case AL_BUFFERS_PROCESSED: + case AL_SOURCE_STATE: + case AL_SAMPLE_OFFSET_LATENCY_SOFT: + case AL_SAMPLE_OFFSET_CLOCK_SOFT: + /* Query only */ + SETERR_RETURN(Context, AL_INVALID_OPERATION, false, + "Setting read-only source property 0x%04x", prop); + + /* 1x int */ + case AL_SOURCE_RELATIVE: + case AL_LOOPING: + case AL_SEC_OFFSET: + case AL_SAMPLE_OFFSET: + case AL_BYTE_OFFSET: + case AL_DIRECT_FILTER_GAINHF_AUTO: + case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: + case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: + case AL_DIRECT_CHANNELS_SOFT: + case AL_DISTANCE_MODEL: + case AL_SOURCE_RESAMPLER_SOFT: + case AL_SOURCE_SPATIALIZE_SOFT: + CHECKSIZE(values, 1); + CHECKVAL(values[0] <= INT_MAX && values[0] >= INT_MIN); + + ivals[0] = static_cast(values[0]); + return SetSourceiv(Source, Context, prop, {ivals, 1u}); + + /* 1x uint */ + case AL_BUFFER: + case AL_DIRECT_FILTER: + CHECKSIZE(values, 1); + CHECKVAL(values[0] <= UINT_MAX && values[0] >= 0); + + ivals[0] = static_cast(values[0]); + return SetSourceiv(Source, Context, prop, {ivals, 1u}); + + /* 3x uint */ + case AL_AUXILIARY_SEND_FILTER: + CHECKSIZE(values, 3); + CHECKVAL(values[0] <= UINT_MAX && values[0] >= 0 && values[1] <= UINT_MAX && values[1] >= 0 + && values[2] <= UINT_MAX && values[2] >= 0); + + ivals[0] = static_cast(values[0]); + ivals[1] = static_cast(values[1]); + ivals[2] = static_cast(values[2]); + return SetSourceiv(Source, Context, prop, {ivals, 3u}); + + /* 1x float */ + case AL_CONE_INNER_ANGLE: + case AL_CONE_OUTER_ANGLE: + case AL_PITCH: + case AL_GAIN: + case AL_MIN_GAIN: + case AL_MAX_GAIN: + case AL_REFERENCE_DISTANCE: + case AL_ROLLOFF_FACTOR: + case AL_CONE_OUTER_GAIN: + case AL_MAX_DISTANCE: + case AL_DOPPLER_FACTOR: + case AL_CONE_OUTER_GAINHF: + case AL_AIR_ABSORPTION_FACTOR: + case AL_ROOM_ROLLOFF_FACTOR: + case AL_SOURCE_RADIUS: + CHECKSIZE(values, 1); + fvals[0] = static_cast(values[0]); + return SetSourcefv(Source, Context, prop, {fvals, 1u}); + + /* 3x float */ + case AL_POSITION: + case AL_VELOCITY: + case AL_DIRECTION: + CHECKSIZE(values, 3); + fvals[0] = static_cast(values[0]); + fvals[1] = static_cast(values[1]); + fvals[2] = static_cast(values[2]); + return SetSourcefv(Source, Context, prop, {fvals, 3u}); + + /* 6x float */ + case AL_ORIENTATION: + CHECKSIZE(values, 6); + fvals[0] = static_cast(values[0]); + fvals[1] = static_cast(values[1]); + fvals[2] = static_cast(values[2]); + fvals[3] = static_cast(values[3]); + fvals[4] = static_cast(values[4]); + fvals[5] = static_cast(values[5]); + return SetSourcefv(Source, Context, prop, {fvals, 6u}); + + case AL_SEC_OFFSET_LATENCY_SOFT: + case AL_SEC_OFFSET_CLOCK_SOFT: + case AL_STEREO_ANGLES: + break; } ERR("Unexpected property: 0x%04x\n", prop); @@ -1541,185 +1542,185 @@ bool GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a { ALCdevice *device{Context->mDevice.get()}; ClockLatency clocktime; - std::chrono::nanoseconds srcclock; + nanoseconds srcclock; ALint ivals[MaxValues]; bool err; switch(prop) { - case AL_GAIN: - CHECKSIZE(values, 1); - values[0] = Source->Gain; - return true; - - case AL_PITCH: - CHECKSIZE(values, 1); - values[0] = Source->Pitch; - return true; - - case AL_MAX_DISTANCE: - CHECKSIZE(values, 1); - values[0] = Source->MaxDistance; - return true; - - case AL_ROLLOFF_FACTOR: - CHECKSIZE(values, 1); - values[0] = Source->RolloffFactor; - return true; - - case AL_REFERENCE_DISTANCE: - CHECKSIZE(values, 1); - values[0] = Source->RefDistance; - return true; - - case AL_CONE_INNER_ANGLE: - CHECKSIZE(values, 1); - values[0] = Source->InnerAngle; - return true; - - case AL_CONE_OUTER_ANGLE: - CHECKSIZE(values, 1); - values[0] = Source->OuterAngle; - return true; - - case AL_MIN_GAIN: - CHECKSIZE(values, 1); - values[0] = Source->MinGain; - return true; - - case AL_MAX_GAIN: - CHECKSIZE(values, 1); - values[0] = Source->MaxGain; - return true; - - case AL_CONE_OUTER_GAIN: - CHECKSIZE(values, 1); - values[0] = Source->OuterGain; - return true; - - case AL_SEC_OFFSET: - case AL_SAMPLE_OFFSET: - case AL_BYTE_OFFSET: - CHECKSIZE(values, 1); - values[0] = GetSourceOffset(Source, prop, Context); - return true; - - case AL_CONE_OUTER_GAINHF: - CHECKSIZE(values, 1); - values[0] = Source->OuterGainHF; - return true; - - case AL_AIR_ABSORPTION_FACTOR: - CHECKSIZE(values, 1); - values[0] = Source->AirAbsorptionFactor; - return true; - - case AL_ROOM_ROLLOFF_FACTOR: - CHECKSIZE(values, 1); - values[0] = Source->RoomRolloffFactor; - return true; - - case AL_DOPPLER_FACTOR: - CHECKSIZE(values, 1); - values[0] = Source->DopplerFactor; - return true; - - case AL_SOURCE_RADIUS: - CHECKSIZE(values, 1); - values[0] = Source->Radius; - return true; - - case AL_STEREO_ANGLES: - CHECKSIZE(values, 2); - values[0] = Source->StereoPan[0]; - values[1] = Source->StereoPan[1]; - return true; - - case AL_SEC_OFFSET_LATENCY_SOFT: - CHECKSIZE(values, 2); - /* Get the source offset with the clock time first. Then get the - * clock time with the device latency. Order is important. + case AL_GAIN: + CHECKSIZE(values, 1); + values[0] = Source->Gain; + return true; + + case AL_PITCH: + CHECKSIZE(values, 1); + values[0] = Source->Pitch; + return true; + + case AL_MAX_DISTANCE: + CHECKSIZE(values, 1); + values[0] = Source->MaxDistance; + return true; + + case AL_ROLLOFF_FACTOR: + CHECKSIZE(values, 1); + values[0] = Source->RolloffFactor; + return true; + + case AL_REFERENCE_DISTANCE: + CHECKSIZE(values, 1); + values[0] = Source->RefDistance; + return true; + + case AL_CONE_INNER_ANGLE: + CHECKSIZE(values, 1); + values[0] = Source->InnerAngle; + return true; + + case AL_CONE_OUTER_ANGLE: + CHECKSIZE(values, 1); + values[0] = Source->OuterAngle; + return true; + + case AL_MIN_GAIN: + CHECKSIZE(values, 1); + values[0] = Source->MinGain; + return true; + + case AL_MAX_GAIN: + CHECKSIZE(values, 1); + values[0] = Source->MaxGain; + return true; + + case AL_CONE_OUTER_GAIN: + CHECKSIZE(values, 1); + values[0] = Source->OuterGain; + return true; + + case AL_SEC_OFFSET: + case AL_SAMPLE_OFFSET: + case AL_BYTE_OFFSET: + CHECKSIZE(values, 1); + values[0] = GetSourceOffset(Source, prop, Context); + return true; + + case AL_CONE_OUTER_GAINHF: + CHECKSIZE(values, 1); + values[0] = Source->OuterGainHF; + return true; + + case AL_AIR_ABSORPTION_FACTOR: + CHECKSIZE(values, 1); + values[0] = Source->AirAbsorptionFactor; + return true; + + case AL_ROOM_ROLLOFF_FACTOR: + CHECKSIZE(values, 1); + values[0] = Source->RoomRolloffFactor; + return true; + + case AL_DOPPLER_FACTOR: + CHECKSIZE(values, 1); + values[0] = Source->DopplerFactor; + return true; + + case AL_SOURCE_RADIUS: + CHECKSIZE(values, 1); + values[0] = Source->Radius; + return true; + + case AL_STEREO_ANGLES: + CHECKSIZE(values, 2); + values[0] = Source->StereoPan[0]; + values[1] = Source->StereoPan[1]; + return true; + + case AL_SEC_OFFSET_LATENCY_SOFT: + CHECKSIZE(values, 2); + /* Get the source offset with the clock time first. Then get the clock + * time with the device latency. Order is important. + */ + values[0] = GetSourceSecOffset(Source, Context, &srcclock); + { + std::lock_guard _{device->StateLock}; + clocktime = GetClockLatency(device); + } + if(srcclock == clocktime.ClockTime) + values[1] = static_cast(clocktime.Latency.count()) / 1000000000.0; + else + { + /* If the clock time incremented, reduce the latency by that much + * since it's that much closer to the source offset it got earlier. */ - values[0] = GetSourceSecOffset(Source, Context, &srcclock); - { std::lock_guard _{device->StateLock}; - clocktime = GetClockLatency(device); - } - if(srcclock == clocktime.ClockTime) - values[1] = static_cast(clocktime.Latency.count()) / 1000000000.0; - else - { - /* If the clock time incremented, reduce the latency by that - * much since it's that much closer to the source offset it got - * earlier. - */ - std::chrono::nanoseconds diff = clocktime.ClockTime - srcclock; - values[1] = static_cast((clocktime.Latency - std::min(clocktime.Latency, diff)).count()) / - 1000000000.0; - } - return true; - - case AL_SEC_OFFSET_CLOCK_SOFT: - CHECKSIZE(values, 2); - values[0] = GetSourceSecOffset(Source, Context, &srcclock); - values[1] = srcclock.count() / 1000000000.0; - return true; - - case AL_POSITION: - CHECKSIZE(values, 3); - values[0] = Source->Position[0]; - values[1] = Source->Position[1]; - values[2] = Source->Position[2]; - return true; - - case AL_VELOCITY: - CHECKSIZE(values, 3); - values[0] = Source->Velocity[0]; - values[1] = Source->Velocity[1]; - values[2] = Source->Velocity[2]; - return true; - - case AL_DIRECTION: - CHECKSIZE(values, 3); - values[0] = Source->Direction[0]; - values[1] = Source->Direction[1]; - values[2] = Source->Direction[2]; - return true; - - case AL_ORIENTATION: - CHECKSIZE(values, 6); - values[0] = Source->OrientAt[0]; - values[1] = Source->OrientAt[1]; - values[2] = Source->OrientAt[2]; - values[3] = Source->OrientUp[0]; - values[4] = Source->OrientUp[1]; - values[5] = Source->OrientUp[2]; - return true; - - /* 1x int */ - case AL_SOURCE_RELATIVE: - case AL_LOOPING: - case AL_SOURCE_STATE: - case AL_BUFFERS_QUEUED: - case AL_BUFFERS_PROCESSED: - case AL_SOURCE_TYPE: - case AL_DIRECT_FILTER_GAINHF_AUTO: - case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: - case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: - case AL_DIRECT_CHANNELS_SOFT: - case AL_DISTANCE_MODEL: - case AL_SOURCE_RESAMPLER_SOFT: - case AL_SOURCE_SPATIALIZE_SOFT: - CHECKSIZE(values, 1); - if((err=GetSourceiv(Source, Context, prop, {ivals, 1u})) != false) - values[0] = static_cast(ivals[0]); - return err; - - case AL_BUFFER: - case AL_DIRECT_FILTER: - case AL_AUXILIARY_SEND_FILTER: - case AL_SAMPLE_OFFSET_LATENCY_SOFT: - case AL_SAMPLE_OFFSET_CLOCK_SOFT: - break; + const nanoseconds diff{clocktime.ClockTime - srcclock}; + const nanoseconds latency{clocktime.Latency - std::min(clocktime.Latency, diff)}; + values[1] = static_cast(latency.count()) / 1000000000.0; + } + return true; + + case AL_SEC_OFFSET_CLOCK_SOFT: + CHECKSIZE(values, 2); + values[0] = GetSourceSecOffset(Source, Context, &srcclock); + values[1] = srcclock.count() / 1000000000.0; + return true; + + case AL_POSITION: + CHECKSIZE(values, 3); + values[0] = Source->Position[0]; + values[1] = Source->Position[1]; + values[2] = Source->Position[2]; + return true; + + case AL_VELOCITY: + CHECKSIZE(values, 3); + values[0] = Source->Velocity[0]; + values[1] = Source->Velocity[1]; + values[2] = Source->Velocity[2]; + return true; + + case AL_DIRECTION: + CHECKSIZE(values, 3); + values[0] = Source->Direction[0]; + values[1] = Source->Direction[1]; + values[2] = Source->Direction[2]; + return true; + + case AL_ORIENTATION: + CHECKSIZE(values, 6); + values[0] = Source->OrientAt[0]; + values[1] = Source->OrientAt[1]; + values[2] = Source->OrientAt[2]; + values[3] = Source->OrientUp[0]; + values[4] = Source->OrientUp[1]; + values[5] = Source->OrientUp[2]; + return true; + + /* 1x int */ + case AL_SOURCE_RELATIVE: + case AL_LOOPING: + case AL_SOURCE_STATE: + case AL_BUFFERS_QUEUED: + case AL_BUFFERS_PROCESSED: + case AL_SOURCE_TYPE: + case AL_DIRECT_FILTER_GAINHF_AUTO: + case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: + case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: + case AL_DIRECT_CHANNELS_SOFT: + case AL_DISTANCE_MODEL: + case AL_SOURCE_RESAMPLER_SOFT: + case AL_SOURCE_SPATIALIZE_SOFT: + CHECKSIZE(values, 1); + if((err=GetSourceiv(Source, Context, prop, {ivals, 1u})) != false) + values[0] = static_cast(ivals[0]); + return err; + + case AL_BUFFER: + case AL_DIRECT_FILTER: + case AL_AUXILIARY_SEND_FILTER: + case AL_SAMPLE_OFFSET_LATENCY_SOFT: + case AL_SAMPLE_OFFSET_CLOCK_SOFT: + break; } ERR("Unexpected property: 0x%04x\n", prop); @@ -1735,174 +1736,176 @@ bool GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a switch(prop) { - case AL_SOURCE_RELATIVE: - CHECKSIZE(values, 1); - values[0] = Source->HeadRelative; - return true; - - case AL_LOOPING: - CHECKSIZE(values, 1); - values[0] = Source->Looping; - return true; - - case AL_BUFFER: - CHECKSIZE(values, 1); - BufferList = (Source->SourceType == AL_STATIC) ? Source->queue : nullptr; - values[0] = (BufferList && BufferList->mBuffer) ? BufferList->mBuffer->id : 0; - return true; - - case AL_SOURCE_STATE: - CHECKSIZE(values, 1); - values[0] = GetSourceState(Source, GetSourceVoice(Source, Context)); - return true; - - case AL_BUFFERS_QUEUED: - CHECKSIZE(values, 1); - if(!(BufferList=Source->queue)) - values[0] = 0; - else - { - ALsizei count{0}; - do { - ++count; - BufferList = BufferList->mNext.load(std::memory_order_relaxed); - } while(BufferList != nullptr); - values[0] = count; - } - return true; + case AL_SOURCE_RELATIVE: + CHECKSIZE(values, 1); + values[0] = Source->HeadRelative; + return true; + + case AL_LOOPING: + CHECKSIZE(values, 1); + values[0] = Source->Looping; + return true; + + case AL_BUFFER: + CHECKSIZE(values, 1); + BufferList = (Source->SourceType == AL_STATIC) ? Source->queue : nullptr; + values[0] = (BufferList && BufferList->mBuffer) ? + static_cast(BufferList->mBuffer->id) : 0; + return true; + + case AL_SOURCE_STATE: + CHECKSIZE(values, 1); + values[0] = GetSourceState(Source, GetSourceVoice(Source, Context)); + return true; + + case AL_BUFFERS_QUEUED: + CHECKSIZE(values, 1); + if(!(BufferList=Source->queue)) + values[0] = 0; + else + { + ALsizei count{0}; + do { + ++count; + BufferList = BufferList->mNext.load(std::memory_order_relaxed); + } while(BufferList != nullptr); + values[0] = count; + } + return true; - case AL_BUFFERS_PROCESSED: - CHECKSIZE(values, 1); - if(Source->Looping || Source->SourceType != AL_STREAMING) - { - /* Buffers on a looping source are in a perpetual state of - * PENDING, so don't report any as PROCESSED */ - values[0] = 0; - } - else - { - const ALbufferlistitem *BufferList{Source->queue}; - const ALbufferlistitem *Current{nullptr}; - ALsizei played{0}; - - ALvoice *voice{GetSourceVoice(Source, Context)}; - if(voice != nullptr) - Current = voice->mCurrentBuffer.load(std::memory_order_relaxed); - else if(Source->state == AL_INITIAL) - Current = BufferList; - - while(BufferList && BufferList != Current) - { - ++played; - BufferList = BufferList->mNext.load(std::memory_order_relaxed); - } - values[0] = played; - } - return true; - - case AL_SOURCE_TYPE: - CHECKSIZE(values, 1); - values[0] = Source->SourceType; - return true; - - case AL_DIRECT_FILTER_GAINHF_AUTO: - CHECKSIZE(values, 1); - values[0] = Source->DryGainHFAuto; - return true; - - case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: - CHECKSIZE(values, 1); - values[0] = Source->WetGainAuto; - return true; - - case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: - CHECKSIZE(values, 1); - values[0] = Source->WetGainHFAuto; - return true; - - case AL_DIRECT_CHANNELS_SOFT: - CHECKSIZE(values, 1); - values[0] = Source->DirectChannels; - return true; - - case AL_DISTANCE_MODEL: - CHECKSIZE(values, 1); - values[0] = static_cast(Source->mDistanceModel); - return true; - - case AL_SOURCE_RESAMPLER_SOFT: - CHECKSIZE(values, 1); - values[0] = Source->mResampler; - return true; - - case AL_SOURCE_SPATIALIZE_SOFT: - CHECKSIZE(values, 1); - values[0] = Source->mSpatialize; - return true; - - /* 1x float/double */ - case AL_CONE_INNER_ANGLE: - case AL_CONE_OUTER_ANGLE: - case AL_PITCH: - case AL_GAIN: - case AL_MIN_GAIN: - case AL_MAX_GAIN: - case AL_REFERENCE_DISTANCE: - case AL_ROLLOFF_FACTOR: - case AL_CONE_OUTER_GAIN: - case AL_MAX_DISTANCE: - case AL_SEC_OFFSET: - case AL_SAMPLE_OFFSET: - case AL_BYTE_OFFSET: - case AL_DOPPLER_FACTOR: - case AL_AIR_ABSORPTION_FACTOR: - case AL_ROOM_ROLLOFF_FACTOR: - case AL_CONE_OUTER_GAINHF: - case AL_SOURCE_RADIUS: - CHECKSIZE(values, 1); - if((err=GetSourcedv(Source, Context, prop, {dvals, 1u})) != false) - values[0] = static_cast(dvals[0]); - return err; - - /* 3x float/double */ - case AL_POSITION: - case AL_VELOCITY: - case AL_DIRECTION: - CHECKSIZE(values, 3); - if((err=GetSourcedv(Source, Context, prop, {dvals, 3u})) != false) - { - values[0] = static_cast(dvals[0]); - values[1] = static_cast(dvals[1]); - values[2] = static_cast(dvals[2]); - } - return err; + case AL_BUFFERS_PROCESSED: + CHECKSIZE(values, 1); + if(Source->Looping || Source->SourceType != AL_STREAMING) + { + /* Buffers on a looping source are in a perpetual state of PENDING, + * so don't report any as PROCESSED + */ + values[0] = 0; + } + else + { + const ALbufferlistitem *BufferList{Source->queue}; + const ALbufferlistitem *Current{nullptr}; + ALsizei played{0}; + + ALvoice *voice{GetSourceVoice(Source, Context)}; + if(voice != nullptr) + Current = voice->mCurrentBuffer.load(std::memory_order_relaxed); + else if(Source->state == AL_INITIAL) + Current = BufferList; - /* 6x float/double */ - case AL_ORIENTATION: - CHECKSIZE(values, 6); - if((err=GetSourcedv(Source, Context, prop, {dvals, 6u})) != false) + while(BufferList && BufferList != Current) { - values[0] = static_cast(dvals[0]); - values[1] = static_cast(dvals[1]); - values[2] = static_cast(dvals[2]); - values[3] = static_cast(dvals[3]); - values[4] = static_cast(dvals[4]); - values[5] = static_cast(dvals[5]); + ++played; + BufferList = BufferList->mNext.load(std::memory_order_relaxed); } - return err; - - case AL_SAMPLE_OFFSET_LATENCY_SOFT: - case AL_SAMPLE_OFFSET_CLOCK_SOFT: - break; /* i64 only */ - case AL_SEC_OFFSET_LATENCY_SOFT: - case AL_SEC_OFFSET_CLOCK_SOFT: - break; /* Double only */ - case AL_STEREO_ANGLES: - break; /* Float/double only */ - - case AL_DIRECT_FILTER: - case AL_AUXILIARY_SEND_FILTER: - break; /* ??? */ + values[0] = played; + } + return true; + + case AL_SOURCE_TYPE: + CHECKSIZE(values, 1); + values[0] = Source->SourceType; + return true; + + case AL_DIRECT_FILTER_GAINHF_AUTO: + CHECKSIZE(values, 1); + values[0] = Source->DryGainHFAuto; + return true; + + case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: + CHECKSIZE(values, 1); + values[0] = Source->WetGainAuto; + return true; + + case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: + CHECKSIZE(values, 1); + values[0] = Source->WetGainHFAuto; + return true; + + case AL_DIRECT_CHANNELS_SOFT: + CHECKSIZE(values, 1); + values[0] = Source->DirectChannels; + return true; + + case AL_DISTANCE_MODEL: + CHECKSIZE(values, 1); + values[0] = static_cast(Source->mDistanceModel); + return true; + + case AL_SOURCE_RESAMPLER_SOFT: + CHECKSIZE(values, 1); + values[0] = Source->mResampler; + return true; + + case AL_SOURCE_SPATIALIZE_SOFT: + CHECKSIZE(values, 1); + values[0] = Source->mSpatialize; + return true; + + /* 1x float/double */ + case AL_CONE_INNER_ANGLE: + case AL_CONE_OUTER_ANGLE: + case AL_PITCH: + case AL_GAIN: + case AL_MIN_GAIN: + case AL_MAX_GAIN: + case AL_REFERENCE_DISTANCE: + case AL_ROLLOFF_FACTOR: + case AL_CONE_OUTER_GAIN: + case AL_MAX_DISTANCE: + case AL_SEC_OFFSET: + case AL_SAMPLE_OFFSET: + case AL_BYTE_OFFSET: + case AL_DOPPLER_FACTOR: + case AL_AIR_ABSORPTION_FACTOR: + case AL_ROOM_ROLLOFF_FACTOR: + case AL_CONE_OUTER_GAINHF: + case AL_SOURCE_RADIUS: + CHECKSIZE(values, 1); + if((err=GetSourcedv(Source, Context, prop, {dvals, 1u})) != false) + values[0] = static_cast(dvals[0]); + return err; + + /* 3x float/double */ + case AL_POSITION: + case AL_VELOCITY: + case AL_DIRECTION: + CHECKSIZE(values, 3); + if((err=GetSourcedv(Source, Context, prop, {dvals, 3u})) != false) + { + values[0] = static_cast(dvals[0]); + values[1] = static_cast(dvals[1]); + values[2] = static_cast(dvals[2]); + } + return err; + + /* 6x float/double */ + case AL_ORIENTATION: + CHECKSIZE(values, 6); + if((err=GetSourcedv(Source, Context, prop, {dvals, 6u})) != false) + { + values[0] = static_cast(dvals[0]); + values[1] = static_cast(dvals[1]); + values[2] = static_cast(dvals[2]); + values[3] = static_cast(dvals[3]); + values[4] = static_cast(dvals[4]); + values[5] = static_cast(dvals[5]); + } + return err; + + case AL_SAMPLE_OFFSET_LATENCY_SOFT: + case AL_SAMPLE_OFFSET_CLOCK_SOFT: + break; /* i64 only */ + case AL_SEC_OFFSET_LATENCY_SOFT: + case AL_SEC_OFFSET_CLOCK_SOFT: + break; /* Double only */ + case AL_STEREO_ANGLES: + break; /* Float/double only */ + + case AL_DIRECT_FILTER: + case AL_AUXILIARY_SEND_FILTER: + break; /* ??? */ } ERR("Unexpected property: 0x%04x\n", prop); @@ -1914,135 +1917,135 @@ bool GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, const { ALCdevice *device = Context->mDevice.get(); ClockLatency clocktime; - std::chrono::nanoseconds srcclock; + nanoseconds srcclock; ALdouble dvals[MaxValues]; ALint ivals[MaxValues]; bool err; switch(prop) { - case AL_SAMPLE_OFFSET_LATENCY_SOFT: - CHECKSIZE(values, 2); - /* Get the source offset with the clock time first. Then get the - * clock time with the device latency. Order is important. + case AL_SAMPLE_OFFSET_LATENCY_SOFT: + CHECKSIZE(values, 2); + /* Get the source offset with the clock time first. Then get the clock + * time with the device latency. Order is important. + */ + values[0] = GetSourceSampleOffset(Source, Context, &srcclock); + { + std::lock_guard _{device->StateLock}; + clocktime = GetClockLatency(device); + } + if(srcclock == clocktime.ClockTime) + values[1] = clocktime.Latency.count(); + else + { + /* If the clock time incremented, reduce the latency by that much + * since it's that much closer to the source offset it got earlier. */ - values[0] = GetSourceSampleOffset(Source, Context, &srcclock); - { std::lock_guard _{device->StateLock}; - clocktime = GetClockLatency(device); - } - if(srcclock == clocktime.ClockTime) - values[1] = clocktime.Latency.count(); - else - { - /* If the clock time incremented, reduce the latency by that - * much since it's that much closer to the source offset it got - * earlier. - */ - auto diff = clocktime.ClockTime - srcclock; - values[1] = (clocktime.Latency - std::min(clocktime.Latency, diff)).count(); - } - return true; - - case AL_SAMPLE_OFFSET_CLOCK_SOFT: - CHECKSIZE(values, 2); - values[0] = GetSourceSampleOffset(Source, Context, &srcclock); - values[1] = srcclock.count(); - return true; - - /* 1x float/double */ - case AL_CONE_INNER_ANGLE: - case AL_CONE_OUTER_ANGLE: - case AL_PITCH: - case AL_GAIN: - case AL_MIN_GAIN: - case AL_MAX_GAIN: - case AL_REFERENCE_DISTANCE: - case AL_ROLLOFF_FACTOR: - case AL_CONE_OUTER_GAIN: - case AL_MAX_DISTANCE: - case AL_SEC_OFFSET: - case AL_SAMPLE_OFFSET: - case AL_BYTE_OFFSET: - case AL_DOPPLER_FACTOR: - case AL_AIR_ABSORPTION_FACTOR: - case AL_ROOM_ROLLOFF_FACTOR: - case AL_CONE_OUTER_GAINHF: - case AL_SOURCE_RADIUS: - CHECKSIZE(values, 1); - if((err=GetSourcedv(Source, Context, prop, {dvals, 1u})) != false) - values[0] = static_cast(dvals[0]); - return err; - - /* 3x float/double */ - case AL_POSITION: - case AL_VELOCITY: - case AL_DIRECTION: - CHECKSIZE(values, 3); - if((err=GetSourcedv(Source, Context, prop, {dvals, 3u})) != false) - { - values[0] = static_cast(dvals[0]); - values[1] = static_cast(dvals[1]); - values[2] = static_cast(dvals[2]); - } - return err; + const nanoseconds diff{clocktime.ClockTime - srcclock}; + values[1] = nanoseconds{clocktime.Latency - std::min(clocktime.Latency, diff)}.count(); + } + return true; + + case AL_SAMPLE_OFFSET_CLOCK_SOFT: + CHECKSIZE(values, 2); + values[0] = GetSourceSampleOffset(Source, Context, &srcclock); + values[1] = srcclock.count(); + return true; + + /* 1x float/double */ + case AL_CONE_INNER_ANGLE: + case AL_CONE_OUTER_ANGLE: + case AL_PITCH: + case AL_GAIN: + case AL_MIN_GAIN: + case AL_MAX_GAIN: + case AL_REFERENCE_DISTANCE: + case AL_ROLLOFF_FACTOR: + case AL_CONE_OUTER_GAIN: + case AL_MAX_DISTANCE: + case AL_SEC_OFFSET: + case AL_SAMPLE_OFFSET: + case AL_BYTE_OFFSET: + case AL_DOPPLER_FACTOR: + case AL_AIR_ABSORPTION_FACTOR: + case AL_ROOM_ROLLOFF_FACTOR: + case AL_CONE_OUTER_GAINHF: + case AL_SOURCE_RADIUS: + CHECKSIZE(values, 1); + if((err=GetSourcedv(Source, Context, prop, {dvals, 1u})) != false) + values[0] = static_cast(dvals[0]); + return err; + + /* 3x float/double */ + case AL_POSITION: + case AL_VELOCITY: + case AL_DIRECTION: + CHECKSIZE(values, 3); + if((err=GetSourcedv(Source, Context, prop, {dvals, 3u})) != false) + { + values[0] = static_cast(dvals[0]); + values[1] = static_cast(dvals[1]); + values[2] = static_cast(dvals[2]); + } + return err; - /* 6x float/double */ - case AL_ORIENTATION: - CHECKSIZE(values, 6); - if((err=GetSourcedv(Source, Context, prop, {dvals, 6u})) != false) - { - values[0] = static_cast(dvals[0]); - values[1] = static_cast(dvals[1]); - values[2] = static_cast(dvals[2]); - values[3] = static_cast(dvals[3]); - values[4] = static_cast(dvals[4]); - values[5] = static_cast(dvals[5]); - } - return err; - - /* 1x int */ - case AL_SOURCE_RELATIVE: - case AL_LOOPING: - case AL_SOURCE_STATE: - case AL_BUFFERS_QUEUED: - case AL_BUFFERS_PROCESSED: - case AL_SOURCE_TYPE: - case AL_DIRECT_FILTER_GAINHF_AUTO: - case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: - case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: - case AL_DIRECT_CHANNELS_SOFT: - case AL_DISTANCE_MODEL: - case AL_SOURCE_RESAMPLER_SOFT: - case AL_SOURCE_SPATIALIZE_SOFT: - CHECKSIZE(values, 1); - if((err=GetSourceiv(Source, Context, prop, {ivals, 1u})) != false) - values[0] = ivals[0]; - return err; - - /* 1x uint */ - case AL_BUFFER: - case AL_DIRECT_FILTER: - CHECKSIZE(values, 1); - if((err=GetSourceiv(Source, Context, prop, {ivals, 1u})) != false) - values[0] = static_cast(ivals[0]); - return err; - - /* 3x uint */ - case AL_AUXILIARY_SEND_FILTER: - CHECKSIZE(values, 3); - if((err=GetSourceiv(Source, Context, prop, {ivals, 3u})) != false) - { - values[0] = static_cast(ivals[0]); - values[1] = static_cast(ivals[1]); - values[2] = static_cast(ivals[2]); - } - return err; + /* 6x float/double */ + case AL_ORIENTATION: + CHECKSIZE(values, 6); + if((err=GetSourcedv(Source, Context, prop, {dvals, 6u})) != false) + { + values[0] = static_cast(dvals[0]); + values[1] = static_cast(dvals[1]); + values[2] = static_cast(dvals[2]); + values[3] = static_cast(dvals[3]); + values[4] = static_cast(dvals[4]); + values[5] = static_cast(dvals[5]); + } + return err; + + /* 1x int */ + case AL_SOURCE_RELATIVE: + case AL_LOOPING: + case AL_SOURCE_STATE: + case AL_BUFFERS_QUEUED: + case AL_BUFFERS_PROCESSED: + case AL_SOURCE_TYPE: + case AL_DIRECT_FILTER_GAINHF_AUTO: + case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: + case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: + case AL_DIRECT_CHANNELS_SOFT: + case AL_DISTANCE_MODEL: + case AL_SOURCE_RESAMPLER_SOFT: + case AL_SOURCE_SPATIALIZE_SOFT: + CHECKSIZE(values, 1); + if((err=GetSourceiv(Source, Context, prop, {ivals, 1u})) != false) + values[0] = ivals[0]; + return err; + + /* 1x uint */ + case AL_BUFFER: + case AL_DIRECT_FILTER: + CHECKSIZE(values, 1); + if((err=GetSourceiv(Source, Context, prop, {ivals, 1u})) != false) + values[0] = static_cast(ivals[0]); + return err; + + /* 3x uint */ + case AL_AUXILIARY_SEND_FILTER: + CHECKSIZE(values, 3); + if((err=GetSourceiv(Source, Context, prop, {ivals, 3u})) != false) + { + values[0] = static_cast(ivals[0]); + values[1] = static_cast(ivals[1]); + values[2] = static_cast(ivals[2]); + } + return err; - case AL_SEC_OFFSET_LATENCY_SOFT: - case AL_SEC_OFFSET_CLOCK_SOFT: - break; /* Double only */ - case AL_STEREO_ANGLES: - break; /* Float/double only */ + case AL_SEC_OFFSET_LATENCY_SOFT: + case AL_SEC_OFFSET_CLOCK_SOFT: + break; /* Double only */ + case AL_STEREO_ANGLES: + break; /* Float/double only */ } ERR("Unexpected property: 0x%04x\n", prop); @@ -2060,28 +2063,36 @@ START_API_FUNC if UNLIKELY(n < 0) context->setError(AL_INVALID_VALUE, "Generating %d sources", n); - else if(n == 1) + if UNLIKELY(n <= 0) return; + + std::unique_lock srclock{context->mSourceLock}; + ALCdevice *device{context->mDevice.get()}; + if(static_cast(n) >= device->SourcesMax-context->mNumSources) + { + context->setError(AL_OUT_OF_MEMORY, "Exceeding %u source limit", device->SourcesMax); + return; + } + if(!EnsureSources(context.get(), static_cast(n))) { - ALsource *source = AllocSource(context.get()); - if(source) sources[0] = source->id; + context->setError(AL_OUT_OF_MEMORY, "Failed to allocate %d source%s", n, (n==1)?"":"s"); + return; + } + + if(n == 1) + { + ALsource *source{AllocSource(context.get(), device->NumAuxSends)}; + sources[0] = source->id; } else { - al::vector tempids(n); - auto alloc_end = std::find_if_not(tempids.begin(), tempids.end(), - [&context](ALuint &id) -> bool - { - ALsource *source{AllocSource(context.get())}; - if(!source) return false; - id = source->id; - return true; - } - ); - if(alloc_end != tempids.end()) - alDeleteSources(static_cast(std::distance(tempids.begin(), alloc_end)), - tempids.data()); - else - std::copy(tempids.cbegin(), tempids.cend(), sources); + const ALsizei num_sends{device->NumAuxSends}; + al::vector ids; + ids.reserve(static_cast(n)); + do { + ALsource *source{AllocSource(context.get(), num_sends)}; + ids.emplace_back(source->id); + } while(--n); + std::copy(ids.cbegin(), ids.cend(), sources); } } END_API_FUNC @@ -2098,29 +2109,24 @@ START_API_FUNC std::lock_guard _{context->mSourceLock}; /* Check that all Sources are valid */ + auto validate_source = [&context](ALuint sid) -> bool + { return LookupSource(context.get(), sid) != nullptr; }; + const ALuint *sources_end = sources + n; - auto invsrc = std::find_if_not(sources, sources_end, - [&context](ALuint sid) -> bool - { - if(!LookupSource(context.get(), sid)) - { - context->setError(AL_INVALID_NAME, "Invalid source ID %u", sid); - return false; - } - return true; - } - ); - if LIKELY(invsrc == sources_end) + auto invsrc = std::find_if_not(sources, sources_end, validate_source); + if UNLIKELY(invsrc != sources_end) { - /* All good. Delete source IDs. */ - std::for_each(sources, sources_end, - [&context](ALuint sid) -> void - { - ALsource *src{LookupSource(context.get(), sid)}; - if(src) FreeSource(context.get(), src); - } - ); + context->setError(AL_INVALID_NAME, "Invalid source ID %u", *invsrc); + return; } + + /* All good. Delete source IDs. */ + auto delete_source = [&context](ALuint sid) -> void + { + ALsource *src{LookupSource(context.get(), sid)}; + if(src) FreeSource(context.get(), src); + }; + std::for_each(sources, sources_end, delete_source); } END_API_FUNC @@ -2637,7 +2643,7 @@ START_API_FUNC ALsource **srchandles{source_storage.data()}; if UNLIKELY(static_cast(n) > source_storage.size()) { - extra_sources.resize(n); + extra_sources.resize(static_cast(n)); srchandles = extra_sources.data(); } @@ -2667,16 +2673,16 @@ START_API_FUNC } /* Count the number of reusable voices. */ - auto count_free_voices = [](const ALsizei count, const ALvoice &voice) noexcept -> ALsizei + auto count_free_voices = [](const ALuint count, const ALvoice &voice) noexcept -> ALuint { - if(voice.mPlayState.load(std::memory_order_acquire) == ALvoice::Stopped && - voice.mSourceID.load(std::memory_order_relaxed) == 0u) + if(voice.mPlayState.load(std::memory_order_acquire) == ALvoice::Stopped + && voice.mSourceID.load(std::memory_order_relaxed) == 0u) return count + 1; return count; }; auto free_voices = std::accumulate(context->mVoices.begin(), context->mVoices.end(), - ALsizei{0}, count_free_voices); - if UNLIKELY(n > free_voices) + ALuint{0}, count_free_voices); + if UNLIKELY(static_cast(n) > free_voices) { /* Increase the number of voices to handle the request. */ const ALuint need_voices{static_cast(n) - free_voices}; @@ -2775,7 +2781,7 @@ START_API_FUNC } ALbuffer *buffer{BufferList->mBuffer}; - voice->mFrequency = buffer->Frequency; + voice->mFrequency = static_cast(buffer->Frequency); voice->mFmtChannels = buffer->mFmtChannels; voice->mNumChannels = ChannelsFromFmt(buffer->mFmtChannels); voice->mSampleSize = BytesFromFmt(buffer->mFmtType); @@ -2791,20 +2797,20 @@ START_API_FUNC /* Don't need to set the VOICE_IS_AMBISONIC flag if the device is * mixing in first order. No HF scaling is necessary to mix it. */ - if((voice->mFmtChannels == FmtBFormat2D || voice->mFmtChannels == FmtBFormat3D) && - device->mAmbiOrder > 1) + if((voice->mFmtChannels == FmtBFormat2D || voice->mFmtChannels == FmtBFormat3D) + && device->mAmbiOrder > 1) { - const int *OrderFromChan; + const ALuint *OrderFromChan; if(voice->mFmtChannels == FmtBFormat2D) { - static constexpr int Order2DFromChan[MAX_AMBI2D_CHANNELS]{ + static constexpr ALuint Order2DFromChan[MAX_AMBI2D_CHANNELS]{ 0, 1,1, 2,2, 3,3 }; OrderFromChan = Order2DFromChan; } else { - static constexpr int Order3DFromChan[MAX_AMBI_CHANNELS]{ + static constexpr ALuint Order3DFromChan[MAX_AMBI_CHANNELS]{ 0, 1,1,1, 2,2,2,2,2, 3,3,3,3,3,3,3, }; OrderFromChan = Order3DFromChan; @@ -2886,7 +2892,7 @@ START_API_FUNC ALsource **srchandles{source_storage.data()}; if UNLIKELY(static_cast(n) > source_storage.size()) { - extra_sources.resize(n); + extra_sources.resize(static_cast(n)); srchandles = extra_sources.data(); } @@ -2941,7 +2947,7 @@ START_API_FUNC ALsource **srchandles{source_storage.data()}; if UNLIKELY(static_cast(n) > source_storage.size()) { - extra_sources.resize(n); + extra_sources.resize(static_cast(n)); srchandles = extra_sources.data(); } @@ -3006,7 +3012,7 @@ START_API_FUNC ALsource **srchandles{source_storage.data()}; if UNLIKELY(static_cast(n) > source_storage.size()) { - extra_sources.resize(n); + extra_sources.resize(static_cast(n)); srchandles = extra_sources.data(); } @@ -3197,8 +3203,7 @@ START_API_FUNC ++i; } - while(nb > 0) - { + do { std::unique_ptr head{source->queue}; source->queue = head->mNext.load(std::memory_order_relaxed); @@ -3209,8 +3214,7 @@ START_API_FUNC } else *(buffers++) = 0; - --nb; - } + } while(--nb); } END_API_FUNC @@ -3267,7 +3271,7 @@ ALsource::ALsource(ALsizei num_sends) Direct.HFReference = LOWPASSFREQREF; Direct.GainLF = 1.0f; Direct.LFReference = HIGHPASSFREQREF; - Send.resize(num_sends); + Send.resize(static_cast(num_sends)); for(auto &send : Send) { send.Slot = nullptr; diff --git a/al/source.h b/al/source.h index 05037fd3..e0219a04 100644 --- a/al/source.h +++ b/al/source.h @@ -49,17 +49,17 @@ struct ALsource { std::array Direction; std::array OrientAt; std::array OrientUp; - ALboolean HeadRelative; - ALboolean Looping; + bool HeadRelative; + bool Looping; DistanceModel mDistanceModel; Resampler mResampler; - ALboolean DirectChannels; + bool DirectChannels; SpatializeMode mSpatialize; - ALboolean DryGainHFAuto; - ALboolean WetGainAuto; - ALboolean WetGainHFAuto; - ALfloat OuterGainHF; + bool DryGainHFAuto; + bool WetGainAuto; + bool WetGainHFAuto; + ALfloat OuterGainHF; ALfloat AirAbsorptionFactor; ALfloat RoomRolloffFactor; @@ -98,7 +98,7 @@ struct ALsource { ALenum OffsetType{AL_NONE}; /** Source type (static, streaming, or undetermined) */ - ALint SourceType{AL_UNDETERMINED}; + ALenum SourceType{AL_UNDETERMINED}; /** Source state (initial, playing, paused, or stopped) */ ALenum state{AL_INITIAL}; diff --git a/alc/alu.h b/alc/alu.h index 3b6045f0..51b7a5c1 100644 --- a/alc/alu.h +++ b/alc/alu.h @@ -232,8 +232,8 @@ struct ALvoice { /* Properties for the attached buffer(s). */ FmtChannels mFmtChannels; ALuint mFrequency; - ALsizei mNumChannels; - ALsizei mSampleSize; + ALuint mNumChannels; + ALuint mSampleSize; /** Current target parameters used for mixing. */ ALint mStep; diff --git a/alc/mixvoice.cpp b/alc/mixvoice.cpp index 98b86c9a..acc3af1d 100644 --- a/alc/mixvoice.cpp +++ b/alc/mixvoice.cpp @@ -485,8 +485,8 @@ void ALvoice::mix(State vstate, ALCcontext *Context, const ALuint SamplesToDo) ALuint DataPosFrac{mPositionFrac.load(std::memory_order_relaxed)}; ALbufferlistitem *BufferListItem{mCurrentBuffer.load(std::memory_order_relaxed)}; ALbufferlistitem *BufferLoopItem{mLoopBuffer.load(std::memory_order_relaxed)}; - const auto NumChannels = static_cast(mNumChannels); - const auto SampleSize = static_cast(mSampleSize); + const ALuint NumChannels{mNumChannels}; + const ALuint SampleSize{mSampleSize}; const auto increment = static_cast(mStep); if(increment < 1) return; -- cgit v1.2.3 From 6ca8fadd583ade917a07da90c038ce62220593f7 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 12 Sep 2019 12:14:23 -0700 Subject: Fix counting free objects --- al/auxeffectslot.cpp | 2 +- al/buffer.cpp | 2 +- al/effect.cpp | 2 +- al/filter.cpp | 2 +- al/source.cpp | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'al/source.cpp') diff --git a/al/auxeffectslot.cpp b/al/auxeffectslot.cpp index 85c07c89..4dc38ecc 100644 --- a/al/auxeffectslot.cpp +++ b/al/auxeffectslot.cpp @@ -164,7 +164,7 @@ bool EnsureEffectSlots(ALCcontext *context, size_t needed) size_t count{std::accumulate(context->mEffectSlotList.cbegin(), context->mEffectSlotList.cend(), size_t{0}, [](size_t cur, const EffectSlotSubList &sublist) noexcept -> size_t - { return cur + static_cast(POPCNT64(~sublist.FreeMask)); } + { return cur + static_cast(POPCNT64(sublist.FreeMask)); } )}; while(needed > count) diff --git a/al/buffer.cpp b/al/buffer.cpp index 1b4f6846..de1b1e9a 100644 --- a/al/buffer.cpp +++ b/al/buffer.cpp @@ -286,7 +286,7 @@ bool EnsureBuffers(ALCdevice *device, size_t needed) { size_t count{std::accumulate(device->BufferList.cbegin(), device->BufferList.cend(), size_t{0}, [](size_t cur, const BufferSubList &sublist) noexcept -> size_t - { return cur + static_cast(POPCNT64(~sublist.FreeMask)); } + { return cur + static_cast(POPCNT64(sublist.FreeMask)); } )}; while(needed > count) diff --git a/al/effect.cpp b/al/effect.cpp index c27fc8df..0bef3ce6 100644 --- a/al/effect.cpp +++ b/al/effect.cpp @@ -141,7 +141,7 @@ bool EnsureEffects(ALCdevice *device, size_t needed) { size_t count{std::accumulate(device->EffectList.cbegin(), device->EffectList.cend(), size_t{0}, [](size_t cur, const EffectSubList &sublist) noexcept -> size_t - { return cur + static_cast(POPCNT64(~sublist.FreeMask)); } + { return cur + static_cast(POPCNT64(sublist.FreeMask)); } )}; while(needed > count) diff --git a/al/filter.cpp b/al/filter.cpp index 920b4ca1..2dd82bb0 100644 --- a/al/filter.cpp +++ b/al/filter.cpp @@ -283,7 +283,7 @@ 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(POPCNT64(~sublist.FreeMask)); } + { return cur + static_cast(POPCNT64(sublist.FreeMask)); } )}; while(needed > count) diff --git a/al/source.cpp b/al/source.cpp index 3c22b620..38c4ff54 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -500,7 +500,7 @@ bool EnsureSources(ALCcontext *context, size_t needed) size_t count{std::accumulate(context->mSourceList.cbegin(), context->mSourceList.cend(), size_t{0}, [](size_t cur, const SourceSubList &sublist) noexcept -> size_t - { return cur + static_cast(POPCNT64(~sublist.FreeMask)); } + { return cur + static_cast(POPCNT64(sublist.FreeMask)); } )}; while(needed > count) -- cgit v1.2.3 From 70b58d79fe06581a7ca6db3feb17d5d07f8f8de6 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 12 Sep 2019 12:19:07 -0700 Subject: Fix source limit check --- al/source.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'al/source.cpp') diff --git a/al/source.cpp b/al/source.cpp index 38c4ff54..b9989d5d 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -2067,9 +2067,10 @@ START_API_FUNC std::unique_lock srclock{context->mSourceLock}; ALCdevice *device{context->mDevice.get()}; - if(static_cast(n) >= device->SourcesMax-context->mNumSources) + if(static_cast(n) > device->SourcesMax-context->mNumSources) { - context->setError(AL_OUT_OF_MEMORY, "Exceeding %u source limit", device->SourcesMax); + context->setError(AL_OUT_OF_MEMORY, "Exceeding %u source limit (%u + %d)", + device->SourcesMax, context->mNumSources, n); return; } if(!EnsureSources(context.get(), static_cast(n))) -- cgit v1.2.3 From 5ca8796d6ab804841be2724ecb3daa134eb23c39 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 12 Sep 2019 17:10:33 -0700 Subject: Clean up some lambda definitions --- al/auxeffectslot.cpp | 52 ++++++++++++++++++++++++---------------------------- al/buffer.cpp | 49 +++++++++++++++++++++++-------------------------- al/effect.cpp | 38 +++++++++++++++----------------------- al/filter.cpp | 38 +++++++++++++++----------------------- al/source.cpp | 4 ++-- 5 files changed, 79 insertions(+), 102 deletions(-) (limited to 'al/source.cpp') diff --git a/al/auxeffectslot.cpp b/al/auxeffectslot.cpp index 4dc38ecc..b765887c 100644 --- a/al/auxeffectslot.cpp +++ b/al/auxeffectslot.cpp @@ -193,7 +193,6 @@ ALeffectslot *AllocEffectSlot(ALCcontext *context) [](const EffectSlotSubList &entry) noexcept -> bool { return entry.FreeMask != 0; } ); - auto lidx = static_cast(std::distance(context->mEffectSlotList.begin(), sublist)); auto slidx = static_cast(CTZ64(sublist->FreeMask)); @@ -305,41 +304,38 @@ START_API_FUNC ContextRef context{GetContextRef()}; if UNLIKELY(!context) return; - if(n < 0) - SETERR_RETURN(context, AL_INVALID_VALUE,, "Deleting %d effect slots", n); - if(n == 0) return; + if UNLIKELY(n < 0) + context->setError(AL_INVALID_VALUE, "Deleting %d effect slots", n); + if UNLIKELY(n <= 0) return; std::lock_guard _{context->mEffectSlotLock}; - auto effectslots_end = effectslots + n; - auto bad_slot = std::find_if(effectslots, effectslots_end, - [&context](ALuint id) -> bool + auto validate_slot = [&context](const ALuint id) -> bool + { + ALeffectslot *slot{LookupEffectSlot(context.get(), id)}; + if UNLIKELY(!slot) { - ALeffectslot *slot{LookupEffectSlot(context.get(), id)}; - if(!slot) - { - context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", id); - return true; - } - if(ReadRef(slot->ref) != 0) - { - context->setError(AL_INVALID_NAME, "Deleting in-use effect slot %u", id); - return true; - } + context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", id); return false; } - ); - if(bad_slot != effectslots_end) - return; + if UNLIKELY(ReadRef(slot->ref) != 0) + { + context->setError(AL_INVALID_OPERATION, "Deleting in-use effect slot %u", id); + return false; + } + return true; + }; + auto effectslots_end = effectslots + n; + auto bad_slot = std::find_if_not(effectslots, effectslots_end, validate_slot); + if UNLIKELY(bad_slot != effectslots_end) return; // All effectslots are valid, remove and delete them RemoveActiveEffectSlots(effectslots, static_cast(n), context.get()); - std::for_each(effectslots, effectslots_end, - [&context](ALuint sid) -> void - { - ALeffectslot *slot{LookupEffectSlot(context.get(), sid)}; - if(slot) FreeEffectSlot(context.get(), slot); - } - ); + auto delete_slot = [&context](const ALuint sid) -> void + { + ALeffectslot *slot{LookupEffectSlot(context.get(), sid)}; + if(slot) FreeEffectSlot(context.get(), slot); + }; + std::for_each(effectslots, effectslots_end, delete_slot); } END_API_FUNC diff --git a/al/buffer.cpp b/al/buffer.cpp index de1b1e9a..42db68a8 100644 --- a/al/buffer.cpp +++ b/al/buffer.cpp @@ -682,36 +682,33 @@ START_API_FUNC std::lock_guard _{device->BufferLock}; /* First try to find any buffers that are invalid or in-use. */ - const ALuint *buffers_end = buffers + n; - auto invbuf = std::find_if(buffers, buffers_end, - [device, &context](ALuint bid) -> bool + auto validate_buffer = [device, &context](const ALuint bid) -> bool + { + if(!bid) return true; + ALbuffer *ALBuf{LookupBuffer(device, bid)}; + if UNLIKELY(!ALBuf) { - if(!bid) return false; - ALbuffer *ALBuf = LookupBuffer(device, bid); - if UNLIKELY(!ALBuf) - { - context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", bid); - return true; - } - if UNLIKELY(ReadRef(ALBuf->ref) != 0) - { - context->setError(AL_INVALID_OPERATION, "Deleting in-use buffer %u", bid); - return true; - } + context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", bid); return false; } - ); - if LIKELY(invbuf == buffers_end) + if UNLIKELY(ReadRef(ALBuf->ref) != 0) + { + context->setError(AL_INVALID_OPERATION, "Deleting in-use buffer %u", bid); + return false; + } + return true; + }; + const ALuint *buffers_end = buffers + n; + auto invbuf = std::find_if_not(buffers, buffers_end, validate_buffer); + if UNLIKELY(invbuf != buffers_end) return; + + /* All good. Delete non-0 buffer IDs. */ + auto delete_buffer = [device](const ALuint bid) -> void { - /* All good. Delete non-0 buffer IDs. */ - std::for_each(buffers, buffers_end, - [device](ALuint bid) -> void - { - ALbuffer *buffer{bid ? LookupBuffer(device, bid) : nullptr}; - if(buffer) FreeBuffer(device, buffer); - } - ); - } + ALbuffer *buffer{bid ? LookupBuffer(device, bid) : nullptr}; + if(buffer) FreeBuffer(device, buffer); + }; + std::for_each(buffers, buffers_end, delete_buffer); } END_API_FUNC diff --git a/al/effect.cpp b/al/effect.cpp index 0bef3ce6..2ad4c26e 100644 --- a/al/effect.cpp +++ b/al/effect.cpp @@ -169,7 +169,6 @@ ALeffect *AllocEffect(ALCdevice *device) [](const EffectSubList &entry) noexcept -> bool { return entry.FreeMask != 0; } ); - auto lidx = static_cast(std::distance(device->EffectList.begin(), sublist)); auto slidx = static_cast(CTZ64(sublist->FreeMask)); @@ -264,31 +263,24 @@ START_API_FUNC std::lock_guard _{device->EffectLock}; /* First try to find any effects that are invalid. */ + auto validate_effect = [device](const ALuint eid) -> bool + { return !eid || LookupEffect(device, eid) != nullptr; }; + const ALuint *effects_end = effects + n; - auto inveffect = std::find_if(effects, effects_end, - [device, &context](ALuint eid) -> bool - { - if(!eid) return false; - ALeffect *effect{LookupEffect(device, eid)}; - if UNLIKELY(!effect) - { - context->setError(AL_INVALID_NAME, "Invalid effect ID %u", eid); - return true; - } - return false; - } - ); - if LIKELY(inveffect == effects_end) + auto inveffect = std::find_if_not(effects, effects_end, validate_effect); + if UNLIKELY(inveffect != effects_end) { - /* All good. Delete non-0 effect IDs. */ - std::for_each(effects, effects_end, - [device](ALuint eid) -> void - { - ALeffect *effect{eid ? LookupEffect(device, eid) : nullptr}; - if(effect) FreeEffect(device, effect); - } - ); + context->setError(AL_INVALID_NAME, "Invalid effect ID %u", *inveffect); + return; } + + /* All good. Delete non-0 effect IDs. */ + auto delete_effect = [device](ALuint eid) -> void + { + ALeffect *effect{eid ? LookupEffect(device, eid) : nullptr}; + if(effect) FreeEffect(device, effect); + }; + std::for_each(effects, effects_end, delete_effect); } END_API_FUNC diff --git a/al/filter.cpp b/al/filter.cpp index 2dd82bb0..33887254 100644 --- a/al/filter.cpp +++ b/al/filter.cpp @@ -312,7 +312,6 @@ ALfilter *AllocFilter(ALCdevice *device) [](const FilterSubList &entry) noexcept -> bool { return entry.FreeMask != 0; } ); - auto lidx = static_cast(std::distance(device->FilterList.begin(), sublist)); auto slidx = static_cast(CTZ64(sublist->FreeMask)); @@ -408,31 +407,24 @@ START_API_FUNC std::lock_guard _{device->FilterLock}; /* First try to find any filters that are invalid. */ + auto validate_filter = [device](const ALuint fid) -> bool + { return !fid || LookupFilter(device, fid) != nullptr; }; + const ALuint *filters_end = filters + n; - auto invflt = std::find_if(filters, filters_end, - [device, &context](ALuint fid) -> bool - { - if(!fid) return false; - ALfilter *filter{LookupFilter(device, fid)}; - if UNLIKELY(!filter) - { - context->setError(AL_INVALID_NAME, "Invalid filter ID %u", fid); - return true; - } - return false; - } - ); - if LIKELY(invflt == filters_end) + auto invflt = std::find_if_not(filters, filters_end, validate_filter); + if UNLIKELY(invflt != filters_end) { - /* All good. Delete non-0 filter IDs. */ - std::for_each(filters, filters_end, - [device](ALuint fid) -> void - { - ALfilter *filter{fid ? LookupFilter(device, fid) : nullptr}; - if(filter) FreeFilter(device, filter); - } - ); + context->setError(AL_INVALID_NAME, "Invalid filter ID %u", *invflt); + return; } + + /* All good. Delete non-0 filter IDs. */ + auto delete_filter = [device](const ALuint fid) -> void + { + ALfilter *filter{fid ? LookupFilter(device, fid) : nullptr}; + if(filter) FreeFilter(device, filter); + }; + std::for_each(filters, filters_end, delete_filter); } END_API_FUNC diff --git a/al/source.cpp b/al/source.cpp index b9989d5d..09b4133c 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -2110,7 +2110,7 @@ START_API_FUNC std::lock_guard _{context->mSourceLock}; /* Check that all Sources are valid */ - auto validate_source = [&context](ALuint sid) -> bool + auto validate_source = [&context](const ALuint sid) -> bool { return LookupSource(context.get(), sid) != nullptr; }; const ALuint *sources_end = sources + n; @@ -2122,7 +2122,7 @@ START_API_FUNC } /* All good. Delete source IDs. */ - auto delete_source = [&context](ALuint sid) -> void + auto delete_source = [&context](const ALuint sid) -> void { ALsource *src{LookupSource(context.get(), sid)}; if(src) FreeSource(context.get(), src); -- cgit v1.2.3 From df306b55245de7a281d695046e74717e4cdd511f Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 13 Sep 2019 04:15:05 -0700 Subject: Make NumAuxSends unsigned --- al/source.cpp | 10 +++++----- al/source.h | 2 +- alc/alc.cpp | 33 ++++++++++++++++++--------------- alc/alcmain.h | 2 +- alc/alu.cpp | 8 ++++---- alc/mixvoice.cpp | 7 +++---- 6 files changed, 32 insertions(+), 30 deletions(-) (limited to 'al/source.cpp') diff --git a/al/source.cpp b/al/source.cpp index 09b4133c..478ee3d2 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -522,7 +522,7 @@ bool EnsureSources(ALCcontext *context, size_t needed) return true; } -ALsource *AllocSource(ALCcontext *context, ALsizei num_sends) +ALsource *AllocSource(ALCcontext *context, ALuint num_sends) { auto sublist = std::find_if(context->mSourceList.begin(), context->mSourceList.end(), [](const SourceSubList &entry) noexcept -> bool @@ -1315,7 +1315,7 @@ bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a slotlock = std::unique_lock{Context->mEffectSlotLock}; if(values[0] && (slot=LookupEffectSlot(Context, static_cast(values[0]))) == nullptr) SETERR_RETURN(Context, AL_INVALID_VALUE, false, "Invalid effect ID %u", values[0]); - if(static_cast(values[1]) >= static_cast(device->NumAuxSends)) + if(static_cast(values[1]) >= device->NumAuxSends) SETERR_RETURN(Context, AL_INVALID_VALUE, false, "Invalid send %u", values[1]); filtlock = std::unique_lock{device->FilterLock}; @@ -2086,7 +2086,7 @@ START_API_FUNC } else { - const ALsizei num_sends{device->NumAuxSends}; + const ALuint num_sends{device->NumAuxSends}; al::vector ids; ids.reserve(static_cast(n)); do { @@ -3220,7 +3220,7 @@ START_API_FUNC END_API_FUNC -ALsource::ALsource(ALsizei num_sends) +ALsource::ALsource(ALuint num_sends) { InnerAngle = 360.0f; OuterAngle = 360.0f; @@ -3272,7 +3272,7 @@ ALsource::ALsource(ALsizei num_sends) Direct.HFReference = LOWPASSFREQREF; Direct.GainLF = 1.0f; Direct.LFReference = HIGHPASSFREQREF; - Send.resize(static_cast(num_sends)); + Send.resize(num_sends); for(auto &send : Send) { send.Slot = nullptr; diff --git a/al/source.h b/al/source.h index e0219a04..7ca889d7 100644 --- a/al/source.h +++ b/al/source.h @@ -117,7 +117,7 @@ struct ALsource { ALuint id{0}; - ALsource(ALsizei num_sends); + ALsource(ALuint num_sends); ~ALsource(); ALsource(const ALsource&) = delete; diff --git a/alc/alc.cpp b/alc/alc.cpp index a819bbf7..6d7228f5 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -1614,15 +1614,15 @@ static inline void UpdateClockBase(ALCdevice *device) */ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) { - HrtfRequestMode hrtf_userreq = Hrtf_Default; - HrtfRequestMode hrtf_appreq = Hrtf_Default; - ALCenum gainLimiter = device->LimiterState; - const ALsizei old_sends = device->NumAuxSends; - ALsizei new_sends = device->NumAuxSends; + HrtfRequestMode hrtf_userreq{Hrtf_Default}; + HrtfRequestMode hrtf_appreq{Hrtf_Default}; + ALCenum gainLimiter{device->LimiterState}; + const ALCuint old_sends{device->NumAuxSends}; + ALCuint new_sends{device->NumAuxSends}; DevFmtChannels oldChans; DevFmtType oldType; ALboolean update_failed; - ALCsizei hrtf_id = -1; + ALCsizei hrtf_id{-1}; ALCuint oldFreq; if((!attrList || !attrList[0]) && device->Type == Loopback) @@ -1644,7 +1644,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) ALuint numMono{device->NumMonoSources}; ALuint numStereo{device->NumStereoSources}; - ALsizei numSends{old_sends}; + ALuint numSends{old_sends}; #define TRACE_ATTR(a, v) TRACE("%s = %d\n", #a, v) while(attrList[attrIdx]) @@ -1694,9 +1694,10 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) break; case ALC_MAX_AUXILIARY_SENDS: - numSends = attrList[attrIdx + 1]; + numSends = static_cast(attrList[attrIdx + 1]); TRACE_ATTR(ALC_MAX_AUXILIARY_SENDS, numSends); - numSends = clampi(numSends, 0, MAX_SENDS); + if(numSends > INT_MAX) numSends = 0; + else numSends = minu(numSends, MAX_SENDS); break; case ALC_HRTF_SOFT: @@ -1828,7 +1829,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) device->NumStereoSources = numStereo; if(auto sendsopt = ConfigValueInt(devname, nullptr, "sends")) - new_sends = mini(numSends, clampi(*sendsopt, 0, MAX_SENDS)); + new_sends = minu(numSends, static_cast(clampi(*sendsopt, 0, MAX_SENDS))); else new_sends = numSends; } @@ -2176,7 +2177,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) if(device->NumAuxSends < old_sends) { - const ALsizei num_sends{device->NumAuxSends}; + const ALuint num_sends{device->NumAuxSends}; /* Clear extraneous property set sends. */ auto clear_sends = [num_sends](ALvoice &voice) -> void { @@ -2871,7 +2872,7 @@ static size_t GetIntegerv(ALCdevice *device, ALCenum param, const al::span(device->NumStereoSources); values[i++] = ALC_MAX_AUXILIARY_SENDS; - values[i++] = device->NumAuxSends; + values[i++] = static_cast(device->NumAuxSends); values[i++] = ALC_HRTF_SOFT; values[i++] = (device->mHrtf ? ALC_TRUE : ALC_FALSE); @@ -2984,7 +2985,7 @@ static size_t GetIntegerv(ALCdevice *device, ALCenum param, const al::spanNumAuxSends; + values[0] = static_cast(device->NumAuxSends); return 1; case ALC_CONNECTED: @@ -3647,7 +3648,8 @@ START_API_FUNC } if(auto sendsopt = ConfigValueInt(deviceName, nullptr, "sends")) - device->NumAuxSends = clampi(DEFAULT_SENDS, 0, clampi(*sendsopt, 0, MAX_SENDS)); + device->NumAuxSends = clampu(DEFAULT_SENDS, 0, + static_cast(clampi(*sendsopt, 0, MAX_SENDS))); device->NumStereoSources = 1; device->NumMonoSources = device->SourcesMax - device->NumStereoSources; @@ -3959,7 +3961,8 @@ START_API_FUNC } if(auto sendsopt = ConfigValueInt(nullptr, nullptr, "sends")) - device->NumAuxSends = clampi(DEFAULT_SENDS, 0, clampi(*sendsopt, 0, MAX_SENDS)); + device->NumAuxSends = clampu(DEFAULT_SENDS, 0, + static_cast(clampi(*sendsopt, 0, MAX_SENDS))); device->NumStereoSources = 1; device->NumMonoSources = device->SourcesMax - device->NumStereoSources; diff --git a/alc/alcmain.h b/alc/alcmain.h index fb93488f..338897ab 100644 --- a/alc/alcmain.h +++ b/alc/alcmain.h @@ -242,7 +242,7 @@ struct ALCdevice : public al::intrusive_ref { ALCuint NumMonoSources{}; ALCuint NumStereoSources{}; - ALsizei NumAuxSends{}; + ALCuint NumAuxSends{}; // Map of Buffers for this device std::mutex BufferLock; diff --git a/alc/alu.cpp b/alc/alu.cpp index d9464125..0def577e 100644 --- a/alc/alu.cpp +++ b/alc/alu.cpp @@ -451,7 +451,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat xpos, const ALfloat ypo }; const auto Frequency = static_cast(Device->Frequency); - const auto NumSends = static_cast(Device->NumAuxSends); + const ALuint NumSends{Device->NumAuxSends}; bool DirectChannels{props->DirectChannels != AL_FALSE}; const ChanMap *chans{nullptr}; @@ -923,7 +923,7 @@ void CalcNonAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, cons ALeffectslot *SendSlots[MAX_SENDS]; voice->mDirect.Buffer = Device->Dry.Buffer; - for(ALuint i{0};i < static_cast(Device->NumAuxSends);i++) + for(ALuint i{0};i < Device->NumAuxSends;i++) { SendSlots[i] = props->Send[i].Slot; if(!SendSlots[i] && i == 0) @@ -958,7 +958,7 @@ void CalcNonAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, cons ALfloat DryGainHF{props->Direct.GainHF}; ALfloat DryGainLF{props->Direct.GainLF}; ALfloat WetGain[MAX_SENDS], WetGainHF[MAX_SENDS], WetGainLF[MAX_SENDS]; - for(ALsizei i{0};i < Device->NumAuxSends;i++) + for(ALuint i{0};i < Device->NumAuxSends;i++) { WetGain[i] = clampf(props->Gain, props->MinGain, props->MaxGain); WetGain[i] *= props->Send[i].Gain * Listener.Params.Gain; @@ -974,7 +974,7 @@ void CalcNonAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, cons void CalcAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, const ALCcontext *ALContext) { const ALCdevice *Device{ALContext->mDevice.get()}; - const auto NumSends = static_cast(Device->NumAuxSends); + const ALuint NumSends{Device->NumAuxSends}; const ALlistener &Listener = ALContext->mListener; /* Set mixing buffers and get send parameters. */ diff --git a/alc/mixvoice.cpp b/alc/mixvoice.cpp index 3c621934..9d7dead4 100644 --- a/alc/mixvoice.cpp +++ b/alc/mixvoice.cpp @@ -495,10 +495,9 @@ void ALvoice::mix(State vstate, ALCcontext *Context, const ALuint SamplesToDo) ASSUME(increment > 0); ALCdevice *Device{Context->mDevice.get()}; - const ALsizei NumSends{Device->NumAuxSends}; + const ALuint NumSends{Device->NumAuxSends}; const ALsizei IrSize{Device->mHrtf ? Device->mHrtf->irSize : 0}; - ASSUME(NumSends >= 0); ASSUME(IrSize >= 0); ResamplerFunc Resample{(increment == FRACTIONONE && DataPosFrac == 0) ? @@ -517,7 +516,7 @@ void ALvoice::mix(State vstate, ALCcontext *Context, const ALuint SamplesToDo) std::begin(parms.Gains.Current)); else parms.Hrtf.Old = parms.Hrtf.Target; - for(ALsizei send{0};send < NumSends;++send) + for(ALuint send{0};send < NumSends;++send) { if(mSend[send].Buffer.empty()) continue; @@ -785,7 +784,7 @@ void ALvoice::mix(State vstate, ALCcontext *Context, const ALuint SamplesToDo) } } - for(ALsizei send{0};send < NumSends;++send) + for(ALuint send{0};send < NumSends;++send) { if(mSend[send].Buffer.empty()) continue; -- cgit v1.2.3 From 2c348cecb68bd3a71d388547d6b3330f9cebbfad Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 14 Sep 2019 16:55:28 -0700 Subject: Fix some more implicit conversions noted by GCC --- al/source.cpp | 6 +++--- alc/alc.cpp | 34 +++++++++++++++++-------------- alc/alu.cpp | 10 ++++----- alc/backends/alsa.cpp | 2 +- alc/backends/coreaudio.cpp | 17 ++++++++-------- alc/backends/opensl.cpp | 6 +++--- alc/backends/pulseaudio.cpp | 2 +- alc/bs2b.cpp | 4 ++-- alc/converter.cpp | 2 +- alc/effects/autowah.cpp | 9 +++++---- alc/effects/chorus.cpp | 32 +++++++++++++++-------------- alc/effects/echo.cpp | 6 ++++-- alc/effects/fshifter.cpp | 3 ++- alc/effects/modulator.cpp | 2 +- alc/effects/pshifter.cpp | 19 +++++++++--------- alc/effects/vmorpher.cpp | 14 +++++++------ alc/hrtf.cpp | 49 ++++++++++++++++++++++++--------------------- alc/mastering.cpp | 3 +-- alc/mastering.h | 3 +-- alc/mixer/mixer_c.cpp | 9 +++++---- alc/mixer/mixer_neon.cpp | 13 ++++++------ alc/mixer/mixer_sse.cpp | 7 ++++--- alc/mixer/mixer_sse2.cpp | 2 +- alc/mixer/mixer_sse41.cpp | 2 +- alc/mixvoice.cpp | 18 +++++++++-------- common/almalloc.cpp | 6 +++--- examples/alrecord.c | 5 +++-- examples/altonegen.c | 2 +- examples/common/alhelpers.c | 4 ++-- 29 files changed, 156 insertions(+), 135 deletions(-) (limited to 'al/source.cpp') diff --git a/al/source.cpp b/al/source.cpp index 478ee3d2..733758f7 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -310,8 +310,8 @@ ALdouble GetSourceOffset(ALsource *Source, ALenum name, ALCcontext *context) const ALbufferlistitem *BufferList{Source->queue}; const ALbuffer *BufferFmt{nullptr}; - ALboolean readFin{AL_FALSE}; ALuint totalBufferLen{0u}; + bool readFin{false}; while(BufferList) { @@ -1662,7 +1662,7 @@ bool GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a case AL_SEC_OFFSET_CLOCK_SOFT: CHECKSIZE(values, 2); values[0] = GetSourceSecOffset(Source, Context, &srcclock); - values[1] = srcclock.count() / 1000000000.0; + values[1] = static_cast(srcclock.count()) / 1000000000.0; return true; case AL_POSITION: @@ -2851,7 +2851,7 @@ START_API_FUNC if(device->AvgSpeakerDist > 0.0f) { const ALfloat w1{SPEEDOFSOUNDMETRESPERSEC / - (device->AvgSpeakerDist * device->Frequency)}; + (device->AvgSpeakerDist * static_cast(device->Frequency))}; auto init_nfc = [w1](ALvoice::ChannelData &chandata) -> void { chandata.mDryParams.NFCtrlFilter.init(w1); }; std::for_each(voice->mChans.begin(), voice->mChans.begin()+voice->mNumChannels, diff --git a/alc/alc.cpp b/alc/alc.cpp index 408b3ca3..8e9d3963 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -1587,9 +1587,9 @@ static void alcSetError(ALCdevice *device, ALCenum errorCode) static std::unique_ptr CreateDeviceLimiter(const ALCdevice *device, const ALfloat threshold) { - return CompressorInit(static_cast(device->RealOut.Buffer.size()), device->Frequency, - AL_TRUE, AL_TRUE, AL_TRUE, AL_TRUE, AL_TRUE, 0.001f, 0.002f, 0.0f, 0.0f, threshold, - INFINITY, 0.0f, 0.020f, 0.200f); + return CompressorInit(static_cast(device->RealOut.Buffer.size()), + static_cast(device->Frequency), AL_TRUE, AL_TRUE, AL_TRUE, AL_TRUE, AL_TRUE, 0.001f, + 0.002f, 0.0f, 0.0f, threshold, INFINITY, 0.0f, 0.020f, 0.200f); } /* UpdateClockBase @@ -2145,17 +2145,21 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) if(old_sends != device->NumAuxSends) { - if(source->Send.size() > static_cast(device->NumAuxSends)) - std::for_each(source->Send.begin()+device->NumAuxSends, source->Send.end(), - [](ALsource::SendData &send) -> void - { - if(send.Slot) - DecrementRef(send.Slot->ref); - send.Slot = nullptr; - }); - - source->Send.resize(static_cast(device->NumAuxSends), - ALsource::SendData{nullptr, 1.0f, 1.0f, LOWPASSFREQREF, 1.0f, HIGHPASSFREQREF}); + if(source->Send.size() > device->NumAuxSends) + { + auto clear_send = [](ALsource::SendData &send) -> void + { + if(send.Slot) + DecrementRef(send.Slot->ref); + send.Slot = nullptr; + }; + auto send_begin = source->Send.begin() + + static_cast(device->NumAuxSends); + std::for_each(send_begin, source->Send.end(), clear_send); + } + + source->Send.resize(device->NumAuxSends, + {nullptr, 1.0f, 1.0f, LOWPASSFREQREF, 1.0f, HIGHPASSFREQREF}); source->Send.shrink_to_fit(); } @@ -2209,7 +2213,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) { /* Reinitialize the NFC filters for new parameters. */ const ALfloat w1{SPEEDOFSOUNDMETRESPERSEC / - (device->AvgSpeakerDist * device->Frequency)}; + (device->AvgSpeakerDist * static_cast(device->Frequency))}; auto init_nfc = [w1](ALvoice::ChannelData &chandata) -> void { chandata.mDryParams.NFCtrlFilter.init(w1); }; std::for_each(voice.mChans.begin(), voice.mChans.begin()+voice.mNumChannels, diff --git a/alc/alu.cpp b/alc/alu.cpp index 0def577e..d7acf8d3 100644 --- a/alc/alu.cpp +++ b/alc/alu.cpp @@ -201,19 +201,19 @@ void ALCdevice::ProcessBs2b(const size_t SamplesToDo) */ void BsincPrepare(const ALuint increment, BsincState *state, const BSincTable *table) { - ALsizei si{BSINC_SCALE_COUNT - 1}; - ALfloat sf{0.0f}; + size_t si{BSINC_SCALE_COUNT - 1}; + float sf{0.0f}; if(increment > FRACTIONONE) { - sf = static_castFRACTIONONE / increment; + sf = FRACTIONONE / static_cast(increment); sf = maxf(0.0f, (BSINC_SCALE_COUNT-1) * (sf-table->scaleBase) * table->scaleRange); - si = float2int(sf); + si = float2uint(sf); /* The interpolation factor is fit to this diagonally-symmetric curve * to reduce the transition ripple caused by interpolating different * scales of the sinc function. */ - sf = 1.0f - std::cos(std::asin(sf - si)); + sf = 1.0f - std::cos(std::asin(sf - static_cast(si))); } state->sf = sf; diff --git a/alc/backends/alsa.cpp b/alc/backends/alsa.cpp index cd85afaf..b797c768 100644 --- a/alc/backends/alsa.cpp +++ b/alc/backends/alsa.cpp @@ -1112,7 +1112,7 @@ ALCenum AlsaCapture::captureSamples(ALCvoid *buffer, ALCuint samples) } buffer = static_cast(buffer) + amt; - samples -= amt; + samples -= static_cast(amt); } if(samples > 0) std::fill_n(static_cast(buffer), snd_pcm_frames_to_bytes(mPcmHandle, samples), diff --git a/alc/backends/coreaudio.cpp b/alc/backends/coreaudio.cpp index 39f6241a..99b06b7a 100644 --- a/alc/backends/coreaudio.cpp +++ b/alc/backends/coreaudio.cpp @@ -177,7 +177,7 @@ ALCboolean CoreAudioPlayback::reset() { mDevice->BufferSize = static_cast(uint64_t{mDevice->BufferSize} * streamFormat.mSampleRate / mDevice->Frequency); - mDevice->Frequency = streamFormat.mSampleRate; + mDevice->Frequency = static_cast(streamFormat.mSampleRate); } /* FIXME: How to tell what channels are what in the output device, and how @@ -357,7 +357,8 @@ OSStatus CoreAudioCapture::RecordProc(AudioUnitRenderActionFlags*, } audiobuf = { { 0 } }; auto rec_vec = mRing->getWriteVector(); - inNumberFrames = minz(inNumberFrames, rec_vec.first.len+rec_vec.second.len); + inNumberFrames = static_cast(minz(inNumberFrames, + rec_vec.first.len+rec_vec.second.len)); // Fill the ringbuffer's two segments with data from the input device if(rec_vec.first.len >= inNumberFrames) @@ -369,7 +370,7 @@ OSStatus CoreAudioCapture::RecordProc(AudioUnitRenderActionFlags*, } else { - const size_t remaining{inNumberFrames-rec_vec.first.len}; + const auto remaining = static_cast(inNumberFrames - rec_vec.first.len); audiobuf.list.mNumberBuffers = 2; audiobuf.list.mBuffers[0].mNumberChannels = mFormat.mChannelsPerFrame; audiobuf.list.mBuffers[0].mData = rec_vec.first.buf; @@ -594,7 +595,7 @@ ALCenum CoreAudioCapture::open(const ALCchar *name) // Set the AudioUnit output format frame count uint64_t FrameCount64{mDevice->UpdateSize}; - FrameCount64 = (FrameCount64*outputFormat.mSampleRate + mDevice->Frequency-1) / + FrameCount64 = static_cast(FrameCount64*outputFormat.mSampleRate + mDevice->Frequency-1) / mDevice->Frequency; FrameCount64 += MAX_RESAMPLE_PADDING*2; if(FrameCount64 > std::numeric_limits::max()/2) @@ -615,8 +616,8 @@ ALCenum CoreAudioCapture::open(const ALCchar *name) // Set up sample converter if needed if(outputFormat.mSampleRate != mDevice->Frequency) mConverter = CreateSampleConverter(mDevice->FmtType, mDevice->FmtType, - mFormat.mChannelsPerFrame, hardwareFormat.mSampleRate, mDevice->Frequency, - BSinc24Resampler); + mFormat.mChannelsPerFrame, static_cast(hardwareFormat.mSampleRate), + mDevice->Frequency, BSinc24Resampler); mRing = CreateRingBuffer(outputFrameCount, mFrameSize, false); if(!mRing) return ALC_INVALID_VALUE; @@ -671,8 +672,8 @@ ALCenum CoreAudioCapture::captureSamples(void *buffer, ALCuint samples) ALCuint CoreAudioCapture::availableSamples() { - if(!mConverter) return mRing->readSpace(); - return mConverter->availableOut(mRing->readSpace()); + if(!mConverter) return static_cast(mRing->readSpace()); + return mConverter->availableOut(static_cast(mRing->readSpace())); } } // namespace diff --git a/alc/backends/opensl.cpp b/alc/backends/opensl.cpp index 3ec2177f..06d5cd40 100644 --- a/alc/backends/opensl.cpp +++ b/alc/backends/opensl.cpp @@ -170,7 +170,7 @@ struct OpenSLPlayback final : public BackendBase { RingBufferPtr mRing{nullptr}; al::semaphore mSem; - ALsizei mFrameSize{0}; + ALuint mFrameSize{0}; std::atomic mKillNow{true}; std::thread mThread; @@ -630,7 +630,7 @@ struct OpenSLCapture final : public BackendBase { RingBufferPtr mRing{nullptr}; ALCuint mSplOffset{0u}; - ALsizei mFrameSize{0}; + ALuint mFrameSize{0}; DEF_NEWDEL(OpenSLCapture) }; @@ -851,7 +851,7 @@ void OpenSLCapture::stop() ALCenum OpenSLCapture::captureSamples(void *buffer, ALCuint samples) { - ALsizei chunk_size = mDevice->UpdateSize * mFrameSize; + ALuint chunk_size{mDevice->UpdateSize * mFrameSize}; SLAndroidSimpleBufferQueueItf bufferQueue; SLresult result; ALCuint i; diff --git a/alc/backends/pulseaudio.cpp b/alc/backends/pulseaudio.cpp index 08420748..30c13a69 100644 --- a/alc/backends/pulseaudio.cpp +++ b/alc/backends/pulseaudio.cpp @@ -1324,7 +1324,7 @@ ALCenum PulseCapture::captureSamples(ALCvoid *buffer, ALCuint samples) /* Capture is done in fragment-sized chunks, so we loop until we get all * that's available */ - mLastReadable -= dstbuf.size(); + mLastReadable -= static_cast(dstbuf.size()); std::lock_guard _{pulse_lock}; while(!dstbuf.empty()) { diff --git a/alc/bs2b.cpp b/alc/bs2b.cpp index fb75188c..00207bc0 100644 --- a/alc/bs2b.cpp +++ b/alc/bs2b.cpp @@ -91,11 +91,11 @@ static void init(struct bs2b *bs2b) * $d = 1 / 2 / pi / $fc; * $x = exp(-1 / $d); */ - x = std::exp(-al::MathDefs::Tau() * Fc_lo / bs2b->srate); + x = std::exp(-al::MathDefs::Tau() * Fc_lo / static_cast(bs2b->srate)); bs2b->b1_lo = x; bs2b->a0_lo = G_lo * (1.0f - x) * g; - x = std::exp(-al::MathDefs::Tau() * Fc_hi / bs2b->srate); + x = std::exp(-al::MathDefs::Tau() * Fc_hi / static_cast(bs2b->srate)); bs2b->b1_hi = x; bs2b->a0_hi = (1.0f - G_hi * (1.0f - x)) * g; bs2b->a1_hi = -x * g; diff --git a/alc/converter.cpp b/alc/converter.cpp index 2913f533..2ad2ac3b 100644 --- a/alc/converter.cpp +++ b/alc/converter.cpp @@ -27,7 +27,7 @@ template<> inline ALfloat LoadSample(DevFmtTypeTraits::T template<> inline ALfloat LoadSample(DevFmtTypeTraits::Type val) noexcept { return val * (1.0f/32768.0f); } template<> inline ALfloat LoadSample(DevFmtTypeTraits::Type val) noexcept -{ return val * (1.0f/2147483648.0f); } +{ return static_cast(val) * (1.0f/2147483648.0f); } template<> inline ALfloat LoadSample(DevFmtTypeTraits::Type val) noexcept { return val; } diff --git a/alc/effects/autowah.cpp b/alc/effects/autowah.cpp index f28cfd54..5e396d0c 100644 --- a/alc/effects/autowah.cpp +++ b/alc/effects/autowah.cpp @@ -107,16 +107,17 @@ ALboolean ALautowahState::deviceUpdate(const ALCdevice*) void ALautowahState::update(const ALCcontext *context, const ALeffectslot *slot, const EffectProps *props, const EffectTarget target) { const ALCdevice *device{context->mDevice.get()}; + const auto frequency = static_cast(device->Frequency); const ALfloat ReleaseTime{clampf(props->Autowah.ReleaseTime, 0.001f, 1.0f)}; - mAttackRate = expf(-1.0f / (props->Autowah.AttackTime*device->Frequency)); - mReleaseRate = expf(-1.0f / (ReleaseTime*device->Frequency)); + mAttackRate = std::exp(-1.0f / (props->Autowah.AttackTime*frequency)); + mReleaseRate = std::exp(-1.0f / (ReleaseTime*frequency)); /* 0-20dB Resonance Peak gain */ mResonanceGain = std::sqrt(std::log10(props->Autowah.Resonance)*10.0f / 3.0f); mPeakGain = 1.0f - std::log10(props->Autowah.PeakGain/AL_AUTOWAH_MAX_PEAK_GAIN); - mFreqMinNorm = MIN_FREQ / device->Frequency; - mBandwidthNorm = (MAX_FREQ-MIN_FREQ) / device->Frequency; + mFreqMinNorm = MIN_FREQ / frequency; + mBandwidthNorm = (MAX_FREQ-MIN_FREQ) / frequency; mOutTarget = target.Main->Buffer; for(size_t i{0u};i < slot->Wet.Buffer.size();++i) diff --git a/alc/effects/chorus.cpp b/alc/effects/chorus.cpp index 6e73f1f0..0e3c9d89 100644 --- a/alc/effects/chorus.cpp +++ b/alc/effects/chorus.cpp @@ -64,8 +64,8 @@ void GetTriangleDelays(ALuint *delays, const ALuint start_offset, const ALuint l auto gen_lfo = [&offset,lfo_range,lfo_scale,depth,delay]() -> ALuint { offset = (offset+1)%lfo_range; - return static_cast( - fastf2i((1.0f - std::abs(2.0f - lfo_scale*offset)) * depth) + delay); + const float offset_norm{static_cast(offset) * lfo_scale}; + return static_cast(fastf2i((1.0f-std::abs(2.0f-offset_norm)) * depth) + delay); }; std::generate_n(delays, todo, gen_lfo); } @@ -80,7 +80,8 @@ void GetSinusoidDelays(ALuint *delays, const ALuint start_offset, const ALuint l auto gen_lfo = [&offset,lfo_range,lfo_scale,depth,delay]() -> ALuint { offset = (offset+1)%lfo_range; - return static_cast(fastf2i(std::sin(lfo_scale*offset) * depth) + delay); + const float offset_norm{static_cast(offset) * lfo_scale}; + return static_cast(fastf2i(std::sin(offset_norm)*depth) + delay); }; std::generate_n(delays, todo, gen_lfo); } @@ -118,7 +119,8 @@ ALboolean ChorusState::deviceUpdate(const ALCdevice *Device) { constexpr ALfloat max_delay{maxf(AL_CHORUS_MAX_DELAY, AL_FLANGER_MAX_DELAY)}; - const size_t maxlen{NextPowerOf2(float2uint(max_delay*2.0f*Device->Frequency) + 1u)}; + const auto frequency = static_cast(Device->Frequency); + const size_t maxlen{NextPowerOf2(float2uint(max_delay*2.0f*frequency) + 1u)}; if(maxlen != mSampleBuffer.size()) { mSampleBuffer.resize(maxlen); @@ -153,9 +155,11 @@ void ChorusState::update(const ALCcontext *Context, const ALeffectslot *Slot, co * delay and depth to allow enough padding for resampling. */ const ALCdevice *device{Context->mDevice.get()}; - const auto frequency = static_cast(device->Frequency); + const auto frequency = static_cast(device->Frequency); + mDelay = maxi(float2int(props->Chorus.Delay*frequency*FRACTIONONE + 0.5f), mindelay); - mDepth = minf(props->Chorus.Depth * mDelay, static_cast(mDelay - mindelay)); + mDepth = minf(props->Chorus.Depth * static_cast(mDelay), + static_cast(mDelay - mindelay)); mFeedback = props->Chorus.Feedback; @@ -188,10 +192,10 @@ void ChorusState::update(const ALCcontext *Context, const ALeffectslot *Slot, co switch(mWaveform) { case WaveForm::Triangle: - mLfoScale = 4.0f / mLfoRange; + mLfoScale = 4.0f / static_cast(mLfoRange); break; case WaveForm::Sinusoid: - mLfoScale = al::MathDefs::Tau() / mLfoRange; + mLfoScale = al::MathDefs::Tau() / static_cast(mLfoRange); break; } @@ -229,7 +233,7 @@ void ChorusState::process(const size_t samplesToDo, const al::span(todo)) % mLfoRange; alignas(16) ALfloat temps[2][256]; for(size_t i{0u};i < todo;i++) @@ -239,17 +243,15 @@ void ChorusState::process(const size_t samplesToDo, const al::span>FRACTIONBITS)}; - ALfloat mu{(moddelays[0][i]&FRACTIONMASK) * (1.0f/FRACTIONONE)}; + ALfloat mu{static_cast(moddelays[0][i]&FRACTIONMASK) * (1.0f/FRACTIONONE)}; temps[0][i] = cubic(delaybuf[(delay+1) & bufmask], delaybuf[(delay ) & bufmask], - delaybuf[(delay-1) & bufmask], delaybuf[(delay-2) & bufmask], - mu); + delaybuf[(delay-1) & bufmask], delaybuf[(delay-2) & bufmask], mu); // Tap for the right output. delay = offset - (moddelays[1][i]>>FRACTIONBITS); - mu = (moddelays[1][i]&FRACTIONMASK) * (1.0f/FRACTIONONE); + mu = static_cast(moddelays[1][i]&FRACTIONMASK) * (1.0f/FRACTIONONE); temps[1][i] = cubic(delaybuf[(delay+1) & bufmask], delaybuf[(delay ) & bufmask], - delaybuf[(delay-1) & bufmask], delaybuf[(delay-2) & bufmask], - mu); + delaybuf[(delay-1) & bufmask], delaybuf[(delay-2) & bufmask], mu); // Accumulate feedback from the average delay of the taps. delaybuf[offset&bufmask] += delaybuf[(offset-avgdelay) & bufmask] * feedback; diff --git a/alc/effects/echo.cpp b/alc/effects/echo.cpp index 47c0fedb..a9213df5 100644 --- a/alc/effects/echo.cpp +++ b/alc/effects/echo.cpp @@ -66,10 +66,12 @@ struct EchoState final : public EffectState { ALboolean EchoState::deviceUpdate(const ALCdevice *Device) { + const auto frequency = static_cast(Device->Frequency); + // Use the next power of 2 for the buffer length, so the tap offsets can be // wrapped using a mask instead of a modulo - const ALuint maxlen{NextPowerOf2(float2uint(AL_ECHO_MAX_DELAY*Device->Frequency + 0.5f) + - float2uint(AL_ECHO_MAX_LRDELAY*Device->Frequency + 0.5f))}; + const ALuint maxlen{NextPowerOf2(float2uint(AL_ECHO_MAX_DELAY*frequency + 0.5f) + + float2uint(AL_ECHO_MAX_LRDELAY*frequency + 0.5f))}; if(maxlen != mSampleBuffer.size()) { mSampleBuffer.resize(maxlen); diff --git a/alc/effects/fshifter.cpp b/alc/effects/fshifter.cpp index c015831c..1b935047 100644 --- a/alc/effects/fshifter.cpp +++ b/alc/effects/fshifter.cpp @@ -51,7 +51,8 @@ std::array InitHannWindow() /* Create lookup table of the Hann window for the desired size, i.e. HIL_SIZE */ for(size_t i{0};i < HIL_SIZE>>1;i++) { - const double val{std::sin(al::MathDefs::Pi() * i / double{HIL_SIZE-1})}; + constexpr double scale{al::MathDefs::Pi() / double{HIL_SIZE-1}}; + const double val{std::sin(static_cast(i) * scale)}; ret[i] = ret[HIL_SIZE-1-i] = val * val; } return ret; diff --git a/alc/effects/modulator.cpp b/alc/effects/modulator.cpp index fbc6377c..8042378a 100644 --- a/alc/effects/modulator.cpp +++ b/alc/effects/modulator.cpp @@ -146,7 +146,7 @@ void ModulatorState::process(const size_t samplesToDo, const al::span(mStep * td); mIndex &= WAVEFORM_FRACMASK; auto chandata = std::addressof(mChans[0]); diff --git a/alc/effects/pshifter.cpp b/alc/effects/pshifter.cpp index a4d66706..d7ba072e 100644 --- a/alc/effects/pshifter.cpp +++ b/alc/effects/pshifter.cpp @@ -57,7 +57,8 @@ std::array InitHannWindow() /* Create lookup table of the Hann window for the desired size, i.e. HIL_SIZE */ for(size_t i{0};i < STFT_SIZE>>1;i++) { - const double val{std::sin(al::MathDefs::Pi() * i / ALdouble{STFT_SIZE-1})}; + constexpr double scale{al::MathDefs::Pi() / double{STFT_SIZE-1}}; + const double val{std::sin(static_cast(i) * scale)}; ret[i] = ret[STFT_SIZE-1-i] = val * val; } return ret; @@ -129,7 +130,7 @@ ALboolean PshifterState::deviceUpdate(const ALCdevice *device) mCount = FIFO_LATENCY; mPitchShiftI = FRACTIONONE; mPitchShift = 1.0f; - mFreqPerBin = device->Frequency / static_cast(STFT_SIZE); + mFreqPerBin = static_cast(device->Frequency) / float{STFT_SIZE}; std::fill(std::begin(mInFIFO), std::end(mInFIFO), 0.0f); std::fill(std::begin(mOutFIFO), std::end(mOutFIFO), 0.0f); @@ -152,7 +153,7 @@ void PshifterState::update(const ALCcontext*, const ALeffectslot *slot, const Ef static_cast(props->Pshifter.CoarseTune*100 + props->Pshifter.FineTune) / 1200.0f )}; mPitchShiftI = fastf2u(pitch*FRACTIONONE); - mPitchShift = mPitchShiftI * (1.0f/FRACTIONONE); + mPitchShift = static_cast(mPitchShiftI) * (1.0f/FRACTIONONE); ALfloat coeffs[MAX_AMBI_CHANNELS]; CalcDirectionCoeffs({0.0f, 0.0f, -1.0f}, 0.0f, coeffs); @@ -187,7 +188,7 @@ void PshifterState::process(const size_t samplesToDo, const al::spanVmorpher.Waveform == AL_VOCAL_MORPHER_WAVEFORM_TRIANGLE)*/ mGetSamples = Oscillate; - const ALfloat pitchA{std::pow(2.0f, props->Vmorpher.PhonemeACoarseTuning / 12.0f)}; - const ALfloat pitchB{std::pow(2.0f, props->Vmorpher.PhonemeBCoarseTuning / 12.0f)}; + const ALfloat pitchA{std::pow(2.0f, + static_cast(props->Vmorpher.PhonemeACoarseTuning) / 12.0f)}; + const ALfloat pitchB{std::pow(2.0f, + static_cast(props->Vmorpher.PhonemeBCoarseTuning) / 12.0f)}; auto vowelA = getFiltersByPhoneme(props->Vmorpher.PhonemeA, frequency, pitchA); auto vowelB = getFiltersByPhoneme(props->Vmorpher.PhonemeB, frequency, pitchB); @@ -255,7 +257,7 @@ void VmorpherState::process(const size_t samplesToDo, const al::span(mStep * td); mIndex &= WAVEFORM_FRACMASK; auto chandata = std::addressof(mChans[0]); diff --git a/alc/hrtf.cpp b/alc/hrtf.cpp index bd6ecb3a..e20bf0a9 100644 --- a/alc/hrtf.cpp +++ b/alc/hrtf.cpp @@ -182,10 +182,11 @@ struct IdxBlend { ALsizei idx; ALfloat blend; }; */ IdxBlend CalcEvIndex(ALsizei evcount, ALfloat ev) { - ev = (al::MathDefs::Pi()*0.5f + ev) * (evcount-1) / al::MathDefs::Pi(); + ev = (al::MathDefs::Pi()*0.5f + ev) * static_cast(evcount-1) / + al::MathDefs::Pi(); ALsizei idx{float2int(ev)}; - return IdxBlend{mini(idx, evcount-1), ev-idx}; + return IdxBlend{mini(idx, evcount-1), ev-static_cast(idx)}; } /* Calculate the azimuth index given the polar azimuth in radians. This will @@ -193,10 +194,11 @@ IdxBlend CalcEvIndex(ALsizei evcount, ALfloat ev) */ IdxBlend CalcAzIndex(ALsizei azcount, ALfloat az) { - az = (al::MathDefs::Tau()+az) * azcount / al::MathDefs::Tau(); + az = (al::MathDefs::Tau()+az) * static_cast(azcount) / + al::MathDefs::Tau(); ALsizei idx{float2int(az)}; - return IdxBlend{idx%azcount, az-idx}; + return IdxBlend{idx%azcount, az-static_cast(idx)}; } } // namespace @@ -303,24 +305,25 @@ void BuildBFormatHrtf(const HrtfEntry *Hrtf, DirectHrtfState *state, const ALuin ASSUME(NumChannels > 0); ASSUME(AmbiCount > 0); - auto &field = Hrtf->field[0]; ALuint min_delay{HRTF_HISTORY_LENGTH}; ALuint max_delay{0}; auto idx = al::vector(AmbiCount); - auto calc_idxs = [Hrtf,&field,&max_delay,&min_delay](const AngularPoint &pt) noexcept -> ALuint + auto calc_idxs = [Hrtf,&max_delay,&min_delay](const AngularPoint &pt) noexcept -> ALuint { + auto &field = Hrtf->field[0]; /* Calculate elevation index. */ - const auto evidx = clampi(float2int((90.0f+pt.Elev)*(field.evCount-1)/180.0f + 0.5f), - 0, field.evCount-1); + const auto ev_limit = static_cast(field.evCount-1); + const ALuint evidx{float2uint(clampf((90.0f+pt.Elev)/180.0f, 0.0f, 1.0f)*ev_limit + 0.5f)}; const ALuint azcount{Hrtf->elev[evidx].azCount}; const ALuint iroffset{Hrtf->elev[evidx].irOffset}; /* Calculate azimuth index for this elevation. */ - const auto azidx = static_cast((360.0f+pt.Azim)*azcount/360.0f + 0.5f) % azcount; + const float az_norm{(360.0f*pt.Azim) / 360.0f}; + const ALuint azidx{float2uint(az_norm*static_cast(azcount) + 0.5f) % azcount}; /* Calculate the index for the impulse response. */ - ALuint idx{iroffset + azidx}; + const ALuint idx{iroffset + azidx}; min_delay = minu(min_delay, minu(Hrtf->delays[idx][0], Hrtf->delays[idx][1])); max_delay = maxu(max_delay, maxu(Hrtf->delays[idx][0], Hrtf->delays[idx][1])); @@ -594,7 +597,7 @@ std::unique_ptr LoadHrtf00(std::istream &data, const char *filename) if(failed) return nullptr; - al::vector evOffset(evCount); + auto evOffset = al::vector(evCount); for(auto &val : evOffset) val = GetLE_ALushort(data); if(!data || data.eof()) @@ -619,10 +622,10 @@ std::unique_ptr LoadHrtf00(std::istream &data, const char *filename) if(failed) return nullptr; - al::vector azCount(evCount); + auto azCount = al::vector(evCount); for(size_t i{1};i < evCount;i++) { - azCount[i-1] = evOffset[i] - evOffset[i-1]; + azCount[i-1] = static_cast(evOffset[i] - evOffset[i-1]); if(azCount[i-1] < MIN_AZ_COUNT || azCount[i-1] > MAX_AZ_COUNT) { ERR("Unsupported azimuth count: azCount[%zd]=%d (%d to %d)\n", @@ -630,7 +633,7 @@ std::unique_ptr LoadHrtf00(std::istream &data, const char *filename) failed = AL_TRUE; } } - azCount.back() = irCount - evOffset.back(); + azCount.back() = static_cast(irCount - evOffset.back()); if(azCount.back() < MIN_AZ_COUNT || azCount.back() > MAX_AZ_COUNT) { ERR("Unsupported azimuth count: azCount[%zu]=%d (%d to %d)\n", @@ -640,8 +643,8 @@ std::unique_ptr LoadHrtf00(std::istream &data, const char *filename) if(failed) return nullptr; - al::vector> coeffs(irSize*irCount); - al::vector> delays(irCount); + auto coeffs = al::vector>(irSize*irCount); + auto delays = al::vector>(irCount); for(auto &val : coeffs) val[0] = GetLE_ALshort(data) / 32768.0f; for(auto &val : delays) @@ -711,7 +714,7 @@ std::unique_ptr LoadHrtf01(std::istream &data, const char *filename) if(failed) return nullptr; - al::vector azCount(evCount); + auto azCount = al::vector(evCount); std::generate(azCount.begin(), azCount.end(), std::bind(GetLE_ALubyte, std::ref(data))); if(!data || data.eof()) { @@ -735,12 +738,12 @@ std::unique_ptr LoadHrtf01(std::istream &data, const char *filename) ALushort irCount{azCount[0]}; for(size_t i{1};i < evCount;i++) { - evOffset[i] = evOffset[i-1] + azCount[i-1]; + evOffset[i] = static_cast(evOffset[i-1] + azCount[i-1]); irCount += azCount[i]; } - al::vector> coeffs(irSize*irCount); - al::vector> delays(irCount); + auto coeffs = al::vector>(irSize*irCount); + auto delays = al::vector>(irCount); for(auto &val : coeffs) val[0] = GetLE_ALshort(data) / 32768.0f; for(auto &val : delays) @@ -903,7 +906,7 @@ std::unique_ptr LoadHrtf02(std::istream &data, const char *filename) else if(sampleType == SAMPLETYPE_S24) { for(auto &val : coeffs) - val[0] = GetLE_ALint24(data) / 8388608.0f; + val[0] = static_cast(GetLE_ALint24(data)) / 8388608.0f; } for(auto &val : delays) val[0] = GetLE_ALubyte(data); @@ -935,8 +938,8 @@ std::unique_ptr LoadHrtf02(std::istream &data, const char *filename) { for(auto &val : coeffs) { - val[0] = GetLE_ALint24(data) / 8388608.0f; - val[1] = GetLE_ALint24(data) / 8388608.0f; + val[0] = static_cast(GetLE_ALint24(data)) / 8388608.0f; + val[1] = static_cast(GetLE_ALint24(data)) / 8388608.0f; } } for(auto &val : delays) diff --git a/alc/mastering.cpp b/alc/mastering.cpp index 2f575f35..d0a2f78a 100644 --- a/alc/mastering.cpp +++ b/alc/mastering.cpp @@ -337,7 +337,7 @@ void SignalDelay(Compressor *Comp, const ALuint SamplesToDo, FloatBufferLine *Ou * ReleaseTimeMin - Release time (in seconds). Acts as a maximum when * automating release time. */ -std::unique_ptr CompressorInit(const ALuint NumChans, const ALuint SampleRate, +std::unique_ptr CompressorInit(const ALuint NumChans, const ALfloat SampleRate, const ALboolean AutoKnee, const ALboolean AutoAttack, const ALboolean AutoRelease, const ALboolean AutoPostGain, const ALboolean AutoDeclip, const ALfloat LookAheadTime, const ALfloat HoldTime, const ALfloat PreGainDb, const ALfloat PostGainDb, @@ -363,7 +363,6 @@ std::unique_ptr CompressorInit(const ALuint NumChans, const ALuint S auto Comp = std::unique_ptr{new (al_calloc(16, size)) Compressor{}}; Comp->mNumChans = NumChans; - Comp->mSampleRate = SampleRate; Comp->mAuto.Knee = AutoKnee != AL_FALSE; Comp->mAuto.Attack = AutoAttack != AL_FALSE; Comp->mAuto.Release = AutoRelease != AL_FALSE; diff --git a/alc/mastering.h b/alc/mastering.h index 6c8fc628..851381e9 100644 --- a/alc/mastering.h +++ b/alc/mastering.h @@ -24,7 +24,6 @@ struct SlidingHold; */ struct Compressor { ALuint mNumChans{0u}; - ALuint mSampleRate{0u}; struct { bool Knee : 1; @@ -94,7 +93,7 @@ struct Compressor { * ReleaseTimeMin - Release time (in seconds). Acts as a maximum when * automating release time. */ -std::unique_ptr CompressorInit(const ALuint NumChans, const ALuint SampleRate, +std::unique_ptr CompressorInit(const ALuint NumChans, const ALfloat SampleRate, const ALboolean AutoKnee, const ALboolean AutoAttack, const ALboolean AutoRelease, const ALboolean AutoPostGain, const ALboolean AutoDeclip, const ALfloat LookAheadTime, const ALfloat HoldTime, const ALfloat PreGainDb, const ALfloat PostGainDb, diff --git a/alc/mixer/mixer_c.cpp b/alc/mixer/mixer_c.cpp index 720b264b..74315dd5 100644 --- a/alc/mixer/mixer_c.cpp +++ b/alc/mixer/mixer_c.cpp @@ -16,9 +16,9 @@ namespace { inline ALfloat do_point(const InterpState&, const ALfloat *RESTRICT vals, const ALuint) { return vals[0]; } inline ALfloat do_lerp(const InterpState&, const ALfloat *RESTRICT vals, const ALuint frac) -{ return lerp(vals[0], vals[1], frac * (1.0f/FRACTIONONE)); } +{ return lerp(vals[0], vals[1], static_cast(frac)*(1.0f/FRACTIONONE)); } inline ALfloat do_cubic(const InterpState&, const ALfloat *RESTRICT vals, const ALuint frac) -{ return cubic(vals[0], vals[1], vals[2], vals[3], frac * (1.0f/FRACTIONONE)); } +{ return cubic(vals[0], vals[1], vals[2], vals[3], static_cast(frac)*(1.0f/FRACTIONONE)); } inline ALfloat do_bsinc(const InterpState &istate, const ALfloat *RESTRICT vals, const ALuint frac) { ASSUME(istate.bsinc.m > 0); @@ -26,10 +26,11 @@ inline ALfloat do_bsinc(const InterpState &istate, const ALfloat *RESTRICT vals, // Calculate the phase index and factor. #define FRAC_PHASE_BITDIFF (FRACTIONBITS-BSINC_PHASE_BITS) const ALuint pi{frac >> FRAC_PHASE_BITDIFF}; - const ALfloat pf{(frac & ((1<(frac & ((1<(istate.bsinc.m)*pi*4}; const ALfloat *scd{fil + istate.bsinc.m}; const ALfloat *phd{scd + istate.bsinc.m}; const ALfloat *spd{phd + istate.bsinc.m}; diff --git a/alc/mixer/mixer_neon.cpp b/alc/mixer/mixer_neon.cpp index 852bef38..2f11273a 100644 --- a/alc/mixer/mixer_neon.cpp +++ b/alc/mixer/mixer_neon.cpp @@ -55,10 +55,10 @@ const ALfloat *Resample_(const InterpState*, const ALfloat *RES if(dst_iter != dst.end()) { src += static_cast(vgetq_lane_s32(pos4, 0)); - frac = vgetq_lane_s32(frac4, 0); + frac = static_cast(vgetq_lane_s32(frac4, 0)); do { - *(dst_iter++) = lerp(src[0], src[1], frac * (1.0f/FRACTIONONE)); + *(dst_iter++) = lerp(src[0], src[1], static_cast(frac) * (1.0f/FRACTIONONE)); frac += increment; src += frac>>FRACTIONBITS; @@ -84,14 +84,15 @@ const ALfloat *Resample_(const InterpState *state, const ALflo // Calculate the phase index and factor. #define FRAC_PHASE_BITDIFF (FRACTIONBITS-BSINC_PHASE_BITS) const ALuint pi{frac >> FRAC_PHASE_BITDIFF}; - const ALfloat pf{(frac & ((1<(frac & ((1<(pi*4)}; const float *scd{fil + m}; const float *phd{scd + m}; const float *spd{phd + m}; @@ -179,8 +180,8 @@ void Mix_(const al::span InSamples, const al::span 0) ? 1.0f / static_cast(Counter) : 0.0f}; const bool reached_target{InSamples.size() >= Counter}; const auto min_end = reached_target ? InSamples.begin() + Counter : InSamples.end(); - const auto aligned_end = minz(InSamples.size(), (min_end-InSamples.begin()+3) & ~3u) + - InSamples.begin(); + const auto aligned_end = minz(static_cast(min_end-InSamples.begin()+3) & ~3u, + InSamples.size()) + InSamples.begin(); for(FloatBufferLine &output : OutBuffer) { ALfloat *RESTRICT dst{al::assume_aligned<16>(output.data()+OutPos)}; diff --git a/alc/mixer/mixer_sse.cpp b/alc/mixer/mixer_sse.cpp index 368b8dfe..65eb0dee 100644 --- a/alc/mixer/mixer_sse.cpp +++ b/alc/mixer/mixer_sse.cpp @@ -29,7 +29,8 @@ const ALfloat *Resample_(const InterpState *state, const ALfloa // Calculate the phase index and factor. #define FRAC_PHASE_BITDIFF (FRACTIONBITS-BSINC_PHASE_BITS) const ALuint pi{frac >> FRAC_PHASE_BITDIFF}; - const ALfloat pf{(frac & ((1<(frac & ((1<(const al::span InSamples, const al::span 0) ? 1.0f / static_cast(Counter) : 0.0f}; const bool reached_target{InSamples.size() >= Counter}; const auto min_end = reached_target ? InSamples.begin() + Counter : InSamples.end(); - const auto aligned_end = minz(InSamples.size(), (min_end-InSamples.begin()+3) & ~3u) + - InSamples.begin(); + const auto aligned_end = minz(static_cast(min_end-InSamples.begin()+3) & ~3u, + InSamples.size()) + InSamples.begin(); for(FloatBufferLine &output : OutBuffer) { ALfloat *RESTRICT dst{al::assume_aligned<16>(output.data()+OutPos)}; diff --git a/alc/mixer/mixer_sse2.cpp b/alc/mixer/mixer_sse2.cpp index 38d77fd9..897cd1f7 100644 --- a/alc/mixer/mixer_sse2.cpp +++ b/alc/mixer/mixer_sse2.cpp @@ -72,7 +72,7 @@ const ALfloat *Resample_(const InterpState*, const ALfloat *RES frac = static_cast(_mm_cvtsi128_si32(frac4)); do { - *(dst_iter++) = lerp(src[0], src[1], frac * (1.0f/FRACTIONONE)); + *(dst_iter++) = lerp(src[0], src[1], static_cast(frac) * (1.0f/FRACTIONONE)); frac += increment; src += frac>>FRACTIONBITS; diff --git a/alc/mixer/mixer_sse41.cpp b/alc/mixer/mixer_sse41.cpp index 0a87f76f..cfa21e99 100644 --- a/alc/mixer/mixer_sse41.cpp +++ b/alc/mixer/mixer_sse41.cpp @@ -77,7 +77,7 @@ const ALfloat *Resample_(const InterpState*, const ALfloat *RES frac = static_cast(_mm_cvtsi128_si32(frac4)); do { - *(dst_iter++) = lerp(src[0], src[1], frac * (1.0f/FRACTIONONE)); + *(dst_iter++) = lerp(src[0], src[1], static_cast(frac) * (1.0f/FRACTIONONE)); frac += increment; src += frac>>FRACTIONBITS; diff --git a/alc/mixvoice.cpp b/alc/mixvoice.cpp index 7bdeea5e..d7a32f35 100644 --- a/alc/mixvoice.cpp +++ b/alc/mixvoice.cpp @@ -287,33 +287,35 @@ struct FmtTypeTraits { }; template<> struct FmtTypeTraits { using Type = ALubyte; - static constexpr ALfloat to_float(const Type val) { return (val-128) * (1.0f/128.0f); } + static constexpr ALfloat to_float(const Type val) noexcept + { return val*(1.0f/128.0f) - 128.0f; } }; template<> struct FmtTypeTraits { using Type = ALshort; - static constexpr ALfloat to_float(const Type val) { return val * (1.0f/32768.0f); } + static constexpr ALfloat to_float(const Type val) noexcept { return val*(1.0f/32768.0f); } }; template<> struct FmtTypeTraits { using Type = ALfloat; - static constexpr ALfloat to_float(const Type val) { return val; } + static constexpr ALfloat to_float(const Type val) noexcept { return val; } }; template<> struct FmtTypeTraits { using Type = ALdouble; - static constexpr ALfloat to_float(const Type val) { return static_cast(val); } + static constexpr ALfloat to_float(const Type val) noexcept + { return static_cast(val); } }; template<> struct FmtTypeTraits { using Type = ALubyte; - static constexpr ALfloat to_float(const Type val) + static constexpr ALfloat to_float(const Type val) noexcept { return muLawDecompressionTable[val] * (1.0f/32768.0f); } }; template<> struct FmtTypeTraits { using Type = ALubyte; - static constexpr ALfloat to_float(const Type val) + static constexpr ALfloat to_float(const Type val) noexcept { return aLawDecompressionTable[val] * (1.0f/32768.0f); } }; @@ -363,7 +365,7 @@ const ALfloat *DoFilters(BiquadFilter *lpfilter, BiquadFilter *hpfilter, ALfloat template inline void LoadSampleArray(ALfloat *RESTRICT dst, const al::byte *src, const size_t srcstep, - const size_t samples) + const size_t samples) noexcept { using SampleType = typename FmtTypeTraits::Type; @@ -373,7 +375,7 @@ inline void LoadSampleArray(ALfloat *RESTRICT dst, const al::byte *src, const si } void LoadSamples(ALfloat *RESTRICT dst, const al::byte *src, const size_t srcstep, FmtType srctype, - const size_t samples) + const size_t samples) noexcept { #define HANDLE_FMT(T) case T: LoadSampleArray(dst, src, srcstep, samples); break switch(srctype) diff --git a/common/almalloc.cpp b/common/almalloc.cpp index 8700bddc..842fb400 100644 --- a/common/almalloc.cpp +++ b/common/almalloc.cpp @@ -30,11 +30,11 @@ void *al_malloc(size_t alignment, size_t size) #elif defined(HAVE__ALIGNED_MALLOC) return _aligned_malloc(size, alignment); #else - char *ret = static_cast(malloc(size+alignment)); + auto *ret = static_cast(malloc(size+alignment)); if(ret != nullptr) { *(ret++) = 0x00; - while((reinterpret_cast(ret)&(alignment-1)) != 0) + while((reinterpret_cast(ret)&(alignment-1)) != 0) *(ret++) = 0x55; } return ret; @@ -57,7 +57,7 @@ void al_free(void *ptr) noexcept #else if(ptr != nullptr) { - char *finder = static_cast(ptr); + auto *finder = static_cast(ptr); do { --finder; } while(*finder == 0x55); diff --git a/examples/alrecord.c b/examples/alrecord.c index 627f8540..a66e5471 100644 --- a/examples/alrecord.c +++ b/examples/alrecord.c @@ -54,13 +54,14 @@ static float msvc_strtof(const char *str, char **end) static void fwrite16le(ALushort val, FILE *f) { - ALubyte data[2] = { val&0xff, (val>>8)&0xff }; + ALubyte data[2] = { (ALubyte)(val&0xff), (ALubyte)((val>>8)&0xff) }; fwrite(data, 1, 2, f); } static void fwrite32le(ALuint val, FILE *f) { - ALubyte data[4] = { val&0xff, (val>>8)&0xff, (val>>16)&0xff, (val>>24)&0xff }; + ALubyte data[4] = { (ALubyte)(val&0xff), (ALubyte)((val>>8)&0xff), (ALubyte)((val>>16)&0xff), + (ALubyte)((val>>24)&0xff) }; fwrite(data, 1, 4, f); } diff --git a/examples/altonegen.c b/examples/altonegen.c index aacc3496..26ae788d 100644 --- a/examples/altonegen.c +++ b/examples/altonegen.c @@ -97,7 +97,7 @@ static ALuint CreateWave(enum WaveType type, ALuint freq, ALuint srate) ALenum err; ALuint i; - data_size = srate * sizeof(ALfloat); + data_size = (ALuint)(srate * sizeof(ALfloat)); data = calloc(1, data_size); switch(type) { diff --git a/examples/common/alhelpers.c b/examples/common/alhelpers.c index 730d2e13..0febef43 100644 --- a/examples/common/alhelpers.c +++ b/examples/common/alhelpers.c @@ -175,8 +175,8 @@ int altime_get(void) void al_nssleep(unsigned long nsec) { struct timespec ts, rem; - ts.tv_sec = nsec / 1000000000ul; - ts.tv_nsec = nsec % 1000000000ul; + ts.tv_sec = (time_t)(nsec / 1000000000ul); + ts.tv_nsec = (long)(nsec % 1000000000ul); while(nanosleep(&ts, &rem) == -1 && errno == EINTR) ts = rem; } -- cgit v1.2.3 From 807d3b64cac2793ce678acb3fc4d4191b2252875 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 14 Sep 2019 18:27:57 -0700 Subject: Enable and fix more warnings --- CMakeLists.txt | 7 ++----- al/event.cpp | 18 +++++------------- al/source.cpp | 30 ++++++++++++++++-------------- alc/alc.cpp | 8 ++++---- alc/alconfig.cpp | 12 ++++++------ alc/backends/base.h | 2 ++ alc/backends/pulseaudio.cpp | 2 +- alc/filters/biquad.cpp | 28 ++++++++++++++-------------- alc/filters/biquad.h | 32 +++++++++++++++----------------- alc/filters/splitter.cpp | 44 ++++++++++++++++++++++---------------------- alc/filters/splitter.h | 10 +++++----- alc/hrtf.cpp | 8 ++++---- alc/hrtf.h | 2 +- alc/mixvoice.cpp | 29 +++++++++++++++-------------- utils/makemhr/loaddef.cpp | 9 ++++----- utils/makemhr/loadsofa.cpp | 10 +++------- utils/sofa-info.cpp | 10 +++------- 17 files changed, 122 insertions(+), 139 deletions(-) (limited to 'al/source.cpp') diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ec17ce5..44d829d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -220,11 +220,8 @@ IF(MSVC) ENDFOREACH(flag_var) ENDIF() ELSE() - SET(C_FLAGS ${C_FLAGS} -Winline -Wall $<$:-Wold-style-cast> -Wconversion) - CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA) - IF(HAVE_W_EXTRA) - SET(C_FLAGS ${C_FLAGS} -Wextra) - ENDIF() + SET(C_FLAGS ${C_FLAGS} -Winline -Wall -Wextra -Wshadow -Wconversion -Wcast-align + $<$:-Wold-style-cast -Wnon-virtual-dtor -Woverloaded-virtual>) IF(ALSOFT_WERROR) SET(C_FLAGS ${C_FLAGS} -Werror) diff --git a/al/event.cpp b/al/event.cpp index 2832ace7..0da48cbf 100644 --- a/al/event.cpp +++ b/al/event.cpp @@ -44,21 +44,13 @@ static int EventThread(ALCcontext *context) std::lock_guard _{context->mEventCbLock}; do { - auto &evt = *reinterpret_cast(evt_data.buf); + auto *evt_ptr = reinterpret_cast(evt_data.buf); evt_data.buf += sizeof(AsyncEvent); evt_data.len -= 1; - /* This automatically destructs the event object and advances the - * ringbuffer's read offset at the end of scope. - */ - const struct EventAutoDestructor { - AsyncEvent &evt_; - RingBuffer *ring_; - ~EventAutoDestructor() - { - al::destroy_at(std::addressof(evt_)); - ring_->readAdvance(1); - } - } _{evt, ring}; + + AsyncEvent evt{*evt_ptr}; + al::destroy_at(evt_ptr); + ring->readAdvance(1); quitnow = evt.EnumType == EventType_KillThread; if UNLIKELY(quitnow) break; diff --git a/al/source.cpp b/al/source.cpp index 733758f7..f8d5fbcd 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -1199,7 +1199,7 @@ bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a std::unique_ptr temp{oldlist}; oldlist = temp->mNext.load(std::memory_order_relaxed); - if(ALbuffer *buffer{temp->mBuffer}) + if((buffer=temp->mBuffer) != nullptr) DecrementRef(buffer->ref); } return true; @@ -1215,7 +1215,6 @@ bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a if(IsPlayingOrPaused(Source)) { - ALCdevice *device{Context->mDevice.get()}; BackendLockGuard _{*device->Backend}; if(ALvoice *voice{GetSourceVoice(Source, Context)}) { @@ -1347,8 +1346,8 @@ bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a { /* Add refcount on the new slot, and release the previous slot */ if(slot) IncrementRef(slot->ref); - if(auto *slot = Source->Send[static_cast(values[1])].Slot) - DecrementRef(slot->ref); + if(auto *oldslot = Source->Send[static_cast(values[1])].Slot) + DecrementRef(oldslot->ref); Source->Send[static_cast(values[1])].Slot = slot; /* We must force an update if the auxiliary slot changed on an @@ -1361,8 +1360,8 @@ bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a else { if(slot) IncrementRef(slot->ref); - if(auto *slot = Source->Send[static_cast(values[1])].Slot) - DecrementRef(slot->ref); + if(auto *oldslot = Source->Send[static_cast(values[1])].Slot) + DecrementRef(oldslot->ref); Source->Send[static_cast(values[1])].Slot = slot; UpdateSourceProps(Source, Context); } @@ -1730,7 +1729,6 @@ bool GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a bool GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const al::span values) { - ALbufferlistitem *BufferList; ALdouble dvals[MaxValues]; bool err; @@ -1748,9 +1746,13 @@ bool GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a case AL_BUFFER: CHECKSIZE(values, 1); - BufferList = (Source->SourceType == AL_STATIC) ? Source->queue : nullptr; - values[0] = (BufferList && BufferList->mBuffer) ? - static_cast(BufferList->mBuffer->id) : 0; + { + ALbufferlistitem *BufferList{nullptr}; + if(Source->SourceType == AL_STATIC) BufferList = Source->queue; + ALbuffer *buffer{nullptr}; + if(BufferList) buffer = BufferList->mBuffer; + values[0] = buffer ? static_cast(buffer->id) : 0; + } return true; case AL_SOURCE_STATE: @@ -1760,9 +1762,7 @@ bool GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a case AL_BUFFERS_QUEUED: CHECKSIZE(values, 1); - if(!(BufferList=Source->queue)) - values[0] = 0; - else + if(ALbufferlistitem *BufferList{Source->queue}) { ALsizei count{0}; do { @@ -1771,6 +1771,8 @@ bool GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a } while(BufferList != nullptr); values[0] = count; } + else + values[0] = 0; return true; case AL_BUFFERS_PROCESSED: @@ -3135,7 +3137,7 @@ START_API_FUNC { std::unique_ptr head{BufferListStart}; BufferListStart = head->mNext.load(std::memory_order_relaxed); - if(ALbuffer *buffer{head->mBuffer}) DecrementRef(buffer->ref); + if((buffer=head->mBuffer) != nullptr) DecrementRef(buffer->ref); } return; } diff --git a/alc/alc.cpp b/alc/alc.cpp index 8e9d3963..fa88cba8 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -3731,11 +3731,11 @@ START_API_FUNC al::vector orphanctxs; for(ALCcontext *ctx : *dev->mContexts.load()) { - auto iter = std::lower_bound(ContextList.begin(), ContextList.end(), ctx); - if(iter != ContextList.end() && *iter == ctx) + auto ctxiter = std::lower_bound(ContextList.begin(), ContextList.end(), ctx); + if(ctxiter != ContextList.end() && *ctxiter == ctx) { - orphanctxs.emplace_back(std::move(*iter)); - ContextList.erase(iter); + orphanctxs.emplace_back(std::move(*ctxiter)); + ContextList.erase(ctxiter); } } listlock.unlock(); diff --git a/alc/alconfig.cpp b/alc/alconfig.cpp index 8ca81bc8..666c2c2d 100644 --- a/alc/alconfig.cpp +++ b/alc/alconfig.cpp @@ -359,7 +359,7 @@ void ReadALConfig() else fname += "alsoft.conf"; TRACE("Loading config %s...\n", fname.c_str()); - al::ifstream f{fname}; + f = al::ifstream{fname}; if(f.is_open()) LoadConfigFromFile(f); } @@ -376,7 +376,7 @@ void ReadALConfig() if((configURL=CFBundleCopyResourceURL(mainBundle, CFSTR(".alsoftrc"), CFSTR(""), nullptr)) && CFURLGetFileSystemRepresentation(configURL, true, fileName, sizeof(fileName))) { - al::ifstream f{reinterpret_cast(fileName)}; + f = al::ifstream{reinterpret_cast(fileName)}; if(f.is_open()) LoadConfigFromFile(f); } @@ -390,7 +390,7 @@ void ReadALConfig() else fname += ".alsoftrc"; TRACE("Loading config %s...\n", fname.c_str()); - al::ifstream f{fname}; + f = al::ifstream{fname}; if(f.is_open()) LoadConfigFromFile(f); } @@ -414,7 +414,7 @@ void ReadALConfig() if(!fname.empty()) { TRACE("Loading config %s...\n", fname.c_str()); - al::ifstream f{fname}; + f = al::ifstream{fname}; if(f.is_open()) LoadConfigFromFile(f); } @@ -426,7 +426,7 @@ void ReadALConfig() else ppath += "alsoft.conf"; TRACE("Loading config %s...\n", ppath.c_str()); - al::ifstream f{ppath}; + f = al::ifstream{ppath}; if(f.is_open()) LoadConfigFromFile(f); } @@ -434,7 +434,7 @@ void ReadALConfig() if(auto confname = al::getenv("ALSOFT_CONF")) { TRACE("Loading config %s...\n", confname->c_str()); - al::ifstream f{*confname}; + f = al::ifstream{*confname}; if(f.is_open()) LoadConfigFromFile(f); } diff --git a/alc/backends/base.h b/alc/backends/base.h index 5e294fe8..e88734dc 100644 --- a/alc/backends/base.h +++ b/alc/backends/base.h @@ -68,6 +68,8 @@ enum class DevProbe { struct BackendFactory { + virtual ~BackendFactory() = default; + virtual bool init() = 0; virtual bool querySupport(BackendType type) = 0; diff --git a/alc/backends/pulseaudio.cpp b/alc/backends/pulseaudio.cpp index 9c54c07b..23d4e71a 100644 --- a/alc/backends/pulseaudio.cpp +++ b/alc/backends/pulseaudio.cpp @@ -484,7 +484,7 @@ pa_stream *pulse_connect_stream(const char *device_name, std::unique_lock::setParams(BiquadType type, Real gain, Real f0norm, Rea break; } - a1 = a[1] / a[0]; - a2 = a[2] / a[0]; - b0 = b[0] / a[0]; - b1 = b[1] / a[0]; - b2 = b[2] / a[0]; + mA1 = a[1] / a[0]; + mA2 = a[2] / a[0]; + mB0 = b[0] / a[0]; + mB1 = b[1] / a[0]; + mB2 = b[2] / a[0]; } template @@ -93,13 +93,13 @@ void BiquadFilterR::process(Real *dst, const Real *src, const size_t numsa { ASSUME(numsamples > 0); - const Real b0{this->b0}; - const Real b1{this->b1}; - const Real b2{this->b2}; - const Real a1{this->a1}; - const Real a2{this->a2}; - Real z1{this->z1}; - Real z2{this->z2}; + const Real b0{mB0}; + const Real b1{mB1}; + const Real b2{mB2}; + const Real a1{mA1}; + const Real a2{mA2}; + Real z1{mZ1}; + Real z2{mZ2}; /* Processing loop is Transposed Direct Form II. This requires less storage * compared to Direct Form I (only two delay components, instead of a four- @@ -118,8 +118,8 @@ void BiquadFilterR::process(Real *dst, const Real *src, const size_t numsa }; std::transform(src, src+numsamples, dst, proc_sample); - this->z1 = z1; - this->z2 = z2; + mZ1 = z1; + mZ2 = z2; } template class BiquadFilterR; diff --git a/alc/filters/biquad.h b/alc/filters/biquad.h index 9de86f2f..9af954ae 100644 --- a/alc/filters/biquad.h +++ b/alc/filters/biquad.h @@ -38,14 +38,14 @@ enum class BiquadType { template class BiquadFilterR { /* Last two delayed components for direct form II. */ - Real z1{0.0f}, z2{0.0f}; + Real mZ1{0.0f}, mZ2{0.0f}; /* Transfer function coefficients "b" (numerator) */ - Real b0{1.0f}, b1{0.0f}, b2{0.0f}; + Real mB0{1.0f}, mB1{0.0f}, mB2{0.0f}; /* Transfer function coefficients "a" (denominator; a0 is pre-applied). */ - Real a1{0.0f}, a2{0.0f}; + Real mA1{0.0f}, mA2{0.0f}; public: - void clear() noexcept { z1 = z2 = 0.0f; } + void clear() noexcept { mZ1 = mZ2 = 0.0f; } /** * Sets the filter state for the specified filter type and its parameters. @@ -65,26 +65,24 @@ public: void copyParamsFrom(const BiquadFilterR &other) { - b0 = other.b0; - b1 = other.b1; - b2 = other.b2; - a1 = other.a1; - a2 = other.a2; + mB0 = other.mB0; + mB1 = other.mB1; + mB2 = other.mB2; + mA1 = other.mA1; + mA2 = other.mA2; } void process(Real *dst, const Real *src, const size_t numsamples); /* Rather hacky. It's just here to support "manual" processing. */ - std::pair getComponents() const noexcept - { return {z1, z2}; } - void setComponents(Real z1_, Real z2_) noexcept - { z1 = z1_; z2 = z2_; } - Real processOne(const Real in, Real &z1_, Real &z2_) const noexcept + std::pair getComponents() const noexcept { return {mZ1, mZ2}; } + void setComponents(Real z1, Real z2) noexcept { mZ1 = z1; mZ2 = z2; } + Real processOne(const Real in, Real &z1, Real &z2) const noexcept { - Real out{in*b0 + z1_}; - z1_ = in*b1 - out*a1 + z2_; - z2_ = in*b2 - out*a2; + Real out{in*mB0 + z1}; + z1 = in*mB1 - out*mA1 + z2; + z2 = in*mB2 - out*mA2; return out; } diff --git a/alc/filters/splitter.cpp b/alc/filters/splitter.cpp index 66806ea9..c6218e70 100644 --- a/alc/filters/splitter.cpp +++ b/alc/filters/splitter.cpp @@ -17,13 +17,13 @@ void BandSplitterR::init(Real f0norm) const Real w{f0norm * al::MathDefs::Tau()}; const Real cw{std::cos(w)}; if(cw > std::numeric_limits::epsilon()) - coeff = (std::sin(w) - 1.0f) / cw; + mCoeff = (std::sin(w) - 1.0f) / cw; else - coeff = cw * -0.5f; + mCoeff = cw * -0.5f; - lp_z1 = 0.0f; - lp_z2 = 0.0f; - ap_z1 = 0.0f; + mLpZ1 = 0.0f; + mLpZ2 = 0.0f; + mApZ1 = 0.0f; } template @@ -31,11 +31,11 @@ void BandSplitterR::process(Real *hpout, Real *lpout, const Real *input, c { ASSUME(count > 0); - const Real ap_coeff{this->coeff}; - const Real lp_coeff{this->coeff*0.5f + 0.5f}; - Real lp_z1{this->lp_z1}; - Real lp_z2{this->lp_z2}; - Real ap_z1{this->ap_z1}; + const Real ap_coeff{mCoeff}; + const Real lp_coeff{mCoeff*0.5f + 0.5f}; + Real lp_z1{mLpZ1}; + Real lp_z2{mLpZ2}; + Real ap_z1{mApZ1}; auto proc_sample = [ap_coeff,lp_coeff,&lp_z1,&lp_z2,&ap_z1,&lpout](const Real in) noexcept -> Real { /* Low-pass sample processing. */ @@ -57,9 +57,9 @@ void BandSplitterR::process(Real *hpout, Real *lpout, const Real *input, c return ap_y - lp_y; }; std::transform(input, input+count, hpout, proc_sample); - this->lp_z1 = lp_z1; - this->lp_z2 = lp_z2; - this->ap_z1 = ap_z1; + mLpZ1 = lp_z1; + mLpZ2 = lp_z2; + mApZ1 = ap_z1; } template @@ -67,11 +67,11 @@ void BandSplitterR::applyHfScale(Real *samples, const Real hfscale, const { ASSUME(count > 0); - const Real ap_coeff{this->coeff}; - const Real lp_coeff{this->coeff*0.5f + 0.5f}; - Real lp_z1{this->lp_z1}; - Real lp_z2{this->lp_z2}; - Real ap_z1{this->ap_z1}; + const Real ap_coeff{mCoeff}; + const Real lp_coeff{mCoeff*0.5f + 0.5f}; + Real lp_z1{mLpZ1}; + Real lp_z2{mLpZ2}; + Real ap_z1{mApZ1}; auto proc_sample = [hfscale,ap_coeff,lp_coeff,&lp_z1,&lp_z2,&ap_z1](const Real in) noexcept -> Real { /* Low-pass sample processing. */ @@ -91,9 +91,9 @@ void BandSplitterR::applyHfScale(Real *samples, const Real hfscale, const return (ap_y-lp_y)*hfscale + lp_y; }; std::transform(samples, samples+count, samples, proc_sample); - this->lp_z1 = lp_z1; - this->lp_z2 = lp_z2; - this->ap_z1 = ap_z1; + mLpZ1 = lp_z1; + mLpZ2 = lp_z2; + mApZ1 = ap_z1; } template @@ -101,7 +101,7 @@ void BandSplitterR::applyAllpass(Real *samples, const size_t count) const { ASSUME(count > 0); - const Real coeff{this->coeff}; + const Real coeff{mCoeff}; Real z1{0.0f}; auto proc_sample = [coeff,&z1](const Real in) noexcept -> Real { diff --git a/alc/filters/splitter.h b/alc/filters/splitter.h index b024f0c3..5117a244 100644 --- a/alc/filters/splitter.h +++ b/alc/filters/splitter.h @@ -7,10 +7,10 @@ /* Band splitter. Splits a signal into two phase-matching frequency bands. */ template class BandSplitterR { - Real coeff{0.0f}; - Real lp_z1{0.0f}; - Real lp_z2{0.0f}; - Real ap_z1{0.0f}; + Real mCoeff{0.0f}; + Real mLpZ1{0.0f}; + Real mLpZ2{0.0f}; + Real mApZ1{0.0f}; public: BandSplitterR() = default; @@ -18,7 +18,7 @@ public: BandSplitterR(Real f0norm) { init(f0norm); } void init(Real f0norm); - void clear() noexcept { lp_z1 = lp_z2 = ap_z1 = 0.0f; } + void clear() noexcept { mLpZ1 = mLpZ2 = mApZ1 = 0.0f; } void process(Real *hpout, Real *lpout, const Real *input, const size_t count); void applyHfScale(Real *samples, const Real hfscale, const size_t count); diff --git a/alc/hrtf.cpp b/alc/hrtf.cpp index e20bf0a9..3d2f36ea 100644 --- a/alc/hrtf.cpp +++ b/alc/hrtf.cpp @@ -475,7 +475,7 @@ std::unique_ptr CreateHrtfStore(ALuint rate, ALushort irSize, const A ERR("Out of memory allocating storage for %s.\n", filename); else { - InitRef(Hrtf->ref, 1u); + InitRef(Hrtf->mRef, 1u); Hrtf->sampleRate = rate; Hrtf->irSize = irSize; Hrtf->fdCount = fdCount; @@ -1362,13 +1362,13 @@ HrtfEntry *GetLoadedHrtf(HrtfHandle *handle) void HrtfEntry::IncRef() { - auto ref = IncrementRef(this->ref); + auto ref = IncrementRef(mRef); TRACE("HrtfEntry %p increasing refcount to %u\n", this, ref); } void HrtfEntry::DecRef() { - auto ref = DecrementRef(this->ref); + auto ref = DecrementRef(mRef); TRACE("HrtfEntry %p decreasing refcount to %u\n", this, ref); if(ref == 0) { @@ -1378,7 +1378,7 @@ void HrtfEntry::DecRef() auto delete_unused = [](HrtfHandlePtr &handle) -> void { HrtfEntry *entry{handle->entry.get()}; - if(entry && ReadRef(entry->ref) == 0) + if(entry && ReadRef(entry->mRef) == 0) { TRACE("Unloading unused HRTF %s\n", handle->filename.data()); handle->entry = nullptr; diff --git a/alc/hrtf.h b/alc/hrtf.h index 92b3fd96..20b3409d 100644 --- a/alc/hrtf.h +++ b/alc/hrtf.h @@ -26,7 +26,7 @@ struct HrtfHandle; struct HrtfEntry { - RefCount ref; + RefCount mRef; ALuint sampleRate; ALuint irSize; diff --git a/alc/mixvoice.cpp b/alc/mixvoice.cpp index d7a32f35..2b5972f3 100644 --- a/alc/mixvoice.cpp +++ b/alc/mixvoice.cpp @@ -405,24 +405,24 @@ ALfloat *LoadBufferStatic(ALbufferlistitem *BufferListItem, ALbufferlistitem *&B BufferLoopItem = nullptr; /* Load what's left to play from the buffer */ - const size_t DataSize{minz(SrcBuffer.size(), Buffer->SampleLen-DataPosInt)}; + const size_t DataRem{minz(SrcBuffer.size(), Buffer->SampleLen-DataPosInt)}; const al::byte *Data{Buffer->mData.data()}; Data += (DataPosInt*NumChannels + chan)*SampleSize; - LoadSamples(SrcBuffer.data(), Data, NumChannels, Buffer->mFmtType, DataSize); - SrcBuffer = SrcBuffer.subspan(DataSize); + LoadSamples(SrcBuffer.data(), Data, NumChannels, Buffer->mFmtType, DataRem); + SrcBuffer = SrcBuffer.subspan(DataRem); } else { /* Load what's left of this loop iteration */ - const size_t DataSize{minz(SrcBuffer.size(), LoopEnd-DataPosInt)}; + const size_t DataRem{minz(SrcBuffer.size(), LoopEnd-DataPosInt)}; const al::byte *Data{Buffer->mData.data()}; Data += (DataPosInt*NumChannels + chan)*SampleSize; - LoadSamples(SrcBuffer.data(), Data, NumChannels, Buffer->mFmtType, DataSize); - SrcBuffer = SrcBuffer.subspan(DataSize); + LoadSamples(SrcBuffer.data(), Data, NumChannels, Buffer->mFmtType, DataRem); + SrcBuffer = SrcBuffer.subspan(DataRem); /* Load any repeats of the loop we can to fill the buffer. */ const auto LoopSize = static_cast(LoopEnd - LoopStart); @@ -430,8 +430,7 @@ ALfloat *LoadBufferStatic(ALbufferlistitem *BufferListItem, ALbufferlistitem *&B { const size_t DataSize{minz(SrcBuffer.size(), LoopSize)}; - const al::byte *Data{Buffer->mData.data()}; - Data += (LoopStart*NumChannels + chan)*SampleSize; + Data = Buffer->mData.data() + (LoopStart*NumChannels + chan)*SampleSize; LoadSamples(SrcBuffer.data(), Data, NumChannels, Buffer->mFmtType, DataSize); SrcBuffer = SrcBuffer.subspan(DataSize); @@ -510,12 +509,14 @@ void ALvoice::mix(State vstate, ALCcontext *Context, const ALuint SamplesToDo) for(ALuint chan{0};chan < NumChannels;chan++) { ChannelData &chandata = mChans[chan]; - DirectParams &parms = chandata.mDryParams; - if(!(mFlags&VOICE_HAS_HRTF)) - std::copy(std::begin(parms.Gains.Target), std::end(parms.Gains.Target), - std::begin(parms.Gains.Current)); - else - parms.Hrtf.Old = parms.Hrtf.Target; + { + DirectParams &parms = chandata.mDryParams; + if(!(mFlags&VOICE_HAS_HRTF)) + std::copy(std::begin(parms.Gains.Target), std::end(parms.Gains.Target), + std::begin(parms.Gains.Current)); + else + parms.Hrtf.Old = parms.Hrtf.Target; + } for(ALuint send{0};send < NumSends;++send) { if(mSend[send].Buffer.empty()) diff --git a/utils/makemhr/loaddef.cpp b/utils/makemhr/loaddef.cpp index 5f6d76d8..aaefd62c 100644 --- a/utils/makemhr/loaddef.cpp +++ b/utils/makemhr/loaddef.cpp @@ -1737,7 +1737,7 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData) hData->mHrirsBase.resize(channels * hData->mIrCount * hData->mIrSize); double *hrirs = hData->mHrirsBase.data(); std::vector hrir(hData->mIrPoints); - uint line, col, fi, ei, ai, ti; + uint line, col, fi, ei, ai; int count; printf("Loading sources..."); @@ -1827,8 +1827,7 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData) for(fi = 0;fi < hData->mFdCount;fi++) { double delta = aer[2] - hData->mFds[fi].mDistance; - if(std::abs(delta) < 0.001) - break; + if(std::abs(delta) < 0.001) break; } if(fi >= hData->mFdCount) continue; @@ -1892,7 +1891,6 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData) for(;;) { SourceRefT src; - uint ti = 0; if(!ReadSourceRef(tr, &src)) return 0; @@ -1907,6 +1905,7 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData) if(!LoadSource(&src, hData->mIrRate, hData->mIrPoints, hrir.data())) return 0; + uint ti{0}; if(hData->mChannelType == CT_STEREO) { char ident[MAX_IDENT_LEN+1]; @@ -1976,7 +1975,7 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData) } } } - for(ti = 0;ti < channels;ti++) + for(uint ti{0};ti < channels;ti++) { for(fi = 0;fi < hData->mFdCount;fi++) { diff --git a/utils/makemhr/loadsofa.cpp b/utils/makemhr/loadsofa.cpp index 02911e12..219eb558 100644 --- a/utils/makemhr/loadsofa.cpp +++ b/utils/makemhr/loadsofa.cpp @@ -101,7 +101,6 @@ static float GetUniformStepSize(const double epsilon, const uint m, const float { auto steps = std::vector(m, 0.0f); auto counts = std::vector(m, 0u); - float step{0.0f}; uint count{0u}; for(uint stride{1u};stride < m/2;stride++) @@ -140,15 +139,12 @@ static float GetUniformStepSize(const double epsilon, const uint m, const float count = 1; if(counts[0] > m/2) - { - step = steps[0]; - return step; - } + return steps[0]; } if(counts[0] > 5) - step = steps[0]; - return step; + return steps[0]; + return 0.0f; } /* Attempts to produce a compatible layout. Most data sets tend to be diff --git a/utils/sofa-info.cpp b/utils/sofa-info.cpp index e9f2257c..87531b37 100644 --- a/utils/sofa-info.cpp +++ b/utils/sofa-info.cpp @@ -136,7 +136,6 @@ static float GetUniformStepSize(const float epsilon, const uint m, const float * { std::vector steps(m, 0.0f); std::vector counts(m, 0u); - float step{0.0f}; uint count{0u}; for(uint stride{1u};stride < m/2;stride++) @@ -175,15 +174,12 @@ static float GetUniformStepSize(const float epsilon, const uint m, const float * count = 1; if(counts[0] > m/2) - { - step = steps[0]; - return step; - } + return steps[0]; } if(counts[0] > 5) - step = steps[0]; - return step; + return steps[0]; + return 0.0f; } /* Attempts to produce a compatible layout. Most data sets tend to be -- cgit v1.2.3 From e4cc77ea237c8a2ca67cb0a1cb28e6d652746590 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 14 Sep 2019 20:19:59 -0700 Subject: Fix a few warnings from MSVC --- al/source.cpp | 12 ++++++------ alc/effects/compressor.cpp | 2 +- alc/effects/reverb.cpp | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'al/source.cpp') diff --git a/al/source.cpp b/al/source.cpp index f8d5fbcd..53d2a705 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -1126,14 +1126,14 @@ bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a CHECKSIZE(values, 1); CHECKVAL(values[0] == AL_FALSE || values[0] == AL_TRUE); - Source->HeadRelative = static_cast(values[0]); + Source->HeadRelative = values[0] != AL_FALSE; return UpdateSourceProps(Source, Context); case AL_LOOPING: CHECKSIZE(values, 1); CHECKVAL(values[0] == AL_FALSE || values[0] == AL_TRUE); - Source->Looping = static_cast(values[0]); + Source->Looping = values[0] != AL_FALSE; if(IsPlayingOrPaused(Source)) { if(ALvoice *voice{GetSourceVoice(Source, Context)}) @@ -1258,28 +1258,28 @@ bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a CHECKSIZE(values, 1); CHECKVAL(values[0] == AL_FALSE || values[0] == AL_TRUE); - Source->DryGainHFAuto = values[0]; + Source->DryGainHFAuto = values[0] != AL_FALSE; return UpdateSourceProps(Source, Context); case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO: CHECKSIZE(values, 1); CHECKVAL(values[0] == AL_FALSE || values[0] == AL_TRUE); - Source->WetGainAuto = values[0]; + Source->WetGainAuto = values[0] != AL_FALSE; return UpdateSourceProps(Source, Context); case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO: CHECKSIZE(values, 1); CHECKVAL(values[0] == AL_FALSE || values[0] == AL_TRUE); - Source->WetGainHFAuto = values[0]; + Source->WetGainHFAuto = values[0] != AL_FALSE; return UpdateSourceProps(Source, Context); case AL_DIRECT_CHANNELS_SOFT: CHECKSIZE(values, 1); CHECKVAL(values[0] == AL_FALSE || values[0] == AL_TRUE); - Source->DirectChannels = values[0]; + Source->DirectChannels = values[0] != AL_FALSE; return UpdateSourceProps(Source, Context); case AL_DISTANCE_MODEL: diff --git a/alc/effects/compressor.cpp b/alc/effects/compressor.cpp index 176e5a58..44ffaaef 100644 --- a/alc/effects/compressor.cpp +++ b/alc/effects/compressor.cpp @@ -161,7 +161,7 @@ void Compressor_setParami(EffectProps *props, ALCcontext *context, ALenum param, case AL_COMPRESSOR_ONOFF: if(!(val >= AL_COMPRESSOR_MIN_ONOFF && val <= AL_COMPRESSOR_MAX_ONOFF)) SETERR_RETURN(context, AL_INVALID_VALUE,, "Compressor state out of range"); - props->Compressor.OnOff = val; + props->Compressor.OnOff = val != AL_FALSE; break; default: diff --git a/alc/effects/reverb.cpp b/alc/effects/reverb.cpp index b5100a14..82a80198 100644 --- a/alc/effects/reverb.cpp +++ b/alc/effects/reverb.cpp @@ -1526,7 +1526,7 @@ void EAXReverb_setParami(EffectProps *props, ALCcontext *context, ALenum param, case AL_EAXREVERB_DECAY_HFLIMIT: if(!(val >= AL_EAXREVERB_MIN_DECAY_HFLIMIT && val <= AL_EAXREVERB_MAX_DECAY_HFLIMIT)) SETERR_RETURN(context, AL_INVALID_VALUE,, "EAX Reverb decay hflimit out of range"); - props->Reverb.DecayHFLimit = val; + props->Reverb.DecayHFLimit = val != AL_FALSE; break; default: @@ -1863,7 +1863,7 @@ void StdReverb_setParami(EffectProps *props, ALCcontext *context, ALenum param, case AL_REVERB_DECAY_HFLIMIT: if(!(val >= AL_REVERB_MIN_DECAY_HFLIMIT && val <= AL_REVERB_MAX_DECAY_HFLIMIT)) SETERR_RETURN(context, AL_INVALID_VALUE,, "Reverb decay hflimit out of range"); - props->Reverb.DecayHFLimit = val; + props->Reverb.DecayHFLimit = val != AL_FALSE; break; default: -- cgit v1.2.3 From bf2c865d3953370ccf9d56e7a5dc6d2d4c587be1 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 16 Sep 2019 07:16:31 -0700 Subject: Clean up some more shadowing warnings --- al/source.cpp | 14 +++++++------- alc/alu.cpp | 21 ++++++++++----------- alc/backends/pulseaudio.cpp | 14 ++++++-------- alc/hrtf.cpp | 8 ++++---- alc/mixer/mixer_c.cpp | 7 ++++--- alc/mixer/mixer_neon.cpp | 12 +++++++----- alc/mixer/mixer_sse.cpp | 12 +++++++----- alc/mixvoice.cpp | 8 ++++---- 8 files changed, 49 insertions(+), 47 deletions(-) (limited to 'al/source.cpp') diff --git a/al/source.cpp b/al/source.cpp index 53d2a705..f5550caf 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -2749,15 +2749,15 @@ START_API_FUNC } /* Look for an unused voice to play this source with. */ + auto find_voice = [](const ALvoice &v) noexcept -> bool + { + return v.mPlayState.load(std::memory_order_acquire) == ALvoice::Stopped + && v.mSourceID.load(std::memory_order_relaxed) == 0u; + }; auto voices_end = context->mVoices.data() + context->mVoices.size(); - voice = std::find_if(context->mVoices.data(), voices_end, - [](const ALvoice &voice) noexcept -> bool - { - return voice.mPlayState.load(std::memory_order_acquire) == ALvoice::Stopped && - voice.mSourceID.load(std::memory_order_relaxed) == 0u; - } - ); + voice = std::find_if(context->mVoices.data(), voices_end, find_voice); assert(voice != voices_end); + auto vidx = static_cast(std::distance(context->mVoices.data(), voice)); voice->mPlayState.store(ALvoice::Stopped, std::memory_order_release); diff --git a/alc/alu.cpp b/alc/alu.cpp index d7acf8d3..60c8e8e2 100644 --- a/alc/alu.cpp +++ b/alc/alu.cpp @@ -1320,17 +1320,16 @@ void ProcessParamUpdates(ALCcontext *ctx, const ALeffectslotArray &slots, bool force{CalcContextParams(ctx)}; force |= CalcListenerParams(ctx); force = std::accumulate(slots.begin(), slots.end(), force, - [ctx](const bool force, ALeffectslot *slot) -> bool - { return CalcEffectSlotParams(slot, ctx) | force; } + [ctx](const bool f, ALeffectslot *slot) -> bool + { return CalcEffectSlotParams(slot, ctx) | f; } ); - std::for_each(voices.begin(), voices.end(), - [ctx,force](ALvoice &voice) -> void - { - ALuint sid{voice.mSourceID.load(std::memory_order_acquire)}; - if(sid) CalcSourceParams(&voice, ctx, force); - } - ); + auto calc_params = [ctx,force](ALvoice &voice) -> void + { + if(ALuint sid{voice.mSourceID.load(std::memory_order_acquire)}) + CalcSourceParams(&voice, ctx, force); + }; + std::for_each(voices.begin(), voices.end(), calc_params); } IncrementRef(ctx->mUpdateCount); } @@ -1446,7 +1445,7 @@ void ApplyStablizer(FrontStablizer *Stablizer, const al::span B /* This applies the band-splitter, preserving phase at the cost of some * delay. The shorter the delay, the more error seeps into the result. */ - auto apply_splitter = [&tmpbuf,SamplesToDo](const FloatBufferLine &Buffer, + auto apply_splitter = [&tmpbuf,SamplesToDo](const FloatBufferLine &InBuf, ALfloat (&DelayBuf)[FrontStablizer::DelayLength], BandSplitter &Filter, ALfloat (&splitbuf)[2][BUFFERSIZE]) -> void { @@ -1457,7 +1456,7 @@ void ApplyStablizer(FrontStablizer *Stablizer, const al::span B */ auto tmpbuf_end = std::begin(tmpbuf) + SamplesToDo; std::copy_n(std::begin(DelayBuf), FrontStablizer::DelayLength, tmpbuf_end); - std::reverse_copy(Buffer.begin(), Buffer.begin()+SamplesToDo, std::begin(tmpbuf)); + std::reverse_copy(InBuf.begin(), InBuf.begin()+SamplesToDo, std::begin(tmpbuf)); std::copy_n(std::begin(tmpbuf), FrontStablizer::DelayLength, std::begin(DelayBuf)); /* Apply an all-pass on the reversed signal, then reverse the samples diff --git a/alc/backends/pulseaudio.cpp b/alc/backends/pulseaudio.cpp index e9997013..4d3b34d9 100644 --- a/alc/backends/pulseaudio.cpp +++ b/alc/backends/pulseaudio.cpp @@ -447,10 +447,8 @@ struct DevMap { bool checkName(const al::vector &list, const std::string &name) { - return std::find_if(list.cbegin(), list.cend(), - [&name](const DevMap &entry) -> bool - { return entry.name == name; } - ) != list.cend(); + auto match_name = [&name](const DevMap &entry) -> bool { return entry.name == name; }; + return std::find_if(list.cbegin(), list.cend(), match_name) != list.cend(); } al::vector PlaybackDevices; @@ -756,7 +754,7 @@ void PulsePlayback::sinkInfoCallbackC(pa_context *context, const pa_sink_info *i void PulsePlayback::sinkInfoCallback(pa_context*, const pa_sink_info *info, int eol) { struct ChannelMap { - DevFmtChannels chans; + DevFmtChannels fmt; pa_channel_map map; }; static constexpr std::array chanmaps{{ @@ -775,14 +773,14 @@ void PulsePlayback::sinkInfoCallback(pa_context*, const pa_sink_info *info, int return; } - auto chanmap = std::find_if(chanmaps.cbegin(), chanmaps.cend(), + auto chaniter = std::find_if(chanmaps.cbegin(), chanmaps.cend(), [info](const ChannelMap &chanmap) -> bool { return pa_channel_map_superset(&info->channel_map, &chanmap.map); } ); - if(chanmap != chanmaps.cend()) + if(chaniter != chanmaps.cend()) { if(!mDevice->Flags.get()) - mDevice->FmtChans = chanmap->chans; + mDevice->FmtChans = chaniter->fmt; } else { diff --git a/alc/hrtf.cpp b/alc/hrtf.cpp index 7d40b16c..7110478d 100644 --- a/alc/hrtf.cpp +++ b/alc/hrtf.cpp @@ -323,12 +323,12 @@ void BuildBFormatHrtf(const HrtfEntry *Hrtf, DirectHrtfState *state, const ALuin const ALuint azidx{float2uint(az_norm*static_cast(azcount) + 0.5f) % azcount}; /* Calculate the index for the impulse response. */ - const ALuint idx{iroffset + azidx}; + const ALuint iridx{iroffset + azidx}; - min_delay = minu(min_delay, minu(Hrtf->delays[idx][0], Hrtf->delays[idx][1])); - max_delay = maxu(max_delay, maxu(Hrtf->delays[idx][0], Hrtf->delays[idx][1])); + min_delay = minu(min_delay, minu(Hrtf->delays[iridx][0], Hrtf->delays[iridx][1])); + max_delay = maxu(max_delay, maxu(Hrtf->delays[iridx][0], Hrtf->delays[iridx][1])); - return idx; + return iridx; }; std::transform(AmbiPoints, AmbiPoints+AmbiCount, idx.begin(), calc_idxs); diff --git a/alc/mixer/mixer_c.cpp b/alc/mixer/mixer_c.cpp index 7beab1a9..6e96e54e 100644 --- a/alc/mixer/mixer_c.cpp +++ b/alc/mixer/mixer_c.cpp @@ -188,13 +188,14 @@ void MixRow_(const al::span OutBuffer, const al::span { for(const float gain : Gains) { - const float *RESTRICT src{InSamples}; + const float *RESTRICT input{InSamples}; InSamples += InStride; if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD)) continue; - std::transform(OutBuffer.begin(), OutBuffer.end(), src, OutBuffer.begin(), - [gain](const ALfloat cur, const ALfloat src) -> ALfloat { return cur + src*gain; }); + auto do_mix = [gain](const float cur, const float src) noexcept -> float + { return cur + src*gain; }; + std::transform(OutBuffer.begin(), OutBuffer.end(), input, OutBuffer.begin(), do_mix); } } diff --git a/alc/mixer/mixer_neon.cpp b/alc/mixer/mixer_neon.cpp index 2f11273a..e7313876 100644 --- a/alc/mixer/mixer_neon.cpp +++ b/alc/mixer/mixer_neon.cpp @@ -262,7 +262,7 @@ void MixRow_(const al::span OutBuffer, const al::span GAIN_SILENCE_THRESHOLD)) @@ -273,14 +273,16 @@ void MixRow_(const al::span OutBuffer, const al::span ALfloat { return cur + src*gain; }); + + auto do_mix = [gain](const float cur, const float src) noexcept -> float + { return cur + src*gain; }; + std::transform(out_iter, OutBuffer.end(), input, out_iter, do_mix); } } diff --git a/alc/mixer/mixer_sse.cpp b/alc/mixer/mixer_sse.cpp index 65eb0dee..d47a0e66 100644 --- a/alc/mixer/mixer_sse.cpp +++ b/alc/mixer/mixer_sse.cpp @@ -226,7 +226,7 @@ void MixRow_(const al::span OutBuffer, const al::span GAIN_SILENCE_THRESHOLD)) @@ -237,14 +237,16 @@ void MixRow_(const al::span OutBuffer, const al::span ALfloat { return cur + src*gain; }); + + auto do_mix = [gain](const float cur, const float src) noexcept -> float + { return cur + src*gain; }; + std::transform(out_iter, OutBuffer.end(), input, out_iter, do_mix); } } diff --git a/alc/mixvoice.cpp b/alc/mixvoice.cpp index 2b5972f3..3d4d9cb8 100644 --- a/alc/mixvoice.cpp +++ b/alc/mixvoice.cpp @@ -763,14 +763,14 @@ void ALvoice::mix(State vstate, ALCcontext *Context, const ALuint SamplesToDo) const al::span nfcsamples{Device->NfcSampleData, DstBufferSize}; size_t chanoffset{outcount}; using FilterProc = void (NfcFilter::*)(float*,const float*,const size_t); - auto apply_nfc = [this,&parms,samples,TargetGains,Counter,OutPos,&chanoffset,nfcsamples](const FilterProc process, const size_t outcount) -> void + auto apply_nfc = [this,&parms,samples,TargetGains,Counter,OutPos,&chanoffset,nfcsamples](const FilterProc process, const size_t chancount) -> void { - if(outcount < 1) return; + if(chancount < 1) return; (parms.NFCtrlFilter.*process)(nfcsamples.data(), samples, nfcsamples.size()); - MixSamples(nfcsamples, mDirect.Buffer.subspan(chanoffset, outcount), + MixSamples(nfcsamples, mDirect.Buffer.subspan(chanoffset, chancount), parms.Gains.Current+chanoffset, TargetGains+chanoffset, Counter, OutPos); - chanoffset += outcount; + chanoffset += chancount; }; apply_nfc(&NfcFilter::process1, Device->NumChannelsPerOrder[1]); apply_nfc(&NfcFilter::process2, Device->NumChannelsPerOrder[2]); -- cgit v1.2.3 From 564c953e9465855890149a2d1b4b51f1f644fd9b Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 21 Sep 2019 16:47:33 -0700 Subject: Make the buffer frequency unsigned --- al/buffer.cpp | 6 +++--- al/buffer.h | 2 +- al/source.cpp | 5 ++--- 3 files changed, 6 insertions(+), 7 deletions(-) (limited to 'al/source.cpp') diff --git a/al/buffer.cpp b/al/buffer.cpp index f1f792e9..c9e195d1 100644 --- a/al/buffer.cpp +++ b/al/buffer.cpp @@ -463,7 +463,7 @@ void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALsizei freq, ALuint size, /* Can only preserve data with the same format and alignment. */ if UNLIKELY(ALBuf->mFmtChannels != DstChannels || ALBuf->OriginalType != SrcType) SETERR_RETURN(context, AL_INVALID_VALUE,, "Preserving data of mismatched format"); - if UNLIKELY(static_cast(ALBuf->OriginalAlign) != align) + if UNLIKELY(ALBuf->OriginalAlign != align) SETERR_RETURN(context, AL_INVALID_VALUE,, "Preserving data of mismatched alignment"); } @@ -539,7 +539,7 @@ void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALsizei freq, ALuint size, ALBuf->OriginalSize = size; ALBuf->OriginalType = SrcType; - ALBuf->Frequency = freq; + ALBuf->Frequency = static_cast(freq); ALBuf->mFmtChannels = DstChannels; ALBuf->mFmtType = DstType; ALBuf->Access = access; @@ -1253,7 +1253,7 @@ START_API_FUNC else switch(param) { case AL_FREQUENCY: - *value = albuf->Frequency; + *value = static_cast(albuf->Frequency); break; case AL_BITS: diff --git a/al/buffer.h b/al/buffer.h index 70faf56e..d41eec5d 100644 --- a/al/buffer.h +++ b/al/buffer.h @@ -68,7 +68,7 @@ inline ALuint FrameSizeFromFmt(FmtChannels chans, FmtType type) struct ALbuffer { al::vector mData; - ALsizei Frequency{0}; + ALuint Frequency{0u}; ALbitfieldSOFT Access{0u}; ALuint SampleLen{0u}; diff --git a/al/source.cpp b/al/source.cpp index f5550caf..7eda4fb6 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -267,8 +267,7 @@ ALdouble GetSourceSecOffset(ALsource *Source, ALCcontext *context, nanoseconds * } assert(BufferFmt != nullptr); - offset = static_cast(readPos) / ALdouble{FRACTIONONE} / - static_cast(BufferFmt->Frequency); + offset = static_cast(readPos) / ALdouble{FRACTIONONE} / BufferFmt->Frequency; } return offset; @@ -2784,7 +2783,7 @@ START_API_FUNC } ALbuffer *buffer{BufferList->mBuffer}; - voice->mFrequency = static_cast(buffer->Frequency); + voice->mFrequency = buffer->Frequency; voice->mFmtChannels = buffer->mFmtChannels; voice->mNumChannels = ChannelsFromFmt(buffer->mFmtChannels); voice->mSampleSize = BytesFromFmt(buffer->mFmtType); -- cgit v1.2.3 From 24db8a3f4bdbd787c23ac6e2ec78c2bafed81f1f Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 22 Sep 2019 21:19:19 -0700 Subject: Make the resampler type an enum class --- al/source.cpp | 4 ++-- al/state.cpp | 15 ++++++++------- alc/alu.cpp | 8 ++++---- alc/alu.h | 16 ++++++++-------- alc/backends/coreaudio.cpp | 2 +- alc/backends/wasapi.cpp | 2 +- alc/converter.cpp | 4 ++-- alc/mixvoice.cpp | 22 +++++++++++----------- 8 files changed, 37 insertions(+), 36 deletions(-) (limited to 'al/source.cpp') diff --git a/al/source.cpp b/al/source.cpp index 7eda4fb6..3aaaaf90 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -1295,7 +1295,7 @@ bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a case AL_SOURCE_RESAMPLER_SOFT: CHECKSIZE(values, 1); - CHECKVAL(values[0] >= 0 && values[0] <= ResamplerMax); + CHECKVAL(values[0] >= 0 && values[0] <= static_cast(Resampler::Max)); Source->mResampler = static_cast(values[0]); return UpdateSourceProps(Source, Context); @@ -1836,7 +1836,7 @@ bool GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a case AL_SOURCE_RESAMPLER_SOFT: CHECKSIZE(values, 1); - values[0] = Source->mResampler; + values[0] = static_cast(Source->mResampler); return true; case AL_SOURCE_SPATIALIZE_SOFT: diff --git a/al/state.cpp b/al/state.cpp index 74fb3b55..8f456ed3 100644 --- a/al/state.cpp +++ b/al/state.cpp @@ -196,7 +196,7 @@ START_API_FUNC break; case AL_DEFAULT_RESAMPLER_SOFT: - value = ResamplerDefault ? AL_TRUE : AL_FALSE; + value = static_cast(ResamplerDefault) ? AL_TRUE : AL_FALSE; break; default: @@ -243,7 +243,7 @@ START_API_FUNC break; case AL_NUM_RESAMPLERS_SOFT: - value = static_cast(ResamplerMax + 1); + value = static_cast(Resampler::Max) + 1.0; break; case AL_DEFAULT_RESAMPLER_SOFT: @@ -294,7 +294,7 @@ START_API_FUNC break; case AL_NUM_RESAMPLERS_SOFT: - value = static_cast(ResamplerMax + 1); + value = static_cast(Resampler::Max) + 1.0f; break; case AL_DEFAULT_RESAMPLER_SOFT: @@ -345,11 +345,11 @@ START_API_FUNC break; case AL_NUM_RESAMPLERS_SOFT: - value = ResamplerMax + 1; + value = static_cast(Resampler::Max) + 1; break; case AL_DEFAULT_RESAMPLER_SOFT: - value = ResamplerDefault; + value = static_cast(ResamplerDefault); break; default: @@ -396,7 +396,7 @@ START_API_FUNC break; case AL_NUM_RESAMPLERS_SOFT: - value = static_cast(ResamplerMax + 1); + value = static_cast(Resampler::Max) + 1; break; case AL_DEFAULT_RESAMPLER_SOFT: @@ -801,7 +801,8 @@ START_API_FUNC alCubicResampler, alBSinc12Resampler, alBSinc24Resampler, }; - static_assert(al::size(ResamplerNames) == ResamplerMax+1, "Incorrect ResamplerNames list"); + static_assert(al::size(ResamplerNames) == static_cast(Resampler::Max)+1, + "Incorrect ResamplerNames list"); ContextRef context{GetContextRef()}; if UNLIKELY(!context) return nullptr; diff --git a/alc/alu.cpp b/alc/alu.cpp index 606d8fdb..8affbde4 100644 --- a/alc/alu.cpp +++ b/alc/alu.cpp @@ -947,9 +947,9 @@ void CalcNonAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, cons voice->mStep = MAX_PITCH<mStep = maxu(fastf2u(Pitch * FRACTIONONE), 1); - if(props->mResampler == BSinc24Resampler) + if(props->mResampler == Resampler::BSinc24) BsincPrepare(voice->mStep, &voice->mResampleState.bsinc, &bsinc24); - else if(props->mResampler == BSinc12Resampler) + else if(props->mResampler == Resampler::BSinc12) BsincPrepare(voice->mStep, &voice->mResampleState.bsinc, &bsinc12); voice->mResampler = SelectResampler(props->mResampler); @@ -1277,9 +1277,9 @@ void CalcAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, const A voice->mStep = MAX_PITCH<mStep = maxu(fastf2u(Pitch * FRACTIONONE), 1); - if(props->mResampler == BSinc24Resampler) + if(props->mResampler == Resampler::BSinc24) BsincPrepare(voice->mStep, &voice->mResampleState.bsinc, &bsinc24); - else if(props->mResampler == BSinc12Resampler) + else if(props->mResampler == Resampler::BSinc12) BsincPrepare(voice->mStep, &voice->mResampleState.bsinc, &bsinc12); voice->mResampler = SelectResampler(props->mResampler); diff --git a/alc/alu.h b/alc/alu.h index 33c67630..aa698f7d 100644 --- a/alc/alu.h +++ b/alc/alu.h @@ -42,14 +42,14 @@ enum SpatializeMode { SpatializeAuto = AL_AUTO_SOFT }; -enum Resampler { - PointResampler, - LinearResampler, - FIR4Resampler, - BSinc12Resampler, - BSinc24Resampler, - - ResamplerMax = BSinc24Resampler +enum class Resampler { + Point, + Linear, + Cubic, + BSinc12, + BSinc24, + + Max = BSinc24 }; extern Resampler ResamplerDefault; diff --git a/alc/backends/coreaudio.cpp b/alc/backends/coreaudio.cpp index 72754718..9e8291e2 100644 --- a/alc/backends/coreaudio.cpp +++ b/alc/backends/coreaudio.cpp @@ -618,7 +618,7 @@ ALCenum CoreAudioCapture::open(const ALCchar *name) if(outputFormat.mSampleRate != mDevice->Frequency) mConverter = CreateSampleConverter(mDevice->FmtType, mDevice->FmtType, mFormat.mChannelsPerFrame, static_cast(hardwareFormat.mSampleRate), - mDevice->Frequency, BSinc24Resampler); + mDevice->Frequency, Resampler::BSinc24); mRing = CreateRingBuffer(outputFrameCount, mFrameSize, false); if(!mRing) return ALC_INVALID_VALUE; diff --git a/alc/backends/wasapi.cpp b/alc/backends/wasapi.cpp index 1271eeaa..e1a8dc6f 100644 --- a/alc/backends/wasapi.cpp +++ b/alc/backends/wasapi.cpp @@ -1568,7 +1568,7 @@ HRESULT WasapiCapture::resetProxy() if(mDevice->Frequency != OutputType.Format.nSamplesPerSec || mDevice->FmtType != srcType) { mSampleConv = CreateSampleConverter(srcType, mDevice->FmtType, mDevice->channelsFromFmt(), - OutputType.Format.nSamplesPerSec, mDevice->Frequency, BSinc24Resampler); + OutputType.Format.nSamplesPerSec, mDevice->Frequency, Resampler::BSinc24); if(!mSampleConv) { ERR("Failed to create converter for %s format, dst: %s %uhz, src: %s %luhz\n", diff --git a/alc/converter.cpp b/alc/converter.cpp index 2ad2ac3b..6622a997 100644 --- a/alc/converter.cpp +++ b/alc/converter.cpp @@ -167,9 +167,9 @@ SampleConverterPtr CreateSampleConverter(DevFmtType srcType, DevFmtType dstType, converter->mResample = Resample_; else { - if(resampler == BSinc24Resampler) + if(resampler == Resampler::BSinc24) BsincPrepare(converter->mIncrement, &converter->mState.bsinc, &bsinc24); - else if(resampler == BSinc12Resampler) + else if(resampler == Resampler::BSinc12) BsincPrepare(converter->mIncrement, &converter->mState.bsinc, &bsinc12); converter->mResample = SelectResampler(resampler); } diff --git a/alc/mixvoice.cpp b/alc/mixvoice.cpp index bf10444a..99e4dc48 100644 --- a/alc/mixvoice.cpp +++ b/alc/mixvoice.cpp @@ -70,7 +70,7 @@ static_assert((INT_MAX>>FRACTIONBITS)/MAX_PITCH > BUFFERSIZE, static_assert(MAX_RESAMPLE_PADDING >= 24, "MAX_RESAMPLE_PADDING must be at least 24!"); -Resampler ResamplerDefault = LinearResampler; +Resampler ResamplerDefault{Resampler::Linear}; MixerFunc MixSamples = Mix_; RowMixerFunc MixRowSamples = MixRow_; @@ -139,9 +139,9 @@ ResamplerFunc SelectResampler(Resampler resampler) { switch(resampler) { - case PointResampler: + case Resampler::Point: return Resample_; - case LinearResampler: + case Resampler::Linear: #ifdef HAVE_NEON if((CPUCapFlags&CPU_CAP_NEON)) return Resample_; @@ -155,10 +155,10 @@ ResamplerFunc SelectResampler(Resampler resampler) return Resample_; #endif return Resample_; - case FIR4Resampler: + case Resampler::Cubic: return Resample_; - case BSinc12Resampler: - case BSinc24Resampler: + case Resampler::BSinc12: + case Resampler::BSinc24: #ifdef HAVE_NEON if((CPUCapFlags&CPU_CAP_NEON)) return Resample_; @@ -183,11 +183,11 @@ void aluInitMixer() const Resampler resampler; }; constexpr ResamplerEntry ResamplerList[]{ - { "none", PointResampler }, - { "point", PointResampler }, - { "cubic", FIR4Resampler }, - { "bsinc12", BSinc12Resampler }, - { "bsinc24", BSinc24Resampler }, + { "none", Resampler::Point }, + { "point", Resampler::Point }, + { "cubic", Resampler::Cubic }, + { "bsinc12", Resampler::BSinc12 }, + { "bsinc24", Resampler::BSinc24 }, }; const char *str{resopt->c_str()}; -- cgit v1.2.3 From d50ca464cd5e4f07bc399fd244578b0b34d72aef Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 25 Sep 2019 03:01:58 -0700 Subject: Use a span for holding the source handles --- al/source.cpp | 90 +++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 51 insertions(+), 39 deletions(-) (limited to 'al/source.cpp') diff --git a/al/source.cpp b/al/source.cpp index 3aaaaf90..a802cabc 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -2641,20 +2641,23 @@ START_API_FUNC if UNLIKELY(n <= 0) return; al::vector extra_sources; - std::array source_storage; - ALsource **srchandles{source_storage.data()}; - if UNLIKELY(static_cast(n) > source_storage.size()) + std::array source_storage; + al::span srchandles; + if LIKELY(static_cast(n) <= source_storage.size()) + srchandles = {source_storage.data(), static_cast(n)}; + else { extra_sources.resize(static_cast(n)); - srchandles = extra_sources.data(); + srchandles = {extra_sources.data(), extra_sources.size()}; } std::lock_guard _{context->mSourceLock}; - for(ALsizei i{0};i < n;i++) + for(auto &srchdl : srchandles) { - srchandles[i] = LookupSource(context.get(), sources[i]); - if(!srchandles[i]) - SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid source ID %u", sources[i]); + srchdl = LookupSource(context.get(), *sources); + if(!srchdl) + SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid source ID %u", *sources); + ++sources; } ALCdevice *device{context->mDevice.get()}; @@ -2663,7 +2666,7 @@ START_API_FUNC if UNLIKELY(!device->Connected.load(std::memory_order_acquire)) { /* TODO: Send state change event? */ - std::for_each(srchandles, srchandles+n, + std::for_each(srchandles.begin(), srchandles.end(), [](ALsource *source) -> void { source->OffsetType = AL_NONE; @@ -2684,10 +2687,10 @@ START_API_FUNC }; auto free_voices = std::accumulate(context->mVoices.begin(), context->mVoices.end(), ALuint{0}, count_free_voices); - if UNLIKELY(static_cast(n) > free_voices) + if UNLIKELY(srchandles.size() > free_voices) { /* Increase the number of voices to handle the request. */ - const ALuint need_voices{static_cast(n) - free_voices}; + const size_t need_voices{srchandles.size() - free_voices}; context->mVoices.resize(context->mVoices.size() + need_voices); } @@ -2869,7 +2872,7 @@ START_API_FUNC SendStateChangeEvent(context.get(), source->id, AL_PLAYING); } }; - std::for_each(srchandles, srchandles+n, start_source); + std::for_each(srchandles.begin(), srchandles.end(), start_source); } END_API_FUNC @@ -2890,20 +2893,23 @@ START_API_FUNC if UNLIKELY(n <= 0) return; al::vector extra_sources; - std::array source_storage; - ALsource **srchandles{source_storage.data()}; - if UNLIKELY(static_cast(n) > source_storage.size()) + std::array source_storage; + al::span srchandles; + if LIKELY(static_cast(n) <= source_storage.size()) + srchandles = {source_storage.data(), static_cast(n)}; + else { extra_sources.resize(static_cast(n)); - srchandles = extra_sources.data(); + srchandles = {extra_sources.data(), extra_sources.size()}; } std::lock_guard _{context->mSourceLock}; - for(ALsizei i{0};i < n;i++) + for(auto &srchdl : srchandles) { - srchandles[i] = LookupSource(context.get(), sources[i]); - if(!srchandles[i]) - SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid source ID %u", sources[i]); + srchdl = LookupSource(context.get(), *sources); + if(!srchdl) + SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid source ID %u", *sources); + ++sources; } ALCdevice *device{context->mDevice.get()}; @@ -2924,7 +2930,7 @@ START_API_FUNC SendStateChangeEvent(context.get(), source->id, AL_PAUSED); } }; - std::for_each(srchandles, srchandles+n, pause_source); + std::for_each(srchandles.begin(), srchandles.end(), pause_source); } END_API_FUNC @@ -2945,20 +2951,23 @@ START_API_FUNC if UNLIKELY(n <= 0) return; al::vector extra_sources; - std::array source_storage; - ALsource **srchandles{source_storage.data()}; - if UNLIKELY(static_cast(n) > source_storage.size()) + std::array source_storage; + al::span srchandles; + if LIKELY(static_cast(n) <= source_storage.size()) + srchandles = {source_storage.data(), static_cast(n)}; + else { extra_sources.resize(static_cast(n)); - srchandles = extra_sources.data(); + srchandles = {extra_sources.data(), extra_sources.size()}; } std::lock_guard _{context->mSourceLock}; - for(ALsizei i{0};i < n;i++) + for(auto &srchdl : srchandles) { - srchandles[i] = LookupSource(context.get(), sources[i]); - if(!srchandles[i]) - SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid source ID %u", sources[i]); + srchdl = LookupSource(context.get(), *sources); + if(!srchdl) + SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid source ID %u", *sources); + ++sources; } ALCdevice *device{context->mDevice.get()}; @@ -2989,7 +2998,7 @@ START_API_FUNC source->OffsetType = AL_NONE; source->Offset = 0.0; }; - std::for_each(srchandles, srchandles+n, stop_source); + std::for_each(srchandles.begin(), srchandles.end(), stop_source); } END_API_FUNC @@ -3010,20 +3019,23 @@ START_API_FUNC if UNLIKELY(n <= 0) return; al::vector extra_sources; - std::array source_storage; - ALsource **srchandles{source_storage.data()}; - if UNLIKELY(static_cast(n) > source_storage.size()) + std::array source_storage; + al::span srchandles; + if LIKELY(static_cast(n) <= source_storage.size()) + srchandles = {source_storage.data(), static_cast(n)}; + else { extra_sources.resize(static_cast(n)); - srchandles = extra_sources.data(); + srchandles = {extra_sources.data(), extra_sources.size()}; } std::lock_guard _{context->mSourceLock}; - for(ALsizei i{0};i < n;i++) + for(auto &srchdl : srchandles) { - srchandles[i] = LookupSource(context.get(), sources[i]); - if(!srchandles[i]) - SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid source ID %u", sources[i]); + srchdl = LookupSource(context.get(), *sources); + if(!srchdl) + SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid source ID %u", *sources); + ++sources; } ALCdevice *device{context->mDevice.get()}; @@ -3050,7 +3062,7 @@ START_API_FUNC source->OffsetType = AL_NONE; source->Offset = 0.0; }; - std::for_each(srchandles, srchandles+n, rewind_source); + std::for_each(srchandles.begin(), srchandles.end(), rewind_source); } END_API_FUNC -- cgit v1.2.3 From cf617760b6eb68d38493dd546746880cd5c88b90 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 30 Sep 2019 03:03:27 -0700 Subject: Separate a couple assignments from conditionals --- al/source.cpp | 3 ++- alc/mixvoice.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'al/source.cpp') diff --git a/al/source.cpp b/al/source.cpp index a802cabc..6d15f73a 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -3159,7 +3159,8 @@ START_API_FUNC /* Source is now streaming */ source->SourceType = AL_STREAMING; - if(!(BufferList=source->queue)) + BufferList = source->queue; + if(!BufferList) source->queue = BufferListStart; else { diff --git a/alc/mixvoice.cpp b/alc/mixvoice.cpp index c696f114..d6be174e 100644 --- a/alc/mixvoice.cpp +++ b/alc/mixvoice.cpp @@ -820,7 +820,8 @@ void ALvoice::mix(State vstate, ALCcontext *Context, const ALuint SamplesToDo) ++buffers_done; BufferListItem = BufferListItem->mNext.load(std::memory_order_relaxed); - if(!BufferListItem && !(BufferListItem=BufferLoopItem)) + if(!BufferListItem) BufferListItem = BufferLoopItem; + if(!BufferListItem) { if LIKELY(vstate == ALvoice::Playing) vstate = ALvoice::Stopped; -- cgit v1.2.3 From 0cba99ed1bc2712c15c17f0940127e6f84395729 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 25 Oct 2019 01:43:23 -0700 Subject: Avoid static constexpr for arrays iterated over at run-time --- al/buffer.cpp | 2 +- al/source.cpp | 12 +++++------- al/state.cpp | 2 +- alc/alc.cpp | 6 +++--- alc/alu.cpp | 2 +- alc/helpers.cpp | 2 +- alc/hrtf.cpp | 6 +++--- alc/panning.cpp | 20 ++++++++++---------- common/alnumeric.h | 2 +- 9 files changed, 26 insertions(+), 28 deletions(-) (limited to 'al/source.cpp') diff --git a/al/buffer.cpp b/al/buffer.cpp index c9e195d1..8f4228a8 100644 --- a/al/buffer.cpp +++ b/al/buffer.cpp @@ -557,7 +557,7 @@ al::optional DecomposeUserFormat(ALenum format) UserFmtChannels channels; UserFmtType type; }; - static constexpr std::array UserFmtList{{ + static const std::array UserFmtList{{ { AL_FORMAT_MONO8, UserFmtMono, UserFmtUByte }, { AL_FORMAT_MONO16, UserFmtMono, UserFmtShort }, { AL_FORMAT_MONO_FLOAT32, UserFmtMono, UserFmtFloat }, diff --git a/al/source.cpp b/al/source.cpp index 6d15f73a..8b8e6382 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -2808,20 +2808,18 @@ START_API_FUNC const ALuint *OrderFromChan; if(voice->mFmtChannels == FmtBFormat2D) { - static constexpr ALuint Order2DFromChan[MAX_AMBI2D_CHANNELS]{ - 0, 1,1, 2,2, 3,3 - }; + static const ALuint Order2DFromChan[MAX_AMBI2D_CHANNELS]{ + 0, 1,1, 2,2, 3,3,}; OrderFromChan = Order2DFromChan; } else { - static constexpr ALuint Order3DFromChan[MAX_AMBI_CHANNELS]{ - 0, 1,1,1, 2,2,2,2,2, 3,3,3,3,3,3,3, - }; + static const ALuint Order3DFromChan[MAX_AMBI_CHANNELS]{ + 0, 1,1,1, 2,2,2,2,2, 3,3,3,3,3,3,3,}; OrderFromChan = Order3DFromChan; } - BandSplitter splitter{400.0f / static_cast(device->Frequency)}; + BandSplitter splitter{400.0f / static_cast(device->Frequency)}; const auto scales = BFormatDec::GetHFOrderScales(1, device->mAmbiOrder); auto init_ambi = [scales,&OrderFromChan,&splitter](ALvoice::ChannelData &chandata) -> void diff --git a/al/state.cpp b/al/state.cpp index 3ce09be9..25a0efd1 100644 --- a/al/state.cpp +++ b/al/state.cpp @@ -742,7 +742,7 @@ START_API_FUNC ALbitfieldSOFT enabledevts{context->mEnabledEvts.load(std::memory_order_relaxed)}; if((enabledevts&EventType_Deprecated) && context->mEventCb) { - static constexpr ALCchar msg[] = + static const char msg[] = "alDopplerVelocity is deprecated in AL1.1, use alSpeedOfSound"; const ALsizei msglen{sizeof(msg)-1}; (*context->mEventCb)(AL_EVENT_TYPE_DEPRECATED_SOFT, 0, 0, msglen, msg, diff --git a/alc/alc.cpp b/alc/alc.cpp index 7702a147..cd2911f5 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -1988,7 +1988,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) * constexpr variable to avoid a reference on * FrontStablizer::DelayLength... */ - static constexpr size_t StablizerDelay{FrontStablizer::DelayLength}; + constexpr size_t StablizerDelay{FrontStablizer::DelayLength}; device->FixedLatency += nanoseconds{seconds{StablizerDelay}} / device->Frequency; } break; @@ -3568,7 +3568,7 @@ START_API_FUNC deviceName = device->DeviceName.c_str(); if(auto chanopt = ConfigValueStr(deviceName, nullptr, "channels")) { - static constexpr struct ChannelMap { + static const struct ChannelMap { const char name[16]; DevFmtChannels chans; ALuint order; @@ -3601,7 +3601,7 @@ START_API_FUNC } if(auto typeopt = ConfigValueStr(deviceName, nullptr, "sample-type")) { - static constexpr struct TypeMap { + static const struct TypeMap { const char name[16]; DevFmtType type; } typelist[] = { diff --git a/alc/alu.cpp b/alc/alu.cpp index 5cd8c918..9bf052e1 100644 --- a/alc/alu.cpp +++ b/alc/alu.cpp @@ -509,7 +509,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat xpos, const ALfloat ypo ALeffectslot *(&SendSlots)[MAX_SENDS], const ALvoicePropsBase *props, const ALlistener &Listener, const ALCdevice *Device) { - static constexpr ChanMap MonoMap[1]{ + static const ChanMap MonoMap[1]{ { FrontCenter, 0.0f, 0.0f } }, RearMap[2]{ { BackLeft, Deg2Rad(-150.0f), Deg2Rad(0.0f) }, diff --git a/alc/helpers.cpp b/alc/helpers.cpp index 25b2e4a2..4ea94c7d 100644 --- a/alc/helpers.cpp +++ b/alc/helpers.cpp @@ -385,7 +385,7 @@ al::vector SearchDataFiles(const char *ext, const char *subdir) DirectorySearch(path.c_str(), ext, &results); /* Search the local and global data dirs. */ - static constexpr int ids[2]{ CSIDL_APPDATA, CSIDL_COMMON_APPDATA }; + static const int ids[2]{ CSIDL_APPDATA, CSIDL_COMMON_APPDATA }; for(int id : ids) { WCHAR buffer[MAX_PATH]; diff --git a/alc/hrtf.cpp b/alc/hrtf.cpp index fa0085ff..c22848d6 100644 --- a/alc/hrtf.cpp +++ b/alc/hrtf.cpp @@ -300,7 +300,7 @@ void BuildBFormatHrtf(const HrtfEntry *Hrtf, DirectHrtfState *state, ALuint ldelay, rdelay; }; - static constexpr int OrderFromChan[MAX_AMBI_CHANNELS]{ + static const int OrderFromChan[MAX_AMBI_CHANNELS]{ 0, 1,1,1, 2,2,2,2,2, 3,3,3,3,3,3,3, }; /* Set this to true for dual-band HRTF processing. May require better @@ -718,7 +718,7 @@ std::unique_ptr LoadHrtf00(std::istream &data, const char *filename) } } - static constexpr ALfloat distance{0.0f}; + static const ALfloat distance{0.0f}; return CreateHrtfStore(rate, irSize, 1, &evCount, &distance, azCount.data(), evOffset.data(), irCount, &reinterpret_cast(coeffs[0]), &reinterpret_cast(delays[0]), filename); @@ -817,7 +817,7 @@ std::unique_ptr LoadHrtf01(std::istream &data, const char *filename) } } - static constexpr ALfloat distance{0.0f}; + static const ALfloat distance{0.0f}; return CreateHrtfStore(rate, irSize, 1, &evCount, &distance, azCount.data(), evOffset.data(), irCount, &reinterpret_cast(coeffs[0]), &reinterpret_cast(delays[0]), filename); diff --git a/alc/panning.cpp b/alc/panning.cpp index aa30a71c..6056b9d9 100644 --- a/alc/panning.cpp +++ b/alc/panning.cpp @@ -423,7 +423,7 @@ void InitPanning(ALCdevice *device) ALfloat nfc_delay{ConfigValueFloat(devname, "decoder", "nfc-ref-delay").value_or(0.0f)}; if(nfc_delay > 0.0f) { - static constexpr ALuint chans_per_order[MAX_AMBI_ORDER+1]{ 1, 3, 5, 7 }; + static const ALuint chans_per_order[MAX_AMBI_ORDER+1]{ 1, 3, 5, 7 }; InitNearFieldCtrl(device, nfc_delay * SPEEDOFSOUNDMETRESPERSEC, device->mAmbiOrder, chans_per_order); } @@ -470,8 +470,8 @@ void InitPanning(ALCdevice *device) void InitCustomPanning(ALCdevice *device, bool hqdec, const AmbDecConf *conf, const ALuint (&speakermap)[MAX_OUTPUT_CHANNELS]) { - static constexpr ALuint chans_per_order2d[MAX_AMBI_ORDER+1] = { 1, 2, 2, 2 }; - static constexpr ALuint chans_per_order3d[MAX_AMBI_ORDER+1] = { 1, 3, 5, 7 }; + static const ALuint chans_per_order2d[MAX_AMBI_ORDER+1] = { 1, 2, 2, 2 }; + static const ALuint chans_per_order3d[MAX_AMBI_ORDER+1] = { 1, 3, 5, 7 }; if(!hqdec && conf->FreqBands != 1) ERR("Basic renderer uses the high-frequency matrix as single-band (xover_freq = %.0fhz)\n", @@ -522,7 +522,7 @@ void InitCustomPanning(ALCdevice *device, bool hqdec, const AmbDecConf *conf, void InitHrtfPanning(ALCdevice *device) { - static constexpr AngularPoint AmbiPoints[]{ + static const AngularPoint AmbiPoints[]{ { Deg2Rad( 0.000000f), Deg2Rad( 0.000000f) }, { Deg2Rad( 0.000000f), Deg2Rad( 180.000000f) }, { Deg2Rad( 0.000000f), Deg2Rad( -90.000000f) }, @@ -550,7 +550,7 @@ void InitHrtfPanning(ALCdevice *device) { Deg2Rad( 35.264390f), Deg2Rad( 135.000000f) }, { Deg2Rad(-35.264390f), Deg2Rad( 135.000000f) }, }; - static constexpr ALfloat AmbiMatrix[][MAX_AMBI_CHANNELS]{ + static const float AmbiMatrix[][MAX_AMBI_CHANNELS]{ { 3.84615387e-02f, 0.00000000e+00f, 0.00000000e+00f, 8.33950391e-02f, 0.00000000e+00f, 0.00000000e+00f, -4.96903997e-02f, 0.00000000e+00f, 8.60662966e-02f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, -7.49473409e-02f, 0.00000000e+00f, 9.67566016e-02f }, { 3.84615387e-02f, 0.00000000e+00f, 0.00000000e+00f, -8.33950391e-02f, 0.00000000e+00f, 0.00000000e+00f, -4.96903997e-02f, 0.00000000e+00f, 8.60662966e-02f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, 7.49473409e-02f, 0.00000000e+00f, -9.67566016e-02f }, { 3.84615387e-02f, 8.33950391e-02f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, -4.96903997e-02f, 0.00000000e+00f, -8.60662966e-02f, -9.67566016e-02f, 0.00000000e+00f, -7.49473409e-02f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f }, @@ -578,15 +578,15 @@ void InitHrtfPanning(ALCdevice *device) { 3.84615385e-02f, -3.33333332e-02f, 3.33333335e-02f, -3.33333332e-02f, 4.55645099e-02f, -4.55645100e-02f, 5.38752428e-10f, -4.55645100e-02f, 0.00000000e+00f, -2.95742381e-02f, 6.33865691e-02f, -2.29081068e-02f, -3.74087810e-02f, -2.29081068e-02f, 0.00000000e+00f, 2.95742381e-02f }, { 3.84615385e-02f, -3.33333332e-02f, -3.33333335e-02f, -3.33333332e-02f, 4.55645099e-02f, 4.55645100e-02f, 5.38752429e-10f, 4.55645100e-02f, 0.00000000e+00f, -2.95742381e-02f, -6.33865691e-02f, -2.29081068e-02f, 3.74087810e-02f, -2.29081068e-02f, 0.00000000e+00f, 2.95742381e-02f }, }; - static constexpr ALfloat AmbiOrderHFGain1O[MAX_AMBI_ORDER+1]{ + static const float AmbiOrderHFGain1O[MAX_AMBI_ORDER+1]{ 3.60555128e+00f, 2.08166600e+00f }, AmbiOrderHFGain2O[MAX_AMBI_ORDER+1]{ 2.68741925e+00f, 2.08166600e+00f, 1.07496770e+00f }, AmbiOrderHFGain3O[MAX_AMBI_ORDER+1]{ 2.12652604e+00f, 1.83122879e+00f, 1.30214339e+00f, 6.48052398e-01f }; - static constexpr ALuint ChansPerOrder[MAX_AMBI_ORDER+1]{ 1, 3, 5, 7 }; - const ALfloat *AmbiOrderHFGain{AmbiOrderHFGain1O}; + static const ALuint ChansPerOrder[MAX_AMBI_ORDER+1]{ 1, 3, 5, 7 }; + const float *AmbiOrderHFGain{AmbiOrderHFGain1O}; static_assert(al::size(AmbiPoints) == al::size(AmbiMatrix), "Ambisonic HRTF mismatch"); @@ -602,7 +602,7 @@ void InitHrtfPanning(ALCdevice *device) RenderMode mode; ALuint order; }; - static constexpr HrtfModeEntry hrtf_modes[]{ + static const HrtfModeEntry hrtf_modes[]{ { "full", HrtfRender, 1 }, { "ambi1", NormalRender, 1 }, { "ambi2", NormalRender, 2 }, @@ -662,7 +662,7 @@ void InitHrtfPanning(ALCdevice *device) void InitUhjPanning(ALCdevice *device) { /* UHJ is always 2D first-order. */ - static constexpr size_t count{Ambi2DChannelsFromOrder(1)}; + constexpr size_t count{Ambi2DChannelsFromOrder(1)}; device->mAmbiOrder = 1; diff --git a/common/alnumeric.h b/common/alnumeric.h index b409ce9c..9158b764 100644 --- a/common/alnumeric.h +++ b/common/alnumeric.h @@ -308,7 +308,7 @@ inline float fast_roundf(float f) noexcept /* Integral limit, where sub-integral precision is not available for * floats. */ - static constexpr float ilim[2] = { + static const float ilim[2]{ 8388608.0f /* 0x1.0p+23 */, -8388608.0f /* -0x1.0p+23 */ }; -- cgit v1.2.3