Fix "no remove aqua speed" bug when player leaves the water
[ryzomcore.git] / nel / src / sound / driver / openal / source_al.h
blob526c44de22b9d05c15514b96ffe13c74102dfdf2
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2012 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef NL_SOURCE_AL_H
21 #define NL_SOURCE_AL_H
23 #include "nel/sound/driver/source.h"
25 namespace NLSOUND {
26 class IBuffer;
27 class CBufferAL;
28 class CSoundDriverAL;
29 class CEffectAL;
31 /**
32 * OpenAL sound source
34 * Note: the creation/deletion of sources and the setting of their rolloff factor
35 * are done in CSoundDriverAL.
37 * The EAX extensions are not available on all sound cards, and currently not at
38 * all on Linux.
40 * For arguments as 3D vectors, use the NeL vector coordinate system
41 * (not OpenAL/OpenGL's one).
43 * \author Olivier Cado
44 * \author Nevrax France
45 * \date 2001
47 class CSourceAL : public ISource
49 private:
50 /// Sound driver
51 CSoundDriverAL *_SoundDriver;
53 /// Assigned buffer object
54 CBufferAL *_Buffer;
55 std::queue<CBufferAL *> _QueuedBuffers;
57 /// AL Handles
58 ALuint _Source;
59 ALuint _DirectFilter, _EffectFilter;
61 /// Playing status
62 bool _IsPlaying;
63 bool _IsPaused;
64 NLMISC::TTime _StartTime;
66 bool _IsStreaming;
67 bool _RelativeMode;
69 NLMISC::CVector _Pos;
70 float _Gain;
71 double _Alpha;
72 /// Minimum distance of sound at max volume.
73 float _MinDistance;
74 /// Maximum distance of sound.
75 float _MaxDistance;
77 /// Send paths
78 CEffectAL *_Effect;
79 bool _Direct;
80 float _DirectGain, _EffectGain;
82 /// Send filters
83 TFilter _DirectFilterType, _EffectFilterType;
84 bool _DirectFilterEnabled, _EffectFilterEnabled;
85 float _DirectFilterPassGain, _EffectFilterPassGain;
87 public:
88 /// Constructor
89 CSourceAL(CSoundDriverAL *soundDriver);
90 /// Destructor
91 virtual ~CSourceAL();
93 /// Release called by the driver to release internal AL handles.
94 void release();
96 /// Return the OpenAL source name
97 inline ALuint getSource() const { return _Source; }
99 /// (Internal) Set the effect send for this source, NULL to disable.
100 void setEffect(CEffectAL *effect);
101 /// (Internal) Setup the direct send filter.
102 void setupDirectFilter();
103 /// (Internal) Setup the effect send filter.
104 void setupEffectFilter();
105 /// (Internal) Update the manual rolloff, only called when using manual rolloff.
106 void updateManualRolloff();
108 /// \name Initialization
109 //@{
110 /// Enable or disable streaming mode. Source must be stopped to call this.
111 virtual void setStreaming(bool streaming);
112 /** Set the buffer that will be played (no streaming)
113 * If the buffer is stereo, the source mode becomes stereo and the source relative mode is on,
114 * otherwise the source is considered as a 3D source. Use submitStreamingBuffer for streaming.
116 virtual void setStaticBuffer(IBuffer *buffer);
117 /// Return the buffer, or NULL if streaming is used. Not available for streaming.
118 virtual IBuffer *getStaticBuffer();
119 /// Add a buffer to the streaming queue. A buffer of 100ms length is optimal for streaming.
120 /// Should be called by a thread which checks countStreamingBuffers every 100ms.
121 virtual void submitStreamingBuffer(IBuffer *buffer);
122 /// Return the amount of buffers in the queue (playing and waiting). 3 buffers is optimal.
123 virtual uint countStreamingBuffers() const;
124 //@}
126 /// \name Playback control
127 //@{
128 /// Set looping on/off for future playbacks (default: off), not available for streaming
129 virtual void setLooping(bool l);
130 /// Return the looping state
131 virtual bool getLooping() const;
133 /** Play the static buffer (or stream in and play).
134 * This method can return false if the sample for this sound is unloaded.
136 virtual bool play();
137 /// Stop playing
138 virtual void stop();
139 /// Pause. Call play() to resume.
140 virtual void pause();
141 /// Return true if play() or pause(), false if stop().
142 virtual bool isPlaying() const;
143 /// Return true if playing is finished or stop() has been called.
144 virtual bool isStopped() const;
145 /// Return true if the playing source is paused
146 virtual bool isPaused() const;
147 /// Returns the number of milliseconds the source has been playing
148 virtual uint32 getTime();
149 //@}
151 /// \name Source properties
152 //@{
153 /** Set the position vector (default: (0,0,0)).
154 * 3D mode -> 3D position
155 * st mode -> x is the pan value (from left (-1) to right (1)), set y and z to 0
157 virtual void setPos(const NLMISC::CVector& pos, bool deffered = true);
158 /** Get the position vector.
159 * See setPos() for details.
161 virtual const NLMISC::CVector &getPos() const;
162 /// Set the velocity vector (3D mode only, ignored in stereo mode) (default: (0,0,0))
163 virtual void setVelocity(const NLMISC::CVector& vel, bool deferred = true);
164 /// Get the velocity vector
165 virtual void getVelocity(NLMISC::CVector& vel) const;
166 /// Set the direction vector (3D mode only, ignored in stereo mode) (default: (0,0,0) as non-directional)
167 virtual void setDirection(const NLMISC::CVector& dir);
168 /// Get the direction vector
169 virtual void getDirection(NLMISC::CVector& dir) const;
170 /** Set the gain (volume value inside [0 , 1]). (default: 1)
171 * 0.0 -> silence
172 * 0.5 -> -6dB
173 * 1.0 -> no attenuation
174 * values > 1 (amplification) not supported by most drivers
176 virtual void setGain(float gain);
177 /// Get the gain
178 virtual float getGain() const;
179 /** Shift the frequency. 1.0f equals identity, each reduction of 50% equals a pitch shift
180 * of one octave. 0 is not a legal value.
182 virtual void setPitch(float pitch);
183 /// Get the pitch
184 virtual float getPitch() const;
185 /// Set the source relative mode. If true, positions are interpreted relative to the listener position
186 virtual void setSourceRelativeMode(bool mode);
187 /// Get the source relative mode
188 virtual bool getSourceRelativeMode() const;
189 /// Set the min and max distances (default: 1, MAX_FLOAT) (3D mode only)
190 virtual void setMinMaxDistances(float mindist, float maxdist, bool deferred = true);
191 /// Get the min and max distances
192 virtual void getMinMaxDistances(float& mindist, float& maxdist) const;
193 /// Set the cone angles (in radian) and gain (in [0 , 1]) (default: 2PI, 2PI, 0)
194 virtual void setCone(float innerAngle, float outerAngle, float outerGain);
195 /// Get the cone angles (in radian)
196 virtual void getCone(float& innerAngle, float& outerAngle, float& outerGain) const;
197 /** Set the alpha value for the volume-distance curve
199 * Useful only with OptionManualRolloff. value from -1 to 1 (default 0)
201 * alpha.0: the volume will decrease linearly between 0dB and -100 dB
202 * alpha = 1.0: the volume will decrease linearly between 1.0 and 0.0 (linear scale)
203 * alpha = -1.0: the volume will decrease inversely with the distance (1/dist). This
204 * is the default used by DirectSound/OpenAL
206 * For any other value of alpha, an interpolation is be done between the two
207 * adjacent curves. For example, if alpha equals 0.5, the volume will be halfway between
208 * the linear dB curve and the linear amplitude curve.
210 virtual void setAlpha(double a);
211 //@}
213 /// \name Direct output
214 //@{
215 /// Enable or disable direct output [true/false], default: true
216 virtual void setDirect(bool enable = true);
217 /// Return if the direct output is enabled
218 virtual bool getDirect() const;
219 /// Set the gain for the direct path
220 virtual void setDirectGain(float gain);
221 /// Get the gain for the direct path
222 virtual float getDirectGain() const;
224 /// Enable or disable the filter for the direct channel
225 virtual void enableDirectFilter(bool enable = true);
226 /// Check if the filter on the direct channel is enabled
227 virtual bool isDirectFilterEnabled() const;
228 /// Set the filter parameters for the direct channel
229 virtual void setDirectFilter(TFilter filter, float lowFrequency, float highFrequency, float passGain);
230 /// Get the filter parameters for the direct channel
231 virtual void getDirectFilter(TFilter &filterType, float &lowFrequency, float &highFrequency, float &passGain) const;
232 /// Set the direct filter gain
233 virtual void setDirectFilterPassGain(float passGain);
234 /// Get the direct filter gain
235 virtual float getDirectFilterPassGain() const;
236 //@}
238 /// \name Effect output
239 //@{
240 /// Set the effect send for this source, NULL to disable. [IEffect], default: NULL
241 virtual void setEffect(IReverbEffect *reverbEffect);
242 /// Get the effect send for this source
243 virtual IEffect *getEffect() const;
244 /// Set the gain for the effect path
245 virtual void setEffectGain(float gain);
246 /// Get the gain for the effect path
247 virtual float getEffectGain() const;
249 /// Enable or disable the filter for the effect channel
250 virtual void enableEffectFilter(bool enable = true);
251 /// Check if the filter on the effect channel is enabled
252 virtual bool isEffectFilterEnabled() const;
253 /// Set the filter parameters for the effect channel
254 virtual void setEffectFilter(TFilter filter, float lowFrequency, float highFrequency, float passGain);
255 /// Get the filter parameters for the effect channel
256 virtual void getEffectFilter(TFilter &filterType, float &lowFrequency, float &highFrequency, float &passGain) const;
257 /// Set the effect filter gain
258 virtual void setEffectFilterPassGain(float passGain);
259 /// Get the effect filter gain
260 virtual float getEffectFilterPassGain() const;
261 //@}
265 } // NLSOUND
267 #endif // NL_SOURCE_AL_H
269 /* End of source_al.h */