Imported Upstream version 3.0.4
[debian/gnuradio] / gnuradio-examples / python / audio / dialtone_v.py
1 #!/usr/bin/env python
2
3 # Copyright 2006 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, audio
24 from math import pi, sin
25
26 """
27 This test script demonstrates the use of element-wise vector processing
28 vs. stream processing.  The example is artificial in that the stream
29 version in dial_tone.py is the normal way to do it; in addition, the
30 envelope processing here is just for demo purposes and isn't needed.
31 """
32
33 # For testing different buffer sizes
34 rate = 48000
35
36 fg = gr.flow_graph()
37
38 # Two streams of floats
39 a = gr.sig_source_f(rate, gr.GR_SIN_WAVE, 350, 0.5, 0.0);
40 b = gr.sig_source_f(rate, gr.GR_SIN_WAVE, 440, 0.5, 0.0);
41
42 # Turn them into vectors of length 'size'
43 av = gr.stream_to_vector(gr.sizeof_float, rate)
44 bv = gr.stream_to_vector(gr.sizeof_float, rate)
45
46 # Make a vector adder for float vectors
47 adder = gr.add_vff(rate)
48
49 # Make a 1 Hz sine envelope
50 envelope = [sin(2*pi*x/rate)*0.5 for x in range(rate)]
51 multiplier = gr.multiply_const_vff(envelope)
52
53 # Make an offset adder
54 offset = gr.add_const_vff((0.5,)*rate)
55
56 # Turn the vector back into a stream of floats
57 result = gr.vector_to_stream(gr.sizeof_float, rate)
58
59 # Play it
60 sink = audio.sink(rate)
61
62 fg.connect(a, av)
63 fg.connect(b, bv)
64 fg.connect(av, (adder, 0))
65 fg.connect(bv, (adder, 1))
66 fg.connect(adder, multiplier, offset, result, sink)
67
68 try:
69     fg.run()
70 except KeyboardInterrupt:
71     pass