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
--- 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];