Music Syncing: Please help!

I’m making a 3D puzzle game about 3 machines that dream of being musicians. Music is important to the theme.

Each character has their own theme song and as you progress through the game I add more tracks to their theme song. All tracks must sync up or the song sounds like garbage. Also, there is a constant bass that acts as the through-line, so when you switch between the different machines the bass needs to remain consistent. Here’s a video where I’m cheating to jump around different points of the game. I’m exiting out to the menu each time, but you can imagine if you are playing and moving right from one level to another then the music would build into a full composition.

https://drive.google.com/open?id=1jDR5uTuRYLfL8m5HOXG-8oIF4imzwika

My current solution involves having 1 sound cue that has 40 sounds all set to “virtualize when silent.” I’m blending the tracks up when I need them. This keeps everything in sync (theoretically) but I suspect it isn’t very performent. Also, when all audio is complete I expect to have about 70 tracks so I don’t think this is sustainable.

I thought I’d try just switching between sounds rather than having them all playing and set to virtualize when silent, however I can’t find a way to do that. If I stop playing a sound and I use “Play” for an audio component the “Start Time” seems be ignored. I’ve used some print strings to verify that no matter what I enter when I use “Play” on an audio component it will always play from 0.

Is there any way to alter the playback start time? Am I approaching this all wrong? I’m starting to feel really helpless. I want to play around with the visualizing sounds at some point, but I can’t even get the basics to work right now. (Also, this is an entirely blueprint project.)

Hi @diregoldfish,

A couple of questions:

What version of UE4 are you using?

Are you using the New Audio Engine?

Are any of your music SoundWaves set as Streaming?

Have you watched my video on creating a complicated interactive music stitching system?

In your Project Settings, go to Audio > Quality > Quality Levels > 0 > Max Channels, what is it set at?

What about Max Channels on your specified Platform? (Windows or whatever) What is it set at?

Hi!

What version of UE4 are you using?
4.18

Are you using the New Audio Engine?
Yes

Also, everything is syncing as is right now. I had already upped my max channels to 100 in order to get this to work. The problem is that I can’t ship a game with 100 sounds visualizing while silent - that is just too many!

I hadn’t seen your video, but I just skimmed it and it looks like my plan is very similar to yours. I was breaking the music into clips that I can fade between. The difference being that the nodes you are using wont work on my version of unreal. “Start Time” isn’t working anymore fwict. I was contacted by another friendly Epic dev on twitter DMs and it looks like this bug is what is holding me back:

That said maybe if I use the “Fade In” node you are using rather than the “Play” node I can get around this? Maybe the bug doesn’t hit that node? I’ll try it when I get home after work tonight.

The project for that stream was built in 4.19, works in 4.20, and I recently tested it in 4.21.

So Start Time should work now.

For your case, I would build a little stem manager and use the Wave Param node to pass stems in and I would not do any internal looping (kind of like my Ambient Music demo later on in the stream). Then I would be maybe playing a handfull of stems at any given time and I would just reuse the same two SoundCues to alternate between them.

Thank you for the guidance! I’ll watch the rest of your video, try this out tonight, and let you know how it goes.

You can download the project file from this post:

https://forums.unrealengine.com/unreal-engine/events/1455337-unreal-engine-livestream-building-a-music-system-in-blueprints-apr-5-live-from-epic-hq

The setup and approach might be different than you’re used to and I don’t expect you to duplicate this exactly; but rather give you some ideas on how to build a music stitching system in BP.

Okay, sorry for the delay! I updated to 4.2 just to make sure we are on the same engine… and that broke a few animation things & made my post proc look terrible. I had to spend a few hours of just updating stuff.

I see what you are doing based on the project files, and after a bit of banging my head against the wall I think I can do something similar in my project. The key is to never have a music file (Cue or sound file) ever set to be looping. If something is looping then the Start Time input is ignored. With your system there is no need to loop animations, you are manually handling the looping (at least I think so based on what I am seeing.) I think I can get this working now.

Your blueprint is very well organized and neatly laid out. Thank you Dan! :slight_smile:

edit: I realize my post just echoed what you said earlier, but more rambling and stupider. Sorry man, I’m tired :stuck_out_tongue_winking_eye:

Start Time works whether the sound is looping or not. The only time Start Time doesn’t work is if you have a Streaming File.

What you experienced before was a bug that has been fixed since your version.

With my BP you can do loops or no loops, but you can get looping behavior without marking the file as looping because it can handle looping behavior at a higher level.

The Kite Music Demo uses looped SoundWaves if you want to use looping.

Heh, sorry for the weird hours, I just got home.

I would love to set the files to loop as that would make my scripting solution much much cleaner. However, I’m still noticing that if a sound is set to looping the start time is ignored in the “Fade In” blueprint node.

Here’s a quick video:
https://drive.google.com/open?id=1xB…FrCoD7mK6jo3mW

Interesting.

To be sure, I just tested both SoundCues and SoundWaves using Fade In with a variety of Start Times both Looping and not Looping and verified Fade In Start Time is working. And it should because in the code, Fade In just calls Play with a Volume Adjustment from 0 to your input level. To simplify the problem, I tested it with these two very concise cases:

To more closely mimic your scenario, I used a Wave Param node in the SoundCue and passed my SoundWave in directly. Again, both Looped and non Looped worked.
[HR][/HR]
I’m not sure how different your Music Manager is from mine. In my General Music Sequencer, I use a custom struct called a Music Clip which allows me to define whether or not the sound is supposed to be looped.

If you look at the Kite Music Sequencer child object, you’ll see I have a custom defined array of Music Clips where I define which of the Music Clips are meant to loop and which are not. I do this because looping behavior is unclear in SoundCues (whereas it’s very clear in SoundWaves) so I can’t query the USoundBase variable “Music” in the Music Clip reliably. There is a lot of other data in there that I add manually, one of the reasons is that I can’t retrieve duration values from a looped SoundCue because they just return 10,000 seconds.

In my Calculate Start Time for Next Transition function, I attempt to calculate the transition time of entry into the next clip. If your implementation is similar or based off of mine, this is where I would look for bugs (because this is the scariest part of the script, certainly the most delicate).

If you’re updating your implementation based off my script, then it’s worth noting that one of the assumptions I made in my General Music Sequencer, which for your case, might be something to modify (or maybe you already have, depending on how much of it was used for you), is that a music clip that is not looping (bLooping FALSE) is uninterruptible. Which I did as a convenience (or rather to simplify the music transition problem space somewhat).
[HR][/HR]
However, if you’re experiencing a bug with Fade In with my above BP examples, then there definitely is a problem. I always try to make my tests as clear of extra bits as possible when isolating an issue, so on my end, it appears to be working correctly. So let me know if you’re still seeing this behavior on these simpler cases.

Thank you for your write up, but I feel like there has to be something different between our projects. Even the simplest examples of trying to set a start time on a looping SoundWav doesn’t work for me. Here’s another video for you:
https://drive.google.com/open?id=16v…dgrKOAIeDrLOD_

I don’t have streaming on for the audio file. I don’t think it is set anywhere (is there somewhere I should look to verify I’m not streaming in audio?) …I don’t know why this doesn’t work for me and clearly does for you. There must be something really obvious that I am missing!

Here’s the map, actor, and audio file that I used in the video. I’m on the latest version of ue4 atm.
https://drive.google.com/open?id=1mT…t-Qb-sfeD82Yb_

I think I see the misunderstanding. I thought you were saying that the sound itself doesn’t start playing at the Start Time, but in your latest video you’re talking about the Playback Percent starting value.

However, I’m even MORE baffled by your bug because Playback Percent doesn’t account for Start Time.

It is a known bug that Playback Percent doesn’t account for Start Time.

In fact, I mention that in my Live Stream and account for it in my Calculate Start Time for Next Transition function:



This is a bug that we haven’t gotten around to addressing yet.

Testing this on a 4.20.1 Project, my Playback Percent always starts at 0 no matter where in the file I start playing, looping or not looping. Which means I’m super confused why your version is ever right. D:

Out of curiosity, do either of the Music Sequencer Levels work in your project? I would expect it to break for non-looping Music Clips.

Very strange!

I probably can’t get back to this again tonight, so I’ll have to follow up tomorrow morning with any further tests, but just FYI:

I am not just talking about the Playback Pct. I didn’t include the audio of the game for some reason, but the audio in that video was also starting from the beginning when the playback was starting from 0. I promise you the audio is not starting from the input start time on my version of ue4 when it is set to looping. On my computer the playback pct is always matching the actual playback of the file. When the playback pct is 0 for the looping animation I’m also hearing the audio file start from 0.

I did steal a bit of time at work and did a test test on my machine here at TMF. TMF is on UE4.19 atm and I am experiencing what you describe: If I play a an animation the start time works regardless of if the file is looping or not, and the playback pct is always 0 initially.

Something is clearly wrong with my build at home. Its possible that looping is broken on the very latest engine build… but I’m guessing that might not be the case since you tested that with your project already. Maybe there is a project setting somewhere that is changing things or something… I don’t know much about audio, but is there any variable that would set all audio files to be streaming globally? Or is there any other variable that might be flipped which would result in the behavior I am seeing?

I’ll dig more tomorrow morning and report back. Thanks for the continued support!

I don’t think the issue is Streaming.

Is your build from the Epic Games Launcher or from Github?

Epic games launcher.

This is embarrassing. When I updated the engine I never updated the ini file to use the new audio mixer. I checked that the plugins were set, but I forgot to check the ini.

Sorry for dragging this out, and thanks for helping me think through this.

When you open your project. In the Output Log, if you filter search AudioMixer, do log entries come up? Usually after loading the project with the Audio Mixer enabled, it will give you details on your audio device with AudioMixer as the log tag.

This is just to verify that the Audio Mixer module is loading.

Also what platform are you developing on (running the Editor on)? PC or Mac?

EDIT: Didn’t see your last post as it was on the second page. That was the next thing I was going to check! :slight_smile:

I’m glad you got it sorted out, your game looks like it’s trying to do some cool things and I hope the Audio Mixer can help with that!

It’s also interesting that the Audio Percent Playback delegate works without the Audio Mixer, probably not on every platform though. Running with the Audio Mixer should increase your accuracy. But you will want to compensate for that one bug I mentioned earlier.

Hi @dan.reynolds, thanks for all your work on this!

I’m having the same ‘bug’ with Playback Percent, that when I play an audio file using Start Time, the Playback Percent always begins at 0. I’m confused how you’re accounting for this?

I’m creating a real-time cross-fading system that switches between tracks immediately, without waiting on the playing clip to finish, and have to know how far along a particular clip is.

Any further help is appreciated!

The bug is that the playback percent doesn’t know that you started in the middle of the file.

So your offset is your start time. If you start 50% into the file, then your offset is 50%.

Then when you’re checking your playback percent, you add your offset to whatever the value is.

So how would I start further down the file for a streaming file? I want my music to be streaming but the track should not start from 0 every time.