I have installed raspbian on my Pi and configured a PulseAudio sink with the intention to stream all audio from my desktop to a Pi, driving the loudspeakers.
I followed this nice description: http://www.raspberrypi.org/phpBB3/viewtopic.php?f=38&t=11124
At first, this appeared to work without problem. However, the audio sent from the desktop is constantly stuttering on the Pi, as if there were constant buffer underruns with just a few samples missing in-between.
I spent the whole day trying to find the cause, but to no avail. The basic setup is:
- wired LAN connection
- latest raspbian pi (26 Sep 2013) with latest firmware updates
- PulseAudio 2.0 on both sides (Ubuntu desktop)
- Playback through mplayer, totem, ffplay
- network transmission via module-native-protocol-tcp
This is what I tried:
- Playing audio directly on the Pi works perfectly.
- Streaming to other (desktop) computers works fine.
- Sending audio with a direct connection (specifying $PULSE_SERVER) works quite well with very little stuttering, but still prone to Problem-2 (see below)
- Sending audio via desktop PulseAudio tunneling gives constant stuttering
- Increasing priorities / realtime scheduling... did not help
- Fixing sampling rate to 48 kHz ... did not help
- Setting resampling algorithm to "trivial" ... did not help
- Adjusting default-fragments/fragment-size ... did not help
I cannot find any indication of a problem in the PulseAudio logs (shown from the time I started playback):
D: [alsa-sink] protocol-native.c: Requesting rewind due to end of underrun. D: [alsa-sink] sink-input.c: Requesting rewind due to uncorking D: [pulseaudio] sink.c: Suspend cause of sink alsa_output.platform-bcm2835_AUD0.0.analog-stereo is 0x0000, resuming I: [alsa-sink] alsa-sink.c: Trying resume... I: [alsa-sink] alsa-util.c: cannot disable ALSA period wakeups D: [alsa-sink] alsa-util.c: Maximum hw buffer size is 341 ms D: [alsa-sink] alsa-util.c: Set buffer size first (to 16384 samples), period size second (to 16384 samples). I: [alsa-sink] alsa-util.c: ALSA period wakeups were not disabled D: [alsa-sink] alsa-sink.c: Latency set to 25.00ms D: [alsa-sink] alsa-sink.c: hwbuf_unused=60736 D: [alsa-sink] alsa-sink.c: setting avail_min=15665 I: [alsa-sink] alsa-sink.c: Time scheduling watermark is 15.00ms I: [alsa-sink] alsa-sink.c: Resumed successfully... I: [alsa-sink] alsa-sink.c: Starting playback. D: [alsa-sink] alsa-sink.c: Cutting sleep time for the initial iterations by half. D: [alsa-sink] alsa-sink.c: Cutting sleep time for the initial iterations by half. D: [alsa-sink] alsa-sink.c: Cutting sleep time for the initial iterations by half. D: [pulseaudio] module-suspend-on-idle.c: Sink alsa_output.platform-bcm2835_AUD0.0.analog-stereo becomes busy. D: [alsa-sink] alsa-sink.c: Cutting sleep time for the initial iterations by half. D: [alsa-sink] alsa-sink.c: Cutting sleep time for the initial iterations by half. D: [alsa-sink] alsa-sink.c: Cutting sleep time for the initial iterations by half. D: [alsa-sink] alsa-sink.c: Cutting sleep time for the initial iterations by half. D: [alsa-sink] alsa-sink.c: Cutting sleep time for the initial iterations by half. D: [alsa-sink] alsa-sink.c: Cutting sleep time for the initial iterations by half. D: [alsa-sink] alsa-sink.c: Cutting sleep time for the initial iterations by half. D: [alsa-sink] alsa-sink.c: Cutting sleep time for the initial iterations by half. D: [alsa-sink] ratelimit.c: 115 events suppressed D: [alsa-sink] alsa-sink.c: Wakeup from ALSA! ... no more output, but stuttering continues ...
Problem 2: as said above, I can get quite ok audio with a direct connection. However, after a few skips within the stream (using mplayer), the PulseAudio server hangs and does not play any audio at all. Sometimes it can be revived by restarting mplayer. Sometimes it hangs so badly that PulseAudio has to be restarted. Sometimes it even hangs when I only change the volume level.
According to the PulseAudio docs, the advantage of a direct connection over a tunnelled connection is to have better buffering control, which seems to indicate why I get good audio with the direct connection: http://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/Network/
I am out of ideas now. What could cause the stuttering and Problem 2 ? Just an idea how to proceed debugging would also be appreciated.