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 {


Published by

Charles Céleste Hutchins

Supercolliding since 2003

Leave a Reply

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

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