-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathalsa_control.c
61 lines (53 loc) · 1.34 KB
/
alsa_control.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <stdio.h>
#include <stdlib.h>
#include <alsa/asoundlib.h>
#include <alsa/mixer.h>
void SetAlsaMasterVolume(long volume)
{
long min, max;
snd_mixer_t *handle;
snd_mixer_selem_id_t *sid;
const char *card = "default";
const char *selem_name = "Master";
snd_mixer_open(&handle, 0);
snd_mixer_attach(handle, card);
snd_mixer_selem_register(handle, NULL, NULL);
snd_mixer_load(handle);
snd_mixer_selem_id_alloca(&sid);
snd_mixer_selem_id_set_index(sid, 0);
snd_mixer_selem_id_set_name(sid, selem_name);
snd_mixer_elem_t* elem = snd_mixer_find_selem(handle, sid);
snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
snd_mixer_selem_set_playback_volume_all(elem, volume * max / 100);
snd_mixer_close(handle);
}
void main(void){
char input[10] = {0};
char in = 0;
int count = 0;
long output = 50;
while(1){
in = getchar();
if(in == 'u'){
if(++output < 102){
SetAlsaMasterVolume(output);
printf("output: %d\n",output);
}
else{
output = 102;
printf("output: MAX\n",output);
}
}
else if(in == 'd'){
if(--output >= 0){
SetAlsaMasterVolume(output);
printf("output: %d\n",output);
}
else{
output = 0;
printf("output: %d\n",output);
}
}
}
return;
}