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