Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <title>Test the PeriodicWave interface</title>
5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
6 <script type="text/javascript" src="webaudio.js"></script>
7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
8 </head>
9 <body>
10 <pre id="test">
11 <script class="testbody" type="text/javascript">
13 SimpleTest.waitForExplicitFinish();
15 // real and imag are used in separate PeriodicWaves to make their peak values
16 // easy to determine.
17 const realMax = 99;
18 var real = new Float32Array(realMax + 1);
19 real[1] = 2.0; // fundamental
20 real[realMax] = 3.0;
21 const realPeak = real[1] + real[realMax];
22 const realFundamental = 19.0;
23 var imag = new Float32Array(4);
24 imag[0] = 6.0; // should be ignored.
25 imag[3] = 0.5;
26 const imagPeak = imag[3];
27 const imagFundamental = 551.0;
29 const testLength = 4096;
31 addLoadEvent(function() {
32 var ac = new AudioContext();
33 ac.createPeriodicWave(new Float32Array(4096), new Float32Array(4096));
34 expectException(function() {
35 ac.createPeriodicWave(new Float32Array(512), imag);
36 }, DOMException.NOT_SUPPORTED_ERR);
37 expectException(function() {
38 ac.createPeriodicWave(new Float32Array(0), new Float32Array(0));
39 }, DOMException.NOT_SUPPORTED_ERR);
40 expectException(function() {
41 ac.createPeriodicWave(new Float32Array(4097), new Float32Array(4097));
42 }, DOMException.NOT_SUPPORTED_ERR);
44 runTest();
45 });
47 var gTest = {
48 createGraph: function(context) {
49 var merger = context.createChannelMerger();
51 var osc0 = context.createOscillator();
52 var osc1 = context.createOscillator();
54 osc0.setPeriodicWave(context.
55 createPeriodicWave(real,
56 new Float32Array(real.length)));
57 osc1.setPeriodicWave(context.
58 createPeriodicWave(new Float32Array(imag.length),
59 imag));
61 osc0.frequency.value = realFundamental;
62 osc1.frequency.value = imagFundamental;
64 osc0.start();
65 osc1.start();
67 osc0.connect(merger, 0, 0);
68 osc1.connect(merger, 0, 1);
70 return merger;
71 },
72 createExpectedBuffers: function(context) {
73 var buffer = context.createBuffer(2, testLength, context.sampleRate);
75 for (var i = 0; i < buffer.length; ++i) {
77 buffer.getChannelData(0)[i] = 1.0 / realPeak *
78 (real[1] * Math.cos(2 * Math.PI * realFundamental * i /
79 context.sampleRate) +
80 real[realMax] * Math.cos(2 * Math.PI * realMax * realFundamental * i /
81 context.sampleRate));
83 buffer.getChannelData(1)[i] = 1.0 / imagPeak *
84 imag[3] * Math.sin(2 * Math.PI * 3 * imagFundamental * i /
85 context.sampleRate);
86 }
87 return buffer;
88 },
89 };
91 </script>
92 </pre>
93 </body>
94 </html>