mirror of
https://github.com/love2d/megasource.git
synced 2026-08-19 04:05:09 +02:00
Update OpenAL-soft to 1.23.1-bc7cb17.
This commit is contained in:
@@ -13,536 +13,228 @@
|
||||
|
||||
#ifdef ALSOFT_EAX
|
||||
#include "alnumeric.h"
|
||||
|
||||
#include "al/eax_exception.h"
|
||||
#include "al/eax_utils.h"
|
||||
#include "al/eax/effect.h"
|
||||
#include "al/eax/exception.h"
|
||||
#include "al/eax/utils.h"
|
||||
#endif // ALSOFT_EAX
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
void Autowah_setParamf(EffectProps *props, ALenum param, float val)
|
||||
constexpr EffectProps genDefaultProps() noexcept
|
||||
{
|
||||
AutowahProps props{};
|
||||
props.AttackTime = AL_AUTOWAH_DEFAULT_ATTACK_TIME;
|
||||
props.ReleaseTime = AL_AUTOWAH_DEFAULT_RELEASE_TIME;
|
||||
props.Resonance = AL_AUTOWAH_DEFAULT_RESONANCE;
|
||||
props.PeakGain = AL_AUTOWAH_DEFAULT_PEAK_GAIN;
|
||||
return props;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
const EffectProps AutowahEffectProps{genDefaultProps()};
|
||||
|
||||
void EffectHandler::SetParami(AutowahProps&, ALenum param, int)
|
||||
{ throw effect_exception{AL_INVALID_ENUM, "Invalid autowah integer property 0x%04x", param}; }
|
||||
void EffectHandler::SetParamiv(AutowahProps&, ALenum param, const int*)
|
||||
{
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid autowah integer vector property 0x%04x",
|
||||
param};
|
||||
}
|
||||
|
||||
void EffectHandler::SetParamf(AutowahProps &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;
|
||||
props.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;
|
||||
props.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;
|
||||
props.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;
|
||||
props.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 EffectHandler::SetParamfv(AutowahProps &props, ALenum param, const float *vals)
|
||||
{ SetParamf(props, param, *vals); }
|
||||
|
||||
void Autowah_setParami(EffectProps*, ALenum param, int)
|
||||
void EffectHandler::GetParami(const AutowahProps&, ALenum param, int*)
|
||||
{ throw effect_exception{AL_INVALID_ENUM, "Invalid autowah integer property 0x%04x", param}; }
|
||||
void Autowah_setParamiv(EffectProps*, ALenum param, const int*)
|
||||
void EffectHandler::GetParamiv(const AutowahProps&, ALenum param, 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)
|
||||
void EffectHandler::GetParamf(const AutowahProps &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;
|
||||
case AL_AUTOWAH_ATTACK_TIME: *val = props.AttackTime; break;
|
||||
case AL_AUTOWAH_RELEASE_TIME: *val = props.ReleaseTime; break;
|
||||
case AL_AUTOWAH_RESONANCE: *val = props.Resonance; break;
|
||||
case AL_AUTOWAH_PEAK_GAIN: *val = props.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()};
|
||||
void EffectHandler::GetParamfv(const AutowahProps &props, ALenum param, float *vals)
|
||||
{ GetParamf(props, param, vals); }
|
||||
|
||||
#ifdef ALSOFT_EAX
|
||||
namespace {
|
||||
|
||||
using EaxAutoWahEffectDirtyFlagsValue = std::uint_least8_t;
|
||||
using AutowahCommitter = EaxCommitter<EaxAutowahCommitter>;
|
||||
|
||||
struct EaxAutoWahEffectDirtyFlags
|
||||
{
|
||||
using EaxIsBitFieldStruct = bool;
|
||||
|
||||
EaxAutoWahEffectDirtyFlagsValue flAttackTime : 1;
|
||||
EaxAutoWahEffectDirtyFlagsValue flReleaseTime : 1;
|
||||
EaxAutoWahEffectDirtyFlagsValue lResonance : 1;
|
||||
EaxAutoWahEffectDirtyFlagsValue lPeakLevel : 1;
|
||||
}; // EaxAutoWahEffectDirtyFlags
|
||||
|
||||
|
||||
class EaxAutoWahEffect final :
|
||||
public EaxEffect
|
||||
{
|
||||
public:
|
||||
EaxAutoWahEffect();
|
||||
|
||||
|
||||
void dispatch(const EaxEaxCall& eax_call) override;
|
||||
|
||||
// [[nodiscard]]
|
||||
bool apply_deferred() override;
|
||||
|
||||
private:
|
||||
EAXAUTOWAHPROPERTIES eax_{};
|
||||
EAXAUTOWAHPROPERTIES eax_d_{};
|
||||
EaxAutoWahEffectDirtyFlags eax_dirty_flags_{};
|
||||
|
||||
|
||||
void set_eax_defaults();
|
||||
|
||||
|
||||
void set_efx_attack_time();
|
||||
|
||||
void set_efx_release_time();
|
||||
|
||||
void set_efx_resonance();
|
||||
|
||||
void set_efx_peak_gain();
|
||||
|
||||
void set_efx_defaults();
|
||||
|
||||
|
||||
void get(const EaxEaxCall& eax_call);
|
||||
|
||||
|
||||
void validate_attack_time(
|
||||
float flAttackTime);
|
||||
|
||||
void validate_release_time(
|
||||
float flReleaseTime);
|
||||
|
||||
void validate_resonance(
|
||||
long lResonance);
|
||||
|
||||
void validate_peak_level(
|
||||
long lPeakLevel);
|
||||
|
||||
void validate_all(
|
||||
const EAXAUTOWAHPROPERTIES& eax_all);
|
||||
|
||||
|
||||
void defer_attack_time(
|
||||
float flAttackTime);
|
||||
|
||||
void defer_release_time(
|
||||
float flReleaseTime);
|
||||
|
||||
void defer_resonance(
|
||||
long lResonance);
|
||||
|
||||
void defer_peak_level(
|
||||
long lPeakLevel);
|
||||
|
||||
void defer_all(
|
||||
const EAXAUTOWAHPROPERTIES& eax_all);
|
||||
|
||||
|
||||
void defer_attack_time(
|
||||
const EaxEaxCall& eax_call);
|
||||
|
||||
void defer_release_time(
|
||||
const EaxEaxCall& eax_call);
|
||||
|
||||
void defer_resonance(
|
||||
const EaxEaxCall& eax_call);
|
||||
|
||||
void defer_peak_level(
|
||||
const EaxEaxCall& eax_call);
|
||||
|
||||
void defer_all(
|
||||
const EaxEaxCall& eax_call);
|
||||
|
||||
void set(const EaxEaxCall& eax_call);
|
||||
}; // EaxAutoWahEffect
|
||||
|
||||
|
||||
class EaxAutoWahEffectException :
|
||||
public EaxException
|
||||
{
|
||||
public:
|
||||
explicit EaxAutoWahEffectException(
|
||||
const char* message)
|
||||
:
|
||||
EaxException{"EAX_AUTO_WAH_EFFECT", message}
|
||||
struct AttackTimeValidator {
|
||||
void operator()(float flAttackTime) const
|
||||
{
|
||||
eax_validate_range<AutowahCommitter::Exception>(
|
||||
"Attack Time",
|
||||
flAttackTime,
|
||||
EAXAUTOWAH_MINATTACKTIME,
|
||||
EAXAUTOWAH_MAXATTACKTIME);
|
||||
}
|
||||
}; // EaxAutoWahEffectException
|
||||
}; // AttackTimeValidator
|
||||
|
||||
|
||||
EaxAutoWahEffect::EaxAutoWahEffect()
|
||||
: EaxEffect{AL_EFFECT_AUTOWAH}
|
||||
{
|
||||
set_eax_defaults();
|
||||
set_efx_defaults();
|
||||
}
|
||||
|
||||
void EaxAutoWahEffect::dispatch(const EaxEaxCall& eax_call)
|
||||
{
|
||||
eax_call.is_get() ? get(eax_call) : set(eax_call);
|
||||
}
|
||||
|
||||
void EaxAutoWahEffect::set_eax_defaults()
|
||||
{
|
||||
eax_.flAttackTime = EAXAUTOWAH_DEFAULTATTACKTIME;
|
||||
eax_.flReleaseTime = EAXAUTOWAH_DEFAULTRELEASETIME;
|
||||
eax_.lResonance = EAXAUTOWAH_DEFAULTRESONANCE;
|
||||
eax_.lPeakLevel = EAXAUTOWAH_DEFAULTPEAKLEVEL;
|
||||
|
||||
eax_d_ = eax_;
|
||||
}
|
||||
|
||||
void EaxAutoWahEffect::set_efx_attack_time()
|
||||
{
|
||||
const auto attack_time = clamp(
|
||||
eax_.flAttackTime,
|
||||
AL_AUTOWAH_MIN_ATTACK_TIME,
|
||||
AL_AUTOWAH_MAX_ATTACK_TIME);
|
||||
|
||||
al_effect_props_.Autowah.AttackTime = attack_time;
|
||||
}
|
||||
|
||||
void EaxAutoWahEffect::set_efx_release_time()
|
||||
{
|
||||
const auto release_time = clamp(
|
||||
eax_.flReleaseTime,
|
||||
AL_AUTOWAH_MIN_RELEASE_TIME,
|
||||
AL_AUTOWAH_MAX_RELEASE_TIME);
|
||||
|
||||
al_effect_props_.Autowah.ReleaseTime = release_time;
|
||||
}
|
||||
|
||||
void EaxAutoWahEffect::set_efx_resonance()
|
||||
{
|
||||
const auto resonance = clamp(
|
||||
level_mb_to_gain(static_cast<float>(eax_.lResonance)),
|
||||
AL_AUTOWAH_MIN_RESONANCE,
|
||||
AL_AUTOWAH_MAX_RESONANCE);
|
||||
|
||||
al_effect_props_.Autowah.Resonance = resonance;
|
||||
}
|
||||
|
||||
void EaxAutoWahEffect::set_efx_peak_gain()
|
||||
{
|
||||
const auto peak_gain = clamp(
|
||||
level_mb_to_gain(static_cast<float>(eax_.lPeakLevel)),
|
||||
AL_AUTOWAH_MIN_PEAK_GAIN,
|
||||
AL_AUTOWAH_MAX_PEAK_GAIN);
|
||||
|
||||
al_effect_props_.Autowah.PeakGain = peak_gain;
|
||||
}
|
||||
|
||||
void EaxAutoWahEffect::set_efx_defaults()
|
||||
{
|
||||
set_efx_attack_time();
|
||||
set_efx_release_time();
|
||||
set_efx_resonance();
|
||||
set_efx_peak_gain();
|
||||
}
|
||||
|
||||
void EaxAutoWahEffect::get(const EaxEaxCall& eax_call)
|
||||
{
|
||||
switch (eax_call.get_property_id())
|
||||
struct ReleaseTimeValidator {
|
||||
void operator()(float flReleaseTime) const
|
||||
{
|
||||
case EAXAUTOWAH_NONE:
|
||||
break;
|
||||
|
||||
case EAXAUTOWAH_ALLPARAMETERS:
|
||||
eax_call.set_value<EaxAutoWahEffectException>(eax_);
|
||||
break;
|
||||
|
||||
case EAXAUTOWAH_ATTACKTIME:
|
||||
eax_call.set_value<EaxAutoWahEffectException>(eax_.flAttackTime);
|
||||
break;
|
||||
|
||||
case EAXAUTOWAH_RELEASETIME:
|
||||
eax_call.set_value<EaxAutoWahEffectException>(eax_.flReleaseTime);
|
||||
break;
|
||||
|
||||
case EAXAUTOWAH_RESONANCE:
|
||||
eax_call.set_value<EaxAutoWahEffectException>(eax_.lResonance);
|
||||
break;
|
||||
|
||||
case EAXAUTOWAH_PEAKLEVEL:
|
||||
eax_call.set_value<EaxAutoWahEffectException>(eax_.lPeakLevel);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw EaxAutoWahEffectException{"Unsupported property id."};
|
||||
eax_validate_range<AutowahCommitter::Exception>(
|
||||
"Release Time",
|
||||
flReleaseTime,
|
||||
EAXAUTOWAH_MINRELEASETIME,
|
||||
EAXAUTOWAH_MAXRELEASETIME);
|
||||
}
|
||||
}
|
||||
}; // ReleaseTimeValidator
|
||||
|
||||
void EaxAutoWahEffect::validate_attack_time(
|
||||
float flAttackTime)
|
||||
{
|
||||
eax_validate_range<EaxAutoWahEffectException>(
|
||||
"Attack Time",
|
||||
flAttackTime,
|
||||
EAXAUTOWAH_MINATTACKTIME,
|
||||
EAXAUTOWAH_MAXATTACKTIME);
|
||||
}
|
||||
|
||||
void EaxAutoWahEffect::validate_release_time(
|
||||
float flReleaseTime)
|
||||
{
|
||||
eax_validate_range<EaxAutoWahEffectException>(
|
||||
"Release Time",
|
||||
flReleaseTime,
|
||||
EAXAUTOWAH_MINRELEASETIME,
|
||||
EAXAUTOWAH_MAXRELEASETIME);
|
||||
}
|
||||
|
||||
void EaxAutoWahEffect::validate_resonance(
|
||||
long lResonance)
|
||||
{
|
||||
eax_validate_range<EaxAutoWahEffectException>(
|
||||
"Resonance",
|
||||
lResonance,
|
||||
EAXAUTOWAH_MINRESONANCE,
|
||||
EAXAUTOWAH_MAXRESONANCE);
|
||||
}
|
||||
|
||||
void EaxAutoWahEffect::validate_peak_level(
|
||||
long lPeakLevel)
|
||||
{
|
||||
eax_validate_range<EaxAutoWahEffectException>(
|
||||
"Peak Level",
|
||||
lPeakLevel,
|
||||
EAXAUTOWAH_MINPEAKLEVEL,
|
||||
EAXAUTOWAH_MAXPEAKLEVEL);
|
||||
}
|
||||
|
||||
void EaxAutoWahEffect::validate_all(
|
||||
const EAXAUTOWAHPROPERTIES& eax_all)
|
||||
{
|
||||
validate_attack_time(eax_all.flAttackTime);
|
||||
validate_release_time(eax_all.flReleaseTime);
|
||||
validate_resonance(eax_all.lResonance);
|
||||
validate_peak_level(eax_all.lPeakLevel);
|
||||
}
|
||||
|
||||
void EaxAutoWahEffect::defer_attack_time(
|
||||
float flAttackTime)
|
||||
{
|
||||
eax_d_.flAttackTime = flAttackTime;
|
||||
eax_dirty_flags_.flAttackTime = (eax_.flAttackTime != eax_d_.flAttackTime);
|
||||
}
|
||||
|
||||
void EaxAutoWahEffect::defer_release_time(
|
||||
float flReleaseTime)
|
||||
{
|
||||
eax_d_.flReleaseTime = flReleaseTime;
|
||||
eax_dirty_flags_.flReleaseTime = (eax_.flReleaseTime != eax_d_.flReleaseTime);
|
||||
}
|
||||
|
||||
void EaxAutoWahEffect::defer_resonance(
|
||||
long lResonance)
|
||||
{
|
||||
eax_d_.lResonance = lResonance;
|
||||
eax_dirty_flags_.lResonance = (eax_.lResonance != eax_d_.lResonance);
|
||||
}
|
||||
|
||||
void EaxAutoWahEffect::defer_peak_level(
|
||||
long lPeakLevel)
|
||||
{
|
||||
eax_d_.lPeakLevel = lPeakLevel;
|
||||
eax_dirty_flags_.lPeakLevel = (eax_.lPeakLevel != eax_d_.lPeakLevel);
|
||||
}
|
||||
|
||||
void EaxAutoWahEffect::defer_all(
|
||||
const EAXAUTOWAHPROPERTIES& eax_all)
|
||||
{
|
||||
validate_all(eax_all);
|
||||
|
||||
defer_attack_time(eax_all.flAttackTime);
|
||||
defer_release_time(eax_all.flReleaseTime);
|
||||
defer_resonance(eax_all.lResonance);
|
||||
defer_peak_level(eax_all.lPeakLevel);
|
||||
}
|
||||
|
||||
void EaxAutoWahEffect::defer_attack_time(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& attack_time =
|
||||
eax_call.get_value<EaxAutoWahEffectException, const decltype(EAXAUTOWAHPROPERTIES::flAttackTime)>();
|
||||
|
||||
validate_attack_time(attack_time);
|
||||
defer_attack_time(attack_time);
|
||||
}
|
||||
|
||||
void EaxAutoWahEffect::defer_release_time(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& release_time =
|
||||
eax_call.get_value<EaxAutoWahEffectException, const decltype(EAXAUTOWAHPROPERTIES::flReleaseTime)>();
|
||||
|
||||
validate_release_time(release_time);
|
||||
defer_release_time(release_time);
|
||||
}
|
||||
|
||||
void EaxAutoWahEffect::defer_resonance(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& resonance =
|
||||
eax_call.get_value<EaxAutoWahEffectException, const decltype(EAXAUTOWAHPROPERTIES::lResonance)>();
|
||||
|
||||
validate_resonance(resonance);
|
||||
defer_resonance(resonance);
|
||||
}
|
||||
|
||||
void EaxAutoWahEffect::defer_peak_level(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& peak_level =
|
||||
eax_call.get_value<EaxAutoWahEffectException, const decltype(EAXAUTOWAHPROPERTIES::lPeakLevel)>();
|
||||
|
||||
validate_peak_level(peak_level);
|
||||
defer_peak_level(peak_level);
|
||||
}
|
||||
|
||||
void EaxAutoWahEffect::defer_all(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& all =
|
||||
eax_call.get_value<EaxAutoWahEffectException, const EAXAUTOWAHPROPERTIES>();
|
||||
|
||||
validate_all(all);
|
||||
defer_all(all);
|
||||
}
|
||||
|
||||
// [[nodiscard]]
|
||||
bool EaxAutoWahEffect::apply_deferred()
|
||||
{
|
||||
if (eax_dirty_flags_ == EaxAutoWahEffectDirtyFlags{})
|
||||
struct ResonanceValidator {
|
||||
void operator()(long lResonance) const
|
||||
{
|
||||
eax_validate_range<AutowahCommitter::Exception>(
|
||||
"Resonance",
|
||||
lResonance,
|
||||
EAXAUTOWAH_MINRESONANCE,
|
||||
EAXAUTOWAH_MAXRESONANCE);
|
||||
}
|
||||
}; // ResonanceValidator
|
||||
|
||||
struct PeakLevelValidator {
|
||||
void operator()(long lPeakLevel) const
|
||||
{
|
||||
eax_validate_range<AutowahCommitter::Exception>(
|
||||
"Peak Level",
|
||||
lPeakLevel,
|
||||
EAXAUTOWAH_MINPEAKLEVEL,
|
||||
EAXAUTOWAH_MAXPEAKLEVEL);
|
||||
}
|
||||
}; // PeakLevelValidator
|
||||
|
||||
struct AllValidator {
|
||||
void operator()(const EAXAUTOWAHPROPERTIES& all) const
|
||||
{
|
||||
AttackTimeValidator{}(all.flAttackTime);
|
||||
ReleaseTimeValidator{}(all.flReleaseTime);
|
||||
ResonanceValidator{}(all.lResonance);
|
||||
PeakLevelValidator{}(all.lPeakLevel);
|
||||
}
|
||||
}; // AllValidator
|
||||
|
||||
} // namespace
|
||||
|
||||
template<>
|
||||
struct AutowahCommitter::Exception : public EaxException
|
||||
{
|
||||
explicit Exception(const char *message) : EaxException{"EAX_AUTOWAH_EFFECT", message}
|
||||
{ }
|
||||
};
|
||||
|
||||
template<>
|
||||
[[noreturn]] void AutowahCommitter::fail(const char *message)
|
||||
{
|
||||
throw Exception{message};
|
||||
}
|
||||
|
||||
bool EaxAutowahCommitter::commit(const EAXAUTOWAHPROPERTIES &props)
|
||||
{
|
||||
if(auto *cur = std::get_if<EAXAUTOWAHPROPERTIES>(&mEaxProps); cur && *cur == props)
|
||||
return false;
|
||||
}
|
||||
|
||||
eax_ = eax_d_;
|
||||
|
||||
if (eax_dirty_flags_.flAttackTime)
|
||||
{
|
||||
set_efx_attack_time();
|
||||
}
|
||||
|
||||
if (eax_dirty_flags_.flReleaseTime)
|
||||
{
|
||||
set_efx_release_time();
|
||||
}
|
||||
|
||||
if (eax_dirty_flags_.lResonance)
|
||||
{
|
||||
set_efx_resonance();
|
||||
}
|
||||
|
||||
if (eax_dirty_flags_.lPeakLevel)
|
||||
{
|
||||
set_efx_peak_gain();
|
||||
}
|
||||
|
||||
eax_dirty_flags_ = EaxAutoWahEffectDirtyFlags{};
|
||||
mEaxProps = props;
|
||||
mAlProps = [&]{
|
||||
AutowahProps ret{};
|
||||
ret.AttackTime = props.flAttackTime;
|
||||
ret.ReleaseTime = props.flReleaseTime;
|
||||
ret.Resonance = level_mb_to_gain(static_cast<float>(props.lResonance));
|
||||
ret.PeakGain = level_mb_to_gain(static_cast<float>(props.lPeakLevel));
|
||||
return ret;
|
||||
}();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void EaxAutoWahEffect::set(const EaxEaxCall& eax_call)
|
||||
void EaxAutowahCommitter::SetDefaults(EaxEffectProps &props)
|
||||
{
|
||||
switch (eax_call.get_property_id())
|
||||
static constexpr EAXAUTOWAHPROPERTIES defprops{[]
|
||||
{
|
||||
case EAXAUTOWAH_NONE:
|
||||
break;
|
||||
EAXAUTOWAHPROPERTIES ret{};
|
||||
ret.flAttackTime = EAXAUTOWAH_DEFAULTATTACKTIME;
|
||||
ret.flReleaseTime = EAXAUTOWAH_DEFAULTRELEASETIME;
|
||||
ret.lResonance = EAXAUTOWAH_DEFAULTRESONANCE;
|
||||
ret.lPeakLevel = EAXAUTOWAH_DEFAULTPEAKLEVEL;
|
||||
return ret;
|
||||
}()};
|
||||
props = defprops;
|
||||
}
|
||||
|
||||
case EAXAUTOWAH_ALLPARAMETERS:
|
||||
defer_all(eax_call);
|
||||
break;
|
||||
|
||||
case EAXAUTOWAH_ATTACKTIME:
|
||||
defer_attack_time(eax_call);
|
||||
break;
|
||||
|
||||
case EAXAUTOWAH_RELEASETIME:
|
||||
defer_release_time(eax_call);
|
||||
break;
|
||||
|
||||
case EAXAUTOWAH_RESONANCE:
|
||||
defer_resonance(eax_call);
|
||||
break;
|
||||
|
||||
case EAXAUTOWAH_PEAKLEVEL:
|
||||
defer_peak_level(eax_call);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw EaxAutoWahEffectException{"Unsupported property id."};
|
||||
void EaxAutowahCommitter::Get(const EaxCall &call, const EAXAUTOWAHPROPERTIES &props)
|
||||
{
|
||||
switch(call.get_property_id())
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
EaxEffectUPtr eax_create_eax_auto_wah_effect()
|
||||
void EaxAutowahCommitter::Set(const EaxCall &call, EAXAUTOWAHPROPERTIES &props)
|
||||
{
|
||||
return std::make_unique<::EaxAutoWahEffect>();
|
||||
switch(call.get_property_id())
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
#endif // ALSOFT_EAX
|
||||
|
||||
+406
-1111
File diff suppressed because it is too large
Load Diff
@@ -9,22 +9,33 @@
|
||||
|
||||
#ifdef ALSOFT_EAX
|
||||
#include "alnumeric.h"
|
||||
|
||||
#include "al/eax_exception.h"
|
||||
#include "al/eax_utils.h"
|
||||
#include "al/eax/effect.h"
|
||||
#include "al/eax/exception.h"
|
||||
#include "al/eax/utils.h"
|
||||
#endif // ALSOFT_EAX
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
void Compressor_setParami(EffectProps *props, ALenum param, int val)
|
||||
constexpr EffectProps genDefaultProps() noexcept
|
||||
{
|
||||
CompressorProps props{};
|
||||
props.OnOff = AL_COMPRESSOR_DEFAULT_ONOFF;
|
||||
return props;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
const EffectProps CompressorEffectProps{genDefaultProps()};
|
||||
|
||||
void EffectHandler::SetParami(CompressorProps &props, ALenum param, int val)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case AL_COMPRESSOR_ONOFF:
|
||||
if(!(val >= AL_COMPRESSOR_MIN_ONOFF && val <= AL_COMPRESSOR_MAX_ONOFF))
|
||||
throw effect_exception{AL_INVALID_VALUE, "Compressor state out of range"};
|
||||
props->Compressor.OnOff = (val != AL_FALSE);
|
||||
props.OnOff = (val != AL_FALSE);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -32,22 +43,22 @@ void Compressor_setParami(EffectProps *props, ALenum param, int val)
|
||||
param};
|
||||
}
|
||||
}
|
||||
void Compressor_setParamiv(EffectProps *props, ALenum param, const int *vals)
|
||||
{ Compressor_setParami(props, param, vals[0]); }
|
||||
void Compressor_setParamf(EffectProps*, ALenum param, float)
|
||||
void EffectHandler::SetParamiv(CompressorProps &props, ALenum param, const int *vals)
|
||||
{ SetParami(props, param, *vals); }
|
||||
void EffectHandler::SetParamf(CompressorProps&, ALenum param, float)
|
||||
{ throw effect_exception{AL_INVALID_ENUM, "Invalid compressor float property 0x%04x", param}; }
|
||||
void Compressor_setParamfv(EffectProps*, ALenum param, const float*)
|
||||
void EffectHandler::SetParamfv(CompressorProps&, ALenum param, const float*)
|
||||
{
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid compressor float-vector property 0x%04x",
|
||||
param};
|
||||
}
|
||||
|
||||
void Compressor_getParami(const EffectProps *props, ALenum param, int *val)
|
||||
void EffectHandler::GetParami(const CompressorProps &props, ALenum param, int *val)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case AL_COMPRESSOR_ONOFF:
|
||||
*val = props->Compressor.OnOff;
|
||||
*val = props.OnOff;
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -55,242 +66,91 @@ void Compressor_getParami(const EffectProps *props, ALenum param, int *val)
|
||||
param};
|
||||
}
|
||||
}
|
||||
void Compressor_getParamiv(const EffectProps *props, ALenum param, int *vals)
|
||||
{ Compressor_getParami(props, param, vals); }
|
||||
void Compressor_getParamf(const EffectProps*, ALenum param, float*)
|
||||
void EffectHandler::GetParamiv(const CompressorProps &props, ALenum param, int *vals)
|
||||
{ GetParami(props, param, vals); }
|
||||
void EffectHandler::GetParamf(const CompressorProps&, ALenum param, float*)
|
||||
{ throw effect_exception{AL_INVALID_ENUM, "Invalid compressor float property 0x%04x", param}; }
|
||||
void Compressor_getParamfv(const EffectProps*, ALenum param, float*)
|
||||
void EffectHandler::GetParamfv(const CompressorProps&, ALenum param, float*)
|
||||
{
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid compressor float-vector property 0x%04x",
|
||||
param};
|
||||
}
|
||||
|
||||
EffectProps genDefaultProps() noexcept
|
||||
{
|
||||
EffectProps props{};
|
||||
props.Compressor.OnOff = AL_COMPRESSOR_DEFAULT_ONOFF;
|
||||
return props;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
DEFINE_ALEFFECT_VTABLE(Compressor);
|
||||
|
||||
const EffectProps CompressorEffectProps{genDefaultProps()};
|
||||
|
||||
#ifdef ALSOFT_EAX
|
||||
namespace {
|
||||
|
||||
using EaxCompressorEffectDirtyFlagsValue = std::uint_least8_t;
|
||||
using CompressorCommitter = EaxCommitter<EaxCompressorCommitter>;
|
||||
|
||||
struct EaxCompressorEffectDirtyFlags
|
||||
{
|
||||
using EaxIsBitFieldStruct = bool;
|
||||
|
||||
EaxCompressorEffectDirtyFlagsValue ulOnOff : 1;
|
||||
}; // EaxCompressorEffectDirtyFlags
|
||||
|
||||
|
||||
class EaxCompressorEffect final :
|
||||
public EaxEffect
|
||||
{
|
||||
public:
|
||||
EaxCompressorEffect();
|
||||
|
||||
|
||||
void dispatch(const EaxEaxCall& eax_call) override;
|
||||
|
||||
// [[nodiscard]]
|
||||
bool apply_deferred() override;
|
||||
|
||||
private:
|
||||
EAXAGCCOMPRESSORPROPERTIES eax_{};
|
||||
EAXAGCCOMPRESSORPROPERTIES eax_d_{};
|
||||
EaxCompressorEffectDirtyFlags eax_dirty_flags_{};
|
||||
|
||||
|
||||
void set_eax_defaults();
|
||||
|
||||
void set_efx_on_off();
|
||||
void set_efx_defaults();
|
||||
|
||||
void get(const EaxEaxCall& eax_call);
|
||||
|
||||
void validate_on_off(unsigned long ulOnOff);
|
||||
void validate_all(const EAXAGCCOMPRESSORPROPERTIES& eax_all);
|
||||
|
||||
void defer_on_off(unsigned long ulOnOff);
|
||||
void defer_all(const EAXAGCCOMPRESSORPROPERTIES& eax_all);
|
||||
|
||||
void defer_on_off(const EaxEaxCall& eax_call);
|
||||
void defer_all(const EaxEaxCall& eax_call);
|
||||
|
||||
void set(const EaxEaxCall& eax_call);
|
||||
}; // EaxCompressorEffect
|
||||
|
||||
|
||||
class EaxCompressorEffectException :
|
||||
public EaxException
|
||||
{
|
||||
public:
|
||||
explicit EaxCompressorEffectException(
|
||||
const char* message)
|
||||
:
|
||||
EaxException{"EAX_COMPRESSOR_EFFECT", message}
|
||||
struct OnOffValidator {
|
||||
void operator()(unsigned long ulOnOff) const
|
||||
{
|
||||
eax_validate_range<CompressorCommitter::Exception>(
|
||||
"On-Off",
|
||||
ulOnOff,
|
||||
EAXAGCCOMPRESSOR_MINONOFF,
|
||||
EAXAGCCOMPRESSOR_MAXONOFF);
|
||||
}
|
||||
}; // EaxCompressorEffectException
|
||||
}; // OnOffValidator
|
||||
|
||||
|
||||
EaxCompressorEffect::EaxCompressorEffect()
|
||||
: EaxEffect{AL_EFFECT_COMPRESSOR}
|
||||
{
|
||||
set_eax_defaults();
|
||||
set_efx_defaults();
|
||||
}
|
||||
|
||||
// [[nodiscard]]
|
||||
void EaxCompressorEffect::dispatch(const EaxEaxCall& eax_call)
|
||||
{
|
||||
eax_call.is_get() ? get(eax_call) : set(eax_call);
|
||||
}
|
||||
|
||||
void EaxCompressorEffect::set_eax_defaults()
|
||||
{
|
||||
eax_.ulOnOff = EAXAGCCOMPRESSOR_DEFAULTONOFF;
|
||||
|
||||
eax_d_ = eax_;
|
||||
}
|
||||
|
||||
void EaxCompressorEffect::set_efx_on_off()
|
||||
{
|
||||
const auto on_off = clamp(
|
||||
static_cast<ALint>(eax_.ulOnOff),
|
||||
AL_COMPRESSOR_MIN_ONOFF,
|
||||
AL_COMPRESSOR_MAX_ONOFF);
|
||||
|
||||
al_effect_props_.Compressor.OnOff = (on_off != AL_FALSE);
|
||||
}
|
||||
|
||||
void EaxCompressorEffect::set_efx_defaults()
|
||||
{
|
||||
set_efx_on_off();
|
||||
}
|
||||
|
||||
void EaxCompressorEffect::get(const EaxEaxCall& eax_call)
|
||||
{
|
||||
switch(eax_call.get_property_id())
|
||||
struct AllValidator {
|
||||
void operator()(const EAXAGCCOMPRESSORPROPERTIES& all) const
|
||||
{
|
||||
case EAXAGCCOMPRESSOR_NONE:
|
||||
break;
|
||||
|
||||
case EAXAGCCOMPRESSOR_ALLPARAMETERS:
|
||||
eax_call.set_value<EaxCompressorEffectException>(eax_);
|
||||
break;
|
||||
|
||||
case EAXAGCCOMPRESSOR_ONOFF:
|
||||
eax_call.set_value<EaxCompressorEffectException>(eax_.ulOnOff);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw EaxCompressorEffectException{"Unsupported property id."};
|
||||
OnOffValidator{}(all.ulOnOff);
|
||||
}
|
||||
}; // AllValidator
|
||||
|
||||
} // namespace
|
||||
|
||||
template<>
|
||||
struct CompressorCommitter::Exception : public EaxException
|
||||
{
|
||||
explicit Exception(const char *message) : EaxException{"EAX_CHORUS_EFFECT", message}
|
||||
{ }
|
||||
};
|
||||
|
||||
template<>
|
||||
[[noreturn]] void CompressorCommitter::fail(const char *message)
|
||||
{
|
||||
throw Exception{message};
|
||||
}
|
||||
|
||||
void EaxCompressorEffect::validate_on_off(
|
||||
unsigned long ulOnOff)
|
||||
bool EaxCompressorCommitter::commit(const EAXAGCCOMPRESSORPROPERTIES &props)
|
||||
{
|
||||
eax_validate_range<EaxCompressorEffectException>(
|
||||
"On-Off",
|
||||
ulOnOff,
|
||||
EAXAGCCOMPRESSOR_MINONOFF,
|
||||
EAXAGCCOMPRESSOR_MAXONOFF);
|
||||
}
|
||||
|
||||
void EaxCompressorEffect::validate_all(
|
||||
const EAXAGCCOMPRESSORPROPERTIES& eax_all)
|
||||
{
|
||||
validate_on_off(eax_all.ulOnOff);
|
||||
}
|
||||
|
||||
void EaxCompressorEffect::defer_on_off(
|
||||
unsigned long ulOnOff)
|
||||
{
|
||||
eax_d_.ulOnOff = ulOnOff;
|
||||
eax_dirty_flags_.ulOnOff = (eax_.ulOnOff != eax_d_.ulOnOff);
|
||||
}
|
||||
|
||||
void EaxCompressorEffect::defer_all(
|
||||
const EAXAGCCOMPRESSORPROPERTIES& eax_all)
|
||||
{
|
||||
defer_on_off(eax_all.ulOnOff);
|
||||
}
|
||||
|
||||
void EaxCompressorEffect::defer_on_off(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& on_off =
|
||||
eax_call.get_value<EaxCompressorEffectException, const decltype(EAXAGCCOMPRESSORPROPERTIES::ulOnOff)>();
|
||||
|
||||
validate_on_off(on_off);
|
||||
defer_on_off(on_off);
|
||||
}
|
||||
|
||||
void EaxCompressorEffect::defer_all(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& all =
|
||||
eax_call.get_value<EaxCompressorEffectException, const EAXAGCCOMPRESSORPROPERTIES>();
|
||||
|
||||
validate_all(all);
|
||||
defer_all(all);
|
||||
}
|
||||
|
||||
// [[nodiscard]]
|
||||
bool EaxCompressorEffect::apply_deferred()
|
||||
{
|
||||
if (eax_dirty_flags_ == EaxCompressorEffectDirtyFlags{})
|
||||
{
|
||||
if(auto *cur = std::get_if<EAXAGCCOMPRESSORPROPERTIES>(&mEaxProps); cur && *cur == props)
|
||||
return false;
|
||||
}
|
||||
|
||||
eax_ = eax_d_;
|
||||
|
||||
if (eax_dirty_flags_.ulOnOff)
|
||||
{
|
||||
set_efx_on_off();
|
||||
}
|
||||
|
||||
eax_dirty_flags_ = EaxCompressorEffectDirtyFlags{};
|
||||
mEaxProps = props;
|
||||
mAlProps = CompressorProps{props.ulOnOff != 0};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void EaxCompressorEffect::set(const EaxEaxCall& eax_call)
|
||||
void EaxCompressorCommitter::SetDefaults(EaxEffectProps &props)
|
||||
{
|
||||
switch(eax_call.get_property_id())
|
||||
props = EAXAGCCOMPRESSORPROPERTIES{EAXAGCCOMPRESSOR_DEFAULTONOFF};
|
||||
}
|
||||
|
||||
void EaxCompressorCommitter::Get(const EaxCall &call, const EAXAGCCOMPRESSORPROPERTIES &props)
|
||||
{
|
||||
switch(call.get_property_id())
|
||||
{
|
||||
case EAXAGCCOMPRESSOR_NONE:
|
||||
break;
|
||||
|
||||
case EAXAGCCOMPRESSOR_ALLPARAMETERS:
|
||||
defer_all(eax_call);
|
||||
break;
|
||||
|
||||
case EAXAGCCOMPRESSOR_ONOFF:
|
||||
defer_on_off(eax_call);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw EaxCompressorEffectException{"Unsupported property id."};
|
||||
case EAXAGCCOMPRESSOR_NONE: break;
|
||||
case EAXAGCCOMPRESSOR_ALLPARAMETERS: call.set_value<Exception>(props); break;
|
||||
case EAXAGCCOMPRESSOR_ONOFF: call.set_value<Exception>(props.ulOnOff); break;
|
||||
default: fail_unknown_property_id();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
EaxEffectUPtr eax_create_eax_compressor_effect()
|
||||
void EaxCompressorCommitter::Set(const EaxCall &call, EAXAGCCOMPRESSORPROPERTIES &props)
|
||||
{
|
||||
return std::make_unique<EaxCompressorEffect>();
|
||||
switch(call.get_property_id())
|
||||
{
|
||||
case EAXAGCCOMPRESSOR_NONE: break;
|
||||
case EAXAGCCOMPRESSOR_ALLPARAMETERS: defer<AllValidator>(call, props); break;
|
||||
case EAXAGCCOMPRESSOR_ONOFF: defer<OnOffValidator>(call, props.ulOnOff); break;
|
||||
default: fail_unknown_property_id();
|
||||
}
|
||||
}
|
||||
|
||||
#endif // ALSOFT_EAX
|
||||
|
||||
@@ -1,93 +1,117 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "AL/al.h"
|
||||
#include "alc/inprogext.h"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
|
||||
#include "alc/effects/base.h"
|
||||
#include "AL/al.h"
|
||||
|
||||
#include "alc/inprogext.h"
|
||||
#include "alnumeric.h"
|
||||
#include "alspan.h"
|
||||
#include "core/effects/base.h"
|
||||
#include "effects.h"
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
void Convolution_setParami(EffectProps* /*props*/, ALenum param, int /*val*/)
|
||||
constexpr EffectProps genDefaultProps() noexcept
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid null effect integer property 0x%04x",
|
||||
param};
|
||||
}
|
||||
}
|
||||
void Convolution_setParamiv(EffectProps *props, ALenum param, const int *vals)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
Convolution_setParami(props, param, vals[0]);
|
||||
}
|
||||
}
|
||||
void Convolution_setParamf(EffectProps* /*props*/, ALenum param, float /*val*/)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid null effect float property 0x%04x",
|
||||
param};
|
||||
}
|
||||
}
|
||||
void Convolution_setParamfv(EffectProps *props, ALenum param, const float *vals)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
Convolution_setParamf(props, param, vals[0]);
|
||||
}
|
||||
}
|
||||
|
||||
void Convolution_getParami(const EffectProps* /*props*/, ALenum param, int* /*val*/)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid null effect integer property 0x%04x",
|
||||
param};
|
||||
}
|
||||
}
|
||||
void Convolution_getParamiv(const EffectProps *props, ALenum param, int *vals)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
Convolution_getParami(props, param, vals);
|
||||
}
|
||||
}
|
||||
void Convolution_getParamf(const EffectProps* /*props*/, ALenum param, float* /*val*/)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid null effect float property 0x%04x",
|
||||
param};
|
||||
}
|
||||
}
|
||||
void Convolution_getParamfv(const EffectProps *props, ALenum param, float *vals)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
Convolution_getParamf(props, param, vals);
|
||||
}
|
||||
}
|
||||
|
||||
EffectProps genDefaultProps() noexcept
|
||||
{
|
||||
EffectProps props{};
|
||||
ConvolutionProps props{};
|
||||
props.OrientAt = {0.0f, 0.0f, -1.0f};
|
||||
props.OrientUp = {0.0f, 1.0f, 0.0f};
|
||||
return props;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
DEFINE_ALEFFECT_VTABLE(Convolution);
|
||||
|
||||
const EffectProps ConvolutionEffectProps{genDefaultProps()};
|
||||
|
||||
void EffectHandler::SetParami(ConvolutionProps& /*props*/, ALenum param, int /*val*/)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid convolution effect integer property 0x%04x",
|
||||
param};
|
||||
}
|
||||
}
|
||||
void EffectHandler::SetParamiv(ConvolutionProps &props, ALenum param, const int *vals)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
SetParami(props, param, *vals);
|
||||
}
|
||||
}
|
||||
void EffectHandler::SetParamf(ConvolutionProps& /*props*/, ALenum param, float /*val*/)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid convolution effect float property 0x%04x",
|
||||
param};
|
||||
}
|
||||
}
|
||||
void EffectHandler::SetParamfv(ConvolutionProps &props, ALenum param, const float *values)
|
||||
{
|
||||
static constexpr auto finite_checker = [](float val) -> bool { return std::isfinite(val); };
|
||||
al::span<const float> vals;
|
||||
switch(param)
|
||||
{
|
||||
case AL_CONVOLUTION_ORIENTATION_SOFT:
|
||||
vals = {values, 6_uz};
|
||||
if(!std::all_of(vals.cbegin(), vals.cend(), finite_checker))
|
||||
throw effect_exception{AL_INVALID_VALUE, "Property 0x%04x value out of range", param};
|
||||
|
||||
std::copy_n(vals.cbegin(), props.OrientAt.size(), props.OrientAt.begin());
|
||||
std::copy_n(vals.cbegin()+3, props.OrientUp.size(), props.OrientUp.begin());
|
||||
break;
|
||||
|
||||
default:
|
||||
SetParamf(props, param, *values);
|
||||
}
|
||||
}
|
||||
|
||||
void EffectHandler::GetParami(const ConvolutionProps& /*props*/, ALenum param, int* /*val*/)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid convolution effect integer property 0x%04x",
|
||||
param};
|
||||
}
|
||||
}
|
||||
void EffectHandler::GetParamiv(const ConvolutionProps &props, ALenum param, int *vals)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
GetParami(props, param, vals);
|
||||
}
|
||||
}
|
||||
void EffectHandler::GetParamf(const ConvolutionProps& /*props*/, ALenum param, float* /*val*/)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid convolution effect float property 0x%04x",
|
||||
param};
|
||||
}
|
||||
}
|
||||
void EffectHandler::GetParamfv(const ConvolutionProps &props, ALenum param, float *values)
|
||||
{
|
||||
al::span<float> vals;
|
||||
switch(param)
|
||||
{
|
||||
case AL_CONVOLUTION_ORIENTATION_SOFT:
|
||||
vals = {values, 6_uz};
|
||||
std::copy(props.OrientAt.cbegin(), props.OrientAt.cend(), vals.begin());
|
||||
std::copy(props.OrientUp.cbegin(), props.OrientUp.cend(), vals.begin()+3);
|
||||
break;
|
||||
|
||||
default:
|
||||
GetParamf(props, param, values);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,61 +12,109 @@
|
||||
|
||||
namespace {
|
||||
|
||||
void Dedicated_setParami(EffectProps*, ALenum param, int)
|
||||
constexpr EffectProps genDefaultDialogProps() noexcept
|
||||
{
|
||||
DedicatedDialogProps props{};
|
||||
props.Gain = 1.0f;
|
||||
return props;
|
||||
}
|
||||
|
||||
constexpr EffectProps genDefaultLfeProps() noexcept
|
||||
{
|
||||
DedicatedLfeProps props{};
|
||||
props.Gain = 1.0f;
|
||||
return props;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
const EffectProps DedicatedDialogEffectProps{genDefaultDialogProps()};
|
||||
|
||||
void EffectHandler::SetParami(DedicatedDialogProps&, ALenum param, int)
|
||||
{ throw effect_exception{AL_INVALID_ENUM, "Invalid dedicated integer property 0x%04x", param}; }
|
||||
void Dedicated_setParamiv(EffectProps*, ALenum param, const int*)
|
||||
void EffectHandler::SetParamiv(DedicatedDialogProps&, ALenum param, const int*)
|
||||
{
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid dedicated integer-vector property 0x%04x",
|
||||
param};
|
||||
}
|
||||
void Dedicated_setParamf(EffectProps *props, ALenum param, float val)
|
||||
void EffectHandler::SetParamf(DedicatedDialogProps &props, ALenum param, float val)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case AL_DEDICATED_GAIN:
|
||||
if(!(val >= 0.0f && std::isfinite(val)))
|
||||
throw effect_exception{AL_INVALID_VALUE, "Dedicated gain out of range"};
|
||||
props->Dedicated.Gain = val;
|
||||
props.Gain = val;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid dedicated float property 0x%04x", param};
|
||||
}
|
||||
}
|
||||
void Dedicated_setParamfv(EffectProps *props, ALenum param, const float *vals)
|
||||
{ Dedicated_setParamf(props, param, vals[0]); }
|
||||
void EffectHandler::SetParamfv(DedicatedDialogProps &props, ALenum param, const float *vals)
|
||||
{ SetParamf(props, param, *vals); }
|
||||
|
||||
void Dedicated_getParami(const EffectProps*, ALenum param, int*)
|
||||
void EffectHandler::GetParami(const DedicatedDialogProps&, ALenum param, int*)
|
||||
{ throw effect_exception{AL_INVALID_ENUM, "Invalid dedicated integer property 0x%04x", param}; }
|
||||
void Dedicated_getParamiv(const EffectProps*, ALenum param, int*)
|
||||
void EffectHandler::GetParamiv(const DedicatedDialogProps&, ALenum param, int*)
|
||||
{
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid dedicated integer-vector property 0x%04x",
|
||||
param};
|
||||
}
|
||||
void Dedicated_getParamf(const EffectProps *props, ALenum param, float *val)
|
||||
void EffectHandler::GetParamf(const DedicatedDialogProps &props, ALenum param, float *val)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case AL_DEDICATED_GAIN: *val = props.Gain; break;
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid dedicated float property 0x%04x", param};
|
||||
}
|
||||
}
|
||||
void EffectHandler::GetParamfv(const DedicatedDialogProps &props, ALenum param, float *vals)
|
||||
{ GetParamf(props, param, vals); }
|
||||
|
||||
|
||||
const EffectProps DedicatedLfeEffectProps{genDefaultLfeProps()};
|
||||
|
||||
void EffectHandler::SetParami(DedicatedLfeProps&, ALenum param, int)
|
||||
{ throw effect_exception{AL_INVALID_ENUM, "Invalid dedicated integer property 0x%04x", param}; }
|
||||
void EffectHandler::SetParamiv(DedicatedLfeProps&, ALenum param, const int*)
|
||||
{
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid dedicated integer-vector property 0x%04x",
|
||||
param};
|
||||
}
|
||||
void EffectHandler::SetParamf(DedicatedLfeProps &props, ALenum param, float val)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case AL_DEDICATED_GAIN:
|
||||
*val = props->Dedicated.Gain;
|
||||
if(!(val >= 0.0f && std::isfinite(val)))
|
||||
throw effect_exception{AL_INVALID_VALUE, "Dedicated gain out of range"};
|
||||
props.Gain = val;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid dedicated float property 0x%04x", param};
|
||||
}
|
||||
}
|
||||
void Dedicated_getParamfv(const EffectProps *props, ALenum param, float *vals)
|
||||
{ Dedicated_getParamf(props, param, vals); }
|
||||
void EffectHandler::SetParamfv(DedicatedLfeProps &props, ALenum param, const float *vals)
|
||||
{ SetParamf(props, param, *vals); }
|
||||
|
||||
EffectProps genDefaultProps() noexcept
|
||||
void EffectHandler::GetParami(const DedicatedLfeProps&, ALenum param, int*)
|
||||
{ throw effect_exception{AL_INVALID_ENUM, "Invalid dedicated integer property 0x%04x", param}; }
|
||||
void EffectHandler::GetParamiv(const DedicatedLfeProps&, ALenum param, int*)
|
||||
{
|
||||
EffectProps props{};
|
||||
props.Dedicated.Gain = 1.0f;
|
||||
return props;
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid dedicated integer-vector property 0x%04x",
|
||||
param};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
DEFINE_ALEFFECT_VTABLE(Dedicated);
|
||||
|
||||
const EffectProps DedicatedEffectProps{genDefaultProps()};
|
||||
void EffectHandler::GetParamf(const DedicatedLfeProps &props, ALenum param, float *val)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case AL_DEDICATED_GAIN: *val = props.Gain; break;
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid dedicated float property 0x%04x", param};
|
||||
}
|
||||
}
|
||||
void EffectHandler::GetParamfv(const DedicatedLfeProps &props, ALenum param, float *vals)
|
||||
{ GetParamf(props, param, vals); }
|
||||
|
||||
@@ -9,563 +9,249 @@
|
||||
|
||||
#ifdef ALSOFT_EAX
|
||||
#include "alnumeric.h"
|
||||
|
||||
#include "al/eax_exception.h"
|
||||
#include "al/eax_utils.h"
|
||||
#include "al/eax/effect.h"
|
||||
#include "al/eax/exception.h"
|
||||
#include "al/eax/utils.h"
|
||||
#endif // ALSOFT_EAX
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
void Distortion_setParami(EffectProps*, ALenum param, int)
|
||||
constexpr EffectProps genDefaultProps() noexcept
|
||||
{
|
||||
DistortionProps props{};
|
||||
props.Edge = AL_DISTORTION_DEFAULT_EDGE;
|
||||
props.Gain = AL_DISTORTION_DEFAULT_GAIN;
|
||||
props.LowpassCutoff = AL_DISTORTION_DEFAULT_LOWPASS_CUTOFF;
|
||||
props.EQCenter = AL_DISTORTION_DEFAULT_EQCENTER;
|
||||
props.EQBandwidth = AL_DISTORTION_DEFAULT_EQBANDWIDTH;
|
||||
return props;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
const EffectProps DistortionEffectProps{genDefaultProps()};
|
||||
|
||||
void EffectHandler::SetParami(DistortionProps&, ALenum param, int)
|
||||
{ throw effect_exception{AL_INVALID_ENUM, "Invalid distortion integer property 0x%04x", param}; }
|
||||
void Distortion_setParamiv(EffectProps*, ALenum param, const int*)
|
||||
void EffectHandler::SetParamiv(DistortionProps&, ALenum param, const int*)
|
||||
{
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid distortion integer-vector property 0x%04x",
|
||||
param};
|
||||
}
|
||||
void Distortion_setParamf(EffectProps *props, ALenum param, float val)
|
||||
void EffectHandler::SetParamf(DistortionProps &props, ALenum param, float val)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case AL_DISTORTION_EDGE:
|
||||
if(!(val >= AL_DISTORTION_MIN_EDGE && val <= AL_DISTORTION_MAX_EDGE))
|
||||
throw effect_exception{AL_INVALID_VALUE, "Distortion edge out of range"};
|
||||
props->Distortion.Edge = val;
|
||||
props.Edge = val;
|
||||
break;
|
||||
|
||||
case AL_DISTORTION_GAIN:
|
||||
if(!(val >= AL_DISTORTION_MIN_GAIN && val <= AL_DISTORTION_MAX_GAIN))
|
||||
throw effect_exception{AL_INVALID_VALUE, "Distortion gain out of range"};
|
||||
props->Distortion.Gain = val;
|
||||
props.Gain = val;
|
||||
break;
|
||||
|
||||
case AL_DISTORTION_LOWPASS_CUTOFF:
|
||||
if(!(val >= AL_DISTORTION_MIN_LOWPASS_CUTOFF && val <= AL_DISTORTION_MAX_LOWPASS_CUTOFF))
|
||||
throw effect_exception{AL_INVALID_VALUE, "Distortion low-pass cutoff out of range"};
|
||||
props->Distortion.LowpassCutoff = val;
|
||||
props.LowpassCutoff = val;
|
||||
break;
|
||||
|
||||
case AL_DISTORTION_EQCENTER:
|
||||
if(!(val >= AL_DISTORTION_MIN_EQCENTER && val <= AL_DISTORTION_MAX_EQCENTER))
|
||||
throw effect_exception{AL_INVALID_VALUE, "Distortion EQ center out of range"};
|
||||
props->Distortion.EQCenter = val;
|
||||
props.EQCenter = val;
|
||||
break;
|
||||
|
||||
case AL_DISTORTION_EQBANDWIDTH:
|
||||
if(!(val >= AL_DISTORTION_MIN_EQBANDWIDTH && val <= AL_DISTORTION_MAX_EQBANDWIDTH))
|
||||
throw effect_exception{AL_INVALID_VALUE, "Distortion EQ bandwidth out of range"};
|
||||
props->Distortion.EQBandwidth = val;
|
||||
props.EQBandwidth = val;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid distortion float property 0x%04x", param};
|
||||
}
|
||||
}
|
||||
void Distortion_setParamfv(EffectProps *props, ALenum param, const float *vals)
|
||||
{ Distortion_setParamf(props, param, vals[0]); }
|
||||
void EffectHandler::SetParamfv(DistortionProps &props, ALenum param, const float *vals)
|
||||
{ SetParamf(props, param, *vals); }
|
||||
|
||||
void Distortion_getParami(const EffectProps*, ALenum param, int*)
|
||||
void EffectHandler::GetParami(const DistortionProps&, ALenum param, int*)
|
||||
{ throw effect_exception{AL_INVALID_ENUM, "Invalid distortion integer property 0x%04x", param}; }
|
||||
void Distortion_getParamiv(const EffectProps*, ALenum param, int*)
|
||||
void EffectHandler::GetParamiv(const DistortionProps&, ALenum param, int*)
|
||||
{
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid distortion integer-vector property 0x%04x",
|
||||
param};
|
||||
}
|
||||
void Distortion_getParamf(const EffectProps *props, ALenum param, float *val)
|
||||
void EffectHandler::GetParamf(const DistortionProps &props, ALenum param, float *val)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case AL_DISTORTION_EDGE:
|
||||
*val = props->Distortion.Edge;
|
||||
break;
|
||||
|
||||
case AL_DISTORTION_GAIN:
|
||||
*val = props->Distortion.Gain;
|
||||
break;
|
||||
|
||||
case AL_DISTORTION_LOWPASS_CUTOFF:
|
||||
*val = props->Distortion.LowpassCutoff;
|
||||
break;
|
||||
|
||||
case AL_DISTORTION_EQCENTER:
|
||||
*val = props->Distortion.EQCenter;
|
||||
break;
|
||||
|
||||
case AL_DISTORTION_EQBANDWIDTH:
|
||||
*val = props->Distortion.EQBandwidth;
|
||||
break;
|
||||
case AL_DISTORTION_EDGE: *val = props.Edge; break;
|
||||
case AL_DISTORTION_GAIN: *val = props.Gain; break;
|
||||
case AL_DISTORTION_LOWPASS_CUTOFF: *val = props.LowpassCutoff; break;
|
||||
case AL_DISTORTION_EQCENTER: *val = props.EQCenter; break;
|
||||
case AL_DISTORTION_EQBANDWIDTH: *val = props.EQBandwidth; break;
|
||||
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid distortion float property 0x%04x", param};
|
||||
}
|
||||
}
|
||||
void Distortion_getParamfv(const EffectProps *props, ALenum param, float *vals)
|
||||
{ Distortion_getParamf(props, param, vals); }
|
||||
void EffectHandler::GetParamfv(const DistortionProps &props, ALenum param, float *vals)
|
||||
{ GetParamf(props, param, vals); }
|
||||
|
||||
EffectProps genDefaultProps() noexcept
|
||||
{
|
||||
EffectProps props{};
|
||||
props.Distortion.Edge = AL_DISTORTION_DEFAULT_EDGE;
|
||||
props.Distortion.Gain = AL_DISTORTION_DEFAULT_GAIN;
|
||||
props.Distortion.LowpassCutoff = AL_DISTORTION_DEFAULT_LOWPASS_CUTOFF;
|
||||
props.Distortion.EQCenter = AL_DISTORTION_DEFAULT_EQCENTER;
|
||||
props.Distortion.EQBandwidth = AL_DISTORTION_DEFAULT_EQBANDWIDTH;
|
||||
return props;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
DEFINE_ALEFFECT_VTABLE(Distortion);
|
||||
|
||||
const EffectProps DistortionEffectProps{genDefaultProps()};
|
||||
|
||||
#ifdef ALSOFT_EAX
|
||||
namespace {
|
||||
|
||||
using EaxDistortionEffectDirtyFlagsValue = std::uint_least8_t;
|
||||
using DistortionCommitter = EaxCommitter<EaxDistortionCommitter>;
|
||||
|
||||
struct EaxDistortionEffectDirtyFlags
|
||||
{
|
||||
using EaxIsBitFieldStruct = bool;
|
||||
|
||||
EaxDistortionEffectDirtyFlagsValue flEdge : 1;
|
||||
EaxDistortionEffectDirtyFlagsValue lGain : 1;
|
||||
EaxDistortionEffectDirtyFlagsValue flLowPassCutOff : 1;
|
||||
EaxDistortionEffectDirtyFlagsValue flEQCenter : 1;
|
||||
EaxDistortionEffectDirtyFlagsValue flEQBandwidth : 1;
|
||||
}; // EaxDistortionEffectDirtyFlags
|
||||
|
||||
|
||||
class EaxDistortionEffect final :
|
||||
public EaxEffect
|
||||
{
|
||||
public:
|
||||
EaxDistortionEffect();
|
||||
|
||||
void dispatch(const EaxEaxCall& eax_call) override;
|
||||
|
||||
// [[nodiscard]]
|
||||
bool apply_deferred() override;
|
||||
|
||||
private:
|
||||
EAXDISTORTIONPROPERTIES eax_{};
|
||||
EAXDISTORTIONPROPERTIES eax_d_{};
|
||||
EaxDistortionEffectDirtyFlags eax_dirty_flags_{};
|
||||
|
||||
void set_eax_defaults();
|
||||
|
||||
void set_efx_edge();
|
||||
void set_efx_gain();
|
||||
void set_efx_lowpass_cutoff();
|
||||
void set_efx_eq_center();
|
||||
void set_efx_eq_bandwidth();
|
||||
void set_efx_defaults();
|
||||
|
||||
void get(const EaxEaxCall& eax_call);
|
||||
|
||||
void validate_edge(float flEdge);
|
||||
void validate_gain(long lGain);
|
||||
void validate_lowpass_cutoff(float flLowPassCutOff);
|
||||
void validate_eq_center(float flEQCenter);
|
||||
void validate_eq_bandwidth(float flEQBandwidth);
|
||||
void validate_all(const EAXDISTORTIONPROPERTIES& eax_all);
|
||||
|
||||
void defer_edge(float flEdge);
|
||||
void defer_gain(long lGain);
|
||||
void defer_low_pass_cutoff(float flLowPassCutOff);
|
||||
void defer_eq_center(float flEQCenter);
|
||||
void defer_eq_bandwidth(float flEQBandwidth);
|
||||
void defer_all(const EAXDISTORTIONPROPERTIES& eax_all);
|
||||
|
||||
void defer_edge(const EaxEaxCall& eax_call);
|
||||
void defer_gain(const EaxEaxCall& eax_call);
|
||||
void defer_low_pass_cutoff(const EaxEaxCall& eax_call);
|
||||
void defer_eq_center(const EaxEaxCall& eax_call);
|
||||
void defer_eq_bandwidth(const EaxEaxCall& eax_call);
|
||||
void defer_all(const EaxEaxCall& eax_call);
|
||||
|
||||
void set(const EaxEaxCall& eax_call);
|
||||
}; // EaxDistortionEffect
|
||||
|
||||
|
||||
class EaxDistortionEffectException :
|
||||
public EaxException
|
||||
{
|
||||
public:
|
||||
explicit EaxDistortionEffectException(
|
||||
const char* message)
|
||||
:
|
||||
EaxException{"EAX_DISTORTION_EFFECT", message}
|
||||
struct EdgeValidator {
|
||||
void operator()(float flEdge) const
|
||||
{
|
||||
eax_validate_range<DistortionCommitter::Exception>(
|
||||
"Edge",
|
||||
flEdge,
|
||||
EAXDISTORTION_MINEDGE,
|
||||
EAXDISTORTION_MAXEDGE);
|
||||
}
|
||||
}; // EaxDistortionEffectException
|
||||
}; // EdgeValidator
|
||||
|
||||
|
||||
EaxDistortionEffect::EaxDistortionEffect()
|
||||
: EaxEffect{AL_EFFECT_DISTORTION}
|
||||
{
|
||||
set_eax_defaults();
|
||||
set_efx_defaults();
|
||||
}
|
||||
|
||||
void EaxDistortionEffect::dispatch(const EaxEaxCall& eax_call)
|
||||
{
|
||||
eax_call.is_get() ? get(eax_call) : set(eax_call);
|
||||
}
|
||||
|
||||
void EaxDistortionEffect::set_eax_defaults()
|
||||
{
|
||||
eax_.flEdge = EAXDISTORTION_DEFAULTEDGE;
|
||||
eax_.lGain = EAXDISTORTION_DEFAULTGAIN;
|
||||
eax_.flLowPassCutOff = EAXDISTORTION_DEFAULTLOWPASSCUTOFF;
|
||||
eax_.flEQCenter = EAXDISTORTION_DEFAULTEQCENTER;
|
||||
eax_.flEQBandwidth = EAXDISTORTION_DEFAULTEQBANDWIDTH;
|
||||
|
||||
eax_d_ = eax_;
|
||||
}
|
||||
|
||||
void EaxDistortionEffect::set_efx_edge()
|
||||
{
|
||||
const auto edge = clamp(
|
||||
eax_.flEdge,
|
||||
AL_DISTORTION_MIN_EDGE,
|
||||
AL_DISTORTION_MAX_EDGE);
|
||||
|
||||
al_effect_props_.Distortion.Edge = edge;
|
||||
}
|
||||
|
||||
void EaxDistortionEffect::set_efx_gain()
|
||||
{
|
||||
const auto gain = clamp(
|
||||
level_mb_to_gain(static_cast<float>(eax_.lGain)),
|
||||
AL_DISTORTION_MIN_GAIN,
|
||||
AL_DISTORTION_MAX_GAIN);
|
||||
|
||||
al_effect_props_.Distortion.Gain = gain;
|
||||
}
|
||||
|
||||
void EaxDistortionEffect::set_efx_lowpass_cutoff()
|
||||
{
|
||||
const auto lowpass_cutoff = clamp(
|
||||
eax_.flLowPassCutOff,
|
||||
AL_DISTORTION_MIN_LOWPASS_CUTOFF,
|
||||
AL_DISTORTION_MAX_LOWPASS_CUTOFF);
|
||||
|
||||
al_effect_props_.Distortion.LowpassCutoff = lowpass_cutoff;
|
||||
}
|
||||
|
||||
void EaxDistortionEffect::set_efx_eq_center()
|
||||
{
|
||||
const auto eq_center = clamp(
|
||||
eax_.flEQCenter,
|
||||
AL_DISTORTION_MIN_EQCENTER,
|
||||
AL_DISTORTION_MAX_EQCENTER);
|
||||
|
||||
al_effect_props_.Distortion.EQCenter = eq_center;
|
||||
}
|
||||
|
||||
void EaxDistortionEffect::set_efx_eq_bandwidth()
|
||||
{
|
||||
const auto eq_bandwidth = clamp(
|
||||
eax_.flEdge,
|
||||
AL_DISTORTION_MIN_EQBANDWIDTH,
|
||||
AL_DISTORTION_MAX_EQBANDWIDTH);
|
||||
|
||||
al_effect_props_.Distortion.EQBandwidth = eq_bandwidth;
|
||||
}
|
||||
|
||||
void EaxDistortionEffect::set_efx_defaults()
|
||||
{
|
||||
set_efx_edge();
|
||||
set_efx_gain();
|
||||
set_efx_lowpass_cutoff();
|
||||
set_efx_eq_center();
|
||||
set_efx_eq_bandwidth();
|
||||
}
|
||||
|
||||
void EaxDistortionEffect::get(const EaxEaxCall& eax_call)
|
||||
{
|
||||
switch(eax_call.get_property_id())
|
||||
struct GainValidator {
|
||||
void operator()(long lGain) const
|
||||
{
|
||||
case EAXDISTORTION_NONE:
|
||||
break;
|
||||
|
||||
case EAXDISTORTION_ALLPARAMETERS:
|
||||
eax_call.set_value<EaxDistortionEffectException>(eax_);
|
||||
break;
|
||||
|
||||
case EAXDISTORTION_EDGE:
|
||||
eax_call.set_value<EaxDistortionEffectException>(eax_.flEdge);
|
||||
break;
|
||||
|
||||
case EAXDISTORTION_GAIN:
|
||||
eax_call.set_value<EaxDistortionEffectException>(eax_.lGain);
|
||||
break;
|
||||
|
||||
case EAXDISTORTION_LOWPASSCUTOFF:
|
||||
eax_call.set_value<EaxDistortionEffectException>(eax_.flLowPassCutOff);
|
||||
break;
|
||||
|
||||
case EAXDISTORTION_EQCENTER:
|
||||
eax_call.set_value<EaxDistortionEffectException>(eax_.flEQCenter);
|
||||
break;
|
||||
|
||||
case EAXDISTORTION_EQBANDWIDTH:
|
||||
eax_call.set_value<EaxDistortionEffectException>(eax_.flEQBandwidth);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw EaxDistortionEffectException{"Unsupported property id."};
|
||||
eax_validate_range<DistortionCommitter::Exception>(
|
||||
"Gain",
|
||||
lGain,
|
||||
EAXDISTORTION_MINGAIN,
|
||||
EAXDISTORTION_MAXGAIN);
|
||||
}
|
||||
}
|
||||
}; // GainValidator
|
||||
|
||||
void EaxDistortionEffect::validate_edge(
|
||||
float flEdge)
|
||||
{
|
||||
eax_validate_range<EaxDistortionEffectException>(
|
||||
"Edge",
|
||||
flEdge,
|
||||
EAXDISTORTION_MINEDGE,
|
||||
EAXDISTORTION_MAXEDGE);
|
||||
}
|
||||
|
||||
void EaxDistortionEffect::validate_gain(
|
||||
long lGain)
|
||||
{
|
||||
eax_validate_range<EaxDistortionEffectException>(
|
||||
"Gain",
|
||||
lGain,
|
||||
EAXDISTORTION_MINGAIN,
|
||||
EAXDISTORTION_MAXGAIN);
|
||||
}
|
||||
|
||||
void EaxDistortionEffect::validate_lowpass_cutoff(
|
||||
float flLowPassCutOff)
|
||||
{
|
||||
eax_validate_range<EaxDistortionEffectException>(
|
||||
"Low-pass Cut-off",
|
||||
flLowPassCutOff,
|
||||
EAXDISTORTION_MINLOWPASSCUTOFF,
|
||||
EAXDISTORTION_MAXLOWPASSCUTOFF);
|
||||
}
|
||||
|
||||
void EaxDistortionEffect::validate_eq_center(
|
||||
float flEQCenter)
|
||||
{
|
||||
eax_validate_range<EaxDistortionEffectException>(
|
||||
"EQ Center",
|
||||
flEQCenter,
|
||||
EAXDISTORTION_MINEQCENTER,
|
||||
EAXDISTORTION_MAXEQCENTER);
|
||||
}
|
||||
|
||||
void EaxDistortionEffect::validate_eq_bandwidth(
|
||||
float flEQBandwidth)
|
||||
{
|
||||
eax_validate_range<EaxDistortionEffectException>(
|
||||
"EQ Bandwidth",
|
||||
flEQBandwidth,
|
||||
EAXDISTORTION_MINEQBANDWIDTH,
|
||||
EAXDISTORTION_MAXEQBANDWIDTH);
|
||||
}
|
||||
|
||||
void EaxDistortionEffect::validate_all(
|
||||
const EAXDISTORTIONPROPERTIES& eax_all)
|
||||
{
|
||||
validate_edge(eax_all.flEdge);
|
||||
validate_gain(eax_all.lGain);
|
||||
validate_lowpass_cutoff(eax_all.flLowPassCutOff);
|
||||
validate_eq_center(eax_all.flEQCenter);
|
||||
validate_eq_bandwidth(eax_all.flEQBandwidth);
|
||||
}
|
||||
|
||||
void EaxDistortionEffect::defer_edge(
|
||||
float flEdge)
|
||||
{
|
||||
eax_d_.flEdge = flEdge;
|
||||
eax_dirty_flags_.flEdge = (eax_.flEdge != eax_d_.flEdge);
|
||||
}
|
||||
|
||||
void EaxDistortionEffect::defer_gain(
|
||||
long lGain)
|
||||
{
|
||||
eax_d_.lGain = lGain;
|
||||
eax_dirty_flags_.lGain = (eax_.lGain != eax_d_.lGain);
|
||||
}
|
||||
|
||||
void EaxDistortionEffect::defer_low_pass_cutoff(
|
||||
float flLowPassCutOff)
|
||||
{
|
||||
eax_d_.flLowPassCutOff = flLowPassCutOff;
|
||||
eax_dirty_flags_.flLowPassCutOff = (eax_.flLowPassCutOff != eax_d_.flLowPassCutOff);
|
||||
}
|
||||
|
||||
void EaxDistortionEffect::defer_eq_center(
|
||||
float flEQCenter)
|
||||
{
|
||||
eax_d_.flEQCenter = flEQCenter;
|
||||
eax_dirty_flags_.flEQCenter = (eax_.flEQCenter != eax_d_.flEQCenter);
|
||||
}
|
||||
|
||||
void EaxDistortionEffect::defer_eq_bandwidth(
|
||||
float flEQBandwidth)
|
||||
{
|
||||
eax_d_.flEQBandwidth = flEQBandwidth;
|
||||
eax_dirty_flags_.flEQBandwidth = (eax_.flEQBandwidth != eax_d_.flEQBandwidth);
|
||||
}
|
||||
|
||||
void EaxDistortionEffect::defer_all(
|
||||
const EAXDISTORTIONPROPERTIES& eax_all)
|
||||
{
|
||||
defer_edge(eax_all.flEdge);
|
||||
defer_gain(eax_all.lGain);
|
||||
defer_low_pass_cutoff(eax_all.flLowPassCutOff);
|
||||
defer_eq_center(eax_all.flEQCenter);
|
||||
defer_eq_bandwidth(eax_all.flEQBandwidth);
|
||||
}
|
||||
|
||||
void EaxDistortionEffect::defer_edge(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& edge =
|
||||
eax_call.get_value<EaxDistortionEffectException, const decltype(EAXDISTORTIONPROPERTIES::flEdge)>();
|
||||
|
||||
validate_edge(edge);
|
||||
defer_edge(edge);
|
||||
}
|
||||
|
||||
void EaxDistortionEffect::defer_gain(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& gain =
|
||||
eax_call.get_value<EaxDistortionEffectException, const decltype(EAXDISTORTIONPROPERTIES::lGain)>();
|
||||
|
||||
validate_gain(gain);
|
||||
defer_gain(gain);
|
||||
}
|
||||
|
||||
void EaxDistortionEffect::defer_low_pass_cutoff(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& lowpass_cutoff =
|
||||
eax_call.get_value<EaxDistortionEffectException, const decltype(EAXDISTORTIONPROPERTIES::flLowPassCutOff)>();
|
||||
|
||||
validate_lowpass_cutoff(lowpass_cutoff);
|
||||
defer_low_pass_cutoff(lowpass_cutoff);
|
||||
}
|
||||
|
||||
void EaxDistortionEffect::defer_eq_center(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& eq_center =
|
||||
eax_call.get_value<EaxDistortionEffectException, const decltype(EAXDISTORTIONPROPERTIES::flEQCenter)>();
|
||||
|
||||
validate_eq_center(eq_center);
|
||||
defer_eq_center(eq_center);
|
||||
}
|
||||
|
||||
void EaxDistortionEffect::defer_eq_bandwidth(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& eq_bandwidth =
|
||||
eax_call.get_value<EaxDistortionEffectException, const decltype(EAXDISTORTIONPROPERTIES::flEQBandwidth)>();
|
||||
|
||||
validate_eq_bandwidth(eq_bandwidth);
|
||||
defer_eq_bandwidth(eq_bandwidth);
|
||||
}
|
||||
|
||||
void EaxDistortionEffect::defer_all(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& all =
|
||||
eax_call.get_value<EaxDistortionEffectException, const EAXDISTORTIONPROPERTIES>();
|
||||
|
||||
validate_all(all);
|
||||
defer_all(all);
|
||||
}
|
||||
|
||||
// [[nodiscard]]
|
||||
bool EaxDistortionEffect::apply_deferred()
|
||||
{
|
||||
if (eax_dirty_flags_ == EaxDistortionEffectDirtyFlags{})
|
||||
struct LowPassCutOffValidator {
|
||||
void operator()(float flLowPassCutOff) const
|
||||
{
|
||||
eax_validate_range<DistortionCommitter::Exception>(
|
||||
"Low-pass Cut-off",
|
||||
flLowPassCutOff,
|
||||
EAXDISTORTION_MINLOWPASSCUTOFF,
|
||||
EAXDISTORTION_MAXLOWPASSCUTOFF);
|
||||
}
|
||||
}; // LowPassCutOffValidator
|
||||
|
||||
struct EqCenterValidator {
|
||||
void operator()(float flEQCenter) const
|
||||
{
|
||||
eax_validate_range<DistortionCommitter::Exception>(
|
||||
"EQ Center",
|
||||
flEQCenter,
|
||||
EAXDISTORTION_MINEQCENTER,
|
||||
EAXDISTORTION_MAXEQCENTER);
|
||||
}
|
||||
}; // EqCenterValidator
|
||||
|
||||
struct EqBandwidthValidator {
|
||||
void operator()(float flEQBandwidth) const
|
||||
{
|
||||
eax_validate_range<DistortionCommitter::Exception>(
|
||||
"EQ Bandwidth",
|
||||
flEQBandwidth,
|
||||
EAXDISTORTION_MINEQBANDWIDTH,
|
||||
EAXDISTORTION_MAXEQBANDWIDTH);
|
||||
}
|
||||
}; // EqBandwidthValidator
|
||||
|
||||
struct AllValidator {
|
||||
void operator()(const EAXDISTORTIONPROPERTIES& all) const
|
||||
{
|
||||
EdgeValidator{}(all.flEdge);
|
||||
GainValidator{}(all.lGain);
|
||||
LowPassCutOffValidator{}(all.flLowPassCutOff);
|
||||
EqCenterValidator{}(all.flEQCenter);
|
||||
EqBandwidthValidator{}(all.flEQBandwidth);
|
||||
}
|
||||
}; // AllValidator
|
||||
|
||||
} // namespace
|
||||
|
||||
template<>
|
||||
struct DistortionCommitter::Exception : public EaxException {
|
||||
explicit Exception(const char *message) : EaxException{"EAX_DISTORTION_EFFECT", message}
|
||||
{ }
|
||||
};
|
||||
|
||||
template<>
|
||||
[[noreturn]] void DistortionCommitter::fail(const char *message)
|
||||
{
|
||||
throw Exception{message};
|
||||
}
|
||||
|
||||
bool EaxDistortionCommitter::commit(const EAXDISTORTIONPROPERTIES &props)
|
||||
{
|
||||
if(auto *cur = std::get_if<EAXDISTORTIONPROPERTIES>(&mEaxProps); cur && *cur == props)
|
||||
return false;
|
||||
}
|
||||
|
||||
eax_ = eax_d_;
|
||||
|
||||
if (eax_dirty_flags_.flEdge)
|
||||
{
|
||||
set_efx_edge();
|
||||
}
|
||||
|
||||
if (eax_dirty_flags_.lGain)
|
||||
{
|
||||
set_efx_gain();
|
||||
}
|
||||
|
||||
if (eax_dirty_flags_.flLowPassCutOff)
|
||||
{
|
||||
set_efx_lowpass_cutoff();
|
||||
}
|
||||
|
||||
if (eax_dirty_flags_.flEQCenter)
|
||||
{
|
||||
set_efx_eq_center();
|
||||
}
|
||||
|
||||
if (eax_dirty_flags_.flEQBandwidth)
|
||||
{
|
||||
set_efx_eq_bandwidth();
|
||||
}
|
||||
|
||||
eax_dirty_flags_ = EaxDistortionEffectDirtyFlags{};
|
||||
mEaxProps = props;
|
||||
mAlProps = [&]{
|
||||
DistortionProps ret{};
|
||||
ret.Edge = props.flEdge;
|
||||
ret.Gain = level_mb_to_gain(static_cast<float>(props.lGain));
|
||||
ret.LowpassCutoff = props.flLowPassCutOff;
|
||||
ret.EQCenter = props.flEQCenter;
|
||||
ret.EQBandwidth = props.flEdge;
|
||||
return ret;
|
||||
}();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void EaxDistortionEffect::set(const EaxEaxCall& eax_call)
|
||||
void EaxDistortionCommitter::SetDefaults(EaxEffectProps &props)
|
||||
{
|
||||
switch(eax_call.get_property_id())
|
||||
static constexpr EAXDISTORTIONPROPERTIES defprops{[]
|
||||
{
|
||||
case EAXDISTORTION_NONE:
|
||||
break;
|
||||
EAXDISTORTIONPROPERTIES ret{};
|
||||
ret.flEdge = EAXDISTORTION_DEFAULTEDGE;
|
||||
ret.lGain = EAXDISTORTION_DEFAULTGAIN;
|
||||
ret.flLowPassCutOff = EAXDISTORTION_DEFAULTLOWPASSCUTOFF;
|
||||
ret.flEQCenter = EAXDISTORTION_DEFAULTEQCENTER;
|
||||
ret.flEQBandwidth = EAXDISTORTION_DEFAULTEQBANDWIDTH;
|
||||
return ret;
|
||||
}()};
|
||||
props = defprops;
|
||||
}
|
||||
|
||||
case EAXDISTORTION_ALLPARAMETERS:
|
||||
defer_all(eax_call);
|
||||
break;
|
||||
|
||||
case EAXDISTORTION_EDGE:
|
||||
defer_edge(eax_call);
|
||||
break;
|
||||
|
||||
case EAXDISTORTION_GAIN:
|
||||
defer_gain(eax_call);
|
||||
break;
|
||||
|
||||
case EAXDISTORTION_LOWPASSCUTOFF:
|
||||
defer_low_pass_cutoff(eax_call);
|
||||
break;
|
||||
|
||||
case EAXDISTORTION_EQCENTER:
|
||||
defer_eq_center(eax_call);
|
||||
break;
|
||||
|
||||
case EAXDISTORTION_EQBANDWIDTH:
|
||||
defer_eq_bandwidth(eax_call);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw EaxDistortionEffectException{"Unsupported property id."};
|
||||
void EaxDistortionCommitter::Get(const EaxCall &call, const EAXDISTORTIONPROPERTIES &props)
|
||||
{
|
||||
switch(call.get_property_id())
|
||||
{
|
||||
case EAXDISTORTION_NONE: break;
|
||||
case EAXDISTORTION_ALLPARAMETERS: call.set_value<Exception>(props); break;
|
||||
case EAXDISTORTION_EDGE: call.set_value<Exception>(props.flEdge); break;
|
||||
case EAXDISTORTION_GAIN: call.set_value<Exception>(props.lGain); break;
|
||||
case EAXDISTORTION_LOWPASSCUTOFF: call.set_value<Exception>(props.flLowPassCutOff); break;
|
||||
case EAXDISTORTION_EQCENTER: call.set_value<Exception>(props.flEQCenter); break;
|
||||
case EAXDISTORTION_EQBANDWIDTH: call.set_value<Exception>(props.flEQBandwidth); break;
|
||||
default: fail_unknown_property_id();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
EaxEffectUPtr eax_create_eax_distortion_effect()
|
||||
void EaxDistortionCommitter::Set(const EaxCall &call, EAXDISTORTIONPROPERTIES &props)
|
||||
{
|
||||
return std::make_unique<EaxDistortionEffect>();
|
||||
switch(call.get_property_id())
|
||||
{
|
||||
case EAXDISTORTION_NONE: break;
|
||||
case EAXDISTORTION_ALLPARAMETERS: defer<AllValidator>(call, props); break;
|
||||
case EAXDISTORTION_EDGE: defer<EdgeValidator>(call, props.flEdge); break;
|
||||
case EAXDISTORTION_GAIN: defer<GainValidator>(call, props.lGain); break;
|
||||
case EAXDISTORTION_LOWPASSCUTOFF: defer<LowPassCutOffValidator>(call, props.flLowPassCutOff); break;
|
||||
case EAXDISTORTION_EQCENTER: defer<EqCenterValidator>(call, props.flEQCenter); break;
|
||||
case EAXDISTORTION_EQBANDWIDTH: defer<EqBandwidthValidator>(call, props.flEQBandwidth); break;
|
||||
default: fail_unknown_property_id();
|
||||
}
|
||||
}
|
||||
|
||||
#endif // ALSOFT_EAX
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
#ifdef ALSOFT_EAX
|
||||
#include "alnumeric.h"
|
||||
|
||||
#include "al/eax_exception.h"
|
||||
#include "al/eax_utils.h"
|
||||
#include "al/eax/effect.h"
|
||||
#include "al/eax/exception.h"
|
||||
#include "al/eax/utils.h"
|
||||
#endif // ALSOFT_EAX
|
||||
|
||||
|
||||
@@ -20,550 +20,235 @@ namespace {
|
||||
static_assert(EchoMaxDelay >= AL_ECHO_MAX_DELAY, "Echo max delay too short");
|
||||
static_assert(EchoMaxLRDelay >= AL_ECHO_MAX_LRDELAY, "Echo max left-right delay too short");
|
||||
|
||||
void Echo_setParami(EffectProps*, ALenum param, int)
|
||||
constexpr EffectProps genDefaultProps() noexcept
|
||||
{
|
||||
EchoProps props{};
|
||||
props.Delay = AL_ECHO_DEFAULT_DELAY;
|
||||
props.LRDelay = AL_ECHO_DEFAULT_LRDELAY;
|
||||
props.Damping = AL_ECHO_DEFAULT_DAMPING;
|
||||
props.Feedback = AL_ECHO_DEFAULT_FEEDBACK;
|
||||
props.Spread = AL_ECHO_DEFAULT_SPREAD;
|
||||
return props;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
const EffectProps EchoEffectProps{genDefaultProps()};
|
||||
|
||||
void EffectHandler::SetParami(EchoProps&, ALenum param, int)
|
||||
{ throw effect_exception{AL_INVALID_ENUM, "Invalid echo integer property 0x%04x", param}; }
|
||||
void Echo_setParamiv(EffectProps*, ALenum param, const int*)
|
||||
void EffectHandler::SetParamiv(EchoProps&, ALenum param, const int*)
|
||||
{ throw effect_exception{AL_INVALID_ENUM, "Invalid echo integer-vector property 0x%04x", param}; }
|
||||
void Echo_setParamf(EffectProps *props, ALenum param, float val)
|
||||
void EffectHandler::SetParamf(EchoProps &props, ALenum param, float val)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case AL_ECHO_DELAY:
|
||||
if(!(val >= AL_ECHO_MIN_DELAY && val <= AL_ECHO_MAX_DELAY))
|
||||
throw effect_exception{AL_INVALID_VALUE, "Echo delay out of range"};
|
||||
props->Echo.Delay = val;
|
||||
props.Delay = val;
|
||||
break;
|
||||
|
||||
case AL_ECHO_LRDELAY:
|
||||
if(!(val >= AL_ECHO_MIN_LRDELAY && val <= AL_ECHO_MAX_LRDELAY))
|
||||
throw effect_exception{AL_INVALID_VALUE, "Echo LR delay out of range"};
|
||||
props->Echo.LRDelay = val;
|
||||
props.LRDelay = val;
|
||||
break;
|
||||
|
||||
case AL_ECHO_DAMPING:
|
||||
if(!(val >= AL_ECHO_MIN_DAMPING && val <= AL_ECHO_MAX_DAMPING))
|
||||
throw effect_exception{AL_INVALID_VALUE, "Echo damping out of range"};
|
||||
props->Echo.Damping = val;
|
||||
props.Damping = val;
|
||||
break;
|
||||
|
||||
case AL_ECHO_FEEDBACK:
|
||||
if(!(val >= AL_ECHO_MIN_FEEDBACK && val <= AL_ECHO_MAX_FEEDBACK))
|
||||
throw effect_exception{AL_INVALID_VALUE, "Echo feedback out of range"};
|
||||
props->Echo.Feedback = val;
|
||||
props.Feedback = val;
|
||||
break;
|
||||
|
||||
case AL_ECHO_SPREAD:
|
||||
if(!(val >= AL_ECHO_MIN_SPREAD && val <= AL_ECHO_MAX_SPREAD))
|
||||
throw effect_exception{AL_INVALID_VALUE, "Echo spread out of range"};
|
||||
props->Echo.Spread = val;
|
||||
props.Spread = val;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid echo float property 0x%04x", param};
|
||||
}
|
||||
}
|
||||
void Echo_setParamfv(EffectProps *props, ALenum param, const float *vals)
|
||||
{ Echo_setParamf(props, param, vals[0]); }
|
||||
void EffectHandler::SetParamfv(EchoProps &props, ALenum param, const float *vals)
|
||||
{ SetParamf(props, param, *vals); }
|
||||
|
||||
void Echo_getParami(const EffectProps*, ALenum param, int*)
|
||||
void EffectHandler::GetParami(const EchoProps&, ALenum param, int*)
|
||||
{ throw effect_exception{AL_INVALID_ENUM, "Invalid echo integer property 0x%04x", param}; }
|
||||
void Echo_getParamiv(const EffectProps*, ALenum param, int*)
|
||||
void EffectHandler::GetParamiv(const EchoProps&, ALenum param, int*)
|
||||
{ throw effect_exception{AL_INVALID_ENUM, "Invalid echo integer-vector property 0x%04x", param}; }
|
||||
void Echo_getParamf(const EffectProps *props, ALenum param, float *val)
|
||||
void EffectHandler::GetParamf(const EchoProps &props, ALenum param, float *val)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case AL_ECHO_DELAY:
|
||||
*val = props->Echo.Delay;
|
||||
break;
|
||||
|
||||
case AL_ECHO_LRDELAY:
|
||||
*val = props->Echo.LRDelay;
|
||||
break;
|
||||
|
||||
case AL_ECHO_DAMPING:
|
||||
*val = props->Echo.Damping;
|
||||
break;
|
||||
|
||||
case AL_ECHO_FEEDBACK:
|
||||
*val = props->Echo.Feedback;
|
||||
break;
|
||||
|
||||
case AL_ECHO_SPREAD:
|
||||
*val = props->Echo.Spread;
|
||||
break;
|
||||
case AL_ECHO_DELAY: *val = props.Delay; break;
|
||||
case AL_ECHO_LRDELAY: *val = props.LRDelay; break;
|
||||
case AL_ECHO_DAMPING: *val = props.Damping; break;
|
||||
case AL_ECHO_FEEDBACK: *val = props.Feedback; break;
|
||||
case AL_ECHO_SPREAD: *val = props.Spread; break;
|
||||
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid echo float property 0x%04x", param};
|
||||
}
|
||||
}
|
||||
void Echo_getParamfv(const EffectProps *props, ALenum param, float *vals)
|
||||
{ Echo_getParamf(props, param, vals); }
|
||||
void EffectHandler::GetParamfv(const EchoProps &props, ALenum param, float *vals)
|
||||
{ GetParamf(props, param, vals); }
|
||||
|
||||
EffectProps genDefaultProps() noexcept
|
||||
{
|
||||
EffectProps props{};
|
||||
props.Echo.Delay = AL_ECHO_DEFAULT_DELAY;
|
||||
props.Echo.LRDelay = AL_ECHO_DEFAULT_LRDELAY;
|
||||
props.Echo.Damping = AL_ECHO_DEFAULT_DAMPING;
|
||||
props.Echo.Feedback = AL_ECHO_DEFAULT_FEEDBACK;
|
||||
props.Echo.Spread = AL_ECHO_DEFAULT_SPREAD;
|
||||
return props;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
DEFINE_ALEFFECT_VTABLE(Echo);
|
||||
|
||||
const EffectProps EchoEffectProps{genDefaultProps()};
|
||||
|
||||
#ifdef ALSOFT_EAX
|
||||
namespace {
|
||||
|
||||
using EaxEchoEffectDirtyFlagsValue = std::uint_least8_t;
|
||||
using EchoCommitter = EaxCommitter<EaxEchoCommitter>;
|
||||
|
||||
struct EaxEchoEffectDirtyFlags
|
||||
{
|
||||
using EaxIsBitFieldStruct = bool;
|
||||
|
||||
EaxEchoEffectDirtyFlagsValue flDelay : 1;
|
||||
EaxEchoEffectDirtyFlagsValue flLRDelay : 1;
|
||||
EaxEchoEffectDirtyFlagsValue flDamping : 1;
|
||||
EaxEchoEffectDirtyFlagsValue flFeedback : 1;
|
||||
EaxEchoEffectDirtyFlagsValue flSpread : 1;
|
||||
}; // EaxEchoEffectDirtyFlags
|
||||
|
||||
|
||||
class EaxEchoEffect final :
|
||||
public EaxEffect
|
||||
{
|
||||
public:
|
||||
EaxEchoEffect();
|
||||
|
||||
void dispatch(const EaxEaxCall& eax_call) override;
|
||||
|
||||
// [[nodiscard]]
|
||||
bool apply_deferred() override;
|
||||
|
||||
private:
|
||||
EAXECHOPROPERTIES eax_{};
|
||||
EAXECHOPROPERTIES eax_d_{};
|
||||
EaxEchoEffectDirtyFlags eax_dirty_flags_{};
|
||||
|
||||
void set_eax_defaults();
|
||||
|
||||
void set_efx_delay();
|
||||
void set_efx_lr_delay();
|
||||
void set_efx_damping();
|
||||
void set_efx_feedback();
|
||||
void set_efx_spread();
|
||||
void set_efx_defaults();
|
||||
|
||||
void get(const EaxEaxCall& eax_call);
|
||||
|
||||
void validate_delay(float flDelay);
|
||||
void validate_lr_delay(float flLRDelay);
|
||||
void validate_damping(float flDamping);
|
||||
void validate_feedback(float flFeedback);
|
||||
void validate_spread(float flSpread);
|
||||
void validate_all(const EAXECHOPROPERTIES& all);
|
||||
|
||||
void defer_delay(float flDelay);
|
||||
void defer_lr_delay(float flLRDelay);
|
||||
void defer_damping(float flDamping);
|
||||
void defer_feedback(float flFeedback);
|
||||
void defer_spread(float flSpread);
|
||||
void defer_all(const EAXECHOPROPERTIES& all);
|
||||
|
||||
void defer_delay(const EaxEaxCall& eax_call);
|
||||
void defer_lr_delay(const EaxEaxCall& eax_call);
|
||||
void defer_damping(const EaxEaxCall& eax_call);
|
||||
void defer_feedback(const EaxEaxCall& eax_call);
|
||||
void defer_spread(const EaxEaxCall& eax_call);
|
||||
void defer_all(const EaxEaxCall& eax_call);
|
||||
|
||||
void set(const EaxEaxCall& eax_call);
|
||||
}; // EaxEchoEffect
|
||||
|
||||
|
||||
class EaxEchoEffectException :
|
||||
public EaxException
|
||||
{
|
||||
public:
|
||||
explicit EaxEchoEffectException(
|
||||
const char* message)
|
||||
:
|
||||
EaxException{"EAX_ECHO_EFFECT", message}
|
||||
struct DelayValidator {
|
||||
void operator()(float flDelay) const
|
||||
{
|
||||
eax_validate_range<EchoCommitter::Exception>(
|
||||
"Delay",
|
||||
flDelay,
|
||||
EAXECHO_MINDELAY,
|
||||
EAXECHO_MAXDELAY);
|
||||
}
|
||||
}; // EaxEchoEffectException
|
||||
}; // DelayValidator
|
||||
|
||||
|
||||
EaxEchoEffect::EaxEchoEffect()
|
||||
: EaxEffect{AL_EFFECT_ECHO}
|
||||
{
|
||||
set_eax_defaults();
|
||||
set_efx_defaults();
|
||||
}
|
||||
|
||||
void EaxEchoEffect::dispatch(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
eax_call.is_get() ? get(eax_call) : set(eax_call);
|
||||
}
|
||||
|
||||
void EaxEchoEffect::set_eax_defaults()
|
||||
{
|
||||
eax_.flDelay = EAXECHO_DEFAULTDELAY;
|
||||
eax_.flLRDelay = EAXECHO_DEFAULTLRDELAY;
|
||||
eax_.flDamping = EAXECHO_DEFAULTDAMPING;
|
||||
eax_.flFeedback = EAXECHO_DEFAULTFEEDBACK;
|
||||
eax_.flSpread = EAXECHO_DEFAULTSPREAD;
|
||||
|
||||
eax_d_ = eax_;
|
||||
}
|
||||
|
||||
void EaxEchoEffect::set_efx_delay()
|
||||
{
|
||||
const auto delay = clamp(
|
||||
eax_.flDelay,
|
||||
AL_ECHO_MIN_DELAY,
|
||||
AL_ECHO_MAX_DELAY);
|
||||
|
||||
al_effect_props_.Echo.Delay = delay;
|
||||
}
|
||||
|
||||
void EaxEchoEffect::set_efx_lr_delay()
|
||||
{
|
||||
const auto lr_delay = clamp(
|
||||
eax_.flLRDelay,
|
||||
AL_ECHO_MIN_LRDELAY,
|
||||
AL_ECHO_MAX_LRDELAY);
|
||||
|
||||
al_effect_props_.Echo.LRDelay = lr_delay;
|
||||
}
|
||||
|
||||
void EaxEchoEffect::set_efx_damping()
|
||||
{
|
||||
const auto damping = clamp(
|
||||
eax_.flDamping,
|
||||
AL_ECHO_MIN_DAMPING,
|
||||
AL_ECHO_MAX_DAMPING);
|
||||
|
||||
al_effect_props_.Echo.Damping = damping;
|
||||
}
|
||||
|
||||
void EaxEchoEffect::set_efx_feedback()
|
||||
{
|
||||
const auto feedback = clamp(
|
||||
eax_.flFeedback,
|
||||
AL_ECHO_MIN_FEEDBACK,
|
||||
AL_ECHO_MAX_FEEDBACK);
|
||||
|
||||
al_effect_props_.Echo.Feedback = feedback;
|
||||
}
|
||||
|
||||
void EaxEchoEffect::set_efx_spread()
|
||||
{
|
||||
const auto spread = clamp(
|
||||
eax_.flSpread,
|
||||
AL_ECHO_MIN_SPREAD,
|
||||
AL_ECHO_MAX_SPREAD);
|
||||
|
||||
al_effect_props_.Echo.Spread = spread;
|
||||
}
|
||||
|
||||
void EaxEchoEffect::set_efx_defaults()
|
||||
{
|
||||
set_efx_delay();
|
||||
set_efx_lr_delay();
|
||||
set_efx_damping();
|
||||
set_efx_feedback();
|
||||
set_efx_spread();
|
||||
}
|
||||
|
||||
void EaxEchoEffect::get(const EaxEaxCall& eax_call)
|
||||
{
|
||||
switch(eax_call.get_property_id())
|
||||
struct LrDelayValidator {
|
||||
void operator()(float flLRDelay) const
|
||||
{
|
||||
case EAXECHO_NONE:
|
||||
break;
|
||||
|
||||
case EAXECHO_ALLPARAMETERS:
|
||||
eax_call.set_value<EaxEchoEffectException>(eax_);
|
||||
break;
|
||||
|
||||
case EAXECHO_DELAY:
|
||||
eax_call.set_value<EaxEchoEffectException>(eax_.flDelay);
|
||||
break;
|
||||
|
||||
case EAXECHO_LRDELAY:
|
||||
eax_call.set_value<EaxEchoEffectException>(eax_.flLRDelay);
|
||||
break;
|
||||
|
||||
case EAXECHO_DAMPING:
|
||||
eax_call.set_value<EaxEchoEffectException>(eax_.flDamping);
|
||||
break;
|
||||
|
||||
case EAXECHO_FEEDBACK:
|
||||
eax_call.set_value<EaxEchoEffectException>(eax_.flFeedback);
|
||||
break;
|
||||
|
||||
case EAXECHO_SPREAD:
|
||||
eax_call.set_value<EaxEchoEffectException>(eax_.flSpread);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw EaxEchoEffectException{"Unsupported property id."};
|
||||
eax_validate_range<EchoCommitter::Exception>(
|
||||
"LR Delay",
|
||||
flLRDelay,
|
||||
EAXECHO_MINLRDELAY,
|
||||
EAXECHO_MAXLRDELAY);
|
||||
}
|
||||
}
|
||||
}; // LrDelayValidator
|
||||
|
||||
void EaxEchoEffect::validate_delay(
|
||||
float flDelay)
|
||||
{
|
||||
eax_validate_range<EaxEchoEffectException>(
|
||||
"Delay",
|
||||
flDelay,
|
||||
EAXECHO_MINDELAY,
|
||||
EAXECHO_MAXDELAY);
|
||||
}
|
||||
|
||||
void EaxEchoEffect::validate_lr_delay(
|
||||
float flLRDelay)
|
||||
{
|
||||
eax_validate_range<EaxEchoEffectException>(
|
||||
"LR Delay",
|
||||
flLRDelay,
|
||||
EAXECHO_MINLRDELAY,
|
||||
EAXECHO_MAXLRDELAY);
|
||||
}
|
||||
|
||||
void EaxEchoEffect::validate_damping(
|
||||
float flDamping)
|
||||
{
|
||||
eax_validate_range<EaxEchoEffectException>(
|
||||
"Damping",
|
||||
flDamping,
|
||||
EAXECHO_MINDAMPING,
|
||||
EAXECHO_MAXDAMPING);
|
||||
}
|
||||
|
||||
void EaxEchoEffect::validate_feedback(
|
||||
float flFeedback)
|
||||
{
|
||||
eax_validate_range<EaxEchoEffectException>(
|
||||
"Feedback",
|
||||
flFeedback,
|
||||
EAXECHO_MINFEEDBACK,
|
||||
EAXECHO_MAXFEEDBACK);
|
||||
}
|
||||
|
||||
void EaxEchoEffect::validate_spread(
|
||||
float flSpread)
|
||||
{
|
||||
eax_validate_range<EaxEchoEffectException>(
|
||||
"Spread",
|
||||
flSpread,
|
||||
EAXECHO_MINSPREAD,
|
||||
EAXECHO_MAXSPREAD);
|
||||
}
|
||||
|
||||
void EaxEchoEffect::validate_all(
|
||||
const EAXECHOPROPERTIES& all)
|
||||
{
|
||||
validate_delay(all.flDelay);
|
||||
validate_lr_delay(all.flLRDelay);
|
||||
validate_damping(all.flDamping);
|
||||
validate_feedback(all.flFeedback);
|
||||
validate_spread(all.flSpread);
|
||||
}
|
||||
|
||||
void EaxEchoEffect::defer_delay(
|
||||
float flDelay)
|
||||
{
|
||||
eax_d_.flDelay = flDelay;
|
||||
eax_dirty_flags_.flDelay = (eax_.flDelay != eax_d_.flDelay);
|
||||
}
|
||||
|
||||
void EaxEchoEffect::defer_lr_delay(
|
||||
float flLRDelay)
|
||||
{
|
||||
eax_d_.flLRDelay = flLRDelay;
|
||||
eax_dirty_flags_.flLRDelay = (eax_.flLRDelay != eax_d_.flLRDelay);
|
||||
}
|
||||
|
||||
void EaxEchoEffect::defer_damping(
|
||||
float flDamping)
|
||||
{
|
||||
eax_d_.flDamping = flDamping;
|
||||
eax_dirty_flags_.flDamping = (eax_.flDamping != eax_d_.flDamping);
|
||||
}
|
||||
|
||||
void EaxEchoEffect::defer_feedback(
|
||||
float flFeedback)
|
||||
{
|
||||
eax_d_.flFeedback = flFeedback;
|
||||
eax_dirty_flags_.flFeedback = (eax_.flFeedback != eax_d_.flFeedback);
|
||||
}
|
||||
|
||||
void EaxEchoEffect::defer_spread(
|
||||
float flSpread)
|
||||
{
|
||||
eax_d_.flSpread = flSpread;
|
||||
eax_dirty_flags_.flSpread = (eax_.flSpread != eax_d_.flSpread);
|
||||
}
|
||||
|
||||
void EaxEchoEffect::defer_all(
|
||||
const EAXECHOPROPERTIES& all)
|
||||
{
|
||||
defer_delay(all.flDelay);
|
||||
defer_lr_delay(all.flLRDelay);
|
||||
defer_damping(all.flDamping);
|
||||
defer_feedback(all.flFeedback);
|
||||
defer_spread(all.flSpread);
|
||||
}
|
||||
|
||||
void EaxEchoEffect::defer_delay(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& delay =
|
||||
eax_call.get_value<EaxEchoEffectException, const decltype(EAXECHOPROPERTIES::flDelay)>();
|
||||
|
||||
validate_delay(delay);
|
||||
defer_delay(delay);
|
||||
}
|
||||
|
||||
void EaxEchoEffect::defer_lr_delay(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& lr_delay =
|
||||
eax_call.get_value<EaxEchoEffectException, const decltype(EAXECHOPROPERTIES::flLRDelay)>();
|
||||
|
||||
validate_lr_delay(lr_delay);
|
||||
defer_lr_delay(lr_delay);
|
||||
}
|
||||
|
||||
void EaxEchoEffect::defer_damping(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& damping =
|
||||
eax_call.get_value<EaxEchoEffectException, const decltype(EAXECHOPROPERTIES::flDamping)>();
|
||||
|
||||
validate_damping(damping);
|
||||
defer_damping(damping);
|
||||
}
|
||||
|
||||
void EaxEchoEffect::defer_feedback(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& feedback =
|
||||
eax_call.get_value<EaxEchoEffectException, const decltype(EAXECHOPROPERTIES::flFeedback)>();
|
||||
|
||||
validate_feedback(feedback);
|
||||
defer_feedback(feedback);
|
||||
}
|
||||
|
||||
void EaxEchoEffect::defer_spread(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& spread =
|
||||
eax_call.get_value<EaxEchoEffectException, const decltype(EAXECHOPROPERTIES::flSpread)>();
|
||||
|
||||
validate_spread(spread);
|
||||
defer_spread(spread);
|
||||
}
|
||||
|
||||
void EaxEchoEffect::defer_all(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& all =
|
||||
eax_call.get_value<EaxEchoEffectException, const EAXECHOPROPERTIES>();
|
||||
|
||||
validate_all(all);
|
||||
defer_all(all);
|
||||
}
|
||||
|
||||
// [[nodiscard]]
|
||||
bool EaxEchoEffect::apply_deferred()
|
||||
{
|
||||
if (eax_dirty_flags_ == EaxEchoEffectDirtyFlags{})
|
||||
struct DampingValidator {
|
||||
void operator()(float flDamping) const
|
||||
{
|
||||
eax_validate_range<EchoCommitter::Exception>(
|
||||
"Damping",
|
||||
flDamping,
|
||||
EAXECHO_MINDAMPING,
|
||||
EAXECHO_MAXDAMPING);
|
||||
}
|
||||
}; // DampingValidator
|
||||
|
||||
struct FeedbackValidator {
|
||||
void operator()(float flFeedback) const
|
||||
{
|
||||
eax_validate_range<EchoCommitter::Exception>(
|
||||
"Feedback",
|
||||
flFeedback,
|
||||
EAXECHO_MINFEEDBACK,
|
||||
EAXECHO_MAXFEEDBACK);
|
||||
}
|
||||
}; // FeedbackValidator
|
||||
|
||||
struct SpreadValidator {
|
||||
void operator()(float flSpread) const
|
||||
{
|
||||
eax_validate_range<EchoCommitter::Exception>(
|
||||
"Spread",
|
||||
flSpread,
|
||||
EAXECHO_MINSPREAD,
|
||||
EAXECHO_MAXSPREAD);
|
||||
}
|
||||
}; // SpreadValidator
|
||||
|
||||
struct AllValidator {
|
||||
void operator()(const EAXECHOPROPERTIES& all) const
|
||||
{
|
||||
DelayValidator{}(all.flDelay);
|
||||
LrDelayValidator{}(all.flLRDelay);
|
||||
DampingValidator{}(all.flDamping);
|
||||
FeedbackValidator{}(all.flFeedback);
|
||||
SpreadValidator{}(all.flSpread);
|
||||
}
|
||||
}; // AllValidator
|
||||
|
||||
} // namespace
|
||||
|
||||
template<>
|
||||
struct EchoCommitter::Exception : public EaxException {
|
||||
explicit Exception(const char* message) : EaxException{"EAX_ECHO_EFFECT", message}
|
||||
{ }
|
||||
};
|
||||
|
||||
template<>
|
||||
[[noreturn]] void EchoCommitter::fail(const char *message)
|
||||
{
|
||||
throw Exception{message};
|
||||
}
|
||||
|
||||
bool EaxEchoCommitter::commit(const EAXECHOPROPERTIES &props)
|
||||
{
|
||||
if(auto *cur = std::get_if<EAXECHOPROPERTIES>(&mEaxProps); cur && *cur == props)
|
||||
return false;
|
||||
}
|
||||
|
||||
eax_ = eax_d_;
|
||||
|
||||
if (eax_dirty_flags_.flDelay)
|
||||
{
|
||||
set_efx_delay();
|
||||
}
|
||||
|
||||
if (eax_dirty_flags_.flLRDelay)
|
||||
{
|
||||
set_efx_lr_delay();
|
||||
}
|
||||
|
||||
if (eax_dirty_flags_.flDamping)
|
||||
{
|
||||
set_efx_damping();
|
||||
}
|
||||
|
||||
if (eax_dirty_flags_.flFeedback)
|
||||
{
|
||||
set_efx_feedback();
|
||||
}
|
||||
|
||||
if (eax_dirty_flags_.flSpread)
|
||||
{
|
||||
set_efx_spread();
|
||||
}
|
||||
|
||||
eax_dirty_flags_ = EaxEchoEffectDirtyFlags{};
|
||||
mEaxProps = props;
|
||||
mAlProps = [&]{
|
||||
EchoProps ret{};
|
||||
ret.Delay = props.flDelay;
|
||||
ret.LRDelay = props.flLRDelay;
|
||||
ret.Damping = props.flDamping;
|
||||
ret.Feedback = props.flFeedback;
|
||||
ret.Spread = props.flSpread;
|
||||
return ret;
|
||||
}();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void EaxEchoEffect::set(const EaxEaxCall& eax_call)
|
||||
void EaxEchoCommitter::SetDefaults(EaxEffectProps &props)
|
||||
{
|
||||
switch(eax_call.get_property_id())
|
||||
static constexpr EAXECHOPROPERTIES defprops{[]
|
||||
{
|
||||
case EAXECHO_NONE:
|
||||
break;
|
||||
EAXECHOPROPERTIES ret{};
|
||||
ret.flDelay = EAXECHO_DEFAULTDELAY;
|
||||
ret.flLRDelay = EAXECHO_DEFAULTLRDELAY;
|
||||
ret.flDamping = EAXECHO_DEFAULTDAMPING;
|
||||
ret.flFeedback = EAXECHO_DEFAULTFEEDBACK;
|
||||
ret.flSpread = EAXECHO_DEFAULTSPREAD;
|
||||
return ret;
|
||||
}()};
|
||||
props = defprops;
|
||||
}
|
||||
|
||||
case EAXECHO_ALLPARAMETERS:
|
||||
defer_all(eax_call);
|
||||
break;
|
||||
|
||||
case EAXECHO_DELAY:
|
||||
defer_delay(eax_call);
|
||||
break;
|
||||
|
||||
case EAXECHO_LRDELAY:
|
||||
defer_lr_delay(eax_call);
|
||||
break;
|
||||
|
||||
case EAXECHO_DAMPING:
|
||||
defer_damping(eax_call);
|
||||
break;
|
||||
|
||||
case EAXECHO_FEEDBACK:
|
||||
defer_feedback(eax_call);
|
||||
break;
|
||||
|
||||
case EAXECHO_SPREAD:
|
||||
defer_spread(eax_call);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw EaxEchoEffectException{"Unsupported property id."};
|
||||
void EaxEchoCommitter::Get(const EaxCall &call, const EAXECHOPROPERTIES &props)
|
||||
{
|
||||
switch(call.get_property_id())
|
||||
{
|
||||
case EAXECHO_NONE: break;
|
||||
case EAXECHO_ALLPARAMETERS: call.set_value<Exception>(props); break;
|
||||
case EAXECHO_DELAY: call.set_value<Exception>(props.flDelay); break;
|
||||
case EAXECHO_LRDELAY: call.set_value<Exception>(props.flLRDelay); break;
|
||||
case EAXECHO_DAMPING: call.set_value<Exception>(props.flDamping); break;
|
||||
case EAXECHO_FEEDBACK: call.set_value<Exception>(props.flFeedback); break;
|
||||
case EAXECHO_SPREAD: call.set_value<Exception>(props.flSpread); break;
|
||||
default: fail_unknown_property_id();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
EaxEffectUPtr eax_create_eax_echo_effect()
|
||||
void EaxEchoCommitter::Set(const EaxCall &call, EAXECHOPROPERTIES &props)
|
||||
{
|
||||
return std::make_unique<EaxEchoEffect>();
|
||||
switch(call.get_property_id())
|
||||
{
|
||||
case EAXECHO_NONE: break;
|
||||
case EAXECHO_ALLPARAMETERS: defer<AllValidator>(call, props); break;
|
||||
case EAXECHO_DELAY: defer<DelayValidator>(call, props.flDelay); break;
|
||||
case EAXECHO_LRDELAY: defer<LrDelayValidator>(call, props.flLRDelay); break;
|
||||
case EAXECHO_DAMPING: defer<DampingValidator>(call, props.flDamping); break;
|
||||
case EAXECHO_FEEDBACK: defer<FeedbackValidator>(call, props.flFeedback); break;
|
||||
case EAXECHO_SPREAD: defer<SpreadValidator>(call, props.flSpread); break;
|
||||
default: fail_unknown_property_id();
|
||||
}
|
||||
}
|
||||
|
||||
#endif // ALSOFT_EAX
|
||||
|
||||
@@ -1,66 +1,3 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifdef ALSOFT_EAX
|
||||
|
||||
#include "effects.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include "AL/efx.h"
|
||||
|
||||
|
||||
EaxEffectUPtr eax_create_eax_effect(ALenum al_effect_type)
|
||||
{
|
||||
#define EAX_PREFIX "[EAX_MAKE_EAX_EFFECT] "
|
||||
|
||||
switch (al_effect_type)
|
||||
{
|
||||
case AL_EFFECT_NULL:
|
||||
return eax_create_eax_null_effect();
|
||||
|
||||
case AL_EFFECT_CHORUS:
|
||||
return eax_create_eax_chorus_effect();
|
||||
|
||||
case AL_EFFECT_DISTORTION:
|
||||
return eax_create_eax_distortion_effect();
|
||||
|
||||
case AL_EFFECT_ECHO:
|
||||
return eax_create_eax_echo_effect();
|
||||
|
||||
case AL_EFFECT_FLANGER:
|
||||
return eax_create_eax_flanger_effect();
|
||||
|
||||
case AL_EFFECT_FREQUENCY_SHIFTER:
|
||||
return eax_create_eax_frequency_shifter_effect();
|
||||
|
||||
case AL_EFFECT_VOCAL_MORPHER:
|
||||
return eax_create_eax_vocal_morpher_effect();
|
||||
|
||||
case AL_EFFECT_PITCH_SHIFTER:
|
||||
return eax_create_eax_pitch_shifter_effect();
|
||||
|
||||
case AL_EFFECT_RING_MODULATOR:
|
||||
return eax_create_eax_ring_modulator_effect();
|
||||
|
||||
case AL_EFFECT_AUTOWAH:
|
||||
return eax_create_eax_auto_wah_effect();
|
||||
|
||||
case AL_EFFECT_COMPRESSOR:
|
||||
return eax_create_eax_compressor_effect();
|
||||
|
||||
case AL_EFFECT_EQUALIZER:
|
||||
return eax_create_eax_equalizer_effect();
|
||||
|
||||
case AL_EFFECT_EAXREVERB:
|
||||
return eax_create_eax_reverb_effect();
|
||||
|
||||
default:
|
||||
assert(false && "Unsupported AL effect type.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#undef EAX_PREFIX
|
||||
}
|
||||
|
||||
#endif // ALSOFT_EAX
|
||||
|
||||
@@ -1,51 +1,54 @@
|
||||
#ifndef AL_EFFECTS_EFFECTS_H
|
||||
#define AL_EFFECTS_EFFECTS_H
|
||||
|
||||
#include <variant>
|
||||
|
||||
#include "AL/al.h"
|
||||
|
||||
#include "core/except.h"
|
||||
|
||||
#ifdef ALSOFT_EAX
|
||||
#include "al/eax_effect.h"
|
||||
#endif // ALSOFT_EAX
|
||||
|
||||
union EffectProps;
|
||||
#include "al/error.h"
|
||||
#include "core/effects/base.h"
|
||||
|
||||
|
||||
class effect_exception final : public al::base_exception {
|
||||
ALenum mErrorCode;
|
||||
struct EffectHandler {
|
||||
#define DECL_HANDLER(T) \
|
||||
static void SetParami(T &props, ALenum param, int val); \
|
||||
static void SetParamiv(T &props, ALenum param, const int *vals); \
|
||||
static void SetParamf(T &props, ALenum param, float val); \
|
||||
static void SetParamfv(T &props, ALenum param, const float *vals); \
|
||||
static void GetParami(const T &props, ALenum param, int *val); \
|
||||
static void GetParamiv(const T &props, ALenum param, int *vals); \
|
||||
static void GetParamf(const T &props, ALenum param, float *val); \
|
||||
static void GetParamfv(const T &props, ALenum param, float *vals);
|
||||
|
||||
public:
|
||||
#ifdef __USE_MINGW_ANSI_STDIO
|
||||
[[gnu::format(gnu_printf, 3, 4)]]
|
||||
#else
|
||||
[[gnu::format(printf, 3, 4)]]
|
||||
#endif
|
||||
effect_exception(ALenum code, const char *msg, ...);
|
||||
DECL_HANDLER(std::monostate)
|
||||
DECL_HANDLER(ReverbProps)
|
||||
DECL_HANDLER(ChorusProps)
|
||||
DECL_HANDLER(AutowahProps)
|
||||
DECL_HANDLER(CompressorProps)
|
||||
DECL_HANDLER(ConvolutionProps)
|
||||
DECL_HANDLER(DedicatedDialogProps)
|
||||
DECL_HANDLER(DedicatedLfeProps)
|
||||
DECL_HANDLER(DistortionProps)
|
||||
DECL_HANDLER(EchoProps)
|
||||
DECL_HANDLER(EqualizerProps)
|
||||
DECL_HANDLER(FlangerProps)
|
||||
DECL_HANDLER(FshifterProps)
|
||||
DECL_HANDLER(ModulatorProps)
|
||||
DECL_HANDLER(PshifterProps)
|
||||
DECL_HANDLER(VmorpherProps)
|
||||
#undef DECL_HANDLER
|
||||
|
||||
ALenum errorCode() const noexcept { return mErrorCode; }
|
||||
static void StdReverbSetParami(ReverbProps &props, ALenum param, int val);
|
||||
static void StdReverbSetParamiv(ReverbProps &props, ALenum param, const int *vals);
|
||||
static void StdReverbSetParamf(ReverbProps &props, ALenum param, float val);
|
||||
static void StdReverbSetParamfv(ReverbProps &props, ALenum param, const float *vals);
|
||||
static void StdReverbGetParami(const ReverbProps &props, ALenum param, int *val);
|
||||
static void StdReverbGetParamiv(const ReverbProps &props, ALenum param, int *vals);
|
||||
static void StdReverbGetParamf(const ReverbProps &props, ALenum param, float *val);
|
||||
static void StdReverbGetParamfv(const ReverbProps &props, ALenum param, float *vals);
|
||||
};
|
||||
|
||||
|
||||
struct EffectVtable {
|
||||
void (*const setParami)(EffectProps *props, ALenum param, int val);
|
||||
void (*const setParamiv)(EffectProps *props, ALenum param, const int *vals);
|
||||
void (*const setParamf)(EffectProps *props, ALenum param, float val);
|
||||
void (*const setParamfv)(EffectProps *props, ALenum param, const float *vals);
|
||||
|
||||
void (*const getParami)(const EffectProps *props, ALenum param, int *val);
|
||||
void (*const getParamiv)(const EffectProps *props, ALenum param, int *vals);
|
||||
void (*const getParamf)(const EffectProps *props, ALenum param, float *val);
|
||||
void (*const getParamfv)(const EffectProps *props, ALenum param, float *vals);
|
||||
};
|
||||
|
||||
#define DEFINE_ALEFFECT_VTABLE(T) \
|
||||
const EffectVtable T##EffectVtable = { \
|
||||
T##_setParami, T##_setParamiv, \
|
||||
T##_setParamf, T##_setParamfv, \
|
||||
T##_getParami, T##_getParamiv, \
|
||||
T##_getParamf, T##_getParamfv, \
|
||||
}
|
||||
using effect_exception = al::context_error;
|
||||
|
||||
|
||||
/* Default properties for the given effect types. */
|
||||
@@ -63,30 +66,8 @@ extern const EffectProps FshifterEffectProps;
|
||||
extern const EffectProps ModulatorEffectProps;
|
||||
extern const EffectProps PshifterEffectProps;
|
||||
extern const EffectProps VmorpherEffectProps;
|
||||
extern const EffectProps DedicatedEffectProps;
|
||||
extern const EffectProps DedicatedDialogEffectProps;
|
||||
extern const EffectProps DedicatedLfeEffectProps;
|
||||
extern const EffectProps ConvolutionEffectProps;
|
||||
|
||||
/* Vtables to get/set properties for the given effect types. */
|
||||
extern const EffectVtable NullEffectVtable;
|
||||
extern const EffectVtable ReverbEffectVtable;
|
||||
extern const EffectVtable StdReverbEffectVtable;
|
||||
extern const EffectVtable AutowahEffectVtable;
|
||||
extern const EffectVtable ChorusEffectVtable;
|
||||
extern const EffectVtable CompressorEffectVtable;
|
||||
extern const EffectVtable DistortionEffectVtable;
|
||||
extern const EffectVtable EchoEffectVtable;
|
||||
extern const EffectVtable EqualizerEffectVtable;
|
||||
extern const EffectVtable FlangerEffectVtable;
|
||||
extern const EffectVtable FshifterEffectVtable;
|
||||
extern const EffectVtable ModulatorEffectVtable;
|
||||
extern const EffectVtable PshifterEffectVtable;
|
||||
extern const EffectVtable VmorpherEffectVtable;
|
||||
extern const EffectVtable DedicatedEffectVtable;
|
||||
extern const EffectVtable ConvolutionEffectVtable;
|
||||
|
||||
|
||||
#ifdef ALSOFT_EAX
|
||||
EaxEffectUPtr eax_create_eax_effect(ALenum al_effect_type);
|
||||
#endif // ALSOFT_EAX
|
||||
|
||||
#endif /* AL_EFFECTS_EFFECTS_H */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,38 +1,37 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <optional>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "AL/al.h"
|
||||
#include "AL/efx.h"
|
||||
|
||||
#include "alc/effects/base.h"
|
||||
#include "aloptional.h"
|
||||
#include "effects.h"
|
||||
|
||||
#ifdef ALSOFT_EAX
|
||||
#include <cassert>
|
||||
|
||||
#include "alnumeric.h"
|
||||
|
||||
#include "al/eax_exception.h"
|
||||
#include "al/eax_utils.h"
|
||||
#include "al/eax/effect.h"
|
||||
#include "al/eax/exception.h"
|
||||
#include "al/eax/utils.h"
|
||||
#endif // ALSOFT_EAX
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
al::optional<FShifterDirection> DirectionFromEmum(ALenum value)
|
||||
constexpr std::optional<FShifterDirection> DirectionFromEmum(ALenum value) noexcept
|
||||
{
|
||||
switch(value)
|
||||
{
|
||||
case AL_FREQUENCY_SHIFTER_DIRECTION_DOWN: return al::make_optional(FShifterDirection::Down);
|
||||
case AL_FREQUENCY_SHIFTER_DIRECTION_UP: return al::make_optional(FShifterDirection::Up);
|
||||
case AL_FREQUENCY_SHIFTER_DIRECTION_OFF: return al::make_optional(FShifterDirection::Off);
|
||||
case AL_FREQUENCY_SHIFTER_DIRECTION_DOWN: return FShifterDirection::Down;
|
||||
case AL_FREQUENCY_SHIFTER_DIRECTION_UP: return FShifterDirection::Up;
|
||||
case AL_FREQUENCY_SHIFTER_DIRECTION_OFF: return FShifterDirection::Off;
|
||||
}
|
||||
return al::nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
ALenum EnumFromDirection(FShifterDirection dir)
|
||||
constexpr ALenum EnumFromDirection(FShifterDirection dir)
|
||||
{
|
||||
switch(dir)
|
||||
{
|
||||
@@ -43,31 +42,26 @@ ALenum EnumFromDirection(FShifterDirection dir)
|
||||
throw std::runtime_error{"Invalid direction: "+std::to_string(static_cast<int>(dir))};
|
||||
}
|
||||
|
||||
void Fshifter_setParamf(EffectProps *props, ALenum param, float val)
|
||||
constexpr EffectProps genDefaultProps() noexcept
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case AL_FREQUENCY_SHIFTER_FREQUENCY:
|
||||
if(!(val >= AL_FREQUENCY_SHIFTER_MIN_FREQUENCY && val <= AL_FREQUENCY_SHIFTER_MAX_FREQUENCY))
|
||||
throw effect_exception{AL_INVALID_VALUE, "Frequency shifter frequency out of range"};
|
||||
props->Fshifter.Frequency = val;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid frequency shifter float property 0x%04x",
|
||||
param};
|
||||
}
|
||||
FshifterProps props{};
|
||||
props.Frequency = AL_FREQUENCY_SHIFTER_DEFAULT_FREQUENCY;
|
||||
props.LeftDirection = DirectionFromEmum(AL_FREQUENCY_SHIFTER_DEFAULT_LEFT_DIRECTION).value();
|
||||
props.RightDirection = DirectionFromEmum(AL_FREQUENCY_SHIFTER_DEFAULT_RIGHT_DIRECTION).value();
|
||||
return props;
|
||||
}
|
||||
void Fshifter_setParamfv(EffectProps *props, ALenum param, const float *vals)
|
||||
{ Fshifter_setParamf(props, param, vals[0]); }
|
||||
|
||||
void Fshifter_setParami(EffectProps *props, ALenum param, int val)
|
||||
} // namespace
|
||||
|
||||
const EffectProps FshifterEffectProps{genDefaultProps()};
|
||||
|
||||
void EffectHandler::SetParami(FshifterProps &props, ALenum param, int val)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case AL_FREQUENCY_SHIFTER_LEFT_DIRECTION:
|
||||
if(auto diropt = DirectionFromEmum(val))
|
||||
props->Fshifter.LeftDirection = *diropt;
|
||||
props.LeftDirection = *diropt;
|
||||
else
|
||||
throw effect_exception{AL_INVALID_VALUE,
|
||||
"Unsupported frequency shifter left direction: 0x%04x", val};
|
||||
@@ -75,7 +69,7 @@ void Fshifter_setParami(EffectProps *props, ALenum param, int val)
|
||||
|
||||
case AL_FREQUENCY_SHIFTER_RIGHT_DIRECTION:
|
||||
if(auto diropt = DirectionFromEmum(val))
|
||||
props->Fshifter.RightDirection = *diropt;
|
||||
props.RightDirection = *diropt;
|
||||
else
|
||||
throw effect_exception{AL_INVALID_VALUE,
|
||||
"Unsupported frequency shifter right direction: 0x%04x", val};
|
||||
@@ -86,33 +80,17 @@ void Fshifter_setParami(EffectProps *props, ALenum param, int val)
|
||||
"Invalid frequency shifter integer property 0x%04x", param};
|
||||
}
|
||||
}
|
||||
void Fshifter_setParamiv(EffectProps *props, ALenum param, const int *vals)
|
||||
{ Fshifter_setParami(props, param, vals[0]); }
|
||||
void EffectHandler::SetParamiv(FshifterProps &props, ALenum param, const int *vals)
|
||||
{ SetParami(props, param, *vals); }
|
||||
|
||||
void Fshifter_getParami(const EffectProps *props, ALenum param, int *val)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case AL_FREQUENCY_SHIFTER_LEFT_DIRECTION:
|
||||
*val = EnumFromDirection(props->Fshifter.LeftDirection);
|
||||
break;
|
||||
case AL_FREQUENCY_SHIFTER_RIGHT_DIRECTION:
|
||||
*val = EnumFromDirection(props->Fshifter.RightDirection);
|
||||
break;
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM,
|
||||
"Invalid frequency shifter integer property 0x%04x", param};
|
||||
}
|
||||
}
|
||||
void Fshifter_getParamiv(const EffectProps *props, ALenum param, int *vals)
|
||||
{ Fshifter_getParami(props, param, vals); }
|
||||
|
||||
void Fshifter_getParamf(const EffectProps *props, ALenum param, float *val)
|
||||
void EffectHandler::SetParamf(FshifterProps &props, ALenum param, float val)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case AL_FREQUENCY_SHIFTER_FREQUENCY:
|
||||
*val = props->Fshifter.Frequency;
|
||||
if(!(val >= AL_FREQUENCY_SHIFTER_MIN_FREQUENCY && val <= AL_FREQUENCY_SHIFTER_MAX_FREQUENCY))
|
||||
throw effect_exception{AL_INVALID_VALUE, "Frequency shifter frequency out of range"};
|
||||
props.Frequency = val;
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -120,360 +98,170 @@ void Fshifter_getParamf(const EffectProps *props, ALenum param, float *val)
|
||||
param};
|
||||
}
|
||||
}
|
||||
void Fshifter_getParamfv(const EffectProps *props, ALenum param, float *vals)
|
||||
{ Fshifter_getParamf(props, param, vals); }
|
||||
void EffectHandler::SetParamfv(FshifterProps &props, ALenum param, const float *vals)
|
||||
{ SetParamf(props, param, *vals); }
|
||||
|
||||
EffectProps genDefaultProps() noexcept
|
||||
void EffectHandler::GetParami(const FshifterProps &props, ALenum param, int *val)
|
||||
{
|
||||
EffectProps props{};
|
||||
props.Fshifter.Frequency = AL_FREQUENCY_SHIFTER_DEFAULT_FREQUENCY;
|
||||
props.Fshifter.LeftDirection = *DirectionFromEmum(AL_FREQUENCY_SHIFTER_DEFAULT_LEFT_DIRECTION);
|
||||
props.Fshifter.RightDirection = *DirectionFromEmum(AL_FREQUENCY_SHIFTER_DEFAULT_RIGHT_DIRECTION);
|
||||
return props;
|
||||
switch(param)
|
||||
{
|
||||
case AL_FREQUENCY_SHIFTER_LEFT_DIRECTION:
|
||||
*val = EnumFromDirection(props.LeftDirection);
|
||||
break;
|
||||
case AL_FREQUENCY_SHIFTER_RIGHT_DIRECTION:
|
||||
*val = EnumFromDirection(props.RightDirection);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM,
|
||||
"Invalid frequency shifter integer property 0x%04x", param};
|
||||
}
|
||||
}
|
||||
void EffectHandler::GetParamiv(const FshifterProps &props, ALenum param, int *vals)
|
||||
{ GetParami(props, param, vals); }
|
||||
|
||||
} // namespace
|
||||
void EffectHandler::GetParamf(const FshifterProps &props, ALenum param, float *val)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case AL_FREQUENCY_SHIFTER_FREQUENCY:
|
||||
*val = props.Frequency;
|
||||
break;
|
||||
|
||||
DEFINE_ALEFFECT_VTABLE(Fshifter);
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid frequency shifter float property 0x%04x",
|
||||
param};
|
||||
}
|
||||
}
|
||||
void EffectHandler::GetParamfv(const FshifterProps &props, ALenum param, float *vals)
|
||||
{ GetParamf(props, param, vals); }
|
||||
|
||||
const EffectProps FshifterEffectProps{genDefaultProps()};
|
||||
|
||||
#ifdef ALSOFT_EAX
|
||||
namespace {
|
||||
|
||||
using EaxFrequencyShifterEffectDirtyFlagsValue = std::uint_least8_t;
|
||||
using FrequencyShifterCommitter = EaxCommitter<EaxFrequencyShifterCommitter>;
|
||||
|
||||
struct EaxFrequencyShifterEffectDirtyFlags
|
||||
{
|
||||
using EaxIsBitFieldStruct = bool;
|
||||
|
||||
EaxFrequencyShifterEffectDirtyFlagsValue flFrequency : 1;
|
||||
EaxFrequencyShifterEffectDirtyFlagsValue ulLeftDirection : 1;
|
||||
EaxFrequencyShifterEffectDirtyFlagsValue ulRightDirection : 1;
|
||||
}; // EaxFrequencyShifterEffectDirtyFlags
|
||||
|
||||
|
||||
class EaxFrequencyShifterEffect final :
|
||||
public EaxEffect
|
||||
{
|
||||
public:
|
||||
EaxFrequencyShifterEffect();
|
||||
|
||||
void dispatch(const EaxEaxCall& eax_call) override;
|
||||
|
||||
// [[nodiscard]]
|
||||
bool apply_deferred() override;
|
||||
|
||||
private:
|
||||
EAXFREQUENCYSHIFTERPROPERTIES eax_{};
|
||||
EAXFREQUENCYSHIFTERPROPERTIES eax_d_{};
|
||||
EaxFrequencyShifterEffectDirtyFlags eax_dirty_flags_{};
|
||||
|
||||
void set_eax_defaults();
|
||||
|
||||
void set_efx_frequency();
|
||||
void set_efx_left_direction();
|
||||
void set_efx_right_direction();
|
||||
void set_efx_defaults();
|
||||
|
||||
void get(const EaxEaxCall& eax_call);
|
||||
|
||||
void validate_frequency(float flFrequency);
|
||||
void validate_left_direction(unsigned long ulLeftDirection);
|
||||
void validate_right_direction(unsigned long ulRightDirection);
|
||||
void validate_all(const EAXFREQUENCYSHIFTERPROPERTIES& all);
|
||||
|
||||
void defer_frequency(float flFrequency);
|
||||
void defer_left_direction(unsigned long ulLeftDirection);
|
||||
void defer_right_direction(unsigned long ulRightDirection);
|
||||
void defer_all(const EAXFREQUENCYSHIFTERPROPERTIES& all);
|
||||
|
||||
void defer_frequency(const EaxEaxCall& eax_call);
|
||||
void defer_left_direction(const EaxEaxCall& eax_call);
|
||||
void defer_right_direction(const EaxEaxCall& eax_call);
|
||||
void defer_all(const EaxEaxCall& eax_call);
|
||||
|
||||
void set(const EaxEaxCall& eax_call);
|
||||
}; // EaxFrequencyShifterEffect
|
||||
|
||||
|
||||
class EaxFrequencyShifterEffectException :
|
||||
public EaxException
|
||||
{
|
||||
public:
|
||||
explicit EaxFrequencyShifterEffectException(
|
||||
const char* message)
|
||||
:
|
||||
EaxException{"EAX_FREQUENCY_SHIFTER_EFFECT", message}
|
||||
struct FrequencyValidator {
|
||||
void operator()(float flFrequency) const
|
||||
{
|
||||
eax_validate_range<FrequencyShifterCommitter::Exception>(
|
||||
"Frequency",
|
||||
flFrequency,
|
||||
EAXFREQUENCYSHIFTER_MINFREQUENCY,
|
||||
EAXFREQUENCYSHIFTER_MAXFREQUENCY);
|
||||
}
|
||||
}; // EaxFrequencyShifterEffectException
|
||||
}; // FrequencyValidator
|
||||
|
||||
|
||||
EaxFrequencyShifterEffect::EaxFrequencyShifterEffect()
|
||||
: EaxEffect{AL_EFFECT_FREQUENCY_SHIFTER}
|
||||
{
|
||||
set_eax_defaults();
|
||||
set_efx_defaults();
|
||||
}
|
||||
|
||||
void EaxFrequencyShifterEffect::dispatch(const EaxEaxCall& eax_call)
|
||||
{
|
||||
eax_call.is_get() ? get(eax_call) : set(eax_call);
|
||||
}
|
||||
|
||||
void EaxFrequencyShifterEffect::set_eax_defaults()
|
||||
{
|
||||
eax_.flFrequency = EAXFREQUENCYSHIFTER_DEFAULTFREQUENCY;
|
||||
eax_.ulLeftDirection = EAXFREQUENCYSHIFTER_DEFAULTLEFTDIRECTION;
|
||||
eax_.ulRightDirection = EAXFREQUENCYSHIFTER_DEFAULTRIGHTDIRECTION;
|
||||
|
||||
eax_d_ = eax_;
|
||||
}
|
||||
|
||||
void EaxFrequencyShifterEffect::set_efx_frequency()
|
||||
{
|
||||
const auto frequency = clamp(
|
||||
eax_.flFrequency,
|
||||
AL_FREQUENCY_SHIFTER_MIN_FREQUENCY,
|
||||
AL_FREQUENCY_SHIFTER_MAX_FREQUENCY);
|
||||
|
||||
al_effect_props_.Fshifter.Frequency = frequency;
|
||||
}
|
||||
|
||||
void EaxFrequencyShifterEffect::set_efx_left_direction()
|
||||
{
|
||||
const auto left_direction = clamp(
|
||||
static_cast<ALint>(eax_.ulLeftDirection),
|
||||
AL_FREQUENCY_SHIFTER_MIN_LEFT_DIRECTION,
|
||||
AL_FREQUENCY_SHIFTER_MAX_LEFT_DIRECTION);
|
||||
|
||||
const auto efx_left_direction = DirectionFromEmum(left_direction);
|
||||
assert(efx_left_direction.has_value());
|
||||
al_effect_props_.Fshifter.LeftDirection = *efx_left_direction;
|
||||
}
|
||||
|
||||
void EaxFrequencyShifterEffect::set_efx_right_direction()
|
||||
{
|
||||
const auto right_direction = clamp(
|
||||
static_cast<ALint>(eax_.ulRightDirection),
|
||||
AL_FREQUENCY_SHIFTER_MIN_RIGHT_DIRECTION,
|
||||
AL_FREQUENCY_SHIFTER_MAX_RIGHT_DIRECTION);
|
||||
|
||||
const auto efx_right_direction = DirectionFromEmum(right_direction);
|
||||
assert(efx_right_direction.has_value());
|
||||
al_effect_props_.Fshifter.RightDirection = *efx_right_direction;
|
||||
}
|
||||
|
||||
void EaxFrequencyShifterEffect::set_efx_defaults()
|
||||
{
|
||||
set_efx_frequency();
|
||||
set_efx_left_direction();
|
||||
set_efx_right_direction();
|
||||
}
|
||||
|
||||
void EaxFrequencyShifterEffect::get(const EaxEaxCall& eax_call)
|
||||
{
|
||||
switch(eax_call.get_property_id())
|
||||
struct LeftDirectionValidator {
|
||||
void operator()(unsigned long ulLeftDirection) const
|
||||
{
|
||||
case EAXFREQUENCYSHIFTER_NONE:
|
||||
break;
|
||||
|
||||
case EAXFREQUENCYSHIFTER_ALLPARAMETERS:
|
||||
eax_call.set_value<EaxFrequencyShifterEffectException>(eax_);
|
||||
break;
|
||||
|
||||
case EAXFREQUENCYSHIFTER_FREQUENCY:
|
||||
eax_call.set_value<EaxFrequencyShifterEffectException>(eax_.flFrequency);
|
||||
break;
|
||||
|
||||
case EAXFREQUENCYSHIFTER_LEFTDIRECTION:
|
||||
eax_call.set_value<EaxFrequencyShifterEffectException>(eax_.ulLeftDirection);
|
||||
break;
|
||||
|
||||
case EAXFREQUENCYSHIFTER_RIGHTDIRECTION:
|
||||
eax_call.set_value<EaxFrequencyShifterEffectException>(eax_.ulRightDirection);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw EaxFrequencyShifterEffectException{"Unsupported property id."};
|
||||
eax_validate_range<FrequencyShifterCommitter::Exception>(
|
||||
"Left Direction",
|
||||
ulLeftDirection,
|
||||
EAXFREQUENCYSHIFTER_MINLEFTDIRECTION,
|
||||
EAXFREQUENCYSHIFTER_MAXLEFTDIRECTION);
|
||||
}
|
||||
}
|
||||
}; // LeftDirectionValidator
|
||||
|
||||
void EaxFrequencyShifterEffect::validate_frequency(
|
||||
float flFrequency)
|
||||
{
|
||||
eax_validate_range<EaxFrequencyShifterEffectException>(
|
||||
"Frequency",
|
||||
flFrequency,
|
||||
EAXFREQUENCYSHIFTER_MINFREQUENCY,
|
||||
EAXFREQUENCYSHIFTER_MAXFREQUENCY);
|
||||
}
|
||||
|
||||
void EaxFrequencyShifterEffect::validate_left_direction(
|
||||
unsigned long ulLeftDirection)
|
||||
{
|
||||
eax_validate_range<EaxFrequencyShifterEffectException>(
|
||||
"Left Direction",
|
||||
ulLeftDirection,
|
||||
EAXFREQUENCYSHIFTER_MINLEFTDIRECTION,
|
||||
EAXFREQUENCYSHIFTER_MAXLEFTDIRECTION);
|
||||
}
|
||||
|
||||
void EaxFrequencyShifterEffect::validate_right_direction(
|
||||
unsigned long ulRightDirection)
|
||||
{
|
||||
eax_validate_range<EaxFrequencyShifterEffectException>(
|
||||
"Right Direction",
|
||||
ulRightDirection,
|
||||
EAXFREQUENCYSHIFTER_MINRIGHTDIRECTION,
|
||||
EAXFREQUENCYSHIFTER_MAXRIGHTDIRECTION);
|
||||
}
|
||||
|
||||
void EaxFrequencyShifterEffect::validate_all(
|
||||
const EAXFREQUENCYSHIFTERPROPERTIES& all)
|
||||
{
|
||||
validate_frequency(all.flFrequency);
|
||||
validate_left_direction(all.ulLeftDirection);
|
||||
validate_right_direction(all.ulRightDirection);
|
||||
}
|
||||
|
||||
void EaxFrequencyShifterEffect::defer_frequency(
|
||||
float flFrequency)
|
||||
{
|
||||
eax_d_.flFrequency = flFrequency;
|
||||
eax_dirty_flags_.flFrequency = (eax_.flFrequency != eax_d_.flFrequency);
|
||||
}
|
||||
|
||||
void EaxFrequencyShifterEffect::defer_left_direction(
|
||||
unsigned long ulLeftDirection)
|
||||
{
|
||||
eax_d_.ulLeftDirection = ulLeftDirection;
|
||||
eax_dirty_flags_.ulLeftDirection = (eax_.ulLeftDirection != eax_d_.ulLeftDirection);
|
||||
}
|
||||
|
||||
void EaxFrequencyShifterEffect::defer_right_direction(
|
||||
unsigned long ulRightDirection)
|
||||
{
|
||||
eax_d_.ulRightDirection = ulRightDirection;
|
||||
eax_dirty_flags_.ulRightDirection = (eax_.ulRightDirection != eax_d_.ulRightDirection);
|
||||
}
|
||||
|
||||
void EaxFrequencyShifterEffect::defer_all(
|
||||
const EAXFREQUENCYSHIFTERPROPERTIES& all)
|
||||
{
|
||||
defer_frequency(all.flFrequency);
|
||||
defer_left_direction(all.ulLeftDirection);
|
||||
defer_right_direction(all.ulRightDirection);
|
||||
}
|
||||
|
||||
void EaxFrequencyShifterEffect::defer_frequency(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& frequency =
|
||||
eax_call.get_value<
|
||||
EaxFrequencyShifterEffectException, const decltype(EAXFREQUENCYSHIFTERPROPERTIES::flFrequency)>();
|
||||
|
||||
validate_frequency(frequency);
|
||||
defer_frequency(frequency);
|
||||
}
|
||||
|
||||
void EaxFrequencyShifterEffect::defer_left_direction(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& left_direction =
|
||||
eax_call.get_value<
|
||||
EaxFrequencyShifterEffectException, const decltype(EAXFREQUENCYSHIFTERPROPERTIES::ulLeftDirection)>();
|
||||
|
||||
validate_left_direction(left_direction);
|
||||
defer_left_direction(left_direction);
|
||||
}
|
||||
|
||||
void EaxFrequencyShifterEffect::defer_right_direction(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& right_direction =
|
||||
eax_call.get_value<
|
||||
EaxFrequencyShifterEffectException, const decltype(EAXFREQUENCYSHIFTERPROPERTIES::ulRightDirection)>();
|
||||
|
||||
validate_right_direction(right_direction);
|
||||
defer_right_direction(right_direction);
|
||||
}
|
||||
|
||||
void EaxFrequencyShifterEffect::defer_all(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& all =
|
||||
eax_call.get_value<
|
||||
EaxFrequencyShifterEffectException, const EAXFREQUENCYSHIFTERPROPERTIES>();
|
||||
|
||||
validate_all(all);
|
||||
defer_all(all);
|
||||
}
|
||||
|
||||
// [[nodiscard]]
|
||||
bool EaxFrequencyShifterEffect::apply_deferred()
|
||||
{
|
||||
if (eax_dirty_flags_ == EaxFrequencyShifterEffectDirtyFlags{})
|
||||
struct RightDirectionValidator {
|
||||
void operator()(unsigned long ulRightDirection) const
|
||||
{
|
||||
eax_validate_range<FrequencyShifterCommitter::Exception>(
|
||||
"Right Direction",
|
||||
ulRightDirection,
|
||||
EAXFREQUENCYSHIFTER_MINRIGHTDIRECTION,
|
||||
EAXFREQUENCYSHIFTER_MAXRIGHTDIRECTION);
|
||||
}
|
||||
}; // RightDirectionValidator
|
||||
|
||||
struct AllValidator {
|
||||
void operator()(const EAXFREQUENCYSHIFTERPROPERTIES& all) const
|
||||
{
|
||||
FrequencyValidator{}(all.flFrequency);
|
||||
LeftDirectionValidator{}(all.ulLeftDirection);
|
||||
RightDirectionValidator{}(all.ulRightDirection);
|
||||
}
|
||||
}; // AllValidator
|
||||
|
||||
} // namespace
|
||||
|
||||
template<>
|
||||
struct FrequencyShifterCommitter::Exception : public EaxException {
|
||||
explicit Exception(const char *message) : EaxException{"EAX_FREQUENCY_SHIFTER_EFFECT", message}
|
||||
{ }
|
||||
};
|
||||
|
||||
template<>
|
||||
[[noreturn]] void FrequencyShifterCommitter::fail(const char *message)
|
||||
{
|
||||
throw Exception{message};
|
||||
}
|
||||
|
||||
bool EaxFrequencyShifterCommitter::commit(const EAXFREQUENCYSHIFTERPROPERTIES &props)
|
||||
{
|
||||
if(auto *cur = std::get_if<EAXFREQUENCYSHIFTERPROPERTIES>(&mEaxProps); cur && *cur == props)
|
||||
return false;
|
||||
}
|
||||
|
||||
eax_ = eax_d_;
|
||||
mEaxProps = props;
|
||||
|
||||
if (eax_dirty_flags_.flFrequency)
|
||||
auto get_direction = [](unsigned long dir) noexcept
|
||||
{
|
||||
set_efx_frequency();
|
||||
}
|
||||
if(dir == EAX_FREQUENCYSHIFTER_DOWN)
|
||||
return FShifterDirection::Down;
|
||||
if(dir == EAX_FREQUENCYSHIFTER_UP)
|
||||
return FShifterDirection::Up;
|
||||
return FShifterDirection::Off;
|
||||
};
|
||||
|
||||
if (eax_dirty_flags_.ulLeftDirection)
|
||||
{
|
||||
set_efx_left_direction();
|
||||
}
|
||||
|
||||
if (eax_dirty_flags_.ulRightDirection)
|
||||
{
|
||||
set_efx_right_direction();
|
||||
}
|
||||
|
||||
eax_dirty_flags_ = EaxFrequencyShifterEffectDirtyFlags{};
|
||||
mAlProps = [&]{
|
||||
FshifterProps ret{};
|
||||
ret.Frequency = props.flFrequency;
|
||||
ret.LeftDirection = get_direction(props.ulLeftDirection);
|
||||
ret.RightDirection = get_direction(props.ulRightDirection);
|
||||
return ret;
|
||||
}();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void EaxFrequencyShifterEffect::set(const EaxEaxCall& eax_call)
|
||||
void EaxFrequencyShifterCommitter::SetDefaults(EaxEffectProps &props)
|
||||
{
|
||||
switch(eax_call.get_property_id())
|
||||
static constexpr EAXFREQUENCYSHIFTERPROPERTIES defprops{[]
|
||||
{
|
||||
case EAXFREQUENCYSHIFTER_NONE:
|
||||
break;
|
||||
EAXFREQUENCYSHIFTERPROPERTIES ret{};
|
||||
ret.flFrequency = EAXFREQUENCYSHIFTER_DEFAULTFREQUENCY;
|
||||
ret.ulLeftDirection = EAXFREQUENCYSHIFTER_DEFAULTLEFTDIRECTION;
|
||||
ret.ulRightDirection = EAXFREQUENCYSHIFTER_DEFAULTRIGHTDIRECTION;
|
||||
return ret;
|
||||
}()};
|
||||
props = defprops;
|
||||
}
|
||||
|
||||
case EAXFREQUENCYSHIFTER_ALLPARAMETERS:
|
||||
defer_all(eax_call);
|
||||
break;
|
||||
|
||||
case EAXFREQUENCYSHIFTER_FREQUENCY:
|
||||
defer_frequency(eax_call);
|
||||
break;
|
||||
|
||||
case EAXFREQUENCYSHIFTER_LEFTDIRECTION:
|
||||
defer_left_direction(eax_call);
|
||||
break;
|
||||
|
||||
case EAXFREQUENCYSHIFTER_RIGHTDIRECTION:
|
||||
defer_right_direction(eax_call);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw EaxFrequencyShifterEffectException{"Unsupported property id."};
|
||||
void EaxFrequencyShifterCommitter::Get(const EaxCall &call, const EAXFREQUENCYSHIFTERPROPERTIES &props)
|
||||
{
|
||||
switch(call.get_property_id())
|
||||
{
|
||||
case EAXFREQUENCYSHIFTER_NONE: break;
|
||||
case EAXFREQUENCYSHIFTER_ALLPARAMETERS: call.set_value<Exception>(props); break;
|
||||
case EAXFREQUENCYSHIFTER_FREQUENCY: call.set_value<Exception>(props.flFrequency); break;
|
||||
case EAXFREQUENCYSHIFTER_LEFTDIRECTION: call.set_value<Exception>(props.ulLeftDirection); break;
|
||||
case EAXFREQUENCYSHIFTER_RIGHTDIRECTION: call.set_value<Exception>(props.ulRightDirection); break;
|
||||
default: fail_unknown_property_id();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
EaxEffectUPtr eax_create_eax_frequency_shifter_effect()
|
||||
void EaxFrequencyShifterCommitter::Set(const EaxCall &call, EAXFREQUENCYSHIFTERPROPERTIES &props)
|
||||
{
|
||||
return std::make_unique<EaxFrequencyShifterEffect>();
|
||||
switch(call.get_property_id())
|
||||
{
|
||||
case EAXFREQUENCYSHIFTER_NONE: break;
|
||||
case EAXFREQUENCYSHIFTER_ALLPARAMETERS: defer<AllValidator>(call, props); break;
|
||||
case EAXFREQUENCYSHIFTER_FREQUENCY: defer<FrequencyValidator>(call, props.flFrequency); break;
|
||||
case EAXFREQUENCYSHIFTER_LEFTDIRECTION: defer<LeftDirectionValidator>(call, props.ulLeftDirection); break;
|
||||
case EAXFREQUENCYSHIFTER_RIGHTDIRECTION: defer<RightDirectionValidator>(call, props.ulRightDirection); break;
|
||||
default: fail_unknown_property_id();
|
||||
}
|
||||
}
|
||||
|
||||
#endif // ALSOFT_EAX
|
||||
|
||||
@@ -1,38 +1,37 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <optional>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "AL/al.h"
|
||||
#include "AL/efx.h"
|
||||
|
||||
#include "alc/effects/base.h"
|
||||
#include "aloptional.h"
|
||||
#include "effects.h"
|
||||
|
||||
#ifdef ALSOFT_EAX
|
||||
#include <cassert>
|
||||
|
||||
#include "alnumeric.h"
|
||||
|
||||
#include "al/eax_exception.h"
|
||||
#include "al/eax_utils.h"
|
||||
#include "al/eax/effect.h"
|
||||
#include "al/eax/exception.h"
|
||||
#include "al/eax/utils.h"
|
||||
#endif // ALSOFT_EAX
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
al::optional<ModulatorWaveform> WaveformFromEmum(ALenum value)
|
||||
constexpr std::optional<ModulatorWaveform> WaveformFromEmum(ALenum value) noexcept
|
||||
{
|
||||
switch(value)
|
||||
{
|
||||
case AL_RING_MODULATOR_SINUSOID: return al::make_optional(ModulatorWaveform::Sinusoid);
|
||||
case AL_RING_MODULATOR_SAWTOOTH: return al::make_optional(ModulatorWaveform::Sawtooth);
|
||||
case AL_RING_MODULATOR_SQUARE: return al::make_optional(ModulatorWaveform::Square);
|
||||
case AL_RING_MODULATOR_SINUSOID: return ModulatorWaveform::Sinusoid;
|
||||
case AL_RING_MODULATOR_SAWTOOTH: return ModulatorWaveform::Sawtooth;
|
||||
case AL_RING_MODULATOR_SQUARE: return ModulatorWaveform::Square;
|
||||
}
|
||||
return al::nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
ALenum EnumFromWaveform(ModulatorWaveform type)
|
||||
constexpr ALenum EnumFromWaveform(ModulatorWaveform type)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
@@ -44,40 +43,31 @@ ALenum EnumFromWaveform(ModulatorWaveform type)
|
||||
std::to_string(static_cast<int>(type))};
|
||||
}
|
||||
|
||||
void Modulator_setParamf(EffectProps *props, ALenum param, float val)
|
||||
constexpr EffectProps genDefaultProps() noexcept
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case AL_RING_MODULATOR_FREQUENCY:
|
||||
if(!(val >= AL_RING_MODULATOR_MIN_FREQUENCY && val <= AL_RING_MODULATOR_MAX_FREQUENCY))
|
||||
throw effect_exception{AL_INVALID_VALUE, "Modulator frequency out of range: %f", val};
|
||||
props->Modulator.Frequency = val;
|
||||
break;
|
||||
|
||||
case AL_RING_MODULATOR_HIGHPASS_CUTOFF:
|
||||
if(!(val >= AL_RING_MODULATOR_MIN_HIGHPASS_CUTOFF && val <= AL_RING_MODULATOR_MAX_HIGHPASS_CUTOFF))
|
||||
throw effect_exception{AL_INVALID_VALUE, "Modulator high-pass cutoff out of range: %f", val};
|
||||
props->Modulator.HighPassCutoff = val;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid modulator float property 0x%04x", param};
|
||||
}
|
||||
ModulatorProps props{};
|
||||
props.Frequency = AL_RING_MODULATOR_DEFAULT_FREQUENCY;
|
||||
props.HighPassCutoff = AL_RING_MODULATOR_DEFAULT_HIGHPASS_CUTOFF;
|
||||
props.Waveform = WaveformFromEmum(AL_RING_MODULATOR_DEFAULT_WAVEFORM).value();
|
||||
return props;
|
||||
}
|
||||
void Modulator_setParamfv(EffectProps *props, ALenum param, const float *vals)
|
||||
{ Modulator_setParamf(props, param, vals[0]); }
|
||||
void Modulator_setParami(EffectProps *props, ALenum param, int val)
|
||||
|
||||
} // namespace
|
||||
|
||||
const EffectProps ModulatorEffectProps{genDefaultProps()};
|
||||
|
||||
void EffectHandler::SetParami(ModulatorProps &props, ALenum param, int val)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case AL_RING_MODULATOR_FREQUENCY:
|
||||
case AL_RING_MODULATOR_HIGHPASS_CUTOFF:
|
||||
Modulator_setParamf(props, param, static_cast<float>(val));
|
||||
SetParamf(props, param, static_cast<float>(val));
|
||||
break;
|
||||
|
||||
case AL_RING_MODULATOR_WAVEFORM:
|
||||
if(auto formopt = WaveformFromEmum(val))
|
||||
props->Modulator.Waveform = *formopt;
|
||||
props.Waveform = *formopt;
|
||||
else
|
||||
throw effect_exception{AL_INVALID_VALUE, "Invalid modulator waveform: 0x%04x", val};
|
||||
break;
|
||||
@@ -87,396 +77,189 @@ void Modulator_setParami(EffectProps *props, ALenum param, int val)
|
||||
param};
|
||||
}
|
||||
}
|
||||
void Modulator_setParamiv(EffectProps *props, ALenum param, const int *vals)
|
||||
{ Modulator_setParami(props, param, vals[0]); }
|
||||
void EffectHandler::SetParamiv(ModulatorProps &props, ALenum param, const int *vals)
|
||||
{ SetParami(props, param, *vals); }
|
||||
|
||||
void Modulator_getParami(const EffectProps *props, ALenum param, int *val)
|
||||
void EffectHandler::SetParamf(ModulatorProps &props, ALenum param, float val)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case AL_RING_MODULATOR_FREQUENCY:
|
||||
*val = static_cast<int>(props->Modulator.Frequency);
|
||||
break;
|
||||
case AL_RING_MODULATOR_HIGHPASS_CUTOFF:
|
||||
*val = static_cast<int>(props->Modulator.HighPassCutoff);
|
||||
break;
|
||||
case AL_RING_MODULATOR_WAVEFORM:
|
||||
*val = EnumFromWaveform(props->Modulator.Waveform);
|
||||
if(!(val >= AL_RING_MODULATOR_MIN_FREQUENCY && val <= AL_RING_MODULATOR_MAX_FREQUENCY))
|
||||
throw effect_exception{AL_INVALID_VALUE, "Modulator frequency out of range: %f", val};
|
||||
props.Frequency = val;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid modulator integer property 0x%04x",
|
||||
param};
|
||||
}
|
||||
}
|
||||
void Modulator_getParamiv(const EffectProps *props, ALenum param, int *vals)
|
||||
{ Modulator_getParami(props, param, vals); }
|
||||
void Modulator_getParamf(const EffectProps *props, ALenum param, float *val)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case AL_RING_MODULATOR_FREQUENCY:
|
||||
*val = props->Modulator.Frequency;
|
||||
break;
|
||||
case AL_RING_MODULATOR_HIGHPASS_CUTOFF:
|
||||
*val = props->Modulator.HighPassCutoff;
|
||||
if(!(val >= AL_RING_MODULATOR_MIN_HIGHPASS_CUTOFF && val <= AL_RING_MODULATOR_MAX_HIGHPASS_CUTOFF))
|
||||
throw effect_exception{AL_INVALID_VALUE, "Modulator high-pass cutoff out of range: %f", val};
|
||||
props.HighPassCutoff = val;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid modulator float property 0x%04x", param};
|
||||
}
|
||||
}
|
||||
void Modulator_getParamfv(const EffectProps *props, ALenum param, float *vals)
|
||||
{ Modulator_getParamf(props, param, vals); }
|
||||
void EffectHandler::SetParamfv(ModulatorProps &props, ALenum param, const float *vals)
|
||||
{ SetParamf(props, param, *vals); }
|
||||
|
||||
EffectProps genDefaultProps() noexcept
|
||||
void EffectHandler::GetParami(const ModulatorProps &props, ALenum param, int *val)
|
||||
{
|
||||
EffectProps props{};
|
||||
props.Modulator.Frequency = AL_RING_MODULATOR_DEFAULT_FREQUENCY;
|
||||
props.Modulator.HighPassCutoff = AL_RING_MODULATOR_DEFAULT_HIGHPASS_CUTOFF;
|
||||
props.Modulator.Waveform = *WaveformFromEmum(AL_RING_MODULATOR_DEFAULT_WAVEFORM);
|
||||
return props;
|
||||
switch(param)
|
||||
{
|
||||
case AL_RING_MODULATOR_FREQUENCY: *val = static_cast<int>(props.Frequency); break;
|
||||
case AL_RING_MODULATOR_HIGHPASS_CUTOFF: *val = static_cast<int>(props.HighPassCutoff); break;
|
||||
case AL_RING_MODULATOR_WAVEFORM: *val = EnumFromWaveform(props.Waveform); break;
|
||||
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid modulator integer property 0x%04x",
|
||||
param};
|
||||
}
|
||||
}
|
||||
void EffectHandler::GetParamiv(const ModulatorProps &props, ALenum param, int *vals)
|
||||
{ GetParami(props, param, vals); }
|
||||
void EffectHandler::GetParamf(const ModulatorProps &props, ALenum param, float *val)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case AL_RING_MODULATOR_FREQUENCY: *val = props.Frequency; break;
|
||||
case AL_RING_MODULATOR_HIGHPASS_CUTOFF: *val = props.HighPassCutoff; break;
|
||||
|
||||
} // namespace
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid modulator float property 0x%04x", param};
|
||||
}
|
||||
}
|
||||
void EffectHandler::GetParamfv(const ModulatorProps &props, ALenum param, float *vals)
|
||||
{ GetParamf(props, param, vals); }
|
||||
|
||||
DEFINE_ALEFFECT_VTABLE(Modulator);
|
||||
|
||||
const EffectProps ModulatorEffectProps{genDefaultProps()};
|
||||
|
||||
#ifdef ALSOFT_EAX
|
||||
namespace {
|
||||
|
||||
using EaxRingModulatorEffectDirtyFlagsValue = std::uint_least8_t;
|
||||
using ModulatorCommitter = EaxCommitter<EaxModulatorCommitter>;
|
||||
|
||||
struct EaxRingModulatorEffectDirtyFlags
|
||||
{
|
||||
using EaxIsBitFieldStruct = bool;
|
||||
|
||||
EaxRingModulatorEffectDirtyFlagsValue flFrequency : 1;
|
||||
EaxRingModulatorEffectDirtyFlagsValue flHighPassCutOff : 1;
|
||||
EaxRingModulatorEffectDirtyFlagsValue ulWaveform : 1;
|
||||
}; // EaxPitchShifterEffectDirtyFlags
|
||||
|
||||
|
||||
class EaxRingModulatorEffect final :
|
||||
public EaxEffect
|
||||
{
|
||||
public:
|
||||
EaxRingModulatorEffect();
|
||||
|
||||
void dispatch(const EaxEaxCall& eax_call) override;
|
||||
|
||||
// [[nodiscard]]
|
||||
bool apply_deferred() override;
|
||||
|
||||
private:
|
||||
EAXRINGMODULATORPROPERTIES eax_{};
|
||||
EAXRINGMODULATORPROPERTIES eax_d_{};
|
||||
EaxRingModulatorEffectDirtyFlags eax_dirty_flags_{};
|
||||
|
||||
void set_eax_defaults();
|
||||
|
||||
void set_efx_frequency();
|
||||
void set_efx_high_pass_cutoff();
|
||||
void set_efx_waveform();
|
||||
void set_efx_defaults();
|
||||
|
||||
void get(const EaxEaxCall& eax_call);
|
||||
|
||||
void validate_frequency(float flFrequency);
|
||||
void validate_high_pass_cutoff(float flHighPassCutOff);
|
||||
void validate_waveform(unsigned long ulWaveform);
|
||||
void validate_all(const EAXRINGMODULATORPROPERTIES& all);
|
||||
|
||||
void defer_frequency(float flFrequency);
|
||||
void defer_high_pass_cutoff(float flHighPassCutOff);
|
||||
void defer_waveform(unsigned long ulWaveform);
|
||||
void defer_all(const EAXRINGMODULATORPROPERTIES& all);
|
||||
|
||||
void defer_frequency(const EaxEaxCall& eax_call);
|
||||
void defer_high_pass_cutoff(const EaxEaxCall& eax_call);
|
||||
void defer_waveform(const EaxEaxCall& eax_call);
|
||||
void defer_all(const EaxEaxCall& eax_call);
|
||||
|
||||
void set(const EaxEaxCall& eax_call);
|
||||
}; // EaxRingModulatorEffect
|
||||
|
||||
|
||||
class EaxRingModulatorEffectException :
|
||||
public EaxException
|
||||
{
|
||||
public:
|
||||
explicit EaxRingModulatorEffectException(
|
||||
const char* message)
|
||||
:
|
||||
EaxException{"EAX_RING_MODULATOR_EFFECT", message}
|
||||
struct FrequencyValidator {
|
||||
void operator()(float flFrequency) const
|
||||
{
|
||||
eax_validate_range<ModulatorCommitter::Exception>(
|
||||
"Frequency",
|
||||
flFrequency,
|
||||
EAXRINGMODULATOR_MINFREQUENCY,
|
||||
EAXRINGMODULATOR_MAXFREQUENCY);
|
||||
}
|
||||
}; // EaxRingModulatorEffectException
|
||||
}; // FrequencyValidator
|
||||
|
||||
|
||||
EaxRingModulatorEffect::EaxRingModulatorEffect()
|
||||
: EaxEffect{AL_EFFECT_RING_MODULATOR}
|
||||
{
|
||||
set_eax_defaults();
|
||||
set_efx_defaults();
|
||||
}
|
||||
|
||||
void EaxRingModulatorEffect::dispatch(const EaxEaxCall& eax_call)
|
||||
{
|
||||
eax_call.is_get() ? get(eax_call) : set(eax_call);
|
||||
}
|
||||
|
||||
void EaxRingModulatorEffect::set_eax_defaults()
|
||||
{
|
||||
eax_.flFrequency = EAXRINGMODULATOR_DEFAULTFREQUENCY;
|
||||
eax_.flHighPassCutOff = EAXRINGMODULATOR_DEFAULTHIGHPASSCUTOFF;
|
||||
eax_.ulWaveform = EAXRINGMODULATOR_DEFAULTWAVEFORM;
|
||||
|
||||
eax_d_ = eax_;
|
||||
}
|
||||
|
||||
void EaxRingModulatorEffect::set_efx_frequency()
|
||||
{
|
||||
const auto frequency = clamp(
|
||||
eax_.flFrequency,
|
||||
AL_RING_MODULATOR_MIN_FREQUENCY,
|
||||
AL_RING_MODULATOR_MAX_FREQUENCY);
|
||||
|
||||
al_effect_props_.Modulator.Frequency = frequency;
|
||||
}
|
||||
|
||||
void EaxRingModulatorEffect::set_efx_high_pass_cutoff()
|
||||
{
|
||||
const auto high_pass_cutoff = clamp(
|
||||
eax_.flHighPassCutOff,
|
||||
AL_RING_MODULATOR_MIN_HIGHPASS_CUTOFF,
|
||||
AL_RING_MODULATOR_MAX_HIGHPASS_CUTOFF);
|
||||
|
||||
al_effect_props_.Modulator.HighPassCutoff = high_pass_cutoff;
|
||||
}
|
||||
|
||||
void EaxRingModulatorEffect::set_efx_waveform()
|
||||
{
|
||||
const auto waveform = clamp(
|
||||
static_cast<ALint>(eax_.ulWaveform),
|
||||
AL_RING_MODULATOR_MIN_WAVEFORM,
|
||||
AL_RING_MODULATOR_MAX_WAVEFORM);
|
||||
|
||||
const auto efx_waveform = WaveformFromEmum(waveform);
|
||||
assert(efx_waveform.has_value());
|
||||
al_effect_props_.Modulator.Waveform = *efx_waveform;
|
||||
}
|
||||
|
||||
void EaxRingModulatorEffect::set_efx_defaults()
|
||||
{
|
||||
set_efx_frequency();
|
||||
set_efx_high_pass_cutoff();
|
||||
set_efx_waveform();
|
||||
}
|
||||
|
||||
void EaxRingModulatorEffect::get(const EaxEaxCall& eax_call)
|
||||
{
|
||||
switch(eax_call.get_property_id())
|
||||
struct HighPassCutOffValidator {
|
||||
void operator()(float flHighPassCutOff) const
|
||||
{
|
||||
case EAXRINGMODULATOR_NONE:
|
||||
break;
|
||||
|
||||
case EAXRINGMODULATOR_ALLPARAMETERS:
|
||||
eax_call.set_value<EaxRingModulatorEffectException>(eax_);
|
||||
break;
|
||||
|
||||
case EAXRINGMODULATOR_FREQUENCY:
|
||||
eax_call.set_value<EaxRingModulatorEffectException>(eax_.flFrequency);
|
||||
break;
|
||||
|
||||
case EAXRINGMODULATOR_HIGHPASSCUTOFF:
|
||||
eax_call.set_value<EaxRingModulatorEffectException>(eax_.flHighPassCutOff);
|
||||
break;
|
||||
|
||||
case EAXRINGMODULATOR_WAVEFORM:
|
||||
eax_call.set_value<EaxRingModulatorEffectException>(eax_.ulWaveform);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw EaxRingModulatorEffectException{"Unsupported property id."};
|
||||
eax_validate_range<ModulatorCommitter::Exception>(
|
||||
"High-Pass Cutoff",
|
||||
flHighPassCutOff,
|
||||
EAXRINGMODULATOR_MINHIGHPASSCUTOFF,
|
||||
EAXRINGMODULATOR_MAXHIGHPASSCUTOFF);
|
||||
}
|
||||
}
|
||||
}; // HighPassCutOffValidator
|
||||
|
||||
void EaxRingModulatorEffect::validate_frequency(
|
||||
float flFrequency)
|
||||
{
|
||||
eax_validate_range<EaxRingModulatorEffectException>(
|
||||
"Frequency",
|
||||
flFrequency,
|
||||
EAXRINGMODULATOR_MINFREQUENCY,
|
||||
EAXRINGMODULATOR_MAXFREQUENCY);
|
||||
}
|
||||
|
||||
void EaxRingModulatorEffect::validate_high_pass_cutoff(
|
||||
float flHighPassCutOff)
|
||||
{
|
||||
eax_validate_range<EaxRingModulatorEffectException>(
|
||||
"High-Pass Cutoff",
|
||||
flHighPassCutOff,
|
||||
EAXRINGMODULATOR_MINHIGHPASSCUTOFF,
|
||||
EAXRINGMODULATOR_MAXHIGHPASSCUTOFF);
|
||||
}
|
||||
|
||||
void EaxRingModulatorEffect::validate_waveform(
|
||||
unsigned long ulWaveform)
|
||||
{
|
||||
eax_validate_range<EaxRingModulatorEffectException>(
|
||||
"Waveform",
|
||||
ulWaveform,
|
||||
EAXRINGMODULATOR_MINWAVEFORM,
|
||||
EAXRINGMODULATOR_MAXWAVEFORM);
|
||||
}
|
||||
|
||||
void EaxRingModulatorEffect::validate_all(
|
||||
const EAXRINGMODULATORPROPERTIES& all)
|
||||
{
|
||||
validate_frequency(all.flFrequency);
|
||||
validate_high_pass_cutoff(all.flHighPassCutOff);
|
||||
validate_waveform(all.ulWaveform);
|
||||
}
|
||||
|
||||
void EaxRingModulatorEffect::defer_frequency(
|
||||
float flFrequency)
|
||||
{
|
||||
eax_d_.flFrequency = flFrequency;
|
||||
eax_dirty_flags_.flFrequency = (eax_.flFrequency != eax_d_.flFrequency);
|
||||
}
|
||||
|
||||
void EaxRingModulatorEffect::defer_high_pass_cutoff(
|
||||
float flHighPassCutOff)
|
||||
{
|
||||
eax_d_.flHighPassCutOff = flHighPassCutOff;
|
||||
eax_dirty_flags_.flHighPassCutOff = (eax_.flHighPassCutOff != eax_d_.flHighPassCutOff);
|
||||
}
|
||||
|
||||
void EaxRingModulatorEffect::defer_waveform(
|
||||
unsigned long ulWaveform)
|
||||
{
|
||||
eax_d_.ulWaveform = ulWaveform;
|
||||
eax_dirty_flags_.ulWaveform = (eax_.ulWaveform != eax_d_.ulWaveform);
|
||||
}
|
||||
|
||||
void EaxRingModulatorEffect::defer_all(
|
||||
const EAXRINGMODULATORPROPERTIES& all)
|
||||
{
|
||||
defer_frequency(all.flFrequency);
|
||||
defer_high_pass_cutoff(all.flHighPassCutOff);
|
||||
defer_waveform(all.ulWaveform);
|
||||
}
|
||||
|
||||
void EaxRingModulatorEffect::defer_frequency(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& frequency =
|
||||
eax_call.get_value<
|
||||
EaxRingModulatorEffectException, const decltype(EAXRINGMODULATORPROPERTIES::flFrequency)>();
|
||||
|
||||
validate_frequency(frequency);
|
||||
defer_frequency(frequency);
|
||||
}
|
||||
|
||||
void EaxRingModulatorEffect::defer_high_pass_cutoff(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& high_pass_cutoff =
|
||||
eax_call.get_value<
|
||||
EaxRingModulatorEffectException, const decltype(EAXRINGMODULATORPROPERTIES::flHighPassCutOff)>();
|
||||
|
||||
validate_high_pass_cutoff(high_pass_cutoff);
|
||||
defer_high_pass_cutoff(high_pass_cutoff);
|
||||
}
|
||||
|
||||
void EaxRingModulatorEffect::defer_waveform(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& waveform =
|
||||
eax_call.get_value<
|
||||
EaxRingModulatorEffectException, const decltype(EAXRINGMODULATORPROPERTIES::ulWaveform)>();
|
||||
|
||||
validate_waveform(waveform);
|
||||
defer_waveform(waveform);
|
||||
}
|
||||
|
||||
void EaxRingModulatorEffect::defer_all(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& all =
|
||||
eax_call.get_value<EaxRingModulatorEffectException, const EAXRINGMODULATORPROPERTIES>();
|
||||
|
||||
validate_all(all);
|
||||
defer_all(all);
|
||||
}
|
||||
|
||||
// [[nodiscard]]
|
||||
bool EaxRingModulatorEffect::apply_deferred()
|
||||
{
|
||||
if (eax_dirty_flags_ == EaxRingModulatorEffectDirtyFlags{})
|
||||
struct WaveformValidator {
|
||||
void operator()(unsigned long ulWaveform) const
|
||||
{
|
||||
eax_validate_range<ModulatorCommitter::Exception>(
|
||||
"Waveform",
|
||||
ulWaveform,
|
||||
EAXRINGMODULATOR_MINWAVEFORM,
|
||||
EAXRINGMODULATOR_MAXWAVEFORM);
|
||||
}
|
||||
}; // WaveformValidator
|
||||
|
||||
struct AllValidator {
|
||||
void operator()(const EAXRINGMODULATORPROPERTIES& all) const
|
||||
{
|
||||
FrequencyValidator{}(all.flFrequency);
|
||||
HighPassCutOffValidator{}(all.flHighPassCutOff);
|
||||
WaveformValidator{}(all.ulWaveform);
|
||||
}
|
||||
}; // AllValidator
|
||||
|
||||
} // namespace
|
||||
|
||||
template<>
|
||||
struct ModulatorCommitter::Exception : public EaxException {
|
||||
explicit Exception(const char *message) : EaxException{"EAX_RING_MODULATOR_EFFECT", message}
|
||||
{ }
|
||||
};
|
||||
|
||||
template<>
|
||||
[[noreturn]] void ModulatorCommitter::fail(const char *message)
|
||||
{
|
||||
throw Exception{message};
|
||||
}
|
||||
|
||||
bool EaxModulatorCommitter::commit(const EAXRINGMODULATORPROPERTIES &props)
|
||||
{
|
||||
if(auto *cur = std::get_if<EAXRINGMODULATORPROPERTIES>(&mEaxProps); cur && *cur == props)
|
||||
return false;
|
||||
}
|
||||
|
||||
eax_ = eax_d_;
|
||||
mEaxProps = props;
|
||||
|
||||
if (eax_dirty_flags_.flFrequency)
|
||||
auto get_waveform = [](unsigned long form)
|
||||
{
|
||||
set_efx_frequency();
|
||||
}
|
||||
if(form == EAX_RINGMODULATOR_SINUSOID)
|
||||
return ModulatorWaveform::Sinusoid;
|
||||
if(form == EAX_RINGMODULATOR_SAWTOOTH)
|
||||
return ModulatorWaveform::Sawtooth;
|
||||
if(form == EAX_RINGMODULATOR_SQUARE)
|
||||
return ModulatorWaveform::Square;
|
||||
return ModulatorWaveform::Sinusoid;
|
||||
};
|
||||
|
||||
if (eax_dirty_flags_.flHighPassCutOff)
|
||||
{
|
||||
set_efx_high_pass_cutoff();
|
||||
}
|
||||
|
||||
if (eax_dirty_flags_.ulWaveform)
|
||||
{
|
||||
set_efx_waveform();
|
||||
}
|
||||
|
||||
eax_dirty_flags_ = EaxRingModulatorEffectDirtyFlags{};
|
||||
mAlProps = [&]{
|
||||
ModulatorProps ret{};
|
||||
ret.Frequency = props.flFrequency;
|
||||
ret.HighPassCutoff = props.flHighPassCutOff;
|
||||
ret.Waveform = get_waveform(props.ulWaveform);
|
||||
return ret;
|
||||
}();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void EaxRingModulatorEffect::set(const EaxEaxCall& eax_call)
|
||||
void EaxModulatorCommitter::SetDefaults(EaxEffectProps &props)
|
||||
{
|
||||
switch (eax_call.get_property_id())
|
||||
static constexpr EAXRINGMODULATORPROPERTIES defprops{[]
|
||||
{
|
||||
case EAXRINGMODULATOR_NONE:
|
||||
break;
|
||||
EAXRINGMODULATORPROPERTIES ret{};
|
||||
ret.flFrequency = EAXRINGMODULATOR_DEFAULTFREQUENCY;
|
||||
ret.flHighPassCutOff = EAXRINGMODULATOR_DEFAULTHIGHPASSCUTOFF;
|
||||
ret.ulWaveform = EAXRINGMODULATOR_DEFAULTWAVEFORM;
|
||||
return ret;
|
||||
}()};
|
||||
props = defprops;
|
||||
}
|
||||
|
||||
case EAXRINGMODULATOR_ALLPARAMETERS:
|
||||
defer_all(eax_call);
|
||||
break;
|
||||
|
||||
case EAXRINGMODULATOR_FREQUENCY:
|
||||
defer_frequency(eax_call);
|
||||
break;
|
||||
|
||||
case EAXRINGMODULATOR_HIGHPASSCUTOFF:
|
||||
defer_high_pass_cutoff(eax_call);
|
||||
break;
|
||||
|
||||
case EAXRINGMODULATOR_WAVEFORM:
|
||||
defer_waveform(eax_call);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw EaxRingModulatorEffectException{"Unsupported property id."};
|
||||
void EaxModulatorCommitter::Get(const EaxCall &call, const EAXRINGMODULATORPROPERTIES &props)
|
||||
{
|
||||
switch(call.get_property_id())
|
||||
{
|
||||
case EAXRINGMODULATOR_NONE: break;
|
||||
case EAXRINGMODULATOR_ALLPARAMETERS: call.set_value<Exception>(props); break;
|
||||
case EAXRINGMODULATOR_FREQUENCY: call.set_value<Exception>(props.flFrequency); break;
|
||||
case EAXRINGMODULATOR_HIGHPASSCUTOFF: call.set_value<Exception>(props.flHighPassCutOff); break;
|
||||
case EAXRINGMODULATOR_WAVEFORM: call.set_value<Exception>(props.ulWaveform); break;
|
||||
default: fail_unknown_property_id();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
EaxEffectUPtr eax_create_eax_ring_modulator_effect()
|
||||
void EaxModulatorCommitter::Set(const EaxCall &call, EAXRINGMODULATORPROPERTIES &props)
|
||||
{
|
||||
return std::make_unique<EaxRingModulatorEffect>();
|
||||
switch(call.get_property_id())
|
||||
{
|
||||
case EAXRINGMODULATOR_NONE: break;
|
||||
case EAXRINGMODULATOR_ALLPARAMETERS: defer<AllValidator>(call, props); break;
|
||||
case EAXRINGMODULATOR_FREQUENCY: defer<FrequencyValidator>(call, props.flFrequency); break;
|
||||
case EAXRINGMODULATOR_HIGHPASSCUTOFF: defer<HighPassCutOffValidator>(call, props.flHighPassCutOff); break;
|
||||
case EAXRINGMODULATOR_WAVEFORM: defer<WaveformValidator>(call, props.ulWaveform); break;
|
||||
default: fail_unknown_property_id();
|
||||
}
|
||||
}
|
||||
|
||||
#endif // ALSOFT_EAX
|
||||
|
||||
@@ -8,145 +8,136 @@
|
||||
#include "effects.h"
|
||||
|
||||
#ifdef ALSOFT_EAX
|
||||
#include "al/eax_exception.h"
|
||||
#include "al/eax/effect.h"
|
||||
#include "al/eax/exception.h"
|
||||
#endif // ALSOFT_EAX
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
void Null_setParami(EffectProps* /*props*/, ALenum param, int /*val*/)
|
||||
constexpr EffectProps genDefaultProps() noexcept
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid null effect integer property 0x%04x",
|
||||
param};
|
||||
}
|
||||
}
|
||||
void Null_setParamiv(EffectProps *props, ALenum param, const int *vals)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
Null_setParami(props, param, vals[0]);
|
||||
}
|
||||
}
|
||||
void Null_setParamf(EffectProps* /*props*/, ALenum param, float /*val*/)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid null effect float property 0x%04x",
|
||||
param};
|
||||
}
|
||||
}
|
||||
void Null_setParamfv(EffectProps *props, ALenum param, const float *vals)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
Null_setParamf(props, param, vals[0]);
|
||||
}
|
||||
}
|
||||
|
||||
void Null_getParami(const EffectProps* /*props*/, ALenum param, int* /*val*/)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid null effect integer property 0x%04x",
|
||||
param};
|
||||
}
|
||||
}
|
||||
void Null_getParamiv(const EffectProps *props, ALenum param, int *vals)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
Null_getParami(props, param, vals);
|
||||
}
|
||||
}
|
||||
void Null_getParamf(const EffectProps* /*props*/, ALenum param, float* /*val*/)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid null effect float property 0x%04x",
|
||||
param};
|
||||
}
|
||||
}
|
||||
void Null_getParamfv(const EffectProps *props, ALenum param, float *vals)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
Null_getParamf(props, param, vals);
|
||||
}
|
||||
}
|
||||
|
||||
EffectProps genDefaultProps() noexcept
|
||||
{
|
||||
EffectProps props{};
|
||||
return props;
|
||||
return std::monostate{};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
DEFINE_ALEFFECT_VTABLE(Null);
|
||||
|
||||
const EffectProps NullEffectProps{genDefaultProps()};
|
||||
|
||||
void EffectHandler::SetParami(std::monostate& /*props*/, ALenum param, int /*val*/)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid null effect integer property 0x%04x",
|
||||
param};
|
||||
}
|
||||
}
|
||||
void EffectHandler::SetParamiv(std::monostate &props, ALenum param, const int *vals)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
SetParami(props, param, *vals);
|
||||
}
|
||||
}
|
||||
void EffectHandler::SetParamf(std::monostate& /*props*/, ALenum param, float /*val*/)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid null effect float property 0x%04x",
|
||||
param};
|
||||
}
|
||||
}
|
||||
void EffectHandler::SetParamfv(std::monostate &props, ALenum param, const float *vals)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
SetParamf(props, param, *vals);
|
||||
}
|
||||
}
|
||||
|
||||
void EffectHandler::GetParami(const std::monostate& /*props*/, ALenum param, int* /*val*/)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid null effect integer property 0x%04x",
|
||||
param};
|
||||
}
|
||||
}
|
||||
void EffectHandler::GetParamiv(const std::monostate &props, ALenum param, int *vals)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
GetParami(props, param, vals);
|
||||
}
|
||||
}
|
||||
void EffectHandler::GetParamf(const std::monostate& /*props*/, ALenum param, float* /*val*/)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid null effect float property 0x%04x",
|
||||
param};
|
||||
}
|
||||
}
|
||||
void EffectHandler::GetParamfv(const std::monostate &props, ALenum param, float *vals)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
GetParamf(props, param, vals);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef ALSOFT_EAX
|
||||
namespace {
|
||||
|
||||
class EaxNullEffect final :
|
||||
public EaxEffect
|
||||
{
|
||||
public:
|
||||
EaxNullEffect();
|
||||
|
||||
void dispatch(const EaxEaxCall& eax_call) override;
|
||||
|
||||
// [[nodiscard]]
|
||||
bool apply_deferred() override;
|
||||
}; // EaxNullEffect
|
||||
|
||||
|
||||
class EaxNullEffectException :
|
||||
public EaxException
|
||||
{
|
||||
public:
|
||||
explicit EaxNullEffectException(
|
||||
const char* message)
|
||||
:
|
||||
EaxException{"EAX_NULL_EFFECT", message}
|
||||
{
|
||||
}
|
||||
}; // EaxNullEffectException
|
||||
|
||||
|
||||
EaxNullEffect::EaxNullEffect()
|
||||
: EaxEffect{AL_EFFECT_NULL}
|
||||
{
|
||||
}
|
||||
|
||||
void EaxNullEffect::dispatch(const EaxEaxCall& eax_call)
|
||||
{
|
||||
if(eax_call.get_property_id() != 0)
|
||||
throw EaxNullEffectException{"Unsupported property id."};
|
||||
}
|
||||
|
||||
bool EaxNullEffect::apply_deferred()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
using NullCommitter = EaxCommitter<EaxNullCommitter>;
|
||||
|
||||
} // namespace
|
||||
|
||||
EaxEffectUPtr eax_create_eax_null_effect()
|
||||
template<>
|
||||
struct NullCommitter::Exception : public EaxException
|
||||
{
|
||||
return std::make_unique<EaxNullEffect>();
|
||||
explicit Exception(const char *message) : EaxException{"EAX_NULL_EFFECT", message}
|
||||
{ }
|
||||
};
|
||||
|
||||
template<>
|
||||
[[noreturn]] void NullCommitter::fail(const char *message)
|
||||
{
|
||||
throw Exception{message};
|
||||
}
|
||||
|
||||
bool EaxNullCommitter::commit(const std::monostate &props)
|
||||
{
|
||||
const bool ret{std::holds_alternative<std::monostate>(mEaxProps)};
|
||||
mEaxProps = props;
|
||||
mAlProps = std::monostate{};
|
||||
return ret;
|
||||
}
|
||||
|
||||
void EaxNullCommitter::SetDefaults(EaxEffectProps &props)
|
||||
{
|
||||
props = std::monostate{};
|
||||
}
|
||||
|
||||
void EaxNullCommitter::Get(const EaxCall &call, const std::monostate&)
|
||||
{
|
||||
if(call.get_property_id() != 0)
|
||||
fail_unknown_property_id();
|
||||
}
|
||||
|
||||
void EaxNullCommitter::Set(const EaxCall &call, std::monostate&)
|
||||
{
|
||||
if(call.get_property_id() != 0)
|
||||
fail_unknown_property_id();
|
||||
}
|
||||
|
||||
#endif // ALSOFT_EAX
|
||||
|
||||
@@ -9,36 +9,40 @@
|
||||
|
||||
#ifdef ALSOFT_EAX
|
||||
#include "alnumeric.h"
|
||||
|
||||
#include "al/eax_exception.h"
|
||||
#include "al/eax_utils.h"
|
||||
#include "al/eax/effect.h"
|
||||
#include "al/eax/exception.h"
|
||||
#include "al/eax/utils.h"
|
||||
#endif // ALSOFT_EAX
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
void Pshifter_setParamf(EffectProps*, ALenum param, float)
|
||||
{ throw effect_exception{AL_INVALID_ENUM, "Invalid pitch shifter float property 0x%04x", param}; }
|
||||
void Pshifter_setParamfv(EffectProps*, ALenum param, const float*)
|
||||
constexpr EffectProps genDefaultProps() noexcept
|
||||
{
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid pitch shifter float-vector property 0x%04x",
|
||||
param};
|
||||
PshifterProps props{};
|
||||
props.CoarseTune = AL_PITCH_SHIFTER_DEFAULT_COARSE_TUNE;
|
||||
props.FineTune = AL_PITCH_SHIFTER_DEFAULT_FINE_TUNE;
|
||||
return props;
|
||||
}
|
||||
|
||||
void Pshifter_setParami(EffectProps *props, ALenum param, int val)
|
||||
} // namespace
|
||||
|
||||
const EffectProps PshifterEffectProps{genDefaultProps()};
|
||||
|
||||
void EffectHandler::SetParami(PshifterProps &props, ALenum param, int val)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case AL_PITCH_SHIFTER_COARSE_TUNE:
|
||||
if(!(val >= AL_PITCH_SHIFTER_MIN_COARSE_TUNE && val <= AL_PITCH_SHIFTER_MAX_COARSE_TUNE))
|
||||
throw effect_exception{AL_INVALID_VALUE, "Pitch shifter coarse tune out of range"};
|
||||
props->Pshifter.CoarseTune = val;
|
||||
props.CoarseTune = val;
|
||||
break;
|
||||
|
||||
case AL_PITCH_SHIFTER_FINE_TUNE:
|
||||
if(!(val >= AL_PITCH_SHIFTER_MIN_FINE_TUNE && val <= AL_PITCH_SHIFTER_MAX_FINE_TUNE))
|
||||
throw effect_exception{AL_INVALID_VALUE, "Pitch shifter fine tune out of range"};
|
||||
props->Pshifter.FineTune = val;
|
||||
props.FineTune = val;
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -46,319 +50,134 @@ void Pshifter_setParami(EffectProps *props, ALenum param, int val)
|
||||
param};
|
||||
}
|
||||
}
|
||||
void Pshifter_setParamiv(EffectProps *props, ALenum param, const int *vals)
|
||||
{ Pshifter_setParami(props, param, vals[0]); }
|
||||
void EffectHandler::SetParamiv(PshifterProps &props, ALenum param, const int *vals)
|
||||
{ SetParami(props, param, *vals); }
|
||||
|
||||
void Pshifter_getParami(const EffectProps *props, ALenum param, int *val)
|
||||
void EffectHandler::SetParamf(PshifterProps&, ALenum param, float)
|
||||
{ throw effect_exception{AL_INVALID_ENUM, "Invalid pitch shifter float property 0x%04x", param}; }
|
||||
void EffectHandler::SetParamfv(PshifterProps&, ALenum param, const float*)
|
||||
{
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid pitch shifter float-vector property 0x%04x",
|
||||
param};
|
||||
}
|
||||
|
||||
void EffectHandler::GetParami(const PshifterProps &props, ALenum param, int *val)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case AL_PITCH_SHIFTER_COARSE_TUNE:
|
||||
*val = props->Pshifter.CoarseTune;
|
||||
break;
|
||||
case AL_PITCH_SHIFTER_FINE_TUNE:
|
||||
*val = props->Pshifter.FineTune;
|
||||
break;
|
||||
case AL_PITCH_SHIFTER_COARSE_TUNE: *val = props.CoarseTune; break;
|
||||
case AL_PITCH_SHIFTER_FINE_TUNE: *val = props.FineTune; break;
|
||||
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid pitch shifter integer property 0x%04x",
|
||||
param};
|
||||
}
|
||||
}
|
||||
void Pshifter_getParamiv(const EffectProps *props, ALenum param, int *vals)
|
||||
{ Pshifter_getParami(props, param, vals); }
|
||||
void EffectHandler::GetParamiv(const PshifterProps &props, ALenum param, int *vals)
|
||||
{ GetParami(props, param, vals); }
|
||||
|
||||
void Pshifter_getParamf(const EffectProps*, ALenum param, float*)
|
||||
void EffectHandler::GetParamf(const PshifterProps&, ALenum param, float*)
|
||||
{ throw effect_exception{AL_INVALID_ENUM, "Invalid pitch shifter float property 0x%04x", param}; }
|
||||
void Pshifter_getParamfv(const EffectProps*, ALenum param, float*)
|
||||
void EffectHandler::GetParamfv(const PshifterProps&, ALenum param, float*)
|
||||
{
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid pitch shifter float vector-property 0x%04x",
|
||||
param};
|
||||
}
|
||||
|
||||
EffectProps genDefaultProps() noexcept
|
||||
{
|
||||
EffectProps props{};
|
||||
props.Pshifter.CoarseTune = AL_PITCH_SHIFTER_DEFAULT_COARSE_TUNE;
|
||||
props.Pshifter.FineTune = AL_PITCH_SHIFTER_DEFAULT_FINE_TUNE;
|
||||
return props;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
DEFINE_ALEFFECT_VTABLE(Pshifter);
|
||||
|
||||
const EffectProps PshifterEffectProps{genDefaultProps()};
|
||||
|
||||
#ifdef ALSOFT_EAX
|
||||
namespace {
|
||||
|
||||
using EaxPitchShifterEffectDirtyFlagsValue = std::uint_least8_t;
|
||||
using PitchShifterCommitter = EaxCommitter<EaxPitchShifterCommitter>;
|
||||
|
||||
struct EaxPitchShifterEffectDirtyFlags
|
||||
{
|
||||
using EaxIsBitFieldStruct = bool;
|
||||
|
||||
EaxPitchShifterEffectDirtyFlagsValue lCoarseTune : 1;
|
||||
EaxPitchShifterEffectDirtyFlagsValue lFineTune : 1;
|
||||
}; // EaxPitchShifterEffectDirtyFlags
|
||||
|
||||
|
||||
class EaxPitchShifterEffect final :
|
||||
public EaxEffect
|
||||
{
|
||||
public:
|
||||
EaxPitchShifterEffect();
|
||||
|
||||
void dispatch(const EaxEaxCall& eax_call) override;
|
||||
|
||||
// [[nodiscard]]
|
||||
bool apply_deferred() override;
|
||||
|
||||
private:
|
||||
EAXPITCHSHIFTERPROPERTIES eax_{};
|
||||
EAXPITCHSHIFTERPROPERTIES eax_d_{};
|
||||
EaxPitchShifterEffectDirtyFlags eax_dirty_flags_{};
|
||||
|
||||
void set_eax_defaults();
|
||||
|
||||
void set_efx_coarse_tune();
|
||||
void set_efx_fine_tune();
|
||||
void set_efx_defaults();
|
||||
|
||||
void get(const EaxEaxCall& eax_call);
|
||||
|
||||
void validate_coarse_tune(long lCoarseTune);
|
||||
void validate_fine_tune(long lFineTune);
|
||||
void validate_all(const EAXPITCHSHIFTERPROPERTIES& all);
|
||||
|
||||
void defer_coarse_tune(long lCoarseTune);
|
||||
void defer_fine_tune(long lFineTune);
|
||||
void defer_all(const EAXPITCHSHIFTERPROPERTIES& all);
|
||||
|
||||
void defer_coarse_tune(const EaxEaxCall& eax_call);
|
||||
void defer_fine_tune(const EaxEaxCall& eax_call);
|
||||
void defer_all(const EaxEaxCall& eax_call);
|
||||
|
||||
void set(const EaxEaxCall& eax_call);
|
||||
}; // EaxPitchShifterEffect
|
||||
|
||||
|
||||
class EaxPitchShifterEffectException :
|
||||
public EaxException
|
||||
{
|
||||
public:
|
||||
explicit EaxPitchShifterEffectException(
|
||||
const char* message)
|
||||
:
|
||||
EaxException{"EAX_PITCH_SHIFTER_EFFECT", message}
|
||||
struct CoarseTuneValidator {
|
||||
void operator()(long lCoarseTune) const
|
||||
{
|
||||
eax_validate_range<PitchShifterCommitter::Exception>(
|
||||
"Coarse Tune",
|
||||
lCoarseTune,
|
||||
EAXPITCHSHIFTER_MINCOARSETUNE,
|
||||
EAXPITCHSHIFTER_MAXCOARSETUNE);
|
||||
}
|
||||
}; // EaxPitchShifterEffectException
|
||||
}; // CoarseTuneValidator
|
||||
|
||||
|
||||
EaxPitchShifterEffect::EaxPitchShifterEffect()
|
||||
: EaxEffect{AL_EFFECT_PITCH_SHIFTER}
|
||||
{
|
||||
set_eax_defaults();
|
||||
set_efx_defaults();
|
||||
}
|
||||
|
||||
void EaxPitchShifterEffect::dispatch(const EaxEaxCall& eax_call)
|
||||
{
|
||||
eax_call.is_get() ? get(eax_call) : set(eax_call);
|
||||
}
|
||||
|
||||
void EaxPitchShifterEffect::set_eax_defaults()
|
||||
{
|
||||
eax_.lCoarseTune = EAXPITCHSHIFTER_DEFAULTCOARSETUNE;
|
||||
eax_.lFineTune = EAXPITCHSHIFTER_DEFAULTFINETUNE;
|
||||
|
||||
eax_d_ = eax_;
|
||||
}
|
||||
|
||||
void EaxPitchShifterEffect::set_efx_coarse_tune()
|
||||
{
|
||||
const auto coarse_tune = clamp(
|
||||
static_cast<ALint>(eax_.lCoarseTune),
|
||||
AL_PITCH_SHIFTER_MIN_COARSE_TUNE,
|
||||
AL_PITCH_SHIFTER_MAX_COARSE_TUNE);
|
||||
|
||||
al_effect_props_.Pshifter.CoarseTune = coarse_tune;
|
||||
}
|
||||
|
||||
void EaxPitchShifterEffect::set_efx_fine_tune()
|
||||
{
|
||||
const auto fine_tune = clamp(
|
||||
static_cast<ALint>(eax_.lFineTune),
|
||||
AL_PITCH_SHIFTER_MIN_FINE_TUNE,
|
||||
AL_PITCH_SHIFTER_MAX_FINE_TUNE);
|
||||
|
||||
al_effect_props_.Pshifter.FineTune = fine_tune;
|
||||
}
|
||||
|
||||
void EaxPitchShifterEffect::set_efx_defaults()
|
||||
{
|
||||
set_efx_coarse_tune();
|
||||
set_efx_fine_tune();
|
||||
}
|
||||
|
||||
void EaxPitchShifterEffect::get(const EaxEaxCall& eax_call)
|
||||
{
|
||||
switch(eax_call.get_property_id())
|
||||
struct FineTuneValidator {
|
||||
void operator()(long lFineTune) const
|
||||
{
|
||||
case EAXPITCHSHIFTER_NONE:
|
||||
break;
|
||||
|
||||
case EAXPITCHSHIFTER_ALLPARAMETERS:
|
||||
eax_call.set_value<EaxPitchShifterEffectException>(eax_);
|
||||
break;
|
||||
|
||||
case EAXPITCHSHIFTER_COARSETUNE:
|
||||
eax_call.set_value<EaxPitchShifterEffectException>(eax_.lCoarseTune);
|
||||
break;
|
||||
|
||||
case EAXPITCHSHIFTER_FINETUNE:
|
||||
eax_call.set_value<EaxPitchShifterEffectException>(eax_.lFineTune);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw EaxPitchShifterEffectException{"Unsupported property id."};
|
||||
eax_validate_range<PitchShifterCommitter::Exception>(
|
||||
"Fine Tune",
|
||||
lFineTune,
|
||||
EAXPITCHSHIFTER_MINFINETUNE,
|
||||
EAXPITCHSHIFTER_MAXFINETUNE);
|
||||
}
|
||||
}
|
||||
}; // FineTuneValidator
|
||||
|
||||
void EaxPitchShifterEffect::validate_coarse_tune(
|
||||
long lCoarseTune)
|
||||
{
|
||||
eax_validate_range<EaxPitchShifterEffectException>(
|
||||
"Coarse Tune",
|
||||
lCoarseTune,
|
||||
EAXPITCHSHIFTER_MINCOARSETUNE,
|
||||
EAXPITCHSHIFTER_MAXCOARSETUNE);
|
||||
}
|
||||
|
||||
void EaxPitchShifterEffect::validate_fine_tune(
|
||||
long lFineTune)
|
||||
{
|
||||
eax_validate_range<EaxPitchShifterEffectException>(
|
||||
"Fine Tune",
|
||||
lFineTune,
|
||||
EAXPITCHSHIFTER_MINFINETUNE,
|
||||
EAXPITCHSHIFTER_MAXFINETUNE);
|
||||
}
|
||||
|
||||
void EaxPitchShifterEffect::validate_all(
|
||||
const EAXPITCHSHIFTERPROPERTIES& all)
|
||||
{
|
||||
validate_coarse_tune(all.lCoarseTune);
|
||||
validate_fine_tune(all.lFineTune);
|
||||
}
|
||||
|
||||
void EaxPitchShifterEffect::defer_coarse_tune(
|
||||
long lCoarseTune)
|
||||
{
|
||||
eax_d_.lCoarseTune = lCoarseTune;
|
||||
eax_dirty_flags_.lCoarseTune = (eax_.lCoarseTune != eax_d_.lCoarseTune);
|
||||
}
|
||||
|
||||
void EaxPitchShifterEffect::defer_fine_tune(
|
||||
long lFineTune)
|
||||
{
|
||||
eax_d_.lFineTune = lFineTune;
|
||||
eax_dirty_flags_.lFineTune = (eax_.lFineTune != eax_d_.lFineTune);
|
||||
}
|
||||
|
||||
void EaxPitchShifterEffect::defer_all(
|
||||
const EAXPITCHSHIFTERPROPERTIES& all)
|
||||
{
|
||||
defer_coarse_tune(all.lCoarseTune);
|
||||
defer_fine_tune(all.lFineTune);
|
||||
}
|
||||
|
||||
void EaxPitchShifterEffect::defer_coarse_tune(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& coarse_tune =
|
||||
eax_call.get_value<EaxPitchShifterEffectException, const decltype(EAXPITCHSHIFTERPROPERTIES::lCoarseTune)>();
|
||||
|
||||
validate_coarse_tune(coarse_tune);
|
||||
defer_coarse_tune(coarse_tune);
|
||||
}
|
||||
|
||||
void EaxPitchShifterEffect::defer_fine_tune(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& fine_tune =
|
||||
eax_call.get_value<EaxPitchShifterEffectException, const decltype(EAXPITCHSHIFTERPROPERTIES::lFineTune)>();
|
||||
|
||||
validate_fine_tune(fine_tune);
|
||||
defer_fine_tune(fine_tune);
|
||||
}
|
||||
|
||||
void EaxPitchShifterEffect::defer_all(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& all =
|
||||
eax_call.get_value<EaxPitchShifterEffectException, const EAXPITCHSHIFTERPROPERTIES>();
|
||||
|
||||
validate_all(all);
|
||||
defer_all(all);
|
||||
}
|
||||
|
||||
// [[nodiscard]]
|
||||
bool EaxPitchShifterEffect::apply_deferred()
|
||||
{
|
||||
if (eax_dirty_flags_ == EaxPitchShifterEffectDirtyFlags{})
|
||||
struct AllValidator {
|
||||
void operator()(const EAXPITCHSHIFTERPROPERTIES& all) const
|
||||
{
|
||||
CoarseTuneValidator{}(all.lCoarseTune);
|
||||
FineTuneValidator{}(all.lFineTune);
|
||||
}
|
||||
}; // AllValidator
|
||||
|
||||
} // namespace
|
||||
|
||||
template<>
|
||||
struct PitchShifterCommitter::Exception : public EaxException {
|
||||
explicit Exception(const char *message) : EaxException{"EAX_PITCH_SHIFTER_EFFECT", message}
|
||||
{ }
|
||||
};
|
||||
|
||||
template<>
|
||||
[[noreturn]] void PitchShifterCommitter::fail(const char *message)
|
||||
{
|
||||
throw Exception{message};
|
||||
}
|
||||
|
||||
bool EaxPitchShifterCommitter::commit(const EAXPITCHSHIFTERPROPERTIES &props)
|
||||
{
|
||||
if(auto *cur = std::get_if<EAXPITCHSHIFTERPROPERTIES>(&mEaxProps); cur && *cur == props)
|
||||
return false;
|
||||
}
|
||||
|
||||
eax_ = eax_d_;
|
||||
|
||||
if (eax_dirty_flags_.lCoarseTune)
|
||||
{
|
||||
set_efx_coarse_tune();
|
||||
}
|
||||
|
||||
if (eax_dirty_flags_.lFineTune)
|
||||
{
|
||||
set_efx_fine_tune();
|
||||
}
|
||||
|
||||
eax_dirty_flags_ = EaxPitchShifterEffectDirtyFlags{};
|
||||
mEaxProps = props;
|
||||
mAlProps = [&]{
|
||||
PshifterProps ret{};
|
||||
ret.CoarseTune = static_cast<int>(props.lCoarseTune);
|
||||
ret.FineTune = static_cast<int>(props.lFineTune);
|
||||
return ret;
|
||||
}();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void EaxPitchShifterEffect::set(const EaxEaxCall& eax_call)
|
||||
void EaxPitchShifterCommitter::SetDefaults(EaxEffectProps &props)
|
||||
{
|
||||
switch(eax_call.get_property_id())
|
||||
props = EAXPITCHSHIFTERPROPERTIES{EAXPITCHSHIFTER_DEFAULTCOARSETUNE,
|
||||
EAXPITCHSHIFTER_DEFAULTFINETUNE};
|
||||
}
|
||||
|
||||
void EaxPitchShifterCommitter::Get(const EaxCall &call, const EAXPITCHSHIFTERPROPERTIES &props)
|
||||
{
|
||||
switch(call.get_property_id())
|
||||
{
|
||||
case EAXPITCHSHIFTER_NONE:
|
||||
break;
|
||||
|
||||
case EAXPITCHSHIFTER_ALLPARAMETERS:
|
||||
defer_all(eax_call);
|
||||
break;
|
||||
|
||||
case EAXPITCHSHIFTER_COARSETUNE:
|
||||
defer_coarse_tune(eax_call);
|
||||
break;
|
||||
|
||||
case EAXPITCHSHIFTER_FINETUNE:
|
||||
defer_fine_tune(eax_call);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw EaxPitchShifterEffectException{"Unsupported property id."};
|
||||
case EAXPITCHSHIFTER_NONE: break;
|
||||
case EAXPITCHSHIFTER_ALLPARAMETERS: call.set_value<Exception>(props); break;
|
||||
case EAXPITCHSHIFTER_COARSETUNE: call.set_value<Exception>(props.lCoarseTune); break;
|
||||
case EAXPITCHSHIFTER_FINETUNE: call.set_value<Exception>(props.lFineTune); break;
|
||||
default: fail_unknown_property_id();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
EaxEffectUPtr eax_create_eax_pitch_shifter_effect()
|
||||
void EaxPitchShifterCommitter::Set(const EaxCall &call, EAXPITCHSHIFTERPROPERTIES &props)
|
||||
{
|
||||
return std::make_unique<EaxPitchShifterEffect>();
|
||||
switch(call.get_property_id())
|
||||
{
|
||||
case EAXPITCHSHIFTER_NONE: break;
|
||||
case EAXPITCHSHIFTER_ALLPARAMETERS: defer<AllValidator>(call, props); break;
|
||||
case EAXPITCHSHIFTER_COARSETUNE: defer<CoarseTuneValidator>(call, props.lCoarseTune); break;
|
||||
case EAXPITCHSHIFTER_FINETUNE: defer<FineTuneValidator>(call, props.lFineTune); break;
|
||||
default: fail_unknown_property_id();
|
||||
}
|
||||
}
|
||||
|
||||
#endif // ALSOFT_EAX
|
||||
|
||||
+960
-2250
File diff suppressed because it is too large
Load Diff
@@ -1,31 +1,30 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <optional>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "AL/al.h"
|
||||
#include "AL/efx.h"
|
||||
|
||||
#include "alc/effects/base.h"
|
||||
#include "aloptional.h"
|
||||
#include "effects.h"
|
||||
|
||||
#ifdef ALSOFT_EAX
|
||||
#include <cassert>
|
||||
|
||||
#include "alnumeric.h"
|
||||
|
||||
#include "al/eax_exception.h"
|
||||
#include "al/eax_utils.h"
|
||||
#include "al/eax/effect.h"
|
||||
#include "al/eax/exception.h"
|
||||
#include "al/eax/utils.h"
|
||||
#endif // ALSOFT_EAX
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
al::optional<VMorpherPhenome> PhenomeFromEnum(ALenum val)
|
||||
constexpr std::optional<VMorpherPhenome> PhenomeFromEnum(ALenum val) noexcept
|
||||
{
|
||||
#define HANDLE_PHENOME(x) case AL_VOCAL_MORPHER_PHONEME_ ## x: \
|
||||
return al::make_optional(VMorpherPhenome::x)
|
||||
return VMorpherPhenome::x
|
||||
switch(val)
|
||||
{
|
||||
HANDLE_PHENOME(A);
|
||||
@@ -59,10 +58,10 @@ al::optional<VMorpherPhenome> PhenomeFromEnum(ALenum val)
|
||||
HANDLE_PHENOME(V);
|
||||
HANDLE_PHENOME(Z);
|
||||
}
|
||||
return al::nullopt;
|
||||
return std::nullopt;
|
||||
#undef HANDLE_PHENOME
|
||||
}
|
||||
ALenum EnumFromPhenome(VMorpherPhenome phenome)
|
||||
constexpr ALenum EnumFromPhenome(VMorpherPhenome phenome)
|
||||
{
|
||||
#define HANDLE_PHENOME(x) case VMorpherPhenome::x: return AL_VOCAL_MORPHER_PHONEME_ ## x
|
||||
switch(phenome)
|
||||
@@ -102,17 +101,17 @@ ALenum EnumFromPhenome(VMorpherPhenome phenome)
|
||||
#undef HANDLE_PHENOME
|
||||
}
|
||||
|
||||
al::optional<VMorpherWaveform> WaveformFromEmum(ALenum value)
|
||||
constexpr std::optional<VMorpherWaveform> WaveformFromEmum(ALenum value) noexcept
|
||||
{
|
||||
switch(value)
|
||||
{
|
||||
case AL_VOCAL_MORPHER_WAVEFORM_SINUSOID: return al::make_optional(VMorpherWaveform::Sinusoid);
|
||||
case AL_VOCAL_MORPHER_WAVEFORM_TRIANGLE: return al::make_optional(VMorpherWaveform::Triangle);
|
||||
case AL_VOCAL_MORPHER_WAVEFORM_SAWTOOTH: return al::make_optional(VMorpherWaveform::Sawtooth);
|
||||
case AL_VOCAL_MORPHER_WAVEFORM_SINUSOID: return VMorpherWaveform::Sinusoid;
|
||||
case AL_VOCAL_MORPHER_WAVEFORM_TRIANGLE: return VMorpherWaveform::Triangle;
|
||||
case AL_VOCAL_MORPHER_WAVEFORM_SAWTOOTH: return VMorpherWaveform::Sawtooth;
|
||||
}
|
||||
return al::nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
ALenum EnumFromWaveform(VMorpherWaveform type)
|
||||
constexpr ALenum EnumFromWaveform(VMorpherWaveform type)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
@@ -124,13 +123,29 @@ ALenum EnumFromWaveform(VMorpherWaveform type)
|
||||
std::to_string(static_cast<int>(type))};
|
||||
}
|
||||
|
||||
void Vmorpher_setParami(EffectProps *props, ALenum param, int val)
|
||||
constexpr EffectProps genDefaultProps() noexcept
|
||||
{
|
||||
VmorpherProps props{};
|
||||
props.Rate = AL_VOCAL_MORPHER_DEFAULT_RATE;
|
||||
props.PhonemeA = PhenomeFromEnum(AL_VOCAL_MORPHER_DEFAULT_PHONEMEA).value();
|
||||
props.PhonemeB = PhenomeFromEnum(AL_VOCAL_MORPHER_DEFAULT_PHONEMEB).value();
|
||||
props.PhonemeACoarseTuning = AL_VOCAL_MORPHER_DEFAULT_PHONEMEA_COARSE_TUNING;
|
||||
props.PhonemeBCoarseTuning = AL_VOCAL_MORPHER_DEFAULT_PHONEMEB_COARSE_TUNING;
|
||||
props.Waveform = WaveformFromEmum(AL_VOCAL_MORPHER_DEFAULT_WAVEFORM).value();
|
||||
return props;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
const EffectProps VmorpherEffectProps{genDefaultProps()};
|
||||
|
||||
void EffectHandler::SetParami(VmorpherProps &props, ALenum param, int val)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case AL_VOCAL_MORPHER_PHONEMEA:
|
||||
if(auto phenomeopt = PhenomeFromEnum(val))
|
||||
props->Vmorpher.PhonemeA = *phenomeopt;
|
||||
props.PhonemeA = *phenomeopt;
|
||||
else
|
||||
throw effect_exception{AL_INVALID_VALUE, "Vocal morpher phoneme-a out of range: 0x%04x", val};
|
||||
break;
|
||||
@@ -138,12 +153,12 @@ void Vmorpher_setParami(EffectProps *props, ALenum param, int val)
|
||||
case AL_VOCAL_MORPHER_PHONEMEA_COARSE_TUNING:
|
||||
if(!(val >= AL_VOCAL_MORPHER_MIN_PHONEMEA_COARSE_TUNING && val <= AL_VOCAL_MORPHER_MAX_PHONEMEA_COARSE_TUNING))
|
||||
throw effect_exception{AL_INVALID_VALUE, "Vocal morpher phoneme-a coarse tuning out of range"};
|
||||
props->Vmorpher.PhonemeACoarseTuning = val;
|
||||
props.PhonemeACoarseTuning = val;
|
||||
break;
|
||||
|
||||
case AL_VOCAL_MORPHER_PHONEMEB:
|
||||
if(auto phenomeopt = PhenomeFromEnum(val))
|
||||
props->Vmorpher.PhonemeB = *phenomeopt;
|
||||
props.PhonemeB = *phenomeopt;
|
||||
else
|
||||
throw effect_exception{AL_INVALID_VALUE, "Vocal morpher phoneme-b out of range: 0x%04x", val};
|
||||
break;
|
||||
@@ -151,12 +166,12 @@ void Vmorpher_setParami(EffectProps *props, ALenum param, int val)
|
||||
case AL_VOCAL_MORPHER_PHONEMEB_COARSE_TUNING:
|
||||
if(!(val >= AL_VOCAL_MORPHER_MIN_PHONEMEB_COARSE_TUNING && val <= AL_VOCAL_MORPHER_MAX_PHONEMEB_COARSE_TUNING))
|
||||
throw effect_exception{AL_INVALID_VALUE, "Vocal morpher phoneme-b coarse tuning out of range"};
|
||||
props->Vmorpher.PhonemeBCoarseTuning = val;
|
||||
props.PhonemeBCoarseTuning = val;
|
||||
break;
|
||||
|
||||
case AL_VOCAL_MORPHER_WAVEFORM:
|
||||
if(auto formopt = WaveformFromEmum(val))
|
||||
props->Vmorpher.Waveform = *formopt;
|
||||
props.Waveform = *formopt;
|
||||
else
|
||||
throw effect_exception{AL_INVALID_VALUE, "Vocal morpher waveform out of range: 0x%04x", val};
|
||||
break;
|
||||
@@ -166,19 +181,19 @@ void Vmorpher_setParami(EffectProps *props, ALenum param, int val)
|
||||
param};
|
||||
}
|
||||
}
|
||||
void Vmorpher_setParamiv(EffectProps*, ALenum param, const int*)
|
||||
void EffectHandler::SetParamiv(VmorpherProps&, ALenum param, const int*)
|
||||
{
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid vocal morpher integer-vector property 0x%04x",
|
||||
param};
|
||||
}
|
||||
void Vmorpher_setParamf(EffectProps *props, ALenum param, float val)
|
||||
void EffectHandler::SetParamf(VmorpherProps &props, ALenum param, float val)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case AL_VOCAL_MORPHER_RATE:
|
||||
if(!(val >= AL_VOCAL_MORPHER_MIN_RATE && val <= AL_VOCAL_MORPHER_MAX_RATE))
|
||||
throw effect_exception{AL_INVALID_VALUE, "Vocal morpher rate out of range"};
|
||||
props->Vmorpher.Rate = val;
|
||||
props.Rate = val;
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -186,49 +201,35 @@ void Vmorpher_setParamf(EffectProps *props, ALenum param, float val)
|
||||
param};
|
||||
}
|
||||
}
|
||||
void Vmorpher_setParamfv(EffectProps *props, ALenum param, const float *vals)
|
||||
{ Vmorpher_setParamf(props, param, vals[0]); }
|
||||
void EffectHandler::SetParamfv(VmorpherProps &props, ALenum param, const float *vals)
|
||||
{ SetParamf(props, param, *vals); }
|
||||
|
||||
void Vmorpher_getParami(const EffectProps *props, ALenum param, int* val)
|
||||
void EffectHandler::GetParami(const VmorpherProps &props, ALenum param, int* val)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case AL_VOCAL_MORPHER_PHONEMEA:
|
||||
*val = EnumFromPhenome(props->Vmorpher.PhonemeA);
|
||||
break;
|
||||
|
||||
case AL_VOCAL_MORPHER_PHONEMEA_COARSE_TUNING:
|
||||
*val = props->Vmorpher.PhonemeACoarseTuning;
|
||||
break;
|
||||
|
||||
case AL_VOCAL_MORPHER_PHONEMEB:
|
||||
*val = EnumFromPhenome(props->Vmorpher.PhonemeB);
|
||||
break;
|
||||
|
||||
case AL_VOCAL_MORPHER_PHONEMEB_COARSE_TUNING:
|
||||
*val = props->Vmorpher.PhonemeBCoarseTuning;
|
||||
break;
|
||||
|
||||
case AL_VOCAL_MORPHER_WAVEFORM:
|
||||
*val = EnumFromWaveform(props->Vmorpher.Waveform);
|
||||
break;
|
||||
case AL_VOCAL_MORPHER_PHONEMEA: *val = EnumFromPhenome(props.PhonemeA); break;
|
||||
case AL_VOCAL_MORPHER_PHONEMEA_COARSE_TUNING: *val = props.PhonemeACoarseTuning; break;
|
||||
case AL_VOCAL_MORPHER_PHONEMEB: *val = EnumFromPhenome(props.PhonemeB); break;
|
||||
case AL_VOCAL_MORPHER_PHONEMEB_COARSE_TUNING: *val = props.PhonemeBCoarseTuning; break;
|
||||
case AL_VOCAL_MORPHER_WAVEFORM: *val = EnumFromWaveform(props.Waveform); break;
|
||||
|
||||
default:
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid vocal morpher integer property 0x%04x",
|
||||
param};
|
||||
}
|
||||
}
|
||||
void Vmorpher_getParamiv(const EffectProps*, ALenum param, int*)
|
||||
void EffectHandler::GetParamiv(const VmorpherProps&, ALenum param, int*)
|
||||
{
|
||||
throw effect_exception{AL_INVALID_ENUM, "Invalid vocal morpher integer-vector property 0x%04x",
|
||||
param};
|
||||
}
|
||||
void Vmorpher_getParamf(const EffectProps *props, ALenum param, float *val)
|
||||
void EffectHandler::GetParamf(const VmorpherProps &props, ALenum param, float *val)
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case AL_VOCAL_MORPHER_RATE:
|
||||
*val = props->Vmorpher.Rate;
|
||||
*val = props.Rate;
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -236,551 +237,221 @@ void Vmorpher_getParamf(const EffectProps *props, ALenum param, float *val)
|
||||
param};
|
||||
}
|
||||
}
|
||||
void Vmorpher_getParamfv(const EffectProps *props, ALenum param, float *vals)
|
||||
{ Vmorpher_getParamf(props, param, vals); }
|
||||
void EffectHandler::GetParamfv(const VmorpherProps &props, ALenum param, float *vals)
|
||||
{ GetParamf(props, param, vals); }
|
||||
|
||||
EffectProps genDefaultProps() noexcept
|
||||
{
|
||||
EffectProps props{};
|
||||
props.Vmorpher.Rate = AL_VOCAL_MORPHER_DEFAULT_RATE;
|
||||
props.Vmorpher.PhonemeA = *PhenomeFromEnum(AL_VOCAL_MORPHER_DEFAULT_PHONEMEA);
|
||||
props.Vmorpher.PhonemeB = *PhenomeFromEnum(AL_VOCAL_MORPHER_DEFAULT_PHONEMEB);
|
||||
props.Vmorpher.PhonemeACoarseTuning = AL_VOCAL_MORPHER_DEFAULT_PHONEMEA_COARSE_TUNING;
|
||||
props.Vmorpher.PhonemeBCoarseTuning = AL_VOCAL_MORPHER_DEFAULT_PHONEMEB_COARSE_TUNING;
|
||||
props.Vmorpher.Waveform = *WaveformFromEmum(AL_VOCAL_MORPHER_DEFAULT_WAVEFORM);
|
||||
return props;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
DEFINE_ALEFFECT_VTABLE(Vmorpher);
|
||||
|
||||
const EffectProps VmorpherEffectProps{genDefaultProps()};
|
||||
|
||||
#ifdef ALSOFT_EAX
|
||||
namespace {
|
||||
|
||||
using EaxVocalMorpherEffectDirtyFlagsValue = std::uint_least8_t;
|
||||
using VocalMorpherCommitter = EaxCommitter<EaxVocalMorpherCommitter>;
|
||||
|
||||
struct EaxVocalMorpherEffectDirtyFlags
|
||||
{
|
||||
using EaxIsBitFieldStruct = bool;
|
||||
|
||||
EaxVocalMorpherEffectDirtyFlagsValue ulPhonemeA : 1;
|
||||
EaxVocalMorpherEffectDirtyFlagsValue lPhonemeACoarseTuning : 1;
|
||||
EaxVocalMorpherEffectDirtyFlagsValue ulPhonemeB : 1;
|
||||
EaxVocalMorpherEffectDirtyFlagsValue lPhonemeBCoarseTuning : 1;
|
||||
EaxVocalMorpherEffectDirtyFlagsValue ulWaveform : 1;
|
||||
EaxVocalMorpherEffectDirtyFlagsValue flRate : 1;
|
||||
}; // EaxPitchShifterEffectDirtyFlags
|
||||
|
||||
|
||||
class EaxVocalMorpherEffect final :
|
||||
public EaxEffect
|
||||
{
|
||||
public:
|
||||
EaxVocalMorpherEffect();
|
||||
|
||||
void dispatch(const EaxEaxCall& eax_call) override;
|
||||
|
||||
// [[nodiscard]]
|
||||
bool apply_deferred() override;
|
||||
|
||||
private:
|
||||
EAXVOCALMORPHERPROPERTIES eax_{};
|
||||
EAXVOCALMORPHERPROPERTIES eax_d_{};
|
||||
EaxVocalMorpherEffectDirtyFlags eax_dirty_flags_{};
|
||||
|
||||
void set_eax_defaults();
|
||||
|
||||
void set_efx_phoneme_a();
|
||||
void set_efx_phoneme_a_coarse_tuning();
|
||||
void set_efx_phoneme_b();
|
||||
void set_efx_phoneme_b_coarse_tuning();
|
||||
void set_efx_waveform();
|
||||
void set_efx_rate();
|
||||
void set_efx_defaults();
|
||||
|
||||
void get(const EaxEaxCall& eax_call);
|
||||
|
||||
void validate_phoneme_a(unsigned long ulPhonemeA);
|
||||
void validate_phoneme_a_coarse_tuning(long lPhonemeACoarseTuning);
|
||||
void validate_phoneme_b(unsigned long ulPhonemeB);
|
||||
void validate_phoneme_b_coarse_tuning(long lPhonemeBCoarseTuning);
|
||||
void validate_waveform(unsigned long ulWaveform);
|
||||
void validate_rate(float flRate);
|
||||
void validate_all(const EAXVOCALMORPHERPROPERTIES& all);
|
||||
|
||||
void defer_phoneme_a(unsigned long ulPhonemeA);
|
||||
void defer_phoneme_a_coarse_tuning(long lPhonemeACoarseTuning);
|
||||
void defer_phoneme_b(unsigned long ulPhonemeB);
|
||||
void defer_phoneme_b_coarse_tuning(long lPhonemeBCoarseTuning);
|
||||
void defer_waveform(unsigned long ulWaveform);
|
||||
void defer_rate(float flRate);
|
||||
void defer_all(const EAXVOCALMORPHERPROPERTIES& all);
|
||||
|
||||
void defer_phoneme_a(const EaxEaxCall& eax_call);
|
||||
void defer_phoneme_a_coarse_tuning(const EaxEaxCall& eax_call);
|
||||
void defer_phoneme_b(const EaxEaxCall& eax_call);
|
||||
void defer_phoneme_b_coarse_tuning(const EaxEaxCall& eax_call);
|
||||
void defer_waveform(const EaxEaxCall& eax_call);
|
||||
void defer_rate(const EaxEaxCall& eax_call);
|
||||
void defer_all(const EaxEaxCall& eax_call);
|
||||
|
||||
void set(const EaxEaxCall& eax_call);
|
||||
}; // EaxVocalMorpherEffect
|
||||
|
||||
|
||||
class EaxVocalMorpherEffectException :
|
||||
public EaxException
|
||||
{
|
||||
public:
|
||||
explicit EaxVocalMorpherEffectException(
|
||||
const char* message)
|
||||
:
|
||||
EaxException{"EAX_VOCAL_MORPHER_EFFECT", message}
|
||||
struct PhonemeAValidator {
|
||||
void operator()(unsigned long ulPhonemeA) const
|
||||
{
|
||||
eax_validate_range<VocalMorpherCommitter::Exception>(
|
||||
"Phoneme A",
|
||||
ulPhonemeA,
|
||||
EAXVOCALMORPHER_MINPHONEMEA,
|
||||
EAXVOCALMORPHER_MAXPHONEMEA);
|
||||
}
|
||||
}; // EaxVocalMorpherEffectException
|
||||
}; // PhonemeAValidator
|
||||
|
||||
|
||||
EaxVocalMorpherEffect::EaxVocalMorpherEffect()
|
||||
: EaxEffect{AL_EFFECT_VOCAL_MORPHER}
|
||||
{
|
||||
set_eax_defaults();
|
||||
set_efx_defaults();
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::dispatch(const EaxEaxCall& eax_call)
|
||||
{
|
||||
eax_call.is_get() ? get(eax_call) : set(eax_call);
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::set_eax_defaults()
|
||||
{
|
||||
eax_.ulPhonemeA = EAXVOCALMORPHER_DEFAULTPHONEMEA;
|
||||
eax_.lPhonemeACoarseTuning = EAXVOCALMORPHER_DEFAULTPHONEMEACOARSETUNING;
|
||||
eax_.ulPhonemeB = EAXVOCALMORPHER_DEFAULTPHONEMEB;
|
||||
eax_.lPhonemeBCoarseTuning = EAXVOCALMORPHER_DEFAULTPHONEMEBCOARSETUNING;
|
||||
eax_.ulWaveform = EAXVOCALMORPHER_DEFAULTWAVEFORM;
|
||||
eax_.flRate = EAXVOCALMORPHER_DEFAULTRATE;
|
||||
|
||||
eax_d_ = eax_;
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::set_efx_phoneme_a()
|
||||
{
|
||||
const auto phoneme_a = clamp(
|
||||
static_cast<ALint>(eax_.ulPhonemeA),
|
||||
AL_VOCAL_MORPHER_MIN_PHONEMEA,
|
||||
AL_VOCAL_MORPHER_MAX_PHONEMEA);
|
||||
|
||||
const auto efx_phoneme_a = PhenomeFromEnum(phoneme_a);
|
||||
assert(efx_phoneme_a.has_value());
|
||||
al_effect_props_.Vmorpher.PhonemeA = *efx_phoneme_a;
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::set_efx_phoneme_a_coarse_tuning()
|
||||
{
|
||||
const auto phoneme_a_coarse_tuning = clamp(
|
||||
static_cast<ALint>(eax_.lPhonemeACoarseTuning),
|
||||
AL_VOCAL_MORPHER_MIN_PHONEMEA_COARSE_TUNING,
|
||||
AL_VOCAL_MORPHER_MAX_PHONEMEA_COARSE_TUNING);
|
||||
|
||||
al_effect_props_.Vmorpher.PhonemeACoarseTuning = phoneme_a_coarse_tuning;
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::set_efx_phoneme_b()
|
||||
{
|
||||
const auto phoneme_b = clamp(
|
||||
static_cast<ALint>(eax_.ulPhonemeB),
|
||||
AL_VOCAL_MORPHER_MIN_PHONEMEB,
|
||||
AL_VOCAL_MORPHER_MAX_PHONEMEB);
|
||||
|
||||
const auto efx_phoneme_b = PhenomeFromEnum(phoneme_b);
|
||||
assert(efx_phoneme_b.has_value());
|
||||
al_effect_props_.Vmorpher.PhonemeB = *efx_phoneme_b;
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::set_efx_phoneme_b_coarse_tuning()
|
||||
{
|
||||
const auto phoneme_b_coarse_tuning = clamp(
|
||||
static_cast<ALint>(eax_.lPhonemeBCoarseTuning),
|
||||
AL_VOCAL_MORPHER_MIN_PHONEMEB_COARSE_TUNING,
|
||||
AL_VOCAL_MORPHER_MAX_PHONEMEB_COARSE_TUNING);
|
||||
|
||||
al_effect_props_.Vmorpher.PhonemeBCoarseTuning = phoneme_b_coarse_tuning;
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::set_efx_waveform()
|
||||
{
|
||||
const auto waveform = clamp(
|
||||
static_cast<ALint>(eax_.ulWaveform),
|
||||
AL_VOCAL_MORPHER_MIN_WAVEFORM,
|
||||
AL_VOCAL_MORPHER_MAX_WAVEFORM);
|
||||
|
||||
const auto wfx_waveform = WaveformFromEmum(waveform);
|
||||
assert(wfx_waveform.has_value());
|
||||
al_effect_props_.Vmorpher.Waveform = *wfx_waveform;
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::set_efx_rate()
|
||||
{
|
||||
const auto rate = clamp(
|
||||
eax_.flRate,
|
||||
AL_VOCAL_MORPHER_MIN_RATE,
|
||||
AL_VOCAL_MORPHER_MAX_RATE);
|
||||
|
||||
al_effect_props_.Vmorpher.Rate = rate;
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::set_efx_defaults()
|
||||
{
|
||||
set_efx_phoneme_a();
|
||||
set_efx_phoneme_a_coarse_tuning();
|
||||
set_efx_phoneme_b();
|
||||
set_efx_phoneme_b_coarse_tuning();
|
||||
set_efx_waveform();
|
||||
set_efx_rate();
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::get(const EaxEaxCall& eax_call)
|
||||
{
|
||||
switch(eax_call.get_property_id())
|
||||
struct PhonemeACoarseTuningValidator {
|
||||
void operator()(long lPhonemeACoarseTuning) const
|
||||
{
|
||||
case EAXVOCALMORPHER_NONE:
|
||||
break;
|
||||
|
||||
case EAXVOCALMORPHER_ALLPARAMETERS:
|
||||
eax_call.set_value<EaxVocalMorpherEffectException>(eax_);
|
||||
break;
|
||||
|
||||
case EAXVOCALMORPHER_PHONEMEA:
|
||||
eax_call.set_value<EaxVocalMorpherEffectException>(eax_.ulPhonemeA);
|
||||
break;
|
||||
|
||||
case EAXVOCALMORPHER_PHONEMEACOARSETUNING:
|
||||
eax_call.set_value<EaxVocalMorpherEffectException>(eax_.lPhonemeACoarseTuning);
|
||||
break;
|
||||
|
||||
case EAXVOCALMORPHER_PHONEMEB:
|
||||
eax_call.set_value<EaxVocalMorpherEffectException>(eax_.ulPhonemeB);
|
||||
break;
|
||||
|
||||
case EAXVOCALMORPHER_PHONEMEBCOARSETUNING:
|
||||
eax_call.set_value<EaxVocalMorpherEffectException>(eax_.lPhonemeBCoarseTuning);
|
||||
break;
|
||||
|
||||
case EAXVOCALMORPHER_WAVEFORM:
|
||||
eax_call.set_value<EaxVocalMorpherEffectException>(eax_.ulWaveform);
|
||||
break;
|
||||
|
||||
case EAXVOCALMORPHER_RATE:
|
||||
eax_call.set_value<EaxVocalMorpherEffectException>(eax_.flRate);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw EaxVocalMorpherEffectException{"Unsupported property id."};
|
||||
eax_validate_range<VocalMorpherCommitter::Exception>(
|
||||
"Phoneme A Coarse Tuning",
|
||||
lPhonemeACoarseTuning,
|
||||
EAXVOCALMORPHER_MINPHONEMEACOARSETUNING,
|
||||
EAXVOCALMORPHER_MAXPHONEMEACOARSETUNING);
|
||||
}
|
||||
}
|
||||
}; // PhonemeACoarseTuningValidator
|
||||
|
||||
void EaxVocalMorpherEffect::validate_phoneme_a(
|
||||
unsigned long ulPhonemeA)
|
||||
{
|
||||
eax_validate_range<EaxVocalMorpherEffectException>(
|
||||
"Phoneme A",
|
||||
ulPhonemeA,
|
||||
EAXVOCALMORPHER_MINPHONEMEA,
|
||||
EAXVOCALMORPHER_MAXPHONEMEA);
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::validate_phoneme_a_coarse_tuning(
|
||||
long lPhonemeACoarseTuning)
|
||||
{
|
||||
eax_validate_range<EaxVocalMorpherEffectException>(
|
||||
"Phoneme A Coarse Tuning",
|
||||
lPhonemeACoarseTuning,
|
||||
EAXVOCALMORPHER_MINPHONEMEACOARSETUNING,
|
||||
EAXVOCALMORPHER_MAXPHONEMEACOARSETUNING);
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::validate_phoneme_b(
|
||||
unsigned long ulPhonemeB)
|
||||
{
|
||||
eax_validate_range<EaxVocalMorpherEffectException>(
|
||||
"Phoneme B",
|
||||
ulPhonemeB,
|
||||
EAXVOCALMORPHER_MINPHONEMEB,
|
||||
EAXVOCALMORPHER_MAXPHONEMEB);
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::validate_phoneme_b_coarse_tuning(
|
||||
long lPhonemeBCoarseTuning)
|
||||
{
|
||||
eax_validate_range<EaxVocalMorpherEffectException>(
|
||||
"Phoneme B Coarse Tuning",
|
||||
lPhonemeBCoarseTuning,
|
||||
EAXVOCALMORPHER_MINPHONEMEBCOARSETUNING,
|
||||
EAXVOCALMORPHER_MAXPHONEMEBCOARSETUNING);
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::validate_waveform(
|
||||
unsigned long ulWaveform)
|
||||
{
|
||||
eax_validate_range<EaxVocalMorpherEffectException>(
|
||||
"Waveform",
|
||||
ulWaveform,
|
||||
EAXVOCALMORPHER_MINWAVEFORM,
|
||||
EAXVOCALMORPHER_MAXWAVEFORM);
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::validate_rate(
|
||||
float flRate)
|
||||
{
|
||||
eax_validate_range<EaxVocalMorpherEffectException>(
|
||||
"Rate",
|
||||
flRate,
|
||||
EAXVOCALMORPHER_MINRATE,
|
||||
EAXVOCALMORPHER_MAXRATE);
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::validate_all(
|
||||
const EAXVOCALMORPHERPROPERTIES& all)
|
||||
{
|
||||
validate_phoneme_a(all.ulPhonemeA);
|
||||
validate_phoneme_a_coarse_tuning(all.lPhonemeACoarseTuning);
|
||||
validate_phoneme_b(all.ulPhonemeB);
|
||||
validate_phoneme_b_coarse_tuning(all.lPhonemeBCoarseTuning);
|
||||
validate_waveform(all.ulWaveform);
|
||||
validate_rate(all.flRate);
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::defer_phoneme_a(
|
||||
unsigned long ulPhonemeA)
|
||||
{
|
||||
eax_d_.ulPhonemeA = ulPhonemeA;
|
||||
eax_dirty_flags_.ulPhonemeA = (eax_.ulPhonemeA != eax_d_.ulPhonemeA);
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::defer_phoneme_a_coarse_tuning(
|
||||
long lPhonemeACoarseTuning)
|
||||
{
|
||||
eax_d_.lPhonemeACoarseTuning = lPhonemeACoarseTuning;
|
||||
eax_dirty_flags_.lPhonemeACoarseTuning = (eax_.lPhonemeACoarseTuning != eax_d_.lPhonemeACoarseTuning);
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::defer_phoneme_b(
|
||||
unsigned long ulPhonemeB)
|
||||
{
|
||||
eax_d_.ulPhonemeB = ulPhonemeB;
|
||||
eax_dirty_flags_.ulPhonemeB = (eax_.ulPhonemeB != eax_d_.ulPhonemeB);
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::defer_phoneme_b_coarse_tuning(
|
||||
long lPhonemeBCoarseTuning)
|
||||
{
|
||||
eax_d_.lPhonemeBCoarseTuning = lPhonemeBCoarseTuning;
|
||||
eax_dirty_flags_.lPhonemeBCoarseTuning = (eax_.lPhonemeBCoarseTuning != eax_d_.lPhonemeBCoarseTuning);
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::defer_waveform(
|
||||
unsigned long ulWaveform)
|
||||
{
|
||||
eax_d_.ulWaveform = ulWaveform;
|
||||
eax_dirty_flags_.ulWaveform = (eax_.ulWaveform != eax_d_.ulWaveform);
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::defer_rate(
|
||||
float flRate)
|
||||
{
|
||||
eax_d_.flRate = flRate;
|
||||
eax_dirty_flags_.flRate = (eax_.flRate != eax_d_.flRate);
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::defer_all(
|
||||
const EAXVOCALMORPHERPROPERTIES& all)
|
||||
{
|
||||
defer_phoneme_a(all.ulPhonemeA);
|
||||
defer_phoneme_a_coarse_tuning(all.lPhonemeACoarseTuning);
|
||||
defer_phoneme_b(all.ulPhonemeB);
|
||||
defer_phoneme_b_coarse_tuning(all.lPhonemeBCoarseTuning);
|
||||
defer_waveform(all.ulWaveform);
|
||||
defer_rate(all.flRate);
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::defer_phoneme_a(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& phoneme_a = eax_call.get_value<EaxVocalMorpherEffectException,
|
||||
const decltype(EAXVOCALMORPHERPROPERTIES::ulPhonemeA)>();
|
||||
|
||||
validate_phoneme_a(phoneme_a);
|
||||
defer_phoneme_a(phoneme_a);
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::defer_phoneme_a_coarse_tuning(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& phoneme_a_coarse_tuning = eax_call.get_value<
|
||||
EaxVocalMorpherEffectException,
|
||||
const decltype(EAXVOCALMORPHERPROPERTIES::lPhonemeACoarseTuning)
|
||||
>();
|
||||
|
||||
validate_phoneme_a_coarse_tuning(phoneme_a_coarse_tuning);
|
||||
defer_phoneme_a_coarse_tuning(phoneme_a_coarse_tuning);
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::defer_phoneme_b(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& phoneme_b = eax_call.get_value<
|
||||
EaxVocalMorpherEffectException,
|
||||
const decltype(EAXVOCALMORPHERPROPERTIES::ulPhonemeB)
|
||||
>();
|
||||
|
||||
validate_phoneme_b(phoneme_b);
|
||||
defer_phoneme_b(phoneme_b);
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::defer_phoneme_b_coarse_tuning(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& phoneme_b_coarse_tuning = eax_call.get_value<
|
||||
EaxVocalMorpherEffectException,
|
||||
const decltype(EAXVOCALMORPHERPROPERTIES::lPhonemeBCoarseTuning)
|
||||
>();
|
||||
|
||||
validate_phoneme_b_coarse_tuning(phoneme_b_coarse_tuning);
|
||||
defer_phoneme_b_coarse_tuning(phoneme_b_coarse_tuning);
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::defer_waveform(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& waveform = eax_call.get_value<
|
||||
EaxVocalMorpherEffectException,
|
||||
const decltype(EAXVOCALMORPHERPROPERTIES::ulWaveform)
|
||||
>();
|
||||
|
||||
validate_waveform(waveform);
|
||||
defer_waveform(waveform);
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::defer_rate(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& rate = eax_call.get_value<
|
||||
EaxVocalMorpherEffectException,
|
||||
const decltype(EAXVOCALMORPHERPROPERTIES::flRate)
|
||||
>();
|
||||
|
||||
validate_rate(rate);
|
||||
defer_rate(rate);
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::defer_all(
|
||||
const EaxEaxCall& eax_call)
|
||||
{
|
||||
const auto& all = eax_call.get_value<
|
||||
EaxVocalMorpherEffectException,
|
||||
const EAXVOCALMORPHERPROPERTIES
|
||||
>();
|
||||
|
||||
validate_all(all);
|
||||
defer_all(all);
|
||||
}
|
||||
|
||||
// [[nodiscard]]
|
||||
bool EaxVocalMorpherEffect::apply_deferred()
|
||||
{
|
||||
if (eax_dirty_flags_ == EaxVocalMorpherEffectDirtyFlags{})
|
||||
struct PhonemeBValidator {
|
||||
void operator()(unsigned long ulPhonemeB) const
|
||||
{
|
||||
eax_validate_range<VocalMorpherCommitter::Exception>(
|
||||
"Phoneme B",
|
||||
ulPhonemeB,
|
||||
EAXVOCALMORPHER_MINPHONEMEB,
|
||||
EAXVOCALMORPHER_MAXPHONEMEB);
|
||||
}
|
||||
}; // PhonemeBValidator
|
||||
|
||||
struct PhonemeBCoarseTuningValidator {
|
||||
void operator()(long lPhonemeBCoarseTuning) const
|
||||
{
|
||||
eax_validate_range<VocalMorpherCommitter::Exception>(
|
||||
"Phoneme B Coarse Tuning",
|
||||
lPhonemeBCoarseTuning,
|
||||
EAXVOCALMORPHER_MINPHONEMEBCOARSETUNING,
|
||||
EAXVOCALMORPHER_MAXPHONEMEBCOARSETUNING);
|
||||
}
|
||||
}; // PhonemeBCoarseTuningValidator
|
||||
|
||||
struct WaveformValidator {
|
||||
void operator()(unsigned long ulWaveform) const
|
||||
{
|
||||
eax_validate_range<VocalMorpherCommitter::Exception>(
|
||||
"Waveform",
|
||||
ulWaveform,
|
||||
EAXVOCALMORPHER_MINWAVEFORM,
|
||||
EAXVOCALMORPHER_MAXWAVEFORM);
|
||||
}
|
||||
}; // WaveformValidator
|
||||
|
||||
struct RateValidator {
|
||||
void operator()(float flRate) const
|
||||
{
|
||||
eax_validate_range<VocalMorpherCommitter::Exception>(
|
||||
"Rate",
|
||||
flRate,
|
||||
EAXVOCALMORPHER_MINRATE,
|
||||
EAXVOCALMORPHER_MAXRATE);
|
||||
}
|
||||
}; // RateValidator
|
||||
|
||||
struct AllValidator {
|
||||
void operator()(const EAXVOCALMORPHERPROPERTIES& all) const
|
||||
{
|
||||
PhonemeAValidator{}(all.ulPhonemeA);
|
||||
PhonemeACoarseTuningValidator{}(all.lPhonemeACoarseTuning);
|
||||
PhonemeBValidator{}(all.ulPhonemeB);
|
||||
PhonemeBCoarseTuningValidator{}(all.lPhonemeBCoarseTuning);
|
||||
WaveformValidator{}(all.ulWaveform);
|
||||
RateValidator{}(all.flRate);
|
||||
}
|
||||
}; // AllValidator
|
||||
|
||||
} // namespace
|
||||
|
||||
template<>
|
||||
struct VocalMorpherCommitter::Exception : public EaxException {
|
||||
explicit Exception(const char *message) : EaxException{"EAX_VOCAL_MORPHER_EFFECT", message}
|
||||
{ }
|
||||
};
|
||||
|
||||
template<>
|
||||
[[noreturn]] void VocalMorpherCommitter::fail(const char *message)
|
||||
{
|
||||
throw Exception{message};
|
||||
}
|
||||
|
||||
bool EaxVocalMorpherCommitter::commit(const EAXVOCALMORPHERPROPERTIES &props)
|
||||
{
|
||||
if(auto *cur = std::get_if<EAXVOCALMORPHERPROPERTIES>(&mEaxProps); cur && *cur == props)
|
||||
return false;
|
||||
}
|
||||
|
||||
eax_ = eax_d_;
|
||||
mEaxProps = props;
|
||||
|
||||
if (eax_dirty_flags_.ulPhonemeA)
|
||||
auto get_phoneme = [](unsigned long phoneme) noexcept
|
||||
{
|
||||
set_efx_phoneme_a();
|
||||
}
|
||||
|
||||
if (eax_dirty_flags_.lPhonemeACoarseTuning)
|
||||
#define HANDLE_PHENOME(x) case x: return VMorpherPhenome::x
|
||||
switch(phoneme)
|
||||
{
|
||||
HANDLE_PHENOME(A);
|
||||
HANDLE_PHENOME(E);
|
||||
HANDLE_PHENOME(I);
|
||||
HANDLE_PHENOME(O);
|
||||
HANDLE_PHENOME(U);
|
||||
HANDLE_PHENOME(AA);
|
||||
HANDLE_PHENOME(AE);
|
||||
HANDLE_PHENOME(AH);
|
||||
HANDLE_PHENOME(AO);
|
||||
HANDLE_PHENOME(EH);
|
||||
HANDLE_PHENOME(ER);
|
||||
HANDLE_PHENOME(IH);
|
||||
HANDLE_PHENOME(IY);
|
||||
HANDLE_PHENOME(UH);
|
||||
HANDLE_PHENOME(UW);
|
||||
HANDLE_PHENOME(B);
|
||||
HANDLE_PHENOME(D);
|
||||
HANDLE_PHENOME(F);
|
||||
HANDLE_PHENOME(G);
|
||||
HANDLE_PHENOME(J);
|
||||
HANDLE_PHENOME(K);
|
||||
HANDLE_PHENOME(L);
|
||||
HANDLE_PHENOME(M);
|
||||
HANDLE_PHENOME(N);
|
||||
HANDLE_PHENOME(P);
|
||||
HANDLE_PHENOME(R);
|
||||
HANDLE_PHENOME(S);
|
||||
HANDLE_PHENOME(T);
|
||||
HANDLE_PHENOME(V);
|
||||
HANDLE_PHENOME(Z);
|
||||
}
|
||||
return VMorpherPhenome::A;
|
||||
#undef HANDLE_PHENOME
|
||||
};
|
||||
auto get_waveform = [](unsigned long form) noexcept
|
||||
{
|
||||
set_efx_phoneme_a_coarse_tuning();
|
||||
}
|
||||
if(form == EAX_VOCALMORPHER_SINUSOID) return VMorpherWaveform::Sinusoid;
|
||||
if(form == EAX_VOCALMORPHER_TRIANGLE) return VMorpherWaveform::Triangle;
|
||||
if(form == EAX_VOCALMORPHER_SAWTOOTH) return VMorpherWaveform::Sawtooth;
|
||||
return VMorpherWaveform::Sinusoid;
|
||||
};
|
||||
|
||||
if (eax_dirty_flags_.ulPhonemeB)
|
||||
{
|
||||
set_efx_phoneme_b();
|
||||
}
|
||||
|
||||
if (eax_dirty_flags_.lPhonemeBCoarseTuning)
|
||||
{
|
||||
set_efx_phoneme_b_coarse_tuning();
|
||||
}
|
||||
|
||||
if (eax_dirty_flags_.ulWaveform)
|
||||
{
|
||||
set_efx_waveform();
|
||||
}
|
||||
|
||||
if (eax_dirty_flags_.flRate)
|
||||
{
|
||||
set_efx_rate();
|
||||
}
|
||||
|
||||
eax_dirty_flags_ = EaxVocalMorpherEffectDirtyFlags{};
|
||||
mAlProps = [&]{
|
||||
VmorpherProps ret{};
|
||||
ret.PhonemeA = get_phoneme(props.ulPhonemeA);
|
||||
ret.PhonemeACoarseTuning = static_cast<int>(props.lPhonemeACoarseTuning);
|
||||
ret.PhonemeB = get_phoneme(props.ulPhonemeB);
|
||||
ret.PhonemeBCoarseTuning = static_cast<int>(props.lPhonemeBCoarseTuning);
|
||||
ret.Waveform = get_waveform(props.ulWaveform);
|
||||
ret.Rate = props.flRate;
|
||||
return ret;
|
||||
}();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void EaxVocalMorpherEffect::set(const EaxEaxCall& eax_call)
|
||||
void EaxVocalMorpherCommitter::SetDefaults(EaxEffectProps &props)
|
||||
{
|
||||
switch(eax_call.get_property_id())
|
||||
static constexpr EAXVOCALMORPHERPROPERTIES defprops{[]
|
||||
{
|
||||
case EAXVOCALMORPHER_NONE:
|
||||
break;
|
||||
EAXVOCALMORPHERPROPERTIES ret{};
|
||||
ret.ulPhonemeA = EAXVOCALMORPHER_DEFAULTPHONEMEA;
|
||||
ret.lPhonemeACoarseTuning = EAXVOCALMORPHER_DEFAULTPHONEMEACOARSETUNING;
|
||||
ret.ulPhonemeB = EAXVOCALMORPHER_DEFAULTPHONEMEB;
|
||||
ret.lPhonemeBCoarseTuning = EAXVOCALMORPHER_DEFAULTPHONEMEBCOARSETUNING;
|
||||
ret.ulWaveform = EAXVOCALMORPHER_DEFAULTWAVEFORM;
|
||||
ret.flRate = EAXVOCALMORPHER_DEFAULTRATE;
|
||||
return ret;
|
||||
}()};
|
||||
props = defprops;
|
||||
}
|
||||
|
||||
case EAXVOCALMORPHER_ALLPARAMETERS:
|
||||
defer_all(eax_call);
|
||||
break;
|
||||
|
||||
case EAXVOCALMORPHER_PHONEMEA:
|
||||
defer_phoneme_a(eax_call);
|
||||
break;
|
||||
|
||||
case EAXVOCALMORPHER_PHONEMEACOARSETUNING:
|
||||
defer_phoneme_a_coarse_tuning(eax_call);
|
||||
break;
|
||||
|
||||
case EAXVOCALMORPHER_PHONEMEB:
|
||||
defer_phoneme_b(eax_call);
|
||||
break;
|
||||
|
||||
case EAXVOCALMORPHER_PHONEMEBCOARSETUNING:
|
||||
defer_phoneme_b_coarse_tuning(eax_call);
|
||||
break;
|
||||
|
||||
case EAXVOCALMORPHER_WAVEFORM:
|
||||
defer_waveform(eax_call);
|
||||
break;
|
||||
|
||||
case EAXVOCALMORPHER_RATE:
|
||||
defer_rate(eax_call);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw EaxVocalMorpherEffectException{"Unsupported property id."};
|
||||
void EaxVocalMorpherCommitter::Get(const EaxCall &call, const EAXVOCALMORPHERPROPERTIES &props)
|
||||
{
|
||||
switch(call.get_property_id())
|
||||
{
|
||||
case EAXVOCALMORPHER_NONE: break;
|
||||
case EAXVOCALMORPHER_ALLPARAMETERS: call.set_value<Exception>(props); break;
|
||||
case EAXVOCALMORPHER_PHONEMEA: call.set_value<Exception>(props.ulPhonemeA); break;
|
||||
case EAXVOCALMORPHER_PHONEMEACOARSETUNING: call.set_value<Exception>(props.lPhonemeACoarseTuning); break;
|
||||
case EAXVOCALMORPHER_PHONEMEB: call.set_value<Exception>(props.ulPhonemeB); break;
|
||||
case EAXVOCALMORPHER_PHONEMEBCOARSETUNING: call.set_value<Exception>(props.lPhonemeBCoarseTuning); break;
|
||||
case EAXVOCALMORPHER_WAVEFORM: call.set_value<Exception>(props.ulWaveform); break;
|
||||
case EAXVOCALMORPHER_RATE: call.set_value<Exception>(props.flRate); break;
|
||||
default: fail_unknown_property_id();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
EaxEffectUPtr eax_create_eax_vocal_morpher_effect()
|
||||
void EaxVocalMorpherCommitter::Set(const EaxCall &call, EAXVOCALMORPHERPROPERTIES &props)
|
||||
{
|
||||
return std::make_unique<EaxVocalMorpherEffect>();
|
||||
switch(call.get_property_id())
|
||||
{
|
||||
case EAXVOCALMORPHER_NONE: break;
|
||||
case EAXVOCALMORPHER_ALLPARAMETERS: defer<AllValidator>(call, props); break;
|
||||
case EAXVOCALMORPHER_PHONEMEA: defer<PhonemeAValidator>(call, props.ulPhonemeA); break;
|
||||
case EAXVOCALMORPHER_PHONEMEACOARSETUNING: defer<PhonemeACoarseTuningValidator>(call, props.lPhonemeACoarseTuning); break;
|
||||
case EAXVOCALMORPHER_PHONEMEB: defer<PhonemeBValidator>(call, props.ulPhonemeB); break;
|
||||
case EAXVOCALMORPHER_PHONEMEBCOARSETUNING: defer<PhonemeBCoarseTuningValidator>(call, props.lPhonemeBCoarseTuning); break;
|
||||
case EAXVOCALMORPHER_WAVEFORM: defer<WaveformValidator>(call, props.ulWaveform); break;
|
||||
case EAXVOCALMORPHER_RATE: defer<RateValidator>(call, props.flRate); break;
|
||||
default: fail_unknown_property_id();
|
||||
}
|
||||
}
|
||||
|
||||
#endif // ALSOFT_EAX
|
||||
|
||||
Reference in New Issue
Block a user