7 #include "alc/effects/base.h"
11 #include "alnumeric.h"
12 #include "al/eax/exception.h"
13 #include "al/eax/utils.h"
19 void Pshifter_setParamf(EffectProps*, ALenum param, float)
20 { throw effect_exception{AL_INVALID_ENUM, "Invalid pitch shifter float property 0x%04x", param}; }
21 void Pshifter_setParamfv(EffectProps*, ALenum param, const float*)
23 throw effect_exception{AL_INVALID_ENUM, "Invalid pitch shifter float-vector property 0x%04x",
27 void Pshifter_setParami(EffectProps *props, ALenum param, int val)
31 case AL_PITCH_SHIFTER_COARSE_TUNE:
32 if(!(val >= AL_PITCH_SHIFTER_MIN_COARSE_TUNE && val <= AL_PITCH_SHIFTER_MAX_COARSE_TUNE))
33 throw effect_exception{AL_INVALID_VALUE, "Pitch shifter coarse tune out of range"};
34 props->Pshifter.CoarseTune = val;
37 case AL_PITCH_SHIFTER_FINE_TUNE:
38 if(!(val >= AL_PITCH_SHIFTER_MIN_FINE_TUNE && val <= AL_PITCH_SHIFTER_MAX_FINE_TUNE))
39 throw effect_exception{AL_INVALID_VALUE, "Pitch shifter fine tune out of range"};
40 props->Pshifter.FineTune = val;
44 throw effect_exception{AL_INVALID_ENUM, "Invalid pitch shifter integer property 0x%04x",
48 void Pshifter_setParamiv(EffectProps *props, ALenum param, const int *vals)
49 { Pshifter_setParami(props, param, vals[0]); }
51 void Pshifter_getParami(const EffectProps *props, ALenum param, int *val)
55 case AL_PITCH_SHIFTER_COARSE_TUNE:
56 *val = props->Pshifter.CoarseTune;
58 case AL_PITCH_SHIFTER_FINE_TUNE:
59 *val = props->Pshifter.FineTune;
63 throw effect_exception{AL_INVALID_ENUM, "Invalid pitch shifter integer property 0x%04x",
67 void Pshifter_getParamiv(const EffectProps *props, ALenum param, int *vals)
68 { Pshifter_getParami(props, param, vals); }
70 void Pshifter_getParamf(const EffectProps*, ALenum param, float*)
71 { throw effect_exception{AL_INVALID_ENUM, "Invalid pitch shifter float property 0x%04x", param}; }
72 void Pshifter_getParamfv(const EffectProps*, ALenum param, float*)
74 throw effect_exception{AL_INVALID_ENUM, "Invalid pitch shifter float vector-property 0x%04x",
78 EffectProps genDefaultProps() noexcept
81 props.Pshifter.CoarseTune = AL_PITCH_SHIFTER_DEFAULT_COARSE_TUNE;
82 props.Pshifter.FineTune = AL_PITCH_SHIFTER_DEFAULT_FINE_TUNE;
88 DEFINE_ALEFFECT_VTABLE(Pshifter);
90 const EffectProps PshifterEffectProps{genDefaultProps()};
95 using PitchShifterCommitter = EaxCommitter<EaxPitchShifterCommitter>;
97 struct CoarseTuneValidator {
98 void operator()(long lCoarseTune) const
100 eax_validate_range<PitchShifterCommitter::Exception>(
103 EAXPITCHSHIFTER_MINCOARSETUNE,
104 EAXPITCHSHIFTER_MAXCOARSETUNE);
106 }; // CoarseTuneValidator
108 struct FineTuneValidator {
109 void operator()(long lFineTune) const
111 eax_validate_range<PitchShifterCommitter::Exception>(
114 EAXPITCHSHIFTER_MINFINETUNE,
115 EAXPITCHSHIFTER_MAXFINETUNE);
117 }; // FineTuneValidator
119 struct AllValidator {
120 void operator()(const EAXPITCHSHIFTERPROPERTIES& all) const
122 CoarseTuneValidator{}(all.lCoarseTune);
123 FineTuneValidator{}(all.lFineTune);
130 struct PitchShifterCommitter::Exception : public EaxException {
131 explicit Exception(const char *message) : EaxException{"EAX_PITCH_SHIFTER_EFFECT", message}
136 [[noreturn]] void PitchShifterCommitter::fail(const char *message)
138 throw Exception{message};
142 bool PitchShifterCommitter::commit(const EaxEffectProps &props)
144 if(props.mType == mEaxProps.mType
145 && mEaxProps.mPitchShifter.lCoarseTune == props.mPitchShifter.lCoarseTune
146 && mEaxProps.mPitchShifter.lFineTune == props.mPitchShifter.lFineTune)
151 mAlProps.Pshifter.CoarseTune = static_cast<int>(mEaxProps.mPitchShifter.lCoarseTune);
152 mAlProps.Pshifter.FineTune = static_cast<int>(mEaxProps.mPitchShifter.lFineTune);
158 void PitchShifterCommitter::SetDefaults(EaxEffectProps &props)
160 props.mType = EaxEffectType::PitchShifter;
161 props.mPitchShifter.lCoarseTune = EAXPITCHSHIFTER_DEFAULTCOARSETUNE;
162 props.mPitchShifter.lFineTune = EAXPITCHSHIFTER_DEFAULTFINETUNE;
166 void PitchShifterCommitter::Get(const EaxCall &call, const EaxEffectProps &props)
168 switch(call.get_property_id())
170 case EAXPITCHSHIFTER_NONE: break;
171 case EAXPITCHSHIFTER_ALLPARAMETERS: call.set_value<Exception>(props.mPitchShifter); break;
172 case EAXPITCHSHIFTER_COARSETUNE: call.set_value<Exception>(props.mPitchShifter.lCoarseTune); break;
173 case EAXPITCHSHIFTER_FINETUNE: call.set_value<Exception>(props.mPitchShifter.lFineTune); break;
174 default: fail_unknown_property_id();
179 void PitchShifterCommitter::Set(const EaxCall &call, EaxEffectProps &props)
181 switch(call.get_property_id())
183 case EAXPITCHSHIFTER_NONE: break;
184 case EAXPITCHSHIFTER_ALLPARAMETERS: defer<AllValidator>(call, props.mPitchShifter); break;
185 case EAXPITCHSHIFTER_COARSETUNE: defer<CoarseTuneValidator>(call, props.mPitchShifter.lCoarseTune); break;
186 case EAXPITCHSHIFTER_FINETUNE: defer<FineTuneValidator>(call, props.mPitchShifter.lFineTune); break;
187 default: fail_unknown_property_id();