Ubuntu音频设备检测
Linux Audio Stack
早期使用OSS(开放声音系统, Open Sound System),随后ALSA (高级Linux声音体系,Advanced Linux Sound Architecture)代替了OSS。鉴于ALSA无法共用设备,现代多数Ubuntu Desktop发行版底层使用ALSA,将Pulse Audio作为管理音频的服务来共享音频设备,APP通过Pulse Audio API使用设备。
http://pc-freak.net/images/how-to-boost-increase-sound-in-linux-audio-stack-illustrated.png查看音频设备
ALSA提供了一个alsa-utils
包,其含有arecord
、aplay
等工具来查看音频设备信息。
首先,查看系统的音频设备。如下,可以看到当前有两张卡:
-
0: 系统自带的HDA Intel PCH声卡
-
1: 外接的USB Camera-B4.09.24.1(PS3 EYE摄像头和麦克风阵列)
$ cat /proc/asound/cards 0 [PCH ]: HDA-Intel - HDA Intel PCH HDA Intel PCH at 0xdf120000 irq 126 1 [CameraB409241 ]: USB-Audio - USB Camera-B4.09.24.1 USB Camera-B4.09.24.1 at usb-0000:00:14.0-6, high speed
查看音频输入
通过arecord
命令可以看到,当前有两张音频输入卡,说明两张音频设备都有麦克风输入功能:
-
card 0: 系统自带的HDA Intel PCH声卡
-
card 1: 外接的USB Camera-B4.09.24.1(PS3 EYE摄像头和麦克风阵列)
$ arecord -l **** List of CAPTURE Hardware Devices **** card 0: PCH [HDA Intel PCH], device 0: ALC662 rev3 Analog [ALC662 rev3 Analog] Subdevices: 1/1 Subdevice #0: subdevice #0 card 0: PCH [HDA Intel PCH], device 2: ALC662 rev3 Alt Analog [ALC662 rev3 Alt Analog] Subdevices: 1/1 Subdevice #0: subdevice #0 card 1: CameraB409241 [USB Camera-B4.09.24.1], device 0: USB Audio [USB Audio] Subdevices: 1/1 Subdevice #0: subdevice #0
查看音频输出
通过aplay
命令可以看到,当前只有一张音频输出卡(card 0),说明另一张音频设备USB Camera-B4.09.24.1不带有音频输出功能。
$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC662 rev3 Analog [ALC662 rev3 Analog]
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
检测音频设备-使用alsa-utils
这里使用alsa-utils
的工具来检测音频设备。
检测音频输出
可以使用speaker-test
或aplay
。
-
使用
speaker-test
测试默认音频输出(alsa-utils安装包已包含测试用的几个短wav音频),其默认使用的输出设备可能通过aplay -L
查看$ aplay -L default Playback/recording through the PulseAudio sound server null Discard all samples (playback) or generate zero samples (capture) pulse PulseAudio Sound Server sysdefault:CARD=PCH HDA Intel PCH, ALC662 rev3 Analog Default Audio Device front:CARD=PCH,DEV=0 HDA Intel PCH, ALC662 rev3 Analog Front speakers surround21:CARD=PCH,DEV=0 HDA Intel PCH, ALC662 rev3 Analog 2.1 Surround output to Front and Subwoofer speakers surround40:CARD=PCH,DEV=0 HDA Intel PCH, ALC662 rev3 Analog 4.0 Surround output to Front and Rear speakers surround41:CARD=PCH,DEV=0 HDA Intel PCH, ALC662 rev3 Analog 4.1 Surround output to Front, Rear and Subwoofer speakers surround50:CARD=PCH,DEV=0 HDA Intel PCH, ALC662 rev3 Analog 5.0 Surround output to Front, Center and Rear speakers surround51:CARD=PCH,DEV=0 HDA Intel PCH, ALC662 rev3 Analog 5.1 Surround output to Front, Center, Rear and Subwoofer speakers surround71:CARD=PCH,DEV=0 HDA Intel PCH, ALC662 rev3 Analog 7.1 Surround output to Front, Center, Side, Rear and Woofer speakers hdmi:CARD=PCH,DEV=0 HDA Intel PCH, HDMI 0 HDMI Audio Output dmix:CARD=PCH,DEV=0 HDA Intel PCH, ALC662 rev3 Analog Direct sample mixing device dsnoop:CARD=PCH,DEV=0 HDA Intel PCH, ALC662 rev3 Analog Direct sample snooping device hw:CARD=PCH,DEV=0 HDA Intel PCH, ALC662 rev3 Analog Direct hardware device without any conversions plughw:CARD=PCH,DEV=0 HDA Intel PCH, ALC662 rev3 Analog Hardware device with all software conversions
-
使用
aplay
指定测试音频来测试,例如aplay test.wav -D plughw:CARD=PCH,DEV=0
检测音频输入
使用arecord
录制音频输入
-
-f 表示音频格式。
cd (16 bit little endian, 44100, stereo)
-
-d 录制几秒
-
-c 几个通道,如录制4个麦的麦克风阵列:
-c 4
-
-D 使用ALSA的哪个设备:
-D hw:1,0
表示使用card 0
下的device 0
设备arecord -f cd -d 5 -c 4 -D hw:1,0 > a.pcm
使用aplay
测试
aplay a.pcm
检测音频设备-使用pavucontrol
PulseAudio提供一个GUI的工具pavucontrol
(PulseAudio Volume Control)来配置与控制音频设备。
检测声卡支持的最高输入采样频率
要录制指定采样频率、采样位宽的音频,需要声卡设备与其驱动都支持。下文说明如何检测Linux驱动所加载的音频设备当前能录制的最高采样频率。
arecord
列出系统当前所加载的音频输入设备。如下,card 0
是Intel集成声卡,card 1
是一个USB麦克风:
$ arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC662 rev3 Analog [ALC662 rev3 Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 2: ALC662 rev3 Alt Analog [ALC662 rev3 Alt Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: CameraB409241 [USB Camera-B4.09.24.1], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
这里拿card 1
的device 0
做测试,命令中使用一个比较高的,如-r 60000
:
$ arecord -f S16_LE -r 60000 -D hw:1,0 -d 5 test.wav
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 60000 Hz, Stereo
Warning: rate is not accurate (requested = 60000Hz, got = 16000Hz)
please, try the plug plugin (-Dplug:hw:0,0)
Aborted by signal Interrupt...
如上,命令中断,并提示所指定的设备只支持最高16000Hz的采样率。
Audacity
通过Audacity查看录制音频的Spectrogram(Audio Track -> Spectrogram
),可以检测所录音频的采样率。
在Audacity中配置使用高采样率录制音频(如48000Hz),然后查看音频的Spectrogram。如下,可以看到音频高于8k区域的能量为0,说明音频录制的采样率只有16k。
1563537080712