Audio

啟用 ALSA 以從 CS4207 的 SPDIF 輸入擷取音頻

  • October 28, 2020

在使用 Congatec 的SA5 模組和附加的CS4207 HDA 編解碼器的自定義平台上,我正在嘗試使用編解碼器數字 SPDIF 輸入和輸出。HDA 設計是從 Congatec 的conga-SEVAL評估板上複製而來的。

SPDIF 輸出(連接到放大器)開箱即用 - 這裡沒有問題。

但是 SPDIF 輸入(需要記錄信號)讓我有些頭疼。

在測試期間,我使用的是 Xubuntu 20.04

Linux Test-01 5.4.0-48-generic #52-Ubuntu SMP Thu Sep 10 10:58:49 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

稍後我們將在 buildroot 中實現這些功能。

到目前為止我所做的

通過使用hda_analyser.py工具,我可以看到預設情況下 SPDIF 輸入小元件是禁用的。手動啟用它們對結果沒有影響:

# Node 0x07 SPDIF Reciver Input Converter - Enable
hda-verb /dev/snd/hwC0D0 0x07 0x70d 0x01
# Node 0x0f SPDIF Reciver Input Pin - Enable
hda-verb /dev/snd/hwC0D0 0x0f 0x707 0x20

當我向 SPDIF 輸入提供信號時,hda_analyser 顯示信號的有效標誌和控製字內容。所以我認為來源很好。 hda_analyser 沒有和有有效信號

通過手動啟用 CS4207 的“SPDIF RX to TX1 loopthru”功能:

# Enable Rx to Tx1 Loopthru
hda-verb /dev/snd/hwC0D0 0x11 0x0500 0x01 && hda-verb /dev/snd/hwC0D0 0x11 0x0400 0x402a

我也能聽到從連接到 SPDIF 輸出的揚聲器饋入 SPDIF 輸入的信號。

-> 所以我的結論是硬體部分應該沒問題。

在 ALSA 方面,我認為存在配置問題,因為未列出 IEC958 數字擷取設備。但那是我無法理解的部分。有很多配置路徑 ( /usr/share/pulseaudio/alsa-mixer/ /etc/alsa/conf.d/ /usr/share/alsa/),甚至更多帶有佔位符的配置模板似乎被其他東西填充。但是我沒有找到一種方法來找出有效使用的配置。

在 ALSA 文件中也找不到任何提示。

的輸出aplay -l

**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: CS4207 Analog [CS4207 Analog]
 Subdevices: 1/1
 Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 1: CS4207 Digital [CS4207 Digital]
 Subdevices: 1/1
 Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 3: HDMI 0 [HDMI 0]
 Subdevices: 1/1
 Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 7: HDMI 1 [HDMI 1]
 Subdevices: 1/1
 Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 8: HDMI 2 [HDMI 2]
 Subdevices: 1/1
 Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 9: HDMI 3 [HDMI 3]
 Subdevices: 1/1
 Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 10: HDMI 4 [HDMI 4]
 Subdevices: 1/1
 Subdevice #0: subdevice #0

輸出arecord -l(此處未列出數字輸入):

**** List of CAPTURE Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: CS4207 Analog [CS4207 Analog]
 Subdevices: 1/1
 Subdevice #0: subdevice #0

輸出pacmd list-cards

1 card(s) available.
   index: 0
       name: <alsa_card.pci-0000_00_0e.0>
       driver: <module-alsa-card.c>
       owner module: 7
       properties:
               alsa.card = "0"
               alsa.card_name = "HDA Intel PCH"
               alsa.long_card_name = "HDA Intel PCH at 0x91410000 irq 143"
               alsa.driver_name = "snd_hda_intel"
               device.bus_path = "pci-0000:00:0e.0"
               sysfs.path = "/devices/pci0000:00/0000:00:0e.0/sound/card0"
               device.bus = "pci"
               device.vendor.id = "8086"
               device.vendor.name = "Intel Corporation"
               device.product.id = "5a98"
               device.product.name = "Celeron N3350/Pentium N4200/Atom E3900 Series Audio Cluster"
               device.form_factor = "internal"
               device.string = "0"
               device.description = "Built-in Audio"
               module-udev-detect.discovered = "1"
               device.icon_name = "audio-card-pci"
       profiles:
               input:analog-stereo: Analog Stereo Input (priority 65, available: unknown)
               output:analog-stereo: Analog Stereo Output (priority 6500, available: unknown)
               output:analog-stereo+input:analog-stereo: Analog Stereo Duplex (priority 6565, available: unknown)
               output:iec958-stereo: Digital Stereo (IEC958) Output (priority 5500, available: unknown)
               output:iec958-stereo+input:analog-stereo: Digital Stereo (IEC958) Output + Analog Stereo Input (priority 5565, available: unknown)
               output:hdmi-stereo: Digital Stereo (HDMI) Output (priority 5900, available: no)
               output:hdmi-stereo+input:analog-stereo: Digital Stereo (HDMI) Output + Analog Stereo Input (priority 5965, available: no)
               output:hdmi-surround: Digital Surround 5.1 (HDMI) Output (priority 800, available: no)
               output:hdmi-surround+input:analog-stereo: Digital Surround 5.1 (HDMI) Output + Analog Stereo Input (priority 865, available: no)
               output:hdmi-surround71: Digital Surround 7.1 (HDMI) Output (priority 800, available: no)
               output:hdmi-surround71+input:analog-stereo: Digital Surround 7.1 (HDMI) Output + Analog Stereo Input (priority 865, available: no)
               output:hdmi-stereo-extra1: Digital Stereo (HDMI 2) Output (priority 5700, available: no)
               output:hdmi-stereo-extra1+input:analog-stereo: Digital Stereo (HDMI 2) Output + Analog Stereo Input (priority 5765, available: no)
               output:hdmi-surround-extra1: Digital Surround 5.1 (HDMI 2) Output (priority 600, available: no)
               output:hdmi-surround-extra1+input:analog-stereo: Digital Surround 5.1 (HDMI 2) Output + Analog Stereo Input (priority 665, available: no)
               output:hdmi-surround71-extra1: Digital Surround 7.1 (HDMI 2) Output (priority 600, available: no)
               output:hdmi-surround71-extra1+input:analog-stereo: Digital Surround 7.1 (HDMI 2) Output + Analog Stereo Input (priority 665, available: no)
               output:hdmi-stereo-extra2: Digital Stereo (HDMI 3) Output (priority 5700, available: no)
               output:hdmi-stereo-extra2+input:analog-stereo: Digital Stereo (HDMI 3) Output + Analog Stereo Input (priority 5765, available: no)
               output:hdmi-surround-extra2: Digital Surround 5.1 (HDMI 3) Output (priority 600, available: no)
               output:hdmi-surround-extra2+input:analog-stereo: Digital Surround 5.1 (HDMI 3) Output + Analog Stereo Input (priority 665, available: no)
               output:hdmi-surround71-extra2: Digital Surround 7.1 (HDMI 3) Output (priority 600, available: no)
               output:hdmi-surround71-extra2+input:analog-stereo: Digital Surround 7.1 (HDMI 3) Output + Analog Stereo Input (priority 665, available: no)
               output:hdmi-stereo-extra3: Digital Stereo (HDMI 4) Output (priority 5700, available: no)
               output:hdmi-stereo-extra3+input:analog-stereo: Digital Stereo (HDMI 4) Output + Analog Stereo Input (priority 5765, available: no)
               output:hdmi-surround-extra3: Digital Surround 5.1 (HDMI 4) Output (priority 600, available: no)
               output:hdmi-surround-extra3+input:analog-stereo: Digital Surround 5.1 (HDMI 4) Output + Analog Stereo Input (priority 665, available: no)
               output:hdmi-surround71-extra3: Digital Surround 7.1 (HDMI 4) Output (priority 600, available: no)
               output:hdmi-surround71-extra3+input:analog-stereo: Digital Surround 7.1 (HDMI 4) Output + Analog Stereo Input (priority 665, available: no)
               output:hdmi-stereo-extra4: Digital Stereo (HDMI 5) Output (priority 5700, available: no)
               output:hdmi-stereo-extra4+input:analog-stereo: Digital Stereo (HDMI 5) Output + Analog Stereo Input (priority 5765, available: no)
               output:hdmi-surround-extra4: Digital Surround 5.1 (HDMI 5) Output (priority 600, available: no)
               output:hdmi-surround-extra4+input:analog-stereo: Digital Surround 5.1 (HDMI 5) Output + Analog Stereo Input (priority 665, available: no)
               output:hdmi-surround71-extra4: Digital Surround 7.1 (HDMI 5) Output (priority 600, available: no)
               output:hdmi-surround71-extra4+input:analog-stereo: Digital Surround 7.1 (HDMI 5) Output + Analog Stereo Input (priority 665, available: no)
               off: Off (priority 0, available: unknown)
       active profile: <output:analog-stereo+input:analog-stereo>
       sinks:
               alsa_output.pci-0000_00_0e.0.analog-stereo/#0: Built-in Audio Analog Stereo
       sources:
               alsa_output.pci-0000_00_0e.0.analog-stereo.monitor/#0: Monitor of Built-in Audio Analog Stereo
               alsa_input.pci-0000_00_0e.0.analog-stereo/#1: Built-in Audio Analog Stereo
       ports:
               analog-input-mic: Microphone (priority 8700, latency offset 0 usec, available: no)
                       properties:
                               device.icon_name = "audio-input-microphone"
               analog-input-linein: Line In (priority 8100, latency offset 0 usec, available: yes)
                       properties:

               analog-output-lineout: Line Out (priority 9000, latency offset 0 usec, available: no)
                       properties:

               analog-output-speaker: Speakers (priority 10000, latency offset 0 usec, available: unknown)
                       properties:
                               device.icon_name = "audio-speakers"
               analog-output-headphones: Headphones (priority 9900, latency offset 0 usec, available: no)
                       properties:
                               device.icon_name = "audio-headphones"
               iec958-stereo-output: Digital Output (S/PDIF) (priority 0, latency offset 0 usec, available: unknown)
                       properties:

               hdmi-output-0: HDMI / DisplayPort (priority 5900, latency offset 0 usec, available: no)
                       properties:
                               device.icon_name = "video-display"
               hdmi-output-1: HDMI / DisplayPort 2 (priority 5800, latency offset 0 usec, available: no)
                       properties:
                               device.icon_name = "video-display"
               hdmi-output-2: HDMI / DisplayPort 3 (priority 5700, latency offset 0 usec, available: no)
                       properties:
                               device.icon_name = "video-display"
               hdmi-output-3: HDMI / DisplayPort 4 (priority 5600, latency offset 0 usec, available: no)
                       properties:
                               device.icon_name = "video-display"
               hdmi-output-4: HDMI / DisplayPort 5 (priority 5500, latency offset 0 usec, available: no)
                       properties:
                               device.icon_name = "video-display"

引起我注意的另一件事是/usr/share/pulseaudio/alsa-mixer/paths/analog-input.conf.common

;  We explicitly don't want to wrap the following sources:
;
;       CD
[...]
;       Digital/SPDIF

現在怎麼辦

那麼有沒有一種簡單的方法可以簡單地啟用 IEC958 擷取設備?

我在哪里或如何獲得目前有效的 alsa 配置以進行修改?

–> 看到這個答案

編輯

CS4207 編解碼器的 SPDIF-In 功能在核心 3.5 和 3.8 之間的某個地方失去了。在此期間,對patch_cirrus.c進行了重大重構。

因此,即使我將 IEC958 輸入的 ALSA 控制項(從核心 3.5 的預設配置複製)添加到目前核心的配置中:

   control.67 {
       iface MIXER
       name 'IEC958 Capture Switch'
       value false
       comment {
           access 'read write'
           type BOOLEAN
           count 1
       }
   }
   control.68 {
       iface MIXER
       name 'IEC958 Capture Default'
       value '0400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
       comment {
           access read
           type IEC958
           count 1
       }
   }

我得到回報:

Found hardware: "HDA-Intel" "Cirrus Logic CS4207" "HDA:10134207,10134207,00100302 HDA:8086280a,80860101,00100000" "0x8086" "0x7270"
Hardware is initialized using a generic method
alsactl: set_control:1325: failed to obtain info for control #67 (No such file or directory)
alsactl: set_control:1325: failed to obtain info for control #68 (No such file or directory)

所以看起來 hda-driver 沒有向系統提供 SPDIF 輸入。因此,問題不再與 ALSA 配置有關,而是與 hda-driver 相關。

使 SPDIF-In 可用

主要問題是 snd_hda 框架目前只支持1 個數字輸入引腳,而 CS4207 有 3 個。

在解析編解碼器引腳期間,它們三個都通過循環,最後一個獲勝並呈現給 ALSA。訣竅是沒有任何配置連接的引腳會在循環中被跳過

通常引腳配置由 BIOS 設置。由於我們不控制此設置中的 BIOS,因此這不是一個選項。

另一種選擇是使用更新檔文件設置管腳配置(如“早期更新檔”部分所述)

為此,在這種情況下,我需要引腳節點 ID0x0E0x12並讀取它們目前的引腳配置:

# hda-verb /dev/snd/hwC0D0 0x0e GET_CONFIG_DEFAULT 0x00
nid = 0xe, verb = 0xf1c, param = 0x0
value = 0xb7d6003e
# hda-verb /dev/snd/hwC0D0 0x12 GET_CONFIG_DEFAULT 0x00
nid = 0x12, verb = 0xf1c, param = 0x0
value = 0xb7d6005e

選擇

# cat /sys/class/sound/hwC0D0/init_pin_configs
0x09 0x022140f0
0x0a 0x010140f0
0x0b 0x901700f0
0x0c 0x01813051
0x0d 0x01a19031
0x0e 0xb7d6003e
0x0f 0x02c4e0f0
0x10 0x014460f0
0x12 0xb7d6005e
0x15 0x014510f0

然後將配置中的前 2 位更改為“無連接”(01)。配置位的含義記錄在HDA 規範 7.3.3.31 Configuration Default中。

所以0x0e 0xb7d6003e->0x0e 0x77d6003e0x12 0xb7d6005e-> 0x12 0xb7d6005e

/lib/firmware/patch_cs4207使用這些值可以創建一個更新檔文件,例如具有以下內容:

[codec]
0x10134207 0x10134207 0

[pincfg]
0x0e 0x77d6003e
0x12 0x77d6005e

在下面

$$ codec $$需要列出 vendor_id、subsystem_id 和地址。 之後,更新檔文件需要由 snd_hda_intel 載入。為此,需要將以下行添加到/etc/modprobe.d/alsa-base.conf

options snd-hda-intel patch=patch_cs4207

重新啟動後,無需進一步調整 ALSA,並且 SPDIF-In 被辨識:

# arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: CS4207 Analog [CS4207 Analog]
 Subdevices: 1/1
 Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 1: CS4207 Digital [CS4207 Digital]
 Subdevices: 0/1
 Subdevice #0: subdevice #0

有關其他(與 ALSA 無關的)問題,請參閱原​​始文章中的 EDIT

回答關於 ALSA 配置的原始問題:

看來這alsa-info也是最好的地方。

根據該腳本,您可以通過以下方式保存目前有效的 ALSA 確認:

alsactl -f /tmp/alsa-config.txt store

之後可以在文件中更改配置(在這種情況下/tmp/alsa-config.txt),並且可以通過以下方式恢復配置

alsactl -f /tmp/alsa-config.txt restore

此外,目前有效的 ALSA 配置預設儲存在

/var/lib/alsa/asound.state

引用自:https://unix.stackexchange.com/questions/612626