Documentation
¶
Index ¶
- Constants
- func AnalyzeHighestFrequency(samples []float64, sampleRate int) float64
- func ApplyAddPartials(duration, amplitude, frequency float64, partials, ampEnv []float64, ...) []float64
- func ApplyBitcrusher(samples []float64, bitDepth, sampleRateReduction int) []float64
- func ApplyChorus(samples []float64, sampleRate int, delaySec, depth, rate, mix float64) []float64
- func ApplyCompressor(samples []float64, threshold, ratio, attack, release float64, sampleRate int) []float64
- func ApplyEnvelope(samples []float64, attack, decay, sustain, release float64, sampleRate int) []float64
- func ApplyFMSynthesis(duration, carrierFreq, modFreq, modIndex, amplitude float64, ampEnv []float64, ...) []float64
- func ApplyFadeIn(samples []float64, fadeDuration float64, sampleRate int) []float64
- func ApplyFadeOut(samples []float64, fadeDuration float64, sampleRate int) []float64
- func ApplyFlanger(samples []float64, sampleRate int, ...) []float64
- func ApplyFrequencyModulation(samples []float64, carrierFreq, modDepth float64, sampleRate int) []float64
- func ApplyGranularSynthesis(samples []float64, grainSize, overlap, sampleRate int) []float64
- func ApplyKarplusStrong(duration, amplitude float64, p int, b float64, sampleRate int) []float64
- func ApplyLimiter(samples []float64) []float64
- func ApplyMultibandCompression(samples []float64, bands []struct{ ... }, compressors []struct{ ... }, ...) []float64
- func ApplyNoiseGate(samples []float64, threshold, attack, release float64, sampleRate int) []float64
- func ApplyNormalize(samples []float64, targetPeak float64) []float64
- func ApplyPanning(samples []float64, pan float64) ([]float64, []float64)
- func ApplyPhaser(samples []float64, sampleRate int, rate, depth, feedback float64) []float64
- func ApplyPitchModulation(samples []float64, modFreq, modDepth float64, sampleRate int) []float64
- func ApplyQuadraticFadeIn(samples []float64, fadeDuration float64, sampleRate int) []float64
- func ApplyQuadraticFadeOut(samples []float64, fadeDuration float64, sampleRate int) []float64
- func ApplyReverb(samples []float64, sampleRate int, delayTimes, decays []float64, mix float64) []float64
- func ApplySidechainCompressor(target, trigger []float64, threshold, ratio, attack, release float64, ...) []float64
- func ApplySoftClipping(samples []float64, drive float64) []float64
- func ApplyStereoDelay(left, right []float64, sampleRate int, ...) ([]float64, []float64)
- func ApplySubtractOp(duration, amplitude, b1 float64, ampEnv []float64, sampleRate int) []float64
- func ApplyTremolo(samples []float64, sampleRate int, rate, depth float64) []float64
- func BandPassFilter(samples []float64, lowCutoff, highCutoff float64, sampleRate int) []float64
- func DetunedOscillators(freq float64, detune []float64, length int, sampleRate int) []float64
- func Drive(samples []float64, gain float64) []float64
- func ExponentialFade(t float64) float64
- func FindPeakAmplitude(samples []float64) float64
- func GenerateBrownNoise(length int, amount float64) []float64
- func GeneratePinkNoise(length int, amount float64) []float64
- func GenerateWhiteNoise(length int, amount float64) []float64
- func HighPassFilter(samples []float64, cutoff float64, sampleRate int) []float64
- func Limiter(samples []float64) []float64
- func LinearFade(t float64) float64
- func LinearSummation(samples ...[]float64) ([]float64, error)
- func LogarithmicFade(t float64) float64
- func LowPassFilter(samples []float64, cutoff float64, sampleRate int) []float64
- func NormalizeSamples(samples []float64, targetPeak float64) []float64
- func PadSamples(wave1, wave2 []float64) ([]float64, []float64)
- func QuadraticFade(t float64) float64
- func RMSMixing(samples ...[]float64) ([]float64, error)
- func Resample(waveform []float64, originalSampleRate, targetSampleRate int) []float64
- func SawtoothOscillator(freq float64, length int, sampleRate int) []float64
- func SchroederReverb(samples []float64, decayFactor float64, combDelays []int, allPassDelays []int) ([]float64, error)
- func SineFade(t float64) float64
- func WeightedSummation(weights []float64, samples ...[]float64) ([]float64, error)
- type FadeCurve
- type Settings
- func CopySettings(cfg *Settings) *Settings
- func New606(soundType SoundType, output io.WriteSeeker, duration float64, ...) (*Settings, error)
- func New707(soundType SoundType, output io.WriteSeeker, duration float64, ...) (*Settings, error)
- func New808(soundType SoundType, output io.WriteSeeker, duration float64, ...) (*Settings, error)
- func New909(soundType SoundType, output io.WriteSeeker, duration float64, ...) (*Settings, error)
- func NewClapSettings(output io.WriteSeeker, sampleRate, bitDepth, channels int) (*Settings, error)
- func NewDeepHouse(soundType SoundType, output io.WriteSeeker, duration float64, ...) (*Settings, error)
- func NewExperimental(soundType SoundType, output io.WriteSeeker, duration float64, ...) (*Settings, error)
- func NewLinn(soundType SoundType, output io.WriteSeeker, duration float64, ...) (*Settings, error)
- func NewRandom(soundType SoundType, output io.WriteSeeker, sampleRate, bitDepth, channels int) *Settings
- func NewSettings(output io.WriteSeeker, startFreq, endFreq, duration float64, ...) (*Settings, error)
- func NewSnareSettings(output io.WriteSeeker, sampleRate, bitDepth, channels int) (*Settings, error)
- func (cfg *Settings) ApplyDrive(sample float64) float64
- func (cfg *Settings) ApplyEnvelopeAtTime(t float64) float64
- func (cfg *Settings) Color() color.RGBA
- func (cfg *Settings) Generate() ([]float64, error)
- func (cfg *Settings) GenerateAndSaveTo(directory string) (string, error)
- func (cfg *Settings) GenerateBass() ([]float64, error)
- func (cfg *Settings) GenerateClap() ([]float64, error)
- func (cfg *Settings) GenerateClosedHH() ([]float64, error)
- func (cfg *Settings) GenerateCrash() ([]float64, error)
- func (cfg *Settings) GenerateKick() ([]float64, error)
- func (cfg *Settings) GenerateLead() ([]float64, error)
- func (cfg *Settings) GenerateOpenHH() ([]float64, error)
- func (cfg *Settings) GeneratePercussion() ([]float64, error)
- func (cfg *Settings) GenerateRide() ([]float64, error)
- func (cfg *Settings) GenerateRimshot() ([]float64, error)
- func (cfg *Settings) GenerateSnare() ([]float64, error)
- func (cfg *Settings) GenerateSweepWaveform() ([]float64, error)
- func (cfg *Settings) GenerateTom() ([]float64, error)
- func (cfg *Settings) GenerateXylophone() ([]float64, error)
- type SoundType
Constants ¶
const ( Kick = iota Clap Snare ClosedHH OpenHH Rimshot Tom Percussion Ride Crash Bass Xylophone Lead )
const ( WaveSine = iota WaveTriangle WaveSawtooth WaveSquare WaveWhiteNoise WavePinkNoise WaveBrownNoise )
Constants for waveform types
Variables ¶
This section is empty.
Functions ¶
func AnalyzeHighestFrequency ¶
AnalyzeHighestFrequency estimates the highest frequency in the audio signal
func ApplyAddPartials ¶ added in v1.9.0
func ApplyAddPartials(duration, amplitude, frequency float64, partials, ampEnv []float64, sampleRate int) []float64
ApplyAddPartials adds harmonic partials to the samples using the audioeffects package. partials should contain frequency and amplitude pairs.
func ApplyBitcrusher ¶ added in v1.9.0
ApplyBitcrusher applies a bitcrusher effect to the samples using the audioeffects package. bitDepth controls the number of bits used in the reduction. sampleRateReduction reduces the sample rate by the specified factor.
func ApplyChorus ¶ added in v1.2.0
ApplyChorus applies a chorus effect to the samples using the audioeffects package. delaySec specifies the base delay time in seconds. depth controls the modulation depth of the delay time. rate is the modulation rate in Hz. mix determines the blend between dry and wet signals (0.0 = dry only, 1.0 = wet only).
func ApplyCompressor ¶ added in v1.9.0
func ApplyCompressor(samples []float64, threshold, ratio, attack, release float64, sampleRate int) []float64
ApplyCompressor applies dynamic range compression to the samples using the audioeffects package. threshold sets the level above which compression occurs. ratio determines the amount of compression applied. attack and release control the compressor's responsiveness.
func ApplyEnvelope ¶
func ApplyEnvelope(samples []float64, attack, decay, sustain, release float64, sampleRate int) []float64
ApplyEnvelope applies an ADSR envelope to the waveform using the audioeffects package.
func ApplyFMSynthesis ¶ added in v1.9.0
func ApplyFMSynthesis(duration, carrierFreq, modFreq, modIndex, amplitude float64, ampEnv []float64, sampleRate int) []float64
ApplyFM_Synthesis generates a frequency-modulated synthesis signal using the audioeffects package.
func ApplyFadeIn ¶ added in v1.2.0
ApplyFadeIn applies a fade-in to the start of the samples using the audioeffects package.
func ApplyFadeOut ¶ added in v1.2.0
ApplyFadeOut applies a fade-out to the end of the samples using the audioeffects package.
func ApplyFlanger ¶ added in v1.9.0
func ApplyFlanger(samples []float64, sampleRate int, baseDelay, modDepth, modRate, feedback, mix float64) []float64
ApplyFlanger applies a flanger effect to the samples using the audioeffects package. baseDelay is the base delay time in seconds. modDepth controls the modulation depth of the delay time. modRate is the modulation rate in Hz. feedback controls the amount of delayed signal fed back into the delay line. mix determines the blend between dry and wet signals.
func ApplyFrequencyModulation ¶ added in v1.1.0
func ApplyFrequencyModulation(samples []float64, carrierFreq, modDepth float64, sampleRate int) []float64
ApplyFrequencyModulation applies frequency modulation to a waveform using the audioeffects package. carrierFreq is the base frequency of the carrier wave. modDepth controls the extent of frequency deviation.
func ApplyGranularSynthesis ¶ added in v1.9.0
ApplyGranularSynthesis applies granular synthesis to the samples using the audioeffects package. grainSize specifies the size of each grain in samples. overlap determines the overlap between consecutive grains.
func ApplyKarplusStrong ¶ added in v1.9.0
ApplyKarplusStrong applies the Karplus-Strong algorithm to generate plucked string sounds using the audioeffects package. p is the delay line length in samples. b controls the damping factor.
func ApplyLimiter ¶ added in v1.9.0
ApplyLimiter applies a limiter to the samples using the audioeffects package. It ensures that the sample amplitudes do not exceed 1.0 or -1.0.
func ApplyMultibandCompression ¶ added in v1.9.0
func ApplyMultibandCompression(samples []float64, bands []struct { Low float64 High float64 }, compressors []struct { Threshold float64 Ratio float64 Attack float64 Release float64 }, sampleRate int) []float64
ApplyMultibandCompression applies multiband compression to the samples using the audioeffects package. bands defines the frequency ranges for each band. compressors defines the compression settings for each band.
func ApplyNoiseGate ¶ added in v1.9.0
func ApplyNoiseGate(samples []float64, threshold, attack, release float64, sampleRate int) []float64
ApplyNoiseGate applies a noise gate to the samples using the audioeffects package. threshold sets the level below which the signal is attenuated. attack and release control the gate's responsiveness.
func ApplyNormalize ¶ added in v1.9.0
ApplyNormalize scales the samples to ensure the peak amplitude matches the target peak using the audioeffects package.
func ApplyPanning ¶ added in v1.1.0
ApplyPanning applies stereo panning to the samples using the audioeffects package. Pan should be in the range [-1, 1], where -1 is full left and 1 is full right.
func ApplyPhaser ¶ added in v1.9.0
ApplyPhaser applies a phaser effect to the samples using the audioeffects package. rate is the modulation frequency in Hz. depth controls the modulation depth. feedback determines the amount of phase-shifted signal fed back into the phaser.
func ApplyPitchModulation ¶ added in v1.1.0
ApplyPitchModulation applies pitch modulation (vibrato) to the samples using the audioeffects package.
func ApplyQuadraticFadeIn ¶ added in v1.9.0
ApplyQuadraticFadeIn applies a fade-in to the start of the samples using the audioeffects package.
func ApplyQuadraticFadeOut ¶ added in v1.9.0
ApplyQuadraticFadeOut applies a fade-out to the end of the samples using the audioeffects package.
func ApplyReverb ¶ added in v1.9.0
func ApplyReverb(samples []float64, sampleRate int, delayTimes, decays []float64, mix float64) []float64
ApplyReverb applies a reverb effect to the samples using the audioeffects package. delayTimes and decays should be of the same length, specifying multiple delay and decay pairs. mix determines the blend between dry and wet signals.
func ApplySidechainCompressor ¶ added in v1.9.0
func ApplySidechainCompressor(target, trigger []float64, threshold, ratio, attack, release float64, sampleRate int) []float64
ApplySidechainCompressor applies a sidechain compressor to the target samples using the trigger samples. threshold sets the compression threshold. ratio determines the compression ratio. attack and release control the compressor's responsiveness.
func ApplySoftClipping ¶ added in v1.9.0
ApplySoftClipping applies soft clipping distortion to the samples using the audioeffects package.
func ApplyStereoDelay ¶ added in v1.9.0
func ApplyStereoDelay(left, right []float64, sampleRate int, delayTimeLeft, delayTimeRight, feedback, mix float64) ([]float64, []float64)
ApplyStereoDelay applies a stereo delay effect to the left and right channels using the audioeffects package. delayTimeLeft and delayTimeRight specify delay times for each channel in seconds. feedback controls the amount of delayed signal fed back into the delay line. mix determines the blend between dry and wet signals.
func ApplySubtractOp ¶ added in v1.9.0
ApplySubtractOp subtracts noise from the samples using the audioeffects package. duration specifies the noise duration in seconds. amplitude sets the noise amplitude. b1 is a scaling factor for the noise. ampEnv defines the amplitude envelope.
func ApplyTremolo ¶ added in v1.9.0
ApplyTremolo applies a tremolo effect to the samples using the audioeffects package. rate is the modulation frequency in Hz. depth controls the amplitude modulation depth.
func BandPassFilter ¶ added in v1.1.0
BandPassFilter applies a band-pass filter to the samples
func DetunedOscillators ¶
DetunedOscillators generates multiple detuned sawtooth oscillators and combines them
func ExponentialFade ¶ added in v1.2.0
ExponentialFade is an exponential fade curve
func FindPeakAmplitude ¶
FindPeakAmplitude returns the maximum absolute amplitude in the sample set
func GenerateBrownNoise ¶ added in v1.7.0
GenerateBrownNoise generates brown noise
func GeneratePinkNoise ¶ added in v1.7.0
GeneratePinkNoise generates pink noise
func GenerateWhiteNoise ¶ added in v1.7.0
GenerateWhiteNoise generates white noise
func HighPassFilter ¶ added in v1.1.0
HighPassFilter applies a basic high-pass filter to the samples
func LinearFade ¶ added in v1.2.0
LinearFade is a linear fade curve
func LinearSummation ¶
LinearSummation mixes multiple audio samples by averaging them together. It automatically clamps the sum to avoid overflow and distortion.
func LogarithmicFade ¶ added in v1.2.0
LogarithmicFade is a logarithmic fade curve
func LowPassFilter ¶
LowPassFilter applies a basic low-pass filter to the samples
func NormalizeSamples ¶
NormalizeSamples scales the samples so the peak amplitude matches the given max amplitude
func PadSamples ¶
PadSamples pads the shorter waveform with zeros to make both waveforms the same length.
func QuadraticFade ¶ added in v1.2.0
QuadraticFade is a quadratic (ease-in) fade curve
func SawtoothOscillator ¶
SawtoothOscillator generates a sawtooth waveform at a specific frequency
func SchroederReverb ¶ added in v1.1.0
func SchroederReverb(samples []float64, decayFactor float64, combDelays []int, allPassDelays []int) ([]float64, error)
SchroederReverb applies a high-quality reverb effect using the Schroeder algorithm
Types ¶
type Settings ¶
type Settings struct {
SoundType SoundType
SampleRate int
BitDepth int
Channels int
Output io.WriteSeeker
StartFreq float64
EndFreq float64
Duration float64
WaveformType int
NoiseAmount float64
Attack float64
Decay float64
Sustain float64
Release float64
Drive float64
FilterCutoff float64
FilterResonance float64
Sweep float64
PitchDecay float64
NumOscillators int
OscillatorLevels []float64
SaturatorAmount float64
FilterBands []float64
FadeDuration float64
SmoothFrequencyTransitions bool
AttackCurve FadeCurve
DecayCurve FadeCurve
ReleaseCurve FadeCurve
ReverbAmount float64
ReverbDecay float64
DelayAmount float64
DelayTime float64
DelayFeedback float64
}
Settings holds the configuration for generating a sound
func CopySettings ¶
CopySettings creates a deep copy of a Settings struct
func New606 ¶
func New606(soundType SoundType, output io.WriteSeeker, duration float64, sampleRate, bitDepth, channels int) (*Settings, error)
New606 creates sounds similar to the Roland TR-606
func New707 ¶
func New707(soundType SoundType, output io.WriteSeeker, duration float64, sampleRate, bitDepth, channels int) (*Settings, error)
New707 creates sounds similar to the Roland TR-707
func New808 ¶
func New808(soundType SoundType, output io.WriteSeeker, duration float64, sampleRate, bitDepth, channels int) (*Settings, error)
New808 creates sounds similar to the Roland TR-808
func New909 ¶
func New909(soundType SoundType, output io.WriteSeeker, duration float64, sampleRate, bitDepth, channels int) (*Settings, error)
New909 creates sounds similar to the Roland TR-909
func NewClapSettings ¶ added in v1.13.0
func NewClapSettings(output io.WriteSeeker, sampleRate, bitDepth, channels int) (*Settings, error)
NewClapSettings creates a new Settings instance with predefined values optimized for clap sounds.
func NewDeepHouse ¶
func NewDeepHouse(soundType SoundType, output io.WriteSeeker, duration float64, sampleRate, bitDepth, channels int) (*Settings, error)
NewDeepHouse creates Deep House style sounds
func NewExperimental ¶
func NewExperimental(soundType SoundType, output io.WriteSeeker, duration float64, sampleRate, bitDepth, channels int) (*Settings, error)
NewExperimental creates experimental sounds with unusual parameters
func NewLinn ¶ added in v1.13.0
func NewLinn(soundType SoundType, output io.WriteSeeker, duration float64, sampleRate, bitDepth, channels int) (*Settings, error)
NewLinn creates sounds similar to the LinnDrum
func NewRandom ¶
func NewRandom(soundType SoundType, output io.WriteSeeker, sampleRate, bitDepth, channels int) *Settings
NewRandom generates random settings for the given sound type. It handles each SoundType by initializing a Settings instance with randomized parameters suitable for that sound.
func NewSettings ¶
func NewSettings(output io.WriteSeeker, startFreq, endFreq, duration float64, sampleRate, bitDepth, channels int) (*Settings, error)
NewSettings creates a new Settings instance with default values for a percussive sound
func NewSnareSettings ¶ added in v1.10.0
func NewSnareSettings(output io.WriteSeeker, sampleRate, bitDepth, channels int) (*Settings, error)
NewSnareSettings creates a new Settings instance with predefined values optimized for snare drum sounds.
func (*Settings) ApplyDrive ¶
ApplyDrive applies a drive (distortion) effect to a single sample using the audioeffects package.
func (*Settings) ApplyEnvelopeAtTime ¶ added in v1.2.0
ApplyEnvelopeAtTime generates the ADSR envelope value at a specific normalized time. This function retains the custom implementation as audioeffects does not expose envelope evaluation at a specific time.
func (*Settings) Generate ¶ added in v1.5.0
Generate is a wrapper function that calls the appropriate Generate* function based on the given sound type
func (*Settings) GenerateAndSaveTo ¶ added in v1.5.0
GenerateAndSaveTo generates samples for a given type (e.g., "kick", "snare") and saves it to a specified directory, avoiding filename collisions.
func (*Settings) GenerateBass ¶ added in v1.5.0
GenerateBass generates a deep, detuned bass sound typical of deep house
func (*Settings) GenerateClap ¶ added in v1.5.0
GenerateClap generates a clap sound by combining filtered noise bursts
func (*Settings) GenerateClosedHH ¶ added in v1.5.0
GenerateClosedHH generates a closed hi-hat sound using filtered noise
func (*Settings) GenerateCrash ¶ added in v1.5.0
GenerateCrash generates a crash cymbal sound using filtered noise
func (*Settings) GenerateKick ¶
GenerateKick generates the kick waveform and returns it as a slice of float64 samples (without writing to disk).
func (*Settings) GenerateLead ¶ added in v1.5.0
GenerateLead generates a bright, detuned lead sound
func (*Settings) GenerateOpenHH ¶ added in v1.5.0
GenerateOpenHH generates an open hi-hat sound using filtered noise
func (*Settings) GeneratePercussion ¶ added in v1.5.0
GeneratePercussion generates a tonal percussion sound like bongo or conga
func (*Settings) GenerateRide ¶ added in v1.5.0
GenerateRide generates a ride cymbal sound using filtered noise
func (*Settings) GenerateRimshot ¶ added in v1.5.0
GenerateRimshot generates a rimshot sound by using a short burst of high-frequency noise
func (*Settings) GenerateSnare ¶ added in v1.5.0
GenerateSnare generates a snare drum sound by combining noise and a tonal component
func (*Settings) GenerateSweepWaveform ¶ added in v1.2.0
GenerateSweepWaveform generates a frequency sweep waveform based on the settings.
func (*Settings) GenerateTom ¶ added in v1.5.0
GenerateTom generates a tom drum sound, configurable for low, mid, and high toms
func (*Settings) GenerateXylophone ¶ added in v1.5.0
GenerateXylophone generates a xylophone-like sound for arpeggios