diff options
Diffstat (limited to 'al/effects/modulator.cpp')
-rw-r--r-- | al/effects/modulator.cpp | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/al/effects/modulator.cpp b/al/effects/modulator.cpp index 95f379e2..89dcc209 100644 --- a/al/effects/modulator.cpp +++ b/al/effects/modulator.cpp @@ -4,25 +4,48 @@ #include "AL/al.h" #include "AL/efx.h" +#include "aloptional.h" #include "effects.h" #include "effects/base.h" namespace { +al::optional<ModulatorWaveform> WaveformFromEmum(ALenum value) +{ + switch(value) + { + case AL_RING_MODULATOR_SINUSOID: return al::make_optional(ModulatorWaveform::Sinusoid); + case AL_RING_MODULATOR_SAWTOOTH: return al::make_optional(ModulatorWaveform::Sawtooth); + case AL_RING_MODULATOR_SQUARE: return al::make_optional(ModulatorWaveform::Square); + } + return al::nullopt; +} +ALenum EnumFromWaveform(ModulatorWaveform type) +{ + switch(type) + { + case ModulatorWaveform::Sinusoid: return AL_RING_MODULATOR_SINUSOID; + case ModulatorWaveform::Sawtooth: return AL_RING_MODULATOR_SAWTOOTH; + case ModulatorWaveform::Square: return AL_RING_MODULATOR_SQUARE; + } + throw std::runtime_error{"Invalid modulator waveform: " + + std::to_string(static_cast<int>(type))}; +} + void Modulator_setParamf(EffectProps *props, ALenum param, float val) { switch(param) { case AL_RING_MODULATOR_FREQUENCY: if(!(val >= AL_RING_MODULATOR_MIN_FREQUENCY && val <= AL_RING_MODULATOR_MAX_FREQUENCY)) - throw effect_exception{AL_INVALID_VALUE, "Modulator frequency out of range"}; + throw effect_exception{AL_INVALID_VALUE, "Modulator frequency out of range: %f", val}; props->Modulator.Frequency = val; break; case AL_RING_MODULATOR_HIGHPASS_CUTOFF: if(!(val >= AL_RING_MODULATOR_MIN_HIGHPASS_CUTOFF && val <= AL_RING_MODULATOR_MAX_HIGHPASS_CUTOFF)) - throw effect_exception{AL_INVALID_VALUE, "Modulator high-pass cutoff out of range"}; + throw effect_exception{AL_INVALID_VALUE, "Modulator high-pass cutoff out of range: %f", val}; props->Modulator.HighPassCutoff = val; break; @@ -42,9 +65,10 @@ void Modulator_setParami(EffectProps *props, ALenum param, int val) break; case AL_RING_MODULATOR_WAVEFORM: - if(!(val >= AL_RING_MODULATOR_MIN_WAVEFORM && val <= AL_RING_MODULATOR_MAX_WAVEFORM)) - throw effect_exception{AL_INVALID_VALUE, "Invalid modulator waveform"}; - props->Modulator.Waveform = val; + if(auto formopt = WaveformFromEmum(val)) + props->Modulator.Waveform = *formopt; + else + throw effect_exception{AL_INVALID_VALUE, "Invalid modulator waveform: 0x%04x", val}; break; default: @@ -66,7 +90,7 @@ void Modulator_getParami(const EffectProps *props, ALenum param, int *val) *val = static_cast<int>(props->Modulator.HighPassCutoff); break; case AL_RING_MODULATOR_WAVEFORM: - *val = props->Modulator.Waveform; + *val = EnumFromWaveform(props->Modulator.Waveform); break; default: @@ -99,7 +123,7 @@ EffectProps genDefaultProps() noexcept EffectProps props{}; props.Modulator.Frequency = AL_RING_MODULATOR_DEFAULT_FREQUENCY; props.Modulator.HighPassCutoff = AL_RING_MODULATOR_DEFAULT_HIGHPASS_CUTOFF; - props.Modulator.Waveform = AL_RING_MODULATOR_DEFAULT_WAVEFORM; + props.Modulator.Waveform = *WaveformFromEmum(AL_RING_MODULATOR_DEFAULT_WAVEFORM); return props; } |