How can I set up gapless random looping with mutiple sounds?

Hi :slight_smile: My question is one that I have searched for a few days now, and just cannot find the answer I want.
I have a sound cue that has 3 interchangeable sound loops [background music]. The first solution I came across was to have a random loop node that calls the random node in my sound cue to get a random wave file to play, but it has a gap between loops as it says in the soundcue reference.
So that does not work for me, I have also tried doing it in C++, checking for when the sound cue finishes playing, then picking a random node, and telling it to play that. This way also has a small gap between playing.
I need a way to loop my background music, and when a segment (seperate wave player) finishes playing, to choose another segment, and have it immediately play that without any gap between segments. Either C++ or within the soundcue itself would be perfect.

Hey, Iā€™ve got the same problem right now. Either you have your files with a random node and a looping node behind (which results in a gap) or you set your files to be looping but then the random node is accessed only once, so you end up looping the same file over and over again.

How do you actually create random looping ambient sound cues?

The Enveloper Node has indeed a Looping segment, but when I set the Loop Indefinitely flag, it stops looping at all, so either Iā€™m using it wrong or itā€™s a bug. Can you verify this on your end?

Maybe, if this node works, this is the solution to the seamless loop

Sorry, but I cannot get the enveloper node loop at all. I canā€™t find any documentation or examples of how to get it to function in this way.

I just got it to work by specifying Loop Start and Loop End. Also I had to specify the Loop Count and check the Loop flag. If I check the Loop Indefinitely flag, however, it appears to be just a pass through node. So I assume, this is a bug. Maybe one of the staff members reads this. Also I have opened a forum thread about this, but without any response so far.

What did you specify loop start and end too? Is it beginning of song and end of song?

EDIT: When playing around with the loop controls, I cannot get the actual song to loop. Whatever I set the duration ends variable to, simply stops the audio playback alltogether. Iā€™m starting to suspect that this looping fucntion is not meant for looping of the song itself.

I believe, we actually could utilize it for our purpose, if it worked at all, but right now, I guess, itā€™s just broken. Iā€™ve set it to loop the first 5 (so 0 - 5) seconds of a source file and I wanted it to be looped twice (itā€™s indeed independent as long as you leave the loop indefinitely flag unchecked). That worked but for our purpose we need an infinite loop of the source and as it seems that flag isnā€™t doing anyting but passing the signal through the node. Iā€™ve read in another post that this node would do what we need, but I canā€™t find the thread anymore. So, if we get the infinite loop to work somehow, that might be the solution to our problem

I canā€™t get it to even loop 1 time, for any amount of the song.
Loop start: 0.0 Loop End 1.0 Loop Count: 2
Only have the loop flag checked, and the loop indefinitely flag unchecked.
When I play it it will play the first 2 seconds of the song, and the stop playback.
If I change the loop count to 3, it will play for the first 3 seconds of the song, and then stop playback. There is no looping right now, it just plays for a duration of (loops start - loop end) * loop count.

mh, thatā€™s strangeā€¦ maybe they recommended garbage in the other threadā€¦ A friend of mine recommended WWise, there are several free licence forms availableā€¦ maybe an option for you, not for me, however, as my due date is tomorrow

WHAT IF we utilize a switch node and let a blueprint in an infinite loop decide which track to play?

Yes, seems to workā€¦ only barely noticable gaps between the tracks on my side seem to be caused by a not perfectly fitting seamā€¦ if you want, I can send you my blueprint. needs just little setup

Yea that would be good, especially if I can set it up in c++

You should be able to convert my blueprint easily into C++ code. Just write me a pm with your email on the forum, then Iā€™ll send you the uasset

Has this been resolved? I have music clips that loop perfectly in Ableton, logic and Soundfirge as well as unreal but when I try to fire off a random succession of them they click at the start.

Hi there! I managed to do something that works as expected but it requires you to know the BPM and time signature of your music:

I needed to play different music ā€œpartsā€ on different situations but I wanted to randomize some of the layers so that the music isnā€™t always the same (with or without violins or something like that).

The logic is like this:

  • First, you must set a Sound Cue with some random selectors and a switch for each ā€œPartā€ and mix them as you like.
  • Important: each sample must be set to loop.
  • In the Blueprint, you calculate how long in seconds you want each sample to loop by diving 60 (one minute in seconds) by the musicā€™s BPM, then multiplying by the musicā€™s time signature (4/4 would be 4, 5/4 would be 5, etcā€¦) and then by the number of bars you want to loop (a bar is the total number of beats in the time signature or the upper number - [more here][3]).
  • Make sure the Sound Cue is set in the Audio Component and set the switchā€™s param initial value to 0.
  • Play the Audio Component.
  • Call the loop delay, update the ā€œPartā€ parameter and play the Audio Component again with the new part set.

As far as Iā€™ve tested, there are no gaps between each loop.

Hope this helps someone!

Cheers!

I found a number of threads with Epic devs where they say this sort of thing would be hard, because their audio engine was not really designed for sample accurate control from a blueprint level (basically, all blueprint level changes are queued and executed at a per-frame level, meanwhile, most audio is playing through a few thousand samples in that time).

I think they are missing the point that full script sequencing control with seamless audio would be great, but even a simple modifier on the wave player, allowing to specify a loop start and end point, should be simple to implement internal to the wave player, which DOES have sample level accuracy (and uses it already for looping flag), and this alone would probably cover 90% of the cases people are after here. I suspect this might even be a modification I could make myself if I didnā€™t mind having to move to a source build of the engine, but I havenā€™t wandered into the low level audio part of the code enough yet to know for sure.

Regardless, until Epic wraps their head around this one and decides to act on it, I think stgogm has the right idea if you want to generically sequence loops together. But as a vastly simplified version, for example, the case that lead me here, I simply have an orchestrated piece that I want to loop, which has an intro section which should only play once. I produced it as one piece in the DAW, then exported it in two sections. Then, in the sound cue, I added the wave players, with the looping part set to loop. I added a mixer node, and left everything flat. I then added a delay node to the looping piece ahead of the mixer, and set the min and max delay time to the exact run time of the intro. Like this:

This is inspired by stgogmā€™s much more sophisticated answer, which essentially boils down to knowing (or calculating) the exact time of splice points, and delaying the sections so they play in sequence. However, if you donā€™t need to fully randomized sequencing support of his method, and just want a simple deterministic sequence, this above much simpler hack will work. Its the same idea, just that you know the running time of the segments in advance, so you can precompute everything that is being done in stgogmā€™s answer.

this works, but if you need attenuation, the Intro clip will not be played without setting it to ā€œloopā€.
probably this is a ā€˜featureā€™, but i consider it as a unreal bug.