wave

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateWaveHeader

func CreateWaveHeader(sampleRate int, channelCount int, dataSize uint32) ([]byte, error)

CreateWaveHeader -

func PCMToWave

func PCMToWave(sampleRate int, channelCount int, pcm []byte) ([]byte, error)

PCMToWave -

Types

type DataReader

type DataReader interface {
	io.Reader
	io.ReaderAt
}

DataReader - load

type DataReaderChunk

type DataReaderChunk struct {
	ID   []byte     // 'data'
	Size uint32     // data size * channel
	Data DataReader // actual data
}

DataReaderChunk -

type DataWriterChunk

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

DataWriterChunk -

type FmtChunk

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

FmtChunk - 8 + 16 = 24byte

type Reader

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

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

Reader -

func NewReader

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

NewReader -

func NewReaderByData

func NewReaderByData(waveData []byte, size int64) (*Reader, error)

NewReaderByData -

func NewReaderByFile

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

NewReaderByFile -

func (*Reader) Read

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

onlu read sound data

func (*Reader) ReadRawSample

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

ReadRawSample -

func (*Reader) ReadSample

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

ReadSample -

func (*Reader) ReadSampleInt

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

ReadSampleInt -

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 - 12byte

type WavFmtChunkData

type WavFmtChunkData struct {
	WaveFormatType uint16 // PCM  1
	Channel        uint16 // channel
	SamplesPerSec  uint32
	BytesPerSec    uint32 // The number of bytes required per second
	BlockSize      uint16 // Quantization accuracy * number of channels
	BitsPerSamples uint16 // Quantization accuracy
}

WavFmtChunkData - 6byte

type Writer

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

Writer -

func New

func New(fileName string, sampleRate int, channelCount int) (*Writer, error)

New builds a new OGG Opus writer

func NewBuffer

func NewBuffer(sampleRate int, channelCount int) (*Writer, error)

NewBuffer -

func NewWriter

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

NewWriter -

func (*Writer) Close

func (w *Writer) Close() error

Close -

func (*Writer) HeaderBytes

func (w *Writer) HeaderBytes() ([]byte, error)

HeaderBytes -

func (*Writer) Write

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

Write -

func (*Writer) WriteSample8

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

WriteSample8 -

func (*Writer) WriteSample16

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

WriteSample16 -

func (*Writer) WriteSample24

func (w *Writer) WriteSample24(samples []byte) (int, error)

WriteSample24 -

type WriterParam

type WriterParam struct {
	Out           *os.File
	Channel       int
	SampleRate    int
	BitsPerSample int
}

WriterParam -

Jump to

Keyboard shortcuts

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