Comment 17 for bug 31699

Revision history for this message
Daniel T Chen (crimsun) wrote : Malone #31699 (alsa-utils: asoundconf: gnome-control-center && default sound card)

Martin et al.,

I've done some further debugging for Malone #31699, and it appears that
the current fix for #35540 is insufficient (partially my fault). Some
applications expect defaults.pcm.device and defaults.pcm.subdevice,
which must be integers due to /usr/share/alsa/alsa.conf's use of
igetenv for .DEV and .SUBDEV. So to make all audio applications play
nicely together, we need to enumerate the following variables in
~/.asoundrc.asoundconf:

!defaults.pcm.card <string>
!defaults.ctl.card <string>
defaults.pcm.device <integer>
defaults.pcm.subdevice <integer>
[pcm.device <integer>]

Here's the breakdown: defaults.pcm.card and defaults.ctl.card can be
strings (as ``asoundconf list'', in which case the ! is required) or
integers (in which case the ! shouldn't appear). Currently gnome-
control-center sets these two variables, and most apps play nicely.
However, apps like jackd normally require a specific device (implying
that its subdevice must also be set), in which case defaults.pcm.device
and defaults.pcm.subdevice must also be set. The good news is that we
can get away with setting defaults.pcm.subdevice -1 (per definition in
/usr/share/alsa/alsa.conf) always, since apps will override it as
necessary.

I've currently been testing an ~/.asoundrc.asoundconf, and the above
variables for my current sound card configuration (only one on-board
Intel ICH6; the external USB M-Audio Transit is not present) are as
follows:

!defaults.pcm.card ICH6
!defaults.ctl.card ICH6
defaults.pcm.device 0
defaults.pcm.subdevice -1
pcm.device 1

so that I can use the on-board ICH6 by default and still use jackd with
either the onboard or the external usb sound device.

I've tested using both amixer and jackd with the above block (both with
and without pcm.device 1) as follows:

amixer && amixer -c0 && amixer -c1
jackd -d alsa && jackd -d alsa -dhw:0 && jackd -d alsa -dhw:1

The first two invocations of each program (i.e., amixer && amixer -c0
and jackd -d alsa && jackd -d alsa -dhw:0) work exactly as expected. I
am able to list the values of the mixer and successfully invoke jackd.
With pcm.device 1 present in ~/.asoundrc.asoundconf, I am able to
invoke the last set of each program (i.e., amixer -c1 and
jackd -d alsa -dhw:1) with the expected result that there is no such
device. I also receive identical results without pcm.device 1 present
in ~/.asoundrc.asoundconf.

The reason I mention additional "pcm.device"s is because of the
previously mentioned situation where a user may have multiple sound
cards detected and wish to have GNOME use a different default card from
say, jackd.

So, recap, and conclude with what we need to do to resolve #31699 and
its unfortunate duplicates:

At the very least ~/.asoundrc.asoundconf needs to have values for:

defaults.pcm.card
defaults.ctl.card
defaults.pcm.device
defaults.pcm.subdevice

I suggest we use the nominal default of -1 for defaults.pcm.subdevice,
continue using the strings for !defaults.{ctl,pcm}.card, and use an
integer for defaults.pcm.device. This means that gnome-control-center's
debian/patches/23_default_soundcard_selector.patch needs to be modified
such that set_default_card() also sets defaults.pcm.device and
defaults.pcm.subdevice, which should be straightforward since
get_soundcards() already enumerates card_ids, so we can set the integer
associated with val for defaults.pcm.device.

Furthermore, I suggest we go ahead and enumerate all "pcm.device"s so
that users with multiple cards can use hw:X regardless whether it is
also the default device. This is straightforward: We can simply list:

pcm.device 0
pcm.device 1
pcm.device 2
...

for each id in the GArray* card_ids. To have both defaults.pcm.device 0
and pcm.device 0 is harmless. Whenever default_card_changed() returns
success, we should set !defaults.{ctl,pcm}.card and
defaults.pcm.device.

So, what can all of you subscribed to this bug do? If you have multiple
cards, _please test_ what I've described above. For instance, if you
have two sound devices, please try:

!defaults.pcm.card ICH6
!defaults.ctl.card ICH6
defaults.pcm.device 0
defaults.pcm.subdevice -1
pcm.device 0
pcm.device 1

in your ~/.asoundrc.asoundconf (of course replacing ICH6 with your
proper string identifier). Then fire up amixer or your ALSA app of
choice in addition to, say, jackd, and experiment with using different
"defaults.pcm.device"s (defaults.pcm.subdevice should remain -1), and
please comment in this bug report.

Thanks,
--
Daniel T. Chen <email address hidden>
GPG key: www.sh.nu/~crimsun/pubkey.gpg.asc