ミキサーの音量を開いて制御するコードを書きました。
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'.
また、TV カードからオーディオ ストリームをキャプチャし、デフォルトのメインボード サウンド カードに出力するプラグインを作成したいと考えています。ALSA API を使用して、アプリケーションからストリーム ボリュームを制御したいと考えています。
代わりに PulseAudio に移植する必要があるかもしれません。この場合、上記のコードと同等のパルス ミキサー コードの助けが必要です。
ありがとう