source.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #ifndef AL_SOURCE_H
  2. #define AL_SOURCE_H
  3. #include <array>
  4. #include <atomic>
  5. #include <cstddef>
  6. #include <iterator>
  7. #include "AL/al.h"
  8. #include "AL/alc.h"
  9. #include "alcontext.h"
  10. #include "almalloc.h"
  11. #include "alnumeric.h"
  12. #include "alu.h"
  13. #include "vector.h"
  14. struct ALbuffer;
  15. struct ALeffectslot;
  16. #define DEFAULT_SENDS 2
  17. #define INVALID_VOICE_IDX static_cast<ALuint>(-1)
  18. struct ALbufferlistitem {
  19. std::atomic<ALbufferlistitem*> mNext{nullptr};
  20. ALuint mSampleLen{0u};
  21. ALbuffer *mBuffer{nullptr};
  22. DEF_NEWDEL(ALbufferlistitem)
  23. };
  24. struct ALsource {
  25. /** Source properties. */
  26. ALfloat Pitch;
  27. ALfloat Gain;
  28. ALfloat OuterGain;
  29. ALfloat MinGain;
  30. ALfloat MaxGain;
  31. ALfloat InnerAngle;
  32. ALfloat OuterAngle;
  33. ALfloat RefDistance;
  34. ALfloat MaxDistance;
  35. ALfloat RolloffFactor;
  36. std::array<ALfloat,3> Position;
  37. std::array<ALfloat,3> Velocity;
  38. std::array<ALfloat,3> Direction;
  39. std::array<ALfloat,3> OrientAt;
  40. std::array<ALfloat,3> OrientUp;
  41. bool HeadRelative;
  42. bool Looping;
  43. DistanceModel mDistanceModel;
  44. Resampler mResampler;
  45. bool DirectChannels;
  46. SpatializeMode mSpatialize;
  47. bool DryGainHFAuto;
  48. bool WetGainAuto;
  49. bool WetGainHFAuto;
  50. ALfloat OuterGainHF;
  51. ALfloat AirAbsorptionFactor;
  52. ALfloat RoomRolloffFactor;
  53. ALfloat DopplerFactor;
  54. /* NOTE: Stereo pan angles are specified in radians, counter-clockwise
  55. * rather than clockwise.
  56. */
  57. std::array<ALfloat,2> StereoPan;
  58. ALfloat Radius;
  59. /** Direct filter and auxiliary send info. */
  60. struct {
  61. ALfloat Gain;
  62. ALfloat GainHF;
  63. ALfloat HFReference;
  64. ALfloat GainLF;
  65. ALfloat LFReference;
  66. } Direct;
  67. struct SendData {
  68. ALeffectslot *Slot;
  69. ALfloat Gain;
  70. ALfloat GainHF;
  71. ALfloat HFReference;
  72. ALfloat GainLF;
  73. ALfloat LFReference;
  74. };
  75. al::vector<SendData> Send;
  76. /**
  77. * Last user-specified offset, and the offset type (bytes, samples, or
  78. * seconds).
  79. */
  80. ALdouble Offset{0.0};
  81. ALenum OffsetType{AL_NONE};
  82. /** Source type (static, streaming, or undetermined) */
  83. ALenum SourceType{AL_UNDETERMINED};
  84. /** Source state (initial, playing, paused, or stopped) */
  85. ALenum state{AL_INITIAL};
  86. /** Source Buffer Queue head. */
  87. ALbufferlistitem *queue{nullptr};
  88. std::atomic_flag PropsClean;
  89. /* Index into the context's Voices array. Lazily updated, only checked and
  90. * reset when looking up the voice.
  91. */
  92. ALuint VoiceIdx{INVALID_VOICE_IDX};
  93. /** Self ID */
  94. ALuint id{0};
  95. ALsource(ALuint num_sends);
  96. ~ALsource();
  97. ALsource(const ALsource&) = delete;
  98. ALsource& operator=(const ALsource&) = delete;
  99. };
  100. void UpdateAllSourceProps(ALCcontext *context);
  101. #endif