Intuitively Obvious to the Most Casual Observer

Visualizing audio hacks

The other day, an interesting hack came up on #archlinux:

echo "main(i){for(i=0;;i++)putchar(((i*i>>8&46&i>>8))^i&i>>13);}" |
     gcc -x c - && ./a.out | aplay

It’s a quick one-liner that compiles a simple C program and plays its output as audio. Each byte of output will be treated as a new sample. The interesting part is the C program itself - the ith sample is produced by the expression


(The extra modulus at the end serves to discard all but the low byte.) This simple expression produces some very, very bad music - but my computer standards, it’s quite good, especially when you take into account the simplicity of the generator.

As a way of understanding this (and other simple hacks), I whipped up a simple visualizer, providing the FOutier transform as well as the actual audio.

In addition to the default, and the expressions suggested on that page, you might also try i*i>>11. Some “stable” tones are also interesting, like i << (i%6 - 5).