2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
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.
10 * This is a modification of omxSP_FFTInit_R_S32.c to support float
16 #include "dl/api/arm/armOMX.h"
17 #include "dl/api/omxtypes.h"
18 #include "dl/sp/api/armSP.h"
19 #include "dl/sp/api/omxSP.h"
22 * Function: omxSP_FFTInit_R_F32
25 * Initialize the real forward-FFT specification information struct.
28 * This function is used to initialize the specification structures
29 * for functions <ippsFFTFwd_RToCCS_F32_Sfs> and
30 * <ippsFFTInv_CCSToR_F32_Sfs>. Memory for *pFFTSpec must be
31 * allocated prior to calling this function. The number of bytes
32 * required for *pFFTSpec can be determined using
33 * <FFTGetBufSize_R_F32>.
36 * [in] order base-2 logarithm of the desired block length;
37 * valid in the range [1,12]. ([1,15] if
38 * BIG_FFT_TABLE is defined.)
39 * [out] pFFTFwdSpec pointer to the initialized specification structure.
42 * Standard omxError result. See enumeration for possible result codes.
45 OMXResult omxSP_FFTInit_R_F32(OMXFFTSpec_R_F32* pFFTSpec, OMX_INT order) {
64 ARMsFFTSpec_R_FC32* pFFTStruct = 0;
66 pFFTStruct = (ARMsFFTSpec_R_FC32 *) pFFTSpec;
69 if (!pFFTSpec || (order < 1) || (order > TWIDDLE_TABLE_ORDER))
70 return OMX_Sts_BadArgErr;
72 /* Do the initializations */
73 Nby2 = 1 << (order - 1);
76 /* optimized implementations don't use bitreversal */
79 pTwiddle = (OMX_FC32 *) (sizeof(ARMsFFTSpec_R_SC32) + (OMX_S8*) pFFTSpec);
81 /* Align to 32 byte boundary */
82 pTmp = ((uintptr_t)pTwiddle) & 31;
84 pTwiddle = (OMX_FC32*) ((OMX_S8*)pTwiddle + (32 - pTmp));
86 pBuf = (OMX_F32*) (sizeof(OMX_FC32)*(5*N/8) + (OMX_S8*) pTwiddle);
88 /* Align to 32 byte boundary */
89 pTmp = ((uintptr_t)pBuf)&31; /* (uintptr_t)pBuf % 32 */
91 pBuf = (OMX_F32*) ((OMX_S8*)pBuf + (32 - pTmp));
94 * Filling Twiddle factors :
96 * exp^(-j*2*PI*k/ (N/2) ) ; k=0,1,2,...,3/4(N/2)
98 * N/2 point complex FFT is used to compute N point real FFT The
99 * original twiddle table "armSP_FFT_F32TwiddleTable" is of size
100 * (MaxSize/8 + 1) Rest of the values i.e., upto MaxSize are
101 * calculated using the symmetries of sin and cos The max size of
102 * the twiddle table needed is 3/4(N/2) for a radix-4 stage
106 * W = -PI >> (order - 1)
110 diff = TWIDDLE_TABLE_ORDER - (order - 1);
111 /* step into the twiddle table for the current order */
114 x = armSP_FFT_F32TwiddleTable[0];
115 y = armSP_FFT_F32TwiddleTable[1];
118 if ((order - 1) >= 3) {
122 pTwiddle[2*M].Re = -y;
123 pTwiddle[2*M].Im = xNeg;
124 pTwiddle[4*M].Re = xNeg;
125 pTwiddle[4*M].Im = y;
127 for (i = 1; i <= M; i++) {
130 x = armSP_FFT_F32TwiddleTable[2*j];
131 y = armSP_FFT_F32TwiddleTable[2*j+1];
135 pTwiddle[2*M-i].Re = -y;
136 pTwiddle[2*M-i].Im = -x;
137 pTwiddle[2*M+i].Re = y;
138 pTwiddle[2*M+i].Im = -x;
139 pTwiddle[4*M-i].Re = -x;
140 pTwiddle[4*M-i].Im = y;
141 pTwiddle[4*M+i].Re = -x;
142 pTwiddle[4*M+i].Im = -y;
143 pTwiddle[6*M-i].Re = y;
144 pTwiddle[6*M-i].Im = x;
146 } else if ((order - 1) == 2) {
150 pTwiddle[1].Im = xNeg;
151 pTwiddle[2].Re = xNeg;
153 } else if ((order-1) == 1) {
159 * Now fill the last N/4 values : exp^(-j*2*PI*k/N) ;
160 * k=1,3,5,...,N/2-1 These are used for the final twiddle fix-up for
161 * converting complex to real FFT
165 diff = TWIDDLE_TABLE_ORDER - order;
168 pTwiddle1 = pTwiddle + 3*N/8;
169 pTwiddle4 = pTwiddle1 + (N/4 - 1);
170 pTwiddle3 = pTwiddle1 + N/8;
171 pTwiddle2 = pTwiddle1 + (N/8 - 1);
173 x = armSP_FFT_F32TwiddleTable[0];
174 y = armSP_FFT_F32TwiddleTable[1];
178 for (i = 1; i <= M; i += 2) {
181 x = armSP_FFT_F32TwiddleTable[2*j];
182 y = armSP_FFT_F32TwiddleTable[2*j+1];
187 pTwiddle2[0].Re = -y;
188 pTwiddle2[0].Im = -x;
191 pTwiddle3[0].Im = -x;
193 pTwiddle4[0].Re = -x;
199 pTwiddle1[0].Re = -y;
200 pTwiddle1[0].Im = xNeg;
205 /* Update the structure */
207 pFFTStruct->pTwiddle = pTwiddle;
208 pFFTStruct->pBitRev = pBitRev;
209 pFFTStruct->pBuf = pBuf;
211 return OMX_Sts_NoErr;