| OLD | NEW |
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <script src="../../resources/testharness.js"></script> | 4 <script src="../../resources/testharness.js"></script> |
| 5 <script src="../../resources/testharnessreport.js"></script> | 5 <script src="../../resources/testharnessreport.js"></script> |
| 6 <script src="../resources/audit-util.js"></script> | 6 <script src="../resources/audit-util.js"></script> |
| 7 <script src="../resources/audio-testing.js"></script> | 7 <script src="../resources/audit.js"></script> |
| 8 <script src="../resources/audioparam-testing.js"></script> | 8 <script src="../resources/audioparam-testing.js"></script> |
| 9 <title>Test Sampling for SetTargetAtTime</title> | 9 <title>Test Sampling for SetTargetAtTime</title> |
| 10 </head> | 10 </head> |
| 11 | 11 |
| 12 <body> | 12 <body> |
| 13 <script> | 13 <script> |
| 14 | 14 |
| 15 // Some slow sample rate, but otherwise arbitrary. | 15 // Some slow sample rate, but otherwise arbitrary. |
| 16 var sampleRate = 12800; | 16 var sampleRate = 12800; |
| 17 | 17 |
| 18 // Time constant for setTargetValue. Make it short, but is otherwise arbit
rary. | 18 // Time constant for setTargetValue. Make it short, but is otherwise arbit
rary. |
| 19 var timeConstant = 10 / sampleRate; | 19 var timeConstant = 10 / sampleRate; |
| 20 | 20 |
| 21 // Defaut initial gain for test. Arbitrary, but we want it large so the c
hanges look large, | 21 // Defaut initial gain for test. Arbitrary, but we want it large so the c
hanges look large, |
| 22 // even if the relative change isn't. | 22 // even if the relative change isn't. |
| 23 var initialGain = 10000; | 23 var initialGain = 10000; |
| 24 | 24 |
| 25 var audit = Audit.createTaskRunner(); | 25 var audit = Audit.createTaskRunner(); |
| 26 | 26 |
| 27 // Test sampling of setTargetAtTime that starts at |startFrame|. A gain n
ode is used for | 27 // Test sampling of setTargetAtTime that starts at |startFrame|. A gain n
ode is used for |
| 28 // testing. |initializeGainFunction| initializes the gain value. | 28 // testing. |initializeGainFunction| initializes the gain value. |
| 29 function doTest(message, startFrame, threshold, initializeGainFunction) { | 29 function doTest(should, message, startFrame, threshold, initializeGainFunc
tion) { |
| 30 var context = new OfflineAudioContext(1, 256, sampleRate); | 30 var context = new OfflineAudioContext(1, 256, sampleRate); |
| 31 var source = context.createBufferSource(); | 31 var source = context.createBufferSource(); |
| 32 var b = context.createBuffer(1, 1, sampleRate); | 32 var b = context.createBuffer(1, 1, sampleRate); |
| 33 b.getChannelData(0)[0] = 1; | 33 b.getChannelData(0)[0] = 1; |
| 34 source.buffer = b; | 34 source.buffer = b; |
| 35 source.loop = true; | 35 source.loop = true; |
| 36 | 36 |
| 37 var gain = context.createGain(); | 37 var gain = context.createGain(); |
| 38 // Initialize the value of the gain node appropriately. | 38 // Initialize the value of the gain node appropriately. |
| 39 initializeGainFunction(gain); | 39 initializeGainFunction(gain); |
| 40 gain.gain.setTargetAtTime(0, startFrame / sampleRate, timeConstant); | 40 gain.gain.setTargetAtTime(0, startFrame / sampleRate, timeConstant); |
| 41 | 41 |
| 42 source.connect(gain); | 42 source.connect(gain); |
| 43 gain.connect(context.destination); | 43 gain.connect(context.destination); |
| 44 | 44 |
| 45 source.start(); | 45 source.start(); |
| 46 | 46 |
| 47 return context.startRendering().then(function (resultBuffer) { | 47 return context.startRendering().then(function (resultBuffer) { |
| 48 // Verify that the sampling of the setTargetAtTime automation was done
correctly. We just | 48 // Verify that the sampling of the setTargetAtTime automation was done
correctly. We just |
| 49 // look at the sample just past the start of the automation. | 49 // look at the sample just past the start of the automation. |
| 50 var resultData = resultBuffer.getChannelData(0); | 50 var resultData = resultBuffer.getChannelData(0); |
| 51 // Compute the true result at the frame just past startFrame and verif
y that the actual | 51 // Compute the true result at the frame just past startFrame and verif
y that the actual |
| 52 // rendered result is within |threshold| of the expected value. | 52 // rendered result is within |threshold| of the expected value. |
| 53 var frame = Math.ceil(startFrame); | 53 var frame = Math.ceil(startFrame); |
| 54 var v = 10000 * Math.exp(-(frame / sampleRate - startFrame / sampleRat
e) / timeConstant); | 54 var v = 10000 * Math.exp(-(frame / sampleRate - startFrame / sampleRat
e) / timeConstant); |
| 55 Should(message + ": Target value at frame " + frame, resultData[frame]
).beCloseTo(v, threshold); | 55 should(resultData[frame], message + ": Target value at frame " + |
| 56 frame).beCloseTo(v, { |
| 57 threshold: threshold |
| 58 }); |
| 56 }); | 59 }); |
| 57 } | 60 } |
| 58 | 61 |
| 59 function initializeGainBySetter (g) { | 62 function initializeGainBySetter (g) { |
| 60 g.gain.value = initialGain; | 63 g.gain.value = initialGain; |
| 61 } | 64 } |
| 62 | 65 |
| 63 function initializeGainBySetValue (g) { | 66 function initializeGainBySetValue (g) { |
| 64 g.gain.setValueAtTime(initialGain, 0); | 67 g.gain.setValueAtTime(initialGain, 0); |
| 65 } | 68 } |
| 66 | 69 |
| 67 audit.defineTask("setValue;128.1", function (done) { | 70 audit.define("setValue;128.1", (task, should) => { |
| 68 doTest("Initialize by setValueAtTime", 128.1, 3.6029e-8, initializeGainB
ySetValue).then(done); | 71 doTest(should, "Initialize by setValueAtTime", 128.1, 3.6029e-8, |
| 72 initializeGainBySetValue) |
| 73 .then(() => task.done()); |
| 69 }); | 74 }); |
| 70 | 75 |
| 71 audit.defineTask("setValue;0.1", function (done) { | 76 audit.define("setValue;0.1", (task, should) => { |
| 72 doTest("Initialize by setValueAtTime", 0.1, 3.6029e-8, initializeGainByS
etValue).then(done); | 77 doTest(should, "Initialize by setValueAtTime", 0.1, 3.6029e-8, |
| 78 initializeGainBySetValue) |
| 79 .then(() => task.done()); |
| 73 }); | 80 }); |
| 74 | 81 |
| 75 audit.defineTask("setValue;0.0", function (done) { | 82 audit.define("setValue;0.0", (task, should) => { |
| 76 doTest("Initialize by setValueAtTime", 0, 3.6029e-8, initializeGainBySet
Value).then(done); | 83 doTest(should, "Initialize by setValueAtTime", 0, 3.6029e-8, |
| 84 initializeGainBySetValue) |
| 85 .then(() => task.done()); |
| 77 }); | 86 }); |
| 78 | 87 |
| 79 audit.defineTask("setter;128.1", function (done) { | 88 audit.define("setter;128.1", (task, should) => { |
| 80 doTest("Initialize by setter", 128.1, 3.6029e-8, initializeGainBySetter)
.then(done); | 89 doTest(should, "Initialize by setter", 128.1, 3.6029e-8, |
| 90 initializeGainBySetter) |
| 91 .then(() => task.done()); |
| 81 }); | 92 }); |
| 82 | 93 |
| 83 audit.defineTask("setter;0.1", function (done) { | 94 audit.define("setter;0.1", (task, should) => { |
| 84 doTest("Initialize by setter", 0.1, 3.6029e-8, initializeGainBySetter).t
hen(done); | 95 doTest(should, "Initialize by setter", 0.1, 3.6029e-8, |
| 96 initializeGainBySetter) |
| 97 .then(() => task.done()); |
| 85 }); | 98 }); |
| 86 | 99 |
| 87 audit.defineTask("setter;0.0", function (done) { | 100 audit.define("setter;0.0", (task, should) => { |
| 88 doTest("Initialize by setter", 0, 0, initializeGainBySetter).then(done); | 101 doTest(should, "Initialize by setter", 0, 0, initializeGainBySetter) |
| 102 .then(() => task.done()); |
| 89 }); | 103 }); |
| 90 | 104 |
| 91 | 105 audit.run(); |
| 92 audit.defineTask("finish", function (done) { | |
| 93 done(); | |
| 94 }); | |
| 95 | |
| 96 audit.runTasks(); | |
| 97 successfullyParsed = true; | |
| 98 </script> | 106 </script> |
| 99 </body> | 107 </body> |
| 100 </html> | 108 </html> |
| OLD | NEW |