| getvol.c - sites - public wiki contents of suckless.org | |
| git clone git://git.suckless.org/sites | |
| Log | |
| Files | |
| Refs | |
| --- | |
| getvol.c (1095B) | |
| --- | |
| 1 /* include this into your dwmstatus.c and use get_vol() as volume. | |
| 2 * if your audio card and subunit numbers differ from 0,0 you might havo | |
| 3 * to use amixer, aplay and the /proc/asound file tree to adapt. | |
| 4 * | |
| 5 * I had compilation issues. As result i had to drop the -std=c99 and | |
| 6 * -pedantic flags from the config.mk | |
| 7 */ | |
| 8 | |
| 9 #include <alsa/asoundlib.h> | |
| 10 #include <alsa/control.h> | |
| 11 | |
| 12 int | |
| 13 get_vol(void) | |
| 14 { | |
| 15 int vol; | |
| 16 snd_hctl_t *hctl; | |
| 17 snd_ctl_elem_id_t *id; | |
| 18 snd_ctl_elem_value_t *control; | |
| 19 | |
| 20 // To find card and subdevice: /proc/asound/, aplay -L, amixer controls | |
| 21 snd_hctl_open(&hctl, "hw:0", 0); | |
| 22 snd_hctl_load(hctl); | |
| 23 | |
| 24 snd_ctl_elem_id_alloca(&id); | |
| 25 snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER); | |
| 26 | |
| 27 // amixer controls | |
| 28 snd_ctl_elem_id_set_name(id, "Master Playback Volume"); | |
| 29 | |
| 30 snd_hctl_elem_t *elem = snd_hctl_find_elem(hctl, id); | |
| 31 | |
| 32 snd_ctl_elem_value_alloca(&control); | |
| 33 snd_ctl_elem_value_set_id(control, id); | |
| 34 | |
| 35 snd_hctl_elem_read(elem, control); | |
| 36 vol = (int)snd_ctl_elem_value_get_integer(control,0); | |
| 37 | |
| 38 snd_hctl_close(hctl); | |
| 39 return vol; | |
| 40 } |