alSource.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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 "hrtf.h"
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. struct ALbuffer;
  11. struct ALsource;
  12. struct ALsourceProps;
  13. typedef struct ALbufferlistitem {
  14. struct ALbuffer *buffer;
  15. struct ALbufferlistitem *volatile next;
  16. } ALbufferlistitem;
  17. struct ALsourceProps {
  18. ATOMIC(ALfloat) Pitch;
  19. ATOMIC(ALfloat) Gain;
  20. ATOMIC(ALfloat) OuterGain;
  21. ATOMIC(ALfloat) MinGain;
  22. ATOMIC(ALfloat) MaxGain;
  23. ATOMIC(ALfloat) InnerAngle;
  24. ATOMIC(ALfloat) OuterAngle;
  25. ATOMIC(ALfloat) RefDistance;
  26. ATOMIC(ALfloat) MaxDistance;
  27. ATOMIC(ALfloat) RollOffFactor;
  28. ATOMIC(ALfloat) Position[3];
  29. ATOMIC(ALfloat) Velocity[3];
  30. ATOMIC(ALfloat) Direction[3];
  31. ATOMIC(ALfloat) Orientation[2][3];
  32. ATOMIC(ALboolean) HeadRelative;
  33. ATOMIC(enum DistanceModel) DistanceModel;
  34. ATOMIC(ALboolean) DirectChannels;
  35. ATOMIC(ALboolean) DryGainHFAuto;
  36. ATOMIC(ALboolean) WetGainAuto;
  37. ATOMIC(ALboolean) WetGainHFAuto;
  38. ATOMIC(ALfloat) OuterGainHF;
  39. ATOMIC(ALfloat) AirAbsorptionFactor;
  40. ATOMIC(ALfloat) RoomRolloffFactor;
  41. ATOMIC(ALfloat) DopplerFactor;
  42. ATOMIC(ALfloat) StereoPan[2];
  43. ATOMIC(ALfloat) Radius;
  44. /** Direct filter and auxiliary send info. */
  45. struct {
  46. ATOMIC(ALfloat) Gain;
  47. ATOMIC(ALfloat) GainHF;
  48. ATOMIC(ALfloat) HFReference;
  49. ATOMIC(ALfloat) GainLF;
  50. ATOMIC(ALfloat) LFReference;
  51. } Direct;
  52. struct {
  53. ATOMIC(struct ALeffectslot*) Slot;
  54. ATOMIC(ALfloat) Gain;
  55. ATOMIC(ALfloat) GainHF;
  56. ATOMIC(ALfloat) HFReference;
  57. ATOMIC(ALfloat) GainLF;
  58. ATOMIC(ALfloat) LFReference;
  59. } Send[MAX_SENDS];
  60. ATOMIC(struct ALsourceProps*) next;
  61. };
  62. typedef struct ALvoice {
  63. struct ALsourceProps Props;
  64. struct ALsource *volatile Source;
  65. /** Current target parameters used for mixing. */
  66. ALint Step;
  67. /* If not 'moving', gain/coefficients are set directly without fading. */
  68. ALboolean Moving;
  69. ALboolean IsHrtf;
  70. ALuint Offset; /* Number of output samples mixed since starting. */
  71. alignas(16) ALfloat PrevSamples[MAX_INPUT_CHANNELS][MAX_PRE_SAMPLES];
  72. BsincState SincState;
  73. struct {
  74. ALfloat (*Buffer)[BUFFERSIZE];
  75. ALuint Channels;
  76. } DirectOut;
  77. struct {
  78. ALfloat (*Buffer)[BUFFERSIZE];
  79. ALuint Channels;
  80. } SendOut[MAX_SENDS];
  81. struct {
  82. DirectParams Direct;
  83. SendParams Send[MAX_SENDS];
  84. } Chan[MAX_INPUT_CHANNELS];
  85. } ALvoice;
  86. typedef struct ALsource {
  87. /** Source properties. */
  88. ALfloat Pitch;
  89. ALfloat Gain;
  90. ALfloat OuterGain;
  91. ALfloat MinGain;
  92. ALfloat MaxGain;
  93. ALfloat InnerAngle;
  94. ALfloat OuterAngle;
  95. ALfloat RefDistance;
  96. ALfloat MaxDistance;
  97. ALfloat RollOffFactor;
  98. ALfloat Position[3];
  99. ALfloat Velocity[3];
  100. ALfloat Direction[3];
  101. ALfloat Orientation[2][3];
  102. ALboolean HeadRelative;
  103. enum DistanceModel DistanceModel;
  104. ALboolean DirectChannels;
  105. ALboolean DryGainHFAuto;
  106. ALboolean WetGainAuto;
  107. ALboolean WetGainHFAuto;
  108. ALfloat OuterGainHF;
  109. ALfloat AirAbsorptionFactor;
  110. ALfloat RoomRolloffFactor;
  111. ALfloat DopplerFactor;
  112. /* NOTE: Stereo pan angles are specified in radians, counter-clockwise
  113. * rather than clockwise.
  114. */
  115. ALfloat StereoPan[2];
  116. ALfloat Radius;
  117. /** Direct filter and auxiliary send info. */
  118. struct {
  119. ALfloat Gain;
  120. ALfloat GainHF;
  121. ALfloat HFReference;
  122. ALfloat GainLF;
  123. ALfloat LFReference;
  124. } Direct;
  125. struct {
  126. struct ALeffectslot *Slot;
  127. ALfloat Gain;
  128. ALfloat GainHF;
  129. ALfloat HFReference;
  130. ALfloat GainLF;
  131. ALfloat LFReference;
  132. } Send[MAX_SENDS];
  133. /**
  134. * Last user-specified offset, and the offset type (bytes, samples, or
  135. * seconds).
  136. */
  137. ALdouble Offset;
  138. ALenum OffsetType;
  139. /** Source type (static, streaming, or undetermined) */
  140. ALint SourceType;
  141. /** Source state (initial, playing, paused, or stopped) */
  142. ALenum state;
  143. ALenum new_state;
  144. /** Source Buffer Queue info. */
  145. RWLock queue_lock;
  146. ATOMIC(ALbufferlistitem*) queue;
  147. ATOMIC(ALbufferlistitem*) current_buffer;
  148. /**
  149. * Source offset in samples, relative to the currently playing buffer, NOT
  150. * the whole queue, and the fractional (fixed-point) offset to the next
  151. * sample.
  152. */
  153. ATOMIC(ALuint) position;
  154. ATOMIC(ALuint) position_fraction;
  155. ATOMIC(ALboolean) looping;
  156. /** Current buffer sample info. */
  157. ALuint NumChannels;
  158. ALuint SampleSize;
  159. ATOMIC(struct ALsourceProps*) Update;
  160. ATOMIC(struct ALsourceProps*) FreeList;
  161. /** Self ID */
  162. ALuint id;
  163. } ALsource;
  164. inline void LockSourcesRead(ALCcontext *context)
  165. { LockUIntMapRead(&context->SourceMap); }
  166. inline void UnlockSourcesRead(ALCcontext *context)
  167. { UnlockUIntMapRead(&context->SourceMap); }
  168. inline void LockSourcesWrite(ALCcontext *context)
  169. { LockUIntMapWrite(&context->SourceMap); }
  170. inline void UnlockSourcesWrite(ALCcontext *context)
  171. { UnlockUIntMapWrite(&context->SourceMap); }
  172. inline struct ALsource *LookupSource(ALCcontext *context, ALuint id)
  173. { return (struct ALsource*)LookupUIntMapKeyNoLock(&context->SourceMap, id); }
  174. inline struct ALsource *RemoveSource(ALCcontext *context, ALuint id)
  175. { return (struct ALsource*)RemoveUIntMapKeyNoLock(&context->SourceMap, id); }
  176. void UpdateAllSourceProps(ALCcontext *context);
  177. ALvoid SetSourceState(ALsource *Source, ALCcontext *Context, ALenum state);
  178. ALboolean ApplyOffset(ALsource *Source);
  179. ALvoid ReleaseALSources(ALCcontext *Context);
  180. #ifdef __cplusplus
  181. }
  182. #endif
  183. #endif