diff options
author | Tom Rondeau | 2011-04-06 17:10:16 -0400 |
---|---|---|
committer | Tom Rondeau | 2011-04-06 17:10:16 -0400 |
commit | 831134234e5ab6d3a29f21f89b338c9656328946 (patch) | |
tree | 2318091e9c4140952c8780130310ceec5f29c534 /gnuradio-core/src/lib | |
parent | b30c79326c3eedf5ebf20be62306f0511b98a0e7 (diff) | |
parent | eca5501969aa6175562b7e70b350cf3e6ddec603 (diff) | |
download | gnuradio-831134234e5ab6d3a29f21f89b338c9656328946.tar.gz gnuradio-831134234e5ab6d3a29f21f89b338c9656328946.tar.bz2 gnuradio-831134234e5ab6d3a29f21f89b338c9656328946.zip |
Merge branch 'master' into 8psk
Diffstat (limited to 'gnuradio-core/src/lib')
-rw-r--r-- | gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.h | 4 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_throttle.cc | 136 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_throttle.h | 33 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_throttle.i | 13 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_basic_block.h | 2 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_block.h | 2 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_sync_block.h | 2 |
7 files changed, 73 insertions, 119 deletions
diff --git a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.h b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.h index 4e6ef5fc4..684ac85ce 100644 --- a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.h +++ b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.h @@ -84,7 +84,7 @@ class gr_fir_ccf; * the block constructor, we just ask for "gain," which is d_alpha while d_beta is * equal to (gain^2)/4. * - * The clock sync block needs to know the number of samples per second (sps), because it + * The clock sync block needs to know the number of samples per symbol (sps), because it * only returns a single point representing the sample. The sps can be any positive real * number and does not need to be an integer. The filter taps must also be specified. The * taps are generated by first conceiving of the prototype filter that would be the signal's @@ -115,7 +115,7 @@ class gr_pfb_clock_sync_ccf : public gr_block private: /*! * Build the polyphase filterbank timing synchronizer. - * \param sps (double) The number of samples per second in the incoming signal + * \param sps (double) The number of samples per symbol in the incoming signal * \param gain (float) The alpha gain of the control loop; beta = (gain^2)/4 by default. * \param taps (vector<int>) The filter taps. * \param filter_size (uint) The number of filters in the filterbank (default = 32). diff --git a/gnuradio-core/src/lib/general/gr_throttle.cc b/gnuradio-core/src/lib/general/gr_throttle.cc index 3189e01c0..a24b1da8c 100644 --- a/gnuradio-core/src/lib/general/gr_throttle.cc +++ b/gnuradio-core/src/lib/general/gr_throttle.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2005,2010 Free Software Foundation, Inc. + * Copyright 2005-2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -26,92 +26,64 @@ #include <gr_throttle.h> #include <gr_io_signature.h> -#include <errno.h> -#include <stdio.h> -#include <math.h> -#include <string.h> -#ifdef HAVE_TIME_H -#include <time.h> -#endif -#if !defined(HAVE_NANOSLEEP) && defined(HAVE_SSLEEP) -#include <windows.h> -#endif - +#include <cstring> +#include <boost/thread/thread.hpp> -#ifdef HAVE_NANOSLEEP -void -gr_nanosleep(struct timespec *ts) -{ - struct timespec *req = ts; - struct timespec rem; - int r = nanosleep(req, &rem); - while (r < 0 && errno == EINTR){ - req = &rem; - r = nanosleep(req, &rem); - } - if (r < 0) - perror ("gr_nanosleep"); -} -#endif - -gr_throttle_sptr -gr_make_throttle(size_t itemsize, double samples_per_sec) -{ - return gnuradio::get_initial_sptr(new gr_throttle(itemsize, samples_per_sec)); -} +class gr_throttle_impl : public gr_throttle{ +public: + gr_throttle_impl(size_t itemsize): + gr_sync_block("throttle", + gr_make_io_signature(1, 1, itemsize), + gr_make_io_signature(1, 1, itemsize)), + d_itemsize(itemsize) + { + /* NOP */ + } -gr_throttle::gr_throttle(size_t itemsize, double samples_per_sec) - : gr_sync_block("throttle", - gr_make_io_signature(1, 1, itemsize), - gr_make_io_signature(1, 1, itemsize)), - d_itemsize(itemsize), d_samples_per_sec(samples_per_sec), - d_total_samples(0) -{ -#ifdef HAVE_GETTIMEOFDAY - gettimeofday(&d_start, 0); -#endif -} + void set_sample_rate(double rate){ + //changing the sample rate performs a reset of state params + d_start = boost::get_system_time(); + d_total_samples = 0; + d_samps_per_tick = rate/boost::posix_time::time_duration::ticks_per_second(); + d_samps_per_us = rate/1e6; + } -gr_throttle::~gr_throttle() -{ -} + int work ( + int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items + ){ + //calculate the expected number of samples to have passed through + boost::system_time now = boost::get_system_time(); + boost::int64_t ticks = (now - d_start).ticks(); + uint64_t expected_samps = uint64_t(d_samps_per_tick*ticks); -int -gr_throttle::work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) -{ - const char *in = (const char *) input_items[0]; - char *out = (char *) output_items[0]; + //if the expected samples was less, we need to throttle back + if (d_total_samples > expected_samps){ + boost::this_thread::sleep(boost::posix_time::microseconds( + long((d_total_samples - expected_samps)/d_samps_per_us) + )); + } -#if defined(HAVE_GETTIMEOFDAY) - // - // If our average sample rate exceeds our target sample rate, - // delay long enough to reduce to our target rate. - // - struct timeval now; - gettimeofday(&now, 0); - long t_usec = now.tv_usec - d_start.tv_usec; - long t_sec = now.tv_sec - d_start.tv_sec; - double t = (double)t_sec + (double)t_usec * 1e-6; - if (t < 1e-6) // avoid unlikely divide by zero - t = 1e-6; + //copy all samples output[i] <= input[i] + const char *in = (const char *) input_items[0]; + char *out = (char *) output_items[0]; + std::memcpy(out, in, noutput_items * d_itemsize); + d_total_samples += noutput_items; + return noutput_items; + } - double actual_samples_per_sec = d_total_samples / t; - if (actual_samples_per_sec > d_samples_per_sec){ // need to delay - double delay = d_total_samples / d_samples_per_sec - t; -#ifdef HAVE_NANOSLEEP - struct timespec ts; - ts.tv_sec = (time_t)floor(delay); - ts.tv_nsec = (long)((delay - floor(delay)) * 1e9); - gr_nanosleep(&ts); -#elif HAVE_SSLEEP - Sleep( (DWORD)(delay*1000) ); -#endif - } -#endif +private: + boost::system_time d_start; + size_t d_itemsize; + uint64_t d_total_samples; + double d_samps_per_tick, d_samps_per_us; +}; - memcpy(out, in, noutput_items * d_itemsize); - d_total_samples += noutput_items; - return noutput_items; +gr_throttle::sptr +gr_make_throttle(size_t itemsize, double samples_per_sec) +{ + gr_throttle::sptr throttle(new gr_throttle_impl(itemsize)); + throttle->set_sample_rate(samples_per_sec); + return throttle; } diff --git a/gnuradio-core/src/lib/general/gr_throttle.h b/gnuradio-core/src/lib/general/gr_throttle.h index a1c9773c9..a82821f77 100644 --- a/gnuradio-core/src/lib/general/gr_throttle.h +++ b/gnuradio-core/src/lib/general/gr_throttle.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2005 Free Software Foundation, Inc. + * Copyright 2005-2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -23,15 +23,6 @@ #define INCLUDED_GR_THROTTLE_H #include <gr_sync_block.h> -#ifdef HAVE_SYS_TIME_H -#include <sys/time.h> -#endif - -class gr_throttle; -typedef boost::shared_ptr<gr_throttle> gr_throttle_sptr; - - -gr_throttle_sptr gr_make_throttle(size_t itemsize, double samples_per_sec); /*! * \brief throttle flow of samples such that the average rate does not exceed samples_per_sec. @@ -44,25 +35,15 @@ gr_throttle_sptr gr_make_throttle(size_t itemsize, double samples_per_sec); * controlling the rate of samples. That should be controlled by a * source or sink tied to sample clock. E.g., a USRP or audio card. */ -class gr_throttle : public gr_sync_block +class gr_throttle : virtual public gr_sync_block { - friend gr_throttle_sptr gr_make_throttle(size_t itemsize, double samples_per_sec); - size_t d_itemsize; - double d_samples_per_sec; - double d_total_samples; -#ifdef HAVE_SYS_TIME_H - struct timeval d_start; -#endif - - gr_throttle(size_t itemsize, double samples_per_sec); - public: - ~gr_throttle(); + typedef boost::shared_ptr<gr_throttle> sptr; - int work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + //! Sets the sample rate in samples per second + virtual void set_sample_rate(double rate) = 0; }; - + +gr_throttle::sptr gr_make_throttle(size_t itemsize, double samples_per_sec); #endif /* INCLUDED_GR_THROTTLE_H */ diff --git a/gnuradio-core/src/lib/general/gr_throttle.i b/gnuradio-core/src/lib/general/gr_throttle.i index 21f7703ef..0b1ec165f 100644 --- a/gnuradio-core/src/lib/general/gr_throttle.i +++ b/gnuradio-core/src/lib/general/gr_throttle.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2005 Free Software Foundation, Inc. + * Copyright 2005-2011 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -20,11 +20,10 @@ * Boston, MA 02110-1301, USA. */ -GR_SWIG_BLOCK_MAGIC(gr,throttle); +%{ +#include <gr_throttle.h> +%} -gr_throttle_sptr gr_make_throttle (size_t itemsize, double samples_per_sec); +GR_SWIG_BLOCK_MAGIC(gr,throttle); -class gr_throttle : public gr_sync_block -{ - gr_throttle (size_t itemsize, double samples_per_sec); -}; +%include <gr_throttle.h> diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index ce7a1aa1d..3b0cd51dd 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -73,6 +73,8 @@ protected: long d_unique_id; vcolor d_color; + gr_basic_block(void){} //allows pure virtual interface sub-classes + //! Protected constructor prevents instantiation by non-derived classes gr_basic_block(const std::string &name, gr_io_signature_sptr input_signature, diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h index ad7fa9555..fc22f9ea8 100644 --- a/gnuradio-core/src/lib/runtime/gr_block.h +++ b/gnuradio-core/src/lib/runtime/gr_block.h @@ -236,7 +236,7 @@ class gr_block : public gr_basic_block { tag_propagation_policy_t d_tag_propagation_policy; // policy for moving tags downstream protected: - + gr_block (void){} //allows pure virtual interface sub-classes gr_block (const std::string &name, gr_io_signature_sptr input_signature, gr_io_signature_sptr output_signature); diff --git a/gnuradio-core/src/lib/runtime/gr_sync_block.h b/gnuradio-core/src/lib/runtime/gr_sync_block.h index 3a5d89d19..c5a6a50f1 100644 --- a/gnuradio-core/src/lib/runtime/gr_sync_block.h +++ b/gnuradio-core/src/lib/runtime/gr_sync_block.h @@ -34,7 +34,7 @@ class gr_sync_block : public gr_block { protected: - + gr_sync_block (void){} //allows pure virtual interface sub-classes gr_sync_block (const std::string &name, gr_io_signature_sptr input_signature, gr_io_signature_sptr output_signature); |