aboutsummaryrefslogtreecommitdiffstats
path: root/al/effect.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'al/effect.cpp')
-rw-r--r--al/effect.cpp231
1 files changed, 132 insertions, 99 deletions
diff --git a/al/effect.cpp b/al/effect.cpp
index 005b1557..c33faa2c 100644
--- a/al/effect.cpp
+++ b/al/effect.cpp
@@ -89,72 +89,34 @@ effect_exception::~effect_exception() = default;
namespace {
-struct EffectPropsItem {
- ALenum Type;
- const EffectProps &DefaultProps;
- const EffectVtable &Vtable;
-};
-constexpr std::array EffectPropsList{
- EffectPropsItem{AL_EFFECT_NULL, NullEffectProps, NullEffectVtable},
- EffectPropsItem{AL_EFFECT_EAXREVERB, ReverbEffectProps, ReverbEffectVtable},
- EffectPropsItem{AL_EFFECT_REVERB, StdReverbEffectProps, StdReverbEffectVtable},
- EffectPropsItem{AL_EFFECT_AUTOWAH, AutowahEffectProps, AutowahEffectVtable},
- EffectPropsItem{AL_EFFECT_CHORUS, ChorusEffectProps, ChorusEffectVtable},
- EffectPropsItem{AL_EFFECT_COMPRESSOR, CompressorEffectProps, CompressorEffectVtable},
- EffectPropsItem{AL_EFFECT_DISTORTION, DistortionEffectProps, DistortionEffectVtable},
- EffectPropsItem{AL_EFFECT_ECHO, EchoEffectProps, EchoEffectVtable},
- EffectPropsItem{AL_EFFECT_EQUALIZER, EqualizerEffectProps, EqualizerEffectVtable},
- EffectPropsItem{AL_EFFECT_FLANGER, FlangerEffectProps, FlangerEffectVtable},
- EffectPropsItem{AL_EFFECT_FREQUENCY_SHIFTER, FshifterEffectProps, FshifterEffectVtable},
- EffectPropsItem{AL_EFFECT_RING_MODULATOR, ModulatorEffectProps, ModulatorEffectVtable},
- EffectPropsItem{AL_EFFECT_PITCH_SHIFTER, PshifterEffectProps, PshifterEffectVtable},
- EffectPropsItem{AL_EFFECT_VOCAL_MORPHER, VmorpherEffectProps, VmorpherEffectVtable},
- EffectPropsItem{AL_EFFECT_DEDICATED_DIALOGUE, DedicatedDialogEffectProps, DedicatedDialogEffectVtable},
- EffectPropsItem{AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT, DedicatedLfeEffectProps, DedicatedLfeEffectVtable},
- EffectPropsItem{AL_EFFECT_CONVOLUTION_SOFT, ConvolutionEffectProps, ConvolutionEffectVtable},
-};
-
-
-void ALeffect_setParami(ALeffect *effect, ALenum param, int value)
-{ effect->vtab->setParami(&effect->Props, param, value); }
-void ALeffect_setParamiv(ALeffect *effect, ALenum param, const int *values)
-{ effect->vtab->setParamiv(&effect->Props, param, values); }
-void ALeffect_setParamf(ALeffect *effect, ALenum param, float value)
-{ effect->vtab->setParamf(&effect->Props, param, value); }
-void ALeffect_setParamfv(ALeffect *effect, ALenum param, const float *values)
-{ effect->vtab->setParamfv(&effect->Props, param, values); }
-
-void ALeffect_getParami(const ALeffect *effect, ALenum param, int *value)
-{ effect->vtab->getParami(&effect->Props, param, value); }
-void ALeffect_getParamiv(const ALeffect *effect, ALenum param, int *values)
-{ effect->vtab->getParamiv(&effect->Props, param, values); }
-void ALeffect_getParamf(const ALeffect *effect, ALenum param, float *value)
-{ effect->vtab->getParamf(&effect->Props, param, value); }
-void ALeffect_getParamfv(const ALeffect *effect, ALenum param, float *values)
-{ effect->vtab->getParamfv(&effect->Props, param, values); }
-
-
-const EffectPropsItem *getEffectPropsItemByType(ALenum type)
+auto GetDefaultProps(ALenum type) -> const EffectProps&
{
- auto iter = std::find_if(EffectPropsList.begin(), EffectPropsList.end(),
- [type](const EffectPropsItem &item) noexcept -> bool
- { return item.Type == type; });
- return (iter != std::end(EffectPropsList)) ? al::to_address(iter) : nullptr;
+ switch(type)
+ {
+ case AL_EFFECT_NULL: return NullEffectProps;
+ case AL_EFFECT_EAXREVERB: return ReverbEffectProps;
+ case AL_EFFECT_REVERB: return StdReverbEffectProps;
+ case AL_EFFECT_AUTOWAH: return AutowahEffectProps;
+ case AL_EFFECT_CHORUS: return ChorusEffectProps;
+ case AL_EFFECT_COMPRESSOR: return CompressorEffectProps;
+ case AL_EFFECT_DISTORTION: return DistortionEffectProps;
+ case AL_EFFECT_ECHO: return EchoEffectProps;
+ case AL_EFFECT_EQUALIZER: return EqualizerEffectProps;
+ case AL_EFFECT_FLANGER: return FlangerEffectProps;
+ case AL_EFFECT_FREQUENCY_SHIFTER: return FshifterEffectProps;
+ case AL_EFFECT_RING_MODULATOR: return ModulatorEffectProps;
+ case AL_EFFECT_PITCH_SHIFTER: return PshifterEffectProps;
+ case AL_EFFECT_VOCAL_MORPHER: return VmorpherEffectProps;
+ case AL_EFFECT_DEDICATED_DIALOGUE: return DedicatedDialogEffectProps;
+ case AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT: return DedicatedLfeEffectProps;
+ case AL_EFFECT_CONVOLUTION_SOFT: return ConvolutionEffectProps;
+ }
+ return NullEffectProps;
}
void InitEffectParams(ALeffect *effect, ALenum type)
{
- const EffectPropsItem *item{getEffectPropsItemByType(type)};
- if(item)
- {
- effect->Props = item->DefaultProps;
- effect->vtab = &item->Vtable;
- }
- else
- {
- effect->Props = EffectProps{};
- effect->vtab = &NullEffectVtable;
- }
+ effect->Props = GetDefaultProps(type);
effect->type = type;
}
@@ -342,7 +304,16 @@ FORCE_ALIGN void AL_APIENTRY alEffectiDirect(ALCcontext *context, ALuint effect,
else try
{
/* Call the appropriate handler */
- ALeffect_setParami(aleffect, param, value);
+ std::visit([aleffect,param,value](auto &arg)
+ {
+ using Type = std::remove_cv_t<std::remove_reference_t<decltype(arg)>>;
+ if constexpr(std::is_same_v<Type,ReverbProps>)
+ {
+ if(aleffect->type == AL_EFFECT_REVERB)
+ return EffectHandler::StdReverbSetParami(arg, param, value);
+ }
+ return EffectHandler::SetParami(arg, param, value);
+ }, aleffect->Props);
}
catch(effect_exception &e) {
context->setError(e.errorCode(), "%s", e.what());
@@ -369,7 +340,16 @@ FORCE_ALIGN void AL_APIENTRY alEffectivDirect(ALCcontext *context, ALuint effect
else try
{
/* Call the appropriate handler */
- ALeffect_setParamiv(aleffect, param, values);
+ std::visit([aleffect,param,values](auto &arg)
+ {
+ using Type = std::remove_cv_t<std::remove_reference_t<decltype(arg)>>;
+ if constexpr(std::is_same_v<Type,ReverbProps>)
+ {
+ if(aleffect->type == AL_EFFECT_REVERB)
+ return EffectHandler::StdReverbSetParamiv(arg, param, values);
+ }
+ return EffectHandler::SetParamiv(arg, param, values);
+ }, aleffect->Props);
}
catch(effect_exception &e) {
context->setError(e.errorCode(), "%s", e.what());
@@ -389,7 +369,16 @@ FORCE_ALIGN void AL_APIENTRY alEffectfDirect(ALCcontext *context, ALuint effect,
else try
{
/* Call the appropriate handler */
- ALeffect_setParamf(aleffect, param, value);
+ std::visit([aleffect,param,value](auto &arg)
+ {
+ using Type = std::remove_cv_t<std::remove_reference_t<decltype(arg)>>;
+ if constexpr(std::is_same_v<Type,ReverbProps>)
+ {
+ if(aleffect->type == AL_EFFECT_REVERB)
+ return EffectHandler::StdReverbSetParamf(arg, param, value);
+ }
+ return EffectHandler::SetParamf(arg, param, value);
+ }, aleffect->Props);
}
catch(effect_exception &e) {
context->setError(e.errorCode(), "%s", e.what());
@@ -409,7 +398,16 @@ FORCE_ALIGN void AL_APIENTRY alEffectfvDirect(ALCcontext *context, ALuint effect
else try
{
/* Call the appropriate handler */
- ALeffect_setParamfv(aleffect, param, values);
+ std::visit([aleffect,param,values](auto &arg)
+ {
+ using Type = std::remove_cv_t<std::remove_reference_t<decltype(arg)>>;
+ if constexpr(std::is_same_v<Type,ReverbProps>)
+ {
+ if(aleffect->type == AL_EFFECT_REVERB)
+ return EffectHandler::StdReverbSetParamfv(arg, param, values);
+ }
+ return EffectHandler::SetParamfv(arg, param, values);
+ }, aleffect->Props);
}
catch(effect_exception &e) {
context->setError(e.errorCode(), "%s", e.what());
@@ -431,7 +429,16 @@ FORCE_ALIGN void AL_APIENTRY alGetEffectiDirect(ALCcontext *context, ALuint effe
else try
{
/* Call the appropriate handler */
- ALeffect_getParami(aleffect, param, value);
+ std::visit([aleffect,param,value](auto &arg)
+ {
+ using Type = std::remove_cv_t<std::remove_reference_t<decltype(arg)>>;
+ if constexpr(std::is_same_v<Type,ReverbProps>)
+ {
+ if(aleffect->type == AL_EFFECT_REVERB)
+ return EffectHandler::StdReverbGetParami(arg, param, value);
+ }
+ return EffectHandler::GetParami(arg, param, value);
+ }, aleffect->Props);
}
catch(effect_exception &e) {
context->setError(e.errorCode(), "%s", e.what());
@@ -458,7 +465,16 @@ FORCE_ALIGN void AL_APIENTRY alGetEffectivDirect(ALCcontext *context, ALuint eff
else try
{
/* Call the appropriate handler */
- ALeffect_getParamiv(aleffect, param, values);
+ std::visit([aleffect,param,values](auto &arg)
+ {
+ using Type = std::remove_cv_t<std::remove_reference_t<decltype(arg)>>;
+ if constexpr(std::is_same_v<Type,ReverbProps>)
+ {
+ if(aleffect->type == AL_EFFECT_REVERB)
+ return EffectHandler::StdReverbGetParamiv(arg, param, values);
+ }
+ return EffectHandler::GetParamiv(arg, param, values);
+ }, aleffect->Props);
}
catch(effect_exception &e) {
context->setError(e.errorCode(), "%s", e.what());
@@ -478,7 +494,16 @@ FORCE_ALIGN void AL_APIENTRY alGetEffectfDirect(ALCcontext *context, ALuint effe
else try
{
/* Call the appropriate handler */
- ALeffect_getParamf(aleffect, param, value);
+ std::visit([aleffect,param,value](auto &arg)
+ {
+ using Type = std::remove_cv_t<std::remove_reference_t<decltype(arg)>>;
+ if constexpr(std::is_same_v<Type,ReverbProps>)
+ {
+ if(aleffect->type == AL_EFFECT_REVERB)
+ return EffectHandler::StdReverbGetParamf(arg, param, value);
+ }
+ return EffectHandler::GetParamf(arg, param, value);
+ }, aleffect->Props);
}
catch(effect_exception &e) {
context->setError(e.errorCode(), "%s", e.what());
@@ -498,7 +523,16 @@ FORCE_ALIGN void AL_APIENTRY alGetEffectfvDirect(ALCcontext *context, ALuint eff
else try
{
/* Call the appropriate handler */
- ALeffect_getParamfv(aleffect, param, values);
+ std::visit([aleffect,param,values](auto &arg)
+ {
+ using Type = std::remove_cv_t<std::remove_reference_t<decltype(arg)>>;
+ if constexpr(std::is_same_v<Type,ReverbProps>)
+ {
+ if(aleffect->type == AL_EFFECT_REVERB)
+ return EffectHandler::StdReverbGetParamfv(arg, param, values);
+ }
+ return EffectHandler::GetParamfv(arg, param, values);
+ }, aleffect->Props);
}
catch(effect_exception &e) {
context->setError(e.errorCode(), "%s", e.what());
@@ -694,40 +728,39 @@ void LoadReverbPreset(const char *name, ALeffect *effect)
InitEffectParams(effect, AL_EFFECT_NULL);
for(const auto &reverbitem : reverblist)
{
- const EFXEAXREVERBPROPERTIES *props;
-
if(al::strcasecmp(name, reverbitem.name) != 0)
continue;
TRACE("Loading reverb '%s'\n", reverbitem.name);
- props = &reverbitem.props;
- effect->Props.Reverb.Density = props->flDensity;
- effect->Props.Reverb.Diffusion = props->flDiffusion;
- effect->Props.Reverb.Gain = props->flGain;
- effect->Props.Reverb.GainHF = props->flGainHF;
- effect->Props.Reverb.GainLF = props->flGainLF;
- effect->Props.Reverb.DecayTime = props->flDecayTime;
- effect->Props.Reverb.DecayHFRatio = props->flDecayHFRatio;
- effect->Props.Reverb.DecayLFRatio = props->flDecayLFRatio;
- effect->Props.Reverb.ReflectionsGain = props->flReflectionsGain;
- effect->Props.Reverb.ReflectionsDelay = props->flReflectionsDelay;
- effect->Props.Reverb.ReflectionsPan[0] = props->flReflectionsPan[0];
- effect->Props.Reverb.ReflectionsPan[1] = props->flReflectionsPan[1];
- effect->Props.Reverb.ReflectionsPan[2] = props->flReflectionsPan[2];
- effect->Props.Reverb.LateReverbGain = props->flLateReverbGain;
- effect->Props.Reverb.LateReverbDelay = props->flLateReverbDelay;
- effect->Props.Reverb.LateReverbPan[0] = props->flLateReverbPan[0];
- effect->Props.Reverb.LateReverbPan[1] = props->flLateReverbPan[1];
- effect->Props.Reverb.LateReverbPan[2] = props->flLateReverbPan[2];
- effect->Props.Reverb.EchoTime = props->flEchoTime;
- effect->Props.Reverb.EchoDepth = props->flEchoDepth;
- effect->Props.Reverb.ModulationTime = props->flModulationTime;
- effect->Props.Reverb.ModulationDepth = props->flModulationDepth;
- effect->Props.Reverb.AirAbsorptionGainHF = props->flAirAbsorptionGainHF;
- effect->Props.Reverb.HFReference = props->flHFReference;
- effect->Props.Reverb.LFReference = props->flLFReference;
- effect->Props.Reverb.RoomRolloffFactor = props->flRoomRolloffFactor;
- effect->Props.Reverb.DecayHFLimit = props->iDecayHFLimit ? AL_TRUE : AL_FALSE;
+ const auto &props = reverbitem.props;
+ auto &dst = std::get<ReverbProps>(effect->Props);
+ dst.Density = props.flDensity;
+ dst.Diffusion = props.flDiffusion;
+ dst.Gain = props.flGain;
+ dst.GainHF = props.flGainHF;
+ dst.GainLF = props.flGainLF;
+ dst.DecayTime = props.flDecayTime;
+ dst.DecayHFRatio = props.flDecayHFRatio;
+ dst.DecayLFRatio = props.flDecayLFRatio;
+ dst.ReflectionsGain = props.flReflectionsGain;
+ dst.ReflectionsDelay = props.flReflectionsDelay;
+ dst.ReflectionsPan[0] = props.flReflectionsPan[0];
+ dst.ReflectionsPan[1] = props.flReflectionsPan[1];
+ dst.ReflectionsPan[2] = props.flReflectionsPan[2];
+ dst.LateReverbGain = props.flLateReverbGain;
+ dst.LateReverbDelay = props.flLateReverbDelay;
+ dst.LateReverbPan[0] = props.flLateReverbPan[0];
+ dst.LateReverbPan[1] = props.flLateReverbPan[1];
+ dst.LateReverbPan[2] = props.flLateReverbPan[2];
+ dst.EchoTime = props.flEchoTime;
+ dst.EchoDepth = props.flEchoDepth;
+ dst.ModulationTime = props.flModulationTime;
+ dst.ModulationDepth = props.flModulationDepth;
+ dst.AirAbsorptionGainHF = props.flAirAbsorptionGainHF;
+ dst.HFReference = props.flHFReference;
+ dst.LFReference = props.flLFReference;
+ dst.RoomRolloffFactor = props.flRoomRolloffFactor;
+ dst.DecayHFLimit = props.iDecayHFLimit ? AL_TRUE : AL_FALSE;
return;
}