Xinqi Bao's Git
22fa02fde4f03eaaafb9df98960c899b515f2290
1 /* See LICENSE file for copyright and license details. */
5 #include <sys/soundcard.h>
14 vol_perc(const char *card
)
18 char *vnames
[] = SOUND_DEVICE_NAMES
;
20 afd
= open(card
, O_RDONLY
| O_NONBLOCK
);
22 warn("Cannot open %s", card
);
26 if (ioctl(afd
, SOUND_MIXER_READ_DEVMASK
, &devmask
) == -1) {
27 warn("Cannot get volume for %s", card
);
31 for (i
= 0; i
< LEN(vnames
); i
++) {
32 if (devmask
& (1 << i
) && !strcmp("vol", vnames
[i
])) {
33 if (ioctl(afd
, MIXER_READ(i
), &v
) == -1) {
34 warn("vol_perc: ioctl");
43 return bprintf("%d", v
& 0xff);