我写了一个代码来打开和控制混音器音量:
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;
i = strcspn( card, "/" );
if( i == strlen( card ) ) {
channel = "Line";
} else {
card[i] = 0;
channel = card + i + 1;
}
alsa_open_mixer();
if (!handle) {
fprintf( stderr, "mixer: Can't open mixer '%s'.\n", card );
return 0;
}
return 1;
}
我的问题是打开调音台的方式:
alsa_set_device( "hw:0" )
和:
alsa_set_device( "default" )
得到错误:
mixer: Can't open mixer 'default'.
另外,我想编写一个插件来捕获来自电视卡的音频流,并将其输出到默认的主板声卡中。我希望能够使用我的应用程序控制流量 ALSA API。
可能已经移植到PulseAudio了。在这种情况下,我需要与上述代码等效的脉冲混合器代码的帮助。
由于