content/media/webaudio/test/test_audioParamSetCurveAtTime.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

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 AudioParam.linearRampToValue</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 T0 = 0;
    15 var gTest = {
    16   length: 2048,
    17   numberOfChannels: 1,
    18   createGraph: function(context) {
    19     var sourceBuffer = context.createBuffer(1, 2048, context.sampleRate);
    20     for (var i = 0; i < 2048; ++i) {
    21       sourceBuffer.getChannelData(0)[i] = 1;
    22     }
    24     var source = context.createBufferSource();
    25     source.buffer = sourceBuffer;
    27     var gain = context.createGain();
    28     gain.gain.setValueCurveAtTime(this.curve, T0, this.duration);
    30     source.connect(gain);
    32     source.start(0);
    33     return gain;
    34   },
    35   createExpectedBuffers: function(context) {
    36     this.duration = 1024 / context.sampleRate;
    37     this.curve = new Float32Array(100);
    38     for (var i = 0; i < 100; ++i) {
    39       this.curve[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate);
    40     }
    41     var expectedBuffer = context.createBuffer(1, 2048, context.sampleRate);
    42     for (var i = 0; i < 2048; ++i) {
    43       var t = i / context.sampleRate;
    44       expectedBuffer.getChannelData(0)[i] = this.curve[Math.min(99, Math.floor(100 * Math.min(1.0, (t - T0) / this.duration)))];
    45     }
    46     return expectedBuffer;
    47   },
    48 };
    50 runTest();
    52 </script>
    53 </pre>
    54 </body>
    55 </html>

mercurial