blob: 4233c69fc57cdeed0eee92aaa79766dfe5457c59 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_REAL_FFT_H_
12#define COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_REAL_FFT_H_
andrew@webrtc.org618ab3f2012-09-04 23:39:05 +000013
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "typedefs.h"
andrew@webrtc.org618ab3f2012-09-04 23:39:05 +000015
kma@webrtc.orgfc8aaf02013-07-24 17:38:23 +000016// For ComplexFFT(), the maximum fft order is 10;
17// for OpenMax FFT in ARM, it is 12;
18// WebRTC APM uses orders of only 7 and 8.
19enum {kMaxFFTOrder = 10};
20
andrew@webrtc.org618ab3f2012-09-04 23:39:05 +000021struct RealFFT;
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
bjornv@webrtc.orgee432632014-12-08 16:36:22 +000027struct RealFFT* WebRtcSpl_CreateRealFFT(int order);
28void WebRtcSpl_FreeRealFFT(struct RealFFT* self);
kma@webrtc.orgf9e6cc22012-09-21 18:51:12 +000029
kma@webrtc.orgfc8aaf02013-07-24 17:38:23 +000030// Compute an FFT for a real-valued signal of length of 2^order,
31// where 1 < order <= MAX_FFT_ORDER. Transform length is determined by the
32// specification structure, which must be initialized prior to calling the FFT
33// function with WebRtcSpl_CreateRealFFT().
34// The relationship between the input and output sequences can
35// be expressed in terms of the DFT, i.e.:
36// x[n] = (2^(-scalefactor)/N) . SUM[k=0,...,N-1] X[k].e^(jnk.2.pi/N)
37// n=0,1,2,...N-1
38// N=2^order.
39// The conjugate-symmetric output sequence is represented using a CCS vector,
40// which is of length N+2, and is organized as follows:
41// Index: 0 1 2 3 4 5 . . . N-2 N-1 N N+1
42// Component: R0 0 R1 I1 R2 I2 . . . R[N/2-1] I[N/2-1] R[N/2] 0
43// where R[n] and I[n], respectively, denote the real and imaginary components
44// for FFT bin 'n'. Bins are numbered from 0 to N/2, where N is the FFT length.
45// Bin index 0 corresponds to the DC component, and bin index N/2 corresponds to
46// the foldover frequency.
47//
kma@webrtc.orgf9e6cc22012-09-21 18:51:12 +000048// Input Arguments:
49// self - pointer to preallocated and initialized FFT specification structure.
kma@webrtc.orgfc8aaf02013-07-24 17:38:23 +000050// real_data_in - the input signal. For an ARM Neon platform, it must be
51// aligned on a 32-byte boundary.
andrew@webrtc.org618ab3f2012-09-04 23:39:05 +000052//
kma@webrtc.orgf9e6cc22012-09-21 18:51:12 +000053// Output Arguments:
kma@webrtc.orgfc8aaf02013-07-24 17:38:23 +000054// complex_data_out - the output complex signal with (2^order + 2) 16-bit
55// elements. For an ARM Neon platform, it must be different
56// from real_data_in, and aligned on a 32-byte boundary.
kma@webrtc.orgf9e6cc22012-09-21 18:51:12 +000057//
58// Return Value:
59// 0 - FFT calculation is successful.
deadbeef922246a2017-02-26 04:18:12 -080060// -1 - Error with bad arguments (null pointers).
bjornv@webrtc.orgee432632014-12-08 16:36:22 +000061int WebRtcSpl_RealForwardFFT(struct RealFFT* self,
62 const int16_t* real_data_in,
63 int16_t* complex_data_out);
kma@webrtc.orgf9e6cc22012-09-21 18:51:12 +000064
kma@webrtc.orgfc8aaf02013-07-24 17:38:23 +000065// Compute the inverse FFT for a conjugate-symmetric input sequence of length of
66// 2^order, where 1 < order <= MAX_FFT_ORDER. Transform length is determined by
67// the specification structure, which must be initialized prior to calling the
68// FFT function with WebRtcSpl_CreateRealFFT().
69// For a transform of length M, the input sequence is represented using a packed
70// CCS vector of length M+2, which is explained in the comments for
71// WebRtcSpl_RealForwardFFTC above.
72//
kma@webrtc.orgf9e6cc22012-09-21 18:51:12 +000073// Input Arguments:
74// self - pointer to preallocated and initialized FFT specification structure.
kma@webrtc.orgfc8aaf02013-07-24 17:38:23 +000075// complex_data_in - the input complex signal with (2^order + 2) 16-bit
76// elements. For an ARM Neon platform, it must be aligned on
77// a 32-byte boundary.
kma@webrtc.orgf9e6cc22012-09-21 18:51:12 +000078//
79// Output Arguments:
kma@webrtc.orgfc8aaf02013-07-24 17:38:23 +000080// real_data_out - the output real signal. For an ARM Neon platform, it must
81// be different to complex_data_in, and aligned on a 32-byte
82// boundary.
kma@webrtc.orgf9e6cc22012-09-21 18:51:12 +000083//
84// Return Value:
kma@webrtc.orgfc8aaf02013-07-24 17:38:23 +000085// 0 or a positive number - a value that the elements in the |real_data_out|
86// should be shifted left with in order to get
87// correct physical values.
deadbeef922246a2017-02-26 04:18:12 -080088// -1 - Error with bad arguments (null pointers).
bjornv@webrtc.orgee432632014-12-08 16:36:22 +000089int WebRtcSpl_RealInverseFFT(struct RealFFT* self,
90 const int16_t* complex_data_in,
91 int16_t* real_data_out);
andrew@webrtc.org618ab3f2012-09-04 23:39:05 +000092
93#ifdef __cplusplus
94}
95#endif
96
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020097#endif // COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_REAL_FFT_H_