FLAC

Over the years, FLAC (Free Lossless Audio Codec) has become one of the most popular open source audio codecs.
It works like Zip; you can compress and decompress audio without loss.
As FLAC is optimized for audio, the compression is much better than with Zip.
Depending on the music the compression rate will be 30%-50%.

 

FLAC supports linear PCM audio:

FLAC's metadata system supports tags, cover art, seek tables, and cue sheets.
It runs on Windows, OSX and Linux.

 

The integrity of the audio data is insured by storing an MD5 signature of the original uuencoded audio data in the file header, which can be compared against later during decoding or testing.

 

FLAC is very well supported.
The exceptions to this rule is Apple.

Apple don't support FLAC. Hence you can't use it with iTunes.

From Win10 (2015) on FLAC is supported by Microsoft.

How it works

FLAC uses linear prediction.
The advantage is that this prediction can be written as a couple of coefficients. They can be stored using very little space. The bad news is that there is nothing linear about audio. Hence there will be a residue.  Store the coefficients + residue in a file and the decoder can reconstruct the original signal by calculating the linear prediction and add the residue to it.

 

The “compression” level of FLAC is the amount of resources FLAC is allowed to spend on finding the best possible linear prediction. Obvious, the better this prediction, the smaller the residue.


However this will affect most of all the amount of CPU used when encoding.
At decoding time (playback), there is no search needed for an optimal solution. The decoder simply calculates the linear prediction using the coefficients supplied and add the residue to it.

 

As FLAC uses FIR Linear prediction for its highest compression level, there is still a small performance penalty at playback time compared with e.g. level 0.
So a higher compression level will most of all affect encoding time and to a far lesser extend affect decoding time.
On todays CPU’s you will probably have a hard time to measure the difference between level 0 and level 8 even when encoding.  I/O I expect to be the limiting factor, not the CPU.

Compression

You can choose 0 – 8 where 0 is the lowest and 8 the highest compression.
This "compression" parameter is a permanent source of misunderstanding.
A lot of people thing that it works like the bitrates in MP3 so higher compression is more loss.

As explained above, the compression parameter simply tells how many CPU FLAC is allowed to use to find the best possible linear prediction. The better the predicition, the lower the residue will be hence a smaller file.
In practice 5 is often recommended as a nice compromise between coding time and file size.
Going from 5 to 8 in general results in a marginal smaller file.
When Josh Coalson started the development of FLAC this parameter made sense.
With today’s CPU’s you probably won’t notice the difference in time between e.g. 0 and 8.

The I/O is the li,iting factor, not the CPU.
Once again, regardless of the compression ratio chosen, the result is always lossless.

Bit rate

If you play a 16/44.1 track (CD audio) ripped to WAV you see a bit rate of 1411 Kbit/s.
Play the same track in FLAC format and you will see a lower value, often around 700.
This confuses a lot of people.
If you play MP3 you see a lower bit rate too so people start wondering if FLAC is lossy too.
As FLAC is compressed, the same information is stored using less bits (otherwise you can't get a smaller file….). The bit rate as displayed by your media player is the amount of bits per second readinf the file, not the bit rate after expansion to linear PCM.

 

From the FLAC website:
With FLAC you do not specify a bitrate like with some lossy codecs. It's more like specifying a quality with Vorbis or MPC, except with FLAC the quality is always "lossless" and the resulting bitrate is roughly proportional to the amount of information in the original signal. You cannot control the bitrate much and the result can be from around 100% of the input rate (if you are encoding noise), down to almost 0 (encoding silence).

 

Obvious the compression and therefore the bit rate you see varies with the complexity of the signal.
You will see differences between tracks but also while playing a track bitrates will vary constantly.

In essence it is VBR (Variable Bit Rate) but lossless all of the time.

Uncompressed FLAC

From 14.1 on, dBpoweramp supports uncompressed FLAC

FLAC encoder wording changed, also includes a FLAC Uncompressed encoding option (which stores audio uncompressed, for those who want WAVE PCM but with better ID Tagging).
Source : dBpoweramp

This sounds like we finally have WAV with excellent tagging options.

It is probably not plain PCM as some think.

 

I don't know FLAC algorithms very well, but I think that decoder still needs to convert FLAC bitstream into plain integer values. It requires such operations as byte swap, bit shift, bitwise or, etc. FLAC file cannot store PCM information 'as is'.

Source: https://github.com/xiph/flac/issues/73#event-1667854824

You can create uncompressed FLAC with parameters
-0 --disable-fixed-subframes --disable-constant-subframes

Zero length

If you need a FLAC with zero length e.g. as a placeholder you can do so using:

 

flac --no-padding --force-raw-format --endian=little --sign=signed --channels=2 --bps=16 --sample-rate=44100 -o zero.flac - </dev/null

 

On Windows, just change /dev/null to NUL

integrity

The integrity of a file can be easily tested by running

FLAC –t FileToTest.FLAC

Flac will exit with an exit code of 1 (and print a message, even in silent mode) if there were any errors during decoding, including when the MD5 checksum does not match the decoded output. Otherwise the exit code will be 0.
http://flac.sourceforge.net/documentation_tools_flac.html

Interface

You don't like typing command lines?

Try this one: FLAC frontend

 

 

References
  1. FLAC – FLAC website
  2. FLAC - Wikipedia
  3. Uncompressed FLAC - J Mac
  4. Ogg Vorbis I format specification - xiph.org
  5. FLAC Frontend - ktficer
  6. How to encode FLAC without any compression? - Hydrogen Audio