Fix compilation with older alext.h headers
[alure.git] / src / source.h
blob3716be8cb4f8016c4bc2f58df39b22b15b4d1bde
1 #ifndef SOURCE_H
2 #define SOURCE_H
4 #include "main.h"
6 #include <atomic>
7 #include <mutex>
9 #include "al.h"
10 #include "alext.h"
12 namespace alure {
14 class ALBufferStream;
16 struct SendProps {
17 ALuint mSendIdx;
18 AuxiliaryEffectSlotImpl *mSlot;
19 ALuint mFilter;
21 SendProps(ALuint send, AuxiliaryEffectSlotImpl *slot)
22 : mSendIdx(send), mSlot(slot), mFilter(AL_FILTER_NULL)
23 { }
24 SendProps(ALuint send, ALuint filter) : mSendIdx(send), mSlot(0), mFilter(filter)
25 { }
26 SendProps(ALuint send, AuxiliaryEffectSlotImpl *slot, ALuint filter)
27 : mSendIdx(send), mSlot(slot), mFilter(filter)
28 { }
31 class SourceImpl {
32 ContextImpl *const mContext;
33 ALuint mId;
35 BufferImpl *mBuffer;
36 UniquePtr<ALBufferStream> mStream;
38 SourceGroupImpl *mGroup;
39 ALfloat mGroupPitch;
40 ALfloat mGroupGain;
42 std::chrono::steady_clock::time_point mLastFadeTime;
43 std::chrono::steady_clock::time_point mFadeTimeTarget;
44 ALfloat mFadeGainTarget;
45 ALfloat mFadeGain;
47 mutable std::mutex mMutex;
48 std::atomic<bool> mIsAsync;
50 std::atomic<bool> mPaused;
51 ALuint64SOFT mOffset;
52 ALfloat mPitch;
53 ALfloat mGain;
54 ALfloat mMinGain, mMaxGain;
55 ALfloat mRefDist, mMaxDist;
56 Vector3 mPosition;
57 Vector3 mVelocity;
58 Vector3 mDirection;
59 Vector3 mOrientation[2];
60 ALfloat mConeInnerAngle, mConeOuterAngle;
61 ALfloat mConeOuterGain, mConeOuterGainHF;
62 ALfloat mRolloffFactor, mRoomRolloffFactor;
63 ALfloat mDopplerFactor;
64 ALfloat mAirAbsorptionFactor;
65 ALfloat mRadius;
66 ALfloat mStereoAngles[2];
67 Spatialize mSpatialize;
68 ALsizei mResampler;
69 bool mLooping : 1;
70 bool mRelative : 1;
71 bool mDryGainHFAuto : 1;
72 bool mWetGainAuto : 1;
73 bool mWetGainHFAuto : 1;
75 ALuint mDirectFilter;
76 Vector<SendProps> mEffectSlots;
78 ALuint mPriority;
80 void resetProperties();
81 void applyProperties(bool looping, ALuint offset) const;
83 ALint refillBufferStream();
85 void setFilterParams(ALuint &filterid, const FilterParams &params);
87 public:
88 SourceImpl(ContextImpl *context);
89 ~SourceImpl();
91 ALuint getId() const { return mId; }
93 bool checkPending(SharedFuture<Buffer> &future);
94 bool fadeUpdate(std::chrono::steady_clock::time_point cur_fade_time);
95 bool playUpdate(ALuint id);
96 bool playUpdate();
97 bool updateAsync();
99 void unsetGroup();
100 void groupPropUpdate(ALfloat gain, ALfloat pitch);
102 void checkPaused();
103 void unsetPaused() { mPaused = false; }
104 void makeStopped(bool dolock=true);
106 void play(Buffer buffer);
107 void play(SharedPtr<Decoder>&& decoder, ALuint chunk_len, ALuint queue_size);
108 void play(SharedFuture<Buffer>&& future_buffer);
109 void stop();
110 void fadeOutToStop(ALfloat gain, std::chrono::milliseconds duration);
111 void pause();
112 void resume();
114 bool isPending() const;
115 bool isPlaying() const;
116 bool isPaused() const;
118 void setGroup(SourceGroup group);
119 SourceGroup getGroup() const { return SourceGroup(mGroup); }
121 void setPriority(ALuint priority);
122 ALuint getPriority() const { return mPriority; }
124 void setOffset(uint64_t offset);
125 std::pair<uint64_t,std::chrono::nanoseconds> getSampleOffsetLatency() const;
126 std::pair<Seconds,Seconds> getSecOffsetLatency() const;
128 void setLooping(bool looping);
129 bool getLooping() const { return mLooping; }
131 void setPitch(ALfloat pitch);
132 ALfloat getPitch() const { return mPitch; }
134 void setGain(ALfloat gain);
135 ALfloat getGain() const { return mGain; }
137 void setGainRange(ALfloat mingain, ALfloat maxgain);
138 std::pair<ALfloat,ALfloat> getGainRange() const
139 { return {mMinGain, mMaxGain}; }
141 void setDistanceRange(ALfloat refdist, ALfloat maxdist);
142 std::pair<ALfloat,ALfloat> getDistanceRange() const
143 { return {mRefDist, mMaxDist}; }
145 void set3DParameters(const Vector3 &position, const Vector3 &velocity, const Vector3 &direction);
146 void set3DParameters(const Vector3 &position, const Vector3 &velocity, const std::pair<Vector3,Vector3> &orientation);
148 void setPosition(ALfloat x, ALfloat y, ALfloat z);
149 void setPosition(const ALfloat *pos);
150 Vector3 getPosition() const { return mPosition; }
152 void setVelocity(ALfloat x, ALfloat y, ALfloat z);
153 void setVelocity(const ALfloat *vel);
154 Vector3 getVelocity() const { return mVelocity; }
156 void setDirection(ALfloat x, ALfloat y, ALfloat z);
157 void setDirection(const ALfloat *dir);
158 Vector3 getDirection() const { return mDirection; }
160 void setOrientation(ALfloat x1, ALfloat y1, ALfloat z1, ALfloat x2, ALfloat y2, ALfloat z2);
161 void setOrientation(const ALfloat *at, const ALfloat *up);
162 void setOrientation(const ALfloat *ori);
163 std::pair<Vector3,Vector3> getOrientation() const
164 { return {mOrientation[0], mOrientation[1]}; }
166 void setConeAngles(ALfloat inner, ALfloat outer);
167 std::pair<ALfloat,ALfloat> getConeAngles() const
168 { return {mConeInnerAngle, mConeOuterAngle}; }
170 void setOuterConeGains(ALfloat gain, ALfloat gainhf=1.0f);
171 std::pair<ALfloat,ALfloat> getOuterConeGains() const
172 { return {mConeOuterGain, mConeOuterGainHF}; }
174 void setRolloffFactors(ALfloat factor, ALfloat roomfactor=0.0f);
175 std::pair<ALfloat,ALfloat> getRolloffFactors() const
176 { return {mRolloffFactor, mRoomRolloffFactor}; }
178 void setDopplerFactor(ALfloat factor);
179 ALfloat getDopplerFactor() const { return mDopplerFactor; }
181 void setRelative(bool relative);
182 bool getRelative() const { return mRelative; }
184 void setRadius(ALfloat radius);
185 ALfloat getRadius() const { return mRadius; }
187 void setStereoAngles(ALfloat leftAngle, ALfloat rightAngle);
188 std::pair<ALfloat,ALfloat> getStereoAngles() const
189 { return std::make_pair(mStereoAngles[0], mStereoAngles[1]); }
191 void set3DSpatialize(Spatialize spatialize);
192 Spatialize get3DSpatialize() const { return mSpatialize; }
194 void setResamplerIndex(ALsizei index);
195 ALsizei getResamplerIndex() const { return mResampler; }
197 void setAirAbsorptionFactor(ALfloat factor);
198 ALfloat getAirAbsorptionFactor() const { return mAirAbsorptionFactor; }
200 void setGainAuto(bool directhf, bool send, bool sendhf);
201 std::tuple<bool,bool,bool> getGainAuto() const
202 { return std::make_tuple(mDryGainHFAuto, mWetGainAuto, mWetGainHFAuto); }
204 void setDirectFilter(const FilterParams &filter);
205 void setSendFilter(ALuint send, const FilterParams &filter);
206 void setAuxiliarySend(AuxiliaryEffectSlot slot, ALuint send);
207 void setAuxiliarySendFilter(AuxiliaryEffectSlot slot, ALuint send, const FilterParams &filter);
209 void release();
213 struct SourceBufferUpdateEntry {
214 SourceImpl *mSource;
215 ALuint mId;
217 struct SourceStreamUpdateEntry {
218 SourceImpl *mSource;
221 } // namespace alure
223 #endif /* SOURCE_H */