Merge "[Release] Webkit2-efl-123997_0.11.77" into tizen_2.2
[framework/web/webkit-efl.git] / LayoutTests / webaudio / audioparam-connect-audioratesignal.html
1 <!DOCTYPE html>
2
3 <!--
4 Tests that an audio-rate signal (AudioNode output) can be connected to an AudioParam.
5 Specifically, this tests that an audio-rate signal coming from an AudioBufferSourceNode
6 playing an AudioBuffer containing a specific curve can be connected to an AudioGainNode's
7 .gain attribute (an AudioParam).  Another AudioBufferSourceNode will be the audio source
8 having its gain changed.  We load this one with an AudioBuffer containing a constant value of 1.
9 Thus it's easy to check that the resultant signal should be equal to the gain-scaling curve.
10 -->
11
12 <html>
13 <head>
14 <link rel="stylesheet" href="../fast/js/resources/js-test-style.css"/>
15 <script src="resources/audio-testing.js"></script>
16 <script src="../fast/js/resources/js-test-pre.js"></script>
17
18 </head>
19 <body>
20
21 <script>
22
23 var sampleRate = 44100.0;
24 var lengthInSeconds = 1;
25
26 var context = 0;
27 var constantOneBuffer = 0;
28 var linearRampBuffer = 0;
29
30 function checkResult(event) {
31     var renderedBuffer = event.renderedBuffer;
32     var renderedData = renderedBuffer.getChannelData(0);
33     var expectedData = linearRampBuffer.getChannelData(0);
34     var n = renderedBuffer.length;
35
36     if (n == linearRampBuffer.length) {
37         testPassed("Rendered signal is of correct length.");
38     } else {
39         testFailed("Rendered signal is not of correct length.");
40     }
41
42     // Check that the rendered result exactly matches the buffer used to control gain.
43     // This is because we're changing the gain of a signal having constant value 1.
44     var success = true;
45     for (var i = 0; i < n; ++i) {
46         if (renderedData[i] != expectedData[i]) {
47             success = false;
48             break;
49         }
50     }
51
52     if (success) {
53         testPassed("Rendered signal exactly matches the audio-rate gain changing signal.");
54     } else {
55         testFailed("Rendered signal differs from the audio-rate gain changing signal.");
56     }
57
58     finishJSTest();
59 }
60
61 function runTest() {
62     if (window.testRunner) {
63         testRunner.dumpAsText();
64         testRunner.waitUntilDone();
65     }
66
67     window.jsTestIsAsync = true;
68
69     var sampleFrameLength = sampleRate * lengthInSeconds;
70
71     // Create offline audio context.
72     context = new webkitOfflineAudioContext(1, sampleFrameLength, sampleRate);
73
74     // Create buffer used by the source which will have its gain controlled.
75     constantOneBuffer = createConstantBuffer(context, sampleFrameLength, 1);
76
77     // Create buffer used to control gain.
78     linearRampBuffer = createLinearRampBuffer(context, sampleFrameLength);
79
80     // Create the two sources.
81
82     var constantSource = context.createBufferSource();
83     constantSource.buffer = constantOneBuffer;
84
85     var gainChangingSource = context.createBufferSource();
86     gainChangingSource.buffer = linearRampBuffer;
87
88     // Create a gain node controlling the gain of constantSource and make the connections.
89     var gainNode = context.createGainNode();
90
91     // Intrinsic baseline gain of zero.
92     gainNode.gain.value = 0;
93
94     constantSource.connect(gainNode);
95     gainNode.connect(context.destination);
96
97     // Connect an audio-rate signal to control the .gain AudioParam.
98     // This is the heart of what is being tested.
99     gainChangingSource.connect(gainNode.gain);
100
101     // Start both sources at time 0.
102     constantSource.noteOn(0);
103     gainChangingSource.noteOn(0);
104
105     context.oncomplete = checkResult;
106     context.startRendering();
107 }
108
109 runTest();
110 successfullyParsed = true;
111
112 </script>
113 <script src="../fast/js/resources/js-test-post.js"></script>
114
115 </body>
116 </html>