7 #include "alc/effects/base.h"
11 #include "al/eax/effect.h"
12 #include "al/eax/exception.h"
13 #include "al/eax/utils.h"
19 constexpr EffectProps
genDefaultProps() noexcept
21 CompressorProps props
{};
22 props
.OnOff
= AL_COMPRESSOR_DEFAULT_ONOFF
;
28 const EffectProps CompressorEffectProps
{genDefaultProps()};
30 void CompressorEffectHandler::SetParami(CompressorProps
&props
, ALenum param
, int val
)
34 case AL_COMPRESSOR_ONOFF
:
35 if(!(val
>= AL_COMPRESSOR_MIN_ONOFF
&& val
<= AL_COMPRESSOR_MAX_ONOFF
))
36 throw effect_exception
{AL_INVALID_VALUE
, "Compressor state out of range"};
37 props
.OnOff
= (val
!= AL_FALSE
);
41 throw effect_exception
{AL_INVALID_ENUM
, "Invalid compressor integer property 0x%04x",
45 void CompressorEffectHandler::SetParamiv(CompressorProps
&props
, ALenum param
, const int *vals
)
46 { SetParami(props
, param
, *vals
); }
47 void CompressorEffectHandler::SetParamf(CompressorProps
&, ALenum param
, float)
48 { throw effect_exception
{AL_INVALID_ENUM
, "Invalid compressor float property 0x%04x", param
}; }
49 void CompressorEffectHandler::SetParamfv(CompressorProps
&, ALenum param
, const float*)
51 throw effect_exception
{AL_INVALID_ENUM
, "Invalid compressor float-vector property 0x%04x",
55 void CompressorEffectHandler::GetParami(const CompressorProps
&props
, ALenum param
, int *val
)
59 case AL_COMPRESSOR_ONOFF
: *val
= props
.OnOff
; break;
61 throw effect_exception
{AL_INVALID_ENUM
, "Invalid compressor integer property 0x%04x",
65 void CompressorEffectHandler::GetParamiv(const CompressorProps
&props
, ALenum param
, int *vals
)
66 { GetParami(props
, param
, vals
); }
67 void CompressorEffectHandler::GetParamf(const CompressorProps
&, ALenum param
, float*)
68 { throw effect_exception
{AL_INVALID_ENUM
, "Invalid compressor float property 0x%04x", param
}; }
69 void CompressorEffectHandler::GetParamfv(const CompressorProps
&, ALenum param
, float*)
71 throw effect_exception
{AL_INVALID_ENUM
, "Invalid compressor float-vector property 0x%04x",
79 using CompressorCommitter
= EaxCommitter
<EaxCompressorCommitter
>;
81 struct OnOffValidator
{
82 void operator()(unsigned long ulOnOff
) const
84 eax_validate_range
<CompressorCommitter::Exception
>(
87 EAXAGCCOMPRESSOR_MINONOFF
,
88 EAXAGCCOMPRESSOR_MAXONOFF
);
93 void operator()(const EAXAGCCOMPRESSORPROPERTIES
& all
) const
95 OnOffValidator
{}(all
.ulOnOff
);
102 struct CompressorCommitter::Exception
: public EaxException
104 explicit Exception(const char *message
) : EaxException
{"EAX_CHORUS_EFFECT", message
}
109 [[noreturn
]] void CompressorCommitter::fail(const char *message
)
111 throw Exception
{message
};
114 bool EaxCompressorCommitter::commit(const EAXAGCCOMPRESSORPROPERTIES
&props
)
116 if(auto *cur
= std::get_if
<EAXAGCCOMPRESSORPROPERTIES
>(&mEaxProps
); cur
&& *cur
== props
)
120 mAlProps
= CompressorProps
{props
.ulOnOff
!= 0};
125 void EaxCompressorCommitter::SetDefaults(EaxEffectProps
&props
)
127 props
= EAXAGCCOMPRESSORPROPERTIES
{EAXAGCCOMPRESSOR_DEFAULTONOFF
};
130 void EaxCompressorCommitter::Get(const EaxCall
&call
, const EAXAGCCOMPRESSORPROPERTIES
&props
)
132 switch(call
.get_property_id())
134 case EAXAGCCOMPRESSOR_NONE
: break;
135 case EAXAGCCOMPRESSOR_ALLPARAMETERS
: call
.set_value
<Exception
>(props
); break;
136 case EAXAGCCOMPRESSOR_ONOFF
: call
.set_value
<Exception
>(props
.ulOnOff
); break;
137 default: fail_unknown_property_id();
141 void EaxCompressorCommitter::Set(const EaxCall
&call
, EAXAGCCOMPRESSORPROPERTIES
&props
)
143 switch(call
.get_property_id())
145 case EAXAGCCOMPRESSOR_NONE
: break;
146 case EAXAGCCOMPRESSOR_ALLPARAMETERS
: defer
<AllValidator
>(call
, props
); break;
147 case EAXAGCCOMPRESSOR_ONOFF
: defer
<OnOffValidator
>(call
, props
.ulOnOff
); break;
148 default: fail_unknown_property_id();