I want to port same function from oss mixer to alsa but I don’t now how to check if device
channel have capture mask.
Code for OSS:
These functions handle the mixer device
static int mixer_fd = -1, mixer_src = -1;
int mixer_init(char *mixer_device, char *mixer_source)
{
int i;
mixer_src = -1;
for (i=0;i<SOUND_MIXER_NRDEVICES;i++)
if (strcmp(mixer_source, devices[i]) == 0)
mixer_src = i;
mixer_fd = open(mixer_device, O_RDWR);
if (mixer_src < 0)
return -1;
if (mixer_fd < 0)
return 0;
return 1;
}
char** mixer_get_rec_devices(void)
{
int i, o, devmask, res;
char** result;
if ((ioctl(mixer_fd, SOUND_MIXER_READ_RECMASK, &devmask)) == -1)
return NULL;
else
{
result = malloc(sizeof(char*)*SOUND_MIXER_NRDEVICES);
o = 0;
for (i=0;i<SOUND_MIXER_NRDEVICES;i++)
{
res = (devmask >> i)%2;
if (res)
{
result[o] = malloc(strlen(devices[i])+1);
sprintf(result[o], "%s", devices[i]);
o++;
}
result[o] = NULL;
}
}
return result;
}
int mixer_set_rec_device(void)
{
int devmask, recmask;
if (mixer_fd <= 0)
return 0;
if (mixer_src < 0)
return 0;
if ((ioctl(mixer_fd, SOUND_MIXER_READ_RECMASK, &devmask)) == -1)
return 0;
recmask = 1 << mixer_src;
if (!(recmask & devmask))
return 0;
if ((ioctl(mixer_fd, SOUND_MIXER_WRITE_RECSRC, &recmask)) == -1)
return 0;
return 1;
}
I need help to port this code to ALSA mixer.
function “mixer_set_rec_device()” is used to check if channel mixer can record if user activate recording, where settings.mixer is channel choose by user.
if (!mixer_set_rec_device()) {
fprintf(stderr, "Could not set \"%s\" as recording Source", settings.mixer);
return -1;
}
Some devices can capture from multiple sources; these devices typically have several boolean mixer controls named
xxxxx Capture Switch.Some devices can capture from only one source; these devices typically have an enumerated mixer control named
Capture Source.In the general case, the device’s mixer might work entirely different.
In any case, general-purpose applications should never modify the user’s mixer configuration, but just record from some PCM device; configuring the mixer should be done by the user, or by some specialized mixer application that knows the hardware.