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