aboutsummaryrefslogtreecommitdiffstats
path: root/OpenAL32
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-11-24 13:23:27 -0800
committerChris Robinson <[email protected]>2018-11-24 13:23:27 -0800
commit62d38b1187ac3cf64f3e78531a9720279f877e23 (patch)
tree664924b503d3a2475e981c8c58085485e4079bc3 /OpenAL32
parent6a84a2ca614f368791dd9e03139f47601bff42c7 (diff)
Use RAII in alEffect.cpp
Diffstat (limited to 'OpenAL32')
-rw-r--r--OpenAL32/Include/alEffect.h69
-rw-r--r--OpenAL32/alEffect.cpp755
2 files changed, 398 insertions, 426 deletions
diff --git a/OpenAL32/Include/alEffect.h b/OpenAL32/Include/alEffect.h
index 7b849c0c..38540cfc 100644
--- a/OpenAL32/Include/alEffect.h
+++ b/OpenAL32/Include/alEffect.h
@@ -3,9 +3,6 @@
#include "alMain.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
struct ALeffect;
@@ -36,43 +33,43 @@ struct EffectList {
ALenum val;
};
#define EFFECTLIST_SIZE 14
-extern const struct EffectList EffectList[EFFECTLIST_SIZE];
+extern const EffectList EffectList[EFFECTLIST_SIZE];
struct ALeffectVtable {
- void (*const setParami)(struct ALeffect *effect, ALCcontext *context, ALenum param, ALint val);
- void (*const setParamiv)(struct ALeffect *effect, ALCcontext *context, ALenum param, const ALint *vals);
- void (*const setParamf)(struct ALeffect *effect, ALCcontext *context, ALenum param, ALfloat val);
- void (*const setParamfv)(struct ALeffect *effect, ALCcontext *context, ALenum param, const ALfloat *vals);
-
- void (*const getParami)(const struct ALeffect *effect, ALCcontext *context, ALenum param, ALint *val);
- void (*const getParamiv)(const struct ALeffect *effect, ALCcontext *context, ALenum param, ALint *vals);
- void (*const getParamf)(const struct ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *val);
- void (*const getParamfv)(const struct ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *vals);
+ 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 struct ALeffectVtable T##_vtable = { \
+const ALeffectVtable T##_vtable = { \
T##_setParami, T##_setParamiv, \
T##_setParamf, T##_setParamfv, \
T##_getParami, T##_getParamiv, \
T##_getParamf, T##_getParamfv, \
}
-extern const struct ALeffectVtable ALeaxreverb_vtable;
-extern const struct ALeffectVtable ALreverb_vtable;
-extern const struct ALeffectVtable ALautowah_vtable;
-extern const struct ALeffectVtable ALchorus_vtable;
-extern const struct ALeffectVtable ALcompressor_vtable;
-extern const struct ALeffectVtable ALdistortion_vtable;
-extern const struct ALeffectVtable ALecho_vtable;
-extern const struct ALeffectVtable ALequalizer_vtable;
-extern const struct ALeffectVtable ALflanger_vtable;
-extern const struct ALeffectVtable ALfshifter_vtable;
-extern const struct ALeffectVtable ALmodulator_vtable;
-extern const struct ALeffectVtable ALnull_vtable;
-extern const struct ALeffectVtable ALpshifter_vtable;
-extern const struct ALeffectVtable ALdedicated_vtable;
+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;
typedef union ALeffectProps {
@@ -178,17 +175,17 @@ typedef union ALeffectProps {
} Dedicated;
} ALeffectProps;
-typedef struct ALeffect {
+struct ALeffect {
// Effect type (AL_EFFECT_NULL, ...)
- ALenum type;
+ ALenum type{AL_EFFECT_NULL};
- ALeffectProps Props;
+ ALeffectProps Props{};
- const struct ALeffectVtable *vtab;
+ const ALeffectVtable *vtab{nullptr};
/* Self ID */
- ALuint id;
-} ALeffect;
+ ALuint id{0u};
+};
#define ALeffect_setParami(o, c, p, v) ((o)->vtab->setParami(o, c, p, v))
#define ALeffect_setParamf(o, c, p, v) ((o)->vtab->setParamf(o, c, p, v))
#define ALeffect_setParamiv(o, c, p, v) ((o)->vtab->setParamiv(o, c, p, v))
@@ -206,8 +203,4 @@ void ReleaseALEffects(ALCdevice *device);
void LoadReverbPreset(const char *name, ALeffect *effect);
-#ifdef __cplusplus
-}
-#endif
-
#endif
diff --git a/OpenAL32/alEffect.cpp b/OpenAL32/alEffect.cpp
index 54cfad67..e25e2007 100644
--- a/OpenAL32/alEffect.cpp
+++ b/OpenAL32/alEffect.cpp
@@ -54,11 +54,228 @@ const struct EffectList EffectList[EFFECTLIST_SIZE] = {
ALboolean DisabledEffects[MAX_EFFECTS];
-static ALeffect *AllocEffect(ALCcontext *context);
-static void FreeEffect(ALCdevice *device, ALeffect *effect);
-static void InitEffectParams(ALeffect *effect, ALenum type);
+namespace {
-static inline ALeffect *LookupEffect(ALCdevice *device, ALuint id)
+void InitEffectParams(ALeffect *effect, ALenum type)
+{
+ switch(type)
+ {
+ 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->type = type;
+}
+
+ALeffect *AllocEffect(ALCcontext *context)
+{
+ ALCdevice *device = context->Device;
+ almtx_lock(&device->EffectLock);
+
+ auto sublist = std::find_if(device->EffectList.begin(), device->EffectList.end(),
+ [](const EffectSubList &entry) noexcept -> bool
+ { return entry.FreeMask != 0; }
+ );
+
+ auto lidx = std::distance(device->EffectList.begin(), sublist);
+ ALeffect *effect{nullptr};
+ ALsizei slidx{0};
+ if(LIKELY(sublist != device->EffectList.end()))
+ {
+ slidx = CTZ64(sublist->FreeMask);
+ effect = sublist->Effects + slidx;
+ }
+ else
+ {
+ /* Don't allocate so many list entries that the 32-bit ID could
+ * overflow...
+ */
+ if(UNLIKELY(device->EffectList.size() >= 1<<25))
+ {
+ almtx_unlock(&device->EffectLock);
+ alSetError(context, AL_OUT_OF_MEMORY, "Too many effects allocated");
+ return NULL;
+ }
+ device->EffectList.emplace_back();
+ sublist = device->EffectList.end() - 1;
+ sublist->FreeMask = ~U64(0);
+ sublist->Effects = static_cast<ALeffect*>(al_calloc(16, sizeof(ALeffect)*64));
+ if(UNLIKELY(!sublist->Effects))
+ {
+ device->EffectList.pop_back();
+ almtx_unlock(&device->EffectLock);
+ alSetError(context, AL_OUT_OF_MEMORY, "Failed to allocate effect batch");
+ return NULL;
+ }
+
+ slidx = 0;
+ effect = sublist->Effects + slidx;
+ }
+
+ effect = new (effect) ALeffect{};
+ InitEffectParams(effect, AL_EFFECT_NULL);
+
+ /* Add 1 to avoid effect ID 0. */
+ effect->id = ((lidx<<6) | slidx) + 1;
+
+ sublist->FreeMask &= ~(U64(1)<<slidx);
+ almtx_unlock(&device->EffectLock);
+
+ return effect;
+}
+
+void FreeEffect(ALCdevice *device, ALeffect *effect)
+{
+ ALuint id = effect->id - 1;
+ ALsizei lidx = id >> 6;
+ ALsizei slidx = id & 0x3f;
+
+ effect->~ALeffect();
+
+ device->EffectList[lidx].FreeMask |= U64(1) << slidx;
+}
+
+inline ALeffect *LookupEffect(ALCdevice *device, ALuint id)
{
ALuint lidx = (id-1) >> 6;
ALsizei slidx = (id-1) & 0x3f;
@@ -71,127 +288,140 @@ static inline ALeffect *LookupEffect(ALCdevice *device, ALuint id)
return sublist.Effects + slidx;
}
+} // namespace
AL_API ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects)
{
- ALCcontext *context;
- ALsizei cur;
+ ContextRef context{GetContextRef()};
+ if(UNLIKELY(!context)) return;
- context = GetContextRef();
- if(!context) return;
+ if(UNLIKELY(n < 0))
+ {
+ alSetError(context.get(), AL_INVALID_VALUE, "Generating %d effects", n);
+ return;
+ }
- if(n < 0)
- alSetError(context, AL_INVALID_VALUE, "Generating %d effects", n);
- else for(cur = 0;cur < n;cur++)
+ if(LIKELY(n == 1))
{
- ALeffect *effect = AllocEffect(context);
- if(!effect)
- {
- alDeleteEffects(cur, effects);
- break;
- }
- effects[cur] = effect->id;
+ /* Special handling for the easy and normal case. */
+ ALeffect *effect = AllocEffect(context.get());
+ if(effect) effects[0] = effect->id;
}
+ else if(n > 1)
+ {
+ /* Store the allocated buffer IDs in a separate local list, to avoid
+ * modifying the user storage in case of failure.
+ */
+ std::vector<ALuint> ids;
+ ids.reserve(n);
+ do {
+ ALeffect *effect = AllocEffect(context.get());
+ if(!effect)
+ {
+ alDeleteEffects(ids.size(), ids.data());
+ return;
+ }
- ALCcontext_DecRef(context);
+ ids.emplace_back(effect->id);
+ } while(--n);
+ std::copy(ids.begin(), ids.end(), effects);
+ }
}
AL_API ALvoid AL_APIENTRY alDeleteEffects(ALsizei n, const ALuint *effects)
{
- ALCdevice *device;
- ALCcontext *context;
- ALeffect *effect;
- ALsizei i;
-
- context = GetContextRef();
- if(!context) return;
-
- device = context->Device;
- LockEffectList(device);
- if(n < 0)
- SETERR_GOTO(context, AL_INVALID_VALUE, done, "Deleting %d effects", n);
- for(i = 0;i < n;i++)
+ ContextRef context{GetContextRef()};
+ if(UNLIKELY(!context)) return;
+
+ if(UNLIKELY(n < 0))
{
- if(effects[i] && LookupEffect(device, effects[i]) == NULL)
- SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid effect ID %u", effects[i]);
+ alSetError(context.get(), AL_INVALID_VALUE, "Deleting %d effects", n);
+ return;
}
- for(i = 0;i < n;i++)
+ if(UNLIKELY(n == 0))
+ return;
+
+ ALCdevice *device{context->Device};
+ std::lock_guard<almtx_t> _{device->EffectLock};
+
+ /* First try to find any effects that are invalid. */
+ const ALuint *effects_end = effects + n;
+ auto inveffect = std::find_if(effects, effects_end,
+ [device, &context](ALuint eid) -> bool
+ {
+ if(!eid) return false;
+ ALeffect *effect{LookupEffect(device, eid)};
+ if(UNLIKELY(!effect))
+ {
+ alSetError(context.get(), AL_INVALID_NAME, "Invalid effect ID %u", eid);
+ return true;
+ }
+ return false;
+ }
+ );
+ if(LIKELY(inveffect == effects_end))
{
- if((effect=LookupEffect(device, effects[i])) != NULL)
- FreeEffect(device, effect);
+ /* All good. Delete non-0 effect IDs. */
+ std::for_each(effects, effects_end,
+ [device](ALuint eid) -> void
+ {
+ ALeffect *effect{eid ? LookupEffect(device, eid) : nullptr};
+ if(effect) FreeEffect(device, effect);
+ }
+ );
}
-
-done:
- UnlockEffectList(device);
- ALCcontext_DecRef(context);
}
AL_API ALboolean AL_APIENTRY alIsEffect(ALuint effect)
{
- ALCcontext *Context;
- ALboolean result;
-
- Context = GetContextRef();
- if(!Context) return AL_FALSE;
-
- LockEffectList(Context->Device);
- result = ((!effect || LookupEffect(Context->Device, effect)) ?
- AL_TRUE : AL_FALSE);
- UnlockEffectList(Context->Device);
-
- ALCcontext_DecRef(Context);
-
- return result;
+ ContextRef context{GetContextRef()};
+ if(LIKELY(context))
+ {
+ ALCdevice *device{context->Device};
+ std::lock_guard<almtx_t> _{device->EffectLock};
+ if(!effect || LookupEffect(device, effect))
+ return AL_TRUE;
+ }
+ return AL_FALSE;
}
AL_API ALvoid AL_APIENTRY alEffecti(ALuint effect, ALenum param, ALint value)
{
- ALCcontext *Context;
- ALCdevice *Device;
- ALeffect *ALEffect;
+ ContextRef context{GetContextRef()};
+ if(UNLIKELY(!context)) return;
- Context = GetContextRef();
- if(!Context) return;
+ ALCdevice *device{context->Device};
+ std::lock_guard<almtx_t> _{device->EffectLock};
- Device = Context->Device;
- LockEffectList(Device);
- if((ALEffect=LookupEffect(Device, effect)) == NULL)
- alSetError(Context, AL_INVALID_NAME, "Invalid effect ID %u", effect);
+ ALeffect *aleffect{LookupEffect(device, effect)};
+ if(UNLIKELY(!aleffect))
+ alSetError(context.get(), AL_INVALID_NAME, "Invalid effect ID %u", effect);
else
{
if(param == AL_EFFECT_TYPE)
{
ALboolean isOk = (value == AL_EFFECT_NULL);
- ALint i;
- for(i = 0;!isOk && i < EFFECTLIST_SIZE;i++)
+ for(ALsizei i{0};!isOk && i < EFFECTLIST_SIZE;i++)
{
- if(value == EffectList[i].val &&
- !DisabledEffects[EffectList[i].type])
+ if(value == EffectList[i].val && !DisabledEffects[EffectList[i].type])
isOk = AL_TRUE;
}
if(isOk)
- InitEffectParams(ALEffect, value);
+ InitEffectParams(aleffect, value);
else
- alSetError(Context, AL_INVALID_VALUE, "Effect type 0x%04x not supported", value);
+ alSetError(context.get(), AL_INVALID_VALUE, "Effect type 0x%04x not supported", value);
}
else
{
/* Call the appropriate handler */
- ALeffect_setParami(ALEffect, Context, param, value);
+ ALeffect_setParami(aleffect, context.get(), param, value);
}
}
- UnlockEffectList(Device);
-
- ALCcontext_DecRef(Context);
}
AL_API ALvoid AL_APIENTRY alEffectiv(ALuint effect, ALenum param, const ALint *values)
{
- ALCcontext *Context;
- ALCdevice *Device;
- ALeffect *ALEffect;
-
switch(param)
{
case AL_EFFECT_TYPE:
@@ -199,103 +429,83 @@ AL_API ALvoid AL_APIENTRY alEffectiv(ALuint effect, ALenum param, const ALint *v
return;
}
- Context = GetContextRef();
- if(!Context) return;
+ ContextRef context{GetContextRef()};
+ if(UNLIKELY(!context)) return;
- Device = Context->Device;
- LockEffectList(Device);
- if((ALEffect=LookupEffect(Device, effect)) == NULL)
- alSetError(Context, AL_INVALID_NAME, "Invalid effect ID %u", effect);
+ ALCdevice *device{context->Device};
+ std::lock_guard<almtx_t> _{device->EffectLock};
+
+ ALeffect *aleffect{LookupEffect(device, effect)};
+ if(UNLIKELY(!aleffect))
+ alSetError(context.get(), AL_INVALID_NAME, "Invalid effect ID %u", effect);
else
{
/* Call the appropriate handler */
- ALeffect_setParamiv(ALEffect, Context, param, values);
+ ALeffect_setParamiv(aleffect, context.get(), param, values);
}
- UnlockEffectList(Device);
-
- ALCcontext_DecRef(Context);
}
AL_API ALvoid AL_APIENTRY alEffectf(ALuint effect, ALenum param, ALfloat value)
{
- ALCcontext *Context;
- ALCdevice *Device;
- ALeffect *ALEffect;
+ ContextRef context{GetContextRef()};
+ if(UNLIKELY(!context)) return;
- Context = GetContextRef();
- if(!Context) return;
+ ALCdevice *device{context->Device};
+ std::lock_guard<almtx_t> _{device->EffectLock};
- Device = Context->Device;
- LockEffectList(Device);
- if((ALEffect=LookupEffect(Device, effect)) == NULL)
- alSetError(Context, AL_INVALID_NAME, "Invalid effect ID %u", effect);
+ ALeffect *aleffect{LookupEffect(device, effect)};
+ if(UNLIKELY(!aleffect))
+ alSetError(context.get(), AL_INVALID_NAME, "Invalid effect ID %u", effect);
else
{
/* Call the appropriate handler */
- ALeffect_setParamf(ALEffect, Context, param, value);
+ ALeffect_setParamf(aleffect, context.get(), param, value);
}
- UnlockEffectList(Device);
-
- ALCcontext_DecRef(Context);
}
AL_API ALvoid AL_APIENTRY alEffectfv(ALuint effect, ALenum param, const ALfloat *values)
{
- ALCcontext *Context;
- ALCdevice *Device;
- ALeffect *ALEffect;
+ ContextRef context{GetContextRef()};
+ if(UNLIKELY(!context)) return;
- Context = GetContextRef();
- if(!Context) return;
+ ALCdevice *device{context->Device};
+ std::lock_guard<almtx_t> _{device->EffectLock};
- Device = Context->Device;
- LockEffectList(Device);
- if((ALEffect=LookupEffect(Device, effect)) == NULL)
- alSetError(Context, AL_INVALID_NAME, "Invalid effect ID %u", effect);
+ ALeffect *aleffect{LookupEffect(device, effect)};
+ if(UNLIKELY(!aleffect))
+ alSetError(context.get(), AL_INVALID_NAME, "Invalid effect ID %u", effect);
else
{
/* Call the appropriate handler */
- ALeffect_setParamfv(ALEffect, Context, param, values);
+ ALeffect_setParamfv(aleffect, context.get(), param, values);
}
- UnlockEffectList(Device);
-
- ALCcontext_DecRef(Context);
}
AL_API ALvoid AL_APIENTRY alGetEffecti(ALuint effect, ALenum param, ALint *value)
{
- ALCcontext *Context;
- ALCdevice *Device;
- ALeffect *ALEffect;
+ ContextRef context{GetContextRef()};
+ if(UNLIKELY(!context)) return;
- Context = GetContextRef();
- if(!Context) return;
+ ALCdevice *device{context->Device};
+ std::lock_guard<almtx_t> _{device->EffectLock};
- Device = Context->Device;
- LockEffectList(Device);
- if((ALEffect=LookupEffect(Device, effect)) == NULL)
- alSetError(Context, AL_INVALID_NAME, "Invalid effect ID %u", effect);
+ const ALeffect *aleffect{LookupEffect(device, effect)};
+ if(UNLIKELY(!aleffect))
+ alSetError(context.get(), AL_INVALID_NAME, "Invalid effect ID %u", effect);
else
{
if(param == AL_EFFECT_TYPE)
- *value = ALEffect->type;
+ *value = aleffect->type;
else
{
/* Call the appropriate handler */
- ALeffect_getParami(ALEffect, Context, param, value);
+ ALeffect_getParami(aleffect, context.get(), param, value);
}
}
- UnlockEffectList(Device);
-
- ALCcontext_DecRef(Context);
}
AL_API ALvoid AL_APIENTRY alGetEffectiv(ALuint effect, ALenum param, ALint *values)
{
- ALCcontext *Context;
- ALCdevice *Device;
- ALeffect *ALEffect;
-
switch(param)
{
case AL_EFFECT_TYPE:
@@ -303,67 +513,56 @@ AL_API ALvoid AL_APIENTRY alGetEffectiv(ALuint effect, ALenum param, ALint *valu
return;
}
- Context = GetContextRef();
- if(!Context) return;
+ ContextRef context{GetContextRef()};
+ if(UNLIKELY(!context)) return;
+
+ ALCdevice *device{context->Device};
+ std::lock_guard<almtx_t> _{device->EffectLock};
- Device = Context->Device;
- LockEffectList(Device);
- if((ALEffect=LookupEffect(Device, effect)) == NULL)
- alSetError(Context, AL_INVALID_NAME, "Invalid effect ID %u", effect);
+ const ALeffect *aleffect{LookupEffect(device, effect)};
+ if(UNLIKELY(!aleffect))
+ alSetError(context.get(), AL_INVALID_NAME, "Invalid effect ID %u", effect);
else
{
/* Call the appropriate handler */
- ALeffect_getParamiv(ALEffect, Context, param, values);
+ ALeffect_getParamiv(aleffect, context.get(), param, values);
}
- UnlockEffectList(Device);
-
- ALCcontext_DecRef(Context);
}
AL_API ALvoid AL_APIENTRY alGetEffectf(ALuint effect, ALenum param, ALfloat *value)
{
- ALCcontext *Context;
- ALCdevice *Device;
- ALeffect *ALEffect;
+ ContextRef context{GetContextRef()};
+ if(UNLIKELY(!context)) return;
- Context = GetContextRef();
- if(!Context) return;
+ ALCdevice *device{context->Device};
+ std::lock_guard<almtx_t> _{device->EffectLock};
- Device = Context->Device;
- LockEffectList(Device);
- if((ALEffect=LookupEffect(Device, effect)) == NULL)
- alSetError(Context, AL_INVALID_NAME, "Invalid effect ID %u", effect);
+ const ALeffect *aleffect{LookupEffect(device, effect)};
+ if(UNLIKELY(!aleffect))
+ alSetError(context.get(), AL_INVALID_NAME, "Invalid effect ID %u", effect);
else
{
/* Call the appropriate handler */
- ALeffect_getParamf(ALEffect, Context, param, value);
+ ALeffect_getParamf(aleffect, context.get(), param, value);
}
- UnlockEffectList(Device);
-
- ALCcontext_DecRef(Context);
}
AL_API ALvoid AL_APIENTRY alGetEffectfv(ALuint effect, ALenum param, ALfloat *values)
{
- ALCcontext *Context;
- ALCdevice *Device;
- ALeffect *ALEffect;
+ ContextRef context{GetContextRef()};
+ if(UNLIKELY(!context)) return;
- Context = GetContextRef();
- if(!Context) return;
+ ALCdevice *device{context->Device};
+ std::lock_guard<almtx_t> _{device->EffectLock};
- Device = Context->Device;
- LockEffectList(Device);
- if((ALEffect=LookupEffect(Device, effect)) == NULL)
- alSetError(Context, AL_INVALID_NAME, "Invalid effect ID %u", effect);
+ const ALeffect *aleffect{LookupEffect(device, effect)};
+ if(UNLIKELY(!aleffect))
+ alSetError(context.get(), AL_INVALID_NAME, "Invalid effect ID %u", effect);
else
{
/* Call the appropriate handler */
- ALeffect_getParamfv(ALEffect, Context, param, values);
+ ALeffect_getParamfv(aleffect, context.get(), param, values);
}
- UnlockEffectList(Device);
-
- ALCcontext_DecRef(Context);
}
@@ -372,74 +571,6 @@ void InitEffect(ALeffect *effect)
InitEffectParams(effect, AL_EFFECT_NULL);
}
-static ALeffect *AllocEffect(ALCcontext *context)
-{
- ALCdevice *device = context->Device;
- almtx_lock(&device->EffectLock);
-
- auto sublist = std::find_if(device->EffectList.begin(), device->EffectList.end(),
- [](const EffectSubList &entry) noexcept -> bool
- { return entry.FreeMask != 0; }
- );
-
- auto lidx = std::distance(device->EffectList.begin(), sublist);
- ALeffect *effect{nullptr};
- ALsizei slidx{0};
- if(LIKELY(sublist != device->EffectList.end()))
- {
- slidx = CTZ64(sublist->FreeMask);
- effect = sublist->Effects + slidx;
- }
- else
- {
- /* Don't allocate so many list entries that the 32-bit ID could
- * overflow...
- */
- if(UNLIKELY(device->EffectList.size() >= 1<<25))
- {
- almtx_unlock(&device->EffectLock);
- alSetError(context, AL_OUT_OF_MEMORY, "Too many effects allocated");
- return NULL;
- }
- device->EffectList.emplace_back();
- sublist = device->EffectList.end() - 1;
- sublist->FreeMask = ~U64(0);
- sublist->Effects = static_cast<ALeffect*>(al_calloc(16, sizeof(ALeffect)*64));
- if(UNLIKELY(!sublist->Effects))
- {
- device->EffectList.pop_back();
- almtx_unlock(&device->EffectLock);
- alSetError(context, AL_OUT_OF_MEMORY, "Failed to allocate effect batch");
- return NULL;
- }
-
- slidx = 0;
- effect = sublist->Effects + slidx;
- }
-
- effect = new (effect) ALeffect{};
- InitEffectParams(effect, AL_EFFECT_NULL);
-
- /* Add 1 to avoid effect ID 0. */
- effect->id = ((lidx<<6) | slidx) + 1;
-
- sublist->FreeMask &= ~(U64(1)<<slidx);
- almtx_unlock(&device->EffectLock);
-
- return effect;
-}
-
-static void FreeEffect(ALCdevice *device, ALeffect *effect)
-{
- ALuint id = effect->id - 1;
- ALsizei lidx = id >> 6;
- ALsizei slidx = id & 0x3f;
-
- effect->~ALeffect();
-
- device->EffectList[lidx].FreeMask |= U64(1) << slidx;
-}
-
void ReleaseALEffects(ALCdevice *device)
{
size_t leftover = 0;
@@ -463,158 +594,6 @@ void ReleaseALEffects(ALCdevice *device)
}
-static void InitEffectParams(ALeffect *effect, ALenum type)
-{
- switch(type)
- {
- 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->type = type;
-}
-
-
#include "AL/efx-presets.h"
#define DECL(x) { #x, EFX_REVERB_PRESET_##x }