audio

package
v0.0.0-...-0b38cba Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Gain

func Gain(chunk *Chunk, multiplier float32)

Gain applies the multiplier to the passed chunk.

func GenerateChunks

func GenerateChunks(totalDur time.Duration, chunkSamples int) chan Chunk

GenerateChunks generates sine wave chunks.

func GetWavChunks

func GetWavChunks(wavURL string, chunkSamples int) chan Chunk

GetWavChunks fetches a wav file and returns a channel to PCM chunks.

Types

type Chunk

type Chunk struct {
	Index       uint64
	StreamStart uint64
	Samples     []float32
}

Chunk is a chunk of audio.

type EmptySink

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

EmptySink outputs all chunks it receives.

func NewEmptySink

func NewEmptySink() *EmptySink

NewEmptySink constructor.

func (*EmptySink) Append

func (sink *EmptySink) Append(chunk *Chunk)

Append to sink.

func (*EmptySink) Drain

func (sink *EmptySink) Drain() <-chan *Chunk

Drain the sink.

func (*EmptySink) OutputTo

func (sink *EmptySink) OutputTo(nextSink Sink)

OutputTo forwards all output to next sink.

type OrderedSink

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

OrderedSink allows appending audio chunks in any order and outputs them ordered.

func NewOrderedSink

func NewOrderedSink(streamStart uint64) *OrderedSink

NewOrderedSink constructor.

func (*OrderedSink) Append

func (sink *OrderedSink) Append(chunk *Chunk)

Append a chunk.

func (*OrderedSink) Drain

func (sink *OrderedSink) Drain() <-chan *Chunk

Drain the audio.

func (*OrderedSink) OutputTo

func (sink *OrderedSink) OutputTo(nextSink Sink)

OutputTo forwards all output to next sink.

type PriorityLocker

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

PriorityLocker hands out lock/unlock wrappers to a single mutex that when locked, first waits until the lock has been locked and unlocked by all callers with lower priority before attempting to lock it.

func NewPriorityLocker

func NewPriorityLocker(lowestPriority uint64) *PriorityLocker

NewPriorityLocker constructor.

func (*PriorityLocker) NewLock

func (l *PriorityLocker) NewLock(priority uint64) sync.Locker

NewLock creates a priority-assigned lock. The returned locker must only be locked and unlocked once.

type Sink

type Sink interface {
	Append(*Chunk)
	OutputTo(Sink)
	Drain() <-chan *Chunk
}

Sink is an audio sink that processes audio chunks using an array of transformers.

type TimeBuffer

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

TimeBuffer blocks a speedy caller to be ahead of realtime by max amount.

func NewTimeBuffer

func NewTimeBuffer(max time.Duration) *TimeBuffer

NewTimeBuffer constructor.

func (*TimeBuffer) Add

func (tb *TimeBuffer) Add(elapsed time.Duration)

Add an amount of time to buffer the caller thinks has passed. It will block if necessary to slow down the caller to be ahead of real time by max.

type TransformSink

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

TransformSink allows using audio transformers on passed in chunks.

func NewTransformSink

func NewTransformSink(fx ...Transformer) *TransformSink

NewTransformSink constructor.

func (*TransformSink) Append

func (sink *TransformSink) Append(chunk *Chunk)

Append to sink.

func (*TransformSink) Drain

func (sink *TransformSink) Drain() <-chan *Chunk

Drain the sink.

func (*TransformSink) OutputTo

func (sink *TransformSink) OutputTo(nextSink Sink)

OutputTo forwards all output to next sink.

type Transformer

type Transformer func(*Chunk)

Transformer is a function that modifies the chunk in place.

Jump to

Keyboard shortcuts

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