Documentation ¶
Overview ¶
Package dsp provides processors that can be chained together to build digital signal processing systems.
Digital signals are represented as sequence of numbers where each number is associated with a disctrete time. Discrete time is represented as a squence of integers that can correspond to physycal time sampled at fixed time intervals.
Sequences are divided into equally-spaced frames such that each frame corresponds to a fixed number of samples.
Processors can return values for a frame index or a global value for the entire sequence. To compute frame-level values, the processor must implement the Framer interface which defines the "Get(int) (Value, error)" method. To return a global value the processor must implement the OneValuer interface which defines the "Get() (Value, error.)" method.
The application is a graph of processors where the input of a processor is read from the output of another processor. Processors exchange values of interface type Value. To perform operations, the Processors must agree on the underlying types of Value.
Values are lazily computed when they are requested by a consumer. That is, when a value is requested for one of the processor's outputs, the computation chain propagates all the way to the source.
To achieve high performance, computed frames are cached by the processors. If the cache capacity is big enough, values are only computed once. (For example, to do a moving average, the same input frames may be requested multiple times.)
For a comrehensive example see examples/speech2/main.go.
Convention: Input values should be treated as read-only because they may be shared with other processors.
CONTACT: Leo Neumeyer leo@akualab.com
Index ¶
- Variables
- func IsFramer(p Processer) bool
- func IsInputter(p Processer) bool
- func IsOneValuer(p Processer) bool
- type App
- func (app *App) Add(name string, p Processer) Node
- func (app *App) Chain(nodes ...Node) Node
- func (app *App) Connect(to Node, from ...Node) Node
- func (app *App) NodeByName(name string) Node
- func (app *App) NodesByName(names ...string) ([]Node, error)
- func (app *App) Reset()
- func (app *App) String() string
- type Framer
- type Inputter
- type Node
- type OneProc
- type OneProcFunc
- type OneValuer
- type Proc
- func (bp *Proc) ClearCache()
- func (bp *Proc) Framer(n int) Framer
- func (bp *Proc) Get(idx int) (Value, error)
- func (bp *Proc) GetCache(idx int) (Value, bool)
- func (bp *Proc) Inputs() []Processer
- func (bp *Proc) OneValuer(n int) OneValuer
- func (bp *Proc) Reset()
- func (bp *Proc) SetCache(idx int, val Value)
- func (bp *Proc) SetInputs(inputs ...Processer)
- type ProcFunc
- type Processer
- type Processers
- type Resetter
- type Value
Constants ¶
This section is empty.
Variables ¶
var ErrNoFunc = errors.New("no ProcFunc set")
Called a Proc that has no ProcFunc set.
var ErrOOB = errors.New("frame index out of bounds")
Returned when frame index is out of bounds. Can be used as a termination flag.
Functions ¶
func IsInputter ¶
IsInputter returns true if the processor implements the Inputter interface.
func IsOneValuer ¶
IsOneValuer returns true if the processor implements the OneValuer interface.
Types ¶
type App ¶
type App struct { // App name. Name string // contains filtered or unexported fields }
App defines a DSP application.
func (*App) Chain ¶
Chain connects a sequence of processors as follows:
var p0, p1, p2, p3 dsp.Node ... out := app.Pipe(p0, p1, p2, p3)
p0 <= p1 <= p2 <= p3 (the last processor in the chain is p0 which is return by the method.
func (*App) Connect ¶
Connect connects processor inputs. Example:
var y,x1,x2 dsp.Node ... out := app.Connect(y, x1, x2)
the output values of processors x1 and x2 are inputs to processor y. Returns node corresponding to processor y.
func (*App) NodeByName ¶
NodeByName returns a node from the processor graph.
func (*App) NodesByName ¶
NodesByName converts a list of names into a list of nodes.
type Inputter ¶
type Inputter interface {
SetInputs(...Processer)
}
The Inputter interface is used to set processor inputs.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node is a node in the processor graph.
type OneProc ¶
type OneProc struct {
// contains filtered or unexported fields
}
OneProc can be embedded in structs that need to implement the OneValuer interface.
type OneProcFunc ¶
OneProcFunc is the type used to implement processing functions that return a single value per stream.
type Proc ¶
type Proc struct {
// contains filtered or unexported fields
}
Proc can be embedded in objects that implement the Processer interface.
func (*Proc) Reset ¶
func (bp *Proc) Reset()
Reset - override this method to reset the processor state.
type Processer ¶
type Processer interface { }
The Processer interface is the common interface for all processors types.
type Processers ¶
type Processers []Processer
Processers is a slice of Processer values.
func (Processers) CheckInputs ¶
func (ps Processers) CheckInputs(n int) ([]Framer, error)
CheckInputs is a convenience method that checks that the first n inputs exist and implement the Framer interface.
func (Processers) Framer ¶
func (ps Processers) Framer(n int) (Framer, error)
Framer is a convenience method that checks that input #n exist and implements the Framer interface.
type Resetter ¶
type Resetter interface {
Reset()
}
The Resetter interface is used to reset the state of a stateful processor.