panner-equalpower.html (3851B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title> 5 panner-equalpower.html 6 </title> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script src="../../resources/audit-util.js"></script> 10 <script src="../../resources/panner-model-testing.js"></script> 11 </head> 12 <body> 13 <script> 14 15 // To test the panner, we create a number of panner nodes 16 // equally spaced on a semicircle at unit distance. The 17 // semicircle covers the azimuth range from -90 to 90 deg, 18 // covering full left to full right. Each source is an impulse 19 // turning at a different time and we check that the rendered 20 // impulse has the expected gain. 21 promise_test(async () => { 22 const context = new OfflineAudioContext( 23 2, sampleRate * renderLengthSeconds, sampleRate); 24 await createTestAndRun_W3CTH( 25 context, nodesToCreate, 1, 26 (panner, x, y, z) => panner.setPosition(x, y, z)); 27 }, 'Equal-power panner model of AudioPannerNode'); 28 29 // Test that a mono source plays out on both the left and right channels 30 // when the source and listener positions are the same. 31 32 promise_test(async () => { 33 const context = 34 new OfflineAudioContext(2, 0.25 * sampleRate, sampleRate); 35 36 // Arbitrary position for source and listener. Just so we don't use 37 // defaults positions. 38 const x = 1; 39 const y = 2; 40 const z = 3; 41 42 context.listener.setPosition(x, y, z); 43 44 const source = new OscillatorNode(context); 45 const panner = new PannerNode(context, { 46 panningModel: 'equalpower', 47 positionX: x, 48 positionY: y, 49 positionZ: z, 50 }); 51 52 source.connect(panner).connect(context.destination); 53 source.start(); 54 55 const renderedBuffer = await context.startRendering(); 56 57 // The rendered left and right channels should be identical. 58 const left = renderedBuffer.getChannelData(0); 59 const right = renderedBuffer.getChannelData(1); 60 assert_array_equals( 61 left, right, 62 'Mono: left and right channels should contain identical samples.'); 63 }, 'Mono source and listener at the same position'); 64 65 // Test that a stereo source plays out on both the left and right channels 66 // when the source and listener positions are the same. 67 68 promise_test(async () => { 69 const context = 70 new OfflineAudioContext(2, 0.25 * sampleRate, sampleRate); 71 72 // Arbitrary position for source and listener. Just so we don't use 73 // defaults positions. 74 const x = 1; 75 const y = 2; 76 const z = 3; 77 78 context.listener.setPosition(x, y, z); 79 80 const source = new OscillatorNode(context); 81 const merger = new ChannelMergerNode(context, {numberOfInputs: 2}); 82 const panner = new PannerNode(context, { 83 panningModel: 'equalpower', 84 positionX: x, 85 positionY: y, 86 positionZ: z, 87 }); 88 89 // Make the oscillator a stereo signal (identical signals on each 90 // channel). 91 source.connect(merger, 0, 0); 92 source.connect(merger, 0, 1); 93 94 merger.connect(panner).connect(context.destination); 95 source.start(); 96 97 const renderedBuffer = await context.startRendering(); 98 99 // The rendered left and right channels should be identical. 100 const left = renderedBuffer.getChannelData(0); 101 const right = renderedBuffer.getChannelData(1); 102 assert_array_equals( 103 left, right, 104 'Stereo: left and right channels should contain identical ' + 105 'samples.'); 106 }, 'Stereo source and listener at the same position'); 107 </script> 108 </body> 109 </html>