andrew@webrtc.org | 618ab3f | 2012-09-04 23:39:05 +0000 | [diff] [blame] | 1 | /* |
| 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.org | aa30bb7 | 2013-05-27 09:49:58 +0000 | [diff] [blame] | 11 | #include "webrtc/common_audio/signal_processing/include/real_fft.h" |
andrew@webrtc.org | 618ab3f | 2012-09-04 23:39:05 +0000 | [diff] [blame] | 12 | |
| 13 | #include <stdlib.h> |
| 14 | |
pbos@webrtc.org | aa30bb7 | 2013-05-27 09:49:58 +0000 | [diff] [blame] | 15 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" |
andrew@webrtc.org | 618ab3f | 2012-09-04 23:39:05 +0000 | [diff] [blame] | 16 | |
| 17 | struct RealFFT { |
| 18 | int order; |
| 19 | }; |
| 20 | |
| 21 | struct RealFFT* WebRtcSpl_CreateRealFFT(int order) { |
| 22 | struct RealFFT* self = NULL; |
kma@webrtc.org | f9e6cc2 | 2012-09-21 18:51:12 +0000 | [diff] [blame] | 23 | |
andrew@webrtc.org | 618ab3f | 2012-09-04 23:39:05 +0000 | [diff] [blame] | 24 | // This constraint comes from ComplexFFT(). |
| 25 | if (order > 10 || order < 0) { |
| 26 | return NULL; |
| 27 | } |
kma@webrtc.org | f9e6cc2 | 2012-09-21 18:51:12 +0000 | [diff] [blame] | 28 | |
andrew@webrtc.org | 618ab3f | 2012-09-04 23:39:05 +0000 | [diff] [blame] | 29 | self = malloc(sizeof(struct RealFFT)); |
| 30 | self->order = order; |
kma@webrtc.org | f9e6cc2 | 2012-09-21 18:51:12 +0000 | [diff] [blame] | 31 | |
andrew@webrtc.org | 618ab3f | 2012-09-04 23:39:05 +0000 | [diff] [blame] | 32 | return self; |
| 33 | } |
| 34 | |
| 35 | void WebRtcSpl_FreeRealFFT(struct RealFFT* self) { |
| 36 | free(self); |
| 37 | } |
| 38 | |
kma@webrtc.org | f9e6cc2 | 2012-09-21 18:51:12 +0000 | [diff] [blame] | 39 | // 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 | |
| 42 | int 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.org | 618ab3f | 2012-09-04 23:39:05 +0000 | [diff] [blame] | 48 | } |
| 49 | |
kma@webrtc.org | f9e6cc2 | 2012-09-21 18:51:12 +0000 | [diff] [blame] | 50 | int 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.org | 618ab3f | 2012-09-04 23:39:05 +0000 | [diff] [blame] | 56 | } |
kma@webrtc.org | f9e6cc2 | 2012-09-21 18:51:12 +0000 | [diff] [blame] | 57 | |
| 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. |
| 61 | int 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 | |
| 67 | int 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 |