generator

package module
v0.0.0-...-fe54388 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2019 License: Apache-2.0 Imports: 3 Imported by: 6

README

generator

A PCM generator using the go-audio interface

GoDoc Build Status

Checkout the examples to get an idea of how to use the generator.

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.FloatBuffer) error

Fill fills up the pass audio Buffer 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
Euclidean package implements the Euclidean Algorithm to generate traditional musical rhythms.
Euclidean package implements the Euclidean Algorithm to generate traditional musical rhythms.
examples
offline
generator example
generator example
offline/stereo
sterep generator example
sterep generator example
realtime
demo package simulating a realtime generation and processing.
demo package simulating a realtime generation and processing.

Jump to

Keyboard shortcuts

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