我想从 snd_mixer_selem_get_id 函数返回 char 数组:
char* alsa_get_channel_name( void )
{
int err;
snd_mixer_selem_id_t *sid;
snd_mixer_elem_t *elem;
if ((err = snd_mixer_open (&handle, 0)) < 0) {
fprintf(stderr, "mixer: open error: %s\n", snd_strerror(err));
}
if ((err = snd_mixer_attach (handle, card)) < 0) {
fprintf(stderr, "mixer: attach error: %s\n", snd_strerror(err));
}
if ((err = snd_mixer_selem_register (handle, NULL, NULL)) < 0) {
fprintf(stderr, "mixer: register error: %s\n", snd_strerror(err));
}
if ((err = snd_mixer_load (handle)) < 0) {
fprintf(stderr, "mixer: load error: %s\n", snd_strerror(err));
}
snd_mixer_selem_id_alloca(&sid);
for (elem = snd_mixer_first_elem(handle); elem; elem = snd_mixer_elem_next(elem)) {
if ((!snd_mixer_selem_is_active(elem))
continue;
snd_mixer_selem_get_id(elem, sid);
const char *name = snd_mixer_selem_id_get_name(sid);
if (name)
sprintf(name, sizeof(name), "%s", snd_mixer_selem_get_name(elem));
}
snd_mixer_close(handle);
return name;
}
我不知道怎么写 sprintf(name, sizeof(name), "%s", snd_mixer_selem_get_name(elem)); 返回频道名称。
谢谢