summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_ccf.cc34
-rw-r--r--gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_ccf.h11
2 files changed, 19 insertions, 26 deletions
diff --git a/gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_ccf.cc b/gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_ccf.cc
index e9545549f..55e316d02 100644
--- a/gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_ccf.cc
+++ b/gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_ccf.cc
@@ -23,8 +23,8 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+
#include <gri_fir_filter_with_buffer_ccf.h>
-#include <cstdio>
gri_fir_filter_with_buffer_ccf::gri_fir_filter_with_buffer_ccf(const std::vector<float> &taps)
{
@@ -34,42 +34,30 @@ gri_fir_filter_with_buffer_ccf::gri_fir_filter_with_buffer_ccf(const std::vector
gri_fir_filter_with_buffer_ccf::~gri_fir_filter_with_buffer_ccf()
{
- free(d_buffer);
+ if(d_buffer != NULL)
+ free(d_buffer);
}
gr_complex
gri_fir_filter_with_buffer_ccf::filter (gr_complex input)
{
-#if 0
- unsigned int i;
-
- for(i = ntaps()-1; i > 0; i--) {
- d_buffer[i] = d_buffer[i-1];
- }
- d_buffer[0] = input;
-
- gr_complex out = d_buffer[0]*d_taps[0];
- for(i = 1; i < ntaps(); i++) {
- out += d_buffer[i]*d_taps[i];
- }
- return out;
-
-#else
unsigned int i;
d_buffer[d_idx] = input;
d_buffer[d_idx+ntaps()] = input;
+
+ // using the later for the case when ntaps=0;
+ // profiling shows this doesn't make a difference
//d_idx = (d_idx + 1) % ntaps();
d_idx++;
- if(d_idx == ntaps())
+ if(d_idx >= ntaps())
d_idx = 0;
- gr_complex out = d_buffer[d_idx]*d_taps[0];
- for(i = 1; i < ntaps(); i++) {
+ gr_complex out = gr_complex(0,0);
+ for(i = 0; i < ntaps(); i++) {
out += d_buffer[d_idx + i]*d_taps[i];
}
return out;
-#endif
}
void
@@ -77,5 +65,7 @@ gri_fir_filter_with_buffer_ccf::filterN (gr_complex output[],
const gr_complex input[],
unsigned long n)
{
-
+ for(unsigned long i = 0; i < n; i++) {
+ output[i] = filter(input[i]);
+ }
}
diff --git a/gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_ccf.h b/gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_ccf.h
index 5adc3e231..c91d70534 100644
--- a/gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_ccf.h
+++ b/gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_ccf.h
@@ -33,6 +33,7 @@
#include <gr_types.h>
#include <gr_reverse.h>
#include <string.h>
+#include <cstdio>
/*!
* \brief FIR with internal buffer for gr_complex input,
@@ -100,14 +101,16 @@ public:
void set_taps (const std::vector<float> &taps)
{
d_taps = gr_reverse(taps);
- //d_taps = (taps);
- if(d_buffer != NULL)
+ if(d_buffer != NULL) {
free(d_buffer);
+ d_buffer = NULL;
+ }
// FIXME: memalign this to 16-byte boundaries for SIMD later
- d_buffer = (gr_complex*)malloc(sizeof(gr_complex) * 2 * d_taps.size());
- memset(d_buffer, 0x00, sizeof(gr_complex) * 2 * d_taps.size());
+ size_t t = sizeof(gr_complex) * 2 * d_taps.size();
+ d_buffer = (gr_complex*)malloc(t);
+ memset(d_buffer, 0x00, t);
d_idx = 0;
}