discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Discuss-gnuradio] Listen to Mp3 via FM broadcast


From: jingx kwan
Subject: [Discuss-gnuradio] Listen to Mp3 via FM broadcast
Date: Sun, 25 Jan 2009 15:00:55 -0500

Hello,

I just have the GNU Radio equipment setups and runs together with the Ubutun 8.10 with my Latitude D610 notebook.
I have successfully test and the GNU software is running properly. Still, I have problem to run a code posted on-line by Elie Salameh. I typed and copied the code exactly as what it is, but I still fail.

The error message said:
address@hidden:~/gnuradio/gnuradio-examples/python/usrp$ ./gnu_fm2.py -l 2.plsNumber of items in list 3

/home/usrp/gnuradio/gnuradio-examples/python/usrp/se-exp-steve-fossett-21jan09_0.Mp3
/home/usrp/gnuradio/gnuradio-examples/python/usrp/se-tia-presidential-inaugurations-19jan09-CQ_0.Mp3
/home/usrp/gnuradio/gnuradio-examples/python/usrp/jan-24-09-AS-Paul-Bunyan_0.Mp3
Using TX d'board A: Flex 2400 Tx MIMO B
Traceback (most recent call last):
  File "./gnu_fm2.py", line 132, in <module>
    wfm_tx()
  File "./gnu_fm2.py", line 85, in __init__
    if not self.set_freq(options.freq):
  File "./gnu_fm2.py", line 123, in set_freq
    r = self.u.tune(self.subdev.which, self.subdev, target_freq)
  File "/usr/local/lib/python2.5/site-packages/gnuradio/usrp/usrp_swig.py", line 2688, in __tune
    r = self._real_tune(chan, db, target_freq, tr)
  File "/usr/local/lib/python2.5/site-packages/gnuradio/usrp/usrp_swig.py", line 2089, in _real_tune
    return _usrp_swig.usrp_sink_c_sptr__real_tune(*args, **kwargs)
TypeError: in method 'usrp_sink_c_sptr__real_tune', argument 2 of type 'int'
========================================
the code

#!/usr/bin/python

from gnuradio import gr, eng_notation
from gnuradio import usrp
from gnuradio import audio
from gnuradio import blks2
from gnuradio.eng_option import eng_option
from optparse import OptionParser
from usrpm import usrp_dbid
import math, re, sys, thread, time, tempfile, os, random
from gnuradio.wxgui import stdgui2, fftsink2
import wx


# this function sends a command to Linux that will
# use sox to transform mp3 to raw
def mp3toraw(filename,outputfile):
    print("nice -n 19 sox \"%s\" -r 32000 -t raw -f -l -c 1 %s\n" %
(filename,outputfile))
    os.system("nice -n 19 sox \"%s\" -r 32000 -t raw -f -l -c 1 %s" %
(filename,outputfile))
# this function will read the location of the mp3 files out of the
#.pls file
def read_playlist(fname):
    input = open(fname, 'r')
    playlist=[]
    l = input.readline()
    # NumberOfEntries
    l = input.readline()
    nentries = int(re.findall("NumberOfEntries=([0-9]+)",l)[0])
    print "Number of items in list %d\n" % nentries
    i = 1
    while l:
        l=input.readline()
        filepath = re.findall("File[0-9]+=(.*)$",l)
        if filepath:
            print filepath[0]
            playlist.append(filepath[0])
            i = i + 1
    input.close()
    return(playlist)
#this function will create a temprary .raw file that will used by the sox command
def mktempfn():
    tf = tempfile.mkstemp(".raw")
    outputfile = tf[1]
    os.close(tf[0])
    os.remove(tf[1])
    return(outputfile)
# this code is used for mudulation
# it takes options from the command line
# most of this code is take from fm_tx4.py
class wfm_tx:
    def __init__(self):
        parser = OptionParser (option_class=eng_option)
        parser.add_option("-T", "--tx-subdev-spec", type="subdev",default=None,help="select USRP Tx side A or B")
        parser.add_option("-f", "--freq", type="eng_float",default=90.1e6, help="set Tx frequency to FREQ (default 90.1e6)", metavar="FREQ")
        parser.add_option("-l","--playlist", action="" default="1.pls", help="MP3 playlist containing files to air.")
        parser.add_option("","--debug", action="" default=False,help="Launch Tx debugger")
        (options, args) = parser.parse_args ()
        if len(args) != 0:
            parser.print_help()
            sys.exit(1)
        if options.playlist == None:
            print "No playlist specified\n"
            sys.exit()
        # parse playlist
        playlist = read_playlist(options.playlist)
        # setup IQ rate to 320kS/s and audio rate to 32kS/s
        self.u = usrp.sink_c()
        self.dac_rate = self.u.dac_rate()                    # 128 MS/s
        self.usrp_interp = 400
        self.u.set_interp_rate(self.usrp_interp)
        self.usrp_rate = self.dac_rate / self.usrp_interp    # 320 kS/s
        self.sw_interp = 10
        self.audio_rate = self.usrp_rate / self.sw_interp    # 32 kS/s
        # determine the daughterboard subdevice we're using
        if options.tx_subdev_spec is None:
            options.tx_subdev_spec = usrp.pick_tx_subdevice(self.u)
        m = usrp.determine_tx_mux_value(self.u, options.tx_subdev_spec)
        self.u.set_mux(m)
        self.subdev = usrp.selected_subdev(self.u,options.tx_subdev_spec)
        print "Using TX d'board %s" % (self.subdev.side_and_name(),)
        self.subdev.set_gain(self.subdev.gain_range()[1])    # set max Tx gain

        if not self.set_freq(options.freq):
            freq_range = self.subdev.freq_range()
            print "Failed to set frequency to %s. Daughterboard supports %s to %s" % (
                eng_notation.num_to_str(options.freq),
                eng_notation.num_to_str(freq_range[0]),
                eng_notation.num_to_str(freq_range[1]))
            raise SystemExit

        self.subdev.set_enable(True)                         # enable transmitter
        print "TX freq %1.2f MHz\n" % (options.freq/1e6)
        gain = gr.multiply_const_cc(4000.0)
        i = 0
        while 1:
            self.fg = gr.flow_graph()
            outputfile = mktempfn()
            # write raw sound to named pipe in background
            thread.start_new_thread(mp3toraw,(playlist[i],outputfile))
            # wait untill the conversion of mp3 to raw is completed
            time.sleep(3)
            print "File size %d\n" % int(os.stat(outputfile)[6])
            #specify the source file
            src = "" outputfile, False)
            #configure the modulation block
            fmtx = blks.wfm_tx(self.fg, self.audio_rate,
self.usrp_rate,max_dev=75e3, tau=75e-6)
            # connect blocks
            self.fg.connect(src, fmtx, gain, self.u)
            print "starting to transmit\n"
            self.fg.run()
            print "done..."
            # remove the temprary file
            os.remove(outputfile)
            # stop the sox command if it is still working
            os.system("killall sox")
    def set_freq(self, target_freq):
        """
        Set the center frequency we're interested in.
        """
        r = self.u.tune(self.subdev.which, self.subdev, target_freq)
        if r:
            print "r.baseband_freq =",eng_notation.num_to_str(r.baseband_freq)
            print "r.dxc_freq      =",eng_notation.num_to_str(r.dxc_freq)
            print "r.residual_freq =",eng_notation.num_to_str(r.residual_freq)
            print "r.inverted      =", r.inverted
            return True
        return False
if __name__ == '__main__':
    wfm_tx()


reply via email to

[Prev in Thread] Current Thread [Next in Thread]