| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 | 3 |
| 4 <head> | 4 <head> |
| 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/audit.js"></script> |
| 9 <script src="../resources/audioparam-testing.js"></script> | 9 <script src="../resources/audioparam-testing.js"></script> |
| 10 </head> | 10 </head> |
| 11 | 11 |
| 12 <body> | 12 <body> |
| 13 <script> | 13 <script> |
| 14 | 14 |
| 15 var sampleRate = 8000; | 15 var sampleRate = 8000; |
| 16 | 16 |
| 17 // Create a dummy array for setValueCurveAtTime method. | 17 // Create a dummy array for setValueCurveAtTime method. |
| 18 var curveArray = new Float32Array([5.0, 6.0]); | 18 var curveArray = new Float32Array([5.0, 6.0]); |
| 19 | 19 |
| 20 // AudioNode dictionary with associated dummy arguments. | 20 // AudioNode dictionary with associated dummy arguments. |
| 21 var methodDictionary = [ | 21 var methodDictionary = [ |
| 22 { name: 'setValueAtTime', args: [1.0, 0.0] }, | 22 { name: 'setValueAtTime', args: [1.0, 0.0] }, |
| 23 { name: 'linearRampToValueAtTime', args: [2.0, 1.0] }, | 23 { name: 'linearRampToValueAtTime', args: [2.0, 1.0] }, |
| 24 { name: 'exponentialRampToValueAtTime', args: [3.0, 2.0] }, | 24 { name: 'exponentialRampToValueAtTime', args: [3.0, 2.0] }, |
| 25 { name: 'setTargetAtTime', args: [4.0, 2.0, 0.5] }, | 25 { name: 'setTargetAtTime', args: [4.0, 2.0, 0.5] }, |
| 26 { name: 'setValueCurveAtTime', args: [curveArray, 5.0, 1.0] }, | 26 { name: 'setValueCurveAtTime', args: [curveArray, 5.0, 1.0] }, |
| 27 { name: 'cancelScheduledValues', args: [6.0] } | 27 { name: 'cancelScheduledValues', args: [6.0] } |
| 28 ]; | 28 ]; |
| 29 | 29 |
| 30 function verifyReturnedParam(config) { | |
| 31 Should('The return value of ' + config.desc + ' matches the source AudioPa
ram', | |
| 32 config.source === config.returned) | |
| 33 .beEqualTo(true); | |
| 34 } | |
| 35 | |
| 36 var audit = Audit.createTaskRunner(); | 30 var audit = Audit.createTaskRunner(); |
| 37 | 31 |
| 38 // Task: testing entries from the dictionary. | 32 // Task: testing entries from the dictionary. |
| 39 audit.defineTask('from-dictionary', function (done) { | 33 audit.define('from-dictionary', (task, should) => { |
| 40 var context = new AudioContext(); | 34 var context = new AudioContext(); |
| 41 | 35 |
| 42 methodDictionary.forEach(function (method) { | 36 methodDictionary.forEach(function (method) { |
| 43 var sourceParam = context.createGain().gain; | 37 var sourceParam = context.createGain().gain; |
| 44 verifyReturnedParam({ | 38 should(sourceParam === sourceParam[method.name](...method.args), |
| 45 source: sourceParam, | 39 'The return value of ' + sourceParam.constructor.name + '.' + |
| 46 returned: sourceParam[method.name](...method.args), | 40 method.name + '()' + ' matches the source AudioParam') |
| 47 desc: sourceParam.constructor.name + '.' + method.name + '()' | 41 .beEqualTo(true); |
| 48 }); | 42 |
| 49 }); | 43 }); |
| 50 | 44 |
| 51 done(); | 45 task.done(); |
| 52 }); | 46 }); |
| 53 | 47 |
| 54 // Task: test method chaining with invalid operation. | 48 // Task: test method chaining with invalid operation. |
| 55 audit.defineTask('invalid-operation', function (done) { | 49 audit.define('invalid-operation', (task, should) => { |
| 56 var context = new OfflineAudioContext(1, sampleRate, sampleRate); | 50 var context = new OfflineAudioContext(1, sampleRate, sampleRate); |
| 57 var osc = context.createOscillator(); | 51 var osc = context.createOscillator(); |
| 58 var amp1 = context.createGain(); | 52 var amp1 = context.createGain(); |
| 59 var amp2 = context.createGain(); | 53 var amp2 = context.createGain(); |
| 60 | 54 |
| 61 osc.connect(amp1); | 55 osc.connect(amp1); |
| 62 osc.connect(amp2); | 56 osc.connect(amp2); |
| 63 amp1.connect(context.destination); | 57 amp1.connect(context.destination); |
| 64 amp2.connect(context.destination); | 58 amp2.connect(context.destination); |
| 65 | 59 |
| 66 // The first operation fails with an exception, thus the second one | 60 // The first operation fails with an exception, thus the second one |
| 67 // should not have effect on the parameter value. Instead, it should | 61 // should not have effect on the parameter value. Instead, it should |
| 68 // maintain the default value of 1.0. | 62 // maintain the default value of 1.0. |
| 69 Should('Calling setValueAtTime() with a negative end time', function () { | 63 should(function () { |
| 70 amp1.gain | 64 amp1.gain |
| 71 .setValueAtTime(0.25, -1.0) | 65 .setValueAtTime(0.25, -1.0) |
| 72 .linearRampToValueAtTime(2.0, 1.0); | 66 .linearRampToValueAtTime(2.0, 1.0); |
| 73 }).throw('InvalidAccessError'); | 67 }, |
| 68 'Calling setValueAtTime() with a negative end time') |
| 69 .throw('InvalidAccessError'); |
| 74 | 70 |
| 75 // The first operation succeeds but the second fails due to zero target | 71 // The first operation succeeds but the second fails due to zero target |
| 76 // value for the exponential ramp. Thus only the first should have effect | 72 // value for the exponential ramp. Thus only the first should have effect |
| 77 // on the parameter value, setting the value to 0.5. | 73 // on the parameter value, setting the value to 0.5. |
| 78 Should('Calling exponentialRampToValueAtTime() with a zero target value',
function () { | 74 should(function () { |
| 79 amp2.gain | 75 amp2.gain |
| 80 .setValueAtTime(0.5, 0.0) | 76 .setValueAtTime(0.5, 0.0) |
| 81 .exponentialRampToValueAtTime(0.0, 1.0); | 77 .exponentialRampToValueAtTime(0.0, 1.0); |
| 82 }).throw('InvalidAccessError'); | 78 }, |
| 79 'Calling exponentialRampToValueAtTime() with a zero target value') |
| 80 .throw('InvalidAccessError'); |
| 83 | 81 |
| 84 osc.start(); | 82 osc.start(); |
| 85 osc.stop(1.0); | 83 osc.stop(1.0); |
| 86 | 84 |
| 87 context.startRendering().then(function (buffer) { | 85 context.startRendering().then(function (buffer) { |
| 88 Should('The gain value of the first gain node', amp1.gain.value).beEqual
To(1.0); | 86 should(amp1.gain.value, 'The gain value of the first gain node').beEqual
To(1.0); |
| 89 Should('The gain value of the second gain node', amp2.gain.value).beEqua
lTo(0.5); | 87 should(amp2.gain.value, 'The gain value of the second gain node').beEqua
lTo(0.5); |
| 90 }).then(done); | 88 }).then(() => task.done()); |
| 91 }); | 89 }); |
| 92 | 90 |
| 93 // Task: verify if the method chaining actually works. Create an arbitrary | 91 // Task: verify if the method chaining actually works. Create an arbitrary |
| 94 // envelope and compare the result with the expected one created by JS code. | 92 // envelope and compare the result with the expected one created by JS code. |
| 95 audit.defineTask('verification', function (done) { | 93 audit.define('verification', (task, should) => { |
| 96 var context = new OfflineAudioContext(1, sampleRate * 4, sampleRate); | 94 var context = new OfflineAudioContext(1, sampleRate * 4, sampleRate); |
| 97 var constantBuffer = createConstantBuffer(context, 1, 1.0); | 95 var constantBuffer = createConstantBuffer(context, 1, 1.0); |
| 98 | 96 |
| 99 var source = context.createBufferSource(); | 97 var source = context.createBufferSource(); |
| 100 source.buffer = constantBuffer; | 98 source.buffer = constantBuffer; |
| 101 source.loop = true; | 99 source.loop = true; |
| 102 | 100 |
| 103 var envelope = context.createGain(); | 101 var envelope = context.createGain(); |
| 104 | 102 |
| 105 source.connect(envelope); | 103 source.connect(envelope); |
| 106 envelope.connect(context.destination); | 104 envelope.connect(context.destination); |
| 107 | 105 |
| 108 envelope.gain | 106 envelope.gain |
| 109 .setValueAtTime(0.0, 0.0) | 107 .setValueAtTime(0.0, 0.0) |
| 110 .linearRampToValueAtTime(1.0, 1.0) | 108 .linearRampToValueAtTime(1.0, 1.0) |
| 111 .exponentialRampToValueAtTime(0.5, 2.0) | 109 .exponentialRampToValueAtTime(0.5, 2.0) |
| 112 .setTargetAtTime(0.001, 2.0, 0.5); | 110 .setTargetAtTime(0.001, 2.0, 0.5); |
| 113 | 111 |
| 114 source.start(); | 112 source.start(); |
| 115 | 113 |
| 116 context.startRendering().then(function (buffer) { | 114 context.startRendering().then(function (buffer) { |
| 117 var expectedEnvelope = createLinearRampArray(0.0, 1.0, 0.0, 1.0, sampleR
ate); | 115 var expectedEnvelope = createLinearRampArray(0.0, 1.0, 0.0, 1.0, sampleR
ate); |
| 118 expectedEnvelope.push(...createExponentialRampArray(1.0, 2.0, 1.0, 0.5,
sampleRate)); | 116 expectedEnvelope.push(...createExponentialRampArray(1.0, 2.0, 1.0, 0.5,
sampleRate)); |
| 119 expectedEnvelope.push(...createExponentialApproachArray(2.0, 4.0, 0.5, 0
.001, sampleRate, 0.5)); | 117 expectedEnvelope.push(...createExponentialApproachArray(2.0, 4.0, 0.5, 0
.001, sampleRate, 0.5)); |
| 120 | 118 |
| 121 // There are slight differences between JS implementation of AudioParam | 119 // There are slight differences between JS implementation of AudioParam |
| 122 // envelope and the internal implementation. (i.e. double/float and | 120 // envelope and the internal implementation. (i.e. double/float and |
| 123 // rounding up) The error threshold is adjusted empirically through | 121 // rounding up) The error threshold is adjusted empirically through |
| 124 // the local testing. | 122 // the local testing. |
| 125 Should('The rendered envelope', buffer.getChannelData(0), { | 123 should(buffer.getChannelData(0), 'The rendered envelope') |
| 126 numberOfArrayLog: 5 | 124 .beCloseToArray(expectedEnvelope, {absoluteThreshold: 4.0532e-6}); |
| 127 }).beCloseToArray(expectedEnvelope, 4.0532e-6); | 125 }).then(() => task.done()); |
| 128 }).then(done); | |
| 129 }); | 126 }); |
| 130 | 127 |
| 131 audit.defineTask('finish', function (done) { | 128 audit.run(); |
| 132 done(); | |
| 133 }); | |
| 134 | |
| 135 audit.runTasks(); | |
| 136 | |
| 137 successfullyParsed = true; | |
| 138 </script> | 129 </script> |
| 139 </body> | 130 </body> |
| 140 | 131 |
| 141 </html> | 132 </html> |
| OLD | NEW |