Tuning pulseaudio for RPi

  • Hi,
    I'm currently experimenting with pulseaudio in LibreELEC. What I did so far:

    Code
    mount -o remount,rw /flash
    echo "dtparam=audio=on" >> /flash/config.txt
    mount -o remount,ro /flash
    echo "snd-bcm2835" > /etc/modules-load.d/snd-bcm2835.conf
    echo "pactl load-module module-udev-detect" >> /storage/.config/autostart.sh


    After that I rebooted and configured Kodi to use pulseaudio.

    The good thing is this works. The bad thing is it adds a noticeable (1-3 seconds!) delay to the sound processing. The delay is clearly added by pulseaudio as it goes away when you configure Kodi to use ALSA instead. Also from time to time audio stops completely without anything (pulseaudio showing "D: [alsa-sink-bcm2835 ALSA] source.c: Processing rewind..." - which seems to be a harmless message as it does that while the sound works, too. dmesg doesn#t show anything for that issue).

    The next thing I did was to create the file /storage/.config/pulse-daemon.conf.d/9999-pulsetest.conf - then I started to play around with it. My findings so far:

    • resample-method = trivial uses more CPU than the default (speex-float-1) - In fact with the default pulseaudio will always show ~0% CPU usage.
    • default-sample-rate beeing 44100 or 48000 doesn't seem to make a difference.
    • Lowering default-fragments produces sound distortion. But even when we tune default-fragments and default-fragment-size-msec the delay won't go away.
    • Highering realtime-priority also doesn't change the delay.
    • Highering the suspend timeout from 5 to 120 seconds doesn't stop the sound from stopping randomly.


    Now to my questions:

    • Does anyone know a way to show FPU usage?
    • Any ideas what else to test?


    And a moment before I wanted to post this I found something new: When the sound stops and you do a killall kodi.bin the screen will stay black untill you kill pulseaudio, too. When you kill pulseaudio in that scenario it shows this:

  • Hi there, I was looking at using Pulse audio to stream to a pair of active speakers connected to a low cost Pi device over Wifi.
    Did you ever get your setup working?

    I noticed a recent update in the Wiki that showcases a number of use cases. The text looks really well written with examples, perhaps some of what you want to do is covered?

    Pulseaudio - LibreELEC

    Regarding your ask for FPU perhaps installing htop might be an option? Using htop to monitor system processes on the Raspberry Pi | Tafkas' Blog

    GuruCoding.com - Raspberry Pi (Wheezy) Cross-Compiler Guide - The Difference Between HardFP and SoftFP Notes how the generic builds tend to avoud Hardware FP and opt for Software FP. As this post shows adding hardware support is an option Floating point performance of the Raspberry Pi – darrenjw's blog but you noted very low CPU usage so I think your assumption is correct that LE is using Hardware FP.

    I'm new to LibreElec just migrated all 4 of my home installation from OpenElec to the Bleeding Edge Millhouse LE. I have TV headend servers and clients and lots of other add on all working fine after the upgrade. Even the old Ras Pi B (Model 1) seems to fly with the Millhouse build. Saw your post had no replies and as I was thinking of using Pulse audio thought I'd reach out to you.

    I wanted to use a set up like this - to avoid cables :) wifi - Using Pi to stream all audio output from my pc to my stereo - Raspberry Pi Stack Exchange


  • Did you ever get your setup working?

    Sorry or the late reply but I didn't work on this anymore untill yesterday. Anyway, it (almost) works now. :cool:

    I don't remember the exact settings but at least I disabled audio passthrough. Then I enabled pulseaudio by doing:

    Code
    echo snd-bcm2835 > /storage/.config/modules-load.d/snd-bcm2835.conf
    echo dtparam=audio=on >> /flash/config.txt
    audio_pwm_mode=2 >> /flash/config.txt


    I also created /storage/.config/autostart.sh with the following contend:

    Code
    systemctl start brcmfmac_sdio-firmware.service
    systemctl start bluetooth
    pactl load-module module-udev-detect
    #pactl load-module module-cli-protocol-unix
    pactl set-default-sink alsa_output.platform-soc_audio.analog-stereo
    hciconfig hci0 down
    hciconfig hci0 up


    Please note: A few of these commands are workarounds to get bluetooth working. As you don't need bluetooth all you need are the pactl commands.#

    If you did everything correctly you should be able to get sound over pulseaudio now but with a one second delay. To fix the delay create /storage/.kodi/userdata/advancedsettings.xml with this content:

    Code
    <advancedsettings>
      <video>
        <latency>
          <delay>-1000</delay>
        </latency>
      </video>
    </advancedsettings>


    Note: The -1000 is exactly one second (1000 milliseconds) - This value is quick&dirty, so it probably needs some fine-tuning. Anyway, after a reboot everything should work for your case. In my case I'm stuck at Pi3 bluetooth audio stutters with Wifi enabled · Issue #1402 · raspberrypi/linux · GitHub :(