engine

package
v0.0.0-...-a19c61f Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2023 License: MIT Imports: 7 Imported by: 2

Documentation

Overview

Package engine provides a low-level audio interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clear

func Clear(e *Engine) error

Clear is an action that resets the Engine's state.

func EmitOutputs

func EmitOutputs(left, right unit.OutRef) func(*Graph) error

EmitOutputs sinks 1 or 2 outputs to the Engine.

func MountUnit

func MountUnit(u *unit.Unit) func(*Graph) error

MountUnit mounts a Unit into the audio graph.

func PatchInput

func PatchInput(u *unit.Unit, inputs map[string]interface{}, forceReset bool) func(*Graph) error

PatchInput patches values into a Unit's Ins. If `forceReset` is set to `true` all Ins on that Unit that haven't been referenced in `inputs` will be reset to their default values.

func SwapUnit

func SwapUnit(u1, u2 *unit.Unit) func(*Graph) error

SwapUnit swaps one unit out in the graph for another. If the two units or of different types, the original is just removed and nothing is done. Otherwise, it tries its best to patch sources and destinatinos from the original unit to the new unit.

func UnmountUnit

func UnmountUnit(u *unit.Unit) func(*Graph) error

UnmountUnit removes a Unit from the audio graph.

Types

type Backend

type Backend interface {
	Start(func([]float32, [][]float32)) error
	Stop() error
	SampleRate() int
	FrameSize() int
}

Backend is a low-level callback-based engine

type Engine

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

Engine is the connection of the synthesizer to PortAudio

func New

func New(backend Backend, frameSize int, opts ...Option) (*Engine, error)

New returns a new Sink

func (*Engine) Errors

func (e *Engine) Errors() <-chan error

Errors returns a channel that expresses any errors during operation of the Engine

func (*Engine) FrameSize

func (e *Engine) FrameSize() int

FrameSize returns the frame size

func (*Engine) Reset

func (e *Engine) Reset() error

Reset clears the state of the Engine. This includes clearing the audio graph.

func (*Engine) Run

func (e *Engine) Run()

Run starts the Engine; running the audio stream

func (*Engine) SampleRate

func (e *Engine) SampleRate() int

SampleRate returns the sample rate

func (*Engine) SendMessage

func (e *Engine) SendMessage(msg *Message) error

SendMessage sends a message to to the engine for it to handle within its goroutine

func (*Engine) Stop

func (e *Engine) Stop() error

Stop shuts down the Engine

func (*Engine) UnitBuilders

func (e *Engine) UnitBuilders() map[string]unit.Builder

UnitBuilders returns all unit.Builders for Units provided by the Engine.

type Graph

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

Graph is a graph of units.

func NewGraph

func NewGraph(frameSize int) *Graph

NewGraph returns a new Graph.

func (*Graph) Close

func (g *Graph) Close() error

Close closes all processors in the graph.

func (*Graph) Mount

func (g *Graph) Mount(u *unit.Unit) error

Mount adds a unit to the graph.

func (*Graph) Patch

func (g *Graph) Patch(v interface{}, in *unit.In) error

Patch patches a value into an input.

func (*Graph) Processors

func (g *Graph) Processors() []unit.FrameProcessor

Processors returns the sorted slice of unit.FrameProcessors.

func (*Graph) Reset

func (g *Graph) Reset(fadeIn, frameSize, sampleRate int) error

Reset empties the graph.

func (*Graph) Size

func (g *Graph) Size() int

Size returns the number of units in the graph.

func (*Graph) Sort

func (g *Graph) Sort()

Sort sorts the graph; caching a slice of unit.FrameProcessors.

func (*Graph) Unmount

func (g *Graph) Unmount(u *unit.Unit) error

Unmount removes a unit from the graph.

func (*Graph) Unpatch

func (g *Graph) Unpatch(in *unit.In) error

Unpatch disconnects any sources from an input.

type Message

type Message struct {
	Action interface{}
	Reply  chan *Reply
}

Message is a payload that contains an operation that the Engine can process and channel that must be received on by the goroutine sending the Message.

func NewMessage

func NewMessage(action interface{}) *Message

NewMessage creates a new Message to be sent to the Engine for evaluation.

type MessageChannel

type MessageChannel interface {
	Receive() *Message
	Send(*Message) error
	Close()
}

MessageChannel is abstraction of a channel that handles engine messages. This provides us a means of implementing slightly more strict synchronization behavior during testing.

type Option

type Option func(*Engine)

Option is an option for the Engine

func WithFadeIn

func WithFadeIn(ms int) Option

WithFadeIn fades the engine output in to prevent pops

func WithGain

func WithGain(gain float32) Option

WithGain sets the global gain for all samples written to the output

func WithMessageChannel

func WithMessageChannel(ch MessageChannel) Option

WithMessageChannel establishes a MessageChannel to be used for sending and receiving messages within the Engine.

func WithSingleSampleDisabled

func WithSingleSampleDisabled() Option

WithSingleSampleDisabled disables the single-sample feedback loop behavior.

type Reply

type Reply struct {
	Duration time.Duration
	Error    error
}

Reply is a payload that the Engine sends in response to a Message. It contains any resulting data from its processing of the action, any error that might of occurred and how long the action took to process.

Directories

Path Synopsis
Package portaudio provides a portaudio backend for the engine.
Package portaudio provides a portaudio backend for the engine.

Jump to

Keyboard shortcuts

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