Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
FLAC
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Design == FLAC is a lossless encoding of [[linear pulse-code modulation]] data.<ref name="format-about">{{Cite web|last=Coalson|first=Josh|title=About the FLAC Format|url=https://xiph.org/flac/documentation_format_overview.html|access-date=13 February 2022}}</ref> === File structure === A FLAC file consists of the [[File format#Magic number|magic number]] <code>fLaC</code>, [[metadata]], and encoded audio.<ref name="format-about"/> The encoded audio is divided into frames, each of which consists of a header, a data block, and a [[CRC16]] checksum. Each frame is encoded independent of each other. A frame header begins with a [[sync word]], used to identify the beginning of a valid frame. The rest of the header contains the number of samples, position of the frame, channel assignment, and optionally the [[sample rate]] and [[audio bit depth|bit depth]]. The data block contains the audio information.<ref name="format-about"/> Metadata in FLAC precedes the audio. Properties like the [[sample rate]] and the number of channels are always contained in the metadata. It may also contain other information, the [[album cover]] for example.<ref name="format-about"/> FLAC uses [[Vorbis comment]]s for textual metadata like track title and artist name. === Encoding and decoding === [[File:FLAC_1.5.0_screenshot.webp|thumb|250x250px|Screenshot of <code>flac</code> command-line software]] The FLAC encoding algorithm consists of multiple stages. In the first stage, the input audio is split into blocks. If the audio [[stereo|contains multiple channels]], each channel is encoded separately as a subblock. The encoder then tries to find a good mathematical approximation of the block, either by fitting a simple [[polynomial]], or through general [[linear predictive coding]]. A description of the approximation, which is only a few bytes in length, is then written. Finally, the difference between the approximation and the input, called residual, is encoded using [[Rice coding]]. In many cases, a description of the approximation and the encoded residual takes up less space than using [[pulse-code modulation]].<ref name="format-about"/> The decoding process is the reverse of encoding. The compressed residual is first decoded.<ref>{{cite web |title=stream_decoder.c |url=https://gitlab.xiph.org/xiph/flac/-/blob/a2fe43f64e7ce8057fb274c64996568d69b301b8/src/libFLAC/stream_decoder.c |website=libFLAC |access-date=19 February 2022 |ref=libflac_stream_decoder}}</ref><ref>[[#libflac_stream_decoder|libFLAC/stream_decoder.c]], line 2734.</ref> The description of the mathematical approximation is then used to calculate a waveform. The result is formed by adding the residual and the calculated waveform.<ref>{{cite web |title=lpc.c |url=https://gitlab.xiph.org/xiph/flac/-/blob/a2fe43f64e7ce8057fb274c64996568d69b301b8/src/libFLAC/lpc.c |website=libFLAC |access-date=19 February 2022 |ref=libflac_lpc}}</ref><ref>[[#libflac_lpc|libFLAC/lpc.c]], lines 813β820.</ref> As FLAC [[lossless compression|compresses losslessly]], the decoded waveform is identical to the waveform before encoding. For two-channel stereo, the encoder may choose to [[joint stereo|joint-encode]] the audio. The channels are transformed into a side channel, which is the difference between the two input channels, and a mid channel, the sum of the two input channels. In place of a mid channel, the left channel or the right channel may be encoded instead, which is sometimes more space-efficient.<ref>{{Cite web |title=FLAC Format Specification |url=https://xiph.org/flac/format.html |access-date=19 February 2022 |website=FLAC}}</ref> Even though the [[reference implementation|reference encoder]] uses a single block size for the whole stream,<ref name="format-about"/> FLAC allows the block size in samples to vary per block. === Compression === The amount of compression is determined by various parameters, including the order of the linear prediction model and the block size. Regardless of the amount of compression, the original data can always be reconstructed perfectly. For the user's convenience, the reference implementation defines 9 compression levels, which are [[default (computer science)|presets]] of the more technical parameters to the encoding algorithm. The levels are labeled from 0 to 8, with higher numbers resulting in a higher compression ratio, at the cost of compression speed. The meaning of each compression level varies by implementation.<ref>{{Cite web |url=http://www.cuetools.net/wiki/CUETools_FLAC_encoders_comparison |title=CUETools FLAC encoders comparison |website=CUETools Wiki |access-date=27 May 2013}}</ref><ref>{{cite web |url=http://wiki.jriver.com/index.php/Encoding_Settings |title=Encoding Settings |website=JRiver Media Centre |access-date=27 May 2013}}</ref> FLAC is optimized for decoding speed at the expense of encoding speed. A benchmark has shown that, while there is little variation in decoding speed as compression level increases, beyond the default compression level 5, the encoding process takes up considerably more time with little space saved compared to level 5.<ref>{{cite web |title=Lossless Codec Comparison |url=http://synthetic-soul.co.uk/comparison/lossless/index.asp |website=Synthetic-soul.co.uk |access-date=26 November 2016 |archive-url=https://web.archive.org/web/20090202063734/http://synthetic-soul.co.uk/comparison/lossless/index.asp |archive-date=2 February 2009 |url-status=dead }}</ref> === Implementation === Alongside the format, the FLAC project also contains a [[free and open-source]] reference implementation of FLAC called libFLAC. libFLAC contains facilities to encode and decode FLAC data and to manipulate the metadata of FLAC files. libFLAC++, an [[object-oriented]] wrapper around libFLAC for [[C++]], and the [[command-line program]]s <code>flac</code> and <code>metaflac</code>, are also part of the reference implementation. The FLAC format, along with libFLAC, are not known to be covered by any [[software patent|patents]], and anyone is free to write their own implementations of FLAC.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)