Is there any way to get the PCM handles for ALSA devices?

https://lemmy.world/post/44415563

Is there any way to get the PCM handles for ALSA devices? - Lemmy.World

All the tutorials I can find is just telling me to jUSt UsE tHe DefAUltS (or even to use SDL or some similar library instead of my own solution), but some more advanced features such as getting HD rumble working on controllers with such features would require to connect to select devices. So far I’ve tried: - using library functions, but they give weird results for some reason. - reading the contents of /proc/asound/cards, which supposed to work and contains some very useful addresses, but not the PCM handles themselves. Unfortunately, 99% of my search results is about how to configure ALSA to be used in Linux, which is obviously not what I need.

The way is to use the appropriate ALSA library functions as mentioned in the associated docs, and see referenced examples for an outline how the flow is authoritatively supposed to look like, right from the tap.

Please elaborate “weird results for some reason” with minimal examples, as in “this is what I get running this code, and that is what I expected”. More often than not, the process of writing up your problems for external review leads to understanding, or at least to a couple good ideas what you might be doing wrong, or expecting to work differently.

The ALSA API is dense, and very C. It’s super-easy to make wrong assumptions about how things should work there. Great training for slogging through API docs, though. :)

ALSA project - the C library reference: PCM Interface

name ASCII identifier of the PCM handle

What does this mean exactly?

With “pcm” as the iface parameter in snd_device_name_hint() this should not happen. Did you check out and pilfer the code from aplay.c as I suggested before?

Post minimal, compilable sources to show your issue and the output you get, please.

ALSA project - the C library reference: Name Hint Interface

I’m not having problems with opening the default sound device, I’m having problems with specifying sound devices.