Completed control and mixer API

This commit is contained in:
Abramo Bagnara 2001-02-09 11:20:32 +00:00
parent 7b2cc96f18
commit 012584247c
4 changed files with 508 additions and 471 deletions

View file

@ -63,16 +63,16 @@ static void help(void)
printf(" from configuration file\n"); printf(" from configuration file\n");
} }
char *id_str(snd_ctl_element_id_t *id) char *id_str(snd_ctl_elem_id_t *id)
{ {
static char str[128]; static char str[128];
assert(id); assert(id);
sprintf(str, "%i,%i,%i,%s,%i", sprintf(str, "%i,%i,%i,%s,%i",
snd_enum_to_int(snd_ctl_element_id_get_interface(id)), snd_enum_to_int(snd_ctl_elem_id_get_interface(id)),
snd_ctl_element_id_get_device(id), snd_ctl_elem_id_get_device(id),
snd_ctl_element_id_get_subdevice(id), snd_ctl_elem_id_get_subdevice(id),
snd_ctl_element_id_get_name(id), snd_ctl_elem_id_get_name(id),
snd_ctl_element_id_get_index(id)); snd_ctl_elem_id_get_index(id));
return str; return str;
} }
@ -140,10 +140,10 @@ static int snd_config_compound_add(snd_config_t *father, const char *id, int joi
return 0; return 0;
} }
static int get_control(snd_ctl_t *handle, snd_ctl_element_id_t *id, snd_config_t *top) static int get_control(snd_ctl_t *handle, snd_ctl_elem_id_t *id, snd_config_t *top)
{ {
snd_ctl_element_t *ctl; snd_ctl_elem_t *ctl;
snd_ctl_element_info_t *info; snd_ctl_elem_info_t *info;
snd_config_t *control, *comment, *item, *value; snd_config_t *control, *comment, *item, *value;
const char *s; const char *s;
char buf[256]; char buf[256];
@ -151,27 +151,27 @@ static int get_control(snd_ctl_t *handle, snd_ctl_element_id_t *id, snd_config_t
int err; int err;
unsigned int device, subdevice, index; unsigned int device, subdevice, index;
const char *name; const char *name;
snd_ctl_element_type_t type; snd_ctl_elem_type_t type;
unsigned int count; unsigned int count;
snd_ctl_element_alloca(&ctl); snd_ctl_elem_alloca(&ctl);
snd_ctl_element_info_alloca(&info); snd_ctl_elem_info_alloca(&info);
snd_ctl_element_info_set_id(info, id); snd_ctl_elem_info_set_id(info, id);
err = snd_ctl_element_info(handle, info); err = snd_ctl_elem_info(handle, info);
if (err < 0) { if (err < 0) {
error("Cannot read control info '%s': %s", id_str(id), snd_strerror(err)); error("Cannot read control info '%s': %s", id_str(id), snd_strerror(err));
return err; return err;
} }
if (!snd_ctl_element_info_is_readable(info)) if (!snd_ctl_elem_info_is_readable(info))
return 0; return 0;
snd_ctl_element_set_id(ctl, id); snd_ctl_elem_set_id(ctl, id);
err = snd_ctl_element_read(handle, ctl); err = snd_ctl_elem_read(handle, ctl);
if (err < 0) { if (err < 0) {
error("Cannot read control '%s': %s", id_str(id), snd_strerror(err)); error("Cannot read control '%s': %s", id_str(id), snd_strerror(err));
return err; return err;
} }
err = snd_config_compound_add(top, num_str(snd_ctl_element_info_get_numid(info)), 0, &control); err = snd_config_compound_add(top, num_str(snd_ctl_elem_info_get_numid(info)), 0, &control);
if (err < 0) { if (err < 0) {
error("snd_config_compound_add: %s", snd_strerror(err)); error("snd_config_compound_add: %s", snd_strerror(err));
return err; return err;
@ -184,17 +184,17 @@ static int get_control(snd_ctl_t *handle, snd_ctl_element_id_t *id, snd_config_t
buf[0] = '\0'; buf[0] = '\0';
buf[1] = '\0'; buf[1] = '\0';
if (snd_ctl_element_info_is_readable(info)) if (snd_ctl_elem_info_is_readable(info))
strcat(buf, " read"); strcat(buf, " read");
if (snd_ctl_element_info_is_writable(info)) if (snd_ctl_elem_info_is_writable(info))
strcat(buf, " write"); strcat(buf, " write");
if (snd_ctl_element_info_is_inactive(info)) if (snd_ctl_elem_info_is_inactive(info))
strcat(buf, " inactive"); strcat(buf, " inactive");
if (snd_ctl_element_info_is_volatile(info)) if (snd_ctl_elem_info_is_volatile(info))
strcat(buf, " volatile"); strcat(buf, " volatile");
if (snd_ctl_element_info_is_locked(info)) if (snd_ctl_elem_info_is_locked(info))
strcat(buf, " locked"); strcat(buf, " locked");
if (snd_ctl_element_info_is_indirect(info)) if (snd_ctl_elem_info_is_indirect(info))
strcat(buf, " indirect"); strcat(buf, " indirect");
err = snd_config_string_add(comment, "access", buf + 1); err = snd_config_string_add(comment, "access", buf + 1);
if (err < 0) { if (err < 0) {
@ -202,13 +202,13 @@ static int get_control(snd_ctl_t *handle, snd_ctl_element_id_t *id, snd_config_t
return err; return err;
} }
type = snd_ctl_element_info_get_type(info); type = snd_ctl_elem_info_get_type(info);
device = snd_ctl_element_info_get_device(info); device = snd_ctl_elem_info_get_device(info);
subdevice = snd_ctl_element_info_get_subdevice(info); subdevice = snd_ctl_elem_info_get_subdevice(info);
index = snd_ctl_element_info_get_index(info); index = snd_ctl_elem_info_get_index(info);
name = snd_ctl_element_info_get_name(info); name = snd_ctl_elem_info_get_name(info);
count = snd_ctl_element_info_get_count(info); count = snd_ctl_elem_info_get_count(info);
s = snd_ctl_element_type_name(type); s = snd_ctl_elem_type_name(type);
err = snd_config_string_add(comment, "type", s); err = snd_config_string_add(comment, "type", s);
if (err < 0) { if (err < 0) {
error("snd_config_string_add: %s", snd_strerror(err)); error("snd_config_string_add: %s", snd_strerror(err));
@ -216,13 +216,13 @@ static int get_control(snd_ctl_t *handle, snd_ctl_element_id_t *id, snd_config_t
} }
switch (snd_enum_to_int(type)) { switch (snd_enum_to_int(type)) {
case SND_CTL_ELEMENT_TYPE_BOOLEAN: case SND_CTL_ELEM_TYPE_BOOLEAN:
break; break;
case SND_CTL_ELEMENT_TYPE_INTEGER: case SND_CTL_ELEM_TYPE_INTEGER:
{ {
long min = snd_ctl_element_info_get_min(info); long min = snd_ctl_elem_info_get_min(info);
long max = snd_ctl_element_info_get_max(info); long max = snd_ctl_elem_info_get_max(info);
long step = snd_ctl_element_info_get_step(info); long step = snd_ctl_elem_info_get_step(info);
if (step) if (step)
sprintf(buf, "%li - %li (step %li)", min, max, step); sprintf(buf, "%li - %li (step %li)", min, max, step);
else else
@ -234,7 +234,7 @@ static int get_control(snd_ctl_t *handle, snd_ctl_element_id_t *id, snd_config_t
} }
break; break;
} }
case SND_CTL_ELEMENT_TYPE_ENUMERATED: case SND_CTL_ELEM_TYPE_ENUMERATED:
{ {
unsigned int items; unsigned int items;
err = snd_config_compound_add(comment, "item", 1, &item); err = snd_config_compound_add(comment, "item", 1, &item);
@ -242,15 +242,15 @@ static int get_control(snd_ctl_t *handle, snd_ctl_element_id_t *id, snd_config_t
error("snd_config_compound_add: %s", snd_strerror(err)); error("snd_config_compound_add: %s", snd_strerror(err));
return err; return err;
} }
items = snd_ctl_element_info_get_items(info); items = snd_ctl_elem_info_get_items(info);
for (idx = 0; idx < items; idx++) { for (idx = 0; idx < items; idx++) {
snd_ctl_element_info_set_item(info, idx); snd_ctl_elem_info_set_item(info, idx);
err = snd_ctl_element_info(handle, info); err = snd_ctl_elem_info(handle, info);
if (err < 0) { if (err < 0) {
error("snd_ctl_card_info: %s", snd_strerror(err)); error("snd_ctl_card_info: %s", snd_strerror(err));
return err; return err;
} }
err = snd_config_string_add(item, num_str(idx), snd_ctl_element_info_get_item_name(info)); err = snd_config_string_add(item, num_str(idx), snd_ctl_elem_info_get_item_name(info));
if (err < 0) { if (err < 0) {
error("snd_config_string_add: %s", snd_strerror(err)); error("snd_config_string_add: %s", snd_strerror(err));
return err; return err;
@ -261,7 +261,7 @@ static int get_control(snd_ctl_t *handle, snd_ctl_element_id_t *id, snd_config_t
default: default:
break; break;
} }
s = snd_ctl_element_iface_name(snd_ctl_element_info_get_interface(info)); s = snd_ctl_elem_iface_name(snd_ctl_elem_info_get_interface(info));
err = snd_config_string_add(control, "iface", s); err = snd_config_string_add(control, "iface", s);
if (err < 0) { if (err < 0) {
error("snd_config_string_add: %s", snd_strerror(err)); error("snd_config_string_add: %s", snd_strerror(err));
@ -295,15 +295,15 @@ static int get_control(snd_ctl_t *handle, snd_ctl_element_id_t *id, snd_config_t
} }
switch (snd_enum_to_int(type)) { switch (snd_enum_to_int(type)) {
case SND_CTL_ELEMENT_TYPE_BYTES: case SND_CTL_ELEM_TYPE_BYTES:
case SND_CTL_ELEMENT_TYPE_IEC958: case SND_CTL_ELEM_TYPE_IEC958:
{ {
size_t size = type == SND_CTL_ELEMENT_TYPE_BYTES ? size_t size = type == SND_CTL_ELEM_TYPE_BYTES ?
count : sizeof(snd_aes_iec958_t); count : sizeof(snd_aes_iec958_t);
char buf[size * 2 + 1]; char buf[size * 2 + 1];
char *p = buf; char *p = buf;
char *hex = "0123456789abcdef"; char *hex = "0123456789abcdef";
const unsigned char *bytes = snd_ctl_element_get_bytes(ctl); const unsigned char *bytes = snd_ctl_elem_get_bytes(ctl);
for (idx = 0; idx < size; idx++) { for (idx = 0; idx < size; idx++) {
int v = bytes[idx]; int v = bytes[idx];
*p++ = hex[v >> 4]; *p++ = hex[v >> 4];
@ -323,23 +323,23 @@ static int get_control(snd_ctl_t *handle, snd_ctl_element_id_t *id, snd_config_t
if (count == 1) { if (count == 1) {
switch (snd_enum_to_int(type)) { switch (snd_enum_to_int(type)) {
case SND_CTL_ELEMENT_TYPE_BOOLEAN: case SND_CTL_ELEM_TYPE_BOOLEAN:
err = snd_config_string_add(control, "value", snd_ctl_element_get_boolean(ctl, 0) ? "true" : "false"); err = snd_config_string_add(control, "value", snd_ctl_elem_get_boolean(ctl, 0) ? "true" : "false");
if (err < 0) { if (err < 0) {
error("snd_config_string_add: %s", snd_strerror(err)); error("snd_config_string_add: %s", snd_strerror(err));
return err; return err;
} }
return 0; return 0;
case SND_CTL_ELEMENT_TYPE_INTEGER: case SND_CTL_ELEM_TYPE_INTEGER:
err = snd_config_integer_add(control, "value", snd_ctl_element_get_integer(ctl, 0)); err = snd_config_integer_add(control, "value", snd_ctl_elem_get_integer(ctl, 0));
if (err < 0) { if (err < 0) {
error("snd_config_integer_add: %s", snd_strerror(err)); error("snd_config_integer_add: %s", snd_strerror(err));
return err; return err;
} }
return 0; return 0;
case SND_CTL_ELEMENT_TYPE_ENUMERATED: case SND_CTL_ELEM_TYPE_ENUMERATED:
{ {
unsigned int v = snd_ctl_element_get_enumerated(ctl, 0); unsigned int v = snd_ctl_elem_get_enumerated(ctl, 0);
snd_config_t *c; snd_config_t *c;
err = snd_config_search(item, num_str(v), &c); err = snd_config_search(item, num_str(v), &c);
if (err == 0) { if (err == 0) {
@ -366,27 +366,27 @@ static int get_control(snd_ctl_t *handle, snd_ctl_element_id_t *id, snd_config_t
} }
switch (snd_enum_to_int(type)) { switch (snd_enum_to_int(type)) {
case SND_CTL_ELEMENT_TYPE_BOOLEAN: case SND_CTL_ELEM_TYPE_BOOLEAN:
for (idx = 0; idx < count; idx++) { for (idx = 0; idx < count; idx++) {
err = snd_config_string_add(value, num_str(idx), snd_ctl_element_get_boolean(ctl, idx) ? "true" : "false"); err = snd_config_string_add(value, num_str(idx), snd_ctl_elem_get_boolean(ctl, idx) ? "true" : "false");
if (err < 0) { if (err < 0) {
error("snd_config_string_add: %s", snd_strerror(err)); error("snd_config_string_add: %s", snd_strerror(err));
return err; return err;
} }
} }
break; break;
case SND_CTL_ELEMENT_TYPE_INTEGER: case SND_CTL_ELEM_TYPE_INTEGER:
for (idx = 0; idx < count; idx++) { for (idx = 0; idx < count; idx++) {
err = snd_config_integer_add(value, num_str(idx), snd_ctl_element_get_integer(ctl, idx)); err = snd_config_integer_add(value, num_str(idx), snd_ctl_elem_get_integer(ctl, idx));
if (err < 0) { if (err < 0) {
error("snd_config_integer_add: %s", snd_strerror(err)); error("snd_config_integer_add: %s", snd_strerror(err));
return err; return err;
} }
} }
break; break;
case SND_CTL_ELEMENT_TYPE_ENUMERATED: case SND_CTL_ELEM_TYPE_ENUMERATED:
for (idx = 0; idx < count; idx++) { for (idx = 0; idx < count; idx++) {
unsigned int v = snd_ctl_element_get_enumerated(ctl, idx); unsigned int v = snd_ctl_elem_get_enumerated(ctl, idx);
snd_config_t *c; snd_config_t *c;
err = snd_config_search(item, num_str(v), &c); err = snd_config_search(item, num_str(v), &c);
if (err == 0) { if (err == 0) {
@ -415,14 +415,14 @@ static int get_controls(int cardno, snd_config_t *top)
snd_ctl_t *handle; snd_ctl_t *handle;
snd_ctl_card_info_t *info; snd_ctl_card_info_t *info;
snd_config_t *state, *card, *control; snd_config_t *state, *card, *control;
snd_ctl_element_list_t *list; snd_ctl_elem_list_t *list;
unsigned int idx; unsigned int idx;
int err; int err;
char name[32]; char name[32];
unsigned int count; unsigned int count;
const char *id; const char *id;
snd_ctl_card_info_alloca(&info); snd_ctl_card_info_alloca(&info);
snd_ctl_element_list_alloca(&list); snd_ctl_elem_list_alloca(&list);
sprintf(name, "hw:%d", cardno); sprintf(name, "hw:%d", cardno);
err = snd_ctl_open(&handle, name); err = snd_ctl_open(&handle, name);
@ -477,29 +477,29 @@ static int get_controls(int cardno, snd_config_t *top)
error("snd_config_compound_add: %s", snd_strerror(err)); error("snd_config_compound_add: %s", snd_strerror(err));
goto _close; goto _close;
} }
err = snd_ctl_clist(handle, list); err = snd_ctl_elem_list(handle, list);
if (err < 0) { if (err < 0) {
error("Cannot determine controls: %s", snd_strerror(err)); error("Cannot determine controls: %s", snd_strerror(err));
goto _close; goto _close;
} }
count = snd_ctl_element_list_get_count(list); count = snd_ctl_elem_list_get_count(list);
if (count <= 0) { if (count <= 0) {
err = 0; err = 0;
goto _close; goto _close;
} }
snd_ctl_element_list_set_offset(list, 0); snd_ctl_elem_list_set_offset(list, 0);
if (snd_ctl_element_list_alloc_space(list, count) < 0) { if (snd_ctl_elem_list_alloc_space(list, count) < 0) {
error("No enough memory..."); error("No enough memory...");
goto _close; goto _close;
} }
if ((err = snd_ctl_clist(handle, list)) < 0) { if ((err = snd_ctl_elem_list(handle, list)) < 0) {
error("Cannot determine controls (2): %s", snd_strerror(err)); error("Cannot determine controls (2): %s", snd_strerror(err));
goto _free; goto _free;
} }
for (idx = 0; idx < count; ++idx) { for (idx = 0; idx < count; ++idx) {
snd_ctl_element_id_t *id; snd_ctl_elem_id_t *id;
snd_ctl_element_id_alloca(&id); snd_ctl_elem_id_alloca(&id);
snd_ctl_element_list_get_id(list, idx, id); snd_ctl_elem_list_get_id(list, idx, id);
err = get_control(handle, id, control); err = get_control(handle, id, control);
if (err < 0) if (err < 0)
goto _free; goto _free;
@ -507,7 +507,7 @@ static int get_controls(int cardno, snd_config_t *top)
err = 0; err = 0;
_free: _free:
snd_ctl_element_list_free_space(list); snd_ctl_elem_list_free_space(list);
_close: _close:
snd_ctl_close(handle); snd_ctl_close(handle);
return err; return err;
@ -517,7 +517,7 @@ static int get_controls(int cardno, snd_config_t *top)
static int config_iface(snd_config_t *n) static int config_iface(snd_config_t *n)
{ {
unsigned long i; unsigned long i;
snd_ctl_element_iface_t idx; snd_ctl_elem_iface_t idx;
const char *str; const char *str;
switch (snd_enum_to_int(snd_config_get_type(n))) { switch (snd_enum_to_int(snd_config_get_type(n))) {
case SND_CONFIG_TYPE_INTEGER: case SND_CONFIG_TYPE_INTEGER:
@ -529,8 +529,8 @@ static int config_iface(snd_config_t *n)
default: default:
return -1; return -1;
} }
for (idx = 0; idx <= SND_CTL_ELEMENT_IFACE_LAST; snd_enum_incr(idx)) { for (idx = 0; idx <= SND_CTL_ELEM_IFACE_LAST; snd_enum_incr(idx)) {
if (strcasecmp(snd_ctl_element_iface_name(idx), str) == 0) if (strcasecmp(snd_ctl_elem_iface_name(idx), str) == 0)
return snd_enum_to_int(idx); return snd_enum_to_int(idx);
} }
return -1; return -1;
@ -560,7 +560,7 @@ static int config_bool(snd_config_t *n)
} }
static int config_enumerated(snd_config_t *n, snd_ctl_t *handle, static int config_enumerated(snd_config_t *n, snd_ctl_t *handle,
snd_ctl_element_info_t *info) snd_ctl_elem_info_t *info)
{ {
const char *str; const char *str;
long val; long val;
@ -575,16 +575,16 @@ static int config_enumerated(snd_config_t *n, snd_ctl_t *handle,
default: default:
return -1; return -1;
} }
items = snd_ctl_element_info_get_items(info); items = snd_ctl_elem_info_get_items(info);
for (idx = 0; idx < items; idx++) { for (idx = 0; idx < items; idx++) {
int err; int err;
snd_ctl_element_info_set_item(info, idx); snd_ctl_elem_info_set_item(info, idx);
err = snd_ctl_element_info(handle, info); err = snd_ctl_elem_info(handle, info);
if (err < 0) { if (err < 0) {
error("snd_ctl_card_info: %s", snd_strerror(err)); error("snd_ctl_card_info: %s", snd_strerror(err));
return err; return err;
} }
if (strcmp(str, snd_ctl_element_info_get_item_name(info)) == 0) if (strcmp(str, snd_ctl_elem_info_get_item_name(info)) == 0)
return idx; return idx;
} }
return -1; return -1;
@ -592,13 +592,13 @@ static int config_enumerated(snd_config_t *n, snd_ctl_t *handle,
static int set_control(snd_ctl_t *handle, snd_config_t *control) static int set_control(snd_ctl_t *handle, snd_config_t *control)
{ {
snd_ctl_element_t *ctl; snd_ctl_elem_t *ctl;
snd_ctl_element_info_t *info; snd_ctl_elem_info_t *info;
snd_config_iterator_t i; snd_config_iterator_t i;
unsigned int numid1, iface1, device1, subdevice1, index1; unsigned int numid1, iface1, device1, subdevice1, index1;
const char *name1; const char *name1;
unsigned int numid; unsigned int numid;
snd_ctl_element_type_t type; snd_ctl_elem_type_t type;
unsigned int count; unsigned int count;
long iface = -1; long iface = -1;
long device = -1; long device = -1;
@ -610,8 +610,8 @@ static int set_control(snd_ctl_t *handle, snd_config_t *control)
unsigned int idx; unsigned int idx;
int err; int err;
char *set; char *set;
snd_ctl_element_alloca(&ctl); snd_ctl_elem_alloca(&ctl);
snd_ctl_element_info_alloca(&info); snd_ctl_elem_info_alloca(&info);
if (snd_config_get_type(control) != SND_CONFIG_TYPE_COMPOUND) { if (snd_config_get_type(control) != SND_CONFIG_TYPE_COMPOUND) {
error("control is not a compound"); error("control is not a compound");
return -EINVAL; return -EINVAL;
@ -679,31 +679,31 @@ static int set_control(snd_ctl_t *handle, snd_config_t *control)
if (index < 0) if (index < 0)
index = 0; index = 0;
snd_ctl_element_info_set_numid(info, numid); snd_ctl_elem_info_set_numid(info, numid);
err = snd_ctl_element_info(handle, info); err = snd_ctl_elem_info(handle, info);
if (err < 0) { if (err < 0) {
if (iface >= 0 && name) { if (iface >= 0 && name) {
snd_ctl_element_info_set_numid(info, 0); snd_ctl_elem_info_set_numid(info, 0);
snd_ctl_element_info_set_interface(info, snd_int_to_enum(iface)); snd_ctl_elem_info_set_interface(info, snd_int_to_enum(iface));
snd_ctl_element_info_set_device(info, device); snd_ctl_elem_info_set_device(info, device);
snd_ctl_element_info_set_subdevice(info, subdevice); snd_ctl_elem_info_set_subdevice(info, subdevice);
snd_ctl_element_info_set_name(info, name); snd_ctl_elem_info_set_name(info, name);
snd_ctl_element_info_set_index(info, index); snd_ctl_elem_info_set_index(info, index);
err = snd_ctl_element_info(handle, info); err = snd_ctl_elem_info(handle, info);
} }
} }
if (err < 0) { if (err < 0) {
error("failed to obtain info for control #%d (%s)", numid, snd_strerror(err)); error("failed to obtain info for control #%d (%s)", numid, snd_strerror(err));
return -ENOENT; return -ENOENT;
} }
numid1 = snd_ctl_element_info_get_numid(info); numid1 = snd_ctl_elem_info_get_numid(info);
iface1 = snd_enum_to_int(snd_ctl_element_info_get_interface(info)); iface1 = snd_enum_to_int(snd_ctl_elem_info_get_interface(info));
device1 = snd_ctl_element_info_get_device(info); device1 = snd_ctl_elem_info_get_device(info);
subdevice1 = snd_ctl_element_info_get_subdevice(info); subdevice1 = snd_ctl_elem_info_get_subdevice(info);
name1 = snd_ctl_element_info_get_name(info); name1 = snd_ctl_elem_info_get_name(info);
index1 = snd_ctl_element_info_get_index(info); index1 = snd_ctl_elem_info_get_index(info);
count = snd_ctl_element_info_get_count(info); count = snd_ctl_elem_info_get_count(info);
type = snd_ctl_element_info_get_type(info); type = snd_ctl_elem_info_get_type(info);
if (numid != numid1) if (numid != numid1)
error("warning: numid mismatch (%d/%d) for control #%d", error("warning: numid mismatch (%d/%d) for control #%d",
numid, numid1, numid); numid, numid1, numid);
@ -718,35 +718,35 @@ static int set_control(snd_ctl_t *handle, snd_config_t *control)
if (index != index1) if (index != index1)
error("warning: index mismatch (%ld/%d) for control #%d", index, index1, numid); error("warning: index mismatch (%ld/%d) for control #%d", index, index1, numid);
if (!snd_ctl_element_info_is_writable(info)) if (!snd_ctl_elem_info_is_writable(info))
return 0; return 0;
snd_ctl_element_set_numid(ctl, numid); snd_ctl_elem_set_numid(ctl, numid);
if (count == 1) { if (count == 1) {
switch (snd_enum_to_int(type)) { switch (snd_enum_to_int(type)) {
case SND_CTL_ELEMENT_TYPE_BOOLEAN: case SND_CTL_ELEM_TYPE_BOOLEAN:
val = config_bool(value); val = config_bool(value);
if (val >= 0) { if (val >= 0) {
snd_ctl_element_set_boolean(ctl, 0, val); snd_ctl_elem_set_boolean(ctl, 0, val);
goto _ok; goto _ok;
} }
break; break;
case SND_CTL_ELEMENT_TYPE_INTEGER: case SND_CTL_ELEM_TYPE_INTEGER:
err = snd_config_get_integer(value, &val); err = snd_config_get_integer(value, &val);
if (err == 0) { if (err == 0) {
snd_ctl_element_set_integer(ctl, 0, val); snd_ctl_elem_set_integer(ctl, 0, val);
goto _ok; goto _ok;
} }
break; break;
case SND_CTL_ELEMENT_TYPE_ENUMERATED: case SND_CTL_ELEM_TYPE_ENUMERATED:
val = config_enumerated(value, handle, info); val = config_enumerated(value, handle, info);
if (val >= 0) { if (val >= 0) {
snd_ctl_element_set_enumerated(ctl, 0, val); snd_ctl_elem_set_enumerated(ctl, 0, val);
goto _ok; goto _ok;
} }
break; break;
case SND_CTL_ELEMENT_TYPE_BYTES: case SND_CTL_ELEM_TYPE_BYTES:
case SND_CTL_ELEMENT_TYPE_IEC958: case SND_CTL_ELEM_TYPE_IEC958:
break; break;
default: default:
error("Unknow control type: %d", snd_enum_to_int(type)); error("Unknow control type: %d", snd_enum_to_int(type));
@ -754,8 +754,8 @@ static int set_control(snd_ctl_t *handle, snd_config_t *control)
} }
} }
switch (snd_enum_to_int(type)) { switch (snd_enum_to_int(type)) {
case SND_CTL_ELEMENT_TYPE_BYTES: case SND_CTL_ELEM_TYPE_BYTES:
case SND_CTL_ELEMENT_TYPE_IEC958: case SND_CTL_ELEM_TYPE_IEC958:
{ {
const char *buf; const char *buf;
err = snd_config_get_string(value, &buf); err = snd_config_get_string(value, &buf);
@ -763,7 +763,7 @@ static int set_control(snd_ctl_t *handle, snd_config_t *control)
int c1 = 0; int c1 = 0;
int len = strlen(buf); int len = strlen(buf);
unsigned int idx = 0; unsigned int idx = 0;
int size = type == SND_CTL_ELEMENT_TYPE_BYTES ? int size = type == SND_CTL_ELEM_TYPE_BYTES ?
count : sizeof(snd_aes_iec958_t); count : sizeof(snd_aes_iec958_t);
if (size * 2 != len) { if (size * 2 != len) {
error("bad control.%d.value contents\n", numid); error("bad control.%d.value contents\n", numid);
@ -783,7 +783,7 @@ static int set_control(snd_ctl_t *handle, snd_config_t *control)
} }
idx++; idx++;
if (idx % 2 == 0) if (idx % 2 == 0)
snd_ctl_element_set_byte(ctl, idx / 2, c1 << 4 | c); snd_ctl_elem_set_byte(ctl, idx / 2, c1 << 4 | c);
else else
c1 = c; c1 = c;
} }
@ -809,38 +809,38 @@ static int set_control(snd_ctl_t *handle, snd_config_t *control)
return -EINVAL; return -EINVAL;
} }
switch (snd_enum_to_int(type)) { switch (snd_enum_to_int(type)) {
case SND_CTL_ELEMENT_TYPE_BOOLEAN: case SND_CTL_ELEM_TYPE_BOOLEAN:
val = config_bool(n); val = config_bool(n);
if (val < 0) { if (val < 0) {
error("bad control.%d.value.%d content", numid, idx); error("bad control.%d.value.%d content", numid, idx);
return -EINVAL; return -EINVAL;
} }
snd_ctl_element_set_boolean(ctl, idx, val); snd_ctl_elem_set_boolean(ctl, idx, val);
break; break;
case SND_CTL_ELEMENT_TYPE_INTEGER: case SND_CTL_ELEM_TYPE_INTEGER:
err = snd_config_get_integer(n, &val); err = snd_config_get_integer(n, &val);
if (err < 0) { if (err < 0) {
error("bad control.%d.value.%d content", numid, idx); error("bad control.%d.value.%d content", numid, idx);
return -EINVAL; return -EINVAL;
} }
snd_ctl_element_set_integer(ctl, idx, val); snd_ctl_elem_set_integer(ctl, idx, val);
break; break;
case SND_CTL_ELEMENT_TYPE_ENUMERATED: case SND_CTL_ELEM_TYPE_ENUMERATED:
val = config_enumerated(n, handle, info); val = config_enumerated(n, handle, info);
if (val < 0) { if (val < 0) {
error("bad control.%d.value.%d content", numid, idx); error("bad control.%d.value.%d content", numid, idx);
return -EINVAL; return -EINVAL;
} }
snd_ctl_element_set_enumerated(ctl, idx, val); snd_ctl_elem_set_enumerated(ctl, idx, val);
break; break;
case SND_CTL_ELEMENT_TYPE_BYTES: case SND_CTL_ELEM_TYPE_BYTES:
case SND_CTL_ELEMENT_TYPE_IEC958: case SND_CTL_ELEM_TYPE_IEC958:
err = snd_config_get_integer(n, &val); err = snd_config_get_integer(n, &val);
if (err < 0 || val < 0 || val > 255) { if (err < 0 || val < 0 || val > 255) {
error("bad control.%d.value.%d content", numid, idx); error("bad control.%d.value.%d content", numid, idx);
return -EINVAL; return -EINVAL;
} }
snd_ctl_element_set_byte(ctl, idx, val); snd_ctl_elem_set_byte(ctl, idx, val);
break; break;
default: default:
break; break;
@ -855,11 +855,11 @@ static int set_control(snd_ctl_t *handle, snd_config_t *control)
} }
_ok: _ok:
err = snd_ctl_element_write(handle, ctl); err = snd_ctl_elem_write(handle, ctl);
if (err < 0) { if (err < 0) {
snd_ctl_element_id_t *id; snd_ctl_elem_id_t *id;
snd_ctl_element_id_alloca(&id); snd_ctl_elem_id_alloca(&id);
snd_ctl_element_get_id(ctl, id); snd_ctl_elem_get_id(ctl, id);
error("Cannot write control '%s': %s", id_str(id), snd_strerror(err)); error("Cannot write control '%s': %s", id_str(id), snd_strerror(err));
return err; return err;
} }

View file

@ -214,7 +214,7 @@ static snd_mixer_channel_id_t mixer_elem_chn[][2] = {
{ SND_MIXER_CHN_WOOFER, SND_MIXER_CHN_UNKNOWN }, { SND_MIXER_CHN_WOOFER, SND_MIXER_CHN_UNKNOWN },
}; };
static snd_mixer_sid_t *mixer_sid = NULL; static snd_mixer_selem_id_t *mixer_sid = NULL;
static int mixer_n_scontrols = 0; static int mixer_n_scontrols = 0;
/* split scontrols */ /* split scontrols */
@ -469,22 +469,24 @@ mixer_conv(int val, int omin, int omax, int nmin, int nmax)
} }
static int static int
mixer_calc_volume(snd_mixer_simple_element_t *scontrol, int vol, snd_mixer_channel_id_t chn) mixer_calc_volume(snd_mixer_selem_t *scontrol, int vol, snd_mixer_channel_id_t chn)
{ {
int vol1; int vol1;
long min = snd_mixer_selem_get_min(scontrol);
long max = snd_mixer_selem_get_max(scontrol);
vol1 = (vol < 0) ? -vol : vol; vol1 = (vol < 0) ? -vol : vol;
if (vol1 > 0) { if (vol1 > 0) {
if (vol1 > 100) if (vol1 > 100)
vol1 = scontrol->max; vol1 = max;
else else
vol1 = mixer_conv(vol1, 0, 100, scontrol->min, scontrol->max); vol1 = mixer_conv(vol1, 0, 100, min, max);
if (vol1 <= 0) if (vol1 <= 0)
vol1 = 1; vol1 = 1;
if (vol < 0) if (vol < 0)
vol1 = -vol1; vol1 = -vol1;
} }
vol1 += scontrol->volume.values[snd_enum_to_int(chn)]; vol1 += snd_mixer_selem_get_channel_volume(scontrol, chn);
return CLAMP(vol1, scontrol->min, scontrol->max); return CLAMP(vol1, min, max);
} }
/* set new channel values /* set new channel values
@ -492,18 +494,18 @@ mixer_calc_volume(snd_mixer_simple_element_t *scontrol, int vol, snd_mixer_chann
static void static void
mixer_write_cbar (int elem_index) mixer_write_cbar (int elem_index)
{ {
snd_mixer_simple_element_t scontrol; snd_mixer_selem_t *scontrol;
int vleft, vright, vbalance; int vleft, vright, vbalance;
int type; int type;
snd_mixer_channel_id_t chn_left, chn_right, chn; snd_mixer_channel_id_t chn_left, chn_right, chn;
int err, changed; int err, changed;
snd_mixer_selem_alloca(&scontrol);
bzero(&scontrol, sizeof(scontrol));
if (mixer_sid == NULL) if (mixer_sid == NULL)
return; return;
scontrol.sid = mixer_sid[mixer_grpidx[elem_index]]; scontrol.sid = mixer_sid[mixer_grpidx[elem_index]];
if ((err = snd_mixer_simple_element_read (mixer_handle, &scontrol)) < 0) if ((err = snd_mixer_selem_read (mixer_handle, &scontrol)) < 0)
CHECK_ABORT (ERR_FCN, "snd_mixer_simple_element_read()", err); CHECK_ABORT (ERR_FCN, "snd_mixer_selem_read()", err);
type = mixer_type[elem_index]; type = mixer_type[elem_index];
chn_left = mixer_elem_chn[type][MIXER_CHN_LEFT]; chn_left = mixer_elem_chn[type][MIXER_CHN_LEFT];
@ -587,8 +589,8 @@ mixer_write_cbar (int elem_index)
mixer_toggle_capture = 0; mixer_toggle_capture = 0;
if (changed) { if (changed) {
if ((err = snd_mixer_simple_element_write (mixer_handle, &scontrol)) < 0) if ((err = snd_mixer_selem_write (mixer_handle, &scontrol)) < 0)
CHECK_ABORT (ERR_FCN, "snd_mixer_simple_element_write()", err); CHECK_ABORT (ERR_FCN, "snd_mixer_selem_write()", err);
} }
} }
@ -598,7 +600,7 @@ mixer_update_cbar (int elem_index)
{ {
char string[128], string1[64]; char string[128], string1[64];
int err, dc; int err, dc;
snd_mixer_simple_element_t scontrol; snd_mixer_selem_t scontrol;
int vleft, vright; int vleft, vright;
int type; int type;
snd_mixer_channel_id_t chn_left, chn_right; snd_mixer_channel_id_t chn_left, chn_right;
@ -611,8 +613,8 @@ mixer_update_cbar (int elem_index)
if (mixer_sid == NULL) if (mixer_sid == NULL)
return; return;
scontrol.sid = mixer_sid[mixer_grpidx[elem_index]]; scontrol.sid = mixer_sid[mixer_grpidx[elem_index]];
if ((err = snd_mixer_simple_element_read (mixer_handle, &scontrol)) < 0) if ((err = snd_mixer_selem_read (mixer_handle, &scontrol)) < 0)
CHECK_ABORT (ERR_FCN, "snd_mixer_simple_element_read()", err); CHECK_ABORT (ERR_FCN, "snd_mixer_selem_read()", err);
type = mixer_type[elem_index]; type = mixer_type[elem_index];
chn_left = mixer_elem_chn[type][MIXER_CHN_LEFT]; chn_left = mixer_elem_chn[type][MIXER_CHN_LEFT];
@ -627,8 +629,8 @@ mixer_update_cbar (int elem_index)
/* first, read values for the numbers to be displayed /* first, read values for the numbers to be displayed
*/ */
if ((err = snd_mixer_simple_element_read (mixer_handle, &scontrol)) < 0) if ((err = snd_mixer_selem_read (mixer_handle, &scontrol)) < 0)
CHECK_ABORT (ERR_FCN, "snd_mixer_simple_element_read()", err); CHECK_ABORT (ERR_FCN, "snd_mixer_selem_read()", err);
vleft = scontrol.volume.values[c_left]; vleft = scontrol.volume.values[c_left];
vleft = mixer_conv(vleft, scontrol.min, scontrol.max, 0, 100); vleft = mixer_conv(vleft, scontrol.min, scontrol.max, 0, 100);
@ -1237,9 +1239,9 @@ mixer_init (void)
static void static void
mixer_reinit (void) mixer_reinit (void)
{ {
snd_mixer_simple_element_list_t scontrols; snd_mixer_selem_list_t scontrols;
int idx, err, elem_index, i; int idx, err, elem_index, i;
snd_mixer_sid_t focus_gid; snd_mixer_selem_id_t focus_gid;
int focus_type = -1; int focus_type = -1;
if (mixer_sid) { if (mixer_sid) {
@ -1248,18 +1250,18 @@ mixer_reinit (void)
} }
while (1) { while (1) {
bzero(&scontrols, sizeof(scontrols)); bzero(&scontrols, sizeof(scontrols));
if ((err = snd_mixer_simple_element_list(mixer_handle, &scontrols)) < 0) if ((err = snd_mixer_selem_list(mixer_handle, &scontrols)) < 0)
mixer_abort (ERR_FCN, "snd_mixer_simple_element_list", err); mixer_abort (ERR_FCN, "snd_mixer_selem_list", err);
mixer_n_scontrols = scontrols.controls; mixer_n_scontrols = scontrols.controls;
if (mixer_n_scontrols > 0) { if (mixer_n_scontrols > 0) {
scontrols.controls_request = mixer_n_scontrols; scontrols.controls_request = mixer_n_scontrols;
scontrols.pids = (snd_mixer_sid_t *)malloc(sizeof(snd_mixer_sid_t) * mixer_n_scontrols); scontrols.pids = (snd_mixer_selem_id_t *)malloc(sizeof(snd_mixer_selem_id_t) * mixer_n_scontrols);
if (scontrols.pids == NULL) if (scontrols.pids == NULL)
mixer_abort (ERR_FCN, "malloc", 0); mixer_abort (ERR_FCN, "malloc", 0);
scontrols.controls_offset = 0; scontrols.controls_offset = 0;
scontrols.controls_count = 0; scontrols.controls_count = 0;
if ((err = snd_mixer_simple_element_list(mixer_handle, &scontrols)) < 0) if ((err = snd_mixer_selem_list(mixer_handle, &scontrols)) < 0)
mixer_abort (ERR_FCN, "snd_mixer_simple_element_list", err); mixer_abort (ERR_FCN, "snd_mixer_selem_list", err);
if (scontrols.controls > scontrols.controls_count) { if (scontrols.controls > scontrols.controls_count) {
free(scontrols.pids); free(scontrols.pids);
continue; continue;
@ -1276,11 +1278,11 @@ mixer_reinit (void)
mixer_n_elems = 0; mixer_n_elems = 0;
for (idx = 0; idx < mixer_n_scontrols; idx++) { for (idx = 0; idx < mixer_n_scontrols; idx++) {
snd_mixer_simple_element_t scontrol; snd_mixer_selem_t scontrol;
bzero(&scontrol, sizeof(scontrol)); bzero(&scontrol, sizeof(scontrol));
scontrol.sid = mixer_sid[idx]; scontrol.sid = mixer_sid[idx];
if ((err = snd_mixer_simple_element_read(mixer_handle, &scontrol)) < 0) if ((err = snd_mixer_selem_read(mixer_handle, &scontrol)) < 0)
CHECK_ABORT (ERR_FCN, "snd_mixer_simple_element_read()", 0); CHECK_ABORT (ERR_FCN, "snd_mixer_selem_read()", 0);
for (i = 0; i < MIXER_ELEM_END; i++) { for (i = 0; i < MIXER_ELEM_END; i++) {
if (scontrol.channels & mixer_elem_mask[i]) if (scontrol.channels & mixer_elem_mask[i])
mixer_n_elems++; mixer_n_elems++;
@ -1299,11 +1301,11 @@ mixer_reinit (void)
mixer_abort(ERR_FCN, "malloc", 0); mixer_abort(ERR_FCN, "malloc", 0);
elem_index = 0; elem_index = 0;
for (idx = 0; idx < mixer_n_scontrols; idx++) { for (idx = 0; idx < mixer_n_scontrols; idx++) {
snd_mixer_simple_element_t scontrol; snd_mixer_selem_t scontrol;
bzero(&scontrol, sizeof(scontrol)); bzero(&scontrol, sizeof(scontrol));
scontrol.sid = mixer_sid[idx]; scontrol.sid = mixer_sid[idx];
if ((err = snd_mixer_simple_element_read(mixer_handle, &scontrol)) < 0) if ((err = snd_mixer_selem_read(mixer_handle, &scontrol)) < 0)
CHECK_ABORT (ERR_FCN, "snd_mixer_simple_element_read()", err); CHECK_ABORT (ERR_FCN, "snd_mixer_selem_read()", err);
for (i = 0; i < MIXER_ELEM_END; i++) { for (i = 0; i < MIXER_ELEM_END; i++) {
if (scontrol.channels & mixer_elem_mask[i]) { if (scontrol.channels & mixer_elem_mask[i]) {
mixer_grpidx[elem_index] = idx; mixer_grpidx[elem_index] = idx;
@ -1416,7 +1418,7 @@ mixer_callback_rebuild (snd_mixer_t *handle ATTRIBUTE_UNUSED, void *private_data
} }
static void static void
mixer_callback_scontrol (snd_mixer_t *handle ATTRIBUTE_UNUSED, void *private_data ATTRIBUTE_UNUSED, snd_mixer_sid_t *gid ATTRIBUTE_UNUSED) mixer_callback_scontrol (snd_mixer_t *handle ATTRIBUTE_UNUSED, void *private_data ATTRIBUTE_UNUSED, snd_mixer_selem_id_t *gid ATTRIBUTE_UNUSED)
{ {
mixer_reinit (); mixer_reinit ();
} }

File diff suppressed because it is too large Load diff

View file

@ -83,7 +83,7 @@ static int verbose = 0;
static int buffer_pos = 0; static int buffer_pos = 0;
static size_t bits_per_sample, bits_per_frame; static size_t bits_per_sample, bits_per_frame;
static size_t chunk_bytes; static size_t chunk_bytes;
static snd_ctl_element_type_t digtype = SND_CTL_ELEMENT_TYPE_NONE; static snd_ctl_elem_type_t digtype = SND_CTL_ELEM_TYPE_NONE;
static snd_aes_iec958_t spdif; static snd_aes_iec958_t spdif;
static snd_output_t *log; static snd_output_t *log;
@ -410,7 +410,7 @@ int main(int argc, char *argv[])
interleaved = 0; interleaved = 0;
break; break;
case 'C': case 'C':
digtype = SND_CTL_ELEMENT_TYPE_IEC958; digtype = SND_CTL_ELEM_TYPE_IEC958;
spdif.status[0] = IEC958_AES0_NONAUDIO | spdif.status[0] = IEC958_AES0_NONAUDIO |
IEC958_AES0_CON_EMPHASIS_NONE; IEC958_AES0_CON_EMPHASIS_NONE;
spdif.status[1] = IEC958_AES1_CON_ORIGINAL | spdif.status[1] = IEC958_AES1_CON_ORIGINAL |
@ -419,7 +419,7 @@ int main(int argc, char *argv[])
spdif.status[3] = IEC958_AES3_CON_FS_48000; spdif.status[3] = IEC958_AES3_CON_FS_48000;
break; break;
case 'P': case 'P':
digtype = SND_CTL_ELEMENT_TYPE_IEC958; digtype = SND_CTL_ELEM_TYPE_IEC958;
spdif.status[0] = IEC958_AES0_PROFESSIONAL | spdif.status[0] = IEC958_AES0_PROFESSIONAL |
IEC958_AES0_NONAUDIO | IEC958_AES0_NONAUDIO |
IEC958_AES0_PRO_EMPHASIS_NONE | IEC958_AES0_PRO_EMPHASIS_NONE |
@ -447,17 +447,17 @@ int main(int argc, char *argv[])
return 1; return 1;
} }
if (digtype != SND_CTL_ELEMENT_TYPE_NONE) { if (digtype != SND_CTL_ELEM_TYPE_NONE) {
snd_ctl_element_t *ctl; snd_ctl_elem_t *ctl;
snd_ctl_t *ctl_handle; snd_ctl_t *ctl_handle;
char ctl_name[12]; char ctl_name[12];
int ctl_card; int ctl_card;
snd_ctl_element_alloca(&ctl); snd_ctl_elem_alloca(&ctl);
snd_ctl_element_set_interface(ctl, SND_CTL_ELEMENT_IFACE_PCM); snd_ctl_elem_set_interface(ctl, SND_CTL_ELEM_IFACE_PCM);
snd_ctl_element_set_device(ctl, snd_pcm_info_get_device(info)); snd_ctl_elem_set_device(ctl, snd_pcm_info_get_device(info));
snd_ctl_element_set_subdevice(ctl, snd_pcm_info_get_subdevice(info)); snd_ctl_elem_set_subdevice(ctl, snd_pcm_info_get_subdevice(info));
snd_ctl_element_set_name(ctl, "IEC958 (S/PDIF) Stream"); snd_ctl_elem_set_name(ctl, "IEC958 (S/PDIF) Stream");
snd_ctl_element_set_iec958(ctl, &spdif); snd_ctl_elem_set_iec958(ctl, &spdif);
ctl_card = snd_pcm_info_get_card(info); ctl_card = snd_pcm_info_get_card(info);
if (ctl_card < 0) { if (ctl_card < 0) {
error("Unable to setup the IEC958 (S/PDIF) interface - PCM has no assigned card"); error("Unable to setup the IEC958 (S/PDIF) interface - PCM has no assigned card");
@ -468,7 +468,7 @@ int main(int argc, char *argv[])
error("Unable to open the control interface '%s': %s", ctl_name, snd_strerror(err)); error("Unable to open the control interface '%s': %s", ctl_name, snd_strerror(err));
goto __diga_end; goto __diga_end;
} }
if ((err = snd_ctl_element_write(ctl_handle, ctl)) < 0) { if ((err = snd_ctl_elem_write(ctl_handle, ctl)) < 0) {
error("Unable to update the IEC958 control: %s", snd_strerror(err)); error("Unable to update the IEC958 control: %s", snd_strerror(err));
goto __diga_end; goto __diga_end;
} }