Module sfxr

A port of the sfxr sound effect synthesizer to Lua

Functions

newSound (...) The constructor for the Sound class.

Tables

WAVEFORM Wave form constants
SAMPLERATE Sample rate constants (use the number values directly, these are just for lookup)
BITDEPTH Bit depth constants (use the number values directly, these are just for lookup)
ENDIANNESS Endianness constants

Fields

VERSION The module version (SemVer)

Class Sound

sfxr.Sound:__init () Initialize the Sound instance.
self.volume.master Master volume (default 0.5)
self.volume.sound Additional gain (default 0.5)
sfxr.Sound:resetParameters () Set all parameters to their default values.
self.repeatspeed Repeat speed: Times to repeat the frequency slide over the course of the envelope (default 0.0, min 0.0, max 1.0)
self.waveform (WAVEFORM) The base wave form
self.envelope.attack Attack time: Time the sound takes to reach its peak volume (default 0.0, min 0.0, max 1.0)
self.envelope.sustain Sustain time: Time the sound sustains on its peak volume (default 0.0, min 0.0, max 1.0)
self.envelope.punch Sustain punch: Amount by which the sound peak volume is increased at the start of the sustain time (default 0.0, min 0.0, max 1.0)
self.envelope.decay Decay time: Time the sound takes to decay after its sustain time (default 0.0, min 0.0, max 1.0)
self.frequency.start Start frequency: Base tone of the sound, before sliding (default 0.0, min 0.0, max 1.0)
self.frequency.min Min frequency: Tone below which the sound will get cut off (default 0.0, min 0.0, max 1.0)
self.frequency.slide Slide: Amount by which the frequency is increased or decreased through time (default 0.0, min -1.0, max 1.0)
self.frequency.dslide Delta slide: Amount by which the slide is increased or decreased through time (default 0.0, min -1.0, max 1.0)
self.vibrato.depth Vibrato depth: Amount of vibrato-like amplitude (volume) modulation (default 0.0, min 0.0, max 1.0)
self.vibrato.speed Vibrato speed: Oscillation speed of the vibrato (default 0.0, min 0.0, max 1.0)
self.vibrato.delay Vibrato delay: Unused and unimplemented (default 0.0, min 0.0, max 1.0)
self.change.amount Change amount: Amount by which the frequency is changed mid-sound (default 0.0, min -1.0, max 1.0)
self.change.speed Change speed: Time before the frequency change happens (default 0.0, min 0.0, max 1.0)
self.duty.ratio Square duty: Width of the square wave pulse cycle (doesn't affect other wave forms) (default 0.0, min 0.0, max 1.0)
self.duty.sweep Duty sweep: Amount by which the square duty is increased or decreased through time (default 0.0, min -1.0, max 1.0)
self.phaser.offset Phaser offset: Amount by which the phaser signal is offset from the sound (default 0.0, min -1.0, max 1.0)
self.phaser.sweep Phaser sweep: Amount by which the phaser offset is increased or decreased through time (default 0.0, min -1.0, max 1.0)
self.lowpass.cutoff Lowpass filter cutoff: Lower bound for frequencies allowed to pass through this filter (default 0.0, min 0.0, max 1.0)
self.lowpass.sweep Lowpass filter cutoff sweep: Amount by which the LP filter cutoff is increased or decreased through time (default 0.0, min -1.0, max 1.0)
self.lowpass.resonance Lowpass filter resonance: Amount by which certain resonant frequencies near the cutoff are increased (default 0.0, min 0.0, max 1.0)
self.highpass.cutoff Highpass filter cutoff: Upper bound for frequencies allowed to pass through this filter (default 0.0, min 0.0, max 1.0)
self.highpass.sweep Highpass filter cutoff sweep: Amount by which the HP filter cutoff is increased or decreased through time (default 0.0, min -1.0, max 1.0)
sfxr.Sound:sanitizeParameters () Clamp all parameters within sane ranges.
sfxr.Sound:generate ([rate=44100[, depth=0]]) Generate the sound and yield the sample data.
sfxr.Sound:getEnvelopeLimit ([rate=44100]) Get the maximum sample limit allowed by the current envelope.
sfxr.Sound:generateTable ([rate=44100[, depth=0[, tab]]]) Generate the sound into a table.
sfxr.Sound:generateString ([rate=44100[, depth=16[, endianness=0]]]) Generate the sound to a binary string.
sfxr.Sound:generateSoundData ([rate=44100[, depth=0[, a]]]) Synthesize the sound to a LÖVE SoundData instance.
sfxr.Sound:randomize ([seed]) Randomize all sound parameters
sfxr.Sound:mutate ([by=1][, seed], whether) Mutate all sound parameters
sfxr.Sound:randomPickup ([seed]) Randomize all sound parameters to generate an item pick up sound
sfxr.Sound:randomLaser ([seed]) Randomize all sound parameters to generate a laser sound
sfxr.Sound:randomExplosion ([seed]) Randomize all sound parameters to generate an explosion sound
sfxr.Sound:randomPowerup ([seed]) Randomize all sound parameters to generate a power up sound
sfxr.Sound:randomHit ([seed]) Randomize all sound parameters to generate a hit sound
sfxr.Sound:randomJump ([seed]) Randomize all sound parameters to generate a jump sound
sfxr.Sound:randomBlip ([seed]) Randomize all sound parameters to generate a blip sound
sfxr.Sound:exportWAV (f[, rate=44100[, depth=0]]) Generate and export the audio data to a PCM WAVE file.
sfxr.Sound:save (f[, to=true]) Save the sound parameters to a file as a Lua table
sfxr.Sound:load (f) Load the sound parameters from a file containing a Lua table
sfxr.Sound:saveBinary (f) Save the sound parameters to a file in the sfxr binary format
sfxr.Sound:loadBinary (f) Load the sound parameters from a file in the sfxr binary format


Functions

newSound (...)
The constructor for the Sound class.

Parameters:

  • ...

Returns:

    Sound a Sound instance

Tables

WAVEFORM
Wave form constants

Fields:

  • SQUARE square wave (= 0)
  • SAW saw wave (= 1)
  • SINE sine wave (= 2)
  • NOISE white noise (= 3)
SAMPLERATE
Sample rate constants (use the number values directly, these are just for lookup)

Fields:

  • 22050 22.05 kHz (= 22050)
  • 44100 44.1 kHz (= 44100)
BITDEPTH
Bit depth constants (use the number values directly, these are just for lookup)

Fields:

  • 0 floating point bit depth, -1 to 1 (= 0)
  • 8 unsigned 8 bit, 0x00 to 0xFF (= 8)
  • 16 unsigned 16 bit, 0x0000 to 0xFFFF (= 16)
ENDIANNESS
Endianness constants

Fields:

  • LITTLE little endian (= 0)
  • BIG big endian (= 1)

Fields

VERSION
The module version (SemVer)

Class Sound

The main Sound class.
sfxr.Sound:__init ()
Initialize the Sound instance. Called by the constructor.
self.volume.master
Master volume (default 0.5)
self.volume.sound
Additional gain (default 0.5)
sfxr.Sound:resetParameters ()
Set all parameters to their default values. Called by the initializer.
self.repeatspeed
Repeat speed: Times to repeat the frequency slide over the course of the envelope (default 0.0, min 0.0, max 1.0)
self.waveform
(WAVEFORM) The base wave form
self.envelope.attack
Attack time: Time the sound takes to reach its peak volume (default 0.0, min 0.0, max 1.0)
self.envelope.sustain
Sustain time: Time the sound sustains on its peak volume (default 0.0, min 0.0, max 1.0)
self.envelope.punch
Sustain punch: Amount by which the sound peak volume is increased at the start of the sustain time (default 0.0, min 0.0, max 1.0)
self.envelope.decay
Decay time: Time the sound takes to decay after its sustain time (default 0.0, min 0.0, max 1.0)
self.frequency.start
Start frequency: Base tone of the sound, before sliding (default 0.0, min 0.0, max 1.0)
self.frequency.min
Min frequency: Tone below which the sound will get cut off (default 0.0, min 0.0, max 1.0)
self.frequency.slide
Slide: Amount by which the frequency is increased or decreased through time (default 0.0, min -1.0, max 1.0)
self.frequency.dslide
Delta slide: Amount by which the slide is increased or decreased through time (default 0.0, min -1.0, max 1.0)
self.vibrato.depth
Vibrato depth: Amount of vibrato-like amplitude (volume) modulation (default 0.0, min 0.0, max 1.0)
self.vibrato.speed
Vibrato speed: Oscillation speed of the vibrato (default 0.0, min 0.0, max 1.0)
self.vibrato.delay
Vibrato delay: Unused and unimplemented (default 0.0, min 0.0, max 1.0)
self.change.amount
Change amount: Amount by which the frequency is changed mid-sound (default 0.0, min -1.0, max 1.0)
self.change.speed
Change speed: Time before the frequency change happens (default 0.0, min 0.0, max 1.0)
self.duty.ratio
Square duty: Width of the square wave pulse cycle (doesn't affect other wave forms) (default 0.0, min 0.0, max 1.0)
self.duty.sweep
Duty sweep: Amount by which the square duty is increased or decreased through time (default 0.0, min -1.0, max 1.0)
self.phaser.offset
Phaser offset: Amount by which the phaser signal is offset from the sound (default 0.0, min -1.0, max 1.0)
self.phaser.sweep
Phaser sweep: Amount by which the phaser offset is increased or decreased through time (default 0.0, min -1.0, max 1.0)
self.lowpass.cutoff
Lowpass filter cutoff: Lower bound for frequencies allowed to pass through this filter (default 0.0, min 0.0, max 1.0)
self.lowpass.sweep
Lowpass filter cutoff sweep: Amount by which the LP filter cutoff is increased or decreased through time (default 0.0, min -1.0, max 1.0)
self.lowpass.resonance
Lowpass filter resonance: Amount by which certain resonant frequencies near the cutoff are increased (default 0.0, min 0.0, max 1.0)
self.highpass.cutoff
Highpass filter cutoff: Upper bound for frequencies allowed to pass through this filter (default 0.0, min 0.0, max 1.0)
self.highpass.sweep
Highpass filter cutoff sweep: Amount by which the HP filter cutoff is increased or decreased through time (default 0.0, min -1.0, max 1.0)
sfxr.Sound:sanitizeParameters ()
Clamp all parameters within sane ranges.
sfxr.Sound:generate ([rate=44100[, depth=0]])
Generate the sound and yield the sample data.

Parameters:

  • rate SAMPLERATE the sample rate (default 44100)
  • depth BITDEPTH the bit depth (default 0)

Returns:

    function() a generator that yields the sample data when called

Usage:

     for s in sound:generate(44100, 0) do
       -- do something with s
     end
sfxr.Sound:getEnvelopeLimit ([rate=44100])
Get the maximum sample limit allowed by the current envelope. Does not take any other limits into account, so the returned count might be higher than samples actually generated. Still useful though.

Parameters:

sfxr.Sound:generateTable ([rate=44100[, depth=0[, tab]]])
Generate the sound into a table.

Parameters:

  • rate SAMPLERATE the sample rate (default 44100)
  • depth BITDEPTH the bit depth (default 0)
  • tab {} the table to synthesize into (optional)

Returns:

  1. {number,...} the table filled with sample data
  2. int the number of written samples (== #tab)
sfxr.Sound:generateString ([rate=44100[, depth=16[, endianness=0]]])
Generate the sound to a binary string.

Parameters:

  • rate SAMPLERATE the sample rate (default 44100)
  • depth BITDEPTH the bit depth (may not be 0) (default 16)
  • endianness ENDIANNESS the endianness (ignored when depth == 8) (default 0)

Returns:

  1. string a binary string of sample data
  2. int the number of written samples
sfxr.Sound:generateSoundData ([rate=44100[, depth=0[, a]]])
Synthesize the sound to a LÖVE SoundData instance.

Parameters:

  • rate SAMPLERATE the sample rate (default 44100)
  • depth BITDEPTH the bit depth (default 0)
  • a love.sound.SoundData SoundData instance (will be created if not passed) (optional)

Returns:

  1. love.sound.SoundData a SoundData instance
  2. int the number of written samples
sfxr.Sound:randomize ([seed])
Randomize all sound parameters

Parameters:

  • seed number a random seed (optional)
sfxr.Sound:mutate ([by=1][, seed], whether)
Mutate all sound parameters

Parameters:

  • by amount how much to mutate the parameters (default 1)
  • seed number a random seed (optional)
  • whether bool to change the frequency parameters
sfxr.Sound:randomPickup ([seed])
Randomize all sound parameters to generate an item pick up sound

Parameters:

  • seed number a random seed (optional)
sfxr.Sound:randomLaser ([seed])
Randomize all sound parameters to generate a laser sound

Parameters:

  • seed number a random seed (optional)
sfxr.Sound:randomExplosion ([seed])
Randomize all sound parameters to generate an explosion sound

Parameters:

  • seed number a random seed (optional)
sfxr.Sound:randomPowerup ([seed])
Randomize all sound parameters to generate a power up sound

Parameters:

  • seed number a random seed (optional)
sfxr.Sound:randomHit ([seed])
Randomize all sound parameters to generate a hit sound

Parameters:

  • seed number a random seed (optional)
sfxr.Sound:randomJump ([seed])
Randomize all sound parameters to generate a jump sound

Parameters:

  • seed number a random seed (optional)
sfxr.Sound:randomBlip ([seed])
Randomize all sound parameters to generate a blip sound

Parameters:

  • seed number a random seed (optional)
sfxr.Sound:exportWAV (f[, rate=44100[, depth=0]])
Generate and export the audio data to a PCM WAVE file.

Parameters:

  • f string, file or love.filesystem.File a file path, a Lua file object, a love.filesystem.File instance
  • rate SAMPLERATE the sample rate (default 44100)
  • depth BITDEPTH the bit depth (default 0)
sfxr.Sound:save (f[, to=true])
Save the sound parameters to a file as a Lua table

Parameters:

  • f string, file or love.filesystem.File a file path, a Lua file object, a love.filesystem.File instance
  • to whether minify the output (default true)
sfxr.Sound:load (f)
Load the sound parameters from a file containing a Lua table

Parameters:

  • f string, file or love.filesystem.File a file path, a Lua file object, a love.filesystem.File instance
sfxr.Sound:saveBinary (f)
Save the sound parameters to a file in the sfxr binary format

Parameters:

  • f string, file or love.filesystem.File a file path, a Lua file object, a love.filesystem.File instance
sfxr.Sound:loadBinary (f)
Load the sound parameters from a file in the sfxr binary format

Parameters:

  • f string, file or love.filesystem.File a file path, a Lua file object, a love.filesystem.File instance
generated by LDoc 1.4.3 Last updated 2016-03-02 00:35:01