Documentation
¶
Index ¶
- type Engine
- type Event
- type EventType
- type OggCodec
- type OggPage
- type OggReader
- func (o *OggReader) Duration() int64
- func (o *OggReader) PreSkip() int
- func (o *OggReader) ReadPage() (*OggPage, error)
- func (o *OggReader) Reset() error
- func (o *OggReader) SampleRate() int
- func (o *OggReader) ScanLastGranule() error
- func (o *OggReader) SeekToGranule(target int64) error
- func (o *OggReader) SetDataStart(offset int64)
- type Options
- type SeekResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine runs audio playback in a background goroutine.
func (*Engine) TogglePause ¶
func (e *Engine) TogglePause()
type OggCodec ¶
type OggCodec interface {
// SampleRate returns the audio sample rate.
SampleRate() int
// Channels returns the number of audio channels.
Channels() int
// PreSkip returns samples to skip at stream start (0 for Vorbis).
PreSkip() int
// GranuleToSamples converts granule position to sample count.
GranuleToSamples(granule int64) int64
// AddHeaderPacket adds a header packet for codecs that need multiple headers.
// Returns true when all headers are received.
// For Opus, this is a no-op (single header). For Vorbis, collects 3 headers.
AddHeaderPacket(packet []byte) (complete bool, err error)
// Decode decodes a packet into PCM samples.
// Returns the number of samples per channel decoded.
Decode(packet []byte, pcm []float32) (samplesPerChannel int, err error)
// Reset resets decoder state (needed after seeking).
Reset() error
}
OggCodec handles codec-specific initialization and decoding for Ogg streams.
type OggReader ¶
type OggReader struct {
// contains filtered or unexported fields
}
OggReader reads Ogg streams with seeking support. It is codec-agnostic - the caller is responsible for parsing codec headers.
func NewOggReader ¶
func NewOggReader(r io.ReadSeeker, sampleRate, preSkip int) (*OggReader, error)
NewOggReader creates a new OggReader from a seekable stream. sampleRate and preSkip are needed for duration/seeking calculations. The caller is responsible for parsing codec headers before calling this.
func (*OggReader) Duration ¶
Duration returns the total number of audio samples (excluding pre-skip).
func (*OggReader) ReadPage ¶
ReadPage reads the next Ogg page from the stream. Handles packets that span multiple pages by joining partial data. Returns io.EOF when no more pages are available.
func (*OggReader) SampleRate ¶
SampleRate returns the sample rate used for duration calculations.
func (*OggReader) ScanLastGranule ¶
ScanLastGranule finds the granule position of the last page. This should be called after header parsing to enable duration calculation.
func (*OggReader) SeekToGranule ¶
SeekToGranule seeks to the page containing or just before the target granule position. Uses bisection search for efficiency on large files.
func (*OggReader) SetDataStart ¶
SetDataStart sets the byte offset where audio data begins. Called after header parsing is complete.