4

I'm quite new to Linux (Lubuntu 12.04 for sake of precision) and ALSA programming at all. I'm trying to write a C program to capture audio from internal PC microphone for processing it. So as first step I google a bit and I found this article for capturing audio samples

A tutorial on using the ALSA Audio API

but when I compile it and execute it with:

./mycapture "default" or ./mycapture "hw:0,0" and all the possible variants on theme it always raises the error:

cannot open device hw:0,0 (no such file or directory).

So the issue is: what is the name of the mic audio device to pass as parameter to record the audio from mic ?

The mic is working ok because the Sound Recorder program records sounds perfectly and I can playback them.

The output of the aplay -l is the following :

**** 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

and this is the amixer output (cut)

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]

so for aplay it seems I have no recording device, but for amixer I've got the mic, a mic boost and mic stereo as well with all those gorgeous stuffs on their place !!. If so, how could my Sound Recorder record the audio without any problem at all ?!?!

For sure I'm giving the wrong device name to the command line for capturing audio but I'm loosing the hope for finding the correct one !

Please help....before I tear my hair out !!!

Randagio
  • 141
  • The default device should work; please show all error messages output by arecord test.wav. – CL. Oct 15 '12 at 21:34
  • arecord test.wav Recording WAVE 'test.wav' : Unsigned 8 bit, Rate 8000 Hz, Mono It seems recording fine. – Randagio Oct 17 '12 at 09:08
  • Then mycapture default should work as well. – CL. Oct 17 '12 at 09:43
  • Well, that's exactly what I supposed it should be, but it always returns the error: Cannot open device default: (no such file or directory) – Randagio Oct 17 '12 at 14:21
  • Please check that you are calling mycapture and arecord in exactly the same circumstances (same machine/user etc.). – CL. Oct 17 '12 at 15:13

1 Answers1

0

aplay -l lists playback devices. Use arecord -l.

The capture program works just fine after fixing the bugs (the third parameter to snd_pcm_hw_params_set_rate_near must be a pointer to the rate, and the size of buf must be doubled to have enough space for two channels).

CL.
  • 1,745
  • I can correctly record using arecord -l but this doesn't solve the problem: the objective is to write a C/C++ programs using ALSA API for capturing and processing audio samples in real-time and not to use another program to accomplish this task. – Randagio Oct 16 '12 at 08:21
  • What device are you using with arecord? default? – CL. Oct 16 '12 at 08:25
  • Actually I don't know wich device arecord is using. I just launch it and it works fine. On the othe side "my" capture program does't work with 'default' nor 'hw:0,0' but I'm not yet fixed the bugs you pointed out. I hope they're the problem. – Randagio Oct 16 '12 at 13:45