Store the voice output buffers separate from the params
[openal-soft.git] / OpenAL32 / Include / alSource.h
blob2dd8229c3d7932c6bb769ee2cf47ff394d3f0d13
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 typedef struct ALvoice {
26 struct ALsource *volatile Source;
28 /** Current target parameters used for mixing. */
29 ALint Step;
31 ALboolean Looping;
33 /* If not 'moving', gain/coefficients are set directly without fading. */
34 ALboolean Moving;
36 ALboolean IsHrtf;
38 ALuint Offset; /* Number of output samples mixed since starting. */
40 alignas(16) ALfloat PrevSamples[MAX_INPUT_CHANNELS][MAX_PRE_SAMPLES];
42 BsincState SincState;
44 struct {
45 ALfloat (*Buffer)[BUFFERSIZE];
46 ALuint Channels;
47 } DirectOut;
49 struct {
50 ALfloat (*Buffer)[BUFFERSIZE];
51 ALuint Channels;
52 } SendOut[MAX_SENDS];
54 DirectParams Direct;
55 SendParams Send[MAX_SENDS];
56 } ALvoice;
59 struct ALsourceProps {
60 ATOMIC(ALfloat) Pitch;
61 ATOMIC(ALfloat) Gain;
62 ATOMIC(ALfloat) OuterGain;
63 ATOMIC(ALfloat) MinGain;
64 ATOMIC(ALfloat) MaxGain;
65 ATOMIC(ALfloat) InnerAngle;
66 ATOMIC(ALfloat) OuterAngle;
67 ATOMIC(ALfloat) RefDistance;
68 ATOMIC(ALfloat) MaxDistance;
69 ATOMIC(ALfloat) RollOffFactor;
70 ATOMIC(ALfloat) Position[3];
71 ATOMIC(ALfloat) Velocity[3];
72 ATOMIC(ALfloat) Direction[3];
73 ATOMIC(ALfloat) Orientation[2][3];
74 ATOMIC(ALboolean) HeadRelative;
75 ATOMIC(ALboolean) Looping;
76 ATOMIC(enum DistanceModel) DistanceModel;
77 ATOMIC(ALboolean) DirectChannels;
79 ATOMIC(ALboolean) DryGainHFAuto;
80 ATOMIC(ALboolean) WetGainAuto;
81 ATOMIC(ALboolean) WetGainHFAuto;
82 ATOMIC(ALfloat) OuterGainHF;
84 ATOMIC(ALfloat) AirAbsorptionFactor;
85 ATOMIC(ALfloat) RoomRolloffFactor;
86 ATOMIC(ALfloat) DopplerFactor;
88 ATOMIC(ALfloat) StereoPan[2];
90 ATOMIC(ALfloat) Radius;
92 /** Direct filter and auxiliary send info. */
93 struct {
94 ATOMIC(ALfloat) Gain;
95 ATOMIC(ALfloat) GainHF;
96 ATOMIC(ALfloat) HFReference;
97 ATOMIC(ALfloat) GainLF;
98 ATOMIC(ALfloat) LFReference;
99 } Direct;
100 struct {
101 ATOMIC(struct ALeffectslot*) Slot;
102 ATOMIC(ALfloat) Gain;
103 ATOMIC(ALfloat) GainHF;
104 ATOMIC(ALfloat) HFReference;
105 ATOMIC(ALfloat) GainLF;
106 ATOMIC(ALfloat) LFReference;
107 } Send[MAX_SENDS];
109 ATOMIC(struct ALsourceProps*) next;
112 typedef struct ALsource {
113 /** Source properties. */
114 ALfloat Pitch;
115 ALfloat Gain;
116 ALfloat OuterGain;
117 ALfloat MinGain;
118 ALfloat MaxGain;
119 ALfloat InnerAngle;
120 ALfloat OuterAngle;
121 ALfloat RefDistance;
122 ALfloat MaxDistance;
123 ALfloat RollOffFactor;
124 ALfloat Position[3];
125 ALfloat Velocity[3];
126 ALfloat Direction[3];
127 ALfloat Orientation[2][3];
128 ALboolean HeadRelative;
129 ALboolean Looping;
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 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 /** Current buffer sample info. */
194 ALuint NumChannels;
195 ALuint SampleSize;
197 ATOMIC(struct ALsourceProps*) Update;
198 ATOMIC(struct ALsourceProps*) FreeList;
200 /** Self ID */
201 ALuint id;
202 } ALsource;
204 inline void LockSourcesRead(ALCcontext *context)
205 { LockUIntMapRead(&context->SourceMap); }
206 inline void UnlockSourcesRead(ALCcontext *context)
207 { UnlockUIntMapRead(&context->SourceMap); }
208 inline void LockSourcesWrite(ALCcontext *context)
209 { LockUIntMapWrite(&context->SourceMap); }
210 inline void UnlockSourcesWrite(ALCcontext *context)
211 { UnlockUIntMapWrite(&context->SourceMap); }
213 inline struct ALsource *LookupSource(ALCcontext *context, ALuint id)
214 { return (struct ALsource*)LookupUIntMapKeyNoLock(&context->SourceMap, id); }
215 inline struct ALsource *RemoveSource(ALCcontext *context, ALuint id)
216 { return (struct ALsource*)RemoveUIntMapKeyNoLock(&context->SourceMap, id); }
218 void UpdateAllSourceProps(ALCcontext *context);
219 ALvoid SetSourceState(ALsource *Source, ALCcontext *Context, ALenum state);
220 ALboolean ApplyOffset(ALsource *Source);
222 ALvoid ReleaseALSources(ALCcontext *Context);
224 #ifdef __cplusplus
226 #endif
228 #endif