|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <head> |
|
4 <title>Test GainNode</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"> |
|
12 |
|
13 var gTest = { |
|
14 length: 2048, |
|
15 numberOfChannels: 1, |
|
16 createGraph: function(context) { |
|
17 var buffer = context.createBuffer(1, 2048, context.sampleRate); |
|
18 for (var i = 0; i < 2048; ++i) { |
|
19 buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate); |
|
20 } |
|
21 |
|
22 var source = context.createBufferSource(); |
|
23 |
|
24 var gain = context.createGain(); |
|
25 |
|
26 source.buffer = buffer; |
|
27 |
|
28 source.connect(gain); |
|
29 |
|
30 ok(gain.gain, "The audioparam member must exist"); |
|
31 is(gain.gain.value, 1.0, "Correct initial value"); |
|
32 is(gain.gain.defaultValue, 1.0, "Correct default value"); |
|
33 gain.gain.value = 0.5; |
|
34 is(gain.gain.value, 0.5, "Correct initial value"); |
|
35 is(gain.gain.defaultValue, 1.0, "Correct default value"); |
|
36 is(gain.channelCount, 2, "gain node has 2 input channels by default"); |
|
37 is(gain.channelCountMode, "max", "Correct channelCountMode for the gain node"); |
|
38 is(gain.channelInterpretation, "speakers", "Correct channelCountInterpretation for the gain node"); |
|
39 |
|
40 source.start(0); |
|
41 return gain; |
|
42 }, |
|
43 createExpectedBuffers: function(context) { |
|
44 var expectedBuffer = context.createBuffer(1, 2048, context.sampleRate); |
|
45 for (var i = 0; i < 2048; ++i) { |
|
46 expectedBuffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate) / 2; |
|
47 } |
|
48 return expectedBuffer; |
|
49 }, |
|
50 }; |
|
51 |
|
52 runTest(); |
|
53 |
|
54 </script> |
|
55 </pre> |
|
56 </body> |
|
57 </html> |