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
- Variables
- func End(start, size, limit int64) (int64, error)
- func ReadHeader(source io.ReaderAt, pos, end int64, order binary.ByteOrder) (id string, size int64, err error)
- func ReadTags(source io.ReaderAt, size int64) (tagdata.Result, error)
- func Reserve(budget *int64, size int64) error
- func SampleRateFromFormat(chunk []byte) int
- func Sniff(header []byte) bool
- type Decoder
- func (d *Decoder) BufferedInput() int
- func (d *Decoder) CanSeek() bool
- func (d *Decoder) ChannelMask() uint32
- func (d *Decoder) Close() error
- func (d *Decoder) Decode(consume func(channels [][]int32)) error
- func (d *Decoder) DecodeFloat(consume func(channels [][]float32)) error
- func (d *Decoder) FloatPCM() bool
- func (d *Decoder) Format() (channels, bitsPerSample int)
- func (d *Decoder) FrameCount() (int64, bool)
- func (d *Decoder) NextBlock() (any, error)
- func (d *Decoder) PCMFormat() audio.Format
- func (d *Decoder) SampleRate() int
- func (d *Decoder) SeekFrame(frame int64) error
Constants ¶
const ( FileHeaderSize = 12 HeaderSize = 8 MaxChunks = 4096 MaxTextBytes = 1 << 20 MaxTagBytes = 16 << 20 )
Variables ¶
var ErrInvalidHeader = errors.New("invalid WAVE header")
ErrInvalidHeader means a required WAVE header field is absent or malformed.
var ErrMetadataLimit = errors.New("WAVE metadata limit exceeded")
ErrMetadataLimit means the decoder did not find audio within its metadata budget.
var ErrUnsupported = errors.New("unsupported WAVE format")
ErrUnsupported means the file is not WAVE or uses an unsupported encoding.
Functions ¶
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 ¶
ReadTags scans RIFF INFO and ID3 chunks, including tags after the audio. PCM data is skipped using the container's chunk extents.
func SampleRateFromFormat ¶
SampleRateFromFormat returns the sample rate for a recognized WAVE format tag. Metadata probing does not apply the limits used to allocate PCM buffers.
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 ¶
Open reads WAVE metadata and stops at the audio data. The caller owns r and must keep it open until decoding finishes.
func OpenWithTags ¶
OpenWithTags opens WAVE and retains bounded INFO and ID3 metadata found before the audio data.
func (*Decoder) BufferedInput ¶
BufferedInput reports input bytes read ahead of the last returned block.
func (*Decoder) ChannelMask ¶
ChannelMask reports the WAVEFORMATEXTENSIBLE speaker mask, or zero when unspecified. Channel slices arrive in increasing speaker-bit order.
func (*Decoder) Decode ¶
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 ¶
DecodeFloat calls consume with IEEE float samples before saturation. Float64 input is narrowed to float32. The slices are borrowed for the call.
func (*Decoder) Format ¶
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 ¶
FrameCount reports the number of frames in a sized audio chunk.
func (*Decoder) PCMFormat ¶
PCMFormat reports the native representation, sample rate, and layout. Companded G.711 expands to signed 16-bit samples.
func (*Decoder) SampleRate ¶
SampleRate reports the sample rate in Hz.