Use hidden visibility by default
[alure.git] / src / source.h
blob17fd5a3712005e568d872c2b1156d6b10df243a3
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 ContextImpl;
16 class BufferImpl;
17 class ALBufferStream;
18 class AuxiliaryEffectSlotImpl;
19 class SourceGroupImpl;
21 struct SendProps {
22 AuxiliaryEffectSlotImpl *mSlot;
23 ALuint mFilter;
25 SendProps(AuxiliaryEffectSlotImpl *slot) : mSlot(slot), mFilter(AL_FILTER_NULL)
26 { }
27 SendProps(ALuint filter) : mSlot(0), mFilter(filter)
28 { }
29 SendProps(AuxiliaryEffectSlotImpl *slot, ALuint filter) : mSlot(slot), mFilter(filter)
30 { }
32 typedef std::unordered_map<ALuint,SendProps> SendPropMap;
34 class SourceImpl {
35 ContextImpl *const mContext;
36 ALuint mId;
38 BufferImpl *mBuffer;
39 UniquePtr<ALBufferStream> mStream;
41 SourceGroupImpl *mGroup;
43 mutable std::mutex mMutex;
44 std::atomic<bool> mIsAsync;
46 std::atomic<bool> mPaused;
47 ALuint64SOFT mOffset;
48 ALfloat mPitch;
49 ALfloat mGain;
50 ALfloat mMinGain, mMaxGain;
51 ALfloat mRefDist, mMaxDist;
52 Vector3 mPosition;
53 Vector3 mVelocity;
54 Vector3 mDirection;
55 Vector3 mOrientation[2];
56 ALfloat mConeInnerAngle, mConeOuterAngle;
57 ALfloat mConeOuterGain, mConeOuterGainHF;
58 ALfloat mRolloffFactor, mRoomRolloffFactor;
59 ALfloat mDopplerFactor;
60 ALfloat mAirAbsorptionFactor;
61 ALfloat mRadius;
62 ALfloat mStereoAngles[2];
63 Spatialize mSpatialize;
64 ALsizei mResampler;
65 bool mLooping : 1;
66 bool mRelative : 1;
67 bool mDryGainHFAuto : 1;
68 bool mWetGainAuto : 1;
69 bool mWetGainHFAuto : 1;
71 ALuint mDirectFilter;
72 SendPropMap mEffectSlots;
74 ALuint mPriority;
76 void resetProperties();
77 void applyProperties(bool looping, ALuint offset) const;
79 ALint refillBufferStream();
81 void setFilterParams(ALuint &filterid, const FilterParams &params);
83 public:
84 SourceImpl(ContextImpl *context);
85 ~SourceImpl();
87 ALuint getId() const { return mId; }
89 bool playUpdate(ALuint id);
90 bool playUpdate();
91 bool updateAsync();
93 void setGroup(SourceGroupImpl *group);
94 void unsetGroup();
96 void groupUpdate();
97 void groupPropUpdate(ALfloat gain, ALfloat pitch);
99 void checkPaused();
100 void unsetPaused() { mPaused = false; }
101 void makeStopped(bool dolock=true);
103 void play(Buffer buffer);
104 void play(SharedPtr<Decoder> decoder, ALuint updatelen, ALuint queuesize);
105 void stop();
106 void pause();
107 void resume();
109 bool isPlaying() const;
110 bool isPaused() const;
112 void setPriority(ALuint priority);
113 ALuint getPriority() const { return mPriority; }
115 void setOffset(uint64_t offset);
116 std::pair<uint64_t,std::chrono::nanoseconds> getSampleOffsetLatency() const;
117 std::pair<Seconds,Seconds> getSecOffsetLatency() const;
119 void setLooping(bool looping);
120 bool getLooping() const { return mLooping; }
122 void setPitch(ALfloat pitch);
123 ALfloat getPitch() const { return mPitch; }
125 void setGain(ALfloat gain);
126 ALfloat getGain() const { return mGain; }
128 void setGainRange(ALfloat mingain, ALfloat maxgain);
129 std::pair<ALfloat,ALfloat> getGainRange() const
130 { return {mMinGain, mMaxGain}; }
132 void setDistanceRange(ALfloat refdist, ALfloat maxdist);
133 std::pair<ALfloat,ALfloat> getDistanceRange() const
134 { return {mRefDist, mMaxDist}; }
136 void set3DParameters(const Vector3 &position, const Vector3 &velocity, const Vector3 &direction);
137 void set3DParameters(const Vector3 &position, const Vector3 &velocity, std::pair<Vector3,Vector3> orientation);
139 void setPosition(ALfloat x, ALfloat y, ALfloat z);
140 void setPosition(const ALfloat *pos);
141 Vector3 getPosition() const { return mPosition; }
143 void setVelocity(ALfloat x, ALfloat y, ALfloat z);
144 void setVelocity(const ALfloat *vel);
145 Vector3 getVelocity() const { return mVelocity; }
147 void setDirection(ALfloat x, ALfloat y, ALfloat z);
148 void setDirection(const ALfloat *dir);
149 Vector3 getDirection() const { return mDirection; }
151 void setOrientation(ALfloat x1, ALfloat y1, ALfloat z1, ALfloat x2, ALfloat y2, ALfloat z2);
152 void setOrientation(const ALfloat *at, const ALfloat *up);
153 void setOrientation(const ALfloat *ori);
154 std::pair<Vector3,Vector3> getOrientation() const
155 { return {mOrientation[0], mOrientation[1]}; }
157 void setConeAngles(ALfloat inner, ALfloat outer);
158 std::pair<ALfloat,ALfloat> getConeAngles() const
159 { return {mConeInnerAngle, mConeOuterAngle}; }
161 void setOuterConeGains(ALfloat gain, ALfloat gainhf=1.0f);
162 std::pair<ALfloat,ALfloat> getOuterConeGains() const
163 { return {mConeOuterGain, mConeOuterGainHF}; }
165 void setRolloffFactors(ALfloat factor, ALfloat roomfactor=0.0f);
166 std::pair<ALfloat,ALfloat> getRolloffFactors() const
167 { return {mRolloffFactor, mRoomRolloffFactor}; }
169 void setDopplerFactor(ALfloat factor);
170 ALfloat getDopplerFactor() const { return mDopplerFactor; }
172 void setRelative(bool relative);
173 bool getRelative() const { return mRelative; }
175 void setRadius(ALfloat radius);
176 ALfloat getRadius() const { return mRadius; }
178 void setStereoAngles(ALfloat leftAngle, ALfloat rightAngle);
179 std::pair<ALfloat,ALfloat> getStereoAngles() const
180 { return std::make_pair(mStereoAngles[0], mStereoAngles[1]); }
182 void set3DSpatialize(Spatialize spatialize);
183 Spatialize get3DSpatialize() const { return mSpatialize; }
185 void setResamplerIndex(ALsizei index);
186 ALsizei getResamplerIndex() const { return mResampler; }
188 void setAirAbsorptionFactor(ALfloat factor);
189 ALfloat getAirAbsorptionFactor() const { return mAirAbsorptionFactor; }
191 void setGainAuto(bool directhf, bool send, bool sendhf);
192 std::tuple<bool,bool,bool> getGainAuto() const
193 { return std::make_tuple(mDryGainHFAuto, mWetGainAuto, mWetGainHFAuto); }
195 void setDirectFilter(const FilterParams &filter);
196 void setSendFilter(ALuint send, const FilterParams &filter);
197 void setAuxiliarySend(AuxiliaryEffectSlot slot, ALuint send);
198 void setAuxiliarySendFilter(AuxiliaryEffectSlot slot, ALuint send, const FilterParams &filter);
200 void release();
204 struct SourceBufferUpdateEntry {
205 SourceImpl *mSource;
206 ALuint mId;
208 struct SourceStreamUpdateEntry {
209 SourceImpl *mSource;
212 } // namespace alure
214 #endif /* SOURCE_H */