[Top][All Lists]
[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: |
Sat, 01 Jul 2006 01:38:29 +0000 |
CVSROOT: /sources/gnuradio
Module name: gnuradio-core
Changes by: Johnathan Corgan <jcorgan> 06/07/01 01:38:28
Modified files:
src/lib/general: Makefile.am gr_pwr_squelch_ff.cc
gr_pwr_squelch_ff.h gr_pwr_squelch_ff.i
gr_squelch_base_cc.i
Added files:
src/lib/general: gr_squelch_base_ff.cc gr_squelch_base_ff.h
gr_squelch_base_ff.i
Log message:
Refactored gr_pwr_squelch_ff the same way as gr_pwr_squelch_cc.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnuradio-core/src/lib/general/Makefile.am?cvsroot=gnuradio&r1=1.107&r2=1.108
http://cvs.savannah.gnu.org/viewcvs/gnuradio-core/src/lib/general/gr_pwr_squelch_ff.cc?cvsroot=gnuradio&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/gnuradio-core/src/lib/general/gr_pwr_squelch_ff.h?cvsroot=gnuradio&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/gnuradio-core/src/lib/general/gr_pwr_squelch_ff.i?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.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/gnuradio-core/src/lib/general/gr_squelch_base_ff.cc?cvsroot=gnuradio&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnuradio-core/src/lib/general/gr_squelch_base_ff.h?cvsroot=gnuradio&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnuradio-core/src/lib/general/gr_squelch_base_ff.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.107
retrieving revision 1.108
diff -u -b -r1.107 -r1.108
--- Makefile.am 30 Jun 2006 21:39:16 -0000 1.107
+++ Makefile.am 1 Jul 2006 01:38:28 -0000 1.108
@@ -184,6 +184,7 @@
gr_simple_squelch_cc.cc \
gr_skiphead.cc \
gr_squelch_base_cc.cc \
+ gr_squelch_base_ff.cc \
gr_stream_to_streams.cc \
gr_stream_to_vector.cc \
gr_streams_to_stream.cc \
@@ -308,6 +309,7 @@
gr_simple_squelch_cc.h \
gr_skiphead.h \
gr_squelch_base_cc.h \
+ gr_squelch_base_ff.h \
gr_stream_to_streams.h \
gr_stream_to_vector.h \
gr_streams_to_stream.h \
@@ -426,6 +428,7 @@
gr_simple_squelch_cc.i \
gr_skiphead.i \
gr_squelch_base_cc.i \
+ gr_squelch_base_ff.i \
gr_stream_to_streams.i \
gr_stream_to_vector.i \
gr_streams_to_stream.i \
Index: gr_pwr_squelch_ff.cc
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/general/gr_pwr_squelch_ff.cc,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- gr_pwr_squelch_ff.cc 18 Jun 2006 19:20:00 -0000 1.1
+++ gr_pwr_squelch_ff.cc 1 Jul 2006 01:38:28 -0000 1.2
@@ -24,9 +24,7 @@
#include "config.h"
#endif
-#include <cmath>
#include <gr_pwr_squelch_ff.h>
-#include <gr_io_signature.h>
gr_pwr_squelch_ff_sptr
gr_make_pwr_squelch_ff(double threshold, double alpha, int ramp, bool gate)
@@ -35,51 +33,10 @@
}
gr_pwr_squelch_ff::gr_pwr_squelch_ff(double threshold, double alpha, int ramp,
bool gate) :
- gr_block("pwr_squelch_ff",
- gr_make_io_signature (1, 1, sizeof(float)),
- gr_make_io_signature (1, 1, sizeof(float))),
+ gr_squelch_base_ff("pwr_squelch_ff", 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_ff::~gr_pwr_squelch_ff()
-{
-}
-
-double gr_pwr_squelch_ff::threshold() const
-{
- return 10*log10(d_threshold);
-}
-
-void gr_pwr_squelch_ff::set_threshold(double db)
-{
- d_threshold = std::pow(10.0, db/10);
-}
-
-void gr_pwr_squelch_ff::set_alpha(double alpha)
-{
- d_iir.set_taps(alpha);
-}
-
-void gr_pwr_squelch_ff::set_gate(bool gate)
-{
- d_gate = gate;
-}
-
-void gr_pwr_squelch_ff::set_ramp(int ramp)
-{
- d_ramp = ramp;
-}
-
-bool gr_pwr_squelch_ff::unmuted() const
-{
- return (d_state == ST_UNMUTED || d_state == ST_ATTACK);
}
std::vector<float> gr_pwr_squelch_ff::squelch_range() const
@@ -92,57 +49,7 @@
return r;
}
-int gr_pwr_squelch_ff::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_ff::update_state(const float &in)
{
- const float *in = (const float *) input_items[0];
- float *out = (float *) output_items[0];
-
- int j = 0;
-
- for (int i = 0; i < noutput_items; i++) {
- // Calculate average power
- double mag_sqrd = in[i]*in[i];
- double f = d_iir.filter(mag_sqrd);
-
- // Update squelch state based on power vs. threshold
- switch(d_state) {
- case ST_MUTED:
- if (f >= 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)
- 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;
- 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]*d_envelope;
- else
- if (!d_gate)
- out[j++] = 0.0;
- }
-
- consume_each(noutput_items); // Use all the inputs
- return j; // But only report outputs copied
+ d_pwr = d_iir.filter(in*in);
}
Index: gr_pwr_squelch_ff.h
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/general/gr_pwr_squelch_ff.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- gr_pwr_squelch_ff.h 18 Jun 2006 19:20:00 -0000 1.1
+++ gr_pwr_squelch_ff.h 1 Jul 2006 01:38:28 -0000 1.2
@@ -23,56 +23,40 @@
#ifndef INCLUDED_GR_PWR_SQUELCH_FF_H
#define INCLUDED_GR_PWR_SQUELCH_FF_H
-#include <gr_block.h>
+#include <cmath>
+#include <gr_squelch_base_ff.h>
#include <gr_single_pole_iir.h>
class gr_pwr_squelch_ff;
typedef boost::shared_ptr<gr_pwr_squelch_ff> gr_pwr_squelch_ff_sptr;
-gr_pwr_squelch_ff_sptr gr_make_pwr_squelch_ff(double db, double alpha =
0.0001, int ramp=0, bool gate=false);
+gr_pwr_squelch_ff_sptr
+gr_make_pwr_squelch_ff(double db, double alpha = 0.0001, int ramp=0, bool
gate=false);
/*!
* \brief gate or zero output when input power below threshold
* \ingroup block
*/
-class gr_pwr_squelch_ff : public gr_block
+class gr_pwr_squelch_ff : public gr_squelch_base_ff
{
- enum state_t { ST_MUTED, ST_ATTACK, ST_UNMUTED, ST_DECAY };
-
+private:
double d_threshold;
- int d_ramp;
- bool d_gate;
-
+ double d_pwr;
gr_single_pole_iir<double,double,double> d_iir;
- state_t d_state;
- int d_ramped;
- double d_envelope;
friend gr_pwr_squelch_ff_sptr gr_make_pwr_squelch_ff(double db, double
alpha, int ramp, bool gate);
gr_pwr_squelch_ff(double db, double alpha, int ramp, bool gate);
- public:
- ~gr_pwr_squelch_ff();
-
- 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;
+protected:
+ virtual void update_state(const float &in);
+ virtual bool mute() const { return d_pwr < d_threshold; }
+public:
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);
+ 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_FF_H */
Index: gr_pwr_squelch_ff.i
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/general/gr_pwr_squelch_ff.i,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- gr_pwr_squelch_ff.i 18 Jun 2006 19:20:00 -0000 1.1
+++ gr_pwr_squelch_ff.i 1 Jul 2006 01:38:28 -0000 1.2
@@ -22,26 +22,19 @@
GR_SWIG_BLOCK_MAGIC(gr,pwr_squelch_ff);
-gr_pwr_squelch_ff_sptr gr_make_pwr_squelch_ff(double db, double alpha=0.0001,
int ramp=0, bool gate=false);
+%include gr_squelch_base_ff.i
-class gr_pwr_squelch_ff : public gr_block
+gr_pwr_squelch_ff_sptr
+gr_make_pwr_squelch_ff(double db, double alpha=0.0001, int ramp=0, bool
gate=false);
+
+class gr_pwr_squelch_ff : public gr_squelch_base_ff
{
- private:
+private:
gr_pwr_squelch_ff(double db, double alpha, int ramp, bool gate);
- public:
- 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;
-
+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.i
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/general/gr_squelch_base_cc.i,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- gr_squelch_base_cc.i 1 Jul 2006 01:02:56 -0000 1.2
+++ gr_squelch_base_cc.i 1 Jul 2006 01:38:28 -0000 1.3
@@ -29,7 +29,6 @@
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) { d_ramp = ramp; }
Index: gr_squelch_base_ff.cc
===================================================================
RCS file: gr_squelch_base_ff.cc
diff -N gr_squelch_base_ff.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gr_squelch_base_ff.cc 1 Jul 2006 01:38:28 -0000 1.1
@@ -0,0 +1,93 @@
+/* -*- 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_ff.h>
+#include <gr_io_signature.h>
+
+gr_squelch_base_ff::gr_squelch_base_ff(const char *name, int ramp, bool gate)
:
+ gr_block(name,
+ gr_make_io_signature(1, 1, sizeof(float)),
+ gr_make_io_signature(1, 1, sizeof(float)))
+{
+ set_ramp(ramp);
+ set_gate(gate);
+ d_state = ST_MUTED;
+ d_envelope = d_ramp ? 0.0 : 1.0;
+ d_ramped = 0;
+}
+
+int gr_squelch_base_ff::general_work(int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ const float *in = (const float *) input_items[0];
+ float *out = (float *) 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_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
+ 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;
+ };
+
+ // 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]*d_envelope;
+ 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_ff.h
===================================================================
RCS file: gr_squelch_base_ff.h
diff -N gr_squelch_base_ff.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gr_squelch_base_ff.h 1 Jul 2006 01:38:28 -0000 1.1
@@ -0,0 +1,58 @@
+/* -*- 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_FF_H
+#define INCLUDED_GR_SQUELCH_BASE_FF_H
+
+#include <gr_block.h>
+
+class gr_squelch_base_ff : public gr_block
+{
+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 float &sample) {};
+ virtual bool mute() const { return false; };
+
+public:
+ gr_squelch_base_ff(const char *name, int ramp, bool gate);
+
+ int ramp() const { return d_ramp; }
+ void set_ramp(int ramp) { d_ramp = ramp; }
+ bool gate() const { return d_gate; }
+ 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;
+
+ 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_FF_H */
Index: gr_squelch_base_ff.i
===================================================================
RCS file: gr_squelch_base_ff.i
diff -N gr_squelch_base_ff.i
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gr_squelch_base_ff.i 1 Jul 2006 01:38:28 -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_ff : public gr_block
+{
+private:
+ enum { ST_MUTED, ST_ATTACK, ST_UNMUTED, ST_DECAY } d_state;
+
+public:
+ gr_squelch_base_ff(const char *name, int ramp, bool gate);
+
+ int ramp() const { return d_ramp; }
+ void set_ramp(int ramp) { d_ramp = ramp; }
+ bool gate() const { return d_gate; }
+ 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;
+};