Bug 1214545 - Update getFrequencyResponse to have NaN at index with invalid frequencies r=padenot
authorDan Minor <dminor@mozilla.com>
Tue, 20 Oct 2015 23:36:45 -0400
changeset 304146 0df6d6188fee64b4692499eaddb3985e5e4779e1
parent 304145 01c1f46069567aa2477b4fe70b24fbf14c6f3459
child 304147 d43d4d4e26fbb3f9a2217a53bb61cfab1828f6dc
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1214545
milestone44.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 1214545 - Update getFrequencyResponse to have NaN at index with invalid frequencies r=padenot
dom/media/webaudio/BiquadFilterNode.cpp
dom/media/webaudio/test/test_biquadFilterNode.html
--- a/dom/media/webaudio/BiquadFilterNode.cpp
+++ b/dom/media/webaudio/BiquadFilterNode.cpp
@@ -317,17 +317,21 @@ BiquadFilterNode::GetFrequencyResponse(c
   }
 
   nsAutoArrayPtr<float> frequencies(new float[length]);
   float* frequencyHz = aFrequencyHz.Data();
   const double nyquist = Context()->SampleRate() * 0.5;
 
   // Normalize the frequencies
   for (uint32_t i = 0; i < length; ++i) {
-    frequencies[i] = static_cast<float>(frequencyHz[i] / nyquist);
+    if (frequencyHz[i] >= 0 && frequencyHz[i] <= nyquist) {
+        frequencies[i] = static_cast<float>(frequencyHz[i] / nyquist);
+    } else {
+        frequencies[i] = std::numeric_limits<float>::quiet_NaN();
+    }
   }
 
   const double currentTime = Context()->CurrentTime();
 
   double freq = mFrequency->GetValueAtTime(currentTime);
   double q = mQ->GetValueAtTime(currentTime);
   double gain = mGain->GetValueAtTime(currentTime);
   double detune = mDetune->GetValueAtTime(currentTime);
--- a/dom/media/webaudio/test/test_biquadFilterNode.html
+++ b/dom/media/webaudio/test/test_biquadFilterNode.html
@@ -53,16 +53,28 @@ addLoadEvent(function() {
     "peaking",
     "notch",
     "allpass",
   ];
   for (var i = 0; i < types.length; ++i) {
     filter.type = types[i];
   }
 
+  // Make sure getFrequencyResponse handles invalid frequencies properly
+  var frequencies = new Float32Array([-1.0, context.sampleRate*0.5 - 1.0, context.sampleRate]);
+  var magResults = new Float32Array(3);
+  var phaseResults = new Float32Array(3);
+  filter.getFrequencyResponse(frequencies, magResults, phaseResults);
+  ok(isNaN(magResults[0]), "Invalid input frequency should give NaN magnitude response");
+  ok(!isNaN(magResults[1]), "Valid input frequency should not give NaN magnitude response");
+  ok(isNaN(magResults[2]), "Invalid input frequency should give NaN magnitude response");
+  ok(isNaN(phaseResults[0]), "Invalid input frquency should give NaN phase response");
+  ok(!isNaN(phaseResults[1]), "Valid input frquency should not give NaN phase response");
+  ok(isNaN(phaseResults[2]), "Invalid input frquency should give NaN phase response");
+
   source.start(0);
   SimpleTest.executeSoon(function() {
     source.stop(0);
     source.disconnect();
     filter.disconnect();
 
     SimpleTest.finish();
   });