「PulseAudio/サンプル」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
389行目: 389行目:
 
=== フロント/リアの分割 ===
 
=== フロント/リアの分割 ===
   
  +
スピーカーを前面のアナログ出力に、ヘッドフォンを背面の出力に接続します。フロント/リアを分割して sink を分離すると便利です。{{ic|/etc/pulse/default.pa}} に追加:
Connect speakers to front analog output and headphones to rear output. It would be useful to split front/rear to separate sinks. Add to {{ic|/etc/pulse/default.pa}}:
 
   
 
load-module module-remap-sink sink_name=speakers sink_properties="device.description='Speakers'" remix=no master=alsa_output.pci-0000_05_00.0.analog-surround-40 channels=2 master_channel_map=front-left,front-right channel_map=front-left,front-right
 
load-module module-remap-sink sink_name=speakers sink_properties="device.description='Speakers'" remix=no master=alsa_output.pci-0000_05_00.0.analog-surround-40 channels=2 master_channel_map=front-left,front-right channel_map=front-left,front-right
395行目: 395行目:
 
alsa_output.pci-0000_05_00.0.analog-surround-40 は 'pacmd list-sinks' で表示されるサウンドカードの名前に置き換えてください。
 
alsa_output.pci-0000_05_00.0.analog-surround-40 は 'pacmd list-sinks' で表示されるサウンドカードの名前に置き換えてください。
   
  +
これで、別々に使用できる sink が 2 つ追加されました。'sink_name' は、その名前の sink が存在しない限り、自由に選択できます。''remix'' パラメーターは、sink 内のチャンネルと一致するようにオーディオをダウン/アップミックスするかどうかを制御します。
Now you have 2 additional sinks which can be used separately. You can choose 'sink_name' freely, as long as there is no sink with that name already. The 'remix' parameter controls whether the audio should be down-/upmixed to match the channels in the sink.
 
   
{{Tip|pulseaudio が {{ic|master sink not found}} と表示する場合、リマップの行をコメントアウトしてから、PulseAudio を起動してカードの出力が正しく設定されているか確認してください (例: アナログサラウンド 4.0)もしくは、sink 名の代わりに [[#デフォルトの出力ソースを設定|sink index]] を使ってみてください。}}
+
{{Tip|pulseaudio が {{ic|master sink not found}} と表示する場合、リマップの行をコメントアウトしてから、PulseAudio を起動してカードの出力が正しく設定されているか確認してください (例: アナログサラウンド 4.0) もしくは、sink 名の代わりに [[PulseAudio/サンプル#デフォルトの出力 sink プロファイルを設定する|sink index]] を使ってみてください。}}
   
 
===7.1 を 5.1+2.0 に分割===
 
===7.1 を 5.1+2.0 に分割===

2023年1月16日 (月) 17:59時点における版

関連記事

目次

ユーザー設定ファイルの作成

システム全体の設定ファイルは /etc/pulse の下にありますが、ユーザー設定ファイルは $XDG_CONFIG_HOME/pulse の下にあり、デフォルトは ~/.config/pulse です。ユーザーの設定ファイルを変更する以下の例では、最初にファイルを作成する必要がある場合があります。これは、/etc/pulse の下にあるシステム ファイルをユーザーの構成ディレクトリにコピーするか、構文 .include/etc/pulse/name システム全体のデフォルトが変更されたときにユーザーがファイルを更新する必要がないため、単純な変更の場合は後者が推奨されます。

ユーザークライアント設定ファイルの例

~/.config/pulse/client.conf
.include /etc/pulse/client.conf
# User's directives go here.

この構文は、default.padaemon.conf、および system.pa に対して機能しますが、後者がユーザー設定ファイルとして意味をなさない場合でも同様です。

ヒント: クリップボードからコピーした可能性のあるカード名などの文字列から末尾の空白を必ず削除してください。

Sink alsa_output.pci-0000_03_00.0.analog-stereo does not exist. こういうエラーは存在しません、このような空白を間接的に示す場合があります。

デフォルトの入力ソースを設定

利用可能な入力ソースの一覧を表示するには:

$ pacmd list-sources | grep -e 'index:' -e device.string -e 'name:'
  index: 0
    name: <input>
      device.string = "hw:2"
* index: 1
    name: <oss_input.dsp>
      device.string = "/dev/dsp"
  index: 2
    name: <alsa_output.pci-0000_04_01.0.analog-stereo.monitor>

インデックスの前の * は現在のデフォルト入力を示します。

システム全体のデフォルトとして設定するには、使用する入力ソースを /etc/pulse/default.pa に追加してください:

/etc/pulse/default.pa
...
set-default-source alsa_output.pci-0000_04_01.0.analog-stereo.monitor
...

一時的に使用するには:

$ pacmd "set-default-source alsa_output.pci-0000_04_01.0.analog-stereo.monitor"
ヒント: デフォルトのソースは、コマンド内で @DEFAULT_SOURCE@ として参照できます。たとえば: $ pactl set-source-mute @DEFAULT_SOURCE@ toggle

デフォルトの出力ソースを設定

index の前に * が付いている新しいソースの名前を確認:

$ pacmd list-sinks | grep -e 'name:' -e 'index:'
* index: 0
	name: <alsa_output.pci-0000_04_01.0.analog-stereo>
  index: 1
	name: <combined>

システム全体のデフォルトとして設定するには、以下を /etc/pulse/default.pa に追加してください:

/etc/pulse/default.pa
...
set-default-sink alsa_output.pci-0000_04_01.0.analog-stereo
...

設定したら変更を有効にするためにログアウト/ログインまたは PulseAudio を手動で再起動してください。

ノート:
  • デフォルトに設定されている sink には、インデックスの前に * 印が付きます。
  • sink の番号付けは永続的ではないため、default.pa ファイル内ではすべての sink を名前で識別する必要があります。
  • 実行時に素早く識別したい場合 (音量の制御など)、sink 名の代わりに sink index を使用することができます:
    $ pactl set-sink-volume 0 +3%
    $ pactl set-sink-volume 0 -3%
    $ pactl set-sink-mute 0 toggle
    
  • 通常の音量 (100%) を不必要に上書きしないようにするには、サウンドを管理するための別のユーティリティを使用する方がよいでしょう。詳細については フォーラムスレッド を参照してください。
ヒント: デフォルトの sink は @DEFAULT_SINK@ で指定することができます。たとえば: $ pactl set-sink-volume @DEFAULT_SINK@ +5%

デフォルトの出力 sink プロファイルを設定する

PulseAudio は、開始時に目的のプロファイルをロードしない場合があります (同じカード上の独立したアナログおよびデジタル出力 を持つためのプロファイルなど) デフォルトのプロファイルを変更するには、次を default.pa に追加します。

/etc/pulse/default.pa
...
set-card-profile <symbolic-name> <profilename>
ノート:

<symbolic-name> の代わりに <cardindex> を使用することもできますが、<symbolic-name> を使用すると、正しいデバイスを確実に参照できます。<cardindex> は動的で、新しいデバイスが接続されると変化します。

pacmd list-cards を実行して <symbolic-name> を見つけます。

$ pacmd list-cards
3 card(s) available.
    index: 0
	name: <alsa_card.pci-0000_01_00.1>
	driver: <module-alsa-card.c>
	owner module: 6
        (...)

    index: 1
	name: <alsa_card.usb-Sony_Interactive_Entertainment_Wireless_Controller-00>
	driver: <module-alsa-card.c>
	owner module: 7
        (...)
				
    index: 2
	name: <alsa_card.pci-0000_00_14.2>
	driver: <module-alsa-card.c>
	owner module: 8
	(...)

この場合、インデックス番号 2 のデバイスを使用したいので、<symbolic-name>alsa_card.pci-0000_00_14.2 にする必要があります。

<profilename> を見つけるには、目的のプロファイルを手動で設定してから pacmd list-cards :

$ pacmd list-cards | grep 'active profile'
        active profile: <off>
	active profile: <off>
	active profile: <output:analog-stereo+output:iec958-stereo+input:analog-stereo>

この場合、default.pa を次のように変更する必要があります。

/etc/pulse/default.pa
...
 set-card-profile alsa_card.pci-0000_00_14.2 output:analog-stereo+output:iec958-stereo+input:analog-stereo

pactl set-card-profile <symbolic-name> <profilename> を実行して、構成をテストできます。

同じカード上の独立したアナログおよびデジタル出力

サウンドカードには、アナログ出力とデジタル (iec958) 出力の両方がある場合があります。Pulseaudio は、デフォルトでは複合プロファイルを生成しません。デジタルまたはアナログ プロファイルのいずれかを選択できます。

両方の出力を利用できるようにする最も簡単な方法は、組み合わせたプロファイルをデフォルトのプロファイル構成ファイルの最後に追加することです。

/usr/share/pulseaudio/alsa-mixer/profile-sets/default.conf
...

# Profile must be a '+' separated list of relevant mappings configured above
[Profile output:analog-stereo+output:iec958-stereo+input:analog-stereo]
# Human readable description
description = Analog and digital stereo output and analog stereo intput
output-mappings = analog-stereo iec958-stereo
input-mappings = analog-stereo

このようにして、定義済みのプロファイルが使用可能なプロファイルのリストの最後に追加されます。

これは機能しますが、pulseaudio には自動生成されたプロファイルにフォールバックするという厄介な癖があるため、最終的にカードを組み合わせたプロファイルに戻す必要がある場合があります。これを克服する最善の方法は、auto-profiles を無効にしてカスタムの設定を作成することです。 default.confcustom-profile.conf にコピーし、必要に応じて編集します (この例はステレオ出力/入力用です)

/usr/share/pulseaudio/alsa-mixer/profile-sets/custom-profile.conf

[General]
auto-profiles = no # disable  profile auto-generation
# Leave only relevant mappings:
[Mapping analog-stereo]
device-strings = front:%f
channel-map = left,right
paths-output = analog-output analog-output-lineout analog-output-speaker analog-output-headphones analog-output-headphones-2
paths-input = analog-input-front-mic analog-input-rear-mic analog-input-internal-mic analog-input-dock-mic analog-input analog-input-mic analog-input-linein analog-input-aux analog-input-video analog-input-tvtuner analog-input-fm analog-input-mic-line analog-input-headphone-mic analog-input-headset-mic
priority = 15

[Mapping iec958-stereo]
device-strings = iec958:%f
channel-map = left,right
paths-input = iec958-stereo-input
paths-output = iec958-stereo-output
priority = 5

[Profile output:analog-stereo+output:iec958-stereo+input:analog-stereo]
description = Analog and digital stereo output and analog stereo intput
output-mappings = analog-stereo iec958-stereo
input-mappings = analog-stereo
skip-probe=yes # since you know what your sound card has, there is no need for checking which sinks are available

カスタムプロファイルが作成されたので、それを使用するよう pulseaudio に指示する必要があります。これは、udev ルール を定義することで実行できます。

まず、サウンド カードに関する関連情報を取得します。

$ pactl list cards

Card #0
        Name: alsa_card.pci-0000_00_1b.0
--- snip ----
        Properties:
--- snip ---
                device.vendor.id = "8086" # This is a 'vendor' attribute for udev rule
                device.product.id = "1c20" # This is a 'device' attribute for udev rule

次に、設定ファイルを作成します。

/usr/lib/udev/rules.d/91-pulseaudio-custom.rules

SUBSYSTEM!="sound", GOTO="pulseaudio_end"
ACTION!="change", GOTO="pulseaudio_end"
KERNEL!="card*", GOTO="pulseaudio_end"

SUBSYSTEMS=="pci", ATTRS{vendor}=="0x8086", ATTRS{device}=="0x1c20", ENV{PULSE_PROFILE_SET}="custom-profile.conf"

LABEL="pulseaudio_end"

ここで、udev にサウンドサブシステム udevadm trigger -ssound をリロードするように指示し (root ユーザーとして)、pulseaudio を再起動します。サウンドカードは、定義されたプロファイルのみを使用し、アナログ出力とデジタル出力の両方を使用できるようになります。

HDMIとアナログの同時出力

PulseAudio では、複数のソースへの同時出力が可能です。この例では、HDMI を使用するように構成されたアプリケーションと、アナログを使用するように構成されたアプリケーションがあっても。複数のアプリケーションが同時に音声を受信できます。(aplayalsa-utils パッケージに含まれています。)

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Intel [HDA Intel], device 0: ALC889A Analog [ALC889A Analog]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 0: Intel [HDA Intel], device 1: ALC889A Digital [ALC889A Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: Intel [HDA Intel], device 3: HDMI 0 [HDMI 0]
  Subdevices: 0/1
  Subdevice #0: subdevice #0

または pacmd コマンドを使用して:

$ pacmd list-sinks  | grep -e 'name:'  -e 'alsa.device ' -e 'alsa.subdevice '
	name: <alsa_output.pci-0000_00_1b.0.analog-stereo>
		alsa.subdevice = "0"
		alsa.device = "0"

このような構成の鍵は、pavucontrol で 構成 > 内部オーディオ の下で選択されているものが、デフォルトのデバイスであることを理解することです。pavucontrol > Configuration をロードし、HDMI をプロファイルとして選択します。

アナログ デバイスをセカンダリ ソースとしてセットアップするには、他のモジュールがロードされる前に、最初に /etc/pulse/default.pa 構成に次を追加します。

### Load analog device
load-module module-alsa-sink device=hw:0,0
load-module module-combine-sink sink_name=combined
set-default-sink combined

PulseAudio を再起動し、pavucontrol を実行して、出力デバイス タブを選択します。次の 3 つの設定が表示されます。

  1. Internal Audio Digital Stereo (HDMI)
  2. Internal Audio
  3. Simultaneous output to Internal Audio Digital Stereo (HDMI), Internal Audio

MPlayer、VLC、mpd などの PulseAudio を使用するプログラムを起動し、"再生" タブに切り替えます。実行中のプログラムが 3 つのソースのいずれかをドロップダウンリストから選択します。

このテーマのバリエーションについては このスレッド[1] も参照してください。]

遅延補正付きのモジュールループバックを使用した代替ソリューション

上記の例が、たとえばエコーや遅延のために機能しない場合は、次の構成を試すことができます。

この場合、module-combine-sink を使用すると、HDMI-Audio はアナログより 65ms 遅れています。

/etc/pulse/default.pa
[...]
load-module module-alsa-sink device=hw:0,0 sink_name=analog sink_properties=device.description=analog
load-module module-alsa-sink device=hw:0,1 sink_name=digital sink_properties=device.description=digital
load-module module-alsa-sink device=hw:0,3 sink_name=hdmi sink_properties=device.description=hdmi
load-module module-loopback sink=analog latency_msec=65
[...]
set-default-sink hdmi

HDMI 出力の設定

ftp://download.nvidia.com/XFree86/gpu-hdmi-audio-document/gpu-hdmi-audio.html#_issues_in_pulseaudio に書かれているように、 HDMI オーディオをサポートする特定のグラフィック カードを使用している場合、PulseAudio はオーディオを受信できません。これは、デバイスの最初の HDMI 出力のみを選択する PulseAudio のバグが原因です。回避策としては、ALSA の aplay ユーティリティ (alsa-utils 内) を使用して、どの HDMI 出力が機能しているかを最初に見つけることです。

NVIDIA 製のカードで主に発生しますが、フォーラムスレッド に書かれているように他のカードでも発生することがあります。NVIDIA のカードをケーススタディとして取り上げますが、他のカードでも同じように解決することができます。

HDMI 出力の確認

利用可能なカードを表示して出力を確認してください:

# aplay -l

出力例:

**** List of PLAYBACK Hardware Devices ****
card 0: NVidia [HDA NVidia], device 0: ALC1200 Analog [ALC1200 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 3: ALC1200 Digital [ALC1200 Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: NVidia_1 [HDA NVidia], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: NVidia_1 [HDA NVidia], device 7: HDMI 0 [HDMI 0]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 1: NVidia_1 [HDA NVidia], device 8: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: NVidia_1 [HDA NVidia], device 9: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

HDMI ポートが NVIDIA カードに配線されているが、aplay が NVIDIA オーディオ カードを検出しない場合は、NVIDIA/トラブルシューティング#HDMI で音が出ない に従ってください。

適切なカードでテスト

検出されたカードとデバイスのリストができたので、ユーザーはどれが TV/モニターに出力されているかをテストする必要があります。 たとえば、上記のリストからカード 1、デバイス 3 をテストするには:

# aplay -D plughw:1,3 /usr/share/sounds/alsa/Front_Right.wav

1 は前のセクションで確認した card の値、同じく 3 は device に置き換えてください。音がでない場合、別の device で試してみてください。

PulseAudio を手動で設定して Nvidia HDMI を検出

動作している HDMI デバイスを特定したら、/etc/pulse/default.pa を編集することで、PulseAudio にそのデバイスを強制的に使用させることができます。

# load-module module-alsa-sink device=hw:1,7

ここで、1 はカード、7 は前のセクションで動作することが判明したデバイスです。

pulse audio を再起動します

$ pulseaudio -k
$ pulseaudio --start

サウンド設定マネージャーを開き、ハードウェア タブで、グラフィックスカードの HDMI オーディオが "Digital Stereo (HDMI) Output" に設定されていることを確認します (参考として、私のグラフィックスカードオーディオは "GF100 High Definition Audio Controller" と呼ばれます)

次に、出力タブを開きます。 これで、グラフィックカード用の 2 つの HDMI 出力があるはずです。それらのいずれかを選択し、プログラムを使用してオーディオを再生して、どれが機能するかをテストします。たとえば、VLC を使用してムービーを再生し、それが機能しない場合は別のものを選択します。

オーディオを自動的に HDMI に切り替えます

HDMI ケーブルが接続されている場合に、目的のオーディオプロファイルに切り替えるスクリプトを作成します。

/usr/local/bin/hdmi_sound_toggle.sh
#!/bin/bash

export PATH=/usr/bin

USER_NAME=$(who | awk -v vt=tty$(fgconsole) '$0 ~ vt {print $1}')
USER_ID=$(id -u "$USER_NAME")
CARD_PATH="/sys/class/drm/card0/"
AUDIO_OUTPUT="analog-surround-40"
PULSE_SERVER="unix:/run/user/"$USER_ID"/pulse/native"

for OUTPUT in $(cd "$CARD_PATH" && echo card*); do
  OUT_STATUS=$(<"$CARD_PATH"/"$OUTPUT"/status)
  if [[ $OUT_STATUS == connected ]]
  then
    echo $OUTPUT connected
    case "$OUTPUT" in
      "card0-HDMI-A-1")
        AUDIO_OUTPUT="hdmi-stereo" # Digital Stereo (HDMI 1)
     ;;
      "card0-HDMI-A-2")
        AUDIO_OUTPUT="hdmi-stereo-extra1" # Digital Stereo (HDMI 2)
     ;;
    esac
  fi
done
echo selecting output $AUDIO_OUTPUT
sudo -u "$USER_NAME" pactl --server "$PULSE_SERVER" set-card-profile 0 output:$AUDIO_OUTPUT+input:analog-stereo

スクリプトを 実行可能 にします。

udev ルールを作成して、HDMI のステータスが変化したときにこのスクリプトを実行します。

/etc/udev/rules.d/99-hdmi_sound.rules
KERNEL=="card0", SUBSYSTEM=="drm", ACTION=="change", RUN+="/usr/local/bin/hdmi_sound_toggle.sh"

変更を有効にするには、udev ルールを再読み込みすることを忘れないでください。

udevadm control --reload-rules

再起動が必要になる場合があります。

サラウンドサウンドシステム

大抵の人はサラウンド対応のサウンドカードを持っていても、2チャンネルのスピーカーしか持っていないため、PulseAudio はサラウンド音声の設定をデフォルトとしません。全てのチャンネルを有効にするには、/etc/pulse/daemon.conf を編集して default-sample-channels 行をアンコメント (行頭のセミコロンを削除) して、5.1 チャンネルなら値を 6 に、7.1 チャンネルなら 8 に設定してください:

# Default
default-sample-channels=2
# For 5.1
default-sample-channels=6
# For 7.1
default-sample-channels=8

チャンネルが正しくマッピングされなかったり、pavucontrol で個々のチャンネルのボリュームコントロールが機能しない場合、HDMI とアナログサウンドカードがあるのであれば、以下の行を /etc/pulse/default.pa に追加してみてください:

load-module module-combine channels=6 channel_map=front-left,front-right,rear-left,rear-right,front-center,lfe

上記は 5.1ch での設定例です。

設定を編集したら PulseAudio を再起動してください。

UCM/"HiFi" を無効にする

サラウンドサウンドを PulseAudio で動作させるためのほとんどのガイドでは、カード/HDMI 出力に適切なサラウンド サウンドプロファイルを選択する必要があることが示されています。これは、pavucontrol の "構成" タブを使用して行うことができます。ただし、カードの唯一のプロファイルは "HiFi: Play HiFi quality Music" であり、サラウンドサウンドプロファイルではありません。その後、カードのプロファイルを作成したり、udev ルールを正しく設定したりしようとして、非常に多くの時間を無駄にする可能性があります。どちらも何もしません。

alsa-ucm-conf がインストールされているので、PulseAudio は自分自身のプロファイルを無視して、代わりに ALSA Use Case Manager プロファイルを使おうとしている、というのが実際のところです。 残念ながら、ALSA UCM があなたのカードに有用なプロファイルを持っていない場合、代わりにデフォルトの 2ch "HiFi" になってしまいます。 幸いなことに、PulseAudio プロファイルに切り替えることでこの問題を解決することができます。

これを行う最も簡単な方法は、次のように /etc/pulse/default.pa編集 することです:

load-module module-udev-detect use_ucm=0

pulseaudio.serviceリロード して、ユーザーユニット を 再読み込みしてください。

PulseAudio インストールは UCM を無視し、PulseAudio プロファイルを使用します。上記の手順に従って default-sample-channels を変更した場合、サラウンドサウンドの出力に使用できるサラウンド サウンドプロファイルが含まれます。pavucontrol の構成タブを確認すると、"HiFi" が表示されなくなっていることを確認できます。

フロント/リアの分割

スピーカーを前面のアナログ出力に、ヘッドフォンを背面の出力に接続します。フロント/リアを分割して sink を分離すると便利です。/etc/pulse/default.pa に追加:

load-module module-remap-sink sink_name=speakers sink_properties="device.description='Speakers'" remix=no master=alsa_output.pci-0000_05_00.0.analog-surround-40 channels=2 master_channel_map=front-left,front-right channel_map=front-left,front-right
load-module module-remap-sink sink_name=headphones sink_properties="device.description='Headphones'" remix=no master=alsa_output.pci-0000_05_00.0.analog-surround-40 channels=2 master_channel_map=rear-left,rear-right channel_map=front-left,front-right

alsa_output.pci-0000_05_00.0.analog-surround-40 は 'pacmd list-sinks' で表示されるサウンドカードの名前に置き換えてください。

これで、別々に使用できる sink が 2 つ追加されました。'sink_name' は、その名前の sink が存在しない限り、自由に選択できます。remix パラメーターは、sink 内のチャンネルと一致するようにオーディオをダウン/アップミックスするかどうかを制御します。

ヒント: pulseaudio が master sink not found と表示する場合、リマップの行をコメントアウトしてから、PulseAudio を起動してカードの出力が正しく設定されているか確認してください (例: アナログサラウンド 4.0) もしくは、sink 名の代わりに sink index を使ってみてください。

7.1 を 5.1+2.0 に分割

上記の例と同じように、7.1 構成を 5.1 サラウンドとステレオ出力に分割することもできます。使用しているカードを 7.1 モードに設定してから、以下の行を /etc/pulse/default.pa に追加してください:

load-module module-remap-sink sink_name=Surround sink_properties="device.description='Surround'" remix=no master=alsa_output.pci-0000_00_14.2.analog-surround-71 channels=6 master_channel_map=front-left,front-right,rear-left,rear-right,front-center,lfe channel_map=front-left,front-right,rear-left,rear-right,front-center,lfe
load-module module-remap-sink sink_name=Stereo sink_properties="device.description='Stereo'" remix=no master=alsa_output.pci-0000_00_14.2.analog-surround-71 channels=2 master_channel_map=side-left,side-right channel_map=front-left,front-right

alsa_output.pci-0000_00_14.2 は使用しているサウンドカードの名前に置き換えてください (pacmd list-sinks で確認できます)。上記の設定は 5.1 sink ではフロント/リア/センター+LFE (緑/黒/橙) のジャックを使い stereo sink ではサイドスピーカー (灰) のジャックを使います。stereo sink 用に音声はステレオにダウンミックスされますが、5.1 出力には何も手を加えません。

ヒント: pulseaudio が master sink not found と表示する場合、リマップの行をコメントアウトしてから、PulseAudio を起動してカードの出力がアナログサラウンド 7.1 に設定されているか確認してください。もしくは、sink 名の代わりに sink index を使ってみてください。

LFE リミックスの無効化

デフォルトで、PulseAudio はチャンネル数を default-sample-channels にリミックスし、バージョン 7 から LFE チャンネルもリミックスされます。LFE リミックスを無効化したい場合、以下の行をアンコメントして:

; enable-lfe-remixing = yes

以下のように yes を no に置き換えてください:

enable-lfe-remixing = no

設定したら PulseAudio を再起動してください。

バイノーラルヘッドフォン

ladspa-bs2bAUR にはステレオヘッドホンでサラウンド音声をシミュレートするプラグインが入っています。使用するには、まずヘッドホンを確認:

$ pacmd list-sinks | grep -e 'name:'
name: <alsa_output.pci-0000_00_1b.0.iec958-ac3-surround-51>
name: <alsa_output.pci-0000_00_1b.0.iec958-ac3-surround-51.equalizer>
name: <bluez_sink.00_1F_82_28_93_51>

プラグインをロード (new sink_name is up to you, master=headphone's sink name):

pacmd load-module module-ladspa-sink sink_name=binaural master=bluez_sink.00_1F_82_28_93_51 plugin=bs2b label=bs2b control=700,4.5

pavucontrol を使ってストリームを新しい sink に転送、または:

pactl move-sink-input $INPUTID $BINAURALSINKNAME

ネットワークを介して PulseAudio

PulseAudio のユニークな機能のひとつとして、TCP 経由で LAN 内のサーバーで動作している PulseAudio デーモンにクライアントから音声をストリーミングすることができます。クライアントとサーバーのシステム時刻が正しくないと、音声ストリームが途切れたり音が全く出ないことがあるので注意してください。

ストリーミングを行うには、module-native-protocol-tcp を有効にする必要があります。

TCP サポート (networked sound)

TCP モジュールを有効にするために、クライアントとサーバーの両方で /etc/pulse/default.pa に以下を追加してください (既に行が存在する場合はアンコメント):

load-module module-native-protocol-tcp

For this to work, 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.

Note: If experiencing trouble connecting, use (on server)

pacmd list-modules

TCP サポートと匿名クライアント

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

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

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

Zeroconf (Avahi) パブリッシング

PulseAudio のリモートサーバーを PulseAudio Device Chooser (pasystray) に表示させるには、適当な zeroconf モジュールをロードして、Avahi デーモンを有効化してください。

クライアントとサーバーの両方で pulseaudio-zeroconf パッケージをインストールして、avahi-daemon の systemd ユニットを起動有効化してください。

サーバー側で、load-module module-zeroconf-publish/etc/pulse/default.pa に追加して、クライアント側で、load-module module-zeroconf-discover/etc/pulse/default.pa に追加してください。これで適切な sink を選択することでストリームや音声出力がリモートの PulseAudio サーバーに転送されます。

If you have issues with the remote syncs appearing on the client, try restarting the Avahi daemon on the server to rebroadcast the available interfaces.

サーバーの選択

Run the graphical PulseAudio Volume Control pavucontrol. Under the Output Devices tab, you should see the local and remote output devices. Under the Playback tab, to the left of the "X" Mute Audio button, you should see a box containing the name of an output device. That box is actually a button, which will display a drop-down radio-button list of the available output devices, with one output device selected. Selecting an output device from the list will allow the audio stream to be switched to the PulseAudio server associated with that output device. This control is not at all obvious until you have used it, and is especially useful with a remote Headless sound server.

Similarly, under the Input Devices tab, local and remote input devices will be seen. And under the Recording tab, there will be a box, to the left of the "X" Mute Audio button, with the name of an input device which is actually a button which will display a drop-down radio-button list of available input devices.

Run pavucontrol on the local or remote host associated with the audio stream to be directed. For instance, run pavucontrol on the remote host to direct the remote audio output to the local host. Run pavucontrol on the local host to direct the local audio output to some remote host.

Setting up simultaneous inputs or outputs is a different thing. Search about "monitor" and "module-combine-sink" for that.

ローカルの X クライアントで使用する PulseAudio サーバーを切り替える

X の中からクライアントで使用するサーバーを切り替えるには pax11publish コマンドを使います。例えば、デフォルトのサーバーからホストネーム foo のサーバーに切り替えるには:

$ pax11publish -e -S foo

もしくは、デフォルトのサーバーに戻すには:

$ pax11publish -e -r

上記のコマンドは (上で説明しているのと同じように) PulseAudio サーバーで音声をストリーミングする代わりに、X11 ルートウィンドウの PulseAudio 変数を編集します。それによって PulseAudio のクライアントライブラリが localhost 以外の PulseAudio サーバーに接続するようになります。プログラムはローカルの pulseaudio プロセスに依存しなくなるため、ローカルのプロセスは停止してかまいません。pactl, pacmd, pavucontrol などのプログラムでリモートの PulseAudio サーバーを制御するには適切な PULSE_SERVER 変数/X 変数を指定して実行する必要があります。

Note that for the switch to become apparent, the programs using Pulse must be restarted, or their PulseAudio client library otherwise reinitialized (completely stopping and restarting playback may be enough). To make this setting permanent, edit default-server in ~/.config/pulse/client.conf or /etc/pulse/client.conf.

何もかもが失敗しているような場合

The following is a quick fix and NOT a permanent solution

On the server:

$ paprefs 

Go to Network Access -> Enable access to local sound devices (Also check both 'Allow discover' and 'Don't require authentication').

On the client:

$ export PULSE_SERVER=server.ip && mplayer test.mp3

ALSA モニターのソース

To be able to record from a monitor source (a.k.a. "What-U-Hear", "Stereo Mix"), use pactl list to find out the name of the source in PulseAudio (e.g. alsa_output.pci-0000_00_1b.0.analog-stereo.monitor). Then add lines like the following to /etc/asound.conf or ~/.asoundrc:

pcm.pulse_monitor {
  type pulse
  device alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
}

ctl.pulse_monitor {
  type pulse
  device alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
}

Now you can select pulse_monitor as a recording source.

Alternatively, you can use pavucontrol to do this: make sure you have set up the display to "All input devices", then select "Monitor of [your sound card]" as the recording source.

特定の出力のモニター

It is possible to monitor a specific output, for example to stream audio from a music player into a VOIP application. Simply create a null output device:

pactl load-module module-null-sink sink_name=<name>

In Pulseaudio Volume Control (pavucontrol), under the "Playback" tab, change the output of an application to <name>, and in the recording tab change the input of an application to "Monitor of <name>". Audio will now be outputted from one application into the other.

PulseAudio と JACK

音楽を作曲・編集するときは JACK Audio Connection Kit が人気があり、Linux のオーディオアプリケーションによって広くサポートされています。PulseAudio と同じような機能を提供しますが、特にプロフェッショナルなオーディオ作業環境に特化しています。音楽をモニタリングするときの遅延を少なくして、マルチ I/O を備えたサウンドデバイスの入出力を多彩に制御できます。

KXStudio を使う方法

JACK の開発者 によって公式に推奨されている方法です。

jack2-dbus[リンク切れ: 置換パッケージ: jack2]jack2 パッケージの両方で動作します。

JACK には ALSA と PulseAudio、そして JACK とブリッジする機能がネイティブで備わっています。JACK と PulseAudio を両方動かして同時に出力することが可能であり、設定の編集やターミナルコマンドは必要ありません。

qjackctl を使用している場合、先に進む前にアンインストールすることが推奨されます。

まずは cadencepulseaudio-jack をインストールしてください。インストールして起動したら、ウィンドウ右下の JACK ブリッジ設定を探してください。ALSA の音声ブリッジを ALSA -> PulseAudio -> JACK と設定して PulseAudio のブリッジを有効にしてください。pavucontrol で Jack sink の全ての出力デバイスと Jack input の全ての入力デバイスをミュートにしてください。Force Restart ボタンを使って JACK を起動して、問題なく起動すれば PulseAudio プログラムは JACK に出力するようになっているはずです。

sink を手動で設定する方法

この設定は jackdbus (D-Bus のサポートを有効にしてコンパイルされた JACK2) でのみ機能します。また、pulseaudio-jack パッケージが必要です。/etc/pulse/default.pa に以下の行を記述してください:

load-module module-jackdbus-detect options

options はモジュールによってサポートされているオプションならなんでもかまいません。通常は channels=2 です。

Jack-DBUS Packaging ページより:

Server auto-launching is implemented as D-Bus call that auto-activates JACK D-Bus service, in case it is not already started, and starts the JACK server. Correct interaction with PulseAudio is done using a D-Bus based audio card "acquire/release" mechanism. When JACK server starts, it asks this D-Bus service to acquire the audio card and PulseAudio will unconditionally release it. When JACK server stops, it releases the audio card that can be grabbed again by PulseAudio.

module-jackdbus-detect.so は jackdbus が起動・停止したときに動的に module-jack-sink と module-jack-source をロード・アンロードします。

PulseAudio の音が鳴らない場合、pavucontrol で適当なプログラムが再生タブに現れていることを確認してください。存在しない場合、以下を ~/.asoundrc または /etc/asound.conf に追加して ALSA を PulseAudio にリダイレクトしてください:

pcm.pulse {
    type pulse
}

ctl.pulse {
    type pulse
}

pcm.!default {
    type pulse
}
ctl.!default {
    type pulse
}

上記の設定で上手く行かない場合、pavucontrol で再生タブを確認してプログラムがオーディオカード (JACK が制御するため、機能しません) ではなく PulseAudio JACK Sink に出力するようになっているか確認してください。また、JACK のグラフで PulseAudio JACK Source がシステムオーディオ出力に接続されていることを確認してください。

シェルスクリプトを使う方法

This method allows JACK and PulseAudio to output at the same time. It mostly relies on shell scripts that are automatically run by QJackCTL to manage aspects of how the JACK sinks and PulseAudio behave.

The basic idea is that killing PulseAudio is a bad idea because it may crash any apps using PulseAudio and disrupt any audio playing.

The flow of how this setup works:

  1. PulseAudio releases the sound card
  2. JACK grabs sound card and starts up
  3. script redirects PulseAudio to JACK
  4. manually send PulseAudio apps to JACK output (pavucontrol may come in helpful for this)
  5. use JACK programs etc
  6. via script, stop redirecting PulseAudio to JACK
  7. stop JACK and release sound card
  8. PulseAudio grabs sound card and reroutes audio to it directly

With QJackCTL, set up these scripts:

pulse-jack-pre-start.sh set it up as the execute script on startup script

#!/bin/bash
pacmd suspend true

pulse-jack-post-start.sh set this one up as execute script after startup

#!/bin/bash
pactl load-module module-jack-sink channels=2
pactl load-module module-jack-source channels=2
pacmd set-default-sink jack_out
pacmd set-default-source jack_in

pulse-jack-pre-stop.sh "execute script on shutdown"

#!/bin/bash
SINKID=$(pactl list | grep -B 1 "Name: module-jack-sink" | grep Module | sed 's/[^0-9]//g')
SOURCEID=$(pactl list | grep -B 1 "Name: module-jack-source" | grep Module | sed 's/[^0-9]//g')
pactl unload-module $SINKID
pactl unload-module $SOURCEID
sleep 5

pulse-jack-post-stop.sh "execute script after shutdown"

#!/bin/bash
pacmd suspend false

PulseAudio を終了する方法

This method relies on shell scripts to automatically kill PulseAudio when JACK is started, and automatically restart it when JACK is stopped. This will result in lower CPU usage than having both running, but can cause errors in already running PulseAudio application and does not allow simultaneous output of both.

Using the settings listed above, use QjackCtl to execute a script upon startup and shutdown to load/unload PulseAudio. Part of the reason users may wish to do this is that the above changes disable PulseAudio's automatic hardware detection modules. This particular setup is for using PulseAudio in an exclusive fashion with JACK, though the scripts could be modified to unload and load an alternate non-JACK setup, but killing and starting PulseAudio while programs might be using it would become problematic.

ノート: padevchooser in the following example is deprecated. It is replaced by pasystray

The following example could be used and modified as necessary as a startup script that daemonizes PulseAudio and loads the padevchooser program (optional, needs to be built from AUR) called jack_startup:

#!/bin/bash	
#Load PulseAudio and PulseAudio Device Chooser
pulseaudio -D
padevchooser&

as well as a shutdown script to kill PulseAudio and the Pulse Audio Device Chooser, as another example called jack_shutdown also in the home directory:

#!/bin/bash	
#Kill PulseAudio and PulseAudio Device Chooser		
pulseaudio --kill	
killall padevchooser	

Both scripts need to be made executable:

chmod +x jack_startup jack_shutdown

then with QjackCtl loaded, click on the Setup button and then the Options tab and tick both "Execute Script after Startup:" And "Execute Script on Shutdown:" and put either use the ... button or type the path to the scripts (assuming the scripts are in the home directory) ~/jack_startup and ~/jack_shutdown making sure to save the changes.

PulseAudio と OSS

/etc/pulse/default.pa に以下を追加してください:

load-module module-oss

PulseAudio を再起動して、OSS デバイスの sink と source が定義されていることを確認してください。

chroot から PulseAudio

Since a chroot sets up an alternative root for the running/jailing of applications, PulseAudio must be installed within the chroot itself (pacman -S pulseaudio within the chroot environment).

PulseAudio, if not set up to connect to any specific server (this can be done in /etc/pulse/client.conf, through the PULSE_SERVER environment variable, or through publishing to the local X11 properties using module-x11-publish), will attempt to connect to the local pulse server, failing which it will spawn a new pulse server. Each pulse server has a unique ID based on the machine-id value in /var/lib/dbus. To allow for chrooted apps to access the pulse server, the following directories must be mounted within the chroot:-

/run
/var/lib/dbus
/tmp
~/config/.pulse

/dev/shm should also be mounted for efficiency and good performance. Note that mounting /home would normally also allow sharing of the ~/.pulse folder.

PulseAudio は XDG_RUNTIME_DIR でソケットのパスを選択します。sudo を使って通常ユーザーとして chroot する場合は注意してください (Sudo#環境変数を参照)。

For specific direction on accomplishing the appropriate mounts, please refer to the wiki on installing a bundled 32-bit system, especially the additional section specific to PulseAudio.

PulseAudio サーバーの自動生成を無効化

Some users may prefer to manually start the PulseAudio server before running certain programs and then stop the PulseAudio server when they are finished. A simple way to accomplish this is to edit ~/.config/pulse/client.conf or /etc/pulse/client.conf and change autospawn = yes to autospawn=no. Make sure the line is uncommented as well.

~/.config/pulse/client.conf #or /etc/pulse/client.conf
autospawn=no

Now you can manually start the pulseaudio server with

$ pulseaudio --start

and stop it with

$ pulseaudio --kill

This setting is also respected by the default pulseaudio dektop session startup script start-pulseaudio-x11 which is executed from /etc/xdg/autostart/pulseaudio.desktop.

pulseaudio デーモンの無効化

pulseaudio デーモンを完全に無効にして起動しないようにしたい場合、設定ファイル (~/.config/pulse/client.conf または /etc/pulse/client.conf) に daemon-binary=/bin/true を追加してください:

~/.config/pulse/client.conf
daemon-binary=/bin/true

ステレオからモノにリマップ

Remap a stereo input-sink to a mono sink by creating a virtual sink. It would be useful if you only have one speaker. Add to /etc/pulse/default.pa:

load-module module-remap-sink master=alsa_output.pci-0000_00_1f.5.analog-stereo sink_name=mono sink_properties="device.description='Mono'" channels=2 channel_map=mono,mono
# Optional: Select new remap as default
set-default-sink mono

(replace alsa_output.pci-0000_00_1f.5.analog-stereo in the sound card name shown from pacmd list-sinks)

Switch player between virtual mono sink and real stereo sink.

左/右チャンネルの交換

左と右のチャンネルが入れ替わる「リバースステレオ」と同じ設定です。

First, identify the card you want its channels swapped:

$ cat /proc/asound/cards

and use the name string for the device you wish to use (the one in square brackets, e.g. [Intel]).

Edit /etc/pulse/default.pa and comment out module-hal-detect and module-detect lines.

Search for the commented-out line that starts "#load-module module-alsa-sink", uncomment it and change it to

load-module module-alsa-sink device=hw:[device name] channel_map=right,left

Restart the pulseaudio deamon by running

pulseaudio -k; pulseaudio -D

Pulseaudio FAQ: How can I reverse my left and right speaker channels?

default.pa を使う

別の方法でチャンネルを入れ替えることもできます [2]:

~/.config/pulse/default.pa
#!/usr/bin/pulseaudio -nF

.include /etc/pulse/default.pa

load-module module-remap-sink sink_name=reverse-stereo master=0 channels=2 master_channel_map=front-right,front-left channel_map=front-left,front-right
set-default-sink reverse-stereo

PulseAudio を ALSA のダムパイプとする

Some people do not want to run PulseAudio all the time for various reasons. This example will turn the full fledged audio server into an unobstrusive dumb pipe to ALSA devices that automatically starts and stops itself when done, allowing applications that requires PulseAudio to fully function while not touching any ALSA setting nor setting itself as the default ALSA device.

This configuration tells native PA clients to autospawn the daemon when they need it, then the daemon is configured to autoexit as soon as all clients have disconnected. The daemon itself uses a plain simple static configuration that uses your configured pcm.!default ALSA devices and nothing more. No replacement of ALSA's default, no playing with mixer levels, nothing but record/playback. Also make sure pulseaudio-alsa is not installed so standard ALSA clients don't default to pulse. alsamixer functions properly as well as any other ALSA clients. Also make sure common frameworks like Xine, Gstreamer and Phonon are configured to use ALSA: by default if they detect PulseAudio is installed they will try to use it before ALSA.

/etc/pulse/daemon.conf
# Replace these with the proper values
exit-idle-time = 0 # Exit as soon as unneeded
flat-volumes = yes # Prevent messing with the master volume
/etc/pulse/client.conf
# Replace these with the proper values

# Applications that uses PulseAudio *directly* will spawn it,
# use it, and pulse will exit itself when done because of the
# exit-idle-time setting in daemon.conf
autospawn = yes
/etc/pulse/default.pa
# Replace the *entire* content of this file with these few lines and
# read the comments

.fail
    # Set tsched=0 here if you experience glitchy playback. This will
    # revert back to interrupt-based scheduling and should fix it.
    #
    # Replace the device= part if you want pulse to use a specific device
    # such as "dmix" and "dsnoop" so it doesn't lock an hw: device.
    
    # INPUT/RECORD
    load-module module-alsa-source device="default" tsched=1
    
    # OUTPUT/PLAYBACK
    load-module module-alsa-sink device="default" tsched=1 
    
    # Accept clients -- very important
    load-module module-native-protocol-unix

.nofail
.ifexists module-x11-publish.so
    # Publish to X11 so the clients know how to connect to Pulse. Will
    # clear itself on unload.
    load-module module-x11-publish
.endif

スピーカーとヘッドホンを両方とも接続してソフトウェアで切り替える

By design, Pulseaudio automatically turns off Line Out when headphones are plugged in and uses Headphone slider instead. You can observe this behavior in alsamixer. What we want is to have Headphone and Line Out sliders working separately and at the same time. This is extremely useful if you want to remap Realtek's jacks to have, say, Rear Green for headphones and Blue for speakers (with the help of hdajackretask from alsa-tools).

To achieve this, you should directly edit Pulseaudio mixer's configuration.

1. We tell pulseaudio that headphones are always plugged in. Edit:

/usr/share/pulseaudio/alsa-mixer/paths/analog-output-lineout.conf

Find:

[Jack Headphone]
state.plugged = no
state.unplugged = unknown

Change no to yes

2. By default, Line Out's volume controlled only by Master, and not by Line Out slider itself. We want to merge Line Out with Master.

Add this snippet to the end of the file:

[Element Line Out]
switch = mute
volume = merge

3. We need to completely cut off Line Out when we use headphones. Edit:

/usr/share/pulseaudio/alsa-mixer/paths/analog-output-headphones.conf

Add this snippet to the end of the file:

[Element Line Out]
switch = off
volume = off

4. Like Pulseaudio, Alsa itself cuts off speakers when headphones are plugged in. Open alsamixer (in case of Realtek HDA alsamixer -c0) and change Auto-Mute mode to disabled.

5. Restart Pulseaudio

$ pulseaudio -k
$ pulseaudio --start

Now you have two separate ports on the same sink in pulseaudio. They mute each other, so you can switch to headphones and this will mute Line Out, and vice versa. To switch between ports you can use Gnome or Plasma sound mixer, or install appropriate desktop extension.

複数のユーザーが同時に PulseAudio を使えるようにする

ときにはデスクトップのメインユーザーとは別のユーザーを使ってソフトウェアを分離したいという場合があります。しかしながら、PulseAudio はデフォルトでは別のユーザーからの接続を拒否します。PulseAudio の UNIX ソケットを作成することで、メインユーザーで動作している PulseAudio デーモンに他のユーザーから接続することができるようになります。

まず、/etc/pulse/default.pa または ~/.config/pulse/default.pa を編集して unix ソケットのディレクティブを追加してください:

~/.config/pulse/default.pa
load-module module-native-protocol-unix auth-anonymous=1 socket=/tmp/pulse-socket

そして、作成した UNIX ソケットを別のユーザーから使うように PulseAudio をクライアントとして設定します:

/home/secondaryuser/.config/pulse/client.conf
default-server = unix:/tmp/pulse-socket

PulseAudio デーモンを再起動すると、メインユーザーの PulseAudio デーモンを使って他のユーザーから音声を流すことができるようになります。