src/engine/eSound.h File Reference

#include "rSDL.h"
#include "defs.h"
#include "tString.h"
#include "tLinkedList.h"

Include dependency graph for eSound.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  eAudioPos
class  eWavData
class  eSoundPlayer

Functions

void se_SoundInit ()
void se_SoundExit ()
void se_SoundLock ()
void se_SoundUnlock ()
void se_SoundPause (bool p)
void se_SoundMenu ()


Function Documentation

void se_SoundExit (  ) 

Definition at line 257 of file eSound.cpp.

References con, NULL, se_SoundLock(), se_SoundPause(), se_SoundUnlock(), sound_is_there, eWavData::UnloadAll(), and uses_sdl_mixer.

Referenced by se_SoundInit(), and se_SoundMenu().

00257                    {
00258 #ifndef DEDICATED
00259     se_SoundLock();
00260 
00261     eWavData::UnloadAll();
00262     se_SoundPause(true);
00263 
00264     se_SoundUnlock();
00265 
00266     if (sound_is_there){
00267 #ifdef DEBUG
00268         con << tOutput("$sound_disabling");
00269 #endif
00270         //              se_SoundPause(false);
00271         //    for(int i=wavs.Len()-1;i>=0;i--)
00272         //wavs(i)->Exit();
00273 
00274 #ifdef HAVE_LIBSDL_MIXER
00275         if ( music )
00276         {
00277             if( Mix_PlayingMusic() )
00278             {
00279                 Mix_FadeOutMusic(100);
00280                 SDL_Delay(100);
00281             }
00282             Mix_FreeMusic( music );
00283             music = NULL;
00284         }
00285 
00286         se_SoundPause(true);
00287 
00288         if ( uses_sdl_mixer )
00289             Mix_CloseAudio();
00290         else
00291 #endif
00292             SDL_CloseAudio();
00293 
00294 #ifdef DEBUG
00295         con << tOutput("$sound_disabling_done");
00296 #endif
00297     }
00298     sound_is_there=false;
00299 #endif
00300 }

Here is the call graph for this function:

Here is the caller graph for this function:

void se_SoundInit (  ) 

Definition at line 139 of file eSound.cpp.

References audio, buffer_shift, con, tDirectories::Data(), fill_audio(), tPath::GetReadPath(), NULL, se_SoundExit(), tOutput::SetTemplateParameter(), SOUND_HIGH, sound_is_there, SOUND_LOW, SOUND_MED, SOUND_OFF, sound_quality, st_FirstUse, st_SaveConfig(), and uses_sdl_mixer.

Referenced by se_SoundMenu().

00140 {
00141 #ifndef DEDICATED
00142     // save configuration file with sound disabled on first use so we don't try again
00143     bool needSave = false;
00144     static bool firstRun = true;
00145     if ( st_FirstUse )
00146     {
00147         needSave = true;
00148         int sound_quality_back = sound_quality;
00149         sound_quality = SOUND_OFF;
00150         st_SaveConfig();
00151         if ( firstRun )
00152             con << tOutput("$sound_firstinit");
00153         sound_quality=sound_quality_back;
00154     }
00155 
00156     if ( sound_quality != SOUND_OFF )
00157     {
00158 #ifdef DEFAULT_SDL_AUDIODRIVER
00159         static bool init = se_SoundInitPrepare();
00160         if ( !init )
00161             return;
00162 #endif
00163         if ( firstRun && !SDL_WasInit( SDL_INIT_AUDIO ) )
00164             return;
00165         firstRun = false;
00166     }
00167 
00168     if (!sound_is_there && sound_quality!=SOUND_OFF)
00169     {
00170         SDL_AudioSpec desired;
00171 
00172         switch (sound_quality)
00173         {
00174         case SOUND_LOW:
00175             desired.freq=11025; break;
00176         case SOUND_MED:
00177             desired.freq=22050; break;
00178         case SOUND_HIGH:
00179             desired.freq=44100; break;
00180         default:
00181             desired.freq=22050;
00182         }
00183 
00184         desired.format=AUDIO_S16SYS;
00185         desired.samples=128;
00186         while (desired.samples <= desired.freq >> (6-buffer_shift))
00187             desired.samples <<= 1;
00188         desired.channels = 2;
00189         desired.callback = fill_audio;
00190         desired.userdata = NULL;
00191 
00192 #ifdef HAVE_LIBSDL_MIXER
00193         uses_sdl_mixer=true;
00194 
00195         // init using SDL_Mixer
00196         sound_is_there=(Mix_OpenAudio(desired.freq, desired.format, desired.channels, desired.samples)>=0);
00197 
00198         if ( sound_is_there )
00199         {
00200             // query actual sound info
00201             audio = desired;
00202             int channels;
00203             Mix_QuerySpec( &audio.freq, &audio.format, &channels );
00204             audio.channels = channels;
00205 
00206             // register callback
00207             Mix_SetPostMix( &fill_audio, NULL );
00208 
00209             const tPath& vpath = tDirectories::Data();
00210             tString musFile = vpath.GetReadPath( "music/fire.xm" );
00211 
00212             music = Mix_LoadMUS( musFile );
00213 
00214             if ( music )
00215                 Mix_FadeInMusic( music, -1, 2000 );
00216 
00217         }
00218 #else
00219         // just use SDL to init sound
00220         uses_sdl_mixer=false;
00221         sound_is_there=(SDL_OpenAudio(&desired,&audio)>=0);
00222 #endif
00223         if (sound_is_there && (audio.format!=AUDIO_S16SYS || audio.channels!=2))
00224         {
00225             uses_sdl_mixer=false;
00226             se_SoundExit();
00227             // force emulation of 16 bit stereo; sadly, this cannot use SDL_Mixer :-(
00228             audio.format=AUDIO_S16SYS;
00229             audio.channels=2;
00230             sound_is_there=(SDL_OpenAudio(&audio,NULL)>=0);
00231             con << tOutput("$sound_error_no16bit");
00232         }
00233         if (!sound_is_there)
00234             con << tOutput("$sound_error_initfailed");
00235         else
00236         {
00237             //for(int i=wavs.Len()-1;i>=0;i--)
00238             //wavs(i)->Init();
00239 #ifdef DEBUG
00240             tOutput o;
00241             o.SetTemplateParameter(1,audio.freq);
00242             o.SetTemplateParameter(2,audio.samples);
00243             o << "$sound_inited";
00244             con << o;
00245 #endif
00246         }
00247     }
00248 
00249     // save sound settings, they appear to work
00250     if ( needSave )
00251     {
00252         st_SaveConfig();
00253     }
00254 #endif
00255 }

Here is the call graph for this function:

Here is the caller graph for this function:

void se_SoundLock (  ) 

Definition at line 306 of file eSound.cpp.

Referenced by eSoundPlayer::MakeGlobal(), se_SoundExit(), and eWavData::Unload().

00306                    {
00307 #ifndef DEDICATED
00308     if (!locks)
00309         SDL_LockAudio();
00310     locks++;
00311 #endif
00312 }

Here is the caller graph for this function:

void se_SoundMenu (  ) 

Definition at line 856 of file eSound.cpp.

00856                    {
00857     //  se_SoundPause(true);
00858     //  se_SoundLock();
00859     int oldsettings=sound_quality;
00860     int oldshift=buffer_shift;
00861     Sound_menu.Enter();
00862     if (oldsettings!=sound_quality || oldshift!=buffer_shift){
00863         se_SoundExit();
00864         se_SoundInit();
00865     }
00866     //  se_SoundUnlock();
00867     //  se_SoundPause(false);
00868 }

void se_SoundPause ( bool  p  ) 

Definition at line 322 of file eSound.cpp.

Referenced by se_SoundExit().

00322                           {
00323 #ifndef DEDICATED
00324     SDL_PauseAudio(p);
00325 #endif
00326 }

Here is the caller graph for this function:

void se_SoundUnlock (  ) 

Definition at line 314 of file eSound.cpp.

Referenced by eSoundPlayer::MakeGlobal(), se_SoundExit(), and eWavData::Unload().

00314                      {
00315 #ifndef DEDICATED
00316     locks--;
00317     if (!locks)
00318         SDL_UnlockAudio();
00319 #endif
00320 }

Here is the caller graph for this function:


Generated on Sat Mar 15 22:58:48 2008 for Armagetron Advanced by  doxygen 1.5.4