Working bmp converter

This is fun you can try at home, if you are on a unix or linux system or on OS X. You must have imagemagick installed, as well as the bash shell. For best results, install sox also.

This script has just been shown to work and prints out too many debugging statements and deals with a weird bug in bash on my system. Cut and paste the code at the bottom and save to a file called

  1. Open your favourite audio tool, such as audacity and generate a sawtooth wave.
  2. Save it in the same directory as the script as a wav file: saw.wav
  3. Open a terminal, and cd to the directory you saved your wav file in
  4. Type sox saw.wav
  5. Type
  6. Open in an image viewer. Isn’t it amazing?
  7. Type convert saw.jpg
  8. Open saw.jpg in a text editor, like emacs
  9. Scroll down to random points in the file and type a few characters. Do this a few times.
  10. Save the file as glitch.jpg
  11. Open glitch.jpb in an image viewer. Isn’t it amazing?
  12. Type convert glitch.jpg -depth 16
  13. Open audacity (or your favourite robust audio editor) and tell it to import raw data (under the File menu in audacity)
  14. Treat the data as 16 bit little endian
  15. Play it back. Isn’t it amazing?

You get a little glitch at the start of the file, whenever you import an au file as raw data. That’s the au header. You can delete the glitch and re-save. There is probably an automated fix for this, but there aren’t enough hours in the day. You’ll also get a little bit of silence appended to the end of the file. This is so the number of samples makes a square image size for the bmp.
Try out other ways of messing with the image, such as drawing on it, especially with less than full opacity or otherwise transforming it. Have fun times! The script is below the sales pitch.
I figured out how to do this and posted it here because I was commissioned to write a noise piece. When you commission music, you not only cause a new piece of music to exist, but you might cause some new tools to become available to other composers. Music commissions make great gifts for birthdays or other holidays. Order now to make sure your commission arrives in time for Christmas or Hanukkah.



size=`wc -c $1 | cut -f 1 -d ' '`
ints=`expr $size / 6`
root=`echo "sqrt($ints)" | bc`

echo "$x x $y"
squared=`echo "$x * $y" | bc`
    echo "squared is $squared"

while [ $squared -lt $ints ];do
    x=`expr $x + 1`
    squared=`echo "$x * $y" | bc`
    echo "squared is $squared"

echo "expr $squared - $ints"
diff=`expr $squared - $ints`
diff=`echo "$diff * 6" |bc`

echo "diff is $diff"

base=`basename $file`
temp=`echo "/tmp/$base"`
cp $file $temp

truncate -s +$diff $temp


echo $size
command=`echo "convert -size $size -depth 16 rgb:$temp $file.bmp"`
echo $command

Broken bmp converter

I’ve spent all evening trying to convert from .au files to bmp, and I’ve realised I’m really doing this the wrong way. This realisation partly brought about becase the conversion is obviously not working. The images are kind of pretty, though, so I thought I’d post the script. It runs in Processing, which is a simplified version of java.
How this code works is that it opens a file dialogue, in which the user is expected to select an .au audio file, but it doesn’t enforce this, so try data bending any file if you want. It then prints the file out onto the screen as if it were made up of integers giving pixel colours. Then, it saves that as a bmp.
What it should do is just put a bmp header at the top of an existing file, but I thought I was being smart.
the code is below. This was developed for a new commission I’m trying to get done. Hopefully, I’ll sort this out properly tomorrow, or if not, it will have to wait for the next digital commission (which could be yours!).
Commissions make excellent gifts! Order now and delivery is guaranteed in time for Christmas or Hanukkah.

// look at au header
// get the offset (32 bit word #1 (starting from 0))
// get the size (32 bit word #2) -- nevermind that
// set the sketch to that size, roughly square
// write from the the offset to the end to all the pixels
// save as bmp


int x, y;
long length;

DataInputStream din;
FileInputStream fin;

String name;

void setup()
  x = 100; y = 100;
  size(4410, 600); // 1 minute
  selectInput("Select a file to process:", "fileSelected");


void fileSelected(File file){
    try {
    //File file = new File("/home/celesteh/Documents/inProgress/shorts/rh/auToBmp/data/");
    name = file.getName();
    fin = new FileInputStream(file);
    din = new DataInputStream(fin);
    din.readInt(); // magic number
    int offset = din.readInt();
    int skipTo = 16;//offset-8;// (32 bits + 32 bits) / 8
    length = file.length() /*864*/ - skipTo;
    length = length /4; // 32 bit ints
    float root = sqrt(length);
    x = ceil(root);
    y = floor(root);
    while( (x * y) < length)
    frame.setSize(x, y);
  } catch (IOException fe)
  {  exit();


void draw() {
    int b;
    frame.setSize(x, y);
    if (din != null) {
      try {
        for (int i = 0; (i < length) && (i < pixels.length); i++)  {
          pixels[i] = din.readInt(); //readByte();
          //din.readByte(); din.readByte();
      } catch (IOException fe) {
      } finally {