Home | History | Annotate | Download | only in common_audio
      1 /*
      2  *  Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 #include "webrtc/common_audio/real_fourier_openmax.h"
     12 
     13 #include <cstdlib>
     14 
     15 #include "dl/sp/api/omxSP.h"
     16 #include "webrtc/base/checks.h"
     17 
     18 namespace webrtc {
     19 
     20 using std::complex;
     21 
     22 namespace {
     23 
     24 // Creates and initializes the Openmax state. Transfers ownership to caller.
     25 OMXFFTSpec_R_F32* CreateOpenmaxState(int order) {
     26   RTC_CHECK_GE(order, 1);
     27   // The omx implementation uses this macro to check order validity.
     28   RTC_CHECK_LE(order, TWIDDLE_TABLE_ORDER);
     29 
     30   OMX_INT buffer_size;
     31   OMXResult r = omxSP_FFTGetBufSize_R_F32(order, &buffer_size);
     32   RTC_CHECK_EQ(r, OMX_Sts_NoErr);
     33 
     34   OMXFFTSpec_R_F32* omx_spec = malloc(buffer_size);
     35   RTC_DCHECK(omx_spec);
     36 
     37   r = omxSP_FFTInit_R_F32(omx_spec, order);
     38   RTC_CHECK_EQ(r, OMX_Sts_NoErr);
     39   return omx_spec;
     40 }
     41 
     42 }  // namespace
     43 
     44 RealFourierOpenmax::RealFourierOpenmax(int fft_order)
     45     : order_(fft_order),
     46       omx_spec_(CreateOpenmaxState(order_)) {
     47 }
     48 
     49 RealFourierOpenmax::~RealFourierOpenmax() {
     50   free(omx_spec_);
     51 }
     52 
     53 void RealFourierOpenmax::Forward(const float* src, complex<float>* dest) const {
     54   // This cast is well-defined since C++11. See "Non-static data members" at:
     55   // http://en.cppreference.com/w/cpp/numeric/complex
     56   OMXResult r =
     57       omxSP_FFTFwd_RToCCS_F32(src, reinterpret_cast<OMX_F32*>(dest), omx_spec_);
     58   RTC_CHECK_EQ(r, OMX_Sts_NoErr);
     59 }
     60 
     61 void RealFourierOpenmax::Inverse(const complex<float>* src, float* dest) const {
     62   OMXResult r =
     63       omxSP_FFTInv_CCSToR_F32(reinterpret_cast<const OMX_F32*>(src), dest,
     64                               omx_spec_);
     65   RTC_CHECK_EQ(r, OMX_Sts_NoErr);
     66 }
     67 
     68 }  // namespace webrtc
     69 
     70