I'm attempting a barebones program to use tinyalsa, but pcm_start
always fails, returning -1
and setting errno
to 9
(EBADF
, i.e. bad file number). The call to pcm_open
before this returns a non-null pointer, but it sets errno
to 22
.
There appears to be no documentation for tinyalsa, so I'm having trouble understanding what I'm supposed to do. I based my program on an example from alsa (not tinyalsa), and I've read the header files for tinyalsa. Can anyone provide any guidance?
pcm * dev = pcm_open(1, 0, PCM_OUT, &config);
if (err = pcm_start(dev)) printf("err: %d\t errno: %d\n", err, errno);
(Full code available on pastebin.)
I infer the values for the first two arguments of pcm_open
from aplay --list-devices
, which outputs:
**** List of PLAYBACK Hardware Devices ****
card 1: PCH [HDA Intel PCH], device 0: ALC3232 Analog [ALC3232 Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
(I am compiling and running this on my workstation, not on an Android.)
I'm one of the maintainers for the TinyALSA project.
You should error check that code of yours.
This is how you would correctly check for a failure with the PCM structure:
And that should tell you why TinyALSA could not open your device.
If that doesn't help debug your problem, submit an issue on GitHub and include a link to the code, the error message after
pcm_open
, and a list of the directory contents in/dev/snd
.Also, the documentation on the API is definitely a work in progress. I included the bit about error checking
pcm_open
in the master branch. If you need further clarification on something, please create an issue for it!Thanks