How to set USB-Headset volume with udev and amixer

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

 



Hi all,

I have a C-Media USB Headphone Set which is working well. One issue though is 
that when plugging it in the mixer levels are initialized to bad values. The 
"Speaker" level is set to 100% (*very* loud, like in "ouch !!!") while the "Mic 
Capture" level is set to 0%.

Therefore I set the mixer levels by hand (using alsamixer) until now. So I wrote 
a script which is invoked by udev. The script tries to set the levels using amixer.


dmesg output:
================================================================================
[ 6010.971400] usb 5-1: new full speed USB device using uhci_hcd and address 2
[ 6011.116126] usb 5-1: configuration #1 chosen from 1 choice
[ 6011.124401] input: C-Media USB Headphone Set   as 
/devices/pci0000:00/0000:00:1d.0/usb5/5-1/5-1:1.3/input/input9
[ 6011.127448] generic-usb 0003:0D8C:000C.0002: input: USB HID v1.00 Device 
[C-Media USB Headphone Set  ] on usb-0000:00:1d.0-1/input3
[ 6011.127931] usb 5-1: New USB device found, idVendor=0d8c, idProduct=000c
[ 6011.127936] usb 5-1: New USB device strings: Mfr=0, Product=1, SerialNumber=0
[ 6011.127942] usb 5-1: Product: C-Media USB Headphone Set
[ 6011.309124] usbcore: registered new interface driver snd-usb-audio
================================================================================


amixer output:
================================================================================
jens:~> amixer -c1
Simple mixer control 'Mic',0
   Capabilities: pvolume pvolume-joined cvolume cvolume-joined pswitch 
pswitch-joined cswitch cswitch-joined
   Playback channels: Mono
   Capture channels: Mono
   Limits: Playback 0 - 32 Capture 0 - 16
   Mono: Playback 23 [72%] [34.50dB] [off] Capture 0 [0%] [0.00dB] [on]
Simple mixer control 'Auto Gain Control',0
   Capabilities: pswitch pswitch-joined
   Playback channels: Mono
   Mono: Playback [on]
Simple mixer control 'Speaker',0
   Capabilities: pvolume pswitch pswitch-joined
   Playback channels: Front Left - Front Right
   Limits: Playback 0 - 151
   Mono:
   Front Left: Playback 150 [99%] [-1.37dB] [on]
   Front Right: Playback 150 [99%] [-1.37dB] [on]
================================================================================



So I wrote the following script and udev rule:

Udev rule (a single line in the file):
================ /etc/udev/rules.d/usb-headset.rules contents: =================
ATTR{idProduct}=="000c", ATTR{idVendor}=="0d8c", ACTION=="add", 
RUN+="/usr/local/bin/headset_volume.sh"
================================================================================



Script (It writes the amixer output to a logfile for debugging purposes):
================ /usr/local/bin/headset_volume.sh contents: ====================
#!/bin/sh

exec >> /home/jens/log.file

/usr/bin/amixer -c1 sset Mic 75%
echo $?
/usr/bin/amixer -c1 sset Speaker 25%
echo $?
================================================================================



The script is executed since I get the log file, but amixer obviously isn't 
executed correctly, here's the log file contents:
============================ logfile contents ================================

Usage: amixer <options> [command]

Available options:
   -h,--help       this help
   -c,--card N     select the card
   -D,--device N   select the device, default 'default'
   -d,--debug      debug mode
   -n,--nocheck    do not perform range checking
   -v,--version    print version of this program
   -q,--quiet      be quiet
   -i,--inactive   show also inactive controls
   -a,--abstract L select abstraction level (none or basic)
   -s,--stdin      Read and execute commands from stdin sequentially

Available commands:
   scontrols       show all mixer simple controls
   scontents	  show contents of all mixer simple controls (default command)
   sset sID P      set contents for one mixer simple control
   sget sID        get contents for one mixer simple control
   controls        show all controls for given card
   contents        show contents of all controls for given card
   cset cID P      set control contents for one control
   cget cID        get control contents for one control
1
Usage: amixer <options> [command]

Available options:
   -h,--help       this help
   -c,--card N     select the card
   -D,--device N   select the device, default 'default'
   -d,--debug      debug mode
   -n,--nocheck    do not perform range checking
   -v,--version    print version of this program
   -q,--quiet      be quiet
   -i,--inactive   show also inactive controls
   -a,--abstract L select abstraction level (none or basic)
   -s,--stdin      Read and execute commands from stdin sequentially

Available commands:
   scontrols       show all mixer simple controls
   scontents	  show contents of all mixer simple controls (default command)
   sset sID P      set contents for one mixer simple control
   sget sID        get contents for one mixer simple control
   controls        show all controls for given card
   contents        show contents of all controls for given card
   cset cID P      set control contents for one control
   cget cID        get control contents for one control
1
============================ end of logfile ================================

Of course, if I manually execute the commands from the script they work 
flawlessly. Also executing the script manually from a terminal sets the volume 
levels correctly.

Adding a "sleep 5" at the top of the script didn't work either.
I also tried manually invoking amixer with a clean environment (since udev only 
passes a very minimalistic environment to the script) but amixer worked without 
problems.

What am I missing ? Why is amixer not working correctly when it is called from udev.

Best regards,
Jens

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
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