ByteBeat Shell Script
April 28, 2013 in Tutorials
Recently I have been playing around with ByteBeat. You can play around with these in your browser here if you are interested. SuperCollider can also do this as of version 3.5 (although I’ve noticed some differences in the output) if you want more control. I however felt like being able to play with these in a more brute force way: directly from terminal.
Since the workflow for messing with these is always the same I decided to make a little shell script to speed up the process. I’m on a Mac so I have to use sox for playback. If you are on Linux you’d need to change the pipe to /dev/audio or /dev/dsp unless you wanted to use sox instead.
#!/bin/bash
# This script creates and plays a simple ByteBeat
# ARGS
# $1: a string with the ByteBeat algorithm e.g. "((t * 3) & (t >> 5))"
# $2: the name of the file to be creates (without an extension)
###
# make the c file
echo "main(t) {
for( t = 0;;t++)
putchar( $1 );
}" > "$2.c"
###
# compile the source
gcc "$2.c" -o "$2"
###
# play it with standard ByteBeat settings
./"$2" | sox -traw -r8000 -b8 -u - -tcoreaudio
Save that to a file called something like bytebeat.sh and make it executable with chmod 755. after that you can just run
./bytebeat.sh "((t * 3) & (t >> 5))" test
and automagically you get 8-bit goodness right from your terminal. There’s a slight delay between running the script and hearing the output because it needs to compile so I wouldn’t necessarily perform with this (unless you get really good a timing it). Now this could be modified to let you specify the arguments for sox or whatever… but meh. This is just intended as a quick and dirty way to look like you are more of a hacker than you really are.