OLD | NEW |
1 <!doctype html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
| 4 <title> |
| 5 Test Negative AudioParam.exponentialRampToValueAtTime |
| 6 </title> |
4 <script src="../../resources/testharness.js"></script> | 7 <script src="../../resources/testharness.js"></script> |
5 <script src="../../resources/testharnessreport.js"></script> | 8 <script src="../../resources/testharnessreport.js"></script> |
6 <script src="../resources/audit-util.js"></script> | 9 <script src="../resources/audit-util.js"></script> |
7 <script src="../resources/audit.js"></script> | 10 <script src="../resources/audit.js"></script> |
8 <title>Test Negative AudioParam.exponentialRampToValueAtTime</title> | |
9 </head> | 11 </head> |
| 12 <body> |
| 13 <script id="layout-test-code"> |
| 14 let sampleRate = 48000; |
10 | 15 |
11 <body> | 16 let audit = Audit.createTaskRunner(); |
12 <script> | |
13 | |
14 var sampleRate = 48000; | |
15 | 17 |
16 var audit = Audit.createTaskRunner(); | 18 audit.define('both negative values', (task, should) => { |
| 19 let renderDuration = 0.125; |
17 | 20 |
18 audit.define("both negative values", (task, should) => { | 21 // Create context with two channels. Channel 0 contains the |
19 var renderDuration = 0.125; | 22 // positive-valued exponential and channel 1 contains the |
20 | 23 // negative-valued exponential. We'll compare the two channels to |
21 // Create context with two channels. Channel 0 contains the positive-va
lued exponential and | |
22 // channel 1 contains the negative-valued exponential. We'll compare th
e two channels to | |
23 // verify that they're the same, as they should be. | 24 // verify that they're the same, as they should be. |
24 var context = new OfflineAudioContext(2, renderDuration * sampleRate, sa
mpleRate); | 25 let context = |
25 var source = context.createBufferSource(); | 26 new OfflineAudioContext(2, renderDuration * sampleRate, sampleRate); |
| 27 let source = context.createBufferSource(); |
26 source.buffer = createConstantBuffer(context, 1, 1); | 28 source.buffer = createConstantBuffer(context, 1, 1); |
27 source.loop = true; | 29 source.loop = true; |
28 | 30 |
29 // Gain node gp is for the positive-valued exponential ramp, and gn is f
or the negative-valued | 31 // Gain node gp is for the positive-valued exponential ramp, and gn is |
30 // exponential ramp. | 32 // for the negative-valued exponential ramp. |
31 var gp = context.createGain(); | 33 let gp = context.createGain(); |
32 var gn = context.createGain(); | 34 let gn = context.createGain(); |
33 var merger = context.createChannelMerger(2); | 35 let merger = context.createChannelMerger(2); |
34 | 36 |
35 source.connect(gp) | 37 source.connect(gp).connect(merger, 0, 0); |
36 .connect(merger, 0, 0); | 38 source.connect(gn).connect(merger, 0, 1); |
37 source.connect(gn) | |
38 .connect(merger, 0, 1); | |
39 merger.connect(context.destination); | 39 merger.connect(context.destination); |
40 | 40 |
41 gp.gain.setValueAtTime(1, 0); | 41 gp.gain.setValueAtTime(1, 0); |
42 gp.gain.exponentialRampToValueAtTime(2, renderDuration); | 42 gp.gain.exponentialRampToValueAtTime(2, renderDuration); |
43 | 43 |
44 gn.gain.setValueAtTime(-1, 0); | 44 gn.gain.setValueAtTime(-1, 0); |
45 gn.gain.exponentialRampToValueAtTime(-2, renderDuration); | 45 gn.gain.exponentialRampToValueAtTime(-2, renderDuration); |
46 | 46 |
47 source.start(); | 47 source.start(); |
48 | 48 |
49 context.startRendering().then(function (resultBuffer) { | 49 context.startRendering() |
50 // Verify that channels have the same values, except for the sign. | 50 .then(function(resultBuffer) { |
51 var expected = resultBuffer.getChannelData(0); | 51 // Verify that channels have the same values, except for the sign. |
52 var actual = resultBuffer.getChannelData(1); | 52 let expected = resultBuffer.getChannelData(0); |
53 var inverted = expected.map(sample => -sample); | 53 let actual = resultBuffer.getChannelData(1); |
| 54 let inverted = expected.map(sample => -sample); |
54 | 55 |
55 should(actual, "Negative exponential ramp from -1 to -2") | 56 should(actual, 'Negative exponential ramp from -1 to -2') |
56 .beEqualToArray(inverted); | 57 .beEqualToArray(inverted); |
57 }).then(() => task.done()); | 58 }) |
| 59 .then(() => task.done()); |
58 }); | 60 }); |
59 | 61 |
60 audit.define("negative-end", (task, should) => { | 62 audit.define('negative-end', (task, should) => { |
61 // Positive start value and negative end value should just do nothing. | 63 // Positive start value and negative end value should just do nothing. |
62 var renderDuration = 0.125; | 64 let renderDuration = 0.125; |
63 var context = new OfflineAudioContext(1, renderDuration * sampleRate, sa
mpleRate); | 65 let context = |
64 var source = context.createBufferSource(); | 66 new OfflineAudioContext(1, renderDuration * sampleRate, sampleRate); |
| 67 let source = context.createBufferSource(); |
65 source.buffer = createConstantBuffer(context, 1, 1); | 68 source.buffer = createConstantBuffer(context, 1, 1); |
66 source.loop = true; | 69 source.loop = true; |
67 | 70 |
68 // Gain node gp is for the positive-valued exponential ramp, and gn is f
or the negative-valued | 71 // Gain node gp is for the positive-valued exponential ramp, and gn is |
69 // exponential ramp. | 72 // for the negative-valued exponential ramp. |
70 var g = context.createGain(); | 73 let g = context.createGain(); |
71 | 74 |
72 g.gain.setValueAtTime(2, 0); | 75 g.gain.setValueAtTime(2, 0); |
73 g.gain.exponentialRampToValueAtTime(-1, renderDuration); | 76 g.gain.exponentialRampToValueAtTime(-1, renderDuration); |
74 | 77 |
75 source.connect(g) | 78 source.connect(g).connect(context.destination); |
76 .connect(context.destination); | |
77 | 79 |
78 source.start(); | 80 source.start(); |
79 | 81 |
80 context.startRendering().then(function (resultBuffer) { | 82 context.startRendering() |
81 var actual = resultBuffer.getChannelData(0); | 83 .then(function(resultBuffer) { |
| 84 let actual = resultBuffer.getChannelData(0); |
82 | 85 |
83 should(actual, "Exponential ramp from 2 to -1") | 86 should(actual, 'Exponential ramp from 2 to -1') |
84 .beConstantValueOf(2); | 87 .beConstantValueOf(2); |
85 }).then(() => task.done()); | 88 }) |
| 89 .then(() => task.done()); |
86 }); | 90 }); |
87 | 91 |
88 audit.define("positive-end", (task, should) => { | 92 audit.define('positive-end', (task, should) => { |
89 // Positive start value and negative end value should just do nothing. | 93 // Positive start value and negative end value should just do nothing. |
90 var renderDuration = 0.125; | 94 let renderDuration = 0.125; |
91 var context = new OfflineAudioContext(1, renderDuration * sampleRate, sa
mpleRate); | 95 let context = |
92 var source = context.createBufferSource(); | 96 new OfflineAudioContext(1, renderDuration * sampleRate, sampleRate); |
| 97 let source = context.createBufferSource(); |
93 source.buffer = createConstantBuffer(context, 1, 1); | 98 source.buffer = createConstantBuffer(context, 1, 1); |
94 source.loop = true; | 99 source.loop = true; |
95 | 100 |
96 var g = context.createGain(); | 101 let g = context.createGain(); |
97 | 102 |
98 g.gain.setValueAtTime(-1, 0); | 103 g.gain.setValueAtTime(-1, 0); |
99 g.gain.exponentialRampToValueAtTime(1, renderDuration); | 104 g.gain.exponentialRampToValueAtTime(1, renderDuration); |
100 | 105 |
101 source.connect(g) | 106 source.connect(g).connect(context.destination); |
102 .connect(context.destination); | |
103 source.start(); | 107 source.start(); |
104 | 108 |
105 context.startRendering().then(function (resultBuffer) { | 109 context.startRendering() |
106 var actual = resultBuffer.getChannelData(0); | 110 .then(function(resultBuffer) { |
| 111 let actual = resultBuffer.getChannelData(0); |
107 | 112 |
108 should(actual, "Exponential ramp from -1 to 1") | 113 should(actual, 'Exponential ramp from -1 to 1') |
109 .beConstantValueOf(-1); | 114 .beConstantValueOf(-1); |
110 }).then(() => task.done()); | 115 }) |
| 116 .then(() => task.done()); |
111 }); | 117 }); |
112 | 118 |
113 audit.define("propagate", (task, should) => { | 119 audit.define('propagate', (task, should) => { |
114 // Test propagation of ramp if the exponential ramp start and end values
have opposite sign. | 120 // Test propagation of ramp if the exponential ramp start and end values |
115 var renderDuration = 0.125; | 121 // have opposite sign. |
116 var linearRampEnd = renderDuration / 4; | 122 let renderDuration = 0.125; |
117 var exponentialRampEnd = renderDuration / 2; | 123 let linearRampEnd = renderDuration / 4; |
| 124 let exponentialRampEnd = renderDuration / 2; |
118 | 125 |
119 var context = new OfflineAudioContext(1, renderDuration * sampleRate, sa
mpleRate); | 126 let context = |
120 var source = context.createBufferSource(); | 127 new OfflineAudioContext(1, renderDuration * sampleRate, sampleRate); |
| 128 let source = context.createBufferSource(); |
121 source.buffer = createConstantBuffer(context, 1, 1); | 129 source.buffer = createConstantBuffer(context, 1, 1); |
122 source.loop = true; | 130 source.loop = true; |
123 | 131 |
124 var g = context.createGain(); | 132 let g = context.createGain(); |
125 | 133 |
126 g.gain.setValueAtTime(2, 0); | 134 g.gain.setValueAtTime(2, 0); |
127 g.gain.linearRampToValueAtTime(-1, linearRampEnd); | 135 g.gain.linearRampToValueAtTime(-1, linearRampEnd); |
128 g.gain.exponentialRampToValueAtTime(1, exponentialRampEnd); | 136 g.gain.exponentialRampToValueAtTime(1, exponentialRampEnd); |
129 | 137 |
130 source.connect(g) | 138 source.connect(g).connect(context.destination); |
131 .connect(context.destination); | |
132 source.start(); | 139 source.start(); |
133 | 140 |
134 context.startRendering().then(function (resultBuffer) { | 141 context.startRendering() |
135 var actual = resultBuffer.getChannelData(0); | 142 .then(function(resultBuffer) { |
| 143 let actual = resultBuffer.getChannelData(0); |
136 | 144 |
137 // Since the start value of the exponential ramp is -1 and the end val
ue is 1, the ramp | 145 // Since the start value of the exponential ramp is -1 and the end |
138 // should just propagate -1 from the end of the linear ramp "forever". | 146 // value is 1, the ramp should just propagate -1 from the end of |
139 var endFrame = Math.ceil(linearRampEnd * sampleRate); | 147 // the linear ramp "forever". |
140 should(actual.slice(endFrame), | 148 let endFrame = Math.ceil(linearRampEnd * sampleRate); |
141 "Exponential ramp from -1 to 1 after the end of the linear ramp") | 149 should( |
142 .beConstantValueOf(-1); | 150 actual.slice(endFrame), |
143 }).then(() => task.done()); | 151 'Exponential ramp from -1 to 1 after the end of the linear ram
p') |
144 | 152 .beConstantValueOf(-1); |
| 153 }) |
| 154 .then(() => task.done()); |
| 155 |
145 }); | 156 }); |
146 | 157 |
147 audit.run(); | 158 audit.run(); |
148 </script> | 159 </script> |
149 </body> | 160 </body> |
150 </html> | 161 </html> |
OLD | NEW |