[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] gnuradio-core/src/lib/general gr_pwr_squelch_cc...
From: |
Johnathan Corgan |
Subject: |
[Commit-gnuradio] gnuradio-core/src/lib/general gr_pwr_squelch_cc... |
Date: |
Sat, 01 Jul 2006 01:02:56 +0000 |
CVSROOT: /sources/gnuradio
Module name: gnuradio-core
Changes by: Johnathan Corgan <jcorgan> 06/07/01 01:02:56
Modified files:
src/lib/general: gr_pwr_squelch_cc.cc gr_pwr_squelch_cc.h
gr_pwr_squelch_cc.i gr_squelch_base_cc.cc
gr_squelch_base_cc.h gr_squelch_base_cc.i
Log message:
More refactoring and cleanup of squelch base class.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnuradio-core/src/lib/general/gr_pwr_squelch_cc.cc?cvsroot=gnuradio&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/gnuradio-core/src/lib/general/gr_pwr_squelch_cc.h?cvsroot=gnuradio&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/gnuradio-core/src/lib/general/gr_pwr_squelch_cc.i?cvsroot=gnuradio&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/gnuradio-core/src/lib/general/gr_squelch_base_cc.cc?cvsroot=gnuradio&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/gnuradio-core/src/lib/general/gr_squelch_base_cc.h?cvsroot=gnuradio&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/gnuradio-core/src/lib/general/gr_squelch_base_cc.i?cvsroot=gnuradio&r1=1.1&r2=1.2
Patches:
Index: gr_pwr_squelch_cc.cc
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/general/gr_pwr_squelch_cc.cc,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- gr_pwr_squelch_cc.cc 30 Jun 2006 21:39:16 -0000 1.4
+++ gr_pwr_squelch_cc.cc 1 Jul 2006 01:02:56 -0000 1.5
@@ -24,7 +24,6 @@
#include "config.h"
#endif
-#include <cmath>
#include <gr_pwr_squelch_cc.h>
gr_pwr_squelch_cc_sptr
@@ -40,25 +39,6 @@
set_threshold(threshold);
}
-gr_pwr_squelch_cc::~gr_pwr_squelch_cc()
-{
-}
-
-double gr_pwr_squelch_cc::threshold() const
-{
- return 10*log10(d_threshold);
-}
-
-void gr_pwr_squelch_cc::set_threshold(double db)
-{
- d_threshold = std::pow(10.0, db/10);
-}
-
-void gr_pwr_squelch_cc::set_alpha(double alpha)
-{
- d_iir.set_taps(alpha);
-}
-
std::vector<float> gr_pwr_squelch_cc::squelch_range() const
{
std::vector<float> r(3);
@@ -71,22 +51,5 @@
void gr_pwr_squelch_cc::update_state(const gr_complex &in)
{
- // Calculate average power
- double mag_sqrd = in.real()*in.real()+in.imag()*in.imag();
- double pwr = d_iir.filter(mag_sqrd);
-
- switch(d_state) {
- case ST_MUTED:
- if (pwr >= d_threshold)
- d_state = d_ramp ? ST_ATTACK : ST_UNMUTED; // If not ramping, go
straight to unmuted
- break;
-
- case ST_UNMUTED:
- if (pwr < d_threshold)
- d_state = d_ramp ? ST_DECAY : ST_MUTED; // If not ramping, go
straight to muted
- break;
-
- default:
- break;
- };
+ d_pwr = d_iir.filter(in.real()*in.real()+in.imag()*in.imag());
}
Index: gr_pwr_squelch_cc.h
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/general/gr_pwr_squelch_cc.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- gr_pwr_squelch_cc.h 30 Jun 2006 21:39:16 -0000 1.2
+++ gr_pwr_squelch_cc.h 1 Jul 2006 01:02:56 -0000 1.3
@@ -23,13 +23,15 @@
#ifndef INCLUDED_GR_PWR_SQUELCH_CC_H
#define INCLUDED_GR_PWR_SQUELCH_CC_H
+#include <cmath>
#include <gr_squelch_base_cc.h>
#include <gr_single_pole_iir.h>
class gr_pwr_squelch_cc;
typedef boost::shared_ptr<gr_pwr_squelch_cc> gr_pwr_squelch_cc_sptr;
-gr_pwr_squelch_cc_sptr gr_make_pwr_squelch_cc(double db, double alpha =
0.0001, int ramp=0, bool gate=false);
+gr_pwr_squelch_cc_sptr
+gr_make_pwr_squelch_cc(double db, double alpha = 0.0001, int ramp=0, bool
gate=false);
/*!
* \brief gate or zero output when input power below threshold
@@ -39,22 +41,22 @@
{
private:
double d_threshold;
+ double d_pwr;
gr_single_pole_iir<double,double,double> d_iir;
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);
- void update_state(const gr_complex &in);
+protected:
+ virtual void update_state(const gr_complex &in);
+ virtual bool mute() const { return d_pwr < d_threshold; }
public:
- ~gr_pwr_squelch_cc();
-
std::vector<float> squelch_range() const;
- double threshold() const;
- void set_threshold(double db);
-
- void set_alpha(double alpha);
+ double threshold() const { return 10*log10(d_threshold); }
+ void set_threshold(double db) { d_threshold = std::pow(10.0, db/10); }
+ void set_alpha(double alpha) { d_iir.set_taps(alpha); }
};
#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.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- gr_pwr_squelch_cc.i 30 Jun 2006 21:39:16 -0000 1.2
+++ gr_pwr_squelch_cc.i 1 Jul 2006 01:02:56 -0000 1.3
@@ -29,14 +29,12 @@
class gr_pwr_squelch_cc : public gr_squelch_base_cc
{
- private:
+private:
gr_pwr_squelch_cc(double db, double alpha, int ramp, bool gate);
- public:
- double threshold() const;
- void set_threshold(double db);
-
- void set_alpha(double alpha);
-
+public:
+ double threshold() const { return 10*log10(d_threshold); }
+ void set_threshold(double db) { d_threshold = std::pow(10.0, db/10); }
+ void set_alpha(double alpha) { d_iir.set_taps(alpha); }
std::vector<float> squelch_range() const;
};
Index: gr_squelch_base_cc.cc
===================================================================
RCS file:
/sources/gnuradio/gnuradio-core/src/lib/general/gr_squelch_base_cc.cc,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- gr_squelch_base_cc.cc 30 Jun 2006 21:39:16 -0000 1.1
+++ gr_squelch_base_cc.cc 1 Jul 2006 01:02:56 -0000 1.2
@@ -39,25 +39,6 @@
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,
@@ -73,6 +54,16 @@
// Adjust envelope based on current state
switch(d_state) {
+ case ST_MUTED:
+ if (!mute())
+ d_state = d_ramp ? ST_ATTACK : ST_UNMUTED; // If not ramping, go
straight to unmuted
+ break;
+
+ case ST_UNMUTED:
+ if (mute())
+ 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
@@ -86,9 +77,6 @@
if (d_ramped == 0.0)
d_state = ST_MUTED;
break;
-
- default: // Do nothing for now
- break;
};
// If unmuted, copy input times envelope to output
Index: gr_squelch_base_cc.h
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/general/gr_squelch_base_cc.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- gr_squelch_base_cc.h 30 Jun 2006 21:39:16 -0000 1.1
+++ gr_squelch_base_cc.h 1 Jul 2006 01:02:56 -0000 1.2
@@ -27,26 +27,25 @@
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;
-
+private:
int d_ramp;
int d_ramped;
bool d_gate;
double d_envelope;
+ enum { ST_MUTED, ST_ATTACK, ST_UNMUTED, ST_DECAY } d_state;
+
+protected:
+ virtual void update_state(const gr_complex &sample) {};
+ virtual bool mute() const { return false; };
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);
-
+ void set_ramp(int ramp) { d_ramp = ramp; }
bool gate() const { return d_gate; }
- void set_gate(bool gate);
-
- bool unmuted() const;
+ void set_gate(bool gate) { d_gate = gate; }
+ bool unmuted() const { return (d_state == ST_UNMUTED || d_state ==
ST_ATTACK); }
virtual std::vector<float> squelch_range() const = 0;
Index: gr_squelch_base_cc.i
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/general/gr_squelch_base_cc.i,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- gr_squelch_base_cc.i 30 Jun 2006 21:39:16 -0000 1.1
+++ gr_squelch_base_cc.i 1 Jul 2006 01:02:56 -0000 1.2
@@ -24,17 +24,18 @@
class gr_squelch_base_cc : public gr_block
{
+private:
+ enum { ST_MUTED, ST_ATTACK, ST_UNMUTED, ST_DECAY } d_state;
+
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);
-
+ void set_ramp(int ramp) { d_ramp = ramp; }
bool gate() const { return d_gate; }
- void set_gate(bool gate);
-
- bool unmuted() const;
+ void set_gate(bool gate) { d_gate = gate; }
+ bool unmuted() const { return (d_state == ST_UNMUTED || d_state ==
ST_ATTACK); }
virtual std::vector<float> squelch_range() const = 0;
};
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] gnuradio-core/src/lib/general gr_pwr_squelch_cc...,
Johnathan Corgan <=