c - Set mixer as "default" ALSA API -
i wrote code open , control mixer volume:
char *card, *channel; snd_mixer_t *handle = null; snd_mixer_elem_t *elem = null; static long alsa_min, alsa_max; void alsa_open_mixer( void ) { int err; static snd_mixer_selem_id_t *sid = null; if ((err = snd_mixer_open (&handle, 0)) < 0) return; if ((err = snd_mixer_attach (handle, card)) < 0) goto error; if ((err = snd_mixer_selem_register (handle, null, null)) < 0) goto error; if ((err = snd_mixer_load (handle)) < 0) goto error; snd_mixer_selem_id_malloc(&sid); if (sid == null) goto error; snd_mixer_selem_id_set_name(sid, channel); if (!(elem = snd_mixer_find_selem(handle, sid))) goto error; if (!snd_mixer_selem_has_playback_volume(elem)) goto error; snd_mixer_selem_get_playback_volume_range(elem, &alsa_min, &alsa_max); if ((alsa_max - alsa_min) <= 0) goto error; snd_mixer_selem_id_free(sid); return; error: if (sid != null) { snd_mixer_selem_id_free(sid); sid = null; } if (handle) { snd_mixer_close(handle); handle = null; } return; } int alsa_set_device( const char *devname ) { int i; if (card) free(card); card = strdup( devname ); if( !card ) return 0; = strcspn( card, "/" ); if( == strlen( card ) ) { channel = "line"; } else { card[i] = 0; channel = card + + 1; } alsa_open_mixer(); if (!handle) { fprintf( stderr, "mixer: can't open mixer '%s'.\n", card ); return 0; } return 1; }
my questions way can open mixer with:
alsa_set_device( "hw:0" )
and with:
alsa_set_device( "default" )
got error:
mixer: can't open mixer 'default'.
also want write plugin capture audio stream tv card , output them in default mainboard sound card. want can control stream volume application using alsa api.
maybe have porting pulseaudio instead. in case need pulse mixer code equivalent above code.
thanks
Comments
Post a Comment