Bug 134060

Summary: Float denormal issue in JavaScript processor node in Web Audio API
Product: WebKit Reporter: letz
Component: Web AudioAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Major CC: crogers, jer.noble
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Mac (Intel)   
OS: OS X 10.8   
Attachments:
Description Flags
Test file that contains a ScripProcessorNode that shows the problem none

Description letz 2014-06-19 06:53:56 PDT
We successfully compile our C++ audio processing code with emcripten in asm.js to deploy on the web using the WebAudio API , so running the resulting asm.js code in a ScriptProcessorNode in the Web Audio API. 

Our C++ code uses the following denormalized float number protection code ("protection" is needed since denormalized float number computation is awfully slow and has to be avoided): 

#ifdef __SSE__
   #include <xmmintrin.h>
   #ifdef __SSE2__
       #define AVOIDDENORMALS _mm_setcsr(_mm_getcsr() | 0x8040)
   #else
       #define AVOIDDENORMALS _mm_setcsr(_mm_getcsr() | 0x8000)
   #endif
#else
   #define AVOIDDENORMALS
#endif

Basically we add a call at AVOIDDENORMALS before each audio  block processing. It seems this AVOIDDENORMALS is just removed by the emcripten compiler and so we get asm.js code that seems to produce denormalized floats and the speed issue occurs.

The attached "piano.html" page contains a piano physical model that is compiled in asm.js and run as a Web Audio API ScriptProcessorNode. It you hit the "gate" button a sound is played. After some seconds the CPU use (seen in activity monitor on OSX) raises to 100%.

ScriptProcessorNode node takes a lot of time to execute since float denormal issue happens

ScriptProcessorNode should probably be processes in an context where flush denormals to zero is done automatically.
Comment 1 letz 2014-06-19 06:56:38 PDT
Created attachment 233358 [details]
Test file that contains a ScripProcessorNode that shows the problem