Audio Synchronization

Hi, I was wondering if there was an easy way to synchronize music to events in the game. For example, for every bass beat in a song, an enemy would spawn. I have looked at flashAmp, but it isn't free.

The way I'm doing this is simply using the beats per minute of the audio-files and then creating certain events at certain times calculated from the BPM (using AudioSource.time). For example, if you have 120 beats per minute, you have one beat every half-second. From there, you could basically mimic any kind of rhythm. If, for instance, you want something to happen at the beginning of the 5th bar (assuming a 4/4-rhythm), it would be exactly after 8 seconds. It's not too hard to write a little "engine" that handles some of these calculations automatically (e.g. from the BPM). Of course, you might end up writing a sequencer this way ... but for most use cases, you can keep it comparatively simple.

That obviously requires a bit of musical background to be implemented, and it's not the most convenient (or easy) way of doing this - but it works well enough, at least if you don't have tempo-changes in your music.

A good way to implement this could be to use unity's Animation Editor. You could create an animation which matches your audio track, with the animation specifically modifying variables which control when (and even where) your enemies are spawned. You can animate any publicly visible property of a gameobject or component.

For more information, see the Animation Editor Manual Page

Thank you so much for both your ideas!