Crate truehd

Source
Expand description

Β§truehd

A low-level parser and decoder for Dolby TrueHD audio bitstreams, implemented in Rust.

⚠️ Experimental:

This crate is intended for internal or research use only.
It is not designed for production or end-user playback systems.

Β§Development Status

CategoryFeatureStatusPriorityCriticalityNotes
ParserFBA sync bitstream (Dolby)🟒HighEssential
FBB sync bitstream (Meridian)πŸ”΄LowNice-to-haveDo you really need it?
Evolution frame🟒HighEssential
CRC and parity validation🟒HighEssential
SMPTE timestamp🟒MediumOptional
FBA hires output timing🟒MediumOptional
Object audio metadata🟑HighEssentialMostly done
FIFO conformance tests🟑MediumOptionalPartially done
FBA bitstream seekingπŸ”΄LowNice-to-haveYes, it’s possible
Decoder31EA / 31EB sync substream🟒HighEssential
31EC sync substream🟒HighEssential4th / 16ch presentation
Lossless check🟒HighEssential
Optimize DSP performanceπŸ”΄MediumImportant
Dynamic range controlπŸ”΄LowOptional
Intermediate spatial formatπŸ”΄LowOut-of-scopeI have no idea
Other TODOsDocumentation🟑HighEssentialWith kind support from Claude
Unit testsπŸ”΄HighEssential
BenchmarkingπŸ”΄MediumImportant
Metadata interpolationπŸ”΄LowNice-to-have
Bitstream editingπŸ”΄LowNice-to-have
EncodingπŸ”΄LowNice-to-have
Object audio renderingπŸ”΄LowOut-of-scope

Legend: 🟒 Completed β€’ 🟑 In Progress β€’ πŸ”΄ Not Started


Β§License

Licensed under the Apache License, Version 2.0. See LICENSE for details.

Β§Technical Overview

Parser and decoder for Dolby TrueHD (MLP) bitstreams according to FBA syntax specification.

Β§Bitstream Organization

External Structure: Access units containing MLP Syncs and substream segments. Internal Structure: Blocks with optional restart headers.

Β§Audio Presentations

  • 2-channel (stereo, Lt/Rt, binaural, mono)
  • 6-channel
  • 8-channel
  • 16-channel

Β§Data Rate Management

Variable bitrate compression with FIFO buffering. Peak data rates limited to 18 Mbps for FBA streams.

Β§Quick Start

Steps for processing audio streams:

  1. Extract access units from a bitstream using process::extract::Extractor
  2. Parse access units into structured data using process::parse::Parser
  3. Decode audio to PCM samples using process::decode::Decoder
use truehd::process::{extract::Extractor, parse::Parser, decode::Decoder, EXAMPLE_DATA};

// Initialize processing components
let mut extractor = Extractor::default();
let mut parser = Parser::default();
let mut decoder = Decoder::default();

// Push bitstream data
let data = &EXAMPLE_DATA; // Example data
extractor.push_bytes(data);

// Process frames with error recovery
for frame_result in extractor {
    match frame_result {
        Ok(frame) => {
            let access_unit = parser.parse(&frame)?;
             
            // Decode the first presentation
            let decoded = decoder.decode_presentation(&access_unit, 0)?;
             
            // Access PCM data
            let pcm_samples = &decoded.pcm_data;
        }
        Err(extract_error) => {
            // Handle extraction errors - stream continues automatically
            eprintln!("Frame extraction error: {}", extract_error);
        }
    }
}

ModulesΒ§

process
Processing functionality for audio bitstreams.
structs
Data structures representing TrueHD format components.
utils
Utility functions and supporting infrastructure.

MacrosΒ§

log_or_err