gpt4 book ai didi

linux - ALSA - 使用 alsa api (linux) 在 c 代码中更改麦克风增益

转载 作者:太空狗 更新时间:2023-10-29 12:34:43 26 4
gpt4 key购买 nike

我正在尝试使用 linux 机器上的 alsa api 从我的应用程序内部将麦克风静音。我正在使用以下代码更改 volume=0 的音量:

long min, max;
snd_mixer_t *handle;
snd_mixer_selem_id_t *sid;
const char *card = "default";
const char *selem_name = "Capture";
snd_mixer_open(&handle, 0);
snd_mixer_attach(handle, card);
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, selem_name);
snd_mixer_elem_t* elem = snd_mixer_find_selem(handle, sid);
snd_mixer_selem_get_capture_volume_range(elem, &min, &max);
snd_mixer_selem_set_capture_volume_all(elem, volume * max / 100);
snd_mixer_close(handle);

这有效,并且在 alsamixer 中捕获音量减少到零。但我也想使用 api 将麦克风增益更改为 0dB,但我似乎不知道如何实现这一点......

有什么想法吗?

谢谢

编辑:感谢 CL。有效。不过 7 小时后无法粘贴我的代码。

最佳答案

这段代码:

const char *selem_name = "Capture";
snd_mixer_selem_id_set_index(sid, 0);
snd_mixer_selem_id_set_name(sid, selem_name);

选择名为“Capture”的第一个控件。

将名称更改为您机器上的麦克风增益控件。

如果该控件的类型不是数字而是枚举,则必须使用 snd_mixer_selem_set_enum_item() 更改其值。

关于linux - ALSA - 使用 alsa api (linux) 在 c 代码中更改麦克风增益,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14813806/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com