mirror of
https://github.com/alsa-project/alsa-utils
synced 2024-12-22 18:16:31 +01:00
Encapsulated hwdep. Converted all enums to type safety
This commit is contained in:
parent
2121e1576c
commit
3df0171dc0
4 changed files with 104 additions and 85 deletions
|
@ -142,7 +142,8 @@ static int get_control(snd_ctl_t *handle, snd_control_id_t *id, snd_config_t *to
|
||||||
snd_config_t *control, *comment, *item, *value;
|
snd_config_t *control, *comment, *item, *value;
|
||||||
char *s;
|
char *s;
|
||||||
char buf[256];
|
char buf[256];
|
||||||
int idx, err;
|
unsigned int idx;
|
||||||
|
int err;
|
||||||
|
|
||||||
memset(&info, 0, sizeof(info));
|
memset(&info, 0, sizeof(info));
|
||||||
info.id = *id;
|
info.id = *id;
|
||||||
|
@ -316,7 +317,7 @@ static int get_control(snd_ctl_t *handle, snd_control_id_t *id, snd_config_t *to
|
||||||
case SND_CONTROL_TYPE_BYTES:
|
case SND_CONTROL_TYPE_BYTES:
|
||||||
case SND_CONTROL_TYPE_IEC958:
|
case SND_CONTROL_TYPE_IEC958:
|
||||||
{
|
{
|
||||||
int count = info.type == SND_CONTROL_TYPE_BYTES ?
|
size_t count = info.type == SND_CONTROL_TYPE_BYTES ?
|
||||||
info.values_count : sizeof(snd_aes_iec958_t);
|
info.values_count : sizeof(snd_aes_iec958_t);
|
||||||
char buf[count * 2 + 1];
|
char buf[count * 2 + 1];
|
||||||
char *p = buf;
|
char *p = buf;
|
||||||
|
@ -433,7 +434,8 @@ static int get_controls(int cardno, snd_config_t *top)
|
||||||
snd_ctl_hw_info_t info;
|
snd_ctl_hw_info_t info;
|
||||||
snd_config_t *state, *card, *control;
|
snd_config_t *state, *card, *control;
|
||||||
snd_control_list_t list;
|
snd_control_list_t list;
|
||||||
int idx, err;
|
unsigned int idx;
|
||||||
|
int err;
|
||||||
char name[32];
|
char name[32];
|
||||||
|
|
||||||
sprintf(name, "hw:%d", cardno);
|
sprintf(name, "hw:%d", cardno);
|
||||||
|
@ -538,12 +540,13 @@ static int config_iface(snd_config_t *n)
|
||||||
{ SND_CONTROL_IFACE_TIMER, "timer" },
|
{ SND_CONTROL_IFACE_TIMER, "timer" },
|
||||||
{ SND_CONTROL_IFACE_SEQUENCER, "sequencer" }
|
{ SND_CONTROL_IFACE_SEQUENCER, "sequencer" }
|
||||||
};
|
};
|
||||||
long idx;
|
unsigned long i;
|
||||||
|
unsigned int idx;
|
||||||
char *str;
|
char *str;
|
||||||
switch (snd_config_type(n)) {
|
switch (snd_enum_to_int(snd_config_type(n))) {
|
||||||
case SND_CONFIG_TYPE_INTEGER:
|
case SND_CONFIG_TYPE_INTEGER:
|
||||||
snd_config_integer_get(n, &idx);
|
snd_config_integer_get(n, &i);
|
||||||
return idx;
|
return i;
|
||||||
case SND_CONFIG_TYPE_STRING:
|
case SND_CONFIG_TYPE_STRING:
|
||||||
snd_config_string_get(n, &str);
|
snd_config_string_get(n, &str);
|
||||||
break;
|
break;
|
||||||
|
@ -561,7 +564,7 @@ static int config_bool(snd_config_t *n)
|
||||||
{
|
{
|
||||||
char *str;
|
char *str;
|
||||||
long val;
|
long val;
|
||||||
switch (snd_config_type(n)) {
|
switch (snd_enum_to_int(snd_config_type(n))) {
|
||||||
case SND_CONFIG_TYPE_INTEGER:
|
case SND_CONFIG_TYPE_INTEGER:
|
||||||
snd_config_integer_get(n, &val);
|
snd_config_integer_get(n, &val);
|
||||||
if (val < 0 || val > 1)
|
if (val < 0 || val > 1)
|
||||||
|
@ -585,8 +588,8 @@ static int config_enumerated(snd_config_t *n, snd_ctl_t *handle,
|
||||||
{
|
{
|
||||||
char *str;
|
char *str;
|
||||||
long val;
|
long val;
|
||||||
int idx;
|
unsigned int idx;
|
||||||
switch (snd_config_type(n)) {
|
switch (snd_enum_to_int(snd_config_type(n))) {
|
||||||
case SND_CONFIG_TYPE_INTEGER:
|
case SND_CONFIG_TYPE_INTEGER:
|
||||||
snd_config_integer_get(n, &val);
|
snd_config_integer_get(n, &val);
|
||||||
return val;
|
return val;
|
||||||
|
@ -615,7 +618,7 @@ static int set_control(snd_ctl_t *handle, snd_config_t *control)
|
||||||
snd_control_t ctl;
|
snd_control_t ctl;
|
||||||
snd_control_info_t info;
|
snd_control_info_t info;
|
||||||
snd_config_iterator_t i;
|
snd_config_iterator_t i;
|
||||||
int numid;
|
unsigned int numid;
|
||||||
long iface = -1;
|
long iface = -1;
|
||||||
long device = -1;
|
long device = -1;
|
||||||
long subdevice = -1;
|
long subdevice = -1;
|
||||||
|
@ -623,7 +626,8 @@ static int set_control(snd_ctl_t *handle, snd_config_t *control)
|
||||||
long index = -1;
|
long index = -1;
|
||||||
snd_config_t *value = NULL;
|
snd_config_t *value = NULL;
|
||||||
long val;
|
long val;
|
||||||
int idx, err;
|
unsigned int idx;
|
||||||
|
int err;
|
||||||
char *set;
|
char *set;
|
||||||
if (snd_config_type(control) != SND_CONFIG_TYPE_COMPOUND) {
|
if (snd_config_type(control) != SND_CONFIG_TYPE_COMPOUND) {
|
||||||
error("control is not a compound");
|
error("control is not a compound");
|
||||||
|
@ -768,7 +772,7 @@ static int set_control(snd_ctl_t *handle, snd_config_t *control)
|
||||||
if (err >= 0) {
|
if (err >= 0) {
|
||||||
int c1 = 0;
|
int c1 = 0;
|
||||||
int len = strlen(buf);
|
int len = strlen(buf);
|
||||||
int idx = 0;
|
unsigned int idx = 0;
|
||||||
int count = info.type == SND_CONTROL_TYPE_BYTES ?
|
int count = info.type == SND_CONTROL_TYPE_BYTES ?
|
||||||
info.values_count : sizeof(snd_aes_iec958_t);
|
info.values_count : sizeof(snd_aes_iec958_t);
|
||||||
if (count * 2 != len) {
|
if (count * 2 != len) {
|
||||||
|
|
|
@ -207,11 +207,11 @@ static int mixer_elem_mask[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* left and right channels for each type */
|
/* left and right channels for each type */
|
||||||
static int mixer_elem_chn[][2] = {
|
static snd_mixer_channel_id_t mixer_elem_chn[][2] = {
|
||||||
{ SND_MIXER_CHN_FRONT_LEFT, SND_MIXER_CHN_FRONT_RIGHT },
|
{ SND_MIXER_CHN_FRONT_LEFT, SND_MIXER_CHN_FRONT_RIGHT },
|
||||||
{ SND_MIXER_CHN_REAR_LEFT, SND_MIXER_CHN_REAR_RIGHT },
|
{ SND_MIXER_CHN_REAR_LEFT, SND_MIXER_CHN_REAR_RIGHT },
|
||||||
{ SND_MIXER_CHN_FRONT_CENTER, -1 },
|
{ SND_MIXER_CHN_FRONT_CENTER, SND_MIXER_CHN_UNKNOWN },
|
||||||
{ SND_MIXER_CHN_WOOFER, -1 },
|
{ SND_MIXER_CHN_WOOFER, SND_MIXER_CHN_UNKNOWN },
|
||||||
};
|
};
|
||||||
|
|
||||||
static snd_mixer_sid_t *mixer_sid = NULL;
|
static snd_mixer_sid_t *mixer_sid = NULL;
|
||||||
|
@ -469,10 +469,9 @@ mixer_conv(int val, int omin, int omax, int nmin, int nmax)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
mixer_calc_volume(snd_mixer_simple_control_t *scontrol, int vol, int chn)
|
mixer_calc_volume(snd_mixer_simple_control_t *scontrol, int vol, snd_mixer_channel_id_t chn)
|
||||||
{
|
{
|
||||||
int vol1;
|
int vol1;
|
||||||
|
|
||||||
vol1 = (vol < 0) ? -vol : vol;
|
vol1 = (vol < 0) ? -vol : vol;
|
||||||
if (vol1 > 0) {
|
if (vol1 > 0) {
|
||||||
if (vol1 > 100)
|
if (vol1 > 100)
|
||||||
|
@ -484,7 +483,7 @@ mixer_calc_volume(snd_mixer_simple_control_t *scontrol, int vol, int chn)
|
||||||
if (vol < 0)
|
if (vol < 0)
|
||||||
vol1 = -vol1;
|
vol1 = -vol1;
|
||||||
}
|
}
|
||||||
vol1 += scontrol->volume.values[chn];
|
vol1 += scontrol->volume.values[snd_enum_to_int(chn)];
|
||||||
return CLAMP(vol1, scontrol->min, scontrol->max);
|
return CLAMP(vol1, scontrol->min, scontrol->max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -495,8 +494,9 @@ mixer_write_cbar (int elem_index)
|
||||||
{
|
{
|
||||||
snd_mixer_simple_control_t scontrol;
|
snd_mixer_simple_control_t scontrol;
|
||||||
int vleft, vright, vbalance;
|
int vleft, vright, vbalance;
|
||||||
int type, chn_left, chn_right;
|
int type;
|
||||||
int i, err, changed;
|
snd_mixer_channel_id_t chn_left, chn_right, chn;
|
||||||
|
int err, changed;
|
||||||
|
|
||||||
bzero(&scontrol, sizeof(scontrol));
|
bzero(&scontrol, sizeof(scontrol));
|
||||||
if (mixer_sid == NULL)
|
if (mixer_sid == NULL)
|
||||||
|
@ -507,11 +507,11 @@ mixer_write_cbar (int elem_index)
|
||||||
|
|
||||||
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];
|
||||||
if (! (scontrol.channels & (1 << chn_left)))
|
if (! (scontrol.channels & (1 << snd_enum_to_int(chn_left))))
|
||||||
return; /* ..??.. */
|
return; /* ..??.. */
|
||||||
chn_right = mixer_elem_chn[type][MIXER_CHN_RIGHT];
|
chn_right = mixer_elem_chn[type][MIXER_CHN_RIGHT];
|
||||||
if (chn_right >= 0 && ! (scontrol.channels & (1 << chn_right)))
|
if (chn_right != SND_MIXER_CHN_UNKNOWN && ! (scontrol.channels & (1 << snd_enum_to_int(chn_right))))
|
||||||
chn_right = -1;
|
chn_right = SND_MIXER_CHN_UNKNOWN;
|
||||||
|
|
||||||
changed = 0;
|
changed = 0;
|
||||||
|
|
||||||
|
@ -522,7 +522,7 @@ mixer_write_cbar (int elem_index)
|
||||||
mixer_balance_volumes) &&
|
mixer_balance_volumes) &&
|
||||||
(scontrol.caps & SND_MIXER_SCTCAP_VOLUME)) {
|
(scontrol.caps & SND_MIXER_SCTCAP_VOLUME)) {
|
||||||
int mono =
|
int mono =
|
||||||
(chn_right < 0 || (scontrol.caps & SND_MIXER_SCTCAP_JOINTLY_VOLUME));
|
(chn_right == SND_MIXER_CHN_UNKNOWN || (scontrol.caps & SND_MIXER_SCTCAP_JOINTLY_VOLUME));
|
||||||
if (mono && !mixer_volume_delta[MIXER_CHN_LEFT])
|
if (mono && !mixer_volume_delta[MIXER_CHN_LEFT])
|
||||||
mixer_volume_delta[MIXER_CHN_LEFT] = mixer_volume_delta[MIXER_CHN_RIGHT];
|
mixer_volume_delta[MIXER_CHN_LEFT] = mixer_volume_delta[MIXER_CHN_RIGHT];
|
||||||
vleft = mixer_calc_volume(&scontrol, mixer_volume_delta[MIXER_CHN_LEFT], chn_left);
|
vleft = mixer_calc_volume(&scontrol, mixer_volume_delta[MIXER_CHN_LEFT], chn_left);
|
||||||
|
@ -535,16 +535,17 @@ mixer_write_cbar (int elem_index)
|
||||||
vright = vleft;
|
vright = vleft;
|
||||||
if (vleft >= 0 && vright >= 0) {
|
if (vleft >= 0 && vright >= 0) {
|
||||||
if (scontrol.caps & SND_MIXER_SCTCAP_JOINTLY_VOLUME) {
|
if (scontrol.caps & SND_MIXER_SCTCAP_JOINTLY_VOLUME) {
|
||||||
for (i = 0; i < SND_MIXER_CHN_LAST; i++) {
|
for (chn = 0; chn < SND_MIXER_CHN_LAST; snd_enum_incr(chn)) {
|
||||||
if (scontrol.channels & (1 << i))
|
int c = snd_enum_to_int(chn);
|
||||||
scontrol.volume.values[i] = vleft;
|
if (scontrol.channels & (1 << c))
|
||||||
|
scontrol.volume.values[c] = vleft;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (mixer_balance_volumes)
|
if (mixer_balance_volumes)
|
||||||
vleft = vright = vbalance;
|
vleft = vright = vbalance;
|
||||||
scontrol.volume.values[chn_left] = vleft;
|
scontrol.volume.values[snd_enum_to_int(chn_left)] = vleft;
|
||||||
if (! mono)
|
if (! mono)
|
||||||
scontrol.volume.values[chn_right] = vright;
|
scontrol.volume.values[snd_enum_to_int(chn_right)] = vright;
|
||||||
}
|
}
|
||||||
changed = 1;
|
changed = 1;
|
||||||
}
|
}
|
||||||
|
@ -560,9 +561,10 @@ mixer_write_cbar (int elem_index)
|
||||||
scontrol.mute = scontrol.mute ? 0 : scontrol.channels;
|
scontrol.mute = scontrol.mute ? 0 : scontrol.channels;
|
||||||
else {
|
else {
|
||||||
if (mixer_toggle_mute & MIXER_MASK_LEFT)
|
if (mixer_toggle_mute & MIXER_MASK_LEFT)
|
||||||
scontrol.mute ^= (1 << chn_left);
|
scontrol.mute ^= (1 << snd_enum_to_int(chn_left));
|
||||||
if (chn_right >= 0 && (mixer_toggle_mute & MIXER_MASK_RIGHT))
|
if (chn_right != SND_MIXER_CHN_UNKNOWN &&
|
||||||
scontrol.mute ^= (1 << chn_right);
|
(mixer_toggle_mute & MIXER_MASK_RIGHT))
|
||||||
|
scontrol.mute ^= (1 << snd_enum_to_int(chn_right));
|
||||||
}
|
}
|
||||||
changed = 1;
|
changed = 1;
|
||||||
}
|
}
|
||||||
|
@ -576,9 +578,9 @@ mixer_write_cbar (int elem_index)
|
||||||
scontrol.capture = scontrol.capture ? 0 : scontrol.channels;
|
scontrol.capture = scontrol.capture ? 0 : scontrol.channels;
|
||||||
else {
|
else {
|
||||||
if (mixer_toggle_capture & MIXER_MASK_LEFT)
|
if (mixer_toggle_capture & MIXER_MASK_LEFT)
|
||||||
scontrol.capture ^= (1 << chn_left);
|
scontrol.capture ^= (1 << snd_enum_to_int(chn_left));
|
||||||
if (chn_right >= 0 && (mixer_toggle_capture & MIXER_MASK_RIGHT))
|
if (chn_right != SND_MIXER_CHN_UNKNOWN && (mixer_toggle_capture & MIXER_MASK_RIGHT))
|
||||||
scontrol.capture ^= (1 << chn_right);
|
scontrol.capture ^= (1 << snd_enum_to_int(chn_right));
|
||||||
}
|
}
|
||||||
changed = 1;
|
changed = 1;
|
||||||
}
|
}
|
||||||
|
@ -598,8 +600,10 @@ mixer_update_cbar (int elem_index)
|
||||||
int err, dc;
|
int err, dc;
|
||||||
snd_mixer_simple_control_t scontrol;
|
snd_mixer_simple_control_t scontrol;
|
||||||
int vleft, vright;
|
int vleft, vright;
|
||||||
int type, chn_left, chn_right;
|
int type;
|
||||||
|
snd_mixer_channel_id_t chn_left, chn_right;
|
||||||
int x, y, i;
|
int x, y, i;
|
||||||
|
int c_left, c_right;
|
||||||
|
|
||||||
/* set new scontrol indices and read info
|
/* set new scontrol indices and read info
|
||||||
*/
|
*/
|
||||||
|
@ -612,21 +616,24 @@ mixer_update_cbar (int elem_index)
|
||||||
|
|
||||||
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];
|
||||||
if (! (scontrol.channels & (1 << chn_left)))
|
if (! (scontrol.channels & (1 << snd_enum_to_int(chn_left))))
|
||||||
return; /* ..??.. */
|
return; /* ..??.. */
|
||||||
chn_right = mixer_elem_chn[type][MIXER_CHN_RIGHT];
|
chn_right = mixer_elem_chn[type][MIXER_CHN_RIGHT];
|
||||||
if (chn_right >= 0 && ! (scontrol.channels & (1 << chn_right)))
|
if (chn_right != SND_MIXER_CHN_UNKNOWN &&
|
||||||
chn_right = -1;
|
! (scontrol.channels & (1 << snd_enum_to_int(chn_right))))
|
||||||
|
chn_right = SND_MIXER_CHN_UNKNOWN;
|
||||||
|
c_left = snd_enum_to_int(chn_left);
|
||||||
|
c_right = snd_enum_to_int(chn_right);
|
||||||
|
|
||||||
/* first, read values for the numbers to be displayed
|
/* first, read values for the numbers to be displayed
|
||||||
*/
|
*/
|
||||||
if ((err = snd_mixer_simple_control_read (mixer_handle, &scontrol)) < 0)
|
if ((err = snd_mixer_simple_control_read (mixer_handle, &scontrol)) < 0)
|
||||||
CHECK_ABORT (ERR_FCN, "snd_mixer_simple_control_read()", err);
|
CHECK_ABORT (ERR_FCN, "snd_mixer_simple_control_read()", err);
|
||||||
|
|
||||||
vleft = scontrol.volume.values[chn_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);
|
||||||
if (chn_right >= 0) {
|
if (chn_right != SND_MIXER_CHN_UNKNOWN) {
|
||||||
vright = scontrol.volume.values[chn_right];
|
vright = scontrol.volume.values[c_right];
|
||||||
vright = mixer_conv(vright, scontrol.min, scontrol.max, 0, 100);
|
vright = mixer_conv(vright, scontrol.min, scontrol.max, 0, 100);
|
||||||
} else {
|
} else {
|
||||||
vright = vleft;
|
vright = vleft;
|
||||||
|
@ -722,10 +729,10 @@ mixer_update_cbar (int elem_index)
|
||||||
mvaddstr (y, x, " ");
|
mvaddstr (y, x, " ");
|
||||||
mixer_dc (DC_CBAR_FRAME);
|
mixer_dc (DC_CBAR_FRAME);
|
||||||
mvaddch (y, x + 2, ACS_ULCORNER);
|
mvaddch (y, x + 2, ACS_ULCORNER);
|
||||||
dc = scontrol.mute & (1 << chn_left) ? DC_CBAR_MUTE : DC_CBAR_NOMUTE;
|
dc = scontrol.mute & (1 << c_left) ? DC_CBAR_MUTE : DC_CBAR_NOMUTE;
|
||||||
mvaddch (y, x + 3, mixer_dc (dc));
|
mvaddch (y, x + 3, mixer_dc (dc));
|
||||||
if (chn_right >= 0)
|
if (chn_right != SND_MIXER_CHN_UNKNOWN)
|
||||||
dc = scontrol.mute & (1 << chn_right) ? DC_CBAR_MUTE : DC_CBAR_NOMUTE;
|
dc = scontrol.mute & (1 << c_right) ? DC_CBAR_MUTE : DC_CBAR_NOMUTE;
|
||||||
mvaddch (y, x + 4, mixer_dc (dc));
|
mvaddch (y, x + 4, mixer_dc (dc));
|
||||||
mixer_dc (DC_CBAR_FRAME);
|
mixer_dc (DC_CBAR_FRAME);
|
||||||
mvaddch (y, x + 5, ACS_URCORNER);
|
mvaddch (y, x + 5, ACS_URCORNER);
|
||||||
|
@ -733,17 +740,18 @@ mixer_update_cbar (int elem_index)
|
||||||
|
|
||||||
/* capture input?
|
/* capture input?
|
||||||
*/
|
*/
|
||||||
if ((scontrol.capture & (1 << chn_left)) ||
|
if ((scontrol.capture & (1 << c_left)) ||
|
||||||
(chn_right >= 0 && (scontrol.capture & (1 << chn_right))))
|
(chn_right != SND_MIXER_CHN_UNKNOWN && (scontrol.capture & (1 << c_right))))
|
||||||
{
|
{
|
||||||
mixer_dc (DC_CBAR_CAPTURE);
|
mixer_dc (DC_CBAR_CAPTURE);
|
||||||
mvaddstr (y, x + 1, "CAPTUR");
|
mvaddstr (y, x + 1, "CAPTUR");
|
||||||
if (scontrol.capture & (1 << chn_left)) {
|
if (scontrol.capture & (1 << c_left)) {
|
||||||
mvaddstr (y + 1, x + 1, "L");
|
mvaddstr (y + 1, x + 1, "L");
|
||||||
if (chn_right < 0)
|
if (chn_right == SND_MIXER_CHN_UNKNOWN)
|
||||||
mvaddstr (y + 1, x + 6, "R");
|
mvaddstr (y + 1, x + 6, "R");
|
||||||
}
|
}
|
||||||
if (chn_right >= 0 && (scontrol.capture & (1 << chn_right)))
|
if (chn_right != SND_MIXER_CHN_UNKNOWN &&
|
||||||
|
(scontrol.capture & (1 << c_right)))
|
||||||
mvaddstr (y + 1, x + 6, "R");
|
mvaddstr (y + 1, x + 6, "R");
|
||||||
}
|
}
|
||||||
else if (scontrol.caps & SND_MIXER_SCTCAP_CAPTURE)
|
else if (scontrol.caps & SND_MIXER_SCTCAP_CAPTURE)
|
||||||
|
@ -1398,7 +1406,7 @@ mixer_resize (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mixer_callback_rebuild (snd_mixer_t *handle, void *private_data)
|
mixer_callback_rebuild (snd_mixer_t *handle ATTRIBUTE_UNUSED, void *private_data ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
/* we don't actually need to update the individual channels because
|
/* we don't actually need to update the individual channels because
|
||||||
* we redraw the whole screen upon every main iteration anyways.
|
* we redraw the whole screen upon every main iteration anyways.
|
||||||
|
@ -1407,7 +1415,7 @@ mixer_callback_rebuild (snd_mixer_t *handle, void *private_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mixer_callback_scontrol (snd_mixer_t *handle, void *private_data, snd_mixer_sid_t *gid)
|
mixer_callback_scontrol (snd_mixer_t *handle ATTRIBUTE_UNUSED, void *private_data ATTRIBUTE_UNUSED, snd_mixer_sid_t *gid ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
mixer_reinit ();
|
mixer_reinit ();
|
||||||
}
|
}
|
||||||
|
@ -1433,7 +1441,7 @@ mixer_add_delta(int delta)
|
||||||
static int
|
static int
|
||||||
mixer_iteration (void)
|
mixer_iteration (void)
|
||||||
{
|
{
|
||||||
struct timeval delay = { 0, };
|
struct timeval delay = { 0, 0 };
|
||||||
snd_mixer_simple_callbacks_t callbacks = { 0, };
|
snd_mixer_simple_callbacks_t callbacks = { 0, };
|
||||||
int mixer_fd;
|
int mixer_fd;
|
||||||
fd_set rfds;
|
fd_set rfds;
|
||||||
|
|
|
@ -416,7 +416,8 @@ static int show_control(const char *space, snd_ctl_t *handle, snd_control_id_t *
|
||||||
|
|
||||||
static int controls(int level)
|
static int controls(int level)
|
||||||
{
|
{
|
||||||
int err, idx;
|
int err;
|
||||||
|
unsigned int idx;
|
||||||
snd_ctl_t *handle;
|
snd_ctl_t *handle;
|
||||||
snd_hcontrol_list_t list;
|
snd_hcontrol_list_t list;
|
||||||
|
|
||||||
|
@ -456,7 +457,8 @@ static int controls(int level)
|
||||||
|
|
||||||
static int show_simple_control(void *handle, snd_mixer_sid_t *sid, const char *space, int level)
|
static int show_simple_control(void *handle, snd_mixer_sid_t *sid, const char *space, int level)
|
||||||
{
|
{
|
||||||
int err, chn;
|
int err;
|
||||||
|
snd_mixer_channel_id_t chn;
|
||||||
snd_mixer_simple_control_t scontrol;
|
snd_mixer_simple_control_t scontrol;
|
||||||
|
|
||||||
bzero(&scontrol, sizeof(scontrol));
|
bzero(&scontrol, sizeof(scontrol));
|
||||||
|
@ -490,8 +492,8 @@ static int show_simple_control(void *handle, snd_mixer_sid_t *sid, const char *s
|
||||||
if (scontrol.channels == SND_MIXER_CHN_MASK_MONO) {
|
if (scontrol.channels == SND_MIXER_CHN_MASK_MONO) {
|
||||||
printf("Mono");
|
printf("Mono");
|
||||||
} else {
|
} else {
|
||||||
for (chn = 0; chn <= SND_MIXER_CHN_LAST; chn++) {
|
for (chn = 0; chn <= SND_MIXER_CHN_LAST; snd_enum_incr(chn)){
|
||||||
if (!(scontrol.channels & (1<<chn)))
|
if (!(scontrol.channels & (1<<snd_enum_to_int(chn))))
|
||||||
continue;
|
continue;
|
||||||
printf("%s ", snd_mixer_simple_channel_name(chn));
|
printf("%s ", snd_mixer_simple_channel_name(chn));
|
||||||
}
|
}
|
||||||
|
@ -501,15 +503,16 @@ static int show_simple_control(void *handle, snd_mixer_sid_t *sid, const char *s
|
||||||
if (scontrol.channels == SND_MIXER_CHN_MASK_MONO) {
|
if (scontrol.channels == SND_MIXER_CHN_MASK_MONO) {
|
||||||
printf("%sMono: %s [%s]\n", space, get_percent(scontrol.volume.names.front_left, scontrol.min, scontrol.max), scontrol.mute & SND_MIXER_CHN_MASK_MONO ? "mute" : "on");
|
printf("%sMono: %s [%s]\n", space, get_percent(scontrol.volume.names.front_left, scontrol.min, scontrol.max), scontrol.mute & SND_MIXER_CHN_MASK_MONO ? "mute" : "on");
|
||||||
} else {
|
} else {
|
||||||
for (chn = 0; chn <= SND_MIXER_CHN_LAST; chn++) {
|
for (chn = 0; chn <= SND_MIXER_CHN_LAST; snd_enum_incr(chn)) {
|
||||||
if (!(scontrol.channels & (1<<chn)))
|
int c = snd_enum_to_int(chn);
|
||||||
|
if (!(scontrol.channels & (1<<c)))
|
||||||
continue;
|
continue;
|
||||||
printf("%s%s: %s [%s] [%s]\n",
|
printf("%s%s: %s [%s] [%s]\n",
|
||||||
space,
|
space,
|
||||||
snd_mixer_simple_channel_name(chn),
|
snd_mixer_simple_channel_name(chn),
|
||||||
get_percent(scontrol.volume.values[chn], scontrol.min, scontrol.max),
|
get_percent(scontrol.volume.values[c], scontrol.min, scontrol.max),
|
||||||
scontrol.mute & (1<<chn) ? "mute" : "on",
|
scontrol.mute & (1<<c) ? "mute" : "on",
|
||||||
scontrol.capture & (1<<chn) ? "capture" : "---");
|
scontrol.capture & (1<<c) ? "capture" : "---");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -518,7 +521,8 @@ static int show_simple_control(void *handle, snd_mixer_sid_t *sid, const char *s
|
||||||
|
|
||||||
static int simple_controls(int level)
|
static int simple_controls(int level)
|
||||||
{
|
{
|
||||||
int err, idx;
|
int err;
|
||||||
|
unsigned int idx;
|
||||||
snd_mixer_t *handle;
|
snd_mixer_t *handle;
|
||||||
snd_mixer_simple_control_list_t list;
|
snd_mixer_simple_control_list_t list;
|
||||||
snd_mixer_sid_t *sid;
|
snd_mixer_sid_t *sid;
|
||||||
|
@ -691,7 +695,7 @@ static int cset(int argc, char *argv[], int roflag)
|
||||||
snd_control_id_t id;
|
snd_control_id_t id;
|
||||||
snd_control_t control;
|
snd_control_t control;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
int idx;
|
unsigned int idx;
|
||||||
long tmp;
|
long tmp;
|
||||||
|
|
||||||
if (argc < 1) {
|
if (argc < 1) {
|
||||||
|
@ -785,7 +789,7 @@ static channel_mask_t chanmask[] = {
|
||||||
{"rearright", SND_MIXER_CHN_MASK_REAR_RIGHT},
|
{"rearright", SND_MIXER_CHN_MASK_REAR_RIGHT},
|
||||||
{"rear", SND_MIXER_CHN_MASK_REAR_LEFT|SND_MIXER_CHN_MASK_REAR_RIGHT},
|
{"rear", SND_MIXER_CHN_MASK_REAR_LEFT|SND_MIXER_CHN_MASK_REAR_RIGHT},
|
||||||
{"woofer", SND_MIXER_CHN_MASK_WOOFER},
|
{"woofer", SND_MIXER_CHN_MASK_WOOFER},
|
||||||
{NULL}
|
{NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
static int check_channels(char *arg, unsigned int mask, unsigned int *mask_return)
|
static int check_channels(char *arg, unsigned int mask, unsigned int *mask_return)
|
||||||
|
@ -801,9 +805,11 @@ static int check_channels(char *arg, unsigned int mask, unsigned int *mask_retur
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sset(int argc, char *argv[], int roflag)
|
static int sset(unsigned int argc, char *argv[], int roflag)
|
||||||
{
|
{
|
||||||
int err, idx, chn;
|
int err;
|
||||||
|
unsigned int idx;
|
||||||
|
snd_mixer_channel_id_t chn;
|
||||||
unsigned int channels;
|
unsigned int channels;
|
||||||
snd_mixer_t *handle;
|
snd_mixer_t *handle;
|
||||||
snd_mixer_sid_t sid;
|
snd_mixer_sid_t sid;
|
||||||
|
@ -864,14 +870,15 @@ static int sset(int argc, char *argv[], int roflag)
|
||||||
|
|
||||||
multi = (strchr(argv[idx], ',') != NULL);
|
multi = (strchr(argv[idx], ',') != NULL);
|
||||||
ptr = argv[idx];
|
ptr = argv[idx];
|
||||||
for (chn = 0; chn <= SND_MIXER_CHN_LAST; chn++) {
|
for (chn = 0; chn <= SND_MIXER_CHN_LAST; snd_enum_incr(chn)) {
|
||||||
if (!(control.channels & (1<<chn)) ||
|
int c = snd_enum_to_int(chn);
|
||||||
!(channels & (1<<chn)))
|
if (!(control.channels & (1<<c)) ||
|
||||||
|
!(channels & (1<<c)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (! multi)
|
if (! multi)
|
||||||
ptr = argv[idx];
|
ptr = argv[idx];
|
||||||
control.volume.values[chn] = get_volume_simple(&ptr, control.min, control.max, control.volume.values[chn]);
|
control.volume.values[c] = get_volume_simple(&ptr, control.min, control.max, control.volume.values[c]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
error("Unknown setup '%s'..\n", argv[idx]);
|
error("Unknown setup '%s'..\n", argv[idx]);
|
||||||
|
@ -893,34 +900,34 @@ static int sset(int argc, char *argv[], int roflag)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void events_change(snd_ctl_t *handle, snd_hcontrol_t *hcontrol)
|
static void events_change(snd_ctl_t *handle ATTRIBUTE_UNUSED, snd_hcontrol_t *hcontrol)
|
||||||
{
|
{
|
||||||
printf("event change: ");
|
printf("event change: ");
|
||||||
show_control_id(&hcontrol->id);
|
show_control_id(&hcontrol->id);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void events_value(snd_ctl_t *handle, snd_hcontrol_t *hcontrol)
|
static void events_value(snd_ctl_t *handle ATTRIBUTE_UNUSED, snd_hcontrol_t *hcontrol)
|
||||||
{
|
{
|
||||||
printf("event value: ");
|
printf("event value: ");
|
||||||
show_control_id(&hcontrol->id);
|
show_control_id(&hcontrol->id);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void events_remove(snd_ctl_t *handle, snd_hcontrol_t *hcontrol)
|
static void events_remove(snd_ctl_t *handle ATTRIBUTE_UNUSED, snd_hcontrol_t *hcontrol)
|
||||||
{
|
{
|
||||||
printf("event remove: ");
|
printf("event remove: ");
|
||||||
show_control_id(&hcontrol->id);
|
show_control_id(&hcontrol->id);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void events_rebuild(snd_ctl_t *handle, void *private_data)
|
static void events_rebuild(snd_ctl_t *handle ATTRIBUTE_UNUSED, void *private_data)
|
||||||
{
|
{
|
||||||
assert(private_data != (void *)1);
|
assert(private_data != (void *)1);
|
||||||
printf("event rebuild\n");
|
printf("event rebuild\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void events_add(snd_ctl_t *handle, void *private_data, snd_hcontrol_t *hcontrol)
|
static void events_add(snd_ctl_t *handle ATTRIBUTE_UNUSED, void *private_data, snd_hcontrol_t *hcontrol)
|
||||||
{
|
{
|
||||||
assert(private_data != (void *)1);
|
assert(private_data != (void *)1);
|
||||||
printf("event add: ");
|
printf("event add: ");
|
||||||
|
@ -931,7 +938,7 @@ static void events_add(snd_ctl_t *handle, void *private_data, snd_hcontrol_t *hc
|
||||||
hcontrol->event_remove = events_remove;
|
hcontrol->event_remove = events_remove;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int events(int argc, char *argv[])
|
static int events(int argc ATTRIBUTE_UNUSED, char *argv[] ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
snd_ctl_t *handle;
|
snd_ctl_t *handle;
|
||||||
snd_hcontrol_t *hcontrol;
|
snd_hcontrol_t *hcontrol;
|
||||||
|
@ -975,40 +982,40 @@ static int events(int argc, char *argv[])
|
||||||
snd_ctl_close(handle);
|
snd_ctl_close(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sevents_rebuild(snd_mixer_t *handle, void *private_data)
|
static void sevents_rebuild(snd_mixer_t *handle ATTRIBUTE_UNUSED, void *private_data ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
printf("event rebuild\n");
|
printf("event rebuild\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sevents_value(snd_mixer_t *handle, void *private_data, snd_mixer_sid_t *sid)
|
static void sevents_value(snd_mixer_t *handle ATTRIBUTE_UNUSED, void *private_data ATTRIBUTE_UNUSED, snd_mixer_sid_t *sid)
|
||||||
{
|
{
|
||||||
char name[simple_name_size];
|
char name[simple_name_size];
|
||||||
|
|
||||||
printf("event value: '%s',%i\n", simple_name(sid->name, name), sid->index);
|
printf("event value: '%s',%i\n", simple_name(sid->name, name), sid->index);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sevents_change(snd_mixer_t *handle, void *private_data, snd_mixer_sid_t *sid)
|
static void sevents_change(snd_mixer_t *handle ATTRIBUTE_UNUSED, void *private_data ATTRIBUTE_UNUSED, snd_mixer_sid_t *sid)
|
||||||
{
|
{
|
||||||
char name[simple_name_size];
|
char name[simple_name_size];
|
||||||
|
|
||||||
printf("event change: '%s',%i\n", simple_name(sid->name, name), sid->index);
|
printf("event change: '%s',%i\n", simple_name(sid->name, name), sid->index);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sevents_add(snd_mixer_t *handle, void *private_data, snd_mixer_sid_t *sid)
|
static void sevents_add(snd_mixer_t *handle ATTRIBUTE_UNUSED, void *private_data ATTRIBUTE_UNUSED, snd_mixer_sid_t *sid)
|
||||||
{
|
{
|
||||||
char name[simple_name_size];
|
char name[simple_name_size];
|
||||||
|
|
||||||
printf("event add: '%s',%i\n", simple_name(sid->name, name), sid->index);
|
printf("event add: '%s',%i\n", simple_name(sid->name, name), sid->index);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sevents_remove(snd_mixer_t *handle, void *private_data, snd_mixer_sid_t *sid)
|
static void sevents_remove(snd_mixer_t *handle ATTRIBUTE_UNUSED, void *private_data ATTRIBUTE_UNUSED, snd_mixer_sid_t *sid)
|
||||||
{
|
{
|
||||||
char name[simple_name_size];
|
char name[simple_name_size];
|
||||||
|
|
||||||
printf("event remove: '%s',%i\n", simple_name(sid->name, name), sid->index);
|
printf("event remove: '%s',%i\n", simple_name(sid->name, name), sid->index);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sevents(int argc, char *argv[])
|
static int sevents(int argc ATTRIBUTE_UNUSED, char *argv[] ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
snd_mixer_t *handle;
|
snd_mixer_t *handle;
|
||||||
static snd_mixer_simple_callbacks_t callbacks = {
|
static snd_mixer_simple_callbacks_t callbacks = {
|
||||||
|
|
|
@ -364,7 +364,7 @@ int main(int argc, char *argv[])
|
||||||
rhwparams.channels = 2;
|
rhwparams.channels = 2;
|
||||||
} else {
|
} else {
|
||||||
rhwparams.format = snd_pcm_format_value(optarg);
|
rhwparams.format = snd_pcm_format_value(optarg);
|
||||||
if (rhwparams.format < 0) {
|
if (rhwparams.format == SND_PCM_FORMAT_UNKNOWN) {
|
||||||
error("wrong extended format '%s'", optarg);
|
error("wrong extended format '%s'", optarg);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue