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 blks2
26 from gnuradio.eng_option import eng_option
27 from optparse import OptionParser
31 class wfm_rx_block (gr.top_block):
33 gr.top_block.__init__(self)
35 usage = "usage: %prog [options] input-samples-320kS.dat output.wav"
36 parser=OptionParser(option_class=eng_option, usage=usage)
37 parser.add_option("-V", "--volume", type="eng_float", default=None,
38 help="set volume (default is midpoint)")
40 (options, args) = parser.parse_args()
45 input_filename = args[0]
46 output_filename = args[1]
52 self.src = gr.file_source(gr.sizeof_gr_complex, input_filename, False)
54 adc_rate = 64e6 # 64 MS/s
56 usrp_rate = adc_rate / usrp_decim # 320 kS/s
58 demod_rate = usrp_rate / chanfilt_decim
60 audio_rate = demod_rate / audio_decimation # 32 kHz
63 chan_filt_coeffs = optfir.low_pass (1, # gain
64 usrp_rate, # sampling rate
65 80e3, # passband cutoff
66 115e3, # stopband cutoff
67 0.1, # passband ripple
68 60) # stopband attenuation
69 #print len(chan_filt_coeffs)
70 chan_filt = gr.fir_filter_ccf (chanfilt_decim, chan_filt_coeffs)
73 #self.guts = blks2.wfm_rcv (demod_rate, audio_decimation)
74 self.guts = blks2.wfm_rcv_pll (demod_rate, audio_decimation)
76 # FIXME rework {add,multiply}_const_* to handle multiple streams
77 self.volume_control_l = gr.multiply_const_ff(self.vol)
78 self.volume_control_r = gr.multiply_const_ff(self.vol)
80 # wave file as final sink
82 sink = gr.wavfile_sink(output_filename, 2, int(audio_rate), 16)
84 sink = audio.sink (int (audio_rate),
88 # now wire it all together
89 self.connect (self.src, chan_filt, self.guts)
90 self.connect ((self.guts, 0), self.volume_control_l, (sink, 0))
91 self.connect ((self.guts, 1), self.volume_control_r, (sink, 1))
93 self.guts.stereo_carrier_pll_recovery.squelch_enable(True)
96 #print "FYI: This implementation of the stereo_carrier_pll_recovery has no squelch implementation yet"
98 if options.volume is None:
99 g = self.volume_range()
100 options.volume = float(g[0]+g[1])/2
104 self.set_vol(options.volume)
106 self.guts.stereo_carrier_pll_recovery.set_lock_threshold(options.squelch)
109 #print "FYI: This implementation of the stereo_carrier_pll_recovery has no squelch implementation yet"
112 def set_vol (self, vol):
113 g = self.volume_range()
114 self.vol = max(g[0], min(g[1], vol))
115 self.volume_control_l.set_k(10**(self.vol/10))
116 self.volume_control_r.set_k(10**(self.vol/10))
118 def volume_range(self):
119 return (-20.0, 0.0, 0.5)
122 if __name__ == '__main__':
126 except KeyboardInterrupt: