blob: bd544322183421215afcf2eb9f674e8d3385fbf6 [file] [log] [blame]
andrew@webrtc.org618ab3f2012-09-04 23:39:05 +00001/*
2 * Copyright (c) 2012 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
pbos@webrtc.orgaa30bb72013-05-27 09:49:58 +000011#include "webrtc/common_audio/signal_processing/include/real_fft.h"
andrew@webrtc.org618ab3f2012-09-04 23:39:05 +000012
13#include <stdlib.h>
14
pbos@webrtc.orgaa30bb72013-05-27 09:49:58 +000015#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
andrew@webrtc.org618ab3f2012-09-04 23:39:05 +000016
17struct RealFFT {
18 int order;
19};
20
21struct RealFFT* WebRtcSpl_CreateRealFFT(int order) {
22 struct RealFFT* self = NULL;
kma@webrtc.orgf9e6cc22012-09-21 18:51:12 +000023
andrew@webrtc.org618ab3f2012-09-04 23:39:05 +000024 // This constraint comes from ComplexFFT().
25 if (order > 10 || order < 0) {
26 return NULL;
27 }
kma@webrtc.orgf9e6cc22012-09-21 18:51:12 +000028
andrew@webrtc.org618ab3f2012-09-04 23:39:05 +000029 self = malloc(sizeof(struct RealFFT));
30 self->order = order;
kma@webrtc.orgf9e6cc22012-09-21 18:51:12 +000031
andrew@webrtc.org618ab3f2012-09-04 23:39:05 +000032 return self;
33}
34
35void WebRtcSpl_FreeRealFFT(struct RealFFT* self) {
36 free(self);
37}
38
kma@webrtc.orgf9e6cc22012-09-21 18:51:12 +000039// WebRtcSpl_ComplexFFT and WebRtcSpl_ComplexIFFT use in-place algorithm,
40// so copy data from data_in to data_out in the next two functions.
41
42int WebRtcSpl_RealForwardFFTC(struct RealFFT* self,
43 const int16_t* data_in,
44 int16_t* data_out) {
45 memcpy(data_out, data_in, sizeof(int16_t) * (1 << (self->order + 1)));
46 WebRtcSpl_ComplexBitReverse(data_out, self->order);
47 return WebRtcSpl_ComplexFFT(data_out, self->order, 1);
andrew@webrtc.org618ab3f2012-09-04 23:39:05 +000048}
49
kma@webrtc.orgf9e6cc22012-09-21 18:51:12 +000050int WebRtcSpl_RealInverseFFTC(struct RealFFT* self,
51 const int16_t* data_in,
52 int16_t* data_out) {
53 memcpy(data_out, data_in, sizeof(int16_t) * (1 << (self->order + 1)));
54 WebRtcSpl_ComplexBitReverse(data_out, self->order);
55 return WebRtcSpl_ComplexIFFT(data_out, self->order, 1);
andrew@webrtc.org618ab3f2012-09-04 23:39:05 +000056}
kma@webrtc.orgf9e6cc22012-09-21 18:51:12 +000057
58#if defined(WEBRTC_DETECT_ARM_NEON) || defined(WEBRTC_ARCH_ARM_NEON)
59// TODO(kma): Replace the following function bodies into optimized functions
60// for ARM Neon.
61int WebRtcSpl_RealForwardFFTNeon(struct RealFFT* self,
62 const int16_t* data_in,
63 int16_t* data_out) {
64 return WebRtcSpl_RealForwardFFTC(self, data_in, data_out);
65}
66
67int WebRtcSpl_RealInverseFFTNeon(struct RealFFT* self,
68 const int16_t* data_in,
69 int16_t* data_out) {
70 return WebRtcSpl_RealInverseFFTC(self, data_in, data_out);
71}
72#endif