diff options
author | Tom Rondeau <trondeau@vt.edu> | 2012-06-20 11:01:54 -0400 |
---|---|---|
committer | Tom Rondeau <trondeau@vt.edu> | 2012-06-20 22:08:52 -0400 |
commit | 958bc6f7365a19b42b0acc98e4c082eee6cf6e51 (patch) | |
tree | 82c68d92ba18cffc9f2c9c922c089192412c3861 | |
parent | 81bb55f3a7bb8f64c2bc75b02306700fb5b60a43 (diff) |
filter: adding set/get for phase of arb resampler.
-rw-r--r-- | gr-filter/include/filter/pfb_arb_resampler_ccf.h | 13 | ||||
-rw-r--r-- | gr-filter/include/filter/pfb_arb_resampler_fff.h | 13 | ||||
-rw-r--r-- | gr-filter/lib/pfb_arb_resampler_ccf_impl.cc | 41 | ||||
-rw-r--r-- | gr-filter/lib/pfb_arb_resampler_ccf_impl.h | 3 | ||||
-rw-r--r-- | gr-filter/lib/pfb_arb_resampler_fff_impl.cc | 21 | ||||
-rw-r--r-- | gr-filter/lib/pfb_arb_resampler_fff_impl.h | 3 |
6 files changed, 85 insertions, 9 deletions
diff --git a/gr-filter/include/filter/pfb_arb_resampler_ccf.h b/gr-filter/include/filter/pfb_arb_resampler_ccf.h index cf5fa4a3b7..397ac25ea5 100644 --- a/gr-filter/include/filter/pfb_arb_resampler_ccf.h +++ b/gr-filter/include/filter/pfb_arb_resampler_ccf.h @@ -129,7 +129,20 @@ namespace gr { */ virtual void print_taps() = 0; + /*! + * Sets the resampling rate of the block. + */ virtual void set_rate (float rate) = 0; + + /*! + * Sets the current phase offset in radians (0 to 2pi). + */ + virtual void set_phase(float ph) = 0; + + /*! + * Gets the current phase of the resampler in radians (2 to 2pi). + */ + virtual float phase() const = 0; }; } /* namespace filter */ diff --git a/gr-filter/include/filter/pfb_arb_resampler_fff.h b/gr-filter/include/filter/pfb_arb_resampler_fff.h index 2504c92ec2..b6623b028e 100644 --- a/gr-filter/include/filter/pfb_arb_resampler_fff.h +++ b/gr-filter/include/filter/pfb_arb_resampler_fff.h @@ -130,7 +130,20 @@ namespace gr { */ virtual void print_taps() = 0; + /*! + * Sets the resampling rate of the block. + */ virtual void set_rate (float rate) = 0; + + /*! + * Sets the current phase offset in radians (0 to 2pi). + */ + virtual void set_phase(float ph) = 0; + + /*! + * Gets the current phase of the resampler in radians (2 to 2pi). + */ + virtual float phase() const = 0; }; } /* namespace filter */ diff --git a/gr-filter/lib/pfb_arb_resampler_ccf_impl.cc b/gr-filter/lib/pfb_arb_resampler_ccf_impl.cc index bb0906aa54..5480366de2 100644 --- a/gr-filter/lib/pfb_arb_resampler_ccf_impl.cc +++ b/gr-filter/lib/pfb_arb_resampler_ccf_impl.cc @@ -78,10 +78,8 @@ namespace gr { } // Now, actually set the filters' taps - std::vector<float> dtaps; - create_diff_taps(taps, dtaps); - create_taps(taps, d_taps, d_filters); - create_taps(dtaps, d_dtaps, d_diff_filters); + set_taps(taps); + d_updated = false; } pfb_arb_resampler_ccf_impl::~pfb_arb_resampler_ccf_impl() @@ -122,11 +120,6 @@ namespace gr { // Build a filter for each channel and add it's taps to it ourfilter[i]->set_taps(ourtaps[d_int_rate-1-i]); } - - // Set the history to ensure enough input items for each filter - set_history (d_taps_per_filter + 1); - - d_updated = true; } void @@ -148,6 +141,13 @@ namespace gr { pfb_arb_resampler_ccf_impl::set_taps(const std::vector<float> &taps) { gruel::scoped_lock guard(d_mutex); + + std::vector<float> dtaps; + create_diff_taps(taps, dtaps); + create_taps(taps, d_taps, d_filters); + create_taps(dtaps, d_dtaps, d_diff_filters); + set_history(d_taps_per_filter + 1); + d_updated = true; } std::vector<std::vector<float> > @@ -172,17 +172,40 @@ namespace gr { void pfb_arb_resampler_ccf_impl::set_rate(float rate) { + gruel::scoped_lock guard(d_mutex); + d_dec_rate = (unsigned int)floor(d_int_rate/rate); d_flt_rate = (d_int_rate/rate) - d_dec_rate; set_relative_rate(rate); } + void + pfb_arb_resampler_ccf_impl::set_phase(float ph) + { + gruel::scoped_lock guard(d_mutex); + if((ph < 0) || (ph >= 2.0*M_PI)) { + throw std::runtime_error("pfb_arb_resampler_ccf: set_phase value out of bounds [0, 2pi).\n"); + } + + float ph_diff = 2.0*M_PI / (float)d_filters.size(); + d_last_filter = static_cast<int>(ph / ph_diff); + } + + float + pfb_arb_resampler_ccf_impl::phase() const + { + float ph_diff = 2.0*M_PI / static_cast<float>(d_filters.size()); + return d_last_filter * ph_diff; + } + int pfb_arb_resampler_ccf_impl::general_work(int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { + gruel::scoped_lock guard(d_mutex); + gr_complex *in = (gr_complex*)input_items[0]; gr_complex *out = (gr_complex*)output_items[0]; diff --git a/gr-filter/lib/pfb_arb_resampler_ccf_impl.h b/gr-filter/lib/pfb_arb_resampler_ccf_impl.h index 8e7e993cb7..891e601e09 100644 --- a/gr-filter/lib/pfb_arb_resampler_ccf_impl.h +++ b/gr-filter/lib/pfb_arb_resampler_ccf_impl.h @@ -74,6 +74,9 @@ namespace gr { void print_taps(); void set_rate(float rate); + void set_phase(float ph); + float phase() const; + int general_work(int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, diff --git a/gr-filter/lib/pfb_arb_resampler_fff_impl.cc b/gr-filter/lib/pfb_arb_resampler_fff_impl.cc index 79c19655a3..6aff374fdd 100644 --- a/gr-filter/lib/pfb_arb_resampler_fff_impl.cc +++ b/gr-filter/lib/pfb_arb_resampler_fff_impl.cc @@ -172,11 +172,32 @@ namespace gr { void pfb_arb_resampler_fff_impl::set_rate(float rate) { + gruel::scoped_lock guard(d_mutex); + d_dec_rate = (unsigned int)floor(d_int_rate/rate); d_flt_rate = (d_int_rate/rate) - d_dec_rate; set_relative_rate(rate); } + void + pfb_arb_resampler_fff_impl::set_phase(float ph) + { + gruel::scoped_lock guard(d_mutex); + if((ph < 0) || (ph >= 2.0*M_PI)) { + throw std::runtime_error("pfb_arb_resampler_ccf: set_phase value out of bounds [0, 2pi).\n"); + } + + float ph_diff = 2.0*M_PI / (float)d_filters.size(); + d_last_filter = static_cast<int>(ph / ph_diff); + } + + float + pfb_arb_resampler_fff_impl::phase() const + { + float ph_diff = 2.0*M_PI / static_cast<float>(d_filters.size()); + return d_last_filter * ph_diff; + } + int pfb_arb_resampler_fff_impl::general_work(int noutput_items, gr_vector_int &ninput_items, diff --git a/gr-filter/lib/pfb_arb_resampler_fff_impl.h b/gr-filter/lib/pfb_arb_resampler_fff_impl.h index 54e01375ac..5889627114 100644 --- a/gr-filter/lib/pfb_arb_resampler_fff_impl.h +++ b/gr-filter/lib/pfb_arb_resampler_fff_impl.h @@ -73,6 +73,9 @@ namespace gr { void print_taps(); void set_rate(float rate); + void set_phase(float ph); + float phase() const; + int general_work(int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, |