oggvorbis

package
v0.0.0-...-682a2af Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2024 License: BSD-2-Clause, MIT Imports: 11 Imported by: 0

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 Clear

func Clear(f *OVFile) error

Clear clears the decoded buffers and closes the file

func GetCommentHeader

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

GetCommentHeader returns a struct containing info from the comment header.

func Info

func Info(f *OVFile, info *VorbisInfo) error

Info updates the specified VorbisInfo structure with contains basic information about the audio in a vorbis stream

func PcmSeek

func PcmSeek(f *OVFile, pos int64) error

Seek seeks to the offset specified (in number pcm samples) within the physical bitstream. This function only works for seekable streams. Updates everything needed within the decoder, so you can immediately call Read() and get data from the newly seeked to position.

func PcmTotal

func PcmTotal(f *OVFile) (int64, error)

PcmTotal returns the total number of pcm samples of the physical bitstream or a specified logical bit stream. To retrieve the total pcm samples for the entire physical bitstream, the 'link' parameter should be set to -1

func Read

func Read(f *OVFile, buffer unsafe.Pointer, nrBytes int) (int, int, error)

Read decodes next data from the file updating the specified buffer contents and returns the number of bytes read, the number of current logical bitstream and an error

func Seekable

func Seekable() bool

Seekable returns indication whether or not the bitstream is seekable

func TimeTell

func TimeTell() (float64, error)

TimeTell returns the current decoding offset in seconds.

func TimeTotal

func TimeTotal() (float64, error)

TimeTotal returns the total time in seconds of the physical bitstream or a specified logical bitstream To retrieve the time total for the entire physical bitstream, 'i' should be set to -1.

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 OVFile

type OVFile struct {
	OsHandle *os.File
	FsHandle fs.File
	OvReader *Reader
}

func Open

func Open(path string) (*OVFile, error)

Open opens an ogg vorbis file for decoding Returns an opaque pointer to the internal decode structure and an error

func OpenEmbedded

func OpenEmbedded(path string, efs *embed.FS) (*OVFile, error)

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.

type VorbisInfo

type VorbisInfo struct {
	Version        int
	Channels       int
	Rate           int
	BitrateUpper   int
	BitrateNominal int
	BitrateLower   int
}

Jump to

Keyboard shortcuts

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