Listen to Mp3 via FM broadcast


#1

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:
usrp@usrp-laptop:~/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
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=“store”,
default=“1.pls”, help=“MP3 playlist containing files to air.”)
parser.add_option("","–debug", action=“store_true”,
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 = gr.file_source(gr.sizeof_float, 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()


#2

could you post a link to this code?
I could take a look at it for you…

Dimitris S.
“If you think you’re too small to make a difference, try sleeping with
a mosquito!” - Amnesty International


#3

hi all,

does the problem still continue?

also i have an error msg at below.

didem@didem:~/Desktop/gnuradio/gnuradio-examples/python/usrp$
./didemdenemeraw.py -1 dodi.pls
Traceback (most recent call last):
File “./didemdenemeraw.py”, line 4, in ?
from gnuradio import gr, eng_notation
ImportError: No module named gnuradio

i am using ubuntu 8.04 and python 2.5 .

thanks,

----- Original Message ----
From: Dimitris S. removed_email_address@domain.invalid
To: jingx kwan removed_email_address@domain.invalid
Cc: removed_email_address@domain.invalid
Sent: Tuesday, January 27, 2009 6:21:31 PM
Subject: Re: [Discuss-gnuradio] Listen to Mp3 via FM broadcast

could you post a link to this code?
I could take a look at it for you…

Dimitris S.
“If you think you’re too small to make a difference, try sleeping with
a mosquito!” - Amnesty International

On Sun, Jan 25, 2009 at 21:00, jingx kwan removed_email_address@domain.invalid wrote:

2.plsNumber of items in list 3
File “./gnu_fm2.py”, line 123, in set_freq

from gnuradio.wxgui import stdgui2, fftsink2

this function will read the location of the mp3 files out of the

while l:

def mktempfn():
parser = OptionParser (option_class=eng_option)
parser.print_help()
self.u.set_interp_rate(self.usrp_interp)
self.subdev.set_gain(self.subdev.gain_range()[1]) # set max Tx

        # wait untill the conversion of mp3 to raw is completed
        self.fg.run()
    if r:

Discuss-gnuradio mailing list
removed_email_address@domain.invalid
http://lists.gnu.org/mailman/listinfo/discuss-gnuradio


Discuss-gnuradio mailing list
removed_email_address@domain.invalid
http://lists.gnu.org/mailman/listinfo/discuss-gnuradio


#4

On Sun, Mar 08, 2009 at 04:01:53PM -0700, didem colak wrote:

File “./didemdenemeraw.py”, line 4, in ?
from gnuradio import gr, eng_notation
ImportError: No module named gnuradio

i am using ubuntu 8.04 and python 2.5 .
thanks,

Did you set PYTHONPATH?

Did you read and follow these directions:
http://gnuradio.org/trac/wiki/UbuntuInstall#BrokenlibtoolonDebianandUbuntu

Eric


#5

hi all,

does the problem still continue?

also i have an error msg at below.

didem@didem:~/Desktop/gnuradio/gnuradio-examples/python/usrp$
./didemdenemeraw.py -1 dodi.pls
Traceback (most recent call last):
File “./didemdenemeraw.py”, line 4, in ?
from gnuradio import gr, eng_notation
ImportError: No module named gnuradio

i am using ubuntu 8.04 and python 2.5 .

thanks,

----- Original Message ----
From: Dimitris S. removed_email_address@domain.invalid
To: jingx kwan removed_email_address@domain.invalid
Cc: removed_email_address@domain.invalid
Sent: Tuesday, January 27, 2009 6:21:31 PM
Subject: Re: [Discuss-gnuradio] Listen to Mp3 via FM broadcast

could you post a link to this code?
I could take a look at it for you…

Dimitris S.
“If you think you’re too small to make a difference, try sleeping with
a mosquito!” - Amnesty International

On Sun, Jan 25, 2009 at 21:00, jingx kwan removed_email_address@domain.invalid wrote:

2.plsNumber of items in list 3
File “./gnu_fm2.py”, line 123, in set_freq

from gnuradio.wxgui import stdgui2, fftsink2

this function will read the location of the mp3 files out of the

while l:
def mktempfn():
parser = OptionParser (option_class=eng_option)
parser.print_help()
self.u.set_interp_rate(self.usrp_interp)
self.subdev.set_gain(self.subdev.gain_range()[1]) # set max Tx

       # wait untill the conversion of mp3 to raw is completed
       self.fg.run()
   if r:

Discuss-gnuradio mailing list
removed_email_address@domain.invalid
http://lists.gnu.org/mailman/listinfo/discuss-gnuradio


Discuss-gnuradio mailing list
removed_email_address@domain.invalid
http://lists.gnu.org/mailman/listinfo/discuss-gnuradio


Discuss-gnuradio mailing list
removed_email_address@domain.invalid
http://lists.gnu.org/mailman/listinfo/discuss-gnuradio


#6

Hello Eric,

I late to reply to your email. I have set the paths according to the
installation.
However, I still can not listen to any radio signal.
I just found out that I need TVRX in order for me to receive the FM
radio.

Thank you


#7

The code in Elie’s PDF looks like my old fmradio.py script. In most
universities verbatim copying is a serious offence, at least if you
strip copyright from the file.

Well at least the guy probably didn’t get a very good grade because my
code was so awful :slight_smile:

I can look at the code at some point, but as the comments in the
original code say, the code only works with linux, and it requires
sox. Also I would probably start trying with a BasicTX daughterboard,
I never tried it with a FLEX 2400.

Here is my “original” code, it’s outdated and could use a lot of work:

http://www.mep.fi/viewcvs/fmradio/?root=cvs

It would be cool to do this properly some day. I would love to have a
super MP3 to FM system that transmits many different channels at the
same time, or maybe even does it the other way around: a full FM-band
TiVo that generates mp3s out of multiple simultaneous broadcasts.

BR,
juha


#8

I late to reply to your email. I have set the paths according to the
installation.

I think the real problem was the python2.4 on the first line. You
have probably installed gnuradio with 2.5.

However, I still can not listen to any radio signal.
I just found out that I need TVRX in order for me to receive the FM radio.

You can receive FM radio with BasicRX, and also every plain old radio
set.

I now updated my fmradio.py script and tested that it works at least
with BasicTX. I guess this could be done a lot better, I just don’t
have time right now. This was originally a one night hack, and it will
remain one for now. The script can be found here:

http://www.mep.fi/viewcvs/fmradio/fmradio.py?revision=1.4&root=cvs&view=markup

I also noticed that debian’s sox didn’t support mp3 out of the box
anymore, so I compiled my own. Why no support? Politics:

https://bugs.launchpad.net/ubuntu/+source/sox/+bug/223783

juha


#9

no need to compile from source, just install libsox-fmt-mp3

Dimitris S.
“If you think you’re too small to make a difference, try sleeping with
a mosquito!” - Amnesty International