Documentation
¶
Overview ¶
Package aac implements a streaming AAC-LC (ISO/IEC 14496-3) encoder and decoder in pure Go, producing and consuming ADTS streams.
See the README for the implemented subset and the extension seams: long windows only, mono SCE and stereo CPE, 44.1/48 kHz.
Index ¶
Constants ¶
const (
// SamplesPerFrame is the AAC-LC frame length for a long window.
SamplesPerFrame = 1024
)
Variables ¶
var ErrEncoderFlushed = errors.New("AAC encoder has already been flushed")
var ErrUnsupported = errors.New("AAC feature is not supported")
ErrUnsupported reports a stream feature that is syntactically valid AAC but outside the currently implemented subset (see the README). The error message names the missing tool; extending support means implementing the tool, not changing callers.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
SampleRate int
Channels int
// Quality in [0, 1] trades bitrate for fidelity (VBR). It maps
// linearly onto the encoder's uniform quantization noise floor.
Quality float64
// EnableTNS enables encoder-side Temporal Noise Shaping. It is opt-in and
// best suited to transient-dominant material; it is not recommended for
// tone-dominant material because this simple predictor can reduce its SNR
// Decoding TNS is always enabled.
EnableTNS bool
}
Config configures an AAC encoder.
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder incrementally decodes ADTS-framed AAC-LC data.
The stream format (sample rate, channel layout) is locked in by the first frame. Construct with NewDecoder.
func NewDecoder ¶
NewDecoder returns an AAC streaming decoder. The format is detected from the first ADTS header seen by Decode.
func (*Decoder) Channels ¶
Channels returns the stream's channel count, or 0 before the first decoded frame.
func (*Decoder) Decode ¶
Decode consumes ADTS bytes and returns the PCM decoded so far. Input may be sliced arbitrarily: a partial trailing frame is buffered until the remaining bytes arrive (ISO/IEC 14496-3 §1.A.3 adts_frame).
func (*Decoder) SampleRate ¶
SampleRate returns the stream's sample rate in Hz, or 0 before the first decoded frame.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder buffers interleaved PCM and emits ADTS frames.
Each 1024-sample block is transformed together with the previous block (50% MDCT overlap). Block switching needs one block of lookahead — a frame becomes LONG_START only when the *next* frame is known to hold a transient — so a frame is emitted when the block after it arrives, and Flush drains the pipeline plus the final MDCT tail.
func NewEncoder ¶
NewEncoder validates config and returns an AAC-LC streaming encoder.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package adts builds and parses Audio Data Transport Stream headers.
|
Package adts builds and parses Audio Data Transport Stream headers. |
|
cmd
|
|
|
aacdec
command
Command aacdec decodes an ADTS .aac stream into a 16-bit PCM WAV file.
|
Command aacdec decodes an ADTS .aac stream into a 16-bit PCM WAV file. |
|
aacenc
command
Command aacenc encodes a 16-bit PCM WAV file into an ADTS .aac stream.
|
Command aacenc encodes a 16-bit PCM WAV file into an ADTS .aac stream. |
|
internal
|
|
|
bits
Package bits implements the MSB-first bit I/O used by AAC syntax elements.
|
Package bits implements the MSB-first bit I/O used by AAC syntax elements. |
|
coder
Package coder implements the quantization and entropy-coding layer shared by the AAC encoder and decoder: scalefactor and spectral Huffman codes (ISO/IEC 14496-3 §4.6.3) and the inverse quantizer (§4.6.2).
|
Package coder implements the quantization and entropy-coding layer shared by the AAC encoder and decoder: scalefactor and spectral Huffman codes (ISO/IEC 14496-3 §4.6.3) and the inverse quantizer (§4.6.2). |
|
tables
Package tables contains data tables shared by the AAC codec stages.
|
Package tables contains data tables shared by the AAC codec stages. |
|
transform
Package transform implements the modified discrete cosine transform pair used by AAC (ISO/IEC 14496-3 §4.6.11) together with the window functions applied around it.
|
Package transform implements the modified discrete cosine transform pair used by AAC (ISO/IEC 14496-3 §4.6.11) together with the window functions applied around it. |
|
Package wav provides a minimal RIFF/WAVE reader and writer for 16-bit little-endian PCM.
|
Package wav provides a minimal RIFF/WAVE reader and writer for 16-bit little-endian PCM. |