Music Demo

Music demo

![|250x200](upload://lnokyLBSTq6jfBSKtakt9YsgBgM.gif)

I have been working on extending the Gamebuino library with more advanced music capabilities. This demo shows the results. It's only 151 kB in size but generates more than 22 minutes of music.

Controls

  • Play/Pause: A
  • Stop: B
  • Previous: Left
  • Next: Right
  • Toggle Repeat: Up
  • Toggle CPU load display: Down

Music generation

The new music functionality is very similar to that supported by the PICO-8 fantasy console. More specifically:

  • The basic element is a NOTE, which has a wave form, a frequency, a volume and optionally an effect
  • Eight wave forms: TRIANGLE, TILTED_SAW, SAW, SQUARE, PULSE, ORGAN, PHASER and NOISE
  • Seven effects: FADE_IN, FADE_OUT, DROP, SLIDE, VIBRATO, ARPEGGIO and ARPEGGIO_FAST
  • Layered composition: Multiple NOTES comprise a TUNE, multiple TUNES played in parallel comprise a PATTERN, multiple PATTERNS comprise a SONG

This enables very space-efficient music generation. Including the music in this demo as WAV files would require 30 MB of space.

Dynamically generating the music does require a bit of CPU. The CPU goes up with the number of channels that is used. Furthermore, the PHASER and NOISE instruments require more CPU than the other instruments. The ARPEGGIO and VIBRATO effects also increase CPU usage. Nevertheless, CPU usage of this demo never exceeds 75%, even for the four-track songs, so there are still spare cycles that can be used to implement a game. :slight_smile:

Credits

  • “Alex Kidd” songs by Domarius from PICO-8 game Alex Kidd
  • “Bubble Bobble” songs by pahammond from PICO-8 game Bubble Bobble
  • “Bumble Bots” songs by Paul Bonsma from PICO-8 game Bumble Bots
  • “Neon” song by Luca Harris from PICO-8 demo Neon
  • “Porklike” song by Krystian Majewski from PICO-8 game Porklike
  • “Rock for Metal” song by Jumalauta from PICO-8 demo Rock for Metal
  • “Sweet Buns” songs by Krystian Majewski from PICO-8 game Sweet Buns
  • “Techno Utopian Edict” song by Jumalauta from PICO-8 demo Techno Utopian Edict
  • “The Lair” songs by Gruber Music from PICO-8 game The Lair
  • “Wintergolf” songs by Gruber Music from PICO-8 game Wintergolf

Version 1.0

New player UI:

  • Controls for Play/Pause, Stop, Previous, Next and Repeat
  • Show output level
  • Toggle CPU load visualisation

More music:

  • Now featuring 17 songs
  • by 7 artists
  • comprising more than 22 minutes of music
    Note: Some tracks are designed to loop endlessly and end somewhat abruptly if they are not on repeat.

Improved music generation:

  • Add PHASER instrument
  • Improve note blending
  • Improved NOISE
  • Fixed ARPEGGIO implementation
  • Add optional volume boosting

Version 0.2

Demonstrates improvements to music generation:

  • Reduced CPU usage for NOISE instrument
  • Fix bug in SongGenerator that caused occasional glitches
  • Reduced memory footprint and program size
  • Reduced CPU usage by switching to 11025 Hz
  • Increased accuracy of volume and wave index calculations
  • Let octaves start with C note, as is the convention

    See more
3 Likes

Cool
First i can acces to the forum and i see this post. I will have to look this and test. I will have to change sounds i all my games but i was looking for that since so many long.

I don’t know why, I can’t see the icon folder from my gamebuino.
Edit: I have used the one from the binarie folder from the source and it works.
There are some glitches in the music, but it’s impressive !
So the music need to be composed with the PICO8 tracker ?

I am not sure why the icon did not work. I think I uploaded the .GMV file, which displayed correctly on the web, but maybe it needs to be the .BMP file. I uploaded that one now instead.

There are occasional glitches, but I am not sure if those can be prevented. As the current demo hardly does anything besides playing music, the CPU usage is still quite low. It never exceeds 75% so the buffer should always contain sufficient samples. It might be that the glitches are caused by lower-level issues, e.g. interrupt variations. I will look into it though as I continue working on it.

Currently the PICO-8 tracker is indeed be the easiest way to compose the music, as it gives you nice editing capabilities and it lets you directly preview the results. It is hard to compose music by directly coding it, compiling it, uploading it and only then hear the result. If my changes make it eventually into the library, someone might decide to write a tracker on the Gamebuino, but with the relatively small screen, it will still be challenging to make that easy to use. It would be nice though…

For technical reasons, the music implementation for Gamebuino does not fully match that of PICO-8. So ever after composing music on the PICO-8 and converting it to Gamebuino code, some manual tweaking might be needed. To test and refine my music generation code, I plan to port various other PICO-8 sound tracks and will see what can be done to streamline the process.

Just asking, I don’t have a clue of the amount of work : wouldn’t it be possible to write a replay routine that plays Protrackers mods (they are already 4 channels 8bits). The Tracker is available for Windows. https://16-bits.org/pt2.php

and a c++ source replay routine here : http://www.pouet.net/topic.php?which=4832&page=1

I think it should not be that much work to write a script that converts MOD files to my new Gamebuino music format.

However, this does not mean that any MOD file can be played on the Gamebuino and sound similar. MOD files can contain effects and instruments that are not supported by my music generation code (and it will also be hard/impossible to support them all, as the CPU capabilities limit what can be done). Furthermore, even when effects and instruments have the same name, they may be implemented differently, so the sound would not be identical.

Nevertheless, once such a conversion script is in place, you could use such a tracker to compose songs for the Gamebuino. As long as you stick to the instruments and effects supported by the Gamebuino, I would expect this to work pretty well.

For now, however, my focus will be in maturing my music generation code, and make it suitable for use by others.

Ok but the gamebuino is able to play 8bit sounds so would it be possible to play a .mod ? of course the .mod would need to be put in the game directory as the wav file. It’s just a question, I don’t ask you do work on that :slight_smile:

That would be cool if you can explain (kind of tutorial) to bring the music from the pico8 tracker to the gamebuino.

There is a big difference between WAV files and MOD files. WAV files specify exactly each sample that needs to be played. It does not specify anything else. How a MOD file specifies music, in contrast, is very similar to how this is done by PICO-8 and my music generator. It specifies notes, instruments, effects, tracks, which means that it is much more compact. However, it also means that it is much more work to play the music. The player needs to simulate each instrument, calculate the effects at real-time, combine the multiple tracks, etc. This all needs to happen at real-time.

So to play MOD files on the Gamebuino there are basically two options. First, convert the MOD file to a WAV file on your computer (a tracker could maybe do this?) and play the WAV file on the Gamebuino with the existing logic. Or, the second option, use music generation code similar to what I am working on to render the music at real-time. It will, however, then never sound the identical to how it sounds when played in the original tracker. However, the advantage is that the music is then expressed much more concisely. You ideally then do not need to include even the MOD file, but represent it (by running a suitable conversion script) as data embedded in your program.

Yes, once my music generation code is more mature, I plan to also document how to use it, including how to import music from PICO-8.

hi,

i used successfully pmf player on the gamebuino meta, https://github.com/JarkkoPFC/arduino-music-player

not using official library and using fastled for music visualization

here is a bin > http://www.mirari.fr/sZ0t :notes:

Cool new. Playing mod files could be great. I have no time to play with my META atm but you all give me lust to test all that… I think i’ll take some times this weekend to see how i could use it.

Thanks for the info. Finally it was a good idea to ask :slight_smile:
And thanks to Jarkko for making this.

Going to experiment now. :kissing_heart:

Ps: In order to not polute Eriban’s project: