bug 1339889 add logging of maximum noise r?padenot draft
authorKarl Tomlinson <karlt+@karlt.net>
Sat, 02 Dec 2017 21:58:40 +1300
changeset 706693 c1bf00685661d557bae4227945b04fa96c6c89b0
parent 706692 709f355a7a8c4ae426d1824841a71ffdb5ce0137
child 706694 5eabc652eb4a665c6522c11427a9e7bc022aa4cd
push id91882
push userktomlinson@mozilla.com
push dateSun, 03 Dec 2017 22:52:12 +0000
reviewerspadenot
bugs1339889
milestone59.0a1
bug 1339889 add logging of maximum noise r?padenot MozReview-Commit-ID: 4kPl6Jt8rXS
dom/media/webaudio/test/test_mediaElementAudioSourceNodeFidelity.html
--- a/dom/media/webaudio/test/test_mediaElementAudioSourceNodeFidelity.html
+++ b/dom/media/webaudio/test/test_mediaElementAudioSourceNodeFidelity.html
@@ -41,33 +41,38 @@ function debugCanvas(analyser) {
 }
 
 
 function checkFrequency(an) {
   an.getFloatFrequencyData(frequencyArray);
   // We should have no energy when checking the data largely outside the index
   // for 440Hz (the frequency of the sine wave), start checking an octave above,
   // the Opus compression can add some harmonics to the pure since wave.
-  var index = binIndexForFrequency(880, an);
-  var underTreshold = true;
-  for (var i = index; i < frequencyArray.length; i++) {
-    // Let some slack, there might be some noise here because of int -> float
-    // conversion or the Opus encoding.
-    if (frequencyArray[i] > an.minDecibels + 40) {
-      return false;
+  var maxNoiseIndex = binIndexForFrequency(880, an);
+  for (var i = maxNoiseIndex + 1; i < frequencyArray.length; i++) {
+    if (frequencyArray[i] > frequencyArray[maxNoiseIndex]) {
+       maxNoiseIndex = i;
     }
   }
 
   // On the other hand, we should find a peak at 440Hz. Our sine wave is not
   // attenuated, we're expecting the peak to reach 0dBFs.
-  index = binIndexForFrequency(440, an);
-  info("energy at 440: " + frequencyArray[index] + ", threshold " + (an.maxDecibels - 10));
+  var index = binIndexForFrequency(440, an);
+  info("energy at 440: " + frequencyArray[index] +
+       ", threshold " + (an.maxDecibels - 10) +
+       "; max noise at index " + maxNoiseIndex +
+       ": " + frequencyArray[maxNoiseIndex] );
   if (frequencyArray[index] < (an.maxDecibels - 10)) {
     return false;
   }
+  // Let some slack, there might be some noise here because of int -> float
+  // conversion or the Opus encoding.
+  if (frequencyArray[maxNoiseIndex] > an.minDecibels + 40) {
+    return false;
+  }
 
   return true;
 }
 
 var audioElement = new Audio();
 audioElement.src = 'sine-440-10s.opus'
 audioElement.loop = true;
 var ac = new AudioContext();