unit

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: 12 Imported by: 3

Documentation

Overview

Package unit provides built-in units for synthesis.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Builders

func Builders() map[string]Builder

Builders returns all Builders for all Units provided by this package.

func Patch

func Patch(g *graph.Graph, out Output, in *In) error

Patch connects a one Unit's Out to another's In. It also creates an edge on a graph to track the connection.

func PrepareBuilders

func PrepareBuilders(builders map[string]IOBuilder) map[string]Builder

PrepareBuilders converts a set of IOBuilders to a set of Builders.

func Unpatch

func Unpatch(g *graph.Graph, in *In) error

Unpatch disconnects all inbound neighbors (Outs) from an In. All graph edges are removed as well to track the disconnection. Once all, if any, Outs are disconnected the In is reset to its default value constant.

Types

type Builder

type Builder func(Config) (*Unit, error)

Builder constructs a Unit of some type.

type CondProcessor

type CondProcessor interface {
	IsProcessable() bool
}

CondProcessor informs another party whether or not it should be processed.

type Config

type Config struct {
	Values                map[string]interface{}
	SampleRate, FrameSize int
}

Config is a map that's used to provide configuration options to Builders.

func (Config) Decode

func (c Config) Decode(v interface{}) error

Decode loads a struct with the contents of the raw Config object.

type FrameProcessor

type FrameProcessor interface {
	ProcessFrame(n int)
}

FrameProcessor processes a block of samples of a given size.

type IO

type IO struct {
	ID, Type string
	Prop     map[string]*Prop
	In       map[string]*In
	Out      map[string]Output
	// contains filtered or unexported fields
}

IO is the registry of inputs, outputs and properties for a Module

func NewIO

func NewIO(typ string, frameSize int) *IO

NewIO returns a new IO

func (*IO) ExposeOutputProcessor

func (io *IO) ExposeOutputProcessor(o OutputProcessor)

ExposeOutputProcessor registers a new output that is also a Processor

func (*IO) NewIn

func (io *IO) NewIn(name string, v dsp.Valuer) *In

NewIn registers a new input

func (*IO) NewOut

func (io *IO) NewOut(name string) *Out

NewOut registers a new output

func (*IO) NewOutWithFrame

func (io *IO) NewOutWithFrame(name string, f []float64) *Out

NewOutWithFrame registers a new output that has a specific frame

func (*IO) NewProp

func (io *IO) NewProp(name string, v interface{}, setter func(*Prop, interface{}) error) *Prop

NewProp registers a new property

type IOBuilder

type IOBuilder func(*IO, Config) (*Unit, error)

IOBuilder provides an IO, containing identifying information, for a Unit to be constructed around.

type In

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

In is a unit input

func NewIn

func NewIn(name string, v dsp.Valuer, frameSize int) *In

NewIn returns a new input

func (*In) Constant

func (in *In) Constant() dsp.Valuer

Constant is the constant value that's filling the buffer.

func (*In) Couple

func (in *In) Couple(out Output)

Couple assigns the internal frame of this input to the frame of an output; binding them together. This in-of-itself does not define the connection. That is controlled by the the Nodes and Graph.

func (*In) ExternalNeighborCount

func (in *In) ExternalNeighborCount() int

ExternalNeighborCount returns the count of neighboring nodes outside of the parent Unit

func (*In) Fill

func (in *In) Fill(v dsp.Valuer)

Fill fills the internal frame with a specific constant value

func (*In) HasSource

func (in *In) HasSource() bool

HasSource returns whether or not we have an inbound connection

func (*In) Read

func (in *In) Read(i int) float64

Read reads a specific sample from the input frame

func (*In) ReadSlow

func (in *In) ReadSlow(i int, f func(float64) float64) float64

ReadSlow reads a specific sample from the input frame at a slow rate

func (*In) ReadSlowInt

func (in *In) ReadSlowInt(i int, f func(float64) int) int

ReadSlowInt reads a specific sample from the input frame at a slow rate

func (*In) Reset

func (in *In) Reset()

Reset disconnects an input from an output (if a connection has been established) and fills the frame with the normal constant value

func (*In) SetMode

func (in *In) SetMode(mode InMode)

SetMode sets the processing mode for this input.

func (*In) Source

func (in *In) Source() *Out

Source returns the inbound connection if it has one

func (*In) String

func (in *In) String() string

func (*In) Write

func (in *In) Write(i int, v float64)

Write writes a sample to the internal buffer

type InMode

type InMode int

InMode is a mode of processing of an In.

const (
	Block InMode = iota
	Sample
)

InModes

type InvalidPropValueError

type InvalidPropValueError struct {
	Prop  *Prop
	Value interface{}
}

InvalidPropValueError is an error that indicates a Prop cannot handle a value that's been given to it

func (InvalidPropValueError) Error

func (e InvalidPropValueError) Error() string

type Out

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

Out is a unit output

func NewOut

func NewOut(name string, f []float64) *Out

NewOut returns a new output

func (*Out) DestinationCount

func (out *Out) DestinationCount() int

DestinationCount returns the number of outbound connections to this output

func (*Out) Destinations

func (out *Out) Destinations() []*In

Destinations returns a list of all destination inputs of the output

func (*Out) ExternalNeighborCount

func (out *Out) ExternalNeighborCount() int

ExternalNeighborCount returns the count of neighboring nodes outside of the parent Unit

func (*Out) Out

func (out *Out) Out() *Out

Out implements Output interface

func (*Out) Rate

func (out *Out) Rate() Rate

Rate returns the rate of the parent Unit

func (*Out) Read

func (out *Out) Read(i int) float64

Read reads a sample from the internal buffer

func (*Out) String

func (out *Out) String() string

func (*Out) Write

func (out *Out) Write(i int, v float64)

Write writes a sample to the output frame if there are downstream consumers of the output

type OutRef

type OutRef struct {
	Unit   *Unit
	Output string
}

OutRef is an unresolved reference to a Unit's Out.

func (OutRef) String

func (r OutRef) String() string

type Output

type Output interface {
	Out() *Out
}

Output is an abstract Out provider. Allows us to wrap an Out in some other behavior if we choose to. Out itself implements this interface.

type OutputProcessor

type OutputProcessor interface {
	Output
	SampleProcessor
	FrameProcessor
}

OutputProcessor is an output that can be ticked by the engine.

type Prop

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

Prop is a module property

func (*Prop) SetValue

func (p *Prop) SetValue(v interface{}) error

SetValue sets the Prop's value using its internal PropSetterFunc (if it has one)

func (*Prop) Value

func (p *Prop) Value() interface{}

Value returns the Prop's value

type PropSetterFunc

type PropSetterFunc func(*Prop, interface{}) error

PropSetterFunc is a function that will be used when setting the value of a Prop. It provides Modules a point a control for the values that are given to its Props.

type Rate

type Rate int

Rate is a rate in which signals will be processed by units

const (
	RateAudio Rate = iota
	RateControl
)

Supported processing rates

type SampleProcessor

type SampleProcessor interface {
	ProcessSample(i int)
}

SampleProcessor processes a single sample of signal.

type Unit

type Unit struct {
	*IO
	SampleProcessor
	// contains filtered or unexported fields
}

Unit is a synthesizer unit

func NewUnit

func NewUnit(io *IO, p SampleProcessor) *Unit

NewUnit creates a new Unit that defaults to audio rate.

func (*Unit) Attach

func (u *Unit) Attach(g *graph.Graph) error

Attach connects this unit and its inputs/outputs to a Graph

func (*Unit) Close

func (u *Unit) Close() error

Close closes the Processor if it is an io.Closer. It also closes any Outs that it has.

func (*Unit) Detach

func (u *Unit) Detach(g *graph.Graph) error

Detach removes this unit and its inputs/outputs from a Graph

func (*Unit) ExternalNeighborCount

func (u *Unit) ExternalNeighborCount() int

ExternalNeighborCount returns the count of neighboring nodes outside of the Unit

func (*Unit) IsProcessable

func (u *Unit) IsProcessable() bool

IsProcessable determines whether or not this Unit's ProcessFrame method should be called by the engine

func (*Unit) ProcessFrame

func (u *Unit) ProcessFrame(n int)

ProcessFrame calculates a block of samples.

func (*Unit) String

func (u *Unit) String() string

Jump to

Keyboard shortcuts

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