OLD | NEW |
1 var sampleRate = 44100; | 1 var sampleRate = 44100; |
2 | 2 |
3 // Information about the starting/ending times and starting/ending values for ea
ch time interval. | 3 // Information about the starting/ending times and starting/ending values for ea
ch time interval. |
4 var timeValueInfo; | 4 var timeValueInfo; |
5 | 5 |
6 // The difference between starting values between each time interval. | 6 // The difference between starting values between each time interval. |
7 var startingValueDelta; | 7 var startingValueDelta; |
8 | 8 |
9 // For any automation function that has an end or target value, the end value is
based the starting | 9 // For any automation function that has an end or target value, the end value is
based the starting |
10 // value of the time interval. The starting value will be increased or decrease
d by | 10 // value of the time interval. The starting value will be increased or decrease
d by |
(...skipping 15 matching lines...) Expand all Loading... |
26 var gainNode; | 26 var gainNode; |
27 | 27 |
28 var context; | 28 var context; |
29 | 29 |
30 // Make sure we render long enough to capture all of our test data. | 30 // Make sure we render long enough to capture all of our test data. |
31 function renderLength(numberOfTests) | 31 function renderLength(numberOfTests) |
32 { | 32 { |
33 return timeToSampleFrame((numberOfTests + 1) * timeInterval, sampleRate); | 33 return timeToSampleFrame((numberOfTests + 1) * timeInterval, sampleRate); |
34 } | 34 } |
35 | 35 |
36 // Create a buffer containing the same constant value. | |
37 function createConstantBuffer(context, constant, length) { | |
38 var buffer = context.createBuffer(1, length, context.sampleRate); | |
39 var n = buffer.length; | |
40 var data = buffer.getChannelData(0); | |
41 | |
42 for (var k = 0; k < n; ++k) { | |
43 data[k] = constant; | |
44 } | |
45 | |
46 return buffer; | |
47 } | |
48 | |
49 // Create a constant reference signal with the given |value|. Basically the sam
e as | 36 // Create a constant reference signal with the given |value|. Basically the sam
e as |
50 // |createConstantBuffer|, but with the parameters to match the other create fun
ctions. The | 37 // |createConstantBuffer|, but with the parameters to match the other create fun
ctions. The |
51 // |endValue| is ignored. | 38 // |endValue| is ignored. |
52 function createConstantArray(startTime, endTime, value, endValue, sampleRate) | 39 function createConstantArray(startTime, endTime, value, endValue, sampleRate) |
53 { | 40 { |
54 var startFrame = timeToSampleFrame(startTime, sampleRate); | 41 var startFrame = timeToSampleFrame(startTime, sampleRate); |
55 var endFrame = timeToSampleFrame(endTime, sampleRate); | 42 var endFrame = timeToSampleFrame(endTime, sampleRate); |
56 var length = endFrame - startFrame; | 43 var length = endFrame - startFrame; |
57 | 44 |
58 var buffer = createConstantBuffer(context, value, length); | 45 var buffer = createConstantBuffer(context, length, value); |
59 | 46 |
60 return buffer.getChannelData(0); | 47 return buffer.getChannelData(0); |
61 } | 48 } |
62 | 49 |
| 50 function getStartEndFrames(startTime, endTime, sampleRate) |
| 51 { |
| 52 // Start frame is the ceiling of the start time because the ramp |
| 53 // starts at or after the sample frame. End frame is the ceiling |
| 54 // because it's the exclusive ending frame of the automation. |
| 55 var startFrame = Math.ceil(startTime * sampleRate); |
| 56 var endFrame = Math.ceil(endTime * sampleRate); |
| 57 |
| 58 return {startFrame: startFrame, endFrame: endFrame}; |
| 59 } |
| 60 |
63 // Create a linear ramp starting at |startValue| and ending at |endValue|. The
ramp starts at time | 61 // Create a linear ramp starting at |startValue| and ending at |endValue|. The
ramp starts at time |
64 // |startTime| and ends at |endTime|. (The start and end times are only used to
compute how many | 62 // |startTime| and ends at |endTime|. (The start and end times are only used to
compute how many |
65 // samples to return.) | 63 // samples to return.) |
66 function createLinearRampArray(startTime, endTime, startValue, endValue, sampleR
ate) | 64 function createLinearRampArray(startTime, endTime, startValue, endValue, sampleR
ate) |
67 { | 65 { |
68 var startFrame = timeToSampleFrame(startTime, sampleRate); | 66 var frameInfo = getStartEndFrames(startTime, endTime, sampleRate); |
69 var endFrame = timeToSampleFrame(endTime, sampleRate); | 67 var startFrame = frameInfo.startFrame; |
| 68 var endFrame = frameInfo.endFrame; |
70 var length = endFrame - startFrame; | 69 var length = endFrame - startFrame; |
71 var array = new Array(length); | 70 var array = new Array(length); |
72 | 71 |
73 var step = (endValue - startValue) / length; | 72 var step = Math.fround((endValue - startValue) / (endTime - startTime) / sam
pleRate); |
| 73 var start = Math.fround(startValue + (endValue - startValue) * (startFrame /
sampleRate - startTime) / (endTime - startTime)); |
74 | 74 |
| 75 var slope = (endValue - startValue) / (endTime - startTime); |
| 76 |
| 77 // v(t) = v0 + (v1 - v0)*(t-t0)/(t1-t0) |
75 for (k = 0; k < length; ++k) { | 78 for (k = 0; k < length; ++k) { |
76 array[k] = startValue + k * step; | 79 //array[k] = Math.fround(start + k * step); |
| 80 var t = (startFrame + k) / sampleRate; |
| 81 array[k] = startValue + slope * (t - startTime); |
77 } | 82 } |
78 | 83 |
79 return array; | 84 return array; |
80 } | 85 } |
81 | 86 |
82 // Create an exponential ramp starting at |startValue| and ending at |endValue|.
The ramp starts at | 87 // Create an exponential ramp starting at |startValue| and ending at |endValue|.
The ramp starts at |
83 // time |startTime| and ends at |endTime|. (The start and end times are only us
ed to compute how | 88 // time |startTime| and ends at |endTime|. (The start and end times are only us
ed to compute how |
84 // many samples to return.) | 89 // many samples to return.) |
85 function createExponentialRampArray(startTime, endTime, startValue, endValue, sa
mpleRate) | 90 function createExponentialRampArray(startTime, endTime, startValue, endValue, sa
mpleRate) |
86 { | 91 { |
87 var startFrame = timeToSampleFrame(startTime, sampleRate); | 92 var deltaTime = endTime - startTime; |
88 var endFrame = timeToSampleFrame(endTime, sampleRate); | 93 |
| 94 var frameInfo = getStartEndFrames(startTime, endTime, sampleRate); |
| 95 var startFrame = frameInfo.startFrame; |
| 96 var endFrame = frameInfo.endFrame; |
89 var length = endFrame - startFrame; | 97 var length = endFrame - startFrame; |
90 var array = new Array(length); | 98 var array = new Array(length); |
91 | 99 |
92 var multiplier = Math.pow(endValue / startValue, 1 / length); | 100 var ratio = endValue / startValue; |
93 | 101 |
| 102 // v(t) = v0*(v1/v0)^((t-t0)/(t1-t0)) |
94 for (var k = 0; k < length; ++k) { | 103 for (var k = 0; k < length; ++k) { |
95 array[k] = startValue * Math.pow(multiplier, k); | 104 var t = Math.fround((startFrame + k) / sampleRate); |
| 105 array[k] = Math.fround(startValue * Math.pow(ratio, (t - startTime) / de
ltaTime)); |
96 } | 106 } |
97 | 107 |
98 return array; | 108 return array; |
99 } | 109 } |
100 | 110 |
101 function discreteTimeConstantForSampleRate(timeConstant, sampleRate) | 111 function discreteTimeConstantForSampleRate(timeConstant, sampleRate) |
102 { | 112 { |
103 return 1 - Math.exp(-1 / (sampleRate * timeConstant)); | 113 return 1 - Math.exp(-1 / (sampleRate * timeConstant)); |
104 } | 114 } |
105 | 115 |
106 // Create a signal that starts at |startValue| and exponentially approaches the
target value of | 116 // Create a signal that starts at |startValue| and exponentially approaches the
target value of |
107 // |targetValue|, using a time constant of |timeConstant|. The ramp starts at t
ime |startTime| and | 117 // |targetValue|, using a time constant of |timeConstant|. The ramp starts at t
ime |startTime| and |
108 // ends at |endTime|. (The start and end times are only used to compute how man
y samples to | 118 // ends at |endTime|. (The start and end times are only used to compute how man
y samples to |
109 // return.) | 119 // return.) |
110 function createExponentialApproachArray(startTime, endTime, startValue, targetVa
lue, sampleRate, timeConstant) | 120 function createExponentialApproachArray(startTime, endTime, startValue, targetVa
lue, sampleRate, timeConstant) |
111 { | 121 { |
112 var startFrame = timeToSampleFrame(startTime, sampleRate); | 122 var startFrameFloat = startTime * sampleRate; |
113 var endFrame = timeToSampleFrame(endTime, sampleRate); | 123 var frameInfo = getStartEndFrames(startTime, endTime, sampleRate); |
114 var length = endFrame - startFrame; | 124 var startFrame = frameInfo.startFrame; |
| 125 var endFrame = frameInfo.endFrame; |
| 126 var length = Math.floor(endFrame - startFrame); |
115 var array = new Array(length); | 127 var array = new Array(length); |
116 var c = discreteTimeConstantForSampleRate(timeConstant, sampleRate); | 128 var c = discreteTimeConstantForSampleRate(timeConstant, sampleRate); |
117 | 129 |
118 var value = startValue; | 130 var delta = startValue - targetValue; |
119 | 131 |
| 132 // v(t) = v1 + (v0 - v1) * exp(-(t-t0)/tau) |
120 for (var k = 0; k < length; ++k) { | 133 for (var k = 0; k < length; ++k) { |
| 134 var t = (startFrame + k) / sampleRate; |
| 135 var value = targetValue + delta * Math.exp(-(t - startTime) / timeConsta
nt); |
121 array[k] = value; | 136 array[k] = value; |
122 value += (targetValue - value) * c; | |
123 } | 137 } |
124 | 138 |
125 return array; | 139 return array; |
| 140 } |
| 141 |
| 142 // Create a sine wave of the specified duration. |
| 143 function createReferenceSineArray(startTime, endTime, startValue, endValue, samp
leRate) |
| 144 { |
| 145 // Ignore |startValue| and |endValue| for the sine wave. |
| 146 var curve = createSineWaveArray(endTime - startTime, freqHz, sineAmplitude,
sampleRate); |
| 147 // Sample the curve appropriately. |
| 148 var frameInfo = getStartEndFrames(startTime, endTime, sampleRate); |
| 149 var startFrame = frameInfo.startFrame; |
| 150 var endFrame = frameInfo.endFrame; |
| 151 var length = Math.floor(endFrame - startFrame); |
| 152 var array = new Array(length); |
| 153 |
| 154 // v(t) = linearly interpolate between V[k] and V[k + 1] where k = floor(N/d
uration*(t - t0)) |
| 155 var f = length / (endTime - startTime); |
| 156 |
| 157 for (var k = 0; k < length; ++k) { |
| 158 var t = (startFrame + k) / sampleRate; |
| 159 var indexFloat = f * (t - startTime); |
| 160 var index = Math.floor(indexFloat); |
| 161 if (index + 1 < length) { |
| 162 var v0 = curve[index]; |
| 163 var v1 = curve[index + 1]; |
| 164 array[k] = v0 + (v1 - v0) * (indexFloat - index); |
| 165 } else { |
| 166 array[k] = curve[length - 1]; |
| 167 } |
| 168 } |
| 169 |
| 170 return array; |
126 } | 171 } |
127 | 172 |
128 // Create a sine wave of the given frequency and amplitude. The sine wave is of
fset by half the | 173 // Create a sine wave of the given frequency and amplitude. The sine wave is of
fset by half the |
129 // amplitude so that result is always positive. | 174 // amplitude so that result is always positive. |
130 function createSineWaveArray(durationSeconds, freqHz, amplitude, sampleRate) | 175 function createSineWaveArray(durationSeconds, freqHz, amplitude, sampleRate) |
131 { | 176 { |
132 var length = timeToSampleFrame(durationSeconds, sampleRate); | 177 var length = timeToSampleFrame(durationSeconds, sampleRate); |
133 var signal = new Float32Array(length); | 178 var signal = new Float32Array(length); |
134 var omega = 2 * Math.PI * freqHz / sampleRate; | 179 var omega = 2 * Math.PI * freqHz / sampleRate; |
135 var halfAmplitude = amplitude / 2; | 180 var halfAmplitude = amplitude / 2; |
(...skipping 10 matching lines...) Expand all Loading... |
146 // value. | 191 // value. |
147 function endValueDelta(timeIntervalIndex) | 192 function endValueDelta(timeIntervalIndex) |
148 { | 193 { |
149 if (timeIntervalIndex & 1) { | 194 if (timeIntervalIndex & 1) { |
150 return -startEndValueChange; | 195 return -startEndValueChange; |
151 } else { | 196 } else { |
152 return startEndValueChange; | 197 return startEndValueChange; |
153 } | 198 } |
154 } | 199 } |
155 | 200 |
| 201 // Relative error metric |
| 202 function relativeErrorMetric(actual, expected) |
| 203 { |
| 204 return (actual - expected) / Math.abs(expected); |
| 205 } |
| 206 |
| 207 // Difference metric |
| 208 function differenceErrorMetric(actual, expected) |
| 209 { |
| 210 return actual - expected; |
| 211 } |
| 212 |
156 // Return the difference between the starting value at |timeIntervalIndex| and t
he starting value at | 213 // Return the difference between the starting value at |timeIntervalIndex| and t
he starting value at |
157 // the next time interval. Since we started at a large initial value, we decrea
se the value at each | 214 // the next time interval. Since we started at a large initial value, we decrea
se the value at each |
158 // time interval. | 215 // time interval. |
159 function valueUpdate(timeIntervalIndex) | 216 function valueUpdate(timeIntervalIndex) |
160 { | 217 { |
161 return -startingValueDelta; | 218 return -startingValueDelta; |
162 } | 219 } |
163 | 220 |
164 // Compare a section of the rendered data against our expected signal. | 221 // Compare a section of the rendered data against our expected signal. |
165 function comparePartialSignals(rendered, expectedFunction, startTime, endTime, v
alueInfo, sampleRate) | 222 function comparePartialSignals(rendered, expectedFunction, startTime, endTime, v
alueInfo, sampleRate, errorMetric) |
166 { | 223 { |
167 var startSample = timeToSampleFrame(startTime, sampleRate); | 224 var startSample = timeToSampleFrame(startTime, sampleRate); |
168 var expected = expectedFunction(startTime, endTime, valueInfo.startValue, va
lueInfo.endValue, sampleRate, timeConstant); | 225 var expected = expectedFunction(startTime, endTime, valueInfo.startValue, va
lueInfo.endValue, sampleRate, timeConstant); |
169 | 226 |
170 var n = expected.length; | 227 var n = expected.length; |
171 var maxError = -1; | 228 var maxError = -1; |
172 var maxErrorIndex = -1; | 229 var maxErrorIndex = -1; |
173 | 230 |
174 for (var k = 0; k < n; ++k) { | 231 for (var k = 0; k < n; ++k) { |
175 // Make sure we don't pass these tests because a NaN has been generated
in either the | 232 // Make sure we don't pass these tests because a NaN has been generated
in either the |
176 // rendered data or the reference data. | 233 // rendered data or the reference data. |
177 if (!isValidNumber(rendered[startSample + k])) { | 234 if (!isValidNumber(rendered[startSample + k])) { |
178 maxError = Infinity; | 235 maxError = Infinity; |
179 maxErrorIndex = startSample + k; | 236 maxErrorIndex = startSample + k; |
180 testFailed("NaN or infinity for rendered data at " + maxErrorIndex); | 237 testFailed("NaN or infinity for rendered data at " + maxErrorIndex); |
181 break; | 238 break; |
182 } | 239 } |
183 if (!isValidNumber(expected[k])) { | 240 if (!isValidNumber(expected[k])) { |
184 maxError = Infinity; | 241 maxError = Infinity; |
185 maxErrorIndex = startSample + k; | 242 maxErrorIndex = startSample + k; |
186 testFailed("Nan or infinity for reference data at " + maxErrorIndex)
; | 243 testFailed("Nan or infinity for reference data at " + maxErrorIndex)
; |
187 break; | 244 break; |
188 } | 245 } |
189 var error = Math.abs(rendered[startSample + k] - expected[k]); | 246 var error = Math.abs(errorMetric(rendered[startSample + k], expected[k])
); |
190 if (error > maxError) { | 247 if (error > maxError) { |
191 maxError = error; | 248 maxError = error; |
192 maxErrorIndex = k; | 249 maxErrorIndex = k; |
193 } | 250 } |
194 } | 251 } |
195 | 252 |
196 return {maxError : maxError, index : maxErrorIndex}; | 253 return {maxError : maxError, index : maxErrorIndex, expected: expected}; |
197 } | 254 } |
198 | 255 |
199 // Find the discontinuities in the data and compare the locations of the discont
inuities with the | 256 // Find the discontinuities in the data and compare the locations of the discont
inuities with the |
200 // times that define the time intervals. There is a discontinuity if the differe
nce between | 257 // times that define the time intervals. There is a discontinuity if the differe
nce between |
201 // successive samples exceeds the threshold. | 258 // successive samples exceeds the threshold. |
202 function verifyDiscontinuities(values, times, threshold) | 259 function verifyDiscontinuities(values, times, threshold) |
203 { | 260 { |
204 var n = values.length; | 261 var n = values.length; |
205 var success = true; | 262 var success = true; |
206 var badLocations = 0; | 263 var badLocations = 0; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 // maxError - maximum allowed difference between the rendered data and the expec
ted data | 320 // maxError - maximum allowed difference between the rendered data and the expec
ted data |
264 // | 321 // |
265 // rendererdData - array containing the rendered (actual) data | 322 // rendererdData - array containing the rendered (actual) data |
266 // | 323 // |
267 // expectedFunction - function to compute the expected data | 324 // expectedFunction - function to compute the expected data |
268 // | 325 // |
269 // timeValueInfo - array containing information about the start and end times an
d the start and end | 326 // timeValueInfo - array containing information about the start and end times an
d the start and end |
270 // values of each interval. | 327 // values of each interval. |
271 // | 328 // |
272 // breakThreshold - threshold to use for determining discontinuities. | 329 // breakThreshold - threshold to use for determining discontinuities. |
273 function compareSignals(testName, maxError, renderedData, expectedFunction, time
ValueInfo, breakThreshold) | 330 function compareSignals(testName, maxError, renderedData, expectedFunction, time
ValueInfo, breakThreshold, errorMetric) |
274 { | 331 { |
275 var success = true; | 332 var success = true; |
276 var failedTestCount = 0; | 333 var failedTestCount = 0; |
277 var times = timeValueInfo.times; | 334 var times = timeValueInfo.times; |
278 var values = timeValueInfo.values; | 335 var values = timeValueInfo.values; |
279 var n = values.length; | 336 var n = values.length; |
| 337 var expectedSignal = []; |
280 | 338 |
281 success = verifyDiscontinuities(renderedData, times, breakThreshold); | 339 success = verifyDiscontinuities(renderedData, times, breakThreshold); |
282 | 340 |
283 for (var k = 0; k < n; ++k) { | 341 for (var k = 0; k < n; ++k) { |
284 var result = comparePartialSignals(renderedData, expectedFunction, times
[k], times[k + 1], values[k], sampleRate); | 342 var result = comparePartialSignals(renderedData, expectedFunction, times
[k], times[k + 1], values[k], sampleRate, errorMetric); |
| 343 |
| 344 expectedSignal = expectedSignal.concat(Array.prototype.slice.call(result
.expected)); |
285 | 345 |
286 if (result.maxError > maxError) { | 346 if (result.maxError > maxError) { |
287 testFailed("Incorrect value for test " + k + ". Max error = " + resu
lt.maxError + " at offset " + (result.index + timeToSampleFrame(times[k], sample
Rate))); | 347 var offset = result.index + timeToSampleFrame(times[k], sampleRate); |
| 348 testFailed("Incorrect value for test " + k + ". Max error = " + resu
lt.maxError |
| 349 + " at offset " + offset |
| 350 + ": actual = " + renderedData[offset] |
| 351 + ", expected = " + expectedSignal[offset] + "."); |
288 ++failedTestCount; | 352 ++failedTestCount; |
289 } | 353 } |
290 } | 354 } |
291 | 355 |
292 if (failedTestCount) { | 356 if (failedTestCount) { |
293 testFailed(failedTestCount + " tests failed out of " + n); | 357 testFailed(failedTestCount + " tests failed out of " + n); |
294 success = false; | 358 success = false; |
295 } else { | 359 } else { |
296 testPassed("All " + n + " tests passed within an acceptable tolerance.")
; | 360 testPassed("All " + n + " tests passed within an acceptable relative tol
erance of " + maxError + "."); |
297 } | 361 } |
298 | 362 |
299 if (success) { | 363 if (success) { |
300 testPassed("AudioParam " + testName + " test passed."); | 364 testPassed("AudioParam " + testName + " test passed."); |
301 } else { | 365 } else { |
302 testFailed("AudioParam " + testName + " test failed."); | 366 testFailed("AudioParam " + testName + " test failed."); |
303 } | 367 } |
304 } | 368 } |
305 | 369 |
306 // Create a function to test the rendered data with the reference data. | 370 // Create a function to test the rendered data with the reference data. |
307 // | 371 // |
308 // testName - string describing the test | 372 // testName - string describing the test |
309 // | 373 // |
310 // error - max allowed error between rendered data and the reference data. | 374 // error - max allowed error between rendered data and the reference data. |
311 // | 375 // |
312 // referenceFunction - function that generates the reference data to be compared
with the rendered | 376 // referenceFunction - function that generates the reference data to be compared
with the rendered |
313 // data. | 377 // data. |
314 // | 378 // |
315 // jumpThreshold - optional parameter that specifies the threshold to use for de
tecting | 379 // jumpThreshold - optional parameter that specifies the threshold to use for de
tecting |
316 // discontinuities. If not specified, defaults to discontinuityThreshold. | 380 // discontinuities. If not specified, defaults to discontinuityThreshold. |
317 // | 381 // |
318 function checkResultFunction(testName, error, referenceFunction, jumpThreshold) | 382 function checkResultFunction(testName, error, referenceFunction, jumpThreshold,
errorMetric) |
319 { | 383 { |
320 return function(event) { | 384 return function(event) { |
321 var buffer = event.renderedBuffer; | 385 var buffer = event.renderedBuffer; |
322 renderedData = buffer.getChannelData(0); | 386 renderedData = buffer.getChannelData(0); |
323 | 387 |
324 var threshold; | 388 var threshold; |
325 | 389 |
326 if (!jumpThreshold) { | 390 if (!jumpThreshold) { |
327 threshold = discontinuityThreshold; | 391 threshold = discontinuityThreshold; |
328 } else { | 392 } else { |
329 threshold = jumpThreshold; | 393 threshold = jumpThreshold; |
330 } | 394 } |
331 | 395 |
332 compareSignals(testName, error, renderedData, referenceFunction, timeVal
ueInfo, threshold); | 396 compareSignals(testName, error, renderedData, referenceFunction, timeVal
ueInfo, threshold, errorMetric); |
333 | 397 |
334 finishJSTest(); | 398 finishJSTest(); |
335 } | 399 } |
336 } | 400 } |
337 | 401 |
338 // Run all the automation tests. | 402 // Run all the automation tests. |
339 // | 403 // |
340 // numberOfTests - number of tests (time intervals) to run. | 404 // numberOfTests - number of tests (time intervals) to run. |
341 // | 405 // |
342 // initialValue - The initial value of the first time interval. | 406 // initialValue - The initial value of the first time interval. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 // testName - string indicating the test that is being run. | 452 // testName - string indicating the test that is being run. |
389 // | 453 // |
390 // maxError - maximum allowed error between the rendered data and the reference
data | 454 // maxError - maximum allowed error between the rendered data and the reference
data |
391 // | 455 // |
392 // referenceFunction - function that generates the reference data to be compared
against the | 456 // referenceFunction - function that generates the reference data to be compared
against the |
393 // rendered data. | 457 // rendered data. |
394 // | 458 // |
395 // jumpThreshold - optional parameter that specifies the threshold to use for de
tecting | 459 // jumpThreshold - optional parameter that specifies the threshold to use for de
tecting |
396 // discontinuities. If not specified, defaults to discontinuityThreshold. | 460 // discontinuities. If not specified, defaults to discontinuityThreshold. |
397 // | 461 // |
398 function createAudioGraphAndTest(numberOfTests, initialValue, setValueFunction,
automationFunction, testName, maxError, referenceFunction, jumpThreshold) | 462 function createAudioGraphAndTest(numberOfTests, initialValue, setValueFunction,
automationFunction, testName, maxError, referenceFunction, jumpThreshold, errorM
etric) |
399 { | 463 { |
400 if (window.testRunner) { | 464 if (window.testRunner) { |
401 testRunner.dumpAsText(); | 465 testRunner.dumpAsText(); |
402 testRunner.waitUntilDone(); | 466 testRunner.waitUntilDone(); |
403 } | 467 } |
404 | 468 |
405 window.jsTestIsAsync = true; | 469 window.jsTestIsAsync = true; |
406 | 470 |
407 // Create offline audio context. | 471 // Create offline audio context. |
408 context = new OfflineAudioContext(2, renderLength(numberOfTests), sampleRate
); | 472 context = new OfflineAudioContext(2, renderLength(numberOfTests), sampleRate
); |
409 var constantBuffer = createConstantBuffer(context, 1, renderLength(numberOfT
ests)); | 473 var constantBuffer = createConstantBuffer(context, renderLength(numberOfTest
s), 1); |
410 | 474 |
411 // We use an AudioGainNode here simply as a convenient way to test the Audio
Param | 475 // We use an AudioGainNode here simply as a convenient way to test the Audio
Param |
412 // automation, since it's easy to pass a constant value through the node, au
tomate the | 476 // automation, since it's easy to pass a constant value through the node, au
tomate the |
413 // .gain attribute and observe the resulting values. | 477 // .gain attribute and observe the resulting values. |
414 | 478 |
415 gainNode = context.createGain(); | 479 gainNode = context.createGain(); |
416 | 480 |
417 var bufferSource = context.createBufferSource(); | 481 var bufferSource = context.createBufferSource(); |
418 bufferSource.buffer = constantBuffer; | 482 bufferSource.buffer = constantBuffer; |
419 bufferSource.connect(gainNode); | 483 bufferSource.connect(gainNode); |
420 gainNode.connect(context.destination); | 484 gainNode.connect(context.destination); |
421 | 485 |
422 // Set up default values for the parameters that control how the automation
test values progress | 486 // Set up default values for the parameters that control how the automation
test values progress |
423 // for each time interval. | 487 // for each time interval. |
424 startingValueDelta = initialValue / numberOfTests; | 488 startingValueDelta = initialValue / numberOfTests; |
425 startEndValueChange = startingValueDelta / 2; | 489 startEndValueChange = startingValueDelta / 2; |
426 discontinuityThreshold = startEndValueChange / 2; | 490 discontinuityThreshold = startEndValueChange / 2; |
427 | 491 |
428 // Run the automation tests. | 492 // Run the automation tests. |
429 timeValueInfo = doAutomation(numberOfTests, | 493 timeValueInfo = doAutomation(numberOfTests, |
430 initialValue, | 494 initialValue, |
431 setValueFunction, | 495 setValueFunction, |
432 automationFunction); | 496 automationFunction); |
433 bufferSource.start(0); | 497 bufferSource.start(0); |
434 | 498 |
435 context.oncomplete = checkResultFunction(testName, | 499 context.oncomplete = checkResultFunction(testName, |
436 maxError, | 500 maxError, |
437 referenceFunction, | 501 referenceFunction, |
438 jumpThreshold); | 502 jumpThreshold, |
| 503 errorMetric || relativeErrorMetric)
; |
439 context.startRendering(); | 504 context.startRendering(); |
440 } | 505 } |
OLD | NEW |