7 #include "alc/effects/base.h"
11 #include "alnumeric.h"
12 #include "al/eax/effect.h"
13 #include "al/eax/exception.h"
14 #include "al/eax/utils.h"
20 constexpr EffectProps
genDefaultProps() noexcept
22 CompressorProps props
{};
23 props
.OnOff
= AL_COMPRESSOR_DEFAULT_ONOFF
;
29 const EffectProps CompressorEffectProps
{genDefaultProps()};
31 void CompressorEffectHandler::SetParami(CompressorProps
&props
, ALenum param
, int val
)
35 case AL_COMPRESSOR_ONOFF
:
36 if(!(val
>= AL_COMPRESSOR_MIN_ONOFF
&& val
<= AL_COMPRESSOR_MAX_ONOFF
))
37 throw effect_exception
{AL_INVALID_VALUE
, "Compressor state out of range"};
38 props
.OnOff
= (val
!= AL_FALSE
);
42 throw effect_exception
{AL_INVALID_ENUM
, "Invalid compressor integer property 0x%04x",
46 void CompressorEffectHandler::SetParamiv(CompressorProps
&props
, ALenum param
, const int *vals
)
47 { SetParami(props
, param
, *vals
); }
48 void CompressorEffectHandler::SetParamf(CompressorProps
&, ALenum param
, float)
49 { throw effect_exception
{AL_INVALID_ENUM
, "Invalid compressor float property 0x%04x", param
}; }
50 void CompressorEffectHandler::SetParamfv(CompressorProps
&, ALenum param
, const float*)
52 throw effect_exception
{AL_INVALID_ENUM
, "Invalid compressor float-vector property 0x%04x",
56 void CompressorEffectHandler::GetParami(const CompressorProps
&props
, ALenum param
, int *val
)
60 case AL_COMPRESSOR_ONOFF
: *val
= props
.OnOff
; break;
62 throw effect_exception
{AL_INVALID_ENUM
, "Invalid compressor integer property 0x%04x",
66 void CompressorEffectHandler::GetParamiv(const CompressorProps
&props
, ALenum param
, int *vals
)
67 { GetParami(props
, param
, vals
); }
68 void CompressorEffectHandler::GetParamf(const CompressorProps
&, ALenum param
, float*)
69 { throw effect_exception
{AL_INVALID_ENUM
, "Invalid compressor float property 0x%04x", param
}; }
70 void CompressorEffectHandler::GetParamfv(const CompressorProps
&, ALenum param
, float*)
72 throw effect_exception
{AL_INVALID_ENUM
, "Invalid compressor float-vector property 0x%04x",
80 using CompressorCommitter
= EaxCommitter
<EaxCompressorCommitter
>;
82 struct OnOffValidator
{
83 void operator()(unsigned long ulOnOff
) const
85 eax_validate_range
<CompressorCommitter::Exception
>(
88 EAXAGCCOMPRESSOR_MINONOFF
,
89 EAXAGCCOMPRESSOR_MAXONOFF
);
94 void operator()(const EAXAGCCOMPRESSORPROPERTIES
& all
) const
96 OnOffValidator
{}(all
.ulOnOff
);
103 struct CompressorCommitter::Exception
: public EaxException
105 explicit Exception(const char *message
) : EaxException
{"EAX_CHORUS_EFFECT", message
}
110 [[noreturn
]] void CompressorCommitter::fail(const char *message
)
112 throw Exception
{message
};
115 bool EaxCompressorCommitter::commit(const EAXAGCCOMPRESSORPROPERTIES
&props
)
117 if(auto *cur
= std::get_if
<EAXAGCCOMPRESSORPROPERTIES
>(&mEaxProps
); cur
&& *cur
== props
)
121 mAlProps
= CompressorProps
{props
.ulOnOff
!= 0};
126 void EaxCompressorCommitter::SetDefaults(EaxEffectProps
&props
)
128 props
= EAXAGCCOMPRESSORPROPERTIES
{EAXAGCCOMPRESSOR_DEFAULTONOFF
};
131 void EaxCompressorCommitter::Get(const EaxCall
&call
, const EAXAGCCOMPRESSORPROPERTIES
&props
)
133 switch(call
.get_property_id())
135 case EAXAGCCOMPRESSOR_NONE
: break;
136 case EAXAGCCOMPRESSOR_ALLPARAMETERS
: call
.set_value
<Exception
>(props
); break;
137 case EAXAGCCOMPRESSOR_ONOFF
: call
.set_value
<Exception
>(props
.ulOnOff
); break;
138 default: fail_unknown_property_id();
142 void EaxCompressorCommitter::Set(const EaxCall
&call
, EAXAGCCOMPRESSORPROPERTIES
&props
)
144 switch(call
.get_property_id())
146 case EAXAGCCOMPRESSOR_NONE
: break;
147 case EAXAGCCOMPRESSOR_ALLPARAMETERS
: defer
<AllValidator
>(call
, props
); break;
148 case EAXAGCCOMPRESSOR_ONOFF
: defer
<OnOffValidator
>(call
, props
.ulOnOff
); break;
149 default: fail_unknown_property_id();