Devlog - Conductor, Music, and Sound
What's the most important thing in a rhythm game? Not actual rhythm gameplay, but the music. Actually, not really; I just didn't know how to start this post.
As this was my first real game project (plus, the game was only meant to be an April Fool's joke), I took to looking online for a solution. This post by Graham Tattersall was a massive help, and I definitely would not have figured things out without it. Having an accurate way to track the current song's position was the first step, and from there, I would just have to figure out some more custom needs. And of course, since that post itself used the code of someone else, I put the source code with all of our adjustments at the bottom of this post.
Looping and Transitions
Songs in Damn Daniel have four different sound files associated with them: the intro, loop, outro, and full track. All songs start with the intro, transition to the looping track, and then to the outro track when told to stop. This sounds easy, but this was so, so annoying.
Looping was easy. Just set an audio source to loop, and it'll loop perfectly. However, this meant that I couldn't just use one audio source and switch the sound files; I'd have to have separate audio sources for the intro, loop, and outro. This also meant I had to track what audio source is playing, and switch any operations to be done with the audio source with it. In hindsight, I didn't even need to separate the outro audio source.
Here's the hard part. How do I switch from the intro to the loop, then from the loop to the outro? Well, I'll just check every frame for when the intro audio source is stopped, and then play the loop audio source. This was completely wrong. The precision needed to play two pieces of music and not have any crackling is a lot higher than the 0.16 second frame window. Thankfully, Unity has the PlayScheduled function, allowing me to very precisely schedule when to play audio. There was another catch to this though, as scheduling a sound to play immediately will also cause a crackle. I solved this by simply offsetting all audio playback by 0.1 seconds, giving the computer time to prepare for the audio. This was the annoying part. Other than that, we're all done!
Saved Times
I think it's really cool when you go to a menu, and the music picks up from where it was stopped before. When switching between songs, I make sure to save the previous song's position so it can be played back later.
Music Responsive UI
I want EVERYTHING to move to the beat. The Conductor script fires off events when a beat passes, allowing me to do anything I want in the code. Usually, I just bounce the element by making it bigger for a few frames.
Normalized Volume
This is really important. I hate when the loudness of a game or piece of media isn't consistent. We normalize all of our songs to -16 LUFS, which I think is a standard? We don't do this in code, but I do have a Python script to quickly note which songs are outliers. I manually normalize all the music using Reaper, applying different loudness levels when needed.
Thanks for reading! I hope this was entertaining or interesting in some way. I might post more things like this on more complicated topics.
The source code of our Conductor script is here. Sorry that it is messy!
Get Damn Daniel: White Vans Adventure
Damn Daniel: White Vans Adventure
An urban stylized rhythm game RPG.
Status | In development |
Author | Stamos |
Genre | Rhythm, Role Playing |
Tags | 3D, First-Person, Unity |
Languages | English |
Accessibility | Configurable controls |
More posts
- Beta 12.2Jun 18, 2024
- Beta 12.1May 31, 2024
- Beta 12 - Weirdo, Save/Load, Inventory, Battle UI OverhaulApr 19, 2024
- Beta 11 - House Redesign, Quality of Life, Bugfixes GaloreNov 26, 2022
- Second Anniversary + 10.2 UpdateApr 01, 2022
- Beta 10.1 - Bugfixing, Polishing, ImprovingFeb 27, 2022
- Beta 10 - Public Launch!Dec 27, 2021
Leave a comment
Log in with itch.io to leave a comment.