vorbis

package
v0.3.21 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 9 Imported by: 2 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 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

View Source
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

func NewDecoder(id, comment, setup []byte) (*Decoder, error)

NewDecoder parses the stream's identification, comment and setup headers.

func (*Decoder) Channels

func (d *Decoder) Channels() int

Channels is the stream's channel count, in Vorbis channel order.

func (*Decoder) Decode

func (d *Decoder) Decode(dst []int16, packet []byte) ([]int16, error)

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

func (d *Decoder) SampleRate() int

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.

func Decode

func Decode(data []byte) (Sound, error)

Decode decodes the first logical Vorbis stream of an Ogg file. Other logical streams multiplexed with it are skipped; a chained stream after it is not read.

func (Sound) Frames

func (s Sound) Frames() int

Frames is the length of the sound in frames (samples per channel).

Jump to

Keyboard shortcuts

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