Store the applied group properties in the source
[alure.git] / src / source.h
blob8a2a72f28b1aaf7fe7144f246f7d8f6440d2166a
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 mutable std::mutex mMutex;
42 std::atomic<bool> mIsAsync;
44 std::atomic<bool> mPaused;
45 ALuint64SOFT mOffset;
46 ALfloat mPitch;
47 ALfloat mGain;
48 ALfloat mMinGain, mMaxGain;
49 ALfloat mRefDist, mMaxDist;
50 Vector3 mPosition;
51 Vector3 mVelocity;
52 Vector3 mDirection;
53 Vector3 mOrientation[2];
54 ALfloat mConeInnerAngle, mConeOuterAngle;
55 ALfloat mConeOuterGain, mConeOuterGainHF;
56 ALfloat mRolloffFactor, mRoomRolloffFactor;
57 ALfloat mDopplerFactor;
58 ALfloat mAirAbsorptionFactor;
59 ALfloat mRadius;
60 ALfloat mStereoAngles[2];
61 Spatialize mSpatialize;
62 ALsizei mResampler;
63 bool mLooping : 1;
64 bool mRelative : 1;
65 bool mDryGainHFAuto : 1;
66 bool mWetGainAuto : 1;
67 bool mWetGainHFAuto : 1;
69 ALuint mDirectFilter;
70 SendPropMap mEffectSlots;
72 ALuint mPriority;
74 void resetProperties();
75 void applyProperties(bool looping, ALuint offset) const;
77 ALint refillBufferStream();
79 void setFilterParams(ALuint &filterid, const FilterParams &params);
81 public:
82 SourceImpl(ContextImpl *context);
83 ~SourceImpl();
85 ALuint getId() const { return mId; }
87 bool playUpdate(ALuint id);
88 bool playUpdate();
89 bool updateAsync();
91 void setGroup(SourceGroupImpl *group);
92 void unsetGroup();
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 */