generator

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const Tau = math.Pi * 2 // why would you only have half the pie?

Variables

This section is empty.

Functions

func FlatlineFunction

func FlatlineFunction(angle float64) float64

FlatlineFunction gives a constant 0 value

func RevSawtoothFunction

func RevSawtoothFunction(angle float64) float64

RevSawtoothFunction returns the value [0-1] for the given angle in radians, using a reverse sawtooth function. Use this in a FunctionGenerator.

func SawtoothFunction

func SawtoothFunction(angle float64) float64

SawtoothFunction returns the value [0-1] for the given angle in radians, using a sawtooth function. Use this in a FunctionGenerator.

func SineFunction

func SineFunction(angle float64) float64

SineFunction returns the value [0-1] for the given angle in radians, using a sine function. Use this in a FunctionGenerator.

func SquareFunction

func SquareFunction(angle float64) float64

SquareFunction returns the value [0-1] for the given angle in radians, using a square function. Use this in a FunctionGenerator.

func TriangleFunction

func TriangleFunction(angle float64) float64

TriangleFunction returns the value [0-1] for the given angle in radians, using a triangle function. Use this in a FunctionGenerator.

Types

type FunctionGenerator

type FunctionGenerator struct {
	Frequency float64
	// contains filtered or unexported fields
}

func NewFunctionGenerator

func NewFunctionGenerator(sampleRate uint) *FunctionGenerator

NewFunctionGenerator creates a new function generator that implements the Generator interface. Noise and pulse width modulation is implemented separately. The actual function is set with SetFunction. It defaults to a flat line with a constant 0 value. The sample rate is in Hz and can't be changed later.

func (*FunctionGenerator) GetNextSample

func (fg *FunctionGenerator) GetNextSample() float64

GetNextSample advances the angle and returns the next sample from the function generator.

func (FunctionGenerator) GetSampleRate

func (fg FunctionGenerator) GetSampleRate() uint

GetSampleRate returns the sample rate with which the oscillator was created.

func (*FunctionGenerator) Reset

func (fg *FunctionGenerator) Reset()

Reset sets the generator back to it's starting state.

func (*FunctionGenerator) SetFunction

func (fg *FunctionGenerator) SetFunction(wf WaveFunction)

SetFunction sets the actual generator function to use.

func (*FunctionGenerator) ShiftPhase

func (fg *FunctionGenerator) ShiftPhase(angleDeg float64)

ShiftPhase sets the phase shift for the generator in degrees.

type Generator

type Generator interface {
	GetSampleRate() uint
	GetNextSample() float64
	Reset() // call this before a new playback
}

Generator is an interface for all function generators and the like mainly for the oscillator.

type NoiseGenerator

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

func NewNoiseGenerator

func NewNoiseGenerator(sampleRate uint) *NoiseGenerator

NewNoiseGenerator creates a noise generator object the implements the Generator interface. You can select the noise type with SetNoiseType. The sample rate is in Hz and can't be changed later.

func (NoiseGenerator) GetNextSample

func (ng NoiseGenerator) GetNextSample() float64

GetNextSample returns the next value for the set type of noise.

func (*NoiseGenerator) Reset

func (ng *NoiseGenerator) Reset()

Reset re-initializes the random generator with the set seed.

func (*NoiseGenerator) SetNoiseType

func (ng *NoiseGenerator) SetNoiseType(noiseType NoiseType) error

SetNoiseType selects the noise type to use. The different types are implemented by filtering white noise and are calculation heavy.

func (*NoiseGenerator) SetSeed

func (ng *NoiseGenerator) SetSeed(seed int64)

SetSeed sets the seed for the random generator for consistency.

type NoiseType

type NoiseType int
const (
	RedNoise NoiseType = iota
	PinkNoise
	WhiteNoise
	BlueNoise
	VioletNoise
)

type WaveFunction

type WaveFunction func(float64) float64

Jump to

Keyboard shortcuts

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