Re: [LAD] [alsa-devel] announcing envy24control, mudita (*) edition.

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Raymond Yau <superquad.vortex2@...>
Cc: ALSA Development Mailing List <alsa-devel@...>, Linux Audio Developers <linux-audio-dev@...>
Date: Thursday, August 5, 2010 - 2:18 am

On Wed, Aug 4, 2010 at 1:20 AM, Raymond Yau w=
rote:

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: h=
w: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/control=
C2
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/control=
C2
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 =3D 0;
profiles_file_name =3D DEFAULT_PROFILERC;
default_profile =3D NULL;
while ((c =3D getopt_long(argc, argv, "D:c:f:i:m:Mo:p:s:w:vt:",
long_options, NULL)) !=3D -1) {
switch (c) {
case 'D':
- name =3D optarg;
- card_number =3D atoi(strchr(name, ':') + sizeof(char));
- if (card_number < 0 || card_number >=3D 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 de=
vice
+ * 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 =3D {
+ .ver =3D 1,
+ .abstract =3D SND_MIXER_SABSTRACT_NONE,
+ .device =3D optarg,
+ };
+ if ((err =3D snd_mixer_open(&mixer, 0)) < 0) {
+ fprintf(stderr, "envy24control: cannot open mixer: %s -
'%s'\n", snd_strerror(err), optarg);
+ exit(1);
+ }
+ if ((err =3D 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 =3D optarg; /* NPM: now that device name validated, e.g.
pass "-D66" unaltered to snd_ctl_open()... */
+ }
+ else {
+ /* NPM: handle e.g. optarg =3D=3D "hw:M66" */
+ card_number =3D snd_card_get_index(strchr(optarg, ':') +
sizeof(char)); /* NPM: use correct ALSA-specific call to fix
https://bugzilla.redhat.com/show_bug.cgi?id=3D602900 */
+ if (card_number < 0) {
+ fprintf(stderr, "envy24control: invalid ALSA audio device,
invalid index or name for card: %s\n", optarg);
+ exit(1);
+ }
+ name =3D optarg; /* e.g. optarg =3D=3D "hw:M66" passed to
snd_ctl_open() below */
}
break;
case 'c':
- i =3D atoi(optarg);
- if (i < 0 || i >=3D MAX_CARD_NUMBERS) {
- fprintf(stderr, "envy24control: invalid card number %d\n", i);
+ card_number =3D snd_card_get_index(optarg); /* NPM: use correct
ALSA-specific call to fix
https://bugzilla.redhat.com/show_bug.cgi?id=3D602900 */
+ 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 =3D 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 =3D tmpname;
break;
case 'f':

.........................................

--Niels
http://nielsmayer.com

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [LAD] [alsa-devel] announcing envy24control, mudita (*) ..., Niels Mayer, (Thu Aug 5, 2:18 am)