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