Only send source updates for sources that have updated
[openal-soft.git] / OpenAL32 / Include / alSource.h
blob8b79310246d93cccf8ec2cda41e5eccbde963af4
1 #ifndef _AL_SOURCE_H_
2 #define _AL_SOURCE_H_
4 #define MAX_SENDS 4
6 #include "alMain.h"
7 #include "alu.h"
8 #include "hrtf.h"
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
14 struct ALbuffer;
15 struct ALsource;
16 struct ALsourceProps;
19 typedef struct ALbufferlistitem {
20 struct ALbuffer *buffer;
21 struct ALbufferlistitem *volatile next;
22 } ALbufferlistitem;
25 struct ALsourceProps {
26 ATOMIC(ALfloat) Pitch;
27 ATOMIC(ALfloat) Gain;
28 ATOMIC(ALfloat) OuterGain;
29 ATOMIC(ALfloat) MinGain;
30 ATOMIC(ALfloat) MaxGain;
31 ATOMIC(ALfloat) InnerAngle;
32 ATOMIC(ALfloat) OuterAngle;
33 ATOMIC(ALfloat) RefDistance;
34 ATOMIC(ALfloat) MaxDistance;
35 ATOMIC(ALfloat) RollOffFactor;
36 ATOMIC(ALfloat) Position[3];
37 ATOMIC(ALfloat) Velocity[3];
38 ATOMIC(ALfloat) Direction[3];
39 ATOMIC(ALfloat) Orientation[2][3];
40 ATOMIC(ALboolean) HeadRelative;
41 ATOMIC(enum DistanceModel) DistanceModel;
42 ATOMIC(ALboolean) DirectChannels;
44 ATOMIC(ALboolean) DryGainHFAuto;
45 ATOMIC(ALboolean) WetGainAuto;
46 ATOMIC(ALboolean) WetGainHFAuto;
47 ATOMIC(ALfloat) OuterGainHF;
49 ATOMIC(ALfloat) AirAbsorptionFactor;
50 ATOMIC(ALfloat) RoomRolloffFactor;
51 ATOMIC(ALfloat) DopplerFactor;
53 ATOMIC(ALfloat) StereoPan[2];
55 ATOMIC(ALfloat) Radius;
57 /** Direct filter and auxiliary send info. */
58 struct {
59 ATOMIC(ALfloat) Gain;
60 ATOMIC(ALfloat) GainHF;
61 ATOMIC(ALfloat) HFReference;
62 ATOMIC(ALfloat) GainLF;
63 ATOMIC(ALfloat) LFReference;
64 } Direct;
65 struct {
66 ATOMIC(struct ALeffectslot*) Slot;
67 ATOMIC(ALfloat) Gain;
68 ATOMIC(ALfloat) GainHF;
69 ATOMIC(ALfloat) HFReference;
70 ATOMIC(ALfloat) GainLF;
71 ATOMIC(ALfloat) LFReference;
72 } Send[MAX_SENDS];
74 ATOMIC(struct ALsourceProps*) next;
78 typedef struct ALvoice {
79 struct ALsourceProps Props;
81 struct ALsource *Source;
83 /** Current target parameters used for mixing. */
84 ALint Step;
86 /* If not 'moving', gain/coefficients are set directly without fading. */
87 ALboolean Moving;
89 ALboolean IsHrtf;
91 ALuint Offset; /* Number of output samples mixed since starting. */
93 alignas(16) ALfloat PrevSamples[MAX_INPUT_CHANNELS][MAX_PRE_SAMPLES];
95 BsincState SincState;
97 struct {
98 ALfloat (*Buffer)[BUFFERSIZE];
99 ALuint Channels;
100 } DirectOut;
102 struct {
103 ALfloat (*Buffer)[BUFFERSIZE];
104 ALuint Channels;
105 } SendOut[MAX_SENDS];
107 struct {
108 DirectParams Direct;
109 SendParams Send[MAX_SENDS];
110 } Chan[MAX_INPUT_CHANNELS];
111 } ALvoice;
114 typedef struct ALsource {
115 /** Source properties. */
116 ALfloat Pitch;
117 ALfloat Gain;
118 ALfloat OuterGain;
119 ALfloat MinGain;
120 ALfloat MaxGain;
121 ALfloat InnerAngle;
122 ALfloat OuterAngle;
123 ALfloat RefDistance;
124 ALfloat MaxDistance;
125 ALfloat RollOffFactor;
126 ALfloat Position[3];
127 ALfloat Velocity[3];
128 ALfloat Direction[3];
129 ALfloat Orientation[2][3];
130 ALboolean HeadRelative;
131 enum DistanceModel DistanceModel;
132 ALboolean DirectChannels;
134 ALboolean DryGainHFAuto;
135 ALboolean WetGainAuto;
136 ALboolean WetGainHFAuto;
137 ALfloat OuterGainHF;
139 ALfloat AirAbsorptionFactor;
140 ALfloat RoomRolloffFactor;
141 ALfloat DopplerFactor;
143 /* NOTE: Stereo pan angles are specified in radians, counter-clockwise
144 * rather than clockwise.
146 ALfloat StereoPan[2];
148 ALfloat Radius;
150 /** Direct filter and auxiliary send info. */
151 struct {
152 ALfloat Gain;
153 ALfloat GainHF;
154 ALfloat HFReference;
155 ALfloat GainLF;
156 ALfloat LFReference;
157 } Direct;
158 struct {
159 struct ALeffectslot *Slot;
160 ALfloat Gain;
161 ALfloat GainHF;
162 ALfloat HFReference;
163 ALfloat GainLF;
164 ALfloat LFReference;
165 } Send[MAX_SENDS];
168 * Last user-specified offset, and the offset type (bytes, samples, or
169 * seconds).
171 ALdouble Offset;
172 ALenum OffsetType;
174 /** Source type (static, streaming, or undetermined) */
175 ALint SourceType;
177 /** Source state (initial, playing, paused, or stopped) */
178 ALenum state;
179 ALenum new_state;
181 /** Source Buffer Queue info. */
182 RWLock queue_lock;
183 ATOMIC(ALbufferlistitem*) queue;
184 ATOMIC(ALbufferlistitem*) current_buffer;
187 * Source offset in samples, relative to the currently playing buffer, NOT
188 * the whole queue, and the fractional (fixed-point) offset to the next
189 * sample.
191 ATOMIC(ALuint) position;
192 ATOMIC(ALuint) position_fraction;
194 ATOMIC(ALboolean) looping;
196 /** Current buffer sample info. */
197 ALuint NumChannels;
198 ALuint SampleSize;
200 ALenum NeedsUpdate;
202 ATOMIC(struct ALsourceProps*) Update;
203 ATOMIC(struct ALsourceProps*) FreeList;
205 /** Self ID */
206 ALuint id;
207 } ALsource;
209 inline void LockSourcesRead(ALCcontext *context)
210 { LockUIntMapRead(&context->SourceMap); }
211 inline void UnlockSourcesRead(ALCcontext *context)
212 { UnlockUIntMapRead(&context->SourceMap); }
213 inline void LockSourcesWrite(ALCcontext *context)
214 { LockUIntMapWrite(&context->SourceMap); }
215 inline void UnlockSourcesWrite(ALCcontext *context)
216 { UnlockUIntMapWrite(&context->SourceMap); }
218 inline struct ALsource *LookupSource(ALCcontext *context, ALuint id)
219 { return (struct ALsource*)LookupUIntMapKeyNoLock(&context->SourceMap, id); }
220 inline struct ALsource *RemoveSource(ALCcontext *context, ALuint id)
221 { return (struct ALsource*)RemoveUIntMapKeyNoLock(&context->SourceMap, id); }
223 void UpdateAllSourceProps(ALCcontext *context);
224 ALvoid SetSourceState(ALsource *Source, ALCcontext *Context, ALenum state);
225 ALboolean ApplyOffset(ALsource *Source);
227 ALvoid ReleaseALSources(ALCcontext *Context);
229 #ifdef __cplusplus
231 #endif
233 #endif