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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/audioparam-clamp-time-to-current-time.html

Issue 2391893005: Implement clamping of AudioParam time. (Closed)
Patch Set: Address review comments Created 4 years, 2 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/webaudio/AudioParamTimeline.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <!doctype html>
2 <html>
3 <head>
4 <title>Test Clamping of AudioParam Time</title>
5 <script src="../resources/testharness.js"></script>
6 <script src="../resources/testharnessreport.js"></script>
7 <script src="resources/audio-testing.js"></script>
8 </head>
9
10 <body>
11 <script>
12 // Fairly arbitrary sample rate and render frames.
13 var sampleRate = 24000;
14 var renderFrames = 1024;
15
16 var audit = Audit.createTaskRunner();
17
18 audit.defineTask("setValue", function (taskDone) {
19 var suspendFrame = 128;
20 createGraph({
21 suspendFrame: suspendFrame,
22 method: "setValueAtTime",
23 initialGain: 0,
24 arg0: 1,
25 })
26 .then(function (resultBuffer) {
27 // Just verify that the cosine wave actually started at
28 // suspendFrame.
29 var result = resultBuffer.getChannelData(0);
30 var success = true;
31
32 success = Should("Output[0-" + (suspendFrame - 1) + "]",
33 result.slice(0, suspendFrame))
34 .beConstantValueOf(0) && success;
35 success = Should("Output[" + suspendFrame + "-" + (
36 renderFrames - 1) + "]",
37 result.slice(suspendFrame))
38 .beConstantValueOf(1) && success;
39
40 Should("*** setValueAtTime in the past", success)
41 .summarize(
42 "correctly clamped to current time",
43 "was not correctly clamped to current time");
44 })
45 .then(taskDone);
46 });
47
48 audit.defineTask("linear", function (taskDone) {
49 var suspendFrame = 128;
50 createGraph({
51 suspendFrame: suspendFrame,
52 method: "linearRampToValueAtTime",
53 initialGain: 1,
54 arg0: 0.5
55 })
56 .then(function (resultBuffer) {
57 // Just verify that the cosine wave actually started at
58 // suspendFrame.
59 var result = resultBuffer.getChannelData(0);
60 var success = true;
61
62 success = Should("Output[0-" + (suspendFrame - 1) + "]",
63 result.slice(0, suspendFrame))
64 .beConstantValueOf(1) && success;
65 success = Should("Output[" + suspendFrame + "-" + (
66 renderFrames - 1) + "]",
67 result.slice(suspendFrame))
68 .beConstantValueOf(0.5) && success;
69
70 Should("*** linearRampToValueAtTime in the past", success)
71 .summarize(
72 "correctly clamped to current time",
73 "was not correctly clamped to current time");
74 })
75 .then(taskDone);
76 });
77
78 audit.defineTask("exponential", function (taskDone) {
79 var suspendFrame = 128;
80 createGraph({
81 suspendFrame: suspendFrame,
82 method: "exponentialRampToValueAtTime",
83 initialGain: 1,
84 arg0: 0.5
85 })
86 .then(function (resultBuffer) {
87 // Just verify that the cosine wave actually started at
88 // suspendFrame.
89 var result = resultBuffer.getChannelData(0);
90 var success = true;
91
92 success = Should("Output[0-" + (suspendFrame - 1) + "]",
93 result.slice(0, suspendFrame))
94 .beConstantValueOf(1) && success;
95 success = Should("Output[" + suspendFrame + "-" + (
96 renderFrames - 1) + "]",
97 result.slice(suspendFrame))
98 .beConstantValueOf(0.5) && success;
99
100 Should("*** exponentialRampToValueAtTime in the past",
101 success)
102 .summarize(
103 "correctly clamped to current time",
104 "was not correctly clamped to current time");
105 })
106 .then(taskDone);
107 });
108
109 audit.defineTask("setTarget", function (taskDone) {
110 var suspendFrame = 128;
111 createGraph({
112 suspendFrame: suspendFrame,
113 method: "setTargetAtTime",
114 initialGain: 1,
115 arg0: 0.5,
116 moreArgs: 0.1
117 })
118 .then(function (resultBuffer) {
119 // Just verify that the cosine wave actually started at
120 // suspendFrame.
121 var result = resultBuffer.getChannelData(0);
122 var success = true;
123
124 success = Should("Output[0-" + (suspendFrame - 1) + "]",
125 result.slice(0, suspendFrame))
126 .beConstantValueOf(1) && success;
127 // For the samples past the suspend time, we only care that first
128 // value is 1 and that the rest are not zero.
129 success = Should("Output[" + suspendFrame + "]",
130 result[suspendFrame]).beEqualTo(1) && success;
131
132 var positive = result.slice(suspendFrame + 1).every(x => x >
133 0);
134 success = Should("Output[" + (suspendFrame + 1) + "-" +
135 (renderFrames - 1) + "] contains only positive values",
136 positive)
137 .beEqualTo(true) && success;
138
139 Should("*** setTargetAtTime in the past", success)
140 .summarize(
141 "correctly clamped to current time",
142 "was not correctly clamped to current time");
143 })
144 .then(taskDone);
145 });
146
147 audit.defineTask("setValueCurve", function (taskDone) {
148 var suspendFrame = 128;
149 createGraph({
150 suspendFrame: suspendFrame,
151 method: "setValueCurveAtTime",
152 initialGain: 1,
153 arg0: Float32Array.from([2, 3]),
154 moreArgs: 0.1
155 })
156 .then(function (resultBuffer) {
157 // Just verify that the cosine wave actually started at
158 // suspendFrame.
159 var result = resultBuffer.getChannelData(0);
160 var success = true;
161
162 success = Should("Output[0-" + (suspendFrame - 1) + "]",
163 result.slice(0, suspendFrame))
164 .beConstantValueOf(1) && success;
165
166 // The selected curve contains values greater than or equal to 2.
167 // Just verify that all values are greater than or equal to 2.
168 var biggerThan2 = result.slice(suspendFrame).every(x => x >=
169 2);
170 success = Should("Output[" + suspendFrame + "-" + (
171 renderFrames - 1) + "]",
172 biggerThan2)
173 .beEqualTo(true) && success;
174
175 Should("*** setValueCurveAtTime in the past", success)
176 .summarize(
177 "correctly clamped to current time",
178 "was not correctly clamped to current time");
179 })
180 .then(taskDone);
181 });
182
183
184 // Create the test graph consisting of a constant source followed by a
185 // gain node. The gain node automations will be tested. |options|
186 // specifies the parameters for the test including
187 //
188 // suspendFrame: time at which we schedule the automation call
189 // method: the name of automation method to be tested
190 // initialGain: the initial gain at time 0 for the gain node
191 // arg0: the first argument to be supplied to the automation method.
192 // moreArgs: An array of any additional arguments for the automation met hod.
193 function createGraph(options) {
194 var context = new OfflineAudioContext(1, renderFrames, sampleRate);
195
196 var cosineWave = new PeriodicWave(context, {
197 real: [0, 1]
198 });
199
200 var src = new OscillatorNode(context, {
201 periodicWave: cosineWave,
202 frequency: 0
203 });
204
205 // The gain node whose automations we're testing.
206 var gain = new GainNode(context, {
207 gain: 0
208 });
209
210 src.connect(gain).connect(context.destination);
211
212 gain.gain.setValueAtTime(options.initialGain, 0);
213
214 // Suspend rendering so that we can call the automation method at the
215 // right time. |startTime| is the time for the automation method. It
216 // must be some time before the suspend time.
217 var suspendFrame = options.suspendFrame;
218 var startTime = (suspendFrame / 2) / context.sampleRate;
219 context.suspend(suspendFrame / context.sampleRate)
220 .then(function () {
221 // Call the appropriate automation method with the desired
222 // automation value, time, and any other arguments needed.
223 gain.gain[options.method](...[options.arg0, startTime, options.moreA rgs]);
224 })
225 .then(context.resume.bind(context));
226
227 // Start the source and begin rendering, returning the promise from
228 // rendering.
229 src.start();
230
231 return context.startRendering();
232 }
233
234 audit.runTasks();
235 </script>
236 </body>
237 </html>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/webaudio/AudioParamTimeline.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698