4 <title>Test Exceptions from setValueCurveAtTime
</title>
5 <script src=
"../resources/js-test.js"></script>
6 <script src=
"resources/compatibility.js"></script>
7 <script src=
"resources/audio-testing.js"></script>
12 description("Test Exceptions from setValueCurveAtTime");
13 window
.jsTestIsAsync
= true;
15 var sampleRate
= 48000;
16 // Some short duration because we don't need to run the test for very long.
17 var testDurationSec
= 0.125;
18 var testDurationFrames
= testDurationSec
* sampleRate
;
20 var audit
= Audit
.createTaskRunner();
22 audit
.defineTask("setValueCurve", function(done
) {
24 var context
= new OfflineAudioContext(1, testDurationFrames
, sampleRate
);
25 var g
= context
.createGain();
26 var curve
= new Float32Array(2);
28 // Start time and duration for setValueCurveAtTime
29 var curveStartTime
= 0.1 * testDurationSec
;
30 var duration
= 0.1 * testDurationSec
;
32 // Some time that is known to during the setValueCurveTime interval.
33 var automationTime
= curveStartTime
+ duration
/ 2;
35 success
= success
&& Should("setValueCurveAtTime(curve, " + curveStartTime
+ ", " + duration
+ ")", function() {
36 g
.gain
.setValueCurveAtTime(curve
, curveStartTime
, duration
);
39 success
= success
&& Should("setValueAtTime(1, " + automationTime
+ ")", function() {
40 g
.gain
.setValueAtTime(1, automationTime
);
41 }).throw("NotSupportedError");
43 success
= success
&& Should("linearRampToValueAtTime(1, " + automationTime
+ ")", function() {
44 g
.gain
.linearRampToValueAtTime(1, automationTime
);
45 }).throw("NotSupportedError");
47 success
= success
&& Should("exponentialRampToValueAtTime(1, " + automationTime
+ ")", function() {
48 g
.gain
.exponentialRampToValueAtTime(1, automationTime
);
49 }).throw("NotSupportedError");
51 success
= success
&& Should("setTargetAtTime(1, " + automationTime
+ ", 1)", function() {
52 g
.gain
.setTargetAtTime(1, automationTime
, 1);
53 }).throw("NotSupportedError");
55 success
= success
&& Should("setValueAtTime(1, " + (curveStartTime
+ 1.1 * duration
) + ")", function() {
56 g
.gain
.setValueAtTime(1, curveStartTime
+ 1.1 * duration
);
59 var prefix
= "Automation functions overlapping an existing setValueCurveAtTime";
61 testPassed(prefix
+ " correctly signaled errors.\n");
63 testFailed(prefix
+ " failed to signal errors.\n");
68 audit
.defineTask("automations", function (done
) {
70 var context
= new OfflineAudioContext(1, testDurationFrames
, sampleRate
);
71 var g
= context
.createGain();
73 var curve
= new Float32Array(2);
74 // Start time and duration for setValueCurveAtTime
76 var timeInterval
= testDurationSec
/ 10;
78 startTime
+= timeInterval
;
79 success
= success
&& Should("linearRampToValueAtTime(1, " + startTime
+ ")", function () {
80 g
.gain
.linearRampToValueAtTime(1, startTime
);
83 startTime
+= timeInterval
;
84 success
= success
&& Should("exponentialRampToValueAtTime(1, " + startTime
+ ")", function () {
85 g
.gain
.exponentialRampToValueAtTime(1, startTime
);
88 startTime
+= timeInterval
;
89 success
= success
&& Should("setTargetAtTime(1, " + startTime
+ ", 0.1)", function () {
90 g
.gain
.setTargetAtTime(1, startTime
, 0.1);
93 startTime
+= timeInterval
;
94 success
= success
&& Should("setValueCurveAtTime(curve, " + startTime
+ ", 0.1)", function () {
95 g
.gain
.setValueCurveAtTime(curve
, startTime
, 0.1);
98 // Now try to setValueCurve that overlaps each of the above automations
99 startTime
= timeInterval
/ 2;
101 for (var k
= 0; k
< 4; ++k
) {
102 success
= success
&& Should("setValueCurveAtTime(curve, " + startTime
+ ", 0.01)", function () {
103 g
.gain
.setValueCurveAtTime(curve
, startTime
, 0.01);
104 }).throw("NotSupportedError");
105 startTime
+= timeInterval
;
108 var prefix
= "setValueCurve overlapping existing automation functions";
110 testPassed(prefix
+ " correctly signaled errors.\n");
112 testFailed(prefix
+ " failed to signal errors.\n");
117 audit
.defineTask("start-end", function (done
) {
119 var context
= new OfflineAudioContext(1, testDurationFrames
, sampleRate
);
120 var g
= context
.createGain();
121 var curve
= new Float32Array(2);
123 // Verify that a setValueCurve can start at the end of an automation.
125 var timeInterval
= testDurationSec
/ 50;
126 success
= Should("setValueAtTime(1, " + time
+ ")", function () {
127 g
.gain
.setValueAtTime(1, time
);
130 time
+= timeInterval
;
131 success
= Should("linearRampToValueAtTime(0, " + time
+ ")", function () {
132 g
.gain
.linearRampToValueAtTime(0, time
);
133 }).notThrow() && success
;
135 // setValueCurve starts at the end of the linear ramp. This should be fine.
136 success
= Should("setValueCurveAtTime(..., " + time
+ ", " + timeInterval
+ ")", function () {
137 g
.gain
.setValueCurveAtTime(curve
, time
, timeInterval
);
138 }).notThrow() && success
;
140 // exponentialRamp ending one interval past the setValueCurve should be fine.
141 time
+= 2*timeInterval
;
142 success
= Should("exponentialRampToValueAtTime(1, " + time
+ ")", function () {
143 g
.gain
.exponentialRampToValueAtTime(1, time
);
144 }).notThrow() && success
;
146 // setValueCurve starts at the end of the exponential ramp. This should be fine.
147 success
= Should("setValueCurveAtTime(..., " + time
+ ", " + timeInterval
+ ")", function () {
148 g
.gain
.setValueCurveAtTime(curve
, time
, timeInterval
);
149 }).notThrow() && success
;
151 // setValueCurve at the end of the setValueCurve should be fine.
152 time
+= timeInterval
;
153 success
= Should("setValueCurveAtTime(..., " + time
+ ", " + timeInterval
+ ")", function () {
154 g
.gain
.setValueCurveAtTime(curve
, time
, timeInterval
);
155 }).notThrow() && success
;
157 // setValueAtTime at the end of setValueCurve should be fine.
158 time
+= timeInterval
;
159 success
= Should("setValueAtTime(0, " + time
+ ")", function () {
160 g
.gain
.setValueAtTime(0, time
);
161 }).notThrow() && success
;
163 // setValueCurve at the end of setValueAtTime should be fine.
164 success
= Should("setValueCurveAtTime(..., " + time
+ ", " + timeInterval
+ ")", function () {
165 g
.gain
.setValueCurveAtTime(curve
, time
, timeInterval
);
166 }).notThrow() && success
;
168 // setTarget starting at the end of setValueCurve should be fine.
169 time
+= timeInterval
;
170 success
= Should("setTargetAtTime(1, " + time
+ ", 1)", function () {
171 g
.gain
.setTargetAtTime(1, time
, 1);
172 }).notThrow() && success
;
174 var prefix
= "setValueCurve with adjoining automation functions";
176 testPassed(prefix
+ " allowed as expected.\n");
178 testFailed(prefix
+ " unexpectedly signaled errors.\n");
183 audit
.defineTask("finish", function (done
) {
189 successfullyParsed
= true;