PulseAudio: Difference between revisions

From Official Kodi Wiki
Jump to navigation Jump to search
(Transition from XBMC to Kodi)
Line 1: Line 1:
{{mininav|[[Audio]]|[[Linux audio]]}}
{{mininav|[[Audio]]|[[Linux audio]]}}
<section begin="intro" />This page goes into detail on using PulseAudio on Linux systems. PulseAudio is used when XBMC 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 XBMC playback of video or audio to be paused in order to run a game, Skype or similar. XBMC is set to only use PulseAudio if you have installed it and running.<section end="intro" />
<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" />


== History ==
== History ==
In the past users have experienced problems with audio not working within XBMC, because they were running a full-blown Ubuntu desktop environment with PulseAudio installed. This happened because PulseAudio blocked the device XBMC required, and audio playback only worked reliably when using the virtual Pulse device.
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.
Our workaround for those users has been to uninstall PulseAudio which completely broke desktop audio.


For XBMC 13 'Gotham' and later we wanted this situation to change, so thanks to the new '''PulseAudio Sink''' users now can run a normal Ubuntu desktop.
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 Output Configuration ==
PulseAudio will be automatically detected and selected in XBMC when it is running.
PulseAudio will be automatically detected and selected in Kodi when it is running.


PulseAudio can be run in one of two modes these are:
PulseAudio can be run in one of two modes these are:
Line 17: Line 17:
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.
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 XBMC implementation.}}
{{Note| PulseAudio does not currently allow TrueHD or DTS-MA passthrough, this is a PulseAudio limitation and not a limitation of the Kodi implementation.}}


<big>'''Multichannel Mode'''</big>
<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 XBMC must decode all audio formats to PCM for passing onto the PulseAudio, this can have the advantage of improve audio/video sync.
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.


{{Note| Audio decoded to PCM and sent through PulseAudio the audio will not likely be "bit perfect". Where a video has TrueHD 7.1 audio, this can be decoded by XBMC to PCM 7.1, however DTS-HD 7.1 audio can't be decoded by XBMC, only the embedded DTS Core 5.1 can be decoded to PCM 5.1 audio. Als 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.}}
{{Note| Audio decoded to PCM and sent through PulseAudio the audio will not likely be "bit perfect". Where a video has TrueHD 7.1 audio, this can be decoded by Kodi to PCM 7.1, however DTS-HD 7.1 audio can't be decoded by Kodi, only the embedded DTS Core 5.1 can be decoded to PCM 5.1 audio. Als 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 />
<br />
Line 59: Line 59:
</gallery>
</gallery>


=== Example setup in xbmc ===
=== Example setup in Kodi ===
{{orangev|'''GOOD TO KNOW:'''| Limit sample rate can be set to Fixed - between 48kHz ~ 192kHz or as Optimized and even Best match.}}
{{orangev|'''GOOD TO KNOW:'''| Limit sample rate can be set to Fixed - between 48kHz ~ 192kHz or as Optimized and even Best match.}}


Line 74: Line 74:


=== Setup Guide ===
=== Setup Guide ===
{{orangev|DEVICE ENUMERATION:| XBMC 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 xbmc will be available.}}
{{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.}}
{{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.}}
{{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.}}
Line 154: Line 154:
|Digital Surround 7.1 <br />(HDMI) Output
|Digital Surround 7.1 <br />(HDMI) Output
|-  
|-  
!Colspan="9"|XBMC Settings
!Colspan="9"|Kodi Settings
|-
|-
|align="left"|'''Audio Output Device'''
|align="left"|'''Audio Output Device'''
Line 268: Line 268:
<pre>killall pulseaudio</pre>
<pre>killall pulseaudio</pre>


xbmc will then pickup the device, it is named '''combined'''.
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. }}
{{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. }}
Line 287: Line 287:
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.
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.


{{orangev|'''Alternatively:'''| If you don't want any resampling outside xbmc, 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 xbmc 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. }}
{{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. }}


== FAQ ==
== FAQ ==
Line 298: Line 298:
You should use '''PulseAudio''' when:
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 applications audio like Skype, youtube, browser mail notification in parallel with XBMC.
* You want other applications audio like Skype, youtube, browser mail notification in parallel with Kodi.
* You use xbmc in windowed mode 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 Bluetooth 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)
}}
}}


Line 312: Line 312:
You should use '''ALSA''' when:
You should use '''ALSA''' when:


* You use XBMC as your standalone media center.
* You use Kodi as your standalone media center.
* You are highly interested in bitperfect exclusive audio output.
* You are highly interested in bitperfect exclusive audio output.
* DTS-HD, TrueHD is something you use daily and is of high importance.
* DTS-HD, TrueHD is something you use daily and is of high importance.
Line 323: Line 323:
| Answer=
| Answer=
* '''PulseAudio''' might hog your Audio device and you cannot open the '''ALSA''' device exclusively, therefore we decided for one or the other.
* '''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 xbmc chooses, might be busy or even might vanish while you are using xbmc, 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.
* 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.
}}
}}


Line 332: Line 332:
{{note|But you know that doing so, it will cause problems!}}
{{note|But you know that doing so, it will cause problems!}}


Yes, you can - start xbmc from terminal with:
Yes, you can - start Kodi from terminal with:
<pre>AE_SINK=ALSA xbmc</pre>
<pre>AE_SINK=ALSA Kodi </pre>
: Be warned as this might interfere with your Desktop sounds and PulseAudio!
: Be warned as this might interfere with your Desktop sounds and PulseAudio!
}}
}}
Line 342: Line 342:
''load-module module-udev-detect tsched=0''
''load-module module-udev-detect tsched=0''


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 xbmc. This is default pulseaudio server behaviour. You can workaround that by disabling ''enable-remixing'' in /etc/pulse/daemon.conf
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''
''enable-remixing = no''

Revision as of 10:26, 15 January 2015

Home icon grey.png   ▶ Audio ▶ Linux 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.

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.

Note: Audio decoded to PCM and sent through PulseAudio the audio will not likely be "bit perfect". Where a video has TrueHD 7.1 audio, this can be decoded by Kodi to PCM 7.1, however DTS-HD 7.1 audio can't be decoded by Kodi, only the embedded DTS Core 5.1 can be decoded to PCM 5.1 audio. Als 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 exclusive mode. If you have another application hogging the device, e.g. google chrome or skype or something else, Passthrough won't work.
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, just setup pavucontrol, as in the following:

If you like to do this from the command line, issue:

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

Where 0 is the sink you want to alter. You can print all sinks, by using:

pactl list sinks

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.


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)
PusleAudio 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 change the default sample rate to 96 or 192 khz. Pulseaudio does not resample audio, that is already in the correct samplerate. Furthermore you need to take care, that your sink has a wide enough output format.

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 = s32le 
default-sample-rate = 96000
resample-method = speex-float-5

Some remark: This will actively make passthrough non working, as we need s16le format for adding ac3 / dts / etc. float 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: But you know that doing so, it will cause problems!

Yes, you can - start Kodi from terminal with:

AE_SINK=ALSA Kodi 
Be warned as this might interfere with your Desktop sounds and PulseAudio!

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

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

References

Attention talk.png Linux - Pulseaudio Sink Discussion and further information.