ELI5: How do audio codecs work?
I have a very basic understanding of audio as a whole, but how do different classes of codecs transform audio as we know it? How are newer codecs made and used to make audio lossless?
Posted Aug 12, 2022, 12:59 PM UTC
I have a very basic understanding of audio as a whole, but how do different classes of codecs transform audio as we know it? How are newer codecs made and used to make audio lossless?
Posted Aug 12, 2022, 12:59 PM UTC
When you record audio, your microphone essentially just records the pressure level in the air a certain number of times every second. Now in something like a .WAV file (a type of lossless audio file), the file just stores all those pressure levels.
There's this neat mathematical trick called a Fourrier Transform to take time-based information and convert it to frequency based information. So instead of storing the individual pressure levels, you would say that the air is vibrating 500 times a second (a frequency of 500 Hz). But rather than there just being one frequency, there will be multiple frequencies layered on top of each other.
I believe that in theory doing a Fourrier Transform is also lossless, i.e. you can reverse it and get the exact original data back. However when Fourrier Transforms are used on audio, the next thing we do is usually delete some of the frequencies. We delete the "weak" frequencies, and we delete the ones that humans can't hear. This is how an .MP3 file works for example. This makes the file much smaller, but at the cost of some audio quality.
Starting with images.
A JPEG image does the following:
The end result is "lossy" - zoom in to any JPG file and you'll see these 8x8 artifacts. The loss is not a big deal because our brains can ignore the defects and get the "basic idea". Kind of like how aggregate collages work ... see this movie poster as an example: https://image.tmdb.org/t/p/original/vuza0WqY239yBXOadKlGwJsZJFE.jpg
Now for music and sound files.
Picture this same idea as above, but instead of transforming a two dimensional 8x8 block, it's a 1-dimentional "sound wave". Cuts out the high frequencies which humans don't notice as much or at least we don't notice super fine variations in those frequencies ... and you have MP3s.
FLAC audio codec is lossess - no quantizing, no loss. It's like ZIP files for audio ... except it's specially designed for audio instead being a general purpose compression format. It exploits patterns known to exist in sound files.
Does that help?
Was this supposed to be a reply to me?
The OP, really. But generally anyone seeking to understand who doesn't already.
A very cleaver dude did some really complicated math in order to algorythmicaly tweak the 1s and 0s that make up a digital audio file in particular ways to achieve whatever his goal was. The codec is just a bunch of math that makes a specific thing happen, USUALLY storing the audio without much loss in perceptible quality while remaining small in file size.
They're just different ways to compress the same audio file. The final goal for all of them is to get smaller file sizes, ideally in a way that the original file can be remade. They get better over time, because while we don't lose any codecs we've managed to develop, we're also constantly working on coming up with new and improved ones.