Re: Sync of scriptProcessorNode and native Node

Dear Arnau,

this is indeed a frustrating (but probably performance wise necessary) limitation of the normal web audio nodes, 
parameters in a scriptProcessorNode can only be updated once every vector which is a minimum of 256 samples.

Maybe you could solve your problem by using one of the javascript libraries that  bypass most of web audio api and do everything in JS itself.
What comes first to mind would be the Gibberish.js library by Charlie Roberts, which gives you the ability to control parameters per sample and easily schedule synchronized parameter changes also with sample accuracy:
http://www.charlie-roberts.com/gibberish/docs.html
It should be quite easy to extend it with your own nodes.
There are other libraries as well like flocking.js and Timbre.js.

Of course it comes with some performance penalties, but Gibberish tries to at least generate javascript code that should be as efficient as possible for it's JIT complication style, as far as it's own nodes are considered.

Hope it helps,
Casper

casper.schipper@monotonestudio.nl
Mauritskade 55C (the thinking hut)
1092 AD  Amsterdam
+316 52 322 590








On 18 apr. 2014, at 10:55, Arnau Julia <Arnau.Julia@ircam.fr> wrote:

> Hello,
> 
> I'm trying to synchronizing the buffer in a scriptProcessorNode with native/regular web audio nodes and I'm having some problems. My problem is that I want to synchronize the scriptProcessorNode with a ramp of a GainNode.
> 
> My program looks like the attached diagram. Each scriptProcessorNode is a filter with n coefficients and these coefficients are in a global variable. My problem comes when I try to update these coefficients and do a ramp in the gain through an audioParam at the "same time".
> 
> The start scenario is (in pseudo-code):
> 
> audioBufferSourceNode.connect(scriptProcessorNode0);
> audioBufferSourceNode.connect(scriptProcessorNode1);
> 
> scriptProcessorNode0.connect(gainNode0);
> scriptProcessorNode0.connect(gainNode1);
> 
> gainNode0.connect(audioContext.destination);
> gainNode1.connect(audioContext.destination);
> 
> gainNode1.gain.value = 0;
> globalVariableOfCoefficients0 = coefficients0;
> globalVariableOfCoefficients1 = null;
> 
> audioBufferSourceNode.start(0);
> 
> The reason to have two scriptProcessorNodes is because I want to do a smooth transition of the coefficients, so I do a crossfading between the 'old' coefficients (scriptProcessorNode0) and the 'new' coefficients (scriptProcessorNode1) with the ramps of gainNode0 and gainNode1. So when I receive the notification to update the coefficients, the global variable is updated and the ramps are started.
> The first problem is that when I change the globalVariableOfCoefficients1, I don't know if the value of the variable is really updated in the scriptProcessorNode. It seems that the scriptProcessorNode have to wait until get a new buffer to update the value of their global variables . On the other hand, there a second problem. If I change the value of the globalVariableOfCoefficients1 and I wait to get a new buffer for update their global variables, how I can know when the first sample of this new buffer "is" really in the gainNode? 
> 
> On the other hand, I would like to find some documentation where the relation between the scriptProcessorNode and the audio thread  is explained for clearly understand the problematic.
> 
> Thank you very much in advance, 
> 
> Arnau Julià
> 
> 
> <diagram_webAudio.png>

Received on Friday, 18 April 2014 14:51:25 UTC