3 # Copyright 2005,2006,2007 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, gru, eng_notation, optfir
24 from gnuradio import audio
25 from gnuradio import usrp
26 from gnuradio import blks2
27 from gnuradio.eng_option import eng_option
28 from optparse import OptionParser
29 from usrpm import usrp_dbid
33 def pick_subdevice(u):
35 The user didn't specify a subdevice on the command line.
36 Try for one of these, in order: TV_RX, BASIC_RX, whatever is on side A.
40 return usrp.pick_subdev(u, (usrp_dbid.TV_RX,
41 usrp_dbid.TV_RX_REV_2,
45 class wfm_rx_block (gr.top_block):
48 gr.top_block.__init__(self)
50 parser=OptionParser(option_class=eng_option)
51 parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None,
52 help="select USRP Rx side A or B (default=A)")
53 parser.add_option("", "--f1", type="eng_float", default=100.7e6,
54 help="set 1st station frequency to FREQ", metavar="FREQ")
55 parser.add_option("", "--f2", type="eng_float", default=102.5e6,
56 help="set 2nd station freq to FREQ", metavar="FREQ")
57 parser.add_option("-g", "--gain", type="eng_float", default=40,
58 help="set gain in dB (default is midpoint)")
59 parser.add_option("-O", "--audio-output", type="string", default="",
60 help="pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp")
62 (options, args) = parser.parse_args()
67 if abs(options.f1) < 1e6:
70 if abs(options.f2) < 1e6:
73 if abs(options.f1 - options.f2) > 5.5e6:
74 print "Sorry, two stations must be within 5.5MHz of each other"
77 f = (options.f1, options.f2)
84 self.u = usrp.source_c(0, nchan=2) # usrp is data source
86 adc_rate = self.u.adc_rate() # 64 MS/s
88 self.u.set_decim_rate(usrp_decim)
89 usrp_rate = adc_rate / usrp_decim # 320 kS/s
91 demod_rate = usrp_rate / chanfilt_decim
93 audio_rate = demod_rate / audio_decimation # 32 kHz
96 if options.rx_subdev_spec is None:
97 options.rx_subdev_spec = pick_subdevice(self.u)
99 mv = usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)
100 mv |= (mv << 8) & 0xff00 # both DDC inputs setup same way
102 self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec)
103 print "Using RX d'board %s" % (self.subdev.side_and_name(),)
106 # deinterleave two channels from FPGA
107 di = gr.deinterleave(gr.sizeof_gr_complex)
109 # wire up the head of the chain
110 self.connect(self.u, di)
112 # sound card as final sink
113 audio_sink = audio.sink(int(audio_rate), options.audio_output)
115 # taps for channel filter
116 chan_filt_coeffs = optfir.low_pass (1, # gain
117 usrp_rate, # sampling rate
118 80e3, # passband cutoff
119 115e3, # stopband cutoff
120 0.1, # passband ripple
121 60) # stopband attenuation
122 #print len(chan_filt_coeffs)
124 mid_freq = (f[0] + f[1]) / 2
125 # set front end PLL to middle frequency
126 ok, baseband_freq = self.subdev.set_freq(mid_freq)
129 chan_filt = gr.fir_filter_ccf (chanfilt_decim, chan_filt_coeffs)
130 guts = blks2.wfm_rcv (demod_rate, audio_decimation)
131 volume_control = gr.multiply_const_ff(self.vol)
132 self.connect((di, n), chan_filt)
133 self.connect(chan_filt, guts, volume_control)
134 self.connect(volume_control, (audio_sink, n))
135 dxc_freq, inverted = usrp.calc_dxc_freq(f[n], baseband_freq,
136 self.u.converter_rate())
137 self.u.set_rx_freq(n, dxc_freq)
140 if options.gain is None:
141 # if no gain was specified, use the mid-point in dB
142 g = self.subdev.gain_range()
143 options.gain = float(g[0]+g[1])/2
147 self.set_gain(options.gain)
150 def set_vol (self, vol):
152 self.volume_control.set_k(self.vol)
155 def set_gain(self, gain):
156 self.subdev.set_gain(gain)
159 # Avoid weak-reference error
162 if __name__ == '__main__':
166 except KeyboardInterrupt: