Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
audiolib.h File Reference
#include "gfx/vec.h"
#include <string>

Go to the source code of this file.

Functions

bool AUDInit ()
 
void AUDDestroy ()
 
void AUDListenerSize (const float size)
 Sets the size in which all sounds are going to be played. More...
 
void AUDListener (const QVector &pos, const Vector &vel)
 
QVector AUDListenerLocation ()
 
void AUDRefreshSounds ()
 Checks if sounds are still playing. More...
 
void AUDListenerOrientation (const Vector &i, const Vector &j, const Vector &k)
 Will the sound be played. More...
 
void AUDListenerGain (const float gain)
 
float AUDGetListenerGain ()
 
int AUDCreateSoundWAV (const std::string &, const bool LOOP=false)
 creates a buffer if one doesn't already exists, and then creates a source More...
 
int AUDCreateSoundMP3 (const std::string &, const bool LOOP=false)
 creates a buffer for an mp3 sound if one doesn't already exist, then creates a source More...
 
int AUDCreateMusicWAV (const std::string &, const bool LOOP=false)
 creates a buffer if one doesn't already exists, and then creates a source More...
 
int AUDCreateMusicMP3 (const std::string &, const bool LOOP=false)
 creates a buffer for an mp3 sound if one doesn't already exist, then creates a source More...
 
int AUDCreateSound (int sound, const bool LOOP=false)
 copies other sound loaded through AUDCreateSound More...
 
int AUDCreateSound (const std::string &, const bool LOOP=false)
 guesses the type of sound by extension More...
 
int AUDCreateMusic (const std::string &, const bool LOOP=false)
 guesses the type of sound by extension More...
 
void AUDStopAllSounds (int except_this_one=-1)
 
int AUDHighestSoundPlaying ()
 
void AUDDeleteSound (int sound, bool music=false)
 deletes a given sound More...
 
void AUDAdjustSound (const int sound, const QVector &pos, const Vector &vel)
 Changes the velocity and/or position of a given sound. More...
 
void AUDStreamingSound (const int sound)
 Setup the sound as a streaming source (this means right now only that it doesn't do 3D positional stuff) More...
 
void AUDSoundGain (int sound, float gain, bool music=false)
 Changes the gain of a loaded sound. More...
 
bool AUDIsPlaying (const int sound)
 Is a loaded sound still playing. More...
 
void AUDStopPlaying (const int sound)
 Stops a loaded sound. More...
 
void AUDStartPlaying (const int sound)
 Plays a loaded sound. More...
 
void AUDPlay (const int sound, const QVector &pos, const Vector &vel, const float gain)
 Queries if the sound should be culled. If not, plays. More...
 
void AUDPausePlaying (const int sound)
 Pauses a loaded sound. More...
 
void AUDChangeVolume (float volume)
 Changes the volume (generally 0 or between 1 and 1000) More...
 
float AUDGetVolume ()
 
void AUDChangeDoppler (float doppler)
 changes the scale used for doppler...generally between 0 for off or .01 and 10 More...
 
float AUDGetCurrentPosition (const int sound)
 Gets the current playback position in seconds (precision is system&driver-dependant) More...
 
float AUDGetDoppler ()
 Gets current doppler val. More...
 

Function Documentation

void AUDAdjustSound ( const int  sound,
const QVector pos,
const Vector vel 
)

Changes the velocity and/or position of a given sound.

Definition at line 683 of file al_sound.cpp.

References f, VegaConfig::getVariable(), XMLSupport::parse_float(), v, and vs_config.

Referenced by AUDPlay(), AUDStartPlaying(), Beam::Draw(), GameUnit< UnitType >::Draw(), Mount::PhysicsAlignedFire(), soundContainer::playsound(), UniverseUtil::playSound(), GameUnit< UnitType >::ResolveForces(), Beam::UpdatePhysics(), and Unit::UpdatePhysics().

684 {
685  static float ref_distance = XMLSupport::parse_float( vs_config->getVariable( "audio", "audio_ref_distance", "4000" ) );
686  static float max_distance = XMLSupport::parse_float( vs_config->getVariable( "audio", "audio_max_distance", "1000000" ) );
687 
688 #ifdef HAVE_AL
689  if ( sound >= 0 && sound < (int) sounds.size() ) {
690  float p[] = {
691  scalepos *pos.i, scalepos*pos.j, scalepos*pos.k
692  }
693  ;
694  float v[] = {scalevel *vel.i, scalevel*vel.j, scalevel*vel.k};
695  sounds[sound].pos = pos.Cast();
696  sounds[sound].vel = vel;
697  if (usepositional && sounds[sound].source) {
698  alSourcefv( sounds[sound].source, AL_POSITION, p );
699  bool relative = (p[0] == 0 && p[1] == 0 && p[2] == 0);
700  alSourcei( sounds[sound].source, AL_SOURCE_RELATIVE, relative );
701  if (!relative) {
702  // Set rolloff factrs
703  alSourcef(sounds[sound].source, AL_MAX_DISTANCE, scalepos * max_distance);
704  alSourcef(sounds[sound].source, AL_REFERENCE_DISTANCE, scalepos * ref_distance);
705  alSourcef(sounds[sound].source, AL_ROLLOFF_FACTOR, 1.f);
706  }
707  }
708  if (usedoppler && sounds[sound].source)
709  alSourcefv( sounds[sound].source, AL_VELOCITY, v );
710  }
711 #endif
712 }
void AUDChangeDoppler ( float  doppler)

changes the scale used for doppler...generally between 0 for off or .01 and 10

Definition at line 102 of file al_init.cpp.

Referenced by decdop(), and incdop().

103 {
104 #ifdef HAVE_AL
105  if (doppler <= 0)
106  usedoppler = false;
107  else
108  usedoppler = true;
109  scalevel = doppler;
110 #endif
111 }
void AUDChangeVolume ( float  volume)

Changes the volume (generally 0 or between 1 and 1000)

Definition at line 81 of file al_init.cpp.

References volume.

Referenced by decvol(), and incvol().

82 {
83 #ifdef HAVE_AL
84  if (volume == 0) {
85  usepositional = false;
86  return;
87  } else {
88  usepositional = true;
89  }
90  scalepos = 1./volume;
91 #endif
92 }
int AUDCreateMusic ( const std::string &  ,
const bool  LOOP = false 
)

guesses the type of sound by extension

Definition at line 615 of file al_sound.cpp.

References AUDCreateMusicMP3(), and AUDCreateMusicWAV().

616 {
617  if ( s.end()-1 >= s.begin() ) {
618  if (*(s.end()-1) == 'v')
619  return AUDCreateMusicWAV( s, LOOP );
620  else
621  return AUDCreateMusicMP3( s, LOOP );
622  }
623  return -1;
624 }
int AUDCreateMusicMP3 ( const std::string &  ,
const bool  LOOP = false 
)

creates a buffer for an mp3 sound if one doesn't already exist, then creates a source

Definition at line 599 of file al_sound.cpp.

References AUDCreateSoundMP3().

Referenced by AUDCreateMusic().

600 {
601  return AUDCreateSoundMP3( s, true, LOOP );
602 }
int AUDCreateMusicWAV ( const std::string &  ,
const bool  LOOP = false 
)

creates a buffer if one doesn't already exists, and then creates a source

Definition at line 545 of file al_sound.cpp.

References AUDCreateSoundWAV().

Referenced by AUDCreateMusic().

546 {
547  return AUDCreateSoundWAV( s, true, LOOP );
548 }
int AUDCreateSound ( int  sound,
const bool  LOOP = false 
)

copies other sound loaded through AUDCreateSound

Definition at line 627 of file al_sound.cpp.

References AUDIsPlaying(), and AUDStopPlaying().

628 {
629 #ifdef HAVE_AL
630  if ( AUDIsPlaying( sound ) )
631  AUDStopPlaying( sound );
632  if ( sound >= 0 && sound < (int) sounds.size() )
633  return LoadSound( sounds[sound].buffer, LOOP, false );
634 #endif
635  return -1;
636 }
int AUDCreateSound ( const std::string &  ,
const bool  LOOP = false 
)

guesses the type of sound by extension

Definition at line 604 of file al_sound.cpp.

References AUDCreateSoundMP3(), and AUDCreateSoundWAV().

Referenced by AddMounts(), AddSounds(), Beam::Beam(), GameStarSystem::DoJumpingLeaveSightAndSound(), Mount::PhysicsAlignedFire(), Mount::ReplaceSound(), GameUnit< UnitType >::Thrust(), and GameUnit< UnitType >::TransferUnitToSystem().

605 {
606  if ( s.end()-1 >= s.begin() ) {
607  if (*(s.end()-1) == '3')
608  return AUDCreateSoundMP3( s, LOOP );
609  else
610  return AUDCreateSoundWAV( s, LOOP );
611  }
612  return -1;
613 }
int AUDCreateSoundMP3 ( const std::string &  ,
const bool  LOOP = false 
)

creates a buffer for an mp3 sound if one doesn't already exist, then creates a source

Definition at line 594 of file al_sound.cpp.

References AUDCreateSoundMP3().

595 {
596  return AUDCreateSoundMP3( s, false, LOOP );
597 }
int AUDCreateSoundWAV ( const std::string &  ,
const bool  LOOP = false 
)

creates a buffer if one doesn't already exists, and then creates a source

Definition at line 540 of file al_sound.cpp.

References AUDCreateSoundWAV().

541 {
542  return AUDCreateSoundWAV( s, false, LOOP );
543 }
void AUDDeleteSound ( int  sound,
bool  music = false 
)

deletes a given sound

Definition at line 639 of file al_sound.cpp.

References AUDIsPlaying(), AUDStopPlaying(), soundstodelete, and VSFileSystem::vs_fprintf().

Referenced by AUDDestroy(), AUDRefreshSounds(), Unit::ClearMounts(), BaseInterface::Room::Talk::Click(), Unit::Kill(), Music::Listen(), Mount::PhysicsAlignedFire(), UniverseUtil::playSound(), UniverseUtil::playSoundCockpit(), Beam::~Beam(), and soundContainer::~soundContainer().

640 {
641 #ifdef HAVE_AL
642  if ( sound >= 0 && sound < (int) sounds.size() ) {
643  if ( AUDIsPlaying( sound ) ) {
644  if (!music) {
645 #ifdef SOUND_DEBUG
646  printf( "AUDDeleteSound: Sound Playing enqueue soundstodelete %d %d\n",
647  sounds[sound].source,
648  sounds[sound].buffer );
649 #endif
650  soundstodelete.push_back( sound );
651  return;
652  } else {
653  AUDStopPlaying( sound );
654  }
655  }
656 #ifdef SOUND_DEBUG
657  printf( "AUDDeleteSound: Sound Not Playing push back to unused src %d %d\n", sounds[sound].source, sounds[sound].buffer );
658 #endif
659  if (sounds[sound].source) {
660  unusedsrcs.push_back( sounds[sound].source );
661  alSourcei( sounds[sound].source, AL_BUFFER, 0 ); //decrement the source refcount
662  sounds[sound].source = (ALuint) 0;
663  }
664 #ifdef SOUND_DEBUG
665  if ( std::find( dirtysounds.begin(), dirtysounds.end(), sound ) == dirtysounds.end() ) {
666 #endif
667  dirtysounds.push_back( sound );
668 #ifdef SOUND_DEBUG
669  } else {
670  VSFileSystem::vs_fprintf( stderr, "double delete of sound %d", sound );
671  return;
672  }
673 #endif
674  //FIXME??
675  //alDeleteSources(1,&sounds[sound].source);
676  if (music)
677  alDeleteBuffers( 1, &sounds[sound].buffer );
678  sounds[sound].buffer = (ALuint) 0;
679  }
680 #endif
681 }
void AUDDestroy ( )

Definition at line 204 of file al_init.cpp.

References AUDDeleteSound(), AUDStopPlaying(), buffer, and i.

Referenced by cleanup().

205 {
206 #ifdef HAVE_AL
207  //Go through and delete all loaded wavs
208  unsigned int i;
209  for (i = 0; i < sounds.size(); i++) {
210  if (sounds[i].buffer != 0)
211  AUDStopPlaying( i );
212  AUDDeleteSound( i );
213  }
214  for (i = 0; i < unusedsrcs.size(); i++)
215  alDeleteSources( 1, &unusedsrcs[i] );
216  for (i = 0; i < buffers.size(); i++)
217  alDeleteBuffers( 1, &buffers[i] );
218  buffers.clear();
219  if (context_id)
220  alcDestroyContext( (ALCcontext*) context_id );
221  if (dev)
222  alcCloseDevice( dev );
223 #endif
224 }
float AUDGetCurrentPosition ( const int  sound)

Gets the current playback position in seconds (precision is system&driver-dependant)

Definition at line 898 of file al_sound.cpp.

References AL_SEC_OFFSET, and float.

899 {
900 #ifdef HAVE_AL
901  ALfloat rv;
902  alGetSourcef( sound, AL_SEC_OFFSET, &rv );
903  return float(rv);
904 #else
905  return 0;
906 #endif
907 }
float AUDGetDoppler ( )

Gets current doppler val.

Definition at line 112 of file al_init.cpp.

Referenced by decdop(), and incdop().

113 {
114 #ifdef HAVE_AL
115  return scalevel;
116 
117 #else
118  return 1;
119 #endif
120 }
float AUDGetListenerGain ( )

Definition at line 273 of file al_listen.cpp.

References Listener::gain, and mylistener.

Referenced by VolDown(), and VolUp().

274 {
275 #ifdef HAVE_AL
276  return mylistener.gain;
277 
278 #else
279  return 0;
280 #endif
281 }
float AUDGetVolume ( )

Definition at line 93 of file al_init.cpp.

Referenced by decvol(), and incvol().

94 {
95 #ifdef HAVE_AL
96  return 1./scalepos;
97 
98 #else
99  return 1;
100 #endif
101 }
int AUDHighestSoundPlaying ( )

Definition at line 738 of file al_sound.cpp.

References AUDIsPlaying().

Referenced by BaseInterface::BaseInterface().

739 {
740  int retval = -1;
741 #ifdef HAVE_AL
742  unsigned int s = ::sounds.size();
743  for (unsigned int i = 0; i < s; ++i)
744  if (false == ::sounds[i].music && AUDIsPlaying( i ) && false == ::sounds[i].looping)
745  retval = i;
746 #endif
747  return retval;
748 }
bool AUDInit ( )

Definition at line 132 of file al_init.cpp.

References game_data_t::audio_frequency_mode, g_game, VegaConfig::getVariable(), game_data_t::max_sound_sources, game_data_t::music_enabled, XMLSupport::parse_bool(), XMLSupport::parse_float(), XMLSupport::parse_int(), game_data_t::sound_enabled, and vs_config.

Referenced by main().

133 {
135  g_game.music_enabled = false;
136 #ifdef HAVE_AL
137  usedoppler = XMLSupport::parse_bool( vs_config->getVariable( "audio", "Doppler", "false" ) );
138  usepositional = XMLSupport::parse_bool( vs_config->getVariable( "audio", "Positional", "true" ) );
139  double linuxadjust=1;
140 #ifndef _WIN32
141 #ifndef __APPLE__
142  linuxadjust=1./3.;
143 #endif
144 #endif
145  scalepos = 1.0f/(XMLSupport::parse_float( vs_config->getVariable( "audio", "Volume", "100" ) )
146  *linuxadjust
147  );
148  scalevel = XMLSupport::parse_float( vs_config->getVariable( "audio", "DopplerScale", "1" ) );
149  //enabled = XMLSupport::parse_bool (vs_config->getVariable ("audio","enabled","true"));
150  g_game.audio_frequency_mode = XMLSupport::parse_int( vs_config->getVariable( "audio", "frequency", "48000" ) );
151  maxallowedsingle = XMLSupport::parse_int( vs_config->getVariable( "audio", "MaxSingleSounds", "8" ) );
153  maxallowedtotal = XMLSupport::parse_int( vs_config->getVariable( "audio", "MaxTotalSounds", "20" ) );
154  bool sound_enabled = XMLSupport::parse_bool( vs_config->getVariable( "audio", "Sound", "true" ) );
155  bool music_enabled = XMLSupport::parse_bool( vs_config->getVariable( "audio", "Music", "true" ) );
156  if (!sound_enabled && !music_enabled)
157  return false;
158  int attrlist[] = {ALC_FREQUENCY, g_game.audio_frequency_mode, 0};
159 #ifdef _WIN32
160  dev = alcOpenDevice( (ALCchar*)"DirectSound3D" );
161  // dev = alcOpenDevice( (ALCubyte*)"DirectSound3D" ); pre update. New includes barf on ubyte. cannot convert parameter.
162 #else
163 #ifdef __APPLE__
164  dev = alcOpenDevice( "sdl" );
165  if (dev == NULL)
166  dev = alcOpenDevice( NULL );
167 #else
168  dev = alcOpenDevice( NULL );
169 #endif
170 #endif
171  if (dev == NULL)
172  return false;
173  context_id = alcCreateContext( dev, attrlist );
174  if (context_id == NULL) {
175  alcCloseDevice( dev );
176  return false;
177  }
178  alcMakeContextCurrent( (ALCcontext*) context_id );
179 
180  fixup_function_pointers();
181  ALenum alGetEr = 0;
182  ALuint cursrc;
183  alGetError();
184  alGenSources( 1, &cursrc );
185  alGetEr = alGetError();
186  while (alGetEr == 0) {
187  unusedsrcs.push_back( cursrc );
188  if (unusedsrcs.size() >= maxallowedtotal)
189  break;
190  alGenSources( 1, &cursrc );
191  alGetEr = alGetError();
192  }
193 
194  alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
195 
196  g_game.sound_enabled = sound_enabled;
197  g_game.music_enabled = music_enabled;
198 
199  return true;
200 #endif
201  return false;
202 }
bool AUDIsPlaying ( const int  sound)

Is a loaded sound still playing.

Definition at line 760 of file al_sound.cpp.

Referenced by GameUnit< UnitType >::ArmorDamageSound(), AUDCreateSound(), AUDDeleteSound(), AUDHighestSoundPlaying(), AUDPlay(), AUDRefreshSounds(), AUDStopAllSounds(), GameUnit< UnitType >::DealDamageToShield(), FireKeyboard::Execute(), GameUnit< UnitType >::HullDamageSound(), Music::Listen(), Mount::PhysicsAlignedFire(), Mount::PhysicsAlignedUnfire(), FireKeyboard::ProcessCommMessage(), FSM::Node::StopSound(), GameUnit< UnitType >::Thrust(), Beam::UpdatePhysics(), Unit::UpdatePhysics(), and UpdateTimeCompressionSounds().

761 {
762 #ifdef HAVE_AL
763  if ( sound >= 0 && sound < (int) sounds.size() ) {
764  if (!sounds[sound].source)
765  return false;
766  ALint state;
767 #if defined (_WIN32) || defined (__APPLE__)
768  alGetSourcei( sounds[sound].source, AL_SOURCE_STATE, &state ); //Obtiene el estado de la fuente para windows
769 #else
770  alGetSourceiv( sounds[sound].source, AL_SOURCE_STATE, &state );
771 #endif
772 
773  return state == AL_PLAYING;
774  }
775 #endif
776  return false;
777 }
void AUDListener ( const QVector pos,
const Vector vel 
)

Definition at line 210 of file al_listen.cpp.

References g_game, mylistener, Listener::pos, game_data_t::sound_enabled, and Listener::vel.

Referenced by Camera::UpdateCameraSounds(), and Camera::UpdateGFX().

211 {
212 #ifdef HAVE_AL
213  mylistener.pos = pos.Cast();
214  mylistener.vel = vel;
215  if (g_game.sound_enabled) {
216  if (usepositional)
217  alListener3f( AL_POSITION, scalepos*pos.i, scalepos*pos.j, scalepos*pos.k );
218  if (usedoppler)
219  alListener3f( AL_VELOCITY, scalevel*vel.i, scalevel*vel.j, scalevel*vel.k );
220  }
221  //printf ("(%f,%f,%f) <%f %f %f>\n",pos.i,pos.j,pos.k,vel.i,vel.j,vel.k);
222 #endif
223 }
void AUDListenerGain ( const float  gain)

Definition at line 259 of file al_listen.cpp.

References AUDSoundGain(), g_game, Listener::gain, i, mylistener, and game_data_t::sound_enabled.

Referenced by main(), VolDown(), and VolUp().

260 {
261 #ifdef HAVE_AL
262  float gain = ggain;
263  if (gain <= 0) gain = 1./16384;
264  mylistener.gain = gain;
265  for (unsigned int i = 0, ie = sounds.size(); i < ie; ++i)
266  if (!sounds[i].music)
267  AUDSoundGain( i, sounds[i].gain, false );
268  if (g_game.sound_enabled)
269  alListenerf( AL_GAIN, 1.0 );
270 #endif
271 }
QVector AUDListenerLocation ( )

Definition at line 60 of file al_listen.cpp.

References mylistener, Listener::pos, and QVector.

Referenced by EstimateGain(), and Mount::PhysicsAlignedFire().

61 {
62  return mylistener.pos.Cast();
63 }
void AUDListenerOrientation ( const Vector i,
const Vector j,
const Vector k 
)

Will the sound be played.

Definition at line 232 of file al_listen.cpp.

References g_game, mylistener, Listener::p, Listener::q, q, Listener::r, and game_data_t::sound_enabled.

Referenced by Camera::UpdateCameraSounds(), and Camera::UpdateGFX().

233 {
234 #ifdef HAVE_AL
235  mylistener.p = p;
236  mylistener.q = q;
237  mylistener.r = r;
238  ALfloat orient[] = {r.i, r.j, r.k, q.i, q.j, q.k};
239  //printf ("R%f,%f,%f>Q<%f %f %f>",r.i,r.j,r.k,q.i,q.j,q.k);
240  if (g_game.sound_enabled)
241  alListenerfv( AL_ORIENTATION, orient );
242 #endif
243 }
void AUDListenerSize ( const float  size)

Sets the size in which all sounds are going to be played.

Definition at line 225 of file al_listen.cpp.

References mylistener, and Listener::rsize.

Referenced by createObjects().

226 {
227 #ifdef HAVE_AL
228  mylistener.rsize = rSize*rSize;
229 #endif
230 }
void AUDPausePlaying ( const int  sound)

Pauses a loaded sound.

Definition at line 909 of file al_sound.cpp.

910 {
911 #ifdef HAVE_AL
912  if ( sound >= 0 && sound < (int) sounds.size() ) {
913  //alSourcePlay( sounds[sound].source() );
914  }
915 #endif
916 }
void AUDPlay ( const int  sound,
const QVector pos,
const Vector vel,
const float  gain 
)

Queries if the sound should be culled. If not, plays.

Definition at line 862 of file al_sound.cpp.

References AUDAddWatchedPlayed(), AUDAdjustSound(), AUDIsPlaying(), AUDQueryAudability(), AUDReclaimSource(), AUDSoundGain(), AUDStopPlaying(), QVector, starSystemOK(), and VSFileSystem::vs_dprintf().

Referenced by abletodock(), GameUnit< UnitType >::ArmorDamageSound(), Beam::Collide(), GameUnit< UnitType >::DealDamageToShield(), GameStarSystem::DoJumpingLeaveSightAndSound(), FireKeyboard::Execute(), GameUnit< UnitType >::Explode(), GameUnit< UnitType >::HullDamageSound(), Mount::PhysicsAlignedFire(), soundContainer::playsound(), FireKeyboard::ProcessCommMessage(), GameCockpit::ScrollVDU(), GameUnit< UnitType >::Thrust(), GameUnit< UnitType >::TransferUnitToSystem(), and GameCockpit::VDUSwitch().

863 {
864 #ifdef HAVE_AL
865  char tmp;
866  if (sound < 0)
867  return;
868  if (sounds[sound].buffer == 0)
869  return;
870  if (!starSystemOK() && !sounds[sound].music)
871  return;
872  if ( AUDIsPlaying( sound ) )
873  AUDStopPlaying( sound );
874  if ( ( tmp = AUDQueryAudability( sound, pos.Cast(), vel, gain ) ) != 0 ) {
875  if ( AUDReclaimSource( sound, pos == QVector( 0, 0, 0 ) ) ) {
876  AUDAdjustSound( sound, pos, vel );
877  AUDSoundGain( sound, gain, sounds[sound].music );
878  if (tmp != 2) {
879  VSFileSystem::vs_dprintf(3, "AUDPlay sound %d %d\n",
880  sounds[sound].source, sounds[sound].buffer );
881  AUDAddWatchedPlayed( sound, pos.Cast() );
882  } else {
883  VSFileSystem::vs_dprintf(3, "AUDPlay stole sound %d %d\n",
884  sounds[sound].source, sounds[sound].buffer );
885  alSourceStop( sounds[sound].source );
886  }
887  alSourcePlay( sounds[sound].source );
888  }
889  }
890 #endif
891 }
void AUDRefreshSounds ( )

Checks if sounds are still playing.

Definition at line 174 of file al_listen.cpp.

References AUDDeleteSound(), AUDIsPlaying(), hashsize, i, j, k, playingbuffers, soundstodelete, and totalplaying.

Referenced by StarSystem::Update().

175 {
176 #ifdef HAVE_AL
177  static unsigned int i = 0;
178  if (i >= hashsize) {
179  i = 0;
180  } else {
181  for (unsigned int j = 0; j < playingbuffers[i].size(); j++)
182  if ( !AUDIsPlaying( playingbuffers[i][j].soundname ) ) {
183  totalplaying--;
184  if (sounds[playingbuffers[i][j].soundname].source != (ALuint) 0) {
185  unusedsrcs.push_back( sounds[playingbuffers[i][j].soundname].source );
186  alSourcei( sounds[playingbuffers[i][j].soundname].source, AL_BUFFER, 0 );
187  sounds[playingbuffers[i][j].soundname].source = (ALuint) 0;
188  }
189  ApproxSoundVec::iterator k = playingbuffers[i].begin();
190  k += j;
191  playingbuffers[i].erase( k );
192  j--;
193  }
194  ++i;
195  }
196  static unsigned int j = 0;
197  if ( j >= soundstodelete.size() ) {
198  j = 0;
199  } else {
200  int tmp = soundstodelete[j];
201  if ( !AUDIsPlaying( tmp ) ) {
202  soundstodelete.erase( soundstodelete.begin()+j );
203  AUDDeleteSound( tmp, false );
204  }
205  ++j;
206  }
207 #endif
208 }
void AUDSoundGain ( int  sound,
float  gain,
bool  music = false 
)

Changes the gain of a loaded sound.

Definition at line 245 of file al_listen.cpp.

References Listener::gain, and mylistener.

Referenced by AUDListenerGain(), AUDPlay(), AUDStartPlaying(), Beam::Draw(), Music::Listen(), and Mount::PhysicsAlignedFire().

246 {
247 #ifdef HAVE_AL
248  if ( sound >= 0 && sound < (int) sounds.size() ) {
249  sounds[sound].music = music;
250  float val = gain*(music ? 1.0f : mylistener.gain);
251  if (sounds[sound].source)
252  alSourcef( sounds[sound].source, AL_GAIN, val <= 1./16384 ? 0 : val );
253  sounds[sound].gain = gain;
254  //alSourcefv(sounds[sound].source,AL_VELOCITY,v);
255  }
256 #endif
257 }
void AUDStartPlaying ( const int  sound)

Plays a loaded sound.

Definition at line 841 of file al_sound.cpp.

References AUDAdjustSound(), AUDReclaimSource(), AUDSoundGain(), QVector, and starSystemOK().

Referenced by BaseInterface::Room::Talk::Click(), Beam::Init(), Music::Listen(), UniverseUtil::playSound(), UniverseUtil::playSoundCockpit(), and Unit::UpdatePhysics().

842 {
843 #ifdef SOUND_DEBUG
844  printf( "AUDStartPlaying(%d)", sound );
845 #endif
846 
847 #ifdef HAVE_AL
848  if ( sound >= 0 && sound < (int) sounds.size() ) {
849  if ( sounds[sound].music || starSystemOK() )
850  if ( AUDReclaimSource( sound, sounds[sound].pos == QVector( 0, 0, 0 ) ) ) {
851 #ifdef SOUND_DEBUG
852  printf( "AUDStartPlaying sound %d source:%d buffer:%d\n", sound, sounds[sound].source, sounds[sound].buffer );
853 #endif
854  AUDAdjustSound( sound, sounds[sound].pos, sounds[sound].vel );
855  AUDSoundGain( sound, sounds[sound].gain, sounds[sound].music );
856  alSourcePlay( sounds[sound].source );
857  }
858  }
859 #endif
860 }
void AUDStopAllSounds ( int  except_this_one = -1)

Definition at line 750 of file al_sound.cpp.

References AUDIsPlaying(), and AUDStopPlaying().

Referenced by BaseComputer::actionDone(), base_main_loop(), UniverseUtil::StopAllSounds(), and GameUnit< UnitType >::TransferUnitToSystem().

751 {
752 #ifdef HAVE_AL
753  unsigned int s = ::sounds.size();
754  for (unsigned int i = 0; i < s; ++i)
755  if ( (int) i != except_this_one && false == ::sounds[i].music && AUDIsPlaying( i ) )
756  AUDStopPlaying( i );
757 #endif
758 }
void AUDStopPlaying ( const int  sound)

Stops a loaded sound.

Definition at line 779 of file al_sound.cpp.

Referenced by GameUnit< UnitType >::ArmorDamageSound(), AUDCreateSound(), AUDDeleteSound(), AUDDestroy(), AUDPlay(), AUDStopAllSounds(), GameUnit< UnitType >::DealDamageToShield(), DestroyMount(), GameUnit< UnitType >::HullDamageSound(), Unit::Kill(), Mount::PhysicsAlignedFire(), Mount::PhysicsAlignedUnfire(), FSM::Node::StopSound(), GameUnit< UnitType >::Thrust(), Beam::UpdatePhysics(), Unit::UpdatePhysics(), UpdateTimeCompressionSounds(), and soundContainer::~soundContainer().

780 {
781 #ifdef HAVE_AL
782  if ( sound >= 0 && sound < (int) sounds.size() ) {
783 #ifdef SOUND_DEBUG
784  printf( "AUDStopPlaying sound %d source(releasing): %d buffer:%d\n", sound, sounds[sound].source, sounds[sound].buffer );
785 #endif
786  if (sounds[sound].source != 0) {
787  alSourceStop( sounds[sound].source );
788  unusedsrcs.push_back( sounds[sound].source );
789  alSourcei( sounds[sound].source, AL_BUFFER, 0 ); //decrement refcount
790  }
791  sounds[sound].source = (ALuint) 0;
792  }
793 #endif
794 }
void AUDStreamingSound ( const int  sound)

Setup the sound as a streaming source (this means right now only that it doesn't do 3D positional stuff)

Definition at line 714 of file al_sound.cpp.

References Audio::alSource3f().

Referenced by Music::Listen().

715 {
716 #ifdef HAVE_AL
717  if (sound >= 0 && sound < (int) sounds.size() && sounds[sound].source) {
718  alSource3f( sounds[sound].source, AL_POSITION, 0.0, 0.0, 0.0 );
719  alSource3f( sounds[sound].source, AL_VELOCITY, 0.0, 0.0, 0.0 );
720  alSource3f( sounds[sound].source, AL_DIRECTION, 0.0, 0.0, 0.0 );
721  alSourcef( sounds[sound].source, AL_ROLLOFF_FACTOR, 0.0 );
722  alSourcei( sounds[sound].source, AL_SOURCE_RELATIVE, AL_TRUE );
723  }
724 #endif
725 }