2021-04-28 12:43:51 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include "AL/efx.h"
|
|
|
|
|
2021-05-14 10:15:42 +08:00
|
|
|
#include "alc/effects/base.h"
|
2021-04-28 12:43:51 +08:00
|
|
|
#include "effects.h"
|
|
|
|
|
2022-04-25 12:02:45 +08:00
|
|
|
#ifdef ALSOFT_EAX
|
|
|
|
#include "alnumeric.h"
|
2022-07-14 23:17:11 +08:00
|
|
|
#include "al/eax/exception.h"
|
|
|
|
#include "al/eax/utils.h"
|
2022-04-25 12:02:45 +08:00
|
|
|
#endif // ALSOFT_EAX
|
|
|
|
|
|
|
|
|
2021-04-28 12:43:51 +08:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
void Autowah_setParamf(EffectProps *props, ALenum param, float val)
|
|
|
|
{
|
|
|
|
switch(param)
|
|
|
|
{
|
|
|
|
case AL_AUTOWAH_ATTACK_TIME:
|
|
|
|
if(!(val >= AL_AUTOWAH_MIN_ATTACK_TIME && val <= AL_AUTOWAH_MAX_ATTACK_TIME))
|
|
|
|
throw effect_exception{AL_INVALID_VALUE, "Autowah attack time out of range"};
|
|
|
|
props->Autowah.AttackTime = val;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AL_AUTOWAH_RELEASE_TIME:
|
|
|
|
if(!(val >= AL_AUTOWAH_MIN_RELEASE_TIME && val <= AL_AUTOWAH_MAX_RELEASE_TIME))
|
|
|
|
throw effect_exception{AL_INVALID_VALUE, "Autowah release time out of range"};
|
|
|
|
props->Autowah.ReleaseTime = val;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AL_AUTOWAH_RESONANCE:
|
|
|
|
if(!(val >= AL_AUTOWAH_MIN_RESONANCE && val <= AL_AUTOWAH_MAX_RESONANCE))
|
|
|
|
throw effect_exception{AL_INVALID_VALUE, "Autowah resonance out of range"};
|
|
|
|
props->Autowah.Resonance = val;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AL_AUTOWAH_PEAK_GAIN:
|
|
|
|
if(!(val >= AL_AUTOWAH_MIN_PEAK_GAIN && val <= AL_AUTOWAH_MAX_PEAK_GAIN))
|
|
|
|
throw effect_exception{AL_INVALID_VALUE, "Autowah peak gain out of range"};
|
|
|
|
props->Autowah.PeakGain = val;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw effect_exception{AL_INVALID_ENUM, "Invalid autowah float property 0x%04x", param};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void Autowah_setParamfv(EffectProps *props, ALenum param, const float *vals)
|
|
|
|
{ Autowah_setParamf(props, param, vals[0]); }
|
|
|
|
|
|
|
|
void Autowah_setParami(EffectProps*, ALenum param, int)
|
|
|
|
{ throw effect_exception{AL_INVALID_ENUM, "Invalid autowah integer property 0x%04x", param}; }
|
|
|
|
void Autowah_setParamiv(EffectProps*, ALenum param, const int*)
|
|
|
|
{
|
|
|
|
throw effect_exception{AL_INVALID_ENUM, "Invalid autowah integer vector property 0x%04x",
|
|
|
|
param};
|
|
|
|
}
|
|
|
|
|
|
|
|
void Autowah_getParamf(const EffectProps *props, ALenum param, float *val)
|
|
|
|
{
|
|
|
|
switch(param)
|
|
|
|
{
|
|
|
|
case AL_AUTOWAH_ATTACK_TIME:
|
|
|
|
*val = props->Autowah.AttackTime;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AL_AUTOWAH_RELEASE_TIME:
|
|
|
|
*val = props->Autowah.ReleaseTime;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AL_AUTOWAH_RESONANCE:
|
|
|
|
*val = props->Autowah.Resonance;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AL_AUTOWAH_PEAK_GAIN:
|
|
|
|
*val = props->Autowah.PeakGain;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw effect_exception{AL_INVALID_ENUM, "Invalid autowah float property 0x%04x", param};
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
void Autowah_getParamfv(const EffectProps *props, ALenum param, float *vals)
|
|
|
|
{ Autowah_getParamf(props, param, vals); }
|
|
|
|
|
|
|
|
void Autowah_getParami(const EffectProps*, ALenum param, int*)
|
|
|
|
{ throw effect_exception{AL_INVALID_ENUM, "Invalid autowah integer property 0x%04x", param}; }
|
|
|
|
void Autowah_getParamiv(const EffectProps*, ALenum param, int*)
|
|
|
|
{
|
|
|
|
throw effect_exception{AL_INVALID_ENUM, "Invalid autowah integer vector property 0x%04x",
|
|
|
|
param};
|
|
|
|
}
|
|
|
|
|
|
|
|
EffectProps genDefaultProps() noexcept
|
|
|
|
{
|
|
|
|
EffectProps props{};
|
|
|
|
props.Autowah.AttackTime = AL_AUTOWAH_DEFAULT_ATTACK_TIME;
|
|
|
|
props.Autowah.ReleaseTime = AL_AUTOWAH_DEFAULT_RELEASE_TIME;
|
|
|
|
props.Autowah.Resonance = AL_AUTOWAH_DEFAULT_RESONANCE;
|
|
|
|
props.Autowah.PeakGain = AL_AUTOWAH_DEFAULT_PEAK_GAIN;
|
|
|
|
return props;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
DEFINE_ALEFFECT_VTABLE(Autowah);
|
|
|
|
|
|
|
|
const EffectProps AutowahEffectProps{genDefaultProps()};
|
2022-04-25 12:02:45 +08:00
|
|
|
|
|
|
|
#ifdef ALSOFT_EAX
|
|
|
|
namespace {
|
|
|
|
|
2022-07-14 23:17:11 +08:00
|
|
|
class EaxAutoWahEffectException : public EaxException {
|
2022-04-25 12:02:45 +08:00
|
|
|
public:
|
2022-07-14 23:17:11 +08:00
|
|
|
explicit EaxAutoWahEffectException(const char* message)
|
|
|
|
: EaxException{"EAX_AUTO_WAH_EFFECT", message}
|
|
|
|
{}
|
|
|
|
}; // EaxAutoWahEffectException
|
2022-04-25 12:02:45 +08:00
|
|
|
|
2022-07-14 23:17:11 +08:00
|
|
|
class EaxAutoWahEffect final : public EaxEffect4<EaxAutoWahEffectException, EAXAUTOWAHPROPERTIES> {
|
|
|
|
public:
|
2023-02-04 15:03:54 +08:00
|
|
|
EaxAutoWahEffect(int eax_version);
|
2022-04-25 12:02:45 +08:00
|
|
|
|
|
|
|
private:
|
2022-07-14 23:17:11 +08:00
|
|
|
struct AttackTimeValidator {
|
|
|
|
void operator()(float flAttackTime) const
|
|
|
|
{
|
|
|
|
eax_validate_range<Exception>(
|
|
|
|
"Attack Time",
|
|
|
|
flAttackTime,
|
|
|
|
EAXAUTOWAH_MINATTACKTIME,
|
|
|
|
EAXAUTOWAH_MAXATTACKTIME);
|
|
|
|
}
|
|
|
|
}; // AttackTimeValidator
|
|
|
|
|
|
|
|
struct ReleaseTimeValidator {
|
|
|
|
void operator()(float flReleaseTime) const
|
|
|
|
{
|
|
|
|
eax_validate_range<Exception>(
|
|
|
|
"Release Time",
|
|
|
|
flReleaseTime,
|
|
|
|
EAXAUTOWAH_MINRELEASETIME,
|
|
|
|
EAXAUTOWAH_MAXRELEASETIME);
|
|
|
|
}
|
|
|
|
}; // ReleaseTimeValidator
|
|
|
|
|
|
|
|
struct ResonanceValidator {
|
|
|
|
void operator()(long lResonance) const
|
|
|
|
{
|
|
|
|
eax_validate_range<Exception>(
|
|
|
|
"Resonance",
|
|
|
|
lResonance,
|
|
|
|
EAXAUTOWAH_MINRESONANCE,
|
|
|
|
EAXAUTOWAH_MAXRESONANCE);
|
|
|
|
}
|
|
|
|
}; // ResonanceValidator
|
|
|
|
|
|
|
|
struct PeakLevelValidator {
|
|
|
|
void operator()(long lPeakLevel) const
|
|
|
|
{
|
|
|
|
eax_validate_range<Exception>(
|
|
|
|
"Peak Level",
|
|
|
|
lPeakLevel,
|
|
|
|
EAXAUTOWAH_MINPEAKLEVEL,
|
|
|
|
EAXAUTOWAH_MAXPEAKLEVEL);
|
|
|
|
}
|
|
|
|
}; // PeakLevelValidator
|
|
|
|
|
|
|
|
struct AllValidator {
|
|
|
|
void operator()(const Props& all) const
|
|
|
|
{
|
|
|
|
AttackTimeValidator{}(all.flAttackTime);
|
|
|
|
ReleaseTimeValidator{}(all.flReleaseTime);
|
|
|
|
ResonanceValidator{}(all.lResonance);
|
|
|
|
PeakLevelValidator{}(all.lPeakLevel);
|
|
|
|
}
|
|
|
|
}; // AllValidator
|
|
|
|
|
|
|
|
void set_defaults(Props& props) override;
|
|
|
|
|
|
|
|
void set_efx_attack_time() noexcept;
|
|
|
|
void set_efx_release_time() noexcept;
|
|
|
|
void set_efx_resonance() noexcept;
|
|
|
|
void set_efx_peak_gain() noexcept;
|
|
|
|
void set_efx_defaults() override;
|
|
|
|
|
|
|
|
void get(const EaxCall& call, const Props& props) override;
|
|
|
|
void set(const EaxCall& call, Props& props) override;
|
|
|
|
bool commit_props(const Props& props) override;
|
2022-04-25 12:02:45 +08:00
|
|
|
}; // EaxAutoWahEffect
|
|
|
|
|
2023-02-04 15:03:54 +08:00
|
|
|
EaxAutoWahEffect::EaxAutoWahEffect(int eax_version)
|
|
|
|
: EaxEffect4{AL_EFFECT_AUTOWAH, eax_version}
|
2022-07-14 23:17:11 +08:00
|
|
|
{}
|
2022-04-25 12:02:45 +08:00
|
|
|
|
2022-07-14 23:17:11 +08:00
|
|
|
void EaxAutoWahEffect::set_defaults(Props& props)
|
2022-04-25 12:02:45 +08:00
|
|
|
{
|
2022-07-14 23:17:11 +08:00
|
|
|
props.flAttackTime = EAXAUTOWAH_DEFAULTATTACKTIME;
|
|
|
|
props.flReleaseTime = EAXAUTOWAH_DEFAULTRELEASETIME;
|
|
|
|
props.lResonance = EAXAUTOWAH_DEFAULTRESONANCE;
|
|
|
|
props.lPeakLevel = EAXAUTOWAH_DEFAULTPEAKLEVEL;
|
2022-04-25 12:02:45 +08:00
|
|
|
}
|
|
|
|
|
2022-07-14 23:17:11 +08:00
|
|
|
void EaxAutoWahEffect::set_efx_attack_time() noexcept
|
2022-04-25 12:02:45 +08:00
|
|
|
{
|
2022-07-14 23:17:11 +08:00
|
|
|
al_effect_props_.Autowah.AttackTime = clamp(
|
|
|
|
props_.flAttackTime,
|
2022-04-25 12:02:45 +08:00
|
|
|
AL_AUTOWAH_MIN_ATTACK_TIME,
|
|
|
|
AL_AUTOWAH_MAX_ATTACK_TIME);
|
|
|
|
}
|
|
|
|
|
2022-07-14 23:17:11 +08:00
|
|
|
void EaxAutoWahEffect::set_efx_release_time() noexcept
|
2022-04-25 12:02:45 +08:00
|
|
|
{
|
2022-07-14 23:17:11 +08:00
|
|
|
al_effect_props_.Autowah.ReleaseTime = clamp(
|
|
|
|
props_.flReleaseTime,
|
2022-04-25 12:02:45 +08:00
|
|
|
AL_AUTOWAH_MIN_RELEASE_TIME,
|
|
|
|
AL_AUTOWAH_MAX_RELEASE_TIME);
|
|
|
|
}
|
|
|
|
|
2022-07-14 23:17:11 +08:00
|
|
|
void EaxAutoWahEffect::set_efx_resonance() noexcept
|
2022-04-25 12:02:45 +08:00
|
|
|
{
|
2022-07-14 23:17:11 +08:00
|
|
|
al_effect_props_.Autowah.Resonance = clamp(
|
|
|
|
level_mb_to_gain(static_cast<float>(props_.lResonance)),
|
2022-04-25 12:02:45 +08:00
|
|
|
AL_AUTOWAH_MIN_RESONANCE,
|
|
|
|
AL_AUTOWAH_MAX_RESONANCE);
|
|
|
|
}
|
|
|
|
|
2022-07-14 23:17:11 +08:00
|
|
|
void EaxAutoWahEffect::set_efx_peak_gain() noexcept
|
2022-04-25 12:02:45 +08:00
|
|
|
{
|
2022-07-14 23:17:11 +08:00
|
|
|
al_effect_props_.Autowah.PeakGain = clamp(
|
|
|
|
level_mb_to_gain(static_cast<float>(props_.lPeakLevel)),
|
2022-04-25 12:02:45 +08:00
|
|
|
AL_AUTOWAH_MIN_PEAK_GAIN,
|
|
|
|
AL_AUTOWAH_MAX_PEAK_GAIN);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EaxAutoWahEffect::set_efx_defaults()
|
|
|
|
{
|
|
|
|
set_efx_attack_time();
|
|
|
|
set_efx_release_time();
|
|
|
|
set_efx_resonance();
|
|
|
|
set_efx_peak_gain();
|
|
|
|
}
|
|
|
|
|
2022-07-14 23:17:11 +08:00
|
|
|
void EaxAutoWahEffect::get(const EaxCall& call, const Props& props)
|
2022-04-25 12:02:45 +08:00
|
|
|
{
|
2022-07-14 23:17:11 +08:00
|
|
|
switch (call.get_property_id())
|
2022-04-25 12:02:45 +08:00
|
|
|
{
|
2022-07-14 23:17:11 +08:00
|
|
|
case EAXAUTOWAH_NONE: break;
|
|
|
|
case EAXAUTOWAH_ALLPARAMETERS: call.set_value<Exception>(props); break;
|
|
|
|
case EAXAUTOWAH_ATTACKTIME: call.set_value<Exception>(props.flAttackTime); break;
|
|
|
|
case EAXAUTOWAH_RELEASETIME: call.set_value<Exception>(props.flReleaseTime); break;
|
|
|
|
case EAXAUTOWAH_RESONANCE: call.set_value<Exception>(props.lResonance); break;
|
|
|
|
case EAXAUTOWAH_PEAKLEVEL: call.set_value<Exception>(props.lPeakLevel); break;
|
|
|
|
default: fail_unknown_property_id();
|
2022-04-25 12:02:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-14 23:17:11 +08:00
|
|
|
void EaxAutoWahEffect::set(const EaxCall& call, Props& props)
|
2022-04-25 12:02:45 +08:00
|
|
|
{
|
2022-07-14 23:17:11 +08:00
|
|
|
switch (call.get_property_id())
|
2022-04-25 12:02:45 +08:00
|
|
|
{
|
2022-07-14 23:17:11 +08:00
|
|
|
case EAXAUTOWAH_NONE: break;
|
|
|
|
case EAXAUTOWAH_ALLPARAMETERS: defer<AllValidator>(call, props); break;
|
|
|
|
case EAXAUTOWAH_ATTACKTIME: defer<AttackTimeValidator>(call, props.flAttackTime); break;
|
|
|
|
case EAXAUTOWAH_RELEASETIME: defer<ReleaseTimeValidator>(call, props.flReleaseTime); break;
|
|
|
|
case EAXAUTOWAH_RESONANCE: defer<ResonanceValidator>(call, props.lResonance); break;
|
|
|
|
case EAXAUTOWAH_PEAKLEVEL: defer<PeakLevelValidator>(call, props.lPeakLevel); break;
|
|
|
|
default: fail_unknown_property_id();
|
2022-04-25 12:02:45 +08:00
|
|
|
}
|
2022-07-14 23:17:11 +08:00
|
|
|
}
|
2022-04-25 12:02:45 +08:00
|
|
|
|
2022-07-14 23:17:11 +08:00
|
|
|
bool EaxAutoWahEffect::commit_props(const Props& props)
|
|
|
|
{
|
|
|
|
auto is_dirty = false;
|
2022-04-25 12:02:45 +08:00
|
|
|
|
2022-07-14 23:17:11 +08:00
|
|
|
if (props_.flAttackTime != props.flAttackTime)
|
2022-04-25 12:02:45 +08:00
|
|
|
{
|
2022-07-14 23:17:11 +08:00
|
|
|
is_dirty = true;
|
2022-04-25 12:02:45 +08:00
|
|
|
set_efx_attack_time();
|
|
|
|
}
|
|
|
|
|
2022-07-14 23:17:11 +08:00
|
|
|
if (props_.flReleaseTime != props.flReleaseTime)
|
2022-04-25 12:02:45 +08:00
|
|
|
{
|
2022-07-14 23:17:11 +08:00
|
|
|
is_dirty = true;
|
2022-04-25 12:02:45 +08:00
|
|
|
set_efx_release_time();
|
|
|
|
}
|
|
|
|
|
2022-07-14 23:17:11 +08:00
|
|
|
if (props_.lResonance != props.lResonance)
|
2022-04-25 12:02:45 +08:00
|
|
|
{
|
2022-07-14 23:17:11 +08:00
|
|
|
is_dirty = true;
|
2022-04-25 12:02:45 +08:00
|
|
|
set_efx_resonance();
|
|
|
|
}
|
|
|
|
|
2022-07-14 23:17:11 +08:00
|
|
|
if (props_.lPeakLevel != props.lPeakLevel)
|
2022-04-25 12:02:45 +08:00
|
|
|
{
|
2022-07-14 23:17:11 +08:00
|
|
|
is_dirty = true;
|
2022-04-25 12:02:45 +08:00
|
|
|
set_efx_peak_gain();
|
|
|
|
}
|
|
|
|
|
2022-07-14 23:17:11 +08:00
|
|
|
return is_dirty;
|
2022-04-25 12:02:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2023-02-04 15:03:54 +08:00
|
|
|
EaxEffectUPtr eax_create_eax_auto_wah_effect(int eax_version)
|
2022-04-25 12:02:45 +08:00
|
|
|
{
|
2023-02-04 15:03:54 +08:00
|
|
|
return eax_create_eax4_effect<EaxAutoWahEffect>(eax_version);
|
2022-04-25 12:02:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // ALSOFT_EAX
|