sfxr.lua/docs/index.html

1800 lines
44 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<title>sfxr.lua Documentation</title>
<link rel="stylesheet" href="ldoc_pale.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"></div>
<div id="product_name"><big><b></b></big></div>
<div id="product_description"></div>
</div> <!-- id="product" -->
<div id="main">
<!-- Menu -->
<div id="navigation">
<br/>
<h1>sfxr.lua</h1>
<h2>Contents</h2>
<ul>
<li><a href="#Functions">Functions</a></li>
<li><a href="#Constants">Constants</a></li>
<li><a href="#Class_Sound">Class Sound </a></li>
<li><a href="#Parameters">Parameters</a></li>
<li><a href="#Volume">Volume</a></li>
<li><a href="#Envelope">Envelope</a></li>
<li><a href="#Frequency">Frequency</a></li>
<li><a href="#Change">Change</a></li>
<li><a href="#Duty">Duty</a></li>
<li><a href="#Phaser">Phaser</a></li>
<li><a href="#Lowpass">Lowpass</a></li>
<li><a href="#Highpass">Highpass</a></li>
<li><a href="#Vibrato">Vibrato</a></li>
<li><a href="#Randomization">Randomization</a></li>
<li><a href="#Serialization">Serialization</a></li>
</ul>
<h2>API</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><strong>sfxr</strong></li>
</ul>
</div>
<div id="content">
<h1>Module <code>sfxr</code></h1>
<p>A port of the sfxr sound effect synthesizer to pure Lua, designed to be used
together with the <em>awesome</em> <a href="https://love2d.org">LÖVE</a> game framework.</p>
<p>
</p>
<h2><a href="#Functions">Functions</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#newSound">newSound (...)</a></td>
<td class="summary">Construct and return a new <a href="index.html#Sound">Sound</a> instance.</td>
</tr>
</table>
<h2><a href="#Constants">Constants</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#VERSION">VERSION</a></td>
<td class="summary">The module version (SemVer format)</td>
</tr>
<tr>
<td class="name" nowrap><a href="#WAVEFORM">WAVEFORM</a></td>
<td class="summary"><a href="https://en.wikipedia.org/wiki/Waveform">Waveform</a> constants</td>
</tr>
<tr>
<td class="name" nowrap><a href="#SAMPLERATE">SAMPLERATE</a></td>
<td class="summary"><a href="https://en.wikipedia.org/wiki/Sampling_(signal_processing">Sampling rate</a> constants
(use the number values directly, these are just for lookup)</td>
</tr>
<tr>
<td class="name" nowrap><a href="#BITDEPTH">BITDEPTH</a></td>
<td class="summary"><a href="https://en.wikipedia.org/wiki/Audio_bit_depth">Bit depth</a> constants
(use the number values directly, these are just for lookup)</td>
</tr>
<tr>
<td class="name" nowrap><a href="#ENDIANNESS">ENDIANNESS</a></td>
<td class="summary"><a href="https://en.wikipedia.org/wiki/Endianness">Endianness</a> constants</td>
</tr>
</table>
<h2><a href="#Class_Sound">Class Sound </a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#sfxr.Sound:__init">sfxr.Sound:__init ()</a></td>
<td class="summary">Initialize the Sound instance.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#self.vibrato">self.vibrato</a></td>
<td class="summary"><strong>A <a href="https://en.wikipedia.org/wiki/Vibrato">vibrato</a>-like amplitude
modulation effect</strong>
SerializationVibrato</td>
</tr>
<tr>
<td class="name" nowrap><a href="#sfxr.Sound:resetParameters">sfxr.Sound:resetParameters ()</a></td>
<td class="summary">Set all parameters to their default values.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#sfxr.Sound:sanitizeParameters">sfxr.Sound:sanitizeParameters ()</a></td>
<td class="summary">Clamp all parameters within their sane ranges.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#sfxr.Sound:generate">sfxr.Sound:generate ([rate=44100[, depth=0]])</a></td>
<td class="summary">Generate the sound and yield the sample data.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#sfxr.Sound:getEnvelopeLimit">sfxr.Sound:getEnvelopeLimit ([rate=44100])</a></td>
<td class="summary">Get the maximum sample limit allowed by the current envelope.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#sfxr.Sound:generateTable">sfxr.Sound:generateTable ([rate=44100[, depth=0[, tab]]])</a></td>
<td class="summary">Generate the sound into a table.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#sfxr.Sound:generateString">sfxr.Sound:generateString ([rate=44100[, depth=16[, endianness=0]]])</a></td>
<td class="summary">Generate the sound to a binary string.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#sfxr.Sound:generateSoundData">sfxr.Sound:generateSoundData ([rate=44100[, depth=0[, sounddata]]])</a></td>
<td class="summary">Synthesize the sound to a LÖVE SoundData instance.</td>
</tr>
</table>
<h2><a href="#Parameters">Parameters</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#self.supersampling">self.supersampling</a></td>
<td class="summary">Number of supersampling passes to perform (<em>default</em> 8)</td>
</tr>
<tr>
<td class="name" nowrap><a href="#self.repeatspeed">self.repeatspeed</a></td>
<td class="summary">Repeat speed:
Times to repeat the frequency slide over the course of the envelope
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)</td>
</tr>
<tr>
<td class="name" nowrap><a href="#self.waveform">self.waveform</a></td>
<td class="summary">The base <a href="index.html#WAVEFORM">waveform</a> (<em>default</em> <a href="index.html#WAVEFORM">SQUARE</a>)</td>
</tr>
</table>
<h2><a href="#Volume">Volume</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#self.volume">self.volume</a></td>
<td class="summary"><strong>The sound volume and gain all samples are multiplied with</strong></td>
</tr>
<tr>
<td class="name" nowrap><a href="#self.volume.master">self.volume.master</a></td>
<td class="summary">Master volume (<em>default</em> 0.5)</td>
</tr>
<tr>
<td class="name" nowrap><a href="#self.volume.sound">self.volume.sound</a></td>
<td class="summary">Additional gain (<em>default</em> 0.5)</td>
</tr>
</table>
<h2><a href="#Envelope">Envelope</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#self.envelope">self.envelope</a></td>
<td class="summary"><strong>The <a href="https://en.wikipedia.org/wiki/Synthesizer#Attack_
Decay_Sustain_Release_.28ADSR.29_envelope">ASD envelope</a> that controls the sound
amplitude (volume) over time</strong></td>
</tr>
<tr>
<td class="name" nowrap><a href="#self.envelope.attack">self.envelope.attack</a></td>
<td class="summary">Attack time:
Time the sound takes to reach its peak amplitude
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)</td>
</tr>
<tr>
<td class="name" nowrap><a href="#self.envelope.sustain">self.envelope.sustain</a></td>
<td class="summary">Sustain time:
Time the sound stays on its peak amplitude
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)</td>
</tr>
<tr>
<td class="name" nowrap><a href="#self.envelope.punch">self.envelope.punch</a></td>
<td class="summary">Sustain punch:
Amount by which the sound peak amplitude is increased at the start of the
sustain time
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)</td>
</tr>
<tr>
<td class="name" nowrap><a href="#self.envelope.decay">self.envelope.decay</a></td>
<td class="summary">Decay time:
Time the sound takes to decay after its sustain time
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)</td>
</tr>
</table>
<h2><a href="#Frequency">Frequency</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#self.frequency">self.frequency</a></td>
<td class="summary"><strong>The base and minimum frequencies of the tone generator and their
slides</strong></td>
</tr>
<tr>
<td class="name" nowrap><a href="#self.frequency.start">self.frequency.start</a></td>
<td class="summary">Start frequency:
Base tone of the sound, before sliding
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)</td>
</tr>
<tr>
<td class="name" nowrap><a href="#self.frequency.min">self.frequency.min</a></td>
<td class="summary">Min frequency:
Tone below which the sound will get cut off
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)</td>
</tr>
<tr>
<td class="name" nowrap><a href="#self.frequency.slide">self.frequency.slide</a></td>
<td class="summary">Slide:
Amount by which the frequency is increased or decreased over time
(<em>default</em> 0.0, <em>min</em> -1.0, <em>max</em> 1.0)</td>
</tr>
<tr>
<td class="name" nowrap><a href="#self.frequency.dslide">self.frequency.dslide</a></td>
<td class="summary">Delta slide:
Amount by which the slide is increased or decreased over time
(<em>default</em> 0.0, <em>min</em> -1.0, <em>max</em> 1.0)</td>
</tr>
</table>
<h2><a href="#Change">Change</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#self.change">self.change</a></td>
<td class="summary"><strong>Changes the frequency mid-sound to create a characteristic
"coin"-effect</strong></td>
</tr>
<tr>
<td class="name" nowrap><a href="#self.change.amount">self.change.amount</a></td>
<td class="summary">Change amount:
Amount by which the frequency is changed mid-sound
(<em>default</em> 0.0, <em>min</em> -1.0, <em>max</em> 1.0)</td>
</tr>
<tr>
<td class="name" nowrap><a href="#self.change.speed">self.change.speed</a></td>
<td class="summary">Change speed:
Time before the frequency change happens
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)</td>
</tr>
</table>
<h2><a href="#Duty">Duty</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#self.duty">self.duty</a></td>
<td class="summary"><strong>The <a href="https://en.wikipedia.org/wiki/Duty_cycle">duty</a> of the square
waveform</strong></td>
</tr>
<tr>
<td class="name" nowrap><a href="#self.duty.ratio">self.duty.ratio</a></td>
<td class="summary">Square duty:
Width of the square wave pulse cycle (doesn't affect other waveforms)
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)</td>
</tr>
<tr>
<td class="name" nowrap><a href="#self.duty.sweep">self.duty.sweep</a></td>
<td class="summary">Duty sweep:
Amount by which the square duty is increased or decreased over time
(<em>default</em> 0.0, <em>min</em> -1.0, <em>max</em> 1.0)</td>
</tr>
</table>
<h2><a href="#Phaser">Phaser</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#self.phaser">self.phaser</a></td>
<td class="summary"><strong>A simple <a href="https://en.wikipedia.org/wiki/Phaser_(effect">phaser</a>
effect</strong></td>
</tr>
<tr>
<td class="name" nowrap><a href="#self.phaser.offset">self.phaser.offset</a></td>
<td class="summary">Phaser offset:
Amount by which the phaser signal is offset from the sound
(<em>default</em> 0.0, <em>min</em> -1.0, <em>max</em> 1.0)</td>
</tr>
<tr>
<td class="name" nowrap><a href="#self.phaser.sweep">self.phaser.sweep</a></td>
<td class="summary">Phaser sweep:
Amount by which the phaser offset is increased or decreased over time
(<em>default</em> 0.0, <em>min</em> -1.0, <em>max</em> 1.0)</td>
</tr>
</table>
<h2><a href="#Lowpass">Lowpass</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#self.lowpass">self.lowpass</a></td>
<td class="summary"><strong>A <a href="https://en.wikipedia.org/wiki/Low-pass_filter">lowpass filter</a>
effect</strong></td>
</tr>
<tr>
<td class="name" nowrap><a href="#self.lowpass.cutoff">self.lowpass.cutoff</a></td>
<td class="summary">Lowpass filter cutoff:
Lower bound for frequencies allowed to pass through this filter
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)</td>
</tr>
<tr>
<td class="name" nowrap><a href="#self.lowpass.sweep">self.lowpass.sweep</a></td>
<td class="summary">Lowpass filter cutoff sweep:
Amount by which the LP filter cutoff is increased or decreased
over time
(<em>default</em> 0.0, <em>min</em> -1.0, <em>max</em> 1.0)</td>
</tr>
<tr>
<td class="name" nowrap><a href="#self.lowpass.resonance">self.lowpass.resonance</a></td>
<td class="summary">Lowpass filter resonance:
Amount by which certain resonant frequencies near the cutoff are
increased
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)</td>
</tr>
</table>
<h2><a href="#Highpass">Highpass</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#self.highpass">self.highpass</a></td>
<td class="summary"><strong>A <a href="https://en.wikipedia.org/wiki/High-pass_filter">highpass filter</a>
effect</strong></td>
</tr>
<tr>
<td class="name" nowrap><a href="#self.highpass.cutoff">self.highpass.cutoff</a></td>
<td class="summary">Highpass filter cutoff:
Upper bound for frequencies allowed to pass through this filter
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)</td>
</tr>
<tr>
<td class="name" nowrap><a href="#self.highpass.sweep">self.highpass.sweep</a></td>
<td class="summary">Highpass filter cutoff sweep:
Amount by which the HP filter cutoff is increased or decreased
over time
(<em>default</em> 0.0, <em>min</em> -1.0, <em>max</em> 1.0)</td>
</tr>
</table>
<h2><a href="#Vibrato">Vibrato</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#self.vibrato.depth">self.vibrato.depth</a></td>
<td class="summary">Vibrato depth:
Amount of amplitude modulation
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)</td>
</tr>
<tr>
<td class="name" nowrap><a href="#self.vibrato.speed">self.vibrato.speed</a></td>
<td class="summary">Vibrato speed:
Oscillation speed of the vibrato
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)</td>
</tr>
<tr>
<td class="name" nowrap><a href="#self.vibrato.delay">self.vibrato.delay</a></td>
<td class="summary">Vibrato delay:
Unused and unimplemented
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)</td>
</tr>
</table>
<h2><a href="#Randomization">Randomization</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#sfxr.Sound:randomize">sfxr.Sound:randomize ([seed])</a></td>
<td class="summary">Randomize all sound parameters</td>
</tr>
<tr>
<td class="name" nowrap><a href="#sfxr.Sound:mutate">sfxr.Sound:mutate ([amount=1][, seed], changefreq)</a></td>
<td class="summary">Mutate all sound parameters</td>
</tr>
<tr>
<td class="name" nowrap><a href="#sfxr.Sound:randomPickup">sfxr.Sound:randomPickup ([seed])</a></td>
<td class="summary">Randomize all sound parameters to generate a "pick up" sound</td>
</tr>
<tr>
<td class="name" nowrap><a href="#sfxr.Sound:randomLaser">sfxr.Sound:randomLaser ([seed])</a></td>
<td class="summary">Randomize all sound parameters to generate a laser sound</td>
</tr>
<tr>
<td class="name" nowrap><a href="#sfxr.Sound:randomExplosion">sfxr.Sound:randomExplosion ([seed])</a></td>
<td class="summary">Randomize all sound parameters to generate an explosion sound</td>
</tr>
<tr>
<td class="name" nowrap><a href="#sfxr.Sound:randomPowerup">sfxr.Sound:randomPowerup ([seed])</a></td>
<td class="summary">Randomize all sound parameters to generate a "power up" sound</td>
</tr>
<tr>
<td class="name" nowrap><a href="#sfxr.Sound:randomHit">sfxr.Sound:randomHit ([seed])</a></td>
<td class="summary">Randomize all sound parameters to generate a hit sound</td>
</tr>
<tr>
<td class="name" nowrap><a href="#sfxr.Sound:randomJump">sfxr.Sound:randomJump ([seed])</a></td>
<td class="summary">Randomize all sound parameters to generate a jump sound</td>
</tr>
<tr>
<td class="name" nowrap><a href="#sfxr.Sound:randomBlip">sfxr.Sound:randomBlip ([seed])</a></td>
<td class="summary">Randomize all sound parameters to generate a "blip" sound</td>
</tr>
</table>
<h2><a href="#Serialization">Serialization</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#sfxr.Sound:exportWAV">sfxr.Sound:exportWAV (f[, rate=44100[, depth=0]])</a></td>
<td class="summary">Generate and export the audio data to a PCM WAVE file.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#sfxr.Sound:save">sfxr.Sound:save (f[, minify=true])</a></td>
<td class="summary">Save the sound parameters to a file as a Lua table</td>
</tr>
<tr>
<td class="name" nowrap><a href="#sfxr.Sound:load">sfxr.Sound:load (f)</a></td>
<td class="summary">Load the sound parameters from a file containing a Lua table</td>
</tr>
<tr>
<td class="name" nowrap><a href="#sfxr.Sound:saveBinary">sfxr.Sound:saveBinary (f)</a></td>
<td class="summary">Save the sound parameters to a file in the sfxr binary format (version 102)</td>
</tr>
<tr>
<td class="name" nowrap><a href="#sfxr.Sound:loadBinary">sfxr.Sound:loadBinary (f)</a></td>
<td class="summary">Load the sound parameters from a file in the sfxr binary format
(version 100-102)</td>
</tr>
</table>
<br/>
<br/>
<h2 class="section-header "><a name="Functions"></a>Functions</h2>
<dl class="function">
<dt>
<a name = "newSound"></a>
<strong>newSound (...)</strong>
</dt>
<dd>
Construct and return a new <a href="index.html#Sound">Sound</a> instance.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">...</span>
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="index.html#Sound">Sound</a></span>
a Sound instance
</ol>
</dd>
</dl>
<h2 class="section-header "><a name="Constants"></a>Constants</h2>
<dl class="function">
<dt>
<a name = "VERSION"></a>
<strong>VERSION</strong>
</dt>
<dd>
The module version (SemVer format)
</dd>
<dt>
<a name = "WAVEFORM"></a>
<strong>WAVEFORM</strong>
</dt>
<dd>
<a href="https://en.wikipedia.org/wiki/Waveform">Waveform</a> constants
<h3>Fields:</h3>
<ul>
<li><span class="parameter">SQUARE</span>
<a href="https://en.wikipedia.org/wiki/Square_wave">square wave</a> (<code>= 0</code>)
</li>
<li><span class="parameter">SAW</span>
<a href="https://en.wikipedia.org/wiki/Sawtooth_wave">saw wave</a> (<code>= 1</code>)
</li>
<li><span class="parameter">SINE</span>
<a href="https://en.wikipedia.org/wiki/Sine_wave">sine wave</a> (<code>= 2</code>)
</li>
<li><span class="parameter">NOISE</span>
<a href="https://en.wikipedia.org/wiki/White_noise">white noise</a> (<code>= 3</code>)
</li>
</ul>
</dd>
<dt>
<a name = "SAMPLERATE"></a>
<strong>SAMPLERATE</strong>
</dt>
<dd>
<a href="https://en.wikipedia.org/wiki/Sampling_(signal_processing">Sampling rate</a> constants
(use the number values directly, these are just for lookup)
<h3>Fields:</h3>
<ul>
<li><span class="parameter">22050</span>
22.05 kHz (<code>= 22050</code>)
</li>
<li><span class="parameter">44100</span>
44.1 kHz (<code>= 44100</code>)
</li>
</ul>
</dd>
<dt>
<a name = "BITDEPTH"></a>
<strong>BITDEPTH</strong>
</dt>
<dd>
<a href="https://en.wikipedia.org/wiki/Audio_bit_depth">Bit depth</a> constants
(use the number values directly, these are just for lookup)
<h3>Fields:</h3>
<ul>
<li><span class="parameter">0</span>
floating point bit depth, -1 to 1 (<code>= 0</code>)
</li>
<li><span class="parameter">8</span>
unsigned 8 bit, 0x00 to 0xFF (<code>= 8</code>)
</li>
<li><span class="parameter">16</span>
unsigned 16 bit, 0x0000 to 0xFFFF (<code>= 16</code>)
</li>
</ul>
</dd>
<dt>
<a name = "ENDIANNESS"></a>
<strong>ENDIANNESS</strong>
</dt>
<dd>
<a href="https://en.wikipedia.org/wiki/Endianness">Endianness</a> constants
<h3>Fields:</h3>
<ul>
<li><span class="parameter">LITTLE</span>
little endian (<code>= 0</code>)
</li>
<li><span class="parameter">BIG</span>
big endian (<code>= 1</code>)
</li>
</ul>
</dd>
</dl>
<h2 class="section-header has-description"><a name="Class_Sound"></a>Class Sound </h2>
<div class="section-description">
The main Sound class.
</div>
<dl class="function">
<dt>
<a name = "sfxr.Sound:__init"></a>
<strong>sfxr.Sound:__init ()</strong>
</dt>
<dd>
Initialize the Sound instance.
Called by <a href="index.html#newSound">the constructor</a>.
</dd>
<dt>
<a name = "self.vibrato"></a>
<strong>self.vibrato</strong>
</dt>
<dd>
<strong>A <a href="https://en.wikipedia.org/wiki/Vibrato">vibrato</a>-like amplitude
modulation effect</strong>
SerializationVibrato
</dd>
<dt>
<a name = "sfxr.Sound:resetParameters"></a>
<strong>sfxr.Sound:resetParameters ()</strong>
</dt>
<dd>
Set all parameters to their default values. Does not affect
<a href="index.html#self.supersampling">supersampling</a> and <a href="index.html#self.volume">volume</a>.
Called by <a href="index.html#sfxr.Sound:__init">the initializer</a>.
</dd>
<dt>
<a name = "sfxr.Sound:sanitizeParameters"></a>
<strong>sfxr.Sound:sanitizeParameters ()</strong>
</dt>
<dd>
Clamp all parameters within their sane ranges.
</dd>
<dt>
<a name = "sfxr.Sound:generate"></a>
<strong>sfxr.Sound:generate ([rate=44100[, depth=0]])</strong>
</dt>
<dd>
Generate the sound and yield the sample data.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">rate</span>
<span class="types"><a class="type" href="index.html#SAMPLERATE">SAMPLERATE</a></span>
the sampling rate
(<em>default</em> 44100)
</li>
<li><span class="parameter">depth</span>
<span class="types"><a class="type" href="index.html#BITDEPTH">BITDEPTH</a></span>
the bit depth
(<em>default</em> 0)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">function()</span></span>
a generator that yields the next sample when called
</ol>
<h3>Raises:</h3>
"invalid sampling rate: x", "invalid bit depth: x"
<h3>Usage:</h3>
<ul>
<pre class="example"> <span class="keyword">for</span> s <span class="keyword">in</span> sound:generate(<span class="number">44100</span>, <span class="number">0</span>) <span class="keyword">do</span>
<span class="comment">-- do something with s
</span> <span class="keyword">end</span></pre>
</ul>
</dd>
<dt>
<a name = "sfxr.Sound:getEnvelopeLimit"></a>
<strong>sfxr.Sound:getEnvelopeLimit ([rate=44100])</strong>
</dt>
<dd>
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.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">rate</span>
<span class="types"><a class="type" href="index.html#SAMPLERATE">SAMPLERATE</a></span>
the sampling rate
(<em>default</em> 44100)
</li>
</ul>
<h3>Raises:</h3>
"invalid sampling rate: x", "invalid bit depth: x"
</dd>
<dt>
<a name = "sfxr.Sound:generateTable"></a>
<strong>sfxr.Sound:generateTable ([rate=44100[, depth=0[, tab]]])</strong>
</dt>
<dd>
Generate the sound into a table.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">rate</span>
<span class="types"><a class="type" href="index.html#SAMPLERATE">SAMPLERATE</a></span>
the sampling rate
(<em>default</em> 44100)
</li>
<li><span class="parameter">depth</span>
<span class="types"><a class="type" href="index.html#BITDEPTH">BITDEPTH</a></span>
the bit depth
(<em>default</em> 0)
</li>
<li><span class="parameter">tab</span>
<span class="types"><span class="type">{}</span></span>
the table to synthesize into
(<em>optional</em>)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<li>
<span class="types"><span class="type">{number,...}</span></span>
the table filled with sample data</li>
<li>
<span class="types"><span class="type">int</span></span>
the number of written samples (== #tab)</li>
</ol>
<h3>Raises:</h3>
"invalid sampling rate: x", "invalid bit depth: x"
</dd>
<dt>
<a name = "sfxr.Sound:generateString"></a>
<strong>sfxr.Sound:generateString ([rate=44100[, depth=16[, endianness=0]]])</strong>
</dt>
<dd>
Generate the sound to a binary string.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">rate</span>
<span class="types"><a class="type" href="index.html#SAMPLERATE">SAMPLERATE</a></span>
the sampling rate
(<em>default</em> 44100)
</li>
<li><span class="parameter">depth</span>
<span class="types"><a class="type" href="index.html#BITDEPTH">BITDEPTH</a></span>
the bit depth (may not be <a href="index.html#BITDEPTH">0</a>)
(<em>default</em> 16)
</li>
<li><span class="parameter">endianness</span>
<span class="types"><a class="type" href="index.html#ENDIANNESS">ENDIANNESS</a></span>
the endianness (ignored when depth == 8)
(<em>default</em> 0)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<li>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
a binary string of sample data</li>
<li>
<span class="types"><span class="type">int</span></span>
the number of written samples</li>
</ol>
<h3>Raises:</h3>
"invalid sampling rate: x", "invalid bit depth: x", "invalid endianness: x"
</dd>
<dt>
<a name = "sfxr.Sound:generateSoundData"></a>
<strong>sfxr.Sound:generateSoundData ([rate=44100[, depth=0[, sounddata]]])</strong>
</dt>
<dd>
Synthesize the sound to a LÖVE SoundData instance.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">rate</span>
<span class="types"><a class="type" href="index.html#SAMPLERATE">SAMPLERATE</a></span>
the sampling rate
(<em>default</em> 44100)
</li>
<li><span class="parameter">depth</span>
<span class="types"><a class="type" href="index.html#BITDEPTH">BITDEPTH</a></span>
the bit depth
(<em>default</em> 0)
</li>
<li><span class="parameter">sounddata</span>
<span class="types"><span class="type">love.sound.SoundData</span></span>
a SoundData instance (will be
created if not passed)
(<em>optional</em>)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<li>
<span class="types"><span class="type">love.sound.SoundData</span></span>
a SoundData instance</li>
<li>
<span class="types"><span class="type">int</span></span>
the number of written samples</li>
</ol>
<h3>Raises:</h3>
"invalid sampling rate: x", "invalid bit depth: x"
</dd>
</dl>
<h2 class="section-header "><a name="Parameters"></a>Parameters</h2>
<dl class="function">
<dt>
<a name = "self.supersampling"></a>
<strong>self.supersampling</strong>
</dt>
<dd>
Number of supersampling passes to perform (<em>default</em> 8)
</dd>
<dt>
<a name = "self.repeatspeed"></a>
<strong>self.repeatspeed</strong>
</dt>
<dd>
Repeat speed:
Times to repeat the frequency slide over the course of the envelope
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)
</dd>
<dt>
<a name = "self.waveform"></a>
<strong>self.waveform</strong>
</dt>
<dd>
The base <a href="index.html#WAVEFORM">waveform</a> (<em>default</em> <a href="index.html#WAVEFORM">SQUARE</a>)
</dd>
</dl>
<h2 class="section-header "><a name="Volume"></a>Volume</h2>
<dl class="function">
<dt>
<a name = "self.volume"></a>
<strong>self.volume</strong>
</dt>
<dd>
<strong>The sound volume and gain all samples are multiplied with</strong>
</dd>
<dt>
<a name = "self.volume.master"></a>
<strong>self.volume.master</strong>
</dt>
<dd>
Master volume (<em>default</em> 0.5)
</dd>
<dt>
<a name = "self.volume.sound"></a>
<strong>self.volume.sound</strong>
</dt>
<dd>
Additional gain (<em>default</em> 0.5)
</dd>
</dl>
<h2 class="section-header "><a name="Envelope"></a>Envelope</h2>
<dl class="function">
<dt>
<a name = "self.envelope"></a>
<strong>self.envelope</strong>
</dt>
<dd>
<strong>The <a href="https://en.wikipedia.org/wiki/Synthesizer#Attack_
Decay_Sustain_Release_.28ADSR.29_envelope">ASD envelope</a> that controls the sound
amplitude (volume) over time</strong>
</dd>
<dt>
<a name = "self.envelope.attack"></a>
<strong>self.envelope.attack</strong>
</dt>
<dd>
Attack time:
Time the sound takes to reach its peak amplitude
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)
</dd>
<dt>
<a name = "self.envelope.sustain"></a>
<strong>self.envelope.sustain</strong>
</dt>
<dd>
Sustain time:
Time the sound stays on its peak amplitude
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)
</dd>
<dt>
<a name = "self.envelope.punch"></a>
<strong>self.envelope.punch</strong>
</dt>
<dd>
Sustain punch:
Amount by which the sound peak amplitude is increased at the start of the
sustain time
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)
</dd>
<dt>
<a name = "self.envelope.decay"></a>
<strong>self.envelope.decay</strong>
</dt>
<dd>
Decay time:
Time the sound takes to decay after its sustain time
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)
</dd>
</dl>
<h2 class="section-header "><a name="Frequency"></a>Frequency</h2>
<dl class="function">
<dt>
<a name = "self.frequency"></a>
<strong>self.frequency</strong>
</dt>
<dd>
<strong>The base and minimum frequencies of the tone generator and their
slides</strong>
</dd>
<dt>
<a name = "self.frequency.start"></a>
<strong>self.frequency.start</strong>
</dt>
<dd>
Start frequency:
Base tone of the sound, before sliding
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)
</dd>
<dt>
<a name = "self.frequency.min"></a>
<strong>self.frequency.min</strong>
</dt>
<dd>
Min frequency:
Tone below which the sound will get cut off
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)
</dd>
<dt>
<a name = "self.frequency.slide"></a>
<strong>self.frequency.slide</strong>
</dt>
<dd>
Slide:
Amount by which the frequency is increased or decreased over time
(<em>default</em> 0.0, <em>min</em> -1.0, <em>max</em> 1.0)
</dd>
<dt>
<a name = "self.frequency.dslide"></a>
<strong>self.frequency.dslide</strong>
</dt>
<dd>
Delta slide:
Amount by which the slide is increased or decreased over time
(<em>default</em> 0.0, <em>min</em> -1.0, <em>max</em> 1.0)
</dd>
</dl>
<h2 class="section-header "><a name="Change"></a>Change</h2>
<dl class="function">
<dt>
<a name = "self.change"></a>
<strong>self.change</strong>
</dt>
<dd>
<strong>Changes the frequency mid-sound to create a characteristic
"coin"-effect</strong>
</dd>
<dt>
<a name = "self.change.amount"></a>
<strong>self.change.amount</strong>
</dt>
<dd>
Change amount:
Amount by which the frequency is changed mid-sound
(<em>default</em> 0.0, <em>min</em> -1.0, <em>max</em> 1.0)
</dd>
<dt>
<a name = "self.change.speed"></a>
<strong>self.change.speed</strong>
</dt>
<dd>
Change speed:
Time before the frequency change happens
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)
</dd>
</dl>
<h2 class="section-header "><a name="Duty"></a>Duty</h2>
<dl class="function">
<dt>
<a name = "self.duty"></a>
<strong>self.duty</strong>
</dt>
<dd>
<strong>The <a href="https://en.wikipedia.org/wiki/Duty_cycle">duty</a> of the square
waveform</strong>
</dd>
<dt>
<a name = "self.duty.ratio"></a>
<strong>self.duty.ratio</strong>
</dt>
<dd>
Square duty:
Width of the square wave pulse cycle (doesn't affect other waveforms)
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)
</dd>
<dt>
<a name = "self.duty.sweep"></a>
<strong>self.duty.sweep</strong>
</dt>
<dd>
Duty sweep:
Amount by which the square duty is increased or decreased over time
(<em>default</em> 0.0, <em>min</em> -1.0, <em>max</em> 1.0)
</dd>
</dl>
<h2 class="section-header "><a name="Phaser"></a>Phaser</h2>
<dl class="function">
<dt>
<a name = "self.phaser"></a>
<strong>self.phaser</strong>
</dt>
<dd>
<strong>A simple <a href="https://en.wikipedia.org/wiki/Phaser_(effect">phaser</a>
effect</strong>
</dd>
<dt>
<a name = "self.phaser.offset"></a>
<strong>self.phaser.offset</strong>
</dt>
<dd>
Phaser offset:
Amount by which the phaser signal is offset from the sound
(<em>default</em> 0.0, <em>min</em> -1.0, <em>max</em> 1.0)
</dd>
<dt>
<a name = "self.phaser.sweep"></a>
<strong>self.phaser.sweep</strong>
</dt>
<dd>
Phaser sweep:
Amount by which the phaser offset is increased or decreased over time
(<em>default</em> 0.0, <em>min</em> -1.0, <em>max</em> 1.0)
</dd>
</dl>
<h2 class="section-header "><a name="Lowpass"></a>Lowpass</h2>
<dl class="function">
<dt>
<a name = "self.lowpass"></a>
<strong>self.lowpass</strong>
</dt>
<dd>
<strong>A <a href="https://en.wikipedia.org/wiki/Low-pass_filter">lowpass filter</a>
effect</strong>
</dd>
<dt>
<a name = "self.lowpass.cutoff"></a>
<strong>self.lowpass.cutoff</strong>
</dt>
<dd>
Lowpass filter cutoff:
Lower bound for frequencies allowed to pass through this filter
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)
</dd>
<dt>
<a name = "self.lowpass.sweep"></a>
<strong>self.lowpass.sweep</strong>
</dt>
<dd>
Lowpass filter cutoff sweep:
Amount by which the LP filter cutoff is increased or decreased
over time
(<em>default</em> 0.0, <em>min</em> -1.0, <em>max</em> 1.0)
</dd>
<dt>
<a name = "self.lowpass.resonance"></a>
<strong>self.lowpass.resonance</strong>
</dt>
<dd>
Lowpass filter resonance:
Amount by which certain resonant frequencies near the cutoff are
increased
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)
</dd>
</dl>
<h2 class="section-header "><a name="Highpass"></a>Highpass</h2>
<dl class="function">
<dt>
<a name = "self.highpass"></a>
<strong>self.highpass</strong>
</dt>
<dd>
<strong>A <a href="https://en.wikipedia.org/wiki/High-pass_filter">highpass filter</a>
effect</strong>
</dd>
<dt>
<a name = "self.highpass.cutoff"></a>
<strong>self.highpass.cutoff</strong>
</dt>
<dd>
Highpass filter cutoff:
Upper bound for frequencies allowed to pass through this filter
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)
</dd>
<dt>
<a name = "self.highpass.sweep"></a>
<strong>self.highpass.sweep</strong>
</dt>
<dd>
Highpass filter cutoff sweep:
Amount by which the HP filter cutoff is increased or decreased
over time
(<em>default</em> 0.0, <em>min</em> -1.0, <em>max</em> 1.0)
</dd>
</dl>
<h2 class="section-header "><a name="Vibrato"></a>Vibrato</h2>
<dl class="function">
<dt>
<a name = "self.vibrato.depth"></a>
<strong>self.vibrato.depth</strong>
</dt>
<dd>
Vibrato depth:
Amount of amplitude modulation
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)
</dd>
<dt>
<a name = "self.vibrato.speed"></a>
<strong>self.vibrato.speed</strong>
</dt>
<dd>
Vibrato speed:
Oscillation speed of the vibrato
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)
</dd>
<dt>
<a name = "self.vibrato.delay"></a>
<strong>self.vibrato.delay</strong>
</dt>
<dd>
Vibrato delay:
Unused and unimplemented
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)
</dd>
</dl>
<h2 class="section-header "><a name="Randomization"></a>Randomization</h2>
<dl class="function">
<dt>
<a name = "sfxr.Sound:randomize"></a>
<strong>sfxr.Sound:randomize ([seed])</strong>
</dt>
<dd>
Randomize all sound parameters
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">seed</span>
<span class="types"><span class="type">number</span></span>
a random seed
(<em>optional</em>)
</li>
</ul>
</dd>
<dt>
<a name = "sfxr.Sound:mutate"></a>
<strong>sfxr.Sound:mutate ([amount=1][, seed], changefreq)</strong>
</dt>
<dd>
Mutate all sound parameters
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">amount</span>
<span class="types"><span class="type">number</span></span>
by how much to mutate the parameters
(<em>default</em> 1)
</li>
<li><span class="parameter">seed</span>
<span class="types"><span class="type">number</span></span>
a random seed
(<em>optional</em>)
</li>
<li><span class="parameter">changefreq</span>
<span class="types"><span class="type">bool</span></span>
whether to change the frequency parameters
</li>
</ul>
</dd>
<dt>
<a name = "sfxr.Sound:randomPickup"></a>
<strong>sfxr.Sound:randomPickup ([seed])</strong>
</dt>
<dd>
Randomize all sound parameters to generate a "pick up" sound
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">seed</span>
<span class="types"><span class="type">number</span></span>
a random seed
(<em>optional</em>)
</li>
</ul>
</dd>
<dt>
<a name = "sfxr.Sound:randomLaser"></a>
<strong>sfxr.Sound:randomLaser ([seed])</strong>
</dt>
<dd>
Randomize all sound parameters to generate a laser sound
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">seed</span>
<span class="types"><span class="type">number</span></span>
a random seed
(<em>optional</em>)
</li>
</ul>
</dd>
<dt>
<a name = "sfxr.Sound:randomExplosion"></a>
<strong>sfxr.Sound:randomExplosion ([seed])</strong>
</dt>
<dd>
Randomize all sound parameters to generate an explosion sound
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">seed</span>
<span class="types"><span class="type">number</span></span>
a random seed
(<em>optional</em>)
</li>
</ul>
</dd>
<dt>
<a name = "sfxr.Sound:randomPowerup"></a>
<strong>sfxr.Sound:randomPowerup ([seed])</strong>
</dt>
<dd>
Randomize all sound parameters to generate a "power up" sound
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">seed</span>
<span class="types"><span class="type">number</span></span>
a random seed
(<em>optional</em>)
</li>
</ul>
</dd>
<dt>
<a name = "sfxr.Sound:randomHit"></a>
<strong>sfxr.Sound:randomHit ([seed])</strong>
</dt>
<dd>
Randomize all sound parameters to generate a hit sound
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">seed</span>
<span class="types"><span class="type">number</span></span>
a random seed
(<em>optional</em>)
</li>
</ul>
</dd>
<dt>
<a name = "sfxr.Sound:randomJump"></a>
<strong>sfxr.Sound:randomJump ([seed])</strong>
</dt>
<dd>
Randomize all sound parameters to generate a jump sound
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">seed</span>
<span class="types"><span class="type">number</span></span>
a random seed
(<em>optional</em>)
</li>
</ul>
</dd>
<dt>
<a name = "sfxr.Sound:randomBlip"></a>
<strong>sfxr.Sound:randomBlip ([seed])</strong>
</dt>
<dd>
Randomize all sound parameters to generate a "blip" sound
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">seed</span>
<span class="types"><span class="type">number</span></span>
a random seed
(<em>optional</em>)
</li>
</ul>
</dd>
</dl>
<h2 class="section-header "><a name="Serialization"></a>Serialization</h2>
<dl class="function">
<dt>
<a name = "sfxr.Sound:exportWAV"></a>
<strong>sfxr.Sound:exportWAV (f[, rate=44100[, depth=0]])</strong>
</dt>
<dd>
Generate and export the audio data to a PCM WAVE file.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">f</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a>, <span class="type">file</span> or <span class="type">love.filesystem.File</span></span>
a path or file in <code>wb</code>-mode
(passed files will not be closed)
</li>
<li><span class="parameter">rate</span>
<span class="types"><a class="type" href="index.html#SAMPLERATE">SAMPLERATE</a></span>
the sampling rate
(<em>default</em> 44100)
</li>
<li><span class="parameter">depth</span>
<span class="types"><a class="type" href="index.html#BITDEPTH">BITDEPTH</a></span>
the bit depth
(<em>default</em> 0)
</li>
</ul>
<h3>Raises:</h3>
"invalid sampling rate: x", "invalid bit depth: x"
</dd>
<dt>
<a name = "sfxr.Sound:save"></a>
<strong>sfxr.Sound:save (f[, minify=true])</strong>
</dt>
<dd>
Save the sound parameters to a file as a Lua table
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">f</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a>, <span class="type">file</span> or <span class="type">love.filesystem.File</span></span>
a path or file in <code>w</code>-mode
(passed files will not be closed)
</li>
<li><span class="parameter">minify</span>
<span class="types"><span class="type">bool</span></span>
whether to minify the output or not
(<em>default</em> true)
</li>
</ul>
</dd>
<dt>
<a name = "sfxr.Sound:load"></a>
<strong>sfxr.Sound:load (f)</strong>
</dt>
<dd>
Load the sound parameters from a file containing a Lua table
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">f</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a>, <span class="type">file</span> or <span class="type">love.filesystem.File</span></span>
a path or file in <code>r</code>-mode
(passed files will not be closed)
</li>
</ul>
<h3>Raises:</h3>
"incompatible version: x.x.x"
</dd>
<dt>
<a name = "sfxr.Sound:saveBinary"></a>
<strong>sfxr.Sound:saveBinary (f)</strong>
</dt>
<dd>
Save the sound parameters to a file in the sfxr binary format (version 102)
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">f</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a>, <span class="type">file</span> or <span class="type">love.filesystem.File</span></span>
a path or file in <code>wb</code>-mode
(passed files will not be closed)
</li>
</ul>
</dd>
<dt>
<a name = "sfxr.Sound:loadBinary"></a>
<strong>sfxr.Sound:loadBinary (f)</strong>
</dt>
<dd>
Load the sound parameters from a file in the sfxr binary format
(version 100-102)
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">f</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a>, <span class="type">file</span> or <span class="type">love.filesystem.File</span></span>
a path or file in <code>rb</code>-mode
(passed files will not be closed)
</li>
</ul>
<h3>Raises:</h3>
"incompatible version: x", "unexpected file length"
</dd>
</dl>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2016-06-12 01:18:55 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>