| OLD | NEW |
| 1 <!doctype html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>Test Clamping of PannerNode rolloffFactor</title> | 4 <title> |
| 5 Test Clamping of PannerNode rolloffFactor |
| 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 </head> | 11 </head> |
| 12 <body> |
| 13 <script id="layout-test-code"> |
| 14 // Fairly arbitrary sample rate and render frames. |
| 15 let sampleRate = 16000; |
| 16 let renderFrames = 2048; |
| 10 | 17 |
| 11 <body> | 18 let audit = Audit.createTaskRunner(); |
| 12 <script> | |
| 13 // Fairly arbitrary sample rate and render frames. | |
| 14 var sampleRate = 16000; | |
| 15 var renderFrames = 2048; | |
| 16 | |
| 17 var audit = Audit.createTaskRunner(); | |
| 18 | 19 |
| 19 audit.define("linear-clamp-low", (task, should) => { | 20 audit.define('linear-clamp-low', (task, should) => { |
| 20 runTest(should, { | 21 runTest(should, { |
| 21 distanceModel: "linear", | 22 distanceModel: 'linear', |
| 22 // Fairly arbitrary value outside the nominal range | 23 // Fairly arbitrary value outside the nominal range |
| 23 rolloffFactor: -1, | 24 rolloffFactor: -1, |
| 24 clampedRolloff: 0 | 25 clampedRolloff: 0 |
| 25 }).then(() => task.done()); | 26 }).then(() => task.done()); |
| 26 }); | 27 }); |
| 27 | 28 |
| 28 audit.define("linear-clamp-high", (task, should) => { | 29 audit.define('linear-clamp-high', (task, should) => { |
| 29 runTest(should, { | 30 runTest(should, { |
| 30 distanceModel: "linear", | 31 distanceModel: 'linear', |
| 31 // Fairly arbitrary value outside the nominal range | 32 // Fairly arbitrary value outside the nominal range |
| 32 rolloffFactor: 2, | 33 rolloffFactor: 2, |
| 33 clampedRolloff: 1 | 34 clampedRolloff: 1 |
| 34 }).then(() => task.done()); | 35 }).then(() => task.done()); |
| 35 }); | 36 }); |
| 36 | 37 |
| 37 audit.define("inverse-clamp", (task, should) => { | 38 audit.define('inverse-clamp', (task, should) => { |
| 38 runTest(should, { | 39 runTest(should, { |
| 39 distanceModel: "inverse", | 40 distanceModel: 'inverse', |
| 40 // Fairly arbitrary value outside the nominal range | 41 // Fairly arbitrary value outside the nominal range |
| 41 rolloffFactor: -1, | 42 rolloffFactor: -1, |
| 42 clampedRolloff: 0 | 43 clampedRolloff: 0 |
| 43 }).then(() => task.done()); | 44 }).then(() => task.done()); |
| 44 }); | 45 }); |
| 45 | 46 |
| 46 audit.define("exponential-clamp", (task, should) => { | 47 audit.define('exponential-clamp', (task, should) => { |
| 47 runTest(should, { | 48 runTest(should, { |
| 48 distanceModel: "exponential", | 49 distanceModel: 'exponential', |
| 49 // Fairly arbitrary value outside the nominal range | 50 // Fairly arbitrary value outside the nominal range |
| 50 rolloffFactor: -2, | 51 rolloffFactor: -2, |
| 51 clampedRolloff: 0 | 52 clampedRolloff: 0 |
| 52 }).then(() => task.done()); | 53 }).then(() => task.done()); |
| 53 }); | 54 }); |
| 54 | 55 |
| 55 // Test clamping of the rolloffFactor. The test is done by comparing the | 56 // Test clamping of the rolloffFactor. The test is done by comparing the |
| 56 // output of a panner with the rolloffFactor set outside the nominal range | 57 // output of a panner with the rolloffFactor set outside the nominal range |
| 57 // against the output of a panner with the rolloffFactor clamped to the | 58 // against the output of a panner with the rolloffFactor clamped to the |
| 58 // nominal range. The outputs should be the same. | 59 // nominal range. The outputs should be the same. |
| 59 // | 60 // |
| 60 // The |options| dictionary should contain the members | 61 // The |options| dictionary should contain the members |
| 61 // distanceModel - The distance model to use for the panners | 62 // distanceModel - The distance model to use for the panners |
| 62 // rolloffFactor - The desired rolloffFactor. Should be outside the | 63 // rolloffFactor - The desired rolloffFactor. Should be outside the |
| 63 // nominal range of the distance model. | 64 // nominal range of the distance model. |
| 64 // clampedRolloff - The rolloffFactor (above) clamped to the nominal | 65 // clampedRolloff - The rolloffFactor (above) clamped to the nominal |
| 65 // range for the given distance model. | 66 // range for the given distance model. |
| 66 function runTest(should, options) { | 67 function runTest(should, options) { |
| 67 // Offline context with two channels. The first channel is the panner | 68 // Offline context with two channels. The first channel is the panner |
| 68 // node under test. The second channel is the reference panner node. | 69 // node under test. The second channel is the reference panner node. |
| 69 var context = new OfflineAudioContext(2, renderFrames, sampleRate); | 70 let context = new OfflineAudioContext(2, renderFrames, sampleRate); |
| 70 | 71 |
| 71 // The source for the panner nodes. This is fairly arbitrary. | 72 // The source for the panner nodes. This is fairly arbitrary. |
| 72 var src = new OscillatorNode(context, { | 73 let src = new OscillatorNode(context, {type: 'sawtooth'}); |
| 73 type: "sawtooth" | |
| 74 }); | |
| 75 | 74 |
| 76 // Create the test panner with the specified rolloff factor. The | 75 // Create the test panner with the specified rolloff factor. The |
| 77 // position is fairly arbitrary, but something that is not the default | 76 // position is fairly arbitrary, but something that is not the default |
| 78 // is good to show the distance model had some effect. | 77 // is good to show the distance model had some effect. |
| 79 var pannerTest = new PannerNode(context, { | 78 let pannerTest = new PannerNode(context, { |
| 80 rolloffFactor: options.rolloffFactor, | 79 rolloffFactor: options.rolloffFactor, |
| 81 distanceModel: options.distanceModel, | 80 distanceModel: options.distanceModel, |
| 82 positionX: 5000 | 81 positionX: 5000 |
| 83 }); | 82 }); |
| 84 | 83 |
| 85 // Create the reference panner with the rolloff factor clamped to the | 84 // Create the reference panner with the rolloff factor clamped to the |
| 86 // appropriate limit. | 85 // appropriate limit. |
| 87 var pannerRef = new PannerNode(context, { | 86 let pannerRef = new PannerNode(context, { |
| 88 rolloffFactor: options.clampedRolloff, | 87 rolloffFactor: options.clampedRolloff, |
| 89 distanceModel: options.distanceModel, | 88 distanceModel: options.distanceModel, |
| 90 positionX: 5000 | 89 positionX: 5000 |
| 91 }); | 90 }); |
| 92 | 91 |
| 93 | 92 |
| 94 // Connect the source to the panners to the destination appropriately. | 93 // Connect the source to the panners to the destination appropriately. |
| 95 var merger = new ChannelMergerNode(context, { | 94 let merger = new ChannelMergerNode(context, {numberOfInputs: 2}); |
| 96 numberOfInputs: 2 | |
| 97 }); | |
| 98 | 95 |
| 99 | 96 |
| 100 src.connect(pannerTest).connect(merger, 0, 0); | 97 src.connect(pannerTest).connect(merger, 0, 0); |
| 101 src.connect(pannerRef).connect(merger, 0, 1); | 98 src.connect(pannerRef).connect(merger, 0, 1); |
| 102 | 99 |
| 103 merger.connect(context.destination); | 100 merger.connect(context.destination); |
| 104 | 101 |
| 105 src.start(); | 102 src.start(); |
| 106 | 103 |
| 107 return context.startRendering() | 104 return context.startRendering().then(function(resultBuffer) { |
| 108 .then(function (resultBuffer) { | 105 // The two channels should be the same due to the clamping. Verify |
| 109 // The two channels should be the same due to the clamping. Verify | 106 // that they are the same. |
| 110 // that they are the same. | 107 let actual = resultBuffer.getChannelData(0); |
| 111 var actual = resultBuffer.getChannelData(0); | 108 let expected = resultBuffer.getChannelData(1); |
| 112 var expected = resultBuffer.getChannelData(1); | |
| 113 | 109 |
| 114 var message = 'Panner distanceModel: "' + options.distanceModel + | 110 let message = 'Panner distanceModel: "' + options.distanceModel + |
| 115 '", rolloffFactor: ' + options.rolloffFactor; | 111 '", rolloffFactor: ' + options.rolloffFactor; |
| 116 | 112 |
| 117 should(actual, message) | 113 should(actual, message).beEqualToArray(expected); |
| 118 .beEqualToArray(expected); | 114 }); |
| 119 }); | |
| 120 } | 115 } |
| 121 | 116 |
| 122 audit.run(); | 117 audit.run(); |
| 123 </script> | 118 </script> |
| 124 </body> | 119 </body> |
| 125 </html> | 120 </html> |
| OLD | NEW |