source.h 3.1 KB

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