blob: 6c5c9cee9285255ae084c3e98e2cdfed2f125d43 [file] [log] [blame]
andrew@webrtc.org04c50982015-03-19 20:06:291/*
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 04:47:3111#include "common_audio/real_fourier_openmax.h"
andrew@webrtc.org04c50982015-03-19 20:06:2912
13#include <cstdlib>
14
kjellander56cf60e2016-03-16 00:41:0115#include "dl/sp/api/omxSP.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3116#include "rtc_base/checks.h"
andrew@webrtc.org04c50982015-03-19 20:06:2917
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 07:24:3426 RTC_CHECK_GE(order, 1);
andrew@webrtc.org04c50982015-03-19 20:06:2927 // The omx implementation uses this macro to check order validity.
henrikg91d6ede2015-09-17 07:24:3428 RTC_CHECK_LE(order, TWIDDLE_TABLE_ORDER);
andrew@webrtc.org04c50982015-03-19 20:06:2929
30 OMX_INT buffer_size;
31 OMXResult r = omxSP_FFTGetBufSize_R_F32(order, &buffer_size);
henrikg91d6ede2015-09-17 07:24:3432 RTC_CHECK_EQ(r, OMX_Sts_NoErr);
andrew@webrtc.org04c50982015-03-19 20:06:2933
34 OMXFFTSpec_R_F32* omx_spec = malloc(buffer_size);
henrikg91d6ede2015-09-17 07:24:3435 RTC_DCHECK(omx_spec);
andrew@webrtc.org04c50982015-03-19 20:06:2936
37 r = omxSP_FFTInit_R_F32(omx_spec, order);
henrikg91d6ede2015-09-17 07:24:3438 RTC_CHECK_EQ(r, OMX_Sts_NoErr);
andrew@webrtc.org04c50982015-03-19 20:06:2939 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 07:24:3458 RTC_CHECK_EQ(r, OMX_Sts_NoErr);
andrew@webrtc.org04c50982015-03-19 20:06:2959}
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 07:24:3465 RTC_CHECK_EQ(r, OMX_Sts_NoErr);
andrew@webrtc.org04c50982015-03-19 20:06:2966}
67
68} // namespace webrtc
69