예제 #1
0
파일: audio.c 프로젝트: crpalmer/pi_lib
static bool
do_set_volume(struct mixer *mixer, const char *name, unsigned volume)
{
    struct mixer_ctl *ctl;
    unsigned i;

    ctl = mixer_get_ctl_by_name(mixer, name);
    if (! ctl) {
	fprintf(stderr, "Failed to find control: %s\n", name);
	mixer_close(mixer);
	return false;
    }

    for (i = 0; i < mixer_ctl_get_num_values(ctl); i++) {
        mixer_ctl_set_percent(ctl, i, volume);
    }

    return true;
}
int write_percentage(int argc, char **argv) {
    int nMixer = -1, nControl = -1;
    int location = -1, value = -1;

    if (argc == 6) {
        nMixer = atoi(argv[2]);
        nControl = atoi(argv[3]);
        location = atoi(argv[4]);
        value = atoi(argv[5]);
    }

    if (argc != 6 || nMixer < 0 || nMixer > 7 || nControl < 0 || location < 0) {
        printf("Usage: ainfo write-percentage <card number> <control number> <location> <value>\n"
               "where <card number> is between 0 and 7\n"
               "<control number> is the control to be written\n"
               "<location> is the location to be written\n"
               "<value> is the value to be written\n");
        return 0;
    }

    mixer *m = mixer_open(nMixer);

    if (m == NULL) {
        printf("Unable to open card #%d\n", nMixer);
        return 0;
    }

    mixer_ctl *c = mixer_get_ctl(m, nControl);

    if (c == NULL) {
        printf("Unable to open control #%d\n", nControl);
        return 0;        
    }

    char name[64], type[64];
    mixer_ctl_get_name(c, name, sizeof(name));
    mixer_ctl_set_percent(c, location, value);
    printf("Control: %s\nPercent: %d\nValue: %d\n", name, 
        mixer_ctl_get_percent(c, location), mixer_ctl_get_value(c, location));

    return 0;
}