diff options
author | Tom Rondeau | 2012-06-22 20:08:06 -0400 |
---|---|---|
committer | Tom Rondeau | 2012-06-22 20:08:06 -0400 |
commit | c94ddc5e0c08693c023c099bd8946ca6e143f471 (patch) | |
tree | f485f5fa62b6d815b58fa9cd60d5a9d7e2384007 | |
parent | 81589710a52c0e1b087f28ac54e83b9cbfa477d1 (diff) | |
download | gnuradio-c94ddc5e0c08693c023c099bd8946ca6e143f471.tar.gz gnuradio-c94ddc5e0c08693c023c099bd8946ca6e143f471.tar.bz2 gnuradio-c94ddc5e0c08693c023c099bd8946ca6e143f471.zip |
filter: fixed fir_filter_with_buffer to make sure nothing that volk looks at could be improperly set.
This fixed issues with qa_fir_filter_with_buffer.
-rw-r--r-- | gr-filter/include/filter/fir_filter_with_buffer.h | 3 | ||||
-rw-r--r-- | gr-filter/lib/fir_filter_with_buffer.cc | 75 | ||||
-rw-r--r-- | gr-filter/lib/qa_fir_filter_with_buffer.cc | 2 |
3 files changed, 52 insertions, 28 deletions
diff --git a/gr-filter/include/filter/fir_filter_with_buffer.h b/gr-filter/include/filter/fir_filter_with_buffer.h index 8b5d9e064..007eae3fa 100644 --- a/gr-filter/include/filter/fir_filter_with_buffer.h +++ b/gr-filter/include/filter/fir_filter_with_buffer.h @@ -40,6 +40,7 @@ namespace gr { private: std::vector<float> d_taps; unsigned int d_ntaps; + float *d_buffer_ptr; float *d_buffer; unsigned int d_idx; float **d_aligned_taps; @@ -136,6 +137,7 @@ namespace gr { private: std::vector<gr_complex> d_taps; unsigned int d_ntaps; + gr_complex *d_buffer_ptr; gr_complex *d_buffer; unsigned int d_idx; gr_complex **d_aligned_taps; @@ -232,6 +234,7 @@ namespace gr { private: std::vector<float> d_taps; unsigned int d_ntaps; + gr_complex *d_buffer_ptr; gr_complex *d_buffer; unsigned int d_idx; float **d_aligned_taps; diff --git a/gr-filter/lib/fir_filter_with_buffer.cc b/gr-filter/lib/fir_filter_with_buffer.cc index 105214087..7a35a9225 100644 --- a/gr-filter/lib/fir_filter_with_buffer.cc +++ b/gr-filter/lib/fir_filter_with_buffer.cc @@ -40,7 +40,7 @@ namespace gr { d_align = volk_get_alignment(); d_naligned = d_align / sizeof(float); - d_buffer = NULL; + d_buffer_ptr = NULL; d_aligned_taps = NULL; set_taps(taps); @@ -50,9 +50,9 @@ namespace gr { fir_filter_with_buffer_fff::~fir_filter_with_buffer_fff() { - if(d_buffer != NULL) { - fft::free(d_buffer); - d_buffer = NULL; + if(d_buffer_ptr != NULL) { + fft::free(d_buffer_ptr); + d_buffer_ptr = NULL; } // Free aligned taps @@ -71,9 +71,9 @@ namespace gr { void fir_filter_with_buffer_fff::set_taps(const std::vector<float> &taps) { - if(d_buffer != NULL) { - fft::free(d_buffer); - d_buffer = NULL; + if(d_buffer_ptr != NULL) { + fft::free(d_buffer_ptr); + d_buffer_ptr = NULL; } // Free the taps if already allocated @@ -89,8 +89,15 @@ namespace gr { d_taps = taps; std::reverse(d_taps.begin(), d_taps.end()); - d_buffer = fft::malloc_float(2*d_ntaps); - memset(d_buffer, 0, 2*d_ntaps*sizeof(float)); + // We allocate enough to be able to look back and forth + // d_naligned beyond the buffer boundaries and make sure these + // are zeroed out (or they may be nan, which will cause + // problems). We then set d_buffer to the position in the + // d_buffer_ptr such that we only touch the internally + // allocated space. + d_buffer_ptr = fft::malloc_float(2*(d_ntaps + d_naligned)); + memset(d_buffer_ptr, 0, 2*(d_ntaps + d_naligned)*sizeof(float)); + d_buffer = d_buffer_ptr + d_naligned; // Allocate aligned taps d_aligned_taps = (float**)malloc(d_naligned*sizeof(float**)); @@ -186,7 +193,7 @@ namespace gr { d_align = volk_get_alignment(); d_naligned = d_align / sizeof(gr_complex); - d_buffer = NULL; + d_buffer_ptr = NULL; d_aligned_taps = NULL; set_taps(taps); @@ -196,9 +203,9 @@ namespace gr { fir_filter_with_buffer_ccc::~fir_filter_with_buffer_ccc() { - if(d_buffer != NULL) { - fft::free(d_buffer); - d_buffer = NULL; + if(d_buffer_ptr != NULL) { + fft::free(d_buffer_ptr); + d_buffer_ptr = NULL; } // Free aligned taps @@ -217,9 +224,9 @@ namespace gr { void fir_filter_with_buffer_ccc::set_taps(const std::vector<gr_complex> &taps) { - if(d_buffer != NULL) { - fft::free(d_buffer); - d_buffer = NULL; + if(d_buffer_ptr != NULL) { + fft::free(d_buffer_ptr); + d_buffer_ptr = NULL; } // Free the taps if already allocated @@ -235,8 +242,15 @@ namespace gr { d_taps = taps; std::reverse(d_taps.begin(), d_taps.end()); - d_buffer = fft::malloc_complex(2*d_ntaps); - memset(d_buffer, 0, 2*d_ntaps*sizeof(gr_complex)); + // We allocate enough to be able to look back and forth + // d_naligned beyond the buffer boundaries and make sure these + // are zeroed out (or they may be nan, which will cause + // problems). We then set d_buffer to the position in the + // d_buffer_ptr such that we only touch the internally + // allocated space. + d_buffer_ptr = fft::malloc_complex(2*(d_ntaps + d_naligned)); + memset(d_buffer_ptr, 0, 2*(d_ntaps + d_naligned)*sizeof(gr_complex)); + d_buffer = d_buffer_ptr + d_naligned; // Allocate aligned taps d_aligned_taps = (gr_complex**)malloc(d_naligned*sizeof(gr_complex**)); @@ -332,7 +346,7 @@ namespace gr { d_align = volk_get_alignment(); d_naligned = d_align / sizeof(gr_complex); - d_buffer = NULL; + d_buffer_ptr = NULL; d_aligned_taps = NULL; set_taps(taps); @@ -342,9 +356,9 @@ namespace gr { fir_filter_with_buffer_ccf::~fir_filter_with_buffer_ccf() { - if(d_buffer != NULL) { - fft::free(d_buffer); - d_buffer = NULL; + if(d_buffer_ptr != NULL) { + fft::free(d_buffer_ptr); + d_buffer_ptr = NULL; } // Free aligned taps @@ -363,9 +377,9 @@ namespace gr { void fir_filter_with_buffer_ccf::set_taps(const std::vector<float> &taps) { - if(d_buffer != NULL) { - fft::free(d_buffer); - d_buffer = NULL; + if(d_buffer_ptr != NULL) { + fft::free(d_buffer_ptr); + d_buffer_ptr = NULL; } // Free the taps if already allocated @@ -381,8 +395,15 @@ namespace gr { d_taps = taps; std::reverse(d_taps.begin(), d_taps.end()); - d_buffer = fft::malloc_complex(2*d_ntaps); - memset(d_buffer, 0, 2*d_ntaps*sizeof(gr_complex)); + // We allocate enough to be able to look back and forth + // d_naligned beyond the buffer boundaries and make sure these + // are zeroed out (or they may be nan, which will cause + // problems). We then set d_buffer to the position in the + // d_buffer_ptr such that we only touch the internally + // allocated space. + d_buffer_ptr = fft::malloc_complex(2*(d_ntaps + d_naligned)); + memset(d_buffer_ptr, 0, 2*(d_ntaps + d_naligned)*sizeof(gr_complex)); + d_buffer = d_buffer_ptr + d_naligned; // Allocate aligned taps d_aligned_taps = (float**)malloc(d_naligned*sizeof(float**)); diff --git a/gr-filter/lib/qa_fir_filter_with_buffer.cc b/gr-filter/lib/qa_fir_filter_with_buffer.cc index eaa0359d0..6a1744b0a 100644 --- a/gr-filter/lib/qa_fir_filter_with_buffer.cc +++ b/gr-filter/lib/qa_fir_filter_with_buffer.cc @@ -146,7 +146,7 @@ namespace gr { new kernel::fir_filter_with_buffer_fff(f1_taps); // zero the output, then do the filtering - memset(actual_output, 0, sizeof(actual_output)); + memset(actual_output, 0, OUTPUT_LEN*sizeof(o_type)); f1->filterNdec(actual_output, input, ol/decimate, decimate); // check results |