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