synthesizer

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2020 License: MIT Imports: 3 Imported by: 9

Documentation

Overview

wavetable implementation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FourierTable added in v0.10.0

func FourierTable(nharms int, amps []float64, length int, phase float64) []float64

FourierTable constructs a lookup table based on fourier addition with 'nharmns' harmonics If amps is provided, scales the harmonics by the provided amp

func Len

func Len(g *Gtable) int

Len returns the length of the data segment without the guard point

func SawTable added in v0.10.0

func SawTable(nharms, length int) []float64

SawTable creates a sawtooth wavetable using Fourier addition

func SquareTable added in v0.10.0

func SquareTable(nharms, length int) []float64

SquareTable uses fourier addition to create a square waveform

func TriangleTable added in v0.10.0

func TriangleTable(nharms, length int) []float64

TriangleTable uses fourier addition to create a triangle waveform

Types

type Gtable

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

Gtable is a Guard-table for oscillator lookup

func NewGtable added in v0.10.0

func NewGtable(data []float64) *Gtable

func NewSineTable

func NewSineTable(length int) *Gtable

NewSineTable returns a lookup table populated for sine-wave generation.

func NewTriangleTable

func NewTriangleTable(length int, nharmonics int) (*Gtable, error)

NewTriangleTable generates a lookup table for a triangle wave of the specified length and with the requested number of harmonics.

type LookupOscillator

type LookupOscillator struct {
	Oscillator
	Table      *Gtable
	SizeOverSr float64 // convenience variable for calculations
}

LookupOscillator is an oscillator that's more gentle on your CPU By performing a table lookup to generate the required waveform..

func NewLookupOscillator

func NewLookupOscillator(sr int, t *Gtable, phase float64) (*LookupOscillator, error)

NewLookupOscillator creates a new oscillator which performs a table-lookup to generate the required waveform

func (*LookupOscillator) BatchInterpolateTick added in v0.10.0

func (l *LookupOscillator) BatchInterpolateTick(freq float64, nframes int) []float64

BatchInterpolateTick performs a lookup for N frames, and interpolates the value if the requested index does not appear in the table.

func (*LookupOscillator) BatchTruncateTick added in v0.10.0

func (l *LookupOscillator) BatchTruncateTick(freq float64, nframes int) []float64

BatchTruncateTick returns a slice of samples from the oscillator of the requested length

func (*LookupOscillator) InterpolateTick

func (l *LookupOscillator) InterpolateTick(freq float64) float64

InterpolateTick performs a lookup but interpolates the value if the requested index does not appear in the table.

func (*LookupOscillator) TruncateTick

func (l *LookupOscillator) TruncateTick(freq float64) float64

TruncateTick performs a lookup and truncates the value index down (if the index for lookup = 10.5, return index 10)

type Oscillator

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

Oscillator represents a wave-oscillator where each tick is calculated in the moment.

func NewOscillator

func NewOscillator(sr int, shape Shape) (*Oscillator, error)

NewOscillator set to a given sample rate

func NewPhaseOscillator

func NewPhaseOscillator(sr int, phase float64, shape Shape) (*Oscillator, error)

NewPhaseOscillator creates a new oscillator where the initial phase is offset by a given phase

func (*Oscillator) Tick

func (o *Oscillator) Tick(freq float64) float64

Tick generates the next value of the oscillator waveform at a given frequency in Hz

type Shape

type Shape int

Shape for defining the different possible waveform shapes for use with the Oscillator

const (
	SINE Shape = iota
	SQUARE
	DOWNWARD_SAWTOOTH
	UPWARD_SAWTOOTH
	TRIANGLE
)

Shapes for which we can generate waveforms

Jump to

Keyboard shortcuts

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