Fix compilation with newer versions of DUMB
[alure.git] / src / source.h
blob41205e7dde5a4cc96dc6e8e1a68fccbf320ce5e2
1 #ifndef SOURCE_H
2 #define SOURCE_H
4 #include "main.h"
6 #include <atomic>
7 #include <mutex>
9 namespace alure {
11 class ALBufferStream;
13 struct SendProps {
14 ALuint mSendIdx;
15 AuxiliaryEffectSlotImpl *mSlot{nullptr};
16 ALuint mFilter{AL_FILTER_NULL};
18 SendProps(ALuint send, AuxiliaryEffectSlotImpl *slot) : mSendIdx(send), mSlot(slot)
19 { }
20 SendProps(ALuint send, ALuint filter) : mSendIdx(send), mFilter(filter)
21 { }
22 SendProps(ALuint send, AuxiliaryEffectSlotImpl *slot, ALuint filter)
23 : mSendIdx(send), mSlot(slot), mFilter(filter)
24 { }
27 struct SourceBufferUpdateEntry {
28 SourceImpl *mSource;
29 ALuint mId;
31 struct SourceStreamUpdateEntry {
32 SourceImpl *mSource;
35 struct SourceFadeUpdateEntry {
36 SourceImpl *mSource;
38 std::chrono::nanoseconds mFadeTimeStart;
39 std::chrono::nanoseconds mFadeTimeTarget;
40 bool mIsFadeOut;
41 ALfloat mFadeGainMult;
45 class SourceImpl {
46 ContextImpl &mContext;
47 ALuint mId;
49 BufferImpl *mBuffer;
50 UniquePtr<ALBufferStream> mStream;
52 SourceGroupImpl *mGroup;
53 ALfloat mGroupPitch;
54 ALfloat mGroupGain;
56 ALfloat mFadeGain;
58 mutable std::mutex mMutex;
59 std::atomic<bool> mIsAsync;
61 std::atomic<bool> mPaused;
62 uint64_t mOffset;
63 ALfloat mPitch;
64 ALfloat mGain;
65 ALfloat mMinGain, mMaxGain;
66 ALfloat mRefDist, mMaxDist;
67 Vector3 mPosition;
68 Vector3 mVelocity;
69 Vector3 mDirection;
70 Vector3 mOrientation[2];
71 ALfloat mConeInnerAngle, mConeOuterAngle;
72 ALfloat mConeOuterGain, mConeOuterGainHF;
73 ALfloat mRolloffFactor, mRoomRolloffFactor;
74 ALfloat mDopplerFactor;
75 ALfloat mAirAbsorptionFactor;
76 ALfloat mRadius;
77 ALfloat mStereoAngles[2];
78 Spatialize mSpatialize;
79 ALsizei mResampler;
80 bool mLooping : 1;
81 bool mRelative : 1;
82 bool mDryGainHFAuto : 1;
83 bool mWetGainAuto : 1;
84 bool mWetGainHFAuto : 1;
86 ALuint mDirectFilter;
87 Vector<SendProps> mEffectSlots;
89 ALuint mPriority;
91 void resetProperties();
92 void applyProperties(bool looping) const;
94 ALint refillBufferStream();
96 void setFilterParams(ALuint &filterid, const FilterParams &params);
98 public:
99 SourceImpl(ContextImpl &context);
100 ~SourceImpl();
102 ALuint getId() const { return mId; }
104 bool checkPending(SharedFuture<Buffer> &future);
105 bool fadeUpdate(std::chrono::nanoseconds cur_fade_time, SourceFadeUpdateEntry &fade);
106 bool playUpdate(ALuint id);
107 bool playUpdate();
108 bool updateAsync();
110 void unsetGroup();
111 void groupPropUpdate(ALfloat gain, ALfloat pitch);
113 void checkPaused();
114 void unsetPaused() { mPaused = false; }
116 void play(Buffer buffer);
117 void play(SharedPtr<Decoder>&& decoder, ALsizei chunk_len, ALsizei queue_size);
118 void play(SharedFuture<Buffer>&& future_buffer);
119 void stop();
120 void makeStopped(bool dolock=true);
121 void fadeOutToStop(ALfloat gain, std::chrono::milliseconds duration);
122 void pause();
123 void resume();
125 bool isPending() const;
126 bool isPlaying() const;
127 bool isPaused() const;
128 bool isPlayingOrPending() const;
130 void setGroup(SourceGroup group);
131 SourceGroup getGroup() const { return SourceGroup(mGroup); }
133 void setPriority(ALuint priority);
134 ALuint getPriority() const { return mPriority; }
136 void setOffset(uint64_t offset);
137 std::pair<uint64_t,std::chrono::nanoseconds> getSampleOffsetLatency() const;
138 std::pair<Seconds,Seconds> getSecOffsetLatency() const;
140 void setLooping(bool looping);
141 bool getLooping() const { return mLooping; }
143 void setPitch(ALfloat pitch);
144 ALfloat getPitch() const { return mPitch; }
146 void setGain(ALfloat gain);
147 ALfloat getGain() const { return mGain; }
149 void setGainRange(ALfloat mingain, ALfloat maxgain);
150 std::pair<ALfloat,ALfloat> getGainRange() const
151 { return {mMinGain, mMaxGain}; }
153 void setDistanceRange(ALfloat refdist, ALfloat maxdist);
154 std::pair<ALfloat,ALfloat> getDistanceRange() const
155 { return {mRefDist, mMaxDist}; }
157 void set3DParameters(const Vector3 &position, const Vector3 &velocity, const Vector3 &direction);
158 void set3DParameters(const Vector3 &position, const Vector3 &velocity, const std::pair<Vector3,Vector3> &orientation);
160 void setPosition(const Vector3 &position);
161 void setPosition(const ALfloat *pos);
162 Vector3 getPosition() const { return mPosition; }
164 void setVelocity(const Vector3 &velocity);
165 void setVelocity(const ALfloat *vel);
166 Vector3 getVelocity() const { return mVelocity; }
168 void setDirection(const Vector3 &direction);
169 void setDirection(const ALfloat *dir);
170 Vector3 getDirection() const { return mDirection; }
172 void setOrientation(const std::pair<Vector3,Vector3> &orientation);
173 void setOrientation(const ALfloat *at, const ALfloat *up);
174 void setOrientation(const ALfloat *ori);
175 std::pair<Vector3,Vector3> getOrientation() const
176 { return {mOrientation[0], mOrientation[1]}; }
178 void setConeAngles(ALfloat inner, ALfloat outer);
179 std::pair<ALfloat,ALfloat> getConeAngles() const
180 { return {mConeInnerAngle, mConeOuterAngle}; }
182 void setOuterConeGains(ALfloat gain, ALfloat gainhf=1.0f);
183 std::pair<ALfloat,ALfloat> getOuterConeGains() const
184 { return {mConeOuterGain, mConeOuterGainHF}; }
186 void setRolloffFactors(ALfloat factor, ALfloat roomfactor=0.0f);
187 std::pair<ALfloat,ALfloat> getRolloffFactors() const
188 { return {mRolloffFactor, mRoomRolloffFactor}; }
190 void setDopplerFactor(ALfloat factor);
191 ALfloat getDopplerFactor() const { return mDopplerFactor; }
193 void setRelative(bool relative);
194 bool getRelative() const { return mRelative; }
196 void setRadius(ALfloat radius);
197 ALfloat getRadius() const { return mRadius; }
199 void setStereoAngles(ALfloat leftAngle, ALfloat rightAngle);
200 std::pair<ALfloat,ALfloat> getStereoAngles() const
201 { return std::make_pair(mStereoAngles[0], mStereoAngles[1]); }
203 void set3DSpatialize(Spatialize spatialize);
204 Spatialize get3DSpatialize() const { return mSpatialize; }
206 void setResamplerIndex(ALsizei index);
207 ALsizei getResamplerIndex() const { return mResampler; }
209 void setAirAbsorptionFactor(ALfloat factor);
210 ALfloat getAirAbsorptionFactor() const { return mAirAbsorptionFactor; }
212 void setGainAuto(bool directhf, bool send, bool sendhf);
213 std::tuple<bool,bool,bool> getGainAuto() const
214 { return std::make_tuple(mDryGainHFAuto, mWetGainAuto, mWetGainHFAuto); }
216 void setDirectFilter(const FilterParams &filter);
217 void setSendFilter(ALuint send, const FilterParams &filter);
218 void setAuxiliarySend(AuxiliaryEffectSlot slot, ALuint send);
219 void setAuxiliarySendFilter(AuxiliaryEffectSlot slot, ALuint send, const FilterParams &filter);
221 void destroy();
224 } // namespace alure
226 #endif /* SOURCE_H */