Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / platform / audio / FFTFrame.cpp
index 30e2da0..56fd269 100644 (file)
 
 #include "platform/audio/FFTFrame.h"
 
-#ifndef NDEBUG
-#include <stdio.h>
-#endif
-
+#include "platform/audio/VectorMath.h"
 #include "platform/Logging.h"
 #include "wtf/Complex.h"
 #include "wtf/MathExtras.h"
 #include "wtf/OwnPtr.h"
 
-namespace WebCore {
+#ifndef NDEBUG
+#include <stdio.h>
+#endif
+
+namespace blink {
 
 void FFTFrame::doPaddedFFT(const float* data, size_t dataSize)
 {
@@ -140,21 +141,21 @@ void FFTFrame::interpolateFrequencyComponents(const FFTFrame& frame1, const FFTF
 
         // Unwrap phase deltas
         if (deltaPhase1 > piDouble)
-            deltaPhase1 -= 2.0 * piDouble;
+            deltaPhase1 -= twoPiDouble;
         if (deltaPhase1 < -piDouble)
-            deltaPhase1 += 2.0 * piDouble;
+            deltaPhase1 += twoPiDouble;
         if (deltaPhase2 > piDouble)
-            deltaPhase2 -= 2.0 * piDouble;
+            deltaPhase2 -= twoPiDouble;
         if (deltaPhase2 < -piDouble)
-            deltaPhase2 += 2.0 * piDouble;
+            deltaPhase2 += twoPiDouble;
 
         // Blend group-delays
         double deltaPhaseBlend;
 
         if (deltaPhase1 - deltaPhase2 > piDouble)
-            deltaPhaseBlend = s1 * deltaPhase1 + s2 * (2.0 * piDouble + deltaPhase2);
+            deltaPhaseBlend = s1 * deltaPhase1 + s2 * (twoPiDouble + deltaPhase2);
         else if (deltaPhase2 - deltaPhase1 > piDouble)
-            deltaPhaseBlend = s1 * (2.0 * piDouble + deltaPhase1) + s2 * deltaPhase2;
+            deltaPhaseBlend = s1 * (twoPiDouble + deltaPhase1) + s2 * deltaPhase2;
         else
             deltaPhaseBlend = s1 * deltaPhase1 + s2 * deltaPhase2;
 
@@ -162,9 +163,9 @@ void FFTFrame::interpolateFrequencyComponents(const FFTFrame& frame1, const FFTF
 
         // Unwrap
         if (phaseAccum > piDouble)
-            phaseAccum -= 2.0 * piDouble;
+            phaseAccum -= twoPiDouble;
         if (phaseAccum < -piDouble)
-            phaseAccum += 2.0 * piDouble;
+            phaseAccum += twoPiDouble;
 
         Complex c = complexFromMagnitudePhase(mag, phaseAccum);
 
@@ -184,7 +185,7 @@ double FFTFrame::extractAverageGroupDelay()
 
     int halfSize = fftSize() / 2;
 
-    const double kSamplePhaseDelay = (2.0 * piDouble) / double(fftSize());
+    const double kSamplePhaseDelay = (twoPiDouble) / double(fftSize());
 
     // Calculate weighted average group delay
     for (int i = 0; i < halfSize; i++) {
@@ -197,9 +198,9 @@ double FFTFrame::extractAverageGroupDelay()
 
         // Unwrap
         if (deltaPhase < -piDouble)
-            deltaPhase += 2.0 * piDouble;
+            deltaPhase += twoPiDouble;
         if (deltaPhase > piDouble)
-            deltaPhase -= 2.0 * piDouble;
+            deltaPhase -= twoPiDouble;
 
         aveSum += mag * deltaPhase;
         weightSum += mag;
@@ -229,7 +230,7 @@ void FFTFrame::addConstantGroupDelay(double sampleFrameDelay)
     float* realP = realData();
     float* imagP = imagData();
 
-    const double kSamplePhaseDelay = (2.0 * piDouble) / double(fftSize());
+    const double kSamplePhaseDelay = (twoPiDouble) / double(fftSize());
 
     double phaseAdj = -sampleFrameDelay * kSamplePhaseDelay;
 
@@ -248,14 +249,35 @@ void FFTFrame::addConstantGroupDelay(double sampleFrameDelay)
     }
 }
 
+void FFTFrame::multiply(const FFTFrame& frame)
+{
+    FFTFrame& frame1 = *this;
+    FFTFrame& frame2 = const_cast<FFTFrame&>(frame);
+
+    float* realP1 = frame1.realData();
+    float* imagP1 = frame1.imagData();
+    const float* realP2 = frame2.realData();
+    const float* imagP2 = frame2.imagData();
+
+    unsigned halfSize = fftSize() / 2;
+    float real0 = realP1[0];
+    float imag0 = imagP1[0];
+
+    VectorMath::zvmul(realP1, imagP1, realP2, imagP2, realP1, imagP1, halfSize);
+
+    // Multiply the packed DC/nyquist component
+    realP1[0] = real0 * realP2[0];
+    imagP1[0] = imag0 * imagP2[0];
+}
+
 #ifndef NDEBUG
 void FFTFrame::print()
 {
     FFTFrame& frame = *this;
     float* realP = frame.realData();
     float* imagP = frame.imagData();
-    LOG(WebAudio, "**** \n");
-    LOG(WebAudio, "DC = %f : nyquist = %f\n", realP[0], imagP[0]);
+    WTF_LOG(WebAudio, "**** \n");
+    WTF_LOG(WebAudio, "DC = %f : nyquist = %f\n", realP[0], imagP[0]);
 
     int n = m_FFTSize / 2;
 
@@ -263,12 +285,12 @@ void FFTFrame::print()
         double mag = sqrt(realP[i] * realP[i] + imagP[i] * imagP[i]);
         double phase = atan2(realP[i], imagP[i]);
 
-        LOG(WebAudio, "[%d] (%f %f)\n", i, mag, phase);
+        WTF_LOG(WebAudio, "[%d] (%f %f)\n", i, mag, phase);
     }
-    LOG(WebAudio, "****\n");
+    WTF_LOG(WebAudio, "****\n");
 }
 #endif // NDEBUG
 
-} // namespace WebCore
+} // namespace blink
 
 #endif // ENABLE(WEB_AUDIO)