| OLD | NEW |
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>Test ConstantSourceNode Output</title> | 4 <title>Test ConstantSourceNode Output</title> |
| 5 <script src="../../resources/testharness.js"></script> | 5 <script src="../../resources/testharness.js"></script> |
| 6 <script src="../../resources/testharnessreport.js"></script> | 6 <script src="../../resources/testharnessreport.js"></script> |
| 7 <script src="../resources/audit-util.js"></script> | 7 <script src="../resources/audit-util.js"></script> |
| 8 <script src="../resources/audio-testing.js"></script> | 8 <script src="../resources/audio-testing.js"></script> |
| 9 <script src="../resources/audioparam-testing.js"></script> | 9 <script src="../resources/audioparam-testing.js"></script> |
| 10 </head> | 10 </head> |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 offset: 0.5 | 24 offset: 0.5 |
| 25 }); | 25 }); |
| 26 node.connect(context.destination); | 26 node.connect(context.destination); |
| 27 node.start(); | 27 node.start(); |
| 28 | 28 |
| 29 context.startRendering().then(function (buffer) { | 29 context.startRendering().then(function (buffer) { |
| 30 var actual = buffer.getChannelData(0); | 30 var actual = buffer.getChannelData(0); |
| 31 var expected = new Float32Array(actual.length); | 31 var expected = new Float32Array(actual.length); |
| 32 expected.fill(node.offset.value); | 32 expected.fill(node.offset.value); |
| 33 | 33 |
| 34 Should("ConstantSourceNode({offset: 0.5})", actual) | 34 Should("Basic: ConstantSourceNode({offset: 0.5})", actual) |
| 35 .beEqualToArray(expected); | 35 .beEqualToArray(expected); |
| 36 }).then(taskDone); | 36 }).then(taskDone); |
| 37 }); | 37 }); |
| 38 | 38 |
| 39 audit.defineTask("start/stop", function (taskDone) { | 39 audit.defineTask("start/stop", function (taskDone) { |
| 40 // Verify a constant source starts and stops at the correct time and has | 40 // Verify a constant source starts and stops at the correct time and has |
| 41 // the correct (fixed) value. | 41 // the correct (fixed) value. |
| 42 var context = new OfflineAudioContext(1, renderFrames, sampleRate); | 42 var context = new OfflineAudioContext(1, renderFrames, sampleRate); |
| 43 var node = new ConstantSourceNode(context, { | 43 var node = new ConstantSourceNode(context, { |
| 44 offset: 1 | 44 offset: 1 |
| 45 }); | 45 }); |
| 46 node.connect(context.destination); | 46 node.connect(context.destination); |
| 47 | 47 |
| 48 var startFrame = 10; | 48 var startFrame = 10; |
| 49 var stopFrame = 300; | 49 var stopFrame = 300; |
| 50 | 50 |
| 51 node.start(startFrame / context.sampleRate); | 51 node.start(startFrame / context.sampleRate); |
| 52 node.stop(stopFrame / context.sampleRate); | 52 node.stop(stopFrame / context.sampleRate); |
| 53 | 53 |
| 54 context.startRendering().then(function (buffer) { | 54 context.startRendering().then(function (buffer) { |
| 55 var actual = buffer.getChannelData(0); | 55 var actual = buffer.getChannelData(0); |
| 56 var expected = new Float32Array(actual.length); | 56 var expected = new Float32Array(actual.length); |
| 57 // The expected output is all 1s from start to stop time. | 57 // The expected output is all 1s from start to stop time. |
| 58 expected.fill(0); | 58 expected.fill(0); |
| 59 | 59 |
| 60 for (var k = startFrame; k < stopFrame; ++k) { | 60 for (var k = startFrame; k < stopFrame; ++k) { |
| 61 expected[k] = node.offset.value; | 61 expected[k] = node.offset.value; |
| 62 } | 62 } |
| 63 | 63 |
| 64 var success = Should("ConstantSourceNode frames [0, " + | 64 var prefix = "start/stop: "; |
| 65 var success = Should(prefix + "ConstantSourceNode frames [0, " + |
| 65 startFrame + ")", | 66 startFrame + ")", |
| 66 actual.slice(0, startFrame)) | 67 actual.slice(0, startFrame)) |
| 67 .beConstantValueOf(0); | 68 .beConstantValueOf(0); |
| 68 | 69 |
| 69 success = Should("ConstantSourceNode frames [" + startFrame + | 70 success = Should(prefix + "ConstantSourceNode frames [" + startFrame + |
| 70 ", " + | 71 ", " + |
| 71 stopFrame + ")", | 72 stopFrame + ")", |
| 72 actual.slice(startFrame, stopFrame)) | 73 actual.slice(startFrame, stopFrame)) |
| 73 .beConstantValueOf(1) && success; | 74 .beConstantValueOf(1) && success; |
| 74 | 75 |
| 75 success = Should("ConstantSourceNode frames [" + stopFrame + ", " + | 76 success = Should(prefix + "ConstantSourceNode frames [" + stopFrame +
", " + |
| 76 renderFrames + ")", | 77 renderFrames + ")", |
| 77 actual.slice(stopFrame)) | 78 actual.slice(stopFrame)) |
| 78 .beConstantValueOf(0) && success; | 79 .beConstantValueOf(0) && success; |
| 79 | 80 |
| 80 Should("ConstantSourceNode started and stopped", success) | 81 Should("ConstantSourceNode started and stopped", success) |
| 81 .summarize( | 82 .summarize( |
| 82 "at the correct times with the correct values", | 83 "at the correct times with the correct values", |
| 83 "with the incorrect times or values"); | 84 "with the incorrect times or values"); |
| 84 }).then(taskDone); | 85 }).then(taskDone); |
| 85 | 86 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 97 | 98 |
| 98 source.start(); | 99 source.start(); |
| 99 | 100 |
| 100 context.startRendering() | 101 context.startRendering() |
| 101 .then(function (buffer) { | 102 .then(function (buffer) { |
| 102 var actual = buffer.getChannelData(0); | 103 var actual = buffer.getChannelData(0); |
| 103 var expected = createLinearRampArray(0, rampEndTime, 0.5, 1, | 104 var expected = createLinearRampArray(0, rampEndTime, 0.5, 1, |
| 104 context.sampleRate); | 105 context.sampleRate); |
| 105 | 106 |
| 106 var rampEndFrame = Math.ceil(rampEndTime * context.sampleRate); | 107 var rampEndFrame = Math.ceil(rampEndTime * context.sampleRate); |
| 107 var success = Should("ConstantSourceNode.linearRamp(1, 0.5)", | 108 var prefix = "Automation: "; |
| 109 |
| 110 var success = Should(prefix + "ConstantSourceNode.linearRamp(1, 0.5)
", |
| 108 actual.slice(0, rampEndFrame)) | 111 actual.slice(0, rampEndFrame)) |
| 109 .beCloseToArray(expected, { | 112 .beCloseToArray(expected, { |
| 110 // Experimentally determined threshold.. | 113 // Experimentally determined threshold.. |
| 111 relativeThreshold: 7.1610e-7 | 114 relativeThreshold: 7.1610e-7 |
| 112 }); | 115 }); |
| 113 | 116 |
| 114 success = Should("ConstantSourceNode after ramp", | 117 success = Should(prefix + "ConstantSourceNode after ramp", |
| 115 actual.slice(rampEndFrame)) | 118 actual.slice(rampEndFrame)) |
| 116 .beConstantValueOf(1) && success; | 119 .beConstantValueOf(1) && success; |
| 117 | 120 |
| 118 Should("ConstantSourceNode automation", success) | 121 Should("ConstantSourceNode automation", success) |
| 119 .summarize( | 122 .summarize( |
| 120 "produced the correct values", | 123 "produced the correct values", |
| 121 "did not produce the correct values"); | 124 "did not produce the correct values"); |
| 122 }) | 125 }) |
| 123 .then(taskDone); | 126 .then(taskDone); |
| 124 }); | 127 }); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 146 context.startRendering() | 149 context.startRendering() |
| 147 .then(function (buffer) { | 150 .then(function (buffer) { |
| 148 // Channel 0 and 1 should be identical, except channel 0 (the | 151 // Channel 0 and 1 should be identical, except channel 0 (the |
| 149 // source) is silent at the beginning. | 152 // source) is silent at the beginning. |
| 150 var actual = buffer.getChannelData(0); | 153 var actual = buffer.getChannelData(0); |
| 151 var expected = buffer.getChannelData(1); | 154 var expected = buffer.getChannelData(1); |
| 152 // The expected output should be oscillator + 1 because offset | 155 // The expected output should be oscillator + 1 because offset |
| 153 // is 1. | 156 // is 1. |
| 154 expected = expected.map(x => 1 + x); | 157 expected = expected.map(x => 1 + x); |
| 155 var success = true; | 158 var success = true; |
| 159 var prefix = "Connected param: "; |
| 156 | 160 |
| 157 // The initial part of the output should be silent because the | 161 // The initial part of the output should be silent because the |
| 158 // source node hasn't started yet. | 162 // source node hasn't started yet. |
| 159 success = Should("ConstantSourceNode frames [0, " + | 163 success = Should(prefix + "ConstantSourceNode frames [0, " + |
| 160 sourceStartFrame + ")", actual.slice(0, sourceStartFrame) | 164 sourceStartFrame + ")", actual.slice(0, sourceStartFrame) |
| 161 ) | 165 ) |
| 162 .beConstantValueOf(0); | 166 .beConstantValueOf(0); |
| 163 // The rest of the output should be the same as the oscillator (in | 167 // The rest of the output should be the same as the oscillator (in |
| 164 // channel 1) | 168 // channel 1) |
| 165 success = Should("ConstantSourceNode frames [" + | 169 success = Should(prefix + "ConstantSourceNode frames [" + |
| 166 sourceStartFrame + ", " + renderFrames + ")", | 170 sourceStartFrame + ", " + renderFrames + ")", |
| 167 actual.slice(sourceStartFrame)) | 171 actual.slice(sourceStartFrame)) |
| 168 .beCloseToArray(expected.slice(sourceStartFrame), 0); | 172 .beCloseToArray(expected.slice(sourceStartFrame), 0); |
| 169 | 173 |
| 170 Should("ConstantSourceNode with connected AudioParam", | 174 Should("ConstantSourceNode with connected AudioParam", |
| 171 success) | 175 success) |
| 172 .summarize( | 176 .summarize( |
| 173 "had the expected output", | 177 "had the expected output", |
| 174 "did not have the expected output"); | 178 "did not have the expected output"); |
| 175 }) | 179 }) |
| 176 .then(taskDone); | 180 .then(taskDone); |
| 177 }); | 181 }); |
| 178 | 182 |
| 179 audit.runTasks(); | 183 audit.runTasks(); |
| 180 </script> | 184 </script> |
| 181 </body> | 185 </body> |
| 182 </html> | 186 </html> |
| OLD | NEW |