Make the voices' Send[] array dynamically sized
[openal-soft.git] / OpenAL32 / Include / alSource.h
blob53e9a2f4785fad71d13a8a127a3e74f983135e8a
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(struct ALsourceProps*) next;
28 ATOMIC(ALfloat) Pitch;
29 ATOMIC(ALfloat) Gain;
30 ATOMIC(ALfloat) OuterGain;
31 ATOMIC(ALfloat) MinGain;
32 ATOMIC(ALfloat) MaxGain;
33 ATOMIC(ALfloat) InnerAngle;
34 ATOMIC(ALfloat) OuterAngle;
35 ATOMIC(ALfloat) RefDistance;
36 ATOMIC(ALfloat) MaxDistance;
37 ATOMIC(ALfloat) RollOffFactor;
38 ATOMIC(ALfloat) Position[3];
39 ATOMIC(ALfloat) Velocity[3];
40 ATOMIC(ALfloat) Direction[3];
41 ATOMIC(ALfloat) Orientation[2][3];
42 ATOMIC(ALboolean) HeadRelative;
43 ATOMIC(enum DistanceModel) DistanceModel;
44 ATOMIC(ALboolean) DirectChannels;
46 ATOMIC(ALboolean) DryGainHFAuto;
47 ATOMIC(ALboolean) WetGainAuto;
48 ATOMIC(ALboolean) WetGainHFAuto;
49 ATOMIC(ALfloat) OuterGainHF;
51 ATOMIC(ALfloat) AirAbsorptionFactor;
52 ATOMIC(ALfloat) RoomRolloffFactor;
53 ATOMIC(ALfloat) DopplerFactor;
55 ATOMIC(ALfloat) StereoPan[2];
57 ATOMIC(ALfloat) Radius;
59 /** Direct filter and auxiliary send info. */
60 struct {
61 ATOMIC(ALfloat) Gain;
62 ATOMIC(ALfloat) GainHF;
63 ATOMIC(ALfloat) HFReference;
64 ATOMIC(ALfloat) GainLF;
65 ATOMIC(ALfloat) LFReference;
66 } Direct;
67 struct {
68 ATOMIC(struct ALeffectslot*) Slot;
69 ATOMIC(ALfloat) Gain;
70 ATOMIC(ALfloat) GainHF;
71 ATOMIC(ALfloat) HFReference;
72 ATOMIC(ALfloat) GainLF;
73 ATOMIC(ALfloat) LFReference;
74 } Send[];
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 InterpState ResampleState;
97 struct {
98 DirectParams Params[MAX_INPUT_CHANNELS];
100 ALfloat (*Buffer)[BUFFERSIZE];
101 ALsizei Channels;
102 } Direct;
104 struct {
105 SendParams Params[MAX_INPUT_CHANNELS];
107 ALfloat (*Buffer)[BUFFERSIZE];
108 ALsizei Channels;
109 } Send[];
110 } ALvoice;
113 typedef struct ALsource {
114 /** Source properties. */
115 ALfloat Pitch;
116 ALfloat Gain;
117 ALfloat OuterGain;
118 ALfloat MinGain;
119 ALfloat MaxGain;
120 ALfloat InnerAngle;
121 ALfloat OuterAngle;
122 ALfloat RefDistance;
123 ALfloat MaxDistance;
124 ALfloat RollOffFactor;
125 ALfloat Position[3];
126 ALfloat Velocity[3];
127 ALfloat Direction[3];
128 ALfloat Orientation[2][3];
129 ALboolean HeadRelative;
130 enum DistanceModel DistanceModel;
131 ALboolean DirectChannels;
133 ALboolean DryGainHFAuto;
134 ALboolean WetGainAuto;
135 ALboolean WetGainHFAuto;
136 ALfloat OuterGainHF;
138 ALfloat AirAbsorptionFactor;
139 ALfloat RoomRolloffFactor;
140 ALfloat DopplerFactor;
142 /* NOTE: Stereo pan angles are specified in radians, counter-clockwise
143 * rather than clockwise.
145 ALfloat StereoPan[2];
147 ALfloat Radius;
149 /** Direct filter and auxiliary send info. */
150 struct {
151 ALfloat Gain;
152 ALfloat GainHF;
153 ALfloat HFReference;
154 ALfloat GainLF;
155 ALfloat LFReference;
156 } Direct;
157 struct {
158 struct ALeffectslot *Slot;
159 ALfloat Gain;
160 ALfloat GainHF;
161 ALfloat HFReference;
162 ALfloat GainLF;
163 ALfloat LFReference;
164 } Send[MAX_SENDS];
167 * Last user-specified offset, and the offset type (bytes, samples, or
168 * seconds).
170 ALdouble Offset;
171 ALenum OffsetType;
173 /** Source type (static, streaming, or undetermined) */
174 ALint SourceType;
176 /** Source state (initial, playing, paused, or stopped) */
177 ATOMIC(ALenum) state;
178 ALenum new_state;
180 /** Source Buffer Queue info. */
181 RWLock queue_lock;
182 ATOMIC(ALbufferlistitem*) queue;
183 ATOMIC(ALbufferlistitem*) current_buffer;
186 * Source offset in samples, relative to the currently playing buffer, NOT
187 * the whole queue, and the fractional (fixed-point) offset to the next
188 * sample.
190 ATOMIC(ALuint) position;
191 ATOMIC(ALuint) position_fraction;
193 ATOMIC(ALboolean) looping;
195 /** Current buffer sample info. */
196 ALsizei NumChannels;
197 ALsizei SampleSize;
199 ALenum NeedsUpdate;
201 ATOMIC(struct ALsourceProps*) Update;
202 ATOMIC(struct ALsourceProps*) FreeList;
204 /** Self ID */
205 ALuint id;
206 } ALsource;
208 inline void LockSourcesRead(ALCcontext *context)
209 { LockUIntMapRead(&context->SourceMap); }
210 inline void UnlockSourcesRead(ALCcontext *context)
211 { UnlockUIntMapRead(&context->SourceMap); }
212 inline void LockSourcesWrite(ALCcontext *context)
213 { LockUIntMapWrite(&context->SourceMap); }
214 inline void UnlockSourcesWrite(ALCcontext *context)
215 { UnlockUIntMapWrite(&context->SourceMap); }
217 inline struct ALsource *LookupSource(ALCcontext *context, ALuint id)
218 { return (struct ALsource*)LookupUIntMapKeyNoLock(&context->SourceMap, id); }
219 inline struct ALsource *RemoveSource(ALCcontext *context, ALuint id)
220 { return (struct ALsource*)RemoveUIntMapKeyNoLock(&context->SourceMap, id); }
222 void UpdateAllSourceProps(ALCcontext *context);
223 ALvoid SetSourceState(ALsource *Source, ALCcontext *Context, ALenum state);
224 ALboolean ApplyOffset(ALsource *Source);
226 inline ALboolean IsPlayingOrPaused(const ALsource *source)
228 ALenum state = ATOMIC_LOAD_SEQ(&source->state);
229 return state == AL_PLAYING || state == AL_PAUSED;
233 ALvoid ReleaseALSources(ALCcontext *Context);
235 #ifdef __cplusplus
237 #endif
239 #endif