ChristopheJacquet / PiFmRds

FM-RDS transmitter using the Raspberry Pi's PWM
GNU General Public License v3.0
1.44k stars 331 forks source link

use mpd/mpc with PiFmRds to rebroadcast internet radios and/or MP3 playlist #73

Open pilovis opened 7 years ago

pilovis commented 7 years ago

This is the audio section for /etc/mpd.conf to use PiFmRds as the output audio device:

_audio_output { type "pipe" name "PiFm" command "sox -t raw -esi -b32 -c2 -r44100 - -t wav - firfit /root/75usPreEmphasis.ff | sudo /root/PiFmRds/src/pi_fmrds -freq 88.0 -rt 'Rochenroll Ciulers' -ps RADIO-88 -audio -" format "44100:32:2" }

note: eventually adjust the paths on the above, same for frequence, rt and ps. don't forget to comment out (or to remove) all the other "audio_output" sections

You need to push your Rasperry Pi2 up to 1000 Mhz (Pi2 overclock), to get good results (cpu and LAN controller heathsinks needed for prolungate operations).

CPU usage is about 55% @ 1000 Mhz overclocking on Pi2.

pilovis commented 7 years ago

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

pilovis commented 7 years ago

this is my 75usPreEmphasis.ff file , not a real 75 or 50uS emphasis, but it gives the best audio output, at least here in Europe:

20 0.000 50 0.001 100 0.004 500 0.096 600 0.138 700 0.186 800 0.241 900 0.303 1000 0.370 2000 1.290 3000 2.430 4000 3.540 5000 4.530 6000 5.380 7000 6.100 8000 6.690 9000 7.190 10000 7.610 11000 7.950 12000 8.250 13000 8.490 14000 8.710 15000 8.890 16000 9.050 17000 9.180 18000 9.300 19000 9.400 20000 9.490 21000 10.000 22000 10.313 23000 10.696 24000 11.063

pilovis commented 7 years ago

The best would be to get the playing song's name/artist from MPD with "mpc current" command and to inject it to RDS "rt"

pilovis commented 7 years ago

I have an idea, what about if we create a network of PiFmRDS transmitters, all connected to a single and centralized internet radio stream? Something like PiFmRDSNetradio :) Each transmitter uses a very low transmitting power (mostly legal in many countries), but by connecting many togheter, located in different areas, we could create a bigger coverage, like the huge WiFi FON free hot spots.

pilovis commented 7 years ago

By connecting an antenna like this one, the coverage range will increase up to 500 mt in open air without obstacles (you should check before if it is legal on your country, probably not ...):

https://www.amazon.com/Stellar-Labs-30-2435-Outdoor-Omnidirectional/dp/B00DHHOZBI

connect the hot pole of the antenna, by a 75 ohm coaxial cable, to a capacitor of 1 nF connected in series to the GPIO 4 of the Raspberry (needed to avoid short circuit vs GND) and the cold pole to GND of raspberry and also to ground (earth ground) like this picture: http://www.hamradio.in/circuits/images/FMAntenna_Fig2.gif

Keep the coaxial cable lenght shorter than a few meters.

A bandpass filter between raspberry and the antenna, to cut the harmonics frequences, is absolutely needed! like this one: http://electronics-diy.com/schematics/803/LPF+Bro.gif (keep connections as short as possible, use ceramic capacitors and don't forget the 1nf capacitor soldered to GPIO4 pin (in series) to avoid short circuit vs GND). Filter used for eliminate unwanted harmonic frequency at second and third. Notch filter, Band Pass Filter (BPF), and High Pass Filter (HPF) sometime combined in constructing LPF design. Schematic below for FM Broadcast Lowpass Filter 88-108 MHz. It has been tested with a good result. Note : Make the coils at 74 nH and eventually trim them to adjust exact value.

pilovis commented 7 years ago

If you want to make the transmitter more robust and less sensitive to micro network outages, add these lines at the end of the /etc/mpd.conf file:

samplerate_converter "internal" audio_buffer_size "8192"
buffer_before_play "10%"

To get more infos on MPD/MPC see my specific how-to on OpenWRT forum: [HowTo] Openwrt cheap Digital Stereo WiFi Internet Radio & MP3 Player https://forum.openwrt.org/viewtopic.php?id=49013

Santanix commented 7 years ago

Hello! I'm new to Pi but I manage to trasmit mpd music to FM. What I cannot is with your code because I can't find the file "75usPreEmphasis.ff". I hear some background noise and in another thread you say the sound get better with PreEmphasis. My cod working is:

audio_output { type "pipe" name "PiFm" command "sox -t raw -b 32 -c 2 -r 44100 -e signed-integer - -t wav -b 32 -c 2 -r 44100 - | sudo /home/pi/PiFmRds/src/pi_fm_rds -audio -" format "44100:32:1" }

Can you explain how I can get PreEnphasis working with your file PreEnphasis?

Thank you!

spabinger commented 7 years ago

Add this parameter to your sox command (see first post) - firfit /root/75usPreEmphasis.ff

Santanix commented 7 years ago

Thanks for the reply! I manage to get it working with the code equal to yours, I only changed the path to the file 75usPreEmphasis because I couldn't find the file so I created one in dir of PiFmRds. command "sox -t raw -esi -b32 -c2 -r44100 - -t wav - firfit /pi/PiFmRds/75usPreEmphasis.ff | sudo /pi/PiFmRds/src/pi_fm_rds -audio -" format "44100:32:2" Is ok making the PreEmphasis file? ( I make a test file, changed the name and termination like above, and inside are the numbers you posted here) Again, Thank You!

pilovis commented 6 years ago

see here for updated how-to:

https://github.com/Miegl/PiFmAdv/issues/37