| 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 <title>Test Negative AudioParam.exponentialRampToValueAtTime</title> | 8 <title>Test Negative AudioParam.exponentialRampToValueAtTime</title> |
| 9 </head> | 9 </head> |
| 10 | 10 |
| 11 <body> | 11 <body> |
| 12 <script> | 12 <script> |
| 13 | 13 |
| 14 var sampleRate = 48000; | 14 var sampleRate = 48000; |
| 15 | 15 |
| 16 var audit = Audit.createTaskRunner(); | 16 var audit = Audit.createTaskRunner(); |
| 17 | 17 |
| 18 audit.defineTask("both negative values", function (done) { | 18 audit.define("both negative values", (task, should) => { |
| 19 var renderDuration = 0.125; | 19 var renderDuration = 0.125; |
| 20 | 20 |
| 21 // Create context with two channels. Channel 0 contains the positive-va
lued exponential and | 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 | 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. | 23 // verify that they're the same, as they should be. |
| 24 var context = new OfflineAudioContext(2, renderDuration * sampleRate, sa
mpleRate); | 24 var context = new OfflineAudioContext(2, renderDuration * sampleRate, sa
mpleRate); |
| 25 var source = context.createBufferSource(); | 25 var source = context.createBufferSource(); |
| 26 source.buffer = createConstantBuffer(context, 1, 1); | 26 source.buffer = createConstantBuffer(context, 1, 1); |
| 27 source.loop = true; | 27 source.loop = true; |
| 28 | 28 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 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().then(function (resultBuffer) { |
| 50 // Verify that channels have the same values, except for the sign. | 50 // Verify that channels have the same values, except for the sign. |
| 51 var expected = resultBuffer.getChannelData(0); | 51 var expected = resultBuffer.getChannelData(0); |
| 52 var actual = resultBuffer.getChannelData(1); | 52 var actual = resultBuffer.getChannelData(1); |
| 53 var inverted = expected.map(sample => -sample); | 53 var inverted = expected.map(sample => -sample); |
| 54 | 54 |
| 55 Should("Negative exponential ramp from -1 to -2", actual) | 55 should(actual, "Negative exponential ramp from -1 to -2") |
| 56 .beEqualToArray(inverted); | 56 .beEqualToArray(inverted); |
| 57 }).then(done); | 57 }).then(() => task.done()); |
| 58 }); | 58 }); |
| 59 | 59 |
| 60 audit.defineTask("negative-end", function (done) { | 60 audit.define("negative-end", (task, should) => { |
| 61 // Positive start value and negative end value should just do nothing. | 61 // Positive start value and negative end value should just do nothing. |
| 62 var renderDuration = 0.125; | 62 var renderDuration = 0.125; |
| 63 var context = new OfflineAudioContext(1, renderDuration * sampleRate, sa
mpleRate); | 63 var context = new OfflineAudioContext(1, renderDuration * sampleRate, sa
mpleRate); |
| 64 var source = context.createBufferSource(); | 64 var source = context.createBufferSource(); |
| 65 source.buffer = createConstantBuffer(context, 1, 1); | 65 source.buffer = createConstantBuffer(context, 1, 1); |
| 66 source.loop = true; | 66 source.loop = true; |
| 67 | 67 |
| 68 // Gain node gp is for the positive-valued exponential ramp, and gn is f
or the negative-valued | 68 // Gain node gp is for the positive-valued exponential ramp, and gn is f
or the negative-valued |
| 69 // exponential ramp. | 69 // exponential ramp. |
| 70 var g = context.createGain(); | 70 var g = context.createGain(); |
| 71 | 71 |
| 72 g.gain.setValueAtTime(2, 0); | 72 g.gain.setValueAtTime(2, 0); |
| 73 g.gain.exponentialRampToValueAtTime(-1, renderDuration); | 73 g.gain.exponentialRampToValueAtTime(-1, renderDuration); |
| 74 | 74 |
| 75 source.connect(g) | 75 source.connect(g) |
| 76 .connect(context.destination); | 76 .connect(context.destination); |
| 77 | 77 |
| 78 source.start(); | 78 source.start(); |
| 79 | 79 |
| 80 context.startRendering().then(function (resultBuffer) { | 80 context.startRendering().then(function (resultBuffer) { |
| 81 var actual = resultBuffer.getChannelData(0); | 81 var actual = resultBuffer.getChannelData(0); |
| 82 | 82 |
| 83 Should("Exponential ramp from 2 to -1", actual) | 83 should(actual, "Exponential ramp from 2 to -1") |
| 84 .beConstantValueOf(2); | 84 .beConstantValueOf(2); |
| 85 }).then(done); | 85 }).then(() => task.done()); |
| 86 }); | 86 }); |
| 87 | 87 |
| 88 audit.defineTask("positive-end", function (done) { | 88 audit.define("positive-end", (task, should) => { |
| 89 // Positive start value and negative end value should just do nothing. | 89 // Positive start value and negative end value should just do nothing. |
| 90 var renderDuration = 0.125; | 90 var renderDuration = 0.125; |
| 91 var context = new OfflineAudioContext(1, renderDuration * sampleRate, sa
mpleRate); | 91 var context = new OfflineAudioContext(1, renderDuration * sampleRate, sa
mpleRate); |
| 92 var source = context.createBufferSource(); | 92 var source = context.createBufferSource(); |
| 93 source.buffer = createConstantBuffer(context, 1, 1); | 93 source.buffer = createConstantBuffer(context, 1, 1); |
| 94 source.loop = true; | 94 source.loop = true; |
| 95 | 95 |
| 96 var g = context.createGain(); | 96 var g = context.createGain(); |
| 97 | 97 |
| 98 g.gain.setValueAtTime(-1, 0); | 98 g.gain.setValueAtTime(-1, 0); |
| 99 g.gain.exponentialRampToValueAtTime(1, renderDuration); | 99 g.gain.exponentialRampToValueAtTime(1, renderDuration); |
| 100 | 100 |
| 101 source.connect(g) | 101 source.connect(g) |
| 102 .connect(context.destination); | 102 .connect(context.destination); |
| 103 source.start(); | 103 source.start(); |
| 104 | 104 |
| 105 context.startRendering().then(function (resultBuffer) { | 105 context.startRendering().then(function (resultBuffer) { |
| 106 var actual = resultBuffer.getChannelData(0); | 106 var actual = resultBuffer.getChannelData(0); |
| 107 | 107 |
| 108 Should("Exponential ramp from -1 to 1", actual) | 108 should(actual, "Exponential ramp from -1 to 1") |
| 109 .beConstantValueOf(-1); | 109 .beConstantValueOf(-1); |
| 110 }).then(done); | 110 }).then(() => task.done()); |
| 111 }); | 111 }); |
| 112 | 112 |
| 113 audit.defineTask("propagate", function (done) { | 113 audit.define("propagate", (task, should) => { |
| 114 // Test propagation of ramp if the exponential ramp start and end values
have opposite sign. | 114 // Test propagation of ramp if the exponential ramp start and end values
have opposite sign. |
| 115 var renderDuration = 0.125; | 115 var renderDuration = 0.125; |
| 116 var linearRampEnd = renderDuration / 4; | 116 var linearRampEnd = renderDuration / 4; |
| 117 var exponentialRampEnd = renderDuration / 2; | 117 var exponentialRampEnd = renderDuration / 2; |
| 118 | 118 |
| 119 var context = new OfflineAudioContext(1, renderDuration * sampleRate, sa
mpleRate); | 119 var context = new OfflineAudioContext(1, renderDuration * sampleRate, sa
mpleRate); |
| 120 var source = context.createBufferSource(); | 120 var source = context.createBufferSource(); |
| 121 source.buffer = createConstantBuffer(context, 1, 1); | 121 source.buffer = createConstantBuffer(context, 1, 1); |
| 122 source.loop = true; | 122 source.loop = true; |
| 123 | 123 |
| 124 var g = context.createGain(); | 124 var g = context.createGain(); |
| 125 | 125 |
| 126 g.gain.setValueAtTime(2, 0); | 126 g.gain.setValueAtTime(2, 0); |
| 127 g.gain.linearRampToValueAtTime(-1, linearRampEnd); | 127 g.gain.linearRampToValueAtTime(-1, linearRampEnd); |
| 128 g.gain.exponentialRampToValueAtTime(1, exponentialRampEnd); | 128 g.gain.exponentialRampToValueAtTime(1, exponentialRampEnd); |
| 129 | 129 |
| 130 source.connect(g) | 130 source.connect(g) |
| 131 .connect(context.destination); | 131 .connect(context.destination); |
| 132 source.start(); | 132 source.start(); |
| 133 | 133 |
| 134 context.startRendering().then(function (resultBuffer) { | 134 context.startRendering().then(function (resultBuffer) { |
| 135 var actual = resultBuffer.getChannelData(0); | 135 var actual = resultBuffer.getChannelData(0); |
| 136 | 136 |
| 137 // Since the start value of the exponential ramp is -1 and the end val
ue is 1, the ramp | 137 // Since the start value of the exponential ramp is -1 and the end val
ue is 1, the ramp |
| 138 // should just propagate -1 from the end of the linear ramp "forever". | 138 // should just propagate -1 from the end of the linear ramp "forever". |
| 139 var endFrame = Math.ceil(linearRampEnd * sampleRate); | 139 var endFrame = Math.ceil(linearRampEnd * sampleRate); |
| 140 Should("Exponential ramp from -1 to 1 after the end of the linear ramp
", | 140 should(actual.slice(endFrame), |
| 141 actual.slice(endFrame)) | 141 "Exponential ramp from -1 to 1 after the end of the linear ramp") |
| 142 .beConstantValueOf(-1); | 142 .beConstantValueOf(-1); |
| 143 }).then(done); | 143 }).then(() => task.done()); |
| 144 | 144 |
| 145 }); | 145 }); |
| 146 | 146 |
| 147 audit.defineTask("finish", function (done) { | 147 audit.run(); |
| 148 done(); | |
| 149 }); | |
| 150 | |
| 151 audit.runTasks(); | |
| 152 </script> | 148 </script> |
| 153 </body> | 149 </body> |
| 154 </html> | 150 </html> |
| OLD | NEW |