Houston, we have a trunk.
[debian/gnuradio] / gnuradio-core / src / python / gnuradio / blksimpl / digital_voice.py.real
1 #!/usr/bin/env python
2 #
3 # Copyright 2005 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 2, 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., 59 Temple Place - Suite 330,
20 # Boston, MA 02111-1307, USA.
21
22
23 """
24 Digital voice Tx and Rx using GSM 13kbit vocoder and GMSK.
25
26 Runs channel at 32kbit/sec.  Currently uses fake channel coding,
27 but there's room for a rate 1/2 coder.
28 """
29
30 from gnuradio import gr, gru
31 from gnuradio.blksimpl.gmsk import gmsk_mod, gmsk_demod
32
33 from gnuradio.vocoder import gsm_full_rate
34
35 # Size of gsm full rate speech encoder output packet in bytes
36
37 GSM_FRAME_SIZE = 33
38
39 # Size of packet in bytes that we send to GMSK modulator:
40 #
41 # Target: 256kS/sec air rate.
42 #
43 #  256kS  1 sym   1 bit   1 byte   0.020 sec   80 bytes
44 #  ---- * ----- * ----- * ------ * --------- = --------
45 #  sec    8 S     1 sym   8 bits     frame      frame
46 #
47 # gr_simple_framer add 10 bytes of overhead.
48
49 AIR_FRAME_SIZE = 70
50
51
52 class digital_voice_tx(gr.hier_block):
53     """
54     Hierarchical block for digital voice tranmission.
55
56     The input is 8kS/sec floating point audio in the range [-1,+1]
57     The output is 256kS/sec GMSK modulated complex baseband signal in the range [-1,+1].
58     """
59     def __init__(self, fg):
60         samples_per_symbol = 8
61         symbol_rate = 32000
62         bt = 0.3                # Gaussian filter bandwidth * symbol time
63
64         src_scale = gr.multiply_const_ff(32767)
65         f2s = gr.float_to_short()
66         voice_coder = gsm_full_rate.encode_sp()
67
68         channel_coder = gr.fake_channel_encoder_pp(GSM_FRAME_SIZE, AIR_FRAME_SIZE)
69         p2s = gr.parallel_to_serial(gr.sizeof_char, AIR_FRAME_SIZE)
70
71         mod = gmsk_mod(fg, sps=samples_per_symbol,
72                        symbol_rate=symbol_rate, bt=bt,
73                        p_size=AIR_FRAME_SIZE)
74
75         fg.connect(src_scale, f2s, voice_coder, channel_coder, p2s, mod)
76         gr.hier_block.__init__(self, fg, src_scale, mod)
77
78
79 class digital_voice_rx(gr.hier_block):
80     """
81     Hierarchical block for digital voice reception.
82
83     The input is 256kS/sec GMSK modulated complex baseband signal.
84     The output is 8kS/sec floating point audio in the range [-1,+1]
85     """
86     def __init__(self, fg):
87         samples_per_symbol = 8
88         symbol_rate = 32000
89
90         demod = gmsk_demod(fg, sps=samples_per_symbol,
91                            symbol_rate=symbol_rate, 
92                            p_size=AIR_FRAME_SIZE)
93
94         s2p = gr.serial_to_parallel(gr.sizeof_char, AIR_FRAME_SIZE)
95         channel_decoder = gr.fake_channel_decoder_pp(AIR_FRAME_SIZE, GSM_FRAME_SIZE)
96
97         voice_decoder = gsm_full_rate.decode_ps()
98         s2f = gr.short_to_float ()
99         sink_scale = gr.multiply_const_ff(1.0/32767.)
100
101         fg.connect(demod, s2p, channel_decoder, voice_decoder, s2f, sink_scale)
102         gr.hier_block.__init__(self, fg, demod, sink_scale)