Page 1 of 4

sfxr.lua - Generate sounds dynamically at runtime

Posted: Mon May 26, 2014 3:24 pm
by nucular
Hello everybody!
Over the last weeks I worked on a port of the awesome sfxr sound generator to pure Lua. My goal was to allow easy dynamical creation of sound effects based on in-game events. Think about infinite, completely procedurally generated games.

The source is on GitHub: http://github.com/nucular/sfxrlua

Here's some code since people love examples:

Code: Select all

local sfxr = require("sfxr")

function love.load()
    local sound = sfxr.newSound()
    sound:randomize()
    sound:play() -- generates a SoundData and plays it
end
Current features:
  • Editable documentation wiki at http://github.com/nucular/sfxrlua/wiki
  • Output samples of a Sound instance can be generated using an iterator
  • All 7 preset generators are implemented
  • Demo application based on LoveFrames that resembles the original
  • Export to the RIFF WAV format
  • Saving and loading of the binary format used by vanilla sfxr
Targeted Features:
  • Embedding into the love-loader framework or other kinds of threaded sound generation
And a screenshot of the demo application:
Image

The entire thing is a work in progress, that means sudden crashes and wild API changes may happen.
Known issues can be found here: http://github.com/nucular/sfxrlua/issues
Pull requests are always welcome!

You can check out the original sfxr here: http://www.drpetter.se/project_sfxr.html
Also, here's a little introduction to it: https://www.youtube.com/watch?v=Sgah1W4y6Zs

The attached demo application may not be up-to-date with the version on the repo.

Re: Pure Lua port of the sfxr sound generator

Posted: Mon May 26, 2014 4:21 pm
by Roland_Yonaba
What-.
Hats off. You sir, are awesome.

EDIT: Since this has known issues, i'd suggest filing a issue using github's issue tracker for each one, and close them when they are solved. It will help monitor them.

Re: Pure Lua port of the sfxr sound generator

Posted: Mon May 26, 2014 4:41 pm
by rxi
I haven't had a chance to try this out yet, but I just wanted to say it looks great from the description and screenshot! I can't wait to give it a go.

Re: Pure Lua port of the sfxr sound generator

Posted: Mon May 26, 2014 4:58 pm
by nucular
Roland_Yonaba wrote:What-.
Hats off. You sir, are awesome.

EDIT: Since this has known issues, i'd suggest filing a issue using github's issue tracker for each one, and close them when they are solved. It will help monitor them.
Thanks!
And good idea, I just moved them over to the issue tracker.

Re: Pure Lua port of the sfxr sound generator

Posted: Mon May 26, 2014 5:35 pm
by MadByte
Wow.

Is it currently possible to play a specific seed as sound, something like :

Code: Select all

local sound = sfxr.newSound({seed = 38754})
sound:play()
?

Re: Pure Lua port of the sfxr sound generator

Posted: Mon May 26, 2014 6:22 pm
by nucular
Yeah, that would be

Code: Select all

local sound = sfxr.newSound()
sound:randomize(38754)
love.audio.newSource(sound:generateSoundData()):play()
Going to add sound:play() now, though :P
EDIT: Added!

Re: Pure Lua port of the sfxr sound generator

Posted: Mon May 26, 2014 7:03 pm
by SiENcE
Yes another tool! Do we need a LÖVE tool section ;) ?

Reminds me to start developing my positional soundsystem for löve. Has someone already done something like this?

Re: Pure Lua port of the sfxr sound generator

Posted: Tue May 27, 2014 2:21 pm
by nucular
Afaik, the inbuilt audio API supports positional sounds for mono sources.

Re: Pure Lua port of the sfxr sound generator

Posted: Tue May 27, 2014 3:31 pm
by SiENcE
nucular wrote:Afaik, the inbuilt audio API supports positional sounds for mono sources.
I know, but i have to build it into my game and the editor. It's no that easy to find the right setup and mixing. I haven't seen a löve game that uses this features.

Re: Pure Lua port of the sfxr sound generator

Posted: Sat May 31, 2014 1:59 pm
by nucular
I just added support for exporting the sound in the RIFF WAV format. It's as easy as calling Sound.exportWAV with a path string. Alternatively, you can also pass Lua file handlers or open love.filesystem.File instances. It also supports exporting in 16 or 8 bits and with 44100 or 22050 Hz sample rate.

EDIT: I'll add this functionality to the demo when I finish my little file dialog thingy for LoveFrames, or somebody else creates a similar thing.