jump to navigation

Everything about File Compression: Take 2 November 17, 2008

Posted by ConnorSmith in : Chit Chat, File Compression, Project Studio , trackback

MP3

Loved by many, despised by some…  regardless of where you stand, mp3 is hugely important in the proliferation of internet music.  It is the original method of delivering compressed audio (mainly over the internet).

What does MP3 stand for? How does it compress?  Why is it “good”? Why is it “bad”?  Let’s dive in…

MP3 actually stands for “MPEG-1 Audio Layer 3″. MPEG-1 was originally developed as a lossy compression standard for audio and video, and layer 3 (of the 5 total) is for audio compression.

So I started hinting at psychoacoustic modeling (aka perceptual modeling) in the last post.  In these encoders, these are essentially digital representations of how our (human) hearing system works.  Through rigorous and complicated testing, this model is formed to predict particularly how the hearing system is going to react to sounds.  What the model is mainly interested in is what parts of any given sound signal are going to be masked, both in the time and frequency domains.

I gave an exaggerated quasi-frequency based masking example in the last article, here’s a time based:  Suppose Jim is the fastest drummer in the world.  He can play a flam so quickly on his imaginary drum that the transients of the two hits are .00000001 seconds apart.  As humans, we probably aren’t going to be able to hear this as two separate hits (like a flam, as Jim originally intended to play).  The mp3 encoder might choose to just squish those two transients together.

**Note, this is just a rather-ridiculous example.  It assumes that both hits ring out independently, there is no comb filtering as a result of the addition, and that our sampling frequency is high enough to capture the difference in the first place (DSD anyone?), etc…

So here is a basic explanation of what is happening in the encoder.  Let’s pretend we have a 3 minute rendition of HAPPY BIRTHDAY as a WAV, and you want to compress it to a 128 kbps (kilo-bits per second) :

1) The uncompressed audio is broken up, both in the time and frequency domain, using a combination of FFT and MDCT filterbanks.  Simply put, the encoder breaks the original audio signal into very small blocks and analyzes the frequency content of each block.

2) At the same time, the encoder begins to examine the audio with the psychoacoustic model.  Here it starts to examine which parts of the audio will be masked by our hearing system.  This information is analyzed and fed with the MDCT’d audio (from step 1) into a quantizer.

3) The quantizer’s job is essentially to assign bits of data to all the information.  Since we chose 128 KBPS at the start of this process, the quantizer knows it has 128,000 bits available to assign for each second of audio.  With the information from the psychoacoustic model, the quantizer will know to give many less bits to parts of the sound that we can’t hear, and the majority of the bits to things that we will hear.  However, problems can arise if the encoder runs out of bits (in this case, if it uses up all 128,000 bits in a second and still has data to encode).

When this happens, something needs to happen. One option is to encode things with yet lower bit depths (or the amount of bits used for each sample).  Unfortunately, this may lead to more quantization distortion, inaccurate signal representation, errors in the time domain, other non-harmonic distortion… more bad things.  Another common thing to do is de-emphasize high frequencies.  If the encoder doesn’t have to worry about any frequencies, say, above 12 kHz, that frees up a lot of bits (in the process, destroying the high end of the source material).  Drag an mp3 into a DAW and run it through a spectral analyzer.  The lower the KBPS, the lower the cutoff for the high frequencies will be.

Some of this problem can be solved by using variable-bit-rate (or VBR) options in the encoders.  We’ll get to that in the next article perhaps.

4) Now quantized into a nice array of 1′s and 0′s, the encoder attaches metadata and other tags on the frames and assembles it into a nice mp3 package.  Once here, an mp3 decoder could quickly and easily decode an mp3 into audio.

Again, I apologize if that got more technical that necessary.  Here it is in sum:  The encoder breaks the original file into small pieces and analyzes the frequency content.  A perceptual model of how humans hear tells the encoder what parts of the original signal are unnecessary (or less important).  The encoder assigns bits to the data based on the model, giving less bits to things that we shouldn’t hear.  Then the encoder packs it up, labeling things so that the decoder can recognize and play the file.

Soon, we’ll get into explanations of the other encoders (most of which are fairly similar to mp3), problems with the encoders, etc…

If anyone is seeking deeper technical explanation of these processes, be sure to let me know in the comments.

C

The Studio Files

Comments»

1. alex - November 23, 2008

So when an mp3 de-emphsizes high frequencies, is that why open hi-hats often sound watery? The cymbals are always a give away to me on whether someone ripped a really low bitrate mp3.

2. ConnorSmith - November 23, 2008

The “birdies” appear as a result of a few things

1) Pre-echo and time smearing (which, I don’t think I talked about pre-echo). I’ll an article today.

2) The encoder runs out of bits, and so it basically lo-passes the high frequencies

3) The encoder runs out of bits, and so it can’t raise the bits of the “good” high frequency information above the noise floor/yuck.

The quintessential example of birdie-like things is anything on YouTube. The metallic, high-frequency warblings are a result of similar events.

3. ConnorSmith - November 23, 2008

Finished an article on the problems inherent to current lossy compression encoders

http://thestudiofiles.com/?p=525


Close
E-mail It