Exemple #1
0
void KSoundManager::update(float dt)
{
	if(mSilent) return;
	mSystem->update();

	if (fading)
	{
		musicFadeTimeCounter -= dt;
		if (musicFadeTimeCounter < 0)
		{
			printf("fade song to %s\n", nextSong.c_str());
			stopSong();
			if(nextSong != "")
				playSong(nextSong, mMusicVolume, 0);
			nextSong = "";
			fading = false;
			musicFadeTimeCounter = 0.0;
			musicFadeTime = 0.0;
		}
		else
		{
			songChannel->setVolume(mMusicVolume * musicFadeTimeCounter/musicFadeTime);
		}
	}
	
	//if we have a play list...well, use it
	if(mUsePlayList && mPlayList.size())
	{
		unsigned int trackTime = 0;
		if(songChannel)
		{
			bool playing;
			songChannel->isPlaying(&playing);
			if(!playing) mTrackTime = 99999;
			else
			{
				songChannel->getPosition(&trackTime, FMOD_TIMEUNIT_MS);
				mTrackTime = 0.001 * trackTime;
			}
		}
		else
			mTrackTime = 99999;			//if the song stops, move on
		if(mTrackTime > mPlayList[mTrack].trackTime)
			skipSong();
	}
	
	for(int i = 0; i < (int)mDelayedSounds.size(); i++)
	{
		mDelayedSounds[i].delay-= dt;
		if(mDelayedSounds[i].delay <= 0)
		{
			mDelayedSounds[i].sound->setPaused(false);
			mDelayedSounds[i] = mDelayedSounds.back();
			mDelayedSounds.pop_back();
			i--;
		}
	}
}
Exemple #2
0
void SoundManager::update(float dt)
{if(mSilent) return;
	mSystem->update();

	if (fading && song)
	{
		musicFadeTimeCounter -= dt;
		if (musicFadeTimeCounter < 0)
		{
			stopSong();
			if(nextSong != "")
				playSong(nextSong, 1, 0);
			nextSong = "";
			fading = false;
			musicFadeTimeCounter = 0.0;
			musicFadeTime = 0.0;
		}
		else
		{
			songChannel->setVolume(mMusicVolume * musicFadeTimeCounter/musicFadeTime);
		}
	}
	
	//if we have a play list...well, use it
	if(mUsePlayList && mPlayList.size())
	{
		unsigned int trackTime = 0;
		if(songChannel)
		{
			bool playing;
			songChannel->isPlaying(&playing);
			if(!playing) mTrackTime = 99999;
			else
			{
				songChannel->getPosition(&trackTime, FMOD_TIMEUNIT_MS);
			//if tracktime is zero and the last tracktime is also zero
		//	if(mTrackTime == 0 && trackTime == 0)
		//		mTrackTime = 9999;
		//	else
				mTrackTime = 0.001 * trackTime;
			}
		}
		else
			mTrackTime = 99999;			//if the song stops, move on
	//	printf("%f/%f\n", mTrackTime, mPlayList[mTrack].trackTime);
		if(mTrackTime > mPlayList[mTrack].trackTime)
			skipSong();

	}
}
Exemple #3
0
void KSoundManager::previousSong()
{
	if(mSilent) return;
	
	//if we didn't just start the song, just rewind it.  otherwise go to the previous song
	if(mTrackTime > 2 && songChannel)
	{
		printf("rewinding\n");
		mTrackTime = 0;
		songChannel->setPosition(5, FMOD_TIMEUNIT_RAWBYTES);
	}
	else
	{
		mTrack -= 2;				//go back two tracks
		skipSong();
	}
}
Exemple #4
0
void SoundManager::previousSong()
{if(mSilent) return;
	//if we didn't just start the song, just rewind it.  otherwise go to the previous song
	if(mTrackTime > 2 && songChannel)
	{
		printf("rewinding\n");
		mTrackTime = 0;
		songChannel->setPosition(5, FMOD_TIMEUNIT_RAWBYTES);
	}
	else
	{
		//printf("back a track from %i\n", mTrack);
		mTrack -= 2;				//go back two tracks
//		if(mTrack < -1)				//if we were on the first track, go to the last one
//			mTrack = mPlayList.size() - 2;
		skipSong();
	}
	
}