Simple sound effect generator functions, using wrapped, cleaned up and modified code from jsfxr and RIFFWAVE.js (jsfxr is a javascript port of sfxr).
Methods
-
(static) generateEffectAudio(waveShape, envAttack, envSustain, envPunch, envDecay, freqBase, freqMinCutoff, freqSlide, freqDeltaSlide, vibDepth, vibSpeed, arpModFreq, arpModSpeed, dutyCycle, dutySweep, repeatSpeed, flangeOffset, flangeSweep, lpfCutoff, lpfCutoffSweep, lpfResonance, hpfCutoff, hpfCutoffSweep, sampleVolume, sampleRate, sampleBits, audioVolume) → {HTMLAudioElement}
-
Instantiate an sfxr sound effect with the given parameters as html audio element.
Values will be capped to the inclusive intervals described as [0,+1] or [-1,+1].
Set any of the parameters to null to use the (default) value.Parameters:
Name Type Description waveShape
number | null rlSfxr.squareWave/sawtoothWave/sineWave/noiseWave (squareWave)
envAttack
number | null [0,+1] envelope attack time (0.0)
envSustain
number | null [0,+1] envelope sustain time (0.3)
envPunch
number | null [0,+1] envelope sustain punch (0.0)
envDecay
number | null [0,+1] envelope decay time (0.4)
freqBase
number | null [0,+1] base frequency (0.3)
freqMinCutoff
number | null [0,+1] min frequency cutoff (0.0)
freqSlide
number | null [-1,+1] frequency slide (0.0)
freqDeltaSlide
number | null [-1,+1] frequency delta slide (0.0)
vibDepth
number | null [0,+1] vibrato depth (0.0)
vibSpeed
number | null [0,+1] vibrato speed (0.0)
arpModFreq
number | null [-1,+1] arpeggio frequency change amount (0.0)
arpModSpeed
number | null [0,+1] arpeggio frequence change speed (0.0)
dutyCycle
number | null [0,+1] square and sawtooth wave duty cycle (0.0)
dutySweep
number | null [-1,+1] square and sawtooth wave duty sweep (0.0)
repeatSpeed
number | null [0,+1] repeat speed (0.0)
flangeOffset
number | null [-1,+1] flanger offset (0.0)
flangeSweep
number | null [-1,+1] flanger sweep (0.0)
lpfCutoff
number | null [0,+1] low pass filter cutoff (1.0)
lpfCutoffSweep
number | null [-1,+1] low pass filter cutoff sweep (0.0)
lpfResonance
number | null [0,+1] low pass filter resonance (0.0)
hpfCutoff
number | null [0,+1] high pass filter cutoff (0.0)
hpfCutoffSweep
number | null [-1,+1] high pass filter cutoff sweep (0.0)
sampleVolume
number | null [0,+1] volume for the generated sample itself (0.5)
sampleRate
number | null [8000,44100] sample rate in Hz (22050)
sampleBits
number | null 8 or 16 sample size in bits (8)
audioVolume
number | null [0,+1] initial volume for the html audio element (0.5)
- See:
Returns:
- Type
- HTMLAudioElement
-
(static) getRandomEffectAudio() → {HTMLAudioElement}
-
Instantiate a random sfxr sound effect as html audio element.
- See:
Returns:
- Type
- HTMLAudioElement