3 # Copyright 2006 Free Software Foundation, Inc.
5 # This file is part of GNU Radio
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)
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.
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.
23 from gnuradio import gr, audio
24 from math import pi, sin
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.
33 # For testing different buffer sizes
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);
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)
46 # Make a vector adder for float vectors
47 adder = gr.add_vff(rate)
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)
53 # Make an offset adder
54 offset = gr.add_const_vff((0.5,)*rate)
56 # Turn the vector back into a stream of floats
57 result = gr.vector_to_stream(gr.sizeof_float, rate)
60 sink = audio.sink(rate)
64 fg.connect(av, (adder, 0))
65 fg.connect(bv, (adder, 1))
66 fg.connect(adder, multiplier, offset, result, sink)
70 except KeyboardInterrupt: