| 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>Test Clamping of PannerNode rolloffFactor</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/audit.js"></script> |
| 9 </head> | 9 </head> |
| 10 | 10 |
| 11 <body> | 11 <body> |
| 12 <script> | 12 <script> |
| 13 // Fairly arbitrary sample rate and render frames. | 13 // Fairly arbitrary sample rate and render frames. |
| 14 var sampleRate = 16000; | 14 var sampleRate = 16000; |
| 15 var renderFrames = 2048; | 15 var renderFrames = 2048; |
| 16 | 16 |
| 17 var audit = Audit.createTaskRunner(); | 17 var audit = Audit.createTaskRunner(); |
| 18 | 18 |
| 19 audit.defineTask("linear-clamp-low", function (taskDone) { | 19 audit.define("linear-clamp-low", (task, should) => { |
| 20 runTest({ | 20 runTest(should, { |
| 21 distanceModel: "linear", | 21 distanceModel: "linear", |
| 22 // Fairly arbitrary value outside the nominal range | 22 // Fairly arbitrary value outside the nominal range |
| 23 rolloffFactor: -1, | 23 rolloffFactor: -1, |
| 24 clampedRolloff: 0 | 24 clampedRolloff: 0 |
| 25 }).then(taskDone); | 25 }).then(() => task.done()); |
| 26 }); | 26 }); |
| 27 | 27 |
| 28 audit.defineTask("linear-clamp-high", function (taskDone) { | 28 audit.define("linear-clamp-high", (task, should) => { |
| 29 runTest({ | 29 runTest(should, { |
| 30 distanceModel: "linear", | 30 distanceModel: "linear", |
| 31 // Fairly arbitrary value outside the nominal range | 31 // Fairly arbitrary value outside the nominal range |
| 32 rolloffFactor: 2, | 32 rolloffFactor: 2, |
| 33 clampedRolloff: 1 | 33 clampedRolloff: 1 |
| 34 }).then(taskDone); | 34 }).then(() => task.done()); |
| 35 }); | 35 }); |
| 36 | 36 |
| 37 audit.defineTask("inverse-clamp", function (taskDone) { | 37 audit.define("inverse-clamp", (task, should) => { |
| 38 runTest({ | 38 runTest(should, { |
| 39 distanceModel: "inverse", | 39 distanceModel: "inverse", |
| 40 // Fairly arbitrary value outside the nominal range | 40 // Fairly arbitrary value outside the nominal range |
| 41 rolloffFactor: -1, | 41 rolloffFactor: -1, |
| 42 clampedRolloff: 0 | 42 clampedRolloff: 0 |
| 43 }).then(taskDone); | 43 }).then(() => task.done()); |
| 44 }); | 44 }); |
| 45 | 45 |
| 46 audit.defineTask("exponential-clamp", function (taskDone) { | 46 audit.define("exponential-clamp", (task, should) => { |
| 47 runTest({ | 47 runTest(should, { |
| 48 distanceModel: "exponential", | 48 distanceModel: "exponential", |
| 49 // Fairly arbitrary value outside the nominal range | 49 // Fairly arbitrary value outside the nominal range |
| 50 rolloffFactor: -2, | 50 rolloffFactor: -2, |
| 51 clampedRolloff: 0 | 51 clampedRolloff: 0 |
| 52 }).then(taskDone); | 52 }).then(() => task.done()); |
| 53 }); | 53 }); |
| 54 | 54 |
| 55 // Test clamping of the rolloffFactor. The test is done by comparing the | 55 // 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 | 56 // 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 | 57 // against the output of a panner with the rolloffFactor clamped to the |
| 58 // nominal range. The outputs should be the same. | 58 // nominal range. The outputs should be the same. |
| 59 // | 59 // |
| 60 // The |options| dictionary should contain the members | 60 // The |options| dictionary should contain the members |
| 61 // distanceModel - The distance model to use for the panners | 61 // distanceModel - The distance model to use for the panners |
| 62 // rolloffFactor - The desired rolloffFactor. Should be outside the | 62 // rolloffFactor - The desired rolloffFactor. Should be outside the |
| 63 // nominal range of the distance model. | 63 // nominal range of the distance model. |
| 64 // clampedRolloff - The rolloffFactor (above) clamped to the nominal | 64 // clampedRolloff - The rolloffFactor (above) clamped to the nominal |
| 65 // range for the given distance model. | 65 // range for the given distance model. |
| 66 function runTest(options) { | 66 function runTest(should, options) { |
| 67 // Offline context with two channels. The first channel is the panner | 67 // Offline context with two channels. The first channel is the panner |
| 68 // node under test. The second channel is the reference panner node. | 68 // node under test. The second channel is the reference panner node. |
| 69 var context = new OfflineAudioContext(2, renderFrames, sampleRate); | 69 var context = new OfflineAudioContext(2, renderFrames, sampleRate); |
| 70 | 70 |
| 71 // The source for the panner nodes. This is fairly arbitrary. | 71 // The source for the panner nodes. This is fairly arbitrary. |
| 72 var src = new OscillatorNode(context, { | 72 var src = new OscillatorNode(context, { |
| 73 type: "sawtooth" | 73 type: "sawtooth" |
| 74 }); | 74 }); |
| 75 | 75 |
| 76 // Create the test panner with the specified rolloff factor. The | 76 // Create the test panner with the specified rolloff factor. The |
| (...skipping 30 matching lines...) Expand all Loading... |
| 107 return context.startRendering() | 107 return context.startRendering() |
| 108 .then(function (resultBuffer) { | 108 .then(function (resultBuffer) { |
| 109 // 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 |
| 110 // that they are the same. | 110 // that they are the same. |
| 111 var actual = resultBuffer.getChannelData(0); | 111 var actual = resultBuffer.getChannelData(0); |
| 112 var expected = resultBuffer.getChannelData(1); | 112 var expected = resultBuffer.getChannelData(1); |
| 113 | 113 |
| 114 var message = 'Panner distanceModel: "' + options.distanceModel + | 114 var message = 'Panner distanceModel: "' + options.distanceModel + |
| 115 '", rolloffFactor: ' + options.rolloffFactor; | 115 '", rolloffFactor: ' + options.rolloffFactor; |
| 116 | 116 |
| 117 var success = Should(message, actual) | 117 should(actual, message) |
| 118 .beEqualToArray(expected); | 118 .beEqualToArray(expected); |
| 119 | |
| 120 Should(message, success) | |
| 121 .summarize( | |
| 122 "correctly clamped rolloffFactor to " + options.clampedRolloff, | |
| 123 "did not correctly clamp rolloffFactor to " + options.clampedRol
loff); | |
| 124 }); | 119 }); |
| 125 } | 120 } |
| 126 | 121 |
| 127 audit.runTasks(); | 122 audit.run(); |
| 128 </script> | 123 </script> |
| 129 </body> | 124 </body> |
| 130 </html> | 125 </html> |
| OLD | NEW |