void playSoundtrack(const char *filename) { #ifdef USE_SOUND if(music == NULL) { music = Mix_LoadMUS(filename); // Load the music Mix_PlayMusic(music, -1); // Loop infinitely Mix_VolumeMusic(10); // Set volume } else { //TODO: add a transition between soundtracks stopSoundtrack(); playSoundtrack(filename); } #endif }
void Gameplay::playSoundtrack(const char* resource) { // stop playing stopSoundtrack(); // obtain desired sound volume TiXmlElement* xmlSound = Gameplay::iGameplay->getConfigElement( "sound" ); assert( xmlSound ); double musicVolume = 0.0f; xmlSound->Attribute( "musicVolume", &musicVolume ); assert( musicVolume >= 0 ); assert( musicVolume <= 1 ); // play new sound if( musicVolume > 0 ) { _soundTrack = iAudio->createStreamSound( resource, 4, 256*1024 ); assert( _soundTrack ); _soundTrack->play(); _soundTrack->setGainLimits( 0.0f, 1.0f ); _soundTrack->setGain( float( musicVolume ) ); } }
static void cleanupSound() { stopSoundtrack(); Mix_CloseAudio(); }