下面这个函数的作用相当与 调用ALSA utility amixer 设置 Mic Capture Volume。 #amixer cset name="Mic Capture Volume" 10 #include <alsa/asoundlib.h> static char card[64] = "default"; BOOL CXXXSoundDevice::SetMicCaptureVolume(UINT32 uVolume) { int err; int orig_volume = 0; static snd_ctl_t *handle = NULL; snd_ctl_elem_info_t *info; snd_ctl_elem_id_t *id; snd_ctl_elem_value_t *control; unsigned int count; snd_ctl_elem_type_t type; snd_ctl_elem_info_alloca(&info); snd_ctl_elem_id_alloca(&id); snd_ctl_elem_value_alloca(&control); snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER);/* default */ snd_ctl_elem_id_set_name(id, "Mic Capture Volume"); // snd_ctl_elem_id_set_index(id, 1); // "Mic Capture Volume" does not have index. if ((err = snd_ctl_open(&handle, card, 0)) < 0) { BTLOGERROR(LCBTLib,"Control %s open error: %s/n", card, snd_strerror(err)); return FALSE; } snd_ctl_elem_info_set_id(info, id); if ((err = snd_ctl_elem_info(handle, info)) < 0) { BTLOGERROR(LCBTLib,"Cannot find the given element from control %s/n", card); snd_ctl_close(handle); handle = NULL; return FALSE; } type = snd_ctl_elem_info_get_type(info); count = snd_ctl_elem_info_get_count(info); if(type != SND_CTL_ELEM_TYPE_INTEGER || 1 != count) { BTLOGERROR(LCBTLib,"Cannot find the given element from control %s/n", card); snd_ctl_close(handle); handle = NULL; return FALSE; } snd_ctl_elem_value_set_id(control, id); if (!snd_ctl_elem_read(handle, control)) { orig_volume = snd_ctl_elem_value_get_integer(control, 0); } if(uVolume != orig_volume) { BTLOGERROR(LCBTLib,"uVolume != orig_volume ##################### new_value(%d) orgin_value(%d)/n",uVolume,orig_volume); snd_ctl_elem_value_set_integer(control, 0, static_cast<long>(uVolume)); if ((err = snd_ctl_elem_write(handle, control)) < 0) { BTLOGERROR(LCBTLib,"Control %s element write error: %s/n", card, snd_strerror(err)); snd_ctl_close(handle); handle = NULL; return FALSE; } } snd_ctl_close(handle); handle = NULL; return TRUE; }