oggvorbis

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2021 License: MIT Imports: 5 Imported by: 78

README

oggvorbis

a native go ogg/vorbis decoder

GoDoc

Usage

This package provides the type oggvorbis.Reader, which can be used to read .ogg files.

r, err := oggvorbis.NewReader(reader)
// handle error

fmt.Println(r.SampleRate())
fmt.Println(r.Channels())

buffer := make([]float32, 8192)
for {
	n, err := r.Read(buffer)

	// use buffer[:n]

	if err == io.EOF {
		break
	}
	if err != nil {
		// handle error
	}
}

The reader also provides methods for seeking, these will only work if the reader was created from an io.ReadSeeker.

There are also convenience functions to read an entire (small) file, similar to ioutil.ReadAll.

data, format, err := oggvorbis.ReadAll(reader)

Documentation

Overview

Package oggvorbis decodes audio from ogg/vorbis files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCommentHeader

func GetCommentHeader(in io.Reader) (vorbis.CommentHeader, error)

GetCommentHeader returns a struct containing info from the comment header.

Types

type Format

type Format struct {
	SampleRate int
	Channels   int
	Bitrate    vorbis.Bitrate
}

Format contains information about the audio format of an ogg/vorbis file.

func GetFormat

func GetFormat(in io.Reader) (*Format, error)

GetFormat reads the first ogg page from in to get the audio format.

func GetLength

func GetLength(in io.ReadSeeker) (int64, *Format, error)

GetLength returns the length of the file in samples and the audio format.

func ReadAll

func ReadAll(in io.Reader) ([]float32, *Format, error)

ReadAll decodes audio from in until an error or EOF.

type Reader

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

A Reader can read audio from an ogg/vorbis file.

func NewReader

func NewReader(in io.Reader) (*Reader, error)

NewReader creates a new Reader. Some of the returned reader's methods will only work if in also implements io.Seeker

func (*Reader) Bitrate

func (r *Reader) Bitrate() vorbis.Bitrate

Bitrate returns a struct containing information about the bitrate.

func (*Reader) Channels

func (r *Reader) Channels() int

Channels returns the number of channels of the vorbis stream.

func (*Reader) CommentHeader

func (r *Reader) CommentHeader() vorbis.CommentHeader

CommentHeader returns a struct containing info from the comment header.

func (*Reader) Length

func (r *Reader) Length() int64

Length returns the length of the audio data in samples. A return value of zero means the length is unknown, probably because the underlying reader is not seekable.

func (*Reader) Position

func (r *Reader) Position() int64

Position returns the current position in samples.

func (*Reader) Read

func (r *Reader) Read(p []float32) (int, error)

Read reads and decodes audio data and stores the result in p.

It returns the number of values decoded (number of samples * channels) and any error encountered, similarly to an io.Reader's Read method.

The number of values produced will always be a multiple of Channels().

func (*Reader) SampleRate

func (r *Reader) SampleRate() int

SampleRate returns the sample rate of the vorbis stream.

func (*Reader) SetPosition

func (r *Reader) SetPosition(pos int64) error

SetPosition seeks to a position in samples. It will return an error if the underlying reader is not seekable.

Jump to

Keyboard shortcuts

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