Hello everyone, I am relatively new to the forums but not to game design. I have two questions if anyone would be so kind as to answer. I initially tried to search it myself but I wasnt sure how to word my questions. I wanted to know if there is a way, in Unity, to make a sort of metronome by using the BPM In the BGM of a stage where the player can press a button on the beat to preform an action ala Guitar Hero or the Bit Trip saga? And I also wanted to know if there is a way to make it so, lets say the BGM is playing, then the player presses a button and changes the genre of the BGM without reseting the whole song, similar to how a DJ would switch from song to song. For this I initially thought of maybe having 2 songs with different genres play at the same time but mute and unmute one or the other depending on which genre id like to hear but I figured that would cause lag unless I’m mistaken. Id appreciate any answers.Thank you all for your time.
There will be a considerable lag when you start a compressed audio file playing. But if it’s already playing silently there will be no delay turning it up.
Also you shouldn’t play more than one MP3 at the same time. So I think what you want will only work with uncompressed audio, which takes a lot of memory.
Search the assetstore, I just saw a Solution with multiple Tracks that can be muted, exchanged, … To create a custom Sound. So its definately possible!
Our plugin does that by the way: Master Audio
You can use the AudioSource.PlayScheduled to make sure the music tracks start playing in sync and then simply do a simple crossfade between them. This should work with multiple compressed files so you don’t need to limit your self to uncompressed audio.
Also if you have a metronome that follows the tempo of the track currently playing you can use it to schedule a transition on a beat/bar instead of having all the tracks playing at the same time (will save on CPU)… To do this you also need to use the AudioSource.SetScheduledEndTime function.
This is more or less what Fabric is doing with music transitions.
I only stated the part about compressed audio because some platforms have a hard time playing more than one mp3 at a time. Master Audio does the exact same thing (PlayScheduled).
I wasn’t aware of any platforms that have a hard time playing more than one mp3… it will be interesting to know which ones.
Obviously it depends on the overall performance of the game but I would think that all current platforms supported by Unity are powerful enough to manage a number of them. I wouldn’t be playing the SFXs as mp3s though just music or long ambiences.
Tazman, I read that mobile platforms have difficulty (read “bad on performance”) playing more than one mp3s at a time. I’m just repeating what I heard elsewhere. It may or may not be true, I haven’t tested. I know that multiple streaming songs is definitely bad for performance though.
With iOS specifically, you can play only one compressed audio file using the hardware assisted decoding. After that, everything is played using software based decoding. It is considered a best practice in iOS development to play only a single compressed file for music and use PCM (uncompressed) sound files for sound effects. Multiple compressed files playing with software based decoding incurs significant processor load.
I’m not really sure how Unity handles deciding which file gets to be the hardware assisted decoding and which goes on software when running on iOS, but my workflow involves having “music” and “sfx” separate, with music being compressed and sfx being uncompressed.
Yeah that sounds like exactly what I read. Thanks for looking that up!
So usually I think “layered” music on iOS is probably a bad idea. Either you have multiple compressed files making it hard on the CPU, or you have multiple uncompressed files making it hard on the RAM (and large download size). Lose / lose proposition.
Thanks everyone for the replies.visually the game was going to go down the road of the classic Sonic games in the sense that the background would be colorful and the asthetics in general would be similar to the genesis sprites. I searched the asset store and couldnt find anything that helps me out with the whole metronome mechanic, unless im searching for the wrong thing.