iffchunks

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 13 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 iffchunks reads bounded chunk headers in IFF-based audio containers.

Package wave decodes WAVE audio in RIFF, RF64, and BW64 containers.

Index

Constants

View Source
const (
	FileHeaderSize = 12
	HeaderSize     = 8
	MaxChunks      = 4096
	MaxTextBytes   = 1 << 20
	MaxTagBytes    = 16 << 20
)

Variables

View Source
var ErrInvalidHeader = errors.New("invalid WAVE header")

ErrInvalidHeader means a required WAVE header field is absent or malformed.

View Source
var ErrMetadataLimit = errors.New("WAVE metadata limit exceeded")

ErrMetadataLimit means the decoder did not find audio within its metadata budget.

View Source
var ErrUnsupported = errors.New("unsupported WAVE format")

ErrUnsupported means the file is not WAVE or uses an unsupported encoding.

Functions

func End

func End(start, size, limit int64) (int64, error)

End returns the next chunk offset including word alignment.

func ReadHeader

func ReadHeader(source io.ReaderAt, pos, end int64, order binary.ByteOrder) (id string, size int64, err error)

ReadHeader reads the chunk identity and its 32-bit payload length.

func ReadTags

func ReadTags(source io.ReaderAt, size int64) (tagdata.Result, error)

ReadTags scans RIFF INFO and ID3 chunks, including tags after the audio. PCM data is skipped using the container's chunk extents.

func Reserve

func Reserve(budget *int64, size int64) error

Reserve reduces the metadata budget before a payload is read.

func SampleRateFromFormat

func SampleRateFromFormat(chunk []byte) int

SampleRateFromFormat returns the sample rate for a recognized WAVE format tag. Metadata probing does not apply the limits used to allocate PCM buffers.

func Sniff

func Sniff(header []byte) bool

Sniff reports whether header begins with a RIFF, RF64, or BW64 WAVE header.

Types

type Decoder

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

Decoder reads WAVE PCM in a single pass. Use it from one goroutine at a time.

func Open

func Open(ctx context.Context, r io.Reader) (*Decoder, error)

Open reads WAVE metadata and stops at the audio data. The caller owns r and must keep it open until decoding finishes.

func OpenWithTags

func OpenWithTags(ctx context.Context, r io.Reader) (*Decoder, tagdata.Result, error)

OpenWithTags opens WAVE and retains bounded INFO and ID3 metadata found before the audio data.

func (*Decoder) BufferedInput

func (d *Decoder) BufferedInput() int

BufferedInput reports input bytes read ahead of the last returned block.

func (*Decoder) CanSeek

func (d *Decoder) CanSeek() bool

CanSeek reports whether exact frame seeks are available.

func (*Decoder) ChannelMask

func (d *Decoder) ChannelMask() uint32

ChannelMask reports the WAVEFORMATEXTENSIBLE speaker mask, or zero when unspecified. Channel slices arrive in increasing speaker-bit order.

func (*Decoder) Close

func (d *Decoder) Close() error

Close releases the decoder and leaves the input open.

func (*Decoder) Decode

func (d *Decoder) Decode(consume func(channels [][]int32)) error

Decode calls consume synchronously for each block of signed PCM. Slices are read-only and valid only during the call. Floating-point samples outside [-1, 1] saturate, and NaN maps to zero.

func (*Decoder) DecodeFloat

func (d *Decoder) DecodeFloat(consume func(channels [][]float32)) error

DecodeFloat calls consume with IEEE float samples before saturation. Float64 input is narrowed to float32. The slices are borrowed for the call.

func (*Decoder) FloatPCM

func (d *Decoder) FloatPCM() bool

FloatPCM reports whether the source stores IEEE floating-point samples.

func (*Decoder) Format

func (d *Decoder) Format() (channels, bitsPerSample int)

Format reports the channel count and the decoded sample depth. IEEE float converts to signed 32-bit PCM. G.711 expands to signed 16-bit PCM.

func (*Decoder) FrameCount

func (d *Decoder) FrameCount() (int64, bool)

FrameCount reports the number of frames in a sized audio chunk.

func (*Decoder) NextBlock

func (d *Decoder) NextBlock() (any, error)

NextBlock returns a borrowed block without changing representation.

func (*Decoder) PCMFormat

func (d *Decoder) PCMFormat() audio.Format

PCMFormat reports the native representation, sample rate, and layout. Companded G.711 expands to signed 16-bit samples.

func (*Decoder) SampleRate

func (d *Decoder) SampleRate() int

SampleRate reports the sample rate in Hz.

func (*Decoder) SeekFrame

func (d *Decoder) SeekFrame(frame int64) error

SeekFrame sets the position in a sized audio chunk on a seekable reader.

Jump to

Keyboard shortcuts

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