4
  • 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

Xofo
  • 1,256
  • 4
  • 18
  • 33
  • I also have the same question. Did you figure out how to mute the speakers and mic? In my program for my GUI I would want to have a general "mute" button that would trigger a muting of the speakers and mic –  Aug 09 '11 at 13:52

1 Answers1

6
#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.

Community
  • 1
  • 1
user1055604
  • 1,624
  • 11
  • 28