Documentation ¶
Index ¶
Constants ¶
const ( BitDepthUndefined = BitDepth(0) BitDepth8 = BitDepth(8) BitDepth16 = BitDepth(16) BitDepth32 = BitDepth(32) BitDepth64 = BitDepth(64) )
Possible values for BitDepth are 8, 16, 32 and 64.
Variables ¶
var ( // ErrInvalidBitDepth is returned when provided BitDepth value is not supported. ErrInvalidBitDepth = errors.New("unsupported bit depth") )
var ErrInvalidBuffer = errors.New("invalid buffer")
ErrInvalidBuffer is returned when specified audio buffer is not valid for the operation.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer interface { // Size returns the size of the underlying slice. Size() int // BitDepth returns bit depth of the buffer. BitDepth() BitDepth // Data returns the pointer to the underlying slice. Data() interface{} // Clone clones the buffer, copying underlying slice. Clone() Buffer // Write writes provided int slice into the buffer. Write([]int, BitDepth) (int, error) // Read reads the contents of the buffer into provided slice. Read([]int, BitDepth) (int, error) // WriteTo writes the contents of the buffer into buf. // buf has to have matching bit depth. WriteTo(buf Buffer) (int, error) // ReadFrom reads the contents of buf into the buffer. // buf has to have matching bit depth. ReadFrom(buf Buffer) (int, error) // Encode writes the contents of the buffer into provided writer. // The buffer is responsible for performing resampling. Encode(binary.ByteOrder, io.Writer) (int, error) // Decode reads the contents of provided reader into the buffer. // The buffer is responsible for performing resampling. Decode(binary.ByteOrder, io.Reader) (int, error) }
Buffer represents a chunk of audio data of a specific size and bit depth. TODO: need to make sure that Write / Read are balanced and do not overwrite.
type Container ¶
Container represents an audio container that holds audio data in a Buffer with a specific Format.
type Player ¶
type Player struct {
// contains filtered or unexported fields
}
Player is an audio player that reads data from specified audio source, and plays it using OS audio stack through default output device. It is based on portaudio, so it will use whatever audio stack implementation that portaudio implements for current OS. It is not safe for concurrent use.
type RecordStream ¶
type RecordStream struct {
// contains filtered or unexported fields
}
RecordStream is an audio stream that implements io.WriterTo interface, by using an audio buffer and encoding it into binary data using specified audio format and byte order.
func NewRecordStream ¶
func NewRecordStream(fmt Format, ord binary.ByteOrder, bufSize int, log logger.Logger) (*RecordStream, error)
NewRecordStream returns a new record stream with specified format, byte order and size of underlying buffer.
func (*RecordStream) Close ¶
func (r *RecordStream) Close() error
Close closes RecordStream by closing the audio stream and terminating the audio stack. Close MUST be called before program exits, otherwise the audio devices of the OS may be unusable until the audio system is restarted.
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder is an audio recorder that reads data from default OS audio input and writes data to specified destination. It is based on portaudio, so it will use whatever audio stack implementation that portaudio implements for current OS. It is not safe for concurrent use.
func NewRecorder ¶
NewRecorder returns a new Recorder that will write audio to dst.
type SourceSink ¶
SourceSink is an audio container that can be both written to and read from.