aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--al/auxeffectslot.cpp70
-rw-r--r--al/auxeffectslot.h2
-rw-r--r--al/effect.cpp59
-rw-r--r--al/effect.h2
-rw-r--r--alc/alu.cpp6
-rw-r--r--alc/effects/dedicated.cpp4
-rw-r--r--alc/effectslot.h24
7 files changed, 114 insertions, 53 deletions
diff --git a/al/auxeffectslot.cpp b/al/auxeffectslot.cpp
index e3e8a125..4c6ea288 100644
--- a/al/auxeffectslot.cpp
+++ b/al/auxeffectslot.cpp
@@ -51,6 +51,39 @@
namespace {
+struct FactoryItem {
+ EffectSlotType Type;
+ EffectStateFactory* (&GetFactory)(void);
+};
+constexpr FactoryItem FactoryList[] = {
+ { EffectSlotType::None, NullStateFactory_getFactory },
+ { EffectSlotType::EAXReverb, ReverbStateFactory_getFactory },
+ { EffectSlotType::Reverb, StdReverbStateFactory_getFactory },
+ { EffectSlotType::Autowah, AutowahStateFactory_getFactory },
+ { EffectSlotType::Chorus, ChorusStateFactory_getFactory },
+ { EffectSlotType::Compressor, CompressorStateFactory_getFactory },
+ { EffectSlotType::Distortion, DistortionStateFactory_getFactory },
+ { EffectSlotType::Echo, EchoStateFactory_getFactory },
+ { EffectSlotType::Equalizer, EqualizerStateFactory_getFactory },
+ { EffectSlotType::Flanger, FlangerStateFactory_getFactory },
+ { EffectSlotType::FrequencyShifter, FshifterStateFactory_getFactory },
+ { EffectSlotType::RingModulator, ModulatorStateFactory_getFactory },
+ { EffectSlotType::PitchShifter, PshifterStateFactory_getFactory },
+ { EffectSlotType::VocalMorpher, VmorpherStateFactory_getFactory },
+ { EffectSlotType::DedicatedDialog, DedicatedStateFactory_getFactory },
+ { EffectSlotType::DedicatedLFE, DedicatedStateFactory_getFactory },
+ { EffectSlotType::Convolution, ConvolutionStateFactory_getFactory },
+};
+
+EffectStateFactory *getFactoryByType(EffectSlotType type)
+{
+ auto iter = std::find_if(std::begin(FactoryList), std::end(FactoryList),
+ [type](const FactoryItem &item) noexcept -> bool
+ { return item.Type == type; });
+ return (iter != std::end(FactoryList)) ? iter->GetFactory() : nullptr;
+}
+
+
inline ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id) noexcept
{
const size_t lidx{(id-1) >> 6};
@@ -175,6 +208,32 @@ void RemoveActiveEffectSlots(const al::span<ALeffectslot*> auxslots, ALCcontext
}
+constexpr EffectSlotType EffectSlotTypeFromEnum(ALenum type)
+{
+ switch(type)
+ {
+ case AL_EFFECT_NULL: return EffectSlotType::None;
+ case AL_EFFECT_REVERB: return EffectSlotType::Reverb;
+ case AL_EFFECT_CHORUS: return EffectSlotType::Chorus;
+ case AL_EFFECT_DISTORTION: return EffectSlotType::Distortion;
+ case AL_EFFECT_ECHO: return EffectSlotType::Echo;
+ case AL_EFFECT_FLANGER: return EffectSlotType::Flanger;
+ case AL_EFFECT_FREQUENCY_SHIFTER: return EffectSlotType::FrequencyShifter;
+ case AL_EFFECT_VOCAL_MORPHER: return EffectSlotType::VocalMorpher;
+ case AL_EFFECT_PITCH_SHIFTER: return EffectSlotType::PitchShifter;
+ case AL_EFFECT_RING_MODULATOR: return EffectSlotType::RingModulator;
+ case AL_EFFECT_AUTOWAH: return EffectSlotType::Autowah;
+ case AL_EFFECT_COMPRESSOR: return EffectSlotType::Compressor;
+ case AL_EFFECT_EQUALIZER: return EffectSlotType::Equalizer;
+ case AL_EFFECT_EAXREVERB: return EffectSlotType::EAXReverb;
+ case AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT: return EffectSlotType::DedicatedLFE;
+ case AL_EFFECT_DEDICATED_DIALOGUE: return EffectSlotType::DedicatedDialog;
+ case AL_EFFECT_CONVOLUTION_REVERB_SOFT: return EffectSlotType::Convolution;
+ }
+ ERR("Unhandled effect enum: 0x%04x\n", type);
+ return EffectSlotType::None;
+}
+
bool EnsureEffectSlots(ALCcontext *context, size_t needed)
{
size_t count{std::accumulate(context->mEffectSlotList.cbegin(),
@@ -859,13 +918,13 @@ ALenum ALeffectslot::init()
ALenum ALeffectslot::initEffect(ALeffect *effect, ALCcontext *context)
{
- ALenum newtype{effect ? effect->type : AL_EFFECT_NULL};
+ EffectSlotType newtype{EffectSlotTypeFromEnum(effect ? effect->type : AL_EFFECT_NULL)};
if(newtype != Effect.Type)
{
EffectStateFactory *factory{getFactoryByType(newtype)};
if(!factory)
{
- ERR("Failed to find factory for effect type 0x%04x\n", newtype);
+ ERR("Failed to find factory for effect slot type %d\n", static_cast<int>(newtype));
return AL_INVALID_ENUM;
}
al::intrusive_ptr<EffectState> State{factory->create()};
@@ -881,16 +940,11 @@ ALenum ALeffectslot::initEffect(ALeffect *effect, ALCcontext *context)
State->setBuffer(Device, Buffer);
}
+ Effect.Type = newtype;
if(!effect)
- {
- Effect.Type = AL_EFFECT_NULL;
Effect.Props = EffectProps{};
- }
else
- {
- Effect.Type = effect->type;
Effect.Props = effect->Props;
- }
Effect.State = std::move(State);
}
diff --git a/al/auxeffectslot.h b/al/auxeffectslot.h
index c2967c93..4d3c8640 100644
--- a/al/auxeffectslot.h
+++ b/al/auxeffectslot.h
@@ -34,7 +34,7 @@ struct ALeffectslot {
ALbuffer *Buffer{nullptr};
struct {
- ALenum Type{AL_EFFECT_NULL};
+ EffectSlotType Type{EffectSlotType::None};
EffectProps Props{};
al::intrusive_ptr<EffectState> State;
diff --git a/al/effect.cpp b/al/effect.cpp
index 7ddf9664..02b31fac 100644
--- a/al/effect.cpp
+++ b/al/effect.cpp
@@ -82,30 +82,29 @@ effect_exception::effect_exception(ALenum code, const char *msg, ...) : mErrorCo
namespace {
-struct FactoryItem {
+struct EffectPropsItem {
ALenum Type;
- EffectStateFactory* (&GetFactory)(void);
const EffectProps &DefaultProps;
const EffectVtable &Vtable;
};
-constexpr FactoryItem FactoryList[] = {
- { AL_EFFECT_NULL, NullStateFactory_getFactory, NullEffectProps, NullEffectVtable },
- { AL_EFFECT_EAXREVERB, ReverbStateFactory_getFactory, ReverbEffectProps, ReverbEffectVtable },
- { AL_EFFECT_REVERB, StdReverbStateFactory_getFactory, StdReverbEffectProps, StdReverbEffectVtable },
- { AL_EFFECT_AUTOWAH, AutowahStateFactory_getFactory, AutowahEffectProps, AutowahEffectVtable },
- { AL_EFFECT_CHORUS, ChorusStateFactory_getFactory, ChorusEffectProps, ChorusEffectVtable },
- { AL_EFFECT_COMPRESSOR, CompressorStateFactory_getFactory, CompressorEffectProps, CompressorEffectVtable },
- { AL_EFFECT_DISTORTION, DistortionStateFactory_getFactory, DistortionEffectProps, DistortionEffectVtable },
- { AL_EFFECT_ECHO, EchoStateFactory_getFactory, EchoEffectProps, EchoEffectVtable },
- { AL_EFFECT_EQUALIZER, EqualizerStateFactory_getFactory, EqualizerEffectProps, EqualizerEffectVtable },
- { AL_EFFECT_FLANGER, FlangerStateFactory_getFactory, FlangerEffectProps, FlangerEffectVtable },
- { AL_EFFECT_FREQUENCY_SHIFTER, FshifterStateFactory_getFactory, FshifterEffectProps, FshifterEffectVtable },
- { AL_EFFECT_RING_MODULATOR, ModulatorStateFactory_getFactory, ModulatorEffectProps, ModulatorEffectVtable },
- { AL_EFFECT_PITCH_SHIFTER, PshifterStateFactory_getFactory, PshifterEffectProps, PshifterEffectVtable },
- { AL_EFFECT_VOCAL_MORPHER, VmorpherStateFactory_getFactory, VmorpherEffectProps, VmorpherEffectVtable },
- { AL_EFFECT_DEDICATED_DIALOGUE, DedicatedStateFactory_getFactory, DedicatedEffectProps, DedicatedEffectVtable },
- { AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT, DedicatedStateFactory_getFactory, DedicatedEffectProps, DedicatedEffectVtable },
- { AL_EFFECT_CONVOLUTION_REVERB_SOFT, ConvolutionStateFactory_getFactory, ConvolutionEffectProps, ConvolutionEffectVtable },
+constexpr EffectPropsItem EffectPropsList[] = {
+ { AL_EFFECT_NULL, NullEffectProps, NullEffectVtable },
+ { AL_EFFECT_EAXREVERB, ReverbEffectProps, ReverbEffectVtable },
+ { AL_EFFECT_REVERB, StdReverbEffectProps, StdReverbEffectVtable },
+ { AL_EFFECT_AUTOWAH, AutowahEffectProps, AutowahEffectVtable },
+ { AL_EFFECT_CHORUS, ChorusEffectProps, ChorusEffectVtable },
+ { AL_EFFECT_COMPRESSOR, CompressorEffectProps, CompressorEffectVtable },
+ { AL_EFFECT_DISTORTION, DistortionEffectProps, DistortionEffectVtable },
+ { AL_EFFECT_ECHO, EchoEffectProps, EchoEffectVtable },
+ { AL_EFFECT_EQUALIZER, EqualizerEffectProps, EqualizerEffectVtable },
+ { AL_EFFECT_FLANGER, FlangerEffectProps, FlangerEffectVtable },
+ { AL_EFFECT_FREQUENCY_SHIFTER, FshifterEffectProps, FshifterEffectVtable },
+ { AL_EFFECT_RING_MODULATOR, ModulatorEffectProps, ModulatorEffectVtable },
+ { AL_EFFECT_PITCH_SHIFTER, PshifterEffectProps, PshifterEffectVtable },
+ { AL_EFFECT_VOCAL_MORPHER, VmorpherEffectProps, VmorpherEffectVtable },
+ { AL_EFFECT_DEDICATED_DIALOGUE, DedicatedEffectProps, DedicatedEffectVtable },
+ { AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT, DedicatedEffectProps, DedicatedEffectVtable },
+ { AL_EFFECT_CONVOLUTION_REVERB_SOFT, ConvolutionEffectProps, ConvolutionEffectVtable },
};
@@ -128,17 +127,17 @@ void ALeffect_getParamfv(const ALeffect *effect, ALenum param, float *values)
{ effect->vtab->getParamfv(&effect->Props, param, values); }
-const FactoryItem *getFactoryItemByType(ALenum type)
+const EffectPropsItem *getEffectPropsItemByType(ALenum type)
{
- auto iter = std::find_if(std::begin(FactoryList), std::end(FactoryList),
- [type](const FactoryItem &item) noexcept -> bool
+ auto iter = std::find_if(std::begin(EffectPropsList), std::end(EffectPropsList),
+ [type](const EffectPropsItem &item) noexcept -> bool
{ return item.Type == type; });
- return (iter != std::end(FactoryList)) ? std::addressof(*iter) : nullptr;
+ return (iter != std::end(EffectPropsList)) ? std::addressof(*iter) : nullptr;
}
void InitEffectParams(ALeffect *effect, ALenum type)
{
- const FactoryItem *item{getFactoryItemByType(type)};
+ const EffectPropsItem *item{getEffectPropsItemByType(type)};
if(item)
{
effect->Props = item->DefaultProps;
@@ -554,16 +553,6 @@ EffectSubList::~EffectSubList()
}
-EffectStateFactory *getFactoryByType(ALenum type)
-{
- auto iter = std::find_if(std::begin(FactoryList), std::end(FactoryList),
- [type](const FactoryItem &item) noexcept -> bool
- { return item.Type == type; }
- );
- return (iter != std::end(FactoryList)) ? iter->GetFactory() : nullptr;
-}
-
-
#define DECL(x) { #x, EFX_REVERB_PRESET_##x }
static const struct {
const char name[32];
diff --git a/al/effect.h b/al/effect.h
index d543828a..10a692c9 100644
--- a/al/effect.h
+++ b/al/effect.h
@@ -53,8 +53,6 @@ struct ALeffect {
DISABLE_ALLOC()
};
-EffectStateFactory *getFactoryByType(ALenum type);
-
void InitEffect(ALeffect *effect);
void LoadReverbPreset(const char *name, ALeffect *effect);
diff --git a/alc/alu.cpp b/alc/alu.cpp
index f3a950f6..ae181af2 100644
--- a/alc/alu.cpp
+++ b/alc/alu.cpp
@@ -433,7 +433,7 @@ bool CalcEffectSlotParams(EffectSlot *slot, EffectSlot **sorted_slots, ALCcontex
slot->Target = props->Target;
slot->EffectType = props->Type;
slot->mEffectProps = props->Props;
- if(props->Type == AL_EFFECT_REVERB || props->Type == AL_EFFECT_EAXREVERB)
+ if(props->Type == EffectSlotType::Reverb || props->Type == EffectSlotType::EAXReverb)
{
slot->RoomRolloff = props->Props.Reverb.RoomRolloffFactor;
slot->DecayTime = props->Props.Reverb.DecayTime;
@@ -1205,7 +1205,7 @@ void CalcNonAttnSourceParams(Voice *voice, const VoiceProps *props, const ALCcon
for(uint i{0};i < Device->NumAuxSends;i++)
{
SendSlots[i] = props->Send[i].Slot;
- if(!SendSlots[i] || SendSlots[i]->EffectType == AL_EFFECT_NULL)
+ if(!SendSlots[i] || SendSlots[i]->EffectType == EffectSlotType::None)
{
SendSlots[i] = nullptr;
voice->mSend[i].Buffer = {};
@@ -1255,7 +1255,7 @@ void CalcAttnSourceParams(Voice *voice, const VoiceProps *props, const ALCcontex
for(uint i{0};i < NumSends;i++)
{
SendSlots[i] = props->Send[i].Slot;
- if(!SendSlots[i] || SendSlots[i]->EffectType == AL_EFFECT_NULL)
+ if(!SendSlots[i] || SendSlots[i]->EffectType == EffectSlotType::None)
{
SendSlots[i] = nullptr;
RoomRolloff[i] = 0.0f;
diff --git a/alc/effects/dedicated.cpp b/alc/effects/dedicated.cpp
index 816b6021..e71f75f0 100644
--- a/alc/effects/dedicated.cpp
+++ b/alc/effects/dedicated.cpp
@@ -58,7 +58,7 @@ void DedicatedState::update(const ALCcontext*, const EffectSlot *slot,
const float Gain{slot->Gain * props->Dedicated.Gain};
- if(slot->EffectType == AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT)
+ if(slot->EffectType == EffectSlotType::DedicatedLFE)
{
const uint idx{!target.RealOut ? INVALID_CHANNEL_INDEX :
GetChannelIdxByName(*target.RealOut, LFE)};
@@ -68,7 +68,7 @@ void DedicatedState::update(const ALCcontext*, const EffectSlot *slot,
mTargetGains[idx] = Gain;
}
}
- else if(slot->EffectType == AL_EFFECT_DEDICATED_DIALOGUE)
+ else if(slot->EffectType == EffectSlotType::DedicatedDialog)
{
/* Dialog goes to the front-center speaker if it exists, otherwise it
* plays from the front-center location. */
diff --git a/alc/effectslot.h b/alc/effectslot.h
index 2bef5477..be84fcab 100644
--- a/alc/effectslot.h
+++ b/alc/effectslot.h
@@ -14,12 +14,32 @@ struct EffectSlot;
using EffectSlotArray = al::FlexArray<EffectSlot*>;
+enum class EffectSlotType : unsigned char {
+ None,
+ Reverb,
+ Chorus,
+ Distortion,
+ Echo,
+ Flanger,
+ FrequencyShifter,
+ VocalMorpher,
+ PitchShifter,
+ RingModulator,
+ Autowah,
+ Compressor,
+ Equalizer,
+ EAXReverb,
+ DedicatedLFE,
+ DedicatedDialog,
+ Convolution
+};
+
struct EffectSlotProps {
float Gain;
bool AuxSendAuto;
EffectSlot *Target;
- ALenum Type;
+ EffectSlotType Type;
EffectProps Props;
al::intrusive_ptr<EffectState> State;
@@ -44,7 +64,7 @@ struct EffectSlot {
bool AuxSendAuto{true};
EffectSlot *Target{nullptr};
- ALenum EffectType{};
+ EffectSlotType EffectType{EffectSlotType::None};
EffectProps mEffectProps{};
EffectState *mEffectState{nullptr};