Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / webaudio / dynamicscompressor-simple.html
1 <!DOCTYPE HTML>
2 <html>
3   <head>
4     <script src="../resources/js-test.js"></script>
5     <script src="resources/compatibility.js"></script>
6     <script type="text/javascript" src="resources/audio-testing.js"></script>
7   </head>
8
9   <body>
10     <div id="description"></div>
11     <div id="console"></div>
12     
13     <script>
14       description("Test pre-emphasis in DynamicsCompressor is removed");
15       var context;
16       var sampleRate = 44100;
17       var lengthInSeconds = 1;
18       var renderedData;
19       // This threshold experimentally determined. It depends on the the gain value of the gain node
20       // below and the dynamics compressor.  When the DynamicsCompressor had the pre-emphasis
21       // filters, the peak value is about 0.21.  Without it, the peak is about 0.84.
22       var peakThreshold = 0.83;
23
24       function checkResult(event) {
25         var renderedBuffer = event.renderedBuffer;
26         renderedData = renderedBuffer.getChannelData(0);
27         // Search for a peak in the last part of the data.
28         var startSample = sampleRate * (lengthInSeconds - .1);
29         var endSample = renderedData.length;
30         var k;
31         var peak = -1;
32
33         for (k = startSample; k < endSample; ++k) {
34           var sample = Math.abs(renderedData[k]);
35           if (peak < sample)
36              peak = sample;
37         }
38
39         if (peak >= peakThreshold) {
40           testPassed("Pre-emphasis effect not applied as expected..");
41         } else {
42           testFailed("Pre-emphasis caused output to be decreased to " + peak
43                      + " (expected >= " + peakThreshold + ")");
44         }
45
46         finishJSTest();
47       }
48
49       function runTest() {
50         if (!window.testRunner) {
51           testRunner.dumpAsTest();
52           testRunner.waitUntilDone();
53         }
54
55         window.jsTestIsAsync = true;
56       
57         context = new OfflineAudioContext(1, sampleRate * lengthInSeconds, sampleRate);
58         // Connect an oscillator to a gain node to the compressor.  The
59         // oscillator frequency is set to a high value for the (original)
60         // emphasis to kick in. The gain is a little extra boost to get the
61         // compressor enabled.
62         //
63         var osc = context.createOscillator();
64         osc.frequency.value = 15000;
65         var gain = context.createGain();
66         gain.gain.value = 1.5;
67         var compressor = context.createDynamicsCompressor();
68         osc.connect(gain);
69         gain.connect(compressor);
70         compressor.connect(context.destination);
71         osc.start();
72         context.oncomplete = checkResult;
73         context.startRendering();
74       }
75       
76       runTest();
77       successfullyParsed = true;
78
79     </script>
80     
81   </body>
82 </html>