generator

package
v0.0.0-...-8ab7c96 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2016 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SineB = 4.0 / math.Pi
	SineC = -4.0 / (math.Pi * math.Pi)
	Q     = 0.775
	SineP = 0.225
)
View Source
const SawtoothA = 1.0 / math.Pi
View Source
const TringleA = 2.0 / math.Pi
View Source
const (
	TwoPi = float64(2 * math.Pi)
)

Variables

This section is empty.

Functions

func Sawtooth

func Sawtooth(x float64) float64

Triangle takes an input value from -Pi to Pi and returns a value between -1 and 1

func Sine

func Sine(x32 float64) float64

Sine takes an input value from -Pi to Pi and returns a value between -1 and 1

func Square

func Square(x float64) float64

Square takes an input value from -Pi to Pi and returns -1 or 1

func Triangle

func Triangle(x float64) float64

Triangle takes an input value from -Pi to Pi and returns a value between -1 and 1

Types

type Osc

type Osc struct {
	Shape     WaveType
	Amplitude float64
	DcOffset  float64
	Freq      float64
	// SampleRate
	Fs                int
	PhaseOffset       float64
	CurrentPhaseAngle float64
	// contains filtered or unexported fields
}

Osc is an oscillator

func NewOsc

func NewOsc(shape WaveType, hz float64, fs int) *Osc

NewOsc returns a new oscillator, note that if you change the phase offset of the returned osc, you also need to set the CurrentPhaseAngle

func (*Osc) Fill

func (o *Osc) Fill(buf *audio.PCMBuffer) error

Fill fills up the pass PCMBuffer with the output of the oscillator.

func (*Osc) Reset

func (o *Osc) Reset()

Reset sets the oscillator back to its starting state

func (*Osc) Sample

func (o *Osc) Sample() (output float64)

Sample returns the next sample generated by the oscillator

func (*Osc) SetAttackInMs

func (o *Osc) SetAttackInMs(ms int)

SetAttackInMs sets the duration for the oscillator to be at full amplitude after it starts.

func (*Osc) SetFreq

func (o *Osc) SetFreq(hz float64)

SetFreq updates the oscillator frequency

func (*Osc) Signal

func (o *Osc) Signal(length int) []float64

Signal uses the osc to generate a discreet signal

type WaveType

type WaveType uint16

WaveType is an alias type for the type of waveforms that can be generated

const (
	WaveSine     WaveType = iota // 0
	WaveTriangle                 // 1
	WaveSaw                      // 2
	WaveSqr                      //3
)

Directories

Path Synopsis
generator example
generator example

Jump to

Keyboard shortcuts

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