Log in

View Full Version : FLAC encoding : lossless or not ?


sirt
23rd January 2013, 16:39
Hi,

Let's say I have ripped a personnal CD via EAC and I end up with FLAC files which are lossless. Then, imagine I want to apply a delay to one track for some or other reason and I choose to do that on Audacity. Finally, I export the resulting track in FLAC. Will it still be lossless in this case ? In addition, is there a way to export an audio without reencoding on Audacity or any other similar program when you are just applying a delay or cutting your audio, adding several (similar) tracks one after the other ?

jkauff
23rd January 2013, 17:24
I think Audacity converts the imported FLAC files to its own flavor of PCM. When you export to FLAC, it compresses the output. It's a totally lossless chain.

tebasuna51
23rd January 2013, 17:47
... In addition, is there a way to export an audio without reencoding on Audacity or any other similar program when you are just applying a delay or cutting your audio, adding several (similar) tracks one after the other ?

Talking about Flac you need decode and recode.

With other format (AC3, DTS, MP3, ...) you can make this with eac3to, or DelayCut, without recode.

detmek
23rd January 2013, 17:51
Unless Audacity has some sort of dithering activated.
@sirt You can not export files from Audacity without re-encoding. Once you edit file by adding silence or cuting it, it is not considered lossless but unedited audio part will remain the same as original.

Edit:
Yes, by default, AC applies dithering.

Snowknight26
23rd January 2013, 17:58
It won't if you don't change the bit depth.

detmek
23rd January 2013, 18:29
I just tried and new FLAC did not pass verification. I had to disable dithering in Preferences - Quality.

sirt
23rd January 2013, 19:02
Then I'm still confused : do you mean compressing my FLAC files using FLAC again via Audacity without doing anything apart from either cutting or delaying the track is lossy in a way ? What is this "dithering" issue about ? Also, it is unclear what you refer to by "remains the same as original" if it is compressed.

detmek
23rd January 2013, 20:54
When you compare audio data, you compare decoded data, uncompessed PCM. Lossless means that content of file1 is bit-by-bit identical with content of file2. Cutting file2 or adding silence will remove or shift some or all bits so file2 will not be bit-by-bit identical to file1 as file2 will have more or less bits then file1 . So technicaly, it is not lossless (from audiophile perspective). But, those remaining bits of file2 will not be altered by adding silence or cutting, just shifted and, after decompression, those will be identical with file1. So, remaining part is lossless.
Dithering will change audio data so two files will not be matematiclly identical. Althouth, in 99,9999999999999999% cases you can not hear difference between those two files.

sirt
23rd January 2013, 21:16
Ok, thanks ; could you upload the sample and its dithering alias you claimed above not to have passed "verification" which, to my mind, means you hear a difference or noticed spectrums distorsions ?

detmek
23rd January 2013, 21:50
Sure. Here (https://dl.dropbox.com/u/19804113/Forumi/Fajlovi/30secSample.zip) is 30 sec sample of original, dithered and not dithered encode. I couldn't hear difference. I used foobar2000 and its Bit Compare plugin to verify files.

sirt
24th January 2013, 00:39
Ok I've checked all of them with no sucess, even the spectrum look nearly identical. Then what is the point to dither ? It doesn't seem to improve anything nor ruin the audio.

Another question : I've read random pages, including Audio FAQ, where it was explained it would be possible to raise up the volume of an MP3 without reencoding : what do you think ? Is that true ? On the other hand, If I decide to do same with a FLAC via Audacity and export it into a FLAC, will that be lossless in term of quality (not in term of bits arranging) ?

Groucho2004
24th January 2013, 02:38
Then what is the point to dither ?It's widely used to minimize quantization errors when reducing the bit depth of audio (PCM) data.

Another question : I've read random pages, including Audio FAQ, where it was explained it would be possible to raise up the volume of an MP3 without reencoding : what do you think ? Is that true ?
What you read is probably about replaygain. It does not alter the mp3 stream.

On the other hand, If I decide to do same with a FLAC via Audacity and export it into a FLAC, will that be lossless in term of quality (not in term of bits arranging) ?
:confused::confused::confused:
If you modify the PCM data, your process is not lossless.

Snowknight26
24th January 2013, 04:19
Please don't mislead him. If he's simply removing PCM frames or adding but otherwise not altering them (applying a transformation to the wave) then it's still lossless.

To answer his original question, yes, it will still be lossless in that case.

Groucho2004
24th January 2013, 10:19
Please don't mislead him. If he's simply removing PCM frames or adding but otherwise not altering them (applying a transformation to the wave) then it's still lossless.

To answer his original question, yes, it will still be lossless in that case.

I believe that was already answered:
Once you edit file by adding silence or cuting it, it is not considered lossless but unedited audio part will remain the same as original.

jkauff
24th January 2013, 13:43
Every lossless file has a source, such as a 16/44.1 CD. The source for the exported compressed FLAC file is Audacity PCM, which I think is 32-bit.

When the FLAC file was imported, its 16/44.1 content was upsampled and converted in order for Audacity to work with it. You now don't have your original FLAC file, but an Audacity project. When you're finished editing, Audacity will downsample using dithering to your desired output specs. It compresses the result, and you now have a new FLAC file which is a version of your Audacity project. Audacity has added information, then removed it, so nothing has been lost from the original source. It can't be identical to the original FLAC, because the source is now different.

You haven't lost any of the original source information except what you've removed yourself during your editing. Keep in mind that your original 16/44.1 content was probably downsampled and dithered from 32/192 or higher (the studio source).

Groucho2004
24th January 2013, 15:08
Every lossless file has a source, such as a 16/44.1 CD. The source for the exported compressed FLAC file is Audacity PCM, which I think is 32-bit.

When the FLAC file was imported, its 16/44.1 content was upsampled and converted in order for Audacity to work with it. You now don't have your original FLAC file, but an Audacity project. When you're finished editing, Audacity will downsample using dithering to your desired output specs. It compresses the result, and you now have a new FLAC file which is a version of your Audacity project. Audacity has added information, then removed it, so nothing has been lost from the original source. It can't be identical to the original FLAC, because the source is now different.

You haven't lost any of the original source information except what you've removed yourself during your editing. Keep in mind that your original 16/44.1 content was probably downsampled and dithered from 32/192 or higher (the studio source).
There is so much nonsense in this post, I don't even know where to start.

"When the FLAC file was imported, its 16/44.1 content was upsampled and converted in order for Audacity to work with it."
Why would Audacity upsample? Are you saying that it cannot work with 44.1 KHz sampling frequency?

"Audacity has added information, then removed it, so nothing has been lost from the original source."
Seriously? Are you aware that dithering uses random values?

"Audacity will downsample using dithering"
Downsampling refers to the time domain whereas dithering is a term used in the context of quantization.

Ghitulescu
24th January 2013, 16:14
There is so much nonsense in this post, I don't even know where to start.

Try with the title :).

FLAC is lossless. If losses are to come from somewhere, they come from the processing the audio has outside the FLAC.

Pomegranate
24th January 2013, 16:40
Audacity imports 16 bit flac (and 16 bit wav) as 32 bit floating point wav by default, maybe because things like volume change, normalizing, etc, are floating point operations. This can be changed in the settings. I think what jkauff was trying to say by using "upsampling" and "downsampling" is bit depth increase and reduction.

pandy
24th January 2013, 17:02
Ok I've checked all of them with no sucess, even the spectrum look nearly identical. Then what is the point to dither ? It doesn't seem to improve anything nor ruin the audio.

Dither is used to address re-quantization and introduced during this quantization errors. It will improve overall audio quality.

sirt
24th January 2013, 17:35
pandy, even if you are right, it looks like this "improvement" you bring out is not clearly justified with the above samples by detmek : not only you can't hear any difference but one spectrum is also similar to another. Would you mind showing us an example of untouched/dithered audio where the difference is noticeable ?

So, finally I I import a FLAC on audacity and export it in FLAC ten times, without modifying it, I can deduce it will be lossless. I tried another weird process : raise the volume by a fixed number B and export it in FLAC ; of course the spectrum has been touched but I reopened this last FLAC file and lowered back the volume by same negative value -B and exported it again in FLAC which, in my opinion, is equivalent to harking back to original volume and spectrum but it didn't work at all. Was that predictible ?

Pomegranate
24th January 2013, 18:16
So, finally I I import a FLAC on audacity and export it in FLAC ten times, without modifying it, I can deduce it will be lossless. I tried another weird process : raise the volume by a fixed number B and export it in FLAC ; of course the spectrum has been touched but I reopened this last FLAC file and lowered back the volume by same negative value -B and exported it again in FLAC which, in my opinion, is equivalent to harking back to original volume and spectrum but it didn't work at all. Was that predictible ?

So, you did :

Flac1 -> volume change -> Flac2 -> volume change -> Flac3
and you'd like Flac3 to be identical to be identical to Flac1?

It didn't work because Flac2 was dithered down to 16 bit from floating point 32 to 16 bit, then its bit depth was increased again to float 32 and dithered down again to 16 bit to get flac3.

sirt
24th January 2013, 18:33
In fact I would have thought raising volume by B factor, exporting in FLAC, and reversing the later FLAC by -B factor and eventually export it in FLAC again may lead to original volume (+B-B=0) but it seems it is not bijective in any way ! The same rationale would apply to any type of transformation in this case : if you operate transformation A and export the result then reopen this and apply transformation A^-1 it doesn't work.

Pomegranate
24th January 2013, 19:09
After you increase volume, do file> export > for save as type, choose "other uncompressed files" > choose options > header "wav", encoding "32 bit float" > save.

Now import the wav file you just saved, decrease volume, then export to flac 16 bit.

I'm not sure it will match exactly to your original, but it should be nearly identical.

Ghitulescu
25th January 2013, 10:56
So, finally I I import a FLAC on audacity and export it in FLAC ten times, without modifying it, I can deduce it will be lossless.
I am not sure about audacity, in some cases is a black box. But if you use the flac.exe, you can do this so many times you want, like archiving and deachiving files with eg WinRAR (no commercial ad here).
I tried another weird process : raise the volume by a fixed number B and export it in FLAC ; of course the spectrum has been touched but I reopened this last FLAC file and lowered back the volume by same negative value -B and exported it again in FLAC which, in my opinion, is equivalent to harking back to original volume and spectrum but it didn't work at all. Was that predictable?
Of course it was. The more evident if that number B was not an integer, which I believe it was the case as few music pieces I know supports the multiplying with 2, let alone with 3 or more.
You have sample W amounting to -9999. Multiply this with 1.5 (50% gain). The result is 14998.5. How can express this in integers? Probably by rounding it up to -14999. Now divide the result again by 1.5, to recover the original value of -9999 :) for sample W. But in practice people normalising to 98% (to give the well-known value) rarely use these nice numbers, but more likely 1.11234 or so, depending on the initial values.
Remember, this is the pure mathematical aspect, which in practice made audible issues, said the golden ears, thus almost no "volume changer" works that simple, most of them use dithering, like for bit-depth change (16->24, or 24->16).

jkauff
25th January 2013, 15:03
Audacity imports 16 bit flac (and 16 bit wav) as 32 bit floating point wav by default, maybe because things like volume change, normalizing, etc, are floating point operations. This can be changed in the settings. I think what jkauff was trying to say by using "upsampling" and "downsampling" is bit depth increase and reduction.
Thanks, you're quite right that "bit depth increase and reduction" is more correct. I also didn't mean to imply that dithering is part of the bit depth processing, but as I read the documentation Audacity chooses to apply dithering by default when you request that operation. My understanding also is that Audacity uses PCM, not WAV, as its native format. You can export to WAV (Microsoft) or AIFF (Apple) PCM containers.

Asmodian
25th January 2013, 23:33
WAV is PCM with a header, in the context of the audio data (and ignoring little-endian vs. big-endian) WAV = AIFF = PCM. Converting between these is trivial and completely lossless.

Dithering is actually part of the bit depth processing, dithering only makes sense when changing the bit depth.

jkauff
26th January 2013, 18:27
WAV is PCM with a header, in the context of the audio data (and ignoring little-endian vs. big-endian) WAV = AIFF = PCM. Converting between these is trivial and completely lossless.

Dithering is actually part of the bit depth processing, dithering only makes sense when changing the bit depth.
I thought Audacity gave you the option of not using dithering, but I was wrong. I also thought it gave you the option of what dithering algorithm to use, but apparently I was wrong about that, too.

Personally, I use the SoX routines through the TAudioConverter GUI for transcoding when no editing is needed. I guess if I were really curious about what Audacity uses I could search the source code.

tebasuna51
26th January 2013, 19:00
I thought Audacity gave you the option of not using dithering, but I was wrong...

Maybe Preferences -> Quality -> Dither: none

sirt
3rd March 2013, 13:31
Sorry for getting back at this but I have another questions : let's say I have an original WAV file, 44100 kHz, 1411 kbit/s (common sampling rate and bitrate)

Then image I encode it to FLAC and I end up with a 990 kbit/s file. How is that possible it is lossless ? Indeed, when encoding to FLAC the resulting bitrate is always lower than original bitrate. Doesn't that mean a few amount of bits are notwithstanding wasted ? In the same vein, the resulting FLAC file generally weighs 20/30 mb whereas original WAV weighs 50/60 Mb which means you loose around 20 mb between too files. So where are those bits "gone" ?

Finally, after reading around, it looks like resampling a file is generally a bad idea : for example, I have many DVDS that feature also music at 48000 kHz. If I resample them to 44100 kHz, it appears it is bad to do that and also to recode them to FLAC after this operation. Why ? I have never noticed anything special after resampling a lossless audio.

Guest
3rd March 2013, 14:40
http://en.wikipedia.org/wiki/Lossless_compression

The simplest example is probably run-length encoding.

Think about when you put files into a ZIP file. You get a smaller size but you don't lose any information. The link I gave contains a link to an article about methods of lossless compression, so if you are interested you can see how the "magic" is accomplished. Ultimately, it is redundancy in the source that makes lossless compression possible.

pandy
4th March 2013, 17:14
pandy, even if you are right, it looks like this "improvement" you bring out is not clearly justified with the above samples by detmek : not only you can't hear any difference but one spectrum is also similar to another. Would you mind showing us an example of untouched/dithered audio where the difference is noticeable ?


Just requantize 16 bit CD sample to 8 bit with and without dither - 8 bit is exactly same as 16 except that quantization error is 256 times bigger. If You ask about my personal hearing abilities then i will say that i can't distinguish correctly dithered and noise shaped audio when i down converting from 24 to 14 bits where if im not using any additional processing i can distinguish between 14 and 24 bit audio (SOX used for comparison).



So, finally if I import a FLAC on audacity and export it in FLAC ten times, without modifying it, I can deduce it will be lossless. I tried another weird process : raise the volume by a fixed number B and export it in FLAC ; of course the spectrum has been touched but I reopened this last FLAC file and lowered back the volume by same negative value -B and exported it again in FLAC which, in my opinion, is equivalent to harking back to original volume and spectrum but it didn't work at all. Was that predictible ?

There is no sense to visually compare spectrum as spectrum is not direct bit representation - FFT + windowing imply bit conversion - just use from your command line: fc /b file1 file2 >result.txt

paradoxical
4th March 2013, 19:16
Sorry for getting back at this but I have another questions : let's say I have an original WAV file, 44100 kHz, 1411 kbit/s (common sampling rate and bitrate)

Then image I encode it to FLAC and I end up with a 990 kbit/s file. How is that possible it is lossless ? Indeed, when encoding to FLAC the resulting bitrate is always lower than original bitrate. Doesn't that mean a few amount of bits are notwithstanding wasted ? In the same vein, the resulting FLAC file generally weighs 20/30 mb whereas original WAV weighs 50/60 Mb which means you loose around 20 mb between too files. So where are those bits "gone" ?

Yes, a FLAC file will be smaller because raw PCM data is uncompressed and contains lots of redundancy. The bits don't go anywhere, they are just represented in a more efficient manner by removing redundancy where possible without throwing out any data.

sirt
8th March 2013, 21:56
Thanks for those clarifications guys. Then I deduce, redundancy is unavoidable in this case and its used by FLAC encoder to shorten the file.

pandy
13th March 2013, 12:43
Yes, a FLAC file will be smaller because raw PCM data is uncompressed and contains lots of redundancy.

Except noise (very high chance) where FLAC can provide slightly bigger file than RAW PCM (as real noise is not redundant).