mirror of
https://github.com/nucular/sfxrlua.git
synced 2024-12-24 18:44:20 +00:00
Added actual generation functions
This commit is contained in:
parent
9b287f7a6e
commit
702398322e
40
sfxr.lua
40
sfxr.lua
@ -340,6 +340,46 @@ function sfxr.Sound:generate()
|
||||
end
|
||||
end
|
||||
|
||||
function sfxr.Sound:getEnvelopeLimit()
|
||||
local env_length = {self.envelope.attack^2 * 100000,
|
||||
self.envelope.sustain^2 * 100000,
|
||||
self.envelope.decay^2 * 100000}
|
||||
|
||||
return env_length[1] + env_length[2] + env_length[3] + 2
|
||||
end
|
||||
|
||||
function sfxr.Sound:getLimit()
|
||||
return self:getEnvelopeLimit()
|
||||
end
|
||||
|
||||
function sfxr.Sound:generateTable()
|
||||
local t = {}
|
||||
t[self:getLimit()] = 0
|
||||
|
||||
local i = 1
|
||||
for v in self:generate() do
|
||||
if not v then
|
||||
break
|
||||
end
|
||||
t[i] = v
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
return t
|
||||
end
|
||||
|
||||
function sfxr.Sound:generateSoundData(freq, bits)
|
||||
local tab = self:generateTable()
|
||||
|
||||
local data = love.sound.newSoundData(#tab, freq, bits, 1)
|
||||
|
||||
for i = 0, #tab - 1 do
|
||||
data:setSample(i, tab[i + 1])
|
||||
end
|
||||
|
||||
return data
|
||||
end
|
||||
|
||||
-- Constructor
|
||||
|
||||
function sfxr.newSound(...)
|
||||
|
Loading…
Reference in New Issue
Block a user