alEffect.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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_EFFECT = 0,
  10. REVERB_EFFECT,
  11. AUTOWAH_EFFECT,
  12. CHORUS_EFFECT,
  13. COMPRESSOR_EFFECT,
  14. DISTORTION_EFFECT,
  15. ECHO_EFFECT,
  16. EQUALIZER_EFFECT,
  17. FLANGER_EFFECT,
  18. FSHIFTER_EFFECT,
  19. MODULATOR_EFFECT,
  20. PSHIFTER_EFFECT,
  21. DEDICATED_EFFECT,
  22. MAX_EFFECTS
  23. };
  24. extern ALboolean DisabledEffects[MAX_EFFECTS];
  25. extern ALfloat ReverbBoost;
  26. struct EffectList {
  27. const char name[16];
  28. int type;
  29. ALenum val;
  30. };
  31. #define EFFECTLIST_SIZE 14
  32. extern const struct EffectList EffectList[EFFECTLIST_SIZE];
  33. struct ALeffectVtable {
  34. void (*const setParami)(struct ALeffect *effect, ALCcontext *context, ALenum param, ALint val);
  35. void (*const setParamiv)(struct ALeffect *effect, ALCcontext *context, ALenum param, const ALint *vals);
  36. void (*const setParamf)(struct ALeffect *effect, ALCcontext *context, ALenum param, ALfloat val);
  37. void (*const setParamfv)(struct ALeffect *effect, ALCcontext *context, ALenum param, const ALfloat *vals);
  38. void (*const getParami)(const struct ALeffect *effect, ALCcontext *context, ALenum param, ALint *val);
  39. void (*const getParamiv)(const struct ALeffect *effect, ALCcontext *context, ALenum param, ALint *vals);
  40. void (*const getParamf)(const struct ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *val);
  41. void (*const getParamfv)(const struct ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *vals);
  42. };
  43. #define DEFINE_ALEFFECT_VTABLE(T) \
  44. const struct ALeffectVtable T##_vtable = { \
  45. T##_setParami, T##_setParamiv, \
  46. T##_setParamf, T##_setParamfv, \
  47. T##_getParami, T##_getParamiv, \
  48. T##_getParamf, T##_getParamfv, \
  49. }
  50. extern const struct ALeffectVtable ALeaxreverb_vtable;
  51. extern const struct ALeffectVtable ALreverb_vtable;
  52. extern const struct ALeffectVtable ALautowah_vtable;
  53. extern const struct ALeffectVtable ALchorus_vtable;
  54. extern const struct ALeffectVtable ALcompressor_vtable;
  55. extern const struct ALeffectVtable ALdistortion_vtable;
  56. extern const struct ALeffectVtable ALecho_vtable;
  57. extern const struct ALeffectVtable ALequalizer_vtable;
  58. extern const struct ALeffectVtable ALflanger_vtable;
  59. extern const struct ALeffectVtable ALfshifter_vtable;
  60. extern const struct ALeffectVtable ALmodulator_vtable;
  61. extern const struct ALeffectVtable ALnull_vtable;
  62. extern const struct ALeffectVtable ALpshifter_vtable;
  63. extern const struct ALeffectVtable ALdedicated_vtable;
  64. typedef union ALeffectProps {
  65. struct {
  66. // Shared Reverb Properties
  67. ALfloat Density;
  68. ALfloat Diffusion;
  69. ALfloat Gain;
  70. ALfloat GainHF;
  71. ALfloat DecayTime;
  72. ALfloat DecayHFRatio;
  73. ALfloat ReflectionsGain;
  74. ALfloat ReflectionsDelay;
  75. ALfloat LateReverbGain;
  76. ALfloat LateReverbDelay;
  77. ALfloat AirAbsorptionGainHF;
  78. ALfloat RoomRolloffFactor;
  79. ALboolean DecayHFLimit;
  80. // Additional EAX Reverb Properties
  81. ALfloat GainLF;
  82. ALfloat DecayLFRatio;
  83. ALfloat ReflectionsPan[3];
  84. ALfloat LateReverbPan[3];
  85. ALfloat EchoTime;
  86. ALfloat EchoDepth;
  87. ALfloat ModulationTime;
  88. ALfloat ModulationDepth;
  89. ALfloat HFReference;
  90. ALfloat LFReference;
  91. } Reverb;
  92. struct {
  93. ALfloat AttackTime;
  94. ALfloat ReleaseTime;
  95. ALfloat Resonance;
  96. ALfloat PeakGain;
  97. } Autowah;
  98. struct {
  99. ALint Waveform;
  100. ALint Phase;
  101. ALfloat Rate;
  102. ALfloat Depth;
  103. ALfloat Feedback;
  104. ALfloat Delay;
  105. } Chorus; /* Also Flanger */
  106. struct {
  107. ALboolean OnOff;
  108. } Compressor;
  109. struct {
  110. ALfloat Edge;
  111. ALfloat Gain;
  112. ALfloat LowpassCutoff;
  113. ALfloat EQCenter;
  114. ALfloat EQBandwidth;
  115. } Distortion;
  116. struct {
  117. ALfloat Delay;
  118. ALfloat LRDelay;
  119. ALfloat Damping;
  120. ALfloat Feedback;
  121. ALfloat Spread;
  122. } Echo;
  123. struct {
  124. ALfloat LowCutoff;
  125. ALfloat LowGain;
  126. ALfloat Mid1Center;
  127. ALfloat Mid1Gain;
  128. ALfloat Mid1Width;
  129. ALfloat Mid2Center;
  130. ALfloat Mid2Gain;
  131. ALfloat Mid2Width;
  132. ALfloat HighCutoff;
  133. ALfloat HighGain;
  134. } Equalizer;
  135. struct {
  136. ALfloat Frequency;
  137. ALint LeftDirection;
  138. ALint RightDirection;
  139. } Fshifter;
  140. struct {
  141. ALfloat Frequency;
  142. ALfloat HighPassCutoff;
  143. ALint Waveform;
  144. } Modulator;
  145. struct {
  146. ALint CoarseTune;
  147. ALint FineTune;
  148. } Pshifter;
  149. struct {
  150. ALfloat Gain;
  151. } Dedicated;
  152. } ALeffectProps;
  153. typedef struct ALeffect {
  154. // Effect type (AL_EFFECT_NULL, ...)
  155. ALenum type;
  156. ALeffectProps Props;
  157. const struct ALeffectVtable *vtab;
  158. /* Self ID */
  159. ALuint id;
  160. } ALeffect;
  161. #define ALeffect_setParami(o, c, p, v) ((o)->vtab->setParami(o, c, p, v))
  162. #define ALeffect_setParamf(o, c, p, v) ((o)->vtab->setParamf(o, c, p, v))
  163. #define ALeffect_setParamiv(o, c, p, v) ((o)->vtab->setParamiv(o, c, p, v))
  164. #define ALeffect_setParamfv(o, c, p, v) ((o)->vtab->setParamfv(o, c, p, v))
  165. #define ALeffect_getParami(o, c, p, v) ((o)->vtab->getParami(o, c, p, v))
  166. #define ALeffect_getParamf(o, c, p, v) ((o)->vtab->getParamf(o, c, p, v))
  167. #define ALeffect_getParamiv(o, c, p, v) ((o)->vtab->getParamiv(o, c, p, v))
  168. #define ALeffect_getParamfv(o, c, p, v) ((o)->vtab->getParamfv(o, c, p, v))
  169. inline ALboolean IsReverbEffect(ALenum type)
  170. { return type == AL_EFFECT_REVERB || type == AL_EFFECT_EAXREVERB; }
  171. void InitEffect(ALeffect *effect);
  172. void ReleaseALEffects(ALCdevice *device);
  173. void LoadReverbPreset(const char *name, ALeffect *effect);
  174. #ifdef __cplusplus
  175. }
  176. #endif
  177. #endif