Worried about that background music eats all of your precious ROM and there is nothing left for the game? Bytebeat comes to rescue :wink: It is generated music based on an algorithm, which normally is an one liner!

The function which generates the music is on screen:


Thats another badge for you for a cool trick!


How did you pick the function?
Did you just choose random bit operations to use or is there some method to the madness?

I bet an LSFR or LCG would produce interesting results :P


@Hanski Source code please!!


Released, “ByteBeat3”. https://os.mbed.com/teams/Pokitto-Community-Team/code/ByteBeat3/

Btw. I accidentally created a library called “ByteBeat”, but I cannot remove it. It can be deleted.


I have not invented that function. It is from http://canonical.org/~kragen/bytebeat/ .

Here is some theoretical background: http://countercomplex.blogspot.fi/2011/10/algorithmic-symphonies-from-one-line-of.html


A bit of a long read but seeing it visualised makes more sense.
The bit about the pitch shifting with multiplication makes sense.
I think it’s probably either a mixture of knowing what some of the operations do and then just trying different numbers or the people doing it know about sound.


Its a really useful technique, I’m surprised I haven’t seen it being used more often. I’ve been using it in an Arduboy game I’m making.

	   playChiptune([](uint16_t t){
		   return t>>5|t>>6|t>>1;


Sorry to resurrect this, but @uXe recently showed me this useful website for testing bytebeat music:


I’m not quite sure how much it correlates to what the Pokitto outputs,
but it seems quite handy if it’s relatively close.


Glad you resurrected this, this freaking blows my mind! I have to read how it works. (Once I’ve been trying to create procedural music too, but on a MIDI level, not soundwave.)

EDIT: That whole website looks awesome.

EDIT2: Alright, goes to my favorites :smiley:


There’s an academic paper (!) you could read about it:



You can hear bytebeat music in my Mars Attack game for Pokitto :slight_smile:


How is it with bytebeat copyright? Such small code can’t possibly be copyrighted, but the emerging result is a quite big piece of art and a lot of effort goes into its creation… so? I’ve seen some licensed CC-BY, but I don’t know if all of these shouldn’t be public domain, just like mathematical formulas. Actually this is nothing but mathematical formulas to me, so I think the result falls under copyright, but not the code. Do you people agree?


It’s a grey area because while functional formulas can’t be copyrighted, things that require a degree of creativity can be, and obviously music crosses the border into the realm of creativity.
And of course code can by copyrighted and patented,
so there’s a grey area of where to draw the line between maths and code.


You might want to have a look at the superformula for a parallel (used for generating images instead of music, covered by a patent).


Patents are a different thing, these can be applied to all kinds of small formulas, but they also have to be explicitly registered and have to go through some manual approvals etc. But this issue definitely covers similar algorithms for visual art etc.

I agree it’s probably a very grey area, but my honest believe is that the formulas can’t fall under copyright, even if they require or spawn creativity – these are both true about mathematical formulas as well. You can probably claim copyright on the resulting sound wave that you generate yourself using your own computer from this formula, but effectively anyone else can do the same and it’s unprovable whether you’ve “stolen” (copied) such music or generated it yourself, so in the result the final music is practically uncopyrightable as well.

Oh well, another copyright headache is coming :slight_smile:


Has anyone came up with some ‘nice’ tunes using this method, I’m hoping to use this to add something to Sensitive, but everything I try just sounds like a room full alarm clocks.


This sounds good, but I have no idea how to convert it from javascript to c…


Anyone able to do this?


Supposing this takes one of the chars (a 8-bit or 16-bit value?) of “6689” depending on the value of t. So the char array index [t>>16&3] is always between 0 and 3.

No idea why exactly “6689” was used?!


If you extend the song generation, you’ll hear this is a loop of 4 parts, 2 identical ones then 2 different ones after and that seems to match this pattern


Need more info:

  • What size are t, x and y? 32-bit? 64-bit?
  • Are they signed, unsigned?
  • What is the type of the result?
  • Is ^ xor or pow in this context?
  • The use of floats is an odd choice, does the behaviour change if you exchange them for their integer equivalents? (3e3 -> 3,000, 4e4 -> 40,000)
  • What were you using to test these? Are you sure it was JavaScript?