src/engine/eSound.cpp File Reference

#include "eSound.h"
#include "config.h"
#include "tMemManager.h"
#include "tDirectories.h"
#include "tRandom.h"
#include "tError.h"
#include <string>
#include "tConfiguration.h"
#include "uMenu.h"
#include "eCamera.h"
#include <iostream>
#include <stdlib.h>
#include "eGrid.h"
#include "tException.h"

Include dependency graph for eSound.cpp:

Go to the source code of this file.

Defines

#define SOUND_OFF   0
#define SOUND_LOW   1
#define SOUND_MED   2
#define SOUND_HIGH   3
#define SPEED_FRACTION   (1<<20)
#define VOL_SHIFT   16
#define VOL_FRACTION   (1<<VOL_SHIFT)
#define MAX_VAL   ((1<<16)-1)
#define MIN_VAL   -(1<<16)

Functions

void fill_audio (void *udata, Uint8 *stream, int len)
void se_SoundInit ()
void se_SoundExit ()
void se_SoundLock ()
void se_SoundUnlock ()
void se_SoundPause (bool p)
void se_SoundMenu ()

Variables

static SDL_AudioSpec audio
static bool sound_is_there = false
static bool uses_sdl_mixer = false
static int buffer_shift = 0
static tConfItem< int > bs ("SOUND_BUFFER_SHIFT", buffer_shift)
int sound_quality = SOUND_MED
static tConfItem< int > sq ("SOUND_QUALITY", sound_quality)
static int sound_sources = 10
static tConfItem< int > ss ("SOUND_SOURCES", sound_sources)
static REAL loudness_thresh = 0
static int real_sound_sources = 0
static tList< eSoundPlayerse_globalPlayers
static unsigned int locks
uMenu Sound_menu ("$sound_menu_text")
static uSelectEntry< int > a (sq_men,"$sound_menu_quality_off_text","$sound_menu_quality_off_help", SOUND_OFF)
static uSelectEntry< int > b (sq_men,"$sound_menu_quality_low_text","$sound_menu_quality_low_help", SOUND_LOW)
static uSelectEntry< int > c (sq_men,"$sound_menu_quality_medium_text","$sound_menu_quality_medium_help", SOUND_MED)
static uSelectEntry< int > d (sq_men,"$sound_menu_quality_high_text","$sound_menu_quality_high_help", SOUND_HIGH)
static uSelectEntry< int > ba (bm_men,"$sound_menu_buffer_vsmall_text","$sound_menu_buffer_vsmall_help",-2)
static uSelectEntry< int > bb (bm_men,"$sound_menu_buffer_small_text","$sound_menu_buffer_small_help",-1)
static uSelectEntry< int > bc (bm_men,"$sound_menu_buffer_med_text","$sound_menu_buffer_med_help", 0)
static uSelectEntry< int > bd (bm_men,"$sound_menu_buffer_high_text","$sound_menu_buffer_high_help", 1)
static uSelectEntry< int > be (bm_men,"$sound_menu_buffer_vhigh_text","$sound_menu_buffer_vhigh_help", 2)


Define Documentation

#define MAX_VAL   ((1<<16)-1)

Referenced by eWavData::Mix().

#define MIN_VAL   -(1<<16)

Referenced by eWavData::Mix().

#define SOUND_HIGH   3

Definition at line 66 of file eSound.cpp.

Referenced by eSoundMixer::Init(), and se_SoundInit().

#define SOUND_LOW   1

Definition at line 64 of file eSound.cpp.

Referenced by eSoundMixer::Init(), and se_SoundInit().

#define SOUND_MED   2

Definition at line 65 of file eSound.cpp.

Referenced by eSoundMixer::Init(), and se_SoundInit().

#define SOUND_OFF   0

Definition at line 63 of file eSound.cpp.

Referenced by eSoundMixer::Init(), and se_SoundInit().

#define SPEED_FRACTION   (1<<20)

Referenced by eWavData::Mix(), and eAudioPos::Reset().

#define VOL_FRACTION   (1<<VOL_SHIFT)

Referenced by eWavData::Mix().

#define VOL_SHIFT   16

Referenced by eWavData::Mix().


Function Documentation

void fill_audio ( void *  udata,
Uint8 *  stream,
int  len 
)

Definition at line 87 of file eSound.cpp.

References eGrid::Cameras(), eGrid::CurrentGrid(), GrowingArrayBase::Len(), loudness_thresh, real_sound_sources, se_globalPlayers, and sound_sources.

Referenced by se_SoundInit().

00088 {
00089 #ifndef DEDICATED
00090     real_sound_sources=0;
00091     int i;
00092     if (eGrid::CurrentGrid())
00093         for(i=eGrid::CurrentGrid()->Cameras().Len()-1;i>=0;i--)
00094             eGrid::CurrentGrid()->Cameras()(i)->SoundMix(stream,len);
00095 
00096     for(i=se_globalPlayers.Len()-1;i>=0;i--)
00097         se_globalPlayers(i)->Mix(stream,len,0,1,1);
00098 
00099     if (real_sound_sources>sound_sources+4)
00100         loudness_thresh+=.01;
00101     if (real_sound_sources>sound_sources+1)
00102         loudness_thresh+=.001;
00103     if (real_sound_sources<sound_sources-4)
00104         loudness_thresh-=.001;
00105     if (real_sound_sources<sound_sources-1)
00106         loudness_thresh-=.0001;
00107     if (loudness_thresh<0)
00108         loudness_thresh=0;
00109 #endif
00110 }

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Referenced by MainMenu().

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 }

Here is the caller graph for this function:

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:


Variable Documentation

uSelectEntry<int> a(sq_men,"$sound_menu_quality_off_text","$sound_menu_quality_off_help", SOUND_OFF) [static]

Referenced by vValue::Expr::Collection::ColDifference::_operation(), vValue::Expr::Collection::ColIntersection::_operation(), vValue::Expr::Collection::ColUnion::_operation(), vValue::Expr::Collection::ColBinary::_operation(), gNetPlayerWall::Alpha(), gPlayerWall::Alpha(), tRecorderSync< DATA >::Archive(), memblock::Check(), cWidget::Map::ClipperCircle::Clip(), CompareBufferToPlayerNames(), Contains(), gAIPlayer::CycleBlocksWay(), rTextField::FlushLine(), tRandomizer::Get(), rGradient::GetColor(), gSpark::gSpark(), eSoundMixer::Init(), rModel::Load(), eWavData::Loop(), md5_process(), nMessage::operator<<(), nMessage::operator>>(), cWidget::WithTable::ProcessCell(), cWidget::WithColorFunctions::ProcessGradientCore(), zShapeCircle::render(), gZone::Render(), gSpark::Render(), zShapeCircle::render2d(), gZone::Render2D(), cWidget::NeedleGauge::RenderGraph(), gNetPlayerWall::RenderList(), rModelFace::rModelFace(), s_InputConfigGeneric(), se_GetAlivePlayerFromUserID(), tPolynomial< T >::setAtSameReferenceVarValue(), SWIG_AsVal_double(), SWIG_AsVal_long(), SWIG_AsVal_unsigned_SS_long(), tPolynomialTest::testAddition(), tPolynomialTest::testEvaluateAndBaseArgument(), tPolynomialTest::testMultiplication(), tPolynomialTest::testParse(), gAIPlayer::ThinkTrace(), and Vec3::Vec3().

SDL_AudioSpec audio [static]

Definition at line 56 of file eSound.cpp.

Referenced by eWavData::Mix(), and se_SoundInit().

uSelectEntry<int> b(sq_men,"$sound_menu_quality_low_text","$sound_menu_quality_low_help", SOUND_LOW) [static]

Referenced by vValue::Expr::Collection::ColDifference::_operation(), vValue::Expr::Collection::ColIntersection::_operation(), vValue::Expr::Collection::ColUnion::_operation(), vValue::Expr::Collection::ColBinary::_operation(), tRecorderSync< DATA >::Archive(), memblock::Check(), Contains(), rTextField::FlushLine(), tRandomizer::Get(), tDecoratableManager< Decorated >::GetBase(), rGradient::GetColor(), gFloor::glFloorColor(), gSpark::gSpark(), eSoundMixer::Init(), rModel::Load(), eWavData::Loop(), md5_process(), uMenu::OnEnter(), pVec::operator/=(), PartialIPAddress(), cWidget::WithTable::ProcessCell(), cWidget::WithColorFunctions::ProcessGradientCore(), zZone::ReadSync(), zShapeCircle::render(), gZone::Render(), gSpark::Render(), zShapeCircle::render2d(), gZone::Render2D(), ArmageTron_color_menuitem::RenderBackground(), gNetPlayerWall::RenderList(), rModelFace::rModelFace(), s_InputConfigGeneric(), gCycle::SyncEnemy(), tPolynomialTest::testAddition(), tPolynomialTest::testEvaluateAndBaseArgument(), tPolynomialTest::testMultiplication(), tPolynomialTest::testParse(), and Vec3::Vec3().

uSelectEntry<int> ba(bm_men,"$sound_menu_buffer_vsmall_text","$sound_menu_buffer_vsmall_help",-2) [static]

uSelectEntry<int> bb(bm_men,"$sound_menu_buffer_small_text","$sound_menu_buffer_small_help",-1) [static]

Referenced by eGrid::DrawLine(), and eHalfEdge::Simplify().

uSelectEntry<int> bc(bm_men,"$sound_menu_buffer_med_text","$sound_menu_buffer_med_help", 0) [static]

uSelectEntry<int> bd(bm_men,"$sound_menu_buffer_high_text","$sound_menu_buffer_high_help", 1) [static]

uSelectEntry<int> be(bm_men,"$sound_menu_buffer_vhigh_text","$sound_menu_buffer_vhigh_help", 2) [static]

tConfItem<int> bs("SOUND_BUFFER_SHIFT", buffer_shift) [static]

int buffer_shift = 0 [static]

Definition at line 71 of file eSound.cpp.

Referenced by se_SoundInit(), and se_SoundMenu().

uSelectEntry<int> c(sq_men,"$sound_menu_quality_medium_text","$sound_menu_quality_medium_help", SOUND_MED) [static]

Referenced by gStatList::add(), gCamera::CenterCycleDir(), DisplayText(), memblock::Dispose(), do_con(), rConsole::DoPrint(), gCycle::DropWall(), tConfItemBase::EatWhitespace(), nKrawall::EncodeString(), uMenuItemString::Event(), uMenuItemInput::Event(), tDirectories::FileMatchesWildcard(), tStatFile::flushWrites(), GetParent(), gStatList::getPlaceInList(), gStatList::greater(), gSpark::gSpark(), eSoundMixer::Init(), zShapePolygon::isInside(), tLocaleItem::Load(), rModel::Load(), tConfItemBase::LoadLine(), LoadSingleAI(), main(), md5_process(), uMenu::Message(), nServerInfo::NetReadThis(), new_destination_handler(), uMenu::OnEnter(), tLocaleItem::operator const char *(), operator<<(), operator>>(), cWidget::WithTable::ProcessCell(), tString::ReadLine(), tConfItem_key::ReadVal(), tConfItem< nConfigItemBehavior >::ReadVal(), gCycle::Render(), cWidget::Label::Render(), eCamera::Render(), rModelFace::rModelFace(), eGameObject::s_Timestep(), eCamera::s_Timestep(), se_EscapeName(), SearchCorClosebracket(), SearchCorOpenbracket(), rGradient::SetValues(), sg_FullscreenMessage(), su_TransformEvent(), Swap(), SWIG_Ruby_CheckConvert(), SWIG_Ruby_ConvertPacked(), SWIG_Ruby_ConvertPtrAndOwn(), tPolynomialTest::testAddition(), tPolynomialTest::testMultiplication(), tPolynomialTest::testParse(), eCamera::Timestep(), uJoystick::uJoystick(), uKeyInput::uKeyInput(), gStatList::update(), Vec3::Vec3(), welcome(), and gStatList::~gStatList().

uSelectEntry<int> d(sq_men,"$sound_menu_quality_high_text","$sound_menu_quality_high_help", SOUND_HIGH) [static]

Referenced by gCycleMovement::CalculateAcceleration(), eGrid::DrawLine(), eh_getdir(), tDecoratableManager< Decorated >::GetBase(), gNetPlayerWall::IndexAlpha(), md5_process(), eWavData::Mix(), eCamera::nextDirIfGlancing(), gCycle::PassEdge(), sg_CycleWallLengthFromDist(), gSpawnPoint::Spawn(), SWIG_UnpackData(), tPolynomialTest::testMultiplication(), gAIPlayer::ThinkPath(), eCamera::Timestep(), and gCycle::WallEndSpeed().

unsigned int locks [static]

Definition at line 303 of file eSound.cpp.

REAL loudness_thresh = 0 [static]

Definition at line 81 of file eSound.cpp.

Referenced by fill_audio(), and eSoundPlayer::Mix().

int real_sound_sources = 0 [static]

Definition at line 82 of file eSound.cpp.

Referenced by fill_audio(), and eSoundPlayer::Mix().

tList<eSoundPlayer> se_globalPlayers [static]

Definition at line 84 of file eSound.cpp.

Referenced by fill_audio().

bool sound_is_there = false [static]

Definition at line 57 of file eSound.cpp.

Referenced by se_SoundExit(), and se_SoundInit().

static uMenuItemSelection< int > bm_men & Sound_menu

Definition at line 797 of file eSound.cpp.

Referenced by se_SoundMenu().

int sound_quality = SOUND_MED

Definition at line 76 of file eSound.cpp.

Referenced by eSoundMixer::Init(), se_SoundInit(), and se_SoundMenu().

int sound_sources = 10 [static]

Definition at line 79 of file eSound.cpp.

Referenced by fill_audio().

tConfItem<int> sq("SOUND_QUALITY", sound_quality) [static]

tConfItem<int> ss("SOUND_SOURCES", sound_sources) [static]

Referenced by zEffectorSetting::effect(), and gParser::parseSetting().

bool uses_sdl_mixer = false [static]

Definition at line 58 of file eSound.cpp.

Referenced by se_SoundExit(), and se_SoundInit().


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