PulseAudio: Difference between revisions

From Official Kodi Wiki
Jump to navigation Jump to search
(And save until spoken to fritsch and get some other info and maybe ping jjd-uk to feed input)
(Update AE_SINK to KODI_AE_SINK, we have v20 out of the door.)
 
(152 intermediate revisions by 12 users not shown)
Line 1: Line 1:
{{Gotham|Current development which will be part of XBMC v13 Now supports '''AESinkPULSE'''|PULSEAUDIO SINK SUPPORT IN XBMC v13}}
{{mininav|[[Audio]]}}
{{-}}
<section begin="intro" />This page goes into detail on using PulseAudio on Linux systems. PulseAudio is used when Kodi is installed in a desktop-environment rather than a dedicated/direct boot setup. PulseAudio allows normal video & audio playback in XBMC while at the same time allowing the user to get audio in their browser or other applications. It also allows Kodi playback of video or audio to be paused in order to run a game, Skype or similar. Kodi is set to only use PulseAudio if you have installed it and running.<section end="intro" />
'''THIS PAGE IS A WIP'''
 
{{progress|64}}
== History ==
In the past users have experienced problems with audio not working within Kodi, because they were running a full-blown Ubuntu desktop environment with PulseAudio installed. This happened because PulseAudio blocked the device Kodi required, and audio playback only worked reliably when using the virtual Pulse device.
 
Our workaround for those users has been to uninstall PulseAudio which completely broke desktop audio.
 
For XBMC 13 'Gotham' and later (named Kodi since 14 'Helix') we wanted this situation to change, so thanks to the new '''PulseAudio Sink''' users now can run a normal Ubuntu desktop.
 
== PulseAudio Output Configuration ==
PulseAudio will be automatically detected and selected in Kodi when it is running.
 
PulseAudio can be run in one of two modes these are:
 
<big>'''Passthrough Mode'''</big>
Used if you want to passthrough (bitstream) AC3, DTS, and EAC3 to an AVR or other device. In order to allow passthrough to work with PulseAudio then it '''MUST''' be set to use a 2.0 channel configuration, despite the 2.0 setting this will still allow 5.1 audio from AC3, DTS, and EAC3.
 
{{Note| PulseAudio does not currently allow TrueHD or DTS-MA passthrough, this is a PulseAudio limitation and not a limitation of the Kodi implementation, in order to get 7.1 audio Multichannel Mode must be used}}
 
<big>'''Multichannel Mode'''</big>
 
Used if you want Multichannel PCM out, in this mode you can configure PulseAudio for up to 7.1 channels. In this mode Kodi must decode all audio formats to PCM for passing onto the PulseAudio, this can have the advantage of improve audio/video sync. In the case of video with TrueHD/DTS-HD 7.1 audio this must be decoded by Kodi to Multichannel PCM by disabling passthrough, then Pulseaudio can handle the 7.1 channels of audio.
 
{{Note| Audio decoded to PCM and sent through PulseAudio the audio will not likely be "bit perfect".  As Pulseaudio will always open the number of channels you have configured. You can stop it doing upmixing (see Known issues), but it will still open all configured channels which makes Dolby Pro Logic II of your AVR not usable.}}
 
<br />
 
== Setting up pavucontrol  ==
 
=== Passthrough Mode ===
{{bluev|'''IMPORTANT:'''|Passthrough is always an exclusive mode. If you have another application hogging the device, e.g. Chrome or Skype, passthrough won't work. Even applications that simply monitor the device, such as SoundWireServer, will prevent passthrough from working.}}
{{greenv|'''REMEMBER:'''| To use passthrough you need to be using '''2.0''' channel configuration via '''pavucontrol''' (e.g. Digital Stereo (HDMI)}}
 
In order to activate passthrough codecs, setup pavucontrol as following:
 
<gallery widths=500px heights=313px>
File:Passthrough2.png|<big>'''Step 1:'''</big>  ''pavucontrol''  '''Output Settings.'''
File:Passthrough1.png|<big>'''Step 2:'''</big>  ''pavucontrol''  '''Configuration.'''
</gallery>


{{Audionav}}
If you like to do this from the command line, first, first identify the correct sound card ID:
'''pacmd list-cards'''


=='''Outline'''==
Look at the output to find the id of the card and  the name/format of the profile you want to use (in this case, card ID is '''0''' and profile is '''output:hdmi-stereo''')
In the past XBMC had immense problems with users not getting Audio, because they had a full blown Ubuntu Desktop environment with PulseAudio installed.
Once you've identified this information, set your output profile to the one for hdmi-stereo:
PulseAudio blocked the specific device required, and Audio Playback only worked reliably when using the virtual pulse device. Our workaround for those users was to uninstall pulseaudio. This of course broke complete Desktop Audio for these users.
'''pacmd set-card-profile 0 output:hdmi-stereo'''


::;We wanted this situation to change with XBMC Gotham releases.
Then, obtain the sink ID you want to set formats on by inspecting output of:
'''pactl list sinks'''


'''Changes in Gotham:'''
Then set the sink format for the sink you want, as below (in this case '''0'''):
Users that run a normal Ubuntu Desktop and just use xbmc for normal video / audio playback while also wanting Audio in parallel in their browser or pause xbmc, run a game or rhythmbox / skype or whatever, they can now use our new '''PulseAudio Sink''' when using nightly and newer XBMC Gotham builds..
  '''pactl set-sink-formats 0 "pcm; ac3-iec61937; dts-iec61937; eac3-iec61937"'''


=='''Introduction'''==
You can leave out the codecs your AVR does not support, always keep pcm.
This Sink automatically detects if PulseAudio is running and <u>'''so'''</u> assumes that the user, which installed PA and uses PA, also wants to use it.


This pulseaudio sink is also able to do '''AC3''', '''DTS''' and '''EAC3''' passthrough. Alternatively it can be configured to be a 7.1 or 5.1 output device.
{{bluev|'''IMPORTANT:'''| If you have for example 5.1 flacs or other multichannel files, you can play them as AC3 streams, check the AC3 Transcoding setting.}}
This is an exclusive OR. pulseaudio only provides '''AC3''', '''DTS''', '''EAC3''' when it is configured to run with '''2 channels''' (which is the default on every Desktop).


{{redv|'''IMPORTANT:'''| Enabling ''' Sync Playback to Display ''' will disable passthrough silently, as it makes zero sense to sync with a display clock while one cannot alter audio.}}


***Clenup
=== Multichannel Mode ===
Further references to Pulseaudio in this page also as '''PA''' or Pulse
{{greenv|'''REMEMBER:'''| When configuring pulse to use '''Multichannel configuration''' passthrough will be disabled}}
***Cleanup
To configure instead Multi channel mode, do the following settings.


<gallery widths=500px heights=313px>
File:Lpcm2.png|<big>'''Step 1:'''</big> ''To alternatively configure Multi channel, check this:''.
File:Lpcm1.png|<big>'''Step 2:'''</big> The ''Add-on manager'', displaying four/five options  (explained below).
</gallery>


=== Device support ===
=== Example setup in Kodi ===
{{editor note|<< table this with rest}}
{{orangev|'''GOOD TO KNOW:'''| Limit sample rate can be set to Fixed - between 48kHz ~ 192kHz or as Optimized and even Best match.}}


What Pulse supports:
<gallery widths=500px heights=313px>
When configured as digital stereo)  
File:Xbmclpcm.png |<big>'''Step 1:'''</big>  ''to be edited''  '''Output Settings.'''
Multichannel Output (when configured as 5.1 device)
File:Xbmcpaa1.png |<big>'''Step 2:'''</big>  ''to be edited'' '''Configuration.'''
</gallery>


What Pulse does not do:
<gallery widths=500px heights=313px>
- DTS-HD, TrueHD passthrough
File:Xbmcpass2.png |<big>'''Step 1:'''</big>  ''to be edited''  '''Output Settings.'''
File:Xbmcpass1.png |<big>'''Step 2:'''</big>  ''to be edited''  '''Configuration.'''
</gallery>
{{-}}


:{|class="wikitable" style="text-align: center; color: black;"
=== Setup Guide ===
!colspan="24" style="color:#000000; background-color:#DBDBDB;"| '''Passthrough Support'''
{{orangev|DEVICE ENUMERATION:| Kodi Enumerates Pulseaudio devices as SPDIF when you have '''Passthrough''' set. Otherwise its '''PCM Device'''. If '''Passthrough''' was not configured with pavucontrol - no '''Passthrough''' setting within Kodi will be available.}}
{{bluev|GOOD TO KNOW:|SPDIF has 2 pcm channels but can do virtual 5.1 formats like dts, ac3, eac3.}}
{{greenv|'''NOTICE'''|The following is meant to act as a guide to get you started, thus you may want to adjust things to suit your own particular set of equipment.}}
{| class="prettytable" style="text-align: center; color: black;"
!
! PC Speakers<br />2.0
! PC Speakers<br />5.1
! TV SPDIF<br />2.0
! TV SPDIF<br />AC3 ('''1''')
! AVR SPDIF<br />AC3/DTS ('''2''')
! AVR HDMI<br />PCM ('''3''')
! AVR HDMI<br />No HD Audio ('''4''')
! AVR HDMI<br />Decode HD Audio ('''5''')
|-
|-
!colspan="20" |'''Audio formats'''
! colspan="9"|'''PulseAudio Mode'''
!colspan="2" |'''Supported'''
!colspan="2" |'''Limitations
|-
|-
|colspan="20"| AC3
|
|colspan="2" {{Yes}}
|Multichannel
|colspan="2" {{No}}
|Multichannel
|Multichannel
|Passthrough
|Passthrough
|Multichannel
|Passthrough
|Multichannel
|-
|-
|colspan="20"| DTS
! colspan="9"|'''Pavucontrol - Output Devices'''
|colspan="2" {{Yes}}
|colspan="2" {{No}}
|-
|-
|colspan="20"| DD+/E-AC3
|align="left"|'''Port'''
|colspan="2" {{Yes}}
|Speakers
|colspan="2" {{No}}
|Speakers
|Digital Output (S/PDIF)
|Digital Output (S/PDIF)
|Digital Output (S/PDIF)
|HDMI/Displayport
|HDMI/Displayport
|HDMI/Displayport
|-
|-
|colspan="20"| DTS-HD
|align="left"|'''AC3'''
|colspan="2" {{No}}
|N/A
|colspan="2" {{Yes}}
|N/A
|Disabled
|Enabled
|Enabled
|Disabled
|Enabled
|Disabled
|-
|-
|colspan="20"| TrueHD
|align="left"|'''EAC3'''
|colspan="2" {{No}}
|N/A
|colspan="2" {{Yes}}
|N/A
|Disabled
|Disabled
|Disabled
|Disabled
|Enabled
|Disabled
|-
|-
|align="left"|'''DTS'''
|N/A
|N/A
|Disabled
|Disabled
|Enabled
|Disabled
|Enabled
|Disabled
|-
! colspan="9"|'''Pavucontrol - Configuration'''
|-
|align="left"|'''Profile'''
|Analog Stereo Output
|Analog Surround 5.1 Output
|Digital Stereo <br />(IEC958) Output
|Digital Stereo <br />(IEC958) Output
|Digital Stereo <br />(IEC958) Output
|Digital Surround 5.1 <br />(HDMI) Output
|Digital Stereo <br />(HDMI) Output
|Digital Surround 7.1 <br />(HDMI) Output
|-
!Colspan="9"|Kodi Settings
|-
|align="left"|'''Audio Output Device'''
|Speakers
|Speakers
|SPDIF
|SPDIF
|SPDIF
|HDMI
|HDMI
|HDMI
|-
|align="left"|'''Number of channels'''
|2.0
|5.1
|N/A
|N/A
|N/A
|5.1
|2.0
|7.1
|-
|align="left"|'''Enabled passthrough'''
|Disabled
|Disabled
|Disabled
|Enabled
|Enabled
|Disabled
|Enabled
|Disabled
|-
|align="left"|'''Passthrough output device'''
|N/A
|N/A
|N/A
|SPDIF
|SPDIF
|N/A
|HDMI
|N/A
|-
|align="left"|'''Dolby Digital (AC3) capable receiver'''
|N/A
|N/A
|N/A
|Enabled
|Enabled
|Disabled
|Enabled
|Disabled
|-
|align="left"|'''Enabled Dolby Digital transcoding'''
|N/A
|N/A
|N/A
|Enabled
|Enabled
|Disabled
|Enabled
|Disabled
|-
|align="left"|'''DTS capable receiver'''
|N/A
|N/A
|N/A
|Disabled
|Enabled
|Disabled
|Enabled
|Disabled
|-
|align="left"|'''TrueHD capable receiver'''
|N/A
|N/A
|N/A
|Disabled
|Disabled
|Disabled
|Disabled
|Disabled
|-
|align="left"|'''DTS-HD capable receiver'''
|N/A
|N/A
|N/A
|Disabled
|Disabled
|Disabled
|Disabled
|Dsiabled
|}
|}


== '''Setup''' ==
'''(1)''' Where TV can decode 5.1 AC3.
In order to activate Passthrough Codecs, just use pavucontrol, like in the following:
 
'''(2)''' Where AVR only has SPDIF which will support 5.1 AC3 & DTS.
 
'''(3)''' Where AVR can do 5.1 PCM.
 
'''(4)''' Where AVR has HDMI inputs but can't decode TrueHD or DTS-HD but does support 5.1 Ac3 or DTS.
 
'''(5)''' Where AVR has full decode capabilities including 7.1 PCM.
 
{{orangev|'''IMPORTANT:'''| You can only have '''AC3''', '''DTS''', '''EAC3''' passthrough '''if your Receiver supports it'''. Most '''TV's''' only support '''AC3'''. If you have a '''HDMI''' connection to your TV and '''from this TV''' a '''SPDIF/Optical''' connection to an '''AVR''', passthrough might not work at all.}}
 
== Combined Output aka dual audio==
If you want to output to all your attached devices in parallel, e.g. HDMI out, analog out and USB sound card, it is enough to do as below:
 
'''Step 1:''' Edit <code>/etc/pulse/default.pa</code>
 
<pre>load-module module-combine-sink sink_name=combined</pre>
'''Step 2: '''Restart pulseaudio.
<pre>killall pulseaudio</pre>
 
Kodi will then pickup the device, it is named '''combined'''.
 
{{orangev|'''Downside:'''| The dual audio sink will only output decoded audio, you cannot use it to have one slave doing AC3/DTS and the other PCM. If you use the combined sink for normal music you will realize that direct passthrough output for your movies won't be working anymore, too. This is a pulseaudio bug, cause the combine sink is not deconstructed fast enough internally while the passthrough opening is always exclusive. It will work however if your passthrough device is not part of the device combination. }}
 
== Audiophile Pulse User ==
Pulseaudio resamples everything that does not match the underlaying sink, so if you are an audiophile user, you perhaps want to hear your 96 / 192 khz and 24 bit recordings as exact as possible. Therefore you need to tell pulseaudio to use a better resampler in general and second  avoid resampling. Starting with version 11 of pulseaudio, it can reopen sinks with their native samplerate. Furthermore you need to take care, that your sink has a wide enough output format. To properly resample samperates that are not available with your sound card, e.g. 176000 or other exotic rates, we set pulseaudio to a default of 44100 khz, which is the default for every standard mp3. As alternate sample-rate we suggest 48000. That means that all non available samplerates are resampled with an exact integer division of src_rate / dst_rate.
 
To do this configuration systemwide (96 khz in that example), change /etc/pulse/daemon.conf to include (please replace already existing lines and also remove the commenting):


[[File:Pavucontrol.png|800px]]
<pre>
default-sample-format = s24le
default-sample-rate = 44100
alternate-sample-rate = 48000
;new with pulseaudio 11
avoid-resampling = true
resample-method = speex-float-5
</pre>


To alternatively configure Multi channel, check this:
Some remark: This will actively make '''passthrough non working''', as we need s16le format for adding ac3 / dts / etc. to the sink.


[[File:Pavucontrol-channels.png|800px]]
The last setting will increase the resample quality from pulse and therefore the CPU load quite a lot. Again: Resampling is only done, when the sink output does not match the data you throw onto it. But as most normal mp3s are in 44.1 khz, you need to take great care when upsampling them. The overwriting of the resample-method is for this use case.


{{note|'''Ubuntu 13.10''' has a bug and passthrough might sound like noise, if you are affected only disabling passthrough helps. This is a distribution bug (OpenELEC, Arch, Debian, OpenSUSE works with the same code)
{{orangev|'''Alternatively:'''| If you don't want any resampling outside Kodi, e.g. no resampling done extra by pulse, you need to configure the sink as told above and set Audio Engine to '''Fixed''' with the number of channels you configured pulseaudio via pavucontrol and samplerate of '''96 khz''' with resample quality high. In that combination Kodi will take care that files are resampled (e.g. 44.1 khz or 48 khz media) in the best possible quality. Already 96 khz files are not touched at all. }}
 
::Passthrough is always exclusive mode. If you have another application hogging the device, e.g. google chrome or skype or something else, Passthrough won't work.}}


== '''FAQ''' ==
== FAQ ==


;When would I want Pulseaudio:
{| width="100%"
{{FAQ|1=When_would_I_want_Pulseaudio
| BGcolor=whitesmoke
| Question=When would I want PulseAudio?
| Answer=
You should use '''PulseAudio''' when:


* You use your xbmc computer mainly as your Desktop when you don't run xbmc
* You use your Kodi computer mainly as your Desktop when you don't run XBMC.
* You want other sounds like Skype, youtube, browser mail notification in parallel
* You want other applications audio like Skype, youtube, browser mail notification in parallel with Kodi.
* You use xbmc windowed as Desktop player
* You use Kodi in windowed mode as Desktop player
* You use Pulseaudio as a network sink to stream Audio to other devices in your living room
* You use Pulseaudio as a network sink to stream Audio to other devices in your living room.
* Passthrough is nice to have for you, but to be honest - you don't really need it.
* Passthrough is nice to have for you, but to be honest - you don't really need it.
* Whenever you plugin your BT headset, xbmc audio will continue over this new device (when Default (PULSE) device is chosen)
* Whenever you plugin your Bluetooth headset, Kodi audio will continue over this new device (when Default 'PULSE' device is chosen)
}}
 
{{FAQ|1=When_would_I_want_ALSA
| BGcolor=
| Question=When would I want ALSA?
| Answer=
You should use '''ALSA''' when:
 
* You use Kodi as your standalone media center.
* You are highly interested in bitperfect exclusive audio output.
* DTS-HD, TrueHD is something you use daily and is of high importance.
* You don't need other applications that would access audio in parallel.
}}
 
{{FAQ|1=Why_cant_I_have_both?
| BGcolor=whitesmoke
| Question=Why can't I have both?
| Answer=
* '''PulseAudio''' might hog your Audio device and you cannot open the '''ALSA''' device exclusively, therefore we decided for one or the other.
* Whenever '''PulseAudio''' is running your '''ALSA''' device that Kodi chooses, might be busy or even might vanish while you are using Kodi, when system sounds are playing and pulseaudio is trying to access the device again. Out of this reason we also won't implement a selection box to decide between '''ALSA''' and '''PULSE''', because it will actively harm users. Advanced Users can go with the workaround listed beneath.
}}
 
{{FAQ|1=Forcing_alsa
| BGcolor=
| Question=Can I force ALSA even with PulseAudio installed?
| Answer=
{{note|Doing so may cause problems!}}
 
Yes, you can - start Kodi from terminal with:
<pre>pasuspender -- env KODI_AE_SINK=ALSA kodi</pre>
 
'''pasuspender''' is a tool that can be used to tell a local PulseAudio sound server to temporarily suspend access to the audio devices, to allow other applications access them directly. pasuspender will suspend access to the audio devices, fork a child process, and when the child process terminates, resume access again.
 
You can also put the previous command in a custom .desktop-file.
 
Be warned as this will interfere with your Desktop sounds!
}}
|}
=== Known issues ===
When your audio is much too fast or crackles a lot or passthrough only produces noise, you might have a broken driver in use. If this is the case, try to add ''tsched=0'' to the udev loading section in /etc/pulse/default.pa to read like:
 
''load-module module-udev-detect tsched=0''
 
Audio devices are disappearing with pulseaudio 8.0 (Ubuntu 16.04, even later version are affected) especially while running kodi and while using ''Adjust Refreshrate to match video''. This is an issue with the module-switch-on-port-available module and will be fixed with pulseaudio 9.0, the fix sadly won't probably make it into Ubuntu 16.04. As a workaround please disable that feature by editing /etc/pulse/default.pa and commenting or removing ''load-module module-switch-on-port-available'' and reboot the system.
 
''' Kodi v16 '''
 
When Pulseaudio is configured to be multi-channel output, e.g. 5.1 profile from within pavucontrol, 2.0 streams are automatically upmixed, no matter what setting you have chosen in Kodi. This is default pulseaudio server behaviour. You can workaround that by disabling ''enable-remixing'' in /etc/pulse/daemon.conf


;When would I want ALSA:
''enable-remixing = no''


* You use xbmc as your standalone media center
Beware: This will also forbid PA to remix e.g. FL,FR, LFE, FC, BL, BR into FL, FR, LFE, FC, SL, SR - which means you might loose your rears if your speaker layout is non standard.
* You are highly interested in bitperfect exclusive audio output
* DTS-HD, TrueHD is something you use daily and is of high importance
* You don't need other applications that would access audio in parallel


Why can't I have both:
''' Kodi v17 '''
* PA might hogg your Audio device and you cannot open the ALSA device exclusively, therefore we decided for one or the other.


Starting with the upcoming kodi v17 Krypton the above behaviour is taken care within kodi. You don't have to disable remixing in pulseaudio anymore. That means content is output without further remixing by pulseaudio server if a sane mapping is possible. Basically that means if the audio is FL, FR, FC, LFE, SL, SR and your speaker-mapping is FL, FR, FC, LFE, BL, BR we will resolve that and output 6 channels accordingly. Whenever we cannot map all input channels to the output we ask pulseaudio to do the mixing for us.


Placeholder for content from http://forum.xbmc.org/showthread.php?tid=183436
''' Volume issues '''


DO NOT Remove page, DO NOT Delete or rename this page
Issue: Changing kodi's volume will change overall system volume, especially on song change this is an irritating behaviour. The effect you hear is not done by kodi, but by a systemwide pulseaudio (mis)configuration. Some distributions sadly still ship pulseaudio with '''flat-volumes = yes''' as the default, which produces this behaviour. In fact it will cause the hardware volume (or master volume) to go up and down for every pulseaudio stream that changes its own volume. As this effect is unexpected behaviour for users, distributions started to ship pulseaudio with '''flat-volumes = no''' by default (as time of writing this is Ubuntu, Arch-Linux and others). In order to change that setting, depending on your distribution edit ''/etc/pulse/daemon.conf'' and set '''flat-volumes = no'''. After a PA server restart, the volume handling is more intuitive. If you are at it, please inform your distribution about those issues, so that they can ship a more user-friendly default with next release. At the time of writing, affected distributions: Debian.


{{forum link2|[[forum:183436|Linux - PulseAudio Sink]] Discussion and further information.}}<br />


Welcome to add information to it.
[[Category:Audio]]

Latest revision as of 19:25, 11 February 2023

Home icon grey.png   ▶ Audio ▶ PulseAudio

This page goes into detail on using PulseAudio on Linux systems. PulseAudio is used when Kodi is installed in a desktop-environment rather than a dedicated/direct boot setup. PulseAudio allows normal video & audio playback in XBMC while at the same time allowing the user to get audio in their browser or other applications. It also allows Kodi playback of video or audio to be paused in order to run a game, Skype or similar. Kodi is set to only use PulseAudio if you have installed it and running.

History

In the past users have experienced problems with audio not working within Kodi, because they were running a full-blown Ubuntu desktop environment with PulseAudio installed. This happened because PulseAudio blocked the device Kodi required, and audio playback only worked reliably when using the virtual Pulse device.

Our workaround for those users has been to uninstall PulseAudio which completely broke desktop audio.

For XBMC 13 'Gotham' and later (named Kodi since 14 'Helix') we wanted this situation to change, so thanks to the new PulseAudio Sink users now can run a normal Ubuntu desktop.

PulseAudio Output Configuration

PulseAudio will be automatically detected and selected in Kodi when it is running.

PulseAudio can be run in one of two modes these are:

Passthrough Mode Used if you want to passthrough (bitstream) AC3, DTS, and EAC3 to an AVR or other device. In order to allow passthrough to work with PulseAudio then it MUST be set to use a 2.0 channel configuration, despite the 2.0 setting this will still allow 5.1 audio from AC3, DTS, and EAC3.

Note: PulseAudio does not currently allow TrueHD or DTS-MA passthrough, this is a PulseAudio limitation and not a limitation of the Kodi implementation, in order to get 7.1 audio Multichannel Mode must be used

Multichannel Mode

Used if you want Multichannel PCM out, in this mode you can configure PulseAudio for up to 7.1 channels. In this mode Kodi must decode all audio formats to PCM for passing onto the PulseAudio, this can have the advantage of improve audio/video sync. In the case of video with TrueHD/DTS-HD 7.1 audio this must be decoded by Kodi to Multichannel PCM by disabling passthrough, then Pulseaudio can handle the 7.1 channels of audio.

Note: Audio decoded to PCM and sent through PulseAudio the audio will not likely be "bit perfect". As Pulseaudio will always open the number of channels you have configured. You can stop it doing upmixing (see Known issues), but it will still open all configured channels which makes Dolby Pro Logic II of your AVR not usable.


Setting up pavucontrol

Passthrough Mode

IMPORTANT: Passthrough is always an exclusive mode. If you have another application hogging the device, e.g. Chrome or Skype, passthrough won't work. Even applications that simply monitor the device, such as SoundWireServer, will prevent passthrough from working.
REMEMBER: To use passthrough you need to be using 2.0 channel configuration via pavucontrol (e.g. Digital Stereo (HDMI)


In order to activate passthrough codecs, setup pavucontrol as following:

If you like to do this from the command line, first, first identify the correct sound card ID:

pacmd list-cards

Look at the output to find the id of the card and the name/format of the profile you want to use (in this case, card ID is 0 and profile is output:hdmi-stereo) Once you've identified this information, set your output profile to the one for hdmi-stereo:

pacmd set-card-profile 0 output:hdmi-stereo

Then, obtain the sink ID you want to set formats on by inspecting output of:

pactl list sinks

Then set the sink format for the sink you want, as below (in this case 0):

pactl set-sink-formats 0 "pcm; ac3-iec61937; dts-iec61937; eac3-iec61937"

You can leave out the codecs your AVR does not support, always keep pcm.

IMPORTANT: If you have for example 5.1 flacs or other multichannel files, you can play them as AC3 streams, check the AC3 Transcoding setting.


IMPORTANT: Enabling Sync Playback to Display will disable passthrough silently, as it makes zero sense to sync with a display clock while one cannot alter audio.


Multichannel Mode

REMEMBER: When configuring pulse to use Multichannel configuration passthrough will be disabled

To configure instead Multi channel mode, do the following settings.

Example setup in Kodi

GOOD TO KNOW: Limit sample rate can be set to Fixed - between 48kHz ~ 192kHz or as Optimized and even Best match.



Setup Guide

DEVICE ENUMERATION: Kodi Enumerates Pulseaudio devices as SPDIF when you have Passthrough set. Otherwise its PCM Device. If Passthrough was not configured with pavucontrol - no Passthrough setting within Kodi will be available.
GOOD TO KNOW: SPDIF has 2 pcm channels but can do virtual 5.1 formats like dts, ac3, eac3.
NOTICE The following is meant to act as a guide to get you started, thus you may want to adjust things to suit your own particular set of equipment.
PC Speakers
2.0
PC Speakers
5.1
TV SPDIF
2.0
TV SPDIF
AC3 (1)
AVR SPDIF
AC3/DTS (2)
AVR HDMI
PCM (3)
AVR HDMI
No HD Audio (4)
AVR HDMI
Decode HD Audio (5)
PulseAudio Mode
Multichannel Multichannel Multichannel Passthrough Passthrough Multichannel Passthrough Multichannel
Pavucontrol - Output Devices
Port Speakers Speakers Digital Output (S/PDIF) Digital Output (S/PDIF) Digital Output (S/PDIF) HDMI/Displayport HDMI/Displayport HDMI/Displayport
AC3 N/A N/A Disabled Enabled Enabled Disabled Enabled Disabled
EAC3 N/A N/A Disabled Disabled Disabled Disabled Enabled Disabled
DTS N/A N/A Disabled Disabled Enabled Disabled Enabled Disabled
Pavucontrol - Configuration
Profile Analog Stereo Output Analog Surround 5.1 Output Digital Stereo
(IEC958) Output
Digital Stereo
(IEC958) Output
Digital Stereo
(IEC958) Output
Digital Surround 5.1
(HDMI) Output
Digital Stereo
(HDMI) Output
Digital Surround 7.1
(HDMI) Output
Kodi Settings
Audio Output Device Speakers Speakers SPDIF SPDIF SPDIF HDMI HDMI HDMI
Number of channels 2.0 5.1 N/A N/A N/A 5.1 2.0 7.1
Enabled passthrough Disabled Disabled Disabled Enabled Enabled Disabled Enabled Disabled
Passthrough output device N/A N/A N/A SPDIF SPDIF N/A HDMI N/A
Dolby Digital (AC3) capable receiver N/A N/A N/A Enabled Enabled Disabled Enabled Disabled
Enabled Dolby Digital transcoding N/A N/A N/A Enabled Enabled Disabled Enabled Disabled
DTS capable receiver N/A N/A N/A Disabled Enabled Disabled Enabled Disabled
TrueHD capable receiver N/A N/A N/A Disabled Disabled Disabled Disabled Disabled
DTS-HD capable receiver N/A N/A N/A Disabled Disabled Disabled Disabled Dsiabled

(1) Where TV can decode 5.1 AC3.

(2) Where AVR only has SPDIF which will support 5.1 AC3 & DTS.

(3) Where AVR can do 5.1 PCM.

(4) Where AVR has HDMI inputs but can't decode TrueHD or DTS-HD but does support 5.1 Ac3 or DTS.

(5) Where AVR has full decode capabilities including 7.1 PCM.

IMPORTANT: You can only have AC3, DTS, EAC3 passthrough if your Receiver supports it. Most TV's only support AC3. If you have a HDMI connection to your TV and from this TV a SPDIF/Optical connection to an AVR, passthrough might not work at all.


Combined Output aka dual audio

If you want to output to all your attached devices in parallel, e.g. HDMI out, analog out and USB sound card, it is enough to do as below:

Step 1: Edit /etc/pulse/default.pa

load-module module-combine-sink sink_name=combined

Step 2: Restart pulseaudio.

killall pulseaudio

Kodi will then pickup the device, it is named combined.

Downside: The dual audio sink will only output decoded audio, you cannot use it to have one slave doing AC3/DTS and the other PCM. If you use the combined sink for normal music you will realize that direct passthrough output for your movies won't be working anymore, too. This is a pulseaudio bug, cause the combine sink is not deconstructed fast enough internally while the passthrough opening is always exclusive. It will work however if your passthrough device is not part of the device combination.


Audiophile Pulse User

Pulseaudio resamples everything that does not match the underlaying sink, so if you are an audiophile user, you perhaps want to hear your 96 / 192 khz and 24 bit recordings as exact as possible. Therefore you need to tell pulseaudio to use a better resampler in general and second avoid resampling. Starting with version 11 of pulseaudio, it can reopen sinks with their native samplerate. Furthermore you need to take care, that your sink has a wide enough output format. To properly resample samperates that are not available with your sound card, e.g. 176000 or other exotic rates, we set pulseaudio to a default of 44100 khz, which is the default for every standard mp3. As alternate sample-rate we suggest 48000. That means that all non available samplerates are resampled with an exact integer division of src_rate / dst_rate.

To do this configuration systemwide (96 khz in that example), change /etc/pulse/daemon.conf to include (please replace already existing lines and also remove the commenting):

default-sample-format = s24le
default-sample-rate = 44100
alternate-sample-rate = 48000
;new with pulseaudio 11
avoid-resampling = true
resample-method = speex-float-5

Some remark: This will actively make passthrough non working, as we need s16le format for adding ac3 / dts / etc. to the sink.

The last setting will increase the resample quality from pulse and therefore the CPU load quite a lot. Again: Resampling is only done, when the sink output does not match the data you throw onto it. But as most normal mp3s are in 44.1 khz, you need to take great care when upsampling them. The overwriting of the resample-method is for this use case.

Alternatively: If you don't want any resampling outside Kodi, e.g. no resampling done extra by pulse, you need to configure the sink as told above and set Audio Engine to Fixed with the number of channels you configured pulseaudio via pavucontrol and samplerate of 96 khz with resample quality high. In that combination Kodi will take care that files are resampled (e.g. 44.1 khz or 48 khz media) in the best possible quality. Already 96 khz files are not touched at all.


FAQ

When would I want PulseAudio?

Link

You should use PulseAudio when:

  • You use your Kodi computer mainly as your Desktop when you don't run XBMC.
  • You want other applications audio like Skype, youtube, browser mail notification in parallel with Kodi.
  • You use Kodi in windowed mode as Desktop player
  • You use Pulseaudio as a network sink to stream Audio to other devices in your living room.
  • Passthrough is nice to have for you, but to be honest - you don't really need it.
  • Whenever you plugin your Bluetooth headset, Kodi audio will continue over this new device (when Default 'PULSE' device is chosen)

When would I want ALSA?

Link

You should use ALSA when:

  • You use Kodi as your standalone media center.
  • You are highly interested in bitperfect exclusive audio output.
  • DTS-HD, TrueHD is something you use daily and is of high importance.
  • You don't need other applications that would access audio in parallel.

Why can't I have both?

Link
  • PulseAudio might hog your Audio device and you cannot open the ALSA device exclusively, therefore we decided for one or the other.
  • Whenever PulseAudio is running your ALSA device that Kodi chooses, might be busy or even might vanish while you are using Kodi, when system sounds are playing and pulseaudio is trying to access the device again. Out of this reason we also won't implement a selection box to decide between ALSA and PULSE, because it will actively harm users. Advanced Users can go with the workaround listed beneath.

Can I force ALSA even with PulseAudio installed?

Link

Note: Doing so may cause problems!

Yes, you can - start Kodi from terminal with:

pasuspender -- env KODI_AE_SINK=ALSA kodi

pasuspender is a tool that can be used to tell a local PulseAudio sound server to temporarily suspend access to the audio devices, to allow other applications access them directly. pasuspender will suspend access to the audio devices, fork a child process, and when the child process terminates, resume access again.

You can also put the previous command in a custom .desktop-file.

Be warned as this will interfere with your Desktop sounds!

Known issues

When your audio is much too fast or crackles a lot or passthrough only produces noise, you might have a broken driver in use. If this is the case, try to add tsched=0 to the udev loading section in /etc/pulse/default.pa to read like:

load-module module-udev-detect tsched=0

Audio devices are disappearing with pulseaudio 8.0 (Ubuntu 16.04, even later version are affected) especially while running kodi and while using Adjust Refreshrate to match video. This is an issue with the module-switch-on-port-available module and will be fixed with pulseaudio 9.0, the fix sadly won't probably make it into Ubuntu 16.04. As a workaround please disable that feature by editing /etc/pulse/default.pa and commenting or removing load-module module-switch-on-port-available and reboot the system.

Kodi v16

When Pulseaudio is configured to be multi-channel output, e.g. 5.1 profile from within pavucontrol, 2.0 streams are automatically upmixed, no matter what setting you have chosen in Kodi. This is default pulseaudio server behaviour. You can workaround that by disabling enable-remixing in /etc/pulse/daemon.conf

enable-remixing = no

Beware: This will also forbid PA to remix e.g. FL,FR, LFE, FC, BL, BR into FL, FR, LFE, FC, SL, SR - which means you might loose your rears if your speaker layout is non standard.

Kodi v17

Starting with the upcoming kodi v17 Krypton the above behaviour is taken care within kodi. You don't have to disable remixing in pulseaudio anymore. That means content is output without further remixing by pulseaudio server if a sane mapping is possible. Basically that means if the audio is FL, FR, FC, LFE, SL, SR and your speaker-mapping is FL, FR, FC, LFE, BL, BR we will resolve that and output 6 channels accordingly. Whenever we cannot map all input channels to the output we ask pulseaudio to do the mixing for us.

Volume issues

Issue: Changing kodi's volume will change overall system volume, especially on song change this is an irritating behaviour. The effect you hear is not done by kodi, but by a systemwide pulseaudio (mis)configuration. Some distributions sadly still ship pulseaudio with flat-volumes = yes as the default, which produces this behaviour. In fact it will cause the hardware volume (or master volume) to go up and down for every pulseaudio stream that changes its own volume. As this effect is unexpected behaviour for users, distributions started to ship pulseaudio with flat-volumes = no by default (as time of writing this is Ubuntu, Arch-Linux and others). In order to change that setting, depending on your distribution edit /etc/pulse/daemon.conf and set flat-volumes = no. After a PA server restart, the volume handling is more intuitive. If you are at it, please inform your distribution about those issues, so that they can ship a more user-friendly default with next release. At the time of writing, affected distributions: Debian.