dsp

package module
v0.0.0-...-a7203c7 Latest Latest
Warning

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

Go to latest
Published: May 29, 2015 License: BSD-3-Clause Imports: 5 Imported by: 0

README

DSP wercker statusGoDoc

Package DSP provides processors that can be chained together to build digital signal processing systems written in the Go language.

Contributing

Contributions to the DSP platform itself and additional modules are welcomed!

About

This work leverages ideas, designs, and implementations from other projects. See special credits in the documentation.

DSP was created by Akualab Inc..

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

Constants

This section is empty.

Variables

View Source
var ErrNoFunc = errors.New("no ProcFunc set")

Called a Proc that has no ProcFunc set.

View Source
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 IsFramer

func IsFramer(p Processer) bool

IsFramer returns true if the processor implements the Framer interface.

func IsInputter

func IsInputter(p Processer) bool

IsInputter returns true if the processor implements the Inputter interface.

func IsOneValuer

func IsOneValuer(p Processer) bool

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 NewApp

func NewApp(name string) *App

NewApp returns a new app.

func (*App) Add

func (app *App) Add(name string, p Processer) Node

Add adds a processor with a name.

func (*App) Chain

func (app *App) Chain(nodes ...Node) Node

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

func (app *App) Connect(to Node, from ...Node) Node

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

func (app *App) NodeByName(name string) Node

NodeByName returns a node from the processor graph.

func (*App) NodesByName

func (app *App) NodesByName(names ...string) ([]Node, error)

NodesByName converts a list of names into a list of nodes.

func (*App) Reset

func (app *App) Reset()

Reset resets processors that implement the Resetter interface. Should be called in preparation for a new stream when processors have state.

func (*App) String

func (app *App) String() string

type Framer

type Framer interface {
	Get(int) (Value, error)
}

The Framer interface is used to get a frame values.

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.

func (Node) Get

func (n Node) Get(idx int) (Value, error)

Get returns value for frame. Underlying processor must implement the Framer interface.

func (Node) GetOne

func (n Node) GetOne() (Value, error)

GetOne returns value for frame.

func (Node) Name

func (n Node) Name() string

Name of the processor.

func (Node) Proc

func (n Node) Proc(idx int) Processer

Proc returns the processor associated to this node.

type OneProc

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

OneProc can be embedded in structs that need to implement the OneValuer interface.

func NewOneProc

func NewOneProc(f OneProcFunc) *OneProc

NewOneProc creates a new Proc.

func (*OneProc) Framer

func (bp *OneProc) Framer(n int) Framer

Framer returns processor input #n as a Framer type.

func (*OneProc) Get

func (bp *OneProc) Get() (Value, error)

Get - returns one value for stream.

func (*OneProc) Inputs

func (bp *OneProc) Inputs() []Processer

Inputs returns the input processors.

func (*OneProc) OneValuer

func (bp *OneProc) OneValuer(n int) OneValuer

OneValuer returns processor input #n as a OneValuer type.

func (*OneProc) Reset

func (bp *OneProc) Reset()

Reset - override this method to reset the processor state.

func (*OneProc) SetInputs

func (bp *OneProc) SetInputs(inputs ...Processer)

SetInputs sets the inputs for a processor.

type OneProcFunc

type OneProcFunc func(...Processer) (Value, error)

OneProcFunc is the type used to implement processing functions that return a single value per stream.

type OneValuer

type OneValuer interface {
	Get() (Value, error)
}

The OneValuer interface is used to get a single value from a stream.

type Proc

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

Proc can be embedded in objects that implement the Processer interface.

func NewProc

func NewProc(bufSize int, f ProcFunc) *Proc

NewProc creates a new Proc.

func (*Proc) ClearCache

func (bp *Proc) ClearCache()

ClearCache clears the cache.

func (*Proc) Framer

func (bp *Proc) Framer(n int) Framer

Framer returns processor input #n as a Framer type.

func (*Proc) Get

func (bp *Proc) Get(idx int) (Value, error)

Get - returns value for index.

func (*Proc) GetCache

func (bp *Proc) GetCache(idx int) (Value, bool)

GetCache gets value from cache.

func (*Proc) Inputs

func (bp *Proc) Inputs() []Processer

Inputs returns the input processors.

func (*Proc) OneValuer

func (bp *Proc) OneValuer(n int) OneValuer

OneValuer returns processor input #n as a OneValuer type.

func (*Proc) Reset

func (bp *Proc) Reset()

Reset - override this method to reset the processor state.

func (*Proc) SetCache

func (bp *Proc) SetCache(idx int, val Value)

SetCache sets the value in the cache.

func (*Proc) SetInputs

func (bp *Proc) SetInputs(inputs ...Processer)

SetInputs sets the inputs for a processor.

type ProcFunc

type ProcFunc func(int, ...Processer) (Value, error)

ProcFunc is the type used to implement processing functions.

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.

func (Processers) Get

func (ps Processers) Get(idx int) (Value, error)

Get is a convenience method to get the value of the input at index 0.

func (Processers) OneValuer

func (ps Processers) OneValuer(n int) (OneValuer, error)

OneValuer is a convenience method that checks that input #n exist and implements the OneValuer interface.

type Resetter

type Resetter interface {
	Reset()
}

The Resetter interface is used to reset the state of a stateful processor.

type Value

type Value interface {
}

The Value interface must be implemented by types that are exchanged by processors.

func Get

func Get(p Processer, idx int) (val Value, err error)

Get is a convenience function to get the value of a processor. The underlying type of p may be a Framer or a OneValuer. If the type is a OneValuer, the idx argument is ignored.

Directories

Path Synopsis
examples
speech
Package speech provides functionality to parametrize digital waveforms.
Package speech provides functionality to parametrize digital waveforms.
wav

Jump to

Keyboard shortcuts

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