[Music Lib] Dynamic Music Demo

0
0
Published 2023-06-12


Demo Controls:
Position the pointer in one of the 4 quarters using the arrow keys to change the music.

The music will change depending on which quarter you're in. The check marks in these quarters show which channels are enabled for each quarter.

The changes will go into effect as soon as the pattern ended.

Background Story:
I came up with the idea of having the music chance depending on where you are while still keeping the same song. I quickly ran into an issue. I realized that there was no way to make this happen using just the "music" function.

Later that day I found out about the "peek" and "poke" functions: allowing you to directly read and write to ram. I found out where to find the music pattern section and started mapping it out to get more control over it.

Music in RAM:
Let's take a look at how the music patterns are mapped out in RAM:

As you can see each pattern takes up 4 bytes, 1 for each channel minus 1-bit per channel which is used to store whether or not this pattern is the start of a loop, the end of a loop or simply the end of a song.

Of course writing the code for this is a little tedious. This is where the music library comes in!
enableSalesManVoice()

The Music Library!
The music library is a small library that you can use to manipulate the flow of your music on runtime!

This means that you can for example dynamically chance your music based on where the player is or what the player is doing.

The music library only consists of 6 functions which can be used to manipulate the music patterns. Everything that you can do from within the editor can be done at runtime.

Features:

Changes made to a pattern that is currently playing will only go into effect the next time it plays. This means that you can easily change out the patterns without having to worry about it changing abruptly.

Feel free to use it in your own game!

In case you're wondering, the song is a sped up, edited version of a song I made a few years ago:
https://www.youtube.com/watch?v=W8ZKLQeQOSM