opus

package
v0.0.0-...-366af99 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrStreamFalse        = StreamError(C.OP_FALSE)
	ErrStreamEOF          = StreamError(C.OP_EOF)
	ErrStreamHole         = StreamError(C.OP_HOLE)
	ErrStreamRead         = StreamError(C.OP_EREAD)
	ErrStreamFault        = StreamError(C.OP_EFAULT)
	ErrStreamImpl         = StreamError(C.OP_EIMPL)
	ErrStreamInval        = StreamError(C.OP_EINVAL)
	ErrStreamNotFormat    = StreamError(C.OP_ENOTFORMAT)
	ErrStreamBadHeader    = StreamError(C.OP_EBADHEADER)
	ErrStreamVersion      = StreamError(C.OP_EVERSION)
	ErrStreamNotAudio     = StreamError(C.OP_ENOTAUDIO)
	ErrStreamBadPacked    = StreamError(C.OP_EBADPACKET)
	ErrStreamBadLink      = StreamError(C.OP_EBADLINK)
	ErrStreamNoSeek       = StreamError(C.OP_ENOSEEK)
	ErrStreamBadTimestamp = StreamError(C.OP_EBADTIMESTAMP)
)

Libopusfile errors. The names are copied verbatim from the libopusfile library.

Variables

This section is empty.

Functions

This section is empty.

Types

type Stream

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

Stream wraps a io.Reader in a decoding layer. It provides an API similar to io.Reader, but it provides raw PCM data instead of the encoded Opus data.

This is not the same as directly decoding the bytes on the io.Reader; opus streams are Ogg Opus audio streams, which package raw Opus data.

This wraps libopusfile. For more information, see the api docs on xiph.org:

https://www.opus-codec.org/docs/opusfile_api-0.7/index.html

func NewStream

func NewStream(read io.Reader) (*Stream, error)

NewStream creates and initializes a new stream. Don't call .Init() on this.

func (*Stream) Close

func (s *Stream) Close() error

func (*Stream) Init

func (s *Stream) Init(read io.Reader) error

Init initializes a stream with an io.Reader to fetch opus encoded data from on demand. Errors from the reader are all transformed to an EOF, any actual error information is lost. The same happens when a read returns successfully, but with zero bytes.

func (*Stream) Read

func (s *Stream) Read(pcm []int16) (int, error)

Read a chunk of raw opus data from the stream and decode it. Returns the number of decoded samples per channel. This means that a dual channel (stereo) feed will have twice as many samples as the value returned.

Read may successfully read less bytes than requested, but it will never read exactly zero bytes successfully if a non-zero buffer is supplied.

The number of channels in the output data must be known in advance. It is possible to extract this information from the stream itself, but I'm not motivated to do that. Feel free to send a pull request.

func (*Stream) ReadFloat32

func (s *Stream) ReadFloat32(pcm []float32) (int, error)

ReadFloat32 is the same as Read, but decodes to float32 instead of int16.

type StreamError

type StreamError int

StreamError represents an error from libopusfile.

func (StreamError) Error

func (i StreamError) Error() string

Jump to

Keyboard shortcuts

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