![[]](/images/special/trans.gif)
LibN2L-4 Library Code ReferenceClassesCompounds Files Members Method Index Full Reference cAudioMixer.hGo to the documentation of this file.00001 /************************************************************************ 00002 Nova-2 Library (libN2L, or simply n2l) Game development C++ Library 00003 Copyright (C) 2003 Aaron Cameron 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 00019 A copy of the GNU Lesser General Public License has been provided with 00020 this library in the file 'COPYING'. 00021 00022 Contact information for the author of this library has been provided 00023 with this library in the file 'AUTHOR'. 00024 ************************************************************************/ 00025 #ifndef _n2l4_cAudioMixer_H 00026 #define _n2l4_cAudioMixer_H 00027 00028 #include "n2l/n2l.h" 00029 00030 #include "audio/types.h" 00031 00032 #include "SDL_mixer.h" 00033 00034 #include <map> 00035 00036 /******************************************************************************/ 00037 namespace n2l 00038 { 00039 00040 class cAudioSource; 00041 00045 class cAudioMixer 00046 { 00047 private: 00048 class cSubSysHolder 00049 { 00050 public: 00051 cSubSysHolder(); 00052 ~cSubSysHolder(); 00053 }; 00054 00055 public: 00056 typedef tUint tFrequency; 00057 typedef tSint tMixChannels; 00058 00059 typedef enum { 00060 Format_U8 = AUDIO_U8, 00061 Format_S8 = AUDIO_S8, 00062 Format_U16LSB = AUDIO_U16LSB, 00063 Format_S16LSB = AUDIO_S16LSB, 00064 Format_U16MSB = AUDIO_U16MSB, 00065 Format_S16MSB = AUDIO_S16MSB, 00066 Format_U16SYS = AUDIO_U16SYS, 00067 Format_S16SYS = AUDIO_S16SYS, 00068 Format_Unknown 00069 } tFormat; 00070 00071 typedef enum { 00072 Fading_None = MIX_NO_FADING, 00073 Fading_Out = MIX_FADING_OUT, 00074 Fading_In = MIX_FADING_IN 00075 } tFadeStatus; 00076 00077 typedef enum { 00078 Channels_Mono = 1, 00079 Channels_Stereo = 2 00080 } tSoundChannels; 00081 00082 typedef enum { 00083 SoundDriver_Auto, 00084 SoundDriver_OpenBSD, 00085 SoundDriver_DSP, 00086 SoundDriver_ALSA, 00087 SoundDriver_Audio, 00088 SoundDriver_AL, 00089 SoundDriver_ARTSC, 00090 SoundDriver_ESD, 00091 SoundDriver_NAS, 00092 SoundDriver_DMA, 00093 SoundDriver_DSound, 00094 SoundDriver_WaveOut, 00095 SoundDriver_BeOS, 00096 SoundDriver_MacOSSoundManager, 00097 SoundDriver_AIX, 00098 SoundDriver_AHI, 00099 SoundDriver_Disk, 00100 00101 SoundDriver_Null, // Pseudo driver. Just skips initialization 00102 00103 SoundDriver_NumSoundDrivers 00104 } tSoundDriver; 00105 00106 static const tFrequency DefaultFrequency; 00107 static const tFormat DefaultFormat; 00108 static const tSoundChannels DefaultSoundChannels; 00109 static const tSint DefaultChunkSize; 00110 static const tMixChannels DefaultMixingChannels; 00111 00112 static const tMixChannels MusicChannel; 00113 00114 static cAutoPtr<cSubSysHolder> smSubSysHolder; 00115 00116 static void setDriver( const tSoundDriver &iDriver ); 00117 static const tSoundDriver getDriver(); 00118 00119 static void openAudio( const tFrequency iFrequency = DefaultFrequency, 00120 const tFormat iFormat = DefaultFormat, 00121 const tSoundChannels iSoundChannels = DefaultSoundChannels, 00122 const tSint iChunkSize = DefaultChunkSize ); 00123 00130 static void closeAudio(); 00131 00132 static const tFrequency frequency(); 00133 static const tFormat format(); 00134 00138 static const tUint sampleSize(); 00139 static const tString &formatAsString(); 00140 static const tSoundChannels soundChannels(); 00141 00142 static void allocateMixingChannels( const tMixChannels iNum ); 00143 00149 static const tUint numChannelsPlaying(); 00150 00157 static const tUint numFreeChannels(); 00158 00166 static const tUint numChannels(); 00167 00168 static void musicVolume( const tSint iVolume ); 00172 static void musicVolume( const tFloat iVolume ); 00173 static void fadeOutMusic( const tUint iMilliseconds ); 00174 static const tFadeStatus musicFadeStatus(); 00175 00176 static void channelVolume( const tAudioChannel iChannel, 00177 const tFloat &iVolume ); 00178 00179 inline static const tBool inited() { return smInited; } 00180 00181 static const tString &driverName( const tSoundDriver &iDriver ); 00182 static const tString &driverName(); 00183 00190 static void registerSource( cAudioSource *ioSource ); 00191 static void unregisterSource( cAudioSource *ioSource ); 00192 00193 private: 00194 typedef std::map<tAudioChannel, cAudioSource*> tChannelSourceMap; 00195 static tBool smInited; 00196 static tMixChannels smNumMixingChannels; 00197 static tSoundDriver smDriver; 00198 00199 static tChannelSourceMap mChannelSourceMap; 00200 00201 static void boundCheckFrequency( const tFrequency iFrequency ); 00202 static void boundCheckFormat( const tFormat iFormat ); 00203 static void boundCheckSoundChannels( const tSoundChannels iChannels ); 00204 static void boundCheckChunkSize( const tSint iChunkSize ); 00205 00206 static void boundCheckSoundDriver( const tSoundDriver &iDriver ); 00207 00208 static const tString &envStringForDriver( const tSoundDriver &iDriver ); 00209 00210 static void mixerSampleFinishedCallback( int iChannel ); 00211 00212 }; // class 00213 00214 } // namespace 00215 00216 #endif |