patch-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Patch-gnuradio] Added "skip" option to gr.simple_squelch_cc


From: Johnathan Corgan
Subject: [Patch-gnuradio] Added "skip" option to gr.simple_squelch_cc
Date: Wed, 07 Jun 2006 12:00:58 -0700
User-agent: Thunderbird 1.5.0.2 (X11/20060522)

This patch to current CVS modifies the gr_simple_squelch_cc block to
optionally skip over input samples (instead of emitting zeros) when the
power criteria is not met.

A new constructor parameter is created, 'skip', which defaults to false
and thus ensures that the existing behavior is preserved for existing
callers.

Additional methods are created to set and get the current value of skipping.

Regardless of skipping, the input buffer is fully consumed on each call
to ::work().

I have tested this with a file sink with skipping turned on and off with
no issues.

Patch is attached.

-Johnathan, AE6HO
Index: gr_simple_squelch_cc.cc
===================================================================
RCS file: 
/sources/gnuradio/gnuradio-core/src/lib/general/gr_simple_squelch_cc.cc,v
retrieving revision 1.2
diff -u -r1.2 gr_simple_squelch_cc.cc
--- gr_simple_squelch_cc.cc     28 Jan 2006 21:42:27 -0000      1.2
+++ gr_simple_squelch_cc.cc     7 Jun 2006 18:41:59 -0000
@@ -28,18 +28,19 @@
 #include <cmath>
 
 gr_simple_squelch_cc_sptr
-gr_make_simple_squelch_cc(double threshold_db, double alpha)
+gr_make_simple_squelch_cc(double threshold_db, double alpha, bool skip)
 {
-  return gr_simple_squelch_cc_sptr(new gr_simple_squelch_cc(threshold_db, 
alpha));
+  return gr_simple_squelch_cc_sptr(new gr_simple_squelch_cc(threshold_db, 
alpha, skip));
 }
 
-gr_simple_squelch_cc::gr_simple_squelch_cc (double threshold_db, double alpha)
+gr_simple_squelch_cc::gr_simple_squelch_cc (double threshold_db, double alpha, 
bool skip)
   : gr_sync_block ("simple_squelch_cc",
                   gr_make_io_signature(1, 1, sizeof(gr_complex)),
                   gr_make_io_signature(1, 1, sizeof(gr_complex))),
     d_iir(alpha), d_unmuted(false)
 {
   set_threshold (threshold_db);
+  set_skip (skip);
 }
 
 gr_simple_squelch_cc::~gr_simple_squelch_cc()
@@ -55,17 +56,20 @@
   const gr_complex *in = (const gr_complex *) input_items[0];
   gr_complex *out = (gr_complex *) output_items[0];
 
+  int j = 0;
   for (int i = 0; i < noutput_items; i++){
     double mag_sqrd = in[i].real()*in[i].real() + in[i].imag()*in[i].imag();
     double f = d_iir.filter(mag_sqrd);
     if (f >= d_threshold)
-      out[i] = in[i];
+      out[j++] = in[i];
     else
-      out[i] = 0;
+      if (!d_skip)
+          out[j++] = 0;
   }
 
   d_unmuted = d_iir.prev_output() >= d_threshold;
-  return noutput_items;
+  consume_each(noutput_items-j); // gr_sync_block::general_work will 
consume_each(j)
+  return j;
 }
 
 void
@@ -87,6 +91,12 @@
   d_iir.set_taps(alpha);
 }
 
+void
+gr_simple_squelch_cc::set_skip(bool skip)
+{
+  d_skip = skip;
+}
+
 std::vector<float>
 gr_simple_squelch_cc::squelch_range() const
 {
Index: gr_simple_squelch_cc.h
===================================================================
RCS file: 
/sources/gnuradio/gnuradio-core/src/lib/general/gr_simple_squelch_cc.h,v
retrieving revision 1.2
diff -u -r1.2 gr_simple_squelch_cc.h
--- gr_simple_squelch_cc.h      28 Jan 2006 21:42:27 -0000      1.2
+++ gr_simple_squelch_cc.h      7 Jun 2006 18:41:59 -0000
@@ -29,7 +29,7 @@
 typedef boost::shared_ptr<gr_simple_squelch_cc> gr_simple_squelch_cc_sptr;
 
 gr_simple_squelch_cc_sptr
-gr_make_simple_squelch_cc (double threshold_db, double alpha = 0.0001);
+gr_make_simple_squelch_cc (double threshold_db, double alpha = 0.0001, bool 
skip=false);
 
 /*!
  * \brief simple squelch block based on average signal power and threshold in 
dB.
@@ -39,11 +39,12 @@
   double                                       d_threshold;
   gr_single_pole_iir<double,double,double>     d_iir;
   bool                                         d_unmuted;
-
+  bool                                         d_skip;
+  
   friend gr_simple_squelch_cc_sptr
-  gr_make_simple_squelch_cc (double threshold_db, double alpha);
+  gr_make_simple_squelch_cc (double threshold_db, double alpha, bool skip);
 
-  gr_simple_squelch_cc (double threshold_db, double alpha);
+  gr_simple_squelch_cc (double threshold_db, double alpha, bool skip);
 
 public:
   ~gr_simple_squelch_cc ();
@@ -53,10 +54,12 @@
            gr_vector_void_star &output_items);
 
   bool unmuted () const { return d_unmuted; }
-
+  bool skipping () const { return d_skip; }
+  
   void set_alpha (double alpha);
   void set_threshold (double decibels);
-
+  void set_skip (bool skip);
+  
   double threshold() const;
   std::vector<float> squelch_range() const;
 
Index: gr_simple_squelch_cc.i
===================================================================
RCS file: 
/sources/gnuradio/gnuradio-core/src/lib/general/gr_simple_squelch_cc.i,v
retrieving revision 1.2
diff -u -r1.2 gr_simple_squelch_cc.i
--- gr_simple_squelch_cc.i      28 Jan 2006 21:42:27 -0000      1.2
+++ gr_simple_squelch_cc.i      7 Jun 2006 18:42:00 -0000
@@ -23,15 +23,18 @@
 GR_SWIG_BLOCK_MAGIC(gr,simple_squelch_cc);
 
 gr_simple_squelch_cc_sptr
-gr_make_simple_squelch_cc (double threshold_db, double alpha = 0.0001);
+gr_make_simple_squelch_cc (double threshold_db, double alpha = 0.0001, bool 
skip=false);
 
 class gr_simple_squelch_cc : public gr_sync_block
 {
 public:
   bool unmuted () const { return d_unmuted; }
+  bool skipping () const { return d_skip; }
+  
   void set_alpha (double alpha);
   void set_threshold (double decibels);
-
+  void set_skip (bool skip);
+  
   double threshold() const;
   std::vector<float> squelch_range() const;
 };

reply via email to

[Prev in Thread] Current Thread [Next in Thread]