Documentation ¶
Overview ¶
Generate audio samples
Index ¶
- Constants
- Variables
- func GetEmptySampleArray(cfg *audio.AudioConfig, n int) []float64
- func HammingWindowFunction(length int) []float64
- func HannWindowFunction(length int) []float64
- func LoadWavData(file string) ([]float64, error)
- func NoWindowFunction(length int) []float64
- func SetResult(cfg *audio.AudioConfig, result []float64, i int, v float64)
- func SineWindowFunction(length int) []float64
- func TrapezoidalWindowFunction(length int) []float64
- func TukeyWindowFunction(length int) []float64
- type BaseGenerator
- func (s *BaseGenerator) GetPitch() float64
- func (s *BaseGenerator) GetSamples(cfg *audio.AudioConfig, n int) []float64
- func (g *BaseGenerator) IncrementPhase(waveLength int)
- func (s *BaseGenerator) SetGain(f float64)
- func (s *BaseGenerator) SetPitch(f float64)
- func (s *BaseGenerator) SetPitchbend(f float64)
- type Generator
- func NewGrainsGenerator(cfg *audio.AudioConfig, sample []float64, grainSize, birthrate float64, ...) Generator
- func NewGrainsGeneratorForWavFile(cfg *audio.AudioConfig, file string, grainSize, birthrate float64, density int, ...) (Generator, error)
- func NewPitchedWavGenerator(file string, gain, sampleBasePitch float64) (Generator, error)
- func NewPulseWaveGenerator(dutyCycle float64, dutyCycleModulator Generator, ...) Generator
- func NewSawtoothWaveOscillator() Generator
- func NewSineWaveOscillator() Generator
- func NewSquareWaveOscillator() Generator
- func NewTriangleWaveOscillator() Generator
- func NewWavGenerator(file string, gain float64) (Generator, error)
- func NewWhiteNoiseGenerator() Generator
- type GrainsGenerator
- type WindowFunction
Constants ¶
View Source
const MaxInt int = (1<<bits.UintSize)/2 - 1
Variables ¶
View Source
var WavCache = map[string][]float64{}
Functions ¶
func GetEmptySampleArray ¶
func GetEmptySampleArray(cfg *audio.AudioConfig, n int) []float64
func LoadWavData ¶
Loads file and returns a stereo sample
func SineWindowFunction ¶
The upper part of a sine wave.
func TrapezoidalWindowFunction ¶
Trapezoidal window
Types ¶
type BaseGenerator ¶
type BaseGenerator struct { Pitch float64 PitchbendFactor float64 Gain float64 Phase int // needs to be updated from GetSamplesFunc GetSamplesFunc func(cfg *audio.AudioConfig, n int) []float64 SetPitchFunc func(float64) }
func NewBaseGenerator ¶
func NewBaseGenerator() *BaseGenerator
func (*BaseGenerator) GetPitch ¶
func (s *BaseGenerator) GetPitch() float64
func (*BaseGenerator) GetSamples ¶
func (s *BaseGenerator) GetSamples(cfg *audio.AudioConfig, n int) []float64
func (*BaseGenerator) IncrementPhase ¶
func (g *BaseGenerator) IncrementPhase(waveLength int)
func (*BaseGenerator) SetGain ¶
func (s *BaseGenerator) SetGain(f float64)
func (*BaseGenerator) SetPitch ¶
func (s *BaseGenerator) SetPitch(f float64)
func (*BaseGenerator) SetPitchbend ¶
func (s *BaseGenerator) SetPitchbend(f float64)
type Generator ¶
type Generator interface { // GetSamples is the meat of each Generator and returns `n` samples. // // There are two important variables in cfg that should be considered: // * cfg.SampleRate: the number of samples per second; affects pitch // * cfg.Stereo: whether or not the output is stereo - should return n*2 samples if so // // `Pitch`, `PitchbendFactor` and `Gain` can in theory all be ignored // (see WhiteNoiseGenerator for one such generator). // GetSamples(cfg *audio.AudioConfig, n int) []float64 // return samples between -1.0 and 1.0 SetPitch(float64) SetPitchbend(float64) SetGain(float64) }
func NewGrainsGenerator ¶
func NewGrainsGenerator(cfg *audio.AudioConfig, sample []float64, grainSize, birthrate float64, density int, spread, speed, randomPosition, gain float64, repeat bool) Generator
Synchronous Granular Synthesis.
grainsize: in milliseconds birthrate: in milliseconds density: number of grain generators spread: milliseconds between generators speed: default 1.0; negative for reverse repeat: whether or not to loop through the sample randomPosition: in milliseconds
func NewGrainsGeneratorForWavFile ¶
func NewGrainsGeneratorForWavFile(cfg *audio.AudioConfig, file string, grainSize, birthrate float64, density int, spread, speed, randomPosition, gain float64, repeat bool) (Generator, error)
grainsize: in milliseconds birthrate: in milliseconds density: number of grain generators spread: milliseconds between generators speed: default 1.0; negative for reverse repeat: whether or not to loop through the sample randomPosition: in milliseconds
func NewPitchedWavGenerator ¶
func NewPulseWaveGenerator ¶
func NewPulseWaveGenerator(dutyCycle float64, dutyCycleModulator Generator, dutyCycleModulatorDepth float64) Generator
Duty cycle should be between 0.0 and 1.0
func NewSawtoothWaveOscillator ¶
func NewSawtoothWaveOscillator() Generator
func NewSineWaveOscillator ¶
func NewSineWaveOscillator() Generator
func NewSquareWaveOscillator ¶
func NewSquareWaveOscillator() Generator
func NewTriangleWaveOscillator ¶
func NewTriangleWaveOscillator() Generator
func NewWhiteNoiseGenerator ¶
func NewWhiteNoiseGenerator() Generator
type GrainsGenerator ¶
type GrainsGenerator struct { *BaseGenerator GrainGain float64 // grainsize: in milliseconds. Recommended value between 10-50. GrainSize float64 // birthrate: in milliseconds BirthRate float64 // density: number of grain generators Density int // spread: milliseconds between generators Spread float64 // speed: default 1.0; negative for reverse Speed float64 // repeat: whether or not to loop through the sample Repeat bool // randomPosition: in milliseconds RandomPosition float64 // The window function WindowFunction WindowFunction }
type WindowFunction ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.