[Demo] 1 Channel music from your code

The TeamArg demo is neat as neat, and I would love to have music in Ardu Valley, but space is a serious concern. This got me to thinking about the smallest code I could come up with to play ‘music’ in my game. Behold, the following.

uint16_t l = 0;

void loop() {

if(!arduboy.nextFrame()){ return; }

uint8_t rbt = pgm_read_byte_near(l++);
if(!(l%31) || !(l%15)){
   sound.tone(150 + (rbt*10 % 100),400);  

//rest of game here

It basically steps through your progmem from address 0 and interprets it as a tone. You can adjust the modulo values and the tone range to get different outcomes. Here is what Ardu Valley sounds like with the above code.

1 Like

haha this is a funny idea!
I just imagine some sequential sprites which are simultaneously image and the score. :'D

Holy crap haha, I changed it to the following and it sounds like duelling bagpipes

if(pgm_read_byte_near(l++) > 20 + (l % 28)){
   sound.tone(190 + (pgm_read_byte_near(l)*10 % 100),400);  
1 Like

It’s actually a technique that used to be used back in the day reasonably often. You would just search your compiled code for byte patters than gave you nice music


Wow how cool is that :smiley:
I love to learn from you guys!

This gives cool morbid dungeon crawler music

if(pgm_read_byte_near(l++) > 128 && !(l%12)){
   sound.tone(190 + (pgm_read_byte_near(l)*10 % 100),4000);  

You’d better have a mute option!! Haha!

Actually, I was also thinking about how possible it would be to compile static data in such an order that you could extrapolate a longish melody hidden within everything.

1 Like

If you use the Ardduboy2 library and its begin() function, mute control is built in :wink:

1 Like

it would be easy enough to make a score that is basically pairs of numbers. When your program counter for your tone location is equal to the first number, change to the second number. Obv you would need to do this last thing.

Procedural music is totally a thing! I think it takes some serious musical chops to build something that sounds intelligible to humans. Seen it done in demo scene world right? Do some of those guys publish their music in formula mode I wonder?

1 Like

If you’re interested in this, check here:

We’ve been testing a long time with this, but it’s very hard to get exactable music out of it, although still fun to play with.

Here you can even test online: http://wurstcaptures.untergrund.net/music/

AND when you’re at it, just copy paste this in the “left” box and press generate sound: