void mixerGuiAlsaMix::cardChanged( int card ) { #ifdef HAVE_ALSA channelSelect->clear(); // get the cards channels snd_mixer_t* alsaDev; snd_mixer_open( &alsaDev, 0); char device[16]; sprintf(device, "hw:%i", card); snd_mixer_attach(alsaDev, device ); snd_mixer_selem_register(alsaDev, NULL, NULL); snd_mixer_load(alsaDev); //load up the mixer snd_mixer_elem_t* mixerElem = snd_mixer_first_elem(alsaDev); while( mixerElem != snd_mixer_last_elem(alsaDev) ) { if(snd_mixer_selem_has_playback_volume(mixerElem) || snd_mixer_selem_has_capture_volume(mixerElem)) channelSelect->addItem( QString( snd_mixer_selem_get_name(mixerElem)), QVariant( snd_mixer_selem_get_name(mixerElem)) ); mixerElem=snd_mixer_elem_next( mixerElem ); } for(int i=0; i<= channelSelect->count(); i++ ) if( channelSelect->itemData(i) == settings["alsa_channel"].toString() ) channelSelect->setCurrentIndex( i ); #endif }
static snd_mixer_elem_t * gst_alsa_mixer_find_master_mixer (GstAlsaMixer * mixer, snd_mixer_t * handle) { snd_mixer_elem_t *element; gint i, count; count = snd_mixer_get_count (handle); /* Check if we have a playback mixer labelled as 'Master' */ element = snd_mixer_first_elem (handle); for (i = 0; i < count; i++) { if (snd_mixer_selem_has_playback_volume (element) && strcmp (snd_mixer_selem_get_name (element), "Master") == 0) { return element; } element = snd_mixer_elem_next (element); } /* If not, check if we have a playback mixer labelled as 'Front' */ element = snd_mixer_first_elem (handle); for (i = 0; i < count; i++) { if (snd_mixer_selem_has_playback_volume (element) && strcmp (snd_mixer_selem_get_name (element), "Front") == 0) { return element; } element = snd_mixer_elem_next (element); } /* If not, check if we have a playback mixer labelled as 'PCM' */ element = snd_mixer_first_elem (handle); for (i = 0; i < count; i++) { if (snd_mixer_selem_has_playback_volume (element) && strcmp (snd_mixer_selem_get_name (element), "PCM") == 0) { return element; } element = snd_mixer_elem_next (element); } /* If not, check if we have a playback mixer with both volume and switch */ element = snd_mixer_first_elem (handle); for (i = 0; i < count; i++) { if (snd_mixer_selem_has_playback_volume (element) && snd_mixer_selem_has_playback_switch (element)) { return element; } element = snd_mixer_elem_next (element); } /* If not, take any playback mixer with a volume control */ element = snd_mixer_first_elem (handle); for (i = 0; i < count; i++) { if (snd_mixer_selem_has_playback_volume (element)) { return element; } element = snd_mixer_elem_next (element); } /* Looks like we're out of luck ... */ return NULL; }
int sa_stream_set_volume_abs(sa_stream_t *s, float vol) { snd_mixer_t* mixer = 0; snd_mixer_elem_t* elem = 0; if (s == NULL || s->output_unit == NULL) { return SA_ERROR_NO_INIT; } if (snd_mixer_open(&mixer, 0) < 0) { return SA_ERROR_SYSTEM; } if (snd_mixer_attach(mixer, "default") < 0) { snd_mixer_close(mixer); return SA_ERROR_SYSTEM; } if (snd_mixer_selem_register(mixer, NULL, NULL) < 0) { snd_mixer_close(mixer); return SA_ERROR_SYSTEM; } if (snd_mixer_load(mixer) < 0) { snd_mixer_close(mixer); return SA_ERROR_SYSTEM; } #if 0 snd_mixer_elem_t* elem = 0; for (elem = snd_mixer_first_elem(mixer); elem != NULL; elem = snd_mixer_elem_next(elem)) { if (snd_mixer_selem_has_playback_volume(elem)) { printf("Playback %s\n", snd_mixer_selem_get_name(elem)); } else { printf("No Playback: %s\n", snd_mixer_selem_get_name(elem)); } } #endif elem = snd_mixer_first_elem(mixer); if (elem && snd_mixer_selem_has_playback_volume(elem)) { long min = 0; long max = 0; if (snd_mixer_selem_get_playback_volume_range(elem, &min, &max) >= 0) { snd_mixer_selem_set_playback_volume_all(elem, (max-min)*vol + min); } } snd_mixer_close(mixer); return SA_SUCCESS; }
/* Gets target sound profile from TOGGLE_SOUND_PROFILES array */ struct sound_profile* get_target_sound_profile(struct sound_profile* current) { struct sound_profile* target = NULL; for (int i = 0; i < TOGGLE_SOUND_PROFILES_SIZE; ++i) { snd_mixer_elem_t* e = TOGGLE_SOUND_PROFILES[i]->mixer_element; if (strcasecmp(snd_mixer_selem_get_name(current->mixer_element), snd_mixer_selem_get_name(e)) == 0) { target = i+1 < TOGGLE_SOUND_PROFILES_SIZE ? TOGGLE_SOUND_PROFILES[i+1] : TOGGLE_SOUND_PROFILES[0]; } } assert(target); return target; }
static enum MixerCode alsaMixerSelectCard(struct MixerSystem* system, int mixerId) { enum MixerCode code; snd_mixer_elem_t* mixerElem = NULL; AlsaMixerCard* card = (AlsaMixerCard*)system->active; if ( !card ) { if ( card == system->mixerCard->pElement[mixerId] ) { return MIXER_CODE_OK; } alsaMixerCardClose(system); } code = commonMixerSelectCard(system, mixerId); if ( code != MIXER_CODE_OK ) { GOC_DEBUG("Cannot select card by commonMixerSelectCard"); return code; } card = (AlsaMixerCard*)system->active; GOC_CHEOP_DEBUG(snd_mixer_open( &card->sndmixer, 0 ) == 0, return MIXER_CODE_CANNOT_OPEN_CARD); GOC_CHEOP_DEBUG(snd_mixer_attach( card->sndmixer, card->physicalName ) == 0, return MIXER_CODE_CANNOT_OPEN_CARD); GOC_CHEOP_DEBUG(snd_mixer_selem_register( card->sndmixer, NULL, NULL ) == 0, return MIXER_CODE_CANNOT_OPEN_CARD); GOC_CHEOP_DEBUG(snd_mixer_load( card->sndmixer ) == 0, return MIXER_CODE_CANNOT_OPEN_CARD); mixerElem = snd_mixer_first_elem( card->sndmixer ); while ( mixerElem ) { AlsaMixerElement* pMixerElement = alsaMixerElementAlloc(); for (int channel = 0; channel <= SND_MIXER_SCHN_LAST; channel++ ) { if ( snd_mixer_selem_has_playback_channel(mixerElem, channel) && snd_mixer_selem_get_playback_volume_range(mixerElem, &pMixerElement->rangemin, &pMixerElement->rangemax) == 0 && snd_mixer_selem_get_playback_volume(mixerElem, channel, &pMixerElement->volume) == 0 ) { pMixerElement->name = goc_stringCopy(NULL, snd_mixer_selem_get_name(mixerElem)); pMixerElement->type = MIXER_ELEMENT_PLAYBACK; pMixerElement->sndelement = mixerElem; card->mixerElement = goc_arrayAdd( card->mixerElement, pMixerElement ); break; } else if ( snd_mixer_selem_has_capture_channel(mixerElem, channel) && snd_mixer_selem_get_capture_volume_range(mixerElem, &pMixerElement->rangemin, &pMixerElement->rangemax) == 0 && snd_mixer_selem_get_capture_volume(mixerElem, channel, &pMixerElement->volume) == 0 ) { pMixerElement->name = goc_stringCopy(NULL, snd_mixer_selem_get_name(mixerElem)); pMixerElement->type = MIXER_ELEMENT_CAPTURE; pMixerElement->sndelement = mixerElem; card->mixerElement = goc_arrayAdd( card->mixerElement, pMixerElement ); break; } } mixerElem = snd_mixer_elem_next( mixerElem ); } return MIXER_CODE_OK; }
void gam_toggle_set_state (GamToggle *gam_toggle, gboolean state) { GamTogglePrivate *priv; const gboolean internal_state = gam_toggle_get_state (gam_toggle); int err; priv = GAM_TOGGLE_GET_PRIVATE (gam_toggle); if (state == internal_state) return; if (snd_mixer_selem_has_playback_switch (priv->elem)) { err = snd_mixer_selem_set_playback_switch_all (priv->elem, state); } else if (snd_mixer_selem_has_capture_switch (priv->elem)) { err = snd_mixer_selem_set_capture_switch_all (priv->elem, state); } else { g_warning ("%s (). No idea what to do for mixer element \"%s\"!", __FUNCTION__, snd_mixer_selem_get_name (priv->elem)); err = 0; } if (err) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gam_toggle), internal_state); }
static void gst_alsa_mixer_track_update_alsa_capabilities (GstAlsaMixerTrack * alsa_track) { alsa_track->alsa_flags = 0; alsa_track->capture_group = -1; if (snd_mixer_selem_has_common_volume (alsa_track->element)) alsa_track->alsa_flags |= GST_ALSA_MIXER_TRACK_VOLUME; if (snd_mixer_selem_has_playback_volume (alsa_track->element)) alsa_track->alsa_flags |= GST_ALSA_MIXER_TRACK_PVOLUME; if (snd_mixer_selem_has_capture_volume (alsa_track->element)) alsa_track->alsa_flags |= GST_ALSA_MIXER_TRACK_CVOLUME; if (snd_mixer_selem_has_common_switch (alsa_track->element)) alsa_track->alsa_flags |= GST_ALSA_MIXER_TRACK_SWITCH; if (snd_mixer_selem_has_playback_switch (alsa_track->element)) alsa_track->alsa_flags |= GST_ALSA_MIXER_TRACK_PSWITCH; if (snd_mixer_selem_has_capture_switch (alsa_track->element)) { alsa_track->alsa_flags |= GST_ALSA_MIXER_TRACK_CSWITCH; if (snd_mixer_selem_has_capture_switch_exclusive (alsa_track->element)) { alsa_track->alsa_flags |= GST_ALSA_MIXER_TRACK_CSWITCH_EXCL; alsa_track->capture_group = snd_mixer_selem_get_capture_group (alsa_track->element); } } GST_LOG ("[%s] alsa_flags=0x%08x, capture_group=%d", snd_mixer_selem_get_name (alsa_track->element), alsa_track->alsa_flags, alsa_track->capture_group); }
void moko_alsa_volume_control_set_element_from_name (MokoAlsaVolumeControl *control, const gchar *name) { MokoAlsaVolumeControlPrivate *priv = ALSA_VOLUME_CONTROL_PRIVATE (control); if (!priv->device) return; detach_mixer (control); if (!name) { moko_alsa_volume_control_set_element (control, NULL); return; } open_mixer (control); if ((snd_mixer_attach (priv->mixer_handle, priv->device) == 0) && (snd_mixer_selem_register (priv->mixer_handle, NULL, NULL) == 0) && (snd_mixer_load (priv->mixer_handle) == 0)) { snd_mixer_elem_t *elem; elem = snd_mixer_first_elem (priv->mixer_handle); while (elem) { const char *elem_name = snd_mixer_selem_get_name (elem); if (strcmp (elem_name, name) == 0) break; elem = snd_mixer_elem_next (elem); } if (!elem) { snd_mixer_detach (priv->mixer_handle, priv->device); close_mixer (control); g_warning ("Mixer element '%s' not found", name); attach_mixer (control); } else { snd_mixer_selem_id_t *id; if (snd_mixer_selem_id_malloc (&id) != 0) { g_warning ("Unable to allocate element id"); snd_mixer_detach ( priv->mixer_handle, priv->device); close_mixer (control); } else { snd_mixer_selem_get_id (elem, id); snd_mixer_detach ( priv->mixer_handle, priv->device); close_mixer (control); g_debug ("Setting element ID"); moko_alsa_volume_control_set_element ( control, id); snd_mixer_selem_id_free (id); } } } else g_warning ("Unable to open mixer on card '%s'", priv->device); }
static int initialize_mixer_device(struct audio_info_struct *ai, char *error) { int sts; snd_mixer_t *mixer; char *mixerdev = "default"; const char *elemnam; snd_mixer_elem_t *mixerelem; sts = snd_mixer_open(&mixer, 0); if (sts) { if (error) { sprintf(error, "snd_mixer_open failed; %d\n", sts); } return 1; } if (mixer) { sts = snd_mixer_attach(mixer, mixerdev); if (sts) { if (error) { sprintf(error, "snd_mixer_attach: failed; %d\n", sts); } return 1; } sts = snd_mixer_selem_register(mixer, NULL, NULL); if (sts) { if (error) { sprintf(error, "snd_mixer_selem_register: failed; %d\n", sts); } return 1; } sts = snd_mixer_load(mixer); if (sts) { if (error) { sprintf(error, "snd_mixer_selem_register: failed; %d\n", sts); } return 1; } mixerelem = snd_mixer_first_elem(mixer); snd_mixer_set_callback(mixer, mixer_callback_func); while (mixerelem) { elemnam = snd_mixer_selem_get_name(mixerelem); if (strcasecmp(elemnam, "Master") == 0) { ai->vh = mixerelem; return 0; } mixerelem = snd_mixer_elem_next(mixerelem); } } return 1; }
static void set_volume(AudioCapture *capture, int level) { snd_mixer_t *mixer=NULL; int err; err=snd_mixer_open(&mixer,0); if(err < 0) { fprintf(stderr, "Could not open alsa mixer: %s\r\n",snd_strerror(err)); exit(1); } char hw_id[100]; snprintf(hw_id, sizeof(hw_id), "hw:%d", capture->pcm_id); if ((err = snd_mixer_attach (mixer, hw_id)) < 0){ fprintf(stderr, "Could not attach mixer to card(%s): %s\r\n", hw_id, snd_strerror(err)); snd_mixer_close(mixer); exit(1); } if ((err = snd_mixer_selem_register (mixer, NULL, NULL)) < 0){ fprintf(stderr, "snd_mixer_selem_register: %s\r\n",snd_strerror(err)); snd_mixer_close(mixer); exit(1); } if ((err = snd_mixer_load (mixer)) < 0){ fprintf(stderr, "snd_mixer_load: %s\r\n",snd_strerror(err)); snd_mixer_close(mixer); exit(1); } snd_mixer_elem_t *elem; elem = snd_mixer_first_elem(mixer); while(elem) { const char *elemname = snd_mixer_selem_get_name(elem); if(strcmp(elemname, "Capture") && strcmp(elemname, "Mic")) { fprintf(stderr, "Skip setting volume for %s\r\n", elemname); elem=snd_mixer_elem_next(elem); continue; } if (snd_mixer_selem_has_capture_volume(elem)){ fprintf(stderr, "Set volume for %s\r\n", elemname); long sndMixerPMin; long sndMixerPMax; long newvol; snd_mixer_selem_get_playback_volume_range(elem, &sndMixerPMin, &sndMixerPMax); newvol=(((sndMixerPMax-sndMixerPMin)*level)/100)+sndMixerPMin; snd_mixer_selem_set_capture_volume_all(elem,newvol); elem=snd_mixer_elem_next(elem); } else { fprintf(stderr, "Can't set capture volume\r\n"); exit(1); } } }
const gchar * gam_toggle_get_name (GamToggle *gam_toggle) { GamTogglePrivate *priv; g_return_val_if_fail (GAM_IS_TOGGLE (gam_toggle), NULL); priv = GAM_TOGGLE_GET_PRIVATE (gam_toggle); return snd_mixer_selem_get_name (priv->elem); }
void asound_setup(const gchar * card, const gchar * channel, void (*volume_changed)(int,gboolean)) { // Make sure (for now) that the setup function only gets called once static int asound_setup_called = 0; assert(asound_setup_called == 0); asound_setup_called++; // Save card, volume_changed strcpy(m_card, card); m_volume_changed = volume_changed; // Load the mixer for the provided cardname snd_mixer_open(&m_mixer, 0); snd_mixer_attach(m_mixer, m_card); snd_mixer_selem_register(m_mixer, NULL, NULL); snd_mixer_load(m_mixer); // Setup g_io_watch for the mixer int count = snd_mixer_poll_descriptors_count(m_mixer); if(count >= 1) { struct pollfd pfd; count = snd_mixer_poll_descriptors(m_mixer, &pfd, 1); if(count == 1) { GIOChannel * giochannel = g_io_channel_unix_new(pfd.fd); g_io_add_watch_full(giochannel, G_PRIORITY_DEFAULT, G_IO_IN, asound_poll_cb, NULL, NULL); } } // Iterate over the elements in the mixer and store them in m_channel_names int elemcount = snd_mixer_get_count(m_mixer); snd_mixer_elem_t * elem = snd_mixer_first_elem(m_mixer); int loop; for(loop = 0; loop < elemcount; loop++) { const char * elemname = snd_mixer_selem_get_name(elem); if(snd_mixer_selem_has_playback_volume(elem)) { m_channel_names = g_list_append(m_channel_names, (gpointer)g_strdup(elemname)); } elem = snd_mixer_elem_next(elem); } // Setup m_elem using the provided channelname if(channel != NULL && asound_channel_exists(channel)) asound_set_channel(channel); else if(m_channel_names != NULL) asound_set_channel((const gchar*)m_channel_names->data); }
void set_state(char *elem_name, int state) { snd_mixer_elem_t *elem; for ( elem = snd_mixer_first_elem( mixerFd); elem; elem = snd_mixer_elem_next( elem) ) { printf("want %s, found %s\n", elem_name, snd_mixer_selem_get_name( elem) ); if (elem_name && strcmp(elem_name,snd_mixer_selem_get_name( elem))) continue; snd_mixer_selem_set_playback_switch_all(elem, state); } }
static void set_mixer_element(snd_mixer_t *mixer,const char *name, int level,MixerAction action){ const char *elemname; snd_mixer_elem_t *elem; long sndMixerPMin=0; long sndMixerPMax=0; long newvol=0; elem=snd_mixer_first_elem(mixer); while (elem!=NULL){ elemname=snd_mixer_selem_get_name(elem); //ms_message("Found alsa mixer element %s.",elemname); if (strcmp(elemname,name)==0){ switch(action){ case CAPTURE: if (snd_mixer_selem_has_capture_volume(elem)){ snd_mixer_selem_get_capture_volume_range(elem, &sndMixerPMin, &sndMixerPMax); newvol=(((sndMixerPMax-sndMixerPMin)*level)/100)+sndMixerPMin; snd_mixer_selem_set_capture_volume_all(elem,newvol); //ms_message("Successfully set capture level for %s.",elemname); return; } break; case PLAYBACK: if (snd_mixer_selem_has_playback_volume(elem)){ snd_mixer_selem_get_playback_volume_range(elem, &sndMixerPMin, &sndMixerPMax); newvol=(((sndMixerPMax-sndMixerPMin)*level)/100)+sndMixerPMin; snd_mixer_selem_set_playback_volume_all(elem,newvol); //ms_message("Successfully set playback level for %s.",elemname); return; } break; case CAPTURE_SWITCH: if (snd_mixer_selem_has_capture_switch(elem)){ snd_mixer_selem_set_capture_switch_all(elem,level); //ms_message("Successfully set capture switch for %s.",elemname); } break; case PLAYBACK_SWITCH: if (snd_mixer_selem_has_playback_switch(elem)){ snd_mixer_selem_set_playback_switch_all(elem,level); //ms_message("Successfully set capture switch for %s.",elemname); } break; } } elem=snd_mixer_elem_next(elem); } return ; }
snd_mixer_elem_t* AlsaMixer::get_playback_elem(const std::string name) { snd_mixer_elem_t* elem; for (elem = snd_mixer_first_elem(this->handle); elem; elem = snd_mixer_elem_next(elem)) { if (snd_mixer_selem_is_active(elem) && snd_mixer_selem_has_playback_volume(elem) && (name == snd_mixer_selem_get_name(elem))) return elem; } }
static int get_mixer_element(snd_mixer_t *mixer,const char *name, MixerAction action){ long value=0; const char *elemname; snd_mixer_elem_t *elem; int err; long sndMixerPMin=0; long sndMixerPMax=0; long newvol=0; elem=snd_mixer_first_elem(mixer); while (elem!=NULL){ elemname=snd_mixer_selem_get_name(elem); //ms_message("Found alsa mixer element %s.",elemname); if (strcmp(elemname,name)==0){ switch (action){ case CAPTURE: if (snd_mixer_selem_has_capture_volume(elem)){ snd_mixer_selem_get_capture_volume_range(elem, &sndMixerPMin, &sndMixerPMax); err=snd_mixer_selem_get_capture_volume(elem,SND_MIXER_SCHN_UNKNOWN,&newvol); newvol-=sndMixerPMin; value=(100*newvol)/(sndMixerPMax-sndMixerPMin); if (err<0) ms_warning("Could not get capture volume for %s:%s",name,snd_strerror(err)); //else ms_message("Successfully get capture level for %s.",elemname); break; } break; case PLAYBACK: if (snd_mixer_selem_has_playback_volume(elem)){ snd_mixer_selem_get_playback_volume_range(elem, &sndMixerPMin, &sndMixerPMax); err=snd_mixer_selem_get_playback_volume(elem,SND_MIXER_SCHN_FRONT_LEFT,&newvol); newvol-=sndMixerPMin; value=(100*newvol)/(sndMixerPMax-sndMixerPMin); if (err<0) ms_warning("Could not get playback volume for %s:%s",name,snd_strerror(err)); //else ms_message("Successfully get playback level for %s.",elemname); break; } break; case CAPTURE_SWITCH: break; case PLAYBACK_SWITCH: break; } } elem=snd_mixer_elem_next(elem); } return value; }
/* openmoko_mixer_open */ static int _openmoko_mixer_open(Openmoko * openmoko) { #ifdef __linux__ PhonePluginHelper * helper = openmoko->helper; char const * audio_device; snd_mixer_elem_t * elem; openmoko->mixer_elem = NULL; openmoko->mixer_elem_headphone = NULL; openmoko->mixer_elem_speaker = NULL; if((audio_device = helper->config_get(helper->phone, "openmoko", "audio_device")) == NULL) audio_device = "hw:0"; if(snd_mixer_open(&openmoko->mixer, 0) != 0) { openmoko->mixer = NULL; return -1; } if(snd_mixer_attach(openmoko->mixer, audio_device) != 0 || snd_mixer_selem_register(openmoko->mixer, NULL, NULL) || snd_mixer_load(openmoko->mixer) != 0) { _openmoko_mixer_close(openmoko); return -1; } for(elem = snd_mixer_first_elem(openmoko->mixer); elem != NULL; elem = snd_mixer_elem_next(elem)) if(strcmp(snd_mixer_selem_get_name(elem), "Headphone") == 0 && snd_mixer_selem_has_playback_volume(elem)) openmoko->mixer_elem_headphone = elem; else if(strcmp(snd_mixer_selem_get_name(elem), "Speaker") == 0 && snd_mixer_selem_has_playback_volume(elem)) openmoko->mixer_elem_speaker = elem; #endif /* __linux__ */ return 0; }
/* * Class: org_tritonus_lowlevel_alsa_AlsaMixerElement * Method: getName * Signature: ()Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_org_tritonus_lowlevel_alsa_AlsaMixerElement_getName (JNIEnv* env, jobject obj) { snd_mixer_elem_t* handle; jstring name; if (debug_flag) { (void) fprintf(debug_file, "Java_org_tritonus_lowlevel_alsa_AlsaMixerElement_getName(): begin\n"); } handle = getHandle(env, obj); name = (*env)->NewStringUTF(env, snd_mixer_selem_get_name(handle)); if (debug_flag) { (void) fprintf(debug_file, "Java_org_tritonus_lowlevel_alsa_AlsaMixerElement_getName(): end\n"); } return name; }
static snd_mixer_elem_t* find_playback_mixer_element(snd_mixer_t *mixer, const char *name) { snd_mixer_elem_t *mixer_elem; for (mixer_elem = snd_mixer_first_elem(mixer); mixer_elem != NULL; mixer_elem = snd_mixer_elem_next(mixer_elem)) { const char *elem_name = snd_mixer_selem_get_name(mixer_elem); if ((elem_name != NULL) && snd_mixer_selem_has_playback_volume(mixer_elem) && (!strcmp(name, elem_name))) { return mixer_elem; } } return NULL; }
static gint _j4status_alsa_section_mixer_callback(snd_mixer_t *mixer, guint mask, snd_mixer_elem_t *elem) { J4statusAlsaSection *section = snd_mixer_get_callback_private(mixer); if ( mask & SND_CTL_EVENT_MASK_ADD ) { if ( ( snd_mixer_selem_get_index(elem) == 0 ) && ( g_strcmp0(snd_mixer_selem_get_name(elem), "Master") == 0 ) && snd_mixer_selem_has_playback_channel(elem, SND_MIXER_SCHN_FRONT_LEFT) && ( snd_mixer_elem_get_callback_private(elem) == NULL ) ) { snd_mixer_elem_set_callback(elem, _j4status_alsa_section_elem_callback); snd_mixer_elem_set_callback_private(elem, section); } } return 0; }
gboolean gam_toggle_get_state (GamToggle *gam_toggle) { GamTogglePrivate *priv; gint value = 0; priv = GAM_TOGGLE_GET_PRIVATE (gam_toggle); if (snd_mixer_selem_has_playback_switch (priv->elem)) { snd_mixer_selem_get_playback_switch (priv->elem, 0, &value); } else if (snd_mixer_selem_has_capture_switch (priv->elem)) { snd_mixer_selem_get_capture_switch (priv->elem, 0, &value); } else { g_warning ("%s (). No idea what to do for mixer element \"%s\"!", __FUNCTION__, snd_mixer_selem_get_name (priv->elem)); } return value; }
INT32 PORT_GetPortCount(void* id) { PortMixer* portMixer; snd_mixer_elem_t *elem; TRACE0("> PORT_GetPortCount\n"); if (id == NULL) { // $$mp: Should become a descriptive error code (invalid handle). return -1; } portMixer = (PortMixer*) id; if (portMixer->numElems == 0) { for (elem = snd_mixer_first_elem(portMixer->mixer_handle); elem; elem = snd_mixer_elem_next(elem)) { if (!snd_mixer_selem_is_active(elem)) continue; TRACE2("Simple mixer control '%s',%i\n", snd_mixer_selem_get_name(elem), snd_mixer_selem_get_index(elem)); if (snd_mixer_selem_has_playback_volume(elem)) { portMixer->elems[portMixer->numElems] = elem; portMixer->types[portMixer->numElems] = PORT_DST_UNKNOWN; portMixer->numElems++; } // to prevent buffer overflow if (portMixer->numElems >= MAX_ELEMS) { break; } /* If an element has both playback an capture volume, it is put into the arrays twice. */ if (snd_mixer_selem_has_capture_volume(elem)) { portMixer->elems[portMixer->numElems] = elem; portMixer->types[portMixer->numElems] = PORT_SRC_UNKNOWN; portMixer->numElems++; } // to prevent buffer overflow if (portMixer->numElems >= MAX_ELEMS) { break; } } } TRACE0("< PORT_GetPortCount\n"); return portMixer->numElems; }
int init_alsa_volume_control(char *name) { snd_mixer_open(&mixer,0); snd_mixer_attach(mixer,name); snd_mixer_selem_register(mixer,NULL,NULL); snd_mixer_load(mixer); mixerelem = snd_mixer_first_elem(mixer); while (mixerelem) { /* It should work on most of the systems. Tested on Debian, Fedora, Gentoo, Ubuntu, RedHat, CentOS */ if (strcasecmp(snd_mixer_selem_get_name(mixerelem), "Master") == 0) { snd_mixer_selem_get_playback_volume_range(mixerelem,&volume_min,&volume_max); return 0; } mixerelem = snd_mixer_elem_next(mixerelem); } return 1; }
INT32 PORT_GetPortName(void* id, INT32 portIndex, char* name, INT32 len) { PortMixer* portMixer; const char* nam; TRACE0("> PORT_GetPortName\n"); if (id == NULL) { // $$mp: Should become a descriptive error code (invalid handle). return -1; } portMixer = (PortMixer*) id; if (portIndex < 0 || portIndex >= portMixer->numElems) { // $$mp: Should become a descriptive error code (index out of bounds). return -1; } nam = snd_mixer_selem_get_name(portMixer->elems[portIndex]); strncpy(name, nam, len - 1); name[len - 1] = 0; TRACE0("< PORT_GetPortName\n"); return TRUE; }
void NeoControl::updateMixer() { if(screen != ScreenMixer) { return; } if(slider4->sliding || slider5->sliding) { QTimer::singleShot(100, this, SLOT(updateMixer())); return; } snd_mixer_elem_t *elem; snd_mixer_elem_t *elem4 = NULL; snd_mixer_elem_t *elem5 = NULL; for (elem = snd_mixer_first_elem(mixerFd); elem; elem = snd_mixer_elem_next(elem)) { QString elemName = QString(snd_mixer_selem_get_name(elem)); if(elemName == "Speaker") { elem4 = elem; } else if(elemName == "Mono Playback") { elem5 = elem; } } slider4->setMixerElem(elem4, true); slider5->setMixerElem(elem5, true); label4->setText(tr("Playback (control.4) %1").arg(slider4->volume)); // Mono Playback Volume label5->setText(tr("Microphone (control.5) %1").arg(slider5->volume)); // Mono Sidetone Playback Volume label->setText(tr("Call volume settings")); QTimer::singleShot(1000, this, SLOT(updateMixer())); }
/** * Get all playable channels for a single alsa card and * return them as a GSList. * * @param card HCTL name of the alsa card * @return the GSList of channels */ static GSList * get_channels(const char *card) { int ccount, i; snd_mixer_t *mixer; snd_mixer_elem_t *telem; GSList *channels = NULL; mixer = open_mixer(card, NULL, 0); if (mixer == NULL) return NULL; ccount = snd_mixer_get_count(mixer); telem = snd_mixer_first_elem(mixer); for (i = 0; i < ccount; i++) { if (snd_mixer_selem_has_playback_volume(telem)) channels = g_slist_append(channels, strdup(snd_mixer_selem_get_name(telem))); telem = snd_mixer_elem_next(telem); } #ifdef DEBUG GSList *tmp = channels; if (tmp) { printf("Card %s: available channels\n", card); while (tmp) { printf("\t%s\n", (char *) tmp->data); tmp = tmp->next; } } else { printf("Card %s: no playable channels\n", card); } #endif close_mixer(mixer, card); return channels; }
GstMixerOptions * gst_alsa_mixer_options_new (snd_mixer_elem_t * element, gint track_num) { GstMixerOptions *opts; GstAlsaMixerOptions *alsa_opts; GstMixerTrack *track; const gchar *label; gint num, i; gchar str[256]; label = snd_mixer_selem_get_name (element); opts = g_object_new (GST_ALSA_MIXER_OPTIONS_TYPE, "untranslated-label", label, NULL); alsa_opts = (GstAlsaMixerOptions *) opts; track = (GstMixerTrack *) opts; /* set basic information */ track->label = g_strdup (label); /* FIXME: translate this? */ track->num_channels = 0; track->flags = 0; alsa_opts->element = element; alsa_opts->track_num = track_num; /* get enumerations for switch/options object */ num = snd_mixer_selem_get_enum_items (element); for (i = 0; i < num; i++) { if (snd_mixer_selem_get_enum_item_name (element, i, 255, str) < 0) { g_object_unref (G_OBJECT (alsa_opts)); return NULL; } opts->values = g_list_append (opts->values, g_strdup (str)); } return opts; }
static void get_mixer_name(struct alsa_factory *af) { snd_mixer_t *handle; snd_mixer_elem_t *elem; if (snd_mixer_open(&handle, 0) < 0) return; if (snd_mixer_attach(handle, "default") < 0) { snd_mixer_close(handle); return; } if (snd_mixer_selem_register(handle, NULL, NULL) < 0) { snd_mixer_close(handle); return; } if (snd_mixer_load(handle) < 0) { snd_mixer_close(handle); return; } for (elem = snd_mixer_first_elem(handle); elem; elem = snd_mixer_elem_next(elem)) { if (snd_mixer_selem_is_active(elem) && snd_mixer_selem_has_playback_volume(elem)) { pj_ansi_strncpy(af->pb_mixer_name, snd_mixer_selem_get_name(elem), sizeof(af->pb_mixer_name)); TRACE_((THIS_FILE, "Playback mixer name: %s", af->pb_mixer_name)); break; } } snd_mixer_close(handle); }
static int simple_update(snd_mixer_elem_t *melem) { selem_none_t *simple; unsigned int caps, pchannels, cchannels; long pmin, pmax, cmin, cmax; selem_ctl_t *ctl; const char *name; caps = 0; pchannels = 0; pmin = LONG_MAX; pmax = LONG_MIN; cchannels = 0; cmin = LONG_MAX; cmax = LONG_MIN; assert(snd_mixer_elem_get_type(melem) == SND_MIXER_ELEM_SIMPLE); simple = snd_mixer_elem_get_private(melem); name = snd_mixer_selem_get_name(melem); ctl = &simple->ctls[CTL_SINGLE]; if (ctl->elem) { pchannels = cchannels = ctl->values; if (ctl->type == SND_CTL_ELEM_TYPE_INTEGER) { caps |= SM_CAP_GVOLUME; pmin = cmin = ctl->min; pmax = cmax = ctl->max; } else caps |= SM_CAP_GSWITCH; } ctl = &simple->ctls[CTL_GLOBAL_SWITCH]; if (ctl->elem) { if (pchannels < ctl->values) pchannels = ctl->values; if (cchannels < ctl->values) cchannels = ctl->values; caps |= SM_CAP_GSWITCH; } ctl = &simple->ctls[CTL_GLOBAL_ROUTE]; if (ctl->elem) { if (pchannels < ctl->values) pchannels = ctl->values; if (cchannels < ctl->values) cchannels = ctl->values; caps |= SM_CAP_GSWITCH; } ctl = &simple->ctls[CTL_GLOBAL_VOLUME]; if (ctl->elem) { if (pchannels < ctl->values) pchannels = ctl->values; if (pmin > ctl->min) pmin = ctl->min; if (pmax < ctl->max) pmax = ctl->max; if (cchannels < ctl->values) cchannels = ctl->values; if (cmin > ctl->min) cmin = ctl->min; if (cmax < ctl->max) cmax = ctl->max; caps |= SM_CAP_GVOLUME; } ctl = &simple->ctls[CTL_PLAYBACK_SWITCH]; if (ctl->elem) { if (pchannels < ctl->values) pchannels = ctl->values; caps |= SM_CAP_PSWITCH; caps &= ~SM_CAP_GSWITCH; } ctl = &simple->ctls[CTL_PLAYBACK_ROUTE]; if (ctl->elem) { if (pchannels < ctl->values) pchannels = ctl->values; caps |= SM_CAP_PSWITCH; caps &= ~SM_CAP_GSWITCH; } ctl = &simple->ctls[CTL_CAPTURE_SWITCH]; if (ctl->elem) { if (cchannels < ctl->values) cchannels = ctl->values; caps |= SM_CAP_CSWITCH; caps &= ~SM_CAP_GSWITCH; } ctl = &simple->ctls[CTL_CAPTURE_ROUTE]; if (ctl->elem) { if (cchannels < ctl->values) cchannels = ctl->values; caps |= SM_CAP_CSWITCH; caps &= ~SM_CAP_GSWITCH; } ctl = &simple->ctls[CTL_PLAYBACK_VOLUME]; if (ctl->elem) { if (pchannels < ctl->values) pchannels = ctl->values; if (pmin > ctl->min) pmin = ctl->min; if (pmax < ctl->max) pmax = ctl->max; caps |= SM_CAP_PVOLUME; caps &= ~SM_CAP_GVOLUME; } ctl = &simple->ctls[CTL_CAPTURE_VOLUME]; if (ctl->elem) { if (cchannels < ctl->values) cchannels = ctl->values; if (cmin > ctl->min) cmin = ctl->min; if (cmax < ctl->max) cmax = ctl->max; caps |= SM_CAP_CVOLUME; caps &= ~SM_CAP_GVOLUME; } ctl = &simple->ctls[CTL_CAPTURE_SOURCE]; if (ctl->elem) { if (cchannels < ctl->values) cchannels = ctl->values; caps |= SM_CAP_CSWITCH | SM_CAP_CSWITCH_EXCL; caps &= ~SM_CAP_GSWITCH; } ctl = &simple->ctls[CTL_GLOBAL_ENUM]; if (ctl->elem) { if (pchannels < ctl->values) pchannels = ctl->values; caps |= SM_CAP_PENUM | SM_CAP_CENUM; } ctl = &simple->ctls[CTL_PLAYBACK_ENUM]; if (ctl->elem) { if (pchannels < ctl->values) pchannels = ctl->values; caps |= SM_CAP_PENUM; } ctl = &simple->ctls[CTL_CAPTURE_ENUM]; if (ctl->elem) { if (pchannels < ctl->values) pchannels = ctl->values; caps |= SM_CAP_CENUM; } if (pchannels > 32) pchannels = 32; if (cchannels > 32) cchannels = 32; if (caps & (SM_CAP_GSWITCH|SM_CAP_PSWITCH)) caps |= SM_CAP_PSWITCH_JOIN; if (caps & (SM_CAP_GVOLUME|SM_CAP_PVOLUME)) caps |= SM_CAP_PVOLUME_JOIN; if (caps & (SM_CAP_GSWITCH|SM_CAP_CSWITCH)) caps |= SM_CAP_CSWITCH_JOIN; if (caps & (SM_CAP_GVOLUME|SM_CAP_CVOLUME)) caps |= SM_CAP_CVOLUME_JOIN; if (pchannels > 1 || cchannels > 1) { if (simple->ctls[CTL_SINGLE].elem && simple->ctls[CTL_SINGLE].values > 1) { if (caps & SM_CAP_GSWITCH) caps &= ~(SM_CAP_PSWITCH_JOIN|SM_CAP_CSWITCH_JOIN); else caps &= ~(SM_CAP_PVOLUME_JOIN|SM_CAP_CVOLUME_JOIN); } if (simple->ctls[CTL_GLOBAL_ROUTE].elem || (simple->ctls[CTL_GLOBAL_SWITCH].elem && simple->ctls[CTL_GLOBAL_SWITCH].values > 1)) { caps &= ~(SM_CAP_PSWITCH_JOIN|SM_CAP_CSWITCH_JOIN); } if (simple->ctls[CTL_GLOBAL_VOLUME].elem && simple->ctls[CTL_GLOBAL_VOLUME].values > 1) { caps &= ~(SM_CAP_PVOLUME_JOIN|SM_CAP_CVOLUME_JOIN); } } if (pchannels > 1) { if (simple->ctls[CTL_PLAYBACK_ROUTE].elem || (simple->ctls[CTL_PLAYBACK_SWITCH].elem && simple->ctls[CTL_PLAYBACK_SWITCH].values > 1)) { caps &= ~SM_CAP_PSWITCH_JOIN; } if (simple->ctls[CTL_PLAYBACK_VOLUME].elem && simple->ctls[CTL_PLAYBACK_VOLUME].values > 1) { caps &= ~SM_CAP_PVOLUME_JOIN; } } if (cchannels > 1) { if (simple->ctls[CTL_CAPTURE_ROUTE].elem || (simple->ctls[CTL_CAPTURE_SWITCH].elem && simple->ctls[CTL_CAPTURE_SWITCH].values > 1) || (simple->ctls[CTL_CAPTURE_SOURCE].elem && simple->ctls[CTL_CAPTURE_SOURCE].values > 1)) { caps &= ~SM_CAP_CSWITCH_JOIN; } if (simple->ctls[CTL_CAPTURE_VOLUME].elem && simple->ctls[CTL_CAPTURE_VOLUME].values > 1) { caps &= ~SM_CAP_CVOLUME_JOIN; } } /* exceptions */ if ((caps & (SM_CAP_GSWITCH|SM_CAP_PSWITCH|SM_CAP_CSWITCH)) && (caps & (SM_CAP_GSWITCH|SM_CAP_PSWITCH|SM_CAP_CSWITCH)) == (caps & SM_CAP_GSWITCH)) { caps &= ~(SM_CAP_GSWITCH|SM_CAP_CSWITCH_JOIN|SM_CAP_CSWITCH_EXCL); caps |= SM_CAP_PSWITCH; } if ((caps & SM_CAP_GSWITCH) && (caps & (SM_CAP_PSWITCH|SM_CAP_CSWITCH)) == 0) caps |= SM_CAP_PSWITCH|SM_CAP_CSWITCH; if ((caps & SM_CAP_GVOLUME) && (caps & (SM_CAP_PVOLUME|SM_CAP_CVOLUME)) == 0) caps |= SM_CAP_PVOLUME|SM_CAP_CVOLUME; simple->selem.caps = caps; simple->str[SM_PLAY].channels = pchannels; if (!simple->str[SM_PLAY].range) { simple->str[SM_PLAY].min = pmin != LONG_MAX ? pmin : 0; simple->str[SM_PLAY].max = pmax != LONG_MIN ? pmax : 0; } simple->str[SM_CAPT].channels = cchannels; if (!simple->str[SM_CAPT].range) { simple->str[SM_CAPT].min = cmin != LONG_MAX ? cmin : 0; simple->str[SM_CAPT].max = cmax != LONG_MIN ? cmax : 0; } return 0; }
static void gst_alsa_mixer_ensure_track_list (GstAlsaMixer * mixer) { gint i, count; snd_mixer_elem_t *element, *master; GList *item; g_return_if_fail (mixer->handle != NULL); if (mixer->tracklist) return; g_static_rec_mutex_lock (mixer->rec_mutex); master = gst_alsa_mixer_find_master_mixer (mixer, mixer->handle); count = snd_mixer_get_count (mixer->handle); element = snd_mixer_first_elem (mixer->handle); /* build track list * * Some ALSA tracks may have playback and capture capabilities. * Here we model them as two separate GStreamer tracks. */ for (i = 0; i < count; i++) { GstMixerTrack *play_track = NULL; GstMixerTrack *cap_track = NULL; const gchar *name; GList *item; gint samename = 0; name = snd_mixer_selem_get_name (element); /* prevent dup names */ for (item = mixer->tracklist; item != NULL; item = item->next) { snd_mixer_elem_t *temp; if (GST_IS_ALSA_MIXER_OPTIONS (item->data)) temp = GST_ALSA_MIXER_OPTIONS (item->data)->element; else temp = GST_ALSA_MIXER_TRACK (item->data)->element; if (strcmp (name, snd_mixer_selem_get_name (temp)) == 0) samename++; } GST_LOG ("[%s] probing element #%u, mixer->dir=%u", name, i, mixer->dir); if (mixer->dir & GST_ALSA_MIXER_PLAYBACK) { gboolean has_playback_switch, has_playback_volume; has_playback_switch = snd_mixer_selem_has_playback_switch (element); has_playback_volume = snd_mixer_selem_has_playback_volume (element); GST_LOG ("[%s] PLAYBACK: has_playback_volume=%d, has_playback_switch=%d" "%s", name, has_playback_volume, has_playback_switch, (element == master) ? " MASTER" : ""); if (has_playback_volume) { gint flags = GST_MIXER_TRACK_OUTPUT; if (element == master) flags |= GST_MIXER_TRACK_MASTER; play_track = gst_alsa_mixer_track_new (element, samename, i, flags, FALSE, NULL, FALSE); } else if (has_playback_switch) { /* simple mute switch */ play_track = gst_alsa_mixer_track_new (element, samename, i, GST_MIXER_TRACK_OUTPUT, TRUE, NULL, FALSE); } if (snd_mixer_selem_is_enumerated (element)) { GstMixerOptions *opts = gst_alsa_mixer_options_new (element, i); GST_LOG ("[%s] is enumerated (%d)", name, i); mixer->tracklist = g_list_append (mixer->tracklist, opts); } } if (mixer->dir & GST_ALSA_MIXER_CAPTURE) { gboolean has_capture_switch, has_common_switch; gboolean has_capture_volume, has_common_volume; has_capture_switch = snd_mixer_selem_has_capture_switch (element); has_common_switch = snd_mixer_selem_has_common_switch (element); has_capture_volume = snd_mixer_selem_has_capture_volume (element); has_common_volume = snd_mixer_selem_has_common_volume (element); GST_LOG ("[%s] CAPTURE: has_capture_volume=%d, has_common_volume=%d, " "has_capture_switch=%d, has_common_switch=%d, play_track=%p", name, has_capture_volume, has_common_volume, has_capture_switch, has_common_switch, play_track); if (has_capture_volume && !(play_track && has_common_volume)) { cap_track = gst_alsa_mixer_track_new (element, samename, i, GST_MIXER_TRACK_INPUT, FALSE, NULL, play_track != NULL); } else if (has_capture_switch && !(play_track && has_common_switch)) { cap_track = gst_alsa_mixer_track_new (element, samename, i, GST_MIXER_TRACK_INPUT, TRUE, NULL, play_track != NULL); } } if (play_track && cap_track) { GST_ALSA_MIXER_TRACK (play_track)->shared_mute = GST_ALSA_MIXER_TRACK (cap_track); GST_ALSA_MIXER_TRACK (cap_track)->shared_mute = GST_ALSA_MIXER_TRACK (play_track); } if (play_track) mixer->tracklist = g_list_append (mixer->tracklist, play_track); if (cap_track) mixer->tracklist = g_list_append (mixer->tracklist, cap_track); element = snd_mixer_elem_next (element); } for (item = mixer->tracklist; item != NULL; item = item->next) { snd_mixer_elem_t *temp; if (GST_IS_ALSA_MIXER_OPTIONS (item->data)) temp = GST_ALSA_MIXER_OPTIONS (item->data)->element; else temp = GST_ALSA_MIXER_TRACK (item->data)->element; snd_mixer_elem_set_callback (temp, gst_alsa_mixer_elem_handle_callback); snd_mixer_elem_set_callback_private (temp, mixer); } g_static_rec_mutex_unlock (mixer->rec_mutex); }