Remove an unnecessary variable
[alure.git] / src / source.h
blobf2a58a04d7d99243c1cc0259d5d0eb2e2efb161f
1 #ifndef SOURCE_H
2 #define SOURCE_H
4 #include "main.h"
6 #include <unordered_map>
7 #include <atomic>
8 #include <mutex>
10 #include "al.h"
11 #include "alext.h"
13 namespace alure {
15 class ALBufferStream;
17 struct SendProps {
18 AuxiliaryEffectSlotImpl *mSlot;
19 ALuint mFilter;
21 SendProps(AuxiliaryEffectSlotImpl *slot) : mSlot(slot), mFilter(AL_FILTER_NULL)
22 { }
23 SendProps(ALuint filter) : mSlot(0), mFilter(filter)
24 { }
25 SendProps(AuxiliaryEffectSlotImpl *slot, ALuint filter) : mSlot(slot), mFilter(filter)
26 { }
28 typedef std::unordered_map<ALuint,SendProps> SendPropMap;
30 class SourceImpl {
31 ContextImpl *const mContext;
32 ALuint mId;
34 BufferImpl *mBuffer;
35 UniquePtr<ALBufferStream> mStream;
37 SourceGroupImpl *mGroup;
38 ALfloat mGroupPitch;
39 ALfloat mGroupGain;
41 std::chrono::steady_clock::time_point mLastFadeTime;
42 std::chrono::steady_clock::time_point mFadeTimeTarget;
43 ALfloat mFadeGainTarget;
44 ALfloat mFadeGain;
46 mutable std::mutex mMutex;
47 std::atomic<bool> mIsAsync;
49 std::atomic<bool> mPaused;
50 ALuint64SOFT mOffset;
51 ALfloat mPitch;
52 ALfloat mGain;
53 ALfloat mMinGain, mMaxGain;
54 ALfloat mRefDist, mMaxDist;
55 Vector3 mPosition;
56 Vector3 mVelocity;
57 Vector3 mDirection;
58 Vector3 mOrientation[2];
59 ALfloat mConeInnerAngle, mConeOuterAngle;
60 ALfloat mConeOuterGain, mConeOuterGainHF;
61 ALfloat mRolloffFactor, mRoomRolloffFactor;
62 ALfloat mDopplerFactor;
63 ALfloat mAirAbsorptionFactor;
64 ALfloat mRadius;
65 ALfloat mStereoAngles[2];
66 Spatialize mSpatialize;
67 ALsizei mResampler;
68 bool mLooping : 1;
69 bool mRelative : 1;
70 bool mDryGainHFAuto : 1;
71 bool mWetGainAuto : 1;
72 bool mWetGainHFAuto : 1;
74 ALuint mDirectFilter;
75 SendPropMap mEffectSlots;
77 ALuint mPriority;
79 void resetProperties();
80 void applyProperties(bool looping, ALuint offset) const;
82 ALint refillBufferStream();
84 void setFilterParams(ALuint &filterid, const FilterParams &params);
86 public:
87 SourceImpl(ContextImpl *context);
88 ~SourceImpl();
90 ALuint getId() const { return mId; }
92 bool fadeUpdate(std::chrono::steady_clock::time_point cur_fade_time);
93 bool playUpdate(ALuint id);
94 bool playUpdate();
95 bool updateAsync();
97 void setGroup(SourceGroupImpl *group);
98 void unsetGroup();
99 void groupPropUpdate(ALfloat gain, ALfloat pitch);
101 void checkPaused();
102 void unsetPaused() { mPaused = false; }
103 void makeStopped(bool dolock=true);
105 void play(Buffer buffer);
106 void play(SharedPtr<Decoder> decoder, ALuint updatelen, ALuint queuesize);
107 void stop();
108 void fadeOutToStop(ALfloat gain, std::chrono::milliseconds duration);
109 void pause();
110 void resume();
112 bool isPlaying() const;
113 bool isPaused() const;
115 void setPriority(ALuint priority);
116 ALuint getPriority() const { return mPriority; }
118 void setOffset(uint64_t offset);
119 std::pair<uint64_t,std::chrono::nanoseconds> getSampleOffsetLatency() const;
120 std::pair<Seconds,Seconds> getSecOffsetLatency() const;
122 void setLooping(bool looping);
123 bool getLooping() const { return mLooping; }
125 void setPitch(ALfloat pitch);
126 ALfloat getPitch() const { return mPitch; }
128 void setGain(ALfloat gain);
129 ALfloat getGain() const { return mGain; }
131 void setGainRange(ALfloat mingain, ALfloat maxgain);
132 std::pair<ALfloat,ALfloat> getGainRange() const
133 { return {mMinGain, mMaxGain}; }
135 void setDistanceRange(ALfloat refdist, ALfloat maxdist);
136 std::pair<ALfloat,ALfloat> getDistanceRange() const
137 { return {mRefDist, mMaxDist}; }
139 void set3DParameters(const Vector3 &position, const Vector3 &velocity, const Vector3 &direction);
140 void set3DParameters(const Vector3 &position, const Vector3 &velocity, std::pair<Vector3,Vector3> orientation);
142 void setPosition(ALfloat x, ALfloat y, ALfloat z);
143 void setPosition(const ALfloat *pos);
144 Vector3 getPosition() const { return mPosition; }
146 void setVelocity(ALfloat x, ALfloat y, ALfloat z);
147 void setVelocity(const ALfloat *vel);
148 Vector3 getVelocity() const { return mVelocity; }
150 void setDirection(ALfloat x, ALfloat y, ALfloat z);
151 void setDirection(const ALfloat *dir);
152 Vector3 getDirection() const { return mDirection; }
154 void setOrientation(ALfloat x1, ALfloat y1, ALfloat z1, ALfloat x2, ALfloat y2, ALfloat z2);
155 void setOrientation(const ALfloat *at, const ALfloat *up);
156 void setOrientation(const ALfloat *ori);
157 std::pair<Vector3,Vector3> getOrientation() const
158 { return {mOrientation[0], mOrientation[1]}; }
160 void setConeAngles(ALfloat inner, ALfloat outer);
161 std::pair<ALfloat,ALfloat> getConeAngles() const
162 { return {mConeInnerAngle, mConeOuterAngle}; }
164 void setOuterConeGains(ALfloat gain, ALfloat gainhf=1.0f);
165 std::pair<ALfloat,ALfloat> getOuterConeGains() const
166 { return {mConeOuterGain, mConeOuterGainHF}; }
168 void setRolloffFactors(ALfloat factor, ALfloat roomfactor=0.0f);
169 std::pair<ALfloat,ALfloat> getRolloffFactors() const
170 { return {mRolloffFactor, mRoomRolloffFactor}; }
172 void setDopplerFactor(ALfloat factor);
173 ALfloat getDopplerFactor() const { return mDopplerFactor; }
175 void setRelative(bool relative);
176 bool getRelative() const { return mRelative; }
178 void setRadius(ALfloat radius);
179 ALfloat getRadius() const { return mRadius; }
181 void setStereoAngles(ALfloat leftAngle, ALfloat rightAngle);
182 std::pair<ALfloat,ALfloat> getStereoAngles() const
183 { return std::make_pair(mStereoAngles[0], mStereoAngles[1]); }
185 void set3DSpatialize(Spatialize spatialize);
186 Spatialize get3DSpatialize() const { return mSpatialize; }
188 void setResamplerIndex(ALsizei index);
189 ALsizei getResamplerIndex() const { return mResampler; }
191 void setAirAbsorptionFactor(ALfloat factor);
192 ALfloat getAirAbsorptionFactor() const { return mAirAbsorptionFactor; }
194 void setGainAuto(bool directhf, bool send, bool sendhf);
195 std::tuple<bool,bool,bool> getGainAuto() const
196 { return std::make_tuple(mDryGainHFAuto, mWetGainAuto, mWetGainHFAuto); }
198 void setDirectFilter(const FilterParams &filter);
199 void setSendFilter(ALuint send, const FilterParams &filter);
200 void setAuxiliarySend(AuxiliaryEffectSlot slot, ALuint send);
201 void setAuxiliarySendFilter(AuxiliaryEffectSlot slot, ALuint send, const FilterParams &filter);
203 void release();
207 struct SourceBufferUpdateEntry {
208 SourceImpl *mSource;
209 ALuint mId;
211 struct SourceStreamUpdateEntry {
212 SourceImpl *mSource;
215 } // namespace alure
217 #endif /* SOURCE_H */