Navigation

FLAC library (Java)

This package contains a library for decoding and encoding FLAC files, as well as sample applications. The implementation is in pure Java and is based on my interpretation of the FLAC format specification.

The library is well-documented with many comments, and the code contains numerous assertions to catch invalid data strictly. This library is moderately sophisticated; for beginners learning about the file format, please first read the code in my simple FLAC implementation. The library is much shorter than the official Xiph.Org FLAC implementation in C.

Notes

This FLAC decoder and encoder library can handle up to 32-bit sample depth for completeness, since it is specified by the FLAC format. Xiph.Org’s FLAC encoder and decoder are currently limited to handling a maximum sample depth of 24 bits. In reality there is no audible benefit beyond 20-bit audio, so anything above 24 bits is certainly overkill.

My FLAC encoder can produce streams with variable block sizes, which decreases the output file size. Experiments were conducted and published on my FLAC benchmarks page. Xiph.Org’s FLAC encoder currently doesn’t generate variable-block streams (except the final block can be shorter than the preceding blocks). Xiph.Org’s FLAC decoder does support variable block sizes, so such streams are definitely usable in practice.