Set input method state when webpage move by history
[framework/web/webkit-efl.git] / LayoutTests / webaudio / audioparam-summingjunction.html
1 <!DOCTYPE html>
2
3 <!--
4 Tests that multiple audio-rate signals (AudioNode outputs) can be connected to an AudioParam
5 and that these signals are summed, along with the AudioParams intrinsic value.
6 -->
7
8 <html>
9 <head>
10 <link rel="stylesheet" href="../fast/js/resources/js-test-style.css"/>
11 <script src="resources/audio-testing.js"></script>
12 <script src="resources/mix-testing.js"></script>
13 <script src="../fast/js/resources/js-test-pre.js"></script>
14
15 </head>
16 <body>
17
18 <script>
19
20 var sampleRate = 44100.0;
21 var lengthInSeconds = 1;
22
23 var context = 0;
24
25 // Buffers used by the two gain controlling sources.
26 var linearRampBuffer;
27 var toneBuffer;
28 var toneFrequency = 440;
29
30 // Arbitrary non-zero value.
31 var baselineGain = 5;
32
33 // Allow for a small round-off error.
34 var maxAllowedError = 1e-6;
35
36 function checkResult(event) {
37     var renderedBuffer = event.renderedBuffer;
38     var renderedData = renderedBuffer.getChannelData(0);
39
40     // Get buffer data from the two sources used to control gain.
41     var linearRampData = linearRampBuffer.getChannelData(0);
42     var toneData = toneBuffer.getChannelData(0);
43
44     var n = renderedBuffer.length;
45
46     if (n == linearRampBuffer.length) {
47         testPassed("Rendered signal is of correct length.");
48     } else {
49         testFailed("Rendered signal is not of correct length.");
50     }
51
52     // Check that the rendered result exactly matches the sum of the intrinsic gain plus the two sources used to control gain.
53     // This is because we're changing the gain of a signal having constant value 1.
54     var success = true;
55     for (var i = 0; i < n; ++i) {
56         var expectedValue = baselineGain + linearRampData[i] + toneData[i];
57         var error = Math.abs(expectedValue - renderedData[i]);
58
59         if (error > maxAllowedError) {
60             success = false;
61             break;
62         }
63     }
64
65     if (success) {
66         testPassed("Rendered signal matches sum of two audio-rate gain changing signals plus baseline gain.");
67     } else {
68         testFailed("Rendered signal differs from the sum of two audio-rate gain changing signals plus baseline gain.");
69     }
70
71     finishJSTest();
72 }
73
74 function runTest() {
75     if (window.testRunner) {
76         testRunner.dumpAsText();
77         testRunner.waitUntilDone();
78     }
79
80     window.jsTestIsAsync = true;
81
82     var sampleFrameLength = sampleRate * lengthInSeconds;
83
84     // Create offline audio context.
85     context = new webkitOfflineAudioContext(1, sampleFrameLength, sampleRate);
86
87     // Create buffer used by the source which will have its gain controlled.
88     var constantOneBuffer = createConstantBuffer(context, sampleFrameLength, 1);
89     var constantSource = context.createBufferSource();
90     constantSource.buffer = constantOneBuffer;
91
92     // Create 1st buffer used to control gain (a linear ramp).
93     linearRampBuffer = createLinearRampBuffer(context, sampleFrameLength);
94     var gainSource1 = context.createBufferSource();
95     gainSource1.buffer = linearRampBuffer;
96
97     // Create 2st buffer used to control gain (a simple sine wave tone).
98     toneBuffer = createToneBuffer(context, toneFrequency, lengthInSeconds, 1);
99     var gainSource2 = context.createBufferSource();
100     gainSource2.buffer = toneBuffer;
101
102     // Create a gain node controlling the gain of constantSource and make the connections.
103     var gainNode = context.createGainNode();
104
105     // Intrinsic baseline gain.
106     // This gain value should be summed with gainSource1 and gainSource2.
107     gainNode.gain.value = baselineGain;
108
109     constantSource.connect(gainNode);
110     gainNode.connect(context.destination);
111
112     // Connect two audio-rate signals to control the .gain AudioParam.
113     gainSource1.connect(gainNode.gain);
114     gainSource2.connect(gainNode.gain);
115
116     // Start all sources at time 0.
117     constantSource.noteOn(0);
118     gainSource1.noteOn(0);
119     gainSource2.noteOn(0);
120
121     context.oncomplete = checkResult;
122     context.startRendering();
123 }
124
125 runTest();
126 successfullyParsed = true;
127
128 </script>
129 <script src="../fast/js/resources/js-test-post.js"></script>
130
131 </body>
132 </html>