Adding SSE version of fft filters. Complex (ccc) version working.
[debian/gnuradio] / gnuradio-core / src / lib / filter / gr_fft_filter_fff.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2005,2010 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
18  * along with GNU Radio; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include <gr_fft_filter_fff.h>
28 #include <gri_fft_filter_fff_generic.h>
29 #include <gr_io_signature.h>
30 #include <assert.h>
31 #include <stdexcept>
32
33 #include <cstdio>
34 #include <iostream>
35 #include <string.h>
36
37 gr_fft_filter_fff_sptr gr_make_fft_filter_fff (int decimation, const std::vector<float> &taps)
38 {
39   return gr_fft_filter_fff_sptr (new gr_fft_filter_fff (decimation, taps));
40 }
41
42
43 gr_fft_filter_fff::gr_fft_filter_fff (int decimation, const std::vector<float> &taps)
44   : gr_sync_decimator ("fft_filter_fff",
45                        gr_make_io_signature (1, 1, sizeof (float)),
46                        gr_make_io_signature (1, 1, sizeof (float)),
47                        decimation),
48     d_updated(false)
49 {
50   set_history(1);
51
52   d_filter = new gri_fft_filter_fff_generic(decimation, taps);
53   d_nsamples = d_filter->set_taps(taps);
54   set_output_multiple(d_nsamples);
55 }
56
57 gr_fft_filter_fff::~gr_fft_filter_fff ()
58 {
59   delete d_filter;
60 }
61
62 void
63 gr_fft_filter_fff::set_taps (const std::vector<float> &taps)
64 {
65   d_new_taps = taps;
66   d_updated = true;
67 }
68
69 int
70 gr_fft_filter_fff::work (int noutput_items,
71                          gr_vector_const_void_star &input_items,
72                          gr_vector_void_star &output_items)
73 {
74   const float *in = (const float *) input_items[0];
75   float *out = (float *) output_items[0];
76
77   if (d_updated){
78     d_nsamples = d_filter->set_taps(d_new_taps);
79     d_updated = false;
80     set_output_multiple(d_nsamples);
81     return 0;                           // output multiple may have changed
82   }
83
84   assert(noutput_items % d_nsamples == 0);
85   
86   d_filter->filter(noutput_items, in, out);
87
88   //assert((out - (float *) output_items[0]) == noutput_items);
89
90   return noutput_items;
91 }