wav

package module
v0.0.0-...-7cfd890 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2021 License: MIT Imports: 6 Imported by: 5

README

go-wav

golang reader and writer for *.wav voice files

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataReader

type DataReader interface {
	io.Reader
	io.ReaderAt
}

DataReader defines interface for DataReader

type DataReaderChunk

type DataReaderChunk struct {
	ID   []byte     // 'data'
	Size uint32     // sound data length * channels
	Data DataReader // Actual data
}

DataReaderChunk defines a data chunk with reader

type DataWriterChunk

type DataWriterChunk struct {
	ID   []byte
	Size uint32
	Data *bytes.Buffer
}

DataWriterChunk defines a data chunk with a writer

type File

type File interface {
	io.Reader
	io.Seeker
	io.ReaderAt
}

File defines a File io interface to read data

type FmtChunk

type FmtChunk struct {
	ID   []byte // 'fmt '
	Size uint32 // 16
	Data *FmtChunkData
}

FmtChunk is with 8 + 16 = 24 bytes

type FmtChunkData

type FmtChunkData struct {
	WaveFormatType uint16 // PCM は 1
	Channel        uint16 // monoral or stereo
	SamplesPerSec  uint32 // Sampling frequency: 8000, 16000 or 44100
	BytesPerSec    uint32 // the number of bytes required per second
	BlockSize      uint16 // Quantization accuracy * Number of channels
	BitsPerSamples uint16
}

FmtChunkData is with 16 bytes

type Reader

type Reader struct {
	RiffChunk *RiffChunk
	FmtChunk  *FmtChunk
	DataChunk *DataReaderChunk

	NumSamples    uint32
	ReadSampleNum uint32
	SampleTime    int
	// contains filtered or unexported fields
}

Reader defines a struct implements WaveHeader interface

func NewReader

func NewReader(r io.Reader) (*Reader, error)

NewReader creates a Reader from a io.Reader of a file

func NewReaderFromBytes

func NewReaderFromBytes(buf []byte) (*Reader, error)

NewReaderFromBytes creates a Reader from a byte slice

func NewReaderFromFile

func NewReaderFromFile(fileName string) (*Reader, error)

NewReaderFromFile opens a file and creates a new reader of it.

func (*Reader) Read

func (rd *Reader) Read(p []byte) (int, error)

reads only audio data

func (*Reader) ReadRawSample

func (rd *Reader) ReadRawSample() ([]byte, error)

ReadRawSample reads raw sample

func (*Reader) ReadSample

func (rd *Reader) ReadSample() ([]float64, error)

ReadSample reads sample as float64 slice

func (*Reader) ReadSampleInt

func (rd *Reader) ReadSampleInt() ([]int, error)

ReadSampleInt reads sample as int slice

type RiffChunk

type RiffChunk struct {
	ID         []byte // 'RIFF'
	Size       uint32 // 36bytes + data_chunk_size or whole_file_size - 'RIFF'+ChunkSize (8byte)
	FormatType []byte // 'WAVE'
}

RiffChunk has 12 bytes

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer defines a writer to write data to a wave file

func NewWriter

func NewWriter(param WriterParam) (*Writer, error)

NewWriter creates and writes wave data to a wave file.

func (*Writer) Close

func (w *Writer) Close() error

Close flushes chunks and closes the created file

func (*Writer) Write

func (w *Writer) Write(p []byte) (int, error)

Write writes byte slice as samples to the writer

func (*Writer) WriteSample16

func (w *Writer) WriteSample16(samples []int16) (int, error)

WriteSample16 writes int16 slice samples to the writer

func (*Writer) WriteSample8

func (w *Writer) WriteSample8(samples []uint8) (int, error)

WriteSample8 writes uint8 slice samples to the writer

type WriterParam

type WriterParam struct {
	Out           io.WriteCloser
	Channel       int
	SampleRate    int
	BitsPerSample int
}

WriterParam defines the parameters for creating a new writer

Jump to

Keyboard shortcuts

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