Simplify module structure

This commit is contained in:
nucular 2014-05-07 16:58:37 +02:00
parent a92cc28afd
commit 3cf88e042e
2 changed files with 14 additions and 18 deletions

View File

@ -15,7 +15,7 @@ With Löve2D 0.9:
local sfxr = require("sfxr")
function love.load()
local sound = sfxr.new()
local sound = sfxr.newSound()
sound:randomize()
love.audio.newSource(sound:generateSoundData()):play()
end
@ -29,7 +29,7 @@ local sfxr = require("sfxr")
local driverId = ao.defaultDriverId()
local device = ao.openLive(driverId, {bits = 16, rate = 44100, channels = 1})
local sound = sfxr.new()
local sound = sfxr.newSound()
sound:randomize()
local buffer = sound:generateString()

View File

@ -22,13 +22,6 @@ SOFTWARE.
]]--
local sfxr = {}
sfxr.__index = sfxr
local function new()
local obj = setmetatable({}, sfxr)
obj:__init()
return obj
end
-- Constants
@ -63,9 +56,12 @@ local function cpypol(a, b)
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
self.volume = {}
self.envelope = {}
@ -193,12 +189,12 @@ function sfxr:generate()
end
end
-- Constructor
sfxr:__init()
function sfxr.newSound(...)
local instance = setmetatable({}, sfxr.Sound)
instance:__init(...)
return instance
end
return setmetatable({new = new},
{
__call = function(_, ...)
return new(...)
end
})
return sfxr