13596161425b3674b13285f67cec7980892c0ce7
[platform/upstream/openal-soft.git] / OpenAL32 / Include / alSource.h
1 #ifndef _AL_SOURCE_H_
2 #define _AL_SOURCE_H_
3
4 #define MAX_SENDS                 4
5
6 #include "alMain.h"
7 #include "alu.h"
8 #include "hrtf.h"
9
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13
14 struct ALbuffer;
15 struct ALsource;
16
17
18 typedef struct ALbufferlistitem {
19     struct ALbuffer *buffer;
20     struct ALbufferlistitem *volatile next;
21     struct ALbufferlistitem *volatile prev;
22 } ALbufferlistitem;
23
24
25 typedef struct ALvoice {
26     struct ALsource *volatile Source;
27
28     /** Method to update mixing parameters. */
29     ALvoid (*Update)(struct ALvoice *self, const struct ALsource *source, const ALCcontext *context);
30
31     /** Current target parameters used for mixing. */
32     ALint Step;
33
34     ALboolean IsHrtf;
35
36     ALuint Offset; /* Number of output samples mixed since starting. */
37
38     alignas(16) ALfloat PrevSamples[MAX_INPUT_CHANNELS][MAX_PRE_SAMPLES];
39
40     BsincState SincState;
41
42     DirectParams Direct;
43     SendParams Send[MAX_SENDS];
44 } ALvoice;
45
46
47 typedef struct ALsource {
48     /** Source properties. */
49     volatile ALfloat   Pitch;
50     volatile ALfloat   Gain;
51     volatile ALfloat   OuterGain;
52     volatile ALfloat   MinGain;
53     volatile ALfloat   MaxGain;
54     volatile ALfloat   InnerAngle;
55     volatile ALfloat   OuterAngle;
56     volatile ALfloat   RefDistance;
57     volatile ALfloat   MaxDistance;
58     volatile ALfloat   RollOffFactor;
59     aluVector Position;
60     aluVector Velocity;
61     aluVector Direction;
62     volatile ALfloat   Orientation[2][3];
63     volatile ALboolean HeadRelative;
64     volatile ALboolean Looping;
65     volatile enum DistanceModel DistanceModel;
66     volatile ALboolean DirectChannels;
67
68     volatile ALboolean DryGainHFAuto;
69     volatile ALboolean WetGainAuto;
70     volatile ALboolean WetGainHFAuto;
71     volatile ALfloat   OuterGainHF;
72
73     volatile ALfloat AirAbsorptionFactor;
74     volatile ALfloat RoomRolloffFactor;
75     volatile ALfloat DopplerFactor;
76
77     volatile ALfloat Radius;
78
79     /**
80      * Last user-specified offset, and the offset type (bytes, samples, or
81      * seconds).
82      */
83     ALdouble Offset;
84     ALenum   OffsetType;
85
86     /** Source type (static, streaming, or undetermined) */
87     volatile ALint SourceType;
88
89     /** Source state (initial, playing, paused, or stopped) */
90     volatile ALenum state;
91     ALenum new_state;
92
93     /**
94      * Source offset in samples, relative to the currently playing buffer, NOT
95      * the whole queue, and the fractional (fixed-point) offset to the next
96      * sample.
97      */
98     ALuint position;
99     ALuint position_fraction;
100
101     /** Source Buffer Queue info. */
102     ATOMIC(ALbufferlistitem*) queue;
103     ATOMIC(ALbufferlistitem*) current_buffer;
104     RWLock queue_lock;
105
106     /** Current buffer sample info. */
107     ALuint NumChannels;
108     ALuint SampleSize;
109
110     /** Direct filter and auxiliary send info. */
111     struct {
112         ALfloat Gain;
113         ALfloat GainHF;
114         ALfloat HFReference;
115         ALfloat GainLF;
116         ALfloat LFReference;
117     } Direct;
118     struct {
119         struct ALeffectslot *Slot;
120         ALfloat Gain;
121         ALfloat GainHF;
122         ALfloat HFReference;
123         ALfloat GainLF;
124         ALfloat LFReference;
125     } Send[MAX_SENDS];
126
127     /** Source needs to update its mixing parameters. */
128     ATOMIC(ALenum) NeedsUpdate;
129
130     /** Self ID */
131     ALuint id;
132 } ALsource;
133
134 inline struct ALsource *LookupSource(ALCcontext *context, ALuint id)
135 { return (struct ALsource*)LookupUIntMapKey(&context->SourceMap, id); }
136 inline struct ALsource *RemoveSource(ALCcontext *context, ALuint id)
137 { return (struct ALsource*)RemoveUIntMapKey(&context->SourceMap, id); }
138
139 ALvoid SetSourceState(ALsource *Source, ALCcontext *Context, ALenum state);
140 ALboolean ApplyOffset(ALsource *Source);
141
142 ALvoid ReleaseALSources(ALCcontext *Context);
143
144 #ifdef __cplusplus
145 }
146 #endif
147
148 #endif