2019-03-22 13:33:58 -07:00
|
|
|
#ifndef EFFECTS_BASE_H
|
|
|
|
#define EFFECTS_BASE_H
|
|
|
|
|
2019-08-20 14:30:04 -07:00
|
|
|
#include <cstddef>
|
|
|
|
|
2019-07-28 18:33:29 -07:00
|
|
|
#include "alcmain.h"
|
2020-04-10 18:26:08 -07:00
|
|
|
#include "alexcpt.h"
|
2019-03-22 13:33:58 -07:00
|
|
|
#include "almalloc.h"
|
2019-05-29 22:31:36 -07:00
|
|
|
#include "alspan.h"
|
2019-03-22 13:33:58 -07:00
|
|
|
#include "atomic.h"
|
2019-08-01 13:28:53 -07:00
|
|
|
#include "intrusive_ptr.h"
|
2019-03-22 13:33:58 -07:00
|
|
|
|
|
|
|
struct ALeffectslot;
|
2020-08-28 00:44:55 -07:00
|
|
|
struct BufferStorage;
|
2019-03-22 22:48:12 -07:00
|
|
|
|
|
|
|
|
|
|
|
union EffectProps {
|
|
|
|
struct {
|
|
|
|
// Shared Reverb Properties
|
2020-03-28 14:34:51 -07:00
|
|
|
float Density;
|
|
|
|
float Diffusion;
|
|
|
|
float Gain;
|
|
|
|
float GainHF;
|
|
|
|
float DecayTime;
|
|
|
|
float DecayHFRatio;
|
|
|
|
float ReflectionsGain;
|
|
|
|
float ReflectionsDelay;
|
|
|
|
float LateReverbGain;
|
|
|
|
float LateReverbDelay;
|
|
|
|
float AirAbsorptionGainHF;
|
|
|
|
float RoomRolloffFactor;
|
2019-09-14 10:59:02 -07:00
|
|
|
bool DecayHFLimit;
|
2019-03-22 22:48:12 -07:00
|
|
|
|
|
|
|
// Additional EAX Reverb Properties
|
2020-03-28 14:34:51 -07:00
|
|
|
float GainLF;
|
|
|
|
float DecayLFRatio;
|
|
|
|
float ReflectionsPan[3];
|
|
|
|
float LateReverbPan[3];
|
|
|
|
float EchoTime;
|
|
|
|
float EchoDepth;
|
|
|
|
float ModulationTime;
|
|
|
|
float ModulationDepth;
|
|
|
|
float HFReference;
|
|
|
|
float LFReference;
|
2019-03-22 22:48:12 -07:00
|
|
|
} Reverb;
|
|
|
|
|
|
|
|
struct {
|
2020-03-28 14:34:51 -07:00
|
|
|
float AttackTime;
|
|
|
|
float ReleaseTime;
|
|
|
|
float Resonance;
|
|
|
|
float PeakGain;
|
2019-03-22 22:48:12 -07:00
|
|
|
} Autowah;
|
|
|
|
|
|
|
|
struct {
|
2020-03-28 14:34:51 -07:00
|
|
|
int Waveform;
|
|
|
|
int Phase;
|
|
|
|
float Rate;
|
|
|
|
float Depth;
|
|
|
|
float Feedback;
|
|
|
|
float Delay;
|
2019-03-22 22:48:12 -07:00
|
|
|
} Chorus; /* Also Flanger */
|
|
|
|
|
|
|
|
struct {
|
2019-09-14 10:59:02 -07:00
|
|
|
bool OnOff;
|
2019-03-22 22:48:12 -07:00
|
|
|
} Compressor;
|
|
|
|
|
|
|
|
struct {
|
2020-03-28 14:34:51 -07:00
|
|
|
float Edge;
|
|
|
|
float Gain;
|
|
|
|
float LowpassCutoff;
|
|
|
|
float EQCenter;
|
|
|
|
float EQBandwidth;
|
2019-03-22 22:48:12 -07:00
|
|
|
} Distortion;
|
|
|
|
|
|
|
|
struct {
|
2020-03-28 14:34:51 -07:00
|
|
|
float Delay;
|
|
|
|
float LRDelay;
|
2019-03-22 22:48:12 -07:00
|
|
|
|
2020-03-28 14:34:51 -07:00
|
|
|
float Damping;
|
|
|
|
float Feedback;
|
2019-03-22 22:48:12 -07:00
|
|
|
|
2020-03-28 14:34:51 -07:00
|
|
|
float Spread;
|
2019-03-22 22:48:12 -07:00
|
|
|
} Echo;
|
|
|
|
|
|
|
|
struct {
|
2020-03-28 14:34:51 -07:00
|
|
|
float LowCutoff;
|
|
|
|
float LowGain;
|
|
|
|
float Mid1Center;
|
|
|
|
float Mid1Gain;
|
|
|
|
float Mid1Width;
|
|
|
|
float Mid2Center;
|
|
|
|
float Mid2Gain;
|
|
|
|
float Mid2Width;
|
|
|
|
float HighCutoff;
|
|
|
|
float HighGain;
|
2019-03-22 22:48:12 -07:00
|
|
|
} Equalizer;
|
|
|
|
|
|
|
|
struct {
|
2020-03-28 14:34:51 -07:00
|
|
|
float Frequency;
|
|
|
|
int LeftDirection;
|
|
|
|
int RightDirection;
|
2019-03-22 22:48:12 -07:00
|
|
|
} Fshifter;
|
|
|
|
|
|
|
|
struct {
|
2020-03-28 14:34:51 -07:00
|
|
|
float Frequency;
|
|
|
|
float HighPassCutoff;
|
|
|
|
int Waveform;
|
2019-03-22 22:48:12 -07:00
|
|
|
} Modulator;
|
|
|
|
|
|
|
|
struct {
|
2020-03-28 14:34:51 -07:00
|
|
|
int CoarseTune;
|
|
|
|
int FineTune;
|
2019-03-22 22:48:12 -07:00
|
|
|
} Pshifter;
|
|
|
|
|
2019-07-10 07:14:31 +02:00
|
|
|
struct {
|
2020-03-28 14:34:51 -07:00
|
|
|
float Rate;
|
|
|
|
int PhonemeA;
|
|
|
|
int PhonemeB;
|
|
|
|
int PhonemeACoarseTuning;
|
|
|
|
int PhonemeBCoarseTuning;
|
|
|
|
int Waveform;
|
2019-07-10 07:14:31 +02:00
|
|
|
} Vmorpher;
|
|
|
|
|
2019-03-22 22:48:12 -07:00
|
|
|
struct {
|
2020-03-28 14:34:51 -07:00
|
|
|
float Gain;
|
2019-03-22 22:48:12 -07:00
|
|
|
} Dedicated;
|
|
|
|
};
|
2019-03-22 13:33:58 -07:00
|
|
|
|
|
|
|
|
2020-04-10 18:26:08 -07:00
|
|
|
class effect_exception final : public al::base_exception {
|
|
|
|
public:
|
|
|
|
[[gnu::format(printf, 3, 4)]]
|
2020-04-14 11:50:59 -07:00
|
|
|
effect_exception(ALenum code, const char *msg, ...);
|
2020-04-10 18:26:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-03-22 13:33:58 -07:00
|
|
|
struct EffectVtable {
|
2020-04-10 20:23:20 -07:00
|
|
|
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);
|
2019-03-22 13:33:58 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#define DEFINE_ALEFFECT_VTABLE(T) \
|
|
|
|
const EffectVtable T##_vtable = { \
|
|
|
|
T##_setParami, T##_setParamiv, \
|
|
|
|
T##_setParamf, T##_setParamfv, \
|
|
|
|
T##_getParami, T##_getParamiv, \
|
|
|
|
T##_getParamf, T##_getParamfv, \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct EffectTarget {
|
|
|
|
MixParams *Main;
|
|
|
|
RealMixParams *RealOut;
|
|
|
|
};
|
|
|
|
|
2019-08-01 13:28:53 -07:00
|
|
|
struct EffectState : public al::intrusive_ref<EffectState> {
|
2019-06-05 19:58:58 -07:00
|
|
|
al::span<FloatBufferLine> mOutTarget;
|
2019-03-22 13:33:58 -07:00
|
|
|
|
|
|
|
|
|
|
|
virtual ~EffectState() = default;
|
|
|
|
|
2020-04-16 17:29:32 -07:00
|
|
|
virtual void deviceUpdate(const ALCdevice *device) = 0;
|
2020-09-05 20:48:56 -07:00
|
|
|
virtual void setBuffer(const ALCdevice* /*device*/, const BufferStorage* /*buffer*/) { }
|
2019-03-22 22:48:12 -07:00
|
|
|
virtual void update(const ALCcontext *context, const ALeffectslot *slot, const EffectProps *props, const EffectTarget target) = 0;
|
2019-08-26 09:16:20 -07:00
|
|
|
virtual void process(const size_t samplesToDo, const al::span<const FloatBufferLine> samplesIn, const al::span<FloatBufferLine> samplesOut) = 0;
|
2019-03-22 13:33:58 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct EffectStateFactory {
|
2020-09-05 14:28:08 -07:00
|
|
|
virtual ~EffectStateFactory() = default;
|
2019-03-22 13:33:58 -07:00
|
|
|
|
|
|
|
virtual EffectState *create() = 0;
|
2019-03-22 22:48:12 -07:00
|
|
|
virtual EffectProps getDefaultProps() const noexcept = 0;
|
2019-03-22 13:33:58 -07:00
|
|
|
virtual const EffectVtable *getEffectVtable() const noexcept = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
2019-07-10 07:14:31 +02:00
|
|
|
EffectStateFactory* VmorpherStateFactory_getFactory(void);
|
2019-03-22 13:33:58 -07:00
|
|
|
|
|
|
|
EffectStateFactory *DedicatedStateFactory_getFactory(void);
|
|
|
|
|
2020-08-24 20:04:16 -07:00
|
|
|
EffectStateFactory *ConvolutionStateFactory_getFactory(void);
|
2019-03-22 13:33:58 -07:00
|
|
|
|
|
|
|
#endif /* EFFECTS_BASE_H */
|