掌機 - Anbernic RG28XX - C/C++ - Volume



main.c

#include <stdio.h>
#include <stdlib.h>
#include <alsa/asoundlib.h>

int main(int argc, char** argv)
{
    int vol = 10;
	snd_mixer_t *mixer = NULL;
	snd_mixer_elem_t *elem = NULL;
	snd_mixer_selem_id_t *sid = NULL;

	snd_mixer_open(&mixer, 1);
	snd_mixer_attach(mixer, "default");
	snd_mixer_selem_register(mixer, NULL, NULL);
	snd_mixer_load(mixer);
	snd_mixer_selem_id_alloca(&sid);
	snd_mixer_selem_id_set_index(sid, 0);
	snd_mixer_selem_id_set_name(sid, "lineout volume");
	elem = snd_mixer_find_selem(mixer, sid);
	snd_mixer_selem_set_playback_volume_all(elem, vol);
	snd_mixer_close(mixer);
	return 0;
}

編譯

$ arm-linux-gcc main.c -o main -lasound