Bytebeat - Overview and How To Make/Record on OSX

“Bytebeat” is the name given to the method of piping mathematical equations to an audio device make lo-fidelity gritty sounds. They often sound pretty musical due to the mathematical nature of the equations and bitwise operations. But that does not mean that it has to be “musical” to be good either, as you will discover when messing around with it.

For a good dive into what Bytebeat is and how it started, check out these links:

Examples:

How To Make Your Own

A fantastic how-to of the basics including the math operations and how to use them can be found in PDF at TuesdayNightMachine’s Github page. I would highly recommend starting here if you don’t get binary or bitwise operations.

The super simplest way to implement and test (hear) Bytebeat code is through the many online HTML5/JS apps online.

Making It Offline On OSX

My desire when starting to mess with this stuff was trying to figure out how I could do it in the command line, as that was how I had seen it laid out in many examples in Linux. The problem was that the built in tools to pipe data into your audio device was not built in to OSX the way it is built in to Linux, so I had to do some sleuthing. With a lot of help from the Merveilles community, I was able to finally figure out the process and I wanted to document it here.

Step 1. Install SoX with homebrew

brew install sox (you can follow this tutorial here if you are confused)

Step 2. Create a bash script to automate the build, compile, and piping of your Bytebeat formulas all on the CLI.

The way that I did this was pretty much completely stolen from Cole Ingraham’s post that I dug up on archive.org. Essentially without this, you have to do quite a few very boring and uninteresting steps which means very little instant gratification, which is what we want.

Here is the script that I created for using it in bash on OSX:

#!/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)
###

# create the C program
echo "#include <math.h>

int s(double num){
    return 256*sin(num);
};

int c(double num){
    return 256*cos(num);
};

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 -t u8 -r 8k -c 1 - -d

Take this script and copy it into a code editor/text editor, saving it as a file with an .sh extension (I called it bytebeat.sh). Put it in a folder where you can access it easily with the command line in your terminal. There you will be able to make the audio using the arguments written in the script. But before that,

Step 3. Turn down your volume!

Trust me, it’s LOUD. Don’t forget!

Step 4. Try it out!

Once you have saved that script and you have navigated to the enclosing folder in your terminal, you can make some noises! Your script takes two arguments:

  1. The Bytebeat algorithm/equation
  2. The name of the file that will be gnenerated and played (can be whatever, I usually go with test)

For example:

./bytebeat.sh "(t/4)*(t>>8|((14 & t)^3))" test

This runs the bash script (bytebeat.sh) and uses the Bytebeat algorithm/equation "(t/4)*(t>>8|((14 & t)^3))" to generate the compiled C program test. This program test is then piped into sox and plays through the speakers. You’re done!

Record it!

There are two ways you can save the audio you’ve created. One is fairly user friendly and the other one is a bit clunky.

The easiest way is to download and install Rogue Amoeba’s Loopback to record your system audio. THis is very simple and highly recommend it.

If for whatever reason that doesn’t work for you, you can create a raw audio file on your computer and use Audacity to open it. This may not output exactly what you heard when playing it using the bash script, but it may yield some cool variations.

  1. Run your script to create the compiled Bytebeat script (give it a proper name instead of test if that’s easier to find). Within your folder, you should find a file of that name.
  2. Send the output of this newly compiled script to a file instead of piped to SoX. (NOTE: This can create endlessly large files on your computer and possibly eat up all empty memory if you don’t stop it quickly. To avoid this, cancel (ctrl + C) the process around a half-second to a second after you start it.) To do this, write this in your shell, assuming your newly compiled file is called test and the output file is called output.raw: ./test > output.raw
  3. As said before, you will want to cancel this process very quickly after you start it with ctrl + C, as it can otherwise create a massive file.
  4. Open Audacity. Select File > Import > Raw Data... and choose your newly output file (output.raw in our example). Use the following settings in the dialog box:
    • Encoding: Unsigned 8-bit PCM
    • Byte Order: No endianness
    • Channels: 1 (Mono)
    • Start Offset: 0
    • Amount to Import: 100
    • Sample Rate: 8000
  5. Listen to your hideous creation.

Other Resources/Implementations

· Send me your thoughts