test_analyserNodeWithGain.html (1534B)
1 <!DOCTYPE html> 2 <title>Test effect of AnalyserNode on GainNode output</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script> 6 promise_test(function() { 7 // fftSize <= bufferSize so that the time domain data is full of input after 8 // processing the buffer. 9 const fftSize = 32; 10 const bufferSize = 128; 11 12 var context = new OfflineAudioContext(1, bufferSize, 48000); 13 14 var analyser1 = context.createAnalyser(); 15 analyser1.fftSize = fftSize; 16 analyser1.connect(context.destination); 17 var analyser2 = context.createAnalyser(); 18 analyser2.fftSize = fftSize; 19 20 var gain = context.createGain(); 21 gain.gain.value = 2.0; 22 gain.connect(analyser1); 23 gain.connect(analyser2); 24 25 // Create a DC input to make getFloatTimeDomainData() output consistent at 26 // any time. 27 var buffer = context.createBuffer(1, 1, context.sampleRate); 28 buffer.getChannelData(0)[0] = 1.0 / gain.gain.value; 29 var source = context.createBufferSource(); 30 source.buffer = buffer; 31 source.loop = true; 32 source.connect(gain); 33 source.start(); 34 35 return context.startRendering(). 36 then(function(buffer) { 37 assert_equals(buffer.getChannelData(0)[0], 1.0, 38 "analyser1 output"); 39 40 var data = new Float32Array(1); 41 analyser1.getFloatTimeDomainData(data); 42 assert_equals(data[0], 1.0, "analyser1 time domain data"); 43 analyser2.getFloatTimeDomainData(data); 44 assert_equals(data[0], 1.0, "analyser2 time domain data"); 45 }); 46 }); 47 </script>