Advanced Raspberry Pi FM transmitter with RDS encoding

Raspberry projects

Advanced Raspberry Pi FM transmitter with RDS encoding

Messaggio da leggereda root » 10/09/2018, 22:03

FM-RDS transmitter using the Raspberry Pi

https://github.com/Miegl/PiFmAdv
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 390
Iscritto il: 10/04/2012, 10:55
Località: Turin

Insert artist and song name in --rt RDS radiotex

Messaggio da leggereda root » 10/09/2018, 22:03

Rebroadcast internet or local streaming radio to FM with updated Artist and Song name in RDS text
(in this example http://webradio.antennevorarlberg.at:80/lounge)

The scope of this How-To is to be able to extract song info and put it into the RT field of RDS in pseudo real time (10 seconds delay)

This is not an issue but a 'How-To', sorry but I didn't find anywhere to put this.

prerequisites

sudo apt-get install sox
sudo apt-get install lame
sudo apt-get install libsox-fmt-mp3
sudo apt-get install perl


install ffmpeg (because we need the ffprobe command to do the job):

download and compile ffmpeg from the source.
https://www.ffmpeg.org/download.html
the current version is ffmpeg-4.0.2.tar.bz2

cd /root
wget https://ffmpeg.org/releases/ffmpeg-4.0.2.tar.bz2
tar -ffmpeg-4.0.2.tar.bz2
cd ffmpeg-4.0.2
./configure
make
sudo make install


IMPORTANT NOTE: on Pi2 the above FFMPEG compile process takes several hours to be completed!! Be extremely patient.

this is my script to do the dirty job:

sudo nano /root/inject-title.sh

Codice: Seleziona tutto
#!/bin/bash
# by pilovis - Italy - parknat12 at yahoo.com
cd /root
/bin/sleep 1
rm /tmp/rds_ctl
/bin/sleep 1
mkfifo /tmp/rds_ctl &
/bin/sleep 1
/usr/bin/sox --buffer 65536 --input-buffer 65536 -t mp3 http://webradio.antennevorarlberg.at:80/hits -t wav -c 2 - | sudo ./PiFmAdv/src/pi_fm_adv --preemph eu --ctl /tmp/rds_ctl --freq 88.0 --audio - &
while :
do
/usr/local/bin/ffprobe 2> /dev/null -show_format http://webradio.antennevorarlberg.at:80/hits | grep TAG:StreamTitle= | cut -d '=' -f 2 | /usr/bin/perl -ne 'print "PS 'RADIO-88'\nRT $_"' > /tmp/rds_ctl
/bin/sleep 10
done

note: I put rds_ctl file in /tmp (RAM tmpfs) to avoid wearing out the SD card.

give the right permissions to the above script:

sudo chmod 755 /root/inject-title.sh

launch the script and it's done:

sudo /bin/sh /root/inject-title.sh &

note: after a few seconds delay the FM radio should start transmitting on 88.0 Mhz with "RADIO-88" station name.

to stop the FM transmitter and all related processes, use the following command:

sudo killall pi_fm_adv

Enjoy
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 390
Iscritto il: 10/04/2012, 10:55
Località: Turin

Re: Advanced Raspberry Pi FM transmitter with RDS encoding

Messaggio da leggereda root » 10/09/2018, 22:05

notes:
with the above script and PiFM trasmitter running, the total CPU usage on a Pi2 overclocked at 1000 Mhz, is about 40%
The total memory usage is less than 50 Mbytes.

You can also create a list of MP3 files to be played in sequence by sox, or better have your own broadcasting station using MPD, see my other how-to here: https://github.com/ChristopheJacquet/PiFmRds/issues/73

If you want to launch this customized "rebroadcasting FM transmitter" at startup, just put the following line in the "/etc/rc.local" file, just before the "exit 0" line:

Codice: Seleziona tutto
/bin/sh /root/inject-title.sh


WARNING: do not launch any script or program, before or after this script, that is using audio otherwise you will have big audio problems (slow speed audio reproduction, like a 45s vinyl disk reproduced at 33 speed) and this is a real bug of this program that should be corrected by the programmers of PiFmAdv
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 390
Iscritto il: 10/04/2012, 10:55
Località: Turin

Re: Advanced Raspberry Pi FM transmitter with RDS encoding

Messaggio da leggereda root » 10/09/2018, 22:05

Another old bug still present and unresolved:

Program quits after 3-4 hours with error: "Could not rewind in audio file. Terminating"

see: https://github.com/ChristopheJacquet/PiFmRds/issues/6 and https://github.com/ChristopheJacquet/PiFmRds/issues/16

I partially mitigated this problem by increasing the sox buffer to 65536 and by rebooting the FM radio trasmitter every 3 hours (1 minute downtime).

sudo crontab -e

and there you have to make the following new entry (in a new line):

Codice: Seleziona tutto
0 */3 * * * /sbin/reboot
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 390
Iscritto il: 10/04/2012, 10:55
Località: Turin


Torna a Raspberry

Chi c’è in linea

Visitano il forum: Nessuno e 1 ospite