alSource.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. #ifndef _AL_SOURCE_H_
  2. #define _AL_SOURCE_H_
  3. #define MAX_SENDS 4
  4. #include "alMain.h"
  5. #include "alu.h"
  6. #include "alFilter.h"
  7. #include "alBuffer.h"
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. #define SRC_HISTORY_BITS (6)
  12. #define SRC_HISTORY_LENGTH (1<<SRC_HISTORY_BITS)
  13. #define SRC_HISTORY_MASK (SRC_HISTORY_LENGTH-1)
  14. extern enum Resampler DefaultResampler;
  15. extern const ALsizei ResamplerPadding[ResamplerMax];
  16. extern const ALsizei ResamplerPrePadding[ResamplerMax];
  17. typedef struct ALbufferlistitem {
  18. struct ALbuffer *buffer;
  19. struct ALbufferlistitem *next;
  20. struct ALbufferlistitem *prev;
  21. } ALbufferlistitem;
  22. typedef struct HrtfState {
  23. ALboolean Moving;
  24. ALuint Counter;
  25. ALIGN(16) ALfloat History[MAX_INPUT_CHANNELS][SRC_HISTORY_LENGTH];
  26. ALIGN(16) ALfloat Values[MAX_INPUT_CHANNELS][HRIR_LENGTH][2];
  27. ALuint Offset;
  28. } HrtfState;
  29. typedef struct HrtfParams {
  30. ALfloat Gain;
  31. ALfloat Dir[3];
  32. ALIGN(16) ALfloat Coeffs[MAX_INPUT_CHANNELS][HRIR_LENGTH][2];
  33. ALIGN(16) ALfloat CoeffStep[HRIR_LENGTH][2];
  34. ALuint Delay[MAX_INPUT_CHANNELS][2];
  35. ALint DelayStep[2];
  36. ALuint IrSize;
  37. } HrtfParams;
  38. typedef struct DirectParams {
  39. ALfloat (*OutBuffer)[BUFFERSIZE];
  40. ALfloat *ClickRemoval;
  41. ALfloat *PendingClicks;
  42. struct {
  43. HrtfParams Params;
  44. HrtfState *State;
  45. } Hrtf;
  46. /* A mixing matrix. First subscript is the channel number of the input data
  47. * (regardless of channel configuration) and the second is the channel
  48. * target (eg. FrontLeft). Not used with HRTF. */
  49. ALfloat Gains[MAX_INPUT_CHANNELS][MaxChannels];
  50. ALfilterState LpFilter[MAX_INPUT_CHANNELS];
  51. } DirectParams;
  52. typedef struct SendParams {
  53. ALfloat (*OutBuffer)[BUFFERSIZE];
  54. ALfloat *ClickRemoval;
  55. ALfloat *PendingClicks;
  56. /* Gain control, which applies to all input channels to a single (mono)
  57. * output buffer. */
  58. ALfloat Gain;
  59. ALfilterState LpFilter[MAX_INPUT_CHANNELS];
  60. } SendParams;
  61. typedef struct ALsource
  62. {
  63. /** Source properties. */
  64. volatile ALfloat Pitch;
  65. volatile ALfloat Gain;
  66. volatile ALfloat OuterGain;
  67. volatile ALfloat MinGain;
  68. volatile ALfloat MaxGain;
  69. volatile ALfloat InnerAngle;
  70. volatile ALfloat OuterAngle;
  71. volatile ALfloat RefDistance;
  72. volatile ALfloat MaxDistance;
  73. volatile ALfloat RollOffFactor;
  74. volatile ALfloat Position[3];
  75. volatile ALfloat Velocity[3];
  76. volatile ALfloat Orientation[3];
  77. volatile ALboolean HeadRelative;
  78. volatile ALboolean Looping;
  79. volatile enum DistanceModel DistanceModel;
  80. volatile ALboolean DirectChannels;
  81. volatile ALboolean DryGainHFAuto;
  82. volatile ALboolean WetGainAuto;
  83. volatile ALboolean WetGainHFAuto;
  84. volatile ALfloat OuterGainHF;
  85. volatile ALfloat AirAbsorptionFactor;
  86. volatile ALfloat RoomRolloffFactor;
  87. volatile ALfloat DopplerFactor;
  88. enum Resampler Resampler;
  89. /**
  90. * Last user-specified offset, and the offset type (bytes, samples, or
  91. * seconds).
  92. */
  93. ALdouble Offset;
  94. ALenum OffsetType;
  95. /** Source type (static, streaming, or undetermined) */
  96. volatile ALint SourceType;
  97. /** Source state (initial, playing, paused, or stopped) */
  98. volatile ALenum state;
  99. ALenum new_state;
  100. /**
  101. * Source offset in samples, relative to the currently playing buffer, NOT
  102. * the whole queue, and the fractional (fixed-point) offset to the next
  103. * sample.
  104. */
  105. ALuint position;
  106. ALuint position_fraction;
  107. /** Source Buffer Queue info. */
  108. ALbufferlistitem *queue;
  109. ALuint BuffersInQueue;
  110. ALuint BuffersPlayed;
  111. /** Current buffer sample info. */
  112. ALuint NumChannels;
  113. ALuint SampleSize;
  114. /** Direct filter and auxiliary send info. */
  115. ALfloat DirectGain;
  116. ALfloat DirectGainHF;
  117. struct {
  118. struct ALeffectslot *Slot;
  119. ALfloat Gain;
  120. ALfloat GainHF;
  121. } Send[MAX_SENDS];
  122. /** HRTF info. */
  123. HrtfState Hrtf;
  124. /** Current target parameters used for mixing. */
  125. struct {
  126. ResamplerFunc Resample;
  127. DryMixerFunc DryMix;
  128. WetMixerFunc WetMix;
  129. ALint Step;
  130. DirectParams Direct;
  131. SendParams Send[MAX_SENDS];
  132. } Params;
  133. /** Source needs to update its mixing parameters. */
  134. volatile ALenum NeedsUpdate;
  135. /** Method to update mixing parameters. */
  136. ALvoid (*Update)(struct ALsource *self, const ALCcontext *context);
  137. /** Self ID */
  138. ALuint id;
  139. } ALsource;
  140. #define ALsource_Update(s,a) ((s)->Update(s,a))
  141. inline struct ALsource *LookupSource(ALCcontext *context, ALuint id)
  142. { return (struct ALsource*)LookupUIntMapKey(&context->SourceMap, id); }
  143. inline struct ALsource *RemoveSource(ALCcontext *context, ALuint id)
  144. { return (struct ALsource*)RemoveUIntMapKey(&context->SourceMap, id); }
  145. ALvoid SetSourceState(ALsource *Source, ALCcontext *Context, ALenum state);
  146. ALboolean ApplyOffset(ALsource *Source);
  147. ALvoid ReleaseALSources(ALCcontext *Context);
  148. #ifdef __cplusplus
  149. }
  150. #endif
  151. #endif