diff options
author | Chris Robinson <[email protected]> | 2019-03-22 13:33:58 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-03-22 15:00:37 -0700 |
commit | e7e585f65c43e2ccd2ae71c36c4940f4b2efa80a (patch) | |
tree | 4851d04798701f67e3c6ca437111129cedaf9f65 /OpenAL32 | |
parent | f951f4a66b3e9cc8db7ab190b8443fa6c834fee7 (diff) |
Use the effect state factory to set the default effect props
Diffstat (limited to 'OpenAL32')
-rw-r--r-- | OpenAL32/Include/alAuxEffectSlot.h | 49 | ||||
-rw-r--r-- | OpenAL32/Include/alEffect.h | 41 | ||||
-rw-r--r-- | OpenAL32/alAuxEffectSlot.cpp | 30 | ||||
-rw-r--r-- | OpenAL32/alEffect.cpp | 186 |
4 files changed, 48 insertions, 258 deletions
diff --git a/OpenAL32/Include/alAuxEffectSlot.h b/OpenAL32/Include/alAuxEffectSlot.h index 7d5775d4..b3323578 100644 --- a/OpenAL32/Include/alAuxEffectSlot.h +++ b/OpenAL32/Include/alAuxEffectSlot.h @@ -6,6 +6,7 @@ #include "alMain.h" #include "alEffect.h" #include "ambidefs.h" +#include "effects/base.h" #include "almalloc.h" #include "atomic.h" @@ -15,37 +16,6 @@ struct ALeffectslot; union ALeffectProps; -struct EffectTarget { - MixParams *Main; - RealMixParams *RealOut; -}; - -struct EffectState { - RefCount mRef{1u}; - - ALfloat (*mOutBuffer)[BUFFERSIZE]{nullptr}; - ALsizei mOutChannels{0}; - - - virtual ~EffectState() = default; - - virtual ALboolean deviceUpdate(const ALCdevice *device) = 0; - virtual void update(const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props, const EffectTarget target) = 0; - virtual void process(ALsizei samplesToDo, const ALfloat (*RESTRICT samplesIn)[BUFFERSIZE], const ALsizei numInput, ALfloat (*RESTRICT samplesOut)[BUFFERSIZE], const ALsizei numOutput) = 0; - - void IncRef() noexcept; - void DecRef() noexcept; -}; - - -struct EffectStateFactory { - virtual ~EffectStateFactory() { } - - virtual EffectState *create() = 0; - virtual ALeffectProps getDefaultProps() const noexcept = 0; -}; - - using ALeffectslotArray = al::FlexArray<ALeffectslot*>; @@ -124,23 +94,6 @@ void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context); void UpdateAllEffectSlotProps(ALCcontext *context); -EffectStateFactory *NullStateFactory_getFactory(void); -EffectStateFactory *ReverbStateFactory_getFactory(void); -EffectStateFactory *StdReverbStateFactory_getFactory(void); -EffectStateFactory *AutowahStateFactory_getFactory(void); -EffectStateFactory *ChorusStateFactory_getFactory(void); -EffectStateFactory *CompressorStateFactory_getFactory(void); -EffectStateFactory *DistortionStateFactory_getFactory(void); -EffectStateFactory *EchoStateFactory_getFactory(void); -EffectStateFactory *EqualizerStateFactory_getFactory(void); -EffectStateFactory *FlangerStateFactory_getFactory(void); -EffectStateFactory *FshifterStateFactory_getFactory(void); -EffectStateFactory *ModulatorStateFactory_getFactory(void); -EffectStateFactory *PshifterStateFactory_getFactory(void); - -EffectStateFactory *DedicatedStateFactory_getFactory(void); - - ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect *effect); #endif diff --git a/OpenAL32/Include/alEffect.h b/OpenAL32/Include/alEffect.h index 710f512a..fdd1b017 100644 --- a/OpenAL32/Include/alEffect.h +++ b/OpenAL32/Include/alEffect.h @@ -5,6 +5,8 @@ struct ALeffect; +struct EffectVtable; +struct EffectStateFactory; enum { EAXREVERB_EFFECT = 0, @@ -34,41 +36,6 @@ struct EffectList { }; extern const EffectList gEffectList[14]; -struct ALeffectVtable { - void (*const setParami)(ALeffect *effect, ALCcontext *context, ALenum param, ALint val); - void (*const setParamiv)(ALeffect *effect, ALCcontext *context, ALenum param, const ALint *vals); - void (*const setParamf)(ALeffect *effect, ALCcontext *context, ALenum param, ALfloat val); - void (*const setParamfv)(ALeffect *effect, ALCcontext *context, ALenum param, const ALfloat *vals); - - void (*const getParami)(const ALeffect *effect, ALCcontext *context, ALenum param, ALint *val); - void (*const getParamiv)(const ALeffect *effect, ALCcontext *context, ALenum param, ALint *vals); - void (*const getParamf)(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *val); - void (*const getParamfv)(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *vals); -}; - -#define DEFINE_ALEFFECT_VTABLE(T) \ -const ALeffectVtable T##_vtable = { \ - T##_setParami, T##_setParamiv, \ - T##_setParamf, T##_setParamfv, \ - T##_getParami, T##_getParamiv, \ - T##_getParamf, T##_getParamfv, \ -} - -extern const ALeffectVtable ALeaxreverb_vtable; -extern const ALeffectVtable ALreverb_vtable; -extern const ALeffectVtable ALautowah_vtable; -extern const ALeffectVtable ALchorus_vtable; -extern const ALeffectVtable ALcompressor_vtable; -extern const ALeffectVtable ALdistortion_vtable; -extern const ALeffectVtable ALecho_vtable; -extern const ALeffectVtable ALequalizer_vtable; -extern const ALeffectVtable ALflanger_vtable; -extern const ALeffectVtable ALfshifter_vtable; -extern const ALeffectVtable ALmodulator_vtable; -extern const ALeffectVtable ALnull_vtable; -extern const ALeffectVtable ALpshifter_vtable; -extern const ALeffectVtable ALdedicated_vtable; - union ALeffectProps { struct { @@ -179,7 +146,7 @@ struct ALeffect { ALeffectProps Props{}; - const ALeffectVtable *vtab{nullptr}; + const EffectVtable *vtab{nullptr}; /* Self ID */ ALuint id{0u}; @@ -196,6 +163,8 @@ struct ALeffect { inline ALboolean IsReverbEffect(ALenum type) { return type == AL_EFFECT_REVERB || type == AL_EFFECT_EAXREVERB; } +EffectStateFactory *getFactoryByType(ALenum type); + void InitEffect(ALeffect *effect); void LoadReverbPreset(const char *name, ALeffect *effect); diff --git a/OpenAL32/alAuxEffectSlot.cpp b/OpenAL32/alAuxEffectSlot.cpp index 473c7240..b8b73bed 100644 --- a/OpenAL32/alAuxEffectSlot.cpp +++ b/OpenAL32/alAuxEffectSlot.cpp @@ -150,36 +150,6 @@ void RemoveActiveEffectSlots(const ALuint *slotids, ALsizei count, ALCcontext *c delete curarray; } -constexpr struct FactoryItem { - ALenum Type; - EffectStateFactory* (&GetFactory)(void); -} FactoryList[] = { - { AL_EFFECT_NULL, NullStateFactory_getFactory }, - { AL_EFFECT_EAXREVERB, ReverbStateFactory_getFactory }, - { AL_EFFECT_REVERB, StdReverbStateFactory_getFactory }, - { AL_EFFECT_AUTOWAH, AutowahStateFactory_getFactory }, - { AL_EFFECT_CHORUS, ChorusStateFactory_getFactory }, - { AL_EFFECT_COMPRESSOR, CompressorStateFactory_getFactory }, - { AL_EFFECT_DISTORTION, DistortionStateFactory_getFactory }, - { AL_EFFECT_ECHO, EchoStateFactory_getFactory }, - { AL_EFFECT_EQUALIZER, EqualizerStateFactory_getFactory }, - { AL_EFFECT_FLANGER, FlangerStateFactory_getFactory }, - { AL_EFFECT_FREQUENCY_SHIFTER, FshifterStateFactory_getFactory }, - { AL_EFFECT_RING_MODULATOR, ModulatorStateFactory_getFactory }, - { AL_EFFECT_PITCH_SHIFTER, PshifterStateFactory_getFactory}, - { AL_EFFECT_DEDICATED_DIALOGUE, DedicatedStateFactory_getFactory }, - { AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT, DedicatedStateFactory_getFactory } -}; - -EffectStateFactory *getFactoryByType(ALenum type) -{ - auto iter = std::find_if(std::begin(FactoryList), std::end(FactoryList), - [type](const FactoryItem &item) noexcept -> bool - { return item.Type == type; } - ); - return (iter != std::end(FactoryList)) ? iter->GetFactory() : nullptr; -} - ALeffectslot *AllocEffectSlot(ALCcontext *context) { diff --git a/OpenAL32/alEffect.cpp b/OpenAL32/alEffect.cpp index 0c11af98..275ac34c 100644 --- a/OpenAL32/alEffect.cpp +++ b/OpenAL32/alEffect.cpp @@ -33,6 +33,7 @@ #include "alcontext.h" #include "alEffect.h" #include "alError.h" +#include "effects/base.h" const EffectList gEffectList[14]{ @@ -56,153 +57,40 @@ ALboolean DisabledEffects[MAX_EFFECTS]; namespace { +constexpr struct FactoryItem { + ALenum Type; + EffectStateFactory* (&GetFactory)(void); +} FactoryList[] = { + { AL_EFFECT_NULL, NullStateFactory_getFactory }, + { AL_EFFECT_EAXREVERB, ReverbStateFactory_getFactory }, + { AL_EFFECT_REVERB, StdReverbStateFactory_getFactory }, + { AL_EFFECT_AUTOWAH, AutowahStateFactory_getFactory }, + { AL_EFFECT_CHORUS, ChorusStateFactory_getFactory }, + { AL_EFFECT_COMPRESSOR, CompressorStateFactory_getFactory }, + { AL_EFFECT_DISTORTION, DistortionStateFactory_getFactory }, + { AL_EFFECT_ECHO, EchoStateFactory_getFactory }, + { AL_EFFECT_EQUALIZER, EqualizerStateFactory_getFactory }, + { AL_EFFECT_FLANGER, FlangerStateFactory_getFactory }, + { AL_EFFECT_FREQUENCY_SHIFTER, FshifterStateFactory_getFactory }, + { AL_EFFECT_RING_MODULATOR, ModulatorStateFactory_getFactory }, + { AL_EFFECT_PITCH_SHIFTER, PshifterStateFactory_getFactory}, + { AL_EFFECT_DEDICATED_DIALOGUE, DedicatedStateFactory_getFactory }, + { AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT, DedicatedStateFactory_getFactory } +}; + + void InitEffectParams(ALeffect *effect, ALenum type) { - switch(type) + EffectStateFactory *factory = getFactoryByType(type); + if(factory) + { + effect->Props = factory->getDefaultProps(); + effect->vtab = factory->getEffectVtable(); + } + else { - case AL_EFFECT_EAXREVERB: - effect->Props.Reverb.Density = AL_EAXREVERB_DEFAULT_DENSITY; - effect->Props.Reverb.Diffusion = AL_EAXREVERB_DEFAULT_DIFFUSION; - effect->Props.Reverb.Gain = AL_EAXREVERB_DEFAULT_GAIN; - effect->Props.Reverb.GainHF = AL_EAXREVERB_DEFAULT_GAINHF; - effect->Props.Reverb.GainLF = AL_EAXREVERB_DEFAULT_GAINLF; - effect->Props.Reverb.DecayTime = AL_EAXREVERB_DEFAULT_DECAY_TIME; - effect->Props.Reverb.DecayHFRatio = AL_EAXREVERB_DEFAULT_DECAY_HFRATIO; - effect->Props.Reverb.DecayLFRatio = AL_EAXREVERB_DEFAULT_DECAY_LFRATIO; - effect->Props.Reverb.ReflectionsGain = AL_EAXREVERB_DEFAULT_REFLECTIONS_GAIN; - effect->Props.Reverb.ReflectionsDelay = AL_EAXREVERB_DEFAULT_REFLECTIONS_DELAY; - effect->Props.Reverb.ReflectionsPan[0] = AL_EAXREVERB_DEFAULT_REFLECTIONS_PAN_XYZ; - effect->Props.Reverb.ReflectionsPan[1] = AL_EAXREVERB_DEFAULT_REFLECTIONS_PAN_XYZ; - effect->Props.Reverb.ReflectionsPan[2] = AL_EAXREVERB_DEFAULT_REFLECTIONS_PAN_XYZ; - effect->Props.Reverb.LateReverbGain = AL_EAXREVERB_DEFAULT_LATE_REVERB_GAIN; - effect->Props.Reverb.LateReverbDelay = AL_EAXREVERB_DEFAULT_LATE_REVERB_DELAY; - effect->Props.Reverb.LateReverbPan[0] = AL_EAXREVERB_DEFAULT_LATE_REVERB_PAN_XYZ; - effect->Props.Reverb.LateReverbPan[1] = AL_EAXREVERB_DEFAULT_LATE_REVERB_PAN_XYZ; - effect->Props.Reverb.LateReverbPan[2] = AL_EAXREVERB_DEFAULT_LATE_REVERB_PAN_XYZ; - effect->Props.Reverb.EchoTime = AL_EAXREVERB_DEFAULT_ECHO_TIME; - effect->Props.Reverb.EchoDepth = AL_EAXREVERB_DEFAULT_ECHO_DEPTH; - effect->Props.Reverb.ModulationTime = AL_EAXREVERB_DEFAULT_MODULATION_TIME; - effect->Props.Reverb.ModulationDepth = AL_EAXREVERB_DEFAULT_MODULATION_DEPTH; - effect->Props.Reverb.AirAbsorptionGainHF = AL_EAXREVERB_DEFAULT_AIR_ABSORPTION_GAINHF; - effect->Props.Reverb.HFReference = AL_EAXREVERB_DEFAULT_HFREFERENCE; - effect->Props.Reverb.LFReference = AL_EAXREVERB_DEFAULT_LFREFERENCE; - effect->Props.Reverb.RoomRolloffFactor = AL_EAXREVERB_DEFAULT_ROOM_ROLLOFF_FACTOR; - effect->Props.Reverb.DecayHFLimit = AL_EAXREVERB_DEFAULT_DECAY_HFLIMIT; - effect->vtab = &ALeaxreverb_vtable; - break; - case AL_EFFECT_REVERB: - effect->Props.Reverb.Density = AL_REVERB_DEFAULT_DENSITY; - effect->Props.Reverb.Diffusion = AL_REVERB_DEFAULT_DIFFUSION; - effect->Props.Reverb.Gain = AL_REVERB_DEFAULT_GAIN; - effect->Props.Reverb.GainHF = AL_REVERB_DEFAULT_GAINHF; - effect->Props.Reverb.GainLF = 1.0f; - effect->Props.Reverb.DecayTime = AL_REVERB_DEFAULT_DECAY_TIME; - effect->Props.Reverb.DecayHFRatio = AL_REVERB_DEFAULT_DECAY_HFRATIO; - effect->Props.Reverb.DecayLFRatio = 1.0f; - effect->Props.Reverb.ReflectionsGain = AL_REVERB_DEFAULT_REFLECTIONS_GAIN; - effect->Props.Reverb.ReflectionsDelay = AL_REVERB_DEFAULT_REFLECTIONS_DELAY; - effect->Props.Reverb.ReflectionsPan[0] = 0.0f; - effect->Props.Reverb.ReflectionsPan[1] = 0.0f; - effect->Props.Reverb.ReflectionsPan[2] = 0.0f; - effect->Props.Reverb.LateReverbGain = AL_REVERB_DEFAULT_LATE_REVERB_GAIN; - effect->Props.Reverb.LateReverbDelay = AL_REVERB_DEFAULT_LATE_REVERB_DELAY; - effect->Props.Reverb.LateReverbPan[0] = 0.0f; - effect->Props.Reverb.LateReverbPan[1] = 0.0f; - effect->Props.Reverb.LateReverbPan[2] = 0.0f; - effect->Props.Reverb.EchoTime = 0.25f; - effect->Props.Reverb.EchoDepth = 0.0f; - effect->Props.Reverb.ModulationTime = 0.25f; - effect->Props.Reverb.ModulationDepth = 0.0f; - effect->Props.Reverb.AirAbsorptionGainHF = AL_REVERB_DEFAULT_AIR_ABSORPTION_GAINHF; - effect->Props.Reverb.HFReference = 5000.0f; - effect->Props.Reverb.LFReference = 250.0f; - effect->Props.Reverb.RoomRolloffFactor = AL_REVERB_DEFAULT_ROOM_ROLLOFF_FACTOR; - effect->Props.Reverb.DecayHFLimit = AL_REVERB_DEFAULT_DECAY_HFLIMIT; - effect->vtab = &ALreverb_vtable; - break; - case AL_EFFECT_AUTOWAH: - effect->Props.Autowah.AttackTime = AL_AUTOWAH_DEFAULT_ATTACK_TIME; - effect->Props.Autowah.ReleaseTime = AL_AUTOWAH_DEFAULT_RELEASE_TIME; - effect->Props.Autowah.Resonance = AL_AUTOWAH_DEFAULT_RESONANCE; - effect->Props.Autowah.PeakGain = AL_AUTOWAH_DEFAULT_PEAK_GAIN; - effect->vtab = &ALautowah_vtable; - break; - case AL_EFFECT_CHORUS: - effect->Props.Chorus.Waveform = AL_CHORUS_DEFAULT_WAVEFORM; - effect->Props.Chorus.Phase = AL_CHORUS_DEFAULT_PHASE; - effect->Props.Chorus.Rate = AL_CHORUS_DEFAULT_RATE; - effect->Props.Chorus.Depth = AL_CHORUS_DEFAULT_DEPTH; - effect->Props.Chorus.Feedback = AL_CHORUS_DEFAULT_FEEDBACK; - effect->Props.Chorus.Delay = AL_CHORUS_DEFAULT_DELAY; - effect->vtab = &ALchorus_vtable; - break; - case AL_EFFECT_COMPRESSOR: - effect->Props.Compressor.OnOff = AL_COMPRESSOR_DEFAULT_ONOFF; - effect->vtab = &ALcompressor_vtable; - break; - case AL_EFFECT_DISTORTION: - effect->Props.Distortion.Edge = AL_DISTORTION_DEFAULT_EDGE; - effect->Props.Distortion.Gain = AL_DISTORTION_DEFAULT_GAIN; - effect->Props.Distortion.LowpassCutoff = AL_DISTORTION_DEFAULT_LOWPASS_CUTOFF; - effect->Props.Distortion.EQCenter = AL_DISTORTION_DEFAULT_EQCENTER; - effect->Props.Distortion.EQBandwidth = AL_DISTORTION_DEFAULT_EQBANDWIDTH; - effect->vtab = &ALdistortion_vtable; - break; - case AL_EFFECT_ECHO: - effect->Props.Echo.Delay = AL_ECHO_DEFAULT_DELAY; - effect->Props.Echo.LRDelay = AL_ECHO_DEFAULT_LRDELAY; - effect->Props.Echo.Damping = AL_ECHO_DEFAULT_DAMPING; - effect->Props.Echo.Feedback = AL_ECHO_DEFAULT_FEEDBACK; - effect->Props.Echo.Spread = AL_ECHO_DEFAULT_SPREAD; - effect->vtab = &ALecho_vtable; - break; - case AL_EFFECT_EQUALIZER: - effect->Props.Equalizer.LowCutoff = AL_EQUALIZER_DEFAULT_LOW_CUTOFF; - effect->Props.Equalizer.LowGain = AL_EQUALIZER_DEFAULT_LOW_GAIN; - effect->Props.Equalizer.Mid1Center = AL_EQUALIZER_DEFAULT_MID1_CENTER; - effect->Props.Equalizer.Mid1Gain = AL_EQUALIZER_DEFAULT_MID1_GAIN; - effect->Props.Equalizer.Mid1Width = AL_EQUALIZER_DEFAULT_MID1_WIDTH; - effect->Props.Equalizer.Mid2Center = AL_EQUALIZER_DEFAULT_MID2_CENTER; - effect->Props.Equalizer.Mid2Gain = AL_EQUALIZER_DEFAULT_MID2_GAIN; - effect->Props.Equalizer.Mid2Width = AL_EQUALIZER_DEFAULT_MID2_WIDTH; - effect->Props.Equalizer.HighCutoff = AL_EQUALIZER_DEFAULT_HIGH_CUTOFF; - effect->Props.Equalizer.HighGain = AL_EQUALIZER_DEFAULT_HIGH_GAIN; - effect->vtab = &ALequalizer_vtable; - break; - case AL_EFFECT_FLANGER: - effect->Props.Chorus.Waveform = AL_FLANGER_DEFAULT_WAVEFORM; - effect->Props.Chorus.Phase = AL_FLANGER_DEFAULT_PHASE; - effect->Props.Chorus.Rate = AL_FLANGER_DEFAULT_RATE; - effect->Props.Chorus.Depth = AL_FLANGER_DEFAULT_DEPTH; - effect->Props.Chorus.Feedback = AL_FLANGER_DEFAULT_FEEDBACK; - effect->Props.Chorus.Delay = AL_FLANGER_DEFAULT_DELAY; - effect->vtab = &ALflanger_vtable; - break; - case AL_EFFECT_FREQUENCY_SHIFTER: - effect->Props.Fshifter.Frequency = AL_FREQUENCY_SHIFTER_DEFAULT_FREQUENCY; - effect->Props.Fshifter.LeftDirection = AL_FREQUENCY_SHIFTER_DEFAULT_LEFT_DIRECTION; - effect->Props.Fshifter.RightDirection = AL_FREQUENCY_SHIFTER_DEFAULT_RIGHT_DIRECTION; - effect->vtab = &ALfshifter_vtable; - break; - case AL_EFFECT_RING_MODULATOR: - effect->Props.Modulator.Frequency = AL_RING_MODULATOR_DEFAULT_FREQUENCY; - effect->Props.Modulator.HighPassCutoff = AL_RING_MODULATOR_DEFAULT_HIGHPASS_CUTOFF; - effect->Props.Modulator.Waveform = AL_RING_MODULATOR_DEFAULT_WAVEFORM; - effect->vtab = &ALmodulator_vtable; - break; - case AL_EFFECT_PITCH_SHIFTER: - effect->Props.Pshifter.CoarseTune = AL_PITCH_SHIFTER_DEFAULT_COARSE_TUNE; - effect->Props.Pshifter.FineTune = AL_PITCH_SHIFTER_DEFAULT_FINE_TUNE; - effect->vtab = &ALpshifter_vtable; - break; - case AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT: - case AL_EFFECT_DEDICATED_DIALOGUE: - effect->Props.Dedicated.Gain = 1.0f; - effect->vtab = &ALdedicated_vtable; - break; - default: - effect->vtab = &ALnull_vtable; - break; + effect->Props = ALeffectProps{}; + effect->vtab = nullptr; } effect->type = type; } @@ -582,6 +470,16 @@ EffectSubList::~EffectSubList() } +EffectStateFactory *getFactoryByType(ALenum type) +{ + auto iter = std::find_if(std::begin(FactoryList), std::end(FactoryList), + [type](const FactoryItem &item) noexcept -> bool + { return item.Type == type; } + ); + return (iter != std::end(FactoryList)) ? iter->GetFactory() : nullptr; +} + + #include "AL/efx-presets.h" #define DECL(x) { #x, EFX_REVERB_PRESET_##x } |