This solution is now obsolete due to OS X 10.9 Mavericks builtin native AirPlay support. Now all applications can use AirPlay, and much more stable. Use XBMC or Shairport to recieve AirPlay streaming.
For Linux to Linux audio streaming, I now recommend PulseAudio instead witch is much simpler, better application support, and supports Multicast RTP streaming
For Windows users, I mostly feel sorry for you.
- Server can be run on Linux/OSX/Windows, thus Linux is recommended.
- Uses mDNS/ZeroConf/Avahi for service auto discovery
- Ability to record audio
- Control master volume on server
- Connect several clients to server
truestream.py (Python script)
Main server script. Will create config file at startup. I recommed running it in a "screen" on Linux.
TrueStream (Mac OSX Application)
- JackOSX (http://www.jackosx.com) on your MacOSX clients
- Python (http://www.python.org) (often bundled with your Linux-distro)
- (Jack win32 if using Windows)
Linux: Install JACK(2):
$ sudo apt-get install jackd2
Windows: Install JACK2 for Windows:
Linux: You could test that JACK works as i should: (we use MPlayer for example)
$ mplayer -ao jack somegoodtune.mp3
Make avahi services directory writable by your user or everyone
$ chmod 777 /etc/avahi/services
$ python truestream.py TrueStream Service version r71 (c) Adam Westerberg 2010-2012 Thanks to JACK Audio Connection team (http://www.jackaudio.org) and the Python community [Mon Dec 3 18:20:56 2012] Linux detected, writing new ~/.jackdrc [Mon Dec 3 18:20:56 2012] creating mDNS service [Mon Dec 3 18:20:56 2012] [Service:getvolume] got current volume level (83%) [Mon Dec 3 18:20:56 2012] listening for client connections at port 8005
I would recomend to run the application in a
screenoch something similar.
Note that it also will write a new
.jackdrcin your home directory with samplerate and dither settings.
Run server in a command terminal (cmd):
> truestream-win32.cmd TrueStream Service version r71 (c) Adam Westerberg 2010-2012 Thanks to JACK Audio Connection team (http://www.jackaudio.org) and the Python community [Mon Dec 3 18:25:12 2012] creating mDNS service [Mon Dec 3 18:25:12 2012] listening for client connections at port 8005
You should now see the server be able to connect with the client
Just unzip file and put TrueStream in Applications :)
Then open the application, select a server in the list and wait until service is started.
You will now see that TrueStream server got the connection and will connect to the JACK server on your client.
[Tue Mar 22 17:54:37 2011] got connection from 192.168.3.20! [Tue Mar 22 17:54:38 2011] starting jack_netsource -> 192.168.3.20 [Tue Mar 22 17:54:40 2011] re-routing virtual audio connections
Open Control panel and select "JACK Router" as sound device.
You should now be able to hear iTunes or Spotify (The client application autoconnects them!) from the other machine. Other applications needs a restart before they work properly.
6. Known problems & issues
- JACK/NetJACK doesn't play well with suspend and hibernation. Always to a Connect-Disconnect when resuming.
- Be aware of some audio breakup if using wireless, during data-bursts (if you fetch some big file) some packets may drop, and it will result in dropped audio. Implent QoS or use wired Ethernet if you can't live with this.
- No master volume control on your client, only per application volume control.
- Some Adobe Flash applications goes crazy (timer/transport error?).
If you loop audio through Soundflower then Adobe Flash works
7. Future improvements
- Linux Client. This is actually very possible.
- Windows Client. This is not so likley to happen.
- 16-bit samples instead of JACK default 32-bit float
- Multicast via NetJack2?
- OpenWRT implentation? :)
You can reach me at adam.westerberg -AT- gmail if you have any suggestions, complaints or improvements.
I had this situation when I was tired draging an audiocable around the apartment from my laptop to my sound system. I even tript over the damn cable for several times and I realised that some day I would break the line-out jack. I'm aware of AirPlay/AirTunes and the audio-features of Airport Express. But I rarley use iTunes (uses Spotify instead), and i don't own an AirPort Express (I'm very satisfied with my Netgear WNR3500L with dd-wrt). And i happends to have a Linux-box next to my TV and reciever for movie watching.
I was quite shocked that no one had come up with a free, multiplatform, easy, and low delay solution. I found some theoretical solution articles and replies in some forums. Some recomended to stream MP3 over HTTP (which adds loads of delay, cpu load and audio quality degradation) with VLC, and some just recommended to buy AirFoil and an AirPort Express and shut up.
In the Linux camp there ofcourse was a bunch of solutions. PCM over nbd (Network block device), Esound, PulseAudio, Jack/JackTrip/NetJack. And thanks MacPorts, some of this software is avalible also on Mac OS X, but not all of them, and unfortunally not all recent versions. We will be using JACK with NetJack(1) module.
Note that we will be using bandwidth, even more if using 48000Hz and 32-bit. This solution will be using up to 3Mbps of unicast UDP traffic because JACK uses 32-bit float internally by default. JACK uses about 8 bytes of header information, with a total of 42 bytes for L2 and L3 headers. JACK uses 1400 bytes MTU (maximum transmission unit) by default. For some reason jackd Segmentation faults when forcing it to use 16-bit.
(44100 * 32bits * 2 channels) = 2 822 400 bps = 352 800 bytes/s 352 800 bytes / 1400 MTU = 252 packets/s 252 packets * 42 bytes overhead = 10 584 bytes/s in packet overhead Total: 352 800 + 10 584 = 363 384 bytes = ~2,9Mbps network bandwidth (about 3% overhead)
|Samplerate||Precision||Bandwidth (bit/s)||with overhead (bit/s)|
|44100 Hz||16-bit||1 411 200||1 453 536|
|48000 Hz||16-bit||1 536 000||1 582 080|
|44100 Hz||32-bit||2 822 400||2 907 072|
|48000 Hz||32-bit||3 072 000||3 164 160|
Seince the master (the machine with the actual soundcard in use) has to connect to the slave (the machine running a JACK-server with net-backend), we are going to need a simple "call-back" solution to simplify this solution.
And because both Python and JACK also runs on Windows, we also can use Windows as master!
- Stream (almost) realtime audio from a MacOSX computer to a Linux or MacOSX-machine with soundcard.
- Minimal audio quality loss, eg. uncompressed PCM audio.
- Lowest possible delay. Low enough for video watching.
- Bandwith is quite irrelevant, we are using LAN connection with at least 802.11g or wired 100BASE-T.
- Some kind of easy-to-use client interface for daily use. So even your sister or girlfriend can use it.
- Low CPU usage.