Delayed Audio in 4.15?

Playing sounds or music often has 1-3 second delays when they start, causing sync issues.

Ex: My boss battle has an intro that plays the loopable version once the ‘OnAudioFinished’ event fires. However it takes 3 full seconds to play the loopable song!
So when the intro ends, there’s 3 seconds of silence before the looping version starts.

This also happens at certain times for sound effects, making them some seconds after the animation required.

Is there any way around this? Or maybe this issue is fixed in 4.16?

Thanks!

Hey Juice-Tin,

Can’t say I’m experiencing that myself. It sounds like something is delaying your audio playback. Perhaps some kind of delay in the trigger or some other system interfering? Hard to tell from your description so far though.

Heya Dan,

I did some more tests and the delay is always there even though there’s no delays coded in. It’s all just instant triggers, and the same happens with every song.
Here’s what I’ve tried:

  1. Play new song when first ends

AudioComponent->OnAudioFinished.AddDynamic(this, &AAKQLevelScript::AudioFinished);

void Project::AudioFinished() {
	//Just prints text to screen
	UT::Pop("AudioFinished");

	AudioComponent->SetSound(Audio2);
	AudioComponent->Play();
}


This prints AudioFinished the moment the song ends, but then there’s a 2-3 second delay before the next song begins.

  1. Play new song when entering a trigger volume.
    Player enters a trigger volume, and this code runs:

void Project::Overlap() {
	//Just prints text to screen
	UT::Pop("Play New Audio");

	AudioComponent->Stop();
	AudioComponent->SetSound(Audio2);
	AudioComponent->Play();
}

Same result. Text prints and first song stops instantly, then after a delay the second song starts.

I’ve also tried having 2 audio components both with the songs already set on them, but there’s still always a delay when the song plays (seemingly dependant on the song file size/complexity?)

It’s perfectly fine when a song is starting on it’s own, or crossfades with other songs as you can’t notice it. But when one song needs to stop with another playing right after
it’s extremely noticeable and jarring.

I figured this was a normal part of Unreal that there was a delay to stream in the song, with some kind of work around or preloading/prioritization?

Out of curiosity, when are you experiencing this? Playback in editor? Playback straight from your IDE? Are you deploying to a platform? If so which?

What platform is this?

This is on windows, brand new SSD, i7, 16GB, through Play in Editor.
Listening to the songs in the content browser work fine though they’re delayed when played in game.

Tried it on the artist’s computer, his all work perfectly fine (same project, same code as mine), so I guess I am the only one with the problem.
This is a pain because I’m trying to update the game’s audio system to allow for intros->loops, with crossfades, etc. But everything has a large delay on it.

I’ve attached a recorded clip, halfway through I walk into a trigger volume that stops the current song and plays the new song, and you can see the delay I’m dealing with. (Works fine on the artist’s computer however).

Any ideas on things I can try? Clearing some sort of unreal cache? Some other tests?

Thanks!

P.s. This is on a clean install of unreal on a new SSD from monday, though it also happened before then.

Edit: Since this is apparently not a very common problem, should I post it in the answers/bugs section?
It’s directly impeding my work so I can’t just leave it unfixed. Thanks.

Edit 2: I created a sound cue with a mixer where a 2 second song and a 200 second song play at the exact same time. Results in PIE were as expected, smaller song plays immediately, with the bigger playing 2- seconds after.

Very odd. We haven’t had any issues like this - are you getting this in the old audio engine and not the new audio engine?

Are you streaming the source files? Are they real-time decompressed?

Hey Kevin,
I’m unsure of any old or new audio engines, so here’s how the audio is setup, what works fine, and what causes delays.

Setup

  • It’s the installed binary of UE4 off the launcher, nothing custom to the audio system or engine in any way.
  • I drag any .wav file into unreal.
  • Create a cube actor with an audio component, add the wav to the audio component

Wav/Cue is already on component when game starts

  • If it’s a wav, it will work fine.
  • If it’s a sound cue with 2 songs playing at the same time, they both play fine.
    X - If it’s a sound cue with 2 songs playing but one has a delay node, that one do the delay node and then have it’s additional delay.
    X - If it’s a sound cue using the concatenator node, the second song will be delayed.
    X - Song is already on component but not playing. Song is played at a later time, delayed.

Song is set into component during runtime through a USoundBase* reference on the blueprint/class (Component->Setsound(startSong))

  • If it’s done during BeginPlay, it works.
    X - If it’s done at any point after, it’ll be delayed.
    X - Same with sound cues, play immediately = works, not immediately = delayed.

It seems music only works properly during the beginplay phase, any any song that is played at runtime, whether it be dynamically through code or just delayed in the beginplay sound cue, will have it’s loading delays.
This also includes songs that are set to the component in beginplay but not actually played until later. Looks like only the reference is stored and they still need to be loaded the moment they are played.

Note: Setting a songs volume to 0% and then higher does not delay the song, even though it starts it from the beginning, possibly because it’s already loaded.

If this is either the old or new audio system, let me know and I’d love to try the other one.
Thanks!

Because it plays fine when you do it before the audio component begins playing, it sounds like maybe an issue with the audio thread messaging and not a fundamental issue with the audio engine.

There could be some edge case with our audio thread you’re hitting that we’ve not run into.

Just so I’m clear on exactly what you’re doing, maybe you can post a video?

I did some more tests and found out something interesting.

My game uses the Persistent World + Streaming levels. It still has loading screens but we found streaming levels had a ton of advantages over loading levels.
Only problem is that navigation wouldn’t work on streaming levels unless it was dynamic and auto rebuilt itself when a level was loaded.


With that in mind, check this out:https://youtube.com/watch?v=2u3JfsC7_5Q
First half shows new audio on a new map working fine.
Second half shows what happens when I introduce a navmesh and it starts building.
When the engine is under any work load (including compiling shaders) audio plays with a delay based on the size of the sound.

This explains why audio is delayed in my game, as the navmesh builds dynamically when the game starts and when levels change (I’d love for it to be a static navmesh but apparently that doesn’t work with persistant/streaming levels)
This also shows why It was working fine on a colleagues computer, as he was working in a level without any navmeshes. Also why it works fine on beginplay, It runs before the navmesh starts dynamically building as the level has to stream-load first.

At the end of the video I tried showing it in game however the nav wasnt dynamically building since that map wasn’t a streaming map, so it didn’t show in game.

Hopefully that clears some stuff up. Could be worth trying yourself in a new project. Make a huge plane with some obstacles, drop in a navmesh, and play a large song >3:00.
If you need any more info I’d be more than willing to help. Thanks!

It’s been quite some time, I think I found a repeatable problem above. Has anyone looked into the issue?

Thanks!

Edit: It seems this happens in all areas of the engine. As long as navigation is building, any source of audio will start delayed.
This includes Audio volumes placed in the level. The delay means the player walks halfway into the audio volume, skipping the fade-in before it starts. This results in a sudden audio track playing at full volume which is jarring.

Note: Navigation has to be dynamically generated with streaminglevels, hense why mine is set that way.

I suspect it’s because the looping sound is long (144 seconds), whilst the one-shot is short. The difference is the long sound is going to be real-time decoded, which uses async workers to decode audio chunks, which in the case of the editor doing some heavy load like building nav-meshes or shaders gets bottlenecked, results in delayed audio. Or force the longer sound to be fully decoded on level load? For cooked games, I believe the first two chunks of audio are already decoded ahead of time.

You could try to tweak the sound group settings and play the second sound with a sound group that has bAlwaysDecompressOnLoad=true. Youc an modify those in your engine ini file:

[/Script/Engine.SoundGroups]
+SoundGroupProfiles=(SoundGroup=SOUNDGROUP_Default, bAlwaysDecompressOnLoad=false, DecompressedDuration=5)
+SoundGroupProfiles=(SoundGroup=SOUNDGROUP_Effects, bAlwaysDecompressOnLoad=false, DecompressedDuration=5)
+SoundGroupProfiles=(SoundGroup=SOUNDGROUP_UI, bAlwaysDecompressOnLoad=false, DecompressedDuration=5)
+SoundGroupProfiles=(SoundGroup=SOUNDGROUP_Music, bAlwaysDecompressOnLoad=false, DecompressedDuration=0)
+SoundGroupProfiles=(SoundGroup=SOUNDGROUP_Voice, bAlwaysDecompressOnLoad=false, DecompressedDuration=0)

Then set the sound group on the asset. Note that it defaults to a decompressed duration of 5 seconds, so the short intro one-shot is fully decompressing during level load.

Also, have you tried making the longer sound a streaming sound?

Another question, is there a delay on the second sound (the longer loop) when you don’t use a concat node?

Thanks for the response, it actually happens on most sounds. I made a video below with more info, and you can see it happening on a 7.2 second sound.

The video with more info:

0:00-0:15
Charging audio is always playing, and volume just fades to 1 during the charge and back to 0 after, but audio doesn’t play until a second or so later when volume hits around 0.4. (It’s only a 7 second sound)
0:20-0:40
Showing it with attenuation (green sphere just to help see the radius in game). Same problem, sound just pops on a second or so later, ignoring the whole point of the attenuation.
0:45-1:10
Just another example with a louder audio clip to show how jarring it can be in game.
So you can see this happens anytime audio is played or even just raised above volume 0, has nothing to do with the concat node, that was just a way for me to show it’s delay at the time.

I’ve tried the suggestions you posted, messing with bAlwaysDecompressOnLoad, DecompressedDuration, and all the other values in the sound properties and custom sound class.
Nothing seemed to make a difference.
I added the changes to Project\Saved\Config\Windows\Engine.ini

I can’t seem to find anything about Streaming sounds, is there any more info on it?

Also, are you saying this audio issue will not be a problem for cooked games? If so that’s great!
However I’d still prefer to solve it in editor if possible.
We’re having a playable demo in gamescom which will need to be played through the editor, as the cooked build has much bigger spline-collision related problems (collision works perfectly in editor, randomly disappears when cooked).

Wow, that’s really bizarre!

Out of curiosity, can you try editing the SoundWave properties like so?

You may have to enable Streaming Audio properties and Allow Virtualized Sounds in the Project Settings.

If that works, it might be a work around for the time being.

Otherwise, for your Audio Components, are you activating them via collision or are they Auto-Activate on?

Are you doing any overriding of the camera Listener–not uncommon in a 3rd person game mode?

Hey Dan,
There doesn’t seem to be anything about Streaming Audio in the Project settings, either under the Audio tab, Streaming tab, or when searching for: ‘strea’.
Perhaps it’s under another title or must be edited through the console/.ini files?
Edit: It’s in Editor settings, will try it soon.

Virtualized is perfect for ambient noise such as rivers, as the sound won’t ever need to restart causing the delay.

There are audio components for common looping sounds such as the Charge attack, grinding on rails, etc (auto activate on).
Music is handled on 2 audio components that alternate and crossfade through c++ when switching to a new song.
There’s the ambient attenuated music dragged onto the stage.
Some audio is played through C++ when certain conditions are met, however it’s always the same. Delays on certain loopable sounds when the sound plays or is raised above 0 volume (fixed with virtualization)

As for the camera listener, I don’t even know what that is. :slight_smile:
Just a regular camera attached to a springarm component, nothing fancy there.
There’s another class that handles the springarm/camera movement, but nothing messing with the base camera class itself.

However I’ve tested this on new projects and they have the same problems, so I doubt it’s anything directly related to my game.

Also if you’re curious, below is the exact uses for the audio in my game, and it’s results.

Minor problems fixed with virtualization:

  • Ambient sound with Attenuation/Specialization: Delayed a second after entering the zone
  • Short looping sounds such as the charge attack from the video: Delayed a second after the charge has started

Not fixed, most problematic:

  • Music Intros->Loops: Loop must start after the intro ends, no way to keep it playing on 0. I’ve tried running it through c++ manually when the intro duration ended, adding an OnFinished event, and using Sound cue concat nodes. All give the same delay.
  • Starting new songs: Moving to a new area, old song fades out while new fades in. Instead, old song fades out, 2 seconds of silence, then new one starts abruptly at full volume (where the fade would have been)
  • Crossfading: A key ability in the game is going into ‘Spirit world’ at any point, where the main song fades out, and a second “spirit” version of the same song starts at the same position and fades in. The delay makes the song start later so it falls out of sync and sounds bad when they switch.

Edit:
At the time I created streaming levels, Navmeshes would not appear unless set to dynamic, rebuild on load, and with an empty navmesh in the persistant map (a workaround suggested by UE4 staff).

Looks like it’s been fixed since then! I just tried setting static navmeshes in the persistant map and it works perfectly!
No Navmesh generation = no audio/grass problems!

Posts above are still valid for anyone requiring dynamic navmeshes, and odd those problems were only introduced in 4.14ish, but it’s good to know dynamic navmeshes aren’t required anymore. :slight_smile:

My guess has to do with massive resources hit during the Nav Mesh gen–it’s pretty awesome that anything concurrently works while that is happening, to be fair.

Something that we discovered since this thread was first posted is that the audio thread tasks were reduced in priority in 4.15. This means that audio thread event/messages have to wait in line for anything else that might be going on with the task manager (e.g. rendering navmeshes, etc).

I have a change for an internal game where I made that an engine ini setting and it fixed some less obvious timing issues were were getting in our runtime. You can experiment with this to see if it fixes your issue.

In FAudioThread::StartAudioThread(), change this code:


GAudioThread = FRunnableThread::Create(AudioThreadRunnable, *FName(NAME_AudioThread).GetPlainNameString(), 0, TPri_BelowNormal, FPlatformAffinity::GetAudioThreadMask());


To:


GAudioThread = FRunnableThread::Create(AudioThreadRunnable, *FName(NAME_AudioThread).GetPlainNameString(), 0, TPri_AboveNormal, FPlatformAffinity::GetAudioThreadMask());