miegl / PiFmAdv

Advanced Raspberry Pi FM transmitter with RDS encoding
GNU General Public License v3.0
487 stars 82 forks source link

Insert artist and song name in --rt RDS radiotex [HOW-TO] #37

Open pilovis opened 6 years ago

pilovis commented 6 years ago

Rebroadcast internet or local streaming radio to FM with updated Artist and Song name in RDS text

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.

0) prerequisites

install PiFmAdv as user "root" in /root directory, do not install the program as "Pi" user.

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

1) 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 xvjf 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.

2) this is my script to do the dirty job:

sudo nano /root/inject-title.sh

#!/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
# start FM transmitter
/usr/bin/sox --buffer 65536 --input-buffer 65536 -t mp3 http://stream.srg-ssr.ch/m/rsp/mp3_128 -t wav -c 2 - | sudo ./PiFmAdv/src/pi_fm_adv --preemph eu --ctl /tmp/rds_ctl --freq 88.0 --audio - &
# RDS text injection section below - 10 seconds loop
while :
do
/usr/local/bin/ffprobe 2> /dev/null -show_format http://stream.srg-ssr.ch/m/rsp/mp3_128 | 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.

4) give the right permissions to the above script:

sudo chmod 755 /root/inject-title.sh

5) 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.

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

sudo killall pi_fm_adv

Enjoy Maurizio

pilovis commented 6 years ago

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:

/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

pilovis commented 6 years ago

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 hour (1 minute downtime).

sudo crontab -e

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

0 */1 * * * /sbin/reboot

crisdash96 commented 3 years ago

does no refresh the song, here are a one solution edit a bin of a notepad

!/bin/bash

while true do

/usr/local/bin/ffprobe 2> /dev/null -show_format http://stream.srg-ssr.ch/m/rsp/mp3_128 | grep TAG:StreamTitle= | cut -d '=' -f 2 | /usr/bin/perl -ne 'print "PS 'RADIO-88'\nRT $_"' | cat > rds_ctl

sleep 10 exit 0

save the sh and rename notepad to inject-title.sh on the folder on PiFmAdv on pi folder user, no ROOT (root its no necesary, delete this folder and script of root folder with sudo nautilus on terminal)

so now, open a terminal open the folder cd Desktop. and cd PiFmAdv. and cd src mode supersu : sudo su sudo /bin/sh /root/inject-title.sh & cat >rds_ctl &

and insert this for funcionality

sox -t mp3 http://stream.srg-ssr.ch/m/rsp/mp3_128 -t wav - | sudo ./pi_fm_adv --gpio 20 --audio - --pty 9 --freq 88.0 --ctl rds_ctl

its ok, now refresh the tittle and artist song, only this song artist is end, and pass the next song artist , the tittle song and artist apears

100% funcionally