test_pannerNodeHRTFSymmetry.html (2480B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Test left/right symmetry and block-offset invariance of HRTF panner</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <script type="text/javascript" src="webaudio.js"></script> 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 8 </head> 9 <body> 10 <pre id="test"> 11 <script class="testbody" type="text/javascript"> 12 13 SimpleTest.waitForExplicitFinish(); 14 15 const blockSize = 128; 16 const bufferSize = 4096; // > HRTF panner latency 17 18 var ctx = new AudioContext(); 19 20 function startTest() { 21 var leftPanner = ctx.createPanner(); 22 var rightPanner = ctx.createPanner(); 23 leftPanner.panningModel = "HRTF"; 24 rightPanner.panningModel = "HRTF"; 25 leftPanner.positionX.value = -1; 26 rightPanner.positionX.value = 1; 27 28 // Test that PannerNode processes the signal consistently irrespective of 29 // the offset in the processing block. This is done by inserting a delay of 30 // less than a block size before one panner. 31 const delayTime = 0.7 * blockSize / ctx.sampleRate; 32 var leftDelay = ctx.createDelay(delayTime); 33 leftDelay.delayTime.value = delayTime; 34 leftDelay.connect(leftPanner); 35 // and compensating for the delay after the other. 36 var rightDelay = ctx.createDelay(delayTime); 37 rightDelay.delayTime.value = delayTime; 38 rightPanner.connect(rightDelay); 39 40 // Feed the panners with a signal having some harmonics to fill the spectrum. 41 var oscillator = ctx.createOscillator(); 42 oscillator.frequency.value = 110; 43 oscillator.type = "sawtooth"; 44 oscillator.connect(leftDelay); 45 oscillator.connect(rightPanner); 46 oscillator.start(0); 47 48 // Switch the channels on one panner output, and it should match the other. 49 var splitter = ctx.createChannelSplitter(); 50 leftPanner.connect(splitter); 51 var merger = ctx.createChannelMerger(); 52 splitter.connect(merger, 0, 1); 53 splitter.connect(merger, 1, 0); 54 55 // Invert one signal so that mixing with the other will find the difference. 56 var gain = ctx.createGain(); 57 gain.gain.value = -1.0; 58 merger.connect(gain); 59 60 var processor = ctx.createScriptProcessor(bufferSize, 2, 0); 61 gain.connect(processor); 62 rightDelay.connect(processor); 63 processor.onaudioprocess = 64 function(e) { 65 compareBuffers(e.inputBuffer, 66 ctx.createBuffer(2, bufferSize, ctx.sampleRate)); 67 e.target.onaudioprocess = null; 68 SimpleTest.finish(); 69 } 70 } 71 72 promiseHRTFReady(ctx.sampleRate).then(startTest); 73 </script> 74 </pre> 75 </body> 76 </html>