]>
git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/dsp/cmsis_dsp/TransformFunctions/arm_bitreversal.c
1 /* ----------------------------------------------------------------------
2 * Copyright (C) 2010-2013 ARM Limited. All rights reserved.
4 * $Date: 17. January 2013
7 * Project: CMSIS DSP Library
8 * Title: arm_bitreversal.c
10 * Description: This file has common tables like Bitreverse, reciprocal etc which are used across different functions
12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * - Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * - Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in
21 * the documentation and/or other materials provided with the
23 * - Neither the name of ARM LIMITED nor the names of its contributors
24 * may be used to endorse or promote products derived from this
25 * software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
39 * -------------------------------------------------------------------- */
42 #include "arm_common_tables.h"
45 * @brief In-place bit reversal function.
46 * @param[in, out] *pSrc points to the in-place buffer of floating-point data type.
47 * @param[in] fftSize length of the FFT.
48 * @param[in] bitRevFactor bit reversal modifier that supports different size FFTs with the same bit reversal table.
49 * @param[in] *pBitRevTab points to the bit reversal table.
53 void arm_bitreversal_f32(
56 uint16_t bitRevFactor
,
57 uint16_t * pBitRevTab
)
59 uint16_t fftLenBy2
, fftLenBy2p1
;
65 fftLenBy2
= fftSize
>> 1u;
66 fftLenBy2p1
= (fftSize
>> 1u) + 1u;
68 /* Bit Reversal Implementation */
69 for (i
= 0u; i
<= (fftLenBy2
- 2u); i
+= 2u)
73 /* pSrc[i] <-> pSrc[j]; */
75 pSrc
[2u * i
] = pSrc
[2u * j
];
78 /* pSrc[i+1u] <-> pSrc[j+1u] */
79 in
= pSrc
[(2u * i
) + 1u];
80 pSrc
[(2u * i
) + 1u] = pSrc
[(2u * j
) + 1u];
81 pSrc
[(2u * j
) + 1u] = in
;
83 /* pSrc[i+fftLenBy2p1] <-> pSrc[j+fftLenBy2p1] */
84 in
= pSrc
[2u * (i
+ fftLenBy2p1
)];
85 pSrc
[2u * (i
+ fftLenBy2p1
)] = pSrc
[2u * (j
+ fftLenBy2p1
)];
86 pSrc
[2u * (j
+ fftLenBy2p1
)] = in
;
88 /* pSrc[i+fftLenBy2p1+1u] <-> pSrc[j+fftLenBy2p1+1u] */
89 in
= pSrc
[(2u * (i
+ fftLenBy2p1
)) + 1u];
90 pSrc
[(2u * (i
+ fftLenBy2p1
)) + 1u] =
91 pSrc
[(2u * (j
+ fftLenBy2p1
)) + 1u];
92 pSrc
[(2u * (j
+ fftLenBy2p1
)) + 1u] = in
;
96 /* pSrc[i+1u] <-> pSrc[j+1u] */
97 in
= pSrc
[2u * (i
+ 1u)];
98 pSrc
[2u * (i
+ 1u)] = pSrc
[2u * (j
+ fftLenBy2
)];
99 pSrc
[2u * (j
+ fftLenBy2
)] = in
;
101 /* pSrc[i+2u] <-> pSrc[j+2u] */
102 in
= pSrc
[(2u * (i
+ 1u)) + 1u];
103 pSrc
[(2u * (i
+ 1u)) + 1u] = pSrc
[(2u * (j
+ fftLenBy2
)) + 1u];
104 pSrc
[(2u * (j
+ fftLenBy2
)) + 1u] = in
;
106 /* Reading the index for the bit reversal */
109 /* Updating the bit reversal index depending on the fft length */
110 pBitRevTab
+= bitRevFactor
;
117 * @brief In-place bit reversal function.
118 * @param[in, out] *pSrc points to the in-place buffer of Q31 data type.
119 * @param[in] fftLen length of the FFT.
120 * @param[in] bitRevFactor bit reversal modifier that supports different size FFTs with the same bit reversal table
121 * @param[in] *pBitRevTab points to bit reversal table.
125 void arm_bitreversal_q31(
128 uint16_t bitRevFactor
,
129 uint16_t * pBitRevTable
)
131 uint32_t fftLenBy2
, fftLenBy2p1
, i
, j
;
134 /* Initializations */
136 fftLenBy2
= fftLen
/ 2u;
137 fftLenBy2p1
= (fftLen
/ 2u) + 1u;
139 /* Bit Reversal Implementation */
140 for (i
= 0u; i
<= (fftLenBy2
- 2u); i
+= 2u)
144 /* pSrc[i] <-> pSrc[j]; */
146 pSrc
[2u * i
] = pSrc
[2u * j
];
149 /* pSrc[i+1u] <-> pSrc[j+1u] */
150 in
= pSrc
[(2u * i
) + 1u];
151 pSrc
[(2u * i
) + 1u] = pSrc
[(2u * j
) + 1u];
152 pSrc
[(2u * j
) + 1u] = in
;
154 /* pSrc[i+fftLenBy2p1] <-> pSrc[j+fftLenBy2p1] */
155 in
= pSrc
[2u * (i
+ fftLenBy2p1
)];
156 pSrc
[2u * (i
+ fftLenBy2p1
)] = pSrc
[2u * (j
+ fftLenBy2p1
)];
157 pSrc
[2u * (j
+ fftLenBy2p1
)] = in
;
159 /* pSrc[i+fftLenBy2p1+1u] <-> pSrc[j+fftLenBy2p1+1u] */
160 in
= pSrc
[(2u * (i
+ fftLenBy2p1
)) + 1u];
161 pSrc
[(2u * (i
+ fftLenBy2p1
)) + 1u] =
162 pSrc
[(2u * (j
+ fftLenBy2p1
)) + 1u];
163 pSrc
[(2u * (j
+ fftLenBy2p1
)) + 1u] = in
;
167 /* pSrc[i+1u] <-> pSrc[j+1u] */
168 in
= pSrc
[2u * (i
+ 1u)];
169 pSrc
[2u * (i
+ 1u)] = pSrc
[2u * (j
+ fftLenBy2
)];
170 pSrc
[2u * (j
+ fftLenBy2
)] = in
;
172 /* pSrc[i+2u] <-> pSrc[j+2u] */
173 in
= pSrc
[(2u * (i
+ 1u)) + 1u];
174 pSrc
[(2u * (i
+ 1u)) + 1u] = pSrc
[(2u * (j
+ fftLenBy2
)) + 1u];
175 pSrc
[(2u * (j
+ fftLenBy2
)) + 1u] = in
;
177 /* Reading the index for the bit reversal */
180 /* Updating the bit reversal index depending on the fft length */
181 pBitRevTable
+= bitRevFactor
;
188 * @brief In-place bit reversal function.
189 * @param[in, out] *pSrc points to the in-place buffer of Q15 data type.
190 * @param[in] fftLen length of the FFT.
191 * @param[in] bitRevFactor bit reversal modifier that supports different size FFTs with the same bit reversal table
192 * @param[in] *pBitRevTab points to bit reversal table.
196 void arm_bitreversal_q15(
199 uint16_t bitRevFactor
,
200 uint16_t * pBitRevTab
)
202 q31_t
*pSrc
= (q31_t
*) pSrc16
;
204 uint32_t fftLenBy2
, fftLenBy2p1
;
207 /* Initializations */
209 fftLenBy2
= fftLen
/ 2u;
210 fftLenBy2p1
= (fftLen
/ 2u) + 1u;
212 /* Bit Reversal Implementation */
213 for (i
= 0u; i
<= (fftLenBy2
- 2u); i
+= 2u)
217 /* pSrc[i] <-> pSrc[j]; */
218 /* pSrc[i+1u] <-> pSrc[j+1u] */
223 /* pSrc[i + fftLenBy2p1] <-> pSrc[j + fftLenBy2p1]; */
224 /* pSrc[i + fftLenBy2p1+1u] <-> pSrc[j + fftLenBy2p1+1u] */
225 in
= pSrc
[i
+ fftLenBy2p1
];
226 pSrc
[i
+ fftLenBy2p1
] = pSrc
[j
+ fftLenBy2p1
];
227 pSrc
[j
+ fftLenBy2p1
] = in
;
230 /* pSrc[i+1u] <-> pSrc[j+fftLenBy2]; */
231 /* pSrc[i+2] <-> pSrc[j+fftLenBy2+1u] */
233 pSrc
[i
+ 1u] = pSrc
[j
+ fftLenBy2
];
234 pSrc
[j
+ fftLenBy2
] = in
;
236 /* Reading the index for the bit reversal */
239 /* Updating the bit reversal index depending on the fft length */
240 pBitRevTab
+= bitRevFactor
;