logo
Published on

Streaming System Audio to an AirPlay Receiver

Notes

If you want to use a Raspberry Pi as an AirPlay receiver, follow this tutorial.

Prerequisites

  • Node.js and npm
  • AirPlay Receiver

Linux

First, let's enable the ALSA Loopback 'Sound Card', snd-aloop. If it's already enabled, the output of aplay -l will look like this. Notice the Loopback cards.

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: STAC92xx Analog [STAC92xx Analog]
    Subdevices: 1/1
    Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 3: HDMI 0 [HDMI 0]
    Subdevices: 1/1
    Subdevice #0: subdevice #0
card 21: Loopback [Loopback], device 0: Loopback PCM [Loopback PCM]
    Subdevices: 8/8
    Subdevice #0: subdevice #0
    Subdevice #1: subdevice #1
    Subdevice #2: subdevice #2
    Subdevice #3: subdevice #3
    Subdevice #4: subdevice #4
    Subdevice #5: subdevice #5
    Subdevice #6: subdevice #6
    Subdevice #7: subdevice #7
card 21: Loopback [Loopback], device 1: Loopback PCM [Loopback PCM]
    Subdevices: 8/8
    Subdevice #0: subdevice #0
    Subdevice #1: subdevice #1
    Subdevice #2: subdevice #2
    Subdevice #3: subdevice #3
    Subdevice #4: subdevice #4
    Subdevice #5: subdevice #5
    Subdevice #6: subdevice #6
    Subdevice #7: subdevice #7

If these aren't listed, run sudo modinfo snd-aloop to check if you have it installed. If the command doesn't output anything, you may need to compile snd-aloop from source. To enable the loopback cards, open /etc/modprobe.d/sound.conf and add the following lines.

alias snd-card-0 snd-aloop
options snd-aloop index=21 pcm_substreams=8

Close any programs playing audio and run sudo /etc/init.d/alsa-utils restart to restart ALSA. Set the loopback card as the default output for your computer.

To test if your configuration is correct, run arecord -D hw:Loopback,1. This will read from 'the other end' of the loopback card and output to stdout. You should see a long stream of characters.

In the next step, we will use the audio sent to the loopback card and stream it to an AirPlay device.

Download node_airtunes and extract it. Change directories to the examples folder and run the following command.

arecord -f cd -D hw:Loopback,1 | node play_stdin.js --host [ip] --volume 100

Where [ip] is the IP address of your AirPlay device. You should now hear your system audio on your AirPlay receiver! By editing play_stdin.js we can stream to multiple devices at the same time (see the node_airtunes GitHub repo)!

Windows

Instead of setting up a loopback card, we'll use a program like CABLE. This behaves like a loopback card and allows us to do the same thing. More details coming soon.