835f9aafcb34558d97909a6ff21200ff64038a19
[debian/gnuradio] / gnuradio-examples / python / network / dial_tone_source.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2006,2007 Free Software Foundation, Inc.
4
5 # This file is part of GNU Radio
6
7 # GNU Radio is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3, or (at your option)
10 # any later version.
11
12 # GNU Radio is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Radio; see the file COPYING.  If not, write to
19 # the Free Software Foundation, Inc., 51 Franklin Street,
20 # Boston, MA 02110-1301, USA.
21
22
23 from gnuradio import gr
24 from gnuradio.eng_option import eng_option
25 from optparse import OptionParser
26
27 class dial_tone_source(gr.top_block):
28     def __init__(self, src, dst, port, pkt_size, sample_rate):
29         gr.top_block.__init__(self, "dial_tone_source")
30
31         amplitude = 0.3
32         src0 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 350, amplitude)
33         src1 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 440, amplitude)
34         add = gr.add_ff()
35
36         # Throttle needed here to account for the other side's audio card sampling rate
37         thr = gr.throttle(gr.sizeof_float, sample_rate)
38         sink = gr.udp_sink(gr.sizeof_float, src, 0, dst, port, pkt_size)
39         self.connect(src0, (add, 0))
40         self.connect(src1, (add, 1))
41         self.connect(add, thr, sink)
42
43 if __name__ == '__main__':
44     parser = OptionParser(option_class=eng_option)
45     parser.add_option("", "--src-name", type="string", default="localhost",
46                       help="local host name (domain name or IP address)")
47     parser.add_option("", "--dst-name", type="string", default="localhost",
48                       help="Remote host name (domain name or IP address")
49     parser.add_option("", "--dst-port", type="int", default=65500,
50                       help="port value to connect to")
51     parser.add_option("", "--packet-size", type="int", default=1472,
52                       help="packet size.")
53     parser.add_option("-r", "--sample-rate", type="int", default=8000,
54                       help="audio signal sample rate [default=%default]")
55     (options, args) = parser.parse_args()
56     if len(args) != 0:
57         parser.print_help()
58         raise SystemExit, 1
59
60     # Create an instance of a hierarchical block
61     top_block = dial_tone_source(options.src_name, options.dst_name, options.dst_port,
62                                  options.packet_size, options.sample_rate)
63     
64     try:    
65         # Run forever
66         top_block.run()
67     except KeyboardInterrupt:
68         # Ctrl-C exits
69         pass
70