Documentation
¶
Overview ¶
Package signal provides types and functions to aid in signal processing.
Index ¶
- Constants
- func ExpDecayFunc(t float64) float64
- func SawtoothFunc(t float64) float64
- func SineFunc(t float64) float64
- func SquareFunc(t float64) float64
- func TriangleFunc(t float64) float64
- type Continuous
- type Discrete
- func (sig Discrete) AdditiveInverse()
- func (sig Discrete) AdditiveSynthesis(fd Discrete, pth int)
- func (sig Discrete) At(t float64) float64
- func (sig Discrete) Index(i int) float64
- func (sig Discrete) Interp(t float64) float64
- func (sig Discrete) Multiply(xs Discrete)
- func (sig Discrete) MultiplyScalar(x float64)
- func (sig Discrete) Normalize()
- func (sig Discrete) NormalizeRange(s, e float64)
- func (sig Discrete) Reverse()
- func (sig Discrete) Sample(src Continuous, interval, phase float64) float64
- func (sig Discrete) UnitInverse()
- type Float
- type Sampler
Constants ¶
const DefaultSize = 4096
Variables ¶
This section is empty.
Functions ¶
func ExpDecayFunc ¶
func SawtoothFunc ¶
SawtoothFunc is the continuous signal of a sawtooth wave.
func SquareFunc ¶
SquareFunc is the continuous signal of a square wave.
func TriangleFunc ¶
TriangleFunc is the continuous signal of a triangle wave.
Types ¶
type Continuous ¶
Continuous represents a continuous-time signal.
Effectively, many things may be represented as continuous. A function returning math.Sin(2*math.Pi*t) samples a sine wave while Discrete.Interpolate returns an interpolated value from its table, with both satisfying this type.
func (Continuous) Sample ¶
func (fn Continuous) Sample(src Continuous, interval, phase float64) float64
Sample satisfies Sampler interface.
The side effect of fn sampling src can not be known, so this returns phase+interval.
type Discrete ¶
type Discrete []float64
Discrete represents a discrete-time signal.
If building a lookup table, let sampling interval equal the recipricol of len(Discrete).
const n = 1024 sig := make(Discrete, n) sig.Sample(SineFunc, 1/n, 0)
If samples are intended to be played back in sequence, provide normalized frequency against output sample rate; e.g. to sample four seconds of 440Hz sine wave at 44.1kHz
r := 44100.0 t := 4.0 out := make(Discrete, int(r*t)) // allocate four seconds of space out.Sample(SineFunc, 440/r, 0) // sample 440Hz sine wave
To play these samples over four second period, use an oscillator as clock.
osc := snd.NewOscil(out, 1/t, nil) // package dasa.cc/snd
TODO document sampling at different rates.
func SawtoothSynthesis ¶
SawtoothSynthesis adds all partial harmonics belonging to [2..n], creating a sinusoidal wave that is the inverse of a sawtooth.
func SquareSynthesis ¶
SquareSynthesis adds odd partial harmonics belonging to [3..n], creating a sinusoidal wave.
func (Discrete) AdditiveInverse ¶
func (sig Discrete) AdditiveInverse()
AdditiveInverse sets each sample to -x.
func (Discrete) AdditiveSynthesis ¶
AdditiveSynthesis adds the fundamental, fd, for the partial harmonic, pth, to sig.
func (Discrete) At ¶
At uses the fractional component of t to return the sample at the truncated index.
func (Discrete) Interp ¶
Interp uses the fractional component of t to return an interpolated sample.
TODO currently does linear interpolation...
func (Discrete) MultiplyScalar ¶
func (Discrete) Normalize ¶
func (sig Discrete) Normalize()
Normalize alters sig so values belong to [-1..1].
func (Discrete) NormalizeRange ¶
NormalizeRange alters sig so values belong to [s..e].
Calling this method for values that already occupy [s..e] will degrade values further due to round-off error.
func (Discrete) Reverse ¶
func (sig Discrete) Reverse()
Reverse sig in place so the first element becomes the last and the last element becomes the first.
func (Discrete) Sample ¶
func (sig Discrete) Sample(src Continuous, interval, phase float64) float64
Sample satisfies Sampler interface.
func (Discrete) UnitInverse ¶
func (sig Discrete) UnitInverse()
UnitInverse sets each sample to 1 - x.
type Sampler ¶
type Sampler interface { // Sample reads values from src at phase by interval and returns next phase to sample. // // The side effect resulting from sampling is implementation specific. Sample(src Continuous, interval, phase float64) float64 }