aboutsummaryrefslogtreecommitdiffstats
path: root/al/effects/equalizer.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2023-12-24 02:48:20 -0800
committerChris Robinson <[email protected]>2023-12-24 02:48:20 -0800
commitdae225e88dbf795e776a2c9f2dbe5bb07c2228b9 (patch)
tree8a2e79a24fef5a99b3d0f883ab03cc070a2b584a /al/effects/equalizer.cpp
parent29a1001a22891294ab63102e8868bdea52eb7b93 (diff)
Rework effect property handling
To nake EffectProps a variant instead of a union, and avoid manual vtables.
Diffstat (limited to 'al/effects/equalizer.cpp')
-rw-r--r--al/effects/equalizer.cpp155
1 files changed, 64 insertions, 91 deletions
diff --git a/al/effects/equalizer.cpp b/al/effects/equalizer.cpp
index 921d1090..74fc43fc 100644
--- a/al/effects/equalizer.cpp
+++ b/al/effects/equalizer.cpp
@@ -16,163 +16,133 @@
namespace {
-void Equalizer_setParami(EffectProps*, ALenum param, int)
+EffectProps genDefaultProps() noexcept
+{
+ EqualizerProps props{};
+ props.LowCutoff = AL_EQUALIZER_DEFAULT_LOW_CUTOFF;
+ props.LowGain = AL_EQUALIZER_DEFAULT_LOW_GAIN;
+ props.Mid1Center = AL_EQUALIZER_DEFAULT_MID1_CENTER;
+ props.Mid1Gain = AL_EQUALIZER_DEFAULT_MID1_GAIN;
+ props.Mid1Width = AL_EQUALIZER_DEFAULT_MID1_WIDTH;
+ props.Mid2Center = AL_EQUALIZER_DEFAULT_MID2_CENTER;
+ props.Mid2Gain = AL_EQUALIZER_DEFAULT_MID2_GAIN;
+ props.Mid2Width = AL_EQUALIZER_DEFAULT_MID2_WIDTH;
+ props.HighCutoff = AL_EQUALIZER_DEFAULT_HIGH_CUTOFF;
+ props.HighGain = AL_EQUALIZER_DEFAULT_HIGH_GAIN;
+ return props;
+}
+
+} // namespace
+
+const EffectProps EqualizerEffectProps{genDefaultProps()};
+
+void EffectHandler::SetParami(EqualizerProps&, ALenum param, int)
{ throw effect_exception{AL_INVALID_ENUM, "Invalid equalizer integer property 0x%04x", param}; }
-void Equalizer_setParamiv(EffectProps*, ALenum param, const int*)
+void EffectHandler::SetParamiv(EqualizerProps&, ALenum param, const int*)
{
throw effect_exception{AL_INVALID_ENUM, "Invalid equalizer integer-vector property 0x%04x",
param};
}
-void Equalizer_setParamf(EffectProps *props, ALenum param, float val)
+void EffectHandler::SetParamf(EqualizerProps &props, ALenum param, float val)
{
switch(param)
{
case AL_EQUALIZER_LOW_GAIN:
if(!(val >= AL_EQUALIZER_MIN_LOW_GAIN && val <= AL_EQUALIZER_MAX_LOW_GAIN))
throw effect_exception{AL_INVALID_VALUE, "Equalizer low-band gain out of range"};
- props->Equalizer.LowGain = val;
+ props.LowGain = val;
break;
case AL_EQUALIZER_LOW_CUTOFF:
if(!(val >= AL_EQUALIZER_MIN_LOW_CUTOFF && val <= AL_EQUALIZER_MAX_LOW_CUTOFF))
throw effect_exception{AL_INVALID_VALUE, "Equalizer low-band cutoff out of range"};
- props->Equalizer.LowCutoff = val;
+ props.LowCutoff = val;
break;
case AL_EQUALIZER_MID1_GAIN:
if(!(val >= AL_EQUALIZER_MIN_MID1_GAIN && val <= AL_EQUALIZER_MAX_MID1_GAIN))
throw effect_exception{AL_INVALID_VALUE, "Equalizer mid1-band gain out of range"};
- props->Equalizer.Mid1Gain = val;
+ props.Mid1Gain = val;
break;
case AL_EQUALIZER_MID1_CENTER:
if(!(val >= AL_EQUALIZER_MIN_MID1_CENTER && val <= AL_EQUALIZER_MAX_MID1_CENTER))
throw effect_exception{AL_INVALID_VALUE, "Equalizer mid1-band center out of range"};
- props->Equalizer.Mid1Center = val;
+ props.Mid1Center = val;
break;
case AL_EQUALIZER_MID1_WIDTH:
if(!(val >= AL_EQUALIZER_MIN_MID1_WIDTH && val <= AL_EQUALIZER_MAX_MID1_WIDTH))
throw effect_exception{AL_INVALID_VALUE, "Equalizer mid1-band width out of range"};
- props->Equalizer.Mid1Width = val;
+ props.Mid1Width = val;
break;
case AL_EQUALIZER_MID2_GAIN:
if(!(val >= AL_EQUALIZER_MIN_MID2_GAIN && val <= AL_EQUALIZER_MAX_MID2_GAIN))
throw effect_exception{AL_INVALID_VALUE, "Equalizer mid2-band gain out of range"};
- props->Equalizer.Mid2Gain = val;
+ props.Mid2Gain = val;
break;
case AL_EQUALIZER_MID2_CENTER:
if(!(val >= AL_EQUALIZER_MIN_MID2_CENTER && val <= AL_EQUALIZER_MAX_MID2_CENTER))
throw effect_exception{AL_INVALID_VALUE, "Equalizer mid2-band center out of range"};
- props->Equalizer.Mid2Center = val;
+ props.Mid2Center = val;
break;
case AL_EQUALIZER_MID2_WIDTH:
if(!(val >= AL_EQUALIZER_MIN_MID2_WIDTH && val <= AL_EQUALIZER_MAX_MID2_WIDTH))
throw effect_exception{AL_INVALID_VALUE, "Equalizer mid2-band width out of range"};
- props->Equalizer.Mid2Width = val;
+ props.Mid2Width = val;
break;
case AL_EQUALIZER_HIGH_GAIN:
if(!(val >= AL_EQUALIZER_MIN_HIGH_GAIN && val <= AL_EQUALIZER_MAX_HIGH_GAIN))
throw effect_exception{AL_INVALID_VALUE, "Equalizer high-band gain out of range"};
- props->Equalizer.HighGain = val;
+ props.HighGain = val;
break;
case AL_EQUALIZER_HIGH_CUTOFF:
if(!(val >= AL_EQUALIZER_MIN_HIGH_CUTOFF && val <= AL_EQUALIZER_MAX_HIGH_CUTOFF))
throw effect_exception{AL_INVALID_VALUE, "Equalizer high-band cutoff out of range"};
- props->Equalizer.HighCutoff = val;
+ props.HighCutoff = val;
break;
default:
throw effect_exception{AL_INVALID_ENUM, "Invalid equalizer float property 0x%04x", param};
}
}
-void Equalizer_setParamfv(EffectProps *props, ALenum param, const float *vals)
-{ Equalizer_setParamf(props, param, vals[0]); }
+void EffectHandler::SetParamfv(EqualizerProps &props, ALenum param, const float *vals)
+{ SetParamf(props, param, vals[0]); }
-void Equalizer_getParami(const EffectProps*, ALenum param, int*)
+void EffectHandler::GetParami(const EqualizerProps&, ALenum param, int*)
{ throw effect_exception{AL_INVALID_ENUM, "Invalid equalizer integer property 0x%04x", param}; }
-void Equalizer_getParamiv(const EffectProps*, ALenum param, int*)
+void EffectHandler::GetParamiv(const EqualizerProps&, ALenum param, int*)
{
throw effect_exception{AL_INVALID_ENUM, "Invalid equalizer integer-vector property 0x%04x",
param};
}
-void Equalizer_getParamf(const EffectProps *props, ALenum param, float *val)
+void EffectHandler::GetParamf(const EqualizerProps &props, ALenum param, float *val)
{
switch(param)
{
- case AL_EQUALIZER_LOW_GAIN:
- *val = props->Equalizer.LowGain;
- break;
-
- case AL_EQUALIZER_LOW_CUTOFF:
- *val = props->Equalizer.LowCutoff;
- break;
-
- case AL_EQUALIZER_MID1_GAIN:
- *val = props->Equalizer.Mid1Gain;
- break;
-
- case AL_EQUALIZER_MID1_CENTER:
- *val = props->Equalizer.Mid1Center;
- break;
-
- case AL_EQUALIZER_MID1_WIDTH:
- *val = props->Equalizer.Mid1Width;
- break;
-
- case AL_EQUALIZER_MID2_GAIN:
- *val = props->Equalizer.Mid2Gain;
- break;
-
- case AL_EQUALIZER_MID2_CENTER:
- *val = props->Equalizer.Mid2Center;
- break;
-
- case AL_EQUALIZER_MID2_WIDTH:
- *val = props->Equalizer.Mid2Width;
- break;
-
- case AL_EQUALIZER_HIGH_GAIN:
- *val = props->Equalizer.HighGain;
- break;
-
- case AL_EQUALIZER_HIGH_CUTOFF:
- *val = props->Equalizer.HighCutoff;
- break;
+ case AL_EQUALIZER_LOW_GAIN: *val = props.LowGain; break;
+ case AL_EQUALIZER_LOW_CUTOFF: *val = props.LowCutoff; break;
+ case AL_EQUALIZER_MID1_GAIN: *val = props.Mid1Gain; break;
+ case AL_EQUALIZER_MID1_CENTER: *val = props.Mid1Center; break;
+ case AL_EQUALIZER_MID1_WIDTH: *val = props.Mid1Width; break;
+ case AL_EQUALIZER_MID2_GAIN: *val = props.Mid2Gain; break;
+ case AL_EQUALIZER_MID2_CENTER: *val = props.Mid2Center; break;
+ case AL_EQUALIZER_MID2_WIDTH: *val = props.Mid2Width; break;
+ case AL_EQUALIZER_HIGH_GAIN: *val = props.HighGain; break;
+ case AL_EQUALIZER_HIGH_CUTOFF: *val = props.HighCutoff; break;
default:
throw effect_exception{AL_INVALID_ENUM, "Invalid equalizer float property 0x%04x", param};
}
}
-void Equalizer_getParamfv(const EffectProps *props, ALenum param, float *vals)
-{ Equalizer_getParamf(props, param, vals); }
-
-EffectProps genDefaultProps() noexcept
-{
- EffectProps props{};
- props.Equalizer.LowCutoff = AL_EQUALIZER_DEFAULT_LOW_CUTOFF;
- props.Equalizer.LowGain = AL_EQUALIZER_DEFAULT_LOW_GAIN;
- props.Equalizer.Mid1Center = AL_EQUALIZER_DEFAULT_MID1_CENTER;
- props.Equalizer.Mid1Gain = AL_EQUALIZER_DEFAULT_MID1_GAIN;
- props.Equalizer.Mid1Width = AL_EQUALIZER_DEFAULT_MID1_WIDTH;
- props.Equalizer.Mid2Center = AL_EQUALIZER_DEFAULT_MID2_CENTER;
- props.Equalizer.Mid2Gain = AL_EQUALIZER_DEFAULT_MID2_GAIN;
- props.Equalizer.Mid2Width = AL_EQUALIZER_DEFAULT_MID2_WIDTH;
- props.Equalizer.HighCutoff = AL_EQUALIZER_DEFAULT_HIGH_CUTOFF;
- props.Equalizer.HighGain = AL_EQUALIZER_DEFAULT_HIGH_GAIN;
- return props;
-}
+void EffectHandler::GetParamfv(const EqualizerProps &props, ALenum param, float *vals)
+{ GetParamf(props, param, vals); }
-} // namespace
-
-DEFINE_ALEFFECT_VTABLE(Equalizer);
-
-const EffectProps EqualizerEffectProps{genDefaultProps()};
#ifdef ALSOFT_EAX
namespace {
@@ -325,17 +295,20 @@ bool EaxEqualizerCommitter::commit(const EAXEQUALIZERPROPERTIES &props)
return false;
mEaxProps = props;
-
- mAlProps.Equalizer.LowGain = level_mb_to_gain(static_cast<float>(props.lLowGain));
- mAlProps.Equalizer.LowCutoff = props.flLowCutOff;
- mAlProps.Equalizer.Mid1Gain = level_mb_to_gain(static_cast<float>(props.lMid1Gain));
- mAlProps.Equalizer.Mid1Center = props.flMid1Center;
- mAlProps.Equalizer.Mid1Width = props.flMid1Width;
- mAlProps.Equalizer.Mid2Gain = level_mb_to_gain(static_cast<float>(props.lMid2Gain));
- mAlProps.Equalizer.Mid2Center = props.flMid2Center;
- mAlProps.Equalizer.Mid2Width = props.flMid2Width;
- mAlProps.Equalizer.HighGain = level_mb_to_gain(static_cast<float>(props.lHighGain));
- mAlProps.Equalizer.HighCutoff = props.flHighCutOff;
+ mAlProps = [&]{
+ EqualizerProps ret{};
+ ret.LowGain = level_mb_to_gain(static_cast<float>(props.lLowGain));
+ ret.LowCutoff = props.flLowCutOff;
+ ret.Mid1Gain = level_mb_to_gain(static_cast<float>(props.lMid1Gain));
+ ret.Mid1Center = props.flMid1Center;
+ ret.Mid1Width = props.flMid1Width;
+ ret.Mid2Gain = level_mb_to_gain(static_cast<float>(props.lMid2Gain));
+ ret.Mid2Center = props.flMid2Center;
+ ret.Mid2Width = props.flMid2Width;
+ ret.HighGain = level_mb_to_gain(static_cast<float>(props.lHighGain));
+ ret.HighCutoff = props.flHighCutOff;
+ return ret;
+ }();
return true;
}