Remove unnecessary forward declarations
[alure.git] / src / source.h
blobac4fd09b9ad6c9f4c2f173e1db5a2d821b593497
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;
39 mutable std::mutex mMutex;
40 std::atomic<bool> mIsAsync;
42 std::atomic<bool> mPaused;
43 ALuint64SOFT mOffset;
44 ALfloat mPitch;
45 ALfloat mGain;
46 ALfloat mMinGain, mMaxGain;
47 ALfloat mRefDist, mMaxDist;
48 Vector3 mPosition;
49 Vector3 mVelocity;
50 Vector3 mDirection;
51 Vector3 mOrientation[2];
52 ALfloat mConeInnerAngle, mConeOuterAngle;
53 ALfloat mConeOuterGain, mConeOuterGainHF;
54 ALfloat mRolloffFactor, mRoomRolloffFactor;
55 ALfloat mDopplerFactor;
56 ALfloat mAirAbsorptionFactor;
57 ALfloat mRadius;
58 ALfloat mStereoAngles[2];
59 Spatialize mSpatialize;
60 ALsizei mResampler;
61 bool mLooping : 1;
62 bool mRelative : 1;
63 bool mDryGainHFAuto : 1;
64 bool mWetGainAuto : 1;
65 bool mWetGainHFAuto : 1;
67 ALuint mDirectFilter;
68 SendPropMap mEffectSlots;
70 ALuint mPriority;
72 void resetProperties();
73 void applyProperties(bool looping, ALuint offset) const;
75 ALint refillBufferStream();
77 void setFilterParams(ALuint &filterid, const FilterParams &params);
79 public:
80 SourceImpl(ContextImpl *context);
81 ~SourceImpl();
83 ALuint getId() const { return mId; }
85 bool playUpdate(ALuint id);
86 bool playUpdate();
87 bool updateAsync();
89 void setGroup(SourceGroupImpl *group);
90 void unsetGroup();
92 void groupUpdate();
93 void groupPropUpdate(ALfloat gain, ALfloat pitch);
95 void checkPaused();
96 void unsetPaused() { mPaused = false; }
97 void makeStopped(bool dolock=true);
99 void play(Buffer buffer);
100 void play(SharedPtr<Decoder> decoder, ALuint updatelen, ALuint queuesize);
101 void stop();
102 void pause();
103 void resume();
105 bool isPlaying() const;
106 bool isPaused() const;
108 void setPriority(ALuint priority);
109 ALuint getPriority() const { return mPriority; }
111 void setOffset(uint64_t offset);
112 std::pair<uint64_t,std::chrono::nanoseconds> getSampleOffsetLatency() const;
113 std::pair<Seconds,Seconds> getSecOffsetLatency() const;
115 void setLooping(bool looping);
116 bool getLooping() const { return mLooping; }
118 void setPitch(ALfloat pitch);
119 ALfloat getPitch() const { return mPitch; }
121 void setGain(ALfloat gain);
122 ALfloat getGain() const { return mGain; }
124 void setGainRange(ALfloat mingain, ALfloat maxgain);
125 std::pair<ALfloat,ALfloat> getGainRange() const
126 { return {mMinGain, mMaxGain}; }
128 void setDistanceRange(ALfloat refdist, ALfloat maxdist);
129 std::pair<ALfloat,ALfloat> getDistanceRange() const
130 { return {mRefDist, mMaxDist}; }
132 void set3DParameters(const Vector3 &position, const Vector3 &velocity, const Vector3 &direction);
133 void set3DParameters(const Vector3 &position, const Vector3 &velocity, std::pair<Vector3,Vector3> orientation);
135 void setPosition(ALfloat x, ALfloat y, ALfloat z);
136 void setPosition(const ALfloat *pos);
137 Vector3 getPosition() const { return mPosition; }
139 void setVelocity(ALfloat x, ALfloat y, ALfloat z);
140 void setVelocity(const ALfloat *vel);
141 Vector3 getVelocity() const { return mVelocity; }
143 void setDirection(ALfloat x, ALfloat y, ALfloat z);
144 void setDirection(const ALfloat *dir);
145 Vector3 getDirection() const { return mDirection; }
147 void setOrientation(ALfloat x1, ALfloat y1, ALfloat z1, ALfloat x2, ALfloat y2, ALfloat z2);
148 void setOrientation(const ALfloat *at, const ALfloat *up);
149 void setOrientation(const ALfloat *ori);
150 std::pair<Vector3,Vector3> getOrientation() const
151 { return {mOrientation[0], mOrientation[1]}; }
153 void setConeAngles(ALfloat inner, ALfloat outer);
154 std::pair<ALfloat,ALfloat> getConeAngles() const
155 { return {mConeInnerAngle, mConeOuterAngle}; }
157 void setOuterConeGains(ALfloat gain, ALfloat gainhf=1.0f);
158 std::pair<ALfloat,ALfloat> getOuterConeGains() const
159 { return {mConeOuterGain, mConeOuterGainHF}; }
161 void setRolloffFactors(ALfloat factor, ALfloat roomfactor=0.0f);
162 std::pair<ALfloat,ALfloat> getRolloffFactors() const
163 { return {mRolloffFactor, mRoomRolloffFactor}; }
165 void setDopplerFactor(ALfloat factor);
166 ALfloat getDopplerFactor() const { return mDopplerFactor; }
168 void setRelative(bool relative);
169 bool getRelative() const { return mRelative; }
171 void setRadius(ALfloat radius);
172 ALfloat getRadius() const { return mRadius; }
174 void setStereoAngles(ALfloat leftAngle, ALfloat rightAngle);
175 std::pair<ALfloat,ALfloat> getStereoAngles() const
176 { return std::make_pair(mStereoAngles[0], mStereoAngles[1]); }
178 void set3DSpatialize(Spatialize spatialize);
179 Spatialize get3DSpatialize() const { return mSpatialize; }
181 void setResamplerIndex(ALsizei index);
182 ALsizei getResamplerIndex() const { return mResampler; }
184 void setAirAbsorptionFactor(ALfloat factor);
185 ALfloat getAirAbsorptionFactor() const { return mAirAbsorptionFactor; }
187 void setGainAuto(bool directhf, bool send, bool sendhf);
188 std::tuple<bool,bool,bool> getGainAuto() const
189 { return std::make_tuple(mDryGainHFAuto, mWetGainAuto, mWetGainHFAuto); }
191 void setDirectFilter(const FilterParams &filter);
192 void setSendFilter(ALuint send, const FilterParams &filter);
193 void setAuxiliarySend(AuxiliaryEffectSlot slot, ALuint send);
194 void setAuxiliarySendFilter(AuxiliaryEffectSlot slot, ALuint send, const FilterParams &filter);
196 void release();
200 struct SourceBufferUpdateEntry {
201 SourceImpl *mSource;
202 ALuint mId;
204 struct SourceStreamUpdateEntry {
205 SourceImpl *mSource;
208 } // namespace alure
210 #endif /* SOURCE_H */