Documentation ¶
Index ¶
- Constants
- Variables
- func NewFilePlayer(path string, bufSize int, ord binary.ByteOrder, l logger.Logger) (*audio.Player, error)
- func NewFileRecorder(path string, fmt audio.Format, bufSize int, l logger.Logger) (*audio.Recorder, error)
- func NewPlayer(src Source, bufSize int, ord binary.ByteOrder, l logger.Logger) (*audio.Player, error)
- func NewRecorder(dst Sink, fmt audio.Format, bufSize int, l logger.Logger) (*audio.Recorder, error)
- type Reader
- type Sink
- type Source
- type Writer
Constants ¶
const (
EncodingPCM = 1
)
Supported WAV encodings.
Variables ¶
var ( ErrInvalidFile = errors.New("invalid WAV file") ErrShortWrite = errors.New("short write") )
WAV reader errors.
Functions ¶
func NewFilePlayer ¶
func NewFilePlayer(path string, bufSize int, ord binary.ByteOrder, l logger.Logger) (*audio.Player, error)
NewFilePlayer returns new audio.Player which uses a WAV reader as an audio source. WAV reader will use the file specified by path as its data source.
func NewFileRecorder ¶
func NewFileRecorder(path string, fmt audio.Format, bufSize int, l logger.Logger) (*audio.Recorder, error)
NewFileRecorder returns a new audio.Recorder with a WAV writer set as destination. The writer will write to a file specified by path.
Types ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader is a WAV file reader that can read serialised WAV files (or other io.Reader sources). Reader implements audio.Source and io.WriterTo interfaces. Data can be read either by calling Read and accessing the returned audio.Buffer, or using WriteTo. In the latter case, data will be serialised to binary using specified byte order.
func NewFileReader ¶
NewFileReader returns a new Reader that has a file specified by path set as its source. It's a convenience wrapper around the following code:
f, err := os.Open(path)
if err != nil { return err }
reader, err := wav.NewReader(f, bufSize, ord)
func NewReader ¶
NewReader returns a new Reader that will read WAV data from specified src. bufSize controls the size of internal buffer that will be used for reading the data, and ord tells the reader which byte order to use for decoding data from src.
func (*Reader) Buffer ¶
Buffer returns a copy of buffer used for reading the data. Returned buffer can be used for calling ReadBuffer, since it's guaranteed to have the same parameters (e.g. bit depth).
func (*Reader) Close ¶
Close closes the reader by closing the underlying src. Close can be called multiple times, but only the first time it will actually close src. All following calls will simply return the error returned by src.Close, if any.
func (*Reader) ReadBuffer ¶
ReadBuffer reads and decodes next chunk of data from src, into b.
type Sink ¶
type Sink interface { io.WriteSeeker io.Closer }
Sink is an interface for a WAV data source.
type Source ¶
type Source interface { io.ReadSeeker io.Closer }
Source is an interface for audio data source.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer is a WAV file writer that performs audio data encoding, serialisation into binary format and headers. Writer implements audio.Sink and io.Closer interfaces.
func NewWriter ¶
NewWriter returns a new Writer that will write data to specified dst. fmt tells the writer what format of audio to use (sample rate, number of channels, etc.). and bufSize controls the size of internal buffer that will be used for writing the data.
func (*Writer) Buffer ¶
Buffer returns a copy of buffer used for writing the data. Returned buffer can be used for calling WriteBuffer, since it's guaranteed to have the same parameters (e.g. bit depth).