content/media/webaudio/test/test_gainNode.html

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

     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">
    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     }
    22     var source = context.createBufferSource();
    24     var gain = context.createGain();
    26     source.buffer = buffer;
    28     source.connect(gain);
    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");
    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 };
    52 runTest();
    54 </script>
    55 </pre>
    56 </body>
    57 </html>

mercurial