Linux ALSA/Sound-API 问题 - 如何静音? [英] Linux ALSA/Sound-API Questions - How do you mute?

查看:39
本文介绍了Linux ALSA/Sound-API 问题 - 如何静音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 如何使用 C 使声音静音?是否有 ALSA 函数调用?

  • How do I mute sound using C? Is there an ALSA function call?

是否还有其他可以使麦克风静音的函数调用/API?

Are there any other function calls/APIs that can MUTE the microphone?

我已经编写了一些代码来使用 ALSA 进行音频播放,并且我注意到在声音开始播放之前有一个延迟......我如何减少声音播放的延迟或延迟?

I have written some code to do audio playback using ALSA, and I have noticed a DELAY before the sound starts playing ... how do I reduce DELAY or LATENCY on sound playback?

x

推荐答案

#include <alsa/asoundlib.h>

void SetAlsaMasterMute()
{
    long min, max;
    snd_mixer_t *handle;
    snd_mixer_selem_id_t *sid;
    const char *card = "default";
    const char *selem_name = "Master";

    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);

    if (snd_mixer_selem_has_playback_switch(elem)) {
        snd_mixer_selem_set_playback_switch_all(elem, 0);
    }

    snd_mixer_close(handle);
}

参考:此处和官方 API 这里.

references: here and official api here.

这篇关于Linux ALSA/Sound-API 问题 - 如何静音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆