On Wed, Aug 4, 2010 at 1:20 AM, Raymond Yau <superquad.vortex2(a)gmail.com> wrote:
The "-D" option seem to be used similar to
"amixer -Dabc"
ctl.abc { type hw , card 2 }
Raymond --
Thanks for the clarification regarding the use of the -D argument for
alsa control devices. I've updated my code to handle things in the
same way that amixer does. The diffs for this change are at the end of
this message, and attached. ALSA names for examples/tests below from
http://nielsmayer.com/npm/dot-asoundrc.txt ....
.........................................
gnulem-277-~> /usr/bin/envy24control -D66 ##behavior on current
head and latest stable release
Segmentation fault (core dumped)
gnulem-278-~> envy24control -D66 ##behavior using this patch ...
using --- input_channels: 4
gnulem-279-~> envy24control -D666
ALSA lib control.c:902:(snd_ctl_open_noupdate) Invalid CTL 666
envy24control: cannot open mixer: No such file or directory - '666'
gnulem-280-~> envy24control -Dhw:66
envy24control: invalid ALSA audio device, invalid index or name for card: hw:66
gnulem-281-~> envy24control -Dhw:M66
using --- input_channels: 4
gnulem-282-~> envy24control -Dmulti
invalid card type (driver is HDA-Intel)
gnulem-283-~> envy24control -Ddefault
invalid card type (driver is USB-Audio)
gnulem-284-~> envy24control -c default
envy24control: invalid ALSA index or name for audio card: default
gnulem-285-~> envy24control -c SB
invalid card type (driver is HDA-Intel)
gnulem-286-~> envy24control -c multi
envy24control: invalid ALSA index or name for audio card: multi
gnulem-287-~> envy24control -c M66
using --- input_channels: 4
gnulem-299-~> amixer -Dhw:/dev/snd/controlC2 >! /tmp/foo
gnulem-301-~> amixer -D/dev/snd/controlC2 > ! /tmp/foo
ALSA lib control.c:902:(snd_ctl_open_noupdate) Invalid CTL /dev/snd/controlC2
amixer: Mixer attach /dev/snd/controlC2 error: No such file or directory
gnulem-290-~> envy24control -D/dev/snd/controlC2
ALSA lib control.c:902:(snd_ctl_open_noupdate) Invalid CTL /dev/snd/controlC2
envy24control: cannot open mixer: No such file or directory -
'/dev/snd/controlC2'
.........................................
diff --git a/envy24control/envy24control.c b/envy24control/envy24control.c
index 0b2749e..e5d89d0 100644
--- a/envy24control/envy24control.c
+++ b/envy24control/envy24control.c
@@ -2084,3 +2166,3 @@ int main(int argc, char **argv)
view_spdif_playback = 0;
profiles_file_name = DEFAULT_PROFILERC;
default_profile = NULL;
while ((c = getopt_long(argc, argv, "D:c:f:i:m:Mo:p:s:w:vt:",
long_options, NULL)) != -1) {
switch (c) {
case 'D':
- name = optarg;
- card_number = atoi(strchr(name, ':') + sizeof(char));
- if (card_number < 0 || card_number >= MAX_CARD_NUMBERS) {
- fprintf(stderr, "envy24control: invalid card number %d\n", card_number);
- exit(1);
+ /* NPM: old code assumed ':' present, e.g. "-Dhw:66",
+ * (w/ .asoundrc "ctl.66 {type hw, card M66}") and would
+ * coredump if given "-D66". Prevent the coredump and even
+ * handle latter case even if keying off ':' is not a
+ * good way to do this. Note that for snd_card_get_index()
+ * "The accepted format is an integer value in ASCII
representation or the card
+ * identifier (the id parameter for sound-card drivers). The control device
+ * name like /dev/snd/controlC0 is accepted, too." */
+ if (!index(optarg, ':')) {
+ /* NPM: unlike old envy24control code, but behaving like amixer et al,
+ "-D66" is valid. Handle it. */
+ snd_mixer_t *mixer;
+ struct snd_mixer_selem_regopt selem_regopt = {
+ .ver = 1,
+ .abstract = SND_MIXER_SABSTRACT_NONE,
+ .device = optarg,
+ };
+ if ((err = snd_mixer_open(&mixer, 0)) < 0) {
+ fprintf(stderr, "envy24control: cannot open mixer: %s -
'%s'\n", snd_strerror(err), optarg);
+ exit(1);
+ }
+ if ((err = snd_mixer_selem_register(mixer, &selem_regopt, NULL)) < 0) {
+ fprintf(stderr, "envy24control: cannot open mixer: %s -
'%s'\n", snd_strerror(err), optarg);
+ exit(1);
+ }
+ name = optarg; /* NPM: now that device name validated, e.g.
pass "-D66" unaltered to snd_ctl_open()... */
+ }
+ else {
+ /* NPM: handle e.g. optarg == "hw:M66" */
+ card_number = snd_card_get_index(strchr(optarg, ':') +
sizeof(char)); /* NPM: use correct ALSA-specific call to fix
https://bugzilla.redhat.com/show_bug.cgi?id=602900 */
+ if (card_number < 0) {
+ fprintf(stderr, "envy24control: invalid ALSA audio device,
invalid index or name for card: %s\n", optarg);
+ exit(1);
+ }
+ name = optarg; /* e.g. optarg == "hw:M66" passed to
snd_ctl_open() below */
}
break;
case 'c':
- i = atoi(optarg);
- if (i < 0 || i >= MAX_CARD_NUMBERS) {
- fprintf(stderr, "envy24control: invalid card number %d\n", i);
+ card_number = snd_card_get_index(optarg); /* NPM: use correct
ALSA-specific call to fix
https://bugzilla.redhat.com/show_bug.cgi?id=602900 */
+ if (card_number < 0) { /* NPM: code orig from alsa-utils/alsamixer/cli.c */
+ fprintf(stderr, "envy24control: invalid ALSA index or name for
audio card: %s\n", optarg);
exit(1);
}
- card_number = i;
- sprintf(tmpname, "hw:%d", i);
+ sprintf(tmpname, "hw:%d", card_number); /* e.g. "hw:M66" for arg
"-cM66" passed to snd_ctl_open() below */
name = tmpname;
break;
case 'f':
.........................................
--Niels
http://nielsmayer.com