PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/qt/qtwebkit/Source/WebCore/platform/audio/FFTFrame.h

https://gitlab.com/x33n/phantomjs
C Header | 197 lines | 114 code | 45 blank | 38 comment | 1 complexity | 32a947e336c4cfd8f5c72e2dc8240e94 MD5 | raw file
  1. /*
  2. * Copyright (C) 2010 Google Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  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.
  16. *
  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.
  27. */
  28. #ifndef FFTFrame_h
  29. #define FFTFrame_h
  30. #include "AudioArray.h"
  31. #if OS(DARWIN) && !USE(WEBAUDIO_FFMPEG)
  32. #define USE_ACCELERATE_FFT 1
  33. #else
  34. #define USE_ACCELERATE_FFT 0
  35. #endif
  36. #if USE_ACCELERATE_FFT
  37. #include <Accelerate/Accelerate.h>
  38. #endif
  39. #if !USE_ACCELERATE_FFT
  40. #if USE(WEBAUDIO_MKL)
  41. #include "mkl_dfti.h"
  42. #endif // USE(WEBAUDIO_MKL)
  43. #if USE(WEBAUDIO_GSTREAMER)
  44. #include <glib.h>
  45. G_BEGIN_DECLS
  46. #include <gst/fft/gstfftf32.h>
  47. G_END_DECLS
  48. #endif // USE(WEBAUDIO_GSTREAMER)
  49. #if USE(WEBAUDIO_OPENMAX_DL_FFT)
  50. #include "dl/sp/api/armSP.h"
  51. #include "dl/sp/api/omxSP.h"
  52. #elif USE(WEBAUDIO_FFMPEG)
  53. struct RDFTContext;
  54. #endif
  55. #endif // !USE_ACCELERATE_FFT
  56. #if USE(WEBAUDIO_IPP)
  57. #include <ipps.h>
  58. #endif // USE(WEBAUDIO_IPP)
  59. #include <wtf/Forward.h>
  60. #include <wtf/PassOwnPtr.h>
  61. #include <wtf/Threading.h>
  62. namespace WebCore {
  63. // Defines the interface for an "FFT frame", an object which is able to perform a forward
  64. // and reverse FFT, internally storing the resultant frequency-domain data.
  65. class FFTFrame {
  66. public:
  67. // The constructors, destructor, and methods up to the CROSS-PLATFORM section have platform-dependent implementations.
  68. FFTFrame(unsigned fftSize);
  69. FFTFrame(); // creates a blank/empty frame for later use with createInterpolatedFrame()
  70. FFTFrame(const FFTFrame& frame);
  71. ~FFTFrame();
  72. static void initialize();
  73. static void cleanup();
  74. void doFFT(const float* data);
  75. void doInverseFFT(float* data);
  76. void multiply(const FFTFrame& frame); // multiplies ourself with frame : effectively operator*=()
  77. float* realData() const;
  78. float* imagData() const;
  79. void print(); // for debugging
  80. // CROSS-PLATFORM
  81. // The remaining public methods have cross-platform implementations:
  82. // Interpolates from frame1 -> frame2 as x goes from 0.0 -> 1.0
  83. static PassOwnPtr<FFTFrame> createInterpolatedFrame(const FFTFrame& frame1, const FFTFrame& frame2, double x);
  84. void doPaddedFFT(const float* data, size_t dataSize); // zero-padding with dataSize <= fftSize
  85. double extractAverageGroupDelay();
  86. void addConstantGroupDelay(double sampleFrameDelay);
  87. unsigned fftSize() const { return m_FFTSize; }
  88. unsigned log2FFTSize() const { return m_log2FFTSize; }
  89. private:
  90. unsigned m_FFTSize;
  91. unsigned m_log2FFTSize;
  92. void interpolateFrequencyComponents(const FFTFrame& frame1, const FFTFrame& frame2, double x);
  93. #if USE_ACCELERATE_FFT
  94. DSPSplitComplex& dspSplitComplex() { return m_frame; }
  95. DSPSplitComplex dspSplitComplex() const { return m_frame; }
  96. static FFTSetup fftSetupForSize(unsigned fftSize);
  97. static FFTSetup* fftSetups;
  98. FFTSetup m_FFTSetup;
  99. DSPSplitComplex m_frame;
  100. AudioFloatArray m_realData;
  101. AudioFloatArray m_imagData;
  102. #else // !USE_ACCELERATE_FFT
  103. #if USE(WEBAUDIO_MKL)
  104. // Interleaves the planar real and imaginary data and returns a
  105. // pointer to the resulting storage which can be used for in-place
  106. // or out-of-place operations. FIXME: ideally all of the MKL
  107. // routines would operate on planar data and this method would be
  108. // removed.
  109. float* getUpToDateComplexData();
  110. static DFTI_DESCRIPTOR_HANDLE descriptorHandleForSize(unsigned fftSize);
  111. static DFTI_DESCRIPTOR_HANDLE* descriptorHandles;
  112. DFTI_DESCRIPTOR_HANDLE m_handle;
  113. AudioFloatArray m_complexData;
  114. AudioFloatArray m_realData;
  115. AudioFloatArray m_imagData;
  116. #endif // USE(WEBAUDIO_MKL)
  117. #if USE(WEBAUDIO_FFMPEG)
  118. static RDFTContext* contextForSize(unsigned fftSize, int trans);
  119. RDFTContext* m_forwardContext;
  120. RDFTContext* m_inverseContext;
  121. float* getUpToDateComplexData();
  122. AudioFloatArray m_complexData;
  123. AudioFloatArray m_realData;
  124. AudioFloatArray m_imagData;
  125. #endif // USE(WEBAUDIO_FFMPEG)
  126. #if USE(WEBAUDIO_GSTREAMER)
  127. GstFFTF32* m_fft;
  128. GstFFTF32* m_inverseFft;
  129. GstFFTF32Complex* m_complexData;
  130. AudioFloatArray m_realData;
  131. AudioFloatArray m_imagData;
  132. #endif // USE(WEBAUDIO_GSTREAMER)
  133. #if USE(WEBAUDIO_IPP)
  134. Ipp8u* m_buffer;
  135. IppsDFTSpec_R_32f* m_DFTSpec;
  136. float* getUpToDateComplexData();
  137. AudioFloatArray m_complexData;
  138. AudioFloatArray m_realData;
  139. AudioFloatArray m_imagData;
  140. #endif // USE(WEBAUDIO_IPP)
  141. #if USE(WEBAUDIO_OPENMAX_DL_FFT)
  142. static OMXFFTSpec_R_F32* contextForSize(unsigned log2FFTSize);
  143. OMXFFTSpec_R_F32* m_forwardContext;
  144. OMXFFTSpec_R_F32* m_inverseContext;
  145. AudioFloatArray m_complexData;
  146. AudioFloatArray m_realData;
  147. AudioFloatArray m_imagData;
  148. #endif
  149. #endif // !USE_ACCELERATE_FFT
  150. };
  151. } // namespace WebCore
  152. #endif // FFTFrame_h