Quantize many SFX events to many musical tracks/different BPMs

In my rhythm-based Unity game, I want enemies to have percussive sound effects that are quantized to a music event’s BPM. I’ve experimented with the nested event solution discussed at Syncing oneshot events perfectly on beat, but unfortunately:

  • I have many music events (with different BPMs), and many SFX events. Adding hundreds of referenced SFX events to all of the music events, and wiring up hundreds of parameters seems to work, but quickly becomes an explosion of duplicated work and complexity as the project grows.
  • For each SFX event, there are several enemies on the screen that should emit the event with correct spatialization. I don’t think I have fine control over the positioning of nested events unless I add yet more parameters.

My dream solution would be some way for Unity to trigger an FMOD event, quantized to an already playing FMOD event, so I can keep my sound effects modular and loosely-coupled. I gather this isn’t straightforward, but is there any workaround, in FMOD or Unity?

For example, I was wondering if Unity’s AudioSource.PlayScheduled() could work for SFX alongside FMOD music playback, just for sound effects that need precision.

Any advice would be appreciated!

It might not be the best to try and control this type of feature from a single event. Instead I would recommend utilizing a custom queuing system together with a music event which is firing off timeline callbacks. So when a sound is triggered you can wait until the appropriate beat is met before actually playing it.

You can see an example of using music beat callbacks in the FMOD Studio API installation’s examples folder.

If I’m understanding correctly, you’re suggesting that I should have Unity use FMOD’s beat callback to conditionally begin playing a new FMOD event. Is that correct?

Can this give me sample-perfect alignment of the audio though? I’m using SFX like a programmable percussion track, where any latency in firing off a new FMOD event has to be corrected for so that it sounds on-beat with the already-playing music. As I understand from Syncing oneshot events perfectly on beat, quantization within FMOD studio achieves that, while triggering a separate FMOD event in Unity does not:

When you play an Event, the command isn’t dispatched until Studio::System::update is called. Processing of Studio update is asynchronous, when this occurs the Event start will be scheduled. Once scheduled the Event will start at the beginning of the next mixer update. These delays and update quantization will likely cause your Events to play out of lock-step with the desired beat.
The easiest way to sync playback is to do it within Studio, via nested Events, you can use the quantization and timeline tempo markers to ensure things are played back on the beat, Internally we take all the delays into account to ensure sample accuracy.

That is correct. I’m unsure of the specifics but I believe there would not be any noticeable delays or going out of sync as long as the events you are firing off on the beats have their instances created already and their samples preloaded.