blob: 6c5c9cee9285255ae084c3e98e2cdfed2f125d43 [file] [log] [blame]
andrew@webrtc.org04c50982015-03-19 20:06:29 +00001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "common_audio/real_fourier_openmax.h"
andrew@webrtc.org04c50982015-03-19 20:06:29 +000012
13#include <cstdlib>
14
kjellander56cf60e2016-03-15 17:41:01 -070015#include "dl/sp/api/omxSP.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "rtc_base/checks.h"
andrew@webrtc.org04c50982015-03-19 20:06:29 +000017
18namespace webrtc {
19
20using std::complex;
21
22namespace {
23
24// Creates and initializes the Openmax state. Transfers ownership to caller.
25OMXFFTSpec_R_F32* CreateOpenmaxState(int order) {
henrikg91d6ede2015-09-17 00:24:34 -070026 RTC_CHECK_GE(order, 1);
andrew@webrtc.org04c50982015-03-19 20:06:29 +000027 // The omx implementation uses this macro to check order validity.
henrikg91d6ede2015-09-17 00:24:34 -070028 RTC_CHECK_LE(order, TWIDDLE_TABLE_ORDER);
andrew@webrtc.org04c50982015-03-19 20:06:29 +000029
30 OMX_INT buffer_size;
31 OMXResult r = omxSP_FFTGetBufSize_R_F32(order, &buffer_size);
henrikg91d6ede2015-09-17 00:24:34 -070032 RTC_CHECK_EQ(r, OMX_Sts_NoErr);
andrew@webrtc.org04c50982015-03-19 20:06:29 +000033
34 OMXFFTSpec_R_F32* omx_spec = malloc(buffer_size);
henrikg91d6ede2015-09-17 00:24:34 -070035 RTC_DCHECK(omx_spec);
andrew@webrtc.org04c50982015-03-19 20:06:29 +000036
37 r = omxSP_FFTInit_R_F32(omx_spec, order);
henrikg91d6ede2015-09-17 00:24:34 -070038 RTC_CHECK_EQ(r, OMX_Sts_NoErr);
andrew@webrtc.org04c50982015-03-19 20:06:29 +000039 return omx_spec;
40}
41
42} // namespace
43
44RealFourierOpenmax::RealFourierOpenmax(int fft_order)
45 : order_(fft_order),
46 omx_spec_(CreateOpenmaxState(order_)) {
47}
48
49RealFourierOpenmax::~RealFourierOpenmax() {
50 free(omx_spec_);
51}
52
53void 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_);
henrikg91d6ede2015-09-17 00:24:34 -070058 RTC_CHECK_EQ(r, OMX_Sts_NoErr);
andrew@webrtc.org04c50982015-03-19 20:06:29 +000059}
60
61void 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_);
henrikg91d6ede2015-09-17 00:24:34 -070065 RTC_CHECK_EQ(r, OMX_Sts_NoErr);
andrew@webrtc.org04c50982015-03-19 20:06:29 +000066}
67
68} // namespace webrtc
69