![如何使用 snd_pcm_open 打开线路或麦克风](https://linux22.com/image/211696/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%20snd_pcm_open%20%E6%89%93%E5%BC%80%E7%BA%BF%E8%B7%AF%E6%88%96%E9%BA%A6%E5%85%8B%E9%A3%8E.png)
我正在 Raspberry Pi 上编写连接到ICUSBAUDIO7D 用于捕获的设备。到目前为止,当我传入“默认”作为路径时,我已经成功地进行了交谈
r = snd_pcm_open(&_pcm, "default",
SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK);
我能够捕捉音频,
我已经在/usr/share/alsa/alsa.conf中定义了
defaults.ctl.card 1
defaults.pcm.card 1
但我想做的是能够选择线路或麦克风的输入。
看着 amixer 我看到了
Simple mixer control 'Speaker',0
Capabilities: pvolume pswitch pswitch-joined
Playback channels: Front Left - Front Right - Rear Left - Rear Right - Front Center - Woofer - Side Left - Side Right
Limits: Playback 0 - 197
Mono:
Front Left: Playback 0 [0%] [-36.93dB] [on]
Front Right: Playback 0 [0%] [-36.93dB] [on]
Rear Left: Playback 90 [46%] [-20.06dB] [on]
Rear Right: Playback 90 [46%] [-20.06dB] [on]
Front Center: Playback 90 [46%] [-20.06dB] [on]
Woofer: Playback 90 [46%] [-20.06dB] [on]
Side Left: Playback 0 [0%] [-36.93dB] [on]
Side Right: Playback 0 [0%] [-36.93dB] [on]
Simple mixer control 'PCM',0
Capabilities: cvolume cswitch cswitch-joined
Capture channels: Front Left - Front Right
Limits: Capture 0 - 6928
Front Left: Capture 4096 [59%] [-0.01dB] [on]
Front Right: Capture 4096 [59%] [-0.01dB] [on]
Simple mixer control 'PCM Capture Source',0
Capabilities: enum
Items: 'Mic' 'Line' 'IEC958 In' 'Mixer'
Item0: 'Line'
Simple mixer control 'Line',0
Capabilities: pvolume cvolume pswitch pswitch-joined cswitch cswitch-joined
Playback channels: Front Left - Front Right
Capture channels: Front Left - Front Right
Limits: Playback 0 - 8065 Capture 0 - 6928
Front Left: Playback 8065 [100%] [7.50dB] [off] Capture 4096 [59%] [-0.01dB] [on]
Front Right: Playback 8065 [100%] [7.50dB] [off] Capture 4096 [59%] [-0.01dB] [on]
Simple mixer control 'Mic',0
Capabilities: pvolume cvolume pswitch pswitch-joined cswitch cswitch-joined
Playback channels: Front Left - Front Right
Capture channels: Front Left - Front Right
Limits: Playback 0 - 8065 Capture 0 - 6928
Front Left: Playback 6144 [76%] [-0.01dB] [off] Capture 4096 [59%] [-0.01dB] [on]
Front Right: Playback 6144 [76%] [-0.01dB] [off] Capture 4096 [59%] [-0.01dB] [on]
Simple mixer control 'IEC958 In',0
Capabilities: cswitch cswitch-joined
Capture channels: Mono
Mono: Capture [on]
但当我这样做时
arecord -L
null
Discard all samples (playback) or generate zero samples (capture)
default
Default Audio Device
sysdefault
Default Audio Device
duplicate
hw:CARD=ICUSBAUDIO7D,DEV=0
ICUSBAUDIO7D, USB Audio
Direct hardware device without any conversions
plughw:CARD=ICUSBAUDIO7D,DEV=0
ICUSBAUDIO7D, USB Audio
Hardware device with all software conversions
default:CARD=ICUSBAUDIO7D
ICUSBAUDIO7D, USB Audio
Default Audio Device
sysdefault:CARD=ICUSBAUDIO7D
ICUSBAUDIO7D, USB Audio
Default Audio Device
front:CARD=ICUSBAUDIO7D,DEV=0
ICUSBAUDIO7D, USB Audio
Front output / input
dsnoop:CARD=ICUSBAUDIO7D,DEV=0
ICUSBAUDIO7D, USB Audio
Direct sample snooping device
amixer -c 1 scontrols
Simple mixer control 'Speaker',0
Simple mixer control 'PCM',0
Simple mixer control 'PCM Capture Source',0
Simple mixer control 'Line',0
Simple mixer control 'Mic',0
Simple mixer control 'IEC958 In',0
我并不真正将麦克风或线路视为一种设备..所以我在这里很困惑如何以编程方式选择一个或另一个?
有人可以给我提供线索吗?非常感谢。