1 2 #include "config.h" 3 4 #include "AL/al.h" 5 #include "AL/efx.h" 6 7 #include "effects.h" 8 #include "effects/base.h" 9 10 11 namespace { 12 13 void Distortion_setParami(EffectProps*, ALenum param, int) 14 { throw effect_exception{AL_INVALID_ENUM, "Invalid distortion integer property 0x%04x", param}; } 15 void Distortion_setParamiv(EffectProps*, ALenum param, const int*) 16 { 17 throw effect_exception{AL_INVALID_ENUM, "Invalid distortion integer-vector property 0x%04x", 18 param}; 19 } 20 void Distortion_setParamf(EffectProps *props, ALenum param, float val) 21 { 22 switch(param) 23 { 24 case AL_DISTORTION_EDGE: 25 if(!(val >= AL_DISTORTION_MIN_EDGE && val <= AL_DISTORTION_MAX_EDGE)) 26 throw effect_exception{AL_INVALID_VALUE, "Distortion edge out of range"}; 27 props->Distortion.Edge = val; 28 break; 29 30 case AL_DISTORTION_GAIN: 31 if(!(val >= AL_DISTORTION_MIN_GAIN && val <= AL_DISTORTION_MAX_GAIN)) 32 throw effect_exception{AL_INVALID_VALUE, "Distortion gain out of range"}; 33 props->Distortion.Gain = val; 34 break; 35 36 case AL_DISTORTION_LOWPASS_CUTOFF: 37 if(!(val >= AL_DISTORTION_MIN_LOWPASS_CUTOFF && val <= AL_DISTORTION_MAX_LOWPASS_CUTOFF)) 38 throw effect_exception{AL_INVALID_VALUE, "Distortion low-pass cutoff out of range"}; 39 props->Distortion.LowpassCutoff = val; 40 break; 41 42 case AL_DISTORTION_EQCENTER: 43 if(!(val >= AL_DISTORTION_MIN_EQCENTER && val <= AL_DISTORTION_MAX_EQCENTER)) 44 throw effect_exception{AL_INVALID_VALUE, "Distortion EQ center out of range"}; 45 props->Distortion.EQCenter = val; 46 break; 47 48 case AL_DISTORTION_EQBANDWIDTH: 49 if(!(val >= AL_DISTORTION_MIN_EQBANDWIDTH && val <= AL_DISTORTION_MAX_EQBANDWIDTH)) 50 throw effect_exception{AL_INVALID_VALUE, "Distortion EQ bandwidth out of range"}; 51 props->Distortion.EQBandwidth = val; 52 break; 53 54 default: 55 throw effect_exception{AL_INVALID_ENUM, "Invalid distortion float property 0x%04x", param}; 56 } 57 } 58 void Distortion_setParamfv(EffectProps *props, ALenum param, const float *vals) 59 { Distortion_setParamf(props, param, vals[0]); } 60 61 void Distortion_getParami(const EffectProps*, ALenum param, int*) 62 { throw effect_exception{AL_INVALID_ENUM, "Invalid distortion integer property 0x%04x", param}; } 63 void Distortion_getParamiv(const EffectProps*, ALenum param, int*) 64 { 65 throw effect_exception{AL_INVALID_ENUM, "Invalid distortion integer-vector property 0x%04x", 66 param}; 67 } 68 void Distortion_getParamf(const EffectProps *props, ALenum param, float *val) 69 { 70 switch(param) 71 { 72 case AL_DISTORTION_EDGE: 73 *val = props->Distortion.Edge; 74 break; 75 76 case AL_DISTORTION_GAIN: 77 *val = props->Distortion.Gain; 78 break; 79 80 case AL_DISTORTION_LOWPASS_CUTOFF: 81 *val = props->Distortion.LowpassCutoff; 82 break; 83 84 case AL_DISTORTION_EQCENTER: 85 *val = props->Distortion.EQCenter; 86 break; 87 88 case AL_DISTORTION_EQBANDWIDTH: 89 *val = props->Distortion.EQBandwidth; 90 break; 91 92 default: 93 throw effect_exception{AL_INVALID_ENUM, "Invalid distortion float property 0x%04x", param}; 94 } 95 } 96 void Distortion_getParamfv(const EffectProps *props, ALenum param, float *vals) 97 { Distortion_getParamf(props, param, vals); } 98 99 EffectProps genDefaultProps() noexcept 100 { 101 EffectProps props{}; 102 props.Distortion.Edge = AL_DISTORTION_DEFAULT_EDGE; 103 props.Distortion.Gain = AL_DISTORTION_DEFAULT_GAIN; 104 props.Distortion.LowpassCutoff = AL_DISTORTION_DEFAULT_LOWPASS_CUTOFF; 105 props.Distortion.EQCenter = AL_DISTORTION_DEFAULT_EQCENTER; 106 props.Distortion.EQBandwidth = AL_DISTORTION_DEFAULT_EQBANDWIDTH; 107 return props; 108 } 109 110 } // namespace 111 112 DEFINE_ALEFFECT_VTABLE(Distortion); 113 114 const EffectProps DistortionEffectProps{genDefaultProps()}; 115