FreeCalypso > hg > gsm-codec-lib
annotate libtwamr/r_fft.c @ 412:810ac4b99025
libtwamr: integrate VAD2 r_fft.c
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 07 May 2024 01:22:02 +0000 |
parents | |
children |
rev | line source |
---|---|
412
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 ***************************************************************************** |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * R99 Version 3.3.0 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * REL-4 Version 4.1.0 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 * |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 ***************************************************************************** |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 * |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 * File : r_fft.c |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 * Purpose : Fast Fourier Transform (FFT) algorithm |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 * |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 ***************************************************************************** |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 */ |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 /***************************************************************** |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 * |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 * This is an implementation of decimation-in-time FFT algorithm for |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 * real sequences. The techniques used here can be found in several |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 * books, e.g., i) Proakis and Manolakis, "Digital Signal Processing", |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 * 2nd Edition, Chapter 9, and ii) W.H. Press et. al., "Numerical |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 * Recipes in C", 2nd Ediiton, Chapter 12. |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 * |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 * Input - There is one input to this function: |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 * |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 * 1) An integer pointer to the input data array |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 * |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 * Output - There is no return value. |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 * The input data are replaced with transformed data. If the |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 * input is a real time domain sequence, it is replaced with |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 * the complex FFT for positive frequencies. The FFT value |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 * for DC and the foldover frequency are combined to form the |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 * first complex number in the array. The remaining complex |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 * numbers correspond to increasing frequencies. If the input |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 * is a complex frequency domain sequence arranged as above, |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 * it is replaced with the corresponding time domain sequence. |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 * |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 * Notes: |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 * |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 * 1) This function is designed to be a part of a VAD |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 * algorithm that requires 128-point FFT of real |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 * sequences. This is achieved here through a 64-point |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 * complex FFT. Consequently, the FFT size information is |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 * not transmitted explicitly. However, some flexibility |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 * is provided in the function to change the size of the |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 * FFT by specifying the size information through "define" |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 * statements. |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 * |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 * 2) The values of the complex sinusoids used in the FFT |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 * algorithm are stored in a ROM table. |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 * |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 * 3) In the c_fft function, the FFT values are divided by |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 * 2 after each stage of computation thus dividing the |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 * final FFT values by 64. This is somewhat different |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 * from the usual definition of FFT where the factor 1/N, |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 * i.e., 1/64, used for the IFFT and not the FFT. No factor |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 * is used in the r_fft function. |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 * |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 *****************************************************************/ |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 #include "tw_amr.h" |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 #include "namespace.h" |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 #include "typedef.h" |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 #include "cnst.h" |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 #include "basic_op.h" |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 #include "oper_32b.h" |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 #include "no_count.h" |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 #include "vad2.h" |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 #define SIZE 128 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 #define SIZE_BY_TWO 64 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 #define NUM_STAGE 6 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 #define TRUE 1 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 #define FALSE 0 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 static const Word16 phs_tbl[] = |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 { |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 32767, 0, 32729, -1608, 32610, -3212, 32413, -4808, |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 32138, -6393, 31786, -7962, 31357, -9512, 30853, -11039, |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 30274, -12540, 29622, -14010, 28899, -15447, 28106, -16846, |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 27246, -18205, 26320, -19520, 25330, -20788, 24279, -22006, |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 23170, -23170, 22006, -24279, 20788, -25330, 19520, -26320, |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 18205, -27246, 16846, -28106, 15447, -28899, 14010, -29622, |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 12540, -30274, 11039, -30853, 9512, -31357, 7962, -31786, |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 6393, -32138, 4808, -32413, 3212, -32610, 1608, -32729, |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 0, -32768, -1608, -32729, -3212, -32610, -4808, -32413, |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 -6393, -32138, -7962, -31786, -9512, -31357, -11039, -30853, |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 -12540, -30274, -14010, -29622, -15447, -28899, -16846, -28106, |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 -18205, -27246, -19520, -26320, -20788, -25330, -22006, -24279, |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 -23170, -23170, -24279, -22006, -25330, -20788, -26320, -19520, |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 -27246, -18205, -28106, -16846, -28899, -15447, -29622, -14010, |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 -30274, -12540, -30853, -11039, -31357, -9512, -31786, -7962, |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 -32138, -6393, -32413, -4808, -32610, -3212, -32729, -1608 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 }; |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 static const Word16 ii_table[] = |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 {SIZE / 2, SIZE / 4, SIZE / 8, SIZE / 16, SIZE / 32, SIZE / 64}; |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 /* FFT function for complex sequences */ |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 /* |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 * The decimation-in-time complex FFT is implemented below. |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 * The input complex numbers are presented as real part followed by |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 * imaginary part for each sample. The counters are therefore |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 * incremented by two to access the complex valued samples. |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 */ |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 static void c_fft(Word16 * farray_ptr) |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 { |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 Word16 i, j, k, ii, jj, kk, ji, kj, ii2; |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 Word32 ftmp, ftmp_real, ftmp_imag; |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 Word16 tmp, tmp1, tmp2; |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 /* Rearrange the input array in bit reversed order */ |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 for (i = 0, j = 0; i < SIZE - 2; i = i + 2) |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 { test(); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 if (sub(j, i) > 0) |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 { |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 ftmp = *(farray_ptr + i); move16(); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 *(farray_ptr + i) = *(farray_ptr + j); move16(); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 *(farray_ptr + j) = ftmp; move16(); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 ftmp = *(farray_ptr + i + 1); move16(); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 *(farray_ptr + i + 1) = *(farray_ptr + j + 1); move16(); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 *(farray_ptr + j + 1) = ftmp; move16(); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 } |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 k = SIZE_BY_TWO; move16(); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 test(); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 while (sub(j, k) >= 0) |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 { |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 j = sub(j, k); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 k = shr(k, 1); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 } |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 j = add(j, k); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 } |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 /* The FFT part */ |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 for (i = 0; i < NUM_STAGE; i++) |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 { /* i is stage counter */ |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 jj = shl(2, i); /* FFT size */ |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 kk = shl(jj, 1); /* 2 * FFT size */ |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 ii = ii_table[i]; /* 2 * number of FFT's */ move16(); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 ii2 = shl(ii, 1); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 ji = 0; /* ji is phase table index */ move16(); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 for (j = 0; j < jj; j = j + 2) |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 { /* j is sample counter */ |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 for (k = j; k < SIZE; k = k + kk) |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 { /* k is butterfly top */ |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 kj = add(k, jj); /* kj is butterfly bottom */ |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 /* Butterfly computations */ |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 ftmp_real = L_mult(*(farray_ptr + kj), phs_tbl[ji]); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 ftmp_real = L_msu(ftmp_real, *(farray_ptr + kj + 1), phs_tbl[ji + 1]); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 ftmp_imag = L_mult(*(farray_ptr + kj + 1), phs_tbl[ji]); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 ftmp_imag = L_mac(ftmp_imag, *(farray_ptr + kj), phs_tbl[ji + 1]); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 tmp1 = round(ftmp_real); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 tmp2 = round(ftmp_imag); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 tmp = sub(*(farray_ptr + k), tmp1); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 *(farray_ptr + kj) = shr(tmp, 1); move16(); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 tmp = sub(*(farray_ptr + k + 1), tmp2); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 *(farray_ptr + kj + 1) = shr(tmp, 1); move16(); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 tmp = add(*(farray_ptr + k), tmp1); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 *(farray_ptr + k) = shr(tmp, 1); move16(); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 tmp = add(*(farray_ptr + k + 1), tmp2); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 *(farray_ptr + k + 1) = shr(tmp, 1); move16(); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 } |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 ji = add(ji, ii2); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 } |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 } |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 } /* end of c_fft () */ |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 void r_fft(Word16 * farray_ptr) |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 { |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 Word16 ftmp1_real, ftmp1_imag, ftmp2_real, ftmp2_imag; |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 Word32 Lftmp1_real, Lftmp1_imag; |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 Word16 i, j; |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 Word32 Ltmp1; |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 /* Perform the complex FFT */ |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 c_fft(farray_ptr); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 /* First, handle the DC and foldover frequencies */ |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 ftmp1_real = *farray_ptr; move16(); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 ftmp2_real = *(farray_ptr + 1); move16(); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 *farray_ptr = add(ftmp1_real, ftmp2_real); move16(); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 *(farray_ptr + 1) = sub(ftmp1_real, ftmp2_real); move16(); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 /* Now, handle the remaining positive frequencies */ |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 for (i = 2, j = SIZE - i; i <= SIZE_BY_TWO; i = i + 2, j = SIZE - i) |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 { |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 ftmp1_real = add(*(farray_ptr + i), *(farray_ptr + j)); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 ftmp1_imag = sub(*(farray_ptr + i + 1), *(farray_ptr + j + 1)); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 ftmp2_real = add(*(farray_ptr + i + 1), *(farray_ptr + j + 1)); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 ftmp2_imag = sub(*(farray_ptr + j), *(farray_ptr + i)); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 Lftmp1_real = L_deposit_h(ftmp1_real); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 Lftmp1_imag = L_deposit_h(ftmp1_imag); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 Ltmp1 = L_mac(Lftmp1_real, ftmp2_real, phs_tbl[i]); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 Ltmp1 = L_msu(Ltmp1, ftmp2_imag, phs_tbl[i + 1]); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 *(farray_ptr + i) = round(L_shr(Ltmp1, 1)); move16(); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
218 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 Ltmp1 = L_mac(Lftmp1_imag, ftmp2_imag, phs_tbl[i]); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
220 Ltmp1 = L_mac(Ltmp1, ftmp2_real, phs_tbl[i + 1]); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
221 *(farray_ptr + i + 1) = round(L_shr(Ltmp1, 1)); move16(); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
222 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
223 Ltmp1 = L_mac(Lftmp1_real, ftmp2_real, phs_tbl[j]); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
224 Ltmp1 = L_mac(Ltmp1, ftmp2_imag, phs_tbl[j + 1]); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
225 *(farray_ptr + j) = round(L_shr(Ltmp1, 1)); move16(); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
226 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
227 Ltmp1 = L_negate(Lftmp1_imag); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
228 Ltmp1 = L_msu(Ltmp1, ftmp2_imag, phs_tbl[j]); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
229 Ltmp1 = L_mac(Ltmp1, ftmp2_real, phs_tbl[j + 1]); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
230 *(farray_ptr + j + 1) = round(L_shr(Ltmp1, 1)); move16(); |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
231 |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
232 } |
810ac4b99025
libtwamr: integrate VAD2 r_fft.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
233 } /* end r_fft () */ |