This blog has moved

This blog is now at

Monday 1 December 2014

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

No comments:

Commission Music

Commission Music
Bespoke Noise!!