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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/audioparam-summingjunction.html

Issue 2581463002: Refactor WebAudio test directory (Closed)
Patch Set: Use correct path for wav result files Created 3 years, 12 months 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>
2
3 <!--
4 Tests that multiple audio-rate signals (AudioNode outputs) can be connected to a n AudioParam
5 and that these signals are summed, along with the AudioParams intrinsic value.
6 -->
7
8 <html>
9 <head>
10 <script src="../resources/js-test.js"></script>
11 <script src="resources/compatibility.js"></script>
12 <script src="resources/audit-util.js"></script>
13 <script src="resources/audio-testing.js"></script>
14 <script src="resources/mix-testing.js"></script>
15
16 </head>
17 <body>
18
19 <script>
20
21 var sampleRate = 44100.0;
22 var lengthInSeconds = 1;
23
24 var context = 0;
25
26 // Buffers used by the two gain controlling sources.
27 var linearRampBuffer;
28 var toneBuffer;
29 var toneFrequency = 440;
30
31 // Arbitrary non-zero value.
32 var baselineGain = 5;
33
34 // Allow for a small round-off error.
35 var maxAllowedError = 1e-6;
36
37 function checkResult(event) {
38 var renderedBuffer = event.renderedBuffer;
39 var renderedData = renderedBuffer.getChannelData(0);
40
41 // Get buffer data from the two sources used to control gain.
42 var linearRampData = linearRampBuffer.getChannelData(0);
43 var toneData = toneBuffer.getChannelData(0);
44
45 var n = renderedBuffer.length;
46
47 if (n == linearRampBuffer.length) {
48 testPassed("Rendered signal is of correct length.");
49 } else {
50 testFailed("Rendered signal is not of correct length.");
51 }
52
53 // Check that the rendered result exactly matches the sum of the intrinsic g ain plus the two sources used to control gain.
54 // This is because we're changing the gain of a signal having constant value 1.
55 var success = true;
56 for (var i = 0; i < n; ++i) {
57 var expectedValue = baselineGain + linearRampData[i] + toneData[i];
58 var error = Math.abs(expectedValue - renderedData[i]);
59
60 if (error > maxAllowedError) {
61 success = false;
62 break;
63 }
64 }
65
66 if (success) {
67 testPassed("Rendered signal matches sum of two audio-rate gain changing signals plus baseline gain.");
68 } else {
69 testFailed("Rendered signal differs from the sum of two audio-rate gain changing signals plus baseline gain.");
70 }
71
72 finishJSTest();
73 }
74
75 function runTest() {
76 if (window.testRunner) {
77 testRunner.dumpAsText();
78 testRunner.waitUntilDone();
79 }
80
81 window.jsTestIsAsync = true;
82
83 var sampleFrameLength = sampleRate * lengthInSeconds;
84
85 // Create offline audio context.
86 context = new OfflineAudioContext(1, sampleFrameLength, sampleRate);
87
88 // Create buffer used by the source which will have its gain controlled.
89 var constantOneBuffer = createConstantBuffer(context, sampleFrameLength, 1);
90 var constantSource = context.createBufferSource();
91 constantSource.buffer = constantOneBuffer;
92
93 // Create 1st buffer used to control gain (a linear ramp).
94 linearRampBuffer = createLinearRampBuffer(context, sampleFrameLength);
95 var gainSource1 = context.createBufferSource();
96 gainSource1.buffer = linearRampBuffer;
97
98 // Create 2st buffer used to control gain (a simple sine wave tone).
99 toneBuffer = createToneBuffer(context, toneFrequency, lengthInSeconds, 1);
100 var gainSource2 = context.createBufferSource();
101 gainSource2.buffer = toneBuffer;
102
103 // Create a gain node controlling the gain of constantSource and make the co nnections.
104 var gainNode = context.createGain();
105
106 // Intrinsic baseline gain.
107 // This gain value should be summed with gainSource1 and gainSource2.
108 gainNode.gain.value = baselineGain;
109
110 constantSource.connect(gainNode);
111 gainNode.connect(context.destination);
112
113 // Connect two audio-rate signals to control the .gain AudioParam.
114 gainSource1.connect(gainNode.gain);
115 gainSource2.connect(gainNode.gain);
116
117 // Start all sources at time 0.
118 constantSource.start(0);
119 gainSource1.start(0);
120 gainSource2.start(0);
121
122 context.oncomplete = checkResult;
123 context.startRendering();
124 }
125
126 runTest();
127 successfullyParsed = true;
128
129 </script>
130
131 </body>
132 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698