Hello,
I’m struggling to get a system that blends between music tracks working. In short, I have about 10 repeating loops (40 seconds each) that are just different sections / intensity levels of the same song. All I want to do is fade out the current track and fade in the new track at the same time, but many frustrating hours later, I am no closer to this working properly.
This is the condensed code:
void USoundManager::PlayMusic(float _fadeTime) {
m_MusicComponent->FadeOut(_fadeTime, 0.0f);
m_MusicComponent->OnAudioPlaybackPercent.RemoveDynamic(this, &USoundManager::OnMusicPercent);
m_MusicComponent = UGameplayStatics::CreateSound2D);
m_MusicComponent->OnAudioPlaybackPercent.AddDynamic(this, &USoundManager::OnMusicPercent);
m_MusicComponent->FadeIn(_fadeTime, 1.0f, m_MusicTime);
}
void USoundManager::OnMusicPercent(const USoundWave* _musicTrack, const float _percent) {
m_MusicTime = _percent * _musicTrack->Duration;
}
OnAudioPlaybackPercent fails to send a real value (always 0.0f) if the decompression type is DTYPE_RealTime, but any wav longer than a couple seconds seems to use that no matter what. Setting the wav files to Streaming gets me a real playback percentage since it uses DTYPE_Streaming, but then the StartTime parameter of Play() and FadeIn() isn’t respected.
Updating a timer in Tick() manually kind of works, but loading and hitches get it out-of-sync. I’ve tried all the UGameplayStatics::GetXXXTime() functions to see if any would make it match up better, but no dice.
I’m not keen on doing a ton of audio work to break the tracks down further, I don’t want to keep 8 or 9 silent tracks playing and adjust volume, but are there any less terrible alternatives?