Documentation ¶
Index ¶
- func AdjustChannels(iChs, oChs int, audioFrames []float32) []float32
- func AdjustVolume(volume float32, aBuffer []float32)
- type DefaultRouter
- func (r *DefaultRouter) AddSink(name string, s Sink, enabled bool) error
- func (r *DefaultRouter) Close()
- func (r *DefaultRouter) EnableSink(name string, enabled bool) error
- func (r *DefaultRouter) Flush()
- func (r *DefaultRouter) RemoveSink(name string) error
- func (r *DefaultRouter) Sink(name string) (Sink, bool, error)
- func (r *DefaultRouter) Write(msg Msg) SinkErrors
- type DefaultSelector
- type Msg
- type Node
- type OnDataCb
- type Router
- type Selector
- type Sink
- type SinkError
- type SinkErrors
- type Source
- type Token
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AdjustChannels ¶
AdjustChannels is a helper function which will either add or remove a channel (e.g. converting from Mono to Stereo or vice versa).
func AdjustVolume ¶
AdjustVolume adjusts the volume in all the audio frames within an audio buffer
Types ¶
type DefaultRouter ¶
type DefaultRouter struct { sync.RWMutex // for map & variables // contains filtered or unexported fields }
DefaultRouter is the standard manager for audio sinks.
func NewDefaultRouter ¶
func NewDefaultRouter() (*DefaultRouter, error)
NewDefaultRouter returns an initialized default router for audio sinks.
func (*DefaultRouter) AddSink ¶
func (r *DefaultRouter) AddSink(name string, s Sink, enabled bool) error
AddSink adds an audio device which satisfies the Sink interface. When marked as enabled, incoming audio Msgs will be written to this device.
func (*DefaultRouter) Close ¶
func (r *DefaultRouter) Close()
Close disables and closes all the Sinks of the router.
func (*DefaultRouter) EnableSink ¶
func (r *DefaultRouter) EnableSink(name string, enabled bool) error
EnableSink will mark the audio Sink as enabled, so that incoming audio Msgs will be written to it.
func (*DefaultRouter) Flush ¶
func (r *DefaultRouter) Flush()
Flush flushes the buffers of all enabled sinks.
func (*DefaultRouter) RemoveSink ¶
func (r *DefaultRouter) RemoveSink(name string) error
RemoveSink removes an audio sink from the router.
func (*DefaultRouter) Sink ¶
func (r *DefaultRouter) Sink(name string) (Sink, bool, error)
Sink returns the audio sink object. The boolean return value indicates if the sink is currently enabled. If no sink is found under the specified name, an error will be returned.
func (*DefaultRouter) Write ¶
func (r *DefaultRouter) Write(msg Msg) SinkErrors
Write will write the Msg to all enabled audio sinks.
type DefaultSelector ¶
DefaultSelector is the default implementation of an audio Selector.
func NewDefaultSelector ¶
func NewDefaultSelector() (*DefaultSelector, error)
NewDefaultSelector returns an initialized, but empty DefaultSelector.
func (*DefaultSelector) AddSource ¶
func (s *DefaultSelector) AddSource(name string, src Source)
AddSource adds an audio device which implements the audio.Source interface to the Selector.
func (*DefaultSelector) Close ¶
func (s *DefaultSelector) Close()
Close disables and closes all the Sources of the selector.
func (*DefaultSelector) RemoveSource ¶
func (s *DefaultSelector) RemoveSource(name string) error
RemoveSource removes an audio Source from the Selector.
func (*DefaultSelector) SetOnDataCb ¶
func (s *DefaultSelector) SetOnDataCb(cb OnDataCb)
SetOnDataCb sets the callback function will will be executed when new audio msgs are available from the selected source.
func (*DefaultSelector) SetSource ¶
func (s *DefaultSelector) SetSource(name string) error
SetSource selects the audio source from which data data will be provided (through the OnDataCb callback).
type Msg ¶
type Msg struct { Data []float32 // audio data, float32 interleaved (if stereo) Samplerate float64 // samplerate, e.g. 48000Hz Channels int // most of the time either 1 (mono) or 2 (stereo) Frames int // Number of Frames in the buffer EOF bool // End of File Metadata map[string]interface{} // storage for passing any kind of data along the audio Msg }
Msg contains an audio buffer with it's metadata. Msgs are internally used to pass the data from the source, through the audio nodes to the audio sink(s).
type Node ¶
type Node interface { Write(Msg) error // Write data into the Node SetCb(OnDataCb) // Set the callback which will be executed when processing has finished. }
Node is the interface for an audio node. Nodes are typically located in an audio Chain between the Source and the Sink and perform custom processing on (Audio)Msgs.
type OnDataCb ¶
type OnDataCb func(Msg)
OnDataCb is a callback function which will be called by an audio source when new data is available
type Router ¶
type Router interface { AddSink(string, Sink, bool) error RemoveSink(string) error Sink(string) (Sink, bool, error) EnableSink(string, bool) error Write(Msg) SinkErrors Close() Flush() }
Router manages several audio sinks. It allows to write incoming audio Messages to serveral sinks (e.g. speakers, files, network..etc).
type Selector ¶
type Selector interface { AddSource(string, Source) RemoveSource(string) error SetSource(string) error SetOnDataCb(OnDataCb) Close() }
Selector manages several audio sources. Whenever the selected source (network, microphone..etc) has new data available the provided OnDataCb Callback will be executed.
type Sink ¶
type Sink interface { Start() error Stop() error Close() error SetVolume(float32) Volume() float32 Write(Msg) error Flush() }
Sink is the interface which is implemented by an audio sink. This could be an Audio player or a file for recording.
type SinkError ¶
SinkError is an Error which is used when data could not be written to a particular audio Sink.
type SinkErrors ¶
type SinkErrors []*SinkError
SinkErrors is a convenience type which represents a slice of SinkError.