Fix "no remove aqua speed" bug when player leaves the water
[ryzomcore.git] / nel / src / sound / driver / openal / sound_driver_al.h
blobf3cfa1152724044e0a655f41ef42faa3875b2398
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_SOUND_DRIVER_AL_H
21 #define NL_SOUND_DRIVER_AL_H
23 #include "nel/sound/driver/sound_driver.h"
25 namespace NLSOUND {
26 class CBufferAL;
27 class CListenerAL;
28 class CSourceAL;
29 class CEffectAL;
31 // alGenBuffers, alGenSources
32 //typedef ALAPI ALvoid ALAPIENTRY (*TGenFunctionAL) ( ALsizei, ALuint* );
33 typedef void (*TGenFunctionAL) ( ALsizei, ALuint* );
35 // alDeleteBuffers
36 typedef void (*TDeleteFunctionAL) ( ALsizei, const ALuint* );
38 // alIsBuffer, alIsSource
39 //typedef ALAPI ALboolean ALAPIENTRY (*TTestFunctionAL) ( ALuint );
40 typedef ALboolean (*TTestFunctionAL) ( ALuint );
42 #if !FINAL_VERSION
43 void alTestWarning(const char *src);
44 #else
45 #define alTestWarning(__src)
46 #endif
48 #ifdef NL_DEBUG
49 void alTestError();
50 #else
51 #define alTestError() alTestWarning("alTestError")
52 #endif
54 /**
55 * OpenAL sound driver
57 * The caller of the create methods is responsible for the deletion of the created objects
58 * These objects must be deleted before deleting the ISoundDriver instance.
62 * \author Olivier Cado
63 * \author Nevrax France
64 * \date 2001
66 class CSoundDriverAL : public ISoundDriver, public NLMISC::CManualSingleton<CSoundDriverAL>
68 private:
69 // outside pointers
70 /// The string mapper provided by client code.
71 IStringMapperProvider *_StringMapper;
73 // openal pointers
74 // OpenAL device
75 ALCdevice *_AlDevice;
76 // OpenAL context
77 ALCcontext *_AlContext;
79 // system vars
80 // Allocated buffers
81 std::vector<ALuint> _Buffers;
82 // Allocated sources
83 std::set<CSourceAL *> _Sources;
84 // Allocated effects
85 std::set<CEffectAL *> _Effects;
86 // Number of exported buffers (including any deleted buffers)
87 uint _NbExpBuffers;
88 // Number of exported sources (including any deleted sources)
89 uint _NbExpSources;
91 // user vars
92 // Rolloff factor (not in the listener in OpenAL, but relative to the sources)
93 float _RolloffFactor; // ***todo*** move
94 /// Driver options
95 TSoundOptions _Options;
96 public:
98 /// Constructor
99 CSoundDriverAL(ISoundDriver::IStringMapperProvider *stringMapper);
100 /// Destructor
101 virtual ~CSoundDriverAL();
103 inline ALCdevice *getAlDevice() { return _AlDevice; }
104 inline ALCcontext *getAlContext() { return _AlContext; }
105 inline float getRolloffFactor() { return _RolloffFactor; }
107 /// Return a list of available devices for the user. The value at index 0 is empty, and is used for automatic device selection.
108 virtual void getDevices(std::vector<std::string> &devices);
109 /// Initialize the driver with a user selected device. If device.empty(), the default or most appropriate device is used.
110 virtual void initDevice(const std::string &device, TSoundOptions options);
112 /// Return options that are enabled (including those that cannot be disabled on this driver).
113 virtual TSoundOptions getOptions();
114 /// Return if an option is enabled (including those that cannot be disabled on this driver).
115 virtual bool getOption(TSoundOptions option);
117 /// Create a sound buffer
118 virtual IBuffer *createBuffer();
119 /// Create the listener instance
120 virtual IListener *createListener();
121 /// Create a source
122 virtual ISource *createSource();
123 /// Create a reverb effect
124 virtual IReverbEffect *createReverbEffect();
125 /// Return the maximum number of sources that can created
126 virtual uint countMaxSources();
127 /// Return the maximum number of effects that can be created
128 virtual uint countMaxEffects();
130 virtual void startBench();
131 virtual void endBench();
132 virtual void displayBench(NLMISC::CLog *log);
135 /// Change the rolloff factor and apply to all sources
136 void applyRolloffFactor(float f);
138 /// Commit all the changes made to 3D settings of listener and sources
139 virtual void commit3DChanges();
141 /// Write information about the driver to the output stream.
142 virtual void writeProfile(std::string& out);
144 /// Remove a buffer
145 void removeBuffer(CBufferAL *buffer);
146 /// Remove a source
147 void removeSource(CSourceAL *source);
148 /// Remove an effect
149 void removeEffect(CEffectAL *effect);
151 /// Get audio/container extensions that are supported natively by the driver implementation.
152 virtual void getMusicExtensions(std::vector<std::string> & /* extensions */) const { }
153 /// Return if a music extension is supported by the driver's music channel.
154 virtual bool isMusicExtensionSupported(const std::string & /* extension */) const { return false; }
156 protected:
158 /// Allocate nb new buffers or sources
159 void allocateNewItems( TGenFunctionAL algenfunc, TTestFunctionAL altestfunc,
160 std::vector<ALuint>& names, uint index, uint nb );
162 /// Generate nb buffers
163 void generateItems( TGenFunctionAL algenfunc, TTestFunctionAL altestfunc, uint nb, ALuint *array );
165 /// Remove names of deleted items and return the number of valid items
166 uint compactAliveNames( std::vector<ALuint>& names, TTestFunctionAL testfunc );
168 /// Create a sound buffer or a sound source
169 ALuint createItem( TGenFunctionAL algenfunc, TTestFunctionAL altestfunc,
170 std::vector<ALuint>& names, uint& index, uint allocrate );
172 /// Delete a buffer or a source
173 bool deleteItem( ALuint name, TDeleteFunctionAL aldeletefunc, std::vector<ALuint>& names );
177 } // NLSOUND
180 #endif // NL_SOUND_DRIVER_AL_H
182 /* End of sound_driver_al.h */