Sync of scriptProcessorNode and native Node

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à

Received on Friday, 18 April 2014 08:55:36 UTC