This source file includes following definitions.
- m_imagData
- m_imagData
- m_imagData
- doFFT
- doInverseFFT
- fftSetupForSize
- initialize
- cleanup
- realData
- imagData
#include "config.h"
#if ENABLE(WEB_AUDIO)
#if OS(MACOSX)
#include "platform/audio/FFTFrame.h"
#include "platform/audio/VectorMath.h"
namespace WebCore {
const int kMaxFFTPow2Size = 24;
FFTSetup* FFTFrame::fftSetups = 0;
FFTFrame::FFTFrame(unsigned fftSize)
: m_realData(fftSize)
, m_imagData(fftSize)
{
m_FFTSize = fftSize;
m_log2FFTSize = static_cast<unsigned>(log2(fftSize));
ASSERT(1UL << m_log2FFTSize == m_FFTSize);
m_FFTSetup = fftSetupForSize(fftSize);
m_frame.realp = m_realData.data();
m_frame.imagp = m_imagData.data();
}
FFTFrame::FFTFrame()
: m_realData(0)
, m_imagData(0)
{
m_frame.realp = 0;
m_frame.imagp = 0;
m_FFTSize = 0;
m_log2FFTSize = 0;
}
FFTFrame::FFTFrame(const FFTFrame& frame)
: m_FFTSize(frame.m_FFTSize)
, m_log2FFTSize(frame.m_log2FFTSize)
, m_FFTSetup(frame.m_FFTSetup)
, m_realData(frame.m_FFTSize)
, m_imagData(frame.m_FFTSize)
{
m_frame.realp = m_realData.data();
m_frame.imagp = m_imagData.data();
unsigned nbytes = sizeof(float) * m_FFTSize;
memcpy(realData(), frame.m_frame.realp, nbytes);
memcpy(imagData(), frame.m_frame.imagp, nbytes);
}
FFTFrame::~FFTFrame()
{
}
void FFTFrame::doFFT(const float* data)
{
AudioFloatArray scaledData(m_FFTSize);
float scale = 0.5f;
VectorMath::vsmul(data, 1, &scale, scaledData.data(), 1, m_FFTSize);
vDSP_ctoz((DSPComplex*)scaledData.data(), 2, &m_frame, 1, m_FFTSize / 2);
vDSP_fft_zrip(m_FFTSetup, &m_frame, 1, m_log2FFTSize, FFT_FORWARD);
}
void FFTFrame::doInverseFFT(float* data)
{
vDSP_fft_zrip(m_FFTSetup, &m_frame, 1, m_log2FFTSize, FFT_INVERSE);
vDSP_ztoc(&m_frame, 1, (DSPComplex*)data, 2, m_FFTSize / 2);
float scale = 1.0f / m_FFTSize;
vDSP_vsmul(data, 1, &scale, data, 1, m_FFTSize);
}
FFTSetup FFTFrame::fftSetupForSize(unsigned fftSize)
{
if (!fftSetups) {
fftSetups = (FFTSetup*)malloc(sizeof(FFTSetup) * kMaxFFTPow2Size);
memset(fftSetups, 0, sizeof(FFTSetup) * kMaxFFTPow2Size);
}
int pow2size = static_cast<int>(log2(fftSize));
ASSERT(pow2size < kMaxFFTPow2Size);
if (!fftSetups[pow2size])
fftSetups[pow2size] = vDSP_create_fftsetup(pow2size, FFT_RADIX2);
return fftSetups[pow2size];
}
void FFTFrame::initialize()
{
}
void FFTFrame::cleanup()
{
if (!fftSetups)
return;
for (int i = 0; i < kMaxFFTPow2Size; ++i) {
if (fftSetups[i])
vDSP_destroy_fftsetup(fftSetups[i]);
}
free(fftSetups);
fftSetups = 0;
}
float* FFTFrame::realData() const
{
return m_frame.realp;
}
float* FFTFrame::imagData() const
{
return m_frame.imagp;
}
}
#endif
#endif