Documentation
¶
Overview ¶
Package alac decodes Apple Lossless audio in progressive MP4 files.
Index ¶
- Constants
- Variables
- func DynDecomp(params *AGParams, bitBuf *BitBuffer, predCoefs []int32, ...) error
- func ReadVerbatim(bits *BitBuffer, left, right []int32, depth uint32)
- func RestoreMono(samples []int32, depth uint8, low []uint16, bytesShifted int)
- func RestoreStereo(left, right []int32, depth uint8, mixBits, mixRes int32, low []uint16, ...)
- func SetAGParams(params *AGParams, ...)
- func UnpcBlock(pc1, out []int32, num int, coefs []int16, numActive int32, ...)
- type AGParams
- type BitBuffer
- func (b *BitBuffer) Advance(numBits uint32)
- func (b *BitBuffer) BitsLeft() int64
- func (b *BitBuffer) ByteAlign()
- func (b *BitBuffer) Copy() BitBuffer
- func (b *BitBuffer) PastEnd() bool
- func (b *BitBuffer) Read(numBits uint8) uint32
- func (b *BitBuffer) ReadOne() uint8
- func (b *BitBuffer) ReadSmall(numBits uint8) uint8
- func (b *BitBuffer) Reset(data []byte, size int)
- type Decoder
- type PacketConfig
Constants ¶
const ( // MaxCoefs is the maximum predictor order (5-bit field). MaxCoefs = 32 // NumActiveDelta triggers first-order delta decode mode. NumActiveDelta = 31 // UnusedHeaderBits is the unused header field size in SCE/CPE (spec-defined). UnusedHeaderBits = 12 )
const MaxPacketSize = mp4.MaxPacketSize
MaxPacketSize is the maximum compressed packet size accepted for waveform decoding.
const Padding = 16
Padding is the zeroed tail a caller appends after the compressed packet.
Variables ¶
var ( // ErrConfig indicates an invalid or unsupported ALAC configuration // (bad magic cookie, unsupported version, unsupported bit depth). ErrConfig = errors.New("invalid configuration") // ErrNoTrack indicates no usable ALAC track was found in the container // (missing track, missing or malformed MP4 boxes). ErrNoTrack = errors.New("no track found") // ErrDecode indicates a failure during packet decoding // (bitstream overrun, invalid headers, unsupported elements). ErrDecode = errors.New("decode failed") )
Public sentinel errors for consumer error matching.
var ( ErrInvalidCookie = errors.New("alac: invalid magic cookie") ErrUnsupportedVersion = errors.New("alac: unsupported compatible version") ErrUnsupportedElement = errors.New("alac: unsupported element type (CCE/PCE)") ErrInvalidHeader = errors.New("alac: invalid frame header") ErrInvalidShift = errors.New("alac: invalid bytesShifted value") ErrBitstreamOverrun = errors.New("alac: bitstream overrun") ErrSampleOverrun = errors.New("alac: sample count exceeds buffer") ErrBitDepth = errors.New("alac: unsupported bit depth") ErrChannels = errors.New("alac: channel count out of range") ErrFrameLength = errors.New("alac: frame length out of range") ErrSampleRate = errors.New("alac: sample rate is zero") ErrMissingChannels = errors.New("alac: fewer channels decoded than declared") ErrElementLayout = errors.New("alac: channel pair element past the channel layout") )
ALAC decoder error sentinels.
var ErrSeekRequired = errors.New("ALAC in MP4 requires a seekable reader")
ErrSeekRequired means the source cannot seek to MP4 metadata and packets.
Functions ¶
func DynDecomp ¶
func DynDecomp(params *AGParams, bitBuf *BitBuffer, predCoefs []int32, numSamples, maxSize int) error
DynDecomp performs adaptive Golomb-Rice entropy decoding of a sample block. Writes decoded prediction residuals into predCoefs. Every code must end within the packet: one that would end in the padding returns ErrBitstreamOverrun.
func ReadVerbatim ¶
ReadVerbatim reads one or two channels of uncompressed signed samples. The caller verifies that the complete element fits in the packet. The padded tail permits a full word load at the last sample.
func RestoreMono ¶
RestoreMono reattaches the low bits and keeps the native signed PCM width.
func RestoreStereo ¶
func RestoreStereo(left, right []int32, depth uint8, mixBits, mixRes int32, low []uint16, bytesShifted int)
RestoreStereo inverts the ALAC stereo matrix in place.
func SetAGParams ¶
SetAGParams initialises the adaptive Golomb-Rice parameters.
func UnpcBlock ¶
func UnpcBlock(pc1, out []int32, num int, coefs []int16, numActive int32, chanBits, denShift uint32)
UnpcBlock reverses the linear prediction encoding. pc1 contains the entropy-decoded prediction residuals (input). out receives the reconstructed sample values (output). pc1 and out may be the same slice for in-place operation (numActive==31 mode).
Types ¶
type AGParams ¶
type AGParams struct {
MB, MB0 uint32
PB uint32
KB uint32
WB uint32
QB uint32
FW, SW uint32
MaxRun uint32
}
AGParams holds the adaptive Golomb-Rice codec state.
type BitBuffer ¶
BitBuffer reads bits from a packet followed by Padding zero bytes.
func (*BitBuffer) BitsLeft ¶
BitsLeft returns the number of data bits from the read position to the end, negative once the position has been advanced past the end.
func (*BitBuffer) ByteAlign ¶
func (b *BitBuffer) ByteAlign()
ByteAlign advances to the next byte boundary (if not already aligned).
func (*BitBuffer) Copy ¶
Copy returns a snapshot of the current BitBuffer state. The copy shares the underlying data but has independent position tracking.
func (*BitBuffer) PastEnd ¶
PastEnd returns true if the read position is at or past the original data end.
func (*BitBuffer) Read ¶
Read reads up to 16 bits and returns them right-aligned. Equivalent to BitBufferRead in the Apple implementation.
A read at or past the end of the data (an overrun, which PastEnd reports) returns zero bits and does not advance: the 4-byte padding covers a read that starts inside the data and crosses its end, not one that starts beyond it.
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder reads and decodes an ALAC track. Use it for one pass in one goroutine.
func Open ¶
Open locates the ALAC track and reads its sample table. The caller owns source and keeps it open for the duration of Decode. Source must implement io.ReadSeeker, since progressive MP4 stores metadata and packets separately.
func (*Decoder) Decode ¶
Decode delivers one block of signed, right-justified PCM at a time. The channel slices are decoder-owned and may only be read during consume.
type PacketConfig ¶
type PacketConfig struct {
FrameLength uint32
BitDepth uint8
NumChannels uint8
PB uint8
MB uint8
KB uint8
MaxRun uint16
MaxFrameBytes uint32
AvgBitRate uint32
SampleRate uint32
}
PacketConfig holds ALAC decoder configuration parsed from the magic cookie.
func ParseMagicCookie ¶
func ParseMagicCookie(cookie []byte) (PacketConfig, error)
ParseMagicCookie reads an ALACSpecificConfig from a magic cookie byte slice. Handles legacy wrappers ('frma' and 'alac' atoms).