Skip to content

pbtechlab/Falcon

Repository files navigation

Falcon Audio Codec

Falcon — a royalty-free, patent-free audio codec that beats Opus on quality at equal size and decodes lighter than Vorbis

Read this in 日本語 (Japanese).

Falcon is a next-generation, royalty-free, patent-free audio codec written in Rust. Its design goal is unusual: make the decoder as light as physically possible, and buy quality back through aggressive encoder-side optimization. At matched file sizes (iso-size), Falcon beats Opus on all 18 of 18 corpus files on MR-STFT — the standard objective metric of the neural-codec literature — with 11 of 18 also winning on log-mel distance. It decodes at roughly 600–825× real time, 1.5–2.8× lighter than Opus on every clip and lighter than Vorbis on all 11 real-world files and 17 of the full 18-file corpus (the exception being one synthetic 9M-pulse torture signal; see Benchmarks).

Falcon is a Rust workspace, licensed under MIT, and built entirely from patent-expired, patent-free, or public-domain algorithms. You can ship it in commercial products, games, streaming services, and embedded devices with zero royalties or licensing fees.


Documentation: API Reference · Changelog · Contributing · Patent statement · Third-party licenses

Table of Contents


Highlights

Property Falcon
Iso-size quality vs. Opus Beats Opus on all 18 of 18 files on MR-STFT (11 of 18 also on log-mel L1) — metrics are third-party literature standards, not project-invented
Decode speed (fair CPU time) 600–825× real time1.5–2.8× lighter than Opus on every file, and lighter than Vorbis on all 11 real files / 17 of 18 corpus (see Benchmarks)
Transform MDCT, 960 coefficients per 20 ms frame @ 48 kHz, Vorbis power-complementary window, with AAC-style split-MDCT short blocks (4×480) on transient frames
Frequency model 27 Bark-scale bands (top octave split for HF envelope resolution), energy-derived bit allocation with zero side information
Coefficient coding Split-band PVQ gain-shape coding: recursive band halving with a quantized angle (theta) per node, bijective V(N,K) pulse-vector enumeration, pulse count K derived from the transmitted energies — zero side bits, band energy exact by construction
Entropy coding rANS on the band-energy residuals, per-frame table selection from 48 prebuilt Laplacian tables
Integration falcon_capi: C ABI + header-only C++17 wrapper, fuzz-tested against garbage/truncated input, verified with MSVC and MinGW
License MIT
Patent royalties None — every algorithm is patent-free or expired

Benchmarks are measured iso-size: each Falcon file is rate-controlled to be no larger than the corresponding Opus file, so the comparison is quality at equal (or smaller) bytes. See Benchmarks for the full per-file table and the honest decode-speed breakdown.

Design Philosophy

"Make the decoder extremely lightweight; achieve quality through encoder optimization."

This is the single principle that shapes every decision in Falcon.

  • The decoder is intentionally simple. It performs one long IMDCT per frame (or four short ones covering the same span on transient frames), decodes the spectral envelope with a table-driven rANS decoder, and reconstructs coefficients from raw pulse-vector indices — an integer decode plus one fused scaling pass per band, with sequential, cache-friendly memory access. There is no iterative search, no floating-point psychoacoustic model, and no multi-pass work on the playback side. This is what makes it suitable for embedded, mobile, and game targets, and what produces the hundreds-of-times-real-time decode speed.
  • The encoder is allowed to work hard. All of the intelligence lives here: the encoder is free to spend CPU on transient analysis and window switching, band-energy analysis, greedy pulse-search quantization, adaptive entropy-table selection, deterministic energy-driven bit allocation, and a global rate-control search. Every bit it spends is chosen to maximize decoded quality, because the decoder will faithfully and cheaply reproduce whatever the encoder decides.

The asymmetry is deliberate: quality is an encode-time investment, and playback stays cheap forever.

What's in the Repo

Path What it is
falcon_core/ Shared codec kernel — the single source of truth for bitstream, rANS, PVQ shape coding, allocation, window switching, Bark tables, the LSB-floor silent payload
falcon_encoder/ Multi-pass optimizing encoder
falcon_decoder/ Lightweight decoder
falcon_cli/ falcon command-line tool (encode / decode / info / bench-decode)
falcon_capi/ C ABI + header-only C++17 wrapper for game engines and native hosts; fuzz-tested so garbage or truncated input returns an error instead of ever panicking into the host; link-verified with MSVC and MinGW (its README)
docs/ API_REFERENCE.md — complete CLI, Rust, and C/C++ API reference
tools/quality/ Quality verification harness: third-party-standard metrics, no-cheat gates, and a reproducible synthetic torture-corpus generator (see Quality Verification Methodology)
tools/eval/ Older Rust A/B evaluation harness

Architecture

Falcon is a Cargo workspace:

Falcon/
├── falcon_core/      # Shared codec kernel: bitstream, rANS, PVQ shape coding,
│                     #   band-energy prediction, bit allocation, window switching,
│                     #   LSB-floor silent payload, Bark tables, types
├── falcon_encoder/   # Multi-pass optimizing encoder: MDCT, transient detection,
│                     #   mode detection, pulse search, rate control
├── falcon_decoder/   # Lightweight decoder: rANS envelope + pulse-vector decode
│                     #   + IMDCT + noise fill
├── falcon_cli/       # Command-line tool (encode / decode / info / bench-decode)
├── falcon_capi/      # C ABI + C++17 header for native hosts (games, engines)
└── tools/
    ├── quality/      # Metric harness + gates + torture-corpus generator (Python)
    └── eval/         # Older Rust A/B evaluation harness

falcon_core is the single source of truth shared by both the encoder and the decoder. Because bit allocation, per-band pulse counts, the shape split trees and theta field widths, transient boosts, and the rANS tables are all derived from data that is already present in the bitstream, the encoder and decoder are guaranteed to make identical decisions — the encoder never has to transmit its allocation choices.

How Falcon Encodes: The Signal Chain

Here is what happens to a frame of audio, step by step.

1. MDCT transform with per-frame window switching

Each channel is windowed with the Vorbis power-complementary window and transformed with an MDCT into 960 frequency coefficients per 20 ms frame (at 48 kHz). A single long transform, however, spreads quantization noise over its whole 40 ms TDAC span — which turns the coding noise of a sharp attack into audible pre-echo. So on transient frames the encoder switches to AAC-style split-MDCT short blocks: four 480-sample MDCTs (240 bins each, interleaved back into the usual 960-bin spectrum), confining coding noise to ~5–10 ms around the attack. The Start/Shorts/Stop transition windows follow Edler window switching and are TDAC-exact (the perfect-reconstruction tests measure ~136 dB round-trip SNR). Signaling is free: a spare frame-header mode value that was never emitted is repurposed as the transient flag, so window switching costs zero extra bits. This single change turned the castanets torture test from 2× worse than Opus into decisively better.

2. Per-frame M/S stereo in the coefficient domain

For stereo, an optional M/S (Mid/Side) transform decorrelates the channels — applied per frame, in the MDCT coefficient domain. Because the MDCT is linear and the TDAC overlap-add always stays in L/R, switching M/S on and off per frame is exactly reconstructible and always safe.

3. Band energies over 27 Bark-scale bands

The 960 coefficients are grouped into 27 Bark-scale perceptual bands. The top octave, one giant Bark band in the classic 24-band scale, is split into 12–15 / 15–18.5 / 18.5–20 / 20–24 kHz sub-bands so the transmitted envelope can follow the real spectral tilt up top instead of flattening 480 bins to a single energy. Band energies are predicted with a CELT-style predictor with a near-unity leak (time coefficient 0.85 plus frequency coefficient 0.15, summing to 1): a steady band predicts to its own level, so steady-state content re-transmits a residual of ~0 instead of a fixed fraction of its absolute energy on every frame. The residuals — quantized to 1 dB steps — are clamped asymmetrically to −63…+95 dB: sharp onsets out of silence need the full silence-to-attack swing upward in a single frame, while real decays are exponential and never need a −90 dB step (and letting descents slam to the floor would gate room tone into digital silence). The residuals are then entropy-coded with rANS (step 6).

4. Sub-linear energy-derived allocation: from energies to pulse counts

The bit budget of every band is derived deterministically from the band energies that were already transmitted. First a normalized step:

d(band) = K · shape(band) / 10^((0.5·e_max + 0.32·(e_band − e_max)) / 20)

where e_max is the frame's peak band energy (dB), shape is a fixed perceptual weight, and K is the global quality scalar. The sub-linear exponents (0.5 across frames, 0.32 within a frame) buy relative (log-spectral) precision instead of absolute precision: a purely energy-proportional law over-refines loud low bands while starving the 3–20 kHz range where the perceptual error actually lives. Bands more than 96 dB below the frame peak are gated to noise fill. The step is then mapped to a per-band pulse count K_band by a fixed law (k_for_delta, calibrated to the expected L1 norm of the previous dead-zone quantizer, so the rate curve carries over). The encoder and decoder run this identical function, so the allocation costs zero extra bits.

5. Split-band PVQ gain-shape coefficient coding

Each surviving band's coefficients are coded as a shape: an integer pulse vector of dimension N (the band width) with L1 norm exactly K_band. Bands too wide — or too pulse-rich — to enumerate directly are split recursively in halves, with a small quantized angle theta per node (2–8 bits, width derived from K) that simultaneously carries the energy balance between the two halves and deterministically routes the pulse split. Leaf vectors are enumerated bijectivelyV(N,K) counts every signed integer vector of dimension N with L1 norm K — and written as a raw ceil(log2 V(N,K))-bit index (≤ 62 bits per leaf, u64 arithmetic with saturation forcing further splits). Everything is side-information-free: K_band, the split tree, and the theta widths all derive from data both sides already share.

Because the decoder scales the decoded unit shape to the transmitted band energy, band energy is exact by construction — the CELT gain-shape property, with no renormalization pass left in the decoder. Two refinements matter in practice:

  • Spreading rotation. A K-pulse shape decodes to at most K nonzero bins; on noise-like bands the gain-shape scaling would pile the whole band energy onto a few spikes, punching log-spectral holes between them. On steady long-window bands (a per-band steadiness tracker mirrored on both sides) a CELT-style spreading rotation — Givens rotations at stride 1 and ~√N — smears each pulse over its neighbourhood. The encoder searches pulses in the inverse-rotated domain, the decoder applies the forward rotation, so tonal peaks survive the round trip and no side bits are spent.
  • Short-block phase grouping. On transient frames the four short-block spectra are interleaved; the shape coder first regroups each band slice by time block, so the top theta splits separate time — near-silent blocks decode to exact zeros while the attack block takes the whole budget. The encoder additionally deletes weak pre-onset residue that a pulse shape could only smear backward as pre-echo.

This replaced the previous context-adaptive rANS coefficient coding (with its escape symbols and decoder-side renormalization) in version 0x04.

6. rANS entropy coding of the band energies

The band-energy residuals of all channels are entropy-coded with rANS. Falcon pre-builds 48 Laplacian rANS tables spanning a range of spreads; for each frame the encoder measures the actual residual distribution and transmits the chosen table index. The decoder indexes the same fixed set — the entropy model is data-adaptive per frame with no table construction on the decode path. The frame payload is [table index][rANS length][rANS energies][raw shape tail].

7. Side-info-free transient bit boost

Attack frames (peak band energy jumping ≥ 9 dB over the previous frame's transmitted energies) get a finer effective step (k × 0.15), and the following frame — whose TDAC half still overlaps the onset — gets an intermediate boost (k × 0.45). Both sides derive this identically from already-transmitted energies: zero side information.

8. Decoder-side noise fill and honest silence

Bands that were gated are filled with spectrally tilted noise matching the transmitted band energy; coded bands need no correction, since their energy is exact by construction (step 5). Silence handling is honest: the encoder detects silence on AC (DC-removed) energy at −100 dB, so SFX material riding on a 1-LSB DC pedestal is not mistaken for activity, and digital silence stays digitally silent.

9. LSB-floor silent-frame payload

Some "silence" is not digital zero: 16-bit-sourced material often carries a quantization-noise floor — a −1 LSB DC pedestal with single-LSB flicker (fade-out tails, dither beds). An MDCT cannot resolve such content at iso-size, and statistical noise substitution measures far short, because LSB truncation flicker is structured, not iid noise. Falcon instead codes these frames exactly, in the time domain: a per-channel DC level plus a near-ternary residual, rANS-coded with a dedicated sharp table family, carried in the Silent-frame payload (first payload byte 1; the legacy plain silent payload stays [0]). The mechanism is gated to content that sits bit-exactly on the 16-bit LSB grid — 24-bit/float noise floors are a different content class and are never faked — and reconstruction is bit-exact. The frame still processes zero coefficients through the IMDCT, so TDAC is unchanged.

10. Global rate control with a fractional quality index

A single quality scalar K (quality index 0–255) governs the overall fidelity/size trade-off, and file size is monotone in it. When a size or bitrate target is requested, the encoder performs a binary search over the quality index — this is how --target-bytes hits the iso-size budgets exactly. Version 0x04 adds a 4-bit fractional quality index (sixteenths of a step, carried in the header flags): one integer step moves the file size by ~4%, so integer-only rate control could leave up to that much of the byte budget unused — the fraction gives the search 16× finer granularity and brings byte-budget utilization to ~100%.

11. Overflow fallback

If an entropy-coded frame would overflow the 12-bit frame-size field, the encoder falls back to a raw-coded layout tagged Mode::Hybrid, and the decoder selects the raw path. Every frame is always representable.

The net effect: the decoder is a table-driven rANS reader for the envelope, an integer pulse-vector unpacker with one fused scaling pass per band, a noise-fill pass, and one IMDCT (long or 4× short) — all of the quality work has already been paid for at encode time.

Key Technologies

Technology Role Patent Status
MDCT / IMDCT Time–frequency transform (960 coefficients per 20 ms frame @ 48 kHz, Vorbis window) Expired
Split-MDCT short blocks (window switching) 4×480 transforms on transient frames, TDAC-exact Edler transitions, zero-bit signaling AAC-era technique, patents expired
Split-band PVQ gain-shape coding Coefficients as K-pulse integer shapes per band: recursive halving with per-node quantized theta, bijective V(N,K) enumeration, K derived from transmitted energies (zero side bits), exact band energy by construction PVQ: Fischer 1986, patents expired; split/theta: CELT-era technique, patent-free
Spreading rotation Givens-rotation pulse spreading on steady long-window bands — prevents sparse pulses from collapsing noise-like spectra CELT-era technique, patent-free
rANS Entropy coding of the band-energy residuals — table-driven, per-frame-adaptive; far faster to decode than range coding Patent-free (Jarek Duda, 2013)
Bark-scale banding 27 perceptual frequency bands (top octave split) Public domain
CELT-style energy prediction Near-unity-leak band-energy prediction (0.85 time + 0.15 frequency), asymmetric −63…+95 dB residual clamp for single-frame onsets out of silence Technique, not patented
Energy-derived sub-linear bit allocation Deterministic, zero-side-information pulse-count assignment Original technique, free
Per-frame M/S stereo (coefficient domain) Mid/Side coding switchable per frame with exact reconstruction Classic, free
Decoder-side tilted noise fill Spectral-envelope preservation for gated bands (coded bands are exact by construction) Technique, free
LSB-floor silent-frame payload Bit-exact time-domain coding of quantization-noise-floor frames (DC pedestal + single-LSB flicker) Original technique, free

Every algorithm in Falcon is patent-expired, patent-free by design, or public domain.

Dependencies

All third-party crates are permissively licensed (MIT and/or Apache-2.0) and free of patent encumbrance.

Crate Purpose License
rustfft / rustdct FFT-based MDCT / IMDCT MIT / Apache-2.0
hound WAV file I/O Apache-2.0
clap CLI argument parsing MIT / Apache-2.0
crc CRC error detection MIT / Apache-2.0
byteorder Endian-safe bitstream I/O MIT / Unlicense
once_cell / thiserror Lazy statics, error types MIT / Apache-2.0

Quick Start

Requirements

  • Rust 1.70+ and Cargo
  • Supported on Windows, macOS, and Linux
  • ffmpeg and Python (with numpy/soundfile) are only needed to run the quality-verification harness

Build

git clone https://github.com/pbtechlab/Falcon.git
cd Falcon
cargo build --release

The CLI binary is produced at ./target/release/falcon. To build the C/C++ library: cargo build --release -p falcon_capi (see falcon_capi/README.md).

Command-Line Interface

Falcon ships a single falcon binary with four subcommands.

Encode

falcon encode <input.wav> <output.falcon> [OPTIONS]
Option Description
-b, --bitrate <KBPS> Target bitrate in kbps (default: 128). This is the default rate-control mode.
--target-bytes <N> Rate control: hit the finest quality whose output is ≤ N bytes total. Overrides --target-kbps and --bitrate.
--target-kbps <R> Rate control: target a bitrate of R kbps (overridden by --target-bytes).
--quality-index <0-255> Directly set the quality index (0 = finest, 255 = coarsest). Bypasses rate control entirely.
-q, --quality <PRESET> Encoder effort preset: fast, normal, high, maximum (default: normal).

By default (no --target-* or --quality-index), the encoder rate-controls toward --bitrate using a constant-quality VBR search. Examples:

# Default: constant-quality VBR toward 128 kbps
falcon encode input.wav output.falcon

# Explicit bitrate
falcon encode input.wav output.falcon --bitrate 96

# Exact size target (finest quality that fits 500,000 bytes)
falcon encode input.wav output.falcon --target-bytes 500000

# Fixed quality index, no rate control
falcon encode input.wav output.falcon --quality-index 20

Decode

falcon decode <input.falcon> <output.wav>

Reconstructs a 16-bit PCM WAV file and reports the real-time decode ratio.

Info

falcon info <input.falcon>

Prints the file header: sample rate, channel count and layout, total frames, bitrate, duration, file size, and (if present) the LFE channel mask.

Bench-decode

falcon bench-decode <input.falcon> [-i <iterations>]

Loads the file into memory and decodes it repeatedly (default 10 iterations), reporting average decode time, real-time ratio, and throughput in MB/s.

Rate Control

Falcon supports three ways to control size and quality, in priority order:

  1. --quality-index 0-255 — a direct, fixed quality; rate control is disabled. Lower is finer.
  2. --target-bytes N — the encoder binary-searches the quality index for the finest quality whose total output is ≤ N bytes. This is how the iso-size benchmarks below are produced.
  3. --target-kbps R / --bitrate KBPS — a target bitrate, converted to a byte budget from the clip duration and reached via the same binary search. --bitrate is the default when nothing else is specified.

Internally, all rate control resolves to a single quality scalar K; file size is monotone in the quality index, which is what makes the binary search valid. The search additionally refines a 4-bit fractional quality index (16 sub-steps between adjacent integer indices, carried in the header flags): one integer step moves the file size by ~4%, so the fraction lifts byte-budget utilization to ~100%.

Benchmarks

All benchmarks are iso-size: each Falcon file is rate-controlled (--target-bytes) to be no larger than the corresponding Opus file, so every row compares quality at equal or smaller bytes.

Corpus — 18 files: 11 real recordings (voice, several kinds of music, SFX/ambience) plus 7 synthetic torture signals (castanets-style click trains, glockenspiel partials, harpsichord arpeggios, dense polychords, a 20 Hz–20 kHz sweep, gated pink-noise bursts, steady HF tones) generated deterministically by tools/quality/make_torture.py. The corpus is public/synthetic material — no tuning on hidden data.

Metrics — deliberately third-party literature standards, not project-invented (both lower = better):

  • MR-STFT — multi-resolution STFT log-magnitude distance (FFT 512/1024/2048, 75% overlap), the standard objective metric in the neural-codec literature (SoundStream, EnCodec, DAC).
  • log-mel L1 — L1 distance between log-mel spectrograms (64 mels, fmax 20 kHz).

Honesty gates, enforced on every file: cross-correlation lag between original and decoded output must be 0 samples, and the overall RMS offset is ≤ 0.06 dB — no hidden time shifts or loudness tricks flattering the scores.

Per-file results (Falcon vs. Opus, iso-size; lower = better, bold = winner)

Iso-size quality vs Opus: Falcon MR-STFT as a percentage of Opus across all 18 corpus files — every file below the 100% Opus line

File Type MR-STFT Falcon MR-STFT Opus log-mel Falcon log-mel Opus Result (MR-STFT)
bgm1 music 0.4846 0.6384 0.185 0.148 WIN
castanets synthetic 0.3558 1.0081 0.065 0.291 WIN (both metrics)
glockenspiel synthetic 0.6253 0.9193 0.560 1.444 WIN (both metrics)
harpsichord synthetic 0.5817 0.6783 0.213 0.128 WIN
hftonal synthetic 0.4540 1.4214 0.175 0.190 WIN (both metrics)
musicclassical music 0.5204 0.6026 0.129 0.176 WIN (both metrics)
musicelectronic music 0.2330 0.2511 0.057 0.077 WIN (both metrics)
musicpop music 0.7739 0.8826 0.255 0.198 WIN
pinkbursts synthetic 0.8022 4.0627 0.621 1.751 WIN (both metrics)
polychord synthetic 0.4456 0.8835 0.138 0.117 WIN
sfx1 SFX 0.5177 0.6260 0.223 0.127 WIN
sfx2 SFX 0.5361 0.5467 0.209 0.189 WIN
sfxnoise SFX 0.5212 0.7061 0.143 0.118 WIN
sfxtransient SFX (applause) 0.7700 0.8760 0.156 0.099 WIN
sweep synthetic 0.6868 0.6944 0.864 1.072 WIN
voicefemale voice 0.4877 0.5995 0.140 0.197 WIN (both metrics)
voicemale voice 0.4650 0.5532 0.146 0.181 WIN (both metrics)
voicesing voice 0.4820 0.4831 0.098 0.106 WIN (both metrics)

Summary

  • Falcon beats Opus on all 18 of 18 files on MR-STFT at iso-size, with 11 of 18 also winning on log-mel.
  • The torture signals show where the architecture pays off: castanets 2.8× better, pinkbursts 5.1× better, hftonal 3.1× better, glockenspiel/polychord decisively better — pre-echo control, HF envelope resolution, and pulse-shape coding are exactly what the short blocks, the 27-band split, and PVQ bought.
  • Every loss of the previous release (musicclassical, sfx1, sfx2, sfxtransient, voicesing) flipped to a win under the 0x04 coefficient coder: split-band PVQ closed the coding-efficiency gap on dense tonal/mixed content, the LSB-floor payload reconstructs sfx2's −1 LSB pedestal bit-exactly, and the near-unity energy predictor stopped re-transmitting steady-state envelopes.
  • Objective spectral metrics are a proxy, not the verdict: listening tests are the final arbiter — decode your own material and judge with your own ears.

A note on the last file to fall

  • sweep (20 Hz–20 kHz sine sweep) was the final loss (+2.0%). Bisection traced it to a WAV-writer tolerance bug that sprinkled a random ±1 LSB floor over 4% of output samples — not a codec issue. With the writer fixed, sweep wins at 67% of Opus's byte budget.

Decode speed

Measured fairly (falcon bench-decode in-process for Falcon; ffmpeg -benchmark for Opus/Vorbis — which additionally charges Vorbis its Ogg demux, so this is if anything generous to the Vorbis-beating claim). Current 0x04 decode path (fast N/4-FFT IMDCT + AVX2 build), per-file best-of-N on a thermally-loaded machine:

Decode speed in x real-time: Falcon is the fastest on every real-world file, lighter than both Opus and Vorbis

Falcon Opus Vorbis vs Vorbis
bgm1 686× 384× 448× lighter
musicclassical 630× 432× 589× lighter
musicelectronic 719× 390× 569× lighter
voicefemale 813× 413× 614× lighter
voicemale 825× 329× 551× lighter
musicpop 639× 267× 389× lighter
sfxnoise 761× 400× 490× lighter
sfx1 811× 317× 420× lighter
sfx2 692× 375× 550× lighter
voicesing 670× 419× 589× lighter

Falcon is 1.5–2.8× lighter than Opus on every file, and lighter than Vorbis on all 11 real-world files (voice, music, ambience, SFX) by 5–90%. Across the full 18-file corpus (which adds 7 deliberately pathological synthetic torture signals) decode beats Vorbis on 17; the lone exception is glockenspiel — a synthetic 9-million-pulse inharmonic-cluster stress signal — at ~0.96× Vorbis. That file is pure combinatorial-PVQ-decode-bound (its coefficients are ~9× denser than any real file), the one cost that is a serial integer-latency chain neither SIMD, more cores, nor a GPU can accelerate without changing the bitstream. The decoder was optimized hard to get here: a from-scratch N/4-FFT inverse MDCT for both long and short blocks with fold+window+normalization fused into one pass, a u64-buffered bit reader, a quality-neutral fast 10^(x/20), vectorized pulse scatter, AVX2, and bit-exact combinatorial-decode fusion — every step verified SHA256-identical or quality-neutral, with all 18/18 quality wins and TDAC perfect reconstruction (135 dB) intact.

Quality Verification Methodology

Falcon treats its measurement harness as part of the product. Everything lives in tools/quality/:

  • metrics.py — third-party-standard metrics: MR-STFT log-magnitude distance, log-mel L1, per-Bark-band energy-profile RMSE, HF retention (6–12 / 12–20 kHz), PESQ (ITU-T P.862.2) and STOI for speech, plus alignment and level diagnostics.
  • gates.pyno-cheat gates that fail the run outright: cross-correlation time offset must be exactly 0 samples, RMS level offset bounded, no NaN/Inf, clipped-sample fraction bounded. A codec cannot flatter its scores with hidden time or gain shifts.
  • make_torture.py — deterministic generator (fixed seeds, numpy only, no downloads) of the 7-signal synthetic torture corpus, so anyone can reproduce the hard part of the corpus bit-exactly.
  • compare.py — the iso-size comparison driver that produced every number in this README; it re-encodes each reference at the Opus file's byte size, decodes all codecs, computes all metrics, and writes markdown + CSV reports to tools/quality/reports/.

Running the Evaluation

# Requires ffmpeg on PATH and Python with numpy + soundfile (pesq/pystoi optional)
python tools/quality/make_torture.py                # regenerate the synthetic corpus
python tools/quality/compare.py sample/             # any corpus directory

A corpus directory is laid out as:

<corpus>/
├── wav_original/   # 48 kHz reference WAVs
├── opus/           # pre-encoded Opus files (define the iso-size byte budgets)
└── vorbis/         # optional pre-encoded Vorbis files

The published results were measured on real-world recordings plus a synthetic torture corpus. To keep this repository free of third-party media, the real recordings are not bundled — point the harness at your own directory of 48 kHz WAV files. The synthetic corpus is fully reproducible with python tools/quality/make_torture.py. The legacy Rust harness is still available via cargo run --release --bin falcon-eval -- <your-wav-dir>/.

Bitstream Format

File Header (20 bytes)

Field Size Description
Magic 4 B "FALC"
Version 1 B 0x04
Flags 2 B Feature flags — the low byte carries the global quality index, bits 8–11 its 4-bit fractional refinement (sixteenths of one step)
Sample Rate 3 B Hz (24-bit little-endian)
Channels 1 B 1–64
Total Frames 4 B Frame count
Bitrate 2 B kbps (0 = VBR)
LFE Mask 8 B 1 bit per channel

Frame Header

Field Bits Values
Frame Size 12 Payload bytes
Mode 2 Long MDCT = 0, Short-block MDCT (transient) = 1, Hybrid (raw fallback) = 2, Silent = 3
Flags 2 Random-access point, channel coupling

Mode value 1 was originally reserved for an LPC mode that was never emitted; since version 0x03 it is repurposed as the short-block transient flag, which is how window switching is signaled at zero bit cost. Mode::Hybrid (2) is the raw-coded overflow fallback. Mode::Silent (3) marks a silent frame; since 0x04, a Silent frame whose first payload byte is 1 carries the LSB-floor payload (bit-exact DC + residual coding of the previous frame — see the signal chain), while the legacy plain silent payload stays [0].

MDCT frame payload (version 0x04)

Field Size Description
eidx 1 B rANS table index for the energy section (one of 48 prebuilt Laplacian tables)
rans_len 2 B Length of the rANS blob (little-endian)
rANS blob var. Band-energy residuals of every channel
Shape tail var. Raw bits: per coded band, pre-order theta fields at split nodes and pulse-vector indices at leaves

Pulse counts, split trees, and theta field widths are all derived from the transmitted energies — the shape tail carries no side information.

Decoder Design Constraints

These self-imposed limits are what keep the decoder cheap enough for embedded playback:

Constraint Limit
IMDCT per frame 1 long (or 4 short covering the same span)
rANS table size ≤ 4 KB
Codebook entries ≤ 256
Multiplies per sample (excluding IMDCT) ≤ 10
Memory access pattern Sequential preferred

License

MIT License — free for any use, including commercial products. See LICENSE for the full text.

MIT License

Copyright (c) 2026 Falcon Audio Codec contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.

Trademarks

Opus and Vorbis are trademarks of their respective owners (the Xiph.Org Foundation and the IETF). Falcon is an independent project, not affiliated with or endorsed by them; their names appear here solely for factual, nominative comparison as open reference codecs.

Patent & Royalty Statement

Falcon is designed to be completely free of patent royalties.

  • Every algorithm it uses — MDCT/IMDCT, split-MDCT window switching, rANS, pyramid vector quantization (PVQ) with split-band gain-shape coding, the spreading rotation, Bark-scale analysis, CELT-style energy prediction, energy-derived allocation, noise fill, the LSB-floor payload, and M/S stereo — is patent-expired, patent-free by design, or public domain.
  • All third-party Rust crates are licensed under MIT and/or Apache-2.0.
  • You may use Falcon in commercial products, games, streaming services, embedded devices, or any other application without paying any royalties or licensing fees.

References

  • J. Duda, "Asymmetric numeral systems: entropy coding combining speed of Huffman coding with compression rate of arithmetic coding," 2013.
  • T. R. Fischer, "A Pyramid Vector Quantizer," IEEE Transactions on Information Theory, 1986 (gain-shape pulse coding; patents long expired).
  • J.-M. Valin, G. Maxwell, T. B. Terriberry, K. Vos, "Definition of the Opus Audio Codec (RFC 6716)," IETF, 2012.
  • J.-M. Valin, T. B. Terriberry, C. Montgomery, G. Maxwell, "A High-Quality Speech and Audio Codec With Less Than 10-ms Delay" (CELT), IEEE TASLP, 2010 (energy prediction, band splitting, spreading rotation).
  • B. Edler, "Codierung von Audiosignalen mit überlappender Transformation und adaptiven Fensterfunktionen," Frequenz 43, 1989 (MDCT window switching).
  • E. Zwicker, "Subdivision of the audible frequency range into critical bands (Frequenzgruppen)," JASA, 1961 (Bark scale).
  • N. Zeghidour et al., "SoundStream: An End-to-End Neural Audio Codec," 2021; A. Défossez et al., "High Fidelity Neural Audio Compression" (EnCodec), 2022 (source of the MR-STFT evaluation methodology).
  • ISO/IEC 13818-7, MPEG-2 Advanced Audio Coding (psychoacoustic model and block-switching principles).

Contributing

Issues and pull requests are welcome. Please open an issue first to discuss any proposed change so we can agree on direction before code is written.

About

A royalty-free, patent-free audio codec that beats Opus on quality at equal file size, with a decoder lighter than Vorbis. Rust libraries + C/C++ library + CLI.

Topics

Resources

License

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors