blob: 8da243da30e77d94e2816b0d15e4a2942ad6e204 [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 Bonadei71207422017-09-15 13:58:09 +020014#include "typedefs.h" // NOLINT(build/include)
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;
kma@webrtc.orgfc8aaf02013-07-24 17:38:23 +000017// WebRTC APM uses orders of only 7 and 8.
Yves Gerey665174f2018-06-19 15:03:05 +020018enum { kMaxFFTOrder = 10 };
kma@webrtc.orgfc8aaf02013-07-24 17:38:23 +000019
andrew@webrtc.org618ab3f2012-09-04 23:39:05 +000020struct RealFFT;
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
bjornv@webrtc.orgee432632014-12-08 16:36:22 +000026struct RealFFT* WebRtcSpl_CreateRealFFT(int order);
27void WebRtcSpl_FreeRealFFT(struct RealFFT* self);
kma@webrtc.orgf9e6cc22012-09-21 18:51:12 +000028
kma@webrtc.orgfc8aaf02013-07-24 17:38:23 +000029// Compute an FFT for a real-valued signal of length of 2^order,
30// where 1 < order <= MAX_FFT_ORDER. Transform length is determined by the
31// specification structure, which must be initialized prior to calling the FFT
32// function with WebRtcSpl_CreateRealFFT().
33// The relationship between the input and output sequences can
34// be expressed in terms of the DFT, i.e.:
35// x[n] = (2^(-scalefactor)/N) . SUM[k=0,...,N-1] X[k].e^(jnk.2.pi/N)
36// n=0,1,2,...N-1
37// N=2^order.
38// The conjugate-symmetric output sequence is represented using a CCS vector,
39// which is of length N+2, and is organized as follows:
40// Index: 0 1 2 3 4 5 . . . N-2 N-1 N N+1
41// Component: R0 0 R1 I1 R2 I2 . . . R[N/2-1] I[N/2-1] R[N/2] 0
42// where R[n] and I[n], respectively, denote the real and imaginary components
43// for FFT bin 'n'. Bins are numbered from 0 to N/2, where N is the FFT length.
44// Bin index 0 corresponds to the DC component, and bin index N/2 corresponds to
45// the foldover frequency.
46//
kma@webrtc.orgf9e6cc22012-09-21 18:51:12 +000047// Input Arguments:
48// self - pointer to preallocated and initialized FFT specification structure.
kma@webrtc.orgfc8aaf02013-07-24 17:38:23 +000049// real_data_in - the input signal. For an ARM Neon platform, it must be
50// aligned on a 32-byte boundary.
andrew@webrtc.org618ab3f2012-09-04 23:39:05 +000051//
kma@webrtc.orgf9e6cc22012-09-21 18:51:12 +000052// Output Arguments:
kma@webrtc.orgfc8aaf02013-07-24 17:38:23 +000053// complex_data_out - the output complex signal with (2^order + 2) 16-bit
54// elements. For an ARM Neon platform, it must be different
55// from real_data_in, and aligned on a 32-byte boundary.
kma@webrtc.orgf9e6cc22012-09-21 18:51:12 +000056//
57// Return Value:
58// 0 - FFT calculation is successful.
deadbeef922246a2017-02-26 04:18:12 -080059// -1 - Error with bad arguments (null pointers).
bjornv@webrtc.orgee432632014-12-08 16:36:22 +000060int WebRtcSpl_RealForwardFFT(struct RealFFT* self,
61 const int16_t* real_data_in,
62 int16_t* complex_data_out);
kma@webrtc.orgf9e6cc22012-09-21 18:51:12 +000063
kma@webrtc.orgfc8aaf02013-07-24 17:38:23 +000064// Compute the inverse FFT for a conjugate-symmetric input sequence of length of
65// 2^order, where 1 < order <= MAX_FFT_ORDER. Transform length is determined by
66// the specification structure, which must be initialized prior to calling the
67// FFT function with WebRtcSpl_CreateRealFFT().
68// For a transform of length M, the input sequence is represented using a packed
69// CCS vector of length M+2, which is explained in the comments for
70// WebRtcSpl_RealForwardFFTC above.
71//
kma@webrtc.orgf9e6cc22012-09-21 18:51:12 +000072// Input Arguments:
73// self - pointer to preallocated and initialized FFT specification structure.
kma@webrtc.orgfc8aaf02013-07-24 17:38:23 +000074// complex_data_in - the input complex signal with (2^order + 2) 16-bit
75// elements. For an ARM Neon platform, it must be aligned on
76// a 32-byte boundary.
kma@webrtc.orgf9e6cc22012-09-21 18:51:12 +000077//
78// Output Arguments:
kma@webrtc.orgfc8aaf02013-07-24 17:38:23 +000079// real_data_out - the output real signal. For an ARM Neon platform, it must
80// be different to complex_data_in, and aligned on a 32-byte
81// boundary.
kma@webrtc.orgf9e6cc22012-09-21 18:51:12 +000082//
83// Return Value:
kma@webrtc.orgfc8aaf02013-07-24 17:38:23 +000084// 0 or a positive number - a value that the elements in the |real_data_out|
85// should be shifted left with in order to get
86// correct physical values.
deadbeef922246a2017-02-26 04:18:12 -080087// -1 - Error with bad arguments (null pointers).
bjornv@webrtc.orgee432632014-12-08 16:36:22 +000088int WebRtcSpl_RealInverseFFT(struct RealFFT* self,
89 const int16_t* complex_data_in,
90 int16_t* real_data_out);
andrew@webrtc.org618ab3f2012-09-04 23:39:05 +000091
92#ifdef __cplusplus
93}
94#endif
95
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020096#endif // COMMON_AUDIO_SIGNAL_PROCESSING_INCLUDE_REAL_FFT_H_