content/media/webaudio/test/test_analyserNode.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <head>
michael@0 4 <title>Test AnalyserNode</title>
michael@0 5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <script type="text/javascript" src="webaudio.js"></script>
michael@0 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 8 </head>
michael@0 9 <body>
michael@0 10 <pre id="test">
michael@0 11 <script class="testbody" type="text/javascript">
michael@0 12
michael@0 13 SimpleTest.waitForExplicitFinish();
michael@0 14 addLoadEvent(function() {
michael@0 15
michael@0 16 var context = new AudioContext();
michael@0 17 var buffer = context.createBuffer(1, 2048, context.sampleRate);
michael@0 18 for (var i = 0; i < 2048; ++i) {
michael@0 19 buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate);
michael@0 20 }
michael@0 21
michael@0 22 var destination = context.destination;
michael@0 23
michael@0 24 var source = context.createBufferSource();
michael@0 25
michael@0 26 var analyser = context.createAnalyser();
michael@0 27
michael@0 28 source.buffer = buffer;
michael@0 29
michael@0 30 source.connect(analyser);
michael@0 31 analyser.connect(destination);
michael@0 32
michael@0 33 is(analyser.channelCount, 1, "analyser node has 2 input channels by default");
michael@0 34 is(analyser.channelCountMode, "explicit", "Correct channelCountMode for the analyser node");
michael@0 35 is(analyser.channelInterpretation, "speakers", "Correct channelCountInterpretation for the analyser node");
michael@0 36
michael@0 37 is(analyser.fftSize, 2048, "Correct default value for fftSize");
michael@0 38 is(analyser.frequencyBinCount, 1024, "Correct default value for frequencyBinCount");
michael@0 39 expectException(function() {
michael@0 40 analyser.fftSize = 0;
michael@0 41 }, DOMException.INDEX_SIZE_ERR);
michael@0 42 expectException(function() {
michael@0 43 analyser.fftSize = 1;
michael@0 44 }, DOMException.INDEX_SIZE_ERR);
michael@0 45 expectException(function() {
michael@0 46 analyser.fftSize = 8;
michael@0 47 }, DOMException.INDEX_SIZE_ERR);
michael@0 48 expectException(function() {
michael@0 49 analyser.fftSize = 100; // non-power of two
michael@0 50 }, DOMException.INDEX_SIZE_ERR);
michael@0 51 expectException(function() {
michael@0 52 analyser.fftSize = 2049;
michael@0 53 }, DOMException.INDEX_SIZE_ERR);
michael@0 54 expectException(function() {
michael@0 55 analyser.fftSize = 4096;
michael@0 56 }, DOMException.INDEX_SIZE_ERR);
michael@0 57 analyser.fftSize = 1024;
michael@0 58 is(analyser.frequencyBinCount, 512, "Correct new value for frequencyBinCount");
michael@0 59
michael@0 60 is(analyser.minDecibels, -100, "Correct default value for minDecibels");
michael@0 61 is(analyser.maxDecibels, -30, "Correct default value for maxDecibels");
michael@0 62 expectException(function() {
michael@0 63 analyser.minDecibels = -30;
michael@0 64 }, DOMException.INDEX_SIZE_ERR);
michael@0 65 expectException(function() {
michael@0 66 analyser.minDecibels = -29;
michael@0 67 }, DOMException.INDEX_SIZE_ERR);
michael@0 68 expectException(function() {
michael@0 69 analyser.maxDecibels = -100;
michael@0 70 }, DOMException.INDEX_SIZE_ERR);
michael@0 71 expectException(function() {
michael@0 72 analyser.maxDecibels = -101;
michael@0 73 }, DOMException.INDEX_SIZE_ERR);
michael@0 74
michael@0 75 is(analyser.smoothingTimeConstant, 0.8, "Correct default value for smoothingTimeConstant");
michael@0 76 expectException(function() {
michael@0 77 analyser.smoothingTimeConstant = -0.1;
michael@0 78 }, DOMException.INDEX_SIZE_ERR);
michael@0 79 expectException(function() {
michael@0 80 analyser.smoothingTimeConstant = 1.1;
michael@0 81 }, DOMException.INDEX_SIZE_ERR);
michael@0 82 analyser.smoothingTimeConstant = 0;
michael@0 83 analyser.smoothingTimeConstant = 1;
michael@0 84
michael@0 85 SimpleTest.finish();
michael@0 86 });
michael@0 87
michael@0 88 </script>
michael@0 89 </pre>
michael@0 90 </body>
michael@0 91 </html>

mercurial