Rename AL* implementation classes to *Impl
[alure.git] / src / source.h
blob6c09d7b5aba3a894ab650cb83b4bf5909e93d85d
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 void updateNoCtxCheck();
90 bool updateAsync();
92 void setGroup(SourceGroupImpl *group);
93 void unsetGroup();
95 void groupUpdate();
96 void groupPropUpdate(ALfloat gain, ALfloat pitch);
98 void checkPaused();
99 void unsetPaused() { mPaused = false; }
100 void makeStopped();
102 void play(Buffer buffer);
103 void play(SharedPtr<Decoder> decoder, ALuint updatelen, ALuint queuesize);
104 void stop();
105 void pause();
106 void resume();
108 bool isPlaying() const;
109 bool isPaused() const;
111 void setPriority(ALuint priority);
112 ALuint getPriority() const { return mPriority; }
114 void setOffset(uint64_t offset);
115 std::pair<uint64_t,std::chrono::nanoseconds> getSampleOffsetLatency() const;
116 std::pair<Seconds,Seconds> getSecOffsetLatency() const;
118 void setLooping(bool looping);
119 bool getLooping() const { return mLooping; }
121 void setPitch(ALfloat pitch);
122 ALfloat getPitch() const { return mPitch; }
124 void setGain(ALfloat gain);
125 ALfloat getGain() const { return mGain; }
127 void setGainRange(ALfloat mingain, ALfloat maxgain);
128 std::pair<ALfloat,ALfloat> getGainRange() const
129 { return {mMinGain, mMaxGain}; }
131 void setDistanceRange(ALfloat refdist, ALfloat maxdist);
132 std::pair<ALfloat,ALfloat> getDistanceRange() const
133 { return {mRefDist, mMaxDist}; }
135 void set3DParameters(const Vector3 &position, const Vector3 &velocity, const Vector3 &direction);
136 void set3DParameters(const Vector3 &position, const Vector3 &velocity, std::pair<Vector3,Vector3> orientation);
138 void setPosition(ALfloat x, ALfloat y, ALfloat z);
139 void setPosition(const ALfloat *pos);
140 Vector3 getPosition() const { return mPosition; }
142 void setVelocity(ALfloat x, ALfloat y, ALfloat z);
143 void setVelocity(const ALfloat *vel);
144 Vector3 getVelocity() const { return mVelocity; }
146 void setDirection(ALfloat x, ALfloat y, ALfloat z);
147 void setDirection(const ALfloat *dir);
148 Vector3 getDirection() const { return mDirection; }
150 void setOrientation(ALfloat x1, ALfloat y1, ALfloat z1, ALfloat x2, ALfloat y2, ALfloat z2);
151 void setOrientation(const ALfloat *at, const ALfloat *up);
152 void setOrientation(const ALfloat *ori);
153 std::pair<Vector3,Vector3> getOrientation() const
154 { return {mOrientation[0], mOrientation[1]}; }
156 void setConeAngles(ALfloat inner, ALfloat outer);
157 std::pair<ALfloat,ALfloat> getConeAngles() const
158 { return {mConeInnerAngle, mConeOuterAngle}; }
160 void setOuterConeGains(ALfloat gain, ALfloat gainhf=1.0f);
161 std::pair<ALfloat,ALfloat> getOuterConeGains() const
162 { return {mConeOuterGain, mConeOuterGainHF}; }
164 void setRolloffFactors(ALfloat factor, ALfloat roomfactor=0.0f);
165 std::pair<ALfloat,ALfloat> getRolloffFactors() const
166 { return {mRolloffFactor, mRoomRolloffFactor}; }
168 void setDopplerFactor(ALfloat factor);
169 ALfloat getDopplerFactor() const { return mDopplerFactor; }
171 void setRelative(bool relative);
172 bool getRelative() const { return mRelative; }
174 void setRadius(ALfloat radius);
175 ALfloat getRadius() const { return mRadius; }
177 void setStereoAngles(ALfloat leftAngle, ALfloat rightAngle);
178 std::pair<ALfloat,ALfloat> getStereoAngles() const
179 { return std::make_pair(mStereoAngles[0], mStereoAngles[1]); }
181 void set3DSpatialize(Spatialize spatialize);
182 Spatialize get3DSpatialize() const { return mSpatialize; }
184 void setResamplerIndex(ALsizei index);
185 ALsizei getResamplerIndex() const { return mResampler; }
187 void setAirAbsorptionFactor(ALfloat factor);
188 ALfloat getAirAbsorptionFactor() const { return mAirAbsorptionFactor; }
190 void setGainAuto(bool directhf, bool send, bool sendhf);
191 std::tuple<bool,bool,bool> getGainAuto() const
192 { return std::make_tuple(mDryGainHFAuto, mWetGainAuto, mWetGainHFAuto); }
194 void setDirectFilter(const FilterParams &filter);
195 void setSendFilter(ALuint send, const FilterParams &filter);
196 void setAuxiliarySend(AuxiliaryEffectSlot slot, ALuint send);
197 void setAuxiliarySendFilter(AuxiliaryEffectSlot slot, ALuint send, const FilterParams &filter);
199 void release();
202 } // namespace alure
204 #endif /* SOURCE_H */