Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / platform / audio / FFTFrame.h
blob177b5444e70dd4ad44e1a78aa0e0ccde162093ed
1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #ifndef FFTFrame_h
30 #define FFTFrame_h
32 #include "platform/PlatformExport.h"
33 #include "platform/audio/AudioArray.h"
34 #include "wtf/Forward.h"
35 #include "wtf/PassOwnPtr.h"
36 #include "wtf/Threading.h"
38 #if OS(MACOSX)
39 #include <Accelerate/Accelerate.h>
40 #elif USE(WEBAUDIO_OPENMAX_DL_FFT)
41 #include <dl/sp/api/omxSP.h>
42 #elif USE(WEBAUDIO_FFMPEG)
43 struct RDFTContext;
44 #elif USE(WEBAUDIO_IPP)
45 #include <ipps.h>
46 #endif
48 namespace blink {
50 // Defines the interface for an "FFT frame", an object which is able to perform a forward
51 // and reverse FFT, internally storing the resultant frequency-domain data.
53 class PLATFORM_EXPORT FFTFrame {
54 public:
55 // The constructors, destructor, and methods up to the CROSS-PLATFORM section have platform-dependent implementations.
57 FFTFrame(unsigned fftSize);
58 FFTFrame(); // creates a blank/empty frame for later use with createInterpolatedFrame()
59 FFTFrame(const FFTFrame& frame);
60 ~FFTFrame();
62 static void initialize();
63 static void cleanup();
64 void doFFT(const float* data);
65 void doInverseFFT(float* data);
67 float* realData() const { return const_cast<float*>(m_realData.data()); }
68 float* imagData() const { return const_cast<float*>(m_imagData.data()); }
70 unsigned fftSize() const { return m_FFTSize; }
71 unsigned log2FFTSize() const { return m_log2FFTSize; }
73 // CROSS-PLATFORM
74 // The remaining public methods have cross-platform implementations:
76 // Interpolates from frame1 -> frame2 as x goes from 0.0 -> 1.0
77 static PassOwnPtr<FFTFrame> createInterpolatedFrame(const FFTFrame& frame1, const FFTFrame& frame2, double x);
78 void doPaddedFFT(const float* data, size_t dataSize); // zero-padding with dataSize <= fftSize
79 double extractAverageGroupDelay();
80 void addConstantGroupDelay(double sampleFrameDelay);
81 void multiply(const FFTFrame&); // multiplies ourself with frame : effectively operator*=()
83 private:
84 void interpolateFrequencyComponents(const FFTFrame& frame1, const FFTFrame& frame2, double x);
86 unsigned m_FFTSize;
87 unsigned m_log2FFTSize;
88 AudioFloatArray m_realData;
89 AudioFloatArray m_imagData;
91 #if OS(MACOSX)
92 DSPSplitComplex& dspSplitComplex() { return m_frame; }
93 DSPSplitComplex dspSplitComplex() const { return m_frame; }
94 static FFTSetup fftSetupForSize(unsigned fftSize);
95 static FFTSetup* fftSetups;
96 FFTSetup m_FFTSetup;
97 DSPSplitComplex m_frame;
98 #elif USE(WEBAUDIO_FFMPEG)
99 static RDFTContext* contextForSize(unsigned fftSize, int trans);
100 RDFTContext* m_forwardContext;
101 RDFTContext* m_inverseContext;
102 float* getUpToDateComplexData();
103 AudioFloatArray m_complexData;
104 #elif USE(WEBAUDIO_IPP)
105 Ipp8u* m_buffer;
106 IppsDFTSpec_R_32f* m_DFTSpec;
107 float* getUpToDateComplexData();
108 AudioFloatArray m_complexData;
109 #elif USE(WEBAUDIO_OPENMAX_DL_FFT)
110 static OMXFFTSpec_R_F32* contextForSize(unsigned log2FFTSize);
111 OMXFFTSpec_R_F32* m_forwardContext;
112 OMXFFTSpec_R_F32* m_inverseContext;
113 AudioFloatArray m_complexData;
114 #endif
117 } // namespace blink
119 #endif // FFTFrame_h