Synchronizing simultaneous and sequential music to create a simple 140 bpm music-loop manager
The Creating a metronome through the precise scheduling of sounds withdspTime
recipe demonstrated how to create a metronome by scheduling when sounds play using the AudioSource.PlayScheduled(...)
method and the AudioSettings.dspTime
value. Another situation when we need to precisely schedule audio start times is to ensure a smooth transition from one music track to another, or to ensure simultaneous music tracks play in time together.
In this recipe, we'll create a simple 4-track 140 bpm music manager that starts playing a new sound after a fixed time – the result of which is that the tracks fit together perfectly, and those that overlap do so in synchronicity:

Getting ready
For this recipe, we have provided several 140 bmp sampled free music clips inside the 04_14
folder.
How to do it...
To create a music-loop manager, do the following:
- Create a new Unity 3D project and import the provided sound clip...