Kodi Community Forum

Full Version: DD or DTS Passthrough and Multi-channel PCM for AAC conflict
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
It appears to me that there is no way to simultaneously set up a pass-through of content with DD or DTS surround while also allowing other content with AAC surround to be sent through as decoded multi-channel PCM. You can do one or the other correctly but it seems not both. This appears (to me) an unnecessary and perhaps unintended constraint and so I am trying to figure out whether this is a feature or a bug.

To make things simple (because there are so many moving parts in the audio setting), let me describe my findings in the simplest possible configuration. I am avoiding availability of SPDIF, etc so as not to complicate things. Just HDMI. I am also ignoring the option to transcode to AC3 as irrelevant to this context.

Audio is played through Pulseaudio which has the possibility to select (keeping it simple here)
- Digital Stereo HDMI
- Digital Surround 5.1 HDMI

There are two media files with the following audio (again to keep it simple)
- Dolby Digital 5.1
- AAC 5.1

The objective is to arrive at a setting where DD 5.1 is passed through with no decoding by Kodi and because AAC is not supported by most devices, Kodi should decode AAC 5.1 to multi-channel PCM and send it out as 5.1 multi-channel PCM (not as stereo). A single setting configuration should support both of the above to happen automatically.

Here is why it does not (and each one can be achieved only at the expense of the other). Do let me know if I have made any error in the assumptions or observations below.

To make sure pass through is possible for the DD 5.1, in Pulseaudio (through pavucontrol) one must select Digital Stereo HDMI for output and NOT Digital Surround 5.1 HDMI. Only then will the option to enable Pass through will be available inside Kodi System->Audio setting. Kodi on startup enumerates available devices and only allows pass through to devices that report as two channels.

So when pass through is enabled with Pulseaudio outputting to Digital Stereo HDMI, the pass through of DD5.1 works just fine. No problems here.

But if you then play the AAC 5.1 media, it is encoded as 2 channel stereo PCM (regardless of what setting one has in the number of channels or output configuration - fixed or best match). It appears the AAC decoding does not use those number of channel setting in this context. Without doing that Kodi has no way of knowing how many channels to send via PCM and depends on the selected device being stereo to send as stereo PCM downmixing the original. This is what appears unnecessary to me and can be handled differently (more below).

On the other hand, if I select Digital Surround 5.1 in Pulseaudio as the output device, then no pass through is available for any format - pass through option is not available. Kodi decodes all audio including DD 5.1 to send it out as multi-channel PCM. There are some issues here that results in low volume or missing channels depending on whether it is AAC or DD and the number of channels in the content but that is a different problem (already pointed out in some other threads). It is possible that Kodi here isn't doing the right things here in how it mixes to output. It seems to work best when the number of channels in the content and the number of channels supported by the device coincide. But I don't wish to go off on this tangent here although the decision logic may be related.

My question is in the first case of enabling pass through to a stereo sink, for content that cannot be passed through (AAC, e.g), isn't it possible for Kodi to check the number of channels setting in System->Audio and mix to that many channels in the PCM output instead of just assuming two channels only from the device characteristics (because of which the AVR gets stereo PCM only instead of multi channel PCM)? Because of the pass through requirements the selected device will always answer two channels - FR and FL (at least in Linux setups). The Fixed or Best Match setting is also ignored it appears.

Am I missing something here or is there a technical reason for not using the number of channels settings (if pass through is enabled) to decide on the number of channels to mix to as PCM for content that cannot be passed through? Or is this an unintended consequence?

Thanks for any input from the audio people at Kodi.
File a bug with pulseaudio as this their behaviour not kodi's. You have two options:
a) disable pulse and use alsa (available on every Linux by default)
b) set kodi channels to 2 and enable Dolby transcode. This will output DTS / AC3 via passthrough and transcode 5.1 AAC to AC3.
c) Don't use passthrough at all. Configure your HDMI sink to 5.1 and kodi will losslessly decode DTS / AC3 / TrueHD / DTS-HD to multi channel pcm and output that.

Don't foget: Pulseaudio is a soundserver! For the entire system, not an audiophile special reconfigure sound library. Kodi's pulse wiki has that documented in detail.
(2019-05-24, 06:39)fritsch Wrote: [ -> ]File a bug with pulseaudio as this their behaviour not kodi's. You have two options:
a) disable pulse and use alsa (available on every Linux by default)
b) set kodi channels to 2 and enable Dolby transcode. This will output DTS / AC3 via passthrough and transcode 5.1 AAC to AC3.
c) Don't use passthrough at all. Configure your HDMI sink to 5.1 and kodi will losslessly decode DTS / AC3 / TrueHD / DTS-HD to multi channel pcm and output that.

Don't foget: Pulseaudio is a soundserver! For the entire system, not an audiophile special reconfigure sound library. Kodi's pulse wiki has that documented in detail.
Thanks for the response. Option b is the easiest solution at the moment although it seems "wrong" to transcode to an inferior codec. Won't make a difference in practice I guess.

May I ask why you believe this is a bug in Pulseaudio? What is it doing that it shouldn't be doing? If I am going to file a bug, I need to understand this. Or is it more of a limitation with Pulseaudio which requires an additional enhancement or feature to it?

I will try direct to Alsa when I get a chance. I don't really need Pulseaudio on this machine, since it is not used as a desktop or anything else requiring sound.

Thanks again.
Pulseaudio can either do passthrough OR multi channel output.
I've had the same issue in the beginning when i started with Linux, i have written a whole thread on how to passthrough the different audio formats to help new users as pulseaudio currently wont pass through AAC when using kodi please see the link to the guide below.

how to enable Dolby Atmos, DTS-X, TrueHD, DTS-HD Master Audio, Passthrough on Linux

this should work on Debian/Ubuntu and Arch based distributions, this guide will bypass PulseAudio Sound server and use ALSA instead without having to make any permanent changes to your system and revert back to using PulseAudio once you close Kodi.
All of this is documented in kodi's pulse wiki for nearly 4 years: https://kodi.wiki/view/PulseAudio
Yes its Documented but not very clearly laid out to new users of Linux hence why i made a clear step by step guide.
What do you miss in above wiki page?
Thanks to both I was able to test out the pass through of all formats directly through ALSA by suspending pulseaudio. While the core information is there in the Wiki, streamlove55's post was useful in recognizing that all formats could be passed through and that Kodi would bring up additional pass through options and to operationalize use of ALSA with a script.

Two things to note:

1. Not mentioned in the Wiki or implied in that post is what to do with my original problem of AAC 5.1 which was either sent as stereo when pass through was enabled via PulseAudio or had to be transcoded to AC3. With PulseAudio suspended and going directly through ALSA, All other formats are passed through with best match to source but AAC to PCM conversion without transcoding to AC3 uses the number of channels specified in the Kodi configuration (which it didn't when PulseAudio was in use). So while it is necessary to set the number of channels to 2 to enable pass through via PulseAudio, this number should be set to the actual number desired (or max capable of such as 5.1, 7.1, etc) and the pass through of other formats will still happen and AAC will be sent without downsizing up to the number of channels specified in kodi. If that number is left at 2 from before, AAC 5.1 will only go out as stereo. If 5.1 is specified as number of channels in Kodi setup, AAC 5.1 will be sent as multi-channel PCM of 5.1. So this certainly solves the problem but the need to specify the channel configuration for sending AAC as multi-channel PCM is not in the Wiki and not obvious because of previous necessity for specifying 2 channels before.

2. Suspending PulseAudio has broken my use of MPV as external player (for hardware decoding and playing of 10-bit 4k X265 using CUDA for the Nvidia card). It freezes right at start (possibly looking for Pusle that has been suspended). I am sure there are some additional parameters that need to be provided to the MPV invocation in playercorefactory.xml to make MPV work with ALSA with PulseAudio suspended. If any one knows the magical parameters that need to be provided, let me know.
I will just leave the following solution here for people who may stumble on this in the future and face the same issue.

To answer my question above on the use of MPV as external player with pulseaudio suspended as above and use ALSA, mpv may fail to play because by default it might try to use pulseaudio.

To overcome this, mpv invoked in playercorefactory.xml can be configured with the following additional parameters for the value of args in the XML

--audio-device='name of audio device to use' (use the command mpv --audio-device=help to get the list of available devices and use any within quotes and skip the quotes)
--audio-spdif=ac3,dts,dts-hd,eac3,truehd (this list specifies the formats that should be passed through to the specified audio device)

If you have set up the default alsa device to be the one you need, the above audio-device parameter can be shortened to

--audio-device=alsa
There are other solutions i have read about to disable Pulse and enable ALSA and I had no luck with any of those.
What worked for me was to create another user.
User 1 has Pulse disabled so that Kodi plays all DTSMA Dobly True HD etc using ALSA
User 2 with no changes made enabling you to watch say TSN in your browser and have sound which would be from Pulse