Added support of AL_LOOP_COUNT Source parameter
[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 #ifdef __TIZEN__
102     /**
103      * Number of repeats Source should be played before finishing playback.
104      */
105     ALuint LoopCount;
106 #endif
107
108     /** Source Buffer Queue info. */
109     ATOMIC(ALbufferlistitem*) queue;
110     ATOMIC(ALbufferlistitem*) current_buffer;
111     RWLock queue_lock;
112
113     /** Current buffer sample info. */
114     ALuint NumChannels;
115     ALuint SampleSize;
116
117     /** Direct filter and auxiliary send info. */
118     struct {
119         ALfloat Gain;
120         ALfloat GainHF;
121         ALfloat HFReference;
122         ALfloat GainLF;
123         ALfloat LFReference;
124     } Direct;
125     struct {
126         struct ALeffectslot *Slot;
127         ALfloat Gain;
128         ALfloat GainHF;
129         ALfloat HFReference;
130         ALfloat GainLF;
131         ALfloat LFReference;
132     } Send[MAX_SENDS];
133
134     /** Source needs to update its mixing parameters. */
135     ATOMIC(ALenum) NeedsUpdate;
136
137     /** Self ID */
138     ALuint id;
139 } ALsource;
140
141 inline struct ALsource *LookupSource(ALCcontext *context, ALuint id)
142 { return (struct ALsource*)LookupUIntMapKey(&context->SourceMap, id); }
143 inline struct ALsource *RemoveSource(ALCcontext *context, ALuint id)
144 { return (struct ALsource*)RemoveUIntMapKey(&context->SourceMap, id); }
145
146 ALvoid SetSourceState(ALsource *Source, ALCcontext *Context, ALenum state);
147 ALboolean ApplyOffset(ALsource *Source);
148
149 ALvoid ReleaseALSources(ALCcontext *Context);
150
151 #ifdef __cplusplus
152 }
153 #endif
154
155 #endif