This repository has been archived on 2024-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
samu/sound.c

36 lines
909 B
C
Raw Normal View History

2024-09-14 13:22:36 +02:00
#include<stdio.h>
#include<alsa/asoundlib.h>
#define VOL_CH "Master"
void increaseVolume()
{
long vol = 0;
long min, max;
snd_mixer_t *handle;
snd_mixer_selem_id_t *sid;
snd_mixer_open(&handle, 0);
snd_mixer_attach(handle, "default");
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, VOL_CH);
snd_mixer_elem_t* elem = snd_mixer_find_selem(handle, sid);
snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
snd_mixer_selem_get_playback_volume(elem, SND_MIXER_SCHN_MONO, &vol );
long vol_percent = vol * 100 / ( int )max;
long vol_new = vol_percent * max / 100;
printf( "%ld%%", vol_percent );
printf( "%ld%%", vol_new );
int volume = vol_percent + 3;
printf( "%i", volume );
snd_mixer_selem_set_playback_volume_all(elem, volume * max / 100);
snd_mixer_close(handle);
}