dec

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 1 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 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

func (d *Decoder) DecodeFrame(mp3 []byte, pcm []float32, info *FrameInfo) int

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.

Jump to

Keyboard shortcuts

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