modular

package
v0.0.0-...-833c7dd Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Much of the magic here provided by https://github.com/brettbuddin/shaden/blob/master/unit/adsr.go

Index

Constants

View Source
const (
	StageOff stage = iota
	StageAttack
	StageDecay
	StageSustain
	StageRelease
)

These stages represent the different envelope stages.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock struct {
	Tempo *core.Knob // In beats per minute.
	// contains filtered or unexported fields
}

A Clock synchronizes all modules connected to it by emitting a steady stream of ticks (96 ticks per beat).

func NewClock

func NewClock() *Clock

NewClock returns a clock initialized with a tempo of 120bpm and a tick rate of 96 ticks / beat.

func (*Clock) Stream

func (c *Clock) Stream() float64

Stream reads the current value of the clock

type Envelope

type Envelope struct {

	// Knobs
	CurveRatio, Attack, Decay, Sustain, Release *core.Knob

	Trigger core.Signal
	// contains filtered or unexported fields
}

An Envelope represents an ADSR envelope.

func NewEnvelope

func NewEnvelope() *Envelope

NewEnvelope returns a new ADSR envelope generator.

func (*Envelope) Stream

func (e *Envelope) Stream() float64

Stream returns the current envelope phase.

type Filter

type Filter struct {
	Cutoff *core.Knob
	Input  core.Signal
	Type   FilterType
	// contains filtered or unexported fields
}

func NewFilter

func NewFilter(filterType FilterType) *Filter

func (*Filter) Stream

func (f *Filter) Stream() float64

type FilterType

type FilterType int
const (
	LowPassFilter FilterType = iota
	HighPassFilter
)

type Gate

type Gate struct {
	Opened bool
}

func NewGate

func NewGate() *Gate

NewGate returns an empty gate.

func (*Gate) Stream

func (g *Gate) Stream() float64

Stream streams a sample from the gate.

type LFO

type LFO struct {
	Osc Oscillator

	Shape WaveShape
	// contains filtered or unexported fields
}

An LFO is a Low-Frequency Oscillator. It differs from the actual oscillator in that it allows for setting a floor and a ceiling.

func NewLFO

func NewLFO(maxValue, minValue float64) *LFO

NewLFO returns an new LFO.

func (*LFO) Stream

func (l *LFO) Stream() float64

Stream returns the current LFO phase.

type MIDIInput

type MIDIInput struct {
	VolumeControl    *constantStreamer
	FrequencyControl *constantStreamer
}

A MIDIInput allows for live control of the synthesizer

func NewMIDIInput

func NewMIDIInput() *MIDIInput

NewMIDIInput returns a midi input

func (*MIDIInput) UpdateFrequency

func (m *MIDIInput) UpdateFrequency(frequency float64)

UpdateFrequency returns the current oscillator frequency

func (*MIDIInput) UpdateVolume

func (m *MIDIInput) UpdateVolume(volume float64)

UpdateVolume returns the current oscillator volume

type Modulator

type Modulator struct {
	Attenuator      *core.Knob // From 0 to 1.
	InitialAmount   *core.Knob
	ModulationRange *core.Knob
}

The Modulator applies a modulation range to a signal. Returns InitialAmount + (Attenuator * ModulationRange).

func NewModulator

func NewModulator(initialAmount float64) *Modulator

NewModulator returns a new modulation source.

func (*Modulator) Stream

func (m *Modulator) Stream() float64

type Oscillator

type Oscillator struct {
	Frequency *core.Knob // Note frequency (in Hz).

	Sine, Square, Saw, Triangle core.Signal // From -1 to 1
	// contains filtered or unexported fields
}

An Oscillator is a simple wave generator

func NewOscillator

func NewOscillator() *Oscillator

NewOscillator returns a new oscillator.

func (*Oscillator) GetOutput

func (o *Oscillator) GetOutput(shape WaveShape) core.Signal

GetOutput returns the signal corresponding to the provided wave shape.

type Sequencer

type Sequencer struct {
	Clock        core.Signal
	BeatsPerStep *core.Knob

	Gate    *Gate
	Trigger *Trigger

	Sequence     []float64
	GateSequence []float64
	// contains filtered or unexported fields
}

A Sequencer loops through a frequency sequence at a pace dictated by the clock and outputs the corresponding frequencies.

func NewSequencer

func NewSequencer() *Sequencer

NewSequencer returns a sequencer instance.

func (*Sequencer) Stream

func (s *Sequencer) Stream() float64

Stream returns the current sequence frequency.

type Trigger

type Trigger struct {
	ShouldTrigger bool
}

func NewTrigger

func NewTrigger() *Trigger

func (*Trigger) Stream

func (t *Trigger) Stream() float64

type VCA

type VCA struct {
	Input  core.Signal
	Gate   core.Signal
	Volume *core.Knob
}

func NewVCA

func NewVCA() *VCA

func (*VCA) Stream

func (v *VCA) Stream() float64

type WaveShape

type WaveShape int

WaveShape represents the possible shapes of an oscillator wave.

const (
	SINE WaveShape = iota
	SQUARE
	SAW
	TRIANGLE
)

Available shapes.

type WaveTable

type WaveTable struct {
	Data [][]float64

	Frequency *core.Knob
	Position  *core.Knob
	// contains filtered or unexported fields
}

func NewWaveTable

func NewWaveTable(data [][]float64) (*WaveTable, error)

func (*WaveTable) Stream

func (wt *WaveTable) Stream() float64

Stream returns the current value at the current wavetable position.

Jump to

Keyboard shortcuts

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