My First WordPress Plugin: Please Welcome shantz-wp-qotd SmartPhones/NextGen Telephony: News That Matters
Feb 12
My Sites: My Blog | My Tech Blog | Follow me on Twitter
—-

If you have multiple soundcards in your system and have to switch between them regularly (e.g. laptop owners like me, who use an external soundcard while being docked to groove to the highest and the lowest of frequencies through those 7.1 channels and use the in-built sound card while on the move) you would definitely be under-whelmed by the less-than-stellar performance of ubuntu in switching between the sound cards. For me at least, ubuntu (fiesty 7.04 amd64) never seems to recognize that I’ve connected the speakers to my Audigy 2 ZS Notebook PCMCIA card, and merrily continues to huff-puff through the tinny laptop speakers until I manually go into the sound preferences, switch over to multichannel playback and vice versa. Well, I still haven’t found an automated solution for the switching, but here is a little cli-magic to do this in a click.

If you have alsa on ur system, just use the command “asoundconf list” first to list out all the soundcards connected to your system. e.g. on my system, the output is

$asoundconf list
IXP
AUDIGY2

Here, IXP is my internal sound card and AUDIGY2 is my external (PCMCIA) sound card. Now, all you need to is use “asoundconf set-default-card <cardname>” to switch over to any card desired. So, what I did was make 2 bash scripts, and insert this command in them with each having one of my soundcards’ names.

script 1 – setixp.sh

#!/bin/bash
asoundconf set-default-card IXP

Similarly, script 2 – setaudigy.sh

#!/bin/bash
asoundconf set-default-card AUDIGY2

Now, all that remains is save the two scripts (maybe in ur home directory or ur desktop), and make them executable (use “chmod +x <scriptname>”). Now, whenever you want to switch to a card, just double-click on the appropriate script, and watch the sound getting redirected. oops, make that “hear” the sound :P.


—-
If you liked this post, then you can Subscribe to my feed
Quote of the day: “The unplanned organism is a question asked by Nature and answered by Death. You are another kind of question, with another kind of answer.” -Morpheus

Share and Enjoy:
  • Digg
  • del.icio.us
  • blogmarks
  • IndianPad
  • StumbleUpon
  • Technorati
  • Facebook
  • Live
  • Reddit
  • Slashdot
  • YahooMyWeb
  • e-mail

Related posts

written by Shantanu Goel \\ tags: , , , , , , , , , ,

2 Responses to “TIP: Switching Soundcards In Ubuntu”

  1. Rahul Gupta Says:

    An alternative way to do the same in a single script (without prior knowledge of installed cards) would be

    #!/bin/bash

    oldIFS=${IFS}
    IFS=$’\n’
    cardList=($(asoundconf list | grep -v “Names of available sound cards”))
    IFS=${oldIFS}

    if [ ${#cardList[@]} -eq 1 ]
    then
    echo “The system detedted only 1 audio card”
    echo “Press enter to exit”
    read
    exit 0
    fi

    echo “Select the AUDIO card to be selected as default”
    select card in “${cardList[@]}”
    do
    if [ -n "${card}" ]
    then
    echo “Changing default-card to: ${card}”
    asoundconf set-default-card ${card}
    echo “Press enter to exit”
    read
    exit $?
    else
    echo “Please select a valid entry”
    fi
    done

  2. Shantanu Goel Says:

    Yeah, that’d be a good and generic approach. But it’d take a click and some typing :). It can be used as it is by someone who just doesn’t want to make his own script.
    But, a bit of extra effort (pre-determining the soundcards available) would make it much easier and faster later on (single click switching).

Leave a Reply