1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
<!DOCTYPE html>
<html>
<head>
<title>
Test AudioParam.setValueCurveAtTime
</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/webaudio/resources/audit-util.js"></script>
<script src="/webaudio/resources/audit.js"></script>
<script src="/webaudio/resources/audioparam-testing.js"></script>
</head>
<body>
<script id="layout-test-code">
let audit = Audit.createTaskRunner();
// Play a long DC signal out through an AudioGainNode and for each time
// interval call setValueCurveAtTime() to set the values for the duration
// of the interval. Each curve is a sine wave, and we assume that the
// time interval is not an exact multiple of the period. This causes a
// discontinuity between time intervals which is used to test timing.
// Number of tests to run.
let numberOfTests = 20;
// Max allowed difference between the rendered data and the expected
// result. Because of the linear interpolation, the rendered curve isn't
// exactly the same as the reference. This value is experimentally
// determined.
let maxAllowedError = 3.7194e-6;
// The amplitude of the sine wave.
let sineAmplitude = 1;
// Frequency of the sine wave.
let freqHz = 440;
// Curve to use for setValueCurveAtTime().
let curve;
// Sets the curve data for the entire time interval.
function automation(value, startTime, endTime) {
gainNode.gain.setValueCurveAtTime(
curve, startTime, endTime - startTime);
}
audit.define(
{
label: 'test',
description: 'AudioParam setValueCurveAtTime() functionality.'
},
function(task, should) {
// The curve of values to use.
curve = createSineWaveArray(
timeInterval, freqHz, sineAmplitude, sampleRate);
createAudioGraphAndTest(
task, should, numberOfTests, sineAmplitude,
function(k) {
// Don't need to set the value.
},
automation, 'setValueCurveAtTime()', maxAllowedError,
createReferenceSineArray,
2 * Math.PI * sineAmplitude * freqHz / sampleRate,
differenceErrorMetric);
});
audit.run();
</script>
</body>
</html>
|