Lossless Audio Encoding

repoman0

Diamond Member
Jun 17, 2010
4,702
3,728
136
How does lossless audio work? What sort of algorithms do formats such as FLAC and ALAC use? And if you run the encoder on a file twice, is the output file the same both times?
 

repoman0

Diamond Member
Jun 17, 2010
4,702
3,728
136
If you attempt to encode it twice it can actually increase in size.

What I meant is if you run the encoder on the WAV file twice, and compare the two resulting FLAC/ALAC/even MP3 files. For some reason I always had the bias that the resulting files would be slightly different somehow, at least in the case of MP3. But learning a bit about algorithms and programming and computers now makes me think that the process should be deterministic and the files should be the same each time. But I guess it's hard to tell without knowing what the actual algorithm is.
 

FrankSchwab

Senior member
Nov 8, 2002
218
0
0
For lossless algorithms,you will get deterministic results - every time you run encoder on the WAV file, you'll get exactly the same output. Decoding the output will get you exactly the same data as the input. Think ZIP - you want exactly the same thing out that you put in.

For lossy algorithms, it's pretty much the same - every time you run the SAME ENCODER with the same parameters, you'll get the same output file. However, if you took a WAV file and ran it through three different MP3 encoders with the same parameters (256 Kbps, etc), you'll get three completely different output files. Decoding the three files, none of them will give the same data as the input file, but they will all sound the same to your ears.

Lossless algorithms suffer from very poor compression ratios - you're lucky if the file is half the size of the uncompressed file. Lossy can give you a file 1/10 the size of the input file, and sound perfectly fine.
 

repoman0

Diamond Member
Jun 17, 2010
4,702
3,728
136
For lossless algorithms,you will get deterministic results - every time you run encoder on the WAV file, you'll get exactly the same output. Decoding the output will get you exactly the same data as the input. Think ZIP - you want exactly the same thing out that you put in.

For lossy algorithms, it's pretty much the same - every time you run the SAME ENCODER with the same parameters, you'll get the same output file. However, if you took a WAV file and ran it through three different MP3 encoders with the same parameters (256 Kbps, etc), you'll get three completely different output files. Decoding the three files, none of them will give the same data as the input file, but they will all sound the same to your ears.

Lossless algorithms suffer from very poor compression ratios - you're lucky if the file is half the size of the uncompressed file. Lossy can give you a file 1/10 the size of the input file, and sound perfectly fine.

Great, this is what I was looking for, and what I figured the answer would be after spending some time as an EE student. Before I learned any of this stuff, "common sense" told me that the files would be different somehow

I started my senior level DSP class today so hopefully I'll get some serious insight into this stuff in the coming months.
 

Howard

Lifer
Oct 14, 1999
47,982
10
81
Fortunately, storage space is cheap enough that storing large amounts of music in lossless format is feasible.

Unfortunately, much of it isn't worth storing losslessly.
 

TecHNooB

Diamond Member
Sep 10, 2005
7,458
1
76
as far as I know, lossless algorithms don't quantize the data. they don't alter the data such that after you encode/decode you get something different from what you put in. quantization is the lossy part in all the algorithms I'm aware of.
 
Last edited:

BrightCandle

Diamond Member
Mar 15, 2007
4,762
0
76
There are a lot of techniques used to try and reduce the stream of information down so that their is no redundant information in there. Lossless algorithms for audio are somewhat different to Zip and RAR because they are based on how audio works and is stored. The algorithms are not useful as general purpose compression algorithms. They do better than ZIP would do on the raw WAV file by a reasonable amount because they understand the data. They will always produce exactly the same output as input in terms of frequencies and volume played back.

Different lossless implementations of the same format might not produce the exact same file however, partly because meta data might be different and partly because there are lots of potential equal cost ways to compress and a different algorithm might choose a different encoding which achieves a similar result when decompressed but the sound produced is identical.

Lossy algorithms will still produce consistently the same file when given the same file and parameters, they don't throw things away randomly. Based on bitrate and other quality measures they can go through and decide which information to throw away, which channels to merge and which changes to smooth out a little to trick the ears into thinking they are hearing the original. They do a surprisingly good job at about 1/20th the size of the uncompressed data.

Computers are deterministic, even their random algorithms are deterministic. Its the nature of algorithms that the same input always produces the same output, they are after all machines that just do the same thing over and over.
 

cantholdanymore

Senior member
Mar 20, 2011
447
0
76
as far as I know, lossless algorithms don't quantize the data. they don't alter the data such that after you encode/decode you get something different from what you put in. quantization is the lossy part in all the algorithms I'm aware of.

Quatization noise is a product of the A/D conversion, trying to fit an analog signal into discrete digital values.
 

TecHNooB

Diamond Member
Sep 10, 2005
7,458
1
76
Quatization noise is a product of the A/D conversion, trying to fit an analog signal into discrete digital values.

that's not what people are talking about when they talk about lossy encoding. the loss comes from quantizing the signal spectrum based on some perceived model of human hearing.
 

repoman0

Diamond Member
Jun 17, 2010
4,702
3,728
136

Yeah I thought so too. Quantization as in quanta, a word for something taking only certain values (also like quantum mechanics which gets its name from when Planck postulated that light exists as photons, where each photon has a discrete energy). In the case of 16bit WAV that means fitting an analog waveform with infinite possible values into one of 65536. Which of course brings about some small but finite error which is heard as noise ("quantization noise").. though I've never heard that noise personally.
 
Last edited:

TecHNooB

Diamond Member
Sep 10, 2005
7,458
1
76
MP3 does something similar but this explains what I mean by quantization pretty well.

http://en.wikipedia.org/wiki/JPEG

you can think of it as every frequency band having an ADC, where the ADC resolution is much higher for more significant frequencies and much lower for less significant frequencies. This makes it so that if you want to keep an insignificant frequency, it has to have a significant amount of energy. Another way of saying this is that insignificant frequencies have a higher value in the Q matrix. There must be a significant amount of energy in that frequency band for it to attain a nonzero value after quantization. Significant energy does get kinda hairy when using DCTs however, because they don't contain phase information. So not only does a frequency need to have significant energy, it must also correlate well with cosine.
 
Last edited:

Abwx

Lifer
Apr 2, 2011
11,543
4,327
136
Losseless encoders have variable compression rate.

Depending on the encoded file , compression rate can be as low as zero,
although such uncompressible files are statistically zero with audio files.
 
Dec 30, 2004
12,553
2
76
someone should make a lossless audio encoding format with configurable "quality" setting like in OGG, just to see what people do...
 

Anarchist420

Diamond Member
Feb 13, 2010
8,645
0
76
www.facebook.com
For lossless algorithms,you will get deterministic results - every time you run encoder on the WAV file, you'll get exactly the same output. Decoding the output will get you exactly the same data as the input. Think ZIP - you want exactly the same thing out that you put in.

For lossy algorithms, it's pretty much the same - every time you run the SAME ENCODER with the same parameters, you'll get the same output file. However, if you took a WAV file and ran it through three different MP3 encoders with the same parameters (256 Kbps, etc), you'll get three completely different output files. Decoding the three files, none of them will give the same data as the input file, but they will all sound the same to your ears.

Lossless algorithms suffer from very poor compression ratios - you're lucky if the file is half the size of the uncompressed file. Lossy can give you a file 1/10 the size of the input file, and sound perfectly fine.
The music I listen to doesn't sound perfectly fine to me if it's lossy. Lossy compression needs to die.
 

yaxattax

Member
May 4, 2011
25
0
0

You've got the wrong understanding:

https://en.wikipedia.org/wiki/Jpeg#Quantization

The general scheme for a lossy encoding scheme (image, video, auditory) is as follows:

Linear transformation
Quantisation (sometimes referred to as truncation) of transformation coefficients
Rasterisation followed by Run-Length encoding and entropy coding

Quantisation is referred to as such because when you have, for example a coefficient 27, and your quantisation factor for a coefficient in that position is 10, you will have 2 after you perform the division. During reconstruction you will multiply by the quantisation factor again and get 20=/=27, which is why it is named quantisation, because just like continuous -> discrete quantisation, some information becomes unrecoverable in the process.

Basically, values that are members of a discrete set, rather than continuous, are not precluded from quantisation just because they are already discrete.
 
Last edited:

d3fu5i0n

Senior member
Feb 15, 2011
305
0
0
You've got the wrong understanding:

https://en.wikipedia.org/wiki/Jpeg#Quantization

The general scheme for a lossy encoding scheme (image, video, auditory) is as follows:

Linear transformation
Quantisation (sometimes referred to as truncation) of transformation coefficients
Rasterisation followed by Run-Length encoding and entropy coding

Quantisation is referred to as such because when you have, for example a coefficient 27, and your quantisation factor for a coefficient in that position is 10, you will have 2 after you perform the division. During reconstruction you will multiply by the quantisation factor again and get 20=/=27, which is why it is named quantisation, because just like continuous -> discrete quantisation, some information becomes unrecoverable in the process.

Basically, values that are members of a discrete set, rather than continuous, are not precluded from quantisation just because they are already discrete.

Brilliant explanation. :thumbsup:
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |