Kodi Community Forum
Solved HiFiBerry Digi under kernel 4.19.x working without patching Kodi source? - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Support (https://forum.kodi.tv/forumdisplay.php?fid=33)
+--- Forum: General Support (https://forum.kodi.tv/forumdisplay.php?fid=111)
+---- Forum: Raspberry Pi (https://forum.kodi.tv/forumdisplay.php?fid=166)
+---- Thread: Solved HiFiBerry Digi under kernel 4.19.x working without patching Kodi source? (/showthread.php?tid=342262)



HiFiBerry Digi under kernel 4.19.x working without patching Kodi source? - graysky - 2019-03-21

It came up in this thread that one can use a .conf file rather than patching Kodi's source to get the HiFiBerry Digi card to work with Kodi and to use the passthrough option.  Doing this doesn't completely work to both enable the hardware and allow for passthrough.

The following comes from this issue wherein Kodi 18.1 on Arch ARM with the HiFiBerry Digi seems to partially work.  The goal is not patch Kodi's source yet enable this hardware and its passthrough feature.  Suggestions are welcomed.

@HiassofT 
@rascas 
nornic Wrote:I had to use RPi-WM8804.conf which was mentioned in comment #4. File name is important, which caught me by surprise.

Once I downgraded to 18.0-1, added RPi-... file and rebooted, I could finally select the passthrough mode in Kodi settings. Wasn't grayed out anymore. So success...
However, even when this passthrough is setup to hifiberry-digi, my amplifier only picks up PCM signal.

To prove I'm not going mental, removed the conf file, upgraded back to 18.1-2 and reboot. Any movie I switched on, had the passthrough working correctly. I got DolbyD and DTS audio.

Perhaps there's something else I am missing here... Don't know much about configuring the alsa cards via those conf files...
Any suggestions?



RE: HiFiBerry Digi under kernel 4.19.x working without patching Kodi source? - HiassofT - 2019-03-21

Enabling the hardware and getting passthrough in Kodi are two different things.

To enable the hardware you either need to do nothing (if the soundcard has an EEPROM with the device tree overlay) or add a dtoverlay to config.txt. This will then result in the standard "default" and "sysdefault" PCMs showing up for your card in "aplay -L".

To use passthrough in Kodi the audio device needs an iec958 PCM. Alsa-lib contains alsa card confs for the typical audio devices you'll find on PCs, eg /usr/share/alsa/cards/HDA-Intel.conf, which add iec958 PCMs for the on-board S/PDIF port.

With the RPi-WM8804.conf file in /usr/share/alsa/cards you'll get the iec958 PCM in aplay -L and are able to select it in Kodi as a passthrough device (on kernel 4.19, on older kernels you need multiple card confs for the various WM8804 based digi cards).

There's a small gotcha with the Hifiberry etc drivers, they don't set the AES status bits in the S/PDIF stream (which are usually configured via the "IEC958 Playback Default" mixer control, set by the ALSA card conf file from the iec958 PCM arguments). This functionality is simply missing in these drivers. I implemented that in the Wolfson/Cirrus Logic Audio Card driver (rpi-cirrus) if someone's interested in porting it to the Hifiberry etc drivers. That's a minor issue though, most receivers don't care about the AES status bits and simply look at the bitstream to determine if it's a PCM or a compressed AC3/DTS stream. In the rare case a receiver needs the status bit's it'll be a rather obvious issue though, as it'll produce a machine-gun like white-noise sound if it receives an AC3/DTS stream and mis-interprets it at PCM.

so long,

Hias


RE: HiFiBerry Digi under kernel 4.19.x working without patching Kodi source? - graysky - 2019-03-21

@HiassofT - Thank you for that detailed explanation.  If I read and understood it correctly:

1) The hacky patch I referenced will satisfy both condition (enabling hardware and allowing passthrough).
2) Without the patch, supplying /usr/share/alsa/cards/RPi-WM8804.conf with only enable the hardware but will not allow for fully functional passthrough.
3) To allow for fully functional passthrough, someone will need to port the code you authored for another device to the HiFiberry Digi or else, the setup will not allow send the AES status bits to the receiver.

Do I understand correctly?  If so, it sounds like nornic's problem is that his receiver is one of the rare ones you pointed out that actually does need the AES status bits.  As I understand it, created case #2 on his system and found that his receiver only picks up PCM signal whereas running with case #1 allows for full functionality.


RE: HiFiBerry Digi under kernel 4.19.x working without patching Kodi source? - nOrNIc - 2019-03-21

(2019-03-21, 21:23)graysky Wrote: @HiassofT - Thank you for that detailed explanation.  If I read and understood it correctly:

1) The hacky patch I referenced will satisfy both condition (enabling hardware and allowing passthrough).
2) Without the patch, supplying /usr/share/alsa/cards/RPi-WM8804.conf with only enable the hardware but will not allow for fully functional passthrough.
3) To allow for fully functional passthrough, someone will need to port the code you authored for another device to the HiFiberry Digi or else, the setup will not allow send the AES status bits to the receiver.

Do I understand correctly?  If so, it sounds like nornic's problem is that his receiver is one of the rare ones you pointed out that actually does need the AES status bits.  As I understand it, created case #2 on his system and found that his receiver only picks up PCM signal whereas running with case #1 allows for full functionality.
I don't think that's right.
As far as I understand this, enabling hardware is something completely different than alsa or kodi settings and I had it done in exactly the same way @HiassofT mentioned.
Basically specifying the following in /boot/config.txt and reboot:
Code:
dtoverlay=hifiberry-digi
 
At this stage the problem was that I couldn't select this new card as passthrough in kodi. Only analog output was visible and not S/PDIF one. Passthrough option was greyed out.

To get the S/PDIF (and passthrough) to work, I needed to modify the card setup to "introduce" itself as iec958 PCM capable. From old days on Arch, we used to do this hack in Kodi's source code.
It seems that for kernels 4.19+ this hack is not needed anymore and simple adding the RPi-WM8804.conf card config (as it was mentioned by @HiassofT) is enough for the alsa and kodi to see the card with iec958 PCM.
For older than 4.19, you would need to add those extra config files, one for each card type.
So after adding this config and reboot I finally was able to see 2 Hifiberry devices, 1 analog and 1 digital:
Code:

​​​​​​$ aplay -L
null
    Discard all samples (playback) or generate zero samples (capture)
jack
    JACK Audio Connection Kit
pulse
    PulseAudio Sound Server
default
    Default ALSA Output (currently PulseAudio Sound Server)
sysdefault:CARD=sndrpihifiberry
    snd_rpi_hifiberry_digi, 
    Default Audio Device
iec958:CARD=sndrpihifiberry,DEV=0
    snd_rpi_hifiberry_digi, 
    IEC958 (S/PDIF) Digital Audio Output
usbstream:CARD=sndrpihifiberry
    snd_rpi_hifiberry_digi
    USB Stream Output

The issue I described yesterday was that, even when I had the passthrough option finally visible and Hifiberry card spdif selected, the Amplifier did not picked the correct signal up.
I had no DolbyD or DTS signal but rather analog one.
Through trial and error I noticed, that although passthrough card is selected as S/PDIF one, if main audio output device in kodi is still selected as analog, this will take precedence.
So in other words, I had to select "hifiberry_digi S/PDIF" card as "audio output device" and "Passthrough output device".
That played all the DTS movies without any problems.

To get the upscaling working, to see movies with ACC audio as DolbyD, I had to enable "AC3 transcoding" in passthrough settings.

In regards to AES status bits Hias mentioned, it all comes down to what Amplifier you connecting you card. I am lucky enough that my one don't care about the status bits... Well I hope it don't, just never noticed any annoying white-noise sounds.

So to get back to your original question @greysky, we are good to remove this hack from the package. It is no longer needed.

Thank you both for your help.


RE: HiFiBerry Digi under kernel 4.19.x working without patching Kodi source? - graysky - 2019-03-21

Nice, thanks all.  Always good to keep upstream code unpatched/customized if possible.