PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/webkit-1.8.1/Source/WebCore/platform/audio/FFTFrame.h

#
C++ Header | 183 lines | 103 code | 42 blank | 38 comment | 1 complexity | 212867c8daef458e9d4e68f096425893 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, LGPL-2.0
  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_FFMPEG)
  50. struct RDFTContext;
  51. #endif // USE(WEBAUDIO_FFMPEG)
  52. #endif // !USE_ACCELERATE_FFT
  53. #if USE(WEBAUDIO_IPP)
  54. #include <ipps.h>
  55. #endif // USE(WEBAUDIO_IPP)
  56. #include <wtf/PassOwnPtr.h>
  57. #include <wtf/Platform.h>
  58. #include <wtf/Threading.h>
  59. namespace WebCore {
  60. // Defines the interface for an "FFT frame", an object which is able to perform a forward
  61. // and reverse FFT, internally storing the resultant frequency-domain data.
  62. class FFTFrame {
  63. public:
  64. // The constructors, destructor, and methods up to the CROSS-PLATFORM section have platform-dependent implementations.
  65. FFTFrame(unsigned fftSize);
  66. FFTFrame(); // creates a blank/empty frame for later use with createInterpolatedFrame()
  67. FFTFrame(const FFTFrame& frame);
  68. ~FFTFrame();
  69. static void initialize();
  70. static void cleanup();
  71. void doFFT(const float* data);
  72. void doInverseFFT(float* data);
  73. void multiply(const FFTFrame& frame); // multiplies ourself with frame : effectively operator*=()
  74. float* realData() const;
  75. float* imagData() const;
  76. void print(); // for debugging
  77. // CROSS-PLATFORM
  78. // The remaining public methods have cross-platform implementations:
  79. // Interpolates from frame1 -> frame2 as x goes from 0.0 -> 1.0
  80. static PassOwnPtr<FFTFrame> createInterpolatedFrame(const FFTFrame& frame1, const FFTFrame& frame2, double x);
  81. void doPaddedFFT(const float* data, size_t dataSize); // zero-padding with dataSize <= fftSize
  82. double extractAverageGroupDelay();
  83. void addConstantGroupDelay(double sampleFrameDelay);
  84. unsigned fftSize() const { return m_FFTSize; }
  85. unsigned log2FFTSize() const { return m_log2FFTSize; }
  86. private:
  87. unsigned m_FFTSize;
  88. unsigned m_log2FFTSize;
  89. void interpolateFrequencyComponents(const FFTFrame& frame1, const FFTFrame& frame2, double x);
  90. #if USE_ACCELERATE_FFT
  91. DSPSplitComplex& dspSplitComplex() { return m_frame; }
  92. DSPSplitComplex dspSplitComplex() const { return m_frame; }
  93. static FFTSetup fftSetupForSize(unsigned fftSize);
  94. static FFTSetup* fftSetups;
  95. FFTSetup m_FFTSetup;
  96. DSPSplitComplex m_frame;
  97. AudioFloatArray m_realData;
  98. AudioFloatArray m_imagData;
  99. #else // !USE_ACCELERATE_FFT
  100. #if USE(WEBAUDIO_MKL)
  101. // Interleaves the planar real and imaginary data and returns a
  102. // pointer to the resulting storage which can be used for in-place
  103. // or out-of-place operations. FIXME: ideally all of the MKL
  104. // routines would operate on planar data and this method would be
  105. // removed.
  106. float* getUpToDateComplexData();
  107. static DFTI_DESCRIPTOR_HANDLE descriptorHandleForSize(unsigned fftSize);
  108. static DFTI_DESCRIPTOR_HANDLE* descriptorHandles;
  109. DFTI_DESCRIPTOR_HANDLE m_handle;
  110. AudioFloatArray m_complexData;
  111. AudioFloatArray m_realData;
  112. AudioFloatArray m_imagData;
  113. #endif // USE(WEBAUDIO_MKL)
  114. #if USE(WEBAUDIO_FFMPEG)
  115. static RDFTContext* contextForSize(unsigned fftSize, int trans);
  116. RDFTContext* m_forwardContext;
  117. RDFTContext* m_inverseContext;
  118. float* getUpToDateComplexData();
  119. AudioFloatArray m_complexData;
  120. AudioFloatArray m_realData;
  121. AudioFloatArray m_imagData;
  122. #endif // USE(WEBAUDIO_FFMPEG)
  123. #if USE(WEBAUDIO_GSTREAMER)
  124. GstFFTF32* m_fft;
  125. GstFFTF32* m_inverseFft;
  126. GstFFTF32Complex* m_complexData;
  127. AudioFloatArray m_realData;
  128. AudioFloatArray m_imagData;
  129. #endif // USE(WEBAUDIO_GSTREAMER)
  130. #if USE(WEBAUDIO_IPP)
  131. Ipp8u* m_buffer;
  132. IppsDFTSpec_R_32f* m_DFTSpec;
  133. float* getUpToDateComplexData();
  134. AudioFloatArray m_complexData;
  135. AudioFloatArray m_realData;
  136. AudioFloatArray m_imagData;
  137. #endif // USE(WEBAUDIO_IPP)
  138. #endif // !USE_ACCELERATE_FFT
  139. };
  140. } // namespace WebCore
  141. #endif // FFTFrame_h