Get things working again

This commit is contained in:
nucular 2016-03-09 23:00:44 +01:00
parent 1bd524489e
commit 02f0239a33
2 changed files with 7 additions and 8 deletions

View File

@ -45,8 +45,7 @@ local device = ao.openLive(driverId, {bits = 16, rate = 44100, channels = 1})
local sound = sfxr.newSound() local sound = sfxr.newSound()
sound:randomize() sound:randomize()
local buffer = sound:generateString() device:play(sound:generateString())
device:play(buffer, #buffer)
``` ```
Documentation Documentation

View File

@ -314,7 +314,7 @@ function sfxr.Sound:resetParameters()
self.repeatspeed = 0.0 self.repeatspeed = 0.0
--- The base @{WAVEFORM|waveform} (*default* @{WAVEFORM|SQUARE}) --- The base @{WAVEFORM|waveform} (*default* @{WAVEFORM|SQUARE})
-- @within Parameters -- @within Parameters
self.waveform = sfxr.SQUARE self.waveform = sfxr.WAVEFORM.SQUARE
--- Attack time: --- Attack time:
-- Time the sound takes to reach its peak amplitude -- Time the sound takes to reach its peak amplitude
@ -441,7 +441,7 @@ end
--- Clamp all parameters within their sane ranges. --- Clamp all parameters within their sane ranges.
function sfxr.Sound:sanitizeParameters() function sfxr.Sound:sanitizeParameters()
self.repeatspeed = clamp(self.repeatspeed, 0, 1) self.repeatspeed = clamp(self.repeatspeed, 0, 1)
self.wavetype = clamp(self.wavetype, sfxr.SQUARE, sfxr.NOISE) self.wavetype = clamp(self.waveform, 0, #sfxr.WAVEFORM)
self.envelope.attack = clamp(self.envelope.attack, 0, 1) self.envelope.attack = clamp(self.envelope.attack, 0, 1)
self.envelope.sustain = clamp(self.envelope.sustain, 0, 1) self.envelope.sustain = clamp(self.envelope.sustain, 0, 1)
@ -672,7 +672,7 @@ function sfxr.Sound:generate(rate, depth)
local fp = phase / period local fp = phase / period
-- Square, including square duty -- Square, including square duty
if self.waveform == sfxr.SQUARE then if self.waveform == sfxr.WAVEFORM.SQUARE then
if fp < square_duty then if fp < square_duty then
sample = 0.5 sample = 0.5
else else
@ -680,15 +680,15 @@ function sfxr.Sound:generate(rate, depth)
end end
-- Sawtooth -- Sawtooth
elseif self.waveform == sfxr.SAWTOOTH then elseif self.waveform == sfxr.WAVEFORM.SAWTOOTH then
sample = 1 - fp * 2 sample = 1 - fp * 2
-- Sine -- Sine
elseif self.waveform == sfxr.SINE then elseif self.waveform == sfxr.WAVEFORM.SINE then
sample = math.sin(fp * 2 * math.pi) sample = math.sin(fp * 2 * math.pi)
-- Pitched white noise -- Pitched white noise
elseif self.waveform == sfxr.NOISE then elseif self.waveform == sfxr.WAVEFORM.NOISE then
sample = noisebuffer[trunc(phase * 32 / period) % 32 + 1] sample = noisebuffer[trunc(phase * 32 / period) % 32 + 1]
end end