sfxr.lua - Generate sounds dynamically at runtime

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
nucular
Prole
Posts: 22
Joined: Sun Mar 16, 2014 1:23 pm

sfxr.lua - Generate sounds dynamically at runtime

Post 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.
Attachments
sfxrlua.love
For Löve 0.9.x
(137.99 KiB) Downloaded 723 times
Last edited by nucular on Wed Aug 27, 2014 9:14 pm, edited 8 times in total.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Pure Lua port of the sfxr sound generator

Post 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.
rxi
Prole
Posts: 47
Joined: Sun Mar 02, 2014 10:22 pm

Re: Pure Lua port of the sfxr sound generator

Post 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.
User avatar
nucular
Prole
Posts: 22
Joined: Sun Mar 16, 2014 1:23 pm

Re: Pure Lua port of the sfxr sound generator

Post 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.
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

Re: Pure Lua port of the sfxr sound generator

Post 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()
?
User avatar
nucular
Prole
Posts: 22
Joined: Sun Mar 16, 2014 1:23 pm

Re: Pure Lua port of the sfxr sound generator

Post 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!
User avatar
SiENcE
Party member
Posts: 806
Joined: Thu Jul 24, 2008 2:25 pm
Location: Berlin/Germany
Contact:

Re: Pure Lua port of the sfxr sound generator

Post 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?
User avatar
nucular
Prole
Posts: 22
Joined: Sun Mar 16, 2014 1:23 pm

Re: Pure Lua port of the sfxr sound generator

Post by nucular »

Afaik, the inbuilt audio API supports positional sounds for mono sources.
User avatar
SiENcE
Party member
Posts: 806
Joined: Thu Jul 24, 2008 2:25 pm
Location: Berlin/Germany
Contact:

Re: Pure Lua port of the sfxr sound generator

Post 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.
User avatar
nucular
Prole
Posts: 22
Joined: Sun Mar 16, 2014 1:23 pm

Re: Pure Lua port of the sfxr sound generator

Post 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.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 8 guests