At a glance

- use a Raspberry Pi to send and receive audio streams over the network
- streaming is based on standard RTP streams
- uncompressed audio streaming over ethernet
- point-to-multipoint broadcasting
- uses PulseAudio
Note: This guide has been written in 2011. Since this time, the software used in this project has changed a lot. The guid won’t work without changes. Take it as a guideline and adapt it wherever necessary.
The following guide will show how to use the Raspberry Pi as a cheap RTP sender. It broadcasts music from the Line input of the sound card to your local network. This can be used for audio distribution in your house.
Using uncompressed audio a stereo audio transmission uses about 180kByte/s on your LAN. That means the utilization of a 100Mbit/s LAN is less than 2%.
Note that the audio quality of the internal “sound card” of the Raspberry Pi is very unsatisfactory. You should use the HDMI audio output or an external sound card. Interested in a add-on sound board? Check out our Raspberry Pi DAC project HifiBerry Mini .
Do you want to control the volume of external sound sources with your Raspberry Pi? Check out our Quad Volume Control circuit, that is Raspberry compatible!
Schematic setup
The simplest setup is a point-to-point setup with one sender (the Raspberry Pi with a sound card as line input) and a receiver on the other side (this could be another Raspberry Pi, a PC or a RTP enabled streaming client).
But there are much more interesting (and complex) setups possible. Think about different audio source that can be distributed to different receivers. Every receiver just listens to the RTP stream that it is interested in:
Audio source must not be a sound card with a line input. It could also be a media server that broadcasts music stored on an attached hard disk.
Hardware setup
Unfortunately the Raspberry Pi does not feature a analog or digital sound input. Therefore an additional sound card is needed. I use the Behringer UControl UCA 202. It is cheap, but features the Burr Brown PCM2902 audio chip which provides a good audio quality. This chip does not support sample rates larger then 48kHz. If you want to use 96kHz/24bit audio quality, you have to buy another (much more expensive) sound card.
The sound card will be plugged into one of the USB ports of the Raspberry Pi. The Behringer sound card consumes less then 0.5W power and can be powered directly from the USB port of the Raspberry Pi, no additional powered USB hub is needed. If you use the Ethernet port for connectivity the whole setup consumes less than 2.5 W (5V, 460mA measured). If additional software is running on the Raspberry Pi, the power usage may be a bit higher but it should not be more then 3W.
Software setup
- Boot archlinux
You can download Archlinux for the Raspberry from the Archlinux web site. - Change root password
Do not forget to do this, even if the Raspberry is only connected to your LAN. - Resize root filesystem
#fdisk /dev/mmcblk0 d 2 n p 2 enter enter w
Now reboot. Once rebooted:
#resize2fs /dev/mmcblk0p2
- Set fix IP address
A fix IP address makes it easier to configure the clients. To do this, you have to create 2 files:
/etc/conf.d/networkinterface=eth0
address=192.168.1.5 netmask=24 broadcast=192.168.1.255 gateway=192.168.1.1
/etc/systemd/system/network.service
[Unit] Description=Static IP Connectivity Wants=network.target Before=network.target [Service] Type=oneshot RemainAfterExit=yes EnvironmentFile=/etc/conf.d/network ExecStart=/sbin/ip link set dev ${interface} up ExecStart=/sbin/ip addr add ${address}/${netmask} broadcast ${broadcast} dev ${interface} ExecStart=/sbin/ip route add default via ${gateway} ExecStop=/sbin/ip addr flush dev ${interface} ExecStop=/sbin/ip link set dev ${interface} down [Install] WantedBy=multi-user.target
Activate static IP:
#systemctl enable network.service systemctl start network.service
- Update all packages
Having the system up-to-date is always a good idea
pacman -Sy; pacman -Syu
- Install alsa-utils, pulseaudio, avahi
pacman -S alsa-utils pulseaudio alsa-plugins libpulse avahi
- Add DBUS config for Pulseaudio
Create the file /etc/dbus-1/system.d/pulseaudio.confDOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> pulseaudio.Server"/>
- Setup pulseaudio config
Create the file /etc/pulse/daemon.pa#!/usr/bin/pulseaudio --system --disallow-exit --disallow-module-loading -nF # # Startup script for system mode. This file will not be # loaded automatically, but has to be loaded with the # -F command line # ### Load audio drivers load-module module-alsa-source ### Load native protocol load-module module-native-protocol-unix ### publish RTP sender load-module module-zeroconf-publish ### Load the RTP sender module load-module module-rtp-send source=alsa_input.default destination=224.0.0.56 port=45678 format=s16be channels=2 rate=44100 ### CLI interface load-module module-cli-protocol-tcp # Output to RTP set-default-sink rtp
- Create user pulse and add it to the audio group
useradd pulse usermod -g audio pulse
- Create a group that can access pulseaudio
groupadd pulse-access usermod -G pulse-access root
- Add pulseaudio to ALSA
Create /etc/asounf.confpcm.pulse { type pulse } ctl.pulse { type pulse }
- Create startup for pulseaudio
Create the file /etc/systemd/system/pulseaudio.service[Unit] Description=Pulseaudio After=network.target [Service] Type=forking ExecStart=/usr/bin/pulseaudio --system --disallow-exit --disallow-module-loading -nF /etc/pulse/daemon.pa [Install] WantedBy=multi-user.target
Start pulseaudio:
systemctl enable pulseaudio.service systemctl start pulseaudio.service
- Use an RTP client on another computer in the same network to check if RTP streaming is working
You can use any RTP client, I use VLC in this example:vlc --rtp-caching 50 rtp://@224.0.0.56:45678/
If sound drops, you may have to increase the caching interval (50 ms in the example). In my tests, caching intervals below 50ms did not work even on 100Mbit/s-LAN.
Pingback: Using a Raspberry Pi for audio distribution
Thanks for this tutorial. I have just one issue – /etc/dbus-1/system.d/pulseaudio.conf seems to have not saved correctly in the article. Can you please check?
how to change sound quality? I want MP3 or OGG 96Kbps
Pingback: Nath's Blog» Blog Archive » Audio distribution via raspberry pi mesh
Pingback: Loft receivers v2…? | ALLOUTPUT.com
Pingback: Raspberry | Pearltrees
this doesnt work :(
What exactly is not working? Where can I help you?
This is a great idea. I’m considering to use this as a wireless tv audio transmitter, and a android smartphone as a receiver. How do you think the latency would be? Thank you!
Depending on the network connectivity you should have a buffer of at least 50ms. If the network is less reliable, larger buffers should be used (on wireless, I would start with 100ms). The buffer size has the biggest impact on the latency. Other factors (network latency, coding/decoding) have only a minimal impact on the latency.
Thank you for replying. I have another question.
I tried to find other usb sound cards, because UCA 202 is a little bit high price for me. However, most 1~2 bucks (in ebay) usb sound cards seem to have mono mic input only. So I am thinking to use two usb sound cards simultaneously and combine them to make stereo. Do you think is it possible, and any chances to be implemented here?
I never tried it. But if you really want a stereo microphone input, you should invest even more then the money for the UCA202. Microphone inputs have a very high gain and a low-quality microphone input will result in a really bad audio quality.Or are you looking for a line-level input?
What about using a cubieboard?
This should work with every linux system.
Newbie here. Sorry if the questions are a tad rudimentary. I would like to use your RP audio distribution system to stream high quality audio from my home theater through Ethernet cat5 to a remote stereo audio reciever that has an airport express input.
Am I right in assuming the airport express has proprietary code; meaning I would need both a new RP send and an RP recieve unit? Also, would I be able to use your new DAC cards as an input (code) on one end and output (decode) on the other?
How controllable is the resolution. I would like to run it as high a rate as possible, but still be able to lower it if need be. Since I am running a 1gig over copper Ethernet I don’t expect problems.
I am an audio pro who has been intrigued by the RP and has been looking for a first project; this one seems like it is a good bunny hill to learn on.
I’m not aware of a solution that can stream to an Airport. Therefore you will need two Raspberry Pis. Note, this guide will help, but it is NOT a copy-and-paste solution. It was written a long time ago. Parts of the software might need different configurations (newer program versions,…)
Any corrections or updates? Setup #3 resizing an active partition!!
IP address is inconsistency!! Add DBUS config for Pulseaudio, how dose it on a working system?
Please update the this page.
Kim
how to change sound quality? I want MP3 or OGG 96Kbps
Can’t get the service to start. Did everything apart from static IP and network.service cause I don’t need that. Here’s the status:
[pi@station23 ~]$ sudo systemctl status pulseaudio -l
● pulseaudio.service – Pulseaudio
Loaded: loaded (/etc/systemd/system/pulseaudio.service; enabled)
Active: failed (Result: exit-code) since Wed 1969-12-31 17:00:10 MST; 44 years 5 months ago
Process: 123 ExecStart=/usr/bin/pulseaudio –system –disallow-exit –disallow-module-loading -nF /etc/pulse/daemon.pa (code=exited, status=1/FAILURE)
Dec 31 17:00:10 station23 pulseaudio[123]: N: [pulseaudio] main.c: Running in system mode, forcibly disabling SHM mode!
Dec 31 17:00:10 station23 pulseaudio[123]: N: [pulseaudio] main.c: Running in system mode, forcibly disabling exit idle time!
Dec 31 17:00:10 station23 pulseaudio[123]: E: [pulseaudio] main.c: GID of user ‘pulse’ and of group ‘pulse’ don’t match.
Dec 31 17:00:10 station23 systemd[1]: pulseaudio.service: control process exited, code=exited status=1
Dec 31 17:00:11 station23 systemd[1]: Failed to start Pulseaudio.
Dec 31 17:00:11 station23 systemd[1]: Unit pulseaudio.service entered failed state.
you have to make sure, that user pulse (id:1000) is memeber of the group pulse (id:1000)
now, I can´t load a module:
/usr/bin/pulseaudio –system –disallow-exit –disallow-module-loading -nF /etc/pulse/daemon.pa
N: [pulseaudio] main.c: Running in system mode, forcibly disabling SHM mode!
N: [pulseaudio] main.c: Running in system mode, forcibly disabling exit idle time!
W: [pulseaudio] main.c: OK, so you are running PA in system mode. Please note that you most likely shouldn’t be doing that.
W: [pulseaudio] main.c: If you do it nonetheless then it’s your own fault if things don’t work as expected.
W: [pulseaudio] main.c: Please read http://pulseaudio.org/wiki/WhatIsWrongWithSystemMode for an explanation why system mode is usually a bad idea.
E: [pulseaudio] module.c: Failed to load module “module-alsa-source” (argument: “”): initialization failed.
E: [pulseaudio] main.c: Module load failed.
E: [pulseaudio] main.c: Failed to initialize daemon.
(using the exact setup as mentionend in the article here with UCA202)
I’m having exactly the same issue that andyH mentioned (“module-alsa-source” (argument: “”): initialization failed.) also pulseaudio.conf doesn’t seem to be correct at all. Any progress?
And Me. this appears to be something to do with alsa. in /etc/pulse/ there is three configuration files one of which is the daemon.pa as typed but until the other two .pa files are renamed to become unusable the commencting out of lines doesn’t have any effect. but when it finally does the systemctl enable trips up on the two load modules that relate to alsa. i’m still looking around to find how alsa decides to snif the usb and decide that the uca202 is the correct source but that’s where i’m headed.
module-udev-detect is something i’m currently looking at, seemed to fix the module-alsa-source problem but module-rtp-send started tripping up.
8hours of my life i won’t be getting back because of a missing <!
the pulseaudio.conf below seems to work fine. all i said above a dead end.
greetings gentlemen
Dear am interested in your products HiFiBerry dac
2 units as audio link on a LAN
send audio from a place to another place travez LAN or WIFI
it can be used as 2 channel audio link? please confirm or recommend another product
Thank you
Hello,
First thank you for all the work done!
Sorry in advance for my english…
I want to confirm something, If I understand correctly, you explain how to create a RTP streaming server with Raspberry Pi.
But is it possible to make a RTP client with an another Pi?
I would like to have a Pi configured to listen, at startup to the streaming of the server (so configuration of the IP is done and at startup, the PI automaticaly listen to the stream, without any new configuration).
I don’t find how to do it. Is it possible?
Thank you in advance,
Hi I am new to this. I am looking for distributing live audio through WiFi using your system. What is needed and how can I achieve this. I want the audio to be received through any smart phones both android and apple. What software and is there any that can be downloaded from app stores?
Pingback: Audio Hardware | Pearltrees
Can you Post your “/etc/dbus-1/system.d/pulseaudio.conf” ? Please?
Does anyone have an updated guide and pulseaudio.conf file?
Pingback: PIrate radio – Chinchilla Paradise Industries