Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / webaudio / note-grain-on-play.html
blob6f6c3d9c34ae63c6c62266c0269347b80005a2ed
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html>
3 <head>
4 <script src="resources/compatibility.js"></script>
5 <script src="resources/audio-testing.js"></script>
6 <script src="resources/note-grain-on-testing.js"></script>
7 <script src="../resources/js-test.js"></script>
8 </head>
10 <body>
11 <div id="description"></div>
12 <div id="console"></div>
14 <script>
15 description("Test noteGrainOn offset rendering.");
17 // To test noteGrainOn, a single ramp signal is created.
18 // Various sections of the ramp are rendered by noteGrainOn() at
19 // different times, and we verify that the actual output
20 // consists of the correct section of the ramp at the correct
21 // time.
23 var linearRampBuffer;
25 // Array of the grain offset used for each ramp played.
26 var grainOffsetTime = [];
28 // Verify the received signal is a ramp from the correct section
29 // of our ramp signal.
30 function verifyGrain(renderedData, startFrame, endFrame, grainIndex) {
31 var grainOffsetFrame = timeToSampleFrame(grainOffsetTime[grainIndex], sampleRate);
32 var grainFrameLength = endFrame - startFrame;
33 var ramp = linearRampBuffer.getChannelData(0);
34 var isCorrect = true;
36 var expected;
37 var actual;
38 var frame;
40 for (var k = 0; k < grainFrameLength; ++k) {
41 if (renderedData[startFrame + k] != ramp[grainOffsetFrame + k]) {
42 expected = ramp[grainOffsetFrame + k];
43 actual = renderedData[startFrame + k];
44 frame = startFrame + k;
45 isCorrect = false;
46 break;
49 return { verified: isCorrect,
50 expected : expected ,
51 actual : actual,
52 frame : frame };
55 function checkResult(event) {
56 var buffer = event.renderedBuffer;
57 renderedData = buffer.getChannelData(0);
58 var nSamples = renderedData.length;
60 var success = true;
62 // Number of grains that we found that have incorrect data.
63 var invalidGrainDataCount = 0;
65 var startEndFrames = findStartAndEndSamples(renderedData);
67 // Verify the start and stop times. Not strictly needed for
68 // this test, but it's useful to know that if the ramp data
69 // appears to be incorrect.
70 success = success && verifyStartAndEndFrames(startEndFrames);
72 // Loop through each of the rendered grains and check that
73 // each grain contains our expected ramp.
74 for (var k = 0; k < startEndFrames.start.length; ++k) {
75 // Verify that the rendered data matches the expected
76 // section of our ramp signal.
77 var result = verifyGrain(renderedData, startEndFrames.start[k], startEndFrames.end[k], k);
79 if (!result.verified) {
80 testFailed("Grain " + k + " incorrect. Expected " + result.expected + " but received " + result.actual + " at sample frame " + result.frame);
81 ++invalidGrainDataCount;
82 success = false;
86 if (!invalidGrainDataCount) {
87 testPassed("All " + numberOfTests + " grains contained the correct data.");
88 } else {
89 testFailed(invalidGrainDataCount + " grains out of " + numberOfTests + " did not contain the expected data.");
90 success = false;
93 if (success) {
94 testPassed("noteGrainOn offset rendering tests passed.");
95 } else {
96 testFailed("noteGrainOn offset rendering tests failed.");
99 finishJSTest();
102 function runTest() {
103 if (window.testRunner) {
104 testRunner.dumpAsText();
105 testRunner.waitUntilDone();
108 window.jsTestIsAsync = true;
110 // Create offline audio context.
111 context = new OfflineAudioContext(2, sampleRate * renderTime, sampleRate);
113 // Create a linear ramp for testing noteGrainOn.
114 linearRampBuffer = createSignalBuffer(context,
115 function(k) {
116 // Want the ramp to start
117 // with 1, not 0.
118 return k + 1;
119 });
121 var grainInfo = playAllGrains(context, linearRampBuffer, numberOfTests);
123 grainOffsetTime = grainInfo.grainOffsetTimes;
125 context.oncomplete = checkResult;
126 context.startRendering();
129 runTest();
130 successfullyParsed = true;
132 </script>
134 </body>
135 </html>