A single-file, dependency-free FLAC decoder written in modern C# (.NET 8+). The core of this repository is FlacDecoder.cs which can be easily integrated into other projects.
A console demo is included, but the main purpose of this repository is to share the FlacDecoder implementation.
- Pure C# implementation with no
unsafecode or native dependencies. - Decoder is entirely self-contained in a single file (
FlacDecoder.cs). - Optimized for performance while maintaining readability.
- Permissively licensed (MIT).
- Support for non-whole-byte bit depths (e.g. 20 bits per sample) and 8 bits per sample is disabled by default. You can enable it with the
AllowNonstandardByteOutputoption, but note that in these cases the byte output is incompatible with the byte format used in PCM WAV files.
using FlacDecoder decoder = new("input.flac");
while (decoder.DecodeFrame()) {
// Access decoded data via:
// * BufferSamples: long[0..ChannelCount][0..BufferSampleCount]
// * BufferBytes: byte[0..BufferByteCount]
}dotnet run -c Release -- input.flac output.wav- C# port and enhancements: J.D. Purcell
- Original Java implementation: Project Nayuki (nayuki.io)