Thursday, April 11, 2013

How make usb-headset as default sound card in Arch Linux

last week I installed ArchBang as replacement to ubuntu ,the installation process went smoothly since all partitions were already set-up, I like it so far , it's more challenging and the learning-curve for me has been great, it requires much more tweaking but in the end , you are in control of every bit of your system. I had few problems though, one of them was cofiguring ALSA sound drivers to take USB-Headset as default card for sound playback, it's possible to choose the audio driver in Smplayer and VLC but not all apps offer this feature and best solution is to edit system-wide setting to take the usb-headset as default.
this is the source I used (if you are into reading  +1000 word guide =) ).
here what i did:
I created a sh script  to generate .asoundrc file with usb-headset as default device
 nano asoundrc.sh  
 paste the following code
 % cat /usr/bin/asoundrc  
 #!/bin/bash  
 # asoundrc v0.1.0 20090101 markc@renta.net GPLv3  
 # asoundrc v0.2.0 20090320 quatro_por_quatro@yahoo.es GPLv3  
 #  
 # A simple script to create a particular default audio device regardless  
 # of what cards are loaded or in what order. It could be used anytime or  
 # placed in a ~/.bashrc script for a persistent setup every login.  
 #  
 # Usage: asoundrc [DEFAULT_CARD] > ~/.asoundrc  
 # use the first parameter as the card name, or else  
 # look for the sound card, discarding those that are only microphones  
 # when there are multiple cards, use the first one  
 if default_card="${1:-$(cat "$(for f in $(ls -1 /proc/asound/card[0-9]*/{midi,codec}* 2>/dev/null); do echo "${f%/*}"; done \  
 | sed -e '\|^[\[:blank:]\]$|d' -e 'q')/id" 2>/dev/null)}"; then  
   echo "Using sound card: ${default_card}" >&2   
   cat /proc/asound/card[0-9]*/id | \  
   gawk --assign default_card="${default_card}" \  
 '{print "pcm."$1" { type hw; card "$1"; }\nctl."$1" { type hw; card "$1"; }" }  
 END {print "pcm.!default pcm."default_card"\nctl.!default ctl."default_card}'  
 else  
   echo "Warning: No sound cards found." >&2  
 fi 
 
 chmod a+x asounrc.sh  
execute the script

here is the output in my case


Using sound card: Intel
pcm.Intel { type hw; card Intel; }
ctl.Intel { type hw; card Intel; }
pcm.CinemaTM { type hw; card CinemaTM; }
ctl.CinemaTM { type hw; card CinemaTM; }
pcm.Headset { type hw; card Headset; }
ctl.Headset { type hw; card Headset; }
pcm.!default pcm.Intel
ctl.!default ctl.Intel
as you can tell, the default card  is Intel (last two lines) , all we need to replace intel with Headset ,copy the text
now create .asoundrc file in your home folder , paste the code , log out then log-in , to see the changes

 #create .asoundrc file in your home folder  
 sudo nano ~/.asoundrc  
 #paste the code and save your work  
 pcm.Intel { type hw; card Intel; }  
 ctl.Intel { type hw; card Intel; }  
 pcm.CinemaTM { type hw; card CinemaTM; }  
 ctl.CinemaTM { type hw; card CinemaTM; }  
 pcm.Headset { type hw; card Headset; }  
 ctl.Headset { type hw; card Headset; }  
 pcm.!default pcm.Headset  
 ctl.!default ctl.Headset  

there are may be other ways to do the same thing but this one sounds simple and did the job for me.


3 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete