| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 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 | 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. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #ifndef FFTFrame_h | 29 #ifndef FFTFrame_h |
| 30 #define FFTFrame_h | 30 #define FFTFrame_h |
| 31 | 31 |
| 32 #include "platform/PlatformExport.h" | 32 #include "platform/PlatformExport.h" |
| 33 #include "platform/audio/AudioArray.h" | 33 #include "platform/audio/AudioArray.h" |
| 34 #include "wtf/Forward.h" |
| 35 #include "wtf/PassOwnPtr.h" |
| 36 #include "wtf/Threading.h" |
| 34 | 37 |
| 35 #if OS(MACOSX) | 38 #if OS(MACOSX) |
| 36 #include <Accelerate/Accelerate.h> | 39 #include <Accelerate/Accelerate.h> |
| 37 #elif USE(WEBAUDIO_OPENMAX_DL_FFT) | 40 #elif USE(WEBAUDIO_OPENMAX_DL_FFT) |
| 38 #include <dl/sp/api/omxSP.h> | 41 #include <dl/sp/api/omxSP.h> |
| 39 #elif USE(WEBAUDIO_FFMPEG) | 42 #elif USE(WEBAUDIO_FFMPEG) |
| 40 struct RDFTContext; | 43 struct RDFTContext; |
| 44 #elif USE(WEBAUDIO_IPP) |
| 45 #include <ipps.h> |
| 41 #endif | 46 #endif |
| 42 | 47 |
| 43 #if USE(WEBAUDIO_IPP) | |
| 44 #include <ipps.h> | |
| 45 #endif // USE(WEBAUDIO_IPP) | |
| 46 | |
| 47 #include "wtf/Forward.h" | |
| 48 #include "wtf/PassOwnPtr.h" | |
| 49 #include "wtf/Threading.h" | |
| 50 | |
| 51 namespace blink { | 48 namespace blink { |
| 52 | 49 |
| 53 // Defines the interface for an "FFT frame", an object which is able to perform
a forward | 50 // Defines the interface for an "FFT frame", an object which is able to perform
a forward |
| 54 // and reverse FFT, internally storing the resultant frequency-domain data. | 51 // and reverse FFT, internally storing the resultant frequency-domain data. |
| 55 | 52 |
| 56 class PLATFORM_EXPORT FFTFrame { | 53 class PLATFORM_EXPORT FFTFrame { |
| 57 public: | 54 public: |
| 58 // The constructors, destructor, and methods up to the CROSS-PLATFORM sectio
n have platform-dependent implementations. | 55 // The constructors, destructor, and methods up to the CROSS-PLATFORM sectio
n have platform-dependent implementations. |
| 59 | 56 |
| 60 FFTFrame(unsigned fftSize); | 57 FFTFrame(unsigned fftSize); |
| 61 FFTFrame(); // creates a blank/empty frame for later use with createInterpol
atedFrame() | 58 FFTFrame(); // creates a blank/empty frame for later use with createInterpol
atedFrame() |
| 62 FFTFrame(const FFTFrame& frame); | 59 FFTFrame(const FFTFrame& frame); |
| 63 ~FFTFrame(); | 60 ~FFTFrame(); |
| 64 | 61 |
| 65 static void initialize(); | 62 static void initialize(); |
| 66 static void cleanup(); | 63 static void cleanup(); |
| 67 void doFFT(const float* data); | 64 void doFFT(const float* data); |
| 68 void doInverseFFT(float* data); | 65 void doInverseFFT(float* data); |
| 69 | 66 |
| 70 float* realData() const; | 67 float* realData() const { return const_cast<float*>(m_realData.data()); } |
| 71 float* imagData() const; | 68 float* imagData() const { return const_cast<float*>(m_imagData.data()); } |
| 72 | 69 |
| 73 void print(); // for debugging | 70 unsigned fftSize() const { return m_FFTSize; } |
| 71 unsigned log2FFTSize() const { return m_log2FFTSize; } |
| 74 | 72 |
| 75 // CROSS-PLATFORM | 73 // CROSS-PLATFORM |
| 76 // The remaining public methods have cross-platform implementations: | 74 // The remaining public methods have cross-platform implementations: |
| 77 | 75 |
| 78 // Interpolates from frame1 -> frame2 as x goes from 0.0 -> 1.0 | 76 // Interpolates from frame1 -> frame2 as x goes from 0.0 -> 1.0 |
| 79 static PassOwnPtr<FFTFrame> createInterpolatedFrame(const FFTFrame& frame1,
const FFTFrame& frame2, double x); | 77 static PassOwnPtr<FFTFrame> createInterpolatedFrame(const FFTFrame& frame1,
const FFTFrame& frame2, double x); |
| 80 | |
| 81 void doPaddedFFT(const float* data, size_t dataSize); // zero-padding with d
ataSize <= fftSize | 78 void doPaddedFFT(const float* data, size_t dataSize); // zero-padding with d
ataSize <= fftSize |
| 82 double extractAverageGroupDelay(); | 79 double extractAverageGroupDelay(); |
| 83 void addConstantGroupDelay(double sampleFrameDelay); | 80 void addConstantGroupDelay(double sampleFrameDelay); |
| 84 void multiply(const FFTFrame&); // multiplies ourself with frame : effective
ly operator*=() | 81 void multiply(const FFTFrame&); // multiplies ourself with frame : effective
ly operator*=() |
| 85 | 82 |
| 86 unsigned fftSize() const { return m_FFTSize; } | 83 #ifndef NDEBUG |
| 87 unsigned log2FFTSize() const { return m_log2FFTSize; } | 84 void print(); // for debugging |
| 85 #endif |
| 88 | 86 |
| 89 private: | 87 private: |
| 88 void interpolateFrequencyComponents(const FFTFrame& frame1, const FFTFrame&
frame2, double x); |
| 89 |
| 90 unsigned m_FFTSize; | 90 unsigned m_FFTSize; |
| 91 unsigned m_log2FFTSize; | 91 unsigned m_log2FFTSize; |
| 92 | 92 AudioFloatArray m_realData; |
| 93 void interpolateFrequencyComponents(const FFTFrame& frame1, const FFTFrame&
frame2, double x); | 93 AudioFloatArray m_imagData; |
| 94 | 94 |
| 95 #if OS(MACOSX) | 95 #if OS(MACOSX) |
| 96 DSPSplitComplex& dspSplitComplex() { return m_frame; } | 96 DSPSplitComplex& dspSplitComplex() { return m_frame; } |
| 97 DSPSplitComplex dspSplitComplex() const { return m_frame; } | 97 DSPSplitComplex dspSplitComplex() const { return m_frame; } |
| 98 | |
| 99 static FFTSetup fftSetupForSize(unsigned fftSize); | 98 static FFTSetup fftSetupForSize(unsigned fftSize); |
| 100 | |
| 101 static FFTSetup* fftSetups; | 99 static FFTSetup* fftSetups; |
| 102 | |
| 103 FFTSetup m_FFTSetup; | 100 FFTSetup m_FFTSetup; |
| 104 | |
| 105 DSPSplitComplex m_frame; | 101 DSPSplitComplex m_frame; |
| 106 AudioFloatArray m_realData; | 102 #elif USE(WEBAUDIO_FFMPEG) |
| 107 AudioFloatArray m_imagData; | |
| 108 #else // !OS(MACOSX) | |
| 109 | |
| 110 #if USE(WEBAUDIO_FFMPEG) | |
| 111 static RDFTContext* contextForSize(unsigned fftSize, int trans); | 103 static RDFTContext* contextForSize(unsigned fftSize, int trans); |
| 112 | |
| 113 RDFTContext* m_forwardContext; | 104 RDFTContext* m_forwardContext; |
| 114 RDFTContext* m_inverseContext; | 105 RDFTContext* m_inverseContext; |
| 115 | |
| 116 float* getUpToDateComplexData(); | 106 float* getUpToDateComplexData(); |
| 117 AudioFloatArray m_complexData; | 107 AudioFloatArray m_complexData; |
| 118 AudioFloatArray m_realData; | 108 #elif USE(WEBAUDIO_IPP) |
| 119 AudioFloatArray m_imagData; | |
| 120 #endif // USE(WEBAUDIO_FFMPEG) | |
| 121 | |
| 122 #if USE(WEBAUDIO_IPP) | |
| 123 Ipp8u* m_buffer; | 109 Ipp8u* m_buffer; |
| 124 IppsDFTSpec_R_32f* m_DFTSpec; | 110 IppsDFTSpec_R_32f* m_DFTSpec; |
| 125 | |
| 126 float* getUpToDateComplexData(); | 111 float* getUpToDateComplexData(); |
| 127 AudioFloatArray m_complexData; | 112 AudioFloatArray m_complexData; |
| 128 AudioFloatArray m_realData; | 113 #elif USE(WEBAUDIO_OPENMAX_DL_FFT) |
| 129 AudioFloatArray m_imagData; | |
| 130 #endif // USE(WEBAUDIO_IPP) | |
| 131 | |
| 132 #if USE(WEBAUDIO_OPENMAX_DL_FFT) | |
| 133 static OMXFFTSpec_R_F32* contextForSize(unsigned log2FFTSize); | 114 static OMXFFTSpec_R_F32* contextForSize(unsigned log2FFTSize); |
| 134 | |
| 135 OMXFFTSpec_R_F32* m_forwardContext; | 115 OMXFFTSpec_R_F32* m_forwardContext; |
| 136 OMXFFTSpec_R_F32* m_inverseContext; | 116 OMXFFTSpec_R_F32* m_inverseContext; |
| 137 | |
| 138 AudioFloatArray m_complexData; | 117 AudioFloatArray m_complexData; |
| 139 AudioFloatArray m_realData; | |
| 140 AudioFloatArray m_imagData; | |
| 141 #endif | 118 #endif |
| 142 | |
| 143 #endif // !OS(MACOSX) | |
| 144 }; | 119 }; |
| 145 | 120 |
| 146 } // namespace blink | 121 } // namespace blink |
| 147 | 122 |
| 148 #endif // FFTFrame_h | 123 #endif // FFTFrame_h |
| OLD | NEW |