Bug 873553 - Part 10: Allow creating OfflineAudioContexts with arbitrary sampling rates; r=roc
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 24 May 2013 13:11:32 -0400
changeset 132930 976545bf713e1438833a544efe4b91f308d8e5f2
parent 132929 0d624598cc17f7399d4151eb13be17a6354a7705
child 132931 670d867ff3bafba4b049ca633417d6ad5177acaa
push id24727
push userphilringnalda@gmail.com
push dateSun, 26 May 2013 04:02:45 +0000
treeherdermozilla-central@0fed3377c839 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs873553
milestone24.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 873553 - Part 10: Allow creating OfflineAudioContexts with arbitrary sampling rates; r=roc
content/media/webaudio/AudioContext.cpp
content/media/webaudio/test/test_OfflineAudioContext.html
--- a/content/media/webaudio/AudioContext.cpp
+++ b/content/media/webaudio/AudioContext.cpp
@@ -103,18 +103,18 @@ AudioContext::Constructor(const GlobalOb
                           ErrorResult& aRv)
 {
   nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.Get());
   if (!window) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
-  if (aSampleRate != IdealAudioRate()) {
-    // TODO: Add support for running OfflineAudioContext at other sampling rates
+  if (aSampleRate <= 0.0f) {
+    // The DOM binding protects us against infinity and NaN
     aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
     return nullptr;
   }
 
   nsRefPtr<AudioContext> object = new AudioContext(window,
                                                    true,
                                                    aNumberOfChannels,
                                                    aLength,
--- a/content/media/webaudio/test/test_OfflineAudioContext.html
+++ b/content/media/webaudio/test/test_OfflineAudioContext.html
@@ -8,26 +8,33 @@
 </head>
 <body>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 SimpleTest.waitForExplicitFinish();
 addLoadEvent(function() {
   SpecialPowers.setBoolPref("media.webaudio.enabled", true);
-  var ctx = new OfflineAudioContext(2, 100, (new AudioContext()).sampleRate);
+  var ctx = new OfflineAudioContext(2, 100, 22050);
   ok(ctx instanceof EventTarget, "OfflineAudioContexts must be EventTargets");
 
   var buf = ctx.createBuffer(2, 100, ctx.sampleRate);
   for (var i = 0; i < 2; ++i) {
     for (var j = 0; j < 100; ++j) {
       buf.getChannelData(i)[j] = Math.sin(2 * Math.PI * 200 * j / ctx.sampleRate);
     }
   }
 
+  expectException(function() {
+    new OfflineAudioContext(2, 100, 0);
+  }, DOMException.SYNTAX_ERR);
+  expectException(function() {
+    new OfflineAudioContext(2, 100, -1);
+  }, DOMException.SYNTAX_ERR);
+
   var src = ctx.createBufferSource();
   src.buffer = buf;
   src.start(0);
   src.connect(ctx.destination);
   ctx.startRendering();
   ctx.addEventListener("complete", function(e) {
     ok(e instanceof OfflineAudioCompletionEvent, "Correct event received");
     is(e.renderedBuffer.numberOfChannels, 2, "Correct expected number of buffers");