1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2012 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
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"
31 // alGenBuffers, alGenSources
32 //typedef ALAPI ALvoid ALAPIENTRY (*TGenFunctionAL) ( ALsizei, ALuint* );
33 typedef void (*TGenFunctionAL
) ( ALsizei
, ALuint
* );
36 typedef void (*TDeleteFunctionAL
) ( ALsizei
, const ALuint
* );
38 // alIsBuffer, alIsSource
39 //typedef ALAPI ALboolean ALAPIENTRY (*TTestFunctionAL) ( ALuint );
40 typedef ALboolean (*TTestFunctionAL
) ( ALuint
);
43 void alTestWarning(const char *src
);
45 #define alTestWarning(__src)
51 #define alTestError() alTestWarning("alTestError")
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
66 class CSoundDriverAL
: public ISoundDriver
, public NLMISC::CManualSingleton
<CSoundDriverAL
>
70 /// The string mapper provided by client code.
71 IStringMapperProvider
*_StringMapper
;
77 ALCcontext
*_AlContext
;
81 std::vector
<ALuint
> _Buffers
;
83 std::set
<CSourceAL
*> _Sources
;
85 std::set
<CEffectAL
*> _Effects
;
86 // Number of exported buffers (including any deleted buffers)
88 // Number of exported sources (including any deleted sources)
92 // Rolloff factor (not in the listener in OpenAL, but relative to the sources)
93 float _RolloffFactor
; // ***todo*** move
95 TSoundOptions _Options
;
99 CSoundDriverAL(ISoundDriver::IStringMapperProvider
*stringMapper
);
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();
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
);
145 void removeBuffer(CBufferAL
*buffer
);
147 void removeSource(CSourceAL
*source
);
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; }
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
);
180 #endif // NL_SOUND_DRIVER_AL_H
182 /* End of sound_driver_al.h */