generators

package
v0.0.0-...-486f928 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2022 License: MIT Imports: 7 Imported by: 3

Documentation

Overview

Generate audio samples

Index

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 HammingWindowFunction

func HammingWindowFunction(length int) []float64

Hamming window

func HannWindowFunction

func HannWindowFunction(length int) []float64

Hann window

func LoadWavData

func LoadWavData(file string) ([]float64, error)

Loads file and returns a stereo sample

func NoWindowFunction

func NoWindowFunction(length int) []float64

No window function.

func SetResult

func SetResult(cfg *audio.AudioConfig, result []float64, i int, v float64)

func SineWindowFunction

func SineWindowFunction(length int) []float64

The upper part of a sine wave.

func TrapezoidalWindowFunction

func TrapezoidalWindowFunction(length int) []float64

Trapezoidal window

func TukeyWindowFunction

func TukeyWindowFunction(length int) []float64

Tukey 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 NewPitchedWavGenerator(file string, gain, sampleBasePitch float64) (Generator, error)

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 NewWavGenerator

func NewWavGenerator(file string, gain float64) (Generator, error)

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

type WindowFunction func(length int) []float64

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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