static int alsa_mixer_set_muted(snd_mixer_elem_t *elem, gboolean muted) { long val, min, max; /**if switch is available, get switch status directly*/ if(snd_mixer_selem_has_playback_switch(elem)) { snd_mixer_selem_set_playback_switch(elem, 0, !muted); snd_mixer_selem_set_playback_switch(elem, 1, !muted); return 0; } else if(snd_mixer_selem_has_capture_switch(elem)) { snd_mixer_selem_set_capture_switch(elem, 0, !muted); snd_mixer_selem_set_capture_switch(elem, 1, !muted); return 0; } if(snd_mixer_selem_has_playback_volume(elem)) { snd_mixer_selem_get_playback_volume_range(elem, &min, &max); val = muted ? min : max; snd_mixer_selem_set_playback_volume(elem, 0, val); snd_mixer_selem_set_playback_volume(elem, 1, val); return 0; } else if(snd_mixer_selem_has_capture_volume(elem)) { snd_mixer_selem_get_capture_volume_range(elem, &min, &max); val = muted ? min : max; snd_mixer_selem_set_capture_volume(elem, 0, val); snd_mixer_selem_set_capture_volume(elem, 1, val); return 0; } return -1; }
static void _set_switch(snd_mixer_elem_t *elem, int playback, int n, int val) { if (playback) snd_mixer_selem_set_playback_switch(elem, n, val); else snd_mixer_selem_set_capture_switch(elem, n, !val); }
/* * Class: org_tritonus_lowlevel_alsa_AlsaMixerElement * Method: setCaptureSwitch * Signature: (IZ)V */ JNIEXPORT void JNICALL Java_org_tritonus_lowlevel_alsa_AlsaMixerElement_setCaptureSwitch (JNIEnv* env, jobject obj, jint nChannelType, jboolean bValue) { snd_mixer_elem_t* handle; int nReturn; if (debug_flag) { (void) fprintf(debug_file, "Java_org_tritonus_lowlevel_alsa_AlsaMixerElement_setCaptureSwitch(): begin\n"); } handle = getHandle(env, obj); nReturn = snd_mixer_selem_set_capture_switch(handle, (snd_mixer_selem_channel_id_t) nChannelType, bValue); if (nReturn < 0) { throwRuntimeException(env, snd_strerror(nReturn)); } if (debug_flag) { (void) fprintf(debug_file, "Java_org_tritonus_lowlevel_alsa_AlsaMixerElement_setCaptureSwitch(): end\n"); } }
/* mute: 0 -> mute, 1 -> unmute */ void sound_mixer_mute(const char *mixer, MUTEST mute) { int i; snd_mixer_t *handle = NULL; snd_mixer_elem_t *elem = NULL; elem = sound_get_elem(mixer, &handle); if (!elem) return; for (i = 0; i <= SND_MIXER_SCHN_LAST; i++) { if (snd_mixer_selem_has_playback_channel(elem, i) && snd_mixer_selem_has_playback_switch(elem)) snd_mixer_selem_set_playback_switch(elem, i, mute); else if (snd_mixer_selem_has_capture_channel(elem, i) && snd_mixer_selem_has_capture_switch(elem)) snd_mixer_selem_set_capture_switch(elem, i, mute); } snd_mixer_close(handle); }
bool AlsaMixer::SwitchChannel( const char* channel, bool value ) { bool success = false; snd_mixer_elem_t *elem; snd_mixer_selem_id_t *sid; snd_mixer_selem_id_alloca(&sid); snd_mixer_selem_id_set_index( sid, 0); snd_mixer_selem_id_set_name( sid, channel); elem = snd_mixer_find_selem(_handle, sid); if (!elem) { LOG( Logger::LOG_ERROR, "Unable to find simple control '%s',%i\n", snd_mixer_selem_id_get_name(sid), snd_mixer_selem_id_get_index(sid)); goto end; } if( snd_mixer_selem_has_playback_switch(elem) ) { for (int chn = 0; chn <= SND_MIXER_SCHN_LAST; chn++) { if (snd_mixer_selem_set_playback_switch(elem, (snd_mixer_selem_channel_id_t)chn, value ? 1 : 0 ) >= 0) { success = true; } } }else if( snd_mixer_selem_has_capture_switch(elem) ) { for (int chn = 0; chn <= SND_MIXER_SCHN_LAST; chn++) { if (snd_mixer_selem_set_capture_switch(elem, (snd_mixer_selem_channel_id_t)chn, value ? 1 : 0 ) >= 0) { success = true; } } } if( !success ) { LOG( Logger::LOG_ERROR, "Error setting control '%s',%i\n", snd_mixer_selem_id_get_name(sid), snd_mixer_selem_id_get_index(sid)); } end: return success; }
static void set_current_input_source(px_mixer *Px, int i) { PxInfo *info = (PxInfo *)Px->info; snd_mixer_elem_t *elem; int j; if (!info->capture.handle) { return; } if (i < 0 || i >= info->capture.numselems) { return; } elem = info->capture.selems[i].elem; for (j = 0; j <= SND_MIXER_SCHN_LAST; j++) { if (snd_mixer_selem_has_capture_switch(elem)) { snd_mixer_selem_set_capture_switch(elem, j, TRUE); } } return; }