Bloerg
       

Wireless Raspberry Pi and Audio

Wireless LAN

Setting up wireless LAN on a Raspberry Pi is straightforward as long as you get a reasonably supported adapter. I bought a Zyxel NWD2105 for under ten euros which is working out of the box with the drivers delivered with Raspbian.

2012-08-26/zyxel.jpg

I wanted to access the RPi with a static IP address, so I added an entry for the wireless interface to /etc/network/interfaces

auto wlan0
iface wlan0 inet static
address 192.168.2.124
gateway 192.168.2.1
netmask 255.255.255.0
wpa-conf /etc/wpa.conf

and put in security credentials in /etc/wpa.conf:

network={
    ssid="CaseSensitive Router SSID"
    proto=RSN
    key_mgmt=WPA-PSK
    pairwise=CCMP TKIP
    group=CCMP TKIP
    psk="password"
}

Now, there was one issue: Wireless is only working when an ethernet cable is connected. I am not joking! I could see both interfaces with ifconfig and verify that the WLAN adapter was connected with iwconfig. But when I unplugged the ethernet cable and rebooted the RPi, I could not connect anymore. Funnily, the RPi itself talked to some services (avahi-browse -a showed some activity) but I could not talk to the RPi. A question on Unix@SE proved, that I am not the only person seeing the interfaces go crazy. One reply suggested to change auto eth0 to allow-hotplug eth0 but this was not working for me. So, again I had to pull out the hammer and just remove the whole eth0 entry.

Streaming music to my stereo system

In an earlier post, I described my half-assed solution to stream from the RPi to my workstation. This is working fine and the next step is to serve the music to my Kenwood stereo system. So installed the music player daemon and mpc on the RPi and ncmpcpp on my local desktop. After starting the daemon, it complained that it could bind to localhost but not to [:1], whatever that means. Nothing really helped except changing the bind_address from localhost to the network interfaces IP address.

I also installed mpdroid, an MPD client for my Nexus S Android smart phone. Although it could not connect to a Zeroconf address – which is raspberrypi.local –, I could connect just fine to the static IP address.

Now, my whole digital audio setup looks like this:

<pre>/----+ DAAP /-----+-----+ Audio /--------+ | PC |<------| RPi | MPD |------->| Stereo | +----+ +-----+-----+ +--------+ | ^ ^ | ncmpcpp | | mpdroid /---------+ +--------=--------+ +----=----| Nexus S | +---------+ </pre>

I can listen to digital music without turning my workstation on or spending money on an expensive third-party solution like the Logitech Squeezebox or the Sonos streaming system.

Unfortunately, there is one big flaw in my setup: I use the 3.5mm analog jack for streaming audio to my stereo. But the quality of this output is unbearable. There is a constant noise and higher frequencies are accompanied by strange popping sounds. Someone at the official forums took the time to analyse the problem:

I’ve done some quick tests on the analogue audio quality. I used audacity to generate a sine wave sweep from 20Hz to 20kHz and saved that as a .wav to play on the Pi. I then played one channel through my Hifi and ran the other channel to an oscilloscope. The signal looks and sounds clean up to about 800Hz, then the distortion start to creep in, by a couple of kHz you can see obvious steps on the edges of the waveform. From then up it looks more and more digital, basically less and less bits, at about 10kHz it’s essentially a square wave. Presumably this is caused by a relatively low PWM frequency and the minimal filtering, according to the schematic it’s just a single RC low pass filter.

One of the official developers wrote:

We are limited to 100MHz, so we can get to 11 bits @ 48kHz.

We did play with 6 bit samples, and an oversampling factor of 8 using a sigma delta algorithm, but it sounded worse.

Argh!

Now, after ditching the analog output, I have two options. First, I could use the integrated HDMI output. Unfortunately, my stereo has only a digital TOSLINK input, no HDMI and I don’t want to buy one of those little boxes that can mix and match TOSLINK and HDMI. They are a too expensive and overpowered for my problem. The other option, that I am realizing now, is to buy a USB sound card that features a TOSLINK output. A small, decently priced sound card is the TerraTec AureonDualUSB, that I just ordered from Amazon. How this turns out is to be told about in another episode of “How I met my perfect audio solution”.

Discussion

pensacola map
Mon, Mar 10 2014

Wow that was odd. I just wrote an really long comment but after I clicked submit my comment didn’t show up. Grrrr… well I’m not writing all that over again. Anyhow, just wanted to say superb blog!

This post might also have some comments at Google+.