Actions

Raspberry Pi Broadcastify Build

From The RadioReference Wiki

Raspberry Pi Broadcastify Feed Appliance

These instructions show you how to purchase and setup a completely self contained Raspberry Pi to broadcast a live audio feed to Broadcastify.com

These instructions have been verified and tested as working on a Raspberry Pi 2 Model B Project Board - 1GB RAM - 900 MHz Quad-Core CPU. Also installed and working on a Raspberry Pi 3 Model B (1 GB RAM - 1.2GHz 64 bit Quad-Core CPU - built in 802.11n wireless).

If you want to skip the build process, you can download our preconfigured Raspberry Pi image here Raspberry_Pi_Broadcastify_Image

Purchase Equipment

Raspberry Pi 2 Model B Project Board

-or- Raspberry Pi 3 Model B+ Project Board

-or- Raspberry Pi 3 Model B+ Kit, includes power supply, case, heat sinks, in-line power switch (recommended)

Power Supply with in-line switch for Raspberry Pi

Memory Card for Raspberry Pi

Case for Raspberry Pi (optional)

Inexpensive USB sound card ($9)

1/8 inch audio cable to connect scanner to USB sound card

Install Raspbian OS

All testing and configuration was done using Raspbian

Install pre-reqs and update raspberry pi to latest version

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install git cmake libusb-1.0-0.dev build-essential lame 
sudo apt-get install libmp3lame-dev libvorbis-dev libshout-dev libtwolame0 libtwolame-dev libjack-jackd2-dev 
sudo reboot

Configure the Sound Card

  • Plug your scanner's headphone jack into the mic jack on the USB sound card dongle
  • Start alsamixer
alsamixer
  • press F6, choose the "USB Headphone Set" entry
  • press your tab key to select the "Capture" device volume control
  • use your "up arrow" key to adjust the level to it's lowest level possible (6)
  • press escape to exist alsamixer
  • run the following command to save the volume settings
sudo alsactl store

Two Choices of Software to Broadcast

We recommend the darkice install and configuration method

Method 1: Darkice Install and Configuration (Recommended)

  • download the precompiled version of darkice
wget http://s.broadcastify.com/darkice/darkice_bcfy_v01.tar.gz
  • uncompress the files
tar zxvf darkice_bcfy_v01.tar.gz
  • move the files to the proper places and make sure they are executable
sudo mv darkice /usr/bin
sudo mv darkice1 /etc/init.d
sudo mv darkice.cfg /etc/darkice1.cfg     <--- note the "1" in the /etc/darkice1.cfg you are copying to
  • Edit the /etc/darkice1.cfg file to match your settings, including the sound card you are using, your feed server, mount, password, and description, then exit and save the file
sudo nano /etc/darkice1.cfg
  • Enable the feed to start broadcasting at boot
sudo update-rc.d darkice1 defaults
  • Start your feed
sudo service darkice1 start

Method 2: Ezstream Install and Configuration

sudo apt-get install ezstream

Create the following configuration file at /etc/ezstream_bcfy.xml and replace with your mount, password, and stream name. If you plan on having multiple streams make sure and create a separate named configuration file (i.e.'/etc/ezstream_bcfy2.xml) for each stream and reference accordingly in your command script below.

<ezstream>
    <url>http://audio#.broadcastify.com:80/your_mount</url>
    <sourcepassword>your_source_password</sourcepassword>
    <format>MP3</format>
    <filename>stdin</filename>
    <svrinfoname>Stream Name</svrinfoname>
    <svrinfourl>http://www.broadcastify.com</svrinfourl>
    <svrinfogenre>Scanner</svrinfogenre>
    <svrinfodescription></svrinfodescription>
    <svrinfobitrate>16</svrinfobitrate>
    <svrinfochannels>1</svrinfochannels>
    <svrinfosamplerate>22050</svrinfosamplerate>
    <svrinfopublic>0</svrinfopublic>
</ezstream>
  • Run this command to start the sound card broadcast
arecord -f dat -c 1 -D hw:1,0 | \
/usr/bin/lame -r -s 48 --resample 22.05 -m m -b 16 --cbr --lowpass 4 - - | \
/usr/bin/ezstream -q -c /etc/ezstream_bcfy1.xml > /var/log/bcfy1.log 2>&1 &

Note: very little volume will be needed from your scanner - adjust the levels as appropriate for a good sounding feed.


Optional Scripts


Troubleshooting

Clicking sound in the audio stream

If your stream has a clicking sound when there is no audio, you may be able to eliminate it by turning off Auto Gain Control.

  • Start alsamixer
alsamixer
  • Press F6 and select your audio device
  • Press Tab to select "Auto Gain Control"
  • Press the "m" key to toggle it off
  • Press Escape key to exit alsamixer
  • Save your settings with the following command
sudo alsactl store

Darkice not working or not starting on boot

The procedure above for starting the darkice service on boot does not seem to work on Raspbian Buster Lite (version: July 2019). This is due to newer versions of Raspbian implementing service management via systemd. It's possible to get it working using Raspbian Stretch and a crontab.

Instead of following the instructions to install the latest version of Raspbian, install the Stretch version:

  • Download the image here: 2019-04-08-raspbian-stretch-lite.zip, or use the non-lite version if you want the GUI.
  • Use Balena Etcher or similar to flash it onto your SD card
  • Enable SSH (optional) by adding a blank file named "ssh" to the SD card
  • Use raspi-config to set your timezone and expand the filesystem if necessary
  • reboot and follow the steps above, starting with "apt-get update", and stopping after editing your /etc/darkice1.cfg file


Set up "screen" and use it to run darkice in a detached screen, where it will keep running even if you close your terminal.

  • Install screen
sudo apt-get install screen
  • run darkice in a screen, specifying your config file
screen -dmS darkice-screen darkice -c /etc/darkice1.cfg

At this point, you should be able to confirm that darkice is running, and streaming your audio.


Now, set up a cron tab to automatically restart things after every reboot.

  • Edit or start your cron file.
crontab -e

If it tells you there's no cron file, let it create one. Choose option 2 for the nano editor.

  • add the following line to the bottom of your cron file:
@reboot sleep 30 && screen -dmS darkice-screen darkice -c /etc/darkice1.cfg

This runs after every reboot. It waits 30 seconds (to allow your network and other requirements to finish loading), and then starts a screen with darkice, using your config file.

Reboot and check that darkice is running:

sudo reboot
ps -A | grep screen
ps -A | grep darkice

The two ps commands should each return a line showing that screen and darkice are running. Your audio should now start streaming about 30 seconds after each reboot.