Compressing audio files without loosing data

FLAC Compression

High quality audio files take a lot of space, for example, a 1 minute stereo sound at CD-quality (44.1 kHz) will take about 10-11 Mb. A large collection of sound files will fill hard drives really fast. The usual solution to this problem is to compress the files, however each compression system has its limitations.

The common zip compression format works well for text but does not compress audio in any significant degree. Encoding the file to mp3 will destroy a lot of information that will be necessary to analyze the audio.

FLAC (Free Lossless Audio Codec) is optimized for wav audio files, and can compress a wav to 30-50% of its original size. It appears that the amount of compression will depend on the complexity of the sound recorded. The decoding back to wav is very fast and it is an exact copy of the original file.

Following are some examples of using FLAC:

To compress a wav file (test.wav) to flac:

  1. flac test.wav

To compress a wav file (test.wav) to flac, verify the compression, and delete the original wav if compression went well:

  1. flac –verify –delete-input-file test.wav

Easy enough, to compress a bunch of files in a directory:

  1. flac *.wav

To recover the wav file from a flac:

  1. flac -d test.flac

How much compression?

Tested using 11280 wav files, each one approximately 60 sec, mono, sampling rate of 48 kHz:

  • Total size in wav: 67 GB
  • Total size in flac: 24 GB
  • Compressed to 36% !

Getting FLAC

FLAC is free and open source.

Libraries for C and C++ are also available with the source code.