Akom's Tech Ruminations

Various tech outbursts - code and solutions to practical problems
Linux

Predictable ALSA numbering of USB sound cards

Posted by Admin • Wednesday, January 12. 2011 • Category: Linux

I have 3 rather cute Monoprice usb sound cards for use by mmpd (client I wrote for multiple mpd instances). The great thing about them is that for $9 you can just keep adding zones to your music systems. The bad news is, UDEV will reorder sound cards on boot as it pleases.

Zones changing would be survivable in itself (reboots are rare), but I also have a webcam and an onboard sound card that I don't use - so sometimes the numbers I've configured mpd to use aren't even valid sound cards! On to the continuing search for a working solution

First of all, the problem is known, and has a few pages dedicated to it: one two three Yet these pages don't really provide a complete solution to the problem. There are two ways to address it:
  1. via module options (alsa way)
  2. via UDEV (hardware way)

I was successful with the first option. The idea is simple - just put the card numbers you want in the modprobe conf file like this:
modprobe.d/alsa-base.conf:
# AKOM: changing this to make usb sound cards numbered from 10 # Anything that isn't a monoprice sound card will start from 0 or 1 options snd-usb-audio index=10,11,12 vid=0x0d8c,0x0d8c,0x0d8c pid=0x000e,0x000e,0x000e

To get the values for vid and pid, run lsusb -v and find VendorId and ProductId for your device.

This is a working solution, but it achieves only one thing: all the USB sound cards from the named vendor will be given the specified numbers. However, the 3 cards listed above can be assigned in any order - either card can be 10,11 or 12. If you had different types of cards this solution is all you'd need - the vid and pid lists would contain different items

The proper(er) way to solve this would be via UDEV. In theory, a rule can be written that would rename the device, but even though I was able to get UDEV to run a script of my choice, I could not figure out how to actually tell UDEV to tell ALSA to give the card a different number. The script could decide which card it should be based on the $PHYSDEVPATH value - basically which USB port the card's in - as everything else about the cards is identical. I gave up on it for now, so if anyone knows how - let me know.

Udev rule writing is described here

0 Trackbacks

  1. No Trackbacks

1 Comments

Display comments as (Linear | Threaded)
  1. Trying to do something similar and found this article http://alsa.opensrc.org/Udev

Add Comment


You can use [geshi lang=lang_name [,ln={y|n}]][/geshi] tags to embed source code snippets.
Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.
Markdown format allowed


Submitted comments will be subject to moderation before being displayed.