b=938450 use an OfflineAudioContext to test decodeAudioData at different sample rates f=padenot
authorKarl Tomlinson <karlt+@karlt.net>
Tue, 03 Dec 2013 12:23:49 +1300
changeset 174190 b962d48690b353fd161021c500b63101a447be05
parent 174189 00c4125744478ce47611bcab9d9c4651fb39b4c8
child 174191 cfb79089bebae95a820431e6c0185a039b5047fd
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs938450
milestone28.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
b=938450 use an OfflineAudioContext to test decodeAudioData at different sample rates f=padenot
content/media/webaudio/test/test_mediaDecoding.html
--- a/content/media/webaudio/test/test_mediaDecoding.html
+++ b/content/media/webaudio/test/test_mediaDecoding.html
@@ -102,18 +102,16 @@ function createWaveFileData(audioBuffer)
     return waveFileData;
 }
 
 </script>
 <script class="testbody" type="text/javascript">
 
 SimpleTest.waitForExplicitFinish();
 
-var cx = new AudioContext();
-
 // fuzzTolerance and fuzzToleranceMobile are used to determine fuzziness
 // thresholds.  They're needed to make sure that we can deal with neglibible
 // differences in the binary buffer caused as a result of resampling the
 // audio.  fuzzToleranceMobile is typically larger on mobile platforms since
 // we do fixed-point resampling as opposed to floating-point resampling on
 // those platforms.
 var files = [
   // An ogg file, 44.1khz, mono
@@ -186,19 +184,19 @@ var files = [
     sampleRate: 48000,
     duration: 0.693,
     fuzzTolerance: 0,
     fuzzToleranceMobile: 0
   },
   //  // A wave file
   //  //{ url: "24bit-44khz.wav", valid: true, expectedUrl: "24bit-44khz-expected.wav" },
   // A non-audio file
-  { url: "invalid.txt", valid: false },
+  { url: "invalid.txt", valid: false, sampleRate: 44100 },
   // A webm file with no audio
-  { url: "noaudio.webm", valid: false },
+  { url: "noaudio.webm", valid: false, sampleRate: 48000 },
   // A video ogg file with audio
   {
     url: "audio.ogv",
     valid: true,
     expectedUrl: "audio-expected.wav",
     numberOfChannels: 2,
     sampleRate: 44100,
     frames: 47680,
@@ -232,27 +230,28 @@ function getFuzzTolerance(test) {
 }
 
 function checkAudioBuffer(buffer, test) {
   is(buffer.numberOfChannels, test.numberOfChannels, "Correct number of channels");
   ok(Math.abs(buffer.duration - test.duration) < 1e-3, "Correct duration");
   if (Math.abs(buffer.duration - test.duration) >= 1e-3) {
     ok(false, "got: " + buffer.duration  + ", expected: " + test.duration);
   }
-  is(buffer.sampleRate, cx.sampleRate, "Correct sample rate");
+  is(buffer.sampleRate, test.sampleRate, "Correct sample rate");
   // Take into account the resampling when checking the size
-  var expectedLength = test.frames * cx.sampleRate / test.sampleRate;
+  var expectedLength = test.frames * buffer.sampleRate / test.sampleRate;
   ok(Math.abs(buffer.length - expectedLength) < 1.0, "Correct length", "got " + buffer.length + ", expected about " + expectedLength);
 
   var wave = createWaveFileData(buffer);
   ok(fuzzyMemcmp(wave, test.expectedWaveData, getFuzzTolerance(test)), "Received expected decoded data");
 }
 
 function runTest(test, response, callback) {
   var expectCallback = false;
+  var cx = new OfflineAudioContext(1, 1, test.sampleRate);
   cx.decodeAudioData(response, function onSuccess(asyncResult) {
     ok(expectCallback, "Success callback should fire asynchronously");
     ok(test.valid, "Did expect success for test " + test.url);
     checkAudioBuffer(asyncResult, test);
 
     syncResult = cx.createBuffer(response, false);
     compareBuffers(syncResult, asyncResult);
     callback();
@@ -288,36 +287,34 @@ function loadNextTest() {
     SimpleTest.finish();
   }
 }
 
 // Run some simple tests first
 function callbackShouldNeverRun() {
   ok(false, "callback should not fire");
 }
-expectTypeError(function() {
-  cx.decodeAudioData(null, callbackShouldNeverRun, callbackShouldNeverRun);
-});
-expectTypeError(function() {
-  cx.decodeAudioData(undefined, callbackShouldNeverRun, callbackShouldNeverRun);
-});
-expectTypeError(function() {
-  cx.decodeAudioData(123, callbackShouldNeverRun, callbackShouldNeverRun);
-});
-expectTypeError(function() {
-  cx.decodeAudioData("buffer", callbackShouldNeverRun, callbackShouldNeverRun);
-});
-expectTypeError(function() {
-  cx.decodeAudioData(new Uint8Array(100), callbackShouldNeverRun, callbackShouldNeverRun);
-});
+(function() {
+  var cx = new AudioContext();
+  expectTypeError(function() {
+    cx.decodeAudioData(null, callbackShouldNeverRun, callbackShouldNeverRun);
+  });
+  expectTypeError(function() {
+    cx.decodeAudioData(undefined, callbackShouldNeverRun, callbackShouldNeverRun);
+  });
+  expectTypeError(function() {
+    cx.decodeAudioData(123, callbackShouldNeverRun, callbackShouldNeverRun);
+  });
+  expectTypeError(function() {
+    cx.decodeAudioData("buffer", callbackShouldNeverRun, callbackShouldNeverRun);
+  });
+  expectTypeError(function() {
+    cx.decodeAudioData(new Uint8Array(100), callbackShouldNeverRun, callbackShouldNeverRun);
+  });
+})();
 
-if (cx.sampleRate >= 44100) {
-  // Now, let's get real!
-  loadNextTest();
-} else {
-  todo(false, "Decoded data tests disabled; context sampleRate " + cx.sampleRate + " not supported");
-  SimpleTest.finish();
-}
+// Now, let's get real!
+loadNextTest();
 
 </script>
 </pre>
 </body>
 </html>