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!

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 autobmp.sh

  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 saw.au
  5. Type autobmp.sh saw.au
  6. Open saw.au.bmp in an image viewer. Isn’t it amazing?
  7. Type convert saw.au.bmp 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 rgb:glitch.au
  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.


#!/bin/bash

file=$1

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

x=$root
y=$root
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"
done

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


size=$x
size+="x"
size+=$y

echo $size
command=`echo "convert -size $size -depth 16 rgb:$temp $file.bmp"`
echo $command
`$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


import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.DataInputStream;

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");
  frame.setResizable(true);
  noLoop();

}

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

  
  //redraw();
  //redraw();
}

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

    }
}

How do commissions work?

Let’s say your friend has a birthday next week. Would I be able to do something? How does the commissioning process work?

  1. If your delivery date is less than two weeks away, please contact me before ordering. Depending on my schedule, etc, I will probably be able to accommodate you, but it’s a good idea to make sure!
  2. You would then order the commission and I would get to work making it. Do you want a physical CD posted to you or not? When you order, check that you’ve picked the right item in the shop. One comes with a CD. The other doesn’t.
  3. Within a few days, I will send you via email a link to a high quality audio file.
  4. After you listen to the file and decide on a tile, you would send me back the title and dedication.
  5. If you ordered a physical CD, I would then post it to you via first or second class post.
  6. If you would like an MP3 with the correct metadata (including title, etc), I can send that to you via email.
  7. I normally would then post the audio online to my website. However, if this is a gift, I’m happy to hold off until after you give the person a file or disk. Or post it right away so you can link them to the site. Whichever works best for you!

Commissions make excellent birthday gifts. In fact, this is the most popular use of commissions! However, they can also be used to mark other dates or events, like the holidays! Although I can usually do last minute commissions for birthdays, with larger holidays, its safer to plan in advance! If you order in November, delivery is guaranteed in time for Hanukkah or Christmas!

Do you love noise music? Do you have fashion? Drop me an email if you’d like your image to be in forthcoming posts about noise and fashion

Holdays!

Really really really the wrong bicycle for touring

I took most of this week off. I went to the New Forest with my puppy, my wife and a couple of bicycles. She rode my touring bike and I rode my delivery bike, with a dog trailer attached. The kit I was carrying definitely outweighed me. Fortunately, the New Forest is only slightly hilly.
It is full of wild horses! These are not like the wild Mustangs of Nevada, but are sort of fat, large ponies that mill around and eat, but they very nice looking and unafraid of people. This is probably because the term ‘national park’ in Britain means an area where you are allowed to build houses and have farms and it not actually a park as I know the term. Although the new forest does have little pockets of land that have trees on them.
We were staying in kind of an odd cabin. Upon arrival, it became clear that the ‘kitchen’ was a bit of an optical illusion. It had lots of kitchen cabinets and a cutting board and a tea kettle and a surprisingly large supply of wooden spoons, but was missing some details like a sink or any kind of cooker. It turned out that a microwave and a tiny oven were located in an outdoor shed that had a combination lock and no lighting. Which is how I came to be standing outside a shed in the pouring rain checking if a ready meal was done. I very strongly suspect that the cabin was registered with the local authority as a shed or something. As there was no kitchen, then it obviously isn’t meant for human habitation, right?
After returning from the fun but slightly shambolic holiday, it was time to prepare for Thanksgiving. One of the advantages of being abroad is that all the shops are open as normal, so its completely reasonable to stroll into a shop Thanksgiving morning (or even evening) and get what you need. My menu this year was:

  • boiled brussel sprouts
  • sweet potatoes
  • garlic mashed potatoes
  • nutloaf
  • roast carrots and spuds
  • american-style stuffing
  • mushroom gravy

My mother in law got very enthusiastic about everything and contacted her American friends for some recipes and so turned up with a wild ride with sausages, a green bean casserole and cranberry sorbet. She had a bit of a comical adventure trying to find ingredients, not realising that ‘frozen orange juice’ meant concentrated. Also, she read that an American cup measure was half a pint, and so was using British pint, which is significantly larger. I’ve never seen so much cranberry in my life.
My wife also made some lovely pumpkin bread and my friend Irene brought rice pudding. I made a pumpkin pie, which went terribly wrong and will not be mentioned again.
Around 12 people came over and fortunately, I made enough food that nobody left hungry. It was a lovely evening, at the end of which, I was too tired to move.
Now that this little break is over, when my hangover wears off, I will quickly be back hard at work at making noise commissions. I brought my recorder to the New Forest, but I learned that English forests are extremely quiet in November. The horses made some nice sounds, but my dog was acting strange and untrustworthy around them, so I didn’t get any recordings. Indeed, I was so exhausted from pedalling such a heavy bicycle that I barely took any pictures.
In my home country, this weekend has been taken over by a million holiday sales in shops and finally with ‘Cyber Monday’ which is the big day for online sales. All of it filled with desperate searching for the perfect gift for friends and family.
My dad is really hard to shop for. He doesn’t want much and what he does want, he just buys for himself. However, he is interested in arts and culture. A few years ago he had season tickets to the San Francisco Symphony and even managed to get me an introduction to the conductor!
For people like my dad, noise music commissions make fantastic gifts. The physical CD from the commission can be wrapped up for under the tree or other exchange. It’s something unexpected, with cultural capital and his name attached as the honouree of the actual piece of music. It’s a great conversation piece. The music is short, so he can store it on his phone and play it for his Square Dancing buddies before the dance starts.
Do you have somebody like my dad in your family, who is hard to shop for, but loves a good conversational started and has an interest in arts or music? This would make a thoughtful gift – something they’ll mention for years afterwards. Get a commission today and the CD will arrive in time for Christmas or Hanukkah. The price goes up after Cyber Monday so get it now!

Satisfied Customers

So far two of the comissions from this round have made it out to their final recipients. What did these folks have to say about it?

David is an American artist. My other commissioner was Dan, a British researcher who does computer analysis of bird songs.

You too could share in excitement like David’s or get to be a patron of the arts. Or, you could pass this joy along to someone else this coming holiday season. Music commissions make great gifts! If you order in November, delivery is guaranteed in time for Hanukkah or Christmas!

Do you love noise music? Do you have fashion? Drop me an email if you’d like your image to be in forthcoming posts about noise and fashion

Acoustic Noise

I’ve just posted a new piece of noise to my podcast, which was commissioned and titled by David Jensenius.

Shorts #31: 1416343620

The title he gave me is the unix timecode (aka: the time expressed as milliseconds since Midnight 1 January 1970 GMT) that he received the commission.
I’ve always had a particularly hard time coming up with titles. Sometimes, it took me as long to title a piece as it took to write the piece in the first place! When I first started this commissioning project, I was somewhat thinking of Mark Twain.
In one of the Tom Sawyer stories, Tom has been told to paint a fence. Since he doesn’t enjoy the task, he starts thinking of ways to get somebody else to do it for him. He could pay them, but he doesn’t have much money. He decided to use psychology instead. He would convince other boys that painting was really fun and they would ask to do it. Then, he realises, if it’s such a joy, they might pay him for the chance to paint. All those pick-your-own strawberry fields are based on the same principle.
I hate picking titles, so therefore, other people should pay me to do it for me! Of course, there’s more to a commission than that! There’s the knowledge that you’ve caused a new work to exist, and a piece of music made just for you!
David wanted an acoustic piece, so I recorded a bunch of sounds around my house. The house is still being painted and the dog was still quarantined, so this combination limited my access to hard drives full of archived recordings (waiting for music to be put into) and made it hard to go out into the world and get new recordings. Fortunately, there’s a lot of fascinating little sounds in the home. I’ve been intending to record my tea kettle for some time, and this finally got me to do it, with my zoom recorder. (Surprisingly, the wider angle microphones got a much nicer recording than the close ones, so keep that in mind, should you decide to record your own kettle.)
I got one extra sound that just did not fit into David’s piece. I recorded myself growling into a microphone, which made a nice harsh noise sound, but the rest of this piece was not harsh. Fortunately, I found a good application for that sound: the Swift Noise Compilation.
A few weeks ago, Taylor Swift released 8 seconds of white noise to iTunes, which topped the charts in Canada. In dedication to her chart topping short noise single, a tribute album is being put together of 8 second long noise pieces. This is extremely short, even for me!
The brief said white noise, but I strayed from that. My growl was only about 4 seconds long, so I ran it through PaulStretch and then used sox to cut it to exactly the right length:

sox –norm stretch.wav trimmed.aiff fade 0 00:00:07.98 0.07 pad 0.02@7.98
This trimmed the sound to 7.98 seconds, with a 0.07 second fade out at the end and 0.02 seconds of silence after that. Then, I used Audacity to put a stereo plate reverb filter on it. I love plate reverb and if I lived some place quiet, I’d try to get a real one.

My next acoustic commission will have a wider world to draw from, as my puppy is now finally clear to walk anywhere I’d care to take him. Today he will have his first trip to a dog park!
I’ve got another commission in my queue and then after that, I’m free to work on yours! Commissions make great gifts. If you order in November, delivery is guaranteed in time for Hanukkah or Christmas!

Do you love noise music? Do you have fashion? Drop me an email if you’d like your image to be in forthcoming posts about noise and fashion

New Noise

I’ve just posted a new piece of noise to my podcast, which was commissioned and titled by Dan Stowell.

Shorts #30: A lazy afternoon in the shade

The title he gave me is a reference to the Philae comet landing. Dan asked for analogue noise, adding he wanted ‘undulations’, if possible. I made some sound that seemed fairly undulating to me, which I recorded in five tracks, all somewhat different from each other. They used my new Gravity Well module from Circuit Abbey, which does orbital modelling. Since I was checking for comet news in between recording, this seemed to fit with the feeling of the day. I decided to use the comet mission as a metaphor for how to mix the piece.

Synth patch for second commission

The first part has a slower undulation and a slowly looping cycle, which I imagined like orbiting the solar system. Then it goes to a much tighter, shorter loop, like orbiting the comet. Then it goes into a nice low rumble, like rocket engines. Finally, it ends with a very low clicky sound, like the comet might be making. Thinking of it in this way really helped me to organise the material, which had more variation than I would normally use for such a short piece.

Comet patch

However, a problem became apparent when I tried to listen on my laptop’s internal speakers. The nice low rumbles were too low for my speakers! However, in the meantime, an actual comet sonification was released by the ESA, which is striking for a few reasons, including how beautiful it is and how much it sounds like synthesis! I decided to emulate it, with a pulse wave and white noise going through a resonant bandpass filter, with (alas, digital) reverb added on in the mix. This filled up the top frequencies and also gave it a good cadence at the end. It definitely made it a stronger piece, but I think it overwhelmed the undulating
Normally, in such a short piece, I would have three closely related ideas. This piece, however, has enough ideas for a piece two or three times as long. However, if I were going to do one thing different, it would be to use a different reverb. I’ve been wishing I had spring reverb for more than 20 years now, so maybe it’s time to finally give in.
There are a lot of reasons you might pick to commission a piece of music, like just because you want to be a patron of the arts! Commissions also make great gifts. If you order in November, delivery is guaranteed in time for Hanukkah or Christmas!

Vocal Contstructivists CD

In other music news, my choir, the Vocal Constructivists have released a CD, Walking Still, which is available for purchase. I’ve just ordered ten copies to give away as Christmas presents. It’s also available via iTunes and you can listen to it on Spotify.
The album has been getting good press, most recently by the Arts Desk, who used words like ‘compelling,’ fabulous’, and ‘faultless’. A previous review, in the Independent, compared it to orgasms with machinery noises.
I’ve also been told that its eligible for Grammy nominations, meaning they think it’s one of the best 500 CD released last year in its category.
I’m a tenor on the album. although I have written a piece for the choir, the first performance was not until after the recording session.
If you’re pondering getting a musical gift for someone, but think noise music might be a bit too much, this is a good disk to introduce people into somewhat out there stuff. As the Arts Desk put it, ‘Everyone needs a disc of offbeat contemporary music on their shelves. Start with this one.’

Sounding Good

Last night, I decided to do the final mixdown of the latest piece while sat in my living room, through my internal speakers. I recorded a bunch of sounds that used my low pass filter, because it’s really got a very nice, Moog-y sound. What the sounds don’t have are high frequencies, because of the filtering. Which means when I went to mix them, there was nothing at all coming out of my speakers.
It happens to be the case that, as laptop speakers go, mine are particularly bad. But, judging from the statistics of people reading this blog, most of you aren’t on mac either. When I got this computer, I told myself that the terrible internal speakers didn’t matter, because I would never use them and would always plug into better speakers. That’s what I told myself, at least. The reality is that I sometimes listen to stuff, even noise and other non-pop music, through the internal speakers. And it’s not reasonable to make somebody a commission and then dictate that they have to use special speakers to listen to it. I’m going to have to record a bunch of new stuff, with higher frequencies in it.
This issue of mixing for laptop (or earbuds or internal phone speaker) was first brought up in popular music by Bjork in her 2001 album Vespertine, which was specifically mixed to sound good on a mac laptop. In the 13 years since, all of pop music has followed her. If you’ve ever wondered why bass lines seem to be missing from most top-40 dance-y singles, this is why. They don’t sound good coming out of an internal laptop speaker or internal phone speaker and a lot of ear buds distort them.
Of course, all of pop music is, on some level a response to technology. singles are the length that they are partly because of the durations of wax cylinders – the first recording medium. But as a bass player, a tuba player and a composer, I have some nostalgic feelings for low notes. I think the answer to the conundrum is to mix carefully – make sure the piece sounds good coming from just laptop speakers, but leave in the low tones, so when people put it through better equipment, they get a nice surprise.
If you or someone you know wants to make a commission and don’t care about laptop speakers, let me know, and I’ll subwoof it up! Otherwise, you’re getting music engineered to sound good no matter how you play it. Noise music commissions make great gifts for people, whether they’re low-fi or high-fi! If you order in November, delivery is guaranteed in time for Hanukkah or Christmas!

Do you love noise music? Do you have fashion? Drop me an email if you’d like your image to be in forthcoming posts about noise and fashion