commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] gnuradio-core/src/lib/general Makefile.am gr_pw...


From: Johnathan Corgan
Subject: [Commit-gnuradio] gnuradio-core/src/lib/general Makefile.am gr_pw...
Date: Fri, 30 Jun 2006 21:39:17 +0000

CVSROOT:        /sources/gnuradio
Module name:    gnuradio-core
Changes by:     Johnathan Corgan <jcorgan>      06/06/30 21:39:16

Modified files:
        src/lib/general: Makefile.am gr_pwr_squelch_cc.cc 
                         gr_pwr_squelch_cc.h gr_pwr_squelch_cc.i 
Added files:
        src/lib/general: gr_squelch_base_cc.cc gr_squelch_base_cc.h 
                         gr_squelch_base_cc.i 

Log message:
        Refactored squelch function into separate base class in preparation for
        adding additional squelch types.  Still need to do _ff class.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnuradio-core/src/lib/general/Makefile.am?cvsroot=gnuradio&r1=1.106&r2=1.107
http://cvs.savannah.gnu.org/viewcvs/gnuradio-core/src/lib/general/gr_pwr_squelch_cc.cc?cvsroot=gnuradio&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/gnuradio-core/src/lib/general/gr_pwr_squelch_cc.h?cvsroot=gnuradio&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/gnuradio-core/src/lib/general/gr_pwr_squelch_cc.i?cvsroot=gnuradio&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/gnuradio-core/src/lib/general/gr_squelch_base_cc.cc?cvsroot=gnuradio&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnuradio-core/src/lib/general/gr_squelch_base_cc.h?cvsroot=gnuradio&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnuradio-core/src/lib/general/gr_squelch_base_cc.i?cvsroot=gnuradio&rev=1.1

Patches:
Index: Makefile.am
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/general/Makefile.am,v
retrieving revision 1.106
retrieving revision 1.107
diff -u -b -r1.106 -r1.107
--- Makefile.am 18 Jun 2006 19:20:00 -0000      1.106
+++ Makefile.am 30 Jun 2006 21:39:16 -0000      1.107
@@ -183,6 +183,7 @@
        gr_simple_framer.cc             \
        gr_simple_squelch_cc.cc         \
        gr_skiphead.cc                  \
+       gr_squelch_base_cc.cc           \
        gr_stream_to_streams.cc         \
        gr_stream_to_vector.cc          \
        gr_streams_to_stream.cc         \
@@ -306,6 +307,7 @@
        gr_simple_framer_sync.h         \
        gr_simple_squelch_cc.h          \
        gr_skiphead.h                   \
+       gr_squelch_base_cc.h            \
        gr_stream_to_streams.h          \
        gr_stream_to_vector.h           \
        gr_streams_to_stream.h          \
@@ -423,6 +425,7 @@
        gr_simple_framer.i              \
        gr_simple_squelch_cc.i          \
        gr_skiphead.i                   \
+       gr_squelch_base_cc.i            \
        gr_stream_to_streams.i          \
        gr_stream_to_vector.i           \
        gr_streams_to_stream.i          \

Index: gr_pwr_squelch_cc.cc
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/general/gr_pwr_squelch_cc.cc,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- gr_pwr_squelch_cc.cc        18 Jun 2006 16:45:20 -0000      1.3
+++ gr_pwr_squelch_cc.cc        30 Jun 2006 21:39:16 -0000      1.4
@@ -26,7 +26,6 @@
 
 #include <cmath>
 #include <gr_pwr_squelch_cc.h>
-#include <gr_io_signature.h>
 
 gr_pwr_squelch_cc_sptr
 gr_make_pwr_squelch_cc(double threshold, double alpha, int ramp, bool gate)
@@ -35,17 +34,10 @@
 }
 
 gr_pwr_squelch_cc::gr_pwr_squelch_cc(double threshold, double alpha, int ramp, 
bool gate) : 
-       gr_block("pwr_squelch_cc",
-       gr_make_io_signature (1, 1, sizeof(gr_complex)),
-       gr_make_io_signature (1, 1, sizeof(gr_complex))),
+       gr_squelch_base_cc("pwr_squelch_cc", ramp, gate),
        d_iir(alpha)
 {
   set_threshold(threshold);
-  set_ramp(ramp);
-  set_gate(gate);
-  d_state = ST_MUTED;
-  d_envelope = d_ramp ? 0.0 : 1.0;
-  d_ramped = 0;
 }
 
 gr_pwr_squelch_cc::~gr_pwr_squelch_cc()
@@ -67,21 +59,6 @@
   d_iir.set_taps(alpha);
 }
 
-void gr_pwr_squelch_cc::set_gate(bool gate)
-{
-  d_gate = gate;
-}
-
-void gr_pwr_squelch_cc::set_ramp(int ramp)
-{
-  d_ramp = ramp;
-}  
-
-bool gr_pwr_squelch_cc::unmuted() const
-{
-  return (d_state == ST_UNMUTED || d_state == ST_ATTACK);
-}
-
 std::vector<float> gr_pwr_squelch_cc::squelch_range() const
 {
   std::vector<float> r(3);
@@ -92,57 +69,24 @@
   return r;
 }
 
-int gr_pwr_squelch_cc::general_work(int noutput_items,
-                                   gr_vector_int &ninput_items,
-                                   gr_vector_const_void_star &input_items,
-                                   gr_vector_void_star &output_items)
+void gr_pwr_squelch_cc::update_state(const gr_complex &in)
 {
-  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++) {
     // Calculate average power
-    double mag_sqrd = in[i].real()*in[i].real() + in[i].imag()*in[i].imag();
-    double f = d_iir.filter(mag_sqrd);
+  double mag_sqrd = in.real()*in.real()+in.imag()*in.imag();
+  double pwr = d_iir.filter(mag_sqrd);
 
-    // Update squelch state based on power vs. threshold
     switch(d_state) {
       case ST_MUTED:
-        if (f >= d_threshold) 
+        if (pwr >= d_threshold) 
           d_state = d_ramp ? ST_ATTACK : ST_UNMUTED; // If not ramping, go 
straight to unmuted
         break;
 
       case ST_UNMUTED:
-        if (f < d_threshold)
+        if (pwr < d_threshold)
           d_state = d_ramp ? ST_DECAY : ST_MUTED;    // If not ramping, go 
straight to muted
         break;
 
-      case ST_ATTACK:
-        d_envelope = 0.5-std::cos(M_PI*(++d_ramped)/d_ramp)/2.0; // FIXME: 
precalculate window for speed
-        if (d_ramped >= d_ramp) {                    // use >= in case d_ramp 
is set to lower value elsewhere
-         d_state = ST_UNMUTED;
-         d_envelope = 1.0;
-        }
-        break;
-
-      case ST_DECAY:
-        d_envelope = 0.5-std::cos(M_PI*(--d_ramped)/d_ramp)/2.0; // FIXME: 
precalculate window for speed
-        if (d_ramped == 0)
-         d_state = ST_MUTED;
+      default:
         break;
     };
-       
-    // If unmuted, copy input times envelope to output
-    // Otherwise, if not gating, copy zero to output
-    if (d_state != ST_MUTED)
-      out[j++] = in[i]*gr_complex(d_envelope, 0.0);
-    else
-      if (!d_gate)
-          out[j++] = 0.0;
-  }
-
-  consume_each(noutput_items);  // Use all the inputs
-  return j;                    // But only report outputs copied
 }

Index: gr_pwr_squelch_cc.h
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/general/gr_pwr_squelch_cc.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- gr_pwr_squelch_cc.h 18 Jun 2006 06:52:46 -0000      1.1
+++ gr_pwr_squelch_cc.h 30 Jun 2006 21:39:16 -0000      1.2
@@ -23,7 +23,7 @@
 #ifndef INCLUDED_GR_PWR_SQUELCH_CC_H
 #define INCLUDED_GR_PWR_SQUELCH_CC_H
 
-#include <gr_block.h>
+#include <gr_squelch_base_cc.h>
 #include <gr_single_pole_iir.h>
 
 class gr_pwr_squelch_cc;
@@ -35,44 +35,26 @@
  * \brief gate or zero output when input power below threshold
  * \ingroup block
  */
-class gr_pwr_squelch_cc : public gr_block
+class gr_pwr_squelch_cc : public gr_squelch_base_cc
 {
-  enum state_t { ST_MUTED, ST_ATTACK, ST_UNMUTED, ST_DECAY };
-
+private:
   double                                  d_threshold;
-  int                                     d_ramp;
-  bool                                    d_gate;
-
   gr_single_pole_iir<double,double,double> d_iir;
-  state_t                                 d_state;
-  int                                     d_ramped;
-  double                                  d_envelope;
 
   friend gr_pwr_squelch_cc_sptr gr_make_pwr_squelch_cc(double db, double 
alpha, int ramp, bool gate);
   gr_pwr_squelch_cc(double db, double alpha, int ramp, bool gate);
   
- public:
+  void update_state(const gr_complex &in);
+  
+public:
   ~gr_pwr_squelch_cc();
 
+  std::vector<float> squelch_range() const;
+
   double threshold() const;
   void set_threshold(double db);
 
   void set_alpha(double alpha);
-
-  int ramp() const { return d_ramp; }
-  void set_ramp(int ramp);
-
-  bool gate() const { return d_gate; }
-  void set_gate(bool gate);
-
-  bool unmuted() const;
-
-  std::vector<float> squelch_range() const;
-
-  int general_work (int noutput_items,
-                   gr_vector_int &ninput_items,
-                   gr_vector_const_void_star &input_items,
-                   gr_vector_void_star &output_items);
 };
 
 #endif /* INCLUDED_GR_PWR_SQUELCH_CC_H */

Index: gr_pwr_squelch_cc.i
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/general/gr_pwr_squelch_cc.i,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- gr_pwr_squelch_cc.i 18 Jun 2006 06:52:46 -0000      1.1
+++ gr_pwr_squelch_cc.i 30 Jun 2006 21:39:16 -0000      1.2
@@ -22,9 +22,12 @@
 
 GR_SWIG_BLOCK_MAGIC(gr,pwr_squelch_cc);
 
-gr_pwr_squelch_cc_sptr gr_make_pwr_squelch_cc(double db, double alpha=0.0001, 
int ramp=0, bool gate=false);
+%include gr_squelch_base_cc.i
 
-class gr_pwr_squelch_cc : public gr_block
+gr_pwr_squelch_cc_sptr 
+gr_make_pwr_squelch_cc(double db, double alpha=0.0001, int ramp=0, bool 
gate=false);
+
+class gr_pwr_squelch_cc : public gr_squelch_base_cc
 {
  private:
   gr_pwr_squelch_cc(double db, double alpha, int ramp, bool gate);
@@ -35,13 +38,5 @@
 
   void set_alpha(double alpha);
 
-  int ramp() const { return d_ramp; }
-  void set_ramp(int ramp);
-
-  bool gate() const { return d_gate; }
-  void set_gate(bool gate);
-
-  bool unmuted() const;
-
   std::vector<float> squelch_range() const;
 };

Index: gr_squelch_base_cc.cc
===================================================================
RCS file: gr_squelch_base_cc.cc
diff -N gr_squelch_base_cc.cc
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ gr_squelch_base_cc.cc       30 Jun 2006 21:39:16 -0000      1.1
@@ -0,0 +1,105 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2006 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gr_squelch_base_cc.h>
+#include <gr_io_signature.h>
+
+gr_squelch_base_cc::gr_squelch_base_cc(const char *name, int ramp, bool gate) 
: 
+       gr_block(name,
+                gr_make_io_signature(1, 1, sizeof(gr_complex)),
+                gr_make_io_signature(1, 1, sizeof(gr_complex)))
+{
+  set_ramp(ramp);
+  set_gate(gate);
+  d_state = ST_MUTED;
+  d_envelope = d_ramp ? 0.0 : 1.0;
+  d_ramped = 0;
+}
+
+gr_squelch_base_cc::~gr_squelch_base_cc()
+{
+}
+
+void gr_squelch_base_cc::set_gate(bool gate)
+{
+  d_gate = gate;
+}
+
+void gr_squelch_base_cc::set_ramp(int ramp)
+{
+  d_ramp = ramp;
+}  
+
+bool gr_squelch_base_cc::unmuted() const
+{
+  return (d_state == ST_UNMUTED || d_state == ST_ATTACK);
+}
+
+int gr_squelch_base_cc::general_work(int noutput_items,
+                                    gr_vector_int &ninput_items,
+                                    gr_vector_const_void_star &input_items,
+                                    gr_vector_void_star &output_items)
+{
+  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++) {
+    update_state(in[i]);
+
+    // Adjust envelope based on current state
+    switch(d_state) {
+      case ST_ATTACK:
+        d_envelope = 0.5-std::cos(M_PI*(++d_ramped)/d_ramp)/2.0; // FIXME: 
precalculate window for speed
+        if (d_ramped >= d_ramp) { // use >= in case d_ramp is set to lower 
value elsewhere
+         d_state = ST_UNMUTED;
+         d_envelope = 1.0;
+        }
+        break;
+
+      case ST_DECAY:
+        d_envelope = 0.5-std::cos(M_PI*(--d_ramped)/d_ramp)/2.0; // FIXME: 
precalculate window for speed
+        if (d_ramped == 0.0)
+         d_state = ST_MUTED;
+        break;
+    
+      default: // Do nothing for now
+        break;
+    };
+       
+    // If unmuted, copy input times envelope to output
+    // Otherwise, if not gating, copy zero to output
+    if (d_state != ST_MUTED)
+      out[j++] = in[i]*gr_complex(d_envelope, 0.0);
+    else
+      if (!d_gate)
+          out[j++] = 0.0;
+  }
+
+  consume_each(noutput_items);  // Use all the inputs
+  return j;                    // But only report outputs copied
+}

Index: gr_squelch_base_cc.h
===================================================================
RCS file: gr_squelch_base_cc.h
diff -N gr_squelch_base_cc.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ gr_squelch_base_cc.h        30 Jun 2006 21:39:16 -0000      1.1
@@ -0,0 +1,59 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2006 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef INCLUDED_GR_SQUELCH_BASE_CC_H
+#define INCLUDED_GR_SQUELCH_BASE_CC_H
+
+#include <gr_block.h>
+
+class gr_squelch_base_cc : public gr_block
+{
+protected:
+  enum { ST_MUTED, ST_ATTACK, ST_UNMUTED, ST_DECAY } d_state;
+  virtual void update_state(const gr_complex &sample) = 0;
+
+  int   d_ramp;
+  int   d_ramped;
+  bool   d_gate;
+  double d_envelope;
+  
+public:
+  gr_squelch_base_cc(const char *name, int ramp, bool gate);
+  ~gr_squelch_base_cc();
+
+  int ramp() const { return d_ramp; }
+  void set_ramp(int ramp);
+
+  bool gate() const { return d_gate; }
+  void set_gate(bool gate);
+
+  bool unmuted() const;
+
+  virtual std::vector<float> squelch_range() const = 0;
+
+  int general_work (int noutput_items,
+                   gr_vector_int &ninput_items,
+                   gr_vector_const_void_star &input_items,
+                   gr_vector_void_star &output_items);
+};
+
+#endif /* INCLUDED_GR_SQUELCH_BASE_CC_H */

Index: gr_squelch_base_cc.i
===================================================================
RCS file: gr_squelch_base_cc.i
diff -N gr_squelch_base_cc.i
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ gr_squelch_base_cc.i        30 Jun 2006 21:39:16 -0000      1.1
@@ -0,0 +1,40 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2006 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <gr_block.h>
+
+class gr_squelch_base_cc : public gr_block
+{
+public:
+  gr_squelch_base_cc(const char *name, int ramp, bool gate);
+  ~gr_squelch_base_cc();
+
+  int ramp() const { return d_ramp; }
+  void set_ramp(int ramp);
+
+  bool gate() const { return d_gate; }
+  void set_gate(bool gate);
+
+  bool unmuted() const;
+
+  virtual std::vector<float> squelch_range() const = 0;
+};




reply via email to

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