mirror of
https://github.com/nucular/sfxrlua.git
synced 2024-12-24 18:44:20 +00:00
Simplify module structure
This commit is contained in:
parent
a92cc28afd
commit
3cf88e042e
@ -15,7 +15,7 @@ With Löve2D 0.9:
|
|||||||
local sfxr = require("sfxr")
|
local sfxr = require("sfxr")
|
||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
local sound = sfxr.new()
|
local sound = sfxr.newSound()
|
||||||
sound:randomize()
|
sound:randomize()
|
||||||
love.audio.newSource(sound:generateSoundData()):play()
|
love.audio.newSource(sound:generateSoundData()):play()
|
||||||
end
|
end
|
||||||
@ -29,7 +29,7 @@ local sfxr = require("sfxr")
|
|||||||
local driverId = ao.defaultDriverId()
|
local driverId = ao.defaultDriverId()
|
||||||
local device = ao.openLive(driverId, {bits = 16, rate = 44100, channels = 1})
|
local device = ao.openLive(driverId, {bits = 16, rate = 44100, channels = 1})
|
||||||
|
|
||||||
local sound = sfxr.new()
|
local sound = sfxr.newSound()
|
||||||
sound:randomize()
|
sound:randomize()
|
||||||
|
|
||||||
local buffer = sound:generateString()
|
local buffer = sound:generateString()
|
||||||
|
28
sfxr.lua
28
sfxr.lua
@ -22,13 +22,6 @@ SOFTWARE.
|
|||||||
]]--
|
]]--
|
||||||
|
|
||||||
local sfxr = {}
|
local sfxr = {}
|
||||||
sfxr.__index = sfxr
|
|
||||||
|
|
||||||
local function new()
|
|
||||||
local obj = setmetatable({}, sfxr)
|
|
||||||
obj:__init()
|
|
||||||
return obj
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Constants
|
-- Constants
|
||||||
|
|
||||||
@ -63,9 +56,12 @@ local function cpypol(a, b)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Class functions
|
-- The main Sound class
|
||||||
|
|
||||||
function sfxr:__init()
|
sfxr.Sound = {}
|
||||||
|
sfxr.Sound.__index = sfxr.Sound
|
||||||
|
|
||||||
|
function sfxr.Sound:__init()
|
||||||
-- Build tables to store the parameters in
|
-- Build tables to store the parameters in
|
||||||
self.volume = {}
|
self.volume = {}
|
||||||
self.envelope = {}
|
self.envelope = {}
|
||||||
@ -193,12 +189,12 @@ function sfxr:generate()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Constructor
|
||||||
|
|
||||||
sfxr:__init()
|
function sfxr.newSound(...)
|
||||||
|
local instance = setmetatable({}, sfxr.Sound)
|
||||||
return setmetatable({new = new},
|
instance:__init(...)
|
||||||
{
|
return instance
|
||||||
__call = function(_, ...)
|
|
||||||
return new(...)
|
|
||||||
end
|
end
|
||||||
})
|
|
||||||
|
return sfxr
|
Loading…
Reference in New Issue
Block a user