root / gr-audio / examples / python / dial_tone_daemon.py @ accb9f2f
History | View | Annotate | Download (2 kB)
| 1 | 92c63035 | jcorgan | #!/usr/bin/env python
|
|---|---|---|---|
| 2 | 92c63035 | jcorgan | #
|
| 3 | 92c63035 | jcorgan | # Copyright 2004,2005,2007,2008 Free Software Foundation, Inc.
|
| 4 | 92c63035 | jcorgan | #
|
| 5 | 92c63035 | jcorgan | # This file is part of GNU Radio
|
| 6 | 92c63035 | jcorgan | #
|
| 7 | 92c63035 | jcorgan | # GNU Radio is free software; you can redistribute it and/or modify
|
| 8 | 92c63035 | jcorgan | # it under the terms of the GNU General Public License as published by
|
| 9 | 92c63035 | jcorgan | # the Free Software Foundation; either version 3, or (at your option)
|
| 10 | 92c63035 | jcorgan | # any later version.
|
| 11 | 92c63035 | jcorgan | #
|
| 12 | 92c63035 | jcorgan | # GNU Radio is distributed in the hope that it will be useful,
|
| 13 | 92c63035 | jcorgan | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 14 | 92c63035 | jcorgan | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 15 | 92c63035 | jcorgan | # GNU General Public License for more details.
|
| 16 | 92c63035 | jcorgan | #
|
| 17 | 92c63035 | jcorgan | # You should have received a copy of the GNU General Public License
|
| 18 | 92c63035 | jcorgan | # along with GNU Radio; see the file COPYING. If not, write to
|
| 19 | 92c63035 | jcorgan | # the Free Software Foundation, Inc., 51 Franklin Street,
|
| 20 | 92c63035 | jcorgan | # Boston, MA 02110-1301, USA.
|
| 21 | 92c63035 | jcorgan | #
|
| 22 | 92c63035 | jcorgan | |
| 23 | 92c63035 | jcorgan | from gnuradio import gr, gru |
| 24 | 92c63035 | jcorgan | from gnuradio import audio |
| 25 | 92c63035 | jcorgan | from gnuradio.eng_option import eng_option |
| 26 | 92c63035 | jcorgan | from optparse import OptionParser |
| 27 | 92c63035 | jcorgan | import os |
| 28 | 92c63035 | jcorgan | |
| 29 | 92c63035 | jcorgan | class my_top_block(gr.top_block): |
| 30 | 92c63035 | jcorgan | |
| 31 | 92c63035 | jcorgan | def __init__(self): |
| 32 | 92c63035 | jcorgan | gr.top_block.__init__(self)
|
| 33 | 92c63035 | jcorgan | |
| 34 | 92c63035 | jcorgan | parser = OptionParser(option_class=eng_option) |
| 35 | 92c63035 | jcorgan | parser.add_option("-O", "--audio-output", type="string", default="", |
| 36 | 92c63035 | jcorgan | help="pcm output device name. E.g., hw:0,0 or /dev/dsp")
|
| 37 | 92c63035 | jcorgan | parser.add_option("-r", "--sample-rate", type="eng_float", default=48000, |
| 38 | 92c63035 | jcorgan | help="set sample rate to RATE (48000)")
|
| 39 | 92c63035 | jcorgan | (options, args) = parser.parse_args () |
| 40 | 92c63035 | jcorgan | if len(args) != 0: |
| 41 | 92c63035 | jcorgan | parser.print_help() |
| 42 | 92c63035 | jcorgan | raise SystemExit, 1 |
| 43 | 92c63035 | jcorgan | |
| 44 | 92c63035 | jcorgan | sample_rate = int(options.sample_rate)
|
| 45 | 92c63035 | jcorgan | ampl = 0.1
|
| 46 | 92c63035 | jcorgan | |
| 47 | 92c63035 | jcorgan | src0 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 350, ampl)
|
| 48 | 92c63035 | jcorgan | src1 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 440, ampl)
|
| 49 | 92c63035 | jcorgan | dst = audio.sink (sample_rate, options.audio_output) |
| 50 | 92c63035 | jcorgan | self.connect (src0, (dst, 0)) |
| 51 | 92c63035 | jcorgan | self.connect (src1, (dst, 1)) |
| 52 | 92c63035 | jcorgan | |
| 53 | 92c63035 | jcorgan | |
| 54 | 92c63035 | jcorgan | if __name__ == '__main__': |
| 55 | 92c63035 | jcorgan | pid = gru.daemonize() |
| 56 | 92c63035 | jcorgan | print "To stop this program, enter 'kill %d'" % pid |
| 57 | 92c63035 | jcorgan | my_top_block().run() |