FLAC Logo
  home  |   news  |   download  |   features  |   goals  |   format  |   id  |   comparison  |   documentation  |   developers  
documentation

This page is broken up into the following sections:

  • format - the user-level view of the FLAC format (for a more detailed explanation see the format page).
  • flac - the usage of the command-line file encoder/decoder flac.
  • metaflac - the usage of the command-line FLAC metadata editor metaflac.
  • plugins - documentation for the various input plugins.
  • libFLAC API - for developers who want to add FLAC support to their programs.
  • bugs - known bugs.

Keep in mind that the online version of this document will always apply to the latest release. For older releases, check the documentation included with the release package.

format

flac has been tuned so that the default options yield a good speed vs. compression tradeoff for many kinds of input. However, if you are looking to maximize the compression rate or speed, or want to use the full power of FLAC's metadata system, this section is for you. If not, just skip to the next section.

The basic structure of a FLAC stream is:

  • The four byte string "fLaC"
  • The STREAMINFO metadata block
  • Zero or more other metadata blocks
  • One or more audio frames

The first four bytes are to identify the FLAC stream. The metadata that follows contains all the information about the stream except for the audio data itself. After the metadata comes the encoded audio data.

METADATA

FLAC defines several types of metadata blocks (see the format page for the complete list. Metadata blocks can be any length and new ones can be defined. A decoder is allowed to skip any metadata types it does not understand. Only one is mandatory: the STREAMINFO block. This block has information like the sample rate, number of channels, etc., and data that can help the decoder manage its buffers, like the minimum and maximum data rate and minimum and maximum block size. Also included in the STREAMINFO block is the MD5 signature of the unencoded audio data. This is useful for checking an entire stream for transmission errors.

Other blocks allow for padding, seek tables, and application-specific data. You can see flac options below for adding PADDING blocks or specifying seek points. FLAC does not require seek points for seeking but they can speed up seeks, or be used for cueing in editing applications.

Also, if you have a need of a custom metadata block, you can define your own and request an ID here. Then you can reserve a PADDING block of the correct size when encoding, and overwrite the padding block with your APPLICATION block after encoding. The resulting stream will be FLAC compatible; decoders that are aware of your metadata can use it and the rest will safely ignore it.

AUDIO DATA

After the metadata comes the encoded audio data. Audio data and metadata are not interleaved. Like most audio codecs, FLAC splits the unencoded audio data into blocks, and encodes each block separately. The encoded block is packed into a frame and appended to the stream. The reference encoder uses a single block size for the whole stream but the FLAC format does not require it.

BLOCKING

The block size is an important parameter to encoding. If it is too small, the frame overhead will lower the compression. If it is too large, the modeling stage of the compressor will not be able to generate an efficient model. Understanding FLAC's modeling will help you to improve compression for some kinds of input by varying the block size. In the most general case, using linear prediction on 44.1kHz audio, the optimal block size will be between 2-6 ksamples. flac defaults to a block size of 4608 in this case. Using the fast fixed predictors, a smaller block size is usually preferable because of the smaller frame header.

INTER-CHANNEL DECORRELATION

In the case of stereo input, once the data is blocked it is optionally passed through an inter-channel decorrelation stage. The left and right channels are converted to center and side channels through the following transformation: mid = (left + right) / 2, side = left - right. This is a lossless process, unlike joint stereo. For normal CD audio this can result in significant extra compression. flac has two options for this: -m always compresses both the left-right and mid-side versions of the block and takes the smallest frame, and -M, which adaptively switches between left-right and mid-side.

MODELING

In the next stage, the encoder tries to approximate the signal with a function in such a way that when the approximation is subracted, the result (called the residual, residue, or error) requires fewer bits-per-sample to encode. The function's parameters also have to be transmitted so they should not be so complex as to eat up the savings. FLAC has two methods of forming approximations: 1) fitting a simple polynomial to the signal; and 2) general linear predictive coding (LPC). I will not go into the details here, only some generalities that involve the encoding options.

First, fixed polynomial prediction (specified with -l 0) is much faster, but less accurate than LPC. The higher the maximum LPC order, the slower, but more accurate, the model will be. However, there are diminishing returns with increasing orders. Also, at some point (around order 9) the part of the encoder that guesses what is the best order to use will start to get it wrong and the compression will actually decrease slightly; at that point you will have to you will have to use the exhaustive search option -e to overcome this, which is significantly slower.

Second, the parameters for the fixed predictors can be transmitted in 3 bits whereas the parameters for the LPC model depend on the bits-per-sample and LPC order. This means the frame header length varies depending on the method and order you choose and can affect the optimal block size.

RESIDUAL CODING

Once the model is generated, the encoder subracts the approximation from the original signal to get the residual (error) signal. The error signal is then losslessly coded. To do this, FLAC takes advantage of the fact that the error signal generally has a Laplacian (two-sided geometric) distribution, and that there are a set of special Huffman codes called Rice codes that can be used to efficiently encode these kind of signals quickly and without needing a dictionary.

Rice coding involves finding a single parameter that matches a signal's distribution, then using that parameter to generate the codes. As the distribution changes, the optimal parameter changes, so FLAC supports a method that allows the parameter to change as needed. The residual can be broken into several contexts or partitions, each with it's own Rice parameter. flac allows you to specify how the partitioning is done with the -r option. The residual can be broken into 2^n partitions, by using the option -r n,n. The parameter n is called the partition order. Furthermore, the encoder can be made to search through m to n partition orders, taking the best one, by specifying -r m,n. Generally, the choice of n does not affect encoding speed but m,n does. The larger the difference between m and n, the more time it will take the encoder to search for the best order. The block size will also affect the optimal order.

FRAMING

An audio frame is preceded by a frame header and trailed by a frame footer. The header starts with a sync code, and contains the minimum information necessary for a decoder to play the stream, like sample rate, bits per sample, etc. It also contains the block or sample number and an 8-bit CRC of the frame header. The sync code, frame header CRC, and block/sample number allow resynchronization and seeking even in the absence of seek points. The frame footer contains a 16-bit CRC of the entire encoded frame for error detection. If the reference decoder detects a CRC error it will generate a silent block.

MISCELLANEOUS

In order to support come common types of metadata, the reference decoder knows how to skip ID3V1 and ID3V2 tags so it is safe to tag FLAC files in this way. ID3V2 tags must come at the beginning of the file (before the "fLaC" marker) and ID3V1 tags must come at the end of the file.

flac has a verify option -V that verifies the output while encoding. With this option, a decoder is run in parallel to the encoder and its output is compared against the original input. If a difference is found flac will stop with an error.

flac

flac is the command-line file encoder/decoder. The input to the encoder and the output to the decoder must either be RIFF WAVE format, or raw interleaved sample data. flac only supports linear PCM samples (in other words, no A-LAW, uLAW, etc.). Another restriction (hopefully short-term) is that the input must be 8, 16, or 24 bits per sample. This is not a limitation of the FLAC format, just the reference encoder/decoder.

flac assumes that RIFF WAVE files will have the extension ".wav"; this may be overridden with a command-line option. For piped-in data, flac tries to determine the type by looking at the beginning of the file. Other than this, flac makes no assumptions about file extensions, though the convention is that FLAC files have the extension ".flac" (or ".fla" on ancient file systems like FAT-16).

Before going into the full command-line description, a few other things help to sort it out: 1) flac encodes by default, so you must use -d to decode; 2) the options -0 .. -9 that control the compression level actually are just synonyms for different groups of specific encoding options (described later) and you can get the same effect by using the same options; 3) flac behaves similarly to gzip in the way it handles input and output files.

flac will be invoked one of four ways, depending on whether you are encoding, decoding, testing, or analyzing:

In any case, if no inputfile is specified, stdin is assumed. If only one inputfile is specified, it may be "-" for stdin. When stdin is used as input, flac will write to stdout. Otherwise flac will perform the desired operation on each input file to similarly named output files (meaning for encoding, the extension will be replaced with ".flac", or appended with ".flac" if the input file has no extension, and for decoding, the extension will be ".wav" for WAVE output and ".raw" for raw output). The original file is not deleted unless --delete-input-file is specified.

If you are encoding/decoding from stdin to a file, you should use the -o option like so:

  • flac [options] -o outputfile
  • flac -d [options] -o outputfile
which are better than:
  • flac [options] > outputfile
  • flac -d [options] > outputfile
since the former allows flac to seek backwards to write the STREAMINFO or RIFF WAVE header contents when necessary.

Also, you can force output data to go to stdout using -c.

The encoding options affect the compression ratio and encoding speed. The format options are used to tell flac the arrangement of samples if the input file (or output file when decoding) is a raw file. If it is a RIFF WAVE file the format options are not needed since they are read from the WAVE header.

In test mode, flac acts just like in decode mode, except no output file is written. Both decode and test modes detect errors in the stream, but they also detect when the MD5 signature of the decoded audio does not match the stored MD5 signature, even when the bitstream is valid.

General Options
-d Decode (flac encodes by default). 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.
-t Test (same as -d except no decoded file is written). The exit codes are the same as in decode mode.
-a Analyze (same as -d except an analysis file is written). The exit codes are the same as in decode mode. This option is mainly for developers; the output will be a text file that has data about each frame and subframe.
-c Write output to stdout
-s Silent: do not show encoding/decoding statistics.
-o filename Force the output file name (usually flac just changes the extension).
--delete-input-file Automatically delete the input file after a successful encode or decode. If there was an error (including a verify error) the input file is left intact.
--skip # Skip over the first # of samples of the input. This works for both encoding and decoding, but not testing.

Analysis Options
--a-rtext Includes the residual signal in the analysis file. This will make the file very big, much larger than even the decoded file.
--a-rgp Generates a gnuplot file for every subframe; each file will contain the residual distribution of the subframe. This will create a lot of files.

Encoding Options
--lax Allow encoder to generate non-Subset files. The resulting FLAC file may not be streamable, so you should only use this option in combination with custom encoding options meant for archival. File decoders will still be able play (and seek in) such files.
-S { # | X | #x } Include a point or points in a SEEKTABLE:
  • : a specific sample number for a seek point
  • : a placeholder point (always goes at the end of the SEEKTABLE)
  • #x : # evenly spaced seekpoints, the first being at sample 0
You may use many -S options; the resulting SEEKTABLE will be the unique-ified union of all such values.
With no -S options, flac defaults to '-S 100x'. Use -S- for no SEEKTABLE.
NOTE: -S #x will not work if the encoder can't determine the input size before starting.
NOTE: if you use -S # and # is >= samples in the input, there will be either no seek point entered (if the input size is determinable before encoding starts) or a placeholder point (if input size is not determinable).
-P # Tell the encoder to write a PADDING metadata block of the given length (in bytes) after the STREAMINFO block. -P 0 implies no PADDING block, which is the default. This is useful if you plan to tag the file later with an APPLICATION block; instead of having to rewrite the entire file later just to insert your block, you can write directly over the PADDING block.
-b # Specify the block size in samples. The default is 1152 for -l 0, otherwise 4608. Subset streams must use one of 192/576/1152/2304/4608/256/512/1024/2048/4096/8192/16384/32768. The reference encoder uses the same block size for the entire stream.
-m Enable mid-side coding (only for stereo streams). Tends to increase compression by a few percent on average. For each block both the stereo pair and mid-side versions of the block will be encoded, and smallest resulting frame will be stored. Currently mid-side encoding is only available when bits-per-sample <= 16.
-M Enable loose mid-side coding (only for stereo streams). Like -m but the encoder adaptively switches between independent and mid-side coding, which is faster but yields less compression than -m (which does an exhaustive search).
-0 .. -9 Fastest compression .. highest compression. The default is -5.
-0 Synonymous with -l 0 -b 1152 -r 2,2
-1 Synonymous with -l 0 -b 1152 -M -r 2,2
-2 Synonymous with -l 0 -b 1152 -m -r 3
-3 Synonymous with -l 6 -b 4608 -r 3,3
-4 Synonymous with -l 8 -b 4608 -M -r 3,3
-5 Synonymous with -l 8 -b 4608 -m -r 3,3
-6 Synonymous with -l 8 -b 4608 -m -r 4
-7 Synonymous with -l 8 -b 4608 -m -e -r 6
-8 Synonymous with -l 12 -b 4608 -m -e -r 6
-9 Synonymous with -l 32 -b 4608 -m -e -r 16 -p. This is painfully slow but gives you the maximum compression flac can do for the given block size.
-e Exhaustive model search (expensive!). Normally the encoder estimates the best model to use and encodes once based on the estimate. With an exhaustive model search, the encoder will generate subframes for every order and use the smallest. If the max LPC order is high this can significantly increase the encode time but can shave off another 0.5%.
-l # Specifies the maximum LPC order. This number must be <= 32. If 0, the encoder will not attempt generic linear prediction, and use only fixed predictors. Using fixed predictors is faster but usually results in files being 5-10% larger.
-q # Specifies the precision of the quantized LP coefficients, in bits. The default is -q 0, which means let the encoder decide based on the signal. Unless you really know your input file it's best to leave this up to the encoder.
-p Do exhaustive LP coefficient quantization optimization. This option overrides any -q option. It is expensive and typically will only improve the compression a tiny fraction of a percent. -q has no effect when -l 0 is used.
-r [#,]# Set the [min,]max residual partition order. The min value defaults to 0 if unspecified.
By default the encoder uses a single Rice parameter for the subframe's entire residual. With this option, the residual is iteratively partitioned into 2^min# .. 2^max# pieces, each with its own Rice parameter. Higher values of max# yield diminishing returns. The most bang for the buck is usually with -r 2,2 (more for higher block sizes). This usually shaves off about 1.5%. The technique tends to peak out about when blocksize/(2^n)=128. Use -r 0,16 to force the highest degree of optimization.
-R # Set the Rice parameter search distance. Defaults to 0. The residual coder will search for the best Rice parameter +/- this number for each residual partition. This option is expensive (run time for -R n will typically be (2n)*30% over that of -R 0) and doesn't give much of a gain. As a matter of fact, none of the -0..-9 options currently use it since -R > 1 is not consistently better like it should be.
-V Verify the encoding process. With this option, flac will create a parallel decoder that decodes the output of the encoder and compares the result against the original. It will abort immediately with an error if a mismatch occurs. -V increases the total encoding time but is guaranteed to catch any unforseen bug in the encoding process.
-S-, -m-, -e-, -p-, -V-, --delete-input-file-, --lax- can all be used to turn off a particular option.

Format Options
-fb | -fl Specify big-endian | little-endian byte order in the raw file.
-fc # Specify the number of channels in the raw file.
-fp # Specify the number of bits per sample in the raw file.
-fs # Specify the sample rate of the raw file.
-fu Specify that the samples in the raw file are unsigned (the default is signed).
-fr Treat the input file (or output file if decoding) as a raw file, regardless of the extension.
-fw Treat the input file (or output file if decoding) as a RIFF WAVE file, regardless of the extension.

metaflac

metaflac is the command-line .flac file metadata editor. Right now it just lists the contents of all metadata blocks in a .flac file, but soon it will allow you to insert, delete, and edit blocks.

Currently metaflac can be invoked only one way:

  • Listing: metaflac [-v] inputfile

inputfile may be "-" for stdin. If -v is used, you will get verbose output.

xmms plugin

All that is necessary is to copy libxmms-flac.so to the directory where XMMS looks for input plugins (usually /usr/lib/xmms/Input). There is nothing else to configure. Make sure to restart XMMS before trying to play any .flac files.

winamp plugin

All that is necessary is to copy in_flac.dll to the Plugins/ directory of your Winamp installation. There is nothing else to configure. Make sure to restart Winamp before trying to play any .flac files.

libFLAC

The FLAC library libFLAC is a C implementation of reference encoders and decoders. By linking against libFLAC and writing a little code, it is relatively easy to add FLAC support to another program. The library is licensed under the LGPL. Complete source code of libFLAC as well as the command-line encoder and plugins is available and is a useful source of examples.

libFLAC usually only requires the standard C library and C math library. In particular, threading is not used so there is no dependency on a thread library. However, libFLAC does not use global variables and should be thread-safe.

The libFLAC interface is described in the public header files in the include/FLAC directory. The public headers and the compiled library are all that is needed to compile and link against the library. Note that none of the code in src/libFLAC/, including the private header files in src/libFLAC/include/ is required.

The basic usage of libFLAC is as follows:

  1. The program creates an instance of a decoder or encoder using *_new().
  2. The program sets the parameters of the instance and callbacks for reading, writing, error reporting, and metadata reporting using *_set_*() functions.
  3. The program initializes the instance to validate the parameters and prepare for decoding/encoding using *_init().
  4. The program calls *_process_*() functions to encode or decode data, which subsequently calls the callbacks.
  5. The program finishes the instance with *_finish(), which flushes the input and output.
  6. The instance may be used again or deleted with *_delete().

For decoding, libFLAC provides two layers of access. The lowest layer is stream-level decoding, and the highest level is file-level decoding, which is a wrapper around the stream decoder. The interfaces are described in stream_decoder.h and file_decoder.h respectively. The file decoder supplies the read callback internally and provides seek functions. Currently there is only one level of encoder implementation which is at the stream level (stream_encoder.h). There is no currently no file encoder because seeking within a file while encoding seemed like too obscure a feature.

Structures and constants related to the format are defined in format.h.

STREAM DECODER

First we discuss the stream decoder. The instance type is FLAC__StreamDecoder. Typically the program will create a new instance by calling FLAC__stream_decoder_new(), then call FLAC__stream_decoder_set_*() functions to set the callbacks and client data, and call FLAC__stream_decoder_init(). The required callbacks are:

  • Read callback - This function will be called when the decoder needs more input data. The address of the buffer to be filled is supplied, along with the number of bytes the buffer can hold. The callback may choose to supply less data and modify the byte count but must be careful not to overflow the buffer. The callback then returns a status code chosen from FLAC__StreamDecoderReadStatus.
  • Write callback - This function will be called when the decoder has decoded a single frame of data. The decoder will pass the frame metadata as well as an array of pointers (one for each channel) pointing to the decoded audio.
  • Metadata callback - This function will be called when the decoder has decoded a metadata block. There will always be one STREAMINFO block per stream, followed by zero or more other metadata blocks. These will be supplied by the decoder in the same order as they appear in the stream and always before the first audio frame.
  • Error callback - This function will be called whenever an error occurs during decoding.

Once the decoder is initialized, the program will call one of several functions to stimulate the decoding process:

  • FLAC__stream_decoder_process_whole_stream() - Tells the decoder to start and continue processing the stream until the read callback says FLAC__STREAM_DECODER_READ_END_OF_STREAM or FLAC__STREAM_DECODER_READ_ABORT.
  • FLAC__stream_decoder_process_metadata() - Tells the decoder to start processing the stream and stop upon reaching the first audio frame.
  • FLAC__stream_decoder_process_one_frame() - Tells the decoder to process one audio frame and return. The decoder must have processed all metadata first before calling this function.
  • FLAC__stream_decoder_process_remaining_frames() - Tells the decoder to process all remaining frames. The decoder must have processed all metadata first but may also have processed frames with FLAC__stream_decoder_process_one_frame().

When the decoder has finished decoding (normally or through an abort), the instance is finished by calling FLAC__stream_decoder_finish(), which ensures the decoder is in the correct state and frees memory. Then the instance may be deleted with FLAC__stream_decoder_delete() or initialized again to decode another stream.

Note that the stream decoder has no real concept of stream position, it just converts data. To seek within a stream the callbacks have only to flush the decoder using FLAC__stream_decoder_flush() and start feeding data from the new position through the read callback. The file decoder does just this.

FILE DECODER

The file decoder is a wrapper around the stream decoder meant to simplfy the process of decoding from a file. The instance type is FLAC__FileDecoder. The flow and callbacks are similar to that of the stream decoder. However, a file path replaces the read callback argument during initialization. The program needs only to provide the path to the file and the file decoder handles the read callbacks. The remaining callbacks and process functions are analogous to their stream decoder counterparts.

Since the file decoder manages the input automatically, it also can provide seeking. This is exposed through the FLAC__file_decoder_seek_absolute() method. At any point after the file decoder has been initialized, the program can call this function to seek to an exact sample within the file. Subsequently, the first time the write callback is called it will contain a (possibly partial) block starting at that sample.

The file decoder also provides MD5 signature checking. If this is turned on before initialization, FLAC__file_decoder_finish() will report when the decoded MD5 signature does not match the one stored in the STREAMINFO block. MD5 checking is automatically turned off if the is no signature in the STREAMINFO block or when a seek is attempted.

STREAM ENCODER

The stream encoder functions similarly to the stream decoder, but has fewer callbacks and more options. The instance type is FLAC__StreamEncoder. Typically the program will create a new instance by calling FLAC__stream_encoder_new(), then set the necessary parameters with FLAC__stream_encoder_set_*(), and initialize it by calling FLAC__stream_encoder_init().

Unlike the decoding process, FLAC encoding has many options that can affect the speed and compression ratio. When the program calls FLAC__stream_encoder_init() the encoder will validate the values, so you should make sure to check the returned state to see that it is FLAC__STREAM_ENCODER_OK. When setting these parameters you should have some basic knowledge of the format (see the user-level documentation or the formal description) but the required parameters are summarized here:

  • streamable_subset - true to force the encoder to generate a Subset stream, else false.
  • do_mid_side_stereo - true to try mid-side encoding on stereo input, else false. channels must be 2.
  • loose_mid_side_stereo - true to do adaptive mid-side switching, else false. do_mid_side_stereo must be true.
  • channels - must be <= FLAC__MAX_CHANNELS.
  • bits_per_sample - do not give the encoder wider data than what you specify here or bad things will happen.
  • sample_rate - must be <= FLAC__MAX_SAMPLE_RATE.
  • blocksize - must be between FLAC__MIN_BLOCKSIZE and FLAC__MAX_BLOCKSIZE.
  • max_lpc_order - 0 implies encoder will not try general LPC, only fixed predictors; must be <= FLAC__MAX_LPC_ORDER.
  • qlp_coeff_precision - must be >= FLAC__MIN_QLP_COEFF_PRECISION, or 0 to let encoder select based on blocksize. In the current imlementation qlp_coeff_precision+bits_per_sample must be < 32.
  • do_qlp_coeff_prec_search - false to use qlp_coeff_precision; true to search around qlp_coeff_precision and take best.
  • do_exhaustive_model_search - false to use estimated bits per residual for scoring; true to generate all and take shortest.
  • min_residual_partition_order, max_residual_partition_order - 0 to estimate Rice parameter based on residual variance; > 0 to partition the residual and use parameter for each based on mean; min_residual_partition_order and max_residual_partition_order specify the min and max Rice partition order.
  • rice_parameter_search_dist - 0 to try only calculated parameter k; else try all [k-rice_parameter_search_dist..k+rice_parameter_search_dist] parameters and use the best.
  • total_samples_estimate - May be set to 0 if unknown. Otherwise, set this to the number of samples to be encoded. This will allow the STREAMINFO block to be more accurate during the first pass in the event that the encoder can't seek back to the beginning of the output file to write the updated STREAMINFO block.
  • seek_table - Optional seek table to prepend; NULL implies no seek table.
  • padding - Size of PADDING block to add (goes after seek table); 0 implies do not add a PADDING block.
  • last_metadata_is_last - The value the encoder will use for the 'is_last' flag of the last metadata block it writes. In normal usage you would set this to true, but if you will be manually inserting more metadata blocks between the time of the first write callback (when the encoder sends the fLaC header and metadata) and the time actual audio encoding starts then set this to false.

The program provide addresses for the following callbacks:

  • Write callback - This function is called anytime there is raw encoded data to write. It may include metadata mixed with encoded audio frames and the data is not guaranteed to be aligned on frame or metadata block boundaries.
  • Metadata callback - This function is called once at the end of encoding with the populated STREAMINFO structure. This is so file encoders can seek back to the beginning of the file and write the STREAMINFO block with the correct statistics after encoding (like minimum/maximum frame size).
The call to FLAC__stream_encoder_init() currently will also immediately call the write callback with the "fLaC" signature and all the encoded metadata.

After initializing the instance, the program may feed audio data to the encoder in one of two ways:

  • Channel separate, through FLAC__stream_encoder_process() - The program will pass an array of pointers to buffers, one for each channel, to the encoder, each of the same length. The samples need not be block-aligned.
  • Channel interleaved, through FLAC__stream_encoder_process_interleaved() - The program will pass a single pointer to data that is channel-interleaved (i.e. channel0_sample0, channel1_sample0, ... , channelN_sample0, channel0_sample1, ...). Again, the samples need not be block-aligned but they must be sample-aligned, i.e. the first value should be channel0_sampleX and the last value channelN_sampleY.

When the program is finished encoding data, it calls FLAC__stream_encoder_finish(), which causes the encoder to encode any data still in its input pipe, and call the metadata callback with the final encoding statistics. Then the instance may be deleted with FLAC__stream_encoder_delete() or initialized again to encode another stream.

MISCELLANEOUS

It should be noted that any time an array of pointers to audio data is passed, the channel order currently only has meaning for stereo streams. Channel 0 corresponds to the left channel and channel 1 corresponds to the right channel.

METADATA

For programs that write their own APPLICATION metadata, it is advantageous to instruct the encoder to write a PADDING block of the correct size, so that instead of rewriting the whole stream after encoding, the program can just overwrite the PADDING block. If only the maximum size of the APPLICATION block is known, the program can write a slightly larger padding block, then split it after encoding into an APPLICATION block and a PADDING block.

In the case where the size of the APPLICATION block data is known ahead of time, the required size of the padding block can be easily calculated. If the APPLICATION block data length in bytes (not including the APPLICATION metadata block header) is N bytes, the size given to the FLAC__StreamEncoder instance before initialization is simply N+4. This accounts for the extra space needed to store the APPLICATION ID.

In the case where only the maximum size is known, say, to be N bytes, the required padding size would be N+8. Four for the APPLICATION ID as before, and four for the extra PADDING block that will fill up the remainder. At the end of the encoding, when the APPLICATION block data length is known, say, to be M bytes, the original PADDING block would be overwritten with the APPLICATION block and a PADDING block of size N-M.

known bugs

Bug tracking is done on the Sourceforge project page here. If you submit a bug, please provide an email contact and/or use the Monitor feature.

 Copyright (c) 2000,2001 Josh Coalson