PulseAudio

出自 Arch Linux 中文维基

PulseAudio 是一種通用的聲音伺服器,旨在使用 ALSA or OSS作為應用程式和硬體設備之間的中間件運行。如果啟用,它還使用 Avahi 在本地設備之間提供輕鬆的網絡流。雖然其主要目的是簡化音頻配置,但其模塊化設計允許更高級的用戶精確地配置守護進程以最適合他們的需求。

注意: ALSA 與 PulseAudio之間可能會出現一些混淆。 ALSA 包括一個帶有音效卡驅動程序的 Linux 內核組件,以及一個用戶空間組件 libasound[1] PulseAudio 僅構建在內核組件上,但提供 libasoundpulseaudio-alsa的兼容性。[2]

安裝[編輯 | 編輯原始碼]

安裝 pulseaudio 軟體包。

某些 PulseAudio 模塊不包括在主封裝中,如果需要,必須單獨安裝:

前端[編輯 | 編輯原始碼]

有許多前端可用於控制 PulseAudio 守護程序:

控制台[編輯 | 編輯原始碼]

  • ncpamixer — 脈衝音頻的Ncurses混音器,靈感來自pavucontrol。
https://github.com/fulhax/ncpamixer || ncpamixerAUR
  • pacmixer — Alsamixer 同樣用於 PulseAudio。
https://github.com/KenjiTakahashi/pacmixer || pacmixerAUR
  • PAmix — Ncurses PulseAudio mixer,類似於 pavucontrol。
https://github.com/patroclos/PAmix || pamix-gitAUR
  • pamixer — PulseAudio 命令行混音器。
https://github.com/cdemoulins/pamixer || pamixer
  • pavolume — PulseAudio 的簡單命令行音量控制,帶有 libnotify 消息。
https://github.com/sseemayer/pavolume || pavolume-gitAUR
  • Ponymix — PulseAudio 命令行混音器。
https://github.com/falconindy/ponymix || ponymixAUR
  • pulseaudio-ctl — 從 shell 控制 PulseAudio 音量或映射到鍵盤快捷鍵。
https://github.com/graysky2/pulseaudio-ctl || pulseaudio-ctlAUR
  • pulsemixer — PulseAudio 的 CLI 和 curses 混音器
https://github.com/GeorgeFilipkin/pulsemixer || pulsemixer

圖形界面[編輯 | 編輯原始碼]

  • KMixKDE 音量控制應用程式支持多個平台,包括PulseAudio,系統托盤小程序可配置。
https://apps.kde.org/kmix/ || kmix
  • MicTray — 輕量級系統托盤應用程式,可讓您使用 PulseAudio 控制麥克風狀態和音量。
https://github.com/Junker/MicTray || mictrayAUR
  • pa-applet — PulseAudio 的系統托盤小程序,帶音量條。
https://github.com/fernandotcl/pa-applet || pa-applet-gitAUR
  • pasystray — PulseAudio 的系統托盤小程序。
https://github.com/christophgysin/pasystray || pasystray
  • plasma-paKDE Plasma 小程序,用於使用 PulseAudio 進行音量管理
https://invent.kde.org/plasma/plasma-pa || plasma-pa
  • PulseAudio Equalizer — 基於LADSPA的多頻段均衡器,用於PulseAudio。
https://github.com/pulseaudio-equalizer-ladspa/equalizer || pulseaudio-equalizer-ladspa
  • PulseAudio Graph Control — PulseAudio 基於 Electron的音量和圖形控制
https://github.com/futpib/pagraphcontrol#readme || pagraphcontrol-gitAUR
  • PulseAudio Manager — PulseAudio 的簡單 GTK 前端。已停止開發。
http://0pointer.de/lennart/projects/paman/ || pamanAUR
  • PulseAudio Preferences — PulseAudio 的簡單 GTK 配置對話框。
https://freedesktop.org/software/pulseaudio/paprefs/ || paprefs
  • PulseAudio Volume Control — PulseAudio的簡單GTK音量控制工具(「混音器」)。
https://freedesktop.org/software/pulseaudio/pavucontrol/ || pavucontrol
  • PulseAudio Volume Control (Qt) — Mixer for PulseAudio (Qt port of pavucontrol).
https://github.com/lxqt/pavucontrol-qt || pavucontrol-qt
  • PulseAudio Volume Control (Sandsmark) — Lightweight fork of the LXQt's pavucontrol, with missing features from pavucontrol implemented, bug fixes and unnecessary dependencies removed.
https://github.com/sandsmark/pavucontrol-qt || pavucontrol-qt-sandsmark-gitAUR
  • PulseAudio Volume Meter — Simple GTK volume meter for PulseAudio. Discontinued development.
http://0pointer.de/lennart/projects/pavumeter/ || pavumeterAUR
  • PulseEffects — Audio effects for PulseAudio applications.
https://github.com/wwmm/easyeffects/tree/pulseaudio-legacy || pulseeffects-legacyAUR
  • Volctl — Per-application system tray applet volume control for PulseAudio.
https://buzz.github.io/volctl/ || volctlAUR
  • Xfce PulseAudio Panel Plugin — PulseAudio plugin for Xfce4 panel.
https://goodies.xfce.org/projects/panel-plugins/xfce4-pulseaudio-plugin || xfce4-pulseaudio-plugin
  • pa-notify — PulseAudio or PipeWire volume notification daemon.
https://github.com/ikrivosheev/pa-notify || pa-notifyAUR

Configuration[編輯 | 編輯原始碼]

默認情況下,PulseAudio 配置為自動檢測所有音效卡並對其進行管理。它控制所有檢測到的ALSA設備,並將所有音頻流重定向到自身,使PulseAudio守護程序成為中央配置點。守護程序應該基本上是開箱即用的,只需要一些小的調整。

雖然PulseAudio通常開箱即用,只需要最少的配置,但高級用戶可以通過更改默認配置文件以禁用模塊或從頭開始編寫自己的模塊來更改守護程序的幾乎每個方面。

PulseAudio作為伺服器守護程序運行,可以使用客戶端/伺服器體系結構在系統範圍內運行或基於每個用戶運行。守護程序本身除了提供 API 和主機動態加載的模塊之外,沒有模塊,什麼都不做。音頻路由和處理任務都由各種模塊處理,包括PulseAudio的原生協議本身(由module-native-protocol-unix提供)。客戶端通過許多協議模塊之一到達伺服器,這些模塊將接受來自外部源的音頻,通過PulseAudio路由它,並最終讓它通過最後的其他模塊出去。輸出模塊不必是實際的聲音輸出:它可以將流轉儲到文件中,將其流式傳輸到Icecast等廣播伺服器,甚至只是丟棄它。

您可以在Pulseaudio Loadable Modules模塊上找到所有可用模塊的詳細列表。要啟用它們,您只需向 ~/.config/pulse/default.pa 中添加一行 load-module module-name-from-list 即可。

配置文件[編輯 | 編輯原始碼]

PulseAudio 將首先在 home 目錄中 ~/.config/pulse/查找配置文件,如果找不到它們,則將應用來自系統 /etc/pulse/ 的配置。

提示:
  • 強烈建議不要編輯系統範圍的配置文件,而是編輯用戶配置文件。創建~/.config/pulse 目錄,然後將系統配置文件複製到其中並根據需要進行編輯。
  • 確保使用戶配置與 /etc/pulse/中打包文件的更改保持同步。否則,PulseAudio可能會因配置錯誤而拒絕啟動。
  • 通常不需要將您的用戶添加到 audio 組中,因為PulseAudio使用 udevlogind 來動態地向當前 "active" 用戶授予訪問權限。例外情況包括無外設運行計算機,以便當前沒有 "active" 用戶。

daemon.conf[編輯 | 編輯原始碼]

這是配置守護程序本身的主配置文件。它定義了基本設置,如模塊使用的默認採樣率、重採樣方法、實時調度以及與伺服器進程相關的各種其他設置。如果不重新啟動 PulseAudio 守護程序,則無法在運行時更改這些內容。對於大多數用戶來說,預設值是明智的, 有關其他信息,請參閱 pulse-daemon.conf(5) man page 。 Boolean 選項接受以下任一選項: true, yes, on and 1 以及 false, no, off and 0.

注意: PulseAudio 不在此文件中的路徑上執行波形符擴展。對任何文件使用絕對路徑。
選項 描述
daemonize 控制伺服器是否將守護自身並返回。設置為 no 調試時,以便您可以在終端上看到調試信息。
resample-method 當需要在模塊之間傳遞採樣率不兼容的音頻時(例如,在僅支持48kHz的硬體上播放96kHz音頻),可以使用 的重採樣器可以與 pulseaudio --dump-resample-methods一起列出。 為當前用例選擇 CPU 使用率和音頻質量之間的最佳權衡。
提示:在某些情況下,PulseAudio將產生高CPU負載。當(單獨)對多個流進行重新採樣時,可能會發生這種情況。如果這是工作流程中的常見用例,則應考慮以匹配的採樣率創建一個額外的接收器,然後將其饋入主接收器,僅重新採樣一次。
avoid-resampling 使用 avoid-resampling = yes, PulseAudio會自動將硬體配置為應用程式使用的採樣率(如果硬體支持此採樣率)(需要 PulseAudio 11+)
警告: 啟用此功能可能會導致音頻失真,因此默認情況下處于禁用狀態,有關詳細信息,請參閱 release notes
enable-remixing 當輸入和輸出具有不同的通道數(例如,將6通道電影輸出到立體聲接收器中)時,pulse可以重新混合所有通道(默認 yes),或者當no時只是按名稱簡單映射通道(左到左,從右到右,所有其他通道被忽略)
system-instance If set to yes, run the daemon as a system-wide instance. Highly discouraged as it can introduce security issues. Useful on Multiseat systems, or headless systems that have no real local users. Defaults to no.
flat-volumes flat-volumes scales the device-volume with the volume of the "loudest" application. For example, raising the VoIP call volume will raise the hardware volume and adjust the music-player volume so it stays where it was, without having to lower the volume of the music-player manually. Defaults to yes upstream, but to no within Arch.
注意: The default behavior upstream can sometimes be confusing and some applications, unaware of this feature, can set their volume to 100% at startup, potentially blowing your speakers or your ears. This is why Arch defaults to the classic (ALSA) behavior by setting this to no.
realtime-scheduling If your kernel supports realtime scheduling (for instance, Realtime kernel or Linux-ck), set this to yes to ensure PulseAudio can deliver low-latency glitch-free playback. You can adjust realtime-priority as well to have it use the correct priority, especially when JACK is also running on the system.
nice-level Since PulseAudio runs in userspace and involves inter-process communication, audio can be subject to dropouts if the daemon does not have enough CPU time to process the audio. The default usually is enough, but can be tweaked to give pulse the wanted priority over (or below) other applications.
exit-idle-time If you want to run PulseAudio only when needed and use ALSA otherwise, you can set a delay in seconds after which the daemon will automatically shutdown after all clients are disconnected. Set it to -1 to disable this feature.
log-level When debugging, you may want to increase the logging level of the daemon to see exactly why a specific module fails to load. High logging levels will sometimes print useful information such as detected minimum latency for the system, which can then be used to tweak default-fragments and default-fragment-size-msec.
default-sample-format This usually does not need to be changed, but if your sound card's native format is different, performance and quality can be improved by setting the right format here.
default-sample-rate The default sample rate user by pulse unless overriden at module level. Change this if your sound card does not support 44100Hz or if you wish to upsample all audio. See previous note about CPU usage.
alternate-sample-rate To fix a common limitation where movies at 48000Hz were needlessly downsampled to 44100Hz, some modules support changing their sample rate dynamically to avoid resampling when possible. See manual for more in-depth information. This usually does not need to be changed.
default-channels The default number of channels when not specified. Usually do not need any change as you can configure more channels on per-module basis.
default-fragments Audio samples are split into multiple fragments of default-fragment-size-msec each. The larger the buffer is, the less likely audio will skip when the system is overloaded. On the downside this will increase the overall latency. Increase this value if you have issues.
default-fragment-size-msec The size in milliseconds of each fragment. This is the amount of data that will be processed at once by the daemon.

default.pa[編輯 | 編輯原始碼]

This file is a startup script and is used to configure modules. It is actually parsed and read after the daemon has finished initializing and additional commands can be sent at runtime using pactl(1) or pacmd(1). The startup script can also be provided on the command line by starting PulseAudio in a terminal using pulseaudio -nC. This will make the daemon load the CLI module and will accept the configuration directly from the command line, and output resulting information or error messages on the same terminal. This can be useful when debugging the daemon or just to test various modules before setting them permanently on disk. The manual page is quite self-explanatory, consult pulse-cli-syntax(5) for the details of the syntax.

提示:
  • Rather than being a complete copy, ~/.config/pulse/default.pa can start with the line .include /etc/pulse/default.pa and then just override the defaults.
  • Run pacmd list-sinks | grep -Ei 'index:|name:' to list available sinks. The present default sink is marked with an asterisk.
  • Edit ~/.config/pulse/default.pa to insert/alter the set-default-sink command using the sink's name as the numbering cannot be guaranteed repeatable.

client.conf[編輯 | 編輯原始碼]

This is the configuration file read by every PulseAudio client application. It is used to configure runtime options for individual clients. It can be used to set and configure the default sink and source statically as well as allowing (or disallowing) clients to automatically start the server if not currently running. If autospawn is enabled, clients will automatically start PulseAudio if it is not already running when a client attempts to connect to it. This can be useful if you do not want PulseAudio to always be running to conserve system resources. Otherwise, you really should have it start with your X11 session.

配置命令[編輯 | 編輯原始碼]

The main command to configure a server during runtime is pacmd. Run pacmd --help for a list options, or just run pacmd to enter the shell interactive mode and Ctrl+d to exit. All modifications will immediately be applied.

Once your new settings have been tested and meet your needs, edit the default.pa accordingly to make the change persistent. See PulseAudio/Examples for some basic settings.

提示:Leave the load-module module-default-device-restore line in the default.pa file untouched. It will allow you to restart the server in its default state, thus dismissing any wrong setting.

It is important to understand that the "sources" (processes, capture devices) and "sinks" (sound cards, servers, other processes) accessible and selectable through PulseAudio depend upon the current hardware "Profile" selected. These "Profiles" are those ALSA "pcms" listed by the command aplay -L, and more specifically by the command pacmd list-cards, which will include a line "index:", a list beginning "profiles:", and a line "active profile: <...>" in the output, among other things. "Profiles" correspond to different card input/output configurations, notably the number of available input/output channels.

The "active profile" can be set with the command pacmd set-card-profile INDEX PROFILE, with no comma separating INDEX and PROFILE, where INDEX is just the number on the line "index:" and a PROFILE name is everything shown from the beginning of any line under "profile:" to just before the colon and first space, as shown by the command pacmd list-cards. For instance, pacmd set-card-profile 0 output:analog-stereo+input:analog-stereo.

It may be easier to select a "Profile" with a graphical tool like pavucontrol, under the "Configuration" tab, or KDE System Settings, "Multimedia/Audio and Video Settings", under the "Audio Hardware Setup" tab. Each audio "Card", which are those devices listed by the command aplay -l, or again by the command pacmd list-cards, will have its own selectable "Profile". When a "Profile" has been selected, the then available "sources" and "sinks" can be seen by using the commands pacmd list-sources and pacmd list-sinks. Note that the "index" of the available sources and sinks will change each time a card profile is changed.

The selected "Profile" can be an issue for some applications, especially the Adobe Flash players, typically /usr/lib/mozilla/plugins/libflashplayer.so and /usr/lib/PepperFlash/libpepflashplayer.so. Often, these Flash players will only work when one of the Stereo profiles is selected, and otherwise, will play video with no sound, or will simply "crash". When all else fails, you might try selecting a different profile.

Of course, when configuring some variation of Surround Sound in PulseAudio, the appropriate Surround profile will have to be selected, before Surround Sound will work, or in order to do things like remap the speaker channels.

連接和認證[編輯 | 編輯原始碼]

Since PulseAudio runs as a daemon as the current user, clients needs to know where to find the daemon socket to connect to it as well as a shared random cookie file clients use to authenticate with it. By default, clients should be able to locate the daemon without problem using environment variables, X11 root window properties and finally by trying the default location (unix:/run/user/$ID/pulse/native). However, if you have clients that needs to access PulseAudio outside of your X11 session like mpd running as a different user, you will need to tell it how to connect to your PulseAudio instance. See PulseAudio/Examples#Allowing multiple users to share a PulseAudio daemon for a complete example. An authentication cookie containing random bytes is enabled by default to ensure audio does not leak from one user to another on a multi-user system. If you already control who can access the server using user/group permissions, you can disable the cookie by passing auth-cookie-enabled=0 to module-native-protocol-unix.

環境變量[編輯 | 編輯原始碼]

These two variables are the important ones in order for libpulse clients to locate PulseAudio if you moved its socket to somewhere else. See pulseaudio(1) for more details and other useful environment variables clients will read.

Variable Definition
PULSE_SERVER Defines where the server is. It takes a protocol prefix like unix: or tcp followed by the path or IP of the server. Example: unix:/home/pulse/native-sock.
PULSE_COOKIE Point this to the location of a file that contains the random cookie generated by PulseAudio. This file will be read by clients and its content sent to the server, thus the file has to be readable by all audio clients. It does not need to be the same file, as long as its content matches the one the daemon uses.

X11 屬性[編輯 | 編輯原始碼]

PulseAudio also uses window properties on the root window of the X11 server to help find the daemon. Since environment variables cannot be modified after child processes are started, X11 properties are more flexible because they are more easily changed because they are globally shared. As long as applications receive a DISPLAY= environment variable, it can read the most up-to-date values. X11 properties can be queried using xprop -root, or with pax11publish -d to read pulse-specific properties. pax11publish can also be used to update the properties from environment variables (pax11publish -e, or pax11publish -r to remove them entirely). If possible, it is recommended to let PulseAudio do it by itself using the module-x11-publish module or the start-pulseaudio-x11 command. The following table is there only for completeness, you should not ever need to manually set these variables by hand.

Variable Definition
PULSE_SERVER String value (xprop -root -f PULSE_SERVER 8s -set PULSE_SERVER "unix:/tmp/pulse-sock"), works the same as the environment variable of the same name.
PULSE_COOKIE String value that contains the hexadecimal representation of the authentication cookie.

運行[編輯 | 編輯原始碼]

PulseAudio on Arch has pulseaudio.socket enabled by default for the systemd/用戶 instance. This means that PulseAudio will automatically start when needed.

注意:
  • To disable pulseaudio.socket, make sure that $XDG_CONFIG_HOME/systemd/user/ exists and mask the pulseaudio.socket user unit.
  • Many desktop environments support XDG Autostart. In those desktop environments, PulseAudio will be launched automatically regardless of the socket activation status.

For more information, see PulseAudio: Running.

停用[編輯 | 編輯原始碼]

Stop the pulseaudio.socket and pulseaudio.service user units.

後端配置[編輯 | 編輯原始碼]

ALSA[編輯 | 編輯原始碼]

警告: Do not attempt to change the ALSA configuration files while using the default PulseAudio configuration. The default configuration grabs the hardware devices directly in order to allow all the on-the-fly configurations using the GUIs. Changes to the ALSA configurations will very likely be ignored by PulseAudio and ALSA applications will break randomly while trying to access an ALSA device already used by PulseAudio. If you intend to change the ALSA configurations, also configure PulseAudio manually to output to your own ALSA device and play nice with your configuration.

If you have applications that do not support PulseAudio explicitly but rely on ALSA, these applications will try to access the sound card directly via ALSA and will therefore bypass PulseAudio. PulseAudio will thus not have access to the sound card any more. As a result, all applications relying on PulseAudio will not be working any more, leading to this issue. To prevent this, you will need to install the pulseaudio-alsa package. It contains the necessary /etc/alsa/conf.d/99-pulseaudio-default.conf for configuring ALSA to use PulseAudio. Also make sure that ~/.asoundrc does not exist, as it would override the /etc/asound.conf file.

Also install lib32-libpulse and lib32-alsa-plugins if you run a x86_64 system and want to have sound for 32-bit multilib programs like Wine and Steam.

To prevent applications from using ALSA's OSS emulation and bypassing PulseAudio (thereby preventing other applications from playing sound), make sure the module snd_pcm_oss is not being loaded at boot. If it is currently loaded (lsmod | grep oss), disable it by executing:

# rmmod snd_pcm_oss

通過 ALSA 啟用 DTS[編輯 | 編輯原始碼]

To enable PulseAudio DTS (Digital Theater System) via ALSA install dcaencAUR package and enable it:

/etc/asound.conf
<confdir:pcm/dca.conf>

Finally restart PulseAudio. If experience volume issues with your DTS device and/or PulseAudio, you may fix it by looking for more setting option at dcaenc's Github.

將 PulseAudio sources, sinks and mixers 暴露於 ALSA[編輯 | 編輯原始碼]

Although pulseaudio-alsa contains the necessary configuration file to allow ALSA applications to use PulseAudio's default device, ALSA's pulse plugin is more versatile than that:

~/.asoundrc (or /etc/asound.conf)
# Create an alsa input/output using specific PulseAudio sources/sinks
pcm.pulse-example1 {
    type pulse
    device "my-combined-sink" # name of a source or sink
    fallback "pulse-example2" # if combined not available
}

pcm.pulse-example2 {
    type pulse
    device "other-sound-card" # name of a source or sink
    # example: device "alsa_output.pci-0000_00_1b.0.analog-stereo"
}

# Create an alsa mixer using specific PulseAudio sources/sinks
# these can be tested with "alsamixer -D pulse-example3"
ctl.pulse-example3 {
    type pulse
    device "my-output" # name of source or sink to control

    # example: always control the laptop speakers:
    # device "alsa_output.pci-0000_00_1b.0.analog-stereo"
    fallback "pulse-example4" # supports fallback too
}

# Mixers also can control a specific source and sink, separately:
ctl.pulse-example4 {
    type pulse
    sink "my-usb-headphones"
    source "my-internal-mic"
    
    # example: output to HDMI, record using internal
    sink "alsa_output.pci-0000_01_00.1.hdmi-stereo-extra1"
    source "alsa_input.pci-0000_00_1b.0.analog-stereo"
}

# These can override the default mixer (example: for pnmixer integration)
ctl.!default {
    type pulse
    sink "alsa_output.pci-0000_01_00.1.hdmi-stereo-extra1"
    source "alsa_input.pci-0000_00_1b.0.analog-stereo"
}

The source code can be read to know all available options.

ALSA/dmix 無需獲取硬體設備[編輯 | 編輯原始碼]

注意: This section describes alternative configuration, which is generally not recommended.

You may want to use ALSA directly in most of your applications while still being able to use applications which require PulseAudio at the same time. The following steps allow you to make PulseAudio use dmix instead of grabbing ALSA hardware device.

  • Remove package pulseaudio-alsa, which provides compatibility layer between ALSA applications and PulseAudio. After this your ALSA applications will use ALSA directly without being hooked by Pulse.
  • Create a configuration file in /etc/pulse/default.pa.d/ to unload the autodetection modules and load back-end drivers statically. Add device parameters as follows:
/etc/pulse/default.pa.d/load-audio-drivers-statically.pa
unload-module module-udev-detect
unload-module module-detect
load-module module-alsa-sink device=dmix
load-module module-alsa-source device=dsnoop
  • Optional: If you use kmix you may want to control ALSA volume instead of PulseAudio volume: set KMIX_PULSEAUDIO_DISABLE=1 as an environment variable.
  • Now, reboot your computer and try running ALSA and PulseAudio applications at the same time. They both should produce sound simultaneously.
Use pavucontrol to control PulseAudio volume if needed.

OSS[編輯 | 編輯原始碼]

There are multiple ways of making OSS-only programs output to PulseAudio:

ossp[編輯 | 編輯原始碼]

Install ossp package and start osspd.service.

padsp wrapper[編輯 | 編輯原始碼]

使用OSS的程序可以通過使用padsp(包含在PulseAudio中)來與PulseAudio一起使用:

$ padsp OSSprogram

舉幾個例子:

$ padsp aumix
$ padsp sox foo.wav -t ossdsp /dev/dsp

您還可以添加自定義包裝器腳本,如下所示:

/usr/local/bin/OSSProgram
#!/bin/sh
exec padsp /usr/bin/OSSprogram "$@"

Make sure /usr/local/bin comes before /usr/bin in your PATH.

注意: This does not work when the module-udev-detect has the option tsched=0.

GStreamer[編輯 | 編輯原始碼]

Install gst-plugins-good, or gstreamer0.10-good-pluginsAUR if your intended program has a legacy GStreamer implementation.

OpenAL[編輯 | 編輯原始碼]

OpenAL Soft 應默認使用 PulseAudio,但可以顯式配置為這樣做:

/etc/openal/alsoft.conf
drivers=pulse,alsa

默認情況下,OpenAL 不允許 pulseaudio 將音頻流移動到其他設備。要更改此設置,請添加允許移動選項:

/etc/openal/alsoft.conf
[pulse]
allow-moves=true

libao[編輯 | 編輯原始碼]

編輯 libao 配置文件:

/etc/libao.conf
default_driver=pulse

請務必刪除 alsa 驅動程序的 dev=default 選項或調整它以指定特定的 Pulse sink 名稱或編號。

注意: You could possibly also keep the libao standard of outputting to the alsa driver and its default device if you install pulseaudio-alsa since the ALSA default device then is PulseAudio.

Audio 後期處理[編輯 | 編輯原始碼]

PulseEffects[編輯 | 編輯原始碼]

PulseEffects is a GTK advanced utility for applying several audio effects (e.g. Noise reduction, Equalizer etc.) to audio input and output.

注意: PulseEffects new version (EasyEffects) only supports Pipewire. You need to install the legacy version (pulseeffects-legacyAUR or pulseeffects-legacy-gitAUR) to use it with PulseAudio.

You may need to also install its optional dependency lsp-plugins in order to get plugins to work. If PulseEffects plugins are greyed out after installing plugins, trying to start the daemon produces an error, or no devices are shown in the Settings > PulseAudio tab, consider clearing the cache as shown in [3].

A collection of PulseEffects presets can be found in community presets.

均衡[編輯 | 編輯原始碼]

If you want to use a different equalizer rather that the one integrated in #PulseEffects, there are the following options.

LADSPA 模塊[編輯 | 編輯原始碼]

Install pulseaudio-equalizer-ladspa, an equalizer based on LADSPA swh-plugins. Launch pulseaudio-equalizer-gtk GUI and tweak the parameters to match your expectations.

集成模塊[編輯 | 編輯原始碼]

PulseAudio has an integrated 10-band equalizer system. In order to use it, install pulseaudio-equalizer and read the following instructions.

警告: PulseAudio equalizer module is considered unstable and might be removed from PulseAudio.

Load the equalizer sink and dbus-protocol module

$ pactl load-module module-equalizer-sink
$ pactl load-module module-dbus-protocol

To start the GUI, run qpaeq.

注意: If qpaeq has no effect, install pavucontrol and change "ALSA Playback on" to "FFT based equalizer on ..." while the media player is running.

To load the equalizer and dbus module on every boot, create a .pa file in /etc/pulse/default.pa.d/ or edit ~/.config/pulse/default.pa and add the following lines:

### Load the integrated PulseAudio equalizer and D-Bus module
load-module module-equalizer-sink
load-module module-dbus-protocol
注意: The equalizer sink needs to be loaded after the master sink is already available.

動態範圍壓縮[編輯 | 編輯原始碼]

Dynamic range compression can be done with #PulseEffects. Anyway PulseEffects might introduce much overhead and latency to audio stream, so if you only need a compression effect and a minor load on the system, other options are available using a module-ladspa-sink.

Steve Harris 插件[編輯 | 編輯原始碼]

Steve Harris LADSPA is a set of plugins containing various compression modules. Install swh-plugins and edit the configuration as the following

~/.config/pulse/default.pa
.include /etc/pulse/default.pa

set-default-sink your_card_sink_name

load-module module-ladspa-sink sink_name=shw_sc4 sink_master=your_card_sink_name plugin=sc4_1882 label=sc4 control=,,,,,,,,
set-default-sink shw_sc4

You have to specify your card sink name, get it from pacmd list-sinks. In order to apply the changes, stop and restart Pulseaudio. The above configuration has empty control options using the default values.

To tweak the module with custom control parameters, fill them respecting the right order.

Control option Description
RMS/peak (0/1) The blanace between the RMS and peak envelope followers. RMS is generally better for subtle, musical compression and peak is better for heavier, fast compression and percussion.
Attack time (ms) The attack time in milliseconds.
Release time (ms) The release time in milliseconds.
Threshold level (dB) The point at which the compressor will start to kick in.
Ratio (1:n) The gain reduction ratio used when the signal level exceeds the threshold. 1 means no compression; higher values stronger compression.
Knee radius (dB) The distance from the threshold where the knee curve starts.
Makeup gain (dB) Controls the gain of the makeup input signal in decibels.
Amplitude (dB) The level of the input signal, in decibels.
Gain reduction (dB) The degree of gain reduction applied to the input signal, in decibels.

Other plugins can be found in Steve Harris' LADSPA Plugin Documentation.

Calf 插件[編輯 | 編輯原始碼]

For a more professional compressor, you can use the one developed by Calf Studio Gear. Install calf-ladspaAUR and edit the configuration as the following

~/.config/pulse/default.pa
.include /etc/pulse/default.pa

set-default-sink your_card_sink_name

load-module module-ladspa-sink sink_name=calf_comp_x2 sink_master=your_card_sink_name plugin=veal label=Compressor control=,,,,,,,,,,
set-default-sink calf_comp_x2

The plugin has 11 control options. If you want to insert custom values, read the following table and do not forget to specify them in the right order.

Control option Default Min Max Type Info
Bypass 0 0 1 Bool
Level in 1 0.015625 64 Float db
Threshold 0.125 0.000976563 1 Float dbFs For example, to set -18 db, the right value is 10^(-18/20) = 0.158
Ratio 2 1 20 Float
Attack 20 0.01 2000 Float ms
Release 250 0.01 2000 Float ms
Makeup 1 1 64 Float db
Knee 2.828427125 1 8 Float db
RMS/Peak 0 0 1 Bool 0 = RMS; 1 = Peak
Stereo Link 0 0 1 Bool 0 = Average; 1 = Max
Mix 1 0 1 Float Percentage
To understand the meaning of every single option, read the Calf Compressor Documentation.

麥克風回聲/噪音消除[編輯 | 編輯原始碼]

Arch 默認不會加載 PulseAudio 的回聲消除模塊,因此,我們需要在/etc/pulse/default.pa.d/中添加它。首先,你可以使用 pacmd 並輸入list-modules。如果你無法找到 name: <module-echo-cancel>,你就需要創建一個。

/etc/pulse/default.pa.d/noise-cancellation.pa
### 啟用回聲消除
load-module module-echo-cancel use_master_format=1 aec_method=webrtc aec_args="analog_gain_control=0\ digital_gain_control=1" source_name=echoCancel_source sink_name=echoCancel_sink
set-default-source echoCancel_source
set-default-sink echoCancel_sink

然後重啟 Pulseaudio

$ pulseaudio -k
$ pulseaudio --start

然後可以使用 pavucontrol 來查看模塊是否被啟用了。在 輸入設備 一欄下,應該已經出現了一個 Echo-Cancel Source Stream from

Turning on beamforming=1 in the aec_args can also significantly reduce background noise if you have more than one microphone (which is common on many new laptops). However, beamforming requires specifying your mic_geometry (see below).

If you want existing streams to be automatically moved to the new sink and source, you have to load the module-switch-on-connect with ignore_virtual=no before.

注意: If you plug in a USB sound card or headset, or you have for example a 5.1 Speaker configuration and plug in a headset on your front audio connectors after you have loaded the module-echo-cancel, you have to manually unload and load the module-echo-cancel again, because unfortunately there is no way to tell the module that it should automatically switch to the new default 'source_master' and 'source_sink'. See [4].

Possible 'aec_args' for 'aec_method=webrtc'[編輯 | 編輯原始碼]

Here is a list of possible 'aec_args' for 'aec_method=webrtc' with their default values [5][6]:

  • analog_gain_control=1 - Analog AGC - 'Automatic Gain Control' done over changing the volume directly - Will most likely lead to distortions.
  • digital_gain_control=0 - Digital AGC - 'Automatic Gain Control' done in post processing (higher CPU load).
  • experimental_agc=0 - Allow enabling of the webrtc experimental AGC mechanism.
  • agc_start_volume=85 - Initial volume when using AGC - Possible values 0-255 - A too low initial volume may prevent the AGC algorithm from ever raising the volume high enough [7].
  • high_pass_filter=1 - ?
  • noise_suppression=1 - Noise suppression.
  • voice_detection=1 - VAD - Voice activity detection.
  • extended_filter=0 - The extended filter is more complex and less sensitive to incorrect delay reporting from the hardware than the regular filter. The extended filter mode is disabled by default, because it seemed produce worse results during double-talk [8]. Enable this option if your microphone or speaker has a larger latency, for example, if you use a wireless microphone or some HDMI TVs as speaker.
  • intelligibility_enhancer=0 - Some bits for webrtc intelligibility enhancer.
  • drift_compensation=0 - Drift compensation to allow echo cancellation between different devices (such as speakers on your laptop and the microphone on your USB webcam). - only possible with "mobile=0".
  • beamforming=0 - This can significantly reduce background noise. See [9][10]
    • mic_geometry=x1,y1,z1,x2,y2,z2 - Only with "beamforming=1".
    • target_direction=a,e,r - Only with "beamforming=1". Note: If the module does not want to load with this argument, set azimuth (a) to the desired value, but set elevation (e) and radius (r) to 0.
  • mobile=0 - ?
    • routing_mode=speakerphone - Possible Values "quiet-earpiece-or-headset,earpiece,loud-earpiece,speakerphone,loud-speakerphone" - only valid with "mobile=1".
    • comfort_noise=1 - ? - only valid with "mobile=1".

在某些應用程式中禁用音頻後處理[編輯 | 編輯原始碼]

If you are using the module-echo-cancel[損壞的連結:無效的章節], you probably do not want other applications to do additional audio post processing. Here is a list for disabling audio post processing in following applications:

  • Mumble:
    1. Configure -> Settings -> Check 'Advanced' check box -> Audio Input
    2. Echo: Select 'Disabled'
    3. Noise Suppression: Set slider to 'Off'
    4. Max. Aplification: Set slider to '1.0'
  • TeamSpeak:
    1. Tools -> Options -> Capture
    2. Uncheck: 'Typing attenuation', 'Remove background noise', 'Echo cancellation' and 'Echo reduction (Ducking)'
  • Firefox: see Firefox tweaks#Disable WebRTC audio post processing
  • Steam:
    1. In window "Friends List" -> Manage friends list settings (gear symbol) -> VOICE -> Show Advanced Settings
    2. Set the following sliders to "OFF": "Echo cancellation", "Noise cancellation", "Automatic volume/gain control"
  • Skype:
    1. Tools -> Settings... -> Audio & Video -> Microphone -> Automatically adjust microphone settings -> off

用於重新加載回聲消除模塊的腳本[編輯 | 編輯原始碼]

Since the module-echo-cancel is not always needed, or must be reloaded if the source_master or sink_master has changed, it is nice to have a easy way to load or reload the module-echo-cancel.

Create the following script and make it executable:

echoCancelEnable.sh
#!/bin/sh
aecArgs="$*"
# If no "aec_args" are passed on to the script, use this "aec_args" as default:
[ -z "$aecArgs" ] && aecArgs="analog_gain_control=0 digital_gain_control=1"
newSourceName="echoCancelSource"
newSinkName="echoCancelSink"

# "module-switch-on-connect" with "ignore_virtual=no" (needs PulseAudio 12 or higher) is needed to automatically move existing streams to a new (virtual) default source and sink.
if ! pactl list modules short | grep "module-switch-on-connect.*ignore_virtual=no" >/dev/null 2>&1; then
	echo Load module \"module-switch-on-connect\" with \"ignore_virtual=no\"
	pactl unload-module module-switch-on-connect 2>/dev/null
	pactl load-module module-switch-on-connect ignore_virtual=no
fi

# Reload "module-echo-cancel"
echo Reload \"module-echo-cancel\" with \"aec_args=$aecArgs\"
pactl unload-module module-echo-cancel 2>/dev/null
if pactl load-module module-echo-cancel use_master_format=1 aec_method=webrtc aec_args=\"$aecArgs\" source_name=$newSourceName sink_name=$newSinkName; then
	# Set a new default source and sink, if module-echo-cancel has loaded successfully.
	pacmd set-default-source $newSourceName
	pacmd set-default-sink $newSinkName
fi

To run the script easily from the graphical environment, you can create a desktop launcher for it.

遞歸神經網絡噪聲抑制 (RNNoise)[編輯 | 編輯原始碼]

Installing the package noise-suppression-for-voice will allow real-time noise suppression based on RNNoise: Learning Noise Suppression [11]. Configuration details can be found on the projects Github site [12]. One can install Cadmus (cadmus-debAUR or cadmus-appimageAUR) which is a GUI frontend for @werman's Pulse Audio real-time noise suppression plugin.

Another alternative is noisetorchAUR which is also build on top of RNNoise. There is not only input noise cancellation but also an output.

應用[編輯 | 編輯原始碼]

QEMU[編輯 | 編輯原始碼]

Refer to QEMU#Host[損壞的連結:無效的章節] for a detailed guide on how to configure pulseaudio within QEMU.

AlsaMixer.app[編輯 | 編輯原始碼]

Make alsamixer.appAUR dockapp for the windowmakerAUR use pulseaudio, e.g.:

$ AlsaMixer.app --device pulse

Here is a two examples where the first one is for ALSA and the other one is for pulseaudio. You can run multiple instances of it. Use the -w option to choose which of the control buttons to bind to the mouse wheel.

# AlsaMixer.app -3 Mic -1 Master -2 PCM --card 0 -w 1
# AlsaMixer.app --device pulse -1 Capture -2 Master -w 2
注意: It can use only those output sinks that set as default.

XMMS2[編輯 | 編輯原始碼]

Make it switch to pulseaudio output:

$ nyxmms2 server config output.plugin pulse

and to alsa:

$ nyxmms2 server config output.plugin alsa

To make xmms2 use a different output sink, e.g.:

$ nyxmms2 server config pulse.sink alsa_output.pci-0000_04_01.0.analog-stereo.monitor

See also the official guide [13].

KDE Plasma Workspaces and Qt4[編輯 | 編輯原始碼]

PulseAudio will automatically be used by KDE/Qt4 applications. It is supported by default in the KDE sound mixer. For more information see the KDE page in the PulseAudio wiki.

One useful tidbit from that page is that load-module module-device-manager should be loaded. This usually happens automatically at login through the script /usr/bin/start-pulseaudio-x11; if you find that the module is not loaded automatically you can consider adding it manually to a configuration file in /etc/pulse/default.pa.d/. See #Switch on connect for possible conflicts with the module-switch-on-connect.

If the phonon-gstreamer backend is used for Phonon, GStreamer should also be configured as described in #GStreamer.

Audacious[編輯 | 編輯原始碼]

In order to use PulseAudio, set Edit → Preferences… → Devices → Playback → Device in Audacious to 「default」 or 「pulse」. These devices are added to the drop-down list by pulseaudio-alsa.

Music Player Daemon (MPD)[編輯 | 編輯原始碼]

Configure MPD to use PulseAudio. See also MPD/Tips and Tricks#PulseAudio.

MPlayer[編輯 | 編輯原始碼]

MPlayer natively supports PulseAudio output with the -ao pulse option. It can also be configured to default to PulseAudio output, in ~/.mplayer/config for per-user, or /etc/mplayer/mplayer.conf for system-wide:

/etc/mplayer/mplayer.conf
ao=pulse

mpv[編輯 | 編輯原始碼]

mpv supports PulseAudio same as written for #MPlayer. Configuration in ~/.config/mpv/mpv.conf per-user, or /etc/mpv/mpv.conf system-wide.

guvcview[編輯 | 編輯原始碼]

guvcview when using the PulseAudio input from a Webcam may have the audio input suspended resulting in no audio being recorded. You can check this by executing:

$ pactl list sources

If the audio source is "suspended" then create the folowing .pa file:

/etc/pulse/default.pa.d/no-module-suspend-on-idle.pa

And then either restarting PulseAudio or your computer will only idle the input source instead of suspending it. guvcview will then correctly record audio from the device.

網絡 audio[編輯 | 編輯原始碼]

本文或本章節可能需要合併到PulseAudio/Examples#PulseAudio over network

附註: No need for two separate sections.(在 Talk:PulseAudio 中討論)

One of PulseAudio's unique features is its ability to stream audio from clients over TCP to a server running the PulseAudio daemon reliably within a LAN. Ensure that client and server systems agree on the time (i.e., use NTP), or audio streams may be choppy or may not work at all. For a more detailed guide visit the Official PulseAudio Documentation

Enable the TCP module on the server(the computer that actually outputs sound), create the folowing .pa file:

/etc/pulse/default.pa.d/tcp.pa
load-module module-native-protocol-tcp

Or you can use the paprefs gui application (root is not required). Go to Network Server > Enable network access to local sound devices.

To make sure module-native-protocol-tcp is loaded on the server, you can use:

$ pacmd list-modules | grep module-native-protocol-tcp

It is a requirement that both the client and server share the same cookie. Ensure that the clients and server share the same cookie file found under ~/.config/pulse/cookie. It does not matter whose cookie file you use (the server or a client's), just that the server and client(s) share the same one.

If it is undesirable to copy the cookie file from clients, anonymous clients can access the server by passing auth-anonymous to module-native-protocol-tcp on the server (again in /etc/pulse/default.pa.d/):

load-module module-native-protocol-tcp auth-anonymous=1

It is also possible to authenticate based on client IP address:

load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1;192.168.0.0/24

Change the LAN IP subnet to match that of those clients you wish to have access to the server.

Starting system-wide on boot[編輯 | 編輯原始碼]

The PulseAudio daemon normally starts as a user service when a user logs in and attempts to play some sort of audio. For running a dedicated PulseAudio server accepting client connections over TCP, the daemon must be started on boot as a system service. Note that in most desktop use cases, system mode likely is not the right choice.

To run PulseAudio in a system mode, first we need to set up users and groups needed by system-wide PulseAudio server instance [14]:

  1. Add user pulse. PulseAudio daemon switches to this user after starting.
    # useradd -d /var/run/pulse -s /usr/bin/nologin -G audio pulse
  2. Optionally add user pulse to the bluetooth group, if you have it (bluez) and want PulseAudio to use bluetooth.
    # usermod -aG bluetooth pulse
  3. Add group pulse-access. This group is used by PulseAudio server for access control.
    # groupadd pulse-access
  4. Add users to pulse-access group, if you want them to have access to the system-wide PulseAudio instance.
    # usermod -aG pulse-access root

Create the service pulseaudio.service in /etc/systemd/system containing the following:

本文或本章節的事實準確性存在爭議。

原因: The service runs as root, not as the pulse user.(在 Talk:PulseAudio 中討論)


/etc/systemd/system/pulseaudio.service
[Unit]
Description=Sound Service
 
[Service]
# Note that notify will only work if --daemonize=no
Type=notify
ExecStart=/usr/bin/pulseaudio --daemonize=no --exit-idle-time=-1 --disallow-exit=true --system --disallow-module-loading
Restart=always
 
[Install]
WantedBy=default.target

Then enable pulseaudio.service at the system level. You will also need to disable the user-level PulseAudio service across the whole system:

# systemctl --global mask pulseaudio.socket

This is necessary even if you are accessing the system over SSH, to make sure the user-level PulseAudio service will never start.

選擇伺服器[編輯 | 編輯原始碼]

For a single shell or command you can set the environment variable $PULSE_SERVER to the host name or IP address of the desired PulseAudio server.

$ env PULSE_SERVER=server-hostname-or-ip mplayer test.mp3

Alternatively you can create or modify ~/.pulse/client.conf or /etc/pulse/client.conf to set a default-server persistently.

default-server = server-hostname-or-ip

It is also possible to specify multiple servers separated by spaces which are subsequently tried by PulseAudio[15]:

default-server = server1 backup

提示和技巧[編輯 | 編輯原始碼]

本文或本章節可能需要合併到PulseAudio/Examples

附註: Same topic.(在 Talk:PulseAudio 中討論)

鍵盤音量控制[編輯 | 編輯原始碼]

See Keyboard shortcuts#Xorg to bind the following commands to your volume keys: XF86AudioRaiseVolume, XF86AudioLowerVolume and XF86AudioMute.

First find out which sink corresponds to the audio output you would like to control. To list available sinks:

$ pactl list sinks short

Suppose sink 0 is to be used, to raise the volume:

$ sh -c "pactl set-sink-mute 0 false ; pactl set-sink-volume 0 +5%"

To lower the volume:

$ sh -c "pactl set-sink-mute 0 false ; pactl set-sink-volume 0 -5%"

To mute/unmute the volume:

$ pactl set-sink-mute 0 toggle

To mute/unmute the microphone:

$ pactl set-source-mute 1 toggle
提示:
  • To have keyboard shortcuts operate always on the default sink, specify @DEFAULT_SINK@ as the sink number, for example pactl set-sink-mute @DEFAULT_SINK@ toggle.
  • For more advanced control, such as limiting the maximum volume, consider using one of the console front-ends[損壞的連結:無效的章節].

從非交互式 shell 播放音頻 (systemd service, cron)[編輯 | 編輯原始碼]

Set XDG_RUNTIME_DIR before the command (replace user_id with the ID of the user running PulseAudio):

$ XDG_RUNTIME_DIR=/run/user/user_id paplay /usr/share/sounds/freedesktop/stereo/complete.oga

Or use machinectl:

# machinectl shell .host --uid=user_id /usr/bin/paplay /usr/share/sounds/freedesktop/stereo/complete.oga

X11 Bell 事件[編輯 | 編輯原始碼]

To get pulseaudio to handle X11 bell events, run the following commands after the X11 session has been started:

$ pactl upload-sample /usr/share/sounds/freedesktop/stereo/bell.oga bell-window-system
$ pactl load-module module-x11-bell display=$DISPLAY

Or use configuration files /etc/pulse/default.pa.d/ or ~/.config/pulse/default.pa:

~/.config/pulse/default.pa
.include /etc/pulse/default.pa

# audible bell
load-sample-lazy bell-window-system /usr/share/sounds/freedesktop/stereo/bell.oga
load-module module-x11-bell

To adjust the volume of the X11 bell, run the following command:

$ xset b 100

100 is a percentage. This requires the xorg-xset package. See Autostarting for a way to run these commands automatically when the X11 session is started.

Switch on connect[編輯 | 編輯原始碼]

This is a default enabled module used to switch the output sound to the newly connected device. For example, if you plug in a USB headset, the output will be switched to that. If you unplug it, the output will be set back to the last device. This used to be quite buggy but got a lot of attention in PulseAudio 8.0 and should work quite well now.

用於切換模擬輸出的腳本[編輯 | 編輯原始碼]

Some sound cards present the option of multiple analog outputs, being switchable through using Pulseaudio profiles. But switching manually can become a chore, so you can use the following commands to switch it:

$ pactl set-sink-port 'number of the card' 'port'

This will set the default output to whatever port you chose. Example:

$ pactl set-sink-port 0 "analog-output;output-speaker" 

The values can be easily obtained using:

$ pactl list

Current output can be obtained through:

$ pactl list sinks | grep "active profile"| cut -d ' ' -f 3-

This process can be automated through a simple script. This script then can be given a shortcut by the user:

~/pa.sh (or anything the user wants)
#!/bin/sh
# This script uses kdialog notification to warn the user of the currently swapped to profile. User could adapt it to their needs or change it.

CURRENT_PROFILE=$(pactl list sinks | grep "active profile"| cut -d ' ' -f 3-)

if [ "$CURRENT_PROFILE" = "analog-output;output-speaker" ] ; then
        pactl set-sink-port 0 "analog-output;output-headphones-1"
        kdialog --title "Pulseaudio" --passivepopup "Headphone" 2 & 
else 
        pactl set-sink-port 0 "analog-output;output-speaker"      
        kdialog --title "Pulseaudio" --passivepopup  "Speaker" 2 &
fi

This script is intended to swap between two profiles. First checking the current profile then swapping it. Users are required to change the field 'active profile' according to the language pactl reports. Users might need to change the number of the card and the output to fit their machine.

禁止媒體進入語音呼叫時靜音 (module-role-cork)[編輯 | 編輯原始碼]

When entering a voice call (e.g. in Microsoft Teams, maybe others too) any media applications might be muted. To disable this behaviour you can simply disable this module in PulseAudio configuration:

/etc/pulse/default.pa.d/no-cork.pa
unload-module module-role-cork

高級配置和使用案例[編輯 | 編輯原始碼]

See PulseAudio/Examples.

疑難解答[編輯 | 編輯原始碼]

See PulseAudio/Troubleshooting.

參考文件[編輯 | 編輯原始碼]