Skip to content

About

Pure-Delphi audio codec stack — WAV, FLAC, Vorbis, Opus, MP3. No DLLs, no C bindings. CC0 Public Domain.

Resources

Contributing

Stars

42 stars

Watchers

1 watching

Forks

Repository files navigation

Delphi Libraries Collection

A growing collection of pure-Delphi libraries covering audio codecs, PDF documents, compression, cryptography, image formats, and data serialization.

No DLLs. No C bindings. No external dependencies. Everything compiles with stock Delphi on Windows, Linux, and any RTL-supported platform.

License: CC0 1.0 Universal (Public Domain) — use however you like. Exception: audio/opus-decoder and audio/opus-encoder are faithful ports of libopus and keep its permissive BSD 3-clause license, and two pieces of ITU-T data are not CC0: the G.729 codebook tables and the G.722 test vectors (see Upstream attributions).


Categories

Category Status Description
audio/ ✅ Active WAV, FLAC, Vorbis, Opus, MP3 decoders + WAV & FLAC encoders
pdf/ ✅ Active PDF reader, writer, text/image extractor, encryption, AcroForms, FMX viewer
compression/ 🚧 Planned LZ4, Zstd, LZMA, Brotli
crypto/ 🚧 Planned ChaCha20-Poly1305, Argon2id, X25519
imaging/ 🚧 Planned QOI, TGA, WebP lossless
formats/ 🚧 Planned TOML, resampler, FFT
barcode/ ✅ Active QR Code generator + reader (v1-40, ECC L/M/Q/H, todos los modos, salida BMP/SVG/PNG, lectura desde foto con perspectiva/rotación)

Audio — what is implemented

Core layer — audio/audio-common

Unit Responsibility
AudioTypes.pas TAudioBuffer (planar Single [-1..1]), TAudioInfo, TAudioDecodeResult
AudioBitReader.pas MSB-first and LSB-first bit reader
AudioSampleConv.pas PCM ↔ float conversions: Int8/16/24/32/Float32/64 ↔ Single
AudioCRC.pas CRC-8 (FLAC headers), CRC-16 (FLAC frames), CRC-32 (Ogg pages)

Format libraries

Library Decoder Encoder Notes
audio/wav-codec ✅ ✅ PCM 8/16/24/32, Float32/64, EXTENSIBLE multichannel
audio/flac-codec ✅ ✅ Lossless, all block sizes, all channel counts, stereo modes
audio/ogg-container ✅ ✅ Ogg page reader/writer, packet segmentation, CRC-32
audio/vorbis-decoder ✅ — Ogg Vorbis I — Floor 0/1, all residue types, full VQ
audio/opus-decoder ✅ — SILK + CELT + Hybrid, 48 kHz, mono/stereo (RFC 6716)
audio/opus-encoder — ✅ libopus 1.5.2 port (stage E1: CELT, bit-exact), Ogg Opus writer
audio/mp3-decoder ✅ — MPEG 1/2/2.5, Layer III, 8–320 kbps, all sample rates
audio/g722-codec ✅ ✅ ITU-T G.722 SB-ADPCM, 16 kHz, 64/56/48 kbit/s, bit-exact vs ITU test vectors
audio/g729-codec ✅ ✅ ITU-T G.729 Annex A + Annex B decoder (SID/comfort noise), 8 kbit/s, written from the Recommendation text (floating point, interoperable, not bit-exact)
audio/audio-codec ✅ — Unified IAudioDecoder factory (auto-detect format)
audio/mp3-encoder — ✅ MPEG-1 Layer III CBR/VBR, mono/stereo/joint, short blocks (window switching), bit reservoir, Xing/LAME tag

Test coverage

Suite Tests
AudioCommonTests 78 ✅
WAVCodecTests 70 ✅
FLACCodecTests 99 ✅
FLACEncoderTests 60 ✅
OggContainerTests 69 ✅
VorbisDecoderTests 119 ✅
OpusDecoderTests 85 ✅
MP3DecoderTests 66 ✅
AudioCodecTests 30 ✅
G722Tests 27 ✅
G729Tests 54 ✅
Total 757 ✅

PDF — what is implemented

Core layer — pdf/Src/Core

Unit Responsibility
uPDF.Types Primitive types, TPDFVersion, TPDFRect, save-mode enum, A4/Letter constants
uPDF.Objects Full PDF object model: Null, Boolean, Integer, Real, String, Name, Array, Dictionary, Stream, Reference
uPDF.Lexer Low-level tokenizer (handles all PDF token types, hex strings, inline images)
uPDF.XRef Cross-reference table + XRef stream parser; supports linearized and repaired PDFs
uPDF.Parser High-level parser: resolves indirect objects, rebuilds xref on corruption
uPDF.Document TPDFDocument — open/create/save PDFs; TPDFPage — geometry, resources, content
uPDF.Crypto MD5, RC4, AES-128/256 primitives used by the encryption layer
uPDF.Encryption TPDFDecryptor — Standard handler Rev 2/3/4/6; RC4 + AES, password auth
uPDF.Filters FlateDecode, ASCIIHexDecode, ASCII85Decode, LZWDecode, RunLengthDecode, CCITTFaxDecode (pure Pascal G3/G4), JBIG2Decode (pure Pascal, T.88), DCTDecode (JPEG passthrough)
uPDF.ContentStream Content-stream interpreter (all path/text/color/transform operators) + TPDFContentBuilder
uPDF.GraphicsState Full graphics-state stack: CTM, colors, fonts, line params, clip path
uPDF.ColorSpace DeviceGray/RGB/CMYK, CalGray/RGB, ICCBased, Indexed, Pattern, Separation
uPDF.Font Type0/1/3/TrueType + CIDFont: glyph widths (standard 14 metrics when /Widths is missing), ToUnicode CMap, encodings
uPDF.FontProgram / uPDF.FontCFF / uPDF.FontType1 Embedded TrueType, CFF and Type 1 programs: glyph outlines and code → glyph lookup, used by the renderer
uPDF.StdFonts Standard 14 font metrics, Annex D encodings and Adobe Glyph List (generated; Adobe notices, not CC0)
uPDF.FontCMap CMaps: predefined identities, embedded, Adobe-CNS1/GB1/Japan1/Korea1
uPDF.Image TPDFImage — inline and XObject images; raw bytes + JPEG/Flate decode
uPDF.TextExtractor TPDFTextExtractor — fragments, line grouping, plain-text export
uPDF.ImageExtractor TPDFImageExtractor — enumerate and export embedded images
uPDF.Writer TPDFWriter — serialize any PDF to stream; FlateDecode, XRef streams, object streams
uPDF.Metadata TPDFInfoRecord — Info dict + XMP metadata, date parsing
uPDF.Outline Bookmark tree (TPDFOutlineNode), named destinations
uPDF.Annotations Link, text, highlight and other annotation types
uPDF.AcroForms AcroForm field enumeration (text, checkbox, radio, listbox, signature)

Viewer layer — pdf/Src/FMX + pdf/Src/Render

Unit Responsibility
uPDF.Render.Types Render primitives: TPDFRenderTarget, tile size, resolution
uPDF.Render.FontCache Platform font resolver + glyph-metric cache for rendering
uPDF.Render.Skia Page rasterizer backed by Skia4Delphi — path fill/stroke, text, images
uPDF.Viewer.Cache Tile + page-bitmap LRU cache
uPDF.Viewer.Control TPDFViewerControl — scrollable FMX control, zoom, page navigation

Test coverage

Suite Tests
TestParser 67 ✅
TestWriter 96 ✅
TestTextExtractor 17 ✅
Total 180+ ✅

How to use — native Delphi

Requirements

  • Delphi 12 Athens (or Delphi 11 Alexandria)
  • No external packages. Add the src/ folders you need to your project's library path.

Adding library paths in the IDE

In Tools → Options → Language → Delphi → Library add one entry per library you use (per platform):

...\delphi-libraries\audio\audio-common\src
...\delphi-libraries\audio\wav-codec\src
...\delphi-libraries\audio\flac-codec\src
...\delphi-libraries\audio\ogg-container\src
...\delphi-libraries\audio\vorbis-decoder\src
...\delphi-libraries\audio\opus-decoder\src
...\delphi-libraries\audio\mp3-decoder\src
...\delphi-libraries\audio\audio-codec\src

...\delphi-libraries\pdf\Src\Core
...\delphi-libraries\pdf\Src\FMX       (only for the FMX viewer)
...\delphi-libraries\pdf\Src\Render    (only for the Skia renderer)

audio-common is always required for audio. For PDF, add only Src/Core unless you also need the visual viewer. Add only the libraries you actually uses.

Decode any audio file (unified API)

uses AudioTypes, AudioCodec;

var
  Dec: IAudioDecoder;
  Buf: TAudioBuffer;
begin
  Dec := CreateAudioDecoderFromFile('music.flac'); // .wav .ogg .opus .mp3 also work
  if (Dec = nil) or not Dec.Ready then Exit;

  WriteLn(Format('%d Hz, %d ch', [Dec.Info.SampleRate, Dec.Info.Channels]));
  while Dec.Decode(Buf) = adrOK do
    ProcessAudio(Buf);
end;

Decode specific formats directly

// WAV
var R := TWAVReader.Create;
R.Open('track.wav');
while R.Decode(Buf) = adrOK do ProcessAudio(Buf);

// FLAC — with seek
var D := TFLACStreamDecoder.Create('album.flac');
while D.Decode(Buf) = adrOK do ProcessAudio(Buf);
D.SeekToSample(44100); // jump to 1 second

// Ogg Vorbis
var V := TVorbisDecoder.Create(TOggPageReader.Create(TFileStream.Create('audio.ogg', fmOpenRead), True));
while V.Decode(Buf) = adrOK do ProcessAudio(Buf);

// Opus
var O := TOpusDecoder.Create('podcast.opus');
while O.Decode(Buf) = adrOK do ProcessAudio(Buf);

Encode audio

// Write WAV
var W := TWAVWriter.Create('output.wav', 44100, 2, woPCM16);
W.Write(Buf); W.Finalize;

// Encode FLAC
var E := TFLACStreamEncoder.Create('output.flac', 44100, 2, {bits=}16);
while HaveSamples do begin FillBuffer(Buf); E.Write(Buf); end;
E.Finalize;

Transcode WAV → FLAC (10 lines)

uses AudioTypes, WAVReader, FLACStreamEncoder;

var R := TWAVReader.Create;
R.Open('input.wav');
var E := TFLACStreamEncoder.Create('output.flac',
           R.Format.SampleRate, R.Format.Channels, R.Format.BitsPerSample);
try
  while R.Decode(Buf) = adrOK do E.Write(Buf);
  E.Finalize;
finally
  E.Free; R.Free;
end;

TAudioBuffer layout

type
  TAudioBuffer = record
    Ch     : array[0..7] of PSingle;  // planar channels, index 0..Channels-1
    Samples: Integer;                 // sample frames in this block
  end;

Samples are normalised Single in [-1.0 .. 1.0], planar (all channel-0 samples first, then channel-1, etc.). To interleave for waveOut/WASAPI:

for I := 0 to Buf.Samples - 1 do
begin
  PCM[I * 2]     := Round(Buf.Ch[0][I] * 32767);
  PCM[I * 2 + 1] := Round(Buf.Ch[1][I] * 32767);
end;

Contributing

We welcome contributions in any category. The most impactful open tasks are:

Task Category Difficulty
Resampler (polyphase FIR) formats Medium
LZ4 block encoder/decoder compression Medium
QOI image codec imaging Easy
TOML parser formats Medium
MP3 encoder audio Hard
Vorbis encoder audio Hard
ChaCha20-Poly1305 AEAD crypto Medium

How to contribute:

  1. Fork the repo and create a branch
  2. Add your library under the appropriate category folder
  3. Include a test project with ≥ 30 assertions
  4. All code must be CC0 1.0 — no GPL/LGPL
  5. Submit a pull request

See CONTRIBUTING.md for coding style, naming conventions, and the full PR checklist. Each category folder has its own README.md with more detail on what's needed and relevant references.


Repository structure

delphi-libraries/
├── audio/                 # Audio codecs and utilities
│   ├── audio-common/      #   Base types, bit reader, CRC, sample conv
│   ├── wav-codec/         #   WAV reader + writer
│   ├── flac-codec/        #   FLAC decoder + encoder
│   ├── ogg-container/     #   Ogg page reader + writer
│   ├── vorbis-decoder/    #   Ogg Vorbis I decoder
│   ├── opus-decoder/      #   Ogg Opus decoder (SILK + CELT)
│   ├── mp3-decoder/       #   MP3 Layer III decoder (MPEG 1/2/2.5)
│   ├── g722-codec/        #   ITU-T G.722 encoder + decoder (VoIP wideband)
│   ├── g729-codec/        #   ITU-T G.729A encoder + decoder (VoIP 8 kbit/s)
│   ├── mp3-encoder/       #   MP3 encoder (work in progress)
│   └── audio-codec/       #   Unified IAudioDecoder API + factory
├── pdf/                   # PDF library
│   ├── Src/Core/          #   Parser, writer, text/image extractor, encryption, forms
│   ├── Src/FMX/           #   FMX viewer control
│   ├── Src/Render/        #   Skia-backed page rasterizer
│   ├── Tests/             #   Test projects (TestParser, TestWriter, TestTextExtractor, TestAdvanced)
│   ├── Demo/              #   Demo console apps (report generation, special chars)
│   └── FMXViewer/         #   Demo FMX viewer app
├── compression/           # Compression codecs (planned)
├── crypto/                # Cryptographic primitives (planned)
├── imaging/               # Image codecs (planned)
├── formats/               # Data formats + signal processing (planned)
└── docs/                  # Shared build and architecture docs

Each library follows the same layout:

category/library-name/
├── src/           # .pas source files
├── tests/src/     # test project (.dpr + .dproj)
├── README.md
└── LICENSE.md     # CC0 1.0

Building

call "C:\Program Files (x86)\Embarcadero\Studio\23.0\bin\rsvars.bat"
msbuild audio\flac-codec\tests\src\FLACCodecTests.dproj /p:Config=Release /p:Platform=Win64
Win64\Release\FLACCodecTests.exe

See docs/BUILD.md for the full guide.


License

All code is CC0 1.0 Universal (Public Domain), except the Opus codec ports (audio/opus-decoder, audio/opus-encoder), which are derivative works of libopus and are distributed under the libopus BSD 3-clause license. Two pieces of ITU-T data included in the repository are not CC0 (see the table below and LICENSE.md). https://creativecommons.org/publicdomain/zero/1.0/

Upstream attributions

Library Origin License
audio/mp3-decoder Translated from minimp3 CC0 1.0
audio/opus-decoder, audio/opus-encoder Faithful ports of libopus 1.5.2 (Xiph.Org, Skype et al.) BSD 3-clause (full text in opus-decoder/README.md and opus-encoder/README.md); tests CC0
audio/g729-codec Written from the text of ITU-T G.729 (06/2012) and Annex A/B; the codebook tables in G729Tables.pas are the numbers of TAB_LD8A.C/tab_dtx.c of the ITU-T software package (© AT&T, France Telecom, NTT, Université de Sherbrooke, Rockwell), required for interoperability Code CC0 1.0; tables not CC0 (copyright, if any, of their authors)
audio/g722-codec Written from the text of ITU-T G.722 (09/2012); test vectors in samples/ from the ITU-T STL (G.191) Code CC0 1.0; test vectors under the ITU-T Software Tools GPL (see samples/NOTICE.md)
audio/ogg-container, audio/vorbis-decoder Written from RFC 3533 and the Vorbis I specification (stb_vorbis, public domain, as reference) CC0 1.0
barcode/qr-generator (encoder) Algorithm translated from QR Code generator library (Project Nayuki) CC0 1.0 (see MIT notice in barcode/qr-generator/README.md)
barcode/qr-generator (reader) Algorithm translated from ZXing CC0 1.0 (see Apache 2.0 notice in barcode/qr-generator/README.md)
All other libraries Written from scratch against public standards CC0 1.0

References

About

Pure-Delphi audio codec stack — WAV, FLAC, Vorbis, Opus, MP3. No DLLs, no C bindings. CC0 Public Domain.

Resources

Contributing

Stars

42 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages