wave

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package wave implements a basic audio data library.

Index

Constants

This section is empty.

Variables

View Source
var (
	Int16SampleFormat = SampleFormatFunc(func(s Sample) Sample {
		if _, ok := s.(Int16Sample); ok {
			return s
		}
		return Int16Sample(s.Int() >> 16)
	})
	Float32SampleFormat = SampleFormatFunc(func(s Sample) Sample {
		if _, ok := s.(Float32Sample); ok {
			return s
		}
		return Float32Sample(float32(s.Int()) / 0x100000000)
	})
)

SampleFormats for the standard formats.

Functions

func RegisterDecoder

func RegisterDecoder(builder DecoderBuilder) error

Types

type Audio

type Audio interface {
	SampleFormat() SampleFormat
	ChunkInfo() ChunkInfo
	At(i, ch int) Sample
}

Audio is a finite series of audio Sample values.

type Buffer

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

Buffer is a buffer that can store any audio format.

func NewBuffer

func NewBuffer() *Buffer

NewBuffer creates a new Buffer instance

func (*Buffer) Load

func (buff *Buffer) Load() Audio

Load loads the current owned Audio

func (*Buffer) StoreCopy

func (buff *Buffer) StoreCopy(src Audio)

StoreCopy makes a copy of src and store its copy. StoreCopy will reuse as much memory as it can from the previous copies. For example, if StoreCopy is given an audio that has the format from the previous call, StoreCopy will not allocate extra memory and only copy the content from src to the previous buffer.

type ChunkInfo

type ChunkInfo struct {
	Len          int
	Channels     int
	SamplingRate int
}

ChunkInfo contains size of the audio chunk.

type Decoder

type Decoder interface {
	// Decode decodes raw chunk in endian byte order
	Decode(endian binary.ByteOrder, chunk []byte, channels int) (Audio, error)
}

Decoder decodes raw chunk to Audio

func NewDecoder

func NewDecoder(format Format) (Decoder, error)

NewDecoder creates a decoder to decode raw audio data in the given format

type DecoderBuilder

type DecoderBuilder interface {
	// NewDecoder creates a new decoder for specified format
	NewDecoder() (Decoder, Format)
}

DecoderBuilder builds raw audio decoder

type DecoderBuilderFunc

type DecoderBuilderFunc func() (Decoder, Format)

DecoderBuilderFunc is a proxy type for DecoderBuilder

func (DecoderBuilderFunc) NewDecoder

func (builderFunc DecoderBuilderFunc) NewDecoder() (Decoder, Format)

type DecoderFunc

type DecoderFunc func(endian binary.ByteOrder, chunk []byte, channels int) (Audio, error)

DecoderFunc is a proxy type for Decoder

func (DecoderFunc) Decode

func (f DecoderFunc) Decode(endian binary.ByteOrder, chunk []byte, channels int) (Audio, error)

type EditableAudio

type EditableAudio interface {
	Audio
	Set(i, ch int, s Sample)
}

EditableAudio is an editable finite series of audio Sample values.

type Float32Interleaved

type Float32Interleaved struct {
	Data []float32
	Size ChunkInfo
}

Float32Interleaved multi-channel interlaced Audio.

func NewFloat32Interleaved

func NewFloat32Interleaved(size ChunkInfo) *Float32Interleaved

func (*Float32Interleaved) At

func (a *Float32Interleaved) At(i, ch int) Sample

func (*Float32Interleaved) ChunkInfo

func (a *Float32Interleaved) ChunkInfo() ChunkInfo

ChunkInfo returns audio chunk size.

func (*Float32Interleaved) SampleFormat

func (a *Float32Interleaved) SampleFormat() SampleFormat

func (*Float32Interleaved) Set

func (a *Float32Interleaved) Set(i, ch int, s Sample)

func (*Float32Interleaved) SetFloat32

func (a *Float32Interleaved) SetFloat32(i, ch int, s Float32Sample)

func (*Float32Interleaved) SubAudio

func (a *Float32Interleaved) SubAudio(offsetSamples, nSamples int) *Float32Interleaved

SubAudio returns part of the original audio sharing the buffer.

type Float32NonInterleaved

type Float32NonInterleaved struct {
	Data [][]float32
	Size ChunkInfo
}

Float32NonInterleaved multi-channel interlaced Audio.

func NewFloat32NonInterleaved

func NewFloat32NonInterleaved(size ChunkInfo) *Float32NonInterleaved

func (*Float32NonInterleaved) At

func (a *Float32NonInterleaved) At(i, ch int) Sample

func (*Float32NonInterleaved) ChunkInfo

func (a *Float32NonInterleaved) ChunkInfo() ChunkInfo

ChunkInfo returns audio chunk size.

func (*Float32NonInterleaved) SampleFormat

func (a *Float32NonInterleaved) SampleFormat() SampleFormat

func (*Float32NonInterleaved) Set

func (a *Float32NonInterleaved) Set(i, ch int, s Sample)

func (*Float32NonInterleaved) SetFloat32

func (a *Float32NonInterleaved) SetFloat32(i, ch int, s Float32Sample)

func (*Float32NonInterleaved) SubAudio

func (a *Float32NonInterleaved) SubAudio(offsetSamples, nSamples int) *Float32NonInterleaved

SubAudio returns part of the original audio sharing the buffer.

type Float32Sample

type Float32Sample float32

Float32Sample is a 32-bits float audio sample.

func (Float32Sample) Int

func (s Float32Sample) Int() int64

type Format

type Format fmt.Stringer

Format represents how audio is formatted in memory

type Int16Interleaved

type Int16Interleaved struct {
	Data []int16
	Size ChunkInfo
}

Int16Interleaved multi-channel interlaced Audio.

func NewInt16Interleaved

func NewInt16Interleaved(size ChunkInfo) *Int16Interleaved

func (*Int16Interleaved) At

func (a *Int16Interleaved) At(i, ch int) Sample

func (*Int16Interleaved) ChunkInfo

func (a *Int16Interleaved) ChunkInfo() ChunkInfo

ChunkInfo returns audio chunk size.

func (*Int16Interleaved) SampleFormat

func (a *Int16Interleaved) SampleFormat() SampleFormat

func (*Int16Interleaved) Set

func (a *Int16Interleaved) Set(i, ch int, s Sample)

func (*Int16Interleaved) SetInt16

func (a *Int16Interleaved) SetInt16(i, ch int, s Int16Sample)

func (*Int16Interleaved) SubAudio

func (a *Int16Interleaved) SubAudio(offsetSamples, nSamples int) *Int16Interleaved

SubAudio returns part of the original audio sharing the buffer.

type Int16NonInterleaved

type Int16NonInterleaved struct {
	Data [][]int16
	Size ChunkInfo
}

Int16NonInterleaved multi-channel interlaced Audio.

func NewInt16NonInterleaved

func NewInt16NonInterleaved(size ChunkInfo) *Int16NonInterleaved

func (*Int16NonInterleaved) At

func (a *Int16NonInterleaved) At(i, ch int) Sample

func (*Int16NonInterleaved) ChunkInfo

func (a *Int16NonInterleaved) ChunkInfo() ChunkInfo

ChunkInfo returns audio chunk size.

func (*Int16NonInterleaved) SampleFormat

func (a *Int16NonInterleaved) SampleFormat() SampleFormat

func (*Int16NonInterleaved) Set

func (a *Int16NonInterleaved) Set(i, ch int, s Sample)

func (*Int16NonInterleaved) SetInt16

func (a *Int16NonInterleaved) SetInt16(i, ch int, s Int16Sample)

func (*Int16NonInterleaved) SubAudio

func (a *Int16NonInterleaved) SubAudio(offsetSamples, nSamples int) *Int16NonInterleaved

SubAudio returns part of the original audio sharing the buffer.

type Int16Sample

type Int16Sample int16

Int16Sample is a 16-bits signed integer audio sample.

func (Int16Sample) Int

func (s Int16Sample) Int() int64

type Int64Sample

type Int64Sample int64

Int64Sample is a 64-bits signed integer audio sample.

func (Int64Sample) Int

func (s Int64Sample) Int() int64

type RawFormat

type RawFormat struct {
	SampleSize  int
	IsFloat     bool
	Interleaved bool
}

func (*RawFormat) String

func (f *RawFormat) String() string

type Sample

type Sample interface {
	// Int returns the audio level value for the sample.
	// A value ranges within [0, 0xffffffff], but is represented by a int64.
	Int() int64
}

Sample can convert itself to 64-bits signed value.

type SampleFormat

type SampleFormat interface {
	Convert(c Sample) Sample
}

SampleFormat can convert any Sample to one from its own sample format.

func SampleFormatFunc

func SampleFormatFunc(f func(Sample) Sample) SampleFormat

SampleFormatFunc returns a SampleFormat that invokes f to implement the conversion.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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