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
al_sound.cpp File Reference
#include "audiolib.h"
#include "hashtable.h"
#include "vsfilesystem.h"
#include <string>
#include "al_globals.h"
#include <stdio.h>
#include <stdlib.h>
#include "cmd/unit_generic.h"
#include "gfx/cockpit_generic.h"
#include <vector>
#include "vs_globals.h"
#include <algorithm>

Go to the source code of this file.

Macros

#define AL_SEC_OFFSET   0x1024
 

Functions

bool AUDLoadSoundFile (const char *s, struct AUDSoundProperties *info, bool use_fileptr)
 
int AUDBufferSound (const struct AUDSoundProperties *info, bool music)
 
int AUDCreateSoundWAV (const std::string &s, const bool music, const bool LOOP)
 
int AUDCreateSoundWAV (const std::string &s, const bool LOOP)
 creates a buffer if one doesn't already exists, and then creates a source More...
 
int AUDCreateMusicWAV (const std::string &s, const bool LOOP)
 creates a buffer if one doesn't already exists, and then creates a source More...
 
int AUDCreateSoundMP3 (const std::string &s, const bool music, const bool LOOP)
 
int AUDCreateSoundMP3 (const std::string &s, const bool LOOP)
 creates a buffer for an mp3 sound if one doesn't already exist, then creates a source More...
 
int AUDCreateMusicMP3 (const std::string &s, const bool LOOP)
 creates a buffer for an mp3 sound if one doesn't already exist, then creates a source More...
 
int AUDCreateSound (const std::string &s, const bool LOOP)
 guesses the type of sound by extension More...
 
int AUDCreateMusic (const std::string &s, const bool LOOP)
 guesses the type of sound by extension More...
 
int AUDCreateSound (int sound, const bool LOOP)
 copies other sound loaded through AUDCreateSound More...
 
void AUDDeleteSound (int sound, bool music)
 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...
 
bool starSystemOK ()
 
int AUDHighestSoundPlaying ()
 
void AUDStopAllSounds (int except_this_one)
 
bool AUDIsPlaying (const int sound)
 Is a loaded sound still playing. More...
 
void AUDStopPlaying (const int sound)
 Stops a loaded sound. More...
 
static bool AUDReclaimSource (const int sound, bool high_priority=false)
 
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...
 
float AUDGetCurrentPosition (const int sound)
 Gets the current playback position in seconds (precision is system&driver-dependant) More...
 
void AUDPausePlaying (const int sound)
 Pauses a loaded sound. More...
 

Variables

unsigned int nil_wavebuf = 0
 
std::vector< intsoundstodelete
 

Macro Definition Documentation

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.

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 }
int AUDBufferSound ( const struct AUDSoundProperties *  info,
bool  music 
)

Definition at line 477 of file al_sound.cpp.

Referenced by Music::Listen().

478 {
479  ALuint wavbuf = 0;
480 #ifdef HAVE_AL
481  alGenBuffers( 1, &wavbuf );
482  if (!wavbuf) printf( "OpenAL Error in alGenBuffers: %d\n", alGetError() );
483  alBufferData( wavbuf, info->format, info->wave, info->size, info->freq );
484 #endif
485  return LoadSound( wavbuf, info->looping, music );
486 }
int AUDCreateMusic ( const std::string &  s,
const bool  LOOP 
)

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 &  s,
const bool  LOOP 
)

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 &  s,
const bool  LOOP 
)

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 ( const std::string &  s,
const bool  LOOP 
)

guesses the type of sound by extension

Definition at line 604 of file al_sound.cpp.

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 AUDCreateSound ( int  sound,
const bool  LOOP 
)

copies other sound loaded through AUDCreateSound

Definition at line 627 of file al_sound.cpp.

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 AUDCreateSoundMP3 ( const std::string &  s,
const bool  music,
const bool  LOOP 
)

Definition at line 550 of file al_sound.cpp.

References VSFileSystem::VSFile::Close(), error, f, g_game, VSFileSystem::GetHashName(), VSFileSystem::GetSharedSoundHashName(), game_data_t::music_enabled, VSFileSystem::Ok, VSFileSystem::VSFile::OpenReadOnly(), VSFileSystem::VSFile::Read(), VSFileSystem::Shared, VSFileSystem::VSFile::Size(), game_data_t::sound_enabled, and VSFileSystem::SoundFile.

Referenced by AUDCreateMusicMP3(), AUDCreateSound(), AUDCreateSoundMP3(), and BeamXML::beginElement().

551 {
552 #ifdef HAVE_AL
553  assert( 0 );
554  if ( (g_game.sound_enabled && !music) || (g_game.music_enabled && music) ) {
555  VSFile f;
556  VSError error = f.OpenReadOnly( s.c_str(), SoundFile );
557  bool shared = (error == Shared);
558  std::string nam( s );
559  ALuint *mp3buf = NULL;
560  std::string hashname;
561  if (!music) {
562  hashname = shared ? VSFileSystem::GetSharedSoundHashName( s ) : VSFileSystem::GetHashName( s );
563  mp3buf = soundHash.Get( hashname );
564  }
565  if (error > Ok)
566  return -1;
567 #ifdef _WIN32
568  return -1;
569 #endif
570  if (mp3buf == NULL) {
571  char *data = new char[f.Size()];
572  f.Read( data, f.Size() );
573  mp3buf = (ALuint*) malloc( sizeof (ALuint) );
574  alGenBuffers( 1, mp3buf );
575  /*
576  * if ((*alutLoadMP3p)(*mp3buf,data,f.Size())!=AL_TRUE) {
577  * delete []data;
578  * return -1;
579  * }*/
580  delete[] data;
581  if (!music) {
582  soundHash.Put( hashname, mp3buf );
583  buffers.push_back( *mp3buf );
584  }
585  } else {
586  f.Close();
587  }
588  return LoadSound( *mp3buf, LOOP, music );
589  }
590 #endif
591  return -1;
592 }
int AUDCreateSoundMP3 ( const std::string &  s,
const bool  LOOP 
)

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.

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

Definition at line 495 of file al_sound.cpp.

References AUDLoadSoundFile(), g_game, VSFileSystem::GetHashName(), VSFileSystem::GetSharedSoundHashName(), game_data_t::music_enabled, nil_wavebuf, and game_data_t::sound_enabled.

Referenced by abletodock(), AddSounds(), GameUnit< UnitType >::ArmorDamageSound(), AUDCreateMusicWAV(), AUDCreateSound(), AUDCreateSoundWAV(), BeamXML::beginElement(), BaseInterface::Room::Talk::Click(), Beam::Collide(), createSound(), GameUnit< UnitType >::DealDamageToShield(), GameUnit< UnitType >::HullDamageSound(), soundContainer::loadsound(), UniverseUtil::playSound(), UniverseUtil::playSoundCockpit(), GameCockpit::SetSoundFile(), and Unit::UpdatePhysics().

496 {
497 #ifdef HAVE_AL
498 #ifdef SOUND_DEBUG
499  printf( "AUDCreateSoundWAV:: " );
500 #endif
501  if ( (g_game.sound_enabled && !music) || (g_game.music_enabled && music) ) {
502  ALuint *wavbuf = NULL;
503  std::string hashname;
504  if (!music) {
505  hashname = VSFileSystem::GetHashName( s );
506  wavbuf = soundHash.Get( hashname );
507  if (!wavbuf) {
508  hashname = VSFileSystem::GetSharedSoundHashName( s );
509  wavbuf = soundHash.Get( hashname );
510  }
511  if (wavbuf == &nil_wavebuf)
512  return -1; //404
513  }
514  if (wavbuf) {
515 #ifdef SOUND_DEBUG
516  printf( "Sound %s restored with alBuffer %d\n", s.c_str(), *wavbuf );
517 #endif
518  }
519  if (wavbuf == NULL) {
520  AUDSoundProperties info;
521  if ( !AUDLoadSoundFile( s.c_str(), &info ) ) {
522  soundHash.Put( info.hashname, &nil_wavebuf );
523  return -1;
524  }
525  wavbuf = (ALuint*) malloc( sizeof (ALuint) );
526  alGenBuffers( 1, wavbuf );
527  alBufferData( *wavbuf, info.format, info.wave, info.size, info.freq );
528  free( info.wave ); //alutUnloadWAV(format,wave,size,freq);
529  if (!music) {
530  soundHash.Put( info.hashname, wavbuf );
531  buffers.push_back( *wavbuf );
532  }
533  }
534  return LoadSound( *wavbuf, LOOP, music );
535  }
536 #endif
537  return -1;
538 }
int AUDCreateSoundWAV ( const std::string &  s,
const bool  LOOP 
)

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

Definition at line 540 of file al_sound.cpp.

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

deletes a given sound

Definition at line 639 of file al_sound.cpp.

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 }
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 }
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 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 }
bool AUDLoadSoundFile ( const char *  s,
struct AUDSoundProperties *  info,
bool  use_fileptr 
)

Definition at line 409 of file al_sound.cpp.

References VSFileSystem::VSFile::Close(), error, f, fclose, fopen, VSFileSystem::GetHashName(), VSFileSystem::GetSharedSoundHashName(), VSFileSystem::Ok, VSFileSystem::VSFile::OpenReadOnly(), VSFileSystem::VSFile::Read(), VSFileSystem::Shared, VSFileSystem::VSFile::Size(), VSFileSystem::SoundFile, VSFileSystem::UnknownFile, and VSFileSystem::vs_dprintf().

Referenced by AUDCreateSoundWAV(), and Muzak::readerThread().

410 {
411  VSFileSystem::vs_dprintf(3, "Loading sound file %s\n", s);
412 
413  info->success = false;
414  vector< char >dat;
415  if (use_fileptr) {
416  FILE *f = fopen( s, "rb" );
417  if (!f) {
418  std::string path = std::string( "sounds/" )+s;
419  f = fopen( path.c_str(), "rb" );
420  }
421  if (!f) {
422  std::string path = std::string( "music/" )+s;
423  f = fopen( path.c_str(), "rb" );
424  }
425  if (f) {
426  fseek( f, 0, SEEK_END );
427  size_t siz = ftell( f );
428  fseek( f, 0, SEEK_SET );
429  dat.resize( siz );
430  size_t bogus_return_var; //added by chuck_starchaser to get rid of warning
431  bogus_return_var = fread( &dat[0], 1, siz, f );
432  info->hashname = s;
433  info->shared = false;
434  fclose( f );
435  } else {
436  return false;
437  }
438  } else {
439  VSFile f;
441  if (error > Ok)
442  error = f.OpenReadOnly( s, UnknownFile );
443  info->shared = (error == Shared);
444  if (info->shared)
445  info->hashname = VSFileSystem::GetSharedSoundHashName( s );
446  else
447  info->hashname = VSFileSystem::GetHashName( s );
448  if (error > Ok)
449  return false;
450 #ifdef SOUND_DEBUG
451  printf( "Sound %s created with and alBuffer %d\n", s.c_str(), *wavbuf );
452 #endif
453  dat.resize( f.Size() );
454  f.Read( &dat[0], f.Size() );
455  f.Close();
456  }
457  ConvertFormat( dat );
458  if (dat.size() == 0) //conversion messed up
459  return false;
460  //blutLoadWAVMemory((ALbyte *)&dat[0], &format, &wave, &size, &freq, &looping);
461 
462 #if 0
463  ALint format;
464  //MAC OS X
465  if (error <= Ok)
466  MacFixedLoadWAVFile( &dat[0], &format, &wave, &size, &freq );
467 #else
468  blutLoadWAVMemory( (ALbyte*) &dat[0], &info->format, &info->wave, &info->size, &info->freq, &info->looping );
469 #endif
470  if (!info->wave)
471  return false; //failure.
472 
473  info->success = true;
474  return true;
475 }
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.

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 }
static bool AUDReclaimSource ( const int  sound,
bool  high_priority = false 
)
static

Definition at line 796 of file al_sound.cpp.

References AUDDistanceSquared().

Referenced by AUDPlay(), and AUDStartPlaying().

797 {
798 #ifdef HAVE_AL
799  if (sounds[sound].source == (ALuint) 0) {
800  if (!sounds[sound].buffer)
801  return false;
802  if ( unusedsrcs.empty() ) {
803  if (high_priority) {
804  unsigned int i;
805  unsigned int candidate = 0;
806  bool found = false;
807  for (i = 0; i < sounds.size(); ++i)
808  if (sounds[i].source != 0)
809  if (sounds[i].pos.i != 0 || sounds[i].pos.j != 0 || sounds[i].pos.k != 0) {
810  if (found) {
811  if ( AUDDistanceSquared( candidate ) < AUDDistanceSquared( i ) )
812  candidate = i;
813  } else {
814  candidate = i;
815  }
816  found = true;
817  }
818  if (!found) {
819  return false;
820  } else {
821  alSourceStop( sounds[candidate].source );
822  sounds[sound].source = sounds[candidate].source;
823  alSourcei( sounds[candidate].source, AL_BUFFER, 0 ); //reclaim the source
824  sounds[candidate].source = 0;
825  }
826  } else {
827  return false;
828  }
829  } else {
830  sounds[sound].source = unusedsrcs.back();
831  unusedsrcs.pop_back();
832  }
833  alSourcei( sounds[sound].source, AL_BUFFER, sounds[sound].buffer );
834  alSourcei( sounds[sound].source, AL_LOOPING, sounds[sound].looping );
835  }
836  return true;
837 #endif
838  return false; //silly
839 }
void AUDStartPlaying ( const int  sound)

Plays a loaded sound.

Definition at line 841 of file al_sound.cpp.

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)

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 }
bool starSystemOK ( )

Definition at line 727 of file al_sound.cpp.

References _Universe, Universe::AccessCockpit(), Universe::activeStarSystem(), Cockpit::GetParent(), and Unit::getStarSystem().

Referenced by AUDPlay(), and AUDStartPlaying().

728 {
729  if ( !_Universe || !_Universe->AccessCockpit( 0 ) )
730  return true; //No Universe yet, so game is loading.
731 
732  Unit *playa = _Universe->AccessCockpit( 0 )->GetParent();
733  if (!playa)
734  return false;
735  return playa->getStarSystem() == _Universe->activeStarSystem();
736 }

Variable Documentation

unsigned int nil_wavebuf = 0

Definition at line 493 of file al_sound.cpp.

Referenced by AUDCreateSoundWAV().

std::vector< int > soundstodelete

Definition at line 172 of file al_listen.cpp.

Referenced by AUDDeleteSound(), and AUDRefreshSounds().