Documentation
¶
Index ¶
- Constants
- func CodecEnabled(c Codec) bool
- func CodecEnabledByName(name string) bool
- func CodecSetEnabled(name string, enabled bool)
- func CodecsSetEnabled(codecs map[string]bool)
- func MonoToStereo(dst, src PCM16Sample)
- func OnRegister(fnc func(c Codec))
- func Pipe[T ~[]E, E comparable](sampleRate int) (*PipeReader[T, E], *PipeWriter[T, E])
- func PlayAudio[T any](ctx context.Context, w Writer[T], sampleDur time.Duration, frames []T) error
- func RegisterCodec(c Codec)
- func StereoToMono(dst, src PCM16Sample)
- type Codec
- type CodecInfo
- type Frame
- type MediaSampleWriter
- type MultiWriter
- type PCM16Processor
- type PCM16Sample
- type PCM16Writer
- type PipeReader
- type PipeWriter
- type Processor
- type ReadCloser
- type Reader
- type SwitchWriter
- func (s *SwitchWriter) Close() error
- func (s *SwitchWriter) Disable()
- func (s *SwitchWriter) Enable()
- func (s *SwitchWriter) Get() PCM16Writer
- func (s *SwitchWriter) SampleRate() int
- func (s *SwitchWriter) SetSampleRate(rate int)
- func (s *SwitchWriter) String() string
- func (s *SwitchWriter) Swap(w PCM16Writer) PCM16Writer
- func (s *SwitchWriter) WriteSample(sample PCM16Sample) error
- type WriteCloser
- func DumpWriter[T Frame](ext string, name string, w WriteCloser[T]) WriteCloser[T]
- func FromSampleWriter[T ~[]byte](w MediaSampleWriter, sampleRate int, sampleDur time.Duration) WriteCloser[T]
- func NewFileWriter[T Frame](w io.WriteCloser, sampleRate int) WriteCloser[T]
- func NopCloser[T any](w Writer[T]) WriteCloser[T]
- type Writer
Constants ¶
const ( // DefFrameDur is a default duration of an audio frame. DefFrameDur = 20 * time.Millisecond // DefFramesPerSec is a default number of audio frames per second. DefFramesPerSec = int(time.Second / DefFrameDur) )
Variables ¶
This section is empty.
Functions ¶
func CodecEnabled ¶
func CodecEnabledByName ¶
func CodecSetEnabled ¶
func CodecsSetEnabled ¶
func MonoToStereo ¶
func MonoToStereo(dst, src PCM16Sample)
MonoToStereo converts mono PCM from src to stereo PCM in dst. It panics if size of dst is too small. Src and dst must not overlap.
func OnRegister ¶
func OnRegister(fnc func(c Codec))
func Pipe ¶
func Pipe[T ~[]E, E comparable](sampleRate int) (*PipeReader[T, E], *PipeWriter[T, E])
Pipe creates a synchronous in-memory pipe. It can be used to connect code expecting a Reader with code expecting a Writer.
func PlayAudio ¶
PlayAudio into a given writer. It assumes that frames are already at the writer's sample rate.
func RegisterCodec ¶
func RegisterCodec(c Codec)
func StereoToMono ¶
func StereoToMono(dst, src PCM16Sample)
StereoToMono converts stereo PCM from src to mono PCM in dst. It panics if size of dst is too small. Src and dst may overlap.
Types ¶
type Codec ¶
type Codec interface {
Info() CodecInfo
}
func EnabledCodecs ¶
func EnabledCodecs() []Codec
type MediaSampleWriter ¶
type MultiWriter ¶
type MultiWriter[T any] []WriteCloser[T]
func (MultiWriter[T]) Close ¶
func (s MultiWriter[T]) Close() error
func (MultiWriter[T]) SampleRate ¶
func (s MultiWriter[T]) SampleRate() int
func (MultiWriter[T]) String ¶
func (s MultiWriter[T]) String() string
func (MultiWriter[T]) WriteSample ¶
func (s MultiWriter[T]) WriteSample(sample T) error
type PCM16Processor ¶
type PCM16Processor = Processor[PCM16Sample]
type PCM16Sample ¶
type PCM16Sample []int16
func Resample ¶
func Resample(dst PCM16Sample, dstSampleRate int, src PCM16Sample, srcSampleRate int) PCM16Sample
Resample the source sample into the destination sample rate. It appends resulting samples to dst and returns the result.
func (PCM16Sample) Clear ¶
func (s PCM16Sample) Clear()
func (PCM16Sample) Size ¶
func (s PCM16Sample) Size() int
func (*PCM16Sample) WriteSample ¶
func (s *PCM16Sample) WriteSample(data PCM16Sample) error
type PCM16Writer ¶
type PCM16Writer = WriteCloser[PCM16Sample]
func DumpWriterPCM16 ¶
func DumpWriterPCM16(name string, w PCM16Writer) PCM16Writer
func NewPCM16BufferWriter ¶
func NewPCM16BufferWriter(buf *PCM16Sample, sampleRate int) PCM16Writer
func NewPCM16FrameWriter ¶
func NewPCM16FrameWriter(buf *[]PCM16Sample, sampleRate int) PCM16Writer
func ResampleWriter ¶
func ResampleWriter(w PCM16Writer, sampleRate int) (w2 PCM16Writer)
ResampleWriter returns a new writer that expects samples of a given sample rate and resamples then for the destination writer.
type PipeReader ¶
type PipeReader[T ~[]E, E comparable] struct { // contains filtered or unexported fields }
A PipeReader is the read half of a pipe.
func (*PipeReader[T, E]) Close ¶
func (r *PipeReader[T, E]) Close() error
Close closes the reader; subsequent writes to the write half of the pipe will return the error io.ErrClosedPipe.
func (*PipeReader[T, E]) CloseWithError ¶
func (r *PipeReader[T, E]) CloseWithError(err error) error
CloseWithError closes the reader; subsequent writes to the write half of the pipe will return the error err.
CloseWithError never overwrites the previous error if it exists and always returns nil.
func (*PipeReader[T, E]) ReadSample ¶
func (r *PipeReader[T, E]) ReadSample(data T) (n int, err error)
ReadSample implements the Reader interface.
type PipeWriter ¶
type PipeWriter[T ~[]E, E comparable] struct { // contains filtered or unexported fields }
A PipeWriter is the write half of a pipe.
func (*PipeWriter[T, E]) Close ¶
func (w *PipeWriter[T, E]) Close() error
Close closes the writer; subsequent reads from the read half of the pipe will return no bytes and EOF.
func (*PipeWriter[T, E]) CloseWithError ¶
func (w *PipeWriter[T, E]) CloseWithError(err error) error
CloseWithError closes the writer; subsequent reads from the read half of the pipe will return no bytes and the error err, or EOF if err is nil.
CloseWithError never overwrites the previous error if it exists and always returns nil.
func (*PipeWriter[T, E]) SampleRate ¶
func (w *PipeWriter[T, E]) SampleRate() int
SampleRate implements the Writer interface.
func (*PipeWriter[T, E]) String ¶
func (w *PipeWriter[T, E]) String() string
func (*PipeWriter[T, E]) WriteSample ¶
func (w *PipeWriter[T, E]) WriteSample(data T) (err error)
WriteSample implements the Writer interface.
type Processor ¶
type Processor[T any] func(w WriteCloser[T]) WriteCloser[T]
type ReadCloser ¶
type Reader ¶
func NewPCM16BufferReader ¶
func NewPCM16BufferReader(buf PCM16Sample) Reader[PCM16Sample]
type SwitchWriter ¶
type SwitchWriter struct {
// contains filtered or unexported fields
}
func NewSwitchWriter ¶
func NewSwitchWriter(sampleRate int) *SwitchWriter
func (*SwitchWriter) Close ¶
func (s *SwitchWriter) Close() error
func (*SwitchWriter) Disable ¶
func (s *SwitchWriter) Disable()
func (*SwitchWriter) Enable ¶
func (s *SwitchWriter) Enable()
func (*SwitchWriter) Get ¶
func (s *SwitchWriter) Get() PCM16Writer
func (*SwitchWriter) SampleRate ¶
func (s *SwitchWriter) SampleRate() int
SampleRate returns an expected sample rate for this writer. It panics if the sample rate is not specified.
func (*SwitchWriter) SetSampleRate ¶
func (s *SwitchWriter) SetSampleRate(rate int)
SetSampleRate sets a new sample rate for the switch. For this to work, NewSwitchWriter(-1) must be called. The code will panic if sample rate is unset when a writer is attached, or if this method is called twice.
func (*SwitchWriter) String ¶
func (s *SwitchWriter) String() string
func (*SwitchWriter) Swap ¶
func (s *SwitchWriter) Swap(w PCM16Writer) PCM16Writer
Swap sets an underlying writer and returns the old one. Caller is responsible for closing the old writer.
func (*SwitchWriter) WriteSample ¶
func (s *SwitchWriter) WriteSample(sample PCM16Sample) error
type WriteCloser ¶
func DumpWriter ¶
func DumpWriter[T Frame](ext string, name string, w WriteCloser[T]) WriteCloser[T]
func FromSampleWriter ¶
func FromSampleWriter[T ~[]byte](w MediaSampleWriter, sampleRate int, sampleDur time.Duration) WriteCloser[T]
func NewFileWriter ¶
func NewFileWriter[T Frame](w io.WriteCloser, sampleRate int) WriteCloser[T]
func NopCloser ¶
func NopCloser[T any](w Writer[T]) WriteCloser[T]