Audio capturing using ALSA library - snd_pcm_open => No such file or directory
Asked Answered
L

2

8

I'm trying to implement audio capturing on a SoC using ALSA library. I've a precompiled libasound.so.2.0.0 a asoundlib.h together with other headers.

now I have

int returnCode;
snd_pcm_t *pcm_Handle;
char *pcm_device_name = "hw:0,0";

returnCode = snd_pcm_open(&pcm_Handle, pcm_device_name, SND_PCM_STREAM_CAPTURE, 0);

which returns snd_strerror(returnCode) of No such file or directory

Does this indicate that the capturing device isn't properly installed (e.g. drivers or something)?

How can I find out what's wrong/missing?

Can I list whether ANY alsa accessible sound device is installed?

UPDATE:

I found out how to scan for devices by: Finding available sound cards on Linux programmatically

snd_card_next finds a single cardNum : 0 but I still fail on snd_ctl_open(&cardHandle, "hw:0", 0) and snd_pcm_open(&pcm_Handle, "hw:0,0", SND_PCM_STREAM_CAPTURE, 0) with No such file or directory. Is that an indication for that the sound device isn't properly installed?

UPDATE::

I found some more information on http://www.tldp.org/HOWTO/Alsa-sound-4.html

"4.6 Preparing the devices There is a script in the driver-directory that will install the ALSA-sound-devices in your /dev directory. Type ./snddevices from the driver-directory. There should be a /dev/snd subdirectory now (test if it is there. If you are not familiar with even the "ls" command, please consider reading other HOWTO's first. You should have some basic Linux knowledge to install these drivers). Now you're ready to insert the driver, so please turn over to the next paragraph."

I remember that I've run a snddevices script that was provided with the SoC alsa version, but I wasnt sure whether it was successful or whether it just didn't show the errors. But the link says I'll have to install drivers afterwards? Unfortunately I can't test before tomorrow.

UPDATE:

From CL. and http://www.tldp.org/HOWTO/Alsa-sound-6.html I tested the following: dev/snd/ has the following entries:

crw-rw----    1 root     audio     116,   0 Mar 11 04:44 controlC0
crw-rw----    1 root     audio     116,  24 Mar 11 04:44 pcmC0D0c
crw-rw----    1 root     audio     116,  16 Mar 11 04:44 pcmC0D0p
crw-rw----    1 root     audio     116,  25 Mar 11 04:44 pcmC0D1c
crw-rw----    1 root     audio     116,  26 Mar 11 04:44 pcmC0D2c
crw-rw----    1 root     audio     116,  27 Mar 11 04:44 pcmC0D3c
crw-rw----    1 root     audio     116,  28 Mar 11 04:44 pcmC0D4c

where cat controlC0 cat pcmC0D0c and cat pcmC0D1c return cat: read error: File descriptor in bad state while the others return like cat: can't open 'pcmC0D2c': No such device

While cat /proc/asound/cards gives

 0 [VPL_AUDIO      ]: VPL AUDIO - VPL Audio TW2866 Driver
                      VPL Audio Codec Driver, TW2866.
 1 [Mozart_SSM2603 ]: I2S - I2S driver
                      I2S driver

Here is some more information. Since I'n not any experienced with audio, I don't know whether they are important or to help...

cat /proc/asound/pcm
00-00: tw2866#0 : VPL Audio TW2866 Driver : capture 1
00-01: tw2866#1 : VPL Audio TW2866 Driver : playback 1 : capture 1
01-00: I2S AIC23 PCM : I2S driver : playback 1 : capture 1
Loosetongued answered 13/10, 2015 at 17:7 Comment(7)
The snddevices script should not be necessary on any modern distribution. Have you access to the files in /dev/snd/?Indictment
@Indictment thank you for the interest. I can't say anything about whether the distribution is "modern". Since it is a system on a chip, the OS is limited to the absolute necessary parts and there really might be missing things. I had a similar problem with video capturing earlier, where some nodes were missing. In /dev/snd/ there are entries controlC0 pcmC0D0c pcmC0D0p pcmC0D1c pcmC0D2c pcmC0D3c pcmC0D4c each of them has a size of 116. If I try cat pcmC0D0c it tells me File descriptor in bad state, same for pcmC0D1c and controlC0 while the others return No such deviceLoosetongued
The "116" is not the size. Anyway, how did you install the other needed files of alsa-lib?Indictment
I just had the preocompiled library and the binary for that hardware platform. Some drivers might have been added by the guy who installed the OS on that platform. So basically I would have to find out which installation steps are missing from the current system state, if that is possible.Loosetongued
I just edited the question to add some more information of /proc/asound/cardsLoosetongued
So you do not have the files in /usr/share/alsa/?Indictment
that's right, folder /usr/share/alsa/ isn't existing. Which files should be there?Loosetongued
L
3

I had different version of the snddevices script. I had to use the right script int he right directory to get snd_pcm_open to work. I had to copy the script to the driver directory of the SoC.

I copied the .conf file to the same directory as in the reference implementation.

The bad file descriptor error message seems to be present if no capturing device is running. The capturing still doesn't work as of now.

Loosetongued answered 19/10, 2015 at 16:17 Comment(2)
I just faced the same issue with No such file or directory. Can you please a bit more explanation about how did you trace this issue?Bryannabryansk
sorry, afair I couldn't find a solution to capture audio, so I cancelled this project and it didn't get any new priority yet. Additionally, I can't remember details :-(Loosetongued
I
3

Your problem is that the alsa-lib package is not installed correctly (and it looks as if there is no package for your hardware).

To find out which files you need, get the alsa-lib source package, compile it, and install it into a temporary directory with

make install DESTDIR=/tmp/test

Then look into /tmp/test/; the compiled library file itself (libasound.so*) cannot be used if you didn't use the correct cross compiler, but the other files are text files suitable for any architecture.

Indictment answered 14/10, 2015 at 7:50 Comment(2)
Just have seen that there was a makefile for my cross-compiler and ALSA source code present. Using the cross-compiler will create 4 folders: bin include lib share. Is my assumption right that I should copy the content of the share folder (with subfolders alsa and aclocal) to my SoC usr/share` folder? Will I have to reboot it or sth?Loosetongued
Yes, but you don't need aclocal. You don't need to reboot.Indictment
L
3

I had different version of the snddevices script. I had to use the right script int he right directory to get snd_pcm_open to work. I had to copy the script to the driver directory of the SoC.

I copied the .conf file to the same directory as in the reference implementation.

The bad file descriptor error message seems to be present if no capturing device is running. The capturing still doesn't work as of now.

Loosetongued answered 19/10, 2015 at 16:17 Comment(2)
I just faced the same issue with No such file or directory. Can you please a bit more explanation about how did you trace this issue?Bryannabryansk
sorry, afair I couldn't find a solution to capture audio, so I cancelled this project and it didn't get any new priority yet. Additionally, I can't remember details :-(Loosetongued

© 2022 - 2024 — McMap. All rights reserved.