[webkit-dev] Using JavaScriptCore in an audio context

Filip Pizlo fpizlo at apple.com
Tue Sep 22 08:59:59 PDT 2015


> On Sep 22, 2015, at 8:32 AM, Stéphane Letz <letz at grame.fr> wrote:
> 
> Hi,
> 
> We have the following project of using JavaScriptCore framework on iOS in an audio context :
> 
> - we generate optimized asm.js code from a Domain Specific Language (actually an asm.js module for the audio code itself + some additional standard JS functions)
> 
> - the asm.js module contains a "compute" function that receive an array of input float buffers, process them, and returns an array of output float buffers.
> 
> - the array of input float buffers is typically got from a realtime CoreAudio audio callback, and the array of output float buffers has to be given back to the callback. So we would basically need to transfer C float arrays to the asm.js code and back.
> 
> Now the questions :
> 
> - since the asm.js code does not allocate memory, we hope calling the asm.js "compute" function directly  form the CoreAudio callback will work, so basically that asm.js code can be called from a real-time callback. Is that a correct assumption?

It's true that in steady state, asm.js code probably won't allocate memory. But I order to execute the code the engine will parse things, compile things, and generate code - all of which requires memory allocation and may acquire locks held by lower priority threads. So, using JSC from a real time callback seems dangerous even if you're using asm.js. 

> 
> - what would be the most efficient manner to transfer C float arrays to the asm.js code and back? Is there a way to completely avoid copies during the process? Since JavaScriptCore can be used using a Objective C API (but not pure C API right?) do we need to use intermediate Objective C arrays to transfer data?

Would this help: https://bugs.webkit.org/show_bug.cgi?id=120112

> 
> Thanks for any advance or code example to look at.
> 
> Stéphane Letz
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/webkit-dev


More information about the webkit-dev mailing list