Documentation
¶
Index ¶
- Constants
- func FlatlineFunction(angle float64) float64
- func RevSawtoothFunction(angle float64) float64
- func SawtoothFunction(angle float64) float64
- func SineFunction(angle float64) float64
- func SquareFunction(angle float64) float64
- func TriangleFunction(angle float64) float64
- type FunctionGenerator
- type Generator
- type NoiseGenerator
- type NoiseType
- type WaveFunction
Constants ¶
const Tau = math.Pi * 2 // why would you only have half the pie?
Variables ¶
This section is empty.
Functions ¶
func FlatlineFunction ¶
FlatlineFunction gives a constant 0 value
func RevSawtoothFunction ¶
RevSawtoothFunction returns the value [0-1] for the given angle in radians, using a reverse sawtooth function. Use this in a FunctionGenerator.
func SawtoothFunction ¶
SawtoothFunction returns the value [0-1] for the given angle in radians, using a sawtooth function. Use this in a FunctionGenerator.
func SineFunction ¶
SineFunction returns the value [0-1] for the given angle in radians, using a sine function. Use this in a FunctionGenerator.
func SquareFunction ¶
SquareFunction returns the value [0-1] for the given angle in radians, using a square function. Use this in a FunctionGenerator.
func TriangleFunction ¶
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.