#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)
{
// 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;
// Unwrap
if (phaseAccum > piDouble)
- phaseAccum -= 2.0 * piDouble;
+ phaseAccum -= twoPiDouble;
if (phaseAccum < -piDouble)
- phaseAccum += 2.0 * piDouble;
+ phaseAccum += twoPiDouble;
Complex c = complexFromMagnitudePhase(mag, phaseAccum);
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++) {
// Unwrap
if (deltaPhase < -piDouble)
- deltaPhase += 2.0 * piDouble;
+ deltaPhase += twoPiDouble;
if (deltaPhase > piDouble)
- deltaPhase -= 2.0 * piDouble;
+ deltaPhase -= twoPiDouble;
aveSum += mag * deltaPhase;
weightSum += mag;
float* realP = realData();
float* imagP = imagData();
- const double kSamplePhaseDelay = (2.0 * piDouble) / double(fftSize());
+ const double kSamplePhaseDelay = (twoPiDouble) / double(fftSize());
double phaseAdj = -sampleFrameDelay * kSamplePhaseDelay;
}
}
+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;
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)