Documentation
¶
Overview ¶
Package dec implements the MP3 (MPEG-1/2/2.5 Layer III) decoder core, ported unit-by-unit from the pinned minimp3 (CC0-1.0, see tools/oracle/minimp3.h and PROVENANCE.md) and gated by differential tests against that C oracle.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder mirrors upstream mp3dec_t (tools/oracle/minimp3.h:18-23): the persistent decoder state carried from one frame to the next. mdctOverlap is the hybrid-IMDCT overlap-add memory (mdct_overlap[2][9*32]), qmfState the synthesis filterbank memory (qmf_state[15*2*32]), res the bit reservoir (reserv + reserv_buf[511]), header the cached header for the fast-path (header[4]), and freeFormatBytes the sticky free-format frame size (free_format_bytes). scratch is the working set (see mp3Scratch), which upstream keeps on the stack rather than in mp3dec_t.
func NewDecoder ¶
func NewDecoder() *Decoder
NewDecoder returns a zero-valued Decoder, mirroring the oracle's `mp3dec_t dec = {0}; mp3dec_init(&dec);` (tools/oracle/mp3dump.c:228-229): Go zero-initializes every field, and mp3dec_init only clears header[0], which is already zero.
func (*Decoder) DecodeFrame ¶
DecodeFrame mirrors upstream mp3dec_decode_frame (tools/oracle/minimp3.h:1713-1806). It decodes one MP3 frame from mp3 into interleaved float32 PCM in pcm and fills info, returning the number of samples per channel (0 when no frame decoded). mp3 must begin at or before a frame; the return and info follow upstream semantics exactly, so a caller advances by info.FrameBytes.
The fast path reuses the cached header when it matches the next frame, avoiding a full resync; a miss zeroes all persistent state (reset) and resyncs via findFrame. Only Layer III is decoded (the library's scope); a non-Layer-III frame is recognized and sized but produces no samples.
func (*Decoder) Reset ¶
func (d *Decoder) Reset()
Reset clears all persistent decoder state (overlap memory, filterbank state, bit reservoir, and cached header), so the next DecodeFrame call resyncs from scratch exactly as a freshly constructed Decoder would. It is exported for package mp3's public Decoder.Reset, which cannot call the unexported reset from outside this package.
type FrameInfo ¶
type FrameInfo struct {
FrameBytes, FrameOffset, Channels, SampleRateHz, Layer, BitrateKbps int
}
FrameInfo mirrors upstream mp3dec_frame_info_t (tools/oracle/minimp3.h:13-16). DecodeFrame fills it with the same semantics as mp3dec_decode_frame: FrameBytes is the offset to the frame plus the frame size (i + frame_size upstream, so it already includes FrameOffset), FrameOffset is the number of bytes skipped before the frame's header, and the rest describe the decoded frame's format.