ALSA 样本捕获:无法打开设备

ALSA 样本捕获:无法打开设备

我对 Linux(为了准确起见,使用的是 Lubuntu 12.04)和 ALSA 编程还很陌生。我正在尝试编写一个 C 程序来捕获 PC 内置麦克风的音频并进行处理。因此,我首先在 Google 上搜索了一下,找到了这篇关于捕获音频样本的文章

关于使用 ALSA 音频 API 的教程

但是当我编译它并执行它时:

./mycapture "default"或者./mycapture "hw:0,0"以及主题上所有可能的变体总是会引发错误:

无法打开设备 hw:0,0(没有此文件或目录)

所以问题是:作为参数传递以从麦克风录制音频的麦克风音频设备的名称是什么?

麦克风工作正常,因为录音机程序可以完美地录制声音,我可以播放它们。

的输出aplay -l如下:

**** List of PLAYBACK Hardware Devices ****
card 0: I82801DBICH4 [Intel 82801DB-ICH4], device 0: Intel ICH [Intel 82801DB-ICH4]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: I82801DBICH4 [Intel 82801DB-ICH4], device 4: Intel ICH - IEC958 [Intel 82801DB-ICH4 - IEC958]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

这是 amixer 的输出(剪切)

Simple mixer control 'Master',0
  Capabilities: pvolume pswitch penum
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 31
  Mono:
  Front Left: Playback 31 [100%] [0.00dB] [on]
  Front Right: Playback 31 [100%] [0.00dB] [on]
Simple mixer control 'Master Mono',0
  Capabilities: pvolume pvolume-joined pswitch pswitch-joined penum
  Playback channels: Mono
  Limits: Playback 0 - 31
  Mono: Playback 4 [13%] [-40.50dB] [on]
Simple mixer control 'PCM',0
  Capabilities: pvolume pswitch penum
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 31
  Mono:
  Front Left: Playback 31 [100%] [12.00dB] [on]
  Front Right: Playback 31 [100%] [12.00dB] [on]
Simple mixer control 'CD',0
  Capabilities: pvolume pswitch cswitch cswitch-exclusive penum
  Capture exclusive group: 0
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: Playback 0 - 31
  Front Left: Playback 0 [0%] [-34.50dB] [off] Capture [off]
  Front Right: Playback 0 [0%] [-34.50dB] [off] Capture [off]
Simple mixer control 'Mic',0
  Capabilities: pvolume pvolume-joined pswitch pswitch-joined cswitch cswitch-exclusive penum
  Capture exclusive group: 0
  Playback channels: Mono
  Capture channels: Front Left - Front Right
  Limits: Playback 0 - 31
  Mono: Playback 22 [71%] [-1.50dB] [on]
  Front Left: Capture [on]
  Front Right: Capture [on]
Simple mixer control 'Mic Boost (+20dB)',0
  Capabilities: pswitch pswitch-joined penum
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'Mic Select',0
  Capabilities: enum
  Items: 'Mic1' 'Mic2'
  Item0: 'Mic1'
Simple mixer control 'Stereo Mic',0
  Capabilities: pswitch pswitch-joined penum
  Playback channels: Mono
  Mono: Playback [off]

所以对于 aplay 来说,我似乎没有录音设备,但对于 amixer,我有麦克风、麦克风增强器和麦克风立体声,以及所有这些华丽的东西!!。如果是这样,我的录音机如何能够毫无问题地录制音频?!?!

可以肯定的是,我向用于捕获音频的命令行提供了错误的设备名称,但我失去了找到正确设备的希望!

请帮帮我...在我扯掉头发之前!!!

答案1

aplay -l列表回放设备。使用arecord -l

修复错误后,捕获程序就可以正常工作了(的第三个参数必须snd_pcm_hw_params_set_rate_near是指向速率的指针,并且的大小buf必须加倍才能有足够的空间容纳两个通道)。

相关内容