bug 1188704 use existing FFTBlock arrays instead of allocating and copying and scaling r=rillian
authorKarl Tomlinson <karlt+@karlt.net>
Mon, 03 Aug 2015 09:28:32 +1200
changeset 287453 91d2934096a14c1a245fedef63136179b8043433
parent 287452 b70aa71884d90b5fe7fa11270dd762db0fc23372
child 287454 3e16627c896837a3f4f5c7a6927edcb861f148a4
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrillian
bugs1188704
milestone42.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 1188704 use existing FFTBlock arrays instead of allocating and copying and scaling r=rillian It is now no longer necessary to clear zero bins because these are zeroed in the FFTBlock constructor. nsTArray bounds assertions now apply.
dom/media/webaudio/blink/PeriodicWave.cpp
--- a/dom/media/webaudio/blink/PeriodicWave.cpp
+++ b/dom/media/webaudio/blink/PeriodicWave.cpp
@@ -185,52 +185,45 @@ void PeriodicWave::createBandLimitedTabl
     // Nyquist of the fixed length inverse FFT.
     numberOfComponents = std::min(numberOfComponents, halfSize);
 
     m_bandLimitedTables.SetCapacity(m_numberOfRanges);
 
     for (unsigned rangeIndex = 0; rangeIndex < m_numberOfRanges; ++rangeIndex) {
         // This FFTBlock is used to cull partials (represented by frequency bins).
         FFTBlock frame(fftSize);
-        nsAutoArrayPtr<float> realP(new float[halfSize + 1]);
-        nsAutoArrayPtr<float> imagP(new float[halfSize + 1]);
 
         // Find the starting bin where we should start culling the aliasing
         // partials for this pitch range.  We need to clear out the highest
         // frequencies to band-limit the waveform.
         unsigned numberOfPartials = numberOfPartialsForRange(rangeIndex);
-        // Also clear bins where components are not provided.
+        // Also limit to the number of components that are provided.
         numberOfPartials = std::min(numberOfPartials, numberOfComponents - 1);
 
-        // Copy from loaded frequency data and scale.
-        float scale = fftSize;
-        AudioBufferCopyWithScale(realData, scale, realP, numberOfPartials + 1);
-        // Generate complex conjugate because of the way the
-        // inverse FFT is defined.
-        AudioBufferCopyWithScale(imagData, -scale, imagP, numberOfPartials + 1);
-
-        // Clear the remaining bins.
-        for (i = numberOfPartials + 1; i < halfSize + 1; ++i) {
-            realP[i] = 0;
-            imagP[i] = 0;
+        // 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];
         }
 
         // Clear any DC-offset.
-        realP[0] = 0;
-
+        frame.RealData(0) = 0;
         // Clear value which has no effect.
-        imagP[0] = 0;
+        frame.ImagData(0) = 0;
 
         // Create the band-limited table.
         AlignedAudioFloatArray* table = new AlignedAudioFloatArray(m_periodicWaveSize);
         m_bandLimitedTables.AppendElement(table);
 
         // Apply an inverse FFT to generate the time-domain table data.
         float* data = m_bandLimitedTables[rangeIndex]->Elements();
-        frame.PerformInverseFFT(realP, imagP, data);
+        frame.GetInverseWithoutScaling(data);
 
         // For the first range (which has the highest power), calculate
         // its peak value then compute normalization scale.
         if (!rangeIndex) {
             float maxValue;
             maxValue = AudioBufferPeakValue(data, m_periodicWaveSize);
 
             if (maxValue)