ALSA

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page ALSA and the translation is 70% complete.


この記事では ALSA (Advanced Linux Sound Architecture) を利用したサウンドカードのセットアップについて解説します。

インストール

ハードウェアの検出

必要なドライバを見つけるためにはまず、稼働しているオーディオコントローラを検出します。そのためには lspci コマンドを実行します:

user $lspci | grep -i audio

コントローラの名前が判明したら、必要なドライバが ALSA sound card matrix で見つけられます。

カーネル

次のカーネルオプションを有効化してください:

カーネル
Device Drivers --->
    <*> Sound card support
        <*> Advanced Linux Sound Architecture --->
            [*] PCI sound devices  --->
                Select the driver for your audio controller.
                HD-Audio  --->
                   Select a codec or enable all and let the generic parse choose the right one:
                   [*] Build Realtek HD-audio codec support
                   [*] ...
                   [*] Build Silicon Labs 3054 HD-modem codec support
                   [*] Enable generic HD-audio codec parser
            [*] USB sound devices  --->
                Must have as some cards are presented as USB devices.
                [*] USB Audio/MIDI driver
General setup --->
    [*] System V IPC

lsmod コマンドが助けになります。

システムが 8 個以上のサウンド出力を持っている場合(GPU の HDMI 出力はそれぞれ 1 個として数えられます)、サウンドカードの最大数を上げる必要があるでしょう:

カーネル
Device Drivers --->
    <*> Sound card support
        <*> Advanced Linux Sound Architecture --->
            [*] Dynamic device file minor numbers
            (32) Max number of sound cards

ソフトウェア

portage は、他のパッケージで ALSA に対するサポートを有効化するためのグローバル USE フラグ alsa を知っています。この USE フラグを有効化することで media-libs/alsa-lib を自動的にインストールします(x86amd64 のデスクトッププロファイルではデフォルトで有効化されています):

root #euse -E alsa

euse コマンドは app-portage/gentoolkit に含まれます。

USE flags for media-libs/alsa-lib Advanced Linux Sound Architecture Library

alisp Enable support for ALISP (ALSA LISP) interpreter for advanced features.
debug Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Backtraces
doc Add extra documentation (API, Javadoc, etc). It is recommended to enable per package instead of globally
python Add optional support/bindings for the Python language

これを設定したら、変更を適用するためにシステムを更新してください:

root #emerge --ask --changed-use --deep @world

media-sound/alsa-utils パッケージはサウンドシステムのトラブルシュートとテストをするためのいくつかのツールを提供します。まだインストールされていなければ、このパッケージをマージするといいでしょう:

root #emerge --ask media-sound/alsa-utils

設定

ファイル

  • /etc/asound.conf - グローバルな (システム全体の) 設定ファイル。
  • ~/.asoundrc - ローカルな (ユーザ毎の) 設定ファイル。

~/.asoundrc

ユーザ毎に ALSA デフォルト設定を上書きするためにこのファイルを利用することができます。システムが特殊なハードウェアを持っている場合、カード 0 デバイス 0 (デフォルト) はおそらく動作しないでしょう。

最も簡単な変更のひとつがカードとデバイスです。Nvidia カード上の HDMI をオンボードの Realtek ALC88* オーディオデバイスに接続した私の場合はこうでした。

ファイル ~/.asoundrc
defaults.pcm.!card 1
defaults.pcm.!device 7

使用する予定のサウンドカードであるデバイスに割り当てられたカード番号が見つからない場合でも、パニックに陥らないでください。カード番号は内部的に名前であり、使用できます。カードがこのようにリストされている場合...

user $aplay -L
front:CARD=Generic,DEV=0
HD-Audio Generic, ALC282 Analog
Front speakers

... この場合は、~/.asoundrc ファイルを次のようにすべきということです:

ファイル ~/.asoundrc
defaults.pcm.!card Generic
defaults.pcm.!device 0
defaults.ctl.!card Generic
警告
これらの設定はすべてのソフトウェアミキシングを無効化します。すべてを 96kHz で出力するには、defaults.pcm.dmix.rate 96000~/.asoundrc ファイルに追加してください。

複数のサウンドカードを使用している場合、デバイス番号はブートの度に順番が変わることがあるので、名前を使うほうが便利です。

正しい名前が分からないなら、有効な名前のリストは次のコマンドで簡単に取得できます:

user $cat /sys/class/sound/card*/id

これは複数のサウンドカードを持つある開発者のシステムからの出力です:

user $cat /sys/class/sound/card*/id
Q1U
HDMI
PCH
C930e

ここでは Q1U のマイクが Q1U として、内蔵 HDMI が HDMI として、アナログオーディオジャックが PCH として、ウェブカムの内蔵マイクが C930e として表示されています。どれもカードに対する有効な名前です。

警告
複数のサウンドカードが使用されている場合に名前ではなく番号で指定すると、ブート毎にデバイスが再整列され、新しい番号を使うように設定ファイルを編集するまでサウンドが正しく動作しないでしょう。

S/PDIFまたはHDMIの .asoundrc

背景

ほとんどのサウンドカードでは、S / PDIFデジタル同軸ケーブルまたは光ケーブルを使用して、オーディオを外部のコンシューマレシーバーまたはDACに渡すことができます。そうすることで、音質と圧縮されたドルビー/ DTSエンコードされた素材が保持されます。非圧縮のドルビー/ DTSまたはBluray素材には、HDMI接続が必要です。より一般的なモノまたはアナログステレオケーブルは、Dolby / DTS信号を伝送できません。

デフォルト設定でインストールされた ALSA でも、(.asoundrc ファイルを変更することなく)そのまま S/PDIF または HDMI の接続を動作させることができる場合がありますが、ウェブブラウザの Adobe Flash プラグインなど一部のアプリケーションは音声を再生できないでしょう。そのため、多くの S/PDIF と HDMI 接続のためには通常、以下の .asoundrc が必要です。加えて、.asoundrc ファイルの内容を反映するには、開いているメディアアプリケーション(つまり、Adobe Flash プラグインを使用しているウェブブラウザ)を再起動する必要があるでしょう。

接続とメディアタイプの選択

基本的なアナログ接続

基本的なアナログ(つまりRCA)接続-基本ユーザー。品質はサウンドカードDACに依存します。SNR dbレベルの高いサウンドカードを探します。

S/PDIF

S / PDIFは、Dobly / DTS圧縮信号を含む音楽、ビデオ、およびDVD品質のムービーに高品質のオーディオを提供します。最近のほとんどのサウンドカードとマザーボードは、何らかのS / PDIFポートを備えています。最近では、マザーボードにS / PDIF Toslinkポートが表示されるのがより一般的です。多くのコンピューターゲームは、圧縮されたDolby / DTS信号を提供します。

S/PDIF デジタル同軸

S / PDIFデジタル同軸には電圧クロストークに問題があるかもしれませんが、単純なミニジャックまたはRCA同軸ケーブルしか必要としないため、より一般的です。

S/PDIF オプティカル(TOSLINK)

S/PDIF (TOSLINK) 光ケーブルは、光ファイバーであるため、ケーブル間の電気的なクロストークや干渉を完全に回避しますが、ケーブルが過度に曲がると信号劣化の影響を受けやすくなります。オーディオ愛好家は、この種のケーブルを好む傾向があります。

HDMI

HDMI (High-Definition Multimedia Interface) ケーブルは、圧縮された Dolby/DTS および非圧縮(つまり Blu-ray)Dolby/DTS 信号を伝送できます。オーディオ市場ではこの接続が好まれていますが、S/PDIF 接続は維持されます。1 つの懸念は、HDMI ケーブルは銅線であり、S/PDIF デジタル同軸接続と同様に、依然として電気的なクロストークまたは干渉を受けやすいことです。

HDMI光ケーブルも生産されていますが、一般的に消費者市場には高すぎます。オーディオ愛好家がS / PDIFオプティカルポートを持っている場合、音楽やDVDムービーなどの他のメディアにはS / PDIF接続を使用しますが、Blu-rayメディアなどの非圧縮Dolby / DTSエンコード素材の処理に必要な場合にのみHDMIを使用します。繰り返しますが、基本的なユーザーはおそらくHDMIを使用するだけで、構成ファイルを変更する手間を省くことができます。

設定

デジタル出力デバイスを探します:

user $aplay --list-devices

カード/デバイス番号を使用するために以下のファイルを変更します。

ファイル ~/.asoundrc
pcm.!spdif {
    type hw
    card 0
    device 1
}

pcm.!default {
    type plug
    slave {
        pcm "spdif"
    }
}

# 単一のカードを複数のアプリケーションで共有する
#pcm.!default {
#    type plug
#    slave.pcm "dmix:CARD=0,DEVICE=1,RATE=48000"
#}
メモ
上記では、複数のサウンドアプリケーションからサウンドを再生したり、1つのサウンドカードを介して2つ以上のサウンドを同時に再生することはできません。このタスクを実行するために、音質はわずかに低下しますが、音はリミックスされます。音楽を聴くほとんどの人は、中断や音質の低下により、これを許可しないことを好みます。しかし、これを望む人のために、上記のコメントされたコードのセクションはこれを達成します。
メモ
aplay を使って音声ファイルを再生するとき、プレイバックの先頭は切り取られるでしょう。デジタル S/PDIF または HDMI 接続を開いたままにせず、音声ファイルを再生するたびに接続を開始する必要があるからです。Microsoft Windows は、レシーバまたは DAC を開いたまま、再生時にメディアをリミックスすることに注意してください。

A/52, AC3, Dolby, DTS

S / PDIF出力を提供するサウンドカードは、損失の多い圧縮マルチチャネルオーディオを通過できます。私の耳には、2ビットのCDまたはDVDオーディオと比較して、高ビットレートの圧縮メディアの損失はほとんどありません。これは、マルチチャンネルが複数のスピーカーに給電しているためだと思われます。したがって、ハードウェアが多くなればなるほど、音質は同等になりますか?

サウンドカードにS / PDIFがあると示されている場合、特にドルビーまたはDTSアイコンを表示したり、その機能内にリストされていなくても、ドルビーまたはDTSを通過します。これは、彼らがドルビーまたはDTSをリストするとき、アップミキシング用のソフトウェアを提供しているため、またはアナログ出力を介してデコードされた信号を提供しているためです。

HDMIは非圧縮のマルチチャンネルオーディオを通過しますが、ビデオフィードはHDMI仕様の要求に応じてインターリーブされます。DVDビデオやオーディオと比較すると、品質の違いはほとんどありません。S / PDIF ToslinkとHDMIの間で気づいた唯一のことについて、HDMIは信号を数ワットまたは5db増幅するようです。(これはビットレートが高いためだと思いますか?)

そのため、現在でもS / PDIFは非常に人気があります。

メモ
高度なエンコーディングをパススルーするためには S/PDIF または HDMI 接続が必須です。アナログ接続(RCA とミニジャック)は高度なエンコーディングをサポートしません。

Dolby または DTS をデコード・エンコードするにはライセンスが必要です。すでにマルチチャンネルに対応したサウンドカードを購入している場合、おそらくすでにライセンスを持っているでしょう。より詳しい情報についてはこの記事をご覧ください。

A/52 (pcm.a52encode) プラグインを利用するには、ALSA media-plugins/alsa-plugins パッケージに ffmpeg USE フラグを含めて再コンパイルする必要があります。

root #USE="ffmpeg" emerge -q media-plugins/alsa-plugins

デコードまたは再生する

ALSA ライブラリを含めるために、mplayer またはお好みのソフトウェアプレイヤーを再コンパイルしてください。

root #USE="a52 dts" emerge -q media-video/mplayer

mplayer.conf にマルチチャネルコーデックを追加してください。そうすることで、再生しようとしているメディアに対して、ダウンミックスではなくハードウェアパススルーを選択させてください。

ファイル /etc/mplayer/mplayer.conf
ac=hwac3,hwdts,hwmpa,spdifac3,spdifeac3,spdifaac,spdifdts,spdifmpa,spdifthd,dts,ffaac,

これで、ほぼすべてのドルビーまたはDTS信号をS / PDIFを介して受信機に渡すことができます(そして楽しむことができます)。

A/52 にエンコードする

2 チャンネルオーディオを A/52 マルチチャンネルオーディオストリームにアップミックスする

通常の1または2チャンネルのオーディオストリームまたはファイルからA / 52エンコードオーディオをシミュレートするために、ALSAはA / 52プラグインを使用してアップミックスできます。(A / 52はAC-3またはDolby Digitalエンコードとも呼ばれます。)

A / 52アップミキシングは、コンピューターゲームをプレイする場合や、古い映画などのDolby / DTSエンコードされた素材なしでビデオを見る場合に推奨されます。多くのサウンドカードメーカーは、アプリケーションにDolby Digitalへのソフトウェアアップミキシング機能を提供しており、音楽を除き、そのようなメディアを聴くときにこのアップミキシングを有効にすることをお勧めします。

A / 52へのアップミキシングは、オーディオマニアによって嫌われています。そのため、ストリームをコンシューマーステレオレシーバーまたはDACに送信する前に、すべてのサウンドをA / 52にアップミックスするかどうかは、ユーザーの好みです。事実、オーディオマニアはシンプルなステレオを好み、さらに状態のステレオは、ドルビー/ DTS素材やギミックでエンコードされた他のオーディオよりも優れた品質です。また、民生用ステレオまたはDACには、オーディオを5チャネルオーディオにアップミックスする機能が含まれている可能性があります。

ファイル ~/.asoundrc
pcm.!default {
    type plug:surroundaudio
}

ctl.!default {
    type plug:surroundaudio
}

pcm.a52encode {
    type a52
    format S16_LE
    channels 6
    rate 48000
    bitrate 448
}

pcm.surroundaudio a52encode

ctl.surroundaudio {
    type hw
    card 0
    device 1
}
user $speaker-test -Dsurroundaudio -c 6
PCM 5.1 24 ビットオーディオを A/52 16 ビットオーディオストリームにエンコードする (S/PDIF 経由でのストリーミングのため)

S/PDIF で再生するために、PCM 5.1 オーディオストリームを圧縮された Dolby Digital ストリームにエンコードすることでも知られています。HDMI は PCM 5.1オーディオストリームの帯域幅を処理できるため、HDMI を使用している場合、これを実際に使用する必要はありません。S/PDIF Toslink もそうするためにアップグレードされたと思われますが、ほとんどのハードウェアはまだ新しい仕様にアップグレードされていません。

For some reason, the previous .asoundrc section previously mentioned doesn't work with PCM 5.1 streams. Another issue I run into with 24 bit PCM 5.1 audio streams, they require downmixing from S24_LE to S16_LE bit format. Reason being, 24 bit is a common format for most media, however receivers can sometimes only decode 16 or 32 bit audio. Also, the S/PDIF can only handle 16 bit audio when encoding to multi-channel formats such as A/52, for the time being until S/PDIF TosLink hardware specifications are upgraded.

The following .asoundrc excerpt will encode a PCM 5.1 24 bit stream into a 16 bit A/52 stream, for streaming over S/PDIF.

ファイル ~/.asoundrc
#####
# Description: This will make it possible to use a52 with PulseAudio out of 
#         the box. It may be useful for other use cases. Just include 
#         this in the ~/.asoundrc file.

pcm.a52 {
    @args [ CARD ]
    @args.CARD {
        type string
        default 0
    }
    type plug
    slave {
        pcm {
            type a52
            card $CARD
            bitrate 640 # Default 448
        }
        # Convert to S16 bit format, per SPDIF spec
        format S16_LE # Required for current S/PDIF spec
    }
}
user $aplay -D pcm.a52 /home/me/Music/Led_Zeppelin/Celegration_Day/PCM51-24bit/*.wav

オーディオを 2 個以上のデバイスにクローンする

オーディオをクローンする必要があるかもしれません (例えば、別々の入力を持つ 2 台のクローンされたスクリーン (一方のスクリーンは HDMI で、もう一方のスクリーンは DVI + アナログオーディオ) を使っていとします)。 次に示すのは、2 チャネル (またはより多く) をクローンするために、グローバルな設定としてもローカルな設定としても使用できる、単純なスクリプトです。 コメントのある行より下の行は使用中のシステムに応じて微修正する必要があります。 スクリプトの作者ついてのさらなる情報と、フォーラムディスカッションはこちらです。

ファイル /etc/asound.conf
ctl.!default {
    type hw
    # デフォルトのカードを設定してください
    card 0
}

pcm.!default both

pcm.both {
    type softvol
    slave {
        pcm {
            type plug
            slave {
                pcm {
                    type route
                    slave {
                        pcm {
                        type multi
                        slaves.a.pcm {
                            type dmix
                            ipc_key 2589455
                            ipc_perm 0666
                            slave {
                                pcm {
                                    # デフォルトカードを追加してください - 1 番目のサウンドカードに合うように変更してください
                                    type hw
                                    card 0
                                    device 0
                                }
                                buffer_size 4096
                                channels 2
                            }
                        }
                        slaves.b.pcm {
                            type dmix
                            ipc_key 4855689
                            ipc_perm 0666
                            slave {
                                pcm {
                                    # スレーブサウンドカードを追加してください - 1 番目のサウンドカードに合うように変更してください
                                    type hw
                                    card 1
                                    device 7
                                }
                                buffer_size 4096
                                channels 2
                            }
                        }
                        slaves.a.channels 2
                        slaves.b.channels 2
                        bindings.0.slave a
                        bindings.0.channel 0
                        bindings.1.slave a
                        bindings.1.channel 1
                        bindings.2.slave b
                        bindings.2.channel 0
                        bindings.3.slave b
                        bindings.3.channel 1
                    }
                }
                ttable.0.0 1
                ttable.1.1 1
                ttable.0.2 1
                ttable.1.3 1
            }
        }
    }
}
control {
    # ボリュームコントロールの名前を設定してください
    name PCM
    # デフォルトカードに設定してください
    card 0
}

JACK audio connection kit

Jack は、すでに低レイテンシーの ALSA ドライバーとアプリケーションに追加のレイヤーを提供し、さらに一定のサウンド レイテンシーとすべてのクライアントの同期動作を保証します。 Jack は一度に 1 つのサウンド カードのみを使用でき、サウンド カードのオーディオ チャネルごとに個別の出力と入力を提供します。 さらに、Jack は、ケーブルを使用してさまざまなオーディオ機器を接続するのと同じ方法で、ハードウェア ストリームとソフトウェア ストリームの両方のオーディオ ストリームを表示、操作、またはパイプする機能を提供します。 たとえば、JAMin は、ストリームを別のオーディオ アプリケーションにエクスポートしたり、アナログ出力や S/PDIF 出力を通じてエクスポートしたりする前に、オーディオ ストリームをインターセプトできます。 Jack ユーザーが所有するデーモンは、通常 [1] を使用して開始されます。 qjackctl ユーティリティは、オーディオ ストリーム接続を含む他の多くの機能を提供します。

What Jack does not do, is handle A/52 encoded (AC-3 or Dolby/DTS) material on input; it is just a sound server that deal with separated channels of audio streams. And it has the capability to connect simultaneously and synchronously any output stream on any input, and any input to any output stream, that on any hardware and software audio component, and with a constant latency. This make JACK an outstanding tool for audio production and creation. The ac3jack tool can be used for encoding multiple separated audio channels to AC-3 streams.

When playing an A/52 encoded media, the player will request as many outputs from JACK than audio channels in the media. This will fail if your sound card doesn't have the requested amount of audio outputs, but will be fine otherwise. As example, you can use mplayer as usual, and configure it to output a 5.1 stream on a 7.1 output configuration, or a 7.1 stream on a 2 channels stereo output.

One solution is to configure your kernel and ALSA according to Jack installation instructions for providing low latency audio. Since ALSA is said to be already very efficient and low latency, providing very good quality playback with no additional mixing when stated within its .asoundrc file, unlike MS Windows, Jack probably isn't needed for most. The main audience of JACK is audio producers and musicians (in studio, live performances, DJ, ...). (The ac3jack package is currently hosted by the pro-audio overlay available with eselect-repository.)

It is possible to interconnect JACK and ALSA. At that time of writing, the best solution is via the snd-loopback module and zita-*2* bridge. For that, see Using an ALSA Loopback device and zita-ajbridge on the ProAudio Gentoo overlay wiki.

Using zita-ajbridge, it is also possible to add additional real sound cards into JACK. (Example needed)

Those who want to try JACK must know one thing: if you are happy with pulseaudio, you don't need to setup a realtime kernel for JACK. You will need rt operations only if you want to make a Digital Audio Workstation (DAW) with your computer, which necessitate something pulseaudio is not able to achieve: constant sound latencies as low or lower than 20 msec (pulseaudio is not able to provide constant sound latency at all), and synchronous operations. But if you want to make a DAW, JACK is definitely the way to go, and you will never look back.

Hopefully this small brief section about Jack will give some quick insight about Jack's features, while reserving the details of Jack to a Wiki page specifically focused on Jack.

In the meantime, you can take a look at the Pro-Audio Gentoo Overlay Wiki.

パーミッション

acl USE フラグがグローバルに有効化されていて、ログインデーモン (例えば、systemd-logind または elogind) が使用されている (つまり、システムが desktop プロファイルを使用している) 場合、サウンドカードに対するパーミッションは自動的に取り扱われます。getfacl を利用することでパーミッションを確認できます:

user $getfacl /dev/snd/controlC0 | grep larry
user:larry:rw-

より広い解決策は、サウンドカードにアクセスできるようにしたいユーザを audio グループに追加することです:

root #gpasswd -a larry audio
user $grep audio /etc/group
audio::18:larry
警告
alsamixer を動作させるためにはログアウトして再度ログインする必要があります。そうしないと、alsamixer コマンドを実行しても "cannot open mixer: No such file or directory" エラーが出力されるでしょう。

サービス

OpenRC

OpenRC を利用している場合は service コマンドを使って ALSA を開始してください:

root #rc-service alsasound start

ALSA をブート時に開始させるには、rc-update を使ってこれを boot ランレベルに追加してください。

root #rc-update add alsasound boot

systemd

systemd を利用している場合は、ALSA の状態は保存され、システム再起動時に自動で復元されます。

ALSA の状態は systemctl コマンドを使って確認できます:

root #systemctl status alsa-restore

ミキサー

何も聞こえないという場合、出力チャンネルがミュートされているかもしれません。デスクトップ環境のミキサーでチャンネルのミュートを解除するか、alsamixer で適切なチャンネルを選択して M キーを押すことでミュートとアンミュートを切り替えてください:

user $alsamixer

使い方

スピーカーをテストする

以上のすべてが完了したら、サウンドカードとスピーカーをテストできるようになっているはずです。media-sound/alsa-utils パッケージ(これは以前に推奨したもので既にインストールされているはずです)の speaker-test コマンドラインツール。

user $speaker-test -t wav -c 2

5.1 サラウンドサウンドシステムを使用する構成では:

user $speaker-test -t wav -c 6 -D surround51

テストを中止するには Ctrl+C を押してください。

マイクをテストする

If needed, select the audio device if no default one is provided and add the --device=hw:0,0 to the incantation of arecord, substituting the CardNumber,DeviceNumber in the integer fields.

次のコマンドは利用可能なデバイスを一覧表示します。

user $arecord --list-devices
メモ
You may also need to unmute the line or microphone channel. Open alsamixer and first select the sound card (i.e. F6), then press F4 to show the Capture Channels, "left/right cursor keys" to select the "Mic" channel and press Space to toggle CAPTURE the channel.

The following will record indefinitely until CTRL+C is depressed and provide a default 8000 Hz mono quality recording:

user $arecord /tmp/test.wav

The following will provide will record for two seconds (--duration=2) using DAT 48000 Hz quality (--format=dat) and display the curses vumeter in stereo (--vumeter=stereo) and save to /tmp/test.wav.

user $arecord --channels=1 --duration=2 --format=dat --vumeter=stereo /tmp/test.wav

Or optionally:

ファイル ~/.bashrc
# Simple convenience wrapper to record then play back a temporary sound file.
# Usage: arecord-mic duration
function arecord-mic {
    [[ $1 == *[![:digit:]]* ]] || return
    typeset tmpFile
    tmpFile=$(mktemp --suffix .wav) || return

typeset -a arecordOpts=(
        -c 1          # number of channels
        -D plughw:0,0 # device name
        -d "$1"       # duration
        -f S32_LE     # format
        -r 48000      # sample rate
        -V mono       # VU meter type
    )

arecord "${arecordOpts[@]}" -- "$tmpFile" && aplay -- "$tmpFile"
    rm -f -- "$tmpFile"
}

Notice, arecord cannot record in S24_LE, and is only capable of recording using S16_LE or S32_LE formats. For the human ear, any audio resolutions greater than 24 bit (S24_LE) or 48000Hz are said to be indistinguishable to differentiate using the human ear. Reference Sampling (signal processing) Wikipedia, Audio sampling. Users should also specify channels=1, as all recordings are performed in mono/monaural when typically using the Microphone Input unless recordings are using the stereo Line Input. In order to further encourage arecord to record monaural or only one channel, using the device=plughw:0,0 is further specified. (Alleviates a common problem, microphone/mic playback only occurs on the right or left channels.)

Use mplayer or aplay to playback the saved file. I usually record in "dat" or atleast "cd" quality formats. DAT is best when benchmarking.

ヒント

PaulBredbury の asoundrc ファイルにあるたくさんの構成オプションのどれかを試してみてください。

トラブルシューティング

.asoundrc をカスタマイズした状態で Firefox、Chromium、YouTube だけ音が鳴らない

Browsers are sometimes picky about ~/.asoundrc settings. If you're specifying the default audio device (likely given that most computers nowadays have an HDMI A/V output and the analog and HDMI audio outputs are viewed as two separate sound cards), try doing this specifically as follows:

ファイル ~/.asoundrc
defaults.pcm.card <number of your default sound card>
defaults.ctl.card <default sound card>
メモ
Since version 52, Firefox has made PulseAudio a hard requirement and dropped support for direct output to ALSA. To enable sound in these versions of Firefox enable the pulseaudio USE flag. See PulseAudio requirement breaks Firefox on ALSA-only systems. This limitation does not affect Firefox (version 52 only) built from sources (www-client/firefox). Chromium is also not immune to problem. Both browsers either depend on pulseaudio to set up correct sample rate or in absence of pulseaudio set sample rate to 48000 as defacto standard in sound card world. So if you have 96000 hz sample rate, downgrade it to 48000 and sound will work once again.

ひとつのアプリケーションからしかサウンドカードを利用できない

場合によっては、1 つのアプリが基本的にすべてのサウンド デバイスを引き継ぐことがあります。 これはパフォーマンス上の理由によるものである可能性もあります。

Force the use of dmix instead of direct audio output (which is what most things use by default, such as Adobe Flash [which really means the browser] and Wine).

デバイスがカード 1 とデバイス 7 の場合 (私の場合は Nvidia HDMI がこれに当てはまります):

ファイル ~/.asoundrc
pcm.dmixed {
    type asym
    playback.pcm {
        type dmix
        ipc_key 5678293
        ipc_perm 0660
        ipc_gid audio

        slave {
            channels 2 # Make 6 or 5.1 channel
            pcm {
                format S16_LE # S32_LE
                rate 48000 # Can also be 44100
                type hw
                card 1 # Your card
                device 7 # Your device
                subdevice 0 # Important?
            }

            period_size 1024
            buffer_size 8192
        }

        bindings {
            0 0
            1 1
# Uncomment below if using 6 channel
#           2 2
#           3 3
#           4 4
#           5 5
        }
    }
    capture.pcm "hw:0"
}

pcm.!default {
    type plug
    slave.pcm "dmixed"
}

Use of ~/.asoundrc is immediate and as long as you are not forcing the use of specific devices in any applications, they either will require a restart or will begin working immediately. One of the best tests is to run Chrome, go to YouTube, open a terminal, run mplayer with an audio or video file and see that you do not get an error about audio (such an error might be 'Device or resource busy').

Missing dialogue (sounds) with 4.0 speakers

If you're using a 4.0 sound card (like an old SB Live!) or 4.0 speakers in general, you may notice that in some games or movies the dialogues are very quiet or even missing. This is because most of those applications/movies support only either 2.0 (stereo) or 5.1 output. In order to achieve surround sound, the 5.1 audio track is used but the two excessive channels are discarded — the center channel (which usually carries dialogues) and subwoofer channel.

The above issue can be circumvented through creating a virtual device which will downmix 5.1 to 4.0, mixing the center and subwoofer channels with other audio channels.

ファイル ~/.asoundrc
pcm.downmix {
    type route

    slave {
        # The sound card output to be used
        pcm surround40
        # Real number of output channels
        channels 4
    }

# ttable.A.B G
# where A - input channel
#       B - output channel
#       G - volume gain (1.0 = original)

# Copy channels 0-3
    ttable.0.0 1
    ttable.1.1 1
    ttable.2.2 1
    ttable.3.3 1

# Mix channel 4 (center) into front speakers, and a bit (0.3) into rear ones
    ttable.4.0 1.0
    ttable.4.1 1.0
    ttable.4.2 0.3
    ttable.4.3 0.3

# Mix channel 5 (subwoofer) mostly (0.6) into rear speakers, and a bit (0.3) into front ones
    ttable.5.0 0.3
    ttable.5.1 0.3
    ttable.5.2 0.6
    ttable.5.3 0.6
}

ctl.downmix {
    type hw
    card 0
}

HDMI/SPDIF 5.1 and 7.1 speaker testing

It is stated ALSA's speaker-test utility will not test more then two channel audio over HDMI or SPDIF. For this, you need to use mplayer, as quoted from ALSA's documentation.

Download either a 5.1 channel (FLAC) or 7.1 channel (FLAC) speaker test file:

Play the provided sound file; specifying the HDMI or SPDIF device, PCM file, and number of channels which will likely be either 6 (for 5.1 surround) or 8 (for 7.1 channel surround).

For testing 5.1 channel with mplayer:

user $mplayer -channels 6 "/path/to/downloaded/flac_file.flac" -channels 6

For testing 7.1 channel:

user $mplayer -channels 8 "/path/to/downloaded/flac_file.flac" -channels 8
メモ
To test mplayer with a none default device, pass the additional option -ao alsa:device=hw=0.7 where the hw= value is aligned with the appropriate device.

Alternatively testing with VLC media player:

user $cvlc /path/to/downloaded/flac_file.flac

APlay SPDIF/HDMI output has incorrect speaker channels

Now that you know how to use MPlayer to play a speaker test PCM WAV file per "HDMI/SPDIF 5.1 and 7.1 Speaker Testing" above, you now find APlay doesn't output to the speaker channels properly when using SPDIF/HDMI. With HDMI, this is likely caused by the snd_hda_intel HDMI audio module/driver which is used by other manufacturers such as NVidia HDMI aside from just Intel's HDMI hardware. As to why MPlayer does use the correct channels, MPlayer is usually under constant development and manually corrects this issue?

Another problem this solution pertains to, trying to play a 24-bit PCM 2.0 or PCM5.1 WAV files and finding APlay constantly refuses to play the stream, due to incorrect bit rate, etc.

To correct this for ALSA (APlay) with minimal alterations to the PCM streams, we'll need to remap the speaker channels within a ${HOME}/.asoundrc file. Add the following to the bottom of your ${HOME}/.asoundrc file. Also note, the below configuration is for both 5.1 and 7.1 audio, or you could further map/copy the two extra channels to your 5.1 channels incase you do not want to omit the audio from a 7.1 stream.

ファイル .asoundrc
pcm.myHDMI {
    type plug
    slave {
        pcm "hw:1,7"
        format S32_LE
        channels 6
    }
    ttable {
        0.0= 1
        1.1= 1
        2.4= 1
        3.5= 1
        4.2= 1
        5.3= 1
        6.6= 1
        7.7= 1
    }
}

It seems that most HDMI to Stereo Receiver connections only stream 16 and 32 bit formats, skipping 24 bit. The above configuration up-mixes any PCM stream to 32 bit when using the pcm.myHDMI profile, as it is quite common to see PCM 2.0 and 5.1 24 bit audio files. It just doesn't seem right to down-mix everything to 16 bit, or use Float as the latter uses more processing power. (Users can also set an alias within their bashrc file for 16 bit or 24 bit incantations as well.)

Test the speaker routing using a surround test PCM file. (See the above previously mentioned "8 Channel Speaker Test".)

user $aplay -D my.HDMI 8Channel.wav

Weak center channel on PCM 5.1 live music

If you have a multi-channel sound track or music with an apparently weak center channel, and the sound track is a live recording; it is possible to map the center channel to the rear channels. Note, the rear channels on live recordings usually contain only the audiance screaming with very little music.

The following incantation of mplayer specifies; your HDMI device of hw:1.7, your PCM 5.1 file, number of channels, the format (not needed if your receiver can natively handle 24 bit and in my case I need to upmix as my Yamaha HDMI receiver can only natively handle 16 or 32 bit audio), and then the mapping. Mapping as follows; specify this is a 6 channel audio stream, with 6 mappings immediately following, copy left front channel to left speaker, copy right channel to right speaker, copy center channel to left rear speaker, copy center channel to right rear speaker, copy center channel to center speaker, and finally copy the subwoofer channel to the subwoofer speaker.

user $mplayer -ao alsa:device=hw=1.7 Music/MyAlbum/PCM51-24bit/01.MyMusic.wav -channels 6 -format s32le -af channels=6:6:0:0:1:1:4:2:4:3:4:4:5:5

See MPlayer's Channel manipulation.

Need to view more detailed information per ALSA stream?

If you need to look at an in-depth illustration of how your program is connecting to ALSA, use the /proc interface. You will need to substitute your relevant card/device details into the command below.

You should see a dump of information regarding the program and useful things like its sample rate(rate) and PID(owner_pid).

user $cat /proc/asound/card2/pcm0p/sub0/*
access: RW_INTERLEAVED
format: S16_LE
subformat: STD
channels: 2
rate: 44100 (44100/1)
period_size: 5513
buffer_size: 22050
card: 2
device: 0
subdevice: 0
stream: PLAYBACK
id: USB Audio
name: USB Audio
subname: subdevice #0
class: 0
subclass: 0
subdevices_count: 1
subdevices_avail: 0
state: RUNNING
owner_pid   : 934
trigger_time: 86393.193574796
tstamp      : 86540.250594985
delay       : 17714
avail       : 4602
avail_max   : 7379
-----
hw_ptr      : 6485052
appl_ptr    : 6502500
tstamp_mode: NONE
period_step: 1
avail_min: 5513
start_threshold: 2147483647
stop_threshold: 22050
silence_threshold: 0
silence_size: 0
boundary: 6206523236469964800

HTML5 does not play in a browser

If there is no sound in any browser used (Firefox, SeaMonkey, Otter Browser, etc.) and ALSA generally works, there is a workaround that might solve this particular issue: try removing the /etc/asound.conf file.

root #mv /etc/asound.conf /etc/asound.conf.old

Restart the browser and test the sound output for HTML5. It might just work now after applying this workaround.

HTML5 does not play in the Firefox browser

Some system motherboards (i.e. Asus Z87-EXPERT) cause Card 0 to be a MID device instead of a PCM device. The same driver module snd_hda_intel is used for both the MID and PCM cards on this motherboard. For some reason Firefox HTML 5 requires Card 0 of the snd_hda_intel no matter how you change it with asoundrc. You can make flash work using the asoundrc file, but HTML 5 audio is silent.

You must remap the PCM device in Linux as card 0 and remove the changes to asoundrc that were added to make Flash work. This wiki page indicates that you should compile the snd_hda_intel driver into the kernel. Using this configuration you must remap the card 0 and card 1 devices using boot parameters instead of a /etc/modprobe.d/alsa.conf file. For example the following kernel command line option will swap the MID and PCM card indicies so that the default card 0 is the PCM card:

snd-hda-intel.index=1,0

メモ
The module is named snd_hda_intel, but the boot parameter name is snd-hda-intel.

Laptops with HDMI audio output

Some laptops with an HDMI audio output will map /proc/asound/card0 as HDMI and therefore makes it default output device for applications as stated above in the Firefox section. Another way to remap is to add these two lines to /etc/modprobe.d/alsa.conf

ファイル /etc/modprobe.d/alsa.conf
# ここは実際のカード数に設定してください。
options snd cards_limit=2
options snd-hda-intel index=1,0

このコマンドを確認して、順序の変更を確認してください

user $cat /proc/asound/cards
 0 [PCH            ]: HDA-Intel - HDA Intel PCH
                      HDA Intel PCH at 0xf2534000 irq 45
 1 [HDMI           ]: HDA-Intel - HDA Intel HDMI
                      HDA Intel HDMI at 0xf2530000 irq 46

この方法は snd-hda-intel が、カーネル組み込みではなくモジュールとしてコンパイルされている場合のみ機能します

IPC semaphore - function not implemented

If you try to run the test procedure, and speaker-test returns an error about a function IPC semaphore not implemented, that is the option to activate in your Kernel :

カーネル
General setup --->
    [*] System V IPC

ヘッドホンジャックが機能しない

ヘッドセットジャックを機能させるために、オーディオドライバに追加のモデル情報を提供する必要がある場合があります。例えば、snd-hda-intel ドライバを利用する Dell Latitude E7470 ノートパソコンの場合は、/etc/modprobe.d/alsa.conf にこれを追加する必要があります:

ファイル /etc/modprobe.d/alsa.conf
options snd-hda-intel model=headset-mic

さらなる構成情報は Linux カーネルドキュメンテーションの Documentation/sound/hd-audio/models.rst で見つかります。

State restoring udev/alsactl errors on boot

Due to partitioning, encryption, or having a split /usr system, these errors may appear on boot:

root #journalctl -b | grep alsa
 
(udev-worker)[2594]: controlC2: Process '/usr/sbin/alsactl restore 2' failed with exit code 2.
 
(udev-worker)[2611]: controlC0: Process '/usr/sbin/alsactl restore 0' failed with exit code 2.
 
(udev-worker)[2579]: controlC1: Process '/usr/sbin/alsactl restore 1' failed with exit code 2.

To fix the issue, add TEST=="@sbindir@/alsactl" to the following lines of this file like so:

ファイル /lib/udev/rules.d/90-alsa-restore.rules
TEST!="/etc/alsa/state-daemon.conf", TEST=="@sbindir@/alsactl", RUN+="/usr/sbin/alsactl restore $attr{device/number}"
TEST=="/etc/alsa/state-daemon.conf", TEST=="@sbindir@/alsactl", RUN+="/usr/sbin/alsactl nrestore $attr{device/number}"

See these references for further details and discussion.[1][2]

関連項目

外部の情報

参照