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

问题描述


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


  • 是否有任何其他函数调用/ API,这些API可以使麦克风静音?


  • 我已经写了一些code做使用ALSA音频播放,声音开始播放...我怎么减少对声音回放延迟或等待时间之前,我注意到延迟?


X


解决方案

 的#include< ALSA / asoundlib.h>无效SetAlsaMasterMute()
{
    长最小值,最大值;
    snd_mixer_t *手柄;
    snd_mixer_selem_id_t * SID;
    为const char *卡=默认;
    为const char * selem_name =大师;    snd_mixer_open(安培;手柄,0);
    snd_mixer_attach(手柄,卡);
    snd_mixer_selem_register(手柄,NULL,NULL);
    snd_mixer_load(手柄);    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(手柄,SID);    如果(snd_mixer_selem_has_playback_switch(ELEM)){
        snd_mixer_selem_set_playback_switch_all(ELEM,0);
    }    snd_mixer_close(手柄);
}

引用:和官方API 这里。

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

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

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

references: here and official api here.

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

07-24 16:29