Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/note-grain-on-play.html

Issue 2581463002: Refactor WebAudio test directory (Closed)
Patch Set: Use correct path for wav result files Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 <script src="resources/audit-util.js"></script>
7 <script src="resources/audio-testing.js"></script>
8 <script src="resources/note-grain-on-testing.js"></script>
9 </head>
10
11 <body>
12 <div id="description"></div>
13 <div id="console"></div>
14
15 <script>
16 description("Test noteGrainOn offset rendering.");
17
18 // To test noteGrainOn, a single ramp signal is created.
19 // Various sections of the ramp are rendered by noteGrainOn() at
20 // different times, and we verify that the actual output
21 // consists of the correct section of the ramp at the correct
22 // time.
23
24 var linearRampBuffer;
25
26 // Array of the grain offset used for each ramp played.
27 var grainOffsetTime = [];
28
29 // Verify the received signal is a ramp from the correct section
30 // of our ramp signal.
31 function verifyGrain(renderedData, startFrame, endFrame, grainIndex) {
32 var grainOffsetFrame = timeToSampleFrame(grainOffsetTime[grainIndex], sampleRate);
33 var grainFrameLength = endFrame - startFrame;
34 var ramp = linearRampBuffer.getChannelData(0);
35 var isCorrect = true;
36
37 var expected;
38 var actual;
39 var frame;
40
41 for (var k = 0; k < grainFrameLength; ++k) {
42 if (renderedData[startFrame + k] != ramp[grainOffsetFrame + k]) {
43 expected = ramp[grainOffsetFrame + k];
44 actual = renderedData[startFrame + k];
45 frame = startFrame + k;
46 isCorrect = false;
47 break;
48 }
49 }
50 return { verified: isCorrect,
51 expected : expected ,
52 actual : actual,
53 frame : frame };
54 }
55
56 function checkResult(event) {
57 var buffer = event.renderedBuffer;
58 renderedData = buffer.getChannelData(0);
59 var nSamples = renderedData.length;
60
61 var success = true;
62
63 // Number of grains that we found that have incorrect data.
64 var invalidGrainDataCount = 0;
65
66 var startEndFrames = findStartAndEndSamples(renderedData);
67
68 // Verify the start and stop times. Not strictly needed for
69 // this test, but it's useful to know that if the ramp data
70 // appears to be incorrect.
71 success = success && verifyStartAndEndFrames(startEndFrames);
72
73 // Loop through each of the rendered grains and check that
74 // each grain contains our expected ramp.
75 for (var k = 0; k < startEndFrames.start.length; ++k) {
76 // Verify that the rendered data matches the expected
77 // section of our ramp signal.
78 var result = verifyGrain(renderedData, startEndFrames.start[k], st artEndFrames.end[k], k);
79
80 if (!result.verified) {
81 testFailed("Grain " + k + " incorrect. Expected " + result.ex pected + " but received " + result.actual + " at sample frame " + result.frame);
82 ++invalidGrainDataCount;
83 success = false;
84 }
85 }
86
87 if (!invalidGrainDataCount) {
88 testPassed("All " + numberOfTests + " grains contained the correct data.");
89 } else {
90 testFailed(invalidGrainDataCount + " grains out of " + numberOfTes ts + " did not contain the expected data.");
91 success = false;
92 }
93
94 if (success) {
95 testPassed("noteGrainOn offset rendering tests passed.");
96 } else {
97 testFailed("noteGrainOn offset rendering tests failed.");
98 }
99
100 finishJSTest();
101 }
102
103 function runTest() {
104 if (window.testRunner) {
105 testRunner.dumpAsText();
106 testRunner.waitUntilDone();
107 }
108
109 window.jsTestIsAsync = true;
110
111 // Create offline audio context.
112 context = new OfflineAudioContext(2, sampleRate * renderTime, sampleRa te);
113
114 // Create a linear ramp for testing noteGrainOn.
115 linearRampBuffer = createSignalBuffer(context,
116 function(k) {
117 // Want the ramp to start
118 // with 1, not 0.
119 return k + 1;
120 });
121
122 var grainInfo = playAllGrains(context, linearRampBuffer, numberOfTests );
123
124 grainOffsetTime = grainInfo.grainOffsetTimes;
125
126 context.oncomplete = checkResult;
127 context.startRendering();
128 }
129
130 runTest();
131 successfullyParsed = true;
132
133 </script>
134
135 </body>
136 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698