void updateMusicTransition(double dt) { if (myNextMusic != null) { myCurrentMusicTransitionTime += dt; //check for the end condition if (myCurrentMusicTransitionTime >= myMusicTransitionTime) { myNextMusic.volume = myMusicVolume; if (myCurrentMusic != null) { myCurrentMusic.stop(); } myCurrentMusic = myNextMusic; myNextMusic = null; return; } //adjust the volumes of the current music and next music float vol = myMusicVolume * (float)(myCurrentMusicTransitionTime / myMusicTransitionTime);; myNextMusic.volume = vol; if (myCurrentMusic != null) { myCurrentMusic.volume = myMusicVolume - vol; } } }
public void transitionMusic(SoundDescriptor music, double transitionTime) { //cleanup if we transition before we're done with a transition if (myNextMusic != null) { if (music.source.filename != myNextMusic.source.filename) { myNextMusic.stop(); myNextMusic = null; } else { return; //don't transition to the same song } } //don't transition to the same song if (myCurrentMusic != null && myCurrentMusic.source.filename == music.source.filename) { return; } //transition to new song Sound snd = new Sound(music); myNextMusic = snd; myNextMusic.volume = 0.0f; myNextMusic.play(); myMusicTransitionTime = transitionTime; myCurrentMusicTransitionTime = 0.0; }
public Voice getVoice(Sound snd) { Voice v = null; if (myInactiveVoiceList.Count > 0) { v = myInactiveVoiceList.Dequeue(); myActiveVoiceList.Add(v); return(v); } //want to try and take a voice from somebody else //priority system is based on priority then loudness (at the distance) //find one of a lower priority, stop it and get it's voice after it cleans up bool soundFound = false; foreach (AbstractAudio asnd in myPlayingSounds) { Sound playingSound = asnd as Sound; if (playingSound != null) { if (playingSound.priority < snd.priority) { //found one of lower priority playingSound.stop(); soundFound = true; break; } } } //look for one of the same priority, but quieter that we can override if (soundFound == false) { //TODO } //try to get the voice again if (myInactiveVoiceList.Count > 0) { v = myInactiveVoiceList.Dequeue(); myActiveVoiceList.Add(v); } //might not get a voice if you're not important enough return(v); }