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