Created
March 31, 2015 17:21
-
-
Save fulup-bzh/891e5627be325150337f to your computer and use it in GitHub Desktop.
Alsa snd_hctl_find_elem function test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <unistd.h> | |
#include <fcntl.h> | |
#include <errno.h> | |
#include <termios.h> | |
#include <sys/ioctl.h> | |
#include <sys/signal.h> | |
#include <sys/types.h> | |
#include <time.h> | |
// gcc -g -o test2-api test2api.c `pkg-config --cflags --libs alsa` | |
#include <alsa/asoundlib.h> | |
main() { | |
int err; | |
snd_hctl_t *handle; | |
snd_hctl_elem_t *elem; | |
snd_ctl_elem_info_t *info; | |
snd_ctl_elem_id_t *id; | |
snd_ctl_elem_value_t *control; | |
snd_ctl_elem_info_alloca(&info); | |
char *card = "hw:1"; | |
int numid = 26; | |
if ((err = snd_hctl_open(&handle, card, 0)) < 0) { | |
error("Control %s open error: %s", card, snd_strerror(err)); | |
goto errorExit; | |
} | |
if ((err = snd_hctl_load(handle)) < 0) { | |
error("Control %s local error: %s\n", card, snd_strerror(err)); | |
goto errorExit; | |
} | |
snd_ctl_elem_id_alloca(&id); | |
snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER); | |
//snd_ctl_elem_id_set_numid (id, 3); | |
snd_ctl_elem_id_set_name(id, "Line Playback Volume"); | |
// verify that element has a defined type | |
elem = snd_hctl_find_elem (handle, id); | |
if (elem == NULL) { | |
fprintf(stderr, "Control %s numid=%d fail to find control\n", card, numid); | |
goto errorExit; | |
} | |
snd_ctl_elem_value_alloca(&control); | |
snd_ctl_elem_value_set_id(control, id); | |
snd_ctl_elem_info_alloca(&info); | |
if ((err = snd_hctl_elem_info (elem, info)) < 0) { | |
fprintf(stderr, "Control %s numid=%d fail to request info \n", card, numid); | |
goto errorExit; | |
} | |
fprintf (stderr,"fin\n"); | |
errorExit: | |
fprintf (stderr,"Error\n"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment