[8.0.2] ALSA/MPD issue (MPD freezing when playing via ALSA)

  • Hello,

    the update to LE 8.0.2 somehow has broken MPD playback via ALSA output on my RPI2.

    I am using a hifiberry dac and a custom asound.conf file to enable volume control (by alsa softvol plugin) for my soundcard.

    After system start/reboot MPD is starting without problems and is accessible via any mpd client. But immediately when I start any playback via ALSA output, MPD completely hangs and is not responding anymore. Unfortunately, the MPD log (even with verbose options) does not give any error message or hint to the problem.

    This only happens, when ALSA is selected as output. If I select e.g. the the null output instead, MPD behaves completely normal (without sound output indeed).

    The above problem only appears since LE 8.0.2. When I downgrade to LE 8.0.1 or any previous version, MPD and/or ALSA is working without problems in my configuration.

    Has there been any change in the ALSA system and/or other parts related to audio between LE 8.0.1 and 8.0.2 causing this problem? What kind of additional information can I deliver in order to solve this problem?

    Thanks, Lars

    • Official Post

    Has there been any change in the ALSA system and/or other parts related to audio between LE 8.0.1 and 8.0.2 causing this problem?

    Comparing 8.0.1...8.0.2 · LibreELEC/LibreELEC.tv · GitHub

    there is nothing obvious :/

    MAYBE RPi/RPi2: add kernel patch to fix I2S clock · LibreELEC/LibreELEC.tv@59be68f · GitHub, ping HiassofT maybe he has some idea

    At the meantime you can test the latest version of the mpd addon if this fix something Index of /addons/8.1/mpd/rpi2/

  • No idea what's happening there, that kernel patch should be harmless. Could you post the output of dmesg when this happens?

    Have you configured Kodi to use ALSA as well? If yes, disable that (eg select HDMI output in kodi).

    Also try with asound.conf removed to disable the softvol plugin.

    Another interesting test would be to disable MPD and use only kodi with ALSA output.


    so long,

    Hias

  • Kodi is configured to use only HDMI, RPI onboard sound is also disabled/not enabled from rpi config.

    All the other things (latest mpd version, dmesg output, no asound.conf, alsa only via kodi) I will test this weekend and report here.

    Thanks, Lars

  • Sorry, for this very late reply. I have been away for some time with no chance to do further test.

    But now, I have tried several things which I want to report here:

    1) The problem still exists even with the latest beta release. I tried all versions starting from 8.0.0 to 8.1.1 and the last version, where my setup is running without problems is 8.0.1

    2) The problem seems to be more generally related to ALSA and/or I2S and not related to MPD

    That is based on the observation, that even aplay is not able to "always" play via the I2S soundcard. I write "always", because the strange thing I observe is, that sometimes the audio file is played fine, sometimes the file starts playing and then suddenly hangs and sometimes there is no sound output at all. In both of the last cases, I have to kill aplay, because it also hangs. So it seems, that something is blocking either the alsa system or the i2s output sometimes.

    3) I also tried with asound.conf (and therefore softvol) removed. Beside the fact, that the sound is extremely loud in this case ;) the behavior is absolutely the same.

    4) And here is the output of dmesg when sound is failing 8.0.2 (sound failing) and when sound is working 8.0.1 (sound working)

    5) My I2S soundcard is using the PCM5102 chip which is able to generate the clock by itself. This is also the mode I am using it right now.


    Hope this helps to find the problem. If you need further info or test, just ask.

    Thanks for your efforts,

    Lars

  • Thanks for the update!

    There's nothing obvious in the logs. You seem to be using a Hifiberry DAC, in which case the clocks are generated by the RPi. Therefore my best guess now is the RPi kernel PCM clock patch in combination with the way mpd uses alsa.

    In order to track down the issue I'll need to be able to reproduce this locally, so I'll need some more information and detailed step how to reproduce this:

    set log_level=verbose in mpd.conf, reboot the RPi, then try to trigger the issue.

    After that post the mpd log, output of "journalctl -a | paste" and your config.txt and mpd.conf files.

    It could be related to the file played (or the file played immediately before that), so having the "mediainfo" output of these files would also help.

    so long,

    Hias

  • Hi Hias,

    thanks that you are looking into my problem.

    Actually I have no real Hifiberry, but a compatible DAC card. This is my card: pHAT DAC. It is actually not using the system clock from the Pi, but generating it by itself from the other signals (froom PCM5102 datasheet: "Integrated High-Performance Audio PLL With BCK Reference To Generate SCK Internally". So only 3 wires and not 4 are connected to the Pi (BCK, LRCK and DIN). Could that be a possible origin of the error?

    Maybe to mention again. I think the problem is not related to MPD, since also a aplay command produces the error.

    Unfortunately, I am on a business trip in Japan this week, but I will do the suggested tests and report the results here beginning of next week.

    Thanks again,

    Lars

  • Those PCM5102 DAC boards derive their frequency from the BCK pin which is driven by the RPi - in contrast to other boards with on-board crystals / PLLs that generate and drive the I2S BCK.

    Make sure you've wired up the board correctly and the SCL is connected to ground. You can also test with the DAC board disconnected - you won't hear anything but you can test if mpd, aplay, ... lock up.

    I did some tests with this PCM5102 DAC board pHAT DAC - Pimoroni on a RPi2 running LE 8.1.1 using MPD, aplay and speaker-test and everything worked as expected, neither of these locked up.

    Please try to find a minimal setup (stock LE installation with only dtoverlay=hifiberry-dac in config.txt and all peripherals removed that aren't strictly needed) and post steps how to reproduce it.

    BTW: Also check if you can trigger the issue with speaker-test (and various rate/format parameters, if needed), this would make it easier for me to reproduce it locally.

    so long,

    Hias

  • Hi Hias,

    in the meantime I tried to do some further investigations. Unfortunately, it is (even for me) not easy to trigger the problem intentionally.

    From now on I will only use aplay and/or speaker-test for further testing because the problem also appears with both of them and really seems not to be related to mpd.

    Latest findings:

    • The problem appears irregular. Maybe around 2 out of 5 times playing exactly the same short 10s wave file.
    • There are 3 possible cases:
      • Wave file is playing normally as it should
      • Wave file is partly playing: Aplay is starting playback, sound is ok, but then suddenly during playback the sound output stops, aplay hangs and has to be killed.
      • Wave file not playing at all: Aplay is only printing the file information like channels, bit rate and so on and then stuck until it is killed
    • Actually it seems to be random and I cant figure out, what triggers the problem
    • Even directly playing to the hardware device: aplay -D "hw:0.1" sample.wav (so bypassing any alsa configuration) shows the same result

    I recently used strace to trace the aplay command when playback is working normally (strace-working) and when it stops during playback (strace-notworking). From this information it seems, that when playback hangs, it hangs on a poll for fd=4 which actually is the pcm-file:

    Output hanging:

    Code
    ioctl(4, SNDRV_PCM_IOCTL_SYNC_PTR, 0xf96498) = 0
    poll([{fd=4, events=POLLOUT|POLLERR|POLLNVAL}], 1, -1) = ?

    Output working normally:

    Code
    ioctl(4, SNDRV_PCM_IOCTL_SYNC_PTR, 0x29a498) = 0
    poll([{fd=4, events=POLLOUT|POLLERR|POLLNVAL}], 1, -1) = 1 ([{fd=4, revents=POLLOUT}])
    ioctl(4, SNDRV_PCM_IOCTL_SYNC_PTR, 0x29a498) = 0

    where fd=4 is /dev/snd/pcmC0D0p, which actually is my DAC.

    Code
    open("/dev/snd/pcmC0D0p", O_RDWR|O_NONBLOCK|O_CLOEXEC) = 4

    I don't know, if this information is helpful for tracking the problem, but I hope it is ;)

    Thanks, Lars

  • Unfortunately the strace isn't telling us much more than we already knew - sound device doesn't seem to be accepting data (maybe didn't manage to start running).

    I did another test here with LE8.1.2 and still haven't been able to reproduce your issue.

    I used a RPi2 with the PCM5102 based pimoroni pHat, connected ethernet and HDMI cables and a USB keyboard. Then I did this

    - fresh installation of LE 8.1.2 image on SD card

    - after bootup only enabled SSH

    - SSHed in, added "dtoverlay=hifiberry-dac" to end of config.txt, then rebooted

    - copied a 10 seconds wav file (44.1kHz, stereo, 16 bit) via scp to the sdcard

    - SSHed in, ran "aplay -Dhw:0 cd-10sec.wav" about 15 times without any issues

    Try if you can replicate using the exact same setup and steps. If you get issues my best bet is some hardware/cabling issue with your soundcard or an issue with your power supply (the number one cause of mysterious problems on RPi).

    so long,

    Hias

  • At upcoming weekend I will perform exactly the same steps and see what happens.

    Actually, I don't think, that this is caused by hardware/cabling issues or issue with my power supply since exactly the same (hardware)setup works completely ok when using any LE version prior to 8.0.2.

    ... but lets see ...

    Lars

  • Hi Hias,

    I just want to report my latest findings here and let you know that my system (latest LE version) is running ok again. That actually means, that I have no issues with MPD, ALSA and I2S anymore.

    By try and error I finally figured out, that all the problems described above were caused by another plugin, namely "Hyperion".

    Starting the the Hyperion daemon with the following pwm device configuration is giving me problems with ALSA/I2S:

    It seems the usage of the RPI pwm (channel 0, GPIO12) is somehow interfering (at least from time to time) with the I2S interface.

    As written in the start post, this problem actually started from LE 8.0.2 and was working nicely in the same configuration in previous versions.

    Best, Lars