Sat, 17 Jun 2006
The DTS File Format.
Having hacked on libsndfile for many years I have become something of an expert on sound file formats. Over that time I have also passed my eye over a large number of software projects and become rather skilled (if I say so myself) at telling the difference between well designed and engineered software and the garbage that is so common on the windows side. Time and time again, these moron windows developers jump on the first bad idea they have and then pursue if without ever thinking if there is a better way.
The latest example of this kind of garbage is the DTS file format. I haven't been able to track down much information about this abomination but I have found some example files The first two files on the site are zip files containing a single WAV file each. Or rather, these files look like WAV files. Opening these files in audio file editors like Sweep or Audacity (both of which use libsndfile for file I/O BTW) results in a waveform that looks like this:
When you play this thing it just sounds like white noise. Why is that?
According to the sndfile-info program that ships with libsndfile this file is a standard 16 bit stereo WAV file recorded at 44.1 kHz. Maybe its a bug in libsndfile. So, I tried playing this using Windows Media Player. Again, nothing but noise.
Now, WAV files are simple binary files. They contain a header which specifies the sample rate, channel count and data encoding followed by the audio data. Here's a hexdump:
00000000: 52494646 24004904 57415645 666D7420 RIFF$.I. WAVEfmt 00000010: 10000000 01000200 44AC0000 10B10200 ........ D....... 00000020: 04001000 64617461 00004904 FF1F00E8 ....data ..I..... 00000030: F107DFFC 98FC00EC EEE40900 DEFBEFFD ........ ........ 00000040: FFFF80FF 3F006DFF B6EDFFF6 FFFFFFFF ....?.m. ........ 00000050: FFFFFFFF FFFFFFFF FFFFFFFF 00F00000 ........ ........
which libsndfile decodes as:
RIFF : 71893028 WAVE fmt : 16 Format : 0x1 => WAVE_FORMAT_PCM Channels : 2 Sample Rate : 44100 Block Align : 4 Bit Width : 16 Bytes/sec : 176400 data : 71892992
So, in its simplest form, a WAV file has four bytes "RIFF", followed by four bytes containing the file length followed by "WAVE" and then "fmt " and then some binary data which is decoded as the sample rate and channels etc, followed by "data" and then the actual audio data. The interesting thing here is the format field which tells me that this file should contain PCM audio data. There's really not much to go wrong, so why does this file sound like white noise?
Well some idiot programmer (may Satan himself gnaw on their testicles) decided that even though they have set the format field to say that this file contains PCM data, they instead decide to put some other form of data in the data section. In one foul swoop they have created a file that is incompatible with every program in the universe that understands WAV files even though those programs think they know what to do with the file.
Now any idiot with an IQ above that of a cane toad should have been able to figure out that this was a bad idea and come up with a better alternative. Like maybe they could have changed the first four bytes of the file to "DTSF", or changed the "WAVE" string of the WAV file format or any one of about 826384768723587345 other possibilities. But no, in typical windiot fashion, they grabbed the first and most stupid idea that came into their heads and went with it.
I curse them 1000 times over. I specifically wish them ill.