Use boolean bit-fields in place of flags
[alure.git] / src / source.h
blobf072f983a425b9f14638dfa3edcfe09355d5e494
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 ALContext;
16 class ALBuffer;
17 class ALBufferStream;
18 class ALAuxiliaryEffectSlot;
19 class ALSourceGroup;
21 struct SendProps {
22 ALAuxiliaryEffectSlot *mSlot;
23 ALuint mFilter;
25 SendProps(ALAuxiliaryEffectSlot *slot) : mSlot(slot), mFilter(AL_FILTER_NULL)
26 { }
27 SendProps(ALuint filter) : mSlot(0), mFilter(filter)
28 { }
29 SendProps(ALAuxiliaryEffectSlot *slot, ALuint filter) : mSlot(slot), mFilter(filter)
30 { }
32 typedef std::unordered_map<ALuint,SendProps> SendPropMap;
34 class ALSource {
35 ALContext *const mContext;
36 ALuint mId;
38 ALBuffer *mBuffer;
39 UniquePtr<ALBufferStream> mStream;
41 ALSourceGroup *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 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 ALSource(ALContext *context);
83 ~ALSource();
85 ALuint getId() const { return mId; }
87 void updateNoCtxCheck();
88 bool updateAsync();
90 void setGroup(ALSourceGroup *group);
91 void unsetGroup();
93 void groupUpdate();
94 void groupPropUpdate(ALfloat gain, ALfloat pitch);
96 void checkPaused();
97 void unsetPaused() { mPaused = false; }
98 void makeStopped();
100 void play(Buffer buffer);
101 void play(SharedPtr<Decoder> decoder, ALuint updatelen, ALuint queuesize);
102 void stop();
103 void pause();
104 void resume();
106 bool isPlaying() const;
107 bool isPaused() const;
109 void setPriority(ALuint priority);
110 ALuint getPriority() const { return mPriority; }
112 void setOffset(uint64_t offset);
113 uint64_t getOffset(uint64_t *latency=0) 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 setPosition(ALfloat x, ALfloat y, ALfloat z);
133 void setPosition(const ALfloat *pos);
134 Vector3 getPosition() const { return mPosition; }
136 void setVelocity(ALfloat x, ALfloat y, ALfloat z);
137 void setVelocity(const ALfloat *vel);
138 Vector3 getVelocity() const { return mVelocity; }
140 void setDirection(ALfloat x, ALfloat y, ALfloat z);
141 void setDirection(const ALfloat *dir);
142 Vector3 getDirection() const { return mDirection; }
144 void setOrientation(ALfloat x1, ALfloat y1, ALfloat z1, ALfloat x2, ALfloat y2, ALfloat z2);
145 void setOrientation(const ALfloat *at, const ALfloat *up);
146 void setOrientation(const ALfloat *ori);
147 std::pair<Vector3,Vector3> getOrientation() const
148 { return {mOrientation[0], mOrientation[1]}; }
150 void setConeAngles(ALfloat inner, ALfloat outer);
151 std::pair<ALfloat,ALfloat> getConeAngles() const
152 { return {mConeInnerAngle, mConeOuterAngle}; }
154 void setOuterConeGains(ALfloat gain, ALfloat gainhf=1.0f);
155 std::pair<ALfloat,ALfloat> getOuterConeGains() const
156 { return {mConeOuterGain, mConeOuterGainHF}; }
158 void setRolloffFactors(ALfloat factor, ALfloat roomfactor=0.0f);
159 std::pair<ALfloat,ALfloat> getRolloffFactors() const
160 { return {mRolloffFactor, mRoomRolloffFactor}; }
162 void setDopplerFactor(ALfloat factor);
163 ALfloat getDopplerFactor() const { return mDopplerFactor; }
165 void setRelative(bool relative);
166 bool getRelative() const { return mRelative; }
168 void setRadius(ALfloat radius);
169 ALfloat getRadius() const { return mRadius; }
171 void setStereoAngles(ALfloat leftAngle, ALfloat rightAngle);
172 std::pair<ALfloat,ALfloat> getStereoAngles() const
173 { return std::make_pair(mStereoAngles[0], mStereoAngles[1]); }
175 void setAirAbsorptionFactor(ALfloat factor);
176 ALfloat getAirAbsorptionFactor() const { return mAirAbsorptionFactor; }
178 void setGainAuto(bool directhf, bool send, bool sendhf);
179 std::tuple<bool,bool,bool> getGainAuto() const
180 { return std::make_tuple(mDryGainHFAuto, mWetGainAuto, mWetGainHFAuto); }
182 void setDirectFilter(const FilterParams &filter);
183 void setSendFilter(ALuint send, const FilterParams &filter);
184 void setAuxiliarySend(AuxiliaryEffectSlot slot, ALuint send);
185 void setAuxiliarySendFilter(AuxiliaryEffectSlot slot, ALuint send, const FilterParams &filter);
187 void update();
189 void release();
192 } // namespace alure
194 #endif /* SOURCE_H */