audio

package
v0.0.0-...-b3bab2c Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2023 License: MIT Imports: 7 Imported by: 4

Documentation

Index

Constants

View Source
const (
	Int8 = iota
	Int16
	Int32
	Float32
)

Possible NumberTypes

Variables

View Source
var ErrBufferTooLarge = errors.New("audio: buffer is too large")

ErrBufferTooLarge is returned when the audio buffer received is too large to process. This commonly occurs with streams for realtime applications.

View Source
var ErrInvalidNumberType = errors.New("audio: invalid number type")

ErrInvalidNumberType is returned if an invalid number type is provided, mainly to offline streams.

View Source
var ErrInvalidReadDestination = errors.New("audio: invalid read destination")

ErrInvalidReadDestination is returned if the destination of a ReadFrom function call is not a valid audio slice.

Functions

func ReadFromAnything

func ReadFromAnything(dst interface{}, src interface{}, num int) error

ReadFromAnything converts between any valid audio slice.

func ReadFromFloat32

func ReadFromFloat32(dst interface{}, src []float32, num int) error

ReadFromFloat32 converts a []float32 to any other valid audio slice.

func ReadFromInt16

func ReadFromInt16(dst interface{}, src []int16, num int) error

ReadFromInt16 converts an []int16 to any other valid audio slice.

func ReadFromInt32

func ReadFromInt32(dst interface{}, src []int32, num int) error

ReadFromInt32 converts an []int32 to any other valid audio slice.

func ReadFromInt8

func ReadFromInt8(dst interface{}, src []int8, num int) error

ReadFromInt8 converts an []int8 to any other valid audio slice.

func SliceLength

func SliceLength(slice interface{}) int

SliceLength returns the length of a valid audio slice.

Types

type DevicePair

type DevicePair struct {
	Playback PlaybackDevice
	Record   RecordingDevice
}

DevicePair represents a pair of a playback and recording device.

func (*DevicePair) Close

func (a *DevicePair) Close()

Close closes both the playback and recording devices of a device pair.

type Filter

type Filter interface {
	Filter(Stream) Stream
}

Filter represents an audio stream filter.

type NumberType

type NumberType int

NumberType represents a PCM number type.

type OfflineStream

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

OfflineStream represents a stream which is wrapped and is usually based on a different stream of bytes or numbers, such as over a network.

func NewOfflineStream

func NewOfflineStream(sampleRate int, bufferSize int) *OfflineStream

NewOfflineStream returns an offline stream, a simple buffered stream that allows you to convert io.Read/Write operations into a stream. Buffer size is measured by number of samples.

func (*OfflineStream) Close

func (o *OfflineStream) Close()

Close closes the offline stream, and causes any ongoing reads to return.

func (*OfflineStream) Read

func (o *OfflineStream) Read(dst interface{}) (int, error)

func (*OfflineStream) ReadBytes

func (o *OfflineStream) ReadBytes(rd io.Reader, bo binary.ByteOrder, numType NumberType) error

ReadBytes reads bytes of values into the offline stream.

func (*OfflineStream) SampleRate

func (o *OfflineStream) SampleRate() int

SampleRate returns the sample rate of the offline stream.

func (*OfflineStream) WriteBytes

func (o *OfflineStream) WriteBytes(b []byte, bo binary.ByteOrder, numType NumberType) error

WriteBytes writes bytes of values into the offline stream.

func (*OfflineStream) WriteValues

func (o *OfflineStream) WriteValues(val interface{}) error

WriteValues writes a slice of number values into the offline stream.

type PlaybackDevice

type PlaybackDevice interface {
	PlayStream(Stream) error
	Close()
}

PlaybackDevice represents a playback device that can play a stream.

type RecordingDevice

type RecordingDevice interface {
	OpenStream() (Stream, error)
	Close()
}

RecordingDevice represents a recording device that can open a stream.

type Stream

type Stream interface {
	SampleRate() int
	Read(interface{}) (int, error)
}

Stream represents an audio stream.

func NewRealtimeStream

func NewRealtimeStream(stream Stream, bufferSize int) Stream

NewRealtimeStream converts a stream into a buffered stream for use in realtime applications, such as audio over a network.

Jump to

Keyboard shortcuts

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