Bug 1267579 - Unexpected result when using OscillatorNode with custom wave shape; r?padenot draft
authorDan Minor <dminor@mozilla.com>
Tue, 26 Apr 2016 09:41:54 -0400
changeset 356467 d2840578e0e784b6fa6180a95e4f6313251c9cb0
parent 355401 fc15477ce628599519cb0055f52cc195d640dc94
child 356468 8a7c983c0d24896b40e878d637f142d4f31145cc
push id16525
push userdminor@mozilla.com
push dateTue, 26 Apr 2016 13:42:26 +0000
reviewerspadenot
bugs1267579, 1222405
milestone48.0a1
Bug 1267579 - Unexpected result when using OscillatorNode with custom wave shape; r?padenot 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];