# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

sound_driver_al.h

Go to the documentation of this file.
00001 
00007 /* Copyright, 2001 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #ifndef NL_SOUND_DRIVER_AL_H
00027 #define NL_SOUND_DRIVER_AL_H
00028 
00029 #include "nel/misc/types_nl.h"
00030 #include "sound/driver/sound_driver.h"
00031 #include "sound/driver/openal/source_al.h"
00032 #include "sound/driver/openal/buffer_al.h"
00033 #include <AL/al.h>
00034 #ifdef NL_OS_WINDOWS
00035 #include <objbase.h> // needed before eax.h
00036 #define EAX_AVAILABLE
00037 #endif
00038 
00039 #ifdef EAX_AVAILABLE
00040 #include <eax.h> // no EAX on Linux !
00041 #endif
00042 
00043 #include <vector>
00044 
00045 
00046 namespace NLSOUND {
00047 
00048 
00049 // alGenBuffers, alGenSources
00050 //typedef ALAPI ALvoid ALAPIENTRY (*TGenFunctionAL) ( ALsizei, ALuint* );
00051 typedef ALvoid (*TGenFunctionAL) ( ALsizei, ALuint* );
00052 
00053 // alIsBuffer, alIsSource
00054 //typedef ALAPI ALboolean ALAPIENTRY (*TTestFunctionAL) ( ALuint );
00055 typedef ALboolean (*TTestFunctionAL) ( ALuint );
00056 
00057 
00058 #ifdef EAX_AVAILABLE
00059 // EAXSet global function
00060 extern EAXSet   EAXSetProp;
00061 
00062 // EAXGet global function
00063 extern EAXGet   EAXGetProp;
00064 #endif
00065 
00066 
00067 #ifdef NL_DEBUG
00068 void TestALError();
00069 #else
00070 #define TestALError() 
00071 #endif
00072 
00073 
00074 
00087 class CSoundDriverAL : public ISoundDriver
00088 {
00089 public:
00090 
00092         CSoundDriverAL();
00093 
00095         static CSoundDriverAL   *instance() { return _Instance; }
00096 
00098         virtual bool                    init();
00099 
00101         virtual IBuffer                 *createBuffer();
00102 
00104         virtual IListener               *createListener();
00105 
00107         virtual uint                    countMaxSources()       { return 32; }
00108 
00110         virtual ISource                 *createSource();
00111 
00113         void                                    applyRolloffFactor( float f );
00114 
00116         virtual bool                    loadWavFile( IBuffer *destbuffer, const char *filename );
00117 
00119         virtual void                    commit3DChanges() {}
00120 
00122         virtual void                    writeProfile(std::ostream& out) {}
00123 
00124         // Does not create a sound loader
00125 
00126 public:
00127         
00129         virtual                                 ~CSoundDriverAL();
00130 
00131 protected:
00132 
00133         friend CBufferAL::~CBufferAL();
00134         friend CSourceAL::~CSourceAL();
00135 
00137         void                                    removeBuffer( IBuffer *buffer );
00138 
00140         void                                    removeSource( ISource *source );
00141 
00142 protected:
00143 
00145         void                                    allocateNewItems( TGenFunctionAL algenfunc, TTestFunctionAL altestfunc,
00146                                                                                           std::vector<ALuint>& names, uint index, uint nb );
00147 
00149         void                                    generateItems( TGenFunctionAL algenfunc, TTestFunctionAL altestfunc, uint nb, ALuint *array );
00150 
00152         uint                                    compactAliveNames( std::vector<ALuint>& names, TTestFunctionAL testfunc );
00153 
00155         ALuint                                  createItem( TGenFunctionAL algenfunc, TTestFunctionAL altestfunc,
00156                                                                                 std::vector<ALuint>& names, uint& index, uint allocrate );
00157 
00159         bool                                    deleteItem( ALuint name, TGenFunctionAL aldeletefunc, std::vector<ALuint>& names );
00160         
00161 private:
00162 
00163         // The instance of the singleton
00164         static CSoundDriverAL   *_Instance;
00165 
00166         // Allocated buffers
00167         std::vector<ALuint>             _Buffers;
00168 
00169         // Allocated sources
00170         std::vector<ALuint>             _Sources;
00171 
00172         // Number of exported buffers (including any deleted buffers)
00173         uint                                    _NbExpBuffers;
00174 
00175         // Number of exported sources (including any deleted buffers)
00176         uint                                    _NbExpSources;
00177 
00178         // Rolloff factor (not in the listener in OpenAL, but relative to the sources)
00179         float                                   _RolloffFactor;
00180 
00181 };
00182 
00183 
00184 } // NLSOUND
00185 
00186 
00187 #endif // NL_SOUND_DRIVER_AL_H
00188 
00189 /* End of sound_driver_al.h */