audio

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(block Block, format media.SampleFormat, bitsPerSample int) (*media.AudioFrame, error)

func EncodeInto

func EncodeInto(block Block, format media.SampleFormat, bitsPerSample int, scratch *Scratch) (*media.AudioFrame, error)

Types

type Block

type Block struct {
	Source   *media.AudioFrame
	Channels Channels
	Layout   media.ChannelLayout
	Rate     int
	Format   media.SampleFormat
	Bits     int
	PTS      media.Pts
}

func Decode

func Decode(frame *media.Frame) (Block, error)

func DecodeInto

func DecodeInto(frame *media.Frame, scratch *Scratch) (Block, error)

func (Block) Clone

func (b Block) Clone() Block

Clone returns an independent copy that shares no state with b.

func (Block) Samples

func (b Block) Samples() int

func (Block) Slice

func (b Block) Slice(start, end int) Block

Slice returns an independent Block covering the [start, end) sample range. It never aliases the receiver's Channels, so mutating the result is safe.

type Channels

type Channels [][]float32

Channels holds one []float32 sample buffer per audio channel.

func (Channels) Clone

func (c Channels) Clone() Channels

Clone returns an independent copy that shares no backing arrays with c.

type Record

type Record struct {
	PTS     media.Pts
	Samples int
}

Record describes a Block's shape (timing and sample count) without retaining its sample data. Spool uses it to index buffered audio; callers that track block shape without buffering samples at all (e.g. a silence-run replay buffer) can reuse the same bookkeeping.

type Scratch

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

Scratch holds reusable per-channel and interleave buffers for repeated DecodeInto/EncodeInto calls made by the same caller, so steady-state frame processing reuses last frame's backing arrays instead of allocating a fresh []float32 per channel per frame. A Block returned by DecodeInto aliases its Scratch's buffers, so the caller must be done with it (mutate it in place and/or hand it to EncodeInto) before decoding another frame into the same Scratch. Not safe for concurrent use: a caller that decodes more than one frame concurrently (e.g. a filter with multiple input ports pulled on separate goroutines) needs one Scratch per concurrent caller.

type Spool

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

Spool retains decoded audio with bounded RAM and transparently spills samples to a temporary file.

func NewSpool

func NewSpool(limit int64, dir string) *Spool

func (*Spool) Append

func (s *Spool) Append(block Block) error

func (*Spool) Close

func (s *Spool) Close() error

func (*Spool) FirstPTS

func (s *Spool) FirstPTS() media.Pts

func (*Spool) Next

func (s *Spool) Next() (Block, bool, error)

func (*Spool) Rewind

func (s *Spool) Rewind() error

Jump to

Keyboard shortcuts

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