2007-12-17 17:43:19 -08:00
|
|
|
/**
|
|
|
|
* 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
|
2014-08-18 14:11:03 +02:00
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2007-12-17 17:43:19 -08:00
|
|
|
* Or go to http://www.gnu.org/copyleft/lgpl.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2019-07-29 17:54:07 -07:00
|
|
|
#include "auxeffectslot.h"
|
2008-01-16 14:09:04 -08:00
|
|
|
|
2018-11-18 02:39:27 -08:00
|
|
|
#include <algorithm>
|
2019-07-28 21:29:59 -07:00
|
|
|
#include <cstdint>
|
|
|
|
#include <iterator>
|
|
|
|
#include <memory>
|
|
|
|
#include <mutex>
|
2019-09-12 06:29:32 -07:00
|
|
|
#include <numeric>
|
2019-07-28 21:29:59 -07:00
|
|
|
#include <thread>
|
2018-11-18 02:39:27 -08:00
|
|
|
|
2007-12-17 17:43:19 -08:00
|
|
|
#include "AL/al.h"
|
|
|
|
#include "AL/alc.h"
|
2019-08-05 22:40:19 -07:00
|
|
|
#include "AL/efx.h"
|
2018-11-17 23:02:27 -08:00
|
|
|
|
2019-07-28 18:33:29 -07:00
|
|
|
#include "alcmain.h"
|
2018-11-17 23:02:27 -08:00
|
|
|
#include "alcontext.h"
|
2019-04-10 17:47:13 -07:00
|
|
|
#include "alexcpt.h"
|
2016-03-29 00:44:58 -07:00
|
|
|
#include "almalloc.h"
|
2019-07-28 21:29:59 -07:00
|
|
|
#include "alnumeric.h"
|
|
|
|
#include "alspan.h"
|
|
|
|
#include "alu.h"
|
2020-08-24 16:08:09 -07:00
|
|
|
#include "buffer.h"
|
2019-07-29 17:54:07 -07:00
|
|
|
#include "effect.h"
|
2020-03-20 15:01:45 -07:00
|
|
|
#include "fpu_ctrl.h"
|
2019-07-28 21:29:59 -07:00
|
|
|
#include "inprogext.h"
|
|
|
|
#include "logging.h"
|
|
|
|
#include "opthelpers.h"
|
2016-03-29 00:44:58 -07:00
|
|
|
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2018-11-20 09:47:49 -08:00
|
|
|
namespace {
|
2018-02-22 12:03:52 -08:00
|
|
|
|
2018-11-20 09:47:49 -08:00
|
|
|
inline ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id) noexcept
|
|
|
|
{
|
2019-09-11 05:53:10 -07:00
|
|
|
const size_t lidx{(id-1) >> 6};
|
|
|
|
const ALuint slidx{(id-1) & 0x3f};
|
2019-02-20 22:00:26 -08:00
|
|
|
|
2019-08-04 11:59:14 -07:00
|
|
|
if UNLIKELY(lidx >= context->mEffectSlotList.size())
|
2019-02-20 22:00:26 -08:00
|
|
|
return nullptr;
|
2019-07-30 09:05:54 -07:00
|
|
|
EffectSlotSubList &sublist{context->mEffectSlotList[lidx]};
|
2019-08-04 11:59:14 -07:00
|
|
|
if UNLIKELY(sublist.FreeMask & (1_u64 << slidx))
|
2018-11-20 09:47:49 -08:00
|
|
|
return nullptr;
|
2019-02-20 22:00:26 -08:00
|
|
|
return sublist.EffectSlots + slidx;
|
2018-11-20 09:47:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline ALeffect *LookupEffect(ALCdevice *device, ALuint id) noexcept
|
|
|
|
{
|
2019-09-11 05:53:10 -07:00
|
|
|
const size_t lidx{(id-1) >> 6};
|
|
|
|
const ALuint slidx{(id-1) & 0x3f};
|
2018-11-20 09:47:49 -08:00
|
|
|
|
2019-08-04 11:59:14 -07:00
|
|
|
if UNLIKELY(lidx >= device->EffectList.size())
|
2018-11-20 09:47:49 -08:00
|
|
|
return nullptr;
|
|
|
|
EffectSubList &sublist = device->EffectList[lidx];
|
2019-08-04 11:59:14 -07:00
|
|
|
if UNLIKELY(sublist.FreeMask & (1_u64 << slidx))
|
2018-11-20 09:47:49 -08:00
|
|
|
return nullptr;
|
|
|
|
return sublist.Effects + slidx;
|
|
|
|
}
|
|
|
|
|
2020-08-24 16:08:09 -07:00
|
|
|
inline ALbuffer *LookupBuffer(ALCdevice *device, ALuint id) noexcept
|
|
|
|
{
|
|
|
|
const size_t lidx{(id-1) >> 6};
|
|
|
|
const ALuint 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;
|
|
|
|
}
|
|
|
|
|
2018-11-20 09:47:49 -08:00
|
|
|
|
2019-09-11 05:53:10 -07:00
|
|
|
void AddActiveEffectSlots(const ALuint *slotids, size_t count, ALCcontext *context)
|
2018-11-20 09:47:49 -08:00
|
|
|
{
|
|
|
|
if(count < 1) return;
|
2019-07-30 09:05:54 -07:00
|
|
|
ALeffectslotArray *curarray{context->mActiveAuxSlots.load(std::memory_order_acquire)};
|
2019-01-09 18:29:22 -08:00
|
|
|
size_t newcount{curarray->size() + count};
|
2018-11-20 09:47:49 -08:00
|
|
|
|
|
|
|
/* Insert the new effect slots into the head of the array, followed by the
|
2019-01-11 07:28:44 -08:00
|
|
|
* existing ones.
|
2018-11-20 09:47:49 -08:00
|
|
|
*/
|
2019-01-11 07:28:44 -08:00
|
|
|
ALeffectslotArray *newarray = ALeffectslot::CreatePtrArray(newcount);
|
2019-01-09 18:29:22 -08:00
|
|
|
auto slotiter = std::transform(slotids, slotids+count, newarray->begin(),
|
2018-11-20 09:47:49 -08:00
|
|
|
[context](ALuint id) noexcept -> ALeffectslot*
|
|
|
|
{ return LookupEffectSlot(context, id); }
|
|
|
|
);
|
2019-01-09 18:29:22 -08:00
|
|
|
std::copy(curarray->begin(), curarray->end(), slotiter);
|
2018-11-20 09:47:49 -08:00
|
|
|
|
|
|
|
/* Remove any duplicates (first instance of each will be kept). */
|
2019-01-09 18:29:22 -08:00
|
|
|
auto last = newarray->end();
|
|
|
|
for(auto start=newarray->begin()+1;;)
|
2018-11-20 09:47:49 -08:00
|
|
|
{
|
|
|
|
last = std::remove(start, last, *(start-1));
|
|
|
|
if(start == last) break;
|
|
|
|
++start;
|
|
|
|
}
|
2019-01-09 18:29:22 -08:00
|
|
|
newcount = static_cast<size_t>(std::distance(newarray->begin(), last));
|
2018-11-20 09:47:49 -08:00
|
|
|
|
|
|
|
/* Reallocate newarray if the new size ended up smaller from duplicate
|
|
|
|
* removal.
|
|
|
|
*/
|
2019-08-04 11:59:14 -07:00
|
|
|
if UNLIKELY(newcount < newarray->size())
|
2018-11-20 09:47:49 -08:00
|
|
|
{
|
|
|
|
curarray = newarray;
|
2019-01-11 07:28:44 -08:00
|
|
|
newarray = ALeffectslot::CreatePtrArray(newcount);
|
2019-01-09 18:29:22 -08:00
|
|
|
std::copy_n(curarray->begin(), newcount, newarray->begin());
|
|
|
|
delete curarray;
|
2018-11-20 09:47:49 -08:00
|
|
|
curarray = nullptr;
|
|
|
|
}
|
2020-01-18 18:53:58 -08:00
|
|
|
std::uninitialized_fill_n(newarray->end(), newcount, nullptr);
|
2018-11-20 09:47:49 -08:00
|
|
|
|
2019-07-30 09:05:54 -07:00
|
|
|
curarray = context->mActiveAuxSlots.exchange(newarray, std::memory_order_acq_rel);
|
2020-03-03 20:32:44 -08:00
|
|
|
context->mDevice->waitForMix();
|
|
|
|
|
2020-01-18 18:53:58 -08:00
|
|
|
al::destroy_n(curarray->end(), curarray->size());
|
2019-01-09 18:29:22 -08:00
|
|
|
delete curarray;
|
2018-11-20 09:47:49 -08:00
|
|
|
}
|
|
|
|
|
2019-09-11 05:53:10 -07:00
|
|
|
void RemoveActiveEffectSlots(const ALuint *slotids, size_t count, ALCcontext *context)
|
2018-11-20 09:47:49 -08:00
|
|
|
{
|
|
|
|
if(count < 1) return;
|
2019-07-30 09:05:54 -07:00
|
|
|
ALeffectslotArray *curarray{context->mActiveAuxSlots.load(std::memory_order_acquire)};
|
2018-11-20 09:47:49 -08:00
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
2019-01-11 07:28:44 -08:00
|
|
|
ALeffectslotArray *newarray = ALeffectslot::CreatePtrArray(curarray->size());
|
2018-11-20 09:47:49 -08:00
|
|
|
|
|
|
|
/* Copy each element in curarray to newarray whose ID is not in slotids. */
|
|
|
|
const ALuint *slotids_end{slotids + count};
|
2019-01-09 18:29:22 -08:00
|
|
|
auto slotiter = std::copy_if(curarray->begin(), curarray->end(), newarray->begin(),
|
2018-11-20 09:47:49 -08:00
|
|
|
[slotids, slotids_end](const ALeffectslot *slot) -> bool
|
|
|
|
{ return std::find(slotids, slotids_end, slot->id) == slotids_end; }
|
|
|
|
);
|
|
|
|
|
2019-01-11 07:28:44 -08:00
|
|
|
/* Reallocate with the new size. */
|
|
|
|
auto newsize = static_cast<size_t>(std::distance(newarray->begin(), slotiter));
|
2019-08-04 11:59:14 -07:00
|
|
|
if LIKELY(newsize != newarray->size())
|
2019-01-11 07:28:44 -08:00
|
|
|
{
|
|
|
|
curarray = newarray;
|
|
|
|
newarray = ALeffectslot::CreatePtrArray(newsize);
|
|
|
|
std::copy_n(curarray->begin(), newsize, newarray->begin());
|
|
|
|
|
|
|
|
delete curarray;
|
|
|
|
curarray = nullptr;
|
|
|
|
}
|
2020-01-18 18:53:58 -08:00
|
|
|
std::uninitialized_fill_n(newarray->end(), newsize, nullptr);
|
2018-11-20 09:47:49 -08:00
|
|
|
|
2019-07-30 09:05:54 -07:00
|
|
|
curarray = context->mActiveAuxSlots.exchange(newarray, std::memory_order_acq_rel);
|
2020-03-03 20:32:44 -08:00
|
|
|
context->mDevice->waitForMix();
|
|
|
|
|
2020-01-18 18:53:58 -08:00
|
|
|
al::destroy_n(curarray->end(), curarray->size());
|
2019-01-09 18:29:22 -08:00
|
|
|
delete curarray;
|
2018-11-20 09:47:49 -08:00
|
|
|
}
|
|
|
|
|
2018-01-27 17:24:18 -08:00
|
|
|
|
2019-09-12 06:29:32 -07:00
|
|
|
bool EnsureEffectSlots(ALCcontext *context, size_t needed)
|
2019-02-20 22:00:26 -08:00
|
|
|
{
|
2019-09-12 06:29:32 -07:00
|
|
|
size_t count{std::accumulate(context->mEffectSlotList.cbegin(),
|
|
|
|
context->mEffectSlotList.cend(), size_t{0},
|
|
|
|
[](size_t cur, const EffectSlotSubList &sublist) noexcept -> size_t
|
2019-09-12 12:14:23 -07:00
|
|
|
{ return cur + static_cast<ALuint>(POPCNT64(sublist.FreeMask)); }
|
2019-09-12 06:29:32 -07:00
|
|
|
)};
|
|
|
|
|
|
|
|
while(needed > count)
|
2019-02-20 22:00:26 -08:00
|
|
|
{
|
2019-08-04 11:59:14 -07:00
|
|
|
if UNLIKELY(context->mEffectSlotList.size() >= 1<<25)
|
2019-09-12 06:29:32 -07:00
|
|
|
return false;
|
2019-02-20 22:00:26 -08:00
|
|
|
|
2019-09-12 06:29:32 -07:00
|
|
|
context->mEffectSlotList.emplace_back();
|
|
|
|
auto sublist = context->mEffectSlotList.end() - 1;
|
2019-02-20 22:00:26 -08:00
|
|
|
sublist->FreeMask = ~0_u64;
|
2019-09-12 06:29:32 -07:00
|
|
|
sublist->EffectSlots = static_cast<ALeffectslot*>(
|
|
|
|
al_calloc(alignof(ALeffectslot), sizeof(ALeffectslot)*64));
|
2019-08-04 11:59:14 -07:00
|
|
|
if UNLIKELY(!sublist->EffectSlots)
|
2019-02-20 22:00:26 -08:00
|
|
|
{
|
2019-07-30 09:05:54 -07:00
|
|
|
context->mEffectSlotList.pop_back();
|
2019-09-12 06:29:32 -07:00
|
|
|
return false;
|
2019-02-20 22:00:26 -08:00
|
|
|
}
|
2019-09-12 06:29:32 -07:00
|
|
|
count += 64;
|
2019-02-20 22:00:26 -08:00
|
|
|
}
|
2019-09-12 06:29:32 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ALeffectslot *AllocEffectSlot(ALCcontext *context)
|
|
|
|
{
|
|
|
|
auto sublist = std::find_if(context->mEffectSlotList.begin(), context->mEffectSlotList.end(),
|
|
|
|
[](const EffectSlotSubList &entry) noexcept -> bool
|
|
|
|
{ return entry.FreeMask != 0; }
|
|
|
|
);
|
|
|
|
auto lidx = static_cast<ALuint>(std::distance(context->mEffectSlotList.begin(), sublist));
|
|
|
|
auto slidx = static_cast<ALuint>(CTZ64(sublist->FreeMask));
|
2019-02-20 22:00:26 -08:00
|
|
|
|
2019-09-01 17:54:17 -07:00
|
|
|
ALeffectslot *slot{::new (sublist->EffectSlots + slidx) ALeffectslot{}};
|
2020-05-10 20:16:43 -07:00
|
|
|
if(ALenum err{slot->init()})
|
2019-02-20 22:00:26 -08:00
|
|
|
{
|
2019-06-05 17:25:08 -07:00
|
|
|
al::destroy_at(slot);
|
2019-07-30 21:32:05 -07:00
|
|
|
context->setError(err, "Effect slot object initialization failed");
|
2019-02-20 22:00:26 -08:00
|
|
|
return nullptr;
|
|
|
|
}
|
2019-09-12 06:29:32 -07:00
|
|
|
aluInitEffectPanning(slot, context->mDevice.get());
|
2019-02-20 22:00:26 -08:00
|
|
|
|
|
|
|
/* Add 1 to avoid source ID 0. */
|
|
|
|
slot->id = ((lidx<<6) | slidx) + 1;
|
|
|
|
|
2019-07-30 09:05:54 -07:00
|
|
|
context->mNumEffectSlots += 1;
|
2019-02-20 22:00:26 -08:00
|
|
|
sublist->FreeMask &= ~(1_u64 << slidx);
|
|
|
|
|
|
|
|
return slot;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FreeEffectSlot(ALCcontext *context, ALeffectslot *slot)
|
|
|
|
{
|
2019-09-11 05:53:10 -07:00
|
|
|
const ALuint id{slot->id - 1};
|
|
|
|
const size_t lidx{id >> 6};
|
2019-09-12 06:29:32 -07:00
|
|
|
const ALuint slidx{id & 0x3f};
|
2019-02-20 22:00:26 -08:00
|
|
|
|
2019-06-05 17:25:08 -07:00
|
|
|
al::destroy_at(slot);
|
2019-02-20 22:00:26 -08:00
|
|
|
|
2019-07-30 09:05:54 -07:00
|
|
|
context->mEffectSlotList[lidx].FreeMask |= 1_u64 << slidx;
|
|
|
|
context->mNumEffectSlots--;
|
2019-02-20 22:00:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-25 06:17:36 -07:00
|
|
|
#define DO_UPDATEPROPS() do { \
|
2019-07-30 09:05:54 -07:00
|
|
|
if(!context->mDeferUpdates.load(std::memory_order_acquire)) \
|
2020-05-10 20:16:43 -07:00
|
|
|
slot->updateProps(context.get()); \
|
2016-08-25 06:17:36 -07:00
|
|
|
else \
|
2018-11-20 10:45:01 -08:00
|
|
|
slot->PropsClean.clear(std::memory_order_release); \
|
2016-08-25 06:17:36 -07:00
|
|
|
} while(0)
|
|
|
|
|
2018-11-20 09:47:49 -08:00
|
|
|
} // namespace
|
2010-05-12 02:20:14 -07:00
|
|
|
|
2019-01-11 07:28:44 -08:00
|
|
|
ALeffectslotArray *ALeffectslot::CreatePtrArray(size_t count) noexcept
|
|
|
|
{
|
|
|
|
/* Allocate space for twice as many pointers, so the mixer has scratch
|
|
|
|
* space to store a sorted list during mixing.
|
|
|
|
*/
|
2019-06-03 22:58:56 -07:00
|
|
|
void *ptr{al_calloc(alignof(ALeffectslotArray), ALeffectslotArray::Sizeof(count*2))};
|
2019-01-11 07:28:44 -08:00
|
|
|
return new (ptr) ALeffectslotArray{count};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-28 14:48:12 -07:00
|
|
|
AL_API void AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots)
|
2019-04-10 17:47:13 -07:00
|
|
|
START_API_FUNC
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2018-11-20 09:47:49 -08:00
|
|
|
ContextRef context{GetContextRef()};
|
2019-08-04 11:59:14 -07:00
|
|
|
if UNLIKELY(!context) return;
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2019-09-12 11:59:36 -07:00
|
|
|
if UNLIKELY(n < 0)
|
|
|
|
context->setError(AL_INVALID_VALUE, "Generating %d effect slots", n);
|
|
|
|
if UNLIKELY(n <= 0) return;
|
2014-04-10 20:49:01 -07:00
|
|
|
|
2019-09-12 06:29:32 -07:00
|
|
|
std::unique_lock<std::mutex> slotlock{context->mEffectSlotLock};
|
|
|
|
ALCdevice *device{context->mDevice.get()};
|
|
|
|
if(static_cast<ALuint>(n) > device->AuxiliaryEffectSlotMax-context->mNumEffectSlots)
|
|
|
|
{
|
|
|
|
context->setError(AL_OUT_OF_MEMORY, "Exceeding %u effect slot limit (%u + %d)",
|
|
|
|
device->AuxiliaryEffectSlotMax, context->mNumEffectSlots, n);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(!EnsureEffectSlots(context.get(), static_cast<ALuint>(n)))
|
|
|
|
{
|
|
|
|
context->setError(AL_OUT_OF_MEMORY, "Failed to allocate %d effectslot%s", n,
|
|
|
|
(n==1) ? "" : "s");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-20 22:00:26 -08:00
|
|
|
if(n == 1)
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2019-02-20 22:00:26 -08:00
|
|
|
ALeffectslot *slot{AllocEffectSlot(context.get())};
|
|
|
|
if(!slot) return;
|
|
|
|
effectslots[0] = slot->id;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-12 06:29:32 -07:00
|
|
|
al::vector<ALuint> ids;
|
2019-09-15 02:09:05 +02:00
|
|
|
ALsizei count{n};
|
|
|
|
ids.reserve(static_cast<ALuint>(count));
|
2019-09-12 06:29:32 -07:00
|
|
|
do {
|
|
|
|
ALeffectslot *slot{AllocEffectSlot(context.get())};
|
|
|
|
if(!slot)
|
2018-09-14 14:53:35 -07:00
|
|
|
{
|
2019-09-12 06:29:32 -07:00
|
|
|
slotlock.unlock();
|
|
|
|
alDeleteAuxiliaryEffectSlots(static_cast<ALsizei>(ids.size()), ids.data());
|
|
|
|
return;
|
2018-09-14 14:53:35 -07:00
|
|
|
}
|
2019-09-12 06:29:32 -07:00
|
|
|
ids.emplace_back(slot->id);
|
2019-09-15 02:09:05 +02:00
|
|
|
} while(--count);
|
2019-09-12 06:29:32 -07:00
|
|
|
std::copy(ids.cbegin(), ids.cend(), effectslots);
|
2013-10-07 11:30:11 -07:00
|
|
|
}
|
2019-02-20 22:00:26 -08:00
|
|
|
|
2019-09-11 05:53:10 -07:00
|
|
|
AddActiveEffectSlots(effectslots, static_cast<ALuint>(n), context.get());
|
2007-12-17 17:43:19 -08:00
|
|
|
}
|
2019-04-10 17:47:13 -07:00
|
|
|
END_API_FUNC
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2020-04-28 14:48:12 -07:00
|
|
|
AL_API void AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, const ALuint *effectslots)
|
2019-04-10 17:47:13 -07:00
|
|
|
START_API_FUNC
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2018-11-20 09:47:49 -08:00
|
|
|
ContextRef context{GetContextRef()};
|
2019-08-04 11:59:14 -07:00
|
|
|
if UNLIKELY(!context) return;
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2019-09-12 17:10:33 -07:00
|
|
|
if UNLIKELY(n < 0)
|
|
|
|
context->setError(AL_INVALID_VALUE, "Deleting %d effect slots", n);
|
|
|
|
if UNLIKELY(n <= 0) return;
|
2018-02-22 12:03:52 -08:00
|
|
|
|
2019-07-30 09:05:54 -07:00
|
|
|
std::lock_guard<std::mutex> _{context->mEffectSlotLock};
|
2019-09-12 17:10:33 -07:00
|
|
|
auto validate_slot = [&context](const ALuint id) -> bool
|
|
|
|
{
|
|
|
|
ALeffectslot *slot{LookupEffectSlot(context.get(), id)};
|
|
|
|
if UNLIKELY(!slot)
|
2018-11-20 09:47:49 -08:00
|
|
|
{
|
2019-09-12 17:10:33 -07:00
|
|
|
context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", id);
|
2018-11-20 09:47:49 -08:00
|
|
|
return false;
|
|
|
|
}
|
2019-09-12 17:10:33 -07:00
|
|
|
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;
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2018-11-20 09:47:49 -08:00
|
|
|
// All effectslots are valid, remove and delete them
|
2019-09-11 05:53:10 -07:00
|
|
|
RemoveActiveEffectSlots(effectslots, static_cast<ALuint>(n), context.get());
|
2019-09-12 17:10:33 -07:00
|
|
|
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);
|
2007-12-17 17:43:19 -08:00
|
|
|
}
|
2019-04-10 17:47:13 -07:00
|
|
|
END_API_FUNC
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2010-03-23 17:44:01 -07:00
|
|
|
AL_API ALboolean AL_APIENTRY alIsAuxiliaryEffectSlot(ALuint effectslot)
|
2019-04-10 17:47:13 -07:00
|
|
|
START_API_FUNC
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2018-11-20 09:47:49 -08:00
|
|
|
ContextRef context{GetContextRef()};
|
2019-08-04 11:59:14 -07:00
|
|
|
if LIKELY(context)
|
2018-11-20 09:47:49 -08:00
|
|
|
{
|
2019-07-30 09:05:54 -07:00
|
|
|
std::lock_guard<std::mutex> _{context->mEffectSlotLock};
|
2018-11-20 09:47:49 -08:00
|
|
|
if(LookupEffectSlot(context.get(), effectslot) != nullptr)
|
|
|
|
return AL_TRUE;
|
|
|
|
}
|
|
|
|
return AL_FALSE;
|
2007-12-17 17:43:19 -08:00
|
|
|
}
|
2019-04-10 17:47:13 -07:00
|
|
|
END_API_FUNC
|
|
|
|
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2020-04-28 14:48:12 -07:00
|
|
|
AL_API void AL_APIENTRY alAuxiliaryEffectSloti(ALuint effectslot, ALenum param, ALint value)
|
2019-04-10 17:47:13 -07:00
|
|
|
START_API_FUNC
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2018-11-20 09:47:49 -08:00
|
|
|
ContextRef context{GetContextRef()};
|
2019-08-04 11:59:14 -07:00
|
|
|
if UNLIKELY(!context) return;
|
2018-11-20 09:47:49 -08:00
|
|
|
|
2019-07-30 09:05:54 -07:00
|
|
|
std::lock_guard<std::mutex> _{context->mPropLock};
|
|
|
|
std::lock_guard<std::mutex> __{context->mEffectSlotLock};
|
2018-11-20 09:47:49 -08:00
|
|
|
ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot);
|
2019-08-04 11:59:14 -07:00
|
|
|
if UNLIKELY(!slot)
|
2019-07-30 21:32:05 -07:00
|
|
|
SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot);
|
2018-11-20 09:47:49 -08:00
|
|
|
|
2018-12-24 15:52:37 -08:00
|
|
|
ALeffectslot *target{};
|
2020-08-24 16:08:09 -07:00
|
|
|
ALbuffer *buffer{};
|
2018-11-20 09:47:49 -08:00
|
|
|
ALCdevice *device{};
|
|
|
|
ALenum err{};
|
2013-10-07 11:30:11 -07:00
|
|
|
switch(param)
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2013-10-07 11:30:11 -07:00
|
|
|
case AL_EFFECTSLOT_EFFECT:
|
2019-08-01 19:44:09 -07:00
|
|
|
device = context->mDevice.get();
|
2016-05-12 23:12:11 -07:00
|
|
|
|
2020-08-24 16:08:09 -07:00
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> ___{device->EffectLock};
|
2019-09-11 05:53:10 -07:00
|
|
|
ALeffect *effect{value ? LookupEffect(device, static_cast<ALuint>(value)) : nullptr};
|
2018-11-20 09:47:49 -08:00
|
|
|
if(!(value == 0 || effect != nullptr))
|
2019-07-30 21:32:05 -07:00
|
|
|
SETERR_RETURN(context, AL_INVALID_VALUE,, "Invalid effect ID %u", value);
|
2020-05-10 20:16:43 -07:00
|
|
|
err = slot->initEffect(effect, context.get());
|
2016-05-12 23:12:11 -07:00
|
|
|
}
|
2013-10-07 11:30:11 -07:00
|
|
|
if(err != AL_NO_ERROR)
|
2018-11-20 09:47:49 -08:00
|
|
|
{
|
2019-07-30 21:32:05 -07:00
|
|
|
context->setError(err, "Effect initialization failed");
|
2018-11-20 09:47:49 -08:00
|
|
|
return;
|
|
|
|
}
|
2013-10-07 11:30:11 -07:00
|
|
|
break;
|
2007-12-18 14:22:59 -08:00
|
|
|
|
2013-10-07 11:30:11 -07:00
|
|
|
case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO:
|
|
|
|
if(!(value == AL_TRUE || value == AL_FALSE))
|
2019-07-30 21:32:05 -07:00
|
|
|
SETERR_RETURN(context, AL_INVALID_VALUE,,
|
|
|
|
"Effect slot auxiliary send auto out of range");
|
2020-03-28 15:37:34 -07:00
|
|
|
slot->AuxSendAuto = !!value;
|
2013-10-07 11:30:11 -07:00
|
|
|
break;
|
2007-12-18 17:41:44 -08:00
|
|
|
|
2018-12-24 15:52:37 -08:00
|
|
|
case AL_EFFECTSLOT_TARGET_SOFT:
|
2019-09-11 05:53:10 -07:00
|
|
|
target = LookupEffectSlot(context.get(), static_cast<ALuint>(value));
|
2018-12-24 15:52:37 -08:00
|
|
|
if(value && !target)
|
2019-07-30 21:32:05 -07:00
|
|
|
SETERR_RETURN(context, AL_INVALID_VALUE,, "Invalid effect slot target ID");
|
2018-12-24 15:52:37 -08:00
|
|
|
if(target)
|
|
|
|
{
|
|
|
|
ALeffectslot *checker{target};
|
|
|
|
while(checker && checker != slot)
|
|
|
|
checker = checker->Target;
|
|
|
|
if(checker)
|
2019-07-30 21:32:05 -07:00
|
|
|
SETERR_RETURN(context, AL_INVALID_OPERATION,,
|
2018-12-24 15:52:37 -08:00
|
|
|
"Setting target of effect slot ID %u to %u creates circular chain", slot->id,
|
|
|
|
target->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ALeffectslot *oldtarget{slot->Target})
|
|
|
|
{
|
|
|
|
/* We must force an update if there was an existing effect slot
|
|
|
|
* target, in case it's about to be deleted.
|
|
|
|
*/
|
2019-08-01 13:28:53 -07:00
|
|
|
if(target) IncrementRef(target->ref);
|
|
|
|
DecrementRef(oldtarget->ref);
|
2018-12-24 15:52:37 -08:00
|
|
|
slot->Target = target;
|
2020-05-10 20:16:43 -07:00
|
|
|
slot->updateProps(context.get());
|
2018-12-24 15:52:37 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-01 13:28:53 -07:00
|
|
|
if(target) IncrementRef(target->ref);
|
2018-12-24 15:52:37 -08:00
|
|
|
slot->Target = target;
|
|
|
|
break;
|
|
|
|
|
2020-08-24 16:08:09 -07:00
|
|
|
case AL_BUFFER:
|
|
|
|
device = context->mDevice.get();
|
|
|
|
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> ___{device->BufferLock};
|
|
|
|
if(value)
|
|
|
|
{
|
|
|
|
buffer = LookupBuffer(device, static_cast<ALuint>(value));
|
|
|
|
if(!buffer) SETERR_RETURN(context, AL_INVALID_VALUE,, "Invalid buffer ID");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(buffer) IncrementRef(buffer->ref);
|
|
|
|
if(ALbuffer *oldbuffer{slot->Buffer})
|
|
|
|
DecrementRef(oldbuffer->ref);
|
|
|
|
slot->Buffer = buffer;
|
|
|
|
|
|
|
|
/* TODO: Create a shared effectstate representation of the buffer. */
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-10-07 11:30:11 -07:00
|
|
|
default:
|
2019-07-30 21:32:05 -07:00
|
|
|
SETERR_RETURN(context, AL_INVALID_ENUM,, "Invalid effect slot integer property 0x%04x",
|
|
|
|
param);
|
2007-12-17 17:43:19 -08:00
|
|
|
}
|
2016-08-25 06:17:36 -07:00
|
|
|
DO_UPDATEPROPS();
|
2007-12-17 17:43:19 -08:00
|
|
|
}
|
2019-04-10 17:47:13 -07:00
|
|
|
END_API_FUNC
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2020-04-28 14:48:12 -07:00
|
|
|
AL_API void AL_APIENTRY alAuxiliaryEffectSlotiv(ALuint effectslot, ALenum param, const ALint *values)
|
2019-04-10 17:47:13 -07:00
|
|
|
START_API_FUNC
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2011-06-16 09:14:41 -07:00
|
|
|
switch(param)
|
|
|
|
{
|
2013-10-07 11:30:11 -07:00
|
|
|
case AL_EFFECTSLOT_EFFECT:
|
|
|
|
case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO:
|
2018-12-24 15:52:37 -08:00
|
|
|
case AL_EFFECTSLOT_TARGET_SOFT:
|
2020-08-24 16:08:09 -07:00
|
|
|
case AL_BUFFER:
|
2013-10-07 11:30:11 -07:00
|
|
|
alAuxiliaryEffectSloti(effectslot, param, values[0]);
|
|
|
|
return;
|
2011-06-16 09:14:41 -07:00
|
|
|
}
|
|
|
|
|
2018-11-20 09:47:49 -08:00
|
|
|
ContextRef context{GetContextRef()};
|
2019-08-04 11:59:14 -07:00
|
|
|
if UNLIKELY(!context) return;
|
2018-11-20 09:47:49 -08:00
|
|
|
|
2019-07-30 09:05:54 -07:00
|
|
|
std::lock_guard<std::mutex> _{context->mEffectSlotLock};
|
2018-11-20 09:47:49 -08:00
|
|
|
ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot);
|
2019-08-04 11:59:14 -07:00
|
|
|
if UNLIKELY(!slot)
|
2019-07-30 21:32:05 -07:00
|
|
|
SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot);
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2013-10-07 11:30:11 -07:00
|
|
|
switch(param)
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2013-10-07 11:30:11 -07:00
|
|
|
default:
|
2019-07-30 21:32:05 -07:00
|
|
|
SETERR_RETURN(context, AL_INVALID_ENUM,,
|
|
|
|
"Invalid effect slot integer-vector property 0x%04x", param);
|
2007-12-17 17:43:19 -08:00
|
|
|
}
|
|
|
|
}
|
2019-04-10 17:47:13 -07:00
|
|
|
END_API_FUNC
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2020-04-28 14:48:12 -07:00
|
|
|
AL_API void AL_APIENTRY alAuxiliaryEffectSlotf(ALuint effectslot, ALenum param, ALfloat value)
|
2019-04-10 17:47:13 -07:00
|
|
|
START_API_FUNC
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2018-11-20 09:47:49 -08:00
|
|
|
ContextRef context{GetContextRef()};
|
2019-08-04 11:59:14 -07:00
|
|
|
if UNLIKELY(!context) return;
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2019-07-30 09:05:54 -07:00
|
|
|
std::lock_guard<std::mutex> _{context->mPropLock};
|
|
|
|
std::lock_guard<std::mutex> __{context->mEffectSlotLock};
|
2018-11-20 09:47:49 -08:00
|
|
|
ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot);
|
2019-08-04 11:59:14 -07:00
|
|
|
if UNLIKELY(!slot)
|
2019-07-30 21:32:05 -07:00
|
|
|
SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot);
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2013-10-07 11:30:11 -07:00
|
|
|
switch(param)
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2013-10-07 11:30:11 -07:00
|
|
|
case AL_EFFECTSLOT_GAIN:
|
|
|
|
if(!(value >= 0.0f && value <= 1.0f))
|
2019-07-30 21:32:05 -07:00
|
|
|
SETERR_RETURN(context, AL_INVALID_VALUE,, "Effect slot gain out of range");
|
2013-10-07 11:30:11 -07:00
|
|
|
slot->Gain = value;
|
|
|
|
break;
|
2007-12-18 15:47:24 -08:00
|
|
|
|
2013-10-07 11:30:11 -07:00
|
|
|
default:
|
2019-07-30 21:32:05 -07:00
|
|
|
SETERR_RETURN(context, AL_INVALID_ENUM,, "Invalid effect slot float property 0x%04x",
|
|
|
|
param);
|
2007-12-17 17:43:19 -08:00
|
|
|
}
|
2016-08-25 06:17:36 -07:00
|
|
|
DO_UPDATEPROPS();
|
2007-12-17 17:43:19 -08:00
|
|
|
}
|
2019-04-10 17:47:13 -07:00
|
|
|
END_API_FUNC
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2020-04-28 14:48:12 -07:00
|
|
|
AL_API void AL_APIENTRY alAuxiliaryEffectSlotfv(ALuint effectslot, ALenum param, const ALfloat *values)
|
2019-04-10 17:47:13 -07:00
|
|
|
START_API_FUNC
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2011-06-16 09:14:41 -07:00
|
|
|
switch(param)
|
|
|
|
{
|
2013-10-07 11:30:11 -07:00
|
|
|
case AL_EFFECTSLOT_GAIN:
|
|
|
|
alAuxiliaryEffectSlotf(effectslot, param, values[0]);
|
|
|
|
return;
|
2011-06-16 09:14:41 -07:00
|
|
|
}
|
|
|
|
|
2018-11-20 09:47:49 -08:00
|
|
|
ContextRef context{GetContextRef()};
|
2019-08-04 11:59:14 -07:00
|
|
|
if UNLIKELY(!context) return;
|
2018-11-20 09:47:49 -08:00
|
|
|
|
2019-07-30 09:05:54 -07:00
|
|
|
std::lock_guard<std::mutex> _{context->mEffectSlotLock};
|
2018-11-20 09:47:49 -08:00
|
|
|
ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot);
|
2019-08-04 11:59:14 -07:00
|
|
|
if UNLIKELY(!slot)
|
2019-07-30 21:32:05 -07:00
|
|
|
SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot);
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2013-10-07 11:30:11 -07:00
|
|
|
switch(param)
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2013-10-07 11:30:11 -07:00
|
|
|
default:
|
2019-07-30 21:32:05 -07:00
|
|
|
SETERR_RETURN(context, AL_INVALID_ENUM,,
|
|
|
|
"Invalid effect slot float-vector property 0x%04x", param);
|
2007-12-17 17:43:19 -08:00
|
|
|
}
|
|
|
|
}
|
2019-04-10 17:47:13 -07:00
|
|
|
END_API_FUNC
|
|
|
|
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2020-04-28 14:48:12 -07:00
|
|
|
AL_API void AL_APIENTRY alGetAuxiliaryEffectSloti(ALuint effectslot, ALenum param, ALint *value)
|
2019-04-10 17:47:13 -07:00
|
|
|
START_API_FUNC
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2018-11-20 09:47:49 -08:00
|
|
|
ContextRef context{GetContextRef()};
|
2019-08-04 11:59:14 -07:00
|
|
|
if UNLIKELY(!context) return;
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2019-07-30 09:05:54 -07:00
|
|
|
std::lock_guard<std::mutex> _{context->mEffectSlotLock};
|
2018-11-20 09:47:49 -08:00
|
|
|
ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot);
|
2019-08-04 11:59:14 -07:00
|
|
|
if UNLIKELY(!slot)
|
2019-07-30 21:32:05 -07:00
|
|
|
SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot);
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2013-10-07 11:30:11 -07:00
|
|
|
switch(param)
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2013-10-07 11:30:11 -07:00
|
|
|
case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO:
|
2020-03-28 15:37:34 -07:00
|
|
|
*value = slot->AuxSendAuto ? AL_TRUE : AL_FALSE;
|
2013-10-07 11:30:11 -07:00
|
|
|
break;
|
2007-12-18 17:41:44 -08:00
|
|
|
|
2018-12-24 15:52:37 -08:00
|
|
|
case AL_EFFECTSLOT_TARGET_SOFT:
|
2019-09-11 05:53:10 -07:00
|
|
|
if(auto *target = slot->Target)
|
|
|
|
*value = static_cast<ALint>(target->id);
|
|
|
|
else
|
|
|
|
*value = 0;
|
2018-12-24 15:52:37 -08:00
|
|
|
break;
|
|
|
|
|
2020-08-24 16:08:09 -07:00
|
|
|
case AL_BUFFER:
|
|
|
|
if(auto *buffer = slot->Buffer)
|
|
|
|
*value = static_cast<ALint>(buffer->id);
|
|
|
|
else
|
|
|
|
*value = 0;
|
|
|
|
break;
|
|
|
|
|
2013-10-07 11:30:11 -07:00
|
|
|
default:
|
2019-07-30 21:32:05 -07:00
|
|
|
context->setError(AL_INVALID_ENUM, "Invalid effect slot integer property 0x%04x", param);
|
2007-12-17 17:43:19 -08:00
|
|
|
}
|
|
|
|
}
|
2019-04-10 17:47:13 -07:00
|
|
|
END_API_FUNC
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2020-04-28 14:48:12 -07:00
|
|
|
AL_API void AL_APIENTRY alGetAuxiliaryEffectSlotiv(ALuint effectslot, ALenum param, ALint *values)
|
2019-04-10 17:47:13 -07:00
|
|
|
START_API_FUNC
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2011-06-16 09:14:41 -07:00
|
|
|
switch(param)
|
|
|
|
{
|
2013-10-07 11:30:11 -07:00
|
|
|
case AL_EFFECTSLOT_EFFECT:
|
|
|
|
case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO:
|
2018-12-24 15:52:37 -08:00
|
|
|
case AL_EFFECTSLOT_TARGET_SOFT:
|
2020-08-24 16:08:09 -07:00
|
|
|
case AL_BUFFER:
|
2013-10-07 11:30:11 -07:00
|
|
|
alGetAuxiliaryEffectSloti(effectslot, param, values);
|
|
|
|
return;
|
2011-06-16 09:14:41 -07:00
|
|
|
}
|
|
|
|
|
2018-11-20 09:47:49 -08:00
|
|
|
ContextRef context{GetContextRef()};
|
2019-08-04 11:59:14 -07:00
|
|
|
if UNLIKELY(!context) return;
|
2018-11-20 09:47:49 -08:00
|
|
|
|
2019-07-30 09:05:54 -07:00
|
|
|
std::lock_guard<std::mutex> _{context->mEffectSlotLock};
|
2018-11-20 09:47:49 -08:00
|
|
|
ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot);
|
2019-08-04 11:59:14 -07:00
|
|
|
if UNLIKELY(!slot)
|
2019-07-30 21:32:05 -07:00
|
|
|
SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot);
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2013-10-07 11:30:11 -07:00
|
|
|
switch(param)
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2013-10-07 11:30:11 -07:00
|
|
|
default:
|
2019-07-30 21:32:05 -07:00
|
|
|
context->setError(AL_INVALID_ENUM, "Invalid effect slot integer-vector property 0x%04x",
|
|
|
|
param);
|
2007-12-17 17:43:19 -08:00
|
|
|
}
|
|
|
|
}
|
2019-04-10 17:47:13 -07:00
|
|
|
END_API_FUNC
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2020-04-28 14:48:12 -07:00
|
|
|
AL_API void AL_APIENTRY alGetAuxiliaryEffectSlotf(ALuint effectslot, ALenum param, ALfloat *value)
|
2019-04-10 17:47:13 -07:00
|
|
|
START_API_FUNC
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2018-11-20 09:47:49 -08:00
|
|
|
ContextRef context{GetContextRef()};
|
2019-08-04 11:59:14 -07:00
|
|
|
if UNLIKELY(!context) return;
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2019-07-30 09:05:54 -07:00
|
|
|
std::lock_guard<std::mutex> _{context->mEffectSlotLock};
|
2018-11-20 09:47:49 -08:00
|
|
|
ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot);
|
2019-08-04 11:59:14 -07:00
|
|
|
if UNLIKELY(!slot)
|
2019-07-30 21:32:05 -07:00
|
|
|
SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot);
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2013-10-07 11:30:11 -07:00
|
|
|
switch(param)
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2013-10-07 11:30:11 -07:00
|
|
|
case AL_EFFECTSLOT_GAIN:
|
|
|
|
*value = slot->Gain;
|
|
|
|
break;
|
2007-12-18 15:47:24 -08:00
|
|
|
|
2013-10-07 11:30:11 -07:00
|
|
|
default:
|
2019-07-30 21:32:05 -07:00
|
|
|
context->setError(AL_INVALID_ENUM, "Invalid effect slot float property 0x%04x", param);
|
2007-12-17 17:43:19 -08:00
|
|
|
}
|
|
|
|
}
|
2019-04-10 17:47:13 -07:00
|
|
|
END_API_FUNC
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2020-04-28 14:48:12 -07:00
|
|
|
AL_API void AL_APIENTRY alGetAuxiliaryEffectSlotfv(ALuint effectslot, ALenum param, ALfloat *values)
|
2019-04-10 17:47:13 -07:00
|
|
|
START_API_FUNC
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2011-06-16 09:14:41 -07:00
|
|
|
switch(param)
|
|
|
|
{
|
2013-10-07 11:30:11 -07:00
|
|
|
case AL_EFFECTSLOT_GAIN:
|
|
|
|
alGetAuxiliaryEffectSlotf(effectslot, param, values);
|
|
|
|
return;
|
2011-06-16 09:14:41 -07:00
|
|
|
}
|
|
|
|
|
2018-11-20 09:47:49 -08:00
|
|
|
ContextRef context{GetContextRef()};
|
2019-08-04 11:59:14 -07:00
|
|
|
if UNLIKELY(!context) return;
|
2018-11-20 09:47:49 -08:00
|
|
|
|
2019-07-30 09:05:54 -07:00
|
|
|
std::lock_guard<std::mutex> _{context->mEffectSlotLock};
|
2018-11-20 09:47:49 -08:00
|
|
|
ALeffectslot *slot = LookupEffectSlot(context.get(), effectslot);
|
2019-08-04 11:59:14 -07:00
|
|
|
if UNLIKELY(!slot)
|
2019-07-30 21:32:05 -07:00
|
|
|
SETERR_RETURN(context, AL_INVALID_NAME,, "Invalid effect slot ID %u", effectslot);
|
2007-12-17 17:43:19 -08:00
|
|
|
|
2013-10-07 11:30:11 -07:00
|
|
|
switch(param)
|
2007-12-17 17:43:19 -08:00
|
|
|
{
|
2013-10-07 11:30:11 -07:00
|
|
|
default:
|
2019-07-30 21:32:05 -07:00
|
|
|
context->setError(AL_INVALID_ENUM, "Invalid effect slot float-vector property 0x%04x",
|
|
|
|
param);
|
2007-12-17 17:43:19 -08:00
|
|
|
}
|
|
|
|
}
|
2019-04-10 17:47:13 -07:00
|
|
|
END_API_FUNC
|
2007-12-17 17:43:19 -08:00
|
|
|
|
|
|
|
|
2020-05-10 20:16:43 -07:00
|
|
|
ALeffectslot::~ALeffectslot()
|
|
|
|
{
|
|
|
|
if(Target)
|
|
|
|
DecrementRef(Target->ref);
|
|
|
|
Target = nullptr;
|
2020-08-24 16:08:09 -07:00
|
|
|
if(Buffer)
|
|
|
|
DecrementRef(Buffer->ref);
|
|
|
|
Buffer = nullptr;
|
2020-05-10 20:16:43 -07:00
|
|
|
|
|
|
|
ALeffectslotProps *props{Params.Update.load()};
|
|
|
|
if(props)
|
|
|
|
{
|
|
|
|
TRACE("Freed unapplied AuxiliaryEffectSlot update %p\n",
|
|
|
|
decltype(std::declval<void*>()){props});
|
|
|
|
delete props;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(Params.mEffectState)
|
|
|
|
Params.mEffectState->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
ALenum ALeffectslot::init()
|
|
|
|
{
|
|
|
|
EffectStateFactory *factory{getFactoryByType(Effect.Type)};
|
|
|
|
if(!factory) return AL_INVALID_VALUE;
|
2020-08-24 16:34:53 -07:00
|
|
|
|
|
|
|
Effect.State.reset(factory->create());
|
2020-05-10 20:16:43 -07:00
|
|
|
if(!Effect.State) return AL_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
Effect.State->add_ref();
|
2020-08-24 16:34:53 -07:00
|
|
|
Params.mEffectState = Effect.State.get();
|
2020-05-10 20:16:43 -07:00
|
|
|
return AL_NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
ALenum ALeffectslot::initEffect(ALeffect *effect, ALCcontext *context)
|
2013-03-19 05:39:34 -07:00
|
|
|
{
|
2018-11-20 09:47:49 -08:00
|
|
|
ALenum newtype{effect ? effect->type : AL_EFFECT_NULL};
|
2020-05-10 20:16:43 -07:00
|
|
|
if(newtype != Effect.Type)
|
2011-09-01 18:51:24 -07:00
|
|
|
{
|
2018-11-20 09:47:49 -08:00
|
|
|
EffectStateFactory *factory{getFactoryByType(newtype)};
|
2013-05-21 12:47:18 -07:00
|
|
|
if(!factory)
|
|
|
|
{
|
|
|
|
ERR("Failed to find factory for effect type 0x%04x\n", newtype);
|
|
|
|
return AL_INVALID_ENUM;
|
|
|
|
}
|
2020-08-24 16:34:53 -07:00
|
|
|
al::intrusive_ptr<EffectState> State{factory->create()};
|
2016-05-27 19:40:54 -07:00
|
|
|
if(!State) return AL_OUT_OF_MEMORY;
|
2013-03-19 05:39:34 -07:00
|
|
|
|
2020-05-10 20:16:43 -07:00
|
|
|
ALCdevice *Device{context->mDevice.get()};
|
2018-12-30 21:38:42 -08:00
|
|
|
std::unique_lock<std::mutex> statelock{Device->StateLock};
|
2019-07-04 15:02:12 -07:00
|
|
|
State->mOutTarget = Device->Dry.Buffer;
|
2018-11-21 09:07:02 -08:00
|
|
|
{
|
2020-04-16 17:29:32 -07:00
|
|
|
FPUCtl mixer_mode{};
|
|
|
|
State->deviceUpdate(Device);
|
2018-11-21 09:07:02 -08:00
|
|
|
}
|
2011-09-29 05:25:01 -07:00
|
|
|
|
2016-05-12 19:05:06 -07:00
|
|
|
if(!effect)
|
|
|
|
{
|
2020-05-10 20:16:43 -07:00
|
|
|
Effect.Type = AL_EFFECT_NULL;
|
|
|
|
Effect.Props = EffectProps{};
|
2016-05-12 19:05:06 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-10 20:16:43 -07:00
|
|
|
Effect.Type = effect->type;
|
|
|
|
Effect.Props = effect->Props;
|
2016-05-12 19:05:06 -07:00
|
|
|
}
|
2016-05-12 18:26:33 -07:00
|
|
|
|
2020-08-24 16:34:53 -07:00
|
|
|
Effect.State = std::move(State);
|
2009-05-29 01:32:54 -07:00
|
|
|
}
|
2016-05-12 19:05:06 -07:00
|
|
|
else if(effect)
|
2020-05-10 20:16:43 -07:00
|
|
|
Effect.Props = effect->Props;
|
2012-03-13 14:58:34 -07:00
|
|
|
|
2016-08-25 04:57:58 -07:00
|
|
|
/* Remove state references from old effect slot property updates. */
|
2020-05-10 20:16:43 -07:00
|
|
|
ALeffectslotProps *props{context->mFreeEffectslotProps.load()};
|
2016-08-25 04:57:58 -07:00
|
|
|
while(props)
|
|
|
|
{
|
2018-11-16 18:28:39 -08:00
|
|
|
props->State = nullptr;
|
2018-11-26 18:19:58 -08:00
|
|
|
props = props->next.load(std::memory_order_relaxed);
|
2016-08-25 04:57:58 -07:00
|
|
|
}
|
|
|
|
|
2012-03-13 14:58:34 -07:00
|
|
|
return AL_NO_ERROR;
|
Implement AL_EFFECT_REVERB
Here is a quick description of how the reverb effect works:
+--->---+*(4)
| V new sample
+-----+---+---+ |
|extra|ltr|ref| <- +*(1)
+-----+---+---+
(3,5)*| |*(2)
+-->|
V
out sample
1) Apply master reverb gain to incoming sample and place it at the head of the
buffer. The master reverb gainhf was already applied when the source was
initially mixed.
2) Copy the delayed reflection sample to an output sample and apply the
reflection gain.
3) Apply the late reverb gain to the late reverb sample
4) Copy the end of the buffer, applying a decay gain and the decay hf ratio,
and add to the late reverb.
5) Copy the late reverb sample, adding to the output sample.
Then the head and sampling points are shifted forward, and done again for each
new sample. The extra buffer length is determined by the Reverb Density
property. A value of 0 gives a length of 0.1 seconds (long, with fairly
distinct echos) , and 1 gives 0.075 seconds (short, indistinct echos).
The decay gain is calculated such that after a number of loops to satisfy the
Decay Time, a sample will be 1/32768th as powerful (virtually insignificant to
the resulting output, and only getting further reduced). It is calculated as:
DecayGain = pow(1.0f/32768.0f, 1.0/(DecayTime/ExtraLength));
Things to note: Reverb Diffusion is not currently handled, nor is Decay HF
Limit. Decay HF Ratios above 1 probably give incorrect results. Also, this
method likely sucks, but it's the best I can come up with before release. :)
2008-01-18 21:25:40 -08:00
|
|
|
}
|
|
|
|
|
2020-05-10 20:16:43 -07:00
|
|
|
void ALeffectslot::updateProps(ALCcontext *context)
|
2016-05-12 18:26:33 -07:00
|
|
|
{
|
2016-08-25 18:19:13 -07:00
|
|
|
/* Get an unused property container, or allocate a new one as needed. */
|
2019-07-30 09:05:54 -07:00
|
|
|
ALeffectslotProps *props{context->mFreeEffectslotProps.load(std::memory_order_relaxed)};
|
2016-08-25 04:57:58 -07:00
|
|
|
if(!props)
|
2019-08-13 22:25:59 -07:00
|
|
|
props = new ALeffectslotProps{};
|
2016-08-25 18:19:13 -07:00
|
|
|
else
|
2016-05-12 18:26:33 -07:00
|
|
|
{
|
2018-12-24 19:29:01 -08:00
|
|
|
ALeffectslotProps *next;
|
2016-08-25 18:19:13 -07:00
|
|
|
do {
|
2018-11-19 03:21:58 -08:00
|
|
|
next = props->next.load(std::memory_order_relaxed);
|
2019-07-30 09:05:54 -07:00
|
|
|
} while(context->mFreeEffectslotProps.compare_exchange_weak(props, next,
|
2018-11-19 03:21:58 -08:00
|
|
|
std::memory_order_seq_cst, std::memory_order_acquire) == 0);
|
2016-05-12 18:26:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy in current property values. */
|
2020-05-10 20:16:43 -07:00
|
|
|
props->Gain = Gain;
|
|
|
|
props->AuxSendAuto = AuxSendAuto;
|
|
|
|
props->Target = Target;
|
2016-05-12 18:26:33 -07:00
|
|
|
|
2020-05-10 20:16:43 -07:00
|
|
|
props->Type = Effect.Type;
|
|
|
|
props->Props = Effect.Props;
|
2016-05-12 18:26:33 -07:00
|
|
|
/* Swap out any stale effect state object there may be in the container, to
|
|
|
|
* delete it.
|
|
|
|
*/
|
2020-08-24 16:34:53 -07:00
|
|
|
props->State = Effect.State;
|
2016-05-12 18:26:33 -07:00
|
|
|
|
|
|
|
/* Set the new container for updating internal parameters. */
|
2020-05-10 20:16:43 -07:00
|
|
|
props = Params.Update.exchange(props, std::memory_order_acq_rel);
|
2016-05-12 18:26:33 -07:00
|
|
|
if(props)
|
|
|
|
{
|
|
|
|
/* If there was an unused update container, put it back in the
|
|
|
|
* freelist.
|
|
|
|
*/
|
2018-11-16 18:28:39 -08:00
|
|
|
props->State = nullptr;
|
2019-07-30 09:05:54 -07:00
|
|
|
AtomicReplaceHead(context->mFreeEffectslotProps, props);
|
2016-05-12 18:26:33 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-25 06:17:36 -07:00
|
|
|
void UpdateAllEffectSlotProps(ALCcontext *context)
|
|
|
|
{
|
2019-07-30 09:05:54 -07:00
|
|
|
std::lock_guard<std::mutex> _{context->mEffectSlotLock};
|
|
|
|
ALeffectslotArray *auxslots{context->mActiveAuxSlots.load(std::memory_order_acquire)};
|
2019-01-09 18:29:22 -08:00
|
|
|
for(ALeffectslot *slot : *auxslots)
|
2016-08-25 06:17:36 -07:00
|
|
|
{
|
2018-11-20 10:45:01 -08:00
|
|
|
if(!slot->PropsClean.test_and_set(std::memory_order_acq_rel))
|
2020-05-10 20:16:43 -07:00
|
|
|
slot->updateProps(context);
|
2016-08-25 06:17:36 -07:00
|
|
|
}
|
|
|
|
}
|
2019-02-20 22:00:26 -08:00
|
|
|
|
|
|
|
EffectSlotSubList::~EffectSlotSubList()
|
|
|
|
{
|
|
|
|
uint64_t usemask{~FreeMask};
|
|
|
|
while(usemask)
|
|
|
|
{
|
|
|
|
ALsizei idx{CTZ64(usemask)};
|
2019-06-05 17:25:08 -07:00
|
|
|
al::destroy_at(EffectSlots+idx);
|
2019-02-20 22:00:26 -08:00
|
|
|
usemask &= ~(1_u64 << idx);
|
|
|
|
}
|
|
|
|
FreeMask = ~usemask;
|
|
|
|
al_free(EffectSlots);
|
|
|
|
EffectSlots = nullptr;
|
|
|
|
}
|