Glitching Sound: how to data bend with imagemagick

Inspired by Antonio Roberts’s excellent tutorial on how to databend with Audacity, and following on from my previous tutorial on how to data bend audio, this post explores how to glitch audio using image software. Many of the required tools use the command line. This will work with linux, unix and mac. If you want to use windows, you will need to edit the autobmp.sh bash script so that it does not use the /tmp directory.

You will need

  • The autobmp.sh script
  • Imagemagick (You probably already have this if you use linux.)
  • BASH (you already have this if you use linux or if you have a terminal on your mac)
  • A utility to convert between audio formats that supports the .au format. I use sox, which is cross-platform and available via apt-get.
  • Audacity

Why these formats?

.au and .bmp are both uncompressed formats, so every sample of audio becomes the R, G or B value of a pixel. AIFF and WAV files are also uncompressed, but the files have more structure to them that is not sound data, so .au seems easier.

Getting Started

10 seconds of a sawtooth wave

Using sox to convert between uncompressed audio formats is really easy. To convert a file called foo.wav to an au file, you would just type: sox foo.wav foo.au  It looks at the extension and does the right thing.
Put the script in a directory in your path, OR just put it in your current working directory.
Once you’ve got foo.au, to convert it to a bmp, you’d type: ./autobmp.sh foo.au foo.bmp  This will give you a file called foo.bmp, which is the bmp image of your audio.
Let’s say, you’ve done a bunch of transformations and now have a file called bar.bmp. To turn that back into audio, you would type: convert -depth 16 bar.bmp rgb:bar.pcm  It is now back in an audio format, but the header has gotten slightly tweaked, so we’re not done. Open Audacity, and under the File mean, select, ‘import’ and then ‘raw audio’. Pick bar.pcm in the file chooser. On the popup window, tell it that the file is ’16-bit linear’ and ‘little endian’. There will be a few samples of crap at the beginning of the imported audio. That’s what’s left of your old .au header. you can delete it if you want. there will also be a bit of silence at the end of the file. This was padding added to make the image rectangular. To convert this into AIFF or WAV or MP3 or whatever, select ‘Export’ from the file menu.
If you have ended up with a different image format, such as jpeg or whatever, you don’t need to first convert back to bmp. To get from baz.jpeg back to audio, use convert directly and carry on as above. convert -depth 16 baz.jpeg rgb:baz.pcm

What to do while it’s a graphics file?

This is the creative bit! Converting to a lossy graphics format, such as jpeg adds some noise, so that might be fun. If you do that, you can glitch the jpeg by opening it in a text editor and doing a bit of typing at various points in the file. This causes weird visual distortions, which will become audio distortions when you convert back.
You can also try opening the graphics file in a graphics program. Some of the graphics effects may make interesting sound changes, although many won’t. Experimentation is needed. You can also try drawing on the image. Wide lines of a solid colour will create weird DC offsets, so if you want to avoid that, consider either using very thin lines or else setting an opacity of under 100%.
Have fun!

Music commissions make great gifts. Order now for this holiday season!

How To Data Bend

I got email asking me how to do data bending for audio. (If you want to know how to do it with images, check out Hello Catfood’s posts.) Databending means taking one kind of data and using it as another kind of data. For example, playing an image file as a sound. Or processing an audio file with an image program and then returning it to it’s audio format. This post will focus on how to open non-audio files as if they were audio.
There are two different programs I’ve used for databending. One is Sound Hack, which is free, but mac-only and the other is Audacity, which is also free and cross-platform. For mac users, I suggest running 1.2.6 instead of the beta version.

Data Files

Opening data files with either Sound Hack or Audacity is easy. A data file is a file used by an application, for example a text file created by Word or Open Office or an image file or anything you might find in your Documents folder. With Sound Hack, under the File menu, select “Open Any” and pick a file. The go to the Hack menu and select “Header Change.” You can try a few different headers and listen to them until you pick one that you like. Once you’ve found a good one, go to the File menu and select “Save a Copy.” That will open a new dialog. At the top is the file name. Add a “.aiff” (without the quotes) to the end of the file name, no matter what you decide to name it. At the bottom, make sure to set the Format to “Audio IFF” and the Encoding to “16 bit linear.” I’ve found that Sound Hack does not save reliably into other formats.
To open a data file with Audacity, under the Project menu, select “Import Raw Data.” Pick the file you want to open. A dialog will pop up asking what header you want. I usually go with the default values, but you can try playing around with that. You can then modify the file with Audacity, using the Effects or whatever. When you think you’re done, first go to Preferences and then go to the File Format tab. Make sure that the format you want (Aiff, WAV, etc) is selected. Then, go to the File menu and “Export As” that file type.

Applications

You can also open applications as audio, but this is a bit weird on the mac. Go to the finder and find the application you want to open. Control-click on it. (by holding down the control key as you click). In the menu that pops up, select, “Show Package Contents” A new window should open with a folder in it called Contents. Open that folder, and you should find some stuff in it including a subfolder called MacOS. In that folder, you’ll find, probably, a file with the same name as the program. Like in Garage Band, under Contents/MacOS/ there’s a file called GarageBand and two other files, all of which may be interesting. Control-click on the file and select “Open With”. Then select “Other . . .”. A new dialog will open. In the Bottom part of the window, change the menu from “Recommended Applications” to “All Applications”. (Do NOT check the box under that!) Then find Audacity or Sound Hack, select it and click the Open button. If you use Sound Hack, you can try out different headers, by doing a Header Change under the Hack menu. Save these files is the same as described above.

Examples

I haven’t used this technique for years, but if you’re searching for examples of how it sounds, I’ve got some pieces. My supervisor, Scott Wilson, also uses this on his CD Muellmusik, in the track Photo Shopped Music. Other examples abound. You’ll find that if you do this a bit, you’ll not only be able to recognize other people doing it, but also sometimes be able to recognize what kind of file they’re using. Stochastic Synthesis also sounds quite a lot like data bending.

It’s Alive!!

Remember, back in 2004 – 2005 I was working on the SuperCollider tutorial of doom? It was going to be my thesis, but, alas, it was not meant to be.

It turns out that writing tutorial chapters is actually a great way to procrastinate. It sort of feels like I’m working on music, but without actually making any sound (alas, this has a lot in common with certain pieces I’m writing). So the project is alive right now.
If you are interested in alpha-testing these chapters as I write them, please leave a comment. The intended audience is people who have never programmed before (and MAX users). If you have never before used SuperCollider in your life, I have the tutorial for you! Or, if you’ve tried and become confused. Or if you just want to see a different way of approaching the language.
Alas, most music professors have never taught (or taken) a regular computer science class. My goal is to convey all the important CS concepts, but in a way that’s immediately useful to musicians. Hopefully, if you follow the tutorial, at the end you’ll not only be able to make some cool sounds in SuperCollider, but you’ll be able to quickly grasp other object oriented languages, like Java (which is actually a very useful second language for SC programmers who want to add visual components to their work).
I’m re-writing them to be more sound focussed than last time. I’m starting users with Pbinds, which are a way of handling note creation and timing and are fast and easy despite being kind of weird. So I need n00bs. Pass it on.

Tutorials

The world has been crying out for my old SuperCollider tutorial. Well, not crying out, exactly. Some of you may recall that I had the idea of a doing a tutorial as a thesis project. My advisor said it was disorganized and error-riddled, and so the project was abandoned. However, some stranger on the internet convinced me to send it to him.
This stranger was my host for my first two weeks here (the house with no hot water). His name is Jeremiah and he’s cool. Anyway, he told me that he liked the tutorial and I should put it on the internet. So here you go. It’s incomplete and disorganized. The errors aren’t serious. (Lines of code are separated by semicolons, not terminated: that means that the last line in any block doesn’t need a semi colon, but can have one anyway if you want. Blocks are not defined by parenthesis, but rather by curly brackets or by highlighting code with the mouse. These are the two most glaring errors. All the examples should work.)

Edit

Tutorials have moved to http://www.berkeleynoise.com/celesteh/podcast/?page_id=65 . Please update your links.