Creating music programmatically

This thread is to continue the discussion started in the Bumble Bots Re-Pair thread, regarding Sound FX and Music, which drifted slowly off-topic.

The easiest way to play music on the Gamebuino is by playing WAV files. A drawback is that this requires relatively a lot of storage. One minute of music at the default sample rate, 44.1 Hz, requires a 2.6 MB file. Another drawback is that the samples are only eight bits. Converting an exiting track, which typically uses 32-bit samples, down to use eight bits often introduces noise. A third drawback is that these sound files currently cannot be included with the game when published on this site, so users will have to download and install these separately which is a bit cumbersome.

So, as an alternative one might consider generating music programmatically. Although that definitely requires skill, it is in principle a way to very efficiently encode the music. Instead of storing all the samples, you simply describe how to generate these. The PICO-8 virtual gaming console uses this to good effect.

Unfortunately, Gamebuino does not yet support this. So, @jicehel, that you cannot do this is therefore not caused by lack of skill at your end. At least, that’s not the only factor… :-). The current Sound FX library can be used to generate in-game sound effects, but is not powerful enough to create music. It might be used as a basis, but more is required.

So what is lacking? PICO-8 can be used as an easy reference. First, the current sound effects are a bit limited. The library currently only supports square waves and noise. The latter is mostly useful for creating sound effects (e.g. crashes) but not so much for music. Adding more wave forms would make it easier to create different instruments. Also, support for extra effects (slides, arpeggios, etc) would help.

Second, the sound effects currently only have one channel. Starting a new sound effect while another is playing cuts of the latter. Multi-channel playing of Sound FX is required to give each instrument its own channel. A challenge will be combining the various channels. You do not want distortions when they are all loud at the same moment, but you may want to avoid unnecessarily limiting the volume of the individual channels beforehand.

Third, you need a higher-level language that allows you to describe the musical composition. E.g. loop this bass track for four bars, next switch to this track for two bars. Meanwhile, the melody line will play these three bars, then repeat. Etc.

Unfortunately, my musical skills are quite poor. Nevertheless, writing the above down does make me wonder what is possible on the Gamebuino. If I find the time, I may have a go at trying to programmatically reproduce the Bumble Bots sound track created by my brother.

Anyway, has anyone already tried to programmatically create music on the Gamebuino? Or experience with creating 8-bit music? Any thoughts or ideas?

Btw, I created two pull requests for my fixes to the Sound FX library: PR #43, PR #44. Let’s wait and see if these get accepted.

1 Like

Great, i made music on Gamebuino Classic and with Arduboy.
I hope that your fixes will works and more than all, a good tutorial to make it.
I all cases, thanks alot Eriban for your works in this domain.
Its one of the inexploited capacity of the Meta.
I hope that for some of us, there will be more time with confinment.

@jicehel wich tool did you use to make music ?
is it possible to use atmlib on gb ?

To make music on classic i define const for notes and enter value for blanche, noir, ronde duration. It was really old school music. The had thing is to continue to play music and maintain the game running…
It was easy to play music i have had problem when i tried to combine the music and the game as i managed it manually.
I don’t know but i think you can manage ATMLib as @Sorunome managed it when she done Arduboy crosscompiling (Arduboy crosscompiling -- By Sorunome).
She done it:

I have not looked more on her works so cant say more about it. If she read that, i hope she will answer better than i can.

The ATMLib port doesn’t do any audio stuff, it just adds dummy functions for that to make sketches compile, sadly.

So i can’t answer but a library seems good i think: https://github.com/nathanRamaNoodles/Noodle-Synth
It seems to be a fin add. What you think about it ?

Another option is GBTracker : if somebody manage to get it work (on the Meta)

http://legacy.gamebuino.com/forum/viewtopic.php?f=12&t=3435

Yes it’s great. We could at less do same than classic with META. We had discussion about that long time ago here: Music examples for original gamebuino - By exocet
In other subjects to resume the answer was to play wav or sound fx

@eriban

I must admit that I have some problems making ALL my 22KHz conversion working with the gamebuino.
Can you confirm that this track works for yo without bringing any modifications ? https://we.tl/t-3uuy6G5FZU