dsp

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: 4 Imported by: 4

Documentation

Overview

Package dsp provides common digital signal processing operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chebyshev

func Chebyshev(n int, x float64) float64

Chebyshev generates the Chebyshev polynomial coefficient for order n

func Clamp

func Clamp(s, min, max float64) float64

Clamp limits a value to a specific range

func Cos

func Cos(x float64) float64

Cos is a lookup table version of math.Cos

func Cubic

func Cubic(y0, y1, y2, y3, m float64) float64

Cubic performs cubic interpolation

func ExpRatio

func ExpRatio(ratio, speed float64) float64

ExpRatio produces an (inverse-)exponential curve that's inflection can be controlled by a specific ratio

func Fold

func Fold(s, min, max float64) float64

Fold reflects a value exceeding minimum/maximum thresholds back over those thresholds

func Hermite

func Hermite(x0, x1, x2, x3, t float64) float64

Hermite performs Hermite interpolation

func IsPowerOfTwo

func IsPowerOfTwo(x int) bool

IsPowerOfTwo determines whether or not an integer is a power of two

func Lerp

func Lerp(x1, x2, m float64) float64

Lerp performs linear interpolation

func Mix

func Mix(mix, a, b float64) float64

Mix sums two panned inputs

func Overload

func Overload(x float64) float64

Overload is a sigmoid function that simulates soft clip overloading

func PanMix

func PanMix(pan, a, b float64) (float64, float64)

PanMix pans two inputs between two outputs

func RandRange

func RandRange(min, max float64) float64

RandRange returns random values between a specified range

func Sin

func Sin(x float64) float64

Sin is a lookup table version of math.Sin

func SoftClamp

func SoftClamp(s, threshold float64) float64

SoftClamp limits a value to a specific range, but compresses the value as it goes beyond the threshold

func Tan

func Tan(x float64) float64

Tan is a lookup table version of math.Tan

Types

type AllPass

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

AllPass is an allpass filter

func NewAllPass

func NewAllPass(size int) *AllPass

NewAllPass returns a new AllPass

func NewAllPassMS

func NewAllPassMS(ms MS) *AllPass

NewAllPassMS returns a new AllPass

func (*AllPass) Tick

func (a *AllPass) Tick(in, gain float64) float64

Tick advances the allpass filter state using the full length of the delay line

func (*AllPass) TickAbsolute

func (a *AllPass) TickAbsolute(in, gain, delay float64) float64

TickAbsolute advances the allpass filter state with a specified absolute delay length (less than maximum)

func (*AllPass) TickRelative

func (a *AllPass) TickRelative(in, gain, scale float64) float64

TickRelative advances the allpass filter state with a delay length relative to the length of the delay line

type BeatsPerMin

type BeatsPerMin struct {
	Valuer
	Raw float64
}

BeatsPerMin represents beats-per-minute

func BPM

func BPM(v float64, sampleRate int) BeatsPerMin

BPM returns a scalar value in beats-per-minute

func (BeatsPerMin) Float64

func (bpm BeatsPerMin) Float64() float64

Float64 returns the constant value

func (BeatsPerMin) String

func (bpm BeatsPerMin) String() string

type DCBlock

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

DCBlock keeps a signal centered around zero

func (*DCBlock) Tick

func (dc *DCBlock) Tick(in float64) float64

Tick advances the state

type Decimate

type Decimate struct {
	SampleRate float64
	// contains filtered or unexported fields
}

Decimate reduces the resolution/bandwidth of a signal to produce bitcrushing effects

func (*Decimate) Tick

func (d *Decimate) Tick(in, rate, bits float64) float64

Tick advances the filter's state

type DelayLine

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

DelayLine is a simple delay line

func NewDelayLine

func NewDelayLine(size int) *DelayLine

NewDelayLine returns a new DelayLine of a specific maximum size in milliseconds

func NewDelayLineMS

func NewDelayLineMS(size MS) *DelayLine

NewDelayLineMS returns a new DelayLine of a specific maximum size in milliseconds

func (*DelayLine) ReadAbsolute

func (d *DelayLine) ReadAbsolute(pos float64) float64

ReadAbsolute reads a specific sample offset from the DelayLine

func (*DelayLine) ReadRelative

func (d *DelayLine) ReadRelative(scale float64) float64

ReadRelative reads sample from the DelayLine at a scale between 0 and 1

func (*DelayLine) Size

func (d *DelayLine) Size() int

Size returns the size of the DelayLine buffer

func (*DelayLine) Tick

func (d *DelayLine) Tick(v float64) float64

Tick advances the state of the DelayLine using the total delay length

func (*DelayLine) TickAbsolute

func (d *DelayLine) TickAbsolute(v, delay float64) float64

TickAbsolute advances the state of the DelayLine using a specific delay length (less than total) in samples

func (*DelayLine) TickRelative

func (d *DelayLine) TickRelative(v, scale float64) float64

TickRelative advances the state of the DelayLine using a scale between 0 and 1

func (*DelayLine) Write

func (d *DelayLine) Write(v float64)

Write writes a value to the DelayLine and steps ahead by one sample

type FBComb

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

FBComb is a feedback comb filter

func NewFBComb

func NewFBComb(size int) *FBComb

NewFBComb returns a new FBComb

func NewFBCombMS

func NewFBCombMS(ms MS) *FBComb

NewFBCombMS returns a new FBComb that's length is represented in milliseconds

func (*FBComb) Tick

func (c *FBComb) Tick(in, gain float64) float64

Tick advances the filter's state with the default delay

func (*FBComb) TickAbsolute

func (c *FBComb) TickAbsolute(in, gain, delay float64) float64

TickAbsolute advances the filter's state with a specific delay

type FFComb

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

FFComb is a feedforward comb filter

func NewFFComb

func NewFFComb(size int) *FFComb

NewFFComb returns a new FBComb

func NewFFCombMS

func NewFFCombMS(ms MS) *FFComb

NewFFCombMS returns a new FFComb that's length is represented in milliseconds

func (*FFComb) Tick

func (c *FFComb) Tick(in, gain float64) float64

Tick advances the filter's state with the default delay

func (*FFComb) TickAbsolute

func (c *FFComb) TickAbsolute(in, gain, delay float64) float64

TickAbsolute advances the filter's state with a specific delay

type Filter

type Filter struct {
	Type              FilterType
	Poles             int
	Cutoff, Resonance float64
	// contains filtered or unexported fields
}

Filter is a simple low-pass or high-pass filter.

func NewFilter

func NewFilter(typ FilterType, poles int) *Filter

NewFilter returns a new Filter.

func (*Filter) Tick

func (f *Filter) Tick(in float64) float64

Tick advances the operation

type FilterType

type FilterType int

FilterType describes what frequencies will be allowed/eliminated in an outgoing signal.

const (
	LowPass FilterType = iota
	HighPass
)

FilterTypes for Filter

type Float64

type Float64 float64

Float64 is a wrapper for float64 that implements Valuer

func (Float64) Float64

func (v Float64) Float64() float64

Float64 returns the constant value

func (Float64) String

func (v Float64) String() string

type Hz

type Hz struct {
	Valuer
	Raw float64
}

Hz represents cycles-per-second

func Frequency

func Frequency(v float64, sampleRate int) Hz

Frequency returns a scalar value in Hz

func (Hz) Float64

func (hz Hz) Float64() float64

Float64 returns the constant value

func (Hz) String

func (hz Hz) String() string

type MS

type MS struct {
	Valuer
	Raw float64
}

MS is a value representation of milliseconds

func Duration

func Duration(v float64, sampleRate int) MS

Duration returns a scalar value (float64) in MS

func DurationInt

func DurationInt(v, sampleRate int) MS

DurationInt returns a scalar value (int) in MS

func (MS) Float64

func (ms MS) Float64() float64

Float64 returns the constant value

func (MS) String

func (ms MS) String() string

type Pitch

type Pitch struct {
	Valuer
	Pitch musictheory.Pitch
	Raw   string
}

Pitch is a pitch that has been expressed in scientific notation

func NewPitch

func NewPitch(p musictheory.Pitch, sampleRate int) Pitch

NewPitch creates a Pitch

func ParsePitch

func ParsePitch(v string, sampleRate int) (Pitch, error)

ParsePitch parses the scientific notation of a pitch

func (Pitch) Float64

func (p Pitch) Float64() float64

Float64 returns the constant value

func (Pitch) String

func (p Pitch) String() string

func (Pitch) Transpose

func (p Pitch) Transpose(interval musictheory.Interval, sampleRate int) Pitch

Transpose transposes the pitch by some interval

type PitchShift

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

PitchShift shifts a pitch

func NewPitchShift

func NewPitchShift() *PitchShift

NewPitchShift returns a new PitchShift

func (*PitchShift) TickSemitones

func (s *PitchShift) TickSemitones(in, semitones float64) float64

TickSemitones shifts a pitch by a specific number of semitones in equal temperament.

type RollingAverage

type RollingAverage struct {
	Window int
	// contains filtered or unexported fields
}

RollingAverage calculates a rolling average over a specified window size

func (*RollingAverage) Tick

func (a *RollingAverage) Tick(in float64) float64

Tick advances the filter's state

type SVFilter

type SVFilter struct {
	Poles             int
	Cutoff, Resonance float64
	// contains filtered or unexported fields
}

SVFilter is a state-variable filter that yields simultaneous lowpass, bandpass and highpass outputs

func (*SVFilter) Tick

func (f *SVFilter) Tick(in float64) (lp, bp, hp float64)

Tick advances the operation

type Valuer

type Valuer interface {
	Float64() float64
}

Valuer is the wrapper interface around the Value method; which is used in obtaining the constant value

Jump to

Keyboard shortcuts

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