Documentation
¶
Overview ¶
Package vorbis is a pure-Go Ogg Vorbis decoder (Vorbis I) for the sound files freedesktop sound themes ship (.oga): it decodes a whole stream once into interleaved signed 16-bit PCM, the layout a sample cache upload or a playback stream takes.
It covers the whole Vorbis I specification: floor types 0 and 1, residue types 0, 1 and 2, codebook lookup types 1 and 2, channel coupling, both block sizes and any channel count, and it checks every Ogg page's CRC. Output matches libvorbis's to within one least significant bit.
data, err := os.ReadFile("message-new-instant.oga")
sound, err := vorbis.Decode(data)
// sound.Samples holds sound.Frames()*sound.Channels samples
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotVorbis is data that is not an Ogg stream carrying Vorbis. ErrNotVorbis = errors.New("not an Ogg Vorbis stream") // ErrCorrupt is a stream whose framing, checksums or headers are // invalid. ErrCorrupt = errors.New("corrupt stream") // ErrTruncated is a stream that ends inside a page or a packet. ErrTruncated = errors.New("truncated stream") )
Decode fails with one of these, wrapped with what was being read.
Functions ¶
This section is empty.
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder decodes a Vorbis stream packet by packet, for a container that carries the packets itself (Matroska, MP4). A Decoder belongs to one goroutine.
func NewDecoder ¶
NewDecoder parses the stream's identification, comment and setup headers.
func (*Decoder) Decode ¶
Decode decodes one audio packet and appends its interleaved signed 16-bit frames to dst. The first packet after NewDecoder or Reset only primes the overlap and appends nothing, as Vorbis I specifies.
func (*Decoder) Reset ¶
func (d *Decoder) Reset()
Reset forgets the overlap with the packet before, for decoding from a packet that does not follow the last one decoded (after a seek).
func (*Decoder) SampleRate ¶
SampleRate is the stream's rate in frames per second.
type Sound ¶
type Sound struct {
// SampleRate is in frames per second.
SampleRate int
// Channels is the number of interleaved channels, in Vorbis
// channel order.
Channels int
// Samples is the PCM, interleaved by channel.
Samples []int16
}
Sound is a decoded stream.