e8857fe8cfbd5d45fdfed39bbc95cd6c85e21f47
[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 <gri_fft_filter_fff_sse.h>
30 #include <gr_io_signature.h>
31 #include <assert.h>
32 #include <stdexcept>
33
34 #include <cstdio>
35 #include <iostream>
36 #include <string.h>
37
38 gr_fft_filter_fff_sptr gr_make_fft_filter_fff (int decimation, const std::vector<float> &taps)
39 {
40   return gr_fft_filter_fff_sptr (new gr_fft_filter_fff (decimation, taps));
41 }
42
43
44 gr_fft_filter_fff::gr_fft_filter_fff (int decimation, const std::vector<float> &taps)
45   : gr_sync_decimator ("fft_filter_fff",
46                        gr_make_io_signature (1, 1, sizeof (float)),
47                        gr_make_io_signature (1, 1, sizeof (float)),
48                        decimation),
49     d_updated(false)
50 {
51   set_history(1);
52   
53 #if 1 // don't enable the sse version until handling it is worked out
54     d_filter = new gri_fft_filter_fff_generic(decimation, taps);
55 #else
56     d_filter = new gri_fft_filter_fff_sse(decimation, taps);
57 #endif
58
59   d_nsamples = d_filter->set_taps(taps);
60   set_output_multiple(d_nsamples);
61 }
62
63 gr_fft_filter_fff::~gr_fft_filter_fff ()
64 {
65   delete d_filter;
66 }
67
68 void
69 gr_fft_filter_fff::set_taps (const std::vector<float> &taps)
70 {
71   d_new_taps = taps;
72   d_updated = true;
73 }
74
75 int
76 gr_fft_filter_fff::work (int noutput_items,
77                          gr_vector_const_void_star &input_items,
78                          gr_vector_void_star &output_items)
79 {
80   const float *in = (const float *) input_items[0];
81   float *out = (float *) output_items[0];
82
83   if (d_updated){
84     d_nsamples = d_filter->set_taps(d_new_taps);
85     d_updated = false;
86     set_output_multiple(d_nsamples);
87     return 0;                           // output multiple may have changed
88   }
89
90   assert(noutput_items % d_nsamples == 0);
91   
92   d_filter->filter(noutput_items, in, out);
93
94   //assert((out - (float *) output_items[0]) == noutput_items);
95
96   return noutput_items;
97 }