Crunching Numbers

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Dr. Peeps
Citizen
Posts: 57
Joined: Sat May 28, 2016 12:57 am
Location: British Columbia, Canada

Crunching Numbers

Post by Dr. Peeps »

Hi! I'm looking for recommendations from more experienced Love2D users than I. My project requires processing a fairly large amount of incoming data in real-time (audio signal processing, to be specific). I've already written the core processing functions in C/C++, and I don't think rewriting them in Lua would be a great idea, performance-wise. So, three options have occured to me:
  • 1. Add the new C functions to the Love2D code itself (and have recompile it for each platform I plan to release on - which will be at least a few).

    2. Compile the new C functions into a DLL, and call them using something like LuaJIT FFI. (I expect this would still require compiling the DLL on each platform.)

    3. Write the new C functions as video shaders. This makes some sense as it would do away with having to recompile anything, and should be platform-independent, and I also like the idea of unloading some processing to the video card. But I wonder how efficient it would be to have to send all the incoming data to the video card.
Anyone have any experience with Love2D in this area? Any wisdom to impart? Are there more options that just the above? Thanks in advance! :)
Last edited by Dr. Peeps on Mon Oct 17, 2016 4:44 am, edited 1 time in total.
User avatar
Tanner
Party member
Posts: 166
Joined: Tue Apr 10, 2012 1:51 am

Re: Crunching Numbers

Post by Tanner »

I mean, my inclination is toward 4. Rewrite them in Lua, using FFI data structures. The performance impact will likely be less than you think.

Alternatively, I would lean toward 2. Encoding data into into a texture to mimic GPGPU just tends to be slightly more of a pain in the ass than cross platform C++ compilation is. Assuming you have no dependencies besides Lua, it should even be relatively straightforward. Here's a project I made that I know works on OSX, Linux and Windows and links against Lua. https://github.com/TannerRogalsky/lua-p ... eLists.txt
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Crunching Numbers

Post by raidho36 »

You're forgetting LÖVE uses LuaJIT which compiles code to native instructions, and using FFI data structures eliminates much of the overhead associated with table lookups and weakly typed variables management.
User avatar
Dr. Peeps
Citizen
Posts: 57
Joined: Sat May 28, 2016 12:57 am
Location: British Columbia, Canada

Re: Crunching Numbers

Post by Dr. Peeps »

raidho36 wrote:You're forgetting LÖVE uses LuaJIT which compiles code to native instructions, and using FFI data structures eliminates much of the overhead associated with table lookups and weakly typed variables management.
Not so much forgetting ... I didn't even know that LuaJIT was now the default. :crazy: And I haven't tried using FFI data structures yet.

Thanks guys - this is exactly the sort of answer I was looking for.

EXCEPT ... I just read that JIT compilation is disabled on iOS and Android (and consoles), meaning the code would run much slower on mobile devices - the devices where the optimization would be the most critical. :( I'm not sure this solution will be ideal for me, but I'll try it before I knock it.
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Crunching Numbers

Post by zorg »

Then again, raidho forgets to mention that the next version will include his awesome contribution of queueable source objects, that can be used for realtime audio processing purposes... i should know, i've been previously using the FFI "version" of it for just that purpose.

You can already get minor builds, for windows at least.

That said, you didn't really detail just how much crunching you want to do, so it still might be too slow if you wrote it in lua, but who knows.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: No registered users and 120 guests