aboutsummaryrefslogtreecommitdiffstats
path: root/al
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2020-12-26 09:21:30 -0800
committerChris Robinson <[email protected]>2020-12-26 09:21:30 -0800
commit54719de13235f6ea216e8d200661027c047bd283 (patch)
tree469e890debbe901619a4cbbcfc6b682a4b686b80 /al
parent8850a3f730dee76c57d5500b0c418078c91096c7 (diff)
Avoid AL enums for the EffectSlot type
Diffstat (limited to 'al')
-rw-r--r--al/auxeffectslot.cpp70
-rw-r--r--al/auxeffectslot.h2
-rw-r--r--al/effect.cpp59
-rw-r--r--al/effect.h2
4 files changed, 87 insertions, 46 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);