Press "Enter" to skip to content

Computer Music Blog Posts

Nathan Davis on Ecology No 4

On Friday morning at 10am, I was lucky enough to run into composer Nathan Kroms Davis at EMM. Despite the fact that neither of us was quite awake yet, he was nice enough to talk to me about his work and the piece he presented at EMM.

Nathan is a programmer and musician who specializes in algorithmic music and graphic scores.

loading flv…


Program notes:

Ecology No. 4
by Nathan Kroms Davis

Ecology No. 4 is the fourth in a series of single-channel tape works that I have composed using Java software of my own design. This series of works explores models of reproduction and decay of sound structures that are suggestive (to me) of the growth and development of ecosystems in the natural world.

More of Nathan’s work, including some very interesting graphic scores can be found at web.mac.com/n.kroms.davis.

EMM 2008 Coverage

This weekend I am covering Electronic Music Midwest. As you can see from the schedule on the festival site, it is jam-packed with events. Unfortunately, this means that I don’t really have time to bring you constant updates. However, I am getting interviews from a lot of fascinating composers, and I’m getting permission to post a ton of interesting work. So on Monday and Tuesday, there will be a massive data dump about all the interesting work at EMM 2008.

For now, here are some shots of the beautiful campus of Lewis University. One of the funny things about Lewis University is that it has its own airport, so it’s not uncommon to see airplanes parked right next to academic buildings. Wild.


Lewis University 01


Lewis University 02

Electronic Music Midwest Starts Today

The first concert in Electronic Music Midwest 2008 is scheduled for tonight at 7:30pm at Lewis University. Here’s the lineup:

Circadian Rhythm – Tsai-yun Huang
What Exit: “I rejoice at the sight of her…” – Marita Bolles
Tensile Strength – Kyong Mee Choi and Timothy Ernest Johnson
Lines 1 – Kirsten Broberg and Sarah Carlson, Video
Prelude to You Brought This on Yourself – Mike McFerron
“artists go from unknown to mainstream overnight” – Julia Miller and Eric Gelehrter
Resonance – Taylor Briggs
HARDCORE – Christopher Preissing

It looks like a very interesting show, and a very interesting weekend. If you are in the Chicago area, then you should definitely think about driving over to Lewis U at some point during the festivities.

I will have more from EMM as the events take place.

Reading and Writing WAV Files in Java

Earlier this year, we looked at how to read and write wav files in C++ and VB.Net, and C/C++ is really the natural choice for this kind of file IO (for a number of reasons that we won’t go into here). Nonetheless, not everyone uses C or C++ for computer music software. Increasingly, programmers are turning to Java.

There are a number of libraries available for reading and writing wav files, however, to really understand the format, it’s necessary to get your hands dirty. So in this article, we are looking at reading and writing wav files in Java, which is not as easy as it may seem.

Java Numbers

The problem is that Java has no unsigned types. In other words, all numerical types in java can hold either positive or negative numbers. There are no types that are designed for only positive numbers.

This doesn’t sound like a big deal unless you know a little bit about how negative numbers are represented in most programming languages. The most important thing to know is that most languages represent negative numbers, in a way that is incompatible with the way they represent only positive numbers. More specifically, wav file headers represent numbers as unsigned bytes, whereas java represents numbers using a format called Two’s Complement.

The practical implications of this are simple: you can’t use java’s built-in IO functions for reading wav headers. You have to read the data as bytes, then do the conversion in a subroutine.

Understanding this problem is hard, but luckily, working around it is relatively easy. In our solution, we made 2 changes. First, we stored all of our numbers with more bytes than are necessary in other languages (to ensure that we are storing the correct numbers). So for each 2-byte number, which would usually be stored by a short, we used an int, and for each 4-byte number, we used a long. Then we added 4 extra subroutines to do the conversions for us. These routines are at the bottom of wavIO.java.

// these two routines convert a byte array to a unsigned short
public static int byteArrayToInt(byte[] b)
{

  int start = 0;
  int low = b[start] & 0xff;
  int high = b[start+1] & 0xff;
  return (int)( high << 8 | low );
}

// these two routines convert a byte array to an unsigned integer

public static long byteArrayToLong(byte[] b)
{
  int start = 0;
  int i = 0;
  int len = 4;
  int cnt = 0;
  byte[] tmp = new byte[len];
  for (i = start; i < (start + len); i++)

  {
    tmp[cnt] = b[i];
    cnt++;
  }
  long accum = 0;
  i = 0;
  for ( int shiftBy = 0; shiftBy < 32; shiftBy += 8 )
  {

    accum |= ( (long)( tmp[i] & 0xff ) ) << shiftBy;
    i++;
  }
  return accum;
}

// returns a byte array of length 4

private static byte[] intToByteArray(int i)
{
  byte[] b = new byte[4];
  b[0] = (byte) (i & 0x00FF);
  b[1] = (byte) ((i >> 8) & 0x000000FF);
  b[2] = (byte) ((i >> 16) & 0x000000FF);

  b[3] = (byte) ((i >> 24) & 0x000000FF);
  return b;
}

// convert a short to a byte array
public static byte[] shortToByteArray(short data)
{

  return new byte[]{(byte)(data & 0xff),(byte)((data >>> 8) & 0xff)};
}

WAV File Specification

Again, we are using a VERY basic version of the wav file format for this example. This won’t read many wav files, it will only read what are referred to here as canonical wave files. Basically, old fashioned wav files (before the chaos introduced by 24 and 32 bit recording).

If you want to read more complicated wav files, you may want to check out what’s written here and here, although you really need to look at the actual specification (and you had better have some free time).

The Source Code

To use the source code, just unzip all the files into the same directory, and then use the batch files I created called compile.bat and run.bat. Of course, I am assuming that you have the latest version of java installed.

Download the source code for reading and writing wav files in java here.