Bug 1459259 [wpt PR 10851] - Move Analyser tests to WPT, a=testonly
authorRaymond Toy <rtoy@chromium.org>
Tue, 15 May 2018 13:36:58 +0000
changeset 418586 7eb1c0f8b5714878acb0dcb507f4ee3c1dc0514e
parent 418585 7bb553acbd3d857eccd0f15d0f0fd6191d0b49df
child 418587 ec6270ca64e1a8df3175a806ccb745900933e894
push id34007
push usercsabou@mozilla.com
push dateThu, 17 May 2018 09:47:02 +0000
treeherdermozilla-central@8fb36531f7d0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1459259, 10851, 745778, 1042853, 556958
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1459259 [wpt PR 10851] - Move Analyser tests to WPT, a=testonly Automatic update from web-platform-testsMove Analyser tests to WPT Firefox passes these tests. The remaining tests that weren't moved all use oac.suspend which Firefox doesn't have (incorrectly), so they weren't moved. Bug: 745778 Change-Id: Ic8e758896cfdd2abfccf29b6444c20f13c0be3f2 Reviewed-on: https://chromium-review.googlesource.com/1042853 Reviewed-by: Hongchan Choi <hongchan@chromium.org> Commit-Queue: Raymond Toy <rtoy@chromium.org> Cr-Commit-Position: refs/heads/master@{#556958} -- wpt-commits: b0edea178f845aefc880cd85b3c74c16ea7e835c wpt-pr: 10851
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/webaudio/the-audio-api/the-analysernode-interface/realtimeanalyser-basic.html
testing/web-platform/tests/webaudio/the-audio-api/the-analysernode-interface/realtimeanalyser-fft-scaling.html
testing/web-platform/tests/webaudio/the-audio-api/the-analysernode-interface/realtimeanalyser-fft-sizing.html
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -370977,16 +370977,34 @@
     ]
    ],
    "webaudio/the-audio-api/the-analysernode-interface/ctor-analyser.html": [
     [
      "/webaudio/the-audio-api/the-analysernode-interface/ctor-analyser.html",
      {}
     ]
    ],
+   "webaudio/the-audio-api/the-analysernode-interface/realtimeanalyser-basic.html": [
+    [
+     "/webaudio/the-audio-api/the-analysernode-interface/realtimeanalyser-basic.html",
+     {}
+    ]
+   ],
+   "webaudio/the-audio-api/the-analysernode-interface/realtimeanalyser-fft-scaling.html": [
+    [
+     "/webaudio/the-audio-api/the-analysernode-interface/realtimeanalyser-fft-scaling.html",
+     {}
+    ]
+   ],
+   "webaudio/the-audio-api/the-analysernode-interface/realtimeanalyser-fft-sizing.html": [
+    [
+     "/webaudio/the-audio-api/the-analysernode-interface/realtimeanalyser-fft-sizing.html",
+     {}
+    ]
+   ],
    "webaudio/the-audio-api/the-analysernode-interface/test-analyser-gain.html": [
     [
      "/webaudio/the-audio-api/the-analysernode-interface/test-analyser-gain.html",
      {}
     ]
    ],
    "webaudio/the-audio-api/the-analysernode-interface/test-analyser-minimum.html": [
     [
@@ -611970,16 +611988,28 @@
   "webaudio/the-audio-api/the-analysernode-interface/.gitkeep": [
    "da39a3ee5e6b4b0d3255bfef95601890afd80709",
    "support"
   ],
   "webaudio/the-audio-api/the-analysernode-interface/ctor-analyser.html": [
    "7e35ac29f00d39c84230535212c0b9ea081951d3",
    "testharness"
   ],
+  "webaudio/the-audio-api/the-analysernode-interface/realtimeanalyser-basic.html": [
+   "a4058a967414b087e19ad8dd2af0999152f1491c",
+   "testharness"
+  ],
+  "webaudio/the-audio-api/the-analysernode-interface/realtimeanalyser-fft-scaling.html": [
+   "f4a4122ebd500cba1d5fb383369849e31f73d7f7",
+   "testharness"
+  ],
+  "webaudio/the-audio-api/the-analysernode-interface/realtimeanalyser-fft-sizing.html": [
+   "9389a7e0b4c115a756e547225140150136d1103d",
+   "testharness"
+  ],
   "webaudio/the-audio-api/the-analysernode-interface/test-analyser-gain.html": [
    "e2320e33ef1df0155d5fcf536550e0e398b15407",
    "testharness"
   ],
   "webaudio/the-audio-api/the-analysernode-interface/test-analyser-minimum.html": [
    "26282412113f6298a90a2cac963a2b0de03ef43d",
    "testharness"
   ],
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webaudio/the-audio-api/the-analysernode-interface/realtimeanalyser-basic.html
@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>
+      realtimeanalyser-basic.html
+    </title>
+    <script src="/resources/testharness.js"></script>
+    <script src="/resources/testharnessreport.js"></script>
+    <script src="/webaudio/resources/audit-util.js"></script>
+    <script src="/webaudio/resources/audit.js"></script>
+  </head>
+  <body>
+    <script id="layout-test-code">
+      let context = 0;
+
+      let audit = Audit.createTaskRunner();
+
+      audit.define('Basic AnalyserNode test', function(task, should) {
+        context = new AudioContext();
+        let analyser = context.createAnalyser();
+
+        should(analyser.numberOfInputs, 'Number of inputs for AnalyserNode')
+            .beEqualTo(1);
+
+        should(analyser.numberOfOutputs, 'Number of outputs for AnalyserNode')
+            .beEqualTo(1);
+
+        should(analyser.minDecibels, 'Default minDecibels value')
+            .beEqualTo(-100);
+
+        should(analyser.maxDecibels, 'Default maxDecibels value')
+            .beEqualTo(-30);
+
+        should(
+            analyser.smoothingTimeConstant,
+            'Default smoothingTimeConstant value')
+            .beEqualTo(0.8);
+
+        let expectedValue = -50 - (1 / 3);
+        analyser.minDecibels = expectedValue;
+
+        should(analyser.minDecibels, 'node.minDecibels = ' + expectedValue)
+            .beEqualTo(expectedValue);
+
+        expectedValue = -40 - (1 / 3);
+        analyser.maxDecibels = expectedValue;
+
+        should(analyser.maxDecibels, 'node.maxDecibels = ' + expectedValue)
+            .beEqualTo(expectedValue);
+
+        task.done();
+      });
+
+      audit.run();
+    </script>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webaudio/the-audio-api/the-analysernode-interface/realtimeanalyser-fft-scaling.html
@@ -0,0 +1,113 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>
+      realtimeanalyser-fft-scaling.html
+    </title>
+    <script src="/resources/testharness.js"></script>
+    <script src="/resources/testharnessreport.js"></script>
+    <script src="/webaudio/resources/audit-util.js"></script>
+    <script src="/webaudio/resources/audit.js"></script>
+  </head>
+  <body>
+    <div id="description"></div>
+    <div id="console"></div>
+    <script id="layout-test-code">
+      let audit = Audit.createTaskRunner();
+
+      // The number of analysers. We have analysers from size for each of the
+      // possible sizes of 2^5 to 2^15 for a total of 11.
+      let numberOfAnalysers = 11;
+      let sampleRate = 44100;
+      let nyquistFrequency = sampleRate / 2;
+
+      // Frequency of the sine wave test signal.  Should be high enough so that
+      // we get at least one full cycle for the 32-point FFT.  This should also
+      // be such that the frequency should be exactly in one of the FFT bins for
+      // each of the possible FFT sizes.
+      let oscFrequency = nyquistFrequency / 16;
+
+      // The actual peak values from each analyser.  Useful for examining the
+      // actual peak values.
+      let peakValue = new Array(numberOfAnalysers);
+
+      // For a 0dBFS sine wave, we would expect the FFT magnitude to be 0dB as
+      // well, but the analyzer node applies a Blackman window (to smooth the
+      // estimate).  This reduces the energy of the signal so the FFT peak is
+      // less than 0dB.  The threshold value given here was determined
+      // experimentally.
+      //
+      // See https://code.google.com/p/chromium/issues/detail?id=341596.
+      let peakThreshold = [
+        -14.43, -13.56, -13.56, -13.56, -13.56, -13.56, -13.56, -13.56, -13.56,
+        -13.56, -13.56
+      ];
+
+      function checkResult(order, analyser, should) {
+        return function() {
+          let index = order - 5;
+          let fftSize = 1 << order;
+          let fftData = new Float32Array(fftSize);
+          analyser.getFloatFrequencyData(fftData);
+
+          // Compute the frequency bin that should contain the peak.
+          let expectedBin =
+              analyser.frequencyBinCount * (oscFrequency / nyquistFrequency);
+
+          // Find the actual bin by finding the bin containing the peak.
+          let actualBin = 0;
+          peakValue[index] = -1000;
+          for (k = 0; k < analyser.frequencyBinCount; ++k) {
+            if (fftData[k] > peakValue[index]) {
+              actualBin = k;
+              peakValue[index] = fftData[k];
+            }
+          }
+
+          should(actualBin, (1 << order) + '-point FFT peak position')
+              .beEqualTo(expectedBin);
+
+          should(
+              peakValue[index], (1 << order) + '-point FFT peak value in dBFS')
+              .beGreaterThanOrEqualTo(peakThreshold[index]);
+        }
+      }
+
+      audit.define(
+          {
+            label: 'FFT scaling tests',
+            description: 'Test Scaling of FFT in AnalyserNode'
+          },
+          function(task, should) {
+            let tests = [];
+            for (let k = 5; k <= 15; ++k)
+              tests.push(runTest(k, should));
+
+            // The order in which the tests finish is not important.
+            Promise.all(tests).then(task.done.bind(task));
+          });
+
+      function runTest(order, should) {
+        let context = new OfflineAudioContext(1, 1 << order, sampleRate);
+        // Use a sine wave oscillator as the reference source signal.
+        let osc = context.createOscillator();
+        osc.type = 'sine';
+        osc.frequency.value = oscFrequency;
+        osc.connect(context.destination);
+
+        let analyser = context.createAnalyser();
+        // No smoothing to simplify the analysis of the result.
+        analyser.smoothingTimeConstant = 0;
+        analyser.fftSize = 1 << order;
+        osc.connect(analyser);
+
+        osc.start();
+        return context.startRendering().then(() => {
+          checkResult(order, analyser, should)();
+        });
+      }
+
+      audit.run();
+    </script>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webaudio/the-audio-api/the-analysernode-interface/realtimeanalyser-fft-sizing.html
@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>
+      realtimeanalyser-fft-sizing.html
+    </title>
+    <script src="/resources/testharness.js"></script>
+    <script src="/resources/testharnessreport.js"></script>
+    <script src="/webaudio/resources/audit-util.js"></script>
+    <script src="/webaudio/resources/audit.js"></script>
+  </head>
+  <body>
+    <script id="layout-test-code">
+      let audit = Audit.createTaskRunner();
+
+      function doTest(fftSize, illegal, should) {
+        let c = new OfflineAudioContext(1, 1000, 44100);
+        let a = c.createAnalyser();
+        let message = 'Setting fftSize to ' + fftSize;
+        let tester = function() {
+          a.fftSize = fftSize;
+        };
+
+        if (illegal) {
+          should(tester, message).throw('IndexSizeError');
+        } else {
+          should(tester, message).notThrow();
+        }
+      }
+
+      audit.define(
+          {
+            label: 'FFT size test',
+            description: 'Test that re-sizing the FFT arrays does not fail.'
+          },
+          function(task, should) {
+            doTest(-1, true, should);
+            doTest(0, true, should);
+            doTest(1, true, should);
+            for (let i = 2; i <= 0x20000; i *= 2) {
+              if (i >= 32 && i <= 32768)
+                doTest(i, false, should);
+              else
+                doTest(i, true, should);
+              doTest(i + 1, true, should);
+            }
+
+            task.done();
+          });
+
+      audit.run();
+    </script>
+  </body>
+</html>