Linux ALSA/Sound-API Questions - How do you mute?

前端 未结 1 1237
星月不相逢
星月不相逢 2021-01-01 05:15
  • 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?

相关标签:
1条回答
  • 2021-01-01 05:43
    #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.

    0 讨论(0)
提交回复
热议问题