2014-04-11 18:16:20 +00:00
|
|
|
sfxr.lua
|
|
|
|
========
|
2014-04-11 17:31:10 +00:00
|
|
|
|
2014-05-24 13:32:13 +00:00
|
|
|
A port of the sfxr sound effect synthesizer to pure Lua, designed to be used
|
2014-04-11 18:16:20 +00:00
|
|
|
together with the *awesome* Löve2D game framework.
|
|
|
|
|
|
|
|
|
|
|
|
Example usage
|
|
|
|
-------------
|
|
|
|
|
|
|
|
These examples should play a randomly generated sound.
|
|
|
|
|
|
|
|
With Löve2D 0.9:
|
|
|
|
```lua
|
|
|
|
local sfxr = require("sfxr")
|
|
|
|
|
|
|
|
function love.load()
|
2014-05-07 14:58:37 +00:00
|
|
|
local sound = sfxr.newSound()
|
2014-04-11 18:16:20 +00:00
|
|
|
sound:randomize()
|
|
|
|
love.audio.newSource(sound:generateSoundData()):play()
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
With lao:
|
|
|
|
```lua
|
|
|
|
require("ao")
|
|
|
|
local sfxr = require("sfxr")
|
|
|
|
|
|
|
|
local driverId = ao.defaultDriverId()
|
|
|
|
local device = ao.openLive(driverId, {bits = 16, rate = 44100, channels = 1})
|
|
|
|
|
2014-05-07 14:58:37 +00:00
|
|
|
local sound = sfxr.newSound()
|
2014-04-11 18:16:20 +00:00
|
|
|
sound:randomize()
|
|
|
|
|
|
|
|
local buffer = sound:generateString()
|
|
|
|
device:play(buffer, #buffer)
|
|
|
|
```
|