Bug 1267579 - Unexpected result when using OscillatorNode with custom wave shape; r=padenot a=ritu
authorDan Minor <dminor@mozilla.com>
Tue, 26 Apr 2016 09:41:54 -0400
changeset 332647 f60b4b71a31963ecc8cec0968358e78a4c0d3694
parent 332646 7110c2140d6d8875d0d9f3cffc8cf0f6c9dc21bc
child 332648 db6cfb052942ec4ff204abb64914cea9fe8a7d39
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot, ritu
bugs1267579, 1222405
milestone48.0a2
Bug 1267579 - Unexpected result when using OscillatorNode with custom wave shape; r=padenot a=ritu This fixes some division by zero errors introduced by Bug 1222405 when the fundamental frequency is zero. MozReview-Commit-ID: A7qfJjJOJ3H
dom/media/webaudio/blink/PeriodicWave.cpp
--- a/dom/media/webaudio/blink/PeriodicWave.cpp
+++ b/dom/media/webaudio/blink/PeriodicWave.cpp
@@ -148,17 +148,19 @@ void PeriodicWave::waveDataForFundamenta
     // to the positive frequency.
     fundamentalFrequency = fabsf(fundamentalFrequency);
 
     // We only need to rebuild to the tables if the new fundamental
     // frequency is low enough to allow for more partials below the
     // Nyquist frequency.
     unsigned numberOfPartials = numberOfPartialsForRange(0);
     float nyquist = 0.5 * m_sampleRate;
-    numberOfPartials = std::min(numberOfPartials, (unsigned)(nyquist / fundamentalFrequency));
+    if (fundamentalFrequency != 0.0) {
+        numberOfPartials = std::min(numberOfPartials, (unsigned)(nyquist / fundamentalFrequency));
+    }
     if (numberOfPartials > m_maxPartialsInBandLimitedTable) {
         for (unsigned rangeIndex = 0; rangeIndex < m_numberOfRanges; ++rangeIndex) {
             m_bandLimitedTables[rangeIndex] = 0;
         }
 
         // We need to create the first table to determine the normalization
         // constant.
         createBandLimitedTables(fundamentalFrequency, 0);
@@ -235,18 +237,20 @@ void PeriodicWave::createBandLimitedTabl
     // partials for this pitch range.  We need to clear out the highest
     // frequencies to band-limit the waveform.
     unsigned numberOfPartials = numberOfPartialsForRange(rangeIndex);
     // Also limit to the number of components that are provided.
     numberOfPartials = std::min(numberOfPartials, m_numberOfComponents - 1);
 
     // Limit number of partials to those below Nyquist frequency
     float nyquist = 0.5 * m_sampleRate;
-    numberOfPartials = std::min(numberOfPartials,
-                                (unsigned)(nyquist / fundamentalFrequency));
+    if (fundamentalFrequency != 0.0) {
+        numberOfPartials = std::min(numberOfPartials,
+                                    (unsigned)(nyquist / fundamentalFrequency));
+    }
 
     // Copy from loaded frequency data and generate complex conjugate
     // because of the way the inverse FFT is defined.
     // The coefficients of higher partials remain zero, as initialized in
     // the FFTBlock constructor.
     for (i = 0; i < numberOfPartials + 1; ++i) {
         frame.RealData(i) = realData[i];
         frame.ImagData(i) = -imagData[i];