8

I understand that when converting between audio formats where no stream encoding is involved like when converting between WAV (PCM), AIFF, FLAC, ALAC, WMA Lossless, and etc, the process is usually lossless, because the PCM audio stream is just being copied to the new container. Depending on the container type, it may be run through a compression algorithm to save space, but it's still bit-for-bit identical data. You could also do the same thing with an MP4(AAC) file, by copying the AAC audio stream in an MKA container file; it's all lossless, because there is no re-encoding of the audio stream.

I understand that when converting between formats like the previously listed WAV(PCM), ALAC, FLAC, and etc to a format that doesn't support the audio stream's encoding the conversion should involve re-encoding. For example when converting to formats like MP3, MP4(AAC), OGG(Vorbis), WMA Lossy, and etc the source audio stream is being re-encoded, and as such data is being discarded. The new file will be of poorer quality.

What I can't wrap my head around is why converting from MP3 to WAV (PCM) is lossless (or ALAC, FLAC, etc). The audio stream is re-encoded so couldn't the new audio stream be of poorer quality than the MP3's audio stream? Enlighten me.

  • 7
    Generally speaking it is only decoded, then stored as the uncompressed. All the losses occured when stuff was tossed out to make it a MP3. A better way to say it is "there is no more loss". If you have a Jpeg, and decompress it to the full bitmap (which occurs in most paint&processing programs) you dont have losses added, because it is just decoded. If you then go to save it out as something that does toss stuff to make it smaller , then you are re-encoding it, and will have loss again. If you were cross-coding it to another lossy format, it would be de-coded and en-coded again with loss. – Psycogeek Dec 3 '14 at 7:46
  • 5
    Conversion between PCM containers in only lossless if and only if the sampling frequency and the resolution/bit depth is exactly the same. Even resampling to a higher frequency or resolution results in a lossy result. – agtoever Dec 3 '14 at 11:33
10

PCM is one of the most used audio codecs; most computers (as well as many devices) use it as their default for audio output/input. All audio heard on this device, whether from a file, or a microphone input, is in PCM, and that is used to regenerate an approximation of the original analog sounds.

When you make a digital audio recording using a mic on a system that is using PCM for audio output/input, the audio stream is PCM. When you losslessly save that recording as WAV, FLAC, WMA Lossless, ALAC, AIFF, and etc, there is no encoding process, the audio stream is just put into the new container file, it's still the PCM stream your system interpreted from the analog real-world sounds.

Lossless formats can be divided into 2 types: compressed, and uncompressed. Uncompressed formats like WAV and AIFF just store the PCM audio stream. Compressed formats like FLAC, ALAC, and WMA Lossless run the stream data through a compression algorithm to save space, like a zip archive. The data isn't changed, it's just stored more efficiently; it's still encoded as PCM.

If you then take the lossless export, and convert it to a 128kbps MP3, there is re-encoding involved. Encoding means organizing the audio stream data in a new way; this is a lossless process. However, there are no codecs to my knowledge that do this, because it would be pointless. The file would sound the same, playback would require the audio to be decoded which means more system resources are needed, and it would be the same size as the original file. Therefore, codecs like MP3, WMA Lossy, AAC, Vorbis (OGG), and etc also perform additional operations. A common operation being to discard data deemed to be of lesser importance. Discarding data results in a smaller file size.

The below isn't a perfect analogy, but it gets the point across I think.

Let's say that a "I hate you Sarah!" written on a piece of paper represents the PCM audio stream in the WAV file you losslessly exported after making a recording.

Encoding that data in a different encoding format would be equivalent to jumbling the letters up to say "h Iyae oSr! haatu". The decoding software knows how this codec arranges data so it can unjumble the message.

However, as discussed, formats like MP3 also discard data during the encoding process. So the MP3 message would be more like "h I Sr! h tu", and when decoded (unjumbled), it would be like this "I h t u S r h!". If you read this back, you still get the message, but excluding letters does alter the sound a bit. The more you exclude, the worse it gets, until you reach a point where you can no longer understand the original message.

The MP3 audio stream represents the original PCM audio stream. When you play the MP3, it's being decoded back to PCM, but the discarded data doesn't return obviously. It sounds plausible in this example to add back in the missing letters, but remember, computers aren't as smart as us, and this is a very very very simple example.

If you were to convert the MP3 to a WAV file, technically you are decoding to PCM, and then saving the PCM stream, which is why the WAV is bigger than the MP3. There is no data loss because the MP3 stream was always just a representation for a PCM stream. The codec specification tells the decoder how to decode the MP3 back to PCM format. If you were to convert the MP3 to a 128kbps AAC, what is actually happening is the MP3 is decoded to PCM, and then the PCM stream is encoded as AAC. The encoding process from PCM to AAC results in further data loss, because "I h t u S r h!" is treated as the original message. Notice the letters aren't squished together. When the AAC file is made, it won't know spaces from excluded letters aren't part of the message when trying to figure out what is safest to discard, which is why re-encoding data at the same bitrate results in quality degradation.

| improve this answer | |
  • Were you having relationship issues when you wrote this? – c24w Mar 16 at 10:53
0

So, you are saying that if you transcode an MP3 to WAV, that it's lossless? WAV is an uncrompressed loseless format, MP3 is a 'lossy' format. Lossy formats are always compressed. When you transcode from lossy to lossless, you will end up with a file that looks lossless, but it really isn't.

You can check this by applying 'spectral analysis' on the file. The image below show a lossless file, that is transcoded from an MP3. Can you see the shelf at 16 kHz? In a uncrompressed losseless file (like WAV), the shelf shouldn't be there.

enter image description here

Really good information on transcoding: https://www.whatinterviewprep.com/prepare-for-the-interview/spectral-analysis/

| improve this answer | |
  • 4
    Just a minor detail: MP3 is an audio codec. WAV is a container format and as such not lossy or lossless. PCM audio is what is typically stored in WAV containers, and PCM is lossless. – slhck Dec 3 '14 at 7:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.