commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] gnuradio-examples/python/audio dial_squelch.py


From: Johnathan Corgan
Subject: [Commit-gnuradio] gnuradio-examples/python/audio dial_squelch.py
Date: Sun, 18 Jun 2006 20:47:48 +0000

CVSROOT:        /sources/gnuradio
Module name:    gnuradio-examples
Changes by:     Johnathan Corgan <jcorgan>      06/06/18 20:47:48

Added files:
        python/audio   : dial_squelch.py 

Log message:
        Added dial_squelch.py script to experiment with audio squelch 
parameters.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnuradio-examples/python/audio/dial_squelch.py?cvsroot=gnuradio&rev=1.1

Patches:
Index: dial_squelch.py
===================================================================
RCS file: dial_squelch.py
diff -N dial_squelch.py
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ dial_squelch.py     18 Jun 2006 20:47:48 -0000      1.1
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+
+# 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.
+# 
+
+from gnuradio import gr, audio, eng_option
+from gnuradio.eng_option import eng_option
+from math import pi, cos
+from optparse import OptionParser
+
+"""
+This script generates a standard dial tone and then applies a sinusoidal
+envelope to vary it's loudness.  The audio is then passed through the
+power squelch block before it gets sent to the sound card. By varying
+the command line parameters, one can see the effect of differing
+amounts of power averaging, threshold, and attack/decay ramping.
+"""
+
+class app_flow_graph(gr.flow_graph):
+    def __init__(self, options, args):
+        gr.flow_graph.__init__(self)
+       
+       # Create dial tone by adding two sine waves
+       SRC1 = gr.sig_source_f(options.rate, gr.GR_SIN_WAVE, 350, 0.5, 0.0)
+       SRC2 = gr.sig_source_f(options.rate, gr.GR_SIN_WAVE, 440, 0.5, 0.0)
+       ADD = gr.add_ff()
+
+       # Convert to vector stream (and back) to apply raised cosine envelope
+       # You could also do this with a vector_source_f block that repeats.
+       S2V = gr.stream_to_vector(gr.sizeof_float, options.rate)
+       ENV = [0.5-cos(2*pi*x/options.rate)/2 for x in range(options.rate)]
+       MLT = gr.multiply_const_vff(ENV)
+       V2S = gr.vector_to_stream(gr.sizeof_float, options.rate)
+
+       # Run through power squelch with user supplied or default options
+       # Zero output when squelch is invoked
+       SQL = gr.pwr_squelch_ff(options.threshold, options.alpha, options.ramp, 
False)
+       DST = audio.sink(options.rate)
+
+       # Solder it all together
+       self.connect(SRC1, (ADD, 0))
+       self.connect(SRC2, (ADD, 1))
+       self.connect(ADD, S2V, MLT, V2S, SQL, DST)
+       
+def main():
+    parser = OptionParser(option_class=eng_option)
+    parser.add_option("-r", "--rate", type="int", default=8000, help="set 
audio output sample rate to RATE", metavar="RATE")
+    parser.add_option("-t", "--threshold", type="eng_float", default=-10.0, 
help="set power squelch to DB", metavar="DB")
+    parser.add_option("-a", "--alpha", type="eng_float", default=None, 
help="set alpha to ALPHA", metavar="ALPHA")
+    parser.add_option("-m", "--ramp", type="int", default=None, help="set 
attack/decay ramp to SAMPLES", metavar="SAMPLES")
+    (options, args) = parser.parse_args()
+
+    if options.alpha == None:
+       options.alpha = 50.0/options.rate
+       
+    if options.ramp == None:
+       options.ramp = options.rate/50  # ~ 20 ms
+
+    print "Using audio rate of", options.rate
+    print "Using threshold of", options.threshold, "db"
+    print "Using alpha of", options.alpha
+    print "Using ramp of", options.ramp, "samples"
+
+    fg = app_flow_graph(options, args)
+
+    try:
+      fg.run()
+    except KeyboardInterrupt:
+      pass
+
+if __name__ == "__main__":
+    main()




reply via email to

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