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

@gibs, sorry, due to being busy and the forum being regularly offline I did not manage to download your WAV file in time. I just tried, but it is not available anymore.

I have started extending the Gamebuino library with more advanced music generation support. Progress has been promising, and I am happy to share the first results today: Music Demo. It’s still using a bit more CPU cycles than I would like, so my next steps will be to try to optimize it further.

2 Likes

Here is the file again, if you want to try: https://we.tl/t-voxB6eeOVP

Update: I made good progress with my music generation code, and consider it done for now. I added a new instrument, but also made many fixes and improvements. The results can be heard in the updated Music Demo. It includes 17 tracks by 7 artists. In total more than 22 minutes of music. This demonstrates what is possible. If there is sufficient interest, I can add documentation on how to use it.

My next step, however, is to try and integrate this into my Bumble Bots Repair game, so that it features music without having to download separate WAV files. I expect it will be challenge to get CPU utilisation below 100%. I may have to refactor the drawing logic, who knows…

2 Likes

Yes, i haven’t test on my Meta yet but i have look at the code and the music generation.
I like how it’s readable and easy to make.
Many thanks Eriban and of course i could be very interested by a documentation to use it even i think i could quickly understand because source of your program is very clear.
Thanks alot Eriban

for me it’s not work, player lauch fine and respond to key but is not output anything :confused:

Great job Erwin!

The sound comes out great, the bass is a bit weak in volume, but it’s overall a great success!

A technical user guide would be really welcome, of course, but, even more, your next challenge:

Create the composition software that goes with it! :stuck_out_tongue_winking_eye:

Create the composition software can be done one a PC too to make a music.h to integer it in main prog.

Not sure why it does not work for you. Did you check the volume settings? If it is set to “mute”, it will not work.

Thanks Steph. Creating composition software is quite a bit of work, and is not yet part of my plans actually. However, as jicehel alluded, you can already use the PICO-8 software to compose music. It has a built-in composer and I have created an export script to convert PICO-8 music to work with my music generation code. Unfortunately PICO-8 is not free, but I think it’s well worth the fifteen dollars. I have been using it to prototype all my Gamebuino games for example. It also has a built-in sprite and map editor, which lets you quickly try out ideas.

1 Like