Imported Upstream version 3.2.2
[debian/gnuradio] / gcell / lib / wrapper / spu / gcs_fft_1d_r2.c
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2008 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #include <gcell/gc_declare_proc.h>
23 #include <gcell/spu/libfft.h>
24 #include <assert.h>
25
26 /*
27  * v is really vector complex<float>
28  */
29 static void
30 conjugate_vector(vector float *v, int nelements)
31 {
32   vector float k = {1, -1, 1, -1};
33   int i;
34   for (i = 0; i < nelements; i++)
35     v[i] *= k;
36 }
37
38 static void
39 gcs_fwd_fft_1d_r2(const gc_job_direct_args_t *input,
40                   gc_job_direct_args_t *output __attribute__((unused)),
41                   const gc_job_ea_args_t *eaa)
42 {
43   vector float *out = (vector float *) eaa->arg[0].ls_addr;     // complex
44   vector float *in = (vector float *) eaa->arg[1].ls_addr;      // complex
45   vector float *twiddle = (vector float *) eaa->arg[2].ls_addr; // complex
46   vector float *window = (vector float *) eaa->arg[3].ls_addr;  // float
47
48   int log2_fft_length = input->arg[0].u32;
49   int shift = input->arg[1].u32;        // non-zero if we should apply fftshift
50
51   if (eaa->arg[3].get_size){    // apply window
52     // FIXME pointwise multiply in *= window
53     assert(0);
54   }
55
56   fft_1d_r2(out, in, twiddle, log2_fft_length);
57
58   if (shift){
59     // FIXME apply "fftshift" to output data in-place
60     assert(0);
61   }
62 }
63
64 GC_DECLARE_PROC(gcs_fwd_fft_1d_r2, "fwd_fft_1d_r2");
65
66 static void
67 gcs_inv_fft_1d_r2(const gc_job_direct_args_t *input,
68                   gc_job_direct_args_t *output __attribute__((unused)),
69                   const gc_job_ea_args_t *eaa)
70 {
71   vector float *out = (vector float *) eaa->arg[0].ls_addr;     // complex
72   vector float *in = (vector float *) eaa->arg[1].ls_addr;      // complex
73   vector float *twiddle = (vector float *) eaa->arg[2].ls_addr; // complex
74   vector float *window = (vector float *) eaa->arg[3].ls_addr;  // float
75
76   int log2_fft_length = input->arg[0].u32;
77   int shift = input->arg[1].u32;        // non-zero if we should apply fftshift
78
79   if (eaa->arg[3].get_size){    // apply window
80     // FIXME pointwise multiply in *= window
81     assert(0);
82   }
83
84   if (shift){
85     // FIXME apply "fftshift" to input data in-place
86     assert(0);
87   }
88
89   conjugate_vector(in, 1 << (log2_fft_length - 1));
90   fft_1d_r2(out, in, twiddle, log2_fft_length);
91   conjugate_vector(out, 1 << (log2_fft_length - 1));
92 }
93
94 GC_DECLARE_PROC(gcs_inv_fft_1d_r2, "inv_fft_1d_r2");