~ubuntu-branches/ubuntu/trusty/gnuradio/trusty

« back to all changes in this revision

Viewing changes to gr-cvsd-vocoder/src/python/encdec.py

  • Committer: Bazaar Package Importer
  • Author(s): Kamal Mostafa
  • Date: 2010-03-13 07:46:01 UTC
  • mfrom: (2.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100313074601-zjsa893a87bozyh7
Tags: 3.2.2.dfsg-1ubuntu1
* Fix build for Ubuntu lucid (LP: #260406)
  - add binary package dep for libusrp0, libusrp2-0: adduser
  - debian/rules clean: remove pre-built Qt moc files

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
#
 
3
# Copyright 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, blks2
 
24
from gnuradio import audio
 
25
from gnuradio.vocoder import cvsd_vocoder
 
26
 
 
27
def build_graph():
 
28
    sample_rate = 8000
 
29
    scale_factor = 32000
 
30
    
 
31
    tb = gr.top_block()
 
32
    src = audio.source(sample_rate, "plughw:0,0")
 
33
    src_scale = gr.multiply_const_ff(scale_factor)
 
34
 
 
35
    interp = blks2.rational_resampler_fff(8, 1)
 
36
    f2s = gr.float_to_short ()
 
37
 
 
38
    enc = cvsd_vocoder.encode_sb()
 
39
    dec = cvsd_vocoder.decode_bs()
 
40
 
 
41
    s2f = gr.short_to_float ()
 
42
    decim = blks2.rational_resampler_fff(1, 8)
 
43
 
 
44
    sink_scale = gr.multiply_const_ff(1.0/scale_factor)
 
45
    sink = audio.sink(sample_rate, "plughw:0,0")
 
46
 
 
47
    tb.connect(src, src_scale, interp, f2s, enc)
 
48
    tb.connect(enc, dec, s2f, decim, sink_scale, sink)
 
49
 
 
50
    if 0: # debug
 
51
        tb.conect(src, gr.file_sink(gr.sizeof_float, "source.dat"))
 
52
        tb.conect(src_scale, gr.file_sink(gr.sizeof_float, "src_scale.dat"))
 
53
        tb.conect(interp, gr.file_sink(gr.sizeof_float, "interp.dat"))
 
54
        tb.conect(f2s, gr.file_sink(gr.sizeof_short, "f2s.dat"))
 
55
        tb.conect(enc, gr.file_sink(gr.sizeof_char,  "enc.dat"))
 
56
        tb.conect(dec, gr.file_sink(gr.sizeof_short, "dec.dat"))
 
57
        tb.conect(s2f, gr.file_sink(gr.sizeof_float, "s2f.dat"))
 
58
        tb.conect(decim, gr.file_sink(gr.sizeof_float, "decim.dat"))
 
59
        tb.conect(sink_scale, gr.file_sink(gr.sizeof_float, "sink_scale.dat"))
 
60
        
 
61
    return tb
 
62
 
 
63
if __name__ == '__main__':
 
64
    tb = build_graph()
 
65
    print "Enter CTRL-C to stop"
 
66
    try:
 
67
        tb.run()
 
68
    except KeyboardInterrupt:
 
69
        pass