Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / webaudio / waveshaper-limits.html
blobf50cd4e5cf0788a5a493873dc4c7b50886abac4d
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html>
3 <head>
4 <script src="../resources/js-test.js"></script>
5 <script src="resources/compatibility.js"></script>
6 </head>
8 <body>
9 <div id="description"></div>
10 <div id="console"></div>
12 <script>
13 description("Test WaveShaperNode including values outside the range of [-1,1]");
15 var context;
16 var bufferData;
17 var outputData;
18 var reference;
20 var sampleRate = 48000;
21 // Must be odd so we have an exact middle point.
22 var testFrames = 23;
23 var scale = 1 / ((testFrames - 1) / 2 - 1);
24 // Number of decimal digits to print
25 var decimals = 6;
26 // Required accuracy
27 var diffThreshold = Math.pow(10, -decimals);
29 // Generate reference data
30 function generateReference() {
31 // The curve data is 0, 1, 0, and the input data is a ramp from -1+eps to 1+eps. Then the
32 // output is a ramp from 0 to 1 back to 0.
33 var ref = new Float32Array(testFrames);
34 var midPoint = (testFrames - 1) / 2;
35 // First sample is below -1 at -1-scale.
36 ref[0] = 0;
37 // Generate ramp up to the mid-point
38 for (var k = 0; k < midPoint; ++k) {
39 ref[k + 1] = k * scale;
41 // The value at the mid-point must be 1, from the curve
42 ref[midPoint] = 1;
43 // Generate a ramp from 1 down to 0
44 for (var k = midPoint; k < testFrames - 1; ++k) {
45 ref[k + 1] = 2 - k * scale;
47 // The last sample is out of range at 1+scale
48 ref[testFrames - 1] = 0;
49 return ref;
52 function checkResult (event) {
53 outputData = event.renderedBuffer.getChannelData(0);
54 reference = generateReference();
55 var success = true;
56 // Verify that every output value matches our expected reference value.
57 for (var k = 0; k < outputData.length; ++k) {
58 var diff = outputData[k] - reference[k];
59 if (Math.abs(diff) <= diffThreshold) {
60 testPassed(bufferData[k].toFixed(decimals) + " -> " + outputData[k].toFixed(decimals) + ".");
61 } else {
62 testFailed(bufferData[k].toFixed(decimals) + " -> " + outputData[k].toFixed(decimals) + ", but expected " + reference[k].toFixed(decimals) + ".");
63 success = false;
67 if (success)
68 testPassed("All outputs matched expected results.");
69 else
70 testFailed("Some outputs did not match expected results.");
72 finishJSTest();
75 function runTest () {
76 if (window.testRunner) {
77 testRunner.dumpAsText();
78 testRunner.waitUntilDone();
81 window.jsTestIsAsync = true;
83 context = new OfflineAudioContext(1, testFrames, sampleRate);
84 // Create input values between -1.1 and 1.1
85 var buffer = context.createBuffer(1, testFrames, context.sampleRate);
86 bufferData = buffer.getChannelData(0);
87 var start = -1 - scale;
88 for (var k = 0; k < testFrames; ++k) {
89 bufferData[k] = k * scale + start;
92 var source = context.createBufferSource();
93 source.buffer = buffer;
95 // Create simple waveshaper. It should map -1 to 0, 0 to 1, and +1 to 0 and interpolate
96 // all points in between using a simple linear interpolator.
97 var shaper = context.createWaveShaper();
98 var curve = new Float32Array(3);
99 curve[0] = 0;
100 curve[1] = 1;
101 curve[2] = 0;
102 shaper.curve = curve;
103 source.connect(shaper);
104 shaper.connect(context.destination);
106 source.start();
107 context.oncomplete = checkResult;
108 context.startRendering();
111 runTest();
112 successfullyParsed = true;
113 </script>
114 </body>
115 </html>