Re: Identical USB cards to fixed card numbers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Unfortunately there are no serial numbers, so my rules are based on the path given by the kernetl. Here's my current script:

#!/bin/bash
kernelStr=$1
devicePathStr=$2


# TEST DATA - PCM
# kernelStr="pcmC1D0pc"
# devicePathStr=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1:1.0/sound/card1/pcmC1D0c

# TEST DATA - HW
# kernelStr="hwC1D0p"
# devicePathStr=/devices/pci0000:00/0000:00:1d.0/usb2/2-2/2-2:1.0/sound/card2/hwC2D0p

# TEST DATA - CONTROL
# kernelStr="controlC1D0p"
# devicePathStr=/devices/pci0000:00/0000:00:1d.0/usb2/2-2/2-2:1.0/sound/card2/controlC2D0p

# TEST DATA 2 - Unresolved
# kernelStr="pcmC1D0p"
# devicePathStr=/devices/pci0000:00/0000:00:1d.0/usb2/2-5/2-15:1.0/sound/card1/pcmC1D0c


# parse then 'kernel' string
if [ ${kernelStr:0:3} = "pcm" ] ; then
	offset=3
fi
if [ ${kernelStr:0:2} = "hw" ] ; then
	offset=2
fi
if [ ${kernelStr:0:7} = "control" ] ; then
	offset=7
fi
if [ ${kernelStr:0:7} = "midi" ] ; then
	offset=4
fi
cardType=${kernelStr:0:offset}
deviceNumber=${kernelStr:${#cardType}+3:1}
interfaceType=${kernelStr:${#cardType}+4:1}

# parse the device path string to retrieve the usb port from it
usbPortStringPosition=42
usbPortSpecifier=${devicePathStr:usbPortStringPosition:3} 

# !!! you may have to update usbPortStringPosition to match the device path format on your machine. The easiest way to see the paths is to echo the value into a file, by uncommenting the following (then unplugging/plugging USB cards to trigger this script):
echo ${devicePathStr} >> ~/alsa_name.log

# find - and if applicable apply - mapping rules from USB port to card number
# !!! UPDATE THIS TO SUIT YOUR USB PORT NAMES AND REQUIRED CARD NUMBERS
if [ "$usbPortSpecifier" = "2-2" ] ; then
	cardNumber="1"
elif [ "$usbPortSpecifier" = "2-1" ] ; then
	cardNumber="2"
elif [ "$usbPortSpecifier" = "4-2" ] ; then
	cardNumber="3"
fi

# debug statements
# echo  - usb port specifier: ${usbPortSpecifier}
# echo  - sound card type: ${cardType}
# echo  - device number: ${deviceNumber}
# echo  - interface: ${interfaceType}, where p = playback, c = capture

# apply the mapping if there is one
if [ $cardNumber != "" ] ; then
	deviceName=${cardType}C${cardNumber}D${deviceNumber}${interfaceType}
	logMessage="Mapped soundcard "$kernelStr" on USB port "${usbPortSpecifier}" to device name "${deviceName}" (card number "${cardNumber}")"
else
	deviceName=${kernelStr}
	logMessage="No custom mapping rule in alsa_name.sh applies to soundcard "$kernelStr" on USB port "${usbPortSpecifier}
fi
# echo $logMessage
echo $logMessage >> ~/alsa_name.log



# done
echo ${deviceName} # return to calling party, i.e. udev
exit 0







On Thu, 21 Jan 2010 01:12:58 am Jaroslav Kysela wrote:
> On Thu, 21 Jan 2010, Diego Tognola wrote:
> 
> > Thanks Clemens,
> >
> > I tried /dev/snd as well but maybe my 'test' is invalid ?
> >
> > My expectations was that if I have rules for USB1-> card1, USB2->card2 
> > and USB3->card3 setup, then reboot with the audio card on USB2 
> > unplugged, then I should not see a card2 in /dev/snd or cat 
> > /proc/asound/cards ? What I see, however, is a card1 and card2, no 
> > card3.
> 
> You should base your rules on USB serial numbers (hopefully the hardware 
> vendor created unique serial numbers, otherwise you have no proper way to 
> determine hw). You may also use the full hardware path (USB bus numbers 
> and USB port numbers).
> 
>  					Jaroslav
> 
> -----
> Jaroslav Kysela <perex@xxxxxxxx>
> Linux Kernel Sound Maintainer
> ALSA Project, Red Hat, Inc.
> 
> 



------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
Alsa-user mailing list
Alsa-user@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/alsa-user

[Index of Archives]     [ALSA Devel]     [Linux Audio Users]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]

  Powered by Linux