alEffect.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. #ifndef _AL_EFFECT_H_
  2. #define _AL_EFFECT_H_
  3. #include "alMain.h"
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. struct ALeffect;
  8. enum {
  9. EAXREVERB = 0,
  10. REVERB,
  11. CHORUS,
  12. COMPRESSOR,
  13. DISTORTION,
  14. ECHO,
  15. EQUALIZER,
  16. FLANGER,
  17. MODULATOR,
  18. DEDICATED,
  19. MAX_EFFECTS
  20. };
  21. extern ALboolean DisabledEffects[MAX_EFFECTS];
  22. extern ALfloat ReverbBoost;
  23. extern ALboolean EmulateEAXReverb;
  24. struct ALeffectVtable {
  25. void (*const setParami)(struct ALeffect *effect, ALCcontext *context, ALenum param, ALint val);
  26. void (*const setParamiv)(struct ALeffect *effect, ALCcontext *context, ALenum param, const ALint *vals);
  27. void (*const setParamf)(struct ALeffect *effect, ALCcontext *context, ALenum param, ALfloat val);
  28. void (*const setParamfv)(struct ALeffect *effect, ALCcontext *context, ALenum param, const ALfloat *vals);
  29. void (*const getParami)(const struct ALeffect *effect, ALCcontext *context, ALenum param, ALint *val);
  30. void (*const getParamiv)(const struct ALeffect *effect, ALCcontext *context, ALenum param, ALint *vals);
  31. void (*const getParamf)(const struct ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *val);
  32. void (*const getParamfv)(const struct ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *vals);
  33. };
  34. #define DEFINE_ALEFFECT_VTABLE(T) \
  35. const struct ALeffectVtable T##_vtable = { \
  36. T##_setParami, T##_setParamiv, \
  37. T##_setParamf, T##_setParamfv, \
  38. T##_getParami, T##_getParamiv, \
  39. T##_getParamf, T##_getParamfv, \
  40. }
  41. extern const struct ALeffectVtable ALeaxreverb_vtable;
  42. extern const struct ALeffectVtable ALreverb_vtable;
  43. extern const struct ALeffectVtable ALchorus_vtable;
  44. extern const struct ALeffectVtable ALcompressor_vtable;
  45. extern const struct ALeffectVtable ALdistortion_vtable;
  46. extern const struct ALeffectVtable ALecho_vtable;
  47. extern const struct ALeffectVtable ALequalizer_vtable;
  48. extern const struct ALeffectVtable ALflanger_vtable;
  49. extern const struct ALeffectVtable ALmodulator_vtable;
  50. extern const struct ALeffectVtable ALnull_vtable;
  51. extern const struct ALeffectVtable ALdedicated_vtable;
  52. typedef union ALeffectProps {
  53. struct {
  54. // Shared Reverb Properties
  55. ALfloat Density;
  56. ALfloat Diffusion;
  57. ALfloat Gain;
  58. ALfloat GainHF;
  59. ALfloat DecayTime;
  60. ALfloat DecayHFRatio;
  61. ALfloat ReflectionsGain;
  62. ALfloat ReflectionsDelay;
  63. ALfloat LateReverbGain;
  64. ALfloat LateReverbDelay;
  65. ALfloat AirAbsorptionGainHF;
  66. ALfloat RoomRolloffFactor;
  67. ALboolean DecayHFLimit;
  68. // Additional EAX Reverb Properties
  69. ALfloat GainLF;
  70. ALfloat DecayLFRatio;
  71. ALfloat ReflectionsPan[3];
  72. ALfloat LateReverbPan[3];
  73. ALfloat EchoTime;
  74. ALfloat EchoDepth;
  75. ALfloat ModulationTime;
  76. ALfloat ModulationDepth;
  77. ALfloat HFReference;
  78. ALfloat LFReference;
  79. } Reverb;
  80. struct {
  81. ALint Waveform;
  82. ALint Phase;
  83. ALfloat Rate;
  84. ALfloat Depth;
  85. ALfloat Feedback;
  86. ALfloat Delay;
  87. } Chorus;
  88. struct {
  89. ALboolean OnOff;
  90. } Compressor;
  91. struct {
  92. ALfloat Edge;
  93. ALfloat Gain;
  94. ALfloat LowpassCutoff;
  95. ALfloat EQCenter;
  96. ALfloat EQBandwidth;
  97. } Distortion;
  98. struct {
  99. ALfloat Delay;
  100. ALfloat LRDelay;
  101. ALfloat Damping;
  102. ALfloat Feedback;
  103. ALfloat Spread;
  104. } Echo;
  105. struct {
  106. ALfloat LowCutoff;
  107. ALfloat LowGain;
  108. ALfloat Mid1Center;
  109. ALfloat Mid1Gain;
  110. ALfloat Mid1Width;
  111. ALfloat Mid2Center;
  112. ALfloat Mid2Gain;
  113. ALfloat Mid2Width;
  114. ALfloat HighCutoff;
  115. ALfloat HighGain;
  116. } Equalizer;
  117. struct {
  118. ALint Waveform;
  119. ALint Phase;
  120. ALfloat Rate;
  121. ALfloat Depth;
  122. ALfloat Feedback;
  123. ALfloat Delay;
  124. } Flanger;
  125. struct {
  126. ALfloat Frequency;
  127. ALfloat HighPassCutoff;
  128. ALint Waveform;
  129. } Modulator;
  130. struct {
  131. ALfloat Gain;
  132. } Dedicated;
  133. } ALeffectProps;
  134. typedef struct ALeffect {
  135. // Effect type (AL_EFFECT_NULL, ...)
  136. ALenum type;
  137. ALeffectProps Props;
  138. const struct ALeffectVtable *vtbl;
  139. /* Self ID */
  140. ALuint id;
  141. } ALeffect;
  142. inline void LockEffectsRead(ALCdevice *device)
  143. { LockUIntMapRead(&device->EffectMap); }
  144. inline void UnlockEffectsRead(ALCdevice *device)
  145. { UnlockUIntMapRead(&device->EffectMap); }
  146. inline void LockEffectsWrite(ALCdevice *device)
  147. { LockUIntMapWrite(&device->EffectMap); }
  148. inline void UnlockEffectsWrite(ALCdevice *device)
  149. { UnlockUIntMapWrite(&device->EffectMap); }
  150. inline struct ALeffect *LookupEffect(ALCdevice *device, ALuint id)
  151. { return (struct ALeffect*)LookupUIntMapKeyNoLock(&device->EffectMap, id); }
  152. inline struct ALeffect *RemoveEffect(ALCdevice *device, ALuint id)
  153. { return (struct ALeffect*)RemoveUIntMapKeyNoLock(&device->EffectMap, id); }
  154. inline ALboolean IsReverbEffect(ALenum type)
  155. { return type == AL_EFFECT_REVERB || type == AL_EFFECT_EAXREVERB; }
  156. ALenum InitEffect(ALeffect *effect);
  157. ALvoid ReleaseALEffects(ALCdevice *device);
  158. ALvoid LoadReverbPreset(const char *name, ALeffect *effect);
  159. #ifdef __cplusplus
  160. }
  161. #endif
  162. #endif