The Sounds of Little C

Sunday 9 October 2011, 3:01 pm   /////  

A group of sonic and code explorers has been discovering excellent super-short C programs that, piped to an 8-bit audio device, generate music. Here’s the first video and a second video with sounds and code.

Here’s the code for one example, “Lost in Space,” from video #2:

main(t){
for(t=0;;t++)putchar(
((t*(t>>8|t>>9)&46&t>>8))^(t&t>>13|t<<6)
);}

If you are also a righteous Ubuntu user, you can paste that into a file (let’s call it “lost_in_space.c”) and compile it with:

% gcc lost_in_space.c -o lost_in_space

Then, pipe it (or pretend to pipe it, using padsp, since recent versions of Ubuntu don’t have /dev/dsp) to your audio device using:

% ./lost_in_space | padsp tee /dev/dsp > /dev/null

Thanks to Andrew Stern for tipping me off about this one.

1 Comment »

  1. There’s a third video now: http://www.youtube.com/watch?v=tCRPUv8V22o with visualization! and Javascript examples.

    Comment by Doug Orleans — 2011-10-15 @ 3:08 pm

RSS feed for comments on this post. TrackBack URI

Leave a comment

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2014 Post Position | Barecity theme