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