| OLD | NEW |
| 1 <!doctype html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>Test Constructor: PeriodicWave</title> | 4 <title> |
| 5 Test Constructor: PeriodicWave |
| 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 <script src="audionodeoptions.js"></script> | 11 <script src="audionodeoptions.js"></script> |
| 10 </head> | 12 </head> |
| 13 <body> |
| 14 <script id="layout-test-code"> |
| 15 let context; |
| 11 | 16 |
| 12 <body> | 17 let audit = Audit.createTaskRunner(); |
| 13 <script> | |
| 14 var context; | |
| 15 | |
| 16 var audit = Audit.createTaskRunner(); | |
| 17 | 18 |
| 18 audit.define('initialize', (task, should) => { | 19 audit.define('initialize', (task, should) => { |
| 19 context = initializeContext(should); | 20 context = initializeContext(should); |
| 20 task.done(); | 21 task.done(); |
| 21 }); | 22 }); |
| 22 | 23 |
| 23 audit.define('invalid constructor', (task, should) => { | 24 audit.define('invalid constructor', (task, should) => { |
| 24 testInvalidConstructor(should, 'PeriodicWave', context); | 25 testInvalidConstructor(should, 'PeriodicWave', context); |
| 25 task.done(); | 26 task.done(); |
| 26 }); | 27 }); |
| 27 | 28 |
| 28 audit.define('default constructor', (task, should) => { | 29 audit.define('default constructor', (task, should) => { |
| 29 should(() => { | 30 should(() => { |
| 30 node = new PeriodicWave(context); | 31 node = new PeriodicWave(context); |
| 31 }, 'node = new PeriodicWave(context)').notThrow(); | 32 }, 'node = new PeriodicWave(context)').notThrow(); |
| 32 | 33 |
| 33 task.done(); | 34 task.done(); |
| 34 }); | 35 }); |
| 35 | 36 |
| 36 audit.define('constructor with options', (task, should) => { | 37 audit.define('constructor with options', (task, should) => { |
| 37 var node1; | 38 let node1; |
| 38 var options = {real: [1, 1]}; | 39 let options = {real: [1, 1]}; |
| 39 should( | 40 should( |
| 40 () => { | 41 () => { |
| 41 node1 = new PeriodicWave(context, options); | 42 node1 = new PeriodicWave(context, options); |
| 42 }, | 43 }, |
| 43 'node = new PeriodicWave(context, ' + JSON.stringify(options) + ')') | 44 'node = new PeriodicWave(context, ' + JSON.stringify(options) + ')') |
| 44 .notThrow(); | 45 .notThrow(); |
| 45 should(node1 instanceof PeriodicWave, 'node1 instanceof PeriodicWave') | 46 should(node1 instanceof PeriodicWave, 'node1 instanceof PeriodicWave') |
| 46 .beEqualTo(true); | 47 .beEqualTo(true); |
| 47 | 48 |
| 48 var node2; | 49 let node2; |
| 49 options = {imag: [1, 1]}; | 50 options = {imag: [1, 1]}; |
| 50 should( | 51 should( |
| 51 () => { | 52 () => { |
| 52 node2 = new PeriodicWave(context, options); | 53 node2 = new PeriodicWave(context, options); |
| 53 }, | 54 }, |
| 54 'node2 = new PeriodicWave(context, ' + JSON.stringify(options) + | 55 'node2 = new PeriodicWave(context, ' + JSON.stringify(options) + |
| 55 ')') | 56 ')') |
| 56 .notThrow(); | 57 .notThrow(); |
| 57 should(node2 instanceof PeriodicWave, 'node2 instanceof PeriodicWave') | 58 should(node2 instanceof PeriodicWave, 'node2 instanceof PeriodicWave') |
| 58 .beEqualTo(true); | 59 .beEqualTo(true); |
| 59 | 60 |
| 60 var node3; | 61 let node3; |
| 61 options = {real: [1, 2], imag: [1, 1]}; | 62 options = {real: [1, 2], imag: [1, 1]}; |
| 62 should( | 63 should( |
| 63 () => { | 64 () => { |
| 64 node3 = new PeriodicWave(context, options); | 65 node3 = new PeriodicWave(context, options); |
| 65 }, | 66 }, |
| 66 'node3 = new PeriodicWave(context, ' + JSON.stringify(options) + | 67 'node3 = new PeriodicWave(context, ' + JSON.stringify(options) + |
| 67 ')') | 68 ')') |
| 68 .notThrow(); | 69 .notThrow(); |
| 69 should(node3 instanceof PeriodicWave, 'node3 instanceof PeriodicWave') | 70 should(node3 instanceof PeriodicWave, 'node3 instanceof PeriodicWave') |
| 70 .beEqualTo(true); | 71 .beEqualTo(true); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 verifyPeriodicWaveOutput( | 142 verifyPeriodicWaveOutput( |
| 142 should, {real: [0, 1], imag: [0, 1], disableNormalization: true}, | 143 should, {real: [0, 1], imag: [0, 1], disableNormalization: true}, |
| 143 generateReference(x => Math.sin(x) + Math.cos(x)), 3.8416e-5) | 144 generateReference(x => Math.sin(x) + Math.cos(x)), 3.8416e-5) |
| 144 .then(() => task.done()); | 145 .then(() => task.done()); |
| 145 }); | 146 }); |
| 146 | 147 |
| 147 // Returns a function that generates the expected reference array where | 148 // Returns a function that generates the expected reference array where |
| 148 // the samples are generated by the function |gen|. | 149 // the samples are generated by the function |gen|. |
| 149 function generateReference(gen) { | 150 function generateReference(gen) { |
| 150 return (length, freq, sampleRate) => { | 151 return (length, freq, sampleRate) => { |
| 151 var expected = new Float32Array(length); | 152 let expected = new Float32Array(length); |
| 152 var omega = 2 * Math.PI * freq / sampleRate; | 153 let omega = 2 * Math.PI * freq / sampleRate; |
| 153 for (var k = 0; k < length; ++k) { | 154 for (let k = 0; k < length; ++k) { |
| 154 expected[k] = gen(omega * k); | 155 expected[k] = gen(omega * k); |
| 155 } | 156 } |
| 156 return expected; | 157 return expected; |
| 157 }; | 158 }; |
| 158 } | 159 } |
| 159 | 160 |
| 160 // Verify that an oscillator constructed from the given periodic wave | 161 // Verify that an oscillator constructed from the given periodic wave |
| 161 // produces the expected result. | 162 // produces the expected result. |
| 162 function verifyPeriodicWaveOutput( | 163 function verifyPeriodicWaveOutput( |
| 163 should, waveOptions, expectedFunction, threshold) { | 164 should, waveOptions, expectedFunction, threshold) { |
| 164 var node; | 165 let node; |
| 165 // Rather arbitrary sample rate and render length. Length doesn't have | 166 // Rather arbitrary sample rate and render length. Length doesn't have |
| 166 // to be very long. | 167 // to be very long. |
| 167 var sampleRate = 48000; | 168 let sampleRate = 48000; |
| 168 var renderLength = 0.25; | 169 let renderLength = 0.25; |
| 169 var testContext = | 170 let testContext = |
| 170 new OfflineAudioContext(1, renderLength * sampleRate, sampleRate); | 171 new OfflineAudioContext(1, renderLength * sampleRate, sampleRate); |
| 171 | 172 |
| 172 var options = { | 173 let options = { |
| 173 periodicWave: new PeriodicWave(testContext, waveOptions) | 174 periodicWave: new PeriodicWave(testContext, waveOptions) |
| 174 }; | 175 }; |
| 175 node = new OscillatorNode(testContext, options); | 176 node = new OscillatorNode(testContext, options); |
| 176 | 177 |
| 177 // Create the graph | 178 // Create the graph |
| 178 node.connect(testContext.destination); | 179 node.connect(testContext.destination); |
| 179 node.start(); | 180 node.start(); |
| 180 | 181 |
| 181 return testContext.startRendering().then(function(resultBuffer) { | 182 return testContext.startRendering().then(function(resultBuffer) { |
| 182 var actual = resultBuffer.getChannelData(0); | 183 let actual = resultBuffer.getChannelData(0); |
| 183 var expected = expectedFunction( | 184 let expected = expectedFunction( |
| 184 actual.length, node.frequency.value, testContext.sampleRate); | 185 actual.length, node.frequency.value, testContext.sampleRate); |
| 185 // Actual must match expected to within the (experimentally) | 186 // Actual must match expected to within the (experimentally) |
| 186 // determined threshold. | 187 // determined threshold. |
| 187 var message = ''; | 188 let message = ''; |
| 188 if (waveOptions.disableNormalization != undefined) | 189 if (waveOptions.disableNormalization != undefined) |
| 189 message = | 190 message = |
| 190 'disableNormalization: ' + waveOptions.disableNormalization; | 191 'disableNormalization: ' + waveOptions.disableNormalization; |
| 191 if (waveOptions.real) { | 192 if (waveOptions.real) { |
| 192 if (message.length > 0) | 193 if (message.length > 0) |
| 193 message += ', ' | 194 message += ', ' |
| 194 message += 'real: [' + waveOptions.real + ']'; | 195 message += 'real: [' + waveOptions.real + ']'; |
| 195 } | 196 } |
| 196 if (waveOptions.imag) { | 197 if (waveOptions.imag) { |
| 197 if (message.length > 0) | 198 if (message.length > 0) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 sineWaveTest( | 250 sineWaveTest( |
| 250 should, (context) => new PeriodicWave(context, {foo: 42}), | 251 should, (context) => new PeriodicWave(context, {foo: 42}), |
| 251 'new PeriodicWave(context, {foo: 42}) output') | 252 'new PeriodicWave(context, {foo: 42}) output') |
| 252 .then(() => task.done()); | 253 .then(() => task.done()); |
| 253 }); | 254 }); |
| 254 | 255 |
| 255 audit.run(); | 256 audit.run(); |
| 256 </script> | 257 </script> |
| 257 </body> | 258 </body> |
| 258 </html> | 259 </html> |
| OLD | NEW |