The Sounds of Little C

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.

One Reply to “The Sounds of Little C”

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

This site uses Akismet to reduce spam. Learn how your comment data is processed.