/ Published in: C
                    
                                        
This script finds out ALSA devices in Linux programatically, which can be a bit tricky.
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
/**
* Reads audio devices from ALSA interface and returns count and array of
* strings containing the devices.
*
* @param[out] count Number of devices found.
* @param[out] Array of strings containing the device names.
*
*/
static void getALSADevices(int *count, char **devices)
{
void **hints;
const char *ifaces[] = {"card", "pcm", "rawmidi", "timer", "seq", "hwdep", 0};
int index = 0;
void **str;
char *name;
char *desc;
char *io;
char *name_tmp;
char *desc_tmp;
int devIdx = 0;
int len;
snd_config_update();
while (ifaces[index]) {
if (snd_device_name_hint(-1, ifaces[index], &hints) < 0) {
index++;
continue;
}
str = hints;
while (*str) {
name = snd_device_name_get_hint(*str, "NAME");
desc = snd_device_name_get_hint(*str, "DESC");
io = snd_device_name_get_hint(*str, "IOID");
devices[devIdx] = name_tmp;
devices[devIdx][len-1] = '\0';
while (desc_tmp != NULL) {
}
devIdx++;
str++;
}
index++;
snd_device_name_free_hint(hints);
}
*count = devIdx;
return;
}
Comments
 Subscribe to comments
                    Subscribe to comments
                
                