Audio Processing - sahajss/knowledge_base GitHub Wiki

The Problem

Audio processing is a pain. There are many different file formats for audio, and none of them are simple to process. Even .wav files vary between each other, even though they are uncompressed. They may have a header, meta data, or other text that makes it hard to tell exactly how to read the data. And this is for uncompressed audio. Compressed audio is much more complicated and difficult to understand. And for someone whose main goal is to manipulate the data in an audio file, having to process the audio files can be a major roadblock in achieving that goal.

Dealing with compression

There are standard file formats in place, but each have their own compression formats and present the data differently. It is not worth it to try to deal with compressed or uncompressed audio alone. There are already libraries that can process audio for you, and can handle different forms of compression using codecs. For example, I used a web based javascript library, aurora. Aurora came with built in support for .wav files, and a simple way to include processing for more complicated formats.

Aurora

Working with aurora, getting the data from an audio file was reduced to a couple lines of code.

var asset = AV.Asset.fromFile(file);
asset.decodeToBuffer(function(buffer) {
    // do something with the data 
}

This would create an array of the raw data from the audio file. This would work for all types of files, as long as the proper codec library was loaded. With these few lines, audio processing was simplified, and I would never have to deal with file formats again.