Soundfile formats.

For most purposes in this course we will be dealing with one of 8 kinds of soundfiles: where the samples are either stored in 32-bit floating point format or 16-bit two's complement integers, which consist of one or two channels, and where the sampling rate is either 22050 or 44100. The reason to use floating point files is that you don't have to worry about scaling your amplitudes to within + or - 32768. A floating point file can have amplitudes greater than a zillion or less than 1 (but not both). You simply have to know what the peak amplitude will be so that it can be scaled for 16 or 24-bit DACs when played

There are also two format of soundfiles we will deal with, aiff and snd

Here is all you have to know.

1) Cmix requires that you create a header before you actually write to a soundfile, if the soundfile doesn't already exist. (If the soundfile does exist it will add the output to that soundfile--that's why it's called C'mix'). To create a header you say [f,F,i,I][1,2], where lower case creates a 22k header and upper case a 44k header, f stands for floating point, i for integer and 1 and 2 are the number of channels. I1 thus creates a 44k, mono header for a file of short integers.

The important thing about these headers is that they store the peak amplitude of the file.

These files are generally known as snd files (NeXT format). Ein and Cmix both read aiff and snd files but only write snd files.

To listen to any kind of short file you can use the SGI utility sfplay. I wrote a program, howeve, called simply, play, which will play aiff, snd, short and floats, as long as the peak amplitude is stored in the header for a floating point file.. If the peak amplitude is not there you can put it there with a program called sndpeak. as long as the soundfile is in snd format. sfplay can only play floating point files if the peak amplitude is less than 1.

Converting soundfiles to aiff or snd format

If you download a wav file from the internet you can use the SGI program called sfconvert to change its format and sampling rate. sfconvert will explain its arguments for you.
The following will convert an 11khz, 8-bit wav file to 22k 16 bit, snd format

sfconvert xwav x.snd format next integer 16 2scomp rate 22050

The only format it doesn't know how to deal with is Microsoft's proprietary wav format. Ignore any soundfiles in this form. They don't deserve to be used.

While sfplay cannot play floating point files, it can play a number of other formats, such as wav and mp2. Use the programs mpg123 or mp3dec to play mp3 files. The latter also has an option to create a file of short integers. Finally you should alias sfplay to 'sfplay -rude' to get around a feature which sometimes doesn't set the sampling rate properly.