test_oscillatorNodeNegativeFrequency.html (1292B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Test the OscillatorNode when the frequency is negative</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 addLoadEvent(function() { 15 16 var types = ["sine", 17 "square", 18 "sawtooth", 19 "triangle"]; 20 21 var finished = 0; 22 function finish() { 23 if (++finished == types.length) { 24 SimpleTest.finish(); 25 } 26 } 27 28 types.forEach(function(t) { 29 var context = new OfflineAudioContext(1, 256, 44100); 30 var osc = context.createOscillator(); 31 32 osc.frequency.value = -440; 33 osc.type = t; 34 35 osc.connect(context.destination); 36 osc.start(); 37 context.startRendering().then(function(buffer) { 38 var samples = buffer.getChannelData(0); 39 // This samples the wave form in the middle of the first period, the value 40 // should be negative. 41 ok(samples[Math.floor(44100 / 440 / 4)] < 0., "Phase should be inverted when using a " + t + " waveform"); 42 finish(); 43 }); 44 }); 45 }); 46 47 </script> 48 </pre> 49 </body> 50 </html>