mirror of
https://github.com/nucular/sfxrlua.git
synced 2024-12-24 18:44:20 +00:00
Fixed some documentation and raised errors
This commit is contained in:
parent
e300cb8548
commit
57ccea261e
@ -113,7 +113,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#self.waveform">self.waveform</a></td>
|
||||
<td class="summary">(<a href="../index.html#WAVEFORM"><em>WAVEFORM</em></a>) The base wave form</td>
|
||||
<td class="summary">The base <a href="../index.html#WAVEFORM">wave form</a> (<em>default</em> <a href="../index.html#WAVEFORM">SQUARE</a>)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#self.envelope.attack">self.envelope.attack</a></td>
|
||||
@ -124,7 +124,7 @@
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#self.envelope.sustain">self.envelope.sustain</a></td>
|
||||
<td class="summary">Sustain time:
|
||||
Time the sound sustains on its peak volume
|
||||
Time the sound stays on its peak volume
|
||||
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@ -272,7 +272,7 @@
|
||||
<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[, a]]])</a></td>
|
||||
<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>
|
||||
<tr>
|
||||
@ -316,7 +316,7 @@
|
||||
<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[, to=true])</a></td>
|
||||
<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>
|
||||
@ -325,11 +325,12 @@
|
||||
</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</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</td>
|
||||
<td class="summary">Load the sound parameters from a file in the sfxr binary format
|
||||
(version 100, 101, 102)</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@ -579,7 +580,7 @@
|
||||
<strong>self.waveform</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
(<a href="../index.html#WAVEFORM"><em>WAVEFORM</em></a>) The base wave form
|
||||
The base <a href="../index.html#WAVEFORM">wave form</a> (<em>default</em> <a href="../index.html#WAVEFORM">SQUARE</a>)
|
||||
|
||||
|
||||
|
||||
@ -610,7 +611,7 @@
|
||||
</dt>
|
||||
<dd>
|
||||
Sustain time:
|
||||
Time the sound sustains on its peak volume
|
||||
Time the sound stays on its peak volume
|
||||
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)
|
||||
|
||||
|
||||
@ -987,6 +988,8 @@
|
||||
a generator that yields the sample data when called
|
||||
</ol>
|
||||
|
||||
<h3>Raises:</h3>
|
||||
"invalid sample rate: x", "invalid bit depth: x"
|
||||
|
||||
|
||||
<h3>Usage:</h3>
|
||||
@ -1017,6 +1020,8 @@
|
||||
</ul>
|
||||
|
||||
|
||||
<h3>Raises:</h3>
|
||||
"invalid sample rate: x", "invalid bit depth: x"
|
||||
|
||||
|
||||
|
||||
@ -1058,6 +1063,8 @@
|
||||
the number of written samples (== #tab)</li>
|
||||
</ol>
|
||||
|
||||
<h3>Raises:</h3>
|
||||
"invalid sample rate: x", "invalid bit depth: x"
|
||||
|
||||
|
||||
|
||||
@ -1099,13 +1106,15 @@
|
||||
the number of written samples</li>
|
||||
</ol>
|
||||
|
||||
<h3>Raises:</h3>
|
||||
"invalid sample 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[, a]]])</strong>
|
||||
<strong>sfxr.Sound:generateSoundData ([rate=44100[, depth=0[, sounddata]]])</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Synthesize the sound to a LÖVE SoundData instance.
|
||||
@ -1123,10 +1132,10 @@
|
||||
the bit depth
|
||||
(<em>default</em> 0)
|
||||
</li>
|
||||
<li><span class="parameter">a</span>
|
||||
<li><span class="parameter">sounddata</span>
|
||||
<span class="types"><span class="type">love.sound.SoundData</span></span>
|
||||
SoundData instance (will be created if
|
||||
not passed)
|
||||
a SoundData instance (will be
|
||||
created if not passed)
|
||||
(<em>optional</em>)
|
||||
</li>
|
||||
</ul>
|
||||
@ -1141,6 +1150,8 @@
|
||||
the number of written samples</li>
|
||||
</ol>
|
||||
|
||||
<h3>Raises:</h3>
|
||||
"invalid sample rate: x", "invalid bit depth: x"
|
||||
|
||||
|
||||
|
||||
@ -1364,7 +1375,8 @@
|
||||
<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 file path, a Lua file object, a love.filesystem.File instance
|
||||
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>
|
||||
@ -1379,13 +1391,15 @@
|
||||
</ul>
|
||||
|
||||
|
||||
<h3>Raises:</h3>
|
||||
"invalid sample rate: x", "invalid bit depth: x"
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
<dt>
|
||||
<a name = "sfxr.Sound:save"></a>
|
||||
<strong>sfxr.Sound:save (f[, to=true])</strong>
|
||||
<strong>sfxr.Sound:save (f[, minify=true])</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Save the sound parameters to a file as a Lua table
|
||||
@ -1395,11 +1409,12 @@
|
||||
<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 file path, a Lua file object, a love.filesystem.File instance
|
||||
a path or file in <code>w</code>-mode
|
||||
(passed files will not be closed)
|
||||
</li>
|
||||
<li><span class="parameter">to</span>
|
||||
<span class="types"><span class="type">whether</span></span>
|
||||
minify the output
|
||||
<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>
|
||||
@ -1421,11 +1436,14 @@
|
||||
<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 file path, a Lua file object, a love.filesystem.File instance
|
||||
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"
|
||||
|
||||
|
||||
|
||||
@ -1435,14 +1453,15 @@
|
||||
<strong>sfxr.Sound:saveBinary (f)</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Save the sound parameters to a file in the sfxr binary format
|
||||
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 file path, a Lua file object, a love.filesystem.File instance
|
||||
a path or file in <code>wb</code>-mode
|
||||
(passed files will not be closed)
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
@ -1457,17 +1476,21 @@
|
||||
</dt>
|
||||
<dd>
|
||||
Load the sound parameters from a file in the sfxr binary format
|
||||
(version 100, 101, 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 file path, a Lua file object, a love.filesystem.File instance
|
||||
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"
|
||||
|
||||
|
||||
|
||||
@ -1479,7 +1502,7 @@
|
||||
</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-03-02 00:35:01 </i>
|
||||
<i style="float:right;">Last updated 2016-03-05 19:36:51 </i>
|
||||
</div> <!-- id="about" -->
|
||||
</div> <!-- id="container" -->
|
||||
</body>
|
||||
|
@ -113,7 +113,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#self.waveform">self.waveform</a></td>
|
||||
<td class="summary">(<a href="index.html#WAVEFORM"><em>WAVEFORM</em></a>) The base wave form</td>
|
||||
<td class="summary">The base <a href="index.html#WAVEFORM">wave form</a> (<em>default</em> <a href="index.html#WAVEFORM">SQUARE</a>)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#self.envelope.attack">self.envelope.attack</a></td>
|
||||
@ -124,7 +124,7 @@
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#self.envelope.sustain">self.envelope.sustain</a></td>
|
||||
<td class="summary">Sustain time:
|
||||
Time the sound sustains on its peak volume
|
||||
Time the sound stays on its peak volume
|
||||
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@ -272,7 +272,7 @@
|
||||
<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[, a]]])</a></td>
|
||||
<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>
|
||||
<tr>
|
||||
@ -316,7 +316,7 @@
|
||||
<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[, to=true])</a></td>
|
||||
<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>
|
||||
@ -325,11 +325,12 @@
|
||||
</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</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</td>
|
||||
<td class="summary">Load the sound parameters from a file in the sfxr binary format
|
||||
(version 100, 101, 102)</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@ -579,7 +580,7 @@
|
||||
<strong>self.waveform</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
(<a href="index.html#WAVEFORM"><em>WAVEFORM</em></a>) The base wave form
|
||||
The base <a href="index.html#WAVEFORM">wave form</a> (<em>default</em> <a href="index.html#WAVEFORM">SQUARE</a>)
|
||||
|
||||
|
||||
|
||||
@ -610,7 +611,7 @@
|
||||
</dt>
|
||||
<dd>
|
||||
Sustain time:
|
||||
Time the sound sustains on its peak volume
|
||||
Time the sound stays on its peak volume
|
||||
(<em>default</em> 0.0, <em>min</em> 0.0, <em>max</em> 1.0)
|
||||
|
||||
|
||||
@ -987,6 +988,8 @@
|
||||
a generator that yields the sample data when called
|
||||
</ol>
|
||||
|
||||
<h3>Raises:</h3>
|
||||
"invalid sample rate: x", "invalid bit depth: x"
|
||||
|
||||
|
||||
<h3>Usage:</h3>
|
||||
@ -1017,6 +1020,8 @@
|
||||
</ul>
|
||||
|
||||
|
||||
<h3>Raises:</h3>
|
||||
"invalid sample rate: x", "invalid bit depth: x"
|
||||
|
||||
|
||||
|
||||
@ -1058,6 +1063,8 @@
|
||||
the number of written samples (== #tab)</li>
|
||||
</ol>
|
||||
|
||||
<h3>Raises:</h3>
|
||||
"invalid sample rate: x", "invalid bit depth: x"
|
||||
|
||||
|
||||
|
||||
@ -1099,13 +1106,15 @@
|
||||
the number of written samples</li>
|
||||
</ol>
|
||||
|
||||
<h3>Raises:</h3>
|
||||
"invalid sample 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[, a]]])</strong>
|
||||
<strong>sfxr.Sound:generateSoundData ([rate=44100[, depth=0[, sounddata]]])</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Synthesize the sound to a LÖVE SoundData instance.
|
||||
@ -1123,10 +1132,10 @@
|
||||
the bit depth
|
||||
(<em>default</em> 0)
|
||||
</li>
|
||||
<li><span class="parameter">a</span>
|
||||
<li><span class="parameter">sounddata</span>
|
||||
<span class="types"><span class="type">love.sound.SoundData</span></span>
|
||||
SoundData instance (will be created if
|
||||
not passed)
|
||||
a SoundData instance (will be
|
||||
created if not passed)
|
||||
(<em>optional</em>)
|
||||
</li>
|
||||
</ul>
|
||||
@ -1141,6 +1150,8 @@
|
||||
the number of written samples</li>
|
||||
</ol>
|
||||
|
||||
<h3>Raises:</h3>
|
||||
"invalid sample rate: x", "invalid bit depth: x"
|
||||
|
||||
|
||||
|
||||
@ -1364,7 +1375,8 @@
|
||||
<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 file path, a Lua file object, a love.filesystem.File instance
|
||||
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>
|
||||
@ -1379,13 +1391,15 @@
|
||||
</ul>
|
||||
|
||||
|
||||
<h3>Raises:</h3>
|
||||
"invalid sample rate: x", "invalid bit depth: x"
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
<dt>
|
||||
<a name = "sfxr.Sound:save"></a>
|
||||
<strong>sfxr.Sound:save (f[, to=true])</strong>
|
||||
<strong>sfxr.Sound:save (f[, minify=true])</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Save the sound parameters to a file as a Lua table
|
||||
@ -1395,11 +1409,12 @@
|
||||
<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 file path, a Lua file object, a love.filesystem.File instance
|
||||
a path or file in <code>w</code>-mode
|
||||
(passed files will not be closed)
|
||||
</li>
|
||||
<li><span class="parameter">to</span>
|
||||
<span class="types"><span class="type">whether</span></span>
|
||||
minify the output
|
||||
<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>
|
||||
@ -1421,11 +1436,14 @@
|
||||
<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 file path, a Lua file object, a love.filesystem.File instance
|
||||
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"
|
||||
|
||||
|
||||
|
||||
@ -1435,14 +1453,15 @@
|
||||
<strong>sfxr.Sound:saveBinary (f)</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Save the sound parameters to a file in the sfxr binary format
|
||||
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 file path, a Lua file object, a love.filesystem.File instance
|
||||
a path or file in <code>wb</code>-mode
|
||||
(passed files will not be closed)
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
@ -1457,17 +1476,21 @@
|
||||
</dt>
|
||||
<dd>
|
||||
Load the sound parameters from a file in the sfxr binary format
|
||||
(version 100, 101, 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 file path, a Lua file object, a love.filesystem.File instance
|
||||
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"
|
||||
|
||||
|
||||
|
||||
@ -1479,7 +1502,7 @@
|
||||
</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-03-02 00:35:01 </i>
|
||||
<i style="float:right;">Last updated 2016-03-05 19:36:51 </i>
|
||||
</div> <!-- id="about" -->
|
||||
</div> <!-- id="container" -->
|
||||
</body>
|
||||
|
74
sfxr.lua
74
sfxr.lua
@ -270,7 +270,7 @@ function sfxr.Sound:resetParameters()
|
||||
-- Times to repeat the frequency slide over the course of the envelope
|
||||
-- (*default* 0.0, *min* 0.0, *max* 1.0)
|
||||
self.repeatspeed = 0.0
|
||||
--- (@{WAVEFORM|*WAVEFORM*}) The base wave form
|
||||
--- The base @{WAVEFORM|wave form} (*default* @{WAVEFORM|SQUARE})
|
||||
self.waveform = sfxr.SQUARE
|
||||
|
||||
--- Attack time:
|
||||
@ -278,7 +278,7 @@ function sfxr.Sound:resetParameters()
|
||||
-- (*default* 0.0, *min* 0.0, *max* 1.0)
|
||||
self.envelope.attack = 0.0
|
||||
--- Sustain time:
|
||||
-- Time the sound sustains on its peak volume
|
||||
-- Time the sound stays on its peak volume
|
||||
-- (*default* 0.0, *min* 0.0, *max* 1.0)
|
||||
self.envelope.sustain = 0.3
|
||||
--- Sustain punch:
|
||||
@ -415,11 +415,12 @@ end
|
||||
-- @usage for s in sound:generate(44100, 0) do
|
||||
-- -- do something with s
|
||||
-- end
|
||||
-- @raise "invalid sample rate: x", "invalid bit depth: x"
|
||||
function sfxr.Sound:generate(rate, depth)
|
||||
rate = rate or 44100
|
||||
depth = depth or 0
|
||||
assert(sfxr.SAMPLERATE[rate], "Invalid sample rate: " .. tostring(rate))
|
||||
assert(sfxr.BITDEPTH[depth], "Invalid bit depth: " .. tostring(depth))
|
||||
assert(sfxr.SAMPLERATE[rate], "invalid sample rate: " .. tostring(rate))
|
||||
assert(sfxr.BITDEPTH[depth], "invalid bit depth: " .. tostring(depth))
|
||||
|
||||
-- Initialize all locals
|
||||
local fperiod, maxperiod
|
||||
@ -691,9 +692,10 @@ end
|
||||
-- Does not take any other limits into account, so the returned count might be
|
||||
-- higher than samples actually generated. Still useful though.
|
||||
-- @tparam[opt=44100] SAMPLERATE rate the sample rate
|
||||
-- @raise "invalid sample rate: x", "invalid bit depth: x"
|
||||
function sfxr.Sound:getEnvelopeLimit(rate)
|
||||
rate = rate or 44100
|
||||
assert(sfxr.SAMPLERATE[rate], "Invalid sample rate: " .. tostring(rate))
|
||||
assert(sfxr.SAMPLERATE[rate], "invalid sample rate: " .. tostring(rate))
|
||||
|
||||
local env_length = {
|
||||
self.envelope.attack^2 * 100000, --- attack
|
||||
@ -711,11 +713,12 @@ end
|
||||
-- @tparam[opt] {} tab the table to synthesize into
|
||||
-- @treturn {number,...} the table filled with sample data
|
||||
-- @treturn int the number of written samples (== #tab)
|
||||
-- @raise "invalid sample rate: x", "invalid bit depth: x"
|
||||
function sfxr.Sound:generateTable(rate, depth, tab)
|
||||
rate = rate or 44100
|
||||
depth = depth or 0
|
||||
assert(sfxr.SAMPLERATE[rate], "Invalid sample rate: " .. tostring(rate))
|
||||
assert(sfxr.BITDEPTH[depth], "Invalid bit depth: " .. tostring(depth))
|
||||
assert(sfxr.SAMPLERATE[rate], "invalid sample rate: " .. tostring(rate))
|
||||
assert(sfxr.BITDEPTH[depth], "invalid bit depth: " .. tostring(depth))
|
||||
|
||||
-- this could really use table pre-allocation, but Lua doesn't provide that
|
||||
local t = tab or {}
|
||||
@ -733,12 +736,13 @@ end
|
||||
-- @tparam[opt=0] ENDIANNESS endianness the endianness (ignored when depth == 8)
|
||||
-- @treturn string a binary string of sample data
|
||||
-- @treturn int the number of written samples
|
||||
-- @raise "invalid sample rate: x", "invalid bit depth: x", "invalid endianness: x"
|
||||
function sfxr.Sound:generateString(rate, depth, endianness)
|
||||
rate = rate or 44100
|
||||
depth = depth or 16
|
||||
assert(sfxr.SAMPLERATE[rate], "Invalid sample rate: " .. tostring(rate))
|
||||
assert(sfxr.BITDEPTH[depth] and depth ~= 0, "Invalid bit depth: " .. tostring(depth))
|
||||
assert(sfxr.ENDIANNESS[endianness], "Invalid endianness: " .. tostring(endianness))
|
||||
assert(sfxr.SAMPLERATE[rate], "invalid sample rate: " .. tostring(rate))
|
||||
assert(sfxr.BITDEPTH[depth] and depth ~= 0, "invalid bit depth: " .. tostring(depth))
|
||||
assert(sfxr.ENDIANNESS[endianness], "invalid endianness: " .. tostring(endianness))
|
||||
|
||||
local s = ""
|
||||
--- buffer for arguments to string.char
|
||||
@ -778,15 +782,16 @@ end
|
||||
--- Synthesize the sound to a LÖVE SoundData instance.
|
||||
-- @tparam[opt=44100] SAMPLERATE rate the sample rate
|
||||
-- @tparam[opt=0] BITDEPTH depth the bit depth
|
||||
-- @tparam[opt] love.sound.SoundData a SoundData instance (will be created if
|
||||
-- not passed)
|
||||
-- @tparam[opt] love.sound.SoundData sounddata a SoundData instance (will be
|
||||
-- created if not passed)
|
||||
-- @treturn love.sound.SoundData a SoundData instance
|
||||
-- @treturn int the number of written samples
|
||||
-- @raise "invalid sample rate: x", "invalid bit depth: x"
|
||||
function sfxr.Sound:generateSoundData(rate, depth, sounddata)
|
||||
rate = rate or 44100
|
||||
depth = depth or 0
|
||||
assert(sfxr.SAMPLERATE[rate], "Invalid sample rate: " .. tostring(rate))
|
||||
assert(sfxr.BITDEPTH[depth] and depth, "Invalid bit depth: " .. tostring(depth))
|
||||
assert(sfxr.SAMPLERATE[rate], "invalid sample rate: " .. tostring(rate))
|
||||
assert(sfxr.BITDEPTH[depth] and depth, "invalid bit depth: " .. tostring(depth))
|
||||
|
||||
local tab, count = self:generateTable(rate, depth)
|
||||
|
||||
@ -1110,14 +1115,16 @@ function sfxr.Sound:randomBlip(seed)
|
||||
end
|
||||
|
||||
--- Generate and export the audio data to a PCM WAVE file.
|
||||
-- @tparam ?string|file|love.filesystem.File f a file path, a Lua file object, a love.filesystem.File instance
|
||||
-- @tparam ?string|file|love.filesystem.File f a path or file in `wb`-mode
|
||||
-- (passed files will not be closed)
|
||||
-- @tparam[opt=44100] SAMPLERATE rate the sample rate
|
||||
-- @tparam[opt=0] BITDEPTH depth the bit depth
|
||||
-- @raise "invalid sample rate: x", "invalid bit depth: x"
|
||||
function sfxr.Sound:exportWAV(f, rate, depth)
|
||||
rate = rate or 44100
|
||||
depth = depth or 16
|
||||
assert(sfxr.SAMPLERATE[rate], "Invalid sample rate: " .. tostring(rate))
|
||||
assert(sfxr.BITDEPTH[depth] and depth ~= 0, "Invalid bit depth: " .. tostring(depth))
|
||||
assert(sfxr.SAMPLERATE[rate], "invalid sample rate: " .. tostring(rate))
|
||||
assert(sfxr.BITDEPTH[depth] and depth ~= 0, "invalid bit depth: " .. tostring(depth))
|
||||
|
||||
local close = false
|
||||
if type(f) == "string" then
|
||||
@ -1216,9 +1223,10 @@ function sfxr.Sound:exportWAV(f, rate, depth)
|
||||
end
|
||||
|
||||
--- Save the sound parameters to a file as a Lua table
|
||||
-- @tparam ?string|file|love.filesystem.File f a file path, a Lua file object, a love.filesystem.File instance
|
||||
-- @tparam[opt=true] whether to minify the output
|
||||
function sfxr.Sound:save(f, compressed)
|
||||
-- @tparam ?string|file|love.filesystem.File f a path or file in `w`-mode
|
||||
-- (passed files will not be closed)
|
||||
-- @tparam[opt=true] bool minify whether to minify the output or not
|
||||
function sfxr.Sound:save(f, minify)
|
||||
local close = false
|
||||
if type(f) == "string" then
|
||||
f = io.open(f, "w")
|
||||
@ -1243,14 +1251,14 @@ function sfxr.Sound:save(f, compressed)
|
||||
|
||||
if obj ~= def then
|
||||
local k = table.concat(keys, ".")
|
||||
if not compressed then
|
||||
if not minify then
|
||||
code = code .. "\n" .. string.rep(" ", #keys - 1)
|
||||
end
|
||||
code = code .. string.format("%s=%s;", name, obj)
|
||||
end
|
||||
|
||||
elseif type(obj) == "table" then
|
||||
local spacing = compressed and "" or "\n" .. string.rep(" ", #keys - 1)
|
||||
local spacing = minify and "" or "\n" .. string.rep(" ", #keys - 1)
|
||||
code = code .. spacing .. string.format("%s={", name)
|
||||
|
||||
for k, v in pairs(obj) do
|
||||
@ -1273,7 +1281,9 @@ function sfxr.Sound:save(f, compressed)
|
||||
end
|
||||
|
||||
--- Load the sound parameters from a file containing a Lua table
|
||||
-- @tparam ?string|file|love.filesystem.File f a file path, a Lua file object, a love.filesystem.File instance
|
||||
-- @tparam ?string|file|love.filesystem.File f a path or file in `r`-mode
|
||||
-- (passed files will not be closed)
|
||||
-- @raise "incompatible version: x.x.x"
|
||||
function sfxr.Sound:load(f)
|
||||
local close = false
|
||||
if type(f) == "string" then
|
||||
@ -1290,9 +1300,7 @@ function sfxr.Sound:load(f)
|
||||
|
||||
local params, version = assert(loadstring(code))()
|
||||
-- check version compatibility
|
||||
if version > sfxr.VERSION then
|
||||
error("Incompatible version: " .. tostring(version))
|
||||
end
|
||||
assert(version > sfxr.VERSION, "incompatible version: " .. tostring(version))
|
||||
|
||||
self:resetParameters()
|
||||
-- merge the loaded table into the own
|
||||
@ -1303,8 +1311,9 @@ function sfxr.Sound:load(f)
|
||||
end
|
||||
end
|
||||
|
||||
--- Save the sound parameters to a file in the sfxr binary format
|
||||
-- @tparam ?string|file|love.filesystem.File f a file path, a Lua file object, a love.filesystem.File instance
|
||||
--- Save the sound parameters to a file in the sfxr binary format (version 102)
|
||||
-- @tparam ?string|file|love.filesystem.File f a path or file in `wb`-mode
|
||||
-- (passed files will not be closed)
|
||||
function sfxr.Sound:saveBinary(f)
|
||||
local close = false
|
||||
if type(f) == "string" then
|
||||
@ -1360,7 +1369,10 @@ function sfxr.Sound:saveBinary(f)
|
||||
end
|
||||
|
||||
--- Load the sound parameters from a file in the sfxr binary format
|
||||
-- @tparam ?string|file|love.filesystem.File f a file path, a Lua file object, a love.filesystem.File instance
|
||||
-- (version 100, 101, 102)
|
||||
-- @tparam ?string|file|love.filesystem.File f a path or file in `rb`-mode
|
||||
-- (passed files will not be closed)
|
||||
-- @raise "incompatible version: x", "unexpected file length"
|
||||
function sfxr.Sound:loadBinary(f)
|
||||
local close = false
|
||||
if type(f) == "string" then
|
||||
@ -1394,7 +1406,7 @@ function sfxr.Sound:loadBinary(f)
|
||||
local version = s:byte(off)
|
||||
off = off + 4
|
||||
if version < 100 or version > 102 then
|
||||
return nil, "unknown version number "..version
|
||||
error("incompatible version: " .. tostring(version))
|
||||
end
|
||||
|
||||
self.wavetype = s:byte(off)
|
||||
@ -1435,7 +1447,7 @@ function sfxr.Sound:loadBinary(f)
|
||||
self.change.amount = readFloat()
|
||||
end
|
||||
|
||||
assert(off-1 == s:len())
|
||||
assert(off-1 == s:len(), "unexpected file length")
|
||||
end
|
||||
|
||||
return sfxr
|
||||
|
Loading…
Reference in New Issue
Block a user