How To: Play HD Radio Throughout Your Home Using Google Cast or Airplay

Overview

I previously covered how to use Airfoil to stream your stored iTunes audio to Google Cast-enabled devices in your home. And, I shared some of my favorite internet radio stations, which can be streamed to Google Cast enabled devices. But not every radio station is available in a high fidelity (high bitrate) format online. So, for some local radio stations, you are better off tuning them over the air. Fortunately, many terrestrial radio broadcasters in the US also broadcast a digital signal, “HD Radio”. The challenge is how to create a local server to stream an HD Radio station to either Google Cast or Airplay-enabled devices.

Digital Radio: Europe v the United States

In Europe, digital audio broadcasting is based on an open standard, DAB. Over thirty countries have adopted DAB. The first generation of DAB was based on the MP2 audio codec, which was relatively inefficient. If radio stations used less than 160 kbit/s for their digital broadcast, then the audio quality could be worse than the analog FM broadcast.

In 2006, the DAB+ standard was introduced. This uses a far more efficient audio codec, MPEG-4 HE-AAC. It also includes a much stronger error correction coding, effectively increasing the quality of the radio signal and therefore the range of a station’s digital broadcast. DAB+ has been adopted as an ITU, ETSI and WorldDAB standard.

radiowaves
Here, in the United States, digital terrestrial radio uses an in-band-on-channel (IBOC) technology for both FM and AM based on a proprietary implementation by DTS (formerly Ibiquity), trademarked as “HD Radio. A radio station’s analog signal is usually simulcast on HD1. Many stations broadcast secondary channels (HD2 or HD3) with niche or specialty programming. Some of the HD Radio implementation, including the physical layer and protocols, is documented as part of the NRSC-5 standard.1 In July 2017, a researcher documented the missing details including HE-AAC audio compression and posted a working implementation of a software-based HD Radio.2 Prior to this, the protocol wasn’t fully, publicly documented, much less defined as an open standard.

Limitations of Dedicated HD Radio Devices

DTS claims that 78% of all radio listening is on stations broadcasting with HD Radio technology. HD Radio tuners are available in over 35% of new car radios.3 But, it is impossible to find HD Radio tuners as embedded technology in home AV receivers below $2000. There’s no existing way to play HD Radio on WiFi/Bluetooth speakers, like the Google Homes and Google Cast-enabled Vizio Soundbars, that we have throughout our home. Finally, there are no cheap dedicated HD Radio USB tuner dongles for computers.

For years, I owned several stand-alone Sony XDR-F1HD HD Radio tuners. These were excellent receivers but they were limited to analog RCA output. Unfortunately, they are no longer available. I am not aware of a better stand-alone tuner with digital outputs. Moreover, the problem with a separate tuner–analog or digital–is that it wouldn’t be scriptable. I could capture a station’s audio via my computer’s microphone input; but I would have to change the station manually.

DIY HD Radio Server for Google Cast and Airplay Clients

Software Defined Radio

Software defined radio refers to using low-cost RF hardware with a computer. Unlike traditional radios with dedicated hardware circuits, the computer handles the signal processing. Software radios have existed for many years, particularly used for military applications. More recently, the GNU Radio community developed an open sourced software toolkit that permits hobbyists to tune in a wide variety of radio stations across the AM, FM, USB/LSB, CW, and GPS bands. GNU Radio includes filters, channel codes, synchronisation elements, equalizers, demodulators, vocoders, and decoders blocks.4 If you are interested in further exploring software defined radio beyond the HD Radio use case in this article, I recommend starting with GNU Radio.

RTL-SDR Hardware Adapter

Low cost DVB-T USB dongles based on the Realtek RTL2832U chipset are widely available. These were originally made to receive European digital TV.5 I purchased the highly rated NooElec NESDR SMArt Bundle from Amazon for $25. It has a brushed aluminum enclosure and three different antenna masts.

IMG_5033

A Better Antenna

If you live in the suburbs, you may find that you need a stronger antenna than the ones provided in the NooElec kit. Your best solution is to use an outdoor or attic-based FM antenna. But if installing a large FM antenna is impractical for you, then you should consider the Terk Amplified AM/FM Stereo Indoor Amplified Antenna for $25.

You should note that the coax connector on the NooElec is RG-58, not RG-6. So you will likely need a male SMA connector to female Type F adapter if you wish to connect the NooElec USB dongle to an outdoor antenna.

Software for your Mac

Airfoil

I use Airfoil to stream audio from applications on my Mac, especially iTunes, to Google Cast and Apple Airplay-enabled devices in my home. It is also possible to use Airfoil to capture audio from the Mac’s Terminal application. So, Airfoil is my starting point to multicast HD Radio to Google Cast and Apple Airplay-enabled devices. Now we just need an HD Radio source application.

MPV

There are a variety of different audio player applications that you can install including SOX, MPV or MPLAYER. I installed MPV.

NRSC5

An open source NRSC-5 receiver can be found here. The researchers modified existing RTL-SDR software to support HD Radio including modest tweaks to an existing AAC decoder.

To install all the open source software on your Mac, including dependencies, I recommend using Homebrew:

$ brew install mpg
$ brew install --HEAD https://raw.githubusercontent.com/theori-io/nrsc5/master/nrsc5.rb

Finding HD Radio Stations in Your Area

DTS provides a useful HD Radio station directory by zip code here. Alternatively, you can use FM Fool’s signal locator site here.

Playing an HD Radio Station

Select a station in which you are interested. For our example, I use WHYY-HD1 in Philadelphia. To play the primary digital stream, you need to specify the frequency and HD channel. 90.9 (Mhz) is “90.9”. The actual HD channel is one less than the advertised HD number. So, HD1 is “0”, HD2 is “1”, and so on. By default, nrsc5 has debugging enabled. I recommend disabling it with the “q” option.

String all of these together in a Terminal command line that pipes audio from the nrsc5 app to the play app, as follows:

nrsc5 -o - -q -f wav 90.9 0 | mpv -

Let’s say that you wished to play a secondary HD channel, like my alma mater‘s station, WXPN’s XPN2 broadcasting on 88.5Mhz HD2. Then you would use a similar command:

nrsc5 -o - -q -f wav 88.5 1 | mpv -

Assuming you have decent radio reception, after a brief amount of time to lock on to the digital signal, you should hear your desired radio station on your Mac’s speakers. To multicast the station beyond your Mac, select the input source in Airfoil as Terminal. Then, select the destination devices or device groups to which you wish to multicast.

I recommend using WAV format because this ensures that nrsc5, not your audio player, will decode the AAC encoded audio. (Not all audio apps correctly interpret HD Radio’s AAC SBR extensions.) However, if you wish, nrsc5 also can output in ADTS format, which is AAC encoded in an MPEG transport stream.

Using a BASH Script for Advanced Audio Effects

I use the following script to simplify tuning radio stations. All you need to do is create a shell file and pass the frequency and band. For example, “sh HDplay.sh 90.9 0”. If a frequency isn’t specified, it will default to 90.9Mhz. Similarly, if a band isn’t specified, it will default to HD1. You can add additional SOX or MPV+FFMPEG effects globally, such as resampling, loudness, and dithering filters. I continue to tweak these settings to obtain a less harsh “digital” sound and to widen the stereo separation. I don’t believe that it is possible yet to extract the title, artist, and artwork from the HD Radio stream.

HDplay.sh

#!/bin/bash
# Script to play nrsc5 encoded radio feeds ("HD Radio")
#

FREQUENCY=$1
#If no frequency is specified, then use 90.9
if [ -z $FREQUENCY ];
then
FREQUENCY="90.9"
fi

#If no band is specified, then use 0 (HD1)
BAND=$2
if [ -z $BAND ];
then
BAND="0"
fi
let "HDBAND = $BAND + 1"

clear

echo "\033[1;44mTuning to the radio station: $FREQUENCY Mhz HD$HDBAND\033[0m"

# Play station using MPV with FFMPEG filters (adts codec)
# nrsc5 -o - -q -f adts $FREQUENCY $BAND | mpv - --audio-samplerate=48000 -af lavfi='extrastereo'

# Alternatively, play station using MPV with FFMPEG filters (WAV codec)
nrsc5 -o - -q -f wav $FREQUENCY $BAND | mpv - --audio-samplerate=48000 -af lavfi='extrastereo'

# Create an ADTS dump file for diagnostics
# nrsc5 -o out.adts -f adts $FREQUENCY $BAND


Updated on June 9th, 2018