How to choose the optimal buffer length

   Hello

   I have created a small program:

<!DOCTYPE html><html><head>
<script type='text/javascript'>
function buffer(e){
   if( !(++counter % (0x10000/bufferSize)) ){
     nt= new Date().getTime();
     if( counter == (0x20000/bufferSize) ){
       text+= bufferSize + '->' + parseInt(0x10000 * 1000 / (nt - time)) 
+ '\n';
       e.currentTarget.disconnect();
       bufferSize<<= 1;
       if( bufferSize == 32768 )
         alert(text);
       else
         context= new webkitAudioContext(),
         node= context.createJavaScriptNode(bufferSize, 0, 1),
         counter= 0x10000/bufferSize - 5,
         node.onaudioprocess= buffer,
         node.connect(context.destination);
     }
     time= nt;
   }
   data1= e.outputBuffer.getChannelData(0);
   data2= e.outputBuffer.getChannelData(1);
   for (var i = 0; i < bufferSize; i++)
     data1[i]= data2[i]= Math.sin(4e3 * (phase++ / context.sampleRate));
}
bufferSize= 256;
context= new webkitAudioContext();
text= 'SampleRate->' + context.sampleRate + '\n';
node= context.createJavaScriptNode(bufferSize, 0, 1);
time= counter= phase= 0;
node.onaudioprocess= buffer;
node.connect(context.destination);
</script></head><body/></html>

   The program sends a sinus wave to the output device at differents 
buffer length. When finishes it shows the results: the original sample 
rate, and the sample speed for each buffer length (from 256 to 16384).

   A similar test is needed in every application, because optimal buffer 
depends on machine performance. So, is possible to add a recommended 
"buffer length value" to specification? Something like 
context.optimalBufferLength or context.recommendedBufferLength

   Regards

-- 
    ,       _            _       __   ___ _ _
   /_\  _ _| |_ ___ _ _ (_)___   \ \ / (_) | |___ _ _  __ _
  / _ \| ' \  _/ _ \ ' \| / _ \   \ V /| | | / -_) ' \/ _` |
/_/ \_\_||_\__\___/_||_|_\___/    \_/ |_|_|_\___|_||_\__,_|

Received on Saturday, 21 May 2011 04:32:56 UTC