truehd

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2026 License: MIT, Apache-2.0, MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package truehd parses framed TrueHD (FBA) access units and reconstructs channel-based PCM for the supported restart syntax and layouts.

The parser and decoder are adapted from truehdd's Apache-2.0 truehd crate. See UPSTREAM.md for the pinned source and LICENSE and NOTICE for attribution.

Index

Constants

View Source
const (
	// MaxAccessUnitSize follows from the 12-bit length in 16-bit words.
	MaxAccessUnitSize = 2 * 0xfff
)

Variables

View Source
var (
	ErrMalformed   = errors.New("malformed TrueHD access unit")
	ErrUnsupported = errors.New("unsupported TrueHD syntax")
)

Functions

func AccessUnitSize

func AccessUnitSize(prefix []byte) (int, error)

AccessUnitSize reads the length from the first two bytes. The caller must gather that many bytes before passing the unit to Parser.Parse.

Types

type AccessUnit

type AccessUnit struct {
	Format      Format
	MajorSync   bool
	InputTiming uint16
	Substreams  [maxSubstreams]Substream
	Auxiliary   []byte
}

AccessUnit holds validated framing and borrowed slices of one input unit. Substreams beyond Format.SubstreamCount are empty.

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder reconstructs the highest channel-based presentation of an FBA stream, including the channel-based presentation in Atmos streams. It reconstructs restart syntax A and B. Its zero value starts at a major sync.

func (*Decoder) Decode

func (d *Decoder) Decode(data []byte) (audio.Buffer[int32], error)

Decode consumes one access unit, returning its borrowed planar PCM. The planes are valid until the next Decode. An error is terminal for this decoder because later access units can depend on the damaged predictor.

func (*Decoder) PCMFormat

func (d *Decoder) PCMFormat() audio.Format

PCMFormat describes the decoded output after the first successful Decode.

type Format

type Format struct {
	SampleRate             int
	SamplesPerAccessUnit   int
	SubstreamCount         int
	SixChannelAssignment   uint8
	EightChannelAssignment uint16
	PresentationMasks      [maxSubstreams]uint8
}

Format is the stream configuration established by the most recent major sync. PresentationMasks lists the substreams needed for each presentation. The highest set bit names the substream that completes the presentation.

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser carries the configuration from one access unit to the next. Its zero value expects an access unit starting with a major sync.

func (*Parser) Parse

func (p *Parser) Parse(data []byte) (AccessUnit, error)

Parse validates one complete access unit. On failure the last valid configuration is retained. To resume at a new major sync, use a zero Parser.

type RestartHeader

type RestartHeader struct {
	SyncWord          uint16
	OutputTiming      uint16
	MinChannel        uint8
	MaxChannel        uint8
	MaxMatrixChannel  uint8
	DitherShift       uint8
	DitherSeed        uint32
	MaxShift          uint8
	MaxLSBs           uint8
	MaxBits           uint8
	ErrorProtection   bool
	LosslessCheck     uint8
	HiResOutputTiming bool
	ChannelAssignment [16]uint8
	BlockHeaderBit    int
}

RestartHeader records the channel and sample coding parameters in a substream's restart. ChannelAssignment maps matrix channels to output channels. BlockHeaderBit is relative to the substream payload.

type Substream

type Substream struct {
	Payload     []byte
	HasChecksum bool
	HasRestart  bool
	Restart     RestartHeader
}

Substream holds the coded blocks, alignment, and optional terminator in Payload. The directory and checksum bytes are excluded from Payload.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL