Results 1 to 10 of 37

Thread: asoundconf is dead, long live asoundconf!

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Location
    Not far from reality...
    Beans
    236
    Distro
    Xubuntu 11.10 Oneiric Ocelot

    Lightbulb asoundconf is dead, long live asoundconf!

    I wanted to bring up yet another ugly little hack that's required in Karmic Koala, all thanks to the failures of the PulseAudio brigade and their tomfoolery.

    Now this is for those who do not believe in having PulseAudio in their cute cuddly Koala. If you have Karmic Koala, you're running ALSA and have multiple sound cards, this post is for you.

    Alsa-utils no longer has asoundconf which, if you don't know, is like a car not having a transmission.

    What it does: Allows the user to switch between two sound cards (for example, on-board sound and a USB headset)

    When you need it: Only for certain situations where it is necessary to use a secondary sound card for specific things (Such as running a voice program in Virtualbox on a USB headset - which will not work with PulseAudio and some hardware, no matter how hard you try).

    What you have to do: Cheap hacks. Let me repeat - This is a crappy little hack that should not have to be done.

    Step 1: Go to http://packages.ubuntu.com/jaunty/alsa-utils and download the alsa-utils for your version of ubuntu (i386 or amd64).

    Step 2: Open a terminal and cd to the download directory and run:

    sudo dpkg -i alsa-utils_1.0.18-1ubuntu11_amd64.deb

    Step 3: Now, after this mess, cd to /usr/bin and use this command:

    sudo cp asoundconf /usr/

    Which will copy (cp) asoundconf (the file you want) to the directory /usr/

    Step 4: Run:

    sudo apt-get install asoundconf-gtk

    This will install a very nice simple gtk frontend for the asoundconf file that is no longer in existence in our software...wait what? Yeah I know, they kept the gtk and removed the actual file the gtk uses. Go figure.

    Step 5: Anyhow, next step is to run your update manager in whatever style you prefer, I just use System -> Administration -> Update manager.

    This will destroy all the fine hard work you did to install asoundconf to begin with. However! All is not lost...your alsa-utils are now updated.

    Step 6: cd to /usr and type:

    cp asoundconf /usr/bin/

    You will now have asoundconf in /usr/bin and it will work just fine.

    To test this, run asoundconf-gtk and see if it comes up, if it does, everything's fine. If it doesn't, something went horribly wrong.

    If it worked fine, you can now select from the detected sound cards in your system.

    Step 6 most likely will have to be repeated for each alsa-utils upgrade done, but hey, it's better than not being able to swap between two or more sound cards without using PulseAudio

    For those wondering why this has happened, it's because the person who was maintaining asoundconf is no longer doing so. Seriously, that's the only reason. We just need someone who knows what they're doing to maintain it again and we won't have to deal with these inglorious hacks.

    Stay loud, talk hard.

    Cheers,
    Ghost|BTFH

  2. #2
    Join Date
    Oct 2008
    Location
    Chicago
    Beans
    755
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: asoundconf is dead, long live asoundconf!

    bump

  3. #3
    Join Date
    Oct 2006
    Beans
    619
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: asoundconf is dead, long live asoundconf!

    craig@craig-desktop:/usr$ cp asoundconf /usr/bin/
    cp: cannot create regular file `/usr/bin/asoundconf': Permission denied
    craig@craig-desktop:/usr$ sudo cp asoundconf /usr/bin/
    craig@craig-desktop:/usr$ asoundconf-gtk
    You need to make sure asoundconf is active!
    By default, asoundconf's configuration file is ~/.asoundrc.asoundconf
    and must be included in ~/.asoundrc. Open this file to make sure it is!

    Why is this not working? I removed pulse audio completely and try this with running only ALSA to no success.

  4. #4
    Join Date
    Sep 2006
    Location
    Not far from reality...
    Beans
    236
    Distro
    Xubuntu 11.10 Oneiric Ocelot

    Re: asoundconf is dead, long live asoundconf!

    Quote Originally Posted by Tumpster View Post
    craig@craig-desktop:/usr$ cp asoundconf /usr/bin/
    cp: cannot create regular file `/usr/bin/asoundconf': Permission denied
    craig@craig-desktop:/usr$ sudo cp asoundconf /usr/bin/
    craig@craig-desktop:/usr$ asoundconf-gtk
    You need to make sure asoundconf is active!
    By default, asoundconf's configuration file is ~/.asoundrc.asoundconf
    and must be included in ~/.asoundrc. Open this file to make sure it is!

    Why is this not working? I removed pulse audio completely and try this with running only ALSA to no success.
    1) Did you have sound working in ALSA before you did this?

    2) Did you give it a reboot after removing pulse and installing ALSA?

    3) I'm presuming you did, but did you follow each step including selecting the correct version of your OS?

    If yes to all, did you try doing:

    asoundconf is-active

    in terminal? It might be something I'd done and hadn't remembered to mention.

    I'm hoping we can get to the bottom of this for you.

    Cheers,
    Ghost
    Last edited by Ghost|BTFH; December 10th, 2009 at 03:38 AM.

  5. #5
    Join Date
    Oct 2006
    Beans
    619
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: asoundconf is dead, long live asoundconf!

    Quote Originally Posted by Ghost|BTFH View Post
    1) Did you have sound working in ALSA before you did this?

    2) Did you give it a reboot after removing pulse and installing ALSA?

    3) I'm presuming you did, but did you follow each step including selecting the correct version of your OS?

    If yes to all, did you try doing:

    asoundconf is-active

    in terminal? It might be something I'd done and hadn't remembered to mention.

    I'm hoping we can get to the bottom of this for you.

    Cheers,
    Ghost
    I never honestly checked alsa before I removed pulseaudio, I just removed pulseaudio and switched to alsa and have had no troubles with it. I did reboot after almost every major change between going from pulse to alsa and finally I input that asoundconf is-active and nothing came up just bumped to my next line. What could I be doing wrong or can I do?

  6. #6
    Join Date
    Sep 2006
    Location
    Not far from reality...
    Beans
    236
    Distro
    Xubuntu 11.10 Oneiric Ocelot

    Re: asoundconf is dead, long live asoundconf!

    If I recall correctly, just doing

    asoundconf is active

    should be enough to make asoundconf work.

    You should have alsa properly installed, everything switched over to it and asoundconf should work.

    You could test it by trying

    asoundconf list

    If you get a list of the sound cards you have in your system - it's working.

    Otherwise, we'd have to go back to the start and see what you did to remove pulse/install alsa.

    Cheers,
    Ghost

  7. #7
    Join Date
    Apr 2008
    Location
    Essex, England
    Beans
    138
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: asoundconf is dead, long live asoundconf!

    Thanks for your instructions. I can now select my soundcard!
    Chris

  8. #8
    Join Date
    Jul 2008
    Location
    Woodstock Cape Town RSA
    Beans
    988
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: asoundconf is dead, long live asoundconf!

    Can't believe asoundconf is not being maintained. This is probably why the soundsystem in Ubuntu is so crappy. Its been getting more complicated and worse as time goes by.

    The lack of a good alsa configuration utility is what is driving me nuts.

    There are a lot of good apps out there which require customised alsa settings and not having the ability to change between settings, well, name your poison.

    Pulseaudio is all find and dandy, but where is the basic architecture of the system?

    Make a noise people.

  9. #9
    Join Date
    Sep 2010
    Beans
    1

    Re: asoundconf is dead, long live asoundconf!

    In Jaunty, the file /usr/bin/asoundconf is not compiled. It is
    a python script, text file. I placed it in /usr/bin and
    then installed the asoundconf-gtk package. It works.

    Here's the text of the file. You could just copy this, save as
    asoundconf, instead of extracting it from the Jaunty package.

    ------starts below this line-------------
    #!/usr/bin/python

    # (C) 2005 Canonical Ltd.
    # Author: Martin Pitt <martin.pitt@ubuntu.com>
    # License: GNU General Public License, version 2 or any later version
    #
    # Modified by: Thomas Hood, Daniel T Chen
    #
    # Get and set configuration parameters in ~/.asoundrc.asoundconf.

    import sys, re, os.path

    our_conf_file = os.path.expanduser('~/.asoundrc.asoundconf')
    asoundrc_file = os.path.expanduser('~/.asoundrc')
    predefs_file = '/usr/share/alsa/alsa.conf'

    setting_re_template = '!?\s*%s\s*(?:=|\s)\s*([^;,]+)[;,]?$'

    our_conf_header = '''# ALSA library configuration file managed by asoundconf(1).
    #
    # MANUAL CHANGES TO THIS FILE WILL BE OVERWRITTEN!
    #
    # Manual changes to the ALSA library configuration should be implemented
    # by editing the ~/.asoundrc file, not by editing this file.
    '''

    asoundrc_header = '''# ALSA library configuration file
    '''

    inclusion_comment = '''# Include settings that are under the control of asoundconf(1).
    # (To disable these settings, comment out this line.)'''

    usage = '''Usage:
    asoundconf is-active
    asoundconf get|delete PARAMETER
    asoundconf set PARAMETER VALUE
    asoundconf list

    Convenience macro functions:
    asoundconf set-default-card PARAMETER
    asoundconf reset-default-card
    asoundconf set-pulseaudio
    asoundconf unset-pulseaudio
    asoundconf set-oss PARAMETER
    asoundconf unset-oss
    '''


    needs_default_card = '''You have omitted a necessary parameter. Please see the output from `asoundconf list`, and use one of those sound card(s) as the parameter.
    '''


    needs_oss_dev = '''You have omitted a necessary parameter. Please specify an OSS device (e.g., /dev/dsp).
    '''


    superuser_warn = '''Please note that you are attempting to run asoundconf as a privileged superuser, which may have unintended consequences.
    '''


    def get_default_predefs():
    try:
    if not os.path.exists(predefs_file):
    return
    predefs_file_entire = open(predefs_file).readlines()
    r = re.compile('^defaults')
    ## Between these hashes, add additional unique regexps that
    ## must exist at the end of the user's custom asoundrc.
    s = re.compile('^defaults.namehint')
    ##
    predefs_list = []
    must_append_predefs_list = []
    for i in predefs_file_entire:
    if r.match(i) and not s.match(i):
    predefs_list.append(str(i).strip())
    elif s.match(i):
    must_append_predefs_list.append(str(i).strip())
    for i in must_append_predefs_list:
    predefs_list.append(str(i).strip())
    return predefs_list
    except IOError:
    pass


    def ensure_our_conf_exists():
    '''If it does not exist then generate a default configuration
    file with no settings.

    Return: True on success, False if the file could not be created.
    '''

    if os.path.exists(our_conf_file):
    return True

    try:
    open(our_conf_file, 'w').write(our_conf_header)
    return True
    except IOError:
    print >> sys.stderr, 'Error: could not create', our_conf_file
    return False


    def ensure_asound_rc_exists():
    '''Generate a default user configuration file with only the
    inclusion line.

    Return: True on success, False if the file could not be created.
    '''

    if os.path.exists(asoundrc_file):
    return True

    try:
    open(asoundrc_file, 'w').write('%s\n%s\n<%s>\n\n' % (asoundrc_header, inclusion_comment, our_conf_file))
    return True
    except IOError:
    print >> sys.stderr, 'Error: could not create', asoundrc_file
    return False


    def sds_transition():
    '''Replace the magic comments added to the user configuration file
    by the obsolete set-default-soundcard program with the standard
    inclusion statement for our configuration file.
    '''

    if not os.path.exists(asoundrc_file):
    return

    lines = open(asoundrc_file).readlines()

    start_marker_re = re.compile('### BEGIN set-default-soundcard')
    end_marker_re = re.compile('### END set-default-soundcard')

    userconf_lines = []
    our_conf_lines = []

    # read up to start comment
    lineno = 0
    found = 0
    for l in lines:
    lineno = lineno+1
    if start_marker_re.match(l):
    found = 1
    break
    userconf_lines.append(l)

    if found:
    # replace magic comment section with include
    userconf_lines.append('%s\n<%s>\n\n' % (inclusion_comment, our_conf_file))
    else:
    # no magic comment
    return

    # read magic comment section until end marker and add it to asoundconf
    found = 0
    for l in lines[lineno:]:
    lineno = lineno+1
    if end_marker_re.match(l):
    found = 1
    break
    if not l.startswith('#'):
    our_conf_lines.append(l)

    if not found:
    # no complete magic comment
    return

    # add the rest to user conf
    userconf_lines = userconf_lines + lines[lineno:]

    # write our configuration file
    if not ensure_our_conf_exists():
    return
    try:
    open(our_conf_file, 'a').writelines(our_conf_lines)
    except IOError:
    return # panic out

    # write user configuration file
    try:
    open(asoundrc_file, 'w').writelines(userconf_lines)
    except IOError:
    pass


    def is_active():
    '''Check that the user configuration file is either absent, or,
    if present, that it includifies the asoundconf configuration file;
    in those cases asoundconf can be used to change the user's ALSA
    library configuration.

    Also transition from the legacy set-default-soundcard program.

    Return True if the above condition is met, False if not.
    '''

    if not os.path.exists(asoundrc_file):
    return True

    sds_transition()

    # check whether or not the file has the inclusion line
    include_re = re.compile('\s*<\s*%s\s*>' % our_conf_file)
    for l in open(asoundrc_file):
    if include_re.match(l):
    return True

    return False

    def get(prmtr):
    '''Print the value of the given parameter on stdout

    Also transition from the legacy set-default-soundcard program.

    Return True on success, and False if the value is not set.
    '''

    sds_transition()

    if not os.path.exists(our_conf_file):
    return False

    setting_re = re.compile(setting_re_template % prmtr)

    try:
    for line in open(our_conf_file):
    m = setting_re.match(line)
    if m:
    print m.group(1).strip()
    return True
    return False
    except IOError:
    return False

    def list():
    '''Get card names from /proc/asound/cards'''

    cardspath = '/proc/asound/cards'
    if not os.path.exists(cardspath):
    return False
    procfile = open(cardspath, 'rb')
    cardline = re.compile('^\s*\d+\s*\[')
    card_lines = []
    lines = procfile.readlines()
    for l in lines:
    if cardline.match(l):
    card_lines.append(re.sub(r'^\s*\d+\s*\[(\w+)\s*\].+','\\1',l))
    print "Names of available sound cards:"
    for cardname in card_lines:
    print cardname.strip()
    return True

    def delete(prmtr):
    '''Delete the given parameter.

    Also transition from the legacy set-default-soundcard program.

    Return True on success, and False on an error.
    '''

    sds_transition()

    if not os.path.exists(our_conf_file):
    return False

    setting_re = re.compile(setting_re_template % prmtr)
    lines = []
    try:
    lines = open(our_conf_file).readlines()
    except IOError:
    return False

    found = 0
    for i in xrange(len(lines)):
    if setting_re.match(lines[i]):
    del lines[i]
    found = 1
    break

    if found:
    # write back file
    try:
    f = open(our_conf_file, 'w')
    except IOError:
    return False
    f.writelines(lines)

    return True


    def set(prmtr, value):
    '''Set the given parameter to the given value

    Also transition from the legacy set-default-soundcard program.

    Return True on success, and False on an error.
    '''

    sds_transition()

    setting_re = re.compile(setting_re_template % prmtr)
    lines = []

    ensure_asound_rc_exists()
    # N.B. We continue even if asoundrc could not be created
    # and we do NOT ensure that our configuration is "active"

    if not ensure_our_conf_exists():
    return False

    try:
    lines = open(our_conf_file).readlines()
    except IOError:
    return False

    newsetting = '%s %s\n' % (prmtr, value)

    # if setting is already present, change it
    found = 0
    for i in xrange(len(lines)):
    if setting_re.match(lines[i]):
    lines[i] = newsetting
    found = 1
    break

    if not found:
    lines.append(newsetting)

    # write back file
    try:
    f = open(our_conf_file, 'w')
    except IOError:
    return False
    f.writelines(lines)
    return True

    def set_default_card(card):
    clist = get_default_predefs()
    sep = re.compile('\s+')
    r = re.compile('^defaults.pcm.card')
    s = re.compile('^defaults.ctl.card')
    ## !defaults.pcm.card and defaults.ctl.card should lead
    ## the user's custom asoundrc.
    if set('!defaults.pcm.card', card) and \
    set('defaults.ctl.card', card):
    for i in clist:
    (j, k) = sep.split(i)
    if not r.match(j) and not s.match(j):
    if not set(j, k):
    return False
    return True
    else:
    return False

    def reset_default_card():
    clist = get_default_predefs()
    sep = re.compile('\s+')
    for i in clist:
    (j, k) = sep.split(i)
    if not delete(j):
    return False
    return True

    def delete_pcm_default():
    return delete('pcm.!default')

    def delete_ctl_default():
    return delete('ctl.!default')

    def set_pulseaudio():
    return set('pcm.!default', '{ type pulse }') and \
    set('ctl.!default', '{ type pulse }')

    def unset_pulseaudio():
    return delete_pcm_default() and \
    delete_ctl_default()

    def set_oss(device):
    endbrace = ' }'
    return set('pcm.!default { type oss device', device + endbrace)

    def unset_oss():
    return delete_pcm_default()

    def exit_code(result):
    '''Exit program with code 0 if result is True, otherwise exit with code
    1.
    '''

    if result:
    sys.exit(0)
    else:
    sys.exit(1)


    ##
    ## main
    ##

    if os.geteuid() == 0:
    print superuser_warn

    if len(sys.argv) < 2 or sys.argv[1] == '--help' or sys.argv[1] == '-h':
    print usage
    sys.exit(0)

    if sys.argv[1] == 'is-active':
    exit_code(is_active())

    if sys.argv[1] == 'get':
    if len(sys.argv) != 3:
    print usage
    sys.exit(1)
    exit_code(get(sys.argv[2]))

    if sys.argv[1] == 'delete':
    if len(sys.argv) != 3:
    print usage
    sys.exit(1)
    exit_code(delete(sys.argv[2]))

    if sys.argv[1] == 'set':
    if len(sys.argv) != 4:
    print usage
    sys.exit(1)
    exit_code(set(sys.argv[2], sys.argv[3]))

    if sys.argv[1] == 'list':
    exit_code(list())

    if sys.argv[1] == 'set-default-card':
    if len(sys.argv) != 3:
    print needs_default_card
    sys.exit(1)
    exit_code(set_default_card(sys.argv[2]))

    if sys.argv[1] == 'reset-default-card':
    exit_code(reset_default_card())

    if sys.argv[1] == 'set-pulseaudio':
    exit_code(set_pulseaudio())

    if sys.argv[1] == 'unset-pulseaudio':
    exit_code(unset_pulseaudio())

    if sys.argv[1] == 'set-oss':
    if len(sys.argv) != 3:
    print needs_oss_dev
    sys.exit(1)
    exit_code(set_oss(sys.argv[2]))

    if sys.argv[1] == 'unset-oss':
    exit_code(unset_oss())

    print usage
    sys.exit(1)
    Last edited by SpeakingFreely; September 2nd, 2010 at 08:02 AM. Reason: add instructions

  10. #10
    Join Date
    Jan 2008
    Location
    Malmö
    Beans
    130
    Distro
    Ubuntu 13.10 Saucy Salamander

    Re: asoundconf is dead, long live asoundconf!

    Quote Originally Posted by SpeakingFreely View Post
    In Jaunty, the file /usr/bin/asoundconf is not compiled. It is
    a python script, text file. I placed it in /usr/bin and
    then installed the asoundconf-gtk package. It works.

    Here's the text of the file. You could just copy this, save as
    asoundconf, instead of extracting it from the Jaunty package.

    ------starts below this line-------------

    ...
    Thanks for pointing out this significant simplification of the process. However, you would have had to paste it within CODE tags in order to preserve the indentation of the code, since python will not work without adequately indented code blocks.

    However, realizing asoundconf was a simple text file made it quite easy to locate a working source of the script:

    http://wiki.marklesh.com/How-to/Asoundconf

    The author of the page mentions having had to modify it to work with newer versions. The page says it's adapted for 10.10, but it works perfectly fine for me also in 11.04. After downloading the asoundconf file (the link is about half way down the page, for the REALLY impatient) it's as simple as making it executable and moving it to /usr/bin:

    chmod +x asoundconf
    sudo cp -a asoundconf /usr/bin

    After which,

    asoundconf is-active
    asoundconf list
    asoundconf set-default-card cardname

    should enable quick and convenient switching between sound cards. It works like a charm for me, and just to point out in the context that I don't even have a big problem with pulseaudio (nowadays) - it's simply that this is my netbook on which I use the delightfully light weight Lubuntu, which doesn't even have pulseaudio, and STILL does not include asoundconf or any other means I could find to enable me to select my usb speakers as the default audio output. Until now.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •