wav

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EncodingPCM = 1
)

Supported WAV encodings.

Variables

View Source
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.

func NewPlayer

func NewPlayer(src Source, bufSize int, ord binary.ByteOrder, l logger.Logger) (*audio.Player, error)

NewPlayer returns new audio.Player which uses a WAV reader as an audio source.

func NewRecorder

func NewRecorder(dst Sink, fmt audio.Format, bufSize int, l logger.Logger) (*audio.Recorder, error)

NewRecorder returns a new audio.Recorder with a WAV writer set as destination.

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

func NewFileReader(path string, bufSize int, ord binary.ByteOrder) (*Reader, error)

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

func NewReader(src Source, bufSize int, ord binary.ByteOrder) (*Reader, error)

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

func (r *Reader) Buffer() audio.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

func (r *Reader) Close() error

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) Format

func (r *Reader) Format() audio.Format

Format returns the audio format of the data.

func (*Reader) ReadBuffer

func (r *Reader) ReadBuffer(b audio.Buffer) (int, error)

ReadBuffer reads and decodes next chunk of data from src, into b.

func (*Reader) WriteTo

func (r *Reader) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo interface. It reads data from internal audio buffer, encodes it using Reader byte order and writes it into w. It will return io.EOF when the underlying buffer and src have been exhausted.

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

func NewWriter(dst Sink, fmt audio.Format, bufSize int) (*Writer, error)

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

func (w *Writer) Buffer() audio.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).

func (*Writer) Close

func (w *Writer) Close() error

Close closes the writer by closing the encoder and the underlying dst.

func (*Writer) Format

func (w *Writer) Format() audio.Format

Format returns the audio format of the writer.

func (*Writer) WriteBuffer

func (w *Writer) WriteBuffer(b audio.Buffer) (int, error)

WriteBuffer writes data from b into the writer.

Jump to

Keyboard shortcuts

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