Use a separate structure for the context/listener params

This commit is contained in:
Chris Robinson
2020-12-15 17:25:45 -08:00
parent 03358a0d80
commit daf9d46478
7 changed files with 109 additions and 126 deletions
+1 -4
View File
@@ -4,8 +4,8 @@
#include "AL/al.h" #include "AL/al.h"
#include "AL/efx.h" #include "AL/efx.h"
#include "effects/base.h"
#include "al/effects/effects.h" #include "al/effects/effects.h"
#include "alc/effects/base.h"
enum { enum {
@@ -53,9 +53,6 @@ struct ALeffect {
DISABLE_ALLOC() DISABLE_ALLOC()
}; };
inline bool IsReverbEffect(const ALenum type) noexcept
{ return type == AL_EFFECT_REVERB || type == AL_EFFECT_EAXREVERB; }
EffectStateFactory *getFactoryByType(ALenum type); EffectStateFactory *getFactoryByType(ALenum type);
void InitEffect(ALeffect *effect); void InitEffect(ALeffect *effect);
+4 -4
View File
@@ -419,12 +419,12 @@ END_API_FUNC
void UpdateListenerProps(ALCcontext *context) void UpdateListenerProps(ALCcontext *context)
{ {
/* Get an unused proprty container, or allocate a new one as needed. */ /* Get an unused proprty container, or allocate a new one as needed. */
ALlistenerProps *props{context->mFreeListenerProps.load(std::memory_order_acquire)}; ListenerProps *props{context->mFreeListenerProps.load(std::memory_order_acquire)};
if(!props) if(!props)
props = new ALlistenerProps{}; props = new ListenerProps{};
else else
{ {
ALlistenerProps *next; ListenerProps *next;
do { do {
next = props->next.load(std::memory_order_relaxed); next = props->next.load(std::memory_order_relaxed);
} while(context->mFreeListenerProps.compare_exchange_weak(props, next, } while(context->mFreeListenerProps.compare_exchange_weak(props, next,
@@ -441,7 +441,7 @@ void UpdateListenerProps(ALCcontext *context)
props->MetersPerUnit = listener.mMetersPerUnit; props->MetersPerUnit = listener.mMetersPerUnit;
/* Set the new container for updating internal parameters. */ /* Set the new container for updating internal parameters. */
props = listener.Params.Update.exchange(props, std::memory_order_acq_rel); props = context->mParams.ListenerUpdate.exchange(props, std::memory_order_acq_rel);
if(props) if(props)
{ {
/* If there was an unused update container, put it back in the /* If there was an unused update container, put it back in the
-35
View File
@@ -9,23 +9,7 @@
#include "AL/efx.h" #include "AL/efx.h"
#include "almalloc.h" #include "almalloc.h"
#include "vecmat.h"
enum class DistanceModel;
struct ALlistenerProps {
std::array<float,3> Position;
std::array<float,3> Velocity;
std::array<float,3> OrientAt;
std::array<float,3> OrientUp;
float Gain;
float MetersPerUnit;
std::atomic<ALlistenerProps*> next;
DEF_NEWDEL(ALlistenerProps)
};
struct ALlistener { struct ALlistener {
std::array<float,3> Position{{0.0f, 0.0f, 0.0f}}; std::array<float,3> Position{{0.0f, 0.0f, 0.0f}};
@@ -37,25 +21,6 @@ struct ALlistener {
std::atomic_flag PropsClean; std::atomic_flag PropsClean;
struct {
/* Pointer to the most recent property values that are awaiting an
* update.
*/
std::atomic<ALlistenerProps*> Update{nullptr};
alu::Matrix Matrix;
alu::Vector Velocity;
float Gain;
float MetersPerUnit;
float DopplerFactor;
float SpeedOfSound; /* in units per sec! */
bool SourceDistanceModel;
DistanceModel mDistanceModel;
} Params;
ALlistener() { PropsClean.test_and_set(std::memory_order_relaxed); } ALlistener() { PropsClean.test_and_set(std::memory_order_relaxed); }
DISABLE_ALLOC() DISABLE_ALLOC()
+4 -4
View File
@@ -834,12 +834,12 @@ END_API_FUNC
void UpdateContextProps(ALCcontext *context) void UpdateContextProps(ALCcontext *context)
{ {
/* Get an unused proprty container, or allocate a new one as needed. */ /* Get an unused proprty container, or allocate a new one as needed. */
ALcontextProps *props{context->mFreeContextProps.load(std::memory_order_acquire)}; ContextProps *props{context->mFreeContextProps.load(std::memory_order_acquire)};
if(!props) if(!props)
props = new ALcontextProps{}; props = new ContextProps{};
else else
{ {
ALcontextProps *next; ContextProps *next;
do { do {
next = props->next.load(std::memory_order_relaxed); next = props->next.load(std::memory_order_relaxed);
} while(context->mFreeContextProps.compare_exchange_weak(props, next, } while(context->mFreeContextProps.compare_exchange_weak(props, next,
@@ -855,7 +855,7 @@ void UpdateContextProps(ALCcontext *context)
props->mDistanceModel = context->mDistanceModel; props->mDistanceModel = context->mDistanceModel;
/* Set the new container for updating internal parameters. */ /* Set the new container for updating internal parameters. */
props = context->mUpdate.exchange(props, std::memory_order_acq_rel); props = context->mParams.ContextUpdate.exchange(props, std::memory_order_acq_rel);
if(props) if(props)
{ {
/* If there was an unused update container, put it back in the /* If there was an unused update container, put it back in the
+18 -22
View File
@@ -2340,7 +2340,7 @@ ALCcontext::~ALCcontext()
TRACE("Freeing context %p\n", voidp{this}); TRACE("Freeing context %p\n", voidp{this});
size_t count{0}; size_t count{0};
ALcontextProps *cprops{mUpdate.exchange(nullptr, std::memory_order_relaxed)}; ContextProps *cprops{mParams.ContextUpdate.exchange(nullptr, std::memory_order_relaxed)};
if(cprops) if(cprops)
{ {
++count; ++count;
@@ -2349,9 +2349,8 @@ ALCcontext::~ALCcontext()
cprops = mFreeContextProps.exchange(nullptr, std::memory_order_acquire); cprops = mFreeContextProps.exchange(nullptr, std::memory_order_acquire);
while(cprops) while(cprops)
{ {
ALcontextProps *next{cprops->next.load(std::memory_order_relaxed)}; std::unique_ptr<ContextProps> old{cprops};
delete cprops; cprops = old->next.load(std::memory_order_relaxed);
cprops = next;
++count; ++count;
} }
TRACE("Freed %zu context property object%s\n", count, (count==1)?"":"s"); TRACE("Freed %zu context property object%s\n", count, (count==1)?"":"s");
@@ -2368,9 +2367,8 @@ ALCcontext::~ALCcontext()
EffectSlotProps *eprops{mFreeEffectslotProps.exchange(nullptr, std::memory_order_acquire)}; EffectSlotProps *eprops{mFreeEffectslotProps.exchange(nullptr, std::memory_order_acquire)};
while(eprops) while(eprops)
{ {
EffectSlotProps *next{eprops->next.load(std::memory_order_relaxed)}; std::unique_ptr<EffectSlotProps> old{eprops};
delete eprops; eprops = old->next.load(std::memory_order_relaxed);
eprops = next;
++count; ++count;
} }
TRACE("Freed %zu AuxiliaryEffectSlot property object%s\n", count, (count==1)?"":"s"); TRACE("Freed %zu AuxiliaryEffectSlot property object%s\n", count, (count==1)?"":"s");
@@ -2394,9 +2392,8 @@ ALCcontext::~ALCcontext()
VoicePropsItem *vprops{mFreeVoiceProps.exchange(nullptr, std::memory_order_acquire)}; VoicePropsItem *vprops{mFreeVoiceProps.exchange(nullptr, std::memory_order_acquire)};
while(vprops) while(vprops)
{ {
VoicePropsItem *next{vprops->next.load(std::memory_order_relaxed)}; std::unique_ptr<VoicePropsItem> old{vprops};
delete vprops; vprops = old->next.load(std::memory_order_relaxed);
vprops = next;
++count; ++count;
} }
TRACE("Freed %zu voice property object%s\n", count, (count==1)?"":"s"); TRACE("Freed %zu voice property object%s\n", count, (count==1)?"":"s");
@@ -2404,7 +2401,7 @@ ALCcontext::~ALCcontext()
delete mVoices.exchange(nullptr, std::memory_order_relaxed); delete mVoices.exchange(nullptr, std::memory_order_relaxed);
count = 0; count = 0;
ALlistenerProps *lprops{mListener.Params.Update.exchange(nullptr, std::memory_order_relaxed)}; ListenerProps *lprops{mParams.ListenerUpdate.exchange(nullptr, std::memory_order_relaxed)};
if(lprops) if(lprops)
{ {
++count; ++count;
@@ -2413,9 +2410,8 @@ ALCcontext::~ALCcontext()
lprops = mFreeListenerProps.exchange(nullptr, std::memory_order_acquire); lprops = mFreeListenerProps.exchange(nullptr, std::memory_order_acquire);
while(lprops) while(lprops)
{ {
ALlistenerProps *next{lprops->next.load(std::memory_order_relaxed)}; std::unique_ptr<ListenerProps> old{lprops};
delete lprops; lprops = old->next.load(std::memory_order_relaxed);
lprops = next;
++count; ++count;
} }
TRACE("Freed %zu listener property object%s\n", count, (count==1)?"":"s"); TRACE("Freed %zu listener property object%s\n", count, (count==1)?"":"s");
@@ -2476,14 +2472,14 @@ void ALCcontext::init()
mExtensionList = alExtList; mExtensionList = alExtList;
mListener.Params.Matrix = alu::Matrix::Identity(); mParams.Matrix = alu::Matrix::Identity();
mListener.Params.Velocity = alu::Vector{}; mParams.Velocity = alu::Vector{};
mListener.Params.Gain = mListener.Gain; mParams.Gain = mListener.Gain;
mListener.Params.MetersPerUnit = mListener.mMetersPerUnit; mParams.MetersPerUnit = mListener.mMetersPerUnit;
mListener.Params.DopplerFactor = mDopplerFactor; mParams.DopplerFactor = mDopplerFactor;
mListener.Params.SpeedOfSound = mSpeedOfSound * mDopplerVelocity; mParams.SpeedOfSound = mSpeedOfSound * mDopplerVelocity;
mListener.Params.SourceDistanceModel = mSourceDistanceModel; mParams.SourceDistanceModel = mSourceDistanceModel;
mListener.Params.mDistanceModel = mDistanceModel; mParams.mDistanceModel = mDistanceModel;
mAsyncEvents = RingBuffer::Create(511, sizeof(AsyncEvent), false); mAsyncEvents = RingBuffer::Create(511, sizeof(AsyncEvent), false);
+40 -7
View File
@@ -1,6 +1,7 @@
#ifndef ALCONTEXT_H #ifndef ALCONTEXT_H
#define ALCONTEXT_H #define ALCONTEXT_H
#include <array>
#include <atomic> #include <atomic>
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
@@ -20,6 +21,7 @@
#include "inprogext.h" #include "inprogext.h"
#include "intrusive_ptr.h" #include "intrusive_ptr.h"
#include "threads.h" #include "threads.h"
#include "vecmat.h"
#include "vector.h" #include "vector.h"
#include "voice.h" #include "voice.h"
@@ -54,16 +56,47 @@ struct WetBuffer {
using WetBufferPtr = std::unique_ptr<WetBuffer>; using WetBufferPtr = std::unique_ptr<WetBuffer>;
struct ALcontextProps { struct ContextProps {
float DopplerFactor; float DopplerFactor;
float DopplerVelocity; float DopplerVelocity;
float SpeedOfSound; float SpeedOfSound;
bool SourceDistanceModel; bool SourceDistanceModel;
DistanceModel mDistanceModel; DistanceModel mDistanceModel;
std::atomic<ALcontextProps*> next; std::atomic<ContextProps*> next;
DEF_NEWDEL(ALcontextProps) DEF_NEWDEL(ContextProps)
};
struct ListenerProps {
std::array<float,3> Position;
std::array<float,3> Velocity;
std::array<float,3> OrientAt;
std::array<float,3> OrientUp;
float Gain;
float MetersPerUnit;
std::atomic<ListenerProps*> next;
DEF_NEWDEL(ListenerProps)
};
struct ContextParams {
/* Pointer to the most recent property values that are awaiting an update. */
std::atomic<ContextProps*> ContextUpdate{nullptr};
std::atomic<ListenerProps*> ListenerUpdate{nullptr};
alu::Matrix Matrix{alu::Matrix::Identity()};
alu::Vector Velocity{};
float Gain{1.0f};
float MetersPerUnit{1.0f};
float DopplerFactor{1.0f};
float SpeedOfSound{343.3f}; /* in units per sec! */
bool SourceDistanceModel{false};
DistanceModel mDistanceModel{};
}; };
@@ -141,13 +174,11 @@ struct ALCcontext : public al::intrusive_ref<ALCcontext> {
float mGainBoost{1.0f}; float mGainBoost{1.0f};
std::atomic<ALcontextProps*> mUpdate{nullptr};
/* Linked lists of unused property containers, free to use for future /* Linked lists of unused property containers, free to use for future
* updates. * updates.
*/ */
std::atomic<ALcontextProps*> mFreeContextProps{nullptr}; std::atomic<ContextProps*> mFreeContextProps{nullptr};
std::atomic<ALlistenerProps*> mFreeListenerProps{nullptr}; std::atomic<ListenerProps*> mFreeListenerProps{nullptr};
std::atomic<VoicePropsItem*> mFreeVoiceProps{nullptr}; std::atomic<VoicePropsItem*> mFreeVoiceProps{nullptr};
std::atomic<EffectSlotProps*> mFreeEffectslotProps{nullptr}; std::atomic<EffectSlotProps*> mFreeEffectslotProps{nullptr};
@@ -212,6 +243,8 @@ struct ALCcontext : public al::intrusive_ref<ALCcontext> {
ALlistener mListener{}; ALlistener mListener{};
ContextParams mParams;
ALCcontext(al::intrusive_ptr<ALCdevice> device); ALCcontext(al::intrusive_ptr<ALCdevice> device);
ALCcontext(const ALCcontext&) = delete; ALCcontext(const ALCcontext&) = delete;
+42 -50
View File
@@ -44,11 +44,7 @@
#include "AL/alc.h" #include "AL/alc.h"
#include "AL/efx.h" #include "AL/efx.h"
#include "al/auxeffectslot.h"
#include "al/buffer.h"
#include "al/effect.h"
#include "al/event.h" #include "al/event.h"
#include "al/listener.h"
#include "alcmain.h" #include "alcmain.h"
#include "alcontext.h" #include "alcontext.h"
#include "almalloc.h" #include "almalloc.h"
@@ -69,6 +65,7 @@
#include "core/uhjfilter.h" #include "core/uhjfilter.h"
#include "cpu_caps.h" #include "cpu_caps.h"
#include "effects/base.h" #include "effects/base.h"
#include "effectslot.h"
#include "fpu_ctrl.h" #include "fpu_ctrl.h"
#include "front_stablizer.h" #include "front_stablizer.h"
#include "hrtf.h" #include "hrtf.h"
@@ -367,27 +364,25 @@ auto GetAmbi2DLayout(AmbiLayout layouttype) noexcept -> const std::array<uint8_t
} }
bool CalcContextParams(ALCcontext *Context) bool CalcContextParams(ALCcontext *ctx)
{ {
ALcontextProps *props{Context->mUpdate.exchange(nullptr, std::memory_order_acq_rel)}; ContextProps *props{ctx->mParams.ContextUpdate.exchange(nullptr, std::memory_order_acq_rel)};
if(!props) return false; if(!props) return false;
ALlistener &Listener = Context->mListener; ctx->mParams.DopplerFactor = props->DopplerFactor;
Listener.Params.DopplerFactor = props->DopplerFactor; ctx->mParams.SpeedOfSound = props->SpeedOfSound * props->DopplerVelocity;
Listener.Params.SpeedOfSound = props->SpeedOfSound * props->DopplerVelocity;
Listener.Params.SourceDistanceModel = props->SourceDistanceModel; ctx->mParams.SourceDistanceModel = props->SourceDistanceModel;
Listener.Params.mDistanceModel = props->mDistanceModel; ctx->mParams.mDistanceModel = props->mDistanceModel;
AtomicReplaceHead(Context->mFreeContextProps, props); AtomicReplaceHead(ctx->mFreeContextProps, props);
return true; return true;
} }
bool CalcListenerParams(ALCcontext *Context) bool CalcListenerParams(ALCcontext *ctx)
{ {
ALlistener &Listener = Context->mListener; ListenerProps *props{ctx->mParams.ListenerUpdate.exchange(nullptr,
std::memory_order_acq_rel)};
ALlistenerProps *props{Listener.Params.Update.exchange(nullptr, std::memory_order_acq_rel)};
if(!props) return false; if(!props) return false;
/* AT then UP */ /* AT then UP */
@@ -405,21 +400,20 @@ bool CalcListenerParams(ALCcontext *Context)
U[2], V[2], -N[2], 0.0, U[2], V[2], -N[2], 0.0,
0.0, 0.0, 0.0, 1.0}; 0.0, 0.0, 0.0, 1.0};
const alu::VectorR<double> pos{props->Position[0],props->Position[1],props->Position[2],1.0}; const alu::VectorR<double> pos{props->Position[0],props->Position[1],props->Position[2],1.0};
const alu::VectorR<double> vel{props->Velocity[0],props->Velocity[1],props->Velocity[2],0.0};
const alu::Vector P{alu::cast_to<float>(rot * pos)}; const alu::Vector P{alu::cast_to<float>(rot * pos)};
Listener.Params.Matrix = alu::Matrix{ ctx->mParams.Matrix = alu::Matrix{
U[0], V[0], -N[0], 0.0f, U[0], V[0], -N[0], 0.0f,
U[1], V[1], -N[1], 0.0f, U[1], V[1], -N[1], 0.0f,
U[2], V[2], -N[2], 0.0f, U[2], V[2], -N[2], 0.0f,
-P[0], -P[1], -P[2], 1.0f}; -P[0], -P[1], -P[2], 1.0f};
ctx->mParams.Velocity = alu::cast_to<float>(rot * vel);
const alu::Vector vel{props->Velocity[0], props->Velocity[1], props->Velocity[2], 0.0f}; ctx->mParams.Gain = props->Gain * ctx->mGainBoost;
Listener.Params.Velocity = Listener.Params.Matrix * vel; ctx->mParams.MetersPerUnit = props->MetersPerUnit;
Listener.Params.Gain = props->Gain * Context->mGainBoost; AtomicReplaceHead(ctx->mFreeListenerProps, props);
Listener.Params.MetersPerUnit = props->MetersPerUnit;
AtomicReplaceHead(Context->mFreeListenerProps, props);
return true; return true;
} }
@@ -438,7 +432,7 @@ bool CalcEffectSlotParams(EffectSlot *slot, EffectSlot **sorted_slots, ALCcontex
slot->Target = props->Target; slot->Target = props->Target;
slot->EffectType = props->Type; slot->EffectType = props->Type;
slot->mEffectProps = props->Props; slot->mEffectProps = props->Props;
if(IsReverbEffect(props->Type)) if(props->Type == AL_EFFECT_REVERB || props->Type == AL_EFFECT_EAXREVERB)
{ {
slot->RoomRolloff = props->Props.Reverb.RoomRolloffFactor; slot->RoomRolloff = props->Props.Reverb.RoomRolloffFactor;
slot->DecayTime = props->Props.Reverb.DecayTime; slot->DecayTime = props->Props.Reverb.DecayTime;
@@ -683,7 +677,7 @@ struct GainTriplet { float Base, HF, LF; };
void CalcPanningAndFilters(Voice *voice, const float xpos, const float ypos, const float zpos, void CalcPanningAndFilters(Voice *voice, const float xpos, const float ypos, const float zpos,
const float Distance, const float Spread, const GainTriplet &DryGain, const float Distance, const float Spread, const GainTriplet &DryGain,
const al::span<const GainTriplet,MAX_SENDS> WetGain, EffectSlot *(&SendSlots)[MAX_SENDS], const al::span<const GainTriplet,MAX_SENDS> WetGain, EffectSlot *(&SendSlots)[MAX_SENDS],
const VoiceProps *props, const ALlistener &Listener, const ALCdevice *Device) const VoiceProps *props, const ContextParams &Context, const ALCdevice *Device)
{ {
static const ChanMap MonoMap[1]{ static const ChanMap MonoMap[1]{
{ FrontCenter, 0.0f, 0.0f } { FrontCenter, 0.0f, 0.0f }
@@ -882,8 +876,8 @@ void CalcPanningAndFilters(Voice *voice, const float xpos, const float ypos, con
V.normalize(); V.normalize();
if(!props->HeadRelative) if(!props->HeadRelative)
{ {
N = Listener.Params.Matrix * N; N = Context.Matrix * N;
V = Listener.Params.Matrix * V; V = Context.Matrix * V;
} }
/* Build and normalize right-vector */ /* Build and normalize right-vector */
alu::Vector U{N.cross_product(V)}; alu::Vector U{N.cross_product(V)};
@@ -1201,9 +1195,9 @@ void CalcPanningAndFilters(Voice *voice, const float xpos, const float ypos, con
} }
} }
void CalcNonAttnSourceParams(Voice *voice, const VoiceProps *props, const ALCcontext *ALContext) void CalcNonAttnSourceParams(Voice *voice, const VoiceProps *props, const ALCcontext *context)
{ {
const ALCdevice *Device{ALContext->mDevice.get()}; const ALCdevice *Device{context->mDevice.get()};
EffectSlot *SendSlots[MAX_SENDS]; EffectSlot *SendSlots[MAX_SENDS];
voice->mDirect.Buffer = Device->Dry.Buffer; voice->mDirect.Buffer = Device->Dry.Buffer;
@@ -1229,30 +1223,28 @@ void CalcNonAttnSourceParams(Voice *voice, const VoiceProps *props, const ALCcon
voice->mResampler = PrepareResampler(props->mResampler, voice->mStep, &voice->mResampleState); voice->mResampler = PrepareResampler(props->mResampler, voice->mStep, &voice->mResampleState);
/* Calculate gains */ /* Calculate gains */
const ALlistener &Listener = ALContext->mListener;
GainTriplet DryGain; GainTriplet DryGain;
DryGain.Base = minf(clampf(props->Gain, props->MinGain, props->MaxGain) * props->Direct.Gain * DryGain.Base = minf(clampf(props->Gain, props->MinGain, props->MaxGain) * props->Direct.Gain *
Listener.Params.Gain, GainMixMax); context->mParams.Gain, GainMixMax);
DryGain.HF = props->Direct.GainHF; DryGain.HF = props->Direct.GainHF;
DryGain.LF = props->Direct.GainLF; DryGain.LF = props->Direct.GainLF;
GainTriplet WetGain[MAX_SENDS]; GainTriplet WetGain[MAX_SENDS];
for(ALuint i{0};i < Device->NumAuxSends;i++) for(ALuint i{0};i < Device->NumAuxSends;i++)
{ {
WetGain[i].Base = minf(clampf(props->Gain, props->MinGain, props->MaxGain) * WetGain[i].Base = minf(clampf(props->Gain, props->MinGain, props->MaxGain) *
props->Send[i].Gain * Listener.Params.Gain, GainMixMax); props->Send[i].Gain * context->mParams.Gain, GainMixMax);
WetGain[i].HF = props->Send[i].GainHF; WetGain[i].HF = props->Send[i].GainHF;
WetGain[i].LF = props->Send[i].GainLF; WetGain[i].LF = props->Send[i].GainLF;
} }
CalcPanningAndFilters(voice, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, DryGain, WetGain, SendSlots, props, CalcPanningAndFilters(voice, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, DryGain, WetGain, SendSlots, props,
Listener, Device); context->mParams, Device);
} }
void CalcAttnSourceParams(Voice *voice, const VoiceProps *props, const ALCcontext *ALContext) void CalcAttnSourceParams(Voice *voice, const VoiceProps *props, const ALCcontext *context)
{ {
const ALCdevice *Device{ALContext->mDevice.get()}; const ALCdevice *Device{context->mDevice.get()};
const ALuint NumSends{Device->NumAuxSends}; const ALuint NumSends{Device->NumAuxSends};
const ALlistener &Listener = ALContext->mListener;
/* Set mixing buffers and get send parameters. */ /* Set mixing buffers and get send parameters. */
voice->mDirect.Buffer = Device->Dry.Buffer; voice->mDirect.Buffer = Device->Dry.Buffer;
@@ -1318,14 +1310,14 @@ void CalcAttnSourceParams(Voice *voice, const VoiceProps *props, const ALCcontex
if(!props->HeadRelative) if(!props->HeadRelative)
{ {
/* Transform source vectors */ /* Transform source vectors */
Position = Listener.Params.Matrix * Position; Position = context->mParams.Matrix * Position;
Velocity = Listener.Params.Matrix * Velocity; Velocity = context->mParams.Matrix * Velocity;
Direction = Listener.Params.Matrix * Direction; Direction = context->mParams.Matrix * Direction;
} }
else else
{ {
/* Offset the source velocity to be relative of the listener velocity */ /* Offset the source velocity to be relative of the listener velocity */
Velocity += Listener.Params.Velocity; Velocity += context->mParams.Velocity;
} }
const bool directional{Direction.normalize() > 0.0f}; const bool directional{Direction.normalize() > 0.0f};
@@ -1341,8 +1333,8 @@ void CalcAttnSourceParams(Voice *voice, const VoiceProps *props, const ALCcontex
/* Calculate distance attenuation */ /* Calculate distance attenuation */
float ClampedDist{Distance}; float ClampedDist{Distance};
switch(Listener.Params.SourceDistanceModel ? switch(context->mParams.SourceDistanceModel ? props->mDistanceModel
props->mDistanceModel : Listener.Params.mDistanceModel) : context->mParams.mDistanceModel)
{ {
case DistanceModel::InverseClamped: case DistanceModel::InverseClamped:
ClampedDist = clampf(ClampedDist, props->RefDistance, props->MaxDistance); ClampedDist = clampf(ClampedDist, props->RefDistance, props->MaxDistance);
@@ -1441,13 +1433,13 @@ void CalcAttnSourceParams(Voice *voice, const VoiceProps *props, const ALCcontex
/* Apply gain and frequency filters */ /* Apply gain and frequency filters */
DryGain.Base = minf(clampf(DryGain.Base, props->MinGain, props->MaxGain) * props->Direct.Gain * DryGain.Base = minf(clampf(DryGain.Base, props->MinGain, props->MaxGain) * props->Direct.Gain *
Listener.Params.Gain, GainMixMax); context->mParams.Gain, GainMixMax);
DryGain.HF *= props->Direct.GainHF; DryGain.HF *= props->Direct.GainHF;
DryGain.LF *= props->Direct.GainLF; DryGain.LF *= props->Direct.GainLF;
for(ALuint i{0};i < NumSends;i++) for(ALuint i{0};i < NumSends;i++)
{ {
WetGain[i].Base = minf(clampf(WetGain[i].Base, props->MinGain, props->MaxGain) * WetGain[i].Base = minf(clampf(WetGain[i].Base, props->MinGain, props->MaxGain) *
props->Send[i].Gain * Listener.Params.Gain, GainMixMax); props->Send[i].Gain * context->mParams.Gain, GainMixMax);
WetGain[i].HF *= props->Send[i].GainHF; WetGain[i].HF *= props->Send[i].GainHF;
WetGain[i].LF *= props->Send[i].GainLF; WetGain[i].LF *= props->Send[i].GainLF;
} }
@@ -1456,7 +1448,7 @@ void CalcAttnSourceParams(Voice *voice, const VoiceProps *props, const ALCcontex
if(ClampedDist > props->RefDistance && props->RolloffFactor > 0.0f) if(ClampedDist > props->RefDistance && props->RolloffFactor > 0.0f)
{ {
const float meters_base{(ClampedDist-props->RefDistance) * props->RolloffFactor * const float meters_base{(ClampedDist-props->RefDistance) * props->RolloffFactor *
Listener.Params.MetersPerUnit}; context->mParams.MetersPerUnit};
if(props->AirAbsorptionFactor > 0.0f) if(props->AirAbsorptionFactor > 0.0f)
{ {
const float hfattn{std::pow(AirAbsorbGainHF, meters_base*props->AirAbsorptionFactor)}; const float hfattn{std::pow(AirAbsorbGainHF, meters_base*props->AirAbsorptionFactor)};
@@ -1497,14 +1489,14 @@ void CalcAttnSourceParams(Voice *voice, const VoiceProps *props, const ALCcontex
float Pitch{props->Pitch}; float Pitch{props->Pitch};
/* Calculate velocity-based doppler effect */ /* Calculate velocity-based doppler effect */
float DopplerFactor{props->DopplerFactor * Listener.Params.DopplerFactor}; float DopplerFactor{props->DopplerFactor * context->mParams.DopplerFactor};
if(DopplerFactor > 0.0f) if(DopplerFactor > 0.0f)
{ {
const alu::Vector &lvelocity = Listener.Params.Velocity; const alu::Vector &lvelocity = context->mParams.Velocity;
float vss{Velocity.dot_product(ToSource) * -DopplerFactor}; float vss{Velocity.dot_product(ToSource) * -DopplerFactor};
float vls{lvelocity.dot_product(ToSource) * -DopplerFactor}; float vls{lvelocity.dot_product(ToSource) * -DopplerFactor};
const float SpeedOfSound{Listener.Params.SpeedOfSound}; const float SpeedOfSound{context->mParams.SpeedOfSound};
if(!(vls < SpeedOfSound)) if(!(vls < SpeedOfSound))
{ {
/* Listener moving away from the source at the speed of sound. /* Listener moving away from the source at the speed of sound.
@@ -1545,8 +1537,8 @@ void CalcAttnSourceParams(Voice *voice, const VoiceProps *props, const ALCcontex
spread = std::asin(props->Radius/Distance) * 2.0f; spread = std::asin(props->Radius/Distance) * 2.0f;
CalcPanningAndFilters(voice, ToSource[0], ToSource[1], ToSource[2]*ZScale, CalcPanningAndFilters(voice, ToSource[0], ToSource[1], ToSource[2]*ZScale,
Distance*Listener.Params.MetersPerUnit, spread, DryGain, WetGain, SendSlots, props, Distance*context->mParams.MetersPerUnit, spread, DryGain, WetGain, SendSlots, props,
Listener, Device); context->mParams, Device);
} }
void CalcSourceParams(Voice *voice, ALCcontext *context, bool force) void CalcSourceParams(Voice *voice, ALCcontext *context, bool force)