aac

package
v0.3.21 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 9 Imported by: 1 module, 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 aac decodes MPEG-4 AAC-LC (ISO/IEC 14496-3 audio object type 2) to interleaved signed 16-bit PCM in pure Go: one raw_data_block per call, as MP4 and Matroska carry them, in channel configurations 1 to 7 (mono to 7.1).

Index

Constants

View Source
const FrameSize = 1024

FrameSize is the samples per channel each frame decodes to.

Variables

View Source
var (
	// ErrInvalid is a malformed AudioSpecificConfig or frame.
	ErrInvalid = errors.New("invalid AAC data")
	// ErrUnsupported is a stream outside AAC-LC: another audio object
	// type (HE-AAC's SBR and PS among them), 960-sample frames, a
	// program config element instead of a channel configuration, or a
	// coupling channel element.
	ErrUnsupported = errors.New("unsupported AAC stream")
)

Decoding fails with these, wrapped with what was being decoded.

Functions

This section is empty.

Types

type Config

type Config struct {
	// SampleRate is the sampling rate in Hz.
	SampleRate int
	// Channels is the number of output channels.
	Channels int
	// contains filtered or unexported fields
}

Config is a stream's AudioSpecificConfig (1.6.2.1), the part an AAC-LC decoder needs.

func ParseConfig

func ParseConfig(asc []byte) (Config, error)

ParseConfig reads an AudioSpecificConfig, as MP4's esds and Matroska's CodecPrivate carry it.

type Decoder

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

Decoder decodes an AAC-LC stream's raw data blocks, one 1024-sample frame per packet, to interleaved signed 16-bit PCM in the channel order of its configuration (front centre first: C, L, R, then the surround pairs, then LFE). Perceptual noise substitution uses the standard's correlated noise in mid/side bands; dynamic range control data is ignored. A Decoder decodes one stream in order and belongs to one goroutine.

func NewDecoder

func NewDecoder(asc []byte) (*Decoder, error)

NewDecoder reads the stream's AudioSpecificConfig. The first one builds the transform, window and codebook tables every Decoder shares.

func (*Decoder) Config

func (d *Decoder) Config() Config

Config is the stream's configuration.

func (*Decoder) Decode

func (d *Decoder) Decode(dst []int16, packet []byte) ([]int16, error)

Decode decodes one raw_data_block and appends its FrameSize samples per channel, interleaved, to dst. After an error the decoder's history is unchanged.

func (*Decoder) Reset

func (d *Decoder) Reset()

Reset forgets the overlap of the last frame, for decoding from a packet that does not follow the last one decoded.

Jump to

Keyboard shortcuts

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